aframe-text-sprite
Advanced tools
Comparing version 2.2.0 to 3.0.0
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("aframe")):"function"==typeof define&&define.amd?define(["aframe"],e):e((t=t||self).AFRAME)}(this,(function(t){"use strict";function e(t,e){return t(e={exports:{}},e.exports),e.exports}var i=(t=t&&t.hasOwnProperty("default")?t.default:t).THREE,n=e((function(t,e){t.exports=function(t){function e(t,e,i,n,o){return[i,n,o,e+"px",t].join(" ")}var i=function(i){function n(e){void 0===e&&(e={});var n=e.align;void 0===n&&(n="center");var o=e.fillStyle;void 0===o&&(o="#fff");var r=e.fontFamily;void 0===r&&(r="sans-serif");var a=e.fontSize;void 0===a&&(a=16);var l=e.fontStyle;void 0===l&&(l="normal");var f=e.fontVariant;void 0===f&&(f="normal");var s=e.fontWeight;void 0===s&&(s="normal");var h=e.lineGap;void 0===h&&(h=.15);var d=e.padding;void 0===d&&(d=.25);var p=e.strokeStyle;void 0===p&&(p="#000");var c=e.strokeWidth;void 0===c&&(c=0);var u=e.text;void 0===u&&(u=""),i.call(this,document.createElement("canvas"),void 0,void 0,void 0,t.LinearFilter,t.LinearFilter),Object.assign(this,{_align:n,_fillStyle:o,_fontFamily:r,_fontSize:a,_fontStyle:l,_fontVariant:f,_fontWeight:s,_lineGap:h,_padding:d,_strokeStyle:p,_strokeWidth:c,_text:u,needsRedraw:!0})}i&&(n.__proto__=i),n.prototype=Object.create(i&&i.prototype),n.prototype.constructor=n;var o={lines:{configurable:!0},textWidth:{configurable:!0},textHeight:{configurable:!0},width:{configurable:!0},height:{configurable:!0}};return o.lines.get=function(){var t=this.text;return t?t.split("\n"):[]},o.textWidth.get=function(){var t=this.fontFamily,i=this.fontStyle,n=this.fontVariant,o=this.fontWeight,r=this.lines;if(r.length){var a=document.createElement("canvas").getContext("2d");return a.font=e(t,1,i,n,o),r.map((function(t){return a.measureText(t).width})).reduce((function(t,e){return Math.max(t,e)}))}return 0},o.textHeight.get=function(){var t=this.lineGap,e=this.lines;return e.length?e.length+t*(e.length-1):0},o.width.get=function(){var t=this.padding;return 2*(t+=this.strokeWidth/2)+this.textWidth},o.height.get=function(){var t=this.padding;return 2*(t+=this.strokeWidth/2)+this.textHeight},Object.defineProperties(n.prototype,o),n}(t.Texture),n=new t.Vector3,o=new t.Vector3,r=new t.Vector3,a={computeAndSetOptimalFontSize:function(){for(var t,e=arguments,i=[],n=arguments.length;n--;)i[n]=e[n];this.fontSize=(t=this).computeOptimalFontSize.apply(t,i)},computeOptimalFontSize:function(e,i,a,l){var f=this.height,s=this.width;if(s&&f){var h=(i.capabilities||{}).maxTextureSize||1/0;e.getWorldPosition(o),a.getWorldPosition(n);var d=o.distanceTo(n);if(a.isPerspectiveCamera&&(d*=2*Math.tan(t.Math.degToRad(a.fov)/2)),(a.isPerspectiveCamera||a.isOrthographicCamera)&&(d/=a.zoom),d){e.getWorldScale(r);var p=r.y*i.domElement.offsetHeight/d/f;return l&&(p=t.Math.ceilPowerOfTwo(p)),f*=p,((s*=p)>h||f>h)&&(p*=h/Math.max(s,f),l&&(p=t.Math.floorPowerOfTwo(p))),p}}return 0},isTextTexture:!0,redraw:function(){if(this.needsRedraw){var t=this.image;if(t){var i=this.fontSize,n=this.height,o=this.width,r=t.getContext("2d");if(r.clearRect(0,0,t.width,t.height),n*=i,(o*=i)&&n){t.width=o,t.height=n;var a,l=this.align,f=this.fillStyle,s=this.fontFamily,h=this.fontStyle,d=this.fontVariant,p=this.fontWeight,c=this.lineGap,u=this.lines,g=this.padding,y=this.strokeStyle,m=this.strokeWidth;switch(g+=m/2,m*=i,c*=i,g*=i,r.font=e(s,i,h,d,p),l){case"left":r.textAlign="left",a=g;break;case"right":r.textAlign="right",a=o-g;break;case"center":r.textAlign="center",a=o/2}r.textBaseline="top";var v=g;r.fillStyle=f,r.miterLimit=1,r.lineWidth=m,r.strokeStyle=y,u.forEach((function(t){m&&r.strokeText(t,a,v),r.fillText(t,a,v),v+=i+c}))}else t.width=t.height=1;this.needsRedraw=!1,this.needsUpdate=!0}}}},l=i.prototype;return Object.entries({_align:"align",_fillStyle:"fillStyle",_fontFamily:"fontFamily",_fontSize:"fontSize",_fontStyle:"fontStyle",_fontVariant:"fontVariant",_fontWeight:"fontWeight",_lineGap:"lineGap",_padding:"padding",_strokeStyle:"strokeStyle",_strokeWidth:"strokeWidth",_text:"text"}).forEach((function(t){var e=t[0],i=t[1];Object.defineProperty(l,i,{get:function(){return this[e]},set:function(t){this[e]!==t&&(this[e]=t,this.needsRedraw=!0)}})})),Object.assign(l,a),i}(i)})),o=e((function(t,e){t.exports=function(t,e){e=e&&e.hasOwnProperty("default")?e.default:e;var i=function(i){function n(n){void 0===n&&(n={});var o=n.fontSize;void 0===o&&(o=1);var r=function(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&-1===e.indexOf(n)&&(i[n]=t[n]);return i}(n,["fontSize"]),a=new e(Object.assign({},r,{fontSize:0})),l=new t.SpriteMaterial({depthWrite:!1,map:a});i.call(this,l),Object.assign(this,{fontSize:o})}i&&(n.__proto__=i),n.prototype=Object.create(i&&i.prototype),n.prototype.constructor=n;var o={width:{configurable:!0},height:{configurable:!0}};return o.width.get=function(){var t=this.fontSize;return this.material.map.width*t},o.height.get=function(){var t=this.fontSize;return this.material.map.height*t},Object.defineProperties(n.prototype,o),n}(t.Sprite),n=i.prototype;return["align","fillStyle","fontFamily","fontStyle","fontVariant","fontWeight","lineGap","padding","strokeStyle","strokeWidth","text"].forEach((function(t){Object.defineProperty(n,t,{get:function(){return this.material.map[t]},set:function(e){this.material.map[t]=e}})})),Object.assign(n,{dispose:function(){var t=this.material;t.map.dispose(),t.dispose()},isTextSprite:!0,onBeforeRender:function(t,e,i){var n=this.height,o=this.material,r=this.scale,a=this.width,l=o.map;a&&n?r.setX(a).setY(n):r.setX(1).setY(1),l.computeAndSetOptimalFontSize(this,t,i,!0),l.redraw()}}),i}(i,n)})),r="text-sprite";t.registerComponent(r,{init:function(){var t=this.data,e=this.el,i=t.align,n=t.fillStyle,a=t.fontFamily,l=t.fontSize,f=t.fontStyle,s=t.fontVariant,h=t.fontWeight,d=t.lineGap,p=t.padding,c=t.strokeStyle,u=t.strokeWidth,g=t.text,y=new o({align:i,fillStyle:n,fontFamily:a,fontSize:l,fontStyle:f,fontVariant:s,fontWeight:h,lineGap:d,padding:p,strokeStyle:c,strokeWidth:u,text:g});e.setObject3D(r,y)},remove:function(){var t=this.el;t.getObject3D(r).dispose(),t.removeObject3D(r)},schema:{align:{type:"string",default:"center"},fillStyle:{type:"color",default:"#fff"},fog:{type:"boolean",default:!1},fontFamily:{type:"string",default:"sans-serif"},fontSize:{type:"number",default:1},fontStyle:{type:"string",default:"normal"},fontVariant:{type:"string",default:"normal"},fontWeight:{type:"string",default:"normal"},lineGap:{type:"number",default:.15},opacity:{type:"number",default:1},padding:{type:"number",default:.25},strokeStyle:{type:"color",default:"#000"},strokeWidth:{type:"number",default:0},text:{type:"string",default:""},transparent:{type:"boolean",default:!0}},update:function(t){var e=this.data,i=this.el,n=e.align,o=e.fillStyle,a=e.fog,l=e.fontFamily,f=e.fontSize,s=e.fontStyle,h=e.fontVariant,d=e.fontWeight,p=e.lineGap,c=e.opacity,u=e.padding,g=e.strokeStyle,y=e.strokeWidth,m=e.text,v=e.transparent,S=i.getObject3D(r);Object.keys(t).length&&Object.assign(S,{align:n,fillStyle:o,fontFamily:l,fontSize:f,fontStyle:s,fontVariant:h,fontWeight:d,lineGap:p,padding:u,strokeStyle:g,strokeWidth:y,text:m});var x=S.material;Object.assign(x,{fog:a,opacity:c,transparent:v})}})})); | ||
!function(t,e){"use strict";function n(t,e,n){return t(n={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&n.path)}},n.exports),n.exports}var o=n((function(e,n){e.exports=function(t){let e=class extends t.Texture{constructor(){super(document.createElement("canvas"));let e=null,n=()=>e||(e=this.createDrawable()),o=()=>n().width,i=()=>n().height,r=!0,a=1,l=()=>t.MathUtils.ceilPowerOfTwo(o()*a),s=()=>t.MathUtils.ceilPowerOfTwo(i()*a),f=t=>{if(a!==t){let e=l(),n=s();a=t;let o=l(),i=s();o===e&&i===n||(r=!0)}},c=(()=>{let e=new t.Vector3,n=new t.Vector3,r=new t.Vector3;return(t,a,l)=>{let s=o(),f=i();if(s&&f){t.getWorldPosition(n),l.getWorldPosition(e);let o=n.distanceTo(e);if(l.isPerspectiveCamera&&(o*=2*Math.tan(THREE.Math.degToRad(l.fov)/2)),(l.isPerspectiveCamera||l.isOrthographicCamera)&&(o/=l.zoom),o){var c,d;t.getWorldScale(r);let e=null!==(c=null===(d=a.capabilities)||void 0===d?void 0:d.maxTextureSize)&&void 0!==c?c:1/0;return Math.min(Math.max(r.x/o*(a.domElement.offsetWidth/s),r.y/o*(a.domElement.offsetHeight/f)),e/s,e/f)}}return 0}})();Object.defineProperties(this,{width:{get:o},height:{get:i},pixelRatio:{get:()=>a,set:f},needsRedraw:{set(t){t&&(r=!0,e=null)}}}),Object.assign(this,{redraw(){if(r){let t=this.image,e=t.getContext("2d");e.clearRect(0,0,t.width,t.height),t.width=l(),t.height=s(),t.width&&t.height?(e.save(),e.scale(t.width/o(),t.height/i()),((...t)=>{n().draw(...t)})(e),e.restore()):t.width=t.height=1,r=!1,this.needsUpdate=!0}},setOptimalPixelRatio(...t){f(c(...t))}})}};e.prototype.isDynamicTexture=!0;let n=class extends e{constructor({alignment:t="center",color:e="#fff",fontFamily:n="sans-serif",fontSize:o=16,fontStyle:i="normal",fontVariant:r="normal",fontWeight:a="normal",lineGap:l=1/4,padding:s=.5,strokeColor:f="#fff",strokeWidth:c=0,text:d=""}={}){super(),Object.entries({alignment:t,color:e,fontFamily:n,fontSize:o,fontStyle:i,fontVariant:r,fontWeight:a,lineGap:l,padding:s,strokeColor:f,strokeWidth:c,text:d}).forEach((([t,e])=>{Object.defineProperty(this,t,{get:()=>e,set(t){e!==t&&(e=t,this.needsRedraw=!0)}})}))}get font(){return function(t,e,n,o,i){let r=document.createElement("span");return r.style.font="1px serif",r.style.fontFamily=t,r.style.fontSize="".concat(e,"px"),r.style.fontStyle=n,r.style.fontVariant=o,r.style.fontWeight=i,r.style.font}(this.fontFamily,this.fontSize,this.fontStyle,this.fontVariant,this.fontWeight)}checkFontFace(){try{return document.fonts.check(this.font)}catch{}return!0}async loadFontFace(){try{return await document.fonts.load(this.font)}catch{}}createDrawable(){let{alignment:t,color:e,font:n,fontSize:o,lineGap:i,padding:r,strokeColor:a,strokeWidth:l,text:s}=this;r*=o,i*=o,l*=o;let f=s?s.split("\n"):[],c=f.length,d=o+i,h=c?(()=>{let t=document.createElement("canvas").getContext("2d");return t.font=n,Math.max(...f.map((e=>t.measureText(e).width)))})():0,p=r+l/2,u=h+2*p;return{width:u,height:(c?o+d*(c-1):0)+2*p,draw(i){let r,s=p+o/2;Object.assign(i,{fillStyle:e,font:n,lineWidth:l,miterLimit:1,strokeStyle:a,textAlign:(()=>{switch(t){case"left":return r=p,"left";case"right":return r=u-p,"right"}return r=u/2,"center"})(),textBaseline:"middle"}),f.forEach((t=>{i.fillText(t,r,s),l&&i.strokeText(t,r,s),s+=d}))}}}};return n.prototype.isTextTexture=!0,n}(t)})),i=n((function(e,n){e.exports=function(t,e){function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=n(e);let i=class extends t.Sprite{constructor(e){let n=new o.default(e);super(new t.SpriteMaterial({depthWrite:!1,map:n}))}onBeforeRender(t,e,n){let{material:o}=this,{map:i}=o;if(i.checkFontFace()){let{scale:e}=this,{height:o,width:r}=i;r&&o?(e.setX(r).setY(o),i.setOptimalPixelRatio(this,t,n),i.redraw()):e.setScalar(1)}else i.loadFontFace()}dispose(){let{material:t}=this,{map:e}=t;e.dispose(),t.dispose()}};return["alignment","color","fontFamily","fontSize","fontStyle","fontVariant","fontWeight","lineGap","padding","strokeColor","strokeWidth","text"].forEach((t=>{Object.defineProperty(i.prototype,t,{get(){return this.material.map[t]},set(e){this.material.map[t]=e}})})),i.prototype.isTextSprite=!0,i}(t,o)})),r="text-sprite";t.MathUtils=t.MathUtils||t.Math,e.registerComponent(r,{init:function(){let{data:t,el:e}=this,{alignment:n,color:o,fontFamily:a,fontSize:l,fontStyle:s,fontVariant:f,fontWeight:c,lineGap:d,padding:h,strokeColor:p,strokeWidth:u,text:m}=t,g=new i({alignment:n,color:o,fontFamily:a,fontSize:l,fontStyle:s,fontVariant:f,fontWeight:c,lineGap:d,padding:h,strokeColor:p,strokeWidth:u,text:m});e.setObject3D(r,g)},remove:function(){let{el:t}=this;t.getObject3D(r).dispose(),t.removeObject3D(r)},schema:{alignment:{type:"string",default:"center"},color:{type:"color",default:"#fff"},fog:{type:"boolean",default:!1},fontFamily:{type:"string",default:"sans-serif"},fontSize:{type:"number",default:1},fontStyle:{type:"string",default:"normal"},fontVariant:{type:"string",default:"normal"},fontWeight:{type:"string",default:"normal"},lineGap:{type:"number",default:.15},opacity:{type:"number",default:1},padding:{type:"number",default:.25},strokeColor:{type:"color",default:"#000"},strokeWidth:{type:"number",default:0},text:{type:"string",default:""},transparent:{type:"boolean",default:!0}},update:function(t){let{data:e,el:n}=this,{alignment:o,color:i,fog:a,fontFamily:l,fontSize:s,fontStyle:f,fontVariant:c,fontWeight:d,lineGap:h,opacity:p,padding:u,strokeColor:m,strokeWidth:g,text:y,transparent:x}=e,w=n.getObject3D(r);Object.keys(t).length&&Object.assign(w,{alignment:o,color:i,fontFamily:l,fontSize:s,fontStyle:f,fontVariant:c,fontWeight:d,lineGap:h,padding:u,strokeColor:m,strokeWidth:g,text:y});let{material:S}=w;Object.assign(S,{fog:a,opacity:p,transparent:x})}})}(THREE,AFRAME); |
{ | ||
"name": "aframe-text-sprite", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "A wrapper for THREE.TextSprite.", | ||
@@ -20,9 +20,12 @@ "keywords": [ | ||
"devDependencies": { | ||
"@seregpie/three.text-sprite": "^2.0.0", | ||
"rollup": "^1.26.3", | ||
"rollup-plugin-buble": "^0.19.8", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-terser": "^5.1.2", | ||
"three": "file:THREE" | ||
"@babel/core": "^7.11.6", | ||
"@babel/preset-env": "^7.11.5", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
"@rollup/plugin-commonjs": "^15.1.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@seregpie/three.text-sprite": "^3.0.0", | ||
"eslint": "^7.11.0", | ||
"eslint-config-seregpie": "^1.0.1", | ||
"rollup": "^2.29.0", | ||
"rollup-plugin-terser": "^7.0.2" | ||
}, | ||
@@ -29,0 +32,0 @@ "peerDependencies": { |
# aframe-text-sprite | ||
A wrapper for THREE.TextSprite. | ||
A wrapper for [`THREE.TextSprite`](https://github.com/SeregPie/THREE.TextSprite). | ||
@@ -17,3 +17,3 @@ ## demo | ||
### ES module | ||
--- | ||
@@ -28,3 +28,3 @@ ```javascript | ||
```html | ||
<script src="https://unpkg.com/aframe/dist/aframe-master.min.js"></script> | ||
<script src="https://unpkg.com/aframe"></script> | ||
<script src="https://unpkg.com/aframe-text-sprite"></script> | ||
@@ -37,4 +37,4 @@ ``` | ||
| ---: | :--- | :--- | | ||
| `align` | `'string'` | `'center'` | | ||
| `fillStyle` | `'color'` | `'#fff'` | | ||
| `alignment` | `'string'` | `'center'` | | ||
| `color` | `'color'` | `'#fff'` | | ||
| `fog` | `'boolean'` | `false` | | ||
@@ -46,8 +46,8 @@ | `fontFamily` | `'string'` | `'sans-serif'` | | ||
| `fontWeight` | `'string'` | `'normal'` | | ||
| `lineGap` | `'number'` | `0.15` | | ||
| `lineGap` | `'number'` | `0.25` | | ||
| `opacity` | `'number'` | `1` | | ||
| `padding` | `'number'` | `0.25` | | ||
| `strokeStyle` | `'color'` | `'#000'` | | ||
| `padding` | `'number'` | `0.5` | | ||
| `strokeColor` | `'color'` | `'#fff'` | | ||
| `strokeWidth` | `'number'` | `0` | | ||
| `text` | `'string'` | `''` | | ||
| `transparent` | `'boolean'` | `true` | |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
1
8792
10
23