pdf.js 502 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. (function webpackUniversalModuleDefinition(root, factory) {
  16. if(typeof exports === 'object' && typeof module === 'object')
  17. module.exports = factory();
  18. else if(typeof define === 'function' && define.amd)
  19. define("pdfjs-dist/build/pdf", [], factory);
  20. else if(typeof exports === 'object')
  21. exports["pdfjs-dist/build/pdf"] = factory();
  22. else
  23. root["pdfjs-dist/build/pdf"] = root.pdfjsDistBuildPdf = factory();
  24. })(this, function() {
  25. return /******/ (function(modules) { // webpackBootstrap
  26. /******/ // The module cache
  27. /******/ var installedModules = {};
  28. /******/
  29. /******/ // The require function
  30. /******/ function __w_pdfjs_require__(moduleId) {
  31. /******/
  32. /******/ // Check if module is in cache
  33. /******/ if(installedModules[moduleId]) {
  34. /******/ return installedModules[moduleId].exports;
  35. /******/ }
  36. /******/ // Create a new module (and put it into the cache)
  37. /******/ var module = installedModules[moduleId] = {
  38. /******/ i: moduleId,
  39. /******/ l: false,
  40. /******/ exports: {}
  41. /******/ };
  42. /******/
  43. /******/ // Execute the module function
  44. /******/ modules[moduleId].call(module.exports, module, module.exports, __w_pdfjs_require__);
  45. /******/
  46. /******/ // Flag the module as loaded
  47. /******/ module.l = true;
  48. /******/
  49. /******/ // Return the exports of the module
  50. /******/ return module.exports;
  51. /******/ }
  52. /******/
  53. /******/
  54. /******/ // expose the modules object (__webpack_modules__)
  55. /******/ __w_pdfjs_require__.m = modules;
  56. /******/
  57. /******/ // expose the module cache
  58. /******/ __w_pdfjs_require__.c = installedModules;
  59. /******/
  60. /******/ // identity function for calling harmony imports with the correct context
  61. /******/ __w_pdfjs_require__.i = function(value) { return value; };
  62. /******/
  63. /******/ // define getter function for harmony exports
  64. /******/ __w_pdfjs_require__.d = function(exports, name, getter) {
  65. /******/ if(!__w_pdfjs_require__.o(exports, name)) {
  66. /******/ Object.defineProperty(exports, name, {
  67. /******/ configurable: false,
  68. /******/ enumerable: true,
  69. /******/ get: getter
  70. /******/ });
  71. /******/ }
  72. /******/ };
  73. /******/
  74. /******/ // getDefaultExport function for compatibility with non-harmony modules
  75. /******/ __w_pdfjs_require__.n = function(module) {
  76. /******/ var getter = module && module.__esModule ?
  77. /******/ function getDefault() { return module['default']; } :
  78. /******/ function getModuleExports() { return module; };
  79. /******/ __w_pdfjs_require__.d(getter, 'a', getter);
  80. /******/ return getter;
  81. /******/ };
  82. /******/
  83. /******/ // Object.prototype.hasOwnProperty.call
  84. /******/ __w_pdfjs_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  85. /******/
  86. /******/ // __webpack_public_path__
  87. /******/ __w_pdfjs_require__.p = "";
  88. /******/
  89. /******/ // Load entry module and return exports
  90. /******/ return __w_pdfjs_require__(__w_pdfjs_require__.s = 15);
  91. /******/ })
  92. /************************************************************************/
  93. /******/ ([
  94. /* 0 */
  95. /***/ (function(module, exports, __w_pdfjs_require__) {
  96. "use strict";
  97. Object.defineProperty(exports, "__esModule", {
  98. value: true
  99. });
  100. exports.unreachable = exports.warn = exports.utf8StringToString = exports.stringToUTF8String = exports.stringToPDFString = exports.stringToBytes = exports.string32 = exports.shadow = exports.setVerbosityLevel = exports.ReadableStream = exports.removeNullCharacters = exports.readUint32 = exports.readUint16 = exports.readInt8 = exports.log2 = exports.loadJpegStream = exports.isEvalSupported = exports.isLittleEndian = exports.createValidAbsoluteUrl = exports.isSameOrigin = exports.isNodeJS = exports.isSpace = exports.isString = exports.isNum = exports.isInt = exports.isEmptyObj = exports.isBool = exports.isArrayBuffer = exports.isArray = exports.info = exports.globalScope = exports.getVerbosityLevel = exports.getLookupTableFactory = exports.deprecated = exports.createObjectURL = exports.createPromiseCapability = exports.createBlob = exports.bytesToString = exports.assert = exports.arraysToBytes = exports.arrayByteLength = exports.FormatError = exports.XRefParseException = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.StatTimer = exports.PasswordResponses = exports.PasswordException = exports.PageViewport = exports.NotImplementedException = exports.NativeImageDecoding = exports.MissingPDFException = exports.MissingDataException = exports.MessageHandler = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VERBOSITY_LEVELS = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = undefined;
  101. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  102. __w_pdfjs_require__(16);
  103. var _streams_polyfill = __w_pdfjs_require__(17);
  104. var globalScope = typeof window !== 'undefined' && window.Math === Math ? window : typeof global !== 'undefined' && global.Math === Math ? global : typeof self !== 'undefined' && self.Math === Math ? self : undefined;
  105. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  106. var NativeImageDecoding = {
  107. NONE: 'none',
  108. DECODE: 'decode',
  109. DISPLAY: 'display'
  110. };
  111. var TextRenderingMode = {
  112. FILL: 0,
  113. STROKE: 1,
  114. FILL_STROKE: 2,
  115. INVISIBLE: 3,
  116. FILL_ADD_TO_PATH: 4,
  117. STROKE_ADD_TO_PATH: 5,
  118. FILL_STROKE_ADD_TO_PATH: 6,
  119. ADD_TO_PATH: 7,
  120. FILL_STROKE_MASK: 3,
  121. ADD_TO_PATH_FLAG: 4
  122. };
  123. var ImageKind = {
  124. GRAYSCALE_1BPP: 1,
  125. RGB_24BPP: 2,
  126. RGBA_32BPP: 3
  127. };
  128. var AnnotationType = {
  129. TEXT: 1,
  130. LINK: 2,
  131. FREETEXT: 3,
  132. LINE: 4,
  133. SQUARE: 5,
  134. CIRCLE: 6,
  135. POLYGON: 7,
  136. POLYLINE: 8,
  137. HIGHLIGHT: 9,
  138. UNDERLINE: 10,
  139. SQUIGGLY: 11,
  140. STRIKEOUT: 12,
  141. STAMP: 13,
  142. CARET: 14,
  143. INK: 15,
  144. POPUP: 16,
  145. FILEATTACHMENT: 17,
  146. SOUND: 18,
  147. MOVIE: 19,
  148. WIDGET: 20,
  149. SCREEN: 21,
  150. PRINTERMARK: 22,
  151. TRAPNET: 23,
  152. WATERMARK: 24,
  153. THREED: 25,
  154. REDACT: 26
  155. };
  156. var AnnotationFlag = {
  157. INVISIBLE: 0x01,
  158. HIDDEN: 0x02,
  159. PRINT: 0x04,
  160. NOZOOM: 0x08,
  161. NOROTATE: 0x10,
  162. NOVIEW: 0x20,
  163. READONLY: 0x40,
  164. LOCKED: 0x80,
  165. TOGGLENOVIEW: 0x100,
  166. LOCKEDCONTENTS: 0x200
  167. };
  168. var AnnotationFieldFlag = {
  169. READONLY: 0x0000001,
  170. REQUIRED: 0x0000002,
  171. NOEXPORT: 0x0000004,
  172. MULTILINE: 0x0001000,
  173. PASSWORD: 0x0002000,
  174. NOTOGGLETOOFF: 0x0004000,
  175. RADIO: 0x0008000,
  176. PUSHBUTTON: 0x0010000,
  177. COMBO: 0x0020000,
  178. EDIT: 0x0040000,
  179. SORT: 0x0080000,
  180. FILESELECT: 0x0100000,
  181. MULTISELECT: 0x0200000,
  182. DONOTSPELLCHECK: 0x0400000,
  183. DONOTSCROLL: 0x0800000,
  184. COMB: 0x1000000,
  185. RICHTEXT: 0x2000000,
  186. RADIOSINUNISON: 0x2000000,
  187. COMMITONSELCHANGE: 0x4000000
  188. };
  189. var AnnotationBorderStyleType = {
  190. SOLID: 1,
  191. DASHED: 2,
  192. BEVELED: 3,
  193. INSET: 4,
  194. UNDERLINE: 5
  195. };
  196. var StreamType = {
  197. UNKNOWN: 0,
  198. FLATE: 1,
  199. LZW: 2,
  200. DCT: 3,
  201. JPX: 4,
  202. JBIG: 5,
  203. A85: 6,
  204. AHX: 7,
  205. CCF: 8,
  206. RL: 9
  207. };
  208. var FontType = {
  209. UNKNOWN: 0,
  210. TYPE1: 1,
  211. TYPE1C: 2,
  212. CIDFONTTYPE0: 3,
  213. CIDFONTTYPE0C: 4,
  214. TRUETYPE: 5,
  215. CIDFONTTYPE2: 6,
  216. TYPE3: 7,
  217. OPENTYPE: 8,
  218. TYPE0: 9,
  219. MMTYPE1: 10
  220. };
  221. var VERBOSITY_LEVELS = {
  222. errors: 0,
  223. warnings: 1,
  224. infos: 5
  225. };
  226. var CMapCompressionType = {
  227. NONE: 0,
  228. BINARY: 1,
  229. STREAM: 2
  230. };
  231. var OPS = {
  232. dependency: 1,
  233. setLineWidth: 2,
  234. setLineCap: 3,
  235. setLineJoin: 4,
  236. setMiterLimit: 5,
  237. setDash: 6,
  238. setRenderingIntent: 7,
  239. setFlatness: 8,
  240. setGState: 9,
  241. save: 10,
  242. restore: 11,
  243. transform: 12,
  244. moveTo: 13,
  245. lineTo: 14,
  246. curveTo: 15,
  247. curveTo2: 16,
  248. curveTo3: 17,
  249. closePath: 18,
  250. rectangle: 19,
  251. stroke: 20,
  252. closeStroke: 21,
  253. fill: 22,
  254. eoFill: 23,
  255. fillStroke: 24,
  256. eoFillStroke: 25,
  257. closeFillStroke: 26,
  258. closeEOFillStroke: 27,
  259. endPath: 28,
  260. clip: 29,
  261. eoClip: 30,
  262. beginText: 31,
  263. endText: 32,
  264. setCharSpacing: 33,
  265. setWordSpacing: 34,
  266. setHScale: 35,
  267. setLeading: 36,
  268. setFont: 37,
  269. setTextRenderingMode: 38,
  270. setTextRise: 39,
  271. moveText: 40,
  272. setLeadingMoveText: 41,
  273. setTextMatrix: 42,
  274. nextLine: 43,
  275. showText: 44,
  276. showSpacedText: 45,
  277. nextLineShowText: 46,
  278. nextLineSetSpacingShowText: 47,
  279. setCharWidth: 48,
  280. setCharWidthAndBounds: 49,
  281. setStrokeColorSpace: 50,
  282. setFillColorSpace: 51,
  283. setStrokeColor: 52,
  284. setStrokeColorN: 53,
  285. setFillColor: 54,
  286. setFillColorN: 55,
  287. setStrokeGray: 56,
  288. setFillGray: 57,
  289. setStrokeRGBColor: 58,
  290. setFillRGBColor: 59,
  291. setStrokeCMYKColor: 60,
  292. setFillCMYKColor: 61,
  293. shadingFill: 62,
  294. beginInlineImage: 63,
  295. beginImageData: 64,
  296. endInlineImage: 65,
  297. paintXObject: 66,
  298. markPoint: 67,
  299. markPointProps: 68,
  300. beginMarkedContent: 69,
  301. beginMarkedContentProps: 70,
  302. endMarkedContent: 71,
  303. beginCompat: 72,
  304. endCompat: 73,
  305. paintFormXObjectBegin: 74,
  306. paintFormXObjectEnd: 75,
  307. beginGroup: 76,
  308. endGroup: 77,
  309. beginAnnotations: 78,
  310. endAnnotations: 79,
  311. beginAnnotation: 80,
  312. endAnnotation: 81,
  313. paintJpegXObject: 82,
  314. paintImageMaskXObject: 83,
  315. paintImageMaskXObjectGroup: 84,
  316. paintImageXObject: 85,
  317. paintInlineImageXObject: 86,
  318. paintInlineImageXObjectGroup: 87,
  319. paintImageXObjectRepeat: 88,
  320. paintImageMaskXObjectRepeat: 89,
  321. paintSolidColorImageMask: 90,
  322. constructPath: 91
  323. };
  324. var verbosity = VERBOSITY_LEVELS.warnings;
  325. function setVerbosityLevel(level) {
  326. verbosity = level;
  327. }
  328. function getVerbosityLevel() {
  329. return verbosity;
  330. }
  331. function info(msg) {
  332. if (verbosity >= VERBOSITY_LEVELS.infos) {
  333. console.log('Info: ' + msg);
  334. }
  335. }
  336. function warn(msg) {
  337. if (verbosity >= VERBOSITY_LEVELS.warnings) {
  338. console.log('Warning: ' + msg);
  339. }
  340. }
  341. function deprecated(details) {
  342. console.log('Deprecated API usage: ' + details);
  343. }
  344. function unreachable(msg) {
  345. throw new Error(msg);
  346. }
  347. function assert(cond, msg) {
  348. if (!cond) {
  349. unreachable(msg);
  350. }
  351. }
  352. var UNSUPPORTED_FEATURES = {
  353. unknown: 'unknown',
  354. forms: 'forms',
  355. javaScript: 'javaScript',
  356. smask: 'smask',
  357. shadingPattern: 'shadingPattern',
  358. font: 'font'
  359. };
  360. function isSameOrigin(baseUrl, otherUrl) {
  361. try {
  362. var base = new URL(baseUrl);
  363. if (!base.origin || base.origin === 'null') {
  364. return false;
  365. }
  366. } catch (e) {
  367. return false;
  368. }
  369. var other = new URL(otherUrl, base);
  370. return base.origin === other.origin;
  371. }
  372. function isValidProtocol(url) {
  373. if (!url) {
  374. return false;
  375. }
  376. switch (url.protocol) {
  377. case 'http:':
  378. case 'https:':
  379. case 'ftp:':
  380. case 'mailto:':
  381. case 'tel:':
  382. return true;
  383. default:
  384. return false;
  385. }
  386. }
  387. function createValidAbsoluteUrl(url, baseUrl) {
  388. if (!url) {
  389. return null;
  390. }
  391. try {
  392. var absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  393. if (isValidProtocol(absoluteUrl)) {
  394. return absoluteUrl;
  395. }
  396. } catch (ex) {}
  397. return null;
  398. }
  399. function shadow(obj, prop, value) {
  400. Object.defineProperty(obj, prop, {
  401. value: value,
  402. enumerable: true,
  403. configurable: true,
  404. writable: false
  405. });
  406. return value;
  407. }
  408. function getLookupTableFactory(initializer) {
  409. var lookup;
  410. return function () {
  411. if (initializer) {
  412. lookup = Object.create(null);
  413. initializer(lookup);
  414. initializer = null;
  415. }
  416. return lookup;
  417. };
  418. }
  419. var PasswordResponses = {
  420. NEED_PASSWORD: 1,
  421. INCORRECT_PASSWORD: 2
  422. };
  423. var PasswordException = function PasswordExceptionClosure() {
  424. function PasswordException(msg, code) {
  425. this.name = 'PasswordException';
  426. this.message = msg;
  427. this.code = code;
  428. }
  429. PasswordException.prototype = new Error();
  430. PasswordException.constructor = PasswordException;
  431. return PasswordException;
  432. }();
  433. var UnknownErrorException = function UnknownErrorExceptionClosure() {
  434. function UnknownErrorException(msg, details) {
  435. this.name = 'UnknownErrorException';
  436. this.message = msg;
  437. this.details = details;
  438. }
  439. UnknownErrorException.prototype = new Error();
  440. UnknownErrorException.constructor = UnknownErrorException;
  441. return UnknownErrorException;
  442. }();
  443. var InvalidPDFException = function InvalidPDFExceptionClosure() {
  444. function InvalidPDFException(msg) {
  445. this.name = 'InvalidPDFException';
  446. this.message = msg;
  447. }
  448. InvalidPDFException.prototype = new Error();
  449. InvalidPDFException.constructor = InvalidPDFException;
  450. return InvalidPDFException;
  451. }();
  452. var MissingPDFException = function MissingPDFExceptionClosure() {
  453. function MissingPDFException(msg) {
  454. this.name = 'MissingPDFException';
  455. this.message = msg;
  456. }
  457. MissingPDFException.prototype = new Error();
  458. MissingPDFException.constructor = MissingPDFException;
  459. return MissingPDFException;
  460. }();
  461. var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() {
  462. function UnexpectedResponseException(msg, status) {
  463. this.name = 'UnexpectedResponseException';
  464. this.message = msg;
  465. this.status = status;
  466. }
  467. UnexpectedResponseException.prototype = new Error();
  468. UnexpectedResponseException.constructor = UnexpectedResponseException;
  469. return UnexpectedResponseException;
  470. }();
  471. var NotImplementedException = function NotImplementedExceptionClosure() {
  472. function NotImplementedException(msg) {
  473. this.message = msg;
  474. }
  475. NotImplementedException.prototype = new Error();
  476. NotImplementedException.prototype.name = 'NotImplementedException';
  477. NotImplementedException.constructor = NotImplementedException;
  478. return NotImplementedException;
  479. }();
  480. var MissingDataException = function MissingDataExceptionClosure() {
  481. function MissingDataException(begin, end) {
  482. this.begin = begin;
  483. this.end = end;
  484. this.message = 'Missing data [' + begin + ', ' + end + ')';
  485. }
  486. MissingDataException.prototype = new Error();
  487. MissingDataException.prototype.name = 'MissingDataException';
  488. MissingDataException.constructor = MissingDataException;
  489. return MissingDataException;
  490. }();
  491. var XRefParseException = function XRefParseExceptionClosure() {
  492. function XRefParseException(msg) {
  493. this.message = msg;
  494. }
  495. XRefParseException.prototype = new Error();
  496. XRefParseException.prototype.name = 'XRefParseException';
  497. XRefParseException.constructor = XRefParseException;
  498. return XRefParseException;
  499. }();
  500. var FormatError = function FormatErrorClosure() {
  501. function FormatError(msg) {
  502. this.message = msg;
  503. }
  504. FormatError.prototype = new Error();
  505. FormatError.prototype.name = 'FormatError';
  506. FormatError.constructor = FormatError;
  507. return FormatError;
  508. }();
  509. var AbortException = function AbortExceptionClosure() {
  510. function AbortException(msg) {
  511. this.name = 'AbortException';
  512. this.message = msg;
  513. }
  514. AbortException.prototype = new Error();
  515. AbortException.constructor = AbortException;
  516. return AbortException;
  517. }();
  518. var NullCharactersRegExp = /\x00/g;
  519. function removeNullCharacters(str) {
  520. if (typeof str !== 'string') {
  521. warn('The argument for removeNullCharacters must be a string.');
  522. return str;
  523. }
  524. return str.replace(NullCharactersRegExp, '');
  525. }
  526. function bytesToString(bytes) {
  527. assert(bytes !== null && (typeof bytes === 'undefined' ? 'undefined' : _typeof(bytes)) === 'object' && bytes.length !== undefined, 'Invalid argument for bytesToString');
  528. var length = bytes.length;
  529. var MAX_ARGUMENT_COUNT = 8192;
  530. if (length < MAX_ARGUMENT_COUNT) {
  531. return String.fromCharCode.apply(null, bytes);
  532. }
  533. var strBuf = [];
  534. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  535. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  536. var chunk = bytes.subarray(i, chunkEnd);
  537. strBuf.push(String.fromCharCode.apply(null, chunk));
  538. }
  539. return strBuf.join('');
  540. }
  541. function stringToBytes(str) {
  542. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  543. var length = str.length;
  544. var bytes = new Uint8Array(length);
  545. for (var i = 0; i < length; ++i) {
  546. bytes[i] = str.charCodeAt(i) & 0xFF;
  547. }
  548. return bytes;
  549. }
  550. function arrayByteLength(arr) {
  551. if (arr.length !== undefined) {
  552. return arr.length;
  553. }
  554. assert(arr.byteLength !== undefined);
  555. return arr.byteLength;
  556. }
  557. function arraysToBytes(arr) {
  558. if (arr.length === 1 && arr[0] instanceof Uint8Array) {
  559. return arr[0];
  560. }
  561. var resultLength = 0;
  562. var i,
  563. ii = arr.length;
  564. var item, itemLength;
  565. for (i = 0; i < ii; i++) {
  566. item = arr[i];
  567. itemLength = arrayByteLength(item);
  568. resultLength += itemLength;
  569. }
  570. var pos = 0;
  571. var data = new Uint8Array(resultLength);
  572. for (i = 0; i < ii; i++) {
  573. item = arr[i];
  574. if (!(item instanceof Uint8Array)) {
  575. if (typeof item === 'string') {
  576. item = stringToBytes(item);
  577. } else {
  578. item = new Uint8Array(item);
  579. }
  580. }
  581. itemLength = item.byteLength;
  582. data.set(item, pos);
  583. pos += itemLength;
  584. }
  585. return data;
  586. }
  587. function string32(value) {
  588. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  589. }
  590. function log2(x) {
  591. var n = 1,
  592. i = 0;
  593. while (x > n) {
  594. n <<= 1;
  595. i++;
  596. }
  597. return i;
  598. }
  599. function readInt8(data, start) {
  600. return data[start] << 24 >> 24;
  601. }
  602. function readUint16(data, offset) {
  603. return data[offset] << 8 | data[offset + 1];
  604. }
  605. function readUint32(data, offset) {
  606. return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
  607. }
  608. function isLittleEndian() {
  609. var buffer8 = new Uint8Array(4);
  610. buffer8[0] = 1;
  611. var view32 = new Uint32Array(buffer8.buffer, 0, 1);
  612. return view32[0] === 1;
  613. }
  614. function isEvalSupported() {
  615. try {
  616. new Function('');
  617. return true;
  618. } catch (e) {
  619. return false;
  620. }
  621. }
  622. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  623. var Util = function UtilClosure() {
  624. function Util() {}
  625. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  626. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  627. rgbBuf[1] = r;
  628. rgbBuf[3] = g;
  629. rgbBuf[5] = b;
  630. return rgbBuf.join('');
  631. };
  632. Util.transform = function Util_transform(m1, m2) {
  633. return [m1[0] * m2[0] + m1[2] * m2[1], m1[1] * m2[0] + m1[3] * m2[1], m1[0] * m2[2] + m1[2] * m2[3], m1[1] * m2[2] + m1[3] * m2[3], m1[0] * m2[4] + m1[2] * m2[5] + m1[4], m1[1] * m2[4] + m1[3] * m2[5] + m1[5]];
  634. };
  635. Util.applyTransform = function Util_applyTransform(p, m) {
  636. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  637. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  638. return [xt, yt];
  639. };
  640. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  641. var d = m[0] * m[3] - m[1] * m[2];
  642. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  643. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  644. return [xt, yt];
  645. };
  646. Util.getAxialAlignedBoundingBox = function Util_getAxialAlignedBoundingBox(r, m) {
  647. var p1 = Util.applyTransform(r, m);
  648. var p2 = Util.applyTransform(r.slice(2, 4), m);
  649. var p3 = Util.applyTransform([r[0], r[3]], m);
  650. var p4 = Util.applyTransform([r[2], r[1]], m);
  651. return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])];
  652. };
  653. Util.inverseTransform = function Util_inverseTransform(m) {
  654. var d = m[0] * m[3] - m[1] * m[2];
  655. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d, (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  656. };
  657. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  658. return [m[0] * v[0] + m[1] * v[1] + m[2] * v[2], m[3] * v[0] + m[4] * v[1] + m[5] * v[2], m[6] * v[0] + m[7] * v[1] + m[8] * v[2]];
  659. };
  660. Util.singularValueDecompose2dScale = function Util_singularValueDecompose2dScale(m) {
  661. var transpose = [m[0], m[2], m[1], m[3]];
  662. var a = m[0] * transpose[0] + m[1] * transpose[2];
  663. var b = m[0] * transpose[1] + m[1] * transpose[3];
  664. var c = m[2] * transpose[0] + m[3] * transpose[2];
  665. var d = m[2] * transpose[1] + m[3] * transpose[3];
  666. var first = (a + d) / 2;
  667. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  668. var sx = first + second || 1;
  669. var sy = first - second || 1;
  670. return [Math.sqrt(sx), Math.sqrt(sy)];
  671. };
  672. Util.normalizeRect = function Util_normalizeRect(rect) {
  673. var r = rect.slice(0);
  674. if (rect[0] > rect[2]) {
  675. r[0] = rect[2];
  676. r[2] = rect[0];
  677. }
  678. if (rect[1] > rect[3]) {
  679. r[1] = rect[3];
  680. r[3] = rect[1];
  681. }
  682. return r;
  683. };
  684. Util.intersect = function Util_intersect(rect1, rect2) {
  685. function compare(a, b) {
  686. return a - b;
  687. }
  688. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  689. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  690. result = [];
  691. rect1 = Util.normalizeRect(rect1);
  692. rect2 = Util.normalizeRect(rect2);
  693. if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
  694. result[0] = orderedX[1];
  695. result[2] = orderedX[2];
  696. } else {
  697. return false;
  698. }
  699. if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
  700. result[1] = orderedY[1];
  701. result[3] = orderedY[2];
  702. } else {
  703. return false;
  704. }
  705. return result;
  706. };
  707. Util.sign = function Util_sign(num) {
  708. return num < 0 ? -1 : 1;
  709. };
  710. var ROMAN_NUMBER_MAP = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'];
  711. Util.toRoman = function Util_toRoman(number, lowerCase) {
  712. assert(isInt(number) && number > 0, 'The number should be a positive integer.');
  713. var pos,
  714. romanBuf = [];
  715. while (number >= 1000) {
  716. number -= 1000;
  717. romanBuf.push('M');
  718. }
  719. pos = number / 100 | 0;
  720. number %= 100;
  721. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  722. pos = number / 10 | 0;
  723. number %= 10;
  724. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  725. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  726. var romanStr = romanBuf.join('');
  727. return lowerCase ? romanStr.toLowerCase() : romanStr;
  728. };
  729. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  730. Array.prototype.push.apply(arr1, arr2);
  731. };
  732. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  733. Array.prototype.unshift.apply(arr1, arr2);
  734. };
  735. Util.extendObj = function extendObj(obj1, obj2) {
  736. for (var key in obj2) {
  737. obj1[key] = obj2[key];
  738. }
  739. };
  740. Util.getInheritableProperty = function Util_getInheritableProperty(dict, name, getArray) {
  741. while (dict && !dict.has(name)) {
  742. dict = dict.get('Parent');
  743. }
  744. if (!dict) {
  745. return null;
  746. }
  747. return getArray ? dict.getArray(name) : dict.get(name);
  748. };
  749. Util.inherit = function Util_inherit(sub, base, prototype) {
  750. sub.prototype = Object.create(base.prototype);
  751. sub.prototype.constructor = sub;
  752. for (var prop in prototype) {
  753. sub.prototype[prop] = prototype[prop];
  754. }
  755. };
  756. Util.loadScript = function Util_loadScript(src, callback) {
  757. var script = document.createElement('script');
  758. var loaded = false;
  759. script.setAttribute('src', src);
  760. if (callback) {
  761. script.onload = function () {
  762. if (!loaded) {
  763. callback();
  764. }
  765. loaded = true;
  766. };
  767. }
  768. document.getElementsByTagName('head')[0].appendChild(script);
  769. };
  770. return Util;
  771. }();
  772. var PageViewport = function PageViewportClosure() {
  773. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  774. this.viewBox = viewBox;
  775. this.scale = scale;
  776. this.rotation = rotation;
  777. this.offsetX = offsetX;
  778. this.offsetY = offsetY;
  779. var centerX = (viewBox[2] + viewBox[0]) / 2;
  780. var centerY = (viewBox[3] + viewBox[1]) / 2;
  781. var rotateA, rotateB, rotateC, rotateD;
  782. rotation = rotation % 360;
  783. rotation = rotation < 0 ? rotation + 360 : rotation;
  784. switch (rotation) {
  785. case 180:
  786. rotateA = -1;
  787. rotateB = 0;
  788. rotateC = 0;
  789. rotateD = 1;
  790. break;
  791. case 90:
  792. rotateA = 0;
  793. rotateB = 1;
  794. rotateC = 1;
  795. rotateD = 0;
  796. break;
  797. case 270:
  798. rotateA = 0;
  799. rotateB = -1;
  800. rotateC = -1;
  801. rotateD = 0;
  802. break;
  803. default:
  804. rotateA = 1;
  805. rotateB = 0;
  806. rotateC = 0;
  807. rotateD = -1;
  808. break;
  809. }
  810. if (dontFlip) {
  811. rotateC = -rotateC;
  812. rotateD = -rotateD;
  813. }
  814. var offsetCanvasX, offsetCanvasY;
  815. var width, height;
  816. if (rotateA === 0) {
  817. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  818. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  819. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  820. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  821. } else {
  822. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  823. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  824. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  825. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  826. }
  827. this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
  828. this.width = width;
  829. this.height = height;
  830. this.fontScale = scale;
  831. }
  832. PageViewport.prototype = {
  833. clone: function PageViewPort_clone(args) {
  834. args = args || {};
  835. var scale = 'scale' in args ? args.scale : this.scale;
  836. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  837. return new PageViewport(this.viewBox.slice(), scale, rotation, this.offsetX, this.offsetY, args.dontFlip);
  838. },
  839. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  840. return Util.applyTransform([x, y], this.transform);
  841. },
  842. convertToViewportRectangle: function PageViewport_convertToViewportRectangle(rect) {
  843. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  844. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  845. return [tl[0], tl[1], br[0], br[1]];
  846. },
  847. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  848. return Util.applyInverseTransform([x, y], this.transform);
  849. }
  850. };
  851. return PageViewport;
  852. }();
  853. var PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C, 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160, 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC];
  854. function stringToPDFString(str) {
  855. var i,
  856. n = str.length,
  857. strBuf = [];
  858. if (str[0] === '\xFE' && str[1] === '\xFF') {
  859. for (i = 2; i < n; i += 2) {
  860. strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
  861. }
  862. } else {
  863. for (i = 0; i < n; ++i) {
  864. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  865. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  866. }
  867. }
  868. return strBuf.join('');
  869. }
  870. function stringToUTF8String(str) {
  871. return decodeURIComponent(escape(str));
  872. }
  873. function utf8StringToString(str) {
  874. return unescape(encodeURIComponent(str));
  875. }
  876. function isEmptyObj(obj) {
  877. for (var key in obj) {
  878. return false;
  879. }
  880. return true;
  881. }
  882. function isBool(v) {
  883. return typeof v === 'boolean';
  884. }
  885. function isInt(v) {
  886. return typeof v === 'number' && (v | 0) === v;
  887. }
  888. function isNum(v) {
  889. return typeof v === 'number';
  890. }
  891. function isString(v) {
  892. return typeof v === 'string';
  893. }
  894. function isArray(v) {
  895. return v instanceof Array;
  896. }
  897. function isArrayBuffer(v) {
  898. return (typeof v === 'undefined' ? 'undefined' : _typeof(v)) === 'object' && v !== null && v.byteLength !== undefined;
  899. }
  900. function isSpace(ch) {
  901. return ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A;
  902. }
  903. function isNodeJS() {
  904. return (typeof process === 'undefined' ? 'undefined' : _typeof(process)) === 'object' && process + '' === '[object process]';
  905. }
  906. function createPromiseCapability() {
  907. var capability = {};
  908. capability.promise = new Promise(function (resolve, reject) {
  909. capability.resolve = resolve;
  910. capability.reject = reject;
  911. });
  912. return capability;
  913. }
  914. var StatTimer = function StatTimerClosure() {
  915. function rpad(str, pad, length) {
  916. while (str.length < length) {
  917. str += pad;
  918. }
  919. return str;
  920. }
  921. function StatTimer() {
  922. this.started = Object.create(null);
  923. this.times = [];
  924. this.enabled = true;
  925. }
  926. StatTimer.prototype = {
  927. time: function StatTimer_time(name) {
  928. if (!this.enabled) {
  929. return;
  930. }
  931. if (name in this.started) {
  932. warn('Timer is already running for ' + name);
  933. }
  934. this.started[name] = Date.now();
  935. },
  936. timeEnd: function StatTimer_timeEnd(name) {
  937. if (!this.enabled) {
  938. return;
  939. }
  940. if (!(name in this.started)) {
  941. warn('Timer has not been started for ' + name);
  942. }
  943. this.times.push({
  944. 'name': name,
  945. 'start': this.started[name],
  946. 'end': Date.now()
  947. });
  948. delete this.started[name];
  949. },
  950. toString: function StatTimer_toString() {
  951. var i, ii;
  952. var times = this.times;
  953. var out = '';
  954. var longest = 0;
  955. for (i = 0, ii = times.length; i < ii; ++i) {
  956. var name = times[i]['name'];
  957. if (name.length > longest) {
  958. longest = name.length;
  959. }
  960. }
  961. for (i = 0, ii = times.length; i < ii; ++i) {
  962. var span = times[i];
  963. var duration = span.end - span.start;
  964. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  965. }
  966. return out;
  967. }
  968. };
  969. return StatTimer;
  970. }();
  971. var createBlob = function createBlob(data, contentType) {
  972. if (typeof Blob !== 'undefined') {
  973. return new Blob([data], { type: contentType });
  974. }
  975. throw new Error('The "Blob" constructor is not supported.');
  976. };
  977. var createObjectURL = function createObjectURLClosure() {
  978. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  979. return function createObjectURL(data, contentType) {
  980. var forceDataSchema = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  981. if (!forceDataSchema && URL.createObjectURL) {
  982. var blob = createBlob(data, contentType);
  983. return URL.createObjectURL(blob);
  984. }
  985. var buffer = 'data:' + contentType + ';base64,';
  986. for (var i = 0, ii = data.length; i < ii; i += 3) {
  987. var b1 = data[i] & 0xFF;
  988. var b2 = data[i + 1] & 0xFF;
  989. var b3 = data[i + 2] & 0xFF;
  990. var d1 = b1 >> 2,
  991. d2 = (b1 & 3) << 4 | b2 >> 4;
  992. var d3 = i + 1 < ii ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
  993. var d4 = i + 2 < ii ? b3 & 0x3F : 64;
  994. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  995. }
  996. return buffer;
  997. };
  998. }();
  999. function resolveCall(fn, args) {
  1000. var thisArg = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  1001. if (!fn) {
  1002. return Promise.resolve(undefined);
  1003. }
  1004. return new Promise(function (resolve, reject) {
  1005. resolve(fn.apply(thisArg, args));
  1006. });
  1007. }
  1008. function wrapReason(reason) {
  1009. if ((typeof reason === 'undefined' ? 'undefined' : _typeof(reason)) !== 'object') {
  1010. return reason;
  1011. }
  1012. switch (reason.name) {
  1013. case 'AbortException':
  1014. return new AbortException(reason.message);
  1015. case 'MissingPDFException':
  1016. return new MissingPDFException(reason.message);
  1017. case 'UnexpectedResponseException':
  1018. return new UnexpectedResponseException(reason.message, reason.status);
  1019. default:
  1020. return new UnknownErrorException(reason.message, reason.details);
  1021. }
  1022. }
  1023. function resolveOrReject(capability, success, reason) {
  1024. if (success) {
  1025. capability.resolve();
  1026. } else {
  1027. capability.reject(reason);
  1028. }
  1029. }
  1030. function finalize(promise) {
  1031. return Promise.resolve(promise).catch(function () {});
  1032. }
  1033. function MessageHandler(sourceName, targetName, comObj) {
  1034. var _this = this;
  1035. this.sourceName = sourceName;
  1036. this.targetName = targetName;
  1037. this.comObj = comObj;
  1038. this.callbackId = 1;
  1039. this.streamId = 1;
  1040. this.postMessageTransfers = true;
  1041. this.streamSinks = Object.create(null);
  1042. this.streamControllers = Object.create(null);
  1043. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  1044. var ah = this.actionHandler = Object.create(null);
  1045. this._onComObjOnMessage = function (event) {
  1046. var data = event.data;
  1047. if (data.targetName !== _this.sourceName) {
  1048. return;
  1049. }
  1050. if (data.stream) {
  1051. _this._processStreamMessage(data);
  1052. } else if (data.isReply) {
  1053. var callbackId = data.callbackId;
  1054. if (data.callbackId in callbacksCapabilities) {
  1055. var callback = callbacksCapabilities[callbackId];
  1056. delete callbacksCapabilities[callbackId];
  1057. if ('error' in data) {
  1058. callback.reject(wrapReason(data.error));
  1059. } else {
  1060. callback.resolve(data.data);
  1061. }
  1062. } else {
  1063. throw new Error('Cannot resolve callback ' + callbackId);
  1064. }
  1065. } else if (data.action in ah) {
  1066. var action = ah[data.action];
  1067. if (data.callbackId) {
  1068. var _sourceName = _this.sourceName;
  1069. var _targetName = data.sourceName;
  1070. Promise.resolve().then(function () {
  1071. return action[0].call(action[1], data.data);
  1072. }).then(function (result) {
  1073. comObj.postMessage({
  1074. sourceName: _sourceName,
  1075. targetName: _targetName,
  1076. isReply: true,
  1077. callbackId: data.callbackId,
  1078. data: result
  1079. });
  1080. }, function (reason) {
  1081. if (reason instanceof Error) {
  1082. reason = reason + '';
  1083. }
  1084. comObj.postMessage({
  1085. sourceName: _sourceName,
  1086. targetName: _targetName,
  1087. isReply: true,
  1088. callbackId: data.callbackId,
  1089. error: reason
  1090. });
  1091. });
  1092. } else if (data.streamId) {
  1093. _this._createStreamSink(data);
  1094. } else {
  1095. action[0].call(action[1], data.data);
  1096. }
  1097. } else {
  1098. throw new Error('Unknown action from worker: ' + data.action);
  1099. }
  1100. };
  1101. comObj.addEventListener('message', this._onComObjOnMessage);
  1102. }
  1103. MessageHandler.prototype = {
  1104. on: function on(actionName, handler, scope) {
  1105. var ah = this.actionHandler;
  1106. if (ah[actionName]) {
  1107. throw new Error('There is already an actionName called "' + actionName + '"');
  1108. }
  1109. ah[actionName] = [handler, scope];
  1110. },
  1111. send: function send(actionName, data, transfers) {
  1112. var message = {
  1113. sourceName: this.sourceName,
  1114. targetName: this.targetName,
  1115. action: actionName,
  1116. data: data
  1117. };
  1118. this.postMessage(message, transfers);
  1119. },
  1120. sendWithPromise: function sendWithPromise(actionName, data, transfers) {
  1121. var callbackId = this.callbackId++;
  1122. var message = {
  1123. sourceName: this.sourceName,
  1124. targetName: this.targetName,
  1125. action: actionName,
  1126. data: data,
  1127. callbackId: callbackId
  1128. };
  1129. var capability = createPromiseCapability();
  1130. this.callbacksCapabilities[callbackId] = capability;
  1131. try {
  1132. this.postMessage(message, transfers);
  1133. } catch (e) {
  1134. capability.reject(e);
  1135. }
  1136. return capability.promise;
  1137. },
  1138. sendWithStream: function sendWithStream(actionName, data, queueingStrategy, transfers) {
  1139. var _this2 = this;
  1140. var streamId = this.streamId++;
  1141. var sourceName = this.sourceName;
  1142. var targetName = this.targetName;
  1143. return new _streams_polyfill.ReadableStream({
  1144. start: function start(controller) {
  1145. var startCapability = createPromiseCapability();
  1146. _this2.streamControllers[streamId] = {
  1147. controller: controller,
  1148. startCall: startCapability,
  1149. isClosed: false
  1150. };
  1151. _this2.postMessage({
  1152. sourceName: sourceName,
  1153. targetName: targetName,
  1154. action: actionName,
  1155. streamId: streamId,
  1156. data: data,
  1157. desiredSize: controller.desiredSize
  1158. });
  1159. return startCapability.promise;
  1160. },
  1161. pull: function pull(controller) {
  1162. var pullCapability = createPromiseCapability();
  1163. _this2.streamControllers[streamId].pullCall = pullCapability;
  1164. _this2.postMessage({
  1165. sourceName: sourceName,
  1166. targetName: targetName,
  1167. stream: 'pull',
  1168. streamId: streamId,
  1169. desiredSize: controller.desiredSize
  1170. });
  1171. return pullCapability.promise;
  1172. },
  1173. cancel: function cancel(reason) {
  1174. var cancelCapability = createPromiseCapability();
  1175. _this2.streamControllers[streamId].cancelCall = cancelCapability;
  1176. _this2.streamControllers[streamId].isClosed = true;
  1177. _this2.postMessage({
  1178. sourceName: sourceName,
  1179. targetName: targetName,
  1180. stream: 'cancel',
  1181. reason: reason,
  1182. streamId: streamId
  1183. });
  1184. return cancelCapability.promise;
  1185. }
  1186. }, queueingStrategy);
  1187. },
  1188. _createStreamSink: function _createStreamSink(data) {
  1189. var _this3 = this;
  1190. var self = this;
  1191. var action = this.actionHandler[data.action];
  1192. var streamId = data.streamId;
  1193. var desiredSize = data.desiredSize;
  1194. var sourceName = this.sourceName;
  1195. var targetName = data.sourceName;
  1196. var capability = createPromiseCapability();
  1197. var sendStreamRequest = function sendStreamRequest(_ref) {
  1198. var stream = _ref.stream,
  1199. chunk = _ref.chunk,
  1200. transfers = _ref.transfers,
  1201. success = _ref.success,
  1202. reason = _ref.reason;
  1203. _this3.postMessage({
  1204. sourceName: sourceName,
  1205. targetName: targetName,
  1206. stream: stream,
  1207. streamId: streamId,
  1208. chunk: chunk,
  1209. success: success,
  1210. reason: reason
  1211. }, transfers);
  1212. };
  1213. var streamSink = {
  1214. enqueue: function enqueue(chunk) {
  1215. var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  1216. var transfers = arguments[2];
  1217. if (this.isCancelled) {
  1218. return;
  1219. }
  1220. var lastDesiredSize = this.desiredSize;
  1221. this.desiredSize -= size;
  1222. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  1223. this.sinkCapability = createPromiseCapability();
  1224. this.ready = this.sinkCapability.promise;
  1225. }
  1226. sendStreamRequest({
  1227. stream: 'enqueue',
  1228. chunk: chunk,
  1229. transfers: transfers
  1230. });
  1231. },
  1232. close: function close() {
  1233. if (this.isCancelled) {
  1234. return;
  1235. }
  1236. sendStreamRequest({ stream: 'close' });
  1237. delete self.streamSinks[streamId];
  1238. },
  1239. error: function error(reason) {
  1240. if (this.isCancelled) {
  1241. return;
  1242. }
  1243. this.isCancelled = true;
  1244. sendStreamRequest({
  1245. stream: 'error',
  1246. reason: reason
  1247. });
  1248. },
  1249. sinkCapability: capability,
  1250. onPull: null,
  1251. onCancel: null,
  1252. isCancelled: false,
  1253. desiredSize: desiredSize,
  1254. ready: null
  1255. };
  1256. streamSink.sinkCapability.resolve();
  1257. streamSink.ready = streamSink.sinkCapability.promise;
  1258. this.streamSinks[streamId] = streamSink;
  1259. resolveCall(action[0], [data.data, streamSink], action[1]).then(function () {
  1260. sendStreamRequest({
  1261. stream: 'start_complete',
  1262. success: true
  1263. });
  1264. }, function (reason) {
  1265. sendStreamRequest({
  1266. stream: 'start_complete',
  1267. success: false,
  1268. reason: reason
  1269. });
  1270. });
  1271. },
  1272. _processStreamMessage: function _processStreamMessage(data) {
  1273. var _this4 = this;
  1274. var sourceName = this.sourceName;
  1275. var targetName = data.sourceName;
  1276. var streamId = data.streamId;
  1277. var sendStreamResponse = function sendStreamResponse(_ref2) {
  1278. var stream = _ref2.stream,
  1279. success = _ref2.success,
  1280. reason = _ref2.reason;
  1281. _this4.comObj.postMessage({
  1282. sourceName: sourceName,
  1283. targetName: targetName,
  1284. stream: stream,
  1285. success: success,
  1286. streamId: streamId,
  1287. reason: reason
  1288. });
  1289. };
  1290. var deleteStreamController = function deleteStreamController() {
  1291. Promise.all([_this4.streamControllers[data.streamId].startCall, _this4.streamControllers[data.streamId].pullCall, _this4.streamControllers[data.streamId].cancelCall].map(function (capability) {
  1292. return capability && finalize(capability.promise);
  1293. })).then(function () {
  1294. delete _this4.streamControllers[data.streamId];
  1295. });
  1296. };
  1297. switch (data.stream) {
  1298. case 'start_complete':
  1299. resolveOrReject(this.streamControllers[data.streamId].startCall, data.success, wrapReason(data.reason));
  1300. break;
  1301. case 'pull_complete':
  1302. resolveOrReject(this.streamControllers[data.streamId].pullCall, data.success, wrapReason(data.reason));
  1303. break;
  1304. case 'pull':
  1305. if (!this.streamSinks[data.streamId]) {
  1306. sendStreamResponse({
  1307. stream: 'pull_complete',
  1308. success: true
  1309. });
  1310. break;
  1311. }
  1312. if (this.streamSinks[data.streamId].desiredSize <= 0 && data.desiredSize > 0) {
  1313. this.streamSinks[data.streamId].sinkCapability.resolve();
  1314. }
  1315. this.streamSinks[data.streamId].desiredSize = data.desiredSize;
  1316. resolveCall(this.streamSinks[data.streamId].onPull).then(function () {
  1317. sendStreamResponse({
  1318. stream: 'pull_complete',
  1319. success: true
  1320. });
  1321. }, function (reason) {
  1322. sendStreamResponse({
  1323. stream: 'pull_complete',
  1324. success: false,
  1325. reason: reason
  1326. });
  1327. });
  1328. break;
  1329. case 'enqueue':
  1330. assert(this.streamControllers[data.streamId], 'enqueue should have stream controller');
  1331. if (!this.streamControllers[data.streamId].isClosed) {
  1332. this.streamControllers[data.streamId].controller.enqueue(data.chunk);
  1333. }
  1334. break;
  1335. case 'close':
  1336. assert(this.streamControllers[data.streamId], 'close should have stream controller');
  1337. if (this.streamControllers[data.streamId].isClosed) {
  1338. break;
  1339. }
  1340. this.streamControllers[data.streamId].isClosed = true;
  1341. this.streamControllers[data.streamId].controller.close();
  1342. deleteStreamController();
  1343. break;
  1344. case 'error':
  1345. assert(this.streamControllers[data.streamId], 'error should have stream controller');
  1346. this.streamControllers[data.streamId].controller.error(wrapReason(data.reason));
  1347. deleteStreamController();
  1348. break;
  1349. case 'cancel_complete':
  1350. resolveOrReject(this.streamControllers[data.streamId].cancelCall, data.success, wrapReason(data.reason));
  1351. deleteStreamController();
  1352. break;
  1353. case 'cancel':
  1354. if (!this.streamSinks[data.streamId]) {
  1355. break;
  1356. }
  1357. resolveCall(this.streamSinks[data.streamId].onCancel, [wrapReason(data.reason)]).then(function () {
  1358. sendStreamResponse({
  1359. stream: 'cancel_complete',
  1360. success: true
  1361. });
  1362. }, function (reason) {
  1363. sendStreamResponse({
  1364. stream: 'cancel_complete',
  1365. success: false,
  1366. reason: reason
  1367. });
  1368. });
  1369. this.streamSinks[data.streamId].sinkCapability.reject(wrapReason(data.reason));
  1370. this.streamSinks[data.streamId].isCancelled = true;
  1371. delete this.streamSinks[data.streamId];
  1372. break;
  1373. default:
  1374. throw new Error('Unexpected stream case');
  1375. }
  1376. },
  1377. postMessage: function postMessage(message, transfers) {
  1378. if (transfers && this.postMessageTransfers) {
  1379. this.comObj.postMessage(message, transfers);
  1380. } else {
  1381. this.comObj.postMessage(message);
  1382. }
  1383. },
  1384. destroy: function destroy() {
  1385. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  1386. }
  1387. };
  1388. function loadJpegStream(id, imageUrl, objs) {
  1389. var img = new Image();
  1390. img.onload = function loadJpegStream_onloadClosure() {
  1391. objs.resolve(id, img);
  1392. };
  1393. img.onerror = function loadJpegStream_onerrorClosure() {
  1394. objs.resolve(id, null);
  1395. warn('Error during JPEG image loading');
  1396. };
  1397. img.src = imageUrl;
  1398. }
  1399. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  1400. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  1401. exports.OPS = OPS;
  1402. exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
  1403. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  1404. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  1405. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  1406. exports.AnnotationFlag = AnnotationFlag;
  1407. exports.AnnotationType = AnnotationType;
  1408. exports.FontType = FontType;
  1409. exports.ImageKind = ImageKind;
  1410. exports.CMapCompressionType = CMapCompressionType;
  1411. exports.AbortException = AbortException;
  1412. exports.InvalidPDFException = InvalidPDFException;
  1413. exports.MessageHandler = MessageHandler;
  1414. exports.MissingDataException = MissingDataException;
  1415. exports.MissingPDFException = MissingPDFException;
  1416. exports.NativeImageDecoding = NativeImageDecoding;
  1417. exports.NotImplementedException = NotImplementedException;
  1418. exports.PageViewport = PageViewport;
  1419. exports.PasswordException = PasswordException;
  1420. exports.PasswordResponses = PasswordResponses;
  1421. exports.StatTimer = StatTimer;
  1422. exports.StreamType = StreamType;
  1423. exports.TextRenderingMode = TextRenderingMode;
  1424. exports.UnexpectedResponseException = UnexpectedResponseException;
  1425. exports.UnknownErrorException = UnknownErrorException;
  1426. exports.Util = Util;
  1427. exports.XRefParseException = XRefParseException;
  1428. exports.FormatError = FormatError;
  1429. exports.arrayByteLength = arrayByteLength;
  1430. exports.arraysToBytes = arraysToBytes;
  1431. exports.assert = assert;
  1432. exports.bytesToString = bytesToString;
  1433. exports.createBlob = createBlob;
  1434. exports.createPromiseCapability = createPromiseCapability;
  1435. exports.createObjectURL = createObjectURL;
  1436. exports.deprecated = deprecated;
  1437. exports.getLookupTableFactory = getLookupTableFactory;
  1438. exports.getVerbosityLevel = getVerbosityLevel;
  1439. exports.globalScope = globalScope;
  1440. exports.info = info;
  1441. exports.isArray = isArray;
  1442. exports.isArrayBuffer = isArrayBuffer;
  1443. exports.isBool = isBool;
  1444. exports.isEmptyObj = isEmptyObj;
  1445. exports.isInt = isInt;
  1446. exports.isNum = isNum;
  1447. exports.isString = isString;
  1448. exports.isSpace = isSpace;
  1449. exports.isNodeJS = isNodeJS;
  1450. exports.isSameOrigin = isSameOrigin;
  1451. exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
  1452. exports.isLittleEndian = isLittleEndian;
  1453. exports.isEvalSupported = isEvalSupported;
  1454. exports.loadJpegStream = loadJpegStream;
  1455. exports.log2 = log2;
  1456. exports.readInt8 = readInt8;
  1457. exports.readUint16 = readUint16;
  1458. exports.readUint32 = readUint32;
  1459. exports.removeNullCharacters = removeNullCharacters;
  1460. exports.ReadableStream = _streams_polyfill.ReadableStream;
  1461. exports.setVerbosityLevel = setVerbosityLevel;
  1462. exports.shadow = shadow;
  1463. exports.string32 = string32;
  1464. exports.stringToBytes = stringToBytes;
  1465. exports.stringToPDFString = stringToPDFString;
  1466. exports.stringToUTF8String = stringToUTF8String;
  1467. exports.utf8StringToString = utf8StringToString;
  1468. exports.warn = warn;
  1469. exports.unreachable = unreachable;
  1470. /***/ }),
  1471. /* 1 */
  1472. /***/ (function(module, exports, __w_pdfjs_require__) {
  1473. "use strict";
  1474. Object.defineProperty(exports, "__esModule", {
  1475. value: true
  1476. });
  1477. exports.DOMCMapReaderFactory = exports.DOMCanvasFactory = exports.DEFAULT_LINK_REL = exports.getDefaultSetting = exports.LinkTarget = exports.getFilenameFromUrl = exports.isValidUrl = exports.isExternalLinkTargetSet = exports.addLinkAttributes = exports.RenderingCancelledException = exports.CustomStyle = undefined;
  1478. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  1479. var _util = __w_pdfjs_require__(0);
  1480. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1481. var DEFAULT_LINK_REL = 'noopener noreferrer nofollow';
  1482. var DOMCanvasFactory = function () {
  1483. function DOMCanvasFactory() {
  1484. _classCallCheck(this, DOMCanvasFactory);
  1485. }
  1486. _createClass(DOMCanvasFactory, [{
  1487. key: 'create',
  1488. value: function create(width, height) {
  1489. if (width <= 0 || height <= 0) {
  1490. throw new Error('invalid canvas size');
  1491. }
  1492. var canvas = document.createElement('canvas');
  1493. var context = canvas.getContext('2d');
  1494. canvas.width = width;
  1495. canvas.height = height;
  1496. return {
  1497. canvas: canvas,
  1498. context: context
  1499. };
  1500. }
  1501. }, {
  1502. key: 'reset',
  1503. value: function reset(canvasAndContext, width, height) {
  1504. if (!canvasAndContext.canvas) {
  1505. throw new Error('canvas is not specified');
  1506. }
  1507. if (width <= 0 || height <= 0) {
  1508. throw new Error('invalid canvas size');
  1509. }
  1510. canvasAndContext.canvas.width = width;
  1511. canvasAndContext.canvas.height = height;
  1512. }
  1513. }, {
  1514. key: 'destroy',
  1515. value: function destroy(canvasAndContext) {
  1516. if (!canvasAndContext.canvas) {
  1517. throw new Error('canvas is not specified');
  1518. }
  1519. canvasAndContext.canvas.width = 0;
  1520. canvasAndContext.canvas.height = 0;
  1521. canvasAndContext.canvas = null;
  1522. canvasAndContext.context = null;
  1523. }
  1524. }]);
  1525. return DOMCanvasFactory;
  1526. }();
  1527. var DOMCMapReaderFactory = function () {
  1528. function DOMCMapReaderFactory(_ref) {
  1529. var _ref$baseUrl = _ref.baseUrl,
  1530. baseUrl = _ref$baseUrl === undefined ? null : _ref$baseUrl,
  1531. _ref$isCompressed = _ref.isCompressed,
  1532. isCompressed = _ref$isCompressed === undefined ? false : _ref$isCompressed;
  1533. _classCallCheck(this, DOMCMapReaderFactory);
  1534. this.baseUrl = baseUrl;
  1535. this.isCompressed = isCompressed;
  1536. }
  1537. _createClass(DOMCMapReaderFactory, [{
  1538. key: 'fetch',
  1539. value: function fetch(_ref2) {
  1540. var _this = this;
  1541. var name = _ref2.name;
  1542. if (!name) {
  1543. return Promise.reject(new Error('CMap name must be specified.'));
  1544. }
  1545. return new Promise(function (resolve, reject) {
  1546. var url = _this.baseUrl + name + (_this.isCompressed ? '.bcmap' : '');
  1547. var request = new XMLHttpRequest();
  1548. request.open('GET', url, true);
  1549. if (_this.isCompressed) {
  1550. request.responseType = 'arraybuffer';
  1551. }
  1552. request.onreadystatechange = function () {
  1553. if (request.readyState !== XMLHttpRequest.DONE) {
  1554. return;
  1555. }
  1556. if (request.status === 200 || request.status === 0) {
  1557. var data = void 0;
  1558. if (_this.isCompressed && request.response) {
  1559. data = new Uint8Array(request.response);
  1560. } else if (!_this.isCompressed && request.responseText) {
  1561. data = (0, _util.stringToBytes)(request.responseText);
  1562. }
  1563. if (data) {
  1564. resolve({
  1565. cMapData: data,
  1566. compressionType: _this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE
  1567. });
  1568. return;
  1569. }
  1570. }
  1571. reject(new Error('Unable to load ' + (_this.isCompressed ? 'binary ' : '') + 'CMap at: ' + url));
  1572. };
  1573. request.send(null);
  1574. });
  1575. }
  1576. }]);
  1577. return DOMCMapReaderFactory;
  1578. }();
  1579. var CustomStyle = function CustomStyleClosure() {
  1580. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  1581. var _cache = Object.create(null);
  1582. function CustomStyle() {}
  1583. CustomStyle.getProp = function get(propName, element) {
  1584. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  1585. return _cache[propName];
  1586. }
  1587. element = element || document.documentElement;
  1588. var style = element.style,
  1589. prefixed,
  1590. uPropName;
  1591. if (typeof style[propName] === 'string') {
  1592. return _cache[propName] = propName;
  1593. }
  1594. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  1595. for (var i = 0, l = prefixes.length; i < l; i++) {
  1596. prefixed = prefixes[i] + uPropName;
  1597. if (typeof style[prefixed] === 'string') {
  1598. return _cache[propName] = prefixed;
  1599. }
  1600. }
  1601. return _cache[propName] = 'undefined';
  1602. };
  1603. CustomStyle.setProp = function set(propName, element, str) {
  1604. var prop = this.getProp(propName);
  1605. if (prop !== 'undefined') {
  1606. element.style[prop] = str;
  1607. }
  1608. };
  1609. return CustomStyle;
  1610. }();
  1611. var RenderingCancelledException = function RenderingCancelledException() {
  1612. function RenderingCancelledException(msg, type) {
  1613. this.message = msg;
  1614. this.type = type;
  1615. }
  1616. RenderingCancelledException.prototype = new Error();
  1617. RenderingCancelledException.prototype.name = 'RenderingCancelledException';
  1618. RenderingCancelledException.constructor = RenderingCancelledException;
  1619. return RenderingCancelledException;
  1620. }();
  1621. var LinkTarget = {
  1622. NONE: 0,
  1623. SELF: 1,
  1624. BLANK: 2,
  1625. PARENT: 3,
  1626. TOP: 4
  1627. };
  1628. var LinkTargetStringMap = ['', '_self', '_blank', '_parent', '_top'];
  1629. function addLinkAttributes(link, params) {
  1630. var url = params && params.url;
  1631. link.href = link.title = url ? (0, _util.removeNullCharacters)(url) : '';
  1632. if (url) {
  1633. var target = params.target;
  1634. if (typeof target === 'undefined') {
  1635. target = getDefaultSetting('externalLinkTarget');
  1636. }
  1637. link.target = LinkTargetStringMap[target];
  1638. var rel = params.rel;
  1639. if (typeof rel === 'undefined') {
  1640. rel = getDefaultSetting('externalLinkRel');
  1641. }
  1642. link.rel = rel;
  1643. }
  1644. }
  1645. function getFilenameFromUrl(url) {
  1646. var anchor = url.indexOf('#');
  1647. var query = url.indexOf('?');
  1648. var end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
  1649. return url.substring(url.lastIndexOf('/', end) + 1, end);
  1650. }
  1651. function getDefaultSetting(id) {
  1652. var globalSettings = _util.globalScope.PDFJS;
  1653. switch (id) {
  1654. case 'pdfBug':
  1655. return globalSettings ? globalSettings.pdfBug : false;
  1656. case 'disableAutoFetch':
  1657. return globalSettings ? globalSettings.disableAutoFetch : false;
  1658. case 'disableStream':
  1659. return globalSettings ? globalSettings.disableStream : false;
  1660. case 'disableRange':
  1661. return globalSettings ? globalSettings.disableRange : false;
  1662. case 'disableFontFace':
  1663. return globalSettings ? globalSettings.disableFontFace : false;
  1664. case 'disableCreateObjectURL':
  1665. return globalSettings ? globalSettings.disableCreateObjectURL : false;
  1666. case 'disableWebGL':
  1667. return globalSettings ? globalSettings.disableWebGL : true;
  1668. case 'cMapUrl':
  1669. return globalSettings ? globalSettings.cMapUrl : null;
  1670. case 'cMapPacked':
  1671. return globalSettings ? globalSettings.cMapPacked : false;
  1672. case 'postMessageTransfers':
  1673. return globalSettings ? globalSettings.postMessageTransfers : true;
  1674. case 'workerPort':
  1675. return globalSettings ? globalSettings.workerPort : null;
  1676. case 'workerSrc':
  1677. return globalSettings ? globalSettings.workerSrc : null;
  1678. case 'disableWorker':
  1679. return globalSettings ? globalSettings.disableWorker : false;
  1680. case 'maxImageSize':
  1681. return globalSettings ? globalSettings.maxImageSize : -1;
  1682. case 'imageResourcesPath':
  1683. return globalSettings ? globalSettings.imageResourcesPath : '';
  1684. case 'isEvalSupported':
  1685. return globalSettings ? globalSettings.isEvalSupported : true;
  1686. case 'externalLinkTarget':
  1687. if (!globalSettings) {
  1688. return LinkTarget.NONE;
  1689. }
  1690. switch (globalSettings.externalLinkTarget) {
  1691. case LinkTarget.NONE:
  1692. case LinkTarget.SELF:
  1693. case LinkTarget.BLANK:
  1694. case LinkTarget.PARENT:
  1695. case LinkTarget.TOP:
  1696. return globalSettings.externalLinkTarget;
  1697. }
  1698. (0, _util.warn)('PDFJS.externalLinkTarget is invalid: ' + globalSettings.externalLinkTarget);
  1699. globalSettings.externalLinkTarget = LinkTarget.NONE;
  1700. return LinkTarget.NONE;
  1701. case 'externalLinkRel':
  1702. return globalSettings ? globalSettings.externalLinkRel : DEFAULT_LINK_REL;
  1703. case 'enableStats':
  1704. return !!(globalSettings && globalSettings.enableStats);
  1705. case 'pdfjsNext':
  1706. return !!(globalSettings && globalSettings.pdfjsNext);
  1707. default:
  1708. throw new Error('Unknown default setting: ' + id);
  1709. }
  1710. }
  1711. function isExternalLinkTargetSet() {
  1712. var externalLinkTarget = getDefaultSetting('externalLinkTarget');
  1713. switch (externalLinkTarget) {
  1714. case LinkTarget.NONE:
  1715. return false;
  1716. case LinkTarget.SELF:
  1717. case LinkTarget.BLANK:
  1718. case LinkTarget.PARENT:
  1719. case LinkTarget.TOP:
  1720. return true;
  1721. }
  1722. }
  1723. function isValidUrl(url, allowRelative) {
  1724. (0, _util.deprecated)('isValidUrl(), please use createValidAbsoluteUrl() instead.');
  1725. var baseUrl = allowRelative ? 'http://example.com' : null;
  1726. return (0, _util.createValidAbsoluteUrl)(url, baseUrl) !== null;
  1727. }
  1728. exports.CustomStyle = CustomStyle;
  1729. exports.RenderingCancelledException = RenderingCancelledException;
  1730. exports.addLinkAttributes = addLinkAttributes;
  1731. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  1732. exports.isValidUrl = isValidUrl;
  1733. exports.getFilenameFromUrl = getFilenameFromUrl;
  1734. exports.LinkTarget = LinkTarget;
  1735. exports.getDefaultSetting = getDefaultSetting;
  1736. exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL;
  1737. exports.DOMCanvasFactory = DOMCanvasFactory;
  1738. exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
  1739. /***/ }),
  1740. /* 2 */
  1741. /***/ (function(module, exports, __w_pdfjs_require__) {
  1742. "use strict";
  1743. Object.defineProperty(exports, "__esModule", {
  1744. value: true
  1745. });
  1746. exports.build = exports.version = exports._UnsupportedManager = exports.setPDFNetworkStreamClass = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFWorker = exports.PDFDataRangeTransport = exports.LoopbackPort = exports.getDocument = undefined;
  1747. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  1748. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  1749. var _util = __w_pdfjs_require__(0);
  1750. var _dom_utils = __w_pdfjs_require__(1);
  1751. var _font_loader = __w_pdfjs_require__(12);
  1752. var _canvas = __w_pdfjs_require__(11);
  1753. var _metadata = __w_pdfjs_require__(6);
  1754. var _transport_stream = __w_pdfjs_require__(14);
  1755. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1756. var DEFAULT_RANGE_CHUNK_SIZE = 65536;
  1757. var isWorkerDisabled = false;
  1758. var workerSrc;
  1759. var isPostMessageTransfersDisabled = false;
  1760. var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : null;
  1761. var fakeWorkerFilesLoader = null;
  1762. var useRequireEnsure = false;
  1763. {
  1764. if (typeof window === 'undefined') {
  1765. isWorkerDisabled = true;
  1766. if (typeof require.ensure === 'undefined') {
  1767. require.ensure = require('node-ensure');
  1768. }
  1769. useRequireEnsure = true;
  1770. } else if (typeof require !== 'undefined' && typeof require.ensure === 'function') {
  1771. useRequireEnsure = true;
  1772. }
  1773. if (typeof requirejs !== 'undefined' && requirejs.toUrl) {
  1774. workerSrc = requirejs.toUrl('pdfjs-dist/build/pdf.worker.js');
  1775. }
  1776. var dynamicLoaderSupported = typeof requirejs !== 'undefined' && requirejs.load;
  1777. fakeWorkerFilesLoader = useRequireEnsure ? function (callback) {
  1778. require.ensure([], function () {
  1779. var worker;
  1780. worker = require('./pdf.worker.js');
  1781. callback(worker.WorkerMessageHandler);
  1782. });
  1783. } : dynamicLoaderSupported ? function (callback) {
  1784. requirejs(['pdfjs-dist/build/pdf.worker'], function (worker) {
  1785. callback(worker.WorkerMessageHandler);
  1786. });
  1787. } : null;
  1788. }
  1789. var PDFNetworkStream;
  1790. function setPDFNetworkStreamClass(cls) {
  1791. PDFNetworkStream = cls;
  1792. }
  1793. function getDocument(src, pdfDataRangeTransport, passwordCallback, progressCallback) {
  1794. var task = new PDFDocumentLoadingTask();
  1795. if (arguments.length > 1) {
  1796. (0, _util.deprecated)('getDocument is called with pdfDataRangeTransport, ' + 'passwordCallback or progressCallback argument');
  1797. }
  1798. if (pdfDataRangeTransport) {
  1799. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  1800. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  1801. pdfDataRangeTransport.length = src.length;
  1802. pdfDataRangeTransport.initialData = src.initialData;
  1803. if (!pdfDataRangeTransport.abort) {
  1804. pdfDataRangeTransport.abort = function () {};
  1805. }
  1806. }
  1807. src = Object.create(src);
  1808. src.range = pdfDataRangeTransport;
  1809. }
  1810. task.onPassword = passwordCallback || null;
  1811. task.onProgress = progressCallback || null;
  1812. var source;
  1813. if (typeof src === 'string') {
  1814. source = { url: src };
  1815. } else if ((0, _util.isArrayBuffer)(src)) {
  1816. source = { data: src };
  1817. } else if (src instanceof PDFDataRangeTransport) {
  1818. source = { range: src };
  1819. } else {
  1820. if ((typeof src === 'undefined' ? 'undefined' : _typeof(src)) !== 'object') {
  1821. throw new Error('Invalid parameter in getDocument, ' + 'need either Uint8Array, string or a parameter object');
  1822. }
  1823. if (!src.url && !src.data && !src.range) {
  1824. throw new Error('Invalid parameter object: need either .data, .range or .url');
  1825. }
  1826. source = src;
  1827. }
  1828. var params = {};
  1829. var rangeTransport = null;
  1830. var worker = null;
  1831. var CMapReaderFactory = _dom_utils.DOMCMapReaderFactory;
  1832. for (var key in source) {
  1833. if (key === 'url' && typeof window !== 'undefined') {
  1834. params[key] = new URL(source[key], window.location).href;
  1835. continue;
  1836. } else if (key === 'range') {
  1837. rangeTransport = source[key];
  1838. continue;
  1839. } else if (key === 'worker') {
  1840. worker = source[key];
  1841. continue;
  1842. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  1843. var pdfBytes = source[key];
  1844. if (typeof pdfBytes === 'string') {
  1845. params[key] = (0, _util.stringToBytes)(pdfBytes);
  1846. } else if ((typeof pdfBytes === 'undefined' ? 'undefined' : _typeof(pdfBytes)) === 'object' && pdfBytes !== null && !isNaN(pdfBytes.length)) {
  1847. params[key] = new Uint8Array(pdfBytes);
  1848. } else if ((0, _util.isArrayBuffer)(pdfBytes)) {
  1849. params[key] = new Uint8Array(pdfBytes);
  1850. } else {
  1851. throw new Error('Invalid PDF binary data: either typed array, ' + 'string or array-like object is expected in the ' + 'data property.');
  1852. }
  1853. continue;
  1854. } else if (key === 'CMapReaderFactory') {
  1855. CMapReaderFactory = source[key];
  1856. continue;
  1857. }
  1858. params[key] = source[key];
  1859. }
  1860. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  1861. params.ignoreErrors = params.stopAtErrors !== true;
  1862. if (params.disableNativeImageDecoder !== undefined) {
  1863. (0, _util.deprecated)('parameter disableNativeImageDecoder, ' + 'use nativeImageDecoderSupport instead');
  1864. }
  1865. params.nativeImageDecoderSupport = params.nativeImageDecoderSupport || (params.disableNativeImageDecoder === true ? _util.NativeImageDecoding.NONE : _util.NativeImageDecoding.DECODE);
  1866. if (params.nativeImageDecoderSupport !== _util.NativeImageDecoding.DECODE && params.nativeImageDecoderSupport !== _util.NativeImageDecoding.NONE && params.nativeImageDecoderSupport !== _util.NativeImageDecoding.DISPLAY) {
  1867. (0, _util.warn)('Invalid parameter nativeImageDecoderSupport: ' + 'need a state of enum {NativeImageDecoding}');
  1868. params.nativeImageDecoderSupport = _util.NativeImageDecoding.DECODE;
  1869. }
  1870. if (!worker) {
  1871. var workerPort = (0, _dom_utils.getDefaultSetting)('workerPort');
  1872. worker = workerPort ? PDFWorker.fromPort(workerPort) : new PDFWorker();
  1873. task._worker = worker;
  1874. }
  1875. var docId = task.docId;
  1876. worker.promise.then(function () {
  1877. if (task.destroyed) {
  1878. throw new Error('Loading aborted');
  1879. }
  1880. return _fetchDocument(worker, params, rangeTransport, docId).then(function (workerId) {
  1881. if (task.destroyed) {
  1882. throw new Error('Loading aborted');
  1883. }
  1884. var networkStream = void 0;
  1885. if (rangeTransport) {
  1886. networkStream = new _transport_stream.PDFDataTransportStream(params, rangeTransport);
  1887. } else if (!params.data) {
  1888. networkStream = new PDFNetworkStream({
  1889. source: params,
  1890. disableRange: (0, _dom_utils.getDefaultSetting)('disableRange')
  1891. });
  1892. }
  1893. var messageHandler = new _util.MessageHandler(docId, workerId, worker.port);
  1894. messageHandler.postMessageTransfers = worker.postMessageTransfers;
  1895. var transport = new WorkerTransport(messageHandler, task, networkStream, CMapReaderFactory);
  1896. task._transport = transport;
  1897. messageHandler.send('Ready', null);
  1898. });
  1899. }).catch(task._capability.reject);
  1900. return task;
  1901. }
  1902. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  1903. if (worker.destroyed) {
  1904. return Promise.reject(new Error('Worker was destroyed'));
  1905. }
  1906. source.disableAutoFetch = (0, _dom_utils.getDefaultSetting)('disableAutoFetch');
  1907. source.disableStream = (0, _dom_utils.getDefaultSetting)('disableStream');
  1908. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  1909. if (pdfDataRangeTransport) {
  1910. source.length = pdfDataRangeTransport.length;
  1911. source.initialData = pdfDataRangeTransport.initialData;
  1912. }
  1913. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  1914. docId: docId,
  1915. source: {
  1916. data: source.data,
  1917. url: source.url,
  1918. password: source.password,
  1919. disableAutoFetch: source.disableAutoFetch,
  1920. rangeChunkSize: source.rangeChunkSize,
  1921. length: source.length
  1922. },
  1923. maxImageSize: (0, _dom_utils.getDefaultSetting)('maxImageSize'),
  1924. disableFontFace: (0, _dom_utils.getDefaultSetting)('disableFontFace'),
  1925. disableCreateObjectURL: (0, _dom_utils.getDefaultSetting)('disableCreateObjectURL'),
  1926. postMessageTransfers: (0, _dom_utils.getDefaultSetting)('postMessageTransfers') && !isPostMessageTransfersDisabled,
  1927. docBaseUrl: source.docBaseUrl,
  1928. nativeImageDecoderSupport: source.nativeImageDecoderSupport,
  1929. ignoreErrors: source.ignoreErrors
  1930. }).then(function (workerId) {
  1931. if (worker.destroyed) {
  1932. throw new Error('Worker was destroyed');
  1933. }
  1934. return workerId;
  1935. });
  1936. }
  1937. var PDFDocumentLoadingTask = function PDFDocumentLoadingTaskClosure() {
  1938. var nextDocumentId = 0;
  1939. function PDFDocumentLoadingTask() {
  1940. this._capability = (0, _util.createPromiseCapability)();
  1941. this._transport = null;
  1942. this._worker = null;
  1943. this.docId = 'd' + nextDocumentId++;
  1944. this.destroyed = false;
  1945. this.onPassword = null;
  1946. this.onProgress = null;
  1947. this.onUnsupportedFeature = null;
  1948. }
  1949. PDFDocumentLoadingTask.prototype = {
  1950. get promise() {
  1951. return this._capability.promise;
  1952. },
  1953. destroy: function destroy() {
  1954. var _this = this;
  1955. this.destroyed = true;
  1956. var transportDestroyed = !this._transport ? Promise.resolve() : this._transport.destroy();
  1957. return transportDestroyed.then(function () {
  1958. _this._transport = null;
  1959. if (_this._worker) {
  1960. _this._worker.destroy();
  1961. _this._worker = null;
  1962. }
  1963. });
  1964. },
  1965. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  1966. return this.promise.then.apply(this.promise, arguments);
  1967. }
  1968. };
  1969. return PDFDocumentLoadingTask;
  1970. }();
  1971. var PDFDataRangeTransport = function pdfDataRangeTransportClosure() {
  1972. function PDFDataRangeTransport(length, initialData) {
  1973. this.length = length;
  1974. this.initialData = initialData;
  1975. this._rangeListeners = [];
  1976. this._progressListeners = [];
  1977. this._progressiveReadListeners = [];
  1978. this._readyCapability = (0, _util.createPromiseCapability)();
  1979. }
  1980. PDFDataRangeTransport.prototype = {
  1981. addRangeListener: function PDFDataRangeTransport_addRangeListener(listener) {
  1982. this._rangeListeners.push(listener);
  1983. },
  1984. addProgressListener: function PDFDataRangeTransport_addProgressListener(listener) {
  1985. this._progressListeners.push(listener);
  1986. },
  1987. addProgressiveReadListener: function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  1988. this._progressiveReadListeners.push(listener);
  1989. },
  1990. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  1991. var listeners = this._rangeListeners;
  1992. for (var i = 0, n = listeners.length; i < n; ++i) {
  1993. listeners[i](begin, chunk);
  1994. }
  1995. },
  1996. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  1997. var _this2 = this;
  1998. this._readyCapability.promise.then(function () {
  1999. var listeners = _this2._progressListeners;
  2000. for (var i = 0, n = listeners.length; i < n; ++i) {
  2001. listeners[i](loaded);
  2002. }
  2003. });
  2004. },
  2005. onDataProgressiveRead: function PDFDataRangeTransport_onDataProgress(chunk) {
  2006. var _this3 = this;
  2007. this._readyCapability.promise.then(function () {
  2008. var listeners = _this3._progressiveReadListeners;
  2009. for (var i = 0, n = listeners.length; i < n; ++i) {
  2010. listeners[i](chunk);
  2011. }
  2012. });
  2013. },
  2014. transportReady: function PDFDataRangeTransport_transportReady() {
  2015. this._readyCapability.resolve();
  2016. },
  2017. requestDataRange: function PDFDataRangeTransport_requestDataRange(begin, end) {
  2018. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  2019. },
  2020. abort: function PDFDataRangeTransport_abort() {}
  2021. };
  2022. return PDFDataRangeTransport;
  2023. }();
  2024. var PDFDocumentProxy = function PDFDocumentProxyClosure() {
  2025. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  2026. this.pdfInfo = pdfInfo;
  2027. this.transport = transport;
  2028. this.loadingTask = loadingTask;
  2029. }
  2030. PDFDocumentProxy.prototype = {
  2031. get numPages() {
  2032. return this.pdfInfo.numPages;
  2033. },
  2034. get fingerprint() {
  2035. return this.pdfInfo.fingerprint;
  2036. },
  2037. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  2038. return this.transport.getPage(pageNumber);
  2039. },
  2040. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  2041. return this.transport.getPageIndex(ref);
  2042. },
  2043. getDestinations: function PDFDocumentProxy_getDestinations() {
  2044. return this.transport.getDestinations();
  2045. },
  2046. getDestination: function PDFDocumentProxy_getDestination(id) {
  2047. return this.transport.getDestination(id);
  2048. },
  2049. getPageLabels: function PDFDocumentProxy_getPageLabels() {
  2050. return this.transport.getPageLabels();
  2051. },
  2052. getPageMode: function getPageMode() {
  2053. return this.transport.getPageMode();
  2054. },
  2055. getAttachments: function PDFDocumentProxy_getAttachments() {
  2056. return this.transport.getAttachments();
  2057. },
  2058. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  2059. return this.transport.getJavaScript();
  2060. },
  2061. getOutline: function PDFDocumentProxy_getOutline() {
  2062. return this.transport.getOutline();
  2063. },
  2064. getMetadata: function PDFDocumentProxy_getMetadata() {
  2065. return this.transport.getMetadata();
  2066. },
  2067. getData: function PDFDocumentProxy_getData() {
  2068. return this.transport.getData();
  2069. },
  2070. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  2071. return this.transport.downloadInfoCapability.promise;
  2072. },
  2073. getStats: function PDFDocumentProxy_getStats() {
  2074. return this.transport.getStats();
  2075. },
  2076. cleanup: function PDFDocumentProxy_cleanup() {
  2077. this.transport.startCleanup();
  2078. },
  2079. destroy: function PDFDocumentProxy_destroy() {
  2080. return this.loadingTask.destroy();
  2081. }
  2082. };
  2083. return PDFDocumentProxy;
  2084. }();
  2085. var PDFPageProxy = function PDFPageProxyClosure() {
  2086. function PDFPageProxy(pageIndex, pageInfo, transport) {
  2087. this.pageIndex = pageIndex;
  2088. this.pageInfo = pageInfo;
  2089. this.transport = transport;
  2090. this.stats = new _util.StatTimer();
  2091. this.stats.enabled = (0, _dom_utils.getDefaultSetting)('enableStats');
  2092. this.commonObjs = transport.commonObjs;
  2093. this.objs = new PDFObjects();
  2094. this.cleanupAfterRender = false;
  2095. this.pendingCleanup = false;
  2096. this.intentStates = Object.create(null);
  2097. this.destroyed = false;
  2098. }
  2099. PDFPageProxy.prototype = {
  2100. get pageNumber() {
  2101. return this.pageIndex + 1;
  2102. },
  2103. get rotate() {
  2104. return this.pageInfo.rotate;
  2105. },
  2106. get ref() {
  2107. return this.pageInfo.ref;
  2108. },
  2109. get userUnit() {
  2110. return this.pageInfo.userUnit;
  2111. },
  2112. get view() {
  2113. return this.pageInfo.view;
  2114. },
  2115. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  2116. if (arguments.length < 2) {
  2117. rotate = this.rotate;
  2118. }
  2119. return new _util.PageViewport(this.view, scale, rotate, 0, 0);
  2120. },
  2121. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  2122. var intent = params && params.intent || null;
  2123. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  2124. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex, intent);
  2125. this.annotationsIntent = intent;
  2126. }
  2127. return this.annotationsPromise;
  2128. },
  2129. render: function PDFPageProxy_render(params) {
  2130. var _this4 = this;
  2131. var stats = this.stats;
  2132. stats.time('Overall');
  2133. this.pendingCleanup = false;
  2134. var renderingIntent = params.intent === 'print' ? 'print' : 'display';
  2135. var canvasFactory = params.canvasFactory || new _dom_utils.DOMCanvasFactory();
  2136. if (!this.intentStates[renderingIntent]) {
  2137. this.intentStates[renderingIntent] = Object.create(null);
  2138. }
  2139. var intentState = this.intentStates[renderingIntent];
  2140. if (!intentState.displayReadyCapability) {
  2141. intentState.receivingOperatorList = true;
  2142. intentState.displayReadyCapability = (0, _util.createPromiseCapability)();
  2143. intentState.operatorList = {
  2144. fnArray: [],
  2145. argsArray: [],
  2146. lastChunk: false
  2147. };
  2148. this.stats.time('Page Request');
  2149. this.transport.messageHandler.send('RenderPageRequest', {
  2150. pageIndex: this.pageNumber - 1,
  2151. intent: renderingIntent,
  2152. renderInteractiveForms: params.renderInteractiveForms === true
  2153. });
  2154. }
  2155. var complete = function complete(error) {
  2156. var i = intentState.renderTasks.indexOf(internalRenderTask);
  2157. if (i >= 0) {
  2158. intentState.renderTasks.splice(i, 1);
  2159. }
  2160. if (_this4.cleanupAfterRender) {
  2161. _this4.pendingCleanup = true;
  2162. }
  2163. _this4._tryCleanup();
  2164. if (error) {
  2165. internalRenderTask.capability.reject(error);
  2166. } else {
  2167. internalRenderTask.capability.resolve();
  2168. }
  2169. stats.timeEnd('Rendering');
  2170. stats.timeEnd('Overall');
  2171. };
  2172. var internalRenderTask = new InternalRenderTask(complete, params, this.objs, this.commonObjs, intentState.operatorList, this.pageNumber, canvasFactory);
  2173. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  2174. if (!intentState.renderTasks) {
  2175. intentState.renderTasks = [];
  2176. }
  2177. intentState.renderTasks.push(internalRenderTask);
  2178. var renderTask = internalRenderTask.task;
  2179. if (params.continueCallback) {
  2180. (0, _util.deprecated)('render is used with continueCallback parameter');
  2181. renderTask.onContinue = params.continueCallback;
  2182. }
  2183. intentState.displayReadyCapability.promise.then(function (transparency) {
  2184. if (_this4.pendingCleanup) {
  2185. complete();
  2186. return;
  2187. }
  2188. stats.time('Rendering');
  2189. internalRenderTask.initializeGraphics(transparency);
  2190. internalRenderTask.operatorListChanged();
  2191. }).catch(complete);
  2192. return renderTask;
  2193. },
  2194. getOperatorList: function PDFPageProxy_getOperatorList() {
  2195. function operatorListChanged() {
  2196. if (intentState.operatorList.lastChunk) {
  2197. intentState.opListReadCapability.resolve(intentState.operatorList);
  2198. var i = intentState.renderTasks.indexOf(opListTask);
  2199. if (i >= 0) {
  2200. intentState.renderTasks.splice(i, 1);
  2201. }
  2202. }
  2203. }
  2204. var renderingIntent = 'oplist';
  2205. if (!this.intentStates[renderingIntent]) {
  2206. this.intentStates[renderingIntent] = Object.create(null);
  2207. }
  2208. var intentState = this.intentStates[renderingIntent];
  2209. var opListTask;
  2210. if (!intentState.opListReadCapability) {
  2211. opListTask = {};
  2212. opListTask.operatorListChanged = operatorListChanged;
  2213. intentState.receivingOperatorList = true;
  2214. intentState.opListReadCapability = (0, _util.createPromiseCapability)();
  2215. intentState.renderTasks = [];
  2216. intentState.renderTasks.push(opListTask);
  2217. intentState.operatorList = {
  2218. fnArray: [],
  2219. argsArray: [],
  2220. lastChunk: false
  2221. };
  2222. this.transport.messageHandler.send('RenderPageRequest', {
  2223. pageIndex: this.pageIndex,
  2224. intent: renderingIntent
  2225. });
  2226. }
  2227. return intentState.opListReadCapability.promise;
  2228. },
  2229. streamTextContent: function streamTextContent() {
  2230. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  2231. var TEXT_CONTENT_CHUNK_SIZE = 100;
  2232. return this.transport.messageHandler.sendWithStream('GetTextContent', {
  2233. pageIndex: this.pageNumber - 1,
  2234. normalizeWhitespace: params.normalizeWhitespace === true,
  2235. combineTextItems: params.disableCombineTextItems !== true
  2236. }, {
  2237. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  2238. size: function size(textContent) {
  2239. return textContent.items.length;
  2240. }
  2241. });
  2242. },
  2243. getTextContent: function PDFPageProxy_getTextContent(params) {
  2244. params = params || {};
  2245. var readableStream = this.streamTextContent(params);
  2246. return new Promise(function (resolve, reject) {
  2247. function pump() {
  2248. reader.read().then(function (_ref) {
  2249. var value = _ref.value,
  2250. done = _ref.done;
  2251. if (done) {
  2252. resolve(textContent);
  2253. return;
  2254. }
  2255. _util.Util.extendObj(textContent.styles, value.styles);
  2256. _util.Util.appendToArray(textContent.items, value.items);
  2257. pump();
  2258. }, reject);
  2259. }
  2260. var reader = readableStream.getReader();
  2261. var textContent = {
  2262. items: [],
  2263. styles: Object.create(null)
  2264. };
  2265. pump();
  2266. });
  2267. },
  2268. _destroy: function PDFPageProxy_destroy() {
  2269. this.destroyed = true;
  2270. this.transport.pageCache[this.pageIndex] = null;
  2271. var waitOn = [];
  2272. Object.keys(this.intentStates).forEach(function (intent) {
  2273. if (intent === 'oplist') {
  2274. return;
  2275. }
  2276. var intentState = this.intentStates[intent];
  2277. intentState.renderTasks.forEach(function (renderTask) {
  2278. var renderCompleted = renderTask.capability.promise.catch(function () {});
  2279. waitOn.push(renderCompleted);
  2280. renderTask.cancel();
  2281. });
  2282. }, this);
  2283. this.objs.clear();
  2284. this.annotationsPromise = null;
  2285. this.pendingCleanup = false;
  2286. return Promise.all(waitOn);
  2287. },
  2288. destroy: function destroy() {
  2289. (0, _util.deprecated)('page destroy method, use cleanup() instead');
  2290. this.cleanup();
  2291. },
  2292. cleanup: function PDFPageProxy_cleanup() {
  2293. this.pendingCleanup = true;
  2294. this._tryCleanup();
  2295. },
  2296. _tryCleanup: function PDFPageProxy_tryCleanup() {
  2297. if (!this.pendingCleanup || Object.keys(this.intentStates).some(function (intent) {
  2298. var intentState = this.intentStates[intent];
  2299. return intentState.renderTasks.length !== 0 || intentState.receivingOperatorList;
  2300. }, this)) {
  2301. return;
  2302. }
  2303. Object.keys(this.intentStates).forEach(function (intent) {
  2304. delete this.intentStates[intent];
  2305. }, this);
  2306. this.objs.clear();
  2307. this.annotationsPromise = null;
  2308. this.pendingCleanup = false;
  2309. },
  2310. _startRenderPage: function PDFPageProxy_startRenderPage(transparency, intent) {
  2311. var intentState = this.intentStates[intent];
  2312. if (intentState.displayReadyCapability) {
  2313. intentState.displayReadyCapability.resolve(transparency);
  2314. }
  2315. },
  2316. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk, intent) {
  2317. var intentState = this.intentStates[intent];
  2318. var i, ii;
  2319. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2320. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2321. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  2322. }
  2323. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2324. for (i = 0; i < intentState.renderTasks.length; i++) {
  2325. intentState.renderTasks[i].operatorListChanged();
  2326. }
  2327. if (operatorListChunk.lastChunk) {
  2328. intentState.receivingOperatorList = false;
  2329. this._tryCleanup();
  2330. }
  2331. }
  2332. };
  2333. return PDFPageProxy;
  2334. }();
  2335. var LoopbackPort = function () {
  2336. function LoopbackPort(defer) {
  2337. _classCallCheck(this, LoopbackPort);
  2338. this._listeners = [];
  2339. this._defer = defer;
  2340. this._deferred = Promise.resolve(undefined);
  2341. }
  2342. _createClass(LoopbackPort, [{
  2343. key: 'postMessage',
  2344. value: function postMessage(obj, transfers) {
  2345. var _this5 = this;
  2346. function cloneValue(value) {
  2347. if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) !== 'object' || value === null) {
  2348. return value;
  2349. }
  2350. if (cloned.has(value)) {
  2351. return cloned.get(value);
  2352. }
  2353. var result;
  2354. var buffer;
  2355. if ((buffer = value.buffer) && (0, _util.isArrayBuffer)(buffer)) {
  2356. var transferable = transfers && transfers.indexOf(buffer) >= 0;
  2357. if (value === buffer) {
  2358. result = value;
  2359. } else if (transferable) {
  2360. result = new value.constructor(buffer, value.byteOffset, value.byteLength);
  2361. } else {
  2362. result = new value.constructor(value);
  2363. }
  2364. cloned.set(value, result);
  2365. return result;
  2366. }
  2367. result = (0, _util.isArray)(value) ? [] : {};
  2368. cloned.set(value, result);
  2369. for (var i in value) {
  2370. var desc,
  2371. p = value;
  2372. while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
  2373. p = Object.getPrototypeOf(p);
  2374. }
  2375. if (typeof desc.value === 'undefined' || typeof desc.value === 'function') {
  2376. continue;
  2377. }
  2378. result[i] = cloneValue(desc.value);
  2379. }
  2380. return result;
  2381. }
  2382. if (!this._defer) {
  2383. this._listeners.forEach(function (listener) {
  2384. listener.call(this, { data: obj });
  2385. }, this);
  2386. return;
  2387. }
  2388. var cloned = new WeakMap();
  2389. var e = { data: cloneValue(obj) };
  2390. this._deferred.then(function () {
  2391. _this5._listeners.forEach(function (listener) {
  2392. listener.call(this, e);
  2393. }, _this5);
  2394. });
  2395. }
  2396. }, {
  2397. key: 'addEventListener',
  2398. value: function addEventListener(name, listener) {
  2399. this._listeners.push(listener);
  2400. }
  2401. }, {
  2402. key: 'removeEventListener',
  2403. value: function removeEventListener(name, listener) {
  2404. var i = this._listeners.indexOf(listener);
  2405. this._listeners.splice(i, 1);
  2406. }
  2407. }, {
  2408. key: 'terminate',
  2409. value: function terminate() {
  2410. this._listeners = [];
  2411. }
  2412. }]);
  2413. return LoopbackPort;
  2414. }();
  2415. var PDFWorker = function PDFWorkerClosure() {
  2416. var nextFakeWorkerId = 0;
  2417. function getWorkerSrc() {
  2418. if (typeof workerSrc !== 'undefined') {
  2419. return workerSrc;
  2420. }
  2421. if ((0, _dom_utils.getDefaultSetting)('workerSrc')) {
  2422. return (0, _dom_utils.getDefaultSetting)('workerSrc');
  2423. }
  2424. if (pdfjsFilePath) {
  2425. return pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, '.worker$1$2');
  2426. }
  2427. throw new Error('No PDFJS.workerSrc specified');
  2428. }
  2429. var fakeWorkerFilesLoadedCapability = void 0;
  2430. function setupFakeWorkerGlobal() {
  2431. var WorkerMessageHandler;
  2432. if (fakeWorkerFilesLoadedCapability) {
  2433. return fakeWorkerFilesLoadedCapability.promise;
  2434. }
  2435. fakeWorkerFilesLoadedCapability = (0, _util.createPromiseCapability)();
  2436. var loader = fakeWorkerFilesLoader || function (callback) {
  2437. _util.Util.loadScript(getWorkerSrc(), function () {
  2438. callback(window.pdfjsDistBuildPdfWorker.WorkerMessageHandler);
  2439. });
  2440. };
  2441. loader(fakeWorkerFilesLoadedCapability.resolve);
  2442. return fakeWorkerFilesLoadedCapability.promise;
  2443. }
  2444. function createCDNWrapper(url) {
  2445. var wrapper = 'importScripts(\'' + url + '\');';
  2446. return URL.createObjectURL(new Blob([wrapper]));
  2447. }
  2448. var pdfWorkerPorts = new WeakMap();
  2449. function PDFWorker(name, port) {
  2450. if (port && pdfWorkerPorts.has(port)) {
  2451. throw new Error('Cannot use more than one PDFWorker per port');
  2452. }
  2453. this.name = name;
  2454. this.destroyed = false;
  2455. this.postMessageTransfers = true;
  2456. this._readyCapability = (0, _util.createPromiseCapability)();
  2457. this._port = null;
  2458. this._webWorker = null;
  2459. this._messageHandler = null;
  2460. if (port) {
  2461. pdfWorkerPorts.set(port, this);
  2462. this._initializeFromPort(port);
  2463. return;
  2464. }
  2465. this._initialize();
  2466. }
  2467. PDFWorker.prototype = {
  2468. get promise() {
  2469. return this._readyCapability.promise;
  2470. },
  2471. get port() {
  2472. return this._port;
  2473. },
  2474. get messageHandler() {
  2475. return this._messageHandler;
  2476. },
  2477. _initializeFromPort: function PDFWorker_initializeFromPort(port) {
  2478. this._port = port;
  2479. this._messageHandler = new _util.MessageHandler('main', 'worker', port);
  2480. this._messageHandler.on('ready', function () {});
  2481. this._readyCapability.resolve();
  2482. },
  2483. _initialize: function PDFWorker_initialize() {
  2484. var _this6 = this;
  2485. if (!isWorkerDisabled && !(0, _dom_utils.getDefaultSetting)('disableWorker') && typeof Worker !== 'undefined') {
  2486. var workerSrc = getWorkerSrc();
  2487. try {
  2488. if (!(0, _util.isSameOrigin)(window.location.href, workerSrc)) {
  2489. workerSrc = createCDNWrapper(new URL(workerSrc, window.location).href);
  2490. }
  2491. var worker = new Worker(workerSrc);
  2492. var messageHandler = new _util.MessageHandler('main', 'worker', worker);
  2493. var terminateEarly = function terminateEarly() {
  2494. worker.removeEventListener('error', onWorkerError);
  2495. messageHandler.destroy();
  2496. worker.terminate();
  2497. if (_this6.destroyed) {
  2498. _this6._readyCapability.reject(new Error('Worker was destroyed'));
  2499. } else {
  2500. _this6._setupFakeWorker();
  2501. }
  2502. };
  2503. var onWorkerError = function onWorkerError() {
  2504. if (!_this6._webWorker) {
  2505. terminateEarly();
  2506. }
  2507. };
  2508. worker.addEventListener('error', onWorkerError);
  2509. messageHandler.on('test', function (data) {
  2510. worker.removeEventListener('error', onWorkerError);
  2511. if (_this6.destroyed) {
  2512. terminateEarly();
  2513. return;
  2514. }
  2515. var supportTypedArray = data && data.supportTypedArray;
  2516. if (supportTypedArray) {
  2517. _this6._messageHandler = messageHandler;
  2518. _this6._port = worker;
  2519. _this6._webWorker = worker;
  2520. if (!data.supportTransfers) {
  2521. _this6.postMessageTransfers = false;
  2522. isPostMessageTransfersDisabled = true;
  2523. }
  2524. _this6._readyCapability.resolve();
  2525. messageHandler.send('configure', { verbosity: (0, _util.getVerbosityLevel)() });
  2526. } else {
  2527. _this6._setupFakeWorker();
  2528. messageHandler.destroy();
  2529. worker.terminate();
  2530. }
  2531. });
  2532. messageHandler.on('console_log', function (data) {
  2533. console.log.apply(console, data);
  2534. });
  2535. messageHandler.on('console_error', function (data) {
  2536. console.error.apply(console, data);
  2537. });
  2538. messageHandler.on('ready', function (data) {
  2539. worker.removeEventListener('error', onWorkerError);
  2540. if (_this6.destroyed) {
  2541. terminateEarly();
  2542. return;
  2543. }
  2544. try {
  2545. sendTest();
  2546. } catch (e) {
  2547. _this6._setupFakeWorker();
  2548. }
  2549. });
  2550. var sendTest = function sendTest() {
  2551. var postMessageTransfers = (0, _dom_utils.getDefaultSetting)('postMessageTransfers') && !isPostMessageTransfersDisabled;
  2552. var testObj = new Uint8Array([postMessageTransfers ? 255 : 0]);
  2553. try {
  2554. messageHandler.send('test', testObj, [testObj.buffer]);
  2555. } catch (ex) {
  2556. (0, _util.info)('Cannot use postMessage transfers');
  2557. testObj[0] = 0;
  2558. messageHandler.send('test', testObj);
  2559. }
  2560. };
  2561. sendTest();
  2562. return;
  2563. } catch (e) {
  2564. (0, _util.info)('The worker has been disabled.');
  2565. }
  2566. }
  2567. this._setupFakeWorker();
  2568. },
  2569. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  2570. var _this7 = this;
  2571. if (!isWorkerDisabled && !(0, _dom_utils.getDefaultSetting)('disableWorker')) {
  2572. (0, _util.warn)('Setting up fake worker.');
  2573. isWorkerDisabled = true;
  2574. }
  2575. setupFakeWorkerGlobal().then(function (WorkerMessageHandler) {
  2576. if (_this7.destroyed) {
  2577. _this7._readyCapability.reject(new Error('Worker was destroyed'));
  2578. return;
  2579. }
  2580. var isTypedArraysPresent = Uint8Array !== Float32Array;
  2581. var port = new LoopbackPort(isTypedArraysPresent);
  2582. _this7._port = port;
  2583. var id = 'fake' + nextFakeWorkerId++;
  2584. var workerHandler = new _util.MessageHandler(id + '_worker', id, port);
  2585. WorkerMessageHandler.setup(workerHandler, port);
  2586. var messageHandler = new _util.MessageHandler(id, id + '_worker', port);
  2587. _this7._messageHandler = messageHandler;
  2588. _this7._readyCapability.resolve();
  2589. });
  2590. },
  2591. destroy: function PDFWorker_destroy() {
  2592. this.destroyed = true;
  2593. if (this._webWorker) {
  2594. this._webWorker.terminate();
  2595. this._webWorker = null;
  2596. }
  2597. pdfWorkerPorts.delete(this._port);
  2598. this._port = null;
  2599. if (this._messageHandler) {
  2600. this._messageHandler.destroy();
  2601. this._messageHandler = null;
  2602. }
  2603. }
  2604. };
  2605. PDFWorker.fromPort = function (port) {
  2606. if (pdfWorkerPorts.has(port)) {
  2607. return pdfWorkerPorts.get(port);
  2608. }
  2609. return new PDFWorker(null, port);
  2610. };
  2611. return PDFWorker;
  2612. }();
  2613. var WorkerTransport = function WorkerTransportClosure() {
  2614. function WorkerTransport(messageHandler, loadingTask, networkStream, CMapReaderFactory) {
  2615. this.messageHandler = messageHandler;
  2616. this.loadingTask = loadingTask;
  2617. this.commonObjs = new PDFObjects();
  2618. this.fontLoader = new _font_loader.FontLoader(loadingTask.docId);
  2619. this.CMapReaderFactory = new CMapReaderFactory({
  2620. baseUrl: (0, _dom_utils.getDefaultSetting)('cMapUrl'),
  2621. isCompressed: (0, _dom_utils.getDefaultSetting)('cMapPacked')
  2622. });
  2623. this.destroyed = false;
  2624. this.destroyCapability = null;
  2625. this._passwordCapability = null;
  2626. this._networkStream = networkStream;
  2627. this._fullReader = null;
  2628. this._lastProgress = null;
  2629. this.pageCache = [];
  2630. this.pagePromises = [];
  2631. this.downloadInfoCapability = (0, _util.createPromiseCapability)();
  2632. this.setupMessageHandler();
  2633. }
  2634. WorkerTransport.prototype = {
  2635. destroy: function WorkerTransport_destroy() {
  2636. var _this8 = this;
  2637. if (this.destroyCapability) {
  2638. return this.destroyCapability.promise;
  2639. }
  2640. this.destroyed = true;
  2641. this.destroyCapability = (0, _util.createPromiseCapability)();
  2642. if (this._passwordCapability) {
  2643. this._passwordCapability.reject(new Error('Worker was destroyed during onPassword callback'));
  2644. }
  2645. var waitOn = [];
  2646. this.pageCache.forEach(function (page) {
  2647. if (page) {
  2648. waitOn.push(page._destroy());
  2649. }
  2650. });
  2651. this.pageCache = [];
  2652. this.pagePromises = [];
  2653. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  2654. waitOn.push(terminated);
  2655. Promise.all(waitOn).then(function () {
  2656. _this8.fontLoader.clear();
  2657. if (_this8._networkStream) {
  2658. _this8._networkStream.cancelAllRequests();
  2659. }
  2660. if (_this8.messageHandler) {
  2661. _this8.messageHandler.destroy();
  2662. _this8.messageHandler = null;
  2663. }
  2664. _this8.destroyCapability.resolve();
  2665. }, this.destroyCapability.reject);
  2666. return this.destroyCapability.promise;
  2667. },
  2668. setupMessageHandler: function WorkerTransport_setupMessageHandler() {
  2669. var messageHandler = this.messageHandler;
  2670. var loadingTask = this.loadingTask;
  2671. messageHandler.on('GetReader', function (data, sink) {
  2672. var _this9 = this;
  2673. (0, _util.assert)(this._networkStream);
  2674. this._fullReader = this._networkStream.getFullReader();
  2675. this._fullReader.onProgress = function (evt) {
  2676. _this9._lastProgress = {
  2677. loaded: evt.loaded,
  2678. total: evt.total
  2679. };
  2680. };
  2681. sink.onPull = function () {
  2682. _this9._fullReader.read().then(function (_ref2) {
  2683. var value = _ref2.value,
  2684. done = _ref2.done;
  2685. if (done) {
  2686. sink.close();
  2687. return;
  2688. }
  2689. (0, _util.assert)((0, _util.isArrayBuffer)(value));
  2690. sink.enqueue(new Uint8Array(value), 1, [value]);
  2691. }).catch(function (reason) {
  2692. sink.error(reason);
  2693. });
  2694. };
  2695. sink.onCancel = function (reason) {
  2696. _this9._fullReader.cancel(reason);
  2697. };
  2698. }, this);
  2699. messageHandler.on('ReaderHeadersReady', function (data) {
  2700. var _this10 = this;
  2701. var headersCapability = (0, _util.createPromiseCapability)();
  2702. var fullReader = this._fullReader;
  2703. fullReader.headersReady.then(function () {
  2704. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  2705. if (_this10._lastProgress) {
  2706. var _loadingTask = _this10.loadingTask;
  2707. if (_loadingTask.onProgress) {
  2708. _loadingTask.onProgress(_this10._lastProgress);
  2709. }
  2710. }
  2711. fullReader.onProgress = function (evt) {
  2712. var loadingTask = _this10.loadingTask;
  2713. if (loadingTask.onProgress) {
  2714. loadingTask.onProgress({
  2715. loaded: evt.loaded,
  2716. total: evt.total
  2717. });
  2718. }
  2719. };
  2720. }
  2721. headersCapability.resolve({
  2722. isStreamingSupported: fullReader.isStreamingSupported,
  2723. isRangeSupported: fullReader.isRangeSupported,
  2724. contentLength: fullReader.contentLength
  2725. });
  2726. }, headersCapability.reject);
  2727. return headersCapability.promise;
  2728. }, this);
  2729. messageHandler.on('GetRangeReader', function (data, sink) {
  2730. (0, _util.assert)(this._networkStream);
  2731. var _rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
  2732. sink.onPull = function () {
  2733. _rangeReader.read().then(function (_ref3) {
  2734. var value = _ref3.value,
  2735. done = _ref3.done;
  2736. if (done) {
  2737. sink.close();
  2738. return;
  2739. }
  2740. (0, _util.assert)((0, _util.isArrayBuffer)(value));
  2741. sink.enqueue(new Uint8Array(value), 1, [value]);
  2742. }).catch(function (reason) {
  2743. sink.error(reason);
  2744. });
  2745. };
  2746. sink.onCancel = function (reason) {
  2747. _rangeReader.cancel(reason);
  2748. };
  2749. }, this);
  2750. messageHandler.on('GetDoc', function transportDoc(data) {
  2751. var pdfInfo = data.pdfInfo;
  2752. this.numPages = data.pdfInfo.numPages;
  2753. var loadingTask = this.loadingTask;
  2754. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  2755. this.pdfDocument = pdfDocument;
  2756. loadingTask._capability.resolve(pdfDocument);
  2757. }, this);
  2758. messageHandler.on('PasswordRequest', function transportPasswordRequest(exception) {
  2759. var _this11 = this;
  2760. this._passwordCapability = (0, _util.createPromiseCapability)();
  2761. if (loadingTask.onPassword) {
  2762. var updatePassword = function updatePassword(password) {
  2763. _this11._passwordCapability.resolve({ password: password });
  2764. };
  2765. loadingTask.onPassword(updatePassword, exception.code);
  2766. } else {
  2767. this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code));
  2768. }
  2769. return this._passwordCapability.promise;
  2770. }, this);
  2771. messageHandler.on('PasswordException', function transportPasswordException(exception) {
  2772. loadingTask._capability.reject(new _util.PasswordException(exception.message, exception.code));
  2773. }, this);
  2774. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  2775. this.loadingTask._capability.reject(new _util.InvalidPDFException(exception.message));
  2776. }, this);
  2777. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  2778. this.loadingTask._capability.reject(new _util.MissingPDFException(exception.message));
  2779. }, this);
  2780. messageHandler.on('UnexpectedResponse', function transportUnexpectedResponse(exception) {
  2781. this.loadingTask._capability.reject(new _util.UnexpectedResponseException(exception.message, exception.status));
  2782. }, this);
  2783. messageHandler.on('UnknownError', function transportUnknownError(exception) {
  2784. this.loadingTask._capability.reject(new _util.UnknownErrorException(exception.message, exception.details));
  2785. }, this);
  2786. messageHandler.on('DataLoaded', function transportPage(data) {
  2787. this.downloadInfoCapability.resolve(data);
  2788. }, this);
  2789. messageHandler.on('PDFManagerReady', function transportPage(data) {}, this);
  2790. messageHandler.on('StartRenderPage', function transportRender(data) {
  2791. if (this.destroyed) {
  2792. return;
  2793. }
  2794. var page = this.pageCache[data.pageIndex];
  2795. page.stats.timeEnd('Page Request');
  2796. page._startRenderPage(data.transparency, data.intent);
  2797. }, this);
  2798. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2799. if (this.destroyed) {
  2800. return;
  2801. }
  2802. var page = this.pageCache[data.pageIndex];
  2803. page._renderPageChunk(data.operatorList, data.intent);
  2804. }, this);
  2805. messageHandler.on('commonobj', function transportObj(data) {
  2806. var _this12 = this;
  2807. if (this.destroyed) {
  2808. return;
  2809. }
  2810. var id = data[0];
  2811. var type = data[1];
  2812. if (this.commonObjs.hasData(id)) {
  2813. return;
  2814. }
  2815. switch (type) {
  2816. case 'Font':
  2817. var exportedData = data[2];
  2818. if ('error' in exportedData) {
  2819. var exportedError = exportedData.error;
  2820. (0, _util.warn)('Error during font loading: ' + exportedError);
  2821. this.commonObjs.resolve(id, exportedError);
  2822. break;
  2823. }
  2824. var fontRegistry = null;
  2825. if ((0, _dom_utils.getDefaultSetting)('pdfBug') && _util.globalScope.FontInspector && _util.globalScope['FontInspector'].enabled) {
  2826. fontRegistry = {
  2827. registerFont: function registerFont(font, url) {
  2828. _util.globalScope['FontInspector'].fontAdded(font, url);
  2829. }
  2830. };
  2831. }
  2832. var font = new _font_loader.FontFaceObject(exportedData, {
  2833. isEvalSuported: (0, _dom_utils.getDefaultSetting)('isEvalSupported'),
  2834. disableFontFace: (0, _dom_utils.getDefaultSetting)('disableFontFace'),
  2835. fontRegistry: fontRegistry
  2836. });
  2837. var fontReady = function fontReady(fontObjs) {
  2838. _this12.commonObjs.resolve(id, font);
  2839. };
  2840. this.fontLoader.bind([font], fontReady);
  2841. break;
  2842. case 'FontPath':
  2843. this.commonObjs.resolve(id, data[2]);
  2844. break;
  2845. default:
  2846. throw new Error('Got unknown common object type ' + type);
  2847. }
  2848. }, this);
  2849. messageHandler.on('obj', function transportObj(data) {
  2850. if (this.destroyed) {
  2851. return;
  2852. }
  2853. var id = data[0];
  2854. var pageIndex = data[1];
  2855. var type = data[2];
  2856. var pageProxy = this.pageCache[pageIndex];
  2857. var imageData;
  2858. if (pageProxy.objs.hasData(id)) {
  2859. return;
  2860. }
  2861. switch (type) {
  2862. case 'JpegStream':
  2863. imageData = data[3];
  2864. (0, _util.loadJpegStream)(id, imageData, pageProxy.objs);
  2865. break;
  2866. case 'Image':
  2867. imageData = data[3];
  2868. pageProxy.objs.resolve(id, imageData);
  2869. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2870. if (imageData && 'data' in imageData && imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2871. pageProxy.cleanupAfterRender = true;
  2872. }
  2873. break;
  2874. default:
  2875. throw new Error('Got unknown object type ' + type);
  2876. }
  2877. }, this);
  2878. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2879. if (this.destroyed) {
  2880. return;
  2881. }
  2882. var loadingTask = this.loadingTask;
  2883. if (loadingTask.onProgress) {
  2884. loadingTask.onProgress({
  2885. loaded: data.loaded,
  2886. total: data.total
  2887. });
  2888. }
  2889. }, this);
  2890. messageHandler.on('PageError', function transportError(data) {
  2891. if (this.destroyed) {
  2892. return;
  2893. }
  2894. var page = this.pageCache[data.pageNum - 1];
  2895. var intentState = page.intentStates[data.intent];
  2896. if (intentState.displayReadyCapability) {
  2897. intentState.displayReadyCapability.reject(data.error);
  2898. } else {
  2899. throw new Error(data.error);
  2900. }
  2901. if (intentState.operatorList) {
  2902. intentState.operatorList.lastChunk = true;
  2903. for (var i = 0; i < intentState.renderTasks.length; i++) {
  2904. intentState.renderTasks[i].operatorListChanged();
  2905. }
  2906. }
  2907. }, this);
  2908. messageHandler.on('UnsupportedFeature', function transportUnsupportedFeature(data) {
  2909. if (this.destroyed) {
  2910. return;
  2911. }
  2912. var featureId = data.featureId;
  2913. var loadingTask = this.loadingTask;
  2914. if (loadingTask.onUnsupportedFeature) {
  2915. loadingTask.onUnsupportedFeature(featureId);
  2916. }
  2917. _UnsupportedManager.notify(featureId);
  2918. }, this);
  2919. messageHandler.on('JpegDecode', function (data) {
  2920. if (this.destroyed) {
  2921. return Promise.reject(new Error('Worker was destroyed'));
  2922. }
  2923. if (typeof document === 'undefined') {
  2924. return Promise.reject(new Error('"document" is not defined.'));
  2925. }
  2926. var imageUrl = data[0];
  2927. var components = data[1];
  2928. if (components !== 3 && components !== 1) {
  2929. return Promise.reject(new Error('Only 3 components or 1 component can be returned'));
  2930. }
  2931. return new Promise(function (resolve, reject) {
  2932. var img = new Image();
  2933. img.onload = function () {
  2934. var width = img.width;
  2935. var height = img.height;
  2936. var size = width * height;
  2937. var rgbaLength = size * 4;
  2938. var buf = new Uint8Array(size * components);
  2939. var tmpCanvas = document.createElement('canvas');
  2940. tmpCanvas.width = width;
  2941. tmpCanvas.height = height;
  2942. var tmpCtx = tmpCanvas.getContext('2d');
  2943. tmpCtx.drawImage(img, 0, 0);
  2944. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2945. var i, j;
  2946. if (components === 3) {
  2947. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2948. buf[j] = data[i];
  2949. buf[j + 1] = data[i + 1];
  2950. buf[j + 2] = data[i + 2];
  2951. }
  2952. } else if (components === 1) {
  2953. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2954. buf[j] = data[i];
  2955. }
  2956. }
  2957. resolve({
  2958. data: buf,
  2959. width: width,
  2960. height: height
  2961. });
  2962. };
  2963. img.onerror = function () {
  2964. reject(new Error('JpegDecode failed to load image'));
  2965. };
  2966. img.src = imageUrl;
  2967. });
  2968. }, this);
  2969. messageHandler.on('FetchBuiltInCMap', function (data) {
  2970. if (this.destroyed) {
  2971. return Promise.reject(new Error('Worker was destroyed'));
  2972. }
  2973. return this.CMapReaderFactory.fetch({ name: data.name });
  2974. }, this);
  2975. },
  2976. getData: function WorkerTransport_getData() {
  2977. return this.messageHandler.sendWithPromise('GetData', null);
  2978. },
  2979. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2980. var _this13 = this;
  2981. if (!(0, _util.isInt)(pageNumber) || pageNumber <= 0 || pageNumber > this.numPages) {
  2982. return Promise.reject(new Error('Invalid page request'));
  2983. }
  2984. var pageIndex = pageNumber - 1;
  2985. if (pageIndex in this.pagePromises) {
  2986. return this.pagePromises[pageIndex];
  2987. }
  2988. var promise = this.messageHandler.sendWithPromise('GetPage', { pageIndex: pageIndex }).then(function (pageInfo) {
  2989. if (_this13.destroyed) {
  2990. throw new Error('Transport destroyed');
  2991. }
  2992. var page = new PDFPageProxy(pageIndex, pageInfo, _this13);
  2993. _this13.pageCache[pageIndex] = page;
  2994. return page;
  2995. });
  2996. this.pagePromises[pageIndex] = promise;
  2997. return promise;
  2998. },
  2999. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  3000. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref }).catch(function (reason) {
  3001. return Promise.reject(new Error(reason));
  3002. });
  3003. },
  3004. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  3005. return this.messageHandler.sendWithPromise('GetAnnotations', {
  3006. pageIndex: pageIndex,
  3007. intent: intent
  3008. });
  3009. },
  3010. getDestinations: function WorkerTransport_getDestinations() {
  3011. return this.messageHandler.sendWithPromise('GetDestinations', null);
  3012. },
  3013. getDestination: function WorkerTransport_getDestination(id) {
  3014. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  3015. },
  3016. getPageLabels: function WorkerTransport_getPageLabels() {
  3017. return this.messageHandler.sendWithPromise('GetPageLabels', null);
  3018. },
  3019. getPageMode: function getPageMode() {
  3020. return this.messageHandler.sendWithPromise('GetPageMode', null);
  3021. },
  3022. getAttachments: function WorkerTransport_getAttachments() {
  3023. return this.messageHandler.sendWithPromise('GetAttachments', null);
  3024. },
  3025. getJavaScript: function WorkerTransport_getJavaScript() {
  3026. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  3027. },
  3028. getOutline: function WorkerTransport_getOutline() {
  3029. return this.messageHandler.sendWithPromise('GetOutline', null);
  3030. },
  3031. getMetadata: function WorkerTransport_getMetadata() {
  3032. return this.messageHandler.sendWithPromise('GetMetadata', null).then(function transportMetadata(results) {
  3033. return {
  3034. info: results[0],
  3035. metadata: results[1] ? new _metadata.Metadata(results[1]) : null
  3036. };
  3037. });
  3038. },
  3039. getStats: function WorkerTransport_getStats() {
  3040. return this.messageHandler.sendWithPromise('GetStats', null);
  3041. },
  3042. startCleanup: function WorkerTransport_startCleanup() {
  3043. var _this14 = this;
  3044. this.messageHandler.sendWithPromise('Cleanup', null).then(function () {
  3045. for (var i = 0, ii = _this14.pageCache.length; i < ii; i++) {
  3046. var page = _this14.pageCache[i];
  3047. if (page) {
  3048. page.cleanup();
  3049. }
  3050. }
  3051. _this14.commonObjs.clear();
  3052. _this14.fontLoader.clear();
  3053. });
  3054. }
  3055. };
  3056. return WorkerTransport;
  3057. }();
  3058. var PDFObjects = function PDFObjectsClosure() {
  3059. function PDFObjects() {
  3060. this.objs = Object.create(null);
  3061. }
  3062. PDFObjects.prototype = {
  3063. ensureObj: function PDFObjects_ensureObj(objId) {
  3064. if (this.objs[objId]) {
  3065. return this.objs[objId];
  3066. }
  3067. var obj = {
  3068. capability: (0, _util.createPromiseCapability)(),
  3069. data: null,
  3070. resolved: false
  3071. };
  3072. this.objs[objId] = obj;
  3073. return obj;
  3074. },
  3075. get: function PDFObjects_get(objId, callback) {
  3076. if (callback) {
  3077. this.ensureObj(objId).capability.promise.then(callback);
  3078. return null;
  3079. }
  3080. var obj = this.objs[objId];
  3081. if (!obj || !obj.resolved) {
  3082. throw new Error('Requesting object that isn\'t resolved yet ' + objId);
  3083. }
  3084. return obj.data;
  3085. },
  3086. resolve: function PDFObjects_resolve(objId, data) {
  3087. var obj = this.ensureObj(objId);
  3088. obj.resolved = true;
  3089. obj.data = data;
  3090. obj.capability.resolve(data);
  3091. },
  3092. isResolved: function PDFObjects_isResolved(objId) {
  3093. var objs = this.objs;
  3094. if (!objs[objId]) {
  3095. return false;
  3096. }
  3097. return objs[objId].resolved;
  3098. },
  3099. hasData: function PDFObjects_hasData(objId) {
  3100. return this.isResolved(objId);
  3101. },
  3102. getData: function PDFObjects_getData(objId) {
  3103. var objs = this.objs;
  3104. if (!objs[objId] || !objs[objId].resolved) {
  3105. return null;
  3106. }
  3107. return objs[objId].data;
  3108. },
  3109. clear: function PDFObjects_clear() {
  3110. this.objs = Object.create(null);
  3111. }
  3112. };
  3113. return PDFObjects;
  3114. }();
  3115. var RenderTask = function RenderTaskClosure() {
  3116. function RenderTask(internalRenderTask) {
  3117. this._internalRenderTask = internalRenderTask;
  3118. this.onContinue = null;
  3119. }
  3120. RenderTask.prototype = {
  3121. get promise() {
  3122. return this._internalRenderTask.capability.promise;
  3123. },
  3124. cancel: function RenderTask_cancel() {
  3125. this._internalRenderTask.cancel();
  3126. },
  3127. then: function RenderTask_then(onFulfilled, onRejected) {
  3128. return this.promise.then.apply(this.promise, arguments);
  3129. }
  3130. };
  3131. return RenderTask;
  3132. }();
  3133. var InternalRenderTask = function InternalRenderTaskClosure() {
  3134. var canvasInRendering = new WeakMap();
  3135. function InternalRenderTask(callback, params, objs, commonObjs, operatorList, pageNumber, canvasFactory) {
  3136. this.callback = callback;
  3137. this.params = params;
  3138. this.objs = objs;
  3139. this.commonObjs = commonObjs;
  3140. this.operatorListIdx = null;
  3141. this.operatorList = operatorList;
  3142. this.pageNumber = pageNumber;
  3143. this.canvasFactory = canvasFactory;
  3144. this.running = false;
  3145. this.graphicsReadyCallback = null;
  3146. this.graphicsReady = false;
  3147. this.useRequestAnimationFrame = false;
  3148. this.cancelled = false;
  3149. this.capability = (0, _util.createPromiseCapability)();
  3150. this.task = new RenderTask(this);
  3151. this._continueBound = this._continue.bind(this);
  3152. this._scheduleNextBound = this._scheduleNext.bind(this);
  3153. this._nextBound = this._next.bind(this);
  3154. this._canvas = params.canvasContext.canvas;
  3155. }
  3156. InternalRenderTask.prototype = {
  3157. initializeGraphics: function InternalRenderTask_initializeGraphics(transparency) {
  3158. if (this._canvas) {
  3159. if (canvasInRendering.has(this._canvas)) {
  3160. throw new Error('Cannot use the same canvas during multiple render() operations. ' + 'Use different canvas or ensure previous operations were ' + 'cancelled or completed.');
  3161. }
  3162. canvasInRendering.set(this._canvas, this);
  3163. }
  3164. if (this.cancelled) {
  3165. return;
  3166. }
  3167. if ((0, _dom_utils.getDefaultSetting)('pdfBug') && _util.globalScope.StepperManager && _util.globalScope.StepperManager.enabled) {
  3168. this.stepper = _util.globalScope.StepperManager.create(this.pageNumber - 1);
  3169. this.stepper.init(this.operatorList);
  3170. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  3171. }
  3172. var params = this.params;
  3173. this.gfx = new _canvas.CanvasGraphics(params.canvasContext, this.commonObjs, this.objs, this.canvasFactory, params.imageLayer);
  3174. this.gfx.beginDrawing({
  3175. transform: params.transform,
  3176. viewport: params.viewport,
  3177. transparency: transparency,
  3178. background: params.background
  3179. });
  3180. this.operatorListIdx = 0;
  3181. this.graphicsReady = true;
  3182. if (this.graphicsReadyCallback) {
  3183. this.graphicsReadyCallback();
  3184. }
  3185. },
  3186. cancel: function InternalRenderTask_cancel() {
  3187. this.running = false;
  3188. this.cancelled = true;
  3189. if (this._canvas) {
  3190. canvasInRendering.delete(this._canvas);
  3191. }
  3192. if ((0, _dom_utils.getDefaultSetting)('pdfjsNext')) {
  3193. this.callback(new _dom_utils.RenderingCancelledException('Rendering cancelled, page ' + this.pageNumber, 'canvas'));
  3194. } else {
  3195. this.callback('cancelled');
  3196. }
  3197. },
  3198. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  3199. if (!this.graphicsReady) {
  3200. if (!this.graphicsReadyCallback) {
  3201. this.graphicsReadyCallback = this._continueBound;
  3202. }
  3203. return;
  3204. }
  3205. if (this.stepper) {
  3206. this.stepper.updateOperatorList(this.operatorList);
  3207. }
  3208. if (this.running) {
  3209. return;
  3210. }
  3211. this._continue();
  3212. },
  3213. _continue: function InternalRenderTask__continue() {
  3214. this.running = true;
  3215. if (this.cancelled) {
  3216. return;
  3217. }
  3218. if (this.task.onContinue) {
  3219. this.task.onContinue(this._scheduleNextBound);
  3220. } else {
  3221. this._scheduleNext();
  3222. }
  3223. },
  3224. _scheduleNext: function InternalRenderTask__scheduleNext() {
  3225. if (this.useRequestAnimationFrame && typeof window !== 'undefined') {
  3226. window.requestAnimationFrame(this._nextBound);
  3227. } else {
  3228. Promise.resolve(undefined).then(this._nextBound);
  3229. }
  3230. },
  3231. _next: function InternalRenderTask__next() {
  3232. if (this.cancelled) {
  3233. return;
  3234. }
  3235. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  3236. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  3237. this.running = false;
  3238. if (this.operatorList.lastChunk) {
  3239. this.gfx.endDrawing();
  3240. if (this._canvas) {
  3241. canvasInRendering.delete(this._canvas);
  3242. }
  3243. this.callback();
  3244. }
  3245. }
  3246. }
  3247. };
  3248. return InternalRenderTask;
  3249. }();
  3250. var _UnsupportedManager = function UnsupportedManagerClosure() {
  3251. var listeners = [];
  3252. return {
  3253. listen: function listen(cb) {
  3254. (0, _util.deprecated)('Global UnsupportedManager.listen is used: ' + ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  3255. listeners.push(cb);
  3256. },
  3257. notify: function notify(featureId) {
  3258. for (var i = 0, ii = listeners.length; i < ii; i++) {
  3259. listeners[i](featureId);
  3260. }
  3261. }
  3262. };
  3263. }();
  3264. var version, build;
  3265. {
  3266. exports.version = version = '1.9.426';
  3267. exports.build = build = '2558a58d';
  3268. }
  3269. exports.getDocument = getDocument;
  3270. exports.LoopbackPort = LoopbackPort;
  3271. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  3272. exports.PDFWorker = PDFWorker;
  3273. exports.PDFDocumentProxy = PDFDocumentProxy;
  3274. exports.PDFPageProxy = PDFPageProxy;
  3275. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  3276. exports._UnsupportedManager = _UnsupportedManager;
  3277. exports.version = version;
  3278. exports.build = build;
  3279. /***/ }),
  3280. /* 3 */
  3281. /***/ (function(module, exports, __w_pdfjs_require__) {
  3282. "use strict";
  3283. Object.defineProperty(exports, "__esModule", {
  3284. value: true
  3285. });
  3286. exports.AnnotationLayer = undefined;
  3287. var _dom_utils = __w_pdfjs_require__(1);
  3288. var _util = __w_pdfjs_require__(0);
  3289. function AnnotationElementFactory() {}
  3290. AnnotationElementFactory.prototype = {
  3291. create: function AnnotationElementFactory_create(parameters) {
  3292. var subtype = parameters.data.annotationType;
  3293. switch (subtype) {
  3294. case _util.AnnotationType.LINK:
  3295. return new LinkAnnotationElement(parameters);
  3296. case _util.AnnotationType.TEXT:
  3297. return new TextAnnotationElement(parameters);
  3298. case _util.AnnotationType.WIDGET:
  3299. var fieldType = parameters.data.fieldType;
  3300. switch (fieldType) {
  3301. case 'Tx':
  3302. return new TextWidgetAnnotationElement(parameters);
  3303. case 'Btn':
  3304. if (parameters.data.radioButton) {
  3305. return new RadioButtonWidgetAnnotationElement(parameters);
  3306. } else if (parameters.data.checkBox) {
  3307. return new CheckboxWidgetAnnotationElement(parameters);
  3308. }
  3309. (0, _util.warn)('Unimplemented button widget annotation: pushbutton');
  3310. break;
  3311. case 'Ch':
  3312. return new ChoiceWidgetAnnotationElement(parameters);
  3313. }
  3314. return new WidgetAnnotationElement(parameters);
  3315. case _util.AnnotationType.POPUP:
  3316. return new PopupAnnotationElement(parameters);
  3317. case _util.AnnotationType.LINE:
  3318. return new LineAnnotationElement(parameters);
  3319. case _util.AnnotationType.HIGHLIGHT:
  3320. return new HighlightAnnotationElement(parameters);
  3321. case _util.AnnotationType.UNDERLINE:
  3322. return new UnderlineAnnotationElement(parameters);
  3323. case _util.AnnotationType.SQUIGGLY:
  3324. return new SquigglyAnnotationElement(parameters);
  3325. case _util.AnnotationType.STRIKEOUT:
  3326. return new StrikeOutAnnotationElement(parameters);
  3327. case _util.AnnotationType.FILEATTACHMENT:
  3328. return new FileAttachmentAnnotationElement(parameters);
  3329. default:
  3330. return new AnnotationElement(parameters);
  3331. }
  3332. }
  3333. };
  3334. var AnnotationElement = function AnnotationElementClosure() {
  3335. function AnnotationElement(parameters, isRenderable, ignoreBorder) {
  3336. this.isRenderable = isRenderable || false;
  3337. this.data = parameters.data;
  3338. this.layer = parameters.layer;
  3339. this.page = parameters.page;
  3340. this.viewport = parameters.viewport;
  3341. this.linkService = parameters.linkService;
  3342. this.downloadManager = parameters.downloadManager;
  3343. this.imageResourcesPath = parameters.imageResourcesPath;
  3344. this.renderInteractiveForms = parameters.renderInteractiveForms;
  3345. if (isRenderable) {
  3346. this.container = this._createContainer(ignoreBorder);
  3347. }
  3348. }
  3349. AnnotationElement.prototype = {
  3350. _createContainer: function AnnotationElement_createContainer(ignoreBorder) {
  3351. var data = this.data,
  3352. page = this.page,
  3353. viewport = this.viewport;
  3354. var container = document.createElement('section');
  3355. var width = data.rect[2] - data.rect[0];
  3356. var height = data.rect[3] - data.rect[1];
  3357. container.setAttribute('data-annotation-id', data.id);
  3358. var rect = _util.Util.normalizeRect([data.rect[0], page.view[3] - data.rect[1] + page.view[1], data.rect[2], page.view[3] - data.rect[3] + page.view[1]]);
  3359. _dom_utils.CustomStyle.setProp('transform', container, 'matrix(' + viewport.transform.join(',') + ')');
  3360. _dom_utils.CustomStyle.setProp('transformOrigin', container, -rect[0] + 'px ' + -rect[1] + 'px');
  3361. if (!ignoreBorder && data.borderStyle.width > 0) {
  3362. container.style.borderWidth = data.borderStyle.width + 'px';
  3363. if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) {
  3364. width = width - 2 * data.borderStyle.width;
  3365. height = height - 2 * data.borderStyle.width;
  3366. }
  3367. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  3368. var verticalRadius = data.borderStyle.verticalCornerRadius;
  3369. if (horizontalRadius > 0 || verticalRadius > 0) {
  3370. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  3371. _dom_utils.CustomStyle.setProp('borderRadius', container, radius);
  3372. }
  3373. switch (data.borderStyle.style) {
  3374. case _util.AnnotationBorderStyleType.SOLID:
  3375. container.style.borderStyle = 'solid';
  3376. break;
  3377. case _util.AnnotationBorderStyleType.DASHED:
  3378. container.style.borderStyle = 'dashed';
  3379. break;
  3380. case _util.AnnotationBorderStyleType.BEVELED:
  3381. (0, _util.warn)('Unimplemented border style: beveled');
  3382. break;
  3383. case _util.AnnotationBorderStyleType.INSET:
  3384. (0, _util.warn)('Unimplemented border style: inset');
  3385. break;
  3386. case _util.AnnotationBorderStyleType.UNDERLINE:
  3387. container.style.borderBottomStyle = 'solid';
  3388. break;
  3389. default:
  3390. break;
  3391. }
  3392. if (data.color) {
  3393. container.style.borderColor = _util.Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  3394. } else {
  3395. container.style.borderWidth = 0;
  3396. }
  3397. }
  3398. container.style.left = rect[0] + 'px';
  3399. container.style.top = rect[1] + 'px';
  3400. container.style.width = width + 'px';
  3401. container.style.height = height + 'px';
  3402. return container;
  3403. },
  3404. _createPopup: function AnnotationElement_createPopup(container, trigger, data) {
  3405. if (!trigger) {
  3406. trigger = document.createElement('div');
  3407. trigger.style.height = container.style.height;
  3408. trigger.style.width = container.style.width;
  3409. container.appendChild(trigger);
  3410. }
  3411. var popupElement = new PopupElement({
  3412. container: container,
  3413. trigger: trigger,
  3414. color: data.color,
  3415. title: data.title,
  3416. contents: data.contents,
  3417. hideWrapper: true
  3418. });
  3419. var popup = popupElement.render();
  3420. popup.style.left = container.style.width;
  3421. container.appendChild(popup);
  3422. },
  3423. render: function AnnotationElement_render() {
  3424. throw new Error('Abstract method AnnotationElement.render called');
  3425. }
  3426. };
  3427. return AnnotationElement;
  3428. }();
  3429. var LinkAnnotationElement = function LinkAnnotationElementClosure() {
  3430. function LinkAnnotationElement(parameters) {
  3431. AnnotationElement.call(this, parameters, true);
  3432. }
  3433. _util.Util.inherit(LinkAnnotationElement, AnnotationElement, {
  3434. render: function LinkAnnotationElement_render() {
  3435. this.container.className = 'linkAnnotation';
  3436. var link = document.createElement('a');
  3437. (0, _dom_utils.addLinkAttributes)(link, {
  3438. url: this.data.url,
  3439. target: this.data.newWindow ? _dom_utils.LinkTarget.BLANK : undefined
  3440. });
  3441. if (!this.data.url) {
  3442. if (this.data.action) {
  3443. this._bindNamedAction(link, this.data.action);
  3444. } else {
  3445. this._bindLink(link, this.data.dest);
  3446. }
  3447. }
  3448. this.container.appendChild(link);
  3449. return this.container;
  3450. },
  3451. _bindLink: function _bindLink(link, destination) {
  3452. var _this = this;
  3453. link.href = this.linkService.getDestinationHash(destination);
  3454. link.onclick = function () {
  3455. if (destination) {
  3456. _this.linkService.navigateTo(destination);
  3457. }
  3458. return false;
  3459. };
  3460. if (destination) {
  3461. link.className = 'internalLink';
  3462. }
  3463. },
  3464. _bindNamedAction: function _bindNamedAction(link, action) {
  3465. var _this2 = this;
  3466. link.href = this.linkService.getAnchorUrl('');
  3467. link.onclick = function () {
  3468. _this2.linkService.executeNamedAction(action);
  3469. return false;
  3470. };
  3471. link.className = 'internalLink';
  3472. }
  3473. });
  3474. return LinkAnnotationElement;
  3475. }();
  3476. var TextAnnotationElement = function TextAnnotationElementClosure() {
  3477. function TextAnnotationElement(parameters) {
  3478. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  3479. AnnotationElement.call(this, parameters, isRenderable);
  3480. }
  3481. _util.Util.inherit(TextAnnotationElement, AnnotationElement, {
  3482. render: function TextAnnotationElement_render() {
  3483. this.container.className = 'textAnnotation';
  3484. var image = document.createElement('img');
  3485. image.style.height = this.container.style.height;
  3486. image.style.width = this.container.style.width;
  3487. image.src = this.imageResourcesPath + 'annotation-' + this.data.name.toLowerCase() + '.svg';
  3488. image.alt = '[{{type}} Annotation]';
  3489. image.dataset.l10nId = 'text_annotation_type';
  3490. image.dataset.l10nArgs = JSON.stringify({ type: this.data.name });
  3491. if (!this.data.hasPopup) {
  3492. this._createPopup(this.container, image, this.data);
  3493. }
  3494. this.container.appendChild(image);
  3495. return this.container;
  3496. }
  3497. });
  3498. return TextAnnotationElement;
  3499. }();
  3500. var WidgetAnnotationElement = function WidgetAnnotationElementClosure() {
  3501. function WidgetAnnotationElement(parameters, isRenderable) {
  3502. AnnotationElement.call(this, parameters, isRenderable);
  3503. }
  3504. _util.Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  3505. render: function WidgetAnnotationElement_render() {
  3506. return this.container;
  3507. }
  3508. });
  3509. return WidgetAnnotationElement;
  3510. }();
  3511. var TextWidgetAnnotationElement = function TextWidgetAnnotationElementClosure() {
  3512. var TEXT_ALIGNMENT = ['left', 'center', 'right'];
  3513. function TextWidgetAnnotationElement(parameters) {
  3514. var isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  3515. WidgetAnnotationElement.call(this, parameters, isRenderable);
  3516. }
  3517. _util.Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, {
  3518. render: function TextWidgetAnnotationElement_render() {
  3519. this.container.className = 'textWidgetAnnotation';
  3520. var element = null;
  3521. if (this.renderInteractiveForms) {
  3522. if (this.data.multiLine) {
  3523. element = document.createElement('textarea');
  3524. element.textContent = this.data.fieldValue;
  3525. } else {
  3526. element = document.createElement('input');
  3527. element.type = 'text';
  3528. element.setAttribute('value', this.data.fieldValue);
  3529. }
  3530. element.disabled = this.data.readOnly;
  3531. if (this.data.maxLen !== null) {
  3532. element.maxLength = this.data.maxLen;
  3533. }
  3534. if (this.data.comb) {
  3535. var fieldWidth = this.data.rect[2] - this.data.rect[0];
  3536. var combWidth = fieldWidth / this.data.maxLen;
  3537. element.classList.add('comb');
  3538. element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)';
  3539. }
  3540. } else {
  3541. element = document.createElement('div');
  3542. element.textContent = this.data.fieldValue;
  3543. element.style.verticalAlign = 'middle';
  3544. element.style.display = 'table-cell';
  3545. var font = null;
  3546. if (this.data.fontRefName) {
  3547. font = this.page.commonObjs.getData(this.data.fontRefName);
  3548. }
  3549. this._setTextStyle(element, font);
  3550. }
  3551. if (this.data.textAlignment !== null) {
  3552. element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  3553. }
  3554. this.container.appendChild(element);
  3555. return this.container;
  3556. },
  3557. _setTextStyle: function TextWidgetAnnotationElement_setTextStyle(element, font) {
  3558. var style = element.style;
  3559. style.fontSize = this.data.fontSize + 'px';
  3560. style.direction = this.data.fontDirection < 0 ? 'rtl' : 'ltr';
  3561. if (!font) {
  3562. return;
  3563. }
  3564. style.fontWeight = font.black ? font.bold ? '900' : 'bold' : font.bold ? 'bold' : 'normal';
  3565. style.fontStyle = font.italic ? 'italic' : 'normal';
  3566. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  3567. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  3568. style.fontFamily = fontFamily + fallbackName;
  3569. }
  3570. });
  3571. return TextWidgetAnnotationElement;
  3572. }();
  3573. var CheckboxWidgetAnnotationElement = function CheckboxWidgetAnnotationElementClosure() {
  3574. function CheckboxWidgetAnnotationElement(parameters) {
  3575. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  3576. }
  3577. _util.Util.inherit(CheckboxWidgetAnnotationElement, WidgetAnnotationElement, {
  3578. render: function CheckboxWidgetAnnotationElement_render() {
  3579. this.container.className = 'buttonWidgetAnnotation checkBox';
  3580. var element = document.createElement('input');
  3581. element.disabled = this.data.readOnly;
  3582. element.type = 'checkbox';
  3583. if (this.data.fieldValue && this.data.fieldValue !== 'Off') {
  3584. element.setAttribute('checked', true);
  3585. }
  3586. this.container.appendChild(element);
  3587. return this.container;
  3588. }
  3589. });
  3590. return CheckboxWidgetAnnotationElement;
  3591. }();
  3592. var RadioButtonWidgetAnnotationElement = function RadioButtonWidgetAnnotationElementClosure() {
  3593. function RadioButtonWidgetAnnotationElement(parameters) {
  3594. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  3595. }
  3596. _util.Util.inherit(RadioButtonWidgetAnnotationElement, WidgetAnnotationElement, {
  3597. render: function RadioButtonWidgetAnnotationElement_render() {
  3598. this.container.className = 'buttonWidgetAnnotation radioButton';
  3599. var element = document.createElement('input');
  3600. element.disabled = this.data.readOnly;
  3601. element.type = 'radio';
  3602. element.name = this.data.fieldName;
  3603. if (this.data.fieldValue === this.data.buttonValue) {
  3604. element.setAttribute('checked', true);
  3605. }
  3606. this.container.appendChild(element);
  3607. return this.container;
  3608. }
  3609. });
  3610. return RadioButtonWidgetAnnotationElement;
  3611. }();
  3612. var ChoiceWidgetAnnotationElement = function ChoiceWidgetAnnotationElementClosure() {
  3613. function ChoiceWidgetAnnotationElement(parameters) {
  3614. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  3615. }
  3616. _util.Util.inherit(ChoiceWidgetAnnotationElement, WidgetAnnotationElement, {
  3617. render: function ChoiceWidgetAnnotationElement_render() {
  3618. this.container.className = 'choiceWidgetAnnotation';
  3619. var selectElement = document.createElement('select');
  3620. selectElement.disabled = this.data.readOnly;
  3621. if (!this.data.combo) {
  3622. selectElement.size = this.data.options.length;
  3623. if (this.data.multiSelect) {
  3624. selectElement.multiple = true;
  3625. }
  3626. }
  3627. for (var i = 0, ii = this.data.options.length; i < ii; i++) {
  3628. var option = this.data.options[i];
  3629. var optionElement = document.createElement('option');
  3630. optionElement.textContent = option.displayValue;
  3631. optionElement.value = option.exportValue;
  3632. if (this.data.fieldValue.indexOf(option.displayValue) >= 0) {
  3633. optionElement.setAttribute('selected', true);
  3634. }
  3635. selectElement.appendChild(optionElement);
  3636. }
  3637. this.container.appendChild(selectElement);
  3638. return this.container;
  3639. }
  3640. });
  3641. return ChoiceWidgetAnnotationElement;
  3642. }();
  3643. var PopupAnnotationElement = function PopupAnnotationElementClosure() {
  3644. var IGNORE_TYPES = ['Line'];
  3645. function PopupAnnotationElement(parameters) {
  3646. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  3647. AnnotationElement.call(this, parameters, isRenderable);
  3648. }
  3649. _util.Util.inherit(PopupAnnotationElement, AnnotationElement, {
  3650. render: function PopupAnnotationElement_render() {
  3651. this.container.className = 'popupAnnotation';
  3652. if (IGNORE_TYPES.indexOf(this.data.parentType) >= 0) {
  3653. return this.container;
  3654. }
  3655. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  3656. var parentElement = this.layer.querySelector(selector);
  3657. if (!parentElement) {
  3658. return this.container;
  3659. }
  3660. var popup = new PopupElement({
  3661. container: this.container,
  3662. trigger: parentElement,
  3663. color: this.data.color,
  3664. title: this.data.title,
  3665. contents: this.data.contents
  3666. });
  3667. var parentLeft = parseFloat(parentElement.style.left);
  3668. var parentWidth = parseFloat(parentElement.style.width);
  3669. _dom_utils.CustomStyle.setProp('transformOrigin', this.container, -(parentLeft + parentWidth) + 'px -' + parentElement.style.top);
  3670. this.container.style.left = parentLeft + parentWidth + 'px';
  3671. this.container.appendChild(popup.render());
  3672. return this.container;
  3673. }
  3674. });
  3675. return PopupAnnotationElement;
  3676. }();
  3677. var PopupElement = function PopupElementClosure() {
  3678. var BACKGROUND_ENLIGHT = 0.7;
  3679. function PopupElement(parameters) {
  3680. this.container = parameters.container;
  3681. this.trigger = parameters.trigger;
  3682. this.color = parameters.color;
  3683. this.title = parameters.title;
  3684. this.contents = parameters.contents;
  3685. this.hideWrapper = parameters.hideWrapper || false;
  3686. this.pinned = false;
  3687. }
  3688. PopupElement.prototype = {
  3689. render: function PopupElement_render() {
  3690. var wrapper = document.createElement('div');
  3691. wrapper.className = 'popupWrapper';
  3692. this.hideElement = this.hideWrapper ? wrapper : this.container;
  3693. this.hideElement.setAttribute('hidden', true);
  3694. var popup = document.createElement('div');
  3695. popup.className = 'popup';
  3696. var color = this.color;
  3697. if (color) {
  3698. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  3699. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  3700. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  3701. popup.style.backgroundColor = _util.Util.makeCssRgb(r | 0, g | 0, b | 0);
  3702. }
  3703. var contents = this._formatContents(this.contents);
  3704. var title = document.createElement('h1');
  3705. title.textContent = this.title;
  3706. this.trigger.addEventListener('click', this._toggle.bind(this));
  3707. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  3708. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  3709. popup.addEventListener('click', this._hide.bind(this, true));
  3710. popup.appendChild(title);
  3711. popup.appendChild(contents);
  3712. wrapper.appendChild(popup);
  3713. return wrapper;
  3714. },
  3715. _formatContents: function PopupElement_formatContents(contents) {
  3716. var p = document.createElement('p');
  3717. var lines = contents.split(/(?:\r\n?|\n)/);
  3718. for (var i = 0, ii = lines.length; i < ii; ++i) {
  3719. var line = lines[i];
  3720. p.appendChild(document.createTextNode(line));
  3721. if (i < ii - 1) {
  3722. p.appendChild(document.createElement('br'));
  3723. }
  3724. }
  3725. return p;
  3726. },
  3727. _toggle: function PopupElement_toggle() {
  3728. if (this.pinned) {
  3729. this._hide(true);
  3730. } else {
  3731. this._show(true);
  3732. }
  3733. },
  3734. _show: function PopupElement_show(pin) {
  3735. if (pin) {
  3736. this.pinned = true;
  3737. }
  3738. if (this.hideElement.hasAttribute('hidden')) {
  3739. this.hideElement.removeAttribute('hidden');
  3740. this.container.style.zIndex += 1;
  3741. }
  3742. },
  3743. _hide: function PopupElement_hide(unpin) {
  3744. if (unpin) {
  3745. this.pinned = false;
  3746. }
  3747. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  3748. this.hideElement.setAttribute('hidden', true);
  3749. this.container.style.zIndex -= 1;
  3750. }
  3751. }
  3752. };
  3753. return PopupElement;
  3754. }();
  3755. var LineAnnotationElement = function LineAnnotationElementClosure() {
  3756. var SVG_NS = 'http://www.w3.org/2000/svg';
  3757. function LineAnnotationElement(parameters) {
  3758. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  3759. AnnotationElement.call(this, parameters, isRenderable, true);
  3760. }
  3761. _util.Util.inherit(LineAnnotationElement, AnnotationElement, {
  3762. render: function LineAnnotationElement_render() {
  3763. this.container.className = 'lineAnnotation';
  3764. var data = this.data;
  3765. var width = data.rect[2] - data.rect[0];
  3766. var height = data.rect[3] - data.rect[1];
  3767. var svg = document.createElementNS(SVG_NS, 'svg:svg');
  3768. svg.setAttributeNS(null, 'version', '1.1');
  3769. svg.setAttributeNS(null, 'width', width + 'px');
  3770. svg.setAttributeNS(null, 'height', height + 'px');
  3771. svg.setAttributeNS(null, 'preserveAspectRatio', 'none');
  3772. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  3773. var line = document.createElementNS(SVG_NS, 'svg:line');
  3774. line.setAttributeNS(null, 'x1', data.rect[2] - data.lineCoordinates[0]);
  3775. line.setAttributeNS(null, 'y1', data.rect[3] - data.lineCoordinates[1]);
  3776. line.setAttributeNS(null, 'x2', data.rect[2] - data.lineCoordinates[2]);
  3777. line.setAttributeNS(null, 'y2', data.rect[3] - data.lineCoordinates[3]);
  3778. line.setAttributeNS(null, 'stroke-width', data.borderStyle.width);
  3779. line.setAttributeNS(null, 'stroke', 'transparent');
  3780. svg.appendChild(line);
  3781. this.container.append(svg);
  3782. this._createPopup(this.container, line, this.data);
  3783. return this.container;
  3784. }
  3785. });
  3786. return LineAnnotationElement;
  3787. }();
  3788. var HighlightAnnotationElement = function HighlightAnnotationElementClosure() {
  3789. function HighlightAnnotationElement(parameters) {
  3790. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  3791. AnnotationElement.call(this, parameters, isRenderable, true);
  3792. }
  3793. _util.Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  3794. render: function HighlightAnnotationElement_render() {
  3795. this.container.className = 'highlightAnnotation';
  3796. if (!this.data.hasPopup) {
  3797. this._createPopup(this.container, null, this.data);
  3798. }
  3799. return this.container;
  3800. }
  3801. });
  3802. return HighlightAnnotationElement;
  3803. }();
  3804. var UnderlineAnnotationElement = function UnderlineAnnotationElementClosure() {
  3805. function UnderlineAnnotationElement(parameters) {
  3806. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  3807. AnnotationElement.call(this, parameters, isRenderable, true);
  3808. }
  3809. _util.Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  3810. render: function UnderlineAnnotationElement_render() {
  3811. this.container.className = 'underlineAnnotation';
  3812. if (!this.data.hasPopup) {
  3813. this._createPopup(this.container, null, this.data);
  3814. }
  3815. return this.container;
  3816. }
  3817. });
  3818. return UnderlineAnnotationElement;
  3819. }();
  3820. var SquigglyAnnotationElement = function SquigglyAnnotationElementClosure() {
  3821. function SquigglyAnnotationElement(parameters) {
  3822. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  3823. AnnotationElement.call(this, parameters, isRenderable, true);
  3824. }
  3825. _util.Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  3826. render: function SquigglyAnnotationElement_render() {
  3827. this.container.className = 'squigglyAnnotation';
  3828. if (!this.data.hasPopup) {
  3829. this._createPopup(this.container, null, this.data);
  3830. }
  3831. return this.container;
  3832. }
  3833. });
  3834. return SquigglyAnnotationElement;
  3835. }();
  3836. var StrikeOutAnnotationElement = function StrikeOutAnnotationElementClosure() {
  3837. function StrikeOutAnnotationElement(parameters) {
  3838. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  3839. AnnotationElement.call(this, parameters, isRenderable, true);
  3840. }
  3841. _util.Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  3842. render: function StrikeOutAnnotationElement_render() {
  3843. this.container.className = 'strikeoutAnnotation';
  3844. if (!this.data.hasPopup) {
  3845. this._createPopup(this.container, null, this.data);
  3846. }
  3847. return this.container;
  3848. }
  3849. });
  3850. return StrikeOutAnnotationElement;
  3851. }();
  3852. var FileAttachmentAnnotationElement = function FileAttachmentAnnotationElementClosure() {
  3853. function FileAttachmentAnnotationElement(parameters) {
  3854. AnnotationElement.call(this, parameters, true);
  3855. var file = this.data.file;
  3856. this.filename = (0, _dom_utils.getFilenameFromUrl)(file.filename);
  3857. this.content = file.content;
  3858. this.linkService.onFileAttachmentAnnotation({
  3859. id: (0, _util.stringToPDFString)(file.filename),
  3860. filename: file.filename,
  3861. content: file.content
  3862. });
  3863. }
  3864. _util.Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, {
  3865. render: function FileAttachmentAnnotationElement_render() {
  3866. this.container.className = 'fileAttachmentAnnotation';
  3867. var trigger = document.createElement('div');
  3868. trigger.style.height = this.container.style.height;
  3869. trigger.style.width = this.container.style.width;
  3870. trigger.addEventListener('dblclick', this._download.bind(this));
  3871. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  3872. this._createPopup(this.container, trigger, this.data);
  3873. }
  3874. this.container.appendChild(trigger);
  3875. return this.container;
  3876. },
  3877. _download: function FileAttachmentAnnotationElement_download() {
  3878. if (!this.downloadManager) {
  3879. (0, _util.warn)('Download cannot be started due to unavailable download manager');
  3880. return;
  3881. }
  3882. this.downloadManager.downloadData(this.content, this.filename, '');
  3883. }
  3884. });
  3885. return FileAttachmentAnnotationElement;
  3886. }();
  3887. var AnnotationLayer = function AnnotationLayerClosure() {
  3888. return {
  3889. render: function AnnotationLayer_render(parameters) {
  3890. var annotationElementFactory = new AnnotationElementFactory();
  3891. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  3892. var data = parameters.annotations[i];
  3893. if (!data) {
  3894. continue;
  3895. }
  3896. var element = annotationElementFactory.create({
  3897. data: data,
  3898. layer: parameters.div,
  3899. page: parameters.page,
  3900. viewport: parameters.viewport,
  3901. linkService: parameters.linkService,
  3902. downloadManager: parameters.downloadManager,
  3903. imageResourcesPath: parameters.imageResourcesPath || (0, _dom_utils.getDefaultSetting)('imageResourcesPath'),
  3904. renderInteractiveForms: parameters.renderInteractiveForms || false
  3905. });
  3906. if (element.isRenderable) {
  3907. parameters.div.appendChild(element.render());
  3908. }
  3909. }
  3910. },
  3911. update: function AnnotationLayer_update(parameters) {
  3912. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  3913. var data = parameters.annotations[i];
  3914. var element = parameters.div.querySelector('[data-annotation-id="' + data.id + '"]');
  3915. if (element) {
  3916. _dom_utils.CustomStyle.setProp('transform', element, 'matrix(' + parameters.viewport.transform.join(',') + ')');
  3917. }
  3918. }
  3919. parameters.div.removeAttribute('hidden');
  3920. }
  3921. };
  3922. }();
  3923. exports.AnnotationLayer = AnnotationLayer;
  3924. /***/ }),
  3925. /* 4 */
  3926. /***/ (function(module, exports, __w_pdfjs_require__) {
  3927. "use strict";
  3928. Object.defineProperty(exports, "__esModule", {
  3929. value: true
  3930. });
  3931. exports.SVGGraphics = undefined;
  3932. var _util = __w_pdfjs_require__(0);
  3933. var SVGGraphics = function SVGGraphics() {
  3934. throw new Error('Not implemented: SVGGraphics');
  3935. };
  3936. {
  3937. var SVG_DEFAULTS = {
  3938. fontStyle: 'normal',
  3939. fontWeight: 'normal',
  3940. fillColor: '#000000'
  3941. };
  3942. var convertImgDataToPng = function convertImgDataToPngClosure() {
  3943. var PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  3944. var CHUNK_WRAPPER_SIZE = 12;
  3945. var crcTable = new Int32Array(256);
  3946. for (var i = 0; i < 256; i++) {
  3947. var c = i;
  3948. for (var h = 0; h < 8; h++) {
  3949. if (c & 1) {
  3950. c = 0xedB88320 ^ c >> 1 & 0x7fffffff;
  3951. } else {
  3952. c = c >> 1 & 0x7fffffff;
  3953. }
  3954. }
  3955. crcTable[i] = c;
  3956. }
  3957. function crc32(data, start, end) {
  3958. var crc = -1;
  3959. for (var i = start; i < end; i++) {
  3960. var a = (crc ^ data[i]) & 0xff;
  3961. var b = crcTable[a];
  3962. crc = crc >>> 8 ^ b;
  3963. }
  3964. return crc ^ -1;
  3965. }
  3966. function writePngChunk(type, body, data, offset) {
  3967. var p = offset;
  3968. var len = body.length;
  3969. data[p] = len >> 24 & 0xff;
  3970. data[p + 1] = len >> 16 & 0xff;
  3971. data[p + 2] = len >> 8 & 0xff;
  3972. data[p + 3] = len & 0xff;
  3973. p += 4;
  3974. data[p] = type.charCodeAt(0) & 0xff;
  3975. data[p + 1] = type.charCodeAt(1) & 0xff;
  3976. data[p + 2] = type.charCodeAt(2) & 0xff;
  3977. data[p + 3] = type.charCodeAt(3) & 0xff;
  3978. p += 4;
  3979. data.set(body, p);
  3980. p += body.length;
  3981. var crc = crc32(data, offset + 4, p);
  3982. data[p] = crc >> 24 & 0xff;
  3983. data[p + 1] = crc >> 16 & 0xff;
  3984. data[p + 2] = crc >> 8 & 0xff;
  3985. data[p + 3] = crc & 0xff;
  3986. }
  3987. function adler32(data, start, end) {
  3988. var a = 1;
  3989. var b = 0;
  3990. for (var i = start; i < end; ++i) {
  3991. a = (a + (data[i] & 0xff)) % 65521;
  3992. b = (b + a) % 65521;
  3993. }
  3994. return b << 16 | a;
  3995. }
  3996. function deflateSync(literals) {
  3997. if (!(0, _util.isNodeJS)()) {
  3998. return deflateSyncUncompressed(literals);
  3999. }
  4000. try {
  4001. var input;
  4002. if (parseInt(process.versions.node) >= 8) {
  4003. input = literals;
  4004. } else {
  4005. input = new Buffer(literals);
  4006. }
  4007. var output = require('zlib').deflateSync(input, { level: 9 });
  4008. return output instanceof Uint8Array ? output : new Uint8Array(output);
  4009. } catch (e) {
  4010. (0, _util.warn)('Not compressing PNG because zlib.deflateSync is unavailable: ' + e);
  4011. }
  4012. return deflateSyncUncompressed(literals);
  4013. }
  4014. function deflateSyncUncompressed(literals) {
  4015. var len = literals.length;
  4016. var maxBlockLength = 0xFFFF;
  4017. var deflateBlocks = Math.ceil(len / maxBlockLength);
  4018. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  4019. var pi = 0;
  4020. idat[pi++] = 0x78;
  4021. idat[pi++] = 0x9c;
  4022. var pos = 0;
  4023. while (len > maxBlockLength) {
  4024. idat[pi++] = 0x00;
  4025. idat[pi++] = 0xff;
  4026. idat[pi++] = 0xff;
  4027. idat[pi++] = 0x00;
  4028. idat[pi++] = 0x00;
  4029. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  4030. pi += maxBlockLength;
  4031. pos += maxBlockLength;
  4032. len -= maxBlockLength;
  4033. }
  4034. idat[pi++] = 0x01;
  4035. idat[pi++] = len & 0xff;
  4036. idat[pi++] = len >> 8 & 0xff;
  4037. idat[pi++] = ~len & 0xffff & 0xff;
  4038. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  4039. idat.set(literals.subarray(pos), pi);
  4040. pi += literals.length - pos;
  4041. var adler = adler32(literals, 0, literals.length);
  4042. idat[pi++] = adler >> 24 & 0xff;
  4043. idat[pi++] = adler >> 16 & 0xff;
  4044. idat[pi++] = adler >> 8 & 0xff;
  4045. idat[pi++] = adler & 0xff;
  4046. return idat;
  4047. }
  4048. function encode(imgData, kind, forceDataSchema) {
  4049. var width = imgData.width;
  4050. var height = imgData.height;
  4051. var bitDepth, colorType, lineSize;
  4052. var bytes = imgData.data;
  4053. switch (kind) {
  4054. case _util.ImageKind.GRAYSCALE_1BPP:
  4055. colorType = 0;
  4056. bitDepth = 1;
  4057. lineSize = width + 7 >> 3;
  4058. break;
  4059. case _util.ImageKind.RGB_24BPP:
  4060. colorType = 2;
  4061. bitDepth = 8;
  4062. lineSize = width * 3;
  4063. break;
  4064. case _util.ImageKind.RGBA_32BPP:
  4065. colorType = 6;
  4066. bitDepth = 8;
  4067. lineSize = width * 4;
  4068. break;
  4069. default:
  4070. throw new Error('invalid format');
  4071. }
  4072. var literals = new Uint8Array((1 + lineSize) * height);
  4073. var offsetLiterals = 0,
  4074. offsetBytes = 0;
  4075. var y, i;
  4076. for (y = 0; y < height; ++y) {
  4077. literals[offsetLiterals++] = 0;
  4078. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  4079. offsetBytes += lineSize;
  4080. offsetLiterals += lineSize;
  4081. }
  4082. if (kind === _util.ImageKind.GRAYSCALE_1BPP) {
  4083. offsetLiterals = 0;
  4084. for (y = 0; y < height; y++) {
  4085. offsetLiterals++;
  4086. for (i = 0; i < lineSize; i++) {
  4087. literals[offsetLiterals++] ^= 0xFF;
  4088. }
  4089. }
  4090. }
  4091. var ihdr = new Uint8Array([width >> 24 & 0xff, width >> 16 & 0xff, width >> 8 & 0xff, width & 0xff, height >> 24 & 0xff, height >> 16 & 0xff, height >> 8 & 0xff, height & 0xff, bitDepth, colorType, 0x00, 0x00, 0x00]);
  4092. var idat = deflateSync(literals);
  4093. var pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  4094. var data = new Uint8Array(pngLength);
  4095. var offset = 0;
  4096. data.set(PNG_HEADER, offset);
  4097. offset += PNG_HEADER.length;
  4098. writePngChunk('IHDR', ihdr, data, offset);
  4099. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  4100. writePngChunk('IDATA', idat, data, offset);
  4101. offset += CHUNK_WRAPPER_SIZE + idat.length;
  4102. writePngChunk('IEND', new Uint8Array(0), data, offset);
  4103. return (0, _util.createObjectURL)(data, 'image/png', forceDataSchema);
  4104. }
  4105. return function convertImgDataToPng(imgData, forceDataSchema) {
  4106. var kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
  4107. return encode(imgData, kind, forceDataSchema);
  4108. };
  4109. }();
  4110. var SVGExtraState = function SVGExtraStateClosure() {
  4111. function SVGExtraState() {
  4112. this.fontSizeScale = 1;
  4113. this.fontWeight = SVG_DEFAULTS.fontWeight;
  4114. this.fontSize = 0;
  4115. this.textMatrix = _util.IDENTITY_MATRIX;
  4116. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  4117. this.leading = 0;
  4118. this.x = 0;
  4119. this.y = 0;
  4120. this.lineX = 0;
  4121. this.lineY = 0;
  4122. this.charSpacing = 0;
  4123. this.wordSpacing = 0;
  4124. this.textHScale = 1;
  4125. this.textRise = 0;
  4126. this.fillColor = SVG_DEFAULTS.fillColor;
  4127. this.strokeColor = '#000000';
  4128. this.fillAlpha = 1;
  4129. this.strokeAlpha = 1;
  4130. this.lineWidth = 1;
  4131. this.lineJoin = '';
  4132. this.lineCap = '';
  4133. this.miterLimit = 0;
  4134. this.dashArray = [];
  4135. this.dashPhase = 0;
  4136. this.dependencies = [];
  4137. this.activeClipUrl = null;
  4138. this.clipGroup = null;
  4139. this.maskId = '';
  4140. }
  4141. SVGExtraState.prototype = {
  4142. clone: function SVGExtraState_clone() {
  4143. return Object.create(this);
  4144. },
  4145. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  4146. this.x = x;
  4147. this.y = y;
  4148. }
  4149. };
  4150. return SVGExtraState;
  4151. }();
  4152. exports.SVGGraphics = SVGGraphics = function SVGGraphicsClosure() {
  4153. function opListToTree(opList) {
  4154. var opTree = [];
  4155. var tmp = [];
  4156. var opListLen = opList.length;
  4157. for (var x = 0; x < opListLen; x++) {
  4158. if (opList[x].fn === 'save') {
  4159. opTree.push({
  4160. 'fnId': 92,
  4161. 'fn': 'group',
  4162. 'items': []
  4163. });
  4164. tmp.push(opTree);
  4165. opTree = opTree[opTree.length - 1].items;
  4166. continue;
  4167. }
  4168. if (opList[x].fn === 'restore') {
  4169. opTree = tmp.pop();
  4170. } else {
  4171. opTree.push(opList[x]);
  4172. }
  4173. }
  4174. return opTree;
  4175. }
  4176. function pf(value) {
  4177. if (value === (value | 0)) {
  4178. return value.toString();
  4179. }
  4180. var s = value.toFixed(10);
  4181. var i = s.length - 1;
  4182. if (s[i] !== '0') {
  4183. return s;
  4184. }
  4185. do {
  4186. i--;
  4187. } while (s[i] === '0');
  4188. return s.substr(0, s[i] === '.' ? i : i + 1);
  4189. }
  4190. function pm(m) {
  4191. if (m[4] === 0 && m[5] === 0) {
  4192. if (m[1] === 0 && m[2] === 0) {
  4193. if (m[0] === 1 && m[3] === 1) {
  4194. return '';
  4195. }
  4196. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  4197. }
  4198. if (m[0] === m[3] && m[1] === -m[2]) {
  4199. var a = Math.acos(m[0]) * 180 / Math.PI;
  4200. return 'rotate(' + pf(a) + ')';
  4201. }
  4202. } else {
  4203. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  4204. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  4205. }
  4206. }
  4207. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' + pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  4208. }
  4209. function SVGGraphics(commonObjs, objs, forceDataSchema) {
  4210. this.current = new SVGExtraState();
  4211. this.transformMatrix = _util.IDENTITY_MATRIX;
  4212. this.transformStack = [];
  4213. this.extraStack = [];
  4214. this.commonObjs = commonObjs;
  4215. this.objs = objs;
  4216. this.pendingClip = null;
  4217. this.pendingEOFill = false;
  4218. this.embedFonts = false;
  4219. this.embeddedFonts = Object.create(null);
  4220. this.cssStyle = null;
  4221. this.forceDataSchema = !!forceDataSchema;
  4222. }
  4223. var NS = 'http://www.w3.org/2000/svg';
  4224. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  4225. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  4226. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  4227. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  4228. var clipCount = 0;
  4229. var maskCount = 0;
  4230. SVGGraphics.prototype = {
  4231. save: function SVGGraphics_save() {
  4232. this.transformStack.push(this.transformMatrix);
  4233. var old = this.current;
  4234. this.extraStack.push(old);
  4235. this.current = old.clone();
  4236. },
  4237. restore: function SVGGraphics_restore() {
  4238. this.transformMatrix = this.transformStack.pop();
  4239. this.current = this.extraStack.pop();
  4240. this.pendingClip = null;
  4241. this.tgrp = null;
  4242. },
  4243. group: function SVGGraphics_group(items) {
  4244. this.save();
  4245. this.executeOpTree(items);
  4246. this.restore();
  4247. },
  4248. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  4249. var _this = this;
  4250. var fnArray = operatorList.fnArray;
  4251. var fnArrayLen = fnArray.length;
  4252. var argsArray = operatorList.argsArray;
  4253. for (var i = 0; i < fnArrayLen; i++) {
  4254. if (_util.OPS.dependency === fnArray[i]) {
  4255. var deps = argsArray[i];
  4256. for (var n = 0, nn = deps.length; n < nn; n++) {
  4257. var obj = deps[n];
  4258. var common = obj.substring(0, 2) === 'g_';
  4259. var promise;
  4260. if (common) {
  4261. promise = new Promise(function (resolve) {
  4262. _this.commonObjs.get(obj, resolve);
  4263. });
  4264. } else {
  4265. promise = new Promise(function (resolve) {
  4266. _this.objs.get(obj, resolve);
  4267. });
  4268. }
  4269. this.current.dependencies.push(promise);
  4270. }
  4271. }
  4272. }
  4273. return Promise.all(this.current.dependencies);
  4274. },
  4275. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  4276. var transformMatrix = [a, b, c, d, e, f];
  4277. this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
  4278. this.tgrp = null;
  4279. },
  4280. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  4281. var _this2 = this;
  4282. this.viewport = viewport;
  4283. var svgElement = this._initialize(viewport);
  4284. return this.loadDependencies(operatorList).then(function () {
  4285. _this2.transformMatrix = _util.IDENTITY_MATRIX;
  4286. var opTree = _this2.convertOpList(operatorList);
  4287. _this2.executeOpTree(opTree);
  4288. return svgElement;
  4289. });
  4290. },
  4291. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  4292. var argsArray = operatorList.argsArray;
  4293. var fnArray = operatorList.fnArray;
  4294. var fnArrayLen = fnArray.length;
  4295. var REVOPS = [];
  4296. var opList = [];
  4297. for (var op in _util.OPS) {
  4298. REVOPS[_util.OPS[op]] = op;
  4299. }
  4300. for (var x = 0; x < fnArrayLen; x++) {
  4301. var fnId = fnArray[x];
  4302. opList.push({
  4303. 'fnId': fnId,
  4304. 'fn': REVOPS[fnId],
  4305. 'args': argsArray[x]
  4306. });
  4307. }
  4308. return opListToTree(opList);
  4309. },
  4310. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  4311. var opTreeLen = opTree.length;
  4312. for (var x = 0; x < opTreeLen; x++) {
  4313. var fn = opTree[x].fn;
  4314. var fnId = opTree[x].fnId;
  4315. var args = opTree[x].args;
  4316. switch (fnId | 0) {
  4317. case _util.OPS.beginText:
  4318. this.beginText();
  4319. break;
  4320. case _util.OPS.setLeading:
  4321. this.setLeading(args);
  4322. break;
  4323. case _util.OPS.setLeadingMoveText:
  4324. this.setLeadingMoveText(args[0], args[1]);
  4325. break;
  4326. case _util.OPS.setFont:
  4327. this.setFont(args);
  4328. break;
  4329. case _util.OPS.showText:
  4330. this.showText(args[0]);
  4331. break;
  4332. case _util.OPS.showSpacedText:
  4333. this.showText(args[0]);
  4334. break;
  4335. case _util.OPS.endText:
  4336. this.endText();
  4337. break;
  4338. case _util.OPS.moveText:
  4339. this.moveText(args[0], args[1]);
  4340. break;
  4341. case _util.OPS.setCharSpacing:
  4342. this.setCharSpacing(args[0]);
  4343. break;
  4344. case _util.OPS.setWordSpacing:
  4345. this.setWordSpacing(args[0]);
  4346. break;
  4347. case _util.OPS.setHScale:
  4348. this.setHScale(args[0]);
  4349. break;
  4350. case _util.OPS.setTextMatrix:
  4351. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  4352. break;
  4353. case _util.OPS.setLineWidth:
  4354. this.setLineWidth(args[0]);
  4355. break;
  4356. case _util.OPS.setLineJoin:
  4357. this.setLineJoin(args[0]);
  4358. break;
  4359. case _util.OPS.setLineCap:
  4360. this.setLineCap(args[0]);
  4361. break;
  4362. case _util.OPS.setMiterLimit:
  4363. this.setMiterLimit(args[0]);
  4364. break;
  4365. case _util.OPS.setFillRGBColor:
  4366. this.setFillRGBColor(args[0], args[1], args[2]);
  4367. break;
  4368. case _util.OPS.setStrokeRGBColor:
  4369. this.setStrokeRGBColor(args[0], args[1], args[2]);
  4370. break;
  4371. case _util.OPS.setDash:
  4372. this.setDash(args[0], args[1]);
  4373. break;
  4374. case _util.OPS.setGState:
  4375. this.setGState(args[0]);
  4376. break;
  4377. case _util.OPS.fill:
  4378. this.fill();
  4379. break;
  4380. case _util.OPS.eoFill:
  4381. this.eoFill();
  4382. break;
  4383. case _util.OPS.stroke:
  4384. this.stroke();
  4385. break;
  4386. case _util.OPS.fillStroke:
  4387. this.fillStroke();
  4388. break;
  4389. case _util.OPS.eoFillStroke:
  4390. this.eoFillStroke();
  4391. break;
  4392. case _util.OPS.clip:
  4393. this.clip('nonzero');
  4394. break;
  4395. case _util.OPS.eoClip:
  4396. this.clip('evenodd');
  4397. break;
  4398. case _util.OPS.paintSolidColorImageMask:
  4399. this.paintSolidColorImageMask();
  4400. break;
  4401. case _util.OPS.paintJpegXObject:
  4402. this.paintJpegXObject(args[0], args[1], args[2]);
  4403. break;
  4404. case _util.OPS.paintImageXObject:
  4405. this.paintImageXObject(args[0]);
  4406. break;
  4407. case _util.OPS.paintInlineImageXObject:
  4408. this.paintInlineImageXObject(args[0]);
  4409. break;
  4410. case _util.OPS.paintImageMaskXObject:
  4411. this.paintImageMaskXObject(args[0]);
  4412. break;
  4413. case _util.OPS.paintFormXObjectBegin:
  4414. this.paintFormXObjectBegin(args[0], args[1]);
  4415. break;
  4416. case _util.OPS.paintFormXObjectEnd:
  4417. this.paintFormXObjectEnd();
  4418. break;
  4419. case _util.OPS.closePath:
  4420. this.closePath();
  4421. break;
  4422. case _util.OPS.closeStroke:
  4423. this.closeStroke();
  4424. break;
  4425. case _util.OPS.closeFillStroke:
  4426. this.closeFillStroke();
  4427. break;
  4428. case _util.OPS.nextLine:
  4429. this.nextLine();
  4430. break;
  4431. case _util.OPS.transform:
  4432. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  4433. break;
  4434. case _util.OPS.constructPath:
  4435. this.constructPath(args[0], args[1]);
  4436. break;
  4437. case _util.OPS.endPath:
  4438. this.endPath();
  4439. break;
  4440. case 92:
  4441. this.group(opTree[x].items);
  4442. break;
  4443. default:
  4444. (0, _util.warn)('Unimplemented operator ' + fn);
  4445. break;
  4446. }
  4447. }
  4448. },
  4449. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  4450. this.current.wordSpacing = wordSpacing;
  4451. },
  4452. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  4453. this.current.charSpacing = charSpacing;
  4454. },
  4455. nextLine: function SVGGraphics_nextLine() {
  4456. this.moveText(0, this.current.leading);
  4457. },
  4458. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  4459. var current = this.current;
  4460. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  4461. this.current.x = this.current.lineX = 0;
  4462. this.current.y = this.current.lineY = 0;
  4463. current.xcoords = [];
  4464. current.tspan = document.createElementNS(NS, 'svg:tspan');
  4465. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  4466. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  4467. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  4468. current.txtElement = document.createElementNS(NS, 'svg:text');
  4469. current.txtElement.appendChild(current.tspan);
  4470. },
  4471. beginText: function SVGGraphics_beginText() {
  4472. this.current.x = this.current.lineX = 0;
  4473. this.current.y = this.current.lineY = 0;
  4474. this.current.textMatrix = _util.IDENTITY_MATRIX;
  4475. this.current.lineMatrix = _util.IDENTITY_MATRIX;
  4476. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  4477. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  4478. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  4479. this.current.xcoords = [];
  4480. },
  4481. moveText: function SVGGraphics_moveText(x, y) {
  4482. var current = this.current;
  4483. this.current.x = this.current.lineX += x;
  4484. this.current.y = this.current.lineY += y;
  4485. current.xcoords = [];
  4486. current.tspan = document.createElementNS(NS, 'svg:tspan');
  4487. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  4488. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  4489. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  4490. },
  4491. showText: function SVGGraphics_showText(glyphs) {
  4492. var current = this.current;
  4493. var font = current.font;
  4494. var fontSize = current.fontSize;
  4495. if (fontSize === 0) {
  4496. return;
  4497. }
  4498. var charSpacing = current.charSpacing;
  4499. var wordSpacing = current.wordSpacing;
  4500. var fontDirection = current.fontDirection;
  4501. var textHScale = current.textHScale * fontDirection;
  4502. var glyphsLength = glyphs.length;
  4503. var vertical = font.vertical;
  4504. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4505. var x = 0,
  4506. i;
  4507. for (i = 0; i < glyphsLength; ++i) {
  4508. var glyph = glyphs[i];
  4509. if (glyph === null) {
  4510. x += fontDirection * wordSpacing;
  4511. continue;
  4512. } else if ((0, _util.isNum)(glyph)) {
  4513. x += -glyph * fontSize * 0.001;
  4514. continue;
  4515. }
  4516. current.xcoords.push(current.x + x * textHScale);
  4517. var width = glyph.width;
  4518. var character = glyph.fontChar;
  4519. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4520. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  4521. x += charWidth;
  4522. current.tspan.textContent += character;
  4523. }
  4524. if (vertical) {
  4525. current.y -= x * textHScale;
  4526. } else {
  4527. current.x += x * textHScale;
  4528. }
  4529. current.tspan.setAttributeNS(null, 'x', current.xcoords.map(pf).join(' '));
  4530. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  4531. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  4532. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  4533. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  4534. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  4535. }
  4536. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  4537. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  4538. }
  4539. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  4540. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  4541. }
  4542. current.txtElement.setAttributeNS(null, 'transform', pm(current.textMatrix) + ' scale(1, -1)');
  4543. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  4544. current.txtElement.appendChild(current.tspan);
  4545. current.txtgrp.appendChild(current.txtElement);
  4546. this._ensureTransformGroup().appendChild(current.txtElement);
  4547. },
  4548. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  4549. this.setLeading(-y);
  4550. this.moveText(x, y);
  4551. },
  4552. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  4553. if (!this.cssStyle) {
  4554. this.cssStyle = document.createElementNS(NS, 'svg:style');
  4555. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  4556. this.defs.appendChild(this.cssStyle);
  4557. }
  4558. var url = (0, _util.createObjectURL)(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  4559. this.cssStyle.textContent += '@font-face { font-family: "' + fontObj.loadedName + '";' + ' src: url(' + url + '); }\n';
  4560. },
  4561. setFont: function SVGGraphics_setFont(details) {
  4562. var current = this.current;
  4563. var fontObj = this.commonObjs.get(details[0]);
  4564. var size = details[1];
  4565. this.current.font = fontObj;
  4566. if (this.embedFonts && fontObj.data && !this.embeddedFonts[fontObj.loadedName]) {
  4567. this.addFontStyle(fontObj);
  4568. this.embeddedFonts[fontObj.loadedName] = fontObj;
  4569. }
  4570. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
  4571. var bold = fontObj.black ? fontObj.bold ? 'bolder' : 'bold' : fontObj.bold ? 'bold' : 'normal';
  4572. var italic = fontObj.italic ? 'italic' : 'normal';
  4573. if (size < 0) {
  4574. size = -size;
  4575. current.fontDirection = -1;
  4576. } else {
  4577. current.fontDirection = 1;
  4578. }
  4579. current.fontSize = size;
  4580. current.fontFamily = fontObj.loadedName;
  4581. current.fontWeight = bold;
  4582. current.fontStyle = italic;
  4583. current.tspan = document.createElementNS(NS, 'svg:tspan');
  4584. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  4585. current.xcoords = [];
  4586. },
  4587. endText: function SVGGraphics_endText() {},
  4588. setLineWidth: function SVGGraphics_setLineWidth(width) {
  4589. this.current.lineWidth = width;
  4590. },
  4591. setLineCap: function SVGGraphics_setLineCap(style) {
  4592. this.current.lineCap = LINE_CAP_STYLES[style];
  4593. },
  4594. setLineJoin: function SVGGraphics_setLineJoin(style) {
  4595. this.current.lineJoin = LINE_JOIN_STYLES[style];
  4596. },
  4597. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  4598. this.current.miterLimit = limit;
  4599. },
  4600. setStrokeAlpha: function SVGGraphics_setStrokeAlpha(strokeAlpha) {
  4601. this.current.strokeAlpha = strokeAlpha;
  4602. },
  4603. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  4604. var color = _util.Util.makeCssRgb(r, g, b);
  4605. this.current.strokeColor = color;
  4606. },
  4607. setFillAlpha: function SVGGraphics_setFillAlpha(fillAlpha) {
  4608. this.current.fillAlpha = fillAlpha;
  4609. },
  4610. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  4611. var color = _util.Util.makeCssRgb(r, g, b);
  4612. this.current.fillColor = color;
  4613. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  4614. this.current.xcoords = [];
  4615. },
  4616. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  4617. this.current.dashArray = dashArray;
  4618. this.current.dashPhase = dashPhase;
  4619. },
  4620. constructPath: function SVGGraphics_constructPath(ops, args) {
  4621. var current = this.current;
  4622. var x = current.x,
  4623. y = current.y;
  4624. current.path = document.createElementNS(NS, 'svg:path');
  4625. var d = [];
  4626. var opLength = ops.length;
  4627. for (var i = 0, j = 0; i < opLength; i++) {
  4628. switch (ops[i] | 0) {
  4629. case _util.OPS.rectangle:
  4630. x = args[j++];
  4631. y = args[j++];
  4632. var width = args[j++];
  4633. var height = args[j++];
  4634. var xw = x + width;
  4635. var yh = y + height;
  4636. d.push('M', pf(x), pf(y), 'L', pf(xw), pf(y), 'L', pf(xw), pf(yh), 'L', pf(x), pf(yh), 'Z');
  4637. break;
  4638. case _util.OPS.moveTo:
  4639. x = args[j++];
  4640. y = args[j++];
  4641. d.push('M', pf(x), pf(y));
  4642. break;
  4643. case _util.OPS.lineTo:
  4644. x = args[j++];
  4645. y = args[j++];
  4646. d.push('L', pf(x), pf(y));
  4647. break;
  4648. case _util.OPS.curveTo:
  4649. x = args[j + 4];
  4650. y = args[j + 5];
  4651. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  4652. j += 6;
  4653. break;
  4654. case _util.OPS.curveTo2:
  4655. x = args[j + 2];
  4656. y = args[j + 3];
  4657. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  4658. j += 4;
  4659. break;
  4660. case _util.OPS.curveTo3:
  4661. x = args[j + 2];
  4662. y = args[j + 3];
  4663. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  4664. j += 4;
  4665. break;
  4666. case _util.OPS.closePath:
  4667. d.push('Z');
  4668. break;
  4669. }
  4670. }
  4671. current.path.setAttributeNS(null, 'd', d.join(' '));
  4672. current.path.setAttributeNS(null, 'fill', 'none');
  4673. this._ensureTransformGroup().appendChild(current.path);
  4674. current.element = current.path;
  4675. current.setCurrentPoint(x, y);
  4676. },
  4677. endPath: function SVGGraphics_endPath() {
  4678. if (!this.pendingClip) {
  4679. return;
  4680. }
  4681. var current = this.current;
  4682. var clipId = 'clippath' + clipCount;
  4683. clipCount++;
  4684. var clipPath = document.createElementNS(NS, 'svg:clipPath');
  4685. clipPath.setAttributeNS(null, 'id', clipId);
  4686. clipPath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  4687. var clipElement = current.element.cloneNode();
  4688. if (this.pendingClip === 'evenodd') {
  4689. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  4690. } else {
  4691. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  4692. }
  4693. this.pendingClip = null;
  4694. clipPath.appendChild(clipElement);
  4695. this.defs.appendChild(clipPath);
  4696. if (current.activeClipUrl) {
  4697. current.clipGroup = null;
  4698. this.extraStack.forEach(function (prev) {
  4699. prev.clipGroup = null;
  4700. });
  4701. }
  4702. current.activeClipUrl = 'url(#' + clipId + ')';
  4703. this.tgrp = null;
  4704. },
  4705. clip: function SVGGraphics_clip(type) {
  4706. this.pendingClip = type;
  4707. },
  4708. closePath: function SVGGraphics_closePath() {
  4709. var current = this.current;
  4710. var d = current.path.getAttributeNS(null, 'd');
  4711. d += 'Z';
  4712. current.path.setAttributeNS(null, 'd', d);
  4713. },
  4714. setLeading: function SVGGraphics_setLeading(leading) {
  4715. this.current.leading = -leading;
  4716. },
  4717. setTextRise: function SVGGraphics_setTextRise(textRise) {
  4718. this.current.textRise = textRise;
  4719. },
  4720. setHScale: function SVGGraphics_setHScale(scale) {
  4721. this.current.textHScale = scale / 100;
  4722. },
  4723. setGState: function SVGGraphics_setGState(states) {
  4724. for (var i = 0, ii = states.length; i < ii; i++) {
  4725. var state = states[i];
  4726. var key = state[0];
  4727. var value = state[1];
  4728. switch (key) {
  4729. case 'LW':
  4730. this.setLineWidth(value);
  4731. break;
  4732. case 'LC':
  4733. this.setLineCap(value);
  4734. break;
  4735. case 'LJ':
  4736. this.setLineJoin(value);
  4737. break;
  4738. case 'ML':
  4739. this.setMiterLimit(value);
  4740. break;
  4741. case 'D':
  4742. this.setDash(value[0], value[1]);
  4743. break;
  4744. case 'Font':
  4745. this.setFont(value);
  4746. break;
  4747. case 'CA':
  4748. this.setStrokeAlpha(value);
  4749. break;
  4750. case 'ca':
  4751. this.setFillAlpha(value);
  4752. break;
  4753. default:
  4754. (0, _util.warn)('Unimplemented graphic state ' + key);
  4755. break;
  4756. }
  4757. }
  4758. },
  4759. fill: function SVGGraphics_fill() {
  4760. var current = this.current;
  4761. current.element.setAttributeNS(null, 'fill', current.fillColor);
  4762. current.element.setAttributeNS(null, 'fill-opacity', current.fillAlpha);
  4763. },
  4764. stroke: function SVGGraphics_stroke() {
  4765. var current = this.current;
  4766. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  4767. current.element.setAttributeNS(null, 'stroke-opacity', current.strokeAlpha);
  4768. current.element.setAttributeNS(null, 'stroke-miterlimit', pf(current.miterLimit));
  4769. current.element.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  4770. current.element.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  4771. current.element.setAttributeNS(null, 'stroke-width', pf(current.lineWidth) + 'px');
  4772. current.element.setAttributeNS(null, 'stroke-dasharray', current.dashArray.map(pf).join(' '));
  4773. current.element.setAttributeNS(null, 'stroke-dashoffset', pf(current.dashPhase) + 'px');
  4774. current.element.setAttributeNS(null, 'fill', 'none');
  4775. },
  4776. eoFill: function SVGGraphics_eoFill() {
  4777. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  4778. this.fill();
  4779. },
  4780. fillStroke: function SVGGraphics_fillStroke() {
  4781. this.stroke();
  4782. this.fill();
  4783. },
  4784. eoFillStroke: function SVGGraphics_eoFillStroke() {
  4785. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  4786. this.fillStroke();
  4787. },
  4788. closeStroke: function SVGGraphics_closeStroke() {
  4789. this.closePath();
  4790. this.stroke();
  4791. },
  4792. closeFillStroke: function SVGGraphics_closeFillStroke() {
  4793. this.closePath();
  4794. this.fillStroke();
  4795. },
  4796. paintSolidColorImageMask: function SVGGraphics_paintSolidColorImageMask() {
  4797. var current = this.current;
  4798. var rect = document.createElementNS(NS, 'svg:rect');
  4799. rect.setAttributeNS(null, 'x', '0');
  4800. rect.setAttributeNS(null, 'y', '0');
  4801. rect.setAttributeNS(null, 'width', '1px');
  4802. rect.setAttributeNS(null, 'height', '1px');
  4803. rect.setAttributeNS(null, 'fill', current.fillColor);
  4804. this._ensureTransformGroup().appendChild(rect);
  4805. },
  4806. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  4807. var imgObj = this.objs.get(objId);
  4808. var imgEl = document.createElementNS(NS, 'svg:image');
  4809. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  4810. imgEl.setAttributeNS(null, 'width', pf(w));
  4811. imgEl.setAttributeNS(null, 'height', pf(h));
  4812. imgEl.setAttributeNS(null, 'x', '0');
  4813. imgEl.setAttributeNS(null, 'y', pf(-h));
  4814. imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  4815. this._ensureTransformGroup().appendChild(imgEl);
  4816. },
  4817. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  4818. var imgData = this.objs.get(objId);
  4819. if (!imgData) {
  4820. (0, _util.warn)('Dependent image isn\'t ready yet');
  4821. return;
  4822. }
  4823. this.paintInlineImageXObject(imgData);
  4824. },
  4825. paintInlineImageXObject: function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  4826. var width = imgData.width;
  4827. var height = imgData.height;
  4828. var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema);
  4829. var cliprect = document.createElementNS(NS, 'svg:rect');
  4830. cliprect.setAttributeNS(null, 'x', '0');
  4831. cliprect.setAttributeNS(null, 'y', '0');
  4832. cliprect.setAttributeNS(null, 'width', pf(width));
  4833. cliprect.setAttributeNS(null, 'height', pf(height));
  4834. this.current.element = cliprect;
  4835. this.clip('nonzero');
  4836. var imgEl = document.createElementNS(NS, 'svg:image');
  4837. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  4838. imgEl.setAttributeNS(null, 'x', '0');
  4839. imgEl.setAttributeNS(null, 'y', pf(-height));
  4840. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  4841. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  4842. imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / width) + ' ' + pf(-1 / height) + ')');
  4843. if (mask) {
  4844. mask.appendChild(imgEl);
  4845. } else {
  4846. this._ensureTransformGroup().appendChild(imgEl);
  4847. }
  4848. },
  4849. paintImageMaskXObject: function SVGGraphics_paintImageMaskXObject(imgData) {
  4850. var current = this.current;
  4851. var width = imgData.width;
  4852. var height = imgData.height;
  4853. var fillColor = current.fillColor;
  4854. current.maskId = 'mask' + maskCount++;
  4855. var mask = document.createElementNS(NS, 'svg:mask');
  4856. mask.setAttributeNS(null, 'id', current.maskId);
  4857. var rect = document.createElementNS(NS, 'svg:rect');
  4858. rect.setAttributeNS(null, 'x', '0');
  4859. rect.setAttributeNS(null, 'y', '0');
  4860. rect.setAttributeNS(null, 'width', pf(width));
  4861. rect.setAttributeNS(null, 'height', pf(height));
  4862. rect.setAttributeNS(null, 'fill', fillColor);
  4863. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId + ')');
  4864. this.defs.appendChild(mask);
  4865. this._ensureTransformGroup().appendChild(rect);
  4866. this.paintInlineImageXObject(imgData, mask);
  4867. },
  4868. paintFormXObjectBegin: function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  4869. if ((0, _util.isArray)(matrix) && matrix.length === 6) {
  4870. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  4871. }
  4872. if ((0, _util.isArray)(bbox) && bbox.length === 4) {
  4873. var width = bbox[2] - bbox[0];
  4874. var height = bbox[3] - bbox[1];
  4875. var cliprect = document.createElementNS(NS, 'svg:rect');
  4876. cliprect.setAttributeNS(null, 'x', bbox[0]);
  4877. cliprect.setAttributeNS(null, 'y', bbox[1]);
  4878. cliprect.setAttributeNS(null, 'width', pf(width));
  4879. cliprect.setAttributeNS(null, 'height', pf(height));
  4880. this.current.element = cliprect;
  4881. this.clip('nonzero');
  4882. this.endPath();
  4883. }
  4884. },
  4885. paintFormXObjectEnd: function SVGGraphics_paintFormXObjectEnd() {},
  4886. _initialize: function SVGGraphics_initialize(viewport) {
  4887. var svg = document.createElementNS(NS, 'svg:svg');
  4888. svg.setAttributeNS(null, 'version', '1.1');
  4889. svg.setAttributeNS(null, 'width', viewport.width + 'px');
  4890. svg.setAttributeNS(null, 'height', viewport.height + 'px');
  4891. svg.setAttributeNS(null, 'preserveAspectRatio', 'none');
  4892. svg.setAttributeNS(null, 'viewBox', '0 0 ' + viewport.width + ' ' + viewport.height);
  4893. var definitions = document.createElementNS(NS, 'svg:defs');
  4894. svg.appendChild(definitions);
  4895. this.defs = definitions;
  4896. var rootGroup = document.createElementNS(NS, 'svg:g');
  4897. rootGroup.setAttributeNS(null, 'transform', pm(viewport.transform));
  4898. svg.appendChild(rootGroup);
  4899. this.svg = rootGroup;
  4900. return svg;
  4901. },
  4902. _ensureClipGroup: function SVGGraphics_ensureClipGroup() {
  4903. if (!this.current.clipGroup) {
  4904. var clipGroup = document.createElementNS(NS, 'svg:g');
  4905. clipGroup.setAttributeNS(null, 'clip-path', this.current.activeClipUrl);
  4906. this.svg.appendChild(clipGroup);
  4907. this.current.clipGroup = clipGroup;
  4908. }
  4909. return this.current.clipGroup;
  4910. },
  4911. _ensureTransformGroup: function SVGGraphics_ensureTransformGroup() {
  4912. if (!this.tgrp) {
  4913. this.tgrp = document.createElementNS(NS, 'svg:g');
  4914. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  4915. if (this.current.activeClipUrl) {
  4916. this._ensureClipGroup().appendChild(this.tgrp);
  4917. } else {
  4918. this.svg.appendChild(this.tgrp);
  4919. }
  4920. }
  4921. return this.tgrp;
  4922. }
  4923. };
  4924. return SVGGraphics;
  4925. }();
  4926. }
  4927. exports.SVGGraphics = SVGGraphics;
  4928. /***/ }),
  4929. /* 5 */
  4930. /***/ (function(module, exports, __w_pdfjs_require__) {
  4931. "use strict";
  4932. Object.defineProperty(exports, "__esModule", {
  4933. value: true
  4934. });
  4935. exports.renderTextLayer = undefined;
  4936. var _util = __w_pdfjs_require__(0);
  4937. var _dom_utils = __w_pdfjs_require__(1);
  4938. var renderTextLayer = function renderTextLayerClosure() {
  4939. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  4940. var NonWhitespaceRegexp = /\S/;
  4941. function isAllWhitespace(str) {
  4942. return !NonWhitespaceRegexp.test(str);
  4943. }
  4944. var styleBuf = ['left: ', 0, 'px; top: ', 0, 'px; font-size: ', 0, 'px; font-family: ', '', ';'];
  4945. function appendText(task, geom, styles) {
  4946. var textDiv = document.createElement('div');
  4947. var textDivProperties = {
  4948. style: null,
  4949. angle: 0,
  4950. canvasWidth: 0,
  4951. isWhitespace: false,
  4952. originalTransform: null,
  4953. paddingBottom: 0,
  4954. paddingLeft: 0,
  4955. paddingRight: 0,
  4956. paddingTop: 0,
  4957. scale: 1
  4958. };
  4959. task._textDivs.push(textDiv);
  4960. if (isAllWhitespace(geom.str)) {
  4961. textDivProperties.isWhitespace = true;
  4962. task._textDivProperties.set(textDiv, textDivProperties);
  4963. return;
  4964. }
  4965. var tx = _util.Util.transform(task._viewport.transform, geom.transform);
  4966. var angle = Math.atan2(tx[1], tx[0]);
  4967. var style = styles[geom.fontName];
  4968. if (style.vertical) {
  4969. angle += Math.PI / 2;
  4970. }
  4971. var fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]);
  4972. var fontAscent = fontHeight;
  4973. if (style.ascent) {
  4974. fontAscent = style.ascent * fontAscent;
  4975. } else if (style.descent) {
  4976. fontAscent = (1 + style.descent) * fontAscent;
  4977. }
  4978. var left;
  4979. var top;
  4980. if (angle === 0) {
  4981. left = tx[4];
  4982. top = tx[5] - fontAscent;
  4983. } else {
  4984. left = tx[4] + fontAscent * Math.sin(angle);
  4985. top = tx[5] - fontAscent * Math.cos(angle);
  4986. }
  4987. styleBuf[1] = left;
  4988. styleBuf[3] = top;
  4989. styleBuf[5] = fontHeight;
  4990. styleBuf[7] = style.fontFamily;
  4991. textDivProperties.style = styleBuf.join('');
  4992. textDiv.setAttribute('style', textDivProperties.style);
  4993. textDiv.textContent = geom.str;
  4994. if ((0, _dom_utils.getDefaultSetting)('pdfBug')) {
  4995. textDiv.dataset.fontName = geom.fontName;
  4996. }
  4997. if (angle !== 0) {
  4998. textDivProperties.angle = angle * (180 / Math.PI);
  4999. }
  5000. if (geom.str.length > 1) {
  5001. if (style.vertical) {
  5002. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  5003. } else {
  5004. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  5005. }
  5006. }
  5007. task._textDivProperties.set(textDiv, textDivProperties);
  5008. if (task._textContentStream) {
  5009. task._layoutText(textDiv);
  5010. }
  5011. if (task._enhanceTextSelection) {
  5012. var angleCos = 1,
  5013. angleSin = 0;
  5014. if (angle !== 0) {
  5015. angleCos = Math.cos(angle);
  5016. angleSin = Math.sin(angle);
  5017. }
  5018. var divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
  5019. var divHeight = fontHeight;
  5020. var m, b;
  5021. if (angle !== 0) {
  5022. m = [angleCos, angleSin, -angleSin, angleCos, left, top];
  5023. b = _util.Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
  5024. } else {
  5025. b = [left, top, left + divWidth, top + divHeight];
  5026. }
  5027. task._bounds.push({
  5028. left: b[0],
  5029. top: b[1],
  5030. right: b[2],
  5031. bottom: b[3],
  5032. div: textDiv,
  5033. size: [divWidth, divHeight],
  5034. m: m
  5035. });
  5036. }
  5037. }
  5038. function render(task) {
  5039. if (task._canceled) {
  5040. return;
  5041. }
  5042. var textDivs = task._textDivs;
  5043. var capability = task._capability;
  5044. var textDivsLength = textDivs.length;
  5045. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  5046. task._renderingDone = true;
  5047. capability.resolve();
  5048. return;
  5049. }
  5050. if (!task._textContentStream) {
  5051. for (var i = 0; i < textDivsLength; i++) {
  5052. task._layoutText(textDivs[i]);
  5053. }
  5054. }
  5055. task._renderingDone = true;
  5056. capability.resolve();
  5057. }
  5058. function expand(task) {
  5059. var bounds = task._bounds;
  5060. var viewport = task._viewport;
  5061. var expanded = expandBounds(viewport.width, viewport.height, bounds);
  5062. for (var i = 0; i < expanded.length; i++) {
  5063. var div = bounds[i].div;
  5064. var divProperties = task._textDivProperties.get(div);
  5065. if (divProperties.angle === 0) {
  5066. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  5067. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  5068. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  5069. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  5070. task._textDivProperties.set(div, divProperties);
  5071. continue;
  5072. }
  5073. var e = expanded[i],
  5074. b = bounds[i];
  5075. var m = b.m,
  5076. c = m[0],
  5077. s = m[1];
  5078. var points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
  5079. var ts = new Float64Array(64);
  5080. points.forEach(function (p, i) {
  5081. var t = _util.Util.applyTransform(p, m);
  5082. ts[i + 0] = c && (e.left - t[0]) / c;
  5083. ts[i + 4] = s && (e.top - t[1]) / s;
  5084. ts[i + 8] = c && (e.right - t[0]) / c;
  5085. ts[i + 12] = s && (e.bottom - t[1]) / s;
  5086. ts[i + 16] = s && (e.left - t[0]) / -s;
  5087. ts[i + 20] = c && (e.top - t[1]) / c;
  5088. ts[i + 24] = s && (e.right - t[0]) / -s;
  5089. ts[i + 28] = c && (e.bottom - t[1]) / c;
  5090. ts[i + 32] = c && (e.left - t[0]) / -c;
  5091. ts[i + 36] = s && (e.top - t[1]) / -s;
  5092. ts[i + 40] = c && (e.right - t[0]) / -c;
  5093. ts[i + 44] = s && (e.bottom - t[1]) / -s;
  5094. ts[i + 48] = s && (e.left - t[0]) / s;
  5095. ts[i + 52] = c && (e.top - t[1]) / -c;
  5096. ts[i + 56] = s && (e.right - t[0]) / s;
  5097. ts[i + 60] = c && (e.bottom - t[1]) / -c;
  5098. });
  5099. var findPositiveMin = function findPositiveMin(ts, offset, count) {
  5100. var result = 0;
  5101. for (var i = 0; i < count; i++) {
  5102. var t = ts[offset++];
  5103. if (t > 0) {
  5104. result = result ? Math.min(t, result) : t;
  5105. }
  5106. }
  5107. return result;
  5108. };
  5109. var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  5110. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  5111. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  5112. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  5113. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  5114. task._textDivProperties.set(div, divProperties);
  5115. }
  5116. }
  5117. function expandBounds(width, height, boxes) {
  5118. var bounds = boxes.map(function (box, i) {
  5119. return {
  5120. x1: box.left,
  5121. y1: box.top,
  5122. x2: box.right,
  5123. y2: box.bottom,
  5124. index: i,
  5125. x1New: undefined,
  5126. x2New: undefined
  5127. };
  5128. });
  5129. expandBoundsLTR(width, bounds);
  5130. var expanded = new Array(boxes.length);
  5131. bounds.forEach(function (b) {
  5132. var i = b.index;
  5133. expanded[i] = {
  5134. left: b.x1New,
  5135. top: 0,
  5136. right: b.x2New,
  5137. bottom: 0
  5138. };
  5139. });
  5140. boxes.map(function (box, i) {
  5141. var e = expanded[i],
  5142. b = bounds[i];
  5143. b.x1 = box.top;
  5144. b.y1 = width - e.right;
  5145. b.x2 = box.bottom;
  5146. b.y2 = width - e.left;
  5147. b.index = i;
  5148. b.x1New = undefined;
  5149. b.x2New = undefined;
  5150. });
  5151. expandBoundsLTR(height, bounds);
  5152. bounds.forEach(function (b) {
  5153. var i = b.index;
  5154. expanded[i].top = b.x1New;
  5155. expanded[i].bottom = b.x2New;
  5156. });
  5157. return expanded;
  5158. }
  5159. function expandBoundsLTR(width, bounds) {
  5160. bounds.sort(function (a, b) {
  5161. return a.x1 - b.x1 || a.index - b.index;
  5162. });
  5163. var fakeBoundary = {
  5164. x1: -Infinity,
  5165. y1: -Infinity,
  5166. x2: 0,
  5167. y2: Infinity,
  5168. index: -1,
  5169. x1New: 0,
  5170. x2New: 0
  5171. };
  5172. var horizon = [{
  5173. start: -Infinity,
  5174. end: Infinity,
  5175. boundary: fakeBoundary
  5176. }];
  5177. bounds.forEach(function (boundary) {
  5178. var i = 0;
  5179. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  5180. i++;
  5181. }
  5182. var j = horizon.length - 1;
  5183. while (j >= 0 && horizon[j].start >= boundary.y2) {
  5184. j--;
  5185. }
  5186. var horizonPart, affectedBoundary;
  5187. var q,
  5188. k,
  5189. maxXNew = -Infinity;
  5190. for (q = i; q <= j; q++) {
  5191. horizonPart = horizon[q];
  5192. affectedBoundary = horizonPart.boundary;
  5193. var xNew;
  5194. if (affectedBoundary.x2 > boundary.x1) {
  5195. xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
  5196. } else if (affectedBoundary.x2New === undefined) {
  5197. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  5198. } else {
  5199. xNew = affectedBoundary.x2New;
  5200. }
  5201. if (xNew > maxXNew) {
  5202. maxXNew = xNew;
  5203. }
  5204. }
  5205. boundary.x1New = maxXNew;
  5206. for (q = i; q <= j; q++) {
  5207. horizonPart = horizon[q];
  5208. affectedBoundary = horizonPart.boundary;
  5209. if (affectedBoundary.x2New === undefined) {
  5210. if (affectedBoundary.x2 > boundary.x1) {
  5211. if (affectedBoundary.index > boundary.index) {
  5212. affectedBoundary.x2New = affectedBoundary.x2;
  5213. }
  5214. } else {
  5215. affectedBoundary.x2New = maxXNew;
  5216. }
  5217. } else if (affectedBoundary.x2New > maxXNew) {
  5218. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  5219. }
  5220. }
  5221. var changedHorizon = [],
  5222. lastBoundary = null;
  5223. for (q = i; q <= j; q++) {
  5224. horizonPart = horizon[q];
  5225. affectedBoundary = horizonPart.boundary;
  5226. var useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
  5227. if (lastBoundary === useBoundary) {
  5228. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  5229. } else {
  5230. changedHorizon.push({
  5231. start: horizonPart.start,
  5232. end: horizonPart.end,
  5233. boundary: useBoundary
  5234. });
  5235. lastBoundary = useBoundary;
  5236. }
  5237. }
  5238. if (horizon[i].start < boundary.y1) {
  5239. changedHorizon[0].start = boundary.y1;
  5240. changedHorizon.unshift({
  5241. start: horizon[i].start,
  5242. end: boundary.y1,
  5243. boundary: horizon[i].boundary
  5244. });
  5245. }
  5246. if (boundary.y2 < horizon[j].end) {
  5247. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  5248. changedHorizon.push({
  5249. start: boundary.y2,
  5250. end: horizon[j].end,
  5251. boundary: horizon[j].boundary
  5252. });
  5253. }
  5254. for (q = i; q <= j; q++) {
  5255. horizonPart = horizon[q];
  5256. affectedBoundary = horizonPart.boundary;
  5257. if (affectedBoundary.x2New !== undefined) {
  5258. continue;
  5259. }
  5260. var used = false;
  5261. for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
  5262. used = horizon[k].boundary === affectedBoundary;
  5263. }
  5264. for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
  5265. used = horizon[k].boundary === affectedBoundary;
  5266. }
  5267. for (k = 0; !used && k < changedHorizon.length; k++) {
  5268. used = changedHorizon[k].boundary === affectedBoundary;
  5269. }
  5270. if (!used) {
  5271. affectedBoundary.x2New = maxXNew;
  5272. }
  5273. }
  5274. Array.prototype.splice.apply(horizon, [i, j - i + 1].concat(changedHorizon));
  5275. });
  5276. horizon.forEach(function (horizonPart) {
  5277. var affectedBoundary = horizonPart.boundary;
  5278. if (affectedBoundary.x2New === undefined) {
  5279. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  5280. }
  5281. });
  5282. }
  5283. function TextLayerRenderTask(_ref) {
  5284. var textContent = _ref.textContent,
  5285. textContentStream = _ref.textContentStream,
  5286. container = _ref.container,
  5287. viewport = _ref.viewport,
  5288. textDivs = _ref.textDivs,
  5289. textContentItemsStr = _ref.textContentItemsStr,
  5290. enhanceTextSelection = _ref.enhanceTextSelection;
  5291. this._textContent = textContent;
  5292. this._textContentStream = textContentStream;
  5293. this._container = container;
  5294. this._viewport = viewport;
  5295. this._textDivs = textDivs || [];
  5296. this._textContentItemsStr = textContentItemsStr || [];
  5297. this._enhanceTextSelection = !!enhanceTextSelection;
  5298. this._reader = null;
  5299. this._layoutTextLastFontSize = null;
  5300. this._layoutTextLastFontFamily = null;
  5301. this._layoutTextCtx = null;
  5302. this._textDivProperties = new WeakMap();
  5303. this._renderingDone = false;
  5304. this._canceled = false;
  5305. this._capability = (0, _util.createPromiseCapability)();
  5306. this._renderTimer = null;
  5307. this._bounds = [];
  5308. }
  5309. TextLayerRenderTask.prototype = {
  5310. get promise() {
  5311. return this._capability.promise;
  5312. },
  5313. cancel: function TextLayer_cancel() {
  5314. if (this._reader) {
  5315. this._reader.cancel(new _util.AbortException('text layer task cancelled'));
  5316. this._reader = null;
  5317. }
  5318. this._canceled = true;
  5319. if (this._renderTimer !== null) {
  5320. clearTimeout(this._renderTimer);
  5321. this._renderTimer = null;
  5322. }
  5323. this._capability.reject('canceled');
  5324. },
  5325. _processItems: function _processItems(items, styleCache) {
  5326. for (var i = 0, len = items.length; i < len; i++) {
  5327. this._textContentItemsStr.push(items[i].str);
  5328. appendText(this, items[i], styleCache);
  5329. }
  5330. },
  5331. _layoutText: function _layoutText(textDiv) {
  5332. var textLayerFrag = this._container;
  5333. var textDivProperties = this._textDivProperties.get(textDiv);
  5334. if (textDivProperties.isWhitespace) {
  5335. return;
  5336. }
  5337. var fontSize = textDiv.style.fontSize;
  5338. var fontFamily = textDiv.style.fontFamily;
  5339. if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
  5340. this._layoutTextCtx.font = fontSize + ' ' + fontFamily;
  5341. this._lastFontSize = fontSize;
  5342. this._lastFontFamily = fontFamily;
  5343. }
  5344. var width = this._layoutTextCtx.measureText(textDiv.textContent).width;
  5345. var transform = '';
  5346. if (textDivProperties.canvasWidth !== 0 && width > 0) {
  5347. textDivProperties.scale = textDivProperties.canvasWidth / width;
  5348. transform = 'scaleX(' + textDivProperties.scale + ')';
  5349. }
  5350. if (textDivProperties.angle !== 0) {
  5351. transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform;
  5352. }
  5353. if (transform !== '') {
  5354. textDivProperties.originalTransform = transform;
  5355. _dom_utils.CustomStyle.setProp('transform', textDiv, transform);
  5356. }
  5357. this._textDivProperties.set(textDiv, textDivProperties);
  5358. textLayerFrag.appendChild(textDiv);
  5359. },
  5360. _render: function TextLayer_render(timeout) {
  5361. var _this = this;
  5362. var capability = (0, _util.createPromiseCapability)();
  5363. var styleCache = Object.create(null);
  5364. var canvas = document.createElement('canvas');
  5365. canvas.mozOpaque = true;
  5366. this._layoutTextCtx = canvas.getContext('2d', { alpha: false });
  5367. if (this._textContent) {
  5368. var textItems = this._textContent.items;
  5369. var textStyles = this._textContent.styles;
  5370. this._processItems(textItems, textStyles);
  5371. capability.resolve();
  5372. } else if (this._textContentStream) {
  5373. var pump = function pump() {
  5374. _this._reader.read().then(function (_ref2) {
  5375. var value = _ref2.value,
  5376. done = _ref2.done;
  5377. if (done) {
  5378. capability.resolve();
  5379. return;
  5380. }
  5381. _util.Util.extendObj(styleCache, value.styles);
  5382. _this._processItems(value.items, styleCache);
  5383. pump();
  5384. }, capability.reject);
  5385. };
  5386. this._reader = this._textContentStream.getReader();
  5387. pump();
  5388. } else {
  5389. throw new Error('Neither "textContent" nor "textContentStream"' + ' parameters specified.');
  5390. }
  5391. capability.promise.then(function () {
  5392. styleCache = null;
  5393. if (!timeout) {
  5394. render(_this);
  5395. } else {
  5396. _this._renderTimer = setTimeout(function () {
  5397. render(_this);
  5398. _this._renderTimer = null;
  5399. }, timeout);
  5400. }
  5401. }, this._capability.reject);
  5402. },
  5403. expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
  5404. if (!this._enhanceTextSelection || !this._renderingDone) {
  5405. return;
  5406. }
  5407. if (this._bounds !== null) {
  5408. expand(this);
  5409. this._bounds = null;
  5410. }
  5411. for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
  5412. var div = this._textDivs[i];
  5413. var divProperties = this._textDivProperties.get(div);
  5414. if (divProperties.isWhitespace) {
  5415. continue;
  5416. }
  5417. if (expandDivs) {
  5418. var transform = '',
  5419. padding = '';
  5420. if (divProperties.scale !== 1) {
  5421. transform = 'scaleX(' + divProperties.scale + ')';
  5422. }
  5423. if (divProperties.angle !== 0) {
  5424. transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
  5425. }
  5426. if (divProperties.paddingLeft !== 0) {
  5427. padding += ' padding-left: ' + divProperties.paddingLeft / divProperties.scale + 'px;';
  5428. transform += ' translateX(' + -divProperties.paddingLeft / divProperties.scale + 'px)';
  5429. }
  5430. if (divProperties.paddingTop !== 0) {
  5431. padding += ' padding-top: ' + divProperties.paddingTop + 'px;';
  5432. transform += ' translateY(' + -divProperties.paddingTop + 'px)';
  5433. }
  5434. if (divProperties.paddingRight !== 0) {
  5435. padding += ' padding-right: ' + divProperties.paddingRight / divProperties.scale + 'px;';
  5436. }
  5437. if (divProperties.paddingBottom !== 0) {
  5438. padding += ' padding-bottom: ' + divProperties.paddingBottom + 'px;';
  5439. }
  5440. if (padding !== '') {
  5441. div.setAttribute('style', divProperties.style + padding);
  5442. }
  5443. if (transform !== '') {
  5444. _dom_utils.CustomStyle.setProp('transform', div, transform);
  5445. }
  5446. } else {
  5447. div.style.padding = 0;
  5448. _dom_utils.CustomStyle.setProp('transform', div, divProperties.originalTransform || '');
  5449. }
  5450. }
  5451. }
  5452. };
  5453. function renderTextLayer(renderParameters) {
  5454. var task = new TextLayerRenderTask({
  5455. textContent: renderParameters.textContent,
  5456. textContentStream: renderParameters.textContentStream,
  5457. container: renderParameters.container,
  5458. viewport: renderParameters.viewport,
  5459. textDivs: renderParameters.textDivs,
  5460. textContentItemsStr: renderParameters.textContentItemsStr,
  5461. enhanceTextSelection: renderParameters.enhanceTextSelection
  5462. });
  5463. task._render(renderParameters.timeout);
  5464. return task;
  5465. }
  5466. return renderTextLayer;
  5467. }();
  5468. exports.renderTextLayer = renderTextLayer;
  5469. /***/ }),
  5470. /* 6 */
  5471. /***/ (function(module, exports, __w_pdfjs_require__) {
  5472. "use strict";
  5473. Object.defineProperty(exports, "__esModule", {
  5474. value: true
  5475. });
  5476. function fixMetadata(meta) {
  5477. return meta.replace(/>\\376\\377([^<]+)/g, function (all, codes) {
  5478. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
  5479. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  5480. });
  5481. var chars = '';
  5482. for (var i = 0; i < bytes.length; i += 2) {
  5483. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  5484. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38 ? String.fromCharCode(code) : '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  5485. }
  5486. return '>' + chars;
  5487. });
  5488. }
  5489. function Metadata(meta) {
  5490. if (typeof meta === 'string') {
  5491. meta = fixMetadata(meta);
  5492. var parser = new DOMParser();
  5493. meta = parser.parseFromString(meta, 'application/xml');
  5494. } else if (!(meta instanceof Document)) {
  5495. throw new Error('Metadata: Invalid metadata object');
  5496. }
  5497. this.metaDocument = meta;
  5498. this.metadata = Object.create(null);
  5499. this.parse();
  5500. }
  5501. Metadata.prototype = {
  5502. parse: function Metadata_parse() {
  5503. var doc = this.metaDocument;
  5504. var rdf = doc.documentElement;
  5505. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  5506. rdf = rdf.firstChild;
  5507. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  5508. rdf = rdf.nextSibling;
  5509. }
  5510. }
  5511. var nodeName = rdf ? rdf.nodeName.toLowerCase() : null;
  5512. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  5513. return;
  5514. }
  5515. var children = rdf.childNodes,
  5516. desc,
  5517. entry,
  5518. name,
  5519. i,
  5520. ii,
  5521. length,
  5522. iLength;
  5523. for (i = 0, length = children.length; i < length; i++) {
  5524. desc = children[i];
  5525. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  5526. continue;
  5527. }
  5528. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  5529. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  5530. entry = desc.childNodes[ii];
  5531. name = entry.nodeName.toLowerCase();
  5532. this.metadata[name] = entry.textContent.trim();
  5533. }
  5534. }
  5535. }
  5536. },
  5537. get: function Metadata_get(name) {
  5538. return this.metadata[name] || null;
  5539. },
  5540. has: function Metadata_has(name) {
  5541. return typeof this.metadata[name] !== 'undefined';
  5542. }
  5543. };
  5544. exports.Metadata = Metadata;
  5545. /***/ }),
  5546. /* 7 */
  5547. /***/ (function(module, exports, __w_pdfjs_require__) {
  5548. "use strict";
  5549. Object.defineProperty(exports, "__esModule", {
  5550. value: true
  5551. });
  5552. exports.WebGLUtils = undefined;
  5553. var _dom_utils = __w_pdfjs_require__(1);
  5554. var _util = __w_pdfjs_require__(0);
  5555. var WebGLUtils = function WebGLUtilsClosure() {
  5556. function loadShader(gl, code, shaderType) {
  5557. var shader = gl.createShader(shaderType);
  5558. gl.shaderSource(shader, code);
  5559. gl.compileShader(shader);
  5560. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  5561. if (!compiled) {
  5562. var errorMsg = gl.getShaderInfoLog(shader);
  5563. throw new Error('Error during shader compilation: ' + errorMsg);
  5564. }
  5565. return shader;
  5566. }
  5567. function createVertexShader(gl, code) {
  5568. return loadShader(gl, code, gl.VERTEX_SHADER);
  5569. }
  5570. function createFragmentShader(gl, code) {
  5571. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  5572. }
  5573. function createProgram(gl, shaders) {
  5574. var program = gl.createProgram();
  5575. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  5576. gl.attachShader(program, shaders[i]);
  5577. }
  5578. gl.linkProgram(program);
  5579. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  5580. if (!linked) {
  5581. var errorMsg = gl.getProgramInfoLog(program);
  5582. throw new Error('Error during program linking: ' + errorMsg);
  5583. }
  5584. return program;
  5585. }
  5586. function createTexture(gl, image, textureId) {
  5587. gl.activeTexture(textureId);
  5588. var texture = gl.createTexture();
  5589. gl.bindTexture(gl.TEXTURE_2D, texture);
  5590. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  5591. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  5592. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  5593. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  5594. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  5595. return texture;
  5596. }
  5597. var currentGL, currentCanvas;
  5598. function generateGL() {
  5599. if (currentGL) {
  5600. return;
  5601. }
  5602. currentCanvas = document.createElement('canvas');
  5603. currentGL = currentCanvas.getContext('webgl', { premultipliedalpha: false });
  5604. }
  5605. var smaskVertexShaderCode = '\
  5606. attribute vec2 a_position; \
  5607. attribute vec2 a_texCoord; \
  5608. \
  5609. uniform vec2 u_resolution; \
  5610. \
  5611. varying vec2 v_texCoord; \
  5612. \
  5613. void main() { \
  5614. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  5615. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  5616. \
  5617. v_texCoord = a_texCoord; \
  5618. } ';
  5619. var smaskFragmentShaderCode = '\
  5620. precision mediump float; \
  5621. \
  5622. uniform vec4 u_backdrop; \
  5623. uniform int u_subtype; \
  5624. uniform sampler2D u_image; \
  5625. uniform sampler2D u_mask; \
  5626. \
  5627. varying vec2 v_texCoord; \
  5628. \
  5629. void main() { \
  5630. vec4 imageColor = texture2D(u_image, v_texCoord); \
  5631. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  5632. if (u_backdrop.a > 0.0) { \
  5633. maskColor.rgb = maskColor.rgb * maskColor.a + \
  5634. u_backdrop.rgb * (1.0 - maskColor.a); \
  5635. } \
  5636. float lum; \
  5637. if (u_subtype == 0) { \
  5638. lum = maskColor.a; \
  5639. } else { \
  5640. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  5641. maskColor.b * 0.11; \
  5642. } \
  5643. imageColor.a *= lum; \
  5644. imageColor.rgb *= imageColor.a; \
  5645. gl_FragColor = imageColor; \
  5646. } ';
  5647. var smaskCache = null;
  5648. function initSmaskGL() {
  5649. var canvas, gl;
  5650. generateGL();
  5651. canvas = currentCanvas;
  5652. currentCanvas = null;
  5653. gl = currentGL;
  5654. currentGL = null;
  5655. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  5656. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  5657. var program = createProgram(gl, [vertexShader, fragmentShader]);
  5658. gl.useProgram(program);
  5659. var cache = {};
  5660. cache.gl = gl;
  5661. cache.canvas = canvas;
  5662. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  5663. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  5664. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  5665. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  5666. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  5667. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  5668. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  5669. var texCoordBuffer = gl.createBuffer();
  5670. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  5671. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]), gl.STATIC_DRAW);
  5672. gl.enableVertexAttribArray(texCoordLocation);
  5673. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  5674. gl.uniform1i(texLayerLocation, 0);
  5675. gl.uniform1i(texMaskLocation, 1);
  5676. smaskCache = cache;
  5677. }
  5678. function composeSMask(layer, mask, properties) {
  5679. var width = layer.width,
  5680. height = layer.height;
  5681. if (!smaskCache) {
  5682. initSmaskGL();
  5683. }
  5684. var cache = smaskCache,
  5685. canvas = cache.canvas,
  5686. gl = cache.gl;
  5687. canvas.width = width;
  5688. canvas.height = height;
  5689. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  5690. gl.uniform2f(cache.resolutionLocation, width, height);
  5691. if (properties.backdrop) {
  5692. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0], properties.backdrop[1], properties.backdrop[2], 1);
  5693. } else {
  5694. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  5695. }
  5696. gl.uniform1i(cache.subtypeLocation, properties.subtype === 'Luminosity' ? 1 : 0);
  5697. var texture = createTexture(gl, layer, gl.TEXTURE0);
  5698. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  5699. var buffer = gl.createBuffer();
  5700. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  5701. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, width, 0, 0, height, 0, height, width, 0, width, height]), gl.STATIC_DRAW);
  5702. gl.enableVertexAttribArray(cache.positionLocation);
  5703. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  5704. gl.clearColor(0, 0, 0, 0);
  5705. gl.enable(gl.BLEND);
  5706. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  5707. gl.clear(gl.COLOR_BUFFER_BIT);
  5708. gl.drawArrays(gl.TRIANGLES, 0, 6);
  5709. gl.flush();
  5710. gl.deleteTexture(texture);
  5711. gl.deleteTexture(maskTexture);
  5712. gl.deleteBuffer(buffer);
  5713. return canvas;
  5714. }
  5715. var figuresVertexShaderCode = '\
  5716. attribute vec2 a_position; \
  5717. attribute vec3 a_color; \
  5718. \
  5719. uniform vec2 u_resolution; \
  5720. uniform vec2 u_scale; \
  5721. uniform vec2 u_offset; \
  5722. \
  5723. varying vec4 v_color; \
  5724. \
  5725. void main() { \
  5726. vec2 position = (a_position + u_offset) * u_scale; \
  5727. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  5728. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  5729. \
  5730. v_color = vec4(a_color / 255.0, 1.0); \
  5731. } ';
  5732. var figuresFragmentShaderCode = '\
  5733. precision mediump float; \
  5734. \
  5735. varying vec4 v_color; \
  5736. \
  5737. void main() { \
  5738. gl_FragColor = v_color; \
  5739. } ';
  5740. var figuresCache = null;
  5741. function initFiguresGL() {
  5742. var canvas, gl;
  5743. generateGL();
  5744. canvas = currentCanvas;
  5745. currentCanvas = null;
  5746. gl = currentGL;
  5747. currentGL = null;
  5748. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  5749. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  5750. var program = createProgram(gl, [vertexShader, fragmentShader]);
  5751. gl.useProgram(program);
  5752. var cache = {};
  5753. cache.gl = gl;
  5754. cache.canvas = canvas;
  5755. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  5756. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  5757. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  5758. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  5759. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  5760. figuresCache = cache;
  5761. }
  5762. function drawFigures(width, height, backgroundColor, figures, context) {
  5763. if (!figuresCache) {
  5764. initFiguresGL();
  5765. }
  5766. var cache = figuresCache,
  5767. canvas = cache.canvas,
  5768. gl = cache.gl;
  5769. canvas.width = width;
  5770. canvas.height = height;
  5771. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  5772. gl.uniform2f(cache.resolutionLocation, width, height);
  5773. var count = 0;
  5774. var i, ii, rows;
  5775. for (i = 0, ii = figures.length; i < ii; i++) {
  5776. switch (figures[i].type) {
  5777. case 'lattice':
  5778. rows = figures[i].coords.length / figures[i].verticesPerRow | 0;
  5779. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  5780. break;
  5781. case 'triangles':
  5782. count += figures[i].coords.length;
  5783. break;
  5784. }
  5785. }
  5786. var coords = new Float32Array(count * 2);
  5787. var colors = new Uint8Array(count * 3);
  5788. var coordsMap = context.coords,
  5789. colorsMap = context.colors;
  5790. var pIndex = 0,
  5791. cIndex = 0;
  5792. for (i = 0, ii = figures.length; i < ii; i++) {
  5793. var figure = figures[i],
  5794. ps = figure.coords,
  5795. cs = figure.colors;
  5796. switch (figure.type) {
  5797. case 'lattice':
  5798. var cols = figure.verticesPerRow;
  5799. rows = ps.length / cols | 0;
  5800. for (var row = 1; row < rows; row++) {
  5801. var offset = row * cols + 1;
  5802. for (var col = 1; col < cols; col++, offset++) {
  5803. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  5804. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  5805. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  5806. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  5807. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  5808. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  5809. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  5810. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  5811. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  5812. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  5813. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  5814. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  5815. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  5816. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  5817. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  5818. coords[pIndex + 6] = coords[pIndex + 2];
  5819. coords[pIndex + 7] = coords[pIndex + 3];
  5820. coords[pIndex + 8] = coords[pIndex + 4];
  5821. coords[pIndex + 9] = coords[pIndex + 5];
  5822. coords[pIndex + 10] = coordsMap[ps[offset]];
  5823. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  5824. colors[cIndex + 9] = colors[cIndex + 3];
  5825. colors[cIndex + 10] = colors[cIndex + 4];
  5826. colors[cIndex + 11] = colors[cIndex + 5];
  5827. colors[cIndex + 12] = colors[cIndex + 6];
  5828. colors[cIndex + 13] = colors[cIndex + 7];
  5829. colors[cIndex + 14] = colors[cIndex + 8];
  5830. colors[cIndex + 15] = colorsMap[cs[offset]];
  5831. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  5832. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  5833. pIndex += 12;
  5834. cIndex += 18;
  5835. }
  5836. }
  5837. break;
  5838. case 'triangles':
  5839. for (var j = 0, jj = ps.length; j < jj; j++) {
  5840. coords[pIndex] = coordsMap[ps[j]];
  5841. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  5842. colors[cIndex] = colorsMap[cs[j]];
  5843. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  5844. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  5845. pIndex += 2;
  5846. cIndex += 3;
  5847. }
  5848. break;
  5849. }
  5850. }
  5851. if (backgroundColor) {
  5852. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255, backgroundColor[2] / 255, 1.0);
  5853. } else {
  5854. gl.clearColor(0, 0, 0, 0);
  5855. }
  5856. gl.clear(gl.COLOR_BUFFER_BIT);
  5857. var coordsBuffer = gl.createBuffer();
  5858. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  5859. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  5860. gl.enableVertexAttribArray(cache.positionLocation);
  5861. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  5862. var colorsBuffer = gl.createBuffer();
  5863. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  5864. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  5865. gl.enableVertexAttribArray(cache.colorLocation);
  5866. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false, 0, 0);
  5867. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  5868. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  5869. gl.drawArrays(gl.TRIANGLES, 0, count);
  5870. gl.flush();
  5871. gl.deleteBuffer(coordsBuffer);
  5872. gl.deleteBuffer(colorsBuffer);
  5873. return canvas;
  5874. }
  5875. function cleanup() {
  5876. if (smaskCache && smaskCache.canvas) {
  5877. smaskCache.canvas.width = 0;
  5878. smaskCache.canvas.height = 0;
  5879. }
  5880. if (figuresCache && figuresCache.canvas) {
  5881. figuresCache.canvas.width = 0;
  5882. figuresCache.canvas.height = 0;
  5883. }
  5884. smaskCache = null;
  5885. figuresCache = null;
  5886. }
  5887. return {
  5888. get isEnabled() {
  5889. if ((0, _dom_utils.getDefaultSetting)('disableWebGL')) {
  5890. return false;
  5891. }
  5892. var enabled = false;
  5893. try {
  5894. generateGL();
  5895. enabled = !!currentGL;
  5896. } catch (e) {}
  5897. return (0, _util.shadow)(this, 'isEnabled', enabled);
  5898. },
  5899. composeSMask: composeSMask,
  5900. drawFigures: drawFigures,
  5901. clear: cleanup
  5902. };
  5903. }();
  5904. exports.WebGLUtils = WebGLUtils;
  5905. /***/ }),
  5906. /* 8 */
  5907. /***/ (function(module, exports, __w_pdfjs_require__) {
  5908. "use strict";
  5909. Object.defineProperty(exports, "__esModule", {
  5910. value: true
  5911. });
  5912. exports.PDFJS = exports.isWorker = exports.globalScope = undefined;
  5913. var _api = __w_pdfjs_require__(2);
  5914. var _dom_utils = __w_pdfjs_require__(1);
  5915. var _util = __w_pdfjs_require__(0);
  5916. var _annotation_layer = __w_pdfjs_require__(3);
  5917. var _metadata = __w_pdfjs_require__(6);
  5918. var _text_layer = __w_pdfjs_require__(5);
  5919. var _svg = __w_pdfjs_require__(4);
  5920. var isWorker = typeof window === 'undefined';
  5921. if (!_util.globalScope.PDFJS) {
  5922. _util.globalScope.PDFJS = {};
  5923. }
  5924. var PDFJS = _util.globalScope.PDFJS;
  5925. {
  5926. PDFJS.version = '1.9.426';
  5927. PDFJS.build = '2558a58d';
  5928. }
  5929. PDFJS.pdfBug = false;
  5930. if (PDFJS.verbosity !== undefined) {
  5931. (0, _util.setVerbosityLevel)(PDFJS.verbosity);
  5932. }
  5933. delete PDFJS.verbosity;
  5934. Object.defineProperty(PDFJS, 'verbosity', {
  5935. get: function get() {
  5936. return (0, _util.getVerbosityLevel)();
  5937. },
  5938. set: function set(level) {
  5939. (0, _util.setVerbosityLevel)(level);
  5940. },
  5941. enumerable: true,
  5942. configurable: true
  5943. });
  5944. PDFJS.VERBOSITY_LEVELS = _util.VERBOSITY_LEVELS;
  5945. PDFJS.OPS = _util.OPS;
  5946. PDFJS.UNSUPPORTED_FEATURES = _util.UNSUPPORTED_FEATURES;
  5947. PDFJS.isValidUrl = _dom_utils.isValidUrl;
  5948. PDFJS.shadow = _util.shadow;
  5949. PDFJS.createBlob = _util.createBlob;
  5950. PDFJS.createObjectURL = function PDFJS_createObjectURL(data, contentType) {
  5951. return (0, _util.createObjectURL)(data, contentType, PDFJS.disableCreateObjectURL);
  5952. };
  5953. Object.defineProperty(PDFJS, 'isLittleEndian', {
  5954. configurable: true,
  5955. get: function PDFJS_isLittleEndian() {
  5956. return (0, _util.shadow)(PDFJS, 'isLittleEndian', (0, _util.isLittleEndian)());
  5957. }
  5958. });
  5959. PDFJS.removeNullCharacters = _util.removeNullCharacters;
  5960. PDFJS.PasswordResponses = _util.PasswordResponses;
  5961. PDFJS.PasswordException = _util.PasswordException;
  5962. PDFJS.UnknownErrorException = _util.UnknownErrorException;
  5963. PDFJS.InvalidPDFException = _util.InvalidPDFException;
  5964. PDFJS.MissingPDFException = _util.MissingPDFException;
  5965. PDFJS.UnexpectedResponseException = _util.UnexpectedResponseException;
  5966. PDFJS.Util = _util.Util;
  5967. PDFJS.PageViewport = _util.PageViewport;
  5968. PDFJS.createPromiseCapability = _util.createPromiseCapability;
  5969. PDFJS.maxImageSize = PDFJS.maxImageSize === undefined ? -1 : PDFJS.maxImageSize;
  5970. PDFJS.cMapUrl = PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl;
  5971. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  5972. PDFJS.disableFontFace = PDFJS.disableFontFace === undefined ? false : PDFJS.disableFontFace;
  5973. PDFJS.imageResourcesPath = PDFJS.imageResourcesPath === undefined ? '' : PDFJS.imageResourcesPath;
  5974. PDFJS.disableWorker = PDFJS.disableWorker === undefined ? false : PDFJS.disableWorker;
  5975. PDFJS.workerSrc = PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc;
  5976. PDFJS.workerPort = PDFJS.workerPort === undefined ? null : PDFJS.workerPort;
  5977. PDFJS.disableRange = PDFJS.disableRange === undefined ? false : PDFJS.disableRange;
  5978. PDFJS.disableStream = PDFJS.disableStream === undefined ? false : PDFJS.disableStream;
  5979. PDFJS.disableAutoFetch = PDFJS.disableAutoFetch === undefined ? false : PDFJS.disableAutoFetch;
  5980. PDFJS.pdfBug = PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug;
  5981. PDFJS.postMessageTransfers = PDFJS.postMessageTransfers === undefined ? true : PDFJS.postMessageTransfers;
  5982. PDFJS.disableCreateObjectURL = PDFJS.disableCreateObjectURL === undefined ? false : PDFJS.disableCreateObjectURL;
  5983. PDFJS.disableWebGL = PDFJS.disableWebGL === undefined ? true : PDFJS.disableWebGL;
  5984. PDFJS.externalLinkTarget = PDFJS.externalLinkTarget === undefined ? _dom_utils.LinkTarget.NONE : PDFJS.externalLinkTarget;
  5985. PDFJS.externalLinkRel = PDFJS.externalLinkRel === undefined ? _dom_utils.DEFAULT_LINK_REL : PDFJS.externalLinkRel;
  5986. PDFJS.isEvalSupported = PDFJS.isEvalSupported === undefined ? true : PDFJS.isEvalSupported;
  5987. PDFJS.pdfjsNext = PDFJS.pdfjsNext === undefined ? false : PDFJS.pdfjsNext;
  5988. {
  5989. var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow;
  5990. delete PDFJS.openExternalLinksInNewWindow;
  5991. Object.defineProperty(PDFJS, 'openExternalLinksInNewWindow', {
  5992. get: function get() {
  5993. return PDFJS.externalLinkTarget === _dom_utils.LinkTarget.BLANK;
  5994. },
  5995. set: function set(value) {
  5996. if (value) {
  5997. (0, _util.deprecated)('PDFJS.openExternalLinksInNewWindow, please use ' + '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  5998. }
  5999. if (PDFJS.externalLinkTarget !== _dom_utils.LinkTarget.NONE) {
  6000. (0, _util.warn)('PDFJS.externalLinkTarget is already initialized');
  6001. return;
  6002. }
  6003. PDFJS.externalLinkTarget = value ? _dom_utils.LinkTarget.BLANK : _dom_utils.LinkTarget.NONE;
  6004. },
  6005. enumerable: true,
  6006. configurable: true
  6007. });
  6008. if (savedOpenExternalLinksInNewWindow) {
  6009. PDFJS.openExternalLinksInNewWindow = savedOpenExternalLinksInNewWindow;
  6010. }
  6011. }
  6012. PDFJS.getDocument = _api.getDocument;
  6013. PDFJS.LoopbackPort = _api.LoopbackPort;
  6014. PDFJS.PDFDataRangeTransport = _api.PDFDataRangeTransport;
  6015. PDFJS.PDFWorker = _api.PDFWorker;
  6016. PDFJS.hasCanvasTypedArrays = true;
  6017. PDFJS.CustomStyle = _dom_utils.CustomStyle;
  6018. PDFJS.LinkTarget = _dom_utils.LinkTarget;
  6019. PDFJS.addLinkAttributes = _dom_utils.addLinkAttributes;
  6020. PDFJS.getFilenameFromUrl = _dom_utils.getFilenameFromUrl;
  6021. PDFJS.isExternalLinkTargetSet = _dom_utils.isExternalLinkTargetSet;
  6022. PDFJS.AnnotationLayer = _annotation_layer.AnnotationLayer;
  6023. PDFJS.renderTextLayer = _text_layer.renderTextLayer;
  6024. PDFJS.Metadata = _metadata.Metadata;
  6025. PDFJS.SVGGraphics = _svg.SVGGraphics;
  6026. PDFJS.UnsupportedManager = _api._UnsupportedManager;
  6027. exports.globalScope = _util.globalScope;
  6028. exports.isWorker = isWorker;
  6029. exports.PDFJS = PDFJS;
  6030. /***/ }),
  6031. /* 9 */
  6032. /***/ (function(module, exports, __w_pdfjs_require__) {
  6033. "use strict";
  6034. Object.defineProperty(exports, "__esModule", {
  6035. value: true
  6036. });
  6037. exports.NetworkManager = exports.PDFNetworkStream = undefined;
  6038. var _util = __w_pdfjs_require__(0);
  6039. var _api = __w_pdfjs_require__(2);
  6040. ;
  6041. var OK_RESPONSE = 200;
  6042. var PARTIAL_CONTENT_RESPONSE = 206;
  6043. function NetworkManager(url, args) {
  6044. this.url = url;
  6045. args = args || {};
  6046. this.isHttp = /^https?:/i.test(url);
  6047. this.httpHeaders = this.isHttp && args.httpHeaders || {};
  6048. this.withCredentials = args.withCredentials || false;
  6049. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  6050. return new XMLHttpRequest();
  6051. };
  6052. this.currXhrId = 0;
  6053. this.pendingRequests = Object.create(null);
  6054. this.loadedRequests = Object.create(null);
  6055. }
  6056. function getArrayBuffer(xhr) {
  6057. var data = xhr.response;
  6058. if (typeof data !== 'string') {
  6059. return data;
  6060. }
  6061. var length = data.length;
  6062. var array = new Uint8Array(length);
  6063. for (var i = 0; i < length; i++) {
  6064. array[i] = data.charCodeAt(i) & 0xFF;
  6065. }
  6066. return array.buffer;
  6067. }
  6068. var supportsMozChunked = function supportsMozChunkedClosure() {
  6069. try {
  6070. var x = new XMLHttpRequest();
  6071. x.open('GET', _util.globalScope.location.href);
  6072. x.responseType = 'moz-chunked-arraybuffer';
  6073. return x.responseType === 'moz-chunked-arraybuffer';
  6074. } catch (e) {
  6075. return false;
  6076. }
  6077. }();
  6078. NetworkManager.prototype = {
  6079. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  6080. var args = {
  6081. begin: begin,
  6082. end: end
  6083. };
  6084. for (var prop in listeners) {
  6085. args[prop] = listeners[prop];
  6086. }
  6087. return this.request(args);
  6088. },
  6089. requestFull: function NetworkManager_requestFull(listeners) {
  6090. return this.request(listeners);
  6091. },
  6092. request: function NetworkManager_request(args) {
  6093. var xhr = this.getXhr();
  6094. var xhrId = this.currXhrId++;
  6095. var pendingRequest = this.pendingRequests[xhrId] = { xhr: xhr };
  6096. xhr.open('GET', this.url);
  6097. xhr.withCredentials = this.withCredentials;
  6098. for (var property in this.httpHeaders) {
  6099. var value = this.httpHeaders[property];
  6100. if (typeof value === 'undefined') {
  6101. continue;
  6102. }
  6103. xhr.setRequestHeader(property, value);
  6104. }
  6105. if (this.isHttp && 'begin' in args && 'end' in args) {
  6106. var rangeStr = args.begin + '-' + (args.end - 1);
  6107. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  6108. pendingRequest.expectedStatus = 206;
  6109. } else {
  6110. pendingRequest.expectedStatus = 200;
  6111. }
  6112. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  6113. if (useMozChunkedLoading) {
  6114. xhr.responseType = 'moz-chunked-arraybuffer';
  6115. pendingRequest.onProgressiveData = args.onProgressiveData;
  6116. pendingRequest.mozChunked = true;
  6117. } else {
  6118. xhr.responseType = 'arraybuffer';
  6119. }
  6120. if (args.onError) {
  6121. xhr.onerror = function (evt) {
  6122. args.onError(xhr.status);
  6123. };
  6124. }
  6125. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  6126. xhr.onprogress = this.onProgress.bind(this, xhrId);
  6127. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  6128. pendingRequest.onDone = args.onDone;
  6129. pendingRequest.onError = args.onError;
  6130. pendingRequest.onProgress = args.onProgress;
  6131. xhr.send(null);
  6132. return xhrId;
  6133. },
  6134. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  6135. var pendingRequest = this.pendingRequests[xhrId];
  6136. if (!pendingRequest) {
  6137. return;
  6138. }
  6139. if (pendingRequest.mozChunked) {
  6140. var chunk = getArrayBuffer(pendingRequest.xhr);
  6141. pendingRequest.onProgressiveData(chunk);
  6142. }
  6143. var onProgress = pendingRequest.onProgress;
  6144. if (onProgress) {
  6145. onProgress(evt);
  6146. }
  6147. },
  6148. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  6149. var pendingRequest = this.pendingRequests[xhrId];
  6150. if (!pendingRequest) {
  6151. return;
  6152. }
  6153. var xhr = pendingRequest.xhr;
  6154. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  6155. pendingRequest.onHeadersReceived();
  6156. delete pendingRequest.onHeadersReceived;
  6157. }
  6158. if (xhr.readyState !== 4) {
  6159. return;
  6160. }
  6161. if (!(xhrId in this.pendingRequests)) {
  6162. return;
  6163. }
  6164. delete this.pendingRequests[xhrId];
  6165. if (xhr.status === 0 && this.isHttp) {
  6166. if (pendingRequest.onError) {
  6167. pendingRequest.onError(xhr.status);
  6168. }
  6169. return;
  6170. }
  6171. var xhrStatus = xhr.status || OK_RESPONSE;
  6172. var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  6173. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  6174. if (pendingRequest.onError) {
  6175. pendingRequest.onError(xhr.status);
  6176. }
  6177. return;
  6178. }
  6179. this.loadedRequests[xhrId] = true;
  6180. var chunk = getArrayBuffer(xhr);
  6181. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  6182. var rangeHeader = xhr.getResponseHeader('Content-Range');
  6183. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  6184. var begin = parseInt(matches[1], 10);
  6185. pendingRequest.onDone({
  6186. begin: begin,
  6187. chunk: chunk
  6188. });
  6189. } else if (pendingRequest.onProgressiveData) {
  6190. pendingRequest.onDone(null);
  6191. } else if (chunk) {
  6192. pendingRequest.onDone({
  6193. begin: 0,
  6194. chunk: chunk
  6195. });
  6196. } else if (pendingRequest.onError) {
  6197. pendingRequest.onError(xhr.status);
  6198. }
  6199. },
  6200. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  6201. for (var xhrId in this.pendingRequests) {
  6202. return true;
  6203. }
  6204. return false;
  6205. },
  6206. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  6207. return this.pendingRequests[xhrId].xhr;
  6208. },
  6209. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  6210. return !!this.pendingRequests[xhrId].onProgressiveData;
  6211. },
  6212. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  6213. return xhrId in this.pendingRequests;
  6214. },
  6215. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  6216. return xhrId in this.loadedRequests;
  6217. },
  6218. abortAllRequests: function NetworkManager_abortAllRequests() {
  6219. for (var xhrId in this.pendingRequests) {
  6220. this.abortRequest(xhrId | 0);
  6221. }
  6222. },
  6223. abortRequest: function NetworkManager_abortRequest(xhrId) {
  6224. var xhr = this.pendingRequests[xhrId].xhr;
  6225. delete this.pendingRequests[xhrId];
  6226. xhr.abort();
  6227. }
  6228. };
  6229. function PDFNetworkStream(options) {
  6230. this._options = options;
  6231. var source = options.source;
  6232. this._manager = new NetworkManager(source.url, {
  6233. httpHeaders: source.httpHeaders,
  6234. withCredentials: source.withCredentials
  6235. });
  6236. this._rangeChunkSize = source.rangeChunkSize;
  6237. this._fullRequestReader = null;
  6238. this._rangeRequestReaders = [];
  6239. }
  6240. PDFNetworkStream.prototype = {
  6241. _onRangeRequestReaderClosed: function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  6242. var i = this._rangeRequestReaders.indexOf(reader);
  6243. if (i >= 0) {
  6244. this._rangeRequestReaders.splice(i, 1);
  6245. }
  6246. },
  6247. getFullReader: function PDFNetworkStream_getFullReader() {
  6248. (0, _util.assert)(!this._fullRequestReader);
  6249. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  6250. return this._fullRequestReader;
  6251. },
  6252. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  6253. var reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  6254. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  6255. this._rangeRequestReaders.push(reader);
  6256. return reader;
  6257. },
  6258. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  6259. if (this._fullRequestReader) {
  6260. this._fullRequestReader.cancel(reason);
  6261. }
  6262. var readers = this._rangeRequestReaders.slice(0);
  6263. readers.forEach(function (reader) {
  6264. reader.cancel(reason);
  6265. });
  6266. }
  6267. };
  6268. function PDFNetworkStreamFullRequestReader(manager, options) {
  6269. this._manager = manager;
  6270. var source = options.source;
  6271. var args = {
  6272. onHeadersReceived: this._onHeadersReceived.bind(this),
  6273. onProgressiveData: source.disableStream ? null : this._onProgressiveData.bind(this),
  6274. onDone: this._onDone.bind(this),
  6275. onError: this._onError.bind(this),
  6276. onProgress: this._onProgress.bind(this)
  6277. };
  6278. this._url = source.url;
  6279. this._fullRequestId = manager.requestFull(args);
  6280. this._headersReceivedCapability = (0, _util.createPromiseCapability)();
  6281. this._disableRange = options.disableRange || false;
  6282. this._contentLength = source.length;
  6283. this._rangeChunkSize = source.rangeChunkSize;
  6284. if (!this._rangeChunkSize && !this._disableRange) {
  6285. this._disableRange = true;
  6286. }
  6287. this._isStreamingSupported = false;
  6288. this._isRangeSupported = false;
  6289. this._cachedChunks = [];
  6290. this._requests = [];
  6291. this._done = false;
  6292. this._storedError = undefined;
  6293. this.onProgress = null;
  6294. }
  6295. PDFNetworkStreamFullRequestReader.prototype = {
  6296. _validateRangeRequestCapabilities: function PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  6297. if (this._disableRange) {
  6298. return false;
  6299. }
  6300. var networkManager = this._manager;
  6301. if (!networkManager.isHttp) {
  6302. return false;
  6303. }
  6304. var fullRequestXhrId = this._fullRequestId;
  6305. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  6306. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  6307. return false;
  6308. }
  6309. var contentEncoding = fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  6310. if (contentEncoding !== 'identity') {
  6311. return false;
  6312. }
  6313. var length = fullRequestXhr.getResponseHeader('Content-Length');
  6314. length = parseInt(length, 10);
  6315. if (!(0, _util.isInt)(length)) {
  6316. return false;
  6317. }
  6318. this._contentLength = length;
  6319. if (length <= 2 * this._rangeChunkSize) {
  6320. return false;
  6321. }
  6322. return true;
  6323. },
  6324. _onHeadersReceived: function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  6325. if (this._validateRangeRequestCapabilities()) {
  6326. this._isRangeSupported = true;
  6327. }
  6328. var networkManager = this._manager;
  6329. var fullRequestXhrId = this._fullRequestId;
  6330. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  6331. this._isStreamingSupported = true;
  6332. } else if (this._isRangeSupported) {
  6333. networkManager.abortRequest(fullRequestXhrId);
  6334. }
  6335. this._headersReceivedCapability.resolve();
  6336. },
  6337. _onProgressiveData: function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  6338. if (this._requests.length > 0) {
  6339. var requestCapability = this._requests.shift();
  6340. requestCapability.resolve({
  6341. value: chunk,
  6342. done: false
  6343. });
  6344. } else {
  6345. this._cachedChunks.push(chunk);
  6346. }
  6347. },
  6348. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  6349. if (args) {
  6350. this._onProgressiveData(args.chunk);
  6351. }
  6352. this._done = true;
  6353. if (this._cachedChunks.length > 0) {
  6354. return;
  6355. }
  6356. this._requests.forEach(function (requestCapability) {
  6357. requestCapability.resolve({
  6358. value: undefined,
  6359. done: true
  6360. });
  6361. });
  6362. this._requests = [];
  6363. },
  6364. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  6365. var url = this._url;
  6366. var exception;
  6367. if (status === 404 || status === 0 && /^file:/.test(url)) {
  6368. exception = new _util.MissingPDFException('Missing PDF "' + url + '".');
  6369. } else {
  6370. exception = new _util.UnexpectedResponseException('Unexpected server response (' + status + ') while retrieving PDF "' + url + '".', status);
  6371. }
  6372. this._storedError = exception;
  6373. this._headersReceivedCapability.reject(exception);
  6374. this._requests.forEach(function (requestCapability) {
  6375. requestCapability.reject(exception);
  6376. });
  6377. this._requests = [];
  6378. this._cachedChunks = [];
  6379. },
  6380. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  6381. if (this.onProgress) {
  6382. this.onProgress({
  6383. loaded: data.loaded,
  6384. total: data.lengthComputable ? data.total : this._contentLength
  6385. });
  6386. }
  6387. },
  6388. get isRangeSupported() {
  6389. return this._isRangeSupported;
  6390. },
  6391. get isStreamingSupported() {
  6392. return this._isStreamingSupported;
  6393. },
  6394. get contentLength() {
  6395. return this._contentLength;
  6396. },
  6397. get headersReady() {
  6398. return this._headersReceivedCapability.promise;
  6399. },
  6400. read: function PDFNetworkStreamFullRequestReader_read() {
  6401. if (this._storedError) {
  6402. return Promise.reject(this._storedError);
  6403. }
  6404. if (this._cachedChunks.length > 0) {
  6405. var chunk = this._cachedChunks.shift();
  6406. return Promise.resolve({
  6407. value: chunk,
  6408. done: false
  6409. });
  6410. }
  6411. if (this._done) {
  6412. return Promise.resolve({
  6413. value: undefined,
  6414. done: true
  6415. });
  6416. }
  6417. var requestCapability = (0, _util.createPromiseCapability)();
  6418. this._requests.push(requestCapability);
  6419. return requestCapability.promise;
  6420. },
  6421. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  6422. this._done = true;
  6423. this._headersReceivedCapability.reject(reason);
  6424. this._requests.forEach(function (requestCapability) {
  6425. requestCapability.resolve({
  6426. value: undefined,
  6427. done: true
  6428. });
  6429. });
  6430. this._requests = [];
  6431. if (this._manager.isPendingRequest(this._fullRequestId)) {
  6432. this._manager.abortRequest(this._fullRequestId);
  6433. }
  6434. this._fullRequestReader = null;
  6435. }
  6436. };
  6437. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  6438. this._manager = manager;
  6439. var args = {
  6440. onDone: this._onDone.bind(this),
  6441. onProgress: this._onProgress.bind(this)
  6442. };
  6443. this._requestId = manager.requestRange(begin, end, args);
  6444. this._requests = [];
  6445. this._queuedChunk = null;
  6446. this._done = false;
  6447. this.onProgress = null;
  6448. this.onClosed = null;
  6449. }
  6450. PDFNetworkStreamRangeRequestReader.prototype = {
  6451. _close: function PDFNetworkStreamRangeRequestReader_close() {
  6452. if (this.onClosed) {
  6453. this.onClosed(this);
  6454. }
  6455. },
  6456. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  6457. var chunk = data.chunk;
  6458. if (this._requests.length > 0) {
  6459. var requestCapability = this._requests.shift();
  6460. requestCapability.resolve({
  6461. value: chunk,
  6462. done: false
  6463. });
  6464. } else {
  6465. this._queuedChunk = chunk;
  6466. }
  6467. this._done = true;
  6468. this._requests.forEach(function (requestCapability) {
  6469. requestCapability.resolve({
  6470. value: undefined,
  6471. done: true
  6472. });
  6473. });
  6474. this._requests = [];
  6475. this._close();
  6476. },
  6477. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  6478. if (!this.isStreamingSupported && this.onProgress) {
  6479. this.onProgress({ loaded: evt.loaded });
  6480. }
  6481. },
  6482. get isStreamingSupported() {
  6483. return false;
  6484. },
  6485. read: function PDFNetworkStreamRangeRequestReader_read() {
  6486. if (this._queuedChunk !== null) {
  6487. var chunk = this._queuedChunk;
  6488. this._queuedChunk = null;
  6489. return Promise.resolve({
  6490. value: chunk,
  6491. done: false
  6492. });
  6493. }
  6494. if (this._done) {
  6495. return Promise.resolve({
  6496. value: undefined,
  6497. done: true
  6498. });
  6499. }
  6500. var requestCapability = (0, _util.createPromiseCapability)();
  6501. this._requests.push(requestCapability);
  6502. return requestCapability.promise;
  6503. },
  6504. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  6505. this._done = true;
  6506. this._requests.forEach(function (requestCapability) {
  6507. requestCapability.resolve({
  6508. value: undefined,
  6509. done: true
  6510. });
  6511. });
  6512. this._requests = [];
  6513. if (this._manager.isPendingRequest(this._requestId)) {
  6514. this._manager.abortRequest(this._requestId);
  6515. }
  6516. this._close();
  6517. }
  6518. };
  6519. (0, _api.setPDFNetworkStreamClass)(PDFNetworkStream);
  6520. exports.PDFNetworkStream = PDFNetworkStream;
  6521. exports.NetworkManager = NetworkManager;
  6522. /***/ }),
  6523. /* 10 */
  6524. /***/ (function(module, exports, __w_pdfjs_require__) {
  6525. "use strict";
  6526. var _typeof2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  6527. (function (e, a) {
  6528. for (var i in a) {
  6529. e[i] = a[i];
  6530. }
  6531. })(exports, function (modules) {
  6532. var installedModules = {};
  6533. function __w_pdfjs_require__(moduleId) {
  6534. if (installedModules[moduleId]) return installedModules[moduleId].exports;
  6535. var module = installedModules[moduleId] = {
  6536. i: moduleId,
  6537. l: false,
  6538. exports: {}
  6539. };
  6540. modules[moduleId].call(module.exports, module, module.exports, __w_pdfjs_require__);
  6541. module.l = true;
  6542. return module.exports;
  6543. }
  6544. __w_pdfjs_require__.m = modules;
  6545. __w_pdfjs_require__.c = installedModules;
  6546. __w_pdfjs_require__.i = function (value) {
  6547. return value;
  6548. };
  6549. __w_pdfjs_require__.d = function (exports, name, getter) {
  6550. if (!__w_pdfjs_require__.o(exports, name)) {
  6551. Object.defineProperty(exports, name, {
  6552. configurable: false,
  6553. enumerable: true,
  6554. get: getter
  6555. });
  6556. }
  6557. };
  6558. __w_pdfjs_require__.n = function (module) {
  6559. var getter = module && module.__esModule ? function getDefault() {
  6560. return module['default'];
  6561. } : function getModuleExports() {
  6562. return module;
  6563. };
  6564. __w_pdfjs_require__.d(getter, 'a', getter);
  6565. return getter;
  6566. };
  6567. __w_pdfjs_require__.o = function (object, property) {
  6568. return Object.prototype.hasOwnProperty.call(object, property);
  6569. };
  6570. __w_pdfjs_require__.p = "";
  6571. return __w_pdfjs_require__(__w_pdfjs_require__.s = 7);
  6572. }([function (module, exports, __w_pdfjs_require__) {
  6573. "use strict";
  6574. var _typeof = typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol" ? function (obj) {
  6575. return typeof obj === 'undefined' ? 'undefined' : _typeof2(obj);
  6576. } : function (obj) {
  6577. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === 'undefined' ? 'undefined' : _typeof2(obj);
  6578. };
  6579. var _require = __w_pdfjs_require__(1),
  6580. assert = _require.assert;
  6581. function IsPropertyKey(argument) {
  6582. return typeof argument === 'string' || (typeof argument === 'undefined' ? 'undefined' : _typeof(argument)) === 'symbol';
  6583. }
  6584. exports.typeIsObject = function (x) {
  6585. return (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && x !== null || typeof x === 'function';
  6586. };
  6587. exports.createDataProperty = function (o, p, v) {
  6588. assert(exports.typeIsObject(o));
  6589. Object.defineProperty(o, p, {
  6590. value: v,
  6591. writable: true,
  6592. enumerable: true,
  6593. configurable: true
  6594. });
  6595. };
  6596. exports.createArrayFromList = function (elements) {
  6597. return elements.slice();
  6598. };
  6599. exports.ArrayBufferCopy = function (dest, destOffset, src, srcOffset, n) {
  6600. new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
  6601. };
  6602. exports.CreateIterResultObject = function (value, done) {
  6603. assert(typeof done === 'boolean');
  6604. var obj = {};
  6605. Object.defineProperty(obj, 'value', {
  6606. value: value,
  6607. enumerable: true,
  6608. writable: true,
  6609. configurable: true
  6610. });
  6611. Object.defineProperty(obj, 'done', {
  6612. value: done,
  6613. enumerable: true,
  6614. writable: true,
  6615. configurable: true
  6616. });
  6617. return obj;
  6618. };
  6619. exports.IsFiniteNonNegativeNumber = function (v) {
  6620. if (Number.isNaN(v)) {
  6621. return false;
  6622. }
  6623. if (v === Infinity) {
  6624. return false;
  6625. }
  6626. if (v < 0) {
  6627. return false;
  6628. }
  6629. return true;
  6630. };
  6631. function Call(F, V, args) {
  6632. if (typeof F !== 'function') {
  6633. throw new TypeError('Argument is not a function');
  6634. }
  6635. return Function.prototype.apply.call(F, V, args);
  6636. }
  6637. exports.InvokeOrNoop = function (O, P, args) {
  6638. assert(O !== undefined);
  6639. assert(IsPropertyKey(P));
  6640. assert(Array.isArray(args));
  6641. var method = O[P];
  6642. if (method === undefined) {
  6643. return undefined;
  6644. }
  6645. return Call(method, O, args);
  6646. };
  6647. exports.PromiseInvokeOrNoop = function (O, P, args) {
  6648. assert(O !== undefined);
  6649. assert(IsPropertyKey(P));
  6650. assert(Array.isArray(args));
  6651. try {
  6652. return Promise.resolve(exports.InvokeOrNoop(O, P, args));
  6653. } catch (returnValueE) {
  6654. return Promise.reject(returnValueE);
  6655. }
  6656. };
  6657. exports.PromiseInvokeOrPerformFallback = function (O, P, args, F, argsF) {
  6658. assert(O !== undefined);
  6659. assert(IsPropertyKey(P));
  6660. assert(Array.isArray(args));
  6661. assert(Array.isArray(argsF));
  6662. var method = void 0;
  6663. try {
  6664. method = O[P];
  6665. } catch (methodE) {
  6666. return Promise.reject(methodE);
  6667. }
  6668. if (method === undefined) {
  6669. return F.apply(null, argsF);
  6670. }
  6671. try {
  6672. return Promise.resolve(Call(method, O, args));
  6673. } catch (e) {
  6674. return Promise.reject(e);
  6675. }
  6676. };
  6677. exports.TransferArrayBuffer = function (O) {
  6678. return O.slice();
  6679. };
  6680. exports.ValidateAndNormalizeHighWaterMark = function (highWaterMark) {
  6681. highWaterMark = Number(highWaterMark);
  6682. if (Number.isNaN(highWaterMark) || highWaterMark < 0) {
  6683. throw new RangeError('highWaterMark property of a queuing strategy must be non-negative and non-NaN');
  6684. }
  6685. return highWaterMark;
  6686. };
  6687. exports.ValidateAndNormalizeQueuingStrategy = function (size, highWaterMark) {
  6688. if (size !== undefined && typeof size !== 'function') {
  6689. throw new TypeError('size property of a queuing strategy must be a function');
  6690. }
  6691. highWaterMark = exports.ValidateAndNormalizeHighWaterMark(highWaterMark);
  6692. return {
  6693. size: size,
  6694. highWaterMark: highWaterMark
  6695. };
  6696. };
  6697. }, function (module, exports, __w_pdfjs_require__) {
  6698. "use strict";
  6699. function rethrowAssertionErrorRejection(e) {
  6700. if (e && e.constructor === AssertionError) {
  6701. setTimeout(function () {
  6702. throw e;
  6703. }, 0);
  6704. }
  6705. }
  6706. function AssertionError(message) {
  6707. this.name = 'AssertionError';
  6708. this.message = message || '';
  6709. this.stack = new Error().stack;
  6710. }
  6711. AssertionError.prototype = Object.create(Error.prototype);
  6712. AssertionError.prototype.constructor = AssertionError;
  6713. function assert(value, message) {
  6714. if (!value) {
  6715. throw new AssertionError(message);
  6716. }
  6717. }
  6718. module.exports = {
  6719. rethrowAssertionErrorRejection: rethrowAssertionErrorRejection,
  6720. AssertionError: AssertionError,
  6721. assert: assert
  6722. };
  6723. }, function (module, exports, __w_pdfjs_require__) {
  6724. "use strict";
  6725. var _createClass = function () {
  6726. function defineProperties(target, props) {
  6727. for (var i = 0; i < props.length; i++) {
  6728. var descriptor = props[i];
  6729. descriptor.enumerable = descriptor.enumerable || false;
  6730. descriptor.configurable = true;
  6731. if ("value" in descriptor) descriptor.writable = true;
  6732. Object.defineProperty(target, descriptor.key, descriptor);
  6733. }
  6734. }
  6735. return function (Constructor, protoProps, staticProps) {
  6736. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  6737. if (staticProps) defineProperties(Constructor, staticProps);
  6738. return Constructor;
  6739. };
  6740. }();
  6741. function _classCallCheck(instance, Constructor) {
  6742. if (!(instance instanceof Constructor)) {
  6743. throw new TypeError("Cannot call a class as a function");
  6744. }
  6745. }
  6746. var _require = __w_pdfjs_require__(0),
  6747. InvokeOrNoop = _require.InvokeOrNoop,
  6748. PromiseInvokeOrNoop = _require.PromiseInvokeOrNoop,
  6749. ValidateAndNormalizeQueuingStrategy = _require.ValidateAndNormalizeQueuingStrategy,
  6750. typeIsObject = _require.typeIsObject;
  6751. var _require2 = __w_pdfjs_require__(1),
  6752. assert = _require2.assert,
  6753. rethrowAssertionErrorRejection = _require2.rethrowAssertionErrorRejection;
  6754. var _require3 = __w_pdfjs_require__(3),
  6755. DequeueValue = _require3.DequeueValue,
  6756. EnqueueValueWithSize = _require3.EnqueueValueWithSize,
  6757. PeekQueueValue = _require3.PeekQueueValue,
  6758. ResetQueue = _require3.ResetQueue;
  6759. var WritableStream = function () {
  6760. function WritableStream() {
  6761. var underlyingSink = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  6762. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  6763. size = _ref.size,
  6764. _ref$highWaterMark = _ref.highWaterMark,
  6765. highWaterMark = _ref$highWaterMark === undefined ? 1 : _ref$highWaterMark;
  6766. _classCallCheck(this, WritableStream);
  6767. this._state = 'writable';
  6768. this._storedError = undefined;
  6769. this._writer = undefined;
  6770. this._writableStreamController = undefined;
  6771. this._writeRequests = [];
  6772. this._inFlightWriteRequest = undefined;
  6773. this._closeRequest = undefined;
  6774. this._inFlightCloseRequest = undefined;
  6775. this._pendingAbortRequest = undefined;
  6776. this._backpressure = false;
  6777. var type = underlyingSink.type;
  6778. if (type !== undefined) {
  6779. throw new RangeError('Invalid type is specified');
  6780. }
  6781. this._writableStreamController = new WritableStreamDefaultController(this, underlyingSink, size, highWaterMark);
  6782. this._writableStreamController.__startSteps();
  6783. }
  6784. _createClass(WritableStream, [{
  6785. key: 'abort',
  6786. value: function abort(reason) {
  6787. if (IsWritableStream(this) === false) {
  6788. return Promise.reject(streamBrandCheckException('abort'));
  6789. }
  6790. if (IsWritableStreamLocked(this) === true) {
  6791. return Promise.reject(new TypeError('Cannot abort a stream that already has a writer'));
  6792. }
  6793. return WritableStreamAbort(this, reason);
  6794. }
  6795. }, {
  6796. key: 'getWriter',
  6797. value: function getWriter() {
  6798. if (IsWritableStream(this) === false) {
  6799. throw streamBrandCheckException('getWriter');
  6800. }
  6801. return AcquireWritableStreamDefaultWriter(this);
  6802. }
  6803. }, {
  6804. key: 'locked',
  6805. get: function get() {
  6806. if (IsWritableStream(this) === false) {
  6807. throw streamBrandCheckException('locked');
  6808. }
  6809. return IsWritableStreamLocked(this);
  6810. }
  6811. }]);
  6812. return WritableStream;
  6813. }();
  6814. module.exports = {
  6815. AcquireWritableStreamDefaultWriter: AcquireWritableStreamDefaultWriter,
  6816. IsWritableStream: IsWritableStream,
  6817. IsWritableStreamLocked: IsWritableStreamLocked,
  6818. WritableStream: WritableStream,
  6819. WritableStreamAbort: WritableStreamAbort,
  6820. WritableStreamDefaultControllerError: WritableStreamDefaultControllerError,
  6821. WritableStreamDefaultWriterCloseWithErrorPropagation: WritableStreamDefaultWriterCloseWithErrorPropagation,
  6822. WritableStreamDefaultWriterRelease: WritableStreamDefaultWriterRelease,
  6823. WritableStreamDefaultWriterWrite: WritableStreamDefaultWriterWrite,
  6824. WritableStreamCloseQueuedOrInFlight: WritableStreamCloseQueuedOrInFlight
  6825. };
  6826. function AcquireWritableStreamDefaultWriter(stream) {
  6827. return new WritableStreamDefaultWriter(stream);
  6828. }
  6829. function IsWritableStream(x) {
  6830. if (!typeIsObject(x)) {
  6831. return false;
  6832. }
  6833. if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) {
  6834. return false;
  6835. }
  6836. return true;
  6837. }
  6838. function IsWritableStreamLocked(stream) {
  6839. assert(IsWritableStream(stream) === true, 'IsWritableStreamLocked should only be used on known writable streams');
  6840. if (stream._writer === undefined) {
  6841. return false;
  6842. }
  6843. return true;
  6844. }
  6845. function WritableStreamAbort(stream, reason) {
  6846. var state = stream._state;
  6847. if (state === 'closed') {
  6848. return Promise.resolve(undefined);
  6849. }
  6850. if (state === 'errored') {
  6851. return Promise.reject(stream._storedError);
  6852. }
  6853. var error = new TypeError('Requested to abort');
  6854. if (stream._pendingAbortRequest !== undefined) {
  6855. return Promise.reject(error);
  6856. }
  6857. assert(state === 'writable' || state === 'erroring', 'state must be writable or erroring');
  6858. var wasAlreadyErroring = false;
  6859. if (state === 'erroring') {
  6860. wasAlreadyErroring = true;
  6861. reason = undefined;
  6862. }
  6863. var promise = new Promise(function (resolve, reject) {
  6864. stream._pendingAbortRequest = {
  6865. _resolve: resolve,
  6866. _reject: reject,
  6867. _reason: reason,
  6868. _wasAlreadyErroring: wasAlreadyErroring
  6869. };
  6870. });
  6871. if (wasAlreadyErroring === false) {
  6872. WritableStreamStartErroring(stream, error);
  6873. }
  6874. return promise;
  6875. }
  6876. function WritableStreamAddWriteRequest(stream) {
  6877. assert(IsWritableStreamLocked(stream) === true);
  6878. assert(stream._state === 'writable');
  6879. var promise = new Promise(function (resolve, reject) {
  6880. var writeRequest = {
  6881. _resolve: resolve,
  6882. _reject: reject
  6883. };
  6884. stream._writeRequests.push(writeRequest);
  6885. });
  6886. return promise;
  6887. }
  6888. function WritableStreamDealWithRejection(stream, error) {
  6889. var state = stream._state;
  6890. if (state === 'writable') {
  6891. WritableStreamStartErroring(stream, error);
  6892. return;
  6893. }
  6894. assert(state === 'erroring');
  6895. WritableStreamFinishErroring(stream);
  6896. }
  6897. function WritableStreamStartErroring(stream, reason) {
  6898. assert(stream._storedError === undefined, 'stream._storedError === undefined');
  6899. assert(stream._state === 'writable', 'state must be writable');
  6900. var controller = stream._writableStreamController;
  6901. assert(controller !== undefined, 'controller must not be undefined');
  6902. stream._state = 'erroring';
  6903. stream._storedError = reason;
  6904. var writer = stream._writer;
  6905. if (writer !== undefined) {
  6906. WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason);
  6907. }
  6908. if (WritableStreamHasOperationMarkedInFlight(stream) === false && controller._started === true) {
  6909. WritableStreamFinishErroring(stream);
  6910. }
  6911. }
  6912. function WritableStreamFinishErroring(stream) {
  6913. assert(stream._state === 'erroring', 'stream._state === erroring');
  6914. assert(WritableStreamHasOperationMarkedInFlight(stream) === false, 'WritableStreamHasOperationMarkedInFlight(stream) === false');
  6915. stream._state = 'errored';
  6916. stream._writableStreamController.__errorSteps();
  6917. var storedError = stream._storedError;
  6918. for (var i = 0; i < stream._writeRequests.length; i++) {
  6919. var writeRequest = stream._writeRequests[i];
  6920. writeRequest._reject(storedError);
  6921. }
  6922. stream._writeRequests = [];
  6923. if (stream._pendingAbortRequest === undefined) {
  6924. WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
  6925. return;
  6926. }
  6927. var abortRequest = stream._pendingAbortRequest;
  6928. stream._pendingAbortRequest = undefined;
  6929. if (abortRequest._wasAlreadyErroring === true) {
  6930. abortRequest._reject(storedError);
  6931. WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
  6932. return;
  6933. }
  6934. var promise = stream._writableStreamController.__abortSteps(abortRequest._reason);
  6935. promise.then(function () {
  6936. abortRequest._resolve();
  6937. WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
  6938. }, function (reason) {
  6939. abortRequest._reject(reason);
  6940. WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
  6941. });
  6942. }
  6943. function WritableStreamFinishInFlightWrite(stream) {
  6944. assert(stream._inFlightWriteRequest !== undefined);
  6945. stream._inFlightWriteRequest._resolve(undefined);
  6946. stream._inFlightWriteRequest = undefined;
  6947. }
  6948. function WritableStreamFinishInFlightWriteWithError(stream, error) {
  6949. assert(stream._inFlightWriteRequest !== undefined);
  6950. stream._inFlightWriteRequest._reject(error);
  6951. stream._inFlightWriteRequest = undefined;
  6952. assert(stream._state === 'writable' || stream._state === 'erroring');
  6953. WritableStreamDealWithRejection(stream, error);
  6954. }
  6955. function WritableStreamFinishInFlightClose(stream) {
  6956. assert(stream._inFlightCloseRequest !== undefined);
  6957. stream._inFlightCloseRequest._resolve(undefined);
  6958. stream._inFlightCloseRequest = undefined;
  6959. var state = stream._state;
  6960. assert(state === 'writable' || state === 'erroring');
  6961. if (state === 'erroring') {
  6962. stream._storedError = undefined;
  6963. if (stream._pendingAbortRequest !== undefined) {
  6964. stream._pendingAbortRequest._resolve();
  6965. stream._pendingAbortRequest = undefined;
  6966. }
  6967. }
  6968. stream._state = 'closed';
  6969. var writer = stream._writer;
  6970. if (writer !== undefined) {
  6971. defaultWriterClosedPromiseResolve(writer);
  6972. }
  6973. assert(stream._pendingAbortRequest === undefined, 'stream._pendingAbortRequest === undefined');
  6974. assert(stream._storedError === undefined, 'stream._storedError === undefined');
  6975. }
  6976. function WritableStreamFinishInFlightCloseWithError(stream, error) {
  6977. assert(stream._inFlightCloseRequest !== undefined);
  6978. stream._inFlightCloseRequest._reject(error);
  6979. stream._inFlightCloseRequest = undefined;
  6980. assert(stream._state === 'writable' || stream._state === 'erroring');
  6981. if (stream._pendingAbortRequest !== undefined) {
  6982. stream._pendingAbortRequest._reject(error);
  6983. stream._pendingAbortRequest = undefined;
  6984. }
  6985. WritableStreamDealWithRejection(stream, error);
  6986. }
  6987. function WritableStreamCloseQueuedOrInFlight(stream) {
  6988. if (stream._closeRequest === undefined && stream._inFlightCloseRequest === undefined) {
  6989. return false;
  6990. }
  6991. return true;
  6992. }
  6993. function WritableStreamHasOperationMarkedInFlight(stream) {
  6994. if (stream._inFlightWriteRequest === undefined && stream._inFlightCloseRequest === undefined) {
  6995. return false;
  6996. }
  6997. return true;
  6998. }
  6999. function WritableStreamMarkCloseRequestInFlight(stream) {
  7000. assert(stream._inFlightCloseRequest === undefined);
  7001. assert(stream._closeRequest !== undefined);
  7002. stream._inFlightCloseRequest = stream._closeRequest;
  7003. stream._closeRequest = undefined;
  7004. }
  7005. function WritableStreamMarkFirstWriteRequestInFlight(stream) {
  7006. assert(stream._inFlightWriteRequest === undefined, 'there must be no pending write request');
  7007. assert(stream._writeRequests.length !== 0, 'writeRequests must not be empty');
  7008. stream._inFlightWriteRequest = stream._writeRequests.shift();
  7009. }
  7010. function WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream) {
  7011. assert(stream._state === 'errored', '_stream_.[[state]] is `"errored"`');
  7012. if (stream._closeRequest !== undefined) {
  7013. assert(stream._inFlightCloseRequest === undefined);
  7014. stream._closeRequest._reject(stream._storedError);
  7015. stream._closeRequest = undefined;
  7016. }
  7017. var writer = stream._writer;
  7018. if (writer !== undefined) {
  7019. defaultWriterClosedPromiseReject(writer, stream._storedError);
  7020. writer._closedPromise.catch(function () {});
  7021. }
  7022. }
  7023. function WritableStreamUpdateBackpressure(stream, backpressure) {
  7024. assert(stream._state === 'writable');
  7025. assert(WritableStreamCloseQueuedOrInFlight(stream) === false);
  7026. var writer = stream._writer;
  7027. if (writer !== undefined && backpressure !== stream._backpressure) {
  7028. if (backpressure === true) {
  7029. defaultWriterReadyPromiseReset(writer);
  7030. } else {
  7031. assert(backpressure === false);
  7032. defaultWriterReadyPromiseResolve(writer);
  7033. }
  7034. }
  7035. stream._backpressure = backpressure;
  7036. }
  7037. var WritableStreamDefaultWriter = function () {
  7038. function WritableStreamDefaultWriter(stream) {
  7039. _classCallCheck(this, WritableStreamDefaultWriter);
  7040. if (IsWritableStream(stream) === false) {
  7041. throw new TypeError('WritableStreamDefaultWriter can only be constructed with a WritableStream instance');
  7042. }
  7043. if (IsWritableStreamLocked(stream) === true) {
  7044. throw new TypeError('This stream has already been locked for exclusive writing by another writer');
  7045. }
  7046. this._ownerWritableStream = stream;
  7047. stream._writer = this;
  7048. var state = stream._state;
  7049. if (state === 'writable') {
  7050. if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._backpressure === true) {
  7051. defaultWriterReadyPromiseInitialize(this);
  7052. } else {
  7053. defaultWriterReadyPromiseInitializeAsResolved(this);
  7054. }
  7055. defaultWriterClosedPromiseInitialize(this);
  7056. } else if (state === 'erroring') {
  7057. defaultWriterReadyPromiseInitializeAsRejected(this, stream._storedError);
  7058. this._readyPromise.catch(function () {});
  7059. defaultWriterClosedPromiseInitialize(this);
  7060. } else if (state === 'closed') {
  7061. defaultWriterReadyPromiseInitializeAsResolved(this);
  7062. defaultWriterClosedPromiseInitializeAsResolved(this);
  7063. } else {
  7064. assert(state === 'errored', 'state must be errored');
  7065. var storedError = stream._storedError;
  7066. defaultWriterReadyPromiseInitializeAsRejected(this, storedError);
  7067. this._readyPromise.catch(function () {});
  7068. defaultWriterClosedPromiseInitializeAsRejected(this, storedError);
  7069. this._closedPromise.catch(function () {});
  7070. }
  7071. }
  7072. _createClass(WritableStreamDefaultWriter, [{
  7073. key: 'abort',
  7074. value: function abort(reason) {
  7075. if (IsWritableStreamDefaultWriter(this) === false) {
  7076. return Promise.reject(defaultWriterBrandCheckException('abort'));
  7077. }
  7078. if (this._ownerWritableStream === undefined) {
  7079. return Promise.reject(defaultWriterLockException('abort'));
  7080. }
  7081. return WritableStreamDefaultWriterAbort(this, reason);
  7082. }
  7083. }, {
  7084. key: 'close',
  7085. value: function close() {
  7086. if (IsWritableStreamDefaultWriter(this) === false) {
  7087. return Promise.reject(defaultWriterBrandCheckException('close'));
  7088. }
  7089. var stream = this._ownerWritableStream;
  7090. if (stream === undefined) {
  7091. return Promise.reject(defaultWriterLockException('close'));
  7092. }
  7093. if (WritableStreamCloseQueuedOrInFlight(stream) === true) {
  7094. return Promise.reject(new TypeError('cannot close an already-closing stream'));
  7095. }
  7096. return WritableStreamDefaultWriterClose(this);
  7097. }
  7098. }, {
  7099. key: 'releaseLock',
  7100. value: function releaseLock() {
  7101. if (IsWritableStreamDefaultWriter(this) === false) {
  7102. throw defaultWriterBrandCheckException('releaseLock');
  7103. }
  7104. var stream = this._ownerWritableStream;
  7105. if (stream === undefined) {
  7106. return;
  7107. }
  7108. assert(stream._writer !== undefined);
  7109. WritableStreamDefaultWriterRelease(this);
  7110. }
  7111. }, {
  7112. key: 'write',
  7113. value: function write(chunk) {
  7114. if (IsWritableStreamDefaultWriter(this) === false) {
  7115. return Promise.reject(defaultWriterBrandCheckException('write'));
  7116. }
  7117. if (this._ownerWritableStream === undefined) {
  7118. return Promise.reject(defaultWriterLockException('write to'));
  7119. }
  7120. return WritableStreamDefaultWriterWrite(this, chunk);
  7121. }
  7122. }, {
  7123. key: 'closed',
  7124. get: function get() {
  7125. if (IsWritableStreamDefaultWriter(this) === false) {
  7126. return Promise.reject(defaultWriterBrandCheckException('closed'));
  7127. }
  7128. return this._closedPromise;
  7129. }
  7130. }, {
  7131. key: 'desiredSize',
  7132. get: function get() {
  7133. if (IsWritableStreamDefaultWriter(this) === false) {
  7134. throw defaultWriterBrandCheckException('desiredSize');
  7135. }
  7136. if (this._ownerWritableStream === undefined) {
  7137. throw defaultWriterLockException('desiredSize');
  7138. }
  7139. return WritableStreamDefaultWriterGetDesiredSize(this);
  7140. }
  7141. }, {
  7142. key: 'ready',
  7143. get: function get() {
  7144. if (IsWritableStreamDefaultWriter(this) === false) {
  7145. return Promise.reject(defaultWriterBrandCheckException('ready'));
  7146. }
  7147. return this._readyPromise;
  7148. }
  7149. }]);
  7150. return WritableStreamDefaultWriter;
  7151. }();
  7152. function IsWritableStreamDefaultWriter(x) {
  7153. if (!typeIsObject(x)) {
  7154. return false;
  7155. }
  7156. if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) {
  7157. return false;
  7158. }
  7159. return true;
  7160. }
  7161. function WritableStreamDefaultWriterAbort(writer, reason) {
  7162. var stream = writer._ownerWritableStream;
  7163. assert(stream !== undefined);
  7164. return WritableStreamAbort(stream, reason);
  7165. }
  7166. function WritableStreamDefaultWriterClose(writer) {
  7167. var stream = writer._ownerWritableStream;
  7168. assert(stream !== undefined);
  7169. var state = stream._state;
  7170. if (state === 'closed' || state === 'errored') {
  7171. return Promise.reject(new TypeError('The stream (in ' + state + ' state) is not in the writable state and cannot be closed'));
  7172. }
  7173. assert(state === 'writable' || state === 'erroring');
  7174. assert(WritableStreamCloseQueuedOrInFlight(stream) === false);
  7175. var promise = new Promise(function (resolve, reject) {
  7176. var closeRequest = {
  7177. _resolve: resolve,
  7178. _reject: reject
  7179. };
  7180. stream._closeRequest = closeRequest;
  7181. });
  7182. if (stream._backpressure === true && state === 'writable') {
  7183. defaultWriterReadyPromiseResolve(writer);
  7184. }
  7185. WritableStreamDefaultControllerClose(stream._writableStreamController);
  7186. return promise;
  7187. }
  7188. function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) {
  7189. var stream = writer._ownerWritableStream;
  7190. assert(stream !== undefined);
  7191. var state = stream._state;
  7192. if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') {
  7193. return Promise.resolve();
  7194. }
  7195. if (state === 'errored') {
  7196. return Promise.reject(stream._storedError);
  7197. }
  7198. assert(state === 'writable' || state === 'erroring');
  7199. return WritableStreamDefaultWriterClose(writer);
  7200. }
  7201. function WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) {
  7202. if (writer._closedPromiseState === 'pending') {
  7203. defaultWriterClosedPromiseReject(writer, error);
  7204. } else {
  7205. defaultWriterClosedPromiseResetToRejected(writer, error);
  7206. }
  7207. writer._closedPromise.catch(function () {});
  7208. }
  7209. function WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) {
  7210. if (writer._readyPromiseState === 'pending') {
  7211. defaultWriterReadyPromiseReject(writer, error);
  7212. } else {
  7213. defaultWriterReadyPromiseResetToRejected(writer, error);
  7214. }
  7215. writer._readyPromise.catch(function () {});
  7216. }
  7217. function WritableStreamDefaultWriterGetDesiredSize(writer) {
  7218. var stream = writer._ownerWritableStream;
  7219. var state = stream._state;
  7220. if (state === 'errored' || state === 'erroring') {
  7221. return null;
  7222. }
  7223. if (state === 'closed') {
  7224. return 0;
  7225. }
  7226. return WritableStreamDefaultControllerGetDesiredSize(stream._writableStreamController);
  7227. }
  7228. function WritableStreamDefaultWriterRelease(writer) {
  7229. var stream = writer._ownerWritableStream;
  7230. assert(stream !== undefined);
  7231. assert(stream._writer === writer);
  7232. var releasedError = new TypeError('Writer was released and can no longer be used to monitor the stream\'s closedness');
  7233. WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError);
  7234. WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError);
  7235. stream._writer = undefined;
  7236. writer._ownerWritableStream = undefined;
  7237. }
  7238. function WritableStreamDefaultWriterWrite(writer, chunk) {
  7239. var stream = writer._ownerWritableStream;
  7240. assert(stream !== undefined);
  7241. var controller = stream._writableStreamController;
  7242. var chunkSize = WritableStreamDefaultControllerGetChunkSize(controller, chunk);
  7243. if (stream !== writer._ownerWritableStream) {
  7244. return Promise.reject(defaultWriterLockException('write to'));
  7245. }
  7246. var state = stream._state;
  7247. if (state === 'errored') {
  7248. return Promise.reject(stream._storedError);
  7249. }
  7250. if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') {
  7251. return Promise.reject(new TypeError('The stream is closing or closed and cannot be written to'));
  7252. }
  7253. if (state === 'erroring') {
  7254. return Promise.reject(stream._storedError);
  7255. }
  7256. assert(state === 'writable');
  7257. var promise = WritableStreamAddWriteRequest(stream);
  7258. WritableStreamDefaultControllerWrite(controller, chunk, chunkSize);
  7259. return promise;
  7260. }
  7261. var WritableStreamDefaultController = function () {
  7262. function WritableStreamDefaultController(stream, underlyingSink, size, highWaterMark) {
  7263. _classCallCheck(this, WritableStreamDefaultController);
  7264. if (IsWritableStream(stream) === false) {
  7265. throw new TypeError('WritableStreamDefaultController can only be constructed with a WritableStream instance');
  7266. }
  7267. if (stream._writableStreamController !== undefined) {
  7268. throw new TypeError('WritableStreamDefaultController instances can only be created by the WritableStream constructor');
  7269. }
  7270. this._controlledWritableStream = stream;
  7271. this._underlyingSink = underlyingSink;
  7272. this._queue = undefined;
  7273. this._queueTotalSize = undefined;
  7274. ResetQueue(this);
  7275. this._started = false;
  7276. var normalizedStrategy = ValidateAndNormalizeQueuingStrategy(size, highWaterMark);
  7277. this._strategySize = normalizedStrategy.size;
  7278. this._strategyHWM = normalizedStrategy.highWaterMark;
  7279. var backpressure = WritableStreamDefaultControllerGetBackpressure(this);
  7280. WritableStreamUpdateBackpressure(stream, backpressure);
  7281. }
  7282. _createClass(WritableStreamDefaultController, [{
  7283. key: 'error',
  7284. value: function error(e) {
  7285. if (IsWritableStreamDefaultController(this) === false) {
  7286. throw new TypeError('WritableStreamDefaultController.prototype.error can only be used on a WritableStreamDefaultController');
  7287. }
  7288. var state = this._controlledWritableStream._state;
  7289. if (state !== 'writable') {
  7290. return;
  7291. }
  7292. WritableStreamDefaultControllerError(this, e);
  7293. }
  7294. }, {
  7295. key: '__abortSteps',
  7296. value: function __abortSteps(reason) {
  7297. return PromiseInvokeOrNoop(this._underlyingSink, 'abort', [reason]);
  7298. }
  7299. }, {
  7300. key: '__errorSteps',
  7301. value: function __errorSteps() {
  7302. ResetQueue(this);
  7303. }
  7304. }, {
  7305. key: '__startSteps',
  7306. value: function __startSteps() {
  7307. var _this = this;
  7308. var startResult = InvokeOrNoop(this._underlyingSink, 'start', [this]);
  7309. var stream = this._controlledWritableStream;
  7310. Promise.resolve(startResult).then(function () {
  7311. assert(stream._state === 'writable' || stream._state === 'erroring');
  7312. _this._started = true;
  7313. WritableStreamDefaultControllerAdvanceQueueIfNeeded(_this);
  7314. }, function (r) {
  7315. assert(stream._state === 'writable' || stream._state === 'erroring');
  7316. _this._started = true;
  7317. WritableStreamDealWithRejection(stream, r);
  7318. }).catch(rethrowAssertionErrorRejection);
  7319. }
  7320. }]);
  7321. return WritableStreamDefaultController;
  7322. }();
  7323. function WritableStreamDefaultControllerClose(controller) {
  7324. EnqueueValueWithSize(controller, 'close', 0);
  7325. WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
  7326. }
  7327. function WritableStreamDefaultControllerGetChunkSize(controller, chunk) {
  7328. var strategySize = controller._strategySize;
  7329. if (strategySize === undefined) {
  7330. return 1;
  7331. }
  7332. try {
  7333. return strategySize(chunk);
  7334. } catch (chunkSizeE) {
  7335. WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE);
  7336. return 1;
  7337. }
  7338. }
  7339. function WritableStreamDefaultControllerGetDesiredSize(controller) {
  7340. return controller._strategyHWM - controller._queueTotalSize;
  7341. }
  7342. function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) {
  7343. var writeRecord = { chunk: chunk };
  7344. try {
  7345. EnqueueValueWithSize(controller, writeRecord, chunkSize);
  7346. } catch (enqueueE) {
  7347. WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE);
  7348. return;
  7349. }
  7350. var stream = controller._controlledWritableStream;
  7351. if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._state === 'writable') {
  7352. var backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
  7353. WritableStreamUpdateBackpressure(stream, backpressure);
  7354. }
  7355. WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
  7356. }
  7357. function IsWritableStreamDefaultController(x) {
  7358. if (!typeIsObject(x)) {
  7359. return false;
  7360. }
  7361. if (!Object.prototype.hasOwnProperty.call(x, '_underlyingSink')) {
  7362. return false;
  7363. }
  7364. return true;
  7365. }
  7366. function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {
  7367. var stream = controller._controlledWritableStream;
  7368. if (controller._started === false) {
  7369. return;
  7370. }
  7371. if (stream._inFlightWriteRequest !== undefined) {
  7372. return;
  7373. }
  7374. var state = stream._state;
  7375. if (state === 'closed' || state === 'errored') {
  7376. return;
  7377. }
  7378. if (state === 'erroring') {
  7379. WritableStreamFinishErroring(stream);
  7380. return;
  7381. }
  7382. if (controller._queue.length === 0) {
  7383. return;
  7384. }
  7385. var writeRecord = PeekQueueValue(controller);
  7386. if (writeRecord === 'close') {
  7387. WritableStreamDefaultControllerProcessClose(controller);
  7388. } else {
  7389. WritableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk);
  7390. }
  7391. }
  7392. function WritableStreamDefaultControllerErrorIfNeeded(controller, error) {
  7393. if (controller._controlledWritableStream._state === 'writable') {
  7394. WritableStreamDefaultControllerError(controller, error);
  7395. }
  7396. }
  7397. function WritableStreamDefaultControllerProcessClose(controller) {
  7398. var stream = controller._controlledWritableStream;
  7399. WritableStreamMarkCloseRequestInFlight(stream);
  7400. DequeueValue(controller);
  7401. assert(controller._queue.length === 0, 'queue must be empty once the final write record is dequeued');
  7402. var sinkClosePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'close', []);
  7403. sinkClosePromise.then(function () {
  7404. WritableStreamFinishInFlightClose(stream);
  7405. }, function (reason) {
  7406. WritableStreamFinishInFlightCloseWithError(stream, reason);
  7407. }).catch(rethrowAssertionErrorRejection);
  7408. }
  7409. function WritableStreamDefaultControllerProcessWrite(controller, chunk) {
  7410. var stream = controller._controlledWritableStream;
  7411. WritableStreamMarkFirstWriteRequestInFlight(stream);
  7412. var sinkWritePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'write', [chunk, controller]);
  7413. sinkWritePromise.then(function () {
  7414. WritableStreamFinishInFlightWrite(stream);
  7415. var state = stream._state;
  7416. assert(state === 'writable' || state === 'erroring');
  7417. DequeueValue(controller);
  7418. if (WritableStreamCloseQueuedOrInFlight(stream) === false && state === 'writable') {
  7419. var backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
  7420. WritableStreamUpdateBackpressure(stream, backpressure);
  7421. }
  7422. WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
  7423. }, function (reason) {
  7424. WritableStreamFinishInFlightWriteWithError(stream, reason);
  7425. }).catch(rethrowAssertionErrorRejection);
  7426. }
  7427. function WritableStreamDefaultControllerGetBackpressure(controller) {
  7428. var desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller);
  7429. return desiredSize <= 0;
  7430. }
  7431. function WritableStreamDefaultControllerError(controller, error) {
  7432. var stream = controller._controlledWritableStream;
  7433. assert(stream._state === 'writable');
  7434. WritableStreamStartErroring(stream, error);
  7435. }
  7436. function streamBrandCheckException(name) {
  7437. return new TypeError('WritableStream.prototype.' + name + ' can only be used on a WritableStream');
  7438. }
  7439. function defaultWriterBrandCheckException(name) {
  7440. return new TypeError('WritableStreamDefaultWriter.prototype.' + name + ' can only be used on a WritableStreamDefaultWriter');
  7441. }
  7442. function defaultWriterLockException(name) {
  7443. return new TypeError('Cannot ' + name + ' a stream using a released writer');
  7444. }
  7445. function defaultWriterClosedPromiseInitialize(writer) {
  7446. writer._closedPromise = new Promise(function (resolve, reject) {
  7447. writer._closedPromise_resolve = resolve;
  7448. writer._closedPromise_reject = reject;
  7449. writer._closedPromiseState = 'pending';
  7450. });
  7451. }
  7452. function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) {
  7453. writer._closedPromise = Promise.reject(reason);
  7454. writer._closedPromise_resolve = undefined;
  7455. writer._closedPromise_reject = undefined;
  7456. writer._closedPromiseState = 'rejected';
  7457. }
  7458. function defaultWriterClosedPromiseInitializeAsResolved(writer) {
  7459. writer._closedPromise = Promise.resolve(undefined);
  7460. writer._closedPromise_resolve = undefined;
  7461. writer._closedPromise_reject = undefined;
  7462. writer._closedPromiseState = 'resolved';
  7463. }
  7464. function defaultWriterClosedPromiseReject(writer, reason) {
  7465. assert(writer._closedPromise_resolve !== undefined, 'writer._closedPromise_resolve !== undefined');
  7466. assert(writer._closedPromise_reject !== undefined, 'writer._closedPromise_reject !== undefined');
  7467. assert(writer._closedPromiseState === 'pending', 'writer._closedPromiseState is pending');
  7468. writer._closedPromise_reject(reason);
  7469. writer._closedPromise_resolve = undefined;
  7470. writer._closedPromise_reject = undefined;
  7471. writer._closedPromiseState = 'rejected';
  7472. }
  7473. function defaultWriterClosedPromiseResetToRejected(writer, reason) {
  7474. assert(writer._closedPromise_resolve === undefined, 'writer._closedPromise_resolve === undefined');
  7475. assert(writer._closedPromise_reject === undefined, 'writer._closedPromise_reject === undefined');
  7476. assert(writer._closedPromiseState !== 'pending', 'writer._closedPromiseState is not pending');
  7477. writer._closedPromise = Promise.reject(reason);
  7478. writer._closedPromiseState = 'rejected';
  7479. }
  7480. function defaultWriterClosedPromiseResolve(writer) {
  7481. assert(writer._closedPromise_resolve !== undefined, 'writer._closedPromise_resolve !== undefined');
  7482. assert(writer._closedPromise_reject !== undefined, 'writer._closedPromise_reject !== undefined');
  7483. assert(writer._closedPromiseState === 'pending', 'writer._closedPromiseState is pending');
  7484. writer._closedPromise_resolve(undefined);
  7485. writer._closedPromise_resolve = undefined;
  7486. writer._closedPromise_reject = undefined;
  7487. writer._closedPromiseState = 'resolved';
  7488. }
  7489. function defaultWriterReadyPromiseInitialize(writer) {
  7490. writer._readyPromise = new Promise(function (resolve, reject) {
  7491. writer._readyPromise_resolve = resolve;
  7492. writer._readyPromise_reject = reject;
  7493. });
  7494. writer._readyPromiseState = 'pending';
  7495. }
  7496. function defaultWriterReadyPromiseInitializeAsRejected(writer, reason) {
  7497. writer._readyPromise = Promise.reject(reason);
  7498. writer._readyPromise_resolve = undefined;
  7499. writer._readyPromise_reject = undefined;
  7500. writer._readyPromiseState = 'rejected';
  7501. }
  7502. function defaultWriterReadyPromiseInitializeAsResolved(writer) {
  7503. writer._readyPromise = Promise.resolve(undefined);
  7504. writer._readyPromise_resolve = undefined;
  7505. writer._readyPromise_reject = undefined;
  7506. writer._readyPromiseState = 'fulfilled';
  7507. }
  7508. function defaultWriterReadyPromiseReject(writer, reason) {
  7509. assert(writer._readyPromise_resolve !== undefined, 'writer._readyPromise_resolve !== undefined');
  7510. assert(writer._readyPromise_reject !== undefined, 'writer._readyPromise_reject !== undefined');
  7511. writer._readyPromise_reject(reason);
  7512. writer._readyPromise_resolve = undefined;
  7513. writer._readyPromise_reject = undefined;
  7514. writer._readyPromiseState = 'rejected';
  7515. }
  7516. function defaultWriterReadyPromiseReset(writer) {
  7517. assert(writer._readyPromise_resolve === undefined, 'writer._readyPromise_resolve === undefined');
  7518. assert(writer._readyPromise_reject === undefined, 'writer._readyPromise_reject === undefined');
  7519. writer._readyPromise = new Promise(function (resolve, reject) {
  7520. writer._readyPromise_resolve = resolve;
  7521. writer._readyPromise_reject = reject;
  7522. });
  7523. writer._readyPromiseState = 'pending';
  7524. }
  7525. function defaultWriterReadyPromiseResetToRejected(writer, reason) {
  7526. assert(writer._readyPromise_resolve === undefined, 'writer._readyPromise_resolve === undefined');
  7527. assert(writer._readyPromise_reject === undefined, 'writer._readyPromise_reject === undefined');
  7528. writer._readyPromise = Promise.reject(reason);
  7529. writer._readyPromiseState = 'rejected';
  7530. }
  7531. function defaultWriterReadyPromiseResolve(writer) {
  7532. assert(writer._readyPromise_resolve !== undefined, 'writer._readyPromise_resolve !== undefined');
  7533. assert(writer._readyPromise_reject !== undefined, 'writer._readyPromise_reject !== undefined');
  7534. writer._readyPromise_resolve(undefined);
  7535. writer._readyPromise_resolve = undefined;
  7536. writer._readyPromise_reject = undefined;
  7537. writer._readyPromiseState = 'fulfilled';
  7538. }
  7539. }, function (module, exports, __w_pdfjs_require__) {
  7540. "use strict";
  7541. var _require = __w_pdfjs_require__(0),
  7542. IsFiniteNonNegativeNumber = _require.IsFiniteNonNegativeNumber;
  7543. var _require2 = __w_pdfjs_require__(1),
  7544. assert = _require2.assert;
  7545. exports.DequeueValue = function (container) {
  7546. assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: DequeueValue should only be used on containers with [[queue]] and [[queueTotalSize]].');
  7547. assert(container._queue.length > 0, 'Spec-level failure: should never dequeue from an empty queue.');
  7548. var pair = container._queue.shift();
  7549. container._queueTotalSize -= pair.size;
  7550. if (container._queueTotalSize < 0) {
  7551. container._queueTotalSize = 0;
  7552. }
  7553. return pair.value;
  7554. };
  7555. exports.EnqueueValueWithSize = function (container, value, size) {
  7556. assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: EnqueueValueWithSize should only be used on containers with [[queue]] and ' + '[[queueTotalSize]].');
  7557. size = Number(size);
  7558. if (!IsFiniteNonNegativeNumber(size)) {
  7559. throw new RangeError('Size must be a finite, non-NaN, non-negative number.');
  7560. }
  7561. container._queue.push({
  7562. value: value,
  7563. size: size
  7564. });
  7565. container._queueTotalSize += size;
  7566. };
  7567. exports.PeekQueueValue = function (container) {
  7568. assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: PeekQueueValue should only be used on containers with [[queue]] and [[queueTotalSize]].');
  7569. assert(container._queue.length > 0, 'Spec-level failure: should never peek at an empty queue.');
  7570. var pair = container._queue[0];
  7571. return pair.value;
  7572. };
  7573. exports.ResetQueue = function (container) {
  7574. assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: ResetQueue should only be used on containers with [[queue]] and [[queueTotalSize]].');
  7575. container._queue = [];
  7576. container._queueTotalSize = 0;
  7577. };
  7578. }, function (module, exports, __w_pdfjs_require__) {
  7579. "use strict";
  7580. var _createClass = function () {
  7581. function defineProperties(target, props) {
  7582. for (var i = 0; i < props.length; i++) {
  7583. var descriptor = props[i];
  7584. descriptor.enumerable = descriptor.enumerable || false;
  7585. descriptor.configurable = true;
  7586. if ("value" in descriptor) descriptor.writable = true;
  7587. Object.defineProperty(target, descriptor.key, descriptor);
  7588. }
  7589. }
  7590. return function (Constructor, protoProps, staticProps) {
  7591. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  7592. if (staticProps) defineProperties(Constructor, staticProps);
  7593. return Constructor;
  7594. };
  7595. }();
  7596. function _classCallCheck(instance, Constructor) {
  7597. if (!(instance instanceof Constructor)) {
  7598. throw new TypeError("Cannot call a class as a function");
  7599. }
  7600. }
  7601. var _require = __w_pdfjs_require__(0),
  7602. ArrayBufferCopy = _require.ArrayBufferCopy,
  7603. CreateIterResultObject = _require.CreateIterResultObject,
  7604. IsFiniteNonNegativeNumber = _require.IsFiniteNonNegativeNumber,
  7605. InvokeOrNoop = _require.InvokeOrNoop,
  7606. PromiseInvokeOrNoop = _require.PromiseInvokeOrNoop,
  7607. TransferArrayBuffer = _require.TransferArrayBuffer,
  7608. ValidateAndNormalizeQueuingStrategy = _require.ValidateAndNormalizeQueuingStrategy,
  7609. ValidateAndNormalizeHighWaterMark = _require.ValidateAndNormalizeHighWaterMark;
  7610. var _require2 = __w_pdfjs_require__(0),
  7611. createArrayFromList = _require2.createArrayFromList,
  7612. createDataProperty = _require2.createDataProperty,
  7613. typeIsObject = _require2.typeIsObject;
  7614. var _require3 = __w_pdfjs_require__(1),
  7615. assert = _require3.assert,
  7616. rethrowAssertionErrorRejection = _require3.rethrowAssertionErrorRejection;
  7617. var _require4 = __w_pdfjs_require__(3),
  7618. DequeueValue = _require4.DequeueValue,
  7619. EnqueueValueWithSize = _require4.EnqueueValueWithSize,
  7620. ResetQueue = _require4.ResetQueue;
  7621. var _require5 = __w_pdfjs_require__(2),
  7622. AcquireWritableStreamDefaultWriter = _require5.AcquireWritableStreamDefaultWriter,
  7623. IsWritableStream = _require5.IsWritableStream,
  7624. IsWritableStreamLocked = _require5.IsWritableStreamLocked,
  7625. WritableStreamAbort = _require5.WritableStreamAbort,
  7626. WritableStreamDefaultWriterCloseWithErrorPropagation = _require5.WritableStreamDefaultWriterCloseWithErrorPropagation,
  7627. WritableStreamDefaultWriterRelease = _require5.WritableStreamDefaultWriterRelease,
  7628. WritableStreamDefaultWriterWrite = _require5.WritableStreamDefaultWriterWrite,
  7629. WritableStreamCloseQueuedOrInFlight = _require5.WritableStreamCloseQueuedOrInFlight;
  7630. var ReadableStream = function () {
  7631. function ReadableStream() {
  7632. var underlyingSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  7633. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  7634. size = _ref.size,
  7635. highWaterMark = _ref.highWaterMark;
  7636. _classCallCheck(this, ReadableStream);
  7637. this._state = 'readable';
  7638. this._reader = undefined;
  7639. this._storedError = undefined;
  7640. this._disturbed = false;
  7641. this._readableStreamController = undefined;
  7642. var type = underlyingSource.type;
  7643. var typeString = String(type);
  7644. if (typeString === 'bytes') {
  7645. if (highWaterMark === undefined) {
  7646. highWaterMark = 0;
  7647. }
  7648. this._readableStreamController = new ReadableByteStreamController(this, underlyingSource, highWaterMark);
  7649. } else if (type === undefined) {
  7650. if (highWaterMark === undefined) {
  7651. highWaterMark = 1;
  7652. }
  7653. this._readableStreamController = new ReadableStreamDefaultController(this, underlyingSource, size, highWaterMark);
  7654. } else {
  7655. throw new RangeError('Invalid type is specified');
  7656. }
  7657. }
  7658. _createClass(ReadableStream, [{
  7659. key: 'cancel',
  7660. value: function cancel(reason) {
  7661. if (IsReadableStream(this) === false) {
  7662. return Promise.reject(streamBrandCheckException('cancel'));
  7663. }
  7664. if (IsReadableStreamLocked(this) === true) {
  7665. return Promise.reject(new TypeError('Cannot cancel a stream that already has a reader'));
  7666. }
  7667. return ReadableStreamCancel(this, reason);
  7668. }
  7669. }, {
  7670. key: 'getReader',
  7671. value: function getReader() {
  7672. var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  7673. mode = _ref2.mode;
  7674. if (IsReadableStream(this) === false) {
  7675. throw streamBrandCheckException('getReader');
  7676. }
  7677. if (mode === undefined) {
  7678. return AcquireReadableStreamDefaultReader(this);
  7679. }
  7680. mode = String(mode);
  7681. if (mode === 'byob') {
  7682. return AcquireReadableStreamBYOBReader(this);
  7683. }
  7684. throw new RangeError('Invalid mode is specified');
  7685. }
  7686. }, {
  7687. key: 'pipeThrough',
  7688. value: function pipeThrough(_ref3, options) {
  7689. var writable = _ref3.writable,
  7690. readable = _ref3.readable;
  7691. var promise = this.pipeTo(writable, options);
  7692. ifIsObjectAndHasAPromiseIsHandledInternalSlotSetPromiseIsHandledToTrue(promise);
  7693. return readable;
  7694. }
  7695. }, {
  7696. key: 'pipeTo',
  7697. value: function pipeTo(dest) {
  7698. var _this = this;
  7699. var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  7700. preventClose = _ref4.preventClose,
  7701. preventAbort = _ref4.preventAbort,
  7702. preventCancel = _ref4.preventCancel;
  7703. if (IsReadableStream(this) === false) {
  7704. return Promise.reject(streamBrandCheckException('pipeTo'));
  7705. }
  7706. if (IsWritableStream(dest) === false) {
  7707. return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo\'s first argument must be a WritableStream'));
  7708. }
  7709. preventClose = Boolean(preventClose);
  7710. preventAbort = Boolean(preventAbort);
  7711. preventCancel = Boolean(preventCancel);
  7712. if (IsReadableStreamLocked(this) === true) {
  7713. return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream'));
  7714. }
  7715. if (IsWritableStreamLocked(dest) === true) {
  7716. return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream'));
  7717. }
  7718. var reader = AcquireReadableStreamDefaultReader(this);
  7719. var writer = AcquireWritableStreamDefaultWriter(dest);
  7720. var shuttingDown = false;
  7721. var currentWrite = Promise.resolve();
  7722. return new Promise(function (resolve, reject) {
  7723. function pipeLoop() {
  7724. currentWrite = Promise.resolve();
  7725. if (shuttingDown === true) {
  7726. return Promise.resolve();
  7727. }
  7728. return writer._readyPromise.then(function () {
  7729. return ReadableStreamDefaultReaderRead(reader).then(function (_ref5) {
  7730. var value = _ref5.value,
  7731. done = _ref5.done;
  7732. if (done === true) {
  7733. return;
  7734. }
  7735. currentWrite = WritableStreamDefaultWriterWrite(writer, value).catch(function () {});
  7736. });
  7737. }).then(pipeLoop);
  7738. }
  7739. isOrBecomesErrored(_this, reader._closedPromise, function (storedError) {
  7740. if (preventAbort === false) {
  7741. shutdownWithAction(function () {
  7742. return WritableStreamAbort(dest, storedError);
  7743. }, true, storedError);
  7744. } else {
  7745. shutdown(true, storedError);
  7746. }
  7747. });
  7748. isOrBecomesErrored(dest, writer._closedPromise, function (storedError) {
  7749. if (preventCancel === false) {
  7750. shutdownWithAction(function () {
  7751. return ReadableStreamCancel(_this, storedError);
  7752. }, true, storedError);
  7753. } else {
  7754. shutdown(true, storedError);
  7755. }
  7756. });
  7757. isOrBecomesClosed(_this, reader._closedPromise, function () {
  7758. if (preventClose === false) {
  7759. shutdownWithAction(function () {
  7760. return WritableStreamDefaultWriterCloseWithErrorPropagation(writer);
  7761. });
  7762. } else {
  7763. shutdown();
  7764. }
  7765. });
  7766. if (WritableStreamCloseQueuedOrInFlight(dest) === true || dest._state === 'closed') {
  7767. var destClosed = new TypeError('the destination writable stream closed before all data could be piped to it');
  7768. if (preventCancel === false) {
  7769. shutdownWithAction(function () {
  7770. return ReadableStreamCancel(_this, destClosed);
  7771. }, true, destClosed);
  7772. } else {
  7773. shutdown(true, destClosed);
  7774. }
  7775. }
  7776. pipeLoop().catch(function (err) {
  7777. currentWrite = Promise.resolve();
  7778. rethrowAssertionErrorRejection(err);
  7779. });
  7780. function waitForWritesToFinish() {
  7781. var oldCurrentWrite = currentWrite;
  7782. return currentWrite.then(function () {
  7783. return oldCurrentWrite !== currentWrite ? waitForWritesToFinish() : undefined;
  7784. });
  7785. }
  7786. function isOrBecomesErrored(stream, promise, action) {
  7787. if (stream._state === 'errored') {
  7788. action(stream._storedError);
  7789. } else {
  7790. promise.catch(action).catch(rethrowAssertionErrorRejection);
  7791. }
  7792. }
  7793. function isOrBecomesClosed(stream, promise, action) {
  7794. if (stream._state === 'closed') {
  7795. action();
  7796. } else {
  7797. promise.then(action).catch(rethrowAssertionErrorRejection);
  7798. }
  7799. }
  7800. function shutdownWithAction(action, originalIsError, originalError) {
  7801. if (shuttingDown === true) {
  7802. return;
  7803. }
  7804. shuttingDown = true;
  7805. if (dest._state === 'writable' && WritableStreamCloseQueuedOrInFlight(dest) === false) {
  7806. waitForWritesToFinish().then(doTheRest);
  7807. } else {
  7808. doTheRest();
  7809. }
  7810. function doTheRest() {
  7811. action().then(function () {
  7812. return finalize(originalIsError, originalError);
  7813. }, function (newError) {
  7814. return finalize(true, newError);
  7815. }).catch(rethrowAssertionErrorRejection);
  7816. }
  7817. }
  7818. function shutdown(isError, error) {
  7819. if (shuttingDown === true) {
  7820. return;
  7821. }
  7822. shuttingDown = true;
  7823. if (dest._state === 'writable' && WritableStreamCloseQueuedOrInFlight(dest) === false) {
  7824. waitForWritesToFinish().then(function () {
  7825. return finalize(isError, error);
  7826. }).catch(rethrowAssertionErrorRejection);
  7827. } else {
  7828. finalize(isError, error);
  7829. }
  7830. }
  7831. function finalize(isError, error) {
  7832. WritableStreamDefaultWriterRelease(writer);
  7833. ReadableStreamReaderGenericRelease(reader);
  7834. if (isError) {
  7835. reject(error);
  7836. } else {
  7837. resolve(undefined);
  7838. }
  7839. }
  7840. });
  7841. }
  7842. }, {
  7843. key: 'tee',
  7844. value: function tee() {
  7845. if (IsReadableStream(this) === false) {
  7846. throw streamBrandCheckException('tee');
  7847. }
  7848. var branches = ReadableStreamTee(this, false);
  7849. return createArrayFromList(branches);
  7850. }
  7851. }, {
  7852. key: 'locked',
  7853. get: function get() {
  7854. if (IsReadableStream(this) === false) {
  7855. throw streamBrandCheckException('locked');
  7856. }
  7857. return IsReadableStreamLocked(this);
  7858. }
  7859. }]);
  7860. return ReadableStream;
  7861. }();
  7862. module.exports = {
  7863. ReadableStream: ReadableStream,
  7864. IsReadableStreamDisturbed: IsReadableStreamDisturbed,
  7865. ReadableStreamDefaultControllerClose: ReadableStreamDefaultControllerClose,
  7866. ReadableStreamDefaultControllerEnqueue: ReadableStreamDefaultControllerEnqueue,
  7867. ReadableStreamDefaultControllerError: ReadableStreamDefaultControllerError,
  7868. ReadableStreamDefaultControllerGetDesiredSize: ReadableStreamDefaultControllerGetDesiredSize
  7869. };
  7870. function AcquireReadableStreamBYOBReader(stream) {
  7871. return new ReadableStreamBYOBReader(stream);
  7872. }
  7873. function AcquireReadableStreamDefaultReader(stream) {
  7874. return new ReadableStreamDefaultReader(stream);
  7875. }
  7876. function IsReadableStream(x) {
  7877. if (!typeIsObject(x)) {
  7878. return false;
  7879. }
  7880. if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) {
  7881. return false;
  7882. }
  7883. return true;
  7884. }
  7885. function IsReadableStreamDisturbed(stream) {
  7886. assert(IsReadableStream(stream) === true, 'IsReadableStreamDisturbed should only be used on known readable streams');
  7887. return stream._disturbed;
  7888. }
  7889. function IsReadableStreamLocked(stream) {
  7890. assert(IsReadableStream(stream) === true, 'IsReadableStreamLocked should only be used on known readable streams');
  7891. if (stream._reader === undefined) {
  7892. return false;
  7893. }
  7894. return true;
  7895. }
  7896. function ReadableStreamTee(stream, cloneForBranch2) {
  7897. assert(IsReadableStream(stream) === true);
  7898. assert(typeof cloneForBranch2 === 'boolean');
  7899. var reader = AcquireReadableStreamDefaultReader(stream);
  7900. var teeState = {
  7901. closedOrErrored: false,
  7902. canceled1: false,
  7903. canceled2: false,
  7904. reason1: undefined,
  7905. reason2: undefined
  7906. };
  7907. teeState.promise = new Promise(function (resolve) {
  7908. teeState._resolve = resolve;
  7909. });
  7910. var pull = create_ReadableStreamTeePullFunction();
  7911. pull._reader = reader;
  7912. pull._teeState = teeState;
  7913. pull._cloneForBranch2 = cloneForBranch2;
  7914. var cancel1 = create_ReadableStreamTeeBranch1CancelFunction();
  7915. cancel1._stream = stream;
  7916. cancel1._teeState = teeState;
  7917. var cancel2 = create_ReadableStreamTeeBranch2CancelFunction();
  7918. cancel2._stream = stream;
  7919. cancel2._teeState = teeState;
  7920. var underlyingSource1 = Object.create(Object.prototype);
  7921. createDataProperty(underlyingSource1, 'pull', pull);
  7922. createDataProperty(underlyingSource1, 'cancel', cancel1);
  7923. var branch1Stream = new ReadableStream(underlyingSource1);
  7924. var underlyingSource2 = Object.create(Object.prototype);
  7925. createDataProperty(underlyingSource2, 'pull', pull);
  7926. createDataProperty(underlyingSource2, 'cancel', cancel2);
  7927. var branch2Stream = new ReadableStream(underlyingSource2);
  7928. pull._branch1 = branch1Stream._readableStreamController;
  7929. pull._branch2 = branch2Stream._readableStreamController;
  7930. reader._closedPromise.catch(function (r) {
  7931. if (teeState.closedOrErrored === true) {
  7932. return;
  7933. }
  7934. ReadableStreamDefaultControllerError(pull._branch1, r);
  7935. ReadableStreamDefaultControllerError(pull._branch2, r);
  7936. teeState.closedOrErrored = true;
  7937. });
  7938. return [branch1Stream, branch2Stream];
  7939. }
  7940. function create_ReadableStreamTeePullFunction() {
  7941. function f() {
  7942. var reader = f._reader,
  7943. branch1 = f._branch1,
  7944. branch2 = f._branch2,
  7945. teeState = f._teeState;
  7946. return ReadableStreamDefaultReaderRead(reader).then(function (result) {
  7947. assert(typeIsObject(result));
  7948. var value = result.value;
  7949. var done = result.done;
  7950. assert(typeof done === 'boolean');
  7951. if (done === true && teeState.closedOrErrored === false) {
  7952. if (teeState.canceled1 === false) {
  7953. ReadableStreamDefaultControllerClose(branch1);
  7954. }
  7955. if (teeState.canceled2 === false) {
  7956. ReadableStreamDefaultControllerClose(branch2);
  7957. }
  7958. teeState.closedOrErrored = true;
  7959. }
  7960. if (teeState.closedOrErrored === true) {
  7961. return;
  7962. }
  7963. var value1 = value;
  7964. var value2 = value;
  7965. if (teeState.canceled1 === false) {
  7966. ReadableStreamDefaultControllerEnqueue(branch1, value1);
  7967. }
  7968. if (teeState.canceled2 === false) {
  7969. ReadableStreamDefaultControllerEnqueue(branch2, value2);
  7970. }
  7971. });
  7972. }
  7973. return f;
  7974. }
  7975. function create_ReadableStreamTeeBranch1CancelFunction() {
  7976. function f(reason) {
  7977. var stream = f._stream,
  7978. teeState = f._teeState;
  7979. teeState.canceled1 = true;
  7980. teeState.reason1 = reason;
  7981. if (teeState.canceled2 === true) {
  7982. var compositeReason = createArrayFromList([teeState.reason1, teeState.reason2]);
  7983. var cancelResult = ReadableStreamCancel(stream, compositeReason);
  7984. teeState._resolve(cancelResult);
  7985. }
  7986. return teeState.promise;
  7987. }
  7988. return f;
  7989. }
  7990. function create_ReadableStreamTeeBranch2CancelFunction() {
  7991. function f(reason) {
  7992. var stream = f._stream,
  7993. teeState = f._teeState;
  7994. teeState.canceled2 = true;
  7995. teeState.reason2 = reason;
  7996. if (teeState.canceled1 === true) {
  7997. var compositeReason = createArrayFromList([teeState.reason1, teeState.reason2]);
  7998. var cancelResult = ReadableStreamCancel(stream, compositeReason);
  7999. teeState._resolve(cancelResult);
  8000. }
  8001. return teeState.promise;
  8002. }
  8003. return f;
  8004. }
  8005. function ReadableStreamAddReadIntoRequest(stream) {
  8006. assert(IsReadableStreamBYOBReader(stream._reader) === true);
  8007. assert(stream._state === 'readable' || stream._state === 'closed');
  8008. var promise = new Promise(function (resolve, reject) {
  8009. var readIntoRequest = {
  8010. _resolve: resolve,
  8011. _reject: reject
  8012. };
  8013. stream._reader._readIntoRequests.push(readIntoRequest);
  8014. });
  8015. return promise;
  8016. }
  8017. function ReadableStreamAddReadRequest(stream) {
  8018. assert(IsReadableStreamDefaultReader(stream._reader) === true);
  8019. assert(stream._state === 'readable');
  8020. var promise = new Promise(function (resolve, reject) {
  8021. var readRequest = {
  8022. _resolve: resolve,
  8023. _reject: reject
  8024. };
  8025. stream._reader._readRequests.push(readRequest);
  8026. });
  8027. return promise;
  8028. }
  8029. function ReadableStreamCancel(stream, reason) {
  8030. stream._disturbed = true;
  8031. if (stream._state === 'closed') {
  8032. return Promise.resolve(undefined);
  8033. }
  8034. if (stream._state === 'errored') {
  8035. return Promise.reject(stream._storedError);
  8036. }
  8037. ReadableStreamClose(stream);
  8038. var sourceCancelPromise = stream._readableStreamController.__cancelSteps(reason);
  8039. return sourceCancelPromise.then(function () {
  8040. return undefined;
  8041. });
  8042. }
  8043. function ReadableStreamClose(stream) {
  8044. assert(stream._state === 'readable');
  8045. stream._state = 'closed';
  8046. var reader = stream._reader;
  8047. if (reader === undefined) {
  8048. return undefined;
  8049. }
  8050. if (IsReadableStreamDefaultReader(reader) === true) {
  8051. for (var i = 0; i < reader._readRequests.length; i++) {
  8052. var _resolve = reader._readRequests[i]._resolve;
  8053. _resolve(CreateIterResultObject(undefined, true));
  8054. }
  8055. reader._readRequests = [];
  8056. }
  8057. defaultReaderClosedPromiseResolve(reader);
  8058. return undefined;
  8059. }
  8060. function ReadableStreamError(stream, e) {
  8061. assert(IsReadableStream(stream) === true, 'stream must be ReadableStream');
  8062. assert(stream._state === 'readable', 'state must be readable');
  8063. stream._state = 'errored';
  8064. stream._storedError = e;
  8065. var reader = stream._reader;
  8066. if (reader === undefined) {
  8067. return undefined;
  8068. }
  8069. if (IsReadableStreamDefaultReader(reader) === true) {
  8070. for (var i = 0; i < reader._readRequests.length; i++) {
  8071. var readRequest = reader._readRequests[i];
  8072. readRequest._reject(e);
  8073. }
  8074. reader._readRequests = [];
  8075. } else {
  8076. assert(IsReadableStreamBYOBReader(reader), 'reader must be ReadableStreamBYOBReader');
  8077. for (var _i = 0; _i < reader._readIntoRequests.length; _i++) {
  8078. var readIntoRequest = reader._readIntoRequests[_i];
  8079. readIntoRequest._reject(e);
  8080. }
  8081. reader._readIntoRequests = [];
  8082. }
  8083. defaultReaderClosedPromiseReject(reader, e);
  8084. reader._closedPromise.catch(function () {});
  8085. }
  8086. function ReadableStreamFulfillReadIntoRequest(stream, chunk, done) {
  8087. var reader = stream._reader;
  8088. assert(reader._readIntoRequests.length > 0);
  8089. var readIntoRequest = reader._readIntoRequests.shift();
  8090. readIntoRequest._resolve(CreateIterResultObject(chunk, done));
  8091. }
  8092. function ReadableStreamFulfillReadRequest(stream, chunk, done) {
  8093. var reader = stream._reader;
  8094. assert(reader._readRequests.length > 0);
  8095. var readRequest = reader._readRequests.shift();
  8096. readRequest._resolve(CreateIterResultObject(chunk, done));
  8097. }
  8098. function ReadableStreamGetNumReadIntoRequests(stream) {
  8099. return stream._reader._readIntoRequests.length;
  8100. }
  8101. function ReadableStreamGetNumReadRequests(stream) {
  8102. return stream._reader._readRequests.length;
  8103. }
  8104. function ReadableStreamHasBYOBReader(stream) {
  8105. var reader = stream._reader;
  8106. if (reader === undefined) {
  8107. return false;
  8108. }
  8109. if (IsReadableStreamBYOBReader(reader) === false) {
  8110. return false;
  8111. }
  8112. return true;
  8113. }
  8114. function ReadableStreamHasDefaultReader(stream) {
  8115. var reader = stream._reader;
  8116. if (reader === undefined) {
  8117. return false;
  8118. }
  8119. if (IsReadableStreamDefaultReader(reader) === false) {
  8120. return false;
  8121. }
  8122. return true;
  8123. }
  8124. var ReadableStreamDefaultReader = function () {
  8125. function ReadableStreamDefaultReader(stream) {
  8126. _classCallCheck(this, ReadableStreamDefaultReader);
  8127. if (IsReadableStream(stream) === false) {
  8128. throw new TypeError('ReadableStreamDefaultReader can only be constructed with a ReadableStream instance');
  8129. }
  8130. if (IsReadableStreamLocked(stream) === true) {
  8131. throw new TypeError('This stream has already been locked for exclusive reading by another reader');
  8132. }
  8133. ReadableStreamReaderGenericInitialize(this, stream);
  8134. this._readRequests = [];
  8135. }
  8136. _createClass(ReadableStreamDefaultReader, [{
  8137. key: 'cancel',
  8138. value: function cancel(reason) {
  8139. if (IsReadableStreamDefaultReader(this) === false) {
  8140. return Promise.reject(defaultReaderBrandCheckException('cancel'));
  8141. }
  8142. if (this._ownerReadableStream === undefined) {
  8143. return Promise.reject(readerLockException('cancel'));
  8144. }
  8145. return ReadableStreamReaderGenericCancel(this, reason);
  8146. }
  8147. }, {
  8148. key: 'read',
  8149. value: function read() {
  8150. if (IsReadableStreamDefaultReader(this) === false) {
  8151. return Promise.reject(defaultReaderBrandCheckException('read'));
  8152. }
  8153. if (this._ownerReadableStream === undefined) {
  8154. return Promise.reject(readerLockException('read from'));
  8155. }
  8156. return ReadableStreamDefaultReaderRead(this);
  8157. }
  8158. }, {
  8159. key: 'releaseLock',
  8160. value: function releaseLock() {
  8161. if (IsReadableStreamDefaultReader(this) === false) {
  8162. throw defaultReaderBrandCheckException('releaseLock');
  8163. }
  8164. if (this._ownerReadableStream === undefined) {
  8165. return;
  8166. }
  8167. if (this._readRequests.length > 0) {
  8168. throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled');
  8169. }
  8170. ReadableStreamReaderGenericRelease(this);
  8171. }
  8172. }, {
  8173. key: 'closed',
  8174. get: function get() {
  8175. if (IsReadableStreamDefaultReader(this) === false) {
  8176. return Promise.reject(defaultReaderBrandCheckException('closed'));
  8177. }
  8178. return this._closedPromise;
  8179. }
  8180. }]);
  8181. return ReadableStreamDefaultReader;
  8182. }();
  8183. var ReadableStreamBYOBReader = function () {
  8184. function ReadableStreamBYOBReader(stream) {
  8185. _classCallCheck(this, ReadableStreamBYOBReader);
  8186. if (!IsReadableStream(stream)) {
  8187. throw new TypeError('ReadableStreamBYOBReader can only be constructed with a ReadableStream instance given a ' + 'byte source');
  8188. }
  8189. if (IsReadableByteStreamController(stream._readableStreamController) === false) {
  8190. throw new TypeError('Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte ' + 'source');
  8191. }
  8192. if (IsReadableStreamLocked(stream)) {
  8193. throw new TypeError('This stream has already been locked for exclusive reading by another reader');
  8194. }
  8195. ReadableStreamReaderGenericInitialize(this, stream);
  8196. this._readIntoRequests = [];
  8197. }
  8198. _createClass(ReadableStreamBYOBReader, [{
  8199. key: 'cancel',
  8200. value: function cancel(reason) {
  8201. if (!IsReadableStreamBYOBReader(this)) {
  8202. return Promise.reject(byobReaderBrandCheckException('cancel'));
  8203. }
  8204. if (this._ownerReadableStream === undefined) {
  8205. return Promise.reject(readerLockException('cancel'));
  8206. }
  8207. return ReadableStreamReaderGenericCancel(this, reason);
  8208. }
  8209. }, {
  8210. key: 'read',
  8211. value: function read(view) {
  8212. if (!IsReadableStreamBYOBReader(this)) {
  8213. return Promise.reject(byobReaderBrandCheckException('read'));
  8214. }
  8215. if (this._ownerReadableStream === undefined) {
  8216. return Promise.reject(readerLockException('read from'));
  8217. }
  8218. if (!ArrayBuffer.isView(view)) {
  8219. return Promise.reject(new TypeError('view must be an array buffer view'));
  8220. }
  8221. if (view.byteLength === 0) {
  8222. return Promise.reject(new TypeError('view must have non-zero byteLength'));
  8223. }
  8224. return ReadableStreamBYOBReaderRead(this, view);
  8225. }
  8226. }, {
  8227. key: 'releaseLock',
  8228. value: function releaseLock() {
  8229. if (!IsReadableStreamBYOBReader(this)) {
  8230. throw byobReaderBrandCheckException('releaseLock');
  8231. }
  8232. if (this._ownerReadableStream === undefined) {
  8233. return;
  8234. }
  8235. if (this._readIntoRequests.length > 0) {
  8236. throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled');
  8237. }
  8238. ReadableStreamReaderGenericRelease(this);
  8239. }
  8240. }, {
  8241. key: 'closed',
  8242. get: function get() {
  8243. if (!IsReadableStreamBYOBReader(this)) {
  8244. return Promise.reject(byobReaderBrandCheckException('closed'));
  8245. }
  8246. return this._closedPromise;
  8247. }
  8248. }]);
  8249. return ReadableStreamBYOBReader;
  8250. }();
  8251. function IsReadableStreamBYOBReader(x) {
  8252. if (!typeIsObject(x)) {
  8253. return false;
  8254. }
  8255. if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) {
  8256. return false;
  8257. }
  8258. return true;
  8259. }
  8260. function IsReadableStreamDefaultReader(x) {
  8261. if (!typeIsObject(x)) {
  8262. return false;
  8263. }
  8264. if (!Object.prototype.hasOwnProperty.call(x, '_readRequests')) {
  8265. return false;
  8266. }
  8267. return true;
  8268. }
  8269. function ReadableStreamReaderGenericInitialize(reader, stream) {
  8270. reader._ownerReadableStream = stream;
  8271. stream._reader = reader;
  8272. if (stream._state === 'readable') {
  8273. defaultReaderClosedPromiseInitialize(reader);
  8274. } else if (stream._state === 'closed') {
  8275. defaultReaderClosedPromiseInitializeAsResolved(reader);
  8276. } else {
  8277. assert(stream._state === 'errored', 'state must be errored');
  8278. defaultReaderClosedPromiseInitializeAsRejected(reader, stream._storedError);
  8279. reader._closedPromise.catch(function () {});
  8280. }
  8281. }
  8282. function ReadableStreamReaderGenericCancel(reader, reason) {
  8283. var stream = reader._ownerReadableStream;
  8284. assert(stream !== undefined);
  8285. return ReadableStreamCancel(stream, reason);
  8286. }
  8287. function ReadableStreamReaderGenericRelease(reader) {
  8288. assert(reader._ownerReadableStream !== undefined);
  8289. assert(reader._ownerReadableStream._reader === reader);
  8290. if (reader._ownerReadableStream._state === 'readable') {
  8291. defaultReaderClosedPromiseReject(reader, new TypeError('Reader was released and can no longer be used to monitor the stream\'s closedness'));
  8292. } else {
  8293. defaultReaderClosedPromiseResetToRejected(reader, new TypeError('Reader was released and can no longer be used to monitor the stream\'s closedness'));
  8294. }
  8295. reader._closedPromise.catch(function () {});
  8296. reader._ownerReadableStream._reader = undefined;
  8297. reader._ownerReadableStream = undefined;
  8298. }
  8299. function ReadableStreamBYOBReaderRead(reader, view) {
  8300. var stream = reader._ownerReadableStream;
  8301. assert(stream !== undefined);
  8302. stream._disturbed = true;
  8303. if (stream._state === 'errored') {
  8304. return Promise.reject(stream._storedError);
  8305. }
  8306. return ReadableByteStreamControllerPullInto(stream._readableStreamController, view);
  8307. }
  8308. function ReadableStreamDefaultReaderRead(reader) {
  8309. var stream = reader._ownerReadableStream;
  8310. assert(stream !== undefined);
  8311. stream._disturbed = true;
  8312. if (stream._state === 'closed') {
  8313. return Promise.resolve(CreateIterResultObject(undefined, true));
  8314. }
  8315. if (stream._state === 'errored') {
  8316. return Promise.reject(stream._storedError);
  8317. }
  8318. assert(stream._state === 'readable');
  8319. return stream._readableStreamController.__pullSteps();
  8320. }
  8321. var ReadableStreamDefaultController = function () {
  8322. function ReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark) {
  8323. _classCallCheck(this, ReadableStreamDefaultController);
  8324. if (IsReadableStream(stream) === false) {
  8325. throw new TypeError('ReadableStreamDefaultController can only be constructed with a ReadableStream instance');
  8326. }
  8327. if (stream._readableStreamController !== undefined) {
  8328. throw new TypeError('ReadableStreamDefaultController instances can only be created by the ReadableStream constructor');
  8329. }
  8330. this._controlledReadableStream = stream;
  8331. this._underlyingSource = underlyingSource;
  8332. this._queue = undefined;
  8333. this._queueTotalSize = undefined;
  8334. ResetQueue(this);
  8335. this._started = false;
  8336. this._closeRequested = false;
  8337. this._pullAgain = false;
  8338. this._pulling = false;
  8339. var normalizedStrategy = ValidateAndNormalizeQueuingStrategy(size, highWaterMark);
  8340. this._strategySize = normalizedStrategy.size;
  8341. this._strategyHWM = normalizedStrategy.highWaterMark;
  8342. var controller = this;
  8343. var startResult = InvokeOrNoop(underlyingSource, 'start', [this]);
  8344. Promise.resolve(startResult).then(function () {
  8345. controller._started = true;
  8346. assert(controller._pulling === false);
  8347. assert(controller._pullAgain === false);
  8348. ReadableStreamDefaultControllerCallPullIfNeeded(controller);
  8349. }, function (r) {
  8350. ReadableStreamDefaultControllerErrorIfNeeded(controller, r);
  8351. }).catch(rethrowAssertionErrorRejection);
  8352. }
  8353. _createClass(ReadableStreamDefaultController, [{
  8354. key: 'close',
  8355. value: function close() {
  8356. if (IsReadableStreamDefaultController(this) === false) {
  8357. throw defaultControllerBrandCheckException('close');
  8358. }
  8359. if (this._closeRequested === true) {
  8360. throw new TypeError('The stream has already been closed; do not close it again!');
  8361. }
  8362. var state = this._controlledReadableStream._state;
  8363. if (state !== 'readable') {
  8364. throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be closed');
  8365. }
  8366. ReadableStreamDefaultControllerClose(this);
  8367. }
  8368. }, {
  8369. key: 'enqueue',
  8370. value: function enqueue(chunk) {
  8371. if (IsReadableStreamDefaultController(this) === false) {
  8372. throw defaultControllerBrandCheckException('enqueue');
  8373. }
  8374. if (this._closeRequested === true) {
  8375. throw new TypeError('stream is closed or draining');
  8376. }
  8377. var state = this._controlledReadableStream._state;
  8378. if (state !== 'readable') {
  8379. throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be enqueued to');
  8380. }
  8381. return ReadableStreamDefaultControllerEnqueue(this, chunk);
  8382. }
  8383. }, {
  8384. key: 'error',
  8385. value: function error(e) {
  8386. if (IsReadableStreamDefaultController(this) === false) {
  8387. throw defaultControllerBrandCheckException('error');
  8388. }
  8389. var stream = this._controlledReadableStream;
  8390. if (stream._state !== 'readable') {
  8391. throw new TypeError('The stream is ' + stream._state + ' and so cannot be errored');
  8392. }
  8393. ReadableStreamDefaultControllerError(this, e);
  8394. }
  8395. }, {
  8396. key: '__cancelSteps',
  8397. value: function __cancelSteps(reason) {
  8398. ResetQueue(this);
  8399. return PromiseInvokeOrNoop(this._underlyingSource, 'cancel', [reason]);
  8400. }
  8401. }, {
  8402. key: '__pullSteps',
  8403. value: function __pullSteps() {
  8404. var stream = this._controlledReadableStream;
  8405. if (this._queue.length > 0) {
  8406. var chunk = DequeueValue(this);
  8407. if (this._closeRequested === true && this._queue.length === 0) {
  8408. ReadableStreamClose(stream);
  8409. } else {
  8410. ReadableStreamDefaultControllerCallPullIfNeeded(this);
  8411. }
  8412. return Promise.resolve(CreateIterResultObject(chunk, false));
  8413. }
  8414. var pendingPromise = ReadableStreamAddReadRequest(stream);
  8415. ReadableStreamDefaultControllerCallPullIfNeeded(this);
  8416. return pendingPromise;
  8417. }
  8418. }, {
  8419. key: 'desiredSize',
  8420. get: function get() {
  8421. if (IsReadableStreamDefaultController(this) === false) {
  8422. throw defaultControllerBrandCheckException('desiredSize');
  8423. }
  8424. return ReadableStreamDefaultControllerGetDesiredSize(this);
  8425. }
  8426. }]);
  8427. return ReadableStreamDefaultController;
  8428. }();
  8429. function IsReadableStreamDefaultController(x) {
  8430. if (!typeIsObject(x)) {
  8431. return false;
  8432. }
  8433. if (!Object.prototype.hasOwnProperty.call(x, '_underlyingSource')) {
  8434. return false;
  8435. }
  8436. return true;
  8437. }
  8438. function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
  8439. var shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
  8440. if (shouldPull === false) {
  8441. return undefined;
  8442. }
  8443. if (controller._pulling === true) {
  8444. controller._pullAgain = true;
  8445. return undefined;
  8446. }
  8447. assert(controller._pullAgain === false);
  8448. controller._pulling = true;
  8449. var pullPromise = PromiseInvokeOrNoop(controller._underlyingSource, 'pull', [controller]);
  8450. pullPromise.then(function () {
  8451. controller._pulling = false;
  8452. if (controller._pullAgain === true) {
  8453. controller._pullAgain = false;
  8454. return ReadableStreamDefaultControllerCallPullIfNeeded(controller);
  8455. }
  8456. return undefined;
  8457. }, function (e) {
  8458. ReadableStreamDefaultControllerErrorIfNeeded(controller, e);
  8459. }).catch(rethrowAssertionErrorRejection);
  8460. return undefined;
  8461. }
  8462. function ReadableStreamDefaultControllerShouldCallPull(controller) {
  8463. var stream = controller._controlledReadableStream;
  8464. if (stream._state === 'closed' || stream._state === 'errored') {
  8465. return false;
  8466. }
  8467. if (controller._closeRequested === true) {
  8468. return false;
  8469. }
  8470. if (controller._started === false) {
  8471. return false;
  8472. }
  8473. if (IsReadableStreamLocked(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) {
  8474. return true;
  8475. }
  8476. var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller);
  8477. if (desiredSize > 0) {
  8478. return true;
  8479. }
  8480. return false;
  8481. }
  8482. function ReadableStreamDefaultControllerClose(controller) {
  8483. var stream = controller._controlledReadableStream;
  8484. assert(controller._closeRequested === false);
  8485. assert(stream._state === 'readable');
  8486. controller._closeRequested = true;
  8487. if (controller._queue.length === 0) {
  8488. ReadableStreamClose(stream);
  8489. }
  8490. }
  8491. function ReadableStreamDefaultControllerEnqueue(controller, chunk) {
  8492. var stream = controller._controlledReadableStream;
  8493. assert(controller._closeRequested === false);
  8494. assert(stream._state === 'readable');
  8495. if (IsReadableStreamLocked(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) {
  8496. ReadableStreamFulfillReadRequest(stream, chunk, false);
  8497. } else {
  8498. var chunkSize = 1;
  8499. if (controller._strategySize !== undefined) {
  8500. var strategySize = controller._strategySize;
  8501. try {
  8502. chunkSize = strategySize(chunk);
  8503. } catch (chunkSizeE) {
  8504. ReadableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE);
  8505. throw chunkSizeE;
  8506. }
  8507. }
  8508. try {
  8509. EnqueueValueWithSize(controller, chunk, chunkSize);
  8510. } catch (enqueueE) {
  8511. ReadableStreamDefaultControllerErrorIfNeeded(controller, enqueueE);
  8512. throw enqueueE;
  8513. }
  8514. }
  8515. ReadableStreamDefaultControllerCallPullIfNeeded(controller);
  8516. return undefined;
  8517. }
  8518. function ReadableStreamDefaultControllerError(controller, e) {
  8519. var stream = controller._controlledReadableStream;
  8520. assert(stream._state === 'readable');
  8521. ResetQueue(controller);
  8522. ReadableStreamError(stream, e);
  8523. }
  8524. function ReadableStreamDefaultControllerErrorIfNeeded(controller, e) {
  8525. if (controller._controlledReadableStream._state === 'readable') {
  8526. ReadableStreamDefaultControllerError(controller, e);
  8527. }
  8528. }
  8529. function ReadableStreamDefaultControllerGetDesiredSize(controller) {
  8530. var stream = controller._controlledReadableStream;
  8531. var state = stream._state;
  8532. if (state === 'errored') {
  8533. return null;
  8534. }
  8535. if (state === 'closed') {
  8536. return 0;
  8537. }
  8538. return controller._strategyHWM - controller._queueTotalSize;
  8539. }
  8540. var ReadableStreamBYOBRequest = function () {
  8541. function ReadableStreamBYOBRequest(controller, view) {
  8542. _classCallCheck(this, ReadableStreamBYOBRequest);
  8543. this._associatedReadableByteStreamController = controller;
  8544. this._view = view;
  8545. }
  8546. _createClass(ReadableStreamBYOBRequest, [{
  8547. key: 'respond',
  8548. value: function respond(bytesWritten) {
  8549. if (IsReadableStreamBYOBRequest(this) === false) {
  8550. throw byobRequestBrandCheckException('respond');
  8551. }
  8552. if (this._associatedReadableByteStreamController === undefined) {
  8553. throw new TypeError('This BYOB request has been invalidated');
  8554. }
  8555. ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
  8556. }
  8557. }, {
  8558. key: 'respondWithNewView',
  8559. value: function respondWithNewView(view) {
  8560. if (IsReadableStreamBYOBRequest(this) === false) {
  8561. throw byobRequestBrandCheckException('respond');
  8562. }
  8563. if (this._associatedReadableByteStreamController === undefined) {
  8564. throw new TypeError('This BYOB request has been invalidated');
  8565. }
  8566. if (!ArrayBuffer.isView(view)) {
  8567. throw new TypeError('You can only respond with array buffer views');
  8568. }
  8569. ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
  8570. }
  8571. }, {
  8572. key: 'view',
  8573. get: function get() {
  8574. return this._view;
  8575. }
  8576. }]);
  8577. return ReadableStreamBYOBRequest;
  8578. }();
  8579. var ReadableByteStreamController = function () {
  8580. function ReadableByteStreamController(stream, underlyingByteSource, highWaterMark) {
  8581. _classCallCheck(this, ReadableByteStreamController);
  8582. if (IsReadableStream(stream) === false) {
  8583. throw new TypeError('ReadableByteStreamController can only be constructed with a ReadableStream instance given ' + 'a byte source');
  8584. }
  8585. if (stream._readableStreamController !== undefined) {
  8586. throw new TypeError('ReadableByteStreamController instances can only be created by the ReadableStream constructor given a byte ' + 'source');
  8587. }
  8588. this._controlledReadableStream = stream;
  8589. this._underlyingByteSource = underlyingByteSource;
  8590. this._pullAgain = false;
  8591. this._pulling = false;
  8592. ReadableByteStreamControllerClearPendingPullIntos(this);
  8593. this._queue = this._queueTotalSize = undefined;
  8594. ResetQueue(this);
  8595. this._closeRequested = false;
  8596. this._started = false;
  8597. this._strategyHWM = ValidateAndNormalizeHighWaterMark(highWaterMark);
  8598. var autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
  8599. if (autoAllocateChunkSize !== undefined) {
  8600. if (Number.isInteger(autoAllocateChunkSize) === false || autoAllocateChunkSize <= 0) {
  8601. throw new RangeError('autoAllocateChunkSize must be a positive integer');
  8602. }
  8603. }
  8604. this._autoAllocateChunkSize = autoAllocateChunkSize;
  8605. this._pendingPullIntos = [];
  8606. var controller = this;
  8607. var startResult = InvokeOrNoop(underlyingByteSource, 'start', [this]);
  8608. Promise.resolve(startResult).then(function () {
  8609. controller._started = true;
  8610. assert(controller._pulling === false);
  8611. assert(controller._pullAgain === false);
  8612. ReadableByteStreamControllerCallPullIfNeeded(controller);
  8613. }, function (r) {
  8614. if (stream._state === 'readable') {
  8615. ReadableByteStreamControllerError(controller, r);
  8616. }
  8617. }).catch(rethrowAssertionErrorRejection);
  8618. }
  8619. _createClass(ReadableByteStreamController, [{
  8620. key: 'close',
  8621. value: function close() {
  8622. if (IsReadableByteStreamController(this) === false) {
  8623. throw byteStreamControllerBrandCheckException('close');
  8624. }
  8625. if (this._closeRequested === true) {
  8626. throw new TypeError('The stream has already been closed; do not close it again!');
  8627. }
  8628. var state = this._controlledReadableStream._state;
  8629. if (state !== 'readable') {
  8630. throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be closed');
  8631. }
  8632. ReadableByteStreamControllerClose(this);
  8633. }
  8634. }, {
  8635. key: 'enqueue',
  8636. value: function enqueue(chunk) {
  8637. if (IsReadableByteStreamController(this) === false) {
  8638. throw byteStreamControllerBrandCheckException('enqueue');
  8639. }
  8640. if (this._closeRequested === true) {
  8641. throw new TypeError('stream is closed or draining');
  8642. }
  8643. var state = this._controlledReadableStream._state;
  8644. if (state !== 'readable') {
  8645. throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be enqueued to');
  8646. }
  8647. if (!ArrayBuffer.isView(chunk)) {
  8648. throw new TypeError('You can only enqueue array buffer views when using a ReadableByteStreamController');
  8649. }
  8650. ReadableByteStreamControllerEnqueue(this, chunk);
  8651. }
  8652. }, {
  8653. key: 'error',
  8654. value: function error(e) {
  8655. if (IsReadableByteStreamController(this) === false) {
  8656. throw byteStreamControllerBrandCheckException('error');
  8657. }
  8658. var stream = this._controlledReadableStream;
  8659. if (stream._state !== 'readable') {
  8660. throw new TypeError('The stream is ' + stream._state + ' and so cannot be errored');
  8661. }
  8662. ReadableByteStreamControllerError(this, e);
  8663. }
  8664. }, {
  8665. key: '__cancelSteps',
  8666. value: function __cancelSteps(reason) {
  8667. if (this._pendingPullIntos.length > 0) {
  8668. var firstDescriptor = this._pendingPullIntos[0];
  8669. firstDescriptor.bytesFilled = 0;
  8670. }
  8671. ResetQueue(this);
  8672. return PromiseInvokeOrNoop(this._underlyingByteSource, 'cancel', [reason]);
  8673. }
  8674. }, {
  8675. key: '__pullSteps',
  8676. value: function __pullSteps() {
  8677. var stream = this._controlledReadableStream;
  8678. assert(ReadableStreamHasDefaultReader(stream) === true);
  8679. if (this._queueTotalSize > 0) {
  8680. assert(ReadableStreamGetNumReadRequests(stream) === 0);
  8681. var entry = this._queue.shift();
  8682. this._queueTotalSize -= entry.byteLength;
  8683. ReadableByteStreamControllerHandleQueueDrain(this);
  8684. var view = void 0;
  8685. try {
  8686. view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
  8687. } catch (viewE) {
  8688. return Promise.reject(viewE);
  8689. }
  8690. return Promise.resolve(CreateIterResultObject(view, false));
  8691. }
  8692. var autoAllocateChunkSize = this._autoAllocateChunkSize;
  8693. if (autoAllocateChunkSize !== undefined) {
  8694. var buffer = void 0;
  8695. try {
  8696. buffer = new ArrayBuffer(autoAllocateChunkSize);
  8697. } catch (bufferE) {
  8698. return Promise.reject(bufferE);
  8699. }
  8700. var pullIntoDescriptor = {
  8701. buffer: buffer,
  8702. byteOffset: 0,
  8703. byteLength: autoAllocateChunkSize,
  8704. bytesFilled: 0,
  8705. elementSize: 1,
  8706. ctor: Uint8Array,
  8707. readerType: 'default'
  8708. };
  8709. this._pendingPullIntos.push(pullIntoDescriptor);
  8710. }
  8711. var promise = ReadableStreamAddReadRequest(stream);
  8712. ReadableByteStreamControllerCallPullIfNeeded(this);
  8713. return promise;
  8714. }
  8715. }, {
  8716. key: 'byobRequest',
  8717. get: function get() {
  8718. if (IsReadableByteStreamController(this) === false) {
  8719. throw byteStreamControllerBrandCheckException('byobRequest');
  8720. }
  8721. if (this._byobRequest === undefined && this._pendingPullIntos.length > 0) {
  8722. var firstDescriptor = this._pendingPullIntos[0];
  8723. var view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
  8724. this._byobRequest = new ReadableStreamBYOBRequest(this, view);
  8725. }
  8726. return this._byobRequest;
  8727. }
  8728. }, {
  8729. key: 'desiredSize',
  8730. get: function get() {
  8731. if (IsReadableByteStreamController(this) === false) {
  8732. throw byteStreamControllerBrandCheckException('desiredSize');
  8733. }
  8734. return ReadableByteStreamControllerGetDesiredSize(this);
  8735. }
  8736. }]);
  8737. return ReadableByteStreamController;
  8738. }();
  8739. function IsReadableByteStreamController(x) {
  8740. if (!typeIsObject(x)) {
  8741. return false;
  8742. }
  8743. if (!Object.prototype.hasOwnProperty.call(x, '_underlyingByteSource')) {
  8744. return false;
  8745. }
  8746. return true;
  8747. }
  8748. function IsReadableStreamBYOBRequest(x) {
  8749. if (!typeIsObject(x)) {
  8750. return false;
  8751. }
  8752. if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) {
  8753. return false;
  8754. }
  8755. return true;
  8756. }
  8757. function ReadableByteStreamControllerCallPullIfNeeded(controller) {
  8758. var shouldPull = ReadableByteStreamControllerShouldCallPull(controller);
  8759. if (shouldPull === false) {
  8760. return undefined;
  8761. }
  8762. if (controller._pulling === true) {
  8763. controller._pullAgain = true;
  8764. return undefined;
  8765. }
  8766. assert(controller._pullAgain === false);
  8767. controller._pulling = true;
  8768. var pullPromise = PromiseInvokeOrNoop(controller._underlyingByteSource, 'pull', [controller]);
  8769. pullPromise.then(function () {
  8770. controller._pulling = false;
  8771. if (controller._pullAgain === true) {
  8772. controller._pullAgain = false;
  8773. ReadableByteStreamControllerCallPullIfNeeded(controller);
  8774. }
  8775. }, function (e) {
  8776. if (controller._controlledReadableStream._state === 'readable') {
  8777. ReadableByteStreamControllerError(controller, e);
  8778. }
  8779. }).catch(rethrowAssertionErrorRejection);
  8780. return undefined;
  8781. }
  8782. function ReadableByteStreamControllerClearPendingPullIntos(controller) {
  8783. ReadableByteStreamControllerInvalidateBYOBRequest(controller);
  8784. controller._pendingPullIntos = [];
  8785. }
  8786. function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) {
  8787. assert(stream._state !== 'errored', 'state must not be errored');
  8788. var done = false;
  8789. if (stream._state === 'closed') {
  8790. assert(pullIntoDescriptor.bytesFilled === 0);
  8791. done = true;
  8792. }
  8793. var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);
  8794. if (pullIntoDescriptor.readerType === 'default') {
  8795. ReadableStreamFulfillReadRequest(stream, filledView, done);
  8796. } else {
  8797. assert(pullIntoDescriptor.readerType === 'byob');
  8798. ReadableStreamFulfillReadIntoRequest(stream, filledView, done);
  8799. }
  8800. }
  8801. function ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) {
  8802. var bytesFilled = pullIntoDescriptor.bytesFilled;
  8803. var elementSize = pullIntoDescriptor.elementSize;
  8804. assert(bytesFilled <= pullIntoDescriptor.byteLength);
  8805. assert(bytesFilled % elementSize === 0);
  8806. return new pullIntoDescriptor.ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize);
  8807. }
  8808. function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) {
  8809. controller._queue.push({
  8810. buffer: buffer,
  8811. byteOffset: byteOffset,
  8812. byteLength: byteLength
  8813. });
  8814. controller._queueTotalSize += byteLength;
  8815. }
  8816. function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) {
  8817. var elementSize = pullIntoDescriptor.elementSize;
  8818. var currentAlignedBytes = pullIntoDescriptor.bytesFilled - pullIntoDescriptor.bytesFilled % elementSize;
  8819. var maxBytesToCopy = Math.min(controller._queueTotalSize, pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled);
  8820. var maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;
  8821. var maxAlignedBytes = maxBytesFilled - maxBytesFilled % elementSize;
  8822. var totalBytesToCopyRemaining = maxBytesToCopy;
  8823. var ready = false;
  8824. if (maxAlignedBytes > currentAlignedBytes) {
  8825. totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;
  8826. ready = true;
  8827. }
  8828. var queue = controller._queue;
  8829. while (totalBytesToCopyRemaining > 0) {
  8830. var headOfQueue = queue[0];
  8831. var bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength);
  8832. var destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
  8833. ArrayBufferCopy(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy);
  8834. if (headOfQueue.byteLength === bytesToCopy) {
  8835. queue.shift();
  8836. } else {
  8837. headOfQueue.byteOffset += bytesToCopy;
  8838. headOfQueue.byteLength -= bytesToCopy;
  8839. }
  8840. controller._queueTotalSize -= bytesToCopy;
  8841. ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor);
  8842. totalBytesToCopyRemaining -= bytesToCopy;
  8843. }
  8844. if (ready === false) {
  8845. assert(controller._queueTotalSize === 0, 'queue must be empty');
  8846. assert(pullIntoDescriptor.bytesFilled > 0);
  8847. assert(pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize);
  8848. }
  8849. return ready;
  8850. }
  8851. function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {
  8852. assert(controller._pendingPullIntos.length === 0 || controller._pendingPullIntos[0] === pullIntoDescriptor);
  8853. ReadableByteStreamControllerInvalidateBYOBRequest(controller);
  8854. pullIntoDescriptor.bytesFilled += size;
  8855. }
  8856. function ReadableByteStreamControllerHandleQueueDrain(controller) {
  8857. assert(controller._controlledReadableStream._state === 'readable');
  8858. if (controller._queueTotalSize === 0 && controller._closeRequested === true) {
  8859. ReadableStreamClose(controller._controlledReadableStream);
  8860. } else {
  8861. ReadableByteStreamControllerCallPullIfNeeded(controller);
  8862. }
  8863. }
  8864. function ReadableByteStreamControllerInvalidateBYOBRequest(controller) {
  8865. if (controller._byobRequest === undefined) {
  8866. return;
  8867. }
  8868. controller._byobRequest._associatedReadableByteStreamController = undefined;
  8869. controller._byobRequest._view = undefined;
  8870. controller._byobRequest = undefined;
  8871. }
  8872. function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) {
  8873. assert(controller._closeRequested === false);
  8874. while (controller._pendingPullIntos.length > 0) {
  8875. if (controller._queueTotalSize === 0) {
  8876. return;
  8877. }
  8878. var pullIntoDescriptor = controller._pendingPullIntos[0];
  8879. if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) {
  8880. ReadableByteStreamControllerShiftPendingPullInto(controller);
  8881. ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor);
  8882. }
  8883. }
  8884. }
  8885. function ReadableByteStreamControllerPullInto(controller, view) {
  8886. var stream = controller._controlledReadableStream;
  8887. var elementSize = 1;
  8888. if (view.constructor !== DataView) {
  8889. elementSize = view.constructor.BYTES_PER_ELEMENT;
  8890. }
  8891. var ctor = view.constructor;
  8892. var pullIntoDescriptor = {
  8893. buffer: view.buffer,
  8894. byteOffset: view.byteOffset,
  8895. byteLength: view.byteLength,
  8896. bytesFilled: 0,
  8897. elementSize: elementSize,
  8898. ctor: ctor,
  8899. readerType: 'byob'
  8900. };
  8901. if (controller._pendingPullIntos.length > 0) {
  8902. pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer);
  8903. controller._pendingPullIntos.push(pullIntoDescriptor);
  8904. return ReadableStreamAddReadIntoRequest(stream);
  8905. }
  8906. if (stream._state === 'closed') {
  8907. var emptyView = new view.constructor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0);
  8908. return Promise.resolve(CreateIterResultObject(emptyView, true));
  8909. }
  8910. if (controller._queueTotalSize > 0) {
  8911. if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) {
  8912. var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);
  8913. ReadableByteStreamControllerHandleQueueDrain(controller);
  8914. return Promise.resolve(CreateIterResultObject(filledView, false));
  8915. }
  8916. if (controller._closeRequested === true) {
  8917. var e = new TypeError('Insufficient bytes to fill elements in the given buffer');
  8918. ReadableByteStreamControllerError(controller, e);
  8919. return Promise.reject(e);
  8920. }
  8921. }
  8922. pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer);
  8923. controller._pendingPullIntos.push(pullIntoDescriptor);
  8924. var promise = ReadableStreamAddReadIntoRequest(stream);
  8925. ReadableByteStreamControllerCallPullIfNeeded(controller);
  8926. return promise;
  8927. }
  8928. function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
  8929. firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
  8930. assert(firstDescriptor.bytesFilled === 0, 'bytesFilled must be 0');
  8931. var stream = controller._controlledReadableStream;
  8932. if (ReadableStreamHasBYOBReader(stream) === true) {
  8933. while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {
  8934. var pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller);
  8935. ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor);
  8936. }
  8937. }
  8938. }
  8939. function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {
  8940. if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) {
  8941. throw new RangeError('bytesWritten out of range');
  8942. }
  8943. ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);
  8944. if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {
  8945. return;
  8946. }
  8947. ReadableByteStreamControllerShiftPendingPullInto(controller);
  8948. var remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
  8949. if (remainderSize > 0) {
  8950. var end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
  8951. var remainder = pullIntoDescriptor.buffer.slice(end - remainderSize, end);
  8952. ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);
  8953. }
  8954. pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer);
  8955. pullIntoDescriptor.bytesFilled -= remainderSize;
  8956. ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor);
  8957. ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
  8958. }
  8959. function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
  8960. var firstDescriptor = controller._pendingPullIntos[0];
  8961. var stream = controller._controlledReadableStream;
  8962. if (stream._state === 'closed') {
  8963. if (bytesWritten !== 0) {
  8964. throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream');
  8965. }
  8966. ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor);
  8967. } else {
  8968. assert(stream._state === 'readable');
  8969. ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
  8970. }
  8971. }
  8972. function ReadableByteStreamControllerShiftPendingPullInto(controller) {
  8973. var descriptor = controller._pendingPullIntos.shift();
  8974. ReadableByteStreamControllerInvalidateBYOBRequest(controller);
  8975. return descriptor;
  8976. }
  8977. function ReadableByteStreamControllerShouldCallPull(controller) {
  8978. var stream = controller._controlledReadableStream;
  8979. if (stream._state !== 'readable') {
  8980. return false;
  8981. }
  8982. if (controller._closeRequested === true) {
  8983. return false;
  8984. }
  8985. if (controller._started === false) {
  8986. return false;
  8987. }
  8988. if (ReadableStreamHasDefaultReader(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) {
  8989. return true;
  8990. }
  8991. if (ReadableStreamHasBYOBReader(stream) === true && ReadableStreamGetNumReadIntoRequests(stream) > 0) {
  8992. return true;
  8993. }
  8994. if (ReadableByteStreamControllerGetDesiredSize(controller) > 0) {
  8995. return true;
  8996. }
  8997. return false;
  8998. }
  8999. function ReadableByteStreamControllerClose(controller) {
  9000. var stream = controller._controlledReadableStream;
  9001. assert(controller._closeRequested === false);
  9002. assert(stream._state === 'readable');
  9003. if (controller._queueTotalSize > 0) {
  9004. controller._closeRequested = true;
  9005. return;
  9006. }
  9007. if (controller._pendingPullIntos.length > 0) {
  9008. var firstPendingPullInto = controller._pendingPullIntos[0];
  9009. if (firstPendingPullInto.bytesFilled > 0) {
  9010. var e = new TypeError('Insufficient bytes to fill elements in the given buffer');
  9011. ReadableByteStreamControllerError(controller, e);
  9012. throw e;
  9013. }
  9014. }
  9015. ReadableStreamClose(stream);
  9016. }
  9017. function ReadableByteStreamControllerEnqueue(controller, chunk) {
  9018. var stream = controller._controlledReadableStream;
  9019. assert(controller._closeRequested === false);
  9020. assert(stream._state === 'readable');
  9021. var buffer = chunk.buffer;
  9022. var byteOffset = chunk.byteOffset;
  9023. var byteLength = chunk.byteLength;
  9024. var transferredBuffer = TransferArrayBuffer(buffer);
  9025. if (ReadableStreamHasDefaultReader(stream) === true) {
  9026. if (ReadableStreamGetNumReadRequests(stream) === 0) {
  9027. ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
  9028. } else {
  9029. assert(controller._queue.length === 0);
  9030. var transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);
  9031. ReadableStreamFulfillReadRequest(stream, transferredView, false);
  9032. }
  9033. } else if (ReadableStreamHasBYOBReader(stream) === true) {
  9034. ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
  9035. ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
  9036. } else {
  9037. assert(IsReadableStreamLocked(stream) === false, 'stream must not be locked');
  9038. ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
  9039. }
  9040. }
  9041. function ReadableByteStreamControllerError(controller, e) {
  9042. var stream = controller._controlledReadableStream;
  9043. assert(stream._state === 'readable');
  9044. ReadableByteStreamControllerClearPendingPullIntos(controller);
  9045. ResetQueue(controller);
  9046. ReadableStreamError(stream, e);
  9047. }
  9048. function ReadableByteStreamControllerGetDesiredSize(controller) {
  9049. var stream = controller._controlledReadableStream;
  9050. var state = stream._state;
  9051. if (state === 'errored') {
  9052. return null;
  9053. }
  9054. if (state === 'closed') {
  9055. return 0;
  9056. }
  9057. return controller._strategyHWM - controller._queueTotalSize;
  9058. }
  9059. function ReadableByteStreamControllerRespond(controller, bytesWritten) {
  9060. bytesWritten = Number(bytesWritten);
  9061. if (IsFiniteNonNegativeNumber(bytesWritten) === false) {
  9062. throw new RangeError('bytesWritten must be a finite');
  9063. }
  9064. assert(controller._pendingPullIntos.length > 0);
  9065. ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
  9066. }
  9067. function ReadableByteStreamControllerRespondWithNewView(controller, view) {
  9068. assert(controller._pendingPullIntos.length > 0);
  9069. var firstDescriptor = controller._pendingPullIntos[0];
  9070. if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
  9071. throw new RangeError('The region specified by view does not match byobRequest');
  9072. }
  9073. if (firstDescriptor.byteLength !== view.byteLength) {
  9074. throw new RangeError('The buffer of view has different capacity than byobRequest');
  9075. }
  9076. firstDescriptor.buffer = view.buffer;
  9077. ReadableByteStreamControllerRespondInternal(controller, view.byteLength);
  9078. }
  9079. function streamBrandCheckException(name) {
  9080. return new TypeError('ReadableStream.prototype.' + name + ' can only be used on a ReadableStream');
  9081. }
  9082. function readerLockException(name) {
  9083. return new TypeError('Cannot ' + name + ' a stream using a released reader');
  9084. }
  9085. function defaultReaderBrandCheckException(name) {
  9086. return new TypeError('ReadableStreamDefaultReader.prototype.' + name + ' can only be used on a ReadableStreamDefaultReader');
  9087. }
  9088. function defaultReaderClosedPromiseInitialize(reader) {
  9089. reader._closedPromise = new Promise(function (resolve, reject) {
  9090. reader._closedPromise_resolve = resolve;
  9091. reader._closedPromise_reject = reject;
  9092. });
  9093. }
  9094. function defaultReaderClosedPromiseInitializeAsRejected(reader, reason) {
  9095. reader._closedPromise = Promise.reject(reason);
  9096. reader._closedPromise_resolve = undefined;
  9097. reader._closedPromise_reject = undefined;
  9098. }
  9099. function defaultReaderClosedPromiseInitializeAsResolved(reader) {
  9100. reader._closedPromise = Promise.resolve(undefined);
  9101. reader._closedPromise_resolve = undefined;
  9102. reader._closedPromise_reject = undefined;
  9103. }
  9104. function defaultReaderClosedPromiseReject(reader, reason) {
  9105. assert(reader._closedPromise_resolve !== undefined);
  9106. assert(reader._closedPromise_reject !== undefined);
  9107. reader._closedPromise_reject(reason);
  9108. reader._closedPromise_resolve = undefined;
  9109. reader._closedPromise_reject = undefined;
  9110. }
  9111. function defaultReaderClosedPromiseResetToRejected(reader, reason) {
  9112. assert(reader._closedPromise_resolve === undefined);
  9113. assert(reader._closedPromise_reject === undefined);
  9114. reader._closedPromise = Promise.reject(reason);
  9115. }
  9116. function defaultReaderClosedPromiseResolve(reader) {
  9117. assert(reader._closedPromise_resolve !== undefined);
  9118. assert(reader._closedPromise_reject !== undefined);
  9119. reader._closedPromise_resolve(undefined);
  9120. reader._closedPromise_resolve = undefined;
  9121. reader._closedPromise_reject = undefined;
  9122. }
  9123. function byobReaderBrandCheckException(name) {
  9124. return new TypeError('ReadableStreamBYOBReader.prototype.' + name + ' can only be used on a ReadableStreamBYOBReader');
  9125. }
  9126. function defaultControllerBrandCheckException(name) {
  9127. return new TypeError('ReadableStreamDefaultController.prototype.' + name + ' can only be used on a ReadableStreamDefaultController');
  9128. }
  9129. function byobRequestBrandCheckException(name) {
  9130. return new TypeError('ReadableStreamBYOBRequest.prototype.' + name + ' can only be used on a ReadableStreamBYOBRequest');
  9131. }
  9132. function byteStreamControllerBrandCheckException(name) {
  9133. return new TypeError('ReadableByteStreamController.prototype.' + name + ' can only be used on a ReadableByteStreamController');
  9134. }
  9135. function ifIsObjectAndHasAPromiseIsHandledInternalSlotSetPromiseIsHandledToTrue(promise) {
  9136. try {
  9137. Promise.prototype.then.call(promise, undefined, function () {});
  9138. } catch (e) {}
  9139. }
  9140. }, function (module, exports, __w_pdfjs_require__) {
  9141. "use strict";
  9142. var transformStream = __w_pdfjs_require__(6);
  9143. var readableStream = __w_pdfjs_require__(4);
  9144. var writableStream = __w_pdfjs_require__(2);
  9145. exports.TransformStream = transformStream.TransformStream;
  9146. exports.ReadableStream = readableStream.ReadableStream;
  9147. exports.IsReadableStreamDisturbed = readableStream.IsReadableStreamDisturbed;
  9148. exports.ReadableStreamDefaultControllerClose = readableStream.ReadableStreamDefaultControllerClose;
  9149. exports.ReadableStreamDefaultControllerEnqueue = readableStream.ReadableStreamDefaultControllerEnqueue;
  9150. exports.ReadableStreamDefaultControllerError = readableStream.ReadableStreamDefaultControllerError;
  9151. exports.ReadableStreamDefaultControllerGetDesiredSize = readableStream.ReadableStreamDefaultControllerGetDesiredSize;
  9152. exports.AcquireWritableStreamDefaultWriter = writableStream.AcquireWritableStreamDefaultWriter;
  9153. exports.IsWritableStream = writableStream.IsWritableStream;
  9154. exports.IsWritableStreamLocked = writableStream.IsWritableStreamLocked;
  9155. exports.WritableStream = writableStream.WritableStream;
  9156. exports.WritableStreamAbort = writableStream.WritableStreamAbort;
  9157. exports.WritableStreamDefaultControllerError = writableStream.WritableStreamDefaultControllerError;
  9158. exports.WritableStreamDefaultWriterCloseWithErrorPropagation = writableStream.WritableStreamDefaultWriterCloseWithErrorPropagation;
  9159. exports.WritableStreamDefaultWriterRelease = writableStream.WritableStreamDefaultWriterRelease;
  9160. exports.WritableStreamDefaultWriterWrite = writableStream.WritableStreamDefaultWriterWrite;
  9161. }, function (module, exports, __w_pdfjs_require__) {
  9162. "use strict";
  9163. var _createClass = function () {
  9164. function defineProperties(target, props) {
  9165. for (var i = 0; i < props.length; i++) {
  9166. var descriptor = props[i];
  9167. descriptor.enumerable = descriptor.enumerable || false;
  9168. descriptor.configurable = true;
  9169. if ("value" in descriptor) descriptor.writable = true;
  9170. Object.defineProperty(target, descriptor.key, descriptor);
  9171. }
  9172. }
  9173. return function (Constructor, protoProps, staticProps) {
  9174. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  9175. if (staticProps) defineProperties(Constructor, staticProps);
  9176. return Constructor;
  9177. };
  9178. }();
  9179. function _classCallCheck(instance, Constructor) {
  9180. if (!(instance instanceof Constructor)) {
  9181. throw new TypeError("Cannot call a class as a function");
  9182. }
  9183. }
  9184. var _require = __w_pdfjs_require__(1),
  9185. assert = _require.assert;
  9186. var _require2 = __w_pdfjs_require__(0),
  9187. InvokeOrNoop = _require2.InvokeOrNoop,
  9188. PromiseInvokeOrPerformFallback = _require2.PromiseInvokeOrPerformFallback,
  9189. PromiseInvokeOrNoop = _require2.PromiseInvokeOrNoop,
  9190. typeIsObject = _require2.typeIsObject;
  9191. var _require3 = __w_pdfjs_require__(4),
  9192. ReadableStream = _require3.ReadableStream,
  9193. ReadableStreamDefaultControllerClose = _require3.ReadableStreamDefaultControllerClose,
  9194. ReadableStreamDefaultControllerEnqueue = _require3.ReadableStreamDefaultControllerEnqueue,
  9195. ReadableStreamDefaultControllerError = _require3.ReadableStreamDefaultControllerError,
  9196. ReadableStreamDefaultControllerGetDesiredSize = _require3.ReadableStreamDefaultControllerGetDesiredSize;
  9197. var _require4 = __w_pdfjs_require__(2),
  9198. WritableStream = _require4.WritableStream,
  9199. WritableStreamDefaultControllerError = _require4.WritableStreamDefaultControllerError;
  9200. function TransformStreamCloseReadable(transformStream) {
  9201. if (transformStream._errored === true) {
  9202. throw new TypeError('TransformStream is already errored');
  9203. }
  9204. if (transformStream._readableClosed === true) {
  9205. throw new TypeError('Readable side is already closed');
  9206. }
  9207. TransformStreamCloseReadableInternal(transformStream);
  9208. }
  9209. function TransformStreamEnqueueToReadable(transformStream, chunk) {
  9210. if (transformStream._errored === true) {
  9211. throw new TypeError('TransformStream is already errored');
  9212. }
  9213. if (transformStream._readableClosed === true) {
  9214. throw new TypeError('Readable side is already closed');
  9215. }
  9216. var controller = transformStream._readableController;
  9217. try {
  9218. ReadableStreamDefaultControllerEnqueue(controller, chunk);
  9219. } catch (e) {
  9220. transformStream._readableClosed = true;
  9221. TransformStreamErrorIfNeeded(transformStream, e);
  9222. throw transformStream._storedError;
  9223. }
  9224. var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller);
  9225. var maybeBackpressure = desiredSize <= 0;
  9226. if (maybeBackpressure === true && transformStream._backpressure === false) {
  9227. TransformStreamSetBackpressure(transformStream, true);
  9228. }
  9229. }
  9230. function TransformStreamError(transformStream, e) {
  9231. if (transformStream._errored === true) {
  9232. throw new TypeError('TransformStream is already errored');
  9233. }
  9234. TransformStreamErrorInternal(transformStream, e);
  9235. }
  9236. function TransformStreamCloseReadableInternal(transformStream) {
  9237. assert(transformStream._errored === false);
  9238. assert(transformStream._readableClosed === false);
  9239. try {
  9240. ReadableStreamDefaultControllerClose(transformStream._readableController);
  9241. } catch (e) {
  9242. assert(false);
  9243. }
  9244. transformStream._readableClosed = true;
  9245. }
  9246. function TransformStreamErrorIfNeeded(transformStream, e) {
  9247. if (transformStream._errored === false) {
  9248. TransformStreamErrorInternal(transformStream, e);
  9249. }
  9250. }
  9251. function TransformStreamErrorInternal(transformStream, e) {
  9252. assert(transformStream._errored === false);
  9253. transformStream._errored = true;
  9254. transformStream._storedError = e;
  9255. if (transformStream._writableDone === false) {
  9256. WritableStreamDefaultControllerError(transformStream._writableController, e);
  9257. }
  9258. if (transformStream._readableClosed === false) {
  9259. ReadableStreamDefaultControllerError(transformStream._readableController, e);
  9260. }
  9261. }
  9262. function TransformStreamReadableReadyPromise(transformStream) {
  9263. assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized');
  9264. if (transformStream._backpressure === false) {
  9265. return Promise.resolve();
  9266. }
  9267. assert(transformStream._backpressure === true, '_backpressure should have been initialized');
  9268. return transformStream._backpressureChangePromise;
  9269. }
  9270. function TransformStreamSetBackpressure(transformStream, backpressure) {
  9271. assert(transformStream._backpressure !== backpressure, 'TransformStreamSetBackpressure() should be called only when backpressure is changed');
  9272. if (transformStream._backpressureChangePromise !== undefined) {
  9273. transformStream._backpressureChangePromise_resolve(backpressure);
  9274. }
  9275. transformStream._backpressureChangePromise = new Promise(function (resolve) {
  9276. transformStream._backpressureChangePromise_resolve = resolve;
  9277. });
  9278. transformStream._backpressureChangePromise.then(function (resolution) {
  9279. assert(resolution !== backpressure, '_backpressureChangePromise should be fulfilled only when backpressure is changed');
  9280. });
  9281. transformStream._backpressure = backpressure;
  9282. }
  9283. function TransformStreamDefaultTransform(chunk, transformStreamController) {
  9284. var transformStream = transformStreamController._controlledTransformStream;
  9285. TransformStreamEnqueueToReadable(transformStream, chunk);
  9286. return Promise.resolve();
  9287. }
  9288. function TransformStreamTransform(transformStream, chunk) {
  9289. assert(transformStream._errored === false);
  9290. assert(transformStream._transforming === false);
  9291. assert(transformStream._backpressure === false);
  9292. transformStream._transforming = true;
  9293. var transformer = transformStream._transformer;
  9294. var controller = transformStream._transformStreamController;
  9295. var transformPromise = PromiseInvokeOrPerformFallback(transformer, 'transform', [chunk, controller], TransformStreamDefaultTransform, [chunk, controller]);
  9296. return transformPromise.then(function () {
  9297. transformStream._transforming = false;
  9298. return TransformStreamReadableReadyPromise(transformStream);
  9299. }, function (e) {
  9300. TransformStreamErrorIfNeeded(transformStream, e);
  9301. return Promise.reject(e);
  9302. });
  9303. }
  9304. function IsTransformStreamDefaultController(x) {
  9305. if (!typeIsObject(x)) {
  9306. return false;
  9307. }
  9308. if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) {
  9309. return false;
  9310. }
  9311. return true;
  9312. }
  9313. function IsTransformStream(x) {
  9314. if (!typeIsObject(x)) {
  9315. return false;
  9316. }
  9317. if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) {
  9318. return false;
  9319. }
  9320. return true;
  9321. }
  9322. var TransformStreamSink = function () {
  9323. function TransformStreamSink(transformStream, startPromise) {
  9324. _classCallCheck(this, TransformStreamSink);
  9325. this._transformStream = transformStream;
  9326. this._startPromise = startPromise;
  9327. }
  9328. _createClass(TransformStreamSink, [{
  9329. key: 'start',
  9330. value: function start(c) {
  9331. var transformStream = this._transformStream;
  9332. transformStream._writableController = c;
  9333. return this._startPromise.then(function () {
  9334. return TransformStreamReadableReadyPromise(transformStream);
  9335. });
  9336. }
  9337. }, {
  9338. key: 'write',
  9339. value: function write(chunk) {
  9340. var transformStream = this._transformStream;
  9341. return TransformStreamTransform(transformStream, chunk);
  9342. }
  9343. }, {
  9344. key: 'abort',
  9345. value: function abort() {
  9346. var transformStream = this._transformStream;
  9347. transformStream._writableDone = true;
  9348. TransformStreamErrorInternal(transformStream, new TypeError('Writable side aborted'));
  9349. }
  9350. }, {
  9351. key: 'close',
  9352. value: function close() {
  9353. var transformStream = this._transformStream;
  9354. assert(transformStream._transforming === false);
  9355. transformStream._writableDone = true;
  9356. var flushPromise = PromiseInvokeOrNoop(transformStream._transformer, 'flush', [transformStream._transformStreamController]);
  9357. return flushPromise.then(function () {
  9358. if (transformStream._errored === true) {
  9359. return Promise.reject(transformStream._storedError);
  9360. }
  9361. if (transformStream._readableClosed === false) {
  9362. TransformStreamCloseReadableInternal(transformStream);
  9363. }
  9364. return Promise.resolve();
  9365. }).catch(function (r) {
  9366. TransformStreamErrorIfNeeded(transformStream, r);
  9367. return Promise.reject(transformStream._storedError);
  9368. });
  9369. }
  9370. }]);
  9371. return TransformStreamSink;
  9372. }();
  9373. var TransformStreamSource = function () {
  9374. function TransformStreamSource(transformStream, startPromise) {
  9375. _classCallCheck(this, TransformStreamSource);
  9376. this._transformStream = transformStream;
  9377. this._startPromise = startPromise;
  9378. }
  9379. _createClass(TransformStreamSource, [{
  9380. key: 'start',
  9381. value: function start(c) {
  9382. var transformStream = this._transformStream;
  9383. transformStream._readableController = c;
  9384. return this._startPromise.then(function () {
  9385. assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized');
  9386. if (transformStream._backpressure === true) {
  9387. return Promise.resolve();
  9388. }
  9389. assert(transformStream._backpressure === false, '_backpressure should have been initialized');
  9390. return transformStream._backpressureChangePromise;
  9391. });
  9392. }
  9393. }, {
  9394. key: 'pull',
  9395. value: function pull() {
  9396. var transformStream = this._transformStream;
  9397. assert(transformStream._backpressure === true, 'pull() should be never called while _backpressure is false');
  9398. assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized');
  9399. TransformStreamSetBackpressure(transformStream, false);
  9400. return transformStream._backpressureChangePromise;
  9401. }
  9402. }, {
  9403. key: 'cancel',
  9404. value: function cancel() {
  9405. var transformStream = this._transformStream;
  9406. transformStream._readableClosed = true;
  9407. TransformStreamErrorInternal(transformStream, new TypeError('Readable side canceled'));
  9408. }
  9409. }]);
  9410. return TransformStreamSource;
  9411. }();
  9412. var TransformStreamDefaultController = function () {
  9413. function TransformStreamDefaultController(transformStream) {
  9414. _classCallCheck(this, TransformStreamDefaultController);
  9415. if (IsTransformStream(transformStream) === false) {
  9416. throw new TypeError('TransformStreamDefaultController can only be ' + 'constructed with a TransformStream instance');
  9417. }
  9418. if (transformStream._transformStreamController !== undefined) {
  9419. throw new TypeError('TransformStreamDefaultController instances can ' + 'only be created by the TransformStream constructor');
  9420. }
  9421. this._controlledTransformStream = transformStream;
  9422. }
  9423. _createClass(TransformStreamDefaultController, [{
  9424. key: 'enqueue',
  9425. value: function enqueue(chunk) {
  9426. if (IsTransformStreamDefaultController(this) === false) {
  9427. throw defaultControllerBrandCheckException('enqueue');
  9428. }
  9429. TransformStreamEnqueueToReadable(this._controlledTransformStream, chunk);
  9430. }
  9431. }, {
  9432. key: 'close',
  9433. value: function close() {
  9434. if (IsTransformStreamDefaultController(this) === false) {
  9435. throw defaultControllerBrandCheckException('close');
  9436. }
  9437. TransformStreamCloseReadable(this._controlledTransformStream);
  9438. }
  9439. }, {
  9440. key: 'error',
  9441. value: function error(reason) {
  9442. if (IsTransformStreamDefaultController(this) === false) {
  9443. throw defaultControllerBrandCheckException('error');
  9444. }
  9445. TransformStreamError(this._controlledTransformStream, reason);
  9446. }
  9447. }, {
  9448. key: 'desiredSize',
  9449. get: function get() {
  9450. if (IsTransformStreamDefaultController(this) === false) {
  9451. throw defaultControllerBrandCheckException('desiredSize');
  9452. }
  9453. var transformStream = this._controlledTransformStream;
  9454. var readableController = transformStream._readableController;
  9455. return ReadableStreamDefaultControllerGetDesiredSize(readableController);
  9456. }
  9457. }]);
  9458. return TransformStreamDefaultController;
  9459. }();
  9460. var TransformStream = function () {
  9461. function TransformStream() {
  9462. var transformer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  9463. _classCallCheck(this, TransformStream);
  9464. this._transformer = transformer;
  9465. var readableStrategy = transformer.readableStrategy,
  9466. writableStrategy = transformer.writableStrategy;
  9467. this._transforming = false;
  9468. this._errored = false;
  9469. this._storedError = undefined;
  9470. this._writableController = undefined;
  9471. this._readableController = undefined;
  9472. this._transformStreamController = undefined;
  9473. this._writableDone = false;
  9474. this._readableClosed = false;
  9475. this._backpressure = undefined;
  9476. this._backpressureChangePromise = undefined;
  9477. this._backpressureChangePromise_resolve = undefined;
  9478. this._transformStreamController = new TransformStreamDefaultController(this);
  9479. var startPromise_resolve = void 0;
  9480. var startPromise = new Promise(function (resolve) {
  9481. startPromise_resolve = resolve;
  9482. });
  9483. var source = new TransformStreamSource(this, startPromise);
  9484. this._readable = new ReadableStream(source, readableStrategy);
  9485. var sink = new TransformStreamSink(this, startPromise);
  9486. this._writable = new WritableStream(sink, writableStrategy);
  9487. assert(this._writableController !== undefined);
  9488. assert(this._readableController !== undefined);
  9489. var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(this._readableController);
  9490. TransformStreamSetBackpressure(this, desiredSize <= 0);
  9491. var transformStream = this;
  9492. var startResult = InvokeOrNoop(transformer, 'start', [transformStream._transformStreamController]);
  9493. startPromise_resolve(startResult);
  9494. startPromise.catch(function (e) {
  9495. if (transformStream._errored === false) {
  9496. transformStream._errored = true;
  9497. transformStream._storedError = e;
  9498. }
  9499. });
  9500. }
  9501. _createClass(TransformStream, [{
  9502. key: 'readable',
  9503. get: function get() {
  9504. if (IsTransformStream(this) === false) {
  9505. throw streamBrandCheckException('readable');
  9506. }
  9507. return this._readable;
  9508. }
  9509. }, {
  9510. key: 'writable',
  9511. get: function get() {
  9512. if (IsTransformStream(this) === false) {
  9513. throw streamBrandCheckException('writable');
  9514. }
  9515. return this._writable;
  9516. }
  9517. }]);
  9518. return TransformStream;
  9519. }();
  9520. module.exports = { TransformStream: TransformStream };
  9521. function defaultControllerBrandCheckException(name) {
  9522. return new TypeError('TransformStreamDefaultController.prototype.' + name + ' can only be used on a TransformStreamDefaultController');
  9523. }
  9524. function streamBrandCheckException(name) {
  9525. return new TypeError('TransformStream.prototype.' + name + ' can only be used on a TransformStream');
  9526. }
  9527. }, function (module, exports, __w_pdfjs_require__) {
  9528. module.exports = __w_pdfjs_require__(5);
  9529. }]));
  9530. /***/ }),
  9531. /* 11 */
  9532. /***/ (function(module, exports, __w_pdfjs_require__) {
  9533. "use strict";
  9534. Object.defineProperty(exports, "__esModule", {
  9535. value: true
  9536. });
  9537. exports.CanvasGraphics = undefined;
  9538. var _util = __w_pdfjs_require__(0);
  9539. var _pattern_helper = __w_pdfjs_require__(13);
  9540. var _webgl = __w_pdfjs_require__(7);
  9541. var MIN_FONT_SIZE = 16;
  9542. var MAX_FONT_SIZE = 100;
  9543. var MAX_GROUP_SIZE = 4096;
  9544. var MIN_WIDTH_FACTOR = 0.65;
  9545. var COMPILE_TYPE3_GLYPHS = true;
  9546. var MAX_SIZE_TO_COMPILE = 1000;
  9547. var FULL_CHUNK_HEIGHT = 16;
  9548. var IsLittleEndianCached = {
  9549. get value() {
  9550. return (0, _util.shadow)(IsLittleEndianCached, 'value', (0, _util.isLittleEndian)());
  9551. }
  9552. };
  9553. function addContextCurrentTransform(ctx) {
  9554. if (!ctx.mozCurrentTransform) {
  9555. ctx._originalSave = ctx.save;
  9556. ctx._originalRestore = ctx.restore;
  9557. ctx._originalRotate = ctx.rotate;
  9558. ctx._originalScale = ctx.scale;
  9559. ctx._originalTranslate = ctx.translate;
  9560. ctx._originalTransform = ctx.transform;
  9561. ctx._originalSetTransform = ctx.setTransform;
  9562. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  9563. ctx._transformStack = [];
  9564. Object.defineProperty(ctx, 'mozCurrentTransform', {
  9565. get: function getCurrentTransform() {
  9566. return this._transformMatrix;
  9567. }
  9568. });
  9569. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  9570. get: function getCurrentTransformInverse() {
  9571. var m = this._transformMatrix;
  9572. var a = m[0],
  9573. b = m[1],
  9574. c = m[2],
  9575. d = m[3],
  9576. e = m[4],
  9577. f = m[5];
  9578. var ad_bc = a * d - b * c;
  9579. var bc_ad = b * c - a * d;
  9580. return [d / ad_bc, b / bc_ad, c / bc_ad, a / ad_bc, (d * e - c * f) / bc_ad, (b * e - a * f) / ad_bc];
  9581. }
  9582. });
  9583. ctx.save = function ctxSave() {
  9584. var old = this._transformMatrix;
  9585. this._transformStack.push(old);
  9586. this._transformMatrix = old.slice(0, 6);
  9587. this._originalSave();
  9588. };
  9589. ctx.restore = function ctxRestore() {
  9590. var prev = this._transformStack.pop();
  9591. if (prev) {
  9592. this._transformMatrix = prev;
  9593. this._originalRestore();
  9594. }
  9595. };
  9596. ctx.translate = function ctxTranslate(x, y) {
  9597. var m = this._transformMatrix;
  9598. m[4] = m[0] * x + m[2] * y + m[4];
  9599. m[5] = m[1] * x + m[3] * y + m[5];
  9600. this._originalTranslate(x, y);
  9601. };
  9602. ctx.scale = function ctxScale(x, y) {
  9603. var m = this._transformMatrix;
  9604. m[0] = m[0] * x;
  9605. m[1] = m[1] * x;
  9606. m[2] = m[2] * y;
  9607. m[3] = m[3] * y;
  9608. this._originalScale(x, y);
  9609. };
  9610. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  9611. var m = this._transformMatrix;
  9612. this._transformMatrix = [m[0] * a + m[2] * b, m[1] * a + m[3] * b, m[0] * c + m[2] * d, m[1] * c + m[3] * d, m[0] * e + m[2] * f + m[4], m[1] * e + m[3] * f + m[5]];
  9613. ctx._originalTransform(a, b, c, d, e, f);
  9614. };
  9615. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  9616. this._transformMatrix = [a, b, c, d, e, f];
  9617. ctx._originalSetTransform(a, b, c, d, e, f);
  9618. };
  9619. ctx.rotate = function ctxRotate(angle) {
  9620. var cosValue = Math.cos(angle);
  9621. var sinValue = Math.sin(angle);
  9622. var m = this._transformMatrix;
  9623. this._transformMatrix = [m[0] * cosValue + m[2] * sinValue, m[1] * cosValue + m[3] * sinValue, m[0] * -sinValue + m[2] * cosValue, m[1] * -sinValue + m[3] * cosValue, m[4], m[5]];
  9624. this._originalRotate(angle);
  9625. };
  9626. }
  9627. }
  9628. var CachedCanvases = function CachedCanvasesClosure() {
  9629. function CachedCanvases(canvasFactory) {
  9630. this.canvasFactory = canvasFactory;
  9631. this.cache = Object.create(null);
  9632. }
  9633. CachedCanvases.prototype = {
  9634. getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) {
  9635. var canvasEntry;
  9636. if (this.cache[id] !== undefined) {
  9637. canvasEntry = this.cache[id];
  9638. this.canvasFactory.reset(canvasEntry, width, height);
  9639. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  9640. } else {
  9641. canvasEntry = this.canvasFactory.create(width, height);
  9642. this.cache[id] = canvasEntry;
  9643. }
  9644. if (trackTransform) {
  9645. addContextCurrentTransform(canvasEntry.context);
  9646. }
  9647. return canvasEntry;
  9648. },
  9649. clear: function clear() {
  9650. for (var id in this.cache) {
  9651. var canvasEntry = this.cache[id];
  9652. this.canvasFactory.destroy(canvasEntry);
  9653. delete this.cache[id];
  9654. }
  9655. }
  9656. };
  9657. return CachedCanvases;
  9658. }();
  9659. function compileType3Glyph(imgData) {
  9660. var POINT_TO_PROCESS_LIMIT = 1000;
  9661. var width = imgData.width,
  9662. height = imgData.height;
  9663. var i,
  9664. j,
  9665. j0,
  9666. width1 = width + 1;
  9667. var points = new Uint8Array(width1 * (height + 1));
  9668. var POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  9669. var lineSize = width + 7 & ~7,
  9670. data0 = imgData.data;
  9671. var data = new Uint8Array(lineSize * height),
  9672. pos = 0,
  9673. ii;
  9674. for (i = 0, ii = data0.length; i < ii; i++) {
  9675. var mask = 128,
  9676. elem = data0[i];
  9677. while (mask > 0) {
  9678. data[pos++] = elem & mask ? 0 : 255;
  9679. mask >>= 1;
  9680. }
  9681. }
  9682. var count = 0;
  9683. pos = 0;
  9684. if (data[pos] !== 0) {
  9685. points[0] = 1;
  9686. ++count;
  9687. }
  9688. for (j = 1; j < width; j++) {
  9689. if (data[pos] !== data[pos + 1]) {
  9690. points[j] = data[pos] ? 2 : 1;
  9691. ++count;
  9692. }
  9693. pos++;
  9694. }
  9695. if (data[pos] !== 0) {
  9696. points[j] = 2;
  9697. ++count;
  9698. }
  9699. for (i = 1; i < height; i++) {
  9700. pos = i * lineSize;
  9701. j0 = i * width1;
  9702. if (data[pos - lineSize] !== data[pos]) {
  9703. points[j0] = data[pos] ? 1 : 8;
  9704. ++count;
  9705. }
  9706. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  9707. for (j = 1; j < width; j++) {
  9708. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  9709. if (POINT_TYPES[sum]) {
  9710. points[j0 + j] = POINT_TYPES[sum];
  9711. ++count;
  9712. }
  9713. pos++;
  9714. }
  9715. if (data[pos - lineSize] !== data[pos]) {
  9716. points[j0 + j] = data[pos] ? 2 : 4;
  9717. ++count;
  9718. }
  9719. if (count > POINT_TO_PROCESS_LIMIT) {
  9720. return null;
  9721. }
  9722. }
  9723. pos = lineSize * (height - 1);
  9724. j0 = i * width1;
  9725. if (data[pos] !== 0) {
  9726. points[j0] = 8;
  9727. ++count;
  9728. }
  9729. for (j = 1; j < width; j++) {
  9730. if (data[pos] !== data[pos + 1]) {
  9731. points[j0 + j] = data[pos] ? 4 : 8;
  9732. ++count;
  9733. }
  9734. pos++;
  9735. }
  9736. if (data[pos] !== 0) {
  9737. points[j0 + j] = 4;
  9738. ++count;
  9739. }
  9740. if (count > POINT_TO_PROCESS_LIMIT) {
  9741. return null;
  9742. }
  9743. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  9744. var outlines = [];
  9745. for (i = 0; count && i <= height; i++) {
  9746. var p = i * width1;
  9747. var end = p + width;
  9748. while (p < end && !points[p]) {
  9749. p++;
  9750. }
  9751. if (p === end) {
  9752. continue;
  9753. }
  9754. var coords = [p % width1, i];
  9755. var type = points[p],
  9756. p0 = p,
  9757. pp;
  9758. do {
  9759. var step = steps[type];
  9760. do {
  9761. p += step;
  9762. } while (!points[p]);
  9763. pp = points[p];
  9764. if (pp !== 5 && pp !== 10) {
  9765. type = pp;
  9766. points[p] = 0;
  9767. } else {
  9768. type = pp & 0x33 * type >> 4;
  9769. points[p] &= type >> 2 | type << 2;
  9770. }
  9771. coords.push(p % width1);
  9772. coords.push(p / width1 | 0);
  9773. --count;
  9774. } while (p0 !== p);
  9775. outlines.push(coords);
  9776. --i;
  9777. }
  9778. var drawOutline = function drawOutline(c) {
  9779. c.save();
  9780. c.scale(1 / width, -1 / height);
  9781. c.translate(0, -height);
  9782. c.beginPath();
  9783. for (var i = 0, ii = outlines.length; i < ii; i++) {
  9784. var o = outlines[i];
  9785. c.moveTo(o[0], o[1]);
  9786. for (var j = 2, jj = o.length; j < jj; j += 2) {
  9787. c.lineTo(o[j], o[j + 1]);
  9788. }
  9789. }
  9790. c.fill();
  9791. c.beginPath();
  9792. c.restore();
  9793. };
  9794. return drawOutline;
  9795. }
  9796. var CanvasExtraState = function CanvasExtraStateClosure() {
  9797. function CanvasExtraState() {
  9798. this.alphaIsShape = false;
  9799. this.fontSize = 0;
  9800. this.fontSizeScale = 1;
  9801. this.textMatrix = _util.IDENTITY_MATRIX;
  9802. this.textMatrixScale = 1;
  9803. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  9804. this.leading = 0;
  9805. this.x = 0;
  9806. this.y = 0;
  9807. this.lineX = 0;
  9808. this.lineY = 0;
  9809. this.charSpacing = 0;
  9810. this.wordSpacing = 0;
  9811. this.textHScale = 1;
  9812. this.textRenderingMode = _util.TextRenderingMode.FILL;
  9813. this.textRise = 0;
  9814. this.fillColor = '#000000';
  9815. this.strokeColor = '#000000';
  9816. this.patternFill = false;
  9817. this.fillAlpha = 1;
  9818. this.strokeAlpha = 1;
  9819. this.lineWidth = 1;
  9820. this.activeSMask = null;
  9821. this.resumeSMaskCtx = null;
  9822. }
  9823. CanvasExtraState.prototype = {
  9824. clone: function CanvasExtraState_clone() {
  9825. return Object.create(this);
  9826. },
  9827. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  9828. this.x = x;
  9829. this.y = y;
  9830. }
  9831. };
  9832. return CanvasExtraState;
  9833. }();
  9834. var CanvasGraphics = function CanvasGraphicsClosure() {
  9835. var EXECUTION_TIME = 15;
  9836. var EXECUTION_STEPS = 10;
  9837. function CanvasGraphics(canvasCtx, commonObjs, objs, canvasFactory, imageLayer) {
  9838. this.ctx = canvasCtx;
  9839. this.current = new CanvasExtraState();
  9840. this.stateStack = [];
  9841. this.pendingClip = null;
  9842. this.pendingEOFill = false;
  9843. this.res = null;
  9844. this.xobjs = null;
  9845. this.commonObjs = commonObjs;
  9846. this.objs = objs;
  9847. this.canvasFactory = canvasFactory;
  9848. this.imageLayer = imageLayer;
  9849. this.groupStack = [];
  9850. this.processingType3 = null;
  9851. this.baseTransform = null;
  9852. this.baseTransformStack = [];
  9853. this.groupLevel = 0;
  9854. this.smaskStack = [];
  9855. this.smaskCounter = 0;
  9856. this.tempSMask = null;
  9857. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  9858. if (canvasCtx) {
  9859. addContextCurrentTransform(canvasCtx);
  9860. }
  9861. this.cachedGetSinglePixelWidth = null;
  9862. }
  9863. function putBinaryImageData(ctx, imgData) {
  9864. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  9865. ctx.putImageData(imgData, 0, 0);
  9866. return;
  9867. }
  9868. var height = imgData.height,
  9869. width = imgData.width;
  9870. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  9871. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  9872. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  9873. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  9874. var srcPos = 0,
  9875. destPos;
  9876. var src = imgData.data;
  9877. var dest = chunkImgData.data;
  9878. var i, j, thisChunkHeight, elemsInThisChunk;
  9879. if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
  9880. var srcLength = src.byteLength;
  9881. var dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  9882. var dest32DataLength = dest32.length;
  9883. var fullSrcDiff = width + 7 >> 3;
  9884. var white = 0xFFFFFFFF;
  9885. var black = IsLittleEndianCached.value ? 0xFF000000 : 0x000000FF;
  9886. for (i = 0; i < totalChunks; i++) {
  9887. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  9888. destPos = 0;
  9889. for (j = 0; j < thisChunkHeight; j++) {
  9890. var srcDiff = srcLength - srcPos;
  9891. var k = 0;
  9892. var kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  9893. var kEndUnrolled = kEnd & ~7;
  9894. var mask = 0;
  9895. var srcByte = 0;
  9896. for (; k < kEndUnrolled; k += 8) {
  9897. srcByte = src[srcPos++];
  9898. dest32[destPos++] = srcByte & 128 ? white : black;
  9899. dest32[destPos++] = srcByte & 64 ? white : black;
  9900. dest32[destPos++] = srcByte & 32 ? white : black;
  9901. dest32[destPos++] = srcByte & 16 ? white : black;
  9902. dest32[destPos++] = srcByte & 8 ? white : black;
  9903. dest32[destPos++] = srcByte & 4 ? white : black;
  9904. dest32[destPos++] = srcByte & 2 ? white : black;
  9905. dest32[destPos++] = srcByte & 1 ? white : black;
  9906. }
  9907. for (; k < kEnd; k++) {
  9908. if (mask === 0) {
  9909. srcByte = src[srcPos++];
  9910. mask = 128;
  9911. }
  9912. dest32[destPos++] = srcByte & mask ? white : black;
  9913. mask >>= 1;
  9914. }
  9915. }
  9916. while (destPos < dest32DataLength) {
  9917. dest32[destPos++] = 0;
  9918. }
  9919. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  9920. }
  9921. } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
  9922. j = 0;
  9923. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  9924. for (i = 0; i < fullChunks; i++) {
  9925. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  9926. srcPos += elemsInThisChunk;
  9927. ctx.putImageData(chunkImgData, 0, j);
  9928. j += FULL_CHUNK_HEIGHT;
  9929. }
  9930. if (i < totalChunks) {
  9931. elemsInThisChunk = width * partialChunkHeight * 4;
  9932. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  9933. ctx.putImageData(chunkImgData, 0, j);
  9934. }
  9935. } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
  9936. thisChunkHeight = FULL_CHUNK_HEIGHT;
  9937. elemsInThisChunk = width * thisChunkHeight;
  9938. for (i = 0; i < totalChunks; i++) {
  9939. if (i >= fullChunks) {
  9940. thisChunkHeight = partialChunkHeight;
  9941. elemsInThisChunk = width * thisChunkHeight;
  9942. }
  9943. destPos = 0;
  9944. for (j = elemsInThisChunk; j--;) {
  9945. dest[destPos++] = src[srcPos++];
  9946. dest[destPos++] = src[srcPos++];
  9947. dest[destPos++] = src[srcPos++];
  9948. dest[destPos++] = 255;
  9949. }
  9950. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  9951. }
  9952. } else {
  9953. throw new Error('bad image kind: ' + imgData.kind);
  9954. }
  9955. }
  9956. function putBinaryImageMask(ctx, imgData) {
  9957. var height = imgData.height,
  9958. width = imgData.width;
  9959. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  9960. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  9961. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  9962. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  9963. var srcPos = 0;
  9964. var src = imgData.data;
  9965. var dest = chunkImgData.data;
  9966. for (var i = 0; i < totalChunks; i++) {
  9967. var thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  9968. var destPos = 3;
  9969. for (var j = 0; j < thisChunkHeight; j++) {
  9970. var mask = 0;
  9971. for (var k = 0; k < width; k++) {
  9972. if (!mask) {
  9973. var elem = src[srcPos++];
  9974. mask = 128;
  9975. }
  9976. dest[destPos] = elem & mask ? 0 : 255;
  9977. destPos += 4;
  9978. mask >>= 1;
  9979. }
  9980. }
  9981. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  9982. }
  9983. }
  9984. function copyCtxState(sourceCtx, destCtx) {
  9985. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha', 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit', 'globalCompositeOperation', 'font'];
  9986. for (var i = 0, ii = properties.length; i < ii; i++) {
  9987. var property = properties[i];
  9988. if (sourceCtx[property] !== undefined) {
  9989. destCtx[property] = sourceCtx[property];
  9990. }
  9991. }
  9992. if (sourceCtx.setLineDash !== undefined) {
  9993. destCtx.setLineDash(sourceCtx.getLineDash());
  9994. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  9995. }
  9996. }
  9997. function resetCtxToDefault(ctx) {
  9998. ctx.strokeStyle = '#000000';
  9999. ctx.fillStyle = '#000000';
  10000. ctx.fillRule = 'nonzero';
  10001. ctx.globalAlpha = 1;
  10002. ctx.lineWidth = 1;
  10003. ctx.lineCap = 'butt';
  10004. ctx.lineJoin = 'miter';
  10005. ctx.miterLimit = 10;
  10006. ctx.globalCompositeOperation = 'source-over';
  10007. ctx.font = '10px sans-serif';
  10008. if (ctx.setLineDash !== undefined) {
  10009. ctx.setLineDash([]);
  10010. ctx.lineDashOffset = 0;
  10011. }
  10012. }
  10013. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  10014. var length = bytes.length;
  10015. for (var i = 3; i < length; i += 4) {
  10016. var alpha = bytes[i];
  10017. if (alpha === 0) {
  10018. bytes[i - 3] = r0;
  10019. bytes[i - 2] = g0;
  10020. bytes[i - 1] = b0;
  10021. } else if (alpha < 255) {
  10022. var alpha_ = 255 - alpha;
  10023. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  10024. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  10025. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  10026. }
  10027. }
  10028. }
  10029. function composeSMaskAlpha(maskData, layerData, transferMap) {
  10030. var length = maskData.length;
  10031. var scale = 1 / 255;
  10032. for (var i = 3; i < length; i += 4) {
  10033. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  10034. layerData[i] = layerData[i] * alpha * scale | 0;
  10035. }
  10036. }
  10037. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  10038. var length = maskData.length;
  10039. for (var i = 3; i < length; i += 4) {
  10040. var y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
  10041. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  10042. }
  10043. }
  10044. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap) {
  10045. var hasBackdrop = !!backdrop;
  10046. var r0 = hasBackdrop ? backdrop[0] : 0;
  10047. var g0 = hasBackdrop ? backdrop[1] : 0;
  10048. var b0 = hasBackdrop ? backdrop[2] : 0;
  10049. var composeFn;
  10050. if (subtype === 'Luminosity') {
  10051. composeFn = composeSMaskLuminosity;
  10052. } else {
  10053. composeFn = composeSMaskAlpha;
  10054. }
  10055. var PIXELS_TO_PROCESS = 1048576;
  10056. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  10057. for (var row = 0; row < height; row += chunkSize) {
  10058. var chunkHeight = Math.min(chunkSize, height - row);
  10059. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  10060. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  10061. if (hasBackdrop) {
  10062. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  10063. }
  10064. composeFn(maskData.data, layerData.data, transferMap);
  10065. maskCtx.putImageData(layerData, 0, row);
  10066. }
  10067. }
  10068. function composeSMask(ctx, smask, layerCtx) {
  10069. var mask = smask.canvas;
  10070. var maskCtx = smask.context;
  10071. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY, smask.offsetX, smask.offsetY);
  10072. var backdrop = smask.backdrop || null;
  10073. if (!smask.transferMap && _webgl.WebGLUtils.isEnabled) {
  10074. var composed = _webgl.WebGLUtils.composeSMask(layerCtx.canvas, mask, {
  10075. subtype: smask.subtype,
  10076. backdrop: backdrop
  10077. });
  10078. ctx.setTransform(1, 0, 0, 1, 0, 0);
  10079. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  10080. return;
  10081. }
  10082. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height, smask.subtype, backdrop, smask.transferMap);
  10083. ctx.drawImage(mask, 0, 0);
  10084. }
  10085. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  10086. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  10087. var NORMAL_CLIP = {};
  10088. var EO_CLIP = {};
  10089. CanvasGraphics.prototype = {
  10090. beginDrawing: function beginDrawing(_ref) {
  10091. var transform = _ref.transform,
  10092. viewport = _ref.viewport,
  10093. transparency = _ref.transparency,
  10094. _ref$background = _ref.background,
  10095. background = _ref$background === undefined ? null : _ref$background;
  10096. var width = this.ctx.canvas.width;
  10097. var height = this.ctx.canvas.height;
  10098. this.ctx.save();
  10099. this.ctx.fillStyle = background || 'rgb(255, 255, 255)';
  10100. this.ctx.fillRect(0, 0, width, height);
  10101. this.ctx.restore();
  10102. if (transparency) {
  10103. var transparentCanvas = this.cachedCanvases.getCanvas('transparent', width, height, true);
  10104. this.compositeCtx = this.ctx;
  10105. this.transparentCanvas = transparentCanvas.canvas;
  10106. this.ctx = transparentCanvas.context;
  10107. this.ctx.save();
  10108. this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
  10109. }
  10110. this.ctx.save();
  10111. resetCtxToDefault(this.ctx);
  10112. if (transform) {
  10113. this.ctx.transform.apply(this.ctx, transform);
  10114. }
  10115. this.ctx.transform.apply(this.ctx, viewport.transform);
  10116. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  10117. if (this.imageLayer) {
  10118. this.imageLayer.beginLayout();
  10119. }
  10120. },
  10121. executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  10122. var argsArray = operatorList.argsArray;
  10123. var fnArray = operatorList.fnArray;
  10124. var i = executionStartIdx || 0;
  10125. var argsArrayLen = argsArray.length;
  10126. if (argsArrayLen === i) {
  10127. return i;
  10128. }
  10129. var chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === 'function';
  10130. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  10131. var steps = 0;
  10132. var commonObjs = this.commonObjs;
  10133. var objs = this.objs;
  10134. var fnId;
  10135. while (true) {
  10136. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  10137. stepper.breakIt(i, continueCallback);
  10138. return i;
  10139. }
  10140. fnId = fnArray[i];
  10141. if (fnId !== _util.OPS.dependency) {
  10142. this[fnId].apply(this, argsArray[i]);
  10143. } else {
  10144. var deps = argsArray[i];
  10145. for (var n = 0, nn = deps.length; n < nn; n++) {
  10146. var depObjId = deps[n];
  10147. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  10148. var objsPool = common ? commonObjs : objs;
  10149. if (!objsPool.isResolved(depObjId)) {
  10150. objsPool.get(depObjId, continueCallback);
  10151. return i;
  10152. }
  10153. }
  10154. }
  10155. i++;
  10156. if (i === argsArrayLen) {
  10157. return i;
  10158. }
  10159. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  10160. if (Date.now() > endTime) {
  10161. continueCallback();
  10162. return i;
  10163. }
  10164. steps = 0;
  10165. }
  10166. }
  10167. },
  10168. endDrawing: function CanvasGraphics_endDrawing() {
  10169. if (this.current.activeSMask !== null) {
  10170. this.endSMaskGroup();
  10171. }
  10172. this.ctx.restore();
  10173. if (this.transparentCanvas) {
  10174. this.ctx = this.compositeCtx;
  10175. this.ctx.save();
  10176. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  10177. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  10178. this.ctx.restore();
  10179. this.transparentCanvas = null;
  10180. }
  10181. this.cachedCanvases.clear();
  10182. _webgl.WebGLUtils.clear();
  10183. if (this.imageLayer) {
  10184. this.imageLayer.endLayout();
  10185. }
  10186. },
  10187. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  10188. this.current.lineWidth = width;
  10189. this.ctx.lineWidth = width;
  10190. },
  10191. setLineCap: function CanvasGraphics_setLineCap(style) {
  10192. this.ctx.lineCap = LINE_CAP_STYLES[style];
  10193. },
  10194. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  10195. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  10196. },
  10197. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  10198. this.ctx.miterLimit = limit;
  10199. },
  10200. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  10201. var ctx = this.ctx;
  10202. if (ctx.setLineDash !== undefined) {
  10203. ctx.setLineDash(dashArray);
  10204. ctx.lineDashOffset = dashPhase;
  10205. }
  10206. },
  10207. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {},
  10208. setFlatness: function CanvasGraphics_setFlatness(flatness) {},
  10209. setGState: function CanvasGraphics_setGState(states) {
  10210. for (var i = 0, ii = states.length; i < ii; i++) {
  10211. var state = states[i];
  10212. var key = state[0];
  10213. var value = state[1];
  10214. switch (key) {
  10215. case 'LW':
  10216. this.setLineWidth(value);
  10217. break;
  10218. case 'LC':
  10219. this.setLineCap(value);
  10220. break;
  10221. case 'LJ':
  10222. this.setLineJoin(value);
  10223. break;
  10224. case 'ML':
  10225. this.setMiterLimit(value);
  10226. break;
  10227. case 'D':
  10228. this.setDash(value[0], value[1]);
  10229. break;
  10230. case 'RI':
  10231. this.setRenderingIntent(value);
  10232. break;
  10233. case 'FL':
  10234. this.setFlatness(value);
  10235. break;
  10236. case 'Font':
  10237. this.setFont(value[0], value[1]);
  10238. break;
  10239. case 'CA':
  10240. this.current.strokeAlpha = state[1];
  10241. break;
  10242. case 'ca':
  10243. this.current.fillAlpha = state[1];
  10244. this.ctx.globalAlpha = state[1];
  10245. break;
  10246. case 'BM':
  10247. this.ctx.globalCompositeOperation = value;
  10248. break;
  10249. case 'SMask':
  10250. if (this.current.activeSMask) {
  10251. if (this.stateStack.length > 0 && this.stateStack[this.stateStack.length - 1].activeSMask === this.current.activeSMask) {
  10252. this.suspendSMaskGroup();
  10253. } else {
  10254. this.endSMaskGroup();
  10255. }
  10256. }
  10257. this.current.activeSMask = value ? this.tempSMask : null;
  10258. if (this.current.activeSMask) {
  10259. this.beginSMaskGroup();
  10260. }
  10261. this.tempSMask = null;
  10262. break;
  10263. }
  10264. }
  10265. },
  10266. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  10267. var activeSMask = this.current.activeSMask;
  10268. var drawnWidth = activeSMask.canvas.width;
  10269. var drawnHeight = activeSMask.canvas.height;
  10270. var cacheId = 'smaskGroupAt' + this.groupLevel;
  10271. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  10272. var currentCtx = this.ctx;
  10273. var currentTransform = currentCtx.mozCurrentTransform;
  10274. this.ctx.save();
  10275. var groupCtx = scratchCanvas.context;
  10276. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  10277. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  10278. groupCtx.transform.apply(groupCtx, currentTransform);
  10279. activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse;
  10280. copyCtxState(currentCtx, groupCtx);
  10281. this.ctx = groupCtx;
  10282. this.setGState([['BM', 'source-over'], ['ca', 1], ['CA', 1]]);
  10283. this.groupStack.push(currentCtx);
  10284. this.groupLevel++;
  10285. },
  10286. suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  10287. var groupCtx = this.ctx;
  10288. this.groupLevel--;
  10289. this.ctx = this.groupStack.pop();
  10290. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  10291. this.ctx.restore();
  10292. this.ctx.save();
  10293. copyCtxState(groupCtx, this.ctx);
  10294. this.current.resumeSMaskCtx = groupCtx;
  10295. var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  10296. this.ctx.transform.apply(this.ctx, deltaTransform);
  10297. groupCtx.save();
  10298. groupCtx.setTransform(1, 0, 0, 1, 0, 0);
  10299. groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
  10300. groupCtx.restore();
  10301. },
  10302. resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  10303. var groupCtx = this.current.resumeSMaskCtx;
  10304. var currentCtx = this.ctx;
  10305. this.ctx = groupCtx;
  10306. this.groupStack.push(currentCtx);
  10307. this.groupLevel++;
  10308. },
  10309. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  10310. var groupCtx = this.ctx;
  10311. this.groupLevel--;
  10312. this.ctx = this.groupStack.pop();
  10313. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  10314. this.ctx.restore();
  10315. copyCtxState(groupCtx, this.ctx);
  10316. var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  10317. this.ctx.transform.apply(this.ctx, deltaTransform);
  10318. },
  10319. save: function CanvasGraphics_save() {
  10320. this.ctx.save();
  10321. var old = this.current;
  10322. this.stateStack.push(old);
  10323. this.current = old.clone();
  10324. this.current.resumeSMaskCtx = null;
  10325. },
  10326. restore: function CanvasGraphics_restore() {
  10327. if (this.current.resumeSMaskCtx) {
  10328. this.resumeSMaskGroup();
  10329. }
  10330. if (this.current.activeSMask !== null && (this.stateStack.length === 0 || this.stateStack[this.stateStack.length - 1].activeSMask !== this.current.activeSMask)) {
  10331. this.endSMaskGroup();
  10332. }
  10333. if (this.stateStack.length !== 0) {
  10334. this.current = this.stateStack.pop();
  10335. this.ctx.restore();
  10336. this.pendingClip = null;
  10337. this.cachedGetSinglePixelWidth = null;
  10338. }
  10339. },
  10340. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  10341. this.ctx.transform(a, b, c, d, e, f);
  10342. this.cachedGetSinglePixelWidth = null;
  10343. },
  10344. constructPath: function CanvasGraphics_constructPath(ops, args) {
  10345. var ctx = this.ctx;
  10346. var current = this.current;
  10347. var x = current.x,
  10348. y = current.y;
  10349. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  10350. switch (ops[i] | 0) {
  10351. case _util.OPS.rectangle:
  10352. x = args[j++];
  10353. y = args[j++];
  10354. var width = args[j++];
  10355. var height = args[j++];
  10356. if (width === 0) {
  10357. width = this.getSinglePixelWidth();
  10358. }
  10359. if (height === 0) {
  10360. height = this.getSinglePixelWidth();
  10361. }
  10362. var xw = x + width;
  10363. var yh = y + height;
  10364. this.ctx.moveTo(x, y);
  10365. this.ctx.lineTo(xw, y);
  10366. this.ctx.lineTo(xw, yh);
  10367. this.ctx.lineTo(x, yh);
  10368. this.ctx.lineTo(x, y);
  10369. this.ctx.closePath();
  10370. break;
  10371. case _util.OPS.moveTo:
  10372. x = args[j++];
  10373. y = args[j++];
  10374. ctx.moveTo(x, y);
  10375. break;
  10376. case _util.OPS.lineTo:
  10377. x = args[j++];
  10378. y = args[j++];
  10379. ctx.lineTo(x, y);
  10380. break;
  10381. case _util.OPS.curveTo:
  10382. x = args[j + 4];
  10383. y = args[j + 5];
  10384. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  10385. j += 6;
  10386. break;
  10387. case _util.OPS.curveTo2:
  10388. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  10389. x = args[j + 2];
  10390. y = args[j + 3];
  10391. j += 4;
  10392. break;
  10393. case _util.OPS.curveTo3:
  10394. x = args[j + 2];
  10395. y = args[j + 3];
  10396. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  10397. j += 4;
  10398. break;
  10399. case _util.OPS.closePath:
  10400. ctx.closePath();
  10401. break;
  10402. }
  10403. }
  10404. current.setCurrentPoint(x, y);
  10405. },
  10406. closePath: function CanvasGraphics_closePath() {
  10407. this.ctx.closePath();
  10408. },
  10409. stroke: function CanvasGraphics_stroke(consumePath) {
  10410. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  10411. var ctx = this.ctx;
  10412. var strokeColor = this.current.strokeColor;
  10413. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth);
  10414. ctx.globalAlpha = this.current.strokeAlpha;
  10415. if (strokeColor && strokeColor.hasOwnProperty('type') && strokeColor.type === 'Pattern') {
  10416. ctx.save();
  10417. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  10418. ctx.stroke();
  10419. ctx.restore();
  10420. } else {
  10421. ctx.stroke();
  10422. }
  10423. if (consumePath) {
  10424. this.consumePath();
  10425. }
  10426. ctx.globalAlpha = this.current.fillAlpha;
  10427. },
  10428. closeStroke: function CanvasGraphics_closeStroke() {
  10429. this.closePath();
  10430. this.stroke();
  10431. },
  10432. fill: function CanvasGraphics_fill(consumePath) {
  10433. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  10434. var ctx = this.ctx;
  10435. var fillColor = this.current.fillColor;
  10436. var isPatternFill = this.current.patternFill;
  10437. var needRestore = false;
  10438. if (isPatternFill) {
  10439. ctx.save();
  10440. if (this.baseTransform) {
  10441. ctx.setTransform.apply(ctx, this.baseTransform);
  10442. }
  10443. ctx.fillStyle = fillColor.getPattern(ctx, this);
  10444. needRestore = true;
  10445. }
  10446. if (this.pendingEOFill) {
  10447. ctx.fill('evenodd');
  10448. this.pendingEOFill = false;
  10449. } else {
  10450. ctx.fill();
  10451. }
  10452. if (needRestore) {
  10453. ctx.restore();
  10454. }
  10455. if (consumePath) {
  10456. this.consumePath();
  10457. }
  10458. },
  10459. eoFill: function CanvasGraphics_eoFill() {
  10460. this.pendingEOFill = true;
  10461. this.fill();
  10462. },
  10463. fillStroke: function CanvasGraphics_fillStroke() {
  10464. this.fill(false);
  10465. this.stroke(false);
  10466. this.consumePath();
  10467. },
  10468. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  10469. this.pendingEOFill = true;
  10470. this.fillStroke();
  10471. },
  10472. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  10473. this.closePath();
  10474. this.fillStroke();
  10475. },
  10476. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  10477. this.pendingEOFill = true;
  10478. this.closePath();
  10479. this.fillStroke();
  10480. },
  10481. endPath: function CanvasGraphics_endPath() {
  10482. this.consumePath();
  10483. },
  10484. clip: function CanvasGraphics_clip() {
  10485. this.pendingClip = NORMAL_CLIP;
  10486. },
  10487. eoClip: function CanvasGraphics_eoClip() {
  10488. this.pendingClip = EO_CLIP;
  10489. },
  10490. beginText: function CanvasGraphics_beginText() {
  10491. this.current.textMatrix = _util.IDENTITY_MATRIX;
  10492. this.current.textMatrixScale = 1;
  10493. this.current.x = this.current.lineX = 0;
  10494. this.current.y = this.current.lineY = 0;
  10495. },
  10496. endText: function CanvasGraphics_endText() {
  10497. var paths = this.pendingTextPaths;
  10498. var ctx = this.ctx;
  10499. if (paths === undefined) {
  10500. ctx.beginPath();
  10501. return;
  10502. }
  10503. ctx.save();
  10504. ctx.beginPath();
  10505. for (var i = 0; i < paths.length; i++) {
  10506. var path = paths[i];
  10507. ctx.setTransform.apply(ctx, path.transform);
  10508. ctx.translate(path.x, path.y);
  10509. path.addToPath(ctx, path.fontSize);
  10510. }
  10511. ctx.restore();
  10512. ctx.clip();
  10513. ctx.beginPath();
  10514. delete this.pendingTextPaths;
  10515. },
  10516. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  10517. this.current.charSpacing = spacing;
  10518. },
  10519. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  10520. this.current.wordSpacing = spacing;
  10521. },
  10522. setHScale: function CanvasGraphics_setHScale(scale) {
  10523. this.current.textHScale = scale / 100;
  10524. },
  10525. setLeading: function CanvasGraphics_setLeading(leading) {
  10526. this.current.leading = -leading;
  10527. },
  10528. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  10529. var fontObj = this.commonObjs.get(fontRefName);
  10530. var current = this.current;
  10531. if (!fontObj) {
  10532. throw new Error('Can\'t find font for ' + fontRefName);
  10533. }
  10534. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
  10535. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  10536. (0, _util.warn)('Invalid font matrix for font ' + fontRefName);
  10537. }
  10538. if (size < 0) {
  10539. size = -size;
  10540. current.fontDirection = -1;
  10541. } else {
  10542. current.fontDirection = 1;
  10543. }
  10544. this.current.font = fontObj;
  10545. this.current.fontSize = size;
  10546. if (fontObj.isType3Font) {
  10547. return;
  10548. }
  10549. var name = fontObj.loadedName || 'sans-serif';
  10550. var bold = fontObj.black ? '900' : fontObj.bold ? 'bold' : 'normal';
  10551. var italic = fontObj.italic ? 'italic' : 'normal';
  10552. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  10553. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE : size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  10554. this.current.fontSizeScale = size / browserFontSize;
  10555. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  10556. this.ctx.font = rule;
  10557. },
  10558. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  10559. this.current.textRenderingMode = mode;
  10560. },
  10561. setTextRise: function CanvasGraphics_setTextRise(rise) {
  10562. this.current.textRise = rise;
  10563. },
  10564. moveText: function CanvasGraphics_moveText(x, y) {
  10565. this.current.x = this.current.lineX += x;
  10566. this.current.y = this.current.lineY += y;
  10567. },
  10568. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  10569. this.setLeading(-y);
  10570. this.moveText(x, y);
  10571. },
  10572. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  10573. this.current.textMatrix = [a, b, c, d, e, f];
  10574. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  10575. this.current.x = this.current.lineX = 0;
  10576. this.current.y = this.current.lineY = 0;
  10577. },
  10578. nextLine: function CanvasGraphics_nextLine() {
  10579. this.moveText(0, this.current.leading);
  10580. },
  10581. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  10582. var ctx = this.ctx;
  10583. var current = this.current;
  10584. var font = current.font;
  10585. var textRenderingMode = current.textRenderingMode;
  10586. var fontSize = current.fontSize / current.fontSizeScale;
  10587. var fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  10588. var isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
  10589. var addToPath;
  10590. if (font.disableFontFace || isAddToPathSet) {
  10591. addToPath = font.getPathGenerator(this.commonObjs, character);
  10592. }
  10593. if (font.disableFontFace) {
  10594. ctx.save();
  10595. ctx.translate(x, y);
  10596. ctx.beginPath();
  10597. addToPath(ctx, fontSize);
  10598. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10599. ctx.fill();
  10600. }
  10601. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10602. ctx.stroke();
  10603. }
  10604. ctx.restore();
  10605. } else {
  10606. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10607. ctx.fillText(character, x, y);
  10608. }
  10609. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10610. ctx.strokeText(character, x, y);
  10611. }
  10612. }
  10613. if (isAddToPathSet) {
  10614. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  10615. paths.push({
  10616. transform: ctx.mozCurrentTransform,
  10617. x: x,
  10618. y: y,
  10619. fontSize: fontSize,
  10620. addToPath: addToPath
  10621. });
  10622. }
  10623. },
  10624. get isFontSubpixelAAEnabled() {
  10625. var ctx = this.canvasFactory.create(10, 10).context;
  10626. ctx.scale(1.5, 1);
  10627. ctx.fillText('I', 0, 10);
  10628. var data = ctx.getImageData(0, 0, 10, 10).data;
  10629. var enabled = false;
  10630. for (var i = 3; i < data.length; i += 4) {
  10631. if (data[i] > 0 && data[i] < 255) {
  10632. enabled = true;
  10633. break;
  10634. }
  10635. }
  10636. return (0, _util.shadow)(this, 'isFontSubpixelAAEnabled', enabled);
  10637. },
  10638. showText: function CanvasGraphics_showText(glyphs) {
  10639. var current = this.current;
  10640. var font = current.font;
  10641. if (font.isType3Font) {
  10642. return this.showType3Text(glyphs);
  10643. }
  10644. var fontSize = current.fontSize;
  10645. if (fontSize === 0) {
  10646. return;
  10647. }
  10648. var ctx = this.ctx;
  10649. var fontSizeScale = current.fontSizeScale;
  10650. var charSpacing = current.charSpacing;
  10651. var wordSpacing = current.wordSpacing;
  10652. var fontDirection = current.fontDirection;
  10653. var textHScale = current.textHScale * fontDirection;
  10654. var glyphsLength = glyphs.length;
  10655. var vertical = font.vertical;
  10656. var spacingDir = vertical ? 1 : -1;
  10657. var defaultVMetrics = font.defaultVMetrics;
  10658. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  10659. var simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace;
  10660. ctx.save();
  10661. ctx.transform.apply(ctx, current.textMatrix);
  10662. ctx.translate(current.x, current.y + current.textRise);
  10663. if (current.patternFill) {
  10664. ctx.fillStyle = current.fillColor.getPattern(ctx, this);
  10665. }
  10666. if (fontDirection > 0) {
  10667. ctx.scale(textHScale, -1);
  10668. } else {
  10669. ctx.scale(textHScale, 1);
  10670. }
  10671. var lineWidth = current.lineWidth;
  10672. var scale = current.textMatrixScale;
  10673. if (scale === 0 || lineWidth === 0) {
  10674. var fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  10675. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10676. this.cachedGetSinglePixelWidth = null;
  10677. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  10678. }
  10679. } else {
  10680. lineWidth /= scale;
  10681. }
  10682. if (fontSizeScale !== 1.0) {
  10683. ctx.scale(fontSizeScale, fontSizeScale);
  10684. lineWidth /= fontSizeScale;
  10685. }
  10686. ctx.lineWidth = lineWidth;
  10687. var x = 0,
  10688. i;
  10689. for (i = 0; i < glyphsLength; ++i) {
  10690. var glyph = glyphs[i];
  10691. if ((0, _util.isNum)(glyph)) {
  10692. x += spacingDir * glyph * fontSize / 1000;
  10693. continue;
  10694. }
  10695. var restoreNeeded = false;
  10696. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  10697. var character = glyph.fontChar;
  10698. var accent = glyph.accent;
  10699. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  10700. var width = glyph.width;
  10701. if (vertical) {
  10702. var vmetric, vx, vy;
  10703. vmetric = glyph.vmetric || defaultVMetrics;
  10704. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  10705. vx = -vx * widthAdvanceScale;
  10706. vy = vmetric[2] * widthAdvanceScale;
  10707. width = vmetric ? -vmetric[0] : width;
  10708. scaledX = vx / fontSizeScale;
  10709. scaledY = (x + vy) / fontSizeScale;
  10710. } else {
  10711. scaledX = x / fontSizeScale;
  10712. scaledY = 0;
  10713. }
  10714. if (font.remeasure && width > 0) {
  10715. var measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  10716. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  10717. var characterScaleX = width / measuredWidth;
  10718. restoreNeeded = true;
  10719. ctx.save();
  10720. ctx.scale(characterScaleX, 1);
  10721. scaledX /= characterScaleX;
  10722. } else if (width !== measuredWidth) {
  10723. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  10724. }
  10725. }
  10726. if (glyph.isInFont || font.missingFile) {
  10727. if (simpleFillText && !accent) {
  10728. ctx.fillText(character, scaledX, scaledY);
  10729. } else {
  10730. this.paintChar(character, scaledX, scaledY);
  10731. if (accent) {
  10732. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  10733. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  10734. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  10735. }
  10736. }
  10737. }
  10738. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  10739. x += charWidth;
  10740. if (restoreNeeded) {
  10741. ctx.restore();
  10742. }
  10743. }
  10744. if (vertical) {
  10745. current.y -= x * textHScale;
  10746. } else {
  10747. current.x += x * textHScale;
  10748. }
  10749. ctx.restore();
  10750. },
  10751. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  10752. var ctx = this.ctx;
  10753. var current = this.current;
  10754. var font = current.font;
  10755. var fontSize = current.fontSize;
  10756. var fontDirection = current.fontDirection;
  10757. var spacingDir = font.vertical ? 1 : -1;
  10758. var charSpacing = current.charSpacing;
  10759. var wordSpacing = current.wordSpacing;
  10760. var textHScale = current.textHScale * fontDirection;
  10761. var fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  10762. var glyphsLength = glyphs.length;
  10763. var isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
  10764. var i, glyph, width, spacingLength;
  10765. if (isTextInvisible || fontSize === 0) {
  10766. return;
  10767. }
  10768. this.cachedGetSinglePixelWidth = null;
  10769. ctx.save();
  10770. ctx.transform.apply(ctx, current.textMatrix);
  10771. ctx.translate(current.x, current.y);
  10772. ctx.scale(textHScale, fontDirection);
  10773. for (i = 0; i < glyphsLength; ++i) {
  10774. glyph = glyphs[i];
  10775. if ((0, _util.isNum)(glyph)) {
  10776. spacingLength = spacingDir * glyph * fontSize / 1000;
  10777. this.ctx.translate(spacingLength, 0);
  10778. current.x += spacingLength * textHScale;
  10779. continue;
  10780. }
  10781. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  10782. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  10783. if (!operatorList) {
  10784. (0, _util.warn)('Type3 character "' + glyph.operatorListId + '" is not available.');
  10785. continue;
  10786. }
  10787. this.processingType3 = glyph;
  10788. this.save();
  10789. ctx.scale(fontSize, fontSize);
  10790. ctx.transform.apply(ctx, fontMatrix);
  10791. this.executeOperatorList(operatorList);
  10792. this.restore();
  10793. var transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
  10794. width = transformed[0] * fontSize + spacing;
  10795. ctx.translate(width, 0);
  10796. current.x += width * textHScale;
  10797. }
  10798. ctx.restore();
  10799. this.processingType3 = null;
  10800. },
  10801. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {},
  10802. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  10803. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  10804. this.clip();
  10805. this.endPath();
  10806. },
  10807. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  10808. var _this = this;
  10809. var pattern;
  10810. if (IR[0] === 'TilingPattern') {
  10811. var color = IR[1];
  10812. var baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
  10813. var canvasGraphicsFactory = {
  10814. createCanvasGraphics: function createCanvasGraphics(ctx) {
  10815. return new CanvasGraphics(ctx, _this.commonObjs, _this.objs, _this.canvasFactory);
  10816. }
  10817. };
  10818. pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  10819. } else {
  10820. pattern = (0, _pattern_helper.getShadingPatternFromIR)(IR);
  10821. }
  10822. return pattern;
  10823. },
  10824. setStrokeColorN: function CanvasGraphics_setStrokeColorN() {
  10825. this.current.strokeColor = this.getColorN_Pattern(arguments);
  10826. },
  10827. setFillColorN: function CanvasGraphics_setFillColorN() {
  10828. this.current.fillColor = this.getColorN_Pattern(arguments);
  10829. this.current.patternFill = true;
  10830. },
  10831. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  10832. var color = _util.Util.makeCssRgb(r, g, b);
  10833. this.ctx.strokeStyle = color;
  10834. this.current.strokeColor = color;
  10835. },
  10836. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  10837. var color = _util.Util.makeCssRgb(r, g, b);
  10838. this.ctx.fillStyle = color;
  10839. this.current.fillColor = color;
  10840. this.current.patternFill = false;
  10841. },
  10842. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  10843. var ctx = this.ctx;
  10844. this.save();
  10845. var pattern = (0, _pattern_helper.getShadingPatternFromIR)(patternIR);
  10846. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  10847. var inv = ctx.mozCurrentTransformInverse;
  10848. if (inv) {
  10849. var canvas = ctx.canvas;
  10850. var width = canvas.width;
  10851. var height = canvas.height;
  10852. var bl = _util.Util.applyTransform([0, 0], inv);
  10853. var br = _util.Util.applyTransform([0, height], inv);
  10854. var ul = _util.Util.applyTransform([width, 0], inv);
  10855. var ur = _util.Util.applyTransform([width, height], inv);
  10856. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  10857. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  10858. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  10859. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  10860. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  10861. } else {
  10862. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  10863. }
  10864. this.restore();
  10865. },
  10866. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  10867. throw new Error('Should not call beginInlineImage');
  10868. },
  10869. beginImageData: function CanvasGraphics_beginImageData() {
  10870. throw new Error('Should not call beginImageData');
  10871. },
  10872. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, bbox) {
  10873. this.save();
  10874. this.baseTransformStack.push(this.baseTransform);
  10875. if ((0, _util.isArray)(matrix) && matrix.length === 6) {
  10876. this.transform.apply(this, matrix);
  10877. }
  10878. this.baseTransform = this.ctx.mozCurrentTransform;
  10879. if ((0, _util.isArray)(bbox) && bbox.length === 4) {
  10880. var width = bbox[2] - bbox[0];
  10881. var height = bbox[3] - bbox[1];
  10882. this.ctx.rect(bbox[0], bbox[1], width, height);
  10883. this.clip();
  10884. this.endPath();
  10885. }
  10886. },
  10887. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  10888. this.restore();
  10889. this.baseTransform = this.baseTransformStack.pop();
  10890. },
  10891. beginGroup: function CanvasGraphics_beginGroup(group) {
  10892. this.save();
  10893. var currentCtx = this.ctx;
  10894. if (!group.isolated) {
  10895. (0, _util.info)('TODO: Support non-isolated groups.');
  10896. }
  10897. if (group.knockout) {
  10898. (0, _util.warn)('Knockout groups not supported.');
  10899. }
  10900. var currentTransform = currentCtx.mozCurrentTransform;
  10901. if (group.matrix) {
  10902. currentCtx.transform.apply(currentCtx, group.matrix);
  10903. }
  10904. if (!group.bbox) {
  10905. throw new Error('Bounding box is required.');
  10906. }
  10907. var bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
  10908. var canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  10909. bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  10910. var offsetX = Math.floor(bounds[0]);
  10911. var offsetY = Math.floor(bounds[1]);
  10912. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  10913. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  10914. var scaleX = 1,
  10915. scaleY = 1;
  10916. if (drawnWidth > MAX_GROUP_SIZE) {
  10917. scaleX = drawnWidth / MAX_GROUP_SIZE;
  10918. drawnWidth = MAX_GROUP_SIZE;
  10919. }
  10920. if (drawnHeight > MAX_GROUP_SIZE) {
  10921. scaleY = drawnHeight / MAX_GROUP_SIZE;
  10922. drawnHeight = MAX_GROUP_SIZE;
  10923. }
  10924. var cacheId = 'groupAt' + this.groupLevel;
  10925. if (group.smask) {
  10926. cacheId += '_smask_' + this.smaskCounter++ % 2;
  10927. }
  10928. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  10929. var groupCtx = scratchCanvas.context;
  10930. groupCtx.scale(1 / scaleX, 1 / scaleY);
  10931. groupCtx.translate(-offsetX, -offsetY);
  10932. groupCtx.transform.apply(groupCtx, currentTransform);
  10933. if (group.smask) {
  10934. this.smaskStack.push({
  10935. canvas: scratchCanvas.canvas,
  10936. context: groupCtx,
  10937. offsetX: offsetX,
  10938. offsetY: offsetY,
  10939. scaleX: scaleX,
  10940. scaleY: scaleY,
  10941. subtype: group.smask.subtype,
  10942. backdrop: group.smask.backdrop,
  10943. transferMap: group.smask.transferMap || null,
  10944. startTransformInverse: null
  10945. });
  10946. } else {
  10947. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  10948. currentCtx.translate(offsetX, offsetY);
  10949. currentCtx.scale(scaleX, scaleY);
  10950. }
  10951. copyCtxState(currentCtx, groupCtx);
  10952. this.ctx = groupCtx;
  10953. this.setGState([['BM', 'source-over'], ['ca', 1], ['CA', 1]]);
  10954. this.groupStack.push(currentCtx);
  10955. this.groupLevel++;
  10956. this.current.activeSMask = null;
  10957. },
  10958. endGroup: function CanvasGraphics_endGroup(group) {
  10959. this.groupLevel--;
  10960. var groupCtx = this.ctx;
  10961. this.ctx = this.groupStack.pop();
  10962. if (this.ctx.imageSmoothingEnabled !== undefined) {
  10963. this.ctx.imageSmoothingEnabled = false;
  10964. } else {
  10965. this.ctx.mozImageSmoothingEnabled = false;
  10966. }
  10967. if (group.smask) {
  10968. this.tempSMask = this.smaskStack.pop();
  10969. } else {
  10970. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  10971. }
  10972. this.restore();
  10973. },
  10974. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  10975. this.save();
  10976. if (this.baseTransform) {
  10977. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  10978. }
  10979. },
  10980. endAnnotations: function CanvasGraphics_endAnnotations() {
  10981. this.restore();
  10982. },
  10983. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform, matrix) {
  10984. this.save();
  10985. resetCtxToDefault(this.ctx);
  10986. this.current = new CanvasExtraState();
  10987. if ((0, _util.isArray)(rect) && rect.length === 4) {
  10988. var width = rect[2] - rect[0];
  10989. var height = rect[3] - rect[1];
  10990. this.ctx.rect(rect[0], rect[1], width, height);
  10991. this.clip();
  10992. this.endPath();
  10993. }
  10994. this.transform.apply(this, transform);
  10995. this.transform.apply(this, matrix);
  10996. },
  10997. endAnnotation: function CanvasGraphics_endAnnotation() {
  10998. this.restore();
  10999. },
  11000. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  11001. var domImage = this.objs.get(objId);
  11002. if (!domImage) {
  11003. (0, _util.warn)('Dependent image isn\'t ready yet');
  11004. return;
  11005. }
  11006. this.save();
  11007. var ctx = this.ctx;
  11008. ctx.scale(1 / w, -1 / h);
  11009. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height, 0, -h, w, h);
  11010. if (this.imageLayer) {
  11011. var currentTransform = ctx.mozCurrentTransformInverse;
  11012. var position = this.getCanvasPosition(0, 0);
  11013. this.imageLayer.appendImage({
  11014. objId: objId,
  11015. left: position[0],
  11016. top: position[1],
  11017. width: w / currentTransform[0],
  11018. height: h / currentTransform[3]
  11019. });
  11020. }
  11021. this.restore();
  11022. },
  11023. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  11024. var ctx = this.ctx;
  11025. var width = img.width,
  11026. height = img.height;
  11027. var fillColor = this.current.fillColor;
  11028. var isPatternFill = this.current.patternFill;
  11029. var glyph = this.processingType3;
  11030. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  11031. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  11032. glyph.compiled = compileType3Glyph({
  11033. data: img.data,
  11034. width: width,
  11035. height: height
  11036. });
  11037. } else {
  11038. glyph.compiled = null;
  11039. }
  11040. }
  11041. if (glyph && glyph.compiled) {
  11042. glyph.compiled(ctx);
  11043. return;
  11044. }
  11045. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  11046. var maskCtx = maskCanvas.context;
  11047. maskCtx.save();
  11048. putBinaryImageMask(maskCtx, img);
  11049. maskCtx.globalCompositeOperation = 'source-in';
  11050. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  11051. maskCtx.fillRect(0, 0, width, height);
  11052. maskCtx.restore();
  11053. this.paintInlineImageXObject(maskCanvas.canvas);
  11054. },
  11055. paintImageMaskXObjectRepeat: function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX, scaleY, positions) {
  11056. var width = imgData.width;
  11057. var height = imgData.height;
  11058. var fillColor = this.current.fillColor;
  11059. var isPatternFill = this.current.patternFill;
  11060. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  11061. var maskCtx = maskCanvas.context;
  11062. maskCtx.save();
  11063. putBinaryImageMask(maskCtx, imgData);
  11064. maskCtx.globalCompositeOperation = 'source-in';
  11065. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  11066. maskCtx.fillRect(0, 0, width, height);
  11067. maskCtx.restore();
  11068. var ctx = this.ctx;
  11069. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  11070. ctx.save();
  11071. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  11072. ctx.scale(1, -1);
  11073. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  11074. ctx.restore();
  11075. }
  11076. },
  11077. paintImageMaskXObjectGroup: function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  11078. var ctx = this.ctx;
  11079. var fillColor = this.current.fillColor;
  11080. var isPatternFill = this.current.patternFill;
  11081. for (var i = 0, ii = images.length; i < ii; i++) {
  11082. var image = images[i];
  11083. var width = image.width,
  11084. height = image.height;
  11085. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  11086. var maskCtx = maskCanvas.context;
  11087. maskCtx.save();
  11088. putBinaryImageMask(maskCtx, image);
  11089. maskCtx.globalCompositeOperation = 'source-in';
  11090. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  11091. maskCtx.fillRect(0, 0, width, height);
  11092. maskCtx.restore();
  11093. ctx.save();
  11094. ctx.transform.apply(ctx, image.transform);
  11095. ctx.scale(1, -1);
  11096. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  11097. ctx.restore();
  11098. }
  11099. },
  11100. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  11101. var imgData = this.objs.get(objId);
  11102. if (!imgData) {
  11103. (0, _util.warn)('Dependent image isn\'t ready yet');
  11104. return;
  11105. }
  11106. this.paintInlineImageXObject(imgData);
  11107. },
  11108. paintImageXObjectRepeat: function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  11109. var imgData = this.objs.get(objId);
  11110. if (!imgData) {
  11111. (0, _util.warn)('Dependent image isn\'t ready yet');
  11112. return;
  11113. }
  11114. var width = imgData.width;
  11115. var height = imgData.height;
  11116. var map = [];
  11117. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  11118. map.push({
  11119. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  11120. x: 0,
  11121. y: 0,
  11122. w: width,
  11123. h: height
  11124. });
  11125. }
  11126. this.paintInlineImageXObjectGroup(imgData, map);
  11127. },
  11128. paintInlineImageXObject: function CanvasGraphics_paintInlineImageXObject(imgData) {
  11129. var width = imgData.width;
  11130. var height = imgData.height;
  11131. var ctx = this.ctx;
  11132. this.save();
  11133. ctx.scale(1 / width, -1 / height);
  11134. var currentTransform = ctx.mozCurrentTransformInverse;
  11135. var a = currentTransform[0],
  11136. b = currentTransform[1];
  11137. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  11138. var c = currentTransform[2],
  11139. d = currentTransform[3];
  11140. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  11141. var imgToPaint, tmpCanvas;
  11142. if (imgData instanceof HTMLElement || !imgData.data) {
  11143. imgToPaint = imgData;
  11144. } else {
  11145. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', width, height);
  11146. var tmpCtx = tmpCanvas.context;
  11147. putBinaryImageData(tmpCtx, imgData);
  11148. imgToPaint = tmpCanvas.canvas;
  11149. }
  11150. var paintWidth = width,
  11151. paintHeight = height;
  11152. var tmpCanvasId = 'prescale1';
  11153. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  11154. var newWidth = paintWidth,
  11155. newHeight = paintHeight;
  11156. if (widthScale > 2 && paintWidth > 1) {
  11157. newWidth = Math.ceil(paintWidth / 2);
  11158. widthScale /= paintWidth / newWidth;
  11159. }
  11160. if (heightScale > 2 && paintHeight > 1) {
  11161. newHeight = Math.ceil(paintHeight / 2);
  11162. heightScale /= paintHeight / newHeight;
  11163. }
  11164. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  11165. tmpCtx = tmpCanvas.context;
  11166. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  11167. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  11168. imgToPaint = tmpCanvas.canvas;
  11169. paintWidth = newWidth;
  11170. paintHeight = newHeight;
  11171. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  11172. }
  11173. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height);
  11174. if (this.imageLayer) {
  11175. var position = this.getCanvasPosition(0, -height);
  11176. this.imageLayer.appendImage({
  11177. imgData: imgData,
  11178. left: position[0],
  11179. top: position[1],
  11180. width: width / currentTransform[0],
  11181. height: height / currentTransform[3]
  11182. });
  11183. }
  11184. this.restore();
  11185. },
  11186. paintInlineImageXObjectGroup: function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  11187. var ctx = this.ctx;
  11188. var w = imgData.width;
  11189. var h = imgData.height;
  11190. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  11191. var tmpCtx = tmpCanvas.context;
  11192. putBinaryImageData(tmpCtx, imgData);
  11193. for (var i = 0, ii = map.length; i < ii; i++) {
  11194. var entry = map[i];
  11195. ctx.save();
  11196. ctx.transform.apply(ctx, entry.transform);
  11197. ctx.scale(1, -1);
  11198. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  11199. if (this.imageLayer) {
  11200. var position = this.getCanvasPosition(entry.x, entry.y);
  11201. this.imageLayer.appendImage({
  11202. imgData: imgData,
  11203. left: position[0],
  11204. top: position[1],
  11205. width: w,
  11206. height: h
  11207. });
  11208. }
  11209. ctx.restore();
  11210. }
  11211. },
  11212. paintSolidColorImageMask: function CanvasGraphics_paintSolidColorImageMask() {
  11213. this.ctx.fillRect(0, 0, 1, 1);
  11214. },
  11215. paintXObject: function CanvasGraphics_paintXObject() {
  11216. (0, _util.warn)('Unsupported \'paintXObject\' command.');
  11217. },
  11218. markPoint: function CanvasGraphics_markPoint(tag) {},
  11219. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {},
  11220. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {},
  11221. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(tag, properties) {},
  11222. endMarkedContent: function CanvasGraphics_endMarkedContent() {},
  11223. beginCompat: function CanvasGraphics_beginCompat() {},
  11224. endCompat: function CanvasGraphics_endCompat() {},
  11225. consumePath: function CanvasGraphics_consumePath() {
  11226. var ctx = this.ctx;
  11227. if (this.pendingClip) {
  11228. if (this.pendingClip === EO_CLIP) {
  11229. ctx.clip('evenodd');
  11230. } else {
  11231. ctx.clip();
  11232. }
  11233. this.pendingClip = null;
  11234. }
  11235. ctx.beginPath();
  11236. },
  11237. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  11238. if (this.cachedGetSinglePixelWidth === null) {
  11239. this.ctx.save();
  11240. var inverse = this.ctx.mozCurrentTransformInverse;
  11241. this.ctx.restore();
  11242. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(inverse[0] * inverse[0] + inverse[1] * inverse[1], inverse[2] * inverse[2] + inverse[3] * inverse[3]));
  11243. }
  11244. return this.cachedGetSinglePixelWidth;
  11245. },
  11246. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  11247. var transform = this.ctx.mozCurrentTransform;
  11248. return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]];
  11249. }
  11250. };
  11251. for (var op in _util.OPS) {
  11252. CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
  11253. }
  11254. return CanvasGraphics;
  11255. }();
  11256. exports.CanvasGraphics = CanvasGraphics;
  11257. /***/ }),
  11258. /* 12 */
  11259. /***/ (function(module, exports, __w_pdfjs_require__) {
  11260. "use strict";
  11261. Object.defineProperty(exports, "__esModule", {
  11262. value: true
  11263. });
  11264. exports.FontLoader = exports.FontFaceObject = undefined;
  11265. var _util = __w_pdfjs_require__(0);
  11266. function FontLoader(docId) {
  11267. this.docId = docId;
  11268. this.styleElement = null;
  11269. this.nativeFontFaces = [];
  11270. this.loadTestFontId = 0;
  11271. this.loadingContext = {
  11272. requests: [],
  11273. nextRequestId: 0
  11274. };
  11275. }
  11276. FontLoader.prototype = {
  11277. insertRule: function fontLoaderInsertRule(rule) {
  11278. var styleElement = this.styleElement;
  11279. if (!styleElement) {
  11280. styleElement = this.styleElement = document.createElement('style');
  11281. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  11282. document.documentElement.getElementsByTagName('head')[0].appendChild(styleElement);
  11283. }
  11284. var styleSheet = styleElement.sheet;
  11285. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  11286. },
  11287. clear: function fontLoaderClear() {
  11288. if (this.styleElement) {
  11289. this.styleElement.remove();
  11290. this.styleElement = null;
  11291. }
  11292. this.nativeFontFaces.forEach(function (nativeFontFace) {
  11293. document.fonts.delete(nativeFontFace);
  11294. });
  11295. this.nativeFontFaces.length = 0;
  11296. }
  11297. };
  11298. {
  11299. var getLoadTestFont = function getLoadTestFont() {
  11300. return atob('T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' + 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' + 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' + 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' + 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' + 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' + 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' + 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' + 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' + 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' + 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' + 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' + 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' + 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' + 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' + 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' + 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' + 'ABAAAAAAAAAAAD6AAAAAAAAA==');
  11301. };
  11302. Object.defineProperty(FontLoader.prototype, 'loadTestFont', {
  11303. get: function get() {
  11304. return (0, _util.shadow)(this, 'loadTestFont', getLoadTestFont());
  11305. },
  11306. configurable: true
  11307. });
  11308. FontLoader.prototype.addNativeFontFace = function fontLoader_addNativeFontFace(nativeFontFace) {
  11309. this.nativeFontFaces.push(nativeFontFace);
  11310. document.fonts.add(nativeFontFace);
  11311. };
  11312. FontLoader.prototype.bind = function fontLoaderBind(fonts, callback) {
  11313. var rules = [];
  11314. var fontsToLoad = [];
  11315. var fontLoadPromises = [];
  11316. var getNativeFontPromise = function getNativeFontPromise(nativeFontFace) {
  11317. return nativeFontFace.loaded.catch(function (e) {
  11318. (0, _util.warn)('Failed to load font "' + nativeFontFace.family + '": ' + e);
  11319. });
  11320. };
  11321. var isFontLoadingAPISupported = FontLoader.isFontLoadingAPISupported && !FontLoader.isSyncFontLoadingSupported;
  11322. for (var i = 0, ii = fonts.length; i < ii; i++) {
  11323. var font = fonts[i];
  11324. if (font.attached || font.loading === false) {
  11325. continue;
  11326. }
  11327. font.attached = true;
  11328. if (isFontLoadingAPISupported) {
  11329. var nativeFontFace = font.createNativeFontFace();
  11330. if (nativeFontFace) {
  11331. this.addNativeFontFace(nativeFontFace);
  11332. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  11333. }
  11334. } else {
  11335. var rule = font.createFontFaceRule();
  11336. if (rule) {
  11337. this.insertRule(rule);
  11338. rules.push(rule);
  11339. fontsToLoad.push(font);
  11340. }
  11341. }
  11342. }
  11343. var request = this.queueLoadingCallback(callback);
  11344. if (isFontLoadingAPISupported) {
  11345. Promise.all(fontLoadPromises).then(function () {
  11346. request.complete();
  11347. });
  11348. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  11349. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  11350. } else {
  11351. request.complete();
  11352. }
  11353. };
  11354. FontLoader.prototype.queueLoadingCallback = function FontLoader_queueLoadingCallback(callback) {
  11355. function LoadLoader_completeRequest() {
  11356. (0, _util.assert)(!request.end, 'completeRequest() cannot be called twice');
  11357. request.end = Date.now();
  11358. while (context.requests.length > 0 && context.requests[0].end) {
  11359. var otherRequest = context.requests.shift();
  11360. setTimeout(otherRequest.callback, 0);
  11361. }
  11362. }
  11363. var context = this.loadingContext;
  11364. var requestId = 'pdfjs-font-loading-' + context.nextRequestId++;
  11365. var request = {
  11366. id: requestId,
  11367. complete: LoadLoader_completeRequest,
  11368. callback: callback,
  11369. started: Date.now()
  11370. };
  11371. context.requests.push(request);
  11372. return request;
  11373. };
  11374. FontLoader.prototype.prepareFontLoadEvent = function fontLoaderPrepareFontLoadEvent(rules, fonts, request) {
  11375. function int32(data, offset) {
  11376. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  11377. }
  11378. function spliceString(s, offset, remove, insert) {
  11379. var chunk1 = s.substr(0, offset);
  11380. var chunk2 = s.substr(offset + remove);
  11381. return chunk1 + insert + chunk2;
  11382. }
  11383. var i, ii;
  11384. var canvas = document.createElement('canvas');
  11385. canvas.width = 1;
  11386. canvas.height = 1;
  11387. var ctx = canvas.getContext('2d');
  11388. var called = 0;
  11389. function isFontReady(name, callback) {
  11390. called++;
  11391. if (called > 30) {
  11392. (0, _util.warn)('Load test font never loaded.');
  11393. callback();
  11394. return;
  11395. }
  11396. ctx.font = '30px ' + name;
  11397. ctx.fillText('.', 0, 20);
  11398. var imageData = ctx.getImageData(0, 0, 1, 1);
  11399. if (imageData.data[3] > 0) {
  11400. callback();
  11401. return;
  11402. }
  11403. setTimeout(isFontReady.bind(null, name, callback));
  11404. }
  11405. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  11406. var data = this.loadTestFont;
  11407. var COMMENT_OFFSET = 976;
  11408. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  11409. var CFF_CHECKSUM_OFFSET = 16;
  11410. var XXXX_VALUE = 0x58585858;
  11411. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  11412. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  11413. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  11414. }
  11415. if (i < loadTestFontId.length) {
  11416. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + 'XXX', i) | 0;
  11417. }
  11418. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum));
  11419. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  11420. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' + url + '}';
  11421. this.insertRule(rule);
  11422. var names = [];
  11423. for (i = 0, ii = fonts.length; i < ii; i++) {
  11424. names.push(fonts[i].loadedName);
  11425. }
  11426. names.push(loadTestFontId);
  11427. var div = document.createElement('div');
  11428. div.setAttribute('style', 'visibility: hidden;' + 'width: 10px; height: 10px;' + 'position: absolute; top: 0px; left: 0px;');
  11429. for (i = 0, ii = names.length; i < ii; ++i) {
  11430. var span = document.createElement('span');
  11431. span.textContent = 'Hi';
  11432. span.style.fontFamily = names[i];
  11433. div.appendChild(span);
  11434. }
  11435. document.body.appendChild(div);
  11436. isFontReady(loadTestFontId, function () {
  11437. document.body.removeChild(div);
  11438. request.complete();
  11439. });
  11440. };
  11441. }
  11442. {
  11443. FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' && !!document.fonts;
  11444. }
  11445. {
  11446. var isSyncFontLoadingSupported = function isSyncFontLoadingSupported() {
  11447. if (typeof navigator === 'undefined') {
  11448. return true;
  11449. }
  11450. var supported = false;
  11451. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  11452. if (m && m[1] >= 14) {
  11453. supported = true;
  11454. }
  11455. return supported;
  11456. };
  11457. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  11458. get: function get() {
  11459. return (0, _util.shadow)(FontLoader, 'isSyncFontLoadingSupported', isSyncFontLoadingSupported());
  11460. },
  11461. enumerable: true,
  11462. configurable: true
  11463. });
  11464. }
  11465. var IsEvalSupportedCached = {
  11466. get value() {
  11467. return (0, _util.shadow)(this, 'value', (0, _util.isEvalSupported)());
  11468. }
  11469. };
  11470. var FontFaceObject = function FontFaceObjectClosure() {
  11471. function FontFaceObject(translatedData, options) {
  11472. this.compiledGlyphs = Object.create(null);
  11473. for (var i in translatedData) {
  11474. this[i] = translatedData[i];
  11475. }
  11476. this.options = options;
  11477. }
  11478. FontFaceObject.prototype = {
  11479. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  11480. if (!this.data) {
  11481. return null;
  11482. }
  11483. if (this.options.disableFontFace) {
  11484. this.disableFontFace = true;
  11485. return null;
  11486. }
  11487. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  11488. if (this.options.fontRegistry) {
  11489. this.options.fontRegistry.registerFont(this);
  11490. }
  11491. return nativeFontFace;
  11492. },
  11493. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  11494. if (!this.data) {
  11495. return null;
  11496. }
  11497. if (this.options.disableFontFace) {
  11498. this.disableFontFace = true;
  11499. return null;
  11500. }
  11501. var data = (0, _util.bytesToString)(new Uint8Array(this.data));
  11502. var fontName = this.loadedName;
  11503. var url = 'url(data:' + this.mimetype + ';base64,' + btoa(data) + ');';
  11504. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  11505. if (this.options.fontRegistry) {
  11506. this.options.fontRegistry.registerFont(this, url);
  11507. }
  11508. return rule;
  11509. },
  11510. getPathGenerator: function FontFaceObject_getPathGenerator(objs, character) {
  11511. if (!(character in this.compiledGlyphs)) {
  11512. var cmds = objs.get(this.loadedName + '_path_' + character);
  11513. var current, i, len;
  11514. if (this.options.isEvalSupported && IsEvalSupportedCached.value) {
  11515. var args,
  11516. js = '';
  11517. for (i = 0, len = cmds.length; i < len; i++) {
  11518. current = cmds[i];
  11519. if (current.args !== undefined) {
  11520. args = current.args.join(',');
  11521. } else {
  11522. args = '';
  11523. }
  11524. js += 'c.' + current.cmd + '(' + args + ');\n';
  11525. }
  11526. this.compiledGlyphs[character] = new Function('c', 'size', js);
  11527. } else {
  11528. this.compiledGlyphs[character] = function (c, size) {
  11529. for (i = 0, len = cmds.length; i < len; i++) {
  11530. current = cmds[i];
  11531. if (current.cmd === 'scale') {
  11532. current.args = [size, -size];
  11533. }
  11534. c[current.cmd].apply(c, current.args);
  11535. }
  11536. };
  11537. }
  11538. }
  11539. return this.compiledGlyphs[character];
  11540. }
  11541. };
  11542. return FontFaceObject;
  11543. }();
  11544. exports.FontFaceObject = FontFaceObject;
  11545. exports.FontLoader = FontLoader;
  11546. /***/ }),
  11547. /* 13 */
  11548. /***/ (function(module, exports, __w_pdfjs_require__) {
  11549. "use strict";
  11550. Object.defineProperty(exports, "__esModule", {
  11551. value: true
  11552. });
  11553. exports.TilingPattern = exports.getShadingPatternFromIR = undefined;
  11554. var _util = __w_pdfjs_require__(0);
  11555. var _webgl = __w_pdfjs_require__(7);
  11556. var ShadingIRs = {};
  11557. ShadingIRs.RadialAxial = {
  11558. fromIR: function RadialAxial_fromIR(raw) {
  11559. var type = raw[1];
  11560. var colorStops = raw[2];
  11561. var p0 = raw[3];
  11562. var p1 = raw[4];
  11563. var r0 = raw[5];
  11564. var r1 = raw[6];
  11565. return {
  11566. type: 'Pattern',
  11567. getPattern: function RadialAxial_getPattern(ctx) {
  11568. var grad;
  11569. if (type === 'axial') {
  11570. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  11571. } else if (type === 'radial') {
  11572. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  11573. }
  11574. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  11575. var c = colorStops[i];
  11576. grad.addColorStop(c[0], c[1]);
  11577. }
  11578. return grad;
  11579. }
  11580. };
  11581. }
  11582. };
  11583. var createMeshCanvas = function createMeshCanvasClosure() {
  11584. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  11585. var coords = context.coords,
  11586. colors = context.colors;
  11587. var bytes = data.data,
  11588. rowSize = data.width * 4;
  11589. var tmp;
  11590. if (coords[p1 + 1] > coords[p2 + 1]) {
  11591. tmp = p1;
  11592. p1 = p2;
  11593. p2 = tmp;
  11594. tmp = c1;
  11595. c1 = c2;
  11596. c2 = tmp;
  11597. }
  11598. if (coords[p2 + 1] > coords[p3 + 1]) {
  11599. tmp = p2;
  11600. p2 = p3;
  11601. p3 = tmp;
  11602. tmp = c2;
  11603. c2 = c3;
  11604. c3 = tmp;
  11605. }
  11606. if (coords[p1 + 1] > coords[p2 + 1]) {
  11607. tmp = p1;
  11608. p1 = p2;
  11609. p2 = tmp;
  11610. tmp = c1;
  11611. c1 = c2;
  11612. c2 = tmp;
  11613. }
  11614. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  11615. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  11616. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  11617. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  11618. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  11619. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  11620. if (y1 >= y3) {
  11621. return;
  11622. }
  11623. var c1r = colors[c1],
  11624. c1g = colors[c1 + 1],
  11625. c1b = colors[c1 + 2];
  11626. var c2r = colors[c2],
  11627. c2g = colors[c2 + 1],
  11628. c2b = colors[c2 + 2];
  11629. var c3r = colors[c3],
  11630. c3g = colors[c3 + 1],
  11631. c3b = colors[c3 + 2];
  11632. var minY = Math.round(y1),
  11633. maxY = Math.round(y3);
  11634. var xa, car, cag, cab;
  11635. var xb, cbr, cbg, cbb;
  11636. var k;
  11637. for (var y = minY; y <= maxY; y++) {
  11638. if (y < y2) {
  11639. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  11640. xa = x1 - (x1 - x2) * k;
  11641. car = c1r - (c1r - c2r) * k;
  11642. cag = c1g - (c1g - c2g) * k;
  11643. cab = c1b - (c1b - c2b) * k;
  11644. } else {
  11645. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  11646. xa = x2 - (x2 - x3) * k;
  11647. car = c2r - (c2r - c3r) * k;
  11648. cag = c2g - (c2g - c3g) * k;
  11649. cab = c2b - (c2b - c3b) * k;
  11650. }
  11651. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  11652. xb = x1 - (x1 - x3) * k;
  11653. cbr = c1r - (c1r - c3r) * k;
  11654. cbg = c1g - (c1g - c3g) * k;
  11655. cbb = c1b - (c1b - c3b) * k;
  11656. var x1_ = Math.round(Math.min(xa, xb));
  11657. var x2_ = Math.round(Math.max(xa, xb));
  11658. var j = rowSize * y + x1_ * 4;
  11659. for (var x = x1_; x <= x2_; x++) {
  11660. k = (xa - x) / (xa - xb);
  11661. k = k < 0 ? 0 : k > 1 ? 1 : k;
  11662. bytes[j++] = car - (car - cbr) * k | 0;
  11663. bytes[j++] = cag - (cag - cbg) * k | 0;
  11664. bytes[j++] = cab - (cab - cbb) * k | 0;
  11665. bytes[j++] = 255;
  11666. }
  11667. }
  11668. }
  11669. function drawFigure(data, figure, context) {
  11670. var ps = figure.coords;
  11671. var cs = figure.colors;
  11672. var i, ii;
  11673. switch (figure.type) {
  11674. case 'lattice':
  11675. var verticesPerRow = figure.verticesPerRow;
  11676. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  11677. var cols = verticesPerRow - 1;
  11678. for (i = 0; i < rows; i++) {
  11679. var q = i * verticesPerRow;
  11680. for (var j = 0; j < cols; j++, q++) {
  11681. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  11682. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  11683. }
  11684. }
  11685. break;
  11686. case 'triangles':
  11687. for (i = 0, ii = ps.length; i < ii; i += 3) {
  11688. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  11689. }
  11690. break;
  11691. default:
  11692. throw new Error('illegal figure');
  11693. }
  11694. }
  11695. function createMeshCanvas(bounds, combinesScale, coords, colors, figures, backgroundColor, cachedCanvases) {
  11696. var EXPECTED_SCALE = 1.1;
  11697. var MAX_PATTERN_SIZE = 3000;
  11698. var BORDER_SIZE = 2;
  11699. var offsetX = Math.floor(bounds[0]);
  11700. var offsetY = Math.floor(bounds[1]);
  11701. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  11702. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  11703. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  11704. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  11705. var scaleX = boundsWidth / width;
  11706. var scaleY = boundsHeight / height;
  11707. var context = {
  11708. coords: coords,
  11709. colors: colors,
  11710. offsetX: -offsetX,
  11711. offsetY: -offsetY,
  11712. scaleX: 1 / scaleX,
  11713. scaleY: 1 / scaleY
  11714. };
  11715. var paddedWidth = width + BORDER_SIZE * 2;
  11716. var paddedHeight = height + BORDER_SIZE * 2;
  11717. var canvas, tmpCanvas, i, ii;
  11718. if (_webgl.WebGLUtils.isEnabled) {
  11719. canvas = _webgl.WebGLUtils.drawFigures(width, height, backgroundColor, figures, context);
  11720. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight, false);
  11721. tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
  11722. canvas = tmpCanvas.canvas;
  11723. } else {
  11724. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight, false);
  11725. var tmpCtx = tmpCanvas.context;
  11726. var data = tmpCtx.createImageData(width, height);
  11727. if (backgroundColor) {
  11728. var bytes = data.data;
  11729. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  11730. bytes[i] = backgroundColor[0];
  11731. bytes[i + 1] = backgroundColor[1];
  11732. bytes[i + 2] = backgroundColor[2];
  11733. bytes[i + 3] = 255;
  11734. }
  11735. }
  11736. for (i = 0; i < figures.length; i++) {
  11737. drawFigure(data, figures[i], context);
  11738. }
  11739. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  11740. canvas = tmpCanvas.canvas;
  11741. }
  11742. return {
  11743. canvas: canvas,
  11744. offsetX: offsetX - BORDER_SIZE * scaleX,
  11745. offsetY: offsetY - BORDER_SIZE * scaleY,
  11746. scaleX: scaleX,
  11747. scaleY: scaleY
  11748. };
  11749. }
  11750. return createMeshCanvas;
  11751. }();
  11752. ShadingIRs.Mesh = {
  11753. fromIR: function Mesh_fromIR(raw) {
  11754. var coords = raw[2];
  11755. var colors = raw[3];
  11756. var figures = raw[4];
  11757. var bounds = raw[5];
  11758. var matrix = raw[6];
  11759. var background = raw[8];
  11760. return {
  11761. type: 'Pattern',
  11762. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  11763. var scale;
  11764. if (shadingFill) {
  11765. scale = _util.Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  11766. } else {
  11767. scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
  11768. if (matrix) {
  11769. var matrixScale = _util.Util.singularValueDecompose2dScale(matrix);
  11770. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  11771. }
  11772. }
  11773. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, colors, figures, shadingFill ? null : background, owner.cachedCanvases);
  11774. if (!shadingFill) {
  11775. ctx.setTransform.apply(ctx, owner.baseTransform);
  11776. if (matrix) {
  11777. ctx.transform.apply(ctx, matrix);
  11778. }
  11779. }
  11780. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  11781. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  11782. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  11783. }
  11784. };
  11785. }
  11786. };
  11787. ShadingIRs.Dummy = {
  11788. fromIR: function Dummy_fromIR() {
  11789. return {
  11790. type: 'Pattern',
  11791. getPattern: function Dummy_fromIR_getPattern() {
  11792. return 'hotpink';
  11793. }
  11794. };
  11795. }
  11796. };
  11797. function getShadingPatternFromIR(raw) {
  11798. var shadingIR = ShadingIRs[raw[0]];
  11799. if (!shadingIR) {
  11800. throw new Error('Unknown IR type: ' + raw[0]);
  11801. }
  11802. return shadingIR.fromIR(raw);
  11803. }
  11804. var TilingPattern = function TilingPatternClosure() {
  11805. var PaintType = {
  11806. COLORED: 1,
  11807. UNCOLORED: 2
  11808. };
  11809. var MAX_PATTERN_SIZE = 3000;
  11810. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  11811. this.operatorList = IR[2];
  11812. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  11813. this.bbox = IR[4];
  11814. this.xstep = IR[5];
  11815. this.ystep = IR[6];
  11816. this.paintType = IR[7];
  11817. this.tilingType = IR[8];
  11818. this.color = color;
  11819. this.canvasGraphicsFactory = canvasGraphicsFactory;
  11820. this.baseTransform = baseTransform;
  11821. this.type = 'Pattern';
  11822. this.ctx = ctx;
  11823. }
  11824. TilingPattern.prototype = {
  11825. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  11826. var operatorList = this.operatorList;
  11827. var bbox = this.bbox;
  11828. var xstep = this.xstep;
  11829. var ystep = this.ystep;
  11830. var paintType = this.paintType;
  11831. var tilingType = this.tilingType;
  11832. var color = this.color;
  11833. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  11834. (0, _util.info)('TilingType: ' + tilingType);
  11835. var x0 = bbox[0],
  11836. y0 = bbox[1],
  11837. x1 = bbox[2],
  11838. y1 = bbox[3];
  11839. var topLeft = [x0, y0];
  11840. var botRight = [x0 + xstep, y0 + ystep];
  11841. var width = botRight[0] - topLeft[0];
  11842. var height = botRight[1] - topLeft[1];
  11843. var matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  11844. var curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
  11845. var combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  11846. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])), MAX_PATTERN_SIZE);
  11847. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])), MAX_PATTERN_SIZE);
  11848. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern', width, height, true);
  11849. var tmpCtx = tmpCanvas.context;
  11850. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  11851. graphics.groupLevel = owner.groupLevel;
  11852. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  11853. this.setScale(width, height, xstep, ystep);
  11854. this.transformToScale(graphics);
  11855. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  11856. graphics.transform.apply(graphics, tmpTranslate);
  11857. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  11858. graphics.executeOperatorList(operatorList);
  11859. return tmpCanvas.canvas;
  11860. },
  11861. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  11862. this.scale = [width / xstep, height / ystep];
  11863. },
  11864. transformToScale: function TilingPattern_transformToScale(graphics) {
  11865. var scale = this.scale;
  11866. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  11867. graphics.transform.apply(graphics, tmpScale);
  11868. },
  11869. scaleToContext: function TilingPattern_scaleToContext() {
  11870. var scale = this.scale;
  11871. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  11872. },
  11873. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  11874. if ((0, _util.isArray)(bbox) && bbox.length === 4) {
  11875. var bboxWidth = x1 - x0;
  11876. var bboxHeight = y1 - y0;
  11877. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  11878. graphics.clip();
  11879. graphics.endPath();
  11880. }
  11881. },
  11882. setFillAndStrokeStyleToContext: function setFillAndStrokeStyleToContext(context, paintType, color) {
  11883. switch (paintType) {
  11884. case PaintType.COLORED:
  11885. var ctx = this.ctx;
  11886. context.fillStyle = ctx.fillStyle;
  11887. context.strokeStyle = ctx.strokeStyle;
  11888. break;
  11889. case PaintType.UNCOLORED:
  11890. var cssColor = _util.Util.makeCssRgb(color[0], color[1], color[2]);
  11891. context.fillStyle = cssColor;
  11892. context.strokeStyle = cssColor;
  11893. break;
  11894. default:
  11895. throw new _util.FormatError('Unsupported paint type: ' + paintType);
  11896. }
  11897. },
  11898. getPattern: function TilingPattern_getPattern(ctx, owner) {
  11899. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  11900. ctx = this.ctx;
  11901. ctx.setTransform.apply(ctx, this.baseTransform);
  11902. ctx.transform.apply(ctx, this.matrix);
  11903. this.scaleToContext();
  11904. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  11905. }
  11906. };
  11907. return TilingPattern;
  11908. }();
  11909. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  11910. exports.TilingPattern = TilingPattern;
  11911. /***/ }),
  11912. /* 14 */
  11913. /***/ (function(module, exports, __w_pdfjs_require__) {
  11914. "use strict";
  11915. Object.defineProperty(exports, "__esModule", {
  11916. value: true
  11917. });
  11918. exports.PDFDataTransportStream = undefined;
  11919. var _util = __w_pdfjs_require__(0);
  11920. var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
  11921. function PDFDataTransportStream(params, pdfDataRangeTransport) {
  11922. var _this = this;
  11923. (0, _util.assert)(pdfDataRangeTransport);
  11924. this._queuedChunks = [];
  11925. var initialData = params.initialData;
  11926. if (initialData && initialData.length > 0) {
  11927. var buffer = new Uint8Array(initialData).buffer;
  11928. this._queuedChunks.push(buffer);
  11929. }
  11930. this._pdfDataRangeTransport = pdfDataRangeTransport;
  11931. this._isRangeSupported = !params.disableRange;
  11932. this._isStreamingSupported = !params.disableStream;
  11933. this._contentLength = params.length;
  11934. this._fullRequestReader = null;
  11935. this._rangeReaders = [];
  11936. this._pdfDataRangeTransport.addRangeListener(function (begin, chunk) {
  11937. _this._onReceiveData({
  11938. begin: begin,
  11939. chunk: chunk
  11940. });
  11941. });
  11942. this._pdfDataRangeTransport.addProgressListener(function (loaded) {
  11943. _this._onProgress({ loaded: loaded });
  11944. });
  11945. this._pdfDataRangeTransport.addProgressiveReadListener(function (chunk) {
  11946. _this._onReceiveData({ chunk: chunk });
  11947. });
  11948. this._pdfDataRangeTransport.transportReady();
  11949. }
  11950. PDFDataTransportStream.prototype = {
  11951. _onReceiveData: function PDFDataTransportStream_onReceiveData(args) {
  11952. var buffer = new Uint8Array(args.chunk).buffer;
  11953. if (args.begin === undefined) {
  11954. if (this._fullRequestReader) {
  11955. this._fullRequestReader._enqueue(buffer);
  11956. } else {
  11957. this._queuedChunks.push(buffer);
  11958. }
  11959. } else {
  11960. var found = this._rangeReaders.some(function (rangeReader) {
  11961. if (rangeReader._begin !== args.begin) {
  11962. return false;
  11963. }
  11964. rangeReader._enqueue(buffer);
  11965. return true;
  11966. });
  11967. (0, _util.assert)(found);
  11968. }
  11969. },
  11970. _onProgress: function PDFDataTransportStream_onDataProgress(evt) {
  11971. if (this._rangeReaders.length > 0) {
  11972. var firstReader = this._rangeReaders[0];
  11973. if (firstReader.onProgress) {
  11974. firstReader.onProgress({ loaded: evt.loaded });
  11975. }
  11976. }
  11977. },
  11978. _removeRangeReader: function PDFDataTransportStream_removeRangeReader(reader) {
  11979. var i = this._rangeReaders.indexOf(reader);
  11980. if (i >= 0) {
  11981. this._rangeReaders.splice(i, 1);
  11982. }
  11983. },
  11984. getFullReader: function PDFDataTransportStream_getFullReader() {
  11985. (0, _util.assert)(!this._fullRequestReader);
  11986. var queuedChunks = this._queuedChunks;
  11987. this._queuedChunks = null;
  11988. return new PDFDataTransportStreamReader(this, queuedChunks);
  11989. },
  11990. getRangeReader: function PDFDataTransportStream_getRangeReader(begin, end) {
  11991. var reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  11992. this._pdfDataRangeTransport.requestDataRange(begin, end);
  11993. this._rangeReaders.push(reader);
  11994. return reader;
  11995. },
  11996. cancelAllRequests: function PDFDataTransportStream_cancelAllRequests(reason) {
  11997. if (this._fullRequestReader) {
  11998. this._fullRequestReader.cancel(reason);
  11999. }
  12000. var readers = this._rangeReaders.slice(0);
  12001. readers.forEach(function (rangeReader) {
  12002. rangeReader.cancel(reason);
  12003. });
  12004. this._pdfDataRangeTransport.abort();
  12005. }
  12006. };
  12007. function PDFDataTransportStreamReader(stream, queuedChunks) {
  12008. this._stream = stream;
  12009. this._done = false;
  12010. this._queuedChunks = queuedChunks || [];
  12011. this._requests = [];
  12012. this._headersReady = Promise.resolve();
  12013. stream._fullRequestReader = this;
  12014. this.onProgress = null;
  12015. }
  12016. PDFDataTransportStreamReader.prototype = {
  12017. _enqueue: function PDFDataTransportStreamReader_enqueue(chunk) {
  12018. if (this._done) {
  12019. return;
  12020. }
  12021. if (this._requests.length > 0) {
  12022. var requestCapability = this._requests.shift();
  12023. requestCapability.resolve({
  12024. value: chunk,
  12025. done: false
  12026. });
  12027. return;
  12028. }
  12029. this._queuedChunks.push(chunk);
  12030. },
  12031. get headersReady() {
  12032. return this._headersReady;
  12033. },
  12034. get isRangeSupported() {
  12035. return this._stream._isRangeSupported;
  12036. },
  12037. get isStreamingSupported() {
  12038. return this._stream._isStreamingSupported;
  12039. },
  12040. get contentLength() {
  12041. return this._stream._contentLength;
  12042. },
  12043. read: function PDFDataTransportStreamReader_read() {
  12044. if (this._queuedChunks.length > 0) {
  12045. var chunk = this._queuedChunks.shift();
  12046. return Promise.resolve({
  12047. value: chunk,
  12048. done: false
  12049. });
  12050. }
  12051. if (this._done) {
  12052. return Promise.resolve({
  12053. value: undefined,
  12054. done: true
  12055. });
  12056. }
  12057. var requestCapability = (0, _util.createPromiseCapability)();
  12058. this._requests.push(requestCapability);
  12059. return requestCapability.promise;
  12060. },
  12061. cancel: function PDFDataTransportStreamReader_cancel(reason) {
  12062. this._done = true;
  12063. this._requests.forEach(function (requestCapability) {
  12064. requestCapability.resolve({
  12065. value: undefined,
  12066. done: true
  12067. });
  12068. });
  12069. this._requests = [];
  12070. }
  12071. };
  12072. function PDFDataTransportStreamRangeReader(stream, begin, end) {
  12073. this._stream = stream;
  12074. this._begin = begin;
  12075. this._end = end;
  12076. this._queuedChunk = null;
  12077. this._requests = [];
  12078. this._done = false;
  12079. this.onProgress = null;
  12080. }
  12081. PDFDataTransportStreamRangeReader.prototype = {
  12082. _enqueue: function PDFDataTransportStreamRangeReader_enqueue(chunk) {
  12083. if (this._done) {
  12084. return;
  12085. }
  12086. if (this._requests.length === 0) {
  12087. this._queuedChunk = chunk;
  12088. } else {
  12089. var requestsCapability = this._requests.shift();
  12090. requestsCapability.resolve({
  12091. value: chunk,
  12092. done: false
  12093. });
  12094. this._requests.forEach(function (requestCapability) {
  12095. requestCapability.resolve({
  12096. value: undefined,
  12097. done: true
  12098. });
  12099. });
  12100. this._requests = [];
  12101. }
  12102. this._done = true;
  12103. this._stream._removeRangeReader(this);
  12104. },
  12105. get isStreamingSupported() {
  12106. return false;
  12107. },
  12108. read: function PDFDataTransportStreamRangeReader_read() {
  12109. if (this._queuedChunk) {
  12110. var chunk = this._queuedChunk;
  12111. this._queuedChunk = null;
  12112. return Promise.resolve({
  12113. value: chunk,
  12114. done: false
  12115. });
  12116. }
  12117. if (this._done) {
  12118. return Promise.resolve({
  12119. value: undefined,
  12120. done: true
  12121. });
  12122. }
  12123. var requestCapability = (0, _util.createPromiseCapability)();
  12124. this._requests.push(requestCapability);
  12125. return requestCapability.promise;
  12126. },
  12127. cancel: function PDFDataTransportStreamRangeReader_cancel(reason) {
  12128. this._done = true;
  12129. this._requests.forEach(function (requestCapability) {
  12130. requestCapability.resolve({
  12131. value: undefined,
  12132. done: true
  12133. });
  12134. });
  12135. this._requests = [];
  12136. this._stream._removeRangeReader(this);
  12137. }
  12138. };
  12139. return PDFDataTransportStream;
  12140. }();
  12141. exports.PDFDataTransportStream = PDFDataTransportStream;
  12142. /***/ }),
  12143. /* 15 */
  12144. /***/ (function(module, exports, __w_pdfjs_require__) {
  12145. "use strict";
  12146. var pdfjsVersion = '1.9.426';
  12147. var pdfjsBuild = '2558a58d';
  12148. var pdfjsSharedUtil = __w_pdfjs_require__(0);
  12149. var pdfjsDisplayGlobal = __w_pdfjs_require__(8);
  12150. var pdfjsDisplayAPI = __w_pdfjs_require__(2);
  12151. var pdfjsDisplayTextLayer = __w_pdfjs_require__(5);
  12152. var pdfjsDisplayAnnotationLayer = __w_pdfjs_require__(3);
  12153. var pdfjsDisplayDOMUtils = __w_pdfjs_require__(1);
  12154. var pdfjsDisplaySVG = __w_pdfjs_require__(4);
  12155. {
  12156. __w_pdfjs_require__(9);
  12157. }
  12158. exports.PDFJS = pdfjsDisplayGlobal.PDFJS;
  12159. exports.build = pdfjsDisplayAPI.build;
  12160. exports.version = pdfjsDisplayAPI.version;
  12161. exports.getDocument = pdfjsDisplayAPI.getDocument;
  12162. exports.LoopbackPort = pdfjsDisplayAPI.LoopbackPort;
  12163. exports.PDFDataRangeTransport = pdfjsDisplayAPI.PDFDataRangeTransport;
  12164. exports.PDFWorker = pdfjsDisplayAPI.PDFWorker;
  12165. exports.renderTextLayer = pdfjsDisplayTextLayer.renderTextLayer;
  12166. exports.AnnotationLayer = pdfjsDisplayAnnotationLayer.AnnotationLayer;
  12167. exports.CustomStyle = pdfjsDisplayDOMUtils.CustomStyle;
  12168. exports.createPromiseCapability = pdfjsSharedUtil.createPromiseCapability;
  12169. exports.PasswordResponses = pdfjsSharedUtil.PasswordResponses;
  12170. exports.InvalidPDFException = pdfjsSharedUtil.InvalidPDFException;
  12171. exports.MissingPDFException = pdfjsSharedUtil.MissingPDFException;
  12172. exports.SVGGraphics = pdfjsDisplaySVG.SVGGraphics;
  12173. exports.NativeImageDecoding = pdfjsSharedUtil.NativeImageDecoding;
  12174. exports.UnexpectedResponseException = pdfjsSharedUtil.UnexpectedResponseException;
  12175. exports.OPS = pdfjsSharedUtil.OPS;
  12176. exports.UNSUPPORTED_FEATURES = pdfjsSharedUtil.UNSUPPORTED_FEATURES;
  12177. exports.isValidUrl = pdfjsDisplayDOMUtils.isValidUrl;
  12178. exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl;
  12179. exports.createObjectURL = pdfjsSharedUtil.createObjectURL;
  12180. exports.removeNullCharacters = pdfjsSharedUtil.removeNullCharacters;
  12181. exports.shadow = pdfjsSharedUtil.shadow;
  12182. exports.createBlob = pdfjsSharedUtil.createBlob;
  12183. exports.RenderingCancelledException = pdfjsDisplayDOMUtils.RenderingCancelledException;
  12184. exports.getFilenameFromUrl = pdfjsDisplayDOMUtils.getFilenameFromUrl;
  12185. exports.addLinkAttributes = pdfjsDisplayDOMUtils.addLinkAttributes;
  12186. exports.StatTimer = pdfjsSharedUtil.StatTimer;
  12187. /***/ }),
  12188. /* 16 */
  12189. /***/ (function(module, exports, __w_pdfjs_require__) {
  12190. "use strict";
  12191. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  12192. if (typeof PDFJS === 'undefined' || !PDFJS.compatibilityChecked) {
  12193. var globalScope = typeof window !== 'undefined' && window.Math === Math ? window : typeof global !== 'undefined' && global.Math === Math ? global : typeof self !== 'undefined' && self.Math === Math ? self : false ? undefined : {};
  12194. var userAgent = typeof navigator !== 'undefined' && navigator.userAgent || '';
  12195. var isAndroid = /Android/.test(userAgent);
  12196. var isAndroidPre3 = /Android\s[0-2][^\d]/.test(userAgent);
  12197. var isAndroidPre5 = /Android\s[0-4][^\d]/.test(userAgent);
  12198. var isChrome = userAgent.indexOf('Chrom') >= 0;
  12199. var isChromeWithRangeBug = /Chrome\/(39|40)\./.test(userAgent);
  12200. var isIOSChrome = userAgent.indexOf('CriOS') >= 0;
  12201. var isIE = userAgent.indexOf('Trident') >= 0;
  12202. var isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent);
  12203. var isOpera = userAgent.indexOf('Opera') >= 0;
  12204. var isSafari = /Safari\//.test(userAgent) && !/(Chrome\/|Android\s)/.test(userAgent);
  12205. var hasDOM = (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' && (typeof document === 'undefined' ? 'undefined' : _typeof(document)) === 'object';
  12206. if (typeof PDFJS === 'undefined') {
  12207. globalScope.PDFJS = {};
  12208. }
  12209. PDFJS.compatibilityChecked = true;
  12210. (function checkTypedArrayCompatibility() {
  12211. if (typeof Uint8Array !== 'undefined') {
  12212. if (typeof Uint8Array.prototype.subarray === 'undefined') {
  12213. Uint8Array.prototype.subarray = function subarray(start, end) {
  12214. return new Uint8Array(this.slice(start, end));
  12215. };
  12216. Float32Array.prototype.subarray = function subarray(start, end) {
  12217. return new Float32Array(this.slice(start, end));
  12218. };
  12219. }
  12220. if (typeof Float64Array === 'undefined') {
  12221. globalScope.Float64Array = Float32Array;
  12222. }
  12223. return;
  12224. }
  12225. function subarray(start, end) {
  12226. return new TypedArray(this.slice(start, end));
  12227. }
  12228. function setArrayOffset(array, offset) {
  12229. if (arguments.length < 2) {
  12230. offset = 0;
  12231. }
  12232. for (var i = 0, n = array.length; i < n; ++i, ++offset) {
  12233. this[offset] = array[i] & 0xFF;
  12234. }
  12235. }
  12236. function Uint32ArrayView(buffer, length) {
  12237. this.buffer = buffer;
  12238. this.byteLength = buffer.length;
  12239. this.length = length;
  12240. ensureUint32ArrayViewProps(this.length);
  12241. }
  12242. Uint32ArrayView.prototype = Object.create(null);
  12243. var uint32ArrayViewSetters = 0;
  12244. function createUint32ArrayProp(index) {
  12245. return {
  12246. get: function get() {
  12247. var buffer = this.buffer,
  12248. offset = index << 2;
  12249. return (buffer[offset] | buffer[offset + 1] << 8 | buffer[offset + 2] << 16 | buffer[offset + 3] << 24) >>> 0;
  12250. },
  12251. set: function set(value) {
  12252. var buffer = this.buffer,
  12253. offset = index << 2;
  12254. buffer[offset] = value & 255;
  12255. buffer[offset + 1] = value >> 8 & 255;
  12256. buffer[offset + 2] = value >> 16 & 255;
  12257. buffer[offset + 3] = value >>> 24 & 255;
  12258. }
  12259. };
  12260. }
  12261. function ensureUint32ArrayViewProps(length) {
  12262. while (uint32ArrayViewSetters < length) {
  12263. Object.defineProperty(Uint32ArrayView.prototype, uint32ArrayViewSetters, createUint32ArrayProp(uint32ArrayViewSetters));
  12264. uint32ArrayViewSetters++;
  12265. }
  12266. }
  12267. function TypedArray(arg1) {
  12268. var result, i, n;
  12269. if (typeof arg1 === 'number') {
  12270. result = [];
  12271. for (i = 0; i < arg1; ++i) {
  12272. result[i] = 0;
  12273. }
  12274. } else if ('slice' in arg1) {
  12275. result = arg1.slice(0);
  12276. } else {
  12277. result = [];
  12278. for (i = 0, n = arg1.length; i < n; ++i) {
  12279. result[i] = arg1[i];
  12280. }
  12281. }
  12282. result.subarray = subarray;
  12283. result.buffer = result;
  12284. result.byteLength = result.length;
  12285. result.set = setArrayOffset;
  12286. if ((typeof arg1 === 'undefined' ? 'undefined' : _typeof(arg1)) === 'object' && arg1.buffer) {
  12287. result.buffer = arg1.buffer;
  12288. }
  12289. return result;
  12290. }
  12291. globalScope.Uint8Array = TypedArray;
  12292. globalScope.Int8Array = TypedArray;
  12293. globalScope.Int32Array = TypedArray;
  12294. globalScope.Uint16Array = TypedArray;
  12295. globalScope.Float32Array = TypedArray;
  12296. globalScope.Float64Array = TypedArray;
  12297. globalScope.Uint32Array = function () {
  12298. if (arguments.length === 3) {
  12299. if (arguments[1] !== 0) {
  12300. throw new Error('offset !== 0 is not supported');
  12301. }
  12302. return new Uint32ArrayView(arguments[0], arguments[2]);
  12303. }
  12304. return TypedArray.apply(this, arguments);
  12305. };
  12306. })();
  12307. (function canvasPixelArrayBuffer() {
  12308. if (!hasDOM || !window.CanvasPixelArray) {
  12309. return;
  12310. }
  12311. var cpaProto = window.CanvasPixelArray.prototype;
  12312. if ('buffer' in cpaProto) {
  12313. return;
  12314. }
  12315. Object.defineProperty(cpaProto, 'buffer', {
  12316. get: function get() {
  12317. return this;
  12318. },
  12319. enumerable: false,
  12320. configurable: true
  12321. });
  12322. Object.defineProperty(cpaProto, 'byteLength', {
  12323. get: function get() {
  12324. return this.length;
  12325. },
  12326. enumerable: false,
  12327. configurable: true
  12328. });
  12329. })();
  12330. (function normalizeURLObject() {
  12331. if (!globalScope.URL) {
  12332. globalScope.URL = globalScope.webkitURL;
  12333. }
  12334. })();
  12335. (function checkObjectDefinePropertyCompatibility() {
  12336. if (typeof Object.defineProperty !== 'undefined') {
  12337. var definePropertyPossible = true;
  12338. try {
  12339. if (hasDOM) {
  12340. Object.defineProperty(new Image(), 'id', { value: 'test' });
  12341. }
  12342. var Test = function Test() {};
  12343. Test.prototype = {
  12344. get id() {}
  12345. };
  12346. Object.defineProperty(new Test(), 'id', {
  12347. value: '',
  12348. configurable: true,
  12349. enumerable: true,
  12350. writable: false
  12351. });
  12352. } catch (e) {
  12353. definePropertyPossible = false;
  12354. }
  12355. if (definePropertyPossible) {
  12356. return;
  12357. }
  12358. }
  12359. Object.defineProperty = function objectDefineProperty(obj, name, def) {
  12360. delete obj[name];
  12361. if ('get' in def) {
  12362. obj.__defineGetter__(name, def['get']);
  12363. }
  12364. if ('set' in def) {
  12365. obj.__defineSetter__(name, def['set']);
  12366. }
  12367. if ('value' in def) {
  12368. obj.__defineSetter__(name, function objectDefinePropertySetter(value) {
  12369. this.__defineGetter__(name, function objectDefinePropertyGetter() {
  12370. return value;
  12371. });
  12372. return value;
  12373. });
  12374. obj[name] = def.value;
  12375. }
  12376. };
  12377. })();
  12378. (function checkXMLHttpRequestResponseCompatibility() {
  12379. if (typeof XMLHttpRequest === 'undefined') {
  12380. return;
  12381. }
  12382. var xhrPrototype = XMLHttpRequest.prototype;
  12383. var xhr = new XMLHttpRequest();
  12384. if (!('overrideMimeType' in xhr)) {
  12385. Object.defineProperty(xhrPrototype, 'overrideMimeType', {
  12386. value: function xmlHttpRequestOverrideMimeType(mimeType) {}
  12387. });
  12388. }
  12389. if ('responseType' in xhr) {
  12390. return;
  12391. }
  12392. Object.defineProperty(xhrPrototype, 'responseType', {
  12393. get: function xmlHttpRequestGetResponseType() {
  12394. return this._responseType || 'text';
  12395. },
  12396. set: function xmlHttpRequestSetResponseType(value) {
  12397. if (value === 'text' || value === 'arraybuffer') {
  12398. this._responseType = value;
  12399. if (value === 'arraybuffer' && typeof this.overrideMimeType === 'function') {
  12400. this.overrideMimeType('text/plain; charset=x-user-defined');
  12401. }
  12402. }
  12403. }
  12404. });
  12405. if (typeof VBArray !== 'undefined') {
  12406. Object.defineProperty(xhrPrototype, 'response', {
  12407. get: function xmlHttpRequestResponseGet() {
  12408. if (this.responseType === 'arraybuffer') {
  12409. return new Uint8Array(new VBArray(this.responseBody).toArray());
  12410. }
  12411. return this.responseText;
  12412. }
  12413. });
  12414. return;
  12415. }
  12416. Object.defineProperty(xhrPrototype, 'response', {
  12417. get: function xmlHttpRequestResponseGet() {
  12418. if (this.responseType !== 'arraybuffer') {
  12419. return this.responseText;
  12420. }
  12421. var text = this.responseText;
  12422. var i,
  12423. n = text.length;
  12424. var result = new Uint8Array(n);
  12425. for (i = 0; i < n; ++i) {
  12426. result[i] = text.charCodeAt(i) & 0xFF;
  12427. }
  12428. return result.buffer;
  12429. }
  12430. });
  12431. })();
  12432. (function checkWindowBtoaCompatibility() {
  12433. if ('btoa' in globalScope) {
  12434. return;
  12435. }
  12436. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  12437. globalScope.btoa = function (chars) {
  12438. var buffer = '';
  12439. var i, n;
  12440. for (i = 0, n = chars.length; i < n; i += 3) {
  12441. var b1 = chars.charCodeAt(i) & 0xFF;
  12442. var b2 = chars.charCodeAt(i + 1) & 0xFF;
  12443. var b3 = chars.charCodeAt(i + 2) & 0xFF;
  12444. var d1 = b1 >> 2,
  12445. d2 = (b1 & 3) << 4 | b2 >> 4;
  12446. var d3 = i + 1 < n ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
  12447. var d4 = i + 2 < n ? b3 & 0x3F : 64;
  12448. buffer += digits.charAt(d1) + digits.charAt(d2) + digits.charAt(d3) + digits.charAt(d4);
  12449. }
  12450. return buffer;
  12451. };
  12452. })();
  12453. (function checkWindowAtobCompatibility() {
  12454. if ('atob' in globalScope) {
  12455. return;
  12456. }
  12457. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  12458. globalScope.atob = function (input) {
  12459. input = input.replace(/=+$/, '');
  12460. if (input.length % 4 === 1) {
  12461. throw new Error('bad atob input');
  12462. }
  12463. for (var bc = 0, bs, buffer, idx = 0, output = ''; buffer = input.charAt(idx++); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) {
  12464. buffer = digits.indexOf(buffer);
  12465. }
  12466. return output;
  12467. };
  12468. })();
  12469. (function checkFunctionPrototypeBindCompatibility() {
  12470. if (typeof Function.prototype.bind !== 'undefined') {
  12471. return;
  12472. }
  12473. Function.prototype.bind = function functionPrototypeBind(obj) {
  12474. var fn = this,
  12475. headArgs = Array.prototype.slice.call(arguments, 1);
  12476. var bound = function functionPrototypeBindBound() {
  12477. var args = headArgs.concat(Array.prototype.slice.call(arguments));
  12478. return fn.apply(obj, args);
  12479. };
  12480. return bound;
  12481. };
  12482. })();
  12483. (function checkDatasetProperty() {
  12484. if (!hasDOM) {
  12485. return;
  12486. }
  12487. var div = document.createElement('div');
  12488. if ('dataset' in div) {
  12489. return;
  12490. }
  12491. Object.defineProperty(HTMLElement.prototype, 'dataset', {
  12492. get: function get() {
  12493. if (this._dataset) {
  12494. return this._dataset;
  12495. }
  12496. var dataset = {};
  12497. for (var j = 0, jj = this.attributes.length; j < jj; j++) {
  12498. var attribute = this.attributes[j];
  12499. if (attribute.name.substring(0, 5) !== 'data-') {
  12500. continue;
  12501. }
  12502. var key = attribute.name.substring(5).replace(/\-([a-z])/g, function (all, ch) {
  12503. return ch.toUpperCase();
  12504. });
  12505. dataset[key] = attribute.value;
  12506. }
  12507. Object.defineProperty(this, '_dataset', {
  12508. value: dataset,
  12509. writable: false,
  12510. enumerable: false
  12511. });
  12512. return dataset;
  12513. },
  12514. enumerable: true
  12515. });
  12516. })();
  12517. (function checkClassListProperty() {
  12518. function changeList(element, itemName, add, remove) {
  12519. var s = element.className || '';
  12520. var list = s.split(/\s+/g);
  12521. if (list[0] === '') {
  12522. list.shift();
  12523. }
  12524. var index = list.indexOf(itemName);
  12525. if (index < 0 && add) {
  12526. list.push(itemName);
  12527. }
  12528. if (index >= 0 && remove) {
  12529. list.splice(index, 1);
  12530. }
  12531. element.className = list.join(' ');
  12532. return index >= 0;
  12533. }
  12534. if (!hasDOM) {
  12535. return;
  12536. }
  12537. var div = document.createElement('div');
  12538. if ('classList' in div) {
  12539. return;
  12540. }
  12541. var classListPrototype = {
  12542. add: function add(name) {
  12543. changeList(this.element, name, true, false);
  12544. },
  12545. contains: function contains(name) {
  12546. return changeList(this.element, name, false, false);
  12547. },
  12548. remove: function remove(name) {
  12549. changeList(this.element, name, false, true);
  12550. },
  12551. toggle: function toggle(name) {
  12552. changeList(this.element, name, true, true);
  12553. }
  12554. };
  12555. Object.defineProperty(HTMLElement.prototype, 'classList', {
  12556. get: function get() {
  12557. if (this._classList) {
  12558. return this._classList;
  12559. }
  12560. var classList = Object.create(classListPrototype, {
  12561. element: {
  12562. value: this,
  12563. writable: false,
  12564. enumerable: true
  12565. }
  12566. });
  12567. Object.defineProperty(this, '_classList', {
  12568. value: classList,
  12569. writable: false,
  12570. enumerable: false
  12571. });
  12572. return classList;
  12573. },
  12574. enumerable: true
  12575. });
  12576. })();
  12577. (function checkWorkerConsoleCompatibility() {
  12578. if (typeof importScripts === 'undefined' || 'console' in globalScope) {
  12579. return;
  12580. }
  12581. var consoleTimer = {};
  12582. var workerConsole = {
  12583. log: function log() {
  12584. var args = Array.prototype.slice.call(arguments);
  12585. globalScope.postMessage({
  12586. targetName: 'main',
  12587. action: 'console_log',
  12588. data: args
  12589. });
  12590. },
  12591. error: function error() {
  12592. var args = Array.prototype.slice.call(arguments);
  12593. globalScope.postMessage({
  12594. targetName: 'main',
  12595. action: 'console_error',
  12596. data: args
  12597. });
  12598. },
  12599. time: function time(name) {
  12600. consoleTimer[name] = Date.now();
  12601. },
  12602. timeEnd: function timeEnd(name) {
  12603. var time = consoleTimer[name];
  12604. if (!time) {
  12605. throw new Error('Unknown timer name ' + name);
  12606. }
  12607. this.log('Timer:', name, Date.now() - time);
  12608. }
  12609. };
  12610. globalScope.console = workerConsole;
  12611. })();
  12612. (function checkConsoleCompatibility() {
  12613. if (!hasDOM) {
  12614. return;
  12615. }
  12616. if (!('console' in window)) {
  12617. window.console = {
  12618. log: function log() {},
  12619. error: function error() {},
  12620. warn: function warn() {}
  12621. };
  12622. return;
  12623. }
  12624. if (!('bind' in console.log)) {
  12625. console.log = function (fn) {
  12626. return function (msg) {
  12627. return fn(msg);
  12628. };
  12629. }(console.log);
  12630. console.error = function (fn) {
  12631. return function (msg) {
  12632. return fn(msg);
  12633. };
  12634. }(console.error);
  12635. console.warn = function (fn) {
  12636. return function (msg) {
  12637. return fn(msg);
  12638. };
  12639. }(console.warn);
  12640. return;
  12641. }
  12642. })();
  12643. (function checkOnClickCompatibility() {
  12644. function ignoreIfTargetDisabled(event) {
  12645. if (isDisabled(event.target)) {
  12646. event.stopPropagation();
  12647. }
  12648. }
  12649. function isDisabled(node) {
  12650. return node.disabled || node.parentNode && isDisabled(node.parentNode);
  12651. }
  12652. if (isOpera) {
  12653. document.addEventListener('click', ignoreIfTargetDisabled, true);
  12654. }
  12655. })();
  12656. (function checkOnBlobSupport() {
  12657. if (isIE || isIOSChrome) {
  12658. PDFJS.disableCreateObjectURL = true;
  12659. }
  12660. })();
  12661. (function checkNavigatorLanguage() {
  12662. if (typeof navigator === 'undefined') {
  12663. return;
  12664. }
  12665. if ('language' in navigator) {
  12666. return;
  12667. }
  12668. PDFJS.locale = navigator.userLanguage || 'en-US';
  12669. })();
  12670. (function checkRangeRequests() {
  12671. if (isSafari || isAndroidPre3 || isChromeWithRangeBug || isIOS) {
  12672. PDFJS.disableRange = true;
  12673. PDFJS.disableStream = true;
  12674. }
  12675. })();
  12676. (function checkHistoryManipulation() {
  12677. if (!hasDOM) {
  12678. return;
  12679. }
  12680. if (!history.pushState || isAndroidPre3) {
  12681. PDFJS.disableHistory = true;
  12682. }
  12683. })();
  12684. (function checkSetPresenceInImageData() {
  12685. if (!hasDOM) {
  12686. return;
  12687. }
  12688. if (window.CanvasPixelArray) {
  12689. if (typeof window.CanvasPixelArray.prototype.set !== 'function') {
  12690. window.CanvasPixelArray.prototype.set = function (arr) {
  12691. for (var i = 0, ii = this.length; i < ii; i++) {
  12692. this[i] = arr[i];
  12693. }
  12694. };
  12695. }
  12696. } else {
  12697. var polyfill = false,
  12698. versionMatch;
  12699. if (isChrome) {
  12700. versionMatch = userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
  12701. polyfill = versionMatch && parseInt(versionMatch[2]) < 21;
  12702. } else if (isAndroid) {
  12703. polyfill = isAndroidPre5;
  12704. } else if (isSafari) {
  12705. versionMatch = userAgent.match(/Version\/([0-9]+)\.([0-9]+)\.([0-9]+) Safari\//);
  12706. polyfill = versionMatch && parseInt(versionMatch[1]) < 6;
  12707. }
  12708. if (polyfill) {
  12709. var contextPrototype = window.CanvasRenderingContext2D.prototype;
  12710. var createImageData = contextPrototype.createImageData;
  12711. contextPrototype.createImageData = function (w, h) {
  12712. var imageData = createImageData.call(this, w, h);
  12713. imageData.data.set = function (arr) {
  12714. for (var i = 0, ii = this.length; i < ii; i++) {
  12715. this[i] = arr[i];
  12716. }
  12717. };
  12718. return imageData;
  12719. };
  12720. contextPrototype = null;
  12721. }
  12722. }
  12723. })();
  12724. (function checkRequestAnimationFrame() {
  12725. function installFakeAnimationFrameFunctions() {
  12726. window.requestAnimationFrame = function (callback) {
  12727. return window.setTimeout(callback, 20);
  12728. };
  12729. window.cancelAnimationFrame = function (timeoutID) {
  12730. window.clearTimeout(timeoutID);
  12731. };
  12732. }
  12733. if (!hasDOM) {
  12734. return;
  12735. }
  12736. if (isIOS) {
  12737. installFakeAnimationFrameFunctions();
  12738. return;
  12739. }
  12740. if ('requestAnimationFrame' in window) {
  12741. return;
  12742. }
  12743. window.requestAnimationFrame = window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame;
  12744. if (window.requestAnimationFrame) {
  12745. return;
  12746. }
  12747. installFakeAnimationFrameFunctions();
  12748. })();
  12749. (function checkCanvasSizeLimitation() {
  12750. if (isIOS || isAndroid) {
  12751. PDFJS.maxCanvasPixels = 5242880;
  12752. }
  12753. })();
  12754. (function checkFullscreenSupport() {
  12755. if (!hasDOM) {
  12756. return;
  12757. }
  12758. if (isIE && window.parent !== window) {
  12759. PDFJS.disableFullscreen = true;
  12760. }
  12761. })();
  12762. (function checkCurrentScript() {
  12763. if (!hasDOM) {
  12764. return;
  12765. }
  12766. if ('currentScript' in document) {
  12767. return;
  12768. }
  12769. Object.defineProperty(document, 'currentScript', {
  12770. get: function get() {
  12771. var scripts = document.getElementsByTagName('script');
  12772. return scripts[scripts.length - 1];
  12773. },
  12774. enumerable: true,
  12775. configurable: true
  12776. });
  12777. })();
  12778. (function checkInputTypeNumberAssign() {
  12779. if (!hasDOM) {
  12780. return;
  12781. }
  12782. var el = document.createElement('input');
  12783. try {
  12784. el.type = 'number';
  12785. } catch (ex) {
  12786. var inputProto = el.constructor.prototype;
  12787. var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type');
  12788. Object.defineProperty(inputProto, 'type', {
  12789. get: function get() {
  12790. return typeProperty.get.call(this);
  12791. },
  12792. set: function set(value) {
  12793. typeProperty.set.call(this, value === 'number' ? 'text' : value);
  12794. },
  12795. enumerable: true,
  12796. configurable: true
  12797. });
  12798. }
  12799. })();
  12800. (function checkDocumentReadyState() {
  12801. if (!hasDOM) {
  12802. return;
  12803. }
  12804. if (!document.attachEvent) {
  12805. return;
  12806. }
  12807. var documentProto = document.constructor.prototype;
  12808. var readyStateProto = Object.getOwnPropertyDescriptor(documentProto, 'readyState');
  12809. Object.defineProperty(documentProto, 'readyState', {
  12810. get: function get() {
  12811. var value = readyStateProto.get.call(this);
  12812. return value === 'interactive' ? 'loading' : value;
  12813. },
  12814. set: function set(value) {
  12815. readyStateProto.set.call(this, value);
  12816. },
  12817. enumerable: true,
  12818. configurable: true
  12819. });
  12820. })();
  12821. (function checkChildNodeRemove() {
  12822. if (!hasDOM) {
  12823. return;
  12824. }
  12825. if (typeof Element.prototype.remove !== 'undefined') {
  12826. return;
  12827. }
  12828. Element.prototype.remove = function () {
  12829. if (this.parentNode) {
  12830. this.parentNode.removeChild(this);
  12831. }
  12832. };
  12833. })();
  12834. (function checkNumberIsNaN() {
  12835. if (Number.isNaN) {
  12836. return;
  12837. }
  12838. Number.isNaN = function (value) {
  12839. return typeof value === 'number' && isNaN(value);
  12840. };
  12841. })();
  12842. (function checkNumberIsInteger() {
  12843. if (Number.isInteger) {
  12844. return;
  12845. }
  12846. Number.isInteger = function (value) {
  12847. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  12848. };
  12849. })();
  12850. (function checkPromise() {
  12851. if (globalScope.Promise) {
  12852. if (typeof globalScope.Promise.all !== 'function') {
  12853. globalScope.Promise.all = function (iterable) {
  12854. var count = 0,
  12855. results = [],
  12856. resolve,
  12857. reject;
  12858. var promise = new globalScope.Promise(function (resolve_, reject_) {
  12859. resolve = resolve_;
  12860. reject = reject_;
  12861. });
  12862. iterable.forEach(function (p, i) {
  12863. count++;
  12864. p.then(function (result) {
  12865. results[i] = result;
  12866. count--;
  12867. if (count === 0) {
  12868. resolve(results);
  12869. }
  12870. }, reject);
  12871. });
  12872. if (count === 0) {
  12873. resolve(results);
  12874. }
  12875. return promise;
  12876. };
  12877. }
  12878. if (typeof globalScope.Promise.resolve !== 'function') {
  12879. globalScope.Promise.resolve = function (value) {
  12880. return new globalScope.Promise(function (resolve) {
  12881. resolve(value);
  12882. });
  12883. };
  12884. }
  12885. if (typeof globalScope.Promise.reject !== 'function') {
  12886. globalScope.Promise.reject = function (reason) {
  12887. return new globalScope.Promise(function (resolve, reject) {
  12888. reject(reason);
  12889. });
  12890. };
  12891. }
  12892. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  12893. globalScope.Promise.prototype.catch = function (onReject) {
  12894. return globalScope.Promise.prototype.then(undefined, onReject);
  12895. };
  12896. }
  12897. return;
  12898. }
  12899. var STATUS_PENDING = 0;
  12900. var STATUS_RESOLVED = 1;
  12901. var STATUS_REJECTED = 2;
  12902. var REJECTION_TIMEOUT = 500;
  12903. var HandlerManager = {
  12904. handlers: [],
  12905. running: false,
  12906. unhandledRejections: [],
  12907. pendingRejectionCheck: false,
  12908. scheduleHandlers: function scheduleHandlers(promise) {
  12909. if (promise._status === STATUS_PENDING) {
  12910. return;
  12911. }
  12912. this.handlers = this.handlers.concat(promise._handlers);
  12913. promise._handlers = [];
  12914. if (this.running) {
  12915. return;
  12916. }
  12917. this.running = true;
  12918. setTimeout(this.runHandlers.bind(this), 0);
  12919. },
  12920. runHandlers: function runHandlers() {
  12921. var RUN_TIMEOUT = 1;
  12922. var timeoutAt = Date.now() + RUN_TIMEOUT;
  12923. while (this.handlers.length > 0) {
  12924. var handler = this.handlers.shift();
  12925. var nextStatus = handler.thisPromise._status;
  12926. var nextValue = handler.thisPromise._value;
  12927. try {
  12928. if (nextStatus === STATUS_RESOLVED) {
  12929. if (typeof handler.onResolve === 'function') {
  12930. nextValue = handler.onResolve(nextValue);
  12931. }
  12932. } else if (typeof handler.onReject === 'function') {
  12933. nextValue = handler.onReject(nextValue);
  12934. nextStatus = STATUS_RESOLVED;
  12935. if (handler.thisPromise._unhandledRejection) {
  12936. this.removeUnhandeledRejection(handler.thisPromise);
  12937. }
  12938. }
  12939. } catch (ex) {
  12940. nextStatus = STATUS_REJECTED;
  12941. nextValue = ex;
  12942. }
  12943. handler.nextPromise._updateStatus(nextStatus, nextValue);
  12944. if (Date.now() >= timeoutAt) {
  12945. break;
  12946. }
  12947. }
  12948. if (this.handlers.length > 0) {
  12949. setTimeout(this.runHandlers.bind(this), 0);
  12950. return;
  12951. }
  12952. this.running = false;
  12953. },
  12954. addUnhandledRejection: function addUnhandledRejection(promise) {
  12955. this.unhandledRejections.push({
  12956. promise: promise,
  12957. time: Date.now()
  12958. });
  12959. this.scheduleRejectionCheck();
  12960. },
  12961. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  12962. promise._unhandledRejection = false;
  12963. for (var i = 0; i < this.unhandledRejections.length; i++) {
  12964. if (this.unhandledRejections[i].promise === promise) {
  12965. this.unhandledRejections.splice(i);
  12966. i--;
  12967. }
  12968. }
  12969. },
  12970. scheduleRejectionCheck: function scheduleRejectionCheck() {
  12971. var _this = this;
  12972. if (this.pendingRejectionCheck) {
  12973. return;
  12974. }
  12975. this.pendingRejectionCheck = true;
  12976. setTimeout(function () {
  12977. _this.pendingRejectionCheck = false;
  12978. var now = Date.now();
  12979. for (var i = 0; i < _this.unhandledRejections.length; i++) {
  12980. if (now - _this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  12981. var unhandled = _this.unhandledRejections[i].promise._value;
  12982. var msg = 'Unhandled rejection: ' + unhandled;
  12983. if (unhandled.stack) {
  12984. msg += '\n' + unhandled.stack;
  12985. }
  12986. try {
  12987. throw new Error(msg);
  12988. } catch (_) {
  12989. console.warn(msg);
  12990. }
  12991. _this.unhandledRejections.splice(i);
  12992. i--;
  12993. }
  12994. }
  12995. if (_this.unhandledRejections.length) {
  12996. _this.scheduleRejectionCheck();
  12997. }
  12998. }, REJECTION_TIMEOUT);
  12999. }
  13000. };
  13001. var Promise = function Promise(resolver) {
  13002. this._status = STATUS_PENDING;
  13003. this._handlers = [];
  13004. try {
  13005. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  13006. } catch (e) {
  13007. this._reject(e);
  13008. }
  13009. };
  13010. Promise.all = function Promise_all(promises) {
  13011. var resolveAll, rejectAll;
  13012. var deferred = new Promise(function (resolve, reject) {
  13013. resolveAll = resolve;
  13014. rejectAll = reject;
  13015. });
  13016. var unresolved = promises.length;
  13017. var results = [];
  13018. if (unresolved === 0) {
  13019. resolveAll(results);
  13020. return deferred;
  13021. }
  13022. function reject(reason) {
  13023. if (deferred._status === STATUS_REJECTED) {
  13024. return;
  13025. }
  13026. results = [];
  13027. rejectAll(reason);
  13028. }
  13029. for (var i = 0, ii = promises.length; i < ii; ++i) {
  13030. var promise = promises[i];
  13031. var resolve = function (i) {
  13032. return function (value) {
  13033. if (deferred._status === STATUS_REJECTED) {
  13034. return;
  13035. }
  13036. results[i] = value;
  13037. unresolved--;
  13038. if (unresolved === 0) {
  13039. resolveAll(results);
  13040. }
  13041. };
  13042. }(i);
  13043. if (Promise.isPromise(promise)) {
  13044. promise.then(resolve, reject);
  13045. } else {
  13046. resolve(promise);
  13047. }
  13048. }
  13049. return deferred;
  13050. };
  13051. Promise.isPromise = function Promise_isPromise(value) {
  13052. return value && typeof value.then === 'function';
  13053. };
  13054. Promise.resolve = function Promise_resolve(value) {
  13055. return new Promise(function (resolve) {
  13056. resolve(value);
  13057. });
  13058. };
  13059. Promise.reject = function Promise_reject(reason) {
  13060. return new Promise(function (resolve, reject) {
  13061. reject(reason);
  13062. });
  13063. };
  13064. Promise.prototype = {
  13065. _status: null,
  13066. _value: null,
  13067. _handlers: null,
  13068. _unhandledRejection: null,
  13069. _updateStatus: function Promise__updateStatus(status, value) {
  13070. if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) {
  13071. return;
  13072. }
  13073. if (status === STATUS_RESOLVED && Promise.isPromise(value)) {
  13074. value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED));
  13075. return;
  13076. }
  13077. this._status = status;
  13078. this._value = value;
  13079. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  13080. this._unhandledRejection = true;
  13081. HandlerManager.addUnhandledRejection(this);
  13082. }
  13083. HandlerManager.scheduleHandlers(this);
  13084. },
  13085. _resolve: function Promise_resolve(value) {
  13086. this._updateStatus(STATUS_RESOLVED, value);
  13087. },
  13088. _reject: function Promise_reject(reason) {
  13089. this._updateStatus(STATUS_REJECTED, reason);
  13090. },
  13091. then: function Promise_then(onResolve, onReject) {
  13092. var nextPromise = new Promise(function (resolve, reject) {
  13093. this.resolve = resolve;
  13094. this.reject = reject;
  13095. });
  13096. this._handlers.push({
  13097. thisPromise: this,
  13098. onResolve: onResolve,
  13099. onReject: onReject,
  13100. nextPromise: nextPromise
  13101. });
  13102. HandlerManager.scheduleHandlers(this);
  13103. return nextPromise;
  13104. },
  13105. catch: function Promise_catch(onReject) {
  13106. return this.then(undefined, onReject);
  13107. }
  13108. };
  13109. globalScope.Promise = Promise;
  13110. })();
  13111. (function checkWeakMap() {
  13112. if (globalScope.WeakMap) {
  13113. return;
  13114. }
  13115. var id = 0;
  13116. function WeakMap() {
  13117. this.id = '$weakmap' + id++;
  13118. }
  13119. WeakMap.prototype = {
  13120. has: function has(obj) {
  13121. if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object' && typeof obj !== 'function' || obj === null) {
  13122. return false;
  13123. }
  13124. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  13125. },
  13126. get: function get(obj) {
  13127. return this.has(obj) ? obj[this.id] : undefined;
  13128. },
  13129. set: function set(obj, value) {
  13130. Object.defineProperty(obj, this.id, {
  13131. value: value,
  13132. enumerable: false,
  13133. configurable: true
  13134. });
  13135. },
  13136. delete: function _delete(obj) {
  13137. delete obj[this.id];
  13138. }
  13139. };
  13140. globalScope.WeakMap = WeakMap;
  13141. })();
  13142. (function checkURLConstructor() {
  13143. var hasWorkingUrl = false;
  13144. try {
  13145. if (typeof URL === 'function' && _typeof(URL.prototype) === 'object' && 'origin' in URL.prototype) {
  13146. var u = new URL('b', 'http://a');
  13147. u.pathname = 'c%20d';
  13148. hasWorkingUrl = u.href === 'http://a/c%20d';
  13149. }
  13150. } catch (e) {}
  13151. if (hasWorkingUrl) {
  13152. return;
  13153. }
  13154. var relative = Object.create(null);
  13155. relative['ftp'] = 21;
  13156. relative['file'] = 0;
  13157. relative['gopher'] = 70;
  13158. relative['http'] = 80;
  13159. relative['https'] = 443;
  13160. relative['ws'] = 80;
  13161. relative['wss'] = 443;
  13162. var relativePathDotMapping = Object.create(null);
  13163. relativePathDotMapping['%2e'] = '.';
  13164. relativePathDotMapping['.%2e'] = '..';
  13165. relativePathDotMapping['%2e.'] = '..';
  13166. relativePathDotMapping['%2e%2e'] = '..';
  13167. function isRelativeScheme(scheme) {
  13168. return relative[scheme] !== undefined;
  13169. }
  13170. function invalid() {
  13171. clear.call(this);
  13172. this._isInvalid = true;
  13173. }
  13174. function IDNAToASCII(h) {
  13175. if (h === '') {
  13176. invalid.call(this);
  13177. }
  13178. return h.toLowerCase();
  13179. }
  13180. function percentEscape(c) {
  13181. var unicode = c.charCodeAt(0);
  13182. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1) {
  13183. return c;
  13184. }
  13185. return encodeURIComponent(c);
  13186. }
  13187. function percentEscapeQuery(c) {
  13188. var unicode = c.charCodeAt(0);
  13189. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1) {
  13190. return c;
  13191. }
  13192. return encodeURIComponent(c);
  13193. }
  13194. var EOF,
  13195. ALPHA = /[a-zA-Z]/,
  13196. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  13197. function parse(input, stateOverride, base) {
  13198. function err(message) {
  13199. errors.push(message);
  13200. }
  13201. var state = stateOverride || 'scheme start',
  13202. cursor = 0,
  13203. buffer = '',
  13204. seenAt = false,
  13205. seenBracket = false,
  13206. errors = [];
  13207. loop: while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  13208. var c = input[cursor];
  13209. switch (state) {
  13210. case 'scheme start':
  13211. if (c && ALPHA.test(c)) {
  13212. buffer += c.toLowerCase();
  13213. state = 'scheme';
  13214. } else if (!stateOverride) {
  13215. buffer = '';
  13216. state = 'no scheme';
  13217. continue;
  13218. } else {
  13219. err('Invalid scheme.');
  13220. break loop;
  13221. }
  13222. break;
  13223. case 'scheme':
  13224. if (c && ALPHANUMERIC.test(c)) {
  13225. buffer += c.toLowerCase();
  13226. } else if (c === ':') {
  13227. this._scheme = buffer;
  13228. buffer = '';
  13229. if (stateOverride) {
  13230. break loop;
  13231. }
  13232. if (isRelativeScheme(this._scheme)) {
  13233. this._isRelative = true;
  13234. }
  13235. if (this._scheme === 'file') {
  13236. state = 'relative';
  13237. } else if (this._isRelative && base && base._scheme === this._scheme) {
  13238. state = 'relative or authority';
  13239. } else if (this._isRelative) {
  13240. state = 'authority first slash';
  13241. } else {
  13242. state = 'scheme data';
  13243. }
  13244. } else if (!stateOverride) {
  13245. buffer = '';
  13246. cursor = 0;
  13247. state = 'no scheme';
  13248. continue;
  13249. } else if (c === EOF) {
  13250. break loop;
  13251. } else {
  13252. err('Code point not allowed in scheme: ' + c);
  13253. break loop;
  13254. }
  13255. break;
  13256. case 'scheme data':
  13257. if (c === '?') {
  13258. this._query = '?';
  13259. state = 'query';
  13260. } else if (c === '#') {
  13261. this._fragment = '#';
  13262. state = 'fragment';
  13263. } else {
  13264. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  13265. this._schemeData += percentEscape(c);
  13266. }
  13267. }
  13268. break;
  13269. case 'no scheme':
  13270. if (!base || !isRelativeScheme(base._scheme)) {
  13271. err('Missing scheme.');
  13272. invalid.call(this);
  13273. } else {
  13274. state = 'relative';
  13275. continue;
  13276. }
  13277. break;
  13278. case 'relative or authority':
  13279. if (c === '/' && input[cursor + 1] === '/') {
  13280. state = 'authority ignore slashes';
  13281. } else {
  13282. err('Expected /, got: ' + c);
  13283. state = 'relative';
  13284. continue;
  13285. }
  13286. break;
  13287. case 'relative':
  13288. this._isRelative = true;
  13289. if (this._scheme !== 'file') {
  13290. this._scheme = base._scheme;
  13291. }
  13292. if (c === EOF) {
  13293. this._host = base._host;
  13294. this._port = base._port;
  13295. this._path = base._path.slice();
  13296. this._query = base._query;
  13297. this._username = base._username;
  13298. this._password = base._password;
  13299. break loop;
  13300. } else if (c === '/' || c === '\\') {
  13301. if (c === '\\') {
  13302. err('\\ is an invalid code point.');
  13303. }
  13304. state = 'relative slash';
  13305. } else if (c === '?') {
  13306. this._host = base._host;
  13307. this._port = base._port;
  13308. this._path = base._path.slice();
  13309. this._query = '?';
  13310. this._username = base._username;
  13311. this._password = base._password;
  13312. state = 'query';
  13313. } else if (c === '#') {
  13314. this._host = base._host;
  13315. this._port = base._port;
  13316. this._path = base._path.slice();
  13317. this._query = base._query;
  13318. this._fragment = '#';
  13319. this._username = base._username;
  13320. this._password = base._password;
  13321. state = 'fragment';
  13322. } else {
  13323. var nextC = input[cursor + 1];
  13324. var nextNextC = input[cursor + 2];
  13325. if (this._scheme !== 'file' || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || nextNextC !== EOF && nextNextC !== '/' && nextNextC !== '\\' && nextNextC !== '?' && nextNextC !== '#') {
  13326. this._host = base._host;
  13327. this._port = base._port;
  13328. this._username = base._username;
  13329. this._password = base._password;
  13330. this._path = base._path.slice();
  13331. this._path.pop();
  13332. }
  13333. state = 'relative path';
  13334. continue;
  13335. }
  13336. break;
  13337. case 'relative slash':
  13338. if (c === '/' || c === '\\') {
  13339. if (c === '\\') {
  13340. err('\\ is an invalid code point.');
  13341. }
  13342. if (this._scheme === 'file') {
  13343. state = 'file host';
  13344. } else {
  13345. state = 'authority ignore slashes';
  13346. }
  13347. } else {
  13348. if (this._scheme !== 'file') {
  13349. this._host = base._host;
  13350. this._port = base._port;
  13351. this._username = base._username;
  13352. this._password = base._password;
  13353. }
  13354. state = 'relative path';
  13355. continue;
  13356. }
  13357. break;
  13358. case 'authority first slash':
  13359. if (c === '/') {
  13360. state = 'authority second slash';
  13361. } else {
  13362. err('Expected \'/\', got: ' + c);
  13363. state = 'authority ignore slashes';
  13364. continue;
  13365. }
  13366. break;
  13367. case 'authority second slash':
  13368. state = 'authority ignore slashes';
  13369. if (c !== '/') {
  13370. err('Expected \'/\', got: ' + c);
  13371. continue;
  13372. }
  13373. break;
  13374. case 'authority ignore slashes':
  13375. if (c !== '/' && c !== '\\') {
  13376. state = 'authority';
  13377. continue;
  13378. } else {
  13379. err('Expected authority, got: ' + c);
  13380. }
  13381. break;
  13382. case 'authority':
  13383. if (c === '@') {
  13384. if (seenAt) {
  13385. err('@ already seen.');
  13386. buffer += '%40';
  13387. }
  13388. seenAt = true;
  13389. for (var i = 0; i < buffer.length; i++) {
  13390. var cp = buffer[i];
  13391. if (cp === '\t' || cp === '\n' || cp === '\r') {
  13392. err('Invalid whitespace in authority.');
  13393. continue;
  13394. }
  13395. if (cp === ':' && this._password === null) {
  13396. this._password = '';
  13397. continue;
  13398. }
  13399. var tempC = percentEscape(cp);
  13400. if (this._password !== null) {
  13401. this._password += tempC;
  13402. } else {
  13403. this._username += tempC;
  13404. }
  13405. }
  13406. buffer = '';
  13407. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  13408. cursor -= buffer.length;
  13409. buffer = '';
  13410. state = 'host';
  13411. continue;
  13412. } else {
  13413. buffer += c;
  13414. }
  13415. break;
  13416. case 'file host':
  13417. if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  13418. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  13419. state = 'relative path';
  13420. } else if (buffer.length === 0) {
  13421. state = 'relative path start';
  13422. } else {
  13423. this._host = IDNAToASCII.call(this, buffer);
  13424. buffer = '';
  13425. state = 'relative path start';
  13426. }
  13427. continue;
  13428. } else if (c === '\t' || c === '\n' || c === '\r') {
  13429. err('Invalid whitespace in file host.');
  13430. } else {
  13431. buffer += c;
  13432. }
  13433. break;
  13434. case 'host':
  13435. case 'hostname':
  13436. if (c === ':' && !seenBracket) {
  13437. this._host = IDNAToASCII.call(this, buffer);
  13438. buffer = '';
  13439. state = 'port';
  13440. if (stateOverride === 'hostname') {
  13441. break loop;
  13442. }
  13443. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  13444. this._host = IDNAToASCII.call(this, buffer);
  13445. buffer = '';
  13446. state = 'relative path start';
  13447. if (stateOverride) {
  13448. break loop;
  13449. }
  13450. continue;
  13451. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  13452. if (c === '[') {
  13453. seenBracket = true;
  13454. } else if (c === ']') {
  13455. seenBracket = false;
  13456. }
  13457. buffer += c;
  13458. } else {
  13459. err('Invalid code point in host/hostname: ' + c);
  13460. }
  13461. break;
  13462. case 'port':
  13463. if (/[0-9]/.test(c)) {
  13464. buffer += c;
  13465. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) {
  13466. if (buffer !== '') {
  13467. var temp = parseInt(buffer, 10);
  13468. if (temp !== relative[this._scheme]) {
  13469. this._port = temp + '';
  13470. }
  13471. buffer = '';
  13472. }
  13473. if (stateOverride) {
  13474. break loop;
  13475. }
  13476. state = 'relative path start';
  13477. continue;
  13478. } else if (c === '\t' || c === '\n' || c === '\r') {
  13479. err('Invalid code point in port: ' + c);
  13480. } else {
  13481. invalid.call(this);
  13482. }
  13483. break;
  13484. case 'relative path start':
  13485. if (c === '\\') {
  13486. err('\'\\\' not allowed in path.');
  13487. }
  13488. state = 'relative path';
  13489. if (c !== '/' && c !== '\\') {
  13490. continue;
  13491. }
  13492. break;
  13493. case 'relative path':
  13494. if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) {
  13495. if (c === '\\') {
  13496. err('\\ not allowed in relative path.');
  13497. }
  13498. var tmp;
  13499. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  13500. buffer = tmp;
  13501. }
  13502. if (buffer === '..') {
  13503. this._path.pop();
  13504. if (c !== '/' && c !== '\\') {
  13505. this._path.push('');
  13506. }
  13507. } else if (buffer === '.' && c !== '/' && c !== '\\') {
  13508. this._path.push('');
  13509. } else if (buffer !== '.') {
  13510. if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  13511. buffer = buffer[0] + ':';
  13512. }
  13513. this._path.push(buffer);
  13514. }
  13515. buffer = '';
  13516. if (c === '?') {
  13517. this._query = '?';
  13518. state = 'query';
  13519. } else if (c === '#') {
  13520. this._fragment = '#';
  13521. state = 'fragment';
  13522. }
  13523. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  13524. buffer += percentEscape(c);
  13525. }
  13526. break;
  13527. case 'query':
  13528. if (!stateOverride && c === '#') {
  13529. this._fragment = '#';
  13530. state = 'fragment';
  13531. } else if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  13532. this._query += percentEscapeQuery(c);
  13533. }
  13534. break;
  13535. case 'fragment':
  13536. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  13537. this._fragment += c;
  13538. }
  13539. break;
  13540. }
  13541. cursor++;
  13542. }
  13543. }
  13544. function clear() {
  13545. this._scheme = '';
  13546. this._schemeData = '';
  13547. this._username = '';
  13548. this._password = null;
  13549. this._host = '';
  13550. this._port = '';
  13551. this._path = [];
  13552. this._query = '';
  13553. this._fragment = '';
  13554. this._isInvalid = false;
  13555. this._isRelative = false;
  13556. }
  13557. function JURL(url, base) {
  13558. if (base !== undefined && !(base instanceof JURL)) {
  13559. base = new JURL(String(base));
  13560. }
  13561. this._url = url;
  13562. clear.call(this);
  13563. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  13564. parse.call(this, input, null, base);
  13565. }
  13566. JURL.prototype = {
  13567. toString: function toString() {
  13568. return this.href;
  13569. },
  13570. get href() {
  13571. if (this._isInvalid) {
  13572. return this._url;
  13573. }
  13574. var authority = '';
  13575. if (this._username !== '' || this._password !== null) {
  13576. authority = this._username + (this._password !== null ? ':' + this._password : '') + '@';
  13577. }
  13578. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  13579. },
  13580. set href(value) {
  13581. clear.call(this);
  13582. parse.call(this, value);
  13583. },
  13584. get protocol() {
  13585. return this._scheme + ':';
  13586. },
  13587. set protocol(value) {
  13588. if (this._isInvalid) {
  13589. return;
  13590. }
  13591. parse.call(this, value + ':', 'scheme start');
  13592. },
  13593. get host() {
  13594. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  13595. },
  13596. set host(value) {
  13597. if (this._isInvalid || !this._isRelative) {
  13598. return;
  13599. }
  13600. parse.call(this, value, 'host');
  13601. },
  13602. get hostname() {
  13603. return this._host;
  13604. },
  13605. set hostname(value) {
  13606. if (this._isInvalid || !this._isRelative) {
  13607. return;
  13608. }
  13609. parse.call(this, value, 'hostname');
  13610. },
  13611. get port() {
  13612. return this._port;
  13613. },
  13614. set port(value) {
  13615. if (this._isInvalid || !this._isRelative) {
  13616. return;
  13617. }
  13618. parse.call(this, value, 'port');
  13619. },
  13620. get pathname() {
  13621. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  13622. },
  13623. set pathname(value) {
  13624. if (this._isInvalid || !this._isRelative) {
  13625. return;
  13626. }
  13627. this._path = [];
  13628. parse.call(this, value, 'relative path start');
  13629. },
  13630. get search() {
  13631. return this._isInvalid || !this._query || this._query === '?' ? '' : this._query;
  13632. },
  13633. set search(value) {
  13634. if (this._isInvalid || !this._isRelative) {
  13635. return;
  13636. }
  13637. this._query = '?';
  13638. if (value[0] === '?') {
  13639. value = value.slice(1);
  13640. }
  13641. parse.call(this, value, 'query');
  13642. },
  13643. get hash() {
  13644. return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment;
  13645. },
  13646. set hash(value) {
  13647. if (this._isInvalid) {
  13648. return;
  13649. }
  13650. this._fragment = '#';
  13651. if (value[0] === '#') {
  13652. value = value.slice(1);
  13653. }
  13654. parse.call(this, value, 'fragment');
  13655. },
  13656. get origin() {
  13657. var host;
  13658. if (this._isInvalid || !this._scheme) {
  13659. return '';
  13660. }
  13661. switch (this._scheme) {
  13662. case 'data':
  13663. case 'file':
  13664. case 'javascript':
  13665. case 'mailto':
  13666. return 'null';
  13667. case 'blob':
  13668. try {
  13669. return new JURL(this._schemeData).origin || 'null';
  13670. } catch (_) {}
  13671. return 'null';
  13672. }
  13673. host = this.host;
  13674. if (!host) {
  13675. return '';
  13676. }
  13677. return this._scheme + '://' + host;
  13678. }
  13679. };
  13680. var OriginalURL = globalScope.URL;
  13681. if (OriginalURL) {
  13682. JURL.createObjectURL = function (blob) {
  13683. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  13684. };
  13685. JURL.revokeObjectURL = function (url) {
  13686. OriginalURL.revokeObjectURL(url);
  13687. };
  13688. }
  13689. globalScope.URL = JURL;
  13690. })();
  13691. }
  13692. /***/ }),
  13693. /* 17 */
  13694. /***/ (function(module, exports, __w_pdfjs_require__) {
  13695. "use strict";
  13696. var isReadableStreamSupported = false;
  13697. if (typeof ReadableStream !== 'undefined') {
  13698. try {
  13699. new ReadableStream({
  13700. start: function start(controller) {
  13701. controller.close();
  13702. }
  13703. });
  13704. isReadableStreamSupported = true;
  13705. } catch (e) {}
  13706. }
  13707. if (isReadableStreamSupported) {
  13708. exports.ReadableStream = ReadableStream;
  13709. } else {
  13710. exports.ReadableStream = __w_pdfjs_require__(10).ReadableStream;
  13711. }
  13712. /***/ })
  13713. /******/ ]);
  13714. });
  13715. //# sourceMappingURL=pdf.js.map