@univerjs-pro/engine-shape 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 +1 -0
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +1 -0
- package/lib/es/index.js +1 -1
- package/lib/facade.js +1 -0
- package/lib/index.js +1 -1
- package/lib/types/config/config.d.ts +5 -0
- package/lib/types/facade/f-connector-shape.d.ts +257 -0
- package/lib/types/facade/f-enum.d.ts +246 -0
- package/lib/types/facade/f-shape-text.d.ts +281 -0
- package/lib/types/facade/f-shape.d.ts +625 -0
- package/lib/types/facade/index.d.ts +6 -0
- package/lib/types/index.d.ts +15 -3
- package/lib/types/models/shape-model.d.ts +1 -1
- package/lib/types/plugin.d.ts +13 -0
- package/lib/types/services/connector-shape-host-adapter.d.ts +40 -0
- package/lib/types/services/connector-shape-host-adapter.service.d.ts +55 -0
- package/lib/types/services/shape-host-adapter.service.d.ts +103 -0
- package/lib/types/shape-type.d.ts +72 -19
- package/lib/types/utils/connector.util.d.ts +15 -0
- package/lib/types/utils/shape-shadow.util.d.ts +8 -0
- package/lib/types/utils/shape-text-behavior.util.d.ts +10 -2
- package/lib/types/utils/shape-text-converter.d.ts +14 -0
- package/lib/umd/facade.js +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +15 -2
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import type { IResolvedShapeTextBoxOptions, IShapeRef, IShapeTextBoxOptions } from '@univerjs-pro/engine-shape';
|
|
2
|
+
import type { HorizontalAlign, Injector, ITextStyle, RichTextValue, VerticalAlign } from '@univerjs/core';
|
|
3
|
+
import type { IShapeGradientStop } from './f-shape';
|
|
4
|
+
import { ImageFillModeEnum, ImageSourceTypeEnum, ShapeGradientTypeEnum } from '@univerjs-pro/engine-shape';
|
|
5
|
+
/** Optional picture-fill properties accepted by `FShapeText.setImageFill()`. */
|
|
6
|
+
export interface IShapeTextImageFillOptions {
|
|
7
|
+
/** Picture opacity in the range from 0 to 1. */
|
|
8
|
+
opacity?: number;
|
|
9
|
+
/** Whether the picture stretches once or tiles repeatedly. */
|
|
10
|
+
mode?: ImageFillModeEnum;
|
|
11
|
+
/** Horizontal picture scale. */
|
|
12
|
+
scaleX?: number;
|
|
13
|
+
/** Vertical picture scale. */
|
|
14
|
+
scaleY?: number;
|
|
15
|
+
/** Horizontal picture offset. */
|
|
16
|
+
offsetX?: number;
|
|
17
|
+
/** Vertical picture offset. */
|
|
18
|
+
offsetY?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A live text facade for a Shape in any supported host.
|
|
22
|
+
*
|
|
23
|
+
* @example Sheet
|
|
24
|
+
* ```ts
|
|
25
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
26
|
+
* const fWorksheet = fWorkbook.getSheetByName('Sheet1');
|
|
27
|
+
* const fShape = fWorksheet.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.Rect });
|
|
28
|
+
* const fShapeText = fShape?.getText();
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example Doc
|
|
32
|
+
* ```ts
|
|
33
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
34
|
+
* const fShape = fDocument.insertShape({
|
|
35
|
+
* shapeType: univerAPI.Enum.ShapeTypeEnum.Rect,
|
|
36
|
+
* textRange: { startOffset: 0, endOffset: 0, collapsed: true },
|
|
37
|
+
* });
|
|
38
|
+
* const fShapeText = fShape?.getText();
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example Slide
|
|
42
|
+
* ```ts
|
|
43
|
+
* const fPresentation = univerAPI.getActivePresentation();
|
|
44
|
+
* const fSlide = fPresentation.getSlideByIndex(0);
|
|
45
|
+
* const fShape = fSlide.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.Rect });
|
|
46
|
+
* const fShapeText = fShape?.getText();
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example Board
|
|
50
|
+
* ```ts
|
|
51
|
+
* const fBoard = univerAPI.getActiveBoard();
|
|
52
|
+
* const fShape = fBoard.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.Rect });
|
|
53
|
+
* const fShapeText = fShape?.getText();
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* fShapeText
|
|
59
|
+
* ?.setText('Quarterly review')
|
|
60
|
+
* .setColor('#2563eb')
|
|
61
|
+
* .setFontSize(18)
|
|
62
|
+
* .setBold(true)
|
|
63
|
+
* .setHorizontalAlign(univerAPI.Enum.HorizontalAlign.CENTER)
|
|
64
|
+
* .setVerticalAlign(univerAPI.Enum.VerticalAlign.MIDDLE)
|
|
65
|
+
* .setTextBoxOptions({ padding: { left: 12, right: 12, top: 8, bottom: 8 } });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare class FShapeText {
|
|
69
|
+
private readonly _shapeRef;
|
|
70
|
+
private readonly _injector;
|
|
71
|
+
constructor(_shapeRef: IShapeRef, _injector: Injector);
|
|
72
|
+
/**
|
|
73
|
+
* Returns the Shape text as a detached rich-text value.
|
|
74
|
+
* @returns {RichTextValue | null} A rich-text value, or `null` when the Shape has no text.
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const richText = fShapeText.getRichText();
|
|
78
|
+
* console.log(richText?.toPlainText());
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
getRichText(): RichTextValue | null;
|
|
82
|
+
/**
|
|
83
|
+
* Returns the Shape text as plain text.
|
|
84
|
+
* @returns {string | null} The plain text, or `null` when the Shape has no text.
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* console.log(fShapeText.getPlainText());
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
getPlainText(): string | null;
|
|
91
|
+
/**
|
|
92
|
+
* Replaces the Shape text with a rich-text value.
|
|
93
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const richText = univerAPI.newRichText()
|
|
97
|
+
* .text('Status: ')
|
|
98
|
+
* .span('Approved', { bold: true, color: '#16a34a' });
|
|
99
|
+
* fShapeText.setRichText(richText);
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
setRichText(value: RichTextValue): this;
|
|
103
|
+
/**
|
|
104
|
+
* Replaces the Shape text with plain text.
|
|
105
|
+
* @param {string} text The plain text to set.
|
|
106
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* fShapeText.setText('Quarterly review');
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
setText(text: string): this;
|
|
113
|
+
/**
|
|
114
|
+
* Merges a text style into the complete Shape text.
|
|
115
|
+
* @param {ITextStyle} style The Univer document text style to apply.
|
|
116
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* fShapeText.setTextStyle({ ff: 'Inter', fs: 18 });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
setTextStyle(style: ITextStyle): this;
|
|
123
|
+
/**
|
|
124
|
+
* Replaces the complete Shape text fill with a solid color.
|
|
125
|
+
* @param {string} color The CSS text color.
|
|
126
|
+
* @param {number} [opacity] Optional opacity in the range from 0 to 1.
|
|
127
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* fShapeText.setColor('#2563eb', 0.8);
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
setColor(color: string, opacity?: number): this;
|
|
134
|
+
/**
|
|
135
|
+
* Removes the visible fill from the complete Shape text.
|
|
136
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* fShapeText.setNoneFill();
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
setNoneFill(): this;
|
|
143
|
+
/**
|
|
144
|
+
* Replaces the complete Shape text fill with a gradient.
|
|
145
|
+
* @param {ShapeGradientTypeEnum} gradientType The gradient geometry.
|
|
146
|
+
* @param {IShapeGradientStop[]} stops At least two gradient color stops.
|
|
147
|
+
* @param {number} [angle] Optional gradient angle in degrees.
|
|
148
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* fShapeText.setGradientFill(univerAPI.Enum.ShapeGradientTypeEnum.Linear, [
|
|
152
|
+
* { position: 0, color: '#2563eb' },
|
|
153
|
+
* { position: 1, color: '#a855f7' },
|
|
154
|
+
* ], 45);
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
setGradientFill(gradientType: ShapeGradientTypeEnum, stops: IShapeGradientStop[], angle?: number): this;
|
|
158
|
+
/**
|
|
159
|
+
* Replaces the complete Shape text fill with an image.
|
|
160
|
+
* @param {string} source The URL, UUID, or base64 image source.
|
|
161
|
+
* @param {ImageSourceTypeEnum} [sourceType] The image source type. Defaults to URL.
|
|
162
|
+
* @param {IShapeTextImageFillOptions} [options] Optional picture opacity, mode, scale, and offset.
|
|
163
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* fShapeText.setImageFill(
|
|
167
|
+
* 'https://github.com/dream-num.png',
|
|
168
|
+
* univerAPI.Enum.ShapeImageSourceTypeEnum.URL,
|
|
169
|
+
* { opacity: 0.9, mode: univerAPI.Enum.ShapeImageFillModeEnum.Stretch }
|
|
170
|
+
* );
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
setImageFill(source: string, sourceType?: ImageSourceTypeEnum, options?: IShapeTextImageFillOptions): this;
|
|
174
|
+
/**
|
|
175
|
+
* Sets the font size of the complete Shape text.
|
|
176
|
+
* @param {number} fontSize The font size in points.
|
|
177
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* fShapeText.setFontSize(18);
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
setFontSize(fontSize: number): this;
|
|
184
|
+
/**
|
|
185
|
+
* Sets the font family of the complete Shape text.
|
|
186
|
+
* @param {string} fontFamily The font family name.
|
|
187
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* fShapeText.setFontFamily('Inter');
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
setFontFamily(fontFamily: string): this;
|
|
194
|
+
/**
|
|
195
|
+
* Sets whether the complete Shape text is bold.
|
|
196
|
+
* @param {boolean} bold Whether bold formatting is enabled.
|
|
197
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* fShapeText.setBold(true);
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
setBold(bold: boolean): this;
|
|
204
|
+
/**
|
|
205
|
+
* Sets whether the complete Shape text is italic.
|
|
206
|
+
* @param {boolean} italic Whether italic formatting is enabled.
|
|
207
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* fShapeText.setItalic(true);
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
setItalic(italic: boolean): this;
|
|
214
|
+
/**
|
|
215
|
+
* Sets whether the complete Shape text is underlined.
|
|
216
|
+
* @param {boolean} underline Whether underline formatting is enabled.
|
|
217
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* fShapeText.setUnderline(true);
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
setUnderline(underline: boolean): this;
|
|
224
|
+
/**
|
|
225
|
+
* Sets whether the complete Shape text has a strikethrough.
|
|
226
|
+
* @param {boolean} strikethrough Whether strikethrough formatting is enabled.
|
|
227
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* fShapeText.setStrikethrough(true);
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
setStrikethrough(strikethrough: boolean): this;
|
|
234
|
+
/**
|
|
235
|
+
* Sets the horizontal alignment of the Shape text.
|
|
236
|
+
* @param {HorizontalAlign} align The horizontal alignment.
|
|
237
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
240
|
+
* fShapeText.setHorizontalAlign(univerAPI.Enum.HorizontalAlign.CENTER);
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
setHorizontalAlign(align: HorizontalAlign): this;
|
|
244
|
+
/**
|
|
245
|
+
* Sets the vertical alignment of the Shape text.
|
|
246
|
+
* @param {VerticalAlign} align The vertical alignment.
|
|
247
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* fShapeText.setVerticalAlign(univerAPI.Enum.VerticalAlign.MIDDLE);
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
setVerticalAlign(align: VerticalAlign): this;
|
|
254
|
+
/**
|
|
255
|
+
* Returns the resolved Shape text-box layout options.
|
|
256
|
+
* @returns {IResolvedShapeTextBoxOptions | null} The resolved text-box options, or `null` when the Shape has no text.
|
|
257
|
+
* @example
|
|
258
|
+
* ```ts
|
|
259
|
+
* console.log(fShapeText.getTextBoxOptions());
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
getTextBoxOptions(): IResolvedShapeTextBoxOptions | null;
|
|
263
|
+
/**
|
|
264
|
+
* Updates the Shape text-box layout options.
|
|
265
|
+
* @param {IShapeTextBoxOptions} options The text-box layout options to apply.
|
|
266
|
+
* @returns {FShapeText} This Shape text facade for chaining.
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* fShapeText.setTextBoxOptions({
|
|
270
|
+
* textDirection: univerAPI.Enum.ShapeTextDirection.Horz,
|
|
271
|
+
* autoFitType: univerAPI.Enum.ShapeTextAutoFitType.NoAutoFit,
|
|
272
|
+
* textWrap: univerAPI.Enum.ShapeTextWrapType.Square,
|
|
273
|
+
* padding: { left: 12, right: 12, top: 8, bottom: 8 },
|
|
274
|
+
* });
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
setTextBoxOptions(options: IShapeTextBoxOptions): this;
|
|
278
|
+
private _getAdapter;
|
|
279
|
+
private _getShapeData;
|
|
280
|
+
private _updateShapeData;
|
|
281
|
+
}
|