@univerjs/docs 1.0.0-insiders.20260809-70eefdd → 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/README.md +0 -1
- package/lib/cjs/facade.js +331 -60
- package/lib/cjs/index.js +2472 -102
- package/lib/es/facade.js +326 -62
- package/lib/es/index.js +2419 -85
- package/lib/facade.js +326 -62
- package/lib/index.js +2419 -85
- package/lib/types/commands/commands/core-editing.command.d.ts +5 -1
- package/lib/types/commands/commands/set-document-permission.command.d.ts +27 -0
- package/lib/types/commands/commands/set-document-permissions.command.d.ts +17 -0
- package/lib/types/commands/mutations/core-editing.mutation-id.d.ts +16 -0
- package/lib/types/commands/mutations/core-editing.mutation.d.ts +20 -1
- package/lib/types/commands/mutations/doc-structure-mutation-validation.d.ts +17 -0
- package/lib/types/commands/mutations/set-document-permission-rule.mutation.d.ts +17 -0
- package/lib/types/commands/mutations/set-document-permission-rules.mutation.d.ts +17 -0
- package/lib/types/controllers/doc-permission.controller.d.ts +26 -0
- package/lib/types/facade/f-document-paragraph.d.ts +15 -2
- package/lib/types/facade/f-document-permission.d.ts +177 -0
- package/lib/types/facade/f-document-section.d.ts +15 -2
- package/lib/types/facade/f-document-text-range.d.ts +3 -1
- package/lib/types/facade/f-document.d.ts +34 -2
- package/lib/types/facade/f-univer.d.ts +4 -3
- package/lib/types/facade/index.d.ts +1 -0
- package/lib/types/facade/utils.d.ts +2 -1
- package/lib/types/index.d.ts +13 -1
- package/lib/types/layout-worker/config/config.d.ts +24 -0
- package/lib/types/layout-worker/document-font-metrics.d.ts +18 -0
- package/lib/types/layout-worker/index.d.ts +70 -0
- package/lib/types/layout-worker/performance-tracker.d.ts +27 -0
- package/lib/types/layout-worker/protocol.d.ts +35 -0
- package/lib/types/layout-worker/worker.d.ts +49 -0
- package/lib/types/services/doc-interceptor/interceptor-const.d.ts +2 -1
- package/lib/types/services/doc-layout-executor.service.d.ts +218 -0
- package/lib/types/services/doc-selection-manager.service.d.ts +7 -1
- package/lib/types/services/doc-skeleton-manager.service.d.ts +6 -1
- package/lib/types/services/doc-state-change-manager.service.d.ts +1 -0
- package/lib/types/services/doc-state-emit.service.d.ts +4 -0
- package/lib/types/services/document-layout-snapshot.d.ts +22 -0
- package/lib/types/services/permission/document-permission-resolver.d.ts +27 -0
- package/lib/types/services/permission/document-permission-rule.model.d.ts +19 -0
- package/lib/types/services/permission/document-permission.d.ts +35 -0
- package/lib/types/services/permission/permission-point/document/comment.d.ts +27 -0
- package/lib/types/services/permission/permission-point/document/copy.d.ts +27 -0
- package/lib/types/services/permission/permission-point/document/editable.d.ts +27 -0
- package/lib/types/services/permission/permission-point/document/export.d.ts +27 -0
- package/lib/types/services/permission/permission-point/document/print.d.ts +27 -0
- package/lib/types/services/permission/permission-point/entity/edit.d.ts +28 -0
- package/lib/types/services/permission/permission-point/paragraph/edit.d.ts +28 -0
- package/lib/types/services/permission/permission-point/section/edit.d.ts +28 -0
- package/lib/umd/facade.js +3 -3
- package/lib/umd/index.js +2 -2
- package/package.json +7 -5
|
@@ -0,0 +1,19 @@
|
|
|
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 { IResourceManagerService, ObjectPermissionRuleModel } from '@univerjs/core';
|
|
17
|
+
export declare class DocumentPermissionRuleModel extends ObjectPermissionRuleModel {
|
|
18
|
+
constructor(resources: IResourceManagerService);
|
|
19
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 { IPermissionService } from '@univerjs/core';
|
|
17
|
+
import { UnitAction } from '@univerjs/protocol';
|
|
18
|
+
import { DocumentCommentPermission } from './permission-point/document/comment';
|
|
19
|
+
import { DocumentCopyPermission } from './permission-point/document/copy';
|
|
20
|
+
import { DocumentEditablePermission } from './permission-point/document/editable';
|
|
21
|
+
import { DocumentExportPermission } from './permission-point/document/export';
|
|
22
|
+
import { DocumentPrintPermission } from './permission-point/document/print';
|
|
23
|
+
import { DocumentEntityEditPermission } from './permission-point/entity/edit';
|
|
24
|
+
import { DocumentParagraphEditPermission } from './permission-point/paragraph/edit';
|
|
25
|
+
import { DocumentSectionEditPermission } from './permission-point/section/edit';
|
|
26
|
+
export declare const DOCUMENT_UNIT_PERMISSION_ACTIONS: readonly [UnitAction.Edit, UnitAction.Copy, UnitAction.Print, UnitAction.Export, UnitAction.Comment];
|
|
27
|
+
export type DocumentUnitPermissionAction = typeof DOCUMENT_UNIT_PERMISSION_ACTIONS[number];
|
|
28
|
+
export declare function getDocumentSectionPermissionObjectId(segmentId: string, sectionId: string): string;
|
|
29
|
+
export declare function getDocumentParagraphPermissionObjectId(segmentId: string, paragraphId: string): string;
|
|
30
|
+
export declare function getDocumentEntityPermissionObjectId(segmentId: string, entityType: string, entityId: string): string;
|
|
31
|
+
export declare function createDocumentPermissionPoint(unitId: string, objectId: string, action: UnitAction): DocumentCommentPermission | DocumentCopyPermission | DocumentEditablePermission | DocumentExportPermission | DocumentPrintPermission | DocumentEntityEditPermission | DocumentParagraphEditPermission | DocumentSectionEditPermission;
|
|
32
|
+
export declare function getDocumentPermissionValue(permissionService: IPermissionService, unitId: string, objectId: string, action: UnitAction): boolean;
|
|
33
|
+
export declare function setDocumentPermissionValue(permissionService: IPermissionService, unitId: string, objectId: string, action: UnitAction, value: boolean): void;
|
|
34
|
+
export declare function clearDocumentPermissionValuesForUnit(permissionService: IPermissionService, unitId: string): void;
|
|
35
|
+
export declare function canEditDocumentTargets(permissionService: IPermissionService, unitId: string, objectIds: Iterable<string>): boolean;
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { IPermissionPoint } from '@univerjs/core';
|
|
17
|
+
import { PermissionStatus } from '@univerjs/core';
|
|
18
|
+
import { UnitAction, UnitObject } from '@univerjs/protocol';
|
|
19
|
+
export declare class DocumentCommentPermission implements IPermissionPoint {
|
|
20
|
+
readonly unitId: string;
|
|
21
|
+
readonly type = UnitObject.Document;
|
|
22
|
+
readonly subType = UnitAction.Comment;
|
|
23
|
+
readonly status = PermissionStatus.INIT;
|
|
24
|
+
readonly id: string;
|
|
25
|
+
value: boolean;
|
|
26
|
+
constructor(unitId: string);
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { IPermissionPoint } from '@univerjs/core';
|
|
17
|
+
import { PermissionStatus } from '@univerjs/core';
|
|
18
|
+
import { UnitAction, UnitObject } from '@univerjs/protocol';
|
|
19
|
+
export declare class DocumentCopyPermission implements IPermissionPoint {
|
|
20
|
+
readonly unitId: string;
|
|
21
|
+
readonly type = UnitObject.Document;
|
|
22
|
+
readonly subType = UnitAction.Copy;
|
|
23
|
+
readonly status = PermissionStatus.INIT;
|
|
24
|
+
readonly id: string;
|
|
25
|
+
value: boolean;
|
|
26
|
+
constructor(unitId: string);
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { IPermissionPoint } from '@univerjs/core';
|
|
17
|
+
import { PermissionStatus } from '@univerjs/core';
|
|
18
|
+
import { UnitAction, UnitObject } from '@univerjs/protocol';
|
|
19
|
+
export declare class DocumentEditablePermission implements IPermissionPoint {
|
|
20
|
+
readonly unitId: string;
|
|
21
|
+
readonly type = UnitObject.Document;
|
|
22
|
+
readonly subType = UnitAction.Edit;
|
|
23
|
+
readonly status = PermissionStatus.INIT;
|
|
24
|
+
readonly id: string;
|
|
25
|
+
value: boolean;
|
|
26
|
+
constructor(unitId: string);
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { IPermissionPoint } from '@univerjs/core';
|
|
17
|
+
import { PermissionStatus } from '@univerjs/core';
|
|
18
|
+
import { UnitAction, UnitObject } from '@univerjs/protocol';
|
|
19
|
+
export declare class DocumentExportPermission implements IPermissionPoint {
|
|
20
|
+
readonly unitId: string;
|
|
21
|
+
readonly type = UnitObject.Document;
|
|
22
|
+
readonly subType = UnitAction.Export;
|
|
23
|
+
readonly status = PermissionStatus.INIT;
|
|
24
|
+
readonly id: string;
|
|
25
|
+
value: boolean;
|
|
26
|
+
constructor(unitId: string);
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { IPermissionPoint } from '@univerjs/core';
|
|
17
|
+
import { PermissionStatus } from '@univerjs/core';
|
|
18
|
+
import { UnitAction, UnitObject } from '@univerjs/protocol';
|
|
19
|
+
export declare class DocumentPrintPermission implements IPermissionPoint {
|
|
20
|
+
readonly unitId: string;
|
|
21
|
+
readonly type = UnitObject.Document;
|
|
22
|
+
readonly subType = UnitAction.Print;
|
|
23
|
+
readonly status = PermissionStatus.INIT;
|
|
24
|
+
readonly id: string;
|
|
25
|
+
value: boolean;
|
|
26
|
+
constructor(unitId: string);
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { IPermissionPoint } from '@univerjs/core';
|
|
17
|
+
import { PermissionStatus } from '@univerjs/core';
|
|
18
|
+
import { UnitAction, UnitObject } from '@univerjs/protocol';
|
|
19
|
+
export declare class DocumentEntityEditPermission implements IPermissionPoint {
|
|
20
|
+
readonly unitId: string;
|
|
21
|
+
readonly objectId: string;
|
|
22
|
+
readonly type = UnitObject.DocumentEntity;
|
|
23
|
+
readonly subType = UnitAction.Edit;
|
|
24
|
+
readonly status = PermissionStatus.INIT;
|
|
25
|
+
readonly id: string;
|
|
26
|
+
value: boolean;
|
|
27
|
+
constructor(unitId: string, objectId: string);
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { IPermissionPoint } from '@univerjs/core';
|
|
17
|
+
import { PermissionStatus } from '@univerjs/core';
|
|
18
|
+
import { UnitAction, UnitObject } from '@univerjs/protocol';
|
|
19
|
+
export declare class DocumentParagraphEditPermission implements IPermissionPoint {
|
|
20
|
+
readonly unitId: string;
|
|
21
|
+
readonly objectId: string;
|
|
22
|
+
readonly type = UnitObject.DocumentParagraph;
|
|
23
|
+
readonly subType = UnitAction.Edit;
|
|
24
|
+
readonly status = PermissionStatus.INIT;
|
|
25
|
+
readonly id: string;
|
|
26
|
+
value: boolean;
|
|
27
|
+
constructor(unitId: string, objectId: string);
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { IPermissionPoint } from '@univerjs/core';
|
|
17
|
+
import { PermissionStatus } from '@univerjs/core';
|
|
18
|
+
import { UnitAction, UnitObject } from '@univerjs/protocol';
|
|
19
|
+
export declare class DocumentSectionEditPermission implements IPermissionPoint {
|
|
20
|
+
readonly unitId: string;
|
|
21
|
+
readonly objectId: string;
|
|
22
|
+
readonly type = UnitObject.DocumentSection;
|
|
23
|
+
readonly subType = UnitAction.Edit;
|
|
24
|
+
readonly status = PermissionStatus.INIT;
|
|
25
|
+
readonly id: string;
|
|
26
|
+
value: boolean;
|
|
27
|
+
constructor(unitId: string, objectId: string);
|
|
28
|
+
}
|
package/lib/umd/facade.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/docs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/core/facade`,`@univerjs/docs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsFacade={},e.UniverCore,e.UniverCoreFacade,e.UniverDocs))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});
|
|
2
|
-
`:e).filter(e=>e!==t.DataStreamTreeTokenType.BLOCK_START&&e!==t.DataStreamTreeTokenType.BLOCK_END&&e!==t.DataStreamTreeTokenType.SECTION_BREAK).join(``).replace(/\n$/,``)}var d=class extends n.FBaseInitialable{constructor(e,t,n,r,i){super(i),this._document=e,this._startOffset=t,this._endOffset=n,this._segmentId=r,this._injector=i,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=>!f(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&&l(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 c(this.getRange(),s(e),this._document.getDocumentDataModel(),this._injector)}_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}};function f(e,t){return JSON.stringify(e)===JSON.stringify(t)}function p(e,t){return function(n,r){t(n,r,e)}}function m(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 h=class extends n.FBaseInitialable{constructor(e,t,n=``,r,i){super(r),this._document=e,this._paragraphId=t,this._segmentId=n,this._injector=r,this._commandService=i}getId(){return this._paragraphId}getSegmentId(){return this._segmentId}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(d,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(d,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 c({startOffset:t,endOffset:n,segmentId:this._segmentId},s(e),this._document.getDocumentDataModel(),this._injector)}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),l({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}};h=m([p(4,t.ICommandService)],h);function g(e){return typeof e!=`object`||!e?!1:typeof e.getId==`function`&&typeof e.getSegmentId==`function`&&typeof e.getInfo==`function`&&typeof e.getRange==`function`}function _(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 v=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 y=class{constructor(e,t,n){this._document=e,this._sectionId=t,this._commandService=n}getId(){return this._sectionId}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(),_(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 v}_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]}}};y=m([p(2,t.ICommandService)],y);function b(e){"@babel/helpers - typeof";return b=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},b(e)}function x(e,t){if(b(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(b(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function S(e){var t=x(e,`string`);return b(t)==`symbol`?t:t+``}function C(e,t,n){return(t=S(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let w=class extends n.FBaseInitialable{constructor(e,t,n,r,i){super(t),this._documentDataModel=e,this._injector=t,this._univerInstanceService=n,this._resourceLoaderService=r,this._commandService=i,C(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}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 c({startOffset:e,endOffset:e,segmentId:n},s(t),this._documentDataModel,this._injector)}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(d,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(y,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 v;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(y,this,o):null}insertColumnBreak(e){if(this._documentDataModel.getSnapshot().documentStyle.documentFlavor!==t.DocumentFlavor.TRADITIONAL)throw new v;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)),l=s[0].paragraphId;return c({startOffset:e,endOffset:e,segmentId:i},{dataStream:t.DataStreamTreeTokenType.PARAGRAPH,paragraphs:s},this._documentDataModel,this._injector)?this.getParagraph(l,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(!c({startOffset:r,endOffset:r,segmentId:n},s(`${t}\r`),this._documentDataModel,this._injector))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:c(t,{dataStream:``},this._documentDataModel,this._injector)}_createFDocumentParagraph(e,t=``){return this._injector.createInstance(h,this,e,t,this._injector)}_normalizeDeleteRange(e){let t=this.getBody(e.segmentId),n=t.dataStream.endsWith(`\r
|
|
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??``}}};
|
|
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
|
|
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});
|