File tree 2 files changed +19
-3
lines changed
integrations/toucantoco/src
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ type ToucanRuntimeContext = RuntimeContext<ToucanRuntimeEnvironment>;
18
18
const embedBlock = createComponent < {
19
19
toucanId ?: string ;
20
20
url ?: string ;
21
+ height ?: number ;
22
+ width ?: number ;
21
23
} > ( {
22
24
componentId : 'embed' ,
23
25
@@ -41,7 +43,16 @@ const embedBlock = createComponent<{
41
43
42
44
async render ( element , context ) {
43
45
const { environment } = context ;
44
- const { toucanId, url } = element . props ;
46
+ const { toucanId, url, height, width } = element . props ;
47
+
48
+ function getAspectRatio ( height ?: number , width ?: number ) : number {
49
+ if ( height && width && height > 0 && width > 0 ) {
50
+ return width / height ;
51
+ }
52
+ return 1 ;
53
+ }
54
+
55
+ const aspectRatio = getAspectRatio ( height , width ) ;
45
56
46
57
if ( ! toucanId || ! url ) {
47
58
return (
@@ -62,7 +73,7 @@ const embedBlock = createComponent<{
62
73
source = { {
63
74
url : environment . integration . urls . icon ,
64
75
} }
65
- aspectRatio = { 1 }
76
+ aspectRatio = { aspectRatio }
66
77
/>
67
78
) : undefined
68
79
}
Original file line number Diff line number Diff line change @@ -5,14 +5,19 @@ export function extractToucanInfoFromURL(input: string):
5
5
| undefined
6
6
| {
7
7
toucanId ?: string ;
8
+ height ?: number ;
9
+ width ?: number ;
8
10
} {
9
11
const url = new URL ( input ) ;
10
12
11
13
// Ignore non-TT URLs
12
14
const toucanId = url . searchParams . get ( 'id' ) ;
15
+ let height = Number ( url . searchParams . get ( 'height' ) ) || 100 ;
16
+ let width = Number ( url . searchParams . get ( 'width' ) ) || 100 ;
17
+
13
18
if ( ! toucanId || ! url . hostname . endsWith ( '.toucantoco.com' ) ) {
14
19
return ;
15
20
}
16
21
17
- return { toucanId } ;
22
+ return { toucanId, height , width } ;
18
23
}
You can’t perform that action at this time.
0 commit comments