@@ -9,7 +9,27 @@ export default class Inserter {
99 this . main . fitImage ( img ) ;
1010 } ,
1111 } ,
12- extend_down : { } ,
12+ extend_down : {
13+ handle : ( img ) => {
14+ this . tmpImg = img ;
15+ const oldH = this . main . size . h ;
16+ const oldW = this . main . size . w ;
17+ const newH = oldH + img . naturalHeight ;
18+ const newW = Math . max ( oldW , img . naturalWidth ) ;
19+ const tmpData = this . ctx . getImageData ( 0 , 0 , this . main . size . w , this . main . size . h ) ;
20+ this . main . resize ( newW , newH ) ;
21+ this . main . clearBackground ( ) ;
22+ this . ctx . putImageData ( tmpData , 0 , 0 ) ;
23+ this . main . adjustSizeFull ( ) ;
24+ this . worklog . captureState ( ) ;
25+ if ( img . naturalWidth < oldW ) {
26+ const offset = Math . round ( ( oldW - img . naturalWidth ) / 2 ) ;
27+ this . main . select . placeAt ( offset , oldH , offset , 0 , img ) ;
28+ } else {
29+ this . main . select . placeAt ( 0 , oldH , 0 , 0 , img ) ;
30+ }
31+ } ,
32+ } ,
1333 extend_right : { } ,
1434 over : { } ,
1535 } ;
@@ -18,8 +38,9 @@ export default class Inserter {
1838 init ( main ) {
1939 this . ctx = main . ctx ;
2040 this . main = main ;
21- this . el = main . toolContainer ;
22- this . selector = this . el . querySelector ( '.ptro-paster-select' ) ;
41+ this . worklog = main . worklog ;
42+ this . selector = main . wrapper . querySelector ( '.ptro-paster-select-wrapper' ) ;
43+ this . selector . setAttribute ( 'hidden' , '' ) ;
2344 this . img = null ;
2445 Object . keys ( this . pasteOptions ) . forEach ( ( k ) => {
2546 const o = this . pasteOptions [ k ] ;
@@ -29,13 +50,18 @@ export default class Inserter {
2950 } else {
3051 o . handle ( this . img ) ;
3152 }
32- this . selector . style . display = 'none' ;
53+ this . selector . setAttribute ( 'hidden' , '' ) ;
3354 } ;
3455 } ) ;
3556 this . loading = false ;
3657 this . doLater = null ;
3758 }
3859
60+ insert ( x , y , w , h ) {
61+ console . log ( "inserting " , this . tmpImg , x , y , w , h ) ;
62+ this . main . ctx . drawImage ( this . tmpImg , x , y , w , h ) ;
63+ }
64+
3965 loaded ( img ) {
4066 this . img = img ;
4167 this . loading = false ;
@@ -59,7 +85,7 @@ export default class Inserter {
5985 this . startLoading ( ) ;
6086 img . src = source ;
6187 if ( ! empty ) {
62- this . selector . style . display = 'inline-block' ;
88+ this . selector . removeAttribute ( 'hidden' ) ;
6389 }
6490 }
6591
@@ -86,7 +112,7 @@ export default class Inserter {
86112 }
87113 }
88114
89- code ( ) {
115+ html ( ) {
90116 let buttons = '' ;
91117 Object . keys ( this . pasteOptions ) . forEach ( ( k ) => {
92118 const o = this . pasteOptions [ k ] ;
@@ -96,8 +122,8 @@ export default class Inserter {
96122 `<div>${ tr ( `pasteOptions.${ k } ` ) } </div>` +
97123 '</button>' ;
98124 } ) ;
99- return `<div class="ptro-paster-select" style="display: none "><div class="ptro-in">${
125+ return `<div class="ptro-paster-select-wrapper" hidden><div class="ptro-paster-select "><div class="ptro-in">${
100126 buttons
101- } </div></div>`;
127+ } </div></div></div> `;
102128 }
103129}
0 commit comments