troika-3d-text
Advanced tools
Comparing version 0.52.1 to 0.52.2
@@ -6,2 +6,13 @@ # Change Log | ||
## [0.52.2](https://github.com/protectwise/troika/compare/v0.52.1...v0.52.2) (2024-11-21) | ||
### Bug Fixes | ||
* **BatchedText:** Fix removing text instances ([8bf4bca](https://github.com/protectwise/troika/commit/8bf4bca24e0aa05c681f183edfaaca7620e2eefd)) | ||
## [0.52.1](https://github.com/protectwise/troika/compare/v0.52.0...v0.52.1) (2024-11-21) | ||
@@ -8,0 +19,0 @@ |
@@ -375,4 +375,9 @@ import { getSelectionRects, getCaretAtPoint, Text, BatchedText } from 'troika-three-text'; | ||
this._texts.children = this.children; | ||
const prevTexts = new Set(this._texts.threeObject.children); | ||
this._texts.afterUpdate(); | ||
this._texts.forEachChild(text => this.threeObject.addText(text.threeObject)); | ||
this._texts.threeObject.children.forEach(text => { | ||
this.threeObject.addText(text); | ||
prevTexts.delete(text); | ||
}); | ||
prevTexts.forEach(text => this.threeObject.removeText(text)); | ||
super.afterUpdate(); | ||
@@ -379,0 +384,0 @@ } |
@@ -375,4 +375,9 @@ (function (global, factory) { | ||
this._texts.children = this.children; | ||
const prevTexts = new Set(this._texts.threeObject.children); | ||
this._texts.afterUpdate(); | ||
this._texts.forEachChild(text => this.threeObject.addText(text.threeObject)); | ||
this._texts.threeObject.children.forEach(text => { | ||
this.threeObject.addText(text); | ||
prevTexts.delete(text); | ||
}); | ||
prevTexts.forEach(text => this.threeObject.removeText(text)); | ||
super.afterUpdate(); | ||
@@ -379,0 +384,0 @@ } |
@@ -1,14 +0,14 @@ | ||
'use strict';(function(b,e){"object"===typeof exports&&"undefined"!==typeof module?e(exports,require("troika-three-text"),require("troika-3d"),require("three"),require("troika-three-utils")):"function"===typeof define&&define.amd?define(["exports","troika-three-text","troika-3d","three","troika-three-utils"],e):(b="undefined"!==typeof globalThis?globalThis:b||self,e(b.troika_3d_text={},b.troika_three_text,b.troika_3d,b.THREE,b.troika_three_utils))})(this,function(b,e,g,d,v){let m=new d.Vector4,n= | ||
function(){let a=g.createDerivedMaterial(new d.MeshBasicMaterial({transparent:!0,opacity:.3,depthWrite:!1}),{uniforms:{rect:{value:new d.Vector4},depthAndCurveRadius:{value:new d.Vector2}},vertexDefs:"\nuniform vec4 rect;\nuniform vec2 depthAndCurveRadius;\n",vertexTransform:"\nfloat depth = depthAndCurveRadius.x;\nfloat rad = depthAndCurveRadius.y;\nposition.x = mix(rect.x, rect.z, position.x);\nposition.y = mix(rect.w, rect.y, position.y);\nposition.z = mix(-depth * 0.5, depth * 0.5, position.z);\nif (rad != 0.0) {\n float angle = position.x / rad;\n position.xz = vec2(sin(angle) * (rad - position.z), rad - cos(angle) * (rad - position.z));\n // TODO fix normals: normal.xz = vec2(sin(angle), cos(angle));\n}\n"}), | ||
b={normal:new d.Mesh((new d.BoxGeometry(1,1,1)).translate(.5,.5,.5),a),curved:new d.Mesh((new d.BoxGeometry(1,1,1,32)).translate(.5,.5,.5),a)};return(n=()=>b)()};class w extends g.Instanceable3DFacade{constructor(a){super(a);this.curveRadius=this.depth=0;this._color=new d.Color;this._rect=new d.Vector4}afterUpdate(){let {top:a,right:b,bottom:e,left:c,color:p,depth:h,curveRadius:l}=this;this.instancedThreeObject=n()[l?"curved":"normal"];this._color.equals(p)||this.setInstanceUniform("diffuse",this._color= | ||
new d.Color(p));this._rect.equals(m.set(c,a,b,e))||this.setInstanceUniform("rect",m.clone());!h===this._depth&&l===this._curveRadius||this.setInstanceUniform("depthAndCurveRadius",new d.Vector2(this._depth=h,this._curveRadius=l));super.afterUpdate()}getBoundingSphere(){return null}}let x=new d.Matrix4,y=new d.Plane,q=new d.Vector2,z=new d.Vector3,r=Object.freeze([-Infinity,-Infinity,Infinity,Infinity]);class A extends g.ListFacade{constructor(a,b){super(a);let d=a.threeObject;this.rangeColor=52479; | ||
this.clipRect=r;this.curveRadius=0;this.template={key:(a,b)=>`rect${b}`,facade:w,top:a=>Math.min(this.clipRect[3],Math.max(this.clipRect[1],a.top)),right:a=>Math.min(this.clipRect[2],Math.max(this.clipRect[0],a.right)),bottom:a=>Math.min(this.clipRect[3],Math.max(this.clipRect[1],a.bottom)),left:a=>Math.min(this.clipRect[2],Math.max(this.clipRect[0],a.left)),depth:a=>.25*(a.top-a.bottom),color:a=>this.rangeColor,curveRadius:a=>this.curveRadius,visible:a=>{let b=this.clipRect;return a.right>b[0]&& | ||
a.top>b[1]&&a.left<b[2]&&a.bottom<b[3]},renderOrder:a=>this.renderOrder||0};let c=c=>{var k=d.textRenderInfo;if(k){const t=d.worldPositionToTextCoords(c.intersection.point,q);if(k=e.getCaretAtPoint(k,t.x,t.y))b(k.charIndex,k.charIndex),a.addEventListener("drag",f),a.addEventListener("dragend",h);c.preventDefault()}},f=a=>{var c=d.textRenderInfo;if(a.ray&&c){var f;(f=(f=a.intersection)&&f.object===d&&f.point?d.worldPositionToTextCoords(f.point,q):a.ray.clone().applyMatrix4(v.invertMatrix4(d.matrixWorld, | ||
x)).intersectPlane(y.setComponents(0,0,1,0),z))&&(c=e.getCaretAtPoint(c,f.x,f.y))&&b(this.selectionStart,c.charIndex);a.preventDefault()}},h=b=>{a.removeEventListener("drag",f);a.removeEventListener("dragend",h)};a.addEventListener("dragstart",c);a.addEventListener("mousedown",c);this._cleanupEvents=()=>{h();a.removeEventListener("dragstart",c);a.removeEventListener("mousedown",c)}}afterUpdate(){this.data=e.getSelectionRects(this.textRenderInfo,this.selectionStart,this.selectionEnd);super.afterUpdate()}set clipRect(a){this._clipRect= | ||
a&&Array.isArray(a)&&4===a.length?a:r}get clipRect(){return this._clipRect}destructor(){this._cleanupEvents();super.destructor()}}let u="text anchorX anchorY font fontSize fontWeight fontStyle letterSpacing lineHeight maxWidth overflowWrap direction textAlign textIndent whiteSpace material color colorRanges fillOpacity outlineOpacity outlineColor outlineWidth outlineOffsetX outlineOffsetY outlineBlur strokeColor strokeWidth strokeOpacity curveRadius depthOffset clipRect orientation glyphGeometryDetail sdfGlyphSize unicodeFontsURL gpuAccelerateSDF debugSDF".split(" "); | ||
class B extends g.Object3DFacade{constructor(a){let b=new e.Text;b.geometry.boundingSphere.version=0;super(a,b);this.selectable=!1;this.selectionStart=this.selectionEnd=-1;this.onSyncComplete=this.onSyncStart=null;this.gpuAccelerateSDF=!0;b.addEventListener("syncstart",a=>{this.notifyWorld("text3DSyncStart");if(this.onSyncStart)this.onSyncStart()});b.addEventListener("synccomplete",a=>{if(!this.isDestroying&&(b.geometry.boundingSphere.version++,this.afterUpdate(),this.notifyWorld("text3DSyncComplete"), | ||
this.requestRender(),this.onSyncComplete))this.onSyncComplete()})}get textRenderInfo(){return this.threeObject.textRenderInfo}afterUpdate(){let a=this.threeObject;u.forEach(b=>{a[b]=this[b]});a.sync();super.afterUpdate();this.text!==this._prevText&&(this.selectionStart=this.selectionEnd=-1,this._prevText=this.text);this._updateSelection()}_updateSelection(){let {selectable:a,selectionStart:b,selectionEnd:d}=this,c=this._selectionFacade;a!==this._selectable&&((this._selectable=a)?c=this._selectionFacade= | ||
new A(this,(a,b)=>{this.selectionStart=a;this.selectionEnd=b;this._updateSelection();this.requestRender()}):(c&&(c.destructor(),c=this._selectionFacade=null),this.selectionStart=this.selectionEnd=-1));c&&(c.textRenderInfo=this.threeObject.textRenderInfo,c.selectionStart=b,c.selectionEnd=d,c.curveRadius=this.curveRadius||0,c.clipRect=this.clipRect,c.renderOrder=this.renderOrder,c.afterUpdate())}destructor(){this.threeObject.dispose();this._selectionFacade&&this._selectionFacade.destructor();super.destructor()}} | ||
class C extends g.Object3DFacade{constructor(a){super(a,new e.BatchedText);this._texts=new g.Object3DFacade(this);this._texts.visible=!1}afterUpdate(){u.forEach(a=>{this.threeObject[a]=this[a]});this._texts.children=this.children;this._texts.afterUpdate();this._texts.forEachChild(a=>this.threeObject.addText(a.threeObject));super.afterUpdate()}shouldUpdateChildren(){return!1}}Object.defineProperty(b,"GlyphsGeometry",{enumerable:!0,get:function(){return e.GlyphsGeometry}});Object.defineProperty(b,"TextMesh", | ||
{enumerable:!0,get:function(){return e.Text}});Object.defineProperty(b,"configureTextBuilder",{enumerable:!0,get:function(){return e.configureTextBuilder}});Object.defineProperty(b,"dumpSDFTextures",{enumerable:!0,get:function(){return e.dumpSDFTextures}});Object.defineProperty(b,"getCaretAtPoint",{enumerable:!0,get:function(){return e.getCaretAtPoint}});Object.defineProperty(b,"getSelectionRects",{enumerable:!0,get:function(){return e.getSelectionRects}});Object.defineProperty(b,"preloadFont",{enumerable:!0, | ||
get:function(){return e.preloadFont}});Object.defineProperty(b,"typesetterWorkerModule",{enumerable:!0,get:function(){return e.typesetterWorkerModule}});b.BatchedText3DFacade=C;b.Text3DFacade=B;Object.defineProperty(b,"__esModule",{value:!0})}) | ||
'use strict';(function(b,e){"object"===typeof exports&&"undefined"!==typeof module?e(exports,require("troika-three-text"),require("troika-3d"),require("three"),require("troika-three-utils")):"function"===typeof define&&define.amd?define(["exports","troika-three-text","troika-3d","three","troika-three-utils"],e):(b="undefined"!==typeof globalThis?globalThis:b||self,e(b.troika_3d_text={},b.troika_three_text,b.troika_3d,b.THREE,b.troika_three_utils))})(this,function(b,e,f,c,u){let m=new c.Vector4,n= | ||
function(){let a=f.createDerivedMaterial(new c.MeshBasicMaterial({transparent:!0,opacity:.3,depthWrite:!1}),{uniforms:{rect:{value:new c.Vector4},depthAndCurveRadius:{value:new c.Vector2}},vertexDefs:"\nuniform vec4 rect;\nuniform vec2 depthAndCurveRadius;\n",vertexTransform:"\nfloat depth = depthAndCurveRadius.x;\nfloat rad = depthAndCurveRadius.y;\nposition.x = mix(rect.x, rect.z, position.x);\nposition.y = mix(rect.w, rect.y, position.y);\nposition.z = mix(-depth * 0.5, depth * 0.5, position.z);\nif (rad != 0.0) {\n float angle = position.x / rad;\n position.xz = vec2(sin(angle) * (rad - position.z), rad - cos(angle) * (rad - position.z));\n // TODO fix normals: normal.xz = vec2(sin(angle), cos(angle));\n}\n"}), | ||
g={normal:new c.Mesh((new c.BoxGeometry(1,1,1)).translate(.5,.5,.5),a),curved:new c.Mesh((new c.BoxGeometry(1,1,1,32)).translate(.5,.5,.5),a)};return(n=()=>g)()};class v extends f.Instanceable3DFacade{constructor(a){super(a);this.curveRadius=this.depth=0;this._color=new c.Color;this._rect=new c.Vector4}afterUpdate(){let {top:a,right:g,bottom:b,left:d,color:e,depth:h,curveRadius:l}=this;this.instancedThreeObject=n()[l?"curved":"normal"];this._color.equals(e)||this.setInstanceUniform("diffuse",this._color= | ||
new c.Color(e));this._rect.equals(m.set(d,a,g,b))||this.setInstanceUniform("rect",m.clone());!h===this._depth&&l===this._curveRadius||this.setInstanceUniform("depthAndCurveRadius",new c.Vector2(this._depth=h,this._curveRadius=l));super.afterUpdate()}getBoundingSphere(){return null}}let w=new c.Matrix4,x=new c.Plane,p=new c.Vector2,y=new c.Vector3,q=Object.freeze([-Infinity,-Infinity,Infinity,Infinity]);class z extends f.ListFacade{constructor(a,g){super(a);let b=a.threeObject;this.rangeColor=52479; | ||
this.clipRect=q;this.curveRadius=0;this.template={key:(a,b)=>`rect${b}`,facade:v,top:a=>Math.min(this.clipRect[3],Math.max(this.clipRect[1],a.top)),right:a=>Math.min(this.clipRect[2],Math.max(this.clipRect[0],a.right)),bottom:a=>Math.min(this.clipRect[3],Math.max(this.clipRect[1],a.bottom)),left:a=>Math.min(this.clipRect[2],Math.max(this.clipRect[0],a.left)),depth:a=>.25*(a.top-a.bottom),color:a=>this.rangeColor,curveRadius:a=>this.curveRadius,visible:a=>{let b=this.clipRect;return a.right>b[0]&& | ||
a.top>b[1]&&a.left<b[2]&&a.bottom<b[3]},renderOrder:a=>this.renderOrder||0};let d=d=>{var k=b.textRenderInfo;if(k){const r=b.worldPositionToTextCoords(d.intersection.point,p);if(k=e.getCaretAtPoint(k,r.x,r.y))g(k.charIndex,k.charIndex),a.addEventListener("drag",c),a.addEventListener("dragend",h);d.preventDefault()}},c=a=>{var d=b.textRenderInfo;if(a.ray&&d){var c;(c=(c=a.intersection)&&c.object===b&&c.point?b.worldPositionToTextCoords(c.point,p):a.ray.clone().applyMatrix4(u.invertMatrix4(b.matrixWorld, | ||
w)).intersectPlane(x.setComponents(0,0,1,0),y))&&(d=e.getCaretAtPoint(d,c.x,c.y))&&g(this.selectionStart,d.charIndex);a.preventDefault()}},h=b=>{a.removeEventListener("drag",c);a.removeEventListener("dragend",h)};a.addEventListener("dragstart",d);a.addEventListener("mousedown",d);this._cleanupEvents=()=>{h();a.removeEventListener("dragstart",d);a.removeEventListener("mousedown",d)}}afterUpdate(){this.data=e.getSelectionRects(this.textRenderInfo,this.selectionStart,this.selectionEnd);super.afterUpdate()}set clipRect(a){this._clipRect= | ||
a&&Array.isArray(a)&&4===a.length?a:q}get clipRect(){return this._clipRect}destructor(){this._cleanupEvents();super.destructor()}}let t="text anchorX anchorY font fontSize fontWeight fontStyle letterSpacing lineHeight maxWidth overflowWrap direction textAlign textIndent whiteSpace material color colorRanges fillOpacity outlineOpacity outlineColor outlineWidth outlineOffsetX outlineOffsetY outlineBlur strokeColor strokeWidth strokeOpacity curveRadius depthOffset clipRect orientation glyphGeometryDetail sdfGlyphSize unicodeFontsURL gpuAccelerateSDF debugSDF".split(" "); | ||
class A extends f.Object3DFacade{constructor(a){let b=new e.Text;b.geometry.boundingSphere.version=0;super(a,b);this.selectable=!1;this.selectionStart=this.selectionEnd=-1;this.onSyncComplete=this.onSyncStart=null;this.gpuAccelerateSDF=!0;b.addEventListener("syncstart",a=>{this.notifyWorld("text3DSyncStart");if(this.onSyncStart)this.onSyncStart()});b.addEventListener("synccomplete",a=>{if(!this.isDestroying&&(b.geometry.boundingSphere.version++,this.afterUpdate(),this.notifyWorld("text3DSyncComplete"), | ||
this.requestRender(),this.onSyncComplete))this.onSyncComplete()})}get textRenderInfo(){return this.threeObject.textRenderInfo}afterUpdate(){let a=this.threeObject;t.forEach(b=>{a[b]=this[b]});a.sync();super.afterUpdate();this.text!==this._prevText&&(this.selectionStart=this.selectionEnd=-1,this._prevText=this.text);this._updateSelection()}_updateSelection(){let {selectable:a,selectionStart:b,selectionEnd:c}=this,d=this._selectionFacade;a!==this._selectable&&((this._selectable=a)?d=this._selectionFacade= | ||
new z(this,(a,b)=>{this.selectionStart=a;this.selectionEnd=b;this._updateSelection();this.requestRender()}):(d&&(d.destructor(),d=this._selectionFacade=null),this.selectionStart=this.selectionEnd=-1));d&&(d.textRenderInfo=this.threeObject.textRenderInfo,d.selectionStart=b,d.selectionEnd=c,d.curveRadius=this.curveRadius||0,d.clipRect=this.clipRect,d.renderOrder=this.renderOrder,d.afterUpdate())}destructor(){this.threeObject.dispose();this._selectionFacade&&this._selectionFacade.destructor();super.destructor()}} | ||
class B extends f.Object3DFacade{constructor(a){super(a,new e.BatchedText);this._texts=new f.Object3DFacade(this);this._texts.visible=!1}afterUpdate(){t.forEach(a=>{this.threeObject[a]=this[a]});this._texts.children=this.children;let a=new Set(this._texts.threeObject.children);this._texts.afterUpdate();this._texts.threeObject.children.forEach(b=>{this.threeObject.addText(b);a.delete(b)});a.forEach(a=>this.threeObject.removeText(a));super.afterUpdate()}shouldUpdateChildren(){return!1}}Object.defineProperty(b, | ||
"GlyphsGeometry",{enumerable:!0,get:function(){return e.GlyphsGeometry}});Object.defineProperty(b,"TextMesh",{enumerable:!0,get:function(){return e.Text}});Object.defineProperty(b,"configureTextBuilder",{enumerable:!0,get:function(){return e.configureTextBuilder}});Object.defineProperty(b,"dumpSDFTextures",{enumerable:!0,get:function(){return e.dumpSDFTextures}});Object.defineProperty(b,"getCaretAtPoint",{enumerable:!0,get:function(){return e.getCaretAtPoint}});Object.defineProperty(b,"getSelectionRects", | ||
{enumerable:!0,get:function(){return e.getSelectionRects}});Object.defineProperty(b,"preloadFont",{enumerable:!0,get:function(){return e.preloadFont}});Object.defineProperty(b,"typesetterWorkerModule",{enumerable:!0,get:function(){return e.typesetterWorkerModule}});b.BatchedText3DFacade=B;b.Text3DFacade=A;Object.defineProperty(b,"__esModule",{value:!0})}) |
{ | ||
"name": "troika-3d-text", | ||
"version": "0.52.1", | ||
"version": "0.52.2", | ||
"description": "SDF text for the Troika 3D scene management framework", | ||
@@ -18,3 +18,3 @@ "author": "Jason Johnston <jason.johnston@protectwise.com>", | ||
"troika-3d": "^0.52.0", | ||
"troika-three-text": "^0.52.1", | ||
"troika-three-text": "^0.52.2", | ||
"troika-three-utils": "^0.52.0" | ||
@@ -25,3 +25,3 @@ }, | ||
}, | ||
"gitHead": "8e62c3421d6efc599b43d6d3aac31a7869774742" | ||
"gitHead": "1af247e61d2f9f884728a7c77914bc8255c4e7cb" | ||
} |
@@ -19,4 +19,9 @@ import { Object3DFacade } from "troika-3d"; | ||
this._texts.children = this.children | ||
const prevTexts = new Set(this._texts.threeObject.children) | ||
this._texts.afterUpdate() | ||
this._texts.forEachChild(text => this.threeObject.addText(text.threeObject)) | ||
this._texts.threeObject.children.forEach(text => { | ||
this.threeObject.addText(text) | ||
prevTexts.delete(text) | ||
}) | ||
prevTexts.forEach(text => this.threeObject.removeText(text)) | ||
super.afterUpdate() | ||
@@ -23,0 +28,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
67063
1151
+ Addedtroika-three-text@0.52.2(transitive)
- Removedtroika-three-text@0.52.3(transitive)
Updatedtroika-three-text@^0.52.2