44 type DraggableApi ,
55 type DraggableOptions
66} from '../draggable' ;
7- import { addReactive , type WithSilent } from '../helpers' ;
7+ import { addReactive } from '../helpers' ;
88
99export type ImageKnobReactive = {
1010 /**
@@ -46,8 +46,7 @@ export type ImageKnobOptions = DraggableOptions & {
4646 onHeightChange ?: ( v : number ) => void ;
4747} & ImageKnobReactive ;
4848
49- type ImageStateRaw = Required < ImageKnobReactive > ;
50- type ImageState = WithSilent < ImageStateRaw > ;
49+ type ImageState = Required < ImageKnobReactive > ;
5150
5251export function createImageKnob < E extends HTMLElement > (
5352 container : E ,
@@ -67,36 +66,48 @@ export function createImageKnob<E extends HTMLElement>(
6766 }
6867 } ;
6968
69+ const engine = createDraggable ( container , {
70+ ...options ,
71+ onValueChange ( v ) {
72+ options . onValueChange ?.( v ) ;
73+ draw ( v ) ;
74+ }
75+ } ) as ImageKnobApi ;
76+
7077 addReactive ( state , 'src' , options . src , ( src ) => {
7178 options . onSrcChange ?.( src ) ;
7279
7380 image . src = src ;
7481 container . style . backgroundImage = `url(${ src } )` ;
7582 } ) ;
7683 addReactive ( state , 'numberOfFrames' , null , options . onNumberOfFramesChange ) ;
77- addReactive ( state , 'width' , options . width , ( width ) => {
78- options . onWidthChange ?.( width ) ;
79-
80- container . style . width = width + 'px' ;
81- draw ( engine . __state . value ) ;
82- } ) ;
83- addReactive ( state , 'height' , options . height , ( height ) => {
84- options . onHeightChange ?.( height ) ;
85-
86- container . style . width = height + 'px' ;
87- draw ( engine . __state . value ) ;
88- } ) ;
84+ addReactive (
85+ state ,
86+ 'width' ,
87+ options . width ,
88+ ( width ) => {
89+ options . onWidthChange ?.( width ) ;
90+
91+ container . style . width = width + 'px' ;
92+ draw ( engine . __state . value ) ;
93+ } ,
94+ false
95+ ) ;
96+ addReactive (
97+ state ,
98+ 'height' ,
99+ options . height ,
100+ ( height ) => {
101+ options . onHeightChange ?.( height ) ;
102+
103+ container . style . width = height + 'px' ;
104+ draw ( engine . __state . value ) ;
105+ } ,
106+ false
107+ ) ;
89108
90109 Object . freeze ( state ) ;
91110
92- const engine = createDraggable ( container , {
93- ...options ,
94- onValueChange ( v ) {
95- options . onValueChange ?.( v ) ;
96- draw ( v ) ;
97- }
98- } ) as ImageKnobApi ;
99-
100111 container . style . width = options . width + 'px' ;
101112 container . style . height = options . height + 'px' ;
102113
@@ -111,10 +122,10 @@ export function createImageKnob<E extends HTMLElement>(
111122 }
112123 } ) ;
113124
114- engine . setSrc = ( v ) => state . srcSilent ( v ) ;
115- engine . setNumberOfFrames = ( v ) => state . numberOfFramesSilent ( v ) ;
116- engine . setWidth = ( v ) => state . widthSilent ( v ) ;
117- engine . setHeight = ( v ) => state . heightSilent ( v ) ;
125+ engine . setSrc = ( v ) => ( state . src = v ) ;
126+ engine . setNumberOfFrames = ( v ) => ( state . numberOfFrames = v ) ;
127+ engine . setWidth = ( v ) => ( state . width = v ) ;
128+ engine . setHeight = ( v ) => ( state . height = v ) ;
118129
119130 return engine ;
120131}
0 commit comments