@mlightcad/cad-simple-viewer 1.0.0

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 (189) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -0
  3. package/dist/index.js +2422 -0
  4. package/dist/index.umd.cjs +9 -0
  5. package/lib/app/AcApContext.d.ts +15 -0
  6. package/lib/app/AcApContext.d.ts.map +1 -0
  7. package/lib/app/AcApContext.js +56 -0
  8. package/lib/app/AcApContext.js.map +1 -0
  9. package/lib/app/AcApDocCreator.d.ts +17 -0
  10. package/lib/app/AcApDocCreator.d.ts.map +1 -0
  11. package/lib/app/AcApDocCreator.js +140 -0
  12. package/lib/app/AcApDocCreator.js.map +1 -0
  13. package/lib/app/AcApDocManager.d.ts +60 -0
  14. package/lib/app/AcApDocManager.d.ts.map +1 -0
  15. package/lib/app/AcApDocManager.js +275 -0
  16. package/lib/app/AcApDocManager.js.map +1 -0
  17. package/lib/app/AcApDocument.d.ts +27 -0
  18. package/lib/app/AcApDocument.d.ts.map +1 -0
  19. package/lib/app/AcApDocument.js +165 -0
  20. package/lib/app/AcApDocument.js.map +1 -0
  21. package/lib/app/AcApFontLoader.d.ts +20 -0
  22. package/lib/app/AcApFontLoader.d.ts.map +1 -0
  23. package/lib/app/AcApFontLoader.js +135 -0
  24. package/lib/app/AcApFontLoader.js.map +1 -0
  25. package/lib/app/AcApSettingManager.d.ts +44 -0
  26. package/lib/app/AcApSettingManager.d.ts.map +1 -0
  27. package/lib/app/AcApSettingManager.js +122 -0
  28. package/lib/app/AcApSettingManager.js.map +1 -0
  29. package/lib/app/index.d.ts +5 -0
  30. package/lib/app/index.d.ts.map +1 -0
  31. package/lib/app/index.js +5 -0
  32. package/lib/app/index.js.map +1 -0
  33. package/lib/command/AcApConvertToSvgCmd.d.ts +6 -0
  34. package/lib/command/AcApConvertToSvgCmd.d.ts.map +1 -0
  35. package/lib/command/AcApConvertToSvgCmd.js +30 -0
  36. package/lib/command/AcApConvertToSvgCmd.js.map +1 -0
  37. package/lib/command/AcApOpenCmd.d.ts +6 -0
  38. package/lib/command/AcApOpenCmd.d.ts.map +1 -0
  39. package/lib/command/AcApOpenCmd.js +29 -0
  40. package/lib/command/AcApOpenCmd.js.map +1 -0
  41. package/lib/command/AcApPanCmd.d.ts +6 -0
  42. package/lib/command/AcApPanCmd.d.ts.map +1 -0
  43. package/lib/command/AcApPanCmd.js +30 -0
  44. package/lib/command/AcApPanCmd.js.map +1 -0
  45. package/lib/command/AcApQNewCmd.d.ts +6 -0
  46. package/lib/command/AcApQNewCmd.d.ts.map +1 -0
  47. package/lib/command/AcApQNewCmd.js +30 -0
  48. package/lib/command/AcApQNewCmd.js.map +1 -0
  49. package/lib/command/AcApSelectCmd.d.ts +6 -0
  50. package/lib/command/AcApSelectCmd.d.ts.map +1 -0
  51. package/lib/command/AcApSelectCmd.js +30 -0
  52. package/lib/command/AcApSelectCmd.js.map +1 -0
  53. package/lib/command/AcApSvgConvertor.d.ts +5 -0
  54. package/lib/command/AcApSvgConvertor.d.ts.map +1 -0
  55. package/lib/command/AcApSvgConvertor.js +55 -0
  56. package/lib/command/AcApSvgConvertor.js.map +1 -0
  57. package/lib/command/AcApZoomCmd.d.ts +6 -0
  58. package/lib/command/AcApZoomCmd.d.ts.map +1 -0
  59. package/lib/command/AcApZoomCmd.js +28 -0
  60. package/lib/command/AcApZoomCmd.js.map +1 -0
  61. package/lib/command/AcApZoomToBoxCmd.d.ts +11 -0
  62. package/lib/command/AcApZoomToBoxCmd.d.ts.map +1 -0
  63. package/lib/command/AcApZoomToBoxCmd.js +101 -0
  64. package/lib/command/AcApZoomToBoxCmd.js.map +1 -0
  65. package/lib/command/index.d.ts +10 -0
  66. package/lib/command/index.d.ts.map +1 -0
  67. package/lib/command/index.js +10 -0
  68. package/lib/command/index.js.map +1 -0
  69. package/lib/editor/command/AcEdCommand.d.ts +42 -0
  70. package/lib/editor/command/AcEdCommand.d.ts.map +1 -0
  71. package/lib/editor/command/AcEdCommand.js +60 -0
  72. package/lib/editor/command/AcEdCommand.js.map +1 -0
  73. package/lib/editor/command/AcEdCommandIterator.d.ts +36 -0
  74. package/lib/editor/command/AcEdCommandIterator.d.ts.map +1 -0
  75. package/lib/editor/command/AcEdCommandIterator.js +65 -0
  76. package/lib/editor/command/AcEdCommandIterator.js.map +1 -0
  77. package/lib/editor/command/AcEdCommandStack.d.ts +66 -0
  78. package/lib/editor/command/AcEdCommandStack.d.ts.map +1 -0
  79. package/lib/editor/command/AcEdCommandStack.js +192 -0
  80. package/lib/editor/command/AcEdCommandStack.js.map +1 -0
  81. package/lib/editor/command/index.d.ts +3 -0
  82. package/lib/editor/command/index.d.ts.map +1 -0
  83. package/lib/editor/command/index.js +3 -0
  84. package/lib/editor/command/index.js.map +1 -0
  85. package/lib/editor/global/AcEdGlobalFunc.d.ts +8 -0
  86. package/lib/editor/global/AcEdGlobalFunc.d.ts.map +1 -0
  87. package/lib/editor/global/AcEdGlobalFunc.js +14 -0
  88. package/lib/editor/global/AcEdGlobalFunc.js.map +1 -0
  89. package/lib/editor/global/AcEdMessage.d.ts +5 -0
  90. package/lib/editor/global/AcEdMessage.d.ts.map +1 -0
  91. package/lib/editor/global/AcEdMessage.js +6 -0
  92. package/lib/editor/global/AcEdMessage.js.map +1 -0
  93. package/lib/editor/global/eventBus.d.ts +34 -0
  94. package/lib/editor/global/eventBus.d.ts.map +1 -0
  95. package/lib/editor/global/eventBus.js +3 -0
  96. package/lib/editor/global/eventBus.js.map +1 -0
  97. package/lib/editor/global/index.d.ts +3 -0
  98. package/lib/editor/global/index.d.ts.map +1 -0
  99. package/lib/editor/global/index.js +3 -0
  100. package/lib/editor/global/index.js.map +1 -0
  101. package/lib/editor/index.d.ts +5 -0
  102. package/lib/editor/index.d.ts.map +1 -0
  103. package/lib/editor/index.js +5 -0
  104. package/lib/editor/index.js.map +1 -0
  105. package/lib/editor/input/AcEdBaseInput.d.ts +25 -0
  106. package/lib/editor/input/AcEdBaseInput.d.ts.map +1 -0
  107. package/lib/editor/input/AcEdBaseInput.js +105 -0
  108. package/lib/editor/input/AcEdBaseInput.js.map +1 -0
  109. package/lib/editor/input/AcEdBoxSelector.d.ts +27 -0
  110. package/lib/editor/input/AcEdBoxSelector.d.ts.map +1 -0
  111. package/lib/editor/input/AcEdBoxSelector.js +140 -0
  112. package/lib/editor/input/AcEdBoxSelector.js.map +1 -0
  113. package/lib/editor/input/AcEdCursorManager.d.ts +43 -0
  114. package/lib/editor/input/AcEdCursorManager.d.ts.map +1 -0
  115. package/lib/editor/input/AcEdCursorManager.js +71 -0
  116. package/lib/editor/input/AcEdCursorManager.js.map +1 -0
  117. package/lib/editor/input/AcEdInputPoint.d.ts +14 -0
  118. package/lib/editor/input/AcEdInputPoint.d.ts.map +1 -0
  119. package/lib/editor/input/AcEdInputPoint.js +41 -0
  120. package/lib/editor/input/AcEdInputPoint.js.map +1 -0
  121. package/lib/editor/input/AcEdJig.d.ts +14 -0
  122. package/lib/editor/input/AcEdJig.d.ts.map +1 -0
  123. package/lib/editor/input/AcEdJig.js +92 -0
  124. package/lib/editor/input/AcEdJig.js.map +1 -0
  125. package/lib/editor/input/AcEdJigLoop.d.ts +14 -0
  126. package/lib/editor/input/AcEdJigLoop.d.ts.map +1 -0
  127. package/lib/editor/input/AcEdJigLoop.js +43 -0
  128. package/lib/editor/input/AcEdJigLoop.js.map +1 -0
  129. package/lib/editor/input/AcEdSelectionSet.d.ts +26 -0
  130. package/lib/editor/input/AcEdSelectionSet.d.ts.map +1 -0
  131. package/lib/editor/input/AcEdSelectionSet.js +63 -0
  132. package/lib/editor/input/AcEdSelectionSet.js.map +1 -0
  133. package/lib/editor/input/AcEditor.d.ts +27 -0
  134. package/lib/editor/input/AcEditor.d.ts.map +1 -0
  135. package/lib/editor/input/AcEditor.js +103 -0
  136. package/lib/editor/input/AcEditor.js.map +1 -0
  137. package/lib/editor/input/index.d.ts +5 -0
  138. package/lib/editor/input/index.d.ts.map +1 -0
  139. package/lib/editor/input/index.js +5 -0
  140. package/lib/editor/input/index.js.map +1 -0
  141. package/lib/editor/view/AcEdBaseView.d.ts +261 -0
  142. package/lib/editor/view/AcEdBaseView.d.ts.map +1 -0
  143. package/lib/editor/view/AcEdBaseView.js +260 -0
  144. package/lib/editor/view/AcEdBaseView.js.map +1 -0
  145. package/lib/editor/view/index.d.ts +2 -0
  146. package/lib/editor/view/index.d.ts.map +1 -0
  147. package/lib/editor/view/index.js +2 -0
  148. package/lib/editor/view/index.js.map +1 -0
  149. package/lib/index.d.ts +5 -0
  150. package/lib/index.d.ts.map +1 -0
  151. package/lib/index.js +5 -0
  152. package/lib/index.js.map +1 -0
  153. package/lib/util/AcTrGeometryUtil.d.ts +18 -0
  154. package/lib/util/AcTrGeometryUtil.d.ts.map +1 -0
  155. package/lib/util/AcTrGeometryUtil.js +33 -0
  156. package/lib/util/AcTrGeometryUtil.js.map +1 -0
  157. package/lib/util/index.d.ts +2 -0
  158. package/lib/util/index.d.ts.map +1 -0
  159. package/lib/util/index.js +2 -0
  160. package/lib/util/index.js.map +1 -0
  161. package/lib/view/AcTrLayer.d.ts +97 -0
  162. package/lib/view/AcTrLayer.d.ts.map +1 -0
  163. package/lib/view/AcTrLayer.js +170 -0
  164. package/lib/view/AcTrLayer.js.map +1 -0
  165. package/lib/view/AcTrLayout.d.ts +114 -0
  166. package/lib/view/AcTrLayout.d.ts.map +1 -0
  167. package/lib/view/AcTrLayout.js +344 -0
  168. package/lib/view/AcTrLayout.js.map +1 -0
  169. package/lib/view/AcTrLayoutView.d.ts +57 -0
  170. package/lib/view/AcTrLayoutView.d.ts.map +1 -0
  171. package/lib/view/AcTrLayoutView.js +151 -0
  172. package/lib/view/AcTrLayoutView.js.map +1 -0
  173. package/lib/view/AcTrLayoutViewManager.d.ts +43 -0
  174. package/lib/view/AcTrLayoutViewManager.d.ts.map +1 -0
  175. package/lib/view/AcTrLayoutViewManager.js +74 -0
  176. package/lib/view/AcTrLayoutViewManager.js.map +1 -0
  177. package/lib/view/AcTrScene.d.ts +115 -0
  178. package/lib/view/AcTrScene.d.ts.map +1 -0
  179. package/lib/view/AcTrScene.js +319 -0
  180. package/lib/view/AcTrScene.js.map +1 -0
  181. package/lib/view/AcTrView2d.d.ts +160 -0
  182. package/lib/view/AcTrView2d.d.ts.map +1 -0
  183. package/lib/view/AcTrView2d.js +473 -0
  184. package/lib/view/AcTrView2d.js.map +1 -0
  185. package/lib/view/index.d.ts +2 -0
  186. package/lib/view/index.d.ts.map +1 -0
  187. package/lib/view/index.js +2 -0
  188. package/lib/view/index.js.map +1 -0
  189. package/package.json +55 -0
@@ -0,0 +1,275 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { AcCmEventManager, acdbHostApplicationServices } from '@mlightcad/data-model';
38
+ import { AcApConvertToSvgCmd, AcApOpenCmd, AcApPanCmd, AcApQNewCmd, AcApSelectCmd, AcApZoomCmd, AcApZoomToBoxCmd, AcEdCommandStack } from '../command';
39
+ import { eventBus } from '../editor';
40
+ import { AcTrView2d } from '../view';
41
+ import { AcApContext } from './AcApContext';
42
+ import { AcApDocCreator } from './AcApDocCreator';
43
+ import { AcApDocument } from './AcApDocument';
44
+ import { AcApFontLoader } from './AcApFontLoader';
45
+ var AcApDocManager = /** @class */ (function () {
46
+ function AcApDocManager(canvas) {
47
+ this.events = {
48
+ documentCreated: new AcCmEventManager(),
49
+ documentActivated: new AcCmEventManager()
50
+ };
51
+ // Create one empty drawing
52
+ var doc = new AcApDocument();
53
+ doc.database.events.openProgress.addEventListener(function (args) {
54
+ eventBus.emit('open-file-progress', {
55
+ percentage: args.percentage,
56
+ stage: args.stage,
57
+ stageStatus: args.stageStatus
58
+ });
59
+ });
60
+ var callback = function () {
61
+ return {
62
+ width: window.innerWidth,
63
+ height: window.innerHeight - 30
64
+ };
65
+ };
66
+ var view = new AcTrView2d({ canvas: canvas, calculateSizeCallback: callback });
67
+ this._context = new AcApContext(view, doc);
68
+ this._fontLoader = new AcApFontLoader(view.renderer);
69
+ acdbHostApplicationServices().workingDatabase = doc.database;
70
+ this.registerCommands();
71
+ this.createExampleDoc();
72
+ }
73
+ AcApDocManager.createInstance = function (canvas) {
74
+ if (AcApDocManager._instance == null) {
75
+ AcApDocManager._instance = new AcApDocManager(canvas);
76
+ }
77
+ return this._instance;
78
+ };
79
+ Object.defineProperty(AcApDocManager, "instance", {
80
+ get: function () {
81
+ if (!AcApDocManager._instance) {
82
+ AcApDocManager._instance = new AcApDocManager();
83
+ }
84
+ return AcApDocManager._instance;
85
+ },
86
+ enumerable: false,
87
+ configurable: true
88
+ });
89
+ Object.defineProperty(AcApDocManager.prototype, "context", {
90
+ /**
91
+ * Current context
92
+ */
93
+ get: function () {
94
+ return this._context;
95
+ },
96
+ enumerable: false,
97
+ configurable: true
98
+ });
99
+ Object.defineProperty(AcApDocManager.prototype, "curDocument", {
100
+ /**
101
+ * Current open drawing
102
+ */
103
+ get: function () {
104
+ return this._context.doc;
105
+ },
106
+ enumerable: false,
107
+ configurable: true
108
+ });
109
+ Object.defineProperty(AcApDocManager.prototype, "mdiActiveDocument", {
110
+ /**
111
+ * For now, it is same as property `curDocument`.
112
+ */
113
+ get: function () {
114
+ return this._context.doc;
115
+ },
116
+ enumerable: false,
117
+ configurable: true
118
+ });
119
+ Object.defineProperty(AcApDocManager.prototype, "curView", {
120
+ /**
121
+ * Current view used to show current drawing
122
+ */
123
+ get: function () {
124
+ return this._context.view;
125
+ },
126
+ enumerable: false,
127
+ configurable: true
128
+ });
129
+ Object.defineProperty(AcApDocManager.prototype, "editor", {
130
+ get: function () {
131
+ return this._context.view.editor;
132
+ },
133
+ enumerable: false,
134
+ configurable: true
135
+ });
136
+ Object.defineProperty(AcApDocManager.prototype, "avaiableFonts", {
137
+ /**
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.
140
+ */
141
+ get: function () {
142
+ return this._fontLoader.avaiableFonts;
143
+ },
144
+ enumerable: false,
145
+ configurable: true
146
+ });
147
+ /**
148
+ * Load the specified fonts
149
+ * @param fonts Input one list of font names
150
+ */
151
+ AcApDocManager.prototype.loadFonts = function (fonts) {
152
+ return __awaiter(this, void 0, void 0, function () {
153
+ return __generator(this, function (_a) {
154
+ switch (_a.label) {
155
+ case 0: return [4 /*yield*/, this._fontLoader.load(fonts)];
156
+ case 1:
157
+ _a.sent();
158
+ return [2 /*return*/];
159
+ }
160
+ });
161
+ });
162
+ };
163
+ /**
164
+ * Load default fonts
165
+ */
166
+ AcApDocManager.prototype.loadDefaultFonts = function () {
167
+ return __awaiter(this, void 0, void 0, function () {
168
+ var fontFiles;
169
+ return __generator(this, function (_a) {
170
+ switch (_a.label) {
171
+ case 0:
172
+ fontFiles = ['simkai'];
173
+ return [4 /*yield*/, this._fontLoader.load(fontFiles)];
174
+ case 1:
175
+ _a.sent();
176
+ return [2 /*return*/];
177
+ }
178
+ });
179
+ });
180
+ };
181
+ AcApDocManager.prototype.createExampleDoc = function () {
182
+ var _this = this;
183
+ setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
184
+ return __generator(this, function (_a) {
185
+ switch (_a.label) {
186
+ case 0: return [4 /*yield*/, this.loadDefaultFonts()];
187
+ case 1:
188
+ _a.sent();
189
+ AcApDocCreator.instance.createExampleDoc2(this.curDocument.database);
190
+ this.setLayoutInfo();
191
+ this.curView.zoomToFit();
192
+ return [2 /*return*/];
193
+ }
194
+ });
195
+ }); });
196
+ };
197
+ AcApDocManager.prototype.openUrl = function (url, options) {
198
+ return __awaiter(this, void 0, void 0, function () {
199
+ var isSuccess;
200
+ return __generator(this, function (_a) {
201
+ switch (_a.label) {
202
+ case 0:
203
+ this.onBeforeOpenDocument();
204
+ options = this.setOptions(options);
205
+ return [4 /*yield*/, this.context.doc.openUri(url, options)];
206
+ case 1:
207
+ isSuccess = _a.sent();
208
+ this.onAfterOpenDocument(isSuccess);
209
+ return [2 /*return*/];
210
+ }
211
+ });
212
+ });
213
+ };
214
+ AcApDocManager.prototype.openDocument = function (fileName, content, options) {
215
+ return __awaiter(this, void 0, void 0, function () {
216
+ var isSuccess;
217
+ return __generator(this, function (_a) {
218
+ switch (_a.label) {
219
+ case 0:
220
+ this.onBeforeOpenDocument();
221
+ options = this.setOptions(options);
222
+ return [4 /*yield*/, this.context.doc.openDocument(fileName, content, options)];
223
+ case 1:
224
+ isSuccess = _a.sent();
225
+ this.onAfterOpenDocument(isSuccess);
226
+ return [2 /*return*/];
227
+ }
228
+ });
229
+ });
230
+ };
231
+ AcApDocManager.prototype.registerCommands = function () {
232
+ var register = AcEdCommandStack.instance;
233
+ register.addCommand(AcEdCommandStack.SYSTEMT_COMMAND_GROUP_NAME, 'pan', 'pan', new AcApPanCmd());
234
+ register.addCommand(AcEdCommandStack.SYSTEMT_COMMAND_GROUP_NAME, 'select', 'select', new AcApSelectCmd());
235
+ register.addCommand(AcEdCommandStack.SYSTEMT_COMMAND_GROUP_NAME, 'zoom', 'zoom', new AcApZoomCmd());
236
+ register.addCommand(AcEdCommandStack.SYSTEMT_COMMAND_GROUP_NAME, 'zoomw', 'zoomw', new AcApZoomToBoxCmd());
237
+ register.addCommand(AcEdCommandStack.SYSTEMT_COMMAND_GROUP_NAME, 'csvg', 'csvg', new AcApConvertToSvgCmd());
238
+ register.addCommand(AcEdCommandStack.SYSTEMT_COMMAND_GROUP_NAME, 'qnew', 'qnew', new AcApQNewCmd());
239
+ register.addCommand(AcEdCommandStack.SYSTEMT_COMMAND_GROUP_NAME, 'open', 'open', new AcApOpenCmd());
240
+ };
241
+ AcApDocManager.prototype.sendStringToExecute = function (cmdStr) {
242
+ var register = AcEdCommandStack.instance;
243
+ var cmd = register.lookupGlobalCmd(cmdStr);
244
+ cmd === null || cmd === void 0 ? void 0 : cmd.execute(this.context);
245
+ };
246
+ AcApDocManager.prototype.onBeforeOpenDocument = function () {
247
+ this.curView.clear();
248
+ };
249
+ AcApDocManager.prototype.onAfterOpenDocument = function (isSuccess) {
250
+ if (isSuccess) {
251
+ this.events.documentActivated.dispatch({
252
+ doc: this.context.doc
253
+ });
254
+ this.setLayoutInfo();
255
+ this.curView.zoomToFit();
256
+ }
257
+ };
258
+ AcApDocManager.prototype.setOptions = function (options) {
259
+ if (options == null) {
260
+ options = { fontLoader: this._fontLoader };
261
+ }
262
+ else if (options.fontLoader == null) {
263
+ options.fontLoader = this._fontLoader;
264
+ }
265
+ return options;
266
+ };
267
+ AcApDocManager.prototype.setLayoutInfo = function () {
268
+ var currentView = this.curView;
269
+ currentView.activeLayoutBtrId = this.curDocument.database.currentSpaceId;
270
+ currentView.modelSpaceBtrId = this.curDocument.database.currentSpaceId;
271
+ };
272
+ return AcApDocManager;
273
+ }());
274
+ export { AcApDocManager };
275
+ //# sourceMappingURL=AcApDocManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcApDocManager.js","sourceRoot":"","sources":["../../src/app/AcApDocManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EACL,gBAAgB,EAChB,2BAA2B,EAE5B,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,WAAW,EACX,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,YAAY,CAAA;AACnB,OAAO,EAA6B,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA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B,CAAC,CAAA;YACF,IAAI,CAAC,aAAa,EAAE,CAAA;YACpB,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAA;QAC1B,CAAC;IACH,CAAC;IAEO,mCAAU,GAAlB,UAAmB,OAAiC;QAClD,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACpB,OAAO,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,WAAW,EAAE,CAAA;QAC5C,CAAC;aAAM,IAAI,OAAO,CAAC,UAAU,IAAI,IAAI,EAAE,CAAC;YACtC,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAA;QACvC,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;IAEO,sCAAa,GAArB;QACE,IAAM,WAAW,GAAG,IAAI,CAAC,OAAqB,CAAA;QAC9C,WAAW,CAAC,iBAAiB,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAA;QACxE,WAAW,CAAC,eAAe,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAA;IACxE,CAAC;IACH,qBAAC;AAAD,CAAC,AA1ND,IA0NC"}
@@ -0,0 +1,27 @@
1
+ import { AcDbDatabase, AcDbOpenDatabaseOptions } from '@mlightcad/data-model';
2
+ export declare class AcApDocument {
3
+ private _uri?;
4
+ private _database;
5
+ private _fileName;
6
+ private _docTitle;
7
+ private _isReadOnly;
8
+ constructor();
9
+ openUri(uri: string, options: AcDbOpenDatabaseOptions): Promise<boolean>;
10
+ openDocument(fileName: string, content: string | ArrayBuffer, options: AcDbOpenDatabaseOptions): Promise<boolean>;
11
+ get uri(): string | undefined;
12
+ /**
13
+ * The database object being used by this document instance.
14
+ */
15
+ get database(): AcDbDatabase;
16
+ /**
17
+ * The window title of the document
18
+ */
19
+ get docTitle(): string;
20
+ set docTitle(value: string);
21
+ /**
22
+ * Return true if the document is read only; otherwise, returns false.
23
+ */
24
+ get isReadOnly(): boolean;
25
+ private getFileNameFromUri;
26
+ }
27
+ //# sourceMappingURL=AcApDocument.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcApDocument.d.ts","sourceRoot":"","sources":["../../src/app/AcApDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAEZ,uBAAuB,EACxB,MAAM,uBAAuB,CAAA;AAI9B,qBAAa,YAAY;IACvB,OAAO,CAAC,IAAI,CAAC,CAAQ;IACrB,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,WAAW,CAAgB;;IAO7B,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB;IAerD,YAAY,CAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,WAAW,EAC7B,OAAO,EAAE,uBAAuB;IAoBlC,IAAI,GAAG,uBAEN;IAED;;OAEG;IACH,IAAI,QAAQ,iBAEX;IAED;;OAEG;IACH,IAAI,QAAQ,IAGQ,MAAM,CADzB;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,MAAM,EAMzB;IAED;;OAEG;IACH,IAAI,UAAU,YAEb;IAED,OAAO,CAAC,kBAAkB;CAa3B"}
@@ -0,0 +1,165 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { AcDbDatabase, AcDbFileType } from '@mlightcad/data-model';
38
+ import { eventBus } from '../editor';
39
+ var AcApDocument = /** @class */ (function () {
40
+ function AcApDocument() {
41
+ this._fileName = '';
42
+ this._docTitle = '';
43
+ this._isReadOnly = true;
44
+ this._database = new AcDbDatabase();
45
+ this.docTitle = 'Untitled';
46
+ }
47
+ AcApDocument.prototype.openUri = function (uri, options) {
48
+ return __awaiter(this, void 0, void 0, function () {
49
+ var isSuccess, _1;
50
+ return __generator(this, function (_a) {
51
+ switch (_a.label) {
52
+ case 0:
53
+ this._uri = uri;
54
+ this._isReadOnly = (options && options.readOnly) || false;
55
+ this._fileName = this.getFileNameFromUri(uri);
56
+ isSuccess = true;
57
+ _a.label = 1;
58
+ case 1:
59
+ _a.trys.push([1, 3, , 4]);
60
+ return [4 /*yield*/, this._database.openUri(uri, options)];
61
+ case 2:
62
+ _a.sent();
63
+ this.docTitle = this._fileName;
64
+ return [3 /*break*/, 4];
65
+ case 3:
66
+ _1 = _a.sent();
67
+ isSuccess = false;
68
+ eventBus.emit('failed-to-open-file', { fileName: uri });
69
+ return [3 /*break*/, 4];
70
+ case 4: return [2 /*return*/, isSuccess];
71
+ }
72
+ });
73
+ });
74
+ };
75
+ AcApDocument.prototype.openDocument = function (fileName, content, options) {
76
+ return __awaiter(this, void 0, void 0, function () {
77
+ var isSuccess, fileExtension, e_1;
78
+ var _a;
79
+ return __generator(this, function (_b) {
80
+ switch (_b.label) {
81
+ case 0:
82
+ isSuccess = true;
83
+ this._fileName = fileName;
84
+ _b.label = 1;
85
+ case 1:
86
+ _b.trys.push([1, 3, , 4]);
87
+ fileExtension = (_a = fileName.split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase();
88
+ return [4 /*yield*/, this._database.read(content, options, fileExtension == 'dwg' ? AcDbFileType.DWG : AcDbFileType.DXF)];
89
+ case 2:
90
+ _b.sent();
91
+ this.docTitle = this._fileName;
92
+ return [3 /*break*/, 4];
93
+ case 3:
94
+ e_1 = _b.sent();
95
+ isSuccess = false;
96
+ eventBus.emit('failed-to-open-file', { fileName: fileName });
97
+ console.error(e_1);
98
+ return [3 /*break*/, 4];
99
+ case 4: return [2 /*return*/, isSuccess];
100
+ }
101
+ });
102
+ });
103
+ };
104
+ Object.defineProperty(AcApDocument.prototype, "uri", {
105
+ get: function () {
106
+ return this._uri;
107
+ },
108
+ enumerable: false,
109
+ configurable: true
110
+ });
111
+ Object.defineProperty(AcApDocument.prototype, "database", {
112
+ /**
113
+ * The database object being used by this document instance.
114
+ */
115
+ get: function () {
116
+ return this._database;
117
+ },
118
+ enumerable: false,
119
+ configurable: true
120
+ });
121
+ Object.defineProperty(AcApDocument.prototype, "docTitle", {
122
+ /**
123
+ * The window title of the document
124
+ */
125
+ get: function () {
126
+ return this._docTitle;
127
+ },
128
+ set: function (value) {
129
+ this._docTitle = value;
130
+ // Update browser title when document title changes
131
+ if (typeof document !== 'undefined') {
132
+ document.title = value;
133
+ }
134
+ },
135
+ enumerable: false,
136
+ configurable: true
137
+ });
138
+ Object.defineProperty(AcApDocument.prototype, "isReadOnly", {
139
+ /**
140
+ * Return true if the document is read only; otherwise, returns false.
141
+ */
142
+ get: function () {
143
+ return this._isReadOnly;
144
+ },
145
+ enumerable: false,
146
+ configurable: true
147
+ });
148
+ AcApDocument.prototype.getFileNameFromUri = function (uri) {
149
+ try {
150
+ // Create a new URL object
151
+ var url = new URL(uri);
152
+ // Get the pathname from the URL
153
+ var pathParts = url.pathname.split('/');
154
+ // Return the last part of the pathname as the file name
155
+ return pathParts[pathParts.length - 1] || '';
156
+ }
157
+ catch (error) {
158
+ console.error('Invalid URI:', error);
159
+ return '';
160
+ }
161
+ };
162
+ return AcApDocument;
163
+ }());
164
+ export { AcApDocument };
165
+ //# sourceMappingURL=AcApDocument.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcApDocument.js","sourceRoot":"","sources":["../../src/app/AcApDocument.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EACL,YAAY,EACZ,YAAY,EAEb,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC;IAOE;QAJQ,cAAS,GAAW,EAAE,CAAA;QACtB,cAAS,GAAW,EAAE,CAAA;QACtB,gBAAW,GAA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CAAA;QACX,CAAC;IACH,CAAC;IACH,mBAAC;AAAD,CAAC,AA/FD,IA+FC"}
@@ -0,0 +1,20 @@
1
+ import { AcDbFontInfo, AcDbFontLoader } from '@mlightcad/data-model';
2
+ import { AcTrRenderer } from '@mlightcad/three-renderer';
3
+ export declare class AcApFontLoader implements AcDbFontLoader {
4
+ private _cadRenderer;
5
+ private _avaiableFonts;
6
+ constructor(renderer: AcTrRenderer);
7
+ /**
8
+ * Avaiable fonts to load.
9
+ */
10
+ get avaiableFonts(): AcDbFontInfo[];
11
+ /**
12
+ * @inheritdoc
13
+ */
14
+ getAvaiableFonts(): Promise<AcDbFontInfo[]>;
15
+ /**
16
+ * @inheritdoc
17
+ */
18
+ load(fontNames: string[]): Promise<void>;
19
+ }
20
+ //# sourceMappingURL=AcApFontLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcApFontLoader.d.ts","sourceRoot":"","sources":["../../src/app/AcApFontLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAKxD,qBAAa,cAAe,YAAW,cAAc;IACnD,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,cAAc,CAAgB;gBAE1B,QAAQ,EAAE,YAAY;IAKlC;;OAEG;IACH,IAAI,aAAa,mBAEhB;IAED;;OAEG;IACG,gBAAgB;IAoBtB;;OAEG;IACG,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE;CAyB/B"}
@@ -0,0 +1,135 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { find, findIndex } from 'lodash-es';
38
+ import { eventBus } from '../editor';
39
+ var AcApFontLoader = /** @class */ (function () {
40
+ function AcApFontLoader(renderer) {
41
+ this._cadRenderer = renderer;
42
+ this._avaiableFonts = [];
43
+ }
44
+ Object.defineProperty(AcApFontLoader.prototype, "avaiableFonts", {
45
+ /**
46
+ * Avaiable fonts to load.
47
+ */
48
+ get: function () {
49
+ return this._avaiableFonts;
50
+ },
51
+ enumerable: false,
52
+ configurable: true
53
+ });
54
+ /**
55
+ * @inheritdoc
56
+ */
57
+ AcApFontLoader.prototype.getAvaiableFonts = function () {
58
+ return __awaiter(this, void 0, void 0, function () {
59
+ var baseUrl_1, fontMetaDataUrl, response, _a, _1;
60
+ return __generator(this, function (_b) {
61
+ switch (_b.label) {
62
+ case 0:
63
+ if (!(this._avaiableFonts.length == 0)) return [3 /*break*/, 6];
64
+ baseUrl_1 = 'https://cdn.jsdelivr.net/gh/mlight-lee/cad-data/fonts/';
65
+ fontMetaDataUrl = baseUrl_1 + 'fonts.json';
66
+ _b.label = 1;
67
+ case 1:
68
+ _b.trys.push([1, 4, , 5]);
69
+ return [4 /*yield*/, fetch(fontMetaDataUrl)];
70
+ case 2:
71
+ response = _b.sent();
72
+ _a = this;
73
+ return [4 /*yield*/, response.json()];
74
+ case 3:
75
+ _a._avaiableFonts = (_b.sent());
76
+ return [3 /*break*/, 5];
77
+ case 4:
78
+ _1 = _b.sent();
79
+ eventBus.emit('failed-to-get-avaiable-fonts', {
80
+ url: fontMetaDataUrl
81
+ });
82
+ return [3 /*break*/, 5];
83
+ case 5:
84
+ this._avaiableFonts.forEach(function (font) {
85
+ font.url = baseUrl_1 + font.file;
86
+ });
87
+ _b.label = 6;
88
+ case 6: return [2 /*return*/, this._avaiableFonts];
89
+ }
90
+ });
91
+ });
92
+ };
93
+ /**
94
+ * @inheritdoc
95
+ */
96
+ AcApFontLoader.prototype.load = function (fontNames) {
97
+ return __awaiter(this, void 0, void 0, function () {
98
+ var urls, loadStatus;
99
+ var _this = this;
100
+ return __generator(this, function (_a) {
101
+ switch (_a.label) {
102
+ case 0: return [4 /*yield*/, this.getAvaiableFonts()];
103
+ case 1:
104
+ _a.sent();
105
+ urls = [];
106
+ fontNames.forEach(function (font) {
107
+ var lowerCaseFontName = font.toLowerCase();
108
+ var result = find(_this._avaiableFonts, function (item) {
109
+ return (findIndex(item.name, function (name) {
110
+ return name.toLowerCase() == lowerCaseFontName;
111
+ }) >= 0);
112
+ });
113
+ if (result)
114
+ urls.push(result.url);
115
+ });
116
+ return [4 /*yield*/, this._cadRenderer.loadFonts(urls)];
117
+ case 2:
118
+ loadStatus = _a.sent();
119
+ loadStatus.forEach(function (item) {
120
+ if (!item.status) {
121
+ eventBus.emit('font-not-loaded', {
122
+ fontName: item.fontName,
123
+ url: item.url
124
+ });
125
+ }
126
+ });
127
+ return [2 /*return*/];
128
+ }
129
+ });
130
+ });
131
+ };
132
+ return AcApFontLoader;
133
+ }());
134
+ export { AcApFontLoader };
135
+ //# sourceMappingURL=AcApFontLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcApFontLoader.js","sourceRoot":"","sources":["../../src/app/AcApFontLoader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC;IAIE,wBAAY,QAAsB;QAChC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAA;QAC5B,IAAI,CAAC,cAAc,GAAG,EAAE,CAAA;IAC1B,CAAC;IAKD,sBAAI,yCAAa;QAHjB;;WAEG;aACH;YACE,OAAO,IAAI,CAAC,cAAc,CAAA;QAC5B,CAAC;;;OAAA;IAED;;OAEG;IACG,yCAAgB,GAAtB;;;;;;6BACM,CAAA,IAAI,CAAC,cAAc,CAAC,MAAM,IAAI,CAAC,CAAA,EAA/B,wBAA+B;wBAC3B,YAAU,wDAAwD,CAAA;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