@@ -36,6 +36,7 @@ export async function setUrl(id, url) {
3636
3737 const { options } = pdf ;
3838 options . url = url ;
39+ options . data = null ;
3940 await loadPdf ( pdf ) ;
4041}
4142
@@ -47,31 +48,12 @@ export async function setData(id, data) {
4748 return ;
4849 }
4950
50- const objectUrl = createObjectURLFromByte ( data ) ;
51- pdf . objectUrl = objectUrl ;
52-
5351 const { options } = pdf ;
54- options . url = objectUrl ;
55- options . data = null ;
52+ options . url = null ;
53+ options . data = data ; ;
5654 await loadPdf ( pdf ) ;
5755}
5856
59- const createObjectURLFromBase64 = base64Data => {
60- const binaryString = atob ( base64Data ) ;
61- const bytes = new Uint8Array ( binaryString . length ) ;
62- for ( let i = 0 ; i < binaryString . length ; i ++ ) {
63- bytes [ i ] = binaryString . charCodeAt ( i ) ;
64- }
65-
66- const blob = new Blob ( [ bytes ] , { type : 'application/pdf' } ) ;
67- return URL . createObjectURL ( blob ) ;
68- }
69-
70- const createObjectURLFromByte = bytes => {
71- const blob = new Blob ( [ bytes ] , { type : 'application/pdf' } ) ;
72- return URL . createObjectURL ( blob ) ;
73- }
74-
7557export function setScaleValue ( id , value ) {
7658 const { pdfViewer } = Data . get ( id ) ;
7759 if ( pdfViewer ) {
@@ -139,10 +121,7 @@ const loadPdf = async pdf => {
139121
140122 if ( bar ) {
141123 const val = loaded / total * 100 ;
142- if ( val > 100 ) {
143- val = 100 ;
144- }
145- bar . style . setProperty ( '--bb-view-progress-val' , `${ val } %` ) ;
124+ bar . style . setProperty ( '--bb-view-progress-val' , `${ Math . min ( val , 100 ) } %` ) ;
146125
147126 if ( progressHandler === null ) {
148127 progressHandler = setTimeout ( ( ) => {
@@ -185,10 +164,7 @@ const loadPdf = async pdf => {
185164}
186165
187166const disposePdf = pdf => {
188- const { el, observer, loadingTask, objectUrl } = pdf ;
189- if ( objectUrl ) {
190- URL . revokeObjectURL ( objectUrl ) ;
191- }
167+ const { el, observer, loadingTask } = pdf ;
192168
193169 if ( observer ) {
194170 observer . disconnect ( ) ;
@@ -203,7 +179,10 @@ const disposePdf = pdf => {
203179 const viewContainer = el . querySelector ( ".bb-view-container" ) ;
204180 if ( viewContainer ) {
205181 [ ...viewContainer . children ] . forEach ( i => {
206- if ( ! i . classList . contains ( "pdfViewer" ) ) {
182+ if ( i . classList . contains ( "pdfViewer" ) ) {
183+ i . innerHTML = "" ;
184+ }
185+ else {
207186 i . remove ( ) ;
208187 }
209188 } )
0 commit comments