@pixi/text-html
Advanced tools
Comparing version 2.0.2 to 2.0.3
/*! | ||
* @pixi/text-html - v2.0.2 | ||
* Compiled Thu, 05 May 2022 16:09:00 UTC | ||
* @pixi/text-html - v2.0.3 | ||
* Compiled Thu, 09 Jun 2022 15:13:58 UTC | ||
* | ||
@@ -8,3 +8,3 @@ * @pixi/text-html is licensed under the MIT License. | ||
*/ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@pixi/sprite"),e=require("@pixi/settings"),i=require("@pixi/core"),o=require("@pixi/math"),r=require("@pixi/utils"),s=require("@pixi/text"),n=function(t){function n(r,s,n){void 0===r&&(r=""),void 0===s&&(s={}),(n=n||document.createElement("canvas")).width=3,n.height=3;var h=i.Texture.from(n,{scaleMode:e.settings.SCALE_MODE});h.orig=new o.Rectangle,h.trim=new o.Rectangle,t.call(this,h),this._parser=new DOMParser,this._image=new Image,this.canvas=n,this.context=this.canvas.getContext("2d"),this._resolution=e.settings.RESOLUTION,this._autoResolution=!0,this._text=null,this._style=null,this._loading=!1,this.text=r,this.style=s,this.localStyleID=-1}t&&(n.__proto__=t),n.prototype=Object.create(t&&t.prototype),n.prototype.constructor=n;var h={width:{configurable:!0},height:{configurable:!0},style:{configurable:!0},text:{configurable:!0},resolution:{configurable:!0}};return n.prototype.updateText=function(t){var e=this,i=this.style,o=this.canvas,s=this.context,n=this.resolution;if(this.localStyleID!==i.styleID&&(this.dirty=!0,this.localStyleID=i.styleID),this.dirty||!t){var h="\n display:inline-block;\n color:"+i.fill+";\n font-size: "+i.fontSize+"px;\n font-family:"+i.fontFamily+";\n font-weight:"+i.fontWeight+";\n font-style:"+i.fontStyle+";\n font-variant:"+i.fontVariant+";\n letter-spacing:"+i.letterSpacing+"px;\n text-align:"+i.align+";\n padding:"+i.padding+"px;\n ";if(i.lineHeight&&(h+="line-height:"+i.lineHeight+"px;"),i.wordWrap&&(h+="word-wrap:"+(i.breakWords?"break-all":"break-word")+";",h+="width:"+i.wordWrapWidth+"px;"),i.strokeThickness){var a=i.stroke;"number"==typeof color&&(a=r.hex2string(a)),h+="-webkit-text-stroke-width: "+i.strokeThickness+"px;",h+="-webkit-text-stroke-color: "+a+";",h+="text-stroke-width: "+i.strokeThickness+"px;",h+="text-stroke-color: "+a+";",h+="paint-order: stroke;"}if(i.dropShadow){var l=i.dropShadowAngle,d=i.dropShadowDistance,u=i.dropShadowBlur,c=i.dropShadowColor,p=i.dropShadowAlpha,g=Math.round(Math.cos(l)*d),x=Math.round(Math.sin(l)*d),y=c;if("number"==typeof y&&(y=r.hex2string(y)),"#"===y.charAt(0)&&p<1){var _=r.hex2rgb(parseInt(y.replace("#",""),16));y="rgba("+(255*_[0]|0)+", "+(255*_[1]|0)+", "+(255*_[2]|0)+", "+p+")"}h+="text-shadow: "+g+"px "+x+"px "+u+"px "+y+";"}var f='\n <svg xmlns="http://www.w3.org/2000/svg" width="2048" height="2048">\n <foreignObject width="100%" height="100%">\n <div xmlns="http://www.w3.org/1999/xhtml" style="'+h+'">'+this._text+"</div>\n </foreignObject>\n </svg>\n ",w=this._parser.parseFromString(f,"text/xml").firstChild.querySelector("div");document.body.appendChild(w);var v=w.getBoundingClientRect(),m=v.width,b=v.height;if(document.body.removeChild(w),o.width=Math.ceil((Math.max(1,m)+2*i.padding)*n),o.height=Math.ceil((Math.max(1,b)+2*i.padding)*n),!this._loading){var T=this._image;this._loading=!0,T.src="data:image/svg+xml,"+encodeURIComponent(f),T.onload=function(){s.scale(n,n),s.clearRect(0,0,o.width,o.height),s.drawImage(T,0,0,m,b,0,0,m,b),T.onload=void 0,e._loading=!1,e.updateTexture()}}}},n.prototype.updateTexture=function(){var t=this.canvas,e=this.context,i=this.style,o=this.texture,s=this.resolution;if(i.trim){var n=r.trimCanvas(t),h=n.width,a=n.height,l=n.data;l&&(t.width=h,t.height=a,e.putImageData(l,0,0))}var d=i.trim?0:i.padding,u=o.baseTexture;o.trim.width=o._frame.width=Math.ceil(t.width/s),o.trim.height=o._frame.height=Math.ceil(t.height/s),o.trim.x=-d,o.trim.y=-d,o.orig.width=o._frame.width-2*d,o.orig.height=o._frame.height-2*d,this._onTextureUpdate(),u.setRealSize(t.width,t.height,s),this.dirty=!1},n.prototype._render=function(e){this._autoResolution&&this._resolution!==e.resolution&&(this._resolution=e.resolution,this.dirty=!0),this.updateText(!0),t.prototype._render.call(this,e)},n.prototype._renderCanvas=function(e){this._autoResolution&&this._resolution!==e.resolution&&(this._resolution=e.resolution,this.dirty=!0),this.updateText(!0),t.prototype._renderCanvas.call(this,e)},n.prototype.getLocalBounds=function(e){return this.updateText(!0),t.prototype.getLocalBounds.call(this,e)},n.prototype._calculateBounds=function(){this.updateText(!0),this.calculateVertices(),this._bounds.addQuad(this.vertexData)},n.prototype._onStyleChange=function(){this.dirty=!0},n.prototype.destroy=function(e){void 0===e&&(e=!0),t.prototype.destroy.call(this,e),this.context=null,this.canvas.width=this.canvas.height=0,this.canvas=null,this._style=null,this._parser=null,this._image.onload=null,this._image.src="",this._image=null},h.width.get=function(){return this.updateText(!0),Math.abs(this.scale.x)*this._texture.orig.width},h.width.set=function(t){this.updateText(!0);var e=r.sign(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t},h.height.get=function(){return this.updateText(!0),Math.abs(this.scale.y)*this._texture.orig.height},h.height.set=function(t){this.updateText(!0);var e=r.sign(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t},h.style.get=function(){return this._style},h.style.set=function(t){(t=t||{})instanceof s.TextStyle?this._style=t:this._style=new s.TextStyle(t),this.localStyleID=-1,this.dirty=!0},h.text.get=function(){return this._text},h.text.set=function(t){t=String(""===t||null==t?" ":t),t=this.sanitiseText(t),this._text!==t&&(this._text=t,this.dirty=!0)},h.resolution.get=function(){return this._resolution},h.resolution.set=function(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)},n.prototype.sanitiseText=function(t){return t.replace(/<br>/gi,"<br/>").replace(/<hr>/gi,"<hr/>").replace(/ /gi," ")},Object.defineProperties(n.prototype,h),n}(t.Sprite);exports.HTMLText=n; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@pixi/sprite"),e=require("@pixi/settings"),i=require("@pixi/core"),o=require("@pixi/math"),s=require("@pixi/utils"),r=require("@pixi/text"),n=function(t){function n(s,r,n){void 0===s&&(s=""),void 0===r&&(r={}),(n=n||document.createElement("canvas")).width=3,n.height=3;var h=i.Texture.from(n,{scaleMode:e.settings.SCALE_MODE});h.orig=new o.Rectangle,h.trim=new o.Rectangle,t.call(this,h);var a="http://www.w3.org/2000/svg",l=document.createElementNS(a,"svg"),d=document.createElementNS(a,"foreignObject"),u=document.createElementNS("http://www.w3.org/1999/xhtml","div");d.setAttribute("height","100%"),d.setAttribute("width","100%"),l.appendChild(d),this._domElement=u,this._svgRoot=l,this._foreignObject=d,this._image=new Image,this.canvas=n,this.context=this.canvas.getContext("2d"),this._resolution=e.settings.RESOLUTION,this._autoResolution=!0,this._text=null,this._style=null,this._loading=!1,this.text=s,this.style=r,this.localStyleID=-1}t&&(n.__proto__=t),n.prototype=Object.create(t&&t.prototype),n.prototype.constructor=n;var h={width:{configurable:!0},height:{configurable:!0},style:{configurable:!0},text:{configurable:!0},resolution:{configurable:!0}};return n.prototype.updateText=function(t){var e=this,i=this.style,o=this.canvas,r=this.context,n=this.resolution;if(this.localStyleID!==i.styleID&&(this.dirty=!0,this.localStyleID=i.styleID),this.dirty||!t){var h="\n display:inline-block;\n color:"+i.fill+";\n font-size: "+i.fontSize+"px;\n font-family:"+i.fontFamily+";\n font-weight:"+i.fontWeight+";\n font-style:"+i.fontStyle+";\n font-variant:"+i.fontVariant+";\n letter-spacing:"+i.letterSpacing+"px;\n text-align:"+i.align+";\n padding:"+i.padding+"px;\n ";if(i.lineHeight&&(h+="line-height:"+i.lineHeight+"px;"),i.wordWrap&&(h+="word-wrap:"+(i.breakWords?"break-all":"break-word")+";",h+="width:"+i.wordWrapWidth+"px;"),i.strokeThickness){var a=i.stroke;"number"==typeof color&&(a=s.hex2string(a)),h+="-webkit-text-stroke-width: "+i.strokeThickness+"px;",h+="-webkit-text-stroke-color: "+a+";",h+="text-stroke-width: "+i.strokeThickness+"px;",h+="text-stroke-color: "+a+";",h+="paint-order: stroke;"}if(i.dropShadow){var l=i.dropShadowAngle,d=i.dropShadowDistance,u=i.dropShadowBlur,c=i.dropShadowColor,p=i.dropShadowAlpha,g=Math.round(Math.cos(l)*d),x=Math.round(Math.sin(l)*d),_=c;if("number"==typeof _&&(_=s.hex2string(_)),"#"===_.charAt(0)&&p<1){var y=s.hex2rgb(parseInt(_.replace("#",""),16));_="rgba("+(255*y[0]|0)+", "+(255*y[1]|0)+", "+(255*y[2]|0)+", "+p+")"}h+="text-shadow: "+g+"px "+x+"px "+u+"px "+_+";"}var f=this._domElement;Object.assign(f,{innerHTML:this._text,style:h}),document.body.appendChild(f);var w=f.getBoundingClientRect(),m=w.width,v=w.height;if(document.body.removeChild(f),this._foreignObject.appendChild(f),this._svgRoot.setAttribute("width",m),this._svgRoot.setAttribute("height",v),o.width=Math.ceil((Math.max(1,m)+2*i.padding)*n),o.height=Math.ceil((Math.max(1,v)+2*i.padding)*n),!this._loading){var b=this._image,S=(new XMLSerializer).serializeToString(this._svgRoot);this._loading=!0,b.src="data:image/svg+xml;charset=utf8,"+encodeURIComponent(S),b.onload=function(){r.scale(n,n),r.clearRect(0,0,o.width,o.height),r.drawImage(b,0,0,m,v,0,0,m,v),b.src="",b.onload=void 0,e._loading=!1,e.updateTexture()}}}},n.prototype.updateTexture=function(){var t=this.canvas,e=this.context,i=this.style,o=this.texture,r=this.resolution;if(i.trim){var n=s.trimCanvas(t),h=n.width,a=n.height,l=n.data;l&&(t.width=h,t.height=a,e.putImageData(l,0,0))}var d=i.trim?0:i.padding,u=o.baseTexture;o.trim.width=o._frame.width=Math.ceil(t.width/r),o.trim.height=o._frame.height=Math.ceil(t.height/r),o.trim.x=-d,o.trim.y=-d,o.orig.width=o._frame.width-2*d,o.orig.height=o._frame.height-2*d,this._onTextureUpdate(),u.setRealSize(t.width,t.height,r),this.dirty=!1},n.prototype._render=function(e){this._autoResolution&&this._resolution!==e.resolution&&(this._resolution=e.resolution,this.dirty=!0),this.updateText(!0),t.prototype._render.call(this,e)},n.prototype._renderCanvas=function(e){this._autoResolution&&this._resolution!==e.resolution&&(this._resolution=e.resolution,this.dirty=!0),this.updateText(!0),t.prototype._renderCanvas.call(this,e)},n.prototype.getLocalBounds=function(e){return this.updateText(!0),t.prototype.getLocalBounds.call(this,e)},n.prototype._calculateBounds=function(){this.updateText(!0),this.calculateVertices(),this._bounds.addQuad(this.vertexData)},n.prototype._onStyleChange=function(){this.dirty=!0},n.prototype.destroy=function(e){void 0===e&&(e=!0),t.prototype.destroy.call(this,e),this.context=null,this.canvas.width=this.canvas.height=0,this.canvas=null,this._style=null,this._svgRoot=null,this._domElement=null,this._foreignObject=null,this._image.onload=null,this._image.src="",this._image=null},h.width.get=function(){return this.updateText(!0),Math.abs(this.scale.x)*this._texture.orig.width},h.width.set=function(t){this.updateText(!0);var e=s.sign(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t},h.height.get=function(){return this.updateText(!0),Math.abs(this.scale.y)*this._texture.orig.height},h.height.set=function(t){this.updateText(!0);var e=s.sign(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t},h.style.get=function(){return this._style},h.style.set=function(t){(t=t||{})instanceof r.TextStyle?this._style=t:this._style=new r.TextStyle(t),this.localStyleID=-1,this.dirty=!0},h.text.get=function(){return this._text},h.text.set=function(t){t=String(""===t||null==t?" ":t),t=this.sanitiseText(t),this._text!==t&&(this._text=t,this.dirty=!0)},h.resolution.get=function(){return this._resolution},h.resolution.set=function(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)},n.prototype.sanitiseText=function(t){return t.replace(/<br>/gi,"<br/>").replace(/<hr>/gi,"<hr/>").replace(/ /gi," ")},Object.defineProperties(n.prototype,h),n}(t.Sprite);exports.HTMLText=n; | ||
//# sourceMappingURL=html-text.cjs.js.map |
/*! | ||
* @pixi/text-html - v2.0.2 | ||
* Compiled Thu, 05 May 2022 16:09:00 UTC | ||
* @pixi/text-html - v2.0.3 | ||
* Compiled Thu, 09 Jun 2022 15:13:58 UTC | ||
* | ||
@@ -8,3 +8,3 @@ * @pixi/text-html is licensed under the MIT License. | ||
*/ | ||
import{Sprite as t}from"@pixi/sprite";import{settings as i}from"@pixi/settings";import{Texture as e}from"@pixi/core";import{Rectangle as o}from"@pixi/math";import{hex2string as r,hex2rgb as s,trimCanvas as n,sign as h}from"@pixi/utils";import{TextStyle as a}from"@pixi/text";var l=function(t){function l(r,s,n){void 0===r&&(r=""),void 0===s&&(s={}),(n=n||document.createElement("canvas")).width=3,n.height=3;var h=e.from(n,{scaleMode:i.SCALE_MODE});h.orig=new o,h.trim=new o,t.call(this,h),this._parser=new DOMParser,this._image=new Image,this.canvas=n,this.context=this.canvas.getContext("2d"),this._resolution=i.RESOLUTION,this._autoResolution=!0,this._text=null,this._style=null,this._loading=!1,this.text=r,this.style=s,this.localStyleID=-1}t&&(l.__proto__=t),l.prototype=Object.create(t&&t.prototype),l.prototype.constructor=l;var d={width:{configurable:!0},height:{configurable:!0},style:{configurable:!0},text:{configurable:!0},resolution:{configurable:!0}};return l.prototype.updateText=function(t){var i=this,e=this.style,o=this.canvas,n=this.context,h=this.resolution;if(this.localStyleID!==e.styleID&&(this.dirty=!0,this.localStyleID=e.styleID),this.dirty||!t){var a="\n display:inline-block;\n color:"+e.fill+";\n font-size: "+e.fontSize+"px;\n font-family:"+e.fontFamily+";\n font-weight:"+e.fontWeight+";\n font-style:"+e.fontStyle+";\n font-variant:"+e.fontVariant+";\n letter-spacing:"+e.letterSpacing+"px;\n text-align:"+e.align+";\n padding:"+e.padding+"px;\n ";if(e.lineHeight&&(a+="line-height:"+e.lineHeight+"px;"),e.wordWrap&&(a+="word-wrap:"+(e.breakWords?"break-all":"break-word")+";",a+="width:"+e.wordWrapWidth+"px;"),e.strokeThickness){var l=e.stroke;"number"==typeof color&&(l=r(l)),a+="-webkit-text-stroke-width: "+e.strokeThickness+"px;",a+="-webkit-text-stroke-color: "+l+";",a+="text-stroke-width: "+e.strokeThickness+"px;",a+="text-stroke-color: "+l+";",a+="paint-order: stroke;"}if(e.dropShadow){var d=e.dropShadowAngle,p=e.dropShadowDistance,u=e.dropShadowBlur,c=e.dropShadowColor,g=e.dropShadowAlpha,x=Math.round(Math.cos(d)*p),f=Math.round(Math.sin(d)*p),y=c;if("number"==typeof y&&(y=r(y)),"#"===y.charAt(0)&&g<1){var _=s(parseInt(y.replace("#",""),16));y="rgba("+(255*_[0]|0)+", "+(255*_[1]|0)+", "+(255*_[2]|0)+", "+g+")"}a+="text-shadow: "+x+"px "+f+"px "+u+"px "+y+";"}var w='\n <svg xmlns="http://www.w3.org/2000/svg" width="2048" height="2048">\n <foreignObject width="100%" height="100%">\n <div xmlns="http://www.w3.org/1999/xhtml" style="'+a+'">'+this._text+"</div>\n </foreignObject>\n </svg>\n ",m=this._parser.parseFromString(w,"text/xml").firstChild.querySelector("div");document.body.appendChild(m);var v=m.getBoundingClientRect(),b=v.width,S=v.height;if(document.body.removeChild(m),o.width=Math.ceil((Math.max(1,b)+2*e.padding)*h),o.height=Math.ceil((Math.max(1,S)+2*e.padding)*h),!this._loading){var T=this._image;this._loading=!0,T.src="data:image/svg+xml,"+encodeURIComponent(w),T.onload=function(){n.scale(h,h),n.clearRect(0,0,o.width,o.height),n.drawImage(T,0,0,b,S,0,0,b,S),T.onload=void 0,i._loading=!1,i.updateTexture()}}}},l.prototype.updateTexture=function(){var t=this.canvas,i=this.context,e=this.style,o=this.texture,r=this.resolution;if(e.trim){var s=n(t),h=s.width,a=s.height,l=s.data;l&&(t.width=h,t.height=a,i.putImageData(l,0,0))}var d=e.trim?0:e.padding,p=o.baseTexture;o.trim.width=o._frame.width=Math.ceil(t.width/r),o.trim.height=o._frame.height=Math.ceil(t.height/r),o.trim.x=-d,o.trim.y=-d,o.orig.width=o._frame.width-2*d,o.orig.height=o._frame.height-2*d,this._onTextureUpdate(),p.setRealSize(t.width,t.height,r),this.dirty=!1},l.prototype._render=function(i){this._autoResolution&&this._resolution!==i.resolution&&(this._resolution=i.resolution,this.dirty=!0),this.updateText(!0),t.prototype._render.call(this,i)},l.prototype._renderCanvas=function(i){this._autoResolution&&this._resolution!==i.resolution&&(this._resolution=i.resolution,this.dirty=!0),this.updateText(!0),t.prototype._renderCanvas.call(this,i)},l.prototype.getLocalBounds=function(i){return this.updateText(!0),t.prototype.getLocalBounds.call(this,i)},l.prototype._calculateBounds=function(){this.updateText(!0),this.calculateVertices(),this._bounds.addQuad(this.vertexData)},l.prototype._onStyleChange=function(){this.dirty=!0},l.prototype.destroy=function(i){void 0===i&&(i=!0),t.prototype.destroy.call(this,i),this.context=null,this.canvas.width=this.canvas.height=0,this.canvas=null,this._style=null,this._parser=null,this._image.onload=null,this._image.src="",this._image=null},d.width.get=function(){return this.updateText(!0),Math.abs(this.scale.x)*this._texture.orig.width},d.width.set=function(t){this.updateText(!0);var i=h(this.scale.x)||1;this.scale.x=i*t/this._texture.orig.width,this._width=t},d.height.get=function(){return this.updateText(!0),Math.abs(this.scale.y)*this._texture.orig.height},d.height.set=function(t){this.updateText(!0);var i=h(this.scale.y)||1;this.scale.y=i*t/this._texture.orig.height,this._height=t},d.style.get=function(){return this._style},d.style.set=function(t){t=t||{},this._style=t instanceof a?t:new a(t),this.localStyleID=-1,this.dirty=!0},d.text.get=function(){return this._text},d.text.set=function(t){t=String(""===t||null==t?" ":t),t=this.sanitiseText(t),this._text!==t&&(this._text=t,this.dirty=!0)},d.resolution.get=function(){return this._resolution},d.resolution.set=function(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)},l.prototype.sanitiseText=function(t){return t.replace(/<br>/gi,"<br/>").replace(/<hr>/gi,"<hr/>").replace(/ /gi," ")},Object.defineProperties(l.prototype,d),l}(t);export{l as HTMLText}; | ||
import{Sprite as t}from"@pixi/sprite";import{settings as e}from"@pixi/settings";import{Texture as i}from"@pixi/core";import{Rectangle as o}from"@pixi/math";import{hex2string as s,hex2rgb as r,trimCanvas as n,sign as h}from"@pixi/utils";import{TextStyle as a}from"@pixi/text";var l=function(t){function l(s,r,n){void 0===s&&(s=""),void 0===r&&(r={}),(n=n||document.createElement("canvas")).width=3,n.height=3;var h=i.from(n,{scaleMode:e.SCALE_MODE});h.orig=new o,h.trim=new o,t.call(this,h);var a="http://www.w3.org/2000/svg",l=document.createElementNS(a,"svg"),d=document.createElementNS(a,"foreignObject"),u=document.createElementNS("http://www.w3.org/1999/xhtml","div");d.setAttribute("height","100%"),d.setAttribute("width","100%"),l.appendChild(d),this._domElement=u,this._svgRoot=l,this._foreignObject=d,this._image=new Image,this.canvas=n,this.context=this.canvas.getContext("2d"),this._resolution=e.RESOLUTION,this._autoResolution=!0,this._text=null,this._style=null,this._loading=!1,this.text=s,this.style=r,this.localStyleID=-1}t&&(l.__proto__=t),l.prototype=Object.create(t&&t.prototype),l.prototype.constructor=l;var d={width:{configurable:!0},height:{configurable:!0},style:{configurable:!0},text:{configurable:!0},resolution:{configurable:!0}};return l.prototype.updateText=function(t){var e=this,i=this.style,o=this.canvas,n=this.context,h=this.resolution;if(this.localStyleID!==i.styleID&&(this.dirty=!0,this.localStyleID=i.styleID),this.dirty||!t){var a="\n display:inline-block;\n color:"+i.fill+";\n font-size: "+i.fontSize+"px;\n font-family:"+i.fontFamily+";\n font-weight:"+i.fontWeight+";\n font-style:"+i.fontStyle+";\n font-variant:"+i.fontVariant+";\n letter-spacing:"+i.letterSpacing+"px;\n text-align:"+i.align+";\n padding:"+i.padding+"px;\n ";if(i.lineHeight&&(a+="line-height:"+i.lineHeight+"px;"),i.wordWrap&&(a+="word-wrap:"+(i.breakWords?"break-all":"break-word")+";",a+="width:"+i.wordWrapWidth+"px;"),i.strokeThickness){var l=i.stroke;"number"==typeof color&&(l=s(l)),a+="-webkit-text-stroke-width: "+i.strokeThickness+"px;",a+="-webkit-text-stroke-color: "+l+";",a+="text-stroke-width: "+i.strokeThickness+"px;",a+="text-stroke-color: "+l+";",a+="paint-order: stroke;"}if(i.dropShadow){var d=i.dropShadowAngle,u=i.dropShadowDistance,c=i.dropShadowBlur,p=i.dropShadowColor,g=i.dropShadowAlpha,x=Math.round(Math.cos(d)*u),f=Math.round(Math.sin(d)*u),_=p;if("number"==typeof _&&(_=s(_)),"#"===_.charAt(0)&&g<1){var m=r(parseInt(_.replace("#",""),16));_="rgba("+(255*m[0]|0)+", "+(255*m[1]|0)+", "+(255*m[2]|0)+", "+g+")"}a+="text-shadow: "+x+"px "+f+"px "+c+"px "+_+";"}var y=this._domElement;Object.assign(y,{innerHTML:this._text,style:a}),document.body.appendChild(y);var w=y.getBoundingClientRect(),v=w.width,b=w.height;if(document.body.removeChild(y),this._foreignObject.appendChild(y),this._svgRoot.setAttribute("width",v),this._svgRoot.setAttribute("height",b),o.width=Math.ceil((Math.max(1,v)+2*i.padding)*h),o.height=Math.ceil((Math.max(1,b)+2*i.padding)*h),!this._loading){var S=this._image,T=(new XMLSerializer).serializeToString(this._svgRoot);this._loading=!0,S.src="data:image/svg+xml;charset=utf8,"+encodeURIComponent(T),S.onload=function(){n.scale(h,h),n.clearRect(0,0,o.width,o.height),n.drawImage(S,0,0,v,b,0,0,v,b),S.src="",S.onload=void 0,e._loading=!1,e.updateTexture()}}}},l.prototype.updateTexture=function(){var t=this.canvas,e=this.context,i=this.style,o=this.texture,s=this.resolution;if(i.trim){var r=n(t),h=r.width,a=r.height,l=r.data;l&&(t.width=h,t.height=a,e.putImageData(l,0,0))}var d=i.trim?0:i.padding,u=o.baseTexture;o.trim.width=o._frame.width=Math.ceil(t.width/s),o.trim.height=o._frame.height=Math.ceil(t.height/s),o.trim.x=-d,o.trim.y=-d,o.orig.width=o._frame.width-2*d,o.orig.height=o._frame.height-2*d,this._onTextureUpdate(),u.setRealSize(t.width,t.height,s),this.dirty=!1},l.prototype._render=function(e){this._autoResolution&&this._resolution!==e.resolution&&(this._resolution=e.resolution,this.dirty=!0),this.updateText(!0),t.prototype._render.call(this,e)},l.prototype._renderCanvas=function(e){this._autoResolution&&this._resolution!==e.resolution&&(this._resolution=e.resolution,this.dirty=!0),this.updateText(!0),t.prototype._renderCanvas.call(this,e)},l.prototype.getLocalBounds=function(e){return this.updateText(!0),t.prototype.getLocalBounds.call(this,e)},l.prototype._calculateBounds=function(){this.updateText(!0),this.calculateVertices(),this._bounds.addQuad(this.vertexData)},l.prototype._onStyleChange=function(){this.dirty=!0},l.prototype.destroy=function(e){void 0===e&&(e=!0),t.prototype.destroy.call(this,e),this.context=null,this.canvas.width=this.canvas.height=0,this.canvas=null,this._style=null,this._svgRoot=null,this._domElement=null,this._foreignObject=null,this._image.onload=null,this._image.src="",this._image=null},d.width.get=function(){return this.updateText(!0),Math.abs(this.scale.x)*this._texture.orig.width},d.width.set=function(t){this.updateText(!0);var e=h(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t},d.height.get=function(){return this.updateText(!0),Math.abs(this.scale.y)*this._texture.orig.height},d.height.set=function(t){this.updateText(!0);var e=h(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t},d.style.get=function(){return this._style},d.style.set=function(t){t=t||{},this._style=t instanceof a?t:new a(t),this.localStyleID=-1,this.dirty=!0},d.text.get=function(){return this._text},d.text.set=function(t){t=String(""===t||null==t?" ":t),t=this.sanitiseText(t),this._text!==t&&(this._text=t,this.dirty=!0)},d.resolution.get=function(){return this._resolution},d.resolution.set=function(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)},l.prototype.sanitiseText=function(t){return t.replace(/<br>/gi,"<br/>").replace(/<hr>/gi,"<hr/>").replace(/ /gi," ")},Object.defineProperties(l.prototype,d),l}(t);export{l as HTMLText}; | ||
//# sourceMappingURL=html-text.es.js.map |
/*! | ||
* @pixi/text-html - v2.0.2 | ||
* Compiled Thu, 05 May 2022 16:09:00 UTC | ||
* @pixi/text-html - v2.0.3 | ||
* Compiled Thu, 09 Jun 2022 15:13:58 UTC | ||
* | ||
@@ -8,3 +8,3 @@ * @pixi/text-html is licensed under the MIT License. | ||
*/ | ||
var _pixi_htmltext=function(t,e,i,o,s,n,r){"use strict";var h=function(t){function e(e,n,r){void 0===e&&(e=""),void 0===n&&(n={}),(r=r||document.createElement("canvas")).width=3,r.height=3;var h=o.Texture.from(r,{scaleMode:i.settings.SCALE_MODE});h.orig=new s.Rectangle,h.trim=new s.Rectangle,t.call(this,h),this._parser=new DOMParser,this._image=new Image,this.canvas=r,this.context=this.canvas.getContext("2d"),this._resolution=i.settings.RESOLUTION,this._autoResolution=!0,this._text=null,this._style=null,this._loading=!1,this.text=e,this.style=n,this.localStyleID=-1}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var h={width:{configurable:!0},height:{configurable:!0},style:{configurable:!0},text:{configurable:!0},resolution:{configurable:!0}};return e.prototype.updateText=function(t){var e=this,i=this.style,o=this.canvas,s=this.context,r=this.resolution;if(this.localStyleID!==i.styleID&&(this.dirty=!0,this.localStyleID=i.styleID),this.dirty||!t){var h="\n display:inline-block;\n color:"+i.fill+";\n font-size: "+i.fontSize+"px;\n font-family:"+i.fontFamily+";\n font-weight:"+i.fontWeight+";\n font-style:"+i.fontStyle+";\n font-variant:"+i.fontVariant+";\n letter-spacing:"+i.letterSpacing+"px;\n text-align:"+i.align+";\n padding:"+i.padding+"px;\n ";if(i.lineHeight&&(h+="line-height:"+i.lineHeight+"px;"),i.wordWrap&&(h+="word-wrap:"+(i.breakWords?"break-all":"break-word")+";",h+="width:"+i.wordWrapWidth+"px;"),i.strokeThickness){var a=i.stroke;"number"==typeof color&&(a=n.hex2string(a)),h+="-webkit-text-stroke-width: "+i.strokeThickness+"px;",h+="-webkit-text-stroke-color: "+a+";",h+="text-stroke-width: "+i.strokeThickness+"px;",h+="text-stroke-color: "+a+";",h+="paint-order: stroke;"}if(i.dropShadow){var l=i.dropShadowAngle,d=i.dropShadowDistance,u=i.dropShadowBlur,c=i.dropShadowColor,p=i.dropShadowAlpha,g=Math.round(Math.cos(l)*d),x=Math.round(Math.sin(l)*d),y=c;if("number"==typeof y&&(y=n.hex2string(y)),"#"===y.charAt(0)&&p<1){var _=n.hex2rgb(parseInt(y.replace("#",""),16));y="rgba("+(255*_[0]|0)+", "+(255*_[1]|0)+", "+(255*_[2]|0)+", "+p+")"}h+="text-shadow: "+g+"px "+x+"px "+u+"px "+y+";"}var f='\n <svg xmlns="http://www.w3.org/2000/svg" width="2048" height="2048">\n <foreignObject width="100%" height="100%">\n <div xmlns="http://www.w3.org/1999/xhtml" style="'+h+'">'+this._text+"</div>\n </foreignObject>\n </svg>\n ",w=this._parser.parseFromString(f,"text/xml").firstChild.querySelector("div");document.body.appendChild(w);var m=w.getBoundingClientRect(),v=m.width,b=m.height;if(document.body.removeChild(w),o.width=Math.ceil((Math.max(1,v)+2*i.padding)*r),o.height=Math.ceil((Math.max(1,b)+2*i.padding)*r),!this._loading){var I=this._image;this._loading=!0,I.src="data:image/svg+xml,"+encodeURIComponent(f),I.onload=function(){s.scale(r,r),s.clearRect(0,0,o.width,o.height),s.drawImage(I,0,0,v,b,0,0,v,b),I.onload=void 0,e._loading=!1,e.updateTexture()}}}},e.prototype.updateTexture=function(){var t=this.canvas,e=this.context,i=this.style,o=this.texture,s=this.resolution;if(i.trim){var r=n.trimCanvas(t),h=r.width,a=r.height,l=r.data;l&&(t.width=h,t.height=a,e.putImageData(l,0,0))}var d=i.trim?0:i.padding,u=o.baseTexture;o.trim.width=o._frame.width=Math.ceil(t.width/s),o.trim.height=o._frame.height=Math.ceil(t.height/s),o.trim.x=-d,o.trim.y=-d,o.orig.width=o._frame.width-2*d,o.orig.height=o._frame.height-2*d,this._onTextureUpdate(),u.setRealSize(t.width,t.height,s),this.dirty=!1},e.prototype._render=function(e){this._autoResolution&&this._resolution!==e.resolution&&(this._resolution=e.resolution,this.dirty=!0),this.updateText(!0),t.prototype._render.call(this,e)},e.prototype._renderCanvas=function(e){this._autoResolution&&this._resolution!==e.resolution&&(this._resolution=e.resolution,this.dirty=!0),this.updateText(!0),t.prototype._renderCanvas.call(this,e)},e.prototype.getLocalBounds=function(e){return this.updateText(!0),t.prototype.getLocalBounds.call(this,e)},e.prototype._calculateBounds=function(){this.updateText(!0),this.calculateVertices(),this._bounds.addQuad(this.vertexData)},e.prototype._onStyleChange=function(){this.dirty=!0},e.prototype.destroy=function(e){void 0===e&&(e=!0),t.prototype.destroy.call(this,e),this.context=null,this.canvas.width=this.canvas.height=0,this.canvas=null,this._style=null,this._parser=null,this._image.onload=null,this._image.src="",this._image=null},h.width.get=function(){return this.updateText(!0),Math.abs(this.scale.x)*this._texture.orig.width},h.width.set=function(t){this.updateText(!0);var e=n.sign(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t},h.height.get=function(){return this.updateText(!0),Math.abs(this.scale.y)*this._texture.orig.height},h.height.set=function(t){this.updateText(!0);var e=n.sign(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t},h.style.get=function(){return this._style},h.style.set=function(t){(t=t||{})instanceof r.TextStyle?this._style=t:this._style=new r.TextStyle(t),this.localStyleID=-1,this.dirty=!0},h.text.get=function(){return this._text},h.text.set=function(t){t=String(""===t||null==t?" ":t),t=this.sanitiseText(t),this._text!==t&&(this._text=t,this.dirty=!0)},h.resolution.get=function(){return this._resolution},h.resolution.set=function(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)},e.prototype.sanitiseText=function(t){return t.replace(/<br>/gi,"<br/>").replace(/<hr>/gi,"<hr/>").replace(/ /gi," ")},Object.defineProperties(e.prototype,h),e}(e.Sprite);return t.HTMLText=h,t}({},PIXI,PIXI,PIXI,PIXI,PIXI.utils,PIXI);Object.assign(PIXI,_pixi_htmltext); | ||
var _pixi_htmltext=function(t,e,i,o,s,n,r){"use strict";var h=function(t){function e(e,n,r){void 0===e&&(e=""),void 0===n&&(n={}),(r=r||document.createElement("canvas")).width=3,r.height=3;var h=o.Texture.from(r,{scaleMode:i.settings.SCALE_MODE});h.orig=new s.Rectangle,h.trim=new s.Rectangle,t.call(this,h);var a="http://www.w3.org/2000/svg",l=document.createElementNS(a,"svg"),d=document.createElementNS(a,"foreignObject"),u=document.createElementNS("http://www.w3.org/1999/xhtml","div");d.setAttribute("height","100%"),d.setAttribute("width","100%"),l.appendChild(d),this._domElement=u,this._svgRoot=l,this._foreignObject=d,this._image=new Image,this.canvas=r,this.context=this.canvas.getContext("2d"),this._resolution=i.settings.RESOLUTION,this._autoResolution=!0,this._text=null,this._style=null,this._loading=!1,this.text=e,this.style=n,this.localStyleID=-1}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var h={width:{configurable:!0},height:{configurable:!0},style:{configurable:!0},text:{configurable:!0},resolution:{configurable:!0}};return e.prototype.updateText=function(t){var e=this,i=this.style,o=this.canvas,s=this.context,r=this.resolution;if(this.localStyleID!==i.styleID&&(this.dirty=!0,this.localStyleID=i.styleID),this.dirty||!t){var h="\n display:inline-block;\n color:"+i.fill+";\n font-size: "+i.fontSize+"px;\n font-family:"+i.fontFamily+";\n font-weight:"+i.fontWeight+";\n font-style:"+i.fontStyle+";\n font-variant:"+i.fontVariant+";\n letter-spacing:"+i.letterSpacing+"px;\n text-align:"+i.align+";\n padding:"+i.padding+"px;\n ";if(i.lineHeight&&(h+="line-height:"+i.lineHeight+"px;"),i.wordWrap&&(h+="word-wrap:"+(i.breakWords?"break-all":"break-word")+";",h+="width:"+i.wordWrapWidth+"px;"),i.strokeThickness){var a=i.stroke;"number"==typeof color&&(a=n.hex2string(a)),h+="-webkit-text-stroke-width: "+i.strokeThickness+"px;",h+="-webkit-text-stroke-color: "+a+";",h+="text-stroke-width: "+i.strokeThickness+"px;",h+="text-stroke-color: "+a+";",h+="paint-order: stroke;"}if(i.dropShadow){var l=i.dropShadowAngle,d=i.dropShadowDistance,u=i.dropShadowBlur,c=i.dropShadowColor,g=i.dropShadowAlpha,p=Math.round(Math.cos(l)*d),x=Math.round(Math.sin(l)*d),_=c;if("number"==typeof _&&(_=n.hex2string(_)),"#"===_.charAt(0)&&g<1){var y=n.hex2rgb(parseInt(_.replace("#",""),16));_="rgba("+(255*y[0]|0)+", "+(255*y[1]|0)+", "+(255*y[2]|0)+", "+g+")"}h+="text-shadow: "+p+"px "+x+"px "+u+"px "+_+";"}var f=this._domElement;Object.assign(f,{innerHTML:this._text,style:h}),document.body.appendChild(f);var w=f.getBoundingClientRect(),m=w.width,v=w.height;if(document.body.removeChild(f),this._foreignObject.appendChild(f),this._svgRoot.setAttribute("width",m),this._svgRoot.setAttribute("height",v),o.width=Math.ceil((Math.max(1,m)+2*i.padding)*r),o.height=Math.ceil((Math.max(1,v)+2*i.padding)*r),!this._loading){var b=this._image,I=(new XMLSerializer).serializeToString(this._svgRoot);this._loading=!0,b.src="data:image/svg+xml;charset=utf8,"+encodeURIComponent(I),b.onload=function(){s.scale(r,r),s.clearRect(0,0,o.width,o.height),s.drawImage(b,0,0,m,v,0,0,m,v),b.src="",b.onload=void 0,e._loading=!1,e.updateTexture()}}}},e.prototype.updateTexture=function(){var t=this.canvas,e=this.context,i=this.style,o=this.texture,s=this.resolution;if(i.trim){var r=n.trimCanvas(t),h=r.width,a=r.height,l=r.data;l&&(t.width=h,t.height=a,e.putImageData(l,0,0))}var d=i.trim?0:i.padding,u=o.baseTexture;o.trim.width=o._frame.width=Math.ceil(t.width/s),o.trim.height=o._frame.height=Math.ceil(t.height/s),o.trim.x=-d,o.trim.y=-d,o.orig.width=o._frame.width-2*d,o.orig.height=o._frame.height-2*d,this._onTextureUpdate(),u.setRealSize(t.width,t.height,s),this.dirty=!1},e.prototype._render=function(e){this._autoResolution&&this._resolution!==e.resolution&&(this._resolution=e.resolution,this.dirty=!0),this.updateText(!0),t.prototype._render.call(this,e)},e.prototype._renderCanvas=function(e){this._autoResolution&&this._resolution!==e.resolution&&(this._resolution=e.resolution,this.dirty=!0),this.updateText(!0),t.prototype._renderCanvas.call(this,e)},e.prototype.getLocalBounds=function(e){return this.updateText(!0),t.prototype.getLocalBounds.call(this,e)},e.prototype._calculateBounds=function(){this.updateText(!0),this.calculateVertices(),this._bounds.addQuad(this.vertexData)},e.prototype._onStyleChange=function(){this.dirty=!0},e.prototype.destroy=function(e){void 0===e&&(e=!0),t.prototype.destroy.call(this,e),this.context=null,this.canvas.width=this.canvas.height=0,this.canvas=null,this._style=null,this._svgRoot=null,this._domElement=null,this._foreignObject=null,this._image.onload=null,this._image.src="",this._image=null},h.width.get=function(){return this.updateText(!0),Math.abs(this.scale.x)*this._texture.orig.width},h.width.set=function(t){this.updateText(!0);var e=n.sign(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t},h.height.get=function(){return this.updateText(!0),Math.abs(this.scale.y)*this._texture.orig.height},h.height.set=function(t){this.updateText(!0);var e=n.sign(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t},h.style.get=function(){return this._style},h.style.set=function(t){(t=t||{})instanceof r.TextStyle?this._style=t:this._style=new r.TextStyle(t),this.localStyleID=-1,this.dirty=!0},h.text.get=function(){return this._text},h.text.set=function(t){t=String(""===t||null==t?" ":t),t=this.sanitiseText(t),this._text!==t&&(this._text=t,this.dirty=!0)},h.resolution.get=function(){return this._resolution},h.resolution.set=function(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)},e.prototype.sanitiseText=function(t){return t.replace(/<br>/gi,"<br/>").replace(/<hr>/gi,"<hr/>").replace(/ /gi," ")},Object.defineProperties(e.prototype,h),e}(e.Sprite);return t.HTMLText=h,t}({},PIXI,PIXI,PIXI,PIXI,PIXI.utils,PIXI);Object.assign(PIXI,_pixi_htmltext); | ||
//# sourceMappingURL=html-text.js.map |
{ | ||
"name": "@pixi/text-html", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Multi-Style Text Rendering Plugin for PixiJS", | ||
@@ -5,0 +5,0 @@ "main": "dist/html-text.cjs.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80897
51896
105