@mlightcad/cad-pdf-plugin 1.7.3 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,3 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -45,17 +34,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
35
  }
47
36
  };
48
- var __values = (this && this.__values) || function(o) {
49
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
50
- if (m) return m.call(o);
51
- if (o && typeof o.length === "number") return {
52
- next: function () {
53
- if (o && i >= o.length) o = void 0;
54
- return { value: o && o[i++], done: !o };
55
- }
56
- };
57
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
58
- };
59
37
  var __read = (this && this.__read) || function (o, n) {
60
38
  var m = typeof Symbol === "function" && o[Symbol.iterator];
61
39
  if (!m) return o;
@@ -72,13 +50,42 @@ var __read = (this && this.__read) || function (o, n) {
72
50
  }
73
51
  return ar;
74
52
  };
75
- import { AcDbLine, AcDbPolyline, AcGePoint2d, AcGePoint3d, log } from '@mlightcad/data-model';
53
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
54
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
55
+ if (ar || !(i in from)) {
56
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
57
+ ar[i] = from[i];
58
+ }
59
+ }
60
+ return to.concat(ar || Array.prototype.slice.call(from));
61
+ };
62
+ var __values = (this && this.__values) || function(o) {
63
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
64
+ if (m) return m.call(o);
65
+ if (o && typeof o.length === "number") return {
66
+ next: function () {
67
+ if (o && i >= o.length) o = void 0;
68
+ return { value: o && o[i++], done: !o };
69
+ }
70
+ };
71
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
72
+ };
73
+ import { AcApDocManager, AcApI18n, AcEdCorsorType } from '@mlightcad/cad-simple-viewer';
74
+ import { AcCmColor, AcDbLine, AcDbPolyline, AcDbText, AcGePoint2d, AcGePoint3d, log } from '@mlightcad/data-model';
76
75
  import * as pdfjsLib from 'pdfjs-dist';
77
- pdfjsLib.GlobalWorkerOptions.workerSrc = '';
78
- /** 1 PDF point in mm (1 pt = 1/72 inch = 25.4/72 mm) */
79
- var PT_TO_MM = 25.4 / 72;
80
- /** Bezier approximation resolution (line segments per curve) */
81
- var BEZIER_STEPS = 8;
76
+ import { allocatePdfFallbackLayerName, collectPdfOcgLayers, normalizeCadLayerKey, pdfOperatorListHasOptionalContent } from './pdfOptionalContent';
77
+ import { extractPdfImportSubpaths } from './pdfVectorImport';
78
+ /**
79
+ * PDF.js worker shipped beside this module.
80
+ *
81
+ * Vite rewrites `new URL(..., import.meta.url)` and emits `pdf.worker.mjs`.
82
+ * App builds that rebundle this package pick that file up from the package
83
+ * `dist` and emit it into their own assets. PDF.js 5 rejects an empty
84
+ * `workerSrc`, and a `?url` import would keep the URL from the library build
85
+ * instead of the app chunk that actually loads it.
86
+ */
87
+ var PDF_WORKER_URL = new URL('../node_modules/pdfjs-dist/build/pdf.worker.mjs', import.meta.url);
88
+ pdfjsLib.GlobalWorkerOptions.workerSrc = PDF_WORKER_URL.href;
82
89
  /**
83
90
  * Converts a PDF file into CAD entities appended to the current document's
84
91
  * model space.
@@ -89,235 +96,240 @@ var AcApPdfImportConvertor = /** @class */ (function () {
89
96
  /**
90
97
  * Prompts the user to pick a PDF file and imports vector geometry.
91
98
  *
99
+ * Returns without database edits when the picker is dismissed. The command
100
+ * undo mark then has no committed changes, so nothing is pushed onto the
101
+ * undo stack.
102
+ *
92
103
  * @param context - Application context for the target document
93
104
  */
94
105
  AcApPdfImportConvertor.prototype.importFromFilePicker = function (context) {
95
- var _this = this;
96
- var input = document.createElement('input');
97
- input.type = 'file';
98
- input.accept = '.pdf';
99
- input.style.display = 'none';
100
- document.body.appendChild(input);
101
- input.addEventListener('change', function () { return __awaiter(_this, void 0, void 0, function () {
106
+ return __awaiter(this, void 0, void 0, function () {
102
107
  var file, buffer;
103
- var _a;
104
- return __generator(this, function (_b) {
105
- switch (_b.label) {
108
+ return __generator(this, function (_a) {
109
+ switch (_a.label) {
106
110
  case 0:
107
- file = (_a = input.files) === null || _a === void 0 ? void 0 : _a[0];
108
- document.body.removeChild(input);
111
+ _a.trys.push([0, , 4, 5]);
112
+ return [4 /*yield*/, this.pickPdfFile()];
113
+ case 1:
114
+ file = _a.sent();
109
115
  if (!file)
110
116
  return [2 /*return*/];
111
117
  return [4 /*yield*/, file.arrayBuffer()];
112
- case 1:
113
- buffer = _b.sent();
114
- return [4 /*yield*/, this.convert(context, buffer)];
115
118
  case 2:
116
- _b.sent();
117
- return [2 /*return*/];
119
+ buffer = _a.sent();
120
+ return [4 /*yield*/, this.convert(context, buffer)];
121
+ case 3:
122
+ _a.sent();
123
+ return [3 /*break*/, 5];
124
+ case 4:
125
+ // Chrome drops an SVG data-URI cursor after the native file dialog.
126
+ restoreViewCursor(context);
127
+ return [7 /*endfinally*/];
128
+ case 5: return [2 /*return*/];
118
129
  }
119
130
  });
120
- }); });
121
- input.click();
131
+ });
122
132
  };
123
133
  /**
124
- * Converts the first page of a PDF ArrayBuffer into CAD entities.
125
- * @param context - Application context for the target document
126
- * @param data - Raw PDF bytes
127
- * @param pageNumber - 1-based page number (default: 1)
134
+ * Opens the browser file picker.
135
+ *
136
+ * Resolves `undefined` when the user cancels the picker. `cancel` does not
137
+ * fire for every dismiss path, so closing the dialog (window focus with no
138
+ * selected file) also settles the promise. Otherwise `ipdf` would stay
139
+ * inside its write transaction.
128
140
  */
141
+ AcApPdfImportConvertor.prototype.pickPdfFile = function () {
142
+ return new Promise(function (resolve) {
143
+ var input = document.createElement('input');
144
+ input.type = 'file';
145
+ input.accept = '.pdf,application/pdf';
146
+ input.style.display = 'none';
147
+ document.body.appendChild(input);
148
+ var settled = false;
149
+ var focusFallbackTimer;
150
+ var finish = function (file) {
151
+ if (settled)
152
+ return;
153
+ settled = true;
154
+ window.removeEventListener('focus', onWindowFocus);
155
+ if (focusFallbackTimer !== undefined) {
156
+ clearTimeout(focusFallbackTimer);
157
+ }
158
+ input.remove();
159
+ resolve(file);
160
+ };
161
+ var onWindowFocus = function () {
162
+ // `change` can arrive just after focus. Wait before treating an empty
163
+ // selection as a cancel.
164
+ focusFallbackTimer = window.setTimeout(function () {
165
+ var _a;
166
+ finish((_a = input.files) === null || _a === void 0 ? void 0 : _a[0]);
167
+ }, 500);
168
+ };
169
+ input.addEventListener('change', function () { var _a; return finish((_a = input.files) === null || _a === void 0 ? void 0 : _a[0]); }, {
170
+ once: true
171
+ });
172
+ input.addEventListener('cancel', function () { return finish(); }, { once: true });
173
+ input.click();
174
+ // Attach after click so the focus event from opening the dialog is not
175
+ // treated as a dismiss.
176
+ window.setTimeout(function () {
177
+ if (!settled) {
178
+ window.addEventListener('focus', onWindowFocus);
179
+ }
180
+ }, 0);
181
+ });
182
+ };
129
183
  AcApPdfImportConvertor.prototype.convert = function (context_1, data_1) {
130
184
  return __awaiter(this, arguments, void 0, function (context, data, pageNumber) {
131
- var pdf, page, viewport, pageHeight, operatorList, entities, modelSpace, entities_1, entities_1_1, entity, err_1;
132
- var e_1, _a;
185
+ var _this = this;
133
186
  if (pageNumber === void 0) { pageNumber = 1; }
134
- return __generator(this, function (_b) {
135
- switch (_b.label) {
187
+ return __generator(this, function (_a) {
188
+ switch (_a.label) {
189
+ case 0: return [4 /*yield*/, AcApDocManager.instance.withBusyIndicator(function () { return _this.importPage(context, data, pageNumber); }, AcApI18n.t('main.message.importingPdf'))];
190
+ case 1:
191
+ _a.sent();
192
+ return [2 /*return*/];
193
+ }
194
+ });
195
+ });
196
+ };
197
+ AcApPdfImportConvertor.prototype.importPage = function (context, data, pageNumber) {
198
+ return __awaiter(this, void 0, void 0, function () {
199
+ var pdf, page, viewport, operatorList, optionalContentConfig, reservedLayerNames, ocgLayers, fallbackLayerName, _a, subpaths, texts, entities, usedLayerNames, subpaths_1, subpaths_1_1, subpath, entity, texts_1, texts_1_1, textRun, entity, layerService, existed, existedKeys, _b, _c, layerInfo, modelSpace, entities_1, entities_1_1, entity, err_1;
200
+ var e_1, _d, e_2, _e, e_3, _f, e_4, _g;
201
+ return __generator(this, function (_h) {
202
+ switch (_h.label) {
136
203
  case 0:
137
- _b.trys.push([0, 4, , 5]);
204
+ _h.trys.push([0, 5, , 6]);
138
205
  return [4 /*yield*/, pdfjsLib.getDocument({ data: data }).promise];
139
206
  case 1:
140
- pdf = _b.sent();
207
+ pdf = _h.sent();
141
208
  return [4 /*yield*/, pdf.getPage(pageNumber)];
142
209
  case 2:
143
- page = _b.sent();
210
+ page = _h.sent();
144
211
  viewport = page.getViewport({ scale: 1 });
145
- pageHeight = viewport.height;
146
212
  return [4 /*yield*/, page.getOperatorList()];
147
213
  case 3:
148
- operatorList = _b.sent();
149
- entities = this.extractEntities(operatorList, pageHeight);
150
- if (entities.length === 0) {
151
- log.warn('[PdfImport] No vector paths found in PDF page.');
152
- return [2 /*return*/];
153
- }
154
- modelSpace = context.doc.database.tables.blockTable.modelSpace;
214
+ operatorList = _h.sent();
215
+ return [4 /*yield*/, pdf.getOptionalContentConfig({
216
+ intent: 'display'
217
+ })];
218
+ case 4:
219
+ optionalContentConfig = (_h.sent());
220
+ reservedLayerNames = databaseLayerNames(context);
221
+ ocgLayers = collectPdfOcgLayers(operatorList, pdfjsLib.OPS.beginMarkedContentProps, optionalContentConfig, reservedLayerNames);
222
+ fallbackLayerName = pdfOperatorListHasOptionalContent(operatorList, pdfjsLib.OPS.beginMarkedContentProps)
223
+ ? allocatePdfFallbackLayerName(reservedLayerNames, __spreadArray([], __read(ocgLayers.values()), false).map(function (layer) { return layer.layerName; }))
224
+ : undefined;
225
+ _a = extractPdfImportSubpaths(operatorList, pdfjsLib.OPS, viewport, ocgLayers, fallbackLayerName), subpaths = _a.subpaths, texts = _a.texts;
226
+ entities = [];
227
+ usedLayerNames = new Set();
155
228
  try {
156
- for (entities_1 = __values(entities), entities_1_1 = entities_1.next(); !entities_1_1.done; entities_1_1 = entities_1.next()) {
157
- entity = entities_1_1.value;
158
- modelSpace.appendEntity(entity);
229
+ for (subpaths_1 = __values(subpaths), subpaths_1_1 = subpaths_1.next(); !subpaths_1_1.done; subpaths_1_1 = subpaths_1.next()) {
230
+ subpath = subpaths_1_1.value;
231
+ if (subpath.layerName) {
232
+ usedLayerNames.add(subpath.layerName);
233
+ }
234
+ entity = this.subpathToEntity(subpath.points, subpath.layerName, subpath.color);
235
+ if (entity)
236
+ entities.push(entity);
159
237
  }
160
238
  }
161
239
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
162
240
  finally {
163
241
  try {
164
- if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
242
+ if (subpaths_1_1 && !subpaths_1_1.done && (_d = subpaths_1.return)) _d.call(subpaths_1);
165
243
  }
166
244
  finally { if (e_1) throw e_1.error; }
167
245
  }
168
- log.info("[PdfImport] Imported ".concat(entities.length, " entities from PDF."));
169
- return [3 /*break*/, 5];
170
- case 4:
171
- err_1 = _b.sent();
172
- log.error('[PdfImport] Failed to import PDF:', err_1);
173
- return [3 /*break*/, 5];
174
- case 5: return [2 /*return*/];
175
- }
176
- });
177
- });
178
- };
179
- AcApPdfImportConvertor.prototype.extractEntities = function (opList, pageHeight) {
180
- var e_2, _a, e_3, _b, e_4, _c;
181
- var _this = this;
182
- var OPS = pdfjsLib.OPS;
183
- var fnArray = opList.fnArray, argsArray = opList.argsArray;
184
- var result = [];
185
- var subpaths = [];
186
- var current = [];
187
- var curX = 0;
188
- var curY = 0;
189
- var flush = function () {
190
- if (current.length > 1)
191
- subpaths.push(current);
192
- current = [];
193
- };
194
- var commit = function () {
195
- var e_5, _a;
196
- flush();
197
- try {
198
- for (var subpaths_1 = __values(subpaths), subpaths_1_1 = subpaths_1.next(); !subpaths_1_1.done; subpaths_1_1 = subpaths_1.next()) {
199
- var sp = subpaths_1_1.value;
200
- var entity = _this.subpathToEntity(sp);
201
- if (entity)
202
- result.push(entity);
203
- }
204
- }
205
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
206
- finally {
207
- try {
208
- if (subpaths_1_1 && !subpaths_1_1.done && (_a = subpaths_1.return)) _a.call(subpaths_1);
209
- }
210
- finally { if (e_5) throw e_5.error; }
211
- }
212
- subpaths = [];
213
- };
214
- var tx = function (x, _y) { return x * PT_TO_MM; };
215
- var ty = function (_x, y) { return (pageHeight - y) * PT_TO_MM; };
216
- for (var i = 0; i < fnArray.length; i++) {
217
- var fn = fnArray[i];
218
- var args = argsArray[i];
219
- switch (fn) {
220
- case OPS.moveTo: {
221
- flush();
222
- curX = args[0];
223
- curY = args[1];
224
- current = [{ x: tx(curX, curY), y: ty(curX, curY) }];
225
- break;
226
- }
227
- case OPS.lineTo: {
228
- curX = args[0];
229
- curY = args[1];
230
- current.push({ x: tx(curX, curY), y: ty(curX, curY) });
231
- break;
232
- }
233
- case OPS.curveTo: {
234
- var _d = __read(args, 6), x1 = _d[0], y1 = _d[1], x2 = _d[2], y2 = _d[3], x3 = _d[4], y3 = _d[5];
235
- var pts = cubicBezier({ x: curX, y: curY }, { x: x1, y: y1 }, { x: x2, y: y2 }, { x: x3, y: y3 }, BEZIER_STEPS);
236
- try {
237
- for (var pts_1 = (e_2 = void 0, __values(pts)), pts_1_1 = pts_1.next(); !pts_1_1.done; pts_1_1 = pts_1.next()) {
238
- var p = pts_1_1.value;
239
- current.push({ x: tx(p.x, p.y), y: ty(p.x, p.y) });
240
- }
241
- }
242
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
243
- finally {
244
246
  try {
245
- if (pts_1_1 && !pts_1_1.done && (_a = pts_1.return)) _a.call(pts_1);
247
+ for (texts_1 = __values(texts), texts_1_1 = texts_1.next(); !texts_1_1.done; texts_1_1 = texts_1.next()) {
248
+ textRun = texts_1_1.value;
249
+ if (textRun.layerName) {
250
+ usedLayerNames.add(textRun.layerName);
251
+ }
252
+ entity = this.textToEntity(textRun);
253
+ if (entity)
254
+ entities.push(entity);
255
+ }
246
256
  }
247
- finally { if (e_2) throw e_2.error; }
248
- }
249
- curX = x3;
250
- curY = y3;
251
- break;
252
- }
253
- case OPS.curveTo2: {
254
- var _e = __read(args, 4), x2 = _e[0], y2 = _e[1], x3 = _e[2], y3 = _e[3];
255
- var pts = cubicBezier({ x: curX, y: curY }, { x: curX, y: curY }, { x: x2, y: y2 }, { x: x3, y: y3 }, BEZIER_STEPS);
256
- try {
257
- for (var pts_2 = (e_3 = void 0, __values(pts)), pts_2_1 = pts_2.next(); !pts_2_1.done; pts_2_1 = pts_2.next()) {
258
- var p = pts_2_1.value;
259
- current.push({ x: tx(p.x, p.y), y: ty(p.x, p.y) });
257
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
258
+ finally {
259
+ try {
260
+ if (texts_1_1 && !texts_1_1.done && (_e = texts_1.return)) _e.call(texts_1);
261
+ }
262
+ finally { if (e_2) throw e_2.error; }
260
263
  }
261
- }
262
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
263
- finally {
264
+ if (entities.length === 0) {
265
+ log.warn('[PdfImport] No vector geometry found in PDF page.');
266
+ return [2 /*return*/];
267
+ }
268
+ layerService = context.doc.layerService;
269
+ existed = usedLayerNames.size > 0
270
+ ? layerService.createLayers(__spreadArray([], __read(usedLayerNames), false)).existed
271
+ : [];
272
+ existedKeys = new Set(existed.map(normalizeCadLayerKey));
264
273
  try {
265
- if (pts_2_1 && !pts_2_1.done && (_b = pts_2.return)) _b.call(pts_2);
274
+ for (_b = __values(ocgLayers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
275
+ layerInfo = _c.value;
276
+ if (!usedLayerNames.has(layerInfo.layerName))
277
+ continue;
278
+ if (existedKeys.has(normalizeCadLayerKey(layerInfo.layerName)))
279
+ continue;
280
+ if (layerInfo.visible)
281
+ continue;
282
+ layerService.setLayerOn(layerInfo.layerName, false);
283
+ }
266
284
  }
267
- finally { if (e_3) throw e_3.error; }
268
- }
269
- curX = x3;
270
- curY = y3;
271
- break;
272
- }
273
- case OPS.curveTo3: {
274
- var _f = __read(args, 4), x1 = _f[0], y1 = _f[1], x3 = _f[2], y3 = _f[3];
275
- var pts = cubicBezier({ x: curX, y: curY }, { x: x1, y: y1 }, { x: x3, y: y3 }, { x: x3, y: y3 }, BEZIER_STEPS);
276
- try {
277
- for (var pts_3 = (e_4 = void 0, __values(pts)), pts_3_1 = pts_3.next(); !pts_3_1.done; pts_3_1 = pts_3.next()) {
278
- var p = pts_3_1.value;
279
- current.push({ x: tx(p.x, p.y), y: ty(p.x, p.y) });
285
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
286
+ finally {
287
+ try {
288
+ if (_c && !_c.done && (_f = _b.return)) _f.call(_b);
289
+ }
290
+ finally { if (e_3) throw e_3.error; }
280
291
  }
281
- }
282
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
283
- finally {
292
+ modelSpace = context.doc.database.tables.blockTable.modelSpace;
284
293
  try {
285
- if (pts_3_1 && !pts_3_1.done && (_c = pts_3.return)) _c.call(pts_3);
294
+ for (entities_1 = __values(entities), entities_1_1 = entities_1.next(); !entities_1_1.done; entities_1_1 = entities_1.next()) {
295
+ entity = entities_1_1.value;
296
+ modelSpace.appendEntity(entity);
297
+ }
286
298
  }
287
- finally { if (e_4) throw e_4.error; }
288
- }
289
- curX = x3;
290
- curY = y3;
291
- break;
292
- }
293
- case OPS.closePath: {
294
- if (current.length > 0 && subpaths.length === 0) {
295
- current.push(__assign({}, current[0]));
296
- }
297
- flush();
298
- break;
299
- }
300
- case OPS.stroke:
301
- case OPS.fill:
302
- case OPS.eoFill:
303
- case OPS.fillStroke:
304
- case OPS.eoFillStroke:
305
- case OPS.endPath: {
306
- commit();
307
- break;
299
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
300
+ finally {
301
+ try {
302
+ if (entities_1_1 && !entities_1_1.done && (_g = entities_1.return)) _g.call(entities_1);
303
+ }
304
+ finally { if (e_4) throw e_4.error; }
305
+ }
306
+ log.info("[PdfImport] Imported ".concat(entities.length, " entities across ").concat(usedLayerNames.size, " CAD layer(s)."));
307
+ return [3 /*break*/, 6];
308
+ case 5:
309
+ err_1 = _h.sent();
310
+ log.error('[PdfImport] Failed to import PDF:', err_1);
311
+ throw err_1;
312
+ case 6: return [2 /*return*/];
308
313
  }
309
- }
310
- }
311
- commit();
312
- return result;
314
+ });
315
+ });
313
316
  };
314
- AcApPdfImportConvertor.prototype.subpathToEntity = function (pts) {
317
+ AcApPdfImportConvertor.prototype.subpathToEntity = function (pts, layerName, color) {
315
318
  if (pts.length < 2)
316
319
  return null;
317
320
  if (pts.length === 2) {
318
- return new AcDbLine(new AcGePoint3d(pts[0].x, pts[0].y, 0), new AcGePoint3d(pts[1].x, pts[1].y, 0));
321
+ var line = new AcDbLine(new AcGePoint3d(pts[0].x, pts[0].y, 0), new AcGePoint3d(pts[1].x, pts[1].y, 0));
322
+ if (layerName) {
323
+ line.layer = layerName;
324
+ }
325
+ applyPdfColor(line, color);
326
+ return line;
319
327
  }
320
328
  var poly = new AcDbPolyline();
329
+ if (layerName) {
330
+ poly.layer = layerName;
331
+ }
332
+ applyPdfColor(poly, color);
321
333
  for (var i = 0; i < pts.length; i++) {
322
334
  poly.addVertexAt(i, new AcGePoint2d(pts[i].x, pts[i].y));
323
335
  }
@@ -330,34 +342,50 @@ var AcApPdfImportConvertor = /** @class */ (function () {
330
342
  }
331
343
  return poly;
332
344
  };
345
+ AcApPdfImportConvertor.prototype.textToEntity = function (run) {
346
+ if (!run.text || run.height <= 0)
347
+ return null;
348
+ var text = new AcDbText();
349
+ text.textString = run.text;
350
+ text.position = new AcGePoint3d(run.position.x, run.position.y, 0);
351
+ text.height = run.height;
352
+ text.rotation = run.rotation;
353
+ if (Number.isFinite(run.widthFactor) && run.widthFactor > 0) {
354
+ text.widthFactor = run.widthFactor;
355
+ }
356
+ if (run.layerName) {
357
+ text.layer = run.layerName;
358
+ }
359
+ applyPdfColor(text, run.color);
360
+ return text;
361
+ };
333
362
  return AcApPdfImportConvertor;
334
363
  }());
335
364
  export { AcApPdfImportConvertor };
336
- /**
337
- * Approximates a cubic Bézier curve as a polyline.
338
- *
339
- * @param p0 - Start point
340
- * @param p1 - First control point
341
- * @param p2 - Second control point
342
- * @param p3 - End point
343
- * @param steps - Number of line segments to generate
344
- * @returns Sampled points along the curve (excluding `p0`)
345
- */
346
- function cubicBezier(p0, p1, p2, p3, steps) {
347
- var pts = [];
348
- for (var i = 1; i <= steps; i++) {
349
- var t = i / steps;
350
- var mt = 1 - t;
351
- var x = mt * mt * mt * p0.x +
352
- 3 * mt * mt * t * p1.x +
353
- 3 * mt * t * t * p2.x +
354
- t * t * t * p3.x;
355
- var y = mt * mt * mt * p0.y +
356
- 3 * mt * mt * t * p1.y +
357
- 3 * mt * t * t * p2.y +
358
- t * t * t * p3.y;
359
- pts.push({ x: x, y: y });
360
- }
361
- return pts;
365
+ function applyPdfColor(entity, color) {
366
+ if (!color)
367
+ return;
368
+ var match = /^#([0-9a-fA-F]{6})$/.exec(color);
369
+ if (!match)
370
+ return;
371
+ var value = Number.parseInt(match[1], 16);
372
+ entity.color = new AcCmColor().setRGB((value >> 16) & 255, (value >> 8) & 255, value & 255);
373
+ }
374
+ function restoreViewCursor(context) {
375
+ var _a;
376
+ var view = context.view;
377
+ if (!view)
378
+ return;
379
+ var cursor = (_a = view.editor.currentCursor) !== null && _a !== void 0 ? _a : AcEdCorsorType.Crosshair;
380
+ var canvas = view.canvas;
381
+ var apply = function () {
382
+ canvas.style.cursor = 'default';
383
+ view.editor.setCursor(cursor);
384
+ };
385
+ apply();
386
+ window.requestAnimationFrame(apply);
387
+ }
388
+ function databaseLayerNames(context) {
389
+ return __spreadArray([], __read(context.doc.database.tables.layerTable.newIterator()), false).map(function (layer) { return layer.name; });
362
390
  }
363
391
  //# sourceMappingURL=AcApPdfImportConvertor.js.map