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