Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

three-spritetext

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

three-spritetext - npm Package Compare versions

Comparing version 1.6.5 to 1.7.0

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

// Version 1.6.5 three-spritetext - https://github.com/vasturiano/three-spritetext
// Version 1.7.0 three-spritetext - https://github.com/vasturiano/three-spritetext
(function (global, factory) {

@@ -8,2 +8,29 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('three')) :

function _iterableToArrayLimit(arr, i) {
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
if (null != _i) {
var _s,
_e,
_x,
_r,
_arr = [],
_n = !0,
_d = !1;
try {
if (_x = (_i = _i.call(arr)).next, 0 === i) {
if (Object(_i) !== _i) return;
_n = !1;
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
} catch (err) {
_d = !0, _e = err;
} finally {
try {
if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
} finally {
if (_d) throw _e;
}
}
return _arr;
}
}
function _classCallCheck(instance, Constructor) {

@@ -14,3 +41,2 @@ if (!(instance instanceof Constructor)) {

}
function _defineProperties(target, props) {

@@ -22,6 +48,5 @@ for (var i = 0; i < props.length; i++) {

if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {

@@ -35,3 +60,2 @@ if (protoProps) _defineProperties(Constructor.prototype, protoProps);

}
function _inherits(subClass, superClass) {

@@ -41,3 +65,2 @@ if (typeof superClass !== "function" && superClass !== null) {

}
subClass.prototype = Object.create(superClass && superClass.prototype, {

@@ -55,5 +78,4 @@ constructor: {

}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);

@@ -63,12 +85,9 @@ };

}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {

@@ -78,3 +97,2 @@ if (typeof Reflect === "undefined" || !Reflect.construct) return false;

if (typeof Proxy === "function") return true;
try {

@@ -87,3 +105,2 @@ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));

}
function _assertThisInitialized(self) {

@@ -93,6 +110,4 @@ if (self === void 0) {

}
return self;
}
function _possibleConstructorReturn(self, call) {

@@ -104,16 +119,11 @@ if (call && (typeof call === "object" || typeof call === "function")) {

}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);

@@ -123,57 +133,20 @@ } else {

}
return _possibleConstructorReturn(this, result);
};
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _iterableToArrayLimit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _unsupportedIterableToArray(o, minLen) {

@@ -187,18 +160,27 @@ if (!o) return;

}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}

@@ -212,17 +194,11 @@ var three = typeof window !== 'undefined' && window.THREE ? window.THREE // Prefer consumption from global THREE, if exists

};
var _default = /*#__PURE__*/function (_three$Sprite) {
_inherits(_default, _three$Sprite);
var _super = _createSuper(_default);
function _default() {
var _this;
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var textHeight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
var color = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'rgba(255, 255, 255, 1)';
_classCallCheck(this, _default);
_this = _super.call(this, new three.SpriteMaterial());

@@ -242,11 +218,7 @@ _this._text = "".concat(text);

_this._fontSize = 90; // defines text resolution
_this._fontWeight = 'normal';
_this._canvas = document.createElement('canvas');
_this._genCanvas();
return _this;
}
_createClass(_default, [{

@@ -259,3 +231,2 @@ key: "text",

this._text = text;
this._genCanvas();

@@ -270,3 +241,2 @@ }

this._textHeight = textHeight;
this._genCanvas();

@@ -281,3 +251,2 @@ }

this._color = color;
this._genCanvas();

@@ -292,3 +261,2 @@ }

this._backgroundColor = color;
this._genCanvas();

@@ -303,3 +271,2 @@ }

this._padding = padding;
this._genCanvas();

@@ -314,3 +281,2 @@ }

this._borderWidth = borderWidth;
this._genCanvas();

@@ -325,3 +291,2 @@ }

this._borderRadius = borderRadius;
this._genCanvas();

@@ -336,3 +301,2 @@ }

this._borderColor = borderColor;
this._genCanvas();

@@ -347,3 +311,2 @@ }

this._fontFace = fontFace;
this._genCanvas();

@@ -358,3 +321,2 @@ }

this._fontSize = fontSize;
this._genCanvas();

@@ -369,3 +331,2 @@ }

this._fontWeight = fontWeight;
this._genCanvas();

@@ -380,3 +341,2 @@ }

this._strokeWidth = strokeWidth;
this._genCanvas();

@@ -391,3 +351,2 @@ }

this._strokeColor = strokeColor;
this._genCanvas();

@@ -399,7 +358,5 @@ }

var _this2 = this;
var canvas = this._canvas;
var ctx = canvas.getContext('2d');
var border = Array.isArray(this.borderWidth) ? this.borderWidth : [this.borderWidth, this.borderWidth]; // x,y border
var relBorder = border.map(function (b) {

@@ -410,3 +367,2 @@ return b * _this2.fontSize * 0.1;

var borderRadius = Array.isArray(this.borderRadius) ? this.borderRadius : [this.borderRadius, this.borderRadius, this.borderRadius, this.borderRadius]; // tl tr br bl corners
var relBorderRadius = borderRadius.map(function (b) {

@@ -417,3 +373,2 @@ return b * _this2.fontSize * 0.1;

var padding = Array.isArray(this.padding) ? this.padding : [this.padding, this.padding]; // x,y padding
var relPadding = padding.map(function (p) {

@@ -426,3 +381,2 @@ return p * _this2.fontSize * 0.1;

ctx.font = font; // measure canvas with appropriate font
var innerWidth = Math.max.apply(Math, _toConsumableArray(lines.map(function (line) {

@@ -433,7 +387,7 @@ return ctx.measureText(line).width;

canvas.width = innerWidth + relBorder[0] * 2 + relPadding[0] * 2;
canvas.height = innerHeight + relBorder[1] * 2 + relPadding[1] * 2; // paint border
canvas.height = innerHeight + relBorder[1] * 2 + relPadding[1] * 2;
// paint border
if (this.borderWidth) {
ctx.strokeStyle = this.borderColor;
if (relBorder[0]) {

@@ -450,7 +404,5 @@ // left + right borders

}
if (relBorder[1]) {
// top + bottom borders
var _hb = relBorder[1] / 2;
ctx.lineWidth = relBorder[1];

@@ -464,9 +416,6 @@ ctx.beginPath();

}
if (this.borderRadius) {
// strike rounded corners
var cornerWidth = Math.max.apply(Math, _toConsumableArray(relBorder));
var _hb2 = cornerWidth / 2;
ctx.lineWidth = cornerWidth;

@@ -478,7 +427,6 @@ ctx.beginPath();

var _ref2 = _slicedToArray(_ref, 4),
x0 = _ref2[0],
x1 = _ref2[1],
y0 = _ref2[2],
y1 = _ref2[3];
x0 = _ref2[0],
x1 = _ref2[1],
y0 = _ref2[2],
y1 = _ref2[3];
ctx.moveTo(x0, y0);

@@ -489,8 +437,7 @@ ctx.quadraticCurveTo(x1, y0, x1, y1);

}
} // paint background
}
// paint background
if (this.backgroundColor) {
ctx.fillStyle = this.backgroundColor;
if (!this.borderRadius) {

@@ -502,15 +449,17 @@ ctx.fillRect(relBorder[0], relBorder[1], canvas.width - relBorder[0] * 2, canvas.height - relBorder[1] * 2);

ctx.moveTo(relBorder[0], relBorderRadius[0]);
[[relBorder[0], relBorderRadius[0], canvas.width - relBorderRadius[1], relBorder[1], relBorder[1], relBorder[1]], // t
[canvas.width - relBorder[0], canvas.width - relBorder[0], canvas.width - relBorder[0], relBorder[1], relBorderRadius[1], canvas.height - relBorderRadius[2]], // r
[canvas.width - relBorder[0], canvas.width - relBorderRadius[2], relBorderRadius[3], canvas.height - relBorder[1], canvas.height - relBorder[1], canvas.height - relBorder[1]], // b
[[relBorder[0], relBorderRadius[0], canvas.width - relBorderRadius[1], relBorder[1], relBorder[1], relBorder[1]],
// t
[canvas.width - relBorder[0], canvas.width - relBorder[0], canvas.width - relBorder[0], relBorder[1], relBorderRadius[1], canvas.height - relBorderRadius[2]],
// r
[canvas.width - relBorder[0], canvas.width - relBorderRadius[2], relBorderRadius[3], canvas.height - relBorder[1], canvas.height - relBorder[1], canvas.height - relBorder[1]],
// b
[relBorder[0], relBorder[0], relBorder[0], canvas.height - relBorder[1], canvas.height - relBorderRadius[3], relBorderRadius[0]] // t
].forEach(function (_ref3) {
var _ref4 = _slicedToArray(_ref3, 6),
x0 = _ref4[0],
x1 = _ref4[1],
x2 = _ref4[2],
y0 = _ref4[3],
y1 = _ref4[4],
y2 = _ref4[5];
x0 = _ref4[0],
x1 = _ref4[1],
x2 = _ref4[2],
y0 = _ref4[3],
y1 = _ref4[4],
y2 = _ref4[5];
ctx.quadraticCurveTo(x0, y0, x1, y1);

@@ -523,12 +472,10 @@ ctx.lineTo(x2, y2);

}
ctx.translate.apply(ctx, _toConsumableArray(relBorder));
ctx.translate.apply(ctx, _toConsumableArray(relPadding)); // paint text
ctx.translate.apply(ctx, _toConsumableArray(relPadding));
// paint text
ctx.font = font; // Set font again after canvas is resized, as context properties are reset
ctx.fillStyle = this.color;
ctx.textBaseline = 'bottom';
var drawTextStroke = this.strokeWidth > 0;
if (drawTextStroke) {

@@ -538,3 +485,2 @@ ctx.lineWidth = this.strokeWidth * this.fontSize / 10;

}
lines.forEach(function (line, index) {

@@ -545,6 +491,6 @@ var lineX = (innerWidth - ctx.measureText(line).width) / 2;

ctx.fillText(line, lineX, lineY);
}); // Inject canvas into sprite
});
// Inject canvas into sprite
if (this.material.map) this.material.map.dispose(); // gc previous texture
var texture = this.material.map = new three.Texture(canvas);

@@ -578,3 +524,2 @@ texture.minFilter = three.LinearFilter;

}]);
return _default;

@@ -581,0 +526,0 @@ }(three.Sprite);

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

// Version 1.6.5 three-spritetext - https://github.com/vasturiano/three-spritetext
!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).SpriteText=e(t.THREE)}(this,(function(t){"use strict";function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}function n(t,e){return n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},n(t,e)}function o(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function a(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=i(t);if(e){var a=i(this).constructor;r=Reflect.construct(n,arguments,a)}else r=n.apply(this,arguments);return o(this,r)}}function h(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null==r)return;var i,n,o=[],a=!0,h=!1;try{for(r=r.call(t);!(a=(i=r.next()).done)&&(o.push(i.value),!e||o.length!==e);a=!0);}catch(t){h=!0,n=t}finally{try{a||null==r.return||r.return()}finally{if(h)throw n}}return o}(t,e)||u(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(t){return function(t){if(Array.isArray(t))return c(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||u(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(t,e){if(t){if("string"==typeof t)return c(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?c(t,e):void 0}}function c(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=new Array(e);r<e;r++)i[r]=t[r];return i}var f="undefined"!=typeof window&&window.THREE?window.THREE:{LinearFilter:t.LinearFilter,Sprite:t.Sprite,SpriteMaterial:t.SpriteMaterial,Texture:t.Texture},l=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&n(t,e)}(l,t);var i,o,u,c=a(l);function l(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"rgba(255, 255, 255, 1)";return e(this,l),(t=c.call(this,new f.SpriteMaterial))._text="".concat(r),t._textHeight=i,t._color=n,t._backgroundColor=!1,t._padding=0,t._borderWidth=0,t._borderRadius=0,t._borderColor="white",t._strokeWidth=0,t._strokeColor="white",t._fontFace="Arial",t._fontSize=90,t._fontWeight="normal",t._canvas=document.createElement("canvas"),t._genCanvas(),t}return i=l,(o=[{key:"text",get:function(){return this._text},set:function(t){this._text=t,this._genCanvas()}},{key:"textHeight",get:function(){return this._textHeight},set:function(t){this._textHeight=t,this._genCanvas()}},{key:"color",get:function(){return this._color},set:function(t){this._color=t,this._genCanvas()}},{key:"backgroundColor",get:function(){return this._backgroundColor},set:function(t){this._backgroundColor=t,this._genCanvas()}},{key:"padding",get:function(){return this._padding},set:function(t){this._padding=t,this._genCanvas()}},{key:"borderWidth",get:function(){return this._borderWidth},set:function(t){this._borderWidth=t,this._genCanvas()}},{key:"borderRadius",get:function(){return this._borderRadius},set:function(t){this._borderRadius=t,this._genCanvas()}},{key:"borderColor",get:function(){return this._borderColor},set:function(t){this._borderColor=t,this._genCanvas()}},{key:"fontFace",get:function(){return this._fontFace},set:function(t){this._fontFace=t,this._genCanvas()}},{key:"fontSize",get:function(){return this._fontSize},set:function(t){this._fontSize=t,this._genCanvas()}},{key:"fontWeight",get:function(){return this._fontWeight},set:function(t){this._fontWeight=t,this._genCanvas()}},{key:"strokeWidth",get:function(){return this._strokeWidth},set:function(t){this._strokeWidth=t,this._genCanvas()}},{key:"strokeColor",get:function(){return this._strokeColor},set:function(t){this._strokeColor=t,this._genCanvas()}},{key:"_genCanvas",value:function(){var t=this,e=this._canvas,r=e.getContext("2d"),i=Array.isArray(this.borderWidth)?this.borderWidth:[this.borderWidth,this.borderWidth],n=i.map((function(e){return e*t.fontSize*.1})),o=(Array.isArray(this.borderRadius)?this.borderRadius:[this.borderRadius,this.borderRadius,this.borderRadius,this.borderRadius]).map((function(e){return e*t.fontSize*.1})),a=Array.isArray(this.padding)?this.padding:[this.padding,this.padding],u=a.map((function(e){return e*t.fontSize*.1})),c=this.text.split("\n"),l="".concat(this.fontWeight," ").concat(this.fontSize,"px ").concat(this.fontFace);r.font=l;var d=Math.max.apply(Math,s(c.map((function(t){return r.measureText(t).width})))),g=this.fontSize*c.length;if(e.width=d+2*n[0]+2*u[0],e.height=g+2*n[1]+2*u[1],this.borderWidth){if(r.strokeStyle=this.borderColor,n[0]){var p=n[0]/2;r.lineWidth=n[0],r.beginPath(),r.moveTo(p,o[0]),r.lineTo(p,e.height-o[3]),r.moveTo(e.width-p,o[1]),r.lineTo(e.width-p,e.height-o[2]),r.stroke()}if(n[1]){var y=n[1]/2;r.lineWidth=n[1],r.beginPath(),r.moveTo(Math.max(n[0],o[0]),y),r.lineTo(e.width-Math.max(n[0],o[1]),y),r.moveTo(Math.max(n[0],o[3]),e.height-y),r.lineTo(e.width-Math.max(n[0],o[2]),e.height-y),r.stroke()}if(this.borderRadius){var b=Math.max.apply(Math,s(n)),v=b/2;r.lineWidth=b,r.beginPath(),[!!o[0]&&[o[0],v,v,o[0]],!!o[1]&&[e.width-o[1],e.width-v,v,o[1]],!!o[2]&&[e.width-o[2],e.width-v,e.height-v,e.height-o[2]],!!o[3]&&[o[3],v,e.height-v,e.height-o[3]]].filter((function(t){return t})).forEach((function(t){var e=h(t,4),i=e[0],n=e[1],o=e[2],a=e[3];r.moveTo(i,o),r.quadraticCurveTo(n,o,n,a)})),r.stroke()}}this.backgroundColor&&(r.fillStyle=this.backgroundColor,this.borderRadius?(r.beginPath(),r.moveTo(n[0],o[0]),[[n[0],o[0],e.width-o[1],n[1],n[1],n[1]],[e.width-n[0],e.width-n[0],e.width-n[0],n[1],o[1],e.height-o[2]],[e.width-n[0],e.width-o[2],o[3],e.height-n[1],e.height-n[1],e.height-n[1]],[n[0],n[0],n[0],e.height-n[1],e.height-o[3],o[0]]].forEach((function(t){var e=h(t,6),i=e[0],n=e[1],o=e[2],a=e[3],s=e[4],u=e[5];r.quadraticCurveTo(i,a,n,s),r.lineTo(o,u)})),r.closePath(),r.fill()):r.fillRect(n[0],n[1],e.width-2*n[0],e.height-2*n[1])),r.translate.apply(r,s(n)),r.translate.apply(r,s(u)),r.font=l,r.fillStyle=this.color,r.textBaseline="bottom";var _=this.strokeWidth>0;_&&(r.lineWidth=this.strokeWidth*this.fontSize/10,r.strokeStyle=this.strokeColor),c.forEach((function(e,i){var n=(d-r.measureText(e).width)/2,o=(i+1)*t.fontSize;_&&r.strokeText(e,n,o),r.fillText(e,n,o)})),this.material.map&&this.material.map.dispose();var m=this.material.map=new f.Texture(e);m.minFilter=f.LinearFilter,m.needsUpdate=!0;var w=this.textHeight*c.length+2*i[1]+2*a[1];this.scale.set(w*e.width/e.height,w,0)}},{key:"clone",value:function(){return new this.constructor(this.text,this.textHeight,this.color).copy(this)}},{key:"copy",value:function(t){return f.Sprite.prototype.copy.call(this,t),this.color=t.color,this.backgroundColor=t.backgroundColor,this.padding=t.padding,this.borderWidth=t.borderWidth,this.borderColor=t.borderColor,this.fontFace=t.fontFace,this.fontSize=t.fontSize,this.fontWeight=t.fontWeight,this.strokeWidth=t.strokeWidth,this.strokeColor=t.strokeColor,this}}])&&r(i.prototype,o),u&&r(i,u),Object.defineProperty(i,"prototype",{writable:!1}),l}(f.Sprite);return l}));
// Version 1.7.0 three-spritetext - https://github.com/vasturiano/three-spritetext
!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).SpriteText=e(t.THREE)}(this,(function(t){"use strict";function e(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,(n=i.key,o=void 0,"symbol"==typeof(o=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(n,"string"))?o:String(o)),i)}var n,o}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}function n(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function o(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var i,o=r(t);if(e){var a=r(this).constructor;i=Reflect.construct(o,arguments,a)}else i=o.apply(this,arguments);return n(this,i)}}function a(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var i,n,o,a,h=[],s=!0,u=!1;try{if(o=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;s=!1}else for(;!(s=(i=o.call(r)).done)&&(h.push(i.value),h.length!==e);s=!0);}catch(t){u=!0,n=t}finally{try{if(!s&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(u)throw n}}return h}}(t,e)||s(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(t){return function(t){if(Array.isArray(t))return u(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||s(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(t,e){if(t){if("string"==typeof t)return u(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(t,e):void 0}}function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=new Array(e);r<e;r++)i[r]=t[r];return i}var c="undefined"!=typeof window&&window.THREE?window.THREE:{LinearFilter:t.LinearFilter,Sprite:t.Sprite,SpriteMaterial:t.SpriteMaterial,Texture:t.Texture},f=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&i(t,e)}(f,t);var r,n,s,u=o(f);function f(){var t,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"rgba(255, 255, 255, 1)";return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,f),(t=u.call(this,new c.SpriteMaterial))._text="".concat(e),t._textHeight=r,t._color=i,t._backgroundColor=!1,t._padding=0,t._borderWidth=0,t._borderRadius=0,t._borderColor="white",t._strokeWidth=0,t._strokeColor="white",t._fontFace="Arial",t._fontSize=90,t._fontWeight="normal",t._canvas=document.createElement("canvas"),t._genCanvas(),t}return r=f,(n=[{key:"text",get:function(){return this._text},set:function(t){this._text=t,this._genCanvas()}},{key:"textHeight",get:function(){return this._textHeight},set:function(t){this._textHeight=t,this._genCanvas()}},{key:"color",get:function(){return this._color},set:function(t){this._color=t,this._genCanvas()}},{key:"backgroundColor",get:function(){return this._backgroundColor},set:function(t){this._backgroundColor=t,this._genCanvas()}},{key:"padding",get:function(){return this._padding},set:function(t){this._padding=t,this._genCanvas()}},{key:"borderWidth",get:function(){return this._borderWidth},set:function(t){this._borderWidth=t,this._genCanvas()}},{key:"borderRadius",get:function(){return this._borderRadius},set:function(t){this._borderRadius=t,this._genCanvas()}},{key:"borderColor",get:function(){return this._borderColor},set:function(t){this._borderColor=t,this._genCanvas()}},{key:"fontFace",get:function(){return this._fontFace},set:function(t){this._fontFace=t,this._genCanvas()}},{key:"fontSize",get:function(){return this._fontSize},set:function(t){this._fontSize=t,this._genCanvas()}},{key:"fontWeight",get:function(){return this._fontWeight},set:function(t){this._fontWeight=t,this._genCanvas()}},{key:"strokeWidth",get:function(){return this._strokeWidth},set:function(t){this._strokeWidth=t,this._genCanvas()}},{key:"strokeColor",get:function(){return this._strokeColor},set:function(t){this._strokeColor=t,this._genCanvas()}},{key:"_genCanvas",value:function(){var t=this,e=this._canvas,r=e.getContext("2d"),i=Array.isArray(this.borderWidth)?this.borderWidth:[this.borderWidth,this.borderWidth],n=i.map((function(e){return e*t.fontSize*.1})),o=(Array.isArray(this.borderRadius)?this.borderRadius:[this.borderRadius,this.borderRadius,this.borderRadius,this.borderRadius]).map((function(e){return e*t.fontSize*.1})),s=Array.isArray(this.padding)?this.padding:[this.padding,this.padding],u=s.map((function(e){return e*t.fontSize*.1})),f=this.text.split("\n"),l="".concat(this.fontWeight," ").concat(this.fontSize,"px ").concat(this.fontFace);r.font=l;var d=Math.max.apply(Math,h(f.map((function(t){return r.measureText(t).width})))),g=this.fontSize*f.length;if(e.width=d+2*n[0]+2*u[0],e.height=g+2*n[1]+2*u[1],this.borderWidth){if(r.strokeStyle=this.borderColor,n[0]){var p=n[0]/2;r.lineWidth=n[0],r.beginPath(),r.moveTo(p,o[0]),r.lineTo(p,e.height-o[3]),r.moveTo(e.width-p,o[1]),r.lineTo(e.width-p,e.height-o[2]),r.stroke()}if(n[1]){var y=n[1]/2;r.lineWidth=n[1],r.beginPath(),r.moveTo(Math.max(n[0],o[0]),y),r.lineTo(e.width-Math.max(n[0],o[1]),y),r.moveTo(Math.max(n[0],o[3]),e.height-y),r.lineTo(e.width-Math.max(n[0],o[2]),e.height-y),r.stroke()}if(this.borderRadius){var b=Math.max.apply(Math,h(n)),v=b/2;r.lineWidth=b,r.beginPath(),[!!o[0]&&[o[0],v,v,o[0]],!!o[1]&&[e.width-o[1],e.width-v,v,o[1]],!!o[2]&&[e.width-o[2],e.width-v,e.height-v,e.height-o[2]],!!o[3]&&[o[3],v,e.height-v,e.height-o[3]]].filter((function(t){return t})).forEach((function(t){var e=a(t,4),i=e[0],n=e[1],o=e[2],h=e[3];r.moveTo(i,o),r.quadraticCurveTo(n,o,n,h)})),r.stroke()}}this.backgroundColor&&(r.fillStyle=this.backgroundColor,this.borderRadius?(r.beginPath(),r.moveTo(n[0],o[0]),[[n[0],o[0],e.width-o[1],n[1],n[1],n[1]],[e.width-n[0],e.width-n[0],e.width-n[0],n[1],o[1],e.height-o[2]],[e.width-n[0],e.width-o[2],o[3],e.height-n[1],e.height-n[1],e.height-n[1]],[n[0],n[0],n[0],e.height-n[1],e.height-o[3],o[0]]].forEach((function(t){var e=a(t,6),i=e[0],n=e[1],o=e[2],h=e[3],s=e[4],u=e[5];r.quadraticCurveTo(i,h,n,s),r.lineTo(o,u)})),r.closePath(),r.fill()):r.fillRect(n[0],n[1],e.width-2*n[0],e.height-2*n[1])),r.translate.apply(r,h(n)),r.translate.apply(r,h(u)),r.font=l,r.fillStyle=this.color,r.textBaseline="bottom";var _=this.strokeWidth>0;_&&(r.lineWidth=this.strokeWidth*this.fontSize/10,r.strokeStyle=this.strokeColor),f.forEach((function(e,i){var n=(d-r.measureText(e).width)/2,o=(i+1)*t.fontSize;_&&r.strokeText(e,n,o),r.fillText(e,n,o)})),this.material.map&&this.material.map.dispose();var m=this.material.map=new c.Texture(e);m.minFilter=c.LinearFilter,m.needsUpdate=!0;var w=this.textHeight*f.length+2*i[1]+2*s[1];this.scale.set(w*e.width/e.height,w,0)}},{key:"clone",value:function(){return new this.constructor(this.text,this.textHeight,this.color).copy(this)}},{key:"copy",value:function(t){return c.Sprite.prototype.copy.call(this,t),this.color=t.color,this.backgroundColor=t.backgroundColor,this.padding=t.padding,this.borderWidth=t.borderWidth,this.borderColor=t.borderColor,this.fontFace=t.fontFace,this.fontSize=t.fontSize,this.fontWeight=t.fontWeight,this.strokeWidth=t.strokeWidth,this.strokeColor=t.strokeColor,this}}])&&e(r.prototype,n),s&&e(r,s),Object.defineProperty(r,"prototype",{writable:!1}),f}(c.Sprite);return f}));
{
"name": "three-spritetext",
"version": "1.6.5",
"version": "1.7.0",
"description": "A sprite based text component for ThreeJS",
"type": "module",
"unpkg": "dist/three-spritetext.min.js",
"main": "dist/three-spritetext.common.js",
"module": "dist/three-spritetext.module.js",
"main": "dist/three-spritetext.mjs",
"module": "dist/three-spritetext.mjs",
"types": "dist/three-spritetext.d.ts",
"exports": {
"umd": "./dist/three-spritetext.min.js",
"default": "./dist/three-spritetext.mjs"
},
"repository": {

@@ -44,16 +49,17 @@ "type": "git",

"devDependencies": {
"@babel/core": "^7.17.4",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-proposal-object-rest-spread": "^7.17.3",
"@babel/preset-env": "^7.16.11",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-node-resolve": "^13.1.3",
"@babel/core": "^7.20.12",
"@babel/preset-env": "^7.20.2",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@types/three": ">=0.86.0",
"rimraf": "^3.0.2",
"rollup": "^2.67.2",
"rollup-plugin-dts": "^4.1.0",
"rollup-plugin-terser": "^7.0.2",
"typescript": "^4.5.5"
"rimraf": "^4.1.2",
"rollup": "^3.14.0",
"rollup-plugin-dts": "^5.1.1",
"typescript": "^4.9.5"
},
"engines": {
"node": ">=12"
}
}

@@ -16,7 +16,3 @@ three-spritetext

```
or
```js
const SpriteText = require('three-spritetext');
```
or even
or using a *script* tag
```html

@@ -23,0 +19,0 @@ <script src="//unpkg.com/three-spritetext"></script>

Sorry, the diff of this file is not supported yet