@mlightcad/cad-simple-viewer 1.0.0 → 1.0.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.
Files changed (136) hide show
  1. package/README.md +296 -2
  2. package/dist/index.js +1347 -122
  3. package/dist/index.umd.cjs +2 -2
  4. package/lib/app/AcApContext.d.ts +45 -3
  5. package/lib/app/AcApContext.d.ts.map +1 -1
  6. package/lib/app/AcApContext.js +43 -3
  7. package/lib/app/AcApContext.js.map +1 -1
  8. package/lib/app/AcApDocCreator.d.ts +68 -2
  9. package/lib/app/AcApDocCreator.d.ts.map +1 -1
  10. package/lib/app/AcApDocCreator.js +67 -2
  11. package/lib/app/AcApDocCreator.js.map +1 -1
  12. package/lib/app/AcApDocManager.d.ts +227 -12
  13. package/lib/app/AcApDocManager.d.ts.map +1 -1
  14. package/lib/app/AcApDocManager.js +228 -17
  15. package/lib/app/AcApDocManager.js.map +1 -1
  16. package/lib/app/AcApDocument.d.ts +77 -3
  17. package/lib/app/AcApDocument.d.ts.map +1 -1
  18. package/lib/app/AcApDocument.js +75 -3
  19. package/lib/app/AcApDocument.js.map +1 -1
  20. package/lib/app/AcApFontLoader.d.ts +32 -0
  21. package/lib/app/AcApFontLoader.d.ts.map +1 -1
  22. package/lib/app/AcApFontLoader.js +30 -0
  23. package/lib/app/AcApFontLoader.js.map +1 -1
  24. package/lib/app/AcApSettingManager.d.ts +191 -3
  25. package/lib/app/AcApSettingManager.d.ts.map +1 -1
  26. package/lib/app/AcApSettingManager.js +161 -0
  27. package/lib/app/AcApSettingManager.js.map +1 -1
  28. package/lib/command/AcApConvertToSvgCmd.d.ts +26 -0
  29. package/lib/command/AcApConvertToSvgCmd.d.ts.map +1 -1
  30. package/lib/command/AcApConvertToSvgCmd.js +26 -0
  31. package/lib/command/AcApConvertToSvgCmd.js.map +1 -1
  32. package/lib/command/AcApOpenCmd.d.ts +31 -0
  33. package/lib/command/AcApOpenCmd.d.ts.map +1 -1
  34. package/lib/command/AcApOpenCmd.js +31 -0
  35. package/lib/command/AcApOpenCmd.js.map +1 -1
  36. package/lib/command/AcApPanCmd.d.ts +25 -0
  37. package/lib/command/AcApPanCmd.d.ts.map +1 -1
  38. package/lib/command/AcApPanCmd.js +25 -0
  39. package/lib/command/AcApPanCmd.js.map +1 -1
  40. package/lib/command/AcApQNewCmd.d.ts +26 -0
  41. package/lib/command/AcApQNewCmd.d.ts.map +1 -1
  42. package/lib/command/AcApQNewCmd.js +26 -0
  43. package/lib/command/AcApQNewCmd.js.map +1 -1
  44. package/lib/command/AcApSelectCmd.d.ts +26 -0
  45. package/lib/command/AcApSelectCmd.d.ts.map +1 -1
  46. package/lib/command/AcApSelectCmd.js +26 -0
  47. package/lib/command/AcApSelectCmd.js.map +1 -1
  48. package/lib/command/AcApSvgConvertor.d.ts +48 -0
  49. package/lib/command/AcApSvgConvertor.d.ts.map +1 -1
  50. package/lib/command/AcApSvgConvertor.js +48 -0
  51. package/lib/command/AcApSvgConvertor.js.map +1 -1
  52. package/lib/command/AcApZoomCmd.d.ts +29 -0
  53. package/lib/command/AcApZoomCmd.d.ts.map +1 -1
  54. package/lib/command/AcApZoomCmd.js +29 -0
  55. package/lib/command/AcApZoomCmd.js.map +1 -1
  56. package/lib/command/AcApZoomToBoxCmd.d.ts +57 -0
  57. package/lib/command/AcApZoomToBoxCmd.d.ts.map +1 -1
  58. package/lib/command/AcApZoomToBoxCmd.js +57 -0
  59. package/lib/command/AcApZoomToBoxCmd.js.map +1 -1
  60. package/lib/editor/command/AcEdCommand.d.ts +118 -9
  61. package/lib/editor/command/AcEdCommand.d.ts.map +1 -1
  62. package/lib/editor/command/AcEdCommand.js +113 -9
  63. package/lib/editor/command/AcEdCommand.js.map +1 -1
  64. package/lib/editor/command/AcEdCommandStack.d.ts +59 -5
  65. package/lib/editor/command/AcEdCommandStack.d.ts.map +1 -1
  66. package/lib/editor/command/AcEdCommandStack.js +48 -5
  67. package/lib/editor/command/AcEdCommandStack.js.map +1 -1
  68. package/lib/editor/global/eventBus.d.ts +69 -1
  69. package/lib/editor/global/eventBus.d.ts.map +1 -1
  70. package/lib/editor/global/eventBus.js +37 -0
  71. package/lib/editor/global/eventBus.js.map +1 -1
  72. package/lib/editor/input/AcEdBaseInput.d.ts +65 -1
  73. package/lib/editor/input/AcEdBaseInput.d.ts.map +1 -1
  74. package/lib/editor/input/AcEdBaseInput.js +62 -1
  75. package/lib/editor/input/AcEdBaseInput.js.map +1 -1
  76. package/lib/editor/input/AcEdBoxSelector.d.ts +81 -0
  77. package/lib/editor/input/AcEdBoxSelector.d.ts.map +1 -1
  78. package/lib/editor/input/AcEdBoxSelector.js +80 -0
  79. package/lib/editor/input/AcEdBoxSelector.js.map +1 -1
  80. package/lib/editor/input/AcEdCursorManager.d.ts +95 -8
  81. package/lib/editor/input/AcEdCursorManager.d.ts.map +1 -1
  82. package/lib/editor/input/AcEdCursorManager.js +95 -11
  83. package/lib/editor/input/AcEdCursorManager.js.map +1 -1
  84. package/lib/editor/input/AcEdInputPoint.d.ts +38 -1
  85. package/lib/editor/input/AcEdInputPoint.d.ts.map +1 -1
  86. package/lib/editor/input/AcEdInputPoint.js +38 -1
  87. package/lib/editor/input/AcEdInputPoint.js.map +1 -1
  88. package/lib/editor/input/AcEdJig.d.ts +166 -0
  89. package/lib/editor/input/AcEdJig.d.ts.map +1 -1
  90. package/lib/editor/input/AcEdJig.js +164 -0
  91. package/lib/editor/input/AcEdJig.js.map +1 -1
  92. package/lib/editor/input/AcEdJigLoop.d.ts +49 -0
  93. package/lib/editor/input/AcEdJigLoop.d.ts.map +1 -1
  94. package/lib/editor/input/AcEdJigLoop.js +48 -0
  95. package/lib/editor/input/AcEdJigLoop.js.map +1 -1
  96. package/lib/editor/input/AcEdSelectionSet.d.ts +122 -2
  97. package/lib/editor/input/AcEdSelectionSet.d.ts.map +1 -1
  98. package/lib/editor/input/AcEdSelectionSet.js +117 -1
  99. package/lib/editor/input/AcEdSelectionSet.js.map +1 -1
  100. package/lib/editor/input/AcEditor.d.ts +90 -6
  101. package/lib/editor/input/AcEditor.d.ts.map +1 -1
  102. package/lib/editor/input/AcEditor.js +86 -6
  103. package/lib/editor/input/AcEditor.js.map +1 -1
  104. package/lib/editor/view/AcEdBaseView.d.ts +163 -16
  105. package/lib/editor/view/AcEdBaseView.d.ts.map +1 -1
  106. package/lib/editor/view/AcEdBaseView.js +94 -5
  107. package/lib/editor/view/AcEdBaseView.js.map +1 -1
  108. package/lib/util/AcTrGeometryUtil.d.ts +65 -0
  109. package/lib/util/AcTrGeometryUtil.d.ts.map +1 -1
  110. package/lib/util/AcTrGeometryUtil.js +65 -0
  111. package/lib/util/AcTrGeometryUtil.js.map +1 -1
  112. package/lib/view/AcTrLayer.d.ts +40 -5
  113. package/lib/view/AcTrLayer.d.ts.map +1 -1
  114. package/lib/view/AcTrLayer.js +34 -5
  115. package/lib/view/AcTrLayer.js.map +1 -1
  116. package/lib/view/AcTrLayout.d.ts +122 -23
  117. package/lib/view/AcTrLayout.d.ts.map +1 -1
  118. package/lib/view/AcTrLayout.js +103 -23
  119. package/lib/view/AcTrLayout.js.map +1 -1
  120. package/lib/view/AcTrLayoutView.d.ts +74 -16
  121. package/lib/view/AcTrLayoutView.d.ts.map +1 -1
  122. package/lib/view/AcTrLayoutView.js +65 -16
  123. package/lib/view/AcTrLayoutView.js.map +1 -1
  124. package/lib/view/AcTrLayoutViewManager.d.ts +58 -12
  125. package/lib/view/AcTrLayoutViewManager.d.ts.map +1 -1
  126. package/lib/view/AcTrLayoutViewManager.js +56 -12
  127. package/lib/view/AcTrLayoutViewManager.js.map +1 -1
  128. package/lib/view/AcTrScene.d.ts +48 -4
  129. package/lib/view/AcTrScene.d.ts.map +1 -1
  130. package/lib/view/AcTrScene.js +44 -4
  131. package/lib/view/AcTrScene.js.map +1 -1
  132. package/lib/view/AcTrView2d.d.ts +71 -0
  133. package/lib/view/AcTrView2d.d.ts.map +1 -1
  134. package/lib/view/AcTrView2d.js +65 -0
  135. package/lib/view/AcTrView2d.js.map +1 -1
  136. package/package.json +8 -4
@@ -2,59 +2,274 @@ import { AcCmEventManager, AcDbOpenDatabaseOptions } from '@mlightcad/data-model
2
2
  import { AcTrView2d } from '../view';
3
3
  import { AcApContext } from './AcApContext';
4
4
  import { AcApDocument } from './AcApDocument';
5
+ /**
6
+ * Event arguments for document-related events.
7
+ */
5
8
  export interface AcDbDocumentEventArgs {
9
+ /** The document involved in the event */
6
10
  doc: AcApDocument;
7
11
  }
12
+ /**
13
+ * Document manager that handles CAD document lifecycle and provides the main entry point for the CAD viewer.
14
+ *
15
+ * This singleton class manages:
16
+ * - Document creation and opening (from URLs or file content)
17
+ * - View and context management
18
+ * - Command registration and execution
19
+ * - Font loading for text rendering
20
+ * - Event handling for document lifecycle
21
+ *
22
+ * The manager follows a singleton pattern to ensure only one instance manages the application state.
23
+ */
8
24
  export declare class AcApDocManager {
25
+ /** The current application context binding document and view */
9
26
  private _context;
27
+ /** Font loader for managing CAD text fonts */
10
28
  private _fontLoader;
29
+ /** Singleton instance */
11
30
  private static _instance?;
31
+ /** Events fired during document lifecycle */
12
32
  readonly events: {
33
+ /** Fired when a new document is created */
13
34
  documentCreated: AcCmEventManager<AcDbDocumentEventArgs>;
35
+ /** Fired when a document becomes active */
14
36
  documentActivated: AcCmEventManager<AcDbDocumentEventArgs>;
15
37
  };
38
+ /**
39
+ * Private constructor for singleton pattern.
40
+ *
41
+ * Creates an empty document with a 2D view and sets up the application context.
42
+ * Registers default commands and creates an example document.
43
+ *
44
+ * @param canvas - Optional HTML canvas element for rendering. If not provided, a new canvas will be created
45
+ * @private
46
+ */
16
47
  private constructor();
48
+ /**
49
+ * Creates the singleton instance with an optional canvas element.
50
+ *
51
+ * This method should be called before accessing the `instance` property
52
+ * if you want to provide a specific canvas element.
53
+ *
54
+ * @param canvas - Optional HTML canvas element for rendering
55
+ * @returns The singleton instance
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const canvas = document.getElementById('my-canvas') as HTMLCanvasElement;
60
+ * const docManager = AcApDocManager.createInstance(canvas);
61
+ * ```
62
+ */
17
63
  static createInstance(canvas?: HTMLCanvasElement): AcApDocManager | undefined;
64
+ /**
65
+ * Gets the singleton instance of the document manager.
66
+ *
67
+ * Creates a new instance if one doesn't exist yet.
68
+ *
69
+ * @returns The singleton document manager instance
70
+ */
18
71
  static get instance(): AcApDocManager;
19
72
  /**
20
- * Current context
73
+ * Gets the current application context.
74
+ *
75
+ * The context binds the current document with its associated view.
76
+ *
77
+ * @returns The current application context
21
78
  */
22
79
  get context(): AcApContext;
23
80
  /**
24
- * Current open drawing
81
+ * Gets the currently open CAD document.
82
+ *
83
+ * @returns The current document instance
25
84
  */
26
85
  get curDocument(): AcApDocument;
27
86
  /**
28
- * For now, it is same as property `curDocument`.
87
+ * Gets the currently active document.
88
+ *
89
+ * For now, this is the same as `curDocument` since only one document
90
+ * can be active at a time.
91
+ *
92
+ * @returns The current active document
29
93
  */
30
94
  get mdiActiveDocument(): AcApDocument;
31
95
  /**
32
- * Current view used to show current drawing
96
+ * Gets the current 2D view used to display the drawing.
97
+ *
98
+ * @returns The current 2D view instance
33
99
  */
34
100
  get curView(): AcTrView2d;
101
+ /**
102
+ * Gets the editor instance for handling user input.
103
+ *
104
+ * @returns The current editor instance
105
+ */
35
106
  get editor(): import("../editor").AcEditor;
36
107
  /**
37
- * Avaiable fonts to load. It means those fonts are avaiable to load. However, it
38
- * doesn't mean those fonts are already loaded and avaiable to use.
108
+ * Gets the list of available fonts that can be loaded.
109
+ *
110
+ * Note: These fonts are available for loading but may not be loaded yet.
111
+ *
112
+ * @returns Array of available font names
39
113
  */
40
114
  get avaiableFonts(): import("@mlightcad/data-model").AcDbFontInfo[];
41
115
  /**
42
- * Load the specified fonts
43
- * @param fonts Input one list of font names
116
+ * Loads the specified fonts for text rendering.
117
+ *
118
+ * @param fonts - Array of font names to load
119
+ * @returns Promise that resolves when fonts are loaded
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * await docManager.loadFonts(['Arial', 'Times New Roman']);
124
+ * ```
44
125
  */
45
126
  loadFonts(fonts: string[]): Promise<void>;
46
127
  /**
47
- * Load default fonts
128
+ * Loads default fonts for CAD text rendering.
129
+ *
130
+ * This method loads either the specified fonts or falls back to default Chinese fonts
131
+ * (specifically 'simkai') if no fonts are provided. The loaded fonts are used for
132
+ * rendering CAD text entities like MText and Text in the viewer.
133
+ *
134
+ * It is better to load default fonts when viewer is initialized so that the viewer can
135
+ * render text correctly if fonts used in the document are not available.
136
+ *
137
+ * @param fonts - Optional array of font names to load. If not provided or null,
138
+ * defaults to ['simkai'] for Chinese text support
139
+ * @returns Promise that resolves when all specified fonts are loaded
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * // Load default fonts (simkai)
144
+ * await docManager.loadDefaultFonts();
145
+ *
146
+ * // Load specific fonts
147
+ * await docManager.loadDefaultFonts(['Arial', 'SimSun']);
148
+ *
149
+ * // Load no fonts (empty array)
150
+ * await docManager.loadDefaultFonts([]);
151
+ * ```
152
+ *
153
+ * @see {@link AcApFontLoader.load} - The underlying font loading implementation
154
+ * @see {@link createExampleDoc} - Method that uses this for example document creation
155
+ */
156
+ loadDefaultFonts(fonts?: string[]): Promise<void>;
157
+ /**
158
+ * Creates an example CAD document with sample content.
159
+ *
160
+ * This method asynchronously loads default fonts, creates example drawing content,
161
+ * sets up layout information, and zooms the view to fit the content.
162
+ * The creation is performed after a short delay to ensure proper initialization.
48
163
  */
49
- loadDefaultFonts(): Promise<void>;
50
164
  createExampleDoc(): void;
51
- openUrl(url: string, options?: AcDbOpenDatabaseOptions): Promise<void>;
52
- openDocument(fileName: string, content: string | ArrayBuffer, options: AcDbOpenDatabaseOptions): Promise<void>;
165
+ /**
166
+ * Opens a CAD document from a URL.
167
+ *
168
+ * This method loads a document from the specified URL and replaces the current document.
169
+ * It handles the complete document lifecycle including before/after open events.
170
+ *
171
+ * @param url - The URL of the CAD file to open
172
+ * @param options - Optional database opening options. If not provided, default options with font loader will be used
173
+ * @returns Promise that resolves to true if the document was successfully opened, false otherwise
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * const success = await docManager.openUrl('https://example.com/drawing.dwg');
178
+ * if (success) {
179
+ * console.log('Document opened successfully');
180
+ * }
181
+ * ```
182
+ */
183
+ openUrl(url: string, options?: AcDbOpenDatabaseOptions): Promise<boolean>;
184
+ /**
185
+ * Opens a CAD document from file content.
186
+ *
187
+ * This method loads a document from the provided file content (string or binary data)
188
+ * and replaces the current document. It handles the complete document lifecycle
189
+ * including before/after open events.
190
+ *
191
+ * @param fileName - The name of the file being opened (used for format detection)
192
+ * @param content - The file content as string or ArrayBuffer
193
+ * @param options - Database opening options including font loader settings
194
+ * @returns Promise that resolves to true if the document was successfully opened, false otherwise
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * const fileContent = await file.arrayBuffer();
199
+ * const success = await docManager.openDocument('drawing.dwg', fileContent, options);
200
+ * ```
201
+ */
202
+ openDocument(fileName: string, content: string | ArrayBuffer, options: AcDbOpenDatabaseOptions): Promise<boolean>;
203
+ /**
204
+ * Registers all default commands available in the CAD viewer.
205
+ *
206
+ * This method sets up the command system by registering built-in commands including:
207
+ * - pan: Pan/move the view
208
+ * - select: Select entities
209
+ * - zoom: Zoom in/out
210
+ * - zoomw: Zoom to window/box
211
+ * - csvg: Convert to SVG
212
+ * - qnew: Quick new document
213
+ * - open: Open document
214
+ *
215
+ * All commands are registered under the system command group.
216
+ */
53
217
  registerCommands(): void;
218
+ /**
219
+ * Executes a command by its string name.
220
+ *
221
+ * This method looks up a registered command by name and executes it with the current context.
222
+ * If the command is not found, no action is taken.
223
+ *
224
+ * @param cmdStr - The command string to execute (e.g., 'pan', 'zoom', 'select')
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * docManager.sendStringToExecute('zoom');
229
+ * docManager.sendStringToExecute('pan');
230
+ * ```
231
+ */
54
232
  sendStringToExecute(cmdStr: string): void;
233
+ /**
234
+ * Performs cleanup operations before opening a new document.
235
+ *
236
+ * This protected method is called automatically before any document opening operation.
237
+ * It clears the current view to prepare for the new document content.
238
+ *
239
+ * @protected
240
+ */
55
241
  protected onBeforeOpenDocument(): void;
242
+ /**
243
+ * Performs setup operations after a document opening attempt.
244
+ *
245
+ * This protected method is called automatically after any document opening operation.
246
+ * If the document was successfully opened, it dispatches the documentActivated event,
247
+ * sets up layout information, and zooms the view to fit the content.
248
+ *
249
+ * @param isSuccess - Whether the document was successfully opened
250
+ * @protected
251
+ */
56
252
  protected onAfterOpenDocument(isSuccess: boolean): void;
253
+ /**
254
+ * Sets up or validates database opening options.
255
+ *
256
+ * This private method ensures that the options object has a font loader configured.
257
+ * If no options are provided, creates new options with the font loader.
258
+ * If options are provided but missing a font loader, adds the font loader.
259
+ *
260
+ * @param options - Optional database opening options to validate/modify
261
+ * @returns The validated options object with font loader configured
262
+ * @private
263
+ */
57
264
  private setOptions;
265
+ /**
266
+ * Configures layout information for the current view.
267
+ *
268
+ * This private method sets up the active layout block table record ID and
269
+ * model space block table record ID based on the current document's space configuration.
270
+ *
271
+ * @private
272
+ */
58
273
  private setLayoutInfo;
59
274
  }
60
275
  //# sourceMappingURL=AcApDocManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AcApDocManager.d.ts","sourceRoot":"","sources":["../../src/app/AcApDocManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAEhB,uBAAuB,EACxB,MAAM,uBAAuB,CAAA;AAa9B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAG7C,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,YAAY,CAAA;CAClB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,WAAW,CAAgB;IACnC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAg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AAC,oBAAoB;IAI9B;;;;;;;;;OASG;IACH,SAAS,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO;IAUhD;;;;;;;;;;OAUG;IACH,OAAO,CAAC,UAAU;IASlB;;;;;;;OAOG;IACH,OAAO,CAAC,aAAa;CAKtB"}
@@ -42,10 +42,34 @@ import { AcApContext } from './AcApContext';
42
42
  import { AcApDocCreator } from './AcApDocCreator';
43
43
  import { AcApDocument } from './AcApDocument';
44
44
  import { AcApFontLoader } from './AcApFontLoader';
45
+ /**
46
+ * Document manager that handles CAD document lifecycle and provides the main entry point for the CAD viewer.
47
+ *
48
+ * This singleton class manages:
49
+ * - Document creation and opening (from URLs or file content)
50
+ * - View and context management
51
+ * - Command registration and execution
52
+ * - Font loading for text rendering
53
+ * - Event handling for document lifecycle
54
+ *
55
+ * The manager follows a singleton pattern to ensure only one instance manages the application state.
56
+ */
45
57
  var AcApDocManager = /** @class */ (function () {
58
+ /**
59
+ * Private constructor for singleton pattern.
60
+ *
61
+ * Creates an empty document with a 2D view and sets up the application context.
62
+ * Registers default commands and creates an example document.
63
+ *
64
+ * @param canvas - Optional HTML canvas element for rendering. If not provided, a new canvas will be created
65
+ * @private
66
+ */
46
67
  function AcApDocManager(canvas) {
68
+ /** Events fired during document lifecycle */
47
69
  this.events = {
70
+ /** Fired when a new document is created */
48
71
  documentCreated: new AcCmEventManager(),
72
+ /** Fired when a document becomes active */
49
73
  documentActivated: new AcCmEventManager()
50
74
  };
51
75
  // Create one empty drawing
@@ -68,8 +92,22 @@ var AcApDocManager = /** @class */ (function () {
68
92
  this._fontLoader = new AcApFontLoader(view.renderer);
69
93
  acdbHostApplicationServices().workingDatabase = doc.database;
70
94
  this.registerCommands();
71
- this.createExampleDoc();
72
95
  }
96
+ /**
97
+ * Creates the singleton instance with an optional canvas element.
98
+ *
99
+ * This method should be called before accessing the `instance` property
100
+ * if you want to provide a specific canvas element.
101
+ *
102
+ * @param canvas - Optional HTML canvas element for rendering
103
+ * @returns The singleton instance
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const canvas = document.getElementById('my-canvas') as HTMLCanvasElement;
108
+ * const docManager = AcApDocManager.createInstance(canvas);
109
+ * ```
110
+ */
73
111
  AcApDocManager.createInstance = function (canvas) {
74
112
  if (AcApDocManager._instance == null) {
75
113
  AcApDocManager._instance = new AcApDocManager(canvas);
@@ -77,6 +115,13 @@ var AcApDocManager = /** @class */ (function () {
77
115
  return this._instance;
78
116
  };
79
117
  Object.defineProperty(AcApDocManager, "instance", {
118
+ /**
119
+ * Gets the singleton instance of the document manager.
120
+ *
121
+ * Creates a new instance if one doesn't exist yet.
122
+ *
123
+ * @returns The singleton document manager instance
124
+ */
80
125
  get: function () {
81
126
  if (!AcApDocManager._instance) {
82
127
  AcApDocManager._instance = new AcApDocManager();
@@ -88,7 +133,11 @@ var AcApDocManager = /** @class */ (function () {
88
133
  });
89
134
  Object.defineProperty(AcApDocManager.prototype, "context", {
90
135
  /**
91
- * Current context
136
+ * Gets the current application context.
137
+ *
138
+ * The context binds the current document with its associated view.
139
+ *
140
+ * @returns The current application context
92
141
  */
93
142
  get: function () {
94
143
  return this._context;
@@ -98,7 +147,9 @@ var AcApDocManager = /** @class */ (function () {
98
147
  });
99
148
  Object.defineProperty(AcApDocManager.prototype, "curDocument", {
100
149
  /**
101
- * Current open drawing
150
+ * Gets the currently open CAD document.
151
+ *
152
+ * @returns The current document instance
102
153
  */
103
154
  get: function () {
104
155
  return this._context.doc;
@@ -108,7 +159,12 @@ var AcApDocManager = /** @class */ (function () {
108
159
  });
109
160
  Object.defineProperty(AcApDocManager.prototype, "mdiActiveDocument", {
110
161
  /**
111
- * For now, it is same as property `curDocument`.
162
+ * Gets the currently active document.
163
+ *
164
+ * For now, this is the same as `curDocument` since only one document
165
+ * can be active at a time.
166
+ *
167
+ * @returns The current active document
112
168
  */
113
169
  get: function () {
114
170
  return this._context.doc;
@@ -118,7 +174,9 @@ var AcApDocManager = /** @class */ (function () {
118
174
  });
119
175
  Object.defineProperty(AcApDocManager.prototype, "curView", {
120
176
  /**
121
- * Current view used to show current drawing
177
+ * Gets the current 2D view used to display the drawing.
178
+ *
179
+ * @returns The current 2D view instance
122
180
  */
123
181
  get: function () {
124
182
  return this._context.view;
@@ -127,6 +185,11 @@ var AcApDocManager = /** @class */ (function () {
127
185
  configurable: true
128
186
  });
129
187
  Object.defineProperty(AcApDocManager.prototype, "editor", {
188
+ /**
189
+ * Gets the editor instance for handling user input.
190
+ *
191
+ * @returns The current editor instance
192
+ */
130
193
  get: function () {
131
194
  return this._context.view.editor;
132
195
  },
@@ -135,8 +198,11 @@ var AcApDocManager = /** @class */ (function () {
135
198
  });
136
199
  Object.defineProperty(AcApDocManager.prototype, "avaiableFonts", {
137
200
  /**
138
- * Avaiable fonts to load. It means those fonts are avaiable to load. However, it
139
- * doesn't mean those fonts are already loaded and avaiable to use.
201
+ * Gets the list of available fonts that can be loaded.
202
+ *
203
+ * Note: These fonts are available for loading but may not be loaded yet.
204
+ *
205
+ * @returns Array of available font names
140
206
  */
141
207
  get: function () {
142
208
  return this._fontLoader.avaiableFonts;
@@ -145,8 +211,15 @@ var AcApDocManager = /** @class */ (function () {
145
211
  configurable: true
146
212
  });
147
213
  /**
148
- * Load the specified fonts
149
- * @param fonts Input one list of font names
214
+ * Loads the specified fonts for text rendering.
215
+ *
216
+ * @param fonts - Array of font names to load
217
+ * @returns Promise that resolves when fonts are loaded
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * await docManager.loadFonts(['Arial', 'Times New Roman']);
222
+ * ```
150
223
  */
151
224
  AcApDocManager.prototype.loadFonts = function (fonts) {
152
225
  return __awaiter(this, void 0, void 0, function () {
@@ -161,23 +234,60 @@ var AcApDocManager = /** @class */ (function () {
161
234
  });
162
235
  };
163
236
  /**
164
- * Load default fonts
237
+ * Loads default fonts for CAD text rendering.
238
+ *
239
+ * This method loads either the specified fonts or falls back to default Chinese fonts
240
+ * (specifically 'simkai') if no fonts are provided. The loaded fonts are used for
241
+ * rendering CAD text entities like MText and Text in the viewer.
242
+ *
243
+ * It is better to load default fonts when viewer is initialized so that the viewer can
244
+ * render text correctly if fonts used in the document are not available.
245
+ *
246
+ * @param fonts - Optional array of font names to load. If not provided or null,
247
+ * defaults to ['simkai'] for Chinese text support
248
+ * @returns Promise that resolves when all specified fonts are loaded
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * // Load default fonts (simkai)
253
+ * await docManager.loadDefaultFonts();
254
+ *
255
+ * // Load specific fonts
256
+ * await docManager.loadDefaultFonts(['Arial', 'SimSun']);
257
+ *
258
+ * // Load no fonts (empty array)
259
+ * await docManager.loadDefaultFonts([]);
260
+ * ```
261
+ *
262
+ * @see {@link AcApFontLoader.load} - The underlying font loading implementation
263
+ * @see {@link createExampleDoc} - Method that uses this for example document creation
165
264
  */
166
- AcApDocManager.prototype.loadDefaultFonts = function () {
265
+ AcApDocManager.prototype.loadDefaultFonts = function (fonts) {
167
266
  return __awaiter(this, void 0, void 0, function () {
168
- var fontFiles;
169
267
  return __generator(this, function (_a) {
170
268
  switch (_a.label) {
171
269
  case 0:
172
- fontFiles = ['simkai'];
173
- return [4 /*yield*/, this._fontLoader.load(fontFiles)];
270
+ if (!(fonts == null)) return [3 /*break*/, 2];
271
+ return [4 /*yield*/, this._fontLoader.load(['simkai'])];
174
272
  case 1:
175
273
  _a.sent();
176
- return [2 /*return*/];
274
+ return [3 /*break*/, 4];
275
+ case 2: return [4 /*yield*/, this._fontLoader.load(fonts)];
276
+ case 3:
277
+ _a.sent();
278
+ _a.label = 4;
279
+ case 4: return [2 /*return*/];
177
280
  }
178
281
  });
179
282
  });
180
283
  };
284
+ /**
285
+ * Creates an example CAD document with sample content.
286
+ *
287
+ * This method asynchronously loads default fonts, creates example drawing content,
288
+ * sets up layout information, and zooms the view to fit the content.
289
+ * The creation is performed after a short delay to ensure proper initialization.
290
+ */
181
291
  AcApDocManager.prototype.createExampleDoc = function () {
182
292
  var _this = this;
183
293
  setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
@@ -194,6 +304,24 @@ var AcApDocManager = /** @class */ (function () {
194
304
  });
195
305
  }); });
196
306
  };
307
+ /**
308
+ * Opens a CAD document from a URL.
309
+ *
310
+ * This method loads a document from the specified URL and replaces the current document.
311
+ * It handles the complete document lifecycle including before/after open events.
312
+ *
313
+ * @param url - The URL of the CAD file to open
314
+ * @param options - Optional database opening options. If not provided, default options with font loader will be used
315
+ * @returns Promise that resolves to true if the document was successfully opened, false otherwise
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * const success = await docManager.openUrl('https://example.com/drawing.dwg');
320
+ * if (success) {
321
+ * console.log('Document opened successfully');
322
+ * }
323
+ * ```
324
+ */
197
325
  AcApDocManager.prototype.openUrl = function (url, options) {
198
326
  return __awaiter(this, void 0, void 0, function () {
199
327
  var isSuccess;
@@ -206,11 +334,29 @@ var AcApDocManager = /** @class */ (function () {
206
334
  case 1:
207
335
  isSuccess = _a.sent();
208
336
  this.onAfterOpenDocument(isSuccess);
209
- return [2 /*return*/];
337
+ return [2 /*return*/, isSuccess];
210
338
  }
211
339
  });
212
340
  });
213
341
  };
342
+ /**
343
+ * Opens a CAD document from file content.
344
+ *
345
+ * This method loads a document from the provided file content (string or binary data)
346
+ * and replaces the current document. It handles the complete document lifecycle
347
+ * including before/after open events.
348
+ *
349
+ * @param fileName - The name of the file being opened (used for format detection)
350
+ * @param content - The file content as string or ArrayBuffer
351
+ * @param options - Database opening options including font loader settings
352
+ * @returns Promise that resolves to true if the document was successfully opened, false otherwise
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * const fileContent = await file.arrayBuffer();
357
+ * const success = await docManager.openDocument('drawing.dwg', fileContent, options);
358
+ * ```
359
+ */
214
360
  AcApDocManager.prototype.openDocument = function (fileName, content, options) {
215
361
  return __awaiter(this, void 0, void 0, function () {
216
362
  var isSuccess;
@@ -223,11 +369,25 @@ var AcApDocManager = /** @class */ (function () {
223
369
  case 1:
224
370
  isSuccess = _a.sent();
225
371
  this.onAfterOpenDocument(isSuccess);
226
- return [2 /*return*/];
372
+ return [2 /*return*/, isSuccess];
227
373
  }
228
374
  });
229
375
  });
230
376
  };
377
+ /**
378
+ * Registers all default commands available in the CAD viewer.
379
+ *
380
+ * This method sets up the command system by registering built-in commands including:
381
+ * - pan: Pan/move the view
382
+ * - select: Select entities
383
+ * - zoom: Zoom in/out
384
+ * - zoomw: Zoom to window/box
385
+ * - csvg: Convert to SVG
386
+ * - qnew: Quick new document
387
+ * - open: Open document
388
+ *
389
+ * All commands are registered under the system command group.
390
+ */
231
391
  AcApDocManager.prototype.registerCommands = function () {
232
392
  var register = AcEdCommandStack.instance;
233
393
  register.addCommand(AcEdCommandStack.SYSTEMT_COMMAND_GROUP_NAME, 'pan', 'pan', new AcApPanCmd());
@@ -238,14 +398,46 @@ var AcApDocManager = /** @class */ (function () {
238
398
  register.addCommand(AcEdCommandStack.SYSTEMT_COMMAND_GROUP_NAME, 'qnew', 'qnew', new AcApQNewCmd());
239
399
  register.addCommand(AcEdCommandStack.SYSTEMT_COMMAND_GROUP_NAME, 'open', 'open', new AcApOpenCmd());
240
400
  };
401
+ /**
402
+ * Executes a command by its string name.
403
+ *
404
+ * This method looks up a registered command by name and executes it with the current context.
405
+ * If the command is not found, no action is taken.
406
+ *
407
+ * @param cmdStr - The command string to execute (e.g., 'pan', 'zoom', 'select')
408
+ *
409
+ * @example
410
+ * ```typescript
411
+ * docManager.sendStringToExecute('zoom');
412
+ * docManager.sendStringToExecute('pan');
413
+ * ```
414
+ */
241
415
  AcApDocManager.prototype.sendStringToExecute = function (cmdStr) {
242
416
  var register = AcEdCommandStack.instance;
243
417
  var cmd = register.lookupGlobalCmd(cmdStr);
244
418
  cmd === null || cmd === void 0 ? void 0 : cmd.execute(this.context);
245
419
  };
420
+ /**
421
+ * Performs cleanup operations before opening a new document.
422
+ *
423
+ * This protected method is called automatically before any document opening operation.
424
+ * It clears the current view to prepare for the new document content.
425
+ *
426
+ * @protected
427
+ */
246
428
  AcApDocManager.prototype.onBeforeOpenDocument = function () {
247
429
  this.curView.clear();
248
430
  };
431
+ /**
432
+ * Performs setup operations after a document opening attempt.
433
+ *
434
+ * This protected method is called automatically after any document opening operation.
435
+ * If the document was successfully opened, it dispatches the documentActivated event,
436
+ * sets up layout information, and zooms the view to fit the content.
437
+ *
438
+ * @param isSuccess - Whether the document was successfully opened
439
+ * @protected
440
+ */
249
441
  AcApDocManager.prototype.onAfterOpenDocument = function (isSuccess) {
250
442
  if (isSuccess) {
251
443
  this.events.documentActivated.dispatch({
@@ -255,6 +447,17 @@ var AcApDocManager = /** @class */ (function () {
255
447
  this.curView.zoomToFit();
256
448
  }
257
449
  };
450
+ /**
451
+ * Sets up or validates database opening options.
452
+ *
453
+ * This private method ensures that the options object has a font loader configured.
454
+ * If no options are provided, creates new options with the font loader.
455
+ * If options are provided but missing a font loader, adds the font loader.
456
+ *
457
+ * @param options - Optional database opening options to validate/modify
458
+ * @returns The validated options object with font loader configured
459
+ * @private
460
+ */
258
461
  AcApDocManager.prototype.setOptions = function (options) {
259
462
  if (options == null) {
260
463
  options = { fontLoader: this._fontLoader };
@@ -264,6 +467,14 @@ var AcApDocManager = /** @class */ (function () {
264
467
  }
265
468
  return options;
266
469
  };
470
+ /**
471
+ * Configures layout information for the current view.
472
+ *
473
+ * This private method sets up the active layout block table record ID and
474
+ * model space block table record ID based on the current document's space configuration.
475
+ *
476
+ * @private
477
+ */
267
478
  AcApDocManager.prototype.setLayoutInfo = function () {
268
479
  var currentView = this.curView;
269
480
  currentView.activeLayoutBtrId = this.curDocument.database.currentSpaceId;