aframe-text-sprite
Advanced tools
Comparing version 2.1.1 to 2.2.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 n=(t=t&&t.hasOwnProperty("default")?t.default:t).THREE,i=e((function(t,e){t.exports=function(t){function e(){}function n(t){return new Promise((function(e){setTimeout(e,t)}))}function i(t){return new Promise((function(e){e(t())}))}function r(){return document.createElement("canvas")}function o(t,e,n,i,r){return[n,i,r,e+"px",t].join(" ")}function a(t,e,n,i){var r=o(t,1,e,n,i);return document.fonts.load(r)}function f(){var t=this;return i((function(){if(t.needsRedraw){var e=t.image;if(e){var n=t,r=n.align,a=n.fillStyle,f=n.fontFamily,l=n.fontSize,s=n.fontStyle,u=n.fontVariant,c=n.fontWeight,d=n.height,p=n.lineGap,h=n.lines,y=n.loadFontFace,g=n.padding,v=n.strokeStyle,m=n.strokeWidth;return i((function(){return y(f,s,u,c)})).then((function(){var n=e.getContext("2d");n.clearRect(0,0,e.width,e.height),d*=l,p*=l,g*=l,g+=(m*=l)/2;var i=o(f,l,s,u,c),y=2*g;if(h.length&&(n.font=i,y+=h.map((function(t){return n.measureText(t).width})).reduce((function(t,e){return Math.max(t,e)}))),y&&d){var S;switch(e.width=y,e.height=d,n.font=i,r){case"left":n.textAlign="left",S=g;break;case"right":n.textAlign="right",S=y-g;break;case"center":n.textAlign="center",S=y/2}n.textBaseline="top";var x=g;n.fillStyle=a,n.miterLimit=1,n.lineWidth=m,n.strokeStyle=v,h.forEach((function(t){m&&n.strokeText(t,S,x),n.fillText(t,S,x),x+=l+p}))}else e.width=e.height=1;t.needsRedraw=!1,t.needsUpdate=!0}))}}}))}var l=function(o){function l(l){void 0===l&&(l={});var s=l.align;void 0===s&&(s="center");var u=l.createCanvas;void 0===u&&(u=r);var c=l.fillStyle;void 0===c&&(c="#fff");var d=l.fontFamily;void 0===d&&(d="sans-serif");var p=l.fontSize;void 0===p&&(p=16);var h=l.fontStyle;void 0===h&&(h="normal");var y=l.fontVariant;void 0===y&&(y="normal");var g=l.fontWeight;void 0===g&&(g="normal");var v=l.lineGap;void 0===v&&(v=.15);var m=l.loadFontFace;void 0===m&&(m=a);var S=l.padding;void 0===S&&(S=.25);var x=l.strokeStyle;void 0===x&&(x="#000");var _=l.strokeWidth;void 0===_&&(_=0);var b,w,k,W,O,F=l.text;void 0===F&&(F=""),o.call(this,u(),void 0,void 0,void 0,t.LinearFilter,t.LinearFilter),Object.assign(this,{_align:s,_fillStyle:c,_fontFamily:d,_fontSize:p,_fontStyle:h,_fontVariant:y,_fontWeight:g,_lineGap:v,_padding:S,_strokeStyle:x,_strokeWidth:_,_text:F,createCanvas:u,loadFontFace:m,needsRedraw:!0,redraw:(b=f,O=Promise.resolve(),function(){for(var t=arguments,r=this,o=[],a=arguments.length;a--;)o[a]=t[a];return i((function(){return k=r,W=o,w||(w=new Promise((function(t){O=O.then((function(){return n(1)})).then((function(){try{var e=b.apply(k,W);return t(e),e}finally{w=null}})).catch(e)}))),w}))})}),this.redraw()}o&&(l.__proto__=o),l.prototype=Object.create(o&&o.prototype),l.prototype.constructor=l;var s={lines:{configurable:!0},height:{configurable:!0}};return s.lines.get=function(){var t=this.text;return t?t.split("\n"):[]},s.height.get=function(){var t=this.lineGap,e=this.lines,n=this.padding,i=2*(n+=this.strokeWidth/2);return e.length&&(i+=e.length+t*(e.length-1)),i},Object.defineProperties(l.prototype,s),l}(t.Texture),s=new t.Vector3,u=new t.Vector3,c=new t.Vector3,d={computeOptimalFontSize:function(e,n,i){var r=this.height;if(r){var o=e.getWorldPosition(u).distanceTo(i.getWorldPosition(s));if(i.isPerspectiveCamera&&(o*=2*Math.tan(t.Math.degToRad(i.fov)/2)),(i.isPerspectiveCamera||i.isOrthographicCamera)&&(o/=i.zoom),o)return Math.round(e.getWorldScale(c).y*n.domElement.offsetHeight/o/r)}return 0},isTextTexture:!0},p=l.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],n=t[1];Object.defineProperty(p,n,{get:function(){return this[e]},set:function(t){this[e]!==t&&(this[e]=t,this.needsRedraw=!0,this.redraw())}})})),Object.assign(p,d),l}(n)})),r=e((function(t,e){t.exports=function(t,e){function n(){}function i(t){return new Promise((function(e){setTimeout(e,t)}))}function r(t){return new Promise((function(e){e(t())}))}function o(){var t=this;return r((function(){var e=t,n=e.fontSize,i=e.material,r=e.scale,o=i.map,a=o.height,f=o.image;return a*=n,o.redraw().then((function(){r.set(f.width/f.height,1,1).multiplyScalar(a)}))}))}function a(e,n){var i=this.material.map;i.fontSize=t.Math.ceilPowerOfTwo(i.computeOptimalFontSize(this,e,n)),this.updateScale()}e=e&&e.hasOwnProperty("default")?e.default:e;var f=function(f){function l(l){void 0===l&&(l={});var s=l.fontSize;void 0===s&&(s=1);var u,c,d,p,h,y=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&-1===e.indexOf(i)&&(n[i]=t[i]);return n}(l,["fontSize"]);f.call(this,new t.SpriteMaterial({depthWrite:!1,map:new e(Object.assign({},y,{fontSize:0}))})),Object.assign(this,{fontSize:s,updateScale:o,updateTextureFontSize:(u=a,h=Promise.resolve(),function(){for(var t=arguments,e=this,o=[],a=arguments.length;a--;)o[a]=t[a];return r((function(){return d=e,p=o,c||(c=new Promise((function(t){h=h.then((function(){try{var e=u.apply(d,p);return t(e),e}finally{c=null}})).catch(n).then((function(){return i(1)}))}))),c}))})})}return f&&(l.__proto__=f),l.prototype=Object.create(f&&f.prototype),l.prototype.constructor=l,l.prototype.onBeforeRender=function(t,e,n){this.updateTextureFontSize(t,n)},l.prototype.dispose=function(){var t=this.material;t.map.dispose(),t.dispose()},l}(t.Sprite),l=f.prototype;return["align","fillStyle","fontFamily","fontStyle","fontVariant","fontWeight","lineGap","padding","strokeStyle","strokeWidth","text"].forEach((function(t){Object.defineProperty(l,t,{get:function(){return this.material.map[t]},set:function(e){this.material.map[t]=e,this.updateScale()}})})),Object.assign(l,{isTextSprite:!0}),f}(n,i)})),o="text-sprite";t.registerComponent(o,{init:function(){var t=this.data,e=this.el,n=t.align,i=t.fillStyle,a=t.fontFamily,f=t.fontSize,l=t.fontStyle,s=t.fontVariant,u=t.fontWeight,c=t.lineGap,d=t.padding,p=t.strokeStyle,h=t.strokeWidth,y=t.text,g=new r({align:n,fillStyle:i,fontFamily:a,fontSize:f,fontStyle:l,fontVariant:s,fontWeight:u,lineGap:c,padding:d,strokeStyle:p,strokeWidth:h,text:y});e.setObject3D(o,g)},remove:function(){var t=this.el;t.getObject3D(o).dispose(),t.removeObject3D(o)},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,n=this.el,i=e.align,r=e.fillStyle,a=e.fog,f=e.fontFamily,l=e.fontSize,s=e.fontStyle,u=e.fontVariant,c=e.fontWeight,d=e.lineGap,p=e.opacity,h=e.padding,y=e.strokeStyle,g=e.strokeWidth,v=e.text,m=e.transparent,S=n.getObject3D(o);Object.keys(t).length&&Object.assign(S,{align:i,fillStyle:r,fontFamily:f,fontSize:l,fontStyle:s,fontVariant:u,fontWeight:c,lineGap:d,padding:h,strokeStyle:y,strokeWidth:g,text:v});var x=S.material;Object.assign(x,{fog:a,opacity:p,transparent:m})}})})); | ||
!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})}})})); |
{ | ||
"name": "aframe-text-sprite", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "A wrapper for THREE.TextSprite.", | ||
@@ -20,4 +20,4 @@ "keywords": [ | ||
"devDependencies": { | ||
"@seregpie/three.text-sprite": "^1.1.0", | ||
"rollup": "^1.23.1", | ||
"@seregpie/three.text-sprite": "^2.0.0", | ||
"rollup": "^1.26.3", | ||
"rollup-plugin-buble": "^0.19.8", | ||
@@ -24,0 +24,0 @@ "rollup-plugin-commonjs": "^10.1.0", |
@@ -20,4 +20,4 @@ # aframe-text-sprite | ||
```javascript | ||
import 'aframe'; | ||
import 'aframe-text-sprite'; | ||
import AFRAME from 'aframe'; | ||
``` | ||
@@ -24,0 +24,0 @@ |
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
10115
28