@univerjs/docs 1.0.0-rc.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +66 -20
- package/lib/cjs/index.js +347 -64
- package/lib/es/facade.js +66 -20
- package/lib/es/index.js +349 -66
- package/lib/facade.js +66 -20
- package/lib/index.js +349 -66
- package/lib/types/commands/mutations/core-editing.mutation.d.ts +2 -0
- package/lib/types/commands/mutations/doc-structure-mutation-validation.d.ts +2 -1
- package/lib/types/facade/f-document-section.d.ts +28 -0
- package/lib/types/facade/f-document-text-range.d.ts +4 -0
- package/lib/types/facade/f-document.d.ts +29 -13
- package/lib/types/facade/f-univer.d.ts +2 -2
- package/lib/types/layout-worker/config/config.d.ts +8 -0
- package/lib/types/layout-worker/font-loader.d.ts +26 -0
- package/lib/types/layout-worker/index.d.ts +5 -2
- package/lib/types/layout-worker/protocol.d.ts +2 -0
- package/lib/types/layout-worker/worker.d.ts +3 -1
- package/lib/types/plugin.d.ts +1 -0
- package/lib/types/services/doc-layout-executor.service.d.ts +6 -0
- package/lib/types/services/doc-state-change-manager.service.d.ts +2 -0
- package/lib/types/services/doc-state-emit.service.d.ts +1 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +7 -7
|
@@ -28,6 +28,8 @@ export declare enum DocHistoryAction {
|
|
|
28
28
|
}
|
|
29
29
|
export interface IRichTextEditingMutationParams extends IMutationCommonParams {
|
|
30
30
|
unitId: string;
|
|
31
|
+
/** Host-owned transient layout state, used only by local editor history. */
|
|
32
|
+
layoutState?: unknown;
|
|
31
33
|
historyAction?: string;
|
|
32
34
|
historyActions?: string[];
|
|
33
35
|
actions: JSONXActions;
|
|
@@ -14,4 +14,5 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import type { DocumentDataModel, JSONXActions } from '@univerjs/core';
|
|
17
|
-
export declare function
|
|
17
|
+
export declare function isDocSdtMutationAllowed(documentDataModel: DocumentDataModel, segmentId: string, actions: JSONXActions): boolean;
|
|
18
|
+
export declare function validateDocStructureMutation(documentDataModel: DocumentDataModel, segmentId: string, actions: JSONXActions, undoActions: JSONXActions, isHistoryReplay?: boolean): boolean;
|
|
@@ -134,6 +134,10 @@ export declare class FDocumentSection {
|
|
|
134
134
|
* Sets equal or explicitly sized columns for this traditional section.
|
|
135
135
|
* Use `columnCount = 1` to restore normal single-column layout.
|
|
136
136
|
* `gap` and `widths` are in 96-DPI layout pixels.
|
|
137
|
+
* @param {number} columnCount Positive integer column count.
|
|
138
|
+
* @param {IFDocumentSectionColumnOptions} [options] Column widths, gap (default 18 pixels), and separator (default none).
|
|
139
|
+
* @returns {boolean} Whether the section update succeeded.
|
|
140
|
+
* @throws {RangeError} If column dimensions or the separator are invalid, or columns exceed the available width.
|
|
137
141
|
* @example
|
|
138
142
|
* ```ts
|
|
139
143
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -145,6 +149,10 @@ export declare class FDocumentSection {
|
|
|
145
149
|
setColumns(columnCount: number, options?: IFDocumentSectionColumnOptions): boolean;
|
|
146
150
|
/**
|
|
147
151
|
* Sets explicit OOXML-compatible column width and trailing-space values in 96-DPI layout pixels.
|
|
152
|
+
* @param {ISectionColumnProperties[]} columns Explicit widths and trailing spaces; an empty array restores a single column.
|
|
153
|
+
* @param {ColumnSeparatorType} [separator] Column separator style. Defaults to `ColumnSeparatorType.NONE`.
|
|
154
|
+
* @returns {boolean} Whether the section update succeeded.
|
|
155
|
+
* @throws {RangeError} If column dimensions or the separator are invalid, or columns exceed the available width.
|
|
148
156
|
* @example
|
|
149
157
|
* ```ts
|
|
150
158
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -271,6 +279,8 @@ export declare class FDocumentSection {
|
|
|
271
279
|
setPageSetup(pageSetup: FDocumentSectionPageSetup): boolean;
|
|
272
280
|
/**
|
|
273
281
|
* Ensures a header segment linked specifically to this section.
|
|
282
|
+
* @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
|
|
283
|
+
* @returns {string} The existing or newly created section-specific segment ID.
|
|
274
284
|
* @example
|
|
275
285
|
* ```ts
|
|
276
286
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -285,6 +295,8 @@ export declare class FDocumentSection {
|
|
|
285
295
|
ensureHeader(variant?: SectionHeaderFooterVariant): string;
|
|
286
296
|
/**
|
|
287
297
|
* Ensures a footer segment linked specifically to this section.
|
|
298
|
+
* @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
|
|
299
|
+
* @returns {string} The existing or newly created section-specific segment ID.
|
|
288
300
|
* @example
|
|
289
301
|
* ```ts
|
|
290
302
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -299,6 +311,8 @@ export declare class FDocumentSection {
|
|
|
299
311
|
ensureFooter(variant?: SectionHeaderFooterVariant): string;
|
|
300
312
|
/**
|
|
301
313
|
* Returns the effective header id after resolving links to previous sections.
|
|
314
|
+
* @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
|
|
315
|
+
* @returns {string | null} The effective segment ID, or `null` if no segment is available.
|
|
302
316
|
* @example
|
|
303
317
|
* ```ts
|
|
304
318
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -308,6 +322,8 @@ export declare class FDocumentSection {
|
|
|
308
322
|
getHeaderId(variant?: SectionHeaderFooterVariant): string | null;
|
|
309
323
|
/**
|
|
310
324
|
* Returns the effective footer id after resolving links to previous sections.
|
|
325
|
+
* @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
|
|
326
|
+
* @returns {string | null} The effective segment ID, or `null` if no segment is available.
|
|
311
327
|
* @example
|
|
312
328
|
* ```ts
|
|
313
329
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -317,6 +333,8 @@ export declare class FDocumentSection {
|
|
|
317
333
|
getFooterId(variant?: SectionHeaderFooterVariant): string | null;
|
|
318
334
|
/**
|
|
319
335
|
* Whether this header variant inherits the previous section's reference.
|
|
336
|
+
* @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
|
|
337
|
+
* @returns {boolean} Whether this variant inherits from the previous section.
|
|
320
338
|
* @example
|
|
321
339
|
* ```ts
|
|
322
340
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -326,6 +344,8 @@ export declare class FDocumentSection {
|
|
|
326
344
|
isHeaderLinkedToPrevious(variant?: SectionHeaderFooterVariant): boolean;
|
|
327
345
|
/**
|
|
328
346
|
* Whether this footer variant inherits the previous section's reference.
|
|
347
|
+
* @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
|
|
348
|
+
* @returns {boolean} Whether this variant inherits from the previous section.
|
|
329
349
|
* @example
|
|
330
350
|
* ```ts
|
|
331
351
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -335,6 +355,9 @@ export declare class FDocumentSection {
|
|
|
335
355
|
isFooterLinkedToPrevious(variant?: SectionHeaderFooterVariant): boolean;
|
|
336
356
|
/**
|
|
337
357
|
* Links or unlinks this header variant. Unlinking clones the inherited header.
|
|
358
|
+
* @param {boolean} linkedToPrevious Whether to inherit the previous section's header/footer.
|
|
359
|
+
* @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
|
|
360
|
+
* @returns {boolean} Whether the link update succeeded.
|
|
338
361
|
* @example
|
|
339
362
|
* ```ts
|
|
340
363
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -346,6 +369,9 @@ export declare class FDocumentSection {
|
|
|
346
369
|
setHeaderLinkedToPrevious(linkedToPrevious: boolean, variant?: SectionHeaderFooterVariant): boolean;
|
|
347
370
|
/**
|
|
348
371
|
* Links or unlinks this footer variant. Unlinking clones the inherited footer.
|
|
372
|
+
* @param {boolean} linkedToPrevious Whether to inherit the previous section's header/footer.
|
|
373
|
+
* @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
|
|
374
|
+
* @returns {boolean} Whether the link update succeeded.
|
|
349
375
|
* @example
|
|
350
376
|
* ```ts
|
|
351
377
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -358,6 +384,8 @@ export declare class FDocumentSection {
|
|
|
358
384
|
/**
|
|
359
385
|
* Updates header/footer switches and margins on this section break.
|
|
360
386
|
* `marginHeader` and `marginFooter` are in 96-DPI layout pixels.
|
|
387
|
+
* @param {IHeaderFooterProps} options Header/footer switches and margins to update. Omitted properties are preserved.
|
|
388
|
+
* @returns {boolean} Whether the update command succeeded.
|
|
361
389
|
* @example
|
|
362
390
|
* ```ts
|
|
363
391
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -108,6 +108,8 @@ export declare class FDocumentTextRange extends FBaseInitialable {
|
|
|
108
108
|
* Existing text-run splitting, merging, and normalization are handled by
|
|
109
109
|
* the document mutation pipeline.
|
|
110
110
|
* `style.fs` is a font size in points (pt), not CSS pixels.
|
|
111
|
+
* @param {ITextStyle} style Text-style properties to merge into the range.
|
|
112
|
+
* @returns {boolean} Whether the style update succeeded; `false` for an empty range.
|
|
111
113
|
* @example
|
|
112
114
|
* ```ts
|
|
113
115
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -118,6 +120,8 @@ export declare class FDocumentTextRange extends FBaseInitialable {
|
|
|
118
120
|
setTextStyle(style: ITextStyle): boolean;
|
|
119
121
|
/**
|
|
120
122
|
* Replaces the range with plain text while preserving document mutation semantics.
|
|
123
|
+
* @param {string} text Replacement plain text. An empty string deletes the range.
|
|
124
|
+
* @returns {boolean} Whether the replacement succeeded.
|
|
121
125
|
* @example
|
|
122
126
|
* ```ts
|
|
123
127
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -66,11 +66,14 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
66
66
|
protected readonly _resourceLoaderService: IResourceLoaderService;
|
|
67
67
|
private readonly _commandService;
|
|
68
68
|
private readonly _permissionService;
|
|
69
|
+
/**
|
|
70
|
+
* The document unit id used to identify this document in commands and snapshots.
|
|
71
|
+
*/
|
|
69
72
|
readonly id: string;
|
|
70
73
|
constructor(_documentDataModel: DocumentDataModel, _injector: Injector, _univerInstanceService: IUniverInstanceService, _resourceLoaderService: IResourceLoaderService, _commandService: ICommandService, _permissionService: IPermissionService);
|
|
71
74
|
/**
|
|
72
75
|
* Get the document data model of the document.
|
|
73
|
-
* @param {string} segmentId The segment id used to get the header/footer data model. Defaults to an empty string for the document data model of the document.
|
|
76
|
+
* @param {string} [segmentId] The segment id used to get the header/footer data model. Defaults to an empty string for the document data model of the document.
|
|
74
77
|
* @returns {DocumentDataModel} The document data model.
|
|
75
78
|
* @example
|
|
76
79
|
* ```typescript
|
|
@@ -101,7 +104,7 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
101
104
|
* Get the document body or header/footer body by the segment id.
|
|
102
105
|
* The main body has an empty segment id.
|
|
103
106
|
* The header and footer body have their respective segment ids.
|
|
104
|
-
* @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
|
|
107
|
+
* @param {string} [segmentId] The segment id of the body. Defaults to an empty string for the main body.
|
|
105
108
|
* @returns {IDocumentBody} The document body.
|
|
106
109
|
* @example
|
|
107
110
|
* ```typescript
|
|
@@ -113,6 +116,7 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
113
116
|
* ```
|
|
114
117
|
*/
|
|
115
118
|
getBody(segmentId?: string): IDocumentBody;
|
|
119
|
+
/** Releases this facade's resources. Use `univerAPI.disposeUnit()` to unload the owning unit. */
|
|
116
120
|
dispose(): void;
|
|
117
121
|
/**
|
|
118
122
|
* Get the document id.
|
|
@@ -271,7 +275,7 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
271
275
|
redo(): boolean;
|
|
272
276
|
/**
|
|
273
277
|
* Ensure the page header segment exists and return its segment id.
|
|
274
|
-
* @param {number} pageIndex The zero-based page index. Defaults to the first page.
|
|
278
|
+
* @param {number} [pageIndex] The zero-based page index. Defaults to the first page.
|
|
275
279
|
* @returns {string} The header segment id.
|
|
276
280
|
* @example
|
|
277
281
|
* ```ts
|
|
@@ -283,7 +287,7 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
283
287
|
ensurePageHeader(pageIndex?: number): string;
|
|
284
288
|
/**
|
|
285
289
|
* Ensure the page footer segment exists and return its segment id.
|
|
286
|
-
* @param {number} pageIndex The zero-based page index. Defaults to the first page.
|
|
290
|
+
* @param {number} [pageIndex] The zero-based page index. Defaults to the first page.
|
|
287
291
|
* @returns {string} The footer segment id.
|
|
288
292
|
* @example
|
|
289
293
|
* ```ts
|
|
@@ -297,7 +301,7 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
297
301
|
* Insert plain text at a document body offset.
|
|
298
302
|
* @param {number} index The zero-based insertion offset.
|
|
299
303
|
* @param {string} text The plain text to insert.
|
|
300
|
-
* @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
|
|
304
|
+
* @param {string} [segmentId] The segment id of the body. Defaults to an empty string for the main body.
|
|
301
305
|
* @returns {boolean} `true` if the edit was applied.
|
|
302
306
|
* @example
|
|
303
307
|
* ```ts
|
|
@@ -324,6 +328,8 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
324
328
|
* Traditional and Unspecified documents keep the legacy header/footer
|
|
325
329
|
* behavior. Modern documents reject this API. `marginHeader` and
|
|
326
330
|
* `marginFooter` use 96-DPI layout pixels.
|
|
331
|
+
* @param {IHeaderFooterProps} options Header/footer switches and margins to update. Omitted properties are preserved.
|
|
332
|
+
* @returns {boolean} Whether the update command succeeded.
|
|
327
333
|
* @example
|
|
328
334
|
* ```ts
|
|
329
335
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -341,7 +347,7 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
341
347
|
* The end offset is exclusive, and offsets are scoped to the selected body segment.
|
|
342
348
|
* @param {number} startOffset The inclusive start offset.
|
|
343
349
|
* @param {number} endOffset The exclusive end offset.
|
|
344
|
-
* @param {string} segmentId The header/footer segment id, or an empty string for the main body.
|
|
350
|
+
* @param {string} [segmentId] The header/footer segment id, or an empty string for the main body.
|
|
345
351
|
* @returns {FDocumentTextRange} A fixed text-range facade.
|
|
346
352
|
* @example
|
|
347
353
|
* ```ts
|
|
@@ -364,6 +370,8 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
364
370
|
getSections(): FDocumentSection[];
|
|
365
371
|
/**
|
|
366
372
|
* Returns a traditional section by zero-based index, or `null` in modern documents.
|
|
373
|
+
* @param {number} index Zero-based section index.
|
|
374
|
+
* @returns {FDocumentSection | null} The matching section, or `null` if none exists or the document is not Traditional.
|
|
367
375
|
* @example
|
|
368
376
|
* ```ts
|
|
369
377
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -374,6 +382,8 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
374
382
|
getSection(index: number): FDocumentSection | null;
|
|
375
383
|
/**
|
|
376
384
|
* Returns the traditional section containing a data-stream offset, or `null` in modern documents.
|
|
385
|
+
* @param {number} offset Zero-based data-stream offset in the main document body.
|
|
386
|
+
* @returns {FDocumentSection | null} The matching section, or `null` if none exists or the document is not Traditional.
|
|
377
387
|
* @example
|
|
378
388
|
* ```ts
|
|
379
389
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -442,6 +452,8 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
442
452
|
* In a single-column section, the traditional renderer advances to the next physical page.
|
|
443
453
|
* Modern documents must use ColumnGroup. Unspecified documents must resolve
|
|
444
454
|
* their flavor first. Both throw `DocsSectionUnsupportedDocumentFlavorError`.
|
|
455
|
+
* @param {number} offset Zero-based data-stream offset at which to insert the column break.
|
|
456
|
+
* @returns {boolean} Whether the insertion succeeded.
|
|
445
457
|
* @example
|
|
446
458
|
* ```ts
|
|
447
459
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -459,6 +471,10 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
459
471
|
* Inserts a horizontal rule using the existing paragraph `borderBottom` mechanism.
|
|
460
472
|
* The returned paragraph can be inspected or removed with normal paragraph APIs.
|
|
461
473
|
* Border width and padding are in points (pt).
|
|
474
|
+
* @param {number} offset Zero-based insertion offset in the selected body segment.
|
|
475
|
+
* @param {IParagraphBorder} [border] Bottom border appearance. Defaults to a solid gray 1 pt line with 5 pt padding.
|
|
476
|
+
* @param {string} [segmentId] Header/footer segment ID, or an empty string for the main body (default).
|
|
477
|
+
* @returns {FDocumentParagraph | null} The inserted paragraph, or `null` if insertion fails.
|
|
462
478
|
* @example
|
|
463
479
|
* ```ts
|
|
464
480
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -471,7 +487,7 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
471
487
|
insertHorizontalRule(offset: number, border?: IParagraphBorder, segmentId?: string): FDocumentParagraph | null;
|
|
472
488
|
/**
|
|
473
489
|
* Get all paragraphs in the document body or header/footer body by the segment id.
|
|
474
|
-
* @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
|
|
490
|
+
* @param {string} [segmentId] The segment id of the body. Defaults to an empty string for the main body.
|
|
475
491
|
* @returns {FDocumentParagraph[]} An array of paragraph facade instances.
|
|
476
492
|
* @example
|
|
477
493
|
* ```ts
|
|
@@ -488,7 +504,7 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
488
504
|
/**
|
|
489
505
|
* Get a paragraph by its paragraph id and segment id.
|
|
490
506
|
* @param {string} paragraphId The paragraph id.
|
|
491
|
-
* @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
|
|
507
|
+
* @param {string} [segmentId] The segment id of the body. Defaults to an empty string for the main body.
|
|
492
508
|
* @returns {FDocumentParagraph | null} The paragraph facade instance, or `null` if the paragraph is not found.
|
|
493
509
|
* @example
|
|
494
510
|
* ```ts
|
|
@@ -505,7 +521,7 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
505
521
|
/**
|
|
506
522
|
* Find a paragraph by its text content and segment id.
|
|
507
523
|
* @param {string} text The text content to search for.
|
|
508
|
-
* @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
|
|
524
|
+
* @param {string} [segmentId] The segment id of the body. Defaults to an empty string for the main body.
|
|
509
525
|
* @returns {FDocumentParagraph | null} The paragraph facade instance, or `null` if the paragraph is not found.
|
|
510
526
|
* @example
|
|
511
527
|
* ```ts
|
|
@@ -541,8 +557,8 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
541
557
|
/**
|
|
542
558
|
* Insert a plain-text paragraph before the paragraph at the given paragraph index.
|
|
543
559
|
* @param {number} index The zero-based paragraph insertion index.
|
|
544
|
-
* @param {string} text The paragraph text. Defaults to an empty paragraph.
|
|
545
|
-
* @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
|
|
560
|
+
* @param {string} [text] The paragraph text. Defaults to an empty paragraph.
|
|
561
|
+
* @param {string} [segmentId] The segment id of the body. Defaults to an empty string for the main body.
|
|
546
562
|
* @returns {FDocumentParagraph} The inserted paragraph facade instance.
|
|
547
563
|
* @example
|
|
548
564
|
* ```ts
|
|
@@ -558,8 +574,8 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
558
574
|
insertParagraph(index: number, text?: string, segmentId?: string): FDocumentParagraph;
|
|
559
575
|
/**
|
|
560
576
|
* Append a plain-text paragraph at the end of the body.
|
|
561
|
-
* @param {string} text The paragraph text. Defaults to an empty paragraph.
|
|
562
|
-
* @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
|
|
577
|
+
* @param {string} [text] The paragraph text. Defaults to an empty paragraph.
|
|
578
|
+
* @param {string} [segmentId] The segment id of the body. Defaults to an empty string for the main body.
|
|
563
579
|
* @returns {FDocumentParagraph} The appended paragraph wrapper.
|
|
564
580
|
* @example
|
|
565
581
|
* ```ts
|
|
@@ -23,11 +23,11 @@ export interface IFUniverDocsMixin {
|
|
|
23
23
|
/**
|
|
24
24
|
* Create a new document and get the API handler of that document.
|
|
25
25
|
* @param {Partial<IDocumentData>} data The snapshot of the document.
|
|
26
|
-
* @param {ICreateUnitOptions} options The options of creating the document.
|
|
26
|
+
* @param {ICreateUnitOptions} [options] The options of creating the document.
|
|
27
27
|
* @returns {FDocument} The document API instance.
|
|
28
28
|
* @example
|
|
29
29
|
* ```typescript
|
|
30
|
-
* const fDocument = univerAPI.
|
|
30
|
+
* const fDocument = univerAPI.createDocument({ id: 'document-01', title: 'Document1' });
|
|
31
31
|
* console.log(fDocument);
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
@@ -16,8 +16,16 @@
|
|
|
16
16
|
export declare const DOCS_LAYOUT_WORKER_PLUGIN_CONFIG_KEY = "docs-layout-worker.config";
|
|
17
17
|
export declare const configSymbol: unique symbol;
|
|
18
18
|
export declare const DEFAULT_DOCS_LAYOUT_WORKER_REQUEST_TIMEOUT_MS = 15000;
|
|
19
|
+
export interface IDocsLayoutFontFace {
|
|
20
|
+
family: string;
|
|
21
|
+
/** Font bytes or a CSS FontFace source, such as url("https://example.test/font.woff2"). */
|
|
22
|
+
source: string | ArrayBuffer;
|
|
23
|
+
descriptors?: FontFaceDescriptors;
|
|
24
|
+
}
|
|
19
25
|
export interface IUniverDocsLayoutWorkerConfig {
|
|
20
26
|
workerFactory?: () => Worker;
|
|
27
|
+
/** Licensed web fonts to load in both the rendering context and the layout Worker before layout. */
|
|
28
|
+
fontFaces?: IDocsLayoutFontFace[];
|
|
21
29
|
/** Maximum time allowed for one Worker RPC request before recovery starts. */
|
|
22
30
|
requestTimeoutMs?: number;
|
|
23
31
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { IDocsLayoutFontFace } from './config/config';
|
|
17
|
+
import { Disposable } from '@univerjs/core';
|
|
18
|
+
/** Owns the same explicitly supplied font faces in the rendering and layout realms. */
|
|
19
|
+
export declare class DocsLayoutFontLoader extends Disposable {
|
|
20
|
+
private _loading;
|
|
21
|
+
private _fontSet;
|
|
22
|
+
private _faces;
|
|
23
|
+
load(fonts: readonly IDocsLayoutFontFace[]): Promise<void>;
|
|
24
|
+
dispose(): void;
|
|
25
|
+
private _load;
|
|
26
|
+
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import type { IDocLayoutCancelRequest, IDocLayoutCreateSessionRequest, IDocLayoutDisposeMountRequest, IDocLayoutDisposeSessionRequest, IDocLayoutExecutor, IDocLayoutPageRequest, IDocLayoutPageResult, IDocLayoutPerformanceMetrics, IDocLayoutStartRequest, IDocLayoutStartResult, IDocLayoutStepRequest, IDocLayoutStepResult } from '../services/doc-layout-executor.service';
|
|
17
|
-
import type { IUniverDocsLayoutWorkerConfig } from './config/config';
|
|
17
|
+
import type { IDocsLayoutFontFace, IUniverDocsLayoutWorkerConfig } from './config/config';
|
|
18
18
|
import type { IDocsLayoutWorkerCapabilities } from './protocol';
|
|
19
19
|
import { Disposable, IConfigService, Injector, Plugin } from '@univerjs/core';
|
|
20
20
|
import { DocLayoutExecutorService, DocLayoutExecutorType } from '../services/doc-layout-executor.service';
|
|
@@ -25,6 +25,7 @@ export declare class DocsLayoutWorkerCapabilityError extends Error {
|
|
|
25
25
|
export declare class DocsLayoutWorkerClientService extends Disposable implements IDocLayoutExecutor {
|
|
26
26
|
private readonly _workerFactory;
|
|
27
27
|
private readonly _requestTimeoutMs;
|
|
28
|
+
private readonly _fontFaces;
|
|
28
29
|
readonly type = DocLayoutExecutorType.WORKER;
|
|
29
30
|
private _worker;
|
|
30
31
|
private _channelService;
|
|
@@ -33,8 +34,10 @@ export declare class DocsLayoutWorkerClientService extends Disposable implements
|
|
|
33
34
|
private _initialized;
|
|
34
35
|
private readonly _performanceTracker;
|
|
35
36
|
private readonly _fontFamilies;
|
|
36
|
-
|
|
37
|
+
private readonly _fontLoader;
|
|
38
|
+
constructor(_workerFactory: () => Worker, _requestTimeoutMs?: number, _fontFaces?: IDocsLayoutFontFace[]);
|
|
37
39
|
initialize(): Promise<void>;
|
|
40
|
+
get renderingFontsReady(): Promise<void> | undefined;
|
|
38
41
|
getCapabilities(): Promise<IDocsLayoutWorkerCapabilities>;
|
|
39
42
|
recover(): Promise<void>;
|
|
40
43
|
createSession(request: IDocLayoutCreateSessionRequest): Promise<void>;
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import type { DocLayoutExecutorType, IDocLayoutExecutor } from '../services/doc-layout-executor.service';
|
|
17
|
+
import type { IDocsLayoutFontFace } from './config/config';
|
|
17
18
|
export declare const DOCS_LAYOUT_WORKER_CHANNEL = "univer.docs-layout-worker";
|
|
18
19
|
export declare const DOCS_LAYOUT_WORKER_PROTOCOL_VERSION = 5;
|
|
19
20
|
export interface IDocsLayoutWorkerFontProbe {
|
|
@@ -31,5 +32,6 @@ export interface IDocsLayoutWorkerCapabilities {
|
|
|
31
32
|
fontProbe: IDocsLayoutWorkerFontProbe;
|
|
32
33
|
}
|
|
33
34
|
export interface IDocsLayoutWorkerRuntime extends IDocLayoutExecutor {
|
|
35
|
+
initialize(fontFaces?: IDocsLayoutFontFace[]): Promise<void>;
|
|
34
36
|
getCapabilities(): Promise<IDocsLayoutWorkerCapabilities>;
|
|
35
37
|
}
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import type { IDocLayoutCancelRequest, IDocLayoutCreateSessionRequest, IDocLayoutDisposeMountRequest, IDocLayoutDisposeSessionRequest, IDocLayoutPageRequest, IDocLayoutPageResult, IDocLayoutPerformanceMetrics, IDocLayoutStartRequest, IDocLayoutStartResult, IDocLayoutStepRequest, IDocLayoutStepResult } from '../services/doc-layout-executor.service';
|
|
17
|
+
import type { IDocsLayoutFontFace } from './config/config';
|
|
17
18
|
import type { IDocsLayoutWorkerCapabilities, IDocsLayoutWorkerRuntime } from './protocol';
|
|
18
19
|
import { ChannelService } from '@univerjs/rpc';
|
|
19
20
|
import { DocLayoutExecutorType } from '../services/doc-layout-executor.service';
|
|
@@ -21,9 +22,10 @@ import { DocsLayoutWorkerPerformanceTracker } from './performance-tracker';
|
|
|
21
22
|
export declare class DocsLayoutWorkerRuntime implements IDocsLayoutWorkerRuntime {
|
|
22
23
|
private readonly _performanceTracker;
|
|
23
24
|
private readonly _sessions;
|
|
25
|
+
private readonly _fontLoader;
|
|
24
26
|
readonly type = DocLayoutExecutorType.WORKER;
|
|
25
27
|
constructor(_performanceTracker?: DocsLayoutWorkerPerformanceTracker);
|
|
26
|
-
initialize(): Promise<void>;
|
|
28
|
+
initialize(fontFaces?: IDocsLayoutFontFace[]): Promise<void>;
|
|
27
29
|
getCapabilities(): Promise<IDocsLayoutWorkerCapabilities>;
|
|
28
30
|
recover(): Promise<void>;
|
|
29
31
|
createSession(request: IDocLayoutCreateSessionRequest): Promise<void>;
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare class UniverDocsPlugin extends Plugin {
|
|
|
24
24
|
static version: string;
|
|
25
25
|
constructor(_config: Partial<IUniverDocsConfig> | undefined, _injector: Injector, _configService: IConfigService);
|
|
26
26
|
onStarting(): void;
|
|
27
|
+
private _initializeWordResources;
|
|
27
28
|
private _initializeCommands;
|
|
28
29
|
private _initializeDependencies;
|
|
29
30
|
onReady(): void;
|
|
@@ -80,6 +80,8 @@ export interface IDocLayoutStartRequest extends IDocLayoutMountIdentity {
|
|
|
80
80
|
anchor?: number;
|
|
81
81
|
priorityAnchor?: number;
|
|
82
82
|
invalidation?: IDocumentLayoutSessionStartOptions['invalidation'];
|
|
83
|
+
modernPageWidth?: number;
|
|
84
|
+
modernHorizontalMargin?: number;
|
|
83
85
|
customBlockViewports?: Record<string, IDocsCustomBlockRenderViewport>;
|
|
84
86
|
customBlockViewportPatch?: IDocLayoutRecordPatch<IDocsCustomBlockRenderViewport>;
|
|
85
87
|
customRangePresentations?: IDocLayoutCustomRangePresentationEntry[];
|
|
@@ -144,6 +146,8 @@ export interface IDocLayoutStepResult extends IDocumentLayoutStepResult, IDocLay
|
|
|
144
146
|
}
|
|
145
147
|
export interface IDocLayoutExecutor {
|
|
146
148
|
readonly type: DocLayoutExecutorType;
|
|
149
|
+
/** When present, foreground layout must wait for the configured rendering and Worker fonts. */
|
|
150
|
+
readonly renderingFontsReady?: Promise<void>;
|
|
147
151
|
initialize(): Promise<void>;
|
|
148
152
|
recover(): Promise<void>;
|
|
149
153
|
/**
|
|
@@ -166,6 +170,8 @@ export interface IDocLayoutStartOptions {
|
|
|
166
170
|
anchor?: number;
|
|
167
171
|
priorityAnchor?: number;
|
|
168
172
|
invalidation?: IDocumentLayoutSessionStartOptions['invalidation'];
|
|
173
|
+
modernPageWidth?: number;
|
|
174
|
+
modernHorizontalMargin?: number;
|
|
169
175
|
}
|
|
170
176
|
export declare class DocLayoutExecutorService extends Disposable {
|
|
171
177
|
private readonly _univerInstanceService;
|
|
@@ -38,12 +38,14 @@ export declare class DocStateChangeManagerService extends RxDisposable {
|
|
|
38
38
|
private _historyTimer;
|
|
39
39
|
private _changeStateCacheTimer;
|
|
40
40
|
constructor(_undoRedoService: Nullable<IUndoRedoService>, _commandService: ICommandService, _univerInstanceService: IUniverInstanceService, _docStateEmitService: DocStateEmitService, _docStateChangeInterceptorService?: IDocStateChangeInterceptorService | undefined);
|
|
41
|
+
dispose(): void;
|
|
41
42
|
getStateCache(unitId: string): {
|
|
42
43
|
history: IDocStateChangeParams[];
|
|
43
44
|
collaboration: IDocStateChangeParams[];
|
|
44
45
|
};
|
|
45
46
|
setStateCache(unitId: string, cache: IStateCache): void;
|
|
46
47
|
clearHistory(unitId: string): void;
|
|
48
|
+
flushPendingChanges(unitId: string): void;
|
|
47
49
|
private _setChangeState;
|
|
48
50
|
private _initialize;
|
|
49
51
|
private _listenDocStateChange;
|
|
@@ -17,6 +17,7 @@ import type { JSONXActions, Nullable } from '@univerjs/core';
|
|
|
17
17
|
import type { ITextRangeWithStyle } from '@univerjs/engine-render';
|
|
18
18
|
import { RxDisposable } from '@univerjs/core';
|
|
19
19
|
interface IDocChangeState {
|
|
20
|
+
layoutState?: unknown;
|
|
20
21
|
actions: JSONXActions;
|
|
21
22
|
textRanges: Nullable<ITextRangeWithStyle[]>;
|
|
22
23
|
options?: {
|
package/lib/umd/facade.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/docs"),require("@univerjs/protocol")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/core/facade`,`@univerjs/docs`,`@univerjs/protocol`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsFacade={},e.UniverCore,e.UniverCoreFacade,e.UniverDocs,e.UniverProtocol))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=class{constructor(e,t,n){this._unitId=e,this._commandService=t,this._permissionService=n}async setObjectPermissions(e){return this._commandService.executeCommand(r.SetDocumentPermissionsCommand.id,{unitId:this._unitId,changes:e})}async setPoint(e,t){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:e,value:t})}getPoint(e){return(0,r.getDocumentPermissionValue)(this._permissionService,this._unitId,this._unitId,e)}async setEditable(e=!0){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:i.UnitAction.Edit,value:e})}async setReadOnly(){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:i.UnitAction.Edit,value:!1})}canEdit(){return(0,r.getDocumentPermissionValue)(this._permissionService,this._unitId,this._unitId,i.UnitAction.Edit)}},o=class{constructor(e,t,n,r,i=()=>[]){this._unitId=e,this._objectId=t,this._commandService=n,this._permissionService=r,this._getParentObjectIds=i}async setEditable(e=!0){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._objectId,action:i.UnitAction.Edit,value:e})}async setReadOnly(){await this._commandService.executeCommand(r.SetDocumentPermissionCommand.id,{unitId:this._unitId,objectId:this._objectId,action:i.UnitAction.Edit,value:!1})}canEdit(){return(0,r.canEditDocumentTargets)(this._permissionService,this._unitId,[...this._getParentObjectIds(),this._objectId])}};function s(e){return e==null?e:JSON.parse(JSON.stringify(e))}function c(e){return e.replace(/\r\n/g,`\r`).replace(/\n/g,`\r`)}function l(e,t){let n=c(e);return t&&n.length>1&&n.startsWith(`\r`)?1:0}function u(e,n={}){let r=c(e).slice(l(e,n.removeLeadingParagraphBreak)),i={dataStream:r,customDecorations:[],customRanges:[],textRuns:[]},a=[],o=new Set;for(let e=0;e<r.length;e++)r[e]===`\r`&&a.push({startIndex:e,paragraphId:(0,t.createParagraphId)(o),...n.paragraphStyle==null?{}:{paragraphStyle:s(n.paragraphStyle)}});return a.length>0&&(i.paragraphs=a),i}function d(e,t,n,i){let{startOffset:a,endOffset:o,segmentId:s}=e;return!!i.syncExecuteCommand(r.InsertTextCommand.id,{unitId:n.getUnitId(),body:t,range:{startOffset:a,endOffset:o,collapsed:a===o,segmentId:s},segmentId:s,debounce:!1,textRanges:[],noNeedSetTextRange:!0,isEditing:!1})}function f(e,n,i,a,o){var s,c;let{startOffset:l,endOffset:u,segmentId:d}=e,f=o.get(t.ICommandService);if((s=n.textRuns)!=null&&s.length&&((c=a.getSelfOrHeaderFooterModel(d))==null||(c=c.getBody())==null?void 0:c.textRuns)==null){let e=t.JSONX.getInstance().replaceOp([...(0,t.getRichTextEditPath)(a,d),`textRuns`],void 0,[]);f.syncExecuteCommand(r.RichTextEditingMutation.id,{unitId:a.getUnitId(),segmentId:d,actions:e,textRanges:[],isEditing:!1})}let p=new t.TextX;l>0&&p.push({t:t.TextXActionType.RETAIN,len:l}),p.push({t:t.TextXActionType.RETAIN,body:n,coverType:i,len:u-l});let m=t.JSONX.getInstance().editOp(p.serialize(),(0,t.getRichTextEditPath)(a,d)),h=f.syncExecuteCommand(r.RichTextEditingMutation.id,{unitId:a.getUnitId(),segmentId:d,actions:m,textRanges:[],isEditing:!1});return!!(h!=null&&h.actions&&h.actions.length>0)}function p(e){return Array.from(e).map(e=>e===t.DataStreamTreeTokenType.PARAGRAPH?`
|
|
2
|
-
`:e).filter(e=>e!==t.DataStreamTreeTokenType.BLOCK_START&&e!==t.DataStreamTreeTokenType.BLOCK_END&&e!==t.DataStreamTreeTokenType.SECTION_BREAK).join(``).replace(/\n$/,``)}function m(e,t){return function(n,r){t(n,r,e)}}function h(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let g=class extends n.FBaseInitialable{constructor(e,t,n,r,i,a){super(i),this._document=e,this._startOffset=t,this._endOffset=n,this._segmentId=r,this._injector=i,this._commandService=a,this._validateRange()}getRange(){return{startOffset:this._startOffset,endOffset:this._endOffset,segmentId:this._segmentId}}getText(){return this._document.getBody(this._segmentId).dataStream.slice(this._startOffset,this._endOffset)}getExplicitTextStyleRuns(){let{textRuns:e=[]}=this._document.getBody(this._segmentId);return e.filter(e=>e.st<this._endOffset&&e.ed>this._startOffset).map(e=>({startOffset:Math.max(e.st,this._startOffset),endOffset:Math.min(e.ed,this._endOffset),textStyle:t.Tools.deepClone(e.ts??{})}))}getCommonExplicitTextStyle(){if(this._startOffset===this._endOffset)return{};let[e,...n]=this._getStyleSegments(),r=t.Tools.deepClone(e.textStyle);for(let e of Object.keys(r))n.some(t=>!_(t.textStyle[e],r[e]))&&delete r[e];return r}describe(){let e=this.getExplicitTextStyleRuns(),t=this.getCommonExplicitTextStyle();return{...this.getRange(),text:this.getText(),length:this._endOffset-this._startOffset,explicitTextStyleRuns:e,commonExplicitTextStyle:t}}setTextStyle(e){return this._startOffset!==this._endOffset&&f(this.getRange(),{dataStream:``,textRuns:[{st:0,ed:this._endOffset-this._startOffset,ts:t.Tools.deepClone(e)}]},t.UpdateDocsAttributeType.COVER,this._document.getDocumentDataModel(),this._injector)}setText(e){return d(this.getRange(),u(e),this._document.getDocumentDataModel(),this._commandService)}_validateRange(){let e=this._document.getBody(this._segmentId).dataStream.length;if(!Number.isInteger(this._startOffset)||!Number.isInteger(this._endOffset)||this._startOffset<0||this._endOffset<this._startOffset||this._endOffset>e)throw RangeError(`Invalid document text range [${this._startOffset}, ${this._endOffset}) for body length ${e}.`)}_getStyleSegments(){let e=this.getExplicitTextStyleRuns(),t=[],n=this._startOffset;for(let r of e)n<r.startOffset&&t.push({startOffset:n,endOffset:r.startOffset,textStyle:{}}),t.push(r),n=r.endOffset;return n<this._endOffset&&t.push({startOffset:n,endOffset:this._endOffset,textStyle:{}}),t}};g=h([m(5,t.ICommandService)],g);function _(e,t){return JSON.stringify(e)===JSON.stringify(t)}let v=class extends n.FBaseInitialable{constructor(e,t,n=``,r,i,a){super(r),this._document=e,this._paragraphId=t,this._segmentId=n,this._injector=r,this._commandService=i,this._permissionService=a}getId(){return this._paragraphId}getSegmentId(){return this._segmentId}getPermission(){return new o(this._document.getId(),(0,r.getDocumentParagraphPermissionObjectId)(this._segmentId,this._paragraphId),this._commandService,this._permissionService,()=>(0,r.getDocumentParagraphParentPermissionObjectIds)(this._document.getDocumentDataModel(),this._segmentId,this._paragraphId))}getInfo(){let e=this._document.getBody(this._segmentId),{paragraphs:n=[]}=e,r=n.map((e,t)=>({paragraph:e,paragraphIndex:t})).filter(({paragraph:e})=>e.paragraphId===this._paragraphId);if(r.length===0)throw Error(`Document paragraph with id ${this._paragraphId} not found`);if(r.length>1)throw Error(`Multiple document paragraphs with id ${this._paragraphId} found`);let{paragraph:i,paragraphIndex:a}=r[0];return{paragraph:i,paragraphIndex:a,startOffset:(0,t.getParagraphContentStartOffset)(e,i),endOffset:i.startIndex}}getRange(){let{startOffset:e,endOffset:t}=this.getInfo();return{startOffset:e,endOffset:t,segmentId:this._segmentId}}getTextRange(){let{startOffset:e,endOffset:t}=this.getInfo();return this._injector.createInstance(g,this._document,e,t,this._segmentId,this._injector)}findText(e,t={}){let n=t.occurrence??0;if(!Number.isInteger(n)||n<0)throw RangeError(`Text occurrence must be a non-negative integer.`);return this.findAllText(e,t)[n]??null}findAllText(e,n={}){if(e.length===0)throw TypeError(`Text to find must not be empty.`);let r=n.matchCase??!0,i=this.getText(),a=t.regexp.createLiteralRegExp(e,r?`gu`:`giu`),{startOffset:o}=this.getInfo(),s=[];for(let e of i.matchAll(a)){let t=o+e.index;s.push(this._injector.createInstance(g,this._document,t,t+e[0].length,this._segmentId,this._injector))}return s}getText(){let{dataStream:e}=this._document.getBody(this._segmentId),{startOffset:t,endOffset:n}=this.getInfo();return e.slice(t,n)}setText(e){let{startOffset:t,endOffset:n}=this.getInfo();return d({startOffset:t,endOffset:n,segmentId:this._segmentId},u(e),this._document.getDocumentDataModel(),this._commandService)}appendText(e){let{endOffset:t}=this.getInfo();return this._document.insertText(t,e,this._segmentId)}setStyle(e){let{startOffset:t,endOffset:n}=this.getInfo();return this._commandService.syncExecuteCommand(r.UpdateDocumentParagraphStyleCommand.id,{unitId:this._document.getId(),segmentId:this._segmentId,paragraphId:this._paragraphId,startOffset:t,endOffset:n,style:e})}isListItem(){let{paragraph:e}=this.getInfo();return!!e.bullet}isTask(){var e;let{paragraph:n}=this.getInfo(),r=(e=n.bullet)==null?void 0:e.listType;return r===t.PresetListType.CHECK_LIST||r===t.PresetListType.CHECK_LIST_CHECKED}setTaskChecked(e){if(!this.isTask())return!1;let{paragraph:n,endOffset:r}=this.getInfo(),i=n.bullet,a={dataStream:``,paragraphs:[{...n,startIndex:0,bullet:{...i,listType:e?t.PresetListType.CHECK_LIST_CHECKED:t.PresetListType.CHECK_LIST}}]};return this._preserveExplicitParagraphIds(a),f({startOffset:r,endOffset:r+1,segmentId:this._segmentId},a,t.UpdateDocsAttributeType.REPLACE,this._document.getDocumentDataModel(),this._injector)}remove(){let{startOffset:e,endOffset:t}=this.getInfo();return this._document.deleteRange({startOffset:e,endOffset:t+1,segmentId:this._segmentId})}_preserveExplicitParagraphIds(e){e[t.RESTORE_INSERTED_PARAGRAPH_IDS]=!0}};v=h([m(4,t.ICommandService),m(5,t.IPermissionService)],v);function y(e){return typeof e!=`object`||!e?!1:typeof e.getId==`function`&&typeof e.getSegmentId==`function`&&typeof e.getInfo==`function`&&typeof e.getRange==`function`}function b(e){let{pageNumberStart:n,pageSize:r,pageOrient:i,marginTop:a,marginBottom:o,marginLeft:s,marginRight:c}=e;if(n!=null&&(!Number.isInteger(n)||n<1))throw RangeError(`Section page number start must be a positive integer.`);if(r&&[r.width,r.height].some(e=>e!=null&&(!Number.isFinite(e)||e<=0)))throw RangeError(`Section page size must be finite and positive.`);if(i!=null&&!Object.values(t.PageOrientType).includes(i))throw RangeError(`Invalid section page orientation.`);if([a,o,s,c].some(e=>e!=null&&(!Number.isFinite(e)||e<0)))throw RangeError(`Section page margins must be finite and non-negative.`)}var x=class extends Error{constructor(){super(`Section column APIs are supported only in traditional documents. Use ColumnGroup APIs for modern documents, or resolve an unspecified document flavor first.`),this.name=`DocsSectionUnsupportedDocumentFlavorError`}};let S=class{constructor(e,t,n,r){this._document=e,this._sectionId=t,this._commandService=n,this._permissionService=r}getId(){return this._sectionId}getPermission(){return new o(this._document.getId(),(0,r.getDocumentSectionPermissionObjectId)(``,this._sectionId),this._commandService,this._permissionService)}getIndex(){return this._resolve().index}getConfig(){return this._getConfigSnapshot()}getRange(){return this._getRange(this._resolve().index)}getColumns(){return t.Tools.deepClone(this._getConfigSnapshot().columnProperties??[])}describe(){let{index:e}=this._resolve(),n=this._getConfigSnapshot(),r=n.columnProperties??[],i={defaultHeader:this._describeHeaderFooterReference(`header`,`default`),defaultFooter:this._describeHeaderFooterReference(`footer`,`default`),firstHeader:this._describeHeaderFooterReference(`header`,`first`),firstFooter:this._describeHeaderFooterReference(`footer`,`first`),evenHeader:this._describeHeaderFooterReference(`header`,`even`),evenFooter:this._describeHeaderFooterReference(`footer`,`even`)};return{sectionId:this._sectionId,index:e,range:this._getRange(e),columnCount:r.length||1,columns:t.Tools.deepClone(r),columnSeparatorType:n.columnSeparatorType??t.ColumnSeparatorType.NONE,sectionType:n.sectionType??t.SectionType.SECTION_TYPE_UNSPECIFIED,headerFooter:i,config:n}}setColumns(e,n={}){if(this._assertTraditionalDocument(),!Number.isInteger(e)||e<1)throw RangeError(`Section column count must be a positive integer.`);if(n.widths&&n.widths.length!==e)throw RangeError(`Section column widths must match the column count.`);if(n.gap!=null&&(!Number.isFinite(n.gap)||n.gap<0))throw RangeError(`Section column gap must be finite and non-negative.`);let i=Math.max(0,n.gap??18),a=this._getConfigSnapshot(),o=(0,r.createSectionColumnProperties)(this._document.getDocumentDataModel().getSnapshot().documentStyle,a,e,i,n.widths),s=typeof n.separator==`boolean`?n.separator?t.ColumnSeparatorType.BETWEEN_EACH_COLUMN:t.ColumnSeparatorType.NONE:n.separator??t.ColumnSeparatorType.NONE;if(!Object.values(t.ColumnSeparatorType).includes(s))throw RangeError(`Invalid section column separator type.`);return this._update({columnProperties:o,columnSeparatorType:s})}setColumnProperties(e,n=t.ColumnSeparatorType.NONE){if(this._assertTraditionalDocument(),!Object.values(t.ColumnSeparatorType).includes(n))throw RangeError(`Invalid section column separator type.`);if(e.some(({width:e,paddingEnd:t})=>!Number.isFinite(e)||!Number.isFinite(t)||e<0||t<0))throw RangeError(`Section column widths and padding must be finite and non-negative.`);let i=(0,r.getSectionContentWidth)(this._document.getDocumentDataModel().getSnapshot().documentStyle,this._getConfigSnapshot());if(e.reduce((e,{width:t,paddingEnd:n})=>e+t+n,0)>i)throw RangeError(`Section columns exceed the available page content width.`);return this._update({columnProperties:t.Tools.deepClone(e),columnSeparatorType:n})}setSectionType(e){if(this._assertTraditionalDocument(),!Object.values(t.SectionType).includes(e))throw RangeError(`Invalid section type.`);return this._update({sectionType:e})}getPageSetup(){let{pageNumberStart:e,pageSize:n,pageOrient:r,marginTop:i,marginBottom:a,marginLeft:o,marginRight:s}=this._getConfigSnapshot();return t.Tools.deepClone({pageNumberStart:e,pageSize:n,pageOrient:r,marginTop:i,marginBottom:a,marginLeft:o,marginRight:s})}getEffectivePageSetup(){this._assertTraditionalDocument();let e=this._document.getDocumentDataModel().getSnapshot().documentStyle;return t.Tools.deepClone((0,r.getEffectiveSectionPageSetup)(e,this._getConfigSnapshot()))}setPageSetup(e){this._assertTraditionalDocument(),b(e);let n=t.Tools.deepClone(e);t.Tools.removeNull(n);let i=this._document.getDocumentDataModel().getSnapshot().documentStyle;return(0,r.getEffectiveSectionPageSetup)(i,{...this._getConfigSnapshot(),...n}),this._update(n)}ensureHeader(e=`default`){return this._ensureHeaderFooter(`header`,e)}ensureFooter(e=`default`){return this._ensureHeaderFooter(`footer`,e)}getHeaderId(e=`default`){return this._getHeaderFooterReference(`header`,e).segmentId??null}getFooterId(e=`default`){return this._getHeaderFooterReference(`footer`,e).segmentId??null}isHeaderLinkedToPrevious(e=`default`){return this._getHeaderFooterReference(`header`,e).linkedToPrevious}isFooterLinkedToPrevious(e=`default`){return this._getHeaderFooterReference(`footer`,e).linkedToPrevious}setHeaderLinkedToPrevious(e,t=`default`){return this._setHeaderFooterLinkedToPrevious(`header`,t,e)}setFooterLinkedToPrevious(e,t=`default`){return this._setHeaderFooterLinkedToPrevious(`footer`,t,e)}setHeaderFooterOptions(e){return this._assertTraditionalDocument(),this._update(e)}remove(){return this._assertTraditionalDocument(),this._commandService.syncExecuteCommand(r.DeleteDocumentSectionBreakCommand.id,{unitId:this._document.getId(),sectionId:this._sectionId})}_update(e){let{sectionId:t,startIndex:n,...i}=e;return this._commandService.syncExecuteCommand(r.UpdateDocumentSectionCommand.id,{unitId:this._document.getId(),updates:[{sectionId:this._sectionId,config:i}]})}_ensureHeaderFooter(e,n){this._assertTraditionalDocument();let{index:i}=this._resolve(),a=this._getConfigSnapshot()[(0,t.getSectionHeaderFooterReferenceKey)(e,n)];if(typeof a==`string`&&a)return a;if(i>0){let i=(0,t.generateRandomId)(6);if(!this._commandService.syncExecuteCommand(r.SetSectionHeaderFooterLinkCommand.id,{unitId:this._document.getId(),sectionId:this._sectionId,kind:e,variant:n,linkedToPrevious:!1,segmentId:i}))throw Error(`Failed to create section ${e}.`);return i}let o={default:e===`header`?r.HeaderFooterType.DEFAULT_HEADER:r.HeaderFooterType.DEFAULT_FOOTER,first:e===`header`?r.HeaderFooterType.FIRST_PAGE_HEADER:r.HeaderFooterType.FIRST_PAGE_FOOTER,even:e===`header`?r.HeaderFooterType.EVEN_PAGE_HEADER:r.HeaderFooterType.EVEN_PAGE_FOOTER},s=(0,t.generateRandomId)(6);if(!this._commandService.syncExecuteCommand(r.CreateHeaderFooterCommand.id,{unitId:this._document.getId(),segmentId:s,createType:o[n],sectionId:this._sectionId}))throw Error(`Failed to create section ${e}.`);return s}_getHeaderFooterReference(e,n){let{index:i}=this._resolve();return(0,t.resolveSectionHeaderFooterReference)(this._document.getDocumentDataModel().getSnapshot().documentStyle,(0,r.getTopLevelSectionBreaks)(this._document.getBody()),i,(0,t.getSectionHeaderFooterReferenceKey)(e,n))}_describeHeaderFooterReference(e,t){let n=this._getHeaderFooterReference(e,t);return{segmentId:n.segmentId??null,linkedToPrevious:n.linkedToPrevious}}_setHeaderFooterLinkedToPrevious(e,n,i){return this._assertTraditionalDocument(),this._commandService.syncExecuteCommand(r.SetSectionHeaderFooterLinkCommand.id,{unitId:this._document.getId(),sectionId:this._sectionId,kind:e,variant:n,linkedToPrevious:i,...i?{}:{segmentId:(0,t.generateRandomId)(6)}})}_assertTraditionalDocument(){if(this._document.getDocumentDataModel().getSnapshot().documentStyle.documentFlavor!==t.DocumentFlavor.TRADITIONAL)throw new x}_getConfigSnapshot(){return t.Tools.deepClone(this._resolve().sectionBreak)}_getRange(e){let t=(0,r.getTopLevelSectionBreaks)(this._document.getBody());return{startOffset:e===0?0:t[e-1].startIndex+1,endOffset:t[e].startIndex,segmentId:``}}_resolve(){this._assertTraditionalDocument();let e=(0,r.getTopLevelSectionBreaks)(this._document.getBody()),t=e.findIndex(e=>e.sectionId===this._sectionId);if(t<0)throw Error(`Document section with id ${this._sectionId} not found.`);return{index:t,sectionBreak:e[t]}}};S=h([m(2,t.ICommandService),m(3,t.IPermissionService)],S);function C(e){"@babel/helpers - typeof";return C=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},C(e)}function w(e,t){if(C(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(C(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function T(e){var t=w(e,`string`);return C(t)==`symbol`?t:t+``}function E(e,t,n){return(t=T(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let D=class extends n.FBaseInitialable{constructor(e,t,n,r,i,a){super(t),this._documentDataModel=e,this._injector=t,this._univerInstanceService=n,this._resourceLoaderService=r,this._commandService=i,this._permissionService=a,E(this,`id`,void 0),this.id=this._documentDataModel.getUnitId()}getDocumentDataModel(e=``){let t=this._documentDataModel.getSelfOrHeaderFooterModel(e);if(!t)throw Error(e===``?`Document data model is not found.`:`Document data model is not found in the segment: ${e}`);return t}getCustomBlockLayout(){var e;return{blocks:(((e=this._documentDataModel.getBody())==null?void 0:e.customBlocks)??[]).map(({blockId:e,startIndex:t},n)=>({blockId:e,startIndex:t,index:n}))}}getBody(e=``){var t;let n=(t=this._documentDataModel.getSelfOrHeaderFooterModel(e))==null?void 0:t.getBody();if(!n)throw Error(e===``?`Body is not found in the document.`:`Body is not found in the segment: ${e}`);return n}dispose(){super.dispose()}getId(){return this.id}getPermission(){return new a(this.id,this._commandService,this._permissionService)}getEntityPermission(e,t,n){return new o(this.id,(0,r.getDocumentEntityPermissionObjectId)(e,t,n),this._commandService,this._permissionService,()=>(0,r.getDocumentEntityParentPermissionObjectIds)(this._documentDataModel,e,t,n))}getName(){return this._documentDataModel.getTitle()||``}setName(e){return this._commandService.syncExecuteCommand(r.SetDocumentNameCommand.id,{unitId:this.id,name:e}),this}getDocumentFlavor(){return this._resolveDocumentFlavor()}isTraditional(){return this._resolveDocumentFlavor()===t.DocumentFlavor.TRADITIONAL}isModern(){return this._resolveDocumentFlavor()===t.DocumentFlavor.MODERN}_resolveDocumentFlavor(){return this._documentDataModel.getSnapshot().documentStyle.documentFlavor??t.DocumentFlavor.UNSPECIFIED}save(){return this._resourceLoaderService.saveUnit(this._documentDataModel.getUnitId())}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(t.UndoCommand.id)}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(t.RedoCommand.id)}ensurePageHeader(e=0){return this._ensureHeaderFooter(`header`,e)}ensurePageFooter(e=0){return this._ensureHeaderFooter(`footer`,e)}insertText(e,t,n=``){return d({startOffset:e,endOffset:e,segmentId:n},u(t),this._documentDataModel,this._commandService)}getHeaderFooterOptions(){let e=this._documentDataModel.getSnapshot().documentStyle;return{marginHeader:e.marginHeader,marginFooter:e.marginFooter,useFirstPageHeaderFooter:e.useFirstPageHeaderFooter,evenAndOddHeaders:e.evenAndOddHeaders}}setHeaderFooterOptions(e){if(this.isModern())throw Error(`The document is a modern document, header/footer is not supported.`);return this._commandService.syncExecuteCommand(r.CreateHeaderFooterCommand.id,{unitId:this.getId(),headerFooterProps:e})}getTextRange(e,t,n=``){return this._injector.createInstance(g,this,e,t,n,this._injector)}getSections(){return this._documentDataModel.getSnapshot().documentStyle.documentFlavor===t.DocumentFlavor.TRADITIONAL?(0,r.getTopLevelSectionBreaks)(this.getBody()).map(e=>this._injector.createInstance(S,this,e.sectionId)):[]}getSection(e){return this.getSections()[e]??null}getSectionAt(e){return this.getSections().find(t=>{let n=t.getRange();return e>=n.startOffset&&e<n.endOffset})??null}insertSectionBreak(e,n={}){if(this._documentDataModel.getSnapshot().documentStyle.documentFlavor!==t.DocumentFlavor.TRADITIONAL)throw new x;let{nextSectionType:i,...a}=n,o=(0,t.createSectionId)(new Set((this.getBody().sectionBreaks??[]).map(e=>e.sectionId)));return this._commandService.syncExecuteCommand(r.InsertDocumentSectionBreakCommand.id,{unitId:this.getId(),offset:e,sectionId:o,config:a,nextSectionType:i})?this._injector.createInstance(S,this,o):null}insertColumnBreak(e){if(this._documentDataModel.getSnapshot().documentStyle.documentFlavor!==t.DocumentFlavor.TRADITIONAL)throw new x;return this._commandService.syncExecuteCommand(r.InsertDocumentColumnBreakCommand.id,{unitId:this.getId(),offset:e})}insertHorizontalRule(e,n={padding:5,color:{rgb:`#CDD0D8`},width:1,dashStyle:t.DashStyleType.SOLID},i=``){var a;let o=this.getBody(i),s=(0,r.generateParagraphs)(t.DataStreamTreeTokenType.PARAGRAPH,void 0,n,(a=o.paragraphs)==null?void 0:a.map(e=>e.paragraphId)),c=s[0].paragraphId;return d({startOffset:e,endOffset:e,segmentId:i},{dataStream:t.DataStreamTreeTokenType.PARAGRAPH,paragraphs:s},this._documentDataModel,this._commandService)?this.getParagraph(c,i):null}getParagraphs(e=``){let{paragraphs:t=[]}=this.getBody(e);return t.map(t=>this._createFDocumentParagraph(t.paragraphId,e))}getParagraph(e,t=``){let{paragraphs:n=[]}=this.getBody(t);return n.find(t=>t.paragraphId===e)?this._createFDocumentParagraph(e,t):null}findParagraphByText(e,t=``){return this.findParagraphs({text:e,segmentId:t})[0]||null}findParagraphs(e){let{text:t,paragraphId:n,segmentId:r=``}=typeof e==`string`?{text:e}:e;return this.getParagraphs(r).filter(e=>!(n&&e.getId()!==n||t&&!e.getText().includes(t)))}insertParagraph(e,t=``,n=``){let r=this._getParagraphInsertOffset(e,n);if(!d({startOffset:r,endOffset:r,segmentId:n},u(`${t}\r`),this._documentDataModel,this._commandService))throw Error(`Failed to insert paragraph.`);let{paragraphs:i=[]}=this.getBody(n),a=i[e];if(!a)throw Error(`Failed to insert paragraph.`);return this._createFDocumentParagraph(a.paragraphId,n)}appendParagraph(e=``,t=``){let{paragraphs:n=[]}=this.getBody(t);return this.insertParagraph(n.length,e,t)}deleteRange(e){let t=this._normalizeDeleteRange(e);return t.startOffset>=t.endOffset?!1:d(t,{dataStream:``},this._documentDataModel,this._commandService)}_createFDocumentParagraph(e,t=``){return this._injector.createInstance(v,this,e,t,this._injector)}_normalizeDeleteRange(e){let t=this.getBody(e.segmentId),n=t.dataStream.endsWith(`\r
|
|
2
|
+
`:e).filter(e=>e!==t.DataStreamTreeTokenType.BLOCK_START&&e!==t.DataStreamTreeTokenType.BLOCK_END&&e!==t.DataStreamTreeTokenType.SECTION_BREAK).join(``).replace(/\n$/,``)}function m(e,t){return function(n,r){t(n,r,e)}}function h(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let g=class extends n.FBaseInitialable{constructor(e,t,n,r,i,a){super(i),this._document=e,this._startOffset=t,this._endOffset=n,this._segmentId=r,this._injector=i,this._commandService=a,this._validateRange()}getRange(){return{startOffset:this._startOffset,endOffset:this._endOffset,segmentId:this._segmentId}}getText(){return this._document.getBody(this._segmentId).dataStream.slice(this._startOffset,this._endOffset)}getExplicitTextStyleRuns(){let{textRuns:e=[]}=this._document.getBody(this._segmentId);return e.filter(e=>e.st<this._endOffset&&e.ed>this._startOffset).map(e=>({startOffset:Math.max(e.st,this._startOffset),endOffset:Math.min(e.ed,this._endOffset),textStyle:t.Tools.deepClone(e.ts??{})}))}getCommonExplicitTextStyle(){if(this._startOffset===this._endOffset)return{};let[e,...n]=this._getStyleSegments(),r=t.Tools.deepClone(e.textStyle);for(let e of Object.keys(r))n.some(t=>!_(t.textStyle[e],r[e]))&&delete r[e];return r}describe(){let e=this.getExplicitTextStyleRuns(),t=this.getCommonExplicitTextStyle();return{...this.getRange(),text:this.getText(),length:this._endOffset-this._startOffset,explicitTextStyleRuns:e,commonExplicitTextStyle:t}}setTextStyle(e){return this._startOffset!==this._endOffset&&f(this.getRange(),{dataStream:``,textRuns:[{st:0,ed:this._endOffset-this._startOffset,ts:t.Tools.deepClone(e)}]},t.UpdateDocsAttributeType.COVER,this._document.getDocumentDataModel(),this._injector)}setText(e){return d(this.getRange(),u(e),this._document.getDocumentDataModel(),this._commandService)}_validateRange(){let e=this._document.getBody(this._segmentId).dataStream.length;if(!Number.isInteger(this._startOffset)||!Number.isInteger(this._endOffset)||this._startOffset<0||this._endOffset<this._startOffset||this._endOffset>e)throw RangeError(`Invalid document text range [${this._startOffset}, ${this._endOffset}) for body length ${e}.`)}_getStyleSegments(){let e=this.getExplicitTextStyleRuns(),t=[],n=this._startOffset;for(let r of e)n<r.startOffset&&t.push({startOffset:n,endOffset:r.startOffset,textStyle:{}}),t.push(r),n=r.endOffset;return n<this._endOffset&&t.push({startOffset:n,endOffset:this._endOffset,textStyle:{}}),t}};g=h([m(5,t.ICommandService)],g);function _(e,t){return JSON.stringify(e)===JSON.stringify(t)}let v=class extends n.FBaseInitialable{constructor(e,t,n=``,r,i,a){super(r),this._document=e,this._paragraphId=t,this._segmentId=n,this._injector=r,this._commandService=i,this._permissionService=a}getId(){return this._paragraphId}getSegmentId(){return this._segmentId}getPermission(){return new o(this._document.getId(),(0,r.getDocumentParagraphPermissionObjectId)(this._segmentId,this._paragraphId),this._commandService,this._permissionService,()=>(0,r.getDocumentParagraphParentPermissionObjectIds)(this._document.getDocumentDataModel(),this._segmentId,this._paragraphId))}getInfo(){let e=this._document.getBody(this._segmentId),{paragraphs:n=[]}=e,r=n.map((e,t)=>({paragraph:e,paragraphIndex:t})).filter(({paragraph:e})=>e.paragraphId===this._paragraphId);if(r.length===0)throw Error(`Document paragraph with id ${this._paragraphId} not found`);if(r.length>1)throw Error(`Multiple document paragraphs with id ${this._paragraphId} found`);let{paragraph:i,paragraphIndex:a}=r[0];return{paragraph:i,paragraphIndex:a,startOffset:(0,t.getParagraphContentStartOffset)(e,i),endOffset:i.startIndex}}getRange(){let{startOffset:e,endOffset:t}=this.getInfo();return{startOffset:e,endOffset:t,segmentId:this._segmentId}}getTextRange(){let{startOffset:e,endOffset:t}=this.getInfo();return this._injector.createInstance(g,this._document,e,t,this._segmentId,this._injector)}findText(e,t={}){let n=t.occurrence??0;if(!Number.isInteger(n)||n<0)throw RangeError(`Text occurrence must be a non-negative integer.`);return this.findAllText(e,t)[n]??null}findAllText(e,n={}){if(e.length===0)throw TypeError(`Text to find must not be empty.`);let r=n.matchCase??!0,i=this.getText(),a=t.regexp.createLiteralRegExp(e,r?`gu`:`giu`),{startOffset:o}=this.getInfo(),s=[];for(let e of i.matchAll(a)){let t=o+e.index;s.push(this._injector.createInstance(g,this._document,t,t+e[0].length,this._segmentId,this._injector))}return s}getText(){let{dataStream:e}=this._document.getBody(this._segmentId),{startOffset:t,endOffset:n}=this.getInfo();return e.slice(t,n)}setText(e){let{startOffset:t,endOffset:n}=this.getInfo();return d({startOffset:t,endOffset:n,segmentId:this._segmentId},u(e),this._document.getDocumentDataModel(),this._commandService)}appendText(e){let{endOffset:t}=this.getInfo();return this._document.insertText(t,e,this._segmentId)}setStyle(e){let{startOffset:t,endOffset:n}=this.getInfo();return this._commandService.syncExecuteCommand(r.UpdateDocumentParagraphStyleCommand.id,{unitId:this._document.getId(),segmentId:this._segmentId,paragraphId:this._paragraphId,startOffset:t,endOffset:n,style:e})}isListItem(){let{paragraph:e}=this.getInfo();return!!e.bullet}isTask(){var e;let{paragraph:n}=this.getInfo(),r=(e=n.bullet)==null?void 0:e.listType;return r===t.PresetListType.CHECK_LIST||r===t.PresetListType.CHECK_LIST_CHECKED}setTaskChecked(e){if(!this.isTask())return!1;let{paragraph:n,endOffset:r}=this.getInfo(),i=n.bullet,a={dataStream:``,paragraphs:[{...n,startIndex:0,bullet:{...i,listType:e?t.PresetListType.CHECK_LIST_CHECKED:t.PresetListType.CHECK_LIST}}]};return this._preserveExplicitParagraphIds(a),f({startOffset:r,endOffset:r+1,segmentId:this._segmentId},a,t.UpdateDocsAttributeType.REPLACE,this._document.getDocumentDataModel(),this._injector)}remove(){let{startOffset:e,endOffset:t}=this.getInfo();return this._document.deleteRange({startOffset:e,endOffset:t+1,segmentId:this._segmentId})}_preserveExplicitParagraphIds(e){e[t.RESTORE_INSERTED_PARAGRAPH_IDS]=!0}};v=h([m(4,t.ICommandService),m(5,t.IPermissionService)],v);function y(e){return typeof e!=`object`||!e?!1:typeof e.getId==`function`&&typeof e.getSegmentId==`function`&&typeof e.getInfo==`function`&&typeof e.getRange==`function`}function b(e){let{pageNumberStart:n,pageSize:r,pageOrient:i,marginTop:a,marginBottom:o,marginLeft:s,marginRight:c}=e;if(n!=null&&(!Number.isInteger(n)||n<1))throw RangeError(`Section page number start must be a positive integer.`);if(r&&[r.width,r.height].some(e=>e!=null&&(!Number.isFinite(e)||e<=0)))throw RangeError(`Section page size must be finite and positive.`);if(i!=null&&!Object.values(t.PageOrientType).includes(i))throw RangeError(`Invalid section page orientation.`);if([a,o,s,c].some(e=>e!=null&&(!Number.isFinite(e)||e<0)))throw RangeError(`Section page margins must be finite and non-negative.`)}var x=class extends Error{constructor(){super(`Section column APIs are supported only in traditional documents. Use ColumnGroup APIs for modern documents, or resolve an unspecified document flavor first.`),this.name=`DocsSectionUnsupportedDocumentFlavorError`}};let S=class{constructor(e,t,n,r){this._document=e,this._sectionId=t,this._commandService=n,this._permissionService=r}getId(){return this._sectionId}getPermission(){return new o(this._document.getId(),(0,r.getDocumentSectionPermissionObjectId)(``,this._sectionId),this._commandService,this._permissionService)}getIndex(){return this._resolve().index}getConfig(){return this._getConfigSnapshot()}getRange(){return this._getRange(this._resolve().index)}getColumns(){return t.Tools.deepClone(this._getConfigSnapshot().columnProperties??[])}describe(){let{index:e}=this._resolve(),n=this._getConfigSnapshot(),r=n.columnProperties??[],i={defaultHeader:this._describeHeaderFooterReference(`header`,`default`),defaultFooter:this._describeHeaderFooterReference(`footer`,`default`),firstHeader:this._describeHeaderFooterReference(`header`,`first`),firstFooter:this._describeHeaderFooterReference(`footer`,`first`),evenHeader:this._describeHeaderFooterReference(`header`,`even`),evenFooter:this._describeHeaderFooterReference(`footer`,`even`)};return{sectionId:this._sectionId,index:e,range:this._getRange(e),columnCount:r.length||1,columns:t.Tools.deepClone(r),columnSeparatorType:n.columnSeparatorType??t.ColumnSeparatorType.NONE,sectionType:n.sectionType??t.SectionType.SECTION_TYPE_UNSPECIFIED,headerFooter:i,config:n}}setColumns(e,n={}){if(this._assertTraditionalDocument(),!Number.isInteger(e)||e<1)throw RangeError(`Section column count must be a positive integer.`);if(n.widths&&n.widths.length!==e)throw RangeError(`Section column widths must match the column count.`);if(n.gap!=null&&(!Number.isFinite(n.gap)||n.gap<0))throw RangeError(`Section column gap must be finite and non-negative.`);let i=Math.max(0,n.gap??18),a=this._getConfigSnapshot(),o=(0,r.createSectionColumnProperties)(this._document.getDocumentDataModel().getSnapshot().documentStyle,a,e,i,n.widths),s=typeof n.separator==`boolean`?n.separator?t.ColumnSeparatorType.BETWEEN_EACH_COLUMN:t.ColumnSeparatorType.NONE:n.separator??t.ColumnSeparatorType.NONE;if(!Object.values(t.ColumnSeparatorType).includes(s))throw RangeError(`Invalid section column separator type.`);return this._update({columnProperties:o,columnSeparatorType:s})}setColumnProperties(e,n=t.ColumnSeparatorType.NONE){if(this._assertTraditionalDocument(),!Object.values(t.ColumnSeparatorType).includes(n))throw RangeError(`Invalid section column separator type.`);if(e.some(({width:e,paddingEnd:t})=>!Number.isFinite(e)||!Number.isFinite(t)||e<0||t<0))throw RangeError(`Section column widths and padding must be finite and non-negative.`);let i=(0,r.getSectionContentWidth)(this._document.getDocumentDataModel().getSnapshot().documentStyle,this._getConfigSnapshot());if(e.reduce((e,{width:t,paddingEnd:n})=>e+t+n,0)>i)throw RangeError(`Section columns exceed the available page content width.`);return this._update({columnProperties:t.Tools.deepClone(e),columnSeparatorType:n})}setSectionType(e){if(this._assertTraditionalDocument(),!Object.values(t.SectionType).includes(e))throw RangeError(`Invalid section type.`);return this._update({sectionType:e})}getPageSetup(){let{pageNumberStart:e,pageSize:n,pageOrient:r,marginTop:i,marginBottom:a,marginLeft:o,marginRight:s}=this._getConfigSnapshot();return t.Tools.deepClone({pageNumberStart:e,pageSize:n,pageOrient:r,marginTop:i,marginBottom:a,marginLeft:o,marginRight:s})}getEffectivePageSetup(){this._assertTraditionalDocument();let e=this._document.getDocumentDataModel().getSnapshot().documentStyle;return t.Tools.deepClone((0,r.getEffectiveSectionPageSetup)(e,this._getConfigSnapshot()))}setPageSetup(e){this._assertTraditionalDocument(),b(e);let n=t.Tools.deepClone(e);t.Tools.removeNull(n);let i=this._document.getDocumentDataModel().getSnapshot().documentStyle;return(0,r.getEffectiveSectionPageSetup)(i,{...this._getConfigSnapshot(),...n}),this._update(n)}ensureHeader(e=`default`){return this._ensureHeaderFooter(`header`,e)}ensureFooter(e=`default`){return this._ensureHeaderFooter(`footer`,e)}getHeaderId(e=`default`){return this._getHeaderFooterReference(`header`,e).segmentId??null}getFooterId(e=`default`){return this._getHeaderFooterReference(`footer`,e).segmentId??null}isHeaderLinkedToPrevious(e=`default`){return this._getHeaderFooterReference(`header`,e).linkedToPrevious}isFooterLinkedToPrevious(e=`default`){return this._getHeaderFooterReference(`footer`,e).linkedToPrevious}setHeaderLinkedToPrevious(e,t=`default`){return this._setHeaderFooterLinkedToPrevious(`header`,t,e)}setFooterLinkedToPrevious(e,t=`default`){return this._setHeaderFooterLinkedToPrevious(`footer`,t,e)}setHeaderFooterOptions(e){return this._assertTraditionalDocument(),this._update(e)}remove(){return this._assertTraditionalDocument(),this._commandService.syncExecuteCommand(r.DeleteDocumentSectionBreakCommand.id,{unitId:this._document.getId(),sectionId:this._sectionId})}_update(e){let{sectionId:t,startIndex:n,...i}=e;return this._commandService.syncExecuteCommand(r.UpdateDocumentSectionCommand.id,{unitId:this._document.getId(),updates:[{sectionId:this._sectionId,config:i}]})}_ensureHeaderFooter(e,n){this._assertTraditionalDocument();let{index:i}=this._resolve(),a=this._getConfigSnapshot()[(0,t.getSectionHeaderFooterReferenceKey)(e,n)];if(typeof a==`string`&&a)return a;if(i>0){let i=(0,t.generateRandomId)(6);if(!this._commandService.syncExecuteCommand(r.SetSectionHeaderFooterLinkCommand.id,{unitId:this._document.getId(),sectionId:this._sectionId,kind:e,variant:n,linkedToPrevious:!1,segmentId:i}))throw Error(`Failed to create section ${e}.`);return i}let o={default:e===`header`?r.HeaderFooterType.DEFAULT_HEADER:r.HeaderFooterType.DEFAULT_FOOTER,first:e===`header`?r.HeaderFooterType.FIRST_PAGE_HEADER:r.HeaderFooterType.FIRST_PAGE_FOOTER,even:e===`header`?r.HeaderFooterType.EVEN_PAGE_HEADER:r.HeaderFooterType.EVEN_PAGE_FOOTER},s=(0,t.generateRandomId)(6);if(!this._commandService.syncExecuteCommand(r.CreateHeaderFooterCommand.id,{unitId:this._document.getId(),segmentId:s,createType:o[n],sectionId:this._sectionId}))throw Error(`Failed to create section ${e}.`);return s}_getHeaderFooterReference(e,n){let{index:i}=this._resolve(),a=this._document.getDocumentDataModel().getSnapshot();return(0,t.resolveSectionHeaderFooterReference)(a.documentStyle,(0,r.getTopLevelSectionBreaks)(this._document.getBody()),i,(0,t.getSectionHeaderFooterReferenceKey)(e,n))}_describeHeaderFooterReference(e,t){let n=this._getHeaderFooterReference(e,t);return{segmentId:n.segmentId??null,linkedToPrevious:n.linkedToPrevious}}_setHeaderFooterLinkedToPrevious(e,n,i){return this._assertTraditionalDocument(),this._commandService.syncExecuteCommand(r.SetSectionHeaderFooterLinkCommand.id,{unitId:this._document.getId(),sectionId:this._sectionId,kind:e,variant:n,linkedToPrevious:i,...i?{}:{segmentId:(0,t.generateRandomId)(6)}})}_assertTraditionalDocument(){if(this._document.getDocumentDataModel().getSnapshot().documentStyle.documentFlavor!==t.DocumentFlavor.TRADITIONAL)throw new x}_getConfigSnapshot(){return t.Tools.deepClone(this._resolve().sectionBreak)}_getRange(e){let t=(0,r.getTopLevelSectionBreaks)(this._document.getBody());return{startOffset:e===0?0:t[e-1].startIndex+1,endOffset:t[e].startIndex,segmentId:``}}_resolve(){this._assertTraditionalDocument();let e=(0,r.getTopLevelSectionBreaks)(this._document.getBody()),t=e.findIndex(e=>e.sectionId===this._sectionId);if(t<0)throw Error(`Document section with id ${this._sectionId} not found.`);return{index:t,sectionBreak:e[t]}}};S=h([m(2,t.ICommandService),m(3,t.IPermissionService)],S);function C(e){"@babel/helpers - typeof";return C=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},C(e)}function w(e,t){if(C(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(C(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function T(e){var t=w(e,`string`);return C(t)==`symbol`?t:t+``}function E(e,t,n){return(t=T(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let D=class extends n.FBaseInitialable{constructor(e,t,n,r,i,a){super(t),this._documentDataModel=e,this._injector=t,this._univerInstanceService=n,this._resourceLoaderService=r,this._commandService=i,this._permissionService=a,E(this,`id`,void 0),this.id=this._documentDataModel.getUnitId()}getDocumentDataModel(e=``){let t=this._documentDataModel.getSelfOrHeaderFooterModel(e);if(!t)throw Error(e===``?`Document data model is not found.`:`Document data model is not found in the segment: ${e}`);return t}getCustomBlockLayout(){var e;return{blocks:(((e=this._documentDataModel.getBody())==null?void 0:e.customBlocks)??[]).map(({blockId:e,startIndex:t},n)=>({blockId:e,startIndex:t,index:n}))}}getBody(e=``){var t;let n=(t=this._documentDataModel.getSelfOrHeaderFooterModel(e))==null?void 0:t.getBody();if(!n)throw Error(e===``?`Body is not found in the document.`:`Body is not found in the segment: ${e}`);return n}dispose(){super.dispose()}getId(){return this.id}getPermission(){return new a(this.id,this._commandService,this._permissionService)}getEntityPermission(e,t,n){return new o(this.id,(0,r.getDocumentEntityPermissionObjectId)(e,t,n),this._commandService,this._permissionService,()=>(0,r.getDocumentEntityParentPermissionObjectIds)(this._documentDataModel,e,t,n))}getName(){return this._documentDataModel.getTitle()||``}setName(e){return this._commandService.syncExecuteCommand(r.SetDocumentNameCommand.id,{unitId:this.id,name:e}),this}getDocumentFlavor(){return this._resolveDocumentFlavor()}isTraditional(){return this._resolveDocumentFlavor()===t.DocumentFlavor.TRADITIONAL}isModern(){return this._resolveDocumentFlavor()===t.DocumentFlavor.MODERN}_resolveDocumentFlavor(){return this._documentDataModel.getSnapshot().documentStyle.documentFlavor??t.DocumentFlavor.UNSPECIFIED}save(){return this._resourceLoaderService.saveUnit(this._documentDataModel.getUnitId())}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(t.UndoCommand.id)}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(t.RedoCommand.id)}ensurePageHeader(e=0){return this._ensureHeaderFooter(`header`,e)}ensurePageFooter(e=0){return this._ensureHeaderFooter(`footer`,e)}insertText(e,t,n=``){return d({startOffset:e,endOffset:e,segmentId:n},u(t),this._documentDataModel,this._commandService)}getHeaderFooterOptions(){let e=this._documentDataModel.getSnapshot().documentStyle;return{marginHeader:e.marginHeader,marginFooter:e.marginFooter,useFirstPageHeaderFooter:e.useFirstPageHeaderFooter,evenAndOddHeaders:e.evenAndOddHeaders}}setHeaderFooterOptions(e){if(this.isModern())throw Error(`The document is a modern document, header/footer is not supported.`);return this._commandService.syncExecuteCommand(r.CreateHeaderFooterCommand.id,{unitId:this.getId(),headerFooterProps:e})}getTextRange(e,t,n=``){return this._injector.createInstance(g,this,e,t,n,this._injector)}getSections(){return this._documentDataModel.getSnapshot().documentStyle.documentFlavor===t.DocumentFlavor.TRADITIONAL?(0,r.getTopLevelSectionBreaks)(this.getBody()).map(e=>this._injector.createInstance(S,this,e.sectionId)):[]}getSection(e){return this.getSections()[e]??null}getSectionAt(e){return this.getSections().find(t=>{let n=t.getRange();return e>=n.startOffset&&e<n.endOffset})??null}insertSectionBreak(e,n={}){if(this._documentDataModel.getSnapshot().documentStyle.documentFlavor!==t.DocumentFlavor.TRADITIONAL)throw new x;let{nextSectionType:i,...a}=n,o=(0,t.createSectionId)(new Set((this.getBody().sectionBreaks??[]).map(e=>e.sectionId)));return this._commandService.syncExecuteCommand(r.InsertDocumentSectionBreakCommand.id,{unitId:this.getId(),offset:e,sectionId:o,config:a,nextSectionType:i})?this._injector.createInstance(S,this,o):null}insertColumnBreak(e){if(this._documentDataModel.getSnapshot().documentStyle.documentFlavor!==t.DocumentFlavor.TRADITIONAL)throw new x;return this._commandService.syncExecuteCommand(r.InsertDocumentColumnBreakCommand.id,{unitId:this.getId(),offset:e})}insertHorizontalRule(e,n={padding:5,color:{rgb:`#CDD0D8`},width:1,dashStyle:t.DashStyleType.SOLID},i=``){var a;let o=this.getBody(i),s=(0,r.generateParagraphs)(t.DataStreamTreeTokenType.PARAGRAPH,void 0,n,(a=o.paragraphs)==null?void 0:a.map(e=>e.paragraphId)),c=s[0].paragraphId;return d({startOffset:e,endOffset:e,segmentId:i},{dataStream:t.DataStreamTreeTokenType.PARAGRAPH,paragraphs:s},this._documentDataModel,this._commandService)?this.getParagraph(c,i):null}getParagraphs(e=``){let{paragraphs:t=[]}=this.getBody(e);return t.map(t=>this._createFDocumentParagraph(t.paragraphId,e))}getParagraph(e,t=``){let{paragraphs:n=[]}=this.getBody(t);return n.find(t=>t.paragraphId===e)?this._createFDocumentParagraph(e,t):null}findParagraphByText(e,t=``){return this.findParagraphs({text:e,segmentId:t})[0]||null}findParagraphs(e){let{text:t,paragraphId:n,segmentId:r=``}=typeof e==`string`?{text:e}:e;return this.getParagraphs(r).filter(e=>!(n&&e.getId()!==n||t&&!e.getText().includes(t)))}insertParagraph(e,t=``,n=``){let r=this._getParagraphInsertOffset(e,n);if(!d({startOffset:r,endOffset:r,segmentId:n},u(`${t}\r`),this._documentDataModel,this._commandService))throw Error(`Failed to insert paragraph.`);let{paragraphs:i=[]}=this.getBody(n),a=i[e];if(!a)throw Error(`Failed to insert paragraph.`);return this._createFDocumentParagraph(a.paragraphId,n)}appendParagraph(e=``,t=``){let{paragraphs:n=[]}=this.getBody(t);return this.insertParagraph(n.length,e,t)}deleteRange(e){let t=this._normalizeDeleteRange(e);return t.startOffset>=t.endOffset?!1:d(t,{dataStream:``},this._documentDataModel,this._commandService)}_createFDocumentParagraph(e,t=``){return this._injector.createInstance(v,this,e,t,this._injector)}_normalizeDeleteRange(e){let t=this.getBody(e.segmentId),n=t.dataStream.endsWith(`\r
|
|
3
3
|
`)?Math.max(0,t.dataStream.length-2):t.dataStream.length,r=Math.min(Math.max(e.endOffset,0),n);return{...e,startOffset:Math.min(Math.max(e.startOffset,0),r),endOffset:r}}_getParagraphInsertOffset(e,n=``){if(e<=0)return 0;let r=this.getBody(n),{dataStream:i,paragraphs:a=[]}=r;return a.length===0?Math.max(0,i.length-1):e>=a.length?a[a.length-1].startIndex+1:(0,t.getParagraphContentStartOffset)(r,a[e])}_ensureHeaderFooter(e,n){if(this.isModern())throw Error(`The document is a modern document, header/footer is not supported.`);let{createType:i,segmentId:a}=this._getHeaderFooterCreateInfo(e,n);if(a)return a;let o=(0,t.generateRandomId)(6);if(!this._commandService.syncExecuteCommand(r.CreateHeaderFooterCommand.id,{unitId:this.getId(),segmentId:o,createType:i}))throw Error(`Failed to create page ${e}.`);return o}_getHeaderFooterCreateInfo(e,n){let{documentStyle:i}=this._documentDataModel.getSnapshot(),a=n===0,o=(n+1)%2==0;return a&&i.useFirstPageHeaderFooter===t.BooleanNumber.TRUE?e===`header`?{createType:r.HeaderFooterType.FIRST_PAGE_HEADER,segmentId:i.firstPageHeaderId??``}:{createType:r.HeaderFooterType.FIRST_PAGE_FOOTER,segmentId:i.firstPageFooterId??``}:o&&i.evenAndOddHeaders===t.BooleanNumber.TRUE?e===`header`?{createType:r.HeaderFooterType.EVEN_PAGE_HEADER,segmentId:i.evenPageHeaderId??``}:{createType:r.HeaderFooterType.EVEN_PAGE_FOOTER,segmentId:i.evenPageFooterId??``}:e===`header`?{createType:r.HeaderFooterType.DEFAULT_HEADER,segmentId:i.defaultHeaderId??``}:{createType:r.HeaderFooterType.DEFAULT_FOOTER,segmentId:i.defaultFooterId??``}}};D=h([m(1,(0,t.Inject)(t.Injector)),m(2,t.IUniverInstanceService),m(3,(0,t.Inject)(t.IResourceLoaderService)),m(4,t.ICommandService),m(5,t.IPermissionService)],D);var O=class extends n.FUniver{createDocument(e,n){let r=this._injector.get(t.IUniverInstanceService).createUnit(t.UniverInstanceType.UNIVER_DOC,e,n);return this._injector.createInstance(D,r)}getActiveDocument(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);return e?this._injector.createInstance(D,e):null}getDocument(e){let n=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_DOC);return n?this._injector.createInstance(D,n):null}};n.FUniver.extend(O);var k=class extends n.FEnum{get DocumentFlavor(){return t.DocumentFlavor}get SectionType(){return t.SectionType}get ColumnSeparatorType(){return t.ColumnSeparatorType}};n.FEnum.extend(k),e.DocsSectionUnsupportedDocumentFlavorError=x,e.FDocsEnumMixin=k,Object.defineProperty(e,"FDocument",{enumerable:!0,get:function(){return D}}),e.FDocumentObjectPermission=o,Object.defineProperty(e,"FDocumentParagraph",{enumerable:!0,get:function(){return v}}),e.FDocumentPermission=a,Object.defineProperty(e,"FDocumentSection",{enumerable:!0,get:function(){return S}}),Object.defineProperty(e,"FDocumentTextRange",{enumerable:!0,get:function(){return g}}),e.isParagraphFacade=y,e.stripBlockTokens=p});
|