@@ -21,9 +21,9 @@ export async function init(id, invoke, options) {
2121 }
2222
2323 const pdfViewer = await loadPdf ( el , invoke , options ) ;
24- setObserver ( el ) ;
24+ const observer = setObserver ( el ) ;
2525
26- Data . set ( id , { el, pdfViewer } ) ;
26+ Data . set ( id , { el, pdfViewer, observer } ) ;
2727}
2828
2929export function setScaleValue ( id , value ) {
@@ -94,11 +94,74 @@ const loadPdf = async (el, invoke, options) => {
9494}
9595
9696const setObserver = el => {
97+ const title = el . querySelector ( ".bb-view-title" ) ;
98+ const subject = el . querySelector ( ".bb-view-subject" ) ;
99+ const groupPage = el . querySelector ( ".bb-view-group-page" ) ;
100+ const groupScale = el . querySelector ( ".bb-view-group-scale" ) ;
101+ const groupRotate = el . querySelector ( ".bb-view-group-rotate" ) ;
102+ const controls = el . querySelector ( ".bb-view-controls" ) ;
103+
104+ el . widths = [ subject . offsetWidth , groupRotate . offsetWidth , groupScale . offsetWidth , groupPage . offsetWidth , controls . offsetWidth ] ;
105+
106+ const increaseSpace = toolbar => {
107+ if ( controls . classList . contains ( 'd-none' ) ) {
108+ if ( title . offsetWidth + el . widths [ 4 ] + groupPage . offsetWidth + groupScale . offsetWidth + groupRotate . offsetWidth + controls . offsetWidth < toolbar . offsetWidth ) {
109+ controls . classList . remove ( "d-none" ) ;
110+ }
111+ }
112+ else if ( groupPage . classList . contains ( 'd-none' ) ) {
113+ if ( title . offsetWidth + el . widths [ 3 ] + groupPage . offsetWidth + groupScale . offsetWidth + groupRotate . offsetWidth + controls . offsetWidth < toolbar . offsetWidth ) {
114+ groupPage . classList . remove ( "d-none" ) ;
115+ }
116+ }
117+ else if ( groupScale . classList . contains ( 'd-none' ) ) {
118+ if ( title . offsetWidth + el . widths [ 2 ] + groupPage . offsetWidth + groupScale . offsetWidth + groupRotate . offsetWidth + controls . offsetWidth < toolbar . offsetWidth ) {
119+ groupScale . classList . remove ( "d-none" ) ;
120+ }
121+ }
122+ else if ( groupRotate . classList . contains ( 'd-none' ) ) {
123+ if ( title . offsetWidth + el . widths [ 1 ] + groupPage . offsetWidth + groupScale . offsetWidth + groupRotate . offsetWidth + controls . offsetWidth < toolbar . offsetWidth ) {
124+ groupRotate . classList . remove ( "d-none" ) ;
125+ }
126+ }
127+ else if ( subject . classList . contains ( "d-none" ) ) {
128+ if ( title . offsetWidth + el . widths [ 0 ] + groupPage . offsetWidth + groupScale . offsetWidth + groupRotate . offsetWidth + controls . offsetWidth < toolbar . offsetWidth ) {
129+ subject . classList . remove ( "d-none" ) ;
130+ }
131+ }
132+ }
133+ const decreaseSpace = toolbar => {
134+ while ( title . offsetWidth + groupPage . offsetWidth + groupScale . offsetWidth + groupRotate . offsetWidth + controls . offsetWidth > toolbar . offsetWidth ) {
135+ if ( subject . classList . contains ( "d-none" ) === false ) {
136+ subject . classList . add ( "d-none" ) ;
137+ }
138+ else if ( groupRotate . classList . contains ( 'd-none' ) === false ) {
139+ groupRotate . classList . add ( "d-none" ) ;
140+ }
141+ else if ( groupScale . classList . contains ( 'd-none' ) === false ) {
142+ groupScale . classList . add ( "d-none" ) ;
143+ }
144+ else if ( groupPage . classList . contains ( 'd-none' ) === false ) {
145+ groupPage . classList . add ( "d-none" ) ;
146+ }
147+ else if ( controls . classList . contains ( 'd-none' ) === false ) {
148+ controls . classList . add ( "d-none" ) ;
149+ }
150+ }
151+ }
152+
97153 const observer = new ResizeObserver ( entries => {
98- console . log ( entries ) ;
154+ const toolbar = el . querySelector ( ".bb-view-toolbar" ) ;
155+ if ( toolbar === null ) {
156+ return ;
157+ }
158+
159+ decreaseSpace ( toolbar ) ;
160+ increaseSpace ( toolbar ) ;
99161 } ) ;
100162
101163 observer . observe ( el ) ;
164+ return observer ;
102165}
103166
104167const addEventListener = ( el , pdfViewer , eventBus , invoke , options ) => {
@@ -318,9 +381,14 @@ const printPdf = url => {
318381}
319382
320383export function dispose ( id ) {
384+ const { el, observer } = Data . get ( id ) ;
321385 Data . remove ( id ) ;
322386
323- const el = document . getElementById ( id ) ;
387+ if ( observer ) {
388+ observer . disconnect ( ) ;
389+ observer = null ;
390+ }
391+
324392 if ( el ) {
325393 const minus = el . querySelector ( ".bb-page-minus" ) ;
326394 const plus = el . querySelector ( ".bb-page-plus" ) ;
0 commit comments