@@ -66,6 +66,47 @@ class Blender {
6666 } ;
6767 }
6868
69+ /**
70+ * Sets up fillStyle/strokeStyle interceptors on an external (group) context
71+ * so that calcStyle transforms text/shape colors within transparency groups.
72+ */
73+ interceptGroupStyles ( ctx ) {
74+ const proto = Object . getPrototypeOf ( ctx ) ;
75+ for ( const prop of [ "fillStyle" , "strokeStyle" ] ) {
76+ const descriptor = Object . getOwnPropertyDescriptor ( proto , prop ) ;
77+ const { get : originalGet , set : originalSet } = descriptor ;
78+ Object . defineProperty ( ctx , prop , {
79+ get : ( ) => originalGet . call ( ctx ) ,
80+ set : v => {
81+ originalSet . call ( ctx , v ) ;
82+ const currentVal = originalGet . call ( ctx ) ;
83+ const newVal = this . getCanvasStyle ( currentVal ) ;
84+ if ( newVal !== undefined ) {
85+ originalSet . call ( ctx , newVal ) ;
86+ }
87+ } ,
88+ configurable : true ,
89+ enumerable : true ,
90+ } ) ;
91+ }
92+ }
93+
94+ /**
95+ * Restores original fillStyle/strokeStyle on a group context.
96+ */
97+ cleanupGroupStyles ( ctx ) {
98+ const proto = Object . getPrototypeOf ( ctx ) ;
99+ for ( const prop of [ "fillStyle" , "strokeStyle" ] ) {
100+ const descriptor = Object . getOwnPropertyDescriptor ( proto , prop ) ;
101+ Object . defineProperty ( ctx , prop , {
102+ get : descriptor . get ? descriptor . get . bind ( ctx ) : undefined ,
103+ set : descriptor . set ? descriptor . set . bind ( ctx ) : undefined ,
104+ configurable : true ,
105+ enumerable : true ,
106+ } ) ;
107+ }
108+ }
109+
69110 /**
70111 * Removes all our property definitions and method wraps on this.ctx.
71112 */
0 commit comments