@yudaocode/univer-pdfs 0.0.0-stage → 1.6.205
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.
- package/LICENSE +190 -0
- package/README.md +26 -2
- package/lib/cjs/facade/index.js +3607 -0
- package/lib/cjs/facade/index.js.map +1 -0
- package/lib/cjs/index.js +23106 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/jsx/index.js +12234 -0
- package/lib/cjs/jsx/index.js.map +1 -0
- package/lib/cjs/jsx/jsx-dev-runtime.js +82 -0
- package/lib/cjs/jsx/jsx-dev-runtime.js.map +1 -0
- package/lib/cjs/jsx/jsx-runtime.js +82 -0
- package/lib/cjs/jsx/jsx-runtime.js.map +1 -0
- package/lib/es/chunk-72OJSR4Z.js +15335 -0
- package/lib/es/chunk-72OJSR4Z.js.map +1 -0
- package/lib/es/chunk-CGOQSYGL.js +160 -0
- package/lib/es/chunk-CGOQSYGL.js.map +1 -0
- package/lib/es/facade/index.js +3681 -0
- package/lib/es/facade/index.js.map +1 -0
- package/lib/es/index.js +7809 -0
- package/lib/es/index.js.map +1 -0
- package/lib/es/jsx/index.js +81 -0
- package/lib/es/jsx/index.js.map +1 -0
- package/lib/es/jsx/jsx-dev-runtime.js +13 -0
- package/lib/es/jsx/jsx-dev-runtime.js.map +1 -0
- package/lib/es/jsx/jsx-runtime.js +13 -0
- package/lib/es/jsx/jsx-runtime.js.map +1 -0
- package/lib/types/facade/index.d.ts +1155 -0
- package/lib/types/index.d.ts +2025 -0
- package/lib/types/jsx/index.d.ts +45 -0
- package/lib/types/jsx/jsx-dev-runtime.d.ts +2 -0
- package/lib/types/jsx/jsx-runtime.d.ts +2 -0
- package/lib/types/jsx-dev-runtime-5tXCUq4v.d.ts +1484 -0
- package/package.json +94 -3
|
@@ -0,0 +1,3681 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
|
|
13
|
+
// src/facade/f-enum.ts
|
|
14
|
+
import { FEnum } from "@univerjs/core/facade";
|
|
15
|
+
import {
|
|
16
|
+
PdfAnnotationType,
|
|
17
|
+
PdfElementType,
|
|
18
|
+
PdfImageSourceType,
|
|
19
|
+
PdfListKind,
|
|
20
|
+
PdfListPresetId,
|
|
21
|
+
PdfTableBorderStyle,
|
|
22
|
+
PdfTableCellVerticalAlign,
|
|
23
|
+
PdfTextAnchor
|
|
24
|
+
} from "@yudaocode/univer-pdfs";
|
|
25
|
+
var FEnumPdfsMixin = class {
|
|
26
|
+
get PdfElementType() {
|
|
27
|
+
return PdfElementType;
|
|
28
|
+
}
|
|
29
|
+
get PdfAnnotationType() {
|
|
30
|
+
return PdfAnnotationType;
|
|
31
|
+
}
|
|
32
|
+
get PdfListKind() {
|
|
33
|
+
return PdfListKind;
|
|
34
|
+
}
|
|
35
|
+
get PdfListPresetId() {
|
|
36
|
+
return PdfListPresetId;
|
|
37
|
+
}
|
|
38
|
+
get PdfTextAnchor() {
|
|
39
|
+
return PdfTextAnchor;
|
|
40
|
+
}
|
|
41
|
+
get PdfTableCellVerticalAlign() {
|
|
42
|
+
return PdfTableCellVerticalAlign;
|
|
43
|
+
}
|
|
44
|
+
get PdfTableBorderStyle() {
|
|
45
|
+
return PdfTableBorderStyle;
|
|
46
|
+
}
|
|
47
|
+
get PdfImageSourceType() {
|
|
48
|
+
return PdfImageSourceType;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
FEnum.extend(FEnumPdfsMixin);
|
|
52
|
+
var cachedEnumSingleton = FEnum._instance;
|
|
53
|
+
if (cachedEnumSingleton) {
|
|
54
|
+
cachedEnumSingleton.PdfElementType = PdfElementType;
|
|
55
|
+
cachedEnumSingleton.PdfAnnotationType = PdfAnnotationType;
|
|
56
|
+
cachedEnumSingleton.PdfListKind = PdfListKind;
|
|
57
|
+
cachedEnumSingleton.PdfListPresetId = PdfListPresetId;
|
|
58
|
+
cachedEnumSingleton.PdfTextAnchor = PdfTextAnchor;
|
|
59
|
+
cachedEnumSingleton.PdfTableCellVerticalAlign = PdfTableCellVerticalAlign;
|
|
60
|
+
cachedEnumSingleton.PdfTableBorderStyle = PdfTableBorderStyle;
|
|
61
|
+
cachedEnumSingleton.PdfImageSourceType = PdfImageSourceType;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/facade/f-event.ts
|
|
65
|
+
import { FEventName } from "@univerjs/core/facade";
|
|
66
|
+
var FEventNamePdfsMixin = class {
|
|
67
|
+
get PdfLoaded() {
|
|
68
|
+
return "PdfLoaded";
|
|
69
|
+
}
|
|
70
|
+
get PdfDisposed() {
|
|
71
|
+
return "PdfDisposed";
|
|
72
|
+
}
|
|
73
|
+
get PdfPageChanged() {
|
|
74
|
+
return "PdfPageChanged";
|
|
75
|
+
}
|
|
76
|
+
get PdfElementSelected() {
|
|
77
|
+
return "PdfElementSelected";
|
|
78
|
+
}
|
|
79
|
+
get PdfFormFieldChanged() {
|
|
80
|
+
return "PdfFormFieldChanged";
|
|
81
|
+
}
|
|
82
|
+
get BeforePdfExport() {
|
|
83
|
+
return "BeforePdfExport";
|
|
84
|
+
}
|
|
85
|
+
get PdfExported() {
|
|
86
|
+
return "PdfExported";
|
|
87
|
+
}
|
|
88
|
+
get BeforePdfPrint() {
|
|
89
|
+
return "BeforePdfPrint";
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
FEventName.extend(FEventNamePdfsMixin);
|
|
93
|
+
var cachedEventNameSingleton = FEventName._instance;
|
|
94
|
+
if (cachedEventNameSingleton) {
|
|
95
|
+
cachedEventNameSingleton.PdfLoaded = "PdfLoaded";
|
|
96
|
+
cachedEventNameSingleton.PdfDisposed = "PdfDisposed";
|
|
97
|
+
cachedEventNameSingleton.PdfPageChanged = "PdfPageChanged";
|
|
98
|
+
cachedEventNameSingleton.PdfElementSelected = "PdfElementSelected";
|
|
99
|
+
cachedEventNameSingleton.PdfFormFieldChanged = "PdfFormFieldChanged";
|
|
100
|
+
cachedEventNameSingleton.BeforePdfExport = "BeforePdfExport";
|
|
101
|
+
cachedEventNameSingleton.PdfExported = "PdfExported";
|
|
102
|
+
cachedEventNameSingleton.BeforePdfPrint = "BeforePdfPrint";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/facade/f-pdf.ts
|
|
106
|
+
import { CanceledError, generateRandomId as generateRandomId3, ICommandService, Inject, Injector, Tools as Tools3 } from "@univerjs/core";
|
|
107
|
+
import { PDFDocument } from "pdf-lib";
|
|
108
|
+
import {
|
|
109
|
+
AddPdfElementCommand as AddPdfElementCommand3,
|
|
110
|
+
AddPdfLayerCommand,
|
|
111
|
+
AddPdfPageCommand,
|
|
112
|
+
applyOcrToUnitPage,
|
|
113
|
+
AssignPdfElementLayerCommand,
|
|
114
|
+
autoDetectFormFieldsOnPage,
|
|
115
|
+
comparePdfUnits,
|
|
116
|
+
convertPdfBytesToDocxBytes,
|
|
117
|
+
convertPdfUnitToCsv,
|
|
118
|
+
DeleteSelectedPdfElementsCommand as DeleteSelectedPdfElementsCommand2,
|
|
119
|
+
detectFormFieldsFromPageSpans,
|
|
120
|
+
DistributeSelectedPdfElementsCommand,
|
|
121
|
+
exportBatchPdfBytes,
|
|
122
|
+
exportCalibrationGridPdfBytes,
|
|
123
|
+
exportFormDataToFdf,
|
|
124
|
+
exportFormDataToXfdf,
|
|
125
|
+
exportPdfBytes,
|
|
126
|
+
exportPdfToDocxSnapshot,
|
|
127
|
+
exportPdfToWorkbookSnapshot,
|
|
128
|
+
exportSignedPdfWithAuditSeal,
|
|
129
|
+
extractAcroFormValuesFromPdfBytes,
|
|
130
|
+
extractNativeTextSpansFromPdfBytes,
|
|
131
|
+
extractPdfFormValues,
|
|
132
|
+
fillPdfFormValues,
|
|
133
|
+
FindAndReplacePdfTextCommand,
|
|
134
|
+
fromPdfmeTemplate,
|
|
135
|
+
importAcroFormPdfToUnit,
|
|
136
|
+
importFormDataFromFdf,
|
|
137
|
+
importFormDataFromXfdf,
|
|
138
|
+
ImportPdfSourceCommand,
|
|
139
|
+
IPdfIoService,
|
|
140
|
+
IPdfSelectionService,
|
|
141
|
+
optimizePdfUnit,
|
|
142
|
+
PdfElementType as PdfElementType4,
|
|
143
|
+
recalculatePdfFormFields,
|
|
144
|
+
RemovePdfLayerCommand,
|
|
145
|
+
ReorderPdfPagesCommand,
|
|
146
|
+
ReplacePdfNativeTextCommand as ReplacePdfNativeTextCommand2,
|
|
147
|
+
ReplacePdfSnapshotCommand,
|
|
148
|
+
RestorePdfVersionCommand,
|
|
149
|
+
RotatePdfPageCommand as RotatePdfPageCommand2,
|
|
150
|
+
sanitizePdfUnit,
|
|
151
|
+
SetPdfAttachmentsCommand,
|
|
152
|
+
SetPdfBatesConfigCommand,
|
|
153
|
+
SetPdfBookmarksCommand,
|
|
154
|
+
SetPdfHeaderFooterConfigCommand,
|
|
155
|
+
SetPdfNativeTextSpansCommand,
|
|
156
|
+
SetPdfPageCropBoxCommand,
|
|
157
|
+
SetPdfPageSizeCommand,
|
|
158
|
+
SetPdfWatermarkConfigCommand,
|
|
159
|
+
signPdfUnitWithDigest,
|
|
160
|
+
splitPdfBytes,
|
|
161
|
+
toPdfmeTemplate,
|
|
162
|
+
UpdatePdfElementsCommand as UpdatePdfElementsCommand2,
|
|
163
|
+
UpdatePdfLayerCommand,
|
|
164
|
+
UpdatePdfUnitPropsCommand,
|
|
165
|
+
validatePdfFormFields,
|
|
166
|
+
validatePdfTemplateSchema,
|
|
167
|
+
validatePdfTemplateVariables,
|
|
168
|
+
verifyPdfAuditSeal,
|
|
169
|
+
verifyPdfUnitSignature,
|
|
170
|
+
collectPdfInputContractHints,
|
|
171
|
+
detectCJKInPdfTemplate,
|
|
172
|
+
diagnosePdfFonts,
|
|
173
|
+
importPdfSource,
|
|
174
|
+
mergePdfBytes
|
|
175
|
+
} from "@yudaocode/univer-pdfs";
|
|
176
|
+
|
|
177
|
+
// src/facade/f-pdf-page.ts
|
|
178
|
+
import { generateRandomId as generateRandomId2, Tools as Tools2 } from "@univerjs/core";
|
|
179
|
+
import {
|
|
180
|
+
AddPdfElementCommand as AddPdfElementCommand2,
|
|
181
|
+
PdfElementType as PdfElementType3,
|
|
182
|
+
RemovePdfPageCommand,
|
|
183
|
+
RotatePdfPageCommand,
|
|
184
|
+
UpdatePdfPagePropsCommand
|
|
185
|
+
} from "@yudaocode/univer-pdfs";
|
|
186
|
+
|
|
187
|
+
// src/facade/f-pdf-elements.ts
|
|
188
|
+
import { generateRandomId, Tools } from "@univerjs/core";
|
|
189
|
+
import {
|
|
190
|
+
AddPdfElementCommand,
|
|
191
|
+
DeleteSelectedPdfElementsCommand,
|
|
192
|
+
formatPdfTableCell,
|
|
193
|
+
normalizeImageCrop,
|
|
194
|
+
PDF_TABLE_THEME_PRESETS,
|
|
195
|
+
PdfElementType as PdfElementType2,
|
|
196
|
+
PdfImageSourceType as PdfImageSourceType2,
|
|
197
|
+
PdfListKind as PdfListKind2,
|
|
198
|
+
PdfTableCellVerticalAlign as PdfTableCellVerticalAlign2,
|
|
199
|
+
ReorderPdfLayerCommand,
|
|
200
|
+
ReplacePdfNativeTextCommand,
|
|
201
|
+
UpdatePdfElementsCommand
|
|
202
|
+
} from "@yudaocode/univer-pdfs";
|
|
203
|
+
function encodeUint8ToBase64(bytes) {
|
|
204
|
+
if (typeof Buffer !== "undefined") {
|
|
205
|
+
return Buffer.from(bytes).toString("base64");
|
|
206
|
+
}
|
|
207
|
+
let bin = "";
|
|
208
|
+
const chunk = 32768;
|
|
209
|
+
for (let i = 0; i < bytes.length; i += chunk) {
|
|
210
|
+
bin += String.fromCharCode(...bytes.subarray(i, i + chunk));
|
|
211
|
+
}
|
|
212
|
+
return btoa(bin);
|
|
213
|
+
}
|
|
214
|
+
var FPdfPageElement = class {
|
|
215
|
+
constructor(_pdfModel, _commandService, _pageId, _elementId) {
|
|
216
|
+
this._pdfModel = _pdfModel;
|
|
217
|
+
this._commandService = _commandService;
|
|
218
|
+
this._pageId = _pageId;
|
|
219
|
+
this._elementId = _elementId;
|
|
220
|
+
}
|
|
221
|
+
getId() {
|
|
222
|
+
return this._elementId;
|
|
223
|
+
}
|
|
224
|
+
getPageId() {
|
|
225
|
+
return this._pageId;
|
|
226
|
+
}
|
|
227
|
+
/** @internal */
|
|
228
|
+
_getInternalPdfModel() {
|
|
229
|
+
return this._pdfModel;
|
|
230
|
+
}
|
|
231
|
+
/** @internal */
|
|
232
|
+
_getInternalCommandService() {
|
|
233
|
+
return this._commandService;
|
|
234
|
+
}
|
|
235
|
+
_readRaw() {
|
|
236
|
+
const el = this._pdfModel.getElementsByPage(this._pageId)[this._elementId];
|
|
237
|
+
if (!el) {
|
|
238
|
+
throw new Error(
|
|
239
|
+
`[UniverPdfs] Element "${this._elementId}" no longer exists on page "${this._pageId}".`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
return el;
|
|
243
|
+
}
|
|
244
|
+
exists() {
|
|
245
|
+
return Boolean(this._pdfModel.getElementsByPage(this._pageId)[this._elementId]);
|
|
246
|
+
}
|
|
247
|
+
getType() {
|
|
248
|
+
return this._readRaw().type;
|
|
249
|
+
}
|
|
250
|
+
getName() {
|
|
251
|
+
return this._readRaw().name;
|
|
252
|
+
}
|
|
253
|
+
setName(name) {
|
|
254
|
+
return this.update({ name });
|
|
255
|
+
}
|
|
256
|
+
getData() {
|
|
257
|
+
return Tools.deepClone(this._readRaw());
|
|
258
|
+
}
|
|
259
|
+
getBounds() {
|
|
260
|
+
const tr = this._readRaw().transform;
|
|
261
|
+
return {
|
|
262
|
+
left: tr.left,
|
|
263
|
+
top: tr.top,
|
|
264
|
+
width: tr.width,
|
|
265
|
+
height: tr.height,
|
|
266
|
+
angle: tr.angle ?? 0
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
getTransform() {
|
|
270
|
+
return Tools.deepClone(this._readRaw().transform);
|
|
271
|
+
}
|
|
272
|
+
setTransform(patch) {
|
|
273
|
+
const cur = this._readRaw().transform;
|
|
274
|
+
return this.update({
|
|
275
|
+
transform: {
|
|
276
|
+
...cur,
|
|
277
|
+
...patch,
|
|
278
|
+
width: patch.width !== void 0 ? Math.max(1, patch.width) : cur.width,
|
|
279
|
+
height: patch.height !== void 0 ? Math.max(0, patch.height) : cur.height
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
setPosition(left, top) {
|
|
284
|
+
const cur = this._readRaw().transform;
|
|
285
|
+
return this.update({
|
|
286
|
+
transform: { ...cur, left, top }
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
setSize(width, height) {
|
|
290
|
+
const cur = this._readRaw().transform;
|
|
291
|
+
return this.update({
|
|
292
|
+
transform: { ...cur, width: Math.max(1, width), height: Math.max(0, height) }
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
setRotation(angle) {
|
|
296
|
+
const cur = this._readRaw().transform;
|
|
297
|
+
return this.update({
|
|
298
|
+
transform: { ...cur, angle }
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
setFlip(flipX, flipY) {
|
|
302
|
+
const raw = this._readRaw();
|
|
303
|
+
const nextFlipY = flipY !== void 0 ? flipY : Boolean(raw.transform.flipY ?? raw.flipY);
|
|
304
|
+
return this.update({
|
|
305
|
+
flipX,
|
|
306
|
+
flipY: nextFlipY,
|
|
307
|
+
transform: { ...raw.transform, flipX, flipY: nextFlipY }
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
setOpacity(opacity) {
|
|
311
|
+
return this.update({ opacity: Math.max(0, Math.min(1, opacity)) });
|
|
312
|
+
}
|
|
313
|
+
setLocked(locked) {
|
|
314
|
+
return this.update({ locked });
|
|
315
|
+
}
|
|
316
|
+
setHidden(hidden) {
|
|
317
|
+
return this.update({ hidden });
|
|
318
|
+
}
|
|
319
|
+
isVisible() {
|
|
320
|
+
return !Boolean(this._readRaw().hidden);
|
|
321
|
+
}
|
|
322
|
+
setVisible(visible) {
|
|
323
|
+
return this.setHidden(!visible);
|
|
324
|
+
}
|
|
325
|
+
_reorderZIndex(mode) {
|
|
326
|
+
this._commandService.syncExecuteCommand(ReorderPdfLayerCommand.id, {
|
|
327
|
+
unitId: this._pdfModel.getUnitId(),
|
|
328
|
+
pageId: this._pageId,
|
|
329
|
+
elementId: this._elementId,
|
|
330
|
+
mode
|
|
331
|
+
});
|
|
332
|
+
return this;
|
|
333
|
+
}
|
|
334
|
+
bringForward() {
|
|
335
|
+
return this._reorderZIndex("forward");
|
|
336
|
+
}
|
|
337
|
+
bringToFront() {
|
|
338
|
+
return this._reorderZIndex("front");
|
|
339
|
+
}
|
|
340
|
+
sendBackward() {
|
|
341
|
+
return this._reorderZIndex("backward");
|
|
342
|
+
}
|
|
343
|
+
sendToBack() {
|
|
344
|
+
return this._reorderZIndex("back");
|
|
345
|
+
}
|
|
346
|
+
update(patch) {
|
|
347
|
+
this._commandService.syncExecuteCommand(UpdatePdfElementsCommand.id, {
|
|
348
|
+
unitId: this._pdfModel.getUnitId(),
|
|
349
|
+
pageId: this._pageId,
|
|
350
|
+
updates: [{ id: this._elementId, patch }]
|
|
351
|
+
});
|
|
352
|
+
return this;
|
|
353
|
+
}
|
|
354
|
+
remove() {
|
|
355
|
+
return this._commandService.syncExecuteCommand(DeleteSelectedPdfElementsCommand.id, {
|
|
356
|
+
unitId: this._pdfModel.getUnitId(),
|
|
357
|
+
pageId: this._pageId,
|
|
358
|
+
elementIds: [this._elementId]
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
function paragraphBlocksToRichSpans(blocks) {
|
|
363
|
+
return blocks.map((b) => ({
|
|
364
|
+
text: b.text,
|
|
365
|
+
...b.style?.fontWeight === "bold" ? { bold: true } : {},
|
|
366
|
+
...b.style?.italic ? { italic: true } : {},
|
|
367
|
+
...b.style?.underline ? { underline: true } : {},
|
|
368
|
+
...b.style?.strikethrough ? { strikethrough: true } : {},
|
|
369
|
+
...b.style?.color ? { color: b.style.color } : {},
|
|
370
|
+
...b.style?.backgroundColor ? { backgroundColor: b.style.backgroundColor } : {},
|
|
371
|
+
...b.style?.fontSize !== void 0 ? { fontSize: b.style.fontSize } : {}
|
|
372
|
+
}));
|
|
373
|
+
}
|
|
374
|
+
var FPdfParagraph = class extends FPdfPageElement {
|
|
375
|
+
constructor(pdfModelOrTextBox, commandServiceOrIndex, pageId, elementId) {
|
|
376
|
+
if (pdfModelOrTextBox instanceof FPdfTextBox) {
|
|
377
|
+
super(
|
|
378
|
+
pdfModelOrTextBox._getInternalPdfModel(),
|
|
379
|
+
pdfModelOrTextBox._getInternalCommandService(),
|
|
380
|
+
pdfModelOrTextBox.getPageId(),
|
|
381
|
+
pdfModelOrTextBox.getId()
|
|
382
|
+
);
|
|
383
|
+
this._ownerTextBox = pdfModelOrTextBox;
|
|
384
|
+
this._paragraphIndex = typeof commandServiceOrIndex === "number" ? commandServiceOrIndex : 0;
|
|
385
|
+
} else {
|
|
386
|
+
super(
|
|
387
|
+
pdfModelOrTextBox,
|
|
388
|
+
commandServiceOrIndex,
|
|
389
|
+
pageId,
|
|
390
|
+
elementId
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
_readTextEl() {
|
|
395
|
+
const el = this._readRaw();
|
|
396
|
+
if (el.type !== PdfElementType2.TEXT) {
|
|
397
|
+
throw new Error(`[UniverPdfs] Element "${this._elementId}" is not a TEXT/PARAGRAPH element.`);
|
|
398
|
+
}
|
|
399
|
+
return el;
|
|
400
|
+
}
|
|
401
|
+
getIndex() {
|
|
402
|
+
return this._paragraphIndex ?? 0;
|
|
403
|
+
}
|
|
404
|
+
getTextBox() {
|
|
405
|
+
return this._ownerTextBox ?? new FPdfTextBox(this._pdfModel, this._commandService, this._pageId, this._elementId);
|
|
406
|
+
}
|
|
407
|
+
getText() {
|
|
408
|
+
if (this._paragraphIndex !== void 0) {
|
|
409
|
+
const lines = this.getTextBox().getText().split("\n");
|
|
410
|
+
return lines[this._paragraphIndex] ?? "";
|
|
411
|
+
}
|
|
412
|
+
return this._readTextEl().content ?? "";
|
|
413
|
+
}
|
|
414
|
+
setText(text) {
|
|
415
|
+
if (this._paragraphIndex !== void 0) {
|
|
416
|
+
const tb = this.getTextBox();
|
|
417
|
+
const lines = tb.getText().split("\n");
|
|
418
|
+
while (lines.length <= this._paragraphIndex) {
|
|
419
|
+
lines.push("");
|
|
420
|
+
}
|
|
421
|
+
lines[this._paragraphIndex] = text;
|
|
422
|
+
tb.setText(lines.join("\n"));
|
|
423
|
+
return this;
|
|
424
|
+
}
|
|
425
|
+
const cur = this._readTextEl();
|
|
426
|
+
const nextBlocks = [{ text, style: cur.style ? { ...cur.style } : void 0 }];
|
|
427
|
+
this._writeBlocks(nextBlocks);
|
|
428
|
+
return this;
|
|
429
|
+
}
|
|
430
|
+
appendText(text) {
|
|
431
|
+
return this.setText(`${this.getText()}${text}`);
|
|
432
|
+
}
|
|
433
|
+
getBlocks() {
|
|
434
|
+
const el = this._readTextEl();
|
|
435
|
+
const stored = el.metadata?.paragraphBlocks;
|
|
436
|
+
if (Array.isArray(stored) && stored.length > 0 && this._paragraphIndex === void 0) {
|
|
437
|
+
return Tools.deepClone(stored);
|
|
438
|
+
}
|
|
439
|
+
if (el.richSpans?.length && this._paragraphIndex === void 0) {
|
|
440
|
+
return el.richSpans.map((sp) => ({
|
|
441
|
+
text: sp.text,
|
|
442
|
+
style: {
|
|
443
|
+
...sp.bold ? { fontWeight: "bold" } : {},
|
|
444
|
+
...sp.italic ? { italic: true } : {},
|
|
445
|
+
...sp.underline ? { underline: true } : {},
|
|
446
|
+
...sp.strikethrough ? { strikethrough: true } : {},
|
|
447
|
+
...sp.color ? { color: sp.color } : {},
|
|
448
|
+
...sp.backgroundColor ? { backgroundColor: sp.backgroundColor } : {},
|
|
449
|
+
...sp.fontSize !== void 0 ? { fontSize: sp.fontSize } : {}
|
|
450
|
+
}
|
|
451
|
+
}));
|
|
452
|
+
}
|
|
453
|
+
const text = this.getText();
|
|
454
|
+
return text ? [{ text, style: el.style ? Tools.deepClone(el.style) : void 0 }] : [];
|
|
455
|
+
}
|
|
456
|
+
_writeBlocks(blocks) {
|
|
457
|
+
const el = this._readTextEl();
|
|
458
|
+
const content = blocks.map((b) => b.text).join("");
|
|
459
|
+
const hasCustomStyles = blocks.some((b) => b.style && Object.keys(b.style).length > 0);
|
|
460
|
+
return this.update({
|
|
461
|
+
content,
|
|
462
|
+
richSpans: hasCustomStyles ? paragraphBlocksToRichSpans(blocks) : void 0,
|
|
463
|
+
metadata: {
|
|
464
|
+
...el.metadata ?? {},
|
|
465
|
+
isParagraph: true,
|
|
466
|
+
paragraphBlocks: Tools.deepClone(blocks)
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
appendBlock(blockOrText, style) {
|
|
471
|
+
const blocks = this.getBlocks();
|
|
472
|
+
const block = typeof blockOrText === "string" ? { text: blockOrText, ...style ? { style: { ...style } } : {} } : { text: blockOrText.text, style: blockOrText.style ? { ...blockOrText.style } : void 0 };
|
|
473
|
+
blocks.push(block);
|
|
474
|
+
return this._writeBlocks(blocks);
|
|
475
|
+
}
|
|
476
|
+
insertBlock(index, blockOrText, style) {
|
|
477
|
+
const blocks = this.getBlocks();
|
|
478
|
+
const clamped = Math.max(0, Math.min(blocks.length, Math.floor(index)));
|
|
479
|
+
const block = typeof blockOrText === "string" ? { text: blockOrText, ...style ? { style: { ...style } } : {} } : { text: blockOrText.text, style: blockOrText.style ? { ...blockOrText.style } : void 0 };
|
|
480
|
+
blocks.splice(clamped, 0, block);
|
|
481
|
+
return this._writeBlocks(blocks);
|
|
482
|
+
}
|
|
483
|
+
removeBlock(index) {
|
|
484
|
+
const blocks = this.getBlocks();
|
|
485
|
+
if (index >= 0 && index < blocks.length) {
|
|
486
|
+
blocks.splice(index, 1);
|
|
487
|
+
this._writeBlocks(blocks);
|
|
488
|
+
}
|
|
489
|
+
return this;
|
|
490
|
+
}
|
|
491
|
+
setBlockText(index, text) {
|
|
492
|
+
const blocks = this.getBlocks();
|
|
493
|
+
if (index >= 0 && index < blocks.length) {
|
|
494
|
+
blocks[index] = { ...blocks[index], text };
|
|
495
|
+
this._writeBlocks(blocks);
|
|
496
|
+
}
|
|
497
|
+
return this;
|
|
498
|
+
}
|
|
499
|
+
setBlockStyle(index, style) {
|
|
500
|
+
const blocks = this.getBlocks();
|
|
501
|
+
if (index >= 0 && index < blocks.length) {
|
|
502
|
+
blocks[index] = {
|
|
503
|
+
...blocks[index],
|
|
504
|
+
style: { ...blocks[index].style ?? {}, ...style }
|
|
505
|
+
};
|
|
506
|
+
this._writeBlocks(blocks);
|
|
507
|
+
}
|
|
508
|
+
return this;
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
var FPdfTextSpan = class {
|
|
512
|
+
constructor(_pdfModel, _commandService, _pageId, _source) {
|
|
513
|
+
this._pdfModel = _pdfModel;
|
|
514
|
+
this._commandService = _commandService;
|
|
515
|
+
this._pageId = _pageId;
|
|
516
|
+
this._source = _source;
|
|
517
|
+
this._stale = false;
|
|
518
|
+
}
|
|
519
|
+
getId() {
|
|
520
|
+
if (this._source.kind === "native" && this._source.nativeSpan) {
|
|
521
|
+
return `${this._source.nativeSpan.id}:${this._source.startOffset}-${this._source.endOffset}`;
|
|
522
|
+
}
|
|
523
|
+
return `${this._source.elementId ?? "span"}:${this._source.startOffset}-${this._source.endOffset}`;
|
|
524
|
+
}
|
|
525
|
+
getPageId() {
|
|
526
|
+
return this._pageId;
|
|
527
|
+
}
|
|
528
|
+
getText() {
|
|
529
|
+
return this._source.matchedText;
|
|
530
|
+
}
|
|
531
|
+
getTextRuns() {
|
|
532
|
+
if (this._source.kind === "element" && this._source.elementId) {
|
|
533
|
+
const el = this._pdfModel.getElementsByPage(this._pageId)[this._source.elementId];
|
|
534
|
+
if (el && el.type === PdfElementType2.TEXT && el.richSpans?.length) {
|
|
535
|
+
const sliced = [];
|
|
536
|
+
let cursor = 0;
|
|
537
|
+
for (const sp of el.richSpans) {
|
|
538
|
+
const nextCursor = cursor + sp.text.length;
|
|
539
|
+
const overlapStart = Math.max(this._source.startOffset, cursor);
|
|
540
|
+
const overlapEnd = Math.min(this._source.endOffset, nextCursor);
|
|
541
|
+
if (overlapEnd > overlapStart) {
|
|
542
|
+
sliced.push({
|
|
543
|
+
...Tools.deepClone(sp),
|
|
544
|
+
text: sp.text.slice(overlapStart - cursor, overlapEnd - cursor)
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
cursor = nextCursor;
|
|
548
|
+
}
|
|
549
|
+
if (sliced.length > 0) return sliced;
|
|
550
|
+
}
|
|
551
|
+
if (el && el.type === PdfElementType2.TEXT) {
|
|
552
|
+
return [
|
|
553
|
+
{
|
|
554
|
+
text: this._source.matchedText,
|
|
555
|
+
bold: el.style?.fontWeight === "bold",
|
|
556
|
+
italic: el.style?.italic,
|
|
557
|
+
underline: el.style?.underline,
|
|
558
|
+
strikethrough: el.style?.strikethrough,
|
|
559
|
+
color: el.style?.color,
|
|
560
|
+
fontSize: el.style?.fontSize
|
|
561
|
+
}
|
|
562
|
+
];
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return [
|
|
566
|
+
{
|
|
567
|
+
text: this._source.matchedText,
|
|
568
|
+
...this._source.nativeSpan?.fontSize !== void 0 ? { fontSize: this._source.nativeSpan.fontSize } : {}
|
|
569
|
+
}
|
|
570
|
+
];
|
|
571
|
+
}
|
|
572
|
+
getStartOffset() {
|
|
573
|
+
return this._source.startOffset;
|
|
574
|
+
}
|
|
575
|
+
getEndOffset() {
|
|
576
|
+
return this._source.endOffset;
|
|
577
|
+
}
|
|
578
|
+
getBounds() {
|
|
579
|
+
return { ...this._source.bounds };
|
|
580
|
+
}
|
|
581
|
+
isStale() {
|
|
582
|
+
return this._stale || Boolean(this._source.siblingGroup?.invalidated);
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Replaces this text span with `replacement`, marks the span stale so it cannot be reused with
|
|
586
|
+
* outdated offsets, and returns the owning/promoted `FPdfTextBox`.
|
|
587
|
+
*/
|
|
588
|
+
replaceText(replacement) {
|
|
589
|
+
if (this.isStale()) {
|
|
590
|
+
throw new Error(
|
|
591
|
+
"[UniverPdfs] FPdfTextSpan is stale after a prior replaceText() mutation; re-query findText() before replacing again."
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
this._stale = true;
|
|
595
|
+
if (this._source.siblingGroup) {
|
|
596
|
+
this._source.siblingGroup.invalidated = true;
|
|
597
|
+
}
|
|
598
|
+
if (this._source.kind === "element" && this._source.elementId) {
|
|
599
|
+
const el = this._pdfModel.getElementsByPage(this._pageId)[this._source.elementId];
|
|
600
|
+
if (!el || el.type !== PdfElementType2.TEXT) {
|
|
601
|
+
throw new Error(`[UniverPdfs] Target TEXT element "${this._source.elementId}" not found.`);
|
|
602
|
+
}
|
|
603
|
+
const curContent = el.content ?? "";
|
|
604
|
+
const nextContent = curContent.slice(0, this._source.startOffset) + replacement + curContent.slice(this._source.endOffset);
|
|
605
|
+
this._commandService.syncExecuteCommand(UpdatePdfElementsCommand.id, {
|
|
606
|
+
unitId: this._pdfModel.getUnitId(),
|
|
607
|
+
pageId: this._pageId,
|
|
608
|
+
updates: [{ id: el.id, patch: { content: nextContent } }]
|
|
609
|
+
});
|
|
610
|
+
return new FPdfTextBox(this._pdfModel, this._commandService, this._pageId, el.id);
|
|
611
|
+
}
|
|
612
|
+
if (this._source.kind === "native" && this._source.nativeSpan) {
|
|
613
|
+
const span = this._source.nativeSpan;
|
|
614
|
+
const fullSpanText = span.text ?? "";
|
|
615
|
+
const nextSpanText = fullSpanText.slice(0, this._source.startOffset) + replacement + fullSpanText.slice(this._source.endOffset);
|
|
616
|
+
const beforeOrder = new Set(this._pdfModel.getElementOrderByPage(this._pageId));
|
|
617
|
+
this._commandService.syncExecuteCommand(ReplacePdfNativeTextCommand.id, {
|
|
618
|
+
unitId: this._pdfModel.getUnitId(),
|
|
619
|
+
pageId: this._pageId,
|
|
620
|
+
spanId: span.id,
|
|
621
|
+
newText: nextSpanText
|
|
622
|
+
});
|
|
623
|
+
const afterOrder = this._pdfModel.getElementOrderByPage(this._pageId);
|
|
624
|
+
const map = this._pdfModel.getElementsByPage(this._pageId);
|
|
625
|
+
let targetElementId = afterOrder.find((id) => !beforeOrder.has(id));
|
|
626
|
+
if (!targetElementId) {
|
|
627
|
+
const promoted = Object.values(map).find(
|
|
628
|
+
(e) => e.type === PdfElementType2.TEXT && e.metadata?.promotedFromNativeSpanId === span.id
|
|
629
|
+
);
|
|
630
|
+
targetElementId = promoted?.id;
|
|
631
|
+
}
|
|
632
|
+
if (!targetElementId) {
|
|
633
|
+
throw new Error(`[UniverPdfs] Failed to promote native text span "${span.id}" to FPdfTextBox.`);
|
|
634
|
+
}
|
|
635
|
+
return new FPdfTextBox(this._pdfModel, this._commandService, this._pageId, targetElementId);
|
|
636
|
+
}
|
|
637
|
+
throw new Error("[UniverPdfs] Invalid FPdfTextSpan source.");
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
var FPdfTextBox = class extends FPdfPageElement {
|
|
641
|
+
_readTextEl() {
|
|
642
|
+
const el = this._readRaw();
|
|
643
|
+
if (el.type !== PdfElementType2.TEXT) {
|
|
644
|
+
throw new Error(`[UniverPdfs] Element "${this._elementId}" is not a TEXT element.`);
|
|
645
|
+
}
|
|
646
|
+
return el;
|
|
647
|
+
}
|
|
648
|
+
getText() {
|
|
649
|
+
return this._readTextEl().content ?? "";
|
|
650
|
+
}
|
|
651
|
+
setText(content) {
|
|
652
|
+
return this.update({ content });
|
|
653
|
+
}
|
|
654
|
+
getStyle() {
|
|
655
|
+
return Tools.deepClone(this._readTextEl().style ?? {});
|
|
656
|
+
}
|
|
657
|
+
setStyle(stylePatch) {
|
|
658
|
+
const prev = this._readTextEl().style ?? {};
|
|
659
|
+
return this.update({
|
|
660
|
+
style: { ...prev, ...stylePatch }
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
getTextRuns() {
|
|
664
|
+
const el = this._readTextEl();
|
|
665
|
+
if (el.richSpans?.length) {
|
|
666
|
+
return Tools.deepClone(el.richSpans);
|
|
667
|
+
}
|
|
668
|
+
return [
|
|
669
|
+
{
|
|
670
|
+
text: el.content ?? "",
|
|
671
|
+
bold: el.style?.fontWeight === "bold",
|
|
672
|
+
italic: el.style?.italic,
|
|
673
|
+
underline: el.style?.underline,
|
|
674
|
+
strikethrough: el.style?.strikethrough,
|
|
675
|
+
color: el.style?.color,
|
|
676
|
+
backgroundColor: el.style?.backgroundColor,
|
|
677
|
+
fontSize: el.style?.fontSize
|
|
678
|
+
}
|
|
679
|
+
];
|
|
680
|
+
}
|
|
681
|
+
setTextStyle(styleOrStart, endOffset, rangeStyle) {
|
|
682
|
+
if (typeof styleOrStart !== "number") {
|
|
683
|
+
return this.setStyle(styleOrStart);
|
|
684
|
+
}
|
|
685
|
+
const el = this._readTextEl();
|
|
686
|
+
const content = el.content ?? "";
|
|
687
|
+
const start = Math.max(0, Math.min(content.length, Math.floor(styleOrStart)));
|
|
688
|
+
const end = Math.max(start, Math.min(content.length, Math.floor(endOffset ?? content.length)));
|
|
689
|
+
if (start >= end || !rangeStyle) return this;
|
|
690
|
+
const baseRuns = this.getTextRuns();
|
|
691
|
+
const nextRuns = [];
|
|
692
|
+
let cursor = 0;
|
|
693
|
+
const applyPatchToSpan = (sp) => ({
|
|
694
|
+
...sp,
|
|
695
|
+
...rangeStyle.fontWeight !== void 0 ? { bold: rangeStyle.fontWeight === "bold" } : {},
|
|
696
|
+
...rangeStyle.italic !== void 0 ? { italic: rangeStyle.italic } : {},
|
|
697
|
+
...rangeStyle.underline !== void 0 ? { underline: rangeStyle.underline } : {},
|
|
698
|
+
...rangeStyle.strikethrough !== void 0 ? { strikethrough: rangeStyle.strikethrough } : {},
|
|
699
|
+
...rangeStyle.color !== void 0 ? { color: rangeStyle.color } : {},
|
|
700
|
+
...rangeStyle.backgroundColor !== void 0 ? { backgroundColor: rangeStyle.backgroundColor } : {},
|
|
701
|
+
...rangeStyle.fontSize !== void 0 ? { fontSize: rangeStyle.fontSize } : {}
|
|
702
|
+
});
|
|
703
|
+
for (const run of baseRuns) {
|
|
704
|
+
const runLen = run.text.length;
|
|
705
|
+
const runEnd = cursor + runLen;
|
|
706
|
+
if (runEnd <= start || cursor >= end) {
|
|
707
|
+
if (run.text) nextRuns.push(run);
|
|
708
|
+
} else {
|
|
709
|
+
if (cursor < start) {
|
|
710
|
+
nextRuns.push({ ...run, text: run.text.slice(0, start - cursor) });
|
|
711
|
+
}
|
|
712
|
+
const midStart = Math.max(cursor, start) - cursor;
|
|
713
|
+
const midEnd = Math.min(runEnd, end) - cursor;
|
|
714
|
+
if (midEnd > midStart) {
|
|
715
|
+
nextRuns.push(applyPatchToSpan({ ...run, text: run.text.slice(midStart, midEnd) }));
|
|
716
|
+
}
|
|
717
|
+
if (runEnd > end) {
|
|
718
|
+
nextRuns.push({ ...run, text: run.text.slice(end - cursor) });
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
cursor = runEnd;
|
|
722
|
+
}
|
|
723
|
+
return this.update({ richSpans: nextRuns });
|
|
724
|
+
}
|
|
725
|
+
setFontSize(fontSize) {
|
|
726
|
+
return this.setStyle({ fontSize: Math.max(4, fontSize) });
|
|
727
|
+
}
|
|
728
|
+
setFontFamily(fontFamily) {
|
|
729
|
+
return this.setStyle({ fontFamily });
|
|
730
|
+
}
|
|
731
|
+
setColor(color) {
|
|
732
|
+
return this.setStyle({ color });
|
|
733
|
+
}
|
|
734
|
+
setBold(bold) {
|
|
735
|
+
return this.setStyle({ fontWeight: bold ? "bold" : "normal" });
|
|
736
|
+
}
|
|
737
|
+
setItalic(italic) {
|
|
738
|
+
return this.setStyle({ italic });
|
|
739
|
+
}
|
|
740
|
+
setUnderline(underline) {
|
|
741
|
+
return this.setStyle({ underline });
|
|
742
|
+
}
|
|
743
|
+
setStrikethrough(strikethrough) {
|
|
744
|
+
return this.setStyle({ strikethrough });
|
|
745
|
+
}
|
|
746
|
+
setCharacterSpacing(characterSpacing) {
|
|
747
|
+
return this.setStyle({ characterSpacing });
|
|
748
|
+
}
|
|
749
|
+
setTextAlign(textAlign) {
|
|
750
|
+
return this.setStyle({ textAlign });
|
|
751
|
+
}
|
|
752
|
+
getDynamicFontSize() {
|
|
753
|
+
const cfg = this._readTextEl().dynamicFontSize;
|
|
754
|
+
return cfg ? Tools.deepClone(cfg) : void 0;
|
|
755
|
+
}
|
|
756
|
+
setDynamicFontSize(config) {
|
|
757
|
+
return this.update({
|
|
758
|
+
dynamicFontSize: config ? Tools.deepClone(config) : void 0
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
getAnchor() {
|
|
762
|
+
return this._readTextEl().anchor;
|
|
763
|
+
}
|
|
764
|
+
setAnchor(anchor) {
|
|
765
|
+
const verticalMap = {
|
|
766
|
+
top: "top",
|
|
767
|
+
center: "middle",
|
|
768
|
+
bottom: "bottom",
|
|
769
|
+
"top-left": "top",
|
|
770
|
+
"top-center": "top",
|
|
771
|
+
"top-right": "top",
|
|
772
|
+
"middle-left": "middle",
|
|
773
|
+
"middle-center": "middle",
|
|
774
|
+
"middle-right": "middle",
|
|
775
|
+
"bottom-left": "bottom",
|
|
776
|
+
"bottom-center": "bottom",
|
|
777
|
+
"bottom-right": "bottom"
|
|
778
|
+
};
|
|
779
|
+
const horizontalMap = {
|
|
780
|
+
"top-left": "left",
|
|
781
|
+
"middle-left": "left",
|
|
782
|
+
"bottom-left": "left",
|
|
783
|
+
"top-center": "center",
|
|
784
|
+
"middle-center": "center",
|
|
785
|
+
"bottom-center": "center",
|
|
786
|
+
"top-right": "right",
|
|
787
|
+
"middle-right": "right",
|
|
788
|
+
"bottom-right": "right"
|
|
789
|
+
};
|
|
790
|
+
const prevStyle = this._readTextEl().style ?? {};
|
|
791
|
+
return this.update({
|
|
792
|
+
anchor,
|
|
793
|
+
style: {
|
|
794
|
+
...prevStyle,
|
|
795
|
+
verticalAlign: verticalMap[anchor] ?? prevStyle.verticalAlign,
|
|
796
|
+
...horizontalMap[anchor] ? { textAlign: horizontalMap[anchor] } : {}
|
|
797
|
+
}
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
getTextAnchor() {
|
|
801
|
+
return this.getAnchor();
|
|
802
|
+
}
|
|
803
|
+
setTextAnchor(anchor) {
|
|
804
|
+
return this.setAnchor(anchor);
|
|
805
|
+
}
|
|
806
|
+
getTextFormat() {
|
|
807
|
+
return this._readTextEl().textFormat ?? "plain";
|
|
808
|
+
}
|
|
809
|
+
setTextFormat(textFormat) {
|
|
810
|
+
return this.update({ textFormat });
|
|
811
|
+
}
|
|
812
|
+
getParagraphs() {
|
|
813
|
+
const lines = this.getText().split("\n");
|
|
814
|
+
return lines.map((_, idx) => new FPdfParagraph(this, idx));
|
|
815
|
+
}
|
|
816
|
+
insertParagraph(text, index) {
|
|
817
|
+
const cur = this.getText();
|
|
818
|
+
const lines = cur === "" ? [] : cur.split("\n");
|
|
819
|
+
const targetIdx = index === void 0 ? lines.length : Math.max(0, Math.min(lines.length, Math.floor(index)));
|
|
820
|
+
lines.splice(targetIdx, 0, text);
|
|
821
|
+
this.setText(lines.join("\n"));
|
|
822
|
+
return new FPdfParagraph(this, targetIdx);
|
|
823
|
+
}
|
|
824
|
+
findText(query) {
|
|
825
|
+
if (!query) return [];
|
|
826
|
+
const textEl = this._readTextEl();
|
|
827
|
+
const content = textEl.content ?? "";
|
|
828
|
+
const spans = [];
|
|
829
|
+
const siblingGroup = { invalidated: false };
|
|
830
|
+
let searchFrom = 0;
|
|
831
|
+
while (searchFrom <= content.length - query.length) {
|
|
832
|
+
const idx = content.indexOf(query, searchFrom);
|
|
833
|
+
if (idx < 0) break;
|
|
834
|
+
spans.push(
|
|
835
|
+
new FPdfTextSpan(this._pdfModel, this._commandService, this._pageId, {
|
|
836
|
+
kind: "element",
|
|
837
|
+
elementId: textEl.id,
|
|
838
|
+
startOffset: idx,
|
|
839
|
+
endOffset: idx + query.length,
|
|
840
|
+
matchedText: query,
|
|
841
|
+
bounds: {
|
|
842
|
+
left: textEl.transform.left,
|
|
843
|
+
top: textEl.transform.top,
|
|
844
|
+
width: textEl.transform.width,
|
|
845
|
+
height: textEl.transform.height
|
|
846
|
+
},
|
|
847
|
+
siblingGroup
|
|
848
|
+
})
|
|
849
|
+
);
|
|
850
|
+
searchFrom = idx + Math.max(1, query.length);
|
|
851
|
+
}
|
|
852
|
+
return spans;
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
var FPdfList = class extends FPdfPageElement {
|
|
856
|
+
_readListEl() {
|
|
857
|
+
const el = this._readRaw();
|
|
858
|
+
if (el.type !== PdfElementType2.LIST) {
|
|
859
|
+
throw new Error(`[UniverPdfs] Element "${this._elementId}" is not a LIST element.`);
|
|
860
|
+
}
|
|
861
|
+
return el;
|
|
862
|
+
}
|
|
863
|
+
getItems() {
|
|
864
|
+
return [...this._readListEl().items ?? []];
|
|
865
|
+
}
|
|
866
|
+
setItems(items) {
|
|
867
|
+
return this.update({ items: [...items] });
|
|
868
|
+
}
|
|
869
|
+
addItem(item, index) {
|
|
870
|
+
return this.insertItem(item, index, 0);
|
|
871
|
+
}
|
|
872
|
+
insertItem(textOrIndex, indexOrText, levelArg = 0) {
|
|
873
|
+
const el = this._readListEl();
|
|
874
|
+
const items = [...el.items ?? []];
|
|
875
|
+
const levels = Array.from(
|
|
876
|
+
{ length: items.length },
|
|
877
|
+
(_, i) => Math.max(0, Math.min(8, Math.floor(el.itemLevels?.[i] ?? 0)))
|
|
878
|
+
);
|
|
879
|
+
const clampedLevel = Math.max(0, Math.min(8, Math.floor(levelArg)));
|
|
880
|
+
let insertIdx;
|
|
881
|
+
let itemText;
|
|
882
|
+
if (typeof textOrIndex === "number") {
|
|
883
|
+
insertIdx = Math.max(0, Math.min(items.length, Math.floor(textOrIndex)));
|
|
884
|
+
itemText = String(indexOrText ?? "");
|
|
885
|
+
} else {
|
|
886
|
+
itemText = textOrIndex;
|
|
887
|
+
insertIdx = typeof indexOrText === "number" ? Math.max(0, Math.min(items.length, Math.floor(indexOrText))) : items.length;
|
|
888
|
+
}
|
|
889
|
+
items.splice(insertIdx, 0, itemText);
|
|
890
|
+
levels.splice(insertIdx, 0, clampedLevel);
|
|
891
|
+
return this.update({
|
|
892
|
+
items,
|
|
893
|
+
itemLevels: levels
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
getItemLevel(index) {
|
|
897
|
+
const el = this._readListEl();
|
|
898
|
+
return Math.max(0, Math.min(8, Math.floor(el.itemLevels?.[index] ?? 0)));
|
|
899
|
+
}
|
|
900
|
+
changeItemLevel(index, level) {
|
|
901
|
+
const el = this._readListEl();
|
|
902
|
+
const items = el.items ?? [];
|
|
903
|
+
if (index < 0 || index >= items.length) return this;
|
|
904
|
+
const levels = Array.from(
|
|
905
|
+
{ length: items.length },
|
|
906
|
+
(_, i) => Math.max(0, Math.min(8, Math.floor(el.itemLevels?.[i] ?? 0)))
|
|
907
|
+
);
|
|
908
|
+
levels[index] = Math.max(0, Math.min(8, Math.floor(level)));
|
|
909
|
+
return this.update({ itemLevels: levels });
|
|
910
|
+
}
|
|
911
|
+
setItemText(index, text) {
|
|
912
|
+
const items = this.getItems();
|
|
913
|
+
if (index >= 0 && index < items.length) {
|
|
914
|
+
items[index] = text;
|
|
915
|
+
this.setItems(items);
|
|
916
|
+
}
|
|
917
|
+
return this;
|
|
918
|
+
}
|
|
919
|
+
removeItem(index) {
|
|
920
|
+
const el = this._readListEl();
|
|
921
|
+
const next = [...el.items ?? []];
|
|
922
|
+
if (index >= 0 && index < next.length) {
|
|
923
|
+
const levels = Array.from(
|
|
924
|
+
{ length: next.length },
|
|
925
|
+
(_, i) => Math.max(0, Math.min(8, Math.floor(el.itemLevels?.[i] ?? 0)))
|
|
926
|
+
);
|
|
927
|
+
next.splice(index, 1);
|
|
928
|
+
levels.splice(index, 1);
|
|
929
|
+
this.update({ items: next, itemLevels: levels });
|
|
930
|
+
}
|
|
931
|
+
return this;
|
|
932
|
+
}
|
|
933
|
+
getStartNumber() {
|
|
934
|
+
return Math.max(1, Math.floor(this._readListEl().startNumber ?? 1));
|
|
935
|
+
}
|
|
936
|
+
setStartNumber(startNumber) {
|
|
937
|
+
return this.update({
|
|
938
|
+
startNumber: Math.max(1, Math.floor(startNumber))
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
getKind() {
|
|
942
|
+
const lt = this._readListEl().listType;
|
|
943
|
+
if (lt === "ordered") return PdfListKind2.ORDERED;
|
|
944
|
+
if (lt === "check") return PdfListKind2.CHECK;
|
|
945
|
+
return PdfListKind2.BULLET;
|
|
946
|
+
}
|
|
947
|
+
setKind(kind) {
|
|
948
|
+
return this.update({ listType: kind });
|
|
949
|
+
}
|
|
950
|
+
getPresetId() {
|
|
951
|
+
return this._readListEl().presetId;
|
|
952
|
+
}
|
|
953
|
+
setPreset(presetId) {
|
|
954
|
+
const impliedType = presetId === "decimal" || presetId === "upper-alpha" || presetId === "lower-alpha" || presetId === "upper-roman" || presetId === "lower-roman" ? "ordered" : presetId === "checklist" ? "check" : "bullet";
|
|
955
|
+
return this.update({
|
|
956
|
+
presetId,
|
|
957
|
+
listType: impliedType
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
var FPdfTableCell = class {
|
|
962
|
+
constructor(_table, _rowIndex, _colIndex) {
|
|
963
|
+
this._table = _table;
|
|
964
|
+
this._rowIndex = _rowIndex;
|
|
965
|
+
this._colIndex = _colIndex;
|
|
966
|
+
}
|
|
967
|
+
getTable() {
|
|
968
|
+
return this._table;
|
|
969
|
+
}
|
|
970
|
+
getRowIndex() {
|
|
971
|
+
return this._rowIndex;
|
|
972
|
+
}
|
|
973
|
+
getColIndex() {
|
|
974
|
+
return this._colIndex;
|
|
975
|
+
}
|
|
976
|
+
getValue() {
|
|
977
|
+
const rows = this._table.getRows();
|
|
978
|
+
return rows[this._rowIndex]?.[this._colIndex];
|
|
979
|
+
}
|
|
980
|
+
getText() {
|
|
981
|
+
const cols = this._table.getColumns();
|
|
982
|
+
const col = cols[this._colIndex];
|
|
983
|
+
const raw = this.getValue();
|
|
984
|
+
return col ? formatPdfTableCell(raw, col) : String(raw ?? "");
|
|
985
|
+
}
|
|
986
|
+
setValue(value) {
|
|
987
|
+
const rows = this._table.getRows().map((r) => [...r]);
|
|
988
|
+
const colCount = Math.max(1, this._table.getColumnCount());
|
|
989
|
+
while (rows.length <= this._rowIndex) {
|
|
990
|
+
rows.push(new Array(colCount).fill(""));
|
|
991
|
+
}
|
|
992
|
+
while (rows[this._rowIndex].length <= this._colIndex) {
|
|
993
|
+
rows[this._rowIndex].push("");
|
|
994
|
+
}
|
|
995
|
+
rows[this._rowIndex][this._colIndex] = value;
|
|
996
|
+
this._table.update({ rows });
|
|
997
|
+
return this;
|
|
998
|
+
}
|
|
999
|
+
setText(text) {
|
|
1000
|
+
return this.setValue(text);
|
|
1001
|
+
}
|
|
1002
|
+
getStyle() {
|
|
1003
|
+
const key = `${this._rowIndex}:${this._colIndex}`;
|
|
1004
|
+
const raw = this._table.getData();
|
|
1005
|
+
return Tools.deepClone(raw.cellStyles?.[key] ?? {});
|
|
1006
|
+
}
|
|
1007
|
+
setStyle(style) {
|
|
1008
|
+
const key = `${this._rowIndex}:${this._colIndex}`;
|
|
1009
|
+
const raw = this._table.getData();
|
|
1010
|
+
const prevCellStyles = raw.cellStyles ?? {};
|
|
1011
|
+
const mergedCellStyle = {
|
|
1012
|
+
...prevCellStyles[key] ?? {},
|
|
1013
|
+
...style
|
|
1014
|
+
};
|
|
1015
|
+
const nextMeta = style.verticalAlign !== void 0 ? {
|
|
1016
|
+
...raw.metadata ?? {},
|
|
1017
|
+
cellVerticalAligns: {
|
|
1018
|
+
...raw.metadata?.cellVerticalAligns ?? {},
|
|
1019
|
+
[key]: style.verticalAlign
|
|
1020
|
+
}
|
|
1021
|
+
} : raw.metadata;
|
|
1022
|
+
this._table.update({
|
|
1023
|
+
cellStyles: {
|
|
1024
|
+
...prevCellStyles,
|
|
1025
|
+
[key]: mergedCellStyle
|
|
1026
|
+
},
|
|
1027
|
+
...nextMeta ? { metadata: nextMeta } : {}
|
|
1028
|
+
});
|
|
1029
|
+
return this;
|
|
1030
|
+
}
|
|
1031
|
+
getVerticalAlign() {
|
|
1032
|
+
const key = `${this._rowIndex}:${this._colIndex}`;
|
|
1033
|
+
const raw = this._table.getData();
|
|
1034
|
+
if (raw.cellStyles?.[key]?.verticalAlign) {
|
|
1035
|
+
return raw.cellStyles[key].verticalAlign;
|
|
1036
|
+
}
|
|
1037
|
+
const cellAligns = raw.metadata?.cellVerticalAligns ?? {};
|
|
1038
|
+
if (cellAligns[key]) return cellAligns[key];
|
|
1039
|
+
const col = this._table.getColumns()[this._colIndex];
|
|
1040
|
+
return col?.verticalAlign ?? PdfTableCellVerticalAlign2.MIDDLE;
|
|
1041
|
+
}
|
|
1042
|
+
setVerticalAlign(align) {
|
|
1043
|
+
const key = `${this._rowIndex}:${this._colIndex}`;
|
|
1044
|
+
const raw = this._table.getData();
|
|
1045
|
+
const prevAligns = raw.metadata?.cellVerticalAligns ?? {};
|
|
1046
|
+
const prevCellStyles = raw.cellStyles ?? {};
|
|
1047
|
+
this._table.update({
|
|
1048
|
+
cellStyles: {
|
|
1049
|
+
...prevCellStyles,
|
|
1050
|
+
[key]: {
|
|
1051
|
+
...prevCellStyles[key] ?? {},
|
|
1052
|
+
verticalAlign: align
|
|
1053
|
+
}
|
|
1054
|
+
},
|
|
1055
|
+
metadata: {
|
|
1056
|
+
...raw.metadata ?? {},
|
|
1057
|
+
cellVerticalAligns: {
|
|
1058
|
+
...prevAligns,
|
|
1059
|
+
[key]: align
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
return this;
|
|
1064
|
+
}
|
|
1065
|
+
};
|
|
1066
|
+
var FPdfTable = class extends FPdfPageElement {
|
|
1067
|
+
_readTableEl() {
|
|
1068
|
+
const el = this._readRaw();
|
|
1069
|
+
if (el.type !== PdfElementType2.TABLE) {
|
|
1070
|
+
throw new Error(`[UniverPdfs] Element "${this._elementId}" is not a TABLE element.`);
|
|
1071
|
+
}
|
|
1072
|
+
return el;
|
|
1073
|
+
}
|
|
1074
|
+
getRowCount() {
|
|
1075
|
+
return (this._readTableEl().rows ?? []).length;
|
|
1076
|
+
}
|
|
1077
|
+
getColumnCount() {
|
|
1078
|
+
return (this._readTableEl().columns ?? []).length;
|
|
1079
|
+
}
|
|
1080
|
+
getColumns() {
|
|
1081
|
+
return Tools.deepClone(this._readTableEl().columns ?? []);
|
|
1082
|
+
}
|
|
1083
|
+
getRows() {
|
|
1084
|
+
return Tools.deepClone(this._readTableEl().rows ?? []);
|
|
1085
|
+
}
|
|
1086
|
+
getCell(rowIndex, colIndex) {
|
|
1087
|
+
return new FPdfTableCell(this, rowIndex, colIndex);
|
|
1088
|
+
}
|
|
1089
|
+
addRow(cells, index) {
|
|
1090
|
+
const colCount = Math.max(1, this.getColumnCount());
|
|
1091
|
+
const normalized = Array.from({ length: colCount }, (_, idx) => cells?.[idx] ?? "");
|
|
1092
|
+
const nextRows = this.getRows();
|
|
1093
|
+
if (index === void 0) {
|
|
1094
|
+
nextRows.push(normalized);
|
|
1095
|
+
} else {
|
|
1096
|
+
nextRows.splice(Math.max(0, Math.min(nextRows.length, Math.floor(index))), 0, normalized);
|
|
1097
|
+
}
|
|
1098
|
+
const cur = this._readTableEl();
|
|
1099
|
+
const headH = cur.showHead === false ? 0 : cur.headerHeight ?? 26;
|
|
1100
|
+
const nextH = headH + nextRows.length * (cur.rowHeight ?? 24);
|
|
1101
|
+
return this.update({
|
|
1102
|
+
rows: nextRows,
|
|
1103
|
+
transform: {
|
|
1104
|
+
...cur.transform,
|
|
1105
|
+
height: Math.max(cur.transform.height, nextH)
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
removeRow(rowIndex) {
|
|
1110
|
+
const nextRows = this.getRows();
|
|
1111
|
+
if (rowIndex >= 0 && rowIndex < nextRows.length) {
|
|
1112
|
+
nextRows.splice(rowIndex, 1);
|
|
1113
|
+
this.update({ rows: nextRows });
|
|
1114
|
+
}
|
|
1115
|
+
return this;
|
|
1116
|
+
}
|
|
1117
|
+
addColumn(column, index) {
|
|
1118
|
+
const cols = this.getColumns();
|
|
1119
|
+
const built = {
|
|
1120
|
+
id: column.id || `col-${generateRandomId(5)}`,
|
|
1121
|
+
header: column.header,
|
|
1122
|
+
field: column.field || `col_${cols.length + 1}`,
|
|
1123
|
+
widthRatio: column.widthRatio ?? 1,
|
|
1124
|
+
align: column.align,
|
|
1125
|
+
verticalAlign: column.verticalAlign,
|
|
1126
|
+
format: column.format,
|
|
1127
|
+
currencySymbol: column.currencySymbol,
|
|
1128
|
+
decimals: column.decimals,
|
|
1129
|
+
summaryType: column.summaryType
|
|
1130
|
+
};
|
|
1131
|
+
const insertIdx = index === void 0 ? cols.length : Math.max(0, Math.min(cols.length, Math.floor(index)));
|
|
1132
|
+
cols.splice(insertIdx, 0, built);
|
|
1133
|
+
const rows = this.getRows().map((r) => {
|
|
1134
|
+
const copy = [...r];
|
|
1135
|
+
copy.splice(insertIdx, 0, "");
|
|
1136
|
+
return copy;
|
|
1137
|
+
});
|
|
1138
|
+
return this.update({ columns: cols, rows });
|
|
1139
|
+
}
|
|
1140
|
+
removeColumn(colIndex) {
|
|
1141
|
+
const cols = this.getColumns();
|
|
1142
|
+
if (colIndex < 0 || colIndex >= cols.length || cols.length <= 1) return this;
|
|
1143
|
+
cols.splice(colIndex, 1);
|
|
1144
|
+
const rows = this.getRows().map((r) => r.filter((_, i) => i !== colIndex));
|
|
1145
|
+
return this.update({ columns: cols, rows });
|
|
1146
|
+
}
|
|
1147
|
+
resize(rowCount, colCount) {
|
|
1148
|
+
const targetRows = Math.max(1, Math.floor(rowCount));
|
|
1149
|
+
const targetCols = Math.max(1, Math.floor(colCount));
|
|
1150
|
+
const cur = this._readTableEl();
|
|
1151
|
+
const cols = this.getColumns();
|
|
1152
|
+
while (cols.length < targetCols) {
|
|
1153
|
+
const idx = cols.length + 1;
|
|
1154
|
+
cols.push({
|
|
1155
|
+
id: `col-${generateRandomId(5)}`,
|
|
1156
|
+
header: `Column ${idx}`,
|
|
1157
|
+
field: `col_${idx}`,
|
|
1158
|
+
widthRatio: 1
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
if (cols.length > targetCols) {
|
|
1162
|
+
cols.length = targetCols;
|
|
1163
|
+
}
|
|
1164
|
+
const prevRows = this.getRows();
|
|
1165
|
+
const nextRows = Array.from(
|
|
1166
|
+
{ length: targetRows },
|
|
1167
|
+
(_, rIdx) => Array.from({ length: targetCols }, (__, cIdx) => String(prevRows[rIdx]?.[cIdx] ?? ""))
|
|
1168
|
+
);
|
|
1169
|
+
const headH = cur.showHead === false ? 0 : cur.headerHeight ?? 26;
|
|
1170
|
+
const nextH = headH + targetRows * (cur.rowHeight ?? 24);
|
|
1171
|
+
return this.update({
|
|
1172
|
+
columns: cols,
|
|
1173
|
+
rows: nextRows,
|
|
1174
|
+
transform: {
|
|
1175
|
+
...cur.transform,
|
|
1176
|
+
height: Math.max(24, nextH)
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
getTheme() {
|
|
1181
|
+
return this._readTableEl().metadata?.themePresetId;
|
|
1182
|
+
}
|
|
1183
|
+
setTheme(presetOrId) {
|
|
1184
|
+
return this.applyThemePreset(presetOrId);
|
|
1185
|
+
}
|
|
1186
|
+
getStyle() {
|
|
1187
|
+
const cur = this._readTableEl();
|
|
1188
|
+
return Tools.deepClone({
|
|
1189
|
+
showHead: cur.showHead !== false,
|
|
1190
|
+
borderColor: cur.borderColor,
|
|
1191
|
+
borderWidth: cur.borderWidth,
|
|
1192
|
+
borderStyle: cur.borderStyle,
|
|
1193
|
+
borderWidths: cur.borderWidths,
|
|
1194
|
+
zebraStripeColor: cur.zebraStripeColor ?? cur.stripedColor,
|
|
1195
|
+
headerStyle: cur.headerStyle,
|
|
1196
|
+
bodyStyle: cur.bodyStyle
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
setStyle(style) {
|
|
1200
|
+
const cur = this._readTableEl();
|
|
1201
|
+
return this.update({
|
|
1202
|
+
...style.showHead !== void 0 ? { showHead: style.showHead } : {},
|
|
1203
|
+
...style.borderColor !== void 0 ? { borderColor: style.borderColor } : {},
|
|
1204
|
+
...style.borderWidth !== void 0 ? { borderWidth: style.borderWidth } : {},
|
|
1205
|
+
...style.borderStyle !== void 0 ? { borderStyle: style.borderStyle } : {},
|
|
1206
|
+
...style.borderWidths !== void 0 ? { borderWidths: style.borderWidths } : {},
|
|
1207
|
+
...style.zebraStripeColor !== void 0 ? { zebraStripeColor: style.zebraStripeColor, stripedColor: style.zebraStripeColor } : {},
|
|
1208
|
+
...style.headerStyle !== void 0 ? { headerStyle: { ...cur.headerStyle ?? {}, ...style.headerStyle } } : {},
|
|
1209
|
+
...style.bodyStyle !== void 0 ? { bodyStyle: { ...cur.bodyStyle ?? {}, ...style.bodyStyle } } : {}
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
getMerges() {
|
|
1213
|
+
return Tools.deepClone(this._readTableEl().merges ?? []);
|
|
1214
|
+
}
|
|
1215
|
+
mergeCells(row, col, rowSpan, colSpan) {
|
|
1216
|
+
const cur = this._readTableEl();
|
|
1217
|
+
const r = Math.max(0, Math.floor(row));
|
|
1218
|
+
const c = Math.max(0, Math.floor(col));
|
|
1219
|
+
const rs = Math.max(1, Math.floor(rowSpan));
|
|
1220
|
+
const cs = Math.max(1, Math.floor(colSpan));
|
|
1221
|
+
if (rs <= 1 && cs <= 1) return this;
|
|
1222
|
+
const filtered = (cur.merges ?? []).filter((m) => !(m.row === r && m.col === c));
|
|
1223
|
+
filtered.push({ row: r, col: c, rowSpan: rs, colSpan: cs });
|
|
1224
|
+
return this.update({ merges: filtered });
|
|
1225
|
+
}
|
|
1226
|
+
applyThemePreset(presetOrId) {
|
|
1227
|
+
const preset = typeof presetOrId === "string" ? PDF_TABLE_THEME_PRESETS.find((p) => p.id === presetOrId) : presetOrId;
|
|
1228
|
+
if (!preset) {
|
|
1229
|
+
throw new Error(`[UniverPdfs] Unknown PDF table theme preset "${String(presetOrId)}".`);
|
|
1230
|
+
}
|
|
1231
|
+
const cur = this._readTableEl();
|
|
1232
|
+
return this.update({
|
|
1233
|
+
borderColor: preset.borderColor,
|
|
1234
|
+
borderWidth: preset.borderWidth,
|
|
1235
|
+
zebraStripeColor: preset.zebraStripeColor,
|
|
1236
|
+
stripedColor: preset.zebraStripeColor,
|
|
1237
|
+
headerStyle: {
|
|
1238
|
+
...cur.headerStyle ?? {},
|
|
1239
|
+
backgroundColor: preset.headerBackgroundColor,
|
|
1240
|
+
color: preset.headerTextColor,
|
|
1241
|
+
fontWeight: "bold"
|
|
1242
|
+
},
|
|
1243
|
+
bodyStyle: {
|
|
1244
|
+
...cur.bodyStyle ?? {},
|
|
1245
|
+
backgroundColor: preset.bodyBackgroundColor,
|
|
1246
|
+
color: preset.bodyTextColor
|
|
1247
|
+
},
|
|
1248
|
+
metadata: {
|
|
1249
|
+
...cur.metadata ?? {},
|
|
1250
|
+
themePresetId: preset.id
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
setAvoidOrphanHeader(avoidOrphanHeader) {
|
|
1255
|
+
return this.update({ avoidOrphanHeader });
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
var FPdfImage = class extends FPdfPageElement {
|
|
1259
|
+
_readImageEl() {
|
|
1260
|
+
const el = this._readRaw();
|
|
1261
|
+
if (el.type !== PdfElementType2.IMAGE) {
|
|
1262
|
+
throw new Error(`[UniverPdfs] Element "${this._elementId}" is not an IMAGE element.`);
|
|
1263
|
+
}
|
|
1264
|
+
return el;
|
|
1265
|
+
}
|
|
1266
|
+
getSrc() {
|
|
1267
|
+
return this._readImageEl().src ?? "";
|
|
1268
|
+
}
|
|
1269
|
+
setSrc(src) {
|
|
1270
|
+
return this.update({ src });
|
|
1271
|
+
}
|
|
1272
|
+
getSource() {
|
|
1273
|
+
const el = this._readImageEl();
|
|
1274
|
+
return el.src || el.resourceId || "";
|
|
1275
|
+
}
|
|
1276
|
+
setSource(srcOrBytes, mimeType) {
|
|
1277
|
+
if (typeof srcOrBytes === "string") {
|
|
1278
|
+
return this.update({ src: srcOrBytes });
|
|
1279
|
+
}
|
|
1280
|
+
const detectedMime = mimeType ?? (srcOrBytes.length >= 4 && srcOrBytes[0] === 137 && srcOrBytes[1] === 80 ? "image/png" : "image/jpeg");
|
|
1281
|
+
return this.update({
|
|
1282
|
+
src: `data:${detectedMime};base64,${encodeUint8ToBase64(srcOrBytes)}`
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
getImageSourceType() {
|
|
1286
|
+
const el = this._readImageEl();
|
|
1287
|
+
if (el.src?.startsWith("data:")) return PdfImageSourceType2.DATA_URI;
|
|
1288
|
+
if (el.src) return PdfImageSourceType2.URL;
|
|
1289
|
+
if (el.resourceId) return PdfImageSourceType2.RESOURCE;
|
|
1290
|
+
return PdfImageSourceType2.EMPTY;
|
|
1291
|
+
}
|
|
1292
|
+
getOpacity() {
|
|
1293
|
+
return this._readImageEl().opacity ?? 1;
|
|
1294
|
+
}
|
|
1295
|
+
getCrop() {
|
|
1296
|
+
const crop = this._readImageEl().crop;
|
|
1297
|
+
return crop ? Tools.deepClone(crop) : void 0;
|
|
1298
|
+
}
|
|
1299
|
+
setCrop(crop) {
|
|
1300
|
+
return this.update({
|
|
1301
|
+
crop: crop ? normalizeImageCrop(crop) : void 0
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
getFit() {
|
|
1305
|
+
return this._readImageEl().fit ?? "contain";
|
|
1306
|
+
}
|
|
1307
|
+
setFit(fit) {
|
|
1308
|
+
return this.update({ fit });
|
|
1309
|
+
}
|
|
1310
|
+
getObjectPosition() {
|
|
1311
|
+
return this._readImageEl().objectPosition ?? "center";
|
|
1312
|
+
}
|
|
1313
|
+
setObjectPosition(objectPosition) {
|
|
1314
|
+
return this.update({ objectPosition });
|
|
1315
|
+
}
|
|
1316
|
+
getAltText() {
|
|
1317
|
+
return this._readImageEl().altText;
|
|
1318
|
+
}
|
|
1319
|
+
setAltText(altText) {
|
|
1320
|
+
return this.update({ altText });
|
|
1321
|
+
}
|
|
1322
|
+
toBuilder() {
|
|
1323
|
+
return new FPdfImageBuilder(
|
|
1324
|
+
this._pdfModel,
|
|
1325
|
+
this._commandService,
|
|
1326
|
+
this._pageId,
|
|
1327
|
+
this._readImageEl()
|
|
1328
|
+
);
|
|
1329
|
+
}
|
|
1330
|
+
};
|
|
1331
|
+
var FPdfImageBuilder = class {
|
|
1332
|
+
constructor(_pdfModel, _commandService, _pageId, existing) {
|
|
1333
|
+
this._pdfModel = _pdfModel;
|
|
1334
|
+
this._commandService = _commandService;
|
|
1335
|
+
this._pageId = _pageId;
|
|
1336
|
+
this._src = "";
|
|
1337
|
+
this._left = 48;
|
|
1338
|
+
this._top = 48;
|
|
1339
|
+
this._width = 180;
|
|
1340
|
+
this._height = 120;
|
|
1341
|
+
this._fit = "contain";
|
|
1342
|
+
this._objectPosition = "center";
|
|
1343
|
+
this._angle = 0;
|
|
1344
|
+
this._opacity = 1;
|
|
1345
|
+
if (existing) {
|
|
1346
|
+
if (existing instanceof FPdfImage) {
|
|
1347
|
+
const raw = existing.getData();
|
|
1348
|
+
this._src = raw.src ?? "";
|
|
1349
|
+
this._resourceId = raw.resourceId;
|
|
1350
|
+
this._left = raw.transform.left;
|
|
1351
|
+
this._top = raw.transform.top;
|
|
1352
|
+
this._width = raw.transform.width;
|
|
1353
|
+
this._height = raw.transform.height;
|
|
1354
|
+
this._angle = raw.transform.angle ?? 0;
|
|
1355
|
+
this._fit = raw.fit ?? "contain";
|
|
1356
|
+
this._objectPosition = raw.objectPosition ?? "center";
|
|
1357
|
+
this._crop = raw.crop ? Tools.deepClone(raw.crop) : void 0;
|
|
1358
|
+
this._opacity = raw.opacity ?? 1;
|
|
1359
|
+
this._altText = raw.altText;
|
|
1360
|
+
this._name = raw.name;
|
|
1361
|
+
} else if ("transform" in existing && existing.transform) {
|
|
1362
|
+
const raw = existing;
|
|
1363
|
+
this._src = raw.src ?? "";
|
|
1364
|
+
this._resourceId = raw.resourceId;
|
|
1365
|
+
this._left = raw.transform.left;
|
|
1366
|
+
this._top = raw.transform.top;
|
|
1367
|
+
this._width = raw.transform.width;
|
|
1368
|
+
this._height = raw.transform.height;
|
|
1369
|
+
this._angle = raw.transform.angle ?? 0;
|
|
1370
|
+
this._fit = raw.fit ?? "contain";
|
|
1371
|
+
this._objectPosition = raw.objectPosition ?? "center";
|
|
1372
|
+
this._crop = raw.crop ? Tools.deepClone(raw.crop) : void 0;
|
|
1373
|
+
this._opacity = raw.opacity ?? 1;
|
|
1374
|
+
this._altText = raw.altText;
|
|
1375
|
+
this._name = raw.name;
|
|
1376
|
+
} else {
|
|
1377
|
+
const info = existing;
|
|
1378
|
+
this._src = info.source ?? info.src ?? "";
|
|
1379
|
+
this._resourceId = info.resourceId;
|
|
1380
|
+
if (info.left !== void 0) this._left = info.left;
|
|
1381
|
+
if (info.top !== void 0) this._top = info.top;
|
|
1382
|
+
if (info.width !== void 0) this._width = info.width;
|
|
1383
|
+
if (info.height !== void 0) this._height = info.height;
|
|
1384
|
+
if (info.rotation !== void 0 || info.angle !== void 0) {
|
|
1385
|
+
this._angle = info.rotation ?? info.angle ?? 0;
|
|
1386
|
+
}
|
|
1387
|
+
if (info.fit) this._fit = info.fit;
|
|
1388
|
+
if (info.objectPosition) this._objectPosition = info.objectPosition;
|
|
1389
|
+
if (info.crop) this._crop = Tools.deepClone(info.crop);
|
|
1390
|
+
if (info.opacity !== void 0) this._opacity = info.opacity;
|
|
1391
|
+
if (info.altText !== void 0) this._altText = info.altText;
|
|
1392
|
+
if (info.name !== void 0) this._name = info.name;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
setSource(srcOrBytes, mimeType) {
|
|
1397
|
+
if (typeof srcOrBytes === "string") {
|
|
1398
|
+
this._src = srcOrBytes;
|
|
1399
|
+
} else {
|
|
1400
|
+
const detectedMime = mimeType ?? (srcOrBytes.length >= 4 && srcOrBytes[0] === 137 && srcOrBytes[1] === 80 ? "image/png" : "image/jpeg");
|
|
1401
|
+
this._src = `data:${detectedMime};base64,${encodeUint8ToBase64(srcOrBytes)}`;
|
|
1402
|
+
}
|
|
1403
|
+
return this;
|
|
1404
|
+
}
|
|
1405
|
+
setPosition(left, top) {
|
|
1406
|
+
this._left = left;
|
|
1407
|
+
this._top = top;
|
|
1408
|
+
return this;
|
|
1409
|
+
}
|
|
1410
|
+
setAbsolutePosition(left, top) {
|
|
1411
|
+
return this.setPosition(left, top);
|
|
1412
|
+
}
|
|
1413
|
+
setSize(width, height) {
|
|
1414
|
+
this._width = Math.max(1, width);
|
|
1415
|
+
this._height = Math.max(1, height);
|
|
1416
|
+
return this;
|
|
1417
|
+
}
|
|
1418
|
+
setFit(fit) {
|
|
1419
|
+
this._fit = fit;
|
|
1420
|
+
return this;
|
|
1421
|
+
}
|
|
1422
|
+
setObjectPosition(objectPosition) {
|
|
1423
|
+
this._objectPosition = objectPosition;
|
|
1424
|
+
return this;
|
|
1425
|
+
}
|
|
1426
|
+
setRotation(angle) {
|
|
1427
|
+
this._angle = angle;
|
|
1428
|
+
return this;
|
|
1429
|
+
}
|
|
1430
|
+
setCrop(crop) {
|
|
1431
|
+
this._crop = crop ? normalizeImageCrop(crop) : void 0;
|
|
1432
|
+
return this;
|
|
1433
|
+
}
|
|
1434
|
+
setOpacity(opacity) {
|
|
1435
|
+
this._opacity = Math.max(0, Math.min(1, opacity));
|
|
1436
|
+
return this;
|
|
1437
|
+
}
|
|
1438
|
+
setAltText(altText) {
|
|
1439
|
+
this._altText = altText;
|
|
1440
|
+
return this;
|
|
1441
|
+
}
|
|
1442
|
+
setName(name) {
|
|
1443
|
+
this._name = name;
|
|
1444
|
+
return this;
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Builds a detached `IPdfImageBuilderInfo` descriptor without mutating the page.
|
|
1448
|
+
* Pass the returned object to `page.insertImage(info, index?)` (or call `info.insert(index?)`) to insert.
|
|
1449
|
+
*/
|
|
1450
|
+
build() {
|
|
1451
|
+
const snapshotSrc = this._src;
|
|
1452
|
+
const snapshotResourceId = this._resourceId;
|
|
1453
|
+
const snapshotLeft = this._left;
|
|
1454
|
+
const snapshotTop = this._top;
|
|
1455
|
+
const snapshotWidth = this._width;
|
|
1456
|
+
const snapshotHeight = this._height;
|
|
1457
|
+
const snapshotAngle = this._angle;
|
|
1458
|
+
const snapshotFit = this._fit;
|
|
1459
|
+
const snapshotObjectPos = this._objectPosition;
|
|
1460
|
+
const snapshotCrop = this._crop ? Tools.deepClone(this._crop) : void 0;
|
|
1461
|
+
const snapshotOpacity = this._opacity;
|
|
1462
|
+
const snapshotAltText = this._altText;
|
|
1463
|
+
const snapshotName = this._name;
|
|
1464
|
+
return {
|
|
1465
|
+
__isPdfImageBuilderInfo: true,
|
|
1466
|
+
source: snapshotSrc,
|
|
1467
|
+
src: snapshotSrc,
|
|
1468
|
+
resourceId: snapshotResourceId,
|
|
1469
|
+
left: snapshotLeft,
|
|
1470
|
+
top: snapshotTop,
|
|
1471
|
+
width: snapshotWidth,
|
|
1472
|
+
height: snapshotHeight,
|
|
1473
|
+
angle: snapshotAngle,
|
|
1474
|
+
rotation: snapshotAngle,
|
|
1475
|
+
fit: snapshotFit,
|
|
1476
|
+
objectPosition: snapshotObjectPos,
|
|
1477
|
+
crop: snapshotCrop,
|
|
1478
|
+
opacity: snapshotOpacity,
|
|
1479
|
+
altText: snapshotAltText,
|
|
1480
|
+
name: snapshotName,
|
|
1481
|
+
getSource: () => snapshotSrc,
|
|
1482
|
+
getSrc: () => snapshotSrc,
|
|
1483
|
+
getFit: () => snapshotFit,
|
|
1484
|
+
getObjectPosition: () => snapshotObjectPos,
|
|
1485
|
+
getOpacity: () => snapshotOpacity,
|
|
1486
|
+
getCrop: () => snapshotCrop ? Tools.deepClone(snapshotCrop) : void 0,
|
|
1487
|
+
insert: (index) => this._insertFromInfo({
|
|
1488
|
+
source: snapshotSrc,
|
|
1489
|
+
src: snapshotSrc,
|
|
1490
|
+
resourceId: snapshotResourceId,
|
|
1491
|
+
left: snapshotLeft,
|
|
1492
|
+
top: snapshotTop,
|
|
1493
|
+
width: snapshotWidth,
|
|
1494
|
+
height: snapshotHeight,
|
|
1495
|
+
angle: snapshotAngle,
|
|
1496
|
+
rotation: snapshotAngle,
|
|
1497
|
+
fit: snapshotFit,
|
|
1498
|
+
objectPosition: snapshotObjectPos,
|
|
1499
|
+
crop: snapshotCrop,
|
|
1500
|
+
opacity: snapshotOpacity,
|
|
1501
|
+
altText: snapshotAltText,
|
|
1502
|
+
name: snapshotName
|
|
1503
|
+
}, index)
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
async buildAsync() {
|
|
1507
|
+
return this.build();
|
|
1508
|
+
}
|
|
1509
|
+
_insertFromInfo(info, index) {
|
|
1510
|
+
const id = `el-${generateRandomId(6)}`;
|
|
1511
|
+
this._commandService.syncExecuteCommand(AddPdfElementCommand.id, {
|
|
1512
|
+
unitId: this._pdfModel.getUnitId(),
|
|
1513
|
+
pageId: this._pageId,
|
|
1514
|
+
elementType: PdfElementType2.IMAGE,
|
|
1515
|
+
index,
|
|
1516
|
+
element: {
|
|
1517
|
+
id,
|
|
1518
|
+
name: info.name,
|
|
1519
|
+
src: info.source || info.src,
|
|
1520
|
+
resourceId: info.resourceId,
|
|
1521
|
+
fit: info.fit,
|
|
1522
|
+
objectPosition: info.objectPosition,
|
|
1523
|
+
crop: info.crop ? Tools.deepClone(info.crop) : void 0,
|
|
1524
|
+
opacity: info.opacity,
|
|
1525
|
+
altText: info.altText,
|
|
1526
|
+
transform: {
|
|
1527
|
+
left: info.left,
|
|
1528
|
+
top: info.top,
|
|
1529
|
+
width: info.width,
|
|
1530
|
+
height: info.height,
|
|
1531
|
+
angle: info.rotation ?? info.angle ?? 0
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
});
|
|
1535
|
+
return new FPdfImage(this._pdfModel, this._commandService, this._pageId, id);
|
|
1536
|
+
}
|
|
1537
|
+
/**
|
|
1538
|
+
* Materializes this builder directly onto the page as an `FPdfImage`.
|
|
1539
|
+
*/
|
|
1540
|
+
insert(index) {
|
|
1541
|
+
return this.build().insert(index);
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
var FPdfDivider = class extends FPdfPageElement {
|
|
1545
|
+
_readLineEl() {
|
|
1546
|
+
const el = this._readRaw();
|
|
1547
|
+
if (el.type !== PdfElementType2.LINE) {
|
|
1548
|
+
throw new Error(`[UniverPdfs] Element "${this._elementId}" is not a LINE divider element.`);
|
|
1549
|
+
}
|
|
1550
|
+
return el;
|
|
1551
|
+
}
|
|
1552
|
+
getStrokeColor() {
|
|
1553
|
+
return this._readLineEl().strokeColor ?? "#E3E5EA";
|
|
1554
|
+
}
|
|
1555
|
+
setStrokeColor(strokeColor) {
|
|
1556
|
+
return this.update({ strokeColor });
|
|
1557
|
+
}
|
|
1558
|
+
getStrokeWidth() {
|
|
1559
|
+
return this._readLineEl().strokeWidth ?? 1;
|
|
1560
|
+
}
|
|
1561
|
+
setStrokeWidth(strokeWidth) {
|
|
1562
|
+
return this.update({ strokeWidth: Math.max(0.25, strokeWidth) });
|
|
1563
|
+
}
|
|
1564
|
+
setDashArray(dashArray) {
|
|
1565
|
+
return this.update({ dashArray });
|
|
1566
|
+
}
|
|
1567
|
+
setArrows(startArrow, endArrow) {
|
|
1568
|
+
return this.update({ startArrow, endArrow });
|
|
1569
|
+
}
|
|
1570
|
+
getStroke() {
|
|
1571
|
+
const line = this._readLineEl();
|
|
1572
|
+
return {
|
|
1573
|
+
color: line.strokeColor ?? "#E3E5EA",
|
|
1574
|
+
width: line.strokeWidth ?? 1,
|
|
1575
|
+
...line.dashArray ? { dashArray: [...line.dashArray] } : {},
|
|
1576
|
+
opacity: line.opacity ?? 1
|
|
1577
|
+
};
|
|
1578
|
+
}
|
|
1579
|
+
setStroke(stroke) {
|
|
1580
|
+
const nextColor = stroke.color ?? stroke.strokeColor;
|
|
1581
|
+
const nextWidth = stroke.width ?? stroke.strokeWidth;
|
|
1582
|
+
return this.update({
|
|
1583
|
+
...nextColor !== void 0 ? { strokeColor: nextColor } : {},
|
|
1584
|
+
...nextWidth !== void 0 ? { strokeWidth: Math.max(0.25, nextWidth) } : {},
|
|
1585
|
+
...stroke.dashArray !== void 0 ? { dashArray: stroke.dashArray } : {},
|
|
1586
|
+
...stroke.opacity !== void 0 ? { opacity: Math.max(0, Math.min(1, stroke.opacity)) } : {}
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
var FPdfAnnotation = class extends FPdfPageElement {
|
|
1591
|
+
_readAnnotEl() {
|
|
1592
|
+
const el = this._readRaw();
|
|
1593
|
+
if (el.type !== PdfElementType2.ANNOTATION) {
|
|
1594
|
+
throw new Error(`[UniverPdfs] Element "${this._elementId}" is not an ANNOTATION element.`);
|
|
1595
|
+
}
|
|
1596
|
+
return el;
|
|
1597
|
+
}
|
|
1598
|
+
getAnnotationType() {
|
|
1599
|
+
return this._readAnnotEl().annotationType;
|
|
1600
|
+
}
|
|
1601
|
+
setAnnotationType(annotationType) {
|
|
1602
|
+
return this.update({ annotationType });
|
|
1603
|
+
}
|
|
1604
|
+
getComment() {
|
|
1605
|
+
return this._readAnnotEl().comment ?? "";
|
|
1606
|
+
}
|
|
1607
|
+
setComment(comment) {
|
|
1608
|
+
return this.update({ comment });
|
|
1609
|
+
}
|
|
1610
|
+
getAuthor() {
|
|
1611
|
+
return this._readAnnotEl().author ?? "";
|
|
1612
|
+
}
|
|
1613
|
+
setAuthor(author) {
|
|
1614
|
+
return this.update({ author });
|
|
1615
|
+
}
|
|
1616
|
+
getStatus() {
|
|
1617
|
+
return this._readAnnotEl().status;
|
|
1618
|
+
}
|
|
1619
|
+
setStatus(status) {
|
|
1620
|
+
return this.update({ status });
|
|
1621
|
+
}
|
|
1622
|
+
setColor(color) {
|
|
1623
|
+
return this.update({ color });
|
|
1624
|
+
}
|
|
1625
|
+
getStyle() {
|
|
1626
|
+
const annot = this._readAnnotEl();
|
|
1627
|
+
return {
|
|
1628
|
+
color: annot.color,
|
|
1629
|
+
opacity: annot.opacity,
|
|
1630
|
+
annotationType: annot.annotationType
|
|
1631
|
+
};
|
|
1632
|
+
}
|
|
1633
|
+
setStyle(style) {
|
|
1634
|
+
return this.update({
|
|
1635
|
+
...style.color !== void 0 ? { color: style.color } : {},
|
|
1636
|
+
...style.opacity !== void 0 ? { opacity: Math.max(0, Math.min(1, style.opacity)) } : {},
|
|
1637
|
+
...style.annotationType !== void 0 ? { annotationType: style.annotationType } : {}
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
getMarkup() {
|
|
1641
|
+
const annot = this._readAnnotEl();
|
|
1642
|
+
return {
|
|
1643
|
+
annotationType: annot.annotationType,
|
|
1644
|
+
bounds: this.getBounds(),
|
|
1645
|
+
color: annot.color,
|
|
1646
|
+
opacity: annot.opacity,
|
|
1647
|
+
comment: annot.comment ?? "",
|
|
1648
|
+
author: annot.author ?? ""
|
|
1649
|
+
};
|
|
1650
|
+
}
|
|
1651
|
+
getInk() {
|
|
1652
|
+
const inkPaths = this._readAnnotEl().metadata?.inkPaths;
|
|
1653
|
+
return Array.isArray(inkPaths) ? Tools.deepClone(inkPaths) : [];
|
|
1654
|
+
}
|
|
1655
|
+
getReplies() {
|
|
1656
|
+
return Tools.deepClone(this._readAnnotEl().replies ?? []);
|
|
1657
|
+
}
|
|
1658
|
+
addReply(author, content) {
|
|
1659
|
+
const reply = {
|
|
1660
|
+
id: `rep-${generateRandomId(6)}`,
|
|
1661
|
+
author: author || "Reviewer",
|
|
1662
|
+
content,
|
|
1663
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1664
|
+
};
|
|
1665
|
+
const nextReplies = [...this.getReplies(), reply];
|
|
1666
|
+
this.update({ replies: nextReplies });
|
|
1667
|
+
return reply;
|
|
1668
|
+
}
|
|
1669
|
+
};
|
|
1670
|
+
function wrapPdfElementFacade(pdfModel, commandService, pageId, el) {
|
|
1671
|
+
switch (el.type) {
|
|
1672
|
+
case PdfElementType2.TEXT:
|
|
1673
|
+
if (el.metadata?.isParagraph === true) {
|
|
1674
|
+
return new FPdfParagraph(pdfModel, commandService, pageId, el.id);
|
|
1675
|
+
}
|
|
1676
|
+
return new FPdfTextBox(pdfModel, commandService, pageId, el.id);
|
|
1677
|
+
case PdfElementType2.LIST:
|
|
1678
|
+
return new FPdfList(pdfModel, commandService, pageId, el.id);
|
|
1679
|
+
case PdfElementType2.TABLE:
|
|
1680
|
+
return new FPdfTable(pdfModel, commandService, pageId, el.id);
|
|
1681
|
+
case PdfElementType2.IMAGE:
|
|
1682
|
+
return new FPdfImage(pdfModel, commandService, pageId, el.id);
|
|
1683
|
+
case PdfElementType2.LINE:
|
|
1684
|
+
return new FPdfDivider(pdfModel, commandService, pageId, el.id);
|
|
1685
|
+
case PdfElementType2.ANNOTATION:
|
|
1686
|
+
return new FPdfAnnotation(pdfModel, commandService, pageId, el.id);
|
|
1687
|
+
default:
|
|
1688
|
+
return new FPdfPageElement(pdfModel, commandService, pageId, el.id);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
// src/facade/f-pdf-page.ts
|
|
1693
|
+
function isDetachedImageBuilderInfo(val) {
|
|
1694
|
+
return Boolean(
|
|
1695
|
+
val && typeof val === "object" && val.__isPdfImageBuilderInfo === true
|
|
1696
|
+
);
|
|
1697
|
+
}
|
|
1698
|
+
var FPdfPage = class {
|
|
1699
|
+
constructor(_pdfModel, _commandService, _pageId) {
|
|
1700
|
+
this._pdfModel = _pdfModel;
|
|
1701
|
+
this._commandService = _commandService;
|
|
1702
|
+
this._pageId = _pageId;
|
|
1703
|
+
}
|
|
1704
|
+
getId() {
|
|
1705
|
+
return this._pageId;
|
|
1706
|
+
}
|
|
1707
|
+
_readPageMeta() {
|
|
1708
|
+
const page = this._pdfModel.getPage(this._pageId);
|
|
1709
|
+
if (!page) {
|
|
1710
|
+
throw new Error(`[UniverPdfs] Page "${this._pageId}" no longer exists in unit "${this._pdfModel.getUnitId()}".`);
|
|
1711
|
+
}
|
|
1712
|
+
return page;
|
|
1713
|
+
}
|
|
1714
|
+
getData() {
|
|
1715
|
+
return Tools2.deepClone(this._readPageMeta());
|
|
1716
|
+
}
|
|
1717
|
+
getIndex() {
|
|
1718
|
+
return this._pdfModel.getPageOrder().indexOf(this._pageId);
|
|
1719
|
+
}
|
|
1720
|
+
getPageNumber() {
|
|
1721
|
+
const idx = this.getIndex();
|
|
1722
|
+
return idx >= 0 ? idx + 1 : 1;
|
|
1723
|
+
}
|
|
1724
|
+
getTitle() {
|
|
1725
|
+
return this._readPageMeta().title ?? `Page ${this.getPageNumber()}`;
|
|
1726
|
+
}
|
|
1727
|
+
setTitle(title) {
|
|
1728
|
+
this._commandService.syncExecuteCommand(UpdatePdfPagePropsCommand.id, {
|
|
1729
|
+
unitId: this._pdfModel.getUnitId(),
|
|
1730
|
+
pageId: this._pageId,
|
|
1731
|
+
patch: { title }
|
|
1732
|
+
});
|
|
1733
|
+
return this;
|
|
1734
|
+
}
|
|
1735
|
+
getSize() {
|
|
1736
|
+
const meta = this._readPageMeta();
|
|
1737
|
+
return Tools2.deepClone(meta.pageSize ?? this._pdfModel.getDocument().pageSize);
|
|
1738
|
+
}
|
|
1739
|
+
setSize(pageSize) {
|
|
1740
|
+
this._commandService.syncExecuteCommand(UpdatePdfPagePropsCommand.id, {
|
|
1741
|
+
unitId: this._pdfModel.getUnitId(),
|
|
1742
|
+
pageId: this._pageId,
|
|
1743
|
+
patch: { pageSize: Tools2.deepClone(pageSize) }
|
|
1744
|
+
});
|
|
1745
|
+
return this;
|
|
1746
|
+
}
|
|
1747
|
+
getRotation() {
|
|
1748
|
+
return this._readPageMeta().rotation ?? 0;
|
|
1749
|
+
}
|
|
1750
|
+
setRotation(rotation) {
|
|
1751
|
+
this._commandService.syncExecuteCommand(RotatePdfPageCommand.id, {
|
|
1752
|
+
unitId: this._pdfModel.getUnitId(),
|
|
1753
|
+
pageId: this._pageId,
|
|
1754
|
+
rotation
|
|
1755
|
+
});
|
|
1756
|
+
return this;
|
|
1757
|
+
}
|
|
1758
|
+
setBackgroundColor(backgroundColor) {
|
|
1759
|
+
this._commandService.syncExecuteCommand(UpdatePdfPagePropsCommand.id, {
|
|
1760
|
+
unitId: this._pdfModel.getUnitId(),
|
|
1761
|
+
pageId: this._pageId,
|
|
1762
|
+
patch: { backgroundColor }
|
|
1763
|
+
});
|
|
1764
|
+
return this;
|
|
1765
|
+
}
|
|
1766
|
+
getElements() {
|
|
1767
|
+
const map = this._pdfModel.getElementsByPage(this._pageId);
|
|
1768
|
+
const order = this._pdfModel.getElementOrderByPage(this._pageId);
|
|
1769
|
+
const out = [];
|
|
1770
|
+
for (const id of order) {
|
|
1771
|
+
const el = map[id];
|
|
1772
|
+
if (el) {
|
|
1773
|
+
out.push(wrapPdfElementFacade(this._pdfModel, this._commandService, this._pageId, el));
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
return out;
|
|
1777
|
+
}
|
|
1778
|
+
getElementById(elementId) {
|
|
1779
|
+
const el = this._pdfModel.getElementsByPage(this._pageId)[elementId];
|
|
1780
|
+
if (!el) return null;
|
|
1781
|
+
return wrapPdfElementFacade(this._pdfModel, this._commandService, this._pageId, el);
|
|
1782
|
+
}
|
|
1783
|
+
getTextBoxes() {
|
|
1784
|
+
return this.getElements().filter((el) => el instanceof FPdfTextBox);
|
|
1785
|
+
}
|
|
1786
|
+
getParagraphs() {
|
|
1787
|
+
return this.getElements().filter((el) => el instanceof FPdfParagraph);
|
|
1788
|
+
}
|
|
1789
|
+
getLists() {
|
|
1790
|
+
return this.getElements().filter((el) => el instanceof FPdfList);
|
|
1791
|
+
}
|
|
1792
|
+
getTables() {
|
|
1793
|
+
return this.getElements().filter((el) => el instanceof FPdfTable);
|
|
1794
|
+
}
|
|
1795
|
+
getImages() {
|
|
1796
|
+
return this.getElements().filter((el) => el instanceof FPdfImage);
|
|
1797
|
+
}
|
|
1798
|
+
getDividers() {
|
|
1799
|
+
return this.getElements().filter((el) => el instanceof FPdfDivider);
|
|
1800
|
+
}
|
|
1801
|
+
getAnnotations() {
|
|
1802
|
+
return this.getElements().filter((el) => el instanceof FPdfAnnotation);
|
|
1803
|
+
}
|
|
1804
|
+
insertTextBox(contentOrOptions, bounds, style) {
|
|
1805
|
+
const id = `el-${generateRandomId2(6)}`;
|
|
1806
|
+
if (typeof contentOrOptions === "object" && contentOrOptions !== null) {
|
|
1807
|
+
const opts = contentOrOptions;
|
|
1808
|
+
this._commandService.syncExecuteCommand(AddPdfElementCommand2.id, {
|
|
1809
|
+
unitId: this._pdfModel.getUnitId(),
|
|
1810
|
+
pageId: this._pageId,
|
|
1811
|
+
elementType: PdfElementType3.TEXT,
|
|
1812
|
+
index: opts.index,
|
|
1813
|
+
element: {
|
|
1814
|
+
id,
|
|
1815
|
+
name: opts.name,
|
|
1816
|
+
content: opts.text ?? opts.content ?? "",
|
|
1817
|
+
dynamicFontSize: opts.dynamicFontSize,
|
|
1818
|
+
linkUrl: opts.linkUrl,
|
|
1819
|
+
linkDest: opts.linkDest,
|
|
1820
|
+
style: {
|
|
1821
|
+
fontSize: 12,
|
|
1822
|
+
color: "#1B1C1F",
|
|
1823
|
+
...opts.style
|
|
1824
|
+
},
|
|
1825
|
+
transform: {
|
|
1826
|
+
left: opts.left ?? 48,
|
|
1827
|
+
top: opts.top ?? 48,
|
|
1828
|
+
width: opts.width ?? 260,
|
|
1829
|
+
height: opts.height ?? 44,
|
|
1830
|
+
...opts.angle !== void 0 ? { angle: opts.angle } : {}
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
});
|
|
1834
|
+
return new FPdfTextBox(this._pdfModel, this._commandService, this._pageId, id);
|
|
1835
|
+
}
|
|
1836
|
+
this._commandService.syncExecuteCommand(AddPdfElementCommand2.id, {
|
|
1837
|
+
unitId: this._pdfModel.getUnitId(),
|
|
1838
|
+
pageId: this._pageId,
|
|
1839
|
+
elementType: PdfElementType3.TEXT,
|
|
1840
|
+
element: {
|
|
1841
|
+
id,
|
|
1842
|
+
content: contentOrOptions,
|
|
1843
|
+
style: {
|
|
1844
|
+
fontSize: 12,
|
|
1845
|
+
color: "#1B1C1F",
|
|
1846
|
+
...style
|
|
1847
|
+
},
|
|
1848
|
+
transform: {
|
|
1849
|
+
left: bounds?.left ?? 48,
|
|
1850
|
+
top: bounds?.top ?? 48,
|
|
1851
|
+
width: bounds?.width ?? 260,
|
|
1852
|
+
height: bounds?.height ?? 44
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
});
|
|
1856
|
+
return new FPdfTextBox(this._pdfModel, this._commandService, this._pageId, id);
|
|
1857
|
+
}
|
|
1858
|
+
insertParagraph(textOrOptions, bounds, style) {
|
|
1859
|
+
const id = `el-${generateRandomId2(6)}`;
|
|
1860
|
+
const opts = typeof textOrOptions === "object" && textOrOptions !== null ? textOrOptions : {
|
|
1861
|
+
text: textOrOptions,
|
|
1862
|
+
left: bounds?.left,
|
|
1863
|
+
top: bounds?.top,
|
|
1864
|
+
width: bounds?.width,
|
|
1865
|
+
height: bounds?.height,
|
|
1866
|
+
style
|
|
1867
|
+
};
|
|
1868
|
+
const blocks = opts.blocks?.length ? Tools2.deepClone(opts.blocks) : [{ text: opts.text ?? "", ...opts.style ? { style: { ...opts.style } } : {} }];
|
|
1869
|
+
const content = blocks.map((b) => b.text).join("");
|
|
1870
|
+
this._commandService.syncExecuteCommand(AddPdfElementCommand2.id, {
|
|
1871
|
+
unitId: this._pdfModel.getUnitId(),
|
|
1872
|
+
pageId: this._pageId,
|
|
1873
|
+
elementType: PdfElementType3.TEXT,
|
|
1874
|
+
index: opts.index,
|
|
1875
|
+
element: {
|
|
1876
|
+
id,
|
|
1877
|
+
name: opts.name,
|
|
1878
|
+
content,
|
|
1879
|
+
style: {
|
|
1880
|
+
fontSize: 12,
|
|
1881
|
+
color: "#1B1C1F",
|
|
1882
|
+
...opts.style
|
|
1883
|
+
},
|
|
1884
|
+
metadata: {
|
|
1885
|
+
isParagraph: true,
|
|
1886
|
+
paragraphBlocks: blocks
|
|
1887
|
+
},
|
|
1888
|
+
transform: {
|
|
1889
|
+
left: opts.left ?? 48,
|
|
1890
|
+
top: opts.top ?? 48,
|
|
1891
|
+
width: opts.width ?? 320,
|
|
1892
|
+
height: opts.height ?? 52
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
});
|
|
1896
|
+
const para = new FPdfParagraph(this._pdfModel, this._commandService, this._pageId, id);
|
|
1897
|
+
if (opts.blocks?.length) {
|
|
1898
|
+
const first = opts.blocks[0];
|
|
1899
|
+
if (first?.style) para.setBlockStyle(0, first.style);
|
|
1900
|
+
}
|
|
1901
|
+
return para;
|
|
1902
|
+
}
|
|
1903
|
+
insertList(itemsOrOptions, options) {
|
|
1904
|
+
const id = `el-${generateRandomId2(6)}`;
|
|
1905
|
+
const normalized = Array.isArray(itemsOrOptions) ? { ...options, items: itemsOrOptions } : itemsOrOptions;
|
|
1906
|
+
const items = [...normalized.items ?? ["Item 1"]];
|
|
1907
|
+
const listType = normalized.listType ?? normalized.kind ?? "bullet";
|
|
1908
|
+
const itemLevels = normalized.itemLevels?.map(
|
|
1909
|
+
(lvl) => Math.max(0, Math.min(8, Math.floor(lvl || 0)))
|
|
1910
|
+
);
|
|
1911
|
+
this._commandService.syncExecuteCommand(AddPdfElementCommand2.id, {
|
|
1912
|
+
unitId: this._pdfModel.getUnitId(),
|
|
1913
|
+
pageId: this._pageId,
|
|
1914
|
+
elementType: PdfElementType3.LIST,
|
|
1915
|
+
index: normalized.index,
|
|
1916
|
+
element: {
|
|
1917
|
+
id,
|
|
1918
|
+
listType,
|
|
1919
|
+
presetId: normalized.presetId,
|
|
1920
|
+
startNumber: normalized.startNumber,
|
|
1921
|
+
itemLevels,
|
|
1922
|
+
items,
|
|
1923
|
+
style: normalized.style,
|
|
1924
|
+
transform: {
|
|
1925
|
+
left: normalized.left ?? 48,
|
|
1926
|
+
top: normalized.top ?? 48,
|
|
1927
|
+
width: normalized.width ?? 260,
|
|
1928
|
+
height: normalized.height ?? Math.max(40, items.length * 20 + 10)
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
});
|
|
1932
|
+
return new FPdfList(this._pdfModel, this._commandService, this._pageId, id);
|
|
1933
|
+
}
|
|
1934
|
+
insertTable(rowsOrOptions, colsOrHeaders, bounds) {
|
|
1935
|
+
const id = `el-${generateRandomId2(6)}`;
|
|
1936
|
+
const isOptsObject = typeof rowsOrOptions === "object" && rowsOrOptions !== null && !Array.isArray(rowsOrOptions);
|
|
1937
|
+
const rowsArg = isOptsObject ? rowsOrOptions.rows ?? 2 : rowsOrOptions;
|
|
1938
|
+
const colsArg = isOptsObject ? rowsOrOptions.columns ?? rowsOrOptions.headers : colsOrHeaders;
|
|
1939
|
+
const showHead = isOptsObject ? rowsOrOptions.showHead !== false : true;
|
|
1940
|
+
let columns;
|
|
1941
|
+
if (Array.isArray(colsArg) && colsArg.length > 0) {
|
|
1942
|
+
columns = colsArg.map(
|
|
1943
|
+
(item, idx) => typeof item === "string" ? { id: `col-${idx + 1}`, header: item, field: `col_${idx + 1}`, widthRatio: 1 } : { ...item, id: item.id || `col-${idx + 1}`, field: item.field || `col_${idx + 1}` }
|
|
1944
|
+
);
|
|
1945
|
+
} else {
|
|
1946
|
+
const colCount = typeof colsArg === "number" && colsArg > 0 ? Math.floor(colsArg) : Array.isArray(rowsArg) && rowsArg[0] ? Math.max(1, rowsArg[0].length) : 3;
|
|
1947
|
+
columns = Array.from({ length: colCount }, (_, idx) => ({
|
|
1948
|
+
id: `col-${idx + 1}`,
|
|
1949
|
+
header: `Column ${idx + 1}`,
|
|
1950
|
+
field: `col_${idx + 1}`,
|
|
1951
|
+
widthRatio: 1
|
|
1952
|
+
}));
|
|
1953
|
+
}
|
|
1954
|
+
const rows = Array.isArray(rowsArg) ? rowsArg.map((r) => [...r]) : Array.from(
|
|
1955
|
+
{ length: Math.max(1, Math.floor(rowsArg || 2)) },
|
|
1956
|
+
() => new Array(columns.length).fill("")
|
|
1957
|
+
);
|
|
1958
|
+
const headerHeight = 26;
|
|
1959
|
+
const rowHeight = 24;
|
|
1960
|
+
const defaultHeight = (showHead ? headerHeight : 0) + rows.length * rowHeight;
|
|
1961
|
+
this._commandService.syncExecuteCommand(AddPdfElementCommand2.id, {
|
|
1962
|
+
unitId: this._pdfModel.getUnitId(),
|
|
1963
|
+
pageId: this._pageId,
|
|
1964
|
+
elementType: PdfElementType3.TABLE,
|
|
1965
|
+
index: isOptsObject ? rowsOrOptions.index : void 0,
|
|
1966
|
+
element: {
|
|
1967
|
+
id,
|
|
1968
|
+
columns,
|
|
1969
|
+
rows,
|
|
1970
|
+
showHead,
|
|
1971
|
+
headerHeight,
|
|
1972
|
+
rowHeight,
|
|
1973
|
+
borderColor: isOptsObject ? rowsOrOptions.borderColor : void 0,
|
|
1974
|
+
borderWidth: isOptsObject ? rowsOrOptions.borderWidth : void 0,
|
|
1975
|
+
borderStyle: isOptsObject ? rowsOrOptions.borderStyle : void 0,
|
|
1976
|
+
borderWidths: isOptsObject ? rowsOrOptions.borderWidths : void 0,
|
|
1977
|
+
merges: isOptsObject ? rowsOrOptions.merges : void 0,
|
|
1978
|
+
cellStyles: isOptsObject ? rowsOrOptions.cellStyles : void 0,
|
|
1979
|
+
avoidOrphanHeader: true,
|
|
1980
|
+
transform: {
|
|
1981
|
+
left: (isOptsObject ? rowsOrOptions.left : bounds?.left) ?? 48,
|
|
1982
|
+
top: (isOptsObject ? rowsOrOptions.top : bounds?.top) ?? 48,
|
|
1983
|
+
width: (isOptsObject ? rowsOrOptions.width : bounds?.width) ?? 420,
|
|
1984
|
+
height: (isOptsObject ? rowsOrOptions.height : bounds?.height) ?? defaultHeight
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
});
|
|
1988
|
+
return new FPdfTable(this._pdfModel, this._commandService, this._pageId, id);
|
|
1989
|
+
}
|
|
1990
|
+
newImage(existing) {
|
|
1991
|
+
return new FPdfImageBuilder(this._pdfModel, this._commandService, this._pageId, existing);
|
|
1992
|
+
}
|
|
1993
|
+
insertImage(srcOrInfoOrOptions, boundsOrIndex, indexArg) {
|
|
1994
|
+
if (isDetachedImageBuilderInfo(srcOrInfoOrOptions)) {
|
|
1995
|
+
const idx2 = typeof boundsOrIndex === "number" ? boundsOrIndex : indexArg;
|
|
1996
|
+
return this.newImage(srcOrInfoOrOptions).insert(idx2);
|
|
1997
|
+
}
|
|
1998
|
+
if (typeof srcOrInfoOrOptions === "object" && srcOrInfoOrOptions !== null && !(srcOrInfoOrOptions instanceof Uint8Array)) {
|
|
1999
|
+
const opts = srcOrInfoOrOptions;
|
|
2000
|
+
const builder2 = this.newImage();
|
|
2001
|
+
const srcVal = opts.source ?? opts.src;
|
|
2002
|
+
if (srcVal !== void 0) builder2.setSource(srcVal);
|
|
2003
|
+
if (opts.left !== void 0 || opts.top !== void 0) {
|
|
2004
|
+
builder2.setPosition(opts.left ?? 48, opts.top ?? 48);
|
|
2005
|
+
}
|
|
2006
|
+
if (opts.width !== void 0 || opts.height !== void 0) {
|
|
2007
|
+
builder2.setSize(opts.width ?? 180, opts.height ?? 120);
|
|
2008
|
+
}
|
|
2009
|
+
if (opts.rotation !== void 0 || opts.angle !== void 0) {
|
|
2010
|
+
builder2.setRotation(opts.rotation ?? opts.angle ?? 0);
|
|
2011
|
+
}
|
|
2012
|
+
if (opts.fit) builder2.setFit(opts.fit);
|
|
2013
|
+
if (opts.objectPosition) builder2.setObjectPosition(opts.objectPosition);
|
|
2014
|
+
if (opts.crop) builder2.setCrop(opts.crop);
|
|
2015
|
+
if (opts.opacity !== void 0) builder2.setOpacity(opts.opacity);
|
|
2016
|
+
if (opts.altText !== void 0) builder2.setAltText(opts.altText);
|
|
2017
|
+
if (opts.name !== void 0) builder2.setName(opts.name);
|
|
2018
|
+
return builder2.insert(opts.index);
|
|
2019
|
+
}
|
|
2020
|
+
const bounds = typeof boundsOrIndex === "object" && boundsOrIndex !== null ? boundsOrIndex : void 0;
|
|
2021
|
+
const idx = typeof boundsOrIndex === "number" ? boundsOrIndex : indexArg;
|
|
2022
|
+
const builder = this.newImage().setSource(srcOrInfoOrOptions);
|
|
2023
|
+
if (bounds?.left !== void 0 || bounds?.top !== void 0) {
|
|
2024
|
+
builder.setPosition(bounds.left ?? 48, bounds.top ?? 48);
|
|
2025
|
+
}
|
|
2026
|
+
if (bounds?.width !== void 0 || bounds?.height !== void 0) {
|
|
2027
|
+
builder.setSize(bounds.width ?? 180, bounds.height ?? 120);
|
|
2028
|
+
}
|
|
2029
|
+
if (bounds?.fit) builder.setFit(bounds.fit);
|
|
2030
|
+
if (bounds?.objectPosition) builder.setObjectPosition(bounds.objectPosition);
|
|
2031
|
+
return builder.insert(idx);
|
|
2032
|
+
}
|
|
2033
|
+
async insertImageAsync(sourceOrInfo, optionsOrIndex) {
|
|
2034
|
+
if (isDetachedImageBuilderInfo(sourceOrInfo)) {
|
|
2035
|
+
const idx = typeof optionsOrIndex === "number" ? optionsOrIndex : optionsOrIndex?.index;
|
|
2036
|
+
return this.insertImage(sourceOrInfo, idx);
|
|
2037
|
+
}
|
|
2038
|
+
let resolvedSource;
|
|
2039
|
+
if (typeof sourceOrInfo === "string" || sourceOrInfo instanceof Uint8Array) {
|
|
2040
|
+
resolvedSource = sourceOrInfo;
|
|
2041
|
+
} else if (sourceOrInfo instanceof ArrayBuffer) {
|
|
2042
|
+
resolvedSource = new Uint8Array(sourceOrInfo);
|
|
2043
|
+
} else if (typeof Blob !== "undefined" && sourceOrInfo instanceof Blob) {
|
|
2044
|
+
const buf = await sourceOrInfo.arrayBuffer();
|
|
2045
|
+
const bytes = new Uint8Array(buf);
|
|
2046
|
+
const mime = sourceOrInfo.type || "image/png";
|
|
2047
|
+
resolvedSource = `data:${mime};base64,${encodeUint8ToBase64(bytes)}`;
|
|
2048
|
+
} else {
|
|
2049
|
+
resolvedSource = String(sourceOrInfo ?? "");
|
|
2050
|
+
}
|
|
2051
|
+
if (typeof optionsOrIndex === "number") {
|
|
2052
|
+
return this.insertImage(resolvedSource, void 0, optionsOrIndex);
|
|
2053
|
+
}
|
|
2054
|
+
return this.insertImage({
|
|
2055
|
+
...optionsOrIndex ?? {},
|
|
2056
|
+
source: resolvedSource
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
insertDivider(bounds) {
|
|
2060
|
+
const id = `el-${generateRandomId2(6)}`;
|
|
2061
|
+
this._commandService.syncExecuteCommand(AddPdfElementCommand2.id, {
|
|
2062
|
+
unitId: this._pdfModel.getUnitId(),
|
|
2063
|
+
pageId: this._pageId,
|
|
2064
|
+
elementType: PdfElementType3.LINE,
|
|
2065
|
+
index: bounds?.index,
|
|
2066
|
+
element: {
|
|
2067
|
+
id,
|
|
2068
|
+
strokeColor: bounds?.strokeColor ?? "#E3E5EA",
|
|
2069
|
+
strokeWidth: bounds?.strokeWidth ?? 1,
|
|
2070
|
+
dashArray: bounds?.dashArray,
|
|
2071
|
+
transform: {
|
|
2072
|
+
left: bounds?.left ?? 48,
|
|
2073
|
+
top: bounds?.top ?? 120,
|
|
2074
|
+
width: bounds?.width ?? 480,
|
|
2075
|
+
height: bounds?.height ?? 8
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
});
|
|
2079
|
+
return new FPdfDivider(this._pdfModel, this._commandService, this._pageId, id);
|
|
2080
|
+
}
|
|
2081
|
+
insertAnnotation(typeOrOptions, bounds, options) {
|
|
2082
|
+
const id = `el-${generateRandomId2(6)}`;
|
|
2083
|
+
if (typeof typeOrOptions === "object" && typeOrOptions !== null) {
|
|
2084
|
+
const opts = typeOrOptions;
|
|
2085
|
+
this._commandService.syncExecuteCommand(AddPdfElementCommand2.id, {
|
|
2086
|
+
unitId: this._pdfModel.getUnitId(),
|
|
2087
|
+
pageId: this._pageId,
|
|
2088
|
+
elementType: PdfElementType3.ANNOTATION,
|
|
2089
|
+
index: opts.index,
|
|
2090
|
+
element: {
|
|
2091
|
+
id,
|
|
2092
|
+
annotationType: opts.annotationType ?? opts.type ?? "highlight",
|
|
2093
|
+
comment: opts.comment,
|
|
2094
|
+
author: opts.author,
|
|
2095
|
+
color: opts.color,
|
|
2096
|
+
opacity: opts.opacity,
|
|
2097
|
+
transform: {
|
|
2098
|
+
left: opts.left ?? 60,
|
|
2099
|
+
top: opts.top ?? 60,
|
|
2100
|
+
width: opts.width ?? 140,
|
|
2101
|
+
height: opts.height ?? 24
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
});
|
|
2105
|
+
return new FPdfAnnotation(this._pdfModel, this._commandService, this._pageId, id);
|
|
2106
|
+
}
|
|
2107
|
+
this._commandService.syncExecuteCommand(AddPdfElementCommand2.id, {
|
|
2108
|
+
unitId: this._pdfModel.getUnitId(),
|
|
2109
|
+
pageId: this._pageId,
|
|
2110
|
+
elementType: PdfElementType3.ANNOTATION,
|
|
2111
|
+
element: {
|
|
2112
|
+
id,
|
|
2113
|
+
annotationType: typeOrOptions,
|
|
2114
|
+
comment: options?.comment,
|
|
2115
|
+
author: options?.author,
|
|
2116
|
+
color: options?.color,
|
|
2117
|
+
opacity: options?.opacity,
|
|
2118
|
+
transform: {
|
|
2119
|
+
left: bounds?.left ?? 60,
|
|
2120
|
+
top: bounds?.top ?? 60,
|
|
2121
|
+
width: bounds?.width ?? 140,
|
|
2122
|
+
height: bounds?.height ?? 24
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
});
|
|
2126
|
+
return new FPdfAnnotation(this._pdfModel, this._commandService, this._pageId, id);
|
|
2127
|
+
}
|
|
2128
|
+
/**
|
|
2129
|
+
* Returns all text spans on this page (both editable `TEXT` / `PARAGRAPH` elements and native base-PDF text spans).
|
|
2130
|
+
* When `query` is provided, filters to matched substring spans via `findText(query)`.
|
|
2131
|
+
*/
|
|
2132
|
+
getTextSpans(query) {
|
|
2133
|
+
if (query) {
|
|
2134
|
+
return this.findText(query);
|
|
2135
|
+
}
|
|
2136
|
+
const results = [];
|
|
2137
|
+
const map = this._pdfModel.getElementsByPage(this._pageId);
|
|
2138
|
+
const order = this._pdfModel.getElementOrderByPage(this._pageId);
|
|
2139
|
+
for (const id of order) {
|
|
2140
|
+
const el = map[id];
|
|
2141
|
+
if (!el || el.hidden || el.type !== PdfElementType3.TEXT) continue;
|
|
2142
|
+
const text = el.content ?? "";
|
|
2143
|
+
if (!text) continue;
|
|
2144
|
+
results.push(
|
|
2145
|
+
new FPdfTextSpan(this._pdfModel, this._commandService, this._pageId, {
|
|
2146
|
+
kind: "element",
|
|
2147
|
+
elementId: el.id,
|
|
2148
|
+
startOffset: 0,
|
|
2149
|
+
endOffset: text.length,
|
|
2150
|
+
matchedText: text,
|
|
2151
|
+
bounds: {
|
|
2152
|
+
left: el.transform.left,
|
|
2153
|
+
top: el.transform.top,
|
|
2154
|
+
width: el.transform.width,
|
|
2155
|
+
height: el.transform.height
|
|
2156
|
+
}
|
|
2157
|
+
})
|
|
2158
|
+
);
|
|
2159
|
+
}
|
|
2160
|
+
const snap = this._pdfModel.save();
|
|
2161
|
+
const suppressedSet = new Set(snap.editState.suppressedSourceIds ?? []);
|
|
2162
|
+
const nativeSpans = snap.editState.nativeTextSpansByPage?.[this._pageId] ?? snap.metadata?.nativeTextSpansByPage?.[this._pageId] ?? [];
|
|
2163
|
+
for (const ns of nativeSpans) {
|
|
2164
|
+
if (ns.suppressed || suppressedSet.has(ns.id) || !ns.text) continue;
|
|
2165
|
+
results.push(
|
|
2166
|
+
new FPdfTextSpan(this._pdfModel, this._commandService, this._pageId, {
|
|
2167
|
+
kind: "native",
|
|
2168
|
+
startOffset: 0,
|
|
2169
|
+
endOffset: ns.text.length,
|
|
2170
|
+
matchedText: ns.text,
|
|
2171
|
+
bounds: {
|
|
2172
|
+
left: ns.left,
|
|
2173
|
+
top: ns.top,
|
|
2174
|
+
width: ns.width,
|
|
2175
|
+
height: ns.height
|
|
2176
|
+
},
|
|
2177
|
+
nativeSpan: ns
|
|
2178
|
+
})
|
|
2179
|
+
);
|
|
2180
|
+
}
|
|
2181
|
+
return results;
|
|
2182
|
+
}
|
|
2183
|
+
/**
|
|
2184
|
+
* Searches both editable `TEXT`/`PARAGRAPH` elements and native imported base-PDF text spans on this page,
|
|
2185
|
+
* returning `FPdfTextSpan` instances that support safe `replaceText()`.
|
|
2186
|
+
*/
|
|
2187
|
+
findText(query) {
|
|
2188
|
+
if (!query) return [];
|
|
2189
|
+
const results = [];
|
|
2190
|
+
const map = this._pdfModel.getElementsByPage(this._pageId);
|
|
2191
|
+
const order = this._pdfModel.getElementOrderByPage(this._pageId);
|
|
2192
|
+
for (const id of order) {
|
|
2193
|
+
const el = map[id];
|
|
2194
|
+
if (el && !el.hidden && el.type === PdfElementType3.TEXT) {
|
|
2195
|
+
const tb = new FPdfTextBox(this._pdfModel, this._commandService, this._pageId, el.id);
|
|
2196
|
+
results.push(...tb.findText(query));
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
const snap = this._pdfModel.save();
|
|
2200
|
+
const suppressedSet = new Set(snap.editState.suppressedSourceIds ?? []);
|
|
2201
|
+
const nativeSpans = snap.editState.nativeTextSpansByPage?.[this._pageId] ?? snap.metadata?.nativeTextSpansByPage?.[this._pageId] ?? [];
|
|
2202
|
+
for (const ns of nativeSpans) {
|
|
2203
|
+
if (ns.suppressed || suppressedSet.has(ns.id) || !ns.text) continue;
|
|
2204
|
+
const siblingGroup = { invalidated: false };
|
|
2205
|
+
let from = 0;
|
|
2206
|
+
while (from <= ns.text.length - query.length) {
|
|
2207
|
+
const idx = ns.text.indexOf(query, from);
|
|
2208
|
+
if (idx < 0) break;
|
|
2209
|
+
results.push(
|
|
2210
|
+
new FPdfTextSpan(this._pdfModel, this._commandService, this._pageId, {
|
|
2211
|
+
kind: "native",
|
|
2212
|
+
startOffset: idx,
|
|
2213
|
+
endOffset: idx + query.length,
|
|
2214
|
+
matchedText: query,
|
|
2215
|
+
bounds: {
|
|
2216
|
+
left: ns.left,
|
|
2217
|
+
top: ns.top,
|
|
2218
|
+
width: ns.width,
|
|
2219
|
+
height: ns.height
|
|
2220
|
+
},
|
|
2221
|
+
nativeSpan: ns,
|
|
2222
|
+
siblingGroup
|
|
2223
|
+
})
|
|
2224
|
+
);
|
|
2225
|
+
from = idx + Math.max(1, query.length);
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
return results;
|
|
2229
|
+
}
|
|
2230
|
+
remove() {
|
|
2231
|
+
return this._commandService.syncExecuteCommand(RemovePdfPageCommand.id, {
|
|
2232
|
+
unitId: this._pdfModel.getUnitId(),
|
|
2233
|
+
pageId: this._pageId
|
|
2234
|
+
});
|
|
2235
|
+
}
|
|
2236
|
+
};
|
|
2237
|
+
|
|
2238
|
+
// src/facade/f-pdf.ts
|
|
2239
|
+
function bytesToBase64Safe(bytes) {
|
|
2240
|
+
if (typeof Buffer !== "undefined") {
|
|
2241
|
+
return Buffer.from(bytes).toString("base64");
|
|
2242
|
+
}
|
|
2243
|
+
let binary = "";
|
|
2244
|
+
const chunkSize = 32768;
|
|
2245
|
+
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
2246
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
|
|
2247
|
+
}
|
|
2248
|
+
return btoa(binary);
|
|
2249
|
+
}
|
|
2250
|
+
function base64OrDataUriToBytesSafe(input) {
|
|
2251
|
+
const commaIdx = input.indexOf(",");
|
|
2252
|
+
const b64 = (commaIdx >= 0 ? input.slice(commaIdx + 1) : input).trim();
|
|
2253
|
+
const dataUri = input.startsWith("data:") ? input : `data:application/pdf;base64,${b64}`;
|
|
2254
|
+
if (typeof Buffer !== "undefined") {
|
|
2255
|
+
return { bytes: new Uint8Array(Buffer.from(b64, "base64")), dataUri };
|
|
2256
|
+
}
|
|
2257
|
+
const bin = atob(b64);
|
|
2258
|
+
const bytes = new Uint8Array(bin.length);
|
|
2259
|
+
for (let i = 0; i < bin.length; i++) {
|
|
2260
|
+
bytes[i] = bin.charCodeAt(i);
|
|
2261
|
+
}
|
|
2262
|
+
return { bytes, dataUri };
|
|
2263
|
+
}
|
|
2264
|
+
var FPdf = class {
|
|
2265
|
+
constructor(_pdfModel, _injector, _commandService) {
|
|
2266
|
+
this._pdfModel = _pdfModel;
|
|
2267
|
+
this._injector = _injector;
|
|
2268
|
+
this._commandService = _commandService;
|
|
2269
|
+
this._isFlushingActiveEditor = false;
|
|
2270
|
+
}
|
|
2271
|
+
getId() {
|
|
2272
|
+
return this._pdfModel.getUnitId();
|
|
2273
|
+
}
|
|
2274
|
+
getModel() {
|
|
2275
|
+
return this._pdfModel;
|
|
2276
|
+
}
|
|
2277
|
+
getName() {
|
|
2278
|
+
return this._pdfModel.getName();
|
|
2279
|
+
}
|
|
2280
|
+
setName(name) {
|
|
2281
|
+
this._commandService.syncExecuteCommand(UpdatePdfUnitPropsCommand.id, {
|
|
2282
|
+
unitId: this.getId(),
|
|
2283
|
+
patch: { name }
|
|
2284
|
+
});
|
|
2285
|
+
}
|
|
2286
|
+
/**
|
|
2287
|
+
* Returns immutable document structure baseline (`pages`, `pageOrder`, `pageSize`).
|
|
2288
|
+
*/
|
|
2289
|
+
getDocument() {
|
|
2290
|
+
return this._pdfModel.getDocument();
|
|
2291
|
+
}
|
|
2292
|
+
/**
|
|
2293
|
+
* Returns object-oriented `FPdfPage` facades for every page in `pageOrder`.
|
|
2294
|
+
*/
|
|
2295
|
+
getPages() {
|
|
2296
|
+
return this._pdfModel.getPageOrder().map((pageId) => new FPdfPage(this._pdfModel, this._commandService, pageId));
|
|
2297
|
+
}
|
|
2298
|
+
/**
|
|
2299
|
+
* Returns the `FPdfPage` facade matching `pageId`, or `null` if not found.
|
|
2300
|
+
*/
|
|
2301
|
+
getPageById(pageId) {
|
|
2302
|
+
if (!this._pdfModel.getPage(pageId)) return null;
|
|
2303
|
+
return new FPdfPage(this._pdfModel, this._commandService, pageId);
|
|
2304
|
+
}
|
|
2305
|
+
/**
|
|
2306
|
+
* Returns the `FPdfPage` facade at 0-based `index`, or `null` if out of range.
|
|
2307
|
+
*/
|
|
2308
|
+
getPageByIndex(index) {
|
|
2309
|
+
const order = this._pdfModel.getPageOrder();
|
|
2310
|
+
if (index < 0 || index >= order.length) return null;
|
|
2311
|
+
return new FPdfPage(this._pdfModel, this._commandService, order[index]);
|
|
2312
|
+
}
|
|
2313
|
+
/**
|
|
2314
|
+
* Inserts a new page at 0-based `index` (or at the end when omitted) via `ICommandService`
|
|
2315
|
+
* and returns its `FPdfPage` facade.
|
|
2316
|
+
*/
|
|
2317
|
+
insertPage(index, page) {
|
|
2318
|
+
let createdPageId = "";
|
|
2319
|
+
this._commandService.syncExecuteCommand(AddPdfPageCommand.id, {
|
|
2320
|
+
unitId: this.getId(),
|
|
2321
|
+
index,
|
|
2322
|
+
page,
|
|
2323
|
+
onCreated: (pid) => {
|
|
2324
|
+
createdPageId = pid;
|
|
2325
|
+
}
|
|
2326
|
+
});
|
|
2327
|
+
if (!createdPageId) {
|
|
2328
|
+
const order = this._pdfModel.getPageOrder();
|
|
2329
|
+
createdPageId = order[order.length - 1];
|
|
2330
|
+
}
|
|
2331
|
+
return new FPdfPage(this._pdfModel, this._commandService, createdPageId);
|
|
2332
|
+
}
|
|
2333
|
+
/**
|
|
2334
|
+
* Appends pages from another PDF binary (`Uint8Array`, `ArrayBuffer`, `Blob`, Base64/Data URI)
|
|
2335
|
+
* or another `IPdfUnitData` snapshot onto the end of this document (Undo/Redo-safe),
|
|
2336
|
+
* returning the newly appended `FPdfPage[]` instances.
|
|
2337
|
+
*/
|
|
2338
|
+
async appendPdf(source, options) {
|
|
2339
|
+
const currentSnap = this.save();
|
|
2340
|
+
if (source && typeof source === "object" && !(source instanceof Uint8Array) && !(source instanceof ArrayBuffer) && !(typeof Blob !== "undefined" && source instanceof Blob) && "document" in source && "editState" in source) {
|
|
2341
|
+
const srcSnap = source;
|
|
2342
|
+
const next2 = Tools3.deepClone(currentSnap);
|
|
2343
|
+
const appendedIds = [];
|
|
2344
|
+
let sourceOffset = 0;
|
|
2345
|
+
if (srcSnap.sourceDocumentRef?.dataUri) {
|
|
2346
|
+
if (next2.sourceDocumentRef?.dataUri) {
|
|
2347
|
+
const curBase = base64OrDataUriToBytesSafe(next2.sourceDocumentRef.dataUri).bytes;
|
|
2348
|
+
const addBase = base64OrDataUriToBytesSafe(srcSnap.sourceDocumentRef.dataUri).bytes;
|
|
2349
|
+
const curDoc = await PDFDocument.load(curBase, { ignoreEncryption: true });
|
|
2350
|
+
sourceOffset = curDoc.getPageCount();
|
|
2351
|
+
const merged = await mergePdfBytes([curBase, addBase]);
|
|
2352
|
+
next2.sourceDocumentRef = {
|
|
2353
|
+
...next2.sourceDocumentRef,
|
|
2354
|
+
dataUri: `data:application/pdf;base64,${bytesToBase64Safe(merged)}`
|
|
2355
|
+
};
|
|
2356
|
+
} else {
|
|
2357
|
+
next2.sourceDocumentRef = Tools3.deepClone(srcSnap.sourceDocumentRef);
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
for (const srcPageId of srcSnap.document.pageOrder) {
|
|
2361
|
+
const srcMeta = srcSnap.document.pages[srcPageId];
|
|
2362
|
+
if (!srcMeta) continue;
|
|
2363
|
+
const newPageId = `page-${generateRandomId3(6)}`;
|
|
2364
|
+
appendedIds.push(newPageId);
|
|
2365
|
+
next2.document.pages[newPageId] = {
|
|
2366
|
+
...Tools3.deepClone(srcMeta),
|
|
2367
|
+
id: newPageId,
|
|
2368
|
+
...srcMeta.sourcePageNumber ? { sourcePageNumber: srcMeta.sourcePageNumber + sourceOffset } : {}
|
|
2369
|
+
};
|
|
2370
|
+
next2.document.pageOrder.push(newPageId);
|
|
2371
|
+
const srcMap = srcSnap.editState.elementsByPage[srcPageId] ?? {};
|
|
2372
|
+
const srcOrder = srcSnap.editState.elementOrderByPage[srcPageId] ?? Object.keys(srcMap);
|
|
2373
|
+
const clonedMap = {};
|
|
2374
|
+
const clonedOrder = [];
|
|
2375
|
+
for (const eid of srcOrder) {
|
|
2376
|
+
const el = srcMap[eid];
|
|
2377
|
+
if (!el) continue;
|
|
2378
|
+
const newElId = `el-${generateRandomId3(6)}`;
|
|
2379
|
+
clonedMap[newElId] = { ...Tools3.deepClone(el), id: newElId };
|
|
2380
|
+
clonedOrder.push(newElId);
|
|
2381
|
+
}
|
|
2382
|
+
next2.editState.elementsByPage[newPageId] = clonedMap;
|
|
2383
|
+
next2.editState.elementOrderByPage[newPageId] = clonedOrder;
|
|
2384
|
+
}
|
|
2385
|
+
this.loadSnapshot(next2);
|
|
2386
|
+
return appendedIds.map((pid) => new FPdfPage(this._pdfModel, this._commandService, pid));
|
|
2387
|
+
}
|
|
2388
|
+
const imported = await importPdfSource(
|
|
2389
|
+
source,
|
|
2390
|
+
{ password: options?.password }
|
|
2391
|
+
);
|
|
2392
|
+
const next = Tools3.deepClone(currentSnap);
|
|
2393
|
+
let basePageOffset = 0;
|
|
2394
|
+
if (next.sourceDocumentRef?.dataUri) {
|
|
2395
|
+
const existingBytes = base64OrDataUriToBytesSafe(next.sourceDocumentRef.dataUri).bytes;
|
|
2396
|
+
const existingDoc = await PDFDocument.load(existingBytes, { ignoreEncryption: true });
|
|
2397
|
+
basePageOffset = existingDoc.getPageCount();
|
|
2398
|
+
const mergedBytes = await mergePdfBytes([existingBytes, imported.bytes]);
|
|
2399
|
+
next.sourceDocumentRef = {
|
|
2400
|
+
...next.sourceDocumentRef,
|
|
2401
|
+
dataUri: `data:application/pdf;base64,${bytesToBase64Safe(mergedBytes)}`
|
|
2402
|
+
};
|
|
2403
|
+
} else {
|
|
2404
|
+
const curRendered = await exportPdfBytes(currentSnap);
|
|
2405
|
+
const curDoc = await PDFDocument.load(curRendered, { ignoreEncryption: true });
|
|
2406
|
+
basePageOffset = curDoc.getPageCount();
|
|
2407
|
+
const mergedBytes = await mergePdfBytes([curRendered, imported.bytes]);
|
|
2408
|
+
next.sourceDocumentRef = {
|
|
2409
|
+
...imported.sourceDocumentRef,
|
|
2410
|
+
dataUri: `data:application/pdf;base64,${bytesToBase64Safe(mergedBytes)}`
|
|
2411
|
+
};
|
|
2412
|
+
}
|
|
2413
|
+
const appendedPageIds = imported.pageSizes.map(() => `page-${generateRandomId3(6)}`);
|
|
2414
|
+
const extractedNative = await extractNativeTextSpansFromPdfBytes(imported.bytes, appendedPageIds);
|
|
2415
|
+
next.editState.nativeTextSpansByPage = {
|
|
2416
|
+
...next.editState.nativeTextSpansByPage ?? {},
|
|
2417
|
+
...extractedNative
|
|
2418
|
+
};
|
|
2419
|
+
next.metadata = {
|
|
2420
|
+
...next.metadata ?? {},
|
|
2421
|
+
nativeTextSpansByPage: {
|
|
2422
|
+
...next.metadata?.nativeTextSpansByPage ?? {},
|
|
2423
|
+
...extractedNative
|
|
2424
|
+
}
|
|
2425
|
+
};
|
|
2426
|
+
imported.pageSizes.forEach((sz, idx) => {
|
|
2427
|
+
const pid = appendedPageIds[idx];
|
|
2428
|
+
next.document.pages[pid] = {
|
|
2429
|
+
id: pid,
|
|
2430
|
+
title: `Page ${next.document.pageOrder.length + 1}`,
|
|
2431
|
+
backgroundColor: "#ffffff",
|
|
2432
|
+
sourcePageNumber: basePageOffset + idx + 1,
|
|
2433
|
+
pageSize: { ...sz }
|
|
2434
|
+
};
|
|
2435
|
+
next.document.pageOrder.push(pid);
|
|
2436
|
+
next.editState.elementsByPage[pid] = {};
|
|
2437
|
+
next.editState.elementOrderByPage[pid] = [];
|
|
2438
|
+
});
|
|
2439
|
+
this.loadSnapshot(next);
|
|
2440
|
+
return appendedPageIds.map((pid) => new FPdfPage(this._pdfModel, this._commandService, pid));
|
|
2441
|
+
}
|
|
2442
|
+
/**
|
|
2443
|
+
* Validates this document's template schema structure, field names, element types, and page bounds.
|
|
2444
|
+
*/
|
|
2445
|
+
validateTemplate(options) {
|
|
2446
|
+
return validatePdfTemplateSchema(this.save(), options);
|
|
2447
|
+
}
|
|
2448
|
+
/**
|
|
2449
|
+
* Runs a full template doctor health check (schema validation, font & CJK coverage, required variables, and input contracts).
|
|
2450
|
+
*/
|
|
2451
|
+
diagnoseHealth(options) {
|
|
2452
|
+
const snap = this.save();
|
|
2453
|
+
const schema = validatePdfTemplateSchema(snap, { strict: options?.strict });
|
|
2454
|
+
const fonts = diagnosePdfFonts(snap, options);
|
|
2455
|
+
const variables = validatePdfTemplateVariables(snap);
|
|
2456
|
+
const cjk = detectCJKInPdfTemplate(snap);
|
|
2457
|
+
const contractHints = collectPdfInputContractHints(snap);
|
|
2458
|
+
return {
|
|
2459
|
+
healthy: schema.valid && fonts.healthy && variables.valid,
|
|
2460
|
+
schema,
|
|
2461
|
+
fonts,
|
|
2462
|
+
variables,
|
|
2463
|
+
cjk,
|
|
2464
|
+
contractHints
|
|
2465
|
+
};
|
|
2466
|
+
}
|
|
2467
|
+
_flushActiveEditingIfNeeded() {
|
|
2468
|
+
if (this._isFlushingActiveEditor) return;
|
|
2469
|
+
this._isFlushingActiveEditor = true;
|
|
2470
|
+
try {
|
|
2471
|
+
if (this._injector.has(IPdfSelectionService)) {
|
|
2472
|
+
this._injector.get(IPdfSelectionService).commitActiveEditing();
|
|
2473
|
+
}
|
|
2474
|
+
} catch {
|
|
2475
|
+
} finally {
|
|
2476
|
+
this._isFlushingActiveEditor = false;
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
/**
|
|
2480
|
+
* Compiles and returns the complete `IPdfUnitData` snapshot (baseline + durable `editState`),
|
|
2481
|
+
* committing any active inline element editor first.
|
|
2482
|
+
*/
|
|
2483
|
+
save() {
|
|
2484
|
+
this._flushActiveEditingIfNeeded();
|
|
2485
|
+
return this._pdfModel.save();
|
|
2486
|
+
}
|
|
2487
|
+
/**
|
|
2488
|
+
* Triggers the configured `IPdfIoAdapter.onSave` hook to persist the snapshot to a backend host.
|
|
2489
|
+
* Returns `true` if a host save hook was executed, or `false` if none was configured.
|
|
2490
|
+
*/
|
|
2491
|
+
async saveToHost() {
|
|
2492
|
+
return this._injector.get(IPdfIoService).saveToHost({
|
|
2493
|
+
unitId: this.getId(),
|
|
2494
|
+
snapshot: this.save()
|
|
2495
|
+
});
|
|
2496
|
+
}
|
|
2497
|
+
getActivePageId() {
|
|
2498
|
+
return this._injector.get(IPdfSelectionService).getActivePageId();
|
|
2499
|
+
}
|
|
2500
|
+
setActivePage(pageId) {
|
|
2501
|
+
this._injector.get(IPdfSelectionService).setActivePage(pageId);
|
|
2502
|
+
}
|
|
2503
|
+
setPageSize(pageSize) {
|
|
2504
|
+
return this._commandService.syncExecuteCommand(SetPdfPageSizeCommand.id, {
|
|
2505
|
+
unitId: this.getId(),
|
|
2506
|
+
pageSize
|
|
2507
|
+
});
|
|
2508
|
+
}
|
|
2509
|
+
addPage(page) {
|
|
2510
|
+
return this._commandService.syncExecuteCommand(AddPdfPageCommand.id, {
|
|
2511
|
+
unitId: this.getId(),
|
|
2512
|
+
page
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
addElement(elementType, element, pageId) {
|
|
2516
|
+
return this._commandService.syncExecuteCommand(AddPdfElementCommand3.id, {
|
|
2517
|
+
unitId: this.getId(),
|
|
2518
|
+
pageId,
|
|
2519
|
+
elementType,
|
|
2520
|
+
element
|
|
2521
|
+
});
|
|
2522
|
+
}
|
|
2523
|
+
updateElement(elementId, patch, pageId) {
|
|
2524
|
+
return this._commandService.syncExecuteCommand(UpdatePdfElementsCommand2.id, {
|
|
2525
|
+
unitId: this.getId(),
|
|
2526
|
+
pageId,
|
|
2527
|
+
updates: [{ id: elementId, patch }]
|
|
2528
|
+
});
|
|
2529
|
+
}
|
|
2530
|
+
deleteElements(elementIds, pageId) {
|
|
2531
|
+
return this._commandService.syncExecuteCommand(DeleteSelectedPdfElementsCommand2.id, {
|
|
2532
|
+
unitId: this.getId(),
|
|
2533
|
+
pageId,
|
|
2534
|
+
elementIds
|
|
2535
|
+
});
|
|
2536
|
+
}
|
|
2537
|
+
/**
|
|
2538
|
+
* Distributes 3+ selected (or explicitly listed) unlocked elements with equal spacing
|
|
2539
|
+
* along the `'horizontal'` or `'vertical'` axis (Undo/Redo-safe).
|
|
2540
|
+
*/
|
|
2541
|
+
distributeElements(direction, elementIds, pageId) {
|
|
2542
|
+
return this._commandService.syncExecuteCommand(DistributeSelectedPdfElementsCommand.id, {
|
|
2543
|
+
unitId: this.getId(),
|
|
2544
|
+
pageId,
|
|
2545
|
+
direction,
|
|
2546
|
+
elementIds
|
|
2547
|
+
});
|
|
2548
|
+
}
|
|
2549
|
+
/**
|
|
2550
|
+
* Generates a `1mm / 5mm / 10mm` millimeter calibration ruler & crosshair test-sheet PDF
|
|
2551
|
+
* matching this document's paper size (or an explicit `pageSize` override).
|
|
2552
|
+
*/
|
|
2553
|
+
async exportCalibrationGridPdf(pageSize) {
|
|
2554
|
+
return exportCalibrationGridPdfBytes(pageSize ?? this.getDocument().pageSize);
|
|
2555
|
+
}
|
|
2556
|
+
/**
|
|
2557
|
+
* Exports a tamper-evident PDF binary embedded with a deterministic SHA-256 cryptographic audit seal.
|
|
2558
|
+
*/
|
|
2559
|
+
async exportSignedPdf(sealOptions, data) {
|
|
2560
|
+
return exportSignedPdfWithAuditSeal(this.save(), data, sealOptions);
|
|
2561
|
+
}
|
|
2562
|
+
/**
|
|
2563
|
+
* Verifies the SHA-256 cryptographic audit seal and page content stream integrity of a signed PDF binary.
|
|
2564
|
+
*/
|
|
2565
|
+
async verifySignedPdf(pdfBytes) {
|
|
2566
|
+
return verifyPdfAuditSeal(pdfBytes);
|
|
2567
|
+
}
|
|
2568
|
+
/**
|
|
2569
|
+
* Validates required template variables across all pages of this PDF document against `data`.
|
|
2570
|
+
*/
|
|
2571
|
+
validateVariables(data) {
|
|
2572
|
+
return validatePdfTemplateVariables(this.save(), data);
|
|
2573
|
+
}
|
|
2574
|
+
loadSnapshot(snapshot) {
|
|
2575
|
+
return this._commandService.syncExecuteCommand(ReplacePdfSnapshotCommand.id, {
|
|
2576
|
+
unitId: this.getId(),
|
|
2577
|
+
snapshot
|
|
2578
|
+
});
|
|
2579
|
+
}
|
|
2580
|
+
getIoCapabilities() {
|
|
2581
|
+
return this._injector.get(IPdfIoService).getIoCapabilities();
|
|
2582
|
+
}
|
|
2583
|
+
async importPdfFile(file, options) {
|
|
2584
|
+
const ioService = this._injector.get(IPdfIoService);
|
|
2585
|
+
const outcome = await ioService.importPdf(file, {
|
|
2586
|
+
unitId: this.getId(),
|
|
2587
|
+
snapshot: this.save(),
|
|
2588
|
+
target: options?.target
|
|
2589
|
+
});
|
|
2590
|
+
if (outcome.mode === "snapshot") {
|
|
2591
|
+
this.loadSnapshot(outcome.snapshot);
|
|
2592
|
+
} else {
|
|
2593
|
+
this._commandService.syncExecuteCommand(ImportPdfSourceCommand.id, {
|
|
2594
|
+
unitId: this.getId(),
|
|
2595
|
+
sourceDocumentRef: outcome.sourceDocumentRef,
|
|
2596
|
+
pageSizes: outcome.pageSizes
|
|
2597
|
+
});
|
|
2598
|
+
}
|
|
2599
|
+
return outcome;
|
|
2600
|
+
}
|
|
2601
|
+
/**
|
|
2602
|
+
* Generates standard PDF binary bytes (`Uint8Array`) with optional dynamic dataset data and export options.
|
|
2603
|
+
* Supports explicit per-operation `options.target` (`'browser' | 'server' | 'auto'`) without mutating adapter state.
|
|
2604
|
+
*/
|
|
2605
|
+
async exportPdf(data, options) {
|
|
2606
|
+
return this._injector.get(IPdfIoService).exportPdf({
|
|
2607
|
+
unitId: this.getId(),
|
|
2608
|
+
snapshot: this.save(),
|
|
2609
|
+
data,
|
|
2610
|
+
options,
|
|
2611
|
+
target: options?.target
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
/**
|
|
2615
|
+
* Exports standard PDF bytes with interactive `AcroForm` widgets (`PDFTextField`, `PDFCheckBox`,
|
|
2616
|
+
* `PDFRadioGroup`, `PDFDropdown`) enabled.
|
|
2617
|
+
*/
|
|
2618
|
+
async exportInteractiveFormPdf(data, options) {
|
|
2619
|
+
const snap = this.save();
|
|
2620
|
+
const mergedOptions = {
|
|
2621
|
+
...options,
|
|
2622
|
+
interactiveForm: true
|
|
2623
|
+
};
|
|
2624
|
+
const ioService = this._injector.get(IPdfIoService);
|
|
2625
|
+
const cancelled = ioService.runBeforeExportHooks({
|
|
2626
|
+
unitId: this.getId(),
|
|
2627
|
+
snapshot: snap,
|
|
2628
|
+
data,
|
|
2629
|
+
options: mergedOptions,
|
|
2630
|
+
cancel: false
|
|
2631
|
+
});
|
|
2632
|
+
if (cancelled) {
|
|
2633
|
+
throw new CanceledError();
|
|
2634
|
+
}
|
|
2635
|
+
const bytes = await exportPdfBytes(snap, data, mergedOptions);
|
|
2636
|
+
ioService.notifyExported({
|
|
2637
|
+
unitId: this.getId(),
|
|
2638
|
+
bytes,
|
|
2639
|
+
byteLength: bytes.byteLength,
|
|
2640
|
+
options: mergedOptions
|
|
2641
|
+
});
|
|
2642
|
+
return bytes;
|
|
2643
|
+
}
|
|
2644
|
+
/**
|
|
2645
|
+
* Extracts user-filled `AcroForm` field values from an interactive PDF binary and populates them
|
|
2646
|
+
* into the current `FPdf` document snapshot (undoable).
|
|
2647
|
+
*/
|
|
2648
|
+
async importAcroFormValues(pdfBytes) {
|
|
2649
|
+
const values = await extractAcroFormValuesFromPdfBytes(pdfBytes);
|
|
2650
|
+
if (Object.keys(values).length > 0) {
|
|
2651
|
+
this.fillFormValues(values);
|
|
2652
|
+
}
|
|
2653
|
+
return values;
|
|
2654
|
+
}
|
|
2655
|
+
/**
|
|
2656
|
+
* Dispatches silent hardware printing via the configured `IPdfIoAdapter.onSilentPrint` bridge
|
|
2657
|
+
* (e.g. Lodop / QZ-Tray / Yudao Print Agent). Throws `PdfIoTargetError` if unconfigured.
|
|
2658
|
+
*/
|
|
2659
|
+
async silentPrint(options) {
|
|
2660
|
+
return this._injector.get(IPdfIoService).silentPrint({
|
|
2661
|
+
unitId: this.getId(),
|
|
2662
|
+
snapshot: this.save(),
|
|
2663
|
+
options
|
|
2664
|
+
});
|
|
2665
|
+
}
|
|
2666
|
+
/**
|
|
2667
|
+
* Generates a millimeter-aligned receipt/waybill/voucher template from a natural-language prompt
|
|
2668
|
+
* via `IPdfAiCopilotAdapter` (or built-in smart millimeter layout engine) and applies it to this document.
|
|
2669
|
+
*/
|
|
2670
|
+
async generateTemplateByAi(prompt) {
|
|
2671
|
+
const generated = await this._injector.get(IPdfIoService).generateTemplateByAi(prompt);
|
|
2672
|
+
const nextSnapshot = {
|
|
2673
|
+
...generated,
|
|
2674
|
+
id: this.getId()
|
|
2675
|
+
};
|
|
2676
|
+
this.loadSnapshot(nextSnapshot);
|
|
2677
|
+
return this.save();
|
|
2678
|
+
}
|
|
2679
|
+
toPdfmeTemplate() {
|
|
2680
|
+
return toPdfmeTemplate(this.save());
|
|
2681
|
+
}
|
|
2682
|
+
loadPdfmeTemplate(template) {
|
|
2683
|
+
const snapshot = fromPdfmeTemplate(template, { id: this.getId(), name: this.getName() });
|
|
2684
|
+
return this.loadSnapshot(snapshot);
|
|
2685
|
+
}
|
|
2686
|
+
getInteractionMode() {
|
|
2687
|
+
return this._injector.get(IPdfSelectionService).getInteractionMode();
|
|
2688
|
+
}
|
|
2689
|
+
setInteractionMode(mode) {
|
|
2690
|
+
this._injector.get(IPdfSelectionService).setInteractionMode(mode);
|
|
2691
|
+
}
|
|
2692
|
+
getFormValues() {
|
|
2693
|
+
return extractPdfFormValues(this.save());
|
|
2694
|
+
}
|
|
2695
|
+
fillFormValues(values) {
|
|
2696
|
+
const filled = fillPdfFormValues(this.save(), values);
|
|
2697
|
+
return this.loadSnapshot(filled);
|
|
2698
|
+
}
|
|
2699
|
+
async exportBatchPdf(records, options) {
|
|
2700
|
+
const snap = this.save();
|
|
2701
|
+
const ioService = this._injector.get(IPdfIoService);
|
|
2702
|
+
const cancelled = ioService.runBeforeExportHooks({
|
|
2703
|
+
unitId: this.getId(),
|
|
2704
|
+
snapshot: snap,
|
|
2705
|
+
options,
|
|
2706
|
+
cancel: false
|
|
2707
|
+
});
|
|
2708
|
+
if (cancelled) {
|
|
2709
|
+
throw new CanceledError();
|
|
2710
|
+
}
|
|
2711
|
+
const bytes = await exportBatchPdfBytes(snap, records, options);
|
|
2712
|
+
ioService.notifyExported({
|
|
2713
|
+
unitId: this.getId(),
|
|
2714
|
+
bytes,
|
|
2715
|
+
byteLength: bytes.byteLength,
|
|
2716
|
+
options
|
|
2717
|
+
});
|
|
2718
|
+
return bytes;
|
|
2719
|
+
}
|
|
2720
|
+
saveVersion(label) {
|
|
2721
|
+
return this._injector.get(IPdfSelectionService).saveVersionSnapshot(this.getId(), label);
|
|
2722
|
+
}
|
|
2723
|
+
getVersions() {
|
|
2724
|
+
return this._injector.get(IPdfSelectionService).listVersionSnapshots(this.getId());
|
|
2725
|
+
}
|
|
2726
|
+
restoreVersion(versionId) {
|
|
2727
|
+
return this._commandService.syncExecuteCommand(RestorePdfVersionCommand.id, {
|
|
2728
|
+
unitId: this.getId(),
|
|
2729
|
+
versionId
|
|
2730
|
+
});
|
|
2731
|
+
}
|
|
2732
|
+
/**
|
|
2733
|
+
* Loads an imported base PDF (`Uint8Array` or Base64 / Data URI string), extracts all native text spans
|
|
2734
|
+
* across pages, and stores both the base PDF background and `nativeTextSpansByPage` undoably.
|
|
2735
|
+
*/
|
|
2736
|
+
async loadBasePdfWithNativeText(pdfBytes) {
|
|
2737
|
+
const normalized = typeof pdfBytes === "string" ? base64OrDataUriToBytesSafe(pdfBytes) : {
|
|
2738
|
+
bytes: pdfBytes,
|
|
2739
|
+
dataUri: `data:application/pdf;base64,${bytesToBase64Safe(pdfBytes)}`
|
|
2740
|
+
};
|
|
2741
|
+
const doc = await PDFDocument.load(normalized.bytes, { ignoreEncryption: true });
|
|
2742
|
+
const pages = doc.getPages();
|
|
2743
|
+
const pageSizes = pages.length > 0 ? pages.map((p) => {
|
|
2744
|
+
const { width, height } = p.getSize();
|
|
2745
|
+
return { width, height, preset: "CUSTOM" };
|
|
2746
|
+
}) : [{ ...this.getDocument().pageSize }];
|
|
2747
|
+
const existingOrder = this._pdfModel.getPageOrder();
|
|
2748
|
+
const targetPageIds = pageSizes.map((_, idx) => existingOrder[idx] || `page-${generateRandomId3(6)}`);
|
|
2749
|
+
const nativeTextSpansByPage = await extractNativeTextSpansFromPdfBytes(normalized.bytes, targetPageIds);
|
|
2750
|
+
this._commandService.syncExecuteCommand(SetPdfNativeTextSpansCommand.id, {
|
|
2751
|
+
unitId: this.getId(),
|
|
2752
|
+
sourceDocumentRef: {
|
|
2753
|
+
id: `src-${generateRandomId3(6)}`,
|
|
2754
|
+
fileName: "base-document.pdf",
|
|
2755
|
+
mimeType: "application/pdf",
|
|
2756
|
+
dataUri: normalized.dataUri,
|
|
2757
|
+
pageCount: pageSizes.length
|
|
2758
|
+
},
|
|
2759
|
+
pageSizes,
|
|
2760
|
+
targetPageIds,
|
|
2761
|
+
nativeTextSpansByPage
|
|
2762
|
+
});
|
|
2763
|
+
return this.getNativeTextSpans();
|
|
2764
|
+
}
|
|
2765
|
+
/**
|
|
2766
|
+
* Returns non-suppressed native text spans extracted from the base PDF (filtered by `pageId` when provided).
|
|
2767
|
+
*/
|
|
2768
|
+
getNativeTextSpans(pageId) {
|
|
2769
|
+
const snap = this.save();
|
|
2770
|
+
const spansByPage = snap.metadata?.nativeTextSpansByPage ?? snap.editState.nativeTextSpansByPage ?? {};
|
|
2771
|
+
const suppressedSet = new Set(snap.editState.suppressedSourceIds ?? []);
|
|
2772
|
+
if (pageId) {
|
|
2773
|
+
return (spansByPage[pageId] ?? []).filter((s) => !s.suppressed && !suppressedSet.has(s.id)).map((s) => Tools3.deepClone(s));
|
|
2774
|
+
}
|
|
2775
|
+
const all = [];
|
|
2776
|
+
for (const pid of snap.document.pageOrder) {
|
|
2777
|
+
for (const s of spansByPage[pid] ?? []) {
|
|
2778
|
+
if (!s.suppressed && !suppressedSet.has(s.id)) {
|
|
2779
|
+
all.push(Tools3.deepClone(s));
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
return all;
|
|
2784
|
+
}
|
|
2785
|
+
/**
|
|
2786
|
+
* Atomically suppresses a native base-PDF text span, covers its original bounding box,
|
|
2787
|
+
* and inserts an editable `TEXT` element at the exact `{ left, top, width, height }`, returning the new element ID.
|
|
2788
|
+
*/
|
|
2789
|
+
replaceNativeText(spanId, newText, style) {
|
|
2790
|
+
const newElementId = `el-${generateRandomId3(6)}`;
|
|
2791
|
+
const ok = this._commandService.syncExecuteCommand(ReplacePdfNativeTextCommand2.id, {
|
|
2792
|
+
unitId: this.getId(),
|
|
2793
|
+
spanId,
|
|
2794
|
+
newText,
|
|
2795
|
+
style,
|
|
2796
|
+
newElementId
|
|
2797
|
+
});
|
|
2798
|
+
return ok ? newElementId : null;
|
|
2799
|
+
}
|
|
2800
|
+
/**
|
|
2801
|
+
* Searches and replaces text across all `TEXT` elements and (by default) native base-PDF text spans
|
|
2802
|
+
* in a single undoable operation, returning the total replacement count.
|
|
2803
|
+
*/
|
|
2804
|
+
findAndReplaceText(query, replacement, options) {
|
|
2805
|
+
let replacedCount = 0;
|
|
2806
|
+
this._commandService.syncExecuteCommand(FindAndReplacePdfTextCommand.id, {
|
|
2807
|
+
unitId: this.getId(),
|
|
2808
|
+
query,
|
|
2809
|
+
replacement,
|
|
2810
|
+
matchCase: options?.matchCase,
|
|
2811
|
+
includeNativeText: options?.includeNativeText,
|
|
2812
|
+
onResult: (count) => {
|
|
2813
|
+
replacedCount = count;
|
|
2814
|
+
}
|
|
2815
|
+
});
|
|
2816
|
+
return replacedCount;
|
|
2817
|
+
}
|
|
2818
|
+
/**
|
|
2819
|
+
* Inserts a review annotation (`highlight`, `underline`, `strikeout`, `squiggly`, or `stickyNote`)
|
|
2820
|
+
* onto `pageId` (Undo/Redo-safe) and returns its created element ID.
|
|
2821
|
+
*/
|
|
2822
|
+
insertAnnotation(pageId, spec) {
|
|
2823
|
+
if (!this._pdfModel.getPage(pageId)) return null;
|
|
2824
|
+
const elementId = spec.id || `annot-${generateRandomId3(6)}`;
|
|
2825
|
+
const isSticky = spec.annotationType === "stickyNote";
|
|
2826
|
+
const transform = spec.transform ?? {
|
|
2827
|
+
left: spec.left ?? 72,
|
|
2828
|
+
top: spec.top ?? 72,
|
|
2829
|
+
width: spec.width ?? (isSticky ? 28 : 160),
|
|
2830
|
+
height: spec.height ?? (isSticky ? 28 : 22),
|
|
2831
|
+
angle: 0
|
|
2832
|
+
};
|
|
2833
|
+
const ok = this._commandService.syncExecuteCommand(AddPdfElementCommand3.id, {
|
|
2834
|
+
unitId: this.getId(),
|
|
2835
|
+
pageId,
|
|
2836
|
+
elementType: PdfElementType4.ANNOTATION,
|
|
2837
|
+
element: {
|
|
2838
|
+
...spec,
|
|
2839
|
+
id: elementId,
|
|
2840
|
+
type: PdfElementType4.ANNOTATION,
|
|
2841
|
+
transform
|
|
2842
|
+
}
|
|
2843
|
+
});
|
|
2844
|
+
return ok ? elementId : null;
|
|
2845
|
+
}
|
|
2846
|
+
/**
|
|
2847
|
+
* Appends a threaded reply to an existing review annotation (Undo/Redo-safe).
|
|
2848
|
+
*/
|
|
2849
|
+
addAnnotationReply(pageId, elementId, reply) {
|
|
2850
|
+
const existing = this._pdfModel.getElement(pageId, elementId);
|
|
2851
|
+
if (!existing || existing.type !== PdfElementType4.ANNOTATION) return null;
|
|
2852
|
+
const builtReply = {
|
|
2853
|
+
id: reply.id || `reply-${generateRandomId3(6)}`,
|
|
2854
|
+
author: reply.author || "Reviewer",
|
|
2855
|
+
content: reply.content,
|
|
2856
|
+
createdAt: reply.createdAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
2857
|
+
};
|
|
2858
|
+
const ok = this._commandService.syncExecuteCommand(UpdatePdfElementsCommand2.id, {
|
|
2859
|
+
unitId: this.getId(),
|
|
2860
|
+
pageId,
|
|
2861
|
+
updates: [
|
|
2862
|
+
{
|
|
2863
|
+
id: elementId,
|
|
2864
|
+
patch: {
|
|
2865
|
+
replies: [...existing.replies ?? [], builtReply]
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
]
|
|
2869
|
+
});
|
|
2870
|
+
return ok ? builtReply : null;
|
|
2871
|
+
}
|
|
2872
|
+
/**
|
|
2873
|
+
* Updates the review workflow status (`open` | `accepted` | `rejected` | `resolved`) of an annotation (Undo/Redo-safe).
|
|
2874
|
+
*/
|
|
2875
|
+
setAnnotationStatus(pageId, elementId, status) {
|
|
2876
|
+
const existing = this._pdfModel.getElement(pageId, elementId);
|
|
2877
|
+
if (!existing || existing.type !== PdfElementType4.ANNOTATION) return false;
|
|
2878
|
+
return this._commandService.syncExecuteCommand(UpdatePdfElementsCommand2.id, {
|
|
2879
|
+
unitId: this.getId(),
|
|
2880
|
+
pageId,
|
|
2881
|
+
updates: [
|
|
2882
|
+
{
|
|
2883
|
+
id: elementId,
|
|
2884
|
+
patch: { status }
|
|
2885
|
+
}
|
|
2886
|
+
]
|
|
2887
|
+
});
|
|
2888
|
+
}
|
|
2889
|
+
/**
|
|
2890
|
+
* Returns all review annotations across `pageId` (or all pages in `pageOrder` when omitted).
|
|
2891
|
+
*/
|
|
2892
|
+
getAnnotations(pageId) {
|
|
2893
|
+
const targetPageIds = pageId ? [pageId] : this._pdfModel.getPageOrder();
|
|
2894
|
+
const out = [];
|
|
2895
|
+
for (const pid of targetPageIds) {
|
|
2896
|
+
for (const el of this._pdfModel.getPageElementsOrdered(pid)) {
|
|
2897
|
+
if (!el.hidden && el.type === PdfElementType4.ANNOTATION) {
|
|
2898
|
+
out.push(Tools3.deepClone(el));
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
return out;
|
|
2903
|
+
}
|
|
2904
|
+
/**
|
|
2905
|
+
* Inserts a permanent redaction blackout box onto `pageId` (Undo/Redo-safe), which draws an opaque
|
|
2906
|
+
* redaction cover and strips intersecting `TEXT` / native base-PDF text on PDF export.
|
|
2907
|
+
*/
|
|
2908
|
+
insertRedaction(pageId, rect, overlayLabel, fillColor) {
|
|
2909
|
+
if (!this._pdfModel.getPage(pageId)) return null;
|
|
2910
|
+
const elementId = `redact-${generateRandomId3(6)}`;
|
|
2911
|
+
const ok = this._commandService.syncExecuteCommand(AddPdfElementCommand3.id, {
|
|
2912
|
+
unitId: this.getId(),
|
|
2913
|
+
pageId,
|
|
2914
|
+
elementType: PdfElementType4.REDACTION,
|
|
2915
|
+
element: {
|
|
2916
|
+
id: elementId,
|
|
2917
|
+
type: PdfElementType4.REDACTION,
|
|
2918
|
+
fillColor: fillColor ?? "#000000",
|
|
2919
|
+
overlayLabel: overlayLabel ?? "[CONFIDENTIAL]",
|
|
2920
|
+
transform: {
|
|
2921
|
+
left: rect.left,
|
|
2922
|
+
top: rect.top,
|
|
2923
|
+
width: rect.width,
|
|
2924
|
+
height: rect.height,
|
|
2925
|
+
angle: 0
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
});
|
|
2929
|
+
return ok ? elementId : null;
|
|
2930
|
+
}
|
|
2931
|
+
/**
|
|
2932
|
+
* Sets clockwise page rotation (`0 | 90 | 180 | 270`) on `pageId` (Undo/Redo-safe).
|
|
2933
|
+
*/
|
|
2934
|
+
rotatePage(pageId, rotation) {
|
|
2935
|
+
return this._commandService.syncExecuteCommand(RotatePdfPageCommand2.id, {
|
|
2936
|
+
unitId: this.getId(),
|
|
2937
|
+
pageId,
|
|
2938
|
+
rotation
|
|
2939
|
+
});
|
|
2940
|
+
}
|
|
2941
|
+
/**
|
|
2942
|
+
* Reorders document pages according to `newPageOrder` (Undo/Redo-safe).
|
|
2943
|
+
*/
|
|
2944
|
+
reorderPages(newPageOrder) {
|
|
2945
|
+
return this._commandService.syncExecuteCommand(ReorderPdfPagesCommand.id, {
|
|
2946
|
+
unitId: this.getId(),
|
|
2947
|
+
pageOrder: newPageOrder
|
|
2948
|
+
});
|
|
2949
|
+
}
|
|
2950
|
+
/**
|
|
2951
|
+
* Sets or clears the page `CropBox` (`{ left, top, width, height }` in pt) on `pageId` (Undo/Redo-safe).
|
|
2952
|
+
*/
|
|
2953
|
+
setPageCropBox(pageId, cropBox) {
|
|
2954
|
+
return this._commandService.syncExecuteCommand(SetPdfPageCropBoxCommand.id, {
|
|
2955
|
+
unitId: this.getId(),
|
|
2956
|
+
pageId,
|
|
2957
|
+
cropBox
|
|
2958
|
+
});
|
|
2959
|
+
}
|
|
2960
|
+
/**
|
|
2961
|
+
* Exports a 1-based inclusive page range `[startPage..endPage]` of this document as standard PDF bytes.
|
|
2962
|
+
*/
|
|
2963
|
+
async exportPageRangePdfBytes(startPage, endPage, data, options) {
|
|
2964
|
+
const fullBytes = await this.exportPdf(data, options);
|
|
2965
|
+
const [rangeBytes] = await splitPdfBytes(fullBytes, [{ startPage, endPage }]);
|
|
2966
|
+
return rangeBytes;
|
|
2967
|
+
}
|
|
2968
|
+
/**
|
|
2969
|
+
* Configures navigable PDF `/Outlines` bookmarks tree on this document (Undo/Redo-safe).
|
|
2970
|
+
*/
|
|
2971
|
+
setBookmarks(bookmarks) {
|
|
2972
|
+
return this._commandService.syncExecuteCommand(SetPdfBookmarksCommand.id, {
|
|
2973
|
+
unitId: this.getId(),
|
|
2974
|
+
bookmarks
|
|
2975
|
+
});
|
|
2976
|
+
}
|
|
2977
|
+
/**
|
|
2978
|
+
* Returns the configured PDF `/Outlines` bookmarks tree.
|
|
2979
|
+
*/
|
|
2980
|
+
getBookmarks() {
|
|
2981
|
+
return Tools3.deepClone(this.save().metadata?.bookmarks ?? []);
|
|
2982
|
+
}
|
|
2983
|
+
/**
|
|
2984
|
+
* Configures or clears legal/archive Bates numbering (`metadata.batesConfig`, Undo/Redo-safe).
|
|
2985
|
+
*/
|
|
2986
|
+
setBatesConfig(batesConfig) {
|
|
2987
|
+
return this._commandService.syncExecuteCommand(SetPdfBatesConfigCommand.id, {
|
|
2988
|
+
unitId: this.getId(),
|
|
2989
|
+
batesConfig
|
|
2990
|
+
});
|
|
2991
|
+
}
|
|
2992
|
+
/**
|
|
2993
|
+
* Returns the current Bates numbering configuration, if any.
|
|
2994
|
+
*/
|
|
2995
|
+
getBatesConfig() {
|
|
2996
|
+
const cfg = this.save().metadata?.batesConfig;
|
|
2997
|
+
return cfg ? Tools3.deepClone(cfg) : void 0;
|
|
2998
|
+
}
|
|
2999
|
+
// =========================================================================
|
|
3000
|
+
// Wave 2: Named PDF Layers (`/OCProperties`), Header/Footer & Watermark
|
|
3001
|
+
// =========================================================================
|
|
3002
|
+
/**
|
|
3003
|
+
* Adds a named Optional Content Group (`/OCProperties`) layer (Undo/Redo-safe).
|
|
3004
|
+
*/
|
|
3005
|
+
addLayer(layer) {
|
|
3006
|
+
const spec = typeof layer === "string" ? { name: layer } : layer;
|
|
3007
|
+
let created = null;
|
|
3008
|
+
this._commandService.syncExecuteCommand(AddPdfLayerCommand.id, {
|
|
3009
|
+
unitId: this.getId(),
|
|
3010
|
+
layer: spec,
|
|
3011
|
+
onCreated: (l) => {
|
|
3012
|
+
created = l;
|
|
3013
|
+
}
|
|
3014
|
+
});
|
|
3015
|
+
return created;
|
|
3016
|
+
}
|
|
3017
|
+
/**
|
|
3018
|
+
* Updates `visible`, `locked`, `printable`, or `name` on an existing PDF layer (Undo/Redo-safe).
|
|
3019
|
+
*/
|
|
3020
|
+
updateLayer(layerId, patch) {
|
|
3021
|
+
return this._commandService.syncExecuteCommand(UpdatePdfLayerCommand.id, {
|
|
3022
|
+
unitId: this.getId(),
|
|
3023
|
+
layerId,
|
|
3024
|
+
patch
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3027
|
+
/**
|
|
3028
|
+
* Removes a named PDF layer and unassigns elements referencing it (Undo/Redo-safe).
|
|
3029
|
+
*/
|
|
3030
|
+
removeLayer(layerId) {
|
|
3031
|
+
return this._commandService.syncExecuteCommand(RemovePdfLayerCommand.id, {
|
|
3032
|
+
unitId: this.getId(),
|
|
3033
|
+
layerId
|
|
3034
|
+
});
|
|
3035
|
+
}
|
|
3036
|
+
/**
|
|
3037
|
+
* Lists all named PDF Optional Content Group layers on this document.
|
|
3038
|
+
*/
|
|
3039
|
+
getLayers() {
|
|
3040
|
+
return this._pdfModel.getLayers();
|
|
3041
|
+
}
|
|
3042
|
+
/**
|
|
3043
|
+
* Assigns one or more elements to `layerId` (or clears assignment when `layerId` is undefined, Undo/Redo-safe).
|
|
3044
|
+
*/
|
|
3045
|
+
assignElementLayer(elementIdOrIds, layerId, pageId) {
|
|
3046
|
+
const elementIds = Array.isArray(elementIdOrIds) ? elementIdOrIds : [elementIdOrIds];
|
|
3047
|
+
return this._commandService.syncExecuteCommand(AssignPdfElementLayerCommand.id, {
|
|
3048
|
+
unitId: this.getId(),
|
|
3049
|
+
pageId,
|
|
3050
|
+
elementIds,
|
|
3051
|
+
layerId
|
|
3052
|
+
});
|
|
3053
|
+
}
|
|
3054
|
+
setHeaderFooterConfig(headerFooterConfig) {
|
|
3055
|
+
return this._commandService.syncExecuteCommand(SetPdfHeaderFooterConfigCommand.id, {
|
|
3056
|
+
unitId: this.getId(),
|
|
3057
|
+
headerFooterConfig
|
|
3058
|
+
});
|
|
3059
|
+
}
|
|
3060
|
+
getHeaderFooterConfig() {
|
|
3061
|
+
const cfg = this.save().metadata?.headerFooterConfig;
|
|
3062
|
+
return cfg ? Tools3.deepClone(cfg) : void 0;
|
|
3063
|
+
}
|
|
3064
|
+
setWatermarkConfig(watermarkConfig) {
|
|
3065
|
+
return this._commandService.syncExecuteCommand(SetPdfWatermarkConfigCommand.id, {
|
|
3066
|
+
unitId: this.getId(),
|
|
3067
|
+
watermarkConfig
|
|
3068
|
+
});
|
|
3069
|
+
}
|
|
3070
|
+
getWatermarkConfig() {
|
|
3071
|
+
const cfg = this.save().metadata?.watermarkConfig;
|
|
3072
|
+
return cfg ? Tools3.deepClone(cfg) : void 0;
|
|
3073
|
+
}
|
|
3074
|
+
// =========================================================================
|
|
3075
|
+
// Wave 2: Comparison, AcroForm Importer/Auto-Detect, Calculation & XFDF/FDF
|
|
3076
|
+
// =========================================================================
|
|
3077
|
+
/**
|
|
3078
|
+
* Compares this PDF document against another `IPdfDocumentData` snapshot or `FPdf` instance.
|
|
3079
|
+
*/
|
|
3080
|
+
compareWith(other) {
|
|
3081
|
+
const otherSnap = other instanceof FPdf ? other.save() : other;
|
|
3082
|
+
return comparePdfUnits(this.save(), otherSnap);
|
|
3083
|
+
}
|
|
3084
|
+
/**
|
|
3085
|
+
* Imports an existing interactive AcroForm PDF binary into this unit as editable form fields + `basePdf` (Undo/Redo-safe).
|
|
3086
|
+
*/
|
|
3087
|
+
async importAcroFormPdf(pdfBytes, options) {
|
|
3088
|
+
const imported = await importAcroFormPdfToUnit(pdfBytes, {
|
|
3089
|
+
unitId: this.getId(),
|
|
3090
|
+
title: options?.title ?? this.getName()
|
|
3091
|
+
});
|
|
3092
|
+
this.loadSnapshot(imported);
|
|
3093
|
+
return this.save();
|
|
3094
|
+
}
|
|
3095
|
+
/**
|
|
3096
|
+
* Auto-detects form fields on `pageIndex` (default `0` or active page) from native text labels
|
|
3097
|
+
* ending with `:` / `:` or `____` underlines (Undo/Redo-safe).
|
|
3098
|
+
*/
|
|
3099
|
+
autoDetectFormFields(pageIndex) {
|
|
3100
|
+
const snap = this.save();
|
|
3101
|
+
const activeId = this.getActivePageId();
|
|
3102
|
+
const resolvedIdx = pageIndex !== void 0 ? pageIndex : activeId ? Math.max(0, snap.document.pageOrder.indexOf(activeId)) : 0;
|
|
3103
|
+
const detected = detectFormFieldsFromPageSpans(snap, resolvedIdx);
|
|
3104
|
+
if (detected.length === 0) return [];
|
|
3105
|
+
const updated = autoDetectFormFieldsOnPage(snap, resolvedIdx);
|
|
3106
|
+
this.loadSnapshot(updated);
|
|
3107
|
+
return detected;
|
|
3108
|
+
}
|
|
3109
|
+
/**
|
|
3110
|
+
* Evaluates all `calcExpression` formulas across named PDF form fields (Undo/Redo-safe).
|
|
3111
|
+
*/
|
|
3112
|
+
recalculateFormFields() {
|
|
3113
|
+
const recalculated = recalculatePdfFormFields(this.save());
|
|
3114
|
+
this.loadSnapshot(recalculated);
|
|
3115
|
+
return extractPdfFormValues(this.save());
|
|
3116
|
+
}
|
|
3117
|
+
/**
|
|
3118
|
+
* Validates `required` and `validationPattern` constraints across all PDF form fields.
|
|
3119
|
+
*/
|
|
3120
|
+
validateFormFields() {
|
|
3121
|
+
return validatePdfFormFields(this.save());
|
|
3122
|
+
}
|
|
3123
|
+
exportFormDataToXfdf() {
|
|
3124
|
+
return exportFormDataToXfdf(this.save());
|
|
3125
|
+
}
|
|
3126
|
+
importFormDataFromXfdf(xfdfXml) {
|
|
3127
|
+
const next = importFormDataFromXfdf(this.save(), xfdfXml);
|
|
3128
|
+
return this.loadSnapshot(next);
|
|
3129
|
+
}
|
|
3130
|
+
exportFormDataToFdf() {
|
|
3131
|
+
return exportFormDataToFdf(this.save());
|
|
3132
|
+
}
|
|
3133
|
+
importFormDataFromFdf(fdfContent) {
|
|
3134
|
+
const next = importFormDataFromFdf(this.save(), fdfContent);
|
|
3135
|
+
return this.loadSnapshot(next);
|
|
3136
|
+
}
|
|
3137
|
+
// =========================================================================
|
|
3138
|
+
// Wave 2: OCR SPI, Word/Sheet Conversion, Sanitization, Attachments & Signing
|
|
3139
|
+
// =========================================================================
|
|
3140
|
+
registerOcrAdapter(adapter) {
|
|
3141
|
+
this._injector.get(IPdfIoService).setOcrAdapter(adapter);
|
|
3142
|
+
}
|
|
3143
|
+
/**
|
|
3144
|
+
* Runs the registered `IPdfOcrAdapter` on `pageIndex` in either `'searchable'` (`3 Tr` invisible text)
|
|
3145
|
+
* or `'editable'` (`PdfElementType.TEXT` boxes) mode with full Undo/Redo support.
|
|
3146
|
+
*/
|
|
3147
|
+
async applyOcrToPage(pageIndex, mode, adapter) {
|
|
3148
|
+
const activeAdapter = adapter ?? this._injector.get(IPdfIoService).getOcrAdapter() ?? void 0;
|
|
3149
|
+
const { unit: nextUnit, blocks } = await applyOcrToUnitPage(this.save(), pageIndex, mode, activeAdapter);
|
|
3150
|
+
this.loadSnapshot(nextUnit);
|
|
3151
|
+
return blocks;
|
|
3152
|
+
}
|
|
3153
|
+
exportToDocxSnapshot() {
|
|
3154
|
+
return exportPdfToDocxSnapshot(this.save());
|
|
3155
|
+
}
|
|
3156
|
+
exportToWorkbookSnapshot() {
|
|
3157
|
+
return exportPdfToWorkbookSnapshot(this.save());
|
|
3158
|
+
}
|
|
3159
|
+
async exportToDocxBytes() {
|
|
3160
|
+
return convertPdfBytesToDocxBytes(this.save());
|
|
3161
|
+
}
|
|
3162
|
+
exportToCsv() {
|
|
3163
|
+
return convertPdfUnitToCsv(this.save());
|
|
3164
|
+
}
|
|
3165
|
+
sanitize(options) {
|
|
3166
|
+
const sanitized = sanitizePdfUnit(this.save(), options);
|
|
3167
|
+
this.loadSnapshot(sanitized);
|
|
3168
|
+
return this.save();
|
|
3169
|
+
}
|
|
3170
|
+
optimize(options) {
|
|
3171
|
+
const optimized = optimizePdfUnit(this.save(), options);
|
|
3172
|
+
this.loadSnapshot(optimized);
|
|
3173
|
+
return this.save();
|
|
3174
|
+
}
|
|
3175
|
+
getAttachments() {
|
|
3176
|
+
const snap = this.save();
|
|
3177
|
+
return Tools3.deepClone(snap.attachments ?? snap.metadata?.attachments ?? []);
|
|
3178
|
+
}
|
|
3179
|
+
setAttachments(attachments) {
|
|
3180
|
+
return this._commandService.syncExecuteCommand(SetPdfAttachmentsCommand.id, {
|
|
3181
|
+
unitId: this.getId(),
|
|
3182
|
+
attachments
|
|
3183
|
+
});
|
|
3184
|
+
}
|
|
3185
|
+
addAttachment(spec) {
|
|
3186
|
+
const built = {
|
|
3187
|
+
id: spec.id || `att-${generateRandomId3(6)}`,
|
|
3188
|
+
fileName: spec.fileName,
|
|
3189
|
+
mimeType: spec.mimeType || "application/octet-stream",
|
|
3190
|
+
dataBase64: spec.dataBase64,
|
|
3191
|
+
...spec.description ? { description: spec.description } : {}
|
|
3192
|
+
};
|
|
3193
|
+
const next = [...this.getAttachments().filter((a) => a.id !== built.id), built];
|
|
3194
|
+
return this.setAttachments(next) ? built : null;
|
|
3195
|
+
}
|
|
3196
|
+
removeAttachment(attachmentId) {
|
|
3197
|
+
const cur = this.getAttachments();
|
|
3198
|
+
const next = cur.filter((a) => a.id !== attachmentId);
|
|
3199
|
+
if (next.length === cur.length) return false;
|
|
3200
|
+
return this.setAttachments(next);
|
|
3201
|
+
}
|
|
3202
|
+
signWithDigest(signerInfo) {
|
|
3203
|
+
const signed = signPdfUnitWithDigest(this.save(), signerInfo);
|
|
3204
|
+
this.loadSnapshot(signed);
|
|
3205
|
+
return this.save();
|
|
3206
|
+
}
|
|
3207
|
+
verifySignature() {
|
|
3208
|
+
return verifyPdfUnitSignature(this.save());
|
|
3209
|
+
}
|
|
3210
|
+
setSecurityPermissions(securityPermissions) {
|
|
3211
|
+
const next = Tools3.deepClone(this.save());
|
|
3212
|
+
next.securityPermissions = securityPermissions ? Tools3.deepClone(securityPermissions) : void 0;
|
|
3213
|
+
next.metadata = {
|
|
3214
|
+
...next.metadata ?? {},
|
|
3215
|
+
securityPermissions: securityPermissions ? Tools3.deepClone(securityPermissions) : void 0
|
|
3216
|
+
};
|
|
3217
|
+
return this.loadSnapshot(next);
|
|
3218
|
+
}
|
|
3219
|
+
setComplianceOptions(opts) {
|
|
3220
|
+
const next = Tools3.deepClone(this.save());
|
|
3221
|
+
if (opts.pdfACompliant !== void 0) {
|
|
3222
|
+
next.pdfACompliant = opts.pdfACompliant;
|
|
3223
|
+
next.metadata = { ...next.metadata ?? {}, pdfACompliant: opts.pdfACompliant };
|
|
3224
|
+
}
|
|
3225
|
+
if (opts.accessibilityTagged !== void 0) {
|
|
3226
|
+
next.accessibilityTagged = opts.accessibilityTagged;
|
|
3227
|
+
next.metadata = { ...next.metadata ?? {}, accessibilityTagged: opts.accessibilityTagged };
|
|
3228
|
+
}
|
|
3229
|
+
return this.loadSnapshot(next);
|
|
3230
|
+
}
|
|
3231
|
+
};
|
|
3232
|
+
FPdf = __decorateClass([
|
|
3233
|
+
__decorateParam(1, Inject(Injector)),
|
|
3234
|
+
__decorateParam(2, ICommandService)
|
|
3235
|
+
], FPdf);
|
|
3236
|
+
|
|
3237
|
+
// src/facade/f-univer.ts
|
|
3238
|
+
import {
|
|
3239
|
+
CanceledError as CanceledError2,
|
|
3240
|
+
generateRandomId as generateRandomId4,
|
|
3241
|
+
ICommandService as ICommandService2,
|
|
3242
|
+
Tools as Tools4,
|
|
3243
|
+
toDisposable,
|
|
3244
|
+
UniverInstanceType
|
|
3245
|
+
} from "@univerjs/core";
|
|
3246
|
+
import { FUniver } from "@univerjs/core/facade";
|
|
3247
|
+
import { skip } from "rxjs";
|
|
3248
|
+
import {
|
|
3249
|
+
createDefaultPdfUnitData,
|
|
3250
|
+
exportPdfBytes as exportPdfBytes2,
|
|
3251
|
+
extractNativeTextSpansFromPdfBytes as extractNativeTextSpansFromPdfBytes2,
|
|
3252
|
+
extractPdfFormValues as extractPdfFormValues2,
|
|
3253
|
+
importAcroFormPdfToUnit as importAcroFormPdfToUnit2,
|
|
3254
|
+
importPdfSource as importPdfSource2,
|
|
3255
|
+
IPdfIoService as IPdfIoService2,
|
|
3256
|
+
IPdfSelectionService as IPdfSelectionService2,
|
|
3257
|
+
PDF_TABLE_THEME_PRESETS as PDF_TABLE_THEME_PRESETS2,
|
|
3258
|
+
PdfElementType as PdfElementType5,
|
|
3259
|
+
ReplacePdfSnapshotCommand as ReplacePdfSnapshotCommand2,
|
|
3260
|
+
UpdatePdfElementsCommand as UpdatePdfElementsCommand3
|
|
3261
|
+
} from "@yudaocode/univer-pdfs";
|
|
3262
|
+
function isBinaryOrSnapshotAppendSource(val) {
|
|
3263
|
+
if (!val || typeof val !== "object") return false;
|
|
3264
|
+
if (val instanceof Uint8Array || val instanceof ArrayBuffer) return true;
|
|
3265
|
+
if (typeof Blob !== "undefined" && val instanceof Blob) return true;
|
|
3266
|
+
if ("document" in val && "editState" in val) return true;
|
|
3267
|
+
return false;
|
|
3268
|
+
}
|
|
3269
|
+
function isFormFieldElement(el) {
|
|
3270
|
+
return el.type === PdfElementType5.CHECKBOX || el.type === PdfElementType5.CIRCLE_MARK || el.type === PdfElementType5.DATE_TIME || el.type === PdfElementType5.RADIO_GROUP || el.type === PdfElementType5.SELECT || el.type === PdfElementType5.SIGNATURE || el.type === PdfElementType5.TEXT && Boolean(el.formFieldName || el.fieldKey || el.bindingField);
|
|
3271
|
+
}
|
|
3272
|
+
function readElementFormValue(el) {
|
|
3273
|
+
if (el.type === PdfElementType5.CHECKBOX || el.type === PdfElementType5.CIRCLE_MARK) {
|
|
3274
|
+
return Boolean(el.checked);
|
|
3275
|
+
}
|
|
3276
|
+
if (el.type === PdfElementType5.DATE_TIME || el.type === PdfElementType5.RADIO_GROUP || el.type === PdfElementType5.SELECT) {
|
|
3277
|
+
return el.value ?? "";
|
|
3278
|
+
}
|
|
3279
|
+
if (el.type === PdfElementType5.SIGNATURE) {
|
|
3280
|
+
return el.signatureDataUri || el.signerName || "";
|
|
3281
|
+
}
|
|
3282
|
+
if (el.type === PdfElementType5.TEXT) {
|
|
3283
|
+
return el.content ?? "";
|
|
3284
|
+
}
|
|
3285
|
+
return void 0;
|
|
3286
|
+
}
|
|
3287
|
+
var FUniverPdfsMixin = class extends FUniver {
|
|
3288
|
+
_getFormValuesByUnit() {
|
|
3289
|
+
if (!this._lastFormValuesByUnit) {
|
|
3290
|
+
this._lastFormValuesByUnit = /* @__PURE__ */ new Map();
|
|
3291
|
+
}
|
|
3292
|
+
return this._lastFormValuesByUnit;
|
|
3293
|
+
}
|
|
3294
|
+
_ensurePdfServiceEventWiring(injector = this._injector) {
|
|
3295
|
+
if (this._pdfServiceEventsWired) return;
|
|
3296
|
+
if (!injector.has(IPdfIoService2) || !injector.has(IPdfSelectionService2)) return;
|
|
3297
|
+
this._pdfServiceEventsWired = true;
|
|
3298
|
+
const ioService = injector.get(IPdfIoService2);
|
|
3299
|
+
const selectionService = injector.get(IPdfSelectionService2);
|
|
3300
|
+
const initialState = selectionService.getState();
|
|
3301
|
+
let prevPageId = initialState.activePageId;
|
|
3302
|
+
let prevSelectedKey = initialState.selectedElementIds.join("\0");
|
|
3303
|
+
const stateSub = selectionService.state$.pipe(skip(1)).subscribe((state) => {
|
|
3304
|
+
const pdf = (state.unitId ? this.getPdf(state.unitId) : null) ?? this.getActivePdf();
|
|
3305
|
+
if (!pdf) {
|
|
3306
|
+
prevPageId = state.activePageId;
|
|
3307
|
+
prevSelectedKey = state.selectedElementIds.join("\0");
|
|
3308
|
+
return;
|
|
3309
|
+
}
|
|
3310
|
+
if (state.activePageId !== prevPageId) {
|
|
3311
|
+
prevPageId = state.activePageId;
|
|
3312
|
+
this.fireEvent(this.Event.PdfPageChanged, {
|
|
3313
|
+
pdf,
|
|
3314
|
+
unitId: pdf.getId(),
|
|
3315
|
+
pageId: state.activePageId,
|
|
3316
|
+
page: state.activePageId ? pdf.getPageById(state.activePageId) : null
|
|
3317
|
+
});
|
|
3318
|
+
}
|
|
3319
|
+
const nextSelectedKey = state.selectedElementIds.join("\0");
|
|
3320
|
+
if (nextSelectedKey !== prevSelectedKey) {
|
|
3321
|
+
prevSelectedKey = nextSelectedKey;
|
|
3322
|
+
const pageId = state.activePageId ?? pdf.getDocument().pageOrder[0] ?? null;
|
|
3323
|
+
const page = pageId ? pdf.getPageById(pageId) : null;
|
|
3324
|
+
const elements = page ? state.selectedElementIds.map((id) => page.getElementById(id)).filter((item) => item !== null) : [];
|
|
3325
|
+
this.fireEvent(this.Event.PdfElementSelected, {
|
|
3326
|
+
pdf,
|
|
3327
|
+
unitId: pdf.getId(),
|
|
3328
|
+
pageId,
|
|
3329
|
+
elementIds: [...state.selectedElementIds],
|
|
3330
|
+
elements
|
|
3331
|
+
});
|
|
3332
|
+
}
|
|
3333
|
+
});
|
|
3334
|
+
this.disposeWithMe(toDisposable(() => stateSub.unsubscribe()));
|
|
3335
|
+
const beforeExpDisp = ioService.registerBeforeExportHook((hookParams) => {
|
|
3336
|
+
const eventParams = {
|
|
3337
|
+
pdf: this.getPdf(hookParams.unitId) ?? void 0,
|
|
3338
|
+
unitId: hookParams.unitId,
|
|
3339
|
+
snapshot: hookParams.snapshot,
|
|
3340
|
+
data: hookParams.data,
|
|
3341
|
+
options: hookParams.options,
|
|
3342
|
+
cancel: false
|
|
3343
|
+
};
|
|
3344
|
+
this.fireEvent(this.Event.BeforePdfExport, eventParams);
|
|
3345
|
+
if (eventParams.cancel) {
|
|
3346
|
+
hookParams.cancel = true;
|
|
3347
|
+
}
|
|
3348
|
+
});
|
|
3349
|
+
this.disposeWithMe(beforeExpDisp);
|
|
3350
|
+
const expSub = ioService.exported$.subscribe((info) => {
|
|
3351
|
+
this.fireEvent(this.Event.PdfExported, {
|
|
3352
|
+
pdf: this.getPdf(info.unitId) ?? void 0,
|
|
3353
|
+
unitId: info.unitId,
|
|
3354
|
+
bytes: info.bytes,
|
|
3355
|
+
byteLength: info.byteLength
|
|
3356
|
+
});
|
|
3357
|
+
});
|
|
3358
|
+
this.disposeWithMe(toDisposable(() => expSub.unsubscribe()));
|
|
3359
|
+
const beforePrintDisp = ioService.registerBeforePrintHook((hookParams) => {
|
|
3360
|
+
const eventParams = {
|
|
3361
|
+
pdf: this.getPdf(hookParams.unitId) ?? void 0,
|
|
3362
|
+
unitId: hookParams.unitId,
|
|
3363
|
+
snapshot: hookParams.snapshot,
|
|
3364
|
+
mode: hookParams.mode,
|
|
3365
|
+
options: hookParams.options,
|
|
3366
|
+
cancel: false
|
|
3367
|
+
};
|
|
3368
|
+
this.fireEvent(this.Event.BeforePdfPrint, eventParams);
|
|
3369
|
+
if (eventParams.cancel) {
|
|
3370
|
+
hookParams.cancel = true;
|
|
3371
|
+
}
|
|
3372
|
+
});
|
|
3373
|
+
this.disposeWithMe(beforePrintDisp);
|
|
3374
|
+
}
|
|
3375
|
+
_initialize(injector) {
|
|
3376
|
+
this._ensurePdfServiceEventWiring(injector);
|
|
3377
|
+
const addedSub = this._univerInstanceService.getTypeOfUnitAdded$(UniverInstanceType.UNIVER_PDF).subscribe((evtOrModel) => {
|
|
3378
|
+
this._ensurePdfServiceEventWiring(injector);
|
|
3379
|
+
const model = evtOrModel && typeof evtOrModel === "object" && "unit" in evtOrModel ? evtOrModel.unit : evtOrModel;
|
|
3380
|
+
if (!model || typeof model.getUnitId !== "function") return;
|
|
3381
|
+
const unitId = model.getUnitId();
|
|
3382
|
+
this._getFormValuesByUnit().set(unitId, extractPdfFormValues2(model.save()));
|
|
3383
|
+
const pdf = injector.createInstance(FPdf, model);
|
|
3384
|
+
this.fireEvent(this.Event.PdfLoaded, {
|
|
3385
|
+
pdf,
|
|
3386
|
+
unitId
|
|
3387
|
+
});
|
|
3388
|
+
});
|
|
3389
|
+
this.disposeWithMe(toDisposable(() => addedSub.unsubscribe()));
|
|
3390
|
+
const disposedSub = this._univerInstanceService.getTypeOfUnitDisposed$(UniverInstanceType.UNIVER_PDF).subscribe((evtOrModel) => {
|
|
3391
|
+
const model = evtOrModel && typeof evtOrModel === "object" && "unit" in evtOrModel ? evtOrModel.unit : evtOrModel;
|
|
3392
|
+
if (!model || typeof model.getUnitId !== "function") return;
|
|
3393
|
+
const unitId = model.getUnitId();
|
|
3394
|
+
this._getFormValuesByUnit().delete(unitId);
|
|
3395
|
+
this.fireEvent(this.Event.PdfDisposed, {
|
|
3396
|
+
unitId
|
|
3397
|
+
});
|
|
3398
|
+
});
|
|
3399
|
+
this.disposeWithMe(toDisposable(() => disposedSub.unsubscribe()));
|
|
3400
|
+
const commandService = injector.get(ICommandService2);
|
|
3401
|
+
this.disposeWithMe(
|
|
3402
|
+
commandService.onCommandExecuted((cmdInfo) => {
|
|
3403
|
+
if (cmdInfo.id === UpdatePdfElementsCommand3.id && cmdInfo.params) {
|
|
3404
|
+
const params = cmdInfo.params;
|
|
3405
|
+
const model = params.unitId ? this._univerInstanceService.getUnit(
|
|
3406
|
+
params.unitId,
|
|
3407
|
+
UniverInstanceType.UNIVER_PDF
|
|
3408
|
+
) : this._univerInstanceService.getCurrentUnitOfType(
|
|
3409
|
+
UniverInstanceType.UNIVER_PDF
|
|
3410
|
+
);
|
|
3411
|
+
if (!model) return;
|
|
3412
|
+
const unitId = model.getUnitId();
|
|
3413
|
+
const pageId = params.pageId ?? (injector.has(IPdfSelectionService2) ? injector.get(IPdfSelectionService2).getActivePageId() : null) ?? model.getPageOrder()[0];
|
|
3414
|
+
if (!pageId) return;
|
|
3415
|
+
const elementsMap = model.getElementsByPage(pageId);
|
|
3416
|
+
const pdf = injector.createInstance(FPdf, model);
|
|
3417
|
+
for (const upd of params.updates ?? []) {
|
|
3418
|
+
const el = elementsMap[upd.id];
|
|
3419
|
+
if (!el || !isFormFieldElement(el)) continue;
|
|
3420
|
+
const p = upd.patch;
|
|
3421
|
+
if (!("checked" in p) && !("value" in p) && !("content" in p) && !("signerName" in p) && !("signatureDataUri" in p)) {
|
|
3422
|
+
continue;
|
|
3423
|
+
}
|
|
3424
|
+
const fieldName = el.formFieldName || el.fieldKey || el.bindingField || el.name || el.id;
|
|
3425
|
+
const value = readElementFormValue(el);
|
|
3426
|
+
const prevMap = this._getFormValuesByUnit().get(unitId) ?? {};
|
|
3427
|
+
prevMap[fieldName] = typeof value === "boolean" ? value : String(value ?? "");
|
|
3428
|
+
this._getFormValuesByUnit().set(unitId, prevMap);
|
|
3429
|
+
this.fireEvent(this.Event.PdfFormFieldChanged, {
|
|
3430
|
+
pdf,
|
|
3431
|
+
unitId,
|
|
3432
|
+
pageId,
|
|
3433
|
+
elementId: el.id,
|
|
3434
|
+
fieldName,
|
|
3435
|
+
value
|
|
3436
|
+
});
|
|
3437
|
+
}
|
|
3438
|
+
} else if (cmdInfo.id === ReplacePdfSnapshotCommand2.id && cmdInfo.params) {
|
|
3439
|
+
const params = cmdInfo.params;
|
|
3440
|
+
const model = params.unitId ? this._univerInstanceService.getUnit(
|
|
3441
|
+
params.unitId,
|
|
3442
|
+
UniverInstanceType.UNIVER_PDF
|
|
3443
|
+
) : this._univerInstanceService.getCurrentUnitOfType(
|
|
3444
|
+
UniverInstanceType.UNIVER_PDF
|
|
3445
|
+
);
|
|
3446
|
+
if (!model) return;
|
|
3447
|
+
const unitId = model.getUnitId();
|
|
3448
|
+
const prevValues = this._getFormValuesByUnit().get(unitId) ?? {};
|
|
3449
|
+
const nextSnap = model.save();
|
|
3450
|
+
const nextValues = extractPdfFormValues2(nextSnap);
|
|
3451
|
+
this._getFormValuesByUnit().set(unitId, nextValues);
|
|
3452
|
+
const pdf = injector.createInstance(FPdf, model);
|
|
3453
|
+
for (const pid of nextSnap.document.pageOrder) {
|
|
3454
|
+
const map = nextSnap.editState.elementsByPage[pid] ?? {};
|
|
3455
|
+
for (const el of Object.values(map)) {
|
|
3456
|
+
if (!el || el.hidden || !isFormFieldElement(el)) continue;
|
|
3457
|
+
const fieldName = el.formFieldName || el.fieldKey || el.bindingField || el.name || el.id;
|
|
3458
|
+
if (Object.prototype.hasOwnProperty.call(nextValues, fieldName) && prevValues[fieldName] !== nextValues[fieldName]) {
|
|
3459
|
+
this.fireEvent(this.Event.PdfFormFieldChanged, {
|
|
3460
|
+
pdf,
|
|
3461
|
+
unitId,
|
|
3462
|
+
pageId: pid,
|
|
3463
|
+
elementId: el.id,
|
|
3464
|
+
fieldName,
|
|
3465
|
+
value: nextValues[fieldName]
|
|
3466
|
+
});
|
|
3467
|
+
}
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
})
|
|
3472
|
+
);
|
|
3473
|
+
}
|
|
3474
|
+
createPdf(data, options) {
|
|
3475
|
+
this._ensurePdfServiceEventWiring();
|
|
3476
|
+
const model = this._univerInstanceService.createUnit(
|
|
3477
|
+
UniverInstanceType.UNIVER_PDF,
|
|
3478
|
+
data ?? {},
|
|
3479
|
+
options
|
|
3480
|
+
);
|
|
3481
|
+
return this._injector.createInstance(FPdf, model);
|
|
3482
|
+
}
|
|
3483
|
+
getActivePdf() {
|
|
3484
|
+
this._ensurePdfServiceEventWiring();
|
|
3485
|
+
const model = this._univerInstanceService.getCurrentUnitOfType(
|
|
3486
|
+
UniverInstanceType.UNIVER_PDF
|
|
3487
|
+
);
|
|
3488
|
+
if (!model) return null;
|
|
3489
|
+
return this._injector.createInstance(FPdf, model);
|
|
3490
|
+
}
|
|
3491
|
+
getPdf(unitId) {
|
|
3492
|
+
this._ensurePdfServiceEventWiring();
|
|
3493
|
+
const model = this._univerInstanceService.getUnit(
|
|
3494
|
+
unitId,
|
|
3495
|
+
UniverInstanceType.UNIVER_PDF
|
|
3496
|
+
);
|
|
3497
|
+
if (!model) return null;
|
|
3498
|
+
return this._injector.createInstance(FPdf, model);
|
|
3499
|
+
}
|
|
3500
|
+
setPdfIoAdapter(adapter) {
|
|
3501
|
+
this._ensurePdfServiceEventWiring();
|
|
3502
|
+
this._injector.get(IPdfIoService2).setAdapter(adapter);
|
|
3503
|
+
}
|
|
3504
|
+
getPdfIoAdapter() {
|
|
3505
|
+
this._ensurePdfServiceEventWiring();
|
|
3506
|
+
return this._injector.get(IPdfIoService2).getAdapter();
|
|
3507
|
+
}
|
|
3508
|
+
setPdfAiCopilotAdapter(adapter) {
|
|
3509
|
+
this._ensurePdfServiceEventWiring();
|
|
3510
|
+
this._injector.get(IPdfIoService2).setAiCopilotAdapter(adapter);
|
|
3511
|
+
}
|
|
3512
|
+
getPdfAiCopilotAdapter() {
|
|
3513
|
+
this._ensurePdfServiceEventWiring();
|
|
3514
|
+
return this._injector.get(IPdfIoService2).getAiCopilotAdapter();
|
|
3515
|
+
}
|
|
3516
|
+
async generateTemplateByAi(prompt, options) {
|
|
3517
|
+
this._ensurePdfServiceEventWiring();
|
|
3518
|
+
const snapshot = await this._injector.get(IPdfIoService2).generateTemplateByAi(prompt);
|
|
3519
|
+
return this.createPdf(snapshot, options);
|
|
3520
|
+
}
|
|
3521
|
+
registerOcrAdapter(adapter) {
|
|
3522
|
+
this._ensurePdfServiceEventWiring();
|
|
3523
|
+
this._injector.get(IPdfIoService2).setOcrAdapter(adapter);
|
|
3524
|
+
}
|
|
3525
|
+
async importAcroFormPdf(pdfBytes, options, createOptions) {
|
|
3526
|
+
const snapshot = await importAcroFormPdfToUnit2(pdfBytes, options);
|
|
3527
|
+
return this.createPdf(snapshot, createOptions);
|
|
3528
|
+
}
|
|
3529
|
+
async importPdfToSnapshotAsync(source, options) {
|
|
3530
|
+
const imported = await importPdfSource2(source, options);
|
|
3531
|
+
if (options?.importAcroForm) {
|
|
3532
|
+
return await importAcroFormPdfToUnit2(imported.bytes, {
|
|
3533
|
+
unitId: options.unitId,
|
|
3534
|
+
title: options.fileName || imported.sourceDocumentRef.fileName
|
|
3535
|
+
});
|
|
3536
|
+
}
|
|
3537
|
+
const pageOrder = imported.pageSizes.map((_, idx) => `page-${idx + 1}`);
|
|
3538
|
+
const pages = {};
|
|
3539
|
+
const elementsByPage = {};
|
|
3540
|
+
const elementOrderByPage = {};
|
|
3541
|
+
imported.pageSizes.forEach((sz, idx) => {
|
|
3542
|
+
const pid = pageOrder[idx];
|
|
3543
|
+
pages[pid] = {
|
|
3544
|
+
id: pid,
|
|
3545
|
+
title: `Page ${idx + 1}`,
|
|
3546
|
+
backgroundColor: "#ffffff",
|
|
3547
|
+
sourcePageNumber: idx + 1,
|
|
3548
|
+
pageSize: { ...sz }
|
|
3549
|
+
};
|
|
3550
|
+
elementsByPage[pid] = {};
|
|
3551
|
+
elementOrderByPage[pid] = [];
|
|
3552
|
+
});
|
|
3553
|
+
const nativeTextSpansByPage = options?.extractNativeText !== false ? await extractNativeTextSpansFromPdfBytes2(imported.bytes, pageOrder) : void 0;
|
|
3554
|
+
return createDefaultPdfUnitData({
|
|
3555
|
+
id: options?.unitId || `pdf-${generateRandomId4(6)}`,
|
|
3556
|
+
name: (options?.fileName || imported.sourceDocumentRef.fileName || "Imported PDF").replace(
|
|
3557
|
+
/\.pdf$/i,
|
|
3558
|
+
""
|
|
3559
|
+
),
|
|
3560
|
+
sourceDocumentRef: imported.sourceDocumentRef,
|
|
3561
|
+
document: {
|
|
3562
|
+
pageSize: { ...imported.pageSizes[0] ?? { width: 595.28, height: 841.89 } },
|
|
3563
|
+
pages,
|
|
3564
|
+
pageOrder
|
|
3565
|
+
},
|
|
3566
|
+
editState: {
|
|
3567
|
+
elementsByPage,
|
|
3568
|
+
elementOrderByPage,
|
|
3569
|
+
...nativeTextSpansByPage ? { nativeTextSpansByPage } : {}
|
|
3570
|
+
},
|
|
3571
|
+
metadata: nativeTextSpansByPage ? { nativeTextSpansByPage } : {}
|
|
3572
|
+
});
|
|
3573
|
+
}
|
|
3574
|
+
async importPdfToUnitIdAsync(source, options) {
|
|
3575
|
+
const snapshot = await this.importPdfToSnapshotAsync(source, options);
|
|
3576
|
+
const pdf = this.createPdf(snapshot, {
|
|
3577
|
+
makeCurrent: options?.makeCurrent ?? true
|
|
3578
|
+
});
|
|
3579
|
+
return pdf.getId();
|
|
3580
|
+
}
|
|
3581
|
+
async exportPdfBySnapshotAsync(snapshot, data, options) {
|
|
3582
|
+
this._ensurePdfServiceEventWiring();
|
|
3583
|
+
if (this._injector.has(IPdfIoService2)) {
|
|
3584
|
+
const ioService = this._injector.get(IPdfIoService2);
|
|
3585
|
+
const cancelled = ioService.runBeforeExportHooks({
|
|
3586
|
+
unitId: snapshot.id,
|
|
3587
|
+
snapshot,
|
|
3588
|
+
data,
|
|
3589
|
+
options,
|
|
3590
|
+
cancel: false
|
|
3591
|
+
});
|
|
3592
|
+
if (cancelled) {
|
|
3593
|
+
throw new CanceledError2();
|
|
3594
|
+
}
|
|
3595
|
+
const bytes = await exportPdfBytes2(snapshot, data, options);
|
|
3596
|
+
ioService.notifyExported({
|
|
3597
|
+
unitId: snapshot.id,
|
|
3598
|
+
bytes,
|
|
3599
|
+
byteLength: bytes.byteLength,
|
|
3600
|
+
options
|
|
3601
|
+
});
|
|
3602
|
+
return bytes;
|
|
3603
|
+
}
|
|
3604
|
+
return await exportPdfBytes2(snapshot, data, options);
|
|
3605
|
+
}
|
|
3606
|
+
async exportPdfByUnitIdAsync(unitId, data, options) {
|
|
3607
|
+
this._ensurePdfServiceEventWiring();
|
|
3608
|
+
const pdf = this.getPdf(unitId);
|
|
3609
|
+
if (!pdf) {
|
|
3610
|
+
throw new Error(`[UniverPdfs] PDF unit "${unitId}" was not found.`);
|
|
3611
|
+
}
|
|
3612
|
+
return await pdf.exportPdf(data, options);
|
|
3613
|
+
}
|
|
3614
|
+
async appendPdfAsync(arg1, arg2, options) {
|
|
3615
|
+
this._ensurePdfServiceEventWiring();
|
|
3616
|
+
if (arg1 instanceof FPdf) {
|
|
3617
|
+
if (arg2 === void 0) {
|
|
3618
|
+
throw new Error("[UniverPdfs] appendPdfAsync(pdf, source) requires a PDF source.");
|
|
3619
|
+
}
|
|
3620
|
+
return await arg1.appendPdf(arg2, options);
|
|
3621
|
+
}
|
|
3622
|
+
if (isBinaryOrSnapshotAppendSource(arg1)) {
|
|
3623
|
+
const targetUnitId = typeof arg2 === "string" ? arg2 : void 0;
|
|
3624
|
+
const target = targetUnitId ? this.getPdf(targetUnitId) : this.getActivePdf();
|
|
3625
|
+
if (!target) {
|
|
3626
|
+
throw new Error(
|
|
3627
|
+
targetUnitId ? `[UniverPdfs] Target PDF unit "${targetUnitId}" was not found.` : "[UniverPdfs] No active PDF unit found for appendPdfAsync()."
|
|
3628
|
+
);
|
|
3629
|
+
}
|
|
3630
|
+
return await target.appendPdf(arg1, options);
|
|
3631
|
+
}
|
|
3632
|
+
if (typeof arg1 === "string") {
|
|
3633
|
+
const asTarget = arg2 !== void 0 ? this.getPdf(arg1) : null;
|
|
3634
|
+
if (asTarget && arg2 !== void 0) {
|
|
3635
|
+
return await asTarget.appendPdf(arg2, options);
|
|
3636
|
+
}
|
|
3637
|
+
const targetUnitId = typeof arg2 === "string" ? arg2 : void 0;
|
|
3638
|
+
const target = targetUnitId ? this.getPdf(targetUnitId) : this.getActivePdf();
|
|
3639
|
+
if (!target) {
|
|
3640
|
+
throw new Error(
|
|
3641
|
+
arg2 !== void 0 && !targetUnitId ? `[UniverPdfs] Target PDF unit "${arg1}" was not found.` : `[UniverPdfs] Target PDF unit "${targetUnitId ?? arg1}" was not found.`
|
|
3642
|
+
);
|
|
3643
|
+
}
|
|
3644
|
+
return await target.appendPdf(arg1, options);
|
|
3645
|
+
}
|
|
3646
|
+
throw new Error("[UniverPdfs] Invalid arguments passed to appendPdfAsync().");
|
|
3647
|
+
}
|
|
3648
|
+
async exportPdfAsync(unitIdOrPdf, data, options) {
|
|
3649
|
+
this._ensurePdfServiceEventWiring();
|
|
3650
|
+
const target = typeof unitIdOrPdf === "string" ? this.getPdf(unitIdOrPdf) : unitIdOrPdf ?? this.getActivePdf();
|
|
3651
|
+
if (!target) {
|
|
3652
|
+
throw new Error("[UniverPdfs] No active or matching PDF unit found for exportPdfAsync().");
|
|
3653
|
+
}
|
|
3654
|
+
return await target.exportPdf(data, options);
|
|
3655
|
+
}
|
|
3656
|
+
getPdfTableThemePresets() {
|
|
3657
|
+
return Tools4.deepClone([...PDF_TABLE_THEME_PRESETS2]);
|
|
3658
|
+
}
|
|
3659
|
+
};
|
|
3660
|
+
FUniver.extend(FUniverPdfsMixin);
|
|
3661
|
+
export {
|
|
3662
|
+
FEnumPdfsMixin,
|
|
3663
|
+
FEventNamePdfsMixin,
|
|
3664
|
+
FPdf,
|
|
3665
|
+
FPdfAnnotation,
|
|
3666
|
+
FPdfDivider,
|
|
3667
|
+
FPdf as FPdfDocument,
|
|
3668
|
+
FPdfImage,
|
|
3669
|
+
FPdfImageBuilder,
|
|
3670
|
+
FPdfList,
|
|
3671
|
+
FPdfPage,
|
|
3672
|
+
FPdfPageElement,
|
|
3673
|
+
FPdfParagraph,
|
|
3674
|
+
FPdfTable,
|
|
3675
|
+
FPdfTableCell,
|
|
3676
|
+
FPdfTextBox,
|
|
3677
|
+
FPdfTextSpan,
|
|
3678
|
+
FUniverPdfsMixin,
|
|
3679
|
+
wrapPdfElementFacade
|
|
3680
|
+
};
|
|
3681
|
+
//# sourceMappingURL=index.js.map
|