@mlightcad/mtext-parser 1.0.11 → 1.1.0
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/dist/parser.cjs.js +2 -2
- package/dist/parser.cjs.js.map +1 -1
- package/dist/parser.es.js +301 -195
- package/dist/parser.es.js.map +1 -1
- package/dist/parser.umd.js +2 -2
- package/dist/parser.umd.js.map +1 -1
- package/dist/types/parser.d.ts +103 -9
- package/package.json +1 -1
package/dist/parser.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var k = /* @__PURE__ */ ((s) => (s[s.NONE = 0] = "NONE", s[s.WORD = 1] = "WORD", s[s.STACK = 2] = "STACK", s[s.SPACE = 3] = "SPACE", s[s.NBSP = 4] = "NBSP", s[s.TABULATOR = 5] = "TABULATOR", s[s.NEW_PARAGRAPH = 6] = "NEW_PARAGRAPH", s[s.NEW_COLUMN = 7] = "NEW_COLUMN", s[s.WRAP_AT_DIMLINE = 8] = "WRAP_AT_DIMLINE", s[s.PROPERTIES_CHANGED = 9] = "PROPERTIES_CHANGED", s))(k || {}),
|
|
2
|
-
const
|
|
1
|
+
var k = /* @__PURE__ */ ((s) => (s[s.NONE = 0] = "NONE", s[s.WORD = 1] = "WORD", s[s.STACK = 2] = "STACK", s[s.SPACE = 3] = "SPACE", s[s.NBSP = 4] = "NBSP", s[s.TABULATOR = 5] = "TABULATOR", s[s.NEW_PARAGRAPH = 6] = "NEW_PARAGRAPH", s[s.NEW_COLUMN = 7] = "NEW_COLUMN", s[s.WRAP_AT_DIMLINE = 8] = "WRAP_AT_DIMLINE", s[s.PROPERTIES_CHANGED = 9] = "PROPERTIES_CHANGED", s))(k || {}), _ = /* @__PURE__ */ ((s) => (s[s.BOTTOM = 0] = "BOTTOM", s[s.MIDDLE = 1] = "MIDDLE", s[s.TOP = 2] = "TOP", s))(_ || {}), m = /* @__PURE__ */ ((s) => (s[s.DEFAULT = 0] = "DEFAULT", s[s.LEFT = 1] = "LEFT", s[s.RIGHT = 2] = "RIGHT", s[s.CENTER = 3] = "CENTER", s[s.JUSTIFIED = 4] = "JUSTIFIED", s[s.DISTRIBUTED = 5] = "DISTRIBUTED", s))(m || {}), E = /* @__PURE__ */ ((s) => (s[s.NONE = 0] = "NONE", s[s.UNDERLINE = 1] = "UNDERLINE", s[s.OVERLINE = 2] = "OVERLINE", s[s.STRIKE_THROUGH = 4] = "STRIKE_THROUGH", s))(E || {});
|
|
2
|
+
const F = {
|
|
3
3
|
c: "Ø",
|
|
4
4
|
d: "°",
|
|
5
5
|
p: "±"
|
|
6
|
-
},
|
|
6
|
+
}, S = {
|
|
7
7
|
l: 1,
|
|
8
8
|
r: 2,
|
|
9
9
|
c: 3,
|
|
@@ -12,49 +12,50 @@ const m = {
|
|
|
12
12
|
/* DISTRIBUTED */
|
|
13
13
|
};
|
|
14
14
|
function R(s) {
|
|
15
|
-
const [
|
|
16
|
-
return r << 16 |
|
|
17
|
-
}
|
|
18
|
-
function S(s) {
|
|
19
|
-
const e = s & 255, t = s >> 8 & 255, r = s >> 16 & 255;
|
|
20
|
-
return [e, t, r];
|
|
15
|
+
const [t, e, r] = s;
|
|
16
|
+
return r << 16 | e << 8 | t;
|
|
21
17
|
}
|
|
22
18
|
function v(s) {
|
|
23
|
-
|
|
19
|
+
const t = s & 255, e = s >> 8 & 255, r = s >> 16 & 255;
|
|
20
|
+
return [t, e, r];
|
|
24
21
|
}
|
|
25
22
|
function I(s) {
|
|
26
|
-
return s.replace(
|
|
23
|
+
return s.replace(/\r\n|\r|\n/g, "\\P");
|
|
27
24
|
}
|
|
28
25
|
function N(s) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
return s.replace(/\\P/g, "").replace(/\\~/g, "").includes("\\");
|
|
27
|
+
}
|
|
28
|
+
function O(s, t = !1) {
|
|
29
|
+
const e = /* @__PURE__ */ new Set(), r = /\\[fF](.*?)[;|]/g;
|
|
30
|
+
return [...s.matchAll(r)].forEach((a) => {
|
|
31
|
+
let i = a[1].toLowerCase();
|
|
32
|
+
t && (i = i.replace(/\.(ttf|otf|woff|shx)$/, "")), e.add(i);
|
|
32
33
|
}), e;
|
|
33
34
|
}
|
|
34
|
-
class
|
|
35
|
+
class D {
|
|
35
36
|
/**
|
|
36
37
|
* Creates a new MTextParser instance
|
|
37
38
|
* @param content - The MText content to parse
|
|
38
39
|
* @param ctx - Optional initial MText context
|
|
39
40
|
* @param yieldPropertyCommands - Whether to yield property change commands
|
|
40
41
|
*/
|
|
41
|
-
constructor(
|
|
42
|
-
this.ctxStack = [], this.continueStroke = !1, this.inStackContext = !1, this.scanner = new
|
|
42
|
+
constructor(t, e, r = !1) {
|
|
43
|
+
this.ctxStack = [], this.continueStroke = !1, this.inStackContext = !1, this.scanner = new g(t), this.ctx = e ?? new d(), this.lastCtx = this.ctx.copy(), this.yieldPropertyCommands = r;
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
45
46
|
* Decode multi-byte character from hex code
|
|
46
47
|
* @param hex - Hex code string (e.g. "C4E3")
|
|
47
48
|
* @returns Decoded character or empty square if invalid
|
|
48
49
|
*/
|
|
49
|
-
decodeMultiByteChar(
|
|
50
|
+
decodeMultiByteChar(t) {
|
|
50
51
|
try {
|
|
51
|
-
const
|
|
52
|
-
parseInt(
|
|
53
|
-
parseInt(
|
|
54
|
-
]), a = new TextDecoder("gbk").decode(
|
|
52
|
+
const e = new Uint8Array([
|
|
53
|
+
parseInt(t.substr(0, 2), 16),
|
|
54
|
+
parseInt(t.substr(2, 2), 16)
|
|
55
|
+
]), a = new TextDecoder("gbk").decode(e);
|
|
55
56
|
if (a !== "▯")
|
|
56
57
|
return a;
|
|
57
|
-
const h = new TextDecoder("big5").decode(
|
|
58
|
+
const h = new TextDecoder("big5").decode(e);
|
|
58
59
|
return h !== "▯" ? h : "▯";
|
|
59
60
|
} catch {
|
|
60
61
|
return "▯";
|
|
@@ -77,14 +78,14 @@ class O {
|
|
|
77
78
|
* @returns Tuple of [TokenType.STACK, [numerator, denominator, type]]
|
|
78
79
|
*/
|
|
79
80
|
parseStacking() {
|
|
80
|
-
const
|
|
81
|
-
let
|
|
81
|
+
const t = new g(this.extractExpression(!0));
|
|
82
|
+
let e = "", r = "", a = "";
|
|
82
83
|
const i = () => {
|
|
83
|
-
let n =
|
|
84
|
-
return n.charCodeAt(0) < 32 && (n = " "), n === "\\" && (l = !0,
|
|
84
|
+
let n = t.peek(), l = !1;
|
|
85
|
+
return n.charCodeAt(0) < 32 && (n = " "), n === "\\" && (l = !0, t.consume(1), n = t.peek()), t.consume(1), [n, l];
|
|
85
86
|
}, h = () => {
|
|
86
87
|
let n = "";
|
|
87
|
-
for (;
|
|
88
|
+
for (; t.hasData; ) {
|
|
88
89
|
const [l, o] = i();
|
|
89
90
|
if (!o && (l === "/" || l === "#" || l === "^"))
|
|
90
91
|
return [n, l];
|
|
@@ -93,7 +94,7 @@ class O {
|
|
|
93
94
|
return [n, ""];
|
|
94
95
|
}, u = (n) => {
|
|
95
96
|
let l = "", o = n;
|
|
96
|
-
for (;
|
|
97
|
+
for (; t.hasData; ) {
|
|
97
98
|
const [c, p] = i();
|
|
98
99
|
if (!(o && c === " ")) {
|
|
99
100
|
if (o = !1, !p && c === ";")
|
|
@@ -103,70 +104,70 @@ class O {
|
|
|
103
104
|
}
|
|
104
105
|
return l;
|
|
105
106
|
};
|
|
106
|
-
return [
|
|
107
|
+
return [e, a] = h(), a && (r = u(a === "^")), e === "" && r.includes("I/") ? [2, [" ", " ", "/"]] : a === "^" ? [2, [e, r, "^"]] : [2, [e, r, a]];
|
|
107
108
|
}
|
|
108
109
|
/**
|
|
109
110
|
* Parse MText properties
|
|
110
111
|
* @param cmd - The property command to parse
|
|
111
112
|
* @returns Property changes if yieldPropertyCommands is true and changes occurred
|
|
112
113
|
*/
|
|
113
|
-
parseProperties(
|
|
114
|
-
const
|
|
115
|
-
switch (
|
|
114
|
+
parseProperties(t) {
|
|
115
|
+
const e = this.ctx.copy();
|
|
116
|
+
switch (t) {
|
|
116
117
|
case "L":
|
|
117
|
-
|
|
118
|
+
e.underline = !0, this.continueStroke = !0;
|
|
118
119
|
break;
|
|
119
120
|
case "l":
|
|
120
|
-
|
|
121
|
+
e.underline = !1, e.hasAnyStroke || (this.continueStroke = !1);
|
|
121
122
|
break;
|
|
122
123
|
case "O":
|
|
123
|
-
|
|
124
|
+
e.overline = !0, this.continueStroke = !0;
|
|
124
125
|
break;
|
|
125
126
|
case "o":
|
|
126
|
-
|
|
127
|
+
e.overline = !1, e.hasAnyStroke || (this.continueStroke = !1);
|
|
127
128
|
break;
|
|
128
129
|
case "K":
|
|
129
|
-
|
|
130
|
+
e.strikeThrough = !0, this.continueStroke = !0;
|
|
130
131
|
break;
|
|
131
132
|
case "k":
|
|
132
|
-
|
|
133
|
+
e.strikeThrough = !1, e.hasAnyStroke || (this.continueStroke = !1);
|
|
133
134
|
break;
|
|
134
135
|
case "A":
|
|
135
|
-
this.parseAlign(
|
|
136
|
+
this.parseAlign(e);
|
|
136
137
|
break;
|
|
137
138
|
case "C":
|
|
138
|
-
this.parseAciColor(
|
|
139
|
+
this.parseAciColor(e);
|
|
139
140
|
break;
|
|
140
141
|
case "c":
|
|
141
|
-
this.parseRgbColor(
|
|
142
|
+
this.parseRgbColor(e);
|
|
142
143
|
break;
|
|
143
144
|
case "H":
|
|
144
|
-
this.parseHeight(
|
|
145
|
+
this.parseHeight(e);
|
|
145
146
|
break;
|
|
146
147
|
case "W":
|
|
147
|
-
this.parseWidth(
|
|
148
|
+
this.parseWidth(e);
|
|
148
149
|
break;
|
|
149
150
|
case "Q":
|
|
150
|
-
this.parseOblique(
|
|
151
|
+
this.parseOblique(e);
|
|
151
152
|
break;
|
|
152
153
|
case "T":
|
|
153
|
-
this.parseCharTracking(
|
|
154
|
+
this.parseCharTracking(e);
|
|
154
155
|
break;
|
|
155
156
|
case "p":
|
|
156
|
-
this.parseParagraphProperties(
|
|
157
|
+
this.parseParagraphProperties(e);
|
|
157
158
|
break;
|
|
158
159
|
case "f":
|
|
159
160
|
case "F":
|
|
160
|
-
this.parseFontProperties(
|
|
161
|
+
this.parseFontProperties(e);
|
|
161
162
|
break;
|
|
162
163
|
default:
|
|
163
|
-
throw new Error(`Unknown command: ${
|
|
164
|
+
throw new Error(`Unknown command: ${t}`);
|
|
164
165
|
}
|
|
165
|
-
if (this.continueStroke =
|
|
166
|
-
const r = this.getPropertyChanges(this.lastCtx,
|
|
166
|
+
if (this.continueStroke = e.hasAnyStroke, e.continueStroke = this.continueStroke, this.ctx = e, this.yieldPropertyCommands) {
|
|
167
|
+
const r = this.getPropertyChanges(this.lastCtx, e);
|
|
167
168
|
if (Object.keys(r).length > 0)
|
|
168
169
|
return this.lastCtx = this.ctx.copy(), {
|
|
169
|
-
command:
|
|
170
|
+
command: t,
|
|
170
171
|
changes: r
|
|
171
172
|
};
|
|
172
173
|
}
|
|
@@ -177,11 +178,11 @@ class O {
|
|
|
177
178
|
* @param newCtx - The new context
|
|
178
179
|
* @returns Object containing changed properties
|
|
179
180
|
*/
|
|
180
|
-
getPropertyChanges(
|
|
181
|
+
getPropertyChanges(t, e) {
|
|
181
182
|
const r = {};
|
|
182
|
-
if (
|
|
183
|
+
if (t.underline !== e.underline && (r.underline = e.underline), t.overline !== e.overline && (r.overline = e.overline), t.strikeThrough !== e.strikeThrough && (r.strikeThrough = e.strikeThrough), t.color.aci !== e.color.aci && (r.aci = e.color.aci, r.rgb = e.color.rgb), t.color.rgbValue !== e.color.rgbValue && (r.rgb = e.color.rgb), t.align !== e.align && (r.align = e.align), JSON.stringify(t.fontFace) !== JSON.stringify(e.fontFace) && (r.fontFace = e.fontFace), (t.capHeight.value !== e.capHeight.value || t.capHeight.isRelative !== e.capHeight.isRelative) && (r.capHeight = e.capHeight), (t.widthFactor.value !== e.widthFactor.value || t.widthFactor.isRelative !== e.widthFactor.isRelative) && (r.widthFactor = e.widthFactor), (t.charTrackingFactor.value !== e.charTrackingFactor.value || t.charTrackingFactor.isRelative !== e.charTrackingFactor.isRelative) && (r.charTrackingFactor = e.charTrackingFactor), t.oblique !== e.oblique && (r.oblique = e.oblique), JSON.stringify(t.paragraph) !== JSON.stringify(e.paragraph)) {
|
|
183
184
|
const a = {};
|
|
184
|
-
|
|
185
|
+
t.paragraph.indent !== e.paragraph.indent && (a.indent = e.paragraph.indent), t.paragraph.align !== e.paragraph.align && (a.align = e.paragraph.align), t.paragraph.left !== e.paragraph.left && (a.left = e.paragraph.left), t.paragraph.right !== e.paragraph.right && (a.right = e.paragraph.right), JSON.stringify(t.paragraph.tab_stops) !== JSON.stringify(e.paragraph.tab_stops) && (a.tab_stops = e.paragraph.tab_stops), Object.keys(a).length > 0 && (r.paragraph = a);
|
|
185
186
|
}
|
|
186
187
|
return r;
|
|
187
188
|
}
|
|
@@ -189,27 +190,27 @@ class O {
|
|
|
189
190
|
* Parse alignment property
|
|
190
191
|
* @param ctx - The context to update
|
|
191
192
|
*/
|
|
192
|
-
parseAlign(
|
|
193
|
-
const
|
|
194
|
-
"012".includes(
|
|
193
|
+
parseAlign(t) {
|
|
194
|
+
const e = this.scanner.get();
|
|
195
|
+
"012".includes(e) ? t.align = parseInt(e) : t.align = 0, this.consumeOptionalTerminator();
|
|
195
196
|
}
|
|
196
197
|
/**
|
|
197
198
|
* Parse height property
|
|
198
199
|
* @param ctx - The context to update
|
|
199
200
|
*/
|
|
200
|
-
parseHeight(
|
|
201
|
-
const
|
|
202
|
-
if (
|
|
201
|
+
parseHeight(t) {
|
|
202
|
+
const e = this.extractFloatExpression(!0);
|
|
203
|
+
if (e)
|
|
203
204
|
try {
|
|
204
|
-
|
|
205
|
-
value: parseFloat(
|
|
205
|
+
e.endsWith("x") ? t.capHeight = {
|
|
206
|
+
value: parseFloat(e.slice(0, -1)),
|
|
206
207
|
isRelative: !0
|
|
207
|
-
} :
|
|
208
|
-
value: parseFloat(
|
|
208
|
+
} : t.capHeight = {
|
|
209
|
+
value: parseFloat(e),
|
|
209
210
|
isRelative: !1
|
|
210
211
|
};
|
|
211
212
|
} catch {
|
|
212
|
-
this.scanner.consume(-
|
|
213
|
+
this.scanner.consume(-e.length);
|
|
213
214
|
return;
|
|
214
215
|
}
|
|
215
216
|
this.consumeOptionalTerminator();
|
|
@@ -218,19 +219,19 @@ class O {
|
|
|
218
219
|
* Parse width property
|
|
219
220
|
* @param ctx - The context to update
|
|
220
221
|
*/
|
|
221
|
-
parseWidth(
|
|
222
|
-
const
|
|
223
|
-
if (
|
|
222
|
+
parseWidth(t) {
|
|
223
|
+
const e = this.extractFloatExpression(!0);
|
|
224
|
+
if (e)
|
|
224
225
|
try {
|
|
225
|
-
|
|
226
|
-
value: parseFloat(
|
|
226
|
+
e.endsWith("x") ? t.widthFactor = {
|
|
227
|
+
value: parseFloat(e.slice(0, -1)),
|
|
227
228
|
isRelative: !0
|
|
228
|
-
} :
|
|
229
|
-
value: parseFloat(
|
|
229
|
+
} : t.widthFactor = {
|
|
230
|
+
value: parseFloat(e),
|
|
230
231
|
isRelative: !1
|
|
231
232
|
};
|
|
232
233
|
} catch {
|
|
233
|
-
this.scanner.consume(-
|
|
234
|
+
this.scanner.consume(-e.length);
|
|
234
235
|
return;
|
|
235
236
|
}
|
|
236
237
|
this.consumeOptionalTerminator();
|
|
@@ -239,19 +240,19 @@ class O {
|
|
|
239
240
|
* Parse character tracking property
|
|
240
241
|
* @param ctx - The context to update
|
|
241
242
|
*/
|
|
242
|
-
parseCharTracking(
|
|
243
|
-
const
|
|
244
|
-
if (
|
|
243
|
+
parseCharTracking(t) {
|
|
244
|
+
const e = this.extractFloatExpression(!0);
|
|
245
|
+
if (e)
|
|
245
246
|
try {
|
|
246
|
-
|
|
247
|
-
value: Math.abs(parseFloat(
|
|
247
|
+
e.endsWith("x") ? t.charTrackingFactor = {
|
|
248
|
+
value: Math.abs(parseFloat(e.slice(0, -1))),
|
|
248
249
|
isRelative: !0
|
|
249
|
-
} :
|
|
250
|
-
value: Math.abs(parseFloat(
|
|
250
|
+
} : t.charTrackingFactor = {
|
|
251
|
+
value: Math.abs(parseFloat(e)),
|
|
251
252
|
isRelative: !1
|
|
252
253
|
};
|
|
253
254
|
} catch {
|
|
254
|
-
this.scanner.consume(-
|
|
255
|
+
this.scanner.consume(-e.length);
|
|
255
256
|
return;
|
|
256
257
|
}
|
|
257
258
|
this.consumeOptionalTerminator();
|
|
@@ -261,33 +262,33 @@ class O {
|
|
|
261
262
|
* @param value - Current value to apply factor to
|
|
262
263
|
* @returns New value
|
|
263
264
|
*/
|
|
264
|
-
parseFloatValueOrFactor(
|
|
265
|
-
const
|
|
266
|
-
if (
|
|
267
|
-
if (
|
|
268
|
-
const r = parseFloat(
|
|
269
|
-
|
|
265
|
+
parseFloatValueOrFactor(t) {
|
|
266
|
+
const e = this.extractFloatExpression(!0);
|
|
267
|
+
if (e)
|
|
268
|
+
if (e.endsWith("x")) {
|
|
269
|
+
const r = parseFloat(e.slice(0, -1));
|
|
270
|
+
t *= r;
|
|
270
271
|
} else
|
|
271
|
-
|
|
272
|
-
return
|
|
272
|
+
t = parseFloat(e);
|
|
273
|
+
return t;
|
|
273
274
|
}
|
|
274
275
|
/**
|
|
275
276
|
* Parse oblique angle property
|
|
276
277
|
* @param ctx - The context to update
|
|
277
278
|
*/
|
|
278
|
-
parseOblique(
|
|
279
|
-
const
|
|
280
|
-
|
|
279
|
+
parseOblique(t) {
|
|
280
|
+
const e = this.extractFloatExpression(!1);
|
|
281
|
+
e && (t.oblique = parseFloat(e)), this.consumeOptionalTerminator();
|
|
281
282
|
}
|
|
282
283
|
/**
|
|
283
284
|
* Parse ACI color property
|
|
284
285
|
* @param ctx - The context to update
|
|
285
286
|
*/
|
|
286
|
-
parseAciColor(
|
|
287
|
-
const
|
|
288
|
-
if (
|
|
289
|
-
const r = parseInt(
|
|
290
|
-
r < 257 && (
|
|
287
|
+
parseAciColor(t) {
|
|
288
|
+
const e = this.extractIntExpression();
|
|
289
|
+
if (e) {
|
|
290
|
+
const r = parseInt(e);
|
|
291
|
+
r < 257 && (t.color.aci = r);
|
|
291
292
|
}
|
|
292
293
|
this.consumeOptionalTerminator();
|
|
293
294
|
}
|
|
@@ -295,11 +296,11 @@ class O {
|
|
|
295
296
|
* Parse RGB color property
|
|
296
297
|
* @param ctx - The context to update
|
|
297
298
|
*/
|
|
298
|
-
parseRgbColor(
|
|
299
|
-
const
|
|
300
|
-
if (
|
|
301
|
-
const r = parseInt(
|
|
302
|
-
|
|
299
|
+
parseRgbColor(t) {
|
|
300
|
+
const e = this.extractIntExpression();
|
|
301
|
+
if (e) {
|
|
302
|
+
const r = parseInt(e) & 16777215;
|
|
303
|
+
t.color.rgbValue = r;
|
|
303
304
|
}
|
|
304
305
|
this.consumeOptionalTerminator();
|
|
305
306
|
}
|
|
@@ -308,8 +309,8 @@ class O {
|
|
|
308
309
|
* @param relative - Whether to allow relative values (ending in 'x')
|
|
309
310
|
* @returns Extracted expression
|
|
310
311
|
*/
|
|
311
|
-
extractFloatExpression(
|
|
312
|
-
const
|
|
312
|
+
extractFloatExpression(t = !1) {
|
|
313
|
+
const e = t ? /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?x?/ : /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/, r = this.scanner.tail.match(e);
|
|
313
314
|
if (r) {
|
|
314
315
|
const a = r[0];
|
|
315
316
|
return this.scanner.consume(a.length), a;
|
|
@@ -321,10 +322,10 @@ class O {
|
|
|
321
322
|
* @returns Extracted expression
|
|
322
323
|
*/
|
|
323
324
|
extractIntExpression() {
|
|
324
|
-
const
|
|
325
|
-
if (
|
|
326
|
-
const
|
|
327
|
-
return this.scanner.consume(
|
|
325
|
+
const t = this.scanner.tail.match(/^\d+/);
|
|
326
|
+
if (t) {
|
|
327
|
+
const e = t[0];
|
|
328
|
+
return this.scanner.consume(e.length), e;
|
|
328
329
|
}
|
|
329
330
|
return "";
|
|
330
331
|
}
|
|
@@ -333,27 +334,27 @@ class O {
|
|
|
333
334
|
* @param escape - Whether to handle escaped semicolons
|
|
334
335
|
* @returns Extracted expression
|
|
335
336
|
*/
|
|
336
|
-
extractExpression(
|
|
337
|
-
const
|
|
338
|
-
if (
|
|
337
|
+
extractExpression(t = !1) {
|
|
338
|
+
const e = this.scanner.find(";", t);
|
|
339
|
+
if (e < 0) {
|
|
339
340
|
const h = this.scanner.tail;
|
|
340
341
|
return this.scanner.consume(h.length), h;
|
|
341
342
|
}
|
|
342
|
-
const a = this.scanner.peek(
|
|
343
|
+
const a = this.scanner.peek(e - this.scanner.currentIndex - 1) === "\\", i = this.scanner.tail.slice(0, e - this.scanner.currentIndex + (a ? 1 : 0));
|
|
343
344
|
return this.scanner.consume(i.length + 1), i;
|
|
344
345
|
}
|
|
345
346
|
/**
|
|
346
347
|
* Parse font properties
|
|
347
348
|
* @param ctx - The context to update
|
|
348
349
|
*/
|
|
349
|
-
parseFontProperties(
|
|
350
|
-
const
|
|
351
|
-
if (
|
|
352
|
-
const r =
|
|
350
|
+
parseFontProperties(t) {
|
|
351
|
+
const e = this.extractExpression().split("|");
|
|
352
|
+
if (e.length > 0 && e[0]) {
|
|
353
|
+
const r = e[0];
|
|
353
354
|
let a = "Regular", i = 400;
|
|
354
|
-
for (const h of
|
|
355
|
+
for (const h of e.slice(1))
|
|
355
356
|
h.startsWith("b1") ? i = 700 : h.startsWith("i1") && (a = "Italic");
|
|
356
|
-
|
|
357
|
+
t.fontFace = {
|
|
357
358
|
family: r,
|
|
358
359
|
style: a,
|
|
359
360
|
weight: i
|
|
@@ -365,21 +366,21 @@ class O {
|
|
|
365
366
|
* Handles properties like indentation, alignment, and tab stops
|
|
366
367
|
* @param ctx - The context to update
|
|
367
368
|
*/
|
|
368
|
-
parseParagraphProperties(
|
|
369
|
-
const
|
|
370
|
-
let r =
|
|
369
|
+
parseParagraphProperties(t) {
|
|
370
|
+
const e = new g(this.extractExpression());
|
|
371
|
+
let r = t.paragraph.indent, a = t.paragraph.left, i = t.paragraph.right, h = t.paragraph.align, u = [];
|
|
371
372
|
const n = () => {
|
|
372
|
-
const l =
|
|
373
|
+
const l = e.tail.match(/^[+-]?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?/);
|
|
373
374
|
if (l) {
|
|
374
375
|
const o = parseFloat(l[0]);
|
|
375
|
-
for (
|
|
376
|
-
|
|
376
|
+
for (e.consume(l[0].length); e.peek() === ","; )
|
|
377
|
+
e.consume(1);
|
|
377
378
|
return o;
|
|
378
379
|
}
|
|
379
380
|
return 0;
|
|
380
381
|
};
|
|
381
|
-
for (;
|
|
382
|
-
switch (
|
|
382
|
+
for (; e.hasData; )
|
|
383
|
+
switch (e.get()) {
|
|
383
384
|
case "i":
|
|
384
385
|
r = n();
|
|
385
386
|
break;
|
|
@@ -392,26 +393,26 @@ class O {
|
|
|
392
393
|
case "x":
|
|
393
394
|
break;
|
|
394
395
|
case "q": {
|
|
395
|
-
const o =
|
|
396
|
-
for (h =
|
|
397
|
-
|
|
396
|
+
const o = e.get();
|
|
397
|
+
for (h = S[o] || 0; e.peek() === ","; )
|
|
398
|
+
e.consume(1);
|
|
398
399
|
break;
|
|
399
400
|
}
|
|
400
401
|
case "t":
|
|
401
|
-
for (u = [];
|
|
402
|
-
const o =
|
|
402
|
+
for (u = []; e.hasData; ) {
|
|
403
|
+
const o = e.peek();
|
|
403
404
|
if (o === "r" || o === "c") {
|
|
404
|
-
|
|
405
|
+
e.consume(1);
|
|
405
406
|
const c = n();
|
|
406
407
|
u.push(o + c.toString());
|
|
407
408
|
} else {
|
|
408
409
|
const c = n();
|
|
409
|
-
isNaN(c) ?
|
|
410
|
+
isNaN(c) ? e.consume(1) : u.push(c);
|
|
410
411
|
}
|
|
411
412
|
}
|
|
412
413
|
break;
|
|
413
414
|
}
|
|
414
|
-
|
|
415
|
+
t.paragraph = {
|
|
415
416
|
indent: r,
|
|
416
417
|
left: a,
|
|
417
418
|
right: i,
|
|
@@ -499,7 +500,7 @@ class O {
|
|
|
499
500
|
continue;
|
|
500
501
|
}
|
|
501
502
|
if (n === "%" && this.scanner.peek(1) === "%") {
|
|
502
|
-
const o = this.scanner.peek(2).toLowerCase(), c =
|
|
503
|
+
const o = this.scanner.peek(2).toLowerCase(), c = F[o];
|
|
503
504
|
if (c) {
|
|
504
505
|
this.scanner.consume(3), i += c;
|
|
505
506
|
continue;
|
|
@@ -548,19 +549,19 @@ class O {
|
|
|
548
549
|
for (; ; ) {
|
|
549
550
|
const [i, h] = a();
|
|
550
551
|
if (i)
|
|
551
|
-
yield new
|
|
552
|
+
yield new b(i, this.ctx, h), r && (yield new b(r, this.ctx, null), r = null);
|
|
552
553
|
else
|
|
553
554
|
break;
|
|
554
555
|
}
|
|
555
556
|
}
|
|
556
557
|
}
|
|
557
|
-
class
|
|
558
|
+
class g {
|
|
558
559
|
/**
|
|
559
560
|
* Create a new text scanner
|
|
560
561
|
* @param text - The text to scan
|
|
561
562
|
*/
|
|
562
|
-
constructor(
|
|
563
|
-
this.text =
|
|
563
|
+
constructor(t) {
|
|
564
|
+
this.text = t, this.textLen = t.length, this._index = 0;
|
|
564
565
|
}
|
|
565
566
|
/**
|
|
566
567
|
* Get the current index in the text
|
|
@@ -587,24 +588,24 @@ class f {
|
|
|
587
588
|
get() {
|
|
588
589
|
if (this.isEmpty)
|
|
589
590
|
return "";
|
|
590
|
-
const
|
|
591
|
-
return this._index++,
|
|
591
|
+
const t = this.text[this._index];
|
|
592
|
+
return this._index++, t;
|
|
592
593
|
}
|
|
593
594
|
/**
|
|
594
595
|
* Advance the index by the specified count
|
|
595
596
|
* @param count - Number of characters to advance
|
|
596
597
|
*/
|
|
597
|
-
consume(
|
|
598
|
-
this._index = Math.max(0, Math.min(this._index +
|
|
598
|
+
consume(t = 1) {
|
|
599
|
+
this._index = Math.max(0, Math.min(this._index + t, this.textLen));
|
|
599
600
|
}
|
|
600
601
|
/**
|
|
601
602
|
* Look at a character without advancing the index
|
|
602
603
|
* @param offset - Offset from current position
|
|
603
604
|
* @returns The character at the offset position, or empty string if out of bounds
|
|
604
605
|
*/
|
|
605
|
-
peek(
|
|
606
|
-
const
|
|
607
|
-
return
|
|
606
|
+
peek(t = 0) {
|
|
607
|
+
const e = this._index + t;
|
|
608
|
+
return e >= this.textLen || e < 0 ? "" : this.text[e];
|
|
608
609
|
}
|
|
609
610
|
/**
|
|
610
611
|
* Find the next occurrence of a character
|
|
@@ -612,12 +613,12 @@ class f {
|
|
|
612
613
|
* @param escape - Whether to handle escaped characters
|
|
613
614
|
* @returns Index of the character, or -1 if not found
|
|
614
615
|
*/
|
|
615
|
-
find(
|
|
616
|
+
find(t, e = !1) {
|
|
616
617
|
let r = this._index;
|
|
617
618
|
for (; r < this.textLen; ) {
|
|
618
|
-
if (
|
|
619
|
+
if (e && this.text[r] === "\\") {
|
|
619
620
|
if (r + 1 < this.textLen) {
|
|
620
|
-
if (this.text[r + 1] ===
|
|
621
|
+
if (this.text[r + 1] === t)
|
|
621
622
|
return r + 1;
|
|
622
623
|
r += 2;
|
|
623
624
|
continue;
|
|
@@ -625,7 +626,7 @@ class f {
|
|
|
625
626
|
r++;
|
|
626
627
|
continue;
|
|
627
628
|
}
|
|
628
|
-
if (this.text[r] ===
|
|
629
|
+
if (this.text[r] === t)
|
|
629
630
|
return r;
|
|
630
631
|
r++;
|
|
631
632
|
}
|
|
@@ -648,15 +649,110 @@ class f {
|
|
|
648
649
|
* @returns Number of spaces consumed
|
|
649
650
|
*/
|
|
650
651
|
consumeSpaces() {
|
|
651
|
-
let
|
|
652
|
+
let t = 0;
|
|
652
653
|
for (; this.isNextSpace(); )
|
|
653
|
-
this.consume(),
|
|
654
|
-
return
|
|
654
|
+
this.consume(), t++;
|
|
655
|
+
return t;
|
|
655
656
|
}
|
|
656
657
|
}
|
|
657
|
-
class
|
|
658
|
+
class f {
|
|
659
|
+
// Store as 0xRRGGBB or null
|
|
660
|
+
/**
|
|
661
|
+
* Create a new MTextColor instance.
|
|
662
|
+
* @param color The initial color: number for ACI, [r,g,b] for RGB, or null/undefined for default (ACI=256).
|
|
663
|
+
*/
|
|
664
|
+
constructor(t) {
|
|
665
|
+
this._aci = 256, this._rgbValue = null, Array.isArray(t) ? this.rgb = t : typeof t == "number" ? this.aci = t : this.aci = 256;
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Get the current ACI color value.
|
|
669
|
+
* @returns The ACI color (0-256), or null if using RGB.
|
|
670
|
+
*/
|
|
671
|
+
get aci() {
|
|
672
|
+
return this._aci;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Set the ACI color value. Setting this disables any RGB color.
|
|
676
|
+
* @param value The ACI color (0-256), or null to unset.
|
|
677
|
+
* @throws Error if value is out of range.
|
|
678
|
+
*/
|
|
679
|
+
set aci(t) {
|
|
680
|
+
if (t === null)
|
|
681
|
+
this._aci = null;
|
|
682
|
+
else if (t >= 0 && t <= 256)
|
|
683
|
+
this._aci = t, this._rgbValue = null;
|
|
684
|
+
else
|
|
685
|
+
throw new Error("ACI not in range [0, 256]");
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Get the current RGB color as a tuple [r, g, b], or null if not set.
|
|
689
|
+
* @returns The RGB color tuple, or null if using ACI.
|
|
690
|
+
*/
|
|
691
|
+
get rgb() {
|
|
692
|
+
if (this._rgbValue === null) return null;
|
|
693
|
+
const t = this._rgbValue >> 16 & 255, e = this._rgbValue >> 8 & 255, r = this._rgbValue & 255;
|
|
694
|
+
return [t, e, r];
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Set the RGB color. Setting this disables ACI color.
|
|
698
|
+
* @param value The RGB color tuple [r, g, b], or null to use ACI.
|
|
699
|
+
*/
|
|
700
|
+
set rgb(t) {
|
|
701
|
+
if (t) {
|
|
702
|
+
const [e, r, a] = t;
|
|
703
|
+
this._rgbValue = (e & 255) << 16 | (r & 255) << 8 | a & 255, this._aci = null;
|
|
704
|
+
} else
|
|
705
|
+
this._rgbValue = null;
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Returns true if the color is set by RGB, false if by ACI.
|
|
709
|
+
*/
|
|
710
|
+
get isRgb() {
|
|
711
|
+
return this._rgbValue !== null;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Returns true if the color is set by ACI, false if by RGB.
|
|
715
|
+
*/
|
|
716
|
+
get isAci() {
|
|
717
|
+
return this._rgbValue === null && this._aci !== null;
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Get or set the internal RGB value as a number (0xRRGGBB), or null if not set.
|
|
721
|
+
* Setting this will switch to RGB mode and set ACI to null.
|
|
722
|
+
*/
|
|
723
|
+
get rgbValue() {
|
|
724
|
+
return this._rgbValue;
|
|
725
|
+
}
|
|
726
|
+
set rgbValue(t) {
|
|
727
|
+
t === null ? this._rgbValue = null : (this._rgbValue = t & 16777215, this._aci = null);
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* Returns a deep copy of this color.
|
|
731
|
+
* @returns A new MTextColor instance with the same color state.
|
|
732
|
+
*/
|
|
733
|
+
copy() {
|
|
734
|
+
const t = new f();
|
|
735
|
+
return t._aci = this._aci, t._rgbValue = this._rgbValue, t;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Returns a plain object for serialization.
|
|
739
|
+
* @returns An object with aci, rgb (tuple), and rgbValue (number or null).
|
|
740
|
+
*/
|
|
741
|
+
toObject() {
|
|
742
|
+
return { aci: this._aci, rgb: this.rgb, rgbValue: this._rgbValue };
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Equality check for color.
|
|
746
|
+
* @param other The other MTextColor to compare.
|
|
747
|
+
* @returns True if both ACI and RGB values are equal.
|
|
748
|
+
*/
|
|
749
|
+
equals(t) {
|
|
750
|
+
return this._aci === t._aci && this._rgbValue === t._rgbValue;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
class d {
|
|
658
754
|
constructor() {
|
|
659
|
-
this._stroke = 0, this.continueStroke = !1, this.
|
|
755
|
+
this._stroke = 0, this.continueStroke = !1, this.color = new f(), this.align = 0, this.fontFace = { family: "", style: "Regular", weight: 400 }, this._capHeight = { value: 1, isRelative: !1 }, this._widthFactor = { value: 1, isRelative: !1 }, this._charTrackingFactor = { value: 1, isRelative: !1 }, this.oblique = 0, this.paragraph = {
|
|
660
756
|
indent: 0,
|
|
661
757
|
left: 0,
|
|
662
758
|
right: 0,
|
|
@@ -674,10 +770,10 @@ class g {
|
|
|
674
770
|
* Set the capital letter height
|
|
675
771
|
* @param value - Height value
|
|
676
772
|
*/
|
|
677
|
-
set capHeight(
|
|
773
|
+
set capHeight(t) {
|
|
678
774
|
this._capHeight = {
|
|
679
|
-
value: Math.abs(
|
|
680
|
-
isRelative:
|
|
775
|
+
value: Math.abs(t.value),
|
|
776
|
+
isRelative: t.isRelative
|
|
681
777
|
};
|
|
682
778
|
}
|
|
683
779
|
/**
|
|
@@ -690,10 +786,10 @@ class g {
|
|
|
690
786
|
* Set the character width factor
|
|
691
787
|
* @param value - Width factor value
|
|
692
788
|
*/
|
|
693
|
-
set widthFactor(
|
|
789
|
+
set widthFactor(t) {
|
|
694
790
|
this._widthFactor = {
|
|
695
|
-
value: Math.abs(
|
|
696
|
-
isRelative:
|
|
791
|
+
value: Math.abs(t.value),
|
|
792
|
+
isRelative: t.isRelative
|
|
697
793
|
};
|
|
698
794
|
}
|
|
699
795
|
/**
|
|
@@ -706,28 +802,37 @@ class g {
|
|
|
706
802
|
* Set the character tracking factor
|
|
707
803
|
* @param value - Tracking factor value
|
|
708
804
|
*/
|
|
709
|
-
set charTrackingFactor(
|
|
805
|
+
set charTrackingFactor(t) {
|
|
710
806
|
this._charTrackingFactor = {
|
|
711
|
-
value: Math.abs(
|
|
712
|
-
isRelative:
|
|
807
|
+
value: Math.abs(t.value),
|
|
808
|
+
isRelative: t.isRelative
|
|
713
809
|
};
|
|
714
810
|
}
|
|
715
811
|
/**
|
|
716
812
|
* Get the ACI color value
|
|
717
813
|
*/
|
|
718
814
|
get aci() {
|
|
719
|
-
return this.
|
|
815
|
+
return this.color.aci;
|
|
720
816
|
}
|
|
721
817
|
/**
|
|
722
818
|
* Set the ACI color value
|
|
723
819
|
* @param value - ACI color value (0-256)
|
|
724
820
|
* @throws Error if value is out of range
|
|
725
821
|
*/
|
|
726
|
-
set aci(
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
822
|
+
set aci(t) {
|
|
823
|
+
this.color.aci = t;
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Get the RGB color value
|
|
827
|
+
*/
|
|
828
|
+
get rgb() {
|
|
829
|
+
return this.color.rgb;
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Set the RGB color value
|
|
833
|
+
*/
|
|
834
|
+
set rgb(t) {
|
|
835
|
+
this.color.rgb = t;
|
|
731
836
|
}
|
|
732
837
|
/**
|
|
733
838
|
* Get whether text is underlined
|
|
@@ -739,8 +844,8 @@ class g {
|
|
|
739
844
|
* Set whether text is underlined
|
|
740
845
|
* @param value - Whether to underline
|
|
741
846
|
*/
|
|
742
|
-
set underline(
|
|
743
|
-
this._setStrokeState(1,
|
|
847
|
+
set underline(t) {
|
|
848
|
+
this._setStrokeState(1, t);
|
|
744
849
|
}
|
|
745
850
|
/**
|
|
746
851
|
* Get whether text has strike-through
|
|
@@ -752,8 +857,8 @@ class g {
|
|
|
752
857
|
* Set whether text has strike-through
|
|
753
858
|
* @param value - Whether to strike through
|
|
754
859
|
*/
|
|
755
|
-
set strikeThrough(
|
|
756
|
-
this._setStrokeState(4,
|
|
860
|
+
set strikeThrough(t) {
|
|
861
|
+
this._setStrokeState(4, t);
|
|
757
862
|
}
|
|
758
863
|
/**
|
|
759
864
|
* Get whether text has overline
|
|
@@ -765,8 +870,8 @@ class g {
|
|
|
765
870
|
* Set whether text has overline
|
|
766
871
|
* @param value - Whether to overline
|
|
767
872
|
*/
|
|
768
|
-
set overline(
|
|
769
|
-
this._setStrokeState(2,
|
|
873
|
+
set overline(t) {
|
|
874
|
+
this._setStrokeState(2, t);
|
|
770
875
|
}
|
|
771
876
|
/**
|
|
772
877
|
* Check if any stroke formatting is active
|
|
@@ -779,42 +884,43 @@ class g {
|
|
|
779
884
|
* @param stroke - The stroke type to set
|
|
780
885
|
* @param state - Whether to enable or disable the stroke
|
|
781
886
|
*/
|
|
782
|
-
_setStrokeState(
|
|
783
|
-
|
|
887
|
+
_setStrokeState(t, e = !0) {
|
|
888
|
+
e ? this._stroke |= t : this._stroke &= ~t;
|
|
784
889
|
}
|
|
785
890
|
/**
|
|
786
891
|
* Create a copy of this context
|
|
787
892
|
* @returns A new context with the same properties
|
|
788
893
|
*/
|
|
789
894
|
copy() {
|
|
790
|
-
const
|
|
791
|
-
return
|
|
895
|
+
const t = new d();
|
|
896
|
+
return t._stroke = this._stroke, t.continueStroke = this.continueStroke, t.color = this.color.copy(), t.align = this.align, t.fontFace = { ...this.fontFace }, t._capHeight = { ...this._capHeight }, t._widthFactor = { ...this._widthFactor }, t._charTrackingFactor = { ...this._charTrackingFactor }, t.oblique = this.oblique, t.paragraph = { ...this.paragraph }, t;
|
|
792
897
|
}
|
|
793
898
|
}
|
|
794
|
-
class
|
|
899
|
+
class b {
|
|
795
900
|
/**
|
|
796
901
|
* Create a new MText token
|
|
797
902
|
* @param type - The token type
|
|
798
903
|
* @param ctx - The text context at this token
|
|
799
904
|
* @param data - Optional token data
|
|
800
905
|
*/
|
|
801
|
-
constructor(
|
|
802
|
-
this.type =
|
|
906
|
+
constructor(t, e, r) {
|
|
907
|
+
this.type = t, this.ctx = e, this.data = r;
|
|
803
908
|
}
|
|
804
909
|
}
|
|
805
910
|
export {
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
911
|
+
f as MTextColor,
|
|
912
|
+
d as MTextContext,
|
|
913
|
+
_ as MTextLineAlignment,
|
|
914
|
+
m as MTextParagraphAlignment,
|
|
915
|
+
D as MTextParser,
|
|
916
|
+
E as MTextStroke,
|
|
917
|
+
b as MTextToken,
|
|
918
|
+
g as TextScanner,
|
|
813
919
|
k as TokenType,
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
920
|
+
I as escapeDxfLineEndings,
|
|
921
|
+
O as getFonts,
|
|
922
|
+
N as hasInlineFormattingCodes,
|
|
923
|
+
v as int2rgb,
|
|
818
924
|
R as rgb2int
|
|
819
925
|
};
|
|
820
926
|
//# sourceMappingURL=parser.es.js.map
|