@mlightcad/mtext-renderer 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +523 -523
- package/dist/index.js +1144 -1114
- package/dist/index.umd.cjs +9 -9
- package/dist/mtext-renderer-worker.js +85 -56
- package/lib/renderer/charBoxUtils.d.ts +4 -0
- package/lib/renderer/mtext.charBoxes.test.d.ts +1 -0
- package/lib/renderer/mtextProcessor.d.ts +0 -1
- package/lib/renderer/types.d.ts +4 -0
- package/package.json +5 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var jh = (n, e) => () => (e || n((e = { exports: {} }).exports, e), e.exports);
|
|
2
|
-
var
|
|
2
|
+
var t1 = jh((O) => {
|
|
3
3
|
/**
|
|
4
4
|
* @license
|
|
5
5
|
* Copyright 2010-2024 Three.js Authors
|
|
@@ -3171,7 +3171,7 @@ var Kd = jh((O) => {
|
|
|
3171
3171
|
return super.copy(e), this.color.copy(e.color), this.map = e.map, this.lightMap = e.lightMap, this.lightMapIntensity = e.lightMapIntensity, this.aoMap = e.aoMap, this.aoMapIntensity = e.aoMapIntensity, this.specularMap = e.specularMap, this.alphaMap = e.alphaMap, this.envMap = e.envMap, this.envMapRotation.copy(e.envMapRotation), this.combine = e.combine, this.reflectivity = e.reflectivity, this.refractionRatio = e.refractionRatio, this.wireframe = e.wireframe, this.wireframeLinewidth = e.wireframeLinewidth, this.wireframeLinecap = e.wireframeLinecap, this.wireframeLinejoin = e.wireframeLinejoin, this.fog = e.fog, this;
|
|
3172
3172
|
}
|
|
3173
3173
|
}
|
|
3174
|
-
const
|
|
3174
|
+
const pe = /* @__PURE__ */ new A(), fn = /* @__PURE__ */ new V();
|
|
3175
3175
|
class Ve {
|
|
3176
3176
|
constructor(e, t, r = !1) {
|
|
3177
3177
|
if (Array.isArray(e))
|
|
@@ -3210,22 +3210,22 @@ var Kd = jh((O) => {
|
|
|
3210
3210
|
fn.fromBufferAttribute(this, t), fn.applyMatrix3(e), this.setXY(t, fn.x, fn.y);
|
|
3211
3211
|
else if (this.itemSize === 3)
|
|
3212
3212
|
for (let t = 0, r = this.count; t < r; t++)
|
|
3213
|
-
|
|
3213
|
+
pe.fromBufferAttribute(this, t), pe.applyMatrix3(e), this.setXYZ(t, pe.x, pe.y, pe.z);
|
|
3214
3214
|
return this;
|
|
3215
3215
|
}
|
|
3216
3216
|
applyMatrix4(e) {
|
|
3217
3217
|
for (let t = 0, r = this.count; t < r; t++)
|
|
3218
|
-
|
|
3218
|
+
pe.fromBufferAttribute(this, t), pe.applyMatrix4(e), this.setXYZ(t, pe.x, pe.y, pe.z);
|
|
3219
3219
|
return this;
|
|
3220
3220
|
}
|
|
3221
3221
|
applyNormalMatrix(e) {
|
|
3222
3222
|
for (let t = 0, r = this.count; t < r; t++)
|
|
3223
|
-
|
|
3223
|
+
pe.fromBufferAttribute(this, t), pe.applyNormalMatrix(e), this.setXYZ(t, pe.x, pe.y, pe.z);
|
|
3224
3224
|
return this;
|
|
3225
3225
|
}
|
|
3226
3226
|
transformDirection(e) {
|
|
3227
3227
|
for (let t = 0, r = this.count; t < r; t++)
|
|
3228
|
-
|
|
3228
|
+
pe.fromBufferAttribute(this, t), pe.transformDirection(e), this.setXYZ(t, pe.x, pe.y, pe.z);
|
|
3229
3229
|
return this;
|
|
3230
3230
|
}
|
|
3231
3231
|
set(e, t = 0) {
|
|
@@ -28870,8 +28870,57 @@ var Kd = jh((O) => {
|
|
|
28870
28870
|
this.type = e, this.ctx = t, this.data = r;
|
|
28871
28871
|
}
|
|
28872
28872
|
}
|
|
28873
|
-
var pr = /* @__PURE__ */ ((n) => (n[n.LEFT_TO_RIGHT = 1] = "LEFT_TO_RIGHT", n[n.RIGHT_TO_LEFT = 2] = "RIGHT_TO_LEFT", n[n.TOP_TO_BOTTOM = 3] = "TOP_TO_BOTTOM", n[n.BOTTOM_TO_TOP = 4] = "BOTTOM_TO_TOP", n[n.BY_STYLE = 5] = "BY_STYLE", n))(pr || {}),
|
|
28874
|
-
const
|
|
28873
|
+
var pr = /* @__PURE__ */ ((n) => (n[n.LEFT_TO_RIGHT = 1] = "LEFT_TO_RIGHT", n[n.RIGHT_TO_LEFT = 2] = "RIGHT_TO_LEFT", n[n.TOP_TO_BOTTOM = 3] = "TOP_TO_BOTTOM", n[n.BOTTOM_TO_TOP = 4] = "BOTTOM_TO_TOP", n[n.BY_STYLE = 5] = "BY_STYLE", n))(pr || {}), fe = /* @__PURE__ */ ((n) => (n.CHAR = "CHAR", n.NEW_PARAGRAPH = "NEW_PARAGRAPH", n.STACK = "STACK", n))(fe || {});
|
|
28874
|
+
const vs = "";
|
|
28875
|
+
function Yd(n) {
|
|
28876
|
+
if (!(!n || [
|
|
28877
|
+
n.min.x,
|
|
28878
|
+
n.min.y,
|
|
28879
|
+
n.min.z,
|
|
28880
|
+
n.max.x,
|
|
28881
|
+
n.max.y,
|
|
28882
|
+
n.max.z
|
|
28883
|
+
].some((t) => !Number.isFinite(t))))
|
|
28884
|
+
return n;
|
|
28885
|
+
}
|
|
28886
|
+
function Zd(n, e, t) {
|
|
28887
|
+
const r = [];
|
|
28888
|
+
if (n.filter((l) => l.char !== vs).forEach((l) => {
|
|
28889
|
+
const p = Yd(
|
|
28890
|
+
new Ae().copy(l.box).applyMatrix4(e)
|
|
28891
|
+
);
|
|
28892
|
+
p && r.push({
|
|
28893
|
+
type: l.type === fe.NEW_PARAGRAPH ? fe.NEW_PARAGRAPH : fe.CHAR,
|
|
28894
|
+
box: p,
|
|
28895
|
+
char: l.type === fe.NEW_PARAGRAPH ? `
|
|
28896
|
+
` : l.char,
|
|
28897
|
+
children: []
|
|
28898
|
+
});
|
|
28899
|
+
}), t !== fe.STACK)
|
|
28900
|
+
return r;
|
|
28901
|
+
const i = (l) => l.type === fe.CHAR && l.char.trim().length === 0, s = (l) => l.type === fe.CHAR && l.char.trim().length > 0, a = r.findIndex(s);
|
|
28902
|
+
if (a < 0) return r;
|
|
28903
|
+
let o = -1;
|
|
28904
|
+
for (let l = r.length - 1; l >= 0; l--)
|
|
28905
|
+
if (s(r[l])) {
|
|
28906
|
+
o = l;
|
|
28907
|
+
break;
|
|
28908
|
+
}
|
|
28909
|
+
const h = r.slice(0, a).filter(i), c = r.slice(o + 1).filter(i), u = r.slice(a, o + 1).filter(s);
|
|
28910
|
+
if (u.length === 0) return [...h, ...c];
|
|
28911
|
+
const f = new Ae().copy(u[0].box);
|
|
28912
|
+
return u.slice(1).forEach((l) => f.union(l.box)), [
|
|
28913
|
+
...h,
|
|
28914
|
+
{
|
|
28915
|
+
type: fe.STACK,
|
|
28916
|
+
char: "",
|
|
28917
|
+
box: f,
|
|
28918
|
+
children: u
|
|
28919
|
+
},
|
|
28920
|
+
...c
|
|
28921
|
+
];
|
|
28922
|
+
}
|
|
28923
|
+
const Jd = /* @__PURE__ */ new A(), $d = 1.666666, On = 0.3;
|
|
28875
28924
|
class Ns extends jr {
|
|
28876
28925
|
/**
|
|
28877
28926
|
* Creates a new RenderContext instance with optional initial values.
|
|
@@ -28905,7 +28954,7 @@ var Kd = jh((O) => {
|
|
|
28905
28954
|
this.color.rgb = [t, r, i];
|
|
28906
28955
|
}
|
|
28907
28956
|
}
|
|
28908
|
-
class
|
|
28957
|
+
class jd {
|
|
28909
28958
|
/**
|
|
28910
28959
|
* Construct one instance of this class and initialize some properties with default values.
|
|
28911
28960
|
* @param style Input text style
|
|
@@ -29004,7 +29053,7 @@ var Kd = jh((O) => {
|
|
|
29004
29053
|
* The height of current line of texts
|
|
29005
29054
|
*/
|
|
29006
29055
|
get currentLineHeight() {
|
|
29007
|
-
return this.defaultLineSpaceFactor * this.currentFontSize *
|
|
29056
|
+
return this.defaultLineSpaceFactor * this.currentFontSize * $d + this.currentMaxFontSize;
|
|
29008
29057
|
}
|
|
29009
29058
|
/**
|
|
29010
29059
|
* The maximum font size in current line. Characters in one line may have different font and font
|
|
@@ -29211,7 +29260,7 @@ var Kd = jh((O) => {
|
|
|
29211
29260
|
i,
|
|
29212
29261
|
s
|
|
29213
29262
|
);
|
|
29214
|
-
const c = h[2] === "^" ?
|
|
29263
|
+
const c = h[2] === "^" ? fe.CHAR : fe.STACK;
|
|
29215
29264
|
this.processGeometries(
|
|
29216
29265
|
t,
|
|
29217
29266
|
r,
|
|
@@ -29229,7 +29278,7 @@ var Kd = jh((O) => {
|
|
|
29229
29278
|
a
|
|
29230
29279
|
), this.processLastLine(), a;
|
|
29231
29280
|
}
|
|
29232
|
-
processGeometries(e, t, r, i, s, a =
|
|
29281
|
+
processGeometries(e, t, r, i, s, a = fe.CHAR) {
|
|
29233
29282
|
if (e.length > 0 || t.length > 0) {
|
|
29234
29283
|
const o = this.toThreeObject(
|
|
29235
29284
|
e,
|
|
@@ -29367,12 +29416,12 @@ var Kd = jh((O) => {
|
|
|
29367
29416
|
new A(e + r, a, 0)
|
|
29368
29417
|
);
|
|
29369
29418
|
this.resolveCharBoxTarget(i, s) === "mesh" ? i.push({
|
|
29370
|
-
type:
|
|
29419
|
+
type: fe.CHAR,
|
|
29371
29420
|
box: o,
|
|
29372
29421
|
char: vs,
|
|
29373
29422
|
children: []
|
|
29374
29423
|
}) : s.push({
|
|
29375
|
-
type:
|
|
29424
|
+
type: fe.CHAR,
|
|
29376
29425
|
box: o,
|
|
29377
29426
|
char: vs,
|
|
29378
29427
|
children: []
|
|
@@ -29396,12 +29445,12 @@ var Kd = jh((O) => {
|
|
|
29396
29445
|
)
|
|
29397
29446
|
);
|
|
29398
29447
|
this.resolveCharBoxTarget(e, t) === "mesh" ? e.push({
|
|
29399
|
-
type:
|
|
29448
|
+
type: fe.CHAR,
|
|
29400
29449
|
box: s,
|
|
29401
29450
|
char: " ",
|
|
29402
29451
|
children: []
|
|
29403
29452
|
}) : t.push({
|
|
29404
|
-
type:
|
|
29453
|
+
type: fe.CHAR,
|
|
29405
29454
|
box: s,
|
|
29406
29455
|
char: " ",
|
|
29407
29456
|
children: []
|
|
@@ -29413,13 +29462,13 @@ var Kd = jh((O) => {
|
|
|
29413
29462
|
if (this._options.collectCharBoxes === !1 || !e || !t) return;
|
|
29414
29463
|
const r = new A(this._hOffset, this._vOffset, 0), i = new Ae(r.clone(), r.clone());
|
|
29415
29464
|
this.resolveCharBoxTarget(e, t) === "mesh" ? e.push({
|
|
29416
|
-
type:
|
|
29465
|
+
type: fe.NEW_PARAGRAPH,
|
|
29417
29466
|
box: i,
|
|
29418
29467
|
char: `
|
|
29419
29468
|
`,
|
|
29420
29469
|
children: []
|
|
29421
29470
|
}) : t.push({
|
|
29422
|
-
type:
|
|
29471
|
+
type: fe.NEW_PARAGRAPH,
|
|
29423
29472
|
box: i,
|
|
29424
29473
|
char: `
|
|
29425
29474
|
`,
|
|
@@ -29463,12 +29512,12 @@ var Kd = jh((O) => {
|
|
|
29463
29512
|
o.userData.char = e, o.boundingBox || o.computeBoundingBox();
|
|
29464
29513
|
const x = new Ae().copy(o.boundingBox);
|
|
29465
29514
|
o instanceof cr ? (this._lastCharBoxTarget = "mesh", i.push({
|
|
29466
|
-
type:
|
|
29515
|
+
type: fe.CHAR,
|
|
29467
29516
|
box: x,
|
|
29468
29517
|
char: e,
|
|
29469
29518
|
children: []
|
|
29470
29519
|
})) : (this._lastCharBoxTarget = "line", s.push({
|
|
29471
|
-
type:
|
|
29520
|
+
type: fe.CHAR,
|
|
29472
29521
|
box: x,
|
|
29473
29522
|
char: e,
|
|
29474
29523
|
children: []
|
|
@@ -29593,7 +29642,7 @@ var Kd = jh((O) => {
|
|
|
29593
29642
|
if (e.forEach((a, o) => {
|
|
29594
29643
|
a.geometry.boundingBox || a.geometry.computeBoundingBox(), o === 0 ? t = a.geometry.boundingBox : t.union(a.geometry.boundingBox);
|
|
29595
29644
|
}), !t) return;
|
|
29596
|
-
const r = t, i = r.getSize(
|
|
29645
|
+
const r = t, i = r.getSize(Jd), s = (a, o) => {
|
|
29597
29646
|
var c;
|
|
29598
29647
|
const h = (c = a.userData) == null ? void 0 : c.charBoxes;
|
|
29599
29648
|
if (h && h.length > 0) {
|
|
@@ -29891,7 +29940,7 @@ var Kd = jh((O) => {
|
|
|
29891
29940
|
value: e.widthFactor ?? 1,
|
|
29892
29941
|
isRelative: !0
|
|
29893
29942
|
}, u.align = s, u.paragraph.align = i;
|
|
29894
|
-
const f = new
|
|
29943
|
+
const f = new jd(
|
|
29895
29944
|
t,
|
|
29896
29945
|
this.styleManager,
|
|
29897
29946
|
this.fontManager,
|
|
@@ -29957,32 +30006,12 @@ var Kd = jh((O) => {
|
|
|
29957
30006
|
e.updateWorldMatrix(!1, !1);
|
|
29958
30007
|
const r = (s = e.userData) == null ? void 0 : s.charBoxes;
|
|
29959
30008
|
if (r && r.length > 0) {
|
|
29960
|
-
const h =
|
|
29961
|
-
|
|
29962
|
-
|
|
29963
|
-
|
|
29964
|
-
|
|
29965
|
-
|
|
29966
|
-
` : u.char,
|
|
29967
|
-
children: []
|
|
29968
|
-
};
|
|
29969
|
-
});
|
|
29970
|
-
if (((a = e.userData) == null ? void 0 : a.charBoxType) === pe.STACK) {
|
|
29971
|
-
const u = new Ae();
|
|
29972
|
-
h.forEach((f) => {
|
|
29973
|
-
u.union(f.box);
|
|
29974
|
-
}), t.push({
|
|
29975
|
-
type: pe.STACK,
|
|
29976
|
-
char: "",
|
|
29977
|
-
box: u,
|
|
29978
|
-
children: h
|
|
29979
|
-
});
|
|
29980
|
-
} else
|
|
29981
|
-
h.forEach((u) => {
|
|
29982
|
-
t.push({
|
|
29983
|
-
...u
|
|
29984
|
-
});
|
|
29985
|
-
});
|
|
30009
|
+
const h = (a = e.userData) == null ? void 0 : a.charBoxType, c = Zd(
|
|
30010
|
+
r,
|
|
30011
|
+
e.matrixWorld,
|
|
30012
|
+
h
|
|
30013
|
+
);
|
|
30014
|
+
t.push(...c);
|
|
29986
30015
|
return;
|
|
29987
30016
|
}
|
|
29988
30017
|
if (e instanceof bs || e instanceof Dn) {
|
|
@@ -29991,7 +30020,7 @@ var Kd = jh((O) => {
|
|
|
29991
30020
|
h.boundingBox === null && h.computeBoundingBox();
|
|
29992
30021
|
const c = new Ae().copy(h.boundingBox);
|
|
29993
30022
|
c.applyMatrix4(e.matrixWorld), t.push({
|
|
29994
|
-
type:
|
|
30023
|
+
type: fe.CHAR,
|
|
29995
30024
|
box: c,
|
|
29996
30025
|
char: "",
|
|
29997
30026
|
children: []
|
|
@@ -30033,7 +30062,7 @@ var Kd = jh((O) => {
|
|
|
30033
30062
|
}
|
|
30034
30063
|
}
|
|
30035
30064
|
}
|
|
30036
|
-
const es = ft.instance,
|
|
30065
|
+
const es = ft.instance, Qd = new Gd();
|
|
30037
30066
|
self.addEventListener("message", async (n) => {
|
|
30038
30067
|
const { type: e, id: t, data: r } = n.data;
|
|
30039
30068
|
try {
|
|
@@ -30044,12 +30073,12 @@ var Kd = jh((O) => {
|
|
|
30044
30073
|
let o = new Gs(
|
|
30045
30074
|
i,
|
|
30046
30075
|
s,
|
|
30047
|
-
|
|
30076
|
+
Qd,
|
|
30048
30077
|
es,
|
|
30049
30078
|
a
|
|
30050
30079
|
);
|
|
30051
30080
|
await o.asyncDraw(), o.updateMatrixWorld(!0);
|
|
30052
|
-
const { data: h, transferableObjects: c } =
|
|
30081
|
+
const { data: h, transferableObjects: c } = Kd(o);
|
|
30053
30082
|
self.postMessage(
|
|
30054
30083
|
{
|
|
30055
30084
|
type: "render",
|
|
@@ -30105,12 +30134,12 @@ var Kd = jh((O) => {
|
|
|
30105
30134
|
});
|
|
30106
30135
|
}
|
|
30107
30136
|
});
|
|
30108
|
-
function
|
|
30137
|
+
function Kd(n) {
|
|
30109
30138
|
const e = n.matrixWorld.clone(), t = new A(), r = new Bt(), i = new A();
|
|
30110
30139
|
e.decompose(t, r, i);
|
|
30111
30140
|
const s = n.box.clone();
|
|
30112
30141
|
s.applyMatrix4(e);
|
|
30113
|
-
const { children: a, transferableObjects: o } =
|
|
30142
|
+
const { children: a, transferableObjects: o } = e1(n);
|
|
30114
30143
|
return { data: {
|
|
30115
30144
|
// Basic properties
|
|
30116
30145
|
type: "MText",
|
|
@@ -30146,7 +30175,7 @@ var Kd = jh((O) => {
|
|
|
30146
30175
|
children: a
|
|
30147
30176
|
}, transferableObjects: o };
|
|
30148
30177
|
}
|
|
30149
|
-
function
|
|
30178
|
+
function e1(n) {
|
|
30150
30179
|
const e = [], t = [];
|
|
30151
30180
|
return n.traverse((r) => {
|
|
30152
30181
|
if (r instanceof Dn || r instanceof bs) {
|
|
@@ -30221,4 +30250,4 @@ var Kd = jh((O) => {
|
|
|
30221
30250
|
}), { children: e, transferableObjects: t };
|
|
30222
30251
|
}
|
|
30223
30252
|
});
|
|
30224
|
-
export default
|
|
30253
|
+
export default t1();
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CharBox, CharBoxType } from './types';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
export declare function normalizeBox(box?: THREE.Box3): THREE.Box3 | undefined;
|
|
4
|
+
export declare function buildCharBoxesFromObject(objectCharBoxes: CharBox[], matrixWorld: THREE.Matrix4, charBoxType?: CharBoxType): CharBox[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -3,7 +3,6 @@ import { FontManager } from '../font';
|
|
|
3
3
|
import { StyleManager } from './styleManager';
|
|
4
4
|
import { MTextFlowDirection, TextStyle } from './types';
|
|
5
5
|
import * as THREE from 'three';
|
|
6
|
-
export declare const STACK_DIVIDER_CHAR = "\uE000";
|
|
7
6
|
export interface MTextFormatOptions {
|
|
8
7
|
/**
|
|
9
8
|
* Font size.
|
package/lib/renderer/types.d.ts
CHANGED
|
@@ -87,6 +87,10 @@ export declare enum CharBoxType {
|
|
|
87
87
|
/** Stack token (for fraction-style stacked expressions). */
|
|
88
88
|
STACK = "STACK"
|
|
89
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Sentinel character used internally to represent a stack divider line.
|
|
92
|
+
*/
|
|
93
|
+
export declare const STACK_DIVIDER_CHAR = "\uE000";
|
|
90
94
|
export interface StyleTraits {
|
|
91
95
|
/**
|
|
92
96
|
* Optional layer name. Material is identified by layer and color. So it means different
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlightcad/mtext-renderer",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "AutoCAD MText renderer based on Three.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "MLight Lee <mlight.lee@outlook.com>",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/opentype.js": "^1.3.8",
|
|
44
|
-
"@types/three": "^0.172.0"
|
|
44
|
+
"@types/three": "^0.172.0",
|
|
45
|
+
"vitest": "^3.2.4"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"three": "^0.172.0"
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"build:worker": "vite build -c vite.config.worker.ts",
|
|
53
54
|
"clean": "rimraf dist lib tsconfig.tsbuildinfo",
|
|
54
55
|
"lint": "eslint src/",
|
|
55
|
-
"lint:fix": "eslint --fix --quiet src/"
|
|
56
|
+
"lint:fix": "eslint --fix --quiet src/",
|
|
57
|
+
"test": "vitest run"
|
|
56
58
|
}
|
|
57
59
|
}
|