You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936
  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. if (PDFJS.disableWorker) {
  1548. // use base64 version of cmap binary
  1549. var key = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."));
  1550. var binary_array = get_binary_bcmap(key);
  1551. if (binary_array) {
  1552. resolve({
  1553. cMapData: binary_array,
  1554. compressionType: _this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE
  1555. });
  1556. return;
  1557. }
  1558. reject(new Error('Unable to load ' + (_this.isCompressed ? 'binary ' : '') + 'CMap at: ' + url));
  1559. } else {
  1560. var request = new XMLHttpRequest();
  1561. request.open('GET', url, true);
  1562. if (_this.isCompressed) {
  1563. request.responseType = 'arraybuffer';
  1564. }
  1565. request.onreadystatechange = function () {
  1566. if (request.readyState !== XMLHttpRequest.DONE) {
  1567. return;
  1568. }
  1569. if (request.status === 200 || request.status === 0) {
  1570. var data = void 0;
  1571. if (_this.isCompressed && request.response) {
  1572. data = new Uint8Array(request.response);
  1573. } else if (!_this.isCompressed && request.responseText) {
  1574. data = (0, _util.stringToBytes)(request.responseText);
  1575. }
  1576. if (data) {
  1577. resolve({
  1578. cMapData: data,
  1579. compressionType: _this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE
  1580. });
  1581. return;
  1582. }
  1583. }
  1584. reject(new Error('Unable to load ' + (_this.isCompressed ? 'binary ' : '') + 'CMap at: ' + url));
  1585. };
  1586. request.send(null);
  1587. }
  1588. });
  1589. }
  1590. }]);
  1591. return DOMCMapReaderFactory;
  1592. }();
  1593. var CustomStyle = function CustomStyleClosure() {
  1594. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  1595. var _cache = Object.create(null);
  1596. function CustomStyle() {}
  1597. CustomStyle.getProp = function get(propName, element) {
  1598. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  1599. return _cache[propName];
  1600. }
  1601. element = element || document.documentElement;
  1602. var style = element.style,
  1603. prefixed,
  1604. uPropName;
  1605. if (typeof style[propName] === 'string') {
  1606. return _cache[propName] = propName;
  1607. }
  1608. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  1609. for (var i = 0, l = prefixes.length; i < l; i++) {
  1610. prefixed = prefixes[i] + uPropName;
  1611. if (typeof style[prefixed] === 'string') {
  1612. return _cache[propName] = prefixed;
  1613. }
  1614. }
  1615. return _cache[propName] = 'undefined';
  1616. };
  1617. CustomStyle.setProp = function set(propName, element, str) {
  1618. var prop = this.getProp(propName);
  1619. if (prop !== 'undefined') {
  1620. element.style[prop] = str;
  1621. }
  1622. };
  1623. return CustomStyle;
  1624. }();
  1625. var RenderingCancelledException = function RenderingCancelledException() {
  1626. function RenderingCancelledException(msg, type) {
  1627. this.message = msg;
  1628. this.type = type;
  1629. }
  1630. RenderingCancelledException.prototype = new Error();
  1631. RenderingCancelledException.prototype.name = 'RenderingCancelledException';
  1632. RenderingCancelledException.constructor = RenderingCancelledException;
  1633. return RenderingCancelledException;
  1634. }();
  1635. var LinkTarget = {
  1636. NONE: 0,
  1637. SELF: 1,
  1638. BLANK: 2,
  1639. PARENT: 3,
  1640. TOP: 4
  1641. };
  1642. var LinkTargetStringMap = ['', '_self', '_blank', '_parent', '_top'];
  1643. function addLinkAttributes(link, params) {
  1644. var url = params && params.url;
  1645. link.href = link.title = url ? (0, _util.removeNullCharacters)(url) : '';
  1646. if (url) {
  1647. var target = params.target;
  1648. if (typeof target === 'undefined') {
  1649. target = getDefaultSetting('externalLinkTarget');
  1650. }
  1651. link.target = LinkTargetStringMap[target];
  1652. var rel = params.rel;
  1653. if (typeof rel === 'undefined') {
  1654. rel = getDefaultSetting('externalLinkRel');
  1655. }
  1656. link.rel = rel;
  1657. }
  1658. }
  1659. function getFilenameFromUrl(url) {
  1660. var anchor = url.indexOf('#');
  1661. var query = url.indexOf('?');
  1662. var end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
  1663. return url.substring(url.lastIndexOf('/', end) + 1, end);
  1664. }
  1665. function getDefaultSetting(id) {
  1666. var globalSettings = _util.globalScope.PDFJS;
  1667. switch (id) {
  1668. case 'pdfBug':
  1669. return globalSettings ? globalSettings.pdfBug : false;
  1670. case 'disableAutoFetch':
  1671. return globalSettings ? globalSettings.disableAutoFetch : false;
  1672. case 'disableStream':
  1673. return globalSettings ? globalSettings.disableStream : false;
  1674. case 'disableRange':
  1675. return globalSettings ? globalSettings.disableRange : false;
  1676. case 'disableFontFace':
  1677. return globalSettings ? globalSettings.disableFontFace : false;
  1678. case 'disableCreateObjectURL':
  1679. return globalSettings ? globalSettings.disableCreateObjectURL : false;
  1680. case 'disableWebGL':
  1681. return globalSettings ? globalSettings.disableWebGL : true;
  1682. case 'cMapUrl':
  1683. return globalSettings ? globalSettings.cMapUrl : null;
  1684. case 'cMapPacked':
  1685. return globalSettings ? globalSettings.cMapPacked : false;
  1686. case 'postMessageTransfers':
  1687. return globalSettings ? globalSettings.postMessageTransfers : true;
  1688. case 'workerPort':
  1689. return globalSettings ? globalSettings.workerPort : null;
  1690. case 'workerSrc':
  1691. return globalSettings ? globalSettings.workerSrc : null;
  1692. case 'disableWorker':
  1693. return globalSettings ? globalSettings.disableWorker : false;
  1694. case 'maxImageSize':
  1695. return globalSettings ? globalSettings.maxImageSize : -1;
  1696. case 'imageResourcesPath':
  1697. return globalSettings ? globalSettings.imageResourcesPath : '';
  1698. case 'isEvalSupported':
  1699. return globalSettings ? globalSettings.isEvalSupported : true;
  1700. case 'externalLinkTarget':
  1701. if (!globalSettings) {
  1702. return LinkTarget.NONE;
  1703. }
  1704. switch (globalSettings.externalLinkTarget) {
  1705. case LinkTarget.NONE:
  1706. case LinkTarget.SELF:
  1707. case LinkTarget.BLANK:
  1708. case LinkTarget.PARENT:
  1709. case LinkTarget.TOP:
  1710. return globalSettings.externalLinkTarget;
  1711. }
  1712. (0, _util.warn)('PDFJS.externalLinkTarget is invalid: ' + globalSettings.externalLinkTarget);
  1713. globalSettings.externalLinkTarget = LinkTarget.NONE;
  1714. return LinkTarget.NONE;
  1715. case 'externalLinkRel':
  1716. return globalSettings ? globalSettings.externalLinkRel : DEFAULT_LINK_REL;
  1717. case 'enableStats':
  1718. return !!(globalSettings && globalSettings.enableStats);
  1719. case 'pdfjsNext':
  1720. return !!(globalSettings && globalSettings.pdfjsNext);
  1721. default:
  1722. throw new Error('Unknown default setting: ' + id);
  1723. }
  1724. }
  1725. function isExternalLinkTargetSet() {
  1726. var externalLinkTarget = getDefaultSetting('externalLinkTarget');
  1727. switch (externalLinkTarget) {
  1728. case LinkTarget.NONE:
  1729. return false;
  1730. case LinkTarget.SELF:
  1731. case LinkTarget.BLANK:
  1732. case LinkTarget.PARENT:
  1733. case LinkTarget.TOP:
  1734. return true;
  1735. }
  1736. }
  1737. function isValidUrl(url, allowRelative) {
  1738. (0, _util.deprecated)('isValidUrl(), please use createValidAbsoluteUrl() instead.');
  1739. var baseUrl = allowRelative ? 'http://example.com' : null;
  1740. return (0, _util.createValidAbsoluteUrl)(url, baseUrl) !== null;
  1741. }
  1742. exports.CustomStyle = CustomStyle;
  1743. exports.RenderingCancelledException = RenderingCancelledException;
  1744. exports.addLinkAttributes = addLinkAttributes;
  1745. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  1746. exports.isValidUrl = isValidUrl;
  1747. exports.getFilenameFromUrl = getFilenameFromUrl;
  1748. exports.LinkTarget = LinkTarget;
  1749. exports.getDefaultSetting = getDefaultSetting;
  1750. exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL;
  1751. exports.DOMCanvasFactory = DOMCanvasFactory;
  1752. exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
  1753. /***/ }),
  1754. /* 2 */
  1755. /***/ (function(module, exports, __w_pdfjs_require__) {
  1756. "use strict";
  1757. Object.defineProperty(exports, "__esModule", {
  1758. value: true
  1759. });
  1760. exports.build = exports.version = exports._UnsupportedManager = exports.setPDFNetworkStreamClass = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFWorker = exports.PDFDataRangeTransport = exports.LoopbackPort = exports.getDocument = undefined;
  1761. 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; }; }();
  1762. 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; };
  1763. var _util = __w_pdfjs_require__(0);
  1764. var _dom_utils = __w_pdfjs_require__(1);
  1765. var _font_loader = __w_pdfjs_require__(12);
  1766. var _canvas = __w_pdfjs_require__(11);
  1767. var _metadata = __w_pdfjs_require__(6);
  1768. var _transport_stream = __w_pdfjs_require__(14);
  1769. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1770. var DEFAULT_RANGE_CHUNK_SIZE = 65536;
  1771. var isWorkerDisabled = false;
  1772. var workerSrc;
  1773. var isPostMessageTransfersDisabled = false;
  1774. var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : null;
  1775. var fakeWorkerFilesLoader = null;
  1776. var useRequireEnsure = false;
  1777. {
  1778. if (typeof window === 'undefined') {
  1779. isWorkerDisabled = true;
  1780. if (typeof require.ensure === 'undefined') {
  1781. require.ensure = require('node-ensure');
  1782. }
  1783. useRequireEnsure = true;
  1784. } else if (typeof require !== 'undefined' && typeof require.ensure === 'function') {
  1785. useRequireEnsure = true;
  1786. }
  1787. if (typeof requirejs !== 'undefined' && requirejs.toUrl) {
  1788. workerSrc = requirejs.toUrl('pdfjs-dist/build/pdf.worker.js');
  1789. }
  1790. var dynamicLoaderSupported = typeof requirejs !== 'undefined' && requirejs.load;
  1791. fakeWorkerFilesLoader = useRequireEnsure ? function (callback) {
  1792. require.ensure([], function () {
  1793. var worker;
  1794. worker = require('./pdf.worker.js');
  1795. callback(worker.WorkerMessageHandler);
  1796. });
  1797. } : dynamicLoaderSupported ? function (callback) {
  1798. requirejs(['pdfjs-dist/build/pdf.worker'], function (worker) {
  1799. callback(worker.WorkerMessageHandler);
  1800. });
  1801. } : null;
  1802. }
  1803. var PDFNetworkStream;
  1804. function setPDFNetworkStreamClass(cls) {
  1805. PDFNetworkStream = cls;
  1806. }
  1807. function getDocument(src, pdfDataRangeTransport, passwordCallback, progressCallback) {
  1808. var task = new PDFDocumentLoadingTask();
  1809. if (arguments.length > 1) {
  1810. (0, _util.deprecated)('getDocument is called with pdfDataRangeTransport, ' + 'passwordCallback or progressCallback argument');
  1811. }
  1812. if (pdfDataRangeTransport) {
  1813. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  1814. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  1815. pdfDataRangeTransport.length = src.length;
  1816. pdfDataRangeTransport.initialData = src.initialData;
  1817. if (!pdfDataRangeTransport.abort) {
  1818. pdfDataRangeTransport.abort = function () {};
  1819. }
  1820. }
  1821. src = Object.create(src);
  1822. src.range = pdfDataRangeTransport;
  1823. }
  1824. task.onPassword = passwordCallback || null;
  1825. task.onProgress = progressCallback || null;
  1826. var source;
  1827. if (typeof src === 'string') {
  1828. source = { url: src };
  1829. } else if ((0, _util.isArrayBuffer)(src)) {
  1830. source = { data: src };
  1831. } else if (src instanceof PDFDataRangeTransport) {
  1832. source = { range: src };
  1833. } else {
  1834. if ((typeof src === 'undefined' ? 'undefined' : _typeof(src)) !== 'object') {
  1835. throw new Error('Invalid parameter in getDocument, ' + 'need either Uint8Array, string or a parameter object');
  1836. }
  1837. if (!src.url && !src.data && !src.range) {
  1838. throw new Error('Invalid parameter object: need either .data, .range or .url');
  1839. }
  1840. source = src;
  1841. }
  1842. var params = {};
  1843. var rangeTransport = null;
  1844. var worker = null;
  1845. var CMapReaderFactory = _dom_utils.DOMCMapReaderFactory;
  1846. for (var key in source) {
  1847. if (key === 'url' && typeof window !== 'undefined') {
  1848. params[key] = new URL(source[key], window.location).href;
  1849. continue;
  1850. } else if (key === 'range') {
  1851. rangeTransport = source[key];
  1852. continue;
  1853. } else if (key === 'worker') {
  1854. worker = source[key];
  1855. continue;
  1856. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  1857. var pdfBytes = source[key];
  1858. if (typeof pdfBytes === 'string') {
  1859. params[key] = (0, _util.stringToBytes)(pdfBytes);
  1860. } else if ((typeof pdfBytes === 'undefined' ? 'undefined' : _typeof(pdfBytes)) === 'object' && pdfBytes !== null && !isNaN(pdfBytes.length)) {
  1861. params[key] = new Uint8Array(pdfBytes);
  1862. } else if ((0, _util.isArrayBuffer)(pdfBytes)) {
  1863. params[key] = new Uint8Array(pdfBytes);
  1864. } else {
  1865. throw new Error('Invalid PDF binary data: either typed array, ' + 'string or array-like object is expected in the ' + 'data property.');
  1866. }
  1867. continue;
  1868. } else if (key === 'CMapReaderFactory') {
  1869. CMapReaderFactory = source[key];
  1870. continue;
  1871. }
  1872. params[key] = source[key];
  1873. }
  1874. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  1875. params.ignoreErrors = params.stopAtErrors !== true;
  1876. if (params.disableNativeImageDecoder !== undefined) {
  1877. (0, _util.deprecated)('parameter disableNativeImageDecoder, ' + 'use nativeImageDecoderSupport instead');
  1878. }
  1879. params.nativeImageDecoderSupport = params.nativeImageDecoderSupport || (params.disableNativeImageDecoder === true ? _util.NativeImageDecoding.NONE : _util.NativeImageDecoding.DECODE);
  1880. if (params.nativeImageDecoderSupport !== _util.NativeImageDecoding.DECODE && params.nativeImageDecoderSupport !== _util.NativeImageDecoding.NONE && params.nativeImageDecoderSupport !== _util.NativeImageDecoding.DISPLAY) {
  1881. (0, _util.warn)('Invalid parameter nativeImageDecoderSupport: ' + 'need a state of enum {NativeImageDecoding}');
  1882. params.nativeImageDecoderSupport = _util.NativeImageDecoding.DECODE;
  1883. }
  1884. if (!worker) {
  1885. var workerPort = (0, _dom_utils.getDefaultSetting)('workerPort');
  1886. worker = workerPort ? PDFWorker.fromPort(workerPort) : new PDFWorker();
  1887. task._worker = worker;
  1888. }
  1889. var docId = task.docId;
  1890. worker.promise.then(function () {
  1891. if (task.destroyed) {
  1892. throw new Error('Loading aborted');
  1893. }
  1894. return _fetchDocument(worker, params, rangeTransport, docId).then(function (workerId) {
  1895. if (task.destroyed) {
  1896. throw new Error('Loading aborted');
  1897. }
  1898. var networkStream = void 0;
  1899. if (rangeTransport) {
  1900. networkStream = new _transport_stream.PDFDataTransportStream(params, rangeTransport);
  1901. } else if (!params.data) {
  1902. networkStream = new PDFNetworkStream({
  1903. source: params,
  1904. disableRange: (0, _dom_utils.getDefaultSetting)('disableRange')
  1905. });
  1906. }
  1907. var messageHandler = new _util.MessageHandler(docId, workerId, worker.port);
  1908. messageHandler.postMessageTransfers = worker.postMessageTransfers;
  1909. var transport = new WorkerTransport(messageHandler, task, networkStream, CMapReaderFactory);
  1910. task._transport = transport;
  1911. messageHandler.send('Ready', null);
  1912. });
  1913. }).catch(task._capability.reject);
  1914. return task;
  1915. }
  1916. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  1917. if (worker.destroyed) {
  1918. return Promise.reject(new Error('Worker was destroyed'));
  1919. }
  1920. source.disableAutoFetch = (0, _dom_utils.getDefaultSetting)('disableAutoFetch');
  1921. source.disableStream = (0, _dom_utils.getDefaultSetting)('disableStream');
  1922. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  1923. if (pdfDataRangeTransport) {
  1924. source.length = pdfDataRangeTransport.length;
  1925. source.initialData = pdfDataRangeTransport.initialData;
  1926. }
  1927. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  1928. docId: docId,
  1929. source: {
  1930. data: source.data,
  1931. url: source.url,
  1932. password: source.password,
  1933. disableAutoFetch: source.disableAutoFetch,
  1934. rangeChunkSize: source.rangeChunkSize,
  1935. length: source.length
  1936. },
  1937. maxImageSize: (0, _dom_utils.getDefaultSetting)('maxImageSize'),
  1938. disableFontFace: (0, _dom_utils.getDefaultSetting)('disableFontFace'),
  1939. disableCreateObjectURL: (0, _dom_utils.getDefaultSetting)('disableCreateObjectURL'),
  1940. postMessageTransfers: (0, _dom_utils.getDefaultSetting)('postMessageTransfers') && !isPostMessageTransfersDisabled,
  1941. docBaseUrl: source.docBaseUrl,
  1942. nativeImageDecoderSupport: source.nativeImageDecoderSupport,
  1943. ignoreErrors: source.ignoreErrors
  1944. }).then(function (workerId) {
  1945. if (worker.destroyed) {
  1946. throw new Error('Worker was destroyed');
  1947. }
  1948. return workerId;
  1949. });
  1950. }
  1951. var PDFDocumentLoadingTask = function PDFDocumentLoadingTaskClosure() {
  1952. var nextDocumentId = 0;
  1953. function PDFDocumentLoadingTask() {
  1954. this._capability = (0, _util.createPromiseCapability)();
  1955. this._transport = null;
  1956. this._worker = null;
  1957. this.docId = 'd' + nextDocumentId++;
  1958. this.destroyed = false;
  1959. this.onPassword = null;
  1960. this.onProgress = null;
  1961. this.onUnsupportedFeature = null;
  1962. }
  1963. PDFDocumentLoadingTask.prototype = {
  1964. get promise() {
  1965. return this._capability.promise;
  1966. },
  1967. destroy: function destroy() {
  1968. var _this = this;
  1969. this.destroyed = true;
  1970. var transportDestroyed = !this._transport ? Promise.resolve() : this._transport.destroy();
  1971. return transportDestroyed.then(function () {
  1972. _this._transport = null;
  1973. if (_this._worker) {
  1974. _this._worker.destroy();
  1975. _this._worker = null;
  1976. }
  1977. });
  1978. },
  1979. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  1980. return this.promise.then.apply(this.promise, arguments);
  1981. }
  1982. };
  1983. return PDFDocumentLoadingTask;
  1984. }();
  1985. var PDFDataRangeTransport = function pdfDataRangeTransportClosure() {
  1986. function PDFDataRangeTransport(length, initialData) {
  1987. this.length = length;
  1988. this.initialData = initialData;
  1989. this._rangeListeners = [];
  1990. this._progressListeners = [];
  1991. this._progressiveReadListeners = [];
  1992. this._readyCapability = (0, _util.createPromiseCapability)();
  1993. }
  1994. PDFDataRangeTransport.prototype = {
  1995. addRangeListener: function PDFDataRangeTransport_addRangeListener(listener) {
  1996. this._rangeListeners.push(listener);
  1997. },
  1998. addProgressListener: function PDFDataRangeTransport_addProgressListener(listener) {
  1999. this._progressListeners.push(listener);
  2000. },
  2001. addProgressiveReadListener: function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  2002. this._progressiveReadListeners.push(listener);
  2003. },
  2004. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  2005. var listeners = this._rangeListeners;
  2006. for (var i = 0, n = listeners.length; i < n; ++i) {
  2007. listeners[i](begin, chunk);
  2008. }
  2009. },
  2010. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  2011. var _this2 = this;
  2012. this._readyCapability.promise.then(function () {
  2013. var listeners = _this2._progressListeners;
  2014. for (var i = 0, n = listeners.length; i < n; ++i) {
  2015. listeners[i](loaded);
  2016. }
  2017. });
  2018. },
  2019. onDataProgressiveRead: function PDFDataRangeTransport_onDataProgress(chunk) {
  2020. var _this3 = this;
  2021. this._readyCapability.promise.then(function () {
  2022. var listeners = _this3._progressiveReadListeners;
  2023. for (var i = 0, n = listeners.length; i < n; ++i) {
  2024. listeners[i](chunk);
  2025. }
  2026. });
  2027. },
  2028. transportReady: function PDFDataRangeTransport_transportReady() {
  2029. this._readyCapability.resolve();
  2030. },
  2031. requestDataRange: function PDFDataRangeTransport_requestDataRange(begin, end) {
  2032. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  2033. },
  2034. abort: function PDFDataRangeTransport_abort() {}
  2035. };
  2036. return PDFDataRangeTransport;
  2037. }();
  2038. var PDFDocumentProxy = function PDFDocumentProxyClosure() {
  2039. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  2040. this.pdfInfo = pdfInfo;
  2041. this.transport = transport;
  2042. this.loadingTask = loadingTask;
  2043. }
  2044. PDFDocumentProxy.prototype = {
  2045. get numPages() {
  2046. return this.pdfInfo.numPages;
  2047. },
  2048. get fingerprint() {
  2049. return this.pdfInfo.fingerprint;
  2050. },
  2051. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  2052. return this.transport.getPage(pageNumber);
  2053. },
  2054. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  2055. return this.transport.getPageIndex(ref);
  2056. },
  2057. getDestinations: function PDFDocumentProxy_getDestinations() {
  2058. return this.transport.getDestinations();
  2059. },
  2060. getDestination: function PDFDocumentProxy_getDestination(id) {
  2061. return this.transport.getDestination(id);
  2062. },
  2063. getPageLabels: function PDFDocumentProxy_getPageLabels() {
  2064. return this.transport.getPageLabels();
  2065. },
  2066. getPageMode: function getPageMode() {
  2067. return this.transport.getPageMode();
  2068. },
  2069. getAttachments: function PDFDocumentProxy_getAttachments() {
  2070. return this.transport.getAttachments();
  2071. },
  2072. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  2073. return this.transport.getJavaScript();
  2074. },
  2075. getOutline: function PDFDocumentProxy_getOutline() {
  2076. return this.transport.getOutline();
  2077. },
  2078. getMetadata: function PDFDocumentProxy_getMetadata() {
  2079. return this.transport.getMetadata();
  2080. },
  2081. getData: function PDFDocumentProxy_getData() {
  2082. return this.transport.getData();
  2083. },
  2084. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  2085. return this.transport.downloadInfoCapability.promise;
  2086. },
  2087. getStats: function PDFDocumentProxy_getStats() {
  2088. return this.transport.getStats();
  2089. },
  2090. cleanup: function PDFDocumentProxy_cleanup() {
  2091. this.transport.startCleanup();
  2092. },
  2093. destroy: function PDFDocumentProxy_destroy() {
  2094. return this.loadingTask.destroy();
  2095. }
  2096. };
  2097. return PDFDocumentProxy;
  2098. }();
  2099. var PDFPageProxy = function PDFPageProxyClosure() {
  2100. function PDFPageProxy(pageIndex, pageInfo, transport) {
  2101. this.pageIndex = pageIndex;
  2102. this.pageInfo = pageInfo;
  2103. this.transport = transport;
  2104. this.stats = new _util.StatTimer();
  2105. this.stats.enabled = (0, _dom_utils.getDefaultSetting)('enableStats');
  2106. this.commonObjs = transport.commonObjs;
  2107. this.objs = new PDFObjects();
  2108. this.cleanupAfterRender = false;
  2109. this.pendingCleanup = false;
  2110. this.intentStates = Object.create(null);
  2111. this.destroyed = false;
  2112. }
  2113. PDFPageProxy.prototype = {
  2114. get pageNumber() {
  2115. return this.pageIndex + 1;
  2116. },
  2117. get rotate() {
  2118. return this.pageInfo.rotate;
  2119. },
  2120. get ref() {
  2121. return this.pageInfo.ref;
  2122. },
  2123. get userUnit() {
  2124. return this.pageInfo.userUnit;
  2125. },
  2126. get view() {
  2127. return this.pageInfo.view;
  2128. },
  2129. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  2130. if (arguments.length < 2) {
  2131. rotate = this.rotate;
  2132. }
  2133. return new _util.PageViewport(this.view, scale, rotate, 0, 0);
  2134. },
  2135. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  2136. var intent = params && params.intent || null;
  2137. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  2138. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex, intent);
  2139. this.annotationsIntent = intent;
  2140. }
  2141. return this.annotationsPromise;
  2142. },
  2143. render: function PDFPageProxy_render(params) {
  2144. var _this4 = this;
  2145. var stats = this.stats;
  2146. stats.time('Overall');
  2147. this.pendingCleanup = false;
  2148. var renderingIntent = params.intent === 'print' ? 'print' : 'display';
  2149. var canvasFactory = params.canvasFactory || new _dom_utils.DOMCanvasFactory();
  2150. if (!this.intentStates[renderingIntent]) {
  2151. this.intentStates[renderingIntent] = Object.create(null);
  2152. }
  2153. var intentState = this.intentStates[renderingIntent];
  2154. if (!intentState.displayReadyCapability) {
  2155. intentState.receivingOperatorList = true;
  2156. intentState.displayReadyCapability = (0, _util.createPromiseCapability)();
  2157. intentState.operatorList = {
  2158. fnArray: [],
  2159. argsArray: [],
  2160. lastChunk: false
  2161. };
  2162. this.stats.time('Page Request');
  2163. this.transport.messageHandler.send('RenderPageRequest', {
  2164. pageIndex: this.pageNumber - 1,
  2165. intent: renderingIntent,
  2166. renderInteractiveForms: params.renderInteractiveForms === true
  2167. });
  2168. }
  2169. var complete = function complete(error) {
  2170. var i = intentState.renderTasks.indexOf(internalRenderTask);
  2171. if (i >= 0) {
  2172. intentState.renderTasks.splice(i, 1);
  2173. }
  2174. if (_this4.cleanupAfterRender) {
  2175. _this4.pendingCleanup = true;
  2176. }
  2177. _this4._tryCleanup();
  2178. if (error) {
  2179. internalRenderTask.capability.reject(error);
  2180. } else {
  2181. internalRenderTask.capability.resolve();
  2182. }
  2183. stats.timeEnd('Rendering');
  2184. stats.timeEnd('Overall');
  2185. };
  2186. var internalRenderTask = new InternalRenderTask(complete, params, this.objs, this.commonObjs, intentState.operatorList, this.pageNumber, canvasFactory);
  2187. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  2188. if (!intentState.renderTasks) {
  2189. intentState.renderTasks = [];
  2190. }
  2191. intentState.renderTasks.push(internalRenderTask);
  2192. var renderTask = internalRenderTask.task;
  2193. if (params.continueCallback) {
  2194. (0, _util.deprecated)('render is used with continueCallback parameter');
  2195. renderTask.onContinue = params.continueCallback;
  2196. }
  2197. intentState.displayReadyCapability.promise.then(function (transparency) {
  2198. if (_this4.pendingCleanup) {
  2199. complete();
  2200. return;
  2201. }
  2202. stats.time('Rendering');
  2203. internalRenderTask.initializeGraphics(transparency);
  2204. internalRenderTask.operatorListChanged();
  2205. }).catch(complete);
  2206. return renderTask;
  2207. },
  2208. getOperatorList: function PDFPageProxy_getOperatorList() {
  2209. function operatorListChanged() {
  2210. if (intentState.operatorList.lastChunk) {
  2211. intentState.opListReadCapability.resolve(intentState.operatorList);
  2212. var i = intentState.renderTasks.indexOf(opListTask);
  2213. if (i >= 0) {
  2214. intentState.renderTasks.splice(i, 1);
  2215. }
  2216. }
  2217. }
  2218. var renderingIntent = 'oplist';
  2219. if (!this.intentStates[renderingIntent]) {
  2220. this.intentStates[renderingIntent] = Object.create(null);
  2221. }
  2222. var intentState = this.intentStates[renderingIntent];
  2223. var opListTask;
  2224. if (!intentState.opListReadCapability) {
  2225. opListTask = {};
  2226. opListTask.operatorListChanged = operatorListChanged;
  2227. intentState.receivingOperatorList = true;
  2228. intentState.opListReadCapability = (0, _util.createPromiseCapability)();
  2229. intentState.renderTasks = [];
  2230. intentState.renderTasks.push(opListTask);
  2231. intentState.operatorList = {
  2232. fnArray: [],
  2233. argsArray: [],
  2234. lastChunk: false
  2235. };
  2236. this.transport.messageHandler.send('RenderPageRequest', {
  2237. pageIndex: this.pageIndex,
  2238. intent: renderingIntent
  2239. });
  2240. }
  2241. return intentState.opListReadCapability.promise;
  2242. },
  2243. streamTextContent: function streamTextContent() {
  2244. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  2245. var TEXT_CONTENT_CHUNK_SIZE = 100;
  2246. return this.transport.messageHandler.sendWithStream('GetTextContent', {
  2247. pageIndex: this.pageNumber - 1,
  2248. normalizeWhitespace: params.normalizeWhitespace === true,
  2249. combineTextItems: params.disableCombineTextItems !== true
  2250. }, {
  2251. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  2252. size: function size(textContent) {
  2253. return textContent.items.length;
  2254. }
  2255. });
  2256. },
  2257. getTextContent: function PDFPageProxy_getTextContent(params) {
  2258. params = params || {};
  2259. var readableStream = this.streamTextContent(params);
  2260. return new Promise(function (resolve, reject) {
  2261. function pump() {
  2262. reader.read().then(function (_ref) {
  2263. var value = _ref.value,
  2264. done = _ref.done;
  2265. if (done) {
  2266. resolve(textContent);
  2267. return;
  2268. }
  2269. _util.Util.extendObj(textContent.styles, value.styles);
  2270. _util.Util.appendToArray(textContent.items, value.items);
  2271. pump();
  2272. }, reject);
  2273. }
  2274. var reader = readableStream.getReader();
  2275. var textContent = {
  2276. items: [],
  2277. styles: Object.create(null)
  2278. };
  2279. pump();
  2280. });
  2281. },
  2282. _destroy: function PDFPageProxy_destroy() {
  2283. this.destroyed = true;
  2284. this.transport.pageCache[this.pageIndex] = null;
  2285. var waitOn = [];
  2286. Object.keys(this.intentStates).forEach(function (intent) {
  2287. if (intent === 'oplist') {
  2288. return;
  2289. }
  2290. var intentState = this.intentStates[intent];
  2291. intentState.renderTasks.forEach(function (renderTask) {
  2292. var renderCompleted = renderTask.capability.promise.catch(function () {});
  2293. waitOn.push(renderCompleted);
  2294. renderTask.cancel();
  2295. });
  2296. }, this);
  2297. this.objs.clear();
  2298. this.annotationsPromise = null;
  2299. this.pendingCleanup = false;
  2300. return Promise.all(waitOn);
  2301. },
  2302. destroy: function destroy() {
  2303. (0, _util.deprecated)('page destroy method, use cleanup() instead');
  2304. this.cleanup();
  2305. },
  2306. cleanup: function PDFPageProxy_cleanup() {
  2307. this.pendingCleanup = true;
  2308. this._tryCleanup();
  2309. },
  2310. _tryCleanup: function PDFPageProxy_tryCleanup() {
  2311. if (!this.pendingCleanup || Object.keys(this.intentStates).some(function (intent) {
  2312. var intentState = this.intentStates[intent];
  2313. return intentState.renderTasks.length !== 0 || intentState.receivingOperatorList;
  2314. }, this)) {
  2315. return;
  2316. }
  2317. Object.keys(this.intentStates).forEach(function (intent) {
  2318. delete this.intentStates[intent];
  2319. }, this);
  2320. this.objs.clear();
  2321. this.annotationsPromise = null;
  2322. this.pendingCleanup = false;
  2323. },
  2324. _startRenderPage: function PDFPageProxy_startRenderPage(transparency, intent) {
  2325. var intentState = this.intentStates[intent];
  2326. if (intentState.displayReadyCapability) {
  2327. intentState.displayReadyCapability.resolve(transparency);
  2328. }
  2329. },
  2330. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk, intent) {
  2331. var intentState = this.intentStates[intent];
  2332. var i, ii;
  2333. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2334. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2335. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  2336. }
  2337. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2338. for (i = 0; i < intentState.renderTasks.length; i++) {
  2339. intentState.renderTasks[i].operatorListChanged();
  2340. }
  2341. if (operatorListChunk.lastChunk) {
  2342. intentState.receivingOperatorList = false;
  2343. this._tryCleanup();
  2344. }
  2345. }
  2346. };
  2347. return PDFPageProxy;
  2348. }();
  2349. var LoopbackPort = function () {
  2350. function LoopbackPort(defer) {
  2351. _classCallCheck(this, LoopbackPort);
  2352. this._listeners = [];
  2353. this._defer = defer;
  2354. this._deferred = Promise.resolve(undefined);
  2355. }
  2356. _createClass(LoopbackPort, [{
  2357. key: 'postMessage',
  2358. value: function postMessage(obj, transfers) {
  2359. var _this5 = this;
  2360. function cloneValue(value) {
  2361. if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) !== 'object' || value === null) {
  2362. return value;
  2363. }
  2364. if (cloned.has(value)) {
  2365. return cloned.get(value);
  2366. }
  2367. var result;
  2368. var buffer;
  2369. if ((buffer = value.buffer) && (0, _util.isArrayBuffer)(buffer)) {
  2370. var transferable = transfers && transfers.indexOf(buffer) >= 0;
  2371. if (value === buffer) {
  2372. result = value;
  2373. } else if (transferable) {
  2374. result = new value.constructor(buffer, value.byteOffset, value.byteLength);
  2375. } else {
  2376. result = new value.constructor(value);
  2377. }
  2378. cloned.set(value, result);
  2379. return result;
  2380. }
  2381. result = (0, _util.isArray)(value) ? [] : {};
  2382. cloned.set(value, result);
  2383. for (var i in value) {
  2384. var desc,
  2385. p = value;
  2386. while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
  2387. p = Object.getPrototypeOf(p);
  2388. }
  2389. if (typeof desc.value === 'undefined' || typeof desc.value === 'function') {
  2390. continue;
  2391. }
  2392. result[i] = cloneValue(desc.value);
  2393. }
  2394. return result;
  2395. }
  2396. if (!this._defer) {
  2397. this._listeners.forEach(function (listener) {
  2398. listener.call(this, { data: obj });
  2399. }, this);
  2400. return;
  2401. }
  2402. var cloned = new WeakMap();
  2403. var e = { data: cloneValue(obj) };
  2404. this._deferred.then(function () {
  2405. _this5._listeners.forEach(function (listener) {
  2406. listener.call(this, e);
  2407. }, _this5);
  2408. });
  2409. }
  2410. }, {
  2411. key: 'addEventListener',
  2412. value: function addEventListener(name, listener) {
  2413. this._listeners.push(listener);
  2414. }
  2415. }, {
  2416. key: 'removeEventListener',
  2417. value: function removeEventListener(name, listener) {
  2418. var i = this._listeners.indexOf(listener);
  2419. this._listeners.splice(i, 1);
  2420. }
  2421. }, {
  2422. key: 'terminate',
  2423. value: function terminate() {
  2424. this._listeners = [];
  2425. }
  2426. }]);
  2427. return LoopbackPort;
  2428. }();
  2429. var PDFWorker = function PDFWorkerClosure() {
  2430. var nextFakeWorkerId = 0;
  2431. function getWorkerSrc() {
  2432. if (typeof workerSrc !== 'undefined') {
  2433. return workerSrc;
  2434. }
  2435. if ((0, _dom_utils.getDefaultSetting)('workerSrc')) {
  2436. return (0, _dom_utils.getDefaultSetting)('workerSrc');
  2437. }
  2438. if (pdfjsFilePath) {
  2439. return pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, '.worker$1$2');
  2440. }
  2441. throw new Error('No PDFJS.workerSrc specified');
  2442. }
  2443. var fakeWorkerFilesLoadedCapability = void 0;
  2444. function setupFakeWorkerGlobal() {
  2445. var WorkerMessageHandler;
  2446. if (fakeWorkerFilesLoadedCapability) {
  2447. return fakeWorkerFilesLoadedCapability.promise;
  2448. }
  2449. fakeWorkerFilesLoadedCapability = (0, _util.createPromiseCapability)();
  2450. var loader = fakeWorkerFilesLoader || function (callback) {
  2451. _util.Util.loadScript(getWorkerSrc(), function () {
  2452. callback(window.pdfjsDistBuildPdfWorker.WorkerMessageHandler);
  2453. });
  2454. };
  2455. loader(fakeWorkerFilesLoadedCapability.resolve);
  2456. return fakeWorkerFilesLoadedCapability.promise;
  2457. }
  2458. function createCDNWrapper(url) {
  2459. var wrapper = 'importScripts(\'' + url + '\');';
  2460. return URL.createObjectURL(new Blob([wrapper]));
  2461. }
  2462. var pdfWorkerPorts = new WeakMap();
  2463. function PDFWorker(name, port) {
  2464. if (port && pdfWorkerPorts.has(port)) {
  2465. throw new Error('Cannot use more than one PDFWorker per port');
  2466. }
  2467. this.name = name;
  2468. this.destroyed = false;
  2469. this.postMessageTransfers = true;
  2470. this._readyCapability = (0, _util.createPromiseCapability)();
  2471. this._port = null;
  2472. this._webWorker = null;
  2473. this._messageHandler = null;
  2474. if (port) {
  2475. pdfWorkerPorts.set(port, this);
  2476. this._initializeFromPort(port);
  2477. return;
  2478. }
  2479. this._initialize();
  2480. }
  2481. PDFWorker.prototype = {
  2482. get promise() {
  2483. return this._readyCapability.promise;
  2484. },
  2485. get port() {
  2486. return this._port;
  2487. },
  2488. get messageHandler() {
  2489. return this._messageHandler;
  2490. },
  2491. _initializeFromPort: function PDFWorker_initializeFromPort(port) {
  2492. this._port = port;
  2493. this._messageHandler = new _util.MessageHandler('main', 'worker', port);
  2494. this._messageHandler.on('ready', function () {});
  2495. this._readyCapability.resolve();
  2496. },
  2497. _initialize: function PDFWorker_initialize() {
  2498. var _this6 = this;
  2499. if (!isWorkerDisabled && !(0, _dom_utils.getDefaultSetting)('disableWorker') && typeof Worker !== 'undefined') {
  2500. var workerSrc = getWorkerSrc();
  2501. try {
  2502. if (!(0, _util.isSameOrigin)(window.location.href, workerSrc)) {
  2503. workerSrc = createCDNWrapper(new URL(workerSrc, window.location).href);
  2504. }
  2505. var worker = new Worker(workerSrc);
  2506. var messageHandler = new _util.MessageHandler('main', 'worker', worker);
  2507. var terminateEarly = function terminateEarly() {
  2508. worker.removeEventListener('error', onWorkerError);
  2509. messageHandler.destroy();
  2510. worker.terminate();
  2511. if (_this6.destroyed) {
  2512. _this6._readyCapability.reject(new Error('Worker was destroyed'));
  2513. } else {
  2514. _this6._setupFakeWorker();
  2515. }
  2516. };
  2517. var onWorkerError = function onWorkerError() {
  2518. if (!_this6._webWorker) {
  2519. terminateEarly();
  2520. }
  2521. };
  2522. worker.addEventListener('error', onWorkerError);
  2523. messageHandler.on('test', function (data) {
  2524. worker.removeEventListener('error', onWorkerError);
  2525. if (_this6.destroyed) {
  2526. terminateEarly();
  2527. return;
  2528. }
  2529. var supportTypedArray = data && data.supportTypedArray;
  2530. if (supportTypedArray) {
  2531. _this6._messageHandler = messageHandler;
  2532. _this6._port = worker;
  2533. _this6._webWorker = worker;
  2534. if (!data.supportTransfers) {
  2535. _this6.postMessageTransfers = false;
  2536. isPostMessageTransfersDisabled = true;
  2537. }
  2538. _this6._readyCapability.resolve();
  2539. messageHandler.send('configure', { verbosity: (0, _util.getVerbosityLevel)() });
  2540. } else {
  2541. _this6._setupFakeWorker();
  2542. messageHandler.destroy();
  2543. worker.terminate();
  2544. }
  2545. });
  2546. messageHandler.on('console_log', function (data) {
  2547. console.log.apply(console, data);
  2548. });
  2549. messageHandler.on('console_error', function (data) {
  2550. console.error.apply(console, data);
  2551. });
  2552. messageHandler.on('ready', function (data) {
  2553. worker.removeEventListener('error', onWorkerError);
  2554. if (_this6.destroyed) {
  2555. terminateEarly();
  2556. return;
  2557. }
  2558. try {
  2559. sendTest();
  2560. } catch (e) {
  2561. _this6._setupFakeWorker();
  2562. }
  2563. });
  2564. var sendTest = function sendTest() {
  2565. var postMessageTransfers = (0, _dom_utils.getDefaultSetting)('postMessageTransfers') && !isPostMessageTransfersDisabled;
  2566. var testObj = new Uint8Array([postMessageTransfers ? 255 : 0]);
  2567. try {
  2568. messageHandler.send('test', testObj, [testObj.buffer]);
  2569. } catch (ex) {
  2570. (0, _util.info)('Cannot use postMessage transfers');
  2571. testObj[0] = 0;
  2572. messageHandler.send('test', testObj);
  2573. }
  2574. };
  2575. sendTest();
  2576. return;
  2577. } catch (e) {
  2578. (0, _util.info)('The worker has been disabled.');
  2579. }
  2580. }
  2581. this._setupFakeWorker();
  2582. },
  2583. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  2584. var _this7 = this;
  2585. if (!isWorkerDisabled && !(0, _dom_utils.getDefaultSetting)('disableWorker')) {
  2586. (0, _util.warn)('Setting up fake worker.');
  2587. isWorkerDisabled = true;
  2588. }
  2589. setupFakeWorkerGlobal().then(function (WorkerMessageHandler) {
  2590. if (_this7.destroyed) {
  2591. _this7._readyCapability.reject(new Error('Worker was destroyed'));
  2592. return;
  2593. }
  2594. var isTypedArraysPresent = Uint8Array !== Float32Array;
  2595. var port = new LoopbackPort(isTypedArraysPresent);
  2596. _this7._port = port;
  2597. var id = 'fake' + nextFakeWorkerId++;
  2598. var workerHandler = new _util.MessageHandler(id + '_worker', id, port);
  2599. WorkerMessageHandler.setup(workerHandler, port);
  2600. var messageHandler = new _util.MessageHandler(id, id + '_worker', port);
  2601. _this7._messageHandler = messageHandler;
  2602. _this7._readyCapability.resolve();
  2603. });
  2604. },
  2605. destroy: function PDFWorker_destroy() {
  2606. this.destroyed = true;
  2607. if (this._webWorker) {
  2608. this._webWorker.terminate();
  2609. this._webWorker = null;
  2610. }
  2611. pdfWorkerPorts.delete(this._port);
  2612. this._port = null;
  2613. if (this._messageHandler) {
  2614. this._messageHandler.destroy();
  2615. this._messageHandler = null;
  2616. }
  2617. }
  2618. };
  2619. PDFWorker.fromPort = function (port) {
  2620. if (pdfWorkerPorts.has(port)) {
  2621. return pdfWorkerPorts.get(port);
  2622. }
  2623. return new PDFWorker(null, port);
  2624. };
  2625. return PDFWorker;
  2626. }();
  2627. var WorkerTransport = function WorkerTransportClosure() {
  2628. function WorkerTransport(messageHandler, loadingTask, networkStream, CMapReaderFactory) {
  2629. this.messageHandler = messageHandler;
  2630. this.loadingTask = loadingTask;
  2631. this.commonObjs = new PDFObjects();
  2632. this.fontLoader = new _font_loader.FontLoader(loadingTask.docId);
  2633. this.CMapReaderFactory = new CMapReaderFactory({
  2634. baseUrl: (0, _dom_utils.getDefaultSetting)('cMapUrl'),
  2635. isCompressed: (0, _dom_utils.getDefaultSetting)('cMapPacked')
  2636. });
  2637. this.destroyed = false;
  2638. this.destroyCapability = null;
  2639. this._passwordCapability = null;
  2640. this._networkStream = networkStream;
  2641. this._fullReader = null;
  2642. this._lastProgress = null;
  2643. this.pageCache = [];
  2644. this.pagePromises = [];
  2645. this.downloadInfoCapability = (0, _util.createPromiseCapability)();
  2646. this.setupMessageHandler();
  2647. }
  2648. WorkerTransport.prototype = {
  2649. destroy: function WorkerTransport_destroy() {
  2650. var _this8 = this;
  2651. if (this.destroyCapability) {
  2652. return this.destroyCapability.promise;
  2653. }
  2654. this.destroyed = true;
  2655. this.destroyCapability = (0, _util.createPromiseCapability)();
  2656. if (this._passwordCapability) {
  2657. this._passwordCapability.reject(new Error('Worker was destroyed during onPassword callback'));
  2658. }
  2659. var waitOn = [];
  2660. this.pageCache.forEach(function (page) {
  2661. if (page) {
  2662. waitOn.push(page._destroy());
  2663. }
  2664. });
  2665. this.pageCache = [];
  2666. this.pagePromises = [];
  2667. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  2668. waitOn.push(terminated);
  2669. Promise.all(waitOn).then(function () {
  2670. _this8.fontLoader.clear();
  2671. if (_this8._networkStream) {
  2672. _this8._networkStream.cancelAllRequests();
  2673. }
  2674. if (_this8.messageHandler) {
  2675. _this8.messageHandler.destroy();
  2676. _this8.messageHandler = null;
  2677. }
  2678. _this8.destroyCapability.resolve();
  2679. }, this.destroyCapability.reject);
  2680. return this.destroyCapability.promise;
  2681. },
  2682. setupMessageHandler: function WorkerTransport_setupMessageHandler() {
  2683. var messageHandler = this.messageHandler;
  2684. var loadingTask = this.loadingTask;
  2685. messageHandler.on('GetReader', function (data, sink) {
  2686. var _this9 = this;
  2687. (0, _util.assert)(this._networkStream);
  2688. this._fullReader = this._networkStream.getFullReader();
  2689. this._fullReader.onProgress = function (evt) {
  2690. _this9._lastProgress = {
  2691. loaded: evt.loaded,
  2692. total: evt.total
  2693. };
  2694. };
  2695. sink.onPull = function () {
  2696. _this9._fullReader.read().then(function (_ref2) {
  2697. var value = _ref2.value,
  2698. done = _ref2.done;
  2699. if (done) {
  2700. sink.close();
  2701. return;
  2702. }
  2703. (0, _util.assert)((0, _util.isArrayBuffer)(value));
  2704. sink.enqueue(new Uint8Array(value), 1, [value]);
  2705. }).catch(function (reason) {
  2706. sink.error(reason);
  2707. });
  2708. };
  2709. sink.onCancel = function (reason) {
  2710. _this9._fullReader.cancel(reason);
  2711. };
  2712. }, this);
  2713. messageHandler.on('ReaderHeadersReady', function (data) {
  2714. var _this10 = this;
  2715. var headersCapability = (0, _util.createPromiseCapability)();
  2716. var fullReader = this._fullReader;
  2717. fullReader.headersReady.then(function () {
  2718. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  2719. if (_this10._lastProgress) {
  2720. var _loadingTask = _this10.loadingTask;
  2721. if (_loadingTask.onProgress) {
  2722. _loadingTask.onProgress(_this10._lastProgress);
  2723. }
  2724. }
  2725. fullReader.onProgress = function (evt) {
  2726. var loadingTask = _this10.loadingTask;
  2727. if (loadingTask.onProgress) {
  2728. loadingTask.onProgress({
  2729. loaded: evt.loaded,
  2730. total: evt.total
  2731. });
  2732. }
  2733. };
  2734. }
  2735. headersCapability.resolve({
  2736. isStreamingSupported: fullReader.isStreamingSupported,
  2737. isRangeSupported: fullReader.isRangeSupported,
  2738. contentLength: fullReader.contentLength
  2739. });
  2740. }, headersCapability.reject);
  2741. return headersCapability.promise;
  2742. }, this);
  2743. messageHandler.on('GetRangeReader', function (data, sink) {
  2744. (0, _util.assert)(this._networkStream);
  2745. var _rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
  2746. sink.onPull = function () {
  2747. _rangeReader.read().then(function (_ref3) {
  2748. var value = _ref3.value,
  2749. done = _ref3.done;
  2750. if (done) {
  2751. sink.close();
  2752. return;
  2753. }
  2754. (0, _util.assert)((0, _util.isArrayBuffer)(value));
  2755. sink.enqueue(new Uint8Array(value), 1, [value]);
  2756. }).catch(function (reason) {
  2757. sink.error(reason);
  2758. });
  2759. };
  2760. sink.onCancel = function (reason) {
  2761. _rangeReader.cancel(reason);
  2762. };
  2763. }, this);
  2764. messageHandler.on('GetDoc', function transportDoc(data) {
  2765. var pdfInfo = data.pdfInfo;
  2766. this.numPages = data.pdfInfo.numPages;
  2767. var loadingTask = this.loadingTask;
  2768. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  2769. this.pdfDocument = pdfDocument;
  2770. loadingTask._capability.resolve(pdfDocument);
  2771. }, this);
  2772. messageHandler.on('PasswordRequest', function transportPasswordRequest(exception) {
  2773. var _this11 = this;
  2774. this._passwordCapability = (0, _util.createPromiseCapability)();
  2775. if (loadingTask.onPassword) {
  2776. var updatePassword = function updatePassword(password) {
  2777. _this11._passwordCapability.resolve({ password: password });
  2778. };
  2779. loadingTask.onPassword(updatePassword, exception.code);
  2780. } else {
  2781. this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code));
  2782. }
  2783. return this._passwordCapability.promise;
  2784. }, this);
  2785. messageHandler.on('PasswordException', function transportPasswordException(exception) {
  2786. loadingTask._capability.reject(new _util.PasswordException(exception.message, exception.code));
  2787. }, this);
  2788. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  2789. this.loadingTask._capability.reject(new _util.InvalidPDFException(exception.message));
  2790. }, this);
  2791. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  2792. this.loadingTask._capability.reject(new _util.MissingPDFException(exception.message));
  2793. }, this);
  2794. messageHandler.on('UnexpectedResponse', function transportUnexpectedResponse(exception) {
  2795. this.loadingTask._capability.reject(new _util.UnexpectedResponseException(exception.message, exception.status));
  2796. }, this);
  2797. messageHandler.on('UnknownError', function transportUnknownError(exception) {
  2798. this.loadingTask._capability.reject(new _util.UnknownErrorException(exception.message, exception.details));
  2799. }, this);
  2800. messageHandler.on('DataLoaded', function transportPage(data) {
  2801. this.downloadInfoCapability.resolve(data);
  2802. }, this);
  2803. messageHandler.on('PDFManagerReady', function transportPage(data) {}, this);
  2804. messageHandler.on('StartRenderPage', function transportRender(data) {
  2805. if (this.destroyed) {
  2806. return;
  2807. }
  2808. var page = this.pageCache[data.pageIndex];
  2809. page.stats.timeEnd('Page Request');
  2810. page._startRenderPage(data.transparency, data.intent);
  2811. }, this);
  2812. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2813. if (this.destroyed) {
  2814. return;
  2815. }
  2816. var page = this.pageCache[data.pageIndex];
  2817. page._renderPageChunk(data.operatorList, data.intent);
  2818. }, this);
  2819. messageHandler.on('commonobj', function transportObj(data) {
  2820. var _this12 = this;
  2821. if (this.destroyed) {
  2822. return;
  2823. }
  2824. var id = data[0];
  2825. var type = data[1];
  2826. if (this.commonObjs.hasData(id)) {
  2827. return;
  2828. }
  2829. switch (type) {
  2830. case 'Font':
  2831. var exportedData = data[2];
  2832. if ('error' in exportedData) {
  2833. var exportedError = exportedData.error;
  2834. (0, _util.warn)('Error during font loading: ' + exportedError);
  2835. this.commonObjs.resolve(id, exportedError);
  2836. break;
  2837. }
  2838. var fontRegistry = null;
  2839. if ((0, _dom_utils.getDefaultSetting)('pdfBug') && _util.globalScope.FontInspector && _util.globalScope['FontInspector'].enabled) {
  2840. fontRegistry = {
  2841. registerFont: function registerFont(font, url) {
  2842. _util.globalScope['FontInspector'].fontAdded(font, url);
  2843. }
  2844. };
  2845. }
  2846. var font = new _font_loader.FontFaceObject(exportedData, {
  2847. isEvalSuported: (0, _dom_utils.getDefaultSetting)('isEvalSupported'),
  2848. disableFontFace: (0, _dom_utils.getDefaultSetting)('disableFontFace'),
  2849. fontRegistry: fontRegistry
  2850. });
  2851. var fontReady = function fontReady(fontObjs) {
  2852. _this12.commonObjs.resolve(id, font);
  2853. };
  2854. this.fontLoader.bind([font], fontReady);
  2855. break;
  2856. case 'FontPath':
  2857. this.commonObjs.resolve(id, data[2]);
  2858. break;
  2859. default:
  2860. throw new Error('Got unknown common object type ' + type);
  2861. }
  2862. }, this);
  2863. messageHandler.on('obj', function transportObj(data) {
  2864. if (this.destroyed) {
  2865. return;
  2866. }
  2867. var id = data[0];
  2868. var pageIndex = data[1];
  2869. var type = data[2];
  2870. var pageProxy = this.pageCache[pageIndex];
  2871. var imageData;
  2872. if (pageProxy.objs.hasData(id)) {
  2873. return;
  2874. }
  2875. switch (type) {
  2876. case 'JpegStream':
  2877. imageData = data[3];
  2878. (0, _util.loadJpegStream)(id, imageData, pageProxy.objs);
  2879. break;
  2880. case 'Image':
  2881. imageData = data[3];
  2882. pageProxy.objs.resolve(id, imageData);
  2883. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2884. if (imageData && 'data' in imageData && imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2885. pageProxy.cleanupAfterRender = true;
  2886. }
  2887. break;
  2888. default:
  2889. throw new Error('Got unknown object type ' + type);
  2890. }
  2891. }, this);
  2892. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2893. if (this.destroyed) {
  2894. return;
  2895. }
  2896. var loadingTask = this.loadingTask;
  2897. if (loadingTask.onProgress) {
  2898. loadingTask.onProgress({
  2899. loaded: data.loaded,
  2900. total: data.total
  2901. });
  2902. }
  2903. }, this);
  2904. messageHandler.on('PageError', function transportError(data) {
  2905. if (this.destroyed) {
  2906. return;
  2907. }
  2908. var page = this.pageCache[data.pageNum - 1];
  2909. var intentState = page.intentStates[data.intent];
  2910. if (intentState.displayReadyCapability) {
  2911. intentState.displayReadyCapability.reject(data.error);
  2912. } else {
  2913. throw new Error(data.error);
  2914. }
  2915. if (intentState.operatorList) {
  2916. intentState.operatorList.lastChunk = true;
  2917. for (var i = 0; i < intentState.renderTasks.length; i++) {
  2918. intentState.renderTasks[i].operatorListChanged();
  2919. }
  2920. }
  2921. }, this);
  2922. messageHandler.on('UnsupportedFeature', function transportUnsupportedFeature(data) {
  2923. if (this.destroyed) {
  2924. return;
  2925. }
  2926. var featureId = data.featureId;
  2927. var loadingTask = this.loadingTask;
  2928. if (loadingTask.onUnsupportedFeature) {
  2929. loadingTask.onUnsupportedFeature(featureId);
  2930. }
  2931. _UnsupportedManager.notify(featureId);
  2932. }, this);
  2933. messageHandler.on('JpegDecode', function (data) {
  2934. if (this.destroyed) {
  2935. return Promise.reject(new Error('Worker was destroyed'));
  2936. }
  2937. if (typeof document === 'undefined') {
  2938. return Promise.reject(new Error('"document" is not defined.'));
  2939. }
  2940. var imageUrl = data[0];
  2941. var components = data[1];
  2942. if (components !== 3 && components !== 1) {
  2943. return Promise.reject(new Error('Only 3 components or 1 component can be returned'));
  2944. }
  2945. return new Promise(function (resolve, reject) {
  2946. var img = new Image();
  2947. img.onload = function () {
  2948. var width = img.width;
  2949. var height = img.height;
  2950. var size = width * height;
  2951. var rgbaLength = size * 4;
  2952. var buf = new Uint8Array(size * components);
  2953. var tmpCanvas = document.createElement('canvas');
  2954. tmpCanvas.width = width;
  2955. tmpCanvas.height = height;
  2956. var tmpCtx = tmpCanvas.getContext('2d');
  2957. tmpCtx.drawImage(img, 0, 0);
  2958. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2959. var i, j;
  2960. if (components === 3) {
  2961. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2962. buf[j] = data[i];
  2963. buf[j + 1] = data[i + 1];
  2964. buf[j + 2] = data[i + 2];
  2965. }
  2966. } else if (components === 1) {
  2967. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2968. buf[j] = data[i];
  2969. }
  2970. }
  2971. resolve({
  2972. data: buf,
  2973. width: width,
  2974. height: height
  2975. });
  2976. };
  2977. img.onerror = function () {
  2978. reject(new Error('JpegDecode failed to load image'));
  2979. };
  2980. img.src = imageUrl;
  2981. });
  2982. }, this);
  2983. messageHandler.on('FetchBuiltInCMap', function (data) {
  2984. if (this.destroyed) {
  2985. return Promise.reject(new Error('Worker was destroyed'));
  2986. }
  2987. return this.CMapReaderFactory.fetch({ name: data.name });
  2988. }, this);
  2989. },
  2990. getData: function WorkerTransport_getData() {
  2991. return this.messageHandler.sendWithPromise('GetData', null);
  2992. },
  2993. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2994. var _this13 = this;
  2995. if (!(0, _util.isInt)(pageNumber) || pageNumber <= 0 || pageNumber > this.numPages) {
  2996. return Promise.reject(new Error('Invalid page request'));
  2997. }
  2998. var pageIndex = pageNumber - 1;
  2999. if (pageIndex in this.pagePromises) {
  3000. return this.pagePromises[pageIndex];
  3001. }
  3002. var promise = this.messageHandler.sendWithPromise('GetPage', { pageIndex: pageIndex }).then(function (pageInfo) {
  3003. if (_this13.destroyed) {
  3004. throw new Error('Transport destroyed');
  3005. }
  3006. var page = new PDFPageProxy(pageIndex, pageInfo, _this13);
  3007. _this13.pageCache[pageIndex] = page;
  3008. return page;
  3009. });
  3010. this.pagePromises[pageIndex] = promise;
  3011. return promise;
  3012. },
  3013. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  3014. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref }).catch(function (reason) {
  3015. return Promise.reject(new Error(reason));
  3016. });
  3017. },
  3018. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  3019. return this.messageHandler.sendWithPromise('GetAnnotations', {
  3020. pageIndex: pageIndex,
  3021. intent: intent
  3022. });
  3023. },
  3024. getDestinations: function WorkerTransport_getDestinations() {
  3025. return this.messageHandler.sendWithPromise('GetDestinations', null);
  3026. },
  3027. getDestination: function WorkerTransport_getDestination(id) {
  3028. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  3029. },
  3030. getPageLabels: function WorkerTransport_getPageLabels() {
  3031. return this.messageHandler.sendWithPromise('GetPageLabels', null);
  3032. },
  3033. getPageMode: function getPageMode() {
  3034. return this.messageHandler.sendWithPromise('GetPageMode', null);
  3035. },
  3036. getAttachments: function WorkerTransport_getAttachments() {
  3037. return this.messageHandler.sendWithPromise('GetAttachments', null);
  3038. },
  3039. getJavaScript: function WorkerTransport_getJavaScript() {
  3040. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  3041. },
  3042. getOutline: function WorkerTransport_getOutline() {
  3043. return this.messageHandler.sendWithPromise('GetOutline', null);
  3044. },
  3045. getMetadata: function WorkerTransport_getMetadata() {
  3046. return this.messageHandler.sendWithPromise('GetMetadata', null).then(function transportMetadata(results) {
  3047. return {
  3048. info: results[0],
  3049. metadata: results[1] ? new _metadata.Metadata(results[1]) : null
  3050. };
  3051. });
  3052. },
  3053. getStats: function WorkerTransport_getStats() {
  3054. return this.messageHandler.sendWithPromise('GetStats', null);
  3055. },
  3056. startCleanup: function WorkerTransport_startCleanup() {
  3057. var _this14 = this;
  3058. this.messageHandler.sendWithPromise('Cleanup', null).then(function () {
  3059. for (var i = 0, ii = _this14.pageCache.length; i < ii; i++) {
  3060. var page = _this14.pageCache[i];
  3061. if (page) {
  3062. page.cleanup();
  3063. }
  3064. }
  3065. _this14.commonObjs.clear();
  3066. _this14.fontLoader.clear();
  3067. });
  3068. }
  3069. };
  3070. return WorkerTransport;
  3071. }();
  3072. var PDFObjects = function PDFObjectsClosure() {
  3073. function PDFObjects() {
  3074. this.objs = Object.create(null);
  3075. }
  3076. PDFObjects.prototype = {
  3077. ensureObj: function PDFObjects_ensureObj(objId) {
  3078. if (this.objs[objId]) {
  3079. return this.objs[objId];
  3080. }
  3081. var obj = {
  3082. capability: (0, _util.createPromiseCapability)(),
  3083. data: null,
  3084. resolved: false
  3085. };
  3086. this.objs[objId] = obj;
  3087. return obj;
  3088. },
  3089. get: function PDFObjects_get(objId, callback) {
  3090. if (callback) {
  3091. this.ensureObj(objId).capability.promise.then(callback);
  3092. return null;
  3093. }
  3094. var obj = this.objs[objId];
  3095. if (!obj || !obj.resolved) {
  3096. throw new Error('Requesting object that isn\'t resolved yet ' + objId);
  3097. }
  3098. return obj.data;
  3099. },
  3100. resolve: function PDFObjects_resolve(objId, data) {
  3101. var obj = this.ensureObj(objId);
  3102. obj.resolved = true;
  3103. obj.data = data;
  3104. obj.capability.resolve(data);
  3105. },
  3106. isResolved: function PDFObjects_isResolved(objId) {
  3107. var objs = this.objs;
  3108. if (!objs[objId]) {
  3109. return false;
  3110. }
  3111. return objs[objId].resolved;
  3112. },
  3113. hasData: function PDFObjects_hasData(objId) {
  3114. return this.isResolved(objId);
  3115. },
  3116. getData: function PDFObjects_getData(objId) {
  3117. var objs = this.objs;
  3118. if (!objs[objId] || !objs[objId].resolved) {
  3119. return null;
  3120. }
  3121. return objs[objId].data;
  3122. },
  3123. clear: function PDFObjects_clear() {
  3124. this.objs = Object.create(null);
  3125. }
  3126. };
  3127. return PDFObjects;
  3128. }();
  3129. var RenderTask = function RenderTaskClosure() {
  3130. function RenderTask(internalRenderTask) {
  3131. this._internalRenderTask = internalRenderTask;
  3132. this.onContinue = null;
  3133. }
  3134. RenderTask.prototype = {
  3135. get promise() {
  3136. return this._internalRenderTask.capability.promise;
  3137. },
  3138. cancel: function RenderTask_cancel() {
  3139. this._internalRenderTask.cancel();
  3140. },
  3141. then: function RenderTask_then(onFulfilled, onRejected) {
  3142. return this.promise.then.apply(this.promise, arguments);
  3143. }
  3144. };
  3145. return RenderTask;
  3146. }();
  3147. var InternalRenderTask = function InternalRenderTaskClosure() {
  3148. var canvasInRendering = new WeakMap();
  3149. function InternalRenderTask(callback, params, objs, commonObjs, operatorList, pageNumber, canvasFactory) {
  3150. this.callback = callback;
  3151. this.params = params;
  3152. this.objs = objs;
  3153. this.commonObjs = commonObjs;
  3154. this.operatorListIdx = null;
  3155. this.operatorList = operatorList;
  3156. this.pageNumber = pageNumber;
  3157. this.canvasFactory = canvasFactory;
  3158. this.running = false;
  3159. this.graphicsReadyCallback = null;
  3160. this.graphicsReady = false;
  3161. this.useRequestAnimationFrame = false;
  3162. this.cancelled = false;
  3163. this.capability = (0, _util.createPromiseCapability)();
  3164. this.task = new RenderTask(this);
  3165. this._continueBound = this._continue.bind(this);
  3166. this._scheduleNextBound = this._scheduleNext.bind(this);
  3167. this._nextBound = this._next.bind(this);
  3168. this._canvas = params.canvasContext.canvas;
  3169. }
  3170. InternalRenderTask.prototype = {
  3171. initializeGraphics: function InternalRenderTask_initializeGraphics(transparency) {
  3172. if (this._canvas) {
  3173. if (canvasInRendering.has(this._canvas)) {
  3174. throw new Error('Cannot use the same canvas during multiple render() operations. ' + 'Use different canvas or ensure previous operations were ' + 'cancelled or completed.');
  3175. }
  3176. canvasInRendering.set(this._canvas, this);
  3177. }
  3178. if (this.cancelled) {
  3179. return;
  3180. }
  3181. if ((0, _dom_utils.getDefaultSetting)('pdfBug') && _util.globalScope.StepperManager && _util.globalScope.StepperManager.enabled) {
  3182. this.stepper = _util.globalScope.StepperManager.create(this.pageNumber - 1);
  3183. this.stepper.init(this.operatorList);
  3184. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  3185. }
  3186. var params = this.params;
  3187. this.gfx = new _canvas.CanvasGraphics(params.canvasContext, this.commonObjs, this.objs, this.canvasFactory, params.imageLayer);
  3188. this.gfx.beginDrawing({
  3189. transform: params.transform,
  3190. viewport: params.viewport,
  3191. transparency: transparency,
  3192. background: params.background
  3193. });
  3194. this.operatorListIdx = 0;
  3195. this.graphicsReady = true;
  3196. if (this.graphicsReadyCallback) {
  3197. this.graphicsReadyCallback();
  3198. }
  3199. },
  3200. cancel: function InternalRenderTask_cancel() {
  3201. this.running = false;
  3202. this.cancelled = true;
  3203. if (this._canvas) {
  3204. canvasInRendering.delete(this._canvas);
  3205. }
  3206. if ((0, _dom_utils.getDefaultSetting)('pdfjsNext')) {
  3207. this.callback(new _dom_utils.RenderingCancelledException('Rendering cancelled, page ' + this.pageNumber, 'canvas'));
  3208. } else {
  3209. this.callback('cancelled');
  3210. }
  3211. },
  3212. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  3213. if (!this.graphicsReady) {
  3214. if (!this.graphicsReadyCallback) {
  3215. this.graphicsReadyCallback = this._continueBound;
  3216. }
  3217. return;
  3218. }
  3219. if (this.stepper) {
  3220. this.stepper.updateOperatorList(this.operatorList);
  3221. }
  3222. if (this.running) {
  3223. return;
  3224. }
  3225. this._continue();
  3226. },
  3227. _continue: function InternalRenderTask__continue() {
  3228. this.running = true;
  3229. if (this.cancelled) {
  3230. return;
  3231. }
  3232. if (this.task.onContinue) {
  3233. this.task.onContinue(this._scheduleNextBound);
  3234. } else {
  3235. this._scheduleNext();
  3236. }
  3237. },
  3238. _scheduleNext: function InternalRenderTask__scheduleNext() {
  3239. if (this.useRequestAnimationFrame && typeof window !== 'undefined') {
  3240. window.requestAnimationFrame(this._nextBound);
  3241. } else {
  3242. Promise.resolve(undefined).then(this._nextBound);
  3243. }
  3244. },
  3245. _next: function InternalRenderTask__next() {
  3246. if (this.cancelled) {
  3247. return;
  3248. }
  3249. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  3250. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  3251. this.running = false;
  3252. if (this.operatorList.lastChunk) {
  3253. this.gfx.endDrawing();
  3254. if (this._canvas) {
  3255. canvasInRendering.delete(this._canvas);
  3256. }
  3257. this.callback();
  3258. }
  3259. }
  3260. }
  3261. };
  3262. return InternalRenderTask;
  3263. }();
  3264. var _UnsupportedManager = function UnsupportedManagerClosure() {
  3265. var listeners = [];
  3266. return {
  3267. listen: function listen(cb) {
  3268. (0, _util.deprecated)('Global UnsupportedManager.listen is used: ' + ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  3269. listeners.push(cb);
  3270. },
  3271. notify: function notify(featureId) {
  3272. for (var i = 0, ii = listeners.length; i < ii; i++) {
  3273. listeners[i](featureId);
  3274. }
  3275. }
  3276. };
  3277. }();
  3278. var version, build;
  3279. {
  3280. exports.version = version = '1.9.426';
  3281. exports.build = build = '2558a58d';
  3282. }
  3283. exports.getDocument = getDocument;
  3284. exports.LoopbackPort = LoopbackPort;
  3285. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  3286. exports.PDFWorker = PDFWorker;
  3287. exports.PDFDocumentProxy = PDFDocumentProxy;
  3288. exports.PDFPageProxy = PDFPageProxy;
  3289. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  3290. exports._UnsupportedManager = _UnsupportedManager;
  3291. exports.version = version;
  3292. exports.build = build;
  3293. /***/ }),
  3294. /* 3 */
  3295. /***/ (function(module, exports, __w_pdfjs_require__) {
  3296. "use strict";
  3297. Object.defineProperty(exports, "__esModule", {
  3298. value: true
  3299. });
  3300. exports.AnnotationLayer = undefined;
  3301. var _dom_utils = __w_pdfjs_require__(1);
  3302. var _util = __w_pdfjs_require__(0);
  3303. function AnnotationElementFactory() {}
  3304. AnnotationElementFactory.prototype = {
  3305. create: function AnnotationElementFactory_create(parameters) {
  3306. var subtype = parameters.data.annotationType;
  3307. switch (subtype) {
  3308. case _util.AnnotationType.LINK:
  3309. return new LinkAnnotationElement(parameters);
  3310. case _util.AnnotationType.TEXT:
  3311. return new TextAnnotationElement(parameters);
  3312. case _util.AnnotationType.WIDGET:
  3313. var fieldType = parameters.data.fieldType;
  3314. switch (fieldType) {
  3315. case 'Tx':
  3316. return new TextWidgetAnnotationElement(parameters);
  3317. case 'Btn':
  3318. if (parameters.data.radioButton) {
  3319. return new RadioButtonWidgetAnnotationElement(parameters);
  3320. } else if (parameters.data.checkBox) {
  3321. return new CheckboxWidgetAnnotationElement(parameters);
  3322. }
  3323. (0, _util.warn)('Unimplemented button widget annotation: pushbutton');
  3324. break;
  3325. case 'Ch':
  3326. return new ChoiceWidgetAnnotationElement(parameters);
  3327. }
  3328. return new WidgetAnnotationElement(parameters);
  3329. case _util.AnnotationType.POPUP:
  3330. return new PopupAnnotationElement(parameters);
  3331. case _util.AnnotationType.LINE:
  3332. return new LineAnnotationElement(parameters);
  3333. case _util.AnnotationType.HIGHLIGHT:
  3334. return new HighlightAnnotationElement(parameters);
  3335. case _util.AnnotationType.UNDERLINE:
  3336. return new UnderlineAnnotationElement(parameters);
  3337. case _util.AnnotationType.SQUIGGLY:
  3338. return new SquigglyAnnotationElement(parameters);
  3339. case _util.AnnotationType.STRIKEOUT:
  3340. return new StrikeOutAnnotationElement(parameters);
  3341. case _util.AnnotationType.FILEATTACHMENT:
  3342. return new FileAttachmentAnnotationElement(parameters);
  3343. default:
  3344. return new AnnotationElement(parameters);
  3345. }
  3346. }
  3347. };
  3348. var AnnotationElement = function AnnotationElementClosure() {
  3349. function AnnotationElement(parameters, isRenderable, ignoreBorder) {
  3350. this.isRenderable = isRenderable || false;
  3351. this.data = parameters.data;
  3352. this.layer = parameters.layer;
  3353. this.page = parameters.page;
  3354. this.viewport = parameters.viewport;
  3355. this.linkService = parameters.linkService;
  3356. this.downloadManager = parameters.downloadManager;
  3357. this.imageResourcesPath = parameters.imageResourcesPath;
  3358. this.renderInteractiveForms = parameters.renderInteractiveForms;
  3359. if (isRenderable) {
  3360. this.container = this._createContainer(ignoreBorder);
  3361. }
  3362. }
  3363. AnnotationElement.prototype = {
  3364. _createContainer: function AnnotationElement_createContainer(ignoreBorder) {
  3365. var data = this.data,
  3366. page = this.page,
  3367. viewport = this.viewport;
  3368. var container = document.createElement('section');
  3369. var width = data.rect[2] - data.rect[0];
  3370. var height = data.rect[3] - data.rect[1];
  3371. container.setAttribute('data-annotation-id', data.id);
  3372. 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]]);
  3373. _dom_utils.CustomStyle.setProp('transform', container, 'matrix(' + viewport.transform.join(',') + ')');
  3374. _dom_utils.CustomStyle.setProp('transformOrigin', container, -rect[0] + 'px ' + -rect[1] + 'px');
  3375. if (!ignoreBorder && data.borderStyle.width > 0) {
  3376. container.style.borderWidth = data.borderStyle.width + 'px';
  3377. if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) {
  3378. width = width - 2 * data.borderStyle.width;
  3379. height = height - 2 * data.borderStyle.width;
  3380. }
  3381. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  3382. var verticalRadius = data.borderStyle.verticalCornerRadius;
  3383. if (horizontalRadius > 0 || verticalRadius > 0) {
  3384. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  3385. _dom_utils.CustomStyle.setProp('borderRadius', container, radius);
  3386. }
  3387. switch (data.borderStyle.style) {
  3388. case _util.AnnotationBorderStyleType.SOLID:
  3389. container.style.borderStyle = 'solid';
  3390. break;
  3391. case _util.AnnotationBorderStyleType.DASHED:
  3392. container.style.borderStyle = 'dashed';
  3393. break;
  3394. case _util.AnnotationBorderStyleType.BEVELED:
  3395. (0, _util.warn)('Unimplemented border style: beveled');
  3396. break;
  3397. case _util.AnnotationBorderStyleType.INSET:
  3398. (0, _util.warn)('Unimplemented border style: inset');
  3399. break;
  3400. case _util.AnnotationBorderStyleType.UNDERLINE:
  3401. container.style.borderBottomStyle = 'solid';
  3402. break;
  3403. default:
  3404. break;
  3405. }
  3406. if (data.color) {
  3407. container.style.borderColor = _util.Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  3408. } else {
  3409. container.style.borderWidth = 0;
  3410. }
  3411. }
  3412. container.style.left = rect[0] + 'px';
  3413. container.style.top = rect[1] + 'px';
  3414. container.style.width = width + 'px';
  3415. container.style.height = height + 'px';
  3416. return container;
  3417. },
  3418. _createPopup: function AnnotationElement_createPopup(container, trigger, data) {
  3419. if (!trigger) {
  3420. trigger = document.createElement('div');
  3421. trigger.style.height = container.style.height;
  3422. trigger.style.width = container.style.width;
  3423. container.appendChild(trigger);
  3424. }
  3425. var popupElement = new PopupElement({
  3426. container: container,
  3427. trigger: trigger,
  3428. color: data.color,
  3429. title: data.title,
  3430. contents: data.contents,
  3431. hideWrapper: true
  3432. });
  3433. var popup = popupElement.render();
  3434. popup.style.left = container.style.width;
  3435. container.appendChild(popup);
  3436. },
  3437. render: function AnnotationElement_render() {
  3438. throw new Error('Abstract method AnnotationElement.render called');
  3439. }
  3440. };
  3441. return AnnotationElement;
  3442. }();
  3443. var LinkAnnotationElement = function LinkAnnotationElementClosure() {
  3444. function LinkAnnotationElement(parameters) {
  3445. AnnotationElement.call(this, parameters, true);
  3446. }
  3447. _util.Util.inherit(LinkAnnotationElement, AnnotationElement, {
  3448. render: function LinkAnnotationElement_render() {
  3449. this.container.className = 'linkAnnotation';
  3450. var link = document.createElement('a');
  3451. (0, _dom_utils.addLinkAttributes)(link, {
  3452. url: this.data.url,
  3453. target: this.data.newWindow ? _dom_utils.LinkTarget.BLANK : undefined
  3454. });
  3455. if (!this.data.url) {
  3456. if (this.data.action) {
  3457. this._bindNamedAction(link, this.data.action);
  3458. } else {
  3459. this._bindLink(link, this.data.dest);
  3460. }
  3461. }
  3462. this.container.appendChild(link);
  3463. return this.container;
  3464. },
  3465. _bindLink: function _bindLink(link, destination) {
  3466. var _this = this;
  3467. link.href = this.linkService.getDestinationHash(destination);
  3468. link.onclick = function () {
  3469. if (destination) {
  3470. _this.linkService.navigateTo(destination);
  3471. }
  3472. return false;
  3473. };
  3474. if (destination) {
  3475. link.className = 'internalLink';
  3476. }
  3477. },
  3478. _bindNamedAction: function _bindNamedAction(link, action) {
  3479. var _this2 = this;
  3480. link.href = this.linkService.getAnchorUrl('');
  3481. link.onclick = function () {
  3482. _this2.linkService.executeNamedAction(action);
  3483. return false;
  3484. };
  3485. link.className = 'internalLink';
  3486. }
  3487. });
  3488. return LinkAnnotationElement;
  3489. }();
  3490. var TextAnnotationElement = function TextAnnotationElementClosure() {
  3491. function TextAnnotationElement(parameters) {
  3492. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  3493. AnnotationElement.call(this, parameters, isRenderable);
  3494. }
  3495. _util.Util.inherit(TextAnnotationElement, AnnotationElement, {
  3496. render: function TextAnnotationElement_render() {
  3497. this.container.className = 'textAnnotation';
  3498. var image = document.createElement('img');
  3499. image.style.height = this.container.style.height;
  3500. image.style.width = this.container.style.width;
  3501. image.src = this.imageResourcesPath + 'annotation-' + this.data.name.toLowerCase() + '.svg';
  3502. image.alt = '[{{type}} Annotation]';
  3503. image.dataset.l10nId = 'text_annotation_type';
  3504. image.dataset.l10nArgs = JSON.stringify({ type: this.data.name });
  3505. if (!this.data.hasPopup) {
  3506. this._createPopup(this.container, image, this.data);
  3507. }
  3508. this.container.appendChild(image);
  3509. return this.container;
  3510. }
  3511. });
  3512. return TextAnnotationElement;
  3513. }();
  3514. var WidgetAnnotationElement = function WidgetAnnotationElementClosure() {
  3515. function WidgetAnnotationElement(parameters, isRenderable) {
  3516. AnnotationElement.call(this, parameters, isRenderable);
  3517. }
  3518. _util.Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  3519. render: function WidgetAnnotationElement_render() {
  3520. return this.container;
  3521. }
  3522. });
  3523. return WidgetAnnotationElement;
  3524. }();
  3525. var TextWidgetAnnotationElement = function TextWidgetAnnotationElementClosure() {
  3526. var TEXT_ALIGNMENT = ['left', 'center', 'right'];
  3527. function TextWidgetAnnotationElement(parameters) {
  3528. var isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  3529. WidgetAnnotationElement.call(this, parameters, isRenderable);
  3530. }
  3531. _util.Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, {
  3532. render: function TextWidgetAnnotationElement_render() {
  3533. this.container.className = 'textWidgetAnnotation';
  3534. var element = null;
  3535. if (this.renderInteractiveForms) {
  3536. if (this.data.multiLine) {
  3537. element = document.createElement('textarea');
  3538. element.textContent = this.data.fieldValue;
  3539. } else {
  3540. element = document.createElement('input');
  3541. element.type = 'text';
  3542. element.setAttribute('value', this.data.fieldValue);
  3543. }
  3544. element.disabled = this.data.readOnly;
  3545. if (this.data.maxLen !== null) {
  3546. element.maxLength = this.data.maxLen;
  3547. }
  3548. if (this.data.comb) {
  3549. var fieldWidth = this.data.rect[2] - this.data.rect[0];
  3550. var combWidth = fieldWidth / this.data.maxLen;
  3551. element.classList.add('comb');
  3552. element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)';
  3553. }
  3554. } else {
  3555. element = document.createElement('div');
  3556. element.textContent = this.data.fieldValue;
  3557. element.style.verticalAlign = 'middle';
  3558. element.style.display = 'table-cell';
  3559. var font = null;
  3560. if (this.data.fontRefName) {
  3561. font = this.page.commonObjs.getData(this.data.fontRefName);
  3562. }
  3563. this._setTextStyle(element, font);
  3564. }
  3565. if (this.data.textAlignment !== null) {
  3566. element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  3567. }
  3568. this.container.appendChild(element);
  3569. return this.container;
  3570. },
  3571. _setTextStyle: function TextWidgetAnnotationElement_setTextStyle(element, font) {
  3572. var style = element.style;
  3573. style.fontSize = this.data.fontSize + 'px';
  3574. style.direction = this.data.fontDirection < 0 ? 'rtl' : 'ltr';
  3575. if (!font) {
  3576. return;
  3577. }
  3578. style.fontWeight = font.black ? font.bold ? '900' : 'bold' : font.bold ? 'bold' : 'normal';
  3579. style.fontStyle = font.italic ? 'italic' : 'normal';
  3580. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  3581. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  3582. style.fontFamily = fontFamily + fallbackName;
  3583. }
  3584. });
  3585. return TextWidgetAnnotationElement;
  3586. }();
  3587. var CheckboxWidgetAnnotationElement = function CheckboxWidgetAnnotationElementClosure() {
  3588. function CheckboxWidgetAnnotationElement(parameters) {
  3589. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  3590. }
  3591. _util.Util.inherit(CheckboxWidgetAnnotationElement, WidgetAnnotationElement, {
  3592. render: function CheckboxWidgetAnnotationElement_render() {
  3593. this.container.className = 'buttonWidgetAnnotation checkBox';
  3594. var element = document.createElement('input');
  3595. element.disabled = this.data.readOnly;
  3596. element.type = 'checkbox';
  3597. if (this.data.fieldValue && this.data.fieldValue !== 'Off') {
  3598. element.setAttribute('checked', true);
  3599. }
  3600. this.container.appendChild(element);
  3601. return this.container;
  3602. }
  3603. });
  3604. return CheckboxWidgetAnnotationElement;
  3605. }();
  3606. var RadioButtonWidgetAnnotationElement = function RadioButtonWidgetAnnotationElementClosure() {
  3607. function RadioButtonWidgetAnnotationElement(parameters) {
  3608. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  3609. }
  3610. _util.Util.inherit(RadioButtonWidgetAnnotationElement, WidgetAnnotationElement, {
  3611. render: function RadioButtonWidgetAnnotationElement_render() {
  3612. this.container.className = 'buttonWidgetAnnotation radioButton';
  3613. var element = document.createElement('input');
  3614. element.disabled = this.data.readOnly;
  3615. element.type = 'radio';
  3616. element.name = this.data.fieldName;
  3617. if (this.data.fieldValue === this.data.buttonValue) {
  3618. element.setAttribute('checked', true);
  3619. }
  3620. this.container.appendChild(element);
  3621. return this.container;
  3622. }
  3623. });
  3624. return RadioButtonWidgetAnnotationElement;
  3625. }();
  3626. var ChoiceWidgetAnnotationElement = function ChoiceWidgetAnnotationElementClosure() {
  3627. function ChoiceWidgetAnnotationElement(parameters) {
  3628. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  3629. }
  3630. _util.Util.inherit(ChoiceWidgetAnnotationElement, WidgetAnnotationElement, {
  3631. render: function ChoiceWidgetAnnotationElement_render() {
  3632. this.container.className = 'choiceWidgetAnnotation';
  3633. var selectElement = document.createElement('select');
  3634. selectElement.disabled = this.data.readOnly;
  3635. if (!this.data.combo) {
  3636. selectElement.size = this.data.options.length;
  3637. if (this.data.multiSelect) {
  3638. selectElement.multiple = true;
  3639. }
  3640. }
  3641. for (var i = 0, ii = this.data.options.length; i < ii; i++) {
  3642. var option = this.data.options[i];
  3643. var optionElement = document.createElement('option');
  3644. optionElement.textContent = option.displayValue;
  3645. optionElement.value = option.exportValue;
  3646. if (this.data.fieldValue.indexOf(option.displayValue) >= 0) {
  3647. optionElement.setAttribute('selected', true);
  3648. }
  3649. selectElement.appendChild(optionElement);
  3650. }
  3651. this.container.appendChild(selectElement);
  3652. return this.container;
  3653. }
  3654. });
  3655. return ChoiceWidgetAnnotationElement;
  3656. }();
  3657. var PopupAnnotationElement = function PopupAnnotationElementClosure() {
  3658. var IGNORE_TYPES = ['Line'];
  3659. function PopupAnnotationElement(parameters) {
  3660. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  3661. AnnotationElement.call(this, parameters, isRenderable);
  3662. }
  3663. _util.Util.inherit(PopupAnnotationElement, AnnotationElement, {
  3664. render: function PopupAnnotationElement_render() {
  3665. this.container.className = 'popupAnnotation';
  3666. if (IGNORE_TYPES.indexOf(this.data.parentType) >= 0) {
  3667. return this.container;
  3668. }
  3669. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  3670. var parentElement = this.layer.querySelector(selector);
  3671. if (!parentElement) {
  3672. return this.container;
  3673. }
  3674. var popup = new PopupElement({
  3675. container: this.container,
  3676. trigger: parentElement,
  3677. color: this.data.color,
  3678. title: this.data.title,
  3679. contents: this.data.contents
  3680. });
  3681. var parentLeft = parseFloat(parentElement.style.left);
  3682. var parentWidth = parseFloat(parentElement.style.width);
  3683. _dom_utils.CustomStyle.setProp('transformOrigin', this.container, -(parentLeft + parentWidth) + 'px -' + parentElement.style.top);
  3684. this.container.style.left = parentLeft + parentWidth + 'px';
  3685. this.container.appendChild(popup.render());
  3686. return this.container;
  3687. }
  3688. });
  3689. return PopupAnnotationElement;
  3690. }();
  3691. var PopupElement = function PopupElementClosure() {
  3692. var BACKGROUND_ENLIGHT = 0.7;
  3693. function PopupElement(parameters) {
  3694. this.container = parameters.container;
  3695. this.trigger = parameters.trigger;
  3696. this.color = parameters.color;
  3697. this.title = parameters.title;
  3698. this.contents = parameters.contents;
  3699. this.hideWrapper = parameters.hideWrapper || false;
  3700. this.pinned = false;
  3701. }
  3702. PopupElement.prototype = {
  3703. render: function PopupElement_render() {
  3704. var wrapper = document.createElement('div');
  3705. wrapper.className = 'popupWrapper';
  3706. this.hideElement = this.hideWrapper ? wrapper : this.container;
  3707. this.hideElement.setAttribute('hidden', true);
  3708. var popup = document.createElement('div');
  3709. popup.className = 'popup';
  3710. var color = this.color;
  3711. if (color) {
  3712. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  3713. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  3714. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  3715. popup.style.backgroundColor = _util.Util.makeCssRgb(r | 0, g | 0, b | 0);
  3716. }
  3717. var contents = this._formatContents(this.contents);
  3718. var title = document.createElement('h1');
  3719. title.textContent = this.title;
  3720. this.trigger.addEventListener('click', this._toggle.bind(this));
  3721. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  3722. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  3723. popup.addEventListener('click', this._hide.bind(this, true));
  3724. popup.appendChild(title);
  3725. popup.appendChild(contents);
  3726. wrapper.appendChild(popup);
  3727. return wrapper;
  3728. },
  3729. _formatContents: function PopupElement_formatContents(contents) {
  3730. var p = document.createElement('p');
  3731. var lines = contents.split(/(?:\r\n?|\n)/);
  3732. for (var i = 0, ii = lines.length; i < ii; ++i) {
  3733. var line = lines[i];
  3734. p.appendChild(document.createTextNode(line));
  3735. if (i < ii - 1) {
  3736. p.appendChild(document.createElement('br'));
  3737. }
  3738. }
  3739. return p;
  3740. },
  3741. _toggle: function PopupElement_toggle() {
  3742. if (this.pinned) {
  3743. this._hide(true);
  3744. } else {
  3745. this._show(true);
  3746. }
  3747. },
  3748. _show: function PopupElement_show(pin) {
  3749. if (pin) {
  3750. this.pinned = true;
  3751. }
  3752. if (this.hideElement.hasAttribute('hidden')) {
  3753. this.hideElement.removeAttribute('hidden');
  3754. this.container.style.zIndex += 1;
  3755. }
  3756. },
  3757. _hide: function PopupElement_hide(unpin) {
  3758. if (unpin) {
  3759. this.pinned = false;
  3760. }
  3761. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  3762. this.hideElement.setAttribute('hidden', true);
  3763. this.container.style.zIndex -= 1;
  3764. }
  3765. }
  3766. };
  3767. return PopupElement;
  3768. }();
  3769. var LineAnnotationElement = function LineAnnotationElementClosure() {
  3770. var SVG_NS = 'http://www.w3.org/2000/svg';
  3771. function LineAnnotationElement(parameters) {
  3772. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  3773. AnnotationElement.call(this, parameters, isRenderable, true);
  3774. }
  3775. _util.Util.inherit(LineAnnotationElement, AnnotationElement, {
  3776. render: function LineAnnotationElement_render() {
  3777. this.container.className = 'lineAnnotation';
  3778. var data = this.data;
  3779. var width = data.rect[2] - data.rect[0];
  3780. var height = data.rect[3] - data.rect[1];
  3781. var svg = document.createElementNS(SVG_NS, 'svg:svg');
  3782. svg.setAttributeNS(null, 'version', '1.1');
  3783. svg.setAttributeNS(null, 'width', width + 'px');
  3784. svg.setAttributeNS(null, 'height', height + 'px');
  3785. svg.setAttributeNS(null, 'preserveAspectRatio', 'none');
  3786. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  3787. var line = document.createElementNS(SVG_NS, 'svg:line');
  3788. line.setAttributeNS(null, 'x1', data.rect[2] - data.lineCoordinates[0]);
  3789. line.setAttributeNS(null, 'y1', data.rect[3] - data.lineCoordinates[1]);
  3790. line.setAttributeNS(null, 'x2', data.rect[2] - data.lineCoordinates[2]);
  3791. line.setAttributeNS(null, 'y2', data.rect[3] - data.lineCoordinates[3]);
  3792. line.setAttributeNS(null, 'stroke-width', data.borderStyle.width);
  3793. line.setAttributeNS(null, 'stroke', 'transparent');
  3794. svg.appendChild(line);
  3795. this.container.append(svg);
  3796. this._createPopup(this.container, line, this.data);
  3797. return this.container;
  3798. }
  3799. });
  3800. return LineAnnotationElement;
  3801. }();
  3802. var HighlightAnnotationElement = function HighlightAnnotationElementClosure() {
  3803. function HighlightAnnotationElement(parameters) {
  3804. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  3805. AnnotationElement.call(this, parameters, isRenderable, true);
  3806. }
  3807. _util.Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  3808. render: function HighlightAnnotationElement_render() {
  3809. this.container.className = 'highlightAnnotation';
  3810. if (!this.data.hasPopup) {
  3811. this._createPopup(this.container, null, this.data);
  3812. }
  3813. return this.container;
  3814. }
  3815. });
  3816. return HighlightAnnotationElement;
  3817. }();
  3818. var UnderlineAnnotationElement = function UnderlineAnnotationElementClosure() {
  3819. function UnderlineAnnotationElement(parameters) {
  3820. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  3821. AnnotationElement.call(this, parameters, isRenderable, true);
  3822. }
  3823. _util.Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  3824. render: function UnderlineAnnotationElement_render() {
  3825. this.container.className = 'underlineAnnotation';
  3826. if (!this.data.hasPopup) {
  3827. this._createPopup(this.container, null, this.data);
  3828. }
  3829. return this.container;
  3830. }
  3831. });
  3832. return UnderlineAnnotationElement;
  3833. }();
  3834. var SquigglyAnnotationElement = function SquigglyAnnotationElementClosure() {
  3835. function SquigglyAnnotationElement(parameters) {
  3836. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  3837. AnnotationElement.call(this, parameters, isRenderable, true);
  3838. }
  3839. _util.Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  3840. render: function SquigglyAnnotationElement_render() {
  3841. this.container.className = 'squigglyAnnotation';
  3842. if (!this.data.hasPopup) {
  3843. this._createPopup(this.container, null, this.data);
  3844. }
  3845. return this.container;
  3846. }
  3847. });
  3848. return SquigglyAnnotationElement;
  3849. }();
  3850. var StrikeOutAnnotationElement = function StrikeOutAnnotationElementClosure() {
  3851. function StrikeOutAnnotationElement(parameters) {
  3852. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  3853. AnnotationElement.call(this, parameters, isRenderable, true);
  3854. }
  3855. _util.Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  3856. render: function StrikeOutAnnotationElement_render() {
  3857. this.container.className = 'strikeoutAnnotation';
  3858. if (!this.data.hasPopup) {
  3859. this._createPopup(this.container, null, this.data);
  3860. }
  3861. return this.container;
  3862. }
  3863. });
  3864. return StrikeOutAnnotationElement;
  3865. }();
  3866. var FileAttachmentAnnotationElement = function FileAttachmentAnnotationElementClosure() {
  3867. function FileAttachmentAnnotationElement(parameters) {
  3868. AnnotationElement.call(this, parameters, true);
  3869. var file = this.data.file;
  3870. this.filename = (0, _dom_utils.getFilenameFromUrl)(file.filename);
  3871. this.content = file.content;
  3872. this.linkService.onFileAttachmentAnnotation({
  3873. id: (0, _util.stringToPDFString)(file.filename),
  3874. filename: file.filename,
  3875. content: file.content
  3876. });
  3877. }
  3878. _util.Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, {
  3879. render: function FileAttachmentAnnotationElement_render() {
  3880. this.container.className = 'fileAttachmentAnnotation';
  3881. var trigger = document.createElement('div');
  3882. trigger.style.height = this.container.style.height;
  3883. trigger.style.width = this.container.style.width;
  3884. trigger.addEventListener('dblclick', this._download.bind(this));
  3885. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  3886. this._createPopup(this.container, trigger, this.data);
  3887. }
  3888. this.container.appendChild(trigger);
  3889. return this.container;
  3890. },
  3891. _download: function FileAttachmentAnnotationElement_download() {
  3892. if (!this.downloadManager) {
  3893. (0, _util.warn)('Download cannot be started due to unavailable download manager');
  3894. return;
  3895. }
  3896. this.downloadManager.downloadData(this.content, this.filename, '');
  3897. }
  3898. });
  3899. return FileAttachmentAnnotationElement;
  3900. }();
  3901. var AnnotationLayer = function AnnotationLayerClosure() {
  3902. return {
  3903. render: function AnnotationLayer_render(parameters) {
  3904. var annotationElementFactory = new AnnotationElementFactory();
  3905. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  3906. var data = parameters.annotations[i];
  3907. if (!data) {
  3908. continue;
  3909. }
  3910. var element = annotationElementFactory.create({
  3911. data: data,
  3912. layer: parameters.div,
  3913. page: parameters.page,
  3914. viewport: parameters.viewport,
  3915. linkService: parameters.linkService,
  3916. downloadManager: parameters.downloadManager,
  3917. imageResourcesPath: parameters.imageResourcesPath || (0, _dom_utils.getDefaultSetting)('imageResourcesPath'),
  3918. renderInteractiveForms: parameters.renderInteractiveForms || false
  3919. });
  3920. if (element.isRenderable) {
  3921. parameters.div.appendChild(element.render());
  3922. }
  3923. }
  3924. },
  3925. update: function AnnotationLayer_update(parameters) {
  3926. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  3927. var data = parameters.annotations[i];
  3928. var element = parameters.div.querySelector('[data-annotation-id="' + data.id + '"]');
  3929. if (element) {
  3930. _dom_utils.CustomStyle.setProp('transform', element, 'matrix(' + parameters.viewport.transform.join(',') + ')');
  3931. }
  3932. }
  3933. parameters.div.removeAttribute('hidden');
  3934. }
  3935. };
  3936. }();
  3937. exports.AnnotationLayer = AnnotationLayer;
  3938. /***/ }),
  3939. /* 4 */
  3940. /***/ (function(module, exports, __w_pdfjs_require__) {
  3941. "use strict";
  3942. Object.defineProperty(exports, "__esModule", {
  3943. value: true
  3944. });
  3945. exports.SVGGraphics = undefined;
  3946. var _util = __w_pdfjs_require__(0);
  3947. var SVGGraphics = function SVGGraphics() {
  3948. throw new Error('Not implemented: SVGGraphics');
  3949. };
  3950. {
  3951. var SVG_DEFAULTS = {
  3952. fontStyle: 'normal',
  3953. fontWeight: 'normal',
  3954. fillColor: '#000000'
  3955. };
  3956. var convertImgDataToPng = function convertImgDataToPngClosure() {
  3957. var PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  3958. var CHUNK_WRAPPER_SIZE = 12;
  3959. var crcTable = new Int32Array(256);
  3960. for (var i = 0; i < 256; i++) {
  3961. var c = i;
  3962. for (var h = 0; h < 8; h++) {
  3963. if (c & 1) {
  3964. c = 0xedB88320 ^ c >> 1 & 0x7fffffff;
  3965. } else {
  3966. c = c >> 1 & 0x7fffffff;
  3967. }
  3968. }
  3969. crcTable[i] = c;
  3970. }
  3971. function crc32(data, start, end) {
  3972. var crc = -1;
  3973. for (var i = start; i < end; i++) {
  3974. var a = (crc ^ data[i]) & 0xff;
  3975. var b = crcTable[a];
  3976. crc = crc >>> 8 ^ b;
  3977. }
  3978. return crc ^ -1;
  3979. }
  3980. function writePngChunk(type, body, data, offset) {
  3981. var p = offset;
  3982. var len = body.length;
  3983. data[p] = len >> 24 & 0xff;
  3984. data[p + 1] = len >> 16 & 0xff;
  3985. data[p + 2] = len >> 8 & 0xff;
  3986. data[p + 3] = len & 0xff;
  3987. p += 4;
  3988. data[p] = type.charCodeAt(0) & 0xff;
  3989. data[p + 1] = type.charCodeAt(1) & 0xff;
  3990. data[p + 2] = type.charCodeAt(2) & 0xff;
  3991. data[p + 3] = type.charCodeAt(3) & 0xff;
  3992. p += 4;
  3993. data.set(body, p);
  3994. p += body.length;
  3995. var crc = crc32(data, offset + 4, p);
  3996. data[p] = crc >> 24 & 0xff;
  3997. data[p + 1] = crc >> 16 & 0xff;
  3998. data[p + 2] = crc >> 8 & 0xff;
  3999. data[p + 3] = crc & 0xff;
  4000. }
  4001. function adler32(data, start, end) {
  4002. var a = 1;
  4003. var b = 0;
  4004. for (var i = start; i < end; ++i) {
  4005. a = (a + (data[i] & 0xff)) % 65521;
  4006. b = (b + a) % 65521;
  4007. }
  4008. return b << 16 | a;
  4009. }
  4010. function deflateSync(literals) {
  4011. if (!(0, _util.isNodeJS)()) {
  4012. return deflateSyncUncompressed(literals);
  4013. }
  4014. try {
  4015. var input;
  4016. if (parseInt(process.versions.node) >= 8) {
  4017. input = literals;
  4018. } else {
  4019. input = new Buffer(literals);
  4020. }
  4021. var output = require('zlib').deflateSync(input, { level: 9 });
  4022. return output instanceof Uint8Array ? output : new Uint8Array(output);
  4023. } catch (e) {
  4024. (0, _util.warn)('Not compressing PNG because zlib.deflateSync is unavailable: ' + e);
  4025. }
  4026. return deflateSyncUncompressed(literals);
  4027. }
  4028. function deflateSyncUncompressed(literals) {
  4029. var len = literals.length;
  4030. var maxBlockLength = 0xFFFF;
  4031. var deflateBlocks = Math.ceil(len / maxBlockLength);
  4032. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  4033. var pi = 0;
  4034. idat[pi++] = 0x78;
  4035. idat[pi++] = 0x9c;
  4036. var pos = 0;
  4037. while (len > maxBlockLength) {
  4038. idat[pi++] = 0x00;
  4039. idat[pi++] = 0xff;
  4040. idat[pi++] = 0xff;
  4041. idat[pi++] = 0x00;
  4042. idat[pi++] = 0x00;
  4043. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  4044. pi += maxBlockLength;
  4045. pos += maxBlockLength;
  4046. len -= maxBlockLength;
  4047. }
  4048. idat[pi++] = 0x01;
  4049. idat[pi++] = len & 0xff;
  4050. idat[pi++] = len >> 8 & 0xff;
  4051. idat[pi++] = ~len & 0xffff & 0xff;
  4052. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  4053. idat.set(literals.subarray(pos), pi);
  4054. pi += literals.length - pos;
  4055. var adler = adler32(literals, 0, literals.length);
  4056. idat[pi++] = adler >> 24 & 0xff;
  4057. idat[pi++] = adler >> 16 & 0xff;
  4058. idat[pi++] = adler >> 8 & 0xff;
  4059. idat[pi++] = adler & 0xff;
  4060. return idat;
  4061. }
  4062. function encode(imgData, kind, forceDataSchema) {
  4063. var width = imgData.width;
  4064. var height = imgData.height;
  4065. var bitDepth, colorType, lineSize;
  4066. var bytes = imgData.data;
  4067. switch (kind) {
  4068. case _util.ImageKind.GRAYSCALE_1BPP:
  4069. colorType = 0;
  4070. bitDepth = 1;
  4071. lineSize = width + 7 >> 3;
  4072. break;
  4073. case _util.ImageKind.RGB_24BPP:
  4074. colorType = 2;
  4075. bitDepth = 8;
  4076. lineSize = width * 3;
  4077. break;
  4078. case _util.ImageKind.RGBA_32BPP:
  4079. colorType = 6;
  4080. bitDepth = 8;
  4081. lineSize = width * 4;
  4082. break;
  4083. default:
  4084. throw new Error('invalid format');
  4085. }
  4086. var literals = new Uint8Array((1 + lineSize) * height);
  4087. var offsetLiterals = 0,
  4088. offsetBytes = 0;
  4089. var y, i;
  4090. for (y = 0; y < height; ++y) {
  4091. literals[offsetLiterals++] = 0;
  4092. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  4093. offsetBytes += lineSize;
  4094. offsetLiterals += lineSize;
  4095. }
  4096. if (kind === _util.ImageKind.GRAYSCALE_1BPP) {
  4097. offsetLiterals = 0;
  4098. for (y = 0; y < height; y++) {
  4099. offsetLiterals++;
  4100. for (i = 0; i < lineSize; i++) {
  4101. literals[offsetLiterals++] ^= 0xFF;
  4102. }
  4103. }
  4104. }
  4105. 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]);
  4106. var idat = deflateSync(literals);
  4107. var pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  4108. var data = new Uint8Array(pngLength);
  4109. var offset = 0;
  4110. data.set(PNG_HEADER, offset);
  4111. offset += PNG_HEADER.length;
  4112. writePngChunk('IHDR', ihdr, data, offset);
  4113. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  4114. writePngChunk('IDATA', idat, data, offset);
  4115. offset += CHUNK_WRAPPER_SIZE + idat.length;
  4116. writePngChunk('IEND', new Uint8Array(0), data, offset);
  4117. return (0, _util.createObjectURL)(data, 'image/png', forceDataSchema);
  4118. }
  4119. return function convertImgDataToPng(imgData, forceDataSchema) {
  4120. var kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
  4121. return encode(imgData, kind, forceDataSchema);
  4122. };
  4123. }();
  4124. var SVGExtraState = function SVGExtraStateClosure() {
  4125. function SVGExtraState() {
  4126. this.fontSizeScale = 1;
  4127. this.fontWeight = SVG_DEFAULTS.fontWeight;
  4128. this.fontSize = 0;
  4129. this.textMatrix = _util.IDENTITY_MATRIX;
  4130. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  4131. this.leading = 0;
  4132. this.x = 0;
  4133. this.y = 0;
  4134. this.lineX = 0;
  4135. this.lineY = 0;
  4136. this.charSpacing = 0;
  4137. this.wordSpacing = 0;
  4138. this.textHScale = 1;
  4139. this.textRise = 0;
  4140. this.fillColor = SVG_DEFAULTS.fillColor;
  4141. this.strokeColor = '#000000';
  4142. this.fillAlpha = 1;
  4143. this.strokeAlpha = 1;
  4144. this.lineWidth = 1;
  4145. this.lineJoin = '';
  4146. this.lineCap = '';
  4147. this.miterLimit = 0;
  4148. this.dashArray = [];
  4149. this.dashPhase = 0;
  4150. this.dependencies = [];
  4151. this.activeClipUrl = null;
  4152. this.clipGroup = null;
  4153. this.maskId = '';
  4154. }
  4155. SVGExtraState.prototype = {
  4156. clone: function SVGExtraState_clone() {
  4157. return Object.create(this);
  4158. },
  4159. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  4160. this.x = x;
  4161. this.y = y;
  4162. }
  4163. };
  4164. return SVGExtraState;
  4165. }();
  4166. exports.SVGGraphics = SVGGraphics = function SVGGraphicsClosure() {
  4167. function opListToTree(opList) {
  4168. var opTree = [];
  4169. var tmp = [];
  4170. var opListLen = opList.length;
  4171. for (var x = 0; x < opListLen; x++) {
  4172. if (opList[x].fn === 'save') {
  4173. opTree.push({
  4174. 'fnId': 92,
  4175. 'fn': 'group',
  4176. 'items': []
  4177. });
  4178. tmp.push(opTree);
  4179. opTree = opTree[opTree.length - 1].items;
  4180. continue;
  4181. }
  4182. if (opList[x].fn === 'restore') {
  4183. opTree = tmp.pop();
  4184. } else {
  4185. opTree.push(opList[x]);
  4186. }
  4187. }
  4188. return opTree;
  4189. }
  4190. function pf(value) {
  4191. if (value === (value | 0)) {
  4192. return value.toString();
  4193. }
  4194. var s = value.toFixed(10);
  4195. var i = s.length - 1;
  4196. if (s[i] !== '0') {
  4197. return s;
  4198. }
  4199. do {
  4200. i--;
  4201. } while (s[i] === '0');
  4202. return s.substr(0, s[i] === '.' ? i : i + 1);
  4203. }
  4204. function pm(m) {
  4205. if (m[4] === 0 && m[5] === 0) {
  4206. if (m[1] === 0 && m[2] === 0) {
  4207. if (m[0] === 1 && m[3] === 1) {
  4208. return '';
  4209. }
  4210. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  4211. }
  4212. if (m[0] === m[3] && m[1] === -m[2]) {
  4213. var a = Math.acos(m[0]) * 180 / Math.PI;
  4214. return 'rotate(' + pf(a) + ')';
  4215. }
  4216. } else {
  4217. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  4218. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  4219. }
  4220. }
  4221. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' + pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  4222. }
  4223. function SVGGraphics(commonObjs, objs, forceDataSchema) {
  4224. this.current = new SVGExtraState();
  4225. this.transformMatrix = _util.IDENTITY_MATRIX;
  4226. this.transformStack = [];
  4227. this.extraStack = [];
  4228. this.commonObjs = commonObjs;
  4229. this.objs = objs;
  4230. this.pendingClip = null;
  4231. this.pendingEOFill = false;
  4232. this.embedFonts = false;
  4233. this.embeddedFonts = Object.create(null);
  4234. this.cssStyle = null;
  4235. this.forceDataSchema = !!forceDataSchema;
  4236. }
  4237. var NS = 'http://www.w3.org/2000/svg';
  4238. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  4239. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  4240. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  4241. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  4242. var clipCount = 0;
  4243. var maskCount = 0;
  4244. SVGGraphics.prototype = {
  4245. save: function SVGGraphics_save() {
  4246. this.transformStack.push(this.transformMatrix);
  4247. var old = this.current;
  4248. this.extraStack.push(old);
  4249. this.current = old.clone();
  4250. },
  4251. restore: function SVGGraphics_restore() {
  4252. this.transformMatrix = this.transformStack.pop();
  4253. this.current = this.extraStack.pop();
  4254. this.pendingClip = null;
  4255. this.tgrp = null;
  4256. },
  4257. group: function SVGGraphics_group(items) {
  4258. this.save();
  4259. this.executeOpTree(items);
  4260. this.restore();
  4261. },
  4262. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  4263. var _this = this;
  4264. var fnArray = operatorList.fnArray;
  4265. var fnArrayLen = fnArray.length;
  4266. var argsArray = operatorList.argsArray;
  4267. for (var i = 0; i < fnArrayLen; i++) {
  4268. if (_util.OPS.dependency === fnArray[i]) {
  4269. var deps = argsArray[i];
  4270. for (var n = 0, nn = deps.length; n < nn; n++) {
  4271. var obj = deps[n];
  4272. var common = obj.substring(0, 2) === 'g_';
  4273. var promise;
  4274. if (common) {
  4275. promise = new Promise(function (resolve) {
  4276. _this.commonObjs.get(obj, resolve);
  4277. });
  4278. } else {
  4279. promise = new Promise(function (resolve) {
  4280. _this.objs.get(obj, resolve);
  4281. });
  4282. }
  4283. this.current.dependencies.push(promise);
  4284. }
  4285. }
  4286. }
  4287. return Promise.all(this.current.dependencies);
  4288. },
  4289. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  4290. var transformMatrix = [a, b, c, d, e, f];
  4291. this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
  4292. this.tgrp = null;
  4293. },
  4294. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  4295. var _this2 = this;
  4296. this.viewport = viewport;
  4297. var svgElement = this._initialize(viewport);
  4298. return this.loadDependencies(operatorList).then(function () {
  4299. _this2.transformMatrix = _util.IDENTITY_MATRIX;
  4300. var opTree = _this2.convertOpList(operatorList);
  4301. _this2.executeOpTree(opTree);
  4302. return svgElement;
  4303. });
  4304. },
  4305. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  4306. var argsArray = operatorList.argsArray;
  4307. var fnArray = operatorList.fnArray;
  4308. var fnArrayLen = fnArray.length;
  4309. var REVOPS = [];
  4310. var opList = [];
  4311. for (var op in _util.OPS) {
  4312. REVOPS[_util.OPS[op]] = op;
  4313. }
  4314. for (var x = 0; x < fnArrayLen; x++) {
  4315. var fnId = fnArray[x];
  4316. opList.push({
  4317. 'fnId': fnId,
  4318. 'fn': REVOPS[fnId],
  4319. 'args': argsArray[x]
  4320. });
  4321. }
  4322. return opListToTree(opList);
  4323. },
  4324. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  4325. var opTreeLen = opTree.length;
  4326. for (var x = 0; x < opTreeLen; x++) {
  4327. var fn = opTree[x].fn;
  4328. var fnId = opTree[x].fnId;
  4329. var args = opTree[x].args;
  4330. switch (fnId | 0) {
  4331. case _util.OPS.beginText:
  4332. this.beginText();
  4333. break;
  4334. case _util.OPS.setLeading:
  4335. this.setLeading(args);
  4336. break;
  4337. case _util.OPS.setLeadingMoveText:
  4338. this.setLeadingMoveText(args[0], args[1]);
  4339. break;
  4340. case _util.OPS.setFont:
  4341. this.setFont(args);
  4342. break;
  4343. case _util.OPS.showText:
  4344. this.showText(args[0]);
  4345. break;
  4346. case _util.OPS.showSpacedText:
  4347. this.showText(args[0]);
  4348. break;
  4349. case _util.OPS.endText:
  4350. this.endText();
  4351. break;
  4352. case _util.OPS.moveText:
  4353. this.moveText(args[0], args[1]);
  4354. break;
  4355. case _util.OPS.setCharSpacing:
  4356. this.setCharSpacing(args[0]);
  4357. break;
  4358. case _util.OPS.setWordSpacing:
  4359. this.setWordSpacing(args[0]);
  4360. break;
  4361. case _util.OPS.setHScale:
  4362. this.setHScale(args[0]);
  4363. break;
  4364. case _util.OPS.setTextMatrix:
  4365. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  4366. break;
  4367. case _util.OPS.setLineWidth:
  4368. this.setLineWidth(args[0]);
  4369. break;
  4370. case _util.OPS.setLineJoin:
  4371. this.setLineJoin(args[0]);
  4372. break;
  4373. case _util.OPS.setLineCap:
  4374. this.setLineCap(args[0]);
  4375. break;
  4376. case _util.OPS.setMiterLimit:
  4377. this.setMiterLimit(args[0]);
  4378. break;
  4379. case _util.OPS.setFillRGBColor:
  4380. this.setFillRGBColor(args[0], args[1], args[2]);
  4381. break;
  4382. case _util.OPS.setStrokeRGBColor:
  4383. this.setStrokeRGBColor(args[0], args[1], args[2]);
  4384. break;
  4385. case _util.OPS.setDash:
  4386. this.setDash(args[0], args[1]);
  4387. break;
  4388. case _util.OPS.setGState:
  4389. this.setGState(args[0]);
  4390. break;
  4391. case _util.OPS.fill:
  4392. this.fill();
  4393. break;
  4394. case _util.OPS.eoFill:
  4395. this.eoFill();
  4396. break;
  4397. case _util.OPS.stroke:
  4398. this.stroke();
  4399. break;
  4400. case _util.OPS.fillStroke:
  4401. this.fillStroke();
  4402. break;
  4403. case _util.OPS.eoFillStroke:
  4404. this.eoFillStroke();
  4405. break;
  4406. case _util.OPS.clip:
  4407. this.clip('nonzero');
  4408. break;
  4409. case _util.OPS.eoClip:
  4410. this.clip('evenodd');
  4411. break;
  4412. case _util.OPS.paintSolidColorImageMask:
  4413. this.paintSolidColorImageMask();
  4414. break;
  4415. case _util.OPS.paintJpegXObject:
  4416. this.paintJpegXObject(args[0], args[1], args[2]);
  4417. break;
  4418. case _util.OPS.paintImageXObject:
  4419. this.paintImageXObject(args[0]);
  4420. break;
  4421. case _util.OPS.paintInlineImageXObject:
  4422. this.paintInlineImageXObject(args[0]);
  4423. break;
  4424. case _util.OPS.paintImageMaskXObject:
  4425. this.paintImageMaskXObject(args[0]);
  4426. break;
  4427. case _util.OPS.paintFormXObjectBegin:
  4428. this.paintFormXObjectBegin(args[0], args[1]);
  4429. break;
  4430. case _util.OPS.paintFormXObjectEnd:
  4431. this.paintFormXObjectEnd();
  4432. break;
  4433. case _util.OPS.closePath:
  4434. this.closePath();
  4435. break;
  4436. case _util.OPS.closeStroke:
  4437. this.closeStroke();
  4438. break;
  4439. case _util.OPS.closeFillStroke:
  4440. this.closeFillStroke();
  4441. break;
  4442. case _util.OPS.nextLine:
  4443. this.nextLine();
  4444. break;
  4445. case _util.OPS.transform:
  4446. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  4447. break;
  4448. case _util.OPS.constructPath:
  4449. this.constructPath(args[0], args[1]);
  4450. break;
  4451. case _util.OPS.endPath:
  4452. this.endPath();
  4453. break;
  4454. case 92:
  4455. this.group(opTree[x].items);
  4456. break;
  4457. default:
  4458. (0, _util.warn)('Unimplemented operator ' + fn);
  4459. break;
  4460. }
  4461. }
  4462. },
  4463. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  4464. this.current.wordSpacing = wordSpacing;
  4465. },
  4466. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  4467. this.current.charSpacing = charSpacing;
  4468. },
  4469. nextLine: function SVGGraphics_nextLine() {
  4470. this.moveText(0, this.current.leading);
  4471. },
  4472. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  4473. var current = this.current;
  4474. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  4475. this.current.x = this.current.lineX = 0;
  4476. this.current.y = this.current.lineY = 0;
  4477. current.xcoords = [];
  4478. current.tspan = document.createElementNS(NS, 'svg:tspan');
  4479. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  4480. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  4481. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  4482. current.txtElement = document.createElementNS(NS, 'svg:text');
  4483. current.txtElement.appendChild(current.tspan);
  4484. },
  4485. beginText: function SVGGraphics_beginText() {
  4486. this.current.x = this.current.lineX = 0;
  4487. this.current.y = this.current.lineY = 0;
  4488. this.current.textMatrix = _util.IDENTITY_MATRIX;
  4489. this.current.lineMatrix = _util.IDENTITY_MATRIX;
  4490. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  4491. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  4492. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  4493. this.current.xcoords = [];
  4494. },
  4495. moveText: function SVGGraphics_moveText(x, y) {
  4496. var current = this.current;
  4497. this.current.x = this.current.lineX += x;
  4498. this.current.y = this.current.lineY += y;
  4499. current.xcoords = [];
  4500. current.tspan = document.createElementNS(NS, 'svg:tspan');
  4501. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  4502. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  4503. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  4504. },
  4505. showText: function SVGGraphics_showText(glyphs) {
  4506. var current = this.current;
  4507. var font = current.font;
  4508. var fontSize = current.fontSize;
  4509. if (fontSize === 0) {
  4510. return;
  4511. }
  4512. var charSpacing = current.charSpacing;
  4513. var wordSpacing = current.wordSpacing;
  4514. var fontDirection = current.fontDirection;
  4515. var textHScale = current.textHScale * fontDirection;
  4516. var glyphsLength = glyphs.length;
  4517. var vertical = font.vertical;
  4518. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4519. var x = 0,
  4520. i;
  4521. for (i = 0; i < glyphsLength; ++i) {
  4522. var glyph = glyphs[i];
  4523. if (glyph === null) {
  4524. x += fontDirection * wordSpacing;
  4525. continue;
  4526. } else if ((0, _util.isNum)(glyph)) {
  4527. x += -glyph * fontSize * 0.001;
  4528. continue;
  4529. }
  4530. current.xcoords.push(current.x + x * textHScale);
  4531. var width = glyph.width;
  4532. var character = glyph.fontChar;
  4533. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4534. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  4535. x += charWidth;
  4536. current.tspan.textContent += character;
  4537. }
  4538. if (vertical) {
  4539. current.y -= x * textHScale;
  4540. } else {
  4541. current.x += x * textHScale;
  4542. }
  4543. current.tspan.setAttributeNS(null, 'x', current.xcoords.map(pf).join(' '));
  4544. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  4545. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  4546. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  4547. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  4548. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  4549. }
  4550. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  4551. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  4552. }
  4553. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  4554. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  4555. }
  4556. current.txtElement.setAttributeNS(null, 'transform', pm(current.textMatrix) + ' scale(1, -1)');
  4557. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  4558. current.txtElement.appendChild(current.tspan);
  4559. current.txtgrp.appendChild(current.txtElement);
  4560. this._ensureTransformGroup().appendChild(current.txtElement);
  4561. },
  4562. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  4563. this.setLeading(-y);
  4564. this.moveText(x, y);
  4565. },
  4566. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  4567. if (!this.cssStyle) {
  4568. this.cssStyle = document.createElementNS(NS, 'svg:style');
  4569. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  4570. this.defs.appendChild(this.cssStyle);
  4571. }
  4572. var url = (0, _util.createObjectURL)(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  4573. this.cssStyle.textContent += '@font-face { font-family: "' + fontObj.loadedName + '";' + ' src: url(' + url + '); }\n';
  4574. },
  4575. setFont: function SVGGraphics_setFont(details) {
  4576. var current = this.current;
  4577. var fontObj = this.commonObjs.get(details[0]);
  4578. var size = details[1];
  4579. this.current.font = fontObj;
  4580. if (this.embedFonts && fontObj.data && !this.embeddedFonts[fontObj.loadedName]) {
  4581. this.addFontStyle(fontObj);
  4582. this.embeddedFonts[fontObj.loadedName] = fontObj;
  4583. }
  4584. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
  4585. var bold = fontObj.black ? fontObj.bold ? 'bolder' : 'bold' : fontObj.bold ? 'bold' : 'normal';
  4586. var italic = fontObj.italic ? 'italic' : 'normal';
  4587. if (size < 0) {
  4588. size = -size;
  4589. current.fontDirection = -1;
  4590. } else {
  4591. current.fontDirection = 1;
  4592. }
  4593. current.fontSize = size;
  4594. current.fontFamily = fontObj.loadedName;
  4595. current.fontWeight = bold;
  4596. current.fontStyle = italic;
  4597. current.tspan = document.createElementNS(NS, 'svg:tspan');
  4598. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  4599. current.xcoords = [];
  4600. },
  4601. endText: function SVGGraphics_endText() {},
  4602. setLineWidth: function SVGGraphics_setLineWidth(width) {
  4603. this.current.lineWidth = width;
  4604. },
  4605. setLineCap: function SVGGraphics_setLineCap(style) {
  4606. this.current.lineCap = LINE_CAP_STYLES[style];
  4607. },
  4608. setLineJoin: function SVGGraphics_setLineJoin(style) {
  4609. this.current.lineJoin = LINE_JOIN_STYLES[style];
  4610. },
  4611. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  4612. this.current.miterLimit = limit;
  4613. },
  4614. setStrokeAlpha: function SVGGraphics_setStrokeAlpha(strokeAlpha) {
  4615. this.current.strokeAlpha = strokeAlpha;
  4616. },
  4617. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  4618. var color = _util.Util.makeCssRgb(r, g, b);
  4619. this.current.strokeColor = color;
  4620. },
  4621. setFillAlpha: function SVGGraphics_setFillAlpha(fillAlpha) {
  4622. this.current.fillAlpha = fillAlpha;
  4623. },
  4624. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  4625. var color = _util.Util.makeCssRgb(r, g, b);
  4626. this.current.fillColor = color;
  4627. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  4628. this.current.xcoords = [];
  4629. },
  4630. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  4631. this.current.dashArray = dashArray;
  4632. this.current.dashPhase = dashPhase;
  4633. },
  4634. constructPath: function SVGGraphics_constructPath(ops, args) {
  4635. var current = this.current;
  4636. var x = current.x,
  4637. y = current.y;
  4638. current.path = document.createElementNS(NS, 'svg:path');
  4639. var d = [];
  4640. var opLength = ops.length;
  4641. for (var i = 0, j = 0; i < opLength; i++) {
  4642. switch (ops[i] | 0) {
  4643. case _util.OPS.rectangle:
  4644. x = args[j++];
  4645. y = args[j++];
  4646. var width = args[j++];
  4647. var height = args[j++];
  4648. var xw = x + width;
  4649. var yh = y + height;
  4650. d.push('M', pf(x), pf(y), 'L', pf(xw), pf(y), 'L', pf(xw), pf(yh), 'L', pf(x), pf(yh), 'Z');
  4651. break;
  4652. case _util.OPS.moveTo:
  4653. x = args[j++];
  4654. y = args[j++];
  4655. d.push('M', pf(x), pf(y));
  4656. break;
  4657. case _util.OPS.lineTo:
  4658. x = args[j++];
  4659. y = args[j++];
  4660. d.push('L', pf(x), pf(y));
  4661. break;
  4662. case _util.OPS.curveTo:
  4663. x = args[j + 4];
  4664. y = args[j + 5];
  4665. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  4666. j += 6;
  4667. break;
  4668. case _util.OPS.curveTo2:
  4669. x = args[j + 2];
  4670. y = args[j + 3];
  4671. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  4672. j += 4;
  4673. break;
  4674. case _util.OPS.curveTo3:
  4675. x = args[j + 2];
  4676. y = args[j + 3];
  4677. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  4678. j += 4;
  4679. break;
  4680. case _util.OPS.closePath:
  4681. d.push('Z');
  4682. break;
  4683. }
  4684. }
  4685. current.path.setAttributeNS(null, 'd', d.join(' '));
  4686. current.path.setAttributeNS(null, 'fill', 'none');
  4687. this._ensureTransformGroup().appendChild(current.path);
  4688. current.element = current.path;
  4689. current.setCurrentPoint(x, y);
  4690. },
  4691. endPath: function SVGGraphics_endPath() {
  4692. if (!this.pendingClip) {
  4693. return;
  4694. }
  4695. var current = this.current;
  4696. var clipId = 'clippath' + clipCount;
  4697. clipCount++;
  4698. var clipPath = document.createElementNS(NS, 'svg:clipPath');
  4699. clipPath.setAttributeNS(null, 'id', clipId);
  4700. clipPath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  4701. var clipElement = current.element.cloneNode();
  4702. if (this.pendingClip === 'evenodd') {
  4703. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  4704. } else {
  4705. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  4706. }
  4707. this.pendingClip = null;
  4708. clipPath.appendChild(clipElement);
  4709. this.defs.appendChild(clipPath);
  4710. if (current.activeClipUrl) {
  4711. current.clipGroup = null;
  4712. this.extraStack.forEach(function (prev) {
  4713. prev.clipGroup = null;
  4714. });
  4715. }
  4716. current.activeClipUrl = 'url(#' + clipId + ')';
  4717. this.tgrp = null;
  4718. },
  4719. clip: function SVGGraphics_clip(type) {
  4720. this.pendingClip = type;
  4721. },
  4722. closePath: function SVGGraphics_closePath() {
  4723. var current = this.current;
  4724. var d = current.path.getAttributeNS(null, 'd');
  4725. d += 'Z';
  4726. current.path.setAttributeNS(null, 'd', d);
  4727. },
  4728. setLeading: function SVGGraphics_setLeading(leading) {
  4729. this.current.leading = -leading;
  4730. },
  4731. setTextRise: function SVGGraphics_setTextRise(textRise) {
  4732. this.current.textRise = textRise;
  4733. },
  4734. setHScale: function SVGGraphics_setHScale(scale) {
  4735. this.current.textHScale = scale / 100;
  4736. },
  4737. setGState: function SVGGraphics_setGState(states) {
  4738. for (var i = 0, ii = states.length; i < ii; i++) {
  4739. var state = states[i];
  4740. var key = state[0];
  4741. var value = state[1];
  4742. switch (key) {
  4743. case 'LW':
  4744. this.setLineWidth(value);
  4745. break;
  4746. case 'LC':
  4747. this.setLineCap(value);
  4748. break;
  4749. case 'LJ':
  4750. this.setLineJoin(value);
  4751. break;
  4752. case 'ML':
  4753. this.setMiterLimit(value);
  4754. break;
  4755. case 'D':
  4756. this.setDash(value[0], value[1]);
  4757. break;
  4758. case 'Font':
  4759. this.setFont(value);
  4760. break;
  4761. case 'CA':
  4762. this.setStrokeAlpha(value);
  4763. break;
  4764. case 'ca':
  4765. this.setFillAlpha(value);
  4766. break;
  4767. default:
  4768. (0, _util.warn)('Unimplemented graphic state ' + key);
  4769. break;
  4770. }
  4771. }
  4772. },
  4773. fill: function SVGGraphics_fill() {
  4774. var current = this.current;
  4775. current.element.setAttributeNS(null, 'fill', current.fillColor);
  4776. current.element.setAttributeNS(null, 'fill-opacity', current.fillAlpha);
  4777. },
  4778. stroke: function SVGGraphics_stroke() {
  4779. var current = this.current;
  4780. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  4781. current.element.setAttributeNS(null, 'stroke-opacity', current.strokeAlpha);
  4782. current.element.setAttributeNS(null, 'stroke-miterlimit', pf(current.miterLimit));
  4783. current.element.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  4784. current.element.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  4785. current.element.setAttributeNS(null, 'stroke-width', pf(current.lineWidth) + 'px');
  4786. current.element.setAttributeNS(null, 'stroke-dasharray', current.dashArray.map(pf).join(' '));
  4787. current.element.setAttributeNS(null, 'stroke-dashoffset', pf(current.dashPhase) + 'px');
  4788. current.element.setAttributeNS(null, 'fill', 'none');
  4789. },
  4790. eoFill: function SVGGraphics_eoFill() {
  4791. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  4792. this.fill();
  4793. },
  4794. fillStroke: function SVGGraphics_fillStroke() {
  4795. this.stroke();
  4796. this.fill();
  4797. },
  4798. eoFillStroke: function SVGGraphics_eoFillStroke() {
  4799. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  4800. this.fillStroke();
  4801. },
  4802. closeStroke: function SVGGraphics_closeStroke() {
  4803. this.closePath();
  4804. this.stroke();
  4805. },
  4806. closeFillStroke: function SVGGraphics_closeFillStroke() {
  4807. this.closePath();
  4808. this.fillStroke();
  4809. },
  4810. paintSolidColorImageMask: function SVGGraphics_paintSolidColorImageMask() {
  4811. var current = this.current;
  4812. var rect = document.createElementNS(NS, 'svg:rect');
  4813. rect.setAttributeNS(null, 'x', '0');
  4814. rect.setAttributeNS(null, 'y', '0');
  4815. rect.setAttributeNS(null, 'width', '1px');
  4816. rect.setAttributeNS(null, 'height', '1px');
  4817. rect.setAttributeNS(null, 'fill', current.fillColor);
  4818. this._ensureTransformGroup().appendChild(rect);
  4819. },
  4820. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  4821. var imgObj = this.objs.get(objId);
  4822. var imgEl = document.createElementNS(NS, 'svg:image');
  4823. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  4824. imgEl.setAttributeNS(null, 'width', pf(w));
  4825. imgEl.setAttributeNS(null, 'height', pf(h));
  4826. imgEl.setAttributeNS(null, 'x', '0');
  4827. imgEl.setAttributeNS(null, 'y', pf(-h));
  4828. imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  4829. this._ensureTransformGroup().appendChild(imgEl);
  4830. },
  4831. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  4832. var imgData = this.objs.get(objId);
  4833. if (!imgData) {
  4834. (0, _util.warn)('Dependent image isn\'t ready yet');
  4835. return;
  4836. }
  4837. this.paintInlineImageXObject(imgData);
  4838. },
  4839. paintInlineImageXObject: function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  4840. var width = imgData.width;
  4841. var height = imgData.height;
  4842. var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema);
  4843. var cliprect = document.createElementNS(NS, 'svg:rect');
  4844. cliprect.setAttributeNS(null, 'x', '0');
  4845. cliprect.setAttributeNS(null, 'y', '0');
  4846. cliprect.setAttributeNS(null, 'width', pf(width));
  4847. cliprect.setAttributeNS(null, 'height', pf(height));
  4848. this.current.element = cliprect;
  4849. this.clip('nonzero');
  4850. var imgEl = document.createElementNS(NS, 'svg:image');
  4851. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  4852. imgEl.setAttributeNS(null, 'x', '0');
  4853. imgEl.setAttributeNS(null, 'y', pf(-height));
  4854. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  4855. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  4856. imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / width) + ' ' + pf(-1 / height) + ')');
  4857. if (mask) {
  4858. mask.appendChild(imgEl);
  4859. } else {
  4860. this._ensureTransformGroup().appendChild(imgEl);
  4861. }
  4862. },
  4863. paintImageMaskXObject: function SVGGraphics_paintImageMaskXObject(imgData) {
  4864. var current = this.current;
  4865. var width = imgData.width;
  4866. var height = imgData.height;
  4867. var fillColor = current.fillColor;
  4868. current.maskId = 'mask' + maskCount++;
  4869. var mask = document.createElementNS(NS, 'svg:mask');
  4870. mask.setAttributeNS(null, 'id', current.maskId);
  4871. var rect = document.createElementNS(NS, 'svg:rect');
  4872. rect.setAttributeNS(null, 'x', '0');
  4873. rect.setAttributeNS(null, 'y', '0');
  4874. rect.setAttributeNS(null, 'width', pf(width));
  4875. rect.setAttributeNS(null, 'height', pf(height));
  4876. rect.setAttributeNS(null, 'fill', fillColor);
  4877. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId + ')');
  4878. this.defs.appendChild(mask);
  4879. this._ensureTransformGroup().appendChild(rect);
  4880. this.paintInlineImageXObject(imgData, mask);
  4881. },
  4882. paintFormXObjectBegin: function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  4883. if ((0, _util.isArray)(matrix) && matrix.length === 6) {
  4884. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  4885. }
  4886. if ((0, _util.isArray)(bbox) && bbox.length === 4) {
  4887. var width = bbox[2] - bbox[0];
  4888. var height = bbox[3] - bbox[1];
  4889. var cliprect = document.createElementNS(NS, 'svg:rect');
  4890. cliprect.setAttributeNS(null, 'x', bbox[0]);
  4891. cliprect.setAttributeNS(null, 'y', bbox[1]);
  4892. cliprect.setAttributeNS(null, 'width', pf(width));
  4893. cliprect.setAttributeNS(null, 'height', pf(height));
  4894. this.current.element = cliprect;
  4895. this.clip('nonzero');
  4896. this.endPath();
  4897. }
  4898. },
  4899. paintFormXObjectEnd: function SVGGraphics_paintFormXObjectEnd() {},
  4900. _initialize: function SVGGraphics_initialize(viewport) {
  4901. var svg = document.createElementNS(NS, 'svg:svg');
  4902. svg.setAttributeNS(null, 'version', '1.1');
  4903. svg.setAttributeNS(null, 'width', viewport.width + 'px');
  4904. svg.setAttributeNS(null, 'height', viewport.height + 'px');
  4905. svg.setAttributeNS(null, 'preserveAspectRatio', 'none');
  4906. svg.setAttributeNS(null, 'viewBox', '0 0 ' + viewport.width + ' ' + viewport.height);
  4907. var definitions = document.createElementNS(NS, 'svg:defs');
  4908. svg.appendChild(definitions);
  4909. this.defs = definitions;
  4910. var rootGroup = document.createElementNS(NS, 'svg:g');
  4911. rootGroup.setAttributeNS(null, 'transform', pm(viewport.transform));
  4912. svg.appendChild(rootGroup);
  4913. this.svg = rootGroup;
  4914. return svg;
  4915. },
  4916. _ensureClipGroup: function SVGGraphics_ensureClipGroup() {
  4917. if (!this.current.clipGroup) {
  4918. var clipGroup = document.createElementNS(NS, 'svg:g');
  4919. clipGroup.setAttributeNS(null, 'clip-path', this.current.activeClipUrl);
  4920. this.svg.appendChild(clipGroup);
  4921. this.current.clipGroup = clipGroup;
  4922. }
  4923. return this.current.clipGroup;
  4924. },
  4925. _ensureTransformGroup: function SVGGraphics_ensureTransformGroup() {
  4926. if (!this.tgrp) {
  4927. this.tgrp = document.createElementNS(NS, 'svg:g');
  4928. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  4929. if (this.current.activeClipUrl) {
  4930. this._ensureClipGroup().appendChild(this.tgrp);
  4931. } else {
  4932. this.svg.appendChild(this.tgrp);
  4933. }
  4934. }
  4935. return this.tgrp;
  4936. }
  4937. };
  4938. return SVGGraphics;
  4939. }();
  4940. }
  4941. exports.SVGGraphics = SVGGraphics;
  4942. /***/ }),
  4943. /* 5 */
  4944. /***/ (function(module, exports, __w_pdfjs_require__) {
  4945. "use strict";
  4946. Object.defineProperty(exports, "__esModule", {
  4947. value: true
  4948. });
  4949. exports.renderTextLayer = undefined;
  4950. var _util = __w_pdfjs_require__(0);
  4951. var _dom_utils = __w_pdfjs_require__(1);
  4952. var renderTextLayer = function renderTextLayerClosure() {
  4953. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  4954. var NonWhitespaceRegexp = /\S/;
  4955. function isAllWhitespace(str) {
  4956. return !NonWhitespaceRegexp.test(str);
  4957. }
  4958. var styleBuf = ['left: ', 0, 'px; top: ', 0, 'px; font-size: ', 0, 'px; font-family: ', '', ';'];
  4959. function appendText(task, geom, styles) {
  4960. var textDiv = document.createElement('div');
  4961. var textDivProperties = {
  4962. style: null,
  4963. angle: 0,
  4964. canvasWidth: 0,
  4965. isWhitespace: false,
  4966. originalTransform: null,
  4967. paddingBottom: 0,
  4968. paddingLeft: 0,
  4969. paddingRight: 0,
  4970. paddingTop: 0,
  4971. scale: 1
  4972. };
  4973. task._textDivs.push(textDiv);
  4974. if (isAllWhitespace(geom.str)) {
  4975. textDivProperties.isWhitespace = true;
  4976. task._textDivProperties.set(textDiv, textDivProperties);
  4977. return;
  4978. }
  4979. var tx = _util.Util.transform(task._viewport.transform, geom.transform);
  4980. var angle = Math.atan2(tx[1], tx[0]);
  4981. var style = styles[geom.fontName];
  4982. if (style.vertical) {
  4983. angle += Math.PI / 2;
  4984. }
  4985. var fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]);
  4986. var fontAscent = fontHeight;
  4987. if (style.ascent) {
  4988. fontAscent = style.ascent * fontAscent;
  4989. } else if (style.descent) {
  4990. fontAscent = (1 + style.descent) * fontAscent;
  4991. }
  4992. var left;
  4993. var top;
  4994. if (angle === 0) {
  4995. left = tx[4];
  4996. top = tx[5] - fontAscent;
  4997. } else {
  4998. left = tx[4] + fontAscent * Math.sin(angle);
  4999. top = tx[5] - fontAscent * Math.cos(angle);
  5000. }
  5001. styleBuf[1] = left;
  5002. styleBuf[3] = top;
  5003. styleBuf[5] = fontHeight;
  5004. styleBuf[7] = style.fontFamily;
  5005. textDivProperties.style = styleBuf.join('');
  5006. textDiv.setAttribute('style', textDivProperties.style);
  5007. textDiv.textContent = geom.str;
  5008. if ((0, _dom_utils.getDefaultSetting)('pdfBug')) {
  5009. textDiv.dataset.fontName = geom.fontName;
  5010. }
  5011. if (angle !== 0) {
  5012. textDivProperties.angle = angle * (180 / Math.PI);
  5013. }
  5014. if (geom.str.length > 1) {
  5015. if (style.vertical) {
  5016. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  5017. } else {
  5018. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  5019. }
  5020. }
  5021. task._textDivProperties.set(textDiv, textDivProperties);
  5022. if (task._textContentStream) {
  5023. task._layoutText(textDiv);
  5024. }
  5025. if (task._enhanceTextSelection) {
  5026. var angleCos = 1,
  5027. angleSin = 0;
  5028. if (angle !== 0) {
  5029. angleCos = Math.cos(angle);
  5030. angleSin = Math.sin(angle);
  5031. }
  5032. var divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
  5033. var divHeight = fontHeight;
  5034. var m, b;
  5035. if (angle !== 0) {
  5036. m = [angleCos, angleSin, -angleSin, angleCos, left, top];
  5037. b = _util.Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
  5038. } else {
  5039. b = [left, top, left + divWidth, top + divHeight];
  5040. }
  5041. task._bounds.push({
  5042. left: b[0],
  5043. top: b[1],
  5044. right: b[2],
  5045. bottom: b[3],
  5046. div: textDiv,
  5047. size: [divWidth, divHeight],
  5048. m: m
  5049. });
  5050. }
  5051. }
  5052. function render(task) {
  5053. if (task._canceled) {
  5054. return;
  5055. }
  5056. var textDivs = task._textDivs;
  5057. var capability = task._capability;
  5058. var textDivsLength = textDivs.length;
  5059. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  5060. task._renderingDone = true;
  5061. capability.resolve();
  5062. return;
  5063. }
  5064. if (!task._textContentStream) {
  5065. for (var i = 0; i < textDivsLength; i++) {
  5066. task._layoutText(textDivs[i]);
  5067. }
  5068. }
  5069. task._renderingDone = true;
  5070. capability.resolve();
  5071. }
  5072. function expand(task) {
  5073. var bounds = task._bounds;
  5074. var viewport = task._viewport;
  5075. var expanded = expandBounds(viewport.width, viewport.height, bounds);
  5076. for (var i = 0; i < expanded.length; i++) {
  5077. var div = bounds[i].div;
  5078. var divProperties = task._textDivProperties.get(div);
  5079. if (divProperties.angle === 0) {
  5080. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  5081. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  5082. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  5083. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  5084. task._textDivProperties.set(div, divProperties);
  5085. continue;
  5086. }
  5087. var e = expanded[i],
  5088. b = bounds[i];
  5089. var m = b.m,
  5090. c = m[0],
  5091. s = m[1];
  5092. var points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
  5093. var ts = new Float64Array(64);
  5094. points.forEach(function (p, i) {
  5095. var t = _util.Util.applyTransform(p, m);
  5096. ts[i + 0] = c && (e.left - t[0]) / c;
  5097. ts[i + 4] = s && (e.top - t[1]) / s;
  5098. ts[i + 8] = c && (e.right - t[0]) / c;
  5099. ts[i + 12] = s && (e.bottom - t[1]) / s;
  5100. ts[i + 16] = s && (e.left - t[0]) / -s;
  5101. ts[i + 20] = c && (e.top - t[1]) / c;
  5102. ts[i + 24] = s && (e.right - t[0]) / -s;
  5103. ts[i + 28] = c && (e.bottom - t[1]) / c;
  5104. ts[i + 32] = c && (e.left - t[0]) / -c;
  5105. ts[i + 36] = s && (e.top - t[1]) / -s;
  5106. ts[i + 40] = c && (e.right - t[0]) / -c;
  5107. ts[i + 44] = s && (e.bottom - t[1]) / -s;
  5108. ts[i + 48] = s && (e.left - t[0]) / s;
  5109. ts[i + 52] = c && (e.top - t[1]) / -c;
  5110. ts[i + 56] = s && (e.right - t[0]) / s;
  5111. ts[i + 60] = c && (e.bottom - t[1]) / -c;
  5112. });
  5113. var findPositiveMin = function findPositiveMin(ts, offset, count) {
  5114. var result = 0;
  5115. for (var i = 0; i < count; i++) {
  5116. var t = ts[offset++];
  5117. if (t > 0) {
  5118. result = result ? Math.min(t, result) : t;
  5119. }
  5120. }
  5121. return result;
  5122. };
  5123. var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  5124. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  5125. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  5126. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  5127. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  5128. task._textDivProperties.set(div, divProperties);
  5129. }
  5130. }
  5131. function expandBounds(width, height, boxes) {
  5132. var bounds = boxes.map(function (box, i) {
  5133. return {
  5134. x1: box.left,
  5135. y1: box.top,
  5136. x2: box.right,
  5137. y2: box.bottom,
  5138. index: i,
  5139. x1New: undefined,
  5140. x2New: undefined
  5141. };
  5142. });
  5143. expandBoundsLTR(width, bounds);
  5144. var expanded = new Array(boxes.length);
  5145. bounds.forEach(function (b) {
  5146. var i = b.index;
  5147. expanded[i] = {
  5148. left: b.x1New,
  5149. top: 0,
  5150. right: b.x2New,
  5151. bottom: 0
  5152. };
  5153. });
  5154. boxes.map(function (box, i) {
  5155. var e = expanded[i],
  5156. b = bounds[i];
  5157. b.x1 = box.top;
  5158. b.y1 = width - e.right;
  5159. b.x2 = box.bottom;
  5160. b.y2 = width - e.left;
  5161. b.index = i;
  5162. b.x1New = undefined;
  5163. b.x2New = undefined;
  5164. });
  5165. expandBoundsLTR(height, bounds);
  5166. bounds.forEach(function (b) {
  5167. var i = b.index;
  5168. expanded[i].top = b.x1New;
  5169. expanded[i].bottom = b.x2New;
  5170. });
  5171. return expanded;
  5172. }
  5173. function expandBoundsLTR(width, bounds) {
  5174. bounds.sort(function (a, b) {
  5175. return a.x1 - b.x1 || a.index - b.index;
  5176. });
  5177. var fakeBoundary = {
  5178. x1: -Infinity,
  5179. y1: -Infinity,
  5180. x2: 0,
  5181. y2: Infinity,
  5182. index: -1,
  5183. x1New: 0,
  5184. x2New: 0
  5185. };
  5186. var horizon = [{
  5187. start: -Infinity,
  5188. end: Infinity,
  5189. boundary: fakeBoundary
  5190. }];
  5191. bounds.forEach(function (boundary) {
  5192. var i = 0;
  5193. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  5194. i++;
  5195. }
  5196. var j = horizon.length - 1;
  5197. while (j >= 0 && horizon[j].start >= boundary.y2) {
  5198. j--;
  5199. }
  5200. var horizonPart, affectedBoundary;
  5201. var q,
  5202. k,
  5203. maxXNew = -Infinity;
  5204. for (q = i; q <= j; q++) {
  5205. horizonPart = horizon[q];
  5206. affectedBoundary = horizonPart.boundary;
  5207. var xNew;
  5208. if (affectedBoundary.x2 > boundary.x1) {
  5209. xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
  5210. } else if (affectedBoundary.x2New === undefined) {
  5211. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  5212. } else {
  5213. xNew = affectedBoundary.x2New;
  5214. }
  5215. if (xNew > maxXNew) {
  5216. maxXNew = xNew;
  5217. }
  5218. }
  5219. boundary.x1New = maxXNew;
  5220. for (q = i; q <= j; q++) {
  5221. horizonPart = horizon[q];
  5222. affectedBoundary = horizonPart.boundary;
  5223. if (affectedBoundary.x2New === undefined) {
  5224. if (affectedBoundary.x2 > boundary.x1) {
  5225. if (affectedBoundary.index > boundary.index) {
  5226. affectedBoundary.x2New = affectedBoundary.x2;
  5227. }
  5228. } else {
  5229. affectedBoundary.x2New = maxXNew;
  5230. }
  5231. } else if (affectedBoundary.x2New > maxXNew) {
  5232. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  5233. }
  5234. }
  5235. var changedHorizon = [],
  5236. lastBoundary = null;
  5237. for (q = i; q <= j; q++) {
  5238. horizonPart = horizon[q];
  5239. affectedBoundary = horizonPart.boundary;
  5240. var useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
  5241. if (lastBoundary === useBoundary) {
  5242. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  5243. } else {
  5244. changedHorizon.push({
  5245. start: horizonPart.start,
  5246. end: horizonPart.end,
  5247. boundary: useBoundary
  5248. });
  5249. lastBoundary = useBoundary;
  5250. }
  5251. }
  5252. if (horizon[i].start < boundary.y1) {
  5253. changedHorizon[0].start = boundary.y1;
  5254. changedHorizon.unshift({
  5255. start: horizon[i].start,
  5256. end: boundary.y1,
  5257. boundary: horizon[i].boundary
  5258. });
  5259. }
  5260. if (boundary.y2 < horizon[j].end) {
  5261. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  5262. changedHorizon.push({
  5263. start: boundary.y2,
  5264. end: horizon[j].end,
  5265. boundary: horizon[j].boundary
  5266. });
  5267. }
  5268. for (q = i; q <= j; q++) {
  5269. horizonPart = horizon[q];
  5270. affectedBoundary = horizonPart.boundary;
  5271. if (affectedBoundary.x2New !== undefined) {
  5272. continue;
  5273. }
  5274. var used = false;
  5275. for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
  5276. used = horizon[k].boundary === affectedBoundary;
  5277. }
  5278. for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
  5279. used = horizon[k].boundary === affectedBoundary;
  5280. }
  5281. for (k = 0; !used && k < changedHorizon.length; k++) {
  5282. used = changedHorizon[k].boundary === affectedBoundary;
  5283. }
  5284. if (!used) {
  5285. affectedBoundary.x2New = maxXNew;
  5286. }
  5287. }
  5288. Array.prototype.splice.apply(horizon, [i, j - i + 1].concat(changedHorizon));
  5289. });
  5290. horizon.forEach(function (horizonPart) {
  5291. var affectedBoundary = horizonPart.boundary;
  5292. if (affectedBoundary.x2New === undefined) {
  5293. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  5294. }
  5295. });
  5296. }
  5297. function TextLayerRenderTask(_ref) {
  5298. var textContent = _ref.textContent,
  5299. textContentStream = _ref.textContentStream,
  5300. container = _ref.container,
  5301. viewport = _ref.viewport,
  5302. textDivs = _ref.textDivs,
  5303. textContentItemsStr = _ref.textContentItemsStr,
  5304. enhanceTextSelection = _ref.enhanceTextSelection;
  5305. this._textContent = textContent;
  5306. this._textContentStream = textContentStream;
  5307. this._container = container;
  5308. this._viewport = viewport;
  5309. this._textDivs = textDivs || [];
  5310. this._textContentItemsStr = textContentItemsStr || [];
  5311. this._enhanceTextSelection = !!enhanceTextSelection;
  5312. this._reader = null;
  5313. this._layoutTextLastFontSize = null;
  5314. this._layoutTextLastFontFamily = null;
  5315. this._layoutTextCtx = null;
  5316. this._textDivProperties = new WeakMap();
  5317. this._renderingDone = false;
  5318. this._canceled = false;
  5319. this._capability = (0, _util.createPromiseCapability)();
  5320. this._renderTimer = null;
  5321. this._bounds = [];
  5322. }
  5323. TextLayerRenderTask.prototype = {
  5324. get promise() {
  5325. return this._capability.promise;
  5326. },
  5327. cancel: function TextLayer_cancel() {
  5328. if (this._reader) {
  5329. this._reader.cancel(new _util.AbortException('text layer task cancelled'));
  5330. this._reader = null;
  5331. }
  5332. this._canceled = true;
  5333. if (this._renderTimer !== null) {
  5334. clearTimeout(this._renderTimer);
  5335. this._renderTimer = null;
  5336. }
  5337. this._capability.reject('canceled');
  5338. },
  5339. _processItems: function _processItems(items, styleCache) {
  5340. for (var i = 0, len = items.length; i < len; i++) {
  5341. this._textContentItemsStr.push(items[i].str);
  5342. appendText(this, items[i], styleCache);
  5343. }
  5344. },
  5345. _layoutText: function _layoutText(textDiv) {
  5346. var textLayerFrag = this._container;
  5347. var textDivProperties = this._textDivProperties.get(textDiv);
  5348. if (textDivProperties.isWhitespace) {
  5349. return;
  5350. }
  5351. var fontSize = textDiv.style.fontSize;
  5352. var fontFamily = textDiv.style.fontFamily;
  5353. if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
  5354. this._layoutTextCtx.font = fontSize + ' ' + fontFamily;
  5355. this._lastFontSize = fontSize;
  5356. this._lastFontFamily = fontFamily;
  5357. }
  5358. var width = this._layoutTextCtx.measureText(textDiv.textContent).width;
  5359. var transform = '';
  5360. if (textDivProperties.canvasWidth !== 0 && width > 0) {
  5361. textDivProperties.scale = textDivProperties.canvasWidth / width;
  5362. transform = 'scaleX(' + textDivProperties.scale + ')';
  5363. }
  5364. if (textDivProperties.angle !== 0) {
  5365. transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform;
  5366. }
  5367. if (transform !== '') {
  5368. textDivProperties.originalTransform = transform;
  5369. _dom_utils.CustomStyle.setProp('transform', textDiv, transform);
  5370. }
  5371. this._textDivProperties.set(textDiv, textDivProperties);
  5372. textLayerFrag.appendChild(textDiv);
  5373. },
  5374. _render: function TextLayer_render(timeout) {
  5375. var _this = this;
  5376. var capability = (0, _util.createPromiseCapability)();
  5377. var styleCache = Object.create(null);
  5378. var canvas = document.createElement('canvas');
  5379. canvas.mozOpaque = true;
  5380. this._layoutTextCtx = canvas.getContext('2d', { alpha: false });
  5381. if (this._textContent) {
  5382. var textItems = this._textContent.items;
  5383. var textStyles = this._textContent.styles;
  5384. this._processItems(textItems, textStyles);
  5385. capability.resolve();
  5386. } else if (this._textContentStream) {
  5387. var pump = function pump() {
  5388. _this._reader.read().then(function (_ref2) {
  5389. var value = _ref2.value,
  5390. done = _ref2.done;
  5391. if (done) {
  5392. capability.resolve();
  5393. return;
  5394. }
  5395. _util.Util.extendObj(styleCache, value.styles);
  5396. _this._processItems(value.items, styleCache);
  5397. pump();
  5398. }, capability.reject);
  5399. };
  5400. this._reader = this._textContentStream.getReader();
  5401. pump();
  5402. } else {
  5403. throw new Error('Neither "textContent" nor "textContentStream"' + ' parameters specified.');
  5404. }
  5405. capability.promise.then(function () {
  5406. styleCache = null;
  5407. if (!timeout) {
  5408. render(_this);
  5409. } else {
  5410. _this._renderTimer = setTimeout(function () {
  5411. render(_this);
  5412. _this._renderTimer = null;
  5413. }, timeout);
  5414. }
  5415. }, this._capability.reject);
  5416. },
  5417. expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
  5418. if (!this._enhanceTextSelection || !this._renderingDone) {
  5419. return;
  5420. }
  5421. if (this._bounds !== null) {
  5422. expand(this);
  5423. this._bounds = null;
  5424. }
  5425. for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
  5426. var div = this._textDivs[i];
  5427. var divProperties = this._textDivProperties.get(div);
  5428. if (divProperties.isWhitespace) {
  5429. continue;
  5430. }
  5431. if (expandDivs) {
  5432. var transform = '',
  5433. padding = '';
  5434. if (divProperties.scale !== 1) {
  5435. transform = 'scaleX(' + divProperties.scale + ')';
  5436. }
  5437. if (divProperties.angle !== 0) {
  5438. transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
  5439. }
  5440. if (divProperties.paddingLeft !== 0) {
  5441. padding += ' padding-left: ' + divProperties.paddingLeft / divProperties.scale + 'px;';
  5442. transform += ' translateX(' + -divProperties.paddingLeft / divProperties.scale + 'px)';
  5443. }
  5444. if (divProperties.paddingTop !== 0) {
  5445. padding += ' padding-top: ' + divProperties.paddingTop + 'px;';
  5446. transform += ' translateY(' + -divProperties.paddingTop + 'px)';
  5447. }
  5448. if (divProperties.paddingRight !== 0) {
  5449. padding += ' padding-right: ' + divProperties.paddingRight / divProperties.scale + 'px;';
  5450. }
  5451. if (divProperties.paddingBottom !== 0) {
  5452. padding += ' padding-bottom: ' + divProperties.paddingBottom + 'px;';
  5453. }
  5454. if (padding !== '') {
  5455. div.setAttribute('style', divProperties.style + padding);
  5456. }
  5457. if (transform !== '') {
  5458. _dom_utils.CustomStyle.setProp('transform', div, transform);
  5459. }
  5460. } else {
  5461. div.style.padding = 0;
  5462. _dom_utils.CustomStyle.setProp('transform', div, divProperties.originalTransform || '');
  5463. }
  5464. }
  5465. }
  5466. };
  5467. function renderTextLayer(renderParameters) {
  5468. var task = new TextLayerRenderTask({
  5469. textContent: renderParameters.textContent,
  5470. textContentStream: renderParameters.textContentStream,
  5471. container: renderParameters.container,
  5472. viewport: renderParameters.viewport,
  5473. textDivs: renderParameters.textDivs,
  5474. textContentItemsStr: renderParameters.textContentItemsStr,
  5475. enhanceTextSelection: renderParameters.enhanceTextSelection
  5476. });
  5477. task._render(renderParameters.timeout);
  5478. return task;
  5479. }
  5480. return renderTextLayer;
  5481. }();
  5482. exports.renderTextLayer = renderTextLayer;
  5483. /***/ }),
  5484. /* 6 */
  5485. /***/ (function(module, exports, __w_pdfjs_require__) {
  5486. "use strict";
  5487. Object.defineProperty(exports, "__esModule", {
  5488. value: true
  5489. });
  5490. function fixMetadata(meta) {
  5491. return meta.replace(/>\\376\\377([^<]+)/g, function (all, codes) {
  5492. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
  5493. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  5494. });
  5495. var chars = '';
  5496. for (var i = 0; i < bytes.length; i += 2) {
  5497. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  5498. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38 ? String.fromCharCode(code) : '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  5499. }
  5500. return '>' + chars;
  5501. });
  5502. }
  5503. function Metadata(meta) {
  5504. if (typeof meta === 'string') {
  5505. meta = fixMetadata(meta);
  5506. var parser = new DOMParser();
  5507. meta = parser.parseFromString(meta, 'application/xml');
  5508. } else if (!(meta instanceof Document)) {
  5509. throw new Error('Metadata: Invalid metadata object');
  5510. }
  5511. this.metaDocument = meta;
  5512. this.metadata = Object.create(null);
  5513. this.parse();
  5514. }
  5515. Metadata.prototype = {
  5516. parse: function Metadata_parse() {
  5517. var doc = this.metaDocument;
  5518. var rdf = doc.documentElement;
  5519. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  5520. rdf = rdf.firstChild;
  5521. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  5522. rdf = rdf.nextSibling;
  5523. }
  5524. }
  5525. var nodeName = rdf ? rdf.nodeName.toLowerCase() : null;
  5526. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  5527. return;
  5528. }
  5529. var children = rdf.childNodes,
  5530. desc,
  5531. entry,
  5532. name,
  5533. i,
  5534. ii,
  5535. length,
  5536. iLength;
  5537. for (i = 0, length = children.length; i < length; i++) {
  5538. desc = children[i];
  5539. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  5540. continue;
  5541. }
  5542. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  5543. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  5544. entry = desc.childNodes[ii];
  5545. name = entry.nodeName.toLowerCase();
  5546. this.metadata[name] = entry.textContent.trim();
  5547. }
  5548. }
  5549. }
  5550. },
  5551. get: function Metadata_get(name) {
  5552. return this.metadata[name] || null;
  5553. },
  5554. has: function Metadata_has(name) {
  5555. return typeof this.metadata[name] !== 'undefined';
  5556. }
  5557. };
  5558. exports.Metadata = Metadata;
  5559. /***/ }),
  5560. /* 7 */
  5561. /***/ (function(module, exports, __w_pdfjs_require__) {
  5562. "use strict";
  5563. Object.defineProperty(exports, "__esModule", {
  5564. value: true
  5565. });
  5566. exports.WebGLUtils = undefined;
  5567. var _dom_utils = __w_pdfjs_require__(1);
  5568. var _util = __w_pdfjs_require__(0);
  5569. var WebGLUtils = function WebGLUtilsClosure() {
  5570. function loadShader(gl, code, shaderType) {
  5571. var shader = gl.createShader(shaderType);
  5572. gl.shaderSource(shader, code);
  5573. gl.compileShader(shader);
  5574. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  5575. if (!compiled) {
  5576. var errorMsg = gl.getShaderInfoLog(shader);
  5577. throw new Error('Error during shader compilation: ' + errorMsg);
  5578. }
  5579. return shader;
  5580. }
  5581. function createVertexShader(gl, code) {
  5582. return loadShader(gl, code, gl.VERTEX_SHADER);
  5583. }
  5584. function createFragmentShader(gl, code) {
  5585. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  5586. }
  5587. function createProgram(gl, shaders) {
  5588. var program = gl.createProgram();
  5589. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  5590. gl.attachShader(program, shaders[i]);
  5591. }
  5592. gl.linkProgram(program);
  5593. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  5594. if (!linked) {
  5595. var errorMsg = gl.getProgramInfoLog(program);
  5596. throw new Error('Error during program linking: ' + errorMsg);
  5597. }
  5598. return program;
  5599. }
  5600. function createTexture(gl, image, textureId) {
  5601. gl.activeTexture(textureId);
  5602. var texture = gl.createTexture();
  5603. gl.bindTexture(gl.TEXTURE_2D, texture);
  5604. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  5605. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  5606. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  5607. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  5608. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  5609. return texture;
  5610. }
  5611. var currentGL, currentCanvas;
  5612. function generateGL() {
  5613. if (currentGL) {
  5614. return;
  5615. }
  5616. currentCanvas = document.createElement('canvas');
  5617. currentGL = currentCanvas.getContext('webgl', { premultipliedalpha: false });
  5618. }
  5619. var smaskVertexShaderCode = '\
  5620. attribute vec2 a_position; \
  5621. attribute vec2 a_texCoord; \
  5622. \
  5623. uniform vec2 u_resolution; \
  5624. \
  5625. varying vec2 v_texCoord; \
  5626. \
  5627. void main() { \
  5628. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  5629. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  5630. \
  5631. v_texCoord = a_texCoord; \
  5632. } ';
  5633. var smaskFragmentShaderCode = '\
  5634. precision mediump float; \
  5635. \
  5636. uniform vec4 u_backdrop; \
  5637. uniform int u_subtype; \
  5638. uniform sampler2D u_image; \
  5639. uniform sampler2D u_mask; \
  5640. \
  5641. varying vec2 v_texCoord; \
  5642. \
  5643. void main() { \
  5644. vec4 imageColor = texture2D(u_image, v_texCoord); \
  5645. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  5646. if (u_backdrop.a > 0.0) { \
  5647. maskColor.rgb = maskColor.rgb * maskColor.a + \
  5648. u_backdrop.rgb * (1.0 - maskColor.a); \
  5649. } \
  5650. float lum; \
  5651. if (u_subtype == 0) { \
  5652. lum = maskColor.a; \
  5653. } else { \
  5654. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  5655. maskColor.b * 0.11; \
  5656. } \
  5657. imageColor.a *= lum; \
  5658. imageColor.rgb *= imageColor.a; \
  5659. gl_FragColor = imageColor; \
  5660. } ';
  5661. var smaskCache = null;
  5662. function initSmaskGL() {
  5663. var canvas, gl;
  5664. generateGL();
  5665. canvas = currentCanvas;
  5666. currentCanvas = null;
  5667. gl = currentGL;
  5668. currentGL = null;
  5669. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  5670. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  5671. var program = createProgram(gl, [vertexShader, fragmentShader]);
  5672. gl.useProgram(program);
  5673. var cache = {};
  5674. cache.gl = gl;
  5675. cache.canvas = canvas;
  5676. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  5677. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  5678. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  5679. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  5680. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  5681. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  5682. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  5683. var texCoordBuffer = gl.createBuffer();
  5684. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  5685. 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);
  5686. gl.enableVertexAttribArray(texCoordLocation);
  5687. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  5688. gl.uniform1i(texLayerLocation, 0);
  5689. gl.uniform1i(texMaskLocation, 1);
  5690. smaskCache = cache;
  5691. }
  5692. function composeSMask(layer, mask, properties) {
  5693. var width = layer.width,
  5694. height = layer.height;
  5695. if (!smaskCache) {
  5696. initSmaskGL();
  5697. }
  5698. var cache = smaskCache,
  5699. canvas = cache.canvas,
  5700. gl = cache.gl;
  5701. canvas.width = width;
  5702. canvas.height = height;
  5703. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  5704. gl.uniform2f(cache.resolutionLocation, width, height);
  5705. if (properties.backdrop) {
  5706. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0], properties.backdrop[1], properties.backdrop[2], 1);
  5707. } else {
  5708. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  5709. }
  5710. gl.uniform1i(cache.subtypeLocation, properties.subtype === 'Luminosity' ? 1 : 0);
  5711. var texture = createTexture(gl, layer, gl.TEXTURE0);
  5712. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  5713. var buffer = gl.createBuffer();
  5714. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  5715. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, width, 0, 0, height, 0, height, width, 0, width, height]), gl.STATIC_DRAW);
  5716. gl.enableVertexAttribArray(cache.positionLocation);
  5717. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  5718. gl.clearColor(0, 0, 0, 0);
  5719. gl.enable(gl.BLEND);
  5720. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  5721. gl.clear(gl.COLOR_BUFFER_BIT);
  5722. gl.drawArrays(gl.TRIANGLES, 0, 6);
  5723. gl.flush();
  5724. gl.deleteTexture(texture);
  5725. gl.deleteTexture(maskTexture);
  5726. gl.deleteBuffer(buffer);
  5727. return canvas;
  5728. }
  5729. var figuresVertexShaderCode = '\
  5730. attribute vec2 a_position; \
  5731. attribute vec3 a_color; \
  5732. \
  5733. uniform vec2 u_resolution; \
  5734. uniform vec2 u_scale; \
  5735. uniform vec2 u_offset; \
  5736. \
  5737. varying vec4 v_color; \
  5738. \
  5739. void main() { \
  5740. vec2 position = (a_position + u_offset) * u_scale; \
  5741. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  5742. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  5743. \
  5744. v_color = vec4(a_color / 255.0, 1.0); \
  5745. } ';
  5746. var figuresFragmentShaderCode = '\
  5747. precision mediump float; \
  5748. \
  5749. varying vec4 v_color; \
  5750. \
  5751. void main() { \
  5752. gl_FragColor = v_color; \
  5753. } ';
  5754. var figuresCache = null;
  5755. function initFiguresGL() {
  5756. var canvas, gl;
  5757. generateGL();
  5758. canvas = currentCanvas;
  5759. currentCanvas = null;
  5760. gl = currentGL;
  5761. currentGL = null;
  5762. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  5763. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  5764. var program = createProgram(gl, [vertexShader, fragmentShader]);
  5765. gl.useProgram(program);
  5766. var cache = {};
  5767. cache.gl = gl;
  5768. cache.canvas = canvas;
  5769. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  5770. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  5771. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  5772. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  5773. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  5774. figuresCache = cache;
  5775. }
  5776. function drawFigures(width, height, backgroundColor, figures, context) {
  5777. if (!figuresCache) {
  5778. initFiguresGL();
  5779. }
  5780. var cache = figuresCache,
  5781. canvas = cache.canvas,
  5782. gl = cache.gl;
  5783. canvas.width = width;
  5784. canvas.height = height;
  5785. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  5786. gl.uniform2f(cache.resolutionLocation, width, height);
  5787. var count = 0;
  5788. var i, ii, rows;
  5789. for (i = 0, ii = figures.length; i < ii; i++) {
  5790. switch (figures[i].type) {
  5791. case 'lattice':
  5792. rows = figures[i].coords.length / figures[i].verticesPerRow | 0;
  5793. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  5794. break;
  5795. case 'triangles':
  5796. count += figures[i].coords.length;
  5797. break;
  5798. }
  5799. }
  5800. var coords = new Float32Array(count * 2);
  5801. var colors = new Uint8Array(count * 3);
  5802. var coordsMap = context.coords,
  5803. colorsMap = context.colors;
  5804. var pIndex = 0,
  5805. cIndex = 0;
  5806. for (i = 0, ii = figures.length; i < ii; i++) {
  5807. var figure = figures[i],
  5808. ps = figure.coords,
  5809. cs = figure.colors;
  5810. switch (figure.type) {
  5811. case 'lattice':
  5812. var cols = figure.verticesPerRow;
  5813. rows = ps.length / cols | 0;
  5814. for (var row = 1; row < rows; row++) {
  5815. var offset = row * cols + 1;
  5816. for (var col = 1; col < cols; col++, offset++) {
  5817. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  5818. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  5819. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  5820. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  5821. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  5822. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  5823. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  5824. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  5825. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  5826. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  5827. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  5828. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  5829. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  5830. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  5831. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  5832. coords[pIndex + 6] = coords[pIndex + 2];
  5833. coords[pIndex + 7] = coords[pIndex + 3];
  5834. coords[pIndex + 8] = coords[pIndex + 4];
  5835. coords[pIndex + 9] = coords[pIndex + 5];
  5836. coords[pIndex + 10] = coordsMap[ps[offset]];
  5837. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  5838. colors[cIndex + 9] = colors[cIndex + 3];
  5839. colors[cIndex + 10] = colors[cIndex + 4];
  5840. colors[cIndex + 11] = colors[cIndex + 5];
  5841. colors[cIndex + 12] = colors[cIndex + 6];
  5842. colors[cIndex + 13] = colors[cIndex + 7];
  5843. colors[cIndex + 14] = colors[cIndex + 8];
  5844. colors[cIndex + 15] = colorsMap[cs[offset]];
  5845. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  5846. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  5847. pIndex += 12;
  5848. cIndex += 18;
  5849. }
  5850. }
  5851. break;
  5852. case 'triangles':
  5853. for (var j = 0, jj = ps.length; j < jj; j++) {
  5854. coords[pIndex] = coordsMap[ps[j]];
  5855. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  5856. colors[cIndex] = colorsMap[cs[j]];
  5857. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  5858. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  5859. pIndex += 2;
  5860. cIndex += 3;
  5861. }
  5862. break;
  5863. }
  5864. }
  5865. if (backgroundColor) {
  5866. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255, backgroundColor[2] / 255, 1.0);
  5867. } else {
  5868. gl.clearColor(0, 0, 0, 0);
  5869. }
  5870. gl.clear(gl.COLOR_BUFFER_BIT);
  5871. var coordsBuffer = gl.createBuffer();
  5872. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  5873. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  5874. gl.enableVertexAttribArray(cache.positionLocation);
  5875. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  5876. var colorsBuffer = gl.createBuffer();
  5877. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  5878. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  5879. gl.enableVertexAttribArray(cache.colorLocation);
  5880. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false, 0, 0);
  5881. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  5882. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  5883. gl.drawArrays(gl.TRIANGLES, 0, count);
  5884. gl.flush();
  5885. gl.deleteBuffer(coordsBuffer);
  5886. gl.deleteBuffer(colorsBuffer);
  5887. return canvas;
  5888. }
  5889. function cleanup() {
  5890. if (smaskCache && smaskCache.canvas) {
  5891. smaskCache.canvas.width = 0;
  5892. smaskCache.canvas.height = 0;
  5893. }
  5894. if (figuresCache && figuresCache.canvas) {
  5895. figuresCache.canvas.width = 0;
  5896. figuresCache.canvas.height = 0;
  5897. }
  5898. smaskCache = null;
  5899. figuresCache = null;
  5900. }
  5901. return {
  5902. get isEnabled() {
  5903. if ((0, _dom_utils.getDefaultSetting)('disableWebGL')) {
  5904. return false;
  5905. }
  5906. var enabled = false;
  5907. try {
  5908. generateGL();
  5909. enabled = !!currentGL;
  5910. } catch (e) {}
  5911. return (0, _util.shadow)(this, 'isEnabled', enabled);
  5912. },
  5913. composeSMask: composeSMask,
  5914. drawFigures: drawFigures,
  5915. clear: cleanup
  5916. };
  5917. }();
  5918. exports.WebGLUtils = WebGLUtils;
  5919. /***/ }),
  5920. /* 8 */
  5921. /***/ (function(module, exports, __w_pdfjs_require__) {
  5922. "use strict";
  5923. Object.defineProperty(exports, "__esModule", {
  5924. value: true
  5925. });
  5926. exports.PDFJS = exports.isWorker = exports.globalScope = undefined;
  5927. var _api = __w_pdfjs_require__(2);
  5928. var _dom_utils = __w_pdfjs_require__(1);
  5929. var _util = __w_pdfjs_require__(0);
  5930. var _annotation_layer = __w_pdfjs_require__(3);
  5931. var _metadata = __w_pdfjs_require__(6);
  5932. var _text_layer = __w_pdfjs_require__(5);
  5933. var _svg = __w_pdfjs_require__(4);
  5934. var isWorker = typeof window === 'undefined';
  5935. if (!_util.globalScope.PDFJS) {
  5936. _util.globalScope.PDFJS = {};
  5937. }
  5938. var PDFJS = _util.globalScope.PDFJS;
  5939. {
  5940. PDFJS.version = '1.9.426';
  5941. PDFJS.build = '2558a58d';
  5942. }
  5943. PDFJS.pdfBug = false;
  5944. if (PDFJS.verbosity !== undefined) {
  5945. (0, _util.setVerbosityLevel)(PDFJS.verbosity);
  5946. }
  5947. delete PDFJS.verbosity;
  5948. Object.defineProperty(PDFJS, 'verbosity', {
  5949. get: function get() {
  5950. return (0, _util.getVerbosityLevel)();
  5951. },
  5952. set: function set(level) {
  5953. (0, _util.setVerbosityLevel)(level);
  5954. },
  5955. enumerable: true,
  5956. configurable: true
  5957. });
  5958. PDFJS.VERBOSITY_LEVELS = _util.VERBOSITY_LEVELS;
  5959. PDFJS.OPS = _util.OPS;
  5960. PDFJS.UNSUPPORTED_FEATURES = _util.UNSUPPORTED_FEATURES;
  5961. PDFJS.isValidUrl = _dom_utils.isValidUrl;
  5962. PDFJS.shadow = _util.shadow;
  5963. PDFJS.createBlob = _util.createBlob;
  5964. PDFJS.createObjectURL = function PDFJS_createObjectURL(data, contentType) {
  5965. return (0, _util.createObjectURL)(data, contentType, PDFJS.disableCreateObjectURL);
  5966. };
  5967. Object.defineProperty(PDFJS, 'isLittleEndian', {
  5968. configurable: true,
  5969. get: function PDFJS_isLittleEndian() {
  5970. return (0, _util.shadow)(PDFJS, 'isLittleEndian', (0, _util.isLittleEndian)());
  5971. }
  5972. });
  5973. PDFJS.removeNullCharacters = _util.removeNullCharacters;
  5974. PDFJS.PasswordResponses = _util.PasswordResponses;
  5975. PDFJS.PasswordException = _util.PasswordException;
  5976. PDFJS.UnknownErrorException = _util.UnknownErrorException;
  5977. PDFJS.InvalidPDFException = _util.InvalidPDFException;
  5978. PDFJS.MissingPDFException = _util.MissingPDFException;
  5979. PDFJS.UnexpectedResponseException = _util.UnexpectedResponseException;
  5980. PDFJS.Util = _util.Util;
  5981. PDFJS.PageViewport = _util.PageViewport;
  5982. PDFJS.createPromiseCapability = _util.createPromiseCapability;
  5983. PDFJS.maxImageSize = PDFJS.maxImageSize === undefined ? -1 : PDFJS.maxImageSize;
  5984. PDFJS.cMapUrl = PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl;
  5985. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  5986. PDFJS.disableFontFace = PDFJS.disableFontFace === undefined ? false : PDFJS.disableFontFace;
  5987. PDFJS.imageResourcesPath = PDFJS.imageResourcesPath === undefined ? '' : PDFJS.imageResourcesPath;
  5988. PDFJS.disableWorker = PDFJS.disableWorker === undefined ? false : PDFJS.disableWorker;
  5989. PDFJS.workerSrc = PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc;
  5990. PDFJS.workerPort = PDFJS.workerPort === undefined ? null : PDFJS.workerPort;
  5991. PDFJS.disableRange = PDFJS.disableRange === undefined ? false : PDFJS.disableRange;
  5992. PDFJS.disableStream = PDFJS.disableStream === undefined ? false : PDFJS.disableStream;
  5993. PDFJS.disableAutoFetch = PDFJS.disableAutoFetch === undefined ? false : PDFJS.disableAutoFetch;
  5994. PDFJS.pdfBug = PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug;
  5995. PDFJS.postMessageTransfers = PDFJS.postMessageTransfers === undefined ? true : PDFJS.postMessageTransfers;
  5996. PDFJS.disableCreateObjectURL = PDFJS.disableCreateObjectURL === undefined ? false : PDFJS.disableCreateObjectURL;
  5997. PDFJS.disableWebGL = PDFJS.disableWebGL === undefined ? true : PDFJS.disableWebGL;
  5998. PDFJS.externalLinkTarget = PDFJS.externalLinkTarget === undefined ? _dom_utils.LinkTarget.NONE : PDFJS.externalLinkTarget;
  5999. PDFJS.externalLinkRel = PDFJS.externalLinkRel === undefined ? _dom_utils.DEFAULT_LINK_REL : PDFJS.externalLinkRel;
  6000. PDFJS.isEvalSupported = PDFJS.isEvalSupported === undefined ? true : PDFJS.isEvalSupported;
  6001. PDFJS.pdfjsNext = PDFJS.pdfjsNext === undefined ? false : PDFJS.pdfjsNext;
  6002. {
  6003. var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow;
  6004. delete PDFJS.openExternalLinksInNewWindow;
  6005. Object.defineProperty(PDFJS, 'openExternalLinksInNewWindow', {
  6006. get: function get() {
  6007. return PDFJS.externalLinkTarget === _dom_utils.LinkTarget.BLANK;
  6008. },
  6009. set: function set(value) {
  6010. if (value) {
  6011. (0, _util.deprecated)('PDFJS.openExternalLinksInNewWindow, please use ' + '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  6012. }
  6013. if (PDFJS.externalLinkTarget !== _dom_utils.LinkTarget.NONE) {
  6014. (0, _util.warn)('PDFJS.externalLinkTarget is already initialized');
  6015. return;
  6016. }
  6017. PDFJS.externalLinkTarget = value ? _dom_utils.LinkTarget.BLANK : _dom_utils.LinkTarget.NONE;
  6018. },
  6019. enumerable: true,
  6020. configurable: true
  6021. });
  6022. if (savedOpenExternalLinksInNewWindow) {
  6023. PDFJS.openExternalLinksInNewWindow = savedOpenExternalLinksInNewWindow;
  6024. }
  6025. }
  6026. PDFJS.getDocument = _api.getDocument;
  6027. PDFJS.LoopbackPort = _api.LoopbackPort;
  6028. PDFJS.PDFDataRangeTransport = _api.PDFDataRangeTransport;
  6029. PDFJS.PDFWorker = _api.PDFWorker;
  6030. PDFJS.hasCanvasTypedArrays = true;
  6031. PDFJS.CustomStyle = _dom_utils.CustomStyle;
  6032. PDFJS.LinkTarget = _dom_utils.LinkTarget;
  6033. PDFJS.addLinkAttributes = _dom_utils.addLinkAttributes;
  6034. PDFJS.getFilenameFromUrl = _dom_utils.getFilenameFromUrl;
  6035. PDFJS.isExternalLinkTargetSet = _dom_utils.isExternalLinkTargetSet;
  6036. PDFJS.AnnotationLayer = _annotation_layer.AnnotationLayer;
  6037. PDFJS.renderTextLayer = _text_layer.renderTextLayer;
  6038. PDFJS.Metadata = _metadata.Metadata;
  6039. PDFJS.SVGGraphics = _svg.SVGGraphics;
  6040. PDFJS.UnsupportedManager = _api._UnsupportedManager;
  6041. exports.globalScope = _util.globalScope;
  6042. exports.isWorker = isWorker;
  6043. exports.PDFJS = PDFJS;
  6044. /***/ }),
  6045. /* 9 */
  6046. /***/ (function(module, exports, __w_pdfjs_require__) {
  6047. "use strict";
  6048. Object.defineProperty(exports, "__esModule", {
  6049. value: true
  6050. });
  6051. exports.NetworkManager = exports.PDFNetworkStream = undefined;
  6052. var _util = __w_pdfjs_require__(0);
  6053. var _api = __w_pdfjs_require__(2);
  6054. ;
  6055. var OK_RESPONSE = 200;
  6056. var PARTIAL_CONTENT_RESPONSE = 206;
  6057. function NetworkManager(url, args) {
  6058. this.url = url;
  6059. args = args || {};
  6060. this.isHttp = /^https?:/i.test(url);
  6061. this.httpHeaders = this.isHttp && args.httpHeaders || {};
  6062. this.withCredentials = args.withCredentials || false;
  6063. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  6064. return new XMLHttpRequest();
  6065. };
  6066. this.currXhrId = 0;
  6067. this.pendingRequests = Object.create(null);
  6068. this.loadedRequests = Object.create(null);
  6069. }
  6070. function getArrayBuffer(xhr) {
  6071. var data = xhr.response;
  6072. if (typeof data !== 'string') {
  6073. return data;
  6074. }
  6075. var length = data.length;
  6076. var array = new Uint8Array(length);
  6077. for (var i = 0; i < length; i++) {
  6078. array[i] = data.charCodeAt(i) & 0xFF;
  6079. }
  6080. return array.buffer;
  6081. }
  6082. var supportsMozChunked = function supportsMozChunkedClosure() {
  6083. try {
  6084. var x = new XMLHttpRequest();
  6085. x.open('GET', _util.globalScope.location.href);
  6086. x.responseType = 'moz-chunked-arraybuffer';
  6087. return x.responseType === 'moz-chunked-arraybuffer';
  6088. } catch (e) {
  6089. return false;
  6090. }
  6091. }();
  6092. NetworkManager.prototype = {
  6093. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  6094. var args = {
  6095. begin: begin,
  6096. end: end
  6097. };
  6098. for (var prop in listeners) {
  6099. args[prop] = listeners[prop];
  6100. }
  6101. return this.request(args);
  6102. },
  6103. requestFull: function NetworkManager_requestFull(listeners) {
  6104. return this.request(listeners);
  6105. },
  6106. request: function NetworkManager_request(args) {
  6107. var xhr = this.getXhr();
  6108. var xhrId = this.currXhrId++;
  6109. var pendingRequest = this.pendingRequests[xhrId] = { xhr: xhr };
  6110. xhr.open('GET', this.url);
  6111. xhr.withCredentials = this.withCredentials;
  6112. for (var property in this.httpHeaders) {
  6113. var value = this.httpHeaders[property];
  6114. if (typeof value === 'undefined') {
  6115. continue;
  6116. }
  6117. xhr.setRequestHeader(property, value);
  6118. }
  6119. if (this.isHttp && 'begin' in args && 'end' in args) {
  6120. var rangeStr = args.begin + '-' + (args.end - 1);
  6121. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  6122. pendingRequest.expectedStatus = 206;
  6123. } else {
  6124. pendingRequest.expectedStatus = 200;
  6125. }
  6126. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  6127. if (useMozChunkedLoading) {
  6128. xhr.responseType = 'moz-chunked-arraybuffer';
  6129. pendingRequest.onProgressiveData = args.onProgressiveData;
  6130. pendingRequest.mozChunked = true;
  6131. } else {
  6132. xhr.responseType = 'arraybuffer';
  6133. }
  6134. if (args.onError) {
  6135. xhr.onerror = function (evt) {
  6136. args.onError(xhr.status);
  6137. };
  6138. }
  6139. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  6140. xhr.onprogress = this.onProgress.bind(this, xhrId);
  6141. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  6142. pendingRequest.onDone = args.onDone;
  6143. pendingRequest.onError = args.onError;
  6144. pendingRequest.onProgress = args.onProgress;
  6145. xhr.send(null);
  6146. return xhrId;
  6147. },
  6148. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  6149. var pendingRequest = this.pendingRequests[xhrId];
  6150. if (!pendingRequest) {
  6151. return;
  6152. }
  6153. if (pendingRequest.mozChunked) {
  6154. var chunk = getArrayBuffer(pendingRequest.xhr);
  6155. pendingRequest.onProgressiveData(chunk);
  6156. }
  6157. var onProgress = pendingRequest.onProgress;
  6158. if (onProgress) {
  6159. onProgress(evt);
  6160. }
  6161. },
  6162. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  6163. var pendingRequest = this.pendingRequests[xhrId];
  6164. if (!pendingRequest) {
  6165. return;
  6166. }
  6167. var xhr = pendingRequest.xhr;
  6168. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  6169. pendingRequest.onHeadersReceived();
  6170. delete pendingRequest.onHeadersReceived;
  6171. }
  6172. if (xhr.readyState !== 4) {
  6173. return;
  6174. }
  6175. if (!(xhrId in this.pendingRequests)) {
  6176. return;
  6177. }
  6178. delete this.pendingRequests[xhrId];
  6179. if (xhr.status === 0 && this.isHttp) {
  6180. if (pendingRequest.onError) {
  6181. pendingRequest.onError(xhr.status);
  6182. }
  6183. return;
  6184. }
  6185. var xhrStatus = xhr.status || OK_RESPONSE;
  6186. var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  6187. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  6188. if (pendingRequest.onError) {
  6189. pendingRequest.onError(xhr.status);
  6190. }
  6191. return;
  6192. }
  6193. this.loadedRequests[xhrId] = true;
  6194. var chunk = getArrayBuffer(xhr);
  6195. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  6196. var rangeHeader = xhr.getResponseHeader('Content-Range');
  6197. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  6198. var begin = parseInt(matches[1], 10);
  6199. pendingRequest.onDone({
  6200. begin: begin,
  6201. chunk: chunk
  6202. });
  6203. } else if (pendingRequest.onProgressiveData) {
  6204. pendingRequest.onDone(null);
  6205. } else if (chunk) {
  6206. pendingRequest.onDone({
  6207. begin: 0,
  6208. chunk: chunk
  6209. });
  6210. } else if (pendingRequest.onError) {
  6211. pendingRequest.onError(xhr.status);
  6212. }
  6213. },
  6214. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  6215. for (var xhrId in this.pendingRequests) {
  6216. return true;
  6217. }
  6218. return false;
  6219. },
  6220. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  6221. return this.pendingRequests[xhrId].xhr;
  6222. },
  6223. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  6224. return !!this.pendingRequests[xhrId].onProgressiveData;
  6225. },
  6226. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  6227. return xhrId in this.pendingRequests;
  6228. },
  6229. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  6230. return xhrId in this.loadedRequests;
  6231. },
  6232. abortAllRequests: function NetworkManager_abortAllRequests() {
  6233. for (var xhrId in this.pendingRequests) {
  6234. this.abortRequest(xhrId | 0);
  6235. }
  6236. },
  6237. abortRequest: function NetworkManager_abortRequest(xhrId) {
  6238. var xhr = this.pendingRequests[xhrId].xhr;
  6239. delete this.pendingRequests[xhrId];
  6240. xhr.abort();
  6241. }
  6242. };
  6243. function PDFNetworkStream(options) {
  6244. this._options = options;
  6245. var source = options.source;
  6246. this._manager = new NetworkManager(source.url, {
  6247. httpHeaders: source.httpHeaders,
  6248. withCredentials: source.withCredentials
  6249. });
  6250. this._rangeChunkSize = source.rangeChunkSize;
  6251. this._fullRequestReader = null;
  6252. this._rangeRequestReaders = [];
  6253. }
  6254. PDFNetworkStream.prototype = {
  6255. _onRangeRequestReaderClosed: function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  6256. var i = this._rangeRequestReaders.indexOf(reader);
  6257. if (i >= 0) {
  6258. this._rangeRequestReaders.splice(i, 1);
  6259. }
  6260. },
  6261. getFullReader: function PDFNetworkStream_getFullReader() {
  6262. (0, _util.assert)(!this._fullRequestReader);
  6263. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  6264. return this._fullRequestReader;
  6265. },
  6266. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  6267. var reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  6268. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  6269. this._rangeRequestReaders.push(reader);
  6270. return reader;
  6271. },
  6272. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  6273. if (this._fullRequestReader) {
  6274. this._fullRequestReader.cancel(reason);
  6275. }
  6276. var readers = this._rangeRequestReaders.slice(0);
  6277. readers.forEach(function (reader) {
  6278. reader.cancel(reason);
  6279. });
  6280. }
  6281. };
  6282. function PDFNetworkStreamFullRequestReader(manager, options) {
  6283. this._manager = manager;
  6284. var source = options.source;
  6285. var args = {
  6286. onHeadersReceived: this._onHeadersReceived.bind(this),
  6287. onProgressiveData: source.disableStream ? null : this._onProgressiveData.bind(this),
  6288. onDone: this._onDone.bind(this),
  6289. onError: this._onError.bind(this),
  6290. onProgress: this._onProgress.bind(this)
  6291. };
  6292. this._url = source.url;
  6293. this._fullRequestId = manager.requestFull(args);
  6294. this._headersReceivedCapability = (0, _util.createPromiseCapability)();
  6295. this._disableRange = options.disableRange || false;
  6296. this._contentLength = source.length;
  6297. this._rangeChunkSize = source.rangeChunkSize;
  6298. if (!this._rangeChunkSize && !this._disableRange) {
  6299. this._disableRange = true;
  6300. }
  6301. this._isStreamingSupported = false;
  6302. this._isRangeSupported = false;
  6303. this._cachedChunks = [];
  6304. this._requests = [];
  6305. this._done = false;
  6306. this._storedError = undefined;
  6307. this.onProgress = null;
  6308. }
  6309. PDFNetworkStreamFullRequestReader.prototype = {
  6310. _validateRangeRequestCapabilities: function PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  6311. if (this._disableRange) {
  6312. return false;
  6313. }
  6314. var networkManager = this._manager;
  6315. if (!networkManager.isHttp) {
  6316. return false;
  6317. }
  6318. var fullRequestXhrId = this._fullRequestId;
  6319. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  6320. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  6321. return false;
  6322. }
  6323. var contentEncoding = fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  6324. if (contentEncoding !== 'identity') {
  6325. return false;
  6326. }
  6327. var length = fullRequestXhr.getResponseHeader('Content-Length');
  6328. length = parseInt(length, 10);
  6329. if (!(0, _util.isInt)(length)) {
  6330. return false;
  6331. }
  6332. this._contentLength = length;
  6333. if (length <= 2 * this._rangeChunkSize) {
  6334. return false;
  6335. }
  6336. return true;
  6337. },
  6338. _onHeadersReceived: function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  6339. if (this._validateRangeRequestCapabilities()) {
  6340. this._isRangeSupported = true;
  6341. }
  6342. var networkManager = this._manager;
  6343. var fullRequestXhrId = this._fullRequestId;
  6344. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  6345. this._isStreamingSupported = true;
  6346. } else if (this._isRangeSupported) {
  6347. networkManager.abortRequest(fullRequestXhrId);
  6348. }
  6349. this._headersReceivedCapability.resolve();
  6350. },
  6351. _onProgressiveData: function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  6352. if (this._requests.length > 0) {
  6353. var requestCapability = this._requests.shift();
  6354. requestCapability.resolve({
  6355. value: chunk,
  6356. done: false
  6357. });
  6358. } else {
  6359. this._cachedChunks.push(chunk);
  6360. }
  6361. },
  6362. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  6363. if (args) {
  6364. this._onProgressiveData(args.chunk);
  6365. }
  6366. this._done = true;
  6367. if (this._cachedChunks.length > 0) {
  6368. return;
  6369. }
  6370. this._requests.forEach(function (requestCapability) {
  6371. requestCapability.resolve({
  6372. value: undefined,
  6373. done: true
  6374. });
  6375. });
  6376. this._requests = [];
  6377. },
  6378. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  6379. var url = this._url;
  6380. var exception;
  6381. if (status === 404 || status === 0 && /^file:/.test(url)) {
  6382. exception = new _util.MissingPDFException('Missing PDF "' + url + '".');
  6383. } else {
  6384. exception = new _util.UnexpectedResponseException('Unexpected server response (' + status + ') while retrieving PDF "' + url + '".', status);
  6385. }
  6386. this._storedError = exception;
  6387. this._headersReceivedCapability.reject(exception);
  6388. this._requests.forEach(function (requestCapability) {
  6389. requestCapability.reject(exception);
  6390. });
  6391. this._requests = [];
  6392. this._cachedChunks = [];
  6393. },
  6394. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  6395. if (this.onProgress) {
  6396. this.onProgress({
  6397. loaded: data.loaded,
  6398. total: data.lengthComputable ? data.total : this._contentLength
  6399. });
  6400. }
  6401. },
  6402. get isRangeSupported() {
  6403. return this._isRangeSupported;
  6404. },
  6405. get isStreamingSupported() {
  6406. return this._isStreamingSupported;
  6407. },
  6408. get contentLength() {
  6409. return this._contentLength;
  6410. },
  6411. get headersReady() {
  6412. return this._headersReceivedCapability.promise;
  6413. },
  6414. read: function PDFNetworkStreamFullRequestReader_read() {
  6415. if (this._storedError) {
  6416. return Promise.reject(this._storedError);
  6417. }
  6418. if (this._cachedChunks.length > 0) {
  6419. var chunk = this._cachedChunks.shift();
  6420. return Promise.resolve({
  6421. value: chunk,
  6422. done: false
  6423. });
  6424. }
  6425. if (this._done) {
  6426. return Promise.resolve({
  6427. value: undefined,
  6428. done: true
  6429. });
  6430. }
  6431. var requestCapability = (0, _util.createPromiseCapability)();
  6432. this._requests.push(requestCapability);
  6433. return requestCapability.promise;
  6434. },
  6435. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  6436. this._done = true;
  6437. this._headersReceivedCapability.reject(reason);
  6438. this._requests.forEach(function (requestCapability) {
  6439. requestCapability.resolve({
  6440. value: undefined,
  6441. done: true
  6442. });
  6443. });
  6444. this._requests = [];
  6445. if (this._manager.isPendingRequest(this._fullRequestId)) {
  6446. this._manager.abortRequest(this._fullRequestId);
  6447. }
  6448. this._fullRequestReader = null;
  6449. }
  6450. };
  6451. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  6452. this._manager = manager;
  6453. var args = {
  6454. onDone: this._onDone.bind(this),
  6455. onProgress: this._onProgress.bind(this)
  6456. };
  6457. this._requestId = manager.requestRange(begin, end, args);
  6458. this._requests = [];
  6459. this._queuedChunk = null;
  6460. this._done = false;
  6461. this.onProgress = null;
  6462. this.onClosed = null;
  6463. }
  6464. PDFNetworkStreamRangeRequestReader.prototype = {
  6465. _close: function PDFNetworkStreamRangeRequestReader_close() {
  6466. if (this.onClosed) {
  6467. this.onClosed(this);
  6468. }
  6469. },
  6470. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  6471. var chunk = data.chunk;
  6472. if (this._requests.length > 0) {
  6473. var requestCapability = this._requests.shift();
  6474. requestCapability.resolve({
  6475. value: chunk,
  6476. done: false
  6477. });
  6478. } else {
  6479. this._queuedChunk = chunk;
  6480. }
  6481. this._done = true;
  6482. this._requests.forEach(function (requestCapability) {
  6483. requestCapability.resolve({
  6484. value: undefined,
  6485. done: true
  6486. });
  6487. });
  6488. this._requests = [];
  6489. this._close();
  6490. },
  6491. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  6492. if (!this.isStreamingSupported && this.onProgress) {
  6493. this.onProgress({ loaded: evt.loaded });
  6494. }
  6495. },
  6496. get isStreamingSupported() {
  6497. return false;
  6498. },
  6499. read: function PDFNetworkStreamRangeRequestReader_read() {
  6500. if (this._queuedChunk !== null) {
  6501. var chunk = this._queuedChunk;
  6502. this._queuedChunk = null;
  6503. return Promise.resolve({
  6504. value: chunk,
  6505. done: false
  6506. });
  6507. }
  6508. if (this._done) {
  6509. return Promise.resolve({
  6510. value: undefined,
  6511. done: true
  6512. });
  6513. }
  6514. var requestCapability = (0, _util.createPromiseCapability)();
  6515. this._requests.push(requestCapability);
  6516. return requestCapability.promise;
  6517. },
  6518. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  6519. this._done = true;
  6520. this._requests.forEach(function (requestCapability) {
  6521. requestCapability.resolve({
  6522. value: undefined,
  6523. done: true
  6524. });
  6525. });
  6526. this._requests = [];
  6527. if (this._manager.isPendingRequest(this._requestId)) {
  6528. this._manager.abortRequest(this._requestId);
  6529. }
  6530. this._close();
  6531. }
  6532. };
  6533. (0, _api.setPDFNetworkStreamClass)(PDFNetworkStream);
  6534. exports.PDFNetworkStream = PDFNetworkStream;
  6535. exports.NetworkManager = NetworkManager;
  6536. /***/ }),
  6537. /* 10 */
  6538. /***/ (function(module, exports, __w_pdfjs_require__) {
  6539. "use strict";
  6540. 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; };
  6541. (function (e, a) {
  6542. for (var i in a) {
  6543. e[i] = a[i];
  6544. }
  6545. })(exports, function (modules) {
  6546. var installedModules = {};
  6547. function __w_pdfjs_require__(moduleId) {
  6548. if (installedModules[moduleId]) return installedModules[moduleId].exports;
  6549. var module = installedModules[moduleId] = {
  6550. i: moduleId,
  6551. l: false,
  6552. exports: {}
  6553. };
  6554. modules[moduleId].call(module.exports, module, module.exports, __w_pdfjs_require__);
  6555. module.l = true;
  6556. return module.exports;
  6557. }
  6558. __w_pdfjs_require__.m = modules;
  6559. __w_pdfjs_require__.c = installedModules;
  6560. __w_pdfjs_require__.i = function (value) {
  6561. return value;
  6562. };
  6563. __w_pdfjs_require__.d = function (exports, name, getter) {
  6564. if (!__w_pdfjs_require__.o(exports, name)) {
  6565. Object.defineProperty(exports, name, {
  6566. configurable: false,
  6567. enumerable: true,
  6568. get: getter
  6569. });
  6570. }
  6571. };
  6572. __w_pdfjs_require__.n = function (module) {
  6573. var getter = module && module.__esModule ? function getDefault() {
  6574. return module['default'];
  6575. } : function getModuleExports() {
  6576. return module;
  6577. };
  6578. __w_pdfjs_require__.d(getter, 'a', getter);
  6579. return getter;
  6580. };
  6581. __w_pdfjs_require__.o = function (object, property) {
  6582. return Object.prototype.hasOwnProperty.call(object, property);
  6583. };
  6584. __w_pdfjs_require__.p = "";
  6585. return __w_pdfjs_require__(__w_pdfjs_require__.s = 7);
  6586. }([function (module, exports, __w_pdfjs_require__) {
  6587. "use strict";
  6588. var _typeof = typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol" ? function (obj) {
  6589. return typeof obj === 'undefined' ? 'undefined' : _typeof2(obj);
  6590. } : function (obj) {
  6591. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === 'undefined' ? 'undefined' : _typeof2(obj);
  6592. };
  6593. var _require = __w_pdfjs_require__(1),
  6594. assert = _require.assert;
  6595. function IsPropertyKey(argument) {
  6596. return typeof argument === 'string' || (typeof argument === 'undefined' ? 'undefined' : _typeof(argument)) === 'symbol';
  6597. }
  6598. exports.typeIsObject = function (x) {
  6599. return (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && x !== null || typeof x === 'function';
  6600. };
  6601. exports.createDataProperty = function (o, p, v) {
  6602. assert(exports.typeIsObject(o));
  6603. Object.defineProperty(o, p, {
  6604. value: v,
  6605. writable: true,
  6606. enumerable: true,
  6607. configurable: true
  6608. });
  6609. };
  6610. exports.createArrayFromList = function (elements) {
  6611. return elements.slice();
  6612. };
  6613. exports.ArrayBufferCopy = function (dest, destOffset, src, srcOffset, n) {
  6614. new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
  6615. };
  6616. exports.CreateIterResultObject = function (value, done) {
  6617. assert(typeof done === 'boolean');
  6618. var obj = {};
  6619. Object.defineProperty(obj, 'value', {
  6620. value: value,
  6621. enumerable: true,
  6622. writable: true,
  6623. configurable: true
  6624. });
  6625. Object.defineProperty(obj, 'done', {
  6626. value: done,
  6627. enumerable: true,
  6628. writable: true,
  6629. configurable: true
  6630. });
  6631. return obj;
  6632. };
  6633. exports.IsFiniteNonNegativeNumber = function (v) {
  6634. if (Number.isNaN(v)) {
  6635. return false;
  6636. }
  6637. if (v === Infinity) {
  6638. return false;
  6639. }
  6640. if (v < 0) {
  6641. return false;
  6642. }
  6643. return true;
  6644. };
  6645. function Call(F, V, args) {
  6646. if (typeof F !== 'function') {
  6647. throw new TypeError('Argument is not a function');
  6648. }
  6649. return Function.prototype.apply.call(F, V, args);
  6650. }
  6651. exports.InvokeOrNoop = function (O, P, args) {
  6652. assert(O !== undefined);
  6653. assert(IsPropertyKey(P));
  6654. assert(Array.isArray(args));
  6655. var method = O[P];
  6656. if (method === undefined) {
  6657. return undefined;
  6658. }
  6659. return Call(method, O, args);
  6660. };
  6661. exports.PromiseInvokeOrNoop = function (O, P, args) {
  6662. assert(O !== undefined);
  6663. assert(IsPropertyKey(P));
  6664. assert(Array.isArray(args));
  6665. try {
  6666. return Promise.resolve(exports.InvokeOrNoop(O, P, args));
  6667. } catch (returnValueE) {
  6668. return Promise.reject(returnValueE);
  6669. }
  6670. };
  6671. exports.PromiseInvokeOrPerformFallback = function (O, P, args, F, argsF) {
  6672. assert(O !== undefined);
  6673. assert(IsPropertyKey(P));
  6674. assert(Array.isArray(args));
  6675. assert(Array.isArray(argsF));
  6676. var method = void 0;
  6677. try {
  6678. method = O[P];
  6679. } catch (methodE) {
  6680. return Promise.reject(methodE);
  6681. }
  6682. if (method === undefined) {
  6683. return F.apply(null, argsF);
  6684. }
  6685. try {
  6686. return Promise.resolve(Call(method, O, args));
  6687. } catch (e) {
  6688. return Promise.reject(e);
  6689. }
  6690. };
  6691. exports.TransferArrayBuffer = function (O) {
  6692. return O.slice();
  6693. };
  6694. exports.ValidateAndNormalizeHighWaterMark = function (highWaterMark) {
  6695. highWaterMark = Number(highWaterMark);
  6696. if (Number.isNaN(highWaterMark) || highWaterMark < 0) {
  6697. throw new RangeError('highWaterMark property of a queuing strategy must be non-negative and non-NaN');
  6698. }
  6699. return highWaterMark;
  6700. };
  6701. exports.ValidateAndNormalizeQueuingStrategy = function (size, highWaterMark) {
  6702. if (size !== undefined && typeof size !== 'function') {
  6703. throw new TypeError('size property of a queuing strategy must be a function');
  6704. }
  6705. highWaterMark = exports.ValidateAndNormalizeHighWaterMark(highWaterMark);
  6706. return {
  6707. size: size,
  6708. highWaterMark: highWaterMark
  6709. };
  6710. };
  6711. }, function (module, exports, __w_pdfjs_require__) {
  6712. "use strict";
  6713. function rethrowAssertionErrorRejection(e) {
  6714. if (e && e.constructor === AssertionError) {
  6715. setTimeout(function () {
  6716. throw e;
  6717. }, 0);
  6718. }
  6719. }
  6720. function AssertionError(message) {
  6721. this.name = 'AssertionError';
  6722. this.message = message || '';
  6723. this.stack = new Error().stack;
  6724. }
  6725. AssertionError.prototype = Object.create(Error.prototype);
  6726. AssertionError.prototype.constructor = AssertionError;
  6727. function assert(value, message) {
  6728. if (!value) {
  6729. throw new AssertionError(message);
  6730. }
  6731. }
  6732. module.exports = {
  6733. rethrowAssertionErrorRejection: rethrowAssertionErrorRejection,
  6734. AssertionError: AssertionError,
  6735. assert: assert
  6736. };
  6737. }, function (module, exports, __w_pdfjs_require__) {
  6738. "use strict";
  6739. var _createClass = function () {
  6740. function defineProperties(target, props) {
  6741. for (var i = 0; i < props.length; i++) {
  6742. var descriptor = props[i];
  6743. descriptor.enumerable = descriptor.enumerable || false;
  6744. descriptor.configurable = true;
  6745. if ("value" in descriptor) descriptor.writable = true;
  6746. Object.defineProperty(target, descriptor.key, descriptor);
  6747. }
  6748. }
  6749. return function (Constructor, protoProps, staticProps) {
  6750. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  6751. if (staticProps) defineProperties(Constructor, staticProps);
  6752. return Constructor;
  6753. };
  6754. }();
  6755. function _classCallCheck(instance, Constructor) {
  6756. if (!(instance instanceof Constructor)) {
  6757. throw new TypeError("Cannot call a class as a function");
  6758. }
  6759. }
  6760. var _require = __w_pdfjs_require__(0),
  6761. InvokeOrNoop = _require.InvokeOrNoop,
  6762. PromiseInvokeOrNoop = _require.PromiseInvokeOrNoop,
  6763. ValidateAndNormalizeQueuingStrategy = _require.ValidateAndNormalizeQueuingStrategy,
  6764. typeIsObject = _require.typeIsObject;
  6765. var _require2 = __w_pdfjs_require__(1),
  6766. assert = _require2.assert,
  6767. rethrowAssertionErrorRejection = _require2.rethrowAssertionErrorRejection;
  6768. var _require3 = __w_pdfjs_require__(3),
  6769. DequeueValue = _require3.DequeueValue,
  6770. EnqueueValueWithSize = _require3.EnqueueValueWithSize,
  6771. PeekQueueValue = _require3.PeekQueueValue,
  6772. ResetQueue = _require3.ResetQueue;
  6773. var WritableStream = function () {
  6774. function WritableStream() {
  6775. var underlyingSink = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  6776. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  6777. size = _ref.size,
  6778. _ref$highWaterMark = _ref.highWaterMark,
  6779. highWaterMark = _ref$highWaterMark === undefined ? 1 : _ref$highWaterMark;
  6780. _classCallCheck(this, WritableStream);
  6781. this._state = 'writable';
  6782. this._storedError = undefined;
  6783. this._writer = undefined;
  6784. this._writableStreamController = undefined;
  6785. this._writeRequests = [];
  6786. this._inFlightWriteRequest = undefined;
  6787. this._closeRequest = undefined;
  6788. this._inFlightCloseRequest = undefined;
  6789. this._pendingAbortRequest = undefined;
  6790. this._backpressure = false;
  6791. var type = underlyingSink.type;
  6792. if (type !== undefined) {
  6793. throw new RangeError('Invalid type is specified');
  6794. }
  6795. this._writableStreamController = new WritableStreamDefaultController(this, underlyingSink, size, highWaterMark);
  6796. this._writableStreamController.__startSteps();
  6797. }
  6798. _createClass(WritableStream, [{
  6799. key: 'abort',
  6800. value: function abort(reason) {
  6801. if (IsWritableStream(this) === false) {
  6802. return Promise.reject(streamBrandCheckException('abort'));
  6803. }
  6804. if (IsWritableStreamLocked(this) === true) {
  6805. return Promise.reject(new TypeError('Cannot abort a stream that already has a writer'));
  6806. }
  6807. return WritableStreamAbort(this, reason);
  6808. }
  6809. }, {
  6810. key: 'getWriter',
  6811. value: function getWriter() {
  6812. if (IsWritableStream(this) === false) {
  6813. throw streamBrandCheckException('getWriter');
  6814. }
  6815. return AcquireWritableStreamDefaultWriter(this);
  6816. }
  6817. }, {
  6818. key: 'locked',
  6819. get: function get() {
  6820. if (IsWritableStream(this) === false) {
  6821. throw streamBrandCheckException('locked');
  6822. }
  6823. return IsWritableStreamLocked(this);
  6824. }
  6825. }]);
  6826. return WritableStream;
  6827. }();
  6828. module.exports = {
  6829. AcquireWritableStreamDefaultWriter: AcquireWritableStreamDefaultWriter,
  6830. IsWritableStream: IsWritableStream,
  6831. IsWritableStreamLocked: IsWritableStreamLocked,
  6832. WritableStream: WritableStream,
  6833. WritableStreamAbort: WritableStreamAbort,
  6834. WritableStreamDefaultControllerError: WritableStreamDefaultControllerError,
  6835. WritableStreamDefaultWriterCloseWithErrorPropagation: WritableStreamDefaultWriterCloseWithErrorPropagation,
  6836. WritableStreamDefaultWriterRelease: WritableStreamDefaultWriterRelease,
  6837. WritableStreamDefaultWriterWrite: WritableStreamDefaultWriterWrite,
  6838. WritableStreamCloseQueuedOrInFlight: WritableStreamCloseQueuedOrInFlight
  6839. };
  6840. function AcquireWritableStreamDefaultWriter(stream) {
  6841. return new WritableStreamDefaultWriter(stream);
  6842. }
  6843. function IsWritableStream(x) {
  6844. if (!typeIsObject(x)) {
  6845. return false;
  6846. }
  6847. if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) {
  6848. return false;
  6849. }
  6850. return true;
  6851. }
  6852. function IsWritableStreamLocked(stream) {
  6853. assert(IsWritableStream(stream) === true, 'IsWritableStreamLocked should only be used on known writable streams');
  6854. if (stream._writer === undefined) {
  6855. return false;
  6856. }
  6857. return true;
  6858. }
  6859. function WritableStreamAbort(stream, reason) {
  6860. var state = stream._state;
  6861. if (state === 'closed') {
  6862. return Promise.resolve(undefined);
  6863. }
  6864. if (state === 'errored') {
  6865. return Promise.reject(stream._storedError);
  6866. }
  6867. var error = new TypeError('Requested to abort');
  6868. if (stream._pendingAbortRequest !== undefined) {
  6869. return Promise.reject(error);
  6870. }
  6871. assert(state === 'writable' || state === 'erroring', 'state must be writable or erroring');
  6872. var wasAlreadyErroring = false;
  6873. if (state === 'erroring') {
  6874. wasAlreadyErroring = true;
  6875. reason = undefined;
  6876. }
  6877. var promise = new Promise(function (resolve, reject) {
  6878. stream._pendingAbortRequest = {
  6879. _resolve: resolve,
  6880. _reject: reject,
  6881. _reason: reason,
  6882. _wasAlreadyErroring: wasAlreadyErroring
  6883. };
  6884. });
  6885. if (wasAlreadyErroring === false) {
  6886. WritableStreamStartErroring(stream, error);
  6887. }
  6888. return promise;
  6889. }
  6890. function WritableStreamAddWriteRequest(stream) {
  6891. assert(IsWritableStreamLocked(stream) === true);
  6892. assert(stream._state === 'writable');
  6893. var promise = new Promise(function (resolve, reject) {
  6894. var writeRequest = {
  6895. _resolve: resolve,
  6896. _reject: reject
  6897. };
  6898. stream._writeRequests.push(writeRequest);
  6899. });
  6900. return promise;
  6901. }
  6902. function WritableStreamDealWithRejection(stream, error) {
  6903. var state = stream._state;
  6904. if (state === 'writable') {
  6905. WritableStreamStartErroring(stream, error);
  6906. return;
  6907. }
  6908. assert(state === 'erroring');
  6909. WritableStreamFinishErroring(stream);
  6910. }
  6911. function WritableStreamStartErroring(stream, reason) {
  6912. assert(stream._storedError === undefined, 'stream._storedError === undefined');
  6913. assert(stream._state === 'writable', 'state must be writable');
  6914. var controller = stream._writableStreamController;
  6915. assert(controller !== undefined, 'controller must not be undefined');
  6916. stream._state = 'erroring';
  6917. stream._storedError = reason;
  6918. var writer = stream._writer;
  6919. if (writer !== undefined) {
  6920. WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason);
  6921. }
  6922. if (WritableStreamHasOperationMarkedInFlight(stream) === false && controller._started === true) {
  6923. WritableStreamFinishErroring(stream);
  6924. }
  6925. }
  6926. function WritableStreamFinishErroring(stream) {
  6927. assert(stream._state === 'erroring', 'stream._state === erroring');
  6928. assert(WritableStreamHasOperationMarkedInFlight(stream) === false, 'WritableStreamHasOperationMarkedInFlight(stream) === false');
  6929. stream._state = 'errored';
  6930. stream._writableStreamController.__errorSteps();
  6931. var storedError = stream._storedError;
  6932. for (var i = 0; i < stream._writeRequests.length; i++) {
  6933. var writeRequest = stream._writeRequests[i];
  6934. writeRequest._reject(storedError);
  6935. }
  6936. stream._writeRequests = [];
  6937. if (stream._pendingAbortRequest === undefined) {
  6938. WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
  6939. return;
  6940. }
  6941. var abortRequest = stream._pendingAbortRequest;
  6942. stream._pendingAbortRequest = undefined;
  6943. if (abortRequest._wasAlreadyErroring === true) {
  6944. abortRequest._reject(storedError);
  6945. WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
  6946. return;
  6947. }
  6948. var promise = stream._writableStreamController.__abortSteps(abortRequest._reason);
  6949. promise.then(function () {
  6950. abortRequest._resolve();
  6951. WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
  6952. }, function (reason) {
  6953. abortRequest._reject(reason);
  6954. WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
  6955. });
  6956. }
  6957. function WritableStreamFinishInFlightWrite(stream) {
  6958. assert(stream._inFlightWriteRequest !== undefined);
  6959. stream._inFlightWriteRequest._resolve(undefined);
  6960. stream._inFlightWriteRequest = undefined;
  6961. }
  6962. function WritableStreamFinishInFlightWriteWithError(stream, error) {
  6963. assert(stream._inFlightWriteRequest !== undefined);
  6964. stream._inFlightWriteRequest._reject(error);
  6965. stream._inFlightWriteRequest = undefined;
  6966. assert(stream._state === 'writable' || stream._state === 'erroring');
  6967. WritableStreamDealWithRejection(stream, error);
  6968. }
  6969. function WritableStreamFinishInFlightClose(stream) {
  6970. assert(stream._inFlightCloseRequest !== undefined);
  6971. stream._inFlightCloseRequest._resolve(undefined);
  6972. stream._inFlightCloseRequest = undefined;
  6973. var state = stream._state;
  6974. assert(state === 'writable' || state === 'erroring');
  6975. if (state === 'erroring') {
  6976. stream._storedError = undefined;
  6977. if (stream._pendingAbortRequest !== undefined) {
  6978. stream._pendingAbortRequest._resolve();
  6979. stream._pendingAbortRequest = undefined;
  6980. }
  6981. }
  6982. stream._state = 'closed';
  6983. var writer = stream._writer;
  6984. if (writer !== undefined) {
  6985. defaultWriterClosedPromiseResolve(writer);
  6986. }
  6987. assert(stream._pendingAbortRequest === undefined, 'stream._pendingAbortRequest === undefined');
  6988. assert(stream._storedError === undefined, 'stream._storedError === undefined');
  6989. }
  6990. function WritableStreamFinishInFlightCloseWithError(stream, error) {
  6991. assert(stream._inFlightCloseRequest !== undefined);
  6992. stream._inFlightCloseRequest._reject(error);
  6993. stream._inFlightCloseRequest = undefined;
  6994. assert(stream._state === 'writable' || stream._state === 'erroring');
  6995. if (stream._pendingAbortRequest !== undefined) {
  6996. stream._pendingAbortRequest._reject(error);
  6997. stream._pendingAbortRequest = undefined;
  6998. }
  6999. WritableStreamDealWithRejection(stream, error);
  7000. }
  7001. function WritableStreamCloseQueuedOrInFlight(stream) {
  7002. if (stream._closeRequest === undefined && stream._inFlightCloseRequest === undefined) {
  7003. return false;
  7004. }
  7005. return true;
  7006. }
  7007. function WritableStreamHasOperationMarkedInFlight(stream) {
  7008. if (stream._inFlightWriteRequest === undefined && stream._inFlightCloseRequest === undefined) {
  7009. return false;
  7010. }
  7011. return true;
  7012. }
  7013. function WritableStreamMarkCloseRequestInFlight(stream) {
  7014. assert(stream._inFlightCloseRequest === undefined);
  7015. assert(stream._closeRequest !== undefined);
  7016. stream._inFlightCloseRequest = stream._closeRequest;
  7017. stream._closeRequest = undefined;
  7018. }
  7019. function WritableStreamMarkFirstWriteRequestInFlight(stream) {
  7020. assert(stream._inFlightWriteRequest === undefined, 'there must be no pending write request');
  7021. assert(stream._writeRequests.length !== 0, 'writeRequests must not be empty');
  7022. stream._inFlightWriteRequest = stream._writeRequests.shift();
  7023. }
  7024. function WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream) {
  7025. assert(stream._state === 'errored', '_stream_.[[state]] is `"errored"`');
  7026. if (stream._closeRequest !== undefined) {
  7027. assert(stream._inFlightCloseRequest === undefined);
  7028. stream._closeRequest._reject(stream._storedError);
  7029. stream._closeRequest = undefined;
  7030. }
  7031. var writer = stream._writer;
  7032. if (writer !== undefined) {
  7033. defaultWriterClosedPromiseReject(writer, stream._storedError);
  7034. writer._closedPromise.catch(function () {});
  7035. }
  7036. }
  7037. function WritableStreamUpdateBackpressure(stream, backpressure) {
  7038. assert(stream._state === 'writable');
  7039. assert(WritableStreamCloseQueuedOrInFlight(stream) === false);
  7040. var writer = stream._writer;
  7041. if (writer !== undefined && backpressure !== stream._backpressure) {
  7042. if (backpressure === true) {
  7043. defaultWriterReadyPromiseReset(writer);
  7044. } else {
  7045. assert(backpressure === false);
  7046. defaultWriterReadyPromiseResolve(writer);
  7047. }
  7048. }
  7049. stream._backpressure = backpressure;
  7050. }
  7051. var WritableStreamDefaultWriter = function () {
  7052. function WritableStreamDefaultWriter(stream) {
  7053. _classCallCheck(this, WritableStreamDefaultWriter);
  7054. if (IsWritableStream(stream) === false) {
  7055. throw new TypeError('WritableStreamDefaultWriter can only be constructed with a WritableStream instance');
  7056. }
  7057. if (IsWritableStreamLocked(stream) === true) {
  7058. throw new TypeError('This stream has already been locked for exclusive writing by another writer');
  7059. }
  7060. this._ownerWritableStream = stream;
  7061. stream._writer = this;
  7062. var state = stream._state;
  7063. if (state === 'writable') {
  7064. if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._backpressure === true) {
  7065. defaultWriterReadyPromiseInitialize(this);
  7066. } else {
  7067. defaultWriterReadyPromiseInitializeAsResolved(this);
  7068. }
  7069. defaultWriterClosedPromiseInitialize(this);
  7070. } else if (state === 'erroring') {
  7071. defaultWriterReadyPromiseInitializeAsRejected(this, stream._storedError);
  7072. this._readyPromise.catch(function () {});
  7073. defaultWriterClosedPromiseInitialize(this);
  7074. } else if (state === 'closed') {
  7075. defaultWriterReadyPromiseInitializeAsResolved(this);
  7076. defaultWriterClosedPromiseInitializeAsResolved(this);
  7077. } else {
  7078. assert(state === 'errored', 'state must be errored');
  7079. var storedError = stream._storedError;
  7080. defaultWriterReadyPromiseInitializeAsRejected(this, storedError);
  7081. this._readyPromise.catch(function () {});
  7082. defaultWriterClosedPromiseInitializeAsRejected(this, storedError);
  7083. this._closedPromise.catch(function () {});
  7084. }
  7085. }
  7086. _createClass(WritableStreamDefaultWriter, [{
  7087. key: 'abort',
  7088. value: function abort(reason) {
  7089. if (IsWritableStreamDefaultWriter(this) === false) {
  7090. return Promise.reject(defaultWriterBrandCheckException('abort'));
  7091. }
  7092. if (this._ownerWritableStream === undefined) {
  7093. return Promise.reject(defaultWriterLockException('abort'));
  7094. }
  7095. return WritableStreamDefaultWriterAbort(this, reason);
  7096. }
  7097. }, {
  7098. key: 'close',
  7099. value: function close() {
  7100. if (IsWritableStreamDefaultWriter(this) === false) {
  7101. return Promise.reject(defaultWriterBrandCheckException('close'));
  7102. }
  7103. var stream = this._ownerWritableStream;
  7104. if (stream === undefined) {
  7105. return Promise.reject(defaultWriterLockException('close'));
  7106. }
  7107. if (WritableStreamCloseQueuedOrInFlight(stream) === true) {
  7108. return Promise.reject(new TypeError('cannot close an already-closing stream'));
  7109. }
  7110. return WritableStreamDefaultWriterClose(this);
  7111. }
  7112. }, {
  7113. key: 'releaseLock',
  7114. value: function releaseLock() {
  7115. if (IsWritableStreamDefaultWriter(this) === false) {
  7116. throw defaultWriterBrandCheckException('releaseLock');
  7117. }
  7118. var stream = this._ownerWritableStream;
  7119. if (stream === undefined) {
  7120. return;
  7121. }
  7122. assert(stream._writer !== undefined);
  7123. WritableStreamDefaultWriterRelease(this);
  7124. }
  7125. }, {
  7126. key: 'write',
  7127. value: function write(chunk) {
  7128. if (IsWritableStreamDefaultWriter(this) === false) {
  7129. return Promise.reject(defaultWriterBrandCheckException('write'));
  7130. }
  7131. if (this._ownerWritableStream === undefined) {
  7132. return Promise.reject(defaultWriterLockException('write to'));
  7133. }
  7134. return WritableStreamDefaultWriterWrite(this, chunk);
  7135. }
  7136. }, {
  7137. key: 'closed',
  7138. get: function get() {
  7139. if (IsWritableStreamDefaultWriter(this) === false) {
  7140. return Promise.reject(defaultWriterBrandCheckException('closed'));
  7141. }
  7142. return this._closedPromise;
  7143. }
  7144. }, {
  7145. key: 'desiredSize',
  7146. get: function get() {
  7147. if (IsWritableStreamDefaultWriter(this) === false) {
  7148. throw defaultWriterBrandCheckException('desiredSize');
  7149. }
  7150. if (this._ownerWritableStream === undefined) {
  7151. throw defaultWriterLockException('desiredSize');
  7152. }
  7153. return WritableStreamDefaultWriterGetDesiredSize(this);
  7154. }
  7155. }, {
  7156. key: 'ready',
  7157. get: function get() {
  7158. if (IsWritableStreamDefaultWriter(this) === false) {
  7159. return Promise.reject(defaultWriterBrandCheckException('ready'));
  7160. }
  7161. return this._readyPromise;
  7162. }
  7163. }]);
  7164. return WritableStreamDefaultWriter;
  7165. }();
  7166. function IsWritableStreamDefaultWriter(x) {
  7167. if (!typeIsObject(x)) {
  7168. return false;
  7169. }
  7170. if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) {
  7171. return false;
  7172. }
  7173. return true;
  7174. }
  7175. function WritableStreamDefaultWriterAbort(writer, reason) {
  7176. var stream = writer._ownerWritableStream;
  7177. assert(stream !== undefined);
  7178. return WritableStreamAbort(stream, reason);
  7179. }
  7180. function WritableStreamDefaultWriterClose(writer) {
  7181. var stream = writer._ownerWritableStream;
  7182. assert(stream !== undefined);
  7183. var state = stream._state;
  7184. if (state === 'closed' || state === 'errored') {
  7185. return Promise.reject(new TypeError('The stream (in ' + state + ' state) is not in the writable state and cannot be closed'));
  7186. }
  7187. assert(state === 'writable' || state === 'erroring');
  7188. assert(WritableStreamCloseQueuedOrInFlight(stream) === false);
  7189. var promise = new Promise(function (resolve, reject) {
  7190. var closeRequest = {
  7191. _resolve: resolve,
  7192. _reject: reject
  7193. };
  7194. stream._closeRequest = closeRequest;
  7195. });
  7196. if (stream._backpressure === true && state === 'writable') {
  7197. defaultWriterReadyPromiseResolve(writer);
  7198. }
  7199. WritableStreamDefaultControllerClose(stream._writableStreamController);
  7200. return promise;
  7201. }
  7202. function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) {
  7203. var stream = writer._ownerWritableStream;
  7204. assert(stream !== undefined);
  7205. var state = stream._state;
  7206. if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') {
  7207. return Promise.resolve();
  7208. }
  7209. if (state === 'errored') {
  7210. return Promise.reject(stream._storedError);
  7211. }
  7212. assert(state === 'writable' || state === 'erroring');
  7213. return WritableStreamDefaultWriterClose(writer);
  7214. }
  7215. function WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) {
  7216. if (writer._closedPromiseState === 'pending') {
  7217. defaultWriterClosedPromiseReject(writer, error);
  7218. } else {
  7219. defaultWriterClosedPromiseResetToRejected(writer, error);
  7220. }
  7221. writer._closedPromise.catch(function () {});
  7222. }
  7223. function WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) {
  7224. if (writer._readyPromiseState === 'pending') {
  7225. defaultWriterReadyPromiseReject(writer, error);
  7226. } else {
  7227. defaultWriterReadyPromiseResetToRejected(writer, error);
  7228. }
  7229. writer._readyPromise.catch(function () {});
  7230. }
  7231. function WritableStreamDefaultWriterGetDesiredSize(writer) {
  7232. var stream = writer._ownerWritableStream;
  7233. var state = stream._state;
  7234. if (state === 'errored' || state === 'erroring') {
  7235. return null;
  7236. }
  7237. if (state === 'closed') {
  7238. return 0;
  7239. }
  7240. return WritableStreamDefaultControllerGetDesiredSize(stream._writableStreamController);
  7241. }
  7242. function WritableStreamDefaultWriterRelease(writer) {
  7243. var stream = writer._ownerWritableStream;
  7244. assert(stream !== undefined);
  7245. assert(stream._writer === writer);
  7246. var releasedError = new TypeError('Writer was released and can no longer be used to monitor the stream\'s closedness');
  7247. WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError);
  7248. WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError);
  7249. stream._writer = undefined;
  7250. writer._ownerWritableStream = undefined;
  7251. }
  7252. function WritableStreamDefaultWriterWrite(writer, chunk) {
  7253. var stream = writer._ownerWritableStream;
  7254. assert(stream !== undefined);
  7255. var controller = stream._writableStreamController;
  7256. var chunkSize = WritableStreamDefaultControllerGetChunkSize(controller, chunk);
  7257. if (stream !== writer._ownerWritableStream) {
  7258. return Promise.reject(defaultWriterLockException('write to'));
  7259. }
  7260. var state = stream._state;
  7261. if (state === 'errored') {
  7262. return Promise.reject(stream._storedError);
  7263. }
  7264. if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') {
  7265. return Promise.reject(new TypeError('The stream is closing or closed and cannot be written to'));
  7266. }
  7267. if (state === 'erroring') {
  7268. return Promise.reject(stream._storedError);
  7269. }
  7270. assert(state === 'writable');
  7271. var promise = WritableStreamAddWriteRequest(stream);
  7272. WritableStreamDefaultControllerWrite(controller, chunk, chunkSize);
  7273. return promise;
  7274. }
  7275. var WritableStreamDefaultController = function () {
  7276. function WritableStreamDefaultController(stream, underlyingSink, size, highWaterMark) {
  7277. _classCallCheck(this, WritableStreamDefaultController);
  7278. if (IsWritableStream(stream) === false) {
  7279. throw new TypeError('WritableStreamDefaultController can only be constructed with a WritableStream instance');
  7280. }
  7281. if (stream._writableStreamController !== undefined) {
  7282. throw new TypeError('WritableStreamDefaultController instances can only be created by the WritableStream constructor');
  7283. }
  7284. this._controlledWritableStream = stream;
  7285. this._underlyingSink = underlyingSink;
  7286. this._queue = undefined;
  7287. this._queueTotalSize = undefined;
  7288. ResetQueue(this);
  7289. this._started = false;
  7290. var normalizedStrategy = ValidateAndNormalizeQueuingStrategy(size, highWaterMark);
  7291. this._strategySize = normalizedStrategy.size;
  7292. this._strategyHWM = normalizedStrategy.highWaterMark;
  7293. var backpressure = WritableStreamDefaultControllerGetBackpressure(this);
  7294. WritableStreamUpdateBackpressure(stream, backpressure);
  7295. }
  7296. _createClass(WritableStreamDefaultController, [{
  7297. key: 'error',
  7298. value: function error(e) {
  7299. if (IsWritableStreamDefaultController(this) === false) {
  7300. throw new TypeError('WritableStreamDefaultController.prototype.error can only be used on a WritableStreamDefaultController');
  7301. }
  7302. var state = this._controlledWritableStream._state;
  7303. if (state !== 'writable') {
  7304. return;
  7305. }
  7306. WritableStreamDefaultControllerError(this, e);
  7307. }
  7308. }, {
  7309. key: '__abortSteps',
  7310. value: function __abortSteps(reason) {
  7311. return PromiseInvokeOrNoop(this._underlyingSink, 'abort', [reason]);
  7312. }
  7313. }, {
  7314. key: '__errorSteps',
  7315. value: function __errorSteps() {
  7316. ResetQueue(this);
  7317. }
  7318. }, {
  7319. key: '__startSteps',
  7320. value: function __startSteps() {
  7321. var _this = this;
  7322. var startResult = InvokeOrNoop(this._underlyingSink, 'start', [this]);
  7323. var stream = this._controlledWritableStream;
  7324. Promise.resolve(startResult).then(function () {
  7325. assert(stream._state === 'writable' || stream._state === 'erroring');
  7326. _this._started = true;
  7327. WritableStreamDefaultControllerAdvanceQueueIfNeeded(_this);
  7328. }, function (r) {
  7329. assert(stream._state === 'writable' || stream._state === 'erroring');
  7330. _this._started = true;
  7331. WritableStreamDealWithRejection(stream, r);
  7332. }).catch(rethrowAssertionErrorRejection);
  7333. }
  7334. }]);
  7335. return WritableStreamDefaultController;
  7336. }();
  7337. function WritableStreamDefaultControllerClose(controller) {
  7338. EnqueueValueWithSize(controller, 'close', 0);
  7339. WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
  7340. }
  7341. function WritableStreamDefaultControllerGetChunkSize(controller, chunk) {
  7342. var strategySize = controller._strategySize;
  7343. if (strategySize === undefined) {
  7344. return 1;
  7345. }
  7346. try {
  7347. return strategySize(chunk);
  7348. } catch (chunkSizeE) {
  7349. WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE);
  7350. return 1;
  7351. }
  7352. }
  7353. function WritableStreamDefaultControllerGetDesiredSize(controller) {
  7354. return controller._strategyHWM - controller._queueTotalSize;
  7355. }
  7356. function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) {
  7357. var writeRecord = { chunk: chunk };
  7358. try {
  7359. EnqueueValueWithSize(controller, writeRecord, chunkSize);
  7360. } catch (enqueueE) {
  7361. WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE);
  7362. return;
  7363. }
  7364. var stream = controller._controlledWritableStream;
  7365. if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._state === 'writable') {
  7366. var backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
  7367. WritableStreamUpdateBackpressure(stream, backpressure);
  7368. }
  7369. WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
  7370. }
  7371. function IsWritableStreamDefaultController(x) {
  7372. if (!typeIsObject(x)) {
  7373. return false;
  7374. }
  7375. if (!Object.prototype.hasOwnProperty.call(x, '_underlyingSink')) {
  7376. return false;
  7377. }
  7378. return true;
  7379. }
  7380. function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {
  7381. var stream = controller._controlledWritableStream;
  7382. if (controller._started === false) {
  7383. return;
  7384. }
  7385. if (stream._inFlightWriteRequest !== undefined) {
  7386. return;
  7387. }
  7388. var state = stream._state;
  7389. if (state === 'closed' || state === 'errored') {
  7390. return;
  7391. }
  7392. if (state === 'erroring') {
  7393. WritableStreamFinishErroring(stream);
  7394. return;
  7395. }
  7396. if (controller._queue.length === 0) {
  7397. return;
  7398. }
  7399. var writeRecord = PeekQueueValue(controller);
  7400. if (writeRecord === 'close') {
  7401. WritableStreamDefaultControllerProcessClose(controller);
  7402. } else {
  7403. WritableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk);
  7404. }
  7405. }
  7406. function WritableStreamDefaultControllerErrorIfNeeded(controller, error) {
  7407. if (controller._controlledWritableStream._state === 'writable') {
  7408. WritableStreamDefaultControllerError(controller, error);
  7409. }
  7410. }
  7411. function WritableStreamDefaultControllerProcessClose(controller) {
  7412. var stream = controller._controlledWritableStream;
  7413. WritableStreamMarkCloseRequestInFlight(stream);
  7414. DequeueValue(controller);
  7415. assert(controller._queue.length === 0, 'queue must be empty once the final write record is dequeued');
  7416. var sinkClosePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'close', []);
  7417. sinkClosePromise.then(function () {
  7418. WritableStreamFinishInFlightClose(stream);
  7419. }, function (reason) {
  7420. WritableStreamFinishInFlightCloseWithError(stream, reason);
  7421. }).catch(rethrowAssertionErrorRejection);
  7422. }
  7423. function WritableStreamDefaultControllerProcessWrite(controller, chunk) {
  7424. var stream = controller._controlledWritableStream;
  7425. WritableStreamMarkFirstWriteRequestInFlight(stream);
  7426. var sinkWritePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'write', [chunk, controller]);
  7427. sinkWritePromise.then(function () {
  7428. WritableStreamFinishInFlightWrite(stream);
  7429. var state = stream._state;
  7430. assert(state === 'writable' || state === 'erroring');
  7431. DequeueValue(controller);
  7432. if (WritableStreamCloseQueuedOrInFlight(stream) === false && state === 'writable') {
  7433. var backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
  7434. WritableStreamUpdateBackpressure(stream, backpressure);
  7435. }
  7436. WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
  7437. }, function (reason) {
  7438. WritableStreamFinishInFlightWriteWithError(stream, reason);
  7439. }).catch(rethrowAssertionErrorRejection);
  7440. }
  7441. function WritableStreamDefaultControllerGetBackpressure(controller) {
  7442. var desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller);
  7443. return desiredSize <= 0;
  7444. }
  7445. function WritableStreamDefaultControllerError(controller, error) {
  7446. var stream = controller._controlledWritableStream;
  7447. assert(stream._state === 'writable');
  7448. WritableStreamStartErroring(stream, error);
  7449. }
  7450. function streamBrandCheckException(name) {
  7451. return new TypeError('WritableStream.prototype.' + name + ' can only be used on a WritableStream');
  7452. }
  7453. function defaultWriterBrandCheckException(name) {
  7454. return new TypeError('WritableStreamDefaultWriter.prototype.' + name + ' can only be used on a WritableStreamDefaultWriter');
  7455. }
  7456. function defaultWriterLockException(name) {
  7457. return new TypeError('Cannot ' + name + ' a stream using a released writer');
  7458. }
  7459. function defaultWriterClosedPromiseInitialize(writer) {
  7460. writer._closedPromise = new Promise(function (resolve, reject) {
  7461. writer._closedPromise_resolve = resolve;
  7462. writer._closedPromise_reject = reject;
  7463. writer._closedPromiseState = 'pending';
  7464. });
  7465. }
  7466. function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) {
  7467. writer._closedPromise = Promise.reject(reason);
  7468. writer._closedPromise_resolve = undefined;
  7469. writer._closedPromise_reject = undefined;
  7470. writer._closedPromiseState = 'rejected';
  7471. }
  7472. function defaultWriterClosedPromiseInitializeAsResolved(writer) {
  7473. writer._closedPromise = Promise.resolve(undefined);
  7474. writer._closedPromise_resolve = undefined;
  7475. writer._closedPromise_reject = undefined;
  7476. writer._closedPromiseState = 'resolved';
  7477. }
  7478. function defaultWriterClosedPromiseReject(writer, reason) {
  7479. assert(writer._closedPromise_resolve !== undefined, 'writer._closedPromise_resolve !== undefined');
  7480. assert(writer._closedPromise_reject !== undefined, 'writer._closedPromise_reject !== undefined');
  7481. assert(writer._closedPromiseState === 'pending', 'writer._closedPromiseState is pending');
  7482. writer._closedPromise_reject(reason);
  7483. writer._closedPromise_resolve = undefined;
  7484. writer._closedPromise_reject = undefined;
  7485. writer._closedPromiseState = 'rejected';
  7486. }
  7487. function defaultWriterClosedPromiseResetToRejected(writer, reason) {
  7488. assert(writer._closedPromise_resolve === undefined, 'writer._closedPromise_resolve === undefined');
  7489. assert(writer._closedPromise_reject === undefined, 'writer._closedPromise_reject === undefined');
  7490. assert(writer._closedPromiseState !== 'pending', 'writer._closedPromiseState is not pending');
  7491. writer._closedPromise = Promise.reject(reason);
  7492. writer._closedPromiseState = 'rejected';
  7493. }
  7494. function defaultWriterClosedPromiseResolve(writer) {
  7495. assert(writer._closedPromise_resolve !== undefined, 'writer._closedPromise_resolve !== undefined');
  7496. assert(writer._closedPromise_reject !== undefined, 'writer._closedPromise_reject !== undefined');
  7497. assert(writer._closedPromiseState === 'pending', 'writer._closedPromiseState is pending');
  7498. writer._closedPromise_resolve(undefined);
  7499. writer._closedPromise_resolve = undefined;
  7500. writer._closedPromise_reject = undefined;
  7501. writer._closedPromiseState = 'resolved';
  7502. }
  7503. function defaultWriterReadyPromiseInitialize(writer) {
  7504. writer._readyPromise = new Promise(function (resolve, reject) {
  7505. writer._readyPromise_resolve = resolve;
  7506. writer._readyPromise_reject = reject;
  7507. });
  7508. writer._readyPromiseState = 'pending';
  7509. }
  7510. function defaultWriterReadyPromiseInitializeAsRejected(writer, reason) {
  7511. writer._readyPromise = Promise.reject(reason);
  7512. writer._readyPromise_resolve = undefined;
  7513. writer._readyPromise_reject = undefined;
  7514. writer._readyPromiseState = 'rejected';
  7515. }
  7516. function defaultWriterReadyPromiseInitializeAsResolved(writer) {
  7517. writer._readyPromise = Promise.resolve(undefined);
  7518. writer._readyPromise_resolve = undefined;
  7519. writer._readyPromise_reject = undefined;
  7520. writer._readyPromiseState = 'fulfilled';
  7521. }
  7522. function defaultWriterReadyPromiseReject(writer, reason) {
  7523. assert(writer._readyPromise_resolve !== undefined, 'writer._readyPromise_resolve !== undefined');
  7524. assert(writer._readyPromise_reject !== undefined, 'writer._readyPromise_reject !== undefined');
  7525. writer._readyPromise_reject(reason);
  7526. writer._readyPromise_resolve = undefined;
  7527. writer._readyPromise_reject = undefined;
  7528. writer._readyPromiseState = 'rejected';
  7529. }
  7530. function defaultWriterReadyPromiseReset(writer) {
  7531. assert(writer._readyPromise_resolve === undefined, 'writer._readyPromise_resolve === undefined');
  7532. assert(writer._readyPromise_reject === undefined, 'writer._readyPromise_reject === undefined');
  7533. writer._readyPromise = new Promise(function (resolve, reject) {
  7534. writer._readyPromise_resolve = resolve;
  7535. writer._readyPromise_reject = reject;
  7536. });
  7537. writer._readyPromiseState = 'pending';
  7538. }
  7539. function defaultWriterReadyPromiseResetToRejected(writer, reason) {
  7540. assert(writer._readyPromise_resolve === undefined, 'writer._readyPromise_resolve === undefined');
  7541. assert(writer._readyPromise_reject === undefined, 'writer._readyPromise_reject === undefined');
  7542. writer._readyPromise = Promise.reject(reason);
  7543. writer._readyPromiseState = 'rejected';
  7544. }
  7545. function defaultWriterReadyPromiseResolve(writer) {
  7546. assert(writer._readyPromise_resolve !== undefined, 'writer._readyPromise_resolve !== undefined');
  7547. assert(writer._readyPromise_reject !== undefined, 'writer._readyPromise_reject !== undefined');
  7548. writer._readyPromise_resolve(undefined);
  7549. writer._readyPromise_resolve = undefined;
  7550. writer._readyPromise_reject = undefined;
  7551. writer._readyPromiseState = 'fulfilled';
  7552. }
  7553. }, function (module, exports, __w_pdfjs_require__) {
  7554. "use strict";
  7555. var _require = __w_pdfjs_require__(0),
  7556. IsFiniteNonNegativeNumber = _require.IsFiniteNonNegativeNumber;
  7557. var _require2 = __w_pdfjs_require__(1),
  7558. assert = _require2.assert;
  7559. exports.DequeueValue = function (container) {
  7560. assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: DequeueValue should only be used on containers with [[queue]] and [[queueTotalSize]].');
  7561. assert(container._queue.length > 0, 'Spec-level failure: should never dequeue from an empty queue.');
  7562. var pair = container._queue.shift();
  7563. container._queueTotalSize -= pair.size;
  7564. if (container._queueTotalSize < 0) {
  7565. container._queueTotalSize = 0;
  7566. }
  7567. return pair.value;
  7568. };
  7569. exports.EnqueueValueWithSize = function (container, value, size) {
  7570. assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: EnqueueValueWithSize should only be used on containers with [[queue]] and ' + '[[queueTotalSize]].');
  7571. size = Number(size);
  7572. if (!IsFiniteNonNegativeNumber(size)) {
  7573. throw new RangeError('Size must be a finite, non-NaN, non-negative number.');
  7574. }
  7575. container._queue.push({
  7576. value: value,
  7577. size: size
  7578. });
  7579. container._queueTotalSize += size;
  7580. };
  7581. exports.PeekQueueValue = function (container) {
  7582. assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: PeekQueueValue should only be used on containers with [[queue]] and [[queueTotalSize]].');
  7583. assert(container._queue.length > 0, 'Spec-level failure: should never peek at an empty queue.');
  7584. var pair = container._queue[0];
  7585. return pair.value;
  7586. };
  7587. exports.ResetQueue = function (container) {
  7588. assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: ResetQueue should only be used on containers with [[queue]] and [[queueTotalSize]].');
  7589. container._queue = [];
  7590. container._queueTotalSize = 0;
  7591. };
  7592. }, function (module, exports, __w_pdfjs_require__) {
  7593. "use strict";
  7594. var _createClass = function () {
  7595. function defineProperties(target, props) {
  7596. for (var i = 0; i < props.length; i++) {
  7597. var descriptor = props[i];
  7598. descriptor.enumerable = descriptor.enumerable || false;
  7599. descriptor.configurable = true;
  7600. if ("value" in descriptor) descriptor.writable = true;
  7601. Object.defineProperty(target, descriptor.key, descriptor);
  7602. }
  7603. }
  7604. return function (Constructor, protoProps, staticProps) {
  7605. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  7606. if (staticProps) defineProperties(Constructor, staticProps);
  7607. return Constructor;
  7608. };
  7609. }();
  7610. function _classCallCheck(instance, Constructor) {
  7611. if (!(instance instanceof Constructor)) {
  7612. throw new TypeError("Cannot call a class as a function");
  7613. }
  7614. }
  7615. var _require = __w_pdfjs_require__(0),
  7616. ArrayBufferCopy = _require.ArrayBufferCopy,
  7617. CreateIterResultObject = _require.CreateIterResultObject,
  7618. IsFiniteNonNegativeNumber = _require.IsFiniteNonNegativeNumber,
  7619. InvokeOrNoop = _require.InvokeOrNoop,
  7620. PromiseInvokeOrNoop = _require.PromiseInvokeOrNoop,
  7621. TransferArrayBuffer = _require.TransferArrayBuffer,
  7622. ValidateAndNormalizeQueuingStrategy = _require.ValidateAndNormalizeQueuingStrategy,
  7623. ValidateAndNormalizeHighWaterMark = _require.ValidateAndNormalizeHighWaterMark;
  7624. var _require2 = __w_pdfjs_require__(0),
  7625. createArrayFromList = _require2.createArrayFromList,
  7626. createDataProperty = _require2.createDataProperty,
  7627. typeIsObject = _require2.typeIsObject;
  7628. var _require3 = __w_pdfjs_require__(1),
  7629. assert = _require3.assert,
  7630. rethrowAssertionErrorRejection = _require3.rethrowAssertionErrorRejection;
  7631. var _require4 = __w_pdfjs_require__(3),
  7632. DequeueValue = _require4.DequeueValue,
  7633. EnqueueValueWithSize = _require4.EnqueueValueWithSize,
  7634. ResetQueue = _require4.ResetQueue;
  7635. var _require5 = __w_pdfjs_require__(2),
  7636. AcquireWritableStreamDefaultWriter = _require5.AcquireWritableStreamDefaultWriter,
  7637. IsWritableStream = _require5.IsWritableStream,
  7638. IsWritableStreamLocked = _require5.IsWritableStreamLocked,
  7639. WritableStreamAbort = _require5.WritableStreamAbort,
  7640. WritableStreamDefaultWriterCloseWithErrorPropagation = _require5.WritableStreamDefaultWriterCloseWithErrorPropagation,
  7641. WritableStreamDefaultWriterRelease = _require5.WritableStreamDefaultWriterRelease,
  7642. WritableStreamDefaultWriterWrite = _require5.WritableStreamDefaultWriterWrite,
  7643. WritableStreamCloseQueuedOrInFlight = _require5.WritableStreamCloseQueuedOrInFlight;
  7644. var ReadableStream = function () {
  7645. function ReadableStream() {
  7646. var underlyingSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  7647. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  7648. size = _ref.size,
  7649. highWaterMark = _ref.highWaterMark;
  7650. _classCallCheck(this, ReadableStream);
  7651. this._state = 'readable';
  7652. this._reader = undefined;
  7653. this._storedError = undefined;
  7654. this._disturbed = false;
  7655. this._readableStreamController = undefined;
  7656. var type = underlyingSource.type;
  7657. var typeString = String(type);
  7658. if (typeString === 'bytes') {
  7659. if (highWaterMark === undefined) {
  7660. highWaterMark = 0;
  7661. }
  7662. this._readableStreamController = new ReadableByteStreamController(this, underlyingSource, highWaterMark);
  7663. } else if (type === undefined) {
  7664. if (highWaterMark === undefined) {
  7665. highWaterMark = 1;
  7666. }
  7667. this._readableStreamController = new ReadableStreamDefaultController(this, underlyingSource, size, highWaterMark);
  7668. } else {
  7669. throw new RangeError('Invalid type is specified');
  7670. }
  7671. }
  7672. _createClass(ReadableStream, [{
  7673. key: 'cancel',
  7674. value: function cancel(reason) {
  7675. if (IsReadableStream(this) === false) {
  7676. return Promise.reject(streamBrandCheckException('cancel'));
  7677. }
  7678. if (IsReadableStreamLocked(this) === true) {
  7679. return Promise.reject(new TypeError('Cannot cancel a stream that already has a reader'));
  7680. }
  7681. return ReadableStreamCancel(this, reason);
  7682. }
  7683. }, {
  7684. key: 'getReader',
  7685. value: function getReader() {
  7686. var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  7687. mode = _ref2.mode;
  7688. if (IsReadableStream(this) === false) {
  7689. throw streamBrandCheckException('getReader');
  7690. }
  7691. if (mode === undefined) {
  7692. return AcquireReadableStreamDefaultReader(this);
  7693. }
  7694. mode = String(mode);
  7695. if (mode === 'byob') {
  7696. return AcquireReadableStreamBYOBReader(this);
  7697. }
  7698. throw new RangeError('Invalid mode is specified');
  7699. }
  7700. }, {
  7701. key: 'pipeThrough',
  7702. value: function pipeThrough(_ref3, options) {
  7703. var writable = _ref3.writable,
  7704. readable = _ref3.readable;
  7705. var promise = this.pipeTo(writable, options);
  7706. ifIsObjectAndHasAPromiseIsHandledInternalSlotSetPromiseIsHandledToTrue(promise);
  7707. return readable;
  7708. }
  7709. }, {
  7710. key: 'pipeTo',
  7711. value: function pipeTo(dest) {
  7712. var _this = this;
  7713. var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  7714. preventClose = _ref4.preventClose,
  7715. preventAbort = _ref4.preventAbort,
  7716. preventCancel = _ref4.preventCancel;
  7717. if (IsReadableStream(this) === false) {
  7718. return Promise.reject(streamBrandCheckException('pipeTo'));
  7719. }
  7720. if (IsWritableStream(dest) === false) {
  7721. return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo\'s first argument must be a WritableStream'));
  7722. }
  7723. preventClose = Boolean(preventClose);
  7724. preventAbort = Boolean(preventAbort);
  7725. preventCancel = Boolean(preventCancel);
  7726. if (IsReadableStreamLocked(this) === true) {
  7727. return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream'));
  7728. }
  7729. if (IsWritableStreamLocked(dest) === true) {
  7730. return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream'));
  7731. }
  7732. var reader = AcquireReadableStreamDefaultReader(this);
  7733. var writer = AcquireWritableStreamDefaultWriter(dest);
  7734. var shuttingDown = false;
  7735. var currentWrite = Promise.resolve();
  7736. return new Promise(function (resolve, reject) {
  7737. function pipeLoop() {
  7738. currentWrite = Promise.resolve();
  7739. if (shuttingDown === true) {
  7740. return Promise.resolve();
  7741. }
  7742. return writer._readyPromise.then(function () {
  7743. return ReadableStreamDefaultReaderRead(reader).then(function (_ref5) {
  7744. var value = _ref5.value,
  7745. done = _ref5.done;
  7746. if (done === true) {
  7747. return;
  7748. }
  7749. currentWrite = WritableStreamDefaultWriterWrite(writer, value).catch(function () {});
  7750. });
  7751. }).then(pipeLoop);
  7752. }
  7753. isOrBecomesErrored(_this, reader._closedPromise, function (storedError) {
  7754. if (preventAbort === false) {
  7755. shutdownWithAction(function () {
  7756. return WritableStreamAbort(dest, storedError);
  7757. }, true, storedError);
  7758. } else {
  7759. shutdown(true, storedError);
  7760. }
  7761. });
  7762. isOrBecomesErrored(dest, writer._closedPromise, function (storedError) {
  7763. if (preventCancel === false) {
  7764. shutdownWithAction(function () {
  7765. return ReadableStreamCancel(_this, storedError);
  7766. }, true, storedError);
  7767. } else {
  7768. shutdown(true, storedError);
  7769. }
  7770. });
  7771. isOrBecomesClosed(_this, reader._closedPromise, function () {
  7772. if (preventClose === false) {
  7773. shutdownWithAction(function () {
  7774. return WritableStreamDefaultWriterCloseWithErrorPropagation(writer);
  7775. });
  7776. } else {
  7777. shutdown();
  7778. }
  7779. });
  7780. if (WritableStreamCloseQueuedOrInFlight(dest) === true || dest._state === 'closed') {
  7781. var destClosed = new TypeError('the destination writable stream closed before all data could be piped to it');
  7782. if (preventCancel === false) {
  7783. shutdownWithAction(function () {
  7784. return ReadableStreamCancel(_this, destClosed);
  7785. }, true, destClosed);
  7786. } else {
  7787. shutdown(true, destClosed);
  7788. }
  7789. }
  7790. pipeLoop().catch(function (err) {
  7791. currentWrite = Promise.resolve();
  7792. rethrowAssertionErrorRejection(err);
  7793. });
  7794. function waitForWritesToFinish() {
  7795. var oldCurrentWrite = currentWrite;
  7796. return currentWrite.then(function () {
  7797. return oldCurrentWrite !== currentWrite ? waitForWritesToFinish() : undefined;
  7798. });
  7799. }
  7800. function isOrBecomesErrored(stream, promise, action) {
  7801. if (stream._state === 'errored') {
  7802. action(stream._storedError);
  7803. } else {
  7804. promise.catch(action).catch(rethrowAssertionErrorRejection);
  7805. }
  7806. }
  7807. function isOrBecomesClosed(stream, promise, action) {
  7808. if (stream._state === 'closed') {
  7809. action();
  7810. } else {
  7811. promise.then(action).catch(rethrowAssertionErrorRejection);
  7812. }
  7813. }
  7814. function shutdownWithAction(action, originalIsError, originalError) {
  7815. if (shuttingDown === true) {
  7816. return;
  7817. }
  7818. shuttingDown = true;
  7819. if (dest._state === 'writable' && WritableStreamCloseQueuedOrInFlight(dest) === false) {
  7820. waitForWritesToFinish().then(doTheRest);
  7821. } else {
  7822. doTheRest();
  7823. }
  7824. function doTheRest() {
  7825. action().then(function () {
  7826. return finalize(originalIsError, originalError);
  7827. }, function (newError) {
  7828. return finalize(true, newError);
  7829. }).catch(rethrowAssertionErrorRejection);
  7830. }
  7831. }
  7832. function shutdown(isError, error) {
  7833. if (shuttingDown === true) {
  7834. return;
  7835. }
  7836. shuttingDown = true;
  7837. if (dest._state === 'writable' && WritableStreamCloseQueuedOrInFlight(dest) === false) {
  7838. waitForWritesToFinish().then(function () {
  7839. return finalize(isError, error);
  7840. }).catch(rethrowAssertionErrorRejection);
  7841. } else {
  7842. finalize(isError, error);
  7843. }
  7844. }
  7845. function finalize(isError, error) {
  7846. WritableStreamDefaultWriterRelease(writer);
  7847. ReadableStreamReaderGenericRelease(reader);
  7848. if (isError) {
  7849. reject(error);
  7850. } else {
  7851. resolve(undefined);
  7852. }
  7853. }
  7854. });
  7855. }
  7856. }, {
  7857. key: 'tee',
  7858. value: function tee() {
  7859. if (IsReadableStream(this) === false) {
  7860. throw streamBrandCheckException('tee');
  7861. }
  7862. var branches = ReadableStreamTee(this, false);
  7863. return createArrayFromList(branches);
  7864. }
  7865. }, {
  7866. key: 'locked',
  7867. get: function get() {
  7868. if (IsReadableStream(this) === false) {
  7869. throw streamBrandCheckException('locked');
  7870. }
  7871. return IsReadableStreamLocked(this);
  7872. }
  7873. }]);
  7874. return ReadableStream;
  7875. }();
  7876. module.exports = {
  7877. ReadableStream: ReadableStream,
  7878. IsReadableStreamDisturbed: IsReadableStreamDisturbed,
  7879. ReadableStreamDefaultControllerClose: ReadableStreamDefaultControllerClose,
  7880. ReadableStreamDefaultControllerEnqueue: ReadableStreamDefaultControllerEnqueue,
  7881. ReadableStreamDefaultControllerError: ReadableStreamDefaultControllerError,
  7882. ReadableStreamDefaultControllerGetDesiredSize: ReadableStreamDefaultControllerGetDesiredSize
  7883. };
  7884. function AcquireReadableStreamBYOBReader(stream) {
  7885. return new ReadableStreamBYOBReader(stream);
  7886. }
  7887. function AcquireReadableStreamDefaultReader(stream) {
  7888. return new ReadableStreamDefaultReader(stream);
  7889. }
  7890. function IsReadableStream(x) {
  7891. if (!typeIsObject(x)) {
  7892. return false;
  7893. }
  7894. if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) {
  7895. return false;
  7896. }
  7897. return true;
  7898. }
  7899. function IsReadableStreamDisturbed(stream) {
  7900. assert(IsReadableStream(stream) === true, 'IsReadableStreamDisturbed should only be used on known readable streams');
  7901. return stream._disturbed;
  7902. }
  7903. function IsReadableStreamLocked(stream) {
  7904. assert(IsReadableStream(stream) === true, 'IsReadableStreamLocked should only be used on known readable streams');
  7905. if (stream._reader === undefined) {
  7906. return false;
  7907. }
  7908. return true;
  7909. }
  7910. function ReadableStreamTee(stream, cloneForBranch2) {
  7911. assert(IsReadableStream(stream) === true);
  7912. assert(typeof cloneForBranch2 === 'boolean');
  7913. var reader = AcquireReadableStreamDefaultReader(stream);
  7914. var teeState = {
  7915. closedOrErrored: false,
  7916. canceled1: false,
  7917. canceled2: false,
  7918. reason1: undefined,
  7919. reason2: undefined
  7920. };
  7921. teeState.promise = new Promise(function (resolve) {
  7922. teeState._resolve = resolve;
  7923. });
  7924. var pull = create_ReadableStreamTeePullFunction();
  7925. pull._reader = reader;
  7926. pull._teeState = teeState;
  7927. pull._cloneForBranch2 = cloneForBranch2;
  7928. var cancel1 = create_ReadableStreamTeeBranch1CancelFunction();
  7929. cancel1._stream = stream;
  7930. cancel1._teeState = teeState;
  7931. var cancel2 = create_ReadableStreamTeeBranch2CancelFunction();
  7932. cancel2._stream = stream;
  7933. cancel2._teeState = teeState;
  7934. var underlyingSource1 = Object.create(Object.prototype);
  7935. createDataProperty(underlyingSource1, 'pull', pull);
  7936. createDataProperty(underlyingSource1, 'cancel', cancel1);
  7937. var branch1Stream = new ReadableStream(underlyingSource1);
  7938. var underlyingSource2 = Object.create(Object.prototype);
  7939. createDataProperty(underlyingSource2, 'pull', pull);
  7940. createDataProperty(underlyingSource2, 'cancel', cancel2);
  7941. var branch2Stream = new ReadableStream(underlyingSource2);
  7942. pull._branch1 = branch1Stream._readableStreamController;
  7943. pull._branch2 = branch2Stream._readableStreamController;
  7944. reader._closedPromise.catch(function (r) {
  7945. if (teeState.closedOrErrored === true) {
  7946. return;
  7947. }
  7948. ReadableStreamDefaultControllerError(pull._branch1, r);
  7949. ReadableStreamDefaultControllerError(pull._branch2, r);
  7950. teeState.closedOrErrored = true;
  7951. });
  7952. return [branch1Stream, branch2Stream];
  7953. }
  7954. function create_ReadableStreamTeePullFunction() {
  7955. function f() {
  7956. var reader = f._reader,
  7957. branch1 = f._branch1,
  7958. branch2 = f._branch2,
  7959. teeState = f._teeState;
  7960. return ReadableStreamDefaultReaderRead(reader).then(function (result) {
  7961. assert(typeIsObject(result));
  7962. var value = result.value;
  7963. var done = result.done;
  7964. assert(typeof done === 'boolean');
  7965. if (done === true && teeState.closedOrErrored === false) {
  7966. if (teeState.canceled1 === false) {
  7967. ReadableStreamDefaultControllerClose(branch1);
  7968. }
  7969. if (teeState.canceled2 === false) {
  7970. ReadableStreamDefaultControllerClose(branch2);
  7971. }
  7972. teeState.closedOrErrored = true;
  7973. }
  7974. if (teeState.closedOrErrored === true) {
  7975. return;
  7976. }
  7977. var value1 = value;
  7978. var value2 = value;
  7979. if (teeState.canceled1 === false) {
  7980. ReadableStreamDefaultControllerEnqueue(branch1, value1);
  7981. }
  7982. if (teeState.canceled2 === false) {
  7983. ReadableStreamDefaultControllerEnqueue(branch2, value2);
  7984. }
  7985. });
  7986. }
  7987. return f;
  7988. }
  7989. function create_ReadableStreamTeeBranch1CancelFunction() {
  7990. function f(reason) {
  7991. var stream = f._stream,
  7992. teeState = f._teeState;
  7993. teeState.canceled1 = true;
  7994. teeState.reason1 = reason;
  7995. if (teeState.canceled2 === true) {
  7996. var compositeReason = createArrayFromList([teeState.reason1, teeState.reason2]);
  7997. var cancelResult = ReadableStreamCancel(stream, compositeReason);
  7998. teeState._resolve(cancelResult);
  7999. }
  8000. return teeState.promise;
  8001. }
  8002. return f;
  8003. }
  8004. function create_ReadableStreamTeeBranch2CancelFunction() {
  8005. function f(reason) {
  8006. var stream = f._stream,
  8007. teeState = f._teeState;
  8008. teeState.canceled2 = true;
  8009. teeState.reason2 = reason;
  8010. if (teeState.canceled1 === true) {
  8011. var compositeReason = createArrayFromList([teeState.reason1, teeState.reason2]);
  8012. var cancelResult = ReadableStreamCancel(stream, compositeReason);
  8013. teeState._resolve(cancelResult);
  8014. }
  8015. return teeState.promise;
  8016. }
  8017. return f;
  8018. }
  8019. function ReadableStreamAddReadIntoRequest(stream) {
  8020. assert(IsReadableStreamBYOBReader(stream._reader) === true);
  8021. assert(stream._state === 'readable' || stream._state === 'closed');
  8022. var promise = new Promise(function (resolve, reject) {
  8023. var readIntoRequest = {
  8024. _resolve: resolve,
  8025. _reject: reject
  8026. };
  8027. stream._reader._readIntoRequests.push(readIntoRequest);
  8028. });
  8029. return promise;
  8030. }
  8031. function ReadableStreamAddReadRequest(stream) {
  8032. assert(IsReadableStreamDefaultReader(stream._reader) === true);
  8033. assert(stream._state === 'readable');
  8034. var promise = new Promise(function (resolve, reject) {
  8035. var readRequest = {
  8036. _resolve: resolve,
  8037. _reject: reject
  8038. };
  8039. stream._reader._readRequests.push(readRequest);
  8040. });
  8041. return promise;
  8042. }
  8043. function ReadableStreamCancel(stream, reason) {
  8044. stream._disturbed = true;
  8045. if (stream._state === 'closed') {
  8046. return Promise.resolve(undefined);
  8047. }
  8048. if (stream._state === 'errored') {
  8049. return Promise.reject(stream._storedError);
  8050. }
  8051. ReadableStreamClose(stream);
  8052. var sourceCancelPromise = stream._readableStreamController.__cancelSteps(reason);
  8053. return sourceCancelPromise.then(function () {
  8054. return undefined;
  8055. });
  8056. }
  8057. function ReadableStreamClose(stream) {
  8058. assert(stream._state === 'readable');
  8059. stream._state = 'closed';
  8060. var reader = stream._reader;
  8061. if (reader === undefined) {
  8062. return undefined;
  8063. }
  8064. if (IsReadableStreamDefaultReader(reader) === true) {
  8065. for (var i = 0; i < reader._readRequests.length; i++) {
  8066. var _resolve = reader._readRequests[i]._resolve;
  8067. _resolve(CreateIterResultObject(undefined, true));
  8068. }
  8069. reader._readRequests = [];
  8070. }
  8071. defaultReaderClosedPromiseResolve(reader);
  8072. return undefined;
  8073. }
  8074. function ReadableStreamError(stream, e) {
  8075. assert(IsReadableStream(stream) === true, 'stream must be ReadableStream');
  8076. assert(stream._state === 'readable', 'state must be readable');
  8077. stream._state = 'errored';
  8078. stream._storedError = e;
  8079. var reader = stream._reader;
  8080. if (reader === undefined) {
  8081. return undefined;
  8082. }
  8083. if (IsReadableStreamDefaultReader(reader) === true) {
  8084. for (var i = 0; i < reader._readRequests.length; i++) {
  8085. var readRequest = reader._readRequests[i];
  8086. readRequest._reject(e);
  8087. }
  8088. reader._readRequests = [];
  8089. } else {
  8090. assert(IsReadableStreamBYOBReader(reader), 'reader must be ReadableStreamBYOBReader');
  8091. for (var _i = 0; _i < reader._readIntoRequests.length; _i++) {
  8092. var readIntoRequest = reader._readIntoRequests[_i];
  8093. readIntoRequest._reject(e);
  8094. }
  8095. reader._readIntoRequests = [];
  8096. }
  8097. defaultReaderClosedPromiseReject(reader, e);
  8098. reader._closedPromise.catch(function () {});
  8099. }
  8100. function ReadableStreamFulfillReadIntoRequest(stream, chunk, done) {
  8101. var reader = stream._reader;
  8102. assert(reader._readIntoRequests.length > 0);
  8103. var readIntoRequest = reader._readIntoRequests.shift();
  8104. readIntoRequest._resolve(CreateIterResultObject(chunk, done));
  8105. }
  8106. function ReadableStreamFulfillReadRequest(stream, chunk, done) {
  8107. var reader = stream._reader;
  8108. assert(reader._readRequests.length > 0);
  8109. var readRequest = reader._readRequests.shift();
  8110. readRequest._resolve(CreateIterResultObject(chunk, done));
  8111. }
  8112. function ReadableStreamGetNumReadIntoRequests(stream) {
  8113. return stream._reader._readIntoRequests.length;
  8114. }
  8115. function ReadableStreamGetNumReadRequests(stream) {
  8116. return stream._reader._readRequests.length;
  8117. }
  8118. function ReadableStreamHasBYOBReader(stream) {
  8119. var reader = stream._reader;
  8120. if (reader === undefined) {
  8121. return false;
  8122. }
  8123. if (IsReadableStreamBYOBReader(reader) === false) {
  8124. return false;
  8125. }
  8126. return true;
  8127. }
  8128. function ReadableStreamHasDefaultReader(stream) {
  8129. var reader = stream._reader;
  8130. if (reader === undefined) {
  8131. return false;
  8132. }
  8133. if (IsReadableStreamDefaultReader(reader) === false) {
  8134. return false;
  8135. }
  8136. return true;
  8137. }
  8138. var ReadableStreamDefaultReader = function () {
  8139. function ReadableStreamDefaultReader(stream) {
  8140. _classCallCheck(this, ReadableStreamDefaultReader);
  8141. if (IsReadableStream(stream) === false) {
  8142. throw new TypeError('ReadableStreamDefaultReader can only be constructed with a ReadableStream instance');
  8143. }
  8144. if (IsReadableStreamLocked(stream) === true) {
  8145. throw new TypeError('This stream has already been locked for exclusive reading by another reader');
  8146. }
  8147. ReadableStreamReaderGenericInitialize(this, stream);
  8148. this._readRequests = [];
  8149. }
  8150. _createClass(ReadableStreamDefaultReader, [{
  8151. key: 'cancel',
  8152. value: function cancel(reason) {
  8153. if (IsReadableStreamDefaultReader(this) === false) {
  8154. return Promise.reject(defaultReaderBrandCheckException('cancel'));
  8155. }
  8156. if (this._ownerReadableStream === undefined) {
  8157. return Promise.reject(readerLockException('cancel'));
  8158. }
  8159. return ReadableStreamReaderGenericCancel(this, reason);
  8160. }
  8161. }, {
  8162. key: 'read',
  8163. value: function read() {
  8164. if (IsReadableStreamDefaultReader(this) === false) {
  8165. return Promise.reject(defaultReaderBrandCheckException('read'));
  8166. }
  8167. if (this._ownerReadableStream === undefined) {
  8168. return Promise.reject(readerLockException('read from'));
  8169. }
  8170. return ReadableStreamDefaultReaderRead(this);
  8171. }
  8172. }, {
  8173. key: 'releaseLock',
  8174. value: function releaseLock() {
  8175. if (IsReadableStreamDefaultReader(this) === false) {
  8176. throw defaultReaderBrandCheckException('releaseLock');
  8177. }
  8178. if (this._ownerReadableStream === undefined) {
  8179. return;
  8180. }
  8181. if (this._readRequests.length > 0) {
  8182. throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled');
  8183. }
  8184. ReadableStreamReaderGenericRelease(this);
  8185. }
  8186. }, {
  8187. key: 'closed',
  8188. get: function get() {
  8189. if (IsReadableStreamDefaultReader(this) === false) {
  8190. return Promise.reject(defaultReaderBrandCheckException('closed'));
  8191. }
  8192. return this._closedPromise;
  8193. }
  8194. }]);
  8195. return ReadableStreamDefaultReader;
  8196. }();
  8197. var ReadableStreamBYOBReader = function () {
  8198. function ReadableStreamBYOBReader(stream) {
  8199. _classCallCheck(this, ReadableStreamBYOBReader);
  8200. if (!IsReadableStream(stream)) {
  8201. throw new TypeError('ReadableStreamBYOBReader can only be constructed with a ReadableStream instance given a ' + 'byte source');
  8202. }
  8203. if (IsReadableByteStreamController(stream._readableStreamController) === false) {
  8204. throw new TypeError('Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte ' + 'source');
  8205. }
  8206. if (IsReadableStreamLocked(stream)) {
  8207. throw new TypeError('This stream has already been locked for exclusive reading by another reader');
  8208. }
  8209. ReadableStreamReaderGenericInitialize(this, stream);
  8210. this._readIntoRequests = [];
  8211. }
  8212. _createClass(ReadableStreamBYOBReader, [{
  8213. key: 'cancel',
  8214. value: function cancel(reason) {
  8215. if (!IsReadableStreamBYOBReader(this)) {
  8216. return Promise.reject(byobReaderBrandCheckException('cancel'));
  8217. }
  8218. if (this._ownerReadableStream === undefined) {
  8219. return Promise.reject(readerLockException('cancel'));
  8220. }
  8221. return ReadableStreamReaderGenericCancel(this, reason);
  8222. }
  8223. }, {
  8224. key: 'read',
  8225. value: function read(view) {
  8226. if (!IsReadableStreamBYOBReader(this)) {
  8227. return Promise.reject(byobReaderBrandCheckException('read'));
  8228. }
  8229. if (this._ownerReadableStream === undefined) {
  8230. return Promise.reject(readerLockException('read from'));
  8231. }
  8232. if (!ArrayBuffer.isView(view)) {
  8233. return Promise.reject(new TypeError('view must be an array buffer view'));
  8234. }
  8235. if (view.byteLength === 0) {
  8236. return Promise.reject(new TypeError('view must have non-zero byteLength'));
  8237. }
  8238. return ReadableStreamBYOBReaderRead(this, view);
  8239. }
  8240. }, {
  8241. key: 'releaseLock',
  8242. value: function releaseLock() {
  8243. if (!IsReadableStreamBYOBReader(this)) {
  8244. throw byobReaderBrandCheckException('releaseLock');
  8245. }
  8246. if (this._ownerReadableStream === undefined) {
  8247. return;
  8248. }
  8249. if (this._readIntoRequests.length > 0) {
  8250. throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled');
  8251. }
  8252. ReadableStreamReaderGenericRelease(this);
  8253. }
  8254. }, {
  8255. key: 'closed',
  8256. get: function get() {
  8257. if (!IsReadableStreamBYOBReader(this)) {
  8258. return Promise.reject(byobReaderBrandCheckException('closed'));
  8259. }
  8260. return this._closedPromise;
  8261. }
  8262. }]);
  8263. return ReadableStreamBYOBReader;
  8264. }();
  8265. function IsReadableStreamBYOBReader(x) {
  8266. if (!typeIsObject(x)) {
  8267. return false;
  8268. }
  8269. if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) {
  8270. return false;
  8271. }
  8272. return true;
  8273. }
  8274. function IsReadableStreamDefaultReader(x) {
  8275. if (!typeIsObject(x)) {
  8276. return false;
  8277. }
  8278. if (!Object.prototype.hasOwnProperty.call(x, '_readRequests')) {
  8279. return false;
  8280. }
  8281. return true;
  8282. }
  8283. function ReadableStreamReaderGenericInitialize(reader, stream) {
  8284. reader._ownerReadableStream = stream;
  8285. stream._reader = reader;
  8286. if (stream._state === 'readable') {
  8287. defaultReaderClosedPromiseInitialize(reader);
  8288. } else if (stream._state === 'closed') {
  8289. defaultReaderClosedPromiseInitializeAsResolved(reader);
  8290. } else {
  8291. assert(stream._state === 'errored', 'state must be errored');
  8292. defaultReaderClosedPromiseInitializeAsRejected(reader, stream._storedError);
  8293. reader._closedPromise.catch(function () {});
  8294. }
  8295. }
  8296. function ReadableStreamReaderGenericCancel(reader, reason) {
  8297. var stream = reader._ownerReadableStream;
  8298. assert(stream !== undefined);
  8299. return ReadableStreamCancel(stream, reason);
  8300. }
  8301. function ReadableStreamReaderGenericRelease(reader) {
  8302. assert(reader._ownerReadableStream !== undefined);
  8303. assert(reader._ownerReadableStream._reader === reader);
  8304. if (reader._ownerReadableStream._state === 'readable') {
  8305. defaultReaderClosedPromiseReject(reader, new TypeError('Reader was released and can no longer be used to monitor the stream\'s closedness'));
  8306. } else {
  8307. defaultReaderClosedPromiseResetToRejected(reader, new TypeError('Reader was released and can no longer be used to monitor the stream\'s closedness'));
  8308. }
  8309. reader._closedPromise.catch(function () {});
  8310. reader._ownerReadableStream._reader = undefined;
  8311. reader._ownerReadableStream = undefined;
  8312. }
  8313. function ReadableStreamBYOBReaderRead(reader, view) {
  8314. var stream = reader._ownerReadableStream;
  8315. assert(stream !== undefined);
  8316. stream._disturbed = true;
  8317. if (stream._state === 'errored') {
  8318. return Promise.reject(stream._storedError);
  8319. }
  8320. return ReadableByteStreamControllerPullInto(stream._readableStreamController, view);
  8321. }
  8322. function ReadableStreamDefaultReaderRead(reader) {
  8323. var stream = reader._ownerReadableStream;
  8324. assert(stream !== undefined);
  8325. stream._disturbed = true;
  8326. if (stream._state === 'closed') {
  8327. return Promise.resolve(CreateIterResultObject(undefined, true));
  8328. }
  8329. if (stream._state === 'errored') {
  8330. return Promise.reject(stream._storedError);
  8331. }
  8332. assert(stream._state === 'readable');
  8333. return stream._readableStreamController.__pullSteps();
  8334. }
  8335. var ReadableStreamDefaultController = function () {
  8336. function ReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark) {
  8337. _classCallCheck(this, ReadableStreamDefaultController);
  8338. if (IsReadableStream(stream) === false) {
  8339. throw new TypeError('ReadableStreamDefaultController can only be constructed with a ReadableStream instance');
  8340. }
  8341. if (stream._readableStreamController !== undefined) {
  8342. throw new TypeError('ReadableStreamDefaultController instances can only be created by the ReadableStream constructor');
  8343. }
  8344. this._controlledReadableStream = stream;
  8345. this._underlyingSource = underlyingSource;
  8346. this._queue = undefined;
  8347. this._queueTotalSize = undefined;
  8348. ResetQueue(this);
  8349. this._started = false;
  8350. this._closeRequested = false;
  8351. this._pullAgain = false;
  8352. this._pulling = false;
  8353. var normalizedStrategy = ValidateAndNormalizeQueuingStrategy(size, highWaterMark);
  8354. this._strategySize = normalizedStrategy.size;
  8355. this._strategyHWM = normalizedStrategy.highWaterMark;
  8356. var controller = this;
  8357. var startResult = InvokeOrNoop(underlyingSource, 'start', [this]);
  8358. Promise.resolve(startResult).then(function () {
  8359. controller._started = true;
  8360. assert(controller._pulling === false);
  8361. assert(controller._pullAgain === false);
  8362. ReadableStreamDefaultControllerCallPullIfNeeded(controller);
  8363. }, function (r) {
  8364. ReadableStreamDefaultControllerErrorIfNeeded(controller, r);
  8365. }).catch(rethrowAssertionErrorRejection);
  8366. }
  8367. _createClass(ReadableStreamDefaultController, [{
  8368. key: 'close',
  8369. value: function close() {
  8370. if (IsReadableStreamDefaultController(this) === false) {
  8371. throw defaultControllerBrandCheckException('close');
  8372. }
  8373. if (this._closeRequested === true) {
  8374. throw new TypeError('The stream has already been closed; do not close it again!');
  8375. }
  8376. var state = this._controlledReadableStream._state;
  8377. if (state !== 'readable') {
  8378. throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be closed');
  8379. }
  8380. ReadableStreamDefaultControllerClose(this);
  8381. }
  8382. }, {
  8383. key: 'enqueue',
  8384. value: function enqueue(chunk) {
  8385. if (IsReadableStreamDefaultController(this) === false) {
  8386. throw defaultControllerBrandCheckException('enqueue');
  8387. }
  8388. if (this._closeRequested === true) {
  8389. throw new TypeError('stream is closed or draining');
  8390. }
  8391. var state = this._controlledReadableStream._state;
  8392. if (state !== 'readable') {
  8393. throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be enqueued to');
  8394. }
  8395. return ReadableStreamDefaultControllerEnqueue(this, chunk);
  8396. }
  8397. }, {
  8398. key: 'error',
  8399. value: function error(e) {
  8400. if (IsReadableStreamDefaultController(this) === false) {
  8401. throw defaultControllerBrandCheckException('error');
  8402. }
  8403. var stream = this._controlledReadableStream;
  8404. if (stream._state !== 'readable') {
  8405. throw new TypeError('The stream is ' + stream._state + ' and so cannot be errored');
  8406. }
  8407. ReadableStreamDefaultControllerError(this, e);
  8408. }
  8409. }, {
  8410. key: '__cancelSteps',
  8411. value: function __cancelSteps(reason) {
  8412. ResetQueue(this);
  8413. return PromiseInvokeOrNoop(this._underlyingSource, 'cancel', [reason]);
  8414. }
  8415. }, {
  8416. key: '__pullSteps',
  8417. value: function __pullSteps() {
  8418. var stream = this._controlledReadableStream;
  8419. if (this._queue.length > 0) {
  8420. var chunk = DequeueValue(this);
  8421. if (this._closeRequested === true && this._queue.length === 0) {
  8422. ReadableStreamClose(stream);
  8423. } else {
  8424. ReadableStreamDefaultControllerCallPullIfNeeded(this);
  8425. }
  8426. return Promise.resolve(CreateIterResultObject(chunk, false));
  8427. }
  8428. var pendingPromise = ReadableStreamAddReadRequest(stream);
  8429. ReadableStreamDefaultControllerCallPullIfNeeded(this);
  8430. return pendingPromise;
  8431. }
  8432. }, {
  8433. key: 'desiredSize',
  8434. get: function get() {
  8435. if (IsReadableStreamDefaultController(this) === false) {
  8436. throw defaultControllerBrandCheckException('desiredSize');
  8437. }
  8438. return ReadableStreamDefaultControllerGetDesiredSize(this);
  8439. }
  8440. }]);
  8441. return ReadableStreamDefaultController;
  8442. }();
  8443. function IsReadableStreamDefaultController(x) {
  8444. if (!typeIsObject(x)) {
  8445. return false;
  8446. }
  8447. if (!Object.prototype.hasOwnProperty.call(x, '_underlyingSource')) {
  8448. return false;
  8449. }
  8450. return true;
  8451. }
  8452. function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
  8453. var shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
  8454. if (shouldPull === false) {
  8455. return undefined;
  8456. }
  8457. if (controller._pulling === true) {
  8458. controller._pullAgain = true;
  8459. return undefined;
  8460. }
  8461. assert(controller._pullAgain === false);
  8462. controller._pulling = true;
  8463. var pullPromise = PromiseInvokeOrNoop(controller._underlyingSource, 'pull', [controller]);
  8464. pullPromise.then(function () {
  8465. controller._pulling = false;
  8466. if (controller._pullAgain === true) {
  8467. controller._pullAgain = false;
  8468. return ReadableStreamDefaultControllerCallPullIfNeeded(controller);
  8469. }
  8470. return undefined;
  8471. }, function (e) {
  8472. ReadableStreamDefaultControllerErrorIfNeeded(controller, e);
  8473. }).catch(rethrowAssertionErrorRejection);
  8474. return undefined;
  8475. }
  8476. function ReadableStreamDefaultControllerShouldCallPull(controller) {
  8477. var stream = controller._controlledReadableStream;
  8478. if (stream._state === 'closed' || stream._state === 'errored') {
  8479. return false;
  8480. }
  8481. if (controller._closeRequested === true) {
  8482. return false;
  8483. }
  8484. if (controller._started === false) {
  8485. return false;
  8486. }
  8487. if (IsReadableStreamLocked(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) {
  8488. return true;
  8489. }
  8490. var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller);
  8491. if (desiredSize > 0) {
  8492. return true;
  8493. }
  8494. return false;
  8495. }
  8496. function ReadableStreamDefaultControllerClose(controller) {
  8497. var stream = controller._controlledReadableStream;
  8498. assert(controller._closeRequested === false);
  8499. assert(stream._state === 'readable');
  8500. controller._closeRequested = true;
  8501. if (controller._queue.length === 0) {
  8502. ReadableStreamClose(stream);
  8503. }
  8504. }
  8505. function ReadableStreamDefaultControllerEnqueue(controller, chunk) {
  8506. var stream = controller._controlledReadableStream;
  8507. assert(controller._closeRequested === false);
  8508. assert(stream._state === 'readable');
  8509. if (IsReadableStreamLocked(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) {
  8510. ReadableStreamFulfillReadRequest(stream, chunk, false);
  8511. } else {
  8512. var chunkSize = 1;
  8513. if (controller._strategySize !== undefined) {
  8514. var strategySize = controller._strategySize;
  8515. try {
  8516. chunkSize = strategySize(chunk);
  8517. } catch (chunkSizeE) {
  8518. ReadableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE);
  8519. throw chunkSizeE;
  8520. }
  8521. }
  8522. try {
  8523. EnqueueValueWithSize(controller, chunk, chunkSize);
  8524. } catch (enqueueE) {
  8525. ReadableStreamDefaultControllerErrorIfNeeded(controller, enqueueE);
  8526. throw enqueueE;
  8527. }
  8528. }
  8529. ReadableStreamDefaultControllerCallPullIfNeeded(controller);
  8530. return undefined;
  8531. }
  8532. function ReadableStreamDefaultControllerError(controller, e) {
  8533. var stream = controller._controlledReadableStream;
  8534. assert(stream._state === 'readable');
  8535. ResetQueue(controller);
  8536. ReadableStreamError(stream, e);
  8537. }
  8538. function ReadableStreamDefaultControllerErrorIfNeeded(controller, e) {
  8539. if (controller._controlledReadableStream._state === 'readable') {
  8540. ReadableStreamDefaultControllerError(controller, e);
  8541. }
  8542. }
  8543. function ReadableStreamDefaultControllerGetDesiredSize(controller) {
  8544. var stream = controller._controlledReadableStream;
  8545. var state = stream._state;
  8546. if (state === 'errored') {
  8547. return null;
  8548. }
  8549. if (state === 'closed') {
  8550. return 0;
  8551. }
  8552. return controller._strategyHWM - controller._queueTotalSize;
  8553. }
  8554. var ReadableStreamBYOBRequest = function () {
  8555. function ReadableStreamBYOBRequest(controller, view) {
  8556. _classCallCheck(this, ReadableStreamBYOBRequest);
  8557. this._associatedReadableByteStreamController = controller;
  8558. this._view = view;
  8559. }
  8560. _createClass(ReadableStreamBYOBRequest, [{
  8561. key: 'respond',
  8562. value: function respond(bytesWritten) {
  8563. if (IsReadableStreamBYOBRequest(this) === false) {
  8564. throw byobRequestBrandCheckException('respond');
  8565. }
  8566. if (this._associatedReadableByteStreamController === undefined) {
  8567. throw new TypeError('This BYOB request has been invalidated');
  8568. }
  8569. ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
  8570. }
  8571. }, {
  8572. key: 'respondWithNewView',
  8573. value: function respondWithNewView(view) {
  8574. if (IsReadableStreamBYOBRequest(this) === false) {
  8575. throw byobRequestBrandCheckException('respond');
  8576. }
  8577. if (this._associatedReadableByteStreamController === undefined) {
  8578. throw new TypeError('This BYOB request has been invalidated');
  8579. }
  8580. if (!ArrayBuffer.isView(view)) {
  8581. throw new TypeError('You can only respond with array buffer views');
  8582. }
  8583. ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
  8584. }
  8585. }, {
  8586. key: 'view',
  8587. get: function get() {
  8588. return this._view;
  8589. }
  8590. }]);
  8591. return ReadableStreamBYOBRequest;
  8592. }();
  8593. var ReadableByteStreamController = function () {
  8594. function ReadableByteStreamController(stream, underlyingByteSource, highWaterMark) {
  8595. _classCallCheck(this, ReadableByteStreamController);
  8596. if (IsReadableStream(stream) === false) {
  8597. throw new TypeError('ReadableByteStreamController can only be constructed with a ReadableStream instance given ' + 'a byte source');
  8598. }
  8599. if (stream._readableStreamController !== undefined) {
  8600. throw new TypeError('ReadableByteStreamController instances can only be created by the ReadableStream constructor given a byte ' + 'source');
  8601. }
  8602. this._controlledReadableStream = stream;
  8603. this._underlyingByteSource = underlyingByteSource;
  8604. this._pullAgain = false;
  8605. this._pulling = false;
  8606. ReadableByteStreamControllerClearPendingPullIntos(this);
  8607. this._queue = this._queueTotalSize = undefined;
  8608. ResetQueue(this);
  8609. this._closeRequested = false;
  8610. this._started = false;
  8611. this._strategyHWM = ValidateAndNormalizeHighWaterMark(highWaterMark);
  8612. var autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
  8613. if (autoAllocateChunkSize !== undefined) {
  8614. if (Number.isInteger(autoAllocateChunkSize) === false || autoAllocateChunkSize <= 0) {
  8615. throw new RangeError('autoAllocateChunkSize must be a positive integer');
  8616. }
  8617. }
  8618. this._autoAllocateChunkSize = autoAllocateChunkSize;
  8619. this._pendingPullIntos = [];
  8620. var controller = this;
  8621. var startResult = InvokeOrNoop(underlyingByteSource, 'start', [this]);
  8622. Promise.resolve(startResult).then(function () {
  8623. controller._started = true;
  8624. assert(controller._pulling === false);
  8625. assert(controller._pullAgain === false);
  8626. ReadableByteStreamControllerCallPullIfNeeded(controller);
  8627. }, function (r) {
  8628. if (stream._state === 'readable') {
  8629. ReadableByteStreamControllerError(controller, r);
  8630. }
  8631. }).catch(rethrowAssertionErrorRejection);
  8632. }
  8633. _createClass(ReadableByteStreamController, [{
  8634. key: 'close',
  8635. value: function close() {
  8636. if (IsReadableByteStreamController(this) === false) {
  8637. throw byteStreamControllerBrandCheckException('close');
  8638. }
  8639. if (this._closeRequested === true) {
  8640. throw new TypeError('The stream has already been closed; do not close it again!');
  8641. }
  8642. var state = this._controlledReadableStream._state;
  8643. if (state !== 'readable') {
  8644. throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be closed');
  8645. }
  8646. ReadableByteStreamControllerClose(this);
  8647. }
  8648. }, {
  8649. key: 'enqueue',
  8650. value: function enqueue(chunk) {
  8651. if (IsReadableByteStreamController(this) === false) {
  8652. throw byteStreamControllerBrandCheckException('enqueue');
  8653. }
  8654. if (this._closeRequested === true) {
  8655. throw new TypeError('stream is closed or draining');
  8656. }
  8657. var state = this._controlledReadableStream._state;
  8658. if (state !== 'readable') {
  8659. throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be enqueued to');
  8660. }
  8661. if (!ArrayBuffer.isView(chunk)) {
  8662. throw new TypeError('You can only enqueue array buffer views when using a ReadableByteStreamController');
  8663. }
  8664. ReadableByteStreamControllerEnqueue(this, chunk);
  8665. }
  8666. }, {
  8667. key: 'error',
  8668. value: function error(e) {
  8669. if (IsReadableByteStreamController(this) === false) {
  8670. throw byteStreamControllerBrandCheckException('error');
  8671. }
  8672. var stream = this._controlledReadableStream;
  8673. if (stream._state !== 'readable') {
  8674. throw new TypeError('The stream is ' + stream._state + ' and so cannot be errored');
  8675. }
  8676. ReadableByteStreamControllerError(this, e);
  8677. }
  8678. }, {
  8679. key: '__cancelSteps',
  8680. value: function __cancelSteps(reason) {
  8681. if (this._pendingPullIntos.length > 0) {
  8682. var firstDescriptor = this._pendingPullIntos[0];
  8683. firstDescriptor.bytesFilled = 0;
  8684. }
  8685. ResetQueue(this);
  8686. return PromiseInvokeOrNoop(this._underlyingByteSource, 'cancel', [reason]);
  8687. }
  8688. }, {
  8689. key: '__pullSteps',
  8690. value: function __pullSteps() {
  8691. var stream = this._controlledReadableStream;
  8692. assert(ReadableStreamHasDefaultReader(stream) === true);
  8693. if (this._queueTotalSize > 0) {
  8694. assert(ReadableStreamGetNumReadRequests(stream) === 0);
  8695. var entry = this._queue.shift();
  8696. this._queueTotalSize -= entry.byteLength;
  8697. ReadableByteStreamControllerHandleQueueDrain(this);
  8698. var view = void 0;
  8699. try {
  8700. view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
  8701. } catch (viewE) {
  8702. return Promise.reject(viewE);
  8703. }
  8704. return Promise.resolve(CreateIterResultObject(view, false));
  8705. }
  8706. var autoAllocateChunkSize = this._autoAllocateChunkSize;
  8707. if (autoAllocateChunkSize !== undefined) {
  8708. var buffer = void 0;
  8709. try {
  8710. buffer = new ArrayBuffer(autoAllocateChunkSize);
  8711. } catch (bufferE) {
  8712. return Promise.reject(bufferE);
  8713. }
  8714. var pullIntoDescriptor = {
  8715. buffer: buffer,
  8716. byteOffset: 0,
  8717. byteLength: autoAllocateChunkSize,
  8718. bytesFilled: 0,
  8719. elementSize: 1,
  8720. ctor: Uint8Array,
  8721. readerType: 'default'
  8722. };
  8723. this._pendingPullIntos.push(pullIntoDescriptor);
  8724. }
  8725. var promise = ReadableStreamAddReadRequest(stream);
  8726. ReadableByteStreamControllerCallPullIfNeeded(this);
  8727. return promise;
  8728. }
  8729. }, {
  8730. key: 'byobRequest',
  8731. get: function get() {
  8732. if (IsReadableByteStreamController(this) === false) {
  8733. throw byteStreamControllerBrandCheckException('byobRequest');
  8734. }
  8735. if (this._byobRequest === undefined && this._pendingPullIntos.length > 0) {
  8736. var firstDescriptor = this._pendingPullIntos[0];
  8737. var view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
  8738. this._byobRequest = new ReadableStreamBYOBRequest(this, view);
  8739. }
  8740. return this._byobRequest;
  8741. }
  8742. }, {
  8743. key: 'desiredSize',
  8744. get: function get() {
  8745. if (IsReadableByteStreamController(this) === false) {
  8746. throw byteStreamControllerBrandCheckException('desiredSize');
  8747. }
  8748. return ReadableByteStreamControllerGetDesiredSize(this);
  8749. }
  8750. }]);
  8751. return ReadableByteStreamController;
  8752. }();
  8753. function IsReadableByteStreamController(x) {
  8754. if (!typeIsObject(x)) {
  8755. return false;
  8756. }
  8757. if (!Object.prototype.hasOwnProperty.call(x, '_underlyingByteSource')) {
  8758. return false;
  8759. }
  8760. return true;
  8761. }
  8762. function IsReadableStreamBYOBRequest(x) {
  8763. if (!typeIsObject(x)) {
  8764. return false;
  8765. }
  8766. if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) {
  8767. return false;
  8768. }
  8769. return true;
  8770. }
  8771. function ReadableByteStreamControllerCallPullIfNeeded(controller) {
  8772. var shouldPull = ReadableByteStreamControllerShouldCallPull(controller);
  8773. if (shouldPull === false) {
  8774. return undefined;
  8775. }
  8776. if (controller._pulling === true) {
  8777. controller._pullAgain = true;
  8778. return undefined;
  8779. }
  8780. assert(controller._pullAgain === false);
  8781. controller._pulling = true;
  8782. var pullPromise = PromiseInvokeOrNoop(controller._underlyingByteSource, 'pull', [controller]);
  8783. pullPromise.then(function () {
  8784. controller._pulling = false;
  8785. if (controller._pullAgain === true) {
  8786. controller._pullAgain = false;
  8787. ReadableByteStreamControllerCallPullIfNeeded(controller);
  8788. }
  8789. }, function (e) {
  8790. if (controller._controlledReadableStream._state === 'readable') {
  8791. ReadableByteStreamControllerError(controller, e);
  8792. }
  8793. }).catch(rethrowAssertionErrorRejection);
  8794. return undefined;
  8795. }
  8796. function ReadableByteStreamControllerClearPendingPullIntos(controller) {
  8797. ReadableByteStreamControllerInvalidateBYOBRequest(controller);
  8798. controller._pendingPullIntos = [];
  8799. }
  8800. function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) {
  8801. assert(stream._state !== 'errored', 'state must not be errored');
  8802. var done = false;
  8803. if (stream._state === 'closed') {
  8804. assert(pullIntoDescriptor.bytesFilled === 0);
  8805. done = true;
  8806. }
  8807. var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);
  8808. if (pullIntoDescriptor.readerType === 'default') {
  8809. ReadableStreamFulfillReadRequest(stream, filledView, done);
  8810. } else {
  8811. assert(pullIntoDescriptor.readerType === 'byob');
  8812. ReadableStreamFulfillReadIntoRequest(stream, filledView, done);
  8813. }
  8814. }
  8815. function ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) {
  8816. var bytesFilled = pullIntoDescriptor.bytesFilled;
  8817. var elementSize = pullIntoDescriptor.elementSize;
  8818. assert(bytesFilled <= pullIntoDescriptor.byteLength);
  8819. assert(bytesFilled % elementSize === 0);
  8820. return new pullIntoDescriptor.ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize);
  8821. }
  8822. function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) {
  8823. controller._queue.push({
  8824. buffer: buffer,
  8825. byteOffset: byteOffset,
  8826. byteLength: byteLength
  8827. });
  8828. controller._queueTotalSize += byteLength;
  8829. }
  8830. function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) {
  8831. var elementSize = pullIntoDescriptor.elementSize;
  8832. var currentAlignedBytes = pullIntoDescriptor.bytesFilled - pullIntoDescriptor.bytesFilled % elementSize;
  8833. var maxBytesToCopy = Math.min(controller._queueTotalSize, pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled);
  8834. var maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;
  8835. var maxAlignedBytes = maxBytesFilled - maxBytesFilled % elementSize;
  8836. var totalBytesToCopyRemaining = maxBytesToCopy;
  8837. var ready = false;
  8838. if (maxAlignedBytes > currentAlignedBytes) {
  8839. totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;
  8840. ready = true;
  8841. }
  8842. var queue = controller._queue;
  8843. while (totalBytesToCopyRemaining > 0) {
  8844. var headOfQueue = queue[0];
  8845. var bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength);
  8846. var destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
  8847. ArrayBufferCopy(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy);
  8848. if (headOfQueue.byteLength === bytesToCopy) {
  8849. queue.shift();
  8850. } else {
  8851. headOfQueue.byteOffset += bytesToCopy;
  8852. headOfQueue.byteLength -= bytesToCopy;
  8853. }
  8854. controller._queueTotalSize -= bytesToCopy;
  8855. ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor);
  8856. totalBytesToCopyRemaining -= bytesToCopy;
  8857. }
  8858. if (ready === false) {
  8859. assert(controller._queueTotalSize === 0, 'queue must be empty');
  8860. assert(pullIntoDescriptor.bytesFilled > 0);
  8861. assert(pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize);
  8862. }
  8863. return ready;
  8864. }
  8865. function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {
  8866. assert(controller._pendingPullIntos.length === 0 || controller._pendingPullIntos[0] === pullIntoDescriptor);
  8867. ReadableByteStreamControllerInvalidateBYOBRequest(controller);
  8868. pullIntoDescriptor.bytesFilled += size;
  8869. }
  8870. function ReadableByteStreamControllerHandleQueueDrain(controller) {
  8871. assert(controller._controlledReadableStream._state === 'readable');
  8872. if (controller._queueTotalSize === 0 && controller._closeRequested === true) {
  8873. ReadableStreamClose(controller._controlledReadableStream);
  8874. } else {
  8875. ReadableByteStreamControllerCallPullIfNeeded(controller);
  8876. }
  8877. }
  8878. function ReadableByteStreamControllerInvalidateBYOBRequest(controller) {
  8879. if (controller._byobRequest === undefined) {
  8880. return;
  8881. }
  8882. controller._byobRequest._associatedReadableByteStreamController = undefined;
  8883. controller._byobRequest._view = undefined;
  8884. controller._byobRequest = undefined;
  8885. }
  8886. function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) {
  8887. assert(controller._closeRequested === false);
  8888. while (controller._pendingPullIntos.length > 0) {
  8889. if (controller._queueTotalSize === 0) {
  8890. return;
  8891. }
  8892. var pullIntoDescriptor = controller._pendingPullIntos[0];
  8893. if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) {
  8894. ReadableByteStreamControllerShiftPendingPullInto(controller);
  8895. ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor);
  8896. }
  8897. }
  8898. }
  8899. function ReadableByteStreamControllerPullInto(controller, view) {
  8900. var stream = controller._controlledReadableStream;
  8901. var elementSize = 1;
  8902. if (view.constructor !== DataView) {
  8903. elementSize = view.constructor.BYTES_PER_ELEMENT;
  8904. }
  8905. var ctor = view.constructor;
  8906. var pullIntoDescriptor = {
  8907. buffer: view.buffer,
  8908. byteOffset: view.byteOffset,
  8909. byteLength: view.byteLength,
  8910. bytesFilled: 0,
  8911. elementSize: elementSize,
  8912. ctor: ctor,
  8913. readerType: 'byob'
  8914. };
  8915. if (controller._pendingPullIntos.length > 0) {
  8916. pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer);
  8917. controller._pendingPullIntos.push(pullIntoDescriptor);
  8918. return ReadableStreamAddReadIntoRequest(stream);
  8919. }
  8920. if (stream._state === 'closed') {
  8921. var emptyView = new view.constructor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0);
  8922. return Promise.resolve(CreateIterResultObject(emptyView, true));
  8923. }
  8924. if (controller._queueTotalSize > 0) {
  8925. if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) {
  8926. var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);
  8927. ReadableByteStreamControllerHandleQueueDrain(controller);
  8928. return Promise.resolve(CreateIterResultObject(filledView, false));
  8929. }
  8930. if (controller._closeRequested === true) {
  8931. var e = new TypeError('Insufficient bytes to fill elements in the given buffer');
  8932. ReadableByteStreamControllerError(controller, e);
  8933. return Promise.reject(e);
  8934. }
  8935. }
  8936. pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer);
  8937. controller._pendingPullIntos.push(pullIntoDescriptor);
  8938. var promise = ReadableStreamAddReadIntoRequest(stream);
  8939. ReadableByteStreamControllerCallPullIfNeeded(controller);
  8940. return promise;
  8941. }
  8942. function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
  8943. firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
  8944. assert(firstDescriptor.bytesFilled === 0, 'bytesFilled must be 0');
  8945. var stream = controller._controlledReadableStream;
  8946. if (ReadableStreamHasBYOBReader(stream) === true) {
  8947. while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {
  8948. var pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller);
  8949. ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor);
  8950. }
  8951. }
  8952. }
  8953. function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {
  8954. if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) {
  8955. throw new RangeError('bytesWritten out of range');
  8956. }
  8957. ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);
  8958. if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {
  8959. return;
  8960. }
  8961. ReadableByteStreamControllerShiftPendingPullInto(controller);
  8962. var remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
  8963. if (remainderSize > 0) {
  8964. var end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
  8965. var remainder = pullIntoDescriptor.buffer.slice(end - remainderSize, end);
  8966. ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);
  8967. }
  8968. pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer);
  8969. pullIntoDescriptor.bytesFilled -= remainderSize;
  8970. ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor);
  8971. ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
  8972. }
  8973. function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
  8974. var firstDescriptor = controller._pendingPullIntos[0];
  8975. var stream = controller._controlledReadableStream;
  8976. if (stream._state === 'closed') {
  8977. if (bytesWritten !== 0) {
  8978. throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream');
  8979. }
  8980. ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor);
  8981. } else {
  8982. assert(stream._state === 'readable');
  8983. ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
  8984. }
  8985. }
  8986. function ReadableByteStreamControllerShiftPendingPullInto(controller) {
  8987. var descriptor = controller._pendingPullIntos.shift();
  8988. ReadableByteStreamControllerInvalidateBYOBRequest(controller);
  8989. return descriptor;
  8990. }
  8991. function ReadableByteStreamControllerShouldCallPull(controller) {
  8992. var stream = controller._controlledReadableStream;
  8993. if (stream._state !== 'readable') {
  8994. return false;
  8995. }
  8996. if (controller._closeRequested === true) {
  8997. return false;
  8998. }
  8999. if (controller._started === false) {
  9000. return false;
  9001. }
  9002. if (ReadableStreamHasDefaultReader(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) {
  9003. return true;
  9004. }
  9005. if (ReadableStreamHasBYOBReader(stream) === true && ReadableStreamGetNumReadIntoRequests(stream) > 0) {
  9006. return true;
  9007. }
  9008. if (ReadableByteStreamControllerGetDesiredSize(controller) > 0) {
  9009. return true;
  9010. }
  9011. return false;
  9012. }
  9013. function ReadableByteStreamControllerClose(controller) {
  9014. var stream = controller._controlledReadableStream;
  9015. assert(controller._closeRequested === false);
  9016. assert(stream._state === 'readable');
  9017. if (controller._queueTotalSize > 0) {
  9018. controller._closeRequested = true;
  9019. return;
  9020. }
  9021. if (controller._pendingPullIntos.length > 0) {
  9022. var firstPendingPullInto = controller._pendingPullIntos[0];
  9023. if (firstPendingPullInto.bytesFilled > 0) {
  9024. var e = new TypeError('Insufficient bytes to fill elements in the given buffer');
  9025. ReadableByteStreamControllerError(controller, e);
  9026. throw e;
  9027. }
  9028. }
  9029. ReadableStreamClose(stream);
  9030. }
  9031. function ReadableByteStreamControllerEnqueue(controller, chunk) {
  9032. var stream = controller._controlledReadableStream;
  9033. assert(controller._closeRequested === false);
  9034. assert(stream._state === 'readable');
  9035. var buffer = chunk.buffer;
  9036. var byteOffset = chunk.byteOffset;
  9037. var byteLength = chunk.byteLength;
  9038. var transferredBuffer = TransferArrayBuffer(buffer);
  9039. if (ReadableStreamHasDefaultReader(stream) === true) {
  9040. if (ReadableStreamGetNumReadRequests(stream) === 0) {
  9041. ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
  9042. } else {
  9043. assert(controller._queue.length === 0);
  9044. var transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);
  9045. ReadableStreamFulfillReadRequest(stream, transferredView, false);
  9046. }
  9047. } else if (ReadableStreamHasBYOBReader(stream) === true) {
  9048. ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
  9049. ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
  9050. } else {
  9051. assert(IsReadableStreamLocked(stream) === false, 'stream must not be locked');
  9052. ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
  9053. }
  9054. }
  9055. function ReadableByteStreamControllerError(controller, e) {
  9056. var stream = controller._controlledReadableStream;
  9057. assert(stream._state === 'readable');
  9058. ReadableByteStreamControllerClearPendingPullIntos(controller);
  9059. ResetQueue(controller);
  9060. ReadableStreamError(stream, e);
  9061. }
  9062. function ReadableByteStreamControllerGetDesiredSize(controller) {
  9063. var stream = controller._controlledReadableStream;
  9064. var state = stream._state;
  9065. if (state === 'errored') {
  9066. return null;
  9067. }
  9068. if (state === 'closed') {
  9069. return 0;
  9070. }
  9071. return controller._strategyHWM - controller._queueTotalSize;
  9072. }
  9073. function ReadableByteStreamControllerRespond(controller, bytesWritten) {
  9074. bytesWritten = Number(bytesWritten);
  9075. if (IsFiniteNonNegativeNumber(bytesWritten) === false) {
  9076. throw new RangeError('bytesWritten must be a finite');
  9077. }
  9078. assert(controller._pendingPullIntos.length > 0);
  9079. ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
  9080. }
  9081. function ReadableByteStreamControllerRespondWithNewView(controller, view) {
  9082. assert(controller._pendingPullIntos.length > 0);
  9083. var firstDescriptor = controller._pendingPullIntos[0];
  9084. if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
  9085. throw new RangeError('The region specified by view does not match byobRequest');
  9086. }
  9087. if (firstDescriptor.byteLength !== view.byteLength) {
  9088. throw new RangeError('The buffer of view has different capacity than byobRequest');
  9089. }
  9090. firstDescriptor.buffer = view.buffer;
  9091. ReadableByteStreamControllerRespondInternal(controller, view.byteLength);
  9092. }
  9093. function streamBrandCheckException(name) {
  9094. return new TypeError('ReadableStream.prototype.' + name + ' can only be used on a ReadableStream');
  9095. }
  9096. function readerLockException(name) {
  9097. return new TypeError('Cannot ' + name + ' a stream using a released reader');
  9098. }
  9099. function defaultReaderBrandCheckException(name) {
  9100. return new TypeError('ReadableStreamDefaultReader.prototype.' + name + ' can only be used on a ReadableStreamDefaultReader');
  9101. }
  9102. function defaultReaderClosedPromiseInitialize(reader) {
  9103. reader._closedPromise = new Promise(function (resolve, reject) {
  9104. reader._closedPromise_resolve = resolve;
  9105. reader._closedPromise_reject = reject;
  9106. });
  9107. }
  9108. function defaultReaderClosedPromiseInitializeAsRejected(reader, reason) {
  9109. reader._closedPromise = Promise.reject(reason);
  9110. reader._closedPromise_resolve = undefined;
  9111. reader._closedPromise_reject = undefined;
  9112. }
  9113. function defaultReaderClosedPromiseInitializeAsResolved(reader) {
  9114. reader._closedPromise = Promise.resolve(undefined);
  9115. reader._closedPromise_resolve = undefined;
  9116. reader._closedPromise_reject = undefined;
  9117. }
  9118. function defaultReaderClosedPromiseReject(reader, reason) {
  9119. assert(reader._closedPromise_resolve !== undefined);
  9120. assert(reader._closedPromise_reject !== undefined);
  9121. reader._closedPromise_reject(reason);
  9122. reader._closedPromise_resolve = undefined;
  9123. reader._closedPromise_reject = undefined;
  9124. }
  9125. function defaultReaderClosedPromiseResetToRejected(reader, reason) {
  9126. assert(reader._closedPromise_resolve === undefined);
  9127. assert(reader._closedPromise_reject === undefined);
  9128. reader._closedPromise = Promise.reject(reason);
  9129. }
  9130. function defaultReaderClosedPromiseResolve(reader) {
  9131. assert(reader._closedPromise_resolve !== undefined);
  9132. assert(reader._closedPromise_reject !== undefined);
  9133. reader._closedPromise_resolve(undefined);
  9134. reader._closedPromise_resolve = undefined;
  9135. reader._closedPromise_reject = undefined;
  9136. }
  9137. function byobReaderBrandCheckException(name) {
  9138. return new TypeError('ReadableStreamBYOBReader.prototype.' + name + ' can only be used on a ReadableStreamBYOBReader');
  9139. }
  9140. function defaultControllerBrandCheckException(name) {
  9141. return new TypeError('ReadableStreamDefaultController.prototype.' + name + ' can only be used on a ReadableStreamDefaultController');
  9142. }
  9143. function byobRequestBrandCheckException(name) {
  9144. return new TypeError('ReadableStreamBYOBRequest.prototype.' + name + ' can only be used on a ReadableStreamBYOBRequest');
  9145. }
  9146. function byteStreamControllerBrandCheckException(name) {
  9147. return new TypeError('ReadableByteStreamController.prototype.' + name + ' can only be used on a ReadableByteStreamController');
  9148. }
  9149. function ifIsObjectAndHasAPromiseIsHandledInternalSlotSetPromiseIsHandledToTrue(promise) {
  9150. try {
  9151. Promise.prototype.then.call(promise, undefined, function () {});
  9152. } catch (e) {}
  9153. }
  9154. }, function (module, exports, __w_pdfjs_require__) {
  9155. "use strict";
  9156. var transformStream = __w_pdfjs_require__(6);
  9157. var readableStream = __w_pdfjs_require__(4);
  9158. var writableStream = __w_pdfjs_require__(2);
  9159. exports.TransformStream = transformStream.TransformStream;
  9160. exports.ReadableStream = readableStream.ReadableStream;
  9161. exports.IsReadableStreamDisturbed = readableStream.IsReadableStreamDisturbed;
  9162. exports.ReadableStreamDefaultControllerClose = readableStream.ReadableStreamDefaultControllerClose;
  9163. exports.ReadableStreamDefaultControllerEnqueue = readableStream.ReadableStreamDefaultControllerEnqueue;
  9164. exports.ReadableStreamDefaultControllerError = readableStream.ReadableStreamDefaultControllerError;
  9165. exports.ReadableStreamDefaultControllerGetDesiredSize = readableStream.ReadableStreamDefaultControllerGetDesiredSize;
  9166. exports.AcquireWritableStreamDefaultWriter = writableStream.AcquireWritableStreamDefaultWriter;
  9167. exports.IsWritableStream = writableStream.IsWritableStream;
  9168. exports.IsWritableStreamLocked = writableStream.IsWritableStreamLocked;
  9169. exports.WritableStream = writableStream.WritableStream;
  9170. exports.WritableStreamAbort = writableStream.WritableStreamAbort;
  9171. exports.WritableStreamDefaultControllerError = writableStream.WritableStreamDefaultControllerError;
  9172. exports.WritableStreamDefaultWriterCloseWithErrorPropagation = writableStream.WritableStreamDefaultWriterCloseWithErrorPropagation;
  9173. exports.WritableStreamDefaultWriterRelease = writableStream.WritableStreamDefaultWriterRelease;
  9174. exports.WritableStreamDefaultWriterWrite = writableStream.WritableStreamDefaultWriterWrite;
  9175. }, function (module, exports, __w_pdfjs_require__) {
  9176. "use strict";
  9177. var _createClass = function () {
  9178. function defineProperties(target, props) {
  9179. for (var i = 0; i < props.length; i++) {
  9180. var descriptor = props[i];
  9181. descriptor.enumerable = descriptor.enumerable || false;
  9182. descriptor.configurable = true;
  9183. if ("value" in descriptor) descriptor.writable = true;
  9184. Object.defineProperty(target, descriptor.key, descriptor);
  9185. }
  9186. }
  9187. return function (Constructor, protoProps, staticProps) {
  9188. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  9189. if (staticProps) defineProperties(Constructor, staticProps);
  9190. return Constructor;
  9191. };
  9192. }();
  9193. function _classCallCheck(instance, Constructor) {
  9194. if (!(instance instanceof Constructor)) {
  9195. throw new TypeError("Cannot call a class as a function");
  9196. }
  9197. }
  9198. var _require = __w_pdfjs_require__(1),
  9199. assert = _require.assert;
  9200. var _require2 = __w_pdfjs_require__(0),
  9201. InvokeOrNoop = _require2.InvokeOrNoop,
  9202. PromiseInvokeOrPerformFallback = _require2.PromiseInvokeOrPerformFallback,
  9203. PromiseInvokeOrNoop = _require2.PromiseInvokeOrNoop,
  9204. typeIsObject = _require2.typeIsObject;
  9205. var _require3 = __w_pdfjs_require__(4),
  9206. ReadableStream = _require3.ReadableStream,
  9207. ReadableStreamDefaultControllerClose = _require3.ReadableStreamDefaultControllerClose,
  9208. ReadableStreamDefaultControllerEnqueue = _require3.ReadableStreamDefaultControllerEnqueue,
  9209. ReadableStreamDefaultControllerError = _require3.ReadableStreamDefaultControllerError,
  9210. ReadableStreamDefaultControllerGetDesiredSize = _require3.ReadableStreamDefaultControllerGetDesiredSize;
  9211. var _require4 = __w_pdfjs_require__(2),
  9212. WritableStream = _require4.WritableStream,
  9213. WritableStreamDefaultControllerError = _require4.WritableStreamDefaultControllerError;
  9214. function TransformStreamCloseReadable(transformStream) {
  9215. if (transformStream._errored === true) {
  9216. throw new TypeError('TransformStream is already errored');
  9217. }
  9218. if (transformStream._readableClosed === true) {
  9219. throw new TypeError('Readable side is already closed');
  9220. }
  9221. TransformStreamCloseReadableInternal(transformStream);
  9222. }
  9223. function TransformStreamEnqueueToReadable(transformStream, chunk) {
  9224. if (transformStream._errored === true) {
  9225. throw new TypeError('TransformStream is already errored');
  9226. }
  9227. if (transformStream._readableClosed === true) {
  9228. throw new TypeError('Readable side is already closed');
  9229. }
  9230. var controller = transformStream._readableController;
  9231. try {
  9232. ReadableStreamDefaultControllerEnqueue(controller, chunk);
  9233. } catch (e) {
  9234. transformStream._readableClosed = true;
  9235. TransformStreamErrorIfNeeded(transformStream, e);
  9236. throw transformStream._storedError;
  9237. }
  9238. var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller);
  9239. var maybeBackpressure = desiredSize <= 0;
  9240. if (maybeBackpressure === true && transformStream._backpressure === false) {
  9241. TransformStreamSetBackpressure(transformStream, true);
  9242. }
  9243. }
  9244. function TransformStreamError(transformStream, e) {
  9245. if (transformStream._errored === true) {
  9246. throw new TypeError('TransformStream is already errored');
  9247. }
  9248. TransformStreamErrorInternal(transformStream, e);
  9249. }
  9250. function TransformStreamCloseReadableInternal(transformStream) {
  9251. assert(transformStream._errored === false);
  9252. assert(transformStream._readableClosed === false);
  9253. try {
  9254. ReadableStreamDefaultControllerClose(transformStream._readableController);
  9255. } catch (e) {
  9256. assert(false);
  9257. }
  9258. transformStream._readableClosed = true;
  9259. }
  9260. function TransformStreamErrorIfNeeded(transformStream, e) {
  9261. if (transformStream._errored === false) {
  9262. TransformStreamErrorInternal(transformStream, e);
  9263. }
  9264. }
  9265. function TransformStreamErrorInternal(transformStream, e) {
  9266. assert(transformStream._errored === false);
  9267. transformStream._errored = true;
  9268. transformStream._storedError = e;
  9269. if (transformStream._writableDone === false) {
  9270. WritableStreamDefaultControllerError(transformStream._writableController, e);
  9271. }
  9272. if (transformStream._readableClosed === false) {
  9273. ReadableStreamDefaultControllerError(transformStream._readableController, e);
  9274. }
  9275. }
  9276. function TransformStreamReadableReadyPromise(transformStream) {
  9277. assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized');
  9278. if (transformStream._backpressure === false) {
  9279. return Promise.resolve();
  9280. }
  9281. assert(transformStream._backpressure === true, '_backpressure should have been initialized');
  9282. return transformStream._backpressureChangePromise;
  9283. }
  9284. function TransformStreamSetBackpressure(transformStream, backpressure) {
  9285. assert(transformStream._backpressure !== backpressure, 'TransformStreamSetBackpressure() should be called only when backpressure is changed');
  9286. if (transformStream._backpressureChangePromise !== undefined) {
  9287. transformStream._backpressureChangePromise_resolve(backpressure);
  9288. }
  9289. transformStream._backpressureChangePromise = new Promise(function (resolve) {
  9290. transformStream._backpressureChangePromise_resolve = resolve;
  9291. });
  9292. transformStream._backpressureChangePromise.then(function (resolution) {
  9293. assert(resolution !== backpressure, '_backpressureChangePromise should be fulfilled only when backpressure is changed');
  9294. });
  9295. transformStream._backpressure = backpressure;
  9296. }
  9297. function TransformStreamDefaultTransform(chunk, transformStreamController) {
  9298. var transformStream = transformStreamController._controlledTransformStream;
  9299. TransformStreamEnqueueToReadable(transformStream, chunk);
  9300. return Promise.resolve();
  9301. }
  9302. function TransformStreamTransform(transformStream, chunk) {
  9303. assert(transformStream._errored === false);
  9304. assert(transformStream._transforming === false);
  9305. assert(transformStream._backpressure === false);
  9306. transformStream._transforming = true;
  9307. var transformer = transformStream._transformer;
  9308. var controller = transformStream._transformStreamController;
  9309. var transformPromise = PromiseInvokeOrPerformFallback(transformer, 'transform', [chunk, controller], TransformStreamDefaultTransform, [chunk, controller]);
  9310. return transformPromise.then(function () {
  9311. transformStream._transforming = false;
  9312. return TransformStreamReadableReadyPromise(transformStream);
  9313. }, function (e) {
  9314. TransformStreamErrorIfNeeded(transformStream, e);
  9315. return Promise.reject(e);
  9316. });
  9317. }
  9318. function IsTransformStreamDefaultController(x) {
  9319. if (!typeIsObject(x)) {
  9320. return false;
  9321. }
  9322. if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) {
  9323. return false;
  9324. }
  9325. return true;
  9326. }
  9327. function IsTransformStream(x) {
  9328. if (!typeIsObject(x)) {
  9329. return false;
  9330. }
  9331. if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) {
  9332. return false;
  9333. }
  9334. return true;
  9335. }
  9336. var TransformStreamSink = function () {
  9337. function TransformStreamSink(transformStream, startPromise) {
  9338. _classCallCheck(this, TransformStreamSink);
  9339. this._transformStream = transformStream;
  9340. this._startPromise = startPromise;
  9341. }
  9342. _createClass(TransformStreamSink, [{
  9343. key: 'start',
  9344. value: function start(c) {
  9345. var transformStream = this._transformStream;
  9346. transformStream._writableController = c;
  9347. return this._startPromise.then(function () {
  9348. return TransformStreamReadableReadyPromise(transformStream);
  9349. });
  9350. }
  9351. }, {
  9352. key: 'write',
  9353. value: function write(chunk) {
  9354. var transformStream = this._transformStream;
  9355. return TransformStreamTransform(transformStream, chunk);
  9356. }
  9357. }, {
  9358. key: 'abort',
  9359. value: function abort() {
  9360. var transformStream = this._transformStream;
  9361. transformStream._writableDone = true;
  9362. TransformStreamErrorInternal(transformStream, new TypeError('Writable side aborted'));
  9363. }
  9364. }, {
  9365. key: 'close',
  9366. value: function close() {
  9367. var transformStream = this._transformStream;
  9368. assert(transformStream._transforming === false);
  9369. transformStream._writableDone = true;
  9370. var flushPromise = PromiseInvokeOrNoop(transformStream._transformer, 'flush', [transformStream._transformStreamController]);
  9371. return flushPromise.then(function () {
  9372. if (transformStream._errored === true) {
  9373. return Promise.reject(transformStream._storedError);
  9374. }
  9375. if (transformStream._readableClosed === false) {
  9376. TransformStreamCloseReadableInternal(transformStream);
  9377. }
  9378. return Promise.resolve();
  9379. }).catch(function (r) {
  9380. TransformStreamErrorIfNeeded(transformStream, r);
  9381. return Promise.reject(transformStream._storedError);
  9382. });
  9383. }
  9384. }]);
  9385. return TransformStreamSink;
  9386. }();
  9387. var TransformStreamSource = function () {
  9388. function TransformStreamSource(transformStream, startPromise) {
  9389. _classCallCheck(this, TransformStreamSource);
  9390. this._transformStream = transformStream;
  9391. this._startPromise = startPromise;
  9392. }
  9393. _createClass(TransformStreamSource, [{
  9394. key: 'start',
  9395. value: function start(c) {
  9396. var transformStream = this._transformStream;
  9397. transformStream._readableController = c;
  9398. return this._startPromise.then(function () {
  9399. assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized');
  9400. if (transformStream._backpressure === true) {
  9401. return Promise.resolve();
  9402. }
  9403. assert(transformStream._backpressure === false, '_backpressure should have been initialized');
  9404. return transformStream._backpressureChangePromise;
  9405. });
  9406. }
  9407. }, {
  9408. key: 'pull',
  9409. value: function pull() {
  9410. var transformStream = this._transformStream;
  9411. assert(transformStream._backpressure === true, 'pull() should be never called while _backpressure is false');
  9412. assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized');
  9413. TransformStreamSetBackpressure(transformStream, false);
  9414. return transformStream._backpressureChangePromise;
  9415. }
  9416. }, {
  9417. key: 'cancel',
  9418. value: function cancel() {
  9419. var transformStream = this._transformStream;
  9420. transformStream._readableClosed = true;
  9421. TransformStreamErrorInternal(transformStream, new TypeError('Readable side canceled'));
  9422. }
  9423. }]);
  9424. return TransformStreamSource;
  9425. }();
  9426. var TransformStreamDefaultController = function () {
  9427. function TransformStreamDefaultController(transformStream) {
  9428. _classCallCheck(this, TransformStreamDefaultController);
  9429. if (IsTransformStream(transformStream) === false) {
  9430. throw new TypeError('TransformStreamDefaultController can only be ' + 'constructed with a TransformStream instance');
  9431. }
  9432. if (transformStream._transformStreamController !== undefined) {
  9433. throw new TypeError('TransformStreamDefaultController instances can ' + 'only be created by the TransformStream constructor');
  9434. }
  9435. this._controlledTransformStream = transformStream;
  9436. }
  9437. _createClass(TransformStreamDefaultController, [{
  9438. key: 'enqueue',
  9439. value: function enqueue(chunk) {
  9440. if (IsTransformStreamDefaultController(this) === false) {
  9441. throw defaultControllerBrandCheckException('enqueue');
  9442. }
  9443. TransformStreamEnqueueToReadable(this._controlledTransformStream, chunk);
  9444. }
  9445. }, {
  9446. key: 'close',
  9447. value: function close() {
  9448. if (IsTransformStreamDefaultController(this) === false) {
  9449. throw defaultControllerBrandCheckException('close');
  9450. }
  9451. TransformStreamCloseReadable(this._controlledTransformStream);
  9452. }
  9453. }, {
  9454. key: 'error',
  9455. value: function error(reason) {
  9456. if (IsTransformStreamDefaultController(this) === false) {
  9457. throw defaultControllerBrandCheckException('error');
  9458. }
  9459. TransformStreamError(this._controlledTransformStream, reason);
  9460. }
  9461. }, {
  9462. key: 'desiredSize',
  9463. get: function get() {
  9464. if (IsTransformStreamDefaultController(this) === false) {
  9465. throw defaultControllerBrandCheckException('desiredSize');
  9466. }
  9467. var transformStream = this._controlledTransformStream;
  9468. var readableController = transformStream._readableController;
  9469. return ReadableStreamDefaultControllerGetDesiredSize(readableController);
  9470. }
  9471. }]);
  9472. return TransformStreamDefaultController;
  9473. }();
  9474. var TransformStream = function () {
  9475. function TransformStream() {
  9476. var transformer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  9477. _classCallCheck(this, TransformStream);
  9478. this._transformer = transformer;
  9479. var readableStrategy = transformer.readableStrategy,
  9480. writableStrategy = transformer.writableStrategy;
  9481. this._transforming = false;
  9482. this._errored = false;
  9483. this._storedError = undefined;
  9484. this._writableController = undefined;
  9485. this._readableController = undefined;
  9486. this._transformStreamController = undefined;
  9487. this._writableDone = false;
  9488. this._readableClosed = false;
  9489. this._backpressure = undefined;
  9490. this._backpressureChangePromise = undefined;
  9491. this._backpressureChangePromise_resolve = undefined;
  9492. this._transformStreamController = new TransformStreamDefaultController(this);
  9493. var startPromise_resolve = void 0;
  9494. var startPromise = new Promise(function (resolve) {
  9495. startPromise_resolve = resolve;
  9496. });
  9497. var source = new TransformStreamSource(this, startPromise);
  9498. this._readable = new ReadableStream(source, readableStrategy);
  9499. var sink = new TransformStreamSink(this, startPromise);
  9500. this._writable = new WritableStream(sink, writableStrategy);
  9501. assert(this._writableController !== undefined);
  9502. assert(this._readableController !== undefined);
  9503. var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(this._readableController);
  9504. TransformStreamSetBackpressure(this, desiredSize <= 0);
  9505. var transformStream = this;
  9506. var startResult = InvokeOrNoop(transformer, 'start', [transformStream._transformStreamController]);
  9507. startPromise_resolve(startResult);
  9508. startPromise.catch(function (e) {
  9509. if (transformStream._errored === false) {
  9510. transformStream._errored = true;
  9511. transformStream._storedError = e;
  9512. }
  9513. });
  9514. }
  9515. _createClass(TransformStream, [{
  9516. key: 'readable',
  9517. get: function get() {
  9518. if (IsTransformStream(this) === false) {
  9519. throw streamBrandCheckException('readable');
  9520. }
  9521. return this._readable;
  9522. }
  9523. }, {
  9524. key: 'writable',
  9525. get: function get() {
  9526. if (IsTransformStream(this) === false) {
  9527. throw streamBrandCheckException('writable');
  9528. }
  9529. return this._writable;
  9530. }
  9531. }]);
  9532. return TransformStream;
  9533. }();
  9534. module.exports = { TransformStream: TransformStream };
  9535. function defaultControllerBrandCheckException(name) {
  9536. return new TypeError('TransformStreamDefaultController.prototype.' + name + ' can only be used on a TransformStreamDefaultController');
  9537. }
  9538. function streamBrandCheckException(name) {
  9539. return new TypeError('TransformStream.prototype.' + name + ' can only be used on a TransformStream');
  9540. }
  9541. }, function (module, exports, __w_pdfjs_require__) {
  9542. module.exports = __w_pdfjs_require__(5);
  9543. }]));
  9544. /***/ }),
  9545. /* 11 */
  9546. /***/ (function(module, exports, __w_pdfjs_require__) {
  9547. "use strict";
  9548. Object.defineProperty(exports, "__esModule", {
  9549. value: true
  9550. });
  9551. exports.CanvasGraphics = undefined;
  9552. var _util = __w_pdfjs_require__(0);
  9553. var _pattern_helper = __w_pdfjs_require__(13);
  9554. var _webgl = __w_pdfjs_require__(7);
  9555. var MIN_FONT_SIZE = 16;
  9556. var MAX_FONT_SIZE = 100;
  9557. var MAX_GROUP_SIZE = 4096;
  9558. var MIN_WIDTH_FACTOR = 0.65;
  9559. var COMPILE_TYPE3_GLYPHS = true;
  9560. var MAX_SIZE_TO_COMPILE = 1000;
  9561. var FULL_CHUNK_HEIGHT = 16;
  9562. var IsLittleEndianCached = {
  9563. get value() {
  9564. return (0, _util.shadow)(IsLittleEndianCached, 'value', (0, _util.isLittleEndian)());
  9565. }
  9566. };
  9567. function addContextCurrentTransform(ctx) {
  9568. if (!ctx.mozCurrentTransform) {
  9569. ctx._originalSave = ctx.save;
  9570. ctx._originalRestore = ctx.restore;
  9571. ctx._originalRotate = ctx.rotate;
  9572. ctx._originalScale = ctx.scale;
  9573. ctx._originalTranslate = ctx.translate;
  9574. ctx._originalTransform = ctx.transform;
  9575. ctx._originalSetTransform = ctx.setTransform;
  9576. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  9577. ctx._transformStack = [];
  9578. Object.defineProperty(ctx, 'mozCurrentTransform', {
  9579. get: function getCurrentTransform() {
  9580. return this._transformMatrix;
  9581. }
  9582. });
  9583. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  9584. get: function getCurrentTransformInverse() {
  9585. var m = this._transformMatrix;
  9586. var a = m[0],
  9587. b = m[1],
  9588. c = m[2],
  9589. d = m[3],
  9590. e = m[4],
  9591. f = m[5];
  9592. var ad_bc = a * d - b * c;
  9593. var bc_ad = b * c - a * d;
  9594. 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];
  9595. }
  9596. });
  9597. ctx.save = function ctxSave() {
  9598. var old = this._transformMatrix;
  9599. this._transformStack.push(old);
  9600. this._transformMatrix = old.slice(0, 6);
  9601. this._originalSave();
  9602. };
  9603. ctx.restore = function ctxRestore() {
  9604. var prev = this._transformStack.pop();
  9605. if (prev) {
  9606. this._transformMatrix = prev;
  9607. this._originalRestore();
  9608. }
  9609. };
  9610. ctx.translate = function ctxTranslate(x, y) {
  9611. var m = this._transformMatrix;
  9612. m[4] = m[0] * x + m[2] * y + m[4];
  9613. m[5] = m[1] * x + m[3] * y + m[5];
  9614. this._originalTranslate(x, y);
  9615. };
  9616. ctx.scale = function ctxScale(x, y) {
  9617. var m = this._transformMatrix;
  9618. m[0] = m[0] * x;
  9619. m[1] = m[1] * x;
  9620. m[2] = m[2] * y;
  9621. m[3] = m[3] * y;
  9622. this._originalScale(x, y);
  9623. };
  9624. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  9625. var m = this._transformMatrix;
  9626. 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]];
  9627. ctx._originalTransform(a, b, c, d, e, f);
  9628. };
  9629. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  9630. this._transformMatrix = [a, b, c, d, e, f];
  9631. ctx._originalSetTransform(a, b, c, d, e, f);
  9632. };
  9633. ctx.rotate = function ctxRotate(angle) {
  9634. var cosValue = Math.cos(angle);
  9635. var sinValue = Math.sin(angle);
  9636. var m = this._transformMatrix;
  9637. 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]];
  9638. this._originalRotate(angle);
  9639. };
  9640. }
  9641. }
  9642. var CachedCanvases = function CachedCanvasesClosure() {
  9643. function CachedCanvases(canvasFactory) {
  9644. this.canvasFactory = canvasFactory;
  9645. this.cache = Object.create(null);
  9646. }
  9647. CachedCanvases.prototype = {
  9648. getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) {
  9649. var canvasEntry;
  9650. if (this.cache[id] !== undefined) {
  9651. canvasEntry = this.cache[id];
  9652. this.canvasFactory.reset(canvasEntry, width, height);
  9653. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  9654. } else {
  9655. canvasEntry = this.canvasFactory.create(width, height);
  9656. this.cache[id] = canvasEntry;
  9657. }
  9658. if (trackTransform) {
  9659. addContextCurrentTransform(canvasEntry.context);
  9660. }
  9661. return canvasEntry;
  9662. },
  9663. clear: function clear() {
  9664. for (var id in this.cache) {
  9665. var canvasEntry = this.cache[id];
  9666. this.canvasFactory.destroy(canvasEntry);
  9667. delete this.cache[id];
  9668. }
  9669. }
  9670. };
  9671. return CachedCanvases;
  9672. }();
  9673. function compileType3Glyph(imgData) {
  9674. var POINT_TO_PROCESS_LIMIT = 1000;
  9675. var width = imgData.width,
  9676. height = imgData.height;
  9677. var i,
  9678. j,
  9679. j0,
  9680. width1 = width + 1;
  9681. var points = new Uint8Array(width1 * (height + 1));
  9682. var POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  9683. var lineSize = width + 7 & ~7,
  9684. data0 = imgData.data;
  9685. var data = new Uint8Array(lineSize * height),
  9686. pos = 0,
  9687. ii;
  9688. for (i = 0, ii = data0.length; i < ii; i++) {
  9689. var mask = 128,
  9690. elem = data0[i];
  9691. while (mask > 0) {
  9692. data[pos++] = elem & mask ? 0 : 255;
  9693. mask >>= 1;
  9694. }
  9695. }
  9696. var count = 0;
  9697. pos = 0;
  9698. if (data[pos] !== 0) {
  9699. points[0] = 1;
  9700. ++count;
  9701. }
  9702. for (j = 1; j < width; j++) {
  9703. if (data[pos] !== data[pos + 1]) {
  9704. points[j] = data[pos] ? 2 : 1;
  9705. ++count;
  9706. }
  9707. pos++;
  9708. }
  9709. if (data[pos] !== 0) {
  9710. points[j] = 2;
  9711. ++count;
  9712. }
  9713. for (i = 1; i < height; i++) {
  9714. pos = i * lineSize;
  9715. j0 = i * width1;
  9716. if (data[pos - lineSize] !== data[pos]) {
  9717. points[j0] = data[pos] ? 1 : 8;
  9718. ++count;
  9719. }
  9720. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  9721. for (j = 1; j < width; j++) {
  9722. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  9723. if (POINT_TYPES[sum]) {
  9724. points[j0 + j] = POINT_TYPES[sum];
  9725. ++count;
  9726. }
  9727. pos++;
  9728. }
  9729. if (data[pos - lineSize] !== data[pos]) {
  9730. points[j0 + j] = data[pos] ? 2 : 4;
  9731. ++count;
  9732. }
  9733. if (count > POINT_TO_PROCESS_LIMIT) {
  9734. return null;
  9735. }
  9736. }
  9737. pos = lineSize * (height - 1);
  9738. j0 = i * width1;
  9739. if (data[pos] !== 0) {
  9740. points[j0] = 8;
  9741. ++count;
  9742. }
  9743. for (j = 1; j < width; j++) {
  9744. if (data[pos] !== data[pos + 1]) {
  9745. points[j0 + j] = data[pos] ? 4 : 8;
  9746. ++count;
  9747. }
  9748. pos++;
  9749. }
  9750. if (data[pos] !== 0) {
  9751. points[j0 + j] = 4;
  9752. ++count;
  9753. }
  9754. if (count > POINT_TO_PROCESS_LIMIT) {
  9755. return null;
  9756. }
  9757. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  9758. var outlines = [];
  9759. for (i = 0; count && i <= height; i++) {
  9760. var p = i * width1;
  9761. var end = p + width;
  9762. while (p < end && !points[p]) {
  9763. p++;
  9764. }
  9765. if (p === end) {
  9766. continue;
  9767. }
  9768. var coords = [p % width1, i];
  9769. var type = points[p],
  9770. p0 = p,
  9771. pp;
  9772. do {
  9773. var step = steps[type];
  9774. do {
  9775. p += step;
  9776. } while (!points[p]);
  9777. pp = points[p];
  9778. if (pp !== 5 && pp !== 10) {
  9779. type = pp;
  9780. points[p] = 0;
  9781. } else {
  9782. type = pp & 0x33 * type >> 4;
  9783. points[p] &= type >> 2 | type << 2;
  9784. }
  9785. coords.push(p % width1);
  9786. coords.push(p / width1 | 0);
  9787. --count;
  9788. } while (p0 !== p);
  9789. outlines.push(coords);
  9790. --i;
  9791. }
  9792. var drawOutline = function drawOutline(c) {
  9793. c.save();
  9794. c.scale(1 / width, -1 / height);
  9795. c.translate(0, -height);
  9796. c.beginPath();
  9797. for (var i = 0, ii = outlines.length; i < ii; i++) {
  9798. var o = outlines[i];
  9799. c.moveTo(o[0], o[1]);
  9800. for (var j = 2, jj = o.length; j < jj; j += 2) {
  9801. c.lineTo(o[j], o[j + 1]);
  9802. }
  9803. }
  9804. c.fill();
  9805. c.beginPath();
  9806. c.restore();
  9807. };
  9808. return drawOutline;
  9809. }
  9810. var CanvasExtraState = function CanvasExtraStateClosure() {
  9811. function CanvasExtraState() {
  9812. this.alphaIsShape = false;
  9813. this.fontSize = 0;
  9814. this.fontSizeScale = 1;
  9815. this.textMatrix = _util.IDENTITY_MATRIX;
  9816. this.textMatrixScale = 1;
  9817. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  9818. this.leading = 0;
  9819. this.x = 0;
  9820. this.y = 0;
  9821. this.lineX = 0;
  9822. this.lineY = 0;
  9823. this.charSpacing = 0;
  9824. this.wordSpacing = 0;
  9825. this.textHScale = 1;
  9826. this.textRenderingMode = _util.TextRenderingMode.FILL;
  9827. this.textRise = 0;
  9828. this.fillColor = '#000000';
  9829. this.strokeColor = '#000000';
  9830. this.patternFill = false;
  9831. this.fillAlpha = 1;
  9832. this.strokeAlpha = 1;
  9833. this.lineWidth = 1;
  9834. this.activeSMask = null;
  9835. this.resumeSMaskCtx = null;
  9836. }
  9837. CanvasExtraState.prototype = {
  9838. clone: function CanvasExtraState_clone() {
  9839. return Object.create(this);
  9840. },
  9841. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  9842. this.x = x;
  9843. this.y = y;
  9844. }
  9845. };
  9846. return CanvasExtraState;
  9847. }();
  9848. var CanvasGraphics = function CanvasGraphicsClosure() {
  9849. var EXECUTION_TIME = 15;
  9850. var EXECUTION_STEPS = 10;
  9851. function CanvasGraphics(canvasCtx, commonObjs, objs, canvasFactory, imageLayer) {
  9852. this.ctx = canvasCtx;
  9853. this.current = new CanvasExtraState();
  9854. this.stateStack = [];
  9855. this.pendingClip = null;
  9856. this.pendingEOFill = false;
  9857. this.res = null;
  9858. this.xobjs = null;
  9859. this.commonObjs = commonObjs;
  9860. this.objs = objs;
  9861. this.canvasFactory = canvasFactory;
  9862. this.imageLayer = imageLayer;
  9863. this.groupStack = [];
  9864. this.processingType3 = null;
  9865. this.baseTransform = null;
  9866. this.baseTransformStack = [];
  9867. this.groupLevel = 0;
  9868. this.smaskStack = [];
  9869. this.smaskCounter = 0;
  9870. this.tempSMask = null;
  9871. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  9872. if (canvasCtx) {
  9873. addContextCurrentTransform(canvasCtx);
  9874. }
  9875. this.cachedGetSinglePixelWidth = null;
  9876. }
  9877. function putBinaryImageData(ctx, imgData) {
  9878. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  9879. ctx.putImageData(imgData, 0, 0);
  9880. return;
  9881. }
  9882. var height = imgData.height,
  9883. width = imgData.width;
  9884. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  9885. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  9886. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  9887. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  9888. var srcPos = 0,
  9889. destPos;
  9890. var src = imgData.data;
  9891. var dest = chunkImgData.data;
  9892. var i, j, thisChunkHeight, elemsInThisChunk;
  9893. if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
  9894. var srcLength = src.byteLength;
  9895. var dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  9896. var dest32DataLength = dest32.length;
  9897. var fullSrcDiff = width + 7 >> 3;
  9898. var white = 0xFFFFFFFF;
  9899. var black = IsLittleEndianCached.value ? 0xFF000000 : 0x000000FF;
  9900. for (i = 0; i < totalChunks; i++) {
  9901. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  9902. destPos = 0;
  9903. for (j = 0; j < thisChunkHeight; j++) {
  9904. var srcDiff = srcLength - srcPos;
  9905. var k = 0;
  9906. var kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  9907. var kEndUnrolled = kEnd & ~7;
  9908. var mask = 0;
  9909. var srcByte = 0;
  9910. for (; k < kEndUnrolled; k += 8) {
  9911. srcByte = src[srcPos++];
  9912. dest32[destPos++] = srcByte & 128 ? white : black;
  9913. dest32[destPos++] = srcByte & 64 ? white : black;
  9914. dest32[destPos++] = srcByte & 32 ? white : black;
  9915. dest32[destPos++] = srcByte & 16 ? white : black;
  9916. dest32[destPos++] = srcByte & 8 ? white : black;
  9917. dest32[destPos++] = srcByte & 4 ? white : black;
  9918. dest32[destPos++] = srcByte & 2 ? white : black;
  9919. dest32[destPos++] = srcByte & 1 ? white : black;
  9920. }
  9921. for (; k < kEnd; k++) {
  9922. if (mask === 0) {
  9923. srcByte = src[srcPos++];
  9924. mask = 128;
  9925. }
  9926. dest32[destPos++] = srcByte & mask ? white : black;
  9927. mask >>= 1;
  9928. }
  9929. }
  9930. while (destPos < dest32DataLength) {
  9931. dest32[destPos++] = 0;
  9932. }
  9933. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  9934. }
  9935. } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
  9936. j = 0;
  9937. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  9938. for (i = 0; i < fullChunks; i++) {
  9939. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  9940. srcPos += elemsInThisChunk;
  9941. ctx.putImageData(chunkImgData, 0, j);
  9942. j += FULL_CHUNK_HEIGHT;
  9943. }
  9944. if (i < totalChunks) {
  9945. elemsInThisChunk = width * partialChunkHeight * 4;
  9946. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  9947. ctx.putImageData(chunkImgData, 0, j);
  9948. }
  9949. } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
  9950. thisChunkHeight = FULL_CHUNK_HEIGHT;
  9951. elemsInThisChunk = width * thisChunkHeight;
  9952. for (i = 0; i < totalChunks; i++) {
  9953. if (i >= fullChunks) {
  9954. thisChunkHeight = partialChunkHeight;
  9955. elemsInThisChunk = width * thisChunkHeight;
  9956. }
  9957. destPos = 0;
  9958. for (j = elemsInThisChunk; j--;) {
  9959. dest[destPos++] = src[srcPos++];
  9960. dest[destPos++] = src[srcPos++];
  9961. dest[destPos++] = src[srcPos++];
  9962. dest[destPos++] = 255;
  9963. }
  9964. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  9965. }
  9966. } else {
  9967. throw new Error('bad image kind: ' + imgData.kind);
  9968. }
  9969. }
  9970. function putBinaryImageMask(ctx, imgData) {
  9971. var height = imgData.height,
  9972. width = imgData.width;
  9973. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  9974. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  9975. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  9976. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  9977. var srcPos = 0;
  9978. var src = imgData.data;
  9979. var dest = chunkImgData.data;
  9980. for (var i = 0; i < totalChunks; i++) {
  9981. var thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  9982. var destPos = 3;
  9983. for (var j = 0; j < thisChunkHeight; j++) {
  9984. var mask = 0;
  9985. for (var k = 0; k < width; k++) {
  9986. if (!mask) {
  9987. var elem = src[srcPos++];
  9988. mask = 128;
  9989. }
  9990. dest[destPos] = elem & mask ? 0 : 255;
  9991. destPos += 4;
  9992. mask >>= 1;
  9993. }
  9994. }
  9995. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  9996. }
  9997. }
  9998. function copyCtxState(sourceCtx, destCtx) {
  9999. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha', 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit', 'globalCompositeOperation', 'font'];
  10000. for (var i = 0, ii = properties.length; i < ii; i++) {
  10001. var property = properties[i];
  10002. if (sourceCtx[property] !== undefined) {
  10003. destCtx[property] = sourceCtx[property];
  10004. }
  10005. }
  10006. if (sourceCtx.setLineDash !== undefined) {
  10007. destCtx.setLineDash(sourceCtx.getLineDash());
  10008. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  10009. }
  10010. }
  10011. function resetCtxToDefault(ctx) {
  10012. ctx.strokeStyle = '#000000';
  10013. ctx.fillStyle = '#000000';
  10014. ctx.fillRule = 'nonzero';
  10015. ctx.globalAlpha = 1;
  10016. ctx.lineWidth = 1;
  10017. ctx.lineCap = 'butt';
  10018. ctx.lineJoin = 'miter';
  10019. ctx.miterLimit = 10;
  10020. ctx.globalCompositeOperation = 'source-over';
  10021. ctx.font = '10px sans-serif';
  10022. if (ctx.setLineDash !== undefined) {
  10023. ctx.setLineDash([]);
  10024. ctx.lineDashOffset = 0;
  10025. }
  10026. }
  10027. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  10028. var length = bytes.length;
  10029. for (var i = 3; i < length; i += 4) {
  10030. var alpha = bytes[i];
  10031. if (alpha === 0) {
  10032. bytes[i - 3] = r0;
  10033. bytes[i - 2] = g0;
  10034. bytes[i - 1] = b0;
  10035. } else if (alpha < 255) {
  10036. var alpha_ = 255 - alpha;
  10037. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  10038. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  10039. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  10040. }
  10041. }
  10042. }
  10043. function composeSMaskAlpha(maskData, layerData, transferMap) {
  10044. var length = maskData.length;
  10045. var scale = 1 / 255;
  10046. for (var i = 3; i < length; i += 4) {
  10047. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  10048. layerData[i] = layerData[i] * alpha * scale | 0;
  10049. }
  10050. }
  10051. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  10052. var length = maskData.length;
  10053. for (var i = 3; i < length; i += 4) {
  10054. var y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
  10055. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  10056. }
  10057. }
  10058. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap) {
  10059. var hasBackdrop = !!backdrop;
  10060. var r0 = hasBackdrop ? backdrop[0] : 0;
  10061. var g0 = hasBackdrop ? backdrop[1] : 0;
  10062. var b0 = hasBackdrop ? backdrop[2] : 0;
  10063. var composeFn;
  10064. if (subtype === 'Luminosity') {
  10065. composeFn = composeSMaskLuminosity;
  10066. } else {
  10067. composeFn = composeSMaskAlpha;
  10068. }
  10069. var PIXELS_TO_PROCESS = 1048576;
  10070. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  10071. for (var row = 0; row < height; row += chunkSize) {
  10072. var chunkHeight = Math.min(chunkSize, height - row);
  10073. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  10074. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  10075. if (hasBackdrop) {
  10076. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  10077. }
  10078. composeFn(maskData.data, layerData.data, transferMap);
  10079. maskCtx.putImageData(layerData, 0, row);
  10080. }
  10081. }
  10082. function composeSMask(ctx, smask, layerCtx) {
  10083. var mask = smask.canvas;
  10084. var maskCtx = smask.context;
  10085. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY, smask.offsetX, smask.offsetY);
  10086. var backdrop = smask.backdrop || null;
  10087. if (!smask.transferMap && _webgl.WebGLUtils.isEnabled) {
  10088. var composed = _webgl.WebGLUtils.composeSMask(layerCtx.canvas, mask, {
  10089. subtype: smask.subtype,
  10090. backdrop: backdrop
  10091. });
  10092. ctx.setTransform(1, 0, 0, 1, 0, 0);
  10093. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  10094. return;
  10095. }
  10096. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height, smask.subtype, backdrop, smask.transferMap);
  10097. ctx.drawImage(mask, 0, 0);
  10098. }
  10099. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  10100. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  10101. var NORMAL_CLIP = {};
  10102. var EO_CLIP = {};
  10103. CanvasGraphics.prototype = {
  10104. beginDrawing: function beginDrawing(_ref) {
  10105. var transform = _ref.transform,
  10106. viewport = _ref.viewport,
  10107. transparency = _ref.transparency,
  10108. _ref$background = _ref.background,
  10109. background = _ref$background === undefined ? null : _ref$background;
  10110. var width = this.ctx.canvas.width;
  10111. var height = this.ctx.canvas.height;
  10112. this.ctx.save();
  10113. this.ctx.fillStyle = background || 'rgb(255, 255, 255)';
  10114. this.ctx.fillRect(0, 0, width, height);
  10115. this.ctx.restore();
  10116. if (transparency) {
  10117. var transparentCanvas = this.cachedCanvases.getCanvas('transparent', width, height, true);
  10118. this.compositeCtx = this.ctx;
  10119. this.transparentCanvas = transparentCanvas.canvas;
  10120. this.ctx = transparentCanvas.context;
  10121. this.ctx.save();
  10122. this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
  10123. }
  10124. this.ctx.save();
  10125. resetCtxToDefault(this.ctx);
  10126. if (transform) {
  10127. this.ctx.transform.apply(this.ctx, transform);
  10128. }
  10129. this.ctx.transform.apply(this.ctx, viewport.transform);
  10130. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  10131. if (this.imageLayer) {
  10132. this.imageLayer.beginLayout();
  10133. }
  10134. },
  10135. executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  10136. var argsArray = operatorList.argsArray;
  10137. var fnArray = operatorList.fnArray;
  10138. var i = executionStartIdx || 0;
  10139. var argsArrayLen = argsArray.length;
  10140. if (argsArrayLen === i) {
  10141. return i;
  10142. }
  10143. var chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === 'function';
  10144. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  10145. var steps = 0;
  10146. var commonObjs = this.commonObjs;
  10147. var objs = this.objs;
  10148. var fnId;
  10149. while (true) {
  10150. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  10151. stepper.breakIt(i, continueCallback);
  10152. return i;
  10153. }
  10154. fnId = fnArray[i];
  10155. if (fnId !== _util.OPS.dependency) {
  10156. this[fnId].apply(this, argsArray[i]);
  10157. } else {
  10158. var deps = argsArray[i];
  10159. for (var n = 0, nn = deps.length; n < nn; n++) {
  10160. var depObjId = deps[n];
  10161. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  10162. var objsPool = common ? commonObjs : objs;
  10163. if (!objsPool.isResolved(depObjId)) {
  10164. objsPool.get(depObjId, continueCallback);
  10165. return i;
  10166. }
  10167. }
  10168. }
  10169. i++;
  10170. if (i === argsArrayLen) {
  10171. return i;
  10172. }
  10173. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  10174. if (Date.now() > endTime) {
  10175. continueCallback();
  10176. return i;
  10177. }
  10178. steps = 0;
  10179. }
  10180. }
  10181. },
  10182. endDrawing: function CanvasGraphics_endDrawing() {
  10183. if (this.current.activeSMask !== null) {
  10184. this.endSMaskGroup();
  10185. }
  10186. this.ctx.restore();
  10187. if (this.transparentCanvas) {
  10188. this.ctx = this.compositeCtx;
  10189. this.ctx.save();
  10190. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  10191. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  10192. this.ctx.restore();
  10193. this.transparentCanvas = null;
  10194. }
  10195. this.cachedCanvases.clear();
  10196. _webgl.WebGLUtils.clear();
  10197. if (this.imageLayer) {
  10198. this.imageLayer.endLayout();
  10199. }
  10200. },
  10201. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  10202. this.current.lineWidth = width;
  10203. this.ctx.lineWidth = width;
  10204. },
  10205. setLineCap: function CanvasGraphics_setLineCap(style) {
  10206. this.ctx.lineCap = LINE_CAP_STYLES[style];
  10207. },
  10208. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  10209. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  10210. },
  10211. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  10212. this.ctx.miterLimit = limit;
  10213. },
  10214. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  10215. var ctx = this.ctx;
  10216. if (ctx.setLineDash !== undefined) {
  10217. ctx.setLineDash(dashArray);
  10218. ctx.lineDashOffset = dashPhase;
  10219. }
  10220. },
  10221. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {},
  10222. setFlatness: function CanvasGraphics_setFlatness(flatness) {},
  10223. setGState: function CanvasGraphics_setGState(states) {
  10224. for (var i = 0, ii = states.length; i < ii; i++) {
  10225. var state = states[i];
  10226. var key = state[0];
  10227. var value = state[1];
  10228. switch (key) {
  10229. case 'LW':
  10230. this.setLineWidth(value);
  10231. break;
  10232. case 'LC':
  10233. this.setLineCap(value);
  10234. break;
  10235. case 'LJ':
  10236. this.setLineJoin(value);
  10237. break;
  10238. case 'ML':
  10239. this.setMiterLimit(value);
  10240. break;
  10241. case 'D':
  10242. this.setDash(value[0], value[1]);
  10243. break;
  10244. case 'RI':
  10245. this.setRenderingIntent(value);
  10246. break;
  10247. case 'FL':
  10248. this.setFlatness(value);
  10249. break;
  10250. case 'Font':
  10251. this.setFont(value[0], value[1]);
  10252. break;
  10253. case 'CA':
  10254. this.current.strokeAlpha = state[1];
  10255. break;
  10256. case 'ca':
  10257. this.current.fillAlpha = state[1];
  10258. this.ctx.globalAlpha = state[1];
  10259. break;
  10260. case 'BM':
  10261. this.ctx.globalCompositeOperation = value;
  10262. break;
  10263. case 'SMask':
  10264. if (this.current.activeSMask) {
  10265. if (this.stateStack.length > 0 && this.stateStack[this.stateStack.length - 1].activeSMask === this.current.activeSMask) {
  10266. this.suspendSMaskGroup();
  10267. } else {
  10268. this.endSMaskGroup();
  10269. }
  10270. }
  10271. this.current.activeSMask = value ? this.tempSMask : null;
  10272. if (this.current.activeSMask) {
  10273. this.beginSMaskGroup();
  10274. }
  10275. this.tempSMask = null;
  10276. break;
  10277. }
  10278. }
  10279. },
  10280. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  10281. var activeSMask = this.current.activeSMask;
  10282. var drawnWidth = activeSMask.canvas.width;
  10283. var drawnHeight = activeSMask.canvas.height;
  10284. var cacheId = 'smaskGroupAt' + this.groupLevel;
  10285. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  10286. var currentCtx = this.ctx;
  10287. var currentTransform = currentCtx.mozCurrentTransform;
  10288. this.ctx.save();
  10289. var groupCtx = scratchCanvas.context;
  10290. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  10291. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  10292. groupCtx.transform.apply(groupCtx, currentTransform);
  10293. activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse;
  10294. copyCtxState(currentCtx, groupCtx);
  10295. this.ctx = groupCtx;
  10296. this.setGState([['BM', 'source-over'], ['ca', 1], ['CA', 1]]);
  10297. this.groupStack.push(currentCtx);
  10298. this.groupLevel++;
  10299. },
  10300. suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  10301. var groupCtx = this.ctx;
  10302. this.groupLevel--;
  10303. this.ctx = this.groupStack.pop();
  10304. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  10305. this.ctx.restore();
  10306. this.ctx.save();
  10307. copyCtxState(groupCtx, this.ctx);
  10308. this.current.resumeSMaskCtx = groupCtx;
  10309. var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  10310. this.ctx.transform.apply(this.ctx, deltaTransform);
  10311. groupCtx.save();
  10312. groupCtx.setTransform(1, 0, 0, 1, 0, 0);
  10313. groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
  10314. groupCtx.restore();
  10315. },
  10316. resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  10317. var groupCtx = this.current.resumeSMaskCtx;
  10318. var currentCtx = this.ctx;
  10319. this.ctx = groupCtx;
  10320. this.groupStack.push(currentCtx);
  10321. this.groupLevel++;
  10322. },
  10323. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  10324. var groupCtx = this.ctx;
  10325. this.groupLevel--;
  10326. this.ctx = this.groupStack.pop();
  10327. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  10328. this.ctx.restore();
  10329. copyCtxState(groupCtx, this.ctx);
  10330. var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  10331. this.ctx.transform.apply(this.ctx, deltaTransform);
  10332. },
  10333. save: function CanvasGraphics_save() {
  10334. this.ctx.save();
  10335. var old = this.current;
  10336. this.stateStack.push(old);
  10337. this.current = old.clone();
  10338. this.current.resumeSMaskCtx = null;
  10339. },
  10340. restore: function CanvasGraphics_restore() {
  10341. if (this.current.resumeSMaskCtx) {
  10342. this.resumeSMaskGroup();
  10343. }
  10344. if (this.current.activeSMask !== null && (this.stateStack.length === 0 || this.stateStack[this.stateStack.length - 1].activeSMask !== this.current.activeSMask)) {
  10345. this.endSMaskGroup();
  10346. }
  10347. if (this.stateStack.length !== 0) {
  10348. this.current = this.stateStack.pop();
  10349. this.ctx.restore();
  10350. this.pendingClip = null;
  10351. this.cachedGetSinglePixelWidth = null;
  10352. }
  10353. },
  10354. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  10355. this.ctx.transform(a, b, c, d, e, f);
  10356. this.cachedGetSinglePixelWidth = null;
  10357. },
  10358. constructPath: function CanvasGraphics_constructPath(ops, args) {
  10359. var ctx = this.ctx;
  10360. var current = this.current;
  10361. var x = current.x,
  10362. y = current.y;
  10363. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  10364. switch (ops[i] | 0) {
  10365. case _util.OPS.rectangle:
  10366. x = args[j++];
  10367. y = args[j++];
  10368. var width = args[j++];
  10369. var height = args[j++];
  10370. if (width === 0) {
  10371. width = this.getSinglePixelWidth();
  10372. }
  10373. if (height === 0) {
  10374. height = this.getSinglePixelWidth();
  10375. }
  10376. var xw = x + width;
  10377. var yh = y + height;
  10378. this.ctx.moveTo(x, y);
  10379. this.ctx.lineTo(xw, y);
  10380. this.ctx.lineTo(xw, yh);
  10381. this.ctx.lineTo(x, yh);
  10382. this.ctx.lineTo(x, y);
  10383. this.ctx.closePath();
  10384. break;
  10385. case _util.OPS.moveTo:
  10386. x = args[j++];
  10387. y = args[j++];
  10388. ctx.moveTo(x, y);
  10389. break;
  10390. case _util.OPS.lineTo:
  10391. x = args[j++];
  10392. y = args[j++];
  10393. ctx.lineTo(x, y);
  10394. break;
  10395. case _util.OPS.curveTo:
  10396. x = args[j + 4];
  10397. y = args[j + 5];
  10398. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  10399. j += 6;
  10400. break;
  10401. case _util.OPS.curveTo2:
  10402. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  10403. x = args[j + 2];
  10404. y = args[j + 3];
  10405. j += 4;
  10406. break;
  10407. case _util.OPS.curveTo3:
  10408. x = args[j + 2];
  10409. y = args[j + 3];
  10410. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  10411. j += 4;
  10412. break;
  10413. case _util.OPS.closePath:
  10414. ctx.closePath();
  10415. break;
  10416. }
  10417. }
  10418. current.setCurrentPoint(x, y);
  10419. },
  10420. closePath: function CanvasGraphics_closePath() {
  10421. this.ctx.closePath();
  10422. },
  10423. stroke: function CanvasGraphics_stroke(consumePath) {
  10424. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  10425. var ctx = this.ctx;
  10426. var strokeColor = this.current.strokeColor;
  10427. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth);
  10428. ctx.globalAlpha = this.current.strokeAlpha;
  10429. if (strokeColor && strokeColor.hasOwnProperty('type') && strokeColor.type === 'Pattern') {
  10430. ctx.save();
  10431. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  10432. ctx.stroke();
  10433. ctx.restore();
  10434. } else {
  10435. ctx.stroke();
  10436. }
  10437. if (consumePath) {
  10438. this.consumePath();
  10439. }
  10440. ctx.globalAlpha = this.current.fillAlpha;
  10441. },
  10442. closeStroke: function CanvasGraphics_closeStroke() {
  10443. this.closePath();
  10444. this.stroke();
  10445. },
  10446. fill: function CanvasGraphics_fill(consumePath) {
  10447. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  10448. var ctx = this.ctx;
  10449. var fillColor = this.current.fillColor;
  10450. var isPatternFill = this.current.patternFill;
  10451. var needRestore = false;
  10452. if (isPatternFill) {
  10453. ctx.save();
  10454. if (this.baseTransform) {
  10455. ctx.setTransform.apply(ctx, this.baseTransform);
  10456. }
  10457. ctx.fillStyle = fillColor.getPattern(ctx, this);
  10458. needRestore = true;
  10459. }
  10460. if (this.pendingEOFill) {
  10461. ctx.fill('evenodd');
  10462. this.pendingEOFill = false;
  10463. } else {
  10464. ctx.fill();
  10465. }
  10466. if (needRestore) {
  10467. ctx.restore();
  10468. }
  10469. if (consumePath) {
  10470. this.consumePath();
  10471. }
  10472. },
  10473. eoFill: function CanvasGraphics_eoFill() {
  10474. this.pendingEOFill = true;
  10475. this.fill();
  10476. },
  10477. fillStroke: function CanvasGraphics_fillStroke() {
  10478. this.fill(false);
  10479. this.stroke(false);
  10480. this.consumePath();
  10481. },
  10482. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  10483. this.pendingEOFill = true;
  10484. this.fillStroke();
  10485. },
  10486. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  10487. this.closePath();
  10488. this.fillStroke();
  10489. },
  10490. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  10491. this.pendingEOFill = true;
  10492. this.closePath();
  10493. this.fillStroke();
  10494. },
  10495. endPath: function CanvasGraphics_endPath() {
  10496. this.consumePath();
  10497. },
  10498. clip: function CanvasGraphics_clip() {
  10499. this.pendingClip = NORMAL_CLIP;
  10500. },
  10501. eoClip: function CanvasGraphics_eoClip() {
  10502. this.pendingClip = EO_CLIP;
  10503. },
  10504. beginText: function CanvasGraphics_beginText() {
  10505. this.current.textMatrix = _util.IDENTITY_MATRIX;
  10506. this.current.textMatrixScale = 1;
  10507. this.current.x = this.current.lineX = 0;
  10508. this.current.y = this.current.lineY = 0;
  10509. },
  10510. endText: function CanvasGraphics_endText() {
  10511. var paths = this.pendingTextPaths;
  10512. var ctx = this.ctx;
  10513. if (paths === undefined) {
  10514. ctx.beginPath();
  10515. return;
  10516. }
  10517. ctx.save();
  10518. ctx.beginPath();
  10519. for (var i = 0; i < paths.length; i++) {
  10520. var path = paths[i];
  10521. ctx.setTransform.apply(ctx, path.transform);
  10522. ctx.translate(path.x, path.y);
  10523. path.addToPath(ctx, path.fontSize);
  10524. }
  10525. ctx.restore();
  10526. ctx.clip();
  10527. ctx.beginPath();
  10528. delete this.pendingTextPaths;
  10529. },
  10530. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  10531. this.current.charSpacing = spacing;
  10532. },
  10533. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  10534. this.current.wordSpacing = spacing;
  10535. },
  10536. setHScale: function CanvasGraphics_setHScale(scale) {
  10537. this.current.textHScale = scale / 100;
  10538. },
  10539. setLeading: function CanvasGraphics_setLeading(leading) {
  10540. this.current.leading = -leading;
  10541. },
  10542. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  10543. var fontObj = this.commonObjs.get(fontRefName);
  10544. var current = this.current;
  10545. if (!fontObj) {
  10546. throw new Error('Can\'t find font for ' + fontRefName);
  10547. }
  10548. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
  10549. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  10550. (0, _util.warn)('Invalid font matrix for font ' + fontRefName);
  10551. }
  10552. if (size < 0) {
  10553. size = -size;
  10554. current.fontDirection = -1;
  10555. } else {
  10556. current.fontDirection = 1;
  10557. }
  10558. this.current.font = fontObj;
  10559. this.current.fontSize = size;
  10560. if (fontObj.isType3Font) {
  10561. return;
  10562. }
  10563. var name = fontObj.loadedName || 'sans-serif';
  10564. var bold = fontObj.black ? '900' : fontObj.bold ? 'bold' : 'normal';
  10565. var italic = fontObj.italic ? 'italic' : 'normal';
  10566. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  10567. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE : size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  10568. this.current.fontSizeScale = size / browserFontSize;
  10569. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  10570. this.ctx.font = rule;
  10571. },
  10572. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  10573. this.current.textRenderingMode = mode;
  10574. },
  10575. setTextRise: function CanvasGraphics_setTextRise(rise) {
  10576. this.current.textRise = rise;
  10577. },
  10578. moveText: function CanvasGraphics_moveText(x, y) {
  10579. this.current.x = this.current.lineX += x;
  10580. this.current.y = this.current.lineY += y;
  10581. },
  10582. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  10583. this.setLeading(-y);
  10584. this.moveText(x, y);
  10585. },
  10586. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  10587. this.current.textMatrix = [a, b, c, d, e, f];
  10588. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  10589. this.current.x = this.current.lineX = 0;
  10590. this.current.y = this.current.lineY = 0;
  10591. },
  10592. nextLine: function CanvasGraphics_nextLine() {
  10593. this.moveText(0, this.current.leading);
  10594. },
  10595. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  10596. var ctx = this.ctx;
  10597. var current = this.current;
  10598. var font = current.font;
  10599. var textRenderingMode = current.textRenderingMode;
  10600. var fontSize = current.fontSize / current.fontSizeScale;
  10601. var fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  10602. var isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
  10603. var addToPath;
  10604. if (font.disableFontFace || isAddToPathSet) {
  10605. addToPath = font.getPathGenerator(this.commonObjs, character);
  10606. }
  10607. if (font.disableFontFace) {
  10608. ctx.save();
  10609. ctx.translate(x, y);
  10610. ctx.beginPath();
  10611. addToPath(ctx, fontSize);
  10612. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10613. ctx.fill();
  10614. }
  10615. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10616. ctx.stroke();
  10617. }
  10618. ctx.restore();
  10619. } else {
  10620. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10621. ctx.fillText(character, x, y);
  10622. }
  10623. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10624. ctx.strokeText(character, x, y);
  10625. }
  10626. }
  10627. if (isAddToPathSet) {
  10628. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  10629. paths.push({
  10630. transform: ctx.mozCurrentTransform,
  10631. x: x,
  10632. y: y,
  10633. fontSize: fontSize,
  10634. addToPath: addToPath
  10635. });
  10636. }
  10637. },
  10638. get isFontSubpixelAAEnabled() {
  10639. var ctx = this.canvasFactory.create(10, 10).context;
  10640. ctx.scale(1.5, 1);
  10641. ctx.fillText('I', 0, 10);
  10642. var data = ctx.getImageData(0, 0, 10, 10).data;
  10643. var enabled = false;
  10644. for (var i = 3; i < data.length; i += 4) {
  10645. if (data[i] > 0 && data[i] < 255) {
  10646. enabled = true;
  10647. break;
  10648. }
  10649. }
  10650. return (0, _util.shadow)(this, 'isFontSubpixelAAEnabled', enabled);
  10651. },
  10652. showText: function CanvasGraphics_showText(glyphs) {
  10653. var current = this.current;
  10654. var font = current.font;
  10655. if (font.isType3Font) {
  10656. return this.showType3Text(glyphs);
  10657. }
  10658. var fontSize = current.fontSize;
  10659. if (fontSize === 0) {
  10660. return;
  10661. }
  10662. var ctx = this.ctx;
  10663. var fontSizeScale = current.fontSizeScale;
  10664. var charSpacing = current.charSpacing;
  10665. var wordSpacing = current.wordSpacing;
  10666. var fontDirection = current.fontDirection;
  10667. var textHScale = current.textHScale * fontDirection;
  10668. var glyphsLength = glyphs.length;
  10669. var vertical = font.vertical;
  10670. var spacingDir = vertical ? 1 : -1;
  10671. var defaultVMetrics = font.defaultVMetrics;
  10672. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  10673. var simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace;
  10674. ctx.save();
  10675. ctx.transform.apply(ctx, current.textMatrix);
  10676. ctx.translate(current.x, current.y + current.textRise);
  10677. if (current.patternFill) {
  10678. ctx.fillStyle = current.fillColor.getPattern(ctx, this);
  10679. }
  10680. if (fontDirection > 0) {
  10681. ctx.scale(textHScale, -1);
  10682. } else {
  10683. ctx.scale(textHScale, 1);
  10684. }
  10685. var lineWidth = current.lineWidth;
  10686. var scale = current.textMatrixScale;
  10687. if (scale === 0 || lineWidth === 0) {
  10688. var fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  10689. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  10690. this.cachedGetSinglePixelWidth = null;
  10691. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  10692. }
  10693. } else {
  10694. lineWidth /= scale;
  10695. }
  10696. if (fontSizeScale !== 1.0) {
  10697. ctx.scale(fontSizeScale, fontSizeScale);
  10698. lineWidth /= fontSizeScale;
  10699. }
  10700. ctx.lineWidth = lineWidth;
  10701. var x = 0,
  10702. i;
  10703. for (i = 0; i < glyphsLength; ++i) {
  10704. var glyph = glyphs[i];
  10705. if ((0, _util.isNum)(glyph)) {
  10706. x += spacingDir * glyph * fontSize / 1000;
  10707. continue;
  10708. }
  10709. var restoreNeeded = false;
  10710. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  10711. var character = glyph.fontChar;
  10712. var accent = glyph.accent;
  10713. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  10714. var width = glyph.width;
  10715. if (vertical) {
  10716. var vmetric, vx, vy;
  10717. vmetric = glyph.vmetric || defaultVMetrics;
  10718. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  10719. vx = -vx * widthAdvanceScale;
  10720. vy = vmetric[2] * widthAdvanceScale;
  10721. width = vmetric ? -vmetric[0] : width;
  10722. scaledX = vx / fontSizeScale;
  10723. scaledY = (x + vy) / fontSizeScale;
  10724. } else {
  10725. scaledX = x / fontSizeScale;
  10726. scaledY = 0;
  10727. }
  10728. if (font.remeasure && width > 0) {
  10729. var measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  10730. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  10731. var characterScaleX = width / measuredWidth;
  10732. restoreNeeded = true;
  10733. ctx.save();
  10734. ctx.scale(characterScaleX, 1);
  10735. scaledX /= characterScaleX;
  10736. } else if (width !== measuredWidth) {
  10737. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  10738. }
  10739. }
  10740. if (glyph.isInFont || font.missingFile) {
  10741. if (simpleFillText && !accent) {
  10742. ctx.fillText(character, scaledX, scaledY);
  10743. } else {
  10744. this.paintChar(character, scaledX, scaledY);
  10745. if (accent) {
  10746. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  10747. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  10748. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  10749. }
  10750. }
  10751. }
  10752. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  10753. x += charWidth;
  10754. if (restoreNeeded) {
  10755. ctx.restore();
  10756. }
  10757. }
  10758. if (vertical) {
  10759. current.y -= x * textHScale;
  10760. } else {
  10761. current.x += x * textHScale;
  10762. }
  10763. ctx.restore();
  10764. },
  10765. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  10766. var ctx = this.ctx;
  10767. var current = this.current;
  10768. var font = current.font;
  10769. var fontSize = current.fontSize;
  10770. var fontDirection = current.fontDirection;
  10771. var spacingDir = font.vertical ? 1 : -1;
  10772. var charSpacing = current.charSpacing;
  10773. var wordSpacing = current.wordSpacing;
  10774. var textHScale = current.textHScale * fontDirection;
  10775. var fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  10776. var glyphsLength = glyphs.length;
  10777. var isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
  10778. var i, glyph, width, spacingLength;
  10779. if (isTextInvisible || fontSize === 0) {
  10780. return;
  10781. }
  10782. this.cachedGetSinglePixelWidth = null;
  10783. ctx.save();
  10784. ctx.transform.apply(ctx, current.textMatrix);
  10785. ctx.translate(current.x, current.y);
  10786. ctx.scale(textHScale, fontDirection);
  10787. for (i = 0; i < glyphsLength; ++i) {
  10788. glyph = glyphs[i];
  10789. if ((0, _util.isNum)(glyph)) {
  10790. spacingLength = spacingDir * glyph * fontSize / 1000;
  10791. this.ctx.translate(spacingLength, 0);
  10792. current.x += spacingLength * textHScale;
  10793. continue;
  10794. }
  10795. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  10796. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  10797. if (!operatorList) {
  10798. (0, _util.warn)('Type3 character "' + glyph.operatorListId + '" is not available.');
  10799. continue;
  10800. }
  10801. this.processingType3 = glyph;
  10802. this.save();
  10803. ctx.scale(fontSize, fontSize);
  10804. ctx.transform.apply(ctx, fontMatrix);
  10805. this.executeOperatorList(operatorList);
  10806. this.restore();
  10807. var transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
  10808. width = transformed[0] * fontSize + spacing;
  10809. ctx.translate(width, 0);
  10810. current.x += width * textHScale;
  10811. }
  10812. ctx.restore();
  10813. this.processingType3 = null;
  10814. },
  10815. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {},
  10816. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  10817. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  10818. this.clip();
  10819. this.endPath();
  10820. },
  10821. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  10822. var _this = this;
  10823. var pattern;
  10824. if (IR[0] === 'TilingPattern') {
  10825. var color = IR[1];
  10826. var baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
  10827. var canvasGraphicsFactory = {
  10828. createCanvasGraphics: function createCanvasGraphics(ctx) {
  10829. return new CanvasGraphics(ctx, _this.commonObjs, _this.objs, _this.canvasFactory);
  10830. }
  10831. };
  10832. pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  10833. } else {
  10834. pattern = (0, _pattern_helper.getShadingPatternFromIR)(IR);
  10835. }
  10836. return pattern;
  10837. },
  10838. setStrokeColorN: function CanvasGraphics_setStrokeColorN() {
  10839. this.current.strokeColor = this.getColorN_Pattern(arguments);
  10840. },
  10841. setFillColorN: function CanvasGraphics_setFillColorN() {
  10842. this.current.fillColor = this.getColorN_Pattern(arguments);
  10843. this.current.patternFill = true;
  10844. },
  10845. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  10846. var color = _util.Util.makeCssRgb(r, g, b);
  10847. this.ctx.strokeStyle = color;
  10848. this.current.strokeColor = color;
  10849. },
  10850. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  10851. var color = _util.Util.makeCssRgb(r, g, b);
  10852. this.ctx.fillStyle = color;
  10853. this.current.fillColor = color;
  10854. this.current.patternFill = false;
  10855. },
  10856. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  10857. var ctx = this.ctx;
  10858. this.save();
  10859. var pattern = (0, _pattern_helper.getShadingPatternFromIR)(patternIR);
  10860. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  10861. var inv = ctx.mozCurrentTransformInverse;
  10862. if (inv) {
  10863. var canvas = ctx.canvas;
  10864. var width = canvas.width;
  10865. var height = canvas.height;
  10866. var bl = _util.Util.applyTransform([0, 0], inv);
  10867. var br = _util.Util.applyTransform([0, height], inv);
  10868. var ul = _util.Util.applyTransform([width, 0], inv);
  10869. var ur = _util.Util.applyTransform([width, height], inv);
  10870. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  10871. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  10872. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  10873. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  10874. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  10875. } else {
  10876. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  10877. }
  10878. this.restore();
  10879. },
  10880. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  10881. throw new Error('Should not call beginInlineImage');
  10882. },
  10883. beginImageData: function CanvasGraphics_beginImageData() {
  10884. throw new Error('Should not call beginImageData');
  10885. },
  10886. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, bbox) {
  10887. this.save();
  10888. this.baseTransformStack.push(this.baseTransform);
  10889. if ((0, _util.isArray)(matrix) && matrix.length === 6) {
  10890. this.transform.apply(this, matrix);
  10891. }
  10892. this.baseTransform = this.ctx.mozCurrentTransform;
  10893. if ((0, _util.isArray)(bbox) && bbox.length === 4) {
  10894. var width = bbox[2] - bbox[0];
  10895. var height = bbox[3] - bbox[1];
  10896. this.ctx.rect(bbox[0], bbox[1], width, height);
  10897. this.clip();
  10898. this.endPath();
  10899. }
  10900. },
  10901. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  10902. this.restore();
  10903. this.baseTransform = this.baseTransformStack.pop();
  10904. },
  10905. beginGroup: function CanvasGraphics_beginGroup(group) {
  10906. this.save();
  10907. var currentCtx = this.ctx;
  10908. if (!group.isolated) {
  10909. (0, _util.info)('TODO: Support non-isolated groups.');
  10910. }
  10911. if (group.knockout) {
  10912. (0, _util.warn)('Knockout groups not supported.');
  10913. }
  10914. var currentTransform = currentCtx.mozCurrentTransform;
  10915. if (group.matrix) {
  10916. currentCtx.transform.apply(currentCtx, group.matrix);
  10917. }
  10918. if (!group.bbox) {
  10919. throw new Error('Bounding box is required.');
  10920. }
  10921. var bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
  10922. var canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  10923. bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  10924. var offsetX = Math.floor(bounds[0]);
  10925. var offsetY = Math.floor(bounds[1]);
  10926. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  10927. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  10928. var scaleX = 1,
  10929. scaleY = 1;
  10930. if (drawnWidth > MAX_GROUP_SIZE) {
  10931. scaleX = drawnWidth / MAX_GROUP_SIZE;
  10932. drawnWidth = MAX_GROUP_SIZE;
  10933. }
  10934. if (drawnHeight > MAX_GROUP_SIZE) {
  10935. scaleY = drawnHeight / MAX_GROUP_SIZE;
  10936. drawnHeight = MAX_GROUP_SIZE;
  10937. }
  10938. var cacheId = 'groupAt' + this.groupLevel;
  10939. if (group.smask) {
  10940. cacheId += '_smask_' + this.smaskCounter++ % 2;
  10941. }
  10942. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  10943. var groupCtx = scratchCanvas.context;
  10944. groupCtx.scale(1 / scaleX, 1 / scaleY);
  10945. groupCtx.translate(-offsetX, -offsetY);
  10946. groupCtx.transform.apply(groupCtx, currentTransform);
  10947. if (group.smask) {
  10948. this.smaskStack.push({
  10949. canvas: scratchCanvas.canvas,
  10950. context: groupCtx,
  10951. offsetX: offsetX,
  10952. offsetY: offsetY,
  10953. scaleX: scaleX,
  10954. scaleY: scaleY,
  10955. subtype: group.smask.subtype,
  10956. backdrop: group.smask.backdrop,
  10957. transferMap: group.smask.transferMap || null,
  10958. startTransformInverse: null
  10959. });
  10960. } else {
  10961. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  10962. currentCtx.translate(offsetX, offsetY);
  10963. currentCtx.scale(scaleX, scaleY);
  10964. }
  10965. copyCtxState(currentCtx, groupCtx);
  10966. this.ctx = groupCtx;
  10967. this.setGState([['BM', 'source-over'], ['ca', 1], ['CA', 1]]);
  10968. this.groupStack.push(currentCtx);
  10969. this.groupLevel++;
  10970. this.current.activeSMask = null;
  10971. },
  10972. endGroup: function CanvasGraphics_endGroup(group) {
  10973. this.groupLevel--;
  10974. var groupCtx = this.ctx;
  10975. this.ctx = this.groupStack.pop();
  10976. if (this.ctx.imageSmoothingEnabled !== undefined) {
  10977. this.ctx.imageSmoothingEnabled = false;
  10978. } else {
  10979. this.ctx.mozImageSmoothingEnabled = false;
  10980. }
  10981. if (group.smask) {
  10982. this.tempSMask = this.smaskStack.pop();
  10983. } else {
  10984. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  10985. }
  10986. this.restore();
  10987. },
  10988. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  10989. this.save();
  10990. if (this.baseTransform) {
  10991. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  10992. }
  10993. },
  10994. endAnnotations: function CanvasGraphics_endAnnotations() {
  10995. this.restore();
  10996. },
  10997. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform, matrix) {
  10998. this.save();
  10999. resetCtxToDefault(this.ctx);
  11000. this.current = new CanvasExtraState();
  11001. if ((0, _util.isArray)(rect) && rect.length === 4) {
  11002. var width = rect[2] - rect[0];
  11003. var height = rect[3] - rect[1];
  11004. this.ctx.rect(rect[0], rect[1], width, height);
  11005. this.clip();
  11006. this.endPath();
  11007. }
  11008. this.transform.apply(this, transform);
  11009. this.transform.apply(this, matrix);
  11010. },
  11011. endAnnotation: function CanvasGraphics_endAnnotation() {
  11012. this.restore();
  11013. },
  11014. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  11015. var domImage = this.objs.get(objId);
  11016. if (!domImage) {
  11017. (0, _util.warn)('Dependent image isn\'t ready yet');
  11018. return;
  11019. }
  11020. this.save();
  11021. var ctx = this.ctx;
  11022. ctx.scale(1 / w, -1 / h);
  11023. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height, 0, -h, w, h);
  11024. if (this.imageLayer) {
  11025. var currentTransform = ctx.mozCurrentTransformInverse;
  11026. var position = this.getCanvasPosition(0, 0);
  11027. this.imageLayer.appendImage({
  11028. objId: objId,
  11029. left: position[0],
  11030. top: position[1],
  11031. width: w / currentTransform[0],
  11032. height: h / currentTransform[3]
  11033. });
  11034. }
  11035. this.restore();
  11036. },
  11037. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  11038. var ctx = this.ctx;
  11039. var width = img.width,
  11040. height = img.height;
  11041. var fillColor = this.current.fillColor;
  11042. var isPatternFill = this.current.patternFill;
  11043. var glyph = this.processingType3;
  11044. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  11045. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  11046. glyph.compiled = compileType3Glyph({
  11047. data: img.data,
  11048. width: width,
  11049. height: height
  11050. });
  11051. } else {
  11052. glyph.compiled = null;
  11053. }
  11054. }
  11055. if (glyph && glyph.compiled) {
  11056. glyph.compiled(ctx);
  11057. return;
  11058. }
  11059. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  11060. var maskCtx = maskCanvas.context;
  11061. maskCtx.save();
  11062. putBinaryImageMask(maskCtx, img);
  11063. maskCtx.globalCompositeOperation = 'source-in';
  11064. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  11065. maskCtx.fillRect(0, 0, width, height);
  11066. maskCtx.restore();
  11067. this.paintInlineImageXObject(maskCanvas.canvas);
  11068. },
  11069. paintImageMaskXObjectRepeat: function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX, scaleY, positions) {
  11070. var width = imgData.width;
  11071. var height = imgData.height;
  11072. var fillColor = this.current.fillColor;
  11073. var isPatternFill = this.current.patternFill;
  11074. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  11075. var maskCtx = maskCanvas.context;
  11076. maskCtx.save();
  11077. putBinaryImageMask(maskCtx, imgData);
  11078. maskCtx.globalCompositeOperation = 'source-in';
  11079. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  11080. maskCtx.fillRect(0, 0, width, height);
  11081. maskCtx.restore();
  11082. var ctx = this.ctx;
  11083. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  11084. ctx.save();
  11085. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  11086. ctx.scale(1, -1);
  11087. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  11088. ctx.restore();
  11089. }
  11090. },
  11091. paintImageMaskXObjectGroup: function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  11092. var ctx = this.ctx;
  11093. var fillColor = this.current.fillColor;
  11094. var isPatternFill = this.current.patternFill;
  11095. for (var i = 0, ii = images.length; i < ii; i++) {
  11096. var image = images[i];
  11097. var width = image.width,
  11098. height = image.height;
  11099. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  11100. var maskCtx = maskCanvas.context;
  11101. maskCtx.save();
  11102. putBinaryImageMask(maskCtx, image);
  11103. maskCtx.globalCompositeOperation = 'source-in';
  11104. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  11105. maskCtx.fillRect(0, 0, width, height);
  11106. maskCtx.restore();
  11107. ctx.save();
  11108. ctx.transform.apply(ctx, image.transform);
  11109. ctx.scale(1, -1);
  11110. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  11111. ctx.restore();
  11112. }
  11113. },
  11114. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  11115. var imgData = this.objs.get(objId);
  11116. if (!imgData) {
  11117. (0, _util.warn)('Dependent image isn\'t ready yet');
  11118. return;
  11119. }
  11120. this.paintInlineImageXObject(imgData);
  11121. },
  11122. paintImageXObjectRepeat: function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  11123. var imgData = this.objs.get(objId);
  11124. if (!imgData) {
  11125. (0, _util.warn)('Dependent image isn\'t ready yet');
  11126. return;
  11127. }
  11128. var width = imgData.width;
  11129. var height = imgData.height;
  11130. var map = [];
  11131. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  11132. map.push({
  11133. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  11134. x: 0,
  11135. y: 0,
  11136. w: width,
  11137. h: height
  11138. });
  11139. }
  11140. this.paintInlineImageXObjectGroup(imgData, map);
  11141. },
  11142. paintInlineImageXObject: function CanvasGraphics_paintInlineImageXObject(imgData) {
  11143. var width = imgData.width;
  11144. var height = imgData.height;
  11145. var ctx = this.ctx;
  11146. this.save();
  11147. ctx.scale(1 / width, -1 / height);
  11148. var currentTransform = ctx.mozCurrentTransformInverse;
  11149. var a = currentTransform[0],
  11150. b = currentTransform[1];
  11151. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  11152. var c = currentTransform[2],
  11153. d = currentTransform[3];
  11154. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  11155. var imgToPaint, tmpCanvas;
  11156. if (imgData instanceof HTMLElement || !imgData.data) {
  11157. imgToPaint = imgData;
  11158. } else {
  11159. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', width, height);
  11160. var tmpCtx = tmpCanvas.context;
  11161. putBinaryImageData(tmpCtx, imgData);
  11162. imgToPaint = tmpCanvas.canvas;
  11163. }
  11164. var paintWidth = width,
  11165. paintHeight = height;
  11166. var tmpCanvasId = 'prescale1';
  11167. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  11168. var newWidth = paintWidth,
  11169. newHeight = paintHeight;
  11170. if (widthScale > 2 && paintWidth > 1) {
  11171. newWidth = Math.ceil(paintWidth / 2);
  11172. widthScale /= paintWidth / newWidth;
  11173. }
  11174. if (heightScale > 2 && paintHeight > 1) {
  11175. newHeight = Math.ceil(paintHeight / 2);
  11176. heightScale /= paintHeight / newHeight;
  11177. }
  11178. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  11179. tmpCtx = tmpCanvas.context;
  11180. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  11181. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  11182. imgToPaint = tmpCanvas.canvas;
  11183. paintWidth = newWidth;
  11184. paintHeight = newHeight;
  11185. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  11186. }
  11187. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height);
  11188. if (this.imageLayer) {
  11189. var position = this.getCanvasPosition(0, -height);
  11190. this.imageLayer.appendImage({
  11191. imgData: imgData,
  11192. left: position[0],
  11193. top: position[1],
  11194. width: width / currentTransform[0],
  11195. height: height / currentTransform[3]
  11196. });
  11197. }
  11198. this.restore();
  11199. },
  11200. paintInlineImageXObjectGroup: function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  11201. var ctx = this.ctx;
  11202. var w = imgData.width;
  11203. var h = imgData.height;
  11204. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  11205. var tmpCtx = tmpCanvas.context;
  11206. putBinaryImageData(tmpCtx, imgData);
  11207. for (var i = 0, ii = map.length; i < ii; i++) {
  11208. var entry = map[i];
  11209. ctx.save();
  11210. ctx.transform.apply(ctx, entry.transform);
  11211. ctx.scale(1, -1);
  11212. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  11213. if (this.imageLayer) {
  11214. var position = this.getCanvasPosition(entry.x, entry.y);
  11215. this.imageLayer.appendImage({
  11216. imgData: imgData,
  11217. left: position[0],
  11218. top: position[1],
  11219. width: w,
  11220. height: h
  11221. });
  11222. }
  11223. ctx.restore();
  11224. }
  11225. },
  11226. paintSolidColorImageMask: function CanvasGraphics_paintSolidColorImageMask() {
  11227. this.ctx.fillRect(0, 0, 1, 1);
  11228. },
  11229. paintXObject: function CanvasGraphics_paintXObject() {
  11230. (0, _util.warn)('Unsupported \'paintXObject\' command.');
  11231. },
  11232. markPoint: function CanvasGraphics_markPoint(tag) {},
  11233. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {},
  11234. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {},
  11235. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(tag, properties) {},
  11236. endMarkedContent: function CanvasGraphics_endMarkedContent() {},
  11237. beginCompat: function CanvasGraphics_beginCompat() {},
  11238. endCompat: function CanvasGraphics_endCompat() {},
  11239. consumePath: function CanvasGraphics_consumePath() {
  11240. var ctx = this.ctx;
  11241. if (this.pendingClip) {
  11242. if (this.pendingClip === EO_CLIP) {
  11243. ctx.clip('evenodd');
  11244. } else {
  11245. ctx.clip();
  11246. }
  11247. this.pendingClip = null;
  11248. }
  11249. ctx.beginPath();
  11250. },
  11251. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  11252. if (this.cachedGetSinglePixelWidth === null) {
  11253. this.ctx.save();
  11254. var inverse = this.ctx.mozCurrentTransformInverse;
  11255. this.ctx.restore();
  11256. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(inverse[0] * inverse[0] + inverse[1] * inverse[1], inverse[2] * inverse[2] + inverse[3] * inverse[3]));
  11257. }
  11258. return this.cachedGetSinglePixelWidth;
  11259. },
  11260. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  11261. var transform = this.ctx.mozCurrentTransform;
  11262. return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]];
  11263. }
  11264. };
  11265. for (var op in _util.OPS) {
  11266. CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
  11267. }
  11268. return CanvasGraphics;
  11269. }();
  11270. exports.CanvasGraphics = CanvasGraphics;
  11271. /***/ }),
  11272. /* 12 */
  11273. /***/ (function(module, exports, __w_pdfjs_require__) {
  11274. "use strict";
  11275. Object.defineProperty(exports, "__esModule", {
  11276. value: true
  11277. });
  11278. exports.FontLoader = exports.FontFaceObject = undefined;
  11279. var _util = __w_pdfjs_require__(0);
  11280. function FontLoader(docId) {
  11281. this.docId = docId;
  11282. this.styleElement = null;
  11283. this.nativeFontFaces = [];
  11284. this.loadTestFontId = 0;
  11285. this.loadingContext = {
  11286. requests: [],
  11287. nextRequestId: 0
  11288. };
  11289. }
  11290. FontLoader.prototype = {
  11291. insertRule: function fontLoaderInsertRule(rule) {
  11292. var styleElement = this.styleElement;
  11293. if (!styleElement) {
  11294. styleElement = this.styleElement = document.createElement('style');
  11295. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  11296. document.documentElement.getElementsByTagName('head')[0].appendChild(styleElement);
  11297. }
  11298. var styleSheet = styleElement.sheet;
  11299. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  11300. },
  11301. clear: function fontLoaderClear() {
  11302. if (this.styleElement) {
  11303. this.styleElement.remove();
  11304. this.styleElement = null;
  11305. }
  11306. this.nativeFontFaces.forEach(function (nativeFontFace) {
  11307. document.fonts.delete(nativeFontFace);
  11308. });
  11309. this.nativeFontFaces.length = 0;
  11310. }
  11311. };
  11312. {
  11313. var getLoadTestFont = function getLoadTestFont() {
  11314. 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==');
  11315. };
  11316. Object.defineProperty(FontLoader.prototype, 'loadTestFont', {
  11317. get: function get() {
  11318. return (0, _util.shadow)(this, 'loadTestFont', getLoadTestFont());
  11319. },
  11320. configurable: true
  11321. });
  11322. FontLoader.prototype.addNativeFontFace = function fontLoader_addNativeFontFace(nativeFontFace) {
  11323. this.nativeFontFaces.push(nativeFontFace);
  11324. document.fonts.add(nativeFontFace);
  11325. };
  11326. FontLoader.prototype.bind = function fontLoaderBind(fonts, callback) {
  11327. var rules = [];
  11328. var fontsToLoad = [];
  11329. var fontLoadPromises = [];
  11330. var getNativeFontPromise = function getNativeFontPromise(nativeFontFace) {
  11331. return nativeFontFace.loaded.catch(function (e) {
  11332. (0, _util.warn)('Failed to load font "' + nativeFontFace.family + '": ' + e);
  11333. });
  11334. };
  11335. var isFontLoadingAPISupported = FontLoader.isFontLoadingAPISupported && !FontLoader.isSyncFontLoadingSupported;
  11336. for (var i = 0, ii = fonts.length; i < ii; i++) {
  11337. var font = fonts[i];
  11338. if (font.attached || font.loading === false) {
  11339. continue;
  11340. }
  11341. font.attached = true;
  11342. if (isFontLoadingAPISupported) {
  11343. var nativeFontFace = font.createNativeFontFace();
  11344. if (nativeFontFace) {
  11345. this.addNativeFontFace(nativeFontFace);
  11346. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  11347. }
  11348. } else {
  11349. var rule = font.createFontFaceRule();
  11350. if (rule) {
  11351. this.insertRule(rule);
  11352. rules.push(rule);
  11353. fontsToLoad.push(font);
  11354. }
  11355. }
  11356. }
  11357. var request = this.queueLoadingCallback(callback);
  11358. if (isFontLoadingAPISupported) {
  11359. Promise.all(fontLoadPromises).then(function () {
  11360. request.complete();
  11361. });
  11362. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  11363. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  11364. } else {
  11365. request.complete();
  11366. }
  11367. };
  11368. FontLoader.prototype.queueLoadingCallback = function FontLoader_queueLoadingCallback(callback) {
  11369. function LoadLoader_completeRequest() {
  11370. (0, _util.assert)(!request.end, 'completeRequest() cannot be called twice');
  11371. request.end = Date.now();
  11372. while (context.requests.length > 0 && context.requests[0].end) {
  11373. var otherRequest = context.requests.shift();
  11374. setTimeout(otherRequest.callback, 0);
  11375. }
  11376. }
  11377. var context = this.loadingContext;
  11378. var requestId = 'pdfjs-font-loading-' + context.nextRequestId++;
  11379. var request = {
  11380. id: requestId,
  11381. complete: LoadLoader_completeRequest,
  11382. callback: callback,
  11383. started: Date.now()
  11384. };
  11385. context.requests.push(request);
  11386. return request;
  11387. };
  11388. FontLoader.prototype.prepareFontLoadEvent = function fontLoaderPrepareFontLoadEvent(rules, fonts, request) {
  11389. function int32(data, offset) {
  11390. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  11391. }
  11392. function spliceString(s, offset, remove, insert) {
  11393. var chunk1 = s.substr(0, offset);
  11394. var chunk2 = s.substr(offset + remove);
  11395. return chunk1 + insert + chunk2;
  11396. }
  11397. var i, ii;
  11398. var canvas = document.createElement('canvas');
  11399. canvas.width = 1;
  11400. canvas.height = 1;
  11401. var ctx = canvas.getContext('2d');
  11402. var called = 0;
  11403. function isFontReady(name, callback) {
  11404. called++;
  11405. if (called > 30) {
  11406. (0, _util.warn)('Load test font never loaded.');
  11407. callback();
  11408. return;
  11409. }
  11410. ctx.font = '30px ' + name;
  11411. ctx.fillText('.', 0, 20);
  11412. var imageData = ctx.getImageData(0, 0, 1, 1);
  11413. if (imageData.data[3] > 0) {
  11414. callback();
  11415. return;
  11416. }
  11417. setTimeout(isFontReady.bind(null, name, callback));
  11418. }
  11419. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  11420. var data = this.loadTestFont;
  11421. var COMMENT_OFFSET = 976;
  11422. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  11423. var CFF_CHECKSUM_OFFSET = 16;
  11424. var XXXX_VALUE = 0x58585858;
  11425. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  11426. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  11427. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  11428. }
  11429. if (i < loadTestFontId.length) {
  11430. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + 'XXX', i) | 0;
  11431. }
  11432. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum));
  11433. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  11434. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' + url + '}';
  11435. this.insertRule(rule);
  11436. var names = [];
  11437. for (i = 0, ii = fonts.length; i < ii; i++) {
  11438. names.push(fonts[i].loadedName);
  11439. }
  11440. names.push(loadTestFontId);
  11441. var div = document.createElement('div');
  11442. div.setAttribute('style', 'visibility: hidden;' + 'width: 10px; height: 10px;' + 'position: absolute; top: 0px; left: 0px;');
  11443. for (i = 0, ii = names.length; i < ii; ++i) {
  11444. var span = document.createElement('span');
  11445. span.textContent = 'Hi';
  11446. span.style.fontFamily = names[i];
  11447. div.appendChild(span);
  11448. }
  11449. document.body.appendChild(div);
  11450. isFontReady(loadTestFontId, function () {
  11451. document.body.removeChild(div);
  11452. request.complete();
  11453. });
  11454. };
  11455. }
  11456. {
  11457. FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' && !!document.fonts;
  11458. }
  11459. {
  11460. var isSyncFontLoadingSupported = function isSyncFontLoadingSupported() {
  11461. if (typeof navigator === 'undefined') {
  11462. return true;
  11463. }
  11464. var supported = false;
  11465. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  11466. if (m && m[1] >= 14) {
  11467. supported = true;
  11468. }
  11469. return supported;
  11470. };
  11471. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  11472. get: function get() {
  11473. return (0, _util.shadow)(FontLoader, 'isSyncFontLoadingSupported', isSyncFontLoadingSupported());
  11474. },
  11475. enumerable: true,
  11476. configurable: true
  11477. });
  11478. }
  11479. var IsEvalSupportedCached = {
  11480. get value() {
  11481. return (0, _util.shadow)(this, 'value', (0, _util.isEvalSupported)());
  11482. }
  11483. };
  11484. var FontFaceObject = function FontFaceObjectClosure() {
  11485. function FontFaceObject(translatedData, options) {
  11486. this.compiledGlyphs = Object.create(null);
  11487. for (var i in translatedData) {
  11488. this[i] = translatedData[i];
  11489. }
  11490. this.options = options;
  11491. }
  11492. FontFaceObject.prototype = {
  11493. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  11494. if (!this.data) {
  11495. return null;
  11496. }
  11497. if (this.options.disableFontFace) {
  11498. this.disableFontFace = true;
  11499. return null;
  11500. }
  11501. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  11502. if (this.options.fontRegistry) {
  11503. this.options.fontRegistry.registerFont(this);
  11504. }
  11505. return nativeFontFace;
  11506. },
  11507. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  11508. if (!this.data) {
  11509. return null;
  11510. }
  11511. if (this.options.disableFontFace) {
  11512. this.disableFontFace = true;
  11513. return null;
  11514. }
  11515. var data = (0, _util.bytesToString)(new Uint8Array(this.data));
  11516. var fontName = this.loadedName;
  11517. var url = 'url(data:' + this.mimetype + ';base64,' + btoa(data) + ');';
  11518. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  11519. if (this.options.fontRegistry) {
  11520. this.options.fontRegistry.registerFont(this, url);
  11521. }
  11522. return rule;
  11523. },
  11524. getPathGenerator: function FontFaceObject_getPathGenerator(objs, character) {
  11525. if (!(character in this.compiledGlyphs)) {
  11526. var cmds = objs.get(this.loadedName + '_path_' + character);
  11527. var current, i, len;
  11528. if (this.options.isEvalSupported && IsEvalSupportedCached.value) {
  11529. var args,
  11530. js = '';
  11531. for (i = 0, len = cmds.length; i < len; i++) {
  11532. current = cmds[i];
  11533. if (current.args !== undefined) {
  11534. args = current.args.join(',');
  11535. } else {
  11536. args = '';
  11537. }
  11538. js += 'c.' + current.cmd + '(' + args + ');\n';
  11539. }
  11540. this.compiledGlyphs[character] = new Function('c', 'size', js);
  11541. } else {
  11542. this.compiledGlyphs[character] = function (c, size) {
  11543. for (i = 0, len = cmds.length; i < len; i++) {
  11544. current = cmds[i];
  11545. if (current.cmd === 'scale') {
  11546. current.args = [size, -size];
  11547. }
  11548. c[current.cmd].apply(c, current.args);
  11549. }
  11550. };
  11551. }
  11552. }
  11553. return this.compiledGlyphs[character];
  11554. }
  11555. };
  11556. return FontFaceObject;
  11557. }();
  11558. exports.FontFaceObject = FontFaceObject;
  11559. exports.FontLoader = FontLoader;
  11560. /***/ }),
  11561. /* 13 */
  11562. /***/ (function(module, exports, __w_pdfjs_require__) {
  11563. "use strict";
  11564. Object.defineProperty(exports, "__esModule", {
  11565. value: true
  11566. });
  11567. exports.TilingPattern = exports.getShadingPatternFromIR = undefined;
  11568. var _util = __w_pdfjs_require__(0);
  11569. var _webgl = __w_pdfjs_require__(7);
  11570. var ShadingIRs = {};
  11571. ShadingIRs.RadialAxial = {
  11572. fromIR: function RadialAxial_fromIR(raw) {
  11573. var type = raw[1];
  11574. var colorStops = raw[2];
  11575. var p0 = raw[3];
  11576. var p1 = raw[4];
  11577. var r0 = raw[5];
  11578. var r1 = raw[6];
  11579. return {
  11580. type: 'Pattern',
  11581. getPattern: function RadialAxial_getPattern(ctx) {
  11582. var grad;
  11583. if (type === 'axial') {
  11584. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  11585. } else if (type === 'radial') {
  11586. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  11587. }
  11588. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  11589. var c = colorStops[i];
  11590. grad.addColorStop(c[0], c[1]);
  11591. }
  11592. return grad;
  11593. }
  11594. };
  11595. }
  11596. };
  11597. var createMeshCanvas = function createMeshCanvasClosure() {
  11598. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  11599. var coords = context.coords,
  11600. colors = context.colors;
  11601. var bytes = data.data,
  11602. rowSize = data.width * 4;
  11603. var tmp;
  11604. if (coords[p1 + 1] > coords[p2 + 1]) {
  11605. tmp = p1;
  11606. p1 = p2;
  11607. p2 = tmp;
  11608. tmp = c1;
  11609. c1 = c2;
  11610. c2 = tmp;
  11611. }
  11612. if (coords[p2 + 1] > coords[p3 + 1]) {
  11613. tmp = p2;
  11614. p2 = p3;
  11615. p3 = tmp;
  11616. tmp = c2;
  11617. c2 = c3;
  11618. c3 = tmp;
  11619. }
  11620. if (coords[p1 + 1] > coords[p2 + 1]) {
  11621. tmp = p1;
  11622. p1 = p2;
  11623. p2 = tmp;
  11624. tmp = c1;
  11625. c1 = c2;
  11626. c2 = tmp;
  11627. }
  11628. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  11629. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  11630. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  11631. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  11632. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  11633. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  11634. if (y1 >= y3) {
  11635. return;
  11636. }
  11637. var c1r = colors[c1],
  11638. c1g = colors[c1 + 1],
  11639. c1b = colors[c1 + 2];
  11640. var c2r = colors[c2],
  11641. c2g = colors[c2 + 1],
  11642. c2b = colors[c2 + 2];
  11643. var c3r = colors[c3],
  11644. c3g = colors[c3 + 1],
  11645. c3b = colors[c3 + 2];
  11646. var minY = Math.round(y1),
  11647. maxY = Math.round(y3);
  11648. var xa, car, cag, cab;
  11649. var xb, cbr, cbg, cbb;
  11650. var k;
  11651. for (var y = minY; y <= maxY; y++) {
  11652. if (y < y2) {
  11653. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  11654. xa = x1 - (x1 - x2) * k;
  11655. car = c1r - (c1r - c2r) * k;
  11656. cag = c1g - (c1g - c2g) * k;
  11657. cab = c1b - (c1b - c2b) * k;
  11658. } else {
  11659. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  11660. xa = x2 - (x2 - x3) * k;
  11661. car = c2r - (c2r - c3r) * k;
  11662. cag = c2g - (c2g - c3g) * k;
  11663. cab = c2b - (c2b - c3b) * k;
  11664. }
  11665. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  11666. xb = x1 - (x1 - x3) * k;
  11667. cbr = c1r - (c1r - c3r) * k;
  11668. cbg = c1g - (c1g - c3g) * k;
  11669. cbb = c1b - (c1b - c3b) * k;
  11670. var x1_ = Math.round(Math.min(xa, xb));
  11671. var x2_ = Math.round(Math.max(xa, xb));
  11672. var j = rowSize * y + x1_ * 4;
  11673. for (var x = x1_; x <= x2_; x++) {
  11674. k = (xa - x) / (xa - xb);
  11675. k = k < 0 ? 0 : k > 1 ? 1 : k;
  11676. bytes[j++] = car - (car - cbr) * k | 0;
  11677. bytes[j++] = cag - (cag - cbg) * k | 0;
  11678. bytes[j++] = cab - (cab - cbb) * k | 0;
  11679. bytes[j++] = 255;
  11680. }
  11681. }
  11682. }
  11683. function drawFigure(data, figure, context) {
  11684. var ps = figure.coords;
  11685. var cs = figure.colors;
  11686. var i, ii;
  11687. switch (figure.type) {
  11688. case 'lattice':
  11689. var verticesPerRow = figure.verticesPerRow;
  11690. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  11691. var cols = verticesPerRow - 1;
  11692. for (i = 0; i < rows; i++) {
  11693. var q = i * verticesPerRow;
  11694. for (var j = 0; j < cols; j++, q++) {
  11695. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  11696. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  11697. }
  11698. }
  11699. break;
  11700. case 'triangles':
  11701. for (i = 0, ii = ps.length; i < ii; i += 3) {
  11702. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  11703. }
  11704. break;
  11705. default:
  11706. throw new Error('illegal figure');
  11707. }
  11708. }
  11709. function createMeshCanvas(bounds, combinesScale, coords, colors, figures, backgroundColor, cachedCanvases) {
  11710. var EXPECTED_SCALE = 1.1;
  11711. var MAX_PATTERN_SIZE = 3000;
  11712. var BORDER_SIZE = 2;
  11713. var offsetX = Math.floor(bounds[0]);
  11714. var offsetY = Math.floor(bounds[1]);
  11715. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  11716. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  11717. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  11718. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  11719. var scaleX = boundsWidth / width;
  11720. var scaleY = boundsHeight / height;
  11721. var context = {
  11722. coords: coords,
  11723. colors: colors,
  11724. offsetX: -offsetX,
  11725. offsetY: -offsetY,
  11726. scaleX: 1 / scaleX,
  11727. scaleY: 1 / scaleY
  11728. };
  11729. var paddedWidth = width + BORDER_SIZE * 2;
  11730. var paddedHeight = height + BORDER_SIZE * 2;
  11731. var canvas, tmpCanvas, i, ii;
  11732. if (_webgl.WebGLUtils.isEnabled) {
  11733. canvas = _webgl.WebGLUtils.drawFigures(width, height, backgroundColor, figures, context);
  11734. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight, false);
  11735. tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
  11736. canvas = tmpCanvas.canvas;
  11737. } else {
  11738. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight, false);
  11739. var tmpCtx = tmpCanvas.context;
  11740. var data = tmpCtx.createImageData(width, height);
  11741. if (backgroundColor) {
  11742. var bytes = data.data;
  11743. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  11744. bytes[i] = backgroundColor[0];
  11745. bytes[i + 1] = backgroundColor[1];
  11746. bytes[i + 2] = backgroundColor[2];
  11747. bytes[i + 3] = 255;
  11748. }
  11749. }
  11750. for (i = 0; i < figures.length; i++) {
  11751. drawFigure(data, figures[i], context);
  11752. }
  11753. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  11754. canvas = tmpCanvas.canvas;
  11755. }
  11756. return {
  11757. canvas: canvas,
  11758. offsetX: offsetX - BORDER_SIZE * scaleX,
  11759. offsetY: offsetY - BORDER_SIZE * scaleY,
  11760. scaleX: scaleX,
  11761. scaleY: scaleY
  11762. };
  11763. }
  11764. return createMeshCanvas;
  11765. }();
  11766. ShadingIRs.Mesh = {
  11767. fromIR: function Mesh_fromIR(raw) {
  11768. var coords = raw[2];
  11769. var colors = raw[3];
  11770. var figures = raw[4];
  11771. var bounds = raw[5];
  11772. var matrix = raw[6];
  11773. var background = raw[8];
  11774. return {
  11775. type: 'Pattern',
  11776. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  11777. var scale;
  11778. if (shadingFill) {
  11779. scale = _util.Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  11780. } else {
  11781. scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
  11782. if (matrix) {
  11783. var matrixScale = _util.Util.singularValueDecompose2dScale(matrix);
  11784. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  11785. }
  11786. }
  11787. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, colors, figures, shadingFill ? null : background, owner.cachedCanvases);
  11788. if (!shadingFill) {
  11789. ctx.setTransform.apply(ctx, owner.baseTransform);
  11790. if (matrix) {
  11791. ctx.transform.apply(ctx, matrix);
  11792. }
  11793. }
  11794. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  11795. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  11796. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  11797. }
  11798. };
  11799. }
  11800. };
  11801. ShadingIRs.Dummy = {
  11802. fromIR: function Dummy_fromIR() {
  11803. return {
  11804. type: 'Pattern',
  11805. getPattern: function Dummy_fromIR_getPattern() {
  11806. return 'hotpink';
  11807. }
  11808. };
  11809. }
  11810. };
  11811. function getShadingPatternFromIR(raw) {
  11812. var shadingIR = ShadingIRs[raw[0]];
  11813. if (!shadingIR) {
  11814. throw new Error('Unknown IR type: ' + raw[0]);
  11815. }
  11816. return shadingIR.fromIR(raw);
  11817. }
  11818. var TilingPattern = function TilingPatternClosure() {
  11819. var PaintType = {
  11820. COLORED: 1,
  11821. UNCOLORED: 2
  11822. };
  11823. var MAX_PATTERN_SIZE = 3000;
  11824. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  11825. this.operatorList = IR[2];
  11826. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  11827. this.bbox = IR[4];
  11828. this.xstep = IR[5];
  11829. this.ystep = IR[6];
  11830. this.paintType = IR[7];
  11831. this.tilingType = IR[8];
  11832. this.color = color;
  11833. this.canvasGraphicsFactory = canvasGraphicsFactory;
  11834. this.baseTransform = baseTransform;
  11835. this.type = 'Pattern';
  11836. this.ctx = ctx;
  11837. }
  11838. TilingPattern.prototype = {
  11839. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  11840. var operatorList = this.operatorList;
  11841. var bbox = this.bbox;
  11842. var xstep = this.xstep;
  11843. var ystep = this.ystep;
  11844. var paintType = this.paintType;
  11845. var tilingType = this.tilingType;
  11846. var color = this.color;
  11847. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  11848. (0, _util.info)('TilingType: ' + tilingType);
  11849. var x0 = bbox[0],
  11850. y0 = bbox[1],
  11851. x1 = bbox[2],
  11852. y1 = bbox[3];
  11853. var topLeft = [x0, y0];
  11854. var botRight = [x0 + xstep, y0 + ystep];
  11855. var width = botRight[0] - topLeft[0];
  11856. var height = botRight[1] - topLeft[1];
  11857. var matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  11858. var curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
  11859. var combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  11860. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])), MAX_PATTERN_SIZE);
  11861. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])), MAX_PATTERN_SIZE);
  11862. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern', width, height, true);
  11863. var tmpCtx = tmpCanvas.context;
  11864. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  11865. graphics.groupLevel = owner.groupLevel;
  11866. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  11867. this.setScale(width, height, xstep, ystep);
  11868. this.transformToScale(graphics);
  11869. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  11870. graphics.transform.apply(graphics, tmpTranslate);
  11871. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  11872. graphics.executeOperatorList(operatorList);
  11873. return tmpCanvas.canvas;
  11874. },
  11875. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  11876. this.scale = [width / xstep, height / ystep];
  11877. },
  11878. transformToScale: function TilingPattern_transformToScale(graphics) {
  11879. var scale = this.scale;
  11880. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  11881. graphics.transform.apply(graphics, tmpScale);
  11882. },
  11883. scaleToContext: function TilingPattern_scaleToContext() {
  11884. var scale = this.scale;
  11885. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  11886. },
  11887. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  11888. if ((0, _util.isArray)(bbox) && bbox.length === 4) {
  11889. var bboxWidth = x1 - x0;
  11890. var bboxHeight = y1 - y0;
  11891. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  11892. graphics.clip();
  11893. graphics.endPath();
  11894. }
  11895. },
  11896. setFillAndStrokeStyleToContext: function setFillAndStrokeStyleToContext(context, paintType, color) {
  11897. switch (paintType) {
  11898. case PaintType.COLORED:
  11899. var ctx = this.ctx;
  11900. context.fillStyle = ctx.fillStyle;
  11901. context.strokeStyle = ctx.strokeStyle;
  11902. break;
  11903. case PaintType.UNCOLORED:
  11904. var cssColor = _util.Util.makeCssRgb(color[0], color[1], color[2]);
  11905. context.fillStyle = cssColor;
  11906. context.strokeStyle = cssColor;
  11907. break;
  11908. default:
  11909. throw new _util.FormatError('Unsupported paint type: ' + paintType);
  11910. }
  11911. },
  11912. getPattern: function TilingPattern_getPattern(ctx, owner) {
  11913. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  11914. ctx = this.ctx;
  11915. ctx.setTransform.apply(ctx, this.baseTransform);
  11916. ctx.transform.apply(ctx, this.matrix);
  11917. this.scaleToContext();
  11918. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  11919. }
  11920. };
  11921. return TilingPattern;
  11922. }();
  11923. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  11924. exports.TilingPattern = TilingPattern;
  11925. /***/ }),
  11926. /* 14 */
  11927. /***/ (function(module, exports, __w_pdfjs_require__) {
  11928. "use strict";
  11929. Object.defineProperty(exports, "__esModule", {
  11930. value: true
  11931. });
  11932. exports.PDFDataTransportStream = undefined;
  11933. var _util = __w_pdfjs_require__(0);
  11934. var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
  11935. function PDFDataTransportStream(params, pdfDataRangeTransport) {
  11936. var _this = this;
  11937. (0, _util.assert)(pdfDataRangeTransport);
  11938. this._queuedChunks = [];
  11939. var initialData = params.initialData;
  11940. if (initialData && initialData.length > 0) {
  11941. var buffer = new Uint8Array(initialData).buffer;
  11942. this._queuedChunks.push(buffer);
  11943. }
  11944. this._pdfDataRangeTransport = pdfDataRangeTransport;
  11945. this._isRangeSupported = !params.disableRange;
  11946. this._isStreamingSupported = !params.disableStream;
  11947. this._contentLength = params.length;
  11948. this._fullRequestReader = null;
  11949. this._rangeReaders = [];
  11950. this._pdfDataRangeTransport.addRangeListener(function (begin, chunk) {
  11951. _this._onReceiveData({
  11952. begin: begin,
  11953. chunk: chunk
  11954. });
  11955. });
  11956. this._pdfDataRangeTransport.addProgressListener(function (loaded) {
  11957. _this._onProgress({ loaded: loaded });
  11958. });
  11959. this._pdfDataRangeTransport.addProgressiveReadListener(function (chunk) {
  11960. _this._onReceiveData({ chunk: chunk });
  11961. });
  11962. this._pdfDataRangeTransport.transportReady();
  11963. }
  11964. PDFDataTransportStream.prototype = {
  11965. _onReceiveData: function PDFDataTransportStream_onReceiveData(args) {
  11966. var buffer = new Uint8Array(args.chunk).buffer;
  11967. if (args.begin === undefined) {
  11968. if (this._fullRequestReader) {
  11969. this._fullRequestReader._enqueue(buffer);
  11970. } else {
  11971. this._queuedChunks.push(buffer);
  11972. }
  11973. } else {
  11974. var found = this._rangeReaders.some(function (rangeReader) {
  11975. if (rangeReader._begin !== args.begin) {
  11976. return false;
  11977. }
  11978. rangeReader._enqueue(buffer);
  11979. return true;
  11980. });
  11981. (0, _util.assert)(found);
  11982. }
  11983. },
  11984. _onProgress: function PDFDataTransportStream_onDataProgress(evt) {
  11985. if (this._rangeReaders.length > 0) {
  11986. var firstReader = this._rangeReaders[0];
  11987. if (firstReader.onProgress) {
  11988. firstReader.onProgress({ loaded: evt.loaded });
  11989. }
  11990. }
  11991. },
  11992. _removeRangeReader: function PDFDataTransportStream_removeRangeReader(reader) {
  11993. var i = this._rangeReaders.indexOf(reader);
  11994. if (i >= 0) {
  11995. this._rangeReaders.splice(i, 1);
  11996. }
  11997. },
  11998. getFullReader: function PDFDataTransportStream_getFullReader() {
  11999. (0, _util.assert)(!this._fullRequestReader);
  12000. var queuedChunks = this._queuedChunks;
  12001. this._queuedChunks = null;
  12002. return new PDFDataTransportStreamReader(this, queuedChunks);
  12003. },
  12004. getRangeReader: function PDFDataTransportStream_getRangeReader(begin, end) {
  12005. var reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  12006. this._pdfDataRangeTransport.requestDataRange(begin, end);
  12007. this._rangeReaders.push(reader);
  12008. return reader;
  12009. },
  12010. cancelAllRequests: function PDFDataTransportStream_cancelAllRequests(reason) {
  12011. if (this._fullRequestReader) {
  12012. this._fullRequestReader.cancel(reason);
  12013. }
  12014. var readers = this._rangeReaders.slice(0);
  12015. readers.forEach(function (rangeReader) {
  12016. rangeReader.cancel(reason);
  12017. });
  12018. this._pdfDataRangeTransport.abort();
  12019. }
  12020. };
  12021. function PDFDataTransportStreamReader(stream, queuedChunks) {
  12022. this._stream = stream;
  12023. this._done = false;
  12024. this._queuedChunks = queuedChunks || [];
  12025. this._requests = [];
  12026. this._headersReady = Promise.resolve();
  12027. stream._fullRequestReader = this;
  12028. this.onProgress = null;
  12029. }
  12030. PDFDataTransportStreamReader.prototype = {
  12031. _enqueue: function PDFDataTransportStreamReader_enqueue(chunk) {
  12032. if (this._done) {
  12033. return;
  12034. }
  12035. if (this._requests.length > 0) {
  12036. var requestCapability = this._requests.shift();
  12037. requestCapability.resolve({
  12038. value: chunk,
  12039. done: false
  12040. });
  12041. return;
  12042. }
  12043. this._queuedChunks.push(chunk);
  12044. },
  12045. get headersReady() {
  12046. return this._headersReady;
  12047. },
  12048. get isRangeSupported() {
  12049. return this._stream._isRangeSupported;
  12050. },
  12051. get isStreamingSupported() {
  12052. return this._stream._isStreamingSupported;
  12053. },
  12054. get contentLength() {
  12055. return this._stream._contentLength;
  12056. },
  12057. read: function PDFDataTransportStreamReader_read() {
  12058. if (this._queuedChunks.length > 0) {
  12059. var chunk = this._queuedChunks.shift();
  12060. return Promise.resolve({
  12061. value: chunk,
  12062. done: false
  12063. });
  12064. }
  12065. if (this._done) {
  12066. return Promise.resolve({
  12067. value: undefined,
  12068. done: true
  12069. });
  12070. }
  12071. var requestCapability = (0, _util.createPromiseCapability)();
  12072. this._requests.push(requestCapability);
  12073. return requestCapability.promise;
  12074. },
  12075. cancel: function PDFDataTransportStreamReader_cancel(reason) {
  12076. this._done = true;
  12077. this._requests.forEach(function (requestCapability) {
  12078. requestCapability.resolve({
  12079. value: undefined,
  12080. done: true
  12081. });
  12082. });
  12083. this._requests = [];
  12084. }
  12085. };
  12086. function PDFDataTransportStreamRangeReader(stream, begin, end) {
  12087. this._stream = stream;
  12088. this._begin = begin;
  12089. this._end = end;
  12090. this._queuedChunk = null;
  12091. this._requests = [];
  12092. this._done = false;
  12093. this.onProgress = null;
  12094. }
  12095. PDFDataTransportStreamRangeReader.prototype = {
  12096. _enqueue: function PDFDataTransportStreamRangeReader_enqueue(chunk) {
  12097. if (this._done) {
  12098. return;
  12099. }
  12100. if (this._requests.length === 0) {
  12101. this._queuedChunk = chunk;
  12102. } else {
  12103. var requestsCapability = this._requests.shift();
  12104. requestsCapability.resolve({
  12105. value: chunk,
  12106. done: false
  12107. });
  12108. this._requests.forEach(function (requestCapability) {
  12109. requestCapability.resolve({
  12110. value: undefined,
  12111. done: true
  12112. });
  12113. });
  12114. this._requests = [];
  12115. }
  12116. this._done = true;
  12117. this._stream._removeRangeReader(this);
  12118. },
  12119. get isStreamingSupported() {
  12120. return false;
  12121. },
  12122. read: function PDFDataTransportStreamRangeReader_read() {
  12123. if (this._queuedChunk) {
  12124. var chunk = this._queuedChunk;
  12125. this._queuedChunk = null;
  12126. return Promise.resolve({
  12127. value: chunk,
  12128. done: false
  12129. });
  12130. }
  12131. if (this._done) {
  12132. return Promise.resolve({
  12133. value: undefined,
  12134. done: true
  12135. });
  12136. }
  12137. var requestCapability = (0, _util.createPromiseCapability)();
  12138. this._requests.push(requestCapability);
  12139. return requestCapability.promise;
  12140. },
  12141. cancel: function PDFDataTransportStreamRangeReader_cancel(reason) {
  12142. this._done = true;
  12143. this._requests.forEach(function (requestCapability) {
  12144. requestCapability.resolve({
  12145. value: undefined,
  12146. done: true
  12147. });
  12148. });
  12149. this._requests = [];
  12150. this._stream._removeRangeReader(this);
  12151. }
  12152. };
  12153. return PDFDataTransportStream;
  12154. }();
  12155. exports.PDFDataTransportStream = PDFDataTransportStream;
  12156. /***/ }),
  12157. /* 15 */
  12158. /***/ (function(module, exports, __w_pdfjs_require__) {
  12159. "use strict";
  12160. var pdfjsVersion = '1.9.426';
  12161. var pdfjsBuild = '2558a58d';
  12162. var pdfjsSharedUtil = __w_pdfjs_require__(0);
  12163. var pdfjsDisplayGlobal = __w_pdfjs_require__(8);
  12164. var pdfjsDisplayAPI = __w_pdfjs_require__(2);
  12165. var pdfjsDisplayTextLayer = __w_pdfjs_require__(5);
  12166. var pdfjsDisplayAnnotationLayer = __w_pdfjs_require__(3);
  12167. var pdfjsDisplayDOMUtils = __w_pdfjs_require__(1);
  12168. var pdfjsDisplaySVG = __w_pdfjs_require__(4);
  12169. {
  12170. __w_pdfjs_require__(9);
  12171. }
  12172. exports.PDFJS = pdfjsDisplayGlobal.PDFJS;
  12173. exports.build = pdfjsDisplayAPI.build;
  12174. exports.version = pdfjsDisplayAPI.version;
  12175. exports.getDocument = pdfjsDisplayAPI.getDocument;
  12176. exports.LoopbackPort = pdfjsDisplayAPI.LoopbackPort;
  12177. exports.PDFDataRangeTransport = pdfjsDisplayAPI.PDFDataRangeTransport;
  12178. exports.PDFWorker = pdfjsDisplayAPI.PDFWorker;
  12179. exports.renderTextLayer = pdfjsDisplayTextLayer.renderTextLayer;
  12180. exports.AnnotationLayer = pdfjsDisplayAnnotationLayer.AnnotationLayer;
  12181. exports.CustomStyle = pdfjsDisplayDOMUtils.CustomStyle;
  12182. exports.createPromiseCapability = pdfjsSharedUtil.createPromiseCapability;
  12183. exports.PasswordResponses = pdfjsSharedUtil.PasswordResponses;
  12184. exports.InvalidPDFException = pdfjsSharedUtil.InvalidPDFException;
  12185. exports.MissingPDFException = pdfjsSharedUtil.MissingPDFException;
  12186. exports.SVGGraphics = pdfjsDisplaySVG.SVGGraphics;
  12187. exports.NativeImageDecoding = pdfjsSharedUtil.NativeImageDecoding;
  12188. exports.UnexpectedResponseException = pdfjsSharedUtil.UnexpectedResponseException;
  12189. exports.OPS = pdfjsSharedUtil.OPS;
  12190. exports.UNSUPPORTED_FEATURES = pdfjsSharedUtil.UNSUPPORTED_FEATURES;
  12191. exports.isValidUrl = pdfjsDisplayDOMUtils.isValidUrl;
  12192. exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl;
  12193. exports.createObjectURL = pdfjsSharedUtil.createObjectURL;
  12194. exports.removeNullCharacters = pdfjsSharedUtil.removeNullCharacters;
  12195. exports.shadow = pdfjsSharedUtil.shadow;
  12196. exports.createBlob = pdfjsSharedUtil.createBlob;
  12197. exports.RenderingCancelledException = pdfjsDisplayDOMUtils.RenderingCancelledException;
  12198. exports.getFilenameFromUrl = pdfjsDisplayDOMUtils.getFilenameFromUrl;
  12199. exports.addLinkAttributes = pdfjsDisplayDOMUtils.addLinkAttributes;
  12200. exports.StatTimer = pdfjsSharedUtil.StatTimer;
  12201. /***/ }),
  12202. /* 16 */
  12203. /***/ (function(module, exports, __w_pdfjs_require__) {
  12204. "use strict";
  12205. 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; };
  12206. if (typeof PDFJS === 'undefined' || !PDFJS.compatibilityChecked) {
  12207. 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 : {};
  12208. var userAgent = typeof navigator !== 'undefined' && navigator.userAgent || '';
  12209. var isAndroid = /Android/.test(userAgent);
  12210. var isAndroidPre3 = /Android\s[0-2][^\d]/.test(userAgent);
  12211. var isAndroidPre5 = /Android\s[0-4][^\d]/.test(userAgent);
  12212. var isChrome = userAgent.indexOf('Chrom') >= 0;
  12213. var isChromeWithRangeBug = /Chrome\/(39|40)\./.test(userAgent);
  12214. var isIOSChrome = userAgent.indexOf('CriOS') >= 0;
  12215. var isIE = userAgent.indexOf('Trident') >= 0;
  12216. var isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent);
  12217. var isOpera = userAgent.indexOf('Opera') >= 0;
  12218. var isSafari = /Safari\//.test(userAgent) && !/(Chrome\/|Android\s)/.test(userAgent);
  12219. var hasDOM = (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' && (typeof document === 'undefined' ? 'undefined' : _typeof(document)) === 'object';
  12220. if (typeof PDFJS === 'undefined') {
  12221. globalScope.PDFJS = {};
  12222. }
  12223. PDFJS.compatibilityChecked = true;
  12224. (function checkTypedArrayCompatibility() {
  12225. if (typeof Uint8Array !== 'undefined') {
  12226. if (typeof Uint8Array.prototype.subarray === 'undefined') {
  12227. Uint8Array.prototype.subarray = function subarray(start, end) {
  12228. return new Uint8Array(this.slice(start, end));
  12229. };
  12230. Float32Array.prototype.subarray = function subarray(start, end) {
  12231. return new Float32Array(this.slice(start, end));
  12232. };
  12233. }
  12234. if (typeof Float64Array === 'undefined') {
  12235. globalScope.Float64Array = Float32Array;
  12236. }
  12237. return;
  12238. }
  12239. function subarray(start, end) {
  12240. return new TypedArray(this.slice(start, end));
  12241. }
  12242. function setArrayOffset(array, offset) {
  12243. if (arguments.length < 2) {
  12244. offset = 0;
  12245. }
  12246. for (var i = 0, n = array.length; i < n; ++i, ++offset) {
  12247. this[offset] = array[i] & 0xFF;
  12248. }
  12249. }
  12250. function Uint32ArrayView(buffer, length) {
  12251. this.buffer = buffer;
  12252. this.byteLength = buffer.length;
  12253. this.length = length;
  12254. ensureUint32ArrayViewProps(this.length);
  12255. }
  12256. Uint32ArrayView.prototype = Object.create(null);
  12257. var uint32ArrayViewSetters = 0;
  12258. function createUint32ArrayProp(index) {
  12259. return {
  12260. get: function get() {
  12261. var buffer = this.buffer,
  12262. offset = index << 2;
  12263. return (buffer[offset] | buffer[offset + 1] << 8 | buffer[offset + 2] << 16 | buffer[offset + 3] << 24) >>> 0;
  12264. },
  12265. set: function set(value) {
  12266. var buffer = this.buffer,
  12267. offset = index << 2;
  12268. buffer[offset] = value & 255;
  12269. buffer[offset + 1] = value >> 8 & 255;
  12270. buffer[offset + 2] = value >> 16 & 255;
  12271. buffer[offset + 3] = value >>> 24 & 255;
  12272. }
  12273. };
  12274. }
  12275. function ensureUint32ArrayViewProps(length) {
  12276. while (uint32ArrayViewSetters < length) {
  12277. Object.defineProperty(Uint32ArrayView.prototype, uint32ArrayViewSetters, createUint32ArrayProp(uint32ArrayViewSetters));
  12278. uint32ArrayViewSetters++;
  12279. }
  12280. }
  12281. function TypedArray(arg1) {
  12282. var result, i, n;
  12283. if (typeof arg1 === 'number') {
  12284. result = [];
  12285. for (i = 0; i < arg1; ++i) {
  12286. result[i] = 0;
  12287. }
  12288. } else if ('slice' in arg1) {
  12289. result = arg1.slice(0);
  12290. } else {
  12291. result = [];
  12292. for (i = 0, n = arg1.length; i < n; ++i) {
  12293. result[i] = arg1[i];
  12294. }
  12295. }
  12296. result.subarray = subarray;
  12297. result.buffer = result;
  12298. result.byteLength = result.length;
  12299. result.set = setArrayOffset;
  12300. if ((typeof arg1 === 'undefined' ? 'undefined' : _typeof(arg1)) === 'object' && arg1.buffer) {
  12301. result.buffer = arg1.buffer;
  12302. }
  12303. return result;
  12304. }
  12305. globalScope.Uint8Array = TypedArray;
  12306. globalScope.Int8Array = TypedArray;
  12307. globalScope.Int32Array = TypedArray;
  12308. globalScope.Uint16Array = TypedArray;
  12309. globalScope.Float32Array = TypedArray;
  12310. globalScope.Float64Array = TypedArray;
  12311. globalScope.Uint32Array = function () {
  12312. if (arguments.length === 3) {
  12313. if (arguments[1] !== 0) {
  12314. throw new Error('offset !== 0 is not supported');
  12315. }
  12316. return new Uint32ArrayView(arguments[0], arguments[2]);
  12317. }
  12318. return TypedArray.apply(this, arguments);
  12319. };
  12320. })();
  12321. (function canvasPixelArrayBuffer() {
  12322. if (!hasDOM || !window.CanvasPixelArray) {
  12323. return;
  12324. }
  12325. var cpaProto = window.CanvasPixelArray.prototype;
  12326. if ('buffer' in cpaProto) {
  12327. return;
  12328. }
  12329. Object.defineProperty(cpaProto, 'buffer', {
  12330. get: function get() {
  12331. return this;
  12332. },
  12333. enumerable: false,
  12334. configurable: true
  12335. });
  12336. Object.defineProperty(cpaProto, 'byteLength', {
  12337. get: function get() {
  12338. return this.length;
  12339. },
  12340. enumerable: false,
  12341. configurable: true
  12342. });
  12343. })();
  12344. (function normalizeURLObject() {
  12345. if (!globalScope.URL) {
  12346. globalScope.URL = globalScope.webkitURL;
  12347. }
  12348. })();
  12349. (function checkObjectDefinePropertyCompatibility() {
  12350. if (typeof Object.defineProperty !== 'undefined') {
  12351. var definePropertyPossible = true;
  12352. try {
  12353. if (hasDOM) {
  12354. Object.defineProperty(new Image(), 'id', { value: 'test' });
  12355. }
  12356. var Test = function Test() {};
  12357. Test.prototype = {
  12358. get id() {}
  12359. };
  12360. Object.defineProperty(new Test(), 'id', {
  12361. value: '',
  12362. configurable: true,
  12363. enumerable: true,
  12364. writable: false
  12365. });
  12366. } catch (e) {
  12367. definePropertyPossible = false;
  12368. }
  12369. if (definePropertyPossible) {
  12370. return;
  12371. }
  12372. }
  12373. Object.defineProperty = function objectDefineProperty(obj, name, def) {
  12374. delete obj[name];
  12375. if ('get' in def) {
  12376. obj.__defineGetter__(name, def['get']);
  12377. }
  12378. if ('set' in def) {
  12379. obj.__defineSetter__(name, def['set']);
  12380. }
  12381. if ('value' in def) {
  12382. obj.__defineSetter__(name, function objectDefinePropertySetter(value) {
  12383. this.__defineGetter__(name, function objectDefinePropertyGetter() {
  12384. return value;
  12385. });
  12386. return value;
  12387. });
  12388. obj[name] = def.value;
  12389. }
  12390. };
  12391. })();
  12392. (function checkXMLHttpRequestResponseCompatibility() {
  12393. if (typeof XMLHttpRequest === 'undefined') {
  12394. return;
  12395. }
  12396. var xhrPrototype = XMLHttpRequest.prototype;
  12397. var xhr = new XMLHttpRequest();
  12398. if (!('overrideMimeType' in xhr)) {
  12399. Object.defineProperty(xhrPrototype, 'overrideMimeType', {
  12400. value: function xmlHttpRequestOverrideMimeType(mimeType) {}
  12401. });
  12402. }
  12403. if ('responseType' in xhr) {
  12404. return;
  12405. }
  12406. Object.defineProperty(xhrPrototype, 'responseType', {
  12407. get: function xmlHttpRequestGetResponseType() {
  12408. return this._responseType || 'text';
  12409. },
  12410. set: function xmlHttpRequestSetResponseType(value) {
  12411. if (value === 'text' || value === 'arraybuffer') {
  12412. this._responseType = value;
  12413. if (value === 'arraybuffer' && typeof this.overrideMimeType === 'function') {
  12414. this.overrideMimeType('text/plain; charset=x-user-defined');
  12415. }
  12416. }
  12417. }
  12418. });
  12419. if (typeof VBArray !== 'undefined') {
  12420. Object.defineProperty(xhrPrototype, 'response', {
  12421. get: function xmlHttpRequestResponseGet() {
  12422. if (this.responseType === 'arraybuffer') {
  12423. return new Uint8Array(new VBArray(this.responseBody).toArray());
  12424. }
  12425. return this.responseText;
  12426. }
  12427. });
  12428. return;
  12429. }
  12430. Object.defineProperty(xhrPrototype, 'response', {
  12431. get: function xmlHttpRequestResponseGet() {
  12432. if (this.responseType !== 'arraybuffer') {
  12433. return this.responseText;
  12434. }
  12435. var text = this.responseText;
  12436. var i,
  12437. n = text.length;
  12438. var result = new Uint8Array(n);
  12439. for (i = 0; i < n; ++i) {
  12440. result[i] = text.charCodeAt(i) & 0xFF;
  12441. }
  12442. return result.buffer;
  12443. }
  12444. });
  12445. })();
  12446. (function checkWindowBtoaCompatibility() {
  12447. if ('btoa' in globalScope) {
  12448. return;
  12449. }
  12450. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  12451. globalScope.btoa = function (chars) {
  12452. var buffer = '';
  12453. var i, n;
  12454. for (i = 0, n = chars.length; i < n; i += 3) {
  12455. var b1 = chars.charCodeAt(i) & 0xFF;
  12456. var b2 = chars.charCodeAt(i + 1) & 0xFF;
  12457. var b3 = chars.charCodeAt(i + 2) & 0xFF;
  12458. var d1 = b1 >> 2,
  12459. d2 = (b1 & 3) << 4 | b2 >> 4;
  12460. var d3 = i + 1 < n ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
  12461. var d4 = i + 2 < n ? b3 & 0x3F : 64;
  12462. buffer += digits.charAt(d1) + digits.charAt(d2) + digits.charAt(d3) + digits.charAt(d4);
  12463. }
  12464. return buffer;
  12465. };
  12466. })();
  12467. (function checkWindowAtobCompatibility() {
  12468. if ('atob' in globalScope) {
  12469. return;
  12470. }
  12471. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  12472. globalScope.atob = function (input) {
  12473. input = input.replace(/=+$/, '');
  12474. if (input.length % 4 === 1) {
  12475. throw new Error('bad atob input');
  12476. }
  12477. 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) {
  12478. buffer = digits.indexOf(buffer);
  12479. }
  12480. return output;
  12481. };
  12482. })();
  12483. (function checkFunctionPrototypeBindCompatibility() {
  12484. if (typeof Function.prototype.bind !== 'undefined') {
  12485. return;
  12486. }
  12487. Function.prototype.bind = function functionPrototypeBind(obj) {
  12488. var fn = this,
  12489. headArgs = Array.prototype.slice.call(arguments, 1);
  12490. var bound = function functionPrototypeBindBound() {
  12491. var args = headArgs.concat(Array.prototype.slice.call(arguments));
  12492. return fn.apply(obj, args);
  12493. };
  12494. return bound;
  12495. };
  12496. })();
  12497. (function checkDatasetProperty() {
  12498. if (!hasDOM) {
  12499. return;
  12500. }
  12501. var div = document.createElement('div');
  12502. if ('dataset' in div) {
  12503. return;
  12504. }
  12505. Object.defineProperty(HTMLElement.prototype, 'dataset', {
  12506. get: function get() {
  12507. if (this._dataset) {
  12508. return this._dataset;
  12509. }
  12510. var dataset = {};
  12511. for (var j = 0, jj = this.attributes.length; j < jj; j++) {
  12512. var attribute = this.attributes[j];
  12513. if (attribute.name.substring(0, 5) !== 'data-') {
  12514. continue;
  12515. }
  12516. var key = attribute.name.substring(5).replace(/\-([a-z])/g, function (all, ch) {
  12517. return ch.toUpperCase();
  12518. });
  12519. dataset[key] = attribute.value;
  12520. }
  12521. Object.defineProperty(this, '_dataset', {
  12522. value: dataset,
  12523. writable: false,
  12524. enumerable: false
  12525. });
  12526. return dataset;
  12527. },
  12528. enumerable: true
  12529. });
  12530. })();
  12531. (function checkClassListProperty() {
  12532. function changeList(element, itemName, add, remove) {
  12533. var s = element.className || '';
  12534. var list = s.split(/\s+/g);
  12535. if (list[0] === '') {
  12536. list.shift();
  12537. }
  12538. var index = list.indexOf(itemName);
  12539. if (index < 0 && add) {
  12540. list.push(itemName);
  12541. }
  12542. if (index >= 0 && remove) {
  12543. list.splice(index, 1);
  12544. }
  12545. element.className = list.join(' ');
  12546. return index >= 0;
  12547. }
  12548. if (!hasDOM) {
  12549. return;
  12550. }
  12551. var div = document.createElement('div');
  12552. if ('classList' in div) {
  12553. return;
  12554. }
  12555. var classListPrototype = {
  12556. add: function add(name) {
  12557. changeList(this.element, name, true, false);
  12558. },
  12559. contains: function contains(name) {
  12560. return changeList(this.element, name, false, false);
  12561. },
  12562. remove: function remove(name) {
  12563. changeList(this.element, name, false, true);
  12564. },
  12565. toggle: function toggle(name) {
  12566. changeList(this.element, name, true, true);
  12567. }
  12568. };
  12569. Object.defineProperty(HTMLElement.prototype, 'classList', {
  12570. get: function get() {
  12571. if (this._classList) {
  12572. return this._classList;
  12573. }
  12574. var classList = Object.create(classListPrototype, {
  12575. element: {
  12576. value: this,
  12577. writable: false,
  12578. enumerable: true
  12579. }
  12580. });
  12581. Object.defineProperty(this, '_classList', {
  12582. value: classList,
  12583. writable: false,
  12584. enumerable: false
  12585. });
  12586. return classList;
  12587. },
  12588. enumerable: true
  12589. });
  12590. })();
  12591. (function checkWorkerConsoleCompatibility() {
  12592. if (typeof importScripts === 'undefined' || 'console' in globalScope) {
  12593. return;
  12594. }
  12595. var consoleTimer = {};
  12596. var workerConsole = {
  12597. log: function log() {
  12598. var args = Array.prototype.slice.call(arguments);
  12599. globalScope.postMessage({
  12600. targetName: 'main',
  12601. action: 'console_log',
  12602. data: args
  12603. });
  12604. },
  12605. error: function error() {
  12606. var args = Array.prototype.slice.call(arguments);
  12607. globalScope.postMessage({
  12608. targetName: 'main',
  12609. action: 'console_error',
  12610. data: args
  12611. });
  12612. },
  12613. time: function time(name) {
  12614. consoleTimer[name] = Date.now();
  12615. },
  12616. timeEnd: function timeEnd(name) {
  12617. var time = consoleTimer[name];
  12618. if (!time) {
  12619. throw new Error('Unknown timer name ' + name);
  12620. }
  12621. this.log('Timer:', name, Date.now() - time);
  12622. }
  12623. };
  12624. globalScope.console = workerConsole;
  12625. })();
  12626. (function checkConsoleCompatibility() {
  12627. if (!hasDOM) {
  12628. return;
  12629. }
  12630. if (!('console' in window)) {
  12631. window.console = {
  12632. log: function log() {},
  12633. error: function error() {},
  12634. warn: function warn() {}
  12635. };
  12636. return;
  12637. }
  12638. if (!('bind' in console.log)) {
  12639. console.log = function (fn) {
  12640. return function (msg) {
  12641. return fn(msg);
  12642. };
  12643. }(console.log);
  12644. console.error = function (fn) {
  12645. return function (msg) {
  12646. return fn(msg);
  12647. };
  12648. }(console.error);
  12649. console.warn = function (fn) {
  12650. return function (msg) {
  12651. return fn(msg);
  12652. };
  12653. }(console.warn);
  12654. return;
  12655. }
  12656. })();
  12657. (function checkOnClickCompatibility() {
  12658. function ignoreIfTargetDisabled(event) {
  12659. if (isDisabled(event.target)) {
  12660. event.stopPropagation();
  12661. }
  12662. }
  12663. function isDisabled(node) {
  12664. return node.disabled || node.parentNode && isDisabled(node.parentNode);
  12665. }
  12666. if (isOpera) {
  12667. document.addEventListener('click', ignoreIfTargetDisabled, true);
  12668. }
  12669. })();
  12670. (function checkOnBlobSupport() {
  12671. if (isIE || isIOSChrome) {
  12672. PDFJS.disableCreateObjectURL = true;
  12673. }
  12674. })();
  12675. (function checkNavigatorLanguage() {
  12676. if (typeof navigator === 'undefined') {
  12677. return;
  12678. }
  12679. if ('language' in navigator) {
  12680. return;
  12681. }
  12682. PDFJS.locale = navigator.userLanguage || 'en-US';
  12683. })();
  12684. (function checkRangeRequests() {
  12685. if (isSafari || isAndroidPre3 || isChromeWithRangeBug || isIOS) {
  12686. PDFJS.disableRange = true;
  12687. PDFJS.disableStream = true;
  12688. }
  12689. })();
  12690. (function checkHistoryManipulation() {
  12691. if (!hasDOM) {
  12692. return;
  12693. }
  12694. if (!history.pushState || isAndroidPre3) {
  12695. PDFJS.disableHistory = true;
  12696. }
  12697. })();
  12698. (function checkSetPresenceInImageData() {
  12699. if (!hasDOM) {
  12700. return;
  12701. }
  12702. if (window.CanvasPixelArray) {
  12703. if (typeof window.CanvasPixelArray.prototype.set !== 'function') {
  12704. window.CanvasPixelArray.prototype.set = function (arr) {
  12705. for (var i = 0, ii = this.length; i < ii; i++) {
  12706. this[i] = arr[i];
  12707. }
  12708. };
  12709. }
  12710. } else {
  12711. var polyfill = false,
  12712. versionMatch;
  12713. if (isChrome) {
  12714. versionMatch = userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
  12715. polyfill = versionMatch && parseInt(versionMatch[2]) < 21;
  12716. } else if (isAndroid) {
  12717. polyfill = isAndroidPre5;
  12718. } else if (isSafari) {
  12719. versionMatch = userAgent.match(/Version\/([0-9]+)\.([0-9]+)\.([0-9]+) Safari\//);
  12720. polyfill = versionMatch && parseInt(versionMatch[1]) < 6;
  12721. }
  12722. if (polyfill) {
  12723. var contextPrototype = window.CanvasRenderingContext2D.prototype;
  12724. var createImageData = contextPrototype.createImageData;
  12725. contextPrototype.createImageData = function (w, h) {
  12726. var imageData = createImageData.call(this, w, h);
  12727. imageData.data.set = function (arr) {
  12728. for (var i = 0, ii = this.length; i < ii; i++) {
  12729. this[i] = arr[i];
  12730. }
  12731. };
  12732. return imageData;
  12733. };
  12734. contextPrototype = null;
  12735. }
  12736. }
  12737. })();
  12738. (function checkRequestAnimationFrame() {
  12739. function installFakeAnimationFrameFunctions() {
  12740. window.requestAnimationFrame = function (callback) {
  12741. return window.setTimeout(callback, 20);
  12742. };
  12743. window.cancelAnimationFrame = function (timeoutID) {
  12744. window.clearTimeout(timeoutID);
  12745. };
  12746. }
  12747. if (!hasDOM) {
  12748. return;
  12749. }
  12750. if (isIOS) {
  12751. installFakeAnimationFrameFunctions();
  12752. return;
  12753. }
  12754. if ('requestAnimationFrame' in window) {
  12755. return;
  12756. }
  12757. window.requestAnimationFrame = window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame;
  12758. if (window.requestAnimationFrame) {
  12759. return;
  12760. }
  12761. installFakeAnimationFrameFunctions();
  12762. })();
  12763. (function checkCanvasSizeLimitation() {
  12764. if (isIOS || isAndroid) {
  12765. PDFJS.maxCanvasPixels = 5242880;
  12766. }
  12767. })();
  12768. (function checkFullscreenSupport() {
  12769. if (!hasDOM) {
  12770. return;
  12771. }
  12772. if (isIE && window.parent !== window) {
  12773. PDFJS.disableFullscreen = true;
  12774. }
  12775. })();
  12776. (function checkCurrentScript() {
  12777. if (!hasDOM) {
  12778. return;
  12779. }
  12780. if ('currentScript' in document) {
  12781. return;
  12782. }
  12783. Object.defineProperty(document, 'currentScript', {
  12784. get: function get() {
  12785. var scripts = document.getElementsByTagName('script');
  12786. return scripts[scripts.length - 1];
  12787. },
  12788. enumerable: true,
  12789. configurable: true
  12790. });
  12791. })();
  12792. (function checkInputTypeNumberAssign() {
  12793. if (!hasDOM) {
  12794. return;
  12795. }
  12796. var el = document.createElement('input');
  12797. try {
  12798. el.type = 'number';
  12799. } catch (ex) {
  12800. var inputProto = el.constructor.prototype;
  12801. var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type');
  12802. Object.defineProperty(inputProto, 'type', {
  12803. get: function get() {
  12804. return typeProperty.get.call(this);
  12805. },
  12806. set: function set(value) {
  12807. typeProperty.set.call(this, value === 'number' ? 'text' : value);
  12808. },
  12809. enumerable: true,
  12810. configurable: true
  12811. });
  12812. }
  12813. })();
  12814. (function checkDocumentReadyState() {
  12815. if (!hasDOM) {
  12816. return;
  12817. }
  12818. if (!document.attachEvent) {
  12819. return;
  12820. }
  12821. var documentProto = document.constructor.prototype;
  12822. var readyStateProto = Object.getOwnPropertyDescriptor(documentProto, 'readyState');
  12823. Object.defineProperty(documentProto, 'readyState', {
  12824. get: function get() {
  12825. var value = readyStateProto.get.call(this);
  12826. return value === 'interactive' ? 'loading' : value;
  12827. },
  12828. set: function set(value) {
  12829. readyStateProto.set.call(this, value);
  12830. },
  12831. enumerable: true,
  12832. configurable: true
  12833. });
  12834. })();
  12835. (function checkChildNodeRemove() {
  12836. if (!hasDOM) {
  12837. return;
  12838. }
  12839. if (typeof Element.prototype.remove !== 'undefined') {
  12840. return;
  12841. }
  12842. Element.prototype.remove = function () {
  12843. if (this.parentNode) {
  12844. this.parentNode.removeChild(this);
  12845. }
  12846. };
  12847. })();
  12848. (function checkNumberIsNaN() {
  12849. if (Number.isNaN) {
  12850. return;
  12851. }
  12852. Number.isNaN = function (value) {
  12853. return typeof value === 'number' && isNaN(value);
  12854. };
  12855. })();
  12856. (function checkNumberIsInteger() {
  12857. if (Number.isInteger) {
  12858. return;
  12859. }
  12860. Number.isInteger = function (value) {
  12861. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  12862. };
  12863. })();
  12864. (function checkPromise() {
  12865. if (globalScope.Promise) {
  12866. if (typeof globalScope.Promise.all !== 'function') {
  12867. globalScope.Promise.all = function (iterable) {
  12868. var count = 0,
  12869. results = [],
  12870. resolve,
  12871. reject;
  12872. var promise = new globalScope.Promise(function (resolve_, reject_) {
  12873. resolve = resolve_;
  12874. reject = reject_;
  12875. });
  12876. iterable.forEach(function (p, i) {
  12877. count++;
  12878. p.then(function (result) {
  12879. results[i] = result;
  12880. count--;
  12881. if (count === 0) {
  12882. resolve(results);
  12883. }
  12884. }, reject);
  12885. });
  12886. if (count === 0) {
  12887. resolve(results);
  12888. }
  12889. return promise;
  12890. };
  12891. }
  12892. if (typeof globalScope.Promise.resolve !== 'function') {
  12893. globalScope.Promise.resolve = function (value) {
  12894. return new globalScope.Promise(function (resolve) {
  12895. resolve(value);
  12896. });
  12897. };
  12898. }
  12899. if (typeof globalScope.Promise.reject !== 'function') {
  12900. globalScope.Promise.reject = function (reason) {
  12901. return new globalScope.Promise(function (resolve, reject) {
  12902. reject(reason);
  12903. });
  12904. };
  12905. }
  12906. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  12907. globalScope.Promise.prototype.catch = function (onReject) {
  12908. return globalScope.Promise.prototype.then(undefined, onReject);
  12909. };
  12910. }
  12911. return;
  12912. }
  12913. var STATUS_PENDING = 0;
  12914. var STATUS_RESOLVED = 1;
  12915. var STATUS_REJECTED = 2;
  12916. var REJECTION_TIMEOUT = 500;
  12917. var HandlerManager = {
  12918. handlers: [],
  12919. running: false,
  12920. unhandledRejections: [],
  12921. pendingRejectionCheck: false,
  12922. scheduleHandlers: function scheduleHandlers(promise) {
  12923. if (promise._status === STATUS_PENDING) {
  12924. return;
  12925. }
  12926. this.handlers = this.handlers.concat(promise._handlers);
  12927. promise._handlers = [];
  12928. if (this.running) {
  12929. return;
  12930. }
  12931. this.running = true;
  12932. setTimeout(this.runHandlers.bind(this), 0);
  12933. },
  12934. runHandlers: function runHandlers() {
  12935. var RUN_TIMEOUT = 1;
  12936. var timeoutAt = Date.now() + RUN_TIMEOUT;
  12937. while (this.handlers.length > 0) {
  12938. var handler = this.handlers.shift();
  12939. var nextStatus = handler.thisPromise._status;
  12940. var nextValue = handler.thisPromise._value;
  12941. try {
  12942. if (nextStatus === STATUS_RESOLVED) {
  12943. if (typeof handler.onResolve === 'function') {
  12944. nextValue = handler.onResolve(nextValue);
  12945. }
  12946. } else if (typeof handler.onReject === 'function') {
  12947. nextValue = handler.onReject(nextValue);
  12948. nextStatus = STATUS_RESOLVED;
  12949. if (handler.thisPromise._unhandledRejection) {
  12950. this.removeUnhandeledRejection(handler.thisPromise);
  12951. }
  12952. }
  12953. } catch (ex) {
  12954. nextStatus = STATUS_REJECTED;
  12955. nextValue = ex;
  12956. }
  12957. handler.nextPromise._updateStatus(nextStatus, nextValue);
  12958. if (Date.now() >= timeoutAt) {
  12959. break;
  12960. }
  12961. }
  12962. if (this.handlers.length > 0) {
  12963. setTimeout(this.runHandlers.bind(this), 0);
  12964. return;
  12965. }
  12966. this.running = false;
  12967. },
  12968. addUnhandledRejection: function addUnhandledRejection(promise) {
  12969. this.unhandledRejections.push({
  12970. promise: promise,
  12971. time: Date.now()
  12972. });
  12973. this.scheduleRejectionCheck();
  12974. },
  12975. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  12976. promise._unhandledRejection = false;
  12977. for (var i = 0; i < this.unhandledRejections.length; i++) {
  12978. if (this.unhandledRejections[i].promise === promise) {
  12979. this.unhandledRejections.splice(i);
  12980. i--;
  12981. }
  12982. }
  12983. },
  12984. scheduleRejectionCheck: function scheduleRejectionCheck() {
  12985. var _this = this;
  12986. if (this.pendingRejectionCheck) {
  12987. return;
  12988. }
  12989. this.pendingRejectionCheck = true;
  12990. setTimeout(function () {
  12991. _this.pendingRejectionCheck = false;
  12992. var now = Date.now();
  12993. for (var i = 0; i < _this.unhandledRejections.length; i++) {
  12994. if (now - _this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  12995. var unhandled = _this.unhandledRejections[i].promise._value;
  12996. var msg = 'Unhandled rejection: ' + unhandled;
  12997. if (unhandled.stack) {
  12998. msg += '\n' + unhandled.stack;
  12999. }
  13000. try {
  13001. throw new Error(msg);
  13002. } catch (_) {
  13003. console.warn(msg);
  13004. }
  13005. _this.unhandledRejections.splice(i);
  13006. i--;
  13007. }
  13008. }
  13009. if (_this.unhandledRejections.length) {
  13010. _this.scheduleRejectionCheck();
  13011. }
  13012. }, REJECTION_TIMEOUT);
  13013. }
  13014. };
  13015. var Promise = function Promise(resolver) {
  13016. this._status = STATUS_PENDING;
  13017. this._handlers = [];
  13018. try {
  13019. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  13020. } catch (e) {
  13021. this._reject(e);
  13022. }
  13023. };
  13024. Promise.all = function Promise_all(promises) {
  13025. var resolveAll, rejectAll;
  13026. var deferred = new Promise(function (resolve, reject) {
  13027. resolveAll = resolve;
  13028. rejectAll = reject;
  13029. });
  13030. var unresolved = promises.length;
  13031. var results = [];
  13032. if (unresolved === 0) {
  13033. resolveAll(results);
  13034. return deferred;
  13035. }
  13036. function reject(reason) {
  13037. if (deferred._status === STATUS_REJECTED) {
  13038. return;
  13039. }
  13040. results = [];
  13041. rejectAll(reason);
  13042. }
  13043. for (var i = 0, ii = promises.length; i < ii; ++i) {
  13044. var promise = promises[i];
  13045. var resolve = function (i) {
  13046. return function (value) {
  13047. if (deferred._status === STATUS_REJECTED) {
  13048. return;
  13049. }
  13050. results[i] = value;
  13051. unresolved--;
  13052. if (unresolved === 0) {
  13053. resolveAll(results);
  13054. }
  13055. };
  13056. }(i);
  13057. if (Promise.isPromise(promise)) {
  13058. promise.then(resolve, reject);
  13059. } else {
  13060. resolve(promise);
  13061. }
  13062. }
  13063. return deferred;
  13064. };
  13065. Promise.isPromise = function Promise_isPromise(value) {
  13066. return value && typeof value.then === 'function';
  13067. };
  13068. Promise.resolve = function Promise_resolve(value) {
  13069. return new Promise(function (resolve) {
  13070. resolve(value);
  13071. });
  13072. };
  13073. Promise.reject = function Promise_reject(reason) {
  13074. return new Promise(function (resolve, reject) {
  13075. reject(reason);
  13076. });
  13077. };
  13078. Promise.prototype = {
  13079. _status: null,
  13080. _value: null,
  13081. _handlers: null,
  13082. _unhandledRejection: null,
  13083. _updateStatus: function Promise__updateStatus(status, value) {
  13084. if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) {
  13085. return;
  13086. }
  13087. if (status === STATUS_RESOLVED && Promise.isPromise(value)) {
  13088. value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED));
  13089. return;
  13090. }
  13091. this._status = status;
  13092. this._value = value;
  13093. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  13094. this._unhandledRejection = true;
  13095. HandlerManager.addUnhandledRejection(this);
  13096. }
  13097. HandlerManager.scheduleHandlers(this);
  13098. },
  13099. _resolve: function Promise_resolve(value) {
  13100. this._updateStatus(STATUS_RESOLVED, value);
  13101. },
  13102. _reject: function Promise_reject(reason) {
  13103. this._updateStatus(STATUS_REJECTED, reason);
  13104. },
  13105. then: function Promise_then(onResolve, onReject) {
  13106. var nextPromise = new Promise(function (resolve, reject) {
  13107. this.resolve = resolve;
  13108. this.reject = reject;
  13109. });
  13110. this._handlers.push({
  13111. thisPromise: this,
  13112. onResolve: onResolve,
  13113. onReject: onReject,
  13114. nextPromise: nextPromise
  13115. });
  13116. HandlerManager.scheduleHandlers(this);
  13117. return nextPromise;
  13118. },
  13119. catch: function Promise_catch(onReject) {
  13120. return this.then(undefined, onReject);
  13121. }
  13122. };
  13123. globalScope.Promise = Promise;
  13124. })();
  13125. (function checkWeakMap() {
  13126. if (globalScope.WeakMap) {
  13127. return;
  13128. }
  13129. var id = 0;
  13130. function WeakMap() {
  13131. this.id = '$weakmap' + id++;
  13132. }
  13133. WeakMap.prototype = {
  13134. has: function has(obj) {
  13135. if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object' && typeof obj !== 'function' || obj === null) {
  13136. return false;
  13137. }
  13138. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  13139. },
  13140. get: function get(obj) {
  13141. return this.has(obj) ? obj[this.id] : undefined;
  13142. },
  13143. set: function set(obj, value) {
  13144. Object.defineProperty(obj, this.id, {
  13145. value: value,
  13146. enumerable: false,
  13147. configurable: true
  13148. });
  13149. },
  13150. delete: function _delete(obj) {
  13151. delete obj[this.id];
  13152. }
  13153. };
  13154. globalScope.WeakMap = WeakMap;
  13155. })();
  13156. (function checkURLConstructor() {
  13157. var hasWorkingUrl = false;
  13158. try {
  13159. if (typeof URL === 'function' && _typeof(URL.prototype) === 'object' && 'origin' in URL.prototype) {
  13160. var u = new URL('b', 'http://a');
  13161. u.pathname = 'c%20d';
  13162. hasWorkingUrl = u.href === 'http://a/c%20d';
  13163. }
  13164. } catch (e) {}
  13165. if (hasWorkingUrl) {
  13166. return;
  13167. }
  13168. var relative = Object.create(null);
  13169. relative['ftp'] = 21;
  13170. relative['file'] = 0;
  13171. relative['gopher'] = 70;
  13172. relative['http'] = 80;
  13173. relative['https'] = 443;
  13174. relative['ws'] = 80;
  13175. relative['wss'] = 443;
  13176. var relativePathDotMapping = Object.create(null);
  13177. relativePathDotMapping['%2e'] = '.';
  13178. relativePathDotMapping['.%2e'] = '..';
  13179. relativePathDotMapping['%2e.'] = '..';
  13180. relativePathDotMapping['%2e%2e'] = '..';
  13181. function isRelativeScheme(scheme) {
  13182. return relative[scheme] !== undefined;
  13183. }
  13184. function invalid() {
  13185. clear.call(this);
  13186. this._isInvalid = true;
  13187. }
  13188. function IDNAToASCII(h) {
  13189. if (h === '') {
  13190. invalid.call(this);
  13191. }
  13192. return h.toLowerCase();
  13193. }
  13194. function percentEscape(c) {
  13195. var unicode = c.charCodeAt(0);
  13196. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1) {
  13197. return c;
  13198. }
  13199. return encodeURIComponent(c);
  13200. }
  13201. function percentEscapeQuery(c) {
  13202. var unicode = c.charCodeAt(0);
  13203. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1) {
  13204. return c;
  13205. }
  13206. return encodeURIComponent(c);
  13207. }
  13208. var EOF,
  13209. ALPHA = /[a-zA-Z]/,
  13210. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  13211. function parse(input, stateOverride, base) {
  13212. function err(message) {
  13213. errors.push(message);
  13214. }
  13215. var state = stateOverride || 'scheme start',
  13216. cursor = 0,
  13217. buffer = '',
  13218. seenAt = false,
  13219. seenBracket = false,
  13220. errors = [];
  13221. loop: while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  13222. var c = input[cursor];
  13223. switch (state) {
  13224. case 'scheme start':
  13225. if (c && ALPHA.test(c)) {
  13226. buffer += c.toLowerCase();
  13227. state = 'scheme';
  13228. } else if (!stateOverride) {
  13229. buffer = '';
  13230. state = 'no scheme';
  13231. continue;
  13232. } else {
  13233. err('Invalid scheme.');
  13234. break loop;
  13235. }
  13236. break;
  13237. case 'scheme':
  13238. if (c && ALPHANUMERIC.test(c)) {
  13239. buffer += c.toLowerCase();
  13240. } else if (c === ':') {
  13241. this._scheme = buffer;
  13242. buffer = '';
  13243. if (stateOverride) {
  13244. break loop;
  13245. }
  13246. if (isRelativeScheme(this._scheme)) {
  13247. this._isRelative = true;
  13248. }
  13249. if (this._scheme === 'file') {
  13250. state = 'relative';
  13251. } else if (this._isRelative && base && base._scheme === this._scheme) {
  13252. state = 'relative or authority';
  13253. } else if (this._isRelative) {
  13254. state = 'authority first slash';
  13255. } else {
  13256. state = 'scheme data';
  13257. }
  13258. } else if (!stateOverride) {
  13259. buffer = '';
  13260. cursor = 0;
  13261. state = 'no scheme';
  13262. continue;
  13263. } else if (c === EOF) {
  13264. break loop;
  13265. } else {
  13266. err('Code point not allowed in scheme: ' + c);
  13267. break loop;
  13268. }
  13269. break;
  13270. case 'scheme data':
  13271. if (c === '?') {
  13272. this._query = '?';
  13273. state = 'query';
  13274. } else if (c === '#') {
  13275. this._fragment = '#';
  13276. state = 'fragment';
  13277. } else {
  13278. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  13279. this._schemeData += percentEscape(c);
  13280. }
  13281. }
  13282. break;
  13283. case 'no scheme':
  13284. if (!base || !isRelativeScheme(base._scheme)) {
  13285. err('Missing scheme.');
  13286. invalid.call(this);
  13287. } else {
  13288. state = 'relative';
  13289. continue;
  13290. }
  13291. break;
  13292. case 'relative or authority':
  13293. if (c === '/' && input[cursor + 1] === '/') {
  13294. state = 'authority ignore slashes';
  13295. } else {
  13296. err('Expected /, got: ' + c);
  13297. state = 'relative';
  13298. continue;
  13299. }
  13300. break;
  13301. case 'relative':
  13302. this._isRelative = true;
  13303. if (this._scheme !== 'file') {
  13304. this._scheme = base._scheme;
  13305. }
  13306. if (c === EOF) {
  13307. this._host = base._host;
  13308. this._port = base._port;
  13309. this._path = base._path.slice();
  13310. this._query = base._query;
  13311. this._username = base._username;
  13312. this._password = base._password;
  13313. break loop;
  13314. } else if (c === '/' || c === '\\') {
  13315. if (c === '\\') {
  13316. err('\\ is an invalid code point.');
  13317. }
  13318. state = 'relative slash';
  13319. } else if (c === '?') {
  13320. this._host = base._host;
  13321. this._port = base._port;
  13322. this._path = base._path.slice();
  13323. this._query = '?';
  13324. this._username = base._username;
  13325. this._password = base._password;
  13326. state = 'query';
  13327. } else if (c === '#') {
  13328. this._host = base._host;
  13329. this._port = base._port;
  13330. this._path = base._path.slice();
  13331. this._query = base._query;
  13332. this._fragment = '#';
  13333. this._username = base._username;
  13334. this._password = base._password;
  13335. state = 'fragment';
  13336. } else {
  13337. var nextC = input[cursor + 1];
  13338. var nextNextC = input[cursor + 2];
  13339. if (this._scheme !== 'file' || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || nextNextC !== EOF && nextNextC !== '/' && nextNextC !== '\\' && nextNextC !== '?' && nextNextC !== '#') {
  13340. this._host = base._host;
  13341. this._port = base._port;
  13342. this._username = base._username;
  13343. this._password = base._password;
  13344. this._path = base._path.slice();
  13345. this._path.pop();
  13346. }
  13347. state = 'relative path';
  13348. continue;
  13349. }
  13350. break;
  13351. case 'relative slash':
  13352. if (c === '/' || c === '\\') {
  13353. if (c === '\\') {
  13354. err('\\ is an invalid code point.');
  13355. }
  13356. if (this._scheme === 'file') {
  13357. state = 'file host';
  13358. } else {
  13359. state = 'authority ignore slashes';
  13360. }
  13361. } else {
  13362. if (this._scheme !== 'file') {
  13363. this._host = base._host;
  13364. this._port = base._port;
  13365. this._username = base._username;
  13366. this._password = base._password;
  13367. }
  13368. state = 'relative path';
  13369. continue;
  13370. }
  13371. break;
  13372. case 'authority first slash':
  13373. if (c === '/') {
  13374. state = 'authority second slash';
  13375. } else {
  13376. err('Expected \'/\', got: ' + c);
  13377. state = 'authority ignore slashes';
  13378. continue;
  13379. }
  13380. break;
  13381. case 'authority second slash':
  13382. state = 'authority ignore slashes';
  13383. if (c !== '/') {
  13384. err('Expected \'/\', got: ' + c);
  13385. continue;
  13386. }
  13387. break;
  13388. case 'authority ignore slashes':
  13389. if (c !== '/' && c !== '\\') {
  13390. state = 'authority';
  13391. continue;
  13392. } else {
  13393. err('Expected authority, got: ' + c);
  13394. }
  13395. break;
  13396. case 'authority':
  13397. if (c === '@') {
  13398. if (seenAt) {
  13399. err('@ already seen.');
  13400. buffer += '%40';
  13401. }
  13402. seenAt = true;
  13403. for (var i = 0; i < buffer.length; i++) {
  13404. var cp = buffer[i];
  13405. if (cp === '\t' || cp === '\n' || cp === '\r') {
  13406. err('Invalid whitespace in authority.');
  13407. continue;
  13408. }
  13409. if (cp === ':' && this._password === null) {
  13410. this._password = '';
  13411. continue;
  13412. }
  13413. var tempC = percentEscape(cp);
  13414. if (this._password !== null) {
  13415. this._password += tempC;
  13416. } else {
  13417. this._username += tempC;
  13418. }
  13419. }
  13420. buffer = '';
  13421. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  13422. cursor -= buffer.length;
  13423. buffer = '';
  13424. state = 'host';
  13425. continue;
  13426. } else {
  13427. buffer += c;
  13428. }
  13429. break;
  13430. case 'file host':
  13431. if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  13432. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  13433. state = 'relative path';
  13434. } else if (buffer.length === 0) {
  13435. state = 'relative path start';
  13436. } else {
  13437. this._host = IDNAToASCII.call(this, buffer);
  13438. buffer = '';
  13439. state = 'relative path start';
  13440. }
  13441. continue;
  13442. } else if (c === '\t' || c === '\n' || c === '\r') {
  13443. err('Invalid whitespace in file host.');
  13444. } else {
  13445. buffer += c;
  13446. }
  13447. break;
  13448. case 'host':
  13449. case 'hostname':
  13450. if (c === ':' && !seenBracket) {
  13451. this._host = IDNAToASCII.call(this, buffer);
  13452. buffer = '';
  13453. state = 'port';
  13454. if (stateOverride === 'hostname') {
  13455. break loop;
  13456. }
  13457. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  13458. this._host = IDNAToASCII.call(this, buffer);
  13459. buffer = '';
  13460. state = 'relative path start';
  13461. if (stateOverride) {
  13462. break loop;
  13463. }
  13464. continue;
  13465. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  13466. if (c === '[') {
  13467. seenBracket = true;
  13468. } else if (c === ']') {
  13469. seenBracket = false;
  13470. }
  13471. buffer += c;
  13472. } else {
  13473. err('Invalid code point in host/hostname: ' + c);
  13474. }
  13475. break;
  13476. case 'port':
  13477. if (/[0-9]/.test(c)) {
  13478. buffer += c;
  13479. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) {
  13480. if (buffer !== '') {
  13481. var temp = parseInt(buffer, 10);
  13482. if (temp !== relative[this._scheme]) {
  13483. this._port = temp + '';
  13484. }
  13485. buffer = '';
  13486. }
  13487. if (stateOverride) {
  13488. break loop;
  13489. }
  13490. state = 'relative path start';
  13491. continue;
  13492. } else if (c === '\t' || c === '\n' || c === '\r') {
  13493. err('Invalid code point in port: ' + c);
  13494. } else {
  13495. invalid.call(this);
  13496. }
  13497. break;
  13498. case 'relative path start':
  13499. if (c === '\\') {
  13500. err('\'\\\' not allowed in path.');
  13501. }
  13502. state = 'relative path';
  13503. if (c !== '/' && c !== '\\') {
  13504. continue;
  13505. }
  13506. break;
  13507. case 'relative path':
  13508. if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) {
  13509. if (c === '\\') {
  13510. err('\\ not allowed in relative path.');
  13511. }
  13512. var tmp;
  13513. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  13514. buffer = tmp;
  13515. }
  13516. if (buffer === '..') {
  13517. this._path.pop();
  13518. if (c !== '/' && c !== '\\') {
  13519. this._path.push('');
  13520. }
  13521. } else if (buffer === '.' && c !== '/' && c !== '\\') {
  13522. this._path.push('');
  13523. } else if (buffer !== '.') {
  13524. if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  13525. buffer = buffer[0] + ':';
  13526. }
  13527. this._path.push(buffer);
  13528. }
  13529. buffer = '';
  13530. if (c === '?') {
  13531. this._query = '?';
  13532. state = 'query';
  13533. } else if (c === '#') {
  13534. this._fragment = '#';
  13535. state = 'fragment';
  13536. }
  13537. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  13538. buffer += percentEscape(c);
  13539. }
  13540. break;
  13541. case 'query':
  13542. if (!stateOverride && c === '#') {
  13543. this._fragment = '#';
  13544. state = 'fragment';
  13545. } else if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  13546. this._query += percentEscapeQuery(c);
  13547. }
  13548. break;
  13549. case 'fragment':
  13550. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  13551. this._fragment += c;
  13552. }
  13553. break;
  13554. }
  13555. cursor++;
  13556. }
  13557. }
  13558. function clear() {
  13559. this._scheme = '';
  13560. this._schemeData = '';
  13561. this._username = '';
  13562. this._password = null;
  13563. this._host = '';
  13564. this._port = '';
  13565. this._path = [];
  13566. this._query = '';
  13567. this._fragment = '';
  13568. this._isInvalid = false;
  13569. this._isRelative = false;
  13570. }
  13571. function JURL(url, base) {
  13572. if (base !== undefined && !(base instanceof JURL)) {
  13573. base = new JURL(String(base));
  13574. }
  13575. this._url = url;
  13576. clear.call(this);
  13577. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  13578. parse.call(this, input, null, base);
  13579. }
  13580. JURL.prototype = {
  13581. toString: function toString() {
  13582. return this.href;
  13583. },
  13584. get href() {
  13585. if (this._isInvalid) {
  13586. return this._url;
  13587. }
  13588. var authority = '';
  13589. if (this._username !== '' || this._password !== null) {
  13590. authority = this._username + (this._password !== null ? ':' + this._password : '') + '@';
  13591. }
  13592. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  13593. },
  13594. set href(value) {
  13595. clear.call(this);
  13596. parse.call(this, value);
  13597. },
  13598. get protocol() {
  13599. return this._scheme + ':';
  13600. },
  13601. set protocol(value) {
  13602. if (this._isInvalid) {
  13603. return;
  13604. }
  13605. parse.call(this, value + ':', 'scheme start');
  13606. },
  13607. get host() {
  13608. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  13609. },
  13610. set host(value) {
  13611. if (this._isInvalid || !this._isRelative) {
  13612. return;
  13613. }
  13614. parse.call(this, value, 'host');
  13615. },
  13616. get hostname() {
  13617. return this._host;
  13618. },
  13619. set hostname(value) {
  13620. if (this._isInvalid || !this._isRelative) {
  13621. return;
  13622. }
  13623. parse.call(this, value, 'hostname');
  13624. },
  13625. get port() {
  13626. return this._port;
  13627. },
  13628. set port(value) {
  13629. if (this._isInvalid || !this._isRelative) {
  13630. return;
  13631. }
  13632. parse.call(this, value, 'port');
  13633. },
  13634. get pathname() {
  13635. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  13636. },
  13637. set pathname(value) {
  13638. if (this._isInvalid || !this._isRelative) {
  13639. return;
  13640. }
  13641. this._path = [];
  13642. parse.call(this, value, 'relative path start');
  13643. },
  13644. get search() {
  13645. return this._isInvalid || !this._query || this._query === '?' ? '' : this._query;
  13646. },
  13647. set search(value) {
  13648. if (this._isInvalid || !this._isRelative) {
  13649. return;
  13650. }
  13651. this._query = '?';
  13652. if (value[0] === '?') {
  13653. value = value.slice(1);
  13654. }
  13655. parse.call(this, value, 'query');
  13656. },
  13657. get hash() {
  13658. return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment;
  13659. },
  13660. set hash(value) {
  13661. if (this._isInvalid) {
  13662. return;
  13663. }
  13664. this._fragment = '#';
  13665. if (value[0] === '#') {
  13666. value = value.slice(1);
  13667. }
  13668. parse.call(this, value, 'fragment');
  13669. },
  13670. get origin() {
  13671. var host;
  13672. if (this._isInvalid || !this._scheme) {
  13673. return '';
  13674. }
  13675. switch (this._scheme) {
  13676. case 'data':
  13677. case 'file':
  13678. case 'javascript':
  13679. case 'mailto':
  13680. return 'null';
  13681. case 'blob':
  13682. try {
  13683. return new JURL(this._schemeData).origin || 'null';
  13684. } catch (_) {}
  13685. return 'null';
  13686. }
  13687. host = this.host;
  13688. if (!host) {
  13689. return '';
  13690. }
  13691. return this._scheme + '://' + host;
  13692. }
  13693. };
  13694. var OriginalURL = globalScope.URL;
  13695. if (OriginalURL) {
  13696. JURL.createObjectURL = function (blob) {
  13697. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  13698. };
  13699. JURL.revokeObjectURL = function (url) {
  13700. OriginalURL.revokeObjectURL(url);
  13701. };
  13702. }
  13703. globalScope.URL = JURL;
  13704. })();
  13705. }
  13706. /***/ }),
  13707. /* 17 */
  13708. /***/ (function(module, exports, __w_pdfjs_require__) {
  13709. "use strict";
  13710. var isReadableStreamSupported = false;
  13711. if (typeof ReadableStream !== 'undefined') {
  13712. try {
  13713. new ReadableStream({
  13714. start: function start(controller) {
  13715. controller.close();
  13716. }
  13717. });
  13718. isReadableStreamSupported = true;
  13719. } catch (e) {}
  13720. }
  13721. if (isReadableStreamSupported) {
  13722. exports.ReadableStream = ReadableStream;
  13723. } else {
  13724. exports.ReadableStream = __w_pdfjs_require__(10).ReadableStream;
  13725. }
  13726. /***/ })
  13727. /******/ ]);
  13728. });
  13729. //# sourceMappingURL=pdf.js.map