@mlightcad/mtext-renderer 0.7.3 → 0.7.4
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/index.js +109 -84
- package/dist/index.umd.cjs +3 -3
- package/dist/mtext-renderer-worker.js +442 -417
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -9896,7 +9896,7 @@ class Mh extends Ma {
|
|
|
9896
9896
|
return new fa("?", e, this);
|
|
9897
9897
|
}
|
|
9898
9898
|
}
|
|
9899
|
-
|
|
9899
|
+
let le = class {
|
|
9900
9900
|
/**
|
|
9901
9901
|
* Converts an unsigned byte to a signed byte as used in SHX format.
|
|
9902
9902
|
* Values > 127 are converted to their signed equivalent (-128 to -1).
|
|
@@ -10051,7 +10051,7 @@ class le {
|
|
|
10051
10051
|
`Position ${e} is out of range for the data length ${this.data.byteLength}!`
|
|
10052
10052
|
);
|
|
10053
10053
|
}
|
|
10054
|
-
}
|
|
10054
|
+
};
|
|
10055
10055
|
var fe = /* @__PURE__ */ ((t) => (t.SHAPES = "shapes", t.BIGFONT = "bigfont", t.UNIFONT = "unifont", t))(fe || {});
|
|
10056
10056
|
class Ih {
|
|
10057
10057
|
parse(e) {
|
|
@@ -22704,27 +22704,53 @@ class Ll {
|
|
|
22704
22704
|
constructor(e, r, n = {}) {
|
|
22705
22705
|
this.continueStroke = !1, this.inStackContext = !1, this.scanner = new Er(e);
|
|
22706
22706
|
const a = r ?? new Ut();
|
|
22707
|
-
this.ctxStack = new Ol(a), this.yieldPropertyCommands = n.yieldPropertyCommands ?? !1, this.resetParagraphParameters = n.resetParagraphParameters ?? !1;
|
|
22707
|
+
this.ctxStack = new Ol(a), this.yieldPropertyCommands = n.yieldPropertyCommands ?? !1, this.resetParagraphParameters = n.resetParagraphParameters ?? !1, this.mifDecoder = n.mifDecoder ?? this.decodeMultiByteChar.bind(this), this.mifCodeLength = n.mifCodeLength ?? "auto";
|
|
22708
22708
|
}
|
|
22709
22709
|
/**
|
|
22710
22710
|
* Decode multi-byte character from hex code
|
|
22711
|
-
* @param hex - Hex code string (e.g. "C4E3")
|
|
22711
|
+
* @param hex - Hex code string (e.g. "C4E3" or "1A2B3")
|
|
22712
22712
|
* @returns Decoded character or empty square if invalid
|
|
22713
22713
|
*/
|
|
22714
22714
|
decodeMultiByteChar(e) {
|
|
22715
22715
|
try {
|
|
22716
|
-
|
|
22717
|
-
|
|
22718
|
-
|
|
22719
|
-
|
|
22720
|
-
|
|
22721
|
-
|
|
22722
|
-
|
|
22723
|
-
|
|
22716
|
+
if (e.length === 5) {
|
|
22717
|
+
const r = e[0];
|
|
22718
|
+
let n = "gbk";
|
|
22719
|
+
r === "1" ? n = "shift-jis" : r === "2" && (n = "big5");
|
|
22720
|
+
const a = new Uint8Array([
|
|
22721
|
+
parseInt(e.substr(1, 2), 16),
|
|
22722
|
+
parseInt(e.substr(3, 2), 16)
|
|
22723
|
+
]);
|
|
22724
|
+
return new TextDecoder(n).decode(a);
|
|
22725
|
+
} else if (e.length === 4) {
|
|
22726
|
+
const r = new Uint8Array([
|
|
22727
|
+
parseInt(e.substr(0, 2), 16),
|
|
22728
|
+
parseInt(e.substr(2, 2), 16)
|
|
22729
|
+
]), n = new TextDecoder("gbk").decode(r);
|
|
22730
|
+
if (n !== "▯")
|
|
22731
|
+
return n;
|
|
22732
|
+
const a = new TextDecoder("big5").decode(r);
|
|
22733
|
+
if (a !== "▯")
|
|
22734
|
+
return a;
|
|
22735
|
+
}
|
|
22736
|
+
return "▯";
|
|
22724
22737
|
} catch {
|
|
22725
22738
|
return "▯";
|
|
22726
22739
|
}
|
|
22727
22740
|
}
|
|
22741
|
+
/**
|
|
22742
|
+
* Extract MIF hex code from scanner
|
|
22743
|
+
* @param length - The length of the hex code to extract (4 or 5), or 'auto' to detect
|
|
22744
|
+
* @returns The extracted hex code, or null if not found
|
|
22745
|
+
*/
|
|
22746
|
+
extractMifCode(e) {
|
|
22747
|
+
var r, n, a;
|
|
22748
|
+
if (e === "auto") {
|
|
22749
|
+
const i = (r = this.scanner.tail.match(/^[0-9A-Fa-f]{5}/)) == null ? void 0 : r[0];
|
|
22750
|
+
return i || ((n = this.scanner.tail.match(/^[0-9A-Fa-f]{4}/)) == null ? void 0 : n[0]) || null;
|
|
22751
|
+
} else
|
|
22752
|
+
return ((a = this.scanner.tail.match(new RegExp(`^[0-9A-Fa-f]{${e}}`))) == null ? void 0 : a[0]) || null;
|
|
22753
|
+
}
|
|
22728
22754
|
/**
|
|
22729
22755
|
* Push current context onto the stack
|
|
22730
22756
|
*/
|
|
@@ -23110,28 +23136,27 @@ class Ll {
|
|
|
23110
23136
|
return i.indent !== 0 && (s.indent = 0), i.left !== 0 && (s.left = 0), i.right !== 0 && (s.right = 0), i.align !== 0 && (s.align = 0), JSON.stringify(i.tabs) !== JSON.stringify([]) && (s.tabs = []), s;
|
|
23111
23137
|
}
|
|
23112
23138
|
const n = () => {
|
|
23113
|
-
|
|
23114
|
-
let i = "";
|
|
23139
|
+
let a = "";
|
|
23115
23140
|
for (; this.scanner.hasData; ) {
|
|
23116
|
-
let
|
|
23117
|
-
const
|
|
23118
|
-
if (
|
|
23119
|
-
if (this.scanner.consume(1),
|
|
23141
|
+
let i = !1, s = this.scanner.peek();
|
|
23142
|
+
const o = this.scanner.currentIndex;
|
|
23143
|
+
if (s.charCodeAt(0) < 32) {
|
|
23144
|
+
if (this.scanner.consume(1), s === " ")
|
|
23120
23145
|
return [5, null];
|
|
23121
|
-
if (
|
|
23146
|
+
if (s === `
|
|
23122
23147
|
`)
|
|
23123
23148
|
return [6, null];
|
|
23124
|
-
|
|
23149
|
+
s = " ";
|
|
23125
23150
|
}
|
|
23126
|
-
if (
|
|
23151
|
+
if (s === "\\")
|
|
23127
23152
|
if ("\\{}".includes(this.scanner.peek(1)))
|
|
23128
|
-
|
|
23153
|
+
i = !0, this.scanner.consume(1), s = this.scanner.peek();
|
|
23129
23154
|
else {
|
|
23130
|
-
if (
|
|
23131
|
-
return [1,
|
|
23155
|
+
if (a)
|
|
23156
|
+
return [1, a];
|
|
23132
23157
|
this.scanner.consume(1);
|
|
23133
|
-
const
|
|
23134
|
-
switch (
|
|
23158
|
+
const c = this.scanner.get();
|
|
23159
|
+
switch (c) {
|
|
23135
23160
|
case "~":
|
|
23136
23161
|
return [4, null];
|
|
23137
23162
|
case "P":
|
|
@@ -23142,116 +23167,116 @@ class Ll {
|
|
|
23142
23167
|
return [8, null];
|
|
23143
23168
|
case "S": {
|
|
23144
23169
|
this.inStackContext = !0;
|
|
23145
|
-
const
|
|
23146
|
-
return this.inStackContext = !1,
|
|
23170
|
+
const u = this.parseStacking();
|
|
23171
|
+
return this.inStackContext = !1, u;
|
|
23147
23172
|
}
|
|
23148
23173
|
case "m":
|
|
23149
23174
|
case "M":
|
|
23150
23175
|
if (this.scanner.peek() === "+") {
|
|
23151
23176
|
this.scanner.consume(1);
|
|
23152
|
-
const
|
|
23153
|
-
if (
|
|
23154
|
-
this.scanner.consume(
|
|
23155
|
-
const
|
|
23156
|
-
return
|
|
23177
|
+
const u = this.extractMifCode(this.mifCodeLength);
|
|
23178
|
+
if (u) {
|
|
23179
|
+
this.scanner.consume(u.length);
|
|
23180
|
+
const h = this.mifDecoder(u);
|
|
23181
|
+
return a ? [1, a] : [1, h];
|
|
23157
23182
|
}
|
|
23158
23183
|
this.scanner.consume(-1);
|
|
23159
23184
|
}
|
|
23160
|
-
|
|
23185
|
+
a += "\\M";
|
|
23161
23186
|
continue;
|
|
23162
23187
|
case "U":
|
|
23163
23188
|
if (this.scanner.peek() === "+") {
|
|
23164
23189
|
this.scanner.consume(1);
|
|
23165
|
-
const
|
|
23166
|
-
if (
|
|
23167
|
-
const
|
|
23168
|
-
this.scanner.consume(
|
|
23169
|
-
const
|
|
23170
|
-
let
|
|
23190
|
+
const u = this.scanner.tail.match(/^[0-9A-Fa-f]{4,8}/);
|
|
23191
|
+
if (u) {
|
|
23192
|
+
const h = u[0];
|
|
23193
|
+
this.scanner.consume(h.length);
|
|
23194
|
+
const d = parseInt(h, 16);
|
|
23195
|
+
let p = "";
|
|
23171
23196
|
try {
|
|
23172
|
-
|
|
23197
|
+
p = String.fromCodePoint(d);
|
|
23173
23198
|
} catch {
|
|
23174
|
-
|
|
23199
|
+
p = "▯";
|
|
23175
23200
|
}
|
|
23176
|
-
return
|
|
23201
|
+
return a ? [1, a] : [1, p];
|
|
23177
23202
|
}
|
|
23178
23203
|
this.scanner.consume(-1);
|
|
23179
23204
|
}
|
|
23180
|
-
|
|
23205
|
+
a += "\\U";
|
|
23181
23206
|
continue;
|
|
23182
23207
|
default:
|
|
23183
|
-
if (
|
|
23208
|
+
if (c)
|
|
23184
23209
|
try {
|
|
23185
|
-
const
|
|
23186
|
-
if (this.yieldPropertyCommands &&
|
|
23187
|
-
return [9,
|
|
23210
|
+
const u = this.parseProperties(c);
|
|
23211
|
+
if (this.yieldPropertyCommands && u)
|
|
23212
|
+
return [9, u];
|
|
23188
23213
|
continue;
|
|
23189
23214
|
} catch {
|
|
23190
|
-
const
|
|
23191
|
-
|
|
23215
|
+
const u = this.scanner.tail.slice(
|
|
23216
|
+
o,
|
|
23192
23217
|
this.scanner.currentIndex
|
|
23193
23218
|
);
|
|
23194
|
-
|
|
23219
|
+
a += u;
|
|
23195
23220
|
}
|
|
23196
23221
|
}
|
|
23197
23222
|
continue;
|
|
23198
23223
|
}
|
|
23199
|
-
if (
|
|
23200
|
-
const
|
|
23201
|
-
if (
|
|
23202
|
-
this.scanner.consume(3),
|
|
23224
|
+
if (s === "%" && this.scanner.peek(1) === "%") {
|
|
23225
|
+
const c = this.scanner.peek(2).toLowerCase(), u = Ul[c];
|
|
23226
|
+
if (u) {
|
|
23227
|
+
this.scanner.consume(3), a += u;
|
|
23203
23228
|
continue;
|
|
23204
23229
|
} else {
|
|
23205
23230
|
this.scanner.consume(3);
|
|
23206
23231
|
continue;
|
|
23207
23232
|
}
|
|
23208
23233
|
}
|
|
23209
|
-
if (
|
|
23210
|
-
return
|
|
23211
|
-
if (!
|
|
23212
|
-
if (
|
|
23213
|
-
if (
|
|
23214
|
-
return [1,
|
|
23234
|
+
if (s === " ")
|
|
23235
|
+
return a ? (this.scanner.consume(1), e = 3, [1, a]) : (this.scanner.consume(1), [3, null]);
|
|
23236
|
+
if (!i) {
|
|
23237
|
+
if (s === "{") {
|
|
23238
|
+
if (a)
|
|
23239
|
+
return [1, a];
|
|
23215
23240
|
this.scanner.consume(1), this.pushCtx();
|
|
23216
23241
|
continue;
|
|
23217
|
-
} else if (
|
|
23218
|
-
if (
|
|
23219
|
-
return [1,
|
|
23242
|
+
} else if (s === "}") {
|
|
23243
|
+
if (a)
|
|
23244
|
+
return [1, a];
|
|
23220
23245
|
if (this.scanner.consume(1), this.yieldPropertyCommands) {
|
|
23221
|
-
const
|
|
23246
|
+
const c = this.ctxStack.current;
|
|
23222
23247
|
this.popCtx();
|
|
23223
|
-
const
|
|
23224
|
-
if (Object.keys(
|
|
23248
|
+
const u = this.getPropertyChanges(c, this.ctxStack.current);
|
|
23249
|
+
if (Object.keys(u).length > 0)
|
|
23225
23250
|
return [
|
|
23226
23251
|
9,
|
|
23227
|
-
{ command: void 0, changes:
|
|
23252
|
+
{ command: void 0, changes: u, depth: this.ctxStack.depth }
|
|
23228
23253
|
];
|
|
23229
23254
|
} else
|
|
23230
23255
|
this.popCtx();
|
|
23231
23256
|
continue;
|
|
23232
23257
|
}
|
|
23233
23258
|
}
|
|
23234
|
-
if (!this.inStackContext &&
|
|
23235
|
-
const
|
|
23236
|
-
if (
|
|
23237
|
-
const
|
|
23238
|
-
if (this.scanner.consume(2),
|
|
23239
|
-
|
|
23259
|
+
if (!this.inStackContext && s === "^") {
|
|
23260
|
+
const c = this.scanner.peek(1);
|
|
23261
|
+
if (c) {
|
|
23262
|
+
const u = c.charCodeAt(0);
|
|
23263
|
+
if (this.scanner.consume(2), u === 32)
|
|
23264
|
+
a += "^";
|
|
23240
23265
|
else {
|
|
23241
|
-
if (
|
|
23242
|
-
return
|
|
23243
|
-
if (
|
|
23244
|
-
return
|
|
23245
|
-
if (
|
|
23266
|
+
if (u === 73)
|
|
23267
|
+
return a ? [1, a] : [5, null];
|
|
23268
|
+
if (u === 74)
|
|
23269
|
+
return a ? [1, a] : [6, null];
|
|
23270
|
+
if (u === 77)
|
|
23246
23271
|
continue;
|
|
23247
|
-
|
|
23272
|
+
a += "▯";
|
|
23248
23273
|
}
|
|
23249
23274
|
continue;
|
|
23250
23275
|
}
|
|
23251
23276
|
}
|
|
23252
|
-
this.scanner.consume(1),
|
|
23277
|
+
this.scanner.consume(1), s.charCodeAt(0) >= 32 && (a += s);
|
|
23253
23278
|
}
|
|
23254
|
-
return
|
|
23279
|
+
return a ? [1, a] : [0, null];
|
|
23255
23280
|
};
|
|
23256
23281
|
for (; ; ) {
|
|
23257
23282
|
const [a, i] = n.call(this);
|
|
@@ -24844,7 +24869,7 @@ class _l {
|
|
|
24844
24869
|
this.isInitialized || (await this.loadFonts([Le.instance.defaultFont]), this.isInitialized = !0);
|
|
24845
24870
|
}
|
|
24846
24871
|
}
|
|
24847
|
-
class
|
|
24872
|
+
class zl {
|
|
24848
24873
|
/**
|
|
24849
24874
|
* Constructor
|
|
24850
24875
|
*
|
|
@@ -24934,6 +24959,6 @@ export {
|
|
|
24934
24959
|
wt as MTextFlowDirection,
|
|
24935
24960
|
_l as MainThreadRenderer,
|
|
24936
24961
|
Ii as StyleManager,
|
|
24937
|
-
|
|
24962
|
+
zl as UnifiedRenderer,
|
|
24938
24963
|
Pl as WebWorkerRenderer
|
|
24939
24964
|
};
|