@mlightcad/data-model 1.9.9 → 1.9.11

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 (79) hide show
  1. package/dist/data-model.cjs +7 -7
  2. package/lib/base/AcDbObject.d.ts +54 -0
  3. package/lib/base/AcDbObject.d.ts.map +1 -1
  4. package/lib/base/AcDbObject.js +200 -21
  5. package/lib/base/AcDbObject.js.map +1 -1
  6. package/lib/database/AcDbBlockTableRecord.d.ts.map +1 -1
  7. package/lib/database/AcDbBlockTableRecord.js +61 -15
  8. package/lib/database/AcDbBlockTableRecord.js.map +1 -1
  9. package/lib/database/AcDbDatabase.d.ts +111 -4
  10. package/lib/database/AcDbDatabase.d.ts.map +1 -1
  11. package/lib/database/AcDbDatabase.js +406 -62
  12. package/lib/database/AcDbDatabase.js.map +1 -1
  13. package/lib/database/AcDbSymbolTable.d.ts +9 -0
  14. package/lib/database/AcDbSymbolTable.d.ts.map +1 -1
  15. package/lib/database/AcDbSymbolTable.js +34 -4
  16. package/lib/database/AcDbSymbolTable.js.map +1 -1
  17. package/lib/database/AcDbSysVarManager.d.ts +15 -0
  18. package/lib/database/AcDbSysVarManager.d.ts.map +1 -1
  19. package/lib/database/AcDbSysVarManager.js +60 -11
  20. package/lib/database/AcDbSysVarManager.js.map +1 -1
  21. package/lib/database/AcDbSystemVariables.d.ts +8 -1
  22. package/lib/database/AcDbSystemVariables.d.ts.map +1 -1
  23. package/lib/database/AcDbSystemVariables.js +7 -0
  24. package/lib/database/AcDbSystemVariables.js.map +1 -1
  25. package/lib/database/index.d.ts +2 -0
  26. package/lib/database/index.d.ts.map +1 -1
  27. package/lib/database/index.js +1 -0
  28. package/lib/database/index.js.map +1 -1
  29. package/lib/database/transaction/AcDbChangeApplier.d.ts +118 -0
  30. package/lib/database/transaction/AcDbChangeApplier.d.ts.map +1 -0
  31. package/lib/database/transaction/AcDbChangeApplier.js +310 -0
  32. package/lib/database/transaction/AcDbChangeApplier.js.map +1 -0
  33. package/lib/database/transaction/AcDbChangeRecorder.d.ts +113 -0
  34. package/lib/database/transaction/AcDbChangeRecorder.d.ts.map +1 -0
  35. package/lib/database/transaction/AcDbChangeRecorder.js +235 -0
  36. package/lib/database/transaction/AcDbChangeRecorder.js.map +1 -0
  37. package/lib/database/transaction/AcDbDatabaseChange.d.ts +67 -0
  38. package/lib/database/transaction/AcDbDatabaseChange.d.ts.map +1 -0
  39. package/lib/database/transaction/AcDbDatabaseChange.js +23 -0
  40. package/lib/database/transaction/AcDbDatabaseChange.js.map +1 -0
  41. package/lib/database/transaction/AcDbDatabaseTransaction.d.ts +26 -0
  42. package/lib/database/transaction/AcDbDatabaseTransaction.d.ts.map +1 -0
  43. package/lib/database/transaction/AcDbDatabaseTransaction.js +51 -0
  44. package/lib/database/transaction/AcDbDatabaseTransaction.js.map +1 -0
  45. package/lib/database/transaction/AcDbDatabaseTransactionManager.d.ts +188 -0
  46. package/lib/database/transaction/AcDbDatabaseTransactionManager.d.ts.map +1 -0
  47. package/lib/database/transaction/AcDbDatabaseTransactionManager.js +594 -0
  48. package/lib/database/transaction/AcDbDatabaseTransactionManager.js.map +1 -0
  49. package/lib/database/transaction/AcDbTransaction.d.ts +7 -0
  50. package/lib/database/transaction/AcDbTransaction.d.ts.map +1 -1
  51. package/lib/database/transaction/AcDbTransaction.js +20 -10
  52. package/lib/database/transaction/AcDbTransaction.js.map +1 -1
  53. package/lib/database/transaction/AcDbTransactionManager.d.ts +3 -4
  54. package/lib/database/transaction/AcDbTransactionManager.d.ts.map +1 -1
  55. package/lib/database/transaction/AcDbTransactionManager.js +3 -4
  56. package/lib/database/transaction/AcDbTransactionManager.js.map +1 -1
  57. package/lib/database/transaction/AcDbUndoRecord.d.ts +11 -0
  58. package/lib/database/transaction/AcDbUndoRecord.d.ts.map +1 -0
  59. package/lib/database/transaction/AcDbUndoRecord.js +2 -0
  60. package/lib/database/transaction/AcDbUndoRecord.js.map +1 -0
  61. package/lib/database/transaction/AcDbUndoStack.d.ts +52 -0
  62. package/lib/database/transaction/AcDbUndoStack.d.ts.map +1 -0
  63. package/lib/database/transaction/AcDbUndoStack.js +74 -0
  64. package/lib/database/transaction/AcDbUndoStack.js.map +1 -0
  65. package/lib/database/transaction/index.d.ts +9 -0
  66. package/lib/database/transaction/index.d.ts.map +1 -1
  67. package/lib/database/transaction/index.js +6 -0
  68. package/lib/database/transaction/index.js.map +1 -1
  69. package/lib/entity/AcDbEntity.js +4 -4
  70. package/lib/entity/AcDbEntity.js.map +1 -1
  71. package/lib/index.d.ts +2 -2
  72. package/lib/index.d.ts.map +1 -1
  73. package/lib/index.js +1 -1
  74. package/lib/index.js.map +1 -1
  75. package/lib/object/AcDbDictionary.d.ts +11 -0
  76. package/lib/object/AcDbDictionary.d.ts.map +1 -1
  77. package/lib/object/AcDbDictionary.js +65 -20
  78. package/lib/object/AcDbDictionary.js.map +1 -1
  79. package/package.json +4 -4
@@ -122,6 +122,7 @@ import { AcDbSysVarManager } from './AcDbSysVarManager';
122
122
  import { AcDbSystemVariables } from './AcDbSystemVariables';
123
123
  import { AcDbLayout } from '../object/layout/AcDbLayout';
124
124
  import { AcDbLayoutDictionary } from '../object/layout/AcDbLayoutDictionary';
125
+ import { AcDbDatabaseTransactionManager } from './transaction/AcDbDatabaseTransactionManager';
125
126
  /**
126
127
  * The AcDbDatabase class represents an AutoCAD drawing file.
127
128
  *
@@ -150,6 +151,12 @@ var AcDbDatabase = /** @class */ (function (_super) {
150
151
  * Set from {@link AcDbOpenDatabaseOptions.drawNoPlotLayers} when opening a database.
151
152
  */
152
153
  _this._drawNoPlotLayers = true;
154
+ _this._eventBatchDepth = 0;
155
+ _this._pendingEntityModified = new Set();
156
+ _this._pendingEntityAppended = [];
157
+ _this._pendingEntityErased = [];
158
+ _this._pendingDictObjectSet = [];
159
+ _this._pendingDictObjectErased = [];
153
160
  /**
154
161
  * Events that can be triggered by the database.
155
162
  *
@@ -176,6 +183,8 @@ var AcDbDatabase = /** @class */ (function (_super) {
176
183
  /** Fired during database opening operations to report progress */
177
184
  openProgress: new AcCmEventManager()
178
185
  };
186
+ AcDbDatabase._unsavedDrawingSequence += 1;
187
+ _this._dwgname = "Drawing".concat(AcDbDatabase._unsavedDrawingSequence, ".dwg");
179
188
  _this._version = new AcDbDwgVersion('AC1014');
180
189
  _this._angbase = 0;
181
190
  _this._angdir = 0;
@@ -227,6 +236,7 @@ var AcDbDatabase = /** @class */ (function (_super) {
227
236
  mlineStyle: new AcDbDictionary(_this),
228
237
  xrecord: new AcDbDictionary(_this)
229
238
  };
239
+ _this.transactionManager = new AcDbDatabaseTransactionManager(_this);
230
240
  return _this;
231
241
  }
232
242
  Object.defineProperty(AcDbDatabase.prototype, "tables", {
@@ -266,6 +276,322 @@ var AcDbDatabase = /** @class */ (function (_super) {
266
276
  enumerable: false,
267
277
  configurable: true
268
278
  });
279
+ /**
280
+ * Looks up a database-resident object by its object ID.
281
+ *
282
+ * Search order: entities, symbol table records, dictionary objects
283
+ * (including nested dictionaries), then the database object itself.
284
+ *
285
+ * @param id - Object identifier to resolve
286
+ * @param _openErased - Reserved for erased-object support
287
+ * @returns The matching object, or undefined if not found
288
+ */
289
+ AcDbDatabase.prototype.getObjectById = function (id, _openErased) {
290
+ var e_1, _a, e_2, _b;
291
+ if (_openErased === void 0) { _openErased = false; }
292
+ if (id === this.objectId) {
293
+ return this;
294
+ }
295
+ var entity = this.tables.blockTable.getEntityById(id);
296
+ if (entity) {
297
+ return entity;
298
+ }
299
+ var symbolTables = [
300
+ this.tables.appIdTable,
301
+ this.tables.blockTable,
302
+ this.tables.dimStyleTable,
303
+ this.tables.linetypeTable,
304
+ this.tables.textStyleTable,
305
+ this.tables.viewTable,
306
+ this.tables.layerTable,
307
+ this.tables.viewportTable
308
+ ];
309
+ try {
310
+ for (var symbolTables_1 = __values(symbolTables), symbolTables_1_1 = symbolTables_1.next(); !symbolTables_1_1.done; symbolTables_1_1 = symbolTables_1.next()) {
311
+ var table = symbolTables_1_1.value;
312
+ var record = table.getIdAt(id);
313
+ if (record) {
314
+ return record;
315
+ }
316
+ }
317
+ }
318
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
319
+ finally {
320
+ try {
321
+ if (symbolTables_1_1 && !symbolTables_1_1.done && (_a = symbolTables_1.return)) _a.call(symbolTables_1);
322
+ }
323
+ finally { if (e_1) throw e_1.error; }
324
+ }
325
+ try {
326
+ for (var _c = __values(this.getRootDictionaries()), _d = _c.next(); !_d.done; _d = _c.next()) {
327
+ var dictionary = _d.value;
328
+ if (dictionary.objectId === id) {
329
+ return dictionary;
330
+ }
331
+ var object = this.findObjectInDictionary(dictionary, id);
332
+ if (object) {
333
+ return object;
334
+ }
335
+ }
336
+ }
337
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
338
+ finally {
339
+ try {
340
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
341
+ }
342
+ finally { if (e_2) throw e_2.error; }
343
+ }
344
+ return undefined;
345
+ };
346
+ /**
347
+ * Returns the top-level named object dictionaries owned by this database.
348
+ */
349
+ AcDbDatabase.prototype.getRootDictionaries = function () {
350
+ return [
351
+ this.objects.dictionary,
352
+ this.objects.imageDefinition,
353
+ this.objects.layout,
354
+ this.objects.mleaderStyle,
355
+ this.objects.mlineStyle,
356
+ this.objects.xrecord
357
+ ];
358
+ };
359
+ /**
360
+ * Recursively searches a dictionary tree for an object with the given ID.
361
+ *
362
+ * @param dictionary - Root dictionary to search (including nested dictionaries)
363
+ * @param id - Object identifier to resolve
364
+ * @returns Matching object, or undefined when not found under `dictionary`
365
+ */
366
+ AcDbDatabase.prototype.findObjectInDictionary = function (dictionary, id) {
367
+ var e_3, _a;
368
+ if (dictionary.objectId === id) {
369
+ return dictionary;
370
+ }
371
+ var direct = dictionary.getIdAt(id);
372
+ if (direct) {
373
+ return direct;
374
+ }
375
+ try {
376
+ for (var _b = __values(dictionary.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
377
+ var _d = __read(_c.value, 2), entry = _d[1];
378
+ if (entry.objectId === id) {
379
+ return entry;
380
+ }
381
+ if (entry instanceof AcDbDictionary) {
382
+ var nested = this.findObjectInDictionary(entry, id);
383
+ if (nested) {
384
+ return nested;
385
+ }
386
+ }
387
+ }
388
+ }
389
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
390
+ finally {
391
+ try {
392
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
393
+ }
394
+ finally { if (e_3) throw e_3.error; }
395
+ }
396
+ return undefined;
397
+ };
398
+ /**
399
+ * Begins suppressing database events until {@link endEventBatch} is called.
400
+ */
401
+ AcDbDatabase.prototype.beginEventBatch = function () {
402
+ this._eventBatchDepth++;
403
+ };
404
+ /**
405
+ * Ends event batching and dispatches accumulated entity events when the outermost batch closes.
406
+ */
407
+ AcDbDatabase.prototype.endEventBatch = function () {
408
+ if (this._eventBatchDepth <= 0) {
409
+ return;
410
+ }
411
+ this._eventBatchDepth--;
412
+ if (this._eventBatchDepth === 0) {
413
+ this.flushEventBatch();
414
+ }
415
+ };
416
+ /**
417
+ * Returns true when database events are being batched.
418
+ */
419
+ AcDbDatabase.prototype.isEventBatched = function () {
420
+ return this._eventBatchDepth > 0;
421
+ };
422
+ /**
423
+ * Dispatches or queues an entity-modified notification.
424
+ *
425
+ * When {@link isEventBatched} is true, the entity is deduplicated in a pending set
426
+ * and dispatched from {@link flushEventBatch} when the outermost batch closes.
427
+ *
428
+ * @param entity - Entity whose properties changed
429
+ */
430
+ AcDbDatabase.prototype.notifyEntityModified = function (entity) {
431
+ if (this.isEventBatched()) {
432
+ this._pendingEntityModified.add(entity);
433
+ return;
434
+ }
435
+ this.events.entityModified.dispatch({
436
+ database: this,
437
+ entity: entity
438
+ });
439
+ };
440
+ /**
441
+ * Dispatches or queues an entity-appended notification.
442
+ *
443
+ * @param entity - One entity or batch of entities added to model/paper space
444
+ */
445
+ AcDbDatabase.prototype.notifyEntityAppended = function (entity) {
446
+ var _a;
447
+ if (this.isEventBatched()) {
448
+ var items = Array.isArray(entity) ? entity : [entity];
449
+ (_a = this._pendingEntityAppended).push.apply(_a, __spreadArray([], __read(items), false));
450
+ return;
451
+ }
452
+ this.events.entityAppended.dispatch({
453
+ database: this,
454
+ entity: entity
455
+ });
456
+ };
457
+ /**
458
+ * Dispatches or queues an entity-erased notification.
459
+ *
460
+ * @param entity - One entity or batch of entities removed from model/paper space
461
+ */
462
+ AcDbDatabase.prototype.notifyEntityErased = function (entity) {
463
+ var _a;
464
+ if (this.isEventBatched()) {
465
+ var items = Array.isArray(entity) ? entity : [entity];
466
+ (_a = this._pendingEntityErased).push.apply(_a, __spreadArray([], __read(items), false));
467
+ return;
468
+ }
469
+ this.events.entityErased.dispatch({
470
+ database: this,
471
+ entity: entity
472
+ });
473
+ };
474
+ /**
475
+ * Dispatches or queues a dictionary-object-set notification.
476
+ *
477
+ * @param object - Object inserted or replaced in a named dictionary
478
+ * @param key - Dictionary key under which the object is stored
479
+ */
480
+ AcDbDatabase.prototype.notifyDictObjectSet = function (object, key) {
481
+ if (this.isEventBatched()) {
482
+ this._pendingDictObjectSet.push({ object: object, key: key });
483
+ return;
484
+ }
485
+ this.events.dictObjetSet.dispatch({
486
+ database: this,
487
+ object: object,
488
+ key: key
489
+ });
490
+ };
491
+ /**
492
+ * Dispatches or queues a dictionary-object-erased notification.
493
+ *
494
+ * @param object - Object removed from a named dictionary
495
+ * @param key - Dictionary key that previously referenced the object
496
+ */
497
+ AcDbDatabase.prototype.notifyDictObjectErased = function (object, key) {
498
+ if (this.isEventBatched()) {
499
+ this._pendingDictObjectErased.push({ object: object, key: key });
500
+ return;
501
+ }
502
+ this.events.dictObjectErased.dispatch({
503
+ database: this,
504
+ object: object,
505
+ key: key
506
+ });
507
+ };
508
+ /**
509
+ * Dispatches all notifications accumulated while event batching was active.
510
+ *
511
+ * Entity-modified events are deduplicated by entity; appended and erased
512
+ * entities are dispatched in batch arrays where applicable.
513
+ */
514
+ AcDbDatabase.prototype.flushEventBatch = function () {
515
+ var e_4, _a, e_5, _b, e_6, _c;
516
+ if (this._pendingEntityModified.size > 0) {
517
+ var modified = __spreadArray([], __read(this._pendingEntityModified), false);
518
+ this._pendingEntityModified.clear();
519
+ try {
520
+ for (var modified_1 = __values(modified), modified_1_1 = modified_1.next(); !modified_1_1.done; modified_1_1 = modified_1.next()) {
521
+ var entity = modified_1_1.value;
522
+ this.events.entityModified.dispatch({
523
+ database: this,
524
+ entity: entity
525
+ });
526
+ }
527
+ }
528
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
529
+ finally {
530
+ try {
531
+ if (modified_1_1 && !modified_1_1.done && (_a = modified_1.return)) _a.call(modified_1);
532
+ }
533
+ finally { if (e_4) throw e_4.error; }
534
+ }
535
+ }
536
+ if (this._pendingEntityAppended.length > 0) {
537
+ var appended = this._pendingEntityAppended;
538
+ this._pendingEntityAppended = [];
539
+ this.events.entityAppended.dispatch({
540
+ database: this,
541
+ entity: appended
542
+ });
543
+ }
544
+ if (this._pendingEntityErased.length > 0) {
545
+ var erased = this._pendingEntityErased;
546
+ this._pendingEntityErased = [];
547
+ this.events.entityErased.dispatch({
548
+ database: this,
549
+ entity: erased
550
+ });
551
+ }
552
+ if (this._pendingDictObjectSet.length > 0) {
553
+ var dictSet = this._pendingDictObjectSet;
554
+ this._pendingDictObjectSet = [];
555
+ try {
556
+ for (var dictSet_1 = __values(dictSet), dictSet_1_1 = dictSet_1.next(); !dictSet_1_1.done; dictSet_1_1 = dictSet_1.next()) {
557
+ var _d = dictSet_1_1.value, object = _d.object, key = _d.key;
558
+ this.events.dictObjetSet.dispatch({
559
+ database: this,
560
+ object: object,
561
+ key: key
562
+ });
563
+ }
564
+ }
565
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
566
+ finally {
567
+ try {
568
+ if (dictSet_1_1 && !dictSet_1_1.done && (_b = dictSet_1.return)) _b.call(dictSet_1);
569
+ }
570
+ finally { if (e_5) throw e_5.error; }
571
+ }
572
+ }
573
+ if (this._pendingDictObjectErased.length > 0) {
574
+ var dictErased = this._pendingDictObjectErased;
575
+ this._pendingDictObjectErased = [];
576
+ try {
577
+ for (var dictErased_1 = __values(dictErased), dictErased_1_1 = dictErased_1.next(); !dictErased_1_1.done; dictErased_1_1 = dictErased_1.next()) {
578
+ var _e = dictErased_1_1.value, object = _e.object, key = _e.key;
579
+ this.events.dictObjectErased.dispatch({
580
+ database: this,
581
+ object: object,
582
+ key: key
583
+ });
584
+ }
585
+ }
586
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
587
+ finally {
588
+ try {
589
+ if (dictErased_1_1 && !dictErased_1_1.done && (_c = dictErased_1.return)) _c.call(dictErased_1);
590
+ }
591
+ finally { if (e_6) throw e_6.error; }
592
+ }
593
+ }
594
+ };
269
595
  Object.defineProperty(AcDbDatabase.prototype, "formatter", {
270
596
  /**
271
597
  * Formatter for linear distances, point coordinates, and angles using this database's
@@ -697,6 +1023,36 @@ var AcDbDatabase = /** @class */ (function (_super) {
697
1023
  enumerable: false,
698
1024
  configurable: true
699
1025
  });
1026
+ Object.defineProperty(AcDbDatabase.prototype, "dwgname", {
1027
+ /**
1028
+ * Name of the current drawing file (**DWGNAME**), including extension.
1029
+ *
1030
+ * Read-only through the system-variable API; updated when a drawing is opened
1031
+ * or via {@link setDwgName} after save.
1032
+ *
1033
+ * @see https://help.autodesk.com/view/ACD/2023/ENU/?caas=caas/documentation/ACD/2014/ENU/files/GUID-A89861EF-5F4F-46C6-A1DB-9D985A3858C9-htm.html
1034
+ */
1035
+ get: function () {
1036
+ return this._dwgname;
1037
+ },
1038
+ enumerable: false,
1039
+ configurable: true
1040
+ });
1041
+ /**
1042
+ * Updates **DWGNAME** after opening or saving a drawing.
1043
+ *
1044
+ * @param value - Drawing file name, including extension.
1045
+ */
1046
+ AcDbDatabase.prototype.setDwgName = function (value) {
1047
+ var _this = this;
1048
+ var normalized = value.trim();
1049
+ if (!normalized) {
1050
+ return;
1051
+ }
1052
+ this.updateSysVar(AcDbSystemVariables.DWGNAME, this._dwgname, normalized, function (nextValue) {
1053
+ _this._dwgname = nextValue;
1054
+ });
1055
+ };
700
1056
  /**
701
1057
  * Returns whether entities on the given layer should be drawn under the
702
1058
  * current {@link drawNoPlotLayers} setting.
@@ -1145,6 +1501,9 @@ var AcDbDatabase = /** @class */ (function (_super) {
1145
1501
  throw new Error("Database converter for file type '".concat(fileType, "' isn't registered and can can't read this file!"));
1146
1502
  this.clear();
1147
1503
  this._drawNoPlotLayers = (_a = options === null || options === void 0 ? void 0 : options.drawNoPlotLayers) !== null && _a !== void 0 ? _a : true;
1504
+ if (options === null || options === void 0 ? void 0 : options.fileName) {
1505
+ this.setDwgName(options.fileName);
1506
+ }
1148
1507
  return [4 /*yield*/, converter.read(data, this, (options && options.minimumChunkSize) || 10, function (percentage, stage, stageStatus, data) { return __awaiter(_this, void 0, void 0, function () {
1149
1508
  var fonts_1;
1150
1509
  return __generator(this, function (_a) {
@@ -1192,7 +1551,7 @@ var AcDbDatabase = /** @class */ (function (_super) {
1192
1551
  AcDbDatabase.prototype.openUri = function (url, options) {
1193
1552
  return __awaiter(this, void 0, void 0, function () {
1194
1553
  var response, contentLength, totalBytes, loadedBytes, reader, chunks, _a, done, value, percentage, content, position, chunks_1, chunks_1_1, chunk, fileName, fileExtension;
1195
- var e_1, _b;
1554
+ var e_7, _b;
1196
1555
  var _c;
1197
1556
  return __generator(this, function (_d) {
1198
1557
  switch (_d.label) {
@@ -1255,14 +1614,17 @@ var AcDbDatabase = /** @class */ (function (_super) {
1255
1614
  position += chunk.length;
1256
1615
  }
1257
1616
  }
1258
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1617
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
1259
1618
  finally {
1260
1619
  try {
1261
1620
  if (chunks_1_1 && !chunks_1_1.done && (_b = chunks_1.return)) _b.call(chunks_1);
1262
1621
  }
1263
- finally { if (e_1) throw e_1.error; }
1622
+ finally { if (e_7) throw e_7.error; }
1264
1623
  }
1265
1624
  fileName = this.getFileNameFromUri(url);
1625
+ if (fileName) {
1626
+ this.setDwgName(fileName);
1627
+ }
1266
1628
  fileExtension = fileName.toLowerCase().split('.').pop();
1267
1629
  if (!(fileExtension === 'dwg')) return [3 /*break*/, 6];
1268
1630
  // DWG files are binary, convert to ArrayBuffer
@@ -1442,7 +1804,7 @@ var AcDbDatabase = /** @class */ (function (_super) {
1442
1804
  }));
1443
1805
  };
1444
1806
  AcDbDatabase.prototype.hasDefaultTextStyle = function () {
1445
- var e_2, _a, e_3, _b;
1807
+ var e_8, _a, e_9, _b;
1446
1808
  var defaultNames = [DEFAULT_TEXT_STYLE, 'STANDARD'];
1447
1809
  try {
1448
1810
  for (var defaultNames_1 = __values(defaultNames), defaultNames_1_1 = defaultNames_1.next(); !defaultNames_1_1.done; defaultNames_1_1 = defaultNames_1.next()) {
@@ -1452,12 +1814,12 @@ var AcDbDatabase = /** @class */ (function (_super) {
1452
1814
  }
1453
1815
  }
1454
1816
  }
1455
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1817
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
1456
1818
  finally {
1457
1819
  try {
1458
1820
  if (defaultNames_1_1 && !defaultNames_1_1.done && (_a = defaultNames_1.return)) _a.call(defaultNames_1);
1459
1821
  }
1460
- finally { if (e_2) throw e_2.error; }
1822
+ finally { if (e_8) throw e_8.error; }
1461
1823
  }
1462
1824
  try {
1463
1825
  for (var _c = __values(this.tables.textStyleTable.newIterator()), _d = _c.next(); !_d.done; _d = _c.next()) {
@@ -1467,12 +1829,12 @@ var AcDbDatabase = /** @class */ (function (_super) {
1467
1829
  }
1468
1830
  }
1469
1831
  }
1470
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1832
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
1471
1833
  finally {
1472
1834
  try {
1473
1835
  if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1474
1836
  }
1475
- finally { if (e_3) throw e_3.error; }
1837
+ finally { if (e_9) throw e_9.error; }
1476
1838
  }
1477
1839
  return false;
1478
1840
  };
@@ -1559,7 +1921,7 @@ var AcDbDatabase = /** @class */ (function (_super) {
1559
1921
  * Ensures one MLINE style exists for the provided style name.
1560
1922
  */
1561
1923
  AcDbDatabase.prototype.ensureMLineStyle = function (styleName) {
1562
- var e_4, _a;
1924
+ var e_10, _a;
1563
1925
  var dictionary = this.objects.mlineStyle;
1564
1926
  var normalizedName = styleName.trim();
1565
1927
  if (!normalizedName)
@@ -1576,12 +1938,12 @@ var AcDbDatabase = /** @class */ (function (_super) {
1576
1938
  }
1577
1939
  }
1578
1940
  }
1579
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1941
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
1580
1942
  finally {
1581
1943
  try {
1582
1944
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1583
1945
  }
1584
- finally { if (e_4) throw e_4.error; }
1946
+ finally { if (e_10) throw e_10.error; }
1585
1947
  }
1586
1948
  var style = new AcDbMlineStyle();
1587
1949
  style.styleName = normalizedName;
@@ -1603,7 +1965,7 @@ var AcDbDatabase = /** @class */ (function (_super) {
1603
1965
  * Ensures one MLEADER style exists for the provided style name.
1604
1966
  */
1605
1967
  AcDbDatabase.prototype.ensureMLeaderStyle = function (styleName) {
1606
- var e_5, _a;
1968
+ var e_11, _a;
1607
1969
  var dictionary = this.objects.mleaderStyle;
1608
1970
  var normalizedName = styleName.trim();
1609
1971
  if (!normalizedName)
@@ -1619,12 +1981,12 @@ var AcDbDatabase = /** @class */ (function (_super) {
1619
1981
  }
1620
1982
  }
1621
1983
  }
1622
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1984
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
1623
1985
  finally {
1624
1986
  try {
1625
1987
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1626
1988
  }
1627
- finally { if (e_5) throw e_5.error; }
1989
+ finally { if (e_11) throw e_11.error; }
1628
1990
  }
1629
1991
  var style = new AcDbMLeaderStyle();
1630
1992
  // Match AutoCAD "Standard" defaults observed in exported DXF.
@@ -1751,7 +2113,7 @@ var AcDbDatabase = /** @class */ (function (_super) {
1751
2113
  * @param filer - DXF output writer.
1752
2114
  */
1753
2115
  AcDbDatabase.prototype.writeDxfBlocksSection = function (filer) {
1754
- var e_6, _a, e_7, _b;
2116
+ var e_12, _a, e_13, _b;
1755
2117
  filer.startSection('BLOCKS');
1756
2118
  try {
1757
2119
  for (var _c = __values(this.tables.blockTable.newIterator()), _d = _c.next(); !_d.done; _d = _c.next()) {
@@ -1759,28 +2121,28 @@ var AcDbDatabase = /** @class */ (function (_super) {
1759
2121
  btr.dxfOutBlockBegin(filer);
1760
2122
  if (!btr.isModelSapce && !btr.isPaperSapce) {
1761
2123
  try {
1762
- for (var _e = (e_7 = void 0, __values(btr.newIterator())), _f = _e.next(); !_f.done; _f = _e.next()) {
2124
+ for (var _e = (e_13 = void 0, __values(btr.newIterator())), _f = _e.next(); !_f.done; _f = _e.next()) {
1763
2125
  var entity = _f.value;
1764
2126
  this.writeDxfEntity(filer, entity);
1765
2127
  }
1766
2128
  }
1767
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
2129
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
1768
2130
  finally {
1769
2131
  try {
1770
2132
  if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
1771
2133
  }
1772
- finally { if (e_7) throw e_7.error; }
2134
+ finally { if (e_13) throw e_13.error; }
1773
2135
  }
1774
2136
  }
1775
2137
  btr.dxfOutBlockEnd(filer);
1776
2138
  }
1777
2139
  }
1778
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
2140
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
1779
2141
  finally {
1780
2142
  try {
1781
2143
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1782
2144
  }
1783
- finally { if (e_6) throw e_6.error; }
2145
+ finally { if (e_12) throw e_12.error; }
1784
2146
  }
1785
2147
  filer.endSection();
1786
2148
  };
@@ -1790,7 +2152,7 @@ var AcDbDatabase = /** @class */ (function (_super) {
1790
2152
  * @param filer - DXF output writer.
1791
2153
  */
1792
2154
  AcDbDatabase.prototype.writeDxfEntitiesSection = function (filer) {
1793
- var e_8, _a, e_9, _b;
2155
+ var e_14, _a, e_15, _b;
1794
2156
  filer.startSection('ENTITIES');
1795
2157
  try {
1796
2158
  for (var _c = __values(this.tables.blockTable.newIterator()), _d = _c.next(); !_d.done; _d = _c.next()) {
@@ -1798,26 +2160,26 @@ var AcDbDatabase = /** @class */ (function (_super) {
1798
2160
  if (!btr.isModelSapce && !btr.isPaperSapce)
1799
2161
  continue;
1800
2162
  try {
1801
- for (var _e = (e_9 = void 0, __values(btr.newIterator())), _f = _e.next(); !_f.done; _f = _e.next()) {
2163
+ for (var _e = (e_15 = void 0, __values(btr.newIterator())), _f = _e.next(); !_f.done; _f = _e.next()) {
1802
2164
  var entity = _f.value;
1803
2165
  this.writeDxfEntity(filer, entity);
1804
2166
  }
1805
2167
  }
1806
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
2168
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
1807
2169
  finally {
1808
2170
  try {
1809
2171
  if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
1810
2172
  }
1811
- finally { if (e_9) throw e_9.error; }
2173
+ finally { if (e_15) throw e_15.error; }
1812
2174
  }
1813
2175
  }
1814
2176
  }
1815
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
2177
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
1816
2178
  finally {
1817
2179
  try {
1818
2180
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1819
2181
  }
1820
- finally { if (e_8) throw e_8.error; }
2182
+ finally { if (e_14) throw e_14.error; }
1821
2183
  }
1822
2184
  filer.endSection();
1823
2185
  };
@@ -1827,7 +2189,7 @@ var AcDbDatabase = /** @class */ (function (_super) {
1827
2189
  * @param filer - DXF output writer.
1828
2190
  */
1829
2191
  AcDbDatabase.prototype.writeDxfObjectsSection = function (filer) {
1830
- var e_10, _a, e_11, _b, e_12, _c, e_13, _d, e_14, _e;
2192
+ var e_16, _a, e_17, _b, e_18, _c, e_19, _d, e_20, _e;
1831
2193
  filer.startSection('OBJECTS');
1832
2194
  var rootDict = this.objects.dictionary;
1833
2195
  rootDict.ownerId = '0';
@@ -1892,12 +2254,12 @@ var AcDbDatabase = /** @class */ (function (_super) {
1892
2254
  layout.dxfOut(filer);
1893
2255
  }
1894
2256
  }
1895
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
2257
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
1896
2258
  finally {
1897
2259
  try {
1898
2260
  if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
1899
2261
  }
1900
- finally { if (e_10) throw e_10.error; }
2262
+ finally { if (e_16) throw e_16.error; }
1901
2263
  }
1902
2264
  try {
1903
2265
  for (var _j = __values(this.objects.imageDefinition.entries()), _k = _j.next(); !_k.done; _k = _j.next()) {
@@ -1906,12 +2268,12 @@ var AcDbDatabase = /** @class */ (function (_super) {
1906
2268
  imageDef.dxfOut(filer);
1907
2269
  }
1908
2270
  }
1909
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
2271
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
1910
2272
  finally {
1911
2273
  try {
1912
2274
  if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
1913
2275
  }
1914
- finally { if (e_11) throw e_11.error; }
2276
+ finally { if (e_17) throw e_17.error; }
1915
2277
  }
1916
2278
  try {
1917
2279
  for (var _m = __values(this.objects.mleaderStyle.entries()), _o = _m.next(); !_o.done; _o = _m.next()) {
@@ -1920,12 +2282,12 @@ var AcDbDatabase = /** @class */ (function (_super) {
1920
2282
  mleaderStyle.dxfOut(filer);
1921
2283
  }
1922
2284
  }
1923
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
2285
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
1924
2286
  finally {
1925
2287
  try {
1926
2288
  if (_o && !_o.done && (_c = _m.return)) _c.call(_m);
1927
2289
  }
1928
- finally { if (e_12) throw e_12.error; }
2290
+ finally { if (e_18) throw e_18.error; }
1929
2291
  }
1930
2292
  try {
1931
2293
  for (var _q = __values(this.objects.mlineStyle.entries()), _r = _q.next(); !_r.done; _r = _q.next()) {
@@ -1934,12 +2296,12 @@ var AcDbDatabase = /** @class */ (function (_super) {
1934
2296
  mlineStyle.dxfOut(filer);
1935
2297
  }
1936
2298
  }
1937
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
2299
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
1938
2300
  finally {
1939
2301
  try {
1940
2302
  if (_r && !_r.done && (_d = _q.return)) _d.call(_q);
1941
2303
  }
1942
- finally { if (e_13) throw e_13.error; }
2304
+ finally { if (e_19) throw e_19.error; }
1943
2305
  }
1944
2306
  try {
1945
2307
  for (var _t = __values(this.objects.xrecord.entries()), _u = _t.next(); !_u.done; _u = _t.next()) {
@@ -1948,12 +2310,12 @@ var AcDbDatabase = /** @class */ (function (_super) {
1948
2310
  xrecord.dxfOut(filer);
1949
2311
  }
1950
2312
  }
1951
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
2313
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
1952
2314
  finally {
1953
2315
  try {
1954
2316
  if (_u && !_u.done && (_e = _t.return)) _e.call(_t);
1955
2317
  }
1956
- finally { if (e_14) throw e_14.error; }
2318
+ finally { if (e_20) throw e_20.error; }
1957
2319
  }
1958
2320
  filer.endSection();
1959
2321
  };
@@ -1967,7 +2329,7 @@ var AcDbDatabase = /** @class */ (function (_super) {
1967
2329
  * @param recordType - DXF record type name for each table record.
1968
2330
  */
1969
2331
  AcDbDatabase.prototype.writeDxfTable = function (filer, tableName, table, records, recordType) {
1970
- var e_15, _a;
2332
+ var e_21, _a;
1971
2333
  var items = __spreadArray([], __read(records), false);
1972
2334
  filer.startTable(tableName);
1973
2335
  table.dxfOut(filer);
@@ -1983,12 +2345,12 @@ var AcDbDatabase = /** @class */ (function (_super) {
1983
2345
  record.dxfOut(filer);
1984
2346
  }
1985
2347
  }
1986
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
2348
+ catch (e_21_1) { e_21 = { error: e_21_1 }; }
1987
2349
  finally {
1988
2350
  try {
1989
2351
  if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
1990
2352
  }
1991
- finally { if (e_15) throw e_15.error; }
2353
+ finally { if (e_21) throw e_21.error; }
1992
2354
  }
1993
2355
  filer.endTable();
1994
2356
  };
@@ -2018,6 +2380,7 @@ var AcDbDatabase = /** @class */ (function (_super) {
2018
2380
  * ```
2019
2381
  */
2020
2382
  AcDbDatabase.prototype.clear = function () {
2383
+ this.transactionManager.clearUndoStack();
2021
2384
  // Clear all tables and dictionaries
2022
2385
  this._tables.blockTable.removeAll();
2023
2386
  this._tables.dimStyleTable.removeAll();
@@ -2038,28 +2401,7 @@ var AcDbDatabase = /** @class */ (function (_super) {
2038
2401
  * Updates a sysvar value and dispatches the change event only when the value changed.
2039
2402
  */
2040
2403
  AcDbDatabase.prototype.updateSysVar = function (sysVarName, currentValue, nextValue, setter) {
2041
- if (!this.hasSysVarValueChanged(currentValue, nextValue)) {
2042
- return;
2043
- }
2044
- setter(nextValue);
2045
- this.triggerSysVarChangedEvent(sysVarName, currentValue, nextValue);
2046
- };
2047
- /**
2048
- * Determines whether two sysvar values are different.
2049
- */
2050
- AcDbDatabase.prototype.hasSysVarValueChanged = function (currentValue, nextValue) {
2051
- if (currentValue instanceof AcCmColor && nextValue instanceof AcCmColor) {
2052
- return !currentValue.equals(nextValue);
2053
- }
2054
- if (currentValue instanceof AcCmTransparency &&
2055
- nextValue instanceof AcCmTransparency) {
2056
- return !currentValue.equals(nextValue);
2057
- }
2058
- if (currentValue instanceof AcDbDwgVersion &&
2059
- nextValue instanceof AcDbDwgVersion) {
2060
- return currentValue.value !== nextValue.value;
2061
- }
2062
- return !Object.is(currentValue, nextValue);
2404
+ AcDbSysVarManager.instance().applyVarMutation(sysVarName, currentValue, nextValue, this, function () { return setter(nextValue); });
2063
2405
  };
2064
2406
  /**
2065
2407
  * Normalizes special linetype aliases to the internal canonical names.
@@ -2112,6 +2454,8 @@ var AcDbDatabase = /** @class */ (function (_super) {
2112
2454
  return '';
2113
2455
  }
2114
2456
  };
2457
+ /** Sequence counter for default unsaved drawing names (Drawing1.dwg, Drawing2.dwg, ...). */
2458
+ AcDbDatabase._unsavedDrawingSequence = 0;
2115
2459
  return AcDbDatabase;
2116
2460
  }(AcDbObject));
2117
2461
  export { AcDbDatabase };