import Embeddable from 'src/api/Embeddable' ; import PDFDocument from 'src/api/PDFDocument' ; import { PDFPageEmbedder , PDFRef } from 'src/core' ; import { assertIs } from 'src/utils' ; /**
 * Represents a PDF page that has been embedded in a [[PDFDocument]].
 */ export default class PDFEmbeddedPage implements Embeddable { param ref param doc param embedder static of = ( ref , doc , embedder ) => new PDFEmbeddedPage ( ref , doc , embedder ) ; /** The unique reference assigned to this embedded page within the document. */ readonly ref : PDFRef ; /** The document to which this embedded page belongs. */ readonly doc : PDFDocument ; /** The width of this page in pixels. */ readonly width : number ; /** The height of this page in pixels. */ readonly height : number ; private alreadyEmbedded = false ; private readonly embedder : PDFPageEmbedder ; private constructor ( ref , doc , embedder ) { assertIs ( ref , 'ref' , [ [ PDFRef , 'PDFRef' ] ] ) ; assertIs ( doc , 'doc' , [ [ PDFDocument , 'PDFDocument' ] ] ) ; assertIs ( embedder , 'embedder' , [ [ PDFPageEmbedder , 'PDFPageEmbedder' ] ] ) ; this . ref = ref ; this . doc = doc ; this . width = embedder . width ; this . height = embedder . height ; this . embedder = embedder ; } param factor returns scale ( factor ) { assertIs ( factor , 'factor' , [ 'number' ] ) ; return { width : this . width * factor , height : this . height * factor } ; } returns size ( ) { return this . scale ( 1 ) ; } returns async embed ( ) { if ( ! this . alreadyEmbedded ) { await this . embedder . embedIntoContext ( this . doc . context , this . ref ) ; this . alreadyEmbedded = true ; } } }