11import {
2- deflate ,
32 enumKey ,
43 fitRects ,
5- inflate ,
6- NodeType ,
74 processCircle ,
85 processColor ,
96 processPath ,
@@ -12,8 +9,6 @@ import {
129} from "../../../dom/nodes" ;
1310import type {
1411 AtlasProps ,
15- BoxProps ,
16- BoxShadowProps ,
1712 CircleProps ,
1813 DiffRectProps ,
1914 DrawingNodeProps ,
@@ -38,18 +33,13 @@ import { saturate } from "../../../renderer/processors";
3833import type { SkPoint , SkRSXform } from "../../../skia/types" ;
3934import {
4035 BlendMode ,
41- BlurStyle ,
42- ClipOp ,
4336 FillType ,
4437 FilterMode ,
4538 isCubicSampling ,
46- isRRect ,
4739 MipmapMode ,
4840 PointMode ,
4941 VertexMode ,
5042} from "../../../skia/types" ;
51- import type { Node } from "../../Node" ;
52- import { materialize } from "../../utils" ;
5343import type { DrawingContext } from "../DrawingContext" ;
5444
5545export const drawLine = ( ctx : DrawingContext , props : LineProps ) => {
@@ -64,61 +54,6 @@ export const drawOval = (ctx: DrawingContext, props: OvalProps) => {
6454 ctx . canvas . drawOval ( rect , ctx . paint ) ;
6555} ;
6656
67- export const drawBox = (
68- ctx : DrawingContext ,
69- props : BoxProps ,
70- // eslint-disable-next-line @typescript-eslint/no-explicit-any
71- children : Node < any > [ ]
72- ) => {
73- "worklet" ;
74- const { paint, Skia, canvas } = ctx ;
75- const { box : defaultBox } = props ;
76- const opacity = paint . getAlphaf ( ) ;
77- const box = isRRect ( defaultBox ) ? defaultBox : Skia . RRectXY ( defaultBox , 0 , 0 ) ;
78- const shadows = children
79- . map ( ( node ) => {
80- if ( node . type === NodeType . BoxShadow ) {
81- return materialize ( node . props ) ;
82- }
83- return null ;
84- } )
85- . filter ( ( n ) : n is BoxShadowProps => n !== null ) ;
86- shadows
87- . filter ( ( shadow ) => ! shadow . inner )
88- . map ( ( shadow ) => {
89- const { color = "black" , blur, spread = 0 , dx = 0 , dy = 0 } = shadow ;
90- const lPaint = Skia . Paint ( ) ;
91- lPaint . setColor ( processColor ( Skia , color ) ) ;
92- lPaint . setAlphaf ( paint . getAlphaf ( ) * opacity ) ;
93- lPaint . setMaskFilter (
94- Skia . MaskFilter . MakeBlur ( BlurStyle . Normal , blur , true )
95- ) ;
96- canvas . drawRRect ( inflate ( Skia , box , spread , spread , dx , dy ) , lPaint ) ;
97- } ) ;
98-
99- canvas . drawRRect ( box , paint ) ;
100-
101- shadows
102- . filter ( ( shadow ) => shadow . inner )
103- . map ( ( shadow ) => {
104- const { color = "black" , blur, spread = 0 , dx = 0 , dy = 0 } = shadow ;
105- const delta = Skia . Point ( 10 + Math . abs ( dx ) , 10 + Math . abs ( dy ) ) ;
106- canvas . save ( ) ;
107- canvas . clipRRect ( box , ClipOp . Intersect , false ) ;
108- const lPaint = Skia . Paint ( ) ;
109- lPaint . setColor ( processColor ( Skia , color ) ) ;
110- lPaint . setAlphaf ( paint . getAlphaf ( ) * opacity ) ;
111-
112- lPaint . setMaskFilter (
113- Skia . MaskFilter . MakeBlur ( BlurStyle . Normal , blur , true )
114- ) ;
115- const inner = deflate ( Skia , box , spread , spread , dx , dy ) ;
116- const outer = inflate ( Skia , box , delta . x , delta . y ) ;
117- canvas . drawDRRect ( outer , inner , lPaint ) ;
118- canvas . restore ( ) ;
119- } ) ;
120- } ;
121-
12257export const drawImage = ( ctx : DrawingContext , props : ImageProps ) => {
12358 "worklet" ;
12459 const { image, sampling } = props ;
0 commit comments