Socket
Socket
Sign inDemoInstall

@seregpie/three.text-texture

Package Overview
Dependencies
1
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 3.1.0

index.d.ts

2

index.js

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

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("three")):"function"==typeof define&&define.amd?define(["three"],e):((t="undefined"!=typeof globalThis?globalThis:t||self).THREE=t.THREE||{},t.THREE.TextTexture=e(t.THREE))}(this,(function(t){"use strict";let e=class extends t.Texture{constructor(){super(document.createElement("canvas"));let e=null,i=()=>e||(e=this.createDrawable()),n=()=>i().width,o=()=>i().height,r=!0,a=1,l=()=>t.MathUtils.ceilPowerOfTwo(n()*a),s=()=>t.MathUtils.ceilPowerOfTwo(o()*a),h=t=>{if(a!==t){let e=l(),i=s();a=t;let n=l(),o=s();n===e&&o===i||(r=!0)}},f=(()=>{let e=new t.Vector3,i=new t.Vector3,r=new t.Vector3;return(t,a,l)=>{let s=n(),h=o();if(s&&h){t.getWorldPosition(i),l.getWorldPosition(e);let n=i.distanceTo(e);if(l.isPerspectiveCamera&&(n*=2*Math.tan(THREE.Math.degToRad(l.fov)/2)),(l.isPerspectiveCamera||l.isOrthographicCamera)&&(n/=l.zoom),n){var f,c;t.getWorldScale(r);let e=null!==(f=null===(c=a.capabilities)||void 0===c?void 0:c.maxTextureSize)&&void 0!==f?f:1/0;return Math.min(Math.max(r.x/n*(a.domElement.offsetWidth/s),r.y/n*(a.domElement.offsetHeight/h)),e/s,e/h)}}return 0}})();Object.defineProperties(this,{width:{get:n},height:{get:o},pixelRatio:{get:()=>a,set:h},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/n(),t.height/o()),((...t)=>{i().draw(...t)})(e),e.restore()):t.width=t.height=1,r=!1,this.needsUpdate=!0}},setOptimalPixelRatio(...t){h(f(...t))}})}};e.prototype.isDynamicTexture=!0;let i=class extends e{constructor({alignment:t="center",color:e="#fff",fontFamily:i="sans-serif",fontSize:n=16,fontStyle:o="normal",fontVariant:r="normal",fontWeight:a="normal",lineGap:l=1/4,padding:s=.5,strokeColor:h="#fff",strokeWidth:f=0,text:c=""}={}){super(),Object.entries({alignment:t,color:e,fontFamily:i,fontSize:n,fontStyle:o,fontVariant:r,fontWeight:a,lineGap:l,padding:s,strokeColor:h,strokeWidth:f,text:c}).forEach((([t,e])=>{Object.defineProperty(this,t,{get:()=>e,set(t){e!==t&&(e=t,this.needsRedraw=!0)}})}))}get font(){return function(t,e,i,n,o){let r=document.createElement("span");return r.style.font="1px serif",r.style.fontFamily=t,r.style.fontSize="".concat(e,"px"),r.style.fontStyle=i,r.style.fontVariant=n,r.style.fontWeight=o,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:i,fontSize:n,lineGap:o,padding:r,strokeColor:a,strokeWidth:l,text:s}=this;r*=n,o*=n,l*=n;let h=s?s.split("\n"):[],f=h.length,c=n+o,d=f?(()=>{let t=document.createElement("canvas").getContext("2d");return t.font=i,Math.max(...h.map((e=>t.measureText(e).width)))})():0,u=r+l/2,m=d+2*u;return{width:m,height:(f?n+c*(f-1):0)+2*u,draw(o){let r,s=u+n/2;Object.assign(o,{fillStyle:e,font:i,lineWidth:l,miterLimit:1,strokeStyle:a,textAlign:(()=>{switch(t){case"left":return r=u,"left";case"right":return r=m-u,"right"}return r=m/2,"center"})(),textBaseline:"middle"}),h.forEach((t=>{o.fillText(t,r,s),l&&o.strokeText(t,r,s),s+=c}))}}}};return i.prototype.isTextTexture=!0,i}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("three")):"function"==typeof define&&define.amd?define(["three"],e):((t="undefined"!=typeof globalThis?globalThis:t||self).THREE=t.THREE||{},t.THREE.TextTexture=e(t.THREE))}(this,(function(t){"use strict";let e=class extends t.Texture{constructor(){super(document.createElement("canvas"));let e=null,i=()=>e||(e=this.createDrawable()),n=()=>i().width,o=()=>i().height,r=!0,l=1,a=()=>t.MathUtils.ceilPowerOfTwo(n()*l),s=()=>t.MathUtils.ceilPowerOfTwo(o()*l),h=t=>{if(l!==t){let e=a(),i=s();l=t;let n=a(),o=s();n===e&&o===i||(r=!0)}},f=(()=>{let e=new t.Vector3,i=new t.Vector3,r=new t.Vector3;return(t,l,a)=>{let s=n(),h=o();if(s&&h){t.getWorldPosition(i),a.getWorldPosition(e);let n=i.distanceTo(e);if(a.isPerspectiveCamera&&(n*=2*Math.tan(THREE.Math.degToRad(a.fov)/2)),(a.isPerspectiveCamera||a.isOrthographicCamera)&&(n/=a.zoom),n){var f,c;t.getWorldScale(r);let e=null!==(f=null===(c=l.capabilities)||void 0===c?void 0:c.maxTextureSize)&&void 0!==f?f:1/0;return Math.min(Math.max(r.x/n*(l.domElement.offsetWidth/s),r.y/n*(l.domElement.offsetHeight/h)),e/s,e/h)}}return 0}})();Object.defineProperties(this,{width:{get:n},height:{get:o},pixelRatio:{get:()=>l,set:h},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=a(),t.height=s(),t.width&&t.height?(e.save(),e.scale(t.width/n(),t.height/o()),((...t)=>{i().draw(...t)})(e),e.restore()):t.width=t.height=1,r=!1,this.needsUpdate=!0}},setOptimalPixelRatio(...t){h(f(...t))}})}};e.prototype.isDynamicTexture=!0;let i=class extends e{constructor({alignment:t="center",color:e="#fff",fontFamily:i="sans-serif",fontSize:n=16,fontStyle:o="normal",fontVariant:r="normal",fontWeight:l="normal",lineGap:a=1/4,padding:s=.5,strokeColor:h="#fff",strokeWidth:f=0,text:c=""}={}){super(),Object.entries({alignment:t,color:e,fontFamily:i,fontSize:n,fontStyle:o,fontVariant:r,fontWeight:l,lineGap:a,padding:s,strokeColor:h,strokeWidth:f,text:c}).forEach((([t,e])=>{Object.defineProperty(this,t,{get:()=>e,set(t){e!==t&&(e=t,this.needsRedraw=!0)}})}))}get lines(){return text?text.split("\n"):[]}get font(){return function(t,e,i,n,o){let r=document.createElement("span");return r.style.font="1px serif",r.style.fontFamily=t,r.style.fontSize="".concat(e,"px"),r.style.fontStyle=i,r.style.fontVariant=n,r.style.fontWeight=o,r.style.font}(this.fontFamily,this.fontSize,this.fontStyle,this.fontVariant,this.fontWeight)}checkFontFace(){try{let{font:t,lines:e}=this;return e.every((e=>document.fonts.check(t,e)))}catch{}return!0}async loadFontFace(){try{let{font:t,lines:e}=this;return await Promise.all(e.map((e=>document.fonts.load(t,e))))}catch{}}createDrawable(){let{alignment:t,color:e,font:i,fontSize:n,lineGap:o,lines:r,padding:l,strokeColor:a,strokeWidth:s}=this;l*=n,o*=n,s*=n;let h=r.length,f=n+o,c=h?(()=>{let t=document.createElement("canvas").getContext("2d");return t.font=i,Math.max(...r.map((e=>t.measureText(e).width)))})():0,d=l+s/2,u=c+2*d;return{width:u,height:(h?n+f*(h-1):0)+2*d,draw(o){let l,h=d+n/2;Object.assign(o,{fillStyle:e,font:i,lineWidth:s,miterLimit:1,strokeStyle:a,textAlign:(()=>{switch(t){case"left":return l=d,"left";case"right":return l=u-d,"right"}return l=u/2,"center"})(),textBaseline:"middle"}),r.forEach((t=>{o.fillText(t,l,h),s&&o.strokeText(t,l,h),h+=f}))}}}};return i.prototype.isTextTexture=!0,i}));
{
"name": "@seregpie/three.text-texture",
"version": "3.0.0",
"version": "3.1.0",
"description": "A texture with the drawn text.",

@@ -12,4 +12,7 @@ "keywords": [

"author": "Sergej Sintschilin <seregpie@gmail.com>",
"files": [],
"files": [
"index.d.ts"
],
"main": "index.js",
"types": "index.d.ts",
"repository": "github:SeregPie/THREE.TextTexture",

@@ -16,0 +19,0 @@ "scripts": {

@@ -140,2 +140,10 @@ # THREE.TextTexture

`.lines`
*read-only*
The text split by the new line character.
---
`.font`

@@ -142,0 +150,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc