22// Licensed under the Apache License Version 2.0 that can be found in the
33// LICENSE file in the root directory of this source tree.
44
5+ import { loadWorkletRuntime } from '@lynx-js/react/worklet-runtime/bindings' ;
56import type { Worklet } from '@lynx-js/react/worklet-runtime/bindings' ;
67import type { BaseEvent } from '@lynx-js/types' ;
78
@@ -14,6 +15,20 @@ function registerMTCEvent(
1415 id : string ,
1516 callback : undefined | ( ( e : BaseEvent ) => void ) ,
1617) : Record < string , unknown > | undefined {
18+ if ( ! globalThis . lynxWorkletImpl ) {
19+ // @ts -ignore
20+ loadWorkletRuntime ( typeof globDynamicComponentEntry === 'undefined' ? undefined : globDynamicComponentEntry ) ;
21+ // @ts -ignore
22+ globalThis . runMTCEvent = ( ctx : Worklet , e : [ any ] ) => {
23+ const event = {
24+ ...e [ 0 ] ,
25+ target : new Element ( e [ 0 ] . target . elementRefptr ) ,
26+ currentTarget : new Element ( e [ 0 ] . currentTarget . elementRefptr ) ,
27+ } as BaseEvent ;
28+ mtcEvents . get ( ctx . _wkltId ) ! ( event ) ;
29+ } ;
30+ }
31+
1732 if ( ! callback ) {
1833 mtcEvents . delete ( id ) ;
1934 return undefined ;
@@ -28,16 +43,6 @@ function registerMTCEvent(
2843 } ;
2944}
3045
31- // @ts -ignore
32- globalThis . runWorklet = ( ctx : Worklet , e : [ any ] ) => {
33- const event = {
34- ...e [ 0 ] ,
35- target : new Element ( e [ 0 ] . target . elementRefptr ) ,
36- currentTarget : new Element ( e [ 0 ] . currentTarget . elementRefptr ) ,
37- } as BaseEvent ;
38- mtcEvents . get ( ctx . _wkltId ) ! ( event ) ;
39- } ;
40-
4146function updateEvent (
4247 snapshot : SnapshotInstance ,
4348 expIndex : number ,
0 commit comments