1313 * limitations under the License.
1414 */
1515
16+ import { makeArr , makeMap , serializeError } from "./app_utils.js" ;
1617import { createActionsMap } from "./common.js" ;
1718import { PDFObject } from "./pdf_object.js" ;
1819import { PrintParams } from "./print_params.js" ;
19- import { serializeError } from "./app_utils.js" ;
2020import { ZoomType } from "./constants.js" ;
2121
2222const DOC_EXTERNAL = false ;
@@ -32,6 +32,10 @@ class InfoProxyHandler {
3232}
3333
3434class Doc extends PDFObject {
35+ #pageActions = null ;
36+
37+ #otherPageActions = null ;
38+
3539 constructor ( data ) {
3640 super ( data ) ;
3741
@@ -96,11 +100,9 @@ class Doc extends PDFObject {
96100 this . _zoom = data . zoom || 100 ;
97101 this . _actions = createActionsMap ( data . actions ) ;
98102 this . _globalEval = data . globalEval ;
99- this . _pageActions = null ;
100103 this . _userActivation = false ;
101104 this . _disablePrinting = false ;
102105 this . _disableSaving = false ;
103- this . _otherPageActions = null ;
104106 }
105107
106108 _initActions ( ) {
@@ -170,14 +172,14 @@ class Doc extends PDFObject {
170172
171173 _dispatchPageEvent ( name , actions , pageNumber ) {
172174 if ( name === "PageOpen" ) {
173- this . _pageActions || = new Map ( ) ;
174- if ( ! this . _pageActions . has ( pageNumber ) ) {
175- this . _pageActions . set ( pageNumber , createActionsMap ( actions ) ) ;
175+ this . #pageActions ?? = new Map ( ) ;
176+ if ( ! this . #pageActions . has ( pageNumber ) ) {
177+ this . #pageActions . set ( pageNumber , createActionsMap ( actions ) ) ;
176178 }
177179 this . _pageNum = pageNumber - 1 ;
178180 }
179181
180- for ( const acts of [ this . _pageActions , this . _otherPageActions ] ) {
182+ for ( const acts of [ this . #pageActions , this . #otherPageActions ] ) {
181183 actions = acts ?. get ( pageNumber ) ?. get ( name ) ;
182184 if ( actions ) {
183185 for ( const action of actions ) {
@@ -212,27 +214,16 @@ class Doc extends PDFObject {
212214 const po = field . obj . _actions . get ( "PageOpen" ) ;
213215 const pc = field . obj . _actions . get ( "PageClose" ) ;
214216 if ( po || pc ) {
215- this . _otherPageActions ||= new Map ( ) ;
216- let actions = this . _otherPageActions . get ( field . obj . _page + 1 ) ;
217- if ( ! actions ) {
218- actions = new Map ( ) ;
219- this . _otherPageActions . set ( field . obj . _page + 1 , actions ) ;
220- }
217+ this . #otherPageActions ??= new Map ( ) ;
218+ const actions = this . #otherPageActions. getOrInsertComputed (
219+ field . obj . _page + 1 ,
220+ makeMap
221+ ) ;
221222 if ( po ) {
222- let poActions = actions . get ( "PageOpen" ) ;
223- if ( ! poActions ) {
224- poActions = [ ] ;
225- actions . set ( "PageOpen" , poActions ) ;
226- }
227- poActions . push ( ...po ) ;
223+ actions . getOrInsertComputed ( "PageOpen" , makeArr ) . push ( ...po ) ;
228224 }
229225 if ( pc ) {
230- let pcActions = actions . get ( "PageClose" ) ;
231- if ( ! pcActions ) {
232- pcActions = [ ] ;
233- actions . set ( "PageClose" , pcActions ) ;
234- }
235- pcActions . push ( ...pc ) ;
226+ actions . getOrInsertComputed ( "PageClose" , makeArr ) . push ( ...pc ) ;
236227 }
237228 }
238229 }
0 commit comments