Skip to content

Commit 64e7f51

Browse files
Add examples and docstrings to Overlay and Underlay (#368)
1 parent c6fdff5 commit 64e7f51

File tree

3 files changed

+100
-13
lines changed

3 files changed

+100
-13
lines changed

src/actions/overlay.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,33 @@ import {LayerAction} from "./layer/LayerAction";
55
* @description Adds a video, text or an image layer as an overlay over the base layer. </br>
66
* @memberOf Actions
77
* @namespace Overlay
8+
* @see Visit {@link Qualifiers.TextStyle|TextStyle} for advanced text options
9+
* @see {@link Actions.Underlay| The underlay action}
810
* @example
911
* import {Cloudinary} from "@cloudinary/base/instance/Cloudinary";
1012
*
1113
* const yourCldInstance = new Cloudinary({cloud:{cloudName:'demo'}});
12-
* const image = yourCldInstance.image('woman');
14+
* const myVideo = yourCldInstance.video('dog');
1315
*
14-
* image.overlay(
15-
* Overlay.source(Source.image('sample'))
16+
* import {source} from "@cloudinary/base/actions/overlay"
17+
* import {image, video, text} from "@cloudinary/base/qualifiers/source"
18+
* import {TextStyle} from '@cloudinary/base/qualifiers/textStyle
19+
*
20+
* myVideo.overlay(
21+
* source(image('myImage'))
22+
* )
23+
*
24+
* myVideo.overlay(
25+
* source(video('myVideo'))
26+
* )
27+
*
28+
* myVideo.overlay(
29+
* source(text('My text'), 'arial_15')
30+
* )
31+
*
32+
* // Or a text with more complex options
33+
* myVideo.overlay(
34+
* source(text('My text'), new TextStyle('arial', 50))
1635
* )
1736
*/
1837

src/actions/underlay.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,39 @@ import {FetchSource} from "../qualifiers/source/sourceTypes/FetchSource";
88
* @memberOf Actions
99
* @namespace Underlay
1010
* @description Adds an image or a text layer as an underlay under the base layer. </br>
11+
* @see Visit {@link Qualifiers.TextStyle|TextStyle} for advanced text options
12+
* @see {@link Actions.Overlay| The overlay action}
1113
* @example
1214
* import {Cloudinary} from "@cloudinary/base/instance/Cloudinary";
1315
*
1416
* const yourCldInstance = new Cloudinary({cloud:{cloudName:'demo'}});
15-
* const image = yourCldInstance.image('woman');
16-
* image.underlay(
17-
* Underlay.source(Source.image('sample'))
17+
* const myVideo = yourCldInstance.video('dog');
18+
*
19+
* import {source} from "@cloudinary/base/actions/underlay"
20+
* import {image, video, text} from "@cloudinary/base/qualifiers/source"
21+
* import {TextStyle} from '@cloudinary/base/qualifiers/textStyle
22+
*
23+
* myVideo.underlay(
24+
* source(image('myImage'))
25+
* )
26+
*
27+
* myVideo.underlay(
28+
* source(video('myVideo'))
29+
* )
30+
*
31+
* myVideo.underlay(
32+
* source(text('My text'), 'arial_15')
33+
* )
34+
*
35+
* // Or a text with more complex options
36+
* myVideo.underlay(
37+
* source(text('My text'), new TextStyle('arial', 50))
1838
* )
1939
*/
2040

41+
42+
43+
2144
/**
2245
* @summary action
2346
* @description Adds a layer for an asset

src/qualifiers/textStyle.ts

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import {serializeCloudinaryCharacters} from "../internal/utils/serializeCloudina
66
/**
77
* @summary qualifier
88
* @description Specifies how to style your layered text, controls the font, font size, line spacing and more.
9-
* <b>Learn more</b>: {@link https://cloudinary.com/documentation/image_transformations#adding_text_overlays | Adding text overlays to images}
10-
* <b>Learn more</b>: {@link https://cloudinary.com/documentation/video_manipulation_and_delivery#adding_text_captions | Adding text overlays to videos}
9+
* </br><b>Learn more</b>: {@link https://cloudinary.com/documentation/image_transformations#adding_text_overlays | Adding text overlays to images}
10+
* </br><b>Learn more</b>: {@link https://cloudinary.com/documentation/video_manipulation_and_delivery#adding_text_captions | Adding text overlays to videos}
11+
* @see {@link Actions.Overlay| The overlay action}
12+
* @see {@link Actions.Underlay| The underlay action}
1113
* @memberOf Qualifiers
12-
* @namespace TextStyle
1314
*/
1415
class TextStyle {
1516
private _lineSpacing: number;
@@ -24,6 +25,10 @@ class TextStyle {
2425
private _stroke: boolean;
2526
private _fontHinting: string;
2627

28+
/**
29+
* @param {string} fontFamily The font family
30+
* @param {number | string} fontSize The font size
31+
*/
2732
constructor(fontFamily: string, fontSize: string | number) {
2833
if (!fontFamily || !fontSize) {
2934
throw `You must provide a fontFamily and fontSize to a TextStyle`;
@@ -32,56 +37,96 @@ class TextStyle {
3237
this._fontSize = fontSize;
3338
}
3439

40+
/**
41+
* @param {number} spacing The spacing between multiple lines in pixels.
42+
*/
3543
lineSpacing(spacing: number): this {
3644
this._lineSpacing = spacing;
3745
return this;
3846
}
3947

48+
49+
/**
50+
* @param spacing The spacing between the letters, in pixels.
51+
*/
4052
letterSpacing(spacing: number): this {
4153
this._letterSpacing = spacing;
4254
return this;
4355
}
4456

57+
/**
58+
* The antialias setting to apply to the text. When this parameter is not specified, the default antialiasing for the subsystem and target device are applied.
59+
* @param antiAlias
60+
*/
4561
fontAntialias(antiAlias: string): this {
4662
this._fontAntialias = antiAlias;
4763
return this;
4864
}
4965

66+
/**
67+
* The name of any universally available font or a custom font, specified as the public ID of a raw, authenticated font in your account.
68+
* For details on custom fonts, see {@link https://cloudinary.com/documentation/image_transformations#using_custom_fonts_for_text_overlays|Using custom fonts for text overlays}.
69+
* @param {string} fontFamilyName
70+
*/
5071
fontFamily(fontFamilyName: string): this {
5172
this._fontFamily = fontFamilyName;
5273
return this;
5374
}
5475

76+
/**
77+
* @param {number} fontSize The font size
78+
*/
5579
fontSize(fontSize: number | string): this {
5680
this._fontSize = fontSize ;
5781
return this;
5882
}
5983

60-
fontWeight(fontWeight: string): this {
84+
/**
85+
* @param {string} fontWeight The font weight
86+
*/
87+
fontWeight(fontWeight: 'normal' | 'bold' | 'thin' | 'light' | string): this {
6188
this._fontWeight = fontWeight;
6289
return this;
6390
}
6491

65-
fontStyle(fontStyle: string): this {
92+
/**
93+
*
94+
* @param {string} fontStyle The font style.
95+
*/
96+
fontStyle(fontStyle: 'normal' | 'italic' | string): this {
6697
this._fontStyle = fontStyle;
6798
return this;
6899
}
69100

101+
/**
102+
* @param {string} fontHinting The outline hinting style to apply to the text. When this parameter is not specified, the default hint style for the font and target device are applied.
103+
*/
70104
fontHinting(fontHinting: string): this {
71105
this._fontHinting = fontHinting;
72106
return this;
73107
}
74108

75-
textDecoration(textDecoration: string): this {
109+
/**
110+
*
111+
* @param {string} textDecoration The font decoration type.
112+
*/
113+
textDecoration(textDecoration: 'normal' | 'underline' | 'strikethrough' | string): this {
76114
this._textDecoration = textDecoration;
77115
return this;
78116
}
79117

80-
textAlignment(textAlignment: string): this {
118+
119+
/**
120+
* @param {string} textAlignment The text alignment
121+
*/
122+
textAlignment(textAlignment: 'left' | 'center' | 'right' | 'end' | 'start' | 'justify' | string): this {
81123
this._textAlignment = textAlignment;
82124
return this;
83125
}
84126

127+
/**
128+
* @description Whether to include an outline stroke. Set the color and weight of the stroke
129+
*/
85130
stroke(): this {
86131
this._stroke = true;
87132
return this;

0 commit comments

Comments
 (0)