@mlightcad/mtext-renderer 0.8.8 → 0.8.10

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.
Files changed (40) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +523 -523
  3. package/dist/index.js +393 -392
  4. package/dist/index.umd.cjs +6 -6
  5. package/lib/cache/fontCacheManager.d.ts +71 -0
  6. package/lib/cache/index.d.ts +1 -0
  7. package/lib/cache/schema.d.ts +27 -0
  8. package/lib/common/eventManager.d.ts +26 -0
  9. package/lib/common/index.d.ts +2 -0
  10. package/lib/common/utils.d.ts +11 -0
  11. package/lib/font/baseFont.d.ts +81 -0
  12. package/lib/font/baseTextShape.d.ts +17 -0
  13. package/lib/font/charGeometryCache.d.ts +43 -0
  14. package/lib/font/defaultFontLoader.d.ts +50 -0
  15. package/lib/font/font.d.ts +25 -0
  16. package/lib/font/fontFactory.d.ts +31 -0
  17. package/lib/font/fontLoader.d.ts +58 -0
  18. package/lib/font/fontManager.d.ts +192 -0
  19. package/lib/font/index.d.ts +7 -0
  20. package/lib/font/meshFont.d.ts +138 -0
  21. package/lib/font/meshFontParser.d.ts +10 -0
  22. package/lib/font/meshTextShape.d.ts +33 -0
  23. package/lib/font/normalComputationToggle.d.ts +57 -0
  24. package/lib/font/shxFont.d.ts +62 -0
  25. package/lib/font/shxTextShape.d.ts +29 -0
  26. package/lib/font/threeFont.d.ts +50 -0
  27. package/lib/index.d.ts +5 -0
  28. package/lib/renderer/defaultStyleManager.d.ts +18 -0
  29. package/lib/renderer/index.d.ts +3 -0
  30. package/lib/renderer/mtext.d.ts +135 -0
  31. package/lib/renderer/mtextProcessor.d.ts +232 -0
  32. package/lib/renderer/styleManager.d.ts +20 -0
  33. package/lib/renderer/types.d.ts +114 -0
  34. package/lib/worker/baseRenderer.d.ts +91 -0
  35. package/lib/worker/index.d.ts +5 -0
  36. package/lib/worker/mainThreadRenderer.d.ts +49 -0
  37. package/lib/worker/mtextWorker.d.ts +1 -0
  38. package/lib/worker/unifiedRenderer.d.ts +69 -0
  39. package/lib/worker/webWorkerRenderer.d.ts +164 -0
  40. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -34,388 +34,14 @@ class mn {
34
34
  n.call(null, e, ...r);
35
35
  }
36
36
  }
37
- class zi {
38
- constructor() {
39
- this.cache = /* @__PURE__ */ new Map();
40
- }
41
- /**
42
- * Returns true if the geometry of the specified character code exists in the cache.
43
- * Otherwise, returns false.
44
- * @param code One character code.
45
- * @param size The font size.
46
- * @returns True if the geometry of the specified character code exists in the cache.
47
- * Otherwise, returns false.
48
- */
49
- hasGeometry(e, r) {
50
- const n = this.generateKey(e, r);
51
- return this.cache.has(n);
52
- }
53
- /**
54
- * Get the geometry for a single character from cache if available.
55
- * The cache key includes both character codeand size.
56
- * @param code The character code to get geometry from cache.
57
- * @param size The font size.
58
- * @returns The geometry for a single character from cache if avaiable.
59
- * Return undefined if the character not found in cache.
60
- */
61
- getGeometry(e, r) {
62
- const n = this.generateKey(e, r);
63
- if (this.cache.has(n))
64
- return this.cache.get(n);
65
- }
66
- /**
67
- * Set the geometry to cache for a single character.
68
- * @param char The character to set geometry for.
69
- * @param size The font size.
70
- * @param geometry The geometry to set.
71
- */
72
- setGeometry(e, r, n) {
73
- const a = this.generateKey(e, r);
74
- this.cache.set(a, n);
75
- }
76
- /**
77
- * Dispose all cached geometries.
78
- */
79
- dispose() {
80
- for (const e of this.cache.values())
81
- e.dispose();
82
- this.cache.clear();
83
- }
84
- /**
85
- * Generates cache key by character and font size.
86
- * @param char One character code.
87
- * @param size The font size.
88
- */
89
- generateKey(e, r) {
90
- return `${e}_${r}`;
91
- }
92
- }
93
- class Ra {
94
- constructor(e) {
95
- this.names = /* @__PURE__ */ new Set(), this.unsupportedChars = {}, this.encoding = e.encoding, e.alias.forEach((r) => this.names.add(r)), this.cache = new zi();
96
- }
97
- /**
98
- * Records an unsupported character in the font.
99
- * Increments the count for the given character in unsupportedChars.
100
- * @param char - The unsupported character to record
101
- */
102
- addUnsupportedChar(e) {
103
- this.unsupportedChars[e] || (this.unsupportedChars[e] = 0), this.unsupportedChars[e]++;
104
- }
105
- }
106
- class Ia extends _.Shape {
107
- constructor() {
108
- super(...arguments), this.width = 0;
109
- }
110
- }
111
- const Or = (t, e) => e.some((r) => t instanceof r);
112
- let bn, xn;
113
- function Wi() {
114
- return bn || (bn = [
115
- IDBDatabase,
116
- IDBObjectStore,
117
- IDBIndex,
118
- IDBCursor,
119
- IDBTransaction
120
- ]);
121
- }
122
- function qi() {
123
- return xn || (xn = [
124
- IDBCursor.prototype.advance,
125
- IDBCursor.prototype.continue,
126
- IDBCursor.prototype.continuePrimaryKey
127
- ]);
128
- }
129
- const Mr = /* @__PURE__ */ new WeakMap(), nr = /* @__PURE__ */ new WeakMap(), Kt = /* @__PURE__ */ new WeakMap();
130
- function Vi(t) {
131
- const e = new Promise((r, n) => {
132
- const a = () => {
133
- t.removeEventListener("success", i), t.removeEventListener("error", s);
134
- }, i = () => {
135
- r(Qe(t.result)), a();
136
- }, s = () => {
137
- n(t.error), a();
138
- };
139
- t.addEventListener("success", i), t.addEventListener("error", s);
140
- });
141
- return Kt.set(e, t), e;
142
- }
143
- function Xi(t) {
144
- if (Mr.has(t))
145
- return;
146
- const e = new Promise((r, n) => {
147
- const a = () => {
148
- t.removeEventListener("complete", i), t.removeEventListener("error", s), t.removeEventListener("abort", s);
149
- }, i = () => {
150
- r(), a();
151
- }, s = () => {
152
- n(t.error || new DOMException("AbortError", "AbortError")), a();
153
- };
154
- t.addEventListener("complete", i), t.addEventListener("error", s), t.addEventListener("abort", s);
155
- });
156
- Mr.set(t, e);
157
- }
158
- let Rr = {
159
- get(t, e, r) {
160
- if (t instanceof IDBTransaction) {
161
- if (e === "done")
162
- return Mr.get(t);
163
- if (e === "store")
164
- return r.objectStoreNames[1] ? void 0 : r.objectStore(r.objectStoreNames[0]);
165
- }
166
- return Qe(t[e]);
167
- },
168
- set(t, e, r) {
169
- return t[e] = r, !0;
170
- },
171
- has(t, e) {
172
- return t instanceof IDBTransaction && (e === "done" || e === "store") ? !0 : e in t;
173
- }
174
- };
175
- function Da(t) {
176
- Rr = t(Rr);
177
- }
178
- function Yi(t) {
179
- return qi().includes(t) ? function(...e) {
180
- return t.apply(Ir(this), e), Qe(this.request);
181
- } : function(...e) {
182
- return Qe(t.apply(Ir(this), e));
183
- };
184
- }
185
- function ji(t) {
186
- return typeof t == "function" ? Yi(t) : (t instanceof IDBTransaction && Xi(t), Or(t, Wi()) ? new Proxy(t, Rr) : t);
187
- }
188
- function Qe(t) {
189
- if (t instanceof IDBRequest)
190
- return Vi(t);
191
- if (nr.has(t))
192
- return nr.get(t);
193
- const e = ji(t);
194
- return e !== t && (nr.set(t, e), Kt.set(e, t)), e;
195
- }
196
- const Ir = (t) => Kt.get(t);
197
- function Zi(t, e, { blocked: r, upgrade: n, blocking: a, terminated: i } = {}) {
198
- const s = indexedDB.open(t, e), o = Qe(s);
199
- return n && s.addEventListener("upgradeneeded", (c) => {
200
- n(Qe(s.result), c.oldVersion, c.newVersion, Qe(s.transaction), c);
201
- }), r && s.addEventListener("blocked", (c) => r(
202
- // Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
203
- c.oldVersion,
204
- c.newVersion,
205
- c
206
- )), o.then((c) => {
207
- i && c.addEventListener("close", () => i()), a && c.addEventListener("versionchange", (u) => a(u.oldVersion, u.newVersion, u));
208
- }).catch(() => {
209
- }), o;
210
- }
211
- const $i = ["get", "getKey", "getAll", "getAllKeys", "count"], Ki = ["put", "add", "delete", "clear"], ar = /* @__PURE__ */ new Map();
212
- function Sn(t, e) {
213
- if (!(t instanceof IDBDatabase && !(e in t) && typeof e == "string"))
214
- return;
215
- if (ar.get(e))
216
- return ar.get(e);
217
- const r = e.replace(/FromIndex$/, ""), n = e !== r, a = Ki.includes(r);
218
- if (
219
- // Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
220
- !(r in (n ? IDBIndex : IDBObjectStore).prototype) || !(a || $i.includes(r))
221
- )
222
- return;
223
- const i = async function(s, ...o) {
224
- const c = this.transaction(s, a ? "readwrite" : "readonly");
225
- let u = c.store;
226
- return n && (u = u.index(o.shift())), (await Promise.all([
227
- u[r](...o),
228
- a && c.done
229
- ]))[0];
230
- };
231
- return ar.set(e, i), i;
232
- }
233
- Da((t) => ({
234
- ...t,
235
- get: (e, r, n) => Sn(e, r) || t.get(e, r, n),
236
- has: (e, r) => !!Sn(e, r) || t.has(e, r)
237
- }));
238
- const Qi = ["continue", "continuePrimaryKey", "advance"], wn = {}, Dr = /* @__PURE__ */ new WeakMap(), _a = /* @__PURE__ */ new WeakMap(), Ji = {
239
- get(t, e) {
240
- if (!Qi.includes(e))
241
- return t[e];
242
- let r = wn[e];
243
- return r || (r = wn[e] = function(...n) {
244
- Dr.set(this, _a.get(this)[e](...n));
245
- }), r;
246
- }
247
- };
248
- async function* es(...t) {
249
- let e = this;
250
- if (e instanceof IDBCursor || (e = await e.openCursor(...t)), !e)
251
- return;
252
- e = e;
253
- const r = new Proxy(e, Ji);
254
- for (_a.set(r, e), Kt.set(r, Ir(e)); e; )
255
- yield r, e = await (Dr.get(r) || e.continue()), Dr.delete(r);
256
- }
257
- function Fn(t, e) {
258
- return e === Symbol.asyncIterator && Or(t, [IDBIndex, IDBObjectStore, IDBCursor]) || e === "iterate" && Or(t, [IDBIndex, IDBObjectStore]);
259
- }
260
- Da((t) => ({
261
- ...t,
262
- get(e, r, n) {
263
- return Fn(e, r) ? es : t.get(e, r, n);
264
- },
265
- has(e, r) {
266
- return Fn(e, r) || t.has(e, r);
267
- }
268
- }));
269
- const Ze = {
270
- fonts: "fonts"
271
- }, ir = [
272
- {
273
- version: 1,
274
- stores: [
275
- {
276
- name: Ze.fonts,
277
- keyPath: "name"
278
- }
279
- ]
280
- },
281
- {
282
- version: 2,
283
- stores: [
284
- {
285
- name: Ze.fonts,
286
- keyPath: "name"
287
- }
288
- ]
289
- }
290
- ], pe = class pe {
291
- constructor() {
292
- this.isClosing = !1, typeof window < "u" && window.addEventListener("unload", () => {
293
- this.close();
294
- });
295
- }
296
- /**
297
- * Returns the singleton instance of the FontCacheManager
298
- */
299
- static get instance() {
300
- return pe._instance || (pe._instance = new pe()), pe._instance;
301
- }
302
- /**
303
- * Sets a font in the cache
304
- * @param fileName The font file name (key)
305
- * @param fontData The font data to store
306
- */
307
- async set(e, r) {
308
- await (await this.getDatabase()).put(Ze.fonts, { ...r, name: e });
309
- }
310
- /**
311
- * Gets a font from the cache
312
- * @param fileName The font file name (key)
313
- * @returns The font data if found, undefined otherwise
314
- */
315
- async get(e) {
316
- return await (await this.getDatabase()).get(Ze.fonts, e);
317
- }
318
- /**
319
- * Deletes a font from the cache
320
- * @param fileName The font file name (key)
321
- */
322
- async delete(e) {
323
- await (await this.getDatabase()).delete(Ze.fonts, e);
324
- }
325
- /**
326
- * Gets all fonts from the cache
327
- * @returns An array of all font data in the cache
328
- */
329
- async getAll() {
330
- return await (await this.getDatabase()).getAll(Ze.fonts);
331
- }
332
- /**
333
- * Clears all fonts from the cache
334
- */
335
- async clear() {
336
- await (await this.getDatabase()).clear(Ze.fonts);
337
- }
338
- /**
339
- * Checks if a font exists in the cache
340
- * @param fileName The font file name (key)
341
- */
342
- async has(e) {
343
- return await this.get(e) !== void 0;
344
- }
345
- /**
346
- * Closes the database connection and cleans up resources.
347
- * After calling this, any further operations will require reopening the database.
348
- */
349
- close() {
350
- if (!this.isClosing) {
351
- this.isClosing = !0;
352
- try {
353
- this.db && (this.db.close(), this.db = void 0);
354
- } finally {
355
- this.isClosing = !1;
356
- }
357
- }
358
- }
359
- /**
360
- * Destroys the database instance and deletes all data.
361
- * Use with caution as this operation cannot be undone.
362
- */
363
- async destroy() {
364
- this.close(), await indexedDB.deleteDatabase(pe.DATABASE_NAME), pe._instance = void 0;
365
- }
366
- // Private methods for database management
367
- async getDatabase() {
368
- if (this.isClosing)
369
- throw new Error("Cannot perform operation while database is closing");
370
- return this.db ? this.db : (this.db = await Zi(
371
- pe.DATABASE_NAME,
372
- pe.DATABASE_VERSION,
373
- {
374
- upgrade: (e, r, n) => this.handleUpgrade(e, r, n),
375
- blocked() {
376
- console.warn(
377
- "Database upgrade blocked - please close other tabs using the application"
378
- );
379
- },
380
- blocking() {
381
- console.warn("Database blocking newer version - closing connection"), pe.instance.close();
382
- }
383
- }
384
- ), this.db);
385
- }
386
- /**
387
- * Applies all schema versions that are greater than the old version and less than or equal to the new version
388
- * @param db The database instance
389
- * @param oldVersion The old version of the database
390
- * @param newVersion The new version of the database
391
- */
392
- handleUpgrade(e, r, n) {
393
- const a = ir.filter(
394
- (i) => i.version > r && (!n || i.version <= n)
395
- );
396
- for (const i of a)
397
- this.applySchemaVersion(e, i);
398
- }
399
- /**
400
- * Applies a single schema version's changes to the database
401
- * @param db The database instance
402
- * @param schema The schema version to apply
403
- */
404
- applySchemaVersion(e, r) {
405
- for (const n of r.stores)
406
- e.objectStoreNames.contains(n.name) || e.createObjectStore(n.name, { keyPath: n.keyPath });
407
- }
408
- };
409
- pe.DATABASE_NAME = "mlightcad", pe.DATABASE_VERSION = ir[ir.length - 1].version;
410
- let gt = pe;
411
- const Pa = (t) => t.split("/").pop(), kn = (t) => {
412
- const e = Pa(t);
413
- if (e) {
414
- const r = e.lastIndexOf(".");
415
- return r === -1 ? e : e.substring(0, r);
37
+ const Ra = (t) => t.split("/").pop(), bn = (t) => {
38
+ const e = Ra(t);
39
+ if (e) {
40
+ const r = e.lastIndexOf(".");
41
+ return r === -1 ? e : e.substring(0, r);
416
42
  }
417
43
  return t;
418
- }, ts = [
44
+ }, zi = [
419
45
  0,
420
46
  16711680,
421
47
  16776960,
@@ -673,7 +299,381 @@ const Pa = (t) => t.split("/").pop(), kn = (t) => {
673
299
  14079702,
674
300
  16777215,
675
301
  0
676
- ], rs = (t) => ts[t];
302
+ ], Wi = (t) => zi[t];
303
+ class qi {
304
+ constructor() {
305
+ this.cache = /* @__PURE__ */ new Map();
306
+ }
307
+ /**
308
+ * Returns true if the geometry of the specified character code exists in the cache.
309
+ * Otherwise, returns false.
310
+ * @param code One character code.
311
+ * @param size The font size.
312
+ * @returns True if the geometry of the specified character code exists in the cache.
313
+ * Otherwise, returns false.
314
+ */
315
+ hasGeometry(e, r) {
316
+ const n = this.generateKey(e, r);
317
+ return this.cache.has(n);
318
+ }
319
+ /**
320
+ * Get the geometry for a single character from cache if available.
321
+ * The cache key includes both character codeand size.
322
+ * @param code The character code to get geometry from cache.
323
+ * @param size The font size.
324
+ * @returns The geometry for a single character from cache if avaiable.
325
+ * Return undefined if the character not found in cache.
326
+ */
327
+ getGeometry(e, r) {
328
+ const n = this.generateKey(e, r);
329
+ if (this.cache.has(n))
330
+ return this.cache.get(n);
331
+ }
332
+ /**
333
+ * Set the geometry to cache for a single character.
334
+ * @param char The character to set geometry for.
335
+ * @param size The font size.
336
+ * @param geometry The geometry to set.
337
+ */
338
+ setGeometry(e, r, n) {
339
+ const a = this.generateKey(e, r);
340
+ this.cache.set(a, n);
341
+ }
342
+ /**
343
+ * Dispose all cached geometries.
344
+ */
345
+ dispose() {
346
+ for (const e of this.cache.values())
347
+ e.dispose();
348
+ this.cache.clear();
349
+ }
350
+ /**
351
+ * Generates cache key by character and font size.
352
+ * @param char One character code.
353
+ * @param size The font size.
354
+ */
355
+ generateKey(e, r) {
356
+ return `${e}_${r}`;
357
+ }
358
+ }
359
+ class Ia {
360
+ constructor(e) {
361
+ this.names = /* @__PURE__ */ new Set(), this.unsupportedChars = {}, this.encoding = e.encoding, e.alias.forEach((r) => this.names.add(r)), this.cache = new qi();
362
+ }
363
+ /**
364
+ * Records an unsupported character in the font.
365
+ * Increments the count for the given character in unsupportedChars.
366
+ * @param char - The unsupported character to record
367
+ */
368
+ addUnsupportedChar(e) {
369
+ this.unsupportedChars[e] || (this.unsupportedChars[e] = 0), this.unsupportedChars[e]++;
370
+ }
371
+ }
372
+ class Da extends _.Shape {
373
+ constructor() {
374
+ super(...arguments), this.width = 0;
375
+ }
376
+ }
377
+ const Or = (t, e) => e.some((r) => t instanceof r);
378
+ let xn, Sn;
379
+ function Vi() {
380
+ return xn || (xn = [
381
+ IDBDatabase,
382
+ IDBObjectStore,
383
+ IDBIndex,
384
+ IDBCursor,
385
+ IDBTransaction
386
+ ]);
387
+ }
388
+ function Xi() {
389
+ return Sn || (Sn = [
390
+ IDBCursor.prototype.advance,
391
+ IDBCursor.prototype.continue,
392
+ IDBCursor.prototype.continuePrimaryKey
393
+ ]);
394
+ }
395
+ const Mr = /* @__PURE__ */ new WeakMap(), nr = /* @__PURE__ */ new WeakMap(), Kt = /* @__PURE__ */ new WeakMap();
396
+ function Yi(t) {
397
+ const e = new Promise((r, n) => {
398
+ const a = () => {
399
+ t.removeEventListener("success", i), t.removeEventListener("error", s);
400
+ }, i = () => {
401
+ r(Qe(t.result)), a();
402
+ }, s = () => {
403
+ n(t.error), a();
404
+ };
405
+ t.addEventListener("success", i), t.addEventListener("error", s);
406
+ });
407
+ return Kt.set(e, t), e;
408
+ }
409
+ function ji(t) {
410
+ if (Mr.has(t))
411
+ return;
412
+ const e = new Promise((r, n) => {
413
+ const a = () => {
414
+ t.removeEventListener("complete", i), t.removeEventListener("error", s), t.removeEventListener("abort", s);
415
+ }, i = () => {
416
+ r(), a();
417
+ }, s = () => {
418
+ n(t.error || new DOMException("AbortError", "AbortError")), a();
419
+ };
420
+ t.addEventListener("complete", i), t.addEventListener("error", s), t.addEventListener("abort", s);
421
+ });
422
+ Mr.set(t, e);
423
+ }
424
+ let Rr = {
425
+ get(t, e, r) {
426
+ if (t instanceof IDBTransaction) {
427
+ if (e === "done")
428
+ return Mr.get(t);
429
+ if (e === "store")
430
+ return r.objectStoreNames[1] ? void 0 : r.objectStore(r.objectStoreNames[0]);
431
+ }
432
+ return Qe(t[e]);
433
+ },
434
+ set(t, e, r) {
435
+ return t[e] = r, !0;
436
+ },
437
+ has(t, e) {
438
+ return t instanceof IDBTransaction && (e === "done" || e === "store") ? !0 : e in t;
439
+ }
440
+ };
441
+ function _a(t) {
442
+ Rr = t(Rr);
443
+ }
444
+ function Zi(t) {
445
+ return Xi().includes(t) ? function(...e) {
446
+ return t.apply(Ir(this), e), Qe(this.request);
447
+ } : function(...e) {
448
+ return Qe(t.apply(Ir(this), e));
449
+ };
450
+ }
451
+ function $i(t) {
452
+ return typeof t == "function" ? Zi(t) : (t instanceof IDBTransaction && ji(t), Or(t, Vi()) ? new Proxy(t, Rr) : t);
453
+ }
454
+ function Qe(t) {
455
+ if (t instanceof IDBRequest)
456
+ return Yi(t);
457
+ if (nr.has(t))
458
+ return nr.get(t);
459
+ const e = $i(t);
460
+ return e !== t && (nr.set(t, e), Kt.set(e, t)), e;
461
+ }
462
+ const Ir = (t) => Kt.get(t);
463
+ function Ki(t, e, { blocked: r, upgrade: n, blocking: a, terminated: i } = {}) {
464
+ const s = indexedDB.open(t, e), o = Qe(s);
465
+ return n && s.addEventListener("upgradeneeded", (c) => {
466
+ n(Qe(s.result), c.oldVersion, c.newVersion, Qe(s.transaction), c);
467
+ }), r && s.addEventListener("blocked", (c) => r(
468
+ // Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
469
+ c.oldVersion,
470
+ c.newVersion,
471
+ c
472
+ )), o.then((c) => {
473
+ i && c.addEventListener("close", () => i()), a && c.addEventListener("versionchange", (u) => a(u.oldVersion, u.newVersion, u));
474
+ }).catch(() => {
475
+ }), o;
476
+ }
477
+ const Qi = ["get", "getKey", "getAll", "getAllKeys", "count"], Ji = ["put", "add", "delete", "clear"], ar = /* @__PURE__ */ new Map();
478
+ function wn(t, e) {
479
+ if (!(t instanceof IDBDatabase && !(e in t) && typeof e == "string"))
480
+ return;
481
+ if (ar.get(e))
482
+ return ar.get(e);
483
+ const r = e.replace(/FromIndex$/, ""), n = e !== r, a = Ji.includes(r);
484
+ if (
485
+ // Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
486
+ !(r in (n ? IDBIndex : IDBObjectStore).prototype) || !(a || Qi.includes(r))
487
+ )
488
+ return;
489
+ const i = async function(s, ...o) {
490
+ const c = this.transaction(s, a ? "readwrite" : "readonly");
491
+ let u = c.store;
492
+ return n && (u = u.index(o.shift())), (await Promise.all([
493
+ u[r](...o),
494
+ a && c.done
495
+ ]))[0];
496
+ };
497
+ return ar.set(e, i), i;
498
+ }
499
+ _a((t) => ({
500
+ ...t,
501
+ get: (e, r, n) => wn(e, r) || t.get(e, r, n),
502
+ has: (e, r) => !!wn(e, r) || t.has(e, r)
503
+ }));
504
+ const es = ["continue", "continuePrimaryKey", "advance"], Fn = {}, Dr = /* @__PURE__ */ new WeakMap(), Pa = /* @__PURE__ */ new WeakMap(), ts = {
505
+ get(t, e) {
506
+ if (!es.includes(e))
507
+ return t[e];
508
+ let r = Fn[e];
509
+ return r || (r = Fn[e] = function(...n) {
510
+ Dr.set(this, Pa.get(this)[e](...n));
511
+ }), r;
512
+ }
513
+ };
514
+ async function* rs(...t) {
515
+ let e = this;
516
+ if (e instanceof IDBCursor || (e = await e.openCursor(...t)), !e)
517
+ return;
518
+ e = e;
519
+ const r = new Proxy(e, ts);
520
+ for (Pa.set(r, e), Kt.set(r, Ir(e)); e; )
521
+ yield r, e = await (Dr.get(r) || e.continue()), Dr.delete(r);
522
+ }
523
+ function kn(t, e) {
524
+ return e === Symbol.asyncIterator && Or(t, [IDBIndex, IDBObjectStore, IDBCursor]) || e === "iterate" && Or(t, [IDBIndex, IDBObjectStore]);
525
+ }
526
+ _a((t) => ({
527
+ ...t,
528
+ get(e, r, n) {
529
+ return kn(e, r) ? rs : t.get(e, r, n);
530
+ },
531
+ has(e, r) {
532
+ return kn(e, r) || t.has(e, r);
533
+ }
534
+ }));
535
+ const Ze = {
536
+ fonts: "fonts"
537
+ }, ir = [
538
+ {
539
+ version: 1,
540
+ stores: [
541
+ {
542
+ name: Ze.fonts,
543
+ keyPath: "name"
544
+ }
545
+ ]
546
+ },
547
+ {
548
+ version: 2,
549
+ stores: [
550
+ {
551
+ name: Ze.fonts,
552
+ keyPath: "name"
553
+ }
554
+ ]
555
+ }
556
+ ], pe = class pe {
557
+ constructor() {
558
+ this.isClosing = !1, typeof window < "u" && window.addEventListener("unload", () => {
559
+ this.close();
560
+ });
561
+ }
562
+ /**
563
+ * Returns the singleton instance of the FontCacheManager
564
+ */
565
+ static get instance() {
566
+ return pe._instance || (pe._instance = new pe()), pe._instance;
567
+ }
568
+ /**
569
+ * Sets a font in the cache
570
+ * @param fileName The font file name (key)
571
+ * @param fontData The font data to store
572
+ */
573
+ async set(e, r) {
574
+ await (await this.getDatabase()).put(Ze.fonts, { ...r, name: e });
575
+ }
576
+ /**
577
+ * Gets a font from the cache
578
+ * @param fileName The font file name (key)
579
+ * @returns The font data if found, undefined otherwise
580
+ */
581
+ async get(e) {
582
+ return await (await this.getDatabase()).get(Ze.fonts, e);
583
+ }
584
+ /**
585
+ * Deletes a font from the cache
586
+ * @param fileName The font file name (key)
587
+ */
588
+ async delete(e) {
589
+ await (await this.getDatabase()).delete(Ze.fonts, e);
590
+ }
591
+ /**
592
+ * Gets all fonts from the cache
593
+ * @returns An array of all font data in the cache
594
+ */
595
+ async getAll() {
596
+ return await (await this.getDatabase()).getAll(Ze.fonts);
597
+ }
598
+ /**
599
+ * Clears all fonts from the cache
600
+ */
601
+ async clear() {
602
+ await (await this.getDatabase()).clear(Ze.fonts);
603
+ }
604
+ /**
605
+ * Checks if a font exists in the cache
606
+ * @param fileName The font file name (key)
607
+ */
608
+ async has(e) {
609
+ return await this.get(e) !== void 0;
610
+ }
611
+ /**
612
+ * Closes the database connection and cleans up resources.
613
+ * After calling this, any further operations will require reopening the database.
614
+ */
615
+ close() {
616
+ if (!this.isClosing) {
617
+ this.isClosing = !0;
618
+ try {
619
+ this.db && (this.db.close(), this.db = void 0);
620
+ } finally {
621
+ this.isClosing = !1;
622
+ }
623
+ }
624
+ }
625
+ /**
626
+ * Destroys the database instance and deletes all data.
627
+ * Use with caution as this operation cannot be undone.
628
+ */
629
+ async destroy() {
630
+ this.close(), await indexedDB.deleteDatabase(pe.DATABASE_NAME), pe._instance = void 0;
631
+ }
632
+ // Private methods for database management
633
+ async getDatabase() {
634
+ if (this.isClosing)
635
+ throw new Error("Cannot perform operation while database is closing");
636
+ return this.db ? this.db : (this.db = await Ki(
637
+ pe.DATABASE_NAME,
638
+ pe.DATABASE_VERSION,
639
+ {
640
+ upgrade: (e, r, n) => this.handleUpgrade(e, r, n),
641
+ blocked() {
642
+ console.warn(
643
+ "Database upgrade blocked - please close other tabs using the application"
644
+ );
645
+ },
646
+ blocking() {
647
+ console.warn("Database blocking newer version - closing connection"), pe.instance.close();
648
+ }
649
+ }
650
+ ), this.db);
651
+ }
652
+ /**
653
+ * Applies all schema versions that are greater than the old version and less than or equal to the new version
654
+ * @param db The database instance
655
+ * @param oldVersion The old version of the database
656
+ * @param newVersion The new version of the database
657
+ */
658
+ handleUpgrade(e, r, n) {
659
+ const a = ir.filter(
660
+ (i) => i.version > r && (!n || i.version <= n)
661
+ );
662
+ for (const i of a)
663
+ this.applySchemaVersion(e, i);
664
+ }
665
+ /**
666
+ * Applies a single schema version's changes to the database
667
+ * @param db The database instance
668
+ * @param schema The schema version to apply
669
+ */
670
+ applySchemaVersion(e, r) {
671
+ for (const n of r.stores)
672
+ e.objectStoreNames.contains(n.name) || e.createObjectStore(n.name, { keyPath: n.keyPath });
673
+ }
674
+ };
675
+ pe.DATABASE_NAME = "mlightcad", pe.DATABASE_VERSION = ir[ir.length - 1].version;
676
+ let gt = pe;
677
677
  /*! https://mths.be/codepointat v0.2.0 by @mathias */
678
678
  String.prototype.codePointAt || function() {
679
679
  var t = function() {
@@ -9448,7 +9448,7 @@ function xh(t, e = 1e-4) {
9448
9448
  return m.setIndex(h), m;
9449
9449
  }
9450
9450
  new _.Vector2();
9451
- class fa extends Ia {
9451
+ class fa extends Da {
9452
9452
  constructor(e, r, n) {
9453
9453
  super(), this.isFound = !1, this.char = e, this.fontSize = r, this.font = n, this.width = this.getCharWidth(e, r, n);
9454
9454
  }
@@ -9758,7 +9758,7 @@ class Mh {
9758
9758
  this.map.clear();
9759
9759
  }
9760
9760
  }
9761
- class Rh extends Ra {
9761
+ class Rh extends Ia {
9762
9762
  /**
9763
9763
  * Creates a new instance of MeshFont.
9764
9764
  * @param fontData - Either a MeshFontData object containing font information or an ArrayBuffer containing raw font data
@@ -22097,7 +22097,7 @@ const wl = {}, Fl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineP
22097
22097
  })(Li);
22098
22098
  var Tl = Li.exports;
22099
22099
  const El = /* @__PURE__ */ qh(Tl);
22100
- class un extends Ia {
22100
+ class un extends Da {
22101
22101
  /**
22102
22102
  * Creates a new instance of ShxTextShape
22103
22103
  * @param code - The character code this shape represents
@@ -22144,7 +22144,7 @@ class un extends Ia {
22144
22144
  return e;
22145
22145
  }
22146
22146
  }
22147
- class Cl extends Ra {
22147
+ class Cl extends Ia {
22148
22148
  constructor(e) {
22149
22149
  super(e), this.type = "shx", this.font = new Wh(e.data), this.data = this.font.fontData;
22150
22150
  }
@@ -22343,7 +22343,7 @@ class Oe {
22343
22343
  const n = [];
22344
22344
  return await Promise.allSettled(r).then((a) => {
22345
22345
  a.forEach((i, s) => {
22346
- const o = i.status === "fulfilled", c = e[s].url, u = kn(c.toLowerCase());
22346
+ const o = i.status === "fulfilled", c = e[s].url, u = bn(c.toLowerCase());
22347
22347
  n.push({
22348
22348
  fontName: u,
22349
22349
  url: c,
@@ -22459,7 +22459,7 @@ class Oe {
22459
22459
  * @param fontInfo - The matadata of the font to be loaded
22460
22460
  */
22461
22461
  async loadFont(e) {
22462
- if (!Pa(e.file))
22462
+ if (!Ra(e.file))
22463
22463
  throw new Error(`Invalid font file name: ${e.file}`);
22464
22464
  const n = this.fontInfoToFontData(e), a = n.name;
22465
22465
  if (this.isFontLoaded(n.name))
@@ -22479,7 +22479,7 @@ class Oe {
22479
22479
  });
22480
22480
  }
22481
22481
  fontInfoToFontData(e) {
22482
- const r = kn(e.file).toLowerCase(), n = ["ttf", "otf", "woff"].includes(e.type) ? "mesh" : e.type;
22482
+ const r = bn(e.file).toLowerCase(), n = ["ttf", "otf", "woff"].includes(e.type) ? "mesh" : e.type;
22483
22483
  return {
22484
22484
  name: r,
22485
22485
  alias: e.name,
@@ -23708,7 +23708,7 @@ class ln extends Ut {
23708
23708
  * @returns The color as a hex number (0xRRGGBB)
23709
23709
  */
23710
23710
  getColorAsHex() {
23711
- return this.color.isRgb && this.color.rgbValue !== null ? this.color.rgbValue : this.color.isAci && this.color.aci !== null ? rs(this.color.aci) : 16777215;
23711
+ return this.color.isRgb && this.color.rgbValue !== null ? this.color.rgbValue : this.color.isAci && this.color.aci !== null ? Wi(this.color.aci) : 16777215;
23712
23712
  }
23713
23713
  /**
23714
23714
  * Set the color using a hex value for rendering purposes.
@@ -25134,8 +25134,8 @@ class ql {
25134
25134
  }
25135
25135
  }
25136
25136
  export {
25137
- Ra as BaseFont,
25138
- Ia as BaseTextShape,
25137
+ Ia as BaseFont,
25138
+ Da as BaseTextShape,
25139
25139
  Ul as DefaultFontLoader,
25140
25140
  mn as EventManager,
25141
25141
  ze as FontFactory,
@@ -25145,5 +25145,6 @@ export {
25145
25145
  ot as MTextFlowDirection,
25146
25146
  Nl as MainThreadRenderer,
25147
25147
  ql as UnifiedRenderer,
25148
- Pl as WebWorkerRenderer
25148
+ Pl as WebWorkerRenderer,
25149
+ Wi as getColorByIndex
25149
25150
  };