import PDFDict from 'src/core/objects/PDFDict' ; import PDFName from 'src/core/objects/PDFName' ; import PDFRef from 'src/core/objects/PDFRef' ; import PDFAcroField from 'src/core/acroform/PDFAcroField' ; import PDFWidgetAnnotation from 'src/core/annotation/PDFWidgetAnnotation' ; import { IndexOutOfBoundsError } from 'src/core/errors' ; class PDFAcroTerminal extends PDFAcroField { static fromDict = ( dict , ref ) => new PDFAcroTerminal ( dict , ref ) ; FT ( ) { const nameOrRef = this . getInheritableAttribute ( PDFName . of ( 'FT' ) ) ; return this . dict . context . lookup ( nameOrRef , PDFName ) ; } getWidgets ( ) { const kidDicts = this . Kids ( ) ; if ( ! kidDicts ) return [ PDFWidgetAnnotation . fromDict ( this . dict ) ] ; const widgets = new Array < PDFWidgetAnnotation > ( kidDicts . size ( ) ) ; for ( let idx = 0 , len = kidDicts . size ( ) ; idx < len ; idx ++ ) { const dict = kidDicts . lookup ( idx , PDFDict ) ; widgets [ idx ] = PDFWidgetAnnotation . fromDict ( dict ) ; } return widgets ; } addWidget ( ref ) { const { Kids } = this . normalizedEntries ( ) ; Kids . push ( ref ) ; } removeWidget ( idx ) { const kidDicts = this . Kids ( ) ; if ( ! kidDicts ) { if ( idx !== 0 ) throw new IndexOutOfBoundsError ( idx , 0 , 0 ) ; this . setKids ( [ ] ) ; } else { if ( idx < 0 || idx > kidDicts . size ( ) ) { throw new IndexOutOfBoundsError ( idx , 0 , kidDicts . size ( ) ) ; } kidDicts . remove ( idx ) ; } } normalizedEntries ( ) { let Kids = this . Kids ( ) ; if ( ! Kids ) { Kids = this . dict . context . obj ( [ this . ref ] ) ; this . dict . set ( PDFName . of ( 'Kids' ) , Kids ) ; } return { Kids } ; } } export default PDFAcroTerminal ;