@yudaocode/univer-docs 0.0.0-stage → 1.6.204

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.
@@ -0,0 +1,1842 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __decorateClass = (decorators, target, key, kind) => {
20
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
21
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
22
+ if (decorator = decorators[i])
23
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
24
+ if (kind && result) __defProp(target, key, result);
25
+ return result;
26
+ };
27
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
28
+
29
+ // src/facade/index.ts
30
+ var facade_exports = {};
31
+ __export(facade_exports, {
32
+ FDocumentExtMixin: () => FEnterpriseDoc,
33
+ FEnterpriseDoc: () => FEnterpriseDoc,
34
+ FUniverDocsExtMixin: () => FUniverDocsExtMixin
35
+ });
36
+ module.exports = __toCommonJS(facade_exports);
37
+
38
+ // src/facade/f-doc-ext.ts
39
+ var import_core = require("@univerjs/core");
40
+ var import_docs = require("@univerjs/docs");
41
+ var import_univer_docs = require("@yudaocode/univer-docs");
42
+ var FEnterpriseDoc = class {
43
+ constructor(_docModel, _injector, _commandService) {
44
+ this._docModel = _docModel;
45
+ this._injector = _injector;
46
+ this._commandService = _commandService;
47
+ }
48
+ getId() {
49
+ return this._docModel.getUnitId();
50
+ }
51
+ getTitle() {
52
+ return this._docModel.getSnapshot().title || "";
53
+ }
54
+ save() {
55
+ return this._docModel.getSnapshot();
56
+ }
57
+ getMode() {
58
+ return this._injector.get(import_univer_docs.IDocSdtService).getDocMode(this.getId());
59
+ }
60
+ setMode(mode) {
61
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocModeCommand.id, {
62
+ unitId: this.getId(),
63
+ mode
64
+ });
65
+ }
66
+ setTemplateMetadata(metadata) {
67
+ this._injector.get(import_univer_docs.IDocSdtService).setTemplateMetadata(this.getId(), metadata);
68
+ }
69
+ getTemplateMetadata() {
70
+ return this._injector.get(import_univer_docs.IDocSdtService).getTemplateMetadata(this.getId());
71
+ }
72
+ getTables() {
73
+ return (0, import_univer_docs.listDocTables)(this.save());
74
+ }
75
+ setTableRowLoop(tableId, rowIndex, config) {
76
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocTableRowLoopCommand.id, {
77
+ unitId: this.getId(),
78
+ tableId,
79
+ rowIndex,
80
+ config
81
+ });
82
+ }
83
+ insertSdtControl(spec, initialValue, offset, segmentId) {
84
+ return this._commandService.syncExecuteCommand(import_univer_docs.InsertDocSdtCommand.id, {
85
+ unitId: this.getId(),
86
+ offset,
87
+ segmentId,
88
+ spec,
89
+ initialValue
90
+ });
91
+ }
92
+ updateSdtValue(controlId, value, force = false, segmentId) {
93
+ return this._commandService.syncExecuteCommand(import_univer_docs.UpdateDocSdtValueCommand.id, {
94
+ unitId: this.getId(),
95
+ controlId,
96
+ value,
97
+ force,
98
+ segmentId
99
+ });
100
+ }
101
+ updateSdtProperties(controlId, patch, segmentId) {
102
+ return this._commandService.syncExecuteCommand(import_univer_docs.UpdateDocSdtPropertiesCommand.id, {
103
+ unitId: this.getId(),
104
+ controlId,
105
+ patch,
106
+ segmentId
107
+ });
108
+ }
109
+ deleteSdtControl(controlId, keepText = false, force = false, segmentId) {
110
+ return this._commandService.syncExecuteCommand(import_univer_docs.DeleteDocSdtCommand.id, {
111
+ unitId: this.getId(),
112
+ controlId,
113
+ keepText,
114
+ force,
115
+ segmentId
116
+ });
117
+ }
118
+ getSdtControls(options) {
119
+ return (0, import_univer_docs.listDocSdtControls)(this.save(), options);
120
+ }
121
+ getFormValues() {
122
+ return (0, import_univer_docs.extractDocFormValues)(this.save());
123
+ }
124
+ validateForm() {
125
+ return (0, import_univer_docs.validateDocForm)(this.save());
126
+ }
127
+ fillDataset(data) {
128
+ return this._commandService.syncExecuteCommand(import_univer_docs.FillDocDatasetCommand.id, {
129
+ unitId: this.getId(),
130
+ data
131
+ });
132
+ }
133
+ // ---- Contract Track Changes (`修订留痕`) ----
134
+ setTrackChanges(enabled, author) {
135
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocTrackChangesCommand.id, {
136
+ unitId: this.getId(),
137
+ enabled,
138
+ author
139
+ });
140
+ }
141
+ insertTrackedText(text, index, author) {
142
+ return this._commandService.syncExecuteCommand(import_univer_docs.RecordDocRevisionCommand.id, {
143
+ unitId: this.getId(),
144
+ type: "insert",
145
+ text,
146
+ index,
147
+ author
148
+ });
149
+ }
150
+ markTrackedDeletion(startIndex, endIndex, author) {
151
+ const stream = this.save().body?.dataStream ?? "";
152
+ const text = stream.slice(startIndex, endIndex).replace(/[\r\n\u0000-\u001F]/g, "");
153
+ return this._commandService.syncExecuteCommand(import_univer_docs.RecordDocRevisionCommand.id, {
154
+ unitId: this.getId(),
155
+ type: "delete",
156
+ text,
157
+ index: startIndex,
158
+ endIndex,
159
+ author
160
+ });
161
+ }
162
+ acceptRevision(revisionId) {
163
+ return this._commandService.syncExecuteCommand(import_univer_docs.ResolveDocRevisionCommand.id, {
164
+ unitId: this.getId(),
165
+ revisionId,
166
+ action: "accept"
167
+ });
168
+ }
169
+ rejectRevision(revisionId) {
170
+ return this._commandService.syncExecuteCommand(import_univer_docs.ResolveDocRevisionCommand.id, {
171
+ unitId: this.getId(),
172
+ revisionId,
173
+ action: "reject"
174
+ });
175
+ }
176
+ acceptAllRevisions() {
177
+ return this._commandService.syncExecuteCommand(import_univer_docs.ResolveDocRevisionCommand.id, {
178
+ unitId: this.getId(),
179
+ action: "accept",
180
+ all: true
181
+ });
182
+ }
183
+ rejectAllRevisions() {
184
+ return this._commandService.syncExecuteCommand(import_univer_docs.ResolveDocRevisionCommand.id, {
185
+ unitId: this.getId(),
186
+ action: "reject",
187
+ all: true
188
+ });
189
+ }
190
+ getRevisions() {
191
+ return this.getTemplateMetadata().revisions ?? [];
192
+ }
193
+ // ---- AI Contract Risk Auditor & Clause Drafter ----
194
+ async auditContractRisks() {
195
+ return this._injector.get(import_univer_docs.IDocAiCopilotService).auditContract(this.getId(), this.save());
196
+ }
197
+ async draftClauseByAi(prompt) {
198
+ return this._injector.get(import_univer_docs.IDocAiCopilotService).draftClause(this.getId(), this.save(), prompt);
199
+ }
200
+ // ---- IO & Export ----
201
+ getIoCapabilities() {
202
+ return this._injector.get(import_univer_docs.IDocIoService).getIoCapabilities();
203
+ }
204
+ async importDocFileWithReport(file, options) {
205
+ const outcome = await this._injector.get(import_univer_docs.IDocIoService).importDocWithReport(file, {
206
+ unitId: this.getId(),
207
+ target: options?.target
208
+ });
209
+ if (outcome.documentData.body) {
210
+ this._commandService.syncExecuteCommand(import_univer_docs.ReplaceDocUnitSnapshotCommand.id, {
211
+ unitId: this.getId(),
212
+ snapshot: outcome.documentData
213
+ });
214
+ }
215
+ return outcome;
216
+ }
217
+ async importDocFile(file, options) {
218
+ const outcome = await this.importDocFileWithReport(file, options);
219
+ return outcome.documentData;
220
+ }
221
+ async exportDocx(data, options) {
222
+ return this._injector.get(import_univer_docs.IDocIoService).exportDoc({
223
+ unitId: this.getId(),
224
+ snapshot: this.save(),
225
+ format: "docx",
226
+ data,
227
+ pdfOptions: options?.signatureImageDataUrl ? { signatureImageDataUrl: options.signatureImageDataUrl } : void 0,
228
+ target: options?.target
229
+ });
230
+ }
231
+ async exportPdf(pdfOptions, options) {
232
+ return this._injector.get(import_univer_docs.IDocIoService).exportDoc({
233
+ unitId: this.getId(),
234
+ snapshot: this.save(),
235
+ format: "pdf",
236
+ data: options?.data ?? pdfOptions?.data,
237
+ pdfOptions,
238
+ target: options?.target
239
+ });
240
+ }
241
+ getCatalog() {
242
+ return (0, import_univer_docs.extractDocCatalog)(this.save());
243
+ }
244
+ getDocumentOutline() {
245
+ return (0, import_univer_docs.extractDocCatalog)(this.save());
246
+ }
247
+ evaluateTableFormulas() {
248
+ return this._commandService.syncExecuteCommand(import_univer_docs.EvaluateDocTableFormulasCommand.id, {
249
+ unitId: this.getId()
250
+ });
251
+ }
252
+ saveVersion(label) {
253
+ return this._injector.get(import_univer_docs.IDocSdtService).saveVersionSnapshot(this.getId(), label);
254
+ }
255
+ getVersions() {
256
+ return this._injector.get(import_univer_docs.IDocSdtService).listVersionSnapshots(this.getId());
257
+ }
258
+ restoreVersion(versionId) {
259
+ return this._commandService.syncExecuteCommand(import_univer_docs.RestoreDocVersionCommand.id, {
260
+ unitId: this.getId(),
261
+ versionId
262
+ });
263
+ }
264
+ async exportHtml(data, printOptions, options) {
265
+ if (printOptions && options?.target !== "server") {
266
+ return (0, import_univer_docs.exportDocHtmlString)(this.save(), data, printOptions);
267
+ }
268
+ const bytes = await this._injector.get(import_univer_docs.IDocIoService).exportDoc({
269
+ unitId: this.getId(),
270
+ snapshot: this.save(),
271
+ format: "html",
272
+ data,
273
+ target: options?.target
274
+ });
275
+ return new TextDecoder().decode(bytes);
276
+ }
277
+ async saveToHost() {
278
+ return this._injector.get(import_univer_docs.IDocIoService).saveToHost({
279
+ unitId: this.getId(),
280
+ snapshot: this.save()
281
+ });
282
+ }
283
+ // ---- v1.6.203 Medical Formulas, Code/Barcode Blocks, Co-Signing Roles, Stats, Diff & Batch Mail-Merge ----
284
+ insertMedicalFormula(spec, offset, blockId) {
285
+ return this._commandService.syncExecuteCommand(import_univer_docs.InsertDocMedicalFormulaCommand.id, {
286
+ unitId: this.getId(),
287
+ offset,
288
+ blockId,
289
+ spec
290
+ });
291
+ }
292
+ insertCodeBlock(codeOrSpec, language, offset) {
293
+ const code = typeof codeOrSpec === "string" ? codeOrSpec : codeOrSpec.code;
294
+ const resolvedLang = typeof codeOrSpec === "string" ? language : codeOrSpec.language ?? language;
295
+ const id = typeof codeOrSpec === "string" ? void 0 : codeOrSpec.id;
296
+ return this._commandService.syncExecuteCommand(import_univer_docs.InsertDocCodeBlockCommand.id, {
297
+ unitId: this.getId(),
298
+ id,
299
+ code,
300
+ language: resolvedLang,
301
+ offset
302
+ });
303
+ }
304
+ insertBarcodeOrQrBlock(spec, offset, blockId) {
305
+ return this._commandService.syncExecuteCommand(import_univer_docs.InsertDocQrOrBarcodeBlockCommand.id, {
306
+ unitId: this.getId(),
307
+ offset,
308
+ blockId,
309
+ spec
310
+ });
311
+ }
312
+ setActiveRole(role) {
313
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocActiveRoleCommand.id, {
314
+ unitId: this.getId(),
315
+ role
316
+ });
317
+ }
318
+ getActiveRole() {
319
+ return this._injector.get(import_univer_docs.IDocSdtService).getActiveRole(this.getId());
320
+ }
321
+ getStats() {
322
+ return (0, import_univer_docs.getDocumentStats)(this.save());
323
+ }
324
+ diffWith(other) {
325
+ const targetSnapshot = other instanceof FEnterpriseDoc ? other.save() : other;
326
+ return (0, import_univer_docs.diffDocSnapshots)(this.save(), targetSnapshot);
327
+ }
328
+ async exportBatchPdf(records, pdfOptions) {
329
+ return (0, import_univer_docs.exportBatchDocPdfBytes)(this.save(), records, pdfOptions);
330
+ }
331
+ async exportBatchDocx(records, fileNamePattern) {
332
+ return (0, import_univer_docs.exportBatchDocxFiles)(this.save(), records, fileNamePattern);
333
+ }
334
+ // ---- v1.6.204 Callout & Quote Blocks ----
335
+ insertCallout(spec, offset) {
336
+ const id = spec.id || `callout_${(0, import_core.generateRandomId)(6)}`;
337
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocCalloutCommand.id, {
338
+ unitId: this.getId(),
339
+ offset,
340
+ spec: { ...spec, id }
341
+ });
342
+ if (!ok) return null;
343
+ return this.getCallouts().find((c) => c.id === id) ?? null;
344
+ }
345
+ updateCallout(id, patch) {
346
+ return this._commandService.syncExecuteCommand(import_univer_docs.UpdateDocCalloutCommand.id, {
347
+ unitId: this.getId(),
348
+ id,
349
+ patch
350
+ });
351
+ }
352
+ removeCallout(id) {
353
+ return this._commandService.syncExecuteCommand(import_univer_docs.RemoveDocCalloutCommand.id, {
354
+ unitId: this.getId(),
355
+ id
356
+ });
357
+ }
358
+ getCallouts() {
359
+ return (0, import_univer_docs.listDocCallouts)(this.save());
360
+ }
361
+ insertQuote(spec, offset) {
362
+ const id = spec.id || `quote_${(0, import_core.generateRandomId)(6)}`;
363
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocQuoteCommand.id, {
364
+ unitId: this.getId(),
365
+ offset,
366
+ spec: { ...spec, id }
367
+ });
368
+ if (!ok) return null;
369
+ return this.getQuotes().find((q) => q.id === id) ?? null;
370
+ }
371
+ updateQuote(id, patch) {
372
+ return this._commandService.syncExecuteCommand(import_univer_docs.UpdateDocQuoteCommand.id, {
373
+ unitId: this.getId(),
374
+ id,
375
+ patch
376
+ });
377
+ }
378
+ removeQuote(id) {
379
+ return this._commandService.syncExecuteCommand(import_univer_docs.RemoveDocQuoteCommand.id, {
380
+ unitId: this.getId(),
381
+ id
382
+ });
383
+ }
384
+ getQuotes() {
385
+ return (0, import_univer_docs.listDocQuotes)(this.save());
386
+ }
387
+ // ---- v1.6.204 General-Purpose LaTeX Mathematical Formula Engine ----
388
+ insertLatexFormula(spec, offset) {
389
+ const id = spec.id || `latex_${(0, import_core.generateRandomId)(6)}`;
390
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocLatexFormulaCommand.id, {
391
+ unitId: this.getId(),
392
+ offset,
393
+ spec: { ...spec, id }
394
+ });
395
+ if (!ok) return null;
396
+ return this.getLatexFormulas().find((f) => f.id === id) ?? null;
397
+ }
398
+ updateLatexFormula(id, latexOrPatch) {
399
+ return this._commandService.syncExecuteCommand(import_univer_docs.UpdateDocLatexFormulaCommand.id, {
400
+ unitId: this.getId(),
401
+ id,
402
+ ...typeof latexOrPatch === "string" ? { latex: latexOrPatch } : { patch: latexOrPatch }
403
+ });
404
+ }
405
+ removeLatexFormula(id) {
406
+ return this._commandService.syncExecuteCommand(import_univer_docs.RemoveDocLatexFormulaCommand.id, {
407
+ unitId: this.getId(),
408
+ id
409
+ });
410
+ }
411
+ getLatexFormulas() {
412
+ return (0, import_univer_docs.listLiveLatexFormulas)(this.save());
413
+ }
414
+ findLatexFormulaByText(substr) {
415
+ const needle = (substr ?? "").trim();
416
+ if (!needle) return void 0;
417
+ return this.getLatexFormulas().find((f) => f.latex.includes(needle) || f.id === needle);
418
+ }
419
+ // ---- v1.6.204 Inline Document Data Formulas + Embedded Charts + Shapes ----
420
+ insertInlineFormula(spec, offset, extraVars) {
421
+ const id = spec.id || `ifml_${(0, import_core.generateRandomId)(6)}`;
422
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocInlineFormulaCommand.id, {
423
+ unitId: this.getId(),
424
+ offset,
425
+ spec: { ...spec, id },
426
+ extraVars
427
+ });
428
+ if (!ok) return null;
429
+ return this.getInlineFormulas().find((f) => f.id === id) ?? null;
430
+ }
431
+ recalculateInlineFormulas(extraVars) {
432
+ return this._commandService.syncExecuteCommand(import_univer_docs.RecalculateDocInlineFormulasCommand.id, {
433
+ unitId: this.getId(),
434
+ extraVars
435
+ });
436
+ }
437
+ getInlineFormulas() {
438
+ return (0, import_univer_docs.listDocInlineFormulas)(this.save());
439
+ }
440
+ insertDocChart(spec, offset) {
441
+ const id = spec.id || `chart_${(0, import_core.generateRandomId)(6)}`;
442
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocChartCommand.id, {
443
+ unitId: this.getId(),
444
+ offset,
445
+ spec: { ...spec, id }
446
+ });
447
+ if (!ok) return null;
448
+ return this.getDocCharts().find((c) => c.id === id) ?? null;
449
+ }
450
+ updateDocChart(id, patch) {
451
+ return this._commandService.syncExecuteCommand(import_univer_docs.UpdateDocChartCommand.id, {
452
+ unitId: this.getId(),
453
+ id,
454
+ patch
455
+ });
456
+ }
457
+ removeDocChart(id) {
458
+ return this._commandService.syncExecuteCommand(import_univer_docs.RemoveDocChartCommand.id, {
459
+ unitId: this.getId(),
460
+ id
461
+ });
462
+ }
463
+ getDocCharts() {
464
+ return (0, import_univer_docs.listLiveDocCharts)(this.save());
465
+ }
466
+ insertDocShape(spec, offset) {
467
+ const id = spec.id || `shape_${(0, import_core.generateRandomId)(6)}`;
468
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocShapeCommand.id, {
469
+ unitId: this.getId(),
470
+ offset,
471
+ spec: { ...spec, id }
472
+ });
473
+ if (!ok) return null;
474
+ return this.getDocShapes().find((s) => s.id === id) ?? null;
475
+ }
476
+ updateDocShape(id, patch) {
477
+ return this._commandService.syncExecuteCommand(import_univer_docs.UpdateDocShapeCommand.id, {
478
+ unitId: this.getId(),
479
+ id,
480
+ patch
481
+ });
482
+ }
483
+ removeDocShape(id) {
484
+ return this._commandService.syncExecuteCommand(import_univer_docs.RemoveDocShapeCommand.id, {
485
+ unitId: this.getId(),
486
+ id
487
+ });
488
+ }
489
+ getDocShapes() {
490
+ return (0, import_univer_docs.listLiveDocShapes)(this.save());
491
+ }
492
+ // ---- v1.6.204 Enhanced Document Tables (Sort, Repeat Header, Text/Table Conversion) ----
493
+ sortTableByColumn(tableIndex, columnIndex, direction = "asc", headerRowCount = 1) {
494
+ return this._commandService.syncExecuteCommand(import_univer_docs.SortDocTableCommand.id, {
495
+ unitId: this.getId(),
496
+ tableIndex,
497
+ columnIndex,
498
+ direction,
499
+ headerRowCount
500
+ });
501
+ }
502
+ setTableRepeatHeader(tableIndex, headerRowCount) {
503
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocTableRepeatHeaderCommand.id, {
504
+ unitId: this.getId(),
505
+ tableIndex,
506
+ headerRowCount
507
+ });
508
+ }
509
+ convertTextToTable(text, delimiter, offset) {
510
+ return this._commandService.syncExecuteCommand(import_univer_docs.ConvertTextToDocTableCommand.id, {
511
+ unitId: this.getId(),
512
+ text,
513
+ delimiter,
514
+ offset
515
+ });
516
+ }
517
+ convertTableToText(tableIndex, delimiter = " ") {
518
+ return (0, import_univer_docs.convertDocTableToText)(this.save(), tableIndex, delimiter);
519
+ }
520
+ // ---- v1.6.204 Repeating Section SDT, Bookmarks & Table of Contents ----
521
+ insertRepeatingSection(spec, offset) {
522
+ const id = spec.id || `rep_${(0, import_core.generateRandomId)(6)}`;
523
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocRepeatingSectionCommand.id, {
524
+ unitId: this.getId(),
525
+ offset,
526
+ spec: { ...spec, id }
527
+ });
528
+ if (!ok) return null;
529
+ return this.getSdtControls().find((c) => c.id === id) ?? null;
530
+ }
531
+ insertBookmark(spec) {
532
+ const id = spec.id || `bm_${(0, import_core.generateRandomId)(6)}`;
533
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocBookmarkCommand.id, {
534
+ unitId: this.getId(),
535
+ spec: { ...spec, id }
536
+ });
537
+ if (!ok) return null;
538
+ return this.getBookmarks().find((b) => b.id === id || b.name === spec.name) ?? null;
539
+ }
540
+ getBookmarks() {
541
+ return (0, import_univer_docs.listDocBookmarks)(this.save());
542
+ }
543
+ removeBookmark(nameOrId) {
544
+ return this._commandService.syncExecuteCommand(import_univer_docs.RemoveDocBookmarkCommand.id, {
545
+ unitId: this.getId(),
546
+ nameOrId
547
+ });
548
+ }
549
+ insertTableOfContents(spec, offset) {
550
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocTableOfContentsCommand.id, {
551
+ unitId: this.getId(),
552
+ offset,
553
+ spec
554
+ });
555
+ if (!ok) return null;
556
+ return this.getTemplateMetadata().tocConfig ?? null;
557
+ }
558
+ refreshTableOfContents() {
559
+ return this._commandService.syncExecuteCommand(import_univer_docs.RefreshDocTableOfContentsCommand.id, {
560
+ unitId: this.getId()
561
+ });
562
+ }
563
+ // ---- v1.6.204 Wave 2: Paragraph Borders/Shading/Divider, Tab Stops, Collapsible Headings & Find/Replace ----
564
+ setParagraphBorderAndShading(paragraphIndex, spec) {
565
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetParagraphBorderAndShadingCommand.id, {
566
+ unitId: this.getId(),
567
+ paragraphIndex,
568
+ spec
569
+ });
570
+ }
571
+ getParagraphBorderAndShading(paragraphIndex) {
572
+ return (0, import_univer_docs.getParagraphBorderAndShading)(this.save(), paragraphIndex);
573
+ }
574
+ insertHorizontalDivider(style = "single", offset) {
575
+ return this._commandService.syncExecuteCommand(import_univer_docs.InsertHorizontalDividerCommand.id, {
576
+ unitId: this.getId(),
577
+ style,
578
+ offset
579
+ });
580
+ }
581
+ setParagraphTabStops(paragraphIndex, tabStops) {
582
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetParagraphTabStopsCommand.id, {
583
+ unitId: this.getId(),
584
+ paragraphIndex,
585
+ tabStops
586
+ });
587
+ }
588
+ getParagraphTabStops(paragraphIndex) {
589
+ return (0, import_univer_docs.getParagraphTabStops)(this.save(), paragraphIndex);
590
+ }
591
+ toggleHeadingCollapse(headingParagraphIndex) {
592
+ return this._commandService.syncExecuteCommand(import_univer_docs.ToggleHeadingCollapseCommand.id, {
593
+ unitId: this.getId(),
594
+ headingParagraphIndex
595
+ });
596
+ }
597
+ getCollapsedHeadings() {
598
+ return (0, import_univer_docs.getCollapsedHeadingsFromSnapshot)(this.save());
599
+ }
600
+ findAndReplaceDocText(query, replacement, options) {
601
+ let count = 0;
602
+ this._commandService.syncExecuteCommand(import_univer_docs.FindAndReplaceDocTextCommand.id, {
603
+ unitId: this.getId(),
604
+ query,
605
+ replacement,
606
+ options,
607
+ onResult: (n) => {
608
+ count = n;
609
+ }
610
+ });
611
+ return count;
612
+ }
613
+ findAndReplace(query, replacement, options) {
614
+ return this.findAndReplaceDocText(query, replacement, options);
615
+ }
616
+ getDocumentStatistics() {
617
+ return (0, import_univer_docs.getDocumentStatistics)(this.save());
618
+ }
619
+ checkDocumentSpellingAndTerms(customGlossary) {
620
+ return (0, import_univer_docs.checkDocumentSpellingAndTerms)(this.save(), customGlossary);
621
+ }
622
+ // ---- v1.6.204 Wave 2: Breaks, Proportional Column Groups (`2..5`), Pagination & Print Setup ----
623
+ insertPageBreak(offset) {
624
+ return this._commandService.syncExecuteCommand(import_univer_docs.InsertDocPageBreakCommand.id, {
625
+ unitId: this.getId(),
626
+ offset
627
+ });
628
+ }
629
+ insertSectionBreak(type = "nextPage", offset, orientation) {
630
+ return this._commandService.syncExecuteCommand(import_univer_docs.InsertDocSectionBreakCommand.id, {
631
+ unitId: this.getId(),
632
+ breakType: type,
633
+ offset,
634
+ orientation
635
+ });
636
+ }
637
+ insertColumnGroup(columnCount, options) {
638
+ return this._commandService.syncExecuteCommand(import_univer_docs.InsertDocColumnGroupCommand.id, {
639
+ unitId: this.getId(),
640
+ columnCount,
641
+ options
642
+ });
643
+ }
644
+ getColumnGroupConfig() {
645
+ return (0, import_univer_docs.getColumnGroupConfigFromSnapshot)(this.save());
646
+ }
647
+ setParagraphPagination(paragraphIndex, spec) {
648
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetParagraphPaginationCommand.id, {
649
+ unitId: this.getId(),
650
+ paragraphIndex,
651
+ spec
652
+ });
653
+ }
654
+ getParagraphPagination(paragraphIndex) {
655
+ return (0, import_univer_docs.getParagraphPagination)(this.save(), paragraphIndex);
656
+ }
657
+ setPrintConfig(config) {
658
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocPrintConfigCommand.id, {
659
+ unitId: this.getId(),
660
+ config
661
+ });
662
+ }
663
+ getPrintConfig() {
664
+ return (0, import_univer_docs.getDocPrintConfigFromSnapshot)(this.save());
665
+ }
666
+ // ---- v1.6.204 Wave 2: Image Transform, SmartArt Diagrams & Programmatic Table Manipulation ----
667
+ updateDocImageTransform(drawingId, spec) {
668
+ return this._commandService.syncExecuteCommand(import_univer_docs.UpdateDocImageTransformCommand.id, {
669
+ unitId: this.getId(),
670
+ drawingId,
671
+ spec
672
+ });
673
+ }
674
+ getDocImageTransform(drawingId) {
675
+ return (0, import_univer_docs.getDocImageTransformFromSnapshot)(this.save(), drawingId);
676
+ }
677
+ insertSmartArt(spec, offset) {
678
+ const id = spec.id || `smartart_${(0, import_core.generateRandomId)(6)}`;
679
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocSmartArtCommand.id, {
680
+ unitId: this.getId(),
681
+ offset,
682
+ spec: { ...spec, id }
683
+ });
684
+ if (!ok) return null;
685
+ return this.getSmartArts().find((s) => s.id === id) ?? null;
686
+ }
687
+ updateSmartArt(id, patch) {
688
+ return this._commandService.syncExecuteCommand(import_univer_docs.UpdateDocSmartArtCommand.id, {
689
+ unitId: this.getId(),
690
+ id,
691
+ patch
692
+ });
693
+ }
694
+ removeSmartArt(id) {
695
+ return this._commandService.syncExecuteCommand(import_univer_docs.RemoveDocSmartArtCommand.id, {
696
+ unitId: this.getId(),
697
+ id
698
+ });
699
+ }
700
+ getSmartArts() {
701
+ return (0, import_univer_docs.listLiveSmartArts)(this.save());
702
+ }
703
+ insertTableRow(tableIndex, rowIndex, position = "below") {
704
+ return this._commandService.syncExecuteCommand(import_univer_docs.InsertDocTableRowCommand.id, {
705
+ unitId: this.getId(),
706
+ tableIndex,
707
+ rowIndex,
708
+ position
709
+ });
710
+ }
711
+ deleteTableRow(tableIndex, rowIndex) {
712
+ return this._commandService.syncExecuteCommand(import_univer_docs.DeleteDocTableRowCommand.id, {
713
+ unitId: this.getId(),
714
+ tableIndex,
715
+ rowIndex
716
+ });
717
+ }
718
+ insertTableColumn(tableIndex, colIndex, position = "right") {
719
+ return this._commandService.syncExecuteCommand(import_univer_docs.InsertDocTableColumnCommand.id, {
720
+ unitId: this.getId(),
721
+ tableIndex,
722
+ colIndex,
723
+ position
724
+ });
725
+ }
726
+ deleteTableColumn(tableIndex, colIndex) {
727
+ return this._commandService.syncExecuteCommand(import_univer_docs.DeleteDocTableColumnCommand.id, {
728
+ unitId: this.getId(),
729
+ tableIndex,
730
+ colIndex
731
+ });
732
+ }
733
+ mergeTableCells(tableIndex, startRow, startCol, endRow, endCol) {
734
+ return this._commandService.syncExecuteCommand(import_univer_docs.MergeDocTableCellsCommand.id, {
735
+ unitId: this.getId(),
736
+ tableIndex,
737
+ startRow,
738
+ startCol,
739
+ endRow,
740
+ endCol
741
+ });
742
+ }
743
+ splitTableCell(tableIndex, row, col) {
744
+ return this._commandService.syncExecuteCommand(import_univer_docs.SplitDocTableCellCommand.id, {
745
+ unitId: this.getId(),
746
+ tableIndex,
747
+ row,
748
+ col
749
+ });
750
+ }
751
+ // ---- v1.6.204 Wave 2: Word Dynamic Fields, Captions, Cross-References, Citations, Building Blocks, Mail Merge & Legacy IO ----
752
+ insertDocField(fieldType, instructionArgs, offset, context) {
753
+ let fieldId = "";
754
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocFieldCommand.id, {
755
+ unitId: this.getId(),
756
+ fieldType,
757
+ instructionArgs,
758
+ offset,
759
+ context,
760
+ fieldIdOut: (id) => {
761
+ fieldId = id;
762
+ }
763
+ });
764
+ if (!ok) return null;
765
+ return this.getDocFields().find((f) => f.id === fieldId) ?? null;
766
+ }
767
+ updateAllDocFields(context) {
768
+ return this._commandService.syncExecuteCommand(import_univer_docs.UpdateAllDocFieldsCommand.id, {
769
+ unitId: this.getId(),
770
+ context
771
+ });
772
+ }
773
+ getDocFields() {
774
+ return (0, import_univer_docs.listDocFields)(this.save());
775
+ }
776
+ insertCaption(category, title, offset) {
777
+ let captionId = "";
778
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocCaptionCommand.id, {
779
+ unitId: this.getId(),
780
+ category,
781
+ title,
782
+ offset,
783
+ captionIdOut: (id) => {
784
+ captionId = id;
785
+ }
786
+ });
787
+ if (!ok) return null;
788
+ return this.getCaptions().find((c) => c.id === captionId) ?? null;
789
+ }
790
+ getCaptions() {
791
+ return (0, import_univer_docs.listDocCaptions)(this.save());
792
+ }
793
+ insertCrossReference(targetBookmarkOrCaptionId, offset) {
794
+ let fieldId = "";
795
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocCrossReferenceCommand.id, {
796
+ unitId: this.getId(),
797
+ targetBookmarkOrCaptionId,
798
+ offset,
799
+ fieldIdOut: (id) => {
800
+ fieldId = id;
801
+ }
802
+ });
803
+ if (!ok) return null;
804
+ return this.getDocFields().find((f) => f.id === fieldId) ?? null;
805
+ }
806
+ insertCitation(source, offset) {
807
+ return this._commandService.syncExecuteCommand(import_univer_docs.InsertDocCitationCommand.id, {
808
+ unitId: this.getId(),
809
+ source,
810
+ offset
811
+ });
812
+ }
813
+ getCitations() {
814
+ return (0, import_univer_docs.listDocCitations)(this.save());
815
+ }
816
+ insertBibliography(offset, title) {
817
+ return this._commandService.syncExecuteCommand(import_univer_docs.InsertDocBibliographyCommand.id, {
818
+ unitId: this.getId(),
819
+ offset,
820
+ title
821
+ });
822
+ }
823
+ saveBuildingBlock(spec) {
824
+ return this._injector.get(import_univer_docs.IDocSdtService).saveBuildingBlock(this.getId(), spec);
825
+ }
826
+ insertBuildingBlock(blockId, offset) {
827
+ return this._commandService.syncExecuteCommand(import_univer_docs.InsertDocBuildingBlockCommand.id, {
828
+ unitId: this.getId(),
829
+ blockId,
830
+ offset
831
+ });
832
+ }
833
+ getBuildingBlocks() {
834
+ return this._injector.get(import_univer_docs.IDocSdtService).getBuildingBlocks(this.getId());
835
+ }
836
+ removeBuildingBlock(blockId) {
837
+ return this._injector.get(import_univer_docs.IDocSdtService).removeBuildingBlock(this.getId(), blockId);
838
+ }
839
+ async runMailMergeBatch(records, format) {
840
+ const workingSnap = this.save();
841
+ return (0, import_univer_docs.runMailMergeBatchOnSnapshot)(workingSnap, records, format);
842
+ }
843
+ importLegacyDocBytes(bytes, title) {
844
+ const parsed = (0, import_univer_docs.importLegacyDocBytes)(bytes, title || this.getTitle() || "\u5BFC\u5165\u6587\u6863");
845
+ if (parsed.body) {
846
+ this._commandService.syncExecuteCommand(import_univer_docs.ReplaceDocUnitSnapshotCommand.id, {
847
+ unitId: this.getId(),
848
+ snapshot: parsed
849
+ });
850
+ }
851
+ return parsed;
852
+ }
853
+ async exportRtf(data, options) {
854
+ const bytes = await this._injector.get(import_univer_docs.IDocIoService).exportDoc({
855
+ unitId: this.getId(),
856
+ snapshot: this.save(),
857
+ format: "rtf",
858
+ data,
859
+ target: options?.target
860
+ });
861
+ return new TextDecoder().decode(bytes);
862
+ }
863
+ async exportOdt(data, options) {
864
+ return this._injector.get(import_univer_docs.IDocIoService).exportDoc({
865
+ unitId: this.getId(),
866
+ snapshot: this.save(),
867
+ format: "odt",
868
+ data,
869
+ target: options?.target
870
+ });
871
+ }
872
+ // ---- v1.6.204 Batch 3: Named Sub-Regions (`Area`/`Zone`) + Corner & Label Badges ----
873
+ insertDocArea(spec, offset) {
874
+ let created = null;
875
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocAreaCommand.id, {
876
+ unitId: this.getId(),
877
+ offset,
878
+ spec,
879
+ onResult: (area) => {
880
+ created = area;
881
+ }
882
+ });
883
+ if (!ok) return null;
884
+ return created ?? this.getDocAreas().find((a) => a.id === spec.id || a.name === spec.name) ?? null;
885
+ }
886
+ getDocAreas() {
887
+ return (0, import_univer_docs.getDocAreasFromSnapshot)(this.save());
888
+ }
889
+ getDocAreaValue(areaId) {
890
+ return (0, import_univer_docs.getDocAreaValueFromSnapshot)(this.save(), areaId);
891
+ }
892
+ setDocAreaValue(areaId, newText) {
893
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocAreaValueCommand.id, {
894
+ unitId: this.getId(),
895
+ areaId,
896
+ newText
897
+ });
898
+ }
899
+ setDocAreaProperties(areaId, patch) {
900
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocAreaPropertiesCommand.id, {
901
+ unitId: this.getId(),
902
+ areaId,
903
+ patch
904
+ });
905
+ }
906
+ deleteDocArea(areaId, options) {
907
+ return this._commandService.syncExecuteCommand(import_univer_docs.DeleteDocAreaCommand.id, {
908
+ unitId: this.getId(),
909
+ areaId,
910
+ force: options?.force,
911
+ keepContent: options?.keepContent
912
+ });
913
+ }
914
+ isOffsetReadonlyByArea(offset, globalMode) {
915
+ return (0, import_univer_docs.isOffsetReadonlyByArea)(this.save(), offset, globalMode ?? this.getMode());
916
+ }
917
+ setDocMainBadge(badge) {
918
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocMainBadgeCommand.id, {
919
+ unitId: this.getId(),
920
+ badge
921
+ });
922
+ }
923
+ getDocMainBadge() {
924
+ return (0, import_univer_docs.getDocMainBadgeFromSnapshot)(this.save());
925
+ }
926
+ setDocAreaBadge(areaId, badge) {
927
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocAreaBadgeCommand.id, {
928
+ unitId: this.getId(),
929
+ areaId,
930
+ badge
931
+ });
932
+ }
933
+ getDocAreaBadge(areaId) {
934
+ return (0, import_univer_docs.getDocAreaBadgeFromSnapshot)(this.save(), areaId);
935
+ }
936
+ insertDocLabelBadge(spec, offset) {
937
+ let created = null;
938
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocLabelBadgeCommand.id, {
939
+ unitId: this.getId(),
940
+ offset,
941
+ spec,
942
+ onResult: (b) => {
943
+ created = b;
944
+ }
945
+ });
946
+ if (!ok) return null;
947
+ return created;
948
+ }
949
+ getDocLabelBadges() {
950
+ return (0, import_univer_docs.getDocLabelBadgesFromSnapshot)(this.save());
951
+ }
952
+ removeDocLabelBadge(id) {
953
+ return this._commandService.syncExecuteCommand(import_univer_docs.RemoveDocLabelBadgeCommand.id, {
954
+ unitId: this.getId(),
955
+ id
956
+ });
957
+ }
958
+ // ---- v1.6.204 Batch 3: Declarative Control Cascade Engine ----
959
+ setDocCascadeRules(rules) {
960
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocCascadeRulesCommand.id, {
961
+ unitId: this.getId(),
962
+ rules
963
+ });
964
+ }
965
+ addDocCascadeRule(rule) {
966
+ return this._commandService.syncExecuteCommand(import_univer_docs.AddDocCascadeRuleCommand.id, {
967
+ unitId: this.getId(),
968
+ rule
969
+ });
970
+ }
971
+ removeDocCascadeRule(ruleId) {
972
+ return this._commandService.syncExecuteCommand(import_univer_docs.RemoveDocCascadeRuleCommand.id, {
973
+ unitId: this.getId(),
974
+ ruleId
975
+ });
976
+ }
977
+ getDocCascadeRules() {
978
+ return (0, import_univer_docs.getDocCascadeRulesFromSnapshot)(this.save());
979
+ }
980
+ evaluateDocCascadeRules(extraData) {
981
+ let out = null;
982
+ this._commandService.syncExecuteCommand(import_univer_docs.EvaluateDocCascadeRulesCommand.id, {
983
+ unitId: this.getId(),
984
+ extraData,
985
+ onResult: (res) => {
986
+ out = res;
987
+ }
988
+ });
989
+ return out ?? (0, import_univer_docs.evaluateDocCascadeRules)(this.save(), extraData);
990
+ }
991
+ // ---- v1.6.204 Batch 3: Styled Separators, Embed Blocks, Macros & Freehand Graffiti ----
992
+ insertStyledSeparator(dashStyle = "single", color, widthPt, offset) {
993
+ let created = null;
994
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertStyledSeparatorCommand.id, {
995
+ unitId: this.getId(),
996
+ dashStyle,
997
+ color,
998
+ widthPt,
999
+ offset,
1000
+ onResult: (sep) => {
1001
+ created = sep;
1002
+ }
1003
+ });
1004
+ if (!ok) return null;
1005
+ return created;
1006
+ }
1007
+ getStyledSeparators() {
1008
+ return (0, import_univer_docs.getStyledSeparatorsFromSnapshot)(this.save());
1009
+ }
1010
+ insertDocEmbedBlock(spec, offset) {
1011
+ let created = null;
1012
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocEmbedBlockCommand.id, {
1013
+ unitId: this.getId(),
1014
+ offset,
1015
+ spec,
1016
+ onResult: (eb) => {
1017
+ created = eb;
1018
+ }
1019
+ });
1020
+ if (!ok) return null;
1021
+ return created;
1022
+ }
1023
+ getDocEmbedBlocks() {
1024
+ return (0, import_univer_docs.getDocEmbedBlocksFromSnapshot)(this.save());
1025
+ }
1026
+ removeDocEmbedBlock(id) {
1027
+ return this._commandService.syncExecuteCommand(import_univer_docs.RemoveDocEmbedBlockCommand.id, {
1028
+ unitId: this.getId(),
1029
+ id
1030
+ });
1031
+ }
1032
+ registerDocMacro(name, resolverOrValue) {
1033
+ const key = (0, import_univer_docs.normalizeMacroName)(name);
1034
+ if (!key) return;
1035
+ (0, import_univer_docs.registerDocMacro)(key, resolverOrValue, this.getId());
1036
+ if (typeof resolverOrValue !== "function") {
1037
+ const prev = this.getTemplateMetadata();
1038
+ this.setTemplateMetadata({
1039
+ ...prev,
1040
+ macros: {
1041
+ ...prev.macros ?? {},
1042
+ [key]: String(resolverOrValue)
1043
+ }
1044
+ });
1045
+ }
1046
+ }
1047
+ unregisterDocMacro(name) {
1048
+ const key = (0, import_univer_docs.normalizeMacroName)(name);
1049
+ const removedRuntime = (0, import_univer_docs.unregisterDocMacro)(key, this.getId());
1050
+ const prev = this.getTemplateMetadata();
1051
+ if (prev.macros && Object.prototype.hasOwnProperty.call(prev.macros, key)) {
1052
+ const nextMacros = { ...prev.macros };
1053
+ delete nextMacros[key];
1054
+ this.setTemplateMetadata({
1055
+ ...prev,
1056
+ macros: nextMacros
1057
+ });
1058
+ return true;
1059
+ }
1060
+ return removedRuntime;
1061
+ }
1062
+ applyDocMacros(extraMacros) {
1063
+ let count = 0;
1064
+ this._commandService.syncExecuteCommand(import_univer_docs.ApplyDocMacrosCommand.id, {
1065
+ unitId: this.getId(),
1066
+ extraMacros,
1067
+ onResult: (n) => {
1068
+ count = n;
1069
+ }
1070
+ });
1071
+ return count;
1072
+ }
1073
+ addDocGraffitiStroke(spec) {
1074
+ let created = null;
1075
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.AddDocGraffitiStrokeCommand.id, {
1076
+ unitId: this.getId(),
1077
+ spec,
1078
+ onResult: (stroke) => {
1079
+ created = stroke;
1080
+ }
1081
+ });
1082
+ if (!ok) return null;
1083
+ return created;
1084
+ }
1085
+ getDocGraffitiStrokes(pageIndex) {
1086
+ return (0, import_univer_docs.getDocGraffitiStrokesFromSnapshot)(this.save(), pageIndex);
1087
+ }
1088
+ clearDocGraffitiStrokes(pageIndex) {
1089
+ return this._commandService.syncExecuteCommand(import_univer_docs.ClearDocGraffitiStrokesCommand.id, {
1090
+ unitId: this.getId(),
1091
+ pageIndex
1092
+ });
1093
+ }
1094
+ // ---- Round 1: Footnotes & Endnotes ----
1095
+ insertFootnote(text, offset, id) {
1096
+ let created = null;
1097
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocFootnoteCommand.id, {
1098
+ unitId: this.getId(),
1099
+ text,
1100
+ offset,
1101
+ id,
1102
+ onResult: (note) => {
1103
+ created = note;
1104
+ }
1105
+ });
1106
+ if (!ok) return null;
1107
+ return created ?? this.getNotes("footnote").slice(-1)[0] ?? null;
1108
+ }
1109
+ insertEndnote(text, offset, id) {
1110
+ let created = null;
1111
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocEndnoteCommand.id, {
1112
+ unitId: this.getId(),
1113
+ text,
1114
+ offset,
1115
+ id,
1116
+ onResult: (note) => {
1117
+ created = note;
1118
+ }
1119
+ });
1120
+ if (!ok) return null;
1121
+ return created ?? this.getNotes("endnote").slice(-1)[0] ?? null;
1122
+ }
1123
+ updateNote(noteId, text) {
1124
+ return this._commandService.syncExecuteCommand(import_univer_docs.UpdateDocNoteCommand.id, {
1125
+ unitId: this.getId(),
1126
+ noteId,
1127
+ text
1128
+ });
1129
+ }
1130
+ deleteNote(noteId) {
1131
+ return this._commandService.syncExecuteCommand(import_univer_docs.DeleteDocNoteCommand.id, {
1132
+ unitId: this.getId(),
1133
+ noteId
1134
+ });
1135
+ }
1136
+ getNotes(noteType) {
1137
+ return (0, import_univer_docs.listDocNotesFromSnapshot)(this.save(), noteType);
1138
+ }
1139
+ setNoteSettings(noteType, settings) {
1140
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocNoteSettingsCommand.id, {
1141
+ unitId: this.getId(),
1142
+ noteType,
1143
+ settings
1144
+ });
1145
+ }
1146
+ getNoteSettings(noteType) {
1147
+ return (0, import_univer_docs.getDocNoteSettingsFromSnapshot)(this.save(), noteType);
1148
+ }
1149
+ // ---- Round 1: Multi-Level Lists, TOC Remove, Column Update/Delete & Custom Properties ----
1150
+ insertDocList(spec) {
1151
+ let created = null;
1152
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocListCommand.id, {
1153
+ unitId: this.getId(),
1154
+ ...spec ?? {},
1155
+ onResult: (res) => {
1156
+ created = res;
1157
+ }
1158
+ });
1159
+ if (!ok) return null;
1160
+ return created;
1161
+ }
1162
+ setDocListGlyphType(listIdOrParagraphId, glyphType, level) {
1163
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocListGlyphTypeCommand.id, {
1164
+ unitId: this.getId(),
1165
+ listIdOrParagraphId,
1166
+ glyphType,
1167
+ level
1168
+ });
1169
+ }
1170
+ setDocListLevel(paragraphIdOrOffset, nestingLevel) {
1171
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocListLevelCommand.id, {
1172
+ unitId: this.getId(),
1173
+ paragraphIdOrOffset,
1174
+ nestingLevel
1175
+ });
1176
+ }
1177
+ toggleDocListCheckbox(paragraphId, checked) {
1178
+ return this._commandService.syncExecuteCommand(import_univer_docs.ToggleDocListCheckboxCommand.id, {
1179
+ unitId: this.getId(),
1180
+ paragraphId,
1181
+ checked
1182
+ });
1183
+ }
1184
+ getDocLists() {
1185
+ return (0, import_univer_docs.getDocListsFromSnapshot)(this.save());
1186
+ }
1187
+ removeTableOfContents() {
1188
+ return this._commandService.syncExecuteCommand(import_univer_docs.RemoveDocTableOfContentsCommand.id, {
1189
+ unitId: this.getId()
1190
+ });
1191
+ }
1192
+ updateColumnGroup(patch) {
1193
+ return this._commandService.syncExecuteCommand(import_univer_docs.UpdateDocColumnGroupCommand.id, {
1194
+ unitId: this.getId(),
1195
+ patch
1196
+ });
1197
+ }
1198
+ deleteColumnGroup() {
1199
+ return this._commandService.syncExecuteCommand(import_univer_docs.DeleteDocColumnGroupCommand.id, {
1200
+ unitId: this.getId()
1201
+ });
1202
+ }
1203
+ setCustomProperties(customProperties, company, title) {
1204
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocCustomPropertiesCommand.id, {
1205
+ unitId: this.getId(),
1206
+ customProperties,
1207
+ company,
1208
+ title
1209
+ });
1210
+ }
1211
+ getCustomProperties() {
1212
+ return (0, import_univer_docs.getDocCustomPropertiesFromSnapshot)(this.save());
1213
+ }
1214
+ // ---- Round 1: Bidirectional Markdown (`.md`) ----
1215
+ importMarkdown(markdown, title) {
1216
+ const parsed = (0, import_univer_docs.importMarkdownToDocData)(markdown, title || this.getTitle() || "\u672A\u547D\u540D\u6587\u6863");
1217
+ if (parsed.body) {
1218
+ this._commandService.syncExecuteCommand(import_univer_docs.ReplaceDocUnitSnapshotCommand.id, {
1219
+ unitId: this.getId(),
1220
+ snapshot: parsed
1221
+ });
1222
+ }
1223
+ return parsed;
1224
+ }
1225
+ async exportMarkdown(data, options) {
1226
+ if (options?.target !== "server") {
1227
+ return (0, import_univer_docs.exportDocToMarkdown)(this.save(), data);
1228
+ }
1229
+ const bytes = await this._injector.get(import_univer_docs.IDocIoService).exportDoc({
1230
+ unitId: this.getId(),
1231
+ snapshot: this.save(),
1232
+ format: "md",
1233
+ data,
1234
+ target: options?.target
1235
+ });
1236
+ return new TextDecoder().decode(bytes);
1237
+ }
1238
+ // ---- Round 1: Advanced SDT Validation Highlight & Tab Jump ----
1239
+ highlightInvalidControls(clear = false) {
1240
+ return this._commandService.syncExecuteCommand(import_univer_docs.HighlightInvalidDocSdtCommand.id, {
1241
+ unitId: this.getId(),
1242
+ clear
1243
+ });
1244
+ }
1245
+ jumpToControl(directionOrOptions) {
1246
+ const opts = typeof directionOrOptions === "string" ? { direction: directionOrOptions } : directionOrOptions ?? {};
1247
+ return this._commandService.syncExecuteCommand(import_univer_docs.JumpDocSdtControlCommand.id, {
1248
+ unitId: this.getId(),
1249
+ ...opts
1250
+ });
1251
+ }
1252
+ // ---- Round 1: Bidi/RTL, Copy/Paste Policy, Table Presets/Slash/AutoFit, Orientation, WordTool, Macros & Visual Diff ----
1253
+ setTextDirection(direction, target) {
1254
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocTextDirectionCommand.id, {
1255
+ unitId: this.getId(),
1256
+ direction,
1257
+ ...target ?? {}
1258
+ });
1259
+ }
1260
+ setCopyPastePolicy(policy) {
1261
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocCopyPastePolicyCommand.id, {
1262
+ unitId: this.getId(),
1263
+ policy
1264
+ });
1265
+ }
1266
+ getCopyPastePolicy() {
1267
+ return (0, import_univer_docs.getDocCopyPastePolicyFromSnapshot)(this.save());
1268
+ }
1269
+ setTableBorderPreset(tableIndexOrId, preset, color, widthPt) {
1270
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocTableBorderPresetCommand.id, {
1271
+ unitId: this.getId(),
1272
+ tableIndexOrId,
1273
+ preset,
1274
+ color,
1275
+ widthPt
1276
+ });
1277
+ }
1278
+ setTableCellProperties(tableIndexOrId, rowIndex, colIndex, properties) {
1279
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocTableCellPropertiesCommand.id, {
1280
+ unitId: this.getId(),
1281
+ tableIndexOrId,
1282
+ rowIndex,
1283
+ colIndex,
1284
+ properties
1285
+ });
1286
+ }
1287
+ getTableCellProperties(tableId, rowIndex, colIndex) {
1288
+ return (0, import_univer_docs.getDocTableCellProperties)(this.save(), tableId, rowIndex, colIndex);
1289
+ }
1290
+ autoFitTable(tableIndexOrId, mode = "window") {
1291
+ return this._commandService.syncExecuteCommand(import_univer_docs.AutoFitDocTableCommand.id, {
1292
+ unitId: this.getId(),
1293
+ tableIndexOrId,
1294
+ mode
1295
+ });
1296
+ }
1297
+ setSectionOrientation(orientation, sectionKeyOrOffset) {
1298
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocSectionOrientationCommand.id, {
1299
+ unitId: this.getId(),
1300
+ orientation,
1301
+ sectionKeyOrOffset
1302
+ });
1303
+ }
1304
+ cleanUpFormatting(options) {
1305
+ let result = {
1306
+ removedBlankParagraphs: 0,
1307
+ trimmedParagraphs: 0,
1308
+ indentedParagraphs: 0,
1309
+ normalizedPunctuationCount: 0
1310
+ };
1311
+ this._commandService.syncExecuteCommand(import_univer_docs.CleanUpDocFormattingCommand.id, {
1312
+ unitId: this.getId(),
1313
+ options,
1314
+ onResult: (res) => {
1315
+ result = res;
1316
+ }
1317
+ });
1318
+ return result;
1319
+ }
1320
+ startMacroRecording(name) {
1321
+ this._injector.get(import_univer_docs.IDocActionMacroService).startRecording(name);
1322
+ }
1323
+ stopMacroRecording(name) {
1324
+ return this._injector.get(import_univer_docs.IDocActionMacroService).stopRecording(name);
1325
+ }
1326
+ async playActionMacro(macroIdOrName) {
1327
+ return this._injector.get(import_univer_docs.IDocActionMacroService).playMacro(macroIdOrName);
1328
+ }
1329
+ getActionMacros() {
1330
+ return this._injector.get(import_univer_docs.IDocActionMacroService).getMacros();
1331
+ }
1332
+ exportActionMacros() {
1333
+ return this._injector.get(import_univer_docs.IDocActionMacroService).exportMacros();
1334
+ }
1335
+ importActionMacros(jsonOrList) {
1336
+ return this._injector.get(import_univer_docs.IDocActionMacroService).importMacros(jsonOrList);
1337
+ }
1338
+ compareWithSnapshot(baseSnapshot, options) {
1339
+ const base = baseSnapshot instanceof FEnterpriseDoc ? baseSnapshot.save() : baseSnapshot;
1340
+ let out = null;
1341
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.CompareDocSnapshotsToTrackCommand.id, {
1342
+ unitId: this.getId(),
1343
+ baseSnapshot: base,
1344
+ options,
1345
+ onResult: (res) => {
1346
+ out = res;
1347
+ }
1348
+ });
1349
+ if (!ok) return null;
1350
+ return out;
1351
+ }
1352
+ // ---- Round 3: Hyperlinks, Comments, Sub/Superscript, Extensibility, Print, Catalog Tree, Title & Events ----
1353
+ insertHyperlink(spec) {
1354
+ let insertedId = null;
1355
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocHyperlinkCommand.id, {
1356
+ unitId: this.getId(),
1357
+ spec,
1358
+ onInserted: (entry) => {
1359
+ insertedId = entry.id;
1360
+ }
1361
+ });
1362
+ return ok ? insertedId : null;
1363
+ }
1364
+ updateHyperlink(idOrOffset, patch) {
1365
+ return this._commandService.syncExecuteCommand(import_univer_docs.UpdateDocHyperlinkCommand.id, {
1366
+ unitId: this.getId(),
1367
+ idOrOffset,
1368
+ patch
1369
+ });
1370
+ }
1371
+ cancelHyperlink(idOrOffset) {
1372
+ return this._commandService.syncExecuteCommand(import_univer_docs.CancelDocHyperlinkCommand.id, {
1373
+ unitId: this.getId(),
1374
+ idOrOffset
1375
+ });
1376
+ }
1377
+ deleteHyperlink(idOrOffset) {
1378
+ return this._commandService.syncExecuteCommand(import_univer_docs.DeleteDocHyperlinkCommand.id, {
1379
+ unitId: this.getId(),
1380
+ idOrOffset
1381
+ });
1382
+ }
1383
+ getHyperlinks() {
1384
+ return (0, import_univer_docs.listDocHyperlinks)(this.save());
1385
+ }
1386
+ addComment(specOrContent, author, startOffset, endOffset) {
1387
+ const spec = typeof specOrContent === "string" ? { content: specOrContent, author, startOffset, endOffset } : specOrContent;
1388
+ let addedId = null;
1389
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.AddDocCommentCommand.id, {
1390
+ unitId: this.getId(),
1391
+ spec,
1392
+ onAdded: (cmt) => {
1393
+ addedId = cmt.id;
1394
+ }
1395
+ });
1396
+ return ok ? addedId : null;
1397
+ }
1398
+ replyComment(commentId, specOrContent, author) {
1399
+ const spec = typeof specOrContent === "string" ? { content: specOrContent, author } : specOrContent;
1400
+ let replyId = null;
1401
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.ReplyDocCommentCommand.id, {
1402
+ unitId: this.getId(),
1403
+ commentId,
1404
+ spec,
1405
+ onReplied: (rep) => {
1406
+ replyId = rep.id;
1407
+ }
1408
+ });
1409
+ return ok ? replyId : null;
1410
+ }
1411
+ resolveComment(commentId, resolved = true) {
1412
+ return this._commandService.syncExecuteCommand(import_univer_docs.ResolveDocCommentCommand.id, {
1413
+ unitId: this.getId(),
1414
+ commentId,
1415
+ resolved
1416
+ });
1417
+ }
1418
+ deleteComment(commentId) {
1419
+ return this._commandService.syncExecuteCommand(import_univer_docs.DeleteDocCommentCommand.id, {
1420
+ unitId: this.getId(),
1421
+ commentId
1422
+ });
1423
+ }
1424
+ getComments() {
1425
+ return (0, import_univer_docs.listDocCommentsFromSnapshot)(this.save());
1426
+ }
1427
+ locateComment(commentId) {
1428
+ const target = this.getComments().find((c) => c.id === commentId);
1429
+ if (!target) return false;
1430
+ try {
1431
+ const selService = this._injector.get(import_docs.DocSelectionManagerService);
1432
+ const selParam = { unitId: this.getId(), subUnitId: this.getId() };
1433
+ const startOffset = target.startIndex;
1434
+ const endOffset = target.endIndex + 1;
1435
+ selService.replaceDocRanges([{ startOffset, endOffset }], selParam);
1436
+ if (selService.getActiveTextRange()?.startOffset !== startOffset) {
1437
+ selService.__TEST_ONLY_setCurrentSelection(selParam);
1438
+ selService.__TEST_ONLY_add([
1439
+ { startOffset, endOffset, collapsed: startOffset === endOffset, isActive: true }
1440
+ ]);
1441
+ }
1442
+ } catch {
1443
+ }
1444
+ return true;
1445
+ }
1446
+ toggleSuperscript(startOffset, endOffset) {
1447
+ return this._commandService.syncExecuteCommand(import_univer_docs.ToggleDocSuperscriptCommand.id, {
1448
+ unitId: this.getId(),
1449
+ startOffset,
1450
+ endOffset
1451
+ });
1452
+ }
1453
+ toggleSubscript(startOffset, endOffset) {
1454
+ return this._commandService.syncExecuteCommand(import_univer_docs.ToggleDocSubscriptCommand.id, {
1455
+ unitId: this.getId(),
1456
+ startOffset,
1457
+ endOffset
1458
+ });
1459
+ }
1460
+ importHtml(html, title) {
1461
+ const parsed = (0, import_univer_docs.importHtmlToDocData)(html, title || this.getTitle() || "\u672A\u547D\u540D\u6587\u6863");
1462
+ return this._commandService.syncExecuteCommand(import_univer_docs.ReplaceDocUnitSnapshotCommand.id, {
1463
+ unitId: this.getId(),
1464
+ snapshot: parsed
1465
+ });
1466
+ }
1467
+ registerContextMenuList(items) {
1468
+ const reg = this._injector.get(import_univer_docs.IDocExtensionRegistryService);
1469
+ reg.setDocApiResolver((uid) => uid === this.getId() ? this : null);
1470
+ return reg.registerContextMenuList(items);
1471
+ }
1472
+ registerShortcutList(shortcuts) {
1473
+ const reg = this._injector.get(import_univer_docs.IDocExtensionRegistryService);
1474
+ reg.setDocApiResolver((uid) => uid === this.getId() ? this : null);
1475
+ return reg.registerShortcutList(shortcuts);
1476
+ }
1477
+ getContextMenuList(ctx) {
1478
+ return this._injector.get(import_univer_docs.IDocExtensionRegistryService).getContextMenuList(ctx);
1479
+ }
1480
+ async print(options) {
1481
+ const pdfBytes = await this.exportPdf(options);
1482
+ if (!pdfBytes || pdfBytes.byteLength < 10) return false;
1483
+ if (typeof document !== "undefined" && typeof URL !== "undefined" && typeof URL.createObjectURL === "function") {
1484
+ try {
1485
+ const ab = pdfBytes.buffer.slice(
1486
+ pdfBytes.byteOffset,
1487
+ pdfBytes.byteOffset + pdfBytes.byteLength
1488
+ );
1489
+ const blob = new Blob([ab], { type: "application/pdf" });
1490
+ const blobUrl = URL.createObjectURL(blob);
1491
+ const iframe = document.createElement("iframe");
1492
+ iframe.style.position = "fixed";
1493
+ iframe.style.right = "0";
1494
+ iframe.style.bottom = "0";
1495
+ iframe.style.width = "0";
1496
+ iframe.style.height = "0";
1497
+ iframe.style.border = "0";
1498
+ iframe.setAttribute("aria-hidden", "true");
1499
+ let printed = false;
1500
+ const cleanup = () => {
1501
+ setTimeout(() => {
1502
+ try {
1503
+ iframe.remove();
1504
+ } catch {
1505
+ }
1506
+ try {
1507
+ URL.revokeObjectURL(blobUrl);
1508
+ } catch {
1509
+ }
1510
+ }, 1500);
1511
+ };
1512
+ iframe.onload = () => {
1513
+ if (printed) return;
1514
+ printed = true;
1515
+ try {
1516
+ iframe.contentWindow?.focus?.();
1517
+ iframe.contentWindow?.print?.();
1518
+ } catch {
1519
+ }
1520
+ cleanup();
1521
+ };
1522
+ document.body.appendChild(iframe);
1523
+ iframe.src = blobUrl;
1524
+ setTimeout(() => {
1525
+ if (!printed) {
1526
+ printed = true;
1527
+ try {
1528
+ iframe.contentWindow?.print?.();
1529
+ } catch {
1530
+ }
1531
+ cleanup();
1532
+ }
1533
+ }, 300);
1534
+ } catch {
1535
+ }
1536
+ }
1537
+ return true;
1538
+ }
1539
+ getCatalogTree() {
1540
+ return (0, import_univer_docs.extractDocCatalogTree)(this.save());
1541
+ }
1542
+ locateCatalog(idOrParagraphId) {
1543
+ const target = this.getCatalog().find(
1544
+ (c) => c.id === idOrParagraphId || c.paragraphId === idOrParagraphId || c.title === idOrParagraphId
1545
+ );
1546
+ if (!target) return false;
1547
+ try {
1548
+ const selService = this._injector.get(import_docs.DocSelectionManagerService);
1549
+ const selParam = { unitId: this.getId(), subUnitId: this.getId() };
1550
+ const startOffset = target.startIndex;
1551
+ selService.replaceDocRanges([{ startOffset, endOffset: startOffset }], selParam);
1552
+ if (selService.getActiveTextRange()?.startOffset !== startOffset) {
1553
+ selService.__TEST_ONLY_setCurrentSelection(selParam);
1554
+ selService.__TEST_ONLY_add([
1555
+ { startOffset, endOffset: startOffset, collapsed: true, isActive: true }
1556
+ ]);
1557
+ }
1558
+ } catch {
1559
+ }
1560
+ return true;
1561
+ }
1562
+ getReadabilityStatistics() {
1563
+ return (0, import_univer_docs.getReadabilityStatistics)(this.save());
1564
+ }
1565
+ insertTitle(spec) {
1566
+ let insertedId = null;
1567
+ const ok = this._commandService.syncExecuteCommand(import_univer_docs.InsertDocTitleCommand.id, {
1568
+ unitId: this.getId(),
1569
+ spec,
1570
+ onInserted: (entry) => {
1571
+ insertedId = entry.id;
1572
+ }
1573
+ });
1574
+ return ok ? insertedId : null;
1575
+ }
1576
+ setTitleProperties(idOrConceptId, patch) {
1577
+ return this._commandService.syncExecuteCommand(import_univer_docs.SetDocTitlePropertiesCommand.id, {
1578
+ unitId: this.getId(),
1579
+ idOrConceptId,
1580
+ patch
1581
+ });
1582
+ }
1583
+ getTitleValue(conceptId) {
1584
+ return (0, import_univer_docs.getDocTitleValueFromSnapshot)(this.save(), conceptId);
1585
+ }
1586
+ getTitles() {
1587
+ return (0, import_univer_docs.getDocTitleEntriesFromSnapshot)(this.save());
1588
+ }
1589
+ onBeforeSave(cb) {
1590
+ return this._injector.get(import_univer_docs.IDocIoService).onBeforeSave(cb, this.getId());
1591
+ }
1592
+ onSaved(cb) {
1593
+ return this._injector.get(import_univer_docs.IDocIoService).onSaved(cb, this.getId());
1594
+ }
1595
+ onControlChange(cb) {
1596
+ const unitId = this.getId();
1597
+ const sub = this._injector.get(import_univer_docs.IDocSdtService).controlChange$.subscribe((ev) => {
1598
+ if (!ev.unitId || ev.unitId === unitId) {
1599
+ cb(ev);
1600
+ }
1601
+ });
1602
+ return { dispose: () => sub.unsubscribe() };
1603
+ }
1604
+ onControlValueChange(cb) {
1605
+ const unitId = this.getId();
1606
+ const sub = this._injector.get(import_univer_docs.IDocSdtService).controlValueChange$.subscribe((ev) => {
1607
+ if (ev.unitId === unitId) {
1608
+ cb(ev);
1609
+ }
1610
+ });
1611
+ return { dispose: () => sub.unsubscribe() };
1612
+ }
1613
+ onModeChange(cb) {
1614
+ const unitId = this.getId();
1615
+ const sub = this._injector.get(import_univer_docs.IDocSdtService).modeChange$.subscribe((ev) => {
1616
+ if (ev.unitId === unitId) {
1617
+ cb(ev);
1618
+ }
1619
+ });
1620
+ return { dispose: () => sub.unsubscribe() };
1621
+ }
1622
+ onContentChange(cb) {
1623
+ const unitId = this.getId();
1624
+ const sub = this._injector.get(import_univer_docs.IDocSdtService).contentChange$.subscribe((ev) => {
1625
+ if (ev.unitId === unitId) {
1626
+ cb(ev);
1627
+ }
1628
+ });
1629
+ return { dispose: () => sub.unsubscribe() };
1630
+ }
1631
+ };
1632
+ FEnterpriseDoc = __decorateClass([
1633
+ __decorateParam(1, (0, import_core.Inject)(import_core.Injector)),
1634
+ __decorateParam(2, import_core.ICommandService)
1635
+ ], FEnterpriseDoc);
1636
+
1637
+ // src/facade/f-univer.ts
1638
+ var import_core2 = require("@univerjs/core");
1639
+ var import_facade = require("@univerjs/core/facade");
1640
+ var import_univer_docs2 = require("@yudaocode/univer-docs");
1641
+ function coerceInputToFile(fileOrInput, options) {
1642
+ if (typeof File !== "undefined" && fileOrInput instanceof File && !options?.format && !options?.fileName) {
1643
+ return fileOrInput;
1644
+ }
1645
+ let ext = options?.format ? `.${options.format}` : "";
1646
+ if (!ext && options?.fileName) {
1647
+ const m = options.fileName.match(/(\.[^.]+)$/);
1648
+ if (m) ext = m[1].toLowerCase();
1649
+ }
1650
+ if (!ext && typeof File !== "undefined" && fileOrInput instanceof File) {
1651
+ const m = fileOrInput.name.match(/(\.[^.]+)$/);
1652
+ if (m) ext = m[1].toLowerCase();
1653
+ }
1654
+ if (typeof fileOrInput === "string") {
1655
+ const trimmed = fileOrInput.trimStart();
1656
+ if (!ext) {
1657
+ if (trimmed.startsWith("{")) ext = ".json";
1658
+ else if (/^<!doctype\s+html|^<html[\s>]|^<(?:p|h[1-6]|div|table)\b/i.test(trimmed)) ext = ".html";
1659
+ else if (trimmed.startsWith("{\\rtf")) ext = ".rtf";
1660
+ else ext = ".md";
1661
+ }
1662
+ const baseName2 = options?.fileName || `${options?.title || "imported"}${ext}`;
1663
+ return new File([fileOrInput], baseName2, { type: "text/plain;charset=utf-8" });
1664
+ }
1665
+ if (fileOrInput instanceof Uint8Array || fileOrInput instanceof ArrayBuffer) {
1666
+ const bytes = fileOrInput instanceof Uint8Array ? fileOrInput : new Uint8Array(fileOrInput);
1667
+ if (!ext) {
1668
+ if (bytes.length >= 4 && bytes[0] === 80 && bytes[1] === 75) {
1669
+ ext = ".docx";
1670
+ } else if (bytes.length >= 5 && bytes[0] === 123 && bytes[1] === 92 && bytes[2] === 114) {
1671
+ ext = ".rtf";
1672
+ } else {
1673
+ ext = ".docx";
1674
+ }
1675
+ }
1676
+ const ab = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
1677
+ const baseName2 = options?.fileName || `${options?.title || "imported"}${ext}`;
1678
+ return new File([ab], baseName2);
1679
+ }
1680
+ const baseName = options?.fileName || `${options?.title || "imported"}${ext || ".docx"}`;
1681
+ return new File([fileOrInput], baseName, { type: fileOrInput.type || "application/octet-stream" });
1682
+ }
1683
+ var FUniverDocsExtMixin = class extends import_facade.FUniver {
1684
+ createEnterpriseDoc(data, metadata, options) {
1685
+ const initialData = data?.body != null ? data : {
1686
+ ...(0, import_univer_docs2.buildStructuredDocData)({
1687
+ id: data?.id,
1688
+ title: data?.title || "\u672A\u547D\u540D\u6587\u6863",
1689
+ paragraphs: [{ segments: [""] }]
1690
+ }),
1691
+ ...data
1692
+ };
1693
+ const model = this._univerInstanceService.createUnit(
1694
+ import_core2.UniverInstanceType.UNIVER_DOC,
1695
+ initialData,
1696
+ options
1697
+ );
1698
+ if (metadata) {
1699
+ this._injector.get(import_univer_docs2.IDocSdtService).setTemplateMetadata(model.getUnitId(), metadata);
1700
+ }
1701
+ return this._injector.createInstance(FEnterpriseDoc, model);
1702
+ }
1703
+ getActiveEnterpriseDoc() {
1704
+ const model = this._univerInstanceService.getCurrentUnitOfType(
1705
+ import_core2.UniverInstanceType.UNIVER_DOC
1706
+ );
1707
+ if (!model) return null;
1708
+ return this._injector.createInstance(FEnterpriseDoc, model);
1709
+ }
1710
+ getEnterpriseDoc(unitId) {
1711
+ const model = this._univerInstanceService.getUnit(
1712
+ unitId,
1713
+ import_core2.UniverInstanceType.UNIVER_DOC
1714
+ );
1715
+ if (!model) return null;
1716
+ return this._injector.createInstance(FEnterpriseDoc, model);
1717
+ }
1718
+ setDocIoAdapter(adapter) {
1719
+ this._injector.get(import_univer_docs2.IDocIoService).setAdapter(adapter);
1720
+ }
1721
+ getDocIoAdapter() {
1722
+ return this._injector.get(import_univer_docs2.IDocIoService).getAdapter();
1723
+ }
1724
+ setDocAiCopilotAdapter(adapter) {
1725
+ this._injector.get(import_univer_docs2.IDocAiCopilotService).setAdapter(adapter);
1726
+ }
1727
+ getDocAiCopilotAdapter() {
1728
+ return this._injector.get(import_univer_docs2.IDocAiCopilotService).getAdapter();
1729
+ }
1730
+ setTrackChanges(enabled, author) {
1731
+ return this.getActiveEnterpriseDoc()?.setTrackChanges(enabled, author) ?? false;
1732
+ }
1733
+ insertTrackedText(text, index, author) {
1734
+ return this.getActiveEnterpriseDoc()?.insertTrackedText(text, index, author) ?? false;
1735
+ }
1736
+ markTrackedDeletion(startIndex, endIndex, author) {
1737
+ return this.getActiveEnterpriseDoc()?.markTrackedDeletion(startIndex, endIndex, author) ?? false;
1738
+ }
1739
+ acceptRevision(revisionId) {
1740
+ return this.getActiveEnterpriseDoc()?.acceptRevision(revisionId) ?? false;
1741
+ }
1742
+ rejectRevision(revisionId) {
1743
+ return this.getActiveEnterpriseDoc()?.rejectRevision(revisionId) ?? false;
1744
+ }
1745
+ acceptAllRevisions() {
1746
+ return this.getActiveEnterpriseDoc()?.acceptAllRevisions() ?? false;
1747
+ }
1748
+ rejectAllRevisions() {
1749
+ return this.getActiveEnterpriseDoc()?.rejectAllRevisions() ?? false;
1750
+ }
1751
+ getRevisions() {
1752
+ return this.getActiveEnterpriseDoc()?.getRevisions() ?? [];
1753
+ }
1754
+ async auditContractRisks() {
1755
+ const doc = this.getActiveEnterpriseDoc();
1756
+ if (!doc) return [];
1757
+ return doc.auditContractRisks();
1758
+ }
1759
+ async draftClauseByAi(prompt) {
1760
+ const doc = this.getActiveEnterpriseDoc();
1761
+ if (!doc) return "";
1762
+ return doc.draftClauseByAi(prompt);
1763
+ }
1764
+ async importDocToSnapshotAsync(fileOrInput, options) {
1765
+ const file = coerceInputToFile(fileOrInput, options);
1766
+ const partial = await this._injector.get(import_univer_docs2.IDocIoService).importDoc(file, void 0, {
1767
+ target: options?.target
1768
+ });
1769
+ if (partial.body) {
1770
+ return {
1771
+ id: partial.id || `doc_${Date.now().toString(36)}`,
1772
+ title: options?.title || partial.title || file.name.replace(/\.[^.]+$/, "") || "\u672A\u547D\u540D\u6587\u6863",
1773
+ documentStyle: partial.documentStyle ?? {
1774
+ pageSize: { width: 595.28, height: 841.89 },
1775
+ marginTop: 56,
1776
+ marginBottom: 56,
1777
+ marginLeft: 64,
1778
+ marginRight: 64
1779
+ },
1780
+ ...partial
1781
+ };
1782
+ }
1783
+ return (0, import_univer_docs2.buildStructuredDocData)({
1784
+ id: partial.id,
1785
+ title: options?.title || partial.title || "\u672A\u547D\u540D\u6587\u6863",
1786
+ paragraphs: [{ segments: [""] }]
1787
+ });
1788
+ }
1789
+ async importDocToUnitIdAsync(unitId, fileOrInput, options) {
1790
+ if (!unitId) return false;
1791
+ const snapshot = await this.importDocToSnapshotAsync(fileOrInput, options);
1792
+ snapshot.id = unitId;
1793
+ const existing = this._univerInstanceService.getUnit(
1794
+ unitId,
1795
+ import_core2.UniverInstanceType.UNIVER_DOC
1796
+ );
1797
+ if (existing) {
1798
+ return this._injector.get(import_core2.ICommandService).syncExecuteCommand(
1799
+ import_univer_docs2.ReplaceDocUnitSnapshotCommand.id,
1800
+ {
1801
+ unitId,
1802
+ snapshot
1803
+ }
1804
+ );
1805
+ }
1806
+ this._univerInstanceService.createUnit(
1807
+ import_core2.UniverInstanceType.UNIVER_DOC,
1808
+ snapshot
1809
+ );
1810
+ return true;
1811
+ }
1812
+ async exportDocBySnapshotAsync(snapshot, format = "docx", options) {
1813
+ return this._injector.get(import_univer_docs2.IDocIoService).exportDoc({
1814
+ unitId: snapshot.id || "snapshot-export",
1815
+ snapshot,
1816
+ format,
1817
+ data: options?.data,
1818
+ pdfOptions: options?.pdfOptions,
1819
+ target: options?.target
1820
+ });
1821
+ }
1822
+ async exportDocByUnitIdAsync(unitId, format = "docx", options) {
1823
+ const doc = this.getEnterpriseDoc(unitId);
1824
+ if (!doc) return null;
1825
+ return this._injector.get(import_univer_docs2.IDocIoService).exportDoc({
1826
+ unitId,
1827
+ snapshot: doc.save(),
1828
+ format,
1829
+ data: options?.data,
1830
+ pdfOptions: options?.pdfOptions,
1831
+ target: options?.target
1832
+ });
1833
+ }
1834
+ };
1835
+ import_facade.FUniver.extend(FUniverDocsExtMixin);
1836
+ // Annotate the CommonJS export names for ESM import in node:
1837
+ 0 && (module.exports = {
1838
+ FDocumentExtMixin,
1839
+ FEnterpriseDoc,
1840
+ FUniverDocsExtMixin
1841
+ });
1842
+ //# sourceMappingURL=index.js.map