@@ -7,7 +7,10 @@ export interface Size {
7
7
height : number ;
8
8
}
9
9
10
- export const size = ( width = 0 , height = 0 ) => ( { width, height } ) ;
10
+ export const size = ( width = 0 , height = 0 ) => {
11
+ "worklet" ;
12
+ return { width, height } ;
13
+ } ;
11
14
12
15
export const rect2rect = (
13
16
src : SkRect ,
@@ -18,37 +21,19 @@ export const rect2rect = (
18
21
{ scaleX : number } ,
19
22
{ scaleY : number }
20
23
] => {
24
+ "worklet" ;
21
25
const scaleX = dst . width / src . width ;
22
26
const scaleY = dst . height / src . height ;
23
27
const translateX = dst . x - src . x * scaleX ;
24
28
const translateY = dst . y - src . y * scaleY ;
25
29
return [ { translateX } , { translateY } , { scaleX } , { scaleY } ] ;
26
30
} ;
27
31
28
- export const fitRects = (
29
- fit : Fit ,
30
- rect : SkRect ,
31
- { x, y, width, height } : SkRect
32
- ) => {
33
- const sizes = applyBoxFit (
34
- fit ,
35
- { width : rect . width , height : rect . height } ,
36
- { width, height }
37
- ) ;
38
- const src = inscribe ( sizes . src , rect ) ;
39
- const dst = inscribe ( sizes . dst , {
40
- x,
41
- y,
42
- width,
43
- height,
44
- } ) ;
45
- return { src, dst } ;
46
- } ;
47
-
48
32
const inscribe = (
49
33
{ width, height } : Size ,
50
34
rect : { x : number ; y : number ; width : number ; height : number }
51
35
) => {
36
+ "worklet" ;
52
37
const halfWidthDelta = ( rect . width - width ) / 2.0 ;
53
38
const halfHeightDelta = ( rect . height - height ) / 2.0 ;
54
39
return {
@@ -60,6 +45,7 @@ const inscribe = (
60
45
} ;
61
46
62
47
const applyBoxFit = ( fit : Fit , input : Size , output : Size ) => {
48
+ "worklet" ;
63
49
let src = size ( ) ,
64
50
dst = size ( ) ;
65
51
if (
@@ -122,3 +108,24 @@ const applyBoxFit = (fit: Fit, input: Size, output: Size) => {
122
108
}
123
109
return { src, dst } ;
124
110
} ;
111
+
112
+ export const fitRects = (
113
+ fit : Fit ,
114
+ rect : SkRect ,
115
+ { x, y, width, height } : SkRect
116
+ ) => {
117
+ "worklet" ;
118
+ const sizes = applyBoxFit (
119
+ fit ,
120
+ { width : rect . width , height : rect . height } ,
121
+ { width, height }
122
+ ) ;
123
+ const src = inscribe ( sizes . src , rect ) ;
124
+ const dst = inscribe ( sizes . dst , {
125
+ x,
126
+ y,
127
+ width,
128
+ height,
129
+ } ) ;
130
+ return { src, dst } ;
131
+ } ;
0 commit comments