@pixi/text-html
Advanced tools
Comparing version 3.2.0 to 3.2.1
"use strict";/*! | ||
* @pixi/text-html - v3.2.0 | ||
* Compiled Wed, 21 Dec 2022 19:41:58 UTC | ||
* @pixi/text-html - v3.2.1 | ||
* Compiled Thu, 05 Jan 2023 15:08:11 UTC | ||
* | ||
* @pixi/text-html is licensed under the MIT License. | ||
* http://www.opensource.org/licenses/mit-license | ||
*/Object.defineProperty(exports,"__esModule",{value:!0});var w=require("@pixi/sprite"),h=require("@pixi/core"),f=require("@pixi/text"),S=Object.defineProperty,T=Object.defineProperties,b=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,v=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable,x=(t,e,i)=>e in t?S(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,L=(t,e)=>{for(var i in e||(e={}))v.call(e,i)&&x(t,i,e[i]);if(_)for(var i of _(e))M.call(e,i)&&x(t,i,e[i]);return t},O=(t,e)=>T(t,b(e));const d=class extends f.TextStyle{constructor(){super(...arguments),this._fonts=[],this._overrides=[],this._stylesheet="",this.fontsDirty=!1}static from(t){return new d(Object.keys(d.defaultOptions).reduce((e,i)=>O(L({},e),{[i]:t[i]}),{}))}cleanFonts(){this._fonts.length>0&&(this._fonts.forEach(t=>{URL.revokeObjectURL(t.src),t.refs--,t.refs===0&&(t.fontFace&&document.fonts.delete(t.fontFace),delete d.availableFonts[t.originalUrl])}),this.fontFamily="Arial",this._fonts.length=0,this.styleID++,this.fontsDirty=!0)}loadFont(t,e={}){const{availableFonts:i}=d;if(i[t]){const s=i[t];return this._fonts.push(s),s.refs++,this.styleID++,this.fontsDirty=!0,Promise.resolve()}return h.settings.ADAPTER.fetch(t).then(s=>s.blob()).then(async s=>new Promise((o,r)=>{const l=URL.createObjectURL(s),n=new FileReader;n.onload=()=>o([l,n.result]),n.onerror=r,n.readAsDataURL(s)})).then(async([s,o])=>{const r=Object.assign({family:h.utils.path.basename(t,h.utils.path.extname(t)),weight:"normal",style:"normal",src:s,dataSrc:o,refs:1,originalUrl:t,fontFace:null},e);i[t]=r,this._fonts.push(r),this.styleID++;const l=new FontFace(r.family,`url(${r.src})`,{weight:r.weight,style:r.style});r.fontFace=l,await l.load(),document.fonts.add(l),await document.fonts.ready,this.styleID++,this.fontsDirty=!0})}addOverride(...t){const e=t.filter(i=>!this._overrides.includes(i));e.length>0&&(this._overrides.push(...e),this.styleID++)}removeOverride(...t){const e=t.filter(i=>this._overrides.includes(i));e.length>0&&(this._overrides=this._overrides.filter(i=>!e.includes(i)),this.styleID++)}toCSS(t){return["display: inline-block",`color: ${this.normalizeColor(this.fill)}`,`font-size: ${this.fontSize*t}px`,`font-family: ${this.fontFamily}`,`font-weight: ${this.fontWeight}`,`font-style: ${this.fontStyle}`,`font-variant: ${this.fontVariant}`,`letter-spacing: ${this.letterSpacing*t}px`,`text-align: ${this.align}`,`padding: ${this.padding*t}px`,`white-space: ${this.whiteSpace}`,...this.lineHeight?[`line-height: ${this.lineHeight*t}px`]:[],...this.wordWrap?[`word-wrap: ${this.breakWords?"break-all":"break-word"}`,`max-width: ${this.wordWrapWidth*t}px`]:[],...this.strokeThickness?[`-webkit-text-stroke-width: ${this.strokeThickness*t}px`,`-webkit-text-stroke-color: ${this.normalizeColor(this.stroke)}`,`text-stroke-width: ${this.strokeThickness*t}px`,`text-stroke-color: ${this.normalizeColor(this.stroke)}`,"paint-order: stroke"]:[],...this.dropShadow?[this.dropShadowToCSS(t)]:[],...this._overrides].join(";")}toGlobalCSS(){return this._fonts.reduce((t,e)=>`${t} | ||
*/Object.defineProperty(exports,"__esModule",{value:!0});var x=require("@pixi/sprite"),l=require("@pixi/core"),m=require("@pixi/text"),w=Object.defineProperty,S=Object.defineProperties,T=Object.getOwnPropertyDescriptors,f=Object.getOwnPropertySymbols,b=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable,_=(t,e,i)=>e in t?w(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,M=(t,e)=>{for(var i in e||(e={}))b.call(e,i)&&_(t,i,e[i]);if(f)for(var i of f(e))v.call(e,i)&&_(t,i,e[i]);return t},L=(t,e)=>S(t,T(e));const d=class extends m.TextStyle{constructor(){super(...arguments),this._fonts=[],this._overrides=[],this._stylesheet="",this.fontsDirty=!1}static from(t){return new d(Object.keys(d.defaultOptions).reduce((e,i)=>L(M({},e),{[i]:t[i]}),{}))}cleanFonts(){this._fonts.length>0&&(this._fonts.forEach(t=>{URL.revokeObjectURL(t.src),t.refs--,t.refs===0&&(t.fontFace&&document.fonts.delete(t.fontFace),delete d.availableFonts[t.originalUrl])}),this.fontFamily="Arial",this._fonts.length=0,this.styleID++,this.fontsDirty=!0)}loadFont(t,e={}){const{availableFonts:i}=d;if(i[t]){const s=i[t];return this._fonts.push(s),s.refs++,this.styleID++,this.fontsDirty=!0,Promise.resolve()}return l.settings.ADAPTER.fetch(t).then(s=>s.blob()).then(async s=>new Promise((o,r)=>{const n=URL.createObjectURL(s),h=new FileReader;h.onload=()=>o([n,h.result]),h.onerror=r,h.readAsDataURL(s)})).then(async([s,o])=>{const r=Object.assign({family:l.utils.path.basename(t,l.utils.path.extname(t)),weight:"normal",style:"normal",src:s,dataSrc:o,refs:1,originalUrl:t,fontFace:null},e);i[t]=r,this._fonts.push(r),this.styleID++;const n=new FontFace(r.family,`url(${r.src})`,{weight:r.weight,style:r.style});r.fontFace=n,await n.load(),document.fonts.add(n),await document.fonts.ready,this.styleID++,this.fontsDirty=!0})}addOverride(...t){const e=t.filter(i=>!this._overrides.includes(i));e.length>0&&(this._overrides.push(...e),this.styleID++)}removeOverride(...t){const e=t.filter(i=>this._overrides.includes(i));e.length>0&&(this._overrides=this._overrides.filter(i=>!e.includes(i)),this.styleID++)}toCSS(t){return["display: inline-block",`color: ${this.normalizeColor(this.fill)}`,`font-size: ${this.fontSize*t}px`,`font-family: ${this.fontFamily}`,`font-weight: ${this.fontWeight}`,`font-style: ${this.fontStyle}`,`font-variant: ${this.fontVariant}`,`letter-spacing: ${this.letterSpacing*t}px`,`text-align: ${this.align}`,`padding: ${this.padding*t}px`,`white-space: ${this.whiteSpace}`,...this.lineHeight?[`line-height: ${this.lineHeight*t}px`]:[],...this.wordWrap?[`word-wrap: ${this.breakWords?"break-all":"break-word"}`,`max-width: ${this.wordWrapWidth*t}px`]:[],...this.strokeThickness?[`-webkit-text-stroke-width: ${this.strokeThickness*t}px`,`-webkit-text-stroke-color: ${this.normalizeColor(this.stroke)}`,`text-stroke-width: ${this.strokeThickness*t}px`,`text-stroke-color: ${this.normalizeColor(this.stroke)}`,"paint-order: stroke"]:[],...this.dropShadow?[this.dropShadowToCSS(t)]:[],...this._overrides].join(";")}toGlobalCSS(){return this._fonts.reduce((t,e)=>`${t} | ||
@font-face { | ||
@@ -13,3 +13,3 @@ font-family: "${e.family}"; | ||
font-style: ${e.style}; | ||
}`,this._stylesheet)}get stylesheet(){return this._stylesheet}set stylesheet(t){this._stylesheet!==t&&(this._stylesheet=t,this.styleID++)}normalizeColor(t){return Array.isArray(t)&&(t=h.utils.rgb2hex(t)),typeof t=="number"?h.utils.hex2string(t):t}dropShadowToCSS(t){let e=this.normalizeColor(this.dropShadowColor);const i=this.dropShadowAlpha,s=Math.round(Math.cos(this.dropShadowAngle)*this.dropShadowDistance),o=Math.round(Math.sin(this.dropShadowAngle)*this.dropShadowDistance);e.startsWith("#")&&i<1&&(e+=(i*255|0).toString(16).padStart(2,"0"));const r=`${s*t}px ${o*t}px`;return this.dropShadowBlur>0?`text-shadow: ${r} ${this.dropShadowBlur}px ${e}`:`text-shadow: ${r} ${e}`}reset(){Object.assign(this,d.defaultOptions)}onBeforeDraw(){const{fontsDirty:t}=this;return this.fontsDirty=!1,this.isSafari&&this._fonts.length>0&&t?new Promise(e=>setTimeout(e,100)):Promise.resolve()}get isSafari(){const{userAgent:t}=h.settings.ADAPTER.getNavigator();return/^((?!chrome|android).)*safari/i.test(t)}set fillGradientStops(t){console.warn("[HTMLTextStyle] fillGradientStops is not supported by HTMLText")}get fillGradientStops(){return super.fillGradientStops}set fillGradientType(t){console.warn("[HTMLTextStyle] fillGradientType is not supported by HTMLText")}get fillGradientType(){return super.fillGradientType}set miterLimit(t){console.warn("[HTMLTextStyle] miterLimit is not supported by HTMLText")}get miterLimit(){return super.miterLimit}set trim(t){console.warn("[HTMLTextStyle] trim is not supported by HTMLText")}get trim(){return super.trim}set textBaseline(t){console.warn("[HTMLTextStyle] textBaseline is not supported by HTMLText")}get textBaseline(){return super.textBaseline}set leading(t){console.warn("[HTMLTextStyle] leading is not supported by HTMLText")}get leading(){return super.leading}set lineJoin(t){console.warn("[HTMLTextStyle] lineJoin is not supported by HTMLText")}get lineJoin(){return super.lineJoin}};let u=d;u.availableFonts={},u.defaultOptions={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",letterSpacing:0,lineHeight:0,padding:0,stroke:"black",strokeThickness:0,whiteSpace:"normal",wordWrap:!1,wordWrapWidth:100};const c=class extends w.Sprite{constructor(t="",e={}){var i;const s=new Image,o=h.Texture.from(s,{scaleMode:h.settings.SCALE_MODE,resourceOptions:{autoLoad:!1}});o.orig=new h.Rectangle,o.trim=new h.Rectangle,super(o),this._text=null,this._style=null,this._autoResolution=!0,this._loading=!1,this.localStyleID=-1,this.dirty=!1,this.ownsStyle=!1;const r="http://www.w3.org/2000/svg",l="http://www.w3.org/1999/xhtml",n=document.createElement("div"),a=document.createElementNS(r,"svg"),p=document.createElementNS(r,"foreignObject"),y=document.createElementNS(l,"div"),m=document.createElementNS(l,"style");p.setAttribute("width","10000"),p.setAttribute("height","10000"),p.style.overflow="hidden",a.appendChild(p),this.maxWidth=c.defaultMaxWidth,this.maxHeight=c.defaultMaxHeight,this._shadow=n,this._domElement=y,this._styleElement=m,this._svgRoot=a,this._foreignObject=p,this._foreignObject.appendChild(m),this._foreignObject.appendChild(y),this._image=s,this._autoResolution=c.defaultAutoResolution,this._shadowRoot=n.attachShadow({mode:"open"}),this._shadowRoot.appendChild(a),n.setAttribute("data-pixi-html-text","1"),Object.assign(n.style,{position:"absolute",top:"0",left:"-1px",width:"1px",height:"1px"}),document.body.appendChild(n),this._resolution=(i=c.defaultResolution)!=null?i:h.settings.RESOLUTION,this.text=t,this.style=e}measureText(t){var e,i;const{text:s,style:o,resolution:r}=Object.assign({text:this._text,style:this._style,resolution:this._resolution},t);Object.assign(this._domElement,{innerHTML:s,style:o.toCSS(r)}),this._styleElement.textContent=o.toGlobalCSS();const l=this._domElement.getBoundingClientRect(),n=Math.min(this.maxWidth,Math.ceil(l.width)),a=Math.min(this.maxHeight,Math.ceil(l.height));return this._svgRoot.setAttribute("width",n.toString()),this._svgRoot.setAttribute("height",a.toString()),s!==this._text&&(this._domElement.innerHTML=this._text),o!==this._style&&(Object.assign(this._domElement,{style:(e=this._style)==null?void 0:e.toCSS(r)}),this._styleElement.textContent=(i=this._style)==null?void 0:i.toGlobalCSS()),{width:n+o.padding*2,height:a+o.padding*2}}async updateText(t=!0){const{style:e,_image:i}=this;if(this.localStyleID!==e.styleID&&(this.dirty=!0,this.localStyleID=e.styleID),!this.dirty&&t)return;const{width:s,height:o}=this.measureText();i.width=Math.ceil(Math.max(1,s)),i.height=Math.ceil(Math.max(1,o)),this._loading||(this._loading=!0,await new Promise(r=>{i.onload=async()=>{await e.onBeforeDraw(),this._loading=!1,this.updateTexture(),r()};const l=new XMLSerializer().serializeToString(this._svgRoot);i.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(l)}`}))}get source(){return this._image}get canvas(){return h.utils.deprecation("3.2.0",'HTMLText property "canvas" is deprecated, use "source" instead.'),this._image}updateTexture(){const{style:t,texture:e,_image:i,resolution:s}=this,{padding:o}=t,{baseTexture:r}=e;e.trim.width=e._frame.width=i.width/s,e.trim.height=e._frame.height=i.height/s,e.trim.x=-o,e.trim.y=-o,e.orig.width=e._frame.width-o*2,e.orig.height=e._frame.height-o*2,this._onTextureUpdate(),r.setRealSize(i.width,i.height,s),this.dirty=!1}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._render(t)}_renderCanvas(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._renderCanvas(t)}getLocalBounds(t){return this.updateText(!0),super.getLocalBounds(t)}_calculateBounds(){this.updateText(!0),this.calculateVertices(),this._bounds.addQuad(this.vertexData)}_onStyleChange(){this.dirty=!0}destroy(t){var e,i,s,o,r,l;typeof t=="boolean"&&(t={children:t}),t=Object.assign({},c.defaultDestroyOptions,t),super.destroy(t);const n=null;this.ownsStyle&&((e=this._style)==null||e.cleanFonts()),this._style=n,(i=this._svgRoot)==null||i.remove(),this._svgRoot=n,(s=this._domElement)==null||s.remove(),this._domElement=n,(o=this._foreignObject)==null||o.remove(),this._foreignObject=n,(r=this._styleElement)==null||r.remove(),this._styleElement=n,(l=this._shadow)==null||l.remove(),this._shadow=n,this._shadowRoot=n,this._image.onload=null,this._image.src="",this._image=n}get width(){return this.updateText(!0),Math.abs(this.scale.x)*this._image.width/this.resolution}set width(t){this.updateText(!0);const e=h.utils.sign(this.scale.x)||1;this.scale.x=e*t/this._image.width/this.resolution,this._width=t}get height(){return this.updateText(!0),Math.abs(this.scale.y)*this._image.height/this.resolution}set height(t){this.updateText(!0);const e=h.utils.sign(this.scale.y)||1;this.scale.y=e*t/this._image.height/this.resolution,this._height=t}get style(){return this._style}set style(t){this._style!==t&&(t=t||{},t instanceof u?(this.ownsStyle=!1,this._style=t):t instanceof f.TextStyle?(console.warn("[HTMLText] Cloning TextStyle, if this is not what you want, use HTMLTextStyle"),this.ownsStyle=!0,this._style=u.from(t)):(this.ownsStyle=!0,this._style=new u(t)),this.localStyleID=-1,this.dirty=!0)}get text(){return this._text}set text(t){t=String(t===""||t===null||t===void 0?" ":t),t=this.sanitiseText(t),this._text!==t&&(this._text=t,this.dirty=!0)}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}sanitiseText(t){return t.replace(/<br>/gi,"<br/>").replace(/<hr>/gi,"<hr/>").replace(/ /gi," ")}};let g=c;g.defaultDestroyOptions={texture:!0,children:!1,baseTexture:!0},g.defaultMaxWidth=2024,g.defaultMaxHeight=2024,g.defaultAutoResolution=!0,exports.HTMLText=g,exports.HTMLTextStyle=u; | ||
}`,this._stylesheet)}get stylesheet(){return this._stylesheet}set stylesheet(t){this._stylesheet!==t&&(this._stylesheet=t,this.styleID++)}normalizeColor(t){return Array.isArray(t)&&(t=l.utils.rgb2hex(t)),typeof t=="number"?l.utils.hex2string(t):t}dropShadowToCSS(t){let e=this.normalizeColor(this.dropShadowColor);const i=this.dropShadowAlpha,s=Math.round(Math.cos(this.dropShadowAngle)*this.dropShadowDistance),o=Math.round(Math.sin(this.dropShadowAngle)*this.dropShadowDistance);e.startsWith("#")&&i<1&&(e+=(i*255|0).toString(16).padStart(2,"0"));const r=`${s*t}px ${o*t}px`;return this.dropShadowBlur>0?`text-shadow: ${r} ${this.dropShadowBlur}px ${e}`:`text-shadow: ${r} ${e}`}reset(){Object.assign(this,d.defaultOptions)}onBeforeDraw(){const{fontsDirty:t}=this;return this.fontsDirty=!1,this.isSafari&&this._fonts.length>0&&t?new Promise(e=>setTimeout(e,100)):Promise.resolve()}get isSafari(){const{userAgent:t}=l.settings.ADAPTER.getNavigator();return/^((?!chrome|android).)*safari/i.test(t)}set fillGradientStops(t){console.warn("[HTMLTextStyle] fillGradientStops is not supported by HTMLText")}get fillGradientStops(){return super.fillGradientStops}set fillGradientType(t){console.warn("[HTMLTextStyle] fillGradientType is not supported by HTMLText")}get fillGradientType(){return super.fillGradientType}set miterLimit(t){console.warn("[HTMLTextStyle] miterLimit is not supported by HTMLText")}get miterLimit(){return super.miterLimit}set trim(t){console.warn("[HTMLTextStyle] trim is not supported by HTMLText")}get trim(){return super.trim}set textBaseline(t){console.warn("[HTMLTextStyle] textBaseline is not supported by HTMLText")}get textBaseline(){return super.textBaseline}set leading(t){console.warn("[HTMLTextStyle] leading is not supported by HTMLText")}get leading(){return super.leading}set lineJoin(t){console.warn("[HTMLTextStyle] lineJoin is not supported by HTMLText")}get lineJoin(){return super.lineJoin}};let u=d;u.availableFonts={},u.defaultOptions={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",letterSpacing:0,lineHeight:0,padding:0,stroke:"black",strokeThickness:0,whiteSpace:"normal",wordWrap:!1,wordWrapWidth:100};const c=class extends x.Sprite{constructor(t="",e={}){var i;const s=new Image,o=l.Texture.from(s,{scaleMode:l.settings.SCALE_MODE,resourceOptions:{autoLoad:!1}});o.orig=new l.Rectangle,o.trim=new l.Rectangle,super(o),this._text=null,this._style=null,this._autoResolution=!0,this._loading=!1,this.localStyleID=-1,this.dirty=!1,this.ownsStyle=!1;const r="http://www.w3.org/2000/svg",n="http://www.w3.org/1999/xhtml",h=document.createElementNS(r,"svg"),a=document.createElementNS(r,"foreignObject"),p=document.createElementNS(n,"div"),y=document.createElementNS(n,"style");a.setAttribute("width","10000"),a.setAttribute("height","10000"),a.style.overflow="hidden",h.appendChild(a),this.maxWidth=c.defaultMaxWidth,this.maxHeight=c.defaultMaxHeight,this._domElement=p,this._styleElement=y,this._svgRoot=h,this._foreignObject=a,this._foreignObject.appendChild(y),this._foreignObject.appendChild(p),this._image=s,this._autoResolution=c.defaultAutoResolution,this._resolution=(i=c.defaultResolution)!=null?i:l.settings.RESOLUTION,this.text=t,this.style=e}measureText(t){var e,i;const{text:s,style:o,resolution:r}=Object.assign({text:this._text,style:this._style,resolution:this._resolution},t);Object.assign(this._domElement,{innerHTML:s,style:o.toCSS(r)}),this._styleElement.textContent=o.toGlobalCSS(),document.body.appendChild(this._svgRoot);const n=this._domElement.getBoundingClientRect();this._svgRoot.remove();const h=Math.min(this.maxWidth,Math.ceil(n.width)),a=Math.min(this.maxHeight,Math.ceil(n.height));return this._svgRoot.setAttribute("width",h.toString()),this._svgRoot.setAttribute("height",a.toString()),s!==this._text&&(this._domElement.innerHTML=this._text),o!==this._style&&(Object.assign(this._domElement,{style:(e=this._style)==null?void 0:e.toCSS(r)}),this._styleElement.textContent=(i=this._style)==null?void 0:i.toGlobalCSS()),{width:h+o.padding*2,height:a+o.padding*2}}async updateText(t=!0){const{style:e,_image:i}=this;if(this.localStyleID!==e.styleID&&(this.dirty=!0,this.localStyleID=e.styleID),!this.dirty&&t)return;const{width:s,height:o}=this.measureText();i.width=Math.ceil(Math.max(1,s)),i.height=Math.ceil(Math.max(1,o)),this._loading||(this._loading=!0,await new Promise(r=>{i.onload=async()=>{await e.onBeforeDraw(),this._loading=!1,this.updateTexture(),r()};const n=new XMLSerializer().serializeToString(this._svgRoot);i.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(n)}`}))}get source(){return this._image}get canvas(){return l.utils.deprecation("3.2.0",'HTMLText property "canvas" is deprecated, use "source" instead.'),this._image}updateTexture(){const{style:t,texture:e,_image:i,resolution:s}=this,{padding:o}=t,{baseTexture:r}=e;e.trim.width=e._frame.width=i.width/s,e.trim.height=e._frame.height=i.height/s,e.trim.x=-o,e.trim.y=-o,e.orig.width=e._frame.width-o*2,e.orig.height=e._frame.height-o*2,this._onTextureUpdate(),r.setRealSize(i.width,i.height,s),this.dirty=!1}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._render(t)}_renderCanvas(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._renderCanvas(t)}getLocalBounds(t){return this.updateText(!0),super.getLocalBounds(t)}_calculateBounds(){this.updateText(!0),this.calculateVertices(),this._bounds.addQuad(this.vertexData)}_onStyleChange(){this.dirty=!0}destroy(t){var e,i,s,o,r;typeof t=="boolean"&&(t={children:t}),t=Object.assign({},c.defaultDestroyOptions,t),super.destroy(t);const n=null;this.ownsStyle&&((e=this._style)==null||e.cleanFonts()),this._style=n,(i=this._svgRoot)==null||i.remove(),this._svgRoot=n,(s=this._domElement)==null||s.remove(),this._domElement=n,(o=this._foreignObject)==null||o.remove(),this._foreignObject=n,(r=this._styleElement)==null||r.remove(),this._styleElement=n,this._image.onload=null,this._image.src="",this._image=n}get width(){return this.updateText(!0),Math.abs(this.scale.x)*this._image.width/this.resolution}set width(t){this.updateText(!0);const e=l.utils.sign(this.scale.x)||1;this.scale.x=e*t/this._image.width/this.resolution,this._width=t}get height(){return this.updateText(!0),Math.abs(this.scale.y)*this._image.height/this.resolution}set height(t){this.updateText(!0);const e=l.utils.sign(this.scale.y)||1;this.scale.y=e*t/this._image.height/this.resolution,this._height=t}get style(){return this._style}set style(t){this._style!==t&&(t=t||{},t instanceof u?(this.ownsStyle=!1,this._style=t):t instanceof m.TextStyle?(console.warn("[HTMLText] Cloning TextStyle, if this is not what you want, use HTMLTextStyle"),this.ownsStyle=!0,this._style=u.from(t)):(this.ownsStyle=!0,this._style=new u(t)),this.localStyleID=-1,this.dirty=!0)}get text(){return this._text}set text(t){t=String(t===""||t===null||t===void 0?" ":t),t=this.sanitiseText(t),this._text!==t&&(this._text=t,this.dirty=!0)}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}sanitiseText(t){return t.replace(/<br>/gi,"<br/>").replace(/<hr>/gi,"<hr/>").replace(/ /gi," ")}};let g=c;g.defaultDestroyOptions={texture:!0,children:!1,baseTexture:!0},g.defaultMaxWidth=2024,g.defaultMaxHeight=2024,g.defaultAutoResolution=!0,exports.HTMLText=g,exports.HTMLTextStyle=u; | ||
//# sourceMappingURL=html-text.cjs.js.map |
@@ -52,4 +52,2 @@ import type { IDestroyOptions } from '@pixi/display'; | ||
private _loading; | ||
private _shadow; | ||
private _shadowRoot; | ||
private localStyleID; | ||
@@ -56,0 +54,0 @@ private dirty; |
/*! | ||
* @pixi/text-html - v3.2.0 | ||
* Compiled Wed, 21 Dec 2022 19:41:58 UTC | ||
* @pixi/text-html - v3.2.1 | ||
* Compiled Thu, 05 Jan 2023 15:08:11 UTC | ||
* | ||
* @pixi/text-html is licensed under the MIT License. | ||
* http://www.opensource.org/licenses/mit-license | ||
*/var _pixi_htmltext=function(y,S,h,m){"use strict";var T=Object.defineProperty,b=Object.defineProperties,v=Object.getOwnPropertyDescriptors,f=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable,_=(t,e,s)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,O=(t,e)=>{for(var s in e||(e={}))M.call(e,s)&&_(t,s,e[s]);if(f)for(var s of f(e))L.call(e,s)&&_(t,s,e[s]);return t},D=(t,e)=>b(t,v(e));const a=class extends m.TextStyle{constructor(){super(...arguments),this._fonts=[],this._overrides=[],this._stylesheet="",this.fontsDirty=!1}static from(t){return new a(Object.keys(a.defaultOptions).reduce((e,s)=>D(O({},e),{[s]:t[s]}),{}))}cleanFonts(){this._fonts.length>0&&(this._fonts.forEach(t=>{URL.revokeObjectURL(t.src),t.refs--,t.refs===0&&(t.fontFace&&document.fonts.delete(t.fontFace),delete a.availableFonts[t.originalUrl])}),this.fontFamily="Arial",this._fonts.length=0,this.styleID++,this.fontsDirty=!0)}loadFont(t,e={}){const{availableFonts:s}=a;if(s[t]){const i=s[t];return this._fonts.push(i),i.refs++,this.styleID++,this.fontsDirty=!0,Promise.resolve()}return h.settings.ADAPTER.fetch(t).then(i=>i.blob()).then(async i=>new Promise((o,n)=>{const l=URL.createObjectURL(i),r=new FileReader;r.onload=()=>o([l,r.result]),r.onerror=n,r.readAsDataURL(i)})).then(async([i,o])=>{const n=Object.assign({family:h.utils.path.basename(t,h.utils.path.extname(t)),weight:"normal",style:"normal",src:i,dataSrc:o,refs:1,originalUrl:t,fontFace:null},e);s[t]=n,this._fonts.push(n),this.styleID++;const l=new FontFace(n.family,`url(${n.src})`,{weight:n.weight,style:n.style});n.fontFace=l,await l.load(),document.fonts.add(l),await document.fonts.ready,this.styleID++,this.fontsDirty=!0})}addOverride(...t){const e=t.filter(s=>!this._overrides.includes(s));e.length>0&&(this._overrides.push(...e),this.styleID++)}removeOverride(...t){const e=t.filter(s=>this._overrides.includes(s));e.length>0&&(this._overrides=this._overrides.filter(s=>!e.includes(s)),this.styleID++)}toCSS(t){return["display: inline-block",`color: ${this.normalizeColor(this.fill)}`,`font-size: ${this.fontSize*t}px`,`font-family: ${this.fontFamily}`,`font-weight: ${this.fontWeight}`,`font-style: ${this.fontStyle}`,`font-variant: ${this.fontVariant}`,`letter-spacing: ${this.letterSpacing*t}px`,`text-align: ${this.align}`,`padding: ${this.padding*t}px`,`white-space: ${this.whiteSpace}`,...this.lineHeight?[`line-height: ${this.lineHeight*t}px`]:[],...this.wordWrap?[`word-wrap: ${this.breakWords?"break-all":"break-word"}`,`max-width: ${this.wordWrapWidth*t}px`]:[],...this.strokeThickness?[`-webkit-text-stroke-width: ${this.strokeThickness*t}px`,`-webkit-text-stroke-color: ${this.normalizeColor(this.stroke)}`,`text-stroke-width: ${this.strokeThickness*t}px`,`text-stroke-color: ${this.normalizeColor(this.stroke)}`,"paint-order: stroke"]:[],...this.dropShadow?[this.dropShadowToCSS(t)]:[],...this._overrides].join(";")}toGlobalCSS(){return this._fonts.reduce((t,e)=>`${t} | ||
*/var _pixi_htmltext=function(p,x,l,y){"use strict";var S=Object.defineProperty,T=Object.defineProperties,b=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,v=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable,f=(t,e,s)=>e in t?S(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,L=(t,e)=>{for(var s in e||(e={}))v.call(e,s)&&f(t,s,e[s]);if(m)for(var s of m(e))M.call(e,s)&&f(t,s,e[s]);return t},O=(t,e)=>T(t,b(e));const d=class extends y.TextStyle{constructor(){super(...arguments),this._fonts=[],this._overrides=[],this._stylesheet="",this.fontsDirty=!1}static from(t){return new d(Object.keys(d.defaultOptions).reduce((e,s)=>O(L({},e),{[s]:t[s]}),{}))}cleanFonts(){this._fonts.length>0&&(this._fonts.forEach(t=>{URL.revokeObjectURL(t.src),t.refs--,t.refs===0&&(t.fontFace&&document.fonts.delete(t.fontFace),delete d.availableFonts[t.originalUrl])}),this.fontFamily="Arial",this._fonts.length=0,this.styleID++,this.fontsDirty=!0)}loadFont(t,e={}){const{availableFonts:s}=d;if(s[t]){const i=s[t];return this._fonts.push(i),i.refs++,this.styleID++,this.fontsDirty=!0,Promise.resolve()}return l.settings.ADAPTER.fetch(t).then(i=>i.blob()).then(async i=>new Promise((o,n)=>{const r=URL.createObjectURL(i),h=new FileReader;h.onload=()=>o([r,h.result]),h.onerror=n,h.readAsDataURL(i)})).then(async([i,o])=>{const n=Object.assign({family:l.utils.path.basename(t,l.utils.path.extname(t)),weight:"normal",style:"normal",src:i,dataSrc:o,refs:1,originalUrl:t,fontFace:null},e);s[t]=n,this._fonts.push(n),this.styleID++;const r=new FontFace(n.family,`url(${n.src})`,{weight:n.weight,style:n.style});n.fontFace=r,await r.load(),document.fonts.add(r),await document.fonts.ready,this.styleID++,this.fontsDirty=!0})}addOverride(...t){const e=t.filter(s=>!this._overrides.includes(s));e.length>0&&(this._overrides.push(...e),this.styleID++)}removeOverride(...t){const e=t.filter(s=>this._overrides.includes(s));e.length>0&&(this._overrides=this._overrides.filter(s=>!e.includes(s)),this.styleID++)}toCSS(t){return["display: inline-block",`color: ${this.normalizeColor(this.fill)}`,`font-size: ${this.fontSize*t}px`,`font-family: ${this.fontFamily}`,`font-weight: ${this.fontWeight}`,`font-style: ${this.fontStyle}`,`font-variant: ${this.fontVariant}`,`letter-spacing: ${this.letterSpacing*t}px`,`text-align: ${this.align}`,`padding: ${this.padding*t}px`,`white-space: ${this.whiteSpace}`,...this.lineHeight?[`line-height: ${this.lineHeight*t}px`]:[],...this.wordWrap?[`word-wrap: ${this.breakWords?"break-all":"break-word"}`,`max-width: ${this.wordWrapWidth*t}px`]:[],...this.strokeThickness?[`-webkit-text-stroke-width: ${this.strokeThickness*t}px`,`-webkit-text-stroke-color: ${this.normalizeColor(this.stroke)}`,`text-stroke-width: ${this.strokeThickness*t}px`,`text-stroke-color: ${this.normalizeColor(this.stroke)}`,"paint-order: stroke"]:[],...this.dropShadow?[this.dropShadowToCSS(t)]:[],...this._overrides].join(";")}toGlobalCSS(){return this._fonts.reduce((t,e)=>`${t} | ||
@font-face { | ||
@@ -13,3 +13,3 @@ font-family: "${e.family}"; | ||
font-style: ${e.style}; | ||
}`,this._stylesheet)}get stylesheet(){return this._stylesheet}set stylesheet(t){this._stylesheet!==t&&(this._stylesheet=t,this.styleID++)}normalizeColor(t){return Array.isArray(t)&&(t=h.utils.rgb2hex(t)),typeof t=="number"?h.utils.hex2string(t):t}dropShadowToCSS(t){let e=this.normalizeColor(this.dropShadowColor);const s=this.dropShadowAlpha,i=Math.round(Math.cos(this.dropShadowAngle)*this.dropShadowDistance),o=Math.round(Math.sin(this.dropShadowAngle)*this.dropShadowDistance);e.startsWith("#")&&s<1&&(e+=(s*255|0).toString(16).padStart(2,"0"));const n=`${i*t}px ${o*t}px`;return this.dropShadowBlur>0?`text-shadow: ${n} ${this.dropShadowBlur}px ${e}`:`text-shadow: ${n} ${e}`}reset(){Object.assign(this,a.defaultOptions)}onBeforeDraw(){const{fontsDirty:t}=this;return this.fontsDirty=!1,this.isSafari&&this._fonts.length>0&&t?new Promise(e=>setTimeout(e,100)):Promise.resolve()}get isSafari(){const{userAgent:t}=h.settings.ADAPTER.getNavigator();return/^((?!chrome|android).)*safari/i.test(t)}set fillGradientStops(t){console.warn("[HTMLTextStyle] fillGradientStops is not supported by HTMLText")}get fillGradientStops(){return super.fillGradientStops}set fillGradientType(t){console.warn("[HTMLTextStyle] fillGradientType is not supported by HTMLText")}get fillGradientType(){return super.fillGradientType}set miterLimit(t){console.warn("[HTMLTextStyle] miterLimit is not supported by HTMLText")}get miterLimit(){return super.miterLimit}set trim(t){console.warn("[HTMLTextStyle] trim is not supported by HTMLText")}get trim(){return super.trim}set textBaseline(t){console.warn("[HTMLTextStyle] textBaseline is not supported by HTMLText")}get textBaseline(){return super.textBaseline}set leading(t){console.warn("[HTMLTextStyle] leading is not supported by HTMLText")}get leading(){return super.leading}set lineJoin(t){console.warn("[HTMLTextStyle] lineJoin is not supported by HTMLText")}get lineJoin(){return super.lineJoin}};let d=a;d.availableFonts={},d.defaultOptions={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",letterSpacing:0,lineHeight:0,padding:0,stroke:"black",strokeThickness:0,whiteSpace:"normal",wordWrap:!1,wordWrapWidth:100};const u=class extends S.Sprite{constructor(t="",e={}){var s;const i=new Image,o=h.Texture.from(i,{scaleMode:h.settings.SCALE_MODE,resourceOptions:{autoLoad:!1}});o.orig=new h.Rectangle,o.trim=new h.Rectangle,super(o),this._text=null,this._style=null,this._autoResolution=!0,this._loading=!1,this.localStyleID=-1,this.dirty=!1,this.ownsStyle=!1;const n="http://www.w3.org/2000/svg",l="http://www.w3.org/1999/xhtml",r=document.createElement("div"),c=document.createElementNS(n,"svg"),p=document.createElementNS(n,"foreignObject"),w=document.createElementNS(l,"div"),x=document.createElementNS(l,"style");p.setAttribute("width","10000"),p.setAttribute("height","10000"),p.style.overflow="hidden",c.appendChild(p),this.maxWidth=u.defaultMaxWidth,this.maxHeight=u.defaultMaxHeight,this._shadow=r,this._domElement=w,this._styleElement=x,this._svgRoot=c,this._foreignObject=p,this._foreignObject.appendChild(x),this._foreignObject.appendChild(w),this._image=i,this._autoResolution=u.defaultAutoResolution,this._shadowRoot=r.attachShadow({mode:"open"}),this._shadowRoot.appendChild(c),r.setAttribute("data-pixi-html-text","1"),Object.assign(r.style,{position:"absolute",top:"0",left:"-1px",width:"1px",height:"1px"}),document.body.appendChild(r),this._resolution=(s=u.defaultResolution)!=null?s:h.settings.RESOLUTION,this.text=t,this.style=e}measureText(t){var e,s;const{text:i,style:o,resolution:n}=Object.assign({text:this._text,style:this._style,resolution:this._resolution},t);Object.assign(this._domElement,{innerHTML:i,style:o.toCSS(n)}),this._styleElement.textContent=o.toGlobalCSS();const l=this._domElement.getBoundingClientRect(),r=Math.min(this.maxWidth,Math.ceil(l.width)),c=Math.min(this.maxHeight,Math.ceil(l.height));return this._svgRoot.setAttribute("width",r.toString()),this._svgRoot.setAttribute("height",c.toString()),i!==this._text&&(this._domElement.innerHTML=this._text),o!==this._style&&(Object.assign(this._domElement,{style:(e=this._style)==null?void 0:e.toCSS(n)}),this._styleElement.textContent=(s=this._style)==null?void 0:s.toGlobalCSS()),{width:r+o.padding*2,height:c+o.padding*2}}async updateText(t=!0){const{style:e,_image:s}=this;if(this.localStyleID!==e.styleID&&(this.dirty=!0,this.localStyleID=e.styleID),!this.dirty&&t)return;const{width:i,height:o}=this.measureText();s.width=Math.ceil(Math.max(1,i)),s.height=Math.ceil(Math.max(1,o)),this._loading||(this._loading=!0,await new Promise(n=>{s.onload=async()=>{await e.onBeforeDraw(),this._loading=!1,this.updateTexture(),n()};const l=new XMLSerializer().serializeToString(this._svgRoot);s.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(l)}`}))}get source(){return this._image}get canvas(){return h.utils.deprecation("3.2.0",'HTMLText property "canvas" is deprecated, use "source" instead.'),this._image}updateTexture(){const{style:t,texture:e,_image:s,resolution:i}=this,{padding:o}=t,{baseTexture:n}=e;e.trim.width=e._frame.width=s.width/i,e.trim.height=e._frame.height=s.height/i,e.trim.x=-o,e.trim.y=-o,e.orig.width=e._frame.width-o*2,e.orig.height=e._frame.height-o*2,this._onTextureUpdate(),n.setRealSize(s.width,s.height,i),this.dirty=!1}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._render(t)}_renderCanvas(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._renderCanvas(t)}getLocalBounds(t){return this.updateText(!0),super.getLocalBounds(t)}_calculateBounds(){this.updateText(!0),this.calculateVertices(),this._bounds.addQuad(this.vertexData)}_onStyleChange(){this.dirty=!0}destroy(t){var e,s,i,o,n,l;typeof t=="boolean"&&(t={children:t}),t=Object.assign({},u.defaultDestroyOptions,t),super.destroy(t);const r=null;this.ownsStyle&&((e=this._style)==null||e.cleanFonts()),this._style=r,(s=this._svgRoot)==null||s.remove(),this._svgRoot=r,(i=this._domElement)==null||i.remove(),this._domElement=r,(o=this._foreignObject)==null||o.remove(),this._foreignObject=r,(n=this._styleElement)==null||n.remove(),this._styleElement=r,(l=this._shadow)==null||l.remove(),this._shadow=r,this._shadowRoot=r,this._image.onload=null,this._image.src="",this._image=r}get width(){return this.updateText(!0),Math.abs(this.scale.x)*this._image.width/this.resolution}set width(t){this.updateText(!0);const e=h.utils.sign(this.scale.x)||1;this.scale.x=e*t/this._image.width/this.resolution,this._width=t}get height(){return this.updateText(!0),Math.abs(this.scale.y)*this._image.height/this.resolution}set height(t){this.updateText(!0);const e=h.utils.sign(this.scale.y)||1;this.scale.y=e*t/this._image.height/this.resolution,this._height=t}get style(){return this._style}set style(t){this._style!==t&&(t=t||{},t instanceof d?(this.ownsStyle=!1,this._style=t):t instanceof m.TextStyle?(console.warn("[HTMLText] Cloning TextStyle, if this is not what you want, use HTMLTextStyle"),this.ownsStyle=!0,this._style=d.from(t)):(this.ownsStyle=!0,this._style=new d(t)),this.localStyleID=-1,this.dirty=!0)}get text(){return this._text}set text(t){t=String(t===""||t===null||t===void 0?" ":t),t=this.sanitiseText(t),this._text!==t&&(this._text=t,this.dirty=!0)}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}sanitiseText(t){return t.replace(/<br>/gi,"<br/>").replace(/<hr>/gi,"<hr/>").replace(/ /gi," ")}};let g=u;return g.defaultDestroyOptions={texture:!0,children:!1,baseTexture:!0},g.defaultMaxWidth=2024,g.defaultMaxHeight=2024,g.defaultAutoResolution=!0,y.HTMLText=g,y.HTMLTextStyle=d,y}({},PIXI,PIXI,PIXI);Object.assign(PIXI,_pixi_htmltext); | ||
}`,this._stylesheet)}get stylesheet(){return this._stylesheet}set stylesheet(t){this._stylesheet!==t&&(this._stylesheet=t,this.styleID++)}normalizeColor(t){return Array.isArray(t)&&(t=l.utils.rgb2hex(t)),typeof t=="number"?l.utils.hex2string(t):t}dropShadowToCSS(t){let e=this.normalizeColor(this.dropShadowColor);const s=this.dropShadowAlpha,i=Math.round(Math.cos(this.dropShadowAngle)*this.dropShadowDistance),o=Math.round(Math.sin(this.dropShadowAngle)*this.dropShadowDistance);e.startsWith("#")&&s<1&&(e+=(s*255|0).toString(16).padStart(2,"0"));const n=`${i*t}px ${o*t}px`;return this.dropShadowBlur>0?`text-shadow: ${n} ${this.dropShadowBlur}px ${e}`:`text-shadow: ${n} ${e}`}reset(){Object.assign(this,d.defaultOptions)}onBeforeDraw(){const{fontsDirty:t}=this;return this.fontsDirty=!1,this.isSafari&&this._fonts.length>0&&t?new Promise(e=>setTimeout(e,100)):Promise.resolve()}get isSafari(){const{userAgent:t}=l.settings.ADAPTER.getNavigator();return/^((?!chrome|android).)*safari/i.test(t)}set fillGradientStops(t){console.warn("[HTMLTextStyle] fillGradientStops is not supported by HTMLText")}get fillGradientStops(){return super.fillGradientStops}set fillGradientType(t){console.warn("[HTMLTextStyle] fillGradientType is not supported by HTMLText")}get fillGradientType(){return super.fillGradientType}set miterLimit(t){console.warn("[HTMLTextStyle] miterLimit is not supported by HTMLText")}get miterLimit(){return super.miterLimit}set trim(t){console.warn("[HTMLTextStyle] trim is not supported by HTMLText")}get trim(){return super.trim}set textBaseline(t){console.warn("[HTMLTextStyle] textBaseline is not supported by HTMLText")}get textBaseline(){return super.textBaseline}set leading(t){console.warn("[HTMLTextStyle] leading is not supported by HTMLText")}get leading(){return super.leading}set lineJoin(t){console.warn("[HTMLTextStyle] lineJoin is not supported by HTMLText")}get lineJoin(){return super.lineJoin}};let u=d;u.availableFonts={},u.defaultOptions={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",letterSpacing:0,lineHeight:0,padding:0,stroke:"black",strokeThickness:0,whiteSpace:"normal",wordWrap:!1,wordWrapWidth:100};const c=class extends x.Sprite{constructor(t="",e={}){var s;const i=new Image,o=l.Texture.from(i,{scaleMode:l.settings.SCALE_MODE,resourceOptions:{autoLoad:!1}});o.orig=new l.Rectangle,o.trim=new l.Rectangle,super(o),this._text=null,this._style=null,this._autoResolution=!0,this._loading=!1,this.localStyleID=-1,this.dirty=!1,this.ownsStyle=!1;const n="http://www.w3.org/2000/svg",r="http://www.w3.org/1999/xhtml",h=document.createElementNS(n,"svg"),a=document.createElementNS(n,"foreignObject"),_=document.createElementNS(r,"div"),w=document.createElementNS(r,"style");a.setAttribute("width","10000"),a.setAttribute("height","10000"),a.style.overflow="hidden",h.appendChild(a),this.maxWidth=c.defaultMaxWidth,this.maxHeight=c.defaultMaxHeight,this._domElement=_,this._styleElement=w,this._svgRoot=h,this._foreignObject=a,this._foreignObject.appendChild(w),this._foreignObject.appendChild(_),this._image=i,this._autoResolution=c.defaultAutoResolution,this._resolution=(s=c.defaultResolution)!=null?s:l.settings.RESOLUTION,this.text=t,this.style=e}measureText(t){var e,s;const{text:i,style:o,resolution:n}=Object.assign({text:this._text,style:this._style,resolution:this._resolution},t);Object.assign(this._domElement,{innerHTML:i,style:o.toCSS(n)}),this._styleElement.textContent=o.toGlobalCSS(),document.body.appendChild(this._svgRoot);const r=this._domElement.getBoundingClientRect();this._svgRoot.remove();const h=Math.min(this.maxWidth,Math.ceil(r.width)),a=Math.min(this.maxHeight,Math.ceil(r.height));return this._svgRoot.setAttribute("width",h.toString()),this._svgRoot.setAttribute("height",a.toString()),i!==this._text&&(this._domElement.innerHTML=this._text),o!==this._style&&(Object.assign(this._domElement,{style:(e=this._style)==null?void 0:e.toCSS(n)}),this._styleElement.textContent=(s=this._style)==null?void 0:s.toGlobalCSS()),{width:h+o.padding*2,height:a+o.padding*2}}async updateText(t=!0){const{style:e,_image:s}=this;if(this.localStyleID!==e.styleID&&(this.dirty=!0,this.localStyleID=e.styleID),!this.dirty&&t)return;const{width:i,height:o}=this.measureText();s.width=Math.ceil(Math.max(1,i)),s.height=Math.ceil(Math.max(1,o)),this._loading||(this._loading=!0,await new Promise(n=>{s.onload=async()=>{await e.onBeforeDraw(),this._loading=!1,this.updateTexture(),n()};const r=new XMLSerializer().serializeToString(this._svgRoot);s.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(r)}`}))}get source(){return this._image}get canvas(){return l.utils.deprecation("3.2.0",'HTMLText property "canvas" is deprecated, use "source" instead.'),this._image}updateTexture(){const{style:t,texture:e,_image:s,resolution:i}=this,{padding:o}=t,{baseTexture:n}=e;e.trim.width=e._frame.width=s.width/i,e.trim.height=e._frame.height=s.height/i,e.trim.x=-o,e.trim.y=-o,e.orig.width=e._frame.width-o*2,e.orig.height=e._frame.height-o*2,this._onTextureUpdate(),n.setRealSize(s.width,s.height,i),this.dirty=!1}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._render(t)}_renderCanvas(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._renderCanvas(t)}getLocalBounds(t){return this.updateText(!0),super.getLocalBounds(t)}_calculateBounds(){this.updateText(!0),this.calculateVertices(),this._bounds.addQuad(this.vertexData)}_onStyleChange(){this.dirty=!0}destroy(t){var e,s,i,o,n;typeof t=="boolean"&&(t={children:t}),t=Object.assign({},c.defaultDestroyOptions,t),super.destroy(t);const r=null;this.ownsStyle&&((e=this._style)==null||e.cleanFonts()),this._style=r,(s=this._svgRoot)==null||s.remove(),this._svgRoot=r,(i=this._domElement)==null||i.remove(),this._domElement=r,(o=this._foreignObject)==null||o.remove(),this._foreignObject=r,(n=this._styleElement)==null||n.remove(),this._styleElement=r,this._image.onload=null,this._image.src="",this._image=r}get width(){return this.updateText(!0),Math.abs(this.scale.x)*this._image.width/this.resolution}set width(t){this.updateText(!0);const e=l.utils.sign(this.scale.x)||1;this.scale.x=e*t/this._image.width/this.resolution,this._width=t}get height(){return this.updateText(!0),Math.abs(this.scale.y)*this._image.height/this.resolution}set height(t){this.updateText(!0);const e=l.utils.sign(this.scale.y)||1;this.scale.y=e*t/this._image.height/this.resolution,this._height=t}get style(){return this._style}set style(t){this._style!==t&&(t=t||{},t instanceof u?(this.ownsStyle=!1,this._style=t):t instanceof y.TextStyle?(console.warn("[HTMLText] Cloning TextStyle, if this is not what you want, use HTMLTextStyle"),this.ownsStyle=!0,this._style=u.from(t)):(this.ownsStyle=!0,this._style=new u(t)),this.localStyleID=-1,this.dirty=!0)}get text(){return this._text}set text(t){t=String(t===""||t===null||t===void 0?" ":t),t=this.sanitiseText(t),this._text!==t&&(this._text=t,this.dirty=!0)}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}sanitiseText(t){return t.replace(/<br>/gi,"<br/>").replace(/<hr>/gi,"<hr/>").replace(/ /gi," ")}};let g=c;return g.defaultDestroyOptions={texture:!0,children:!1,baseTexture:!0},g.defaultMaxWidth=2024,g.defaultMaxHeight=2024,g.defaultAutoResolution=!0,p.HTMLText=g,p.HTMLTextStyle=u,p}({},PIXI,PIXI,PIXI);Object.assign(PIXI,_pixi_htmltext); | ||
//# sourceMappingURL=html-text.js.map |
{ | ||
"name": "@pixi/text-html", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"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
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
175717
463