@univerjs/docs-drawing 1.0.0-alpha.3 → 1.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +559 -0
- package/lib/cjs/index.js +500 -83
- package/lib/es/facade.js +558 -0
- package/lib/es/index.js +495 -85
- package/lib/facade.js +558 -0
- package/lib/index.js +495 -85
- package/lib/types/commands/commands/insert-doc-drawing.command.d.ts +26 -0
- package/lib/types/commands/commands/remove-doc-drawing.command.d.ts +28 -0
- package/lib/types/commands/commands/set-drawing-arrange.command.d.ts +25 -0
- package/lib/types/commands/commands/update-doc-drawing-transform.command.d.ts +27 -0
- package/lib/types/commands/commands/update-doc-drawing-wrapping-style.command.d.ts +36 -0
- package/lib/types/controllers/doc-drawing.controller.d.ts +4 -2
- package/lib/types/facade/f-document-image.d.ts +324 -0
- package/lib/types/facade/f-document.d.ts +120 -0
- package/lib/types/facade/f-enum.d.ts +84 -0
- package/lib/types/facade/index.d.ts +19 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/umd/facade.js +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +16 -4
|
@@ -0,0 +1,25 @@
|
|
|
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 { ICommand } from '@univerjs/core';
|
|
17
|
+
import type { IDrawingOrderMapParam } from '@univerjs/drawing';
|
|
18
|
+
import { ArrangeTypeEnum } from '@univerjs/core';
|
|
19
|
+
export interface ISetDocDrawingArrangeCommandParams extends IDrawingOrderMapParam {
|
|
20
|
+
arrangeType: ArrangeTypeEnum;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The command to arrange drawings.
|
|
24
|
+
*/
|
|
25
|
+
export declare const SetDocDrawingArrangeCommand: ICommand;
|
|
@@ -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 { ICommand, IObjectPositionH, IObjectPositionV, ISize } from '@univerjs/core';
|
|
17
|
+
export interface IDrawingDocTransform {
|
|
18
|
+
drawingId: string;
|
|
19
|
+
key: 'size' | 'angle' | 'positionH' | 'positionV' | 'flipX' | 'flipY';
|
|
20
|
+
value: ISize | number | boolean | IObjectPositionH | IObjectPositionV;
|
|
21
|
+
}
|
|
22
|
+
export interface IUpdateDrawingDocTransformCommandParams {
|
|
23
|
+
unitId: string;
|
|
24
|
+
subUnitId: string;
|
|
25
|
+
drawings: IDrawingDocTransform[];
|
|
26
|
+
}
|
|
27
|
+
export declare const UpdateDrawingDocTransformCommand: ICommand;
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { ICommand } from '@univerjs/core';
|
|
17
|
+
import type { IDocDrawing } from '../../services/doc-drawing.service';
|
|
18
|
+
import { PositionedObjectLayoutType } from '@univerjs/core';
|
|
19
|
+
export declare enum TextWrappingStyle {
|
|
20
|
+
INLINE = "inline",
|
|
21
|
+
BEHIND_TEXT = "behindText",
|
|
22
|
+
IN_FRONT_OF_TEXT = "inFrontOfText",
|
|
23
|
+
WRAP_SQUARE = "wrapSquare",
|
|
24
|
+
WRAP_TOP_AND_BOTTOM = "wrapTopAndBottom"
|
|
25
|
+
}
|
|
26
|
+
export declare const WRAPPING_STYLE_TO_LAYOUT_TYPE: Record<TextWrappingStyle, PositionedObjectLayoutType>;
|
|
27
|
+
export interface IUpdateDocDrawingWrappingStyleParams {
|
|
28
|
+
unitId: string;
|
|
29
|
+
subUnitId: string;
|
|
30
|
+
drawings: IDocDrawing[];
|
|
31
|
+
wrappingStyle: TextWrappingStyle;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Updates document drawing wrapping styles and optional persisted positions.
|
|
35
|
+
*/
|
|
36
|
+
export declare const UpdateDocDrawingWrappingStyleCommand: ICommand;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import type { IDocumentData } from '@univerjs/core';
|
|
17
|
-
import { Disposable, IResourceManagerService, IUniverInstanceService } from '@univerjs/core';
|
|
17
|
+
import { Disposable, ICommandService, IResourceManagerService, IUniverInstanceService } from '@univerjs/core';
|
|
18
18
|
import { IDrawingManagerService } from '@univerjs/drawing';
|
|
19
19
|
import { IDocDrawingService } from '../services/doc-drawing.service';
|
|
20
20
|
export declare const DOCS_DRAWING_PLUGIN = "DOC_DRAWING_PLUGIN";
|
|
@@ -28,9 +28,11 @@ export declare class DocDrawingController extends Disposable {
|
|
|
28
28
|
private readonly _drawingManagerService;
|
|
29
29
|
private _resourceManagerService;
|
|
30
30
|
private _univerInstanceService;
|
|
31
|
-
|
|
31
|
+
private readonly _commandService;
|
|
32
|
+
constructor(_docDrawingService: IDocDrawingService, _drawingManagerService: IDrawingManagerService, _resourceManagerService: IResourceManagerService, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService);
|
|
32
33
|
private _init;
|
|
33
34
|
private _initSnapshot;
|
|
34
35
|
private _setDrawingDataForUnit;
|
|
35
36
|
loadDrawingDataForUnit(unitId: string): boolean;
|
|
37
|
+
private _initCommands;
|
|
36
38
|
}
|
|
@@ -0,0 +1,324 @@
|
|
|
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 { ImageSourceType, Injector, IObjectPositionH, IObjectPositionV, ISize } from '@univerjs/core';
|
|
17
|
+
import type { IDocImage, TextWrappingStyle } from '@univerjs/docs-drawing';
|
|
18
|
+
import type { FDocument } from '@univerjs/docs/facade';
|
|
19
|
+
/**
|
|
20
|
+
* Facade API for an image in a document.
|
|
21
|
+
* @hideconstructor
|
|
22
|
+
*/
|
|
23
|
+
export declare class FDocumentImage {
|
|
24
|
+
private readonly _document;
|
|
25
|
+
private readonly _imageId;
|
|
26
|
+
private readonly _injector;
|
|
27
|
+
constructor(_document: FDocument, _imageId: string, _injector: Injector);
|
|
28
|
+
/**
|
|
29
|
+
* Gets the id of the document containing the image.
|
|
30
|
+
* @returns {string} The document unit id.
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
34
|
+
* const image = fDocument.getImages()[0];
|
|
35
|
+
*
|
|
36
|
+
* if (image) {
|
|
37
|
+
* console.log(image.getUnitId());
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
getUnitId(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the drawing id of the image.
|
|
44
|
+
* @returns {string} The drawing id.
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
48
|
+
* const image = fDocument.getImages()[0];
|
|
49
|
+
*
|
|
50
|
+
* if (image) {
|
|
51
|
+
* console.log(image.getId());
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
getId(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Gets the image source supplied at insertion time.
|
|
58
|
+
* @returns {string | undefined} The image source, or `undefined` when the image no longer exists.
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
62
|
+
* const image = fDocument.getImages()[0];
|
|
63
|
+
*
|
|
64
|
+
* if (image) {
|
|
65
|
+
* console.log(image.getSource());
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
getSource(): string | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Gets the image source type supplied at insertion time.
|
|
72
|
+
* @returns {ImageSourceType | undefined} The image source type, or `undefined` when the image no longer exists.
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
76
|
+
* const image = fDocument.getImages()[0];
|
|
77
|
+
*
|
|
78
|
+
* if (image) {
|
|
79
|
+
* console.log(image.getSourceType());
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
getSourceType(): ImageSourceType | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Gets the current image size.
|
|
86
|
+
* @returns {ISize | null} The width and height in pixels, or `null` when the image no longer exists.
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
90
|
+
* const image = fDocument.getImages()[0];
|
|
91
|
+
*
|
|
92
|
+
* if (image) {
|
|
93
|
+
* console.log(image.getSize());
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
getSize(): ISize | null;
|
|
98
|
+
/**
|
|
99
|
+
* Gets the current clockwise rotation angle.
|
|
100
|
+
* @returns {number | undefined} The rotation angle in degrees, or `undefined` when the image no longer exists.
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
104
|
+
* const image = fDocument.getImages()[0];
|
|
105
|
+
*
|
|
106
|
+
* if (image) {
|
|
107
|
+
* console.log(image.getAngle());
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
getAngle(): number | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Gets the current horizontal position.
|
|
114
|
+
* @returns {IObjectPositionH | null} The horizontal position, or `null` when the image no longer exists.
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
118
|
+
* const image = fDocument.getImages()[0];
|
|
119
|
+
*
|
|
120
|
+
* if (image) {
|
|
121
|
+
* console.log(image.getPositionH());
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
getPositionH(): IObjectPositionH | null;
|
|
126
|
+
/**
|
|
127
|
+
* Gets the current vertical position.
|
|
128
|
+
* @returns {IObjectPositionV | null} The vertical position, or `null` when the image no longer exists.
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
132
|
+
* const image = fDocument.getImages()[0];
|
|
133
|
+
*
|
|
134
|
+
* if (image) {
|
|
135
|
+
* console.log(image.getPositionV());
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
getPositionV(): IObjectPositionV | null;
|
|
140
|
+
/**
|
|
141
|
+
* Gets the current raw document image data.
|
|
142
|
+
* @returns {IDocImage | null} The image data, or `null` when the image no longer exists.
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
146
|
+
* const image = fDocument.getImages()[0];
|
|
147
|
+
*
|
|
148
|
+
* if (image) {
|
|
149
|
+
* console.log(image.getImageData());
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
getImageData(): IDocImage | null;
|
|
154
|
+
/**
|
|
155
|
+
* Sets the image size.
|
|
156
|
+
* @param {number} width The width in pixels.
|
|
157
|
+
* @param {number} height The height in pixels.
|
|
158
|
+
* @returns {boolean} `true` when the update command succeeds; otherwise, `false`.
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
162
|
+
* const image = fDocument.getImages()[0];
|
|
163
|
+
*
|
|
164
|
+
* if (image) {
|
|
165
|
+
* const success = image.setSize(400, 300);
|
|
166
|
+
* console.log(success);
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
setSize(width: number, height: number): boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Sets the clockwise rotation angle.
|
|
173
|
+
* @param {number} angle The rotation angle in degrees.
|
|
174
|
+
* @returns {boolean} `true` when the update command succeeds; otherwise, `false`.
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
178
|
+
* const image = fDocument.getImages()[0];
|
|
179
|
+
*
|
|
180
|
+
* if (image) {
|
|
181
|
+
* const success = image.setRotate(45);
|
|
182
|
+
* console.log(success);
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
setRotate(angle: number): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Sets the horizontal position of the image.
|
|
189
|
+
* Inline images are positioned by their document placeholder, so this has a visible effect only when the image
|
|
190
|
+
* wrapping style is not `TextWrappingStyle.INLINE`.
|
|
191
|
+
* @param {IObjectPositionH} positionH The horizontal position relative to the document.
|
|
192
|
+
* @returns {boolean} `true` when the update command succeeds; otherwise, `false`.
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
196
|
+
* const image = fDocument.getImages()[0];
|
|
197
|
+
*
|
|
198
|
+
* if (image) {
|
|
199
|
+
* const success = image.setPositionH({
|
|
200
|
+
* relativeFrom: univerAPI.Enum.DocsImageRelativeFromH.MARGIN,
|
|
201
|
+
* posOffset: 100
|
|
202
|
+
* });
|
|
203
|
+
* console.log(success);
|
|
204
|
+
* }
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
setPositionH(positionH: IObjectPositionH): boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Sets the vertical position of the image.
|
|
210
|
+
* Inline images are positioned by their document placeholder, so this has a visible effect only when the image
|
|
211
|
+
* wrapping style is not `TextWrappingStyle.INLINE`.
|
|
212
|
+
* @param {IObjectPositionV} positionV The vertical position relative to the document.
|
|
213
|
+
* @returns {boolean} `true` when the update command succeeds; otherwise, `false`.
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
217
|
+
* const image = fDocument.getImages()[0];
|
|
218
|
+
*
|
|
219
|
+
* if (image) {
|
|
220
|
+
* const success = image.setPositionV({
|
|
221
|
+
* relativeFrom: univerAPI.Enum.DocsImageRelativeFromV.MARGIN,
|
|
222
|
+
* posOffset: 100
|
|
223
|
+
* });
|
|
224
|
+
* console.log(success);
|
|
225
|
+
* }
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
setPositionV(positionV: IObjectPositionV): boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Sets the image wrapping style.
|
|
231
|
+
* When switching from inline to a floating style in a UI environment, the current visual position is preserved.
|
|
232
|
+
* @param {TextWrappingStyle} wrappingStyle The wrapping style to apply.
|
|
233
|
+
* @returns {boolean} `true` when the update command succeeds; otherwise, `false`.
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
237
|
+
* const image = fDocument.getImages()[0];
|
|
238
|
+
*
|
|
239
|
+
* if (image) {
|
|
240
|
+
* const success = image.setWrappingStyle(univerAPI.Enum.DocsImageWrappingStyle.WRAP_SQUARE);
|
|
241
|
+
* console.log(success);
|
|
242
|
+
* }
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
setWrappingStyle(wrappingStyle: TextWrappingStyle): boolean;
|
|
246
|
+
/**
|
|
247
|
+
* Moves the image forward by one level in the drawing order.
|
|
248
|
+
* @returns {boolean} `true` when the arrange command succeeds; otherwise, `false`.
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
252
|
+
* const image = fDocument.getImages()[0];
|
|
253
|
+
*
|
|
254
|
+
* if (image) {
|
|
255
|
+
* const success = image.setForward();
|
|
256
|
+
* console.log(success);
|
|
257
|
+
* }
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
setForward(): boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Moves the image backward by one level in the drawing order.
|
|
263
|
+
* @returns {boolean} `true` when the arrange command succeeds; otherwise, `false`.
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
267
|
+
* const image = fDocument.getImages()[0];
|
|
268
|
+
*
|
|
269
|
+
* if (image) {
|
|
270
|
+
* const success = image.setBackward();
|
|
271
|
+
* console.log(success);
|
|
272
|
+
* }
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
setBackward(): boolean;
|
|
276
|
+
/**
|
|
277
|
+
* Moves the image to the back of the drawing order.
|
|
278
|
+
* @returns {boolean} `true` when the arrange command succeeds; otherwise, `false`.
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
282
|
+
* const image = fDocument.getImages()[0];
|
|
283
|
+
*
|
|
284
|
+
* if (image) {
|
|
285
|
+
* const success = image.setBack();
|
|
286
|
+
* console.log(success);
|
|
287
|
+
* }
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
setBack(): boolean;
|
|
291
|
+
/**
|
|
292
|
+
* Moves the image to the front of the drawing order.
|
|
293
|
+
* @returns {boolean} `true` when the arrange command succeeds; otherwise, `false`.
|
|
294
|
+
* @example
|
|
295
|
+
* ```ts
|
|
296
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
297
|
+
* const image = fDocument.getImages()[0];
|
|
298
|
+
*
|
|
299
|
+
* if (image) {
|
|
300
|
+
* const success = image.setFront();
|
|
301
|
+
* console.log(success);
|
|
302
|
+
* }
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
setFront(): boolean;
|
|
306
|
+
/**
|
|
307
|
+
* Removes the image and its document placeholder.
|
|
308
|
+
* @returns {boolean} `true` when the remove command succeeds; otherwise, `false`.
|
|
309
|
+
* @example
|
|
310
|
+
* ```ts
|
|
311
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
312
|
+
* const image = fDocument.getImages()[0];
|
|
313
|
+
*
|
|
314
|
+
* if (image) {
|
|
315
|
+
* const success = image.remove();
|
|
316
|
+
* console.log(success);
|
|
317
|
+
* }
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
remove(): boolean;
|
|
321
|
+
private _updateTransform;
|
|
322
|
+
private _arrange;
|
|
323
|
+
private _getTextRange;
|
|
324
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
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 { IObjectPositionH, IObjectPositionV, ITextRangeParam } from '@univerjs/core';
|
|
17
|
+
import { ImageSourceType } from '@univerjs/core';
|
|
18
|
+
import { TextWrappingStyle } from '@univerjs/docs-drawing';
|
|
19
|
+
import { FDocument } from '@univerjs/docs/facade';
|
|
20
|
+
import { FDocumentImage } from './f-document-image';
|
|
21
|
+
/** Options for inserting an image into a document. */
|
|
22
|
+
export interface IFDocumentInsertImageOptions {
|
|
23
|
+
/** The image source. It cannot be changed after insertion. */
|
|
24
|
+
source: string;
|
|
25
|
+
/** The image source type. It cannot be changed after insertion. */
|
|
26
|
+
imageSourceType: ImageSourceType;
|
|
27
|
+
/** The width in pixels. When only width is provided, height is calculated from the intrinsic aspect ratio. */
|
|
28
|
+
width?: number;
|
|
29
|
+
/** The height in pixels. When only height is provided, width is calculated from the intrinsic aspect ratio. */
|
|
30
|
+
height?: number;
|
|
31
|
+
/** The clockwise rotation angle in degrees. Defaults to `0`. */
|
|
32
|
+
angle?: number;
|
|
33
|
+
/**
|
|
34
|
+
* The horizontal position relative to the document. Defaults to the page with an offset of `0`.
|
|
35
|
+
* It has a visible positioning effect only when `wrappingStyle` is not `INLINE`.
|
|
36
|
+
*/
|
|
37
|
+
positionH?: IObjectPositionH;
|
|
38
|
+
/**
|
|
39
|
+
* The vertical position relative to the document. Defaults to the paragraph with an offset of `0`.
|
|
40
|
+
* It has a visible positioning effect only when `wrappingStyle` is not `INLINE`.
|
|
41
|
+
*/
|
|
42
|
+
positionV?: IObjectPositionV;
|
|
43
|
+
/** The image wrapping style. Defaults to `TextWrappingStyle.INLINE`. */
|
|
44
|
+
wrappingStyle?: TextWrappingStyle;
|
|
45
|
+
/** The document range at which to insert the image. The current selection is used when omitted. */
|
|
46
|
+
textRange?: ITextRangeParam;
|
|
47
|
+
}
|
|
48
|
+
/** Image facade methods mixed into `FDocument`. */
|
|
49
|
+
export interface IFDocumentImageMixin {
|
|
50
|
+
/**
|
|
51
|
+
* Inserts an image into the document.
|
|
52
|
+
*
|
|
53
|
+
* When width and height are both omitted, the intrinsic size is proportionally limited to 500 by 500 pixels.
|
|
54
|
+
*
|
|
55
|
+
* @param {IFDocumentInsertImageOptions} options The image source, optional transform, and insertion range.
|
|
56
|
+
* @returns {Promise<FDocumentImage | null>} The inserted image facade, or `null` when the insertion command fails.
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
60
|
+
* const image = await fDocument.insertImage({
|
|
61
|
+
* source: 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4',
|
|
62
|
+
* imageSourceType: univerAPI.Enum.ImageSourceType.URL,
|
|
63
|
+
* width: 320,
|
|
64
|
+
* textRange: {
|
|
65
|
+
* startOffset: 30,
|
|
66
|
+
* },
|
|
67
|
+
* });
|
|
68
|
+
* console.log(image);
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
74
|
+
* const image = await fDocument.insertImage({
|
|
75
|
+
* source: 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4',
|
|
76
|
+
* imageSourceType: univerAPI.Enum.ImageSourceType.URL,
|
|
77
|
+
* width: 320,
|
|
78
|
+
* wrappingStyle: univerAPI.Enum.DocsImageWrappingStyle.WRAP_SQUARE,
|
|
79
|
+
* textRange: {
|
|
80
|
+
* startOffset: 30,
|
|
81
|
+
* },
|
|
82
|
+
* });
|
|
83
|
+
* console.log(image);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
insertImage(options: IFDocumentInsertImageOptions): Promise<FDocumentImage | null>;
|
|
87
|
+
/**
|
|
88
|
+
* Gets an image by its drawing id.
|
|
89
|
+
* @param {string} imageId The drawing id of the image.
|
|
90
|
+
* @returns {FDocumentImage | null} The image facade, or `null` when the image does not exist.
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
94
|
+
* const image = fDocument.getImage('image-1');
|
|
95
|
+
* console.log(image);
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
getImage(imageId: string): FDocumentImage | null;
|
|
99
|
+
/**
|
|
100
|
+
* Gets all images in the document in drawing order.
|
|
101
|
+
* @returns {FDocumentImage[]} The image facades in drawing order.
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
105
|
+
* const images = fDocument.getImages();
|
|
106
|
+
* console.log(images);
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
getImages(): FDocumentImage[];
|
|
110
|
+
}
|
|
111
|
+
export declare class FDocumentImageMixin extends FDocument implements IFDocumentImageMixin {
|
|
112
|
+
insertImage(options: IFDocumentInsertImageOptions): Promise<FDocumentImage | null>;
|
|
113
|
+
getImage(imageId: string): FDocumentImage | null;
|
|
114
|
+
getImages(): FDocumentImage[];
|
|
115
|
+
private _getIntrinsicSize;
|
|
116
|
+
}
|
|
117
|
+
declare module '@univerjs/docs/facade' {
|
|
118
|
+
interface FDocument extends IFDocumentImageMixin {
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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 { ObjectRelativeFromH, ObjectRelativeFromV } from '@univerjs/core';
|
|
17
|
+
import { FEnum } from '@univerjs/core/facade';
|
|
18
|
+
import { TextWrappingStyle } from '@univerjs/docs-drawing';
|
|
19
|
+
/**
|
|
20
|
+
* @ignore
|
|
21
|
+
*/
|
|
22
|
+
export interface IFDocumentImageEnumMixin {
|
|
23
|
+
/**
|
|
24
|
+
* Represents the wrapping styles used by docs image operations.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
28
|
+
* const image = await fDocument.insertImage({
|
|
29
|
+
* source: 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4',
|
|
30
|
+
* imageSourceType: univerAPI.Enum.ImageSourceType.URL,
|
|
31
|
+
* width: 320,
|
|
32
|
+
* wrappingStyle: univerAPI.Enum.DocsImageWrappingStyle.WRAP_SQUARE,
|
|
33
|
+
* textRange: {
|
|
34
|
+
* startOffset: 30,
|
|
35
|
+
* },
|
|
36
|
+
* });
|
|
37
|
+
* console.log(image);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
DocsImageWrappingStyle: typeof TextWrappingStyle;
|
|
41
|
+
/**
|
|
42
|
+
* Represents the horizontal position types used by docs image operations.
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
46
|
+
* const image = fDocument.getImages()[0];
|
|
47
|
+
*
|
|
48
|
+
* if (image) {
|
|
49
|
+
* const success = image.setPositionH({
|
|
50
|
+
* relativeFrom: univerAPI.Enum.DocsImageRelativeFromH.MARGIN,
|
|
51
|
+
* posOffset: 100
|
|
52
|
+
* });
|
|
53
|
+
* console.log(success);
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
DocsImageRelativeFromH: typeof ObjectRelativeFromH;
|
|
58
|
+
/**
|
|
59
|
+
* Represents the vertical position types used by docs image operations.
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
63
|
+
* const image = fDocument.getImages()[0];
|
|
64
|
+
*
|
|
65
|
+
* if (image) {
|
|
66
|
+
* const success = image.setPositionV({
|
|
67
|
+
* relativeFrom: univerAPI.Enum.DocsImageRelativeFromV.MARGIN,
|
|
68
|
+
* posOffset: 100
|
|
69
|
+
* });
|
|
70
|
+
* console.log(success);
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
DocsImageRelativeFromV: typeof ObjectRelativeFromV;
|
|
75
|
+
}
|
|
76
|
+
export declare class FDocumentImageEnumMixin extends FEnum implements IFDocumentImageEnumMixin {
|
|
77
|
+
get DocsImageWrappingStyle(): typeof TextWrappingStyle;
|
|
78
|
+
get DocsImageRelativeFromH(): typeof ObjectRelativeFromH;
|
|
79
|
+
get DocsImageRelativeFromV(): typeof ObjectRelativeFromV;
|
|
80
|
+
}
|
|
81
|
+
declare module '@univerjs/core/facade' {
|
|
82
|
+
interface FEnum extends IFDocumentImageEnumMixin {
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -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 './f-document';
|
|
17
|
+
import './f-enum';
|
|
18
|
+
export type { IFDocumentInsertImageOptions } from './f-document';
|
|
19
|
+
export { FDocumentImage } from './f-document-image';
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,6 +13,16 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
export { InsertDocDrawingCommand } from './commands/commands/insert-doc-drawing.command';
|
|
17
|
+
export type { IInsertDocDrawingCommandParams } from './commands/commands/insert-doc-drawing.command';
|
|
18
|
+
export { RemoveDocDrawingCommand } from './commands/commands/remove-doc-drawing.command';
|
|
19
|
+
export type { IRemoveDocDrawingCommandParam, IRemoveDocDrawingCommandParams } from './commands/commands/remove-doc-drawing.command';
|
|
20
|
+
export { SetDocDrawingArrangeCommand } from './commands/commands/set-drawing-arrange.command';
|
|
21
|
+
export type { ISetDocDrawingArrangeCommandParams } from './commands/commands/set-drawing-arrange.command';
|
|
22
|
+
export { UpdateDrawingDocTransformCommand } from './commands/commands/update-doc-drawing-transform.command';
|
|
23
|
+
export type { IDrawingDocTransform, IUpdateDrawingDocTransformCommandParams } from './commands/commands/update-doc-drawing-transform.command';
|
|
24
|
+
export { TextWrappingStyle, UpdateDocDrawingWrappingStyleCommand, WRAPPING_STYLE_TO_LAYOUT_TYPE } from './commands/commands/update-doc-drawing-wrapping-style.command';
|
|
25
|
+
export type { IUpdateDocDrawingWrappingStyleParams } from './commands/commands/update-doc-drawing-wrapping-style.command';
|
|
16
26
|
export type { IUniverDocsDrawingConfig } from './config/config';
|
|
17
27
|
export { DOCS_DRAWING_PLUGIN, getDocDrawingRenderOrder } from './controllers/doc-drawing.controller';
|
|
18
28
|
export type { IDocDrawingModel } from './controllers/doc-drawing.controller';
|