@univerjs/core 1.0.0-alpha.2 → 1.0.0-alpha.3

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.
Files changed (51) hide show
  1. package/lib/cjs/facade.js +85 -27
  2. package/lib/cjs/index.js +9898 -8248
  3. package/lib/es/facade.js +86 -28
  4. package/lib/es/index.js +9864 -8253
  5. package/lib/facade.js +86 -28
  6. package/lib/index.js +9864 -8253
  7. package/lib/types/bases/base-data-model.d.ts +4 -0
  8. package/lib/types/bases/empty-snapshot.d.ts +2 -1
  9. package/lib/types/bases/index.d.ts +3 -2
  10. package/lib/types/bases/typedef.d.ts +80 -67
  11. package/lib/types/common/regexp/charset.d.ts +63 -0
  12. package/lib/types/common/regexp/escape.d.ts +30 -0
  13. package/lib/types/common/regexp/factory.d.ts +16 -0
  14. package/lib/types/common/regexp/index.d.ts +37 -0
  15. package/lib/types/common/regexp/or.d.ts +57 -0
  16. package/lib/types/docs/data-model/empty-snapshot.d.ts +2 -1
  17. package/lib/types/docs/data-model/index.d.ts +20 -0
  18. package/lib/types/docs/data-model/paragraph-style.d.ts +22 -0
  19. package/lib/types/docs/data-model/preset-list-type.d.ts +19 -6
  20. package/lib/types/docs/data-model/rich-text-builder.d.ts +269 -1
  21. package/lib/types/docs/data-model/text-x/action-types.d.ts +1 -0
  22. package/lib/types/docs/data-model/text-x/apply-utils/common.d.ts +4 -1
  23. package/lib/types/docs/data-model/text-x/build-utils/data-stream-change.d.ts +28 -0
  24. package/lib/types/docs/data-model/text-x/build-utils/index.d.ts +5 -0
  25. package/lib/types/docs/data-model/text-x/build-utils/paragraph.d.ts +4 -1
  26. package/lib/types/docs/data-model/text-x/build-utils/range-interval.d.ts +74 -0
  27. package/lib/types/docs/data-model/text-x/structure-validator.d.ts +31 -0
  28. package/lib/types/docs/data-model/text-x/utils.d.ts +12 -4
  29. package/lib/types/docs/index.d.ts +5 -0
  30. package/lib/types/docs/section-break-id.d.ts +19 -0
  31. package/lib/types/docs/section-header-footer.d.ts +32 -0
  32. package/lib/types/facade/f-enum.d.ts +40 -1
  33. package/lib/types/facade/f-hooks.d.ts +8 -0
  34. package/lib/types/facade/f-univer.d.ts +28 -27
  35. package/lib/types/index.d.ts +3 -32
  36. package/lib/types/services/authz-io/authz-io-local.service.d.ts +1 -1
  37. package/lib/types/services/instance/instance.service.d.ts +26 -0
  38. package/lib/types/services/resource-manager/type.d.ts +1 -1
  39. package/lib/types/shared/date-kit.d.ts +1 -0
  40. package/lib/types/shared/tools.d.ts +0 -11
  41. package/lib/types/sheets/index.d.ts +26 -0
  42. package/lib/types/sheets/typedef.d.ts +2 -0
  43. package/lib/types/types/const/const.d.ts +0 -1
  44. package/lib/types/types/enum/locale-type.d.ts +9 -0
  45. package/lib/types/types/interfaces/i-document-data-interceptor.d.ts +1 -0
  46. package/lib/types/types/interfaces/i-document-data.d.ts +35 -2
  47. package/lib/types/types/interfaces/i-drawing.d.ts +25 -1
  48. package/lib/types/types/interfaces/i-style-data.d.ts +1 -5
  49. package/lib/umd/facade.js +1 -1
  50. package/lib/umd/index.js +19 -11
  51. package/package.json +5 -5
@@ -14,11 +14,142 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { Nullable } from '../../shared';
17
- import type { BaselineOffset, HorizontalAlign, TextDecoration, TextDirection } from '../../types/enum';
17
+ import type { BaselineOffset, HorizontalAlign, TextDecoration, TextDirection, VerticalAlign } from '../../types/enum';
18
18
  import type { IBorderData, IColorStyle, IDocumentBody, IDocumentData, INumberUnit, IParagraphBorder, IParagraphStyle, IShading, ITabStop, ITextDecoration, ITextStyle, NamedStyleType, SpacingRule } from '../../types/interfaces';
19
19
  import { BooleanNumber } from '../../types/enum';
20
+ import { PresetListType } from './preset-list-type';
20
21
  export declare function normalizeBody(body: IDocumentBody): IDocumentBody;
21
22
  export declare function normalizeData(data: IDocumentData): IDocumentData;
23
+ /**
24
+ * Agent-friendly text style aliases accepted by `RichTextBuilder.span()`.
25
+ *
26
+ * The readable aliases can be combined in one object and apply only to the appended span. Native `ITextStyle` fields
27
+ * remain available for advanced document integrations.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const text = univerAPI.newRichText()
32
+ * .text('Status: ')
33
+ * .span('Blocked', {
34
+ * bold: true,
35
+ * italic: true,
36
+ * color: '#dc2626',
37
+ * background: '#fee2e2',
38
+ * });
39
+ * ```
40
+ */
41
+ export interface IRichTextSpanStyle extends ITextStyle {
42
+ /**
43
+ * Agent-friendly alias for `bl`.
44
+ */
45
+ bold?: boolean;
46
+ /**
47
+ * Agent-friendly alias for `it`.
48
+ */
49
+ italic?: boolean;
50
+ /**
51
+ * Agent-friendly alias for `ff`.
52
+ */
53
+ fontFamily?: string;
54
+ /**
55
+ * Agent-friendly alias for `fs`.
56
+ */
57
+ fontSize?: number;
58
+ /**
59
+ * Agent-friendly alias for `cl`. A string is treated as an RGB color.
60
+ */
61
+ color?: string | IColorStyle | null;
62
+ /**
63
+ * Agent-friendly alias for `bg`. A string is treated as an RGB color.
64
+ */
65
+ background?: string | IColorStyle | null;
66
+ }
67
+ /**
68
+ * Agent-friendly paragraph options accepted by `RichTextBuilder.paragraph()`.
69
+ *
70
+ * Numeric lengths use document points. Pass an `INumberUnit` when another supported unit is required. `lineHeight`
71
+ * behaves as a multiplier with `SpacingRule.AUTO`, and as an absolute document size with `AT_LEAST` or `EXACT`.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const text = univerAPI.newRichText()
76
+ * .paragraph({
77
+ * align: univerAPI.Enum.HorizontalAlign.LEFT,
78
+ * lineHeight: 1.4,
79
+ * lineHeightRule: univerAPI.Enum.SpacingRule.AUTO,
80
+ * firstLineIndent: 12,
81
+ * spaceAfter: 6,
82
+ * })
83
+ * .text('Agent-friendly paragraph');
84
+ * ```
85
+ */
86
+ export interface IRichTextParagraphStyle {
87
+ /** Horizontal paragraph alignment. Use `univerAPI.Enum.HorizontalAlign`. */
88
+ align?: HorizontalAlign;
89
+ /** Line-height multiplier or absolute size, depending on `lineHeightRule`. */
90
+ lineHeight?: number;
91
+ /** Line-height interpretation. Defaults to `SpacingRule.AUTO`. */
92
+ lineHeightRule?: SpacingRule;
93
+ /** First-line indent. A number is interpreted as document points. */
94
+ firstLineIndent?: number | INumberUnit;
95
+ /** Hanging indent. A number is interpreted as document points. */
96
+ hangingIndent?: number | INumberUnit;
97
+ /** Leading-side indent. A number is interpreted as document points. */
98
+ indentStart?: number | INumberUnit;
99
+ /** Trailing-side indent. A number is interpreted as document points. */
100
+ indentEnd?: number | INumberUnit;
101
+ /** Space before the paragraph. A number is interpreted as document points. */
102
+ spaceBefore?: number | INumberUnit;
103
+ /** Space after the paragraph. A number is interpreted as document points. */
104
+ spaceAfter?: number | INumberUnit;
105
+ /** Text direction. Use `univerAPI.Enum.TextDirection`. */
106
+ direction?: TextDirection;
107
+ /** Whether lines may wrap at character boundaries. */
108
+ wordWrap?: boolean;
109
+ /** Keeps all paragraph lines together when pagination applies. */
110
+ keepLines?: boolean;
111
+ /** Keeps this paragraph with the following paragraph when pagination applies. */
112
+ keepNext?: boolean;
113
+ }
114
+ /**
115
+ * Portable text-container alignment accepted by `RichTextBuilder.align()`.
116
+ *
117
+ * Unlike `paragraph({ align })`, which styles one paragraph, this alignment is a document-level presentation hint that
118
+ * can be consumed consistently by shapes, table cells, and other rich-text hosts.
119
+ */
120
+ export interface IRichTextAlignment {
121
+ /** Horizontal alignment for the rich-text block. */
122
+ horizontal?: HorizontalAlign;
123
+ /** Vertical alignment inside the host text container. */
124
+ vertical?: VerticalAlign;
125
+ }
126
+ /**
127
+ * Agent-friendly options for one paragraph list item.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * const text = univerAPI.newRichText()
132
+ * .listItem('Plan', {
133
+ * type: univerAPI.Enum.PresetListType.ORDER_LIST,
134
+ * listId: 'agent.release-steps',
135
+ * })
136
+ * .listItem('Build', {
137
+ * type: univerAPI.Enum.PresetListType.ORDER_LIST,
138
+ * listId: 'agent.release-steps',
139
+ * level: 1,
140
+ * });
141
+ * ```
142
+ */
143
+ export interface IRichTextListItemOptions {
144
+ /** Preset ordered, unordered, or checklist style. Defaults to `PresetListType.BULLET_LIST`. */
145
+ type?: PresetListType;
146
+ /** Stable list identity. Consecutive compatible items reuse the previous id when omitted. */
147
+ listId?: string;
148
+ /** Zero-based nesting level. Defaults to `0`. */
149
+ level?: number;
150
+ /** Optional paragraph layout for this item. */
151
+ paragraphStyle?: ParagraphStyleBuilder | IRichTextParagraphStyle;
152
+ }
22
153
  /**
23
154
  * Represents a read-only font style value object.
24
155
  * This class provides access to font style properties without modification capabilities.
@@ -1230,6 +1361,143 @@ export declare class RichTextBuilder extends RichTextValue {
1230
1361
  static create(data?: IDocumentData): RichTextBuilder;
1231
1362
  private _doc;
1232
1363
  constructor(data: IDocumentData);
1364
+ /**
1365
+ * Appends plain text to the rich text.
1366
+ *
1367
+ * This is an agent-friendly alias of `insertText(text)`. Use it when building rich text from left to right for
1368
+ * shapes, comments, table cells, and document fragments.
1369
+ *
1370
+ * @param text Text to append.
1371
+ * @returns The current builder for chaining.
1372
+ * @example
1373
+ * ```ts
1374
+ * const richText = univerAPI.newRichText()
1375
+ * .text('Priority: ')
1376
+ * .bold('High')
1377
+ * .text(' ')
1378
+ * .code('P0');
1379
+ * ```
1380
+ */
1381
+ text(text: string): RichTextBuilder;
1382
+ /**
1383
+ * Aligns the rich-text block inside its host container.
1384
+ *
1385
+ * This is the preferred facade-friendly API for alignment shared by shapes and table cells. It keeps callers away
1386
+ * from `IDocumentData.documentStyle.renderConfig`. Use `paragraph({ align })` when individual paragraphs need
1387
+ * different horizontal alignment.
1388
+ *
1389
+ * @param alignment Horizontal and/or vertical container alignment.
1390
+ * @returns The current builder for chaining.
1391
+ * @example
1392
+ * ```ts
1393
+ * const text = univerAPI.newRichText()
1394
+ * .align({
1395
+ * horizontal: univerAPI.Enum.HorizontalAlign.CENTER,
1396
+ * vertical: univerAPI.Enum.VerticalAlign.MIDDLE,
1397
+ * })
1398
+ * .text('Centered text');
1399
+ * ```
1400
+ */
1401
+ align(alignment: IRichTextAlignment): RichTextBuilder;
1402
+ /**
1403
+ * Appends one text span with explicit style.
1404
+ *
1405
+ * Prefer this method when combining multiple styles, because the style object is local to the inserted text and does
1406
+ * not leak into following calls.
1407
+ *
1408
+ * @param text Text to append.
1409
+ * @param style Text style for this span. Agent-friendly aliases such as `bold`, `italic`, `fontFamily`, `fontSize`,
1410
+ * `color`, and `background` are supported alongside native document text style fields.
1411
+ * @returns The current builder for chaining.
1412
+ * @example
1413
+ * ```ts
1414
+ * const richText = univerAPI.newRichText()
1415
+ * .text('Status: ')
1416
+ * .span('Important', { bold: true, italic: true, color: '#d92d20' });
1417
+ * ```
1418
+ */
1419
+ span(text: string, style: IRichTextSpanStyle): RichTextBuilder;
1420
+ /**
1421
+ * Appends bold text.
1422
+ *
1423
+ * @param text Text to append.
1424
+ * @returns The current builder for chaining.
1425
+ * @example
1426
+ * ```ts
1427
+ * const richText = univerAPI.newRichText().text('This is ').bold('important');
1428
+ * ```
1429
+ */
1430
+ bold(text: string): RichTextBuilder;
1431
+ /**
1432
+ * Appends italic text.
1433
+ *
1434
+ * @param text Text to append.
1435
+ * @returns The current builder for chaining.
1436
+ * @example
1437
+ * ```ts
1438
+ * const richText = univerAPI.newRichText().text('Use ').italic('judgment');
1439
+ * ```
1440
+ */
1441
+ italic(text: string): RichTextBuilder;
1442
+ /**
1443
+ * Appends inline code-style text.
1444
+ *
1445
+ * This is intentionally an inline text style, not a block range. Use `paragraph().code('...')` when the code should
1446
+ * occupy its own line.
1447
+ *
1448
+ * @param text Text to append as inline code.
1449
+ * @returns The current builder for chaining.
1450
+ * @example
1451
+ * ```ts
1452
+ * const richText = univerAPI.newRichText()
1453
+ * .text('Run ')
1454
+ * .code('pnpm test')
1455
+ * .text(' before submitting.');
1456
+ * ```
1457
+ */
1458
+ code(text: string): RichTextBuilder;
1459
+ /**
1460
+ * Appends one ordered, unordered, or checklist paragraph.
1461
+ *
1462
+ * Consecutive items with the same `type` automatically share a generated list id. Supply a semantic `listId` when
1463
+ * an agent needs stable list identity across regeneration.
1464
+ *
1465
+ * @param text Plain item text.
1466
+ * @param options List type, stable identity, nesting, and optional paragraph layout.
1467
+ * @returns The current builder for chaining.
1468
+ * @example
1469
+ * ```ts
1470
+ * const richText = univerAPI.newRichText()
1471
+ * .listItem('Analyze requirements', {
1472
+ * type: univerAPI.Enum.PresetListType.BULLET_LIST,
1473
+ * listId: 'agent.tasks',
1474
+ * })
1475
+ * .listItem('Implement API', {
1476
+ * type: univerAPI.Enum.PresetListType.BULLET_LIST,
1477
+ * listId: 'agent.tasks',
1478
+ * level: 1,
1479
+ * });
1480
+ * ```
1481
+ */
1482
+ listItem(text: string, options?: IRichTextListItemOptions): RichTextBuilder;
1483
+ /**
1484
+ * Starts a new paragraph before the next appended content.
1485
+ *
1486
+ * Calling `paragraph()` on an empty builder is a no-op, so agents can naturally start chains with
1487
+ * `newRichText().paragraph().text('Title')` without creating a leading blank paragraph.
1488
+ *
1489
+ * @param paragraphStyle Optional agent-friendly paragraph options or an advanced paragraph style builder.
1490
+ * @returns The current builder for chaining.
1491
+ * @example
1492
+ * ```ts
1493
+ * const richText = univerAPI.newRichText()
1494
+ * .paragraph({ lineHeight: 1.4, firstLineIndent: 16, spaceAfter: 8 })
1495
+ * .text('First paragraph')
1496
+ * .paragraph({ align: univerAPI.Enum.HorizontalAlign.CENTER })
1497
+ * .span('Second paragraph', { bold: true, italic: true });
1498
+ * ```
1499
+ */
1500
+ paragraph(paragraphStyle?: ParagraphStyleBuilder | IRichTextParagraphStyle): RichTextBuilder;
1233
1501
  /**
1234
1502
  * Inserts text into the rich text builder at the specified start position
1235
1503
  * @param start The start position of the text to insert
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import type { UpdateDocsAttributeType } from '../../../shared/command-enum';
17
17
  import type { IDocumentBody } from '../../../types/interfaces/i-document-data';
18
+ export declare const PRESERVE_INSERTED_PARAGRAPH_IDS = "__textXPreserveParagraphIds";
18
19
  export declare enum TextXActionType {
19
20
  RETAIN = "r",
20
21
  INSERT = "i",
@@ -32,14 +32,17 @@ export declare function insertTextRuns(body: IDocumentBody, insertBody: IDocumen
32
32
  * @param textLength The length of the inserted content text.
33
33
  * @param currentIndex Determining the index where the content will be inserted into the current content.
34
34
  */
35
- export declare function insertParagraphs(body: IDocumentBody, insertBody: IDocumentBody, textLength: number, currentIndex: number, preserveMissingParagraphIds?: boolean): void;
35
+ export declare function insertParagraphs(body: IDocumentBody, insertBody: IDocumentBody, textLength: number, currentIndex: number, preserveMissingParagraphIds?: boolean, originalDataStream?: string): void;
36
36
  export declare function normalizeInsertedParagraphIdsForDocument(paragraphs: IParagraph[] | undefined, insertParagraphs: IParagraph[] | undefined, currentIndex: number, options: {
37
37
  freshenSplitParagraph: boolean;
38
38
  preserveExplicitSplitParagraphIds?: boolean;
39
+ preserveExplicitParagraphIds?: boolean;
39
40
  preserveMissingParagraphIds?: boolean;
40
41
  reservedParagraphIds?: Set<string>;
42
+ dataStream?: string;
41
43
  }): void;
42
44
  export declare function insertSectionBreaks(body: IDocumentBody, insertBody: IDocumentBody, textLength: number, currentIndex: number): void;
45
+ export declare function normalizeInsertedSectionIdsForDocument(sectionBreaks: ISectionBreak[] | undefined, insertSectionBreaks: ISectionBreak[] | undefined, reservedSectionIds?: Set<string>): void;
43
46
  export declare function insertCustomBlocks(body: IDocumentBody, insertBody: IDocumentBody, textLength: number, currentIndex: number): void;
44
47
  export declare function insertTables(body: IDocumentBody, insertBody: IDocumentBody, textLength: number, currentIndex: number): void;
45
48
  export declare function insertColumnGroups(body: IDocumentBody, insertBody: IDocumentBody, textLength: number, currentIndex: number): void;
@@ -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 { IDocumentBody } from '../../../../types/interfaces';
17
+ export interface IDataStreamChange {
18
+ start: number;
19
+ deleteLength: number;
20
+ insertLength: number;
21
+ }
22
+ /**
23
+ * Finds one contiguous dataStream change. Pure structural insertions are
24
+ * anchored by their new stable ids before falling back to string comparison.
25
+ * This prevents an adjacent identical sentinel from being mistaken for an
26
+ * unchanged prefix and keeps the inserted structure metadata in the TextX body.
27
+ */
28
+ export declare function getSingleDataStreamChange(previousBody: IDocumentBody | undefined, nextBody: IDocumentBody | undefined): IDataStreamChange | null;
@@ -67,4 +67,9 @@ export declare class BuildTextUtils {
67
67
  add: (param: import("./drawings").IAddDrawingParam) => false | import("ot-json1").JSONOp;
68
68
  };
69
69
  }
70
+ export { getSingleDataStreamChange } from './data-stream-change';
71
+ export type { IDataStreamChange } from './data-stream-change';
72
+ export { getParagraphContentStartOffset, getParagraphContentStartOffsets, getParagraphFollowingBlockOffset } from './paragraph';
73
+ export { containsInteriorInsertionOffset, containsStreamIndex, getBlockRangeInterval, getColumnGroupRangeInterval, getCustomBlockInterval, getCustomRangeInterval, getExclusiveRangeInterval, getInclusiveRangeInterval, getTableCellTokenInterval, getTableRangeInterval, getTableRowTokenInterval, intersectsOperationalIntervals, shiftExclusiveRangeOnDelete, shiftExclusiveRangeOnInsert, shiftInclusiveRangeOnDelete, shiftInclusiveRangeOnInsert, } from './range-interval';
74
+ export type { IDocOperationalInterval } from './range-interval';
70
75
  export type { IAddCustomRangeTextXParam, IDeleteCustomRangeParam, IReplaceSelectionTextXParams } from './text-x-utils';
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { ITextRange } from '../../../../sheets/typedef';
17
- import type { ICustomTable, IParagraph, IParagraphStyle, ITextStyle } from '../../../../types/interfaces';
17
+ import type { ICustomTable, IDocumentBody, IParagraph, IParagraphStyle, ITextStyle } from '../../../../types/interfaces';
18
18
  import type { DocumentDataModel } from '../../document-data-model';
19
19
  import { TextX } from '../text-x';
20
20
  export interface ISwitchParagraphBulletParams {
@@ -45,6 +45,9 @@ export interface IChangeParagraphBulletNestLevelParams {
45
45
  type: 1 | -1;
46
46
  }
47
47
  export declare function hasParagraphInTable(paragraph: IParagraph, tables: ICustomTable[]): boolean;
48
+ export declare function getParagraphContentStartOffset(body: Pick<IDocumentBody, 'dataStream' | 'paragraphs'>, paragraph: Pick<IParagraph, 'startIndex'>): number;
49
+ export declare function getParagraphContentStartOffsets(body: Pick<IDocumentBody, 'dataStream' | 'paragraphs'>): Map<number, number>;
50
+ export declare function getParagraphFollowingBlockOffset(body: Pick<IDocumentBody, 'blockRanges'>, paragraph: Pick<IParagraph, 'startIndex'>): number;
48
51
  export declare const changeParagraphBulletNestLevel: (params: IChangeParagraphBulletNestLevelParams) => TextX;
49
52
  export interface ISetParagraphStyleParams {
50
53
  textRanges: readonly ITextRange[];
@@ -0,0 +1,74 @@
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 { ICustomBlock, ICustomColumnGroup, ICustomRange, ICustomTable, IDocumentBlockRange } from '../../../../types/interfaces/i-document-data';
17
+ /**
18
+ * A canonical half-open interval used by document editing algorithms.
19
+ * `startOffset` is included and `endOffset` is excluded.
20
+ */
21
+ export interface IDocOperationalInterval {
22
+ startOffset: number;
23
+ endOffset: number;
24
+ }
25
+ type IInclusiveDocumentRange = Pick<IDocumentBlockRange, 'startIndex' | 'endIndex'>;
26
+ type IExclusiveDocumentRange = Pick<ICustomTable, 'startIndex' | 'endIndex'>;
27
+ /** Converts persisted inclusive indexes `[startIndex, endIndex]` to `[startOffset, endOffset)`. */
28
+ export declare function getInclusiveRangeInterval(range: IInclusiveDocumentRange): IDocOperationalInterval;
29
+ /** Converts persisted half-open indexes `[startIndex, endIndex)` to the operational representation. */
30
+ export declare function getExclusiveRangeInterval(range: IExclusiveDocumentRange): IDocOperationalInterval;
31
+ /** A table stores an exclusive end immediately after `TABLE_END`. */
32
+ export declare function getTableRangeInterval(table: Pick<ICustomTable, 'startIndex' | 'endIndex'>): IDocOperationalInterval;
33
+ /** A document block stores an inclusive end that points at `BLOCK_END`. */
34
+ export declare function getBlockRangeInterval(blockRange: Pick<IDocumentBlockRange, 'startIndex' | 'endIndex'>): IDocOperationalInterval;
35
+ /** A column group stores an inclusive end that points at `COLUMN_GROUP_END`. */
36
+ export declare function getColumnGroupRangeInterval(columnGroup: Pick<ICustomColumnGroup, 'startIndex' | 'endIndex'>): IDocOperationalInterval;
37
+ /** A custom range stores inclusive character indexes. */
38
+ export declare function getCustomRangeInterval(customRange: Pick<ICustomRange, 'startIndex' | 'endIndex'>): IDocOperationalInterval;
39
+ /** A custom block occupies exactly one `CUSTOM_BLOCK` sentinel. */
40
+ export declare function getCustomBlockInterval(customBlock: Pick<ICustomBlock, 'startIndex'>): IDocOperationalInterval;
41
+ /** Returns the half-open token interval for a row that starts at `startOffset`. */
42
+ export declare function getTableRowTokenInterval(dataStream: string, startOffset: number): IDocOperationalInterval | null;
43
+ /** Returns the half-open token interval for a cell that starts at `startOffset`. */
44
+ export declare function getTableCellTokenInterval(dataStream: string, startOffset: number): IDocOperationalInterval | null;
45
+ /** Tests whether a stream index belongs to a half-open operational interval. */
46
+ export declare function containsStreamIndex(interval: IDocOperationalInterval, index: number): boolean;
47
+ /**
48
+ * Tests whether an insertion point is strictly inside a container.
49
+ * Boundary insertion affinity must be decided by the caller.
50
+ */
51
+ export declare function containsInteriorInsertionOffset(interval: IDocOperationalInterval, offset: number): boolean;
52
+ /** Tests whether two half-open operational intervals overlap. */
53
+ export declare function intersectsOperationalIntervals(left: IDocOperationalInterval, right: IDocOperationalInterval): boolean;
54
+ /** Shifts or expands an inclusive persisted range for an insertion at `offset`. */
55
+ export declare function shiftInclusiveRangeOnInsert<T extends {
56
+ startIndex: number;
57
+ endIndex: number;
58
+ }>(range: T, offset: number, length: number): T;
59
+ /** Shifts or expands a half-open persisted range for an insertion at `offset`. */
60
+ export declare function shiftExclusiveRangeOnInsert<T extends {
61
+ startIndex: number;
62
+ endIndex: number;
63
+ }>(range: T, offset: number, length: number): T;
64
+ /** Transforms an inclusive persisted range after deleting `[offset, offset + length)`. */
65
+ export declare function shiftInclusiveRangeOnDelete<T extends {
66
+ startIndex: number;
67
+ endIndex: number;
68
+ }>(range: T, offset: number, length: number): T | null;
69
+ /** Transforms a half-open persisted range after deleting `[offset, offset + length)`. */
70
+ export declare function shiftExclusiveRangeOnDelete<T extends {
71
+ startIndex: number;
72
+ endIndex: number;
73
+ }>(range: T, offset: number, length: number): T | null;
74
+ export {};
@@ -0,0 +1,31 @@
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 { IDocumentBody, IDocumentData } from '../../../types/interfaces/i-document-data';
17
+ export type DocStructureIssueCode = 'missing-root-paragraph' | 'missing-root-section-break' | 'paragraph-token-mismatch' | 'duplicate-paragraph-metadata' | 'section-break-token-mismatch' | 'duplicate-section-break-metadata' | 'missing-section-id' | 'duplicate-section-id' | 'table-start-token-mismatch' | 'table-end-token-mismatch' | 'missing-table-metadata' | 'overlapping-table' | 'block-range-token-mismatch' | 'missing-block-range-metadata' | 'overlapping-block-range' | 'unbalanced-block' | 'column-group-range-token-mismatch' | 'missing-column-group-metadata' | 'overlapping-column-group' | 'column-group-column-count-mismatch' | 'custom-block-token-mismatch' | 'missing-custom-block-metadata' | 'duplicate-custom-block-metadata' | 'empty-column' | 'empty-table-cell' | 'unbalanced-column-group' | 'unbalanced-table';
18
+ export interface IDocStructureIssue {
19
+ code: DocStructureIssueCode;
20
+ segmentType: 'body' | 'header' | 'footer';
21
+ segmentId?: string;
22
+ index?: number;
23
+ message: string;
24
+ }
25
+ interface IValidationContext {
26
+ segmentType: IDocStructureIssue['segmentType'];
27
+ segmentId?: string;
28
+ }
29
+ export declare function validateDocBodyStructure(body: IDocumentBody, context?: IValidationContext): IDocStructureIssue[];
30
+ export declare function validateDocumentStructure(snapshot: Pick<IDocumentData, 'body' | 'headers' | 'footers'>): IDocStructureIssue[];
31
+ export {};
@@ -21,14 +21,19 @@ export declare enum SliceBodyType {
21
21
  copy = 0,
22
22
  cut = 1
23
23
  }
24
+ export declare enum SliceStructuralRangeMode {
25
+ intersect = 0,
26
+ contained = 1,
27
+ ending = 2
28
+ }
24
29
  export declare function getTextRunSlice(body: IDocumentBody, startOffset: number, endOffset: number, returnEmptyTextRuns?: boolean): ITextRun[] | undefined;
25
- export declare function getTableSlice(body: IDocumentBody, startOffset: number, endOffset: number): {
30
+ export declare function getTableSlice(body: IDocumentBody, startOffset: number, endOffset: number, mode?: SliceStructuralRangeMode): {
26
31
  startIndex: number;
27
32
  endIndex: number;
28
33
  tableId: string;
29
34
  }[];
30
- export declare function getBlockRangeSlice(body: IDocumentBody, startOffset: number, endOffset: number): IDocumentBlockRange[];
31
- export declare function getColumnGroupSlice(body: IDocumentBody, startOffset: number, endOffset: number): ICustomColumnGroup[];
35
+ export declare function getBlockRangeSlice(body: IDocumentBody, startOffset: number, endOffset: number, mode?: SliceStructuralRangeMode): IDocumentBlockRange[];
36
+ export declare function getColumnGroupSlice(body: IDocumentBody, startOffset: number, endOffset: number, mode?: SliceStructuralRangeMode): ICustomColumnGroup[];
32
37
  export declare function getParagraphsSlice(body: IDocumentBody, startOffset: number, endOffset: number, type?: SliceBodyType): {
33
38
  startIndex: number;
34
39
  paragraphId: string;
@@ -37,6 +42,7 @@ export declare function getParagraphsSlice(body: IDocumentBody, startOffset: num
37
42
  }[] | undefined;
38
43
  export declare function getSectionBreakSlice(body: IDocumentBody, startOffset: number, endOffset: number): {
39
44
  startIndex: number;
45
+ sectionId: string;
40
46
  pageNumberStart?: number;
41
47
  pageSize?: import("../../..").ISize;
42
48
  pageOrient?: import("../../..").PageOrientType;
@@ -71,7 +77,9 @@ export declare function getCustomBlockSlice(body: IDocumentBody, startOffset: nu
71
77
  blockType?: import("../../..").BlockType;
72
78
  blockId: string;
73
79
  }[] | undefined;
74
- export declare function getBodySlice(body: IDocumentBody, startOffset: number, endOffset: number, returnEmptyArray?: boolean, type?: SliceBodyType): IDocumentBody;
80
+ export declare function getBodySlice(body: IDocumentBody, startOffset: number, endOffset: number, returnEmptyArray?: boolean, type?: SliceBodyType, structuralRangeMode?: SliceStructuralRangeMode): IDocumentBody;
81
+ export declare function getBodySliceForTextXAction(body: IDocumentBody, startOffset: number, endOffset: number, returnEmptyArray?: boolean, type?: SliceBodyType): IDocumentBody;
82
+ export declare function getBodySliceForSplitTextXAction(body: IDocumentBody, startOffset: number, endOffset: number, returnEmptyArray?: boolean, type?: SliceBodyType): IDocumentBody;
75
83
  export declare function normalizeBody(body: IDocumentBody): IDocumentBody;
76
84
  export declare function getCustomRangeSlice(body: IDocumentBody, startOffset: number, endOffset: number): {
77
85
  customRanges?: undefined;
@@ -14,3 +14,8 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export * from './data-model';
17
+ export { cloneBodyWithFreshParagraphIds, cloneParagraphWithId, createParagraphId, PARAGRAPH_ID_PREFIX, } from './paragraph-id';
18
+ export type { IParagraphIdScope } from './paragraph-id';
19
+ export { cloneSectionBreakWithId, createSectionId, SECTION_ID_PREFIX, } from './section-break-id';
20
+ export { getSectionHeaderFooterReferenceKey, resolveSectionHeaderFooterReference, resolveSectionHeaderFooterReferences, } from './section-header-footer';
21
+ export type { IResolvedSectionHeaderFooterReference, SectionHeaderFooterKind, SectionHeaderFooterReferenceKey, SectionHeaderFooterVariant, } from './section-header-footer';
@@ -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 type { ISectionBreak } from '../types/interfaces/i-document-data';
17
+ export declare const SECTION_ID_PREFIX = "section_";
18
+ export declare function createSectionId(existingIds: Set<string>): string;
19
+ export declare function cloneSectionBreakWithId(sectionBreak: ISectionBreak, existingIds: Set<string>, preserveId?: boolean): ISectionBreak;
@@ -0,0 +1,32 @@
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 { IDocumentStyle, ISectionBreak } from '../types/interfaces/i-document-data';
17
+ export type SectionHeaderFooterKind = 'header' | 'footer';
18
+ export type SectionHeaderFooterVariant = 'default' | 'first' | 'even';
19
+ export type SectionHeaderFooterReferenceKey = 'defaultHeaderId' | 'defaultFooterId' | 'firstPageHeaderId' | 'firstPageFooterId' | 'evenPageHeaderId' | 'evenPageFooterId';
20
+ export interface IResolvedSectionHeaderFooterReference {
21
+ segmentId?: string;
22
+ linkedToPrevious: boolean;
23
+ sourceSectionId?: string;
24
+ }
25
+ export declare function getSectionHeaderFooterReferenceKey(kind: SectionHeaderFooterKind, variant: SectionHeaderFooterVariant): SectionHeaderFooterReferenceKey;
26
+ /**
27
+ * Resolves one OOXML header/footer reference for a document section.
28
+ * A missing reference after the first section inherits the previous section.
29
+ * Document-level references are defaults for the first section only.
30
+ */
31
+ export declare function resolveSectionHeaderFooterReference(documentStyle: IDocumentStyle, sections: Readonly<ISectionBreak[]>, sectionIndex: number, key: SectionHeaderFooterReferenceKey): IResolvedSectionHeaderFooterReference;
32
+ export declare function resolveSectionHeaderFooterReferences(documentStyle: IDocumentStyle, sections: Readonly<ISectionBreak[]>, sectionIndex: number): Pick<ISectionBreak, SectionHeaderFooterReferenceKey>;
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { AbsoluteRefType, AutoFillSeries, BaselineOffset, BooleanNumber, BorderStyleTypes, BorderType, ColorType, CommandType, CommonHideTypes, CopyPasteType, DataValidationErrorStyle, DataValidationOperator, DataValidationRenderMode, DataValidationStatus, DataValidationType, DeleteDirection, DeveloperMetadataVisibility, Dimension, Direction, HorizontalAlign, InterpolationPointType, LifecycleStages, LocaleType, MentionType, ProtectionType, RelativeDate, SheetTypes, TextDecoration, TextDirection, ThemeColorType, UniverInstanceType, VerticalAlign, WrapStrategy } from '@univerjs/core';
16
+ import { AbsoluteRefType, AutoFillSeries, BaselineOffset, BooleanNumber, BorderStyleTypes, BorderType, ColorType, CommandType, CommonHideTypes, CopyPasteType, DataValidationErrorStyle, DataValidationOperator, DataValidationRenderMode, DataValidationStatus, DataValidationType, DeleteDirection, DeveloperMetadataVisibility, Dimension, Direction, HorizontalAlign, ImageSourceType, InterpolationPointType, LifecycleStages, LocaleType, MentionType, NumberUnitType, PresetListType, ProtectionType, RelativeDate, SheetTypes, SpacingRule, TextDecoration, TextDirection, ThemeColorType, UniverInstanceType, VerticalAlign, WrapStrategy } from '@univerjs/core';
17
17
  /**
18
18
  * @hideconstructor
19
19
  */
@@ -136,6 +136,36 @@ export declare class FEnum {
136
136
  * ```
137
137
  */
138
138
  get HorizontalAlign(): typeof HorizontalAlign;
139
+ /**
140
+ * Paragraph line-height interpretation modes
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * console.log(univerAPI.Enum.SpacingRule.EXACT);
145
+ * ```
146
+ */
147
+ get SpacingRule(): typeof SpacingRule;
148
+ /**
149
+ * Units accepted by document lengths such as paragraph indentation and spacing
150
+ *
151
+ * Agent-facing rich-text helpers accept plain numbers as document points, so this enum is only needed when an
152
+ * explicit alternative unit is required.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * console.log(univerAPI.Enum.NumberUnitType.POINT);
157
+ * ```
158
+ */
159
+ get NumberUnitType(): typeof NumberUnitType;
160
+ /**
161
+ * Preset ordered, unordered, and checklist styles used by rich-text list items
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * console.log(univerAPI.Enum.PresetListType.BULLET_LIST);
166
+ * ```
167
+ */
168
+ get PresetListType(): typeof PresetListType;
139
169
  /**
140
170
  * Different text decoration styles
141
171
  *
@@ -325,4 +355,13 @@ export declare class FEnum {
325
355
  * ```
326
356
  */
327
357
  get ThemeColorType(): typeof ThemeColorType;
358
+ /**
359
+ * Image source types
360
+ *
361
+ * @example
362
+ * ```ts
363
+ * console.log(univerAPI.Enum.ImageSourceType.URL);
364
+ * ```
365
+ */
366
+ get ImageSourceType(): typeof ImageSourceType;
328
367
  }