@@ -131,44 +131,59 @@ class PDFLinkService {
131
131
return this . pdfDocument ? this . pdfViewer . isInPresentationMode : false ;
132
132
}
133
133
134
- #goToDestinationHelper( rawDest , namedDest = null , explicitDest ) {
134
+ /**
135
+ * This method will, when available, also update the browser history.
136
+ *
137
+ * @param {string|Array } dest - The named, or explicit, PDF destination.
138
+ */
139
+ async goToDestination ( dest ) {
140
+ if ( ! this . pdfDocument ) {
141
+ return ;
142
+ }
143
+ let namedDest , explicitDest , pageNumber ;
144
+ if ( typeof dest === "string" ) {
145
+ namedDest = dest ;
146
+ explicitDest = await this . pdfDocument . getDestination ( dest ) ;
147
+ } else {
148
+ namedDest = null ;
149
+ explicitDest = await dest ;
150
+ }
151
+ if ( ! Array . isArray ( explicitDest ) ) {
152
+ console . error (
153
+ `goToDestination: "${ explicitDest } " is not a valid destination array, for dest="${ dest } ".`
154
+ ) ;
155
+ return ;
156
+ }
135
157
// Dest array looks like that: <page-ref> </XYZ|/FitXXX> <args..>
136
- const destRef = explicitDest [ 0 ] ;
137
- let pageNumber ;
158
+ const [ destRef ] = explicitDest ;
138
159
139
160
if ( typeof destRef === "object" && destRef !== null ) {
140
161
pageNumber = this . _cachedPageNumber ( destRef ) ;
141
162
142
163
if ( ! pageNumber ) {
143
164
// Fetch the page reference if it's not yet available. This could
144
165
// only occur during loading, before all pages have been resolved.
145
- this . pdfDocument
146
- . getPageIndex ( destRef )
147
- . then ( pageIndex => {
148
- this . cachePageRef ( pageIndex + 1 , destRef ) ;
149
- this . #goToDestinationHelper( rawDest , namedDest , explicitDest ) ;
150
- } )
151
- . catch ( ( ) => {
152
- console . error (
153
- `PDFLinkService.#goToDestinationHelper: "${ destRef } " is not ` +
154
- `a valid page reference, for dest="${ rawDest } ".`
155
- ) ;
156
- } ) ;
157
- return ;
166
+ try {
167
+ pageNumber = ( await this . pdfDocument . getPageIndex ( destRef ) ) + 1 ;
168
+ this . cachePageRef ( pageNumber , destRef ) ;
169
+ } catch {
170
+ console . error (
171
+ `goToDestination: "${ destRef } " is not a valid page reference, for dest="${ dest } ".`
172
+ ) ;
173
+ return ;
174
+ }
158
175
}
159
176
} else if ( Number . isInteger ( destRef ) ) {
160
177
pageNumber = destRef + 1 ;
161
178
} else {
162
179
console . error (
163
- `PDFLinkService.#goToDestinationHelper: "${ destRef } " is not ` +
164
- `a valid destination reference, for dest="${ rawDest } ".`
180
+ `goToDestination: "${ destRef } " is not a valid destination reference, for dest="${ dest } ".`
165
181
) ;
166
182
return ;
167
183
}
168
184
if ( ! pageNumber || pageNumber < 1 || pageNumber > this . pagesCount ) {
169
185
console . error (
170
- `PDFLinkService.#goToDestinationHelper: "${ pageNumber } " is not ` +
171
- `a valid page number, for dest="${ rawDest } ".`
186
+ `goToDestination: "${ pageNumber } " is not a valid page number, for dest="${ dest } ".`
172
187
) ;
173
188
return ;
174
189
}
@@ -187,33 +202,6 @@ class PDFLinkService {
187
202
} ) ;
188
203
}
189
204
190
- /**
191
- * This method will, when available, also update the browser history.
192
- *
193
- * @param {string|Array } dest - The named, or explicit, PDF destination.
194
- */
195
- async goToDestination ( dest ) {
196
- if ( ! this . pdfDocument ) {
197
- return ;
198
- }
199
- let namedDest , explicitDest ;
200
- if ( typeof dest === "string" ) {
201
- namedDest = dest ;
202
- explicitDest = await this . pdfDocument . getDestination ( dest ) ;
203
- } else {
204
- namedDest = null ;
205
- explicitDest = await dest ;
206
- }
207
- if ( ! Array . isArray ( explicitDest ) ) {
208
- console . error (
209
- `PDFLinkService.goToDestination: "${ explicitDest } " is not ` +
210
- `a valid destination array, for dest="${ dest } ".`
211
- ) ;
212
- return ;
213
- }
214
- this . #goToDestinationHelper( dest , namedDest , explicitDest ) ;
215
- }
216
-
217
205
/**
218
206
* This method will, when available, also update the browser history.
219
207
*
0 commit comments