p5.js 4.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980979819798297983979849798597986979879798897989979909799197992979939799497995979969799797998979999800098001980029800398004980059800698007980089800998010980119801298013980149801598016980179801898019980209802198022980239802498025980269802798028980299803098031980329803398034980359803698037980389803998040980419804298043980449804598046980479804898049980509805198052980539805498055980569805798058980599806098061980629806398064980659806698067980689806998070980719807298073980749807598076980779807898079980809808198082980839808498085980869808798088980899809098091980929809398094980959809698097980989809998100981019810298103981049810598106981079810898109981109811198112981139811498115981169811798118981199812098121981229812398124981259812698127981289812998130981319813298133981349813598136981379813898139981409814198142981439814498145981469814798148981499815098151981529815398154981559815698157981589815998160981619816298163981649816598166981679816898169981709817198172981739817498175981769817798178981799818098181981829818398184981859818698187981889818998190981919819298193981949819598196981979819898199982009820198202982039820498205982069820798208982099821098211982129821398214982159821698217982189821998220982219822298223982249822598226982279822898229982309823198232982339823498235982369823798238982399824098241982429824398244982459824698247982489824998250982519825298253982549825598256982579825898259982609826198262982639826498265982669826798268982699827098271982729827398274982759827698277982789827998280982819828298283982849828598286982879828898289982909829198292982939829498295982969829798298982999830098301983029830398304983059830698307983089830998310983119831298313983149831598316983179831898319983209832198322983239832498325983269832798328983299833098331983329833398334983359833698337983389833998340983419834298343983449834598346983479834898349983509835198352983539835498355983569835798358983599836098361983629836398364983659836698367983689836998370983719837298373983749837598376983779837898379983809838198382983839838498385983869838798388983899839098391983929839398394983959839698397983989839998400984019840298403984049840598406984079840898409984109841198412984139841498415984169841798418984199842098421984229842398424984259842698427984289842998430984319843298433984349843598436984379843898439984409844198442984439844498445984469844798448984499845098451984529845398454984559845698457984589845998460984619846298463984649846598466984679846898469984709847198472984739847498475984769847798478984799848098481984829848398484984859848698487984889848998490984919849298493984949849598496984979849898499985009850198502985039850498505985069850798508985099851098511985129851398514985159851698517985189851998520985219852298523985249852598526985279852898529985309853198532985339853498535985369853798538985399854098541985429854398544985459854698547985489854998550985519855298553985549855598556985579855898559985609856198562985639856498565985669856798568985699857098571985729857398574985759857698577985789857998580985819858298583985849858598586985879858898589985909859198592985939859498595985969859798598985999860098601986029860398604986059860698607986089860998610986119861298613986149861598616986179861898619986209862198622986239862498625986269862798628986299863098631986329863398634986359863698637986389863998640986419864298643986449864598646986479864898649986509865198652986539865498655986569865798658986599866098661986629866398664986659866698667986689866998670986719867298673986749867598676986779867898679986809868198682986839868498685986869868798688986899869098691986929869398694986959869698697986989869998700987019870298703987049870598706987079870898709987109871198712987139871498715987169871798718987199872098721987229872398724987259872698727987289872998730987319873298733987349873598736987379873898739987409874198742987439874498745987469874798748987499875098751987529875398754987559875698757987589875998760987619876298763987649876598766987679876898769987709877198772987739877498775987769877798778987799878098781987829878398784987859878698787987889878998790987919879298793987949879598796987979879898799988009880198802988039880498805988069880798808988099881098811988129881398814988159881698817988189881998820988219882298823988249882598826988279882898829988309883198832988339883498835988369883798838988399884098841988429884398844988459884698847988489884998850988519885298853988549885598856988579885898859988609886198862988639886498865988669886798868988699887098871988729887398874988759887698877988789887998880988819888298883988849888598886988879888898889988909889198892988939889498895988969889798898988999890098901989029890398904989059890698907989089890998910989119891298913989149891598916989179891898919989209892198922989239892498925989269892798928989299893098931989329893398934989359893698937989389893998940989419894298943989449894598946989479894898949989509895198952989539895498955989569895798958989599896098961989629896398964989659896698967989689896998970989719897298973989749897598976989779897898979989809898198982989839898498985989869898798988989899899098991989929899398994989959899698997989989899999000990019900299003990049900599006990079900899009990109901199012990139901499015990169901799018990199902099021990229902399024990259902699027990289902999030990319903299033990349903599036990379903899039990409904199042990439904499045990469904799048990499905099051990529905399054990559905699057990589905999060990619906299063990649906599066990679906899069990709907199072990739907499075990769907799078990799908099081990829908399084990859908699087990889908999090990919909299093990949909599096990979909899099991009910199102991039910499105991069910799108991099911099111991129911399114991159911699117991189911999120991219912299123991249912599126991279912899129991309913199132991339913499135991369913799138991399914099141991429914399144991459914699147991489914999150991519915299153991549915599156991579915899159991609916199162991639916499165991669916799168991699917099171991729917399174991759917699177991789917999180991819918299183991849918599186991879918899189991909919199192991939919499195991969919799198991999920099201992029920399204992059920699207992089920999210992119921299213992149921599216992179921899219992209922199222992239922499225992269922799228992299923099231992329923399234992359923699237992389923999240992419924299243992449924599246992479924899249992509925199252992539925499255992569925799258992599926099261992629926399264992659926699267992689926999270992719927299273992749927599276992779927899279992809928199282992839928499285992869928799288992899929099291992929929399294992959929699297992989929999300993019930299303993049930599306993079930899309993109931199312993139931499315993169931799318993199932099321993229932399324993259932699327993289932999330993319933299333993349933599336993379933899339993409934199342993439934499345993469934799348993499935099351993529935399354993559935699357993589935999360993619936299363993649936599366993679936899369993709937199372993739937499375993769937799378993799938099381993829938399384993859938699387993889938999390993919939299393993949939599396993979939899399994009940199402994039940499405994069940799408994099941099411994129941399414994159941699417994189941999420994219942299423994249942599426994279942899429994309943199432994339943499435994369943799438994399944099441994429944399444994459944699447994489944999450994519945299453994549945599456994579945899459994609946199462994639946499465994669946799468994699947099471994729947399474994759947699477994789947999480994819948299483994849948599486994879948899489994909949199492994939949499495994969949799498994999950099501995029950399504995059950699507995089950999510995119951299513995149951599516995179951899519995209952199522995239952499525995269952799528995299953099531995329953399534995359953699537995389953999540995419954299543995449954599546995479954899549995509955199552995539955499555995569955799558995599956099561995629956399564995659956699567995689956999570995719957299573995749957599576995779957899579995809958199582995839958499585995869958799588995899959099591995929959399594995959959699597995989959999600996019960299603996049960599606996079960899609996109961199612996139961499615996169961799618996199962099621996229962399624996259962699627996289962999630996319963299633996349963599636996379963899639996409964199642996439964499645996469964799648996499965099651996529965399654996559965699657996589965999660996619966299663996649966599666996679966899669996709967199672996739967499675996769967799678996799968099681996829968399684996859968699687996889968999690996919969299693996949969599696996979969899699997009970199702997039970499705997069970799708997099971099711997129971399714997159971699717997189971999720997219972299723997249972599726997279972899729997309973199732997339973499735997369973799738997399974099741997429974399744997459974699747997489974999750997519975299753997549975599756997579975899759997609976199762997639976499765997669976799768997699977099771997729977399774997759977699777997789977999780997819978299783997849978599786997879978899789997909979199792997939979499795997969979799798997999980099801998029980399804998059980699807998089980999810998119981299813998149981599816998179981899819998209982199822998239982499825998269982799828998299983099831998329983399834998359983699837998389983999840998419984299843998449984599846998479984899849998509985199852998539985499855998569985799858998599986099861998629986399864998659986699867998689986999870998719987299873998749987599876998779987899879998809988199882998839988499885998869988799888998899989099891998929989399894998959989699897998989989999900999019990299903999049990599906999079990899909999109991199912999139991499915999169991799918999199992099921999229992399924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999100000100001100002100003100004100005100006100007100008100009100010100011100012100013100014100015100016100017100018100019100020100021100022100023100024100025100026100027100028100029100030100031100032100033100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054100055100056100057100058100059100060100061100062100063100064100065100066100067100068100069100070100071100072100073100074100075100076100077100078100079100080100081100082100083100084100085100086100087100088100089100090100091100092100093100094100095100096100097100098100099100100100101100102100103100104100105100106100107100108100109100110100111100112100113100114100115100116100117100118100119100120100121100122100123100124100125100126100127100128100129100130100131100132100133100134100135100136100137100138100139100140100141100142100143100144100145100146100147100148100149100150100151100152100153100154100155100156100157100158100159100160100161100162100163100164100165100166100167100168100169100170100171100172100173100174100175100176100177100178100179100180100181100182100183100184100185100186100187100188100189100190100191100192100193100194100195100196100197100198100199100200100201100202100203100204100205100206100207100208100209100210100211100212100213100214100215100216100217100218100219100220100221100222100223100224100225100226100227100228100229100230100231100232100233100234100235100236100237100238100239100240100241100242100243100244100245100246100247100248100249100250100251100252100253100254100255100256100257100258100259100260100261100262100263100264100265100266100267100268100269100270100271100272100273100274100275100276100277100278100279100280100281100282100283100284100285100286100287100288100289100290100291100292100293100294100295100296100297100298100299100300100301100302100303100304100305100306100307100308100309100310100311100312100313100314100315100316100317100318100319100320100321100322100323100324100325100326100327100328100329100330100331100332100333100334100335100336100337100338100339100340100341100342100343100344100345100346100347100348100349100350100351100352100353100354100355100356100357100358100359100360100361100362100363100364100365100366100367100368100369100370100371100372100373100374100375100376100377100378100379100380100381100382100383100384100385100386100387100388100389100390100391100392100393100394100395100396100397100398100399100400100401100402100403100404100405100406100407100408100409100410100411100412100413100414100415100416100417100418100419100420100421100422100423100424100425100426100427100428100429100430100431100432100433100434100435100436100437100438100439100440100441100442100443100444100445100446100447100448100449100450100451100452100453100454100455100456100457100458100459100460100461100462100463100464100465100466100467100468100469100470100471100472100473100474100475100476100477100478100479100480100481100482100483100484100485100486100487100488100489100490100491100492100493100494100495100496100497100498100499100500100501100502100503100504100505100506100507100508100509100510100511100512100513100514100515100516100517100518100519100520100521100522100523100524100525100526100527100528100529100530100531100532100533100534100535100536100537100538100539100540100541100542100543100544100545100546100547100548100549100550100551100552100553100554100555100556100557100558100559100560100561100562100563100564100565100566100567100568100569100570100571100572100573100574100575100576100577100578100579100580100581100582100583100584100585100586100587100588100589100590100591100592100593100594100595100596100597100598100599100600100601100602100603100604100605100606100607100608100609100610100611100612100613100614100615100616100617100618100619100620100621100622100623100624100625100626100627100628100629100630100631100632100633100634100635100636100637100638100639100640100641100642100643100644100645100646100647100648100649100650100651100652100653100654100655100656100657100658100659100660100661100662100663100664100665100666100667100668100669100670100671100672100673100674100675100676100677100678100679100680100681100682100683100684100685100686100687100688100689100690100691100692100693100694100695100696100697100698100699100700100701100702100703100704100705100706100707100708100709100710100711100712100713100714100715100716100717100718100719100720100721100722100723100724100725100726100727100728100729100730100731100732100733100734100735100736100737100738100739100740100741100742100743100744100745100746100747100748100749100750100751100752100753100754100755100756100757100758100759100760100761100762100763100764100765100766100767100768100769100770100771100772100773100774100775100776100777100778100779100780100781100782100783100784100785100786100787100788100789100790100791100792100793100794100795100796100797100798100799100800100801100802100803100804100805100806100807100808100809100810100811100812100813100814100815100816100817100818100819100820100821100822100823100824100825100826100827100828100829100830100831100832100833100834100835100836100837100838100839100840100841100842100843100844100845100846100847100848100849100850100851100852100853100854100855100856100857100858100859100860100861100862100863100864100865100866100867100868100869100870100871100872100873100874100875100876100877100878100879100880100881100882100883100884100885100886100887100888100889100890100891100892100893100894100895100896100897100898100899100900100901100902100903100904100905100906100907100908100909100910100911100912100913100914100915100916100917100918100919100920100921100922100923100924100925100926100927100928100929100930100931100932100933100934100935100936100937100938100939100940100941100942100943100944100945100946100947100948100949100950100951100952100953100954100955100956100957100958100959100960100961100962100963100964100965100966100967100968100969100970100971100972100973100974100975100976100977100978100979100980100981100982100983100984100985100986100987100988100989100990100991100992100993100994100995100996100997100998100999101000101001101002101003101004101005101006101007101008101009101010101011101012101013101014101015101016101017101018101019101020101021101022101023101024101025101026101027101028101029101030101031101032101033101034101035101036101037101038101039101040101041101042101043101044101045101046101047101048101049101050101051101052101053101054101055101056101057101058101059101060101061101062101063101064101065101066101067101068101069101070101071101072101073101074101075101076101077101078101079101080101081101082101083101084101085101086101087101088101089101090101091101092101093101094101095101096101097101098101099101100101101101102101103101104101105101106101107101108101109101110101111101112101113101114101115101116101117101118101119101120101121101122101123101124101125101126101127101128101129101130101131101132101133101134101135101136101137101138101139101140101141101142101143101144101145101146101147101148101149101150101151101152101153101154101155101156101157101158101159101160101161101162101163101164101165101166101167101168101169101170101171101172101173101174101175101176101177101178101179101180101181101182101183101184101185101186101187101188101189101190101191101192101193101194101195101196101197101198101199101200101201101202101203101204101205101206101207101208101209101210101211101212101213101214101215101216101217101218101219101220101221101222101223101224101225101226101227101228101229101230101231101232101233101234101235101236101237101238101239101240101241101242101243101244101245101246101247101248101249101250101251101252101253101254101255101256101257101258101259101260101261101262101263101264101265101266101267101268101269101270101271101272101273101274101275101276101277101278101279101280101281101282101283101284101285101286101287101288101289101290101291101292101293101294101295101296101297101298101299101300101301101302101303101304101305101306101307101308101309101310101311101312101313101314101315101316101317101318101319101320101321101322101323101324101325101326101327101328101329101330101331101332101333101334101335101336101337101338101339101340101341101342101343101344101345101346101347101348101349101350101351101352101353101354101355101356101357101358101359101360101361101362101363101364101365101366101367101368101369101370101371101372101373101374101375101376101377101378101379101380101381101382101383101384101385101386101387101388101389101390101391101392101393101394101395101396101397101398101399101400101401101402101403101404101405101406101407101408101409101410101411101412101413101414101415101416101417101418101419101420101421101422101423101424101425101426101427101428101429101430101431101432101433101434101435101436101437101438101439101440101441101442101443101444101445101446101447101448101449101450101451101452101453101454101455101456101457101458101459101460101461101462101463101464101465101466101467101468101469101470101471101472101473101474101475101476101477101478101479101480101481101482101483101484101485101486101487101488101489101490101491101492101493101494101495101496101497101498101499101500101501101502101503101504101505101506101507101508101509101510101511101512101513101514101515101516101517101518101519101520101521101522101523101524101525101526101527101528101529101530101531101532101533101534101535101536101537101538101539101540101541101542101543101544101545101546101547101548101549101550101551101552101553101554101555101556101557101558101559101560101561101562101563101564101565101566101567101568101569101570101571101572101573101574101575101576101577101578101579101580101581101582101583101584101585101586101587101588101589101590101591101592101593101594101595101596101597101598101599101600101601101602101603101604101605101606101607101608101609101610101611101612101613101614101615101616101617101618101619101620101621101622101623101624101625101626101627101628101629101630101631101632101633101634101635101636101637101638101639101640101641101642101643101644101645101646101647101648101649101650101651101652101653101654101655101656101657101658101659101660101661101662101663101664101665101666101667101668101669101670101671101672101673101674101675101676101677101678101679101680101681101682101683101684101685101686101687101688101689101690101691101692101693101694101695101696101697101698101699101700101701101702101703101704101705101706101707101708101709101710101711101712101713101714101715101716101717101718101719101720101721101722101723101724101725101726101727101728101729101730101731101732101733101734101735101736101737101738101739101740101741101742101743101744101745101746101747101748101749101750101751101752101753101754101755101756101757101758101759101760101761101762101763101764101765101766101767101768101769101770101771101772101773101774101775101776101777101778101779101780101781101782101783101784101785101786101787101788101789101790101791101792101793101794101795101796101797101798101799101800101801101802101803101804101805101806101807101808101809101810101811101812101813101814101815101816101817101818101819101820101821101822101823101824101825101826101827101828101829101830101831101832101833101834101835101836101837101838101839101840101841101842101843101844101845101846101847101848101849101850101851101852101853101854101855101856101857101858101859101860101861101862101863101864101865101866101867101868101869101870101871101872101873101874101875101876101877101878101879101880101881101882101883101884101885101886101887101888101889101890101891101892101893101894101895101896101897101898101899101900101901101902101903101904101905101906101907101908101909101910101911101912101913101914101915101916101917101918101919101920101921101922101923101924101925101926101927101928101929101930101931101932101933101934101935101936101937101938101939101940101941101942101943101944101945101946101947101948101949101950101951101952101953101954101955101956101957101958101959101960101961101962101963101964101965101966101967101968101969101970101971101972101973101974101975101976101977101978101979101980101981101982101983101984101985101986101987101988101989101990101991101992101993101994101995101996101997101998101999102000102001102002102003102004102005102006102007102008102009102010102011102012102013102014102015102016102017102018102019102020102021102022102023102024102025102026102027102028102029102030102031102032102033102034102035102036102037102038102039102040102041102042102043102044102045102046102047102048102049102050102051102052102053102054102055102056102057102058102059102060102061102062102063102064102065102066102067102068102069102070102071102072102073102074102075102076102077102078102079102080102081102082102083102084102085102086102087102088102089102090102091102092102093102094102095102096102097102098102099102100102101102102102103102104102105102106102107102108102109102110102111102112102113102114102115102116102117102118102119102120102121102122102123102124102125102126102127102128102129102130102131102132102133102134102135102136102137102138102139102140102141102142102143102144102145102146102147102148102149102150102151102152102153102154102155102156102157102158102159102160102161102162102163102164102165102166102167102168102169102170102171102172102173102174102175102176102177102178102179102180102181102182102183102184102185102186102187102188102189102190102191102192102193102194102195102196102197102198102199102200102201102202102203102204102205102206102207102208102209102210102211102212102213102214102215102216102217102218102219102220102221102222102223102224102225102226102227102228102229102230102231102232102233102234102235102236102237102238102239102240102241102242102243102244102245102246102247102248102249102250102251102252102253102254102255102256102257102258102259102260102261102262102263102264102265102266102267102268102269102270102271102272102273102274102275102276102277102278102279102280102281102282102283102284102285102286102287102288102289102290102291102292102293102294102295102296102297102298102299102300102301102302102303102304102305102306102307102308102309102310102311102312102313102314102315102316102317102318102319102320102321102322102323102324102325102326102327102328102329102330102331102332102333102334102335102336102337102338102339102340102341102342102343102344102345102346102347102348102349102350102351102352102353102354102355102356102357102358102359102360102361102362102363102364102365102366102367102368102369102370102371102372102373102374102375102376102377102378102379102380102381102382102383102384102385102386102387102388102389102390102391102392102393102394102395102396102397102398102399102400102401102402102403102404102405102406102407102408102409102410102411102412102413102414102415102416102417102418102419102420102421102422102423102424102425102426102427102428102429102430102431102432102433102434102435102436102437102438102439102440102441102442102443102444102445102446102447102448102449102450102451102452102453102454102455102456102457102458102459102460102461102462102463102464102465102466102467102468102469102470102471102472102473102474102475102476102477102478102479102480102481102482102483102484102485102486102487102488102489102490102491102492102493102494102495102496102497102498102499102500102501102502102503102504102505102506102507102508102509102510102511102512102513102514102515102516102517102518102519102520102521102522102523102524102525102526102527102528102529102530102531102532102533102534102535102536102537102538102539102540102541102542102543102544102545102546102547102548102549102550102551102552102553102554102555102556102557102558102559102560102561102562102563102564102565102566102567102568102569102570102571102572102573102574102575102576102577102578102579102580102581102582102583102584102585102586102587102588102589102590102591102592102593102594102595102596102597102598102599102600102601102602102603102604102605102606102607102608102609102610102611102612102613102614102615102616102617102618102619102620102621102622102623102624102625102626102627102628102629102630102631102632102633102634102635102636102637102638102639102640102641102642102643102644102645102646102647102648102649102650102651102652102653102654102655102656102657102658102659102660102661102662102663102664102665102666102667102668102669102670102671102672102673102674102675102676102677102678102679102680102681102682102683102684102685102686102687102688102689102690102691102692102693102694102695102696102697102698102699102700102701102702102703102704102705102706102707102708102709102710102711102712102713102714102715102716102717102718102719102720102721102722102723102724102725102726102727102728102729102730102731102732102733102734102735102736102737102738102739102740102741102742102743102744102745102746102747102748102749102750102751102752102753102754102755102756102757102758102759102760102761102762102763102764102765102766102767102768102769102770102771102772102773102774102775102776102777102778102779102780102781102782102783102784102785102786102787102788102789102790102791102792102793102794102795102796102797102798102799102800102801102802102803102804102805102806102807102808102809102810102811102812102813102814102815102816102817102818102819102820102821102822102823102824102825102826102827102828102829102830102831102832102833102834102835102836102837102838102839102840102841102842102843102844102845102846102847102848102849102850102851102852102853102854102855102856102857102858102859102860102861102862102863102864102865102866102867102868102869102870102871102872102873102874102875102876102877102878102879102880102881102882102883102884102885102886102887102888102889102890102891102892102893102894102895102896102897102898102899102900102901102902102903102904102905102906102907102908102909102910102911102912102913102914102915102916102917102918102919102920102921102922102923102924102925102926102927102928102929102930102931102932102933102934102935102936102937102938102939102940102941102942102943102944102945102946102947102948102949102950102951102952102953102954102955102956102957102958102959102960102961102962102963102964102965102966102967102968102969102970102971102972102973102974102975102976102977102978102979102980102981102982102983102984102985102986102987102988102989102990102991102992102993102994102995102996102997102998102999103000103001103002103003103004103005103006103007103008103009103010103011103012103013103014103015103016103017103018103019103020103021103022103023103024103025103026103027103028103029103030103031103032103033103034103035103036103037103038103039103040103041103042103043103044103045103046103047103048103049103050103051103052103053103054103055103056103057103058103059103060103061103062103063103064103065103066103067103068103069103070103071103072103073103074103075103076103077103078103079103080103081103082103083103084103085103086103087103088103089103090103091103092103093103094103095103096103097103098103099103100103101103102103103103104103105103106103107103108103109103110103111103112103113103114103115103116103117103118103119103120103121103122103123103124103125103126103127103128103129103130103131103132103133103134103135103136103137103138103139103140103141103142103143103144103145103146103147103148103149103150103151103152103153103154103155103156103157103158103159103160103161103162103163103164103165103166103167103168103169103170103171103172103173103174103175103176103177103178103179103180103181103182103183103184103185103186103187103188103189103190103191103192103193103194103195103196103197103198103199103200103201103202103203103204103205103206103207103208103209103210103211103212103213103214103215103216103217103218103219103220103221103222103223103224103225103226103227103228103229103230103231103232103233103234103235103236103237103238103239103240103241103242103243103244103245103246103247103248103249103250103251103252103253103254103255103256103257103258103259103260103261103262103263103264103265103266103267103268103269103270103271103272103273103274103275103276103277103278103279103280103281103282103283103284103285103286103287103288103289103290103291103292103293103294103295103296103297103298103299103300103301103302103303103304103305103306103307103308103309103310103311103312103313103314103315103316103317103318103319103320103321103322103323103324103325103326103327103328103329103330103331103332103333103334103335103336103337103338103339103340103341103342103343103344103345103346103347103348103349103350103351103352103353103354103355103356103357103358103359103360103361103362103363103364103365103366103367103368103369103370103371103372103373103374103375103376103377103378103379103380103381103382103383103384103385103386103387103388103389103390103391103392103393103394103395103396103397103398103399103400103401103402103403103404103405103406103407103408103409103410103411103412103413103414103415103416103417103418103419103420103421103422103423103424103425103426103427103428103429103430103431103432103433103434103435103436103437103438103439103440103441103442103443103444103445103446103447103448103449103450103451103452103453103454103455103456103457103458103459103460103461103462103463103464103465103466103467103468103469103470103471103472103473103474103475103476103477103478103479103480103481103482103483103484103485103486103487103488103489103490103491103492103493103494103495103496103497103498103499103500103501103502103503103504103505103506103507103508103509103510103511103512103513103514103515103516103517103518103519103520103521103522103523103524103525103526103527103528103529103530103531103532103533103534103535103536103537103538103539103540103541103542103543103544103545103546103547103548103549103550103551103552103553103554103555103556103557103558103559103560103561103562103563103564103565103566103567103568103569103570103571103572103573103574103575103576103577103578103579103580103581103582103583103584103585103586103587103588103589103590103591103592103593103594103595103596103597103598103599103600103601103602103603103604103605103606103607103608103609103610103611103612103613103614103615103616103617103618103619103620103621103622103623103624103625103626103627103628103629103630103631103632103633103634103635103636103637103638103639103640103641103642103643103644103645103646103647103648103649103650103651103652103653103654103655103656103657103658103659103660103661103662103663103664103665103666103667103668103669103670103671103672103673103674103675103676103677103678103679103680103681103682103683103684103685103686103687103688103689103690103691103692103693103694103695103696103697103698103699103700103701103702103703103704103705103706103707103708103709103710103711103712103713103714103715103716103717103718103719103720103721103722103723103724103725103726103727103728103729103730103731103732103733103734103735103736103737103738103739103740103741103742103743103744103745103746103747103748103749103750103751103752103753103754103755103756103757103758103759103760103761103762103763103764103765103766103767103768103769103770103771103772103773103774103775103776103777103778103779103780103781103782103783103784103785103786103787103788103789103790103791103792103793103794103795103796103797103798103799103800103801103802103803103804103805103806103807103808103809103810103811103812103813103814103815103816103817103818103819103820103821103822103823103824103825103826103827103828103829103830103831103832103833103834103835103836103837103838103839103840103841103842103843103844103845103846103847103848103849103850103851103852103853103854103855103856103857103858103859103860103861103862103863103864103865103866103867103868103869103870103871103872103873103874103875103876103877103878103879103880103881103882103883103884103885103886103887103888103889103890103891103892103893103894103895103896103897103898103899103900103901103902103903103904103905103906103907103908103909103910103911103912103913103914103915103916103917103918103919103920103921103922103923103924103925103926103927103928103929103930103931103932103933103934103935103936103937103938103939103940103941103942103943103944103945103946103947103948103949103950103951103952103953103954103955103956103957103958103959103960103961103962103963103964103965103966103967103968103969103970103971103972103973103974103975103976103977103978103979103980103981103982103983103984103985103986103987103988103989103990103991103992103993103994103995103996103997103998103999104000104001104002104003104004104005104006104007104008104009104010104011104012104013104014104015104016104017104018104019104020104021104022104023104024104025104026104027104028104029104030104031104032104033104034104035104036104037104038104039104040104041104042104043104044104045104046104047104048104049104050104051104052104053104054104055104056104057104058104059104060104061104062104063104064104065104066104067104068104069104070104071104072104073104074104075104076104077104078104079104080104081104082104083104084104085104086104087104088104089104090104091104092104093104094104095104096104097104098104099104100104101104102104103104104104105104106104107104108104109104110104111104112104113104114104115104116104117104118104119104120104121104122104123104124104125104126104127104128104129104130104131104132104133104134104135104136104137104138104139104140104141104142104143104144104145104146104147104148104149104150104151104152104153104154104155104156104157104158104159104160104161104162104163104164104165104166104167104168104169104170104171104172104173104174104175104176104177104178104179104180104181104182104183104184104185104186104187104188104189104190104191104192104193104194104195104196104197104198104199104200104201104202104203104204104205104206104207104208104209104210104211104212104213104214104215104216104217104218104219104220104221104222104223104224104225104226104227104228104229104230104231104232104233104234104235104236104237104238104239104240104241104242104243104244104245104246104247104248104249104250104251104252104253104254104255104256104257104258104259104260104261104262104263104264104265104266104267104268104269104270104271104272104273104274104275104276104277104278104279104280104281104282104283104284104285104286104287104288104289104290104291104292104293104294104295104296104297104298104299104300104301104302104303104304104305104306104307104308104309104310104311104312104313104314104315104316104317104318104319104320104321104322104323104324104325104326104327104328104329104330104331104332104333104334104335104336104337104338104339104340104341104342104343104344104345104346104347104348104349104350104351104352104353104354104355104356104357104358104359104360104361104362104363104364104365104366104367104368104369104370104371104372104373104374104375104376104377104378104379104380104381104382104383104384104385104386104387104388104389104390104391104392104393104394104395104396104397104398104399104400104401104402104403104404104405104406104407104408104409104410104411104412104413104414104415104416104417104418104419104420104421104422104423104424104425104426104427104428104429104430104431104432104433104434104435104436104437104438104439104440104441104442104443104444104445104446104447104448104449104450104451104452104453104454104455104456104457104458104459104460104461104462104463104464104465104466104467104468104469104470104471104472104473104474104475104476104477104478104479104480104481104482104483104484104485104486104487104488104489104490104491104492104493104494104495104496104497104498104499104500104501104502104503104504104505104506104507104508104509104510104511104512104513104514104515104516104517104518104519104520104521104522104523104524104525104526104527104528104529104530104531104532104533104534104535104536104537104538104539104540104541104542104543104544104545104546104547104548104549104550104551104552104553104554104555104556104557104558104559104560104561104562104563104564104565104566104567104568104569104570104571104572104573104574104575104576104577104578104579104580104581104582104583104584104585104586104587104588104589104590104591104592104593104594104595104596104597104598104599104600104601104602104603104604104605104606104607104608104609104610104611104612104613104614104615104616104617104618104619104620104621104622104623104624104625104626104627104628104629104630104631104632104633104634104635104636104637104638104639104640104641104642104643104644104645104646104647104648104649104650104651104652104653104654104655104656104657104658104659104660104661104662104663104664104665104666104667104668104669104670104671104672104673104674104675104676104677104678104679104680104681104682104683104684104685104686104687104688104689104690104691104692104693104694104695104696104697104698104699104700104701104702104703104704104705104706104707104708104709104710104711104712104713104714104715104716104717104718104719104720104721104722104723104724104725104726104727104728104729104730104731104732104733104734104735104736104737104738104739104740104741104742104743104744104745104746104747104748104749104750104751104752104753104754104755104756104757104758104759104760104761104762104763104764104765104766104767104768104769104770104771104772104773104774104775104776104777104778104779104780104781104782104783104784104785104786104787104788104789104790104791104792104793104794104795104796104797104798104799104800104801104802104803104804104805104806104807104808104809104810104811104812104813104814104815104816104817104818104819104820104821104822104823104824104825104826104827104828104829104830104831104832104833104834104835104836104837104838104839104840104841104842104843104844104845104846104847104848104849104850104851104852104853104854104855104856104857104858104859104860104861104862104863104864104865104866104867104868104869104870104871104872104873104874104875104876104877104878104879104880104881104882104883104884104885104886104887104888104889104890104891104892104893104894104895104896104897104898104899104900104901104902104903104904104905104906104907104908104909104910104911104912104913104914104915104916104917104918104919104920104921104922104923104924104925104926104927104928104929104930104931104932104933104934104935104936104937104938104939104940104941104942104943104944104945104946104947104948104949104950104951104952104953104954104955104956104957104958104959104960104961104962104963104964104965104966104967104968104969104970104971104972104973104974104975104976104977104978104979104980104981104982104983104984104985104986104987104988104989104990104991104992104993104994104995104996104997104998104999105000105001105002105003105004105005105006105007105008105009105010105011105012105013105014105015105016105017105018105019105020105021105022105023105024105025105026105027105028105029105030105031105032105033105034105035105036105037105038105039105040105041105042105043105044105045105046105047105048105049105050105051105052105053105054105055105056105057105058105059105060105061105062105063105064105065105066105067105068105069105070105071105072105073105074105075105076105077105078105079105080105081105082105083105084105085105086105087105088105089105090105091105092105093105094105095105096105097105098105099105100105101105102105103105104105105105106105107105108105109105110105111105112105113105114105115105116105117105118105119105120105121105122105123105124105125105126105127105128105129105130105131105132105133105134105135105136105137105138105139105140105141105142105143105144105145105146105147105148105149105150105151105152105153105154105155105156105157105158105159105160105161105162105163105164105165105166105167105168105169105170105171105172105173105174105175105176105177105178105179105180105181105182105183105184105185105186105187105188105189105190105191105192105193105194105195105196105197105198105199105200105201105202105203105204105205105206105207105208105209105210105211105212105213105214105215105216105217105218105219105220105221105222105223105224105225105226105227105228105229105230105231105232105233105234105235105236105237105238105239105240105241105242105243105244105245105246105247105248105249105250105251105252105253105254105255105256105257105258105259105260105261105262105263105264105265105266105267105268105269105270105271105272105273105274105275105276105277105278105279105280105281105282105283105284105285105286105287105288105289105290105291105292105293105294105295105296105297105298105299105300105301105302105303105304105305105306105307105308105309105310105311105312105313105314105315105316105317105318105319105320105321105322105323105324105325105326105327105328105329105330105331105332105333105334105335105336105337105338105339105340105341105342105343105344105345105346105347105348105349105350105351105352105353105354105355105356105357105358105359105360105361105362105363105364105365105366105367105368105369105370105371105372105373105374105375105376105377105378105379105380105381105382105383105384105385105386105387105388105389105390105391105392105393105394105395105396105397105398105399105400105401105402105403105404105405105406105407105408105409105410105411105412105413105414105415105416105417105418105419105420105421105422105423105424105425105426105427105428105429105430105431105432105433105434105435105436105437105438105439105440105441105442105443105444105445105446105447105448105449105450105451105452105453105454105455105456105457105458105459105460105461105462105463105464105465105466105467105468105469105470105471105472105473105474105475105476105477105478105479105480105481105482105483105484105485105486105487105488105489105490105491105492105493105494105495105496105497105498105499105500105501105502105503105504105505105506105507105508105509105510105511105512105513105514105515105516105517105518105519105520105521105522105523105524105525105526105527105528105529105530105531105532105533105534105535105536105537105538105539105540105541105542105543105544105545105546105547105548105549105550105551105552105553105554105555105556105557105558105559105560105561105562105563105564105565105566105567105568105569105570105571105572105573105574105575105576105577105578105579105580105581105582105583105584105585105586105587105588105589105590105591105592105593105594105595105596105597105598105599105600105601105602105603105604105605105606105607105608105609105610105611105612105613105614105615105616105617105618105619105620105621105622105623105624105625105626105627105628105629105630105631105632105633105634105635105636105637105638105639105640105641105642105643105644105645105646105647105648105649105650105651105652105653105654105655105656105657105658105659105660105661105662105663105664105665105666105667105668105669105670105671105672105673105674105675105676105677105678105679105680105681105682105683105684105685105686105687105688105689105690105691105692105693105694105695105696105697105698105699105700105701105702105703105704105705105706105707105708105709105710105711105712105713105714105715105716105717105718105719105720105721105722105723105724105725105726105727105728105729105730105731105732105733105734105735105736105737105738105739105740105741105742105743105744105745105746105747105748105749105750105751105752105753105754105755105756105757105758105759105760105761105762105763105764105765105766105767105768105769105770105771105772105773105774105775105776105777105778105779105780105781105782105783105784105785105786105787105788105789105790105791105792105793105794105795105796105797105798105799105800105801105802105803105804105805105806105807105808105809105810105811105812105813105814105815105816105817105818105819105820105821105822105823105824105825105826105827105828105829105830105831105832105833105834105835105836105837105838105839105840105841105842105843105844105845105846105847105848105849105850105851105852105853105854105855105856105857105858105859105860105861105862105863105864105865105866105867105868105869105870105871105872105873105874105875105876105877105878105879105880105881105882105883105884105885105886105887105888105889105890105891105892105893105894105895105896105897105898105899105900105901105902105903105904105905105906105907105908105909105910105911105912105913105914105915105916105917105918105919105920105921105922105923105924105925105926105927105928105929105930105931105932105933105934105935105936105937105938105939105940105941105942105943105944105945105946105947105948105949105950105951105952105953105954105955105956105957105958105959105960105961105962105963105964105965105966105967105968105969105970105971105972105973105974105975105976105977105978105979105980105981105982105983105984105985105986105987105988105989105990105991105992105993105994105995105996105997105998105999106000106001106002106003106004106005106006106007106008106009106010106011106012106013106014106015106016106017106018106019106020106021106022106023106024106025106026106027106028106029106030106031106032106033106034106035106036106037106038106039106040106041106042106043106044106045106046106047106048106049106050106051106052106053106054106055106056106057106058106059106060106061106062106063106064106065106066106067106068106069106070106071106072106073106074106075106076106077106078106079106080106081106082106083106084106085106086106087106088106089106090106091106092106093106094106095106096106097106098106099106100106101106102106103106104106105106106106107106108106109106110106111106112106113106114106115106116106117106118106119106120106121106122106123106124106125106126106127106128106129106130106131106132106133106134106135106136106137106138106139106140106141106142106143106144106145106146106147106148106149106150106151106152106153106154106155106156106157106158106159106160106161106162106163106164106165106166106167106168106169106170106171106172106173106174106175106176106177106178106179106180106181106182106183106184106185106186106187106188106189106190106191106192106193106194106195106196106197106198106199106200106201106202106203106204106205106206106207106208106209106210106211106212106213106214106215106216106217106218106219106220106221106222106223106224106225106226106227106228106229106230106231106232106233106234106235106236106237106238106239106240106241106242106243106244106245106246106247106248106249106250106251106252106253106254106255106256106257106258106259106260106261106262106263106264106265106266106267106268106269106270106271106272106273106274106275106276106277106278106279106280106281106282106283106284106285106286106287106288106289106290106291106292106293106294106295106296106297106298106299106300106301106302106303106304106305106306106307106308106309106310106311106312106313106314106315106316106317106318106319106320106321106322106323106324106325106326106327106328106329106330106331106332106333106334106335106336106337106338106339106340106341106342106343106344106345106346106347106348106349106350106351106352106353106354106355106356106357106358106359106360106361106362106363106364106365106366106367106368106369106370106371106372106373106374106375106376106377106378106379106380106381106382106383106384106385106386106387106388106389106390106391106392106393106394106395106396106397106398106399106400106401106402106403106404106405106406106407106408106409106410106411106412106413106414106415106416106417106418106419106420106421106422106423106424106425106426106427106428106429106430106431106432106433106434106435106436106437106438106439106440106441106442106443106444106445106446106447106448106449106450106451106452106453106454106455106456106457106458106459106460106461106462106463106464106465106466106467106468106469106470106471106472106473106474106475106476106477106478106479106480106481106482106483106484106485106486106487106488106489106490106491106492106493106494106495106496106497106498106499106500106501106502106503106504106505106506106507106508106509106510106511106512106513106514106515106516106517106518106519106520106521106522106523106524106525106526106527106528106529106530106531106532106533106534106535106536106537106538106539106540106541106542106543106544106545106546106547106548106549106550106551106552106553106554106555106556106557106558106559106560106561106562106563106564106565106566106567106568106569106570106571106572106573106574106575106576106577106578106579106580106581106582106583106584106585106586106587106588106589106590106591106592106593106594106595106596106597106598106599106600106601106602106603106604106605106606106607106608106609106610106611106612106613106614106615106616106617106618106619106620106621106622106623106624106625106626106627106628106629106630106631106632106633106634106635106636106637106638106639106640106641106642106643106644106645106646106647106648106649106650106651106652106653106654106655106656106657106658106659106660106661106662106663106664106665106666106667106668106669106670106671106672106673106674106675106676106677106678106679106680106681106682106683106684106685106686106687106688106689106690106691106692106693106694106695106696106697106698106699106700106701106702106703106704106705106706106707106708106709106710106711106712106713106714106715106716106717106718106719106720106721106722106723106724106725106726106727106728106729106730106731106732106733106734106735106736106737106738106739106740106741106742106743106744106745106746106747106748106749106750106751106752106753106754106755106756106757106758106759106760106761106762106763106764106765106766106767106768106769106770106771106772106773106774106775106776106777106778106779106780106781106782106783106784106785106786106787106788106789106790106791106792106793106794106795106796106797106798106799106800106801106802106803106804106805106806106807106808106809106810106811106812106813106814106815106816106817106818106819106820106821106822106823106824106825106826106827106828106829106830106831106832106833106834106835106836106837106838106839106840106841106842106843106844106845106846106847106848106849106850106851106852106853106854106855106856106857106858106859106860106861106862106863106864106865106866106867106868106869106870106871106872106873106874106875106876106877106878106879106880106881106882106883106884106885106886106887106888106889106890106891106892106893106894106895106896106897106898106899106900106901106902106903106904106905106906106907106908106909106910106911106912106913106914106915106916106917106918106919106920106921106922106923106924106925106926106927106928106929106930106931106932106933106934106935106936106937106938106939106940106941106942106943106944106945106946106947106948106949106950106951106952106953106954106955106956106957106958106959106960106961106962106963106964106965106966106967106968106969106970106971106972106973106974106975106976106977106978106979106980106981106982106983106984106985106986106987106988106989106990106991106992106993106994106995106996106997106998106999107000107001107002107003107004107005107006107007107008107009107010107011107012107013107014107015107016107017107018107019107020107021107022107023107024107025107026107027107028107029107030107031107032107033107034107035107036107037107038107039107040107041107042107043107044107045107046107047107048107049107050107051107052107053107054107055107056107057107058107059107060107061107062107063107064107065107066107067107068107069107070107071107072107073107074107075107076107077107078107079107080107081107082107083107084107085107086107087107088107089107090107091107092107093107094107095107096107097107098107099107100107101107102107103107104107105107106107107107108107109107110107111107112107113107114107115107116107117107118107119107120107121107122107123107124107125107126107127107128107129107130107131107132107133107134107135107136107137107138107139107140107141107142107143107144107145107146107147107148107149107150107151107152107153107154107155107156107157107158107159107160107161107162107163107164107165107166107167107168107169107170107171107172107173107174107175107176107177107178107179107180107181107182107183107184107185107186107187107188107189107190107191107192107193107194107195107196107197107198107199107200107201107202107203107204107205107206107207107208107209107210107211107212107213107214107215107216107217107218107219107220107221107222107223107224107225107226107227107228107229107230107231107232107233107234107235107236107237107238107239107240107241107242107243107244107245107246107247107248107249107250107251107252107253107254107255107256107257107258107259107260107261107262107263107264107265107266107267107268107269107270107271107272107273107274107275107276107277107278107279107280107281107282107283107284107285107286107287107288107289107290107291107292107293107294107295107296107297107298107299107300107301107302107303107304107305107306107307107308107309107310107311107312107313107314107315107316107317107318107319107320107321107322107323107324107325107326107327107328107329107330107331107332107333107334107335107336107337107338107339107340107341107342107343107344107345107346107347107348107349107350107351107352107353107354107355107356107357107358107359107360107361107362107363107364107365107366107367107368107369107370107371107372107373107374107375107376107377107378107379107380107381107382107383107384107385107386107387107388107389107390107391107392107393107394107395107396107397107398107399107400107401107402107403107404107405107406107407107408107409107410107411107412107413107414107415107416107417107418107419107420107421107422107423107424107425107426107427107428107429107430107431107432107433107434107435107436107437107438107439107440107441107442107443107444107445107446107447107448107449107450107451107452107453107454107455107456107457107458107459107460107461107462107463107464107465107466107467107468107469107470107471107472107473107474107475107476107477107478107479107480107481107482107483107484107485107486107487107488107489107490107491107492107493107494107495107496107497107498107499107500107501107502107503107504107505107506107507107508107509107510107511107512107513107514107515107516107517107518107519107520107521107522107523107524107525107526107527107528107529107530107531107532107533107534107535107536107537107538107539107540107541107542107543107544107545107546107547107548107549107550107551107552107553107554107555107556107557107558107559107560107561107562107563107564107565107566107567107568107569107570107571107572107573107574107575107576107577107578107579107580107581107582107583107584107585107586107587107588107589107590107591107592107593107594107595107596107597107598107599107600107601107602107603107604107605107606107607107608107609107610107611107612107613107614107615107616107617107618107619107620107621107622107623107624107625107626107627107628107629107630107631107632107633107634107635107636107637107638107639107640107641107642107643107644107645107646107647107648107649107650107651107652107653107654107655107656107657107658107659107660107661107662107663107664107665107666107667107668107669107670107671107672107673107674107675107676107677107678107679107680107681107682107683107684107685107686107687107688107689107690107691107692107693107694107695107696107697107698107699107700107701107702107703107704107705107706107707107708107709107710107711107712107713107714107715107716107717107718107719107720107721107722107723107724107725107726107727107728107729107730107731107732107733107734107735107736107737107738107739107740107741107742107743107744107745107746107747107748107749107750107751107752107753107754107755107756107757107758107759107760107761107762107763107764107765107766107767107768107769107770107771107772107773107774107775107776107777107778107779107780107781107782107783107784107785107786107787107788107789107790107791107792107793107794107795107796107797107798107799107800107801107802107803107804107805107806107807107808107809107810107811107812107813107814107815107816107817107818107819107820107821107822107823107824107825107826107827107828107829107830107831107832107833107834107835107836107837107838107839107840107841107842107843107844107845107846107847107848107849107850107851107852107853107854107855107856107857107858107859107860107861107862107863107864107865107866107867107868107869107870107871107872107873107874107875107876107877107878107879107880107881107882107883107884107885107886107887107888107889107890107891107892107893107894107895107896107897107898107899107900107901107902107903107904107905107906107907107908107909107910107911107912107913107914107915107916107917107918107919107920107921107922107923107924107925107926107927107928107929107930107931107932107933107934107935107936107937107938107939107940107941107942107943107944107945107946107947107948107949107950107951107952107953107954107955107956107957107958107959107960107961107962107963107964107965107966107967107968107969107970107971107972107973107974107975107976107977107978107979107980107981107982107983107984107985107986107987107988107989107990107991107992107993107994107995107996107997107998107999108000108001108002108003108004108005108006108007108008108009108010108011108012108013108014108015108016108017108018108019108020108021108022108023108024108025108026108027108028108029108030108031108032108033108034108035108036108037108038108039108040108041108042108043108044108045108046108047108048108049108050108051108052108053108054108055108056108057108058108059108060108061108062108063108064108065108066108067108068108069108070108071108072108073108074108075108076108077108078108079108080108081108082108083108084108085108086108087108088108089108090108091108092108093108094108095108096108097108098108099108100108101108102108103108104108105108106108107108108108109108110108111108112108113108114108115108116108117108118108119108120108121108122108123108124108125108126108127108128108129108130108131108132108133108134108135108136108137108138108139108140108141108142108143108144108145108146108147108148108149108150108151108152108153108154108155108156108157108158108159108160108161108162108163108164108165108166108167108168108169108170108171108172108173108174108175108176108177108178108179108180108181108182108183108184108185108186108187108188108189108190108191108192108193108194108195108196108197108198108199108200108201108202108203108204108205108206108207108208108209108210108211108212108213108214108215108216108217108218108219108220108221108222108223108224108225108226108227108228108229108230108231108232108233108234108235108236108237108238108239108240108241108242108243108244108245108246108247108248108249108250108251108252108253108254108255108256108257108258108259108260108261108262108263108264108265108266108267108268108269108270108271108272108273108274108275108276108277108278108279108280108281108282108283108284108285108286108287108288108289108290108291108292108293108294108295108296108297108298108299108300108301108302108303108304108305108306108307108308108309108310108311108312108313108314108315108316108317108318108319108320108321108322108323108324108325108326108327108328108329108330108331108332108333108334108335108336108337108338108339108340108341108342108343108344108345108346108347108348108349108350108351108352108353108354108355108356108357108358108359108360108361108362108363108364108365108366108367108368108369108370108371108372108373108374108375108376108377108378108379108380108381108382108383108384108385108386108387108388108389108390108391108392108393108394108395108396108397108398108399108400108401108402108403108404108405108406108407108408108409108410108411108412108413108414108415108416108417108418108419108420108421108422108423108424108425108426108427108428108429108430108431108432108433108434108435108436108437108438108439108440108441108442108443108444108445108446108447108448108449108450108451108452108453108454108455108456108457108458108459108460108461108462108463108464108465108466108467108468108469108470108471108472108473108474108475108476108477108478108479108480108481108482108483108484108485108486108487108488108489108490108491108492108493108494108495108496108497108498108499108500108501108502108503108504108505108506108507108508108509108510108511108512108513108514108515108516108517108518108519108520108521108522108523108524108525108526108527108528108529108530108531108532108533108534108535108536108537108538108539108540108541108542108543108544108545108546108547108548108549108550108551108552108553108554108555108556108557108558108559108560108561108562108563108564108565108566108567108568108569108570108571108572108573108574108575108576108577108578108579108580108581108582108583108584108585108586108587108588108589108590108591108592108593108594108595108596108597108598108599108600108601108602108603108604108605108606108607108608108609108610108611108612108613108614108615108616108617108618108619108620108621108622108623108624108625108626108627108628108629108630108631108632108633108634108635108636108637108638108639108640108641108642108643108644108645108646108647108648108649108650108651108652108653108654108655108656108657108658108659108660108661108662108663108664108665108666108667108668108669108670108671108672108673108674108675108676108677108678108679108680108681108682108683108684108685108686108687108688108689108690108691108692108693108694108695108696108697108698108699108700108701108702108703108704108705108706108707108708108709108710108711108712108713108714108715108716108717108718108719108720108721108722108723108724108725108726108727108728108729108730108731108732108733108734108735108736108737108738108739108740108741108742108743108744108745108746108747108748108749108750108751108752108753108754108755108756108757108758108759108760108761108762108763108764108765108766108767108768108769108770108771108772108773108774108775108776108777108778108779108780108781108782108783108784108785108786108787108788108789108790108791108792108793108794108795108796108797108798108799108800108801108802108803108804108805108806108807108808108809108810108811108812108813108814108815108816108817108818108819108820108821108822108823108824108825108826108827108828108829108830108831108832108833108834108835108836108837108838108839108840108841108842108843108844108845108846108847108848108849108850108851108852108853108854108855108856108857108858108859108860108861108862108863108864108865108866108867108868108869108870108871108872108873108874108875108876108877108878108879108880108881108882108883108884108885108886108887108888108889108890108891108892108893108894108895108896108897108898108899108900108901108902108903108904108905108906108907108908108909108910108911108912108913108914108915108916108917108918108919108920108921108922108923108924108925108926108927108928108929108930108931108932108933108934108935108936108937108938108939108940108941108942108943108944108945108946108947108948108949108950108951108952108953108954108955108956108957108958108959108960108961108962108963108964108965108966108967108968108969108970108971108972108973108974108975108976108977108978108979108980108981108982108983108984108985108986108987108988108989108990108991108992108993108994108995108996108997108998108999109000109001109002109003109004109005109006109007109008109009109010109011109012109013109014109015109016109017109018109019109020109021109022109023109024109025109026109027109028109029109030109031109032109033109034109035109036109037109038109039109040109041109042109043109044109045109046109047109048109049109050109051109052109053109054109055109056109057109058109059109060109061109062109063109064109065109066109067109068109069109070109071109072109073109074109075109076109077109078109079109080109081109082109083109084109085109086109087109088109089109090109091109092109093109094109095109096109097109098109099109100109101109102109103109104109105109106109107109108109109109110109111109112109113109114109115109116109117109118109119109120109121109122109123109124109125109126109127109128109129109130109131109132109133109134109135109136109137109138109139109140109141109142109143109144109145109146109147109148109149109150109151109152109153109154109155109156109157109158109159109160109161109162109163109164109165109166109167109168109169109170109171109172109173109174109175109176109177109178109179109180109181109182109183109184109185109186109187109188109189109190109191109192109193109194109195109196109197109198109199109200109201109202109203109204109205109206109207109208109209109210109211109212109213109214109215109216109217109218109219109220109221109222109223109224109225109226109227109228109229109230109231109232109233109234109235109236109237109238109239109240109241109242109243109244109245109246109247109248109249109250109251109252109253109254109255109256109257109258109259109260109261109262109263109264109265109266109267109268109269109270109271109272109273109274109275109276109277109278109279109280109281109282109283109284109285109286109287109288109289109290109291109292109293109294109295109296109297109298109299109300109301109302109303109304109305109306109307109308109309109310109311109312109313109314109315109316109317109318109319109320109321109322109323109324109325109326109327109328109329109330109331109332109333109334109335109336109337109338109339109340109341109342109343109344109345109346109347109348109349109350109351109352109353109354109355109356109357109358109359109360109361109362109363109364109365109366109367109368109369109370109371109372109373109374109375109376109377109378109379109380109381109382109383109384109385109386109387109388109389109390109391109392109393109394109395109396109397109398109399109400109401109402109403109404109405109406109407109408109409109410109411109412109413109414109415109416109417109418109419109420109421109422109423109424109425109426109427109428109429109430109431109432109433109434109435109436109437109438109439109440109441109442109443109444109445109446109447109448109449109450109451109452109453109454109455109456109457109458109459109460109461109462109463109464109465109466109467109468109469109470109471109472109473109474109475109476109477109478109479109480109481109482109483109484109485109486109487109488109489109490109491109492109493109494109495109496109497109498109499109500109501109502109503109504109505109506109507109508109509109510109511109512109513109514109515109516109517109518109519109520109521109522109523109524109525109526109527109528109529109530109531109532109533109534109535109536109537109538109539109540109541109542109543109544109545109546109547109548109549109550109551109552109553109554109555109556109557109558109559109560109561109562109563109564109565109566109567109568109569109570109571109572109573109574109575109576109577109578109579109580109581109582109583109584109585109586109587109588109589109590109591109592109593109594109595109596109597109598109599109600109601109602109603109604109605109606109607109608109609109610109611109612109613109614109615109616109617109618109619109620109621109622109623109624109625109626109627109628109629109630109631109632109633109634109635109636109637109638109639109640109641109642109643109644109645109646109647109648109649109650109651
  1. /*! p5.js v1.4.0 June 29, 2021 */
  2. (function(f) {
  3. if (typeof exports === 'object' && typeof module !== 'undefined') {
  4. module.exports = f();
  5. } else if (typeof define === 'function' && define.amd) {
  6. define([], f);
  7. } else {
  8. var g;
  9. if (typeof window !== 'undefined') {
  10. g = window;
  11. } else if (typeof global !== 'undefined') {
  12. g = global;
  13. } else if (typeof self !== 'undefined') {
  14. g = self;
  15. } else {
  16. g = this;
  17. }
  18. g.p5 = f();
  19. }
  20. })(function() {
  21. var define, module, exports;
  22. return (function() {
  23. function r(e, n, t) {
  24. function o(i, f) {
  25. if (!n[i]) {
  26. if (!e[i]) {
  27. var c = 'function' == typeof require && require;
  28. if (!f && c) return c(i, !0);
  29. if (u) return u(i, !0);
  30. var a = new Error("Cannot find module '" + i + "'");
  31. throw ((a.code = 'MODULE_NOT_FOUND'), a);
  32. }
  33. var p = (n[i] = { exports: {} });
  34. e[i][0].call(
  35. p.exports,
  36. function(r) {
  37. var n = e[i][1][r];
  38. return o(n || r);
  39. },
  40. p,
  41. p.exports,
  42. r,
  43. e,
  44. n,
  45. t
  46. );
  47. }
  48. return n[i].exports;
  49. }
  50. for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++)
  51. o(t[i]);
  52. return o;
  53. }
  54. return r;
  55. })()(
  56. {
  57. 1: [
  58. function(_dereq_, module, exports) {
  59. module.exports = {
  60. p5: {
  61. describe: {
  62. name: 'describe',
  63. params: [
  64. {
  65. name: 'text',
  66. description: '<p>description of the canvas</p>\n',
  67. type: 'String'
  68. },
  69. {
  70. name: 'display',
  71. description: '<p>either LABEL or FALLBACK</p>\n',
  72. type: 'Constant',
  73. optional: true
  74. }
  75. ],
  76. class: 'p5',
  77. module: 'Environment'
  78. },
  79. describeElement: {
  80. name: 'describeElement',
  81. params: [
  82. {
  83. name: 'name',
  84. description: '<p>name of the element</p>\n',
  85. type: 'String'
  86. },
  87. {
  88. name: 'text',
  89. description: '<p>description of the element</p>\n',
  90. type: 'String'
  91. },
  92. {
  93. name: 'display',
  94. description: '<p>either LABEL or FALLBACK</p>\n',
  95. type: 'Constant',
  96. optional: true
  97. }
  98. ],
  99. class: 'p5',
  100. module: 'Environment'
  101. },
  102. textOutput: {
  103. name: 'textOutput',
  104. params: [
  105. {
  106. name: 'display',
  107. description: '<p>either FALLBACK or LABEL</p>\n',
  108. type: 'Constant',
  109. optional: true
  110. }
  111. ],
  112. class: 'p5',
  113. module: 'Environment'
  114. },
  115. gridOutput: {
  116. name: 'gridOutput',
  117. params: [
  118. {
  119. name: 'display',
  120. description: '<p>either FALLBACK or LABEL</p>\n',
  121. type: 'Constant',
  122. optional: true
  123. }
  124. ],
  125. class: 'p5',
  126. module: 'Environment'
  127. },
  128. alpha: {
  129. name: 'alpha',
  130. params: [
  131. {
  132. name: 'color',
  133. description:
  134. '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n',
  135. type: 'p5.Color|Number[]|String'
  136. }
  137. ],
  138. class: 'p5',
  139. module: 'Color'
  140. },
  141. blue: {
  142. name: 'blue',
  143. params: [
  144. {
  145. name: 'color',
  146. description:
  147. '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n',
  148. type: 'p5.Color|Number[]|String'
  149. }
  150. ],
  151. class: 'p5',
  152. module: 'Color'
  153. },
  154. brightness: {
  155. name: 'brightness',
  156. params: [
  157. {
  158. name: 'color',
  159. description:
  160. '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n',
  161. type: 'p5.Color|Number[]|String'
  162. }
  163. ],
  164. class: 'p5',
  165. module: 'Color'
  166. },
  167. color: {
  168. name: 'color',
  169. class: 'p5',
  170. module: 'Color',
  171. overloads: [
  172. {
  173. params: [
  174. {
  175. name: 'gray',
  176. description:
  177. '<p>number specifying value between white and black.</p>\n',
  178. type: 'Number'
  179. },
  180. {
  181. name: 'alpha',
  182. description:
  183. '<p>alpha value relative to current color range\n (default is 0-255)</p>\n',
  184. type: 'Number',
  185. optional: true
  186. }
  187. ]
  188. },
  189. {
  190. params: [
  191. {
  192. name: 'v1',
  193. description:
  194. '<p>red or hue value relative to\n the current color range</p>\n',
  195. type: 'Number'
  196. },
  197. {
  198. name: 'v2',
  199. description:
  200. '<p>green or saturation value\n relative to the current color range</p>\n',
  201. type: 'Number'
  202. },
  203. {
  204. name: 'v3',
  205. description:
  206. '<p>blue or brightness value\n relative to the current color range</p>\n',
  207. type: 'Number'
  208. },
  209. {
  210. name: 'alpha',
  211. description: '',
  212. type: 'Number',
  213. optional: true
  214. }
  215. ]
  216. },
  217. {
  218. params: [
  219. {
  220. name: 'value',
  221. description: '<p>a color string</p>\n',
  222. type: 'String'
  223. }
  224. ]
  225. },
  226. {
  227. params: [
  228. {
  229. name: 'values',
  230. description:
  231. '<p>an array containing the red,green,blue &\n and alpha components of the color</p>\n',
  232. type: 'Number[]'
  233. }
  234. ]
  235. },
  236. {
  237. params: [
  238. {
  239. name: 'color',
  240. description: '',
  241. type: 'p5.Color'
  242. }
  243. ]
  244. }
  245. ]
  246. },
  247. green: {
  248. name: 'green',
  249. params: [
  250. {
  251. name: 'color',
  252. description:
  253. '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n',
  254. type: 'p5.Color|Number[]|String'
  255. }
  256. ],
  257. class: 'p5',
  258. module: 'Color'
  259. },
  260. hue: {
  261. name: 'hue',
  262. params: [
  263. {
  264. name: 'color',
  265. description:
  266. '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n',
  267. type: 'p5.Color|Number[]|String'
  268. }
  269. ],
  270. class: 'p5',
  271. module: 'Color'
  272. },
  273. lerpColor: {
  274. name: 'lerpColor',
  275. params: [
  276. {
  277. name: 'c1',
  278. description: '<p>interpolate from this color</p>\n',
  279. type: 'p5.Color'
  280. },
  281. {
  282. name: 'c2',
  283. description: '<p>interpolate to this color</p>\n',
  284. type: 'p5.Color'
  285. },
  286. {
  287. name: 'amt',
  288. description: '<p>number between 0 and 1</p>\n',
  289. type: 'Number'
  290. }
  291. ],
  292. class: 'p5',
  293. module: 'Color'
  294. },
  295. lightness: {
  296. name: 'lightness',
  297. params: [
  298. {
  299. name: 'color',
  300. description:
  301. '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n',
  302. type: 'p5.Color|Number[]|String'
  303. }
  304. ],
  305. class: 'p5',
  306. module: 'Color'
  307. },
  308. red: {
  309. name: 'red',
  310. params: [
  311. {
  312. name: 'color',
  313. description:
  314. '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n',
  315. type: 'p5.Color|Number[]|String'
  316. }
  317. ],
  318. class: 'p5',
  319. module: 'Color'
  320. },
  321. saturation: {
  322. name: 'saturation',
  323. params: [
  324. {
  325. name: 'color',
  326. description:
  327. '<p><a href="#/p5.Color">p5.Color</a> object, color components,\n or CSS color</p>\n',
  328. type: 'p5.Color|Number[]|String'
  329. }
  330. ],
  331. class: 'p5',
  332. module: 'Color'
  333. },
  334. background: {
  335. name: 'background',
  336. class: 'p5',
  337. module: 'Color',
  338. overloads: [
  339. {
  340. params: [
  341. {
  342. name: 'color',
  343. description:
  344. '<p>any value created by the <a href="#/p5/color">color()</a> function</p>\n',
  345. type: 'p5.Color'
  346. }
  347. ],
  348. chainable: 1
  349. },
  350. {
  351. params: [
  352. {
  353. name: 'colorstring',
  354. description:
  355. '<p>color string, possible formats include: integer\n rgb() or rgba(), percentage rgb() or rgba(),\n 3-digit hex, 6-digit hex</p>\n',
  356. type: 'String'
  357. },
  358. {
  359. name: 'a',
  360. description:
  361. '<p>opacity of the background relative to current\n color range (default is 0-255)</p>\n',
  362. type: 'Number',
  363. optional: true
  364. }
  365. ],
  366. chainable: 1
  367. },
  368. {
  369. params: [
  370. {
  371. name: 'gray',
  372. description: '<p>specifies a value between white and black</p>\n',
  373. type: 'Number'
  374. },
  375. {
  376. name: 'a',
  377. description: '',
  378. type: 'Number',
  379. optional: true
  380. }
  381. ],
  382. chainable: 1
  383. },
  384. {
  385. params: [
  386. {
  387. name: 'v1',
  388. description:
  389. '<p>red or hue value (depending on the current color\n mode)</p>\n',
  390. type: 'Number'
  391. },
  392. {
  393. name: 'v2',
  394. description:
  395. '<p>green or saturation value (depending on the current\n color mode)</p>\n',
  396. type: 'Number'
  397. },
  398. {
  399. name: 'v3',
  400. description:
  401. '<p>blue or brightness value (depending on the current\n color mode)</p>\n',
  402. type: 'Number'
  403. },
  404. {
  405. name: 'a',
  406. description: '',
  407. type: 'Number',
  408. optional: true
  409. }
  410. ],
  411. chainable: 1
  412. },
  413. {
  414. params: [
  415. {
  416. name: 'values',
  417. description:
  418. '<p>an array containing the red, green, blue\n and alpha components of the color</p>\n',
  419. type: 'Number[]'
  420. }
  421. ],
  422. chainable: 1
  423. },
  424. {
  425. params: [
  426. {
  427. name: 'image',
  428. description:
  429. '<p>image created with <a href="#/p5/loadImage">loadImage()</a> or <a href="#/p5/createImage">createImage()</a>,\n to set as background\n (must be same size as the sketch window)</p>\n',
  430. type: 'p5.Image'
  431. },
  432. {
  433. name: 'a',
  434. description: '',
  435. type: 'Number',
  436. optional: true
  437. }
  438. ],
  439. chainable: 1
  440. }
  441. ]
  442. },
  443. clear: {
  444. name: 'clear',
  445. class: 'p5',
  446. module: 'Color'
  447. },
  448. colorMode: {
  449. name: 'colorMode',
  450. class: 'p5',
  451. module: 'Color',
  452. overloads: [
  453. {
  454. params: [
  455. {
  456. name: 'mode',
  457. description:
  458. '<p>either RGB, HSB or HSL, corresponding to\n Red/Green/Blue and Hue/Saturation/Brightness\n (or Lightness)</p>\n',
  459. type: 'Constant'
  460. },
  461. {
  462. name: 'max',
  463. description: '<p>range for all values</p>\n',
  464. type: 'Number',
  465. optional: true
  466. }
  467. ],
  468. chainable: 1
  469. },
  470. {
  471. params: [
  472. {
  473. name: 'mode',
  474. description: '',
  475. type: 'Constant'
  476. },
  477. {
  478. name: 'max1',
  479. description:
  480. '<p>range for the red or hue depending on the\n current color mode</p>\n',
  481. type: 'Number'
  482. },
  483. {
  484. name: 'max2',
  485. description:
  486. '<p>range for the green or saturation depending\n on the current color mode</p>\n',
  487. type: 'Number'
  488. },
  489. {
  490. name: 'max3',
  491. description:
  492. '<p>range for the blue or brightness/lightness\n depending on the current color mode</p>\n',
  493. type: 'Number'
  494. },
  495. {
  496. name: 'maxA',
  497. description: '<p>range for the alpha</p>\n',
  498. type: 'Number',
  499. optional: true
  500. }
  501. ],
  502. chainable: 1
  503. }
  504. ]
  505. },
  506. fill: {
  507. name: 'fill',
  508. class: 'p5',
  509. module: 'Color',
  510. overloads: [
  511. {
  512. params: [
  513. {
  514. name: 'v1',
  515. description:
  516. '<p>red or hue value relative to\n the current color range</p>\n',
  517. type: 'Number'
  518. },
  519. {
  520. name: 'v2',
  521. description:
  522. '<p>green or saturation value\n relative to the current color range</p>\n',
  523. type: 'Number'
  524. },
  525. {
  526. name: 'v3',
  527. description:
  528. '<p>blue or brightness value\n relative to the current color range</p>\n',
  529. type: 'Number'
  530. },
  531. {
  532. name: 'alpha',
  533. description: '',
  534. type: 'Number',
  535. optional: true
  536. }
  537. ],
  538. chainable: 1
  539. },
  540. {
  541. params: [
  542. {
  543. name: 'value',
  544. description: '<p>a color string</p>\n',
  545. type: 'String'
  546. }
  547. ],
  548. chainable: 1
  549. },
  550. {
  551. params: [
  552. {
  553. name: 'gray',
  554. description: '<p>a gray value</p>\n',
  555. type: 'Number'
  556. },
  557. {
  558. name: 'alpha',
  559. description: '',
  560. type: 'Number',
  561. optional: true
  562. }
  563. ],
  564. chainable: 1
  565. },
  566. {
  567. params: [
  568. {
  569. name: 'values',
  570. description:
  571. '<p>an array containing the red,green,blue &\n and alpha components of the color</p>\n',
  572. type: 'Number[]'
  573. }
  574. ],
  575. chainable: 1
  576. },
  577. {
  578. params: [
  579. {
  580. name: 'color',
  581. description: '<p>the fill color</p>\n',
  582. type: 'p5.Color'
  583. }
  584. ],
  585. chainable: 1
  586. }
  587. ]
  588. },
  589. noFill: {
  590. name: 'noFill',
  591. class: 'p5',
  592. module: 'Color'
  593. },
  594. noStroke: {
  595. name: 'noStroke',
  596. class: 'p5',
  597. module: 'Color'
  598. },
  599. stroke: {
  600. name: 'stroke',
  601. class: 'p5',
  602. module: 'Color',
  603. overloads: [
  604. {
  605. params: [
  606. {
  607. name: 'v1',
  608. description:
  609. '<p>red or hue value relative to\n the current color range</p>\n',
  610. type: 'Number'
  611. },
  612. {
  613. name: 'v2',
  614. description:
  615. '<p>green or saturation value\n relative to the current color range</p>\n',
  616. type: 'Number'
  617. },
  618. {
  619. name: 'v3',
  620. description:
  621. '<p>blue or brightness value\n relative to the current color range</p>\n',
  622. type: 'Number'
  623. },
  624. {
  625. name: 'alpha',
  626. description: '',
  627. type: 'Number',
  628. optional: true
  629. }
  630. ],
  631. chainable: 1
  632. },
  633. {
  634. params: [
  635. {
  636. name: 'value',
  637. description: '<p>a color string</p>\n',
  638. type: 'String'
  639. }
  640. ],
  641. chainable: 1
  642. },
  643. {
  644. params: [
  645. {
  646. name: 'gray',
  647. description: '<p>a gray value</p>\n',
  648. type: 'Number'
  649. },
  650. {
  651. name: 'alpha',
  652. description: '',
  653. type: 'Number',
  654. optional: true
  655. }
  656. ],
  657. chainable: 1
  658. },
  659. {
  660. params: [
  661. {
  662. name: 'values',
  663. description:
  664. '<p>an array containing the red,green,blue &\n and alpha components of the color</p>\n',
  665. type: 'Number[]'
  666. }
  667. ],
  668. chainable: 1
  669. },
  670. {
  671. params: [
  672. {
  673. name: 'color',
  674. description: '<p>the stroke color</p>\n',
  675. type: 'p5.Color'
  676. }
  677. ],
  678. chainable: 1
  679. }
  680. ]
  681. },
  682. erase: {
  683. name: 'erase',
  684. params: [
  685. {
  686. name: 'strengthFill',
  687. description:
  688. "<p>A number (0-255) for the strength of erasing for a shape's fill.\n This will default to 255 when no argument is given, which\n is full strength.</p>\n",
  689. type: 'Number',
  690. optional: true
  691. },
  692. {
  693. name: 'strengthStroke',
  694. description:
  695. "<p>A number (0-255) for the strength of erasing for a shape's stroke.\n This will default to 255 when no argument is given, which\n is full strength.</p>\n",
  696. type: 'Number',
  697. optional: true
  698. }
  699. ],
  700. class: 'p5',
  701. module: 'Color'
  702. },
  703. noErase: {
  704. name: 'noErase',
  705. class: 'p5',
  706. module: 'Color'
  707. },
  708. arc: {
  709. name: 'arc',
  710. params: [
  711. {
  712. name: 'x',
  713. description: "<p>x-coordinate of the arc's ellipse</p>\n",
  714. type: 'Number'
  715. },
  716. {
  717. name: 'y',
  718. description: "<p>y-coordinate of the arc's ellipse</p>\n",
  719. type: 'Number'
  720. },
  721. {
  722. name: 'w',
  723. description: "<p>width of the arc's ellipse by default</p>\n",
  724. type: 'Number'
  725. },
  726. {
  727. name: 'h',
  728. description: "<p>height of the arc's ellipse by default</p>\n",
  729. type: 'Number'
  730. },
  731. {
  732. name: 'start',
  733. description: '<p>angle to start the arc, specified in radians</p>\n',
  734. type: 'Number'
  735. },
  736. {
  737. name: 'stop',
  738. description: '<p>angle to stop the arc, specified in radians</p>\n',
  739. type: 'Number'
  740. },
  741. {
  742. name: 'mode',
  743. description:
  744. '<p>optional parameter to determine the way of drawing\n the arc. either CHORD, PIE or OPEN</p>\n',
  745. type: 'Constant',
  746. optional: true
  747. },
  748. {
  749. name: 'detail',
  750. description:
  751. "<p>optional parameter for WebGL mode only. This is to\n specify the number of vertices that makes up the\n perimeter of the arc. Default value is 25. Won't\n draw a stroke for a detail of more than 50.</p>\n",
  752. type: 'Integer',
  753. optional: true
  754. }
  755. ],
  756. class: 'p5',
  757. module: 'Shape'
  758. },
  759. ellipse: {
  760. name: 'ellipse',
  761. class: 'p5',
  762. module: 'Shape',
  763. overloads: [
  764. {
  765. params: [
  766. {
  767. name: 'x',
  768. description: '<p>x-coordinate of the center of ellipse.</p>\n',
  769. type: 'Number'
  770. },
  771. {
  772. name: 'y',
  773. description: '<p>y-coordinate of the center of ellipse.</p>\n',
  774. type: 'Number'
  775. },
  776. {
  777. name: 'w',
  778. description: '<p>width of the ellipse.</p>\n',
  779. type: 'Number'
  780. },
  781. {
  782. name: 'h',
  783. description: '<p>height of the ellipse.</p>\n',
  784. type: 'Number',
  785. optional: true
  786. }
  787. ],
  788. chainable: 1
  789. },
  790. {
  791. params: [
  792. {
  793. name: 'x',
  794. description: '',
  795. type: 'Number'
  796. },
  797. {
  798. name: 'y',
  799. description: '',
  800. type: 'Number'
  801. },
  802. {
  803. name: 'w',
  804. description: '',
  805. type: 'Number'
  806. },
  807. {
  808. name: 'h',
  809. description: '',
  810. type: 'Number'
  811. },
  812. {
  813. name: 'detail',
  814. description:
  815. "<p>optional parameter for WebGL mode only. This is to\n specify the number of vertices that makes up the\n perimeter of the ellipse. Default value is 25. Won't\n draw a stroke for a detail of more than 50.</p>\n",
  816. type: 'Integer',
  817. optional: true
  818. }
  819. ]
  820. }
  821. ]
  822. },
  823. circle: {
  824. name: 'circle',
  825. params: [
  826. {
  827. name: 'x',
  828. description: '<p>x-coordinate of the centre of the circle.</p>\n',
  829. type: 'Number'
  830. },
  831. {
  832. name: 'y',
  833. description: '<p>y-coordinate of the centre of the circle.</p>\n',
  834. type: 'Number'
  835. },
  836. {
  837. name: 'd',
  838. description: '<p>diameter of the circle.</p>\n',
  839. type: 'Number'
  840. }
  841. ],
  842. class: 'p5',
  843. module: 'Shape'
  844. },
  845. line: {
  846. name: 'line',
  847. class: 'p5',
  848. module: 'Shape',
  849. overloads: [
  850. {
  851. params: [
  852. {
  853. name: 'x1',
  854. description: '<p>the x-coordinate of the first point</p>\n',
  855. type: 'Number'
  856. },
  857. {
  858. name: 'y1',
  859. description: '<p>the y-coordinate of the first point</p>\n',
  860. type: 'Number'
  861. },
  862. {
  863. name: 'x2',
  864. description: '<p>the x-coordinate of the second point</p>\n',
  865. type: 'Number'
  866. },
  867. {
  868. name: 'y2',
  869. description: '<p>the y-coordinate of the second point</p>\n',
  870. type: 'Number'
  871. }
  872. ],
  873. chainable: 1
  874. },
  875. {
  876. params: [
  877. {
  878. name: 'x1',
  879. description: '',
  880. type: 'Number'
  881. },
  882. {
  883. name: 'y1',
  884. description: '',
  885. type: 'Number'
  886. },
  887. {
  888. name: 'z1',
  889. description: '<p>the z-coordinate of the first point</p>\n',
  890. type: 'Number'
  891. },
  892. {
  893. name: 'x2',
  894. description: '',
  895. type: 'Number'
  896. },
  897. {
  898. name: 'y2',
  899. description: '',
  900. type: 'Number'
  901. },
  902. {
  903. name: 'z2',
  904. description: '<p>the z-coordinate of the second point</p>\n',
  905. type: 'Number'
  906. }
  907. ],
  908. chainable: 1
  909. }
  910. ]
  911. },
  912. point: {
  913. name: 'point',
  914. class: 'p5',
  915. module: 'Shape',
  916. overloads: [
  917. {
  918. params: [
  919. {
  920. name: 'x',
  921. description: '<p>the x-coordinate</p>\n',
  922. type: 'Number'
  923. },
  924. {
  925. name: 'y',
  926. description: '<p>the y-coordinate</p>\n',
  927. type: 'Number'
  928. },
  929. {
  930. name: 'z',
  931. description: '<p>the z-coordinate (for WebGL mode)</p>\n',
  932. type: 'Number',
  933. optional: true
  934. }
  935. ],
  936. chainable: 1
  937. },
  938. {
  939. params: [
  940. {
  941. name: 'coordinate_vector',
  942. description: '<p>the coordinate vector</p>\n',
  943. type: 'p5.Vector'
  944. }
  945. ],
  946. chainable: 1
  947. }
  948. ]
  949. },
  950. quad: {
  951. name: 'quad',
  952. class: 'p5',
  953. module: 'Shape',
  954. overloads: [
  955. {
  956. params: [
  957. {
  958. name: 'x1',
  959. description: '<p>the x-coordinate of the first point</p>\n',
  960. type: 'Number'
  961. },
  962. {
  963. name: 'y1',
  964. description: '<p>the y-coordinate of the first point</p>\n',
  965. type: 'Number'
  966. },
  967. {
  968. name: 'x2',
  969. description: '<p>the x-coordinate of the second point</p>\n',
  970. type: 'Number'
  971. },
  972. {
  973. name: 'y2',
  974. description: '<p>the y-coordinate of the second point</p>\n',
  975. type: 'Number'
  976. },
  977. {
  978. name: 'x3',
  979. description: '<p>the x-coordinate of the third point</p>\n',
  980. type: 'Number'
  981. },
  982. {
  983. name: 'y3',
  984. description: '<p>the y-coordinate of the third point</p>\n',
  985. type: 'Number'
  986. },
  987. {
  988. name: 'x4',
  989. description: '<p>the x-coordinate of the fourth point</p>\n',
  990. type: 'Number'
  991. },
  992. {
  993. name: 'y4',
  994. description: '<p>the y-coordinate of the fourth point</p>\n',
  995. type: 'Number'
  996. },
  997. {
  998. name: 'detailX',
  999. description: '<p>number of segments in the x-direction</p>\n',
  1000. type: 'Integer',
  1001. optional: true
  1002. },
  1003. {
  1004. name: 'detailY',
  1005. description: '<p>number of segments in the y-direction</p>\n',
  1006. type: 'Integer',
  1007. optional: true
  1008. }
  1009. ],
  1010. chainable: 1
  1011. },
  1012. {
  1013. params: [
  1014. {
  1015. name: 'x1',
  1016. description: '',
  1017. type: 'Number'
  1018. },
  1019. {
  1020. name: 'y1',
  1021. description: '',
  1022. type: 'Number'
  1023. },
  1024. {
  1025. name: 'z1',
  1026. description: '<p>the z-coordinate of the first point</p>\n',
  1027. type: 'Number'
  1028. },
  1029. {
  1030. name: 'x2',
  1031. description: '',
  1032. type: 'Number'
  1033. },
  1034. {
  1035. name: 'y2',
  1036. description: '',
  1037. type: 'Number'
  1038. },
  1039. {
  1040. name: 'z2',
  1041. description: '<p>the z-coordinate of the second point</p>\n',
  1042. type: 'Number'
  1043. },
  1044. {
  1045. name: 'x3',
  1046. description: '',
  1047. type: 'Number'
  1048. },
  1049. {
  1050. name: 'y3',
  1051. description: '',
  1052. type: 'Number'
  1053. },
  1054. {
  1055. name: 'z3',
  1056. description: '<p>the z-coordinate of the third point</p>\n',
  1057. type: 'Number'
  1058. },
  1059. {
  1060. name: 'x4',
  1061. description: '',
  1062. type: 'Number'
  1063. },
  1064. {
  1065. name: 'y4',
  1066. description: '',
  1067. type: 'Number'
  1068. },
  1069. {
  1070. name: 'z4',
  1071. description: '<p>the z-coordinate of the fourth point</p>\n',
  1072. type: 'Number'
  1073. },
  1074. {
  1075. name: 'detailX',
  1076. description: '',
  1077. type: 'Integer',
  1078. optional: true
  1079. },
  1080. {
  1081. name: 'detailY',
  1082. description: '',
  1083. type: 'Integer',
  1084. optional: true
  1085. }
  1086. ],
  1087. chainable: 1
  1088. }
  1089. ]
  1090. },
  1091. rect: {
  1092. name: 'rect',
  1093. class: 'p5',
  1094. module: 'Shape',
  1095. overloads: [
  1096. {
  1097. params: [
  1098. {
  1099. name: 'x',
  1100. description: '<p>x-coordinate of the rectangle.</p>\n',
  1101. type: 'Number'
  1102. },
  1103. {
  1104. name: 'y',
  1105. description: '<p>y-coordinate of the rectangle.</p>\n',
  1106. type: 'Number'
  1107. },
  1108. {
  1109. name: 'w',
  1110. description: '<p>width of the rectangle.</p>\n',
  1111. type: 'Number'
  1112. },
  1113. {
  1114. name: 'h',
  1115. description: '<p>height of the rectangle.</p>\n',
  1116. type: 'Number',
  1117. optional: true
  1118. },
  1119. {
  1120. name: 'tl',
  1121. description: '<p>optional radius of top-left corner.</p>\n',
  1122. type: 'Number',
  1123. optional: true
  1124. },
  1125. {
  1126. name: 'tr',
  1127. description: '<p>optional radius of top-right corner.</p>\n',
  1128. type: 'Number',
  1129. optional: true
  1130. },
  1131. {
  1132. name: 'br',
  1133. description: '<p>optional radius of bottom-right corner.</p>\n',
  1134. type: 'Number',
  1135. optional: true
  1136. },
  1137. {
  1138. name: 'bl',
  1139. description: '<p>optional radius of bottom-left corner.</p>\n',
  1140. type: 'Number',
  1141. optional: true
  1142. }
  1143. ],
  1144. chainable: 1
  1145. },
  1146. {
  1147. params: [
  1148. {
  1149. name: 'x',
  1150. description: '',
  1151. type: 'Number'
  1152. },
  1153. {
  1154. name: 'y',
  1155. description: '',
  1156. type: 'Number'
  1157. },
  1158. {
  1159. name: 'w',
  1160. description: '',
  1161. type: 'Number'
  1162. },
  1163. {
  1164. name: 'h',
  1165. description: '',
  1166. type: 'Number'
  1167. },
  1168. {
  1169. name: 'detailX',
  1170. description:
  1171. '<p>number of segments in the x-direction (for WebGL mode)</p>\n',
  1172. type: 'Integer',
  1173. optional: true
  1174. },
  1175. {
  1176. name: 'detailY',
  1177. description:
  1178. '<p>number of segments in the y-direction (for WebGL mode)</p>\n',
  1179. type: 'Integer',
  1180. optional: true
  1181. }
  1182. ],
  1183. chainable: 1
  1184. }
  1185. ]
  1186. },
  1187. square: {
  1188. name: 'square',
  1189. params: [
  1190. {
  1191. name: 'x',
  1192. description: '<p>x-coordinate of the square.</p>\n',
  1193. type: 'Number'
  1194. },
  1195. {
  1196. name: 'y',
  1197. description: '<p>y-coordinate of the square.</p>\n',
  1198. type: 'Number'
  1199. },
  1200. {
  1201. name: 's',
  1202. description: '<p>side size of the square.</p>\n',
  1203. type: 'Number'
  1204. },
  1205. {
  1206. name: 'tl',
  1207. description: '<p>optional radius of top-left corner.</p>\n',
  1208. type: 'Number',
  1209. optional: true
  1210. },
  1211. {
  1212. name: 'tr',
  1213. description: '<p>optional radius of top-right corner.</p>\n',
  1214. type: 'Number',
  1215. optional: true
  1216. },
  1217. {
  1218. name: 'br',
  1219. description: '<p>optional radius of bottom-right corner.</p>\n',
  1220. type: 'Number',
  1221. optional: true
  1222. },
  1223. {
  1224. name: 'bl',
  1225. description: '<p>optional radius of bottom-left corner.</p>\n',
  1226. type: 'Number',
  1227. optional: true
  1228. }
  1229. ],
  1230. class: 'p5',
  1231. module: 'Shape'
  1232. },
  1233. triangle: {
  1234. name: 'triangle',
  1235. params: [
  1236. {
  1237. name: 'x1',
  1238. description: '<p>x-coordinate of the first point</p>\n',
  1239. type: 'Number'
  1240. },
  1241. {
  1242. name: 'y1',
  1243. description: '<p>y-coordinate of the first point</p>\n',
  1244. type: 'Number'
  1245. },
  1246. {
  1247. name: 'x2',
  1248. description: '<p>x-coordinate of the second point</p>\n',
  1249. type: 'Number'
  1250. },
  1251. {
  1252. name: 'y2',
  1253. description: '<p>y-coordinate of the second point</p>\n',
  1254. type: 'Number'
  1255. },
  1256. {
  1257. name: 'x3',
  1258. description: '<p>x-coordinate of the third point</p>\n',
  1259. type: 'Number'
  1260. },
  1261. {
  1262. name: 'y3',
  1263. description: '<p>y-coordinate of the third point</p>\n',
  1264. type: 'Number'
  1265. }
  1266. ],
  1267. class: 'p5',
  1268. module: 'Shape'
  1269. },
  1270. ellipseMode: {
  1271. name: 'ellipseMode',
  1272. params: [
  1273. {
  1274. name: 'mode',
  1275. description: '<p>either CENTER, RADIUS, CORNER, or CORNERS</p>\n',
  1276. type: 'Constant'
  1277. }
  1278. ],
  1279. class: 'p5',
  1280. module: 'Shape'
  1281. },
  1282. noSmooth: {
  1283. name: 'noSmooth',
  1284. class: 'p5',
  1285. module: 'Shape'
  1286. },
  1287. rectMode: {
  1288. name: 'rectMode',
  1289. params: [
  1290. {
  1291. name: 'mode',
  1292. description: '<p>either CORNER, CORNERS, CENTER, or RADIUS</p>\n',
  1293. type: 'Constant'
  1294. }
  1295. ],
  1296. class: 'p5',
  1297. module: 'Shape'
  1298. },
  1299. smooth: {
  1300. name: 'smooth',
  1301. class: 'p5',
  1302. module: 'Shape'
  1303. },
  1304. strokeCap: {
  1305. name: 'strokeCap',
  1306. params: [
  1307. {
  1308. name: 'cap',
  1309. description: '<p>either ROUND, SQUARE or PROJECT</p>\n',
  1310. type: 'Constant'
  1311. }
  1312. ],
  1313. class: 'p5',
  1314. module: 'Shape'
  1315. },
  1316. strokeJoin: {
  1317. name: 'strokeJoin',
  1318. params: [
  1319. {
  1320. name: 'join',
  1321. description: '<p>either MITER, BEVEL, ROUND</p>\n',
  1322. type: 'Constant'
  1323. }
  1324. ],
  1325. class: 'p5',
  1326. module: 'Shape'
  1327. },
  1328. strokeWeight: {
  1329. name: 'strokeWeight',
  1330. params: [
  1331. {
  1332. name: 'weight',
  1333. description: '<p>the weight of the stroke (in pixels)</p>\n',
  1334. type: 'Number'
  1335. }
  1336. ],
  1337. class: 'p5',
  1338. module: 'Shape'
  1339. },
  1340. bezier: {
  1341. name: 'bezier',
  1342. class: 'p5',
  1343. module: 'Shape',
  1344. overloads: [
  1345. {
  1346. params: [
  1347. {
  1348. name: 'x1',
  1349. description: '<p>x-coordinate for the first anchor point</p>\n',
  1350. type: 'Number'
  1351. },
  1352. {
  1353. name: 'y1',
  1354. description: '<p>y-coordinate for the first anchor point</p>\n',
  1355. type: 'Number'
  1356. },
  1357. {
  1358. name: 'x2',
  1359. description: '<p>x-coordinate for the first control point</p>\n',
  1360. type: 'Number'
  1361. },
  1362. {
  1363. name: 'y2',
  1364. description: '<p>y-coordinate for the first control point</p>\n',
  1365. type: 'Number'
  1366. },
  1367. {
  1368. name: 'x3',
  1369. description: '<p>x-coordinate for the second control point</p>\n',
  1370. type: 'Number'
  1371. },
  1372. {
  1373. name: 'y3',
  1374. description: '<p>y-coordinate for the second control point</p>\n',
  1375. type: 'Number'
  1376. },
  1377. {
  1378. name: 'x4',
  1379. description: '<p>x-coordinate for the second anchor point</p>\n',
  1380. type: 'Number'
  1381. },
  1382. {
  1383. name: 'y4',
  1384. description: '<p>y-coordinate for the second anchor point</p>\n',
  1385. type: 'Number'
  1386. }
  1387. ],
  1388. chainable: 1
  1389. },
  1390. {
  1391. params: [
  1392. {
  1393. name: 'x1',
  1394. description: '',
  1395. type: 'Number'
  1396. },
  1397. {
  1398. name: 'y1',
  1399. description: '',
  1400. type: 'Number'
  1401. },
  1402. {
  1403. name: 'z1',
  1404. description: '<p>z-coordinate for the first anchor point</p>\n',
  1405. type: 'Number'
  1406. },
  1407. {
  1408. name: 'x2',
  1409. description: '',
  1410. type: 'Number'
  1411. },
  1412. {
  1413. name: 'y2',
  1414. description: '',
  1415. type: 'Number'
  1416. },
  1417. {
  1418. name: 'z2',
  1419. description: '<p>z-coordinate for the first control point</p>\n',
  1420. type: 'Number'
  1421. },
  1422. {
  1423. name: 'x3',
  1424. description: '',
  1425. type: 'Number'
  1426. },
  1427. {
  1428. name: 'y3',
  1429. description: '',
  1430. type: 'Number'
  1431. },
  1432. {
  1433. name: 'z3',
  1434. description: '<p>z-coordinate for the second control point</p>\n',
  1435. type: 'Number'
  1436. },
  1437. {
  1438. name: 'x4',
  1439. description: '',
  1440. type: 'Number'
  1441. },
  1442. {
  1443. name: 'y4',
  1444. description: '',
  1445. type: 'Number'
  1446. },
  1447. {
  1448. name: 'z4',
  1449. description: '<p>z-coordinate for the second anchor point</p>\n',
  1450. type: 'Number'
  1451. }
  1452. ],
  1453. chainable: 1
  1454. }
  1455. ]
  1456. },
  1457. bezierDetail: {
  1458. name: 'bezierDetail',
  1459. params: [
  1460. {
  1461. name: 'detail',
  1462. description: '<p>resolution of the curves</p>\n',
  1463. type: 'Number'
  1464. }
  1465. ],
  1466. class: 'p5',
  1467. module: 'Shape'
  1468. },
  1469. bezierPoint: {
  1470. name: 'bezierPoint',
  1471. params: [
  1472. {
  1473. name: 'a',
  1474. description: '<p>coordinate of first point on the curve</p>\n',
  1475. type: 'Number'
  1476. },
  1477. {
  1478. name: 'b',
  1479. description: '<p>coordinate of first control point</p>\n',
  1480. type: 'Number'
  1481. },
  1482. {
  1483. name: 'c',
  1484. description: '<p>coordinate of second control point</p>\n',
  1485. type: 'Number'
  1486. },
  1487. {
  1488. name: 'd',
  1489. description: '<p>coordinate of second point on the curve</p>\n',
  1490. type: 'Number'
  1491. },
  1492. {
  1493. name: 't',
  1494. description: '<p>value between 0 and 1</p>\n',
  1495. type: 'Number'
  1496. }
  1497. ],
  1498. class: 'p5',
  1499. module: 'Shape'
  1500. },
  1501. bezierTangent: {
  1502. name: 'bezierTangent',
  1503. params: [
  1504. {
  1505. name: 'a',
  1506. description: '<p>coordinate of first point on the curve</p>\n',
  1507. type: 'Number'
  1508. },
  1509. {
  1510. name: 'b',
  1511. description: '<p>coordinate of first control point</p>\n',
  1512. type: 'Number'
  1513. },
  1514. {
  1515. name: 'c',
  1516. description: '<p>coordinate of second control point</p>\n',
  1517. type: 'Number'
  1518. },
  1519. {
  1520. name: 'd',
  1521. description: '<p>coordinate of second point on the curve</p>\n',
  1522. type: 'Number'
  1523. },
  1524. {
  1525. name: 't',
  1526. description: '<p>value between 0 and 1</p>\n',
  1527. type: 'Number'
  1528. }
  1529. ],
  1530. class: 'p5',
  1531. module: 'Shape'
  1532. },
  1533. curve: {
  1534. name: 'curve',
  1535. class: 'p5',
  1536. module: 'Shape',
  1537. overloads: [
  1538. {
  1539. params: [
  1540. {
  1541. name: 'x1',
  1542. description:
  1543. '<p>x-coordinate for the beginning control point</p>\n',
  1544. type: 'Number'
  1545. },
  1546. {
  1547. name: 'y1',
  1548. description:
  1549. '<p>y-coordinate for the beginning control point</p>\n',
  1550. type: 'Number'
  1551. },
  1552. {
  1553. name: 'x2',
  1554. description: '<p>x-coordinate for the first point</p>\n',
  1555. type: 'Number'
  1556. },
  1557. {
  1558. name: 'y2',
  1559. description: '<p>y-coordinate for the first point</p>\n',
  1560. type: 'Number'
  1561. },
  1562. {
  1563. name: 'x3',
  1564. description: '<p>x-coordinate for the second point</p>\n',
  1565. type: 'Number'
  1566. },
  1567. {
  1568. name: 'y3',
  1569. description: '<p>y-coordinate for the second point</p>\n',
  1570. type: 'Number'
  1571. },
  1572. {
  1573. name: 'x4',
  1574. description: '<p>x-coordinate for the ending control point</p>\n',
  1575. type: 'Number'
  1576. },
  1577. {
  1578. name: 'y4',
  1579. description: '<p>y-coordinate for the ending control point</p>\n',
  1580. type: 'Number'
  1581. }
  1582. ],
  1583. chainable: 1
  1584. },
  1585. {
  1586. params: [
  1587. {
  1588. name: 'x1',
  1589. description: '',
  1590. type: 'Number'
  1591. },
  1592. {
  1593. name: 'y1',
  1594. description: '',
  1595. type: 'Number'
  1596. },
  1597. {
  1598. name: 'z1',
  1599. description:
  1600. '<p>z-coordinate for the beginning control point</p>\n',
  1601. type: 'Number'
  1602. },
  1603. {
  1604. name: 'x2',
  1605. description: '',
  1606. type: 'Number'
  1607. },
  1608. {
  1609. name: 'y2',
  1610. description: '',
  1611. type: 'Number'
  1612. },
  1613. {
  1614. name: 'z2',
  1615. description: '<p>z-coordinate for the first point</p>\n',
  1616. type: 'Number'
  1617. },
  1618. {
  1619. name: 'x3',
  1620. description: '',
  1621. type: 'Number'
  1622. },
  1623. {
  1624. name: 'y3',
  1625. description: '',
  1626. type: 'Number'
  1627. },
  1628. {
  1629. name: 'z3',
  1630. description: '<p>z-coordinate for the second point</p>\n',
  1631. type: 'Number'
  1632. },
  1633. {
  1634. name: 'x4',
  1635. description: '',
  1636. type: 'Number'
  1637. },
  1638. {
  1639. name: 'y4',
  1640. description: '',
  1641. type: 'Number'
  1642. },
  1643. {
  1644. name: 'z4',
  1645. description: '<p>z-coordinate for the ending control point</p>\n',
  1646. type: 'Number'
  1647. }
  1648. ],
  1649. chainable: 1
  1650. }
  1651. ]
  1652. },
  1653. curveDetail: {
  1654. name: 'curveDetail',
  1655. params: [
  1656. {
  1657. name: 'resolution',
  1658. description: '<p>resolution of the curves</p>\n',
  1659. type: 'Number'
  1660. }
  1661. ],
  1662. class: 'p5',
  1663. module: 'Shape'
  1664. },
  1665. curveTightness: {
  1666. name: 'curveTightness',
  1667. params: [
  1668. {
  1669. name: 'amount',
  1670. description:
  1671. '<p>amount of deformation from the original vertices</p>\n',
  1672. type: 'Number'
  1673. }
  1674. ],
  1675. class: 'p5',
  1676. module: 'Shape'
  1677. },
  1678. curvePoint: {
  1679. name: 'curvePoint',
  1680. params: [
  1681. {
  1682. name: 'a',
  1683. description: '<p>coordinate of first control point of the curve</p>\n',
  1684. type: 'Number'
  1685. },
  1686. {
  1687. name: 'b',
  1688. description: '<p>coordinate of first point</p>\n',
  1689. type: 'Number'
  1690. },
  1691. {
  1692. name: 'c',
  1693. description: '<p>coordinate of second point</p>\n',
  1694. type: 'Number'
  1695. },
  1696. {
  1697. name: 'd',
  1698. description: '<p>coordinate of second control point</p>\n',
  1699. type: 'Number'
  1700. },
  1701. {
  1702. name: 't',
  1703. description: '<p>value between 0 and 1</p>\n',
  1704. type: 'Number'
  1705. }
  1706. ],
  1707. class: 'p5',
  1708. module: 'Shape'
  1709. },
  1710. curveTangent: {
  1711. name: 'curveTangent',
  1712. params: [
  1713. {
  1714. name: 'a',
  1715. description: '<p>coordinate of first control point</p>\n',
  1716. type: 'Number'
  1717. },
  1718. {
  1719. name: 'b',
  1720. description: '<p>coordinate of first point on the curve</p>\n',
  1721. type: 'Number'
  1722. },
  1723. {
  1724. name: 'c',
  1725. description: '<p>coordinate of second point on the curve</p>\n',
  1726. type: 'Number'
  1727. },
  1728. {
  1729. name: 'd',
  1730. description: '<p>coordinate of second conrol point</p>\n',
  1731. type: 'Number'
  1732. },
  1733. {
  1734. name: 't',
  1735. description: '<p>value between 0 and 1</p>\n',
  1736. type: 'Number'
  1737. }
  1738. ],
  1739. class: 'p5',
  1740. module: 'Shape'
  1741. },
  1742. beginContour: {
  1743. name: 'beginContour',
  1744. class: 'p5',
  1745. module: 'Shape'
  1746. },
  1747. beginShape: {
  1748. name: 'beginShape',
  1749. params: [
  1750. {
  1751. name: 'kind',
  1752. description:
  1753. '<p>either POINTS, LINES, TRIANGLES, TRIANGLE_FAN\n TRIANGLE_STRIP, QUADS, QUAD_STRIP or TESS</p>\n',
  1754. type: 'Constant',
  1755. optional: true
  1756. }
  1757. ],
  1758. class: 'p5',
  1759. module: 'Shape'
  1760. },
  1761. bezierVertex: {
  1762. name: 'bezierVertex',
  1763. class: 'p5',
  1764. module: 'Shape',
  1765. overloads: [
  1766. {
  1767. params: [
  1768. {
  1769. name: 'x2',
  1770. description: '<p>x-coordinate for the first control point</p>\n',
  1771. type: 'Number'
  1772. },
  1773. {
  1774. name: 'y2',
  1775. description: '<p>y-coordinate for the first control point</p>\n',
  1776. type: 'Number'
  1777. },
  1778. {
  1779. name: 'x3',
  1780. description: '<p>x-coordinate for the second control point</p>\n',
  1781. type: 'Number'
  1782. },
  1783. {
  1784. name: 'y3',
  1785. description: '<p>y-coordinate for the second control point</p>\n',
  1786. type: 'Number'
  1787. },
  1788. {
  1789. name: 'x4',
  1790. description: '<p>x-coordinate for the anchor point</p>\n',
  1791. type: 'Number'
  1792. },
  1793. {
  1794. name: 'y4',
  1795. description: '<p>y-coordinate for the anchor point</p>\n',
  1796. type: 'Number'
  1797. }
  1798. ],
  1799. chainable: 1
  1800. },
  1801. {
  1802. params: [
  1803. {
  1804. name: 'x2',
  1805. description: '',
  1806. type: 'Number'
  1807. },
  1808. {
  1809. name: 'y2',
  1810. description: '',
  1811. type: 'Number'
  1812. },
  1813. {
  1814. name: 'z2',
  1815. description:
  1816. '<p>z-coordinate for the first control point (for WebGL mode)</p>\n',
  1817. type: 'Number'
  1818. },
  1819. {
  1820. name: 'x3',
  1821. description: '',
  1822. type: 'Number'
  1823. },
  1824. {
  1825. name: 'y3',
  1826. description: '',
  1827. type: 'Number'
  1828. },
  1829. {
  1830. name: 'z3',
  1831. description:
  1832. '<p>z-coordinate for the second control point (for WebGL mode)</p>\n',
  1833. type: 'Number'
  1834. },
  1835. {
  1836. name: 'x4',
  1837. description: '',
  1838. type: 'Number'
  1839. },
  1840. {
  1841. name: 'y4',
  1842. description: '',
  1843. type: 'Number'
  1844. },
  1845. {
  1846. name: 'z4',
  1847. description:
  1848. '<p>z-coordinate for the anchor point (for WebGL mode)</p>\n',
  1849. type: 'Number'
  1850. }
  1851. ],
  1852. chainable: 1
  1853. }
  1854. ]
  1855. },
  1856. curveVertex: {
  1857. name: 'curveVertex',
  1858. class: 'p5',
  1859. module: 'Shape',
  1860. overloads: [
  1861. {
  1862. params: [
  1863. {
  1864. name: 'x',
  1865. description: '<p>x-coordinate of the vertex</p>\n',
  1866. type: 'Number'
  1867. },
  1868. {
  1869. name: 'y',
  1870. description: '<p>y-coordinate of the vertex</p>\n',
  1871. type: 'Number'
  1872. }
  1873. ],
  1874. chainable: 1
  1875. },
  1876. {
  1877. params: [
  1878. {
  1879. name: 'x',
  1880. description: '',
  1881. type: 'Number'
  1882. },
  1883. {
  1884. name: 'y',
  1885. description: '',
  1886. type: 'Number'
  1887. },
  1888. {
  1889. name: 'z',
  1890. description: '<p>z-coordinate of the vertex (for WebGL mode)</p>\n',
  1891. type: 'Number',
  1892. optional: true
  1893. }
  1894. ],
  1895. chainable: 1
  1896. }
  1897. ]
  1898. },
  1899. endContour: {
  1900. name: 'endContour',
  1901. class: 'p5',
  1902. module: 'Shape'
  1903. },
  1904. endShape: {
  1905. name: 'endShape',
  1906. params: [
  1907. {
  1908. name: 'mode',
  1909. description: '<p>use CLOSE to close the shape</p>\n',
  1910. type: 'Constant',
  1911. optional: true
  1912. }
  1913. ],
  1914. class: 'p5',
  1915. module: 'Shape'
  1916. },
  1917. quadraticVertex: {
  1918. name: 'quadraticVertex',
  1919. class: 'p5',
  1920. module: 'Shape',
  1921. overloads: [
  1922. {
  1923. params: [
  1924. {
  1925. name: 'cx',
  1926. description: '<p>x-coordinate for the control point</p>\n',
  1927. type: 'Number'
  1928. },
  1929. {
  1930. name: 'cy',
  1931. description: '<p>y-coordinate for the control point</p>\n',
  1932. type: 'Number'
  1933. },
  1934. {
  1935. name: 'x3',
  1936. description: '<p>x-coordinate for the anchor point</p>\n',
  1937. type: 'Number'
  1938. },
  1939. {
  1940. name: 'y3',
  1941. description: '<p>y-coordinate for the anchor point</p>\n',
  1942. type: 'Number'
  1943. }
  1944. ],
  1945. chainable: 1
  1946. },
  1947. {
  1948. params: [
  1949. {
  1950. name: 'cx',
  1951. description: '',
  1952. type: 'Number'
  1953. },
  1954. {
  1955. name: 'cy',
  1956. description: '',
  1957. type: 'Number'
  1958. },
  1959. {
  1960. name: 'cz',
  1961. description:
  1962. '<p>z-coordinate for the control point (for WebGL mode)</p>\n',
  1963. type: 'Number'
  1964. },
  1965. {
  1966. name: 'x3',
  1967. description: '',
  1968. type: 'Number'
  1969. },
  1970. {
  1971. name: 'y3',
  1972. description: '',
  1973. type: 'Number'
  1974. },
  1975. {
  1976. name: 'z3',
  1977. description:
  1978. '<p>z-coordinate for the anchor point (for WebGL mode)</p>\n',
  1979. type: 'Number'
  1980. }
  1981. ],
  1982. chainable: 1
  1983. }
  1984. ]
  1985. },
  1986. vertex: {
  1987. name: 'vertex',
  1988. class: 'p5',
  1989. module: 'Shape',
  1990. overloads: [
  1991. {
  1992. params: [
  1993. {
  1994. name: 'x',
  1995. description: '<p>x-coordinate of the vertex</p>\n',
  1996. type: 'Number'
  1997. },
  1998. {
  1999. name: 'y',
  2000. description: '<p>y-coordinate of the vertex</p>\n',
  2001. type: 'Number'
  2002. }
  2003. ],
  2004. chainable: 1
  2005. },
  2006. {
  2007. params: [
  2008. {
  2009. name: 'x',
  2010. description: '',
  2011. type: 'Number'
  2012. },
  2013. {
  2014. name: 'y',
  2015. description: '',
  2016. type: 'Number'
  2017. },
  2018. {
  2019. name: 'z',
  2020. description:
  2021. '<p>z-coordinate of the vertex.\n Defaults to 0 if not specified.</p>\n',
  2022. type: 'Number'
  2023. }
  2024. ],
  2025. chainable: 1
  2026. },
  2027. {
  2028. params: [
  2029. {
  2030. name: 'x',
  2031. description: '',
  2032. type: 'Number'
  2033. },
  2034. {
  2035. name: 'y',
  2036. description: '',
  2037. type: 'Number'
  2038. },
  2039. {
  2040. name: 'z',
  2041. description: '',
  2042. type: 'Number',
  2043. optional: true
  2044. },
  2045. {
  2046. name: 'u',
  2047. description: "<p>the vertex's texture u-coordinate</p>\n",
  2048. type: 'Number'
  2049. },
  2050. {
  2051. name: 'v',
  2052. description: "<p>the vertex's texture v-coordinate</p>\n",
  2053. type: 'Number'
  2054. }
  2055. ],
  2056. chainable: 1
  2057. }
  2058. ]
  2059. },
  2060. normal: {
  2061. name: 'normal',
  2062. class: 'p5',
  2063. module: 'Shape',
  2064. overloads: [
  2065. {
  2066. params: [
  2067. {
  2068. name: 'vector',
  2069. description: '<p>A p5.Vector representing the vertex normal.</p>\n',
  2070. type: 'Vector'
  2071. }
  2072. ],
  2073. chainable: 1
  2074. },
  2075. {
  2076. params: [
  2077. {
  2078. name: 'x',
  2079. description: '<p>The x component of the vertex normal.</p>\n',
  2080. type: 'Number'
  2081. },
  2082. {
  2083. name: 'y',
  2084. description: '<p>The y component of the vertex normal.</p>\n',
  2085. type: 'Number'
  2086. },
  2087. {
  2088. name: 'z',
  2089. description: '<p>The z component of the vertex normal.</p>\n',
  2090. type: 'Number'
  2091. }
  2092. ],
  2093. chainable: 1
  2094. }
  2095. ]
  2096. },
  2097. VERSION: {
  2098. name: 'VERSION',
  2099. class: 'p5',
  2100. module: 'Constants'
  2101. },
  2102. P2D: {
  2103. name: 'P2D',
  2104. class: 'p5',
  2105. module: 'Constants'
  2106. },
  2107. WEBGL: {
  2108. name: 'WEBGL',
  2109. class: 'p5',
  2110. module: 'Constants'
  2111. },
  2112. ARROW: {
  2113. name: 'ARROW',
  2114. class: 'p5',
  2115. module: 'Constants'
  2116. },
  2117. CROSS: {
  2118. name: 'CROSS',
  2119. class: 'p5',
  2120. module: 'Constants'
  2121. },
  2122. HAND: {
  2123. name: 'HAND',
  2124. class: 'p5',
  2125. module: 'Constants'
  2126. },
  2127. MOVE: {
  2128. name: 'MOVE',
  2129. class: 'p5',
  2130. module: 'Constants'
  2131. },
  2132. TEXT: {
  2133. name: 'TEXT',
  2134. class: 'p5',
  2135. module: 'Constants'
  2136. },
  2137. WAIT: {
  2138. name: 'WAIT',
  2139. class: 'p5',
  2140. module: 'Constants'
  2141. },
  2142. HALF_PI: {
  2143. name: 'HALF_PI',
  2144. class: 'p5',
  2145. module: 'Constants'
  2146. },
  2147. PI: {
  2148. name: 'PI',
  2149. class: 'p5',
  2150. module: 'Constants'
  2151. },
  2152. QUARTER_PI: {
  2153. name: 'QUARTER_PI',
  2154. class: 'p5',
  2155. module: 'Constants'
  2156. },
  2157. TAU: {
  2158. name: 'TAU',
  2159. class: 'p5',
  2160. module: 'Constants'
  2161. },
  2162. TWO_PI: {
  2163. name: 'TWO_PI',
  2164. class: 'p5',
  2165. module: 'Constants'
  2166. },
  2167. DEGREES: {
  2168. name: 'DEGREES',
  2169. class: 'p5',
  2170. module: 'Constants'
  2171. },
  2172. RADIANS: {
  2173. name: 'RADIANS',
  2174. class: 'p5',
  2175. module: 'Constants'
  2176. },
  2177. CORNER: {
  2178. name: 'CORNER',
  2179. class: 'p5',
  2180. module: 'Constants'
  2181. },
  2182. CORNERS: {
  2183. name: 'CORNERS',
  2184. class: 'p5',
  2185. module: 'Constants'
  2186. },
  2187. RADIUS: {
  2188. name: 'RADIUS',
  2189. class: 'p5',
  2190. module: 'Constants'
  2191. },
  2192. RIGHT: {
  2193. name: 'RIGHT',
  2194. class: 'p5',
  2195. module: 'Constants'
  2196. },
  2197. LEFT: {
  2198. name: 'LEFT',
  2199. class: 'p5',
  2200. module: 'Constants'
  2201. },
  2202. CENTER: {
  2203. name: 'CENTER',
  2204. class: 'p5',
  2205. module: 'Constants'
  2206. },
  2207. TOP: {
  2208. name: 'TOP',
  2209. class: 'p5',
  2210. module: 'Constants'
  2211. },
  2212. BOTTOM: {
  2213. name: 'BOTTOM',
  2214. class: 'p5',
  2215. module: 'Constants'
  2216. },
  2217. BASELINE: {
  2218. name: 'BASELINE',
  2219. class: 'p5',
  2220. module: 'Constants'
  2221. },
  2222. POINTS: {
  2223. name: 'POINTS',
  2224. class: 'p5',
  2225. module: 'Constants'
  2226. },
  2227. LINES: {
  2228. name: 'LINES',
  2229. class: 'p5',
  2230. module: 'Constants'
  2231. },
  2232. LINE_STRIP: {
  2233. name: 'LINE_STRIP',
  2234. class: 'p5',
  2235. module: 'Constants'
  2236. },
  2237. LINE_LOOP: {
  2238. name: 'LINE_LOOP',
  2239. class: 'p5',
  2240. module: 'Constants'
  2241. },
  2242. TRIANGLES: {
  2243. name: 'TRIANGLES',
  2244. class: 'p5',
  2245. module: 'Constants'
  2246. },
  2247. TRIANGLE_FAN: {
  2248. name: 'TRIANGLE_FAN',
  2249. class: 'p5',
  2250. module: 'Constants'
  2251. },
  2252. TRIANGLE_STRIP: {
  2253. name: 'TRIANGLE_STRIP',
  2254. class: 'p5',
  2255. module: 'Constants'
  2256. },
  2257. QUADS: {
  2258. name: 'QUADS',
  2259. class: 'p5',
  2260. module: 'Constants'
  2261. },
  2262. QUAD_STRIP: {
  2263. name: 'QUAD_STRIP',
  2264. class: 'p5',
  2265. module: 'Constants'
  2266. },
  2267. TESS: {
  2268. name: 'TESS',
  2269. class: 'p5',
  2270. module: 'Constants'
  2271. },
  2272. CLOSE: {
  2273. name: 'CLOSE',
  2274. class: 'p5',
  2275. module: 'Constants'
  2276. },
  2277. OPEN: {
  2278. name: 'OPEN',
  2279. class: 'p5',
  2280. module: 'Constants'
  2281. },
  2282. CHORD: {
  2283. name: 'CHORD',
  2284. class: 'p5',
  2285. module: 'Constants'
  2286. },
  2287. PIE: {
  2288. name: 'PIE',
  2289. class: 'p5',
  2290. module: 'Constants'
  2291. },
  2292. PROJECT: {
  2293. name: 'PROJECT',
  2294. class: 'p5',
  2295. module: 'Constants'
  2296. },
  2297. SQUARE: {
  2298. name: 'SQUARE',
  2299. class: 'p5',
  2300. module: 'Constants'
  2301. },
  2302. ROUND: {
  2303. name: 'ROUND',
  2304. class: 'p5',
  2305. module: 'Constants'
  2306. },
  2307. BEVEL: {
  2308. name: 'BEVEL',
  2309. class: 'p5',
  2310. module: 'Constants'
  2311. },
  2312. MITER: {
  2313. name: 'MITER',
  2314. class: 'p5',
  2315. module: 'Constants'
  2316. },
  2317. RGB: {
  2318. name: 'RGB',
  2319. class: 'p5',
  2320. module: 'Constants'
  2321. },
  2322. HSB: {
  2323. name: 'HSB',
  2324. class: 'p5',
  2325. module: 'Constants'
  2326. },
  2327. HSL: {
  2328. name: 'HSL',
  2329. class: 'p5',
  2330. module: 'Constants'
  2331. },
  2332. AUTO: {
  2333. name: 'AUTO',
  2334. class: 'p5',
  2335. module: 'Constants'
  2336. },
  2337. ALT: {
  2338. name: 'ALT',
  2339. class: 'p5',
  2340. module: 'Constants'
  2341. },
  2342. BACKSPACE: {
  2343. name: 'BACKSPACE',
  2344. class: 'p5',
  2345. module: 'Constants'
  2346. },
  2347. CONTROL: {
  2348. name: 'CONTROL',
  2349. class: 'p5',
  2350. module: 'Constants'
  2351. },
  2352. DELETE: {
  2353. name: 'DELETE',
  2354. class: 'p5',
  2355. module: 'Constants'
  2356. },
  2357. DOWN_ARROW: {
  2358. name: 'DOWN_ARROW',
  2359. class: 'p5',
  2360. module: 'Constants'
  2361. },
  2362. ENTER: {
  2363. name: 'ENTER',
  2364. class: 'p5',
  2365. module: 'Constants'
  2366. },
  2367. ESCAPE: {
  2368. name: 'ESCAPE',
  2369. class: 'p5',
  2370. module: 'Constants'
  2371. },
  2372. LEFT_ARROW: {
  2373. name: 'LEFT_ARROW',
  2374. class: 'p5',
  2375. module: 'Constants'
  2376. },
  2377. OPTION: {
  2378. name: 'OPTION',
  2379. class: 'p5',
  2380. module: 'Constants'
  2381. },
  2382. RETURN: {
  2383. name: 'RETURN',
  2384. class: 'p5',
  2385. module: 'Constants'
  2386. },
  2387. RIGHT_ARROW: {
  2388. name: 'RIGHT_ARROW',
  2389. class: 'p5',
  2390. module: 'Constants'
  2391. },
  2392. SHIFT: {
  2393. name: 'SHIFT',
  2394. class: 'p5',
  2395. module: 'Constants'
  2396. },
  2397. TAB: {
  2398. name: 'TAB',
  2399. class: 'p5',
  2400. module: 'Constants'
  2401. },
  2402. UP_ARROW: {
  2403. name: 'UP_ARROW',
  2404. class: 'p5',
  2405. module: 'Constants'
  2406. },
  2407. BLEND: {
  2408. name: 'BLEND',
  2409. class: 'p5',
  2410. module: 'Constants'
  2411. },
  2412. REMOVE: {
  2413. name: 'REMOVE',
  2414. class: 'p5',
  2415. module: 'Constants'
  2416. },
  2417. ADD: {
  2418. name: 'ADD',
  2419. class: 'p5',
  2420. module: 'Constants'
  2421. },
  2422. DARKEST: {
  2423. name: 'DARKEST',
  2424. class: 'p5',
  2425. module: 'Constants'
  2426. },
  2427. LIGHTEST: {
  2428. name: 'LIGHTEST',
  2429. class: 'p5',
  2430. module: 'Constants'
  2431. },
  2432. DIFFERENCE: {
  2433. name: 'DIFFERENCE',
  2434. class: 'p5',
  2435. module: 'Constants'
  2436. },
  2437. SUBTRACT: {
  2438. name: 'SUBTRACT',
  2439. class: 'p5',
  2440. module: 'Constants'
  2441. },
  2442. EXCLUSION: {
  2443. name: 'EXCLUSION',
  2444. class: 'p5',
  2445. module: 'Constants'
  2446. },
  2447. MULTIPLY: {
  2448. name: 'MULTIPLY',
  2449. class: 'p5',
  2450. module: 'Constants'
  2451. },
  2452. SCREEN: {
  2453. name: 'SCREEN',
  2454. class: 'p5',
  2455. module: 'Constants'
  2456. },
  2457. REPLACE: {
  2458. name: 'REPLACE',
  2459. class: 'p5',
  2460. module: 'Constants'
  2461. },
  2462. OVERLAY: {
  2463. name: 'OVERLAY',
  2464. class: 'p5',
  2465. module: 'Constants'
  2466. },
  2467. HARD_LIGHT: {
  2468. name: 'HARD_LIGHT',
  2469. class: 'p5',
  2470. module: 'Constants'
  2471. },
  2472. SOFT_LIGHT: {
  2473. name: 'SOFT_LIGHT',
  2474. class: 'p5',
  2475. module: 'Constants'
  2476. },
  2477. DODGE: {
  2478. name: 'DODGE',
  2479. class: 'p5',
  2480. module: 'Constants'
  2481. },
  2482. BURN: {
  2483. name: 'BURN',
  2484. class: 'p5',
  2485. module: 'Constants'
  2486. },
  2487. THRESHOLD: {
  2488. name: 'THRESHOLD',
  2489. class: 'p5',
  2490. module: 'Constants'
  2491. },
  2492. GRAY: {
  2493. name: 'GRAY',
  2494. class: 'p5',
  2495. module: 'Constants'
  2496. },
  2497. OPAQUE: {
  2498. name: 'OPAQUE',
  2499. class: 'p5',
  2500. module: 'Constants'
  2501. },
  2502. INVERT: {
  2503. name: 'INVERT',
  2504. class: 'p5',
  2505. module: 'Constants'
  2506. },
  2507. POSTERIZE: {
  2508. name: 'POSTERIZE',
  2509. class: 'p5',
  2510. module: 'Constants'
  2511. },
  2512. DILATE: {
  2513. name: 'DILATE',
  2514. class: 'p5',
  2515. module: 'Constants'
  2516. },
  2517. ERODE: {
  2518. name: 'ERODE',
  2519. class: 'p5',
  2520. module: 'Constants'
  2521. },
  2522. BLUR: {
  2523. name: 'BLUR',
  2524. class: 'p5',
  2525. module: 'Constants'
  2526. },
  2527. NORMAL: {
  2528. name: 'NORMAL',
  2529. class: 'p5',
  2530. module: 'Constants'
  2531. },
  2532. ITALIC: {
  2533. name: 'ITALIC',
  2534. class: 'p5',
  2535. module: 'Constants'
  2536. },
  2537. BOLD: {
  2538. name: 'BOLD',
  2539. class: 'p5',
  2540. module: 'Constants'
  2541. },
  2542. BOLDITALIC: {
  2543. name: 'BOLDITALIC',
  2544. class: 'p5',
  2545. module: 'Constants'
  2546. },
  2547. CHAR: {
  2548. name: 'CHAR',
  2549. class: 'p5',
  2550. module: 'Constants'
  2551. },
  2552. WORD: {
  2553. name: 'WORD',
  2554. class: 'p5',
  2555. module: 'Constants'
  2556. },
  2557. LINEAR: {
  2558. name: 'LINEAR',
  2559. class: 'p5',
  2560. module: 'Constants'
  2561. },
  2562. QUADRATIC: {
  2563. name: 'QUADRATIC',
  2564. class: 'p5',
  2565. module: 'Constants'
  2566. },
  2567. BEZIER: {
  2568. name: 'BEZIER',
  2569. class: 'p5',
  2570. module: 'Constants'
  2571. },
  2572. CURVE: {
  2573. name: 'CURVE',
  2574. class: 'p5',
  2575. module: 'Constants'
  2576. },
  2577. STROKE: {
  2578. name: 'STROKE',
  2579. class: 'p5',
  2580. module: 'Constants'
  2581. },
  2582. FILL: {
  2583. name: 'FILL',
  2584. class: 'p5',
  2585. module: 'Constants'
  2586. },
  2587. TEXTURE: {
  2588. name: 'TEXTURE',
  2589. class: 'p5',
  2590. module: 'Constants'
  2591. },
  2592. IMMEDIATE: {
  2593. name: 'IMMEDIATE',
  2594. class: 'p5',
  2595. module: 'Constants'
  2596. },
  2597. IMAGE: {
  2598. name: 'IMAGE',
  2599. class: 'p5',
  2600. module: 'Constants'
  2601. },
  2602. NEAREST: {
  2603. name: 'NEAREST',
  2604. class: 'p5',
  2605. module: 'Constants'
  2606. },
  2607. REPEAT: {
  2608. name: 'REPEAT',
  2609. class: 'p5',
  2610. module: 'Constants'
  2611. },
  2612. CLAMP: {
  2613. name: 'CLAMP',
  2614. class: 'p5',
  2615. module: 'Constants'
  2616. },
  2617. MIRROR: {
  2618. name: 'MIRROR',
  2619. class: 'p5',
  2620. module: 'Constants'
  2621. },
  2622. LANDSCAPE: {
  2623. name: 'LANDSCAPE',
  2624. class: 'p5',
  2625. module: 'Constants'
  2626. },
  2627. PORTRAIT: {
  2628. name: 'PORTRAIT',
  2629. class: 'p5',
  2630. module: 'Constants'
  2631. },
  2632. GRID: {
  2633. name: 'GRID',
  2634. class: 'p5',
  2635. module: 'Constants'
  2636. },
  2637. AXES: {
  2638. name: 'AXES',
  2639. class: 'p5',
  2640. module: 'Constants'
  2641. },
  2642. LABEL: {
  2643. name: 'LABEL',
  2644. class: 'p5',
  2645. module: 'Constants'
  2646. },
  2647. FALLBACK: {
  2648. name: 'FALLBACK',
  2649. class: 'p5',
  2650. module: 'Constants'
  2651. },
  2652. print: {
  2653. name: 'print',
  2654. params: [
  2655. {
  2656. name: 'contents',
  2657. description:
  2658. '<p>any combination of Number, String, Object, Boolean,\n Array to print</p>\n',
  2659. type: 'Any'
  2660. }
  2661. ],
  2662. class: 'p5',
  2663. module: 'Environment'
  2664. },
  2665. frameCount: {
  2666. name: 'frameCount',
  2667. class: 'p5',
  2668. module: 'Environment'
  2669. },
  2670. deltaTime: {
  2671. name: 'deltaTime',
  2672. class: 'p5',
  2673. module: 'Environment'
  2674. },
  2675. focused: {
  2676. name: 'focused',
  2677. class: 'p5',
  2678. module: 'Environment'
  2679. },
  2680. cursor: {
  2681. name: 'cursor',
  2682. params: [
  2683. {
  2684. name: 'type',
  2685. description:
  2686. "<p>Built-In: either ARROW, CROSS, HAND, MOVE, TEXT and WAIT\n Native CSS properties: 'grab', 'progress', 'cell' etc.\n External: path for cursor's images\n (Allowed File extensions: .cur, .gif, .jpg, .jpeg, .png)\n For more information on Native CSS cursors and url visit:\n <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/cursor\">https://developer.mozilla.org/en-US/docs/Web/CSS/cursor</a></p>\n",
  2687. type: 'String|Constant'
  2688. },
  2689. {
  2690. name: 'x',
  2691. description:
  2692. '<p>the horizontal active spot of the cursor (must be less than 32)</p>\n',
  2693. type: 'Number',
  2694. optional: true
  2695. },
  2696. {
  2697. name: 'y',
  2698. description:
  2699. '<p>the vertical active spot of the cursor (must be less than 32)</p>\n',
  2700. type: 'Number',
  2701. optional: true
  2702. }
  2703. ],
  2704. class: 'p5',
  2705. module: 'Environment'
  2706. },
  2707. frameRate: {
  2708. name: 'frameRate',
  2709. class: 'p5',
  2710. module: 'Environment',
  2711. overloads: [
  2712. {
  2713. params: [
  2714. {
  2715. name: 'fps',
  2716. description:
  2717. '<p>number of frames to be displayed every second</p>\n',
  2718. type: 'Number'
  2719. }
  2720. ],
  2721. chainable: 1
  2722. },
  2723. {
  2724. params: []
  2725. }
  2726. ]
  2727. },
  2728. noCursor: {
  2729. name: 'noCursor',
  2730. class: 'p5',
  2731. module: 'Environment'
  2732. },
  2733. displayWidth: {
  2734. name: 'displayWidth',
  2735. class: 'p5',
  2736. module: 'Environment'
  2737. },
  2738. displayHeight: {
  2739. name: 'displayHeight',
  2740. class: 'p5',
  2741. module: 'Environment'
  2742. },
  2743. windowWidth: {
  2744. name: 'windowWidth',
  2745. class: 'p5',
  2746. module: 'Environment'
  2747. },
  2748. windowHeight: {
  2749. name: 'windowHeight',
  2750. class: 'p5',
  2751. module: 'Environment'
  2752. },
  2753. windowResized: {
  2754. name: 'windowResized',
  2755. params: [
  2756. {
  2757. name: 'event',
  2758. description: '<p>optional Event callback argument.</p>\n',
  2759. type: 'Object',
  2760. optional: true
  2761. }
  2762. ],
  2763. class: 'p5',
  2764. module: 'Environment'
  2765. },
  2766. width: {
  2767. name: 'width',
  2768. class: 'p5',
  2769. module: 'Environment'
  2770. },
  2771. height: {
  2772. name: 'height',
  2773. class: 'p5',
  2774. module: 'Environment'
  2775. },
  2776. fullscreen: {
  2777. name: 'fullscreen',
  2778. params: [
  2779. {
  2780. name: 'val',
  2781. description:
  2782. '<p>whether the sketch should be in fullscreen mode\nor not</p>\n',
  2783. type: 'Boolean',
  2784. optional: true
  2785. }
  2786. ],
  2787. class: 'p5',
  2788. module: 'Environment'
  2789. },
  2790. pixelDensity: {
  2791. name: 'pixelDensity',
  2792. class: 'p5',
  2793. module: 'Environment',
  2794. overloads: [
  2795. {
  2796. params: [
  2797. {
  2798. name: 'val',
  2799. description: '<p>whether or how much the sketch should scale</p>\n',
  2800. type: 'Number'
  2801. }
  2802. ],
  2803. chainable: 1
  2804. },
  2805. {
  2806. params: []
  2807. }
  2808. ]
  2809. },
  2810. displayDensity: {
  2811. name: 'displayDensity',
  2812. class: 'p5',
  2813. module: 'Environment'
  2814. },
  2815. getURL: {
  2816. name: 'getURL',
  2817. class: 'p5',
  2818. module: 'Environment'
  2819. },
  2820. getURLPath: {
  2821. name: 'getURLPath',
  2822. class: 'p5',
  2823. module: 'Environment'
  2824. },
  2825. getURLParams: {
  2826. name: 'getURLParams',
  2827. class: 'p5',
  2828. module: 'Environment'
  2829. },
  2830. preload: {
  2831. name: 'preload',
  2832. class: 'p5',
  2833. module: 'Structure'
  2834. },
  2835. setup: {
  2836. name: 'setup',
  2837. class: 'p5',
  2838. module: 'Structure'
  2839. },
  2840. draw: {
  2841. name: 'draw',
  2842. class: 'p5',
  2843. module: 'Structure'
  2844. },
  2845. remove: {
  2846. name: 'remove',
  2847. class: 'p5',
  2848. module: 'Structure'
  2849. },
  2850. disableFriendlyErrors: {
  2851. name: 'disableFriendlyErrors',
  2852. class: 'p5',
  2853. module: 'Structure'
  2854. },
  2855. let: {
  2856. name: 'let',
  2857. class: 'p5',
  2858. module: 'Foundation'
  2859. },
  2860. const: {
  2861. name: 'const',
  2862. class: 'p5',
  2863. module: 'Foundation'
  2864. },
  2865. '===': {
  2866. name: '===',
  2867. class: 'p5',
  2868. module: 'Foundation'
  2869. },
  2870. '>': {
  2871. name: '>',
  2872. class: 'p5',
  2873. module: 'Foundation'
  2874. },
  2875. '>=': {
  2876. name: '>=',
  2877. class: 'p5',
  2878. module: 'Foundation'
  2879. },
  2880. '<': {
  2881. name: '<',
  2882. class: 'p5',
  2883. module: 'Foundation'
  2884. },
  2885. '<=': {
  2886. name: '<=',
  2887. class: 'p5',
  2888. module: 'Foundation'
  2889. },
  2890. 'if-else': {
  2891. name: 'if-else',
  2892. class: 'p5',
  2893. module: 'Foundation'
  2894. },
  2895. function: {
  2896. name: 'function',
  2897. class: 'p5',
  2898. module: 'Foundation'
  2899. },
  2900. return: {
  2901. name: 'return',
  2902. class: 'p5',
  2903. module: 'Foundation'
  2904. },
  2905. boolean: {
  2906. name: 'boolean',
  2907. params: [
  2908. {
  2909. name: 'n',
  2910. description: '<p>value to parse</p>\n',
  2911. type: 'String|Boolean|Number|Array'
  2912. }
  2913. ],
  2914. class: 'p5',
  2915. module: 'Data'
  2916. },
  2917. string: {
  2918. name: 'string',
  2919. class: 'p5',
  2920. module: 'Foundation'
  2921. },
  2922. number: {
  2923. name: 'number',
  2924. class: 'p5',
  2925. module: 'Foundation'
  2926. },
  2927. object: {
  2928. name: 'object',
  2929. class: 'p5',
  2930. module: 'Foundation'
  2931. },
  2932. class: {
  2933. name: 'class',
  2934. class: 'p5',
  2935. module: 'Foundation'
  2936. },
  2937. for: {
  2938. name: 'for',
  2939. class: 'p5',
  2940. module: 'Foundation'
  2941. },
  2942. while: {
  2943. name: 'while',
  2944. class: 'p5',
  2945. module: 'Foundation'
  2946. },
  2947. createCanvas: {
  2948. name: 'createCanvas',
  2949. params: [
  2950. {
  2951. name: 'w',
  2952. description: '<p>width of the canvas</p>\n',
  2953. type: 'Number'
  2954. },
  2955. {
  2956. name: 'h',
  2957. description: '<p>height of the canvas</p>\n',
  2958. type: 'Number'
  2959. },
  2960. {
  2961. name: 'renderer',
  2962. description: '<p>either P2D or WEBGL</p>\n',
  2963. type: 'Constant',
  2964. optional: true
  2965. }
  2966. ],
  2967. class: 'p5',
  2968. module: 'Rendering'
  2969. },
  2970. resizeCanvas: {
  2971. name: 'resizeCanvas',
  2972. params: [
  2973. {
  2974. name: 'w',
  2975. description: '<p>width of the canvas</p>\n',
  2976. type: 'Number'
  2977. },
  2978. {
  2979. name: 'h',
  2980. description: '<p>height of the canvas</p>\n',
  2981. type: 'Number'
  2982. },
  2983. {
  2984. name: 'noRedraw',
  2985. description: "<p>don't redraw the canvas immediately</p>\n",
  2986. type: 'Boolean',
  2987. optional: true
  2988. }
  2989. ],
  2990. class: 'p5',
  2991. module: 'Rendering'
  2992. },
  2993. noCanvas: {
  2994. name: 'noCanvas',
  2995. class: 'p5',
  2996. module: 'Rendering'
  2997. },
  2998. createGraphics: {
  2999. name: 'createGraphics',
  3000. params: [
  3001. {
  3002. name: 'w',
  3003. description: '<p>width of the offscreen graphics buffer</p>\n',
  3004. type: 'Number'
  3005. },
  3006. {
  3007. name: 'h',
  3008. description: '<p>height of the offscreen graphics buffer</p>\n',
  3009. type: 'Number'
  3010. },
  3011. {
  3012. name: 'renderer',
  3013. description:
  3014. '<p>either P2D or WEBGL\n undefined defaults to p2d</p>\n',
  3015. type: 'Constant',
  3016. optional: true
  3017. }
  3018. ],
  3019. class: 'p5',
  3020. module: 'Rendering'
  3021. },
  3022. blendMode: {
  3023. name: 'blendMode',
  3024. params: [
  3025. {
  3026. name: 'mode',
  3027. description:
  3028. '<p>blend mode to set for canvas.\n either BLEND, DARKEST, LIGHTEST, DIFFERENCE, MULTIPLY,\n EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,\n SOFT_LIGHT, DODGE, BURN, ADD, REMOVE or SUBTRACT</p>\n',
  3029. type: 'Constant'
  3030. }
  3031. ],
  3032. class: 'p5',
  3033. module: 'Rendering'
  3034. },
  3035. drawingContext: {
  3036. name: 'drawingContext',
  3037. class: 'p5',
  3038. module: 'Rendering'
  3039. },
  3040. noLoop: {
  3041. name: 'noLoop',
  3042. class: 'p5',
  3043. module: 'Structure'
  3044. },
  3045. loop: {
  3046. name: 'loop',
  3047. class: 'p5',
  3048. module: 'Structure'
  3049. },
  3050. isLooping: {
  3051. name: 'isLooping',
  3052. class: 'p5',
  3053. module: 'Structure'
  3054. },
  3055. push: {
  3056. name: 'push',
  3057. class: 'p5',
  3058. module: 'Structure'
  3059. },
  3060. pop: {
  3061. name: 'pop',
  3062. class: 'p5',
  3063. module: 'Structure'
  3064. },
  3065. redraw: {
  3066. name: 'redraw',
  3067. params: [
  3068. {
  3069. name: 'n',
  3070. description: '<p>Redraw for n-times. The default value is 1.</p>\n',
  3071. type: 'Integer',
  3072. optional: true
  3073. }
  3074. ],
  3075. class: 'p5',
  3076. module: 'Structure'
  3077. },
  3078. p5: {
  3079. name: 'p5',
  3080. params: [
  3081. {
  3082. name: 'sketch',
  3083. description: '<p>a function containing a p5.js sketch</p>\n',
  3084. type: 'Object'
  3085. },
  3086. {
  3087. name: 'node',
  3088. description:
  3089. '<p>ID or pointer to HTML DOM node to contain sketch in</p>\n',
  3090. type: 'String|Object'
  3091. }
  3092. ],
  3093. class: 'p5',
  3094. module: 'Structure'
  3095. },
  3096. applyMatrix: {
  3097. name: 'applyMatrix',
  3098. params: [
  3099. {
  3100. name: 'a',
  3101. description:
  3102. '<p>numbers which define the 2x3 matrix to be multiplied, or an array of numbers</p>\n',
  3103. type: 'Number|Array'
  3104. },
  3105. {
  3106. name: 'b',
  3107. description:
  3108. '<p>numbers which define the 2x3 matrix to be multiplied</p>\n',
  3109. type: 'Number'
  3110. },
  3111. {
  3112. name: 'c',
  3113. description:
  3114. '<p>numbers which define the 2x3 matrix to be multiplied</p>\n',
  3115. type: 'Number'
  3116. },
  3117. {
  3118. name: 'd',
  3119. description:
  3120. '<p>numbers which define the 2x3 matrix to be multiplied</p>\n',
  3121. type: 'Number'
  3122. },
  3123. {
  3124. name: 'e',
  3125. description:
  3126. '<p>numbers which define the 2x3 matrix to be multiplied</p>\n',
  3127. type: 'Number'
  3128. },
  3129. {
  3130. name: 'f',
  3131. description:
  3132. '<p>numbers which define the 2x3 matrix to be multiplied</p>\n',
  3133. type: 'Number'
  3134. }
  3135. ],
  3136. class: 'p5',
  3137. module: 'Transform'
  3138. },
  3139. resetMatrix: {
  3140. name: 'resetMatrix',
  3141. class: 'p5',
  3142. module: 'Transform'
  3143. },
  3144. rotate: {
  3145. name: 'rotate',
  3146. params: [
  3147. {
  3148. name: 'angle',
  3149. description:
  3150. '<p>the angle of rotation, specified in radians\n or degrees, depending on current angleMode</p>\n',
  3151. type: 'Number'
  3152. },
  3153. {
  3154. name: 'axis',
  3155. description: '<p>(in 3d) the axis to rotate around</p>\n',
  3156. type: 'p5.Vector|Number[]',
  3157. optional: true
  3158. }
  3159. ],
  3160. class: 'p5',
  3161. module: 'Transform'
  3162. },
  3163. rotateX: {
  3164. name: 'rotateX',
  3165. params: [
  3166. {
  3167. name: 'angle',
  3168. description:
  3169. '<p>the angle of rotation, specified in radians\n or degrees, depending on current angleMode</p>\n',
  3170. type: 'Number'
  3171. }
  3172. ],
  3173. class: 'p5',
  3174. module: 'Transform'
  3175. },
  3176. rotateY: {
  3177. name: 'rotateY',
  3178. params: [
  3179. {
  3180. name: 'angle',
  3181. description:
  3182. '<p>the angle of rotation, specified in radians\n or degrees, depending on current angleMode</p>\n',
  3183. type: 'Number'
  3184. }
  3185. ],
  3186. class: 'p5',
  3187. module: 'Transform'
  3188. },
  3189. rotateZ: {
  3190. name: 'rotateZ',
  3191. params: [
  3192. {
  3193. name: 'angle',
  3194. description:
  3195. '<p>the angle of rotation, specified in radians\n or degrees, depending on current angleMode</p>\n',
  3196. type: 'Number'
  3197. }
  3198. ],
  3199. class: 'p5',
  3200. module: 'Transform'
  3201. },
  3202. scale: {
  3203. name: 'scale',
  3204. class: 'p5',
  3205. module: 'Transform',
  3206. overloads: [
  3207. {
  3208. params: [
  3209. {
  3210. name: 's',
  3211. description:
  3212. '<p>percent to scale the object, or percentage to\n scale the object in the x-axis if multiple arguments\n are given</p>\n',
  3213. type: 'Number|p5.Vector|Number[]'
  3214. },
  3215. {
  3216. name: 'y',
  3217. description: '<p>percent to scale the object in the y-axis</p>\n',
  3218. type: 'Number',
  3219. optional: true
  3220. },
  3221. {
  3222. name: 'z',
  3223. description:
  3224. '<p>percent to scale the object in the z-axis (webgl only)</p>\n',
  3225. type: 'Number',
  3226. optional: true
  3227. }
  3228. ],
  3229. chainable: 1
  3230. },
  3231. {
  3232. params: [
  3233. {
  3234. name: 'scales',
  3235. description: '<p>per-axis percents to scale the object</p>\n',
  3236. type: 'p5.Vector|Number[]'
  3237. }
  3238. ],
  3239. chainable: 1
  3240. }
  3241. ]
  3242. },
  3243. shearX: {
  3244. name: 'shearX',
  3245. params: [
  3246. {
  3247. name: 'angle',
  3248. description:
  3249. '<p>angle of shear specified in radians or degrees,\n depending on current angleMode</p>\n',
  3250. type: 'Number'
  3251. }
  3252. ],
  3253. class: 'p5',
  3254. module: 'Transform'
  3255. },
  3256. shearY: {
  3257. name: 'shearY',
  3258. params: [
  3259. {
  3260. name: 'angle',
  3261. description:
  3262. '<p>angle of shear specified in radians or degrees,\n depending on current angleMode</p>\n',
  3263. type: 'Number'
  3264. }
  3265. ],
  3266. class: 'p5',
  3267. module: 'Transform'
  3268. },
  3269. translate: {
  3270. name: 'translate',
  3271. class: 'p5',
  3272. module: 'Transform',
  3273. overloads: [
  3274. {
  3275. params: [
  3276. {
  3277. name: 'x',
  3278. description: '<p>left/right translation</p>\n',
  3279. type: 'Number'
  3280. },
  3281. {
  3282. name: 'y',
  3283. description: '<p>up/down translation</p>\n',
  3284. type: 'Number'
  3285. },
  3286. {
  3287. name: 'z',
  3288. description: '<p>forward/backward translation (webgl only)</p>\n',
  3289. type: 'Number',
  3290. optional: true
  3291. }
  3292. ],
  3293. chainable: 1
  3294. },
  3295. {
  3296. params: [
  3297. {
  3298. name: 'vector',
  3299. description: '<p>the vector to translate by</p>\n',
  3300. type: 'p5.Vector'
  3301. }
  3302. ],
  3303. chainable: 1
  3304. }
  3305. ]
  3306. },
  3307. storeItem: {
  3308. name: 'storeItem',
  3309. params: [
  3310. {
  3311. name: 'key',
  3312. description: '',
  3313. type: 'String'
  3314. },
  3315. {
  3316. name: 'value',
  3317. description: '',
  3318. type: 'String|Number|Object|Boolean|p5.Color|p5.Vector'
  3319. }
  3320. ],
  3321. class: 'p5',
  3322. module: 'Data'
  3323. },
  3324. getItem: {
  3325. name: 'getItem',
  3326. params: [
  3327. {
  3328. name: 'key',
  3329. description:
  3330. '<p>name that you wish to use to store in local storage</p>\n',
  3331. type: 'String'
  3332. }
  3333. ],
  3334. class: 'p5',
  3335. module: 'Data'
  3336. },
  3337. clearStorage: {
  3338. name: 'clearStorage',
  3339. class: 'p5',
  3340. module: 'Data'
  3341. },
  3342. removeItem: {
  3343. name: 'removeItem',
  3344. params: [
  3345. {
  3346. name: 'key',
  3347. description: '',
  3348. type: 'String'
  3349. }
  3350. ],
  3351. class: 'p5',
  3352. module: 'Data'
  3353. },
  3354. createStringDict: {
  3355. name: 'createStringDict',
  3356. class: 'p5',
  3357. module: 'Data',
  3358. overloads: [
  3359. {
  3360. params: [
  3361. {
  3362. name: 'key',
  3363. description: '',
  3364. type: 'String'
  3365. },
  3366. {
  3367. name: 'value',
  3368. description: '',
  3369. type: 'String'
  3370. }
  3371. ]
  3372. },
  3373. {
  3374. params: [
  3375. {
  3376. name: 'object',
  3377. description: '<p>object</p>\n',
  3378. type: 'Object'
  3379. }
  3380. ]
  3381. }
  3382. ]
  3383. },
  3384. createNumberDict: {
  3385. name: 'createNumberDict',
  3386. class: 'p5',
  3387. module: 'Data',
  3388. overloads: [
  3389. {
  3390. params: [
  3391. {
  3392. name: 'key',
  3393. description: '',
  3394. type: 'Number'
  3395. },
  3396. {
  3397. name: 'value',
  3398. description: '',
  3399. type: 'Number'
  3400. }
  3401. ]
  3402. },
  3403. {
  3404. params: [
  3405. {
  3406. name: 'object',
  3407. description: '<p>object</p>\n',
  3408. type: 'Object'
  3409. }
  3410. ]
  3411. }
  3412. ]
  3413. },
  3414. select: {
  3415. name: 'select',
  3416. params: [
  3417. {
  3418. name: 'selectors',
  3419. description: '<p>CSS selector string of element to search for</p>\n',
  3420. type: 'String'
  3421. },
  3422. {
  3423. name: 'container',
  3424. description:
  3425. '<p>CSS selector string, <a href="#/p5.Element">p5.Element</a>, or\n HTML element to search within</p>\n',
  3426. type: 'String|p5.Element|HTMLElement',
  3427. optional: true
  3428. }
  3429. ],
  3430. class: 'p5',
  3431. module: 'DOM'
  3432. },
  3433. selectAll: {
  3434. name: 'selectAll',
  3435. params: [
  3436. {
  3437. name: 'selectors',
  3438. description: '<p>CSS selector string of elements to search for</p>\n',
  3439. type: 'String'
  3440. },
  3441. {
  3442. name: 'container',
  3443. description:
  3444. '<p>CSS selector string, <a href="#/p5.Element">p5.Element</a>\n , or HTML element to search within</p>\n',
  3445. type: 'String|p5.Element|HTMLElement',
  3446. optional: true
  3447. }
  3448. ],
  3449. class: 'p5',
  3450. module: 'DOM'
  3451. },
  3452. removeElements: {
  3453. name: 'removeElements',
  3454. class: 'p5',
  3455. module: 'DOM'
  3456. },
  3457. changed: {
  3458. name: 'changed',
  3459. params: [
  3460. {
  3461. name: 'fxn',
  3462. description:
  3463. '<p>function to be fired when the value of\n an element changes.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  3464. type: 'Function|Boolean'
  3465. }
  3466. ],
  3467. class: 'p5',
  3468. module: 'DOM'
  3469. },
  3470. input: {
  3471. name: 'input',
  3472. params: [
  3473. {
  3474. name: 'fxn',
  3475. description:
  3476. '<p>function to be fired when any user input is\n detected within the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  3477. type: 'Function|Boolean'
  3478. }
  3479. ],
  3480. class: 'p5',
  3481. module: 'DOM'
  3482. },
  3483. createDiv: {
  3484. name: 'createDiv',
  3485. params: [
  3486. {
  3487. name: 'html',
  3488. description: '<p>inner HTML for element created</p>\n',
  3489. type: 'String',
  3490. optional: true
  3491. }
  3492. ],
  3493. class: 'p5',
  3494. module: 'DOM'
  3495. },
  3496. createP: {
  3497. name: 'createP',
  3498. params: [
  3499. {
  3500. name: 'html',
  3501. description: '<p>inner HTML for element created</p>\n',
  3502. type: 'String',
  3503. optional: true
  3504. }
  3505. ],
  3506. class: 'p5',
  3507. module: 'DOM'
  3508. },
  3509. createSpan: {
  3510. name: 'createSpan',
  3511. params: [
  3512. {
  3513. name: 'html',
  3514. description: '<p>inner HTML for element created</p>\n',
  3515. type: 'String',
  3516. optional: true
  3517. }
  3518. ],
  3519. class: 'p5',
  3520. module: 'DOM'
  3521. },
  3522. createImg: {
  3523. name: 'createImg',
  3524. class: 'p5',
  3525. module: 'DOM',
  3526. overloads: [
  3527. {
  3528. params: [
  3529. {
  3530. name: 'src',
  3531. description: '<p>src path or url for image</p>\n',
  3532. type: 'String'
  3533. },
  3534. {
  3535. name: 'alt',
  3536. description:
  3537. '<p><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Img#Attributes">alternate text</a> to be used if image does not load. You can use also an empty string (<code>""</code>) if that an image is not intended to be viewed.</p>\n',
  3538. type: 'String'
  3539. }
  3540. ]
  3541. },
  3542. {
  3543. params: [
  3544. {
  3545. name: 'src',
  3546. description: '',
  3547. type: 'String'
  3548. },
  3549. {
  3550. name: 'alt',
  3551. description: '',
  3552. type: 'String'
  3553. },
  3554. {
  3555. name: 'crossOrigin',
  3556. description:
  3557. '<p><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes">crossOrigin property</a> of the <code>img</code> element; use either \'anonymous\' or \'use-credentials\' to retrieve the image with cross-origin access (for later use with <code>canvas</code>. if an empty string(<code>""</code>) is passed, CORS is not used</p>\n',
  3558. type: 'String'
  3559. },
  3560. {
  3561. name: 'successCallback',
  3562. description:
  3563. '<p>callback to be called once image data is loaded with the <a href="#/p5.Element">p5.Element</a> as argument</p>\n',
  3564. type: 'Function',
  3565. optional: true
  3566. }
  3567. ]
  3568. }
  3569. ]
  3570. },
  3571. createA: {
  3572. name: 'createA',
  3573. params: [
  3574. {
  3575. name: 'href',
  3576. description: '<p>url of page to link to</p>\n',
  3577. type: 'String'
  3578. },
  3579. {
  3580. name: 'html',
  3581. description: '<p>inner html of link element to display</p>\n',
  3582. type: 'String'
  3583. },
  3584. {
  3585. name: 'target',
  3586. description:
  3587. '<p>target where new link should open,\n could be _blank, _self, _parent, _top.</p>\n',
  3588. type: 'String',
  3589. optional: true
  3590. }
  3591. ],
  3592. class: 'p5',
  3593. module: 'DOM'
  3594. },
  3595. createSlider: {
  3596. name: 'createSlider',
  3597. params: [
  3598. {
  3599. name: 'min',
  3600. description: '<p>minimum value of the slider</p>\n',
  3601. type: 'Number'
  3602. },
  3603. {
  3604. name: 'max',
  3605. description: '<p>maximum value of the slider</p>\n',
  3606. type: 'Number'
  3607. },
  3608. {
  3609. name: 'value',
  3610. description: '<p>default value of the slider</p>\n',
  3611. type: 'Number',
  3612. optional: true
  3613. },
  3614. {
  3615. name: 'step',
  3616. description:
  3617. '<p>step size for each tick of the slider (if step is set to 0, the slider will move continuously from the minimum to the maximum value)</p>\n',
  3618. type: 'Number',
  3619. optional: true
  3620. }
  3621. ],
  3622. class: 'p5',
  3623. module: 'DOM'
  3624. },
  3625. createButton: {
  3626. name: 'createButton',
  3627. params: [
  3628. {
  3629. name: 'label',
  3630. description: '<p>label displayed on the button</p>\n',
  3631. type: 'String'
  3632. },
  3633. {
  3634. name: 'value',
  3635. description: '<p>value of the button</p>\n',
  3636. type: 'String',
  3637. optional: true
  3638. }
  3639. ],
  3640. class: 'p5',
  3641. module: 'DOM'
  3642. },
  3643. createCheckbox: {
  3644. name: 'createCheckbox',
  3645. params: [
  3646. {
  3647. name: 'label',
  3648. description: '<p>label displayed after checkbox</p>\n',
  3649. type: 'String',
  3650. optional: true
  3651. },
  3652. {
  3653. name: 'value',
  3654. description:
  3655. '<p>value of the checkbox; checked is true, unchecked is false</p>\n',
  3656. type: 'Boolean',
  3657. optional: true
  3658. }
  3659. ],
  3660. class: 'p5',
  3661. module: 'DOM'
  3662. },
  3663. createSelect: {
  3664. name: 'createSelect',
  3665. class: 'p5',
  3666. module: 'DOM',
  3667. overloads: [
  3668. {
  3669. params: [
  3670. {
  3671. name: 'multiple',
  3672. description:
  3673. '<p>true if dropdown should support multiple selections</p>\n',
  3674. type: 'Boolean',
  3675. optional: true
  3676. }
  3677. ]
  3678. },
  3679. {
  3680. params: [
  3681. {
  3682. name: 'existing',
  3683. description: '<p>DOM select element</p>\n',
  3684. type: 'Object'
  3685. }
  3686. ]
  3687. }
  3688. ]
  3689. },
  3690. createRadio: {
  3691. name: 'createRadio',
  3692. class: 'p5',
  3693. module: 'DOM',
  3694. overloads: [
  3695. {
  3696. params: [
  3697. {
  3698. name: 'containerElement',
  3699. description:
  3700. '<p>An container HTML Element either a div\nor span inside which all existing radio inputs will be considered as options.</p>\n',
  3701. type: 'Object'
  3702. },
  3703. {
  3704. name: 'name',
  3705. description: '<p>A name parameter for each Input Element.</p>\n',
  3706. type: 'String',
  3707. optional: true
  3708. }
  3709. ]
  3710. },
  3711. {
  3712. params: [
  3713. {
  3714. name: 'name',
  3715. description: '',
  3716. type: 'String'
  3717. }
  3718. ]
  3719. },
  3720. {
  3721. params: []
  3722. }
  3723. ]
  3724. },
  3725. createColorPicker: {
  3726. name: 'createColorPicker',
  3727. params: [
  3728. {
  3729. name: 'value',
  3730. description: '<p>default color of element</p>\n',
  3731. type: 'String|p5.Color',
  3732. optional: true
  3733. }
  3734. ],
  3735. class: 'p5',
  3736. module: 'DOM'
  3737. },
  3738. createInput: {
  3739. name: 'createInput',
  3740. class: 'p5',
  3741. module: 'DOM',
  3742. overloads: [
  3743. {
  3744. params: [
  3745. {
  3746. name: 'value',
  3747. description: '<p>default value of the input box</p>\n',
  3748. type: 'String'
  3749. },
  3750. {
  3751. name: 'type',
  3752. description:
  3753. '<p>type of text, ie text, password etc. Defaults to text.\n Needs a value to be specified first.</p>\n',
  3754. type: 'String',
  3755. optional: true
  3756. }
  3757. ]
  3758. },
  3759. {
  3760. params: [
  3761. {
  3762. name: 'value',
  3763. description: '',
  3764. type: 'String',
  3765. optional: true
  3766. }
  3767. ]
  3768. }
  3769. ]
  3770. },
  3771. createFileInput: {
  3772. name: 'createFileInput',
  3773. params: [
  3774. {
  3775. name: 'callback',
  3776. description: '<p>callback function for when a file is loaded</p>\n',
  3777. type: 'Function'
  3778. },
  3779. {
  3780. name: 'multiple',
  3781. description:
  3782. '<p>optional, to allow multiple files to be selected</p>\n',
  3783. type: 'Boolean',
  3784. optional: true
  3785. }
  3786. ],
  3787. class: 'p5',
  3788. module: 'DOM'
  3789. },
  3790. createVideo: {
  3791. name: 'createVideo',
  3792. params: [
  3793. {
  3794. name: 'src',
  3795. description:
  3796. '<p>path to a video file, or array of paths for\n supporting different browsers</p>\n',
  3797. type: 'String|String[]'
  3798. },
  3799. {
  3800. name: 'callback',
  3801. description:
  3802. "<p>callback function to be called upon\n 'canplaythrough' event fire, that is, when the\n browser can play the media, and estimates that\n enough data has been loaded to play the media\n up to its end without having to stop for\n further buffering of content</p>\n",
  3803. type: 'Function',
  3804. optional: true
  3805. }
  3806. ],
  3807. class: 'p5',
  3808. module: 'DOM'
  3809. },
  3810. createAudio: {
  3811. name: 'createAudio',
  3812. params: [
  3813. {
  3814. name: 'src',
  3815. description:
  3816. '<p>path to an audio file, or array of paths\n for supporting different browsers</p>\n',
  3817. type: 'String|String[]',
  3818. optional: true
  3819. },
  3820. {
  3821. name: 'callback',
  3822. description:
  3823. "<p>callback function to be called upon\n 'canplaythrough' event fire, that is, when the\n browser can play the media, and estimates that\n enough data has been loaded to play the media\n up to its end without having to stop for\n further buffering of content</p>\n",
  3824. type: 'Function',
  3825. optional: true
  3826. }
  3827. ],
  3828. class: 'p5',
  3829. module: 'DOM'
  3830. },
  3831. VIDEO: {
  3832. name: 'VIDEO',
  3833. class: 'p5',
  3834. module: 'DOM'
  3835. },
  3836. AUDIO: {
  3837. name: 'AUDIO',
  3838. class: 'p5',
  3839. module: 'DOM'
  3840. },
  3841. createCapture: {
  3842. name: 'createCapture',
  3843. params: [
  3844. {
  3845. name: 'type',
  3846. description:
  3847. '<p>type of capture, either VIDEO or\n AUDIO if none specified, default both,\n or a Constraints object</p>\n',
  3848. type: 'String|Constant|Object'
  3849. },
  3850. {
  3851. name: 'callback',
  3852. description:
  3853. '<p>function to be called once\n stream has loaded</p>\n',
  3854. type: 'Function',
  3855. optional: true
  3856. }
  3857. ],
  3858. class: 'p5',
  3859. module: 'DOM'
  3860. },
  3861. createElement: {
  3862. name: 'createElement',
  3863. params: [
  3864. {
  3865. name: 'tag',
  3866. description: '<p>tag for the new element</p>\n',
  3867. type: 'String'
  3868. },
  3869. {
  3870. name: 'content',
  3871. description: '<p>html content to be inserted into the element</p>\n',
  3872. type: 'String',
  3873. optional: true
  3874. }
  3875. ],
  3876. class: 'p5',
  3877. module: 'DOM'
  3878. },
  3879. deviceOrientation: {
  3880. name: 'deviceOrientation',
  3881. class: 'p5',
  3882. module: 'Events'
  3883. },
  3884. accelerationX: {
  3885. name: 'accelerationX',
  3886. class: 'p5',
  3887. module: 'Events'
  3888. },
  3889. accelerationY: {
  3890. name: 'accelerationY',
  3891. class: 'p5',
  3892. module: 'Events'
  3893. },
  3894. accelerationZ: {
  3895. name: 'accelerationZ',
  3896. class: 'p5',
  3897. module: 'Events'
  3898. },
  3899. pAccelerationX: {
  3900. name: 'pAccelerationX',
  3901. class: 'p5',
  3902. module: 'Events'
  3903. },
  3904. pAccelerationY: {
  3905. name: 'pAccelerationY',
  3906. class: 'p5',
  3907. module: 'Events'
  3908. },
  3909. pAccelerationZ: {
  3910. name: 'pAccelerationZ',
  3911. class: 'p5',
  3912. module: 'Events'
  3913. },
  3914. rotationX: {
  3915. name: 'rotationX',
  3916. class: 'p5',
  3917. module: 'Events'
  3918. },
  3919. rotationY: {
  3920. name: 'rotationY',
  3921. class: 'p5',
  3922. module: 'Events'
  3923. },
  3924. rotationZ: {
  3925. name: 'rotationZ',
  3926. class: 'p5',
  3927. module: 'Events'
  3928. },
  3929. pRotationX: {
  3930. name: 'pRotationX',
  3931. class: 'p5',
  3932. module: 'Events'
  3933. },
  3934. pRotationY: {
  3935. name: 'pRotationY',
  3936. class: 'p5',
  3937. module: 'Events'
  3938. },
  3939. pRotationZ: {
  3940. name: 'pRotationZ',
  3941. class: 'p5',
  3942. module: 'Events'
  3943. },
  3944. turnAxis: {
  3945. name: 'turnAxis',
  3946. class: 'p5',
  3947. module: 'Events'
  3948. },
  3949. setMoveThreshold: {
  3950. name: 'setMoveThreshold',
  3951. params: [
  3952. {
  3953. name: 'value',
  3954. description: '<p>The threshold value</p>\n',
  3955. type: 'Number'
  3956. }
  3957. ],
  3958. class: 'p5',
  3959. module: 'Events'
  3960. },
  3961. setShakeThreshold: {
  3962. name: 'setShakeThreshold',
  3963. params: [
  3964. {
  3965. name: 'value',
  3966. description: '<p>The threshold value</p>\n',
  3967. type: 'Number'
  3968. }
  3969. ],
  3970. class: 'p5',
  3971. module: 'Events'
  3972. },
  3973. deviceMoved: {
  3974. name: 'deviceMoved',
  3975. class: 'p5',
  3976. module: 'Events'
  3977. },
  3978. deviceTurned: {
  3979. name: 'deviceTurned',
  3980. class: 'p5',
  3981. module: 'Events'
  3982. },
  3983. deviceShaken: {
  3984. name: 'deviceShaken',
  3985. class: 'p5',
  3986. module: 'Events'
  3987. },
  3988. keyIsPressed: {
  3989. name: 'keyIsPressed',
  3990. class: 'p5',
  3991. module: 'Events'
  3992. },
  3993. key: {
  3994. name: 'key',
  3995. class: 'p5',
  3996. module: 'Events'
  3997. },
  3998. keyCode: {
  3999. name: 'keyCode',
  4000. class: 'p5',
  4001. module: 'Events'
  4002. },
  4003. keyPressed: {
  4004. name: 'keyPressed',
  4005. params: [
  4006. {
  4007. name: 'event',
  4008. description: '<p>optional KeyboardEvent callback argument.</p>\n',
  4009. type: 'Object',
  4010. optional: true
  4011. }
  4012. ],
  4013. class: 'p5',
  4014. module: 'Events'
  4015. },
  4016. keyReleased: {
  4017. name: 'keyReleased',
  4018. params: [
  4019. {
  4020. name: 'event',
  4021. description: '<p>optional KeyboardEvent callback argument.</p>\n',
  4022. type: 'Object',
  4023. optional: true
  4024. }
  4025. ],
  4026. class: 'p5',
  4027. module: 'Events'
  4028. },
  4029. keyTyped: {
  4030. name: 'keyTyped',
  4031. params: [
  4032. {
  4033. name: 'event',
  4034. description: '<p>optional KeyboardEvent callback argument.</p>\n',
  4035. type: 'Object',
  4036. optional: true
  4037. }
  4038. ],
  4039. class: 'p5',
  4040. module: 'Events'
  4041. },
  4042. keyIsDown: {
  4043. name: 'keyIsDown',
  4044. params: [
  4045. {
  4046. name: 'code',
  4047. description: '<p>The key to check for.</p>\n',
  4048. type: 'Number'
  4049. }
  4050. ],
  4051. class: 'p5',
  4052. module: 'Events'
  4053. },
  4054. movedX: {
  4055. name: 'movedX',
  4056. class: 'p5',
  4057. module: 'Events'
  4058. },
  4059. movedY: {
  4060. name: 'movedY',
  4061. class: 'p5',
  4062. module: 'Events'
  4063. },
  4064. mouseX: {
  4065. name: 'mouseX',
  4066. class: 'p5',
  4067. module: 'Events'
  4068. },
  4069. mouseY: {
  4070. name: 'mouseY',
  4071. class: 'p5',
  4072. module: 'Events'
  4073. },
  4074. pmouseX: {
  4075. name: 'pmouseX',
  4076. class: 'p5',
  4077. module: 'Events'
  4078. },
  4079. pmouseY: {
  4080. name: 'pmouseY',
  4081. class: 'p5',
  4082. module: 'Events'
  4083. },
  4084. winMouseX: {
  4085. name: 'winMouseX',
  4086. class: 'p5',
  4087. module: 'Events'
  4088. },
  4089. winMouseY: {
  4090. name: 'winMouseY',
  4091. class: 'p5',
  4092. module: 'Events'
  4093. },
  4094. pwinMouseX: {
  4095. name: 'pwinMouseX',
  4096. class: 'p5',
  4097. module: 'Events'
  4098. },
  4099. pwinMouseY: {
  4100. name: 'pwinMouseY',
  4101. class: 'p5',
  4102. module: 'Events'
  4103. },
  4104. mouseButton: {
  4105. name: 'mouseButton',
  4106. class: 'p5',
  4107. module: 'Events'
  4108. },
  4109. mouseIsPressed: {
  4110. name: 'mouseIsPressed',
  4111. class: 'p5',
  4112. module: 'Events'
  4113. },
  4114. mouseMoved: {
  4115. name: 'mouseMoved',
  4116. params: [
  4117. {
  4118. name: 'event',
  4119. description: '<p>optional MouseEvent callback argument.</p>\n',
  4120. type: 'Object',
  4121. optional: true
  4122. }
  4123. ],
  4124. class: 'p5',
  4125. module: 'Events'
  4126. },
  4127. mouseDragged: {
  4128. name: 'mouseDragged',
  4129. params: [
  4130. {
  4131. name: 'event',
  4132. description: '<p>optional MouseEvent callback argument.</p>\n',
  4133. type: 'Object',
  4134. optional: true
  4135. }
  4136. ],
  4137. class: 'p5',
  4138. module: 'Events'
  4139. },
  4140. mousePressed: {
  4141. name: 'mousePressed',
  4142. params: [
  4143. {
  4144. name: 'event',
  4145. description: '<p>optional MouseEvent callback argument.</p>\n',
  4146. type: 'Object',
  4147. optional: true
  4148. }
  4149. ],
  4150. class: 'p5',
  4151. module: 'Events'
  4152. },
  4153. mouseReleased: {
  4154. name: 'mouseReleased',
  4155. params: [
  4156. {
  4157. name: 'event',
  4158. description: '<p>optional MouseEvent callback argument.</p>\n',
  4159. type: 'Object',
  4160. optional: true
  4161. }
  4162. ],
  4163. class: 'p5',
  4164. module: 'Events'
  4165. },
  4166. mouseClicked: {
  4167. name: 'mouseClicked',
  4168. params: [
  4169. {
  4170. name: 'event',
  4171. description: '<p>optional MouseEvent callback argument.</p>\n',
  4172. type: 'Object',
  4173. optional: true
  4174. }
  4175. ],
  4176. class: 'p5',
  4177. module: 'Events'
  4178. },
  4179. doubleClicked: {
  4180. name: 'doubleClicked',
  4181. params: [
  4182. {
  4183. name: 'event',
  4184. description: '<p>optional MouseEvent callback argument.</p>\n',
  4185. type: 'Object',
  4186. optional: true
  4187. }
  4188. ],
  4189. class: 'p5',
  4190. module: 'Events'
  4191. },
  4192. mouseWheel: {
  4193. name: 'mouseWheel',
  4194. params: [
  4195. {
  4196. name: 'event',
  4197. description: '<p>optional WheelEvent callback argument.</p>\n',
  4198. type: 'Object',
  4199. optional: true
  4200. }
  4201. ],
  4202. class: 'p5',
  4203. module: 'Events'
  4204. },
  4205. requestPointerLock: {
  4206. name: 'requestPointerLock',
  4207. class: 'p5',
  4208. module: 'Events'
  4209. },
  4210. exitPointerLock: {
  4211. name: 'exitPointerLock',
  4212. class: 'p5',
  4213. module: 'Events'
  4214. },
  4215. touches: {
  4216. name: 'touches',
  4217. class: 'p5',
  4218. module: 'Events'
  4219. },
  4220. touchStarted: {
  4221. name: 'touchStarted',
  4222. params: [
  4223. {
  4224. name: 'event',
  4225. description: '<p>optional TouchEvent callback argument.</p>\n',
  4226. type: 'Object',
  4227. optional: true
  4228. }
  4229. ],
  4230. class: 'p5',
  4231. module: 'Events'
  4232. },
  4233. touchMoved: {
  4234. name: 'touchMoved',
  4235. params: [
  4236. {
  4237. name: 'event',
  4238. description: '<p>optional TouchEvent callback argument.</p>\n',
  4239. type: 'Object',
  4240. optional: true
  4241. }
  4242. ],
  4243. class: 'p5',
  4244. module: 'Events'
  4245. },
  4246. touchEnded: {
  4247. name: 'touchEnded',
  4248. params: [
  4249. {
  4250. name: 'event',
  4251. description: '<p>optional TouchEvent callback argument.</p>\n',
  4252. type: 'Object',
  4253. optional: true
  4254. }
  4255. ],
  4256. class: 'p5',
  4257. module: 'Events'
  4258. },
  4259. createImage: {
  4260. name: 'createImage',
  4261. params: [
  4262. {
  4263. name: 'width',
  4264. description: '<p>width in pixels</p>\n',
  4265. type: 'Integer'
  4266. },
  4267. {
  4268. name: 'height',
  4269. description: '<p>height in pixels</p>\n',
  4270. type: 'Integer'
  4271. }
  4272. ],
  4273. class: 'p5',
  4274. module: 'Image'
  4275. },
  4276. saveCanvas: {
  4277. name: 'saveCanvas',
  4278. class: 'p5',
  4279. module: 'Image',
  4280. overloads: [
  4281. {
  4282. params: [
  4283. {
  4284. name: 'selectedCanvas',
  4285. description:
  4286. '<p>a variable\n representing a specific html5 canvas (optional)</p>\n',
  4287. type: 'p5.Element|HTMLCanvasElement'
  4288. },
  4289. {
  4290. name: 'filename',
  4291. description: '',
  4292. type: 'String',
  4293. optional: true
  4294. },
  4295. {
  4296. name: 'extension',
  4297. description: "<p>'jpg' or 'png'</p>\n",
  4298. type: 'String',
  4299. optional: true
  4300. }
  4301. ]
  4302. },
  4303. {
  4304. params: [
  4305. {
  4306. name: 'filename',
  4307. description: '',
  4308. type: 'String',
  4309. optional: true
  4310. },
  4311. {
  4312. name: 'extension',
  4313. description: '',
  4314. type: 'String',
  4315. optional: true
  4316. }
  4317. ]
  4318. }
  4319. ]
  4320. },
  4321. saveFrames: {
  4322. name: 'saveFrames',
  4323. params: [
  4324. {
  4325. name: 'filename',
  4326. description: '',
  4327. type: 'String'
  4328. },
  4329. {
  4330. name: 'extension',
  4331. description: "<p>'jpg' or 'png'</p>\n",
  4332. type: 'String'
  4333. },
  4334. {
  4335. name: 'duration',
  4336. description: '<p>Duration in seconds to save the frames for.</p>\n',
  4337. type: 'Number'
  4338. },
  4339. {
  4340. name: 'framerate',
  4341. description: '<p>Framerate to save the frames in.</p>\n',
  4342. type: 'Number'
  4343. },
  4344. {
  4345. name: 'callback',
  4346. description:
  4347. '<p>A callback function that will be executed\n to handle the image data. This function\n should accept an array as argument. The\n array will contain the specified number of\n frames of objects. Each object has three\n properties: imageData - an\n image/octet-stream, filename and extension.</p>\n',
  4348. type: 'Function(Array)',
  4349. optional: true
  4350. }
  4351. ],
  4352. class: 'p5',
  4353. module: 'Image'
  4354. },
  4355. loadImage: {
  4356. name: 'loadImage',
  4357. params: [
  4358. {
  4359. name: 'path',
  4360. description: '<p>Path of the image to be loaded</p>\n',
  4361. type: 'String'
  4362. },
  4363. {
  4364. name: 'successCallback',
  4365. description:
  4366. '<p>Function to be called once\n the image is loaded. Will be passed the\n <a href="#/p5.Image">p5.Image</a>.</p>\n',
  4367. type: 'function(p5.Image)',
  4368. optional: true
  4369. },
  4370. {
  4371. name: 'failureCallback',
  4372. description:
  4373. '<p>called with event error if\n the image fails to load.</p>\n',
  4374. type: 'Function(Event)',
  4375. optional: true
  4376. }
  4377. ],
  4378. class: 'p5',
  4379. module: 'Image'
  4380. },
  4381. image: {
  4382. name: 'image',
  4383. class: 'p5',
  4384. module: 'Image',
  4385. overloads: [
  4386. {
  4387. params: [
  4388. {
  4389. name: 'img',
  4390. description: '<p>the image to display</p>\n',
  4391. type: 'p5.Image|p5.Element'
  4392. },
  4393. {
  4394. name: 'x',
  4395. description:
  4396. '<p>the x-coordinate of the top-left corner of the image</p>\n',
  4397. type: 'Number'
  4398. },
  4399. {
  4400. name: 'y',
  4401. description:
  4402. '<p>the y-coordinate of the top-left corner of the image</p>\n',
  4403. type: 'Number'
  4404. },
  4405. {
  4406. name: 'width',
  4407. description: '<p>the width to draw the image</p>\n',
  4408. type: 'Number',
  4409. optional: true
  4410. },
  4411. {
  4412. name: 'height',
  4413. description: '<p>the height to draw the image</p>\n',
  4414. type: 'Number',
  4415. optional: true
  4416. }
  4417. ]
  4418. },
  4419. {
  4420. params: [
  4421. {
  4422. name: 'img',
  4423. description: '',
  4424. type: 'p5.Image|p5.Element'
  4425. },
  4426. {
  4427. name: 'dx',
  4428. description:
  4429. '<p>the x-coordinate of the destination\n rectangle in which to draw the source image</p>\n',
  4430. type: 'Number'
  4431. },
  4432. {
  4433. name: 'dy',
  4434. description:
  4435. '<p>the y-coordinate of the destination\n rectangle in which to draw the source image</p>\n',
  4436. type: 'Number'
  4437. },
  4438. {
  4439. name: 'dWidth',
  4440. description: '<p>the width of the destination rectangle</p>\n',
  4441. type: 'Number'
  4442. },
  4443. {
  4444. name: 'dHeight',
  4445. description: '<p>the height of the destination rectangle</p>\n',
  4446. type: 'Number'
  4447. },
  4448. {
  4449. name: 'sx',
  4450. description:
  4451. '<p>the x-coordinate of the subsection of the source\nimage to draw into the destination rectangle</p>\n',
  4452. type: 'Number'
  4453. },
  4454. {
  4455. name: 'sy',
  4456. description:
  4457. '<p>the y-coordinate of the subsection of the source\nimage to draw into the destination rectangle</p>\n',
  4458. type: 'Number'
  4459. },
  4460. {
  4461. name: 'sWidth',
  4462. description:
  4463. '<p>the width of the subsection of the\n source image to draw into the destination\n rectangle</p>\n',
  4464. type: 'Number',
  4465. optional: true
  4466. },
  4467. {
  4468. name: 'sHeight',
  4469. description:
  4470. '<p>the height of the subsection of the\n source image to draw into the destination rectangle</p>\n',
  4471. type: 'Number',
  4472. optional: true
  4473. }
  4474. ]
  4475. }
  4476. ]
  4477. },
  4478. tint: {
  4479. name: 'tint',
  4480. class: 'p5',
  4481. module: 'Image',
  4482. overloads: [
  4483. {
  4484. params: [
  4485. {
  4486. name: 'v1',
  4487. description:
  4488. '<p>red or hue value relative to\n the current color range</p>\n',
  4489. type: 'Number'
  4490. },
  4491. {
  4492. name: 'v2',
  4493. description:
  4494. '<p>green or saturation value\n relative to the current color range</p>\n',
  4495. type: 'Number'
  4496. },
  4497. {
  4498. name: 'v3',
  4499. description:
  4500. '<p>blue or brightness value\n relative to the current color range</p>\n',
  4501. type: 'Number'
  4502. },
  4503. {
  4504. name: 'alpha',
  4505. description: '',
  4506. type: 'Number',
  4507. optional: true
  4508. }
  4509. ]
  4510. },
  4511. {
  4512. params: [
  4513. {
  4514. name: 'value',
  4515. description: '<p>a color string</p>\n',
  4516. type: 'String'
  4517. }
  4518. ]
  4519. },
  4520. {
  4521. params: [
  4522. {
  4523. name: 'gray',
  4524. description: '<p>a gray value</p>\n',
  4525. type: 'Number'
  4526. },
  4527. {
  4528. name: 'alpha',
  4529. description: '',
  4530. type: 'Number',
  4531. optional: true
  4532. }
  4533. ]
  4534. },
  4535. {
  4536. params: [
  4537. {
  4538. name: 'values',
  4539. description:
  4540. '<p>an array containing the red,green,blue &\n and alpha components of the color</p>\n',
  4541. type: 'Number[]'
  4542. }
  4543. ]
  4544. },
  4545. {
  4546. params: [
  4547. {
  4548. name: 'color',
  4549. description: '<p>the tint color</p>\n',
  4550. type: 'p5.Color'
  4551. }
  4552. ]
  4553. }
  4554. ]
  4555. },
  4556. noTint: {
  4557. name: 'noTint',
  4558. class: 'p5',
  4559. module: 'Image'
  4560. },
  4561. imageMode: {
  4562. name: 'imageMode',
  4563. params: [
  4564. {
  4565. name: 'mode',
  4566. description: '<p>either CORNER, CORNERS, or CENTER</p>\n',
  4567. type: 'Constant'
  4568. }
  4569. ],
  4570. class: 'p5',
  4571. module: 'Image'
  4572. },
  4573. pixels: {
  4574. name: 'pixels',
  4575. class: 'p5',
  4576. module: 'Image'
  4577. },
  4578. blend: {
  4579. name: 'blend',
  4580. class: 'p5',
  4581. module: 'Image',
  4582. overloads: [
  4583. {
  4584. params: [
  4585. {
  4586. name: 'srcImage',
  4587. description: '<p>source image</p>\n',
  4588. type: 'p5.Image'
  4589. },
  4590. {
  4591. name: 'sx',
  4592. description:
  4593. "<p>X coordinate of the source's upper left corner</p>\n",
  4594. type: 'Integer'
  4595. },
  4596. {
  4597. name: 'sy',
  4598. description:
  4599. "<p>Y coordinate of the source's upper left corner</p>\n",
  4600. type: 'Integer'
  4601. },
  4602. {
  4603. name: 'sw',
  4604. description: '<p>source image width</p>\n',
  4605. type: 'Integer'
  4606. },
  4607. {
  4608. name: 'sh',
  4609. description: '<p>source image height</p>\n',
  4610. type: 'Integer'
  4611. },
  4612. {
  4613. name: 'dx',
  4614. description:
  4615. "<p>X coordinate of the destination's upper left corner</p>\n",
  4616. type: 'Integer'
  4617. },
  4618. {
  4619. name: 'dy',
  4620. description:
  4621. "<p>Y coordinate of the destination's upper left corner</p>\n",
  4622. type: 'Integer'
  4623. },
  4624. {
  4625. name: 'dw',
  4626. description: '<p>destination image width</p>\n',
  4627. type: 'Integer'
  4628. },
  4629. {
  4630. name: 'dh',
  4631. description: '<p>destination image height</p>\n',
  4632. type: 'Integer'
  4633. },
  4634. {
  4635. name: 'blendMode',
  4636. description:
  4637. '<p>the blend mode. either\n BLEND, DARKEST, LIGHTEST, DIFFERENCE,\n MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,\n SOFT_LIGHT, DODGE, BURN, ADD or NORMAL.</p>\n',
  4638. type: 'Constant'
  4639. }
  4640. ]
  4641. },
  4642. {
  4643. params: [
  4644. {
  4645. name: 'sx',
  4646. description: '',
  4647. type: 'Integer'
  4648. },
  4649. {
  4650. name: 'sy',
  4651. description: '',
  4652. type: 'Integer'
  4653. },
  4654. {
  4655. name: 'sw',
  4656. description: '',
  4657. type: 'Integer'
  4658. },
  4659. {
  4660. name: 'sh',
  4661. description: '',
  4662. type: 'Integer'
  4663. },
  4664. {
  4665. name: 'dx',
  4666. description: '',
  4667. type: 'Integer'
  4668. },
  4669. {
  4670. name: 'dy',
  4671. description: '',
  4672. type: 'Integer'
  4673. },
  4674. {
  4675. name: 'dw',
  4676. description: '',
  4677. type: 'Integer'
  4678. },
  4679. {
  4680. name: 'dh',
  4681. description: '',
  4682. type: 'Integer'
  4683. },
  4684. {
  4685. name: 'blendMode',
  4686. description: '',
  4687. type: 'Constant'
  4688. }
  4689. ]
  4690. }
  4691. ]
  4692. },
  4693. copy: {
  4694. name: 'copy',
  4695. class: 'p5',
  4696. module: 'Image',
  4697. overloads: [
  4698. {
  4699. params: [
  4700. {
  4701. name: 'srcImage',
  4702. description: '<p>source image</p>\n',
  4703. type: 'p5.Image|p5.Element'
  4704. },
  4705. {
  4706. name: 'sx',
  4707. description:
  4708. "<p>X coordinate of the source's upper left corner</p>\n",
  4709. type: 'Integer'
  4710. },
  4711. {
  4712. name: 'sy',
  4713. description:
  4714. "<p>Y coordinate of the source's upper left corner</p>\n",
  4715. type: 'Integer'
  4716. },
  4717. {
  4718. name: 'sw',
  4719. description: '<p>source image width</p>\n',
  4720. type: 'Integer'
  4721. },
  4722. {
  4723. name: 'sh',
  4724. description: '<p>source image height</p>\n',
  4725. type: 'Integer'
  4726. },
  4727. {
  4728. name: 'dx',
  4729. description:
  4730. "<p>X coordinate of the destination's upper left corner</p>\n",
  4731. type: 'Integer'
  4732. },
  4733. {
  4734. name: 'dy',
  4735. description:
  4736. "<p>Y coordinate of the destination's upper left corner</p>\n",
  4737. type: 'Integer'
  4738. },
  4739. {
  4740. name: 'dw',
  4741. description: '<p>destination image width</p>\n',
  4742. type: 'Integer'
  4743. },
  4744. {
  4745. name: 'dh',
  4746. description: '<p>destination image height</p>\n',
  4747. type: 'Integer'
  4748. }
  4749. ]
  4750. },
  4751. {
  4752. params: [
  4753. {
  4754. name: 'sx',
  4755. description: '',
  4756. type: 'Integer'
  4757. },
  4758. {
  4759. name: 'sy',
  4760. description: '',
  4761. type: 'Integer'
  4762. },
  4763. {
  4764. name: 'sw',
  4765. description: '',
  4766. type: 'Integer'
  4767. },
  4768. {
  4769. name: 'sh',
  4770. description: '',
  4771. type: 'Integer'
  4772. },
  4773. {
  4774. name: 'dx',
  4775. description: '',
  4776. type: 'Integer'
  4777. },
  4778. {
  4779. name: 'dy',
  4780. description: '',
  4781. type: 'Integer'
  4782. },
  4783. {
  4784. name: 'dw',
  4785. description: '',
  4786. type: 'Integer'
  4787. },
  4788. {
  4789. name: 'dh',
  4790. description: '',
  4791. type: 'Integer'
  4792. }
  4793. ]
  4794. }
  4795. ]
  4796. },
  4797. filter: {
  4798. name: 'filter',
  4799. params: [
  4800. {
  4801. name: 'filterType',
  4802. description:
  4803. '<p>either THRESHOLD, GRAY, OPAQUE, INVERT,\n POSTERIZE, BLUR, ERODE, DILATE or BLUR.\n See Filters.js for docs on\n each available filter</p>\n',
  4804. type: 'Constant'
  4805. },
  4806. {
  4807. name: 'filterParam',
  4808. description:
  4809. '<p>an optional parameter unique\n to each filter, see above</p>\n',
  4810. type: 'Number',
  4811. optional: true
  4812. }
  4813. ],
  4814. class: 'p5',
  4815. module: 'Image'
  4816. },
  4817. get: {
  4818. name: 'get',
  4819. class: 'p5',
  4820. module: 'Image',
  4821. overloads: [
  4822. {
  4823. params: [
  4824. {
  4825. name: 'x',
  4826. description: '<p>x-coordinate of the pixel</p>\n',
  4827. type: 'Number'
  4828. },
  4829. {
  4830. name: 'y',
  4831. description: '<p>y-coordinate of the pixel</p>\n',
  4832. type: 'Number'
  4833. },
  4834. {
  4835. name: 'w',
  4836. description: '<p>width</p>\n',
  4837. type: 'Number'
  4838. },
  4839. {
  4840. name: 'h',
  4841. description: '<p>height</p>\n',
  4842. type: 'Number'
  4843. }
  4844. ]
  4845. },
  4846. {
  4847. params: []
  4848. },
  4849. {
  4850. params: [
  4851. {
  4852. name: 'x',
  4853. description: '',
  4854. type: 'Number'
  4855. },
  4856. {
  4857. name: 'y',
  4858. description: '',
  4859. type: 'Number'
  4860. }
  4861. ]
  4862. }
  4863. ]
  4864. },
  4865. loadPixels: {
  4866. name: 'loadPixels',
  4867. class: 'p5',
  4868. module: 'Image'
  4869. },
  4870. set: {
  4871. name: 'set',
  4872. params: [
  4873. {
  4874. name: 'x',
  4875. description: '<p>x-coordinate of the pixel</p>\n',
  4876. type: 'Number'
  4877. },
  4878. {
  4879. name: 'y',
  4880. description: '<p>y-coordinate of the pixel</p>\n',
  4881. type: 'Number'
  4882. },
  4883. {
  4884. name: 'c',
  4885. description:
  4886. '<p>insert a grayscale value | a pixel array |\n a <a href="#/p5.Color">p5.Color</a> object | a <a href="#/p5.Image">p5.Image</a> to copy</p>\n',
  4887. type: 'Number|Number[]|Object'
  4888. }
  4889. ],
  4890. class: 'p5',
  4891. module: 'Image'
  4892. },
  4893. updatePixels: {
  4894. name: 'updatePixels',
  4895. params: [
  4896. {
  4897. name: 'x',
  4898. description:
  4899. '<p>x-coordinate of the upper-left corner of region\n to update</p>\n',
  4900. type: 'Number',
  4901. optional: true
  4902. },
  4903. {
  4904. name: 'y',
  4905. description:
  4906. '<p>y-coordinate of the upper-left corner of region\n to update</p>\n',
  4907. type: 'Number',
  4908. optional: true
  4909. },
  4910. {
  4911. name: 'w',
  4912. description: '<p>width of region to update</p>\n',
  4913. type: 'Number',
  4914. optional: true
  4915. },
  4916. {
  4917. name: 'h',
  4918. description: '<p>height of region to update</p>\n',
  4919. type: 'Number',
  4920. optional: true
  4921. }
  4922. ],
  4923. class: 'p5',
  4924. module: 'Image'
  4925. },
  4926. loadJSON: {
  4927. name: 'loadJSON',
  4928. class: 'p5',
  4929. module: 'IO',
  4930. overloads: [
  4931. {
  4932. params: [
  4933. {
  4934. name: 'path',
  4935. description: '<p>name of the file or url to load</p>\n',
  4936. type: 'String'
  4937. },
  4938. {
  4939. name: 'jsonpOptions',
  4940. description: '<p>options object for jsonp related settings</p>\n',
  4941. type: 'Object',
  4942. optional: true
  4943. },
  4944. {
  4945. name: 'datatype',
  4946. description: '<p>"json" or "jsonp"</p>\n',
  4947. type: 'String',
  4948. optional: true
  4949. },
  4950. {
  4951. name: 'callback',
  4952. description:
  4953. '<p>function to be executed after\n <a href="#/p5/loadJSON">loadJSON()</a> completes, data is passed\n in as first argument</p>\n',
  4954. type: 'Function',
  4955. optional: true
  4956. },
  4957. {
  4958. name: 'errorCallback',
  4959. description:
  4960. '<p>function to be executed if\n there is an error, response is passed\n in as first argument</p>\n',
  4961. type: 'Function',
  4962. optional: true
  4963. }
  4964. ]
  4965. },
  4966. {
  4967. params: [
  4968. {
  4969. name: 'path',
  4970. description: '',
  4971. type: 'String'
  4972. },
  4973. {
  4974. name: 'datatype',
  4975. description: '',
  4976. type: 'String'
  4977. },
  4978. {
  4979. name: 'callback',
  4980. description: '',
  4981. type: 'Function',
  4982. optional: true
  4983. },
  4984. {
  4985. name: 'errorCallback',
  4986. description: '',
  4987. type: 'Function',
  4988. optional: true
  4989. }
  4990. ]
  4991. },
  4992. {
  4993. params: [
  4994. {
  4995. name: 'path',
  4996. description: '',
  4997. type: 'String'
  4998. },
  4999. {
  5000. name: 'callback',
  5001. description: '',
  5002. type: 'Function'
  5003. },
  5004. {
  5005. name: 'errorCallback',
  5006. description: '',
  5007. type: 'Function',
  5008. optional: true
  5009. }
  5010. ]
  5011. }
  5012. ]
  5013. },
  5014. loadStrings: {
  5015. name: 'loadStrings',
  5016. params: [
  5017. {
  5018. name: 'filename',
  5019. description: '<p>name of the file or url to load</p>\n',
  5020. type: 'String'
  5021. },
  5022. {
  5023. name: 'callback',
  5024. description:
  5025. '<p>function to be executed after <a href="#/p5/loadStrings">loadStrings()</a>\n completes, Array is passed in as first\n argument</p>\n',
  5026. type: 'Function',
  5027. optional: true
  5028. },
  5029. {
  5030. name: 'errorCallback',
  5031. description:
  5032. '<p>function to be executed if\n there is an error, response is passed\n in as first argument</p>\n',
  5033. type: 'Function',
  5034. optional: true
  5035. }
  5036. ],
  5037. class: 'p5',
  5038. module: 'IO'
  5039. },
  5040. loadTable: {
  5041. name: 'loadTable',
  5042. params: [
  5043. {
  5044. name: 'filename',
  5045. description: '<p>name of the file or URL to load</p>\n',
  5046. type: 'String'
  5047. },
  5048. {
  5049. name: 'extension',
  5050. description:
  5051. '<p>parse the table by comma-separated values "csv", semicolon-separated\n values "ssv", or tab-separated values "tsv"</p>\n',
  5052. type: 'String',
  5053. optional: true
  5054. },
  5055. {
  5056. name: 'header',
  5057. description: '<p>"header" to indicate table has header row</p>\n',
  5058. type: 'String',
  5059. optional: true
  5060. },
  5061. {
  5062. name: 'callback',
  5063. description:
  5064. '<p>function to be executed after\n <a href="#/p5/loadTable">loadTable()</a> completes. On success, the\n <a href="#/p5.Table">Table</a> object is passed in as the\n first argument.</p>\n',
  5065. type: 'Function',
  5066. optional: true
  5067. },
  5068. {
  5069. name: 'errorCallback',
  5070. description:
  5071. '<p>function to be executed if\n there is an error, response is passed\n in as first argument</p>\n',
  5072. type: 'Function',
  5073. optional: true
  5074. }
  5075. ],
  5076. class: 'p5',
  5077. module: 'IO'
  5078. },
  5079. loadXML: {
  5080. name: 'loadXML',
  5081. params: [
  5082. {
  5083. name: 'filename',
  5084. description: '<p>name of the file or URL to load</p>\n',
  5085. type: 'String'
  5086. },
  5087. {
  5088. name: 'callback',
  5089. description:
  5090. '<p>function to be executed after <a href="#/p5/loadXML">loadXML()</a>\n completes, XML object is passed in as\n first argument</p>\n',
  5091. type: 'Function',
  5092. optional: true
  5093. },
  5094. {
  5095. name: 'errorCallback',
  5096. description:
  5097. '<p>function to be executed if\n there is an error, response is passed\n in as first argument</p>\n',
  5098. type: 'Function',
  5099. optional: true
  5100. }
  5101. ],
  5102. class: 'p5',
  5103. module: 'IO'
  5104. },
  5105. loadBytes: {
  5106. name: 'loadBytes',
  5107. params: [
  5108. {
  5109. name: 'file',
  5110. description: '<p>name of the file or URL to load</p>\n',
  5111. type: 'String'
  5112. },
  5113. {
  5114. name: 'callback',
  5115. description:
  5116. '<p>function to be executed after <a href="#/p5/loadBytes">loadBytes()</a>\n completes</p>\n',
  5117. type: 'Function',
  5118. optional: true
  5119. },
  5120. {
  5121. name: 'errorCallback',
  5122. description:
  5123. '<p>function to be executed if there\n is an error</p>\n',
  5124. type: 'Function',
  5125. optional: true
  5126. }
  5127. ],
  5128. class: 'p5',
  5129. module: 'IO'
  5130. },
  5131. httpGet: {
  5132. name: 'httpGet',
  5133. class: 'p5',
  5134. module: 'IO',
  5135. overloads: [
  5136. {
  5137. params: [
  5138. {
  5139. name: 'path',
  5140. description: '<p>name of the file or url to load</p>\n',
  5141. type: 'String'
  5142. },
  5143. {
  5144. name: 'datatype',
  5145. description:
  5146. '<p>"json", "jsonp", "binary", "arrayBuffer",\n "xml", or "text"</p>\n',
  5147. type: 'String',
  5148. optional: true
  5149. },
  5150. {
  5151. name: 'data',
  5152. description: '<p>param data passed sent with request</p>\n',
  5153. type: 'Object|Boolean',
  5154. optional: true
  5155. },
  5156. {
  5157. name: 'callback',
  5158. description:
  5159. '<p>function to be executed after\n <a href="#/p5/httpGet">httpGet()</a> completes, data is passed in\n as first argument</p>\n',
  5160. type: 'Function',
  5161. optional: true
  5162. },
  5163. {
  5164. name: 'errorCallback',
  5165. description:
  5166. '<p>function to be executed if\n there is an error, response is passed\n in as first argument</p>\n',
  5167. type: 'Function',
  5168. optional: true
  5169. }
  5170. ]
  5171. },
  5172. {
  5173. params: [
  5174. {
  5175. name: 'path',
  5176. description: '',
  5177. type: 'String'
  5178. },
  5179. {
  5180. name: 'data',
  5181. description: '',
  5182. type: 'Object|Boolean'
  5183. },
  5184. {
  5185. name: 'callback',
  5186. description: '',
  5187. type: 'Function',
  5188. optional: true
  5189. },
  5190. {
  5191. name: 'errorCallback',
  5192. description: '',
  5193. type: 'Function',
  5194. optional: true
  5195. }
  5196. ]
  5197. },
  5198. {
  5199. params: [
  5200. {
  5201. name: 'path',
  5202. description: '',
  5203. type: 'String'
  5204. },
  5205. {
  5206. name: 'callback',
  5207. description: '',
  5208. type: 'Function'
  5209. },
  5210. {
  5211. name: 'errorCallback',
  5212. description: '',
  5213. type: 'Function',
  5214. optional: true
  5215. }
  5216. ]
  5217. }
  5218. ]
  5219. },
  5220. httpPost: {
  5221. name: 'httpPost',
  5222. class: 'p5',
  5223. module: 'IO',
  5224. overloads: [
  5225. {
  5226. params: [
  5227. {
  5228. name: 'path',
  5229. description: '<p>name of the file or url to load</p>\n',
  5230. type: 'String'
  5231. },
  5232. {
  5233. name: 'datatype',
  5234. description:
  5235. '<p>"json", "jsonp", "xml", or "text".\n If omitted, <a href="#/p5/httpPost">httpPost()</a> will guess.</p>\n',
  5236. type: 'String',
  5237. optional: true
  5238. },
  5239. {
  5240. name: 'data',
  5241. description: '<p>param data passed sent with request</p>\n',
  5242. type: 'Object|Boolean',
  5243. optional: true
  5244. },
  5245. {
  5246. name: 'callback',
  5247. description:
  5248. '<p>function to be executed after\n <a href="#/p5/httpPost">httpPost()</a> completes, data is passed in\n as first argument</p>\n',
  5249. type: 'Function',
  5250. optional: true
  5251. },
  5252. {
  5253. name: 'errorCallback',
  5254. description:
  5255. '<p>function to be executed if\n there is an error, response is passed\n in as first argument</p>\n',
  5256. type: 'Function',
  5257. optional: true
  5258. }
  5259. ]
  5260. },
  5261. {
  5262. params: [
  5263. {
  5264. name: 'path',
  5265. description: '',
  5266. type: 'String'
  5267. },
  5268. {
  5269. name: 'data',
  5270. description: '',
  5271. type: 'Object|Boolean'
  5272. },
  5273. {
  5274. name: 'callback',
  5275. description: '',
  5276. type: 'Function',
  5277. optional: true
  5278. },
  5279. {
  5280. name: 'errorCallback',
  5281. description: '',
  5282. type: 'Function',
  5283. optional: true
  5284. }
  5285. ]
  5286. },
  5287. {
  5288. params: [
  5289. {
  5290. name: 'path',
  5291. description: '',
  5292. type: 'String'
  5293. },
  5294. {
  5295. name: 'callback',
  5296. description: '',
  5297. type: 'Function'
  5298. },
  5299. {
  5300. name: 'errorCallback',
  5301. description: '',
  5302. type: 'Function',
  5303. optional: true
  5304. }
  5305. ]
  5306. }
  5307. ]
  5308. },
  5309. httpDo: {
  5310. name: 'httpDo',
  5311. class: 'p5',
  5312. module: 'IO',
  5313. overloads: [
  5314. {
  5315. params: [
  5316. {
  5317. name: 'path',
  5318. description: '<p>name of the file or url to load</p>\n',
  5319. type: 'String'
  5320. },
  5321. {
  5322. name: 'method',
  5323. description:
  5324. '<p>either "GET", "POST", or "PUT",\n defaults to "GET"</p>\n',
  5325. type: 'String',
  5326. optional: true
  5327. },
  5328. {
  5329. name: 'datatype',
  5330. description: '<p>"json", "jsonp", "xml", or "text"</p>\n',
  5331. type: 'String',
  5332. optional: true
  5333. },
  5334. {
  5335. name: 'data',
  5336. description: '<p>param data passed sent with request</p>\n',
  5337. type: 'Object',
  5338. optional: true
  5339. },
  5340. {
  5341. name: 'callback',
  5342. description:
  5343. '<p>function to be executed after\n <a href="#/p5/httpGet">httpGet()</a> completes, data is passed in\n as first argument</p>\n',
  5344. type: 'Function',
  5345. optional: true
  5346. },
  5347. {
  5348. name: 'errorCallback',
  5349. description:
  5350. '<p>function to be executed if\n there is an error, response is passed\n in as first argument</p>\n',
  5351. type: 'Function',
  5352. optional: true
  5353. }
  5354. ]
  5355. },
  5356. {
  5357. params: [
  5358. {
  5359. name: 'path',
  5360. description: '',
  5361. type: 'String'
  5362. },
  5363. {
  5364. name: 'options',
  5365. description:
  5366. '<p>Request object options as documented in the\n "fetch" API\n<a href="https://developer.mozilla.org/en/docs/Web/API/Fetch_API">reference</a></p>\n',
  5367. type: 'Object'
  5368. },
  5369. {
  5370. name: 'callback',
  5371. description: '',
  5372. type: 'Function',
  5373. optional: true
  5374. },
  5375. {
  5376. name: 'errorCallback',
  5377. description: '',
  5378. type: 'Function',
  5379. optional: true
  5380. }
  5381. ]
  5382. }
  5383. ]
  5384. },
  5385. createWriter: {
  5386. name: 'createWriter',
  5387. params: [
  5388. {
  5389. name: 'name',
  5390. description: '<p>name of the file to be created</p>\n',
  5391. type: 'String'
  5392. },
  5393. {
  5394. name: 'extension',
  5395. description: '',
  5396. type: 'String',
  5397. optional: true
  5398. }
  5399. ],
  5400. class: 'p5',
  5401. module: 'IO'
  5402. },
  5403. save: {
  5404. name: 'save',
  5405. params: [
  5406. {
  5407. name: 'objectOrFilename',
  5408. description:
  5409. '<p>If filename is provided, will\n save canvas as an image with\n either png or jpg extension\n depending on the filename.\n If object is provided, will\n save depending on the object\n and filename (see examples\n above).</p>\n',
  5410. type: 'Object|String',
  5411. optional: true
  5412. },
  5413. {
  5414. name: 'filename',
  5415. description:
  5416. '<p>If an object is provided as the first\n parameter, then the second parameter\n indicates the filename,\n and should include an appropriate\n file extension (see examples above).</p>\n',
  5417. type: 'String',
  5418. optional: true
  5419. },
  5420. {
  5421. name: 'options',
  5422. description:
  5423. '<p>Additional options depend on\n filetype. For example, when saving JSON,\n <code>true</code> indicates that the\n output will be optimized for filesize,\n rather than readability.</p>\n',
  5424. type: 'Boolean|String',
  5425. optional: true
  5426. }
  5427. ],
  5428. class: 'p5',
  5429. module: 'IO'
  5430. },
  5431. saveJSON: {
  5432. name: 'saveJSON',
  5433. params: [
  5434. {
  5435. name: 'json',
  5436. description: '',
  5437. type: 'Array|Object'
  5438. },
  5439. {
  5440. name: 'filename',
  5441. description: '',
  5442. type: 'String'
  5443. },
  5444. {
  5445. name: 'optimize',
  5446. description:
  5447. '<p>If true, removes line breaks\n and spaces from the output\n file to optimize filesize\n (but not readability).</p>\n',
  5448. type: 'Boolean',
  5449. optional: true
  5450. }
  5451. ],
  5452. class: 'p5',
  5453. module: 'IO'
  5454. },
  5455. saveStrings: {
  5456. name: 'saveStrings',
  5457. params: [
  5458. {
  5459. name: 'list',
  5460. description: '<p>string array to be written</p>\n',
  5461. type: 'String[]'
  5462. },
  5463. {
  5464. name: 'filename',
  5465. description: '<p>filename for output</p>\n',
  5466. type: 'String'
  5467. },
  5468. {
  5469. name: 'extension',
  5470. description: "<p>the filename's extension</p>\n",
  5471. type: 'String',
  5472. optional: true
  5473. },
  5474. {
  5475. name: 'isCRLF',
  5476. description: '<p>if true, change line-break to CRLF</p>\n',
  5477. type: 'Boolean',
  5478. optional: true
  5479. }
  5480. ],
  5481. class: 'p5',
  5482. module: 'IO'
  5483. },
  5484. saveTable: {
  5485. name: 'saveTable',
  5486. params: [
  5487. {
  5488. name: 'Table',
  5489. description:
  5490. '<p>the <a href="#/p5.Table">Table</a> object to save to a file</p>\n',
  5491. type: 'p5.Table'
  5492. },
  5493. {
  5494. name: 'filename',
  5495. description: '<p>the filename to which the Table should be saved</p>\n',
  5496. type: 'String'
  5497. },
  5498. {
  5499. name: 'options',
  5500. description: '<p>can be one of "tsv", "csv", or "html"</p>\n',
  5501. type: 'String',
  5502. optional: true
  5503. }
  5504. ],
  5505. class: 'p5',
  5506. module: 'IO'
  5507. },
  5508. abs: {
  5509. name: 'abs',
  5510. params: [
  5511. {
  5512. name: 'n',
  5513. description: '<p>number to compute</p>\n',
  5514. type: 'Number'
  5515. }
  5516. ],
  5517. class: 'p5',
  5518. module: 'Math'
  5519. },
  5520. ceil: {
  5521. name: 'ceil',
  5522. params: [
  5523. {
  5524. name: 'n',
  5525. description: '<p>number to round up</p>\n',
  5526. type: 'Number'
  5527. }
  5528. ],
  5529. class: 'p5',
  5530. module: 'Math'
  5531. },
  5532. constrain: {
  5533. name: 'constrain',
  5534. params: [
  5535. {
  5536. name: 'n',
  5537. description: '<p>number to constrain</p>\n',
  5538. type: 'Number'
  5539. },
  5540. {
  5541. name: 'low',
  5542. description: '<p>minimum limit</p>\n',
  5543. type: 'Number'
  5544. },
  5545. {
  5546. name: 'high',
  5547. description: '<p>maximum limit</p>\n',
  5548. type: 'Number'
  5549. }
  5550. ],
  5551. class: 'p5',
  5552. module: 'Math'
  5553. },
  5554. dist: {
  5555. name: 'dist',
  5556. class: 'p5',
  5557. module: 'Math',
  5558. overloads: [
  5559. {
  5560. params: [
  5561. {
  5562. name: 'x1',
  5563. description: '<p>x-coordinate of the first point</p>\n',
  5564. type: 'Number'
  5565. },
  5566. {
  5567. name: 'y1',
  5568. description: '<p>y-coordinate of the first point</p>\n',
  5569. type: 'Number'
  5570. },
  5571. {
  5572. name: 'x2',
  5573. description: '<p>x-coordinate of the second point</p>\n',
  5574. type: 'Number'
  5575. },
  5576. {
  5577. name: 'y2',
  5578. description: '<p>y-coordinate of the second point</p>\n',
  5579. type: 'Number'
  5580. }
  5581. ]
  5582. },
  5583. {
  5584. params: [
  5585. {
  5586. name: 'x1',
  5587. description: '',
  5588. type: 'Number'
  5589. },
  5590. {
  5591. name: 'y1',
  5592. description: '',
  5593. type: 'Number'
  5594. },
  5595. {
  5596. name: 'z1',
  5597. description: '<p>z-coordinate of the first point</p>\n',
  5598. type: 'Number'
  5599. },
  5600. {
  5601. name: 'x2',
  5602. description: '',
  5603. type: 'Number'
  5604. },
  5605. {
  5606. name: 'y2',
  5607. description: '',
  5608. type: 'Number'
  5609. },
  5610. {
  5611. name: 'z2',
  5612. description: '<p>z-coordinate of the second point</p>\n',
  5613. type: 'Number'
  5614. }
  5615. ]
  5616. }
  5617. ]
  5618. },
  5619. exp: {
  5620. name: 'exp',
  5621. params: [
  5622. {
  5623. name: 'n',
  5624. description: '<p>exponent to raise</p>\n',
  5625. type: 'Number'
  5626. }
  5627. ],
  5628. class: 'p5',
  5629. module: 'Math'
  5630. },
  5631. floor: {
  5632. name: 'floor',
  5633. params: [
  5634. {
  5635. name: 'n',
  5636. description: '<p>number to round down</p>\n',
  5637. type: 'Number'
  5638. }
  5639. ],
  5640. class: 'p5',
  5641. module: 'Math'
  5642. },
  5643. lerp: {
  5644. name: 'lerp',
  5645. params: [
  5646. {
  5647. name: 'start',
  5648. description: '<p>first value</p>\n',
  5649. type: 'Number'
  5650. },
  5651. {
  5652. name: 'stop',
  5653. description: '<p>second value</p>\n',
  5654. type: 'Number'
  5655. },
  5656. {
  5657. name: 'amt',
  5658. description: '<p>number</p>\n',
  5659. type: 'Number'
  5660. }
  5661. ],
  5662. class: 'p5',
  5663. module: 'Math'
  5664. },
  5665. log: {
  5666. name: 'log',
  5667. params: [
  5668. {
  5669. name: 'n',
  5670. description: '<p>number greater than 0</p>\n',
  5671. type: 'Number'
  5672. }
  5673. ],
  5674. class: 'p5',
  5675. module: 'Math'
  5676. },
  5677. mag: {
  5678. name: 'mag',
  5679. params: [
  5680. {
  5681. name: 'a',
  5682. description: '<p>first value</p>\n',
  5683. type: 'Number'
  5684. },
  5685. {
  5686. name: 'b',
  5687. description: '<p>second value</p>\n',
  5688. type: 'Number'
  5689. }
  5690. ],
  5691. class: 'p5',
  5692. module: 'Math'
  5693. },
  5694. map: {
  5695. name: 'map',
  5696. params: [
  5697. {
  5698. name: 'value',
  5699. description: '<p>the incoming value to be converted</p>\n',
  5700. type: 'Number'
  5701. },
  5702. {
  5703. name: 'start1',
  5704. description: "<p>lower bound of the value's current range</p>\n",
  5705. type: 'Number'
  5706. },
  5707. {
  5708. name: 'stop1',
  5709. description: "<p>upper bound of the value's current range</p>\n",
  5710. type: 'Number'
  5711. },
  5712. {
  5713. name: 'start2',
  5714. description: "<p>lower bound of the value's target range</p>\n",
  5715. type: 'Number'
  5716. },
  5717. {
  5718. name: 'stop2',
  5719. description: "<p>upper bound of the value's target range</p>\n",
  5720. type: 'Number'
  5721. },
  5722. {
  5723. name: 'withinBounds',
  5724. description: '<p>constrain the value to the newly mapped range</p>\n',
  5725. type: 'Boolean',
  5726. optional: true
  5727. }
  5728. ],
  5729. class: 'p5',
  5730. module: 'Math'
  5731. },
  5732. max: {
  5733. name: 'max',
  5734. class: 'p5',
  5735. module: 'Math',
  5736. overloads: [
  5737. {
  5738. params: [
  5739. {
  5740. name: 'n0',
  5741. description: '<p>Number to compare</p>\n',
  5742. type: 'Number'
  5743. },
  5744. {
  5745. name: 'n1',
  5746. description: '<p>Number to compare</p>\n',
  5747. type: 'Number'
  5748. }
  5749. ]
  5750. },
  5751. {
  5752. params: [
  5753. {
  5754. name: 'nums',
  5755. description: '<p>Numbers to compare</p>\n',
  5756. type: 'Number[]'
  5757. }
  5758. ]
  5759. }
  5760. ]
  5761. },
  5762. min: {
  5763. name: 'min',
  5764. class: 'p5',
  5765. module: 'Math',
  5766. overloads: [
  5767. {
  5768. params: [
  5769. {
  5770. name: 'n0',
  5771. description: '<p>Number to compare</p>\n',
  5772. type: 'Number'
  5773. },
  5774. {
  5775. name: 'n1',
  5776. description: '<p>Number to compare</p>\n',
  5777. type: 'Number'
  5778. }
  5779. ]
  5780. },
  5781. {
  5782. params: [
  5783. {
  5784. name: 'nums',
  5785. description: '<p>Numbers to compare</p>\n',
  5786. type: 'Number[]'
  5787. }
  5788. ]
  5789. }
  5790. ]
  5791. },
  5792. norm: {
  5793. name: 'norm',
  5794. params: [
  5795. {
  5796. name: 'value',
  5797. description: '<p>incoming value to be normalized</p>\n',
  5798. type: 'Number'
  5799. },
  5800. {
  5801. name: 'start',
  5802. description: "<p>lower bound of the value's current range</p>\n",
  5803. type: 'Number'
  5804. },
  5805. {
  5806. name: 'stop',
  5807. description: "<p>upper bound of the value's current range</p>\n",
  5808. type: 'Number'
  5809. }
  5810. ],
  5811. class: 'p5',
  5812. module: 'Math'
  5813. },
  5814. pow: {
  5815. name: 'pow',
  5816. params: [
  5817. {
  5818. name: 'n',
  5819. description: '<p>base of the exponential expression</p>\n',
  5820. type: 'Number'
  5821. },
  5822. {
  5823. name: 'e',
  5824. description: '<p>power by which to raise the base</p>\n',
  5825. type: 'Number'
  5826. }
  5827. ],
  5828. class: 'p5',
  5829. module: 'Math'
  5830. },
  5831. round: {
  5832. name: 'round',
  5833. params: [
  5834. {
  5835. name: 'n',
  5836. description: '<p>number to round</p>\n',
  5837. type: 'Number'
  5838. },
  5839. {
  5840. name: 'decimals',
  5841. description:
  5842. '<p>number of decimal places to round to, default is 0</p>\n',
  5843. type: 'Number',
  5844. optional: true
  5845. }
  5846. ],
  5847. class: 'p5',
  5848. module: 'Math'
  5849. },
  5850. sq: {
  5851. name: 'sq',
  5852. params: [
  5853. {
  5854. name: 'n',
  5855. description: '<p>number to square</p>\n',
  5856. type: 'Number'
  5857. }
  5858. ],
  5859. class: 'p5',
  5860. module: 'Math'
  5861. },
  5862. sqrt: {
  5863. name: 'sqrt',
  5864. params: [
  5865. {
  5866. name: 'n',
  5867. description: '<p>non-negative number to square root</p>\n',
  5868. type: 'Number'
  5869. }
  5870. ],
  5871. class: 'p5',
  5872. module: 'Math'
  5873. },
  5874. fract: {
  5875. name: 'fract',
  5876. params: [
  5877. {
  5878. name: 'num',
  5879. description:
  5880. '<p>Number whose fractional part needs to be found out</p>\n',
  5881. type: 'Number'
  5882. }
  5883. ],
  5884. class: 'p5',
  5885. module: 'Math'
  5886. },
  5887. createVector: {
  5888. name: 'createVector',
  5889. params: [
  5890. {
  5891. name: 'x',
  5892. description: '<p>x component of the vector</p>\n',
  5893. type: 'Number',
  5894. optional: true
  5895. },
  5896. {
  5897. name: 'y',
  5898. description: '<p>y component of the vector</p>\n',
  5899. type: 'Number',
  5900. optional: true
  5901. },
  5902. {
  5903. name: 'z',
  5904. description: '<p>z component of the vector</p>\n',
  5905. type: 'Number',
  5906. optional: true
  5907. }
  5908. ],
  5909. class: 'p5',
  5910. module: 'Math'
  5911. },
  5912. noise: {
  5913. name: 'noise',
  5914. params: [
  5915. {
  5916. name: 'x',
  5917. description: '<p>x-coordinate in noise space</p>\n',
  5918. type: 'Number'
  5919. },
  5920. {
  5921. name: 'y',
  5922. description: '<p>y-coordinate in noise space</p>\n',
  5923. type: 'Number',
  5924. optional: true
  5925. },
  5926. {
  5927. name: 'z',
  5928. description: '<p>z-coordinate in noise space</p>\n',
  5929. type: 'Number',
  5930. optional: true
  5931. }
  5932. ],
  5933. class: 'p5',
  5934. module: 'Math'
  5935. },
  5936. noiseDetail: {
  5937. name: 'noiseDetail',
  5938. params: [
  5939. {
  5940. name: 'lod',
  5941. description: '<p>number of octaves to be used by the noise</p>\n',
  5942. type: 'Number'
  5943. },
  5944. {
  5945. name: 'falloff',
  5946. description: '<p>falloff factor for each octave</p>\n',
  5947. type: 'Number'
  5948. }
  5949. ],
  5950. class: 'p5',
  5951. module: 'Math'
  5952. },
  5953. noiseSeed: {
  5954. name: 'noiseSeed',
  5955. params: [
  5956. {
  5957. name: 'seed',
  5958. description: '<p>the seed value</p>\n',
  5959. type: 'Number'
  5960. }
  5961. ],
  5962. class: 'p5',
  5963. module: 'Math'
  5964. },
  5965. randomSeed: {
  5966. name: 'randomSeed',
  5967. params: [
  5968. {
  5969. name: 'seed',
  5970. description: '<p>the seed value</p>\n',
  5971. type: 'Number'
  5972. }
  5973. ],
  5974. class: 'p5',
  5975. module: 'Math'
  5976. },
  5977. random: {
  5978. name: 'random',
  5979. class: 'p5',
  5980. module: 'Math',
  5981. overloads: [
  5982. {
  5983. params: [
  5984. {
  5985. name: 'min',
  5986. description: '<p>the lower bound (inclusive)</p>\n',
  5987. type: 'Number',
  5988. optional: true
  5989. },
  5990. {
  5991. name: 'max',
  5992. description: '<p>the upper bound (exclusive)</p>\n',
  5993. type: 'Number',
  5994. optional: true
  5995. }
  5996. ]
  5997. },
  5998. {
  5999. params: [
  6000. {
  6001. name: 'choices',
  6002. description: '<p>the array to choose from</p>\n',
  6003. type: 'Array'
  6004. }
  6005. ]
  6006. }
  6007. ]
  6008. },
  6009. randomGaussian: {
  6010. name: 'randomGaussian',
  6011. params: [
  6012. {
  6013. name: 'mean',
  6014. description: '<p>the mean</p>\n',
  6015. type: 'Number',
  6016. optional: true
  6017. },
  6018. {
  6019. name: 'sd',
  6020. description: '<p>the standard deviation</p>\n',
  6021. type: 'Number',
  6022. optional: true
  6023. }
  6024. ],
  6025. class: 'p5',
  6026. module: 'Math'
  6027. },
  6028. acos: {
  6029. name: 'acos',
  6030. params: [
  6031. {
  6032. name: 'value',
  6033. description: '<p>the value whose arc cosine is to be returned</p>\n',
  6034. type: 'Number'
  6035. }
  6036. ],
  6037. class: 'p5',
  6038. module: 'Math'
  6039. },
  6040. asin: {
  6041. name: 'asin',
  6042. params: [
  6043. {
  6044. name: 'value',
  6045. description: '<p>the value whose arc sine is to be returned</p>\n',
  6046. type: 'Number'
  6047. }
  6048. ],
  6049. class: 'p5',
  6050. module: 'Math'
  6051. },
  6052. atan: {
  6053. name: 'atan',
  6054. params: [
  6055. {
  6056. name: 'value',
  6057. description: '<p>the value whose arc tangent is to be returned</p>\n',
  6058. type: 'Number'
  6059. }
  6060. ],
  6061. class: 'p5',
  6062. module: 'Math'
  6063. },
  6064. atan2: {
  6065. name: 'atan2',
  6066. params: [
  6067. {
  6068. name: 'y',
  6069. description: '<p>y-coordinate of the point</p>\n',
  6070. type: 'Number'
  6071. },
  6072. {
  6073. name: 'x',
  6074. description: '<p>x-coordinate of the point</p>\n',
  6075. type: 'Number'
  6076. }
  6077. ],
  6078. class: 'p5',
  6079. module: 'Math'
  6080. },
  6081. cos: {
  6082. name: 'cos',
  6083. params: [
  6084. {
  6085. name: 'angle',
  6086. description: '<p>the angle</p>\n',
  6087. type: 'Number'
  6088. }
  6089. ],
  6090. class: 'p5',
  6091. module: 'Math'
  6092. },
  6093. sin: {
  6094. name: 'sin',
  6095. params: [
  6096. {
  6097. name: 'angle',
  6098. description: '<p>the angle</p>\n',
  6099. type: 'Number'
  6100. }
  6101. ],
  6102. class: 'p5',
  6103. module: 'Math'
  6104. },
  6105. tan: {
  6106. name: 'tan',
  6107. params: [
  6108. {
  6109. name: 'angle',
  6110. description: '<p>the angle</p>\n',
  6111. type: 'Number'
  6112. }
  6113. ],
  6114. class: 'p5',
  6115. module: 'Math'
  6116. },
  6117. degrees: {
  6118. name: 'degrees',
  6119. params: [
  6120. {
  6121. name: 'radians',
  6122. description: '<p>the radians value to convert to degrees</p>\n',
  6123. type: 'Number'
  6124. }
  6125. ],
  6126. class: 'p5',
  6127. module: 'Math'
  6128. },
  6129. radians: {
  6130. name: 'radians',
  6131. params: [
  6132. {
  6133. name: 'degrees',
  6134. description: '<p>the degree value to convert to radians</p>\n',
  6135. type: 'Number'
  6136. }
  6137. ],
  6138. class: 'p5',
  6139. module: 'Math'
  6140. },
  6141. angleMode: {
  6142. name: 'angleMode',
  6143. params: [
  6144. {
  6145. name: 'mode',
  6146. description: '<p>either RADIANS or DEGREES</p>\n',
  6147. type: 'Constant'
  6148. }
  6149. ],
  6150. class: 'p5',
  6151. module: 'Math'
  6152. },
  6153. textAlign: {
  6154. name: 'textAlign',
  6155. class: 'p5',
  6156. module: 'Typography',
  6157. overloads: [
  6158. {
  6159. params: [
  6160. {
  6161. name: 'horizAlign',
  6162. description:
  6163. '<p>horizontal alignment, either LEFT,\n CENTER, or RIGHT</p>\n',
  6164. type: 'Constant'
  6165. },
  6166. {
  6167. name: 'vertAlign',
  6168. description:
  6169. '<p>vertical alignment, either TOP,\n BOTTOM, CENTER, or BASELINE</p>\n',
  6170. type: 'Constant',
  6171. optional: true
  6172. }
  6173. ],
  6174. chainable: 1
  6175. },
  6176. {
  6177. params: []
  6178. }
  6179. ]
  6180. },
  6181. textLeading: {
  6182. name: 'textLeading',
  6183. class: 'p5',
  6184. module: 'Typography',
  6185. overloads: [
  6186. {
  6187. params: [
  6188. {
  6189. name: 'leading',
  6190. description:
  6191. '<p>the size in pixels for spacing between lines</p>\n',
  6192. type: 'Number'
  6193. }
  6194. ],
  6195. chainable: 1
  6196. },
  6197. {
  6198. params: []
  6199. }
  6200. ]
  6201. },
  6202. textSize: {
  6203. name: 'textSize',
  6204. class: 'p5',
  6205. module: 'Typography',
  6206. overloads: [
  6207. {
  6208. params: [
  6209. {
  6210. name: 'theSize',
  6211. description: '<p>the size of the letters in units of pixels</p>\n',
  6212. type: 'Number'
  6213. }
  6214. ],
  6215. chainable: 1
  6216. },
  6217. {
  6218. params: []
  6219. }
  6220. ]
  6221. },
  6222. textStyle: {
  6223. name: 'textStyle',
  6224. class: 'p5',
  6225. module: 'Typography',
  6226. overloads: [
  6227. {
  6228. params: [
  6229. {
  6230. name: 'theStyle',
  6231. description:
  6232. '<p>styling for text, either NORMAL,\n ITALIC, BOLD or BOLDITALIC</p>\n',
  6233. type: 'Constant'
  6234. }
  6235. ],
  6236. chainable: 1
  6237. },
  6238. {
  6239. params: []
  6240. }
  6241. ]
  6242. },
  6243. textWidth: {
  6244. name: 'textWidth',
  6245. params: [
  6246. {
  6247. name: 'theText',
  6248. description: '<p>the String of characters to measure</p>\n',
  6249. type: 'String'
  6250. }
  6251. ],
  6252. class: 'p5',
  6253. module: 'Typography'
  6254. },
  6255. textAscent: {
  6256. name: 'textAscent',
  6257. class: 'p5',
  6258. module: 'Typography'
  6259. },
  6260. textDescent: {
  6261. name: 'textDescent',
  6262. class: 'p5',
  6263. module: 'Typography'
  6264. },
  6265. textWrap: {
  6266. name: 'textWrap',
  6267. params: [
  6268. {
  6269. name: 'wrapStyle',
  6270. description: '<p>text wrapping style, either WORD or CHAR</p>\n',
  6271. type: 'Constant'
  6272. }
  6273. ],
  6274. class: 'p5',
  6275. module: 'Typography'
  6276. },
  6277. loadFont: {
  6278. name: 'loadFont',
  6279. params: [
  6280. {
  6281. name: 'path',
  6282. description: '<p>name of the file or url to load</p>\n',
  6283. type: 'String'
  6284. },
  6285. {
  6286. name: 'callback',
  6287. description:
  6288. '<p>function to be executed after\n <a href="#/p5/loadFont">loadFont()</a> completes</p>\n',
  6289. type: 'Function',
  6290. optional: true
  6291. },
  6292. {
  6293. name: 'onError',
  6294. description:
  6295. '<p>function to be executed if\n an error occurs</p>\n',
  6296. type: 'Function',
  6297. optional: true
  6298. }
  6299. ],
  6300. class: 'p5',
  6301. module: 'Typography'
  6302. },
  6303. text: {
  6304. name: 'text',
  6305. params: [
  6306. {
  6307. name: 'str',
  6308. description:
  6309. '<p>the alphanumeric\n symbols to be displayed</p>\n',
  6310. type: 'String|Object|Array|Number|Boolean'
  6311. },
  6312. {
  6313. name: 'x',
  6314. description: '<p>x-coordinate of text</p>\n',
  6315. type: 'Number'
  6316. },
  6317. {
  6318. name: 'y',
  6319. description: '<p>y-coordinate of text</p>\n',
  6320. type: 'Number'
  6321. },
  6322. {
  6323. name: 'x2',
  6324. description:
  6325. '<p>by default, the width of the text box,\n see <a href="#/p5/rectMode">rectMode()</a> for more info</p>\n',
  6326. type: 'Number',
  6327. optional: true
  6328. },
  6329. {
  6330. name: 'y2',
  6331. description:
  6332. '<p>by default, the height of the text box,\n see <a href="#/p5/rectMode">rectMode()</a> for more info</p>\n',
  6333. type: 'Number',
  6334. optional: true
  6335. }
  6336. ],
  6337. class: 'p5',
  6338. module: 'Typography'
  6339. },
  6340. textFont: {
  6341. name: 'textFont',
  6342. class: 'p5',
  6343. module: 'Typography',
  6344. overloads: [
  6345. {
  6346. params: []
  6347. },
  6348. {
  6349. params: [
  6350. {
  6351. name: 'font',
  6352. description:
  6353. '<p>a font loaded via <a href="#/p5/loadFont">loadFont()</a>,\nor a String representing a <a href="https://mzl.la/2dOw8WD">web safe font</a>\n(a font that is generally available across all systems)</p>\n',
  6354. type: 'Object|String'
  6355. },
  6356. {
  6357. name: 'size',
  6358. description: '<p>the font size to use</p>\n',
  6359. type: 'Number',
  6360. optional: true
  6361. }
  6362. ],
  6363. chainable: 1
  6364. }
  6365. ]
  6366. },
  6367. append: {
  6368. name: 'append',
  6369. params: [
  6370. {
  6371. name: 'array',
  6372. description: '<p>Array to append</p>\n',
  6373. type: 'Array'
  6374. },
  6375. {
  6376. name: 'value',
  6377. description: '<p>to be added to the Array</p>\n',
  6378. type: 'Any'
  6379. }
  6380. ],
  6381. class: 'p5',
  6382. module: 'Data'
  6383. },
  6384. arrayCopy: {
  6385. name: 'arrayCopy',
  6386. class: 'p5',
  6387. module: 'Data',
  6388. overloads: [
  6389. {
  6390. params: [
  6391. {
  6392. name: 'src',
  6393. description: '<p>the source Array</p>\n',
  6394. type: 'Array'
  6395. },
  6396. {
  6397. name: 'srcPosition',
  6398. description: '<p>starting position in the source Array</p>\n',
  6399. type: 'Integer'
  6400. },
  6401. {
  6402. name: 'dst',
  6403. description: '<p>the destination Array</p>\n',
  6404. type: 'Array'
  6405. },
  6406. {
  6407. name: 'dstPosition',
  6408. description: '<p>starting position in the destination Array</p>\n',
  6409. type: 'Integer'
  6410. },
  6411. {
  6412. name: 'length',
  6413. description: '<p>number of Array elements to be copied</p>\n',
  6414. type: 'Integer'
  6415. }
  6416. ]
  6417. },
  6418. {
  6419. params: [
  6420. {
  6421. name: 'src',
  6422. description: '',
  6423. type: 'Array'
  6424. },
  6425. {
  6426. name: 'dst',
  6427. description: '',
  6428. type: 'Array'
  6429. },
  6430. {
  6431. name: 'length',
  6432. description: '',
  6433. type: 'Integer',
  6434. optional: true
  6435. }
  6436. ]
  6437. }
  6438. ]
  6439. },
  6440. concat: {
  6441. name: 'concat',
  6442. params: [
  6443. {
  6444. name: 'a',
  6445. description: '<p>first Array to concatenate</p>\n',
  6446. type: 'Array'
  6447. },
  6448. {
  6449. name: 'b',
  6450. description: '<p>second Array to concatenate</p>\n',
  6451. type: 'Array'
  6452. }
  6453. ],
  6454. class: 'p5',
  6455. module: 'Data'
  6456. },
  6457. reverse: {
  6458. name: 'reverse',
  6459. params: [
  6460. {
  6461. name: 'list',
  6462. description: '<p>Array to reverse</p>\n',
  6463. type: 'Array'
  6464. }
  6465. ],
  6466. class: 'p5',
  6467. module: 'Data'
  6468. },
  6469. shorten: {
  6470. name: 'shorten',
  6471. params: [
  6472. {
  6473. name: 'list',
  6474. description: '<p>Array to shorten</p>\n',
  6475. type: 'Array'
  6476. }
  6477. ],
  6478. class: 'p5',
  6479. module: 'Data'
  6480. },
  6481. shuffle: {
  6482. name: 'shuffle',
  6483. params: [
  6484. {
  6485. name: 'array',
  6486. description: '<p>Array to shuffle</p>\n',
  6487. type: 'Array'
  6488. },
  6489. {
  6490. name: 'bool',
  6491. description: '<p>modify passed array</p>\n',
  6492. type: 'Boolean',
  6493. optional: true
  6494. }
  6495. ],
  6496. class: 'p5',
  6497. module: 'Data'
  6498. },
  6499. sort: {
  6500. name: 'sort',
  6501. params: [
  6502. {
  6503. name: 'list',
  6504. description: '<p>Array to sort</p>\n',
  6505. type: 'Array'
  6506. },
  6507. {
  6508. name: 'count',
  6509. description: '<p>number of elements to sort, starting from 0</p>\n',
  6510. type: 'Integer',
  6511. optional: true
  6512. }
  6513. ],
  6514. class: 'p5',
  6515. module: 'Data'
  6516. },
  6517. splice: {
  6518. name: 'splice',
  6519. params: [
  6520. {
  6521. name: 'list',
  6522. description: '<p>Array to splice into</p>\n',
  6523. type: 'Array'
  6524. },
  6525. {
  6526. name: 'value',
  6527. description: '<p>value to be spliced in</p>\n',
  6528. type: 'Any'
  6529. },
  6530. {
  6531. name: 'position',
  6532. description: '<p>in the array from which to insert data</p>\n',
  6533. type: 'Integer'
  6534. }
  6535. ],
  6536. class: 'p5',
  6537. module: 'Data'
  6538. },
  6539. subset: {
  6540. name: 'subset',
  6541. params: [
  6542. {
  6543. name: 'list',
  6544. description: '<p>Array to extract from</p>\n',
  6545. type: 'Array'
  6546. },
  6547. {
  6548. name: 'start',
  6549. description: '<p>position to begin</p>\n',
  6550. type: 'Integer'
  6551. },
  6552. {
  6553. name: 'count',
  6554. description: '<p>number of values to extract</p>\n',
  6555. type: 'Integer',
  6556. optional: true
  6557. }
  6558. ],
  6559. class: 'p5',
  6560. module: 'Data'
  6561. },
  6562. float: {
  6563. name: 'float',
  6564. params: [
  6565. {
  6566. name: 'str',
  6567. description: '<p>float string to parse</p>\n',
  6568. type: 'String'
  6569. }
  6570. ],
  6571. class: 'p5',
  6572. module: 'Data'
  6573. },
  6574. int: {
  6575. name: 'int',
  6576. class: 'p5',
  6577. module: 'Data',
  6578. overloads: [
  6579. {
  6580. params: [
  6581. {
  6582. name: 'n',
  6583. description: '<p>value to parse</p>\n',
  6584. type: 'String|Boolean|Number'
  6585. },
  6586. {
  6587. name: 'radix',
  6588. description: '<p>the radix to convert to (default: 10)</p>\n',
  6589. type: 'Integer',
  6590. optional: true
  6591. }
  6592. ]
  6593. },
  6594. {
  6595. params: [
  6596. {
  6597. name: 'ns',
  6598. description: '<p>values to parse</p>\n',
  6599. type: 'Array'
  6600. },
  6601. {
  6602. name: 'radix',
  6603. description: '',
  6604. type: 'Integer',
  6605. optional: true
  6606. }
  6607. ]
  6608. }
  6609. ]
  6610. },
  6611. str: {
  6612. name: 'str',
  6613. params: [
  6614. {
  6615. name: 'n',
  6616. description: '<p>value to parse</p>\n',
  6617. type: 'String|Boolean|Number|Array'
  6618. }
  6619. ],
  6620. class: 'p5',
  6621. module: 'Data'
  6622. },
  6623. byte: {
  6624. name: 'byte',
  6625. class: 'p5',
  6626. module: 'Data',
  6627. overloads: [
  6628. {
  6629. params: [
  6630. {
  6631. name: 'n',
  6632. description: '<p>value to parse</p>\n',
  6633. type: 'String|Boolean|Number'
  6634. }
  6635. ]
  6636. },
  6637. {
  6638. params: [
  6639. {
  6640. name: 'ns',
  6641. description: '<p>values to parse</p>\n',
  6642. type: 'Array'
  6643. }
  6644. ]
  6645. }
  6646. ]
  6647. },
  6648. char: {
  6649. name: 'char',
  6650. class: 'p5',
  6651. module: 'Data',
  6652. overloads: [
  6653. {
  6654. params: [
  6655. {
  6656. name: 'n',
  6657. description: '<p>value to parse</p>\n',
  6658. type: 'String|Number'
  6659. }
  6660. ]
  6661. },
  6662. {
  6663. params: [
  6664. {
  6665. name: 'ns',
  6666. description: '<p>values to parse</p>\n',
  6667. type: 'Array'
  6668. }
  6669. ]
  6670. }
  6671. ]
  6672. },
  6673. unchar: {
  6674. name: 'unchar',
  6675. class: 'p5',
  6676. module: 'Data',
  6677. overloads: [
  6678. {
  6679. params: [
  6680. {
  6681. name: 'n',
  6682. description: '<p>value to parse</p>\n',
  6683. type: 'String'
  6684. }
  6685. ]
  6686. },
  6687. {
  6688. params: [
  6689. {
  6690. name: 'ns',
  6691. description: '<p>values to parse</p>\n',
  6692. type: 'Array'
  6693. }
  6694. ]
  6695. }
  6696. ]
  6697. },
  6698. hex: {
  6699. name: 'hex',
  6700. class: 'p5',
  6701. module: 'Data',
  6702. overloads: [
  6703. {
  6704. params: [
  6705. {
  6706. name: 'n',
  6707. description: '<p>value to parse</p>\n',
  6708. type: 'Number'
  6709. },
  6710. {
  6711. name: 'digits',
  6712. description: '',
  6713. type: 'Number',
  6714. optional: true
  6715. }
  6716. ]
  6717. },
  6718. {
  6719. params: [
  6720. {
  6721. name: 'ns',
  6722. description: '<p>array of values to parse</p>\n',
  6723. type: 'Number[]'
  6724. },
  6725. {
  6726. name: 'digits',
  6727. description: '',
  6728. type: 'Number',
  6729. optional: true
  6730. }
  6731. ]
  6732. }
  6733. ]
  6734. },
  6735. unhex: {
  6736. name: 'unhex',
  6737. class: 'p5',
  6738. module: 'Data',
  6739. overloads: [
  6740. {
  6741. params: [
  6742. {
  6743. name: 'n',
  6744. description: '<p>value to parse</p>\n',
  6745. type: 'String'
  6746. }
  6747. ]
  6748. },
  6749. {
  6750. params: [
  6751. {
  6752. name: 'ns',
  6753. description: '<p>values to parse</p>\n',
  6754. type: 'Array'
  6755. }
  6756. ]
  6757. }
  6758. ]
  6759. },
  6760. join: {
  6761. name: 'join',
  6762. params: [
  6763. {
  6764. name: 'list',
  6765. description: '<p>array of Strings to be joined</p>\n',
  6766. type: 'Array'
  6767. },
  6768. {
  6769. name: 'separator',
  6770. description: '<p>String to be placed between each item</p>\n',
  6771. type: 'String'
  6772. }
  6773. ],
  6774. class: 'p5',
  6775. module: 'Data'
  6776. },
  6777. match: {
  6778. name: 'match',
  6779. params: [
  6780. {
  6781. name: 'str',
  6782. description: '<p>the String to be searched</p>\n',
  6783. type: 'String'
  6784. },
  6785. {
  6786. name: 'regexp',
  6787. description: '<p>the regexp to be used for matching</p>\n',
  6788. type: 'String'
  6789. }
  6790. ],
  6791. class: 'p5',
  6792. module: 'Data'
  6793. },
  6794. matchAll: {
  6795. name: 'matchAll',
  6796. params: [
  6797. {
  6798. name: 'str',
  6799. description: '<p>the String to be searched</p>\n',
  6800. type: 'String'
  6801. },
  6802. {
  6803. name: 'regexp',
  6804. description: '<p>the regexp to be used for matching</p>\n',
  6805. type: 'String'
  6806. }
  6807. ],
  6808. class: 'p5',
  6809. module: 'Data'
  6810. },
  6811. nf: {
  6812. name: 'nf',
  6813. class: 'p5',
  6814. module: 'Data',
  6815. overloads: [
  6816. {
  6817. params: [
  6818. {
  6819. name: 'num',
  6820. description: '<p>the Number to format</p>\n',
  6821. type: 'Number|String'
  6822. },
  6823. {
  6824. name: 'left',
  6825. description:
  6826. '<p>number of digits to the left of the\n decimal point</p>\n',
  6827. type: 'Integer|String',
  6828. optional: true
  6829. },
  6830. {
  6831. name: 'right',
  6832. description:
  6833. '<p>number of digits to the right of the\n decimal point</p>\n',
  6834. type: 'Integer|String',
  6835. optional: true
  6836. }
  6837. ]
  6838. },
  6839. {
  6840. params: [
  6841. {
  6842. name: 'nums',
  6843. description: '<p>the Numbers to format</p>\n',
  6844. type: 'Array'
  6845. },
  6846. {
  6847. name: 'left',
  6848. description: '',
  6849. type: 'Integer|String',
  6850. optional: true
  6851. },
  6852. {
  6853. name: 'right',
  6854. description: '',
  6855. type: 'Integer|String',
  6856. optional: true
  6857. }
  6858. ]
  6859. }
  6860. ]
  6861. },
  6862. nfc: {
  6863. name: 'nfc',
  6864. class: 'p5',
  6865. module: 'Data',
  6866. overloads: [
  6867. {
  6868. params: [
  6869. {
  6870. name: 'num',
  6871. description: '<p>the Number to format</p>\n',
  6872. type: 'Number|String'
  6873. },
  6874. {
  6875. name: 'right',
  6876. description:
  6877. '<p>number of digits to the right of the\n decimal point</p>\n',
  6878. type: 'Integer|String',
  6879. optional: true
  6880. }
  6881. ]
  6882. },
  6883. {
  6884. params: [
  6885. {
  6886. name: 'nums',
  6887. description: '<p>the Numbers to format</p>\n',
  6888. type: 'Array'
  6889. },
  6890. {
  6891. name: 'right',
  6892. description: '',
  6893. type: 'Integer|String',
  6894. optional: true
  6895. }
  6896. ]
  6897. }
  6898. ]
  6899. },
  6900. nfp: {
  6901. name: 'nfp',
  6902. class: 'p5',
  6903. module: 'Data',
  6904. overloads: [
  6905. {
  6906. params: [
  6907. {
  6908. name: 'num',
  6909. description: '<p>the Number to format</p>\n',
  6910. type: 'Number'
  6911. },
  6912. {
  6913. name: 'left',
  6914. description:
  6915. '<p>number of digits to the left of the decimal\n point</p>\n',
  6916. type: 'Integer',
  6917. optional: true
  6918. },
  6919. {
  6920. name: 'right',
  6921. description:
  6922. '<p>number of digits to the right of the\n decimal point</p>\n',
  6923. type: 'Integer',
  6924. optional: true
  6925. }
  6926. ]
  6927. },
  6928. {
  6929. params: [
  6930. {
  6931. name: 'nums',
  6932. description: '<p>the Numbers to format</p>\n',
  6933. type: 'Number[]'
  6934. },
  6935. {
  6936. name: 'left',
  6937. description: '',
  6938. type: 'Integer',
  6939. optional: true
  6940. },
  6941. {
  6942. name: 'right',
  6943. description: '',
  6944. type: 'Integer',
  6945. optional: true
  6946. }
  6947. ]
  6948. }
  6949. ]
  6950. },
  6951. nfs: {
  6952. name: 'nfs',
  6953. class: 'p5',
  6954. module: 'Data',
  6955. overloads: [
  6956. {
  6957. params: [
  6958. {
  6959. name: 'num',
  6960. description: '<p>the Number to format</p>\n',
  6961. type: 'Number'
  6962. },
  6963. {
  6964. name: 'left',
  6965. description:
  6966. '<p>number of digits to the left of the decimal\n point</p>\n',
  6967. type: 'Integer',
  6968. optional: true
  6969. },
  6970. {
  6971. name: 'right',
  6972. description:
  6973. '<p>number of digits to the right of the\n decimal point</p>\n',
  6974. type: 'Integer',
  6975. optional: true
  6976. }
  6977. ]
  6978. },
  6979. {
  6980. params: [
  6981. {
  6982. name: 'nums',
  6983. description: '<p>the Numbers to format</p>\n',
  6984. type: 'Array'
  6985. },
  6986. {
  6987. name: 'left',
  6988. description: '',
  6989. type: 'Integer',
  6990. optional: true
  6991. },
  6992. {
  6993. name: 'right',
  6994. description: '',
  6995. type: 'Integer',
  6996. optional: true
  6997. }
  6998. ]
  6999. }
  7000. ]
  7001. },
  7002. split: {
  7003. name: 'split',
  7004. params: [
  7005. {
  7006. name: 'value',
  7007. description: '<p>the String to be split</p>\n',
  7008. type: 'String'
  7009. },
  7010. {
  7011. name: 'delim',
  7012. description: '<p>the String used to separate the data</p>\n',
  7013. type: 'String'
  7014. }
  7015. ],
  7016. class: 'p5',
  7017. module: 'Data'
  7018. },
  7019. splitTokens: {
  7020. name: 'splitTokens',
  7021. params: [
  7022. {
  7023. name: 'value',
  7024. description: '<p>the String to be split</p>\n',
  7025. type: 'String'
  7026. },
  7027. {
  7028. name: 'delim',
  7029. description:
  7030. '<p>list of individual Strings that will be used as\n separators</p>\n',
  7031. type: 'String',
  7032. optional: true
  7033. }
  7034. ],
  7035. class: 'p5',
  7036. module: 'Data'
  7037. },
  7038. trim: {
  7039. name: 'trim',
  7040. class: 'p5',
  7041. module: 'Data',
  7042. overloads: [
  7043. {
  7044. params: [
  7045. {
  7046. name: 'str',
  7047. description: '<p>a String to be trimmed</p>\n',
  7048. type: 'String'
  7049. }
  7050. ]
  7051. },
  7052. {
  7053. params: [
  7054. {
  7055. name: 'strs',
  7056. description: '<p>an Array of Strings to be trimmed</p>\n',
  7057. type: 'Array'
  7058. }
  7059. ]
  7060. }
  7061. ]
  7062. },
  7063. day: {
  7064. name: 'day',
  7065. class: 'p5',
  7066. module: 'IO'
  7067. },
  7068. hour: {
  7069. name: 'hour',
  7070. class: 'p5',
  7071. module: 'IO'
  7072. },
  7073. minute: {
  7074. name: 'minute',
  7075. class: 'p5',
  7076. module: 'IO'
  7077. },
  7078. millis: {
  7079. name: 'millis',
  7080. class: 'p5',
  7081. module: 'IO'
  7082. },
  7083. month: {
  7084. name: 'month',
  7085. class: 'p5',
  7086. module: 'IO'
  7087. },
  7088. second: {
  7089. name: 'second',
  7090. class: 'p5',
  7091. module: 'IO'
  7092. },
  7093. year: {
  7094. name: 'year',
  7095. class: 'p5',
  7096. module: 'IO'
  7097. },
  7098. plane: {
  7099. name: 'plane',
  7100. params: [
  7101. {
  7102. name: 'width',
  7103. description: '<p>width of the plane</p>\n',
  7104. type: 'Number',
  7105. optional: true
  7106. },
  7107. {
  7108. name: 'height',
  7109. description: '<p>height of the plane</p>\n',
  7110. type: 'Number',
  7111. optional: true
  7112. },
  7113. {
  7114. name: 'detailX',
  7115. description:
  7116. '<p>Optional number of triangle\n subdivisions in x-dimension</p>\n',
  7117. type: 'Integer',
  7118. optional: true
  7119. },
  7120. {
  7121. name: 'detailY',
  7122. description:
  7123. '<p>Optional number of triangle\n subdivisions in y-dimension</p>\n',
  7124. type: 'Integer',
  7125. optional: true
  7126. }
  7127. ],
  7128. class: 'p5',
  7129. module: 'Shape'
  7130. },
  7131. box: {
  7132. name: 'box',
  7133. params: [
  7134. {
  7135. name: 'width',
  7136. description: '<p>width of the box</p>\n',
  7137. type: 'Number',
  7138. optional: true
  7139. },
  7140. {
  7141. name: 'Height',
  7142. description: '<p>height of the box</p>\n',
  7143. type: 'Number',
  7144. optional: true
  7145. },
  7146. {
  7147. name: 'depth',
  7148. description: '<p>depth of the box</p>\n',
  7149. type: 'Number',
  7150. optional: true
  7151. },
  7152. {
  7153. name: 'detailX',
  7154. description:
  7155. '<p>Optional number of triangle\n subdivisions in x-dimension</p>\n',
  7156. type: 'Integer',
  7157. optional: true
  7158. },
  7159. {
  7160. name: 'detailY',
  7161. description:
  7162. '<p>Optional number of triangle\n subdivisions in y-dimension</p>\n',
  7163. type: 'Integer',
  7164. optional: true
  7165. }
  7166. ],
  7167. class: 'p5',
  7168. module: 'Shape'
  7169. },
  7170. sphere: {
  7171. name: 'sphere',
  7172. params: [
  7173. {
  7174. name: 'radius',
  7175. description: '<p>radius of circle</p>\n',
  7176. type: 'Number',
  7177. optional: true
  7178. },
  7179. {
  7180. name: 'detailX',
  7181. description: '<p>optional number of subdivisions in x-dimension</p>\n',
  7182. type: 'Integer',
  7183. optional: true
  7184. },
  7185. {
  7186. name: 'detailY',
  7187. description: '<p>optional number of subdivisions in y-dimension</p>\n',
  7188. type: 'Integer',
  7189. optional: true
  7190. }
  7191. ],
  7192. class: 'p5',
  7193. module: 'Shape'
  7194. },
  7195. cylinder: {
  7196. name: 'cylinder',
  7197. params: [
  7198. {
  7199. name: 'radius',
  7200. description: '<p>radius of the surface</p>\n',
  7201. type: 'Number',
  7202. optional: true
  7203. },
  7204. {
  7205. name: 'height',
  7206. description: '<p>height of the cylinder</p>\n',
  7207. type: 'Number',
  7208. optional: true
  7209. },
  7210. {
  7211. name: 'detailX',
  7212. description:
  7213. '<p>number of subdivisions in x-dimension;\n default is 24</p>\n',
  7214. type: 'Integer',
  7215. optional: true
  7216. },
  7217. {
  7218. name: 'detailY',
  7219. description:
  7220. '<p>number of subdivisions in y-dimension;\n default is 1</p>\n',
  7221. type: 'Integer',
  7222. optional: true
  7223. },
  7224. {
  7225. name: 'bottomCap',
  7226. description: '<p>whether to draw the bottom of the cylinder</p>\n',
  7227. type: 'Boolean',
  7228. optional: true
  7229. },
  7230. {
  7231. name: 'topCap',
  7232. description: '<p>whether to draw the top of the cylinder</p>\n',
  7233. type: 'Boolean',
  7234. optional: true
  7235. }
  7236. ],
  7237. class: 'p5',
  7238. module: 'Shape'
  7239. },
  7240. cone: {
  7241. name: 'cone',
  7242. params: [
  7243. {
  7244. name: 'radius',
  7245. description: '<p>radius of the bottom surface</p>\n',
  7246. type: 'Number',
  7247. optional: true
  7248. },
  7249. {
  7250. name: 'height',
  7251. description: '<p>height of the cone</p>\n',
  7252. type: 'Number',
  7253. optional: true
  7254. },
  7255. {
  7256. name: 'detailX',
  7257. description:
  7258. '<p>number of segments,\n the more segments the smoother geometry\n default is 24</p>\n',
  7259. type: 'Integer',
  7260. optional: true
  7261. },
  7262. {
  7263. name: 'detailY',
  7264. description:
  7265. '<p>number of segments,\n the more segments the smoother geometry\n default is 1</p>\n',
  7266. type: 'Integer',
  7267. optional: true
  7268. },
  7269. {
  7270. name: 'cap',
  7271. description: '<p>whether to draw the base of the cone</p>\n',
  7272. type: 'Boolean',
  7273. optional: true
  7274. }
  7275. ],
  7276. class: 'p5',
  7277. module: 'Shape'
  7278. },
  7279. ellipsoid: {
  7280. name: 'ellipsoid',
  7281. params: [
  7282. {
  7283. name: 'radiusx',
  7284. description: '<p>x-radius of ellipsoid</p>\n',
  7285. type: 'Number',
  7286. optional: true
  7287. },
  7288. {
  7289. name: 'radiusy',
  7290. description: '<p>y-radius of ellipsoid</p>\n',
  7291. type: 'Number',
  7292. optional: true
  7293. },
  7294. {
  7295. name: 'radiusz',
  7296. description: '<p>z-radius of ellipsoid</p>\n',
  7297. type: 'Number',
  7298. optional: true
  7299. },
  7300. {
  7301. name: 'detailX',
  7302. description:
  7303. '<p>number of segments,\n the more segments the smoother geometry\n default is 24. Avoid detail number above\n 150, it may crash the browser.</p>\n',
  7304. type: 'Integer',
  7305. optional: true
  7306. },
  7307. {
  7308. name: 'detailY',
  7309. description:
  7310. '<p>number of segments,\n the more segments the smoother geometry\n default is 16. Avoid detail number above\n 150, it may crash the browser.</p>\n',
  7311. type: 'Integer',
  7312. optional: true
  7313. }
  7314. ],
  7315. class: 'p5',
  7316. module: 'Shape'
  7317. },
  7318. torus: {
  7319. name: 'torus',
  7320. params: [
  7321. {
  7322. name: 'radius',
  7323. description: '<p>radius of the whole ring</p>\n',
  7324. type: 'Number',
  7325. optional: true
  7326. },
  7327. {
  7328. name: 'tubeRadius',
  7329. description: '<p>radius of the tube</p>\n',
  7330. type: 'Number',
  7331. optional: true
  7332. },
  7333. {
  7334. name: 'detailX',
  7335. description:
  7336. '<p>number of segments in x-dimension,\n the more segments the smoother geometry\n default is 24</p>\n',
  7337. type: 'Integer',
  7338. optional: true
  7339. },
  7340. {
  7341. name: 'detailY',
  7342. description:
  7343. '<p>number of segments in y-dimension,\n the more segments the smoother geometry\n default is 16</p>\n',
  7344. type: 'Integer',
  7345. optional: true
  7346. }
  7347. ],
  7348. class: 'p5',
  7349. module: 'Shape'
  7350. },
  7351. orbitControl: {
  7352. name: 'orbitControl',
  7353. params: [
  7354. {
  7355. name: 'sensitivityX',
  7356. description: '<p>sensitivity to mouse movement along X axis</p>\n',
  7357. type: 'Number',
  7358. optional: true
  7359. },
  7360. {
  7361. name: 'sensitivityY',
  7362. description: '<p>sensitivity to mouse movement along Y axis</p>\n',
  7363. type: 'Number',
  7364. optional: true
  7365. },
  7366. {
  7367. name: 'sensitivityZ',
  7368. description: '<p>sensitivity to scroll movement along Z axis</p>\n',
  7369. type: 'Number',
  7370. optional: true
  7371. }
  7372. ],
  7373. class: 'p5',
  7374. module: 'Lights, Camera'
  7375. },
  7376. debugMode: {
  7377. name: 'debugMode',
  7378. class: 'p5',
  7379. module: 'Lights, Camera',
  7380. overloads: [
  7381. {
  7382. params: []
  7383. },
  7384. {
  7385. params: [
  7386. {
  7387. name: 'mode',
  7388. description: '<p>either GRID or AXES</p>\n',
  7389. type: 'Constant'
  7390. }
  7391. ]
  7392. },
  7393. {
  7394. params: [
  7395. {
  7396. name: 'mode',
  7397. description: '',
  7398. type: 'Constant'
  7399. },
  7400. {
  7401. name: 'gridSize',
  7402. description: '<p>size of one side of the grid</p>\n',
  7403. type: 'Number',
  7404. optional: true
  7405. },
  7406. {
  7407. name: 'gridDivisions',
  7408. description: '<p>number of divisions in the grid</p>\n',
  7409. type: 'Number',
  7410. optional: true
  7411. },
  7412. {
  7413. name: 'xOff',
  7414. description: '<p>X axis offset from origin (0,0,0)</p>\n',
  7415. type: 'Number',
  7416. optional: true
  7417. },
  7418. {
  7419. name: 'yOff',
  7420. description: '<p>Y axis offset from origin (0,0,0)</p>\n',
  7421. type: 'Number',
  7422. optional: true
  7423. },
  7424. {
  7425. name: 'zOff',
  7426. description: '<p>Z axis offset from origin (0,0,0)</p>\n',
  7427. type: 'Number',
  7428. optional: true
  7429. }
  7430. ]
  7431. },
  7432. {
  7433. params: [
  7434. {
  7435. name: 'mode',
  7436. description: '',
  7437. type: 'Constant'
  7438. },
  7439. {
  7440. name: 'axesSize',
  7441. description: '<p>size of axes icon</p>\n',
  7442. type: 'Number',
  7443. optional: true
  7444. },
  7445. {
  7446. name: 'xOff',
  7447. description: '',
  7448. type: 'Number',
  7449. optional: true
  7450. },
  7451. {
  7452. name: 'yOff',
  7453. description: '',
  7454. type: 'Number',
  7455. optional: true
  7456. },
  7457. {
  7458. name: 'zOff',
  7459. description: '',
  7460. type: 'Number',
  7461. optional: true
  7462. }
  7463. ]
  7464. },
  7465. {
  7466. params: [
  7467. {
  7468. name: 'gridSize',
  7469. description: '',
  7470. type: 'Number',
  7471. optional: true
  7472. },
  7473. {
  7474. name: 'gridDivisions',
  7475. description: '',
  7476. type: 'Number',
  7477. optional: true
  7478. },
  7479. {
  7480. name: 'gridXOff',
  7481. description: '',
  7482. type: 'Number',
  7483. optional: true
  7484. },
  7485. {
  7486. name: 'gridYOff',
  7487. description: '',
  7488. type: 'Number',
  7489. optional: true
  7490. },
  7491. {
  7492. name: 'gridZOff',
  7493. description: '',
  7494. type: 'Number',
  7495. optional: true
  7496. },
  7497. {
  7498. name: 'axesSize',
  7499. description: '',
  7500. type: 'Number',
  7501. optional: true
  7502. },
  7503. {
  7504. name: 'axesXOff',
  7505. description: '',
  7506. type: 'Number',
  7507. optional: true
  7508. },
  7509. {
  7510. name: 'axesYOff',
  7511. description: '',
  7512. type: 'Number',
  7513. optional: true
  7514. },
  7515. {
  7516. name: 'axesZOff',
  7517. description: '',
  7518. type: 'Number',
  7519. optional: true
  7520. }
  7521. ]
  7522. }
  7523. ]
  7524. },
  7525. noDebugMode: {
  7526. name: 'noDebugMode',
  7527. class: 'p5',
  7528. module: 'Lights, Camera'
  7529. },
  7530. ambientLight: {
  7531. name: 'ambientLight',
  7532. class: 'p5',
  7533. module: 'Lights, Camera',
  7534. overloads: [
  7535. {
  7536. params: [
  7537. {
  7538. name: 'v1',
  7539. description:
  7540. '<p>red or hue value relative to\n the current color range</p>\n',
  7541. type: 'Number'
  7542. },
  7543. {
  7544. name: 'v2',
  7545. description:
  7546. '<p>green or saturation value\n relative to the current color range</p>\n',
  7547. type: 'Number'
  7548. },
  7549. {
  7550. name: 'v3',
  7551. description:
  7552. '<p>blue or brightness value\n relative to the current color range</p>\n',
  7553. type: 'Number'
  7554. },
  7555. {
  7556. name: 'alpha',
  7557. description: '<p>the alpha value</p>\n',
  7558. type: 'Number',
  7559. optional: true
  7560. }
  7561. ],
  7562. chainable: 1
  7563. },
  7564. {
  7565. params: [
  7566. {
  7567. name: 'value',
  7568. description: '<p>a color string</p>\n',
  7569. type: 'String'
  7570. }
  7571. ],
  7572. chainable: 1
  7573. },
  7574. {
  7575. params: [
  7576. {
  7577. name: 'gray',
  7578. description: '<p>a gray value</p>\n',
  7579. type: 'Number'
  7580. },
  7581. {
  7582. name: 'alpha',
  7583. description: '',
  7584. type: 'Number',
  7585. optional: true
  7586. }
  7587. ],
  7588. chainable: 1
  7589. },
  7590. {
  7591. params: [
  7592. {
  7593. name: 'values',
  7594. description:
  7595. '<p>an array containing the red,green,blue &\n and alpha components of the color</p>\n',
  7596. type: 'Number[]'
  7597. }
  7598. ],
  7599. chainable: 1
  7600. },
  7601. {
  7602. params: [
  7603. {
  7604. name: 'color',
  7605. description: '<p>the ambient light color</p>\n',
  7606. type: 'p5.Color'
  7607. }
  7608. ],
  7609. chainable: 1
  7610. }
  7611. ]
  7612. },
  7613. specularColor: {
  7614. name: 'specularColor',
  7615. class: 'p5',
  7616. module: 'Lights, Camera',
  7617. overloads: [
  7618. {
  7619. params: [
  7620. {
  7621. name: 'v1',
  7622. description:
  7623. '<p>red or hue value relative to\n the current color range</p>\n',
  7624. type: 'Number'
  7625. },
  7626. {
  7627. name: 'v2',
  7628. description:
  7629. '<p>green or saturation value\n relative to the current color range</p>\n',
  7630. type: 'Number'
  7631. },
  7632. {
  7633. name: 'v3',
  7634. description:
  7635. '<p>blue or brightness value\n relative to the current color range</p>\n',
  7636. type: 'Number'
  7637. }
  7638. ],
  7639. chainable: 1
  7640. },
  7641. {
  7642. params: [
  7643. {
  7644. name: 'value',
  7645. description: '<p>a color string</p>\n',
  7646. type: 'String'
  7647. }
  7648. ],
  7649. chainable: 1
  7650. },
  7651. {
  7652. params: [
  7653. {
  7654. name: 'gray',
  7655. description: '<p>a gray value</p>\n',
  7656. type: 'Number'
  7657. }
  7658. ],
  7659. chainable: 1
  7660. },
  7661. {
  7662. params: [
  7663. {
  7664. name: 'values',
  7665. description:
  7666. '<p>an array containing the red,green,blue &\n and alpha components of the color</p>\n',
  7667. type: 'Number[]'
  7668. }
  7669. ],
  7670. chainable: 1
  7671. },
  7672. {
  7673. params: [
  7674. {
  7675. name: 'color',
  7676. description: '<p>the ambient light color</p>\n',
  7677. type: 'p5.Color'
  7678. }
  7679. ],
  7680. chainable: 1
  7681. }
  7682. ]
  7683. },
  7684. directionalLight: {
  7685. name: 'directionalLight',
  7686. class: 'p5',
  7687. module: 'Lights, Camera',
  7688. overloads: [
  7689. {
  7690. params: [
  7691. {
  7692. name: 'v1',
  7693. description:
  7694. '<p>red or hue value (depending on the current\ncolor mode),</p>\n',
  7695. type: 'Number'
  7696. },
  7697. {
  7698. name: 'v2',
  7699. description: '<p>green or saturation value</p>\n',
  7700. type: 'Number'
  7701. },
  7702. {
  7703. name: 'v3',
  7704. description: '<p>blue or brightness value</p>\n',
  7705. type: 'Number'
  7706. },
  7707. {
  7708. name: 'position',
  7709. description: '<p>the direction of the light</p>\n',
  7710. type: 'p5.Vector'
  7711. }
  7712. ],
  7713. chainable: 1
  7714. },
  7715. {
  7716. params: [
  7717. {
  7718. name: 'color',
  7719. description:
  7720. '<p>color Array, CSS color string,\n or <a href="#/p5.Color">p5.Color</a> value</p>\n',
  7721. type: 'Number[]|String|p5.Color'
  7722. },
  7723. {
  7724. name: 'x',
  7725. description: '<p>x axis direction</p>\n',
  7726. type: 'Number'
  7727. },
  7728. {
  7729. name: 'y',
  7730. description: '<p>y axis direction</p>\n',
  7731. type: 'Number'
  7732. },
  7733. {
  7734. name: 'z',
  7735. description: '<p>z axis direction</p>\n',
  7736. type: 'Number'
  7737. }
  7738. ],
  7739. chainable: 1
  7740. },
  7741. {
  7742. params: [
  7743. {
  7744. name: 'color',
  7745. description: '',
  7746. type: 'Number[]|String|p5.Color'
  7747. },
  7748. {
  7749. name: 'position',
  7750. description: '',
  7751. type: 'p5.Vector'
  7752. }
  7753. ],
  7754. chainable: 1
  7755. },
  7756. {
  7757. params: [
  7758. {
  7759. name: 'v1',
  7760. description: '',
  7761. type: 'Number'
  7762. },
  7763. {
  7764. name: 'v2',
  7765. description: '',
  7766. type: 'Number'
  7767. },
  7768. {
  7769. name: 'v3',
  7770. description: '',
  7771. type: 'Number'
  7772. },
  7773. {
  7774. name: 'x',
  7775. description: '',
  7776. type: 'Number'
  7777. },
  7778. {
  7779. name: 'y',
  7780. description: '',
  7781. type: 'Number'
  7782. },
  7783. {
  7784. name: 'z',
  7785. description: '',
  7786. type: 'Number'
  7787. }
  7788. ],
  7789. chainable: 1
  7790. }
  7791. ]
  7792. },
  7793. pointLight: {
  7794. name: 'pointLight',
  7795. class: 'p5',
  7796. module: 'Lights, Camera',
  7797. overloads: [
  7798. {
  7799. params: [
  7800. {
  7801. name: 'v1',
  7802. description:
  7803. '<p>red or hue value (depending on the current\ncolor mode),</p>\n',
  7804. type: 'Number'
  7805. },
  7806. {
  7807. name: 'v2',
  7808. description: '<p>green or saturation value</p>\n',
  7809. type: 'Number'
  7810. },
  7811. {
  7812. name: 'v3',
  7813. description: '<p>blue or brightness value</p>\n',
  7814. type: 'Number'
  7815. },
  7816. {
  7817. name: 'x',
  7818. description: '<p>x axis position</p>\n',
  7819. type: 'Number'
  7820. },
  7821. {
  7822. name: 'y',
  7823. description: '<p>y axis position</p>\n',
  7824. type: 'Number'
  7825. },
  7826. {
  7827. name: 'z',
  7828. description: '<p>z axis position</p>\n',
  7829. type: 'Number'
  7830. }
  7831. ],
  7832. chainable: 1
  7833. },
  7834. {
  7835. params: [
  7836. {
  7837. name: 'v1',
  7838. description: '',
  7839. type: 'Number'
  7840. },
  7841. {
  7842. name: 'v2',
  7843. description: '',
  7844. type: 'Number'
  7845. },
  7846. {
  7847. name: 'v3',
  7848. description: '',
  7849. type: 'Number'
  7850. },
  7851. {
  7852. name: 'position',
  7853. description: '<p>the position of the light</p>\n',
  7854. type: 'p5.Vector'
  7855. }
  7856. ],
  7857. chainable: 1
  7858. },
  7859. {
  7860. params: [
  7861. {
  7862. name: 'color',
  7863. description:
  7864. '<p>color Array, CSS color string,\nor <a href="#/p5.Color">p5.Color</a> value</p>\n',
  7865. type: 'Number[]|String|p5.Color'
  7866. },
  7867. {
  7868. name: 'x',
  7869. description: '',
  7870. type: 'Number'
  7871. },
  7872. {
  7873. name: 'y',
  7874. description: '',
  7875. type: 'Number'
  7876. },
  7877. {
  7878. name: 'z',
  7879. description: '',
  7880. type: 'Number'
  7881. }
  7882. ],
  7883. chainable: 1
  7884. },
  7885. {
  7886. params: [
  7887. {
  7888. name: 'color',
  7889. description: '',
  7890. type: 'Number[]|String|p5.Color'
  7891. },
  7892. {
  7893. name: 'position',
  7894. description: '',
  7895. type: 'p5.Vector'
  7896. }
  7897. ],
  7898. chainable: 1
  7899. }
  7900. ]
  7901. },
  7902. lights: {
  7903. name: 'lights',
  7904. class: 'p5',
  7905. module: 'Lights, Camera'
  7906. },
  7907. lightFalloff: {
  7908. name: 'lightFalloff',
  7909. params: [
  7910. {
  7911. name: 'constant',
  7912. description: '<p>constant value for determining falloff</p>\n',
  7913. type: 'Number'
  7914. },
  7915. {
  7916. name: 'linear',
  7917. description: '<p>linear value for determining falloff</p>\n',
  7918. type: 'Number'
  7919. },
  7920. {
  7921. name: 'quadratic',
  7922. description: '<p>quadratic value for determining falloff</p>\n',
  7923. type: 'Number'
  7924. }
  7925. ],
  7926. class: 'p5',
  7927. module: 'Lights, Camera'
  7928. },
  7929. spotLight: {
  7930. name: 'spotLight',
  7931. class: 'p5',
  7932. module: 'Lights, Camera',
  7933. overloads: [
  7934. {
  7935. params: [
  7936. {
  7937. name: 'v1',
  7938. description:
  7939. '<p>red or hue value (depending on the current\ncolor mode),</p>\n',
  7940. type: 'Number'
  7941. },
  7942. {
  7943. name: 'v2',
  7944. description: '<p>green or saturation value</p>\n',
  7945. type: 'Number'
  7946. },
  7947. {
  7948. name: 'v3',
  7949. description: '<p>blue or brightness value</p>\n',
  7950. type: 'Number'
  7951. },
  7952. {
  7953. name: 'x',
  7954. description: '<p>x axis position</p>\n',
  7955. type: 'Number'
  7956. },
  7957. {
  7958. name: 'y',
  7959. description: '<p>y axis position</p>\n',
  7960. type: 'Number'
  7961. },
  7962. {
  7963. name: 'z',
  7964. description: '<p>z axis position</p>\n',
  7965. type: 'Number'
  7966. },
  7967. {
  7968. name: 'rx',
  7969. description: '<p>x axis direction of light</p>\n',
  7970. type: 'Number'
  7971. },
  7972. {
  7973. name: 'ry',
  7974. description: '<p>y axis direction of light</p>\n',
  7975. type: 'Number'
  7976. },
  7977. {
  7978. name: 'rz',
  7979. description: '<p>z axis direction of light</p>\n',
  7980. type: 'Number'
  7981. },
  7982. {
  7983. name: 'angle',
  7984. description:
  7985. '<p>optional parameter for angle. Defaults to PI/3</p>\n',
  7986. type: 'Number',
  7987. optional: true
  7988. },
  7989. {
  7990. name: 'conc',
  7991. description:
  7992. '<p>optional parameter for concentration. Defaults to 100</p>\n',
  7993. type: 'Number',
  7994. optional: true
  7995. }
  7996. ],
  7997. chainable: 1
  7998. },
  7999. {
  8000. params: [
  8001. {
  8002. name: 'color',
  8003. description:
  8004. '<p>color Array, CSS color string,\nor <a href="#/p5.Color">p5.Color</a> value</p>\n',
  8005. type: 'Number[]|String|p5.Color'
  8006. },
  8007. {
  8008. name: 'position',
  8009. description: '<p>the position of the light</p>\n',
  8010. type: 'p5.Vector'
  8011. },
  8012. {
  8013. name: 'direction',
  8014. description: '<p>the direction of the light</p>\n',
  8015. type: 'p5.Vector'
  8016. },
  8017. {
  8018. name: 'angle',
  8019. description: '',
  8020. type: 'Number',
  8021. optional: true
  8022. },
  8023. {
  8024. name: 'conc',
  8025. description: '',
  8026. type: 'Number',
  8027. optional: true
  8028. }
  8029. ]
  8030. },
  8031. {
  8032. params: [
  8033. {
  8034. name: 'v1',
  8035. description: '',
  8036. type: 'Number'
  8037. },
  8038. {
  8039. name: 'v2',
  8040. description: '',
  8041. type: 'Number'
  8042. },
  8043. {
  8044. name: 'v3',
  8045. description: '',
  8046. type: 'Number'
  8047. },
  8048. {
  8049. name: 'position',
  8050. description: '',
  8051. type: 'p5.Vector'
  8052. },
  8053. {
  8054. name: 'direction',
  8055. description: '',
  8056. type: 'p5.Vector'
  8057. },
  8058. {
  8059. name: 'angle',
  8060. description: '',
  8061. type: 'Number',
  8062. optional: true
  8063. },
  8064. {
  8065. name: 'conc',
  8066. description: '',
  8067. type: 'Number',
  8068. optional: true
  8069. }
  8070. ]
  8071. },
  8072. {
  8073. params: [
  8074. {
  8075. name: 'color',
  8076. description: '',
  8077. type: 'Number[]|String|p5.Color'
  8078. },
  8079. {
  8080. name: 'x',
  8081. description: '',
  8082. type: 'Number'
  8083. },
  8084. {
  8085. name: 'y',
  8086. description: '',
  8087. type: 'Number'
  8088. },
  8089. {
  8090. name: 'z',
  8091. description: '',
  8092. type: 'Number'
  8093. },
  8094. {
  8095. name: 'direction',
  8096. description: '',
  8097. type: 'p5.Vector'
  8098. },
  8099. {
  8100. name: 'angle',
  8101. description: '',
  8102. type: 'Number',
  8103. optional: true
  8104. },
  8105. {
  8106. name: 'conc',
  8107. description: '',
  8108. type: 'Number',
  8109. optional: true
  8110. }
  8111. ]
  8112. },
  8113. {
  8114. params: [
  8115. {
  8116. name: 'color',
  8117. description: '',
  8118. type: 'Number[]|String|p5.Color'
  8119. },
  8120. {
  8121. name: 'position',
  8122. description: '',
  8123. type: 'p5.Vector'
  8124. },
  8125. {
  8126. name: 'rx',
  8127. description: '',
  8128. type: 'Number'
  8129. },
  8130. {
  8131. name: 'ry',
  8132. description: '',
  8133. type: 'Number'
  8134. },
  8135. {
  8136. name: 'rz',
  8137. description: '',
  8138. type: 'Number'
  8139. },
  8140. {
  8141. name: 'angle',
  8142. description: '',
  8143. type: 'Number',
  8144. optional: true
  8145. },
  8146. {
  8147. name: 'conc',
  8148. description: '',
  8149. type: 'Number',
  8150. optional: true
  8151. }
  8152. ]
  8153. },
  8154. {
  8155. params: [
  8156. {
  8157. name: 'v1',
  8158. description: '',
  8159. type: 'Number'
  8160. },
  8161. {
  8162. name: 'v2',
  8163. description: '',
  8164. type: 'Number'
  8165. },
  8166. {
  8167. name: 'v3',
  8168. description: '',
  8169. type: 'Number'
  8170. },
  8171. {
  8172. name: 'x',
  8173. description: '',
  8174. type: 'Number'
  8175. },
  8176. {
  8177. name: 'y',
  8178. description: '',
  8179. type: 'Number'
  8180. },
  8181. {
  8182. name: 'z',
  8183. description: '',
  8184. type: 'Number'
  8185. },
  8186. {
  8187. name: 'direction',
  8188. description: '',
  8189. type: 'p5.Vector'
  8190. },
  8191. {
  8192. name: 'angle',
  8193. description: '',
  8194. type: 'Number',
  8195. optional: true
  8196. },
  8197. {
  8198. name: 'conc',
  8199. description: '',
  8200. type: 'Number',
  8201. optional: true
  8202. }
  8203. ]
  8204. },
  8205. {
  8206. params: [
  8207. {
  8208. name: 'v1',
  8209. description: '',
  8210. type: 'Number'
  8211. },
  8212. {
  8213. name: 'v2',
  8214. description: '',
  8215. type: 'Number'
  8216. },
  8217. {
  8218. name: 'v3',
  8219. description: '',
  8220. type: 'Number'
  8221. },
  8222. {
  8223. name: 'position',
  8224. description: '',
  8225. type: 'p5.Vector'
  8226. },
  8227. {
  8228. name: 'rx',
  8229. description: '',
  8230. type: 'Number'
  8231. },
  8232. {
  8233. name: 'ry',
  8234. description: '',
  8235. type: 'Number'
  8236. },
  8237. {
  8238. name: 'rz',
  8239. description: '',
  8240. type: 'Number'
  8241. },
  8242. {
  8243. name: 'angle',
  8244. description: '',
  8245. type: 'Number',
  8246. optional: true
  8247. },
  8248. {
  8249. name: 'conc',
  8250. description: '',
  8251. type: 'Number',
  8252. optional: true
  8253. }
  8254. ]
  8255. },
  8256. {
  8257. params: [
  8258. {
  8259. name: 'color',
  8260. description: '',
  8261. type: 'Number[]|String|p5.Color'
  8262. },
  8263. {
  8264. name: 'x',
  8265. description: '',
  8266. type: 'Number'
  8267. },
  8268. {
  8269. name: 'y',
  8270. description: '',
  8271. type: 'Number'
  8272. },
  8273. {
  8274. name: 'z',
  8275. description: '',
  8276. type: 'Number'
  8277. },
  8278. {
  8279. name: 'rx',
  8280. description: '',
  8281. type: 'Number'
  8282. },
  8283. {
  8284. name: 'ry',
  8285. description: '',
  8286. type: 'Number'
  8287. },
  8288. {
  8289. name: 'rz',
  8290. description: '',
  8291. type: 'Number'
  8292. },
  8293. {
  8294. name: 'angle',
  8295. description: '',
  8296. type: 'Number',
  8297. optional: true
  8298. },
  8299. {
  8300. name: 'conc',
  8301. description: '',
  8302. type: 'Number',
  8303. optional: true
  8304. }
  8305. ]
  8306. }
  8307. ]
  8308. },
  8309. noLights: {
  8310. name: 'noLights',
  8311. class: 'p5',
  8312. module: 'Lights, Camera'
  8313. },
  8314. loadModel: {
  8315. name: 'loadModel',
  8316. class: 'p5',
  8317. module: 'Shape',
  8318. overloads: [
  8319. {
  8320. params: [
  8321. {
  8322. name: 'path',
  8323. description: '<p>Path of the model to be loaded</p>\n',
  8324. type: 'String'
  8325. },
  8326. {
  8327. name: 'normalize',
  8328. description:
  8329. '<p>If true, scale the model to a\n standardized size when loading</p>\n',
  8330. type: 'Boolean'
  8331. },
  8332. {
  8333. name: 'successCallback',
  8334. description:
  8335. '<p>Function to be called\n once the model is loaded. Will be passed\n the 3D model object.</p>\n',
  8336. type: 'function(p5.Geometry)',
  8337. optional: true
  8338. },
  8339. {
  8340. name: 'failureCallback',
  8341. description:
  8342. '<p>called with event error if\n the model fails to load.</p>\n',
  8343. type: 'Function(Event)',
  8344. optional: true
  8345. },
  8346. {
  8347. name: 'fileType',
  8348. description:
  8349. '<p>The file extension of the model\n (<code>.stl</code>, <code>.obj</code>).</p>\n',
  8350. type: 'String',
  8351. optional: true
  8352. }
  8353. ]
  8354. },
  8355. {
  8356. params: [
  8357. {
  8358. name: 'path',
  8359. description: '',
  8360. type: 'String'
  8361. },
  8362. {
  8363. name: 'successCallback',
  8364. description: '',
  8365. type: 'function(p5.Geometry)',
  8366. optional: true
  8367. },
  8368. {
  8369. name: 'failureCallback',
  8370. description: '',
  8371. type: 'Function(Event)',
  8372. optional: true
  8373. },
  8374. {
  8375. name: 'fileType',
  8376. description: '',
  8377. type: 'String',
  8378. optional: true
  8379. }
  8380. ]
  8381. }
  8382. ]
  8383. },
  8384. model: {
  8385. name: 'model',
  8386. params: [
  8387. {
  8388. name: 'model',
  8389. description: '<p>Loaded 3d model to be rendered</p>\n',
  8390. type: 'p5.Geometry'
  8391. }
  8392. ],
  8393. class: 'p5',
  8394. module: 'Shape'
  8395. },
  8396. loadShader: {
  8397. name: 'loadShader',
  8398. params: [
  8399. {
  8400. name: 'vertFilename',
  8401. description:
  8402. '<p>path to file containing vertex shader\nsource code</p>\n',
  8403. type: 'String'
  8404. },
  8405. {
  8406. name: 'fragFilename',
  8407. description:
  8408. '<p>path to file containing fragment shader\nsource code</p>\n',
  8409. type: 'String'
  8410. },
  8411. {
  8412. name: 'callback',
  8413. description:
  8414. '<p>callback to be executed after loadShader\ncompletes. On success, the Shader object is passed as the first argument.</p>\n',
  8415. type: 'Function',
  8416. optional: true
  8417. },
  8418. {
  8419. name: 'errorCallback',
  8420. description:
  8421. '<p>callback to be executed when an error\noccurs inside loadShader. On error, the error is passed as the first\nargument.</p>\n',
  8422. type: 'Function',
  8423. optional: true
  8424. }
  8425. ],
  8426. class: 'p5',
  8427. module: 'Lights, Camera'
  8428. },
  8429. createShader: {
  8430. name: 'createShader',
  8431. params: [
  8432. {
  8433. name: 'vertSrc',
  8434. description: '<p>source code for the vertex shader</p>\n',
  8435. type: 'String'
  8436. },
  8437. {
  8438. name: 'fragSrc',
  8439. description: '<p>source code for the fragment shader</p>\n',
  8440. type: 'String'
  8441. }
  8442. ],
  8443. class: 'p5',
  8444. module: 'Lights, Camera'
  8445. },
  8446. shader: {
  8447. name: 'shader',
  8448. params: [
  8449. {
  8450. name: 's',
  8451. description:
  8452. '<p>the desired <a href="#/p5.Shader">p5.Shader</a> to use for rendering\nshapes.</p>\n',
  8453. type: 'p5.Shader',
  8454. optional: true
  8455. }
  8456. ],
  8457. class: 'p5',
  8458. module: 'Lights, Camera'
  8459. },
  8460. resetShader: {
  8461. name: 'resetShader',
  8462. class: 'p5',
  8463. module: 'Lights, Camera'
  8464. },
  8465. texture: {
  8466. name: 'texture',
  8467. params: [
  8468. {
  8469. name: 'tex',
  8470. description:
  8471. '<p>2-dimensional graphics\n to render as texture</p>\n',
  8472. type: 'p5.Image|p5.MediaElement|p5.Graphics'
  8473. }
  8474. ],
  8475. class: 'p5',
  8476. module: 'Lights, Camera'
  8477. },
  8478. textureMode: {
  8479. name: 'textureMode',
  8480. params: [
  8481. {
  8482. name: 'mode',
  8483. description: '<p>either IMAGE or NORMAL</p>\n',
  8484. type: 'Constant'
  8485. }
  8486. ],
  8487. class: 'p5',
  8488. module: 'Lights, Camera'
  8489. },
  8490. textureWrap: {
  8491. name: 'textureWrap',
  8492. params: [
  8493. {
  8494. name: 'wrapX',
  8495. description: '<p>either CLAMP, REPEAT, or MIRROR</p>\n',
  8496. type: 'Constant'
  8497. },
  8498. {
  8499. name: 'wrapY',
  8500. description: '<p>either CLAMP, REPEAT, or MIRROR</p>\n',
  8501. type: 'Constant',
  8502. optional: true
  8503. }
  8504. ],
  8505. class: 'p5',
  8506. module: 'Lights, Camera'
  8507. },
  8508. normalMaterial: {
  8509. name: 'normalMaterial',
  8510. class: 'p5',
  8511. module: 'Lights, Camera'
  8512. },
  8513. ambientMaterial: {
  8514. name: 'ambientMaterial',
  8515. class: 'p5',
  8516. module: 'Lights, Camera',
  8517. overloads: [
  8518. {
  8519. params: [
  8520. {
  8521. name: 'v1',
  8522. description:
  8523. '<p>gray value, red or hue value\n (depending on the current color mode),</p>\n',
  8524. type: 'Number'
  8525. },
  8526. {
  8527. name: 'v2',
  8528. description: '<p>green or saturation value</p>\n',
  8529. type: 'Number',
  8530. optional: true
  8531. },
  8532. {
  8533. name: 'v3',
  8534. description: '<p>blue or brightness value</p>\n',
  8535. type: 'Number',
  8536. optional: true
  8537. }
  8538. ],
  8539. chainable: 1
  8540. },
  8541. {
  8542. params: [
  8543. {
  8544. name: 'color',
  8545. description: '<p>color, color Array, or CSS color string</p>\n',
  8546. type: 'Number[]|String|p5.Color'
  8547. }
  8548. ],
  8549. chainable: 1
  8550. }
  8551. ]
  8552. },
  8553. emissiveMaterial: {
  8554. name: 'emissiveMaterial',
  8555. class: 'p5',
  8556. module: 'Lights, Camera',
  8557. overloads: [
  8558. {
  8559. params: [
  8560. {
  8561. name: 'v1',
  8562. description:
  8563. '<p>gray value, red or hue value\n (depending on the current color mode),</p>\n',
  8564. type: 'Number'
  8565. },
  8566. {
  8567. name: 'v2',
  8568. description: '<p>green or saturation value</p>\n',
  8569. type: 'Number',
  8570. optional: true
  8571. },
  8572. {
  8573. name: 'v3',
  8574. description: '<p>blue or brightness value</p>\n',
  8575. type: 'Number',
  8576. optional: true
  8577. },
  8578. {
  8579. name: 'a',
  8580. description: '<p>opacity</p>\n',
  8581. type: 'Number',
  8582. optional: true
  8583. }
  8584. ],
  8585. chainable: 1
  8586. },
  8587. {
  8588. params: [
  8589. {
  8590. name: 'color',
  8591. description: '<p>color, color Array, or CSS color string</p>\n',
  8592. type: 'Number[]|String|p5.Color'
  8593. }
  8594. ],
  8595. chainable: 1
  8596. }
  8597. ]
  8598. },
  8599. specularMaterial: {
  8600. name: 'specularMaterial',
  8601. class: 'p5',
  8602. module: 'Lights, Camera',
  8603. overloads: [
  8604. {
  8605. params: [
  8606. {
  8607. name: 'gray',
  8608. description:
  8609. '<p>number specifying value between white and black.</p>\n',
  8610. type: 'Number'
  8611. },
  8612. {
  8613. name: 'alpha',
  8614. description:
  8615. '<p>alpha value relative to current color range\n (default is 0-255)</p>\n',
  8616. type: 'Number',
  8617. optional: true
  8618. }
  8619. ],
  8620. chainable: 1
  8621. },
  8622. {
  8623. params: [
  8624. {
  8625. name: 'v1',
  8626. description:
  8627. '<p>red or hue value relative to\n the current color range</p>\n',
  8628. type: 'Number'
  8629. },
  8630. {
  8631. name: 'v2',
  8632. description:
  8633. '<p>green or saturation value\n relative to the current color range</p>\n',
  8634. type: 'Number'
  8635. },
  8636. {
  8637. name: 'v3',
  8638. description:
  8639. '<p>blue or brightness value\n relative to the current color range</p>\n',
  8640. type: 'Number'
  8641. },
  8642. {
  8643. name: 'alpha',
  8644. description: '',
  8645. type: 'Number',
  8646. optional: true
  8647. }
  8648. ],
  8649. chainable: 1
  8650. },
  8651. {
  8652. params: [
  8653. {
  8654. name: 'color',
  8655. description: '<p>color Array, or CSS color string</p>\n',
  8656. type: 'Number[]|String|p5.Color'
  8657. }
  8658. ],
  8659. chainable: 1
  8660. }
  8661. ]
  8662. },
  8663. shininess: {
  8664. name: 'shininess',
  8665. params: [
  8666. {
  8667. name: 'shine',
  8668. description:
  8669. '<p>Degree of Shininess.\n Defaults to 1.</p>\n',
  8670. type: 'Number'
  8671. }
  8672. ],
  8673. class: 'p5',
  8674. module: 'Lights, Camera'
  8675. },
  8676. camera: {
  8677. name: 'camera',
  8678. params: [
  8679. {
  8680. name: 'x',
  8681. description: '<p>camera position value on x axis</p>\n',
  8682. type: 'Number',
  8683. optional: true
  8684. },
  8685. {
  8686. name: 'y',
  8687. description: '<p>camera position value on y axis</p>\n',
  8688. type: 'Number',
  8689. optional: true
  8690. },
  8691. {
  8692. name: 'z',
  8693. description: '<p>camera position value on z axis</p>\n',
  8694. type: 'Number',
  8695. optional: true
  8696. },
  8697. {
  8698. name: 'centerX',
  8699. description: '<p>x coordinate representing center of the sketch</p>\n',
  8700. type: 'Number',
  8701. optional: true
  8702. },
  8703. {
  8704. name: 'centerY',
  8705. description: '<p>y coordinate representing center of the sketch</p>\n',
  8706. type: 'Number',
  8707. optional: true
  8708. },
  8709. {
  8710. name: 'centerZ',
  8711. description: '<p>z coordinate representing center of the sketch</p>\n',
  8712. type: 'Number',
  8713. optional: true
  8714. },
  8715. {
  8716. name: 'upX',
  8717. description: "<p>x component of direction 'up' from camera</p>\n",
  8718. type: 'Number',
  8719. optional: true
  8720. },
  8721. {
  8722. name: 'upY',
  8723. description: "<p>y component of direction 'up' from camera</p>\n",
  8724. type: 'Number',
  8725. optional: true
  8726. },
  8727. {
  8728. name: 'upZ',
  8729. description: "<p>z component of direction 'up' from camera</p>\n",
  8730. type: 'Number',
  8731. optional: true
  8732. }
  8733. ],
  8734. class: 'p5',
  8735. module: 'Lights, Camera'
  8736. },
  8737. perspective: {
  8738. name: 'perspective',
  8739. params: [
  8740. {
  8741. name: 'fovy',
  8742. description:
  8743. '<p>camera frustum vertical field of view,\n from bottom to top of view, in <a href="#/p5/angleMode">angleMode</a> units</p>\n',
  8744. type: 'Number',
  8745. optional: true
  8746. },
  8747. {
  8748. name: 'aspect',
  8749. description: '<p>camera frustum aspect ratio</p>\n',
  8750. type: 'Number',
  8751. optional: true
  8752. },
  8753. {
  8754. name: 'near',
  8755. description: '<p>frustum near plane length</p>\n',
  8756. type: 'Number',
  8757. optional: true
  8758. },
  8759. {
  8760. name: 'far',
  8761. description: '<p>frustum far plane length</p>\n',
  8762. type: 'Number',
  8763. optional: true
  8764. }
  8765. ],
  8766. class: 'p5',
  8767. module: 'Lights, Camera'
  8768. },
  8769. ortho: {
  8770. name: 'ortho',
  8771. params: [
  8772. {
  8773. name: 'left',
  8774. description: '<p>camera frustum left plane</p>\n',
  8775. type: 'Number',
  8776. optional: true
  8777. },
  8778. {
  8779. name: 'right',
  8780. description: '<p>camera frustum right plane</p>\n',
  8781. type: 'Number',
  8782. optional: true
  8783. },
  8784. {
  8785. name: 'bottom',
  8786. description: '<p>camera frustum bottom plane</p>\n',
  8787. type: 'Number',
  8788. optional: true
  8789. },
  8790. {
  8791. name: 'top',
  8792. description: '<p>camera frustum top plane</p>\n',
  8793. type: 'Number',
  8794. optional: true
  8795. },
  8796. {
  8797. name: 'near',
  8798. description: '<p>camera frustum near plane</p>\n',
  8799. type: 'Number',
  8800. optional: true
  8801. },
  8802. {
  8803. name: 'far',
  8804. description: '<p>camera frustum far plane</p>\n',
  8805. type: 'Number',
  8806. optional: true
  8807. }
  8808. ],
  8809. class: 'p5',
  8810. module: 'Lights, Camera'
  8811. },
  8812. frustum: {
  8813. name: 'frustum',
  8814. params: [
  8815. {
  8816. name: 'left',
  8817. description: '<p>camera frustum left plane</p>\n',
  8818. type: 'Number',
  8819. optional: true
  8820. },
  8821. {
  8822. name: 'right',
  8823. description: '<p>camera frustum right plane</p>\n',
  8824. type: 'Number',
  8825. optional: true
  8826. },
  8827. {
  8828. name: 'bottom',
  8829. description: '<p>camera frustum bottom plane</p>\n',
  8830. type: 'Number',
  8831. optional: true
  8832. },
  8833. {
  8834. name: 'top',
  8835. description: '<p>camera frustum top plane</p>\n',
  8836. type: 'Number',
  8837. optional: true
  8838. },
  8839. {
  8840. name: 'near',
  8841. description: '<p>camera frustum near plane</p>\n',
  8842. type: 'Number',
  8843. optional: true
  8844. },
  8845. {
  8846. name: 'far',
  8847. description: '<p>camera frustum far plane</p>\n',
  8848. type: 'Number',
  8849. optional: true
  8850. }
  8851. ],
  8852. class: 'p5',
  8853. module: 'Lights, Camera'
  8854. },
  8855. createCamera: {
  8856. name: 'createCamera',
  8857. class: 'p5',
  8858. module: 'Lights, Camera'
  8859. },
  8860. setCamera: {
  8861. name: 'setCamera',
  8862. params: [
  8863. {
  8864. name: 'cam',
  8865. description: '<p>p5.Camera object</p>\n',
  8866. type: 'p5.Camera'
  8867. }
  8868. ],
  8869. class: 'p5',
  8870. module: 'Lights, Camera'
  8871. },
  8872. setAttributes: {
  8873. name: 'setAttributes',
  8874. class: 'p5',
  8875. module: 'Rendering',
  8876. overloads: [
  8877. {
  8878. params: [
  8879. {
  8880. name: 'key',
  8881. description: '<p>Name of attribute</p>\n',
  8882. type: 'String'
  8883. },
  8884. {
  8885. name: 'value',
  8886. description: '<p>New value of named attribute</p>\n',
  8887. type: 'Boolean'
  8888. }
  8889. ]
  8890. },
  8891. {
  8892. params: [
  8893. {
  8894. name: 'obj',
  8895. description: '<p>object with key-value pairs</p>\n',
  8896. type: 'Object'
  8897. }
  8898. ]
  8899. }
  8900. ]
  8901. },
  8902. getAudioContext: {
  8903. name: 'getAudioContext',
  8904. class: 'p5',
  8905. module: 'p5.sound'
  8906. },
  8907. userStartAudio: {
  8908. params: [
  8909. {
  8910. name: 'element(s)',
  8911. description:
  8912. '<p>This argument can be an Element,\n Selector String, NodeList, p5.Element,\n jQuery Element, or an Array of any of those.</p>\n',
  8913. type: 'Element|Array',
  8914. optional: true
  8915. },
  8916. {
  8917. name: 'callback',
  8918. description:
  8919. '<p>Callback to invoke when the AudioContext\n has started</p>\n',
  8920. type: 'Function',
  8921. optional: true
  8922. }
  8923. ],
  8924. name: 'userStartAudio',
  8925. class: 'p5',
  8926. module: 'p5.sound'
  8927. },
  8928. getOutputVolume: {
  8929. name: 'getOutputVolume',
  8930. class: 'p5',
  8931. module: 'p5.sound'
  8932. },
  8933. outputVolume: {
  8934. name: 'outputVolume',
  8935. params: [
  8936. {
  8937. name: 'volume',
  8938. description:
  8939. '<p>Volume (amplitude) between 0.0\n and 1.0 or modulating signal/oscillator</p>\n',
  8940. type: 'Number|Object'
  8941. },
  8942. {
  8943. name: 'rampTime',
  8944. description: '<p>Fade for t seconds</p>\n',
  8945. type: 'Number',
  8946. optional: true
  8947. },
  8948. {
  8949. name: 'timeFromNow',
  8950. description:
  8951. '<p>Schedule this event to happen at\n t seconds in the future</p>\n',
  8952. type: 'Number',
  8953. optional: true
  8954. }
  8955. ],
  8956. class: 'p5',
  8957. module: 'p5.sound'
  8958. },
  8959. soundOut: {
  8960. name: 'soundOut',
  8961. class: 'p5',
  8962. module: 'p5.sound'
  8963. },
  8964. sampleRate: {
  8965. name: 'sampleRate',
  8966. class: 'p5',
  8967. module: 'p5.sound'
  8968. },
  8969. freqToMidi: {
  8970. name: 'freqToMidi',
  8971. params: [
  8972. {
  8973. name: 'frequency',
  8974. description:
  8975. '<p>A freqeuncy, for example, the "A"\n above Middle C is 440Hz</p>\n',
  8976. type: 'Number'
  8977. }
  8978. ],
  8979. class: 'p5',
  8980. module: 'p5.sound'
  8981. },
  8982. midiToFreq: {
  8983. name: 'midiToFreq',
  8984. params: [
  8985. {
  8986. name: 'midiNote',
  8987. description: '<p>The number of a MIDI note</p>\n',
  8988. type: 'Number'
  8989. }
  8990. ],
  8991. class: 'p5',
  8992. module: 'p5.sound'
  8993. },
  8994. soundFormats: {
  8995. name: 'soundFormats',
  8996. params: [
  8997. {
  8998. name: 'formats',
  8999. description: "<p>i.e. 'mp3', 'wav', 'ogg'</p>\n",
  9000. type: 'String',
  9001. optional: true,
  9002. multiple: true
  9003. }
  9004. ],
  9005. class: 'p5',
  9006. module: 'p5.sound'
  9007. },
  9008. saveSound: {
  9009. name: 'saveSound',
  9010. params: [
  9011. {
  9012. name: 'soundFile',
  9013. description: '<p>p5.SoundFile that you wish to save</p>\n',
  9014. type: 'p5.SoundFile'
  9015. },
  9016. {
  9017. name: 'fileName',
  9018. description: '<p>name of the resulting .wav file.</p>\n',
  9019. type: 'String'
  9020. }
  9021. ],
  9022. class: 'p5',
  9023. module: 'p5.sound'
  9024. },
  9025. loadSound: {
  9026. name: 'loadSound',
  9027. params: [
  9028. {
  9029. name: 'path',
  9030. description:
  9031. "<p>Path to the sound file, or an array with\n paths to soundfiles in multiple formats\n i.e. ['sound.ogg', 'sound.mp3'].\n Alternately, accepts an object: either\n from the HTML5 File API, or a p5.File.</p>\n",
  9032. type: 'String|Array'
  9033. },
  9034. {
  9035. name: 'successCallback',
  9036. description: '<p>Name of a function to call once file loads</p>\n',
  9037. type: 'Function',
  9038. optional: true
  9039. },
  9040. {
  9041. name: 'errorCallback',
  9042. description:
  9043. '<p>Name of a function to call if there is\n an error loading the file.</p>\n',
  9044. type: 'Function',
  9045. optional: true
  9046. },
  9047. {
  9048. name: 'whileLoading',
  9049. description:
  9050. '<p>Name of a function to call while file is loading.\n This function will receive the percentage loaded\n so far, from 0.0 to 1.0.</p>\n',
  9051. type: 'Function',
  9052. optional: true
  9053. }
  9054. ],
  9055. class: 'p5',
  9056. module: 'p5.sound'
  9057. },
  9058. createConvolver: {
  9059. name: 'createConvolver',
  9060. params: [
  9061. {
  9062. name: 'path',
  9063. description: '<p>path to a sound file</p>\n',
  9064. type: 'String'
  9065. },
  9066. {
  9067. name: 'callback',
  9068. description:
  9069. '<p>function to call if loading is successful.\n The object will be passed in as the argument\n to the callback function.</p>\n',
  9070. type: 'Function',
  9071. optional: true
  9072. },
  9073. {
  9074. name: 'errorCallback',
  9075. description:
  9076. '<p>function to call if loading is not successful.\n A custom error will be passed in as the argument\n to the callback function.</p>\n',
  9077. type: 'Function',
  9078. optional: true
  9079. }
  9080. ],
  9081. class: 'p5',
  9082. module: 'p5.sound'
  9083. },
  9084. setBPM: {
  9085. name: 'setBPM',
  9086. params: [
  9087. {
  9088. name: 'BPM',
  9089. description: '<p>Beats Per Minute</p>\n',
  9090. type: 'Number'
  9091. },
  9092. {
  9093. name: 'rampTime',
  9094. description: '<p>Seconds from now</p>\n',
  9095. type: 'Number'
  9096. }
  9097. ],
  9098. class: 'p5',
  9099. module: 'p5.sound'
  9100. }
  9101. },
  9102. 'p5.Color': {
  9103. toString: {
  9104. name: 'toString',
  9105. params: [
  9106. {
  9107. name: 'format',
  9108. description:
  9109. "<p>How the color string will be formatted.\nLeaving this empty formats the string as rgba(r, g, b, a).\n'#rgb' '#rgba' '#rrggbb' and '#rrggbbaa' format as hexadecimal color codes.\n'rgb' 'hsb' and 'hsl' return the color formatted in the specified color mode.\n'rgba' 'hsba' and 'hsla' are the same as above but with alpha channels.\n'rgb%' 'hsb%' 'hsl%' 'rgba%' 'hsba%' and 'hsla%' format as percentages.</p>\n",
  9110. type: 'String',
  9111. optional: true
  9112. }
  9113. ],
  9114. class: 'p5.Color',
  9115. module: 'Color'
  9116. },
  9117. setRed: {
  9118. name: 'setRed',
  9119. params: [
  9120. {
  9121. name: 'red',
  9122. description: '<p>the new red value</p>\n',
  9123. type: 'Number'
  9124. }
  9125. ],
  9126. class: 'p5.Color',
  9127. module: 'Color'
  9128. },
  9129. setGreen: {
  9130. name: 'setGreen',
  9131. params: [
  9132. {
  9133. name: 'green',
  9134. description: '<p>the new green value</p>\n',
  9135. type: 'Number'
  9136. }
  9137. ],
  9138. class: 'p5.Color',
  9139. module: 'Color'
  9140. },
  9141. setBlue: {
  9142. name: 'setBlue',
  9143. params: [
  9144. {
  9145. name: 'blue',
  9146. description: '<p>the new blue value</p>\n',
  9147. type: 'Number'
  9148. }
  9149. ],
  9150. class: 'p5.Color',
  9151. module: 'Color'
  9152. },
  9153. setAlpha: {
  9154. name: 'setAlpha',
  9155. params: [
  9156. {
  9157. name: 'alpha',
  9158. description: '<p>the new alpha value</p>\n',
  9159. type: 'Number'
  9160. }
  9161. ],
  9162. class: 'p5.Color',
  9163. module: 'Color'
  9164. }
  9165. },
  9166. 'p5.Element': {
  9167. elt: {
  9168. name: 'elt',
  9169. class: 'p5.Element',
  9170. module: 'DOM'
  9171. },
  9172. parent: {
  9173. name: 'parent',
  9174. class: 'p5.Element',
  9175. module: 'DOM',
  9176. overloads: [
  9177. {
  9178. params: [
  9179. {
  9180. name: 'parent',
  9181. description:
  9182. '<p>the ID, DOM node, or <a href="#/p5.Element">p5.Element</a>\n of desired parent element</p>\n',
  9183. type: 'String|p5.Element|Object'
  9184. }
  9185. ],
  9186. chainable: 1
  9187. },
  9188. {
  9189. params: []
  9190. }
  9191. ]
  9192. },
  9193. id: {
  9194. name: 'id',
  9195. class: 'p5.Element',
  9196. module: 'DOM',
  9197. overloads: [
  9198. {
  9199. params: [
  9200. {
  9201. name: 'id',
  9202. description: '<p>ID of the element</p>\n',
  9203. type: 'String'
  9204. }
  9205. ],
  9206. chainable: 1
  9207. },
  9208. {
  9209. params: []
  9210. }
  9211. ]
  9212. },
  9213. class: {
  9214. name: 'class',
  9215. class: 'p5.Element',
  9216. module: 'DOM',
  9217. overloads: [
  9218. {
  9219. params: [
  9220. {
  9221. name: 'class',
  9222. description: '<p>class to add</p>\n',
  9223. type: 'String'
  9224. }
  9225. ],
  9226. chainable: 1
  9227. },
  9228. {
  9229. params: []
  9230. }
  9231. ]
  9232. },
  9233. mousePressed: {
  9234. name: 'mousePressed',
  9235. params: [
  9236. {
  9237. name: 'fxn',
  9238. description:
  9239. '<p>function to be fired when mouse is\n pressed over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  9240. type: 'Function|Boolean'
  9241. }
  9242. ],
  9243. class: 'p5.Element',
  9244. module: 'DOM'
  9245. },
  9246. doubleClicked: {
  9247. name: 'doubleClicked',
  9248. params: [
  9249. {
  9250. name: 'fxn',
  9251. description:
  9252. '<p>function to be fired when mouse is\n double clicked over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  9253. type: 'Function|Boolean'
  9254. }
  9255. ],
  9256. class: 'p5.Element',
  9257. module: 'DOM'
  9258. },
  9259. mouseWheel: {
  9260. name: 'mouseWheel',
  9261. params: [
  9262. {
  9263. name: 'fxn',
  9264. description:
  9265. '<p>function to be fired when mouse is\n scrolled over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  9266. type: 'Function|Boolean'
  9267. }
  9268. ],
  9269. class: 'p5.Element',
  9270. module: 'DOM'
  9271. },
  9272. mouseReleased: {
  9273. name: 'mouseReleased',
  9274. params: [
  9275. {
  9276. name: 'fxn',
  9277. description:
  9278. '<p>function to be fired when mouse is\n released over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  9279. type: 'Function|Boolean'
  9280. }
  9281. ],
  9282. class: 'p5.Element',
  9283. module: 'DOM'
  9284. },
  9285. mouseClicked: {
  9286. name: 'mouseClicked',
  9287. params: [
  9288. {
  9289. name: 'fxn',
  9290. description:
  9291. '<p>function to be fired when mouse is\n clicked over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  9292. type: 'Function|Boolean'
  9293. }
  9294. ],
  9295. class: 'p5.Element',
  9296. module: 'DOM'
  9297. },
  9298. mouseMoved: {
  9299. name: 'mouseMoved',
  9300. params: [
  9301. {
  9302. name: 'fxn',
  9303. description:
  9304. '<p>function to be fired when a mouse moves\n over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  9305. type: 'Function|Boolean'
  9306. }
  9307. ],
  9308. class: 'p5.Element',
  9309. module: 'DOM'
  9310. },
  9311. mouseOver: {
  9312. name: 'mouseOver',
  9313. params: [
  9314. {
  9315. name: 'fxn',
  9316. description:
  9317. '<p>function to be fired when a mouse moves\n onto the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  9318. type: 'Function|Boolean'
  9319. }
  9320. ],
  9321. class: 'p5.Element',
  9322. module: 'DOM'
  9323. },
  9324. mouseOut: {
  9325. name: 'mouseOut',
  9326. params: [
  9327. {
  9328. name: 'fxn',
  9329. description:
  9330. '<p>function to be fired when a mouse\n moves off of an element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  9331. type: 'Function|Boolean'
  9332. }
  9333. ],
  9334. class: 'p5.Element',
  9335. module: 'DOM'
  9336. },
  9337. touchStarted: {
  9338. name: 'touchStarted',
  9339. params: [
  9340. {
  9341. name: 'fxn',
  9342. description:
  9343. '<p>function to be fired when a touch\n starts over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  9344. type: 'Function|Boolean'
  9345. }
  9346. ],
  9347. class: 'p5.Element',
  9348. module: 'DOM'
  9349. },
  9350. touchMoved: {
  9351. name: 'touchMoved',
  9352. params: [
  9353. {
  9354. name: 'fxn',
  9355. description:
  9356. '<p>function to be fired when a touch moves over\n the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  9357. type: 'Function|Boolean'
  9358. }
  9359. ],
  9360. class: 'p5.Element',
  9361. module: 'DOM'
  9362. },
  9363. touchEnded: {
  9364. name: 'touchEnded',
  9365. params: [
  9366. {
  9367. name: 'fxn',
  9368. description:
  9369. '<p>function to be fired when a touch ends\n over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  9370. type: 'Function|Boolean'
  9371. }
  9372. ],
  9373. class: 'p5.Element',
  9374. module: 'DOM'
  9375. },
  9376. dragOver: {
  9377. name: 'dragOver',
  9378. params: [
  9379. {
  9380. name: 'fxn',
  9381. description:
  9382. '<p>function to be fired when a file is\n dragged over the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  9383. type: 'Function|Boolean'
  9384. }
  9385. ],
  9386. class: 'p5.Element',
  9387. module: 'DOM'
  9388. },
  9389. dragLeave: {
  9390. name: 'dragLeave',
  9391. params: [
  9392. {
  9393. name: 'fxn',
  9394. description:
  9395. '<p>function to be fired when a file is\n dragged off the element.\n if <code>false</code> is passed instead, the previously\n firing function will no longer fire.</p>\n',
  9396. type: 'Function|Boolean'
  9397. }
  9398. ],
  9399. class: 'p5.Element',
  9400. module: 'DOM'
  9401. },
  9402. addClass: {
  9403. name: 'addClass',
  9404. params: [
  9405. {
  9406. name: 'class',
  9407. description: '<p>name of class to add</p>\n',
  9408. type: 'String'
  9409. }
  9410. ],
  9411. class: 'p5.Element',
  9412. module: 'DOM'
  9413. },
  9414. removeClass: {
  9415. name: 'removeClass',
  9416. params: [
  9417. {
  9418. name: 'class',
  9419. description: '<p>name of class to remove</p>\n',
  9420. type: 'String'
  9421. }
  9422. ],
  9423. class: 'p5.Element',
  9424. module: 'DOM'
  9425. },
  9426. hasClass: {
  9427. name: 'hasClass',
  9428. params: [
  9429. {
  9430. name: 'c',
  9431. description: '<p>class name of class to check</p>\n',
  9432. type: 'String'
  9433. }
  9434. ],
  9435. class: 'p5.Element',
  9436. module: 'DOM'
  9437. },
  9438. toggleClass: {
  9439. name: 'toggleClass',
  9440. params: [
  9441. {
  9442. name: 'c',
  9443. description: '<p>class name to toggle</p>\n',
  9444. type: 'String'
  9445. }
  9446. ],
  9447. class: 'p5.Element',
  9448. module: 'DOM'
  9449. },
  9450. child: {
  9451. name: 'child',
  9452. class: 'p5.Element',
  9453. module: 'DOM',
  9454. overloads: [
  9455. {
  9456. params: []
  9457. },
  9458. {
  9459. params: [
  9460. {
  9461. name: 'child',
  9462. description:
  9463. '<p>the ID, DOM node, or <a href="#/p5.Element">p5.Element</a>\n to add to the current element</p>\n',
  9464. type: 'String|p5.Element',
  9465. optional: true
  9466. }
  9467. ],
  9468. chainable: 1
  9469. }
  9470. ]
  9471. },
  9472. center: {
  9473. name: 'center',
  9474. params: [
  9475. {
  9476. name: 'align',
  9477. description:
  9478. "<p>passing 'vertical', 'horizontal' aligns element accordingly</p>\n",
  9479. type: 'String',
  9480. optional: true
  9481. }
  9482. ],
  9483. class: 'p5.Element',
  9484. module: 'DOM'
  9485. },
  9486. html: {
  9487. name: 'html',
  9488. class: 'p5.Element',
  9489. module: 'DOM',
  9490. overloads: [
  9491. {
  9492. params: []
  9493. },
  9494. {
  9495. params: [
  9496. {
  9497. name: 'html',
  9498. description: '<p>the HTML to be placed inside the element</p>\n',
  9499. type: 'String',
  9500. optional: true
  9501. },
  9502. {
  9503. name: 'append',
  9504. description: '<p>whether to append HTML to existing</p>\n',
  9505. type: 'Boolean',
  9506. optional: true
  9507. }
  9508. ],
  9509. chainable: 1
  9510. }
  9511. ]
  9512. },
  9513. position: {
  9514. name: 'position',
  9515. class: 'p5.Element',
  9516. module: 'DOM',
  9517. overloads: [
  9518. {
  9519. params: []
  9520. },
  9521. {
  9522. params: [
  9523. {
  9524. name: 'x',
  9525. description:
  9526. '<p>x-position relative to upper left of window (optional)</p>\n',
  9527. type: 'Number',
  9528. optional: true
  9529. },
  9530. {
  9531. name: 'y',
  9532. description:
  9533. '<p>y-position relative to upper left of window (optional)</p>\n',
  9534. type: 'Number',
  9535. optional: true
  9536. },
  9537. {
  9538. name: 'positionType',
  9539. description:
  9540. '<p>it can be static, fixed, relative, sticky, initial or inherit (optional)</p>\n',
  9541. type: 'String'
  9542. }
  9543. ],
  9544. chainable: 1
  9545. }
  9546. ]
  9547. },
  9548. style: {
  9549. name: 'style',
  9550. class: 'p5.Element',
  9551. module: 'DOM',
  9552. overloads: [
  9553. {
  9554. params: [
  9555. {
  9556. name: 'property',
  9557. description: '<p>property to be set</p>\n',
  9558. type: 'String'
  9559. }
  9560. ]
  9561. },
  9562. {
  9563. params: [
  9564. {
  9565. name: 'property',
  9566. description: '',
  9567. type: 'String'
  9568. },
  9569. {
  9570. name: 'value',
  9571. description: '<p>value to assign to property</p>\n',
  9572. type: 'String|p5.Color'
  9573. }
  9574. ],
  9575. chainable: 1
  9576. }
  9577. ]
  9578. },
  9579. attribute: {
  9580. name: 'attribute',
  9581. class: 'p5.Element',
  9582. module: 'DOM',
  9583. overloads: [
  9584. {
  9585. params: []
  9586. },
  9587. {
  9588. params: [
  9589. {
  9590. name: 'attr',
  9591. description: '<p>attribute to set</p>\n',
  9592. type: 'String'
  9593. },
  9594. {
  9595. name: 'value',
  9596. description: '<p>value to assign to attribute</p>\n',
  9597. type: 'String'
  9598. }
  9599. ],
  9600. chainable: 1
  9601. }
  9602. ]
  9603. },
  9604. removeAttribute: {
  9605. name: 'removeAttribute',
  9606. params: [
  9607. {
  9608. name: 'attr',
  9609. description: '<p>attribute to remove</p>\n',
  9610. type: 'String'
  9611. }
  9612. ],
  9613. class: 'p5.Element',
  9614. module: 'DOM'
  9615. },
  9616. value: {
  9617. name: 'value',
  9618. class: 'p5.Element',
  9619. module: 'DOM',
  9620. overloads: [
  9621. {
  9622. params: []
  9623. },
  9624. {
  9625. params: [
  9626. {
  9627. name: 'value',
  9628. description: '',
  9629. type: 'String|Number'
  9630. }
  9631. ],
  9632. chainable: 1
  9633. }
  9634. ]
  9635. },
  9636. show: {
  9637. name: 'show',
  9638. class: 'p5.Element',
  9639. module: 'DOM'
  9640. },
  9641. hide: {
  9642. name: 'hide',
  9643. class: 'p5.Element',
  9644. module: 'DOM'
  9645. },
  9646. size: {
  9647. name: 'size',
  9648. class: 'p5.Element',
  9649. module: 'DOM',
  9650. overloads: [
  9651. {
  9652. params: []
  9653. },
  9654. {
  9655. params: [
  9656. {
  9657. name: 'w',
  9658. description:
  9659. '<p>width of the element, either AUTO, or a number</p>\n',
  9660. type: 'Number|Constant'
  9661. },
  9662. {
  9663. name: 'h',
  9664. description:
  9665. '<p>height of the element, either AUTO, or a number</p>\n',
  9666. type: 'Number|Constant',
  9667. optional: true
  9668. }
  9669. ],
  9670. chainable: 1
  9671. }
  9672. ]
  9673. },
  9674. remove: {
  9675. name: 'remove',
  9676. class: 'p5.Element',
  9677. module: 'DOM'
  9678. },
  9679. drop: {
  9680. name: 'drop',
  9681. params: [
  9682. {
  9683. name: 'callback',
  9684. description:
  9685. '<p>callback to receive loaded file, called for each file dropped.</p>\n',
  9686. type: 'Function'
  9687. },
  9688. {
  9689. name: 'fxn',
  9690. description:
  9691. '<p>callback triggered once when files are dropped with the drop event.</p>\n',
  9692. type: 'Function',
  9693. optional: true
  9694. }
  9695. ],
  9696. class: 'p5.Element',
  9697. module: 'DOM'
  9698. }
  9699. },
  9700. 'p5.Graphics': {
  9701. reset: {
  9702. name: 'reset',
  9703. class: 'p5.Graphics',
  9704. module: 'Rendering'
  9705. },
  9706. remove: {
  9707. name: 'remove',
  9708. class: 'p5.Graphics',
  9709. module: 'Rendering'
  9710. }
  9711. },
  9712. JSON: {
  9713. stringify: {
  9714. name: 'stringify',
  9715. params: [
  9716. {
  9717. name: 'object',
  9718. description:
  9719. '<p>:Javascript object that you would like to convert to JSON</p>\n',
  9720. type: 'Object'
  9721. }
  9722. ],
  9723. class: 'JSON',
  9724. module: 'Foundation'
  9725. }
  9726. },
  9727. console: {
  9728. log: {
  9729. name: 'log',
  9730. params: [
  9731. {
  9732. name: 'message',
  9733. description:
  9734. '<p>:Message that you would like to print to the console</p>\n',
  9735. type: 'String|Expression|Object'
  9736. }
  9737. ],
  9738. class: 'console',
  9739. module: 'Foundation'
  9740. }
  9741. },
  9742. 'p5.TypedDict': {
  9743. size: {
  9744. name: 'size',
  9745. class: 'p5.TypedDict',
  9746. module: 'Data'
  9747. },
  9748. hasKey: {
  9749. name: 'hasKey',
  9750. params: [
  9751. {
  9752. name: 'key',
  9753. description: '<p>that you want to look up</p>\n',
  9754. type: 'Number|String'
  9755. }
  9756. ],
  9757. class: 'p5.TypedDict',
  9758. module: 'Data'
  9759. },
  9760. get: {
  9761. name: 'get',
  9762. params: [
  9763. {
  9764. name: 'the',
  9765. description: '<p>key you want to access</p>\n',
  9766. type: 'Number|String'
  9767. }
  9768. ],
  9769. class: 'p5.TypedDict',
  9770. module: 'Data'
  9771. },
  9772. set: {
  9773. name: 'set',
  9774. params: [
  9775. {
  9776. name: 'key',
  9777. description: '',
  9778. type: 'Number|String'
  9779. },
  9780. {
  9781. name: 'value',
  9782. description: '',
  9783. type: 'Number|String'
  9784. }
  9785. ],
  9786. class: 'p5.TypedDict',
  9787. module: 'Data'
  9788. },
  9789. create: {
  9790. name: 'create',
  9791. class: 'p5.TypedDict',
  9792. module: 'Data',
  9793. overloads: [
  9794. {
  9795. params: [
  9796. {
  9797. name: 'key',
  9798. description: '',
  9799. type: 'Number|String'
  9800. },
  9801. {
  9802. name: 'value',
  9803. description: '',
  9804. type: 'Number|String'
  9805. }
  9806. ]
  9807. },
  9808. {
  9809. params: [
  9810. {
  9811. name: 'obj',
  9812. description: '<p>key/value pair</p>\n',
  9813. type: 'Object'
  9814. }
  9815. ]
  9816. }
  9817. ]
  9818. },
  9819. clear: {
  9820. name: 'clear',
  9821. class: 'p5.TypedDict',
  9822. module: 'Data'
  9823. },
  9824. remove: {
  9825. name: 'remove',
  9826. params: [
  9827. {
  9828. name: 'key',
  9829. description: '<p>for the pair to remove</p>\n',
  9830. type: 'Number|String'
  9831. }
  9832. ],
  9833. class: 'p5.TypedDict',
  9834. module: 'Data'
  9835. },
  9836. print: {
  9837. name: 'print',
  9838. class: 'p5.TypedDict',
  9839. module: 'Data'
  9840. },
  9841. saveTable: {
  9842. name: 'saveTable',
  9843. class: 'p5.TypedDict',
  9844. module: 'Data'
  9845. },
  9846. saveJSON: {
  9847. name: 'saveJSON',
  9848. class: 'p5.TypedDict',
  9849. module: 'Data'
  9850. }
  9851. },
  9852. 'p5.NumberDict': {
  9853. add: {
  9854. name: 'add',
  9855. params: [
  9856. {
  9857. name: 'Key',
  9858. description: '<p>for the value you wish to add to</p>\n',
  9859. type: 'Number'
  9860. },
  9861. {
  9862. name: 'Number',
  9863. description: '<p>to add to the value</p>\n',
  9864. type: 'Number'
  9865. }
  9866. ],
  9867. class: 'p5.NumberDict',
  9868. module: 'Data'
  9869. },
  9870. sub: {
  9871. name: 'sub',
  9872. params: [
  9873. {
  9874. name: 'Key',
  9875. description: '<p>for the value you wish to subtract from</p>\n',
  9876. type: 'Number'
  9877. },
  9878. {
  9879. name: 'Number',
  9880. description: '<p>to subtract from the value</p>\n',
  9881. type: 'Number'
  9882. }
  9883. ],
  9884. class: 'p5.NumberDict',
  9885. module: 'Data'
  9886. },
  9887. mult: {
  9888. name: 'mult',
  9889. params: [
  9890. {
  9891. name: 'Key',
  9892. description: '<p>for value you wish to multiply</p>\n',
  9893. type: 'Number'
  9894. },
  9895. {
  9896. name: 'Amount',
  9897. description: '<p>to multiply the value by</p>\n',
  9898. type: 'Number'
  9899. }
  9900. ],
  9901. class: 'p5.NumberDict',
  9902. module: 'Data'
  9903. },
  9904. div: {
  9905. name: 'div',
  9906. params: [
  9907. {
  9908. name: 'Key',
  9909. description: '<p>for value you wish to divide</p>\n',
  9910. type: 'Number'
  9911. },
  9912. {
  9913. name: 'Amount',
  9914. description: '<p>to divide the value by</p>\n',
  9915. type: 'Number'
  9916. }
  9917. ],
  9918. class: 'p5.NumberDict',
  9919. module: 'Data'
  9920. },
  9921. minValue: {
  9922. name: 'minValue',
  9923. class: 'p5.NumberDict',
  9924. module: 'Data'
  9925. },
  9926. maxValue: {
  9927. name: 'maxValue',
  9928. class: 'p5.NumberDict',
  9929. module: 'Data'
  9930. },
  9931. minKey: {
  9932. name: 'minKey',
  9933. class: 'p5.NumberDict',
  9934. module: 'Data'
  9935. },
  9936. maxKey: {
  9937. name: 'maxKey',
  9938. class: 'p5.NumberDict',
  9939. module: 'Data'
  9940. }
  9941. },
  9942. 'p5.MediaElement': {
  9943. src: {
  9944. name: 'src',
  9945. class: 'p5.MediaElement',
  9946. module: 'DOM'
  9947. },
  9948. play: {
  9949. name: 'play',
  9950. class: 'p5.MediaElement',
  9951. module: 'DOM'
  9952. },
  9953. stop: {
  9954. name: 'stop',
  9955. class: 'p5.MediaElement',
  9956. module: 'DOM'
  9957. },
  9958. pause: {
  9959. name: 'pause',
  9960. class: 'p5.MediaElement',
  9961. module: 'DOM'
  9962. },
  9963. loop: {
  9964. name: 'loop',
  9965. class: 'p5.MediaElement',
  9966. module: 'DOM'
  9967. },
  9968. noLoop: {
  9969. name: 'noLoop',
  9970. class: 'p5.MediaElement',
  9971. module: 'DOM'
  9972. },
  9973. autoplay: {
  9974. name: 'autoplay',
  9975. params: [
  9976. {
  9977. name: 'shouldAutoplay',
  9978. description: '<p>whether the element should autoplay</p>\n',
  9979. type: 'Boolean'
  9980. }
  9981. ],
  9982. class: 'p5.MediaElement',
  9983. module: 'DOM'
  9984. },
  9985. volume: {
  9986. name: 'volume',
  9987. class: 'p5.MediaElement',
  9988. module: 'DOM',
  9989. overloads: [
  9990. {
  9991. params: []
  9992. },
  9993. {
  9994. params: [
  9995. {
  9996. name: 'val',
  9997. description: '<p>volume between 0.0 and 1.0</p>\n',
  9998. type: 'Number'
  9999. }
  10000. ],
  10001. chainable: 1
  10002. }
  10003. ]
  10004. },
  10005. speed: {
  10006. name: 'speed',
  10007. class: 'p5.MediaElement',
  10008. module: 'DOM',
  10009. overloads: [
  10010. {
  10011. params: []
  10012. },
  10013. {
  10014. params: [
  10015. {
  10016. name: 'speed',
  10017. description: '<p>speed multiplier for element playback</p>\n',
  10018. type: 'Number'
  10019. }
  10020. ],
  10021. chainable: 1
  10022. }
  10023. ]
  10024. },
  10025. time: {
  10026. name: 'time',
  10027. class: 'p5.MediaElement',
  10028. module: 'DOM',
  10029. overloads: [
  10030. {
  10031. params: []
  10032. },
  10033. {
  10034. params: [
  10035. {
  10036. name: 'time',
  10037. description: '<p>time to jump to (in seconds)</p>\n',
  10038. type: 'Number'
  10039. }
  10040. ],
  10041. chainable: 1
  10042. }
  10043. ]
  10044. },
  10045. duration: {
  10046. name: 'duration',
  10047. class: 'p5.MediaElement',
  10048. module: 'DOM'
  10049. },
  10050. onended: {
  10051. name: 'onended',
  10052. params: [
  10053. {
  10054. name: 'callback',
  10055. description:
  10056. '<p>function to call when the\n soundfile has ended. The\n media element will be passed\n in as the argument to the\n callback.</p>\n',
  10057. type: 'Function'
  10058. }
  10059. ],
  10060. class: 'p5.MediaElement',
  10061. module: 'DOM'
  10062. },
  10063. connect: {
  10064. name: 'connect',
  10065. params: [
  10066. {
  10067. name: 'audioNode',
  10068. description:
  10069. '<p>AudioNode from the Web Audio API,\nor an object from the p5.sound library</p>\n',
  10070. type: 'AudioNode|Object'
  10071. }
  10072. ],
  10073. class: 'p5.MediaElement',
  10074. module: 'DOM'
  10075. },
  10076. disconnect: {
  10077. name: 'disconnect',
  10078. class: 'p5.MediaElement',
  10079. module: 'DOM'
  10080. },
  10081. showControls: {
  10082. name: 'showControls',
  10083. class: 'p5.MediaElement',
  10084. module: 'DOM'
  10085. },
  10086. hideControls: {
  10087. name: 'hideControls',
  10088. class: 'p5.MediaElement',
  10089. module: 'DOM'
  10090. },
  10091. addCue: {
  10092. name: 'addCue',
  10093. params: [
  10094. {
  10095. name: 'time',
  10096. description:
  10097. "<p>Time in seconds, relative to this media\n element's playback. For example, to trigger\n an event every time playback reaches two\n seconds, pass in the number 2. This will be\n passed as the first parameter to\n the callback function.</p>\n",
  10098. type: 'Number'
  10099. },
  10100. {
  10101. name: 'callback',
  10102. description:
  10103. '<p>Name of a function that will be\n called at the given time. The callback will\n receive time and (optionally) param as its\n two parameters.</p>\n',
  10104. type: 'Function'
  10105. },
  10106. {
  10107. name: 'value',
  10108. description:
  10109. '<p>An object to be passed as the\n second parameter to the\n callback function.</p>\n',
  10110. type: 'Object',
  10111. optional: true
  10112. }
  10113. ],
  10114. class: 'p5.MediaElement',
  10115. module: 'DOM'
  10116. },
  10117. removeCue: {
  10118. name: 'removeCue',
  10119. params: [
  10120. {
  10121. name: 'id',
  10122. description: '<p>ID of the cue, as returned by addCue</p>\n',
  10123. type: 'Number'
  10124. }
  10125. ],
  10126. class: 'p5.MediaElement',
  10127. module: 'DOM'
  10128. },
  10129. clearCues: {
  10130. name: 'clearCues',
  10131. params: [
  10132. {
  10133. name: 'id',
  10134. description: '<p>ID of the cue, as returned by addCue</p>\n',
  10135. type: 'Number'
  10136. }
  10137. ],
  10138. class: 'p5.MediaElement',
  10139. module: 'DOM'
  10140. }
  10141. },
  10142. 'p5.File': {
  10143. file: {
  10144. name: 'file',
  10145. class: 'p5.File',
  10146. module: 'DOM'
  10147. },
  10148. type: {
  10149. name: 'type',
  10150. class: 'p5.File',
  10151. module: 'DOM'
  10152. },
  10153. subtype: {
  10154. name: 'subtype',
  10155. class: 'p5.File',
  10156. module: 'DOM'
  10157. },
  10158. name: {
  10159. name: 'name',
  10160. class: 'p5.File',
  10161. module: 'DOM'
  10162. },
  10163. size: {
  10164. name: 'size',
  10165. class: 'p5.File',
  10166. module: 'DOM'
  10167. },
  10168. data: {
  10169. name: 'data',
  10170. class: 'p5.File',
  10171. module: 'DOM'
  10172. }
  10173. },
  10174. 'p5.Image': {
  10175. width: {
  10176. name: 'width',
  10177. class: 'p5.Image',
  10178. module: 'Image'
  10179. },
  10180. height: {
  10181. name: 'height',
  10182. class: 'p5.Image',
  10183. module: 'Image'
  10184. },
  10185. pixels: {
  10186. name: 'pixels',
  10187. class: 'p5.Image',
  10188. module: 'Image'
  10189. },
  10190. loadPixels: {
  10191. name: 'loadPixels',
  10192. class: 'p5.Image',
  10193. module: 'Image'
  10194. },
  10195. updatePixels: {
  10196. name: 'updatePixels',
  10197. class: 'p5.Image',
  10198. module: 'Image',
  10199. overloads: [
  10200. {
  10201. params: [
  10202. {
  10203. name: 'x',
  10204. description:
  10205. '<p>x-offset of the target update area for the\n underlying canvas</p>\n',
  10206. type: 'Integer'
  10207. },
  10208. {
  10209. name: 'y',
  10210. description:
  10211. '<p>y-offset of the target update area for the\n underlying canvas</p>\n',
  10212. type: 'Integer'
  10213. },
  10214. {
  10215. name: 'w',
  10216. description:
  10217. '<p>height of the target update area for the\n underlying canvas</p>\n',
  10218. type: 'Integer'
  10219. },
  10220. {
  10221. name: 'h',
  10222. description:
  10223. '<p>height of the target update area for the\n underlying canvas</p>\n',
  10224. type: 'Integer'
  10225. }
  10226. ]
  10227. },
  10228. {
  10229. params: []
  10230. }
  10231. ]
  10232. },
  10233. get: {
  10234. name: 'get',
  10235. class: 'p5.Image',
  10236. module: 'Image',
  10237. overloads: [
  10238. {
  10239. params: [
  10240. {
  10241. name: 'x',
  10242. description: '<p>x-coordinate of the pixel</p>\n',
  10243. type: 'Number'
  10244. },
  10245. {
  10246. name: 'y',
  10247. description: '<p>y-coordinate of the pixel</p>\n',
  10248. type: 'Number'
  10249. },
  10250. {
  10251. name: 'w',
  10252. description: '<p>width</p>\n',
  10253. type: 'Number'
  10254. },
  10255. {
  10256. name: 'h',
  10257. description: '<p>height</p>\n',
  10258. type: 'Number'
  10259. }
  10260. ]
  10261. },
  10262. {
  10263. params: []
  10264. },
  10265. {
  10266. params: [
  10267. {
  10268. name: 'x',
  10269. description: '',
  10270. type: 'Number'
  10271. },
  10272. {
  10273. name: 'y',
  10274. description: '',
  10275. type: 'Number'
  10276. }
  10277. ]
  10278. }
  10279. ]
  10280. },
  10281. set: {
  10282. name: 'set',
  10283. params: [
  10284. {
  10285. name: 'x',
  10286. description: '<p>x-coordinate of the pixel</p>\n',
  10287. type: 'Number'
  10288. },
  10289. {
  10290. name: 'y',
  10291. description: '<p>y-coordinate of the pixel</p>\n',
  10292. type: 'Number'
  10293. },
  10294. {
  10295. name: 'a',
  10296. description:
  10297. '<p>grayscale value | pixel array |\n a <a href="#/p5.Color">p5.Color</a> | image to copy</p>\n',
  10298. type: 'Number|Number[]|Object'
  10299. }
  10300. ],
  10301. class: 'p5.Image',
  10302. module: 'Image'
  10303. },
  10304. resize: {
  10305. name: 'resize',
  10306. params: [
  10307. {
  10308. name: 'width',
  10309. description: '<p>the resized image width</p>\n',
  10310. type: 'Number'
  10311. },
  10312. {
  10313. name: 'height',
  10314. description: '<p>the resized image height</p>\n',
  10315. type: 'Number'
  10316. }
  10317. ],
  10318. class: 'p5.Image',
  10319. module: 'Image'
  10320. },
  10321. copy: {
  10322. name: 'copy',
  10323. class: 'p5.Image',
  10324. module: 'Image',
  10325. overloads: [
  10326. {
  10327. params: [
  10328. {
  10329. name: 'srcImage',
  10330. description: '<p>source image</p>\n',
  10331. type: 'p5.Image|p5.Element'
  10332. },
  10333. {
  10334. name: 'sx',
  10335. description:
  10336. "<p>X coordinate of the source's upper left corner</p>\n",
  10337. type: 'Integer'
  10338. },
  10339. {
  10340. name: 'sy',
  10341. description:
  10342. "<p>Y coordinate of the source's upper left corner</p>\n",
  10343. type: 'Integer'
  10344. },
  10345. {
  10346. name: 'sw',
  10347. description: '<p>source image width</p>\n',
  10348. type: 'Integer'
  10349. },
  10350. {
  10351. name: 'sh',
  10352. description: '<p>source image height</p>\n',
  10353. type: 'Integer'
  10354. },
  10355. {
  10356. name: 'dx',
  10357. description:
  10358. "<p>X coordinate of the destination's upper left corner</p>\n",
  10359. type: 'Integer'
  10360. },
  10361. {
  10362. name: 'dy',
  10363. description:
  10364. "<p>Y coordinate of the destination's upper left corner</p>\n",
  10365. type: 'Integer'
  10366. },
  10367. {
  10368. name: 'dw',
  10369. description: '<p>destination image width</p>\n',
  10370. type: 'Integer'
  10371. },
  10372. {
  10373. name: 'dh',
  10374. description: '<p>destination image height</p>\n',
  10375. type: 'Integer'
  10376. }
  10377. ]
  10378. },
  10379. {
  10380. params: [
  10381. {
  10382. name: 'sx',
  10383. description: '',
  10384. type: 'Integer'
  10385. },
  10386. {
  10387. name: 'sy',
  10388. description: '',
  10389. type: 'Integer'
  10390. },
  10391. {
  10392. name: 'sw',
  10393. description: '',
  10394. type: 'Integer'
  10395. },
  10396. {
  10397. name: 'sh',
  10398. description: '',
  10399. type: 'Integer'
  10400. },
  10401. {
  10402. name: 'dx',
  10403. description: '',
  10404. type: 'Integer'
  10405. },
  10406. {
  10407. name: 'dy',
  10408. description: '',
  10409. type: 'Integer'
  10410. },
  10411. {
  10412. name: 'dw',
  10413. description: '',
  10414. type: 'Integer'
  10415. },
  10416. {
  10417. name: 'dh',
  10418. description: '',
  10419. type: 'Integer'
  10420. }
  10421. ]
  10422. }
  10423. ]
  10424. },
  10425. mask: {
  10426. name: 'mask',
  10427. params: [
  10428. {
  10429. name: 'srcImage',
  10430. description: '<p>source image</p>\n',
  10431. type: 'p5.Image'
  10432. }
  10433. ],
  10434. class: 'p5.Image',
  10435. module: 'Image'
  10436. },
  10437. filter: {
  10438. name: 'filter',
  10439. params: [
  10440. {
  10441. name: 'filterType',
  10442. description:
  10443. '<p>either THRESHOLD, GRAY, OPAQUE, INVERT,\n POSTERIZE, ERODE, DILATE or BLUR.\n See Filters.js for docs on\n each available filter</p>\n',
  10444. type: 'Constant'
  10445. },
  10446. {
  10447. name: 'filterParam',
  10448. description:
  10449. '<p>an optional parameter unique\n to each filter, see above</p>\n',
  10450. type: 'Number',
  10451. optional: true
  10452. }
  10453. ],
  10454. class: 'p5.Image',
  10455. module: 'Image'
  10456. },
  10457. blend: {
  10458. name: 'blend',
  10459. class: 'p5.Image',
  10460. module: 'Image',
  10461. overloads: [
  10462. {
  10463. params: [
  10464. {
  10465. name: 'srcImage',
  10466. description: '<p>source image</p>\n',
  10467. type: 'p5.Image'
  10468. },
  10469. {
  10470. name: 'sx',
  10471. description:
  10472. "<p>X coordinate of the source's upper left corner</p>\n",
  10473. type: 'Integer'
  10474. },
  10475. {
  10476. name: 'sy',
  10477. description:
  10478. "<p>Y coordinate of the source's upper left corner</p>\n",
  10479. type: 'Integer'
  10480. },
  10481. {
  10482. name: 'sw',
  10483. description: '<p>source image width</p>\n',
  10484. type: 'Integer'
  10485. },
  10486. {
  10487. name: 'sh',
  10488. description: '<p>source image height</p>\n',
  10489. type: 'Integer'
  10490. },
  10491. {
  10492. name: 'dx',
  10493. description:
  10494. "<p>X coordinate of the destination's upper left corner</p>\n",
  10495. type: 'Integer'
  10496. },
  10497. {
  10498. name: 'dy',
  10499. description:
  10500. "<p>Y coordinate of the destination's upper left corner</p>\n",
  10501. type: 'Integer'
  10502. },
  10503. {
  10504. name: 'dw',
  10505. description: '<p>destination image width</p>\n',
  10506. type: 'Integer'
  10507. },
  10508. {
  10509. name: 'dh',
  10510. description: '<p>destination image height</p>\n',
  10511. type: 'Integer'
  10512. },
  10513. {
  10514. name: 'blendMode',
  10515. description:
  10516. '<p>the blend mode. either\n BLEND, DARKEST, LIGHTEST, DIFFERENCE,\n MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,\n SOFT_LIGHT, DODGE, BURN, ADD or NORMAL.</p>\n<p>Available blend modes are: normal | multiply | screen | overlay |\n darken | lighten | color-dodge | color-burn | hard-light |\n soft-light | difference | exclusion | hue | saturation |\n color | luminosity</p>\n<p><a href="http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/">http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/</a></p>\n',
  10517. type: 'Constant'
  10518. }
  10519. ]
  10520. },
  10521. {
  10522. params: [
  10523. {
  10524. name: 'sx',
  10525. description: '',
  10526. type: 'Integer'
  10527. },
  10528. {
  10529. name: 'sy',
  10530. description: '',
  10531. type: 'Integer'
  10532. },
  10533. {
  10534. name: 'sw',
  10535. description: '',
  10536. type: 'Integer'
  10537. },
  10538. {
  10539. name: 'sh',
  10540. description: '',
  10541. type: 'Integer'
  10542. },
  10543. {
  10544. name: 'dx',
  10545. description: '',
  10546. type: 'Integer'
  10547. },
  10548. {
  10549. name: 'dy',
  10550. description: '',
  10551. type: 'Integer'
  10552. },
  10553. {
  10554. name: 'dw',
  10555. description: '',
  10556. type: 'Integer'
  10557. },
  10558. {
  10559. name: 'dh',
  10560. description: '',
  10561. type: 'Integer'
  10562. },
  10563. {
  10564. name: 'blendMode',
  10565. description: '',
  10566. type: 'Constant'
  10567. }
  10568. ]
  10569. }
  10570. ]
  10571. },
  10572. save: {
  10573. name: 'save',
  10574. params: [
  10575. {
  10576. name: 'filename',
  10577. description: '<p>give your file a name</p>\n',
  10578. type: 'String'
  10579. },
  10580. {
  10581. name: 'extension',
  10582. description: "<p>'png' or 'jpg'</p>\n",
  10583. type: 'String'
  10584. }
  10585. ],
  10586. class: 'p5.Image',
  10587. module: 'Image'
  10588. },
  10589. reset: {
  10590. name: 'reset',
  10591. class: 'p5.Image',
  10592. module: 'Image'
  10593. },
  10594. getCurrentFrame: {
  10595. name: 'getCurrentFrame',
  10596. class: 'p5.Image',
  10597. module: 'Image'
  10598. },
  10599. setFrame: {
  10600. name: 'setFrame',
  10601. params: [
  10602. {
  10603. name: 'index',
  10604. description:
  10605. '<p>the index for the frame that should be displayed</p>\n',
  10606. type: 'Number'
  10607. }
  10608. ],
  10609. class: 'p5.Image',
  10610. module: 'Image'
  10611. },
  10612. numFrames: {
  10613. name: 'numFrames',
  10614. class: 'p5.Image',
  10615. module: 'Image'
  10616. },
  10617. play: {
  10618. name: 'play',
  10619. class: 'p5.Image',
  10620. module: 'Image'
  10621. },
  10622. pause: {
  10623. name: 'pause',
  10624. class: 'p5.Image',
  10625. module: 'Image'
  10626. },
  10627. delay: {
  10628. name: 'delay',
  10629. params: [
  10630. {
  10631. name: 'd',
  10632. description:
  10633. '<p>the amount in milliseconds to delay between switching frames</p>\n',
  10634. type: 'Number'
  10635. },
  10636. {
  10637. name: 'index',
  10638. description:
  10639. '<p>the index of the frame that should have the new delay value {optional}</p>\n',
  10640. type: 'Number',
  10641. optional: true
  10642. }
  10643. ],
  10644. class: 'p5.Image',
  10645. module: 'Image'
  10646. }
  10647. },
  10648. 'p5.PrintWriter': {
  10649. write: {
  10650. name: 'write',
  10651. params: [
  10652. {
  10653. name: 'data',
  10654. description: '<p>all data to be written by the PrintWriter</p>\n',
  10655. type: 'Array'
  10656. }
  10657. ],
  10658. class: 'p5.PrintWriter',
  10659. module: 'IO'
  10660. },
  10661. print: {
  10662. name: 'print',
  10663. params: [
  10664. {
  10665. name: 'data',
  10666. description: '<p>all data to be printed by the PrintWriter</p>\n',
  10667. type: 'Array'
  10668. }
  10669. ],
  10670. class: 'p5.PrintWriter',
  10671. module: 'IO'
  10672. },
  10673. clear: {
  10674. name: 'clear',
  10675. class: 'p5.PrintWriter',
  10676. module: 'IO'
  10677. },
  10678. close: {
  10679. name: 'close',
  10680. class: 'p5.PrintWriter',
  10681. module: 'IO'
  10682. }
  10683. },
  10684. 'p5.Table': {
  10685. columns: {
  10686. name: 'columns',
  10687. class: 'p5.Table',
  10688. module: 'IO'
  10689. },
  10690. rows: {
  10691. name: 'rows',
  10692. class: 'p5.Table',
  10693. module: 'IO'
  10694. },
  10695. addRow: {
  10696. name: 'addRow',
  10697. params: [
  10698. {
  10699. name: 'row',
  10700. description: '<p>row to be added to the table</p>\n',
  10701. type: 'p5.TableRow',
  10702. optional: true
  10703. }
  10704. ],
  10705. class: 'p5.Table',
  10706. module: 'IO'
  10707. },
  10708. removeRow: {
  10709. name: 'removeRow',
  10710. params: [
  10711. {
  10712. name: 'id',
  10713. description: '<p>ID number of the row to remove</p>\n',
  10714. type: 'Integer'
  10715. }
  10716. ],
  10717. class: 'p5.Table',
  10718. module: 'IO'
  10719. },
  10720. getRow: {
  10721. name: 'getRow',
  10722. params: [
  10723. {
  10724. name: 'rowID',
  10725. description: '<p>ID number of the row to get</p>\n',
  10726. type: 'Integer'
  10727. }
  10728. ],
  10729. class: 'p5.Table',
  10730. module: 'IO'
  10731. },
  10732. getRows: {
  10733. name: 'getRows',
  10734. class: 'p5.Table',
  10735. module: 'IO'
  10736. },
  10737. findRow: {
  10738. name: 'findRow',
  10739. params: [
  10740. {
  10741. name: 'value',
  10742. description: '<p>The value to match</p>\n',
  10743. type: 'String'
  10744. },
  10745. {
  10746. name: 'column',
  10747. description:
  10748. '<p>ID number or title of the\n column to search</p>\n',
  10749. type: 'Integer|String'
  10750. }
  10751. ],
  10752. class: 'p5.Table',
  10753. module: 'IO'
  10754. },
  10755. findRows: {
  10756. name: 'findRows',
  10757. params: [
  10758. {
  10759. name: 'value',
  10760. description: '<p>The value to match</p>\n',
  10761. type: 'String'
  10762. },
  10763. {
  10764. name: 'column',
  10765. description:
  10766. '<p>ID number or title of the\n column to search</p>\n',
  10767. type: 'Integer|String'
  10768. }
  10769. ],
  10770. class: 'p5.Table',
  10771. module: 'IO'
  10772. },
  10773. matchRow: {
  10774. name: 'matchRow',
  10775. params: [
  10776. {
  10777. name: 'regexp',
  10778. description: '<p>The regular expression to match</p>\n',
  10779. type: 'String|RegExp'
  10780. },
  10781. {
  10782. name: 'column',
  10783. description:
  10784. '<p>The column ID (number) or\n title (string)</p>\n',
  10785. type: 'String|Integer'
  10786. }
  10787. ],
  10788. class: 'p5.Table',
  10789. module: 'IO'
  10790. },
  10791. matchRows: {
  10792. name: 'matchRows',
  10793. params: [
  10794. {
  10795. name: 'regexp',
  10796. description: '<p>The regular expression to match</p>\n',
  10797. type: 'String'
  10798. },
  10799. {
  10800. name: 'column',
  10801. description:
  10802. '<p>The column ID (number) or\n title (string)</p>\n',
  10803. type: 'String|Integer',
  10804. optional: true
  10805. }
  10806. ],
  10807. class: 'p5.Table',
  10808. module: 'IO'
  10809. },
  10810. getColumn: {
  10811. name: 'getColumn',
  10812. params: [
  10813. {
  10814. name: 'column',
  10815. description: '<p>String or Number of the column to return</p>\n',
  10816. type: 'String|Number'
  10817. }
  10818. ],
  10819. class: 'p5.Table',
  10820. module: 'IO'
  10821. },
  10822. clearRows: {
  10823. name: 'clearRows',
  10824. class: 'p5.Table',
  10825. module: 'IO'
  10826. },
  10827. addColumn: {
  10828. name: 'addColumn',
  10829. params: [
  10830. {
  10831. name: 'title',
  10832. description: '<p>title of the given column</p>\n',
  10833. type: 'String',
  10834. optional: true
  10835. }
  10836. ],
  10837. class: 'p5.Table',
  10838. module: 'IO'
  10839. },
  10840. getColumnCount: {
  10841. name: 'getColumnCount',
  10842. class: 'p5.Table',
  10843. module: 'IO'
  10844. },
  10845. getRowCount: {
  10846. name: 'getRowCount',
  10847. class: 'p5.Table',
  10848. module: 'IO'
  10849. },
  10850. removeTokens: {
  10851. name: 'removeTokens',
  10852. params: [
  10853. {
  10854. name: 'chars',
  10855. description: '<p>String listing characters to be removed</p>\n',
  10856. type: 'String'
  10857. },
  10858. {
  10859. name: 'column',
  10860. description:
  10861. '<p>Column ID (number)\n or name (string)</p>\n',
  10862. type: 'String|Integer',
  10863. optional: true
  10864. }
  10865. ],
  10866. class: 'p5.Table',
  10867. module: 'IO'
  10868. },
  10869. trim: {
  10870. name: 'trim',
  10871. params: [
  10872. {
  10873. name: 'column',
  10874. description:
  10875. '<p>Column ID (number)\n or name (string)</p>\n',
  10876. type: 'String|Integer',
  10877. optional: true
  10878. }
  10879. ],
  10880. class: 'p5.Table',
  10881. module: 'IO'
  10882. },
  10883. removeColumn: {
  10884. name: 'removeColumn',
  10885. params: [
  10886. {
  10887. name: 'column',
  10888. description: '<p>columnName (string) or ID (number)</p>\n',
  10889. type: 'String|Integer'
  10890. }
  10891. ],
  10892. class: 'p5.Table',
  10893. module: 'IO'
  10894. },
  10895. set: {
  10896. name: 'set',
  10897. params: [
  10898. {
  10899. name: 'row',
  10900. description: '<p>row ID</p>\n',
  10901. type: 'Integer'
  10902. },
  10903. {
  10904. name: 'column',
  10905. description:
  10906. '<p>column ID (Number)\n or title (String)</p>\n',
  10907. type: 'String|Integer'
  10908. },
  10909. {
  10910. name: 'value',
  10911. description: '<p>value to assign</p>\n',
  10912. type: 'String|Number'
  10913. }
  10914. ],
  10915. class: 'p5.Table',
  10916. module: 'IO'
  10917. },
  10918. setNum: {
  10919. name: 'setNum',
  10920. params: [
  10921. {
  10922. name: 'row',
  10923. description: '<p>row ID</p>\n',
  10924. type: 'Integer'
  10925. },
  10926. {
  10927. name: 'column',
  10928. description:
  10929. '<p>column ID (Number)\n or title (String)</p>\n',
  10930. type: 'String|Integer'
  10931. },
  10932. {
  10933. name: 'value',
  10934. description: '<p>value to assign</p>\n',
  10935. type: 'Number'
  10936. }
  10937. ],
  10938. class: 'p5.Table',
  10939. module: 'IO'
  10940. },
  10941. setString: {
  10942. name: 'setString',
  10943. params: [
  10944. {
  10945. name: 'row',
  10946. description: '<p>row ID</p>\n',
  10947. type: 'Integer'
  10948. },
  10949. {
  10950. name: 'column',
  10951. description:
  10952. '<p>column ID (Number)\n or title (String)</p>\n',
  10953. type: 'String|Integer'
  10954. },
  10955. {
  10956. name: 'value',
  10957. description: '<p>value to assign</p>\n',
  10958. type: 'String'
  10959. }
  10960. ],
  10961. class: 'p5.Table',
  10962. module: 'IO'
  10963. },
  10964. get: {
  10965. name: 'get',
  10966. params: [
  10967. {
  10968. name: 'row',
  10969. description: '<p>row ID</p>\n',
  10970. type: 'Integer'
  10971. },
  10972. {
  10973. name: 'column',
  10974. description:
  10975. '<p>columnName (string) or\n ID (number)</p>\n',
  10976. type: 'String|Integer'
  10977. }
  10978. ],
  10979. class: 'p5.Table',
  10980. module: 'IO'
  10981. },
  10982. getNum: {
  10983. name: 'getNum',
  10984. params: [
  10985. {
  10986. name: 'row',
  10987. description: '<p>row ID</p>\n',
  10988. type: 'Integer'
  10989. },
  10990. {
  10991. name: 'column',
  10992. description:
  10993. '<p>columnName (string) or\n ID (number)</p>\n',
  10994. type: 'String|Integer'
  10995. }
  10996. ],
  10997. class: 'p5.Table',
  10998. module: 'IO'
  10999. },
  11000. getString: {
  11001. name: 'getString',
  11002. params: [
  11003. {
  11004. name: 'row',
  11005. description: '<p>row ID</p>\n',
  11006. type: 'Integer'
  11007. },
  11008. {
  11009. name: 'column',
  11010. description:
  11011. '<p>columnName (string) or\n ID (number)</p>\n',
  11012. type: 'String|Integer'
  11013. }
  11014. ],
  11015. class: 'p5.Table',
  11016. module: 'IO'
  11017. },
  11018. getObject: {
  11019. name: 'getObject',
  11020. params: [
  11021. {
  11022. name: 'headerColumn',
  11023. description:
  11024. '<p>Name of the column which should be used to\n title each row object (optional)</p>\n',
  11025. type: 'String',
  11026. optional: true
  11027. }
  11028. ],
  11029. class: 'p5.Table',
  11030. module: 'IO'
  11031. },
  11032. getArray: {
  11033. name: 'getArray',
  11034. class: 'p5.Table',
  11035. module: 'IO'
  11036. }
  11037. },
  11038. 'p5.TableRow': {
  11039. set: {
  11040. name: 'set',
  11041. params: [
  11042. {
  11043. name: 'column',
  11044. description:
  11045. '<p>Column ID (Number)\n or Title (String)</p>\n',
  11046. type: 'String|Integer'
  11047. },
  11048. {
  11049. name: 'value',
  11050. description: '<p>The value to be stored</p>\n',
  11051. type: 'String|Number'
  11052. }
  11053. ],
  11054. class: 'p5.TableRow',
  11055. module: 'IO'
  11056. },
  11057. setNum: {
  11058. name: 'setNum',
  11059. params: [
  11060. {
  11061. name: 'column',
  11062. description:
  11063. '<p>Column ID (Number)\n or Title (String)</p>\n',
  11064. type: 'String|Integer'
  11065. },
  11066. {
  11067. name: 'value',
  11068. description:
  11069. '<p>The value to be stored\n as a Float</p>\n',
  11070. type: 'Number|String'
  11071. }
  11072. ],
  11073. class: 'p5.TableRow',
  11074. module: 'IO'
  11075. },
  11076. setString: {
  11077. name: 'setString',
  11078. params: [
  11079. {
  11080. name: 'column',
  11081. description:
  11082. '<p>Column ID (Number)\n or Title (String)</p>\n',
  11083. type: 'String|Integer'
  11084. },
  11085. {
  11086. name: 'value',
  11087. description:
  11088. '<p>The value to be stored\n as a String</p>\n',
  11089. type: 'String|Number|Boolean|Object'
  11090. }
  11091. ],
  11092. class: 'p5.TableRow',
  11093. module: 'IO'
  11094. },
  11095. get: {
  11096. name: 'get',
  11097. params: [
  11098. {
  11099. name: 'column',
  11100. description:
  11101. '<p>columnName (string) or\n ID (number)</p>\n',
  11102. type: 'String|Integer'
  11103. }
  11104. ],
  11105. class: 'p5.TableRow',
  11106. module: 'IO'
  11107. },
  11108. getNum: {
  11109. name: 'getNum',
  11110. params: [
  11111. {
  11112. name: 'column',
  11113. description:
  11114. '<p>columnName (string) or\n ID (number)</p>\n',
  11115. type: 'String|Integer'
  11116. }
  11117. ],
  11118. class: 'p5.TableRow',
  11119. module: 'IO'
  11120. },
  11121. getString: {
  11122. name: 'getString',
  11123. params: [
  11124. {
  11125. name: 'column',
  11126. description:
  11127. '<p>columnName (string) or\n ID (number)</p>\n',
  11128. type: 'String|Integer'
  11129. }
  11130. ],
  11131. class: 'p5.TableRow',
  11132. module: 'IO'
  11133. }
  11134. },
  11135. 'p5.XML': {
  11136. getParent: {
  11137. name: 'getParent',
  11138. class: 'p5.XML',
  11139. module: 'IO'
  11140. },
  11141. getName: {
  11142. name: 'getName',
  11143. class: 'p5.XML',
  11144. module: 'IO'
  11145. },
  11146. setName: {
  11147. name: 'setName',
  11148. params: [
  11149. {
  11150. name: 'the',
  11151. description: '<p>new name of the node</p>\n',
  11152. type: 'String'
  11153. }
  11154. ],
  11155. class: 'p5.XML',
  11156. module: 'IO'
  11157. },
  11158. hasChildren: {
  11159. name: 'hasChildren',
  11160. class: 'p5.XML',
  11161. module: 'IO'
  11162. },
  11163. listChildren: {
  11164. name: 'listChildren',
  11165. class: 'p5.XML',
  11166. module: 'IO'
  11167. },
  11168. getChildren: {
  11169. name: 'getChildren',
  11170. params: [
  11171. {
  11172. name: 'name',
  11173. description: '<p>element name</p>\n',
  11174. type: 'String',
  11175. optional: true
  11176. }
  11177. ],
  11178. class: 'p5.XML',
  11179. module: 'IO'
  11180. },
  11181. getChild: {
  11182. name: 'getChild',
  11183. params: [
  11184. {
  11185. name: 'name',
  11186. description: '<p>element name or index</p>\n',
  11187. type: 'String|Integer'
  11188. }
  11189. ],
  11190. class: 'p5.XML',
  11191. module: 'IO'
  11192. },
  11193. addChild: {
  11194. name: 'addChild',
  11195. params: [
  11196. {
  11197. name: 'node',
  11198. description:
  11199. '<p>a <a href="#/p5.XML">p5.XML</a> Object which will be the child to be added</p>\n',
  11200. type: 'p5.XML'
  11201. }
  11202. ],
  11203. class: 'p5.XML',
  11204. module: 'IO'
  11205. },
  11206. removeChild: {
  11207. name: 'removeChild',
  11208. params: [
  11209. {
  11210. name: 'name',
  11211. description: '<p>element name or index</p>\n',
  11212. type: 'String|Integer'
  11213. }
  11214. ],
  11215. class: 'p5.XML',
  11216. module: 'IO'
  11217. },
  11218. getAttributeCount: {
  11219. name: 'getAttributeCount',
  11220. class: 'p5.XML',
  11221. module: 'IO'
  11222. },
  11223. listAttributes: {
  11224. name: 'listAttributes',
  11225. class: 'p5.XML',
  11226. module: 'IO'
  11227. },
  11228. hasAttribute: {
  11229. name: 'hasAttribute',
  11230. params: [
  11231. {
  11232. name: 'the',
  11233. description: '<p>attribute to be checked</p>\n',
  11234. type: 'String'
  11235. }
  11236. ],
  11237. class: 'p5.XML',
  11238. module: 'IO'
  11239. },
  11240. getNum: {
  11241. name: 'getNum',
  11242. params: [
  11243. {
  11244. name: 'name',
  11245. description: '<p>the non-null full name of the attribute</p>\n',
  11246. type: 'String'
  11247. },
  11248. {
  11249. name: 'defaultValue',
  11250. description: '<p>the default value of the attribute</p>\n',
  11251. type: 'Number',
  11252. optional: true
  11253. }
  11254. ],
  11255. class: 'p5.XML',
  11256. module: 'IO'
  11257. },
  11258. getString: {
  11259. name: 'getString',
  11260. params: [
  11261. {
  11262. name: 'name',
  11263. description: '<p>the non-null full name of the attribute</p>\n',
  11264. type: 'String'
  11265. },
  11266. {
  11267. name: 'defaultValue',
  11268. description: '<p>the default value of the attribute</p>\n',
  11269. type: 'Number',
  11270. optional: true
  11271. }
  11272. ],
  11273. class: 'p5.XML',
  11274. module: 'IO'
  11275. },
  11276. setAttribute: {
  11277. name: 'setAttribute',
  11278. params: [
  11279. {
  11280. name: 'name',
  11281. description: '<p>the full name of the attribute</p>\n',
  11282. type: 'String'
  11283. },
  11284. {
  11285. name: 'value',
  11286. description: '<p>the value of the attribute</p>\n',
  11287. type: 'Number|String|Boolean'
  11288. }
  11289. ],
  11290. class: 'p5.XML',
  11291. module: 'IO'
  11292. },
  11293. getContent: {
  11294. name: 'getContent',
  11295. params: [
  11296. {
  11297. name: 'defaultValue',
  11298. description: '<p>value returned if no content is found</p>\n',
  11299. type: 'String',
  11300. optional: true
  11301. }
  11302. ],
  11303. class: 'p5.XML',
  11304. module: 'IO'
  11305. },
  11306. setContent: {
  11307. name: 'setContent',
  11308. params: [
  11309. {
  11310. name: 'text',
  11311. description: '<p>the new content</p>\n',
  11312. type: 'String'
  11313. }
  11314. ],
  11315. class: 'p5.XML',
  11316. module: 'IO'
  11317. },
  11318. serialize: {
  11319. name: 'serialize',
  11320. class: 'p5.XML',
  11321. module: 'IO'
  11322. }
  11323. },
  11324. 'p5.Vector': {
  11325. x: {
  11326. name: 'x',
  11327. class: 'p5.Vector',
  11328. module: 'Math'
  11329. },
  11330. y: {
  11331. name: 'y',
  11332. class: 'p5.Vector',
  11333. module: 'Math'
  11334. },
  11335. z: {
  11336. name: 'z',
  11337. class: 'p5.Vector',
  11338. module: 'Math'
  11339. },
  11340. toString: {
  11341. name: 'toString',
  11342. class: 'p5.Vector',
  11343. module: 'Math'
  11344. },
  11345. set: {
  11346. name: 'set',
  11347. class: 'p5.Vector',
  11348. module: 'Math',
  11349. overloads: [
  11350. {
  11351. params: [
  11352. {
  11353. name: 'x',
  11354. description: '<p>the x component of the vector</p>\n',
  11355. type: 'Number',
  11356. optional: true
  11357. },
  11358. {
  11359. name: 'y',
  11360. description: '<p>the y component of the vector</p>\n',
  11361. type: 'Number',
  11362. optional: true
  11363. },
  11364. {
  11365. name: 'z',
  11366. description: '<p>the z component of the vector</p>\n',
  11367. type: 'Number',
  11368. optional: true
  11369. }
  11370. ],
  11371. chainable: 1
  11372. },
  11373. {
  11374. params: [
  11375. {
  11376. name: 'value',
  11377. description: '<p>the vector to set</p>\n',
  11378. type: 'p5.Vector|Number[]'
  11379. }
  11380. ],
  11381. chainable: 1
  11382. }
  11383. ]
  11384. },
  11385. copy: {
  11386. name: 'copy',
  11387. class: 'p5.Vector',
  11388. module: 'Math'
  11389. },
  11390. add: {
  11391. name: 'add',
  11392. class: 'p5.Vector',
  11393. module: 'Math',
  11394. overloads: [
  11395. {
  11396. params: [
  11397. {
  11398. name: 'x',
  11399. description: '<p>the x component of the vector to be added</p>\n',
  11400. type: 'Number'
  11401. },
  11402. {
  11403. name: 'y',
  11404. description: '<p>the y component of the vector to be added</p>\n',
  11405. type: 'Number',
  11406. optional: true
  11407. },
  11408. {
  11409. name: 'z',
  11410. description: '<p>the z component of the vector to be added</p>\n',
  11411. type: 'Number',
  11412. optional: true
  11413. }
  11414. ],
  11415. chainable: 1
  11416. },
  11417. {
  11418. params: [
  11419. {
  11420. name: 'value',
  11421. description: '<p>the vector to add</p>\n',
  11422. type: 'p5.Vector|Number[]'
  11423. }
  11424. ],
  11425. chainable: 1
  11426. },
  11427. {
  11428. params: [
  11429. {
  11430. name: 'v1',
  11431. description:
  11432. '<p>a <a href="#/p5.Vector">p5.Vector</a> to add</p>\n',
  11433. type: 'p5.Vector'
  11434. },
  11435. {
  11436. name: 'v2',
  11437. description:
  11438. '<p>a <a href="#/p5.Vector">p5.Vector</a> to add</p>\n',
  11439. type: 'p5.Vector'
  11440. },
  11441. {
  11442. name: 'target',
  11443. description: '<p>the vector to receive the result</p>\n',
  11444. type: 'p5.Vector',
  11445. optional: true
  11446. }
  11447. ],
  11448. static: 1
  11449. }
  11450. ]
  11451. },
  11452. rem: {
  11453. name: 'rem',
  11454. class: 'p5.Vector',
  11455. module: 'Math',
  11456. overloads: [
  11457. {
  11458. params: [
  11459. {
  11460. name: 'x',
  11461. description: '<p>the x component of divisor vector</p>\n',
  11462. type: 'Number'
  11463. },
  11464. {
  11465. name: 'y',
  11466. description: '<p>the y component of divisor vector</p>\n',
  11467. type: 'Number'
  11468. },
  11469. {
  11470. name: 'z',
  11471. description: '<p>the z component of divisor vector</p>\n',
  11472. type: 'Number'
  11473. }
  11474. ],
  11475. chainable: 1
  11476. },
  11477. {
  11478. params: [
  11479. {
  11480. name: 'value',
  11481. description: '<p>divisor vector</p>\n',
  11482. type: 'p5.Vector | Number[]'
  11483. }
  11484. ],
  11485. chainable: 1
  11486. },
  11487. {
  11488. params: [
  11489. {
  11490. name: 'v1',
  11491. description:
  11492. '<p>dividend <a href="#/p5.Vector">p5.Vector</a></p>\n',
  11493. type: 'p5.Vector'
  11494. },
  11495. {
  11496. name: 'v2',
  11497. description: '<p>divisor <a href="#/p5.Vector">p5.Vector</a></p>\n',
  11498. type: 'p5.Vector'
  11499. }
  11500. ],
  11501. static: 1
  11502. },
  11503. {
  11504. params: [
  11505. {
  11506. name: 'v1',
  11507. description: '',
  11508. type: 'p5.Vector'
  11509. },
  11510. {
  11511. name: 'v2',
  11512. description: '',
  11513. type: 'p5.Vector'
  11514. }
  11515. ],
  11516. static: 1
  11517. }
  11518. ]
  11519. },
  11520. sub: {
  11521. name: 'sub',
  11522. class: 'p5.Vector',
  11523. module: 'Math',
  11524. overloads: [
  11525. {
  11526. params: [
  11527. {
  11528. name: 'x',
  11529. description: '<p>the x component of the vector to subtract</p>\n',
  11530. type: 'Number'
  11531. },
  11532. {
  11533. name: 'y',
  11534. description: '<p>the y component of the vector to subtract</p>\n',
  11535. type: 'Number',
  11536. optional: true
  11537. },
  11538. {
  11539. name: 'z',
  11540. description: '<p>the z component of the vector to subtract</p>\n',
  11541. type: 'Number',
  11542. optional: true
  11543. }
  11544. ],
  11545. chainable: 1
  11546. },
  11547. {
  11548. params: [
  11549. {
  11550. name: 'value',
  11551. description: '<p>the vector to subtract</p>\n',
  11552. type: 'p5.Vector|Number[]'
  11553. }
  11554. ],
  11555. chainable: 1
  11556. },
  11557. {
  11558. params: [
  11559. {
  11560. name: 'v1',
  11561. description:
  11562. '<p>a <a href="#/p5.Vector">p5.Vector</a> to subtract from</p>\n',
  11563. type: 'p5.Vector'
  11564. },
  11565. {
  11566. name: 'v2',
  11567. description:
  11568. '<p>a <a href="#/p5.Vector">p5.Vector</a> to subtract</p>\n',
  11569. type: 'p5.Vector'
  11570. },
  11571. {
  11572. name: 'target',
  11573. description: '<p>the vector to receive the result</p>\n',
  11574. type: 'p5.Vector',
  11575. optional: true
  11576. }
  11577. ],
  11578. static: 1
  11579. }
  11580. ]
  11581. },
  11582. mult: {
  11583. name: 'mult',
  11584. class: 'p5.Vector',
  11585. module: 'Math',
  11586. overloads: [
  11587. {
  11588. params: [
  11589. {
  11590. name: 'n',
  11591. description: '<p>The number to multiply with the vector</p>\n',
  11592. type: 'Number'
  11593. }
  11594. ],
  11595. chainable: 1
  11596. },
  11597. {
  11598. params: [
  11599. {
  11600. name: 'x',
  11601. description:
  11602. '<p>The number to multiply with the x component of the vector</p>\n',
  11603. type: 'Number'
  11604. },
  11605. {
  11606. name: 'y',
  11607. description:
  11608. '<p>The number to multiply with the y component of the vector</p>\n',
  11609. type: 'Number'
  11610. },
  11611. {
  11612. name: 'z',
  11613. description:
  11614. '<p>The number to multiply with the z component of the vector</p>\n',
  11615. type: 'Number',
  11616. optional: true
  11617. }
  11618. ],
  11619. chainable: 1
  11620. },
  11621. {
  11622. params: [
  11623. {
  11624. name: 'arr',
  11625. description:
  11626. '<p>The array to multiply with the components of the vector</p>\n',
  11627. type: 'Number[]'
  11628. }
  11629. ],
  11630. chainable: 1
  11631. },
  11632. {
  11633. params: [
  11634. {
  11635. name: 'v',
  11636. description:
  11637. '<p>The vector to multiply with the components of the original vector</p>\n',
  11638. type: 'p5.Vector'
  11639. }
  11640. ],
  11641. chainable: 1
  11642. },
  11643. {
  11644. params: [
  11645. {
  11646. name: 'x',
  11647. description: '',
  11648. type: 'Number'
  11649. },
  11650. {
  11651. name: 'y',
  11652. description: '',
  11653. type: 'Number'
  11654. },
  11655. {
  11656. name: 'z',
  11657. description: '',
  11658. type: 'Number',
  11659. optional: true
  11660. }
  11661. ],
  11662. static: 1
  11663. },
  11664. {
  11665. params: [
  11666. {
  11667. name: 'v',
  11668. description: '',
  11669. type: 'p5.Vector'
  11670. },
  11671. {
  11672. name: 'n',
  11673. description: '',
  11674. type: 'Number'
  11675. },
  11676. {
  11677. name: 'target',
  11678. description: '<p>the vector to receive the result</p>\n',
  11679. type: 'p5.Vector',
  11680. optional: true
  11681. }
  11682. ],
  11683. static: 1
  11684. },
  11685. {
  11686. params: [
  11687. {
  11688. name: 'v0',
  11689. description: '',
  11690. type: 'p5.Vector'
  11691. },
  11692. {
  11693. name: 'v1',
  11694. description: '',
  11695. type: 'p5.Vector'
  11696. },
  11697. {
  11698. name: 'target',
  11699. description: '',
  11700. type: 'p5.Vector',
  11701. optional: true
  11702. }
  11703. ],
  11704. static: 1
  11705. },
  11706. {
  11707. params: [
  11708. {
  11709. name: 'v0',
  11710. description: '',
  11711. type: 'p5.Vector'
  11712. },
  11713. {
  11714. name: 'arr',
  11715. description: '',
  11716. type: 'Number[]'
  11717. },
  11718. {
  11719. name: 'target',
  11720. description: '',
  11721. type: 'p5.Vector',
  11722. optional: true
  11723. }
  11724. ],
  11725. static: 1
  11726. }
  11727. ]
  11728. },
  11729. div: {
  11730. name: 'div',
  11731. class: 'p5.Vector',
  11732. module: 'Math',
  11733. overloads: [
  11734. {
  11735. params: [
  11736. {
  11737. name: 'n',
  11738. description: '<p>The number to divide the vector by</p>\n',
  11739. type: 'Number'
  11740. }
  11741. ],
  11742. chainable: 1
  11743. },
  11744. {
  11745. params: [
  11746. {
  11747. name: 'x',
  11748. description:
  11749. '<p>The number to divide with the x component of the vector</p>\n',
  11750. type: 'Number'
  11751. },
  11752. {
  11753. name: 'y',
  11754. description:
  11755. '<p>The number to divide with the y component of the vector</p>\n',
  11756. type: 'Number'
  11757. },
  11758. {
  11759. name: 'z',
  11760. description:
  11761. '<p>The number to divide with the z component of the vector</p>\n',
  11762. type: 'Number',
  11763. optional: true
  11764. }
  11765. ],
  11766. chainable: 1
  11767. },
  11768. {
  11769. params: [
  11770. {
  11771. name: 'arr',
  11772. description:
  11773. '<p>The array to divide the components of the vector by</p>\n',
  11774. type: 'Number[]'
  11775. }
  11776. ],
  11777. chainable: 1
  11778. },
  11779. {
  11780. params: [
  11781. {
  11782. name: 'v',
  11783. description:
  11784. '<p>The vector to divide the components of the original vector by</p>\n',
  11785. type: 'p5.Vector'
  11786. }
  11787. ],
  11788. chainable: 1
  11789. },
  11790. {
  11791. params: [
  11792. {
  11793. name: 'x',
  11794. description: '',
  11795. type: 'Number'
  11796. },
  11797. {
  11798. name: 'y',
  11799. description: '',
  11800. type: 'Number'
  11801. },
  11802. {
  11803. name: 'z',
  11804. description: '',
  11805. type: 'Number',
  11806. optional: true
  11807. }
  11808. ],
  11809. static: 1
  11810. },
  11811. {
  11812. params: [
  11813. {
  11814. name: 'v',
  11815. description: '',
  11816. type: 'p5.Vector'
  11817. },
  11818. {
  11819. name: 'n',
  11820. description: '',
  11821. type: 'Number'
  11822. },
  11823. {
  11824. name: 'target',
  11825. description: '<p>the vector to receive the result</p>\n',
  11826. type: 'p5.Vector',
  11827. optional: true
  11828. }
  11829. ],
  11830. static: 1
  11831. },
  11832. {
  11833. params: [
  11834. {
  11835. name: 'v0',
  11836. description: '',
  11837. type: 'p5.Vector'
  11838. },
  11839. {
  11840. name: 'v1',
  11841. description: '',
  11842. type: 'p5.Vector'
  11843. },
  11844. {
  11845. name: 'target',
  11846. description: '',
  11847. type: 'p5.Vector',
  11848. optional: true
  11849. }
  11850. ],
  11851. static: 1
  11852. },
  11853. {
  11854. params: [
  11855. {
  11856. name: 'v0',
  11857. description: '',
  11858. type: 'p5.Vector'
  11859. },
  11860. {
  11861. name: 'arr',
  11862. description: '',
  11863. type: 'Number[]'
  11864. },
  11865. {
  11866. name: 'target',
  11867. description: '',
  11868. type: 'p5.Vector',
  11869. optional: true
  11870. }
  11871. ],
  11872. static: 1
  11873. }
  11874. ]
  11875. },
  11876. mag: {
  11877. name: 'mag',
  11878. class: 'p5.Vector',
  11879. module: 'Math',
  11880. overloads: [
  11881. {
  11882. params: []
  11883. },
  11884. {
  11885. params: [
  11886. {
  11887. name: 'vecT',
  11888. description: '<p>the vector to return the magnitude of</p>\n',
  11889. type: 'p5.Vector'
  11890. }
  11891. ],
  11892. static: 1
  11893. }
  11894. ]
  11895. },
  11896. magSq: {
  11897. name: 'magSq',
  11898. class: 'p5.Vector',
  11899. module: 'Math'
  11900. },
  11901. dot: {
  11902. name: 'dot',
  11903. class: 'p5.Vector',
  11904. module: 'Math',
  11905. overloads: [
  11906. {
  11907. params: [
  11908. {
  11909. name: 'x',
  11910. description: '<p>x component of the vector</p>\n',
  11911. type: 'Number'
  11912. },
  11913. {
  11914. name: 'y',
  11915. description: '<p>y component of the vector</p>\n',
  11916. type: 'Number',
  11917. optional: true
  11918. },
  11919. {
  11920. name: 'z',
  11921. description: '<p>z component of the vector</p>\n',
  11922. type: 'Number',
  11923. optional: true
  11924. }
  11925. ]
  11926. },
  11927. {
  11928. params: [
  11929. {
  11930. name: 'value',
  11931. description:
  11932. '<p>value component of the vector or a <a href="#/p5.Vector">p5.Vector</a></p>\n',
  11933. type: 'p5.Vector'
  11934. }
  11935. ]
  11936. },
  11937. {
  11938. params: [
  11939. {
  11940. name: 'v1',
  11941. description:
  11942. '<p>the first <a href="#/p5.Vector">p5.Vector</a></p>\n',
  11943. type: 'p5.Vector'
  11944. },
  11945. {
  11946. name: 'v2',
  11947. description:
  11948. '<p>the second <a href="#/p5.Vector">p5.Vector</a></p>\n',
  11949. type: 'p5.Vector'
  11950. }
  11951. ],
  11952. static: 1
  11953. }
  11954. ]
  11955. },
  11956. cross: {
  11957. name: 'cross',
  11958. class: 'p5.Vector',
  11959. module: 'Math',
  11960. overloads: [
  11961. {
  11962. params: [
  11963. {
  11964. name: 'v',
  11965. description:
  11966. '<p><a href="#/p5.Vector">p5.Vector</a> to be crossed</p>\n',
  11967. type: 'p5.Vector'
  11968. }
  11969. ]
  11970. },
  11971. {
  11972. params: [
  11973. {
  11974. name: 'v1',
  11975. description:
  11976. '<p>the first <a href="#/p5.Vector">p5.Vector</a></p>\n',
  11977. type: 'p5.Vector'
  11978. },
  11979. {
  11980. name: 'v2',
  11981. description:
  11982. '<p>the second <a href="#/p5.Vector">p5.Vector</a></p>\n',
  11983. type: 'p5.Vector'
  11984. }
  11985. ],
  11986. static: 1
  11987. }
  11988. ]
  11989. },
  11990. dist: {
  11991. name: 'dist',
  11992. class: 'p5.Vector',
  11993. module: 'Math',
  11994. overloads: [
  11995. {
  11996. params: [
  11997. {
  11998. name: 'v',
  11999. description:
  12000. '<p>the x, y, and z coordinates of a <a href="#/p5.Vector">p5.Vector</a></p>\n',
  12001. type: 'p5.Vector'
  12002. }
  12003. ]
  12004. },
  12005. {
  12006. params: [
  12007. {
  12008. name: 'v1',
  12009. description:
  12010. '<p>the first <a href="#/p5.Vector">p5.Vector</a></p>\n',
  12011. type: 'p5.Vector'
  12012. },
  12013. {
  12014. name: 'v2',
  12015. description:
  12016. '<p>the second <a href="#/p5.Vector">p5.Vector</a></p>\n',
  12017. type: 'p5.Vector'
  12018. }
  12019. ],
  12020. static: 1
  12021. }
  12022. ]
  12023. },
  12024. normalize: {
  12025. name: 'normalize',
  12026. class: 'p5.Vector',
  12027. module: 'Math',
  12028. overloads: [
  12029. {
  12030. params: []
  12031. },
  12032. {
  12033. params: [
  12034. {
  12035. name: 'v',
  12036. description: '<p>the vector to normalize</p>\n',
  12037. type: 'p5.Vector'
  12038. },
  12039. {
  12040. name: 'target',
  12041. description: '<p>the vector to receive the result</p>\n',
  12042. type: 'p5.Vector',
  12043. optional: true
  12044. }
  12045. ],
  12046. static: 1
  12047. }
  12048. ]
  12049. },
  12050. limit: {
  12051. name: 'limit',
  12052. params: [
  12053. {
  12054. name: 'max',
  12055. description: '<p>the maximum magnitude for the vector</p>\n',
  12056. type: 'Number'
  12057. }
  12058. ],
  12059. class: 'p5.Vector',
  12060. module: 'Math'
  12061. },
  12062. setMag: {
  12063. name: 'setMag',
  12064. params: [
  12065. {
  12066. name: 'len',
  12067. description: '<p>the new length for this vector</p>\n',
  12068. type: 'Number'
  12069. }
  12070. ],
  12071. class: 'p5.Vector',
  12072. module: 'Math'
  12073. },
  12074. heading: {
  12075. name: 'heading',
  12076. class: 'p5.Vector',
  12077. module: 'Math'
  12078. },
  12079. setHeading: {
  12080. name: 'setHeading',
  12081. params: [
  12082. {
  12083. name: 'angle',
  12084. description: '<p>the angle of rotation</p>\n',
  12085. type: 'Number'
  12086. }
  12087. ],
  12088. class: 'p5.Vector',
  12089. module: 'Math'
  12090. },
  12091. rotate: {
  12092. name: 'rotate',
  12093. class: 'p5.Vector',
  12094. module: 'Math',
  12095. overloads: [
  12096. {
  12097. params: [
  12098. {
  12099. name: 'angle',
  12100. description: '<p>the angle of rotation</p>\n',
  12101. type: 'Number'
  12102. }
  12103. ],
  12104. chainable: 1
  12105. },
  12106. {
  12107. params: [
  12108. {
  12109. name: 'v',
  12110. description: '',
  12111. type: 'p5.Vector'
  12112. },
  12113. {
  12114. name: 'angle',
  12115. description: '',
  12116. type: 'Number'
  12117. },
  12118. {
  12119. name: 'target',
  12120. description: '<p>the vector to receive the result</p>\n',
  12121. type: 'p5.Vector',
  12122. optional: true
  12123. }
  12124. ],
  12125. static: 1
  12126. }
  12127. ]
  12128. },
  12129. angleBetween: {
  12130. name: 'angleBetween',
  12131. params: [
  12132. {
  12133. name: 'value',
  12134. description:
  12135. '<p>the x, y, and z components of a <a href="#/p5.Vector">p5.Vector</a></p>\n',
  12136. type: 'p5.Vector'
  12137. }
  12138. ],
  12139. class: 'p5.Vector',
  12140. module: 'Math'
  12141. },
  12142. lerp: {
  12143. name: 'lerp',
  12144. class: 'p5.Vector',
  12145. module: 'Math',
  12146. overloads: [
  12147. {
  12148. params: [
  12149. {
  12150. name: 'x',
  12151. description: '<p>the x component</p>\n',
  12152. type: 'Number'
  12153. },
  12154. {
  12155. name: 'y',
  12156. description: '<p>the y component</p>\n',
  12157. type: 'Number'
  12158. },
  12159. {
  12160. name: 'z',
  12161. description: '<p>the z component</p>\n',
  12162. type: 'Number'
  12163. },
  12164. {
  12165. name: 'amt',
  12166. description:
  12167. '<p>the amount of interpolation; some value between 0.0\n (old vector) and 1.0 (new vector). 0.9 is very near\n the new vector. 0.5 is halfway in between.</p>\n',
  12168. type: 'Number'
  12169. }
  12170. ],
  12171. chainable: 1
  12172. },
  12173. {
  12174. params: [
  12175. {
  12176. name: 'v',
  12177. description:
  12178. '<p>the <a href="#/p5.Vector">p5.Vector</a> to lerp to</p>\n',
  12179. type: 'p5.Vector'
  12180. },
  12181. {
  12182. name: 'amt',
  12183. description: '',
  12184. type: 'Number'
  12185. }
  12186. ],
  12187. chainable: 1
  12188. },
  12189. {
  12190. params: [
  12191. {
  12192. name: 'v1',
  12193. description: '',
  12194. type: 'p5.Vector'
  12195. },
  12196. {
  12197. name: 'v2',
  12198. description: '',
  12199. type: 'p5.Vector'
  12200. },
  12201. {
  12202. name: 'amt',
  12203. description: '',
  12204. type: 'Number'
  12205. },
  12206. {
  12207. name: 'target',
  12208. description: '<p>the vector to receive the result</p>\n',
  12209. type: 'p5.Vector',
  12210. optional: true
  12211. }
  12212. ],
  12213. static: 1
  12214. }
  12215. ]
  12216. },
  12217. reflect: {
  12218. name: 'reflect',
  12219. params: [
  12220. {
  12221. name: 'surfaceNormal',
  12222. description:
  12223. '<p>the <a href="#/p5.Vector">p5.Vector</a> to reflect about, will be normalized by this method</p>\n',
  12224. type: 'p5.Vector'
  12225. }
  12226. ],
  12227. class: 'p5.Vector',
  12228. module: 'Math'
  12229. },
  12230. array: {
  12231. name: 'array',
  12232. class: 'p5.Vector',
  12233. module: 'Math'
  12234. },
  12235. equals: {
  12236. name: 'equals',
  12237. class: 'p5.Vector',
  12238. module: 'Math',
  12239. overloads: [
  12240. {
  12241. params: [
  12242. {
  12243. name: 'x',
  12244. description: '<p>the x component of the vector</p>\n',
  12245. type: 'Number',
  12246. optional: true
  12247. },
  12248. {
  12249. name: 'y',
  12250. description: '<p>the y component of the vector</p>\n',
  12251. type: 'Number',
  12252. optional: true
  12253. },
  12254. {
  12255. name: 'z',
  12256. description: '<p>the z component of the vector</p>\n',
  12257. type: 'Number',
  12258. optional: true
  12259. }
  12260. ]
  12261. },
  12262. {
  12263. params: [
  12264. {
  12265. name: 'value',
  12266. description: '<p>the vector to compare</p>\n',
  12267. type: 'p5.Vector|Array'
  12268. }
  12269. ]
  12270. }
  12271. ]
  12272. },
  12273. fromAngle: {
  12274. name: 'fromAngle',
  12275. params: [
  12276. {
  12277. name: 'angle',
  12278. description:
  12279. '<p>the desired angle, in radians (unaffected by <a href="#/p5/angleMode">angleMode</a>)</p>\n',
  12280. type: 'Number'
  12281. },
  12282. {
  12283. name: 'length',
  12284. description: '<p>the length of the new vector (defaults to 1)</p>\n',
  12285. type: 'Number',
  12286. optional: true
  12287. }
  12288. ],
  12289. class: 'p5.Vector',
  12290. module: 'Math'
  12291. },
  12292. fromAngles: {
  12293. name: 'fromAngles',
  12294. params: [
  12295. {
  12296. name: 'theta',
  12297. description: '<p>the polar angle, in radians (zero is up)</p>\n',
  12298. type: 'Number'
  12299. },
  12300. {
  12301. name: 'phi',
  12302. description:
  12303. '<p>the azimuthal angle, in radians\n (zero is out of the screen)</p>\n',
  12304. type: 'Number'
  12305. },
  12306. {
  12307. name: 'length',
  12308. description: '<p>the length of the new vector (defaults to 1)</p>\n',
  12309. type: 'Number',
  12310. optional: true
  12311. }
  12312. ],
  12313. class: 'p5.Vector',
  12314. module: 'Math'
  12315. },
  12316. random2D: {
  12317. name: 'random2D',
  12318. class: 'p5.Vector',
  12319. module: 'Math'
  12320. },
  12321. random3D: {
  12322. name: 'random3D',
  12323. class: 'p5.Vector',
  12324. module: 'Math'
  12325. }
  12326. },
  12327. 'p5.Font': {
  12328. font: {
  12329. name: 'font',
  12330. class: 'p5.Font',
  12331. module: 'Typography'
  12332. },
  12333. textBounds: {
  12334. name: 'textBounds',
  12335. params: [
  12336. {
  12337. name: 'line',
  12338. description: '<p>a line of text</p>\n',
  12339. type: 'String'
  12340. },
  12341. {
  12342. name: 'x',
  12343. description: '<p>x-position</p>\n',
  12344. type: 'Number'
  12345. },
  12346. {
  12347. name: 'y',
  12348. description: '<p>y-position</p>\n',
  12349. type: 'Number'
  12350. },
  12351. {
  12352. name: 'fontSize',
  12353. description: '<p>font size to use (optional) Default is 12.</p>\n',
  12354. type: 'Number',
  12355. optional: true
  12356. },
  12357. {
  12358. name: 'options',
  12359. description:
  12360. "<p>opentype options (optional)\n opentype fonts contains alignment and baseline options.\n Default is 'LEFT' and 'alphabetic'</p>\n",
  12361. type: 'Object',
  12362. optional: true
  12363. }
  12364. ],
  12365. class: 'p5.Font',
  12366. module: 'Typography'
  12367. },
  12368. textToPoints: {
  12369. name: 'textToPoints',
  12370. params: [
  12371. {
  12372. name: 'txt',
  12373. description: '<p>a line of text</p>\n',
  12374. type: 'String'
  12375. },
  12376. {
  12377. name: 'x',
  12378. description: '<p>x-position</p>\n',
  12379. type: 'Number'
  12380. },
  12381. {
  12382. name: 'y',
  12383. description: '<p>y-position</p>\n',
  12384. type: 'Number'
  12385. },
  12386. {
  12387. name: 'fontSize',
  12388. description: '<p>font size to use (optional)</p>\n',
  12389. type: 'Number'
  12390. },
  12391. {
  12392. name: 'options',
  12393. description:
  12394. '<p>an (optional) object that can contain:</p>\n<p><br>sampleFactor - the ratio of path-length to number of samples\n(default=.1); higher values yield more points and are therefore\nmore precise</p>\n<p><br>simplifyThreshold - if set to a non-zero value, collinear points will be\nbe removed from the polygon; the value represents the threshold angle to use\nwhen determining whether two edges are collinear</p>\n',
  12395. type: 'Object',
  12396. optional: true
  12397. }
  12398. ],
  12399. class: 'p5.Font',
  12400. module: 'Typography'
  12401. }
  12402. },
  12403. 'p5.Camera': {
  12404. eyeX: {
  12405. name: 'eyeX',
  12406. class: 'p5.Camera',
  12407. module: 'Lights, Camera'
  12408. },
  12409. eyeY: {
  12410. name: 'eyeY',
  12411. class: 'p5.Camera',
  12412. module: 'Lights, Camera'
  12413. },
  12414. eyeZ: {
  12415. name: 'eyeZ',
  12416. class: 'p5.Camera',
  12417. module: 'Lights, Camera'
  12418. },
  12419. centerX: {
  12420. name: 'centerX',
  12421. class: 'p5.Camera',
  12422. module: 'Lights, Camera'
  12423. },
  12424. centerY: {
  12425. name: 'centerY',
  12426. class: 'p5.Camera',
  12427. module: 'Lights, Camera'
  12428. },
  12429. centerZ: {
  12430. name: 'centerZ',
  12431. class: 'p5.Camera',
  12432. module: 'Lights, Camera'
  12433. },
  12434. upX: {
  12435. name: 'upX',
  12436. class: 'p5.Camera',
  12437. module: 'Lights, Camera'
  12438. },
  12439. upY: {
  12440. name: 'upY',
  12441. class: 'p5.Camera',
  12442. module: 'Lights, Camera'
  12443. },
  12444. upZ: {
  12445. name: 'upZ',
  12446. class: 'p5.Camera',
  12447. module: 'Lights, Camera'
  12448. },
  12449. perspective: {
  12450. name: 'perspective',
  12451. class: 'p5.Camera',
  12452. module: 'Lights, Camera'
  12453. },
  12454. ortho: {
  12455. name: 'ortho',
  12456. class: 'p5.Camera',
  12457. module: 'Lights, Camera'
  12458. },
  12459. frustum: {
  12460. name: 'frustum',
  12461. class: 'p5.Camera',
  12462. module: 'Lights, Camera'
  12463. },
  12464. pan: {
  12465. name: 'pan',
  12466. params: [
  12467. {
  12468. name: 'angle',
  12469. description:
  12470. '<p>amount to rotate camera in current\n<a href="#/p5/angleMode">angleMode</a> units.\nGreater than 0 values rotate counterclockwise (to the left).</p>\n',
  12471. type: 'Number'
  12472. }
  12473. ],
  12474. class: 'p5.Camera',
  12475. module: 'Lights, Camera'
  12476. },
  12477. tilt: {
  12478. name: 'tilt',
  12479. params: [
  12480. {
  12481. name: 'angle',
  12482. description:
  12483. '<p>amount to rotate camera in current\n<a href="#/p5/angleMode">angleMode</a> units.\nGreater than 0 values rotate counterclockwise (to the left).</p>\n',
  12484. type: 'Number'
  12485. }
  12486. ],
  12487. class: 'p5.Camera',
  12488. module: 'Lights, Camera'
  12489. },
  12490. lookAt: {
  12491. name: 'lookAt',
  12492. params: [
  12493. {
  12494. name: 'x',
  12495. description: '<p>x position of a point in world space</p>\n',
  12496. type: 'Number'
  12497. },
  12498. {
  12499. name: 'y',
  12500. description: '<p>y position of a point in world space</p>\n',
  12501. type: 'Number'
  12502. },
  12503. {
  12504. name: 'z',
  12505. description: '<p>z position of a point in world space</p>\n',
  12506. type: 'Number'
  12507. }
  12508. ],
  12509. class: 'p5.Camera',
  12510. module: 'Lights, Camera'
  12511. },
  12512. camera: {
  12513. name: 'camera',
  12514. class: 'p5.Camera',
  12515. module: 'Lights, Camera'
  12516. },
  12517. move: {
  12518. name: 'move',
  12519. params: [
  12520. {
  12521. name: 'x',
  12522. description: "<p>amount to move along camera's left-right axis</p>\n",
  12523. type: 'Number'
  12524. },
  12525. {
  12526. name: 'y',
  12527. description: "<p>amount to move along camera's up-down axis</p>\n",
  12528. type: 'Number'
  12529. },
  12530. {
  12531. name: 'z',
  12532. description:
  12533. "<p>amount to move along camera's forward-backward axis</p>\n",
  12534. type: 'Number'
  12535. }
  12536. ],
  12537. class: 'p5.Camera',
  12538. module: 'Lights, Camera'
  12539. },
  12540. setPosition: {
  12541. name: 'setPosition',
  12542. params: [
  12543. {
  12544. name: 'x',
  12545. description: '<p>x position of a point in world space</p>\n',
  12546. type: 'Number'
  12547. },
  12548. {
  12549. name: 'y',
  12550. description: '<p>y position of a point in world space</p>\n',
  12551. type: 'Number'
  12552. },
  12553. {
  12554. name: 'z',
  12555. description: '<p>z position of a point in world space</p>\n',
  12556. type: 'Number'
  12557. }
  12558. ],
  12559. class: 'p5.Camera',
  12560. module: 'Lights, Camera'
  12561. }
  12562. },
  12563. 'p5.Geometry': {
  12564. computeFaces: {
  12565. name: 'computeFaces',
  12566. class: 'p5.Geometry',
  12567. module: 'Shape'
  12568. },
  12569. computeNormals: {
  12570. name: 'computeNormals',
  12571. class: 'p5.Geometry',
  12572. module: 'Shape'
  12573. },
  12574. averageNormals: {
  12575. name: 'averageNormals',
  12576. class: 'p5.Geometry',
  12577. module: 'Shape'
  12578. },
  12579. averagePoleNormals: {
  12580. name: 'averagePoleNormals',
  12581. class: 'p5.Geometry',
  12582. module: 'Shape'
  12583. },
  12584. normalize: {
  12585. name: 'normalize',
  12586. class: 'p5.Geometry',
  12587. module: 'Shape'
  12588. }
  12589. },
  12590. 'p5.Shader': {
  12591. setUniform: {
  12592. name: 'setUniform',
  12593. params: [
  12594. {
  12595. name: 'uniformName',
  12596. description: '<p>the name of the uniform in the\nshader program</p>\n',
  12597. type: 'String'
  12598. },
  12599. {
  12600. name: 'data',
  12601. description:
  12602. '<p>the data to be associated\nwith that uniform; type varies (could be a single numerical value, array,\nmatrix, or texture / sampler reference)</p>\n',
  12603. type: 'Object|Number|Boolean|Number[]'
  12604. }
  12605. ],
  12606. class: 'p5.Shader',
  12607. module: 'Lights, Camera'
  12608. }
  12609. },
  12610. 'p5.SoundFile': {
  12611. isLoaded: {
  12612. name: 'isLoaded',
  12613. class: 'p5.SoundFile',
  12614. module: 'p5.sound'
  12615. },
  12616. play: {
  12617. name: 'play',
  12618. params: [
  12619. {
  12620. name: 'startTime',
  12621. description:
  12622. '<p>(optional) schedule playback to start (in seconds from now).</p>\n',
  12623. type: 'Number',
  12624. optional: true
  12625. },
  12626. {
  12627. name: 'rate',
  12628. description: '<p>(optional) playback rate</p>\n',
  12629. type: 'Number',
  12630. optional: true
  12631. },
  12632. {
  12633. name: 'amp',
  12634. description:
  12635. '<p>(optional) amplitude (volume)\n of playback</p>\n',
  12636. type: 'Number',
  12637. optional: true
  12638. },
  12639. {
  12640. name: 'cueStart',
  12641. description: '<p>(optional) cue start time in seconds</p>\n',
  12642. type: 'Number',
  12643. optional: true
  12644. },
  12645. {
  12646. name: 'duration',
  12647. description: '<p>(optional) duration of playback in seconds</p>\n',
  12648. type: 'Number',
  12649. optional: true
  12650. }
  12651. ],
  12652. class: 'p5.SoundFile',
  12653. module: 'p5.sound'
  12654. },
  12655. playMode: {
  12656. name: 'playMode',
  12657. params: [
  12658. {
  12659. name: 'str',
  12660. description: "<p>'restart' or 'sustain' or 'untilDone'</p>\n",
  12661. type: 'String'
  12662. }
  12663. ],
  12664. class: 'p5.SoundFile',
  12665. module: 'p5.sound'
  12666. },
  12667. pause: {
  12668. name: 'pause',
  12669. params: [
  12670. {
  12671. name: 'startTime',
  12672. description:
  12673. '<p>(optional) schedule event to occur\n seconds from now</p>\n',
  12674. type: 'Number',
  12675. optional: true
  12676. }
  12677. ],
  12678. class: 'p5.SoundFile',
  12679. module: 'p5.sound'
  12680. },
  12681. loop: {
  12682. name: 'loop',
  12683. params: [
  12684. {
  12685. name: 'startTime',
  12686. description:
  12687. '<p>(optional) schedule event to occur\n seconds from now</p>\n',
  12688. type: 'Number',
  12689. optional: true
  12690. },
  12691. {
  12692. name: 'rate',
  12693. description: '<p>(optional) playback rate</p>\n',
  12694. type: 'Number',
  12695. optional: true
  12696. },
  12697. {
  12698. name: 'amp',
  12699. description: '<p>(optional) playback volume</p>\n',
  12700. type: 'Number',
  12701. optional: true
  12702. },
  12703. {
  12704. name: 'cueLoopStart',
  12705. description: '<p>(optional) startTime in seconds</p>\n',
  12706. type: 'Number',
  12707. optional: true
  12708. },
  12709. {
  12710. name: 'duration',
  12711. description: '<p>(optional) loop duration in seconds</p>\n',
  12712. type: 'Number',
  12713. optional: true
  12714. }
  12715. ],
  12716. class: 'p5.SoundFile',
  12717. module: 'p5.sound'
  12718. },
  12719. setLoop: {
  12720. name: 'setLoop',
  12721. params: [
  12722. {
  12723. name: 'Boolean',
  12724. description: '<p>set looping to true or false</p>\n',
  12725. type: 'Boolean'
  12726. }
  12727. ],
  12728. class: 'p5.SoundFile',
  12729. module: 'p5.sound'
  12730. },
  12731. isLooping: {
  12732. name: 'isLooping',
  12733. class: 'p5.SoundFile',
  12734. module: 'p5.sound'
  12735. },
  12736. isPlaying: {
  12737. name: 'isPlaying',
  12738. class: 'p5.SoundFile',
  12739. module: 'p5.sound'
  12740. },
  12741. isPaused: {
  12742. name: 'isPaused',
  12743. class: 'p5.SoundFile',
  12744. module: 'p5.sound'
  12745. },
  12746. stop: {
  12747. name: 'stop',
  12748. params: [
  12749. {
  12750. name: 'startTime',
  12751. description:
  12752. '<p>(optional) schedule event to occur\n in seconds from now</p>\n',
  12753. type: 'Number',
  12754. optional: true
  12755. }
  12756. ],
  12757. class: 'p5.SoundFile',
  12758. module: 'p5.sound'
  12759. },
  12760. pan: {
  12761. name: 'pan',
  12762. params: [
  12763. {
  12764. name: 'panValue',
  12765. description: '<p>Set the stereo panner</p>\n',
  12766. type: 'Number',
  12767. optional: true
  12768. },
  12769. {
  12770. name: 'timeFromNow',
  12771. description:
  12772. '<p>schedule this event to happen\n seconds from now</p>\n',
  12773. type: 'Number',
  12774. optional: true
  12775. }
  12776. ],
  12777. class: 'p5.SoundFile',
  12778. module: 'p5.sound'
  12779. },
  12780. getPan: {
  12781. name: 'getPan',
  12782. class: 'p5.SoundFile',
  12783. module: 'p5.sound'
  12784. },
  12785. rate: {
  12786. name: 'rate',
  12787. params: [
  12788. {
  12789. name: 'playbackRate',
  12790. description:
  12791. '<p>Set the playback rate. 1.0 is normal,\n .5 is half-speed, 2.0 is twice as fast.\n Values less than zero play backwards.</p>\n',
  12792. type: 'Number',
  12793. optional: true
  12794. }
  12795. ],
  12796. class: 'p5.SoundFile',
  12797. module: 'p5.sound'
  12798. },
  12799. setVolume: {
  12800. name: 'setVolume',
  12801. params: [
  12802. {
  12803. name: 'volume',
  12804. description:
  12805. '<p>Volume (amplitude) between 0.0\n and 1.0 or modulating signal/oscillator</p>\n',
  12806. type: 'Number|Object'
  12807. },
  12808. {
  12809. name: 'rampTime',
  12810. description: '<p>Fade for t seconds</p>\n',
  12811. type: 'Number',
  12812. optional: true
  12813. },
  12814. {
  12815. name: 'timeFromNow',
  12816. description:
  12817. '<p>Schedule this event to happen at\n t seconds in the future</p>\n',
  12818. type: 'Number',
  12819. optional: true
  12820. }
  12821. ],
  12822. class: 'p5.SoundFile',
  12823. module: 'p5.sound'
  12824. },
  12825. duration: {
  12826. name: 'duration',
  12827. class: 'p5.SoundFile',
  12828. module: 'p5.sound'
  12829. },
  12830. currentTime: {
  12831. name: 'currentTime',
  12832. class: 'p5.SoundFile',
  12833. module: 'p5.sound'
  12834. },
  12835. jump: {
  12836. name: 'jump',
  12837. params: [
  12838. {
  12839. name: 'cueTime',
  12840. description: '<p>cueTime of the soundFile in seconds.</p>\n',
  12841. type: 'Number'
  12842. },
  12843. {
  12844. name: 'duration',
  12845. description: '<p>duration in seconds.</p>\n',
  12846. type: 'Number'
  12847. }
  12848. ],
  12849. class: 'p5.SoundFile',
  12850. module: 'p5.sound'
  12851. },
  12852. channels: {
  12853. name: 'channels',
  12854. class: 'p5.SoundFile',
  12855. module: 'p5.sound'
  12856. },
  12857. sampleRate: {
  12858. name: 'sampleRate',
  12859. class: 'p5.SoundFile',
  12860. module: 'p5.sound'
  12861. },
  12862. frames: {
  12863. name: 'frames',
  12864. class: 'p5.SoundFile',
  12865. module: 'p5.sound'
  12866. },
  12867. getPeaks: {
  12868. name: 'getPeaks',
  12869. params: [
  12870. {
  12871. name: 'length',
  12872. description:
  12873. '<p>length is the size of the returned array.\n Larger length results in more precision.\n Defaults to 5*width of the browser window.</p>\n',
  12874. type: 'Number',
  12875. optional: true
  12876. }
  12877. ],
  12878. class: 'p5.SoundFile',
  12879. module: 'p5.sound'
  12880. },
  12881. reverseBuffer: {
  12882. name: 'reverseBuffer',
  12883. class: 'p5.SoundFile',
  12884. module: 'p5.sound'
  12885. },
  12886. onended: {
  12887. name: 'onended',
  12888. params: [
  12889. {
  12890. name: 'callback',
  12891. description:
  12892. '<p>function to call when the\n soundfile has ended.</p>\n',
  12893. type: 'Function'
  12894. }
  12895. ],
  12896. class: 'p5.SoundFile',
  12897. module: 'p5.sound'
  12898. },
  12899. connect: {
  12900. name: 'connect',
  12901. params: [
  12902. {
  12903. name: 'object',
  12904. description: '<p>Audio object that accepts an input</p>\n',
  12905. type: 'Object',
  12906. optional: true
  12907. }
  12908. ],
  12909. class: 'p5.SoundFile',
  12910. module: 'p5.sound'
  12911. },
  12912. disconnect: {
  12913. name: 'disconnect',
  12914. class: 'p5.SoundFile',
  12915. module: 'p5.sound'
  12916. },
  12917. setPath: {
  12918. name: 'setPath',
  12919. params: [
  12920. {
  12921. name: 'path',
  12922. description: '<p>path to audio file</p>\n',
  12923. type: 'String'
  12924. },
  12925. {
  12926. name: 'callback',
  12927. description: '<p>Callback</p>\n',
  12928. type: 'Function'
  12929. }
  12930. ],
  12931. class: 'p5.SoundFile',
  12932. module: 'p5.sound'
  12933. },
  12934. setBuffer: {
  12935. name: 'setBuffer',
  12936. params: [
  12937. {
  12938. name: 'buf',
  12939. description:
  12940. '<p>Array of Float32 Array(s). 2 Float32 Arrays\n will create a stereo source. 1 will create\n a mono source.</p>\n',
  12941. type: 'Array'
  12942. }
  12943. ],
  12944. class: 'p5.SoundFile',
  12945. module: 'p5.sound'
  12946. },
  12947. addCue: {
  12948. name: 'addCue',
  12949. params: [
  12950. {
  12951. name: 'time',
  12952. description:
  12953. "<p>Time in seconds, relative to this media\n element's playback. For example, to trigger\n an event every time playback reaches two\n seconds, pass in the number 2. This will be\n passed as the first parameter to\n the callback function.</p>\n",
  12954. type: 'Number'
  12955. },
  12956. {
  12957. name: 'callback',
  12958. description:
  12959. '<p>Name of a function that will be\n called at the given time. The callback will\n receive time and (optionally) param as its\n two parameters.</p>\n',
  12960. type: 'Function'
  12961. },
  12962. {
  12963. name: 'value',
  12964. description:
  12965. '<p>An object to be passed as the\n second parameter to the\n callback function.</p>\n',
  12966. type: 'Object',
  12967. optional: true
  12968. }
  12969. ],
  12970. class: 'p5.SoundFile',
  12971. module: 'p5.sound'
  12972. },
  12973. removeCue: {
  12974. name: 'removeCue',
  12975. params: [
  12976. {
  12977. name: 'id',
  12978. description: '<p>ID of the cue, as returned by addCue</p>\n',
  12979. type: 'Number'
  12980. }
  12981. ],
  12982. class: 'p5.SoundFile',
  12983. module: 'p5.sound'
  12984. },
  12985. clearCues: {
  12986. name: 'clearCues',
  12987. class: 'p5.SoundFile',
  12988. module: 'p5.sound'
  12989. },
  12990. save: {
  12991. name: 'save',
  12992. params: [
  12993. {
  12994. name: 'fileName',
  12995. description: '<p>name of the resulting .wav file.</p>\n',
  12996. type: 'String',
  12997. optional: true
  12998. }
  12999. ],
  13000. class: 'p5.SoundFile',
  13001. module: 'p5.sound'
  13002. },
  13003. getBlob: {
  13004. name: 'getBlob',
  13005. class: 'p5.SoundFile',
  13006. module: 'p5.sound'
  13007. }
  13008. },
  13009. 'p5.Amplitude': {
  13010. setInput: {
  13011. name: 'setInput',
  13012. params: [
  13013. {
  13014. name: 'snd',
  13015. description:
  13016. '<p>set the sound source\n (optional, defaults to\n main output)</p>\n',
  13017. type: 'SoundObject|undefined',
  13018. optional: true
  13019. },
  13020. {
  13021. name: 'smoothing',
  13022. description:
  13023. '<p>a range between 0.0 and 1.0\n to smooth amplitude readings</p>\n',
  13024. type: 'Number|undefined',
  13025. optional: true
  13026. }
  13027. ],
  13028. class: 'p5.Amplitude',
  13029. module: 'p5.sound'
  13030. },
  13031. getLevel: {
  13032. name: 'getLevel',
  13033. params: [
  13034. {
  13035. name: 'channel',
  13036. description:
  13037. '<p>Optionally return only channel 0 (left) or 1 (right)</p>\n',
  13038. type: 'Number',
  13039. optional: true
  13040. }
  13041. ],
  13042. class: 'p5.Amplitude',
  13043. module: 'p5.sound'
  13044. },
  13045. toggleNormalize: {
  13046. name: 'toggleNormalize',
  13047. params: [
  13048. {
  13049. name: 'boolean',
  13050. description: '<p>set normalize to true (1) or false (0)</p>\n',
  13051. type: 'Boolean',
  13052. optional: true
  13053. }
  13054. ],
  13055. class: 'p5.Amplitude',
  13056. module: 'p5.sound'
  13057. },
  13058. smooth: {
  13059. name: 'smooth',
  13060. params: [
  13061. {
  13062. name: 'set',
  13063. description: '<p>smoothing from 0.0 <= 1</p>\n',
  13064. type: 'Number'
  13065. }
  13066. ],
  13067. class: 'p5.Amplitude',
  13068. module: 'p5.sound'
  13069. }
  13070. },
  13071. 'p5.FFT': {
  13072. setInput: {
  13073. name: 'setInput',
  13074. params: [
  13075. {
  13076. name: 'source',
  13077. description: '<p>p5.sound object (or web audio API source node)</p>\n',
  13078. type: 'Object',
  13079. optional: true
  13080. }
  13081. ],
  13082. class: 'p5.FFT',
  13083. module: 'p5.sound'
  13084. },
  13085. waveform: {
  13086. name: 'waveform',
  13087. params: [
  13088. {
  13089. name: 'bins',
  13090. description:
  13091. '<p>Must be a power of two between\n 16 and 1024. Defaults to 1024.</p>\n',
  13092. type: 'Number',
  13093. optional: true
  13094. },
  13095. {
  13096. name: 'precision',
  13097. description:
  13098. '<p>If any value is provided, will return results\n in a Float32 Array which is more precise\n than a regular array.</p>\n',
  13099. type: 'String',
  13100. optional: true
  13101. }
  13102. ],
  13103. class: 'p5.FFT',
  13104. module: 'p5.sound'
  13105. },
  13106. analyze: {
  13107. name: 'analyze',
  13108. params: [
  13109. {
  13110. name: 'bins',
  13111. description:
  13112. '<p>Must be a power of two between\n 16 and 1024. Defaults to 1024.</p>\n',
  13113. type: 'Number',
  13114. optional: true
  13115. },
  13116. {
  13117. name: 'scale',
  13118. description:
  13119. '<p>If "dB," returns decibel\n float measurements between\n -140 and 0 (max).\n Otherwise returns integers from 0-255.</p>\n',
  13120. type: 'Number',
  13121. optional: true
  13122. }
  13123. ],
  13124. class: 'p5.FFT',
  13125. module: 'p5.sound'
  13126. },
  13127. getEnergy: {
  13128. name: 'getEnergy',
  13129. params: [
  13130. {
  13131. name: 'frequency1',
  13132. description:
  13133. '<p>Will return a value representing\n energy at this frequency. Alternately,\n the strings "bass", "lowMid" "mid",\n "highMid", and "treble" will return\n predefined frequency ranges.</p>\n',
  13134. type: 'Number|String'
  13135. },
  13136. {
  13137. name: 'frequency2',
  13138. description:
  13139. '<p>If a second frequency is given,\n will return average amount of\n energy that exists between the\n two frequencies.</p>\n',
  13140. type: 'Number',
  13141. optional: true
  13142. }
  13143. ],
  13144. class: 'p5.FFT',
  13145. module: 'p5.sound'
  13146. },
  13147. getCentroid: {
  13148. name: 'getCentroid',
  13149. class: 'p5.FFT',
  13150. module: 'p5.sound'
  13151. },
  13152. smooth: {
  13153. name: 'smooth',
  13154. params: [
  13155. {
  13156. name: 'smoothing',
  13157. description:
  13158. '<p>0.0 < smoothing < 1.0.\n Defaults to 0.8.</p>\n',
  13159. type: 'Number'
  13160. }
  13161. ],
  13162. class: 'p5.FFT',
  13163. module: 'p5.sound'
  13164. },
  13165. linAverages: {
  13166. name: 'linAverages',
  13167. params: [
  13168. {
  13169. name: 'N',
  13170. description: '<p>Number of returned frequency groups</p>\n',
  13171. type: 'Number'
  13172. }
  13173. ],
  13174. class: 'p5.FFT',
  13175. module: 'p5.sound'
  13176. },
  13177. logAverages: {
  13178. name: 'logAverages',
  13179. params: [
  13180. {
  13181. name: 'octaveBands',
  13182. description: '<p>Array of Octave Bands objects for grouping</p>\n',
  13183. type: 'Array'
  13184. }
  13185. ],
  13186. class: 'p5.FFT',
  13187. module: 'p5.sound'
  13188. },
  13189. getOctaveBands: {
  13190. name: 'getOctaveBands',
  13191. params: [
  13192. {
  13193. name: 'N',
  13194. description:
  13195. '<p>Specifies the 1/N type of generated octave bands</p>\n',
  13196. type: 'Number'
  13197. },
  13198. {
  13199. name: 'fCtr0',
  13200. description: '<p>Minimum central frequency for the lowest band</p>\n',
  13201. type: 'Number'
  13202. }
  13203. ],
  13204. class: 'p5.FFT',
  13205. module: 'p5.sound'
  13206. }
  13207. },
  13208. 'p5.Oscillator': {
  13209. start: {
  13210. name: 'start',
  13211. params: [
  13212. {
  13213. name: 'time',
  13214. description: '<p>startTime in seconds from now.</p>\n',
  13215. type: 'Number',
  13216. optional: true
  13217. },
  13218. {
  13219. name: 'frequency',
  13220. description: '<p>frequency in Hz.</p>\n',
  13221. type: 'Number',
  13222. optional: true
  13223. }
  13224. ],
  13225. class: 'p5.Oscillator',
  13226. module: 'p5.sound'
  13227. },
  13228. stop: {
  13229. name: 'stop',
  13230. params: [
  13231. {
  13232. name: 'secondsFromNow',
  13233. description: '<p>Time, in seconds from now.</p>\n',
  13234. type: 'Number'
  13235. }
  13236. ],
  13237. class: 'p5.Oscillator',
  13238. module: 'p5.sound'
  13239. },
  13240. amp: {
  13241. name: 'amp',
  13242. params: [
  13243. {
  13244. name: 'vol',
  13245. description:
  13246. '<p>between 0 and 1.0\n or a modulating signal/oscillator</p>\n',
  13247. type: 'Number|Object'
  13248. },
  13249. {
  13250. name: 'rampTime',
  13251. description: '<p>create a fade that lasts rampTime</p>\n',
  13252. type: 'Number',
  13253. optional: true
  13254. },
  13255. {
  13256. name: 'timeFromNow',
  13257. description:
  13258. '<p>schedule this event to happen\n seconds from now</p>\n',
  13259. type: 'Number',
  13260. optional: true
  13261. }
  13262. ],
  13263. class: 'p5.Oscillator',
  13264. module: 'p5.sound'
  13265. },
  13266. getAmp: {
  13267. name: 'getAmp',
  13268. class: 'p5.Oscillator',
  13269. module: 'p5.sound'
  13270. },
  13271. freq: {
  13272. name: 'freq',
  13273. params: [
  13274. {
  13275. name: 'Frequency',
  13276. description:
  13277. '<p>Frequency in Hz\n or modulating signal/oscillator</p>\n',
  13278. type: 'Number|Object'
  13279. },
  13280. {
  13281. name: 'rampTime',
  13282. description: '<p>Ramp time (in seconds)</p>\n',
  13283. type: 'Number',
  13284. optional: true
  13285. },
  13286. {
  13287. name: 'timeFromNow',
  13288. description:
  13289. '<p>Schedule this event to happen\n at x seconds from now</p>\n',
  13290. type: 'Number',
  13291. optional: true
  13292. }
  13293. ],
  13294. class: 'p5.Oscillator',
  13295. module: 'p5.sound'
  13296. },
  13297. getFreq: {
  13298. name: 'getFreq',
  13299. class: 'p5.Oscillator',
  13300. module: 'p5.sound'
  13301. },
  13302. setType: {
  13303. name: 'setType',
  13304. params: [
  13305. {
  13306. name: 'type',
  13307. description: "<p>'sine', 'triangle', 'sawtooth' or 'square'.</p>\n",
  13308. type: 'String'
  13309. }
  13310. ],
  13311. class: 'p5.Oscillator',
  13312. module: 'p5.sound'
  13313. },
  13314. getType: {
  13315. name: 'getType',
  13316. class: 'p5.Oscillator',
  13317. module: 'p5.sound'
  13318. },
  13319. connect: {
  13320. name: 'connect',
  13321. params: [
  13322. {
  13323. name: 'unit',
  13324. description: '<p>A p5.sound or Web Audio object</p>\n',
  13325. type: 'Object'
  13326. }
  13327. ],
  13328. class: 'p5.Oscillator',
  13329. module: 'p5.sound'
  13330. },
  13331. disconnect: {
  13332. name: 'disconnect',
  13333. class: 'p5.Oscillator',
  13334. module: 'p5.sound'
  13335. },
  13336. pan: {
  13337. name: 'pan',
  13338. params: [
  13339. {
  13340. name: 'panning',
  13341. description: '<p>Number between -1 and 1</p>\n',
  13342. type: 'Number'
  13343. },
  13344. {
  13345. name: 'timeFromNow',
  13346. description:
  13347. '<p>schedule this event to happen\n seconds from now</p>\n',
  13348. type: 'Number'
  13349. }
  13350. ],
  13351. class: 'p5.Oscillator',
  13352. module: 'p5.sound'
  13353. },
  13354. getPan: {
  13355. name: 'getPan',
  13356. class: 'p5.Oscillator',
  13357. module: 'p5.sound'
  13358. },
  13359. phase: {
  13360. name: 'phase',
  13361. params: [
  13362. {
  13363. name: 'phase',
  13364. description: '<p>float between 0.0 and 1.0</p>\n',
  13365. type: 'Number'
  13366. }
  13367. ],
  13368. class: 'p5.Oscillator',
  13369. module: 'p5.sound'
  13370. },
  13371. add: {
  13372. name: 'add',
  13373. params: [
  13374. {
  13375. name: 'number',
  13376. description: '<p>Constant number to add</p>\n',
  13377. type: 'Number'
  13378. }
  13379. ],
  13380. class: 'p5.Oscillator',
  13381. module: 'p5.sound'
  13382. },
  13383. mult: {
  13384. name: 'mult',
  13385. params: [
  13386. {
  13387. name: 'number',
  13388. description: '<p>Constant number to multiply</p>\n',
  13389. type: 'Number'
  13390. }
  13391. ],
  13392. class: 'p5.Oscillator',
  13393. module: 'p5.sound'
  13394. },
  13395. scale: {
  13396. name: 'scale',
  13397. params: [
  13398. {
  13399. name: 'inMin',
  13400. description: '<p>input range minumum</p>\n',
  13401. type: 'Number'
  13402. },
  13403. {
  13404. name: 'inMax',
  13405. description: '<p>input range maximum</p>\n',
  13406. type: 'Number'
  13407. },
  13408. {
  13409. name: 'outMin',
  13410. description: '<p>input range minumum</p>\n',
  13411. type: 'Number'
  13412. },
  13413. {
  13414. name: 'outMax',
  13415. description: '<p>input range maximum</p>\n',
  13416. type: 'Number'
  13417. }
  13418. ],
  13419. class: 'p5.Oscillator',
  13420. module: 'p5.sound'
  13421. }
  13422. },
  13423. 'p5.Envelope': {
  13424. attackTime: {
  13425. name: 'attackTime',
  13426. class: 'p5.Envelope',
  13427. module: 'p5.sound'
  13428. },
  13429. attackLevel: {
  13430. name: 'attackLevel',
  13431. class: 'p5.Envelope',
  13432. module: 'p5.sound'
  13433. },
  13434. decayTime: {
  13435. name: 'decayTime',
  13436. class: 'p5.Envelope',
  13437. module: 'p5.sound'
  13438. },
  13439. decayLevel: {
  13440. name: 'decayLevel',
  13441. class: 'p5.Envelope',
  13442. module: 'p5.sound'
  13443. },
  13444. releaseTime: {
  13445. name: 'releaseTime',
  13446. class: 'p5.Envelope',
  13447. module: 'p5.sound'
  13448. },
  13449. releaseLevel: {
  13450. name: 'releaseLevel',
  13451. class: 'p5.Envelope',
  13452. module: 'p5.sound'
  13453. },
  13454. set: {
  13455. name: 'set',
  13456. params: [
  13457. {
  13458. name: 'attackTime',
  13459. description:
  13460. '<p>Time (in seconds) before level\n reaches attackLevel</p>\n',
  13461. type: 'Number'
  13462. },
  13463. {
  13464. name: 'attackLevel',
  13465. description:
  13466. '<p>Typically an amplitude between\n 0.0 and 1.0</p>\n',
  13467. type: 'Number'
  13468. },
  13469. {
  13470. name: 'decayTime',
  13471. description: '<p>Time</p>\n',
  13472. type: 'Number'
  13473. },
  13474. {
  13475. name: 'decayLevel',
  13476. description:
  13477. '<p>Amplitude (In a standard ADSR envelope,\n decayLevel = sustainLevel)</p>\n',
  13478. type: 'Number'
  13479. },
  13480. {
  13481. name: 'releaseTime',
  13482. description: '<p>Release Time (in seconds)</p>\n',
  13483. type: 'Number'
  13484. },
  13485. {
  13486. name: 'releaseLevel',
  13487. description: '<p>Amplitude</p>\n',
  13488. type: 'Number'
  13489. }
  13490. ],
  13491. class: 'p5.Envelope',
  13492. module: 'p5.sound'
  13493. },
  13494. setADSR: {
  13495. name: 'setADSR',
  13496. params: [
  13497. {
  13498. name: 'attackTime',
  13499. description:
  13500. '<p>Time (in seconds before envelope\n reaches Attack Level</p>\n',
  13501. type: 'Number'
  13502. },
  13503. {
  13504. name: 'decayTime',
  13505. description:
  13506. '<p>Time (in seconds) before envelope\n reaches Decay/Sustain Level</p>\n',
  13507. type: 'Number',
  13508. optional: true
  13509. },
  13510. {
  13511. name: 'susRatio',
  13512. description:
  13513. '<p>Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using <code>setRange</code>),\n then decayLevel would increase proportionally, to become 0.5.</p>\n',
  13514. type: 'Number',
  13515. optional: true
  13516. },
  13517. {
  13518. name: 'releaseTime',
  13519. description: '<p>Time in seconds from now (defaults to 0)</p>\n',
  13520. type: 'Number',
  13521. optional: true
  13522. }
  13523. ],
  13524. class: 'p5.Envelope',
  13525. module: 'p5.sound'
  13526. },
  13527. setRange: {
  13528. name: 'setRange',
  13529. params: [
  13530. {
  13531. name: 'aLevel',
  13532. description: '<p>attack level (defaults to 1)</p>\n',
  13533. type: 'Number'
  13534. },
  13535. {
  13536. name: 'rLevel',
  13537. description: '<p>release level (defaults to 0)</p>\n',
  13538. type: 'Number'
  13539. }
  13540. ],
  13541. class: 'p5.Envelope',
  13542. module: 'p5.sound'
  13543. },
  13544. setInput: {
  13545. name: 'setInput',
  13546. params: [
  13547. {
  13548. name: 'inputs',
  13549. description:
  13550. '<p>A p5.sound object or\n Web Audio Param.</p>\n',
  13551. type: 'Object',
  13552. optional: true,
  13553. multiple: true
  13554. }
  13555. ],
  13556. class: 'p5.Envelope',
  13557. module: 'p5.sound'
  13558. },
  13559. setExp: {
  13560. name: 'setExp',
  13561. params: [
  13562. {
  13563. name: 'isExp',
  13564. description: '<p>true is exponential, false is linear</p>\n',
  13565. type: 'Boolean'
  13566. }
  13567. ],
  13568. class: 'p5.Envelope',
  13569. module: 'p5.sound'
  13570. },
  13571. play: {
  13572. name: 'play',
  13573. params: [
  13574. {
  13575. name: 'unit',
  13576. description:
  13577. '<p>A p5.sound object or\n Web Audio Param.</p>\n',
  13578. type: 'Object'
  13579. },
  13580. {
  13581. name: 'startTime',
  13582. description: '<p>time from now (in seconds) at which to play</p>\n',
  13583. type: 'Number',
  13584. optional: true
  13585. },
  13586. {
  13587. name: 'sustainTime',
  13588. description: '<p>time to sustain before releasing the envelope</p>\n',
  13589. type: 'Number',
  13590. optional: true
  13591. }
  13592. ],
  13593. class: 'p5.Envelope',
  13594. module: 'p5.sound'
  13595. },
  13596. triggerAttack: {
  13597. name: 'triggerAttack',
  13598. params: [
  13599. {
  13600. name: 'unit',
  13601. description: '<p>p5.sound Object or Web Audio Param</p>\n',
  13602. type: 'Object'
  13603. },
  13604. {
  13605. name: 'secondsFromNow',
  13606. description: '<p>time from now (in seconds)</p>\n',
  13607. type: 'Number'
  13608. }
  13609. ],
  13610. class: 'p5.Envelope',
  13611. module: 'p5.sound'
  13612. },
  13613. triggerRelease: {
  13614. name: 'triggerRelease',
  13615. params: [
  13616. {
  13617. name: 'unit',
  13618. description: '<p>p5.sound Object or Web Audio Param</p>\n',
  13619. type: 'Object'
  13620. },
  13621. {
  13622. name: 'secondsFromNow',
  13623. description: '<p>time to trigger the release</p>\n',
  13624. type: 'Number'
  13625. }
  13626. ],
  13627. class: 'p5.Envelope',
  13628. module: 'p5.sound'
  13629. },
  13630. ramp: {
  13631. name: 'ramp',
  13632. params: [
  13633. {
  13634. name: 'unit',
  13635. description: '<p>p5.sound Object or Web Audio Param</p>\n',
  13636. type: 'Object'
  13637. },
  13638. {
  13639. name: 'secondsFromNow',
  13640. description: '<p>When to trigger the ramp</p>\n',
  13641. type: 'Number'
  13642. },
  13643. {
  13644. name: 'v',
  13645. description: '<p>Target value</p>\n',
  13646. type: 'Number'
  13647. },
  13648. {
  13649. name: 'v2',
  13650. description: '<p>Second target value</p>\n',
  13651. type: 'Number',
  13652. optional: true
  13653. }
  13654. ],
  13655. class: 'p5.Envelope',
  13656. module: 'p5.sound'
  13657. },
  13658. add: {
  13659. name: 'add',
  13660. params: [
  13661. {
  13662. name: 'number',
  13663. description: '<p>Constant number to add</p>\n',
  13664. type: 'Number'
  13665. }
  13666. ],
  13667. class: 'p5.Envelope',
  13668. module: 'p5.sound'
  13669. },
  13670. mult: {
  13671. name: 'mult',
  13672. params: [
  13673. {
  13674. name: 'number',
  13675. description: '<p>Constant number to multiply</p>\n',
  13676. type: 'Number'
  13677. }
  13678. ],
  13679. class: 'p5.Envelope',
  13680. module: 'p5.sound'
  13681. },
  13682. scale: {
  13683. name: 'scale',
  13684. params: [
  13685. {
  13686. name: 'inMin',
  13687. description: '<p>input range minumum</p>\n',
  13688. type: 'Number'
  13689. },
  13690. {
  13691. name: 'inMax',
  13692. description: '<p>input range maximum</p>\n',
  13693. type: 'Number'
  13694. },
  13695. {
  13696. name: 'outMin',
  13697. description: '<p>input range minumum</p>\n',
  13698. type: 'Number'
  13699. },
  13700. {
  13701. name: 'outMax',
  13702. description: '<p>input range maximum</p>\n',
  13703. type: 'Number'
  13704. }
  13705. ],
  13706. class: 'p5.Envelope',
  13707. module: 'p5.sound'
  13708. }
  13709. },
  13710. 'p5.Noise': {
  13711. setType: {
  13712. name: 'setType',
  13713. params: [
  13714. {
  13715. name: 'type',
  13716. description: "<p>'white', 'pink' or 'brown'</p>\n",
  13717. type: 'String',
  13718. optional: true
  13719. }
  13720. ],
  13721. class: 'p5.Noise',
  13722. module: 'p5.sound'
  13723. }
  13724. },
  13725. 'p5.Pulse': {
  13726. width: {
  13727. name: 'width',
  13728. params: [
  13729. {
  13730. name: 'width',
  13731. description:
  13732. '<p>Width between the pulses (0 to 1.0,\n defaults to 0)</p>\n',
  13733. type: 'Number',
  13734. optional: true
  13735. }
  13736. ],
  13737. class: 'p5.Pulse',
  13738. module: 'p5.sound'
  13739. }
  13740. },
  13741. 'p5.AudioIn': {
  13742. input: {
  13743. name: 'input',
  13744. class: 'p5.AudioIn',
  13745. module: 'p5.sound'
  13746. },
  13747. output: {
  13748. name: 'output',
  13749. class: 'p5.AudioIn',
  13750. module: 'p5.sound'
  13751. },
  13752. stream: {
  13753. name: 'stream',
  13754. class: 'p5.AudioIn',
  13755. module: 'p5.sound'
  13756. },
  13757. mediaStream: {
  13758. name: 'mediaStream',
  13759. class: 'p5.AudioIn',
  13760. module: 'p5.sound'
  13761. },
  13762. currentSource: {
  13763. name: 'currentSource',
  13764. class: 'p5.AudioIn',
  13765. module: 'p5.sound'
  13766. },
  13767. enabled: {
  13768. name: 'enabled',
  13769. class: 'p5.AudioIn',
  13770. module: 'p5.sound'
  13771. },
  13772. amplitude: {
  13773. name: 'amplitude',
  13774. class: 'p5.AudioIn',
  13775. module: 'p5.sound'
  13776. },
  13777. start: {
  13778. name: 'start',
  13779. params: [
  13780. {
  13781. name: 'successCallback',
  13782. description:
  13783. '<p>Name of a function to call on\n success.</p>\n',
  13784. type: 'Function',
  13785. optional: true
  13786. },
  13787. {
  13788. name: 'errorCallback',
  13789. description:
  13790. '<p>Name of a function to call if\n there was an error. For example,\n some browsers do not support\n getUserMedia.</p>\n',
  13791. type: 'Function',
  13792. optional: true
  13793. }
  13794. ],
  13795. class: 'p5.AudioIn',
  13796. module: 'p5.sound'
  13797. },
  13798. stop: {
  13799. name: 'stop',
  13800. class: 'p5.AudioIn',
  13801. module: 'p5.sound'
  13802. },
  13803. connect: {
  13804. name: 'connect',
  13805. params: [
  13806. {
  13807. name: 'unit',
  13808. description:
  13809. '<p>An object that accepts audio input,\n such as an FFT</p>\n',
  13810. type: 'Object',
  13811. optional: true
  13812. }
  13813. ],
  13814. class: 'p5.AudioIn',
  13815. module: 'p5.sound'
  13816. },
  13817. disconnect: {
  13818. name: 'disconnect',
  13819. class: 'p5.AudioIn',
  13820. module: 'p5.sound'
  13821. },
  13822. getLevel: {
  13823. name: 'getLevel',
  13824. params: [
  13825. {
  13826. name: 'smoothing',
  13827. description:
  13828. '<p>Smoothing is 0.0 by default.\n Smooths values based on previous values.</p>\n',
  13829. type: 'Number',
  13830. optional: true
  13831. }
  13832. ],
  13833. class: 'p5.AudioIn',
  13834. module: 'p5.sound'
  13835. },
  13836. amp: {
  13837. name: 'amp',
  13838. params: [
  13839. {
  13840. name: 'vol',
  13841. description: '<p>between 0 and 1.0</p>\n',
  13842. type: 'Number'
  13843. },
  13844. {
  13845. name: 'time',
  13846. description: '<p>ramp time (optional)</p>\n',
  13847. type: 'Number',
  13848. optional: true
  13849. }
  13850. ],
  13851. class: 'p5.AudioIn',
  13852. module: 'p5.sound'
  13853. },
  13854. getSources: {
  13855. name: 'getSources',
  13856. params: [
  13857. {
  13858. name: 'successCallback',
  13859. description:
  13860. '<p>This callback function handles the sources when they\n have been enumerated. The callback function\n receives the deviceList array as its only argument</p>\n',
  13861. type: 'Function',
  13862. optional: true
  13863. },
  13864. {
  13865. name: 'errorCallback',
  13866. description:
  13867. '<p>This optional callback receives the error\n message as its argument.</p>\n',
  13868. type: 'Function',
  13869. optional: true
  13870. }
  13871. ],
  13872. class: 'p5.AudioIn',
  13873. module: 'p5.sound'
  13874. },
  13875. setSource: {
  13876. name: 'setSource',
  13877. params: [
  13878. {
  13879. name: 'num',
  13880. description: '<p>position of input source in the array</p>\n',
  13881. type: 'Number'
  13882. }
  13883. ],
  13884. class: 'p5.AudioIn',
  13885. module: 'p5.sound'
  13886. }
  13887. },
  13888. 'p5.Effect': {
  13889. amp: {
  13890. name: 'amp',
  13891. params: [
  13892. {
  13893. name: 'vol',
  13894. description: '<p>amplitude between 0 and 1.0</p>\n',
  13895. type: 'Number',
  13896. optional: true
  13897. },
  13898. {
  13899. name: 'rampTime',
  13900. description: '<p>create a fade that lasts until rampTime</p>\n',
  13901. type: 'Number',
  13902. optional: true
  13903. },
  13904. {
  13905. name: 'tFromNow',
  13906. description:
  13907. '<p>schedule this event to happen in tFromNow seconds</p>\n',
  13908. type: 'Number',
  13909. optional: true
  13910. }
  13911. ],
  13912. class: 'p5.Effect',
  13913. module: 'p5.sound'
  13914. },
  13915. chain: {
  13916. name: 'chain',
  13917. params: [
  13918. {
  13919. name: 'arguments',
  13920. description: '<p>Chain together multiple sound objects</p>\n',
  13921. type: 'Object',
  13922. optional: true
  13923. }
  13924. ],
  13925. class: 'p5.Effect',
  13926. module: 'p5.sound'
  13927. },
  13928. drywet: {
  13929. name: 'drywet',
  13930. params: [
  13931. {
  13932. name: 'fade',
  13933. description: '<p>The desired drywet value (0 - 1.0)</p>\n',
  13934. type: 'Number',
  13935. optional: true
  13936. }
  13937. ],
  13938. class: 'p5.Effect',
  13939. module: 'p5.sound'
  13940. },
  13941. connect: {
  13942. name: 'connect',
  13943. params: [
  13944. {
  13945. name: 'unit',
  13946. description: '',
  13947. type: 'Object'
  13948. }
  13949. ],
  13950. class: 'p5.Effect',
  13951. module: 'p5.sound'
  13952. },
  13953. disconnect: {
  13954. name: 'disconnect',
  13955. class: 'p5.Effect',
  13956. module: 'p5.sound'
  13957. }
  13958. },
  13959. 'p5.Filter': {
  13960. biquadFilter: {
  13961. name: 'biquadFilter',
  13962. class: 'p5.Filter',
  13963. module: 'p5.sound'
  13964. },
  13965. process: {
  13966. name: 'process',
  13967. params: [
  13968. {
  13969. name: 'Signal',
  13970. description: '<p>An object that outputs audio</p>\n',
  13971. type: 'Object'
  13972. },
  13973. {
  13974. name: 'freq',
  13975. description: '<p>Frequency in Hz, from 10 to 22050</p>\n',
  13976. type: 'Number',
  13977. optional: true
  13978. },
  13979. {
  13980. name: 'res',
  13981. description:
  13982. '<p>Resonance/Width of the filter frequency\n from 0.001 to 1000</p>\n',
  13983. type: 'Number',
  13984. optional: true
  13985. }
  13986. ],
  13987. class: 'p5.Filter',
  13988. module: 'p5.sound'
  13989. },
  13990. set: {
  13991. name: 'set',
  13992. params: [
  13993. {
  13994. name: 'freq',
  13995. description: '<p>Frequency in Hz, from 10 to 22050</p>\n',
  13996. type: 'Number',
  13997. optional: true
  13998. },
  13999. {
  14000. name: 'res',
  14001. description: '<p>Resonance (Q) from 0.001 to 1000</p>\n',
  14002. type: 'Number',
  14003. optional: true
  14004. },
  14005. {
  14006. name: 'timeFromNow',
  14007. description:
  14008. '<p>schedule this event to happen\n seconds from now</p>\n',
  14009. type: 'Number',
  14010. optional: true
  14011. }
  14012. ],
  14013. class: 'p5.Filter',
  14014. module: 'p5.sound'
  14015. },
  14016. freq: {
  14017. name: 'freq',
  14018. params: [
  14019. {
  14020. name: 'freq',
  14021. description: '<p>Filter Frequency</p>\n',
  14022. type: 'Number'
  14023. },
  14024. {
  14025. name: 'timeFromNow',
  14026. description:
  14027. '<p>schedule this event to happen\n seconds from now</p>\n',
  14028. type: 'Number',
  14029. optional: true
  14030. }
  14031. ],
  14032. class: 'p5.Filter',
  14033. module: 'p5.sound'
  14034. },
  14035. res: {
  14036. name: 'res',
  14037. params: [
  14038. {
  14039. name: 'res',
  14040. description:
  14041. '<p>Resonance/Width of filter freq\n from 0.001 to 1000</p>\n',
  14042. type: 'Number'
  14043. },
  14044. {
  14045. name: 'timeFromNow',
  14046. description:
  14047. '<p>schedule this event to happen\n seconds from now</p>\n',
  14048. type: 'Number',
  14049. optional: true
  14050. }
  14051. ],
  14052. class: 'p5.Filter',
  14053. module: 'p5.sound'
  14054. },
  14055. gain: {
  14056. name: 'gain',
  14057. params: [
  14058. {
  14059. name: 'gain',
  14060. description: '',
  14061. type: 'Number'
  14062. }
  14063. ],
  14064. class: 'p5.Filter',
  14065. module: 'p5.sound'
  14066. },
  14067. toggle: {
  14068. name: 'toggle',
  14069. class: 'p5.Filter',
  14070. module: 'p5.sound'
  14071. },
  14072. setType: {
  14073. name: 'setType',
  14074. params: [
  14075. {
  14076. name: 't',
  14077. description: '',
  14078. type: 'String'
  14079. }
  14080. ],
  14081. class: 'p5.Filter',
  14082. module: 'p5.sound'
  14083. }
  14084. },
  14085. 'p5.EQ': {
  14086. bands: {
  14087. name: 'bands',
  14088. class: 'p5.EQ',
  14089. module: 'p5.sound'
  14090. },
  14091. process: {
  14092. name: 'process',
  14093. params: [
  14094. {
  14095. name: 'src',
  14096. description: '<p>Audio source</p>\n',
  14097. type: 'Object'
  14098. }
  14099. ],
  14100. class: 'p5.EQ',
  14101. module: 'p5.sound'
  14102. }
  14103. },
  14104. 'p5.Panner3D': {
  14105. panner: {
  14106. name: 'panner',
  14107. class: 'p5.Panner3D',
  14108. module: 'p5.sound'
  14109. },
  14110. process: {
  14111. name: 'process',
  14112. params: [
  14113. {
  14114. name: 'src',
  14115. description: '<p>Input source</p>\n',
  14116. type: 'Object'
  14117. }
  14118. ],
  14119. class: 'p5.Panner3D',
  14120. module: 'p5.sound'
  14121. },
  14122. set: {
  14123. name: 'set',
  14124. params: [
  14125. {
  14126. name: 'xVal',
  14127. description: '',
  14128. type: 'Number'
  14129. },
  14130. {
  14131. name: 'yVal',
  14132. description: '',
  14133. type: 'Number'
  14134. },
  14135. {
  14136. name: 'zVal',
  14137. description: '',
  14138. type: 'Number'
  14139. },
  14140. {
  14141. name: 'time',
  14142. description: '',
  14143. type: 'Number'
  14144. }
  14145. ],
  14146. class: 'p5.Panner3D',
  14147. module: 'p5.sound'
  14148. },
  14149. positionX: {
  14150. name: 'positionX',
  14151. class: 'p5.Panner3D',
  14152. module: 'p5.sound'
  14153. },
  14154. positionY: {
  14155. name: 'positionY',
  14156. class: 'p5.Panner3D',
  14157. module: 'p5.sound'
  14158. },
  14159. positionZ: {
  14160. name: 'positionZ',
  14161. class: 'p5.Panner3D',
  14162. module: 'p5.sound'
  14163. },
  14164. orient: {
  14165. name: 'orient',
  14166. params: [
  14167. {
  14168. name: 'xVal',
  14169. description: '',
  14170. type: 'Number'
  14171. },
  14172. {
  14173. name: 'yVal',
  14174. description: '',
  14175. type: 'Number'
  14176. },
  14177. {
  14178. name: 'zVal',
  14179. description: '',
  14180. type: 'Number'
  14181. },
  14182. {
  14183. name: 'time',
  14184. description: '',
  14185. type: 'Number'
  14186. }
  14187. ],
  14188. class: 'p5.Panner3D',
  14189. module: 'p5.sound'
  14190. },
  14191. orientX: {
  14192. name: 'orientX',
  14193. class: 'p5.Panner3D',
  14194. module: 'p5.sound'
  14195. },
  14196. orientY: {
  14197. name: 'orientY',
  14198. class: 'p5.Panner3D',
  14199. module: 'p5.sound'
  14200. },
  14201. orientZ: {
  14202. name: 'orientZ',
  14203. class: 'p5.Panner3D',
  14204. module: 'p5.sound'
  14205. },
  14206. setFalloff: {
  14207. name: 'setFalloff',
  14208. params: [
  14209. {
  14210. name: 'maxDistance',
  14211. description: '',
  14212. type: 'Number',
  14213. optional: true
  14214. },
  14215. {
  14216. name: 'rolloffFactor',
  14217. description: '',
  14218. type: 'Number',
  14219. optional: true
  14220. }
  14221. ],
  14222. class: 'p5.Panner3D',
  14223. module: 'p5.sound'
  14224. },
  14225. maxDist: {
  14226. name: 'maxDist',
  14227. params: [
  14228. {
  14229. name: 'maxDistance',
  14230. description: '',
  14231. type: 'Number'
  14232. }
  14233. ],
  14234. class: 'p5.Panner3D',
  14235. module: 'p5.sound'
  14236. },
  14237. rollof: {
  14238. name: 'rollof',
  14239. params: [
  14240. {
  14241. name: 'rolloffFactor',
  14242. description: '',
  14243. type: 'Number'
  14244. }
  14245. ],
  14246. class: 'p5.Panner3D',
  14247. module: 'p5.sound'
  14248. }
  14249. },
  14250. 'p5.Delay': {
  14251. leftDelay: {
  14252. name: 'leftDelay',
  14253. class: 'p5.Delay',
  14254. module: 'p5.sound'
  14255. },
  14256. rightDelay: {
  14257. name: 'rightDelay',
  14258. class: 'p5.Delay',
  14259. module: 'p5.sound'
  14260. },
  14261. process: {
  14262. name: 'process',
  14263. params: [
  14264. {
  14265. name: 'Signal',
  14266. description: '<p>An object that outputs audio</p>\n',
  14267. type: 'Object'
  14268. },
  14269. {
  14270. name: 'delayTime',
  14271. description:
  14272. '<p>Time (in seconds) of the delay/echo.\n Some browsers limit delayTime to\n 1 second.</p>\n',
  14273. type: 'Number',
  14274. optional: true
  14275. },
  14276. {
  14277. name: 'feedback',
  14278. description:
  14279. '<p>sends the delay back through itself\n in a loop that decreases in volume\n each time.</p>\n',
  14280. type: 'Number',
  14281. optional: true
  14282. },
  14283. {
  14284. name: 'lowPass',
  14285. description:
  14286. '<p>Cutoff frequency. Only frequencies\n below the lowPass will be part of the\n delay.</p>\n',
  14287. type: 'Number',
  14288. optional: true
  14289. }
  14290. ],
  14291. class: 'p5.Delay',
  14292. module: 'p5.sound'
  14293. },
  14294. delayTime: {
  14295. name: 'delayTime',
  14296. params: [
  14297. {
  14298. name: 'delayTime',
  14299. description: '<p>Time (in seconds) of the delay</p>\n',
  14300. type: 'Number'
  14301. }
  14302. ],
  14303. class: 'p5.Delay',
  14304. module: 'p5.sound'
  14305. },
  14306. feedback: {
  14307. name: 'feedback',
  14308. params: [
  14309. {
  14310. name: 'feedback',
  14311. description:
  14312. '<p>0.0 to 1.0, or an object such as an\n Oscillator that can be used to\n modulate this param</p>\n',
  14313. type: 'Number|Object'
  14314. }
  14315. ],
  14316. class: 'p5.Delay',
  14317. module: 'p5.sound'
  14318. },
  14319. filter: {
  14320. name: 'filter',
  14321. params: [
  14322. {
  14323. name: 'cutoffFreq',
  14324. description:
  14325. '<p>A lowpass filter will cut off any\n frequencies higher than the filter frequency.</p>\n',
  14326. type: 'Number|Object'
  14327. },
  14328. {
  14329. name: 'res',
  14330. description:
  14331. '<p>Resonance of the filter frequency\n cutoff, or an object (i.e. a p5.Oscillator)\n that can be used to modulate this parameter.\n High numbers (i.e. 15) will produce a resonance,\n low numbers (i.e. .2) will produce a slope.</p>\n',
  14332. type: 'Number|Object'
  14333. }
  14334. ],
  14335. class: 'p5.Delay',
  14336. module: 'p5.sound'
  14337. },
  14338. setType: {
  14339. name: 'setType',
  14340. params: [
  14341. {
  14342. name: 'type',
  14343. description: "<p>'pingPong' (1) or 'default' (0)</p>\n",
  14344. type: 'String|Number'
  14345. }
  14346. ],
  14347. class: 'p5.Delay',
  14348. module: 'p5.sound'
  14349. },
  14350. amp: {
  14351. name: 'amp',
  14352. params: [
  14353. {
  14354. name: 'volume',
  14355. description: '<p>amplitude between 0 and 1.0</p>\n',
  14356. type: 'Number'
  14357. },
  14358. {
  14359. name: 'rampTime',
  14360. description: '<p>create a fade that lasts rampTime</p>\n',
  14361. type: 'Number',
  14362. optional: true
  14363. },
  14364. {
  14365. name: 'timeFromNow',
  14366. description:
  14367. '<p>schedule this event to happen\n seconds from now</p>\n',
  14368. type: 'Number',
  14369. optional: true
  14370. }
  14371. ],
  14372. class: 'p5.Delay',
  14373. module: 'p5.sound'
  14374. },
  14375. connect: {
  14376. name: 'connect',
  14377. params: [
  14378. {
  14379. name: 'unit',
  14380. description: '',
  14381. type: 'Object'
  14382. }
  14383. ],
  14384. class: 'p5.Delay',
  14385. module: 'p5.sound'
  14386. },
  14387. disconnect: {
  14388. name: 'disconnect',
  14389. class: 'p5.Delay',
  14390. module: 'p5.sound'
  14391. }
  14392. },
  14393. 'p5.Reverb': {
  14394. process: {
  14395. name: 'process',
  14396. params: [
  14397. {
  14398. name: 'src',
  14399. description:
  14400. '<p>p5.sound / Web Audio object with a sound\n output.</p>\n',
  14401. type: 'Object'
  14402. },
  14403. {
  14404. name: 'seconds',
  14405. description:
  14406. '<p>Duration of the reverb, in seconds.\n Min: 0, Max: 10. Defaults to 3.</p>\n',
  14407. type: 'Number',
  14408. optional: true
  14409. },
  14410. {
  14411. name: 'decayRate',
  14412. description:
  14413. '<p>Percentage of decay with each echo.\n Min: 0, Max: 100. Defaults to 2.</p>\n',
  14414. type: 'Number',
  14415. optional: true
  14416. },
  14417. {
  14418. name: 'reverse',
  14419. description: '<p>Play the reverb backwards or forwards.</p>\n',
  14420. type: 'Boolean',
  14421. optional: true
  14422. }
  14423. ],
  14424. class: 'p5.Reverb',
  14425. module: 'p5.sound'
  14426. },
  14427. set: {
  14428. name: 'set',
  14429. params: [
  14430. {
  14431. name: 'seconds',
  14432. description:
  14433. '<p>Duration of the reverb, in seconds.\n Min: 0, Max: 10. Defaults to 3.</p>\n',
  14434. type: 'Number',
  14435. optional: true
  14436. },
  14437. {
  14438. name: 'decayRate',
  14439. description:
  14440. '<p>Percentage of decay with each echo.\n Min: 0, Max: 100. Defaults to 2.</p>\n',
  14441. type: 'Number',
  14442. optional: true
  14443. },
  14444. {
  14445. name: 'reverse',
  14446. description: '<p>Play the reverb backwards or forwards.</p>\n',
  14447. type: 'Boolean',
  14448. optional: true
  14449. }
  14450. ],
  14451. class: 'p5.Reverb',
  14452. module: 'p5.sound'
  14453. },
  14454. amp: {
  14455. name: 'amp',
  14456. params: [
  14457. {
  14458. name: 'volume',
  14459. description: '<p>amplitude between 0 and 1.0</p>\n',
  14460. type: 'Number'
  14461. },
  14462. {
  14463. name: 'rampTime',
  14464. description: '<p>create a fade that lasts rampTime</p>\n',
  14465. type: 'Number',
  14466. optional: true
  14467. },
  14468. {
  14469. name: 'timeFromNow',
  14470. description:
  14471. '<p>schedule this event to happen\n seconds from now</p>\n',
  14472. type: 'Number',
  14473. optional: true
  14474. }
  14475. ],
  14476. class: 'p5.Reverb',
  14477. module: 'p5.sound'
  14478. },
  14479. connect: {
  14480. name: 'connect',
  14481. params: [
  14482. {
  14483. name: 'unit',
  14484. description: '',
  14485. type: 'Object'
  14486. }
  14487. ],
  14488. class: 'p5.Reverb',
  14489. module: 'p5.sound'
  14490. },
  14491. disconnect: {
  14492. name: 'disconnect',
  14493. class: 'p5.Reverb',
  14494. module: 'p5.sound'
  14495. }
  14496. },
  14497. 'p5.Convolver': {
  14498. convolverNode: {
  14499. name: 'convolverNode',
  14500. class: 'p5.Convolver',
  14501. module: 'p5.sound'
  14502. },
  14503. impulses: {
  14504. name: 'impulses',
  14505. class: 'p5.Convolver',
  14506. module: 'p5.sound'
  14507. },
  14508. process: {
  14509. name: 'process',
  14510. params: [
  14511. {
  14512. name: 'src',
  14513. description:
  14514. '<p>p5.sound / Web Audio object with a sound\n output.</p>\n',
  14515. type: 'Object'
  14516. }
  14517. ],
  14518. class: 'p5.Convolver',
  14519. module: 'p5.sound'
  14520. },
  14521. addImpulse: {
  14522. name: 'addImpulse',
  14523. params: [
  14524. {
  14525. name: 'path',
  14526. description: '<p>path to a sound file</p>\n',
  14527. type: 'String'
  14528. },
  14529. {
  14530. name: 'callback',
  14531. description: '<p>function (optional)</p>\n',
  14532. type: 'Function'
  14533. },
  14534. {
  14535. name: 'errorCallback',
  14536. description: '<p>function (optional)</p>\n',
  14537. type: 'Function'
  14538. }
  14539. ],
  14540. class: 'p5.Convolver',
  14541. module: 'p5.sound'
  14542. },
  14543. resetImpulse: {
  14544. name: 'resetImpulse',
  14545. params: [
  14546. {
  14547. name: 'path',
  14548. description: '<p>path to a sound file</p>\n',
  14549. type: 'String'
  14550. },
  14551. {
  14552. name: 'callback',
  14553. description: '<p>function (optional)</p>\n',
  14554. type: 'Function'
  14555. },
  14556. {
  14557. name: 'errorCallback',
  14558. description: '<p>function (optional)</p>\n',
  14559. type: 'Function'
  14560. }
  14561. ],
  14562. class: 'p5.Convolver',
  14563. module: 'p5.sound'
  14564. },
  14565. toggleImpulse: {
  14566. name: 'toggleImpulse',
  14567. params: [
  14568. {
  14569. name: 'id',
  14570. description:
  14571. '<p>Identify the impulse by its original filename\n (String), or by its position in the\n <code>.impulses</code> Array (Number).</p>\n',
  14572. type: 'String|Number'
  14573. }
  14574. ],
  14575. class: 'p5.Convolver',
  14576. module: 'p5.sound'
  14577. }
  14578. },
  14579. 'p5.Phrase': {
  14580. sequence: {
  14581. name: 'sequence',
  14582. class: 'p5.Phrase',
  14583. module: 'p5.sound'
  14584. }
  14585. },
  14586. 'p5.Part': {
  14587. setBPM: {
  14588. name: 'setBPM',
  14589. params: [
  14590. {
  14591. name: 'BPM',
  14592. description: '<p>Beats Per Minute</p>\n',
  14593. type: 'Number'
  14594. },
  14595. {
  14596. name: 'rampTime',
  14597. description: '<p>Seconds from now</p>\n',
  14598. type: 'Number',
  14599. optional: true
  14600. }
  14601. ],
  14602. class: 'p5.Part',
  14603. module: 'p5.sound'
  14604. },
  14605. getBPM: {
  14606. name: 'getBPM',
  14607. class: 'p5.Part',
  14608. module: 'p5.sound'
  14609. },
  14610. start: {
  14611. name: 'start',
  14612. params: [
  14613. {
  14614. name: 'time',
  14615. description: '<p>seconds from now</p>\n',
  14616. type: 'Number',
  14617. optional: true
  14618. }
  14619. ],
  14620. class: 'p5.Part',
  14621. module: 'p5.sound'
  14622. },
  14623. loop: {
  14624. name: 'loop',
  14625. params: [
  14626. {
  14627. name: 'time',
  14628. description: '<p>seconds from now</p>\n',
  14629. type: 'Number',
  14630. optional: true
  14631. }
  14632. ],
  14633. class: 'p5.Part',
  14634. module: 'p5.sound'
  14635. },
  14636. noLoop: {
  14637. name: 'noLoop',
  14638. class: 'p5.Part',
  14639. module: 'p5.sound'
  14640. },
  14641. stop: {
  14642. name: 'stop',
  14643. params: [
  14644. {
  14645. name: 'time',
  14646. description: '<p>seconds from now</p>\n',
  14647. type: 'Number',
  14648. optional: true
  14649. }
  14650. ],
  14651. class: 'p5.Part',
  14652. module: 'p5.sound'
  14653. },
  14654. pause: {
  14655. name: 'pause',
  14656. params: [
  14657. {
  14658. name: 'time',
  14659. description: '<p>seconds from now</p>\n',
  14660. type: 'Number'
  14661. }
  14662. ],
  14663. class: 'p5.Part',
  14664. module: 'p5.sound'
  14665. },
  14666. addPhrase: {
  14667. name: 'addPhrase',
  14668. params: [
  14669. {
  14670. name: 'phrase',
  14671. description: '<p>reference to a p5.Phrase</p>\n',
  14672. type: 'p5.Phrase'
  14673. }
  14674. ],
  14675. class: 'p5.Part',
  14676. module: 'p5.sound'
  14677. },
  14678. removePhrase: {
  14679. name: 'removePhrase',
  14680. params: [
  14681. {
  14682. name: 'phraseName',
  14683. description: '',
  14684. type: 'String'
  14685. }
  14686. ],
  14687. class: 'p5.Part',
  14688. module: 'p5.sound'
  14689. },
  14690. getPhrase: {
  14691. name: 'getPhrase',
  14692. params: [
  14693. {
  14694. name: 'phraseName',
  14695. description: '',
  14696. type: 'String'
  14697. }
  14698. ],
  14699. class: 'p5.Part',
  14700. module: 'p5.sound'
  14701. },
  14702. replaceSequence: {
  14703. name: 'replaceSequence',
  14704. params: [
  14705. {
  14706. name: 'phraseName',
  14707. description: '',
  14708. type: 'String'
  14709. },
  14710. {
  14711. name: 'sequence',
  14712. description:
  14713. '<p>Array of values to pass into the callback\n at each step of the phrase.</p>\n',
  14714. type: 'Array'
  14715. }
  14716. ],
  14717. class: 'p5.Part',
  14718. module: 'p5.sound'
  14719. },
  14720. onStep: {
  14721. name: 'onStep',
  14722. params: [
  14723. {
  14724. name: 'callback',
  14725. description:
  14726. '<p>The name of the callback\n you want to fire\n on every beat/tatum.</p>\n',
  14727. type: 'Function'
  14728. }
  14729. ],
  14730. class: 'p5.Part',
  14731. module: 'p5.sound'
  14732. }
  14733. },
  14734. 'p5.Score': {
  14735. start: {
  14736. name: 'start',
  14737. class: 'p5.Score',
  14738. module: 'p5.sound'
  14739. },
  14740. stop: {
  14741. name: 'stop',
  14742. class: 'p5.Score',
  14743. module: 'p5.sound'
  14744. },
  14745. pause: {
  14746. name: 'pause',
  14747. class: 'p5.Score',
  14748. module: 'p5.sound'
  14749. },
  14750. loop: {
  14751. name: 'loop',
  14752. class: 'p5.Score',
  14753. module: 'p5.sound'
  14754. },
  14755. noLoop: {
  14756. name: 'noLoop',
  14757. class: 'p5.Score',
  14758. module: 'p5.sound'
  14759. },
  14760. setBPM: {
  14761. name: 'setBPM',
  14762. params: [
  14763. {
  14764. name: 'BPM',
  14765. description: '<p>Beats Per Minute</p>\n',
  14766. type: 'Number'
  14767. },
  14768. {
  14769. name: 'rampTime',
  14770. description: '<p>Seconds from now</p>\n',
  14771. type: 'Number'
  14772. }
  14773. ],
  14774. class: 'p5.Score',
  14775. module: 'p5.sound'
  14776. }
  14777. },
  14778. 'p5.SoundLoop': {
  14779. bpm: {
  14780. name: 'bpm',
  14781. class: 'p5.SoundLoop',
  14782. module: 'p5.sound'
  14783. },
  14784. timeSignature: {
  14785. name: 'timeSignature',
  14786. class: 'p5.SoundLoop',
  14787. module: 'p5.sound'
  14788. },
  14789. interval: {
  14790. name: 'interval',
  14791. class: 'p5.SoundLoop',
  14792. module: 'p5.sound'
  14793. },
  14794. iterations: {
  14795. name: 'iterations',
  14796. class: 'p5.SoundLoop',
  14797. module: 'p5.sound'
  14798. },
  14799. musicalTimeMode: {
  14800. name: 'musicalTimeMode',
  14801. class: 'p5.SoundLoop',
  14802. module: 'p5.sound'
  14803. },
  14804. maxIterations: {
  14805. name: 'maxIterations',
  14806. class: 'p5.SoundLoop',
  14807. module: 'p5.sound'
  14808. },
  14809. start: {
  14810. name: 'start',
  14811. params: [
  14812. {
  14813. name: 'timeFromNow',
  14814. description: '<p>schedule a starting time</p>\n',
  14815. type: 'Number',
  14816. optional: true
  14817. }
  14818. ],
  14819. class: 'p5.SoundLoop',
  14820. module: 'p5.sound'
  14821. },
  14822. stop: {
  14823. name: 'stop',
  14824. params: [
  14825. {
  14826. name: 'timeFromNow',
  14827. description: '<p>schedule a stopping time</p>\n',
  14828. type: 'Number',
  14829. optional: true
  14830. }
  14831. ],
  14832. class: 'p5.SoundLoop',
  14833. module: 'p5.sound'
  14834. },
  14835. pause: {
  14836. name: 'pause',
  14837. params: [
  14838. {
  14839. name: 'timeFromNow',
  14840. description: '<p>schedule a pausing time</p>\n',
  14841. type: 'Number',
  14842. optional: true
  14843. }
  14844. ],
  14845. class: 'p5.SoundLoop',
  14846. module: 'p5.sound'
  14847. },
  14848. syncedStart: {
  14849. name: 'syncedStart',
  14850. params: [
  14851. {
  14852. name: 'otherLoop',
  14853. description: '<p>a p5.SoundLoop to sync with</p>\n',
  14854. type: 'Object'
  14855. },
  14856. {
  14857. name: 'timeFromNow',
  14858. description:
  14859. '<p>Start the loops in sync after timeFromNow seconds</p>\n',
  14860. type: 'Number',
  14861. optional: true
  14862. }
  14863. ],
  14864. class: 'p5.SoundLoop',
  14865. module: 'p5.sound'
  14866. }
  14867. },
  14868. 'p5.Compressor': {
  14869. compressor: {
  14870. name: 'compressor',
  14871. class: 'p5.Compressor',
  14872. module: 'p5.sound'
  14873. },
  14874. process: {
  14875. name: 'process',
  14876. params: [
  14877. {
  14878. name: 'src',
  14879. description: '<p>Sound source to be connected</p>\n',
  14880. type: 'Object'
  14881. },
  14882. {
  14883. name: 'attack',
  14884. description:
  14885. '<p>The amount of time (in seconds) to reduce the gain by 10dB,\n default = .003, range 0 - 1</p>\n',
  14886. type: 'Number',
  14887. optional: true
  14888. },
  14889. {
  14890. name: 'knee',
  14891. description:
  14892. '<p>A decibel value representing the range above the\n threshold where the curve smoothly transitions to the "ratio" portion.\n default = 30, range 0 - 40</p>\n',
  14893. type: 'Number',
  14894. optional: true
  14895. },
  14896. {
  14897. name: 'ratio',
  14898. description:
  14899. '<p>The amount of dB change in input for a 1 dB change in output\n default = 12, range 1 - 20</p>\n',
  14900. type: 'Number',
  14901. optional: true
  14902. },
  14903. {
  14904. name: 'threshold',
  14905. description:
  14906. '<p>The decibel value above which the compression will start taking effect\n default = -24, range -100 - 0</p>\n',
  14907. type: 'Number',
  14908. optional: true
  14909. },
  14910. {
  14911. name: 'release',
  14912. description:
  14913. '<p>The amount of time (in seconds) to increase the gain by 10dB\n default = .25, range 0 - 1</p>\n',
  14914. type: 'Number',
  14915. optional: true
  14916. }
  14917. ],
  14918. class: 'p5.Compressor',
  14919. module: 'p5.sound'
  14920. },
  14921. set: {
  14922. name: 'set',
  14923. params: [
  14924. {
  14925. name: 'attack',
  14926. description:
  14927. '<p>The amount of time (in seconds) to reduce the gain by 10dB,\n default = .003, range 0 - 1</p>\n',
  14928. type: 'Number'
  14929. },
  14930. {
  14931. name: 'knee',
  14932. description:
  14933. '<p>A decibel value representing the range above the\n threshold where the curve smoothly transitions to the "ratio" portion.\n default = 30, range 0 - 40</p>\n',
  14934. type: 'Number'
  14935. },
  14936. {
  14937. name: 'ratio',
  14938. description:
  14939. '<p>The amount of dB change in input for a 1 dB change in output\n default = 12, range 1 - 20</p>\n',
  14940. type: 'Number'
  14941. },
  14942. {
  14943. name: 'threshold',
  14944. description:
  14945. '<p>The decibel value above which the compression will start taking effect\n default = -24, range -100 - 0</p>\n',
  14946. type: 'Number'
  14947. },
  14948. {
  14949. name: 'release',
  14950. description:
  14951. '<p>The amount of time (in seconds) to increase the gain by 10dB\n default = .25, range 0 - 1</p>\n',
  14952. type: 'Number'
  14953. }
  14954. ],
  14955. class: 'p5.Compressor',
  14956. module: 'p5.sound'
  14957. },
  14958. attack: {
  14959. name: 'attack',
  14960. params: [
  14961. {
  14962. name: 'attack',
  14963. description:
  14964. '<p>Attack is the amount of time (in seconds) to reduce the gain by 10dB,\n default = .003, range 0 - 1</p>\n',
  14965. type: 'Number',
  14966. optional: true
  14967. },
  14968. {
  14969. name: 'time',
  14970. description:
  14971. '<p>Assign time value to schedule the change in value</p>\n',
  14972. type: 'Number',
  14973. optional: true
  14974. }
  14975. ],
  14976. class: 'p5.Compressor',
  14977. module: 'p5.sound'
  14978. },
  14979. knee: {
  14980. name: 'knee',
  14981. params: [
  14982. {
  14983. name: 'knee',
  14984. description:
  14985. '<p>A decibel value representing the range above the\n threshold where the curve smoothly transitions to the "ratio" portion.\n default = 30, range 0 - 40</p>\n',
  14986. type: 'Number',
  14987. optional: true
  14988. },
  14989. {
  14990. name: 'time',
  14991. description:
  14992. '<p>Assign time value to schedule the change in value</p>\n',
  14993. type: 'Number',
  14994. optional: true
  14995. }
  14996. ],
  14997. class: 'p5.Compressor',
  14998. module: 'p5.sound'
  14999. },
  15000. ratio: {
  15001. name: 'ratio',
  15002. params: [
  15003. {
  15004. name: 'ratio',
  15005. description:
  15006. '<p>The amount of dB change in input for a 1 dB change in output\n default = 12, range 1 - 20</p>\n',
  15007. type: 'Number',
  15008. optional: true
  15009. },
  15010. {
  15011. name: 'time',
  15012. description:
  15013. '<p>Assign time value to schedule the change in value</p>\n',
  15014. type: 'Number',
  15015. optional: true
  15016. }
  15017. ],
  15018. class: 'p5.Compressor',
  15019. module: 'p5.sound'
  15020. },
  15021. threshold: {
  15022. name: 'threshold',
  15023. params: [
  15024. {
  15025. name: 'threshold',
  15026. description:
  15027. '<p>The decibel value above which the compression will start taking effect\n default = -24, range -100 - 0</p>\n',
  15028. type: 'Number'
  15029. },
  15030. {
  15031. name: 'time',
  15032. description:
  15033. '<p>Assign time value to schedule the change in value</p>\n',
  15034. type: 'Number',
  15035. optional: true
  15036. }
  15037. ],
  15038. class: 'p5.Compressor',
  15039. module: 'p5.sound'
  15040. },
  15041. release: {
  15042. name: 'release',
  15043. params: [
  15044. {
  15045. name: 'release',
  15046. description:
  15047. '<p>The amount of time (in seconds) to increase the gain by 10dB\n default = .25, range 0 - 1</p>\n',
  15048. type: 'Number'
  15049. },
  15050. {
  15051. name: 'time',
  15052. description:
  15053. '<p>Assign time value to schedule the change in value</p>\n',
  15054. type: 'Number',
  15055. optional: true
  15056. }
  15057. ],
  15058. class: 'p5.Compressor',
  15059. module: 'p5.sound'
  15060. },
  15061. reduction: {
  15062. name: 'reduction',
  15063. class: 'p5.Compressor',
  15064. module: 'p5.sound'
  15065. }
  15066. },
  15067. 'p5.PeakDetect': {
  15068. isDetected: {
  15069. name: 'isDetected',
  15070. class: 'p5.PeakDetect',
  15071. module: 'p5.sound'
  15072. },
  15073. update: {
  15074. name: 'update',
  15075. params: [
  15076. {
  15077. name: 'fftObject',
  15078. description: '<p>A p5.FFT object</p>\n',
  15079. type: 'p5.FFT'
  15080. }
  15081. ],
  15082. class: 'p5.PeakDetect',
  15083. module: 'p5.sound'
  15084. },
  15085. onPeak: {
  15086. name: 'onPeak',
  15087. params: [
  15088. {
  15089. name: 'callback',
  15090. description:
  15091. '<p>Name of a function that will\n be called when a peak is\n detected.</p>\n',
  15092. type: 'Function'
  15093. },
  15094. {
  15095. name: 'val',
  15096. description:
  15097. '<p>Optional value to pass\n into the function when\n a peak is detected.</p>\n',
  15098. type: 'Object',
  15099. optional: true
  15100. }
  15101. ],
  15102. class: 'p5.PeakDetect',
  15103. module: 'p5.sound'
  15104. }
  15105. },
  15106. 'p5.SoundRecorder': {
  15107. setInput: {
  15108. name: 'setInput',
  15109. params: [
  15110. {
  15111. name: 'unit',
  15112. description:
  15113. '<p>p5.sound object or a web audio unit\n that outputs sound</p>\n',
  15114. type: 'Object',
  15115. optional: true
  15116. }
  15117. ],
  15118. class: 'p5.SoundRecorder',
  15119. module: 'p5.sound'
  15120. },
  15121. record: {
  15122. name: 'record',
  15123. params: [
  15124. {
  15125. name: 'soundFile',
  15126. description: '<p>p5.SoundFile</p>\n',
  15127. type: 'p5.SoundFile'
  15128. },
  15129. {
  15130. name: 'duration',
  15131. description: '<p>Time (in seconds)</p>\n',
  15132. type: 'Number',
  15133. optional: true
  15134. },
  15135. {
  15136. name: 'callback',
  15137. description:
  15138. '<p>The name of a function that will be\n called once the recording completes</p>\n',
  15139. type: 'Function',
  15140. optional: true
  15141. }
  15142. ],
  15143. class: 'p5.SoundRecorder',
  15144. module: 'p5.sound'
  15145. },
  15146. stop: {
  15147. name: 'stop',
  15148. class: 'p5.SoundRecorder',
  15149. module: 'p5.sound'
  15150. }
  15151. },
  15152. 'p5.Distortion': {
  15153. WaveShaperNode: {
  15154. name: 'WaveShaperNode',
  15155. class: 'p5.Distortion',
  15156. module: 'p5.sound'
  15157. },
  15158. process: {
  15159. name: 'process',
  15160. params: [
  15161. {
  15162. name: 'amount',
  15163. description:
  15164. '<p>Unbounded distortion amount.\n Normal values range from 0-1.</p>\n',
  15165. type: 'Number',
  15166. optional: true,
  15167. optdefault: '0.25'
  15168. },
  15169. {
  15170. name: 'oversample',
  15171. description: "<p>'none', '2x', or '4x'.</p>\n",
  15172. type: 'String',
  15173. optional: true,
  15174. optdefault: "'none'"
  15175. }
  15176. ],
  15177. class: 'p5.Distortion',
  15178. module: 'p5.sound'
  15179. },
  15180. set: {
  15181. name: 'set',
  15182. params: [
  15183. {
  15184. name: 'amount',
  15185. description:
  15186. '<p>Unbounded distortion amount.\n Normal values range from 0-1.</p>\n',
  15187. type: 'Number',
  15188. optional: true,
  15189. optdefault: '0.25'
  15190. },
  15191. {
  15192. name: 'oversample',
  15193. description: "<p>'none', '2x', or '4x'.</p>\n",
  15194. type: 'String',
  15195. optional: true,
  15196. optdefault: "'none'"
  15197. }
  15198. ],
  15199. class: 'p5.Distortion',
  15200. module: 'p5.sound'
  15201. },
  15202. getAmount: {
  15203. name: 'getAmount',
  15204. class: 'p5.Distortion',
  15205. module: 'p5.sound'
  15206. },
  15207. getOversample: {
  15208. name: 'getOversample',
  15209. class: 'p5.Distortion',
  15210. module: 'p5.sound'
  15211. }
  15212. },
  15213. 'p5.Gain': {
  15214. setInput: {
  15215. name: 'setInput',
  15216. params: [
  15217. {
  15218. name: 'src',
  15219. description:
  15220. '<p>p5.sound / Web Audio object with a sound\n output.</p>\n',
  15221. type: 'Object'
  15222. }
  15223. ],
  15224. class: 'p5.Gain',
  15225. module: 'p5.sound'
  15226. },
  15227. connect: {
  15228. name: 'connect',
  15229. params: [
  15230. {
  15231. name: 'unit',
  15232. description: '',
  15233. type: 'Object'
  15234. }
  15235. ],
  15236. class: 'p5.Gain',
  15237. module: 'p5.sound'
  15238. },
  15239. disconnect: {
  15240. name: 'disconnect',
  15241. class: 'p5.Gain',
  15242. module: 'p5.sound'
  15243. },
  15244. amp: {
  15245. name: 'amp',
  15246. params: [
  15247. {
  15248. name: 'volume',
  15249. description: '<p>amplitude between 0 and 1.0</p>\n',
  15250. type: 'Number'
  15251. },
  15252. {
  15253. name: 'rampTime',
  15254. description: '<p>create a fade that lasts rampTime</p>\n',
  15255. type: 'Number',
  15256. optional: true
  15257. },
  15258. {
  15259. name: 'timeFromNow',
  15260. description:
  15261. '<p>schedule this event to happen\n seconds from now</p>\n',
  15262. type: 'Number',
  15263. optional: true
  15264. }
  15265. ],
  15266. class: 'p5.Gain',
  15267. module: 'p5.sound'
  15268. }
  15269. },
  15270. 'p5.AudioVoice': {
  15271. connect: {
  15272. name: 'connect',
  15273. params: [
  15274. {
  15275. name: 'unit',
  15276. description: '',
  15277. type: 'Object'
  15278. }
  15279. ],
  15280. class: 'p5.AudioVoice',
  15281. module: 'p5.sound'
  15282. },
  15283. disconnect: {
  15284. name: 'disconnect',
  15285. class: 'p5.AudioVoice',
  15286. module: 'p5.sound'
  15287. }
  15288. },
  15289. 'p5.MonoSynth': {
  15290. attack: {
  15291. name: 'attack',
  15292. class: 'p5.MonoSynth',
  15293. module: 'p5.sound'
  15294. },
  15295. decay: {
  15296. name: 'decay',
  15297. class: 'p5.MonoSynth',
  15298. module: 'p5.sound'
  15299. },
  15300. sustain: {
  15301. name: 'sustain',
  15302. class: 'p5.MonoSynth',
  15303. module: 'p5.sound'
  15304. },
  15305. release: {
  15306. name: 'release',
  15307. class: 'p5.MonoSynth',
  15308. module: 'p5.sound'
  15309. },
  15310. play: {
  15311. name: 'play',
  15312. params: [
  15313. {
  15314. name: 'note',
  15315. description:
  15316. '<p>the note you want to play, specified as a\n frequency in Hertz (Number) or as a midi\n value in Note/Octave format ("C4", "Eb3"...etc")\n See <a href = "https://github.com/Tonejs/Tone.js/wiki/Instruments">\n Tone</a>. Defaults to 440 hz.</p>\n',
  15317. type: 'String | Number'
  15318. },
  15319. {
  15320. name: 'velocity',
  15321. description:
  15322. '<p>velocity of the note to play (ranging from 0 to 1)</p>\n',
  15323. type: 'Number',
  15324. optional: true
  15325. },
  15326. {
  15327. name: 'secondsFromNow',
  15328. description: '<p>time from now (in seconds) at which to play</p>\n',
  15329. type: 'Number',
  15330. optional: true
  15331. },
  15332. {
  15333. name: 'sustainTime',
  15334. description:
  15335. '<p>time to sustain before releasing the envelope. Defaults to 0.15 seconds.</p>\n',
  15336. type: 'Number',
  15337. optional: true
  15338. }
  15339. ],
  15340. class: 'p5.MonoSynth',
  15341. module: 'p5.sound'
  15342. },
  15343. triggerAttack: {
  15344. params: [
  15345. {
  15346. name: 'note',
  15347. description:
  15348. '<p>the note you want to play, specified as a\n frequency in Hertz (Number) or as a midi\n value in Note/Octave format ("C4", "Eb3"...etc")\n See <a href = "https://github.com/Tonejs/Tone.js/wiki/Instruments">\n Tone</a>. Defaults to 440 hz</p>\n',
  15349. type: 'String | Number'
  15350. },
  15351. {
  15352. name: 'velocity',
  15353. description:
  15354. '<p>velocity of the note to play (ranging from 0 to 1)</p>\n',
  15355. type: 'Number',
  15356. optional: true
  15357. },
  15358. {
  15359. name: 'secondsFromNow',
  15360. description: '<p>time from now (in seconds) at which to play</p>\n',
  15361. type: 'Number',
  15362. optional: true
  15363. }
  15364. ],
  15365. name: 'triggerAttack',
  15366. class: 'p5.MonoSynth',
  15367. module: 'p5.sound'
  15368. },
  15369. triggerRelease: {
  15370. params: [
  15371. {
  15372. name: 'secondsFromNow',
  15373. description: '<p>time to trigger the release</p>\n',
  15374. type: 'Number'
  15375. }
  15376. ],
  15377. name: 'triggerRelease',
  15378. class: 'p5.MonoSynth',
  15379. module: 'p5.sound'
  15380. },
  15381. setADSR: {
  15382. name: 'setADSR',
  15383. params: [
  15384. {
  15385. name: 'attackTime',
  15386. description:
  15387. '<p>Time (in seconds before envelope\n reaches Attack Level</p>\n',
  15388. type: 'Number'
  15389. },
  15390. {
  15391. name: 'decayTime',
  15392. description:
  15393. '<p>Time (in seconds) before envelope\n reaches Decay/Sustain Level</p>\n',
  15394. type: 'Number',
  15395. optional: true
  15396. },
  15397. {
  15398. name: 'susRatio',
  15399. description:
  15400. '<p>Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using <code>setRange</code>),\n then decayLevel would increase proportionally, to become 0.5.</p>\n',
  15401. type: 'Number',
  15402. optional: true
  15403. },
  15404. {
  15405. name: 'releaseTime',
  15406. description: '<p>Time in seconds from now (defaults to 0)</p>\n',
  15407. type: 'Number',
  15408. optional: true
  15409. }
  15410. ],
  15411. class: 'p5.MonoSynth',
  15412. module: 'p5.sound'
  15413. },
  15414. amp: {
  15415. name: 'amp',
  15416. params: [
  15417. {
  15418. name: 'vol',
  15419. description: '<p>desired volume</p>\n',
  15420. type: 'Number'
  15421. },
  15422. {
  15423. name: 'rampTime',
  15424. description: '<p>Time to reach new volume</p>\n',
  15425. type: 'Number',
  15426. optional: true
  15427. }
  15428. ],
  15429. class: 'p5.MonoSynth',
  15430. module: 'p5.sound'
  15431. },
  15432. connect: {
  15433. name: 'connect',
  15434. params: [
  15435. {
  15436. name: 'unit',
  15437. description: '<p>A p5.sound or Web Audio object</p>\n',
  15438. type: 'Object'
  15439. }
  15440. ],
  15441. class: 'p5.MonoSynth',
  15442. module: 'p5.sound'
  15443. },
  15444. disconnect: {
  15445. name: 'disconnect',
  15446. class: 'p5.MonoSynth',
  15447. module: 'p5.sound'
  15448. },
  15449. dispose: {
  15450. name: 'dispose',
  15451. class: 'p5.MonoSynth',
  15452. module: 'p5.sound'
  15453. }
  15454. },
  15455. 'p5.PolySynth': {
  15456. notes: {
  15457. name: 'notes',
  15458. class: 'p5.PolySynth',
  15459. module: 'p5.sound'
  15460. },
  15461. polyvalue: {
  15462. name: 'polyvalue',
  15463. class: 'p5.PolySynth',
  15464. module: 'p5.sound'
  15465. },
  15466. AudioVoice: {
  15467. name: 'AudioVoice',
  15468. class: 'p5.PolySynth',
  15469. module: 'p5.sound'
  15470. },
  15471. play: {
  15472. name: 'play',
  15473. params: [
  15474. {
  15475. name: 'note',
  15476. description:
  15477. '<p>midi note to play (ranging from 0 to 127 - 60 being a middle C)</p>\n',
  15478. type: 'Number',
  15479. optional: true
  15480. },
  15481. {
  15482. name: 'velocity',
  15483. description:
  15484. '<p>velocity of the note to play (ranging from 0 to 1)</p>\n',
  15485. type: 'Number',
  15486. optional: true
  15487. },
  15488. {
  15489. name: 'secondsFromNow',
  15490. description: '<p>time from now (in seconds) at which to play</p>\n',
  15491. type: 'Number',
  15492. optional: true
  15493. },
  15494. {
  15495. name: 'sustainTime',
  15496. description: '<p>time to sustain before releasing the envelope</p>\n',
  15497. type: 'Number',
  15498. optional: true
  15499. }
  15500. ],
  15501. class: 'p5.PolySynth',
  15502. module: 'p5.sound'
  15503. },
  15504. noteADSR: {
  15505. name: 'noteADSR',
  15506. params: [
  15507. {
  15508. name: 'note',
  15509. description: '<p>Midi note on which ADSR should be set.</p>\n',
  15510. type: 'Number',
  15511. optional: true
  15512. },
  15513. {
  15514. name: 'attackTime',
  15515. description:
  15516. '<p>Time (in seconds before envelope\n reaches Attack Level</p>\n',
  15517. type: 'Number',
  15518. optional: true
  15519. },
  15520. {
  15521. name: 'decayTime',
  15522. description:
  15523. '<p>Time (in seconds) before envelope\n reaches Decay/Sustain Level</p>\n',
  15524. type: 'Number',
  15525. optional: true
  15526. },
  15527. {
  15528. name: 'susRatio',
  15529. description:
  15530. '<p>Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using <code>setRange</code>),\n then decayLevel would increase proportionally, to become 0.5.</p>\n',
  15531. type: 'Number',
  15532. optional: true
  15533. },
  15534. {
  15535. name: 'releaseTime',
  15536. description: '<p>Time in seconds from now (defaults to 0)</p>\n',
  15537. type: 'Number',
  15538. optional: true
  15539. }
  15540. ],
  15541. class: 'p5.PolySynth',
  15542. module: 'p5.sound'
  15543. },
  15544. setADSR: {
  15545. name: 'setADSR',
  15546. params: [
  15547. {
  15548. name: 'attackTime',
  15549. description:
  15550. '<p>Time (in seconds before envelope\n reaches Attack Level</p>\n',
  15551. type: 'Number',
  15552. optional: true
  15553. },
  15554. {
  15555. name: 'decayTime',
  15556. description:
  15557. '<p>Time (in seconds) before envelope\n reaches Decay/Sustain Level</p>\n',
  15558. type: 'Number',
  15559. optional: true
  15560. },
  15561. {
  15562. name: 'susRatio',
  15563. description:
  15564. '<p>Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using <code>setRange</code>),\n then decayLevel would increase proportionally, to become 0.5.</p>\n',
  15565. type: 'Number',
  15566. optional: true
  15567. },
  15568. {
  15569. name: 'releaseTime',
  15570. description: '<p>Time in seconds from now (defaults to 0)</p>\n',
  15571. type: 'Number',
  15572. optional: true
  15573. }
  15574. ],
  15575. class: 'p5.PolySynth',
  15576. module: 'p5.sound'
  15577. },
  15578. noteAttack: {
  15579. name: 'noteAttack',
  15580. params: [
  15581. {
  15582. name: 'note',
  15583. description: '<p>midi note on which attack should be triggered.</p>\n',
  15584. type: 'Number',
  15585. optional: true
  15586. },
  15587. {
  15588. name: 'velocity',
  15589. description:
  15590. '<p>velocity of the note to play (ranging from 0 to 1)/</p>\n',
  15591. type: 'Number',
  15592. optional: true
  15593. },
  15594. {
  15595. name: 'secondsFromNow',
  15596. description: '<p>time from now (in seconds)</p>\n',
  15597. type: 'Number',
  15598. optional: true
  15599. }
  15600. ],
  15601. class: 'p5.PolySynth',
  15602. module: 'p5.sound'
  15603. },
  15604. noteRelease: {
  15605. name: 'noteRelease',
  15606. params: [
  15607. {
  15608. name: 'note',
  15609. description:
  15610. '<p>midi note on which attack should be triggered.\n If no value is provided, all notes will be released.</p>\n',
  15611. type: 'Number',
  15612. optional: true
  15613. },
  15614. {
  15615. name: 'secondsFromNow',
  15616. description: '<p>time to trigger the release</p>\n',
  15617. type: 'Number',
  15618. optional: true
  15619. }
  15620. ],
  15621. class: 'p5.PolySynth',
  15622. module: 'p5.sound'
  15623. },
  15624. connect: {
  15625. name: 'connect',
  15626. params: [
  15627. {
  15628. name: 'unit',
  15629. description: '<p>A p5.sound or Web Audio object</p>\n',
  15630. type: 'Object'
  15631. }
  15632. ],
  15633. class: 'p5.PolySynth',
  15634. module: 'p5.sound'
  15635. },
  15636. disconnect: {
  15637. name: 'disconnect',
  15638. class: 'p5.PolySynth',
  15639. module: 'p5.sound'
  15640. },
  15641. dispose: {
  15642. name: 'dispose',
  15643. class: 'p5.PolySynth',
  15644. module: 'p5.sound'
  15645. }
  15646. }
  15647. };
  15648. },
  15649. {}
  15650. ],
  15651. 2: [
  15652. function(_dereq_, module, exports) {
  15653. function _arrayWithHoles(arr) {
  15654. if (Array.isArray(arr)) return arr;
  15655. }
  15656. module.exports = _arrayWithHoles;
  15657. },
  15658. {}
  15659. ],
  15660. 3: [
  15661. function(_dereq_, module, exports) {
  15662. function _arrayWithoutHoles(arr) {
  15663. if (Array.isArray(arr)) {
  15664. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  15665. arr2[i] = arr[i];
  15666. }
  15667. return arr2;
  15668. }
  15669. }
  15670. module.exports = _arrayWithoutHoles;
  15671. },
  15672. {}
  15673. ],
  15674. 4: [
  15675. function(_dereq_, module, exports) {
  15676. function _assertThisInitialized(self) {
  15677. if (self === void 0) {
  15678. throw new ReferenceError(
  15679. "this hasn't been initialised - super() hasn't been called"
  15680. );
  15681. }
  15682. return self;
  15683. }
  15684. module.exports = _assertThisInitialized;
  15685. },
  15686. {}
  15687. ],
  15688. 5: [
  15689. function(_dereq_, module, exports) {
  15690. function _classCallCheck(instance, Constructor) {
  15691. if (!(instance instanceof Constructor)) {
  15692. throw new TypeError('Cannot call a class as a function');
  15693. }
  15694. }
  15695. module.exports = _classCallCheck;
  15696. },
  15697. {}
  15698. ],
  15699. 6: [
  15700. function(_dereq_, module, exports) {
  15701. function _defineProperties(target, props) {
  15702. for (var i = 0; i < props.length; i++) {
  15703. var descriptor = props[i];
  15704. descriptor.enumerable = descriptor.enumerable || false;
  15705. descriptor.configurable = true;
  15706. if ('value' in descriptor) descriptor.writable = true;
  15707. Object.defineProperty(target, descriptor.key, descriptor);
  15708. }
  15709. }
  15710. function _createClass(Constructor, protoProps, staticProps) {
  15711. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  15712. if (staticProps) _defineProperties(Constructor, staticProps);
  15713. return Constructor;
  15714. }
  15715. module.exports = _createClass;
  15716. },
  15717. {}
  15718. ],
  15719. 7: [
  15720. function(_dereq_, module, exports) {
  15721. function _defineProperty(obj, key, value) {
  15722. if (key in obj) {
  15723. Object.defineProperty(obj, key, {
  15724. value: value,
  15725. enumerable: true,
  15726. configurable: true,
  15727. writable: true
  15728. });
  15729. } else {
  15730. obj[key] = value;
  15731. }
  15732. return obj;
  15733. }
  15734. module.exports = _defineProperty;
  15735. },
  15736. {}
  15737. ],
  15738. 8: [
  15739. function(_dereq_, module, exports) {
  15740. function _getPrototypeOf(o) {
  15741. module.exports = _getPrototypeOf = Object.setPrototypeOf
  15742. ? Object.getPrototypeOf
  15743. : function _getPrototypeOf(o) {
  15744. return o.__proto__ || Object.getPrototypeOf(o);
  15745. };
  15746. return _getPrototypeOf(o);
  15747. }
  15748. module.exports = _getPrototypeOf;
  15749. },
  15750. {}
  15751. ],
  15752. 9: [
  15753. function(_dereq_, module, exports) {
  15754. var setPrototypeOf = _dereq_('./setPrototypeOf');
  15755. function _inherits(subClass, superClass) {
  15756. if (typeof superClass !== 'function' && superClass !== null) {
  15757. throw new TypeError('Super expression must either be null or a function');
  15758. }
  15759. subClass.prototype = Object.create(superClass && superClass.prototype, {
  15760. constructor: {
  15761. value: subClass,
  15762. writable: true,
  15763. configurable: true
  15764. }
  15765. });
  15766. if (superClass) setPrototypeOf(subClass, superClass);
  15767. }
  15768. module.exports = _inherits;
  15769. },
  15770. { './setPrototypeOf': 16 }
  15771. ],
  15772. 10: [
  15773. function(_dereq_, module, exports) {
  15774. function _iterableToArray(iter) {
  15775. if (
  15776. Symbol.iterator in Object(iter) ||
  15777. Object.prototype.toString.call(iter) === '[object Arguments]'
  15778. )
  15779. return Array.from(iter);
  15780. }
  15781. module.exports = _iterableToArray;
  15782. },
  15783. {}
  15784. ],
  15785. 11: [
  15786. function(_dereq_, module, exports) {
  15787. function _iterableToArrayLimit(arr, i) {
  15788. var _arr = [];
  15789. var _n = true;
  15790. var _d = false;
  15791. var _e = undefined;
  15792. try {
  15793. for (
  15794. var _i = arr[Symbol.iterator](), _s;
  15795. !(_n = (_s = _i.next()).done);
  15796. _n = true
  15797. ) {
  15798. _arr.push(_s.value);
  15799. if (i && _arr.length === i) break;
  15800. }
  15801. } catch (err) {
  15802. _d = true;
  15803. _e = err;
  15804. } finally {
  15805. try {
  15806. if (!_n && _i['return'] != null) _i['return']();
  15807. } finally {
  15808. if (_d) throw _e;
  15809. }
  15810. }
  15811. return _arr;
  15812. }
  15813. module.exports = _iterableToArrayLimit;
  15814. },
  15815. {}
  15816. ],
  15817. 12: [
  15818. function(_dereq_, module, exports) {
  15819. function _nonIterableRest() {
  15820. throw new TypeError('Invalid attempt to destructure non-iterable instance');
  15821. }
  15822. module.exports = _nonIterableRest;
  15823. },
  15824. {}
  15825. ],
  15826. 13: [
  15827. function(_dereq_, module, exports) {
  15828. function _nonIterableSpread() {
  15829. throw new TypeError('Invalid attempt to spread non-iterable instance');
  15830. }
  15831. module.exports = _nonIterableSpread;
  15832. },
  15833. {}
  15834. ],
  15835. 14: [
  15836. function(_dereq_, module, exports) {
  15837. var defineProperty = _dereq_('./defineProperty');
  15838. function _objectSpread(target) {
  15839. for (var i = 1; i < arguments.length; i++) {
  15840. var source = arguments[i] != null ? arguments[i] : {};
  15841. var ownKeys = Object.keys(source);
  15842. if (typeof Object.getOwnPropertySymbols === 'function') {
  15843. ownKeys = ownKeys.concat(
  15844. Object.getOwnPropertySymbols(source).filter(function(sym) {
  15845. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  15846. })
  15847. );
  15848. }
  15849. ownKeys.forEach(function(key) {
  15850. defineProperty(target, key, source[key]);
  15851. });
  15852. }
  15853. return target;
  15854. }
  15855. module.exports = _objectSpread;
  15856. },
  15857. { './defineProperty': 7 }
  15858. ],
  15859. 15: [
  15860. function(_dereq_, module, exports) {
  15861. var _typeof = _dereq_('../helpers/typeof');
  15862. var assertThisInitialized = _dereq_('./assertThisInitialized');
  15863. function _possibleConstructorReturn(self, call) {
  15864. if (call && (_typeof(call) === 'object' || typeof call === 'function')) {
  15865. return call;
  15866. }
  15867. return assertThisInitialized(self);
  15868. }
  15869. module.exports = _possibleConstructorReturn;
  15870. },
  15871. { '../helpers/typeof': 19, './assertThisInitialized': 4 }
  15872. ],
  15873. 16: [
  15874. function(_dereq_, module, exports) {
  15875. function _setPrototypeOf(o, p) {
  15876. module.exports = _setPrototypeOf =
  15877. Object.setPrototypeOf ||
  15878. function _setPrototypeOf(o, p) {
  15879. o.__proto__ = p;
  15880. return o;
  15881. };
  15882. return _setPrototypeOf(o, p);
  15883. }
  15884. module.exports = _setPrototypeOf;
  15885. },
  15886. {}
  15887. ],
  15888. 17: [
  15889. function(_dereq_, module, exports) {
  15890. var arrayWithHoles = _dereq_('./arrayWithHoles');
  15891. var iterableToArrayLimit = _dereq_('./iterableToArrayLimit');
  15892. var nonIterableRest = _dereq_('./nonIterableRest');
  15893. function _slicedToArray(arr, i) {
  15894. return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest();
  15895. }
  15896. module.exports = _slicedToArray;
  15897. },
  15898. { './arrayWithHoles': 2, './iterableToArrayLimit': 11, './nonIterableRest': 12 }
  15899. ],
  15900. 18: [
  15901. function(_dereq_, module, exports) {
  15902. var arrayWithoutHoles = _dereq_('./arrayWithoutHoles');
  15903. var iterableToArray = _dereq_('./iterableToArray');
  15904. var nonIterableSpread = _dereq_('./nonIterableSpread');
  15905. function _toConsumableArray(arr) {
  15906. return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
  15907. }
  15908. module.exports = _toConsumableArray;
  15909. },
  15910. { './arrayWithoutHoles': 3, './iterableToArray': 10, './nonIterableSpread': 13 }
  15911. ],
  15912. 19: [
  15913. function(_dereq_, module, exports) {
  15914. function _typeof2(obj) {
  15915. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  15916. _typeof2 = function _typeof2(obj) {
  15917. return typeof obj;
  15918. };
  15919. } else {
  15920. _typeof2 = function _typeof2(obj) {
  15921. return obj &&
  15922. typeof Symbol === 'function' &&
  15923. obj.constructor === Symbol &&
  15924. obj !== Symbol.prototype
  15925. ? 'symbol'
  15926. : typeof obj;
  15927. };
  15928. }
  15929. return _typeof2(obj);
  15930. }
  15931. function _typeof(obj) {
  15932. if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') {
  15933. module.exports = _typeof = function _typeof(obj) {
  15934. return _typeof2(obj);
  15935. };
  15936. } else {
  15937. module.exports = _typeof = function _typeof(obj) {
  15938. return obj &&
  15939. typeof Symbol === 'function' &&
  15940. obj.constructor === Symbol &&
  15941. obj !== Symbol.prototype
  15942. ? 'symbol'
  15943. : _typeof2(obj);
  15944. };
  15945. }
  15946. return _typeof(obj);
  15947. }
  15948. module.exports = _typeof;
  15949. },
  15950. {}
  15951. ],
  15952. 20: [
  15953. function(_dereq_, module, exports) {
  15954. 'use strict';
  15955. exports.byteLength = byteLength;
  15956. exports.toByteArray = toByteArray;
  15957. exports.fromByteArray = fromByteArray;
  15958. var lookup = [];
  15959. var revLookup = [];
  15960. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  15961. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  15962. for (var i = 0, len = code.length; i < len; ++i) {
  15963. lookup[i] = code[i];
  15964. revLookup[code.charCodeAt(i)] = i;
  15965. }
  15966. // Support decoding URL-safe base64 strings, as Node.js does.
  15967. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  15968. revLookup['-'.charCodeAt(0)] = 62;
  15969. revLookup['_'.charCodeAt(0)] = 63;
  15970. function getLens(b64) {
  15971. var len = b64.length;
  15972. if (len % 4 > 0) {
  15973. throw new Error('Invalid string. Length must be a multiple of 4');
  15974. }
  15975. // Trim off extra bytes after placeholder bytes are found
  15976. // See: https://github.com/beatgammit/base64-js/issues/42
  15977. var validLen = b64.indexOf('=');
  15978. if (validLen === -1) validLen = len;
  15979. var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
  15980. return [validLen, placeHoldersLen];
  15981. }
  15982. // base64 is 4/3 + up to two characters of the original data
  15983. function byteLength(b64) {
  15984. var lens = getLens(b64);
  15985. var validLen = lens[0];
  15986. var placeHoldersLen = lens[1];
  15987. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  15988. }
  15989. function _byteLength(b64, validLen, placeHoldersLen) {
  15990. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  15991. }
  15992. function toByteArray(b64) {
  15993. var tmp;
  15994. var lens = getLens(b64);
  15995. var validLen = lens[0];
  15996. var placeHoldersLen = lens[1];
  15997. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
  15998. var curByte = 0;
  15999. // if there are placeholders, only get up to the last complete 4 chars
  16000. var len = placeHoldersLen > 0 ? validLen - 4 : validLen;
  16001. var i;
  16002. for (i = 0; i < len; i += 4) {
  16003. tmp =
  16004. (revLookup[b64.charCodeAt(i)] << 18) |
  16005. (revLookup[b64.charCodeAt(i + 1)] << 12) |
  16006. (revLookup[b64.charCodeAt(i + 2)] << 6) |
  16007. revLookup[b64.charCodeAt(i + 3)];
  16008. arr[curByte++] = (tmp >> 16) & 0xff;
  16009. arr[curByte++] = (tmp >> 8) & 0xff;
  16010. arr[curByte++] = tmp & 0xff;
  16011. }
  16012. if (placeHoldersLen === 2) {
  16013. tmp =
  16014. (revLookup[b64.charCodeAt(i)] << 2) |
  16015. (revLookup[b64.charCodeAt(i + 1)] >> 4);
  16016. arr[curByte++] = tmp & 0xff;
  16017. }
  16018. if (placeHoldersLen === 1) {
  16019. tmp =
  16020. (revLookup[b64.charCodeAt(i)] << 10) |
  16021. (revLookup[b64.charCodeAt(i + 1)] << 4) |
  16022. (revLookup[b64.charCodeAt(i + 2)] >> 2);
  16023. arr[curByte++] = (tmp >> 8) & 0xff;
  16024. arr[curByte++] = tmp & 0xff;
  16025. }
  16026. return arr;
  16027. }
  16028. function tripletToBase64(num) {
  16029. return (
  16030. lookup[(num >> 18) & 0x3f] +
  16031. lookup[(num >> 12) & 0x3f] +
  16032. lookup[(num >> 6) & 0x3f] +
  16033. lookup[num & 0x3f]
  16034. );
  16035. }
  16036. function encodeChunk(uint8, start, end) {
  16037. var tmp;
  16038. var output = [];
  16039. for (var i = start; i < end; i += 3) {
  16040. tmp =
  16041. ((uint8[i] << 16) & 0xff0000) +
  16042. ((uint8[i + 1] << 8) & 0xff00) +
  16043. (uint8[i + 2] & 0xff);
  16044. output.push(tripletToBase64(tmp));
  16045. }
  16046. return output.join('');
  16047. }
  16048. function fromByteArray(uint8) {
  16049. var tmp;
  16050. var len = uint8.length;
  16051. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  16052. var parts = [];
  16053. var maxChunkLength = 16383; // must be multiple of 3
  16054. // go through the array every three bytes, we'll deal with trailing stuff later
  16055. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  16056. parts.push(
  16057. encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength)
  16058. );
  16059. }
  16060. // pad the end with zeros, but make sure to not forget the extra bytes
  16061. if (extraBytes === 1) {
  16062. tmp = uint8[len - 1];
  16063. parts.push(lookup[tmp >> 2] + lookup[(tmp << 4) & 0x3f] + '==');
  16064. } else if (extraBytes === 2) {
  16065. tmp = (uint8[len - 2] << 8) + uint8[len - 1];
  16066. parts.push(
  16067. lookup[tmp >> 10] +
  16068. lookup[(tmp >> 4) & 0x3f] +
  16069. lookup[(tmp << 2) & 0x3f] +
  16070. '='
  16071. );
  16072. }
  16073. return parts.join('');
  16074. }
  16075. },
  16076. {}
  16077. ],
  16078. 21: [function(_dereq_, module, exports) {}, {}],
  16079. 22: [
  16080. function(_dereq_, module, exports) {
  16081. (function(Buffer) {
  16082. /*!
  16083. * The buffer module from node.js, for the browser.
  16084. *
  16085. * @author Feross Aboukhadijeh <https://feross.org>
  16086. * @license MIT
  16087. */
  16088. /* eslint-disable no-proto */
  16089. 'use strict';
  16090. var base64 = _dereq_('base64-js');
  16091. var ieee754 = _dereq_('ieee754');
  16092. var customInspectSymbol =
  16093. typeof Symbol === 'function' && typeof Symbol.for === 'function'
  16094. ? Symbol.for('nodejs.util.inspect.custom')
  16095. : null;
  16096. exports.Buffer = Buffer;
  16097. exports.SlowBuffer = SlowBuffer;
  16098. exports.INSPECT_MAX_BYTES = 50;
  16099. var K_MAX_LENGTH = 0x7fffffff;
  16100. exports.kMaxLength = K_MAX_LENGTH;
  16101. /**
  16102. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  16103. * === true Use Uint8Array implementation (fastest)
  16104. * === false Print warning and recommend using `buffer` v4.x which has an Object
  16105. * implementation (most compatible, even IE6)
  16106. *
  16107. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  16108. * Opera 11.6+, iOS 4.2+.
  16109. *
  16110. * We report that the browser does not support typed arrays if the are not subclassable
  16111. * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  16112. * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  16113. * for __proto__ and has a buggy typed array implementation.
  16114. */
  16115. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
  16116. if (
  16117. !Buffer.TYPED_ARRAY_SUPPORT &&
  16118. typeof console !== 'undefined' &&
  16119. typeof console.error === 'function'
  16120. ) {
  16121. console.error(
  16122. 'This browser lacks typed array (Uint8Array) support which is required by ' +
  16123. '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
  16124. );
  16125. }
  16126. function typedArraySupport() {
  16127. // Can typed array instances can be augmented?
  16128. try {
  16129. var arr = new Uint8Array(1);
  16130. var proto = {
  16131. foo: function() {
  16132. return 42;
  16133. }
  16134. };
  16135. Object.setPrototypeOf(proto, Uint8Array.prototype);
  16136. Object.setPrototypeOf(arr, proto);
  16137. return arr.foo() === 42;
  16138. } catch (e) {
  16139. return false;
  16140. }
  16141. }
  16142. Object.defineProperty(Buffer.prototype, 'parent', {
  16143. enumerable: true,
  16144. get: function() {
  16145. if (!Buffer.isBuffer(this)) return undefined;
  16146. return this.buffer;
  16147. }
  16148. });
  16149. Object.defineProperty(Buffer.prototype, 'offset', {
  16150. enumerable: true,
  16151. get: function() {
  16152. if (!Buffer.isBuffer(this)) return undefined;
  16153. return this.byteOffset;
  16154. }
  16155. });
  16156. function createBuffer(length) {
  16157. if (length > K_MAX_LENGTH) {
  16158. throw new RangeError(
  16159. 'The value "' + length + '" is invalid for option "size"'
  16160. );
  16161. }
  16162. // Return an augmented `Uint8Array` instance
  16163. var buf = new Uint8Array(length);
  16164. Object.setPrototypeOf(buf, Buffer.prototype);
  16165. return buf;
  16166. }
  16167. /**
  16168. * The Buffer constructor returns instances of `Uint8Array` that have their
  16169. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  16170. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  16171. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  16172. * returns a single octet.
  16173. *
  16174. * The `Uint8Array` prototype remains unmodified.
  16175. */
  16176. function Buffer(arg, encodingOrOffset, length) {
  16177. // Common case.
  16178. if (typeof arg === 'number') {
  16179. if (typeof encodingOrOffset === 'string') {
  16180. throw new TypeError(
  16181. 'The "string" argument must be of type string. Received type number'
  16182. );
  16183. }
  16184. return allocUnsafe(arg);
  16185. }
  16186. return from(arg, encodingOrOffset, length);
  16187. }
  16188. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  16189. if (
  16190. typeof Symbol !== 'undefined' &&
  16191. Symbol.species != null &&
  16192. Buffer[Symbol.species] === Buffer
  16193. ) {
  16194. Object.defineProperty(Buffer, Symbol.species, {
  16195. value: null,
  16196. configurable: true,
  16197. enumerable: false,
  16198. writable: false
  16199. });
  16200. }
  16201. Buffer.poolSize = 8192; // not used by this implementation
  16202. function from(value, encodingOrOffset, length) {
  16203. if (typeof value === 'string') {
  16204. return fromString(value, encodingOrOffset);
  16205. }
  16206. if (ArrayBuffer.isView(value)) {
  16207. return fromArrayLike(value);
  16208. }
  16209. if (value == null) {
  16210. throw new TypeError(
  16211. 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
  16212. 'or Array-like Object. Received type ' +
  16213. typeof value
  16214. );
  16215. }
  16216. if (
  16217. isInstance(value, ArrayBuffer) ||
  16218. (value && isInstance(value.buffer, ArrayBuffer))
  16219. ) {
  16220. return fromArrayBuffer(value, encodingOrOffset, length);
  16221. }
  16222. if (typeof value === 'number') {
  16223. throw new TypeError(
  16224. 'The "value" argument must not be of type number. Received type number'
  16225. );
  16226. }
  16227. var valueOf = value.valueOf && value.valueOf();
  16228. if (valueOf != null && valueOf !== value) {
  16229. return Buffer.from(valueOf, encodingOrOffset, length);
  16230. }
  16231. var b = fromObject(value);
  16232. if (b) return b;
  16233. if (
  16234. typeof Symbol !== 'undefined' &&
  16235. Symbol.toPrimitive != null &&
  16236. typeof value[Symbol.toPrimitive] === 'function'
  16237. ) {
  16238. return Buffer.from(
  16239. value[Symbol.toPrimitive]('string'),
  16240. encodingOrOffset,
  16241. length
  16242. );
  16243. }
  16244. throw new TypeError(
  16245. 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
  16246. 'or Array-like Object. Received type ' +
  16247. typeof value
  16248. );
  16249. }
  16250. /**
  16251. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  16252. * if value is a number.
  16253. * Buffer.from(str[, encoding])
  16254. * Buffer.from(array)
  16255. * Buffer.from(buffer)
  16256. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  16257. **/
  16258. Buffer.from = function(value, encodingOrOffset, length) {
  16259. return from(value, encodingOrOffset, length);
  16260. };
  16261. // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  16262. // https://github.com/feross/buffer/pull/148
  16263. Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
  16264. Object.setPrototypeOf(Buffer, Uint8Array);
  16265. function assertSize(size) {
  16266. if (typeof size !== 'number') {
  16267. throw new TypeError('"size" argument must be of type number');
  16268. } else if (size < 0) {
  16269. throw new RangeError(
  16270. 'The value "' + size + '" is invalid for option "size"'
  16271. );
  16272. }
  16273. }
  16274. function alloc(size, fill, encoding) {
  16275. assertSize(size);
  16276. if (size <= 0) {
  16277. return createBuffer(size);
  16278. }
  16279. if (fill !== undefined) {
  16280. // Only pay attention to encoding if it's a string. This
  16281. // prevents accidentally sending in a number that would
  16282. // be interpretted as a start offset.
  16283. return typeof encoding === 'string'
  16284. ? createBuffer(size).fill(fill, encoding)
  16285. : createBuffer(size).fill(fill);
  16286. }
  16287. return createBuffer(size);
  16288. }
  16289. /**
  16290. * Creates a new filled Buffer instance.
  16291. * alloc(size[, fill[, encoding]])
  16292. **/
  16293. Buffer.alloc = function(size, fill, encoding) {
  16294. return alloc(size, fill, encoding);
  16295. };
  16296. function allocUnsafe(size) {
  16297. assertSize(size);
  16298. return createBuffer(size < 0 ? 0 : checked(size) | 0);
  16299. }
  16300. /**
  16301. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  16302. * */
  16303. Buffer.allocUnsafe = function(size) {
  16304. return allocUnsafe(size);
  16305. };
  16306. /**
  16307. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  16308. */
  16309. Buffer.allocUnsafeSlow = function(size) {
  16310. return allocUnsafe(size);
  16311. };
  16312. function fromString(string, encoding) {
  16313. if (typeof encoding !== 'string' || encoding === '') {
  16314. encoding = 'utf8';
  16315. }
  16316. if (!Buffer.isEncoding(encoding)) {
  16317. throw new TypeError('Unknown encoding: ' + encoding);
  16318. }
  16319. var length = byteLength(string, encoding) | 0;
  16320. var buf = createBuffer(length);
  16321. var actual = buf.write(string, encoding);
  16322. if (actual !== length) {
  16323. // Writing a hex string, for example, that contains invalid characters will
  16324. // cause everything after the first invalid character to be ignored. (e.g.
  16325. // 'abxxcd' will be treated as 'ab')
  16326. buf = buf.slice(0, actual);
  16327. }
  16328. return buf;
  16329. }
  16330. function fromArrayLike(array) {
  16331. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  16332. var buf = createBuffer(length);
  16333. for (var i = 0; i < length; i += 1) {
  16334. buf[i] = array[i] & 255;
  16335. }
  16336. return buf;
  16337. }
  16338. function fromArrayBuffer(array, byteOffset, length) {
  16339. if (byteOffset < 0 || array.byteLength < byteOffset) {
  16340. throw new RangeError('"offset" is outside of buffer bounds');
  16341. }
  16342. if (array.byteLength < byteOffset + (length || 0)) {
  16343. throw new RangeError('"length" is outside of buffer bounds');
  16344. }
  16345. var buf;
  16346. if (byteOffset === undefined && length === undefined) {
  16347. buf = new Uint8Array(array);
  16348. } else if (length === undefined) {
  16349. buf = new Uint8Array(array, byteOffset);
  16350. } else {
  16351. buf = new Uint8Array(array, byteOffset, length);
  16352. }
  16353. // Return an augmented `Uint8Array` instance
  16354. Object.setPrototypeOf(buf, Buffer.prototype);
  16355. return buf;
  16356. }
  16357. function fromObject(obj) {
  16358. if (Buffer.isBuffer(obj)) {
  16359. var len = checked(obj.length) | 0;
  16360. var buf = createBuffer(len);
  16361. if (buf.length === 0) {
  16362. return buf;
  16363. }
  16364. obj.copy(buf, 0, 0, len);
  16365. return buf;
  16366. }
  16367. if (obj.length !== undefined) {
  16368. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  16369. return createBuffer(0);
  16370. }
  16371. return fromArrayLike(obj);
  16372. }
  16373. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  16374. return fromArrayLike(obj.data);
  16375. }
  16376. }
  16377. function checked(length) {
  16378. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  16379. // length is NaN (which is otherwise coerced to zero.)
  16380. if (length >= K_MAX_LENGTH) {
  16381. throw new RangeError(
  16382. 'Attempt to allocate Buffer larger than maximum ' +
  16383. 'size: 0x' +
  16384. K_MAX_LENGTH.toString(16) +
  16385. ' bytes'
  16386. );
  16387. }
  16388. return length | 0;
  16389. }
  16390. function SlowBuffer(length) {
  16391. if (+length != length) {
  16392. // eslint-disable-line eqeqeq
  16393. length = 0;
  16394. }
  16395. return Buffer.alloc(+length);
  16396. }
  16397. Buffer.isBuffer = function isBuffer(b) {
  16398. return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false
  16399. };
  16400. Buffer.compare = function compare(a, b) {
  16401. if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
  16402. if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
  16403. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  16404. throw new TypeError(
  16405. 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
  16406. );
  16407. }
  16408. if (a === b) return 0;
  16409. var x = a.length;
  16410. var y = b.length;
  16411. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  16412. if (a[i] !== b[i]) {
  16413. x = a[i];
  16414. y = b[i];
  16415. break;
  16416. }
  16417. }
  16418. if (x < y) return -1;
  16419. if (y < x) return 1;
  16420. return 0;
  16421. };
  16422. Buffer.isEncoding = function isEncoding(encoding) {
  16423. switch (String(encoding).toLowerCase()) {
  16424. case 'hex':
  16425. case 'utf8':
  16426. case 'utf-8':
  16427. case 'ascii':
  16428. case 'latin1':
  16429. case 'binary':
  16430. case 'base64':
  16431. case 'ucs2':
  16432. case 'ucs-2':
  16433. case 'utf16le':
  16434. case 'utf-16le':
  16435. return true;
  16436. default:
  16437. return false;
  16438. }
  16439. };
  16440. Buffer.concat = function concat(list, length) {
  16441. if (!Array.isArray(list)) {
  16442. throw new TypeError('"list" argument must be an Array of Buffers');
  16443. }
  16444. if (list.length === 0) {
  16445. return Buffer.alloc(0);
  16446. }
  16447. var i;
  16448. if (length === undefined) {
  16449. length = 0;
  16450. for (i = 0; i < list.length; ++i) {
  16451. length += list[i].length;
  16452. }
  16453. }
  16454. var buffer = Buffer.allocUnsafe(length);
  16455. var pos = 0;
  16456. for (i = 0; i < list.length; ++i) {
  16457. var buf = list[i];
  16458. if (isInstance(buf, Uint8Array)) {
  16459. buf = Buffer.from(buf);
  16460. }
  16461. if (!Buffer.isBuffer(buf)) {
  16462. throw new TypeError('"list" argument must be an Array of Buffers');
  16463. }
  16464. buf.copy(buffer, pos);
  16465. pos += buf.length;
  16466. }
  16467. return buffer;
  16468. };
  16469. function byteLength(string, encoding) {
  16470. if (Buffer.isBuffer(string)) {
  16471. return string.length;
  16472. }
  16473. if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
  16474. return string.byteLength;
  16475. }
  16476. if (typeof string !== 'string') {
  16477. throw new TypeError(
  16478. 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
  16479. 'Received type ' +
  16480. typeof string
  16481. );
  16482. }
  16483. var len = string.length;
  16484. var mustMatch = arguments.length > 2 && arguments[2] === true;
  16485. if (!mustMatch && len === 0) return 0;
  16486. // Use a for loop to avoid recursion
  16487. var loweredCase = false;
  16488. for (;;) {
  16489. switch (encoding) {
  16490. case 'ascii':
  16491. case 'latin1':
  16492. case 'binary':
  16493. return len;
  16494. case 'utf8':
  16495. case 'utf-8':
  16496. return utf8ToBytes(string).length;
  16497. case 'ucs2':
  16498. case 'ucs-2':
  16499. case 'utf16le':
  16500. case 'utf-16le':
  16501. return len * 2;
  16502. case 'hex':
  16503. return len >>> 1;
  16504. case 'base64':
  16505. return base64ToBytes(string).length;
  16506. default:
  16507. if (loweredCase) {
  16508. return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8
  16509. }
  16510. encoding = ('' + encoding).toLowerCase();
  16511. loweredCase = true;
  16512. }
  16513. }
  16514. }
  16515. Buffer.byteLength = byteLength;
  16516. function slowToString(encoding, start, end) {
  16517. var loweredCase = false;
  16518. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  16519. // property of a typed array.
  16520. // This behaves neither like String nor Uint8Array in that we set start/end
  16521. // to their upper/lower bounds if the value passed is out of range.
  16522. // undefined is handled specially as per ECMA-262 6th Edition,
  16523. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  16524. if (start === undefined || start < 0) {
  16525. start = 0;
  16526. }
  16527. // Return early if start > this.length. Done here to prevent potential uint32
  16528. // coercion fail below.
  16529. if (start > this.length) {
  16530. return '';
  16531. }
  16532. if (end === undefined || end > this.length) {
  16533. end = this.length;
  16534. }
  16535. if (end <= 0) {
  16536. return '';
  16537. }
  16538. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  16539. end >>>= 0;
  16540. start >>>= 0;
  16541. if (end <= start) {
  16542. return '';
  16543. }
  16544. if (!encoding) encoding = 'utf8';
  16545. while (true) {
  16546. switch (encoding) {
  16547. case 'hex':
  16548. return hexSlice(this, start, end);
  16549. case 'utf8':
  16550. case 'utf-8':
  16551. return utf8Slice(this, start, end);
  16552. case 'ascii':
  16553. return asciiSlice(this, start, end);
  16554. case 'latin1':
  16555. case 'binary':
  16556. return latin1Slice(this, start, end);
  16557. case 'base64':
  16558. return base64Slice(this, start, end);
  16559. case 'ucs2':
  16560. case 'ucs-2':
  16561. case 'utf16le':
  16562. case 'utf-16le':
  16563. return utf16leSlice(this, start, end);
  16564. default:
  16565. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  16566. encoding = (encoding + '').toLowerCase();
  16567. loweredCase = true;
  16568. }
  16569. }
  16570. }
  16571. // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  16572. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  16573. // reliably in a browserify context because there could be multiple different
  16574. // copies of the 'buffer' package in use. This method works even for Buffer
  16575. // instances that were created from another copy of the `buffer` package.
  16576. // See: https://github.com/feross/buffer/issues/154
  16577. Buffer.prototype._isBuffer = true;
  16578. function swap(b, n, m) {
  16579. var i = b[n];
  16580. b[n] = b[m];
  16581. b[m] = i;
  16582. }
  16583. Buffer.prototype.swap16 = function swap16() {
  16584. var len = this.length;
  16585. if (len % 2 !== 0) {
  16586. throw new RangeError('Buffer size must be a multiple of 16-bits');
  16587. }
  16588. for (var i = 0; i < len; i += 2) {
  16589. swap(this, i, i + 1);
  16590. }
  16591. return this;
  16592. };
  16593. Buffer.prototype.swap32 = function swap32() {
  16594. var len = this.length;
  16595. if (len % 4 !== 0) {
  16596. throw new RangeError('Buffer size must be a multiple of 32-bits');
  16597. }
  16598. for (var i = 0; i < len; i += 4) {
  16599. swap(this, i, i + 3);
  16600. swap(this, i + 1, i + 2);
  16601. }
  16602. return this;
  16603. };
  16604. Buffer.prototype.swap64 = function swap64() {
  16605. var len = this.length;
  16606. if (len % 8 !== 0) {
  16607. throw new RangeError('Buffer size must be a multiple of 64-bits');
  16608. }
  16609. for (var i = 0; i < len; i += 8) {
  16610. swap(this, i, i + 7);
  16611. swap(this, i + 1, i + 6);
  16612. swap(this, i + 2, i + 5);
  16613. swap(this, i + 3, i + 4);
  16614. }
  16615. return this;
  16616. };
  16617. Buffer.prototype.toString = function toString() {
  16618. var length = this.length;
  16619. if (length === 0) return '';
  16620. if (arguments.length === 0) return utf8Slice(this, 0, length);
  16621. return slowToString.apply(this, arguments);
  16622. };
  16623. Buffer.prototype.toLocaleString = Buffer.prototype.toString;
  16624. Buffer.prototype.equals = function equals(b) {
  16625. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer');
  16626. if (this === b) return true;
  16627. return Buffer.compare(this, b) === 0;
  16628. };
  16629. Buffer.prototype.inspect = function inspect() {
  16630. var str = '';
  16631. var max = exports.INSPECT_MAX_BYTES;
  16632. str = this.toString('hex', 0, max)
  16633. .replace(/(.{2})/g, '$1 ')
  16634. .trim();
  16635. if (this.length > max) str += ' ... ';
  16636. return '<Buffer ' + str + '>';
  16637. };
  16638. if (customInspectSymbol) {
  16639. Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
  16640. }
  16641. Buffer.prototype.compare = function compare(
  16642. target,
  16643. start,
  16644. end,
  16645. thisStart,
  16646. thisEnd
  16647. ) {
  16648. if (isInstance(target, Uint8Array)) {
  16649. target = Buffer.from(target, target.offset, target.byteLength);
  16650. }
  16651. if (!Buffer.isBuffer(target)) {
  16652. throw new TypeError(
  16653. 'The "target" argument must be one of type Buffer or Uint8Array. ' +
  16654. 'Received type ' +
  16655. typeof target
  16656. );
  16657. }
  16658. if (start === undefined) {
  16659. start = 0;
  16660. }
  16661. if (end === undefined) {
  16662. end = target ? target.length : 0;
  16663. }
  16664. if (thisStart === undefined) {
  16665. thisStart = 0;
  16666. }
  16667. if (thisEnd === undefined) {
  16668. thisEnd = this.length;
  16669. }
  16670. if (
  16671. start < 0 ||
  16672. end > target.length ||
  16673. thisStart < 0 ||
  16674. thisEnd > this.length
  16675. ) {
  16676. throw new RangeError('out of range index');
  16677. }
  16678. if (thisStart >= thisEnd && start >= end) {
  16679. return 0;
  16680. }
  16681. if (thisStart >= thisEnd) {
  16682. return -1;
  16683. }
  16684. if (start >= end) {
  16685. return 1;
  16686. }
  16687. start >>>= 0;
  16688. end >>>= 0;
  16689. thisStart >>>= 0;
  16690. thisEnd >>>= 0;
  16691. if (this === target) return 0;
  16692. var x = thisEnd - thisStart;
  16693. var y = end - start;
  16694. var len = Math.min(x, y);
  16695. var thisCopy = this.slice(thisStart, thisEnd);
  16696. var targetCopy = target.slice(start, end);
  16697. for (var i = 0; i < len; ++i) {
  16698. if (thisCopy[i] !== targetCopy[i]) {
  16699. x = thisCopy[i];
  16700. y = targetCopy[i];
  16701. break;
  16702. }
  16703. }
  16704. if (x < y) return -1;
  16705. if (y < x) return 1;
  16706. return 0;
  16707. };
  16708. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  16709. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  16710. //
  16711. // Arguments:
  16712. // - buffer - a Buffer to search
  16713. // - val - a string, Buffer, or number
  16714. // - byteOffset - an index into `buffer`; will be clamped to an int32
  16715. // - encoding - an optional encoding, relevant is val is a string
  16716. // - dir - true for indexOf, false for lastIndexOf
  16717. function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
  16718. // Empty buffer means no match
  16719. if (buffer.length === 0) return -1;
  16720. // Normalize byteOffset
  16721. if (typeof byteOffset === 'string') {
  16722. encoding = byteOffset;
  16723. byteOffset = 0;
  16724. } else if (byteOffset > 0x7fffffff) {
  16725. byteOffset = 0x7fffffff;
  16726. } else if (byteOffset < -0x80000000) {
  16727. byteOffset = -0x80000000;
  16728. }
  16729. byteOffset = +byteOffset; // Coerce to Number.
  16730. if (numberIsNaN(byteOffset)) {
  16731. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  16732. byteOffset = dir ? 0 : buffer.length - 1;
  16733. }
  16734. // Normalize byteOffset: negative offsets start from the end of the buffer
  16735. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  16736. if (byteOffset >= buffer.length) {
  16737. if (dir) return -1;
  16738. else byteOffset = buffer.length - 1;
  16739. } else if (byteOffset < 0) {
  16740. if (dir) byteOffset = 0;
  16741. else return -1;
  16742. }
  16743. // Normalize val
  16744. if (typeof val === 'string') {
  16745. val = Buffer.from(val, encoding);
  16746. }
  16747. // Finally, search either indexOf (if dir is true) or lastIndexOf
  16748. if (Buffer.isBuffer(val)) {
  16749. // Special case: looking for empty string/buffer always fails
  16750. if (val.length === 0) {
  16751. return -1;
  16752. }
  16753. return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
  16754. } else if (typeof val === 'number') {
  16755. val = val & 0xff; // Search for a byte value [0-255]
  16756. if (typeof Uint8Array.prototype.indexOf === 'function') {
  16757. if (dir) {
  16758. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
  16759. } else {
  16760. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
  16761. }
  16762. }
  16763. return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
  16764. }
  16765. throw new TypeError('val must be string, number or Buffer');
  16766. }
  16767. function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
  16768. var indexSize = 1;
  16769. var arrLength = arr.length;
  16770. var valLength = val.length;
  16771. if (encoding !== undefined) {
  16772. encoding = String(encoding).toLowerCase();
  16773. if (
  16774. encoding === 'ucs2' ||
  16775. encoding === 'ucs-2' ||
  16776. encoding === 'utf16le' ||
  16777. encoding === 'utf-16le'
  16778. ) {
  16779. if (arr.length < 2 || val.length < 2) {
  16780. return -1;
  16781. }
  16782. indexSize = 2;
  16783. arrLength /= 2;
  16784. valLength /= 2;
  16785. byteOffset /= 2;
  16786. }
  16787. }
  16788. function read(buf, i) {
  16789. if (indexSize === 1) {
  16790. return buf[i];
  16791. } else {
  16792. return buf.readUInt16BE(i * indexSize);
  16793. }
  16794. }
  16795. var i;
  16796. if (dir) {
  16797. var foundIndex = -1;
  16798. for (i = byteOffset; i < arrLength; i++) {
  16799. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  16800. if (foundIndex === -1) foundIndex = i;
  16801. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
  16802. } else {
  16803. if (foundIndex !== -1) i -= i - foundIndex;
  16804. foundIndex = -1;
  16805. }
  16806. }
  16807. } else {
  16808. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  16809. for (i = byteOffset; i >= 0; i--) {
  16810. var found = true;
  16811. for (var j = 0; j < valLength; j++) {
  16812. if (read(arr, i + j) !== read(val, j)) {
  16813. found = false;
  16814. break;
  16815. }
  16816. }
  16817. if (found) return i;
  16818. }
  16819. }
  16820. return -1;
  16821. }
  16822. Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
  16823. return this.indexOf(val, byteOffset, encoding) !== -1;
  16824. };
  16825. Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
  16826. return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
  16827. };
  16828. Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
  16829. return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
  16830. };
  16831. function hexWrite(buf, string, offset, length) {
  16832. offset = Number(offset) || 0;
  16833. var remaining = buf.length - offset;
  16834. if (!length) {
  16835. length = remaining;
  16836. } else {
  16837. length = Number(length);
  16838. if (length > remaining) {
  16839. length = remaining;
  16840. }
  16841. }
  16842. var strLen = string.length;
  16843. if (length > strLen / 2) {
  16844. length = strLen / 2;
  16845. }
  16846. for (var i = 0; i < length; ++i) {
  16847. var parsed = parseInt(string.substr(i * 2, 2), 16);
  16848. if (numberIsNaN(parsed)) return i;
  16849. buf[offset + i] = parsed;
  16850. }
  16851. return i;
  16852. }
  16853. function utf8Write(buf, string, offset, length) {
  16854. return blitBuffer(
  16855. utf8ToBytes(string, buf.length - offset),
  16856. buf,
  16857. offset,
  16858. length
  16859. );
  16860. }
  16861. function asciiWrite(buf, string, offset, length) {
  16862. return blitBuffer(asciiToBytes(string), buf, offset, length);
  16863. }
  16864. function latin1Write(buf, string, offset, length) {
  16865. return asciiWrite(buf, string, offset, length);
  16866. }
  16867. function base64Write(buf, string, offset, length) {
  16868. return blitBuffer(base64ToBytes(string), buf, offset, length);
  16869. }
  16870. function ucs2Write(buf, string, offset, length) {
  16871. return blitBuffer(
  16872. utf16leToBytes(string, buf.length - offset),
  16873. buf,
  16874. offset,
  16875. length
  16876. );
  16877. }
  16878. Buffer.prototype.write = function write(string, offset, length, encoding) {
  16879. // Buffer#write(string)
  16880. if (offset === undefined) {
  16881. encoding = 'utf8';
  16882. length = this.length;
  16883. offset = 0;
  16884. // Buffer#write(string, encoding)
  16885. } else if (length === undefined && typeof offset === 'string') {
  16886. encoding = offset;
  16887. length = this.length;
  16888. offset = 0;
  16889. // Buffer#write(string, offset[, length][, encoding])
  16890. } else if (isFinite(offset)) {
  16891. offset = offset >>> 0;
  16892. if (isFinite(length)) {
  16893. length = length >>> 0;
  16894. if (encoding === undefined) encoding = 'utf8';
  16895. } else {
  16896. encoding = length;
  16897. length = undefined;
  16898. }
  16899. } else {
  16900. throw new Error(
  16901. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  16902. );
  16903. }
  16904. var remaining = this.length - offset;
  16905. if (length === undefined || length > remaining) length = remaining;
  16906. if (
  16907. (string.length > 0 && (length < 0 || offset < 0)) ||
  16908. offset > this.length
  16909. ) {
  16910. throw new RangeError('Attempt to write outside buffer bounds');
  16911. }
  16912. if (!encoding) encoding = 'utf8';
  16913. var loweredCase = false;
  16914. for (;;) {
  16915. switch (encoding) {
  16916. case 'hex':
  16917. return hexWrite(this, string, offset, length);
  16918. case 'utf8':
  16919. case 'utf-8':
  16920. return utf8Write(this, string, offset, length);
  16921. case 'ascii':
  16922. return asciiWrite(this, string, offset, length);
  16923. case 'latin1':
  16924. case 'binary':
  16925. return latin1Write(this, string, offset, length);
  16926. case 'base64':
  16927. // Warning: maxLength not taken into account in base64Write
  16928. return base64Write(this, string, offset, length);
  16929. case 'ucs2':
  16930. case 'ucs-2':
  16931. case 'utf16le':
  16932. case 'utf-16le':
  16933. return ucs2Write(this, string, offset, length);
  16934. default:
  16935. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  16936. encoding = ('' + encoding).toLowerCase();
  16937. loweredCase = true;
  16938. }
  16939. }
  16940. };
  16941. Buffer.prototype.toJSON = function toJSON() {
  16942. return {
  16943. type: 'Buffer',
  16944. data: Array.prototype.slice.call(this._arr || this, 0)
  16945. };
  16946. };
  16947. function base64Slice(buf, start, end) {
  16948. if (start === 0 && end === buf.length) {
  16949. return base64.fromByteArray(buf);
  16950. } else {
  16951. return base64.fromByteArray(buf.slice(start, end));
  16952. }
  16953. }
  16954. function utf8Slice(buf, start, end) {
  16955. end = Math.min(buf.length, end);
  16956. var res = [];
  16957. var i = start;
  16958. while (i < end) {
  16959. var firstByte = buf[i];
  16960. var codePoint = null;
  16961. var bytesPerSequence =
  16962. firstByte > 0xef ? 4 : firstByte > 0xdf ? 3 : firstByte > 0xbf ? 2 : 1;
  16963. if (i + bytesPerSequence <= end) {
  16964. var secondByte, thirdByte, fourthByte, tempCodePoint;
  16965. switch (bytesPerSequence) {
  16966. case 1:
  16967. if (firstByte < 0x80) {
  16968. codePoint = firstByte;
  16969. }
  16970. break;
  16971. case 2:
  16972. secondByte = buf[i + 1];
  16973. if ((secondByte & 0xc0) === 0x80) {
  16974. tempCodePoint = ((firstByte & 0x1f) << 0x6) | (secondByte & 0x3f);
  16975. if (tempCodePoint > 0x7f) {
  16976. codePoint = tempCodePoint;
  16977. }
  16978. }
  16979. break;
  16980. case 3:
  16981. secondByte = buf[i + 1];
  16982. thirdByte = buf[i + 2];
  16983. if ((secondByte & 0xc0) === 0x80 && (thirdByte & 0xc0) === 0x80) {
  16984. tempCodePoint =
  16985. ((firstByte & 0xf) << 0xc) |
  16986. ((secondByte & 0x3f) << 0x6) |
  16987. (thirdByte & 0x3f);
  16988. if (
  16989. tempCodePoint > 0x7ff &&
  16990. (tempCodePoint < 0xd800 || tempCodePoint > 0xdfff)
  16991. ) {
  16992. codePoint = tempCodePoint;
  16993. }
  16994. }
  16995. break;
  16996. case 4:
  16997. secondByte = buf[i + 1];
  16998. thirdByte = buf[i + 2];
  16999. fourthByte = buf[i + 3];
  17000. if (
  17001. (secondByte & 0xc0) === 0x80 &&
  17002. (thirdByte & 0xc0) === 0x80 &&
  17003. (fourthByte & 0xc0) === 0x80
  17004. ) {
  17005. tempCodePoint =
  17006. ((firstByte & 0xf) << 0x12) |
  17007. ((secondByte & 0x3f) << 0xc) |
  17008. ((thirdByte & 0x3f) << 0x6) |
  17009. (fourthByte & 0x3f);
  17010. if (tempCodePoint > 0xffff && tempCodePoint < 0x110000) {
  17011. codePoint = tempCodePoint;
  17012. }
  17013. }
  17014. }
  17015. }
  17016. if (codePoint === null) {
  17017. // we did not generate a valid codePoint so insert a
  17018. // replacement char (U+FFFD) and advance only 1 byte
  17019. codePoint = 0xfffd;
  17020. bytesPerSequence = 1;
  17021. } else if (codePoint > 0xffff) {
  17022. // encode to utf16 (surrogate pair dance)
  17023. codePoint -= 0x10000;
  17024. res.push(((codePoint >>> 10) & 0x3ff) | 0xd800);
  17025. codePoint = 0xdc00 | (codePoint & 0x3ff);
  17026. }
  17027. res.push(codePoint);
  17028. i += bytesPerSequence;
  17029. }
  17030. return decodeCodePointsArray(res);
  17031. }
  17032. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  17033. // the lowest limit is Chrome, with 0x10000 args.
  17034. // We go 1 magnitude less, for safety
  17035. var MAX_ARGUMENTS_LENGTH = 0x1000;
  17036. function decodeCodePointsArray(codePoints) {
  17037. var len = codePoints.length;
  17038. if (len <= MAX_ARGUMENTS_LENGTH) {
  17039. return String.fromCharCode.apply(String, codePoints); // avoid extra slice()
  17040. }
  17041. // Decode in chunks to avoid "call stack size exceeded".
  17042. var res = '';
  17043. var i = 0;
  17044. while (i < len) {
  17045. res += String.fromCharCode.apply(
  17046. String,
  17047. codePoints.slice(i, (i += MAX_ARGUMENTS_LENGTH))
  17048. );
  17049. }
  17050. return res;
  17051. }
  17052. function asciiSlice(buf, start, end) {
  17053. var ret = '';
  17054. end = Math.min(buf.length, end);
  17055. for (var i = start; i < end; ++i) {
  17056. ret += String.fromCharCode(buf[i] & 0x7f);
  17057. }
  17058. return ret;
  17059. }
  17060. function latin1Slice(buf, start, end) {
  17061. var ret = '';
  17062. end = Math.min(buf.length, end);
  17063. for (var i = start; i < end; ++i) {
  17064. ret += String.fromCharCode(buf[i]);
  17065. }
  17066. return ret;
  17067. }
  17068. function hexSlice(buf, start, end) {
  17069. var len = buf.length;
  17070. if (!start || start < 0) start = 0;
  17071. if (!end || end < 0 || end > len) end = len;
  17072. var out = '';
  17073. for (var i = start; i < end; ++i) {
  17074. out += hexSliceLookupTable[buf[i]];
  17075. }
  17076. return out;
  17077. }
  17078. function utf16leSlice(buf, start, end) {
  17079. var bytes = buf.slice(start, end);
  17080. var res = '';
  17081. for (var i = 0; i < bytes.length; i += 2) {
  17082. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  17083. }
  17084. return res;
  17085. }
  17086. Buffer.prototype.slice = function slice(start, end) {
  17087. var len = this.length;
  17088. start = ~~start;
  17089. end = end === undefined ? len : ~~end;
  17090. if (start < 0) {
  17091. start += len;
  17092. if (start < 0) start = 0;
  17093. } else if (start > len) {
  17094. start = len;
  17095. }
  17096. if (end < 0) {
  17097. end += len;
  17098. if (end < 0) end = 0;
  17099. } else if (end > len) {
  17100. end = len;
  17101. }
  17102. if (end < start) end = start;
  17103. var newBuf = this.subarray(start, end);
  17104. // Return an augmented `Uint8Array` instance
  17105. Object.setPrototypeOf(newBuf, Buffer.prototype);
  17106. return newBuf;
  17107. };
  17108. /*
  17109. * Need to make sure that buffer isn't trying to write out of bounds.
  17110. */
  17111. function checkOffset(offset, ext, length) {
  17112. if (offset % 1 !== 0 || offset < 0)
  17113. throw new RangeError('offset is not uint');
  17114. if (offset + ext > length)
  17115. throw new RangeError('Trying to access beyond buffer length');
  17116. }
  17117. Buffer.prototype.readUIntLE = function readUIntLE(
  17118. offset,
  17119. byteLength,
  17120. noAssert
  17121. ) {
  17122. offset = offset >>> 0;
  17123. byteLength = byteLength >>> 0;
  17124. if (!noAssert) checkOffset(offset, byteLength, this.length);
  17125. var val = this[offset];
  17126. var mul = 1;
  17127. var i = 0;
  17128. while (++i < byteLength && (mul *= 0x100)) {
  17129. val += this[offset + i] * mul;
  17130. }
  17131. return val;
  17132. };
  17133. Buffer.prototype.readUIntBE = function readUIntBE(
  17134. offset,
  17135. byteLength,
  17136. noAssert
  17137. ) {
  17138. offset = offset >>> 0;
  17139. byteLength = byteLength >>> 0;
  17140. if (!noAssert) {
  17141. checkOffset(offset, byteLength, this.length);
  17142. }
  17143. var val = this[offset + --byteLength];
  17144. var mul = 1;
  17145. while (byteLength > 0 && (mul *= 0x100)) {
  17146. val += this[offset + --byteLength] * mul;
  17147. }
  17148. return val;
  17149. };
  17150. Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
  17151. offset = offset >>> 0;
  17152. if (!noAssert) checkOffset(offset, 1, this.length);
  17153. return this[offset];
  17154. };
  17155. Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
  17156. offset = offset >>> 0;
  17157. if (!noAssert) checkOffset(offset, 2, this.length);
  17158. return this[offset] | (this[offset + 1] << 8);
  17159. };
  17160. Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
  17161. offset = offset >>> 0;
  17162. if (!noAssert) checkOffset(offset, 2, this.length);
  17163. return (this[offset] << 8) | this[offset + 1];
  17164. };
  17165. Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
  17166. offset = offset >>> 0;
  17167. if (!noAssert) checkOffset(offset, 4, this.length);
  17168. return (
  17169. (this[offset] | (this[offset + 1] << 8) | (this[offset + 2] << 16)) +
  17170. this[offset + 3] * 0x1000000
  17171. );
  17172. };
  17173. Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
  17174. offset = offset >>> 0;
  17175. if (!noAssert) checkOffset(offset, 4, this.length);
  17176. return (
  17177. this[offset] * 0x1000000 +
  17178. ((this[offset + 1] << 16) | (this[offset + 2] << 8) | this[offset + 3])
  17179. );
  17180. };
  17181. Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
  17182. offset = offset >>> 0;
  17183. byteLength = byteLength >>> 0;
  17184. if (!noAssert) checkOffset(offset, byteLength, this.length);
  17185. var val = this[offset];
  17186. var mul = 1;
  17187. var i = 0;
  17188. while (++i < byteLength && (mul *= 0x100)) {
  17189. val += this[offset + i] * mul;
  17190. }
  17191. mul *= 0x80;
  17192. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  17193. return val;
  17194. };
  17195. Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
  17196. offset = offset >>> 0;
  17197. byteLength = byteLength >>> 0;
  17198. if (!noAssert) checkOffset(offset, byteLength, this.length);
  17199. var i = byteLength;
  17200. var mul = 1;
  17201. var val = this[offset + --i];
  17202. while (i > 0 && (mul *= 0x100)) {
  17203. val += this[offset + --i] * mul;
  17204. }
  17205. mul *= 0x80;
  17206. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  17207. return val;
  17208. };
  17209. Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
  17210. offset = offset >>> 0;
  17211. if (!noAssert) checkOffset(offset, 1, this.length);
  17212. if (!(this[offset] & 0x80)) return this[offset];
  17213. return (0xff - this[offset] + 1) * -1;
  17214. };
  17215. Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
  17216. offset = offset >>> 0;
  17217. if (!noAssert) checkOffset(offset, 2, this.length);
  17218. var val = this[offset] | (this[offset + 1] << 8);
  17219. return val & 0x8000 ? val | 0xffff0000 : val;
  17220. };
  17221. Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
  17222. offset = offset >>> 0;
  17223. if (!noAssert) checkOffset(offset, 2, this.length);
  17224. var val = this[offset + 1] | (this[offset] << 8);
  17225. return val & 0x8000 ? val | 0xffff0000 : val;
  17226. };
  17227. Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
  17228. offset = offset >>> 0;
  17229. if (!noAssert) checkOffset(offset, 4, this.length);
  17230. return (
  17231. this[offset] |
  17232. (this[offset + 1] << 8) |
  17233. (this[offset + 2] << 16) |
  17234. (this[offset + 3] << 24)
  17235. );
  17236. };
  17237. Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
  17238. offset = offset >>> 0;
  17239. if (!noAssert) checkOffset(offset, 4, this.length);
  17240. return (
  17241. (this[offset] << 24) |
  17242. (this[offset + 1] << 16) |
  17243. (this[offset + 2] << 8) |
  17244. this[offset + 3]
  17245. );
  17246. };
  17247. Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
  17248. offset = offset >>> 0;
  17249. if (!noAssert) checkOffset(offset, 4, this.length);
  17250. return ieee754.read(this, offset, true, 23, 4);
  17251. };
  17252. Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
  17253. offset = offset >>> 0;
  17254. if (!noAssert) checkOffset(offset, 4, this.length);
  17255. return ieee754.read(this, offset, false, 23, 4);
  17256. };
  17257. Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
  17258. offset = offset >>> 0;
  17259. if (!noAssert) checkOffset(offset, 8, this.length);
  17260. return ieee754.read(this, offset, true, 52, 8);
  17261. };
  17262. Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
  17263. offset = offset >>> 0;
  17264. if (!noAssert) checkOffset(offset, 8, this.length);
  17265. return ieee754.read(this, offset, false, 52, 8);
  17266. };
  17267. function checkInt(buf, value, offset, ext, max, min) {
  17268. if (!Buffer.isBuffer(buf))
  17269. throw new TypeError('"buffer" argument must be a Buffer instance');
  17270. if (value > max || value < min)
  17271. throw new RangeError('"value" argument is out of bounds');
  17272. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  17273. }
  17274. Buffer.prototype.writeUIntLE = function writeUIntLE(
  17275. value,
  17276. offset,
  17277. byteLength,
  17278. noAssert
  17279. ) {
  17280. value = +value;
  17281. offset = offset >>> 0;
  17282. byteLength = byteLength >>> 0;
  17283. if (!noAssert) {
  17284. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  17285. checkInt(this, value, offset, byteLength, maxBytes, 0);
  17286. }
  17287. var mul = 1;
  17288. var i = 0;
  17289. this[offset] = value & 0xff;
  17290. while (++i < byteLength && (mul *= 0x100)) {
  17291. this[offset + i] = (value / mul) & 0xff;
  17292. }
  17293. return offset + byteLength;
  17294. };
  17295. Buffer.prototype.writeUIntBE = function writeUIntBE(
  17296. value,
  17297. offset,
  17298. byteLength,
  17299. noAssert
  17300. ) {
  17301. value = +value;
  17302. offset = offset >>> 0;
  17303. byteLength = byteLength >>> 0;
  17304. if (!noAssert) {
  17305. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  17306. checkInt(this, value, offset, byteLength, maxBytes, 0);
  17307. }
  17308. var i = byteLength - 1;
  17309. var mul = 1;
  17310. this[offset + i] = value & 0xff;
  17311. while (--i >= 0 && (mul *= 0x100)) {
  17312. this[offset + i] = (value / mul) & 0xff;
  17313. }
  17314. return offset + byteLength;
  17315. };
  17316. Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
  17317. value = +value;
  17318. offset = offset >>> 0;
  17319. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  17320. this[offset] = value & 0xff;
  17321. return offset + 1;
  17322. };
  17323. Buffer.prototype.writeUInt16LE = function writeUInt16LE(
  17324. value,
  17325. offset,
  17326. noAssert
  17327. ) {
  17328. value = +value;
  17329. offset = offset >>> 0;
  17330. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  17331. this[offset] = value & 0xff;
  17332. this[offset + 1] = value >>> 8;
  17333. return offset + 2;
  17334. };
  17335. Buffer.prototype.writeUInt16BE = function writeUInt16BE(
  17336. value,
  17337. offset,
  17338. noAssert
  17339. ) {
  17340. value = +value;
  17341. offset = offset >>> 0;
  17342. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  17343. this[offset] = value >>> 8;
  17344. this[offset + 1] = value & 0xff;
  17345. return offset + 2;
  17346. };
  17347. Buffer.prototype.writeUInt32LE = function writeUInt32LE(
  17348. value,
  17349. offset,
  17350. noAssert
  17351. ) {
  17352. value = +value;
  17353. offset = offset >>> 0;
  17354. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  17355. this[offset + 3] = value >>> 24;
  17356. this[offset + 2] = value >>> 16;
  17357. this[offset + 1] = value >>> 8;
  17358. this[offset] = value & 0xff;
  17359. return offset + 4;
  17360. };
  17361. Buffer.prototype.writeUInt32BE = function writeUInt32BE(
  17362. value,
  17363. offset,
  17364. noAssert
  17365. ) {
  17366. value = +value;
  17367. offset = offset >>> 0;
  17368. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  17369. this[offset] = value >>> 24;
  17370. this[offset + 1] = value >>> 16;
  17371. this[offset + 2] = value >>> 8;
  17372. this[offset + 3] = value & 0xff;
  17373. return offset + 4;
  17374. };
  17375. Buffer.prototype.writeIntLE = function writeIntLE(
  17376. value,
  17377. offset,
  17378. byteLength,
  17379. noAssert
  17380. ) {
  17381. value = +value;
  17382. offset = offset >>> 0;
  17383. if (!noAssert) {
  17384. var limit = Math.pow(2, 8 * byteLength - 1);
  17385. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  17386. }
  17387. var i = 0;
  17388. var mul = 1;
  17389. var sub = 0;
  17390. this[offset] = value & 0xff;
  17391. while (++i < byteLength && (mul *= 0x100)) {
  17392. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  17393. sub = 1;
  17394. }
  17395. this[offset + i] = (((value / mul) >> 0) - sub) & 0xff;
  17396. }
  17397. return offset + byteLength;
  17398. };
  17399. Buffer.prototype.writeIntBE = function writeIntBE(
  17400. value,
  17401. offset,
  17402. byteLength,
  17403. noAssert
  17404. ) {
  17405. value = +value;
  17406. offset = offset >>> 0;
  17407. if (!noAssert) {
  17408. var limit = Math.pow(2, 8 * byteLength - 1);
  17409. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  17410. }
  17411. var i = byteLength - 1;
  17412. var mul = 1;
  17413. var sub = 0;
  17414. this[offset + i] = value & 0xff;
  17415. while (--i >= 0 && (mul *= 0x100)) {
  17416. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  17417. sub = 1;
  17418. }
  17419. this[offset + i] = (((value / mul) >> 0) - sub) & 0xff;
  17420. }
  17421. return offset + byteLength;
  17422. };
  17423. Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
  17424. value = +value;
  17425. offset = offset >>> 0;
  17426. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
  17427. if (value < 0) value = 0xff + value + 1;
  17428. this[offset] = value & 0xff;
  17429. return offset + 1;
  17430. };
  17431. Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
  17432. value = +value;
  17433. offset = offset >>> 0;
  17434. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  17435. this[offset] = value & 0xff;
  17436. this[offset + 1] = value >>> 8;
  17437. return offset + 2;
  17438. };
  17439. Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
  17440. value = +value;
  17441. offset = offset >>> 0;
  17442. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  17443. this[offset] = value >>> 8;
  17444. this[offset + 1] = value & 0xff;
  17445. return offset + 2;
  17446. };
  17447. Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
  17448. value = +value;
  17449. offset = offset >>> 0;
  17450. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  17451. this[offset] = value & 0xff;
  17452. this[offset + 1] = value >>> 8;
  17453. this[offset + 2] = value >>> 16;
  17454. this[offset + 3] = value >>> 24;
  17455. return offset + 4;
  17456. };
  17457. Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
  17458. value = +value;
  17459. offset = offset >>> 0;
  17460. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  17461. if (value < 0) value = 0xffffffff + value + 1;
  17462. this[offset] = value >>> 24;
  17463. this[offset + 1] = value >>> 16;
  17464. this[offset + 2] = value >>> 8;
  17465. this[offset + 3] = value & 0xff;
  17466. return offset + 4;
  17467. };
  17468. function checkIEEE754(buf, value, offset, ext, max, min) {
  17469. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  17470. if (offset < 0) throw new RangeError('Index out of range');
  17471. }
  17472. function writeFloat(buf, value, offset, littleEndian, noAssert) {
  17473. value = +value;
  17474. offset = offset >>> 0;
  17475. if (!noAssert) {
  17476. checkIEEE754(
  17477. buf,
  17478. value,
  17479. offset,
  17480. 4,
  17481. 3.4028234663852886e38,
  17482. -3.4028234663852886e38
  17483. );
  17484. }
  17485. ieee754.write(buf, value, offset, littleEndian, 23, 4);
  17486. return offset + 4;
  17487. }
  17488. Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
  17489. return writeFloat(this, value, offset, true, noAssert);
  17490. };
  17491. Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
  17492. return writeFloat(this, value, offset, false, noAssert);
  17493. };
  17494. function writeDouble(buf, value, offset, littleEndian, noAssert) {
  17495. value = +value;
  17496. offset = offset >>> 0;
  17497. if (!noAssert) {
  17498. checkIEEE754(
  17499. buf,
  17500. value,
  17501. offset,
  17502. 8,
  17503. 1.7976931348623157e308,
  17504. -1.7976931348623157e308
  17505. );
  17506. }
  17507. ieee754.write(buf, value, offset, littleEndian, 52, 8);
  17508. return offset + 8;
  17509. }
  17510. Buffer.prototype.writeDoubleLE = function writeDoubleLE(
  17511. value,
  17512. offset,
  17513. noAssert
  17514. ) {
  17515. return writeDouble(this, value, offset, true, noAssert);
  17516. };
  17517. Buffer.prototype.writeDoubleBE = function writeDoubleBE(
  17518. value,
  17519. offset,
  17520. noAssert
  17521. ) {
  17522. return writeDouble(this, value, offset, false, noAssert);
  17523. };
  17524. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  17525. Buffer.prototype.copy = function copy(target, targetStart, start, end) {
  17526. if (!Buffer.isBuffer(target))
  17527. throw new TypeError('argument should be a Buffer');
  17528. if (!start) start = 0;
  17529. if (!end && end !== 0) end = this.length;
  17530. if (targetStart >= target.length) targetStart = target.length;
  17531. if (!targetStart) targetStart = 0;
  17532. if (end > 0 && end < start) end = start;
  17533. // Copy 0 bytes; we're done
  17534. if (end === start) return 0;
  17535. if (target.length === 0 || this.length === 0) return 0;
  17536. // Fatal error conditions
  17537. if (targetStart < 0) {
  17538. throw new RangeError('targetStart out of bounds');
  17539. }
  17540. if (start < 0 || start >= this.length)
  17541. throw new RangeError('Index out of range');
  17542. if (end < 0) throw new RangeError('sourceEnd out of bounds');
  17543. // Are we oob?
  17544. if (end > this.length) end = this.length;
  17545. if (target.length - targetStart < end - start) {
  17546. end = target.length - targetStart + start;
  17547. }
  17548. var len = end - start;
  17549. if (
  17550. this === target &&
  17551. typeof Uint8Array.prototype.copyWithin === 'function'
  17552. ) {
  17553. // Use built-in when available, missing from IE11
  17554. this.copyWithin(targetStart, start, end);
  17555. } else if (this === target && start < targetStart && targetStart < end) {
  17556. // descending copy from end
  17557. for (var i = len - 1; i >= 0; --i) {
  17558. target[i + targetStart] = this[i + start];
  17559. }
  17560. } else {
  17561. Uint8Array.prototype.set.call(
  17562. target,
  17563. this.subarray(start, end),
  17564. targetStart
  17565. );
  17566. }
  17567. return len;
  17568. };
  17569. // Usage:
  17570. // buffer.fill(number[, offset[, end]])
  17571. // buffer.fill(buffer[, offset[, end]])
  17572. // buffer.fill(string[, offset[, end]][, encoding])
  17573. Buffer.prototype.fill = function fill(val, start, end, encoding) {
  17574. // Handle string cases:
  17575. if (typeof val === 'string') {
  17576. if (typeof start === 'string') {
  17577. encoding = start;
  17578. start = 0;
  17579. end = this.length;
  17580. } else if (typeof end === 'string') {
  17581. encoding = end;
  17582. end = this.length;
  17583. }
  17584. if (encoding !== undefined && typeof encoding !== 'string') {
  17585. throw new TypeError('encoding must be a string');
  17586. }
  17587. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  17588. throw new TypeError('Unknown encoding: ' + encoding);
  17589. }
  17590. if (val.length === 1) {
  17591. var code = val.charCodeAt(0);
  17592. if ((encoding === 'utf8' && code < 128) || encoding === 'latin1') {
  17593. // Fast path: If `val` fits into a single byte, use that numeric value.
  17594. val = code;
  17595. }
  17596. }
  17597. } else if (typeof val === 'number') {
  17598. val = val & 255;
  17599. } else if (typeof val === 'boolean') {
  17600. val = Number(val);
  17601. }
  17602. // Invalid ranges are not set to a default, so can range check early.
  17603. if (start < 0 || this.length < start || this.length < end) {
  17604. throw new RangeError('Out of range index');
  17605. }
  17606. if (end <= start) {
  17607. return this;
  17608. }
  17609. start = start >>> 0;
  17610. end = end === undefined ? this.length : end >>> 0;
  17611. if (!val) val = 0;
  17612. var i;
  17613. if (typeof val === 'number') {
  17614. for (i = start; i < end; ++i) {
  17615. this[i] = val;
  17616. }
  17617. } else {
  17618. var bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding);
  17619. var len = bytes.length;
  17620. if (len === 0) {
  17621. throw new TypeError(
  17622. 'The value "' + val + '" is invalid for argument "value"'
  17623. );
  17624. }
  17625. for (i = 0; i < end - start; ++i) {
  17626. this[i + start] = bytes[i % len];
  17627. }
  17628. }
  17629. return this;
  17630. };
  17631. // HELPER FUNCTIONS
  17632. // ================
  17633. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
  17634. function base64clean(str) {
  17635. // Node takes equal signs as end of the Base64 encoding
  17636. str = str.split('=')[0];
  17637. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  17638. str = str.trim().replace(INVALID_BASE64_RE, '');
  17639. // Node converts strings with length < 2 to ''
  17640. if (str.length < 2) return '';
  17641. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  17642. while (str.length % 4 !== 0) {
  17643. str = str + '=';
  17644. }
  17645. return str;
  17646. }
  17647. function utf8ToBytes(string, units) {
  17648. units = units || Infinity;
  17649. var codePoint;
  17650. var length = string.length;
  17651. var leadSurrogate = null;
  17652. var bytes = [];
  17653. for (var i = 0; i < length; ++i) {
  17654. codePoint = string.charCodeAt(i);
  17655. // is surrogate component
  17656. if (codePoint > 0xd7ff && codePoint < 0xe000) {
  17657. // last char was a lead
  17658. if (!leadSurrogate) {
  17659. // no lead yet
  17660. if (codePoint > 0xdbff) {
  17661. // unexpected trail
  17662. if ((units -= 3) > -1) bytes.push(0xef, 0xbf, 0xbd);
  17663. continue;
  17664. } else if (i + 1 === length) {
  17665. // unpaired lead
  17666. if ((units -= 3) > -1) bytes.push(0xef, 0xbf, 0xbd);
  17667. continue;
  17668. }
  17669. // valid lead
  17670. leadSurrogate = codePoint;
  17671. continue;
  17672. }
  17673. // 2 leads in a row
  17674. if (codePoint < 0xdc00) {
  17675. if ((units -= 3) > -1) bytes.push(0xef, 0xbf, 0xbd);
  17676. leadSurrogate = codePoint;
  17677. continue;
  17678. }
  17679. // valid surrogate pair
  17680. codePoint =
  17681. (((leadSurrogate - 0xd800) << 10) | (codePoint - 0xdc00)) + 0x10000;
  17682. } else if (leadSurrogate) {
  17683. // valid bmp char, but last char was a lead
  17684. if ((units -= 3) > -1) bytes.push(0xef, 0xbf, 0xbd);
  17685. }
  17686. leadSurrogate = null;
  17687. // encode utf8
  17688. if (codePoint < 0x80) {
  17689. if ((units -= 1) < 0) break;
  17690. bytes.push(codePoint);
  17691. } else if (codePoint < 0x800) {
  17692. if ((units -= 2) < 0) break;
  17693. bytes.push((codePoint >> 0x6) | 0xc0, (codePoint & 0x3f) | 0x80);
  17694. } else if (codePoint < 0x10000) {
  17695. if ((units -= 3) < 0) break;
  17696. bytes.push(
  17697. (codePoint >> 0xc) | 0xe0,
  17698. ((codePoint >> 0x6) & 0x3f) | 0x80,
  17699. (codePoint & 0x3f) | 0x80
  17700. );
  17701. } else if (codePoint < 0x110000) {
  17702. if ((units -= 4) < 0) break;
  17703. bytes.push(
  17704. (codePoint >> 0x12) | 0xf0,
  17705. ((codePoint >> 0xc) & 0x3f) | 0x80,
  17706. ((codePoint >> 0x6) & 0x3f) | 0x80,
  17707. (codePoint & 0x3f) | 0x80
  17708. );
  17709. } else {
  17710. throw new Error('Invalid code point');
  17711. }
  17712. }
  17713. return bytes;
  17714. }
  17715. function asciiToBytes(str) {
  17716. var byteArray = [];
  17717. for (var i = 0; i < str.length; ++i) {
  17718. // Node's code seems to be doing this and not & 0x7F..
  17719. byteArray.push(str.charCodeAt(i) & 0xff);
  17720. }
  17721. return byteArray;
  17722. }
  17723. function utf16leToBytes(str, units) {
  17724. var c, hi, lo;
  17725. var byteArray = [];
  17726. for (var i = 0; i < str.length; ++i) {
  17727. if ((units -= 2) < 0) break;
  17728. c = str.charCodeAt(i);
  17729. hi = c >> 8;
  17730. lo = c % 256;
  17731. byteArray.push(lo);
  17732. byteArray.push(hi);
  17733. }
  17734. return byteArray;
  17735. }
  17736. function base64ToBytes(str) {
  17737. return base64.toByteArray(base64clean(str));
  17738. }
  17739. function blitBuffer(src, dst, offset, length) {
  17740. for (var i = 0; i < length; ++i) {
  17741. if (i + offset >= dst.length || i >= src.length) break;
  17742. dst[i + offset] = src[i];
  17743. }
  17744. return i;
  17745. }
  17746. // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
  17747. // the `instanceof` check but they should be treated as of that type.
  17748. // See: https://github.com/feross/buffer/issues/166
  17749. function isInstance(obj, type) {
  17750. return (
  17751. obj instanceof type ||
  17752. (obj != null &&
  17753. obj.constructor != null &&
  17754. obj.constructor.name != null &&
  17755. obj.constructor.name === type.name)
  17756. );
  17757. }
  17758. function numberIsNaN(obj) {
  17759. // For IE11 support
  17760. return obj !== obj; // eslint-disable-line no-self-compare
  17761. }
  17762. // Create lookup table for `toString('hex')`
  17763. // See: https://github.com/feross/buffer/issues/219
  17764. var hexSliceLookupTable = (function() {
  17765. var alphabet = '0123456789abcdef';
  17766. var table = new Array(256);
  17767. for (var i = 0; i < 16; ++i) {
  17768. var i16 = i * 16;
  17769. for (var j = 0; j < 16; ++j) {
  17770. table[i16 + j] = alphabet[i] + alphabet[j];
  17771. }
  17772. }
  17773. return table;
  17774. })();
  17775. }.call(this, _dereq_('buffer').Buffer));
  17776. },
  17777. { 'base64-js': 20, buffer: 22, ieee754: 255 }
  17778. ],
  17779. 23: [
  17780. function(_dereq_, module, exports) {
  17781. module.exports = function(it) {
  17782. if (typeof it != 'function') {
  17783. throw TypeError(String(it) + ' is not a function');
  17784. }
  17785. return it;
  17786. };
  17787. },
  17788. {}
  17789. ],
  17790. 24: [
  17791. function(_dereq_, module, exports) {
  17792. var isObject = _dereq_('../internals/is-object');
  17793. module.exports = function(it) {
  17794. if (!isObject(it) && it !== null) {
  17795. throw TypeError("Can't set " + String(it) + ' as a prototype');
  17796. }
  17797. return it;
  17798. };
  17799. },
  17800. { '../internals/is-object': 91 }
  17801. ],
  17802. 25: [
  17803. function(_dereq_, module, exports) {
  17804. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  17805. var create = _dereq_('../internals/object-create');
  17806. var definePropertyModule = _dereq_('../internals/object-define-property');
  17807. var UNSCOPABLES = wellKnownSymbol('unscopables');
  17808. var ArrayPrototype = Array.prototype;
  17809. // Array.prototype[@@unscopables]
  17810. // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
  17811. if (ArrayPrototype[UNSCOPABLES] == undefined) {
  17812. definePropertyModule.f(ArrayPrototype, UNSCOPABLES, {
  17813. configurable: true,
  17814. value: create(null)
  17815. });
  17816. }
  17817. // add a key to Array.prototype[@@unscopables]
  17818. module.exports = function(key) {
  17819. ArrayPrototype[UNSCOPABLES][key] = true;
  17820. };
  17821. },
  17822. {
  17823. '../internals/object-create': 107,
  17824. '../internals/object-define-property': 109,
  17825. '../internals/well-known-symbol': 163
  17826. }
  17827. ],
  17828. 26: [
  17829. function(_dereq_, module, exports) {
  17830. 'use strict';
  17831. var charAt = _dereq_('../internals/string-multibyte').charAt;
  17832. // `AdvanceStringIndex` abstract operation
  17833. // https://tc39.github.io/ecma262/#sec-advancestringindex
  17834. module.exports = function(S, index, unicode) {
  17835. return index + (unicode ? charAt(S, index).length : 1);
  17836. };
  17837. },
  17838. { '../internals/string-multibyte': 140 }
  17839. ],
  17840. 27: [
  17841. function(_dereq_, module, exports) {
  17842. module.exports = function(it, Constructor, name) {
  17843. if (!(it instanceof Constructor)) {
  17844. throw TypeError('Incorrect ' + (name ? name + ' ' : '') + 'invocation');
  17845. }
  17846. return it;
  17847. };
  17848. },
  17849. {}
  17850. ],
  17851. 28: [
  17852. function(_dereq_, module, exports) {
  17853. var isObject = _dereq_('../internals/is-object');
  17854. module.exports = function(it) {
  17855. if (!isObject(it)) {
  17856. throw TypeError(String(it) + ' is not an object');
  17857. }
  17858. return it;
  17859. };
  17860. },
  17861. { '../internals/is-object': 91 }
  17862. ],
  17863. 29: [
  17864. function(_dereq_, module, exports) {
  17865. module.exports =
  17866. typeof ArrayBuffer !== 'undefined' && typeof DataView !== 'undefined';
  17867. },
  17868. {}
  17869. ],
  17870. 30: [
  17871. function(_dereq_, module, exports) {
  17872. 'use strict';
  17873. var NATIVE_ARRAY_BUFFER = _dereq_('../internals/array-buffer-native');
  17874. var DESCRIPTORS = _dereq_('../internals/descriptors');
  17875. var global = _dereq_('../internals/global');
  17876. var isObject = _dereq_('../internals/is-object');
  17877. var has = _dereq_('../internals/has');
  17878. var classof = _dereq_('../internals/classof');
  17879. var createNonEnumerableProperty = _dereq_(
  17880. '../internals/create-non-enumerable-property'
  17881. );
  17882. var redefine = _dereq_('../internals/redefine');
  17883. var defineProperty = _dereq_('../internals/object-define-property').f;
  17884. var getPrototypeOf = _dereq_('../internals/object-get-prototype-of');
  17885. var setPrototypeOf = _dereq_('../internals/object-set-prototype-of');
  17886. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  17887. var uid = _dereq_('../internals/uid');
  17888. var Int8Array = global.Int8Array;
  17889. var Int8ArrayPrototype = Int8Array && Int8Array.prototype;
  17890. var Uint8ClampedArray = global.Uint8ClampedArray;
  17891. var Uint8ClampedArrayPrototype = Uint8ClampedArray && Uint8ClampedArray.prototype;
  17892. var TypedArray = Int8Array && getPrototypeOf(Int8Array);
  17893. var TypedArrayPrototype =
  17894. Int8ArrayPrototype && getPrototypeOf(Int8ArrayPrototype);
  17895. var ObjectPrototype = Object.prototype;
  17896. var isPrototypeOf = ObjectPrototype.isPrototypeOf;
  17897. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  17898. var TYPED_ARRAY_TAG = uid('TYPED_ARRAY_TAG');
  17899. // Fixing native typed arrays in Opera Presto crashes the browser, see #595
  17900. var NATIVE_ARRAY_BUFFER_VIEWS =
  17901. NATIVE_ARRAY_BUFFER && !!setPrototypeOf && classof(global.opera) !== 'Opera';
  17902. var TYPED_ARRAY_TAG_REQIRED = false;
  17903. var NAME;
  17904. var TypedArrayConstructorsList = {
  17905. Int8Array: 1,
  17906. Uint8Array: 1,
  17907. Uint8ClampedArray: 1,
  17908. Int16Array: 2,
  17909. Uint16Array: 2,
  17910. Int32Array: 4,
  17911. Uint32Array: 4,
  17912. Float32Array: 4,
  17913. Float64Array: 8
  17914. };
  17915. var isView = function isView(it) {
  17916. var klass = classof(it);
  17917. return klass === 'DataView' || has(TypedArrayConstructorsList, klass);
  17918. };
  17919. var isTypedArray = function(it) {
  17920. return isObject(it) && has(TypedArrayConstructorsList, classof(it));
  17921. };
  17922. var aTypedArray = function(it) {
  17923. if (isTypedArray(it)) return it;
  17924. throw TypeError('Target is not a typed array');
  17925. };
  17926. var aTypedArrayConstructor = function(C) {
  17927. if (setPrototypeOf) {
  17928. if (isPrototypeOf.call(TypedArray, C)) return C;
  17929. } else
  17930. for (var ARRAY in TypedArrayConstructorsList)
  17931. if (has(TypedArrayConstructorsList, NAME)) {
  17932. var TypedArrayConstructor = global[ARRAY];
  17933. if (
  17934. TypedArrayConstructor &&
  17935. (C === TypedArrayConstructor ||
  17936. isPrototypeOf.call(TypedArrayConstructor, C))
  17937. ) {
  17938. return C;
  17939. }
  17940. }
  17941. throw TypeError('Target is not a typed array constructor');
  17942. };
  17943. var exportTypedArrayMethod = function(KEY, property, forced) {
  17944. if (!DESCRIPTORS) return;
  17945. if (forced)
  17946. for (var ARRAY in TypedArrayConstructorsList) {
  17947. var TypedArrayConstructor = global[ARRAY];
  17948. if (TypedArrayConstructor && has(TypedArrayConstructor.prototype, KEY)) {
  17949. delete TypedArrayConstructor.prototype[KEY];
  17950. }
  17951. }
  17952. if (!TypedArrayPrototype[KEY] || forced) {
  17953. redefine(
  17954. TypedArrayPrototype,
  17955. KEY,
  17956. forced
  17957. ? property
  17958. : (NATIVE_ARRAY_BUFFER_VIEWS && Int8ArrayPrototype[KEY]) || property
  17959. );
  17960. }
  17961. };
  17962. var exportTypedArrayStaticMethod = function(KEY, property, forced) {
  17963. var ARRAY, TypedArrayConstructor;
  17964. if (!DESCRIPTORS) return;
  17965. if (setPrototypeOf) {
  17966. if (forced)
  17967. for (ARRAY in TypedArrayConstructorsList) {
  17968. TypedArrayConstructor = global[ARRAY];
  17969. if (TypedArrayConstructor && has(TypedArrayConstructor, KEY)) {
  17970. delete TypedArrayConstructor[KEY];
  17971. }
  17972. }
  17973. if (!TypedArray[KEY] || forced) {
  17974. // V8 ~ Chrome 49-50 `%TypedArray%` methods are non-writable non-configurable
  17975. try {
  17976. return redefine(
  17977. TypedArray,
  17978. KEY,
  17979. forced
  17980. ? property
  17981. : (NATIVE_ARRAY_BUFFER_VIEWS && Int8Array[KEY]) || property
  17982. );
  17983. } catch (error) {
  17984. /* empty */
  17985. }
  17986. } else return;
  17987. }
  17988. for (ARRAY in TypedArrayConstructorsList) {
  17989. TypedArrayConstructor = global[ARRAY];
  17990. if (TypedArrayConstructor && (!TypedArrayConstructor[KEY] || forced)) {
  17991. redefine(TypedArrayConstructor, KEY, property);
  17992. }
  17993. }
  17994. };
  17995. for (NAME in TypedArrayConstructorsList) {
  17996. if (!global[NAME]) NATIVE_ARRAY_BUFFER_VIEWS = false;
  17997. }
  17998. // WebKit bug - typed arrays constructors prototype is Object.prototype
  17999. if (
  18000. !NATIVE_ARRAY_BUFFER_VIEWS ||
  18001. typeof TypedArray != 'function' ||
  18002. TypedArray === Function.prototype
  18003. ) {
  18004. // eslint-disable-next-line no-shadow
  18005. TypedArray = function TypedArray() {
  18006. throw TypeError('Incorrect invocation');
  18007. };
  18008. if (NATIVE_ARRAY_BUFFER_VIEWS)
  18009. for (NAME in TypedArrayConstructorsList) {
  18010. if (global[NAME]) setPrototypeOf(global[NAME], TypedArray);
  18011. }
  18012. }
  18013. if (
  18014. !NATIVE_ARRAY_BUFFER_VIEWS ||
  18015. !TypedArrayPrototype ||
  18016. TypedArrayPrototype === ObjectPrototype
  18017. ) {
  18018. TypedArrayPrototype = TypedArray.prototype;
  18019. if (NATIVE_ARRAY_BUFFER_VIEWS)
  18020. for (NAME in TypedArrayConstructorsList) {
  18021. if (global[NAME])
  18022. setPrototypeOf(global[NAME].prototype, TypedArrayPrototype);
  18023. }
  18024. }
  18025. // WebKit bug - one more object in Uint8ClampedArray prototype chain
  18026. if (
  18027. NATIVE_ARRAY_BUFFER_VIEWS &&
  18028. getPrototypeOf(Uint8ClampedArrayPrototype) !== TypedArrayPrototype
  18029. ) {
  18030. setPrototypeOf(Uint8ClampedArrayPrototype, TypedArrayPrototype);
  18031. }
  18032. if (DESCRIPTORS && !has(TypedArrayPrototype, TO_STRING_TAG)) {
  18033. TYPED_ARRAY_TAG_REQIRED = true;
  18034. defineProperty(TypedArrayPrototype, TO_STRING_TAG, {
  18035. get: function() {
  18036. return isObject(this) ? this[TYPED_ARRAY_TAG] : undefined;
  18037. }
  18038. });
  18039. for (NAME in TypedArrayConstructorsList)
  18040. if (global[NAME]) {
  18041. createNonEnumerableProperty(global[NAME], TYPED_ARRAY_TAG, NAME);
  18042. }
  18043. }
  18044. module.exports = {
  18045. NATIVE_ARRAY_BUFFER_VIEWS: NATIVE_ARRAY_BUFFER_VIEWS,
  18046. TYPED_ARRAY_TAG: TYPED_ARRAY_TAG_REQIRED && TYPED_ARRAY_TAG,
  18047. aTypedArray: aTypedArray,
  18048. aTypedArrayConstructor: aTypedArrayConstructor,
  18049. exportTypedArrayMethod: exportTypedArrayMethod,
  18050. exportTypedArrayStaticMethod: exportTypedArrayStaticMethod,
  18051. isView: isView,
  18052. isTypedArray: isTypedArray,
  18053. TypedArray: TypedArray,
  18054. TypedArrayPrototype: TypedArrayPrototype
  18055. };
  18056. },
  18057. {
  18058. '../internals/array-buffer-native': 29,
  18059. '../internals/classof': 47,
  18060. '../internals/create-non-enumerable-property': 55,
  18061. '../internals/descriptors': 60,
  18062. '../internals/global': 76,
  18063. '../internals/has': 77,
  18064. '../internals/is-object': 91,
  18065. '../internals/object-define-property': 109,
  18066. '../internals/object-get-prototype-of': 114,
  18067. '../internals/object-set-prototype-of': 118,
  18068. '../internals/redefine': 125,
  18069. '../internals/uid': 160,
  18070. '../internals/well-known-symbol': 163
  18071. }
  18072. ],
  18073. 31: [
  18074. function(_dereq_, module, exports) {
  18075. 'use strict';
  18076. var global = _dereq_('../internals/global');
  18077. var DESCRIPTORS = _dereq_('../internals/descriptors');
  18078. var NATIVE_ARRAY_BUFFER = _dereq_('../internals/array-buffer-native');
  18079. var createNonEnumerableProperty = _dereq_(
  18080. '../internals/create-non-enumerable-property'
  18081. );
  18082. var redefineAll = _dereq_('../internals/redefine-all');
  18083. var fails = _dereq_('../internals/fails');
  18084. var anInstance = _dereq_('../internals/an-instance');
  18085. var toInteger = _dereq_('../internals/to-integer');
  18086. var toLength = _dereq_('../internals/to-length');
  18087. var toIndex = _dereq_('../internals/to-index');
  18088. var IEEE754 = _dereq_('../internals/ieee754');
  18089. var getPrototypeOf = _dereq_('../internals/object-get-prototype-of');
  18090. var setPrototypeOf = _dereq_('../internals/object-set-prototype-of');
  18091. var getOwnPropertyNames = _dereq_('../internals/object-get-own-property-names').f;
  18092. var defineProperty = _dereq_('../internals/object-define-property').f;
  18093. var arrayFill = _dereq_('../internals/array-fill');
  18094. var setToStringTag = _dereq_('../internals/set-to-string-tag');
  18095. var InternalStateModule = _dereq_('../internals/internal-state');
  18096. var getInternalState = InternalStateModule.get;
  18097. var setInternalState = InternalStateModule.set;
  18098. var ARRAY_BUFFER = 'ArrayBuffer';
  18099. var DATA_VIEW = 'DataView';
  18100. var PROTOTYPE = 'prototype';
  18101. var WRONG_LENGTH = 'Wrong length';
  18102. var WRONG_INDEX = 'Wrong index';
  18103. var NativeArrayBuffer = global[ARRAY_BUFFER];
  18104. var $ArrayBuffer = NativeArrayBuffer;
  18105. var $DataView = global[DATA_VIEW];
  18106. var $DataViewPrototype = $DataView && $DataView[PROTOTYPE];
  18107. var ObjectPrototype = Object.prototype;
  18108. var RangeError = global.RangeError;
  18109. var packIEEE754 = IEEE754.pack;
  18110. var unpackIEEE754 = IEEE754.unpack;
  18111. var packInt8 = function(number) {
  18112. return [number & 0xff];
  18113. };
  18114. var packInt16 = function(number) {
  18115. return [number & 0xff, (number >> 8) & 0xff];
  18116. };
  18117. var packInt32 = function(number) {
  18118. return [
  18119. number & 0xff,
  18120. (number >> 8) & 0xff,
  18121. (number >> 16) & 0xff,
  18122. (number >> 24) & 0xff
  18123. ];
  18124. };
  18125. var unpackInt32 = function(buffer) {
  18126. return (buffer[3] << 24) | (buffer[2] << 16) | (buffer[1] << 8) | buffer[0];
  18127. };
  18128. var packFloat32 = function(number) {
  18129. return packIEEE754(number, 23, 4);
  18130. };
  18131. var packFloat64 = function(number) {
  18132. return packIEEE754(number, 52, 8);
  18133. };
  18134. var addGetter = function(Constructor, key) {
  18135. defineProperty(Constructor[PROTOTYPE], key, {
  18136. get: function() {
  18137. return getInternalState(this)[key];
  18138. }
  18139. });
  18140. };
  18141. var get = function(view, count, index, isLittleEndian) {
  18142. var intIndex = toIndex(index);
  18143. var store = getInternalState(view);
  18144. if (intIndex + count > store.byteLength) throw RangeError(WRONG_INDEX);
  18145. var bytes = getInternalState(store.buffer).bytes;
  18146. var start = intIndex + store.byteOffset;
  18147. var pack = bytes.slice(start, start + count);
  18148. return isLittleEndian ? pack : pack.reverse();
  18149. };
  18150. var set = function(view, count, index, conversion, value, isLittleEndian) {
  18151. var intIndex = toIndex(index);
  18152. var store = getInternalState(view);
  18153. if (intIndex + count > store.byteLength) throw RangeError(WRONG_INDEX);
  18154. var bytes = getInternalState(store.buffer).bytes;
  18155. var start = intIndex + store.byteOffset;
  18156. var pack = conversion(+value);
  18157. for (var i = 0; i < count; i++)
  18158. bytes[start + i] = pack[isLittleEndian ? i : count - i - 1];
  18159. };
  18160. if (!NATIVE_ARRAY_BUFFER) {
  18161. $ArrayBuffer = function ArrayBuffer(length) {
  18162. anInstance(this, $ArrayBuffer, ARRAY_BUFFER);
  18163. var byteLength = toIndex(length);
  18164. setInternalState(this, {
  18165. bytes: arrayFill.call(new Array(byteLength), 0),
  18166. byteLength: byteLength
  18167. });
  18168. if (!DESCRIPTORS) this.byteLength = byteLength;
  18169. };
  18170. $DataView = function DataView(buffer, byteOffset, byteLength) {
  18171. anInstance(this, $DataView, DATA_VIEW);
  18172. anInstance(buffer, $ArrayBuffer, DATA_VIEW);
  18173. var bufferLength = getInternalState(buffer).byteLength;
  18174. var offset = toInteger(byteOffset);
  18175. if (offset < 0 || offset > bufferLength) throw RangeError('Wrong offset');
  18176. byteLength =
  18177. byteLength === undefined ? bufferLength - offset : toLength(byteLength);
  18178. if (offset + byteLength > bufferLength) throw RangeError(WRONG_LENGTH);
  18179. setInternalState(this, {
  18180. buffer: buffer,
  18181. byteLength: byteLength,
  18182. byteOffset: offset
  18183. });
  18184. if (!DESCRIPTORS) {
  18185. this.buffer = buffer;
  18186. this.byteLength = byteLength;
  18187. this.byteOffset = offset;
  18188. }
  18189. };
  18190. if (DESCRIPTORS) {
  18191. addGetter($ArrayBuffer, 'byteLength');
  18192. addGetter($DataView, 'buffer');
  18193. addGetter($DataView, 'byteLength');
  18194. addGetter($DataView, 'byteOffset');
  18195. }
  18196. redefineAll($DataView[PROTOTYPE], {
  18197. getInt8: function getInt8(byteOffset) {
  18198. return (get(this, 1, byteOffset)[0] << 24) >> 24;
  18199. },
  18200. getUint8: function getUint8(byteOffset) {
  18201. return get(this, 1, byteOffset)[0];
  18202. },
  18203. getInt16: function getInt16(byteOffset /* , littleEndian */) {
  18204. var bytes = get(
  18205. this,
  18206. 2,
  18207. byteOffset,
  18208. arguments.length > 1 ? arguments[1] : undefined
  18209. );
  18210. return (((bytes[1] << 8) | bytes[0]) << 16) >> 16;
  18211. },
  18212. getUint16: function getUint16(byteOffset /* , littleEndian */) {
  18213. var bytes = get(
  18214. this,
  18215. 2,
  18216. byteOffset,
  18217. arguments.length > 1 ? arguments[1] : undefined
  18218. );
  18219. return (bytes[1] << 8) | bytes[0];
  18220. },
  18221. getInt32: function getInt32(byteOffset /* , littleEndian */) {
  18222. return unpackInt32(
  18223. get(this, 4, byteOffset, arguments.length > 1 ? arguments[1] : undefined)
  18224. );
  18225. },
  18226. getUint32: function getUint32(byteOffset /* , littleEndian */) {
  18227. return (
  18228. unpackInt32(
  18229. get(
  18230. this,
  18231. 4,
  18232. byteOffset,
  18233. arguments.length > 1 ? arguments[1] : undefined
  18234. )
  18235. ) >>> 0
  18236. );
  18237. },
  18238. getFloat32: function getFloat32(byteOffset /* , littleEndian */) {
  18239. return unpackIEEE754(
  18240. get(this, 4, byteOffset, arguments.length > 1 ? arguments[1] : undefined),
  18241. 23
  18242. );
  18243. },
  18244. getFloat64: function getFloat64(byteOffset /* , littleEndian */) {
  18245. return unpackIEEE754(
  18246. get(this, 8, byteOffset, arguments.length > 1 ? arguments[1] : undefined),
  18247. 52
  18248. );
  18249. },
  18250. setInt8: function setInt8(byteOffset, value) {
  18251. set(this, 1, byteOffset, packInt8, value);
  18252. },
  18253. setUint8: function setUint8(byteOffset, value) {
  18254. set(this, 1, byteOffset, packInt8, value);
  18255. },
  18256. setInt16: function setInt16(byteOffset, value /* , littleEndian */) {
  18257. set(
  18258. this,
  18259. 2,
  18260. byteOffset,
  18261. packInt16,
  18262. value,
  18263. arguments.length > 2 ? arguments[2] : undefined
  18264. );
  18265. },
  18266. setUint16: function setUint16(byteOffset, value /* , littleEndian */) {
  18267. set(
  18268. this,
  18269. 2,
  18270. byteOffset,
  18271. packInt16,
  18272. value,
  18273. arguments.length > 2 ? arguments[2] : undefined
  18274. );
  18275. },
  18276. setInt32: function setInt32(byteOffset, value /* , littleEndian */) {
  18277. set(
  18278. this,
  18279. 4,
  18280. byteOffset,
  18281. packInt32,
  18282. value,
  18283. arguments.length > 2 ? arguments[2] : undefined
  18284. );
  18285. },
  18286. setUint32: function setUint32(byteOffset, value /* , littleEndian */) {
  18287. set(
  18288. this,
  18289. 4,
  18290. byteOffset,
  18291. packInt32,
  18292. value,
  18293. arguments.length > 2 ? arguments[2] : undefined
  18294. );
  18295. },
  18296. setFloat32: function setFloat32(byteOffset, value /* , littleEndian */) {
  18297. set(
  18298. this,
  18299. 4,
  18300. byteOffset,
  18301. packFloat32,
  18302. value,
  18303. arguments.length > 2 ? arguments[2] : undefined
  18304. );
  18305. },
  18306. setFloat64: function setFloat64(byteOffset, value /* , littleEndian */) {
  18307. set(
  18308. this,
  18309. 8,
  18310. byteOffset,
  18311. packFloat64,
  18312. value,
  18313. arguments.length > 2 ? arguments[2] : undefined
  18314. );
  18315. }
  18316. });
  18317. } else {
  18318. if (
  18319. !fails(function() {
  18320. NativeArrayBuffer(1);
  18321. }) ||
  18322. !fails(function() {
  18323. new NativeArrayBuffer(-1); // eslint-disable-line no-new
  18324. }) ||
  18325. fails(function() {
  18326. new NativeArrayBuffer(); // eslint-disable-line no-new
  18327. new NativeArrayBuffer(1.5); // eslint-disable-line no-new
  18328. new NativeArrayBuffer(NaN); // eslint-disable-line no-new
  18329. return NativeArrayBuffer.name != ARRAY_BUFFER;
  18330. })
  18331. ) {
  18332. $ArrayBuffer = function ArrayBuffer(length) {
  18333. anInstance(this, $ArrayBuffer);
  18334. return new NativeArrayBuffer(toIndex(length));
  18335. };
  18336. var ArrayBufferPrototype = ($ArrayBuffer[PROTOTYPE] =
  18337. NativeArrayBuffer[PROTOTYPE]);
  18338. for (
  18339. var keys = getOwnPropertyNames(NativeArrayBuffer), j = 0, key;
  18340. keys.length > j;
  18341. ) {
  18342. if (!((key = keys[j++]) in $ArrayBuffer)) {
  18343. createNonEnumerableProperty($ArrayBuffer, key, NativeArrayBuffer[key]);
  18344. }
  18345. }
  18346. ArrayBufferPrototype.constructor = $ArrayBuffer;
  18347. }
  18348. // WebKit bug - the same parent prototype for typed arrays and data view
  18349. if (setPrototypeOf && getPrototypeOf($DataViewPrototype) !== ObjectPrototype) {
  18350. setPrototypeOf($DataViewPrototype, ObjectPrototype);
  18351. }
  18352. // iOS Safari 7.x bug
  18353. var testView = new $DataView(new $ArrayBuffer(2));
  18354. var nativeSetInt8 = $DataViewPrototype.setInt8;
  18355. testView.setInt8(0, 2147483648);
  18356. testView.setInt8(1, 2147483649);
  18357. if (testView.getInt8(0) || !testView.getInt8(1))
  18358. redefineAll(
  18359. $DataViewPrototype,
  18360. {
  18361. setInt8: function setInt8(byteOffset, value) {
  18362. nativeSetInt8.call(this, byteOffset, (value << 24) >> 24);
  18363. },
  18364. setUint8: function setUint8(byteOffset, value) {
  18365. nativeSetInt8.call(this, byteOffset, (value << 24) >> 24);
  18366. }
  18367. },
  18368. { unsafe: true }
  18369. );
  18370. }
  18371. setToStringTag($ArrayBuffer, ARRAY_BUFFER);
  18372. setToStringTag($DataView, DATA_VIEW);
  18373. module.exports = {
  18374. ArrayBuffer: $ArrayBuffer,
  18375. DataView: $DataView
  18376. };
  18377. },
  18378. {
  18379. '../internals/an-instance': 27,
  18380. '../internals/array-buffer-native': 29,
  18381. '../internals/array-fill': 33,
  18382. '../internals/create-non-enumerable-property': 55,
  18383. '../internals/descriptors': 60,
  18384. '../internals/fails': 68,
  18385. '../internals/global': 76,
  18386. '../internals/ieee754': 82,
  18387. '../internals/internal-state': 87,
  18388. '../internals/object-define-property': 109,
  18389. '../internals/object-get-own-property-names': 112,
  18390. '../internals/object-get-prototype-of': 114,
  18391. '../internals/object-set-prototype-of': 118,
  18392. '../internals/redefine-all': 124,
  18393. '../internals/set-to-string-tag': 134,
  18394. '../internals/to-index': 148,
  18395. '../internals/to-integer': 150,
  18396. '../internals/to-length': 151
  18397. }
  18398. ],
  18399. 32: [
  18400. function(_dereq_, module, exports) {
  18401. 'use strict';
  18402. var toObject = _dereq_('../internals/to-object');
  18403. var toAbsoluteIndex = _dereq_('../internals/to-absolute-index');
  18404. var toLength = _dereq_('../internals/to-length');
  18405. var min = Math.min;
  18406. // `Array.prototype.copyWithin` method implementation
  18407. // https://tc39.github.io/ecma262/#sec-array.prototype.copywithin
  18408. module.exports =
  18409. [].copyWithin ||
  18410. function copyWithin(target /* = 0 */, start /* = 0, end = @length */) {
  18411. var O = toObject(this);
  18412. var len = toLength(O.length);
  18413. var to = toAbsoluteIndex(target, len);
  18414. var from = toAbsoluteIndex(start, len);
  18415. var end = arguments.length > 2 ? arguments[2] : undefined;
  18416. var count = min(
  18417. (end === undefined ? len : toAbsoluteIndex(end, len)) - from,
  18418. len - to
  18419. );
  18420. var inc = 1;
  18421. if (from < to && to < from + count) {
  18422. inc = -1;
  18423. from += count - 1;
  18424. to += count - 1;
  18425. }
  18426. while (count-- > 0) {
  18427. if (from in O) O[to] = O[from];
  18428. else delete O[to];
  18429. to += inc;
  18430. from += inc;
  18431. }
  18432. return O;
  18433. };
  18434. },
  18435. {
  18436. '../internals/to-absolute-index': 147,
  18437. '../internals/to-length': 151,
  18438. '../internals/to-object': 152
  18439. }
  18440. ],
  18441. 33: [
  18442. function(_dereq_, module, exports) {
  18443. 'use strict';
  18444. var toObject = _dereq_('../internals/to-object');
  18445. var toAbsoluteIndex = _dereq_('../internals/to-absolute-index');
  18446. var toLength = _dereq_('../internals/to-length');
  18447. // `Array.prototype.fill` method implementation
  18448. // https://tc39.github.io/ecma262/#sec-array.prototype.fill
  18449. module.exports = function fill(value /* , start = 0, end = @length */) {
  18450. var O = toObject(this);
  18451. var length = toLength(O.length);
  18452. var argumentsLength = arguments.length;
  18453. var index = toAbsoluteIndex(
  18454. argumentsLength > 1 ? arguments[1] : undefined,
  18455. length
  18456. );
  18457. var end = argumentsLength > 2 ? arguments[2] : undefined;
  18458. var endPos = end === undefined ? length : toAbsoluteIndex(end, length);
  18459. while (endPos > index) O[index++] = value;
  18460. return O;
  18461. };
  18462. },
  18463. {
  18464. '../internals/to-absolute-index': 147,
  18465. '../internals/to-length': 151,
  18466. '../internals/to-object': 152
  18467. }
  18468. ],
  18469. 34: [
  18470. function(_dereq_, module, exports) {
  18471. 'use strict';
  18472. var $forEach = _dereq_('../internals/array-iteration').forEach;
  18473. var arrayMethodIsStrict = _dereq_('../internals/array-method-is-strict');
  18474. var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length');
  18475. var STRICT_METHOD = arrayMethodIsStrict('forEach');
  18476. var USES_TO_LENGTH = arrayMethodUsesToLength('forEach');
  18477. // `Array.prototype.forEach` method implementation
  18478. // https://tc39.github.io/ecma262/#sec-array.prototype.foreach
  18479. module.exports =
  18480. !STRICT_METHOD || !USES_TO_LENGTH
  18481. ? function forEach(callbackfn /* , thisArg */) {
  18482. return $forEach(
  18483. this,
  18484. callbackfn,
  18485. arguments.length > 1 ? arguments[1] : undefined
  18486. );
  18487. }
  18488. : [].forEach;
  18489. },
  18490. {
  18491. '../internals/array-iteration': 37,
  18492. '../internals/array-method-is-strict': 40,
  18493. '../internals/array-method-uses-to-length': 41
  18494. }
  18495. ],
  18496. 35: [
  18497. function(_dereq_, module, exports) {
  18498. 'use strict';
  18499. var bind = _dereq_('../internals/function-bind-context');
  18500. var toObject = _dereq_('../internals/to-object');
  18501. var callWithSafeIterationClosing = _dereq_(
  18502. '../internals/call-with-safe-iteration-closing'
  18503. );
  18504. var isArrayIteratorMethod = _dereq_('../internals/is-array-iterator-method');
  18505. var toLength = _dereq_('../internals/to-length');
  18506. var createProperty = _dereq_('../internals/create-property');
  18507. var getIteratorMethod = _dereq_('../internals/get-iterator-method');
  18508. // `Array.from` method implementation
  18509. // https://tc39.github.io/ecma262/#sec-array.from
  18510. module.exports = function from(
  18511. arrayLike /* , mapfn = undefined, thisArg = undefined */
  18512. ) {
  18513. var O = toObject(arrayLike);
  18514. var C = typeof this == 'function' ? this : Array;
  18515. var argumentsLength = arguments.length;
  18516. var mapfn = argumentsLength > 1 ? arguments[1] : undefined;
  18517. var mapping = mapfn !== undefined;
  18518. var iteratorMethod = getIteratorMethod(O);
  18519. var index = 0;
  18520. var length, result, step, iterator, next, value;
  18521. if (mapping)
  18522. mapfn = bind(mapfn, argumentsLength > 2 ? arguments[2] : undefined, 2);
  18523. // if the target is not iterable or it's an array with the default iterator - use a simple case
  18524. if (
  18525. iteratorMethod != undefined &&
  18526. !(C == Array && isArrayIteratorMethod(iteratorMethod))
  18527. ) {
  18528. iterator = iteratorMethod.call(O);
  18529. next = iterator.next;
  18530. result = new C();
  18531. for (; !(step = next.call(iterator)).done; index++) {
  18532. value = mapping
  18533. ? callWithSafeIterationClosing(iterator, mapfn, [step.value, index], true)
  18534. : step.value;
  18535. createProperty(result, index, value);
  18536. }
  18537. } else {
  18538. length = toLength(O.length);
  18539. result = new C(length);
  18540. for (; length > index; index++) {
  18541. value = mapping ? mapfn(O[index], index) : O[index];
  18542. createProperty(result, index, value);
  18543. }
  18544. }
  18545. result.length = index;
  18546. return result;
  18547. };
  18548. },
  18549. {
  18550. '../internals/call-with-safe-iteration-closing': 44,
  18551. '../internals/create-property': 57,
  18552. '../internals/function-bind-context': 71,
  18553. '../internals/get-iterator-method': 74,
  18554. '../internals/is-array-iterator-method': 88,
  18555. '../internals/to-length': 151,
  18556. '../internals/to-object': 152
  18557. }
  18558. ],
  18559. 36: [
  18560. function(_dereq_, module, exports) {
  18561. var toIndexedObject = _dereq_('../internals/to-indexed-object');
  18562. var toLength = _dereq_('../internals/to-length');
  18563. var toAbsoluteIndex = _dereq_('../internals/to-absolute-index');
  18564. // `Array.prototype.{ indexOf, includes }` methods implementation
  18565. var createMethod = function(IS_INCLUDES) {
  18566. return function($this, el, fromIndex) {
  18567. var O = toIndexedObject($this);
  18568. var length = toLength(O.length);
  18569. var index = toAbsoluteIndex(fromIndex, length);
  18570. var value;
  18571. // Array#includes uses SameValueZero equality algorithm
  18572. // eslint-disable-next-line no-self-compare
  18573. if (IS_INCLUDES && el != el)
  18574. while (length > index) {
  18575. value = O[index++];
  18576. // eslint-disable-next-line no-self-compare
  18577. if (value != value) return true;
  18578. // Array#indexOf ignores holes, Array#includes - not
  18579. }
  18580. else
  18581. for (; length > index; index++) {
  18582. if ((IS_INCLUDES || index in O) && O[index] === el)
  18583. return IS_INCLUDES || index || 0;
  18584. }
  18585. return !IS_INCLUDES && -1;
  18586. };
  18587. };
  18588. module.exports = {
  18589. // `Array.prototype.includes` method
  18590. // https://tc39.github.io/ecma262/#sec-array.prototype.includes
  18591. includes: createMethod(true),
  18592. // `Array.prototype.indexOf` method
  18593. // https://tc39.github.io/ecma262/#sec-array.prototype.indexof
  18594. indexOf: createMethod(false)
  18595. };
  18596. },
  18597. {
  18598. '../internals/to-absolute-index': 147,
  18599. '../internals/to-indexed-object': 149,
  18600. '../internals/to-length': 151
  18601. }
  18602. ],
  18603. 37: [
  18604. function(_dereq_, module, exports) {
  18605. var bind = _dereq_('../internals/function-bind-context');
  18606. var IndexedObject = _dereq_('../internals/indexed-object');
  18607. var toObject = _dereq_('../internals/to-object');
  18608. var toLength = _dereq_('../internals/to-length');
  18609. var arraySpeciesCreate = _dereq_('../internals/array-species-create');
  18610. var push = [].push;
  18611. // `Array.prototype.{ forEach, map, filter, some, every, find, findIndex }` methods implementation
  18612. var createMethod = function(TYPE) {
  18613. var IS_MAP = TYPE == 1;
  18614. var IS_FILTER = TYPE == 2;
  18615. var IS_SOME = TYPE == 3;
  18616. var IS_EVERY = TYPE == 4;
  18617. var IS_FIND_INDEX = TYPE == 6;
  18618. var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
  18619. return function($this, callbackfn, that, specificCreate) {
  18620. var O = toObject($this);
  18621. var self = IndexedObject(O);
  18622. var boundFunction = bind(callbackfn, that, 3);
  18623. var length = toLength(self.length);
  18624. var index = 0;
  18625. var create = specificCreate || arraySpeciesCreate;
  18626. var target = IS_MAP
  18627. ? create($this, length)
  18628. : IS_FILTER ? create($this, 0) : undefined;
  18629. var value, result;
  18630. for (; length > index; index++)
  18631. if (NO_HOLES || index in self) {
  18632. value = self[index];
  18633. result = boundFunction(value, index, O);
  18634. if (TYPE) {
  18635. if (IS_MAP) target[index] = result;
  18636. else if (result)
  18637. // map
  18638. switch (TYPE) {
  18639. case 3:
  18640. return true; // some
  18641. case 5:
  18642. return value; // find
  18643. case 6:
  18644. return index; // findIndex
  18645. case 2:
  18646. push.call(target, value); // filter
  18647. }
  18648. else if (IS_EVERY) return false; // every
  18649. }
  18650. }
  18651. return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target;
  18652. };
  18653. };
  18654. module.exports = {
  18655. // `Array.prototype.forEach` method
  18656. // https://tc39.github.io/ecma262/#sec-array.prototype.foreach
  18657. forEach: createMethod(0),
  18658. // `Array.prototype.map` method
  18659. // https://tc39.github.io/ecma262/#sec-array.prototype.map
  18660. map: createMethod(1),
  18661. // `Array.prototype.filter` method
  18662. // https://tc39.github.io/ecma262/#sec-array.prototype.filter
  18663. filter: createMethod(2),
  18664. // `Array.prototype.some` method
  18665. // https://tc39.github.io/ecma262/#sec-array.prototype.some
  18666. some: createMethod(3),
  18667. // `Array.prototype.every` method
  18668. // https://tc39.github.io/ecma262/#sec-array.prototype.every
  18669. every: createMethod(4),
  18670. // `Array.prototype.find` method
  18671. // https://tc39.github.io/ecma262/#sec-array.prototype.find
  18672. find: createMethod(5),
  18673. // `Array.prototype.findIndex` method
  18674. // https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
  18675. findIndex: createMethod(6)
  18676. };
  18677. },
  18678. {
  18679. '../internals/array-species-create': 43,
  18680. '../internals/function-bind-context': 71,
  18681. '../internals/indexed-object': 83,
  18682. '../internals/to-length': 151,
  18683. '../internals/to-object': 152
  18684. }
  18685. ],
  18686. 38: [
  18687. function(_dereq_, module, exports) {
  18688. 'use strict';
  18689. var toIndexedObject = _dereq_('../internals/to-indexed-object');
  18690. var toInteger = _dereq_('../internals/to-integer');
  18691. var toLength = _dereq_('../internals/to-length');
  18692. var arrayMethodIsStrict = _dereq_('../internals/array-method-is-strict');
  18693. var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length');
  18694. var min = Math.min;
  18695. var nativeLastIndexOf = [].lastIndexOf;
  18696. var NEGATIVE_ZERO = !!nativeLastIndexOf && 1 / [1].lastIndexOf(1, -0) < 0;
  18697. var STRICT_METHOD = arrayMethodIsStrict('lastIndexOf');
  18698. // For preventing possible almost infinite loop in non-standard implementations, test the forward version of the method
  18699. var USES_TO_LENGTH = arrayMethodUsesToLength('indexOf', {
  18700. ACCESSORS: true,
  18701. 1: 0
  18702. });
  18703. var FORCED = NEGATIVE_ZERO || !STRICT_METHOD || !USES_TO_LENGTH;
  18704. // `Array.prototype.lastIndexOf` method implementation
  18705. // https://tc39.github.io/ecma262/#sec-array.prototype.lastindexof
  18706. module.exports = FORCED
  18707. ? function lastIndexOf(searchElement /* , fromIndex = @[*-1] */) {
  18708. // convert -0 to +0
  18709. if (NEGATIVE_ZERO) return nativeLastIndexOf.apply(this, arguments) || 0;
  18710. var O = toIndexedObject(this);
  18711. var length = toLength(O.length);
  18712. var index = length - 1;
  18713. if (arguments.length > 1) index = min(index, toInteger(arguments[1]));
  18714. if (index < 0) index = length + index;
  18715. for (; index >= 0; index--)
  18716. if (index in O && O[index] === searchElement) return index || 0;
  18717. return -1;
  18718. }
  18719. : nativeLastIndexOf;
  18720. },
  18721. {
  18722. '../internals/array-method-is-strict': 40,
  18723. '../internals/array-method-uses-to-length': 41,
  18724. '../internals/to-indexed-object': 149,
  18725. '../internals/to-integer': 150,
  18726. '../internals/to-length': 151
  18727. }
  18728. ],
  18729. 39: [
  18730. function(_dereq_, module, exports) {
  18731. var fails = _dereq_('../internals/fails');
  18732. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  18733. var V8_VERSION = _dereq_('../internals/engine-v8-version');
  18734. var SPECIES = wellKnownSymbol('species');
  18735. module.exports = function(METHOD_NAME) {
  18736. // We can't use this feature detection in V8 since it causes
  18737. // deoptimization and serious performance degradation
  18738. // https://github.com/zloirock/core-js/issues/677
  18739. return (
  18740. V8_VERSION >= 51 ||
  18741. !fails(function() {
  18742. var array = [];
  18743. var constructor = (array.constructor = {});
  18744. constructor[SPECIES] = function() {
  18745. return { foo: 1 };
  18746. };
  18747. return array[METHOD_NAME](Boolean).foo !== 1;
  18748. })
  18749. );
  18750. };
  18751. },
  18752. {
  18753. '../internals/engine-v8-version': 65,
  18754. '../internals/fails': 68,
  18755. '../internals/well-known-symbol': 163
  18756. }
  18757. ],
  18758. 40: [
  18759. function(_dereq_, module, exports) {
  18760. 'use strict';
  18761. var fails = _dereq_('../internals/fails');
  18762. module.exports = function(METHOD_NAME, argument) {
  18763. var method = [][METHOD_NAME];
  18764. return (
  18765. !!method &&
  18766. fails(function() {
  18767. // eslint-disable-next-line no-useless-call,no-throw-literal
  18768. method.call(
  18769. null,
  18770. argument ||
  18771. function() {
  18772. throw 1;
  18773. },
  18774. 1
  18775. );
  18776. })
  18777. );
  18778. };
  18779. },
  18780. { '../internals/fails': 68 }
  18781. ],
  18782. 41: [
  18783. function(_dereq_, module, exports) {
  18784. var DESCRIPTORS = _dereq_('../internals/descriptors');
  18785. var fails = _dereq_('../internals/fails');
  18786. var has = _dereq_('../internals/has');
  18787. var defineProperty = Object.defineProperty;
  18788. var cache = {};
  18789. var thrower = function(it) {
  18790. throw it;
  18791. };
  18792. module.exports = function(METHOD_NAME, options) {
  18793. if (has(cache, METHOD_NAME)) return cache[METHOD_NAME];
  18794. if (!options) options = {};
  18795. var method = [][METHOD_NAME];
  18796. var ACCESSORS = has(options, 'ACCESSORS') ? options.ACCESSORS : false;
  18797. var argument0 = has(options, 0) ? options[0] : thrower;
  18798. var argument1 = has(options, 1) ? options[1] : undefined;
  18799. return (cache[METHOD_NAME] =
  18800. !!method &&
  18801. !fails(function() {
  18802. if (ACCESSORS && !DESCRIPTORS) return true;
  18803. var O = { length: -1 };
  18804. if (ACCESSORS) defineProperty(O, 1, { enumerable: true, get: thrower });
  18805. else O[1] = 1;
  18806. method.call(O, argument0, argument1);
  18807. }));
  18808. };
  18809. },
  18810. { '../internals/descriptors': 60, '../internals/fails': 68, '../internals/has': 77 }
  18811. ],
  18812. 42: [
  18813. function(_dereq_, module, exports) {
  18814. var aFunction = _dereq_('../internals/a-function');
  18815. var toObject = _dereq_('../internals/to-object');
  18816. var IndexedObject = _dereq_('../internals/indexed-object');
  18817. var toLength = _dereq_('../internals/to-length');
  18818. // `Array.prototype.{ reduce, reduceRight }` methods implementation
  18819. var createMethod = function(IS_RIGHT) {
  18820. return function(that, callbackfn, argumentsLength, memo) {
  18821. aFunction(callbackfn);
  18822. var O = toObject(that);
  18823. var self = IndexedObject(O);
  18824. var length = toLength(O.length);
  18825. var index = IS_RIGHT ? length - 1 : 0;
  18826. var i = IS_RIGHT ? -1 : 1;
  18827. if (argumentsLength < 2)
  18828. while (true) {
  18829. if (index in self) {
  18830. memo = self[index];
  18831. index += i;
  18832. break;
  18833. }
  18834. index += i;
  18835. if (IS_RIGHT ? index < 0 : length <= index) {
  18836. throw TypeError('Reduce of empty array with no initial value');
  18837. }
  18838. }
  18839. for (; IS_RIGHT ? index >= 0 : length > index; index += i)
  18840. if (index in self) {
  18841. memo = callbackfn(memo, self[index], index, O);
  18842. }
  18843. return memo;
  18844. };
  18845. };
  18846. module.exports = {
  18847. // `Array.prototype.reduce` method
  18848. // https://tc39.github.io/ecma262/#sec-array.prototype.reduce
  18849. left: createMethod(false),
  18850. // `Array.prototype.reduceRight` method
  18851. // https://tc39.github.io/ecma262/#sec-array.prototype.reduceright
  18852. right: createMethod(true)
  18853. };
  18854. },
  18855. {
  18856. '../internals/a-function': 23,
  18857. '../internals/indexed-object': 83,
  18858. '../internals/to-length': 151,
  18859. '../internals/to-object': 152
  18860. }
  18861. ],
  18862. 43: [
  18863. function(_dereq_, module, exports) {
  18864. var isObject = _dereq_('../internals/is-object');
  18865. var isArray = _dereq_('../internals/is-array');
  18866. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  18867. var SPECIES = wellKnownSymbol('species');
  18868. // `ArraySpeciesCreate` abstract operation
  18869. // https://tc39.github.io/ecma262/#sec-arrayspeciescreate
  18870. module.exports = function(originalArray, length) {
  18871. var C;
  18872. if (isArray(originalArray)) {
  18873. C = originalArray.constructor;
  18874. // cross-realm fallback
  18875. if (typeof C == 'function' && (C === Array || isArray(C.prototype)))
  18876. C = undefined;
  18877. else if (isObject(C)) {
  18878. C = C[SPECIES];
  18879. if (C === null) C = undefined;
  18880. }
  18881. }
  18882. return new (C === undefined ? Array : C)(length === 0 ? 0 : length);
  18883. };
  18884. },
  18885. {
  18886. '../internals/is-array': 89,
  18887. '../internals/is-object': 91,
  18888. '../internals/well-known-symbol': 163
  18889. }
  18890. ],
  18891. 44: [
  18892. function(_dereq_, module, exports) {
  18893. var anObject = _dereq_('../internals/an-object');
  18894. // call something on iterator step with safe closing on error
  18895. module.exports = function(iterator, fn, value, ENTRIES) {
  18896. try {
  18897. return ENTRIES ? fn(anObject(value)[0], value[1]) : fn(value);
  18898. // 7.4.6 IteratorClose(iterator, completion)
  18899. } catch (error) {
  18900. var returnMethod = iterator['return'];
  18901. if (returnMethod !== undefined) anObject(returnMethod.call(iterator));
  18902. throw error;
  18903. }
  18904. };
  18905. },
  18906. { '../internals/an-object': 28 }
  18907. ],
  18908. 45: [
  18909. function(_dereq_, module, exports) {
  18910. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  18911. var ITERATOR = wellKnownSymbol('iterator');
  18912. var SAFE_CLOSING = false;
  18913. try {
  18914. var called = 0;
  18915. var iteratorWithReturn = {
  18916. next: function() {
  18917. return { done: !!called++ };
  18918. },
  18919. return: function() {
  18920. SAFE_CLOSING = true;
  18921. }
  18922. };
  18923. iteratorWithReturn[ITERATOR] = function() {
  18924. return this;
  18925. };
  18926. // eslint-disable-next-line no-throw-literal
  18927. Array.from(iteratorWithReturn, function() {
  18928. throw 2;
  18929. });
  18930. } catch (error) {
  18931. /* empty */
  18932. }
  18933. module.exports = function(exec, SKIP_CLOSING) {
  18934. if (!SKIP_CLOSING && !SAFE_CLOSING) return false;
  18935. var ITERATION_SUPPORT = false;
  18936. try {
  18937. var object = {};
  18938. object[ITERATOR] = function() {
  18939. return {
  18940. next: function() {
  18941. return { done: (ITERATION_SUPPORT = true) };
  18942. }
  18943. };
  18944. };
  18945. exec(object);
  18946. } catch (error) {
  18947. /* empty */
  18948. }
  18949. return ITERATION_SUPPORT;
  18950. };
  18951. },
  18952. { '../internals/well-known-symbol': 163 }
  18953. ],
  18954. 46: [
  18955. function(_dereq_, module, exports) {
  18956. var toString = {}.toString;
  18957. module.exports = function(it) {
  18958. return toString.call(it).slice(8, -1);
  18959. };
  18960. },
  18961. {}
  18962. ],
  18963. 47: [
  18964. function(_dereq_, module, exports) {
  18965. var TO_STRING_TAG_SUPPORT = _dereq_('../internals/to-string-tag-support');
  18966. var classofRaw = _dereq_('../internals/classof-raw');
  18967. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  18968. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  18969. // ES3 wrong here
  18970. var CORRECT_ARGUMENTS =
  18971. classofRaw(
  18972. (function() {
  18973. return arguments;
  18974. })()
  18975. ) == 'Arguments';
  18976. // fallback for IE11 Script Access Denied error
  18977. var tryGet = function(it, key) {
  18978. try {
  18979. return it[key];
  18980. } catch (error) {
  18981. /* empty */
  18982. }
  18983. };
  18984. // getting tag from ES6+ `Object.prototype.toString`
  18985. module.exports = TO_STRING_TAG_SUPPORT
  18986. ? classofRaw
  18987. : function(it) {
  18988. var O, tag, result;
  18989. return it === undefined
  18990. ? 'Undefined'
  18991. : it === null
  18992. ? 'Null'
  18993. : // @@toStringTag case
  18994. typeof (tag = tryGet((O = Object(it)), TO_STRING_TAG)) == 'string'
  18995. ? tag
  18996. : // builtinTag case
  18997. CORRECT_ARGUMENTS
  18998. ? classofRaw(O)
  18999. : // ES3 arguments fallback
  19000. (result = classofRaw(O)) == 'Object' &&
  19001. typeof O.callee == 'function'
  19002. ? 'Arguments'
  19003. : result;
  19004. };
  19005. },
  19006. {
  19007. '../internals/classof-raw': 46,
  19008. '../internals/to-string-tag-support': 156,
  19009. '../internals/well-known-symbol': 163
  19010. }
  19011. ],
  19012. 48: [
  19013. function(_dereq_, module, exports) {
  19014. 'use strict';
  19015. var defineProperty = _dereq_('../internals/object-define-property').f;
  19016. var create = _dereq_('../internals/object-create');
  19017. var redefineAll = _dereq_('../internals/redefine-all');
  19018. var bind = _dereq_('../internals/function-bind-context');
  19019. var anInstance = _dereq_('../internals/an-instance');
  19020. var iterate = _dereq_('../internals/iterate');
  19021. var defineIterator = _dereq_('../internals/define-iterator');
  19022. var setSpecies = _dereq_('../internals/set-species');
  19023. var DESCRIPTORS = _dereq_('../internals/descriptors');
  19024. var fastKey = _dereq_('../internals/internal-metadata').fastKey;
  19025. var InternalStateModule = _dereq_('../internals/internal-state');
  19026. var setInternalState = InternalStateModule.set;
  19027. var internalStateGetterFor = InternalStateModule.getterFor;
  19028. module.exports = {
  19029. getConstructor: function(wrapper, CONSTRUCTOR_NAME, IS_MAP, ADDER) {
  19030. var C = wrapper(function(that, iterable) {
  19031. anInstance(that, C, CONSTRUCTOR_NAME);
  19032. setInternalState(that, {
  19033. type: CONSTRUCTOR_NAME,
  19034. index: create(null),
  19035. first: undefined,
  19036. last: undefined,
  19037. size: 0
  19038. });
  19039. if (!DESCRIPTORS) that.size = 0;
  19040. if (iterable != undefined) iterate(iterable, that[ADDER], that, IS_MAP);
  19041. });
  19042. var getInternalState = internalStateGetterFor(CONSTRUCTOR_NAME);
  19043. var define = function(that, key, value) {
  19044. var state = getInternalState(that);
  19045. var entry = getEntry(that, key);
  19046. var previous, index;
  19047. // change existing entry
  19048. if (entry) {
  19049. entry.value = value;
  19050. // create new entry
  19051. } else {
  19052. state.last = entry = {
  19053. index: (index = fastKey(key, true)),
  19054. key: key,
  19055. value: value,
  19056. previous: (previous = state.last),
  19057. next: undefined,
  19058. removed: false
  19059. };
  19060. if (!state.first) state.first = entry;
  19061. if (previous) previous.next = entry;
  19062. if (DESCRIPTORS) state.size++;
  19063. else that.size++;
  19064. // add to index
  19065. if (index !== 'F') state.index[index] = entry;
  19066. }
  19067. return that;
  19068. };
  19069. var getEntry = function(that, key) {
  19070. var state = getInternalState(that);
  19071. // fast case
  19072. var index = fastKey(key);
  19073. var entry;
  19074. if (index !== 'F') return state.index[index];
  19075. // frozen object case
  19076. for (entry = state.first; entry; entry = entry.next) {
  19077. if (entry.key == key) return entry;
  19078. }
  19079. };
  19080. redefineAll(C.prototype, {
  19081. // 23.1.3.1 Map.prototype.clear()
  19082. // 23.2.3.2 Set.prototype.clear()
  19083. clear: function clear() {
  19084. var that = this;
  19085. var state = getInternalState(that);
  19086. var data = state.index;
  19087. var entry = state.first;
  19088. while (entry) {
  19089. entry.removed = true;
  19090. if (entry.previous) entry.previous = entry.previous.next = undefined;
  19091. delete data[entry.index];
  19092. entry = entry.next;
  19093. }
  19094. state.first = state.last = undefined;
  19095. if (DESCRIPTORS) state.size = 0;
  19096. else that.size = 0;
  19097. },
  19098. // 23.1.3.3 Map.prototype.delete(key)
  19099. // 23.2.3.4 Set.prototype.delete(value)
  19100. delete: function(key) {
  19101. var that = this;
  19102. var state = getInternalState(that);
  19103. var entry = getEntry(that, key);
  19104. if (entry) {
  19105. var next = entry.next;
  19106. var prev = entry.previous;
  19107. delete state.index[entry.index];
  19108. entry.removed = true;
  19109. if (prev) prev.next = next;
  19110. if (next) next.previous = prev;
  19111. if (state.first == entry) state.first = next;
  19112. if (state.last == entry) state.last = prev;
  19113. if (DESCRIPTORS) state.size--;
  19114. else that.size--;
  19115. }
  19116. return !!entry;
  19117. },
  19118. // 23.2.3.6 Set.prototype.forEach(callbackfn, thisArg = undefined)
  19119. // 23.1.3.5 Map.prototype.forEach(callbackfn, thisArg = undefined)
  19120. forEach: function forEach(callbackfn /* , that = undefined */) {
  19121. var state = getInternalState(this);
  19122. var boundFunction = bind(
  19123. callbackfn,
  19124. arguments.length > 1 ? arguments[1] : undefined,
  19125. 3
  19126. );
  19127. var entry;
  19128. while ((entry = entry ? entry.next : state.first)) {
  19129. boundFunction(entry.value, entry.key, this);
  19130. // revert to the last existing entry
  19131. while (entry && entry.removed) entry = entry.previous;
  19132. }
  19133. },
  19134. // 23.1.3.7 Map.prototype.has(key)
  19135. // 23.2.3.7 Set.prototype.has(value)
  19136. has: function has(key) {
  19137. return !!getEntry(this, key);
  19138. }
  19139. });
  19140. redefineAll(
  19141. C.prototype,
  19142. IS_MAP
  19143. ? {
  19144. // 23.1.3.6 Map.prototype.get(key)
  19145. get: function get(key) {
  19146. var entry = getEntry(this, key);
  19147. return entry && entry.value;
  19148. },
  19149. // 23.1.3.9 Map.prototype.set(key, value)
  19150. set: function set(key, value) {
  19151. return define(this, key === 0 ? 0 : key, value);
  19152. }
  19153. }
  19154. : {
  19155. // 23.2.3.1 Set.prototype.add(value)
  19156. add: function add(value) {
  19157. return define(this, (value = value === 0 ? 0 : value), value);
  19158. }
  19159. }
  19160. );
  19161. if (DESCRIPTORS)
  19162. defineProperty(C.prototype, 'size', {
  19163. get: function() {
  19164. return getInternalState(this).size;
  19165. }
  19166. });
  19167. return C;
  19168. },
  19169. setStrong: function(C, CONSTRUCTOR_NAME, IS_MAP) {
  19170. var ITERATOR_NAME = CONSTRUCTOR_NAME + ' Iterator';
  19171. var getInternalCollectionState = internalStateGetterFor(CONSTRUCTOR_NAME);
  19172. var getInternalIteratorState = internalStateGetterFor(ITERATOR_NAME);
  19173. // add .keys, .values, .entries, [@@iterator]
  19174. // 23.1.3.4, 23.1.3.8, 23.1.3.11, 23.1.3.12, 23.2.3.5, 23.2.3.8, 23.2.3.10, 23.2.3.11
  19175. defineIterator(
  19176. C,
  19177. CONSTRUCTOR_NAME,
  19178. function(iterated, kind) {
  19179. setInternalState(this, {
  19180. type: ITERATOR_NAME,
  19181. target: iterated,
  19182. state: getInternalCollectionState(iterated),
  19183. kind: kind,
  19184. last: undefined
  19185. });
  19186. },
  19187. function() {
  19188. var state = getInternalIteratorState(this);
  19189. var kind = state.kind;
  19190. var entry = state.last;
  19191. // revert to the last existing entry
  19192. while (entry && entry.removed) entry = entry.previous;
  19193. // get next entry
  19194. if (
  19195. !state.target ||
  19196. !(state.last = entry = entry ? entry.next : state.state.first)
  19197. ) {
  19198. // or finish the iteration
  19199. state.target = undefined;
  19200. return { value: undefined, done: true };
  19201. }
  19202. // return step by kind
  19203. if (kind == 'keys') return { value: entry.key, done: false };
  19204. if (kind == 'values') return { value: entry.value, done: false };
  19205. return { value: [entry.key, entry.value], done: false };
  19206. },
  19207. IS_MAP ? 'entries' : 'values',
  19208. !IS_MAP,
  19209. true
  19210. );
  19211. // add [@@species], 23.1.2.2, 23.2.2.2
  19212. setSpecies(CONSTRUCTOR_NAME);
  19213. }
  19214. };
  19215. },
  19216. {
  19217. '../internals/an-instance': 27,
  19218. '../internals/define-iterator': 58,
  19219. '../internals/descriptors': 60,
  19220. '../internals/function-bind-context': 71,
  19221. '../internals/internal-metadata': 86,
  19222. '../internals/internal-state': 87,
  19223. '../internals/iterate': 94,
  19224. '../internals/object-create': 107,
  19225. '../internals/object-define-property': 109,
  19226. '../internals/redefine-all': 124,
  19227. '../internals/set-species': 133
  19228. }
  19229. ],
  19230. 49: [
  19231. function(_dereq_, module, exports) {
  19232. 'use strict';
  19233. var $ = _dereq_('../internals/export');
  19234. var global = _dereq_('../internals/global');
  19235. var isForced = _dereq_('../internals/is-forced');
  19236. var redefine = _dereq_('../internals/redefine');
  19237. var InternalMetadataModule = _dereq_('../internals/internal-metadata');
  19238. var iterate = _dereq_('../internals/iterate');
  19239. var anInstance = _dereq_('../internals/an-instance');
  19240. var isObject = _dereq_('../internals/is-object');
  19241. var fails = _dereq_('../internals/fails');
  19242. var checkCorrectnessOfIteration = _dereq_(
  19243. '../internals/check-correctness-of-iteration'
  19244. );
  19245. var setToStringTag = _dereq_('../internals/set-to-string-tag');
  19246. var inheritIfRequired = _dereq_('../internals/inherit-if-required');
  19247. module.exports = function(CONSTRUCTOR_NAME, wrapper, common) {
  19248. var IS_MAP = CONSTRUCTOR_NAME.indexOf('Map') !== -1;
  19249. var IS_WEAK = CONSTRUCTOR_NAME.indexOf('Weak') !== -1;
  19250. var ADDER = IS_MAP ? 'set' : 'add';
  19251. var NativeConstructor = global[CONSTRUCTOR_NAME];
  19252. var NativePrototype = NativeConstructor && NativeConstructor.prototype;
  19253. var Constructor = NativeConstructor;
  19254. var exported = {};
  19255. var fixMethod = function(KEY) {
  19256. var nativeMethod = NativePrototype[KEY];
  19257. redefine(
  19258. NativePrototype,
  19259. KEY,
  19260. KEY == 'add'
  19261. ? function add(value) {
  19262. nativeMethod.call(this, value === 0 ? 0 : value);
  19263. return this;
  19264. }
  19265. : KEY == 'delete'
  19266. ? function(key) {
  19267. return IS_WEAK && !isObject(key)
  19268. ? false
  19269. : nativeMethod.call(this, key === 0 ? 0 : key);
  19270. }
  19271. : KEY == 'get'
  19272. ? function get(key) {
  19273. return IS_WEAK && !isObject(key)
  19274. ? undefined
  19275. : nativeMethod.call(this, key === 0 ? 0 : key);
  19276. }
  19277. : KEY == 'has'
  19278. ? function has(key) {
  19279. return IS_WEAK && !isObject(key)
  19280. ? false
  19281. : nativeMethod.call(this, key === 0 ? 0 : key);
  19282. }
  19283. : function set(key, value) {
  19284. nativeMethod.call(this, key === 0 ? 0 : key, value);
  19285. return this;
  19286. }
  19287. );
  19288. };
  19289. // eslint-disable-next-line max-len
  19290. if (
  19291. isForced(
  19292. CONSTRUCTOR_NAME,
  19293. typeof NativeConstructor != 'function' ||
  19294. !(
  19295. IS_WEAK ||
  19296. (NativePrototype.forEach &&
  19297. !fails(function() {
  19298. new NativeConstructor().entries().next();
  19299. }))
  19300. )
  19301. )
  19302. ) {
  19303. // create collection constructor
  19304. Constructor = common.getConstructor(wrapper, CONSTRUCTOR_NAME, IS_MAP, ADDER);
  19305. InternalMetadataModule.REQUIRED = true;
  19306. } else if (isForced(CONSTRUCTOR_NAME, true)) {
  19307. var instance = new Constructor();
  19308. // early implementations not supports chaining
  19309. var HASNT_CHAINING = instance[ADDER](IS_WEAK ? {} : -0, 1) != instance;
  19310. // V8 ~ Chromium 40- weak-collections throws on primitives, but should return false
  19311. var THROWS_ON_PRIMITIVES = fails(function() {
  19312. instance.has(1);
  19313. });
  19314. // most early implementations doesn't supports iterables, most modern - not close it correctly
  19315. // eslint-disable-next-line no-new
  19316. var ACCEPT_ITERABLES = checkCorrectnessOfIteration(function(iterable) {
  19317. new NativeConstructor(iterable);
  19318. });
  19319. // for early implementations -0 and +0 not the same
  19320. var BUGGY_ZERO =
  19321. !IS_WEAK &&
  19322. fails(function() {
  19323. // V8 ~ Chromium 42- fails only with 5+ elements
  19324. var $instance = new NativeConstructor();
  19325. var index = 5;
  19326. while (index--) $instance[ADDER](index, index);
  19327. return !$instance.has(-0);
  19328. });
  19329. if (!ACCEPT_ITERABLES) {
  19330. Constructor = wrapper(function(dummy, iterable) {
  19331. anInstance(dummy, Constructor, CONSTRUCTOR_NAME);
  19332. var that = inheritIfRequired(new NativeConstructor(), dummy, Constructor);
  19333. if (iterable != undefined) iterate(iterable, that[ADDER], that, IS_MAP);
  19334. return that;
  19335. });
  19336. Constructor.prototype = NativePrototype;
  19337. NativePrototype.constructor = Constructor;
  19338. }
  19339. if (THROWS_ON_PRIMITIVES || BUGGY_ZERO) {
  19340. fixMethod('delete');
  19341. fixMethod('has');
  19342. IS_MAP && fixMethod('get');
  19343. }
  19344. if (BUGGY_ZERO || HASNT_CHAINING) fixMethod(ADDER);
  19345. // weak collections should not contains .clear method
  19346. if (IS_WEAK && NativePrototype.clear) delete NativePrototype.clear;
  19347. }
  19348. exported[CONSTRUCTOR_NAME] = Constructor;
  19349. $({ global: true, forced: Constructor != NativeConstructor }, exported);
  19350. setToStringTag(Constructor, CONSTRUCTOR_NAME);
  19351. if (!IS_WEAK) common.setStrong(Constructor, CONSTRUCTOR_NAME, IS_MAP);
  19352. return Constructor;
  19353. };
  19354. },
  19355. {
  19356. '../internals/an-instance': 27,
  19357. '../internals/check-correctness-of-iteration': 45,
  19358. '../internals/export': 67,
  19359. '../internals/fails': 68,
  19360. '../internals/global': 76,
  19361. '../internals/inherit-if-required': 84,
  19362. '../internals/internal-metadata': 86,
  19363. '../internals/is-forced': 90,
  19364. '../internals/is-object': 91,
  19365. '../internals/iterate': 94,
  19366. '../internals/redefine': 125,
  19367. '../internals/set-to-string-tag': 134
  19368. }
  19369. ],
  19370. 50: [
  19371. function(_dereq_, module, exports) {
  19372. var has = _dereq_('../internals/has');
  19373. var ownKeys = _dereq_('../internals/own-keys');
  19374. var getOwnPropertyDescriptorModule = _dereq_(
  19375. '../internals/object-get-own-property-descriptor'
  19376. );
  19377. var definePropertyModule = _dereq_('../internals/object-define-property');
  19378. module.exports = function(target, source) {
  19379. var keys = ownKeys(source);
  19380. var defineProperty = definePropertyModule.f;
  19381. var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  19382. for (var i = 0; i < keys.length; i++) {
  19383. var key = keys[i];
  19384. if (!has(target, key))
  19385. defineProperty(target, key, getOwnPropertyDescriptor(source, key));
  19386. }
  19387. };
  19388. },
  19389. {
  19390. '../internals/has': 77,
  19391. '../internals/object-define-property': 109,
  19392. '../internals/object-get-own-property-descriptor': 110,
  19393. '../internals/own-keys': 120
  19394. }
  19395. ],
  19396. 51: [
  19397. function(_dereq_, module, exports) {
  19398. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  19399. var MATCH = wellKnownSymbol('match');
  19400. module.exports = function(METHOD_NAME) {
  19401. var regexp = /./;
  19402. try {
  19403. '/./'[METHOD_NAME](regexp);
  19404. } catch (e) {
  19405. try {
  19406. regexp[MATCH] = false;
  19407. return '/./'[METHOD_NAME](regexp);
  19408. } catch (f) {
  19409. /* empty */
  19410. }
  19411. }
  19412. return false;
  19413. };
  19414. },
  19415. { '../internals/well-known-symbol': 163 }
  19416. ],
  19417. 52: [
  19418. function(_dereq_, module, exports) {
  19419. var fails = _dereq_('../internals/fails');
  19420. module.exports = !fails(function() {
  19421. function F() {
  19422. /* empty */
  19423. }
  19424. F.prototype.constructor = null;
  19425. return Object.getPrototypeOf(new F()) !== F.prototype;
  19426. });
  19427. },
  19428. { '../internals/fails': 68 }
  19429. ],
  19430. 53: [
  19431. function(_dereq_, module, exports) {
  19432. var requireObjectCoercible = _dereq_('../internals/require-object-coercible');
  19433. var quot = /"/g;
  19434. // B.2.3.2.1 CreateHTML(string, tag, attribute, value)
  19435. // https://tc39.github.io/ecma262/#sec-createhtml
  19436. module.exports = function(string, tag, attribute, value) {
  19437. var S = String(requireObjectCoercible(string));
  19438. var p1 = '<' + tag;
  19439. if (attribute !== '')
  19440. p1 += ' ' + attribute + '="' + String(value).replace(quot, '&quot;') + '"';
  19441. return p1 + '>' + S + '</' + tag + '>';
  19442. };
  19443. },
  19444. { '../internals/require-object-coercible': 130 }
  19445. ],
  19446. 54: [
  19447. function(_dereq_, module, exports) {
  19448. 'use strict';
  19449. var IteratorPrototype = _dereq_('../internals/iterators-core').IteratorPrototype;
  19450. var create = _dereq_('../internals/object-create');
  19451. var createPropertyDescriptor = _dereq_('../internals/create-property-descriptor');
  19452. var setToStringTag = _dereq_('../internals/set-to-string-tag');
  19453. var Iterators = _dereq_('../internals/iterators');
  19454. var returnThis = function() {
  19455. return this;
  19456. };
  19457. module.exports = function(IteratorConstructor, NAME, next) {
  19458. var TO_STRING_TAG = NAME + ' Iterator';
  19459. IteratorConstructor.prototype = create(IteratorPrototype, {
  19460. next: createPropertyDescriptor(1, next)
  19461. });
  19462. setToStringTag(IteratorConstructor, TO_STRING_TAG, false, true);
  19463. Iterators[TO_STRING_TAG] = returnThis;
  19464. return IteratorConstructor;
  19465. };
  19466. },
  19467. {
  19468. '../internals/create-property-descriptor': 56,
  19469. '../internals/iterators': 96,
  19470. '../internals/iterators-core': 95,
  19471. '../internals/object-create': 107,
  19472. '../internals/set-to-string-tag': 134
  19473. }
  19474. ],
  19475. 55: [
  19476. function(_dereq_, module, exports) {
  19477. var DESCRIPTORS = _dereq_('../internals/descriptors');
  19478. var definePropertyModule = _dereq_('../internals/object-define-property');
  19479. var createPropertyDescriptor = _dereq_('../internals/create-property-descriptor');
  19480. module.exports = DESCRIPTORS
  19481. ? function(object, key, value) {
  19482. return definePropertyModule.f(
  19483. object,
  19484. key,
  19485. createPropertyDescriptor(1, value)
  19486. );
  19487. }
  19488. : function(object, key, value) {
  19489. object[key] = value;
  19490. return object;
  19491. };
  19492. },
  19493. {
  19494. '../internals/create-property-descriptor': 56,
  19495. '../internals/descriptors': 60,
  19496. '../internals/object-define-property': 109
  19497. }
  19498. ],
  19499. 56: [
  19500. function(_dereq_, module, exports) {
  19501. module.exports = function(bitmap, value) {
  19502. return {
  19503. enumerable: !(bitmap & 1),
  19504. configurable: !(bitmap & 2),
  19505. writable: !(bitmap & 4),
  19506. value: value
  19507. };
  19508. };
  19509. },
  19510. {}
  19511. ],
  19512. 57: [
  19513. function(_dereq_, module, exports) {
  19514. 'use strict';
  19515. var toPrimitive = _dereq_('../internals/to-primitive');
  19516. var definePropertyModule = _dereq_('../internals/object-define-property');
  19517. var createPropertyDescriptor = _dereq_('../internals/create-property-descriptor');
  19518. module.exports = function(object, key, value) {
  19519. var propertyKey = toPrimitive(key);
  19520. if (propertyKey in object)
  19521. definePropertyModule.f(
  19522. object,
  19523. propertyKey,
  19524. createPropertyDescriptor(0, value)
  19525. );
  19526. else object[propertyKey] = value;
  19527. };
  19528. },
  19529. {
  19530. '../internals/create-property-descriptor': 56,
  19531. '../internals/object-define-property': 109,
  19532. '../internals/to-primitive': 155
  19533. }
  19534. ],
  19535. 58: [
  19536. function(_dereq_, module, exports) {
  19537. 'use strict';
  19538. var $ = _dereq_('../internals/export');
  19539. var createIteratorConstructor = _dereq_(
  19540. '../internals/create-iterator-constructor'
  19541. );
  19542. var getPrototypeOf = _dereq_('../internals/object-get-prototype-of');
  19543. var setPrototypeOf = _dereq_('../internals/object-set-prototype-of');
  19544. var setToStringTag = _dereq_('../internals/set-to-string-tag');
  19545. var createNonEnumerableProperty = _dereq_(
  19546. '../internals/create-non-enumerable-property'
  19547. );
  19548. var redefine = _dereq_('../internals/redefine');
  19549. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  19550. var IS_PURE = _dereq_('../internals/is-pure');
  19551. var Iterators = _dereq_('../internals/iterators');
  19552. var IteratorsCore = _dereq_('../internals/iterators-core');
  19553. var IteratorPrototype = IteratorsCore.IteratorPrototype;
  19554. var BUGGY_SAFARI_ITERATORS = IteratorsCore.BUGGY_SAFARI_ITERATORS;
  19555. var ITERATOR = wellKnownSymbol('iterator');
  19556. var KEYS = 'keys';
  19557. var VALUES = 'values';
  19558. var ENTRIES = 'entries';
  19559. var returnThis = function() {
  19560. return this;
  19561. };
  19562. module.exports = function(
  19563. Iterable,
  19564. NAME,
  19565. IteratorConstructor,
  19566. next,
  19567. DEFAULT,
  19568. IS_SET,
  19569. FORCED
  19570. ) {
  19571. createIteratorConstructor(IteratorConstructor, NAME, next);
  19572. var getIterationMethod = function(KIND) {
  19573. if (KIND === DEFAULT && defaultIterator) return defaultIterator;
  19574. if (!BUGGY_SAFARI_ITERATORS && KIND in IterablePrototype)
  19575. return IterablePrototype[KIND];
  19576. switch (KIND) {
  19577. case KEYS:
  19578. return function keys() {
  19579. return new IteratorConstructor(this, KIND);
  19580. };
  19581. case VALUES:
  19582. return function values() {
  19583. return new IteratorConstructor(this, KIND);
  19584. };
  19585. case ENTRIES:
  19586. return function entries() {
  19587. return new IteratorConstructor(this, KIND);
  19588. };
  19589. }
  19590. return function() {
  19591. return new IteratorConstructor(this);
  19592. };
  19593. };
  19594. var TO_STRING_TAG = NAME + ' Iterator';
  19595. var INCORRECT_VALUES_NAME = false;
  19596. var IterablePrototype = Iterable.prototype;
  19597. var nativeIterator =
  19598. IterablePrototype[ITERATOR] ||
  19599. IterablePrototype['@@iterator'] ||
  19600. (DEFAULT && IterablePrototype[DEFAULT]);
  19601. var defaultIterator =
  19602. (!BUGGY_SAFARI_ITERATORS && nativeIterator) || getIterationMethod(DEFAULT);
  19603. var anyNativeIterator =
  19604. NAME == 'Array'
  19605. ? IterablePrototype.entries || nativeIterator
  19606. : nativeIterator;
  19607. var CurrentIteratorPrototype, methods, KEY;
  19608. // fix native
  19609. if (anyNativeIterator) {
  19610. CurrentIteratorPrototype = getPrototypeOf(
  19611. anyNativeIterator.call(new Iterable())
  19612. );
  19613. if (IteratorPrototype !== Object.prototype && CurrentIteratorPrototype.next) {
  19614. if (
  19615. !IS_PURE &&
  19616. getPrototypeOf(CurrentIteratorPrototype) !== IteratorPrototype
  19617. ) {
  19618. if (setPrototypeOf) {
  19619. setPrototypeOf(CurrentIteratorPrototype, IteratorPrototype);
  19620. } else if (typeof CurrentIteratorPrototype[ITERATOR] != 'function') {
  19621. createNonEnumerableProperty(
  19622. CurrentIteratorPrototype,
  19623. ITERATOR,
  19624. returnThis
  19625. );
  19626. }
  19627. }
  19628. // Set @@toStringTag to native iterators
  19629. setToStringTag(CurrentIteratorPrototype, TO_STRING_TAG, true, true);
  19630. if (IS_PURE) Iterators[TO_STRING_TAG] = returnThis;
  19631. }
  19632. }
  19633. // fix Array#{values, @@iterator}.name in V8 / FF
  19634. if (DEFAULT == VALUES && nativeIterator && nativeIterator.name !== VALUES) {
  19635. INCORRECT_VALUES_NAME = true;
  19636. defaultIterator = function values() {
  19637. return nativeIterator.call(this);
  19638. };
  19639. }
  19640. // define iterator
  19641. if ((!IS_PURE || FORCED) && IterablePrototype[ITERATOR] !== defaultIterator) {
  19642. createNonEnumerableProperty(IterablePrototype, ITERATOR, defaultIterator);
  19643. }
  19644. Iterators[NAME] = defaultIterator;
  19645. // export additional methods
  19646. if (DEFAULT) {
  19647. methods = {
  19648. values: getIterationMethod(VALUES),
  19649. keys: IS_SET ? defaultIterator : getIterationMethod(KEYS),
  19650. entries: getIterationMethod(ENTRIES)
  19651. };
  19652. if (FORCED)
  19653. for (KEY in methods) {
  19654. if (
  19655. BUGGY_SAFARI_ITERATORS ||
  19656. INCORRECT_VALUES_NAME ||
  19657. !(KEY in IterablePrototype)
  19658. ) {
  19659. redefine(IterablePrototype, KEY, methods[KEY]);
  19660. }
  19661. }
  19662. else
  19663. $(
  19664. {
  19665. target: NAME,
  19666. proto: true,
  19667. forced: BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME
  19668. },
  19669. methods
  19670. );
  19671. }
  19672. return methods;
  19673. };
  19674. },
  19675. {
  19676. '../internals/create-iterator-constructor': 54,
  19677. '../internals/create-non-enumerable-property': 55,
  19678. '../internals/export': 67,
  19679. '../internals/is-pure': 92,
  19680. '../internals/iterators': 96,
  19681. '../internals/iterators-core': 95,
  19682. '../internals/object-get-prototype-of': 114,
  19683. '../internals/object-set-prototype-of': 118,
  19684. '../internals/redefine': 125,
  19685. '../internals/set-to-string-tag': 134,
  19686. '../internals/well-known-symbol': 163
  19687. }
  19688. ],
  19689. 59: [
  19690. function(_dereq_, module, exports) {
  19691. var path = _dereq_('../internals/path');
  19692. var has = _dereq_('../internals/has');
  19693. var wrappedWellKnownSymbolModule = _dereq_(
  19694. '../internals/well-known-symbol-wrapped'
  19695. );
  19696. var defineProperty = _dereq_('../internals/object-define-property').f;
  19697. module.exports = function(NAME) {
  19698. var Symbol = path.Symbol || (path.Symbol = {});
  19699. if (!has(Symbol, NAME))
  19700. defineProperty(Symbol, NAME, {
  19701. value: wrappedWellKnownSymbolModule.f(NAME)
  19702. });
  19703. };
  19704. },
  19705. {
  19706. '../internals/has': 77,
  19707. '../internals/object-define-property': 109,
  19708. '../internals/path': 121,
  19709. '../internals/well-known-symbol-wrapped': 162
  19710. }
  19711. ],
  19712. 60: [
  19713. function(_dereq_, module, exports) {
  19714. var fails = _dereq_('../internals/fails');
  19715. // Thank's IE8 for his funny defineProperty
  19716. module.exports = !fails(function() {
  19717. return (
  19718. Object.defineProperty({}, 1, {
  19719. get: function() {
  19720. return 7;
  19721. }
  19722. })[1] != 7
  19723. );
  19724. });
  19725. },
  19726. { '../internals/fails': 68 }
  19727. ],
  19728. 61: [
  19729. function(_dereq_, module, exports) {
  19730. var global = _dereq_('../internals/global');
  19731. var isObject = _dereq_('../internals/is-object');
  19732. var document = global.document;
  19733. // typeof document.createElement is 'object' in old IE
  19734. var EXISTS = isObject(document) && isObject(document.createElement);
  19735. module.exports = function(it) {
  19736. return EXISTS ? document.createElement(it) : {};
  19737. };
  19738. },
  19739. { '../internals/global': 76, '../internals/is-object': 91 }
  19740. ],
  19741. 62: [
  19742. function(_dereq_, module, exports) {
  19743. // iterable DOM collections
  19744. // flag - `iterable` interface - 'entries', 'keys', 'values', 'forEach' methods
  19745. module.exports = {
  19746. CSSRuleList: 0,
  19747. CSSStyleDeclaration: 0,
  19748. CSSValueList: 0,
  19749. ClientRectList: 0,
  19750. DOMRectList: 0,
  19751. DOMStringList: 0,
  19752. DOMTokenList: 1,
  19753. DataTransferItemList: 0,
  19754. FileList: 0,
  19755. HTMLAllCollection: 0,
  19756. HTMLCollection: 0,
  19757. HTMLFormElement: 0,
  19758. HTMLSelectElement: 0,
  19759. MediaList: 0,
  19760. MimeTypeArray: 0,
  19761. NamedNodeMap: 0,
  19762. NodeList: 1,
  19763. PaintRequestList: 0,
  19764. Plugin: 0,
  19765. PluginArray: 0,
  19766. SVGLengthList: 0,
  19767. SVGNumberList: 0,
  19768. SVGPathSegList: 0,
  19769. SVGPointList: 0,
  19770. SVGStringList: 0,
  19771. SVGTransformList: 0,
  19772. SourceBufferList: 0,
  19773. StyleSheetList: 0,
  19774. TextTrackCueList: 0,
  19775. TextTrackList: 0,
  19776. TouchList: 0
  19777. };
  19778. },
  19779. {}
  19780. ],
  19781. 63: [
  19782. function(_dereq_, module, exports) {
  19783. var userAgent = _dereq_('../internals/engine-user-agent');
  19784. module.exports = /(iphone|ipod|ipad).*applewebkit/i.test(userAgent);
  19785. },
  19786. { '../internals/engine-user-agent': 64 }
  19787. ],
  19788. 64: [
  19789. function(_dereq_, module, exports) {
  19790. var getBuiltIn = _dereq_('../internals/get-built-in');
  19791. module.exports = getBuiltIn('navigator', 'userAgent') || '';
  19792. },
  19793. { '../internals/get-built-in': 73 }
  19794. ],
  19795. 65: [
  19796. function(_dereq_, module, exports) {
  19797. var global = _dereq_('../internals/global');
  19798. var userAgent = _dereq_('../internals/engine-user-agent');
  19799. var process = global.process;
  19800. var versions = process && process.versions;
  19801. var v8 = versions && versions.v8;
  19802. var match, version;
  19803. if (v8) {
  19804. match = v8.split('.');
  19805. version = match[0] + match[1];
  19806. } else if (userAgent) {
  19807. match = userAgent.match(/Edge\/(\d+)/);
  19808. if (!match || match[1] >= 74) {
  19809. match = userAgent.match(/Chrome\/(\d+)/);
  19810. if (match) version = match[1];
  19811. }
  19812. }
  19813. module.exports = version && +version;
  19814. },
  19815. { '../internals/engine-user-agent': 64, '../internals/global': 76 }
  19816. ],
  19817. 66: [
  19818. function(_dereq_, module, exports) {
  19819. // IE8- don't enum bug keys
  19820. module.exports = [
  19821. 'constructor',
  19822. 'hasOwnProperty',
  19823. 'isPrototypeOf',
  19824. 'propertyIsEnumerable',
  19825. 'toLocaleString',
  19826. 'toString',
  19827. 'valueOf'
  19828. ];
  19829. },
  19830. {}
  19831. ],
  19832. 67: [
  19833. function(_dereq_, module, exports) {
  19834. var global = _dereq_('../internals/global');
  19835. var getOwnPropertyDescriptor = _dereq_(
  19836. '../internals/object-get-own-property-descriptor'
  19837. ).f;
  19838. var createNonEnumerableProperty = _dereq_(
  19839. '../internals/create-non-enumerable-property'
  19840. );
  19841. var redefine = _dereq_('../internals/redefine');
  19842. var setGlobal = _dereq_('../internals/set-global');
  19843. var copyConstructorProperties = _dereq_(
  19844. '../internals/copy-constructor-properties'
  19845. );
  19846. var isForced = _dereq_('../internals/is-forced');
  19847. /*
  19848. options.target - name of the target object
  19849. options.global - target is the global object
  19850. options.stat - export as static methods of target
  19851. options.proto - export as prototype methods of target
  19852. options.real - real prototype method for the `pure` version
  19853. options.forced - export even if the native feature is available
  19854. options.bind - bind methods to the target, required for the `pure` version
  19855. options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
  19856. options.unsafe - use the simple assignment of property instead of delete + defineProperty
  19857. options.sham - add a flag to not completely full polyfills
  19858. options.enumerable - export as enumerable property
  19859. options.noTargetGet - prevent calling a getter on target
  19860. */
  19861. module.exports = function(options, source) {
  19862. var TARGET = options.target;
  19863. var GLOBAL = options.global;
  19864. var STATIC = options.stat;
  19865. var FORCED, target, key, targetProperty, sourceProperty, descriptor;
  19866. if (GLOBAL) {
  19867. target = global;
  19868. } else if (STATIC) {
  19869. target = global[TARGET] || setGlobal(TARGET, {});
  19870. } else {
  19871. target = (global[TARGET] || {}).prototype;
  19872. }
  19873. if (target)
  19874. for (key in source) {
  19875. sourceProperty = source[key];
  19876. if (options.noTargetGet) {
  19877. descriptor = getOwnPropertyDescriptor(target, key);
  19878. targetProperty = descriptor && descriptor.value;
  19879. } else targetProperty = target[key];
  19880. FORCED = isForced(
  19881. GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key,
  19882. options.forced
  19883. );
  19884. // contained in target
  19885. if (!FORCED && targetProperty !== undefined) {
  19886. if (typeof sourceProperty === typeof targetProperty) continue;
  19887. copyConstructorProperties(sourceProperty, targetProperty);
  19888. }
  19889. // add a flag to not completely full polyfills
  19890. if (options.sham || (targetProperty && targetProperty.sham)) {
  19891. createNonEnumerableProperty(sourceProperty, 'sham', true);
  19892. }
  19893. // extend global
  19894. redefine(target, key, sourceProperty, options);
  19895. }
  19896. };
  19897. },
  19898. {
  19899. '../internals/copy-constructor-properties': 50,
  19900. '../internals/create-non-enumerable-property': 55,
  19901. '../internals/global': 76,
  19902. '../internals/is-forced': 90,
  19903. '../internals/object-get-own-property-descriptor': 110,
  19904. '../internals/redefine': 125,
  19905. '../internals/set-global': 132
  19906. }
  19907. ],
  19908. 68: [
  19909. function(_dereq_, module, exports) {
  19910. module.exports = function(exec) {
  19911. try {
  19912. return !!exec();
  19913. } catch (error) {
  19914. return true;
  19915. }
  19916. };
  19917. },
  19918. {}
  19919. ],
  19920. 69: [
  19921. function(_dereq_, module, exports) {
  19922. 'use strict';
  19923. // TODO: Remove from `core-js@4` since it's moved to entry points
  19924. _dereq_('../modules/es.regexp.exec');
  19925. var redefine = _dereq_('../internals/redefine');
  19926. var fails = _dereq_('../internals/fails');
  19927. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  19928. var regexpExec = _dereq_('../internals/regexp-exec');
  19929. var createNonEnumerableProperty = _dereq_(
  19930. '../internals/create-non-enumerable-property'
  19931. );
  19932. var SPECIES = wellKnownSymbol('species');
  19933. var REPLACE_SUPPORTS_NAMED_GROUPS = !fails(function() {
  19934. // #replace needs built-in support for named groups.
  19935. // #match works fine because it just return the exec results, even if it has
  19936. // a "grops" property.
  19937. var re = /./;
  19938. re.exec = function() {
  19939. var result = [];
  19940. result.groups = { a: '7' };
  19941. return result;
  19942. };
  19943. return ''.replace(re, '$<a>') !== '7';
  19944. });
  19945. // IE <= 11 replaces $0 with the whole match, as if it was $&
  19946. // https://stackoverflow.com/questions/6024666/getting-ie-to-replace-a-regex-with-the-literal-string-0
  19947. var REPLACE_KEEPS_$0 = (function() {
  19948. return 'a'.replace(/./, '$0') === '$0';
  19949. })();
  19950. var REPLACE = wellKnownSymbol('replace');
  19951. // Safari <= 13.0.3(?) substitutes nth capture where n>m with an empty string
  19952. var REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE = (function() {
  19953. if (/./[REPLACE]) {
  19954. return /./[REPLACE]('a', '$0') === '';
  19955. }
  19956. return false;
  19957. })();
  19958. // Chrome 51 has a buggy "split" implementation when RegExp#exec !== nativeExec
  19959. // Weex JS has frozen built-in prototypes, so use try / catch wrapper
  19960. var SPLIT_WORKS_WITH_OVERWRITTEN_EXEC = !fails(function() {
  19961. var re = /(?:)/;
  19962. var originalExec = re.exec;
  19963. re.exec = function() {
  19964. return originalExec.apply(this, arguments);
  19965. };
  19966. var result = 'ab'.split(re);
  19967. return result.length !== 2 || result[0] !== 'a' || result[1] !== 'b';
  19968. });
  19969. module.exports = function(KEY, length, exec, sham) {
  19970. var SYMBOL = wellKnownSymbol(KEY);
  19971. var DELEGATES_TO_SYMBOL = !fails(function() {
  19972. // String methods call symbol-named RegEp methods
  19973. var O = {};
  19974. O[SYMBOL] = function() {
  19975. return 7;
  19976. };
  19977. return ''[KEY](O) != 7;
  19978. });
  19979. var DELEGATES_TO_EXEC =
  19980. DELEGATES_TO_SYMBOL &&
  19981. !fails(function() {
  19982. // Symbol-named RegExp methods call .exec
  19983. var execCalled = false;
  19984. var re = /a/;
  19985. if (KEY === 'split') {
  19986. // We can't use real regex here since it causes deoptimization
  19987. // and serious performance degradation in V8
  19988. // https://github.com/zloirock/core-js/issues/306
  19989. re = {};
  19990. // RegExp[@@split] doesn't call the regex's exec method, but first creates
  19991. // a new one. We need to return the patched regex when creating the new one.
  19992. re.constructor = {};
  19993. re.constructor[SPECIES] = function() {
  19994. return re;
  19995. };
  19996. re.flags = '';
  19997. re[SYMBOL] = /./[SYMBOL];
  19998. }
  19999. re.exec = function() {
  20000. execCalled = true;
  20001. return null;
  20002. };
  20003. re[SYMBOL]('');
  20004. return !execCalled;
  20005. });
  20006. if (
  20007. !DELEGATES_TO_SYMBOL ||
  20008. !DELEGATES_TO_EXEC ||
  20009. (KEY === 'replace' &&
  20010. !(
  20011. REPLACE_SUPPORTS_NAMED_GROUPS &&
  20012. REPLACE_KEEPS_$0 &&
  20013. !REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE
  20014. )) ||
  20015. (KEY === 'split' && !SPLIT_WORKS_WITH_OVERWRITTEN_EXEC)
  20016. ) {
  20017. var nativeRegExpMethod = /./[SYMBOL];
  20018. var methods = exec(
  20019. SYMBOL,
  20020. ''[KEY],
  20021. function(nativeMethod, regexp, str, arg2, forceStringMethod) {
  20022. if (regexp.exec === regexpExec) {
  20023. if (DELEGATES_TO_SYMBOL && !forceStringMethod) {
  20024. // The native String method already delegates to @@method (this
  20025. // polyfilled function), leasing to infinite recursion.
  20026. // We avoid it by directly calling the native @@method method.
  20027. return {
  20028. done: true,
  20029. value: nativeRegExpMethod.call(regexp, str, arg2)
  20030. };
  20031. }
  20032. return { done: true, value: nativeMethod.call(str, regexp, arg2) };
  20033. }
  20034. return { done: false };
  20035. },
  20036. {
  20037. REPLACE_KEEPS_$0: REPLACE_KEEPS_$0,
  20038. REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE: REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE
  20039. }
  20040. );
  20041. var stringMethod = methods[0];
  20042. var regexMethod = methods[1];
  20043. redefine(String.prototype, KEY, stringMethod);
  20044. redefine(
  20045. RegExp.prototype,
  20046. SYMBOL,
  20047. length == 2
  20048. ? // 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue)
  20049. // 21.2.5.11 RegExp.prototype[@@split](string, limit)
  20050. function(string, arg) {
  20051. return regexMethod.call(string, this, arg);
  20052. }
  20053. : // 21.2.5.6 RegExp.prototype[@@match](string)
  20054. // 21.2.5.9 RegExp.prototype[@@search](string)
  20055. function(string) {
  20056. return regexMethod.call(string, this);
  20057. }
  20058. );
  20059. }
  20060. if (sham) createNonEnumerableProperty(RegExp.prototype[SYMBOL], 'sham', true);
  20061. };
  20062. },
  20063. {
  20064. '../internals/create-non-enumerable-property': 55,
  20065. '../internals/fails': 68,
  20066. '../internals/redefine': 125,
  20067. '../internals/regexp-exec': 127,
  20068. '../internals/well-known-symbol': 163,
  20069. '../modules/es.regexp.exec': 196
  20070. }
  20071. ],
  20072. 70: [
  20073. function(_dereq_, module, exports) {
  20074. var fails = _dereq_('../internals/fails');
  20075. module.exports = !fails(function() {
  20076. return Object.isExtensible(Object.preventExtensions({}));
  20077. });
  20078. },
  20079. { '../internals/fails': 68 }
  20080. ],
  20081. 71: [
  20082. function(_dereq_, module, exports) {
  20083. var aFunction = _dereq_('../internals/a-function');
  20084. // optional / simple context binding
  20085. module.exports = function(fn, that, length) {
  20086. aFunction(fn);
  20087. if (that === undefined) return fn;
  20088. switch (length) {
  20089. case 0:
  20090. return function() {
  20091. return fn.call(that);
  20092. };
  20093. case 1:
  20094. return function(a) {
  20095. return fn.call(that, a);
  20096. };
  20097. case 2:
  20098. return function(a, b) {
  20099. return fn.call(that, a, b);
  20100. };
  20101. case 3:
  20102. return function(a, b, c) {
  20103. return fn.call(that, a, b, c);
  20104. };
  20105. }
  20106. return function(/* ...args */) {
  20107. return fn.apply(that, arguments);
  20108. };
  20109. };
  20110. },
  20111. { '../internals/a-function': 23 }
  20112. ],
  20113. 72: [
  20114. function(_dereq_, module, exports) {
  20115. 'use strict';
  20116. var aFunction = _dereq_('../internals/a-function');
  20117. var isObject = _dereq_('../internals/is-object');
  20118. var slice = [].slice;
  20119. var factories = {};
  20120. var construct = function(C, argsLength, args) {
  20121. if (!(argsLength in factories)) {
  20122. for (var list = [], i = 0; i < argsLength; i++) list[i] = 'a[' + i + ']';
  20123. // eslint-disable-next-line no-new-func
  20124. factories[argsLength] = Function(
  20125. 'C,a',
  20126. 'return new C(' + list.join(',') + ')'
  20127. );
  20128. }
  20129. return factories[argsLength](C, args);
  20130. };
  20131. // `Function.prototype.bind` method implementation
  20132. // https://tc39.github.io/ecma262/#sec-function.prototype.bind
  20133. module.exports =
  20134. Function.bind ||
  20135. function bind(that /* , ...args */) {
  20136. var fn = aFunction(this);
  20137. var partArgs = slice.call(arguments, 1);
  20138. var boundFunction = function bound(/* args... */) {
  20139. var args = partArgs.concat(slice.call(arguments));
  20140. return this instanceof boundFunction
  20141. ? construct(fn, args.length, args)
  20142. : fn.apply(that, args);
  20143. };
  20144. if (isObject(fn.prototype)) boundFunction.prototype = fn.prototype;
  20145. return boundFunction;
  20146. };
  20147. },
  20148. { '../internals/a-function': 23, '../internals/is-object': 91 }
  20149. ],
  20150. 73: [
  20151. function(_dereq_, module, exports) {
  20152. var path = _dereq_('../internals/path');
  20153. var global = _dereq_('../internals/global');
  20154. var aFunction = function(variable) {
  20155. return typeof variable == 'function' ? variable : undefined;
  20156. };
  20157. module.exports = function(namespace, method) {
  20158. return arguments.length < 2
  20159. ? aFunction(path[namespace]) || aFunction(global[namespace])
  20160. : (path[namespace] && path[namespace][method]) ||
  20161. (global[namespace] && global[namespace][method]);
  20162. };
  20163. },
  20164. { '../internals/global': 76, '../internals/path': 121 }
  20165. ],
  20166. 74: [
  20167. function(_dereq_, module, exports) {
  20168. var classof = _dereq_('../internals/classof');
  20169. var Iterators = _dereq_('../internals/iterators');
  20170. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  20171. var ITERATOR = wellKnownSymbol('iterator');
  20172. module.exports = function(it) {
  20173. if (it != undefined)
  20174. return it[ITERATOR] || it['@@iterator'] || Iterators[classof(it)];
  20175. };
  20176. },
  20177. {
  20178. '../internals/classof': 47,
  20179. '../internals/iterators': 96,
  20180. '../internals/well-known-symbol': 163
  20181. }
  20182. ],
  20183. 75: [
  20184. function(_dereq_, module, exports) {
  20185. var anObject = _dereq_('../internals/an-object');
  20186. var getIteratorMethod = _dereq_('../internals/get-iterator-method');
  20187. module.exports = function(it) {
  20188. var iteratorMethod = getIteratorMethod(it);
  20189. if (typeof iteratorMethod != 'function') {
  20190. throw TypeError(String(it) + ' is not iterable');
  20191. }
  20192. return anObject(iteratorMethod.call(it));
  20193. };
  20194. },
  20195. { '../internals/an-object': 28, '../internals/get-iterator-method': 74 }
  20196. ],
  20197. 76: [
  20198. function(_dereq_, module, exports) {
  20199. (function(global) {
  20200. var check = function(it) {
  20201. return it && it.Math == Math && it;
  20202. };
  20203. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  20204. module.exports =
  20205. // eslint-disable-next-line no-undef
  20206. check(typeof globalThis == 'object' && globalThis) ||
  20207. check(typeof window == 'object' && window) ||
  20208. check(typeof self == 'object' && self) ||
  20209. check(typeof global == 'object' && global) ||
  20210. // eslint-disable-next-line no-new-func
  20211. Function('return this')();
  20212. }.call(
  20213. this,
  20214. typeof global !== 'undefined'
  20215. ? global
  20216. : typeof self !== 'undefined'
  20217. ? self
  20218. : typeof window !== 'undefined' ? window : {}
  20219. ));
  20220. },
  20221. {}
  20222. ],
  20223. 77: [
  20224. function(_dereq_, module, exports) {
  20225. var hasOwnProperty = {}.hasOwnProperty;
  20226. module.exports = function(it, key) {
  20227. return hasOwnProperty.call(it, key);
  20228. };
  20229. },
  20230. {}
  20231. ],
  20232. 78: [
  20233. function(_dereq_, module, exports) {
  20234. module.exports = {};
  20235. },
  20236. {}
  20237. ],
  20238. 79: [
  20239. function(_dereq_, module, exports) {
  20240. var global = _dereq_('../internals/global');
  20241. module.exports = function(a, b) {
  20242. var console = global.console;
  20243. if (console && console.error) {
  20244. arguments.length === 1 ? console.error(a) : console.error(a, b);
  20245. }
  20246. };
  20247. },
  20248. { '../internals/global': 76 }
  20249. ],
  20250. 80: [
  20251. function(_dereq_, module, exports) {
  20252. var getBuiltIn = _dereq_('../internals/get-built-in');
  20253. module.exports = getBuiltIn('document', 'documentElement');
  20254. },
  20255. { '../internals/get-built-in': 73 }
  20256. ],
  20257. 81: [
  20258. function(_dereq_, module, exports) {
  20259. var DESCRIPTORS = _dereq_('../internals/descriptors');
  20260. var fails = _dereq_('../internals/fails');
  20261. var createElement = _dereq_('../internals/document-create-element');
  20262. // Thank's IE8 for his funny defineProperty
  20263. module.exports =
  20264. !DESCRIPTORS &&
  20265. !fails(function() {
  20266. return (
  20267. Object.defineProperty(createElement('div'), 'a', {
  20268. get: function() {
  20269. return 7;
  20270. }
  20271. }).a != 7
  20272. );
  20273. });
  20274. },
  20275. {
  20276. '../internals/descriptors': 60,
  20277. '../internals/document-create-element': 61,
  20278. '../internals/fails': 68
  20279. }
  20280. ],
  20281. 82: [
  20282. function(_dereq_, module, exports) {
  20283. // IEEE754 conversions based on https://github.com/feross/ieee754
  20284. // eslint-disable-next-line no-shadow-restricted-names
  20285. var Infinity = 1 / 0;
  20286. var abs = Math.abs;
  20287. var pow = Math.pow;
  20288. var floor = Math.floor;
  20289. var log = Math.log;
  20290. var LN2 = Math.LN2;
  20291. var pack = function(number, mantissaLength, bytes) {
  20292. var buffer = new Array(bytes);
  20293. var exponentLength = bytes * 8 - mantissaLength - 1;
  20294. var eMax = (1 << exponentLength) - 1;
  20295. var eBias = eMax >> 1;
  20296. var rt = mantissaLength === 23 ? pow(2, -24) - pow(2, -77) : 0;
  20297. var sign = number < 0 || (number === 0 && 1 / number < 0) ? 1 : 0;
  20298. var index = 0;
  20299. var exponent, mantissa, c;
  20300. number = abs(number);
  20301. // eslint-disable-next-line no-self-compare
  20302. if (number != number || number === Infinity) {
  20303. // eslint-disable-next-line no-self-compare
  20304. mantissa = number != number ? 1 : 0;
  20305. exponent = eMax;
  20306. } else {
  20307. exponent = floor(log(number) / LN2);
  20308. if (number * (c = pow(2, -exponent)) < 1) {
  20309. exponent--;
  20310. c *= 2;
  20311. }
  20312. if (exponent + eBias >= 1) {
  20313. number += rt / c;
  20314. } else {
  20315. number += rt * pow(2, 1 - eBias);
  20316. }
  20317. if (number * c >= 2) {
  20318. exponent++;
  20319. c /= 2;
  20320. }
  20321. if (exponent + eBias >= eMax) {
  20322. mantissa = 0;
  20323. exponent = eMax;
  20324. } else if (exponent + eBias >= 1) {
  20325. mantissa = (number * c - 1) * pow(2, mantissaLength);
  20326. exponent = exponent + eBias;
  20327. } else {
  20328. mantissa = number * pow(2, eBias - 1) * pow(2, mantissaLength);
  20329. exponent = 0;
  20330. }
  20331. }
  20332. for (
  20333. ;
  20334. mantissaLength >= 8;
  20335. buffer[index++] = mantissa & 255, mantissa /= 256, mantissaLength -= 8
  20336. );
  20337. exponent = (exponent << mantissaLength) | mantissa;
  20338. exponentLength += mantissaLength;
  20339. for (
  20340. ;
  20341. exponentLength > 0;
  20342. buffer[index++] = exponent & 255, exponent /= 256, exponentLength -= 8
  20343. );
  20344. buffer[--index] |= sign * 128;
  20345. return buffer;
  20346. };
  20347. var unpack = function(buffer, mantissaLength) {
  20348. var bytes = buffer.length;
  20349. var exponentLength = bytes * 8 - mantissaLength - 1;
  20350. var eMax = (1 << exponentLength) - 1;
  20351. var eBias = eMax >> 1;
  20352. var nBits = exponentLength - 7;
  20353. var index = bytes - 1;
  20354. var sign = buffer[index--];
  20355. var exponent = sign & 127;
  20356. var mantissa;
  20357. sign >>= 7;
  20358. for (
  20359. ;
  20360. nBits > 0;
  20361. exponent = exponent * 256 + buffer[index], index--, nBits -= 8
  20362. );
  20363. mantissa = exponent & ((1 << -nBits) - 1);
  20364. exponent >>= -nBits;
  20365. nBits += mantissaLength;
  20366. for (
  20367. ;
  20368. nBits > 0;
  20369. mantissa = mantissa * 256 + buffer[index], index--, nBits -= 8
  20370. );
  20371. if (exponent === 0) {
  20372. exponent = 1 - eBias;
  20373. } else if (exponent === eMax) {
  20374. return mantissa ? NaN : sign ? -Infinity : Infinity;
  20375. } else {
  20376. mantissa = mantissa + pow(2, mantissaLength);
  20377. exponent = exponent - eBias;
  20378. }
  20379. return (sign ? -1 : 1) * mantissa * pow(2, exponent - mantissaLength);
  20380. };
  20381. module.exports = {
  20382. pack: pack,
  20383. unpack: unpack
  20384. };
  20385. },
  20386. {}
  20387. ],
  20388. 83: [
  20389. function(_dereq_, module, exports) {
  20390. var fails = _dereq_('../internals/fails');
  20391. var classof = _dereq_('../internals/classof-raw');
  20392. var split = ''.split;
  20393. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  20394. module.exports = fails(function() {
  20395. // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
  20396. // eslint-disable-next-line no-prototype-builtins
  20397. return !Object('z').propertyIsEnumerable(0);
  20398. })
  20399. ? function(it) {
  20400. return classof(it) == 'String' ? split.call(it, '') : Object(it);
  20401. }
  20402. : Object;
  20403. },
  20404. { '../internals/classof-raw': 46, '../internals/fails': 68 }
  20405. ],
  20406. 84: [
  20407. function(_dereq_, module, exports) {
  20408. var isObject = _dereq_('../internals/is-object');
  20409. var setPrototypeOf = _dereq_('../internals/object-set-prototype-of');
  20410. // makes subclassing work correct for wrapped built-ins
  20411. module.exports = function($this, dummy, Wrapper) {
  20412. var NewTarget, NewTargetPrototype;
  20413. if (
  20414. // it can work only with native `setPrototypeOf`
  20415. setPrototypeOf &&
  20416. // we haven't completely correct pre-ES6 way for getting `new.target`, so use this
  20417. typeof (NewTarget = dummy.constructor) == 'function' &&
  20418. NewTarget !== Wrapper &&
  20419. isObject((NewTargetPrototype = NewTarget.prototype)) &&
  20420. NewTargetPrototype !== Wrapper.prototype
  20421. )
  20422. setPrototypeOf($this, NewTargetPrototype);
  20423. return $this;
  20424. };
  20425. },
  20426. { '../internals/is-object': 91, '../internals/object-set-prototype-of': 118 }
  20427. ],
  20428. 85: [
  20429. function(_dereq_, module, exports) {
  20430. var store = _dereq_('../internals/shared-store');
  20431. var functionToString = Function.toString;
  20432. // this helper broken in `3.4.1-3.4.4`, so we can't use `shared` helper
  20433. if (typeof store.inspectSource != 'function') {
  20434. store.inspectSource = function(it) {
  20435. return functionToString.call(it);
  20436. };
  20437. }
  20438. module.exports = store.inspectSource;
  20439. },
  20440. { '../internals/shared-store': 136 }
  20441. ],
  20442. 86: [
  20443. function(_dereq_, module, exports) {
  20444. var hiddenKeys = _dereq_('../internals/hidden-keys');
  20445. var isObject = _dereq_('../internals/is-object');
  20446. var has = _dereq_('../internals/has');
  20447. var defineProperty = _dereq_('../internals/object-define-property').f;
  20448. var uid = _dereq_('../internals/uid');
  20449. var FREEZING = _dereq_('../internals/freezing');
  20450. var METADATA = uid('meta');
  20451. var id = 0;
  20452. var isExtensible =
  20453. Object.isExtensible ||
  20454. function() {
  20455. return true;
  20456. };
  20457. var setMetadata = function(it) {
  20458. defineProperty(it, METADATA, {
  20459. value: {
  20460. objectID: 'O' + ++id, // object ID
  20461. weakData: {} // weak collections IDs
  20462. }
  20463. });
  20464. };
  20465. var fastKey = function(it, create) {
  20466. // return a primitive with prefix
  20467. if (!isObject(it))
  20468. return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it;
  20469. if (!has(it, METADATA)) {
  20470. // can't set metadata to uncaught frozen object
  20471. if (!isExtensible(it)) return 'F';
  20472. // not necessary to add metadata
  20473. if (!create) return 'E';
  20474. // add missing metadata
  20475. setMetadata(it);
  20476. // return object ID
  20477. }
  20478. return it[METADATA].objectID;
  20479. };
  20480. var getWeakData = function(it, create) {
  20481. if (!has(it, METADATA)) {
  20482. // can't set metadata to uncaught frozen object
  20483. if (!isExtensible(it)) return true;
  20484. // not necessary to add metadata
  20485. if (!create) return false;
  20486. // add missing metadata
  20487. setMetadata(it);
  20488. // return the store of weak collections IDs
  20489. }
  20490. return it[METADATA].weakData;
  20491. };
  20492. // add metadata on freeze-family methods calling
  20493. var onFreeze = function(it) {
  20494. if (FREEZING && meta.REQUIRED && isExtensible(it) && !has(it, METADATA))
  20495. setMetadata(it);
  20496. return it;
  20497. };
  20498. var meta = (module.exports = {
  20499. REQUIRED: false,
  20500. fastKey: fastKey,
  20501. getWeakData: getWeakData,
  20502. onFreeze: onFreeze
  20503. });
  20504. hiddenKeys[METADATA] = true;
  20505. },
  20506. {
  20507. '../internals/freezing': 70,
  20508. '../internals/has': 77,
  20509. '../internals/hidden-keys': 78,
  20510. '../internals/is-object': 91,
  20511. '../internals/object-define-property': 109,
  20512. '../internals/uid': 160
  20513. }
  20514. ],
  20515. 87: [
  20516. function(_dereq_, module, exports) {
  20517. var NATIVE_WEAK_MAP = _dereq_('../internals/native-weak-map');
  20518. var global = _dereq_('../internals/global');
  20519. var isObject = _dereq_('../internals/is-object');
  20520. var createNonEnumerableProperty = _dereq_(
  20521. '../internals/create-non-enumerable-property'
  20522. );
  20523. var objectHas = _dereq_('../internals/has');
  20524. var sharedKey = _dereq_('../internals/shared-key');
  20525. var hiddenKeys = _dereq_('../internals/hidden-keys');
  20526. var WeakMap = global.WeakMap;
  20527. var set, get, has;
  20528. var enforce = function(it) {
  20529. return has(it) ? get(it) : set(it, {});
  20530. };
  20531. var getterFor = function(TYPE) {
  20532. return function(it) {
  20533. var state;
  20534. if (!isObject(it) || (state = get(it)).type !== TYPE) {
  20535. throw TypeError('Incompatible receiver, ' + TYPE + ' required');
  20536. }
  20537. return state;
  20538. };
  20539. };
  20540. if (NATIVE_WEAK_MAP) {
  20541. var store = new WeakMap();
  20542. var wmget = store.get;
  20543. var wmhas = store.has;
  20544. var wmset = store.set;
  20545. set = function(it, metadata) {
  20546. wmset.call(store, it, metadata);
  20547. return metadata;
  20548. };
  20549. get = function(it) {
  20550. return wmget.call(store, it) || {};
  20551. };
  20552. has = function(it) {
  20553. return wmhas.call(store, it);
  20554. };
  20555. } else {
  20556. var STATE = sharedKey('state');
  20557. hiddenKeys[STATE] = true;
  20558. set = function(it, metadata) {
  20559. createNonEnumerableProperty(it, STATE, metadata);
  20560. return metadata;
  20561. };
  20562. get = function(it) {
  20563. return objectHas(it, STATE) ? it[STATE] : {};
  20564. };
  20565. has = function(it) {
  20566. return objectHas(it, STATE);
  20567. };
  20568. }
  20569. module.exports = {
  20570. set: set,
  20571. get: get,
  20572. has: has,
  20573. enforce: enforce,
  20574. getterFor: getterFor
  20575. };
  20576. },
  20577. {
  20578. '../internals/create-non-enumerable-property': 55,
  20579. '../internals/global': 76,
  20580. '../internals/has': 77,
  20581. '../internals/hidden-keys': 78,
  20582. '../internals/is-object': 91,
  20583. '../internals/native-weak-map': 102,
  20584. '../internals/shared-key': 135
  20585. }
  20586. ],
  20587. 88: [
  20588. function(_dereq_, module, exports) {
  20589. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  20590. var Iterators = _dereq_('../internals/iterators');
  20591. var ITERATOR = wellKnownSymbol('iterator');
  20592. var ArrayPrototype = Array.prototype;
  20593. // check on default Array iterator
  20594. module.exports = function(it) {
  20595. return (
  20596. it !== undefined &&
  20597. (Iterators.Array === it || ArrayPrototype[ITERATOR] === it)
  20598. );
  20599. };
  20600. },
  20601. { '../internals/iterators': 96, '../internals/well-known-symbol': 163 }
  20602. ],
  20603. 89: [
  20604. function(_dereq_, module, exports) {
  20605. var classof = _dereq_('../internals/classof-raw');
  20606. // `IsArray` abstract operation
  20607. // https://tc39.github.io/ecma262/#sec-isarray
  20608. module.exports =
  20609. Array.isArray ||
  20610. function isArray(arg) {
  20611. return classof(arg) == 'Array';
  20612. };
  20613. },
  20614. { '../internals/classof-raw': 46 }
  20615. ],
  20616. 90: [
  20617. function(_dereq_, module, exports) {
  20618. var fails = _dereq_('../internals/fails');
  20619. var replacement = /#|\.prototype\./;
  20620. var isForced = function(feature, detection) {
  20621. var value = data[normalize(feature)];
  20622. return value == POLYFILL
  20623. ? true
  20624. : value == NATIVE
  20625. ? false
  20626. : typeof detection == 'function' ? fails(detection) : !!detection;
  20627. };
  20628. var normalize = (isForced.normalize = function(string) {
  20629. return String(string)
  20630. .replace(replacement, '.')
  20631. .toLowerCase();
  20632. });
  20633. var data = (isForced.data = {});
  20634. var NATIVE = (isForced.NATIVE = 'N');
  20635. var POLYFILL = (isForced.POLYFILL = 'P');
  20636. module.exports = isForced;
  20637. },
  20638. { '../internals/fails': 68 }
  20639. ],
  20640. 91: [
  20641. function(_dereq_, module, exports) {
  20642. module.exports = function(it) {
  20643. return typeof it === 'object' ? it !== null : typeof it === 'function';
  20644. };
  20645. },
  20646. {}
  20647. ],
  20648. 92: [
  20649. function(_dereq_, module, exports) {
  20650. module.exports = false;
  20651. },
  20652. {}
  20653. ],
  20654. 93: [
  20655. function(_dereq_, module, exports) {
  20656. var isObject = _dereq_('../internals/is-object');
  20657. var classof = _dereq_('../internals/classof-raw');
  20658. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  20659. var MATCH = wellKnownSymbol('match');
  20660. // `IsRegExp` abstract operation
  20661. // https://tc39.github.io/ecma262/#sec-isregexp
  20662. module.exports = function(it) {
  20663. var isRegExp;
  20664. return (
  20665. isObject(it) &&
  20666. ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : classof(it) == 'RegExp')
  20667. );
  20668. };
  20669. },
  20670. {
  20671. '../internals/classof-raw': 46,
  20672. '../internals/is-object': 91,
  20673. '../internals/well-known-symbol': 163
  20674. }
  20675. ],
  20676. 94: [
  20677. function(_dereq_, module, exports) {
  20678. var anObject = _dereq_('../internals/an-object');
  20679. var isArrayIteratorMethod = _dereq_('../internals/is-array-iterator-method');
  20680. var toLength = _dereq_('../internals/to-length');
  20681. var bind = _dereq_('../internals/function-bind-context');
  20682. var getIteratorMethod = _dereq_('../internals/get-iterator-method');
  20683. var callWithSafeIterationClosing = _dereq_(
  20684. '../internals/call-with-safe-iteration-closing'
  20685. );
  20686. var Result = function(stopped, result) {
  20687. this.stopped = stopped;
  20688. this.result = result;
  20689. };
  20690. var iterate = (module.exports = function(
  20691. iterable,
  20692. fn,
  20693. that,
  20694. AS_ENTRIES,
  20695. IS_ITERATOR
  20696. ) {
  20697. var boundFunction = bind(fn, that, AS_ENTRIES ? 2 : 1);
  20698. var iterator, iterFn, index, length, result, next, step;
  20699. if (IS_ITERATOR) {
  20700. iterator = iterable;
  20701. } else {
  20702. iterFn = getIteratorMethod(iterable);
  20703. if (typeof iterFn != 'function') throw TypeError('Target is not iterable');
  20704. // optimisation for array iterators
  20705. if (isArrayIteratorMethod(iterFn)) {
  20706. for (
  20707. index = 0, length = toLength(iterable.length);
  20708. length > index;
  20709. index++
  20710. ) {
  20711. result = AS_ENTRIES
  20712. ? boundFunction(anObject((step = iterable[index]))[0], step[1])
  20713. : boundFunction(iterable[index]);
  20714. if (result && result instanceof Result) return result;
  20715. }
  20716. return new Result(false);
  20717. }
  20718. iterator = iterFn.call(iterable);
  20719. }
  20720. next = iterator.next;
  20721. while (!(step = next.call(iterator)).done) {
  20722. result = callWithSafeIterationClosing(
  20723. iterator,
  20724. boundFunction,
  20725. step.value,
  20726. AS_ENTRIES
  20727. );
  20728. if (typeof result == 'object' && result && result instanceof Result)
  20729. return result;
  20730. }
  20731. return new Result(false);
  20732. });
  20733. iterate.stop = function(result) {
  20734. return new Result(true, result);
  20735. };
  20736. },
  20737. {
  20738. '../internals/an-object': 28,
  20739. '../internals/call-with-safe-iteration-closing': 44,
  20740. '../internals/function-bind-context': 71,
  20741. '../internals/get-iterator-method': 74,
  20742. '../internals/is-array-iterator-method': 88,
  20743. '../internals/to-length': 151
  20744. }
  20745. ],
  20746. 95: [
  20747. function(_dereq_, module, exports) {
  20748. 'use strict';
  20749. var getPrototypeOf = _dereq_('../internals/object-get-prototype-of');
  20750. var createNonEnumerableProperty = _dereq_(
  20751. '../internals/create-non-enumerable-property'
  20752. );
  20753. var has = _dereq_('../internals/has');
  20754. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  20755. var IS_PURE = _dereq_('../internals/is-pure');
  20756. var ITERATOR = wellKnownSymbol('iterator');
  20757. var BUGGY_SAFARI_ITERATORS = false;
  20758. var returnThis = function() {
  20759. return this;
  20760. };
  20761. // `%IteratorPrototype%` object
  20762. // https://tc39.github.io/ecma262/#sec-%iteratorprototype%-object
  20763. var IteratorPrototype, PrototypeOfArrayIteratorPrototype, arrayIterator;
  20764. if ([].keys) {
  20765. arrayIterator = [].keys();
  20766. // Safari 8 has buggy iterators w/o `next`
  20767. if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS = true;
  20768. else {
  20769. PrototypeOfArrayIteratorPrototype = getPrototypeOf(
  20770. getPrototypeOf(arrayIterator)
  20771. );
  20772. if (PrototypeOfArrayIteratorPrototype !== Object.prototype)
  20773. IteratorPrototype = PrototypeOfArrayIteratorPrototype;
  20774. }
  20775. }
  20776. if (IteratorPrototype == undefined) IteratorPrototype = {};
  20777. // 25.1.2.1.1 %IteratorPrototype%[@@iterator]()
  20778. if (!IS_PURE && !has(IteratorPrototype, ITERATOR)) {
  20779. createNonEnumerableProperty(IteratorPrototype, ITERATOR, returnThis);
  20780. }
  20781. module.exports = {
  20782. IteratorPrototype: IteratorPrototype,
  20783. BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS
  20784. };
  20785. },
  20786. {
  20787. '../internals/create-non-enumerable-property': 55,
  20788. '../internals/has': 77,
  20789. '../internals/is-pure': 92,
  20790. '../internals/object-get-prototype-of': 114,
  20791. '../internals/well-known-symbol': 163
  20792. }
  20793. ],
  20794. 96: [
  20795. function(_dereq_, module, exports) {
  20796. arguments[4][78][0].apply(exports, arguments);
  20797. },
  20798. { dup: 78 }
  20799. ],
  20800. 97: [
  20801. function(_dereq_, module, exports) {
  20802. // `Math.sign` method implementation
  20803. // https://tc39.github.io/ecma262/#sec-math.sign
  20804. module.exports =
  20805. Math.sign ||
  20806. function sign(x) {
  20807. // eslint-disable-next-line no-self-compare
  20808. return (x = +x) == 0 || x != x ? x : x < 0 ? -1 : 1;
  20809. };
  20810. },
  20811. {}
  20812. ],
  20813. 98: [
  20814. function(_dereq_, module, exports) {
  20815. var global = _dereq_('../internals/global');
  20816. var getOwnPropertyDescriptor = _dereq_(
  20817. '../internals/object-get-own-property-descriptor'
  20818. ).f;
  20819. var classof = _dereq_('../internals/classof-raw');
  20820. var macrotask = _dereq_('../internals/task').set;
  20821. var IS_IOS = _dereq_('../internals/engine-is-ios');
  20822. var MutationObserver = global.MutationObserver || global.WebKitMutationObserver;
  20823. var process = global.process;
  20824. var Promise = global.Promise;
  20825. var IS_NODE = classof(process) == 'process';
  20826. // Node.js 11 shows ExperimentalWarning on getting `queueMicrotask`
  20827. var queueMicrotaskDescriptor = getOwnPropertyDescriptor(global, 'queueMicrotask');
  20828. var queueMicrotask = queueMicrotaskDescriptor && queueMicrotaskDescriptor.value;
  20829. var flush, head, last, notify, toggle, node, promise, then;
  20830. // modern engines have queueMicrotask method
  20831. if (!queueMicrotask) {
  20832. flush = function() {
  20833. var parent, fn;
  20834. if (IS_NODE && (parent = process.domain)) parent.exit();
  20835. while (head) {
  20836. fn = head.fn;
  20837. head = head.next;
  20838. try {
  20839. fn();
  20840. } catch (error) {
  20841. if (head) notify();
  20842. else last = undefined;
  20843. throw error;
  20844. }
  20845. }
  20846. last = undefined;
  20847. if (parent) parent.enter();
  20848. };
  20849. // Node.js
  20850. if (IS_NODE) {
  20851. notify = function() {
  20852. process.nextTick(flush);
  20853. };
  20854. // browsers with MutationObserver, except iOS - https://github.com/zloirock/core-js/issues/339
  20855. } else if (MutationObserver && !IS_IOS) {
  20856. toggle = true;
  20857. node = document.createTextNode('');
  20858. new MutationObserver(flush).observe(node, { characterData: true });
  20859. notify = function() {
  20860. node.data = toggle = !toggle;
  20861. };
  20862. // environments with maybe non-completely correct, but existent Promise
  20863. } else if (Promise && Promise.resolve) {
  20864. // Promise.resolve without an argument throws an error in LG WebOS 2
  20865. promise = Promise.resolve(undefined);
  20866. then = promise.then;
  20867. notify = function() {
  20868. then.call(promise, flush);
  20869. };
  20870. // for other environments - macrotask based on:
  20871. // - setImmediate
  20872. // - MessageChannel
  20873. // - window.postMessag
  20874. // - onreadystatechange
  20875. // - setTimeout
  20876. } else {
  20877. notify = function() {
  20878. // strange IE + webpack dev server bug - use .call(global)
  20879. macrotask.call(global, flush);
  20880. };
  20881. }
  20882. }
  20883. module.exports =
  20884. queueMicrotask ||
  20885. function(fn) {
  20886. var task = { fn: fn, next: undefined };
  20887. if (last) last.next = task;
  20888. if (!head) {
  20889. head = task;
  20890. notify();
  20891. }
  20892. last = task;
  20893. };
  20894. },
  20895. {
  20896. '../internals/classof-raw': 46,
  20897. '../internals/engine-is-ios': 63,
  20898. '../internals/global': 76,
  20899. '../internals/object-get-own-property-descriptor': 110,
  20900. '../internals/task': 145
  20901. }
  20902. ],
  20903. 99: [
  20904. function(_dereq_, module, exports) {
  20905. var global = _dereq_('../internals/global');
  20906. module.exports = global.Promise;
  20907. },
  20908. { '../internals/global': 76 }
  20909. ],
  20910. 100: [
  20911. function(_dereq_, module, exports) {
  20912. var fails = _dereq_('../internals/fails');
  20913. module.exports =
  20914. !!Object.getOwnPropertySymbols &&
  20915. !fails(function() {
  20916. // Chrome 38 Symbol has incorrect toString conversion
  20917. // eslint-disable-next-line no-undef
  20918. return !String(Symbol());
  20919. });
  20920. },
  20921. { '../internals/fails': 68 }
  20922. ],
  20923. 101: [
  20924. function(_dereq_, module, exports) {
  20925. var fails = _dereq_('../internals/fails');
  20926. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  20927. var IS_PURE = _dereq_('../internals/is-pure');
  20928. var ITERATOR = wellKnownSymbol('iterator');
  20929. module.exports = !fails(function() {
  20930. var url = new URL('b?a=1&b=2&c=3', 'http://a');
  20931. var searchParams = url.searchParams;
  20932. var result = '';
  20933. url.pathname = 'c%20d';
  20934. searchParams.forEach(function(value, key) {
  20935. searchParams['delete']('b');
  20936. result += key + value;
  20937. });
  20938. return (
  20939. (IS_PURE && !url.toJSON) ||
  20940. !searchParams.sort ||
  20941. url.href !== 'http://a/c%20d?a=1&c=3' ||
  20942. searchParams.get('c') !== '3' ||
  20943. String(new URLSearchParams('?a=1')) !== 'a=1' ||
  20944. !searchParams[ITERATOR] ||
  20945. // throws in Edge
  20946. new URL('https://a@b').username !== 'a' ||
  20947. new URLSearchParams(new URLSearchParams('a=b')).get('a') !== 'b' ||
  20948. // not punycoded in Edge
  20949. new URL('http://тест').host !== 'xn--e1aybc' ||
  20950. // not escaped in Chrome 62-
  20951. new URL('http://a#б').hash !== '#%D0%B1' ||
  20952. // fails in Chrome 66-
  20953. result !== 'a1c3' ||
  20954. // throws in Safari
  20955. new URL('http://x', undefined).host !== 'x'
  20956. );
  20957. });
  20958. },
  20959. {
  20960. '../internals/fails': 68,
  20961. '../internals/is-pure': 92,
  20962. '../internals/well-known-symbol': 163
  20963. }
  20964. ],
  20965. 102: [
  20966. function(_dereq_, module, exports) {
  20967. var global = _dereq_('../internals/global');
  20968. var inspectSource = _dereq_('../internals/inspect-source');
  20969. var WeakMap = global.WeakMap;
  20970. module.exports =
  20971. typeof WeakMap === 'function' && /native code/.test(inspectSource(WeakMap));
  20972. },
  20973. { '../internals/global': 76, '../internals/inspect-source': 85 }
  20974. ],
  20975. 103: [
  20976. function(_dereq_, module, exports) {
  20977. 'use strict';
  20978. var aFunction = _dereq_('../internals/a-function');
  20979. var PromiseCapability = function(C) {
  20980. var resolve, reject;
  20981. this.promise = new C(function($$resolve, $$reject) {
  20982. if (resolve !== undefined || reject !== undefined)
  20983. throw TypeError('Bad Promise constructor');
  20984. resolve = $$resolve;
  20985. reject = $$reject;
  20986. });
  20987. this.resolve = aFunction(resolve);
  20988. this.reject = aFunction(reject);
  20989. };
  20990. // 25.4.1.5 NewPromiseCapability(C)
  20991. module.exports.f = function(C) {
  20992. return new PromiseCapability(C);
  20993. };
  20994. },
  20995. { '../internals/a-function': 23 }
  20996. ],
  20997. 104: [
  20998. function(_dereq_, module, exports) {
  20999. var isRegExp = _dereq_('../internals/is-regexp');
  21000. module.exports = function(it) {
  21001. if (isRegExp(it)) {
  21002. throw TypeError("The method doesn't accept regular expressions");
  21003. }
  21004. return it;
  21005. };
  21006. },
  21007. { '../internals/is-regexp': 93 }
  21008. ],
  21009. 105: [
  21010. function(_dereq_, module, exports) {
  21011. var global = _dereq_('../internals/global');
  21012. var globalIsFinite = global.isFinite;
  21013. // `Number.isFinite` method
  21014. // https://tc39.github.io/ecma262/#sec-number.isfinite
  21015. module.exports =
  21016. Number.isFinite ||
  21017. function isFinite(it) {
  21018. return typeof it == 'number' && globalIsFinite(it);
  21019. };
  21020. },
  21021. { '../internals/global': 76 }
  21022. ],
  21023. 106: [
  21024. function(_dereq_, module, exports) {
  21025. 'use strict';
  21026. var DESCRIPTORS = _dereq_('../internals/descriptors');
  21027. var fails = _dereq_('../internals/fails');
  21028. var objectKeys = _dereq_('../internals/object-keys');
  21029. var getOwnPropertySymbolsModule = _dereq_(
  21030. '../internals/object-get-own-property-symbols'
  21031. );
  21032. var propertyIsEnumerableModule = _dereq_(
  21033. '../internals/object-property-is-enumerable'
  21034. );
  21035. var toObject = _dereq_('../internals/to-object');
  21036. var IndexedObject = _dereq_('../internals/indexed-object');
  21037. var nativeAssign = Object.assign;
  21038. var defineProperty = Object.defineProperty;
  21039. // `Object.assign` method
  21040. // https://tc39.github.io/ecma262/#sec-object.assign
  21041. module.exports =
  21042. !nativeAssign ||
  21043. fails(function() {
  21044. // should have correct order of operations (Edge bug)
  21045. if (
  21046. DESCRIPTORS &&
  21047. nativeAssign(
  21048. { b: 1 },
  21049. nativeAssign(
  21050. defineProperty({}, 'a', {
  21051. enumerable: true,
  21052. get: function() {
  21053. defineProperty(this, 'b', {
  21054. value: 3,
  21055. enumerable: false
  21056. });
  21057. }
  21058. }),
  21059. { b: 2 }
  21060. )
  21061. ).b !== 1
  21062. )
  21063. return true;
  21064. // should work with symbols and should have deterministic property order (V8 bug)
  21065. var A = {};
  21066. var B = {};
  21067. // eslint-disable-next-line no-undef
  21068. var symbol = Symbol();
  21069. var alphabet = 'abcdefghijklmnopqrst';
  21070. A[symbol] = 7;
  21071. alphabet.split('').forEach(function(chr) {
  21072. B[chr] = chr;
  21073. });
  21074. return (
  21075. nativeAssign({}, A)[symbol] != 7 ||
  21076. objectKeys(nativeAssign({}, B)).join('') != alphabet
  21077. );
  21078. })
  21079. ? function assign(target, source) {
  21080. // eslint-disable-line no-unused-vars
  21081. var T = toObject(target);
  21082. var argumentsLength = arguments.length;
  21083. var index = 1;
  21084. var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
  21085. var propertyIsEnumerable = propertyIsEnumerableModule.f;
  21086. while (argumentsLength > index) {
  21087. var S = IndexedObject(arguments[index++]);
  21088. var keys = getOwnPropertySymbols
  21089. ? objectKeys(S).concat(getOwnPropertySymbols(S))
  21090. : objectKeys(S);
  21091. var length = keys.length;
  21092. var j = 0;
  21093. var key;
  21094. while (length > j) {
  21095. key = keys[j++];
  21096. if (!DESCRIPTORS || propertyIsEnumerable.call(S, key))
  21097. T[key] = S[key];
  21098. }
  21099. }
  21100. return T;
  21101. }
  21102. : nativeAssign;
  21103. },
  21104. {
  21105. '../internals/descriptors': 60,
  21106. '../internals/fails': 68,
  21107. '../internals/indexed-object': 83,
  21108. '../internals/object-get-own-property-symbols': 113,
  21109. '../internals/object-keys': 116,
  21110. '../internals/object-property-is-enumerable': 117,
  21111. '../internals/to-object': 152
  21112. }
  21113. ],
  21114. 107: [
  21115. function(_dereq_, module, exports) {
  21116. var anObject = _dereq_('../internals/an-object');
  21117. var defineProperties = _dereq_('../internals/object-define-properties');
  21118. var enumBugKeys = _dereq_('../internals/enum-bug-keys');
  21119. var hiddenKeys = _dereq_('../internals/hidden-keys');
  21120. var html = _dereq_('../internals/html');
  21121. var documentCreateElement = _dereq_('../internals/document-create-element');
  21122. var sharedKey = _dereq_('../internals/shared-key');
  21123. var GT = '>';
  21124. var LT = '<';
  21125. var PROTOTYPE = 'prototype';
  21126. var SCRIPT = 'script';
  21127. var IE_PROTO = sharedKey('IE_PROTO');
  21128. var EmptyConstructor = function() {
  21129. /* empty */
  21130. };
  21131. var scriptTag = function(content) {
  21132. return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
  21133. };
  21134. // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
  21135. var NullProtoObjectViaActiveX = function(activeXDocument) {
  21136. activeXDocument.write(scriptTag(''));
  21137. activeXDocument.close();
  21138. var temp = activeXDocument.parentWindow.Object;
  21139. activeXDocument = null; // avoid memory leak
  21140. return temp;
  21141. };
  21142. // Create object with fake `null` prototype: use iframe Object with cleared prototype
  21143. var NullProtoObjectViaIFrame = function() {
  21144. // Thrash, waste and sodomy: IE GC bug
  21145. var iframe = documentCreateElement('iframe');
  21146. var JS = 'java' + SCRIPT + ':';
  21147. var iframeDocument;
  21148. iframe.style.display = 'none';
  21149. html.appendChild(iframe);
  21150. // https://github.com/zloirock/core-js/issues/475
  21151. iframe.src = String(JS);
  21152. iframeDocument = iframe.contentWindow.document;
  21153. iframeDocument.open();
  21154. iframeDocument.write(scriptTag('document.F=Object'));
  21155. iframeDocument.close();
  21156. return iframeDocument.F;
  21157. };
  21158. // Check for document.domain and active x support
  21159. // No need to use active x approach when document.domain is not set
  21160. // see https://github.com/es-shims/es5-shim/issues/150
  21161. // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
  21162. // avoid IE GC bug
  21163. var activeXDocument;
  21164. var NullProtoObject = function() {
  21165. try {
  21166. /* global ActiveXObject */
  21167. activeXDocument = document.domain && new ActiveXObject('htmlfile');
  21168. } catch (error) {
  21169. /* ignore */
  21170. }
  21171. NullProtoObject = activeXDocument
  21172. ? NullProtoObjectViaActiveX(activeXDocument)
  21173. : NullProtoObjectViaIFrame();
  21174. var length = enumBugKeys.length;
  21175. while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
  21176. return NullProtoObject();
  21177. };
  21178. hiddenKeys[IE_PROTO] = true;
  21179. // `Object.create` method
  21180. // https://tc39.github.io/ecma262/#sec-object.create
  21181. module.exports =
  21182. Object.create ||
  21183. function create(O, Properties) {
  21184. var result;
  21185. if (O !== null) {
  21186. EmptyConstructor[PROTOTYPE] = anObject(O);
  21187. result = new EmptyConstructor();
  21188. EmptyConstructor[PROTOTYPE] = null;
  21189. // add "__proto__" for Object.getPrototypeOf polyfill
  21190. result[IE_PROTO] = O;
  21191. } else result = NullProtoObject();
  21192. return Properties === undefined
  21193. ? result
  21194. : defineProperties(result, Properties);
  21195. };
  21196. },
  21197. {
  21198. '../internals/an-object': 28,
  21199. '../internals/document-create-element': 61,
  21200. '../internals/enum-bug-keys': 66,
  21201. '../internals/hidden-keys': 78,
  21202. '../internals/html': 80,
  21203. '../internals/object-define-properties': 108,
  21204. '../internals/shared-key': 135
  21205. }
  21206. ],
  21207. 108: [
  21208. function(_dereq_, module, exports) {
  21209. var DESCRIPTORS = _dereq_('../internals/descriptors');
  21210. var definePropertyModule = _dereq_('../internals/object-define-property');
  21211. var anObject = _dereq_('../internals/an-object');
  21212. var objectKeys = _dereq_('../internals/object-keys');
  21213. // `Object.defineProperties` method
  21214. // https://tc39.github.io/ecma262/#sec-object.defineproperties
  21215. module.exports = DESCRIPTORS
  21216. ? Object.defineProperties
  21217. : function defineProperties(O, Properties) {
  21218. anObject(O);
  21219. var keys = objectKeys(Properties);
  21220. var length = keys.length;
  21221. var index = 0;
  21222. var key;
  21223. while (length > index)
  21224. definePropertyModule.f(O, (key = keys[index++]), Properties[key]);
  21225. return O;
  21226. };
  21227. },
  21228. {
  21229. '../internals/an-object': 28,
  21230. '../internals/descriptors': 60,
  21231. '../internals/object-define-property': 109,
  21232. '../internals/object-keys': 116
  21233. }
  21234. ],
  21235. 109: [
  21236. function(_dereq_, module, exports) {
  21237. var DESCRIPTORS = _dereq_('../internals/descriptors');
  21238. var IE8_DOM_DEFINE = _dereq_('../internals/ie8-dom-define');
  21239. var anObject = _dereq_('../internals/an-object');
  21240. var toPrimitive = _dereq_('../internals/to-primitive');
  21241. var nativeDefineProperty = Object.defineProperty;
  21242. // `Object.defineProperty` method
  21243. // https://tc39.github.io/ecma262/#sec-object.defineproperty
  21244. exports.f = DESCRIPTORS
  21245. ? nativeDefineProperty
  21246. : function defineProperty(O, P, Attributes) {
  21247. anObject(O);
  21248. P = toPrimitive(P, true);
  21249. anObject(Attributes);
  21250. if (IE8_DOM_DEFINE)
  21251. try {
  21252. return nativeDefineProperty(O, P, Attributes);
  21253. } catch (error) {
  21254. /* empty */
  21255. }
  21256. if ('get' in Attributes || 'set' in Attributes)
  21257. throw TypeError('Accessors not supported');
  21258. if ('value' in Attributes) O[P] = Attributes.value;
  21259. return O;
  21260. };
  21261. },
  21262. {
  21263. '../internals/an-object': 28,
  21264. '../internals/descriptors': 60,
  21265. '../internals/ie8-dom-define': 81,
  21266. '../internals/to-primitive': 155
  21267. }
  21268. ],
  21269. 110: [
  21270. function(_dereq_, module, exports) {
  21271. var DESCRIPTORS = _dereq_('../internals/descriptors');
  21272. var propertyIsEnumerableModule = _dereq_(
  21273. '../internals/object-property-is-enumerable'
  21274. );
  21275. var createPropertyDescriptor = _dereq_('../internals/create-property-descriptor');
  21276. var toIndexedObject = _dereq_('../internals/to-indexed-object');
  21277. var toPrimitive = _dereq_('../internals/to-primitive');
  21278. var has = _dereq_('../internals/has');
  21279. var IE8_DOM_DEFINE = _dereq_('../internals/ie8-dom-define');
  21280. var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  21281. // `Object.getOwnPropertyDescriptor` method
  21282. // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor
  21283. exports.f = DESCRIPTORS
  21284. ? nativeGetOwnPropertyDescriptor
  21285. : function getOwnPropertyDescriptor(O, P) {
  21286. O = toIndexedObject(O);
  21287. P = toPrimitive(P, true);
  21288. if (IE8_DOM_DEFINE)
  21289. try {
  21290. return nativeGetOwnPropertyDescriptor(O, P);
  21291. } catch (error) {
  21292. /* empty */
  21293. }
  21294. if (has(O, P))
  21295. return createPropertyDescriptor(
  21296. !propertyIsEnumerableModule.f.call(O, P),
  21297. O[P]
  21298. );
  21299. };
  21300. },
  21301. {
  21302. '../internals/create-property-descriptor': 56,
  21303. '../internals/descriptors': 60,
  21304. '../internals/has': 77,
  21305. '../internals/ie8-dom-define': 81,
  21306. '../internals/object-property-is-enumerable': 117,
  21307. '../internals/to-indexed-object': 149,
  21308. '../internals/to-primitive': 155
  21309. }
  21310. ],
  21311. 111: [
  21312. function(_dereq_, module, exports) {
  21313. var toIndexedObject = _dereq_('../internals/to-indexed-object');
  21314. var nativeGetOwnPropertyNames = _dereq_(
  21315. '../internals/object-get-own-property-names'
  21316. ).f;
  21317. var toString = {}.toString;
  21318. var windowNames =
  21319. typeof window == 'object' && window && Object.getOwnPropertyNames
  21320. ? Object.getOwnPropertyNames(window)
  21321. : [];
  21322. var getWindowNames = function(it) {
  21323. try {
  21324. return nativeGetOwnPropertyNames(it);
  21325. } catch (error) {
  21326. return windowNames.slice();
  21327. }
  21328. };
  21329. // fallback for IE11 buggy Object.getOwnPropertyNames with iframe and window
  21330. module.exports.f = function getOwnPropertyNames(it) {
  21331. return windowNames && toString.call(it) == '[object Window]'
  21332. ? getWindowNames(it)
  21333. : nativeGetOwnPropertyNames(toIndexedObject(it));
  21334. };
  21335. },
  21336. {
  21337. '../internals/object-get-own-property-names': 112,
  21338. '../internals/to-indexed-object': 149
  21339. }
  21340. ],
  21341. 112: [
  21342. function(_dereq_, module, exports) {
  21343. var internalObjectKeys = _dereq_('../internals/object-keys-internal');
  21344. var enumBugKeys = _dereq_('../internals/enum-bug-keys');
  21345. var hiddenKeys = enumBugKeys.concat('length', 'prototype');
  21346. // `Object.getOwnPropertyNames` method
  21347. // https://tc39.github.io/ecma262/#sec-object.getownpropertynames
  21348. exports.f =
  21349. Object.getOwnPropertyNames ||
  21350. function getOwnPropertyNames(O) {
  21351. return internalObjectKeys(O, hiddenKeys);
  21352. };
  21353. },
  21354. { '../internals/enum-bug-keys': 66, '../internals/object-keys-internal': 115 }
  21355. ],
  21356. 113: [
  21357. function(_dereq_, module, exports) {
  21358. exports.f = Object.getOwnPropertySymbols;
  21359. },
  21360. {}
  21361. ],
  21362. 114: [
  21363. function(_dereq_, module, exports) {
  21364. var has = _dereq_('../internals/has');
  21365. var toObject = _dereq_('../internals/to-object');
  21366. var sharedKey = _dereq_('../internals/shared-key');
  21367. var CORRECT_PROTOTYPE_GETTER = _dereq_('../internals/correct-prototype-getter');
  21368. var IE_PROTO = sharedKey('IE_PROTO');
  21369. var ObjectPrototype = Object.prototype;
  21370. // `Object.getPrototypeOf` method
  21371. // https://tc39.github.io/ecma262/#sec-object.getprototypeof
  21372. module.exports = CORRECT_PROTOTYPE_GETTER
  21373. ? Object.getPrototypeOf
  21374. : function(O) {
  21375. O = toObject(O);
  21376. if (has(O, IE_PROTO)) return O[IE_PROTO];
  21377. if (typeof O.constructor == 'function' && O instanceof O.constructor) {
  21378. return O.constructor.prototype;
  21379. }
  21380. return O instanceof Object ? ObjectPrototype : null;
  21381. };
  21382. },
  21383. {
  21384. '../internals/correct-prototype-getter': 52,
  21385. '../internals/has': 77,
  21386. '../internals/shared-key': 135,
  21387. '../internals/to-object': 152
  21388. }
  21389. ],
  21390. 115: [
  21391. function(_dereq_, module, exports) {
  21392. var has = _dereq_('../internals/has');
  21393. var toIndexedObject = _dereq_('../internals/to-indexed-object');
  21394. var indexOf = _dereq_('../internals/array-includes').indexOf;
  21395. var hiddenKeys = _dereq_('../internals/hidden-keys');
  21396. module.exports = function(object, names) {
  21397. var O = toIndexedObject(object);
  21398. var i = 0;
  21399. var result = [];
  21400. var key;
  21401. for (key in O) !has(hiddenKeys, key) && has(O, key) && result.push(key);
  21402. // Don't enum bug & hidden keys
  21403. while (names.length > i)
  21404. if (has(O, (key = names[i++]))) {
  21405. ~indexOf(result, key) || result.push(key);
  21406. }
  21407. return result;
  21408. };
  21409. },
  21410. {
  21411. '../internals/array-includes': 36,
  21412. '../internals/has': 77,
  21413. '../internals/hidden-keys': 78,
  21414. '../internals/to-indexed-object': 149
  21415. }
  21416. ],
  21417. 116: [
  21418. function(_dereq_, module, exports) {
  21419. var internalObjectKeys = _dereq_('../internals/object-keys-internal');
  21420. var enumBugKeys = _dereq_('../internals/enum-bug-keys');
  21421. // `Object.keys` method
  21422. // https://tc39.github.io/ecma262/#sec-object.keys
  21423. module.exports =
  21424. Object.keys ||
  21425. function keys(O) {
  21426. return internalObjectKeys(O, enumBugKeys);
  21427. };
  21428. },
  21429. { '../internals/enum-bug-keys': 66, '../internals/object-keys-internal': 115 }
  21430. ],
  21431. 117: [
  21432. function(_dereq_, module, exports) {
  21433. 'use strict';
  21434. var nativePropertyIsEnumerable = {}.propertyIsEnumerable;
  21435. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  21436. // Nashorn ~ JDK8 bug
  21437. var NASHORN_BUG =
  21438. getOwnPropertyDescriptor && !nativePropertyIsEnumerable.call({ 1: 2 }, 1);
  21439. // `Object.prototype.propertyIsEnumerable` method implementation
  21440. // https://tc39.github.io/ecma262/#sec-object.prototype.propertyisenumerable
  21441. exports.f = NASHORN_BUG
  21442. ? function propertyIsEnumerable(V) {
  21443. var descriptor = getOwnPropertyDescriptor(this, V);
  21444. return !!descriptor && descriptor.enumerable;
  21445. }
  21446. : nativePropertyIsEnumerable;
  21447. },
  21448. {}
  21449. ],
  21450. 118: [
  21451. function(_dereq_, module, exports) {
  21452. var anObject = _dereq_('../internals/an-object');
  21453. var aPossiblePrototype = _dereq_('../internals/a-possible-prototype');
  21454. // `Object.setPrototypeOf` method
  21455. // https://tc39.github.io/ecma262/#sec-object.setprototypeof
  21456. // Works with __proto__ only. Old v8 can't work with null proto objects.
  21457. /* eslint-disable no-proto */
  21458. module.exports =
  21459. Object.setPrototypeOf ||
  21460. ('__proto__' in {}
  21461. ? (function() {
  21462. var CORRECT_SETTER = false;
  21463. var test = {};
  21464. var setter;
  21465. try {
  21466. setter = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__')
  21467. .set;
  21468. setter.call(test, []);
  21469. CORRECT_SETTER = test instanceof Array;
  21470. } catch (error) {
  21471. /* empty */
  21472. }
  21473. return function setPrototypeOf(O, proto) {
  21474. anObject(O);
  21475. aPossiblePrototype(proto);
  21476. if (CORRECT_SETTER) setter.call(O, proto);
  21477. else O.__proto__ = proto;
  21478. return O;
  21479. };
  21480. })()
  21481. : undefined);
  21482. },
  21483. { '../internals/a-possible-prototype': 24, '../internals/an-object': 28 }
  21484. ],
  21485. 119: [
  21486. function(_dereq_, module, exports) {
  21487. 'use strict';
  21488. var TO_STRING_TAG_SUPPORT = _dereq_('../internals/to-string-tag-support');
  21489. var classof = _dereq_('../internals/classof');
  21490. // `Object.prototype.toString` method implementation
  21491. // https://tc39.github.io/ecma262/#sec-object.prototype.tostring
  21492. module.exports = TO_STRING_TAG_SUPPORT
  21493. ? {}.toString
  21494. : function toString() {
  21495. return '[object ' + classof(this) + ']';
  21496. };
  21497. },
  21498. { '../internals/classof': 47, '../internals/to-string-tag-support': 156 }
  21499. ],
  21500. 120: [
  21501. function(_dereq_, module, exports) {
  21502. var getBuiltIn = _dereq_('../internals/get-built-in');
  21503. var getOwnPropertyNamesModule = _dereq_(
  21504. '../internals/object-get-own-property-names'
  21505. );
  21506. var getOwnPropertySymbolsModule = _dereq_(
  21507. '../internals/object-get-own-property-symbols'
  21508. );
  21509. var anObject = _dereq_('../internals/an-object');
  21510. // all object keys, includes non-enumerable and symbols
  21511. module.exports =
  21512. getBuiltIn('Reflect', 'ownKeys') ||
  21513. function ownKeys(it) {
  21514. var keys = getOwnPropertyNamesModule.f(anObject(it));
  21515. var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
  21516. return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys;
  21517. };
  21518. },
  21519. {
  21520. '../internals/an-object': 28,
  21521. '../internals/get-built-in': 73,
  21522. '../internals/object-get-own-property-names': 112,
  21523. '../internals/object-get-own-property-symbols': 113
  21524. }
  21525. ],
  21526. 121: [
  21527. function(_dereq_, module, exports) {
  21528. var global = _dereq_('../internals/global');
  21529. module.exports = global;
  21530. },
  21531. { '../internals/global': 76 }
  21532. ],
  21533. 122: [
  21534. function(_dereq_, module, exports) {
  21535. module.exports = function(exec) {
  21536. try {
  21537. return { error: false, value: exec() };
  21538. } catch (error) {
  21539. return { error: true, value: error };
  21540. }
  21541. };
  21542. },
  21543. {}
  21544. ],
  21545. 123: [
  21546. function(_dereq_, module, exports) {
  21547. var anObject = _dereq_('../internals/an-object');
  21548. var isObject = _dereq_('../internals/is-object');
  21549. var newPromiseCapability = _dereq_('../internals/new-promise-capability');
  21550. module.exports = function(C, x) {
  21551. anObject(C);
  21552. if (isObject(x) && x.constructor === C) return x;
  21553. var promiseCapability = newPromiseCapability.f(C);
  21554. var resolve = promiseCapability.resolve;
  21555. resolve(x);
  21556. return promiseCapability.promise;
  21557. };
  21558. },
  21559. {
  21560. '../internals/an-object': 28,
  21561. '../internals/is-object': 91,
  21562. '../internals/new-promise-capability': 103
  21563. }
  21564. ],
  21565. 124: [
  21566. function(_dereq_, module, exports) {
  21567. var redefine = _dereq_('../internals/redefine');
  21568. module.exports = function(target, src, options) {
  21569. for (var key in src) redefine(target, key, src[key], options);
  21570. return target;
  21571. };
  21572. },
  21573. { '../internals/redefine': 125 }
  21574. ],
  21575. 125: [
  21576. function(_dereq_, module, exports) {
  21577. var global = _dereq_('../internals/global');
  21578. var createNonEnumerableProperty = _dereq_(
  21579. '../internals/create-non-enumerable-property'
  21580. );
  21581. var has = _dereq_('../internals/has');
  21582. var setGlobal = _dereq_('../internals/set-global');
  21583. var inspectSource = _dereq_('../internals/inspect-source');
  21584. var InternalStateModule = _dereq_('../internals/internal-state');
  21585. var getInternalState = InternalStateModule.get;
  21586. var enforceInternalState = InternalStateModule.enforce;
  21587. var TEMPLATE = String(String).split('String');
  21588. (module.exports = function(O, key, value, options) {
  21589. var unsafe = options ? !!options.unsafe : false;
  21590. var simple = options ? !!options.enumerable : false;
  21591. var noTargetGet = options ? !!options.noTargetGet : false;
  21592. if (typeof value == 'function') {
  21593. if (typeof key == 'string' && !has(value, 'name'))
  21594. createNonEnumerableProperty(value, 'name', key);
  21595. enforceInternalState(value).source = TEMPLATE.join(
  21596. typeof key == 'string' ? key : ''
  21597. );
  21598. }
  21599. if (O === global) {
  21600. if (simple) O[key] = value;
  21601. else setGlobal(key, value);
  21602. return;
  21603. } else if (!unsafe) {
  21604. delete O[key];
  21605. } else if (!noTargetGet && O[key]) {
  21606. simple = true;
  21607. }
  21608. if (simple) O[key] = value;
  21609. else createNonEnumerableProperty(O, key, value);
  21610. // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
  21611. })(Function.prototype, 'toString', function toString() {
  21612. return (
  21613. (typeof this == 'function' && getInternalState(this).source) ||
  21614. inspectSource(this)
  21615. );
  21616. });
  21617. },
  21618. {
  21619. '../internals/create-non-enumerable-property': 55,
  21620. '../internals/global': 76,
  21621. '../internals/has': 77,
  21622. '../internals/inspect-source': 85,
  21623. '../internals/internal-state': 87,
  21624. '../internals/set-global': 132
  21625. }
  21626. ],
  21627. 126: [
  21628. function(_dereq_, module, exports) {
  21629. var classof = _dereq_('./classof-raw');
  21630. var regexpExec = _dereq_('./regexp-exec');
  21631. // `RegExpExec` abstract operation
  21632. // https://tc39.github.io/ecma262/#sec-regexpexec
  21633. module.exports = function(R, S) {
  21634. var exec = R.exec;
  21635. if (typeof exec === 'function') {
  21636. var result = exec.call(R, S);
  21637. if (typeof result !== 'object') {
  21638. throw TypeError(
  21639. 'RegExp exec method returned something other than an Object or null'
  21640. );
  21641. }
  21642. return result;
  21643. }
  21644. if (classof(R) !== 'RegExp') {
  21645. throw TypeError('RegExp#exec called on incompatible receiver');
  21646. }
  21647. return regexpExec.call(R, S);
  21648. };
  21649. },
  21650. { './classof-raw': 46, './regexp-exec': 127 }
  21651. ],
  21652. 127: [
  21653. function(_dereq_, module, exports) {
  21654. 'use strict';
  21655. var regexpFlags = _dereq_('./regexp-flags');
  21656. var stickyHelpers = _dereq_('./regexp-sticky-helpers');
  21657. var nativeExec = RegExp.prototype.exec;
  21658. // This always refers to the native implementation, because the
  21659. // String#replace polyfill uses ./fix-regexp-well-known-symbol-logic.js,
  21660. // which loads this file before patching the method.
  21661. var nativeReplace = String.prototype.replace;
  21662. var patchedExec = nativeExec;
  21663. var UPDATES_LAST_INDEX_WRONG = (function() {
  21664. var re1 = /a/;
  21665. var re2 = /b*/g;
  21666. nativeExec.call(re1, 'a');
  21667. nativeExec.call(re2, 'a');
  21668. return re1.lastIndex !== 0 || re2.lastIndex !== 0;
  21669. })();
  21670. var UNSUPPORTED_Y = stickyHelpers.UNSUPPORTED_Y || stickyHelpers.BROKEN_CARET;
  21671. // nonparticipating capturing group, copied from es5-shim's String#split patch.
  21672. var NPCG_INCLUDED = /()??/.exec('')[1] !== undefined;
  21673. var PATCH = UPDATES_LAST_INDEX_WRONG || NPCG_INCLUDED || UNSUPPORTED_Y;
  21674. if (PATCH) {
  21675. patchedExec = function exec(str) {
  21676. var re = this;
  21677. var lastIndex, reCopy, match, i;
  21678. var sticky = UNSUPPORTED_Y && re.sticky;
  21679. var flags = regexpFlags.call(re);
  21680. var source = re.source;
  21681. var charsAdded = 0;
  21682. var strCopy = str;
  21683. if (sticky) {
  21684. flags = flags.replace('y', '');
  21685. if (flags.indexOf('g') === -1) {
  21686. flags += 'g';
  21687. }
  21688. strCopy = String(str).slice(re.lastIndex);
  21689. // Support anchored sticky behavior.
  21690. if (
  21691. re.lastIndex > 0 &&
  21692. (!re.multiline || (re.multiline && str[re.lastIndex - 1] !== '\n'))
  21693. ) {
  21694. source = '(?: ' + source + ')';
  21695. strCopy = ' ' + strCopy;
  21696. charsAdded++;
  21697. }
  21698. // ^(? + rx + ) is needed, in combination with some str slicing, to
  21699. // simulate the 'y' flag.
  21700. reCopy = new RegExp('^(?:' + source + ')', flags);
  21701. }
  21702. if (NPCG_INCLUDED) {
  21703. reCopy = new RegExp('^' + source + '$(?!\\s)', flags);
  21704. }
  21705. if (UPDATES_LAST_INDEX_WRONG) lastIndex = re.lastIndex;
  21706. match = nativeExec.call(sticky ? reCopy : re, strCopy);
  21707. if (sticky) {
  21708. if (match) {
  21709. match.input = match.input.slice(charsAdded);
  21710. match[0] = match[0].slice(charsAdded);
  21711. match.index = re.lastIndex;
  21712. re.lastIndex += match[0].length;
  21713. } else re.lastIndex = 0;
  21714. } else if (UPDATES_LAST_INDEX_WRONG && match) {
  21715. re.lastIndex = re.global ? match.index + match[0].length : lastIndex;
  21716. }
  21717. if (NPCG_INCLUDED && match && match.length > 1) {
  21718. // Fix browsers whose `exec` methods don't consistently return `undefined`
  21719. // for NPCG, like IE8. NOTE: This doesn' work for /(.?)?/
  21720. nativeReplace.call(match[0], reCopy, function() {
  21721. for (i = 1; i < arguments.length - 2; i++) {
  21722. if (arguments[i] === undefined) match[i] = undefined;
  21723. }
  21724. });
  21725. }
  21726. return match;
  21727. };
  21728. }
  21729. module.exports = patchedExec;
  21730. },
  21731. { './regexp-flags': 128, './regexp-sticky-helpers': 129 }
  21732. ],
  21733. 128: [
  21734. function(_dereq_, module, exports) {
  21735. 'use strict';
  21736. var anObject = _dereq_('../internals/an-object');
  21737. // `RegExp.prototype.flags` getter implementation
  21738. // https://tc39.github.io/ecma262/#sec-get-regexp.prototype.flags
  21739. module.exports = function() {
  21740. var that = anObject(this);
  21741. var result = '';
  21742. if (that.global) result += 'g';
  21743. if (that.ignoreCase) result += 'i';
  21744. if (that.multiline) result += 'm';
  21745. if (that.dotAll) result += 's';
  21746. if (that.unicode) result += 'u';
  21747. if (that.sticky) result += 'y';
  21748. return result;
  21749. };
  21750. },
  21751. { '../internals/an-object': 28 }
  21752. ],
  21753. 129: [
  21754. function(_dereq_, module, exports) {
  21755. 'use strict';
  21756. var fails = _dereq_('./fails');
  21757. // babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError,
  21758. // so we use an intermediate function.
  21759. function RE(s, f) {
  21760. return RegExp(s, f);
  21761. }
  21762. exports.UNSUPPORTED_Y = fails(function() {
  21763. // babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError
  21764. var re = RE('a', 'y');
  21765. re.lastIndex = 2;
  21766. return re.exec('abcd') != null;
  21767. });
  21768. exports.BROKEN_CARET = fails(function() {
  21769. // https://bugzilla.mozilla.org/show_bug.cgi?id=773687
  21770. var re = RE('^r', 'gy');
  21771. re.lastIndex = 2;
  21772. return re.exec('str') != null;
  21773. });
  21774. },
  21775. { './fails': 68 }
  21776. ],
  21777. 130: [
  21778. function(_dereq_, module, exports) {
  21779. // `RequireObjectCoercible` abstract operation
  21780. // https://tc39.github.io/ecma262/#sec-requireobjectcoercible
  21781. module.exports = function(it) {
  21782. if (it == undefined) throw TypeError("Can't call method on " + it);
  21783. return it;
  21784. };
  21785. },
  21786. {}
  21787. ],
  21788. 131: [
  21789. function(_dereq_, module, exports) {
  21790. // `SameValue` abstract operation
  21791. // https://tc39.github.io/ecma262/#sec-samevalue
  21792. module.exports =
  21793. Object.is ||
  21794. function is(x, y) {
  21795. // eslint-disable-next-line no-self-compare
  21796. return x === y ? x !== 0 || 1 / x === 1 / y : x != x && y != y;
  21797. };
  21798. },
  21799. {}
  21800. ],
  21801. 132: [
  21802. function(_dereq_, module, exports) {
  21803. var global = _dereq_('../internals/global');
  21804. var createNonEnumerableProperty = _dereq_(
  21805. '../internals/create-non-enumerable-property'
  21806. );
  21807. module.exports = function(key, value) {
  21808. try {
  21809. createNonEnumerableProperty(global, key, value);
  21810. } catch (error) {
  21811. global[key] = value;
  21812. }
  21813. return value;
  21814. };
  21815. },
  21816. { '../internals/create-non-enumerable-property': 55, '../internals/global': 76 }
  21817. ],
  21818. 133: [
  21819. function(_dereq_, module, exports) {
  21820. 'use strict';
  21821. var getBuiltIn = _dereq_('../internals/get-built-in');
  21822. var definePropertyModule = _dereq_('../internals/object-define-property');
  21823. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  21824. var DESCRIPTORS = _dereq_('../internals/descriptors');
  21825. var SPECIES = wellKnownSymbol('species');
  21826. module.exports = function(CONSTRUCTOR_NAME) {
  21827. var Constructor = getBuiltIn(CONSTRUCTOR_NAME);
  21828. var defineProperty = definePropertyModule.f;
  21829. if (DESCRIPTORS && Constructor && !Constructor[SPECIES]) {
  21830. defineProperty(Constructor, SPECIES, {
  21831. configurable: true,
  21832. get: function() {
  21833. return this;
  21834. }
  21835. });
  21836. }
  21837. };
  21838. },
  21839. {
  21840. '../internals/descriptors': 60,
  21841. '../internals/get-built-in': 73,
  21842. '../internals/object-define-property': 109,
  21843. '../internals/well-known-symbol': 163
  21844. }
  21845. ],
  21846. 134: [
  21847. function(_dereq_, module, exports) {
  21848. var defineProperty = _dereq_('../internals/object-define-property').f;
  21849. var has = _dereq_('../internals/has');
  21850. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  21851. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  21852. module.exports = function(it, TAG, STATIC) {
  21853. if (it && !has((it = STATIC ? it : it.prototype), TO_STRING_TAG)) {
  21854. defineProperty(it, TO_STRING_TAG, { configurable: true, value: TAG });
  21855. }
  21856. };
  21857. },
  21858. {
  21859. '../internals/has': 77,
  21860. '../internals/object-define-property': 109,
  21861. '../internals/well-known-symbol': 163
  21862. }
  21863. ],
  21864. 135: [
  21865. function(_dereq_, module, exports) {
  21866. var shared = _dereq_('../internals/shared');
  21867. var uid = _dereq_('../internals/uid');
  21868. var keys = shared('keys');
  21869. module.exports = function(key) {
  21870. return keys[key] || (keys[key] = uid(key));
  21871. };
  21872. },
  21873. { '../internals/shared': 137, '../internals/uid': 160 }
  21874. ],
  21875. 136: [
  21876. function(_dereq_, module, exports) {
  21877. var global = _dereq_('../internals/global');
  21878. var setGlobal = _dereq_('../internals/set-global');
  21879. var SHARED = '__core-js_shared__';
  21880. var store = global[SHARED] || setGlobal(SHARED, {});
  21881. module.exports = store;
  21882. },
  21883. { '../internals/global': 76, '../internals/set-global': 132 }
  21884. ],
  21885. 137: [
  21886. function(_dereq_, module, exports) {
  21887. var IS_PURE = _dereq_('../internals/is-pure');
  21888. var store = _dereq_('../internals/shared-store');
  21889. (module.exports = function(key, value) {
  21890. return store[key] || (store[key] = value !== undefined ? value : {});
  21891. })('versions', []).push({
  21892. version: '3.6.5',
  21893. mode: IS_PURE ? 'pure' : 'global',
  21894. copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
  21895. });
  21896. },
  21897. { '../internals/is-pure': 92, '../internals/shared-store': 136 }
  21898. ],
  21899. 138: [
  21900. function(_dereq_, module, exports) {
  21901. var anObject = _dereq_('../internals/an-object');
  21902. var aFunction = _dereq_('../internals/a-function');
  21903. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  21904. var SPECIES = wellKnownSymbol('species');
  21905. // `SpeciesConstructor` abstract operation
  21906. // https://tc39.github.io/ecma262/#sec-speciesconstructor
  21907. module.exports = function(O, defaultConstructor) {
  21908. var C = anObject(O).constructor;
  21909. var S;
  21910. return C === undefined || (S = anObject(C)[SPECIES]) == undefined
  21911. ? defaultConstructor
  21912. : aFunction(S);
  21913. };
  21914. },
  21915. {
  21916. '../internals/a-function': 23,
  21917. '../internals/an-object': 28,
  21918. '../internals/well-known-symbol': 163
  21919. }
  21920. ],
  21921. 139: [
  21922. function(_dereq_, module, exports) {
  21923. var fails = _dereq_('../internals/fails');
  21924. // check the existence of a method, lowercase
  21925. // of a tag and escaping quotes in arguments
  21926. module.exports = function(METHOD_NAME) {
  21927. return fails(function() {
  21928. var test = ''[METHOD_NAME]('"');
  21929. return test !== test.toLowerCase() || test.split('"').length > 3;
  21930. });
  21931. };
  21932. },
  21933. { '../internals/fails': 68 }
  21934. ],
  21935. 140: [
  21936. function(_dereq_, module, exports) {
  21937. var toInteger = _dereq_('../internals/to-integer');
  21938. var requireObjectCoercible = _dereq_('../internals/require-object-coercible');
  21939. // `String.prototype.{ codePointAt, at }` methods implementation
  21940. var createMethod = function(CONVERT_TO_STRING) {
  21941. return function($this, pos) {
  21942. var S = String(requireObjectCoercible($this));
  21943. var position = toInteger(pos);
  21944. var size = S.length;
  21945. var first, second;
  21946. if (position < 0 || position >= size)
  21947. return CONVERT_TO_STRING ? '' : undefined;
  21948. first = S.charCodeAt(position);
  21949. return first < 0xd800 ||
  21950. first > 0xdbff ||
  21951. position + 1 === size ||
  21952. (second = S.charCodeAt(position + 1)) < 0xdc00 ||
  21953. second > 0xdfff
  21954. ? CONVERT_TO_STRING ? S.charAt(position) : first
  21955. : CONVERT_TO_STRING
  21956. ? S.slice(position, position + 2)
  21957. : ((first - 0xd800) << 10) + (second - 0xdc00) + 0x10000;
  21958. };
  21959. };
  21960. module.exports = {
  21961. // `String.prototype.codePointAt` method
  21962. // https://tc39.github.io/ecma262/#sec-string.prototype.codepointat
  21963. codeAt: createMethod(false),
  21964. // `String.prototype.at` method
  21965. // https://github.com/mathiasbynens/String.prototype.at
  21966. charAt: createMethod(true)
  21967. };
  21968. },
  21969. { '../internals/require-object-coercible': 130, '../internals/to-integer': 150 }
  21970. ],
  21971. 141: [
  21972. function(_dereq_, module, exports) {
  21973. 'use strict';
  21974. // based on https://github.com/bestiejs/punycode.js/blob/master/punycode.js
  21975. var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
  21976. var base = 36;
  21977. var tMin = 1;
  21978. var tMax = 26;
  21979. var skew = 38;
  21980. var damp = 700;
  21981. var initialBias = 72;
  21982. var initialN = 128; // 0x80
  21983. var delimiter = '-'; // '\x2D'
  21984. var regexNonASCII = /[^\0-\u007E]/; // non-ASCII chars
  21985. var regexSeparators = /[.\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
  21986. var OVERFLOW_ERROR = 'Overflow: input needs wider integers to process';
  21987. var baseMinusTMin = base - tMin;
  21988. var floor = Math.floor;
  21989. var stringFromCharCode = String.fromCharCode;
  21990. /**
  21991. * Creates an array containing the numeric code points of each Unicode
  21992. * character in the string. While JavaScript uses UCS-2 internally,
  21993. * this function will convert a pair of surrogate halves (each of which
  21994. * UCS-2 exposes as separate characters) into a single code point,
  21995. * matching UTF-16.
  21996. */
  21997. var ucs2decode = function(string) {
  21998. var output = [];
  21999. var counter = 0;
  22000. var length = string.length;
  22001. while (counter < length) {
  22002. var value = string.charCodeAt(counter++);
  22003. if (value >= 0xd800 && value <= 0xdbff && counter < length) {
  22004. // It's a high surrogate, and there is a next character.
  22005. var extra = string.charCodeAt(counter++);
  22006. if ((extra & 0xfc00) == 0xdc00) {
  22007. // Low surrogate.
  22008. output.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000);
  22009. } else {
  22010. // It's an unmatched surrogate; only append this code unit, in case the
  22011. // next code unit is the high surrogate of a surrogate pair.
  22012. output.push(value);
  22013. counter--;
  22014. }
  22015. } else {
  22016. output.push(value);
  22017. }
  22018. }
  22019. return output;
  22020. };
  22021. /**
  22022. * Converts a digit/integer into a basic code point.
  22023. */
  22024. var digitToBasic = function(digit) {
  22025. // 0..25 map to ASCII a..z or A..Z
  22026. // 26..35 map to ASCII 0..9
  22027. return digit + 22 + 75 * (digit < 26);
  22028. };
  22029. /**
  22030. * Bias adaptation function as per section 3.4 of RFC 3492.
  22031. * https://tools.ietf.org/html/rfc3492#section-3.4
  22032. */
  22033. var adapt = function(delta, numPoints, firstTime) {
  22034. var k = 0;
  22035. delta = firstTime ? floor(delta / damp) : delta >> 1;
  22036. delta += floor(delta / numPoints);
  22037. for (; delta > (baseMinusTMin * tMax) >> 1; k += base) {
  22038. delta = floor(delta / baseMinusTMin);
  22039. }
  22040. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  22041. };
  22042. /**
  22043. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  22044. * Punycode string of ASCII-only symbols.
  22045. */
  22046. // eslint-disable-next-line max-statements
  22047. var encode = function(input) {
  22048. var output = [];
  22049. // Convert the input in UCS-2 to an array of Unicode code points.
  22050. input = ucs2decode(input);
  22051. // Cache the length.
  22052. var inputLength = input.length;
  22053. // Initialize the state.
  22054. var n = initialN;
  22055. var delta = 0;
  22056. var bias = initialBias;
  22057. var i, currentValue;
  22058. // Handle the basic code points.
  22059. for (i = 0; i < input.length; i++) {
  22060. currentValue = input[i];
  22061. if (currentValue < 0x80) {
  22062. output.push(stringFromCharCode(currentValue));
  22063. }
  22064. }
  22065. var basicLength = output.length; // number of basic code points.
  22066. var handledCPCount = basicLength; // number of code points that have been handled;
  22067. // Finish the basic string with a delimiter unless it's empty.
  22068. if (basicLength) {
  22069. output.push(delimiter);
  22070. }
  22071. // Main encoding loop:
  22072. while (handledCPCount < inputLength) {
  22073. // All non-basic code points < n have been handled already. Find the next larger one:
  22074. var m = maxInt;
  22075. for (i = 0; i < input.length; i++) {
  22076. currentValue = input[i];
  22077. if (currentValue >= n && currentValue < m) {
  22078. m = currentValue;
  22079. }
  22080. }
  22081. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>, but guard against overflow.
  22082. var handledCPCountPlusOne = handledCPCount + 1;
  22083. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  22084. throw RangeError(OVERFLOW_ERROR);
  22085. }
  22086. delta += (m - n) * handledCPCountPlusOne;
  22087. n = m;
  22088. for (i = 0; i < input.length; i++) {
  22089. currentValue = input[i];
  22090. if (currentValue < n && ++delta > maxInt) {
  22091. throw RangeError(OVERFLOW_ERROR);
  22092. }
  22093. if (currentValue == n) {
  22094. // Represent delta as a generalized variable-length integer.
  22095. var q = delta;
  22096. for (var k = base /* no condition */; ; k += base) {
  22097. var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
  22098. if (q < t) break;
  22099. var qMinusT = q - t;
  22100. var baseMinusT = base - t;
  22101. output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT)));
  22102. q = floor(qMinusT / baseMinusT);
  22103. }
  22104. output.push(stringFromCharCode(digitToBasic(q)));
  22105. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  22106. delta = 0;
  22107. ++handledCPCount;
  22108. }
  22109. }
  22110. ++delta;
  22111. ++n;
  22112. }
  22113. return output.join('');
  22114. };
  22115. module.exports = function(input) {
  22116. var encoded = [];
  22117. var labels = input
  22118. .toLowerCase()
  22119. .replace(regexSeparators, '\u002E')
  22120. .split('.');
  22121. var i, label;
  22122. for (i = 0; i < labels.length; i++) {
  22123. label = labels[i];
  22124. encoded.push(regexNonASCII.test(label) ? 'xn--' + encode(label) : label);
  22125. }
  22126. return encoded.join('.');
  22127. };
  22128. },
  22129. {}
  22130. ],
  22131. 142: [
  22132. function(_dereq_, module, exports) {
  22133. 'use strict';
  22134. var toInteger = _dereq_('../internals/to-integer');
  22135. var requireObjectCoercible = _dereq_('../internals/require-object-coercible');
  22136. // `String.prototype.repeat` method implementation
  22137. // https://tc39.github.io/ecma262/#sec-string.prototype.repeat
  22138. module.exports =
  22139. ''.repeat ||
  22140. function repeat(count) {
  22141. var str = String(requireObjectCoercible(this));
  22142. var result = '';
  22143. var n = toInteger(count);
  22144. if (n < 0 || n == Infinity) throw RangeError('Wrong number of repetitions');
  22145. for (; n > 0; (n >>>= 1) && (str += str)) if (n & 1) result += str;
  22146. return result;
  22147. };
  22148. },
  22149. { '../internals/require-object-coercible': 130, '../internals/to-integer': 150 }
  22150. ],
  22151. 143: [
  22152. function(_dereq_, module, exports) {
  22153. var fails = _dereq_('../internals/fails');
  22154. var whitespaces = _dereq_('../internals/whitespaces');
  22155. var non = '\u200B\u0085\u180E';
  22156. // check that a method works with the correct list
  22157. // of whitespaces and has a correct name
  22158. module.exports = function(METHOD_NAME) {
  22159. return fails(function() {
  22160. return (
  22161. !!whitespaces[METHOD_NAME]() ||
  22162. non[METHOD_NAME]() != non ||
  22163. whitespaces[METHOD_NAME].name !== METHOD_NAME
  22164. );
  22165. });
  22166. };
  22167. },
  22168. { '../internals/fails': 68, '../internals/whitespaces': 164 }
  22169. ],
  22170. 144: [
  22171. function(_dereq_, module, exports) {
  22172. var requireObjectCoercible = _dereq_('../internals/require-object-coercible');
  22173. var whitespaces = _dereq_('../internals/whitespaces');
  22174. var whitespace = '[' + whitespaces + ']';
  22175. var ltrim = RegExp('^' + whitespace + whitespace + '*');
  22176. var rtrim = RegExp(whitespace + whitespace + '*$');
  22177. // `String.prototype.{ trim, trimStart, trimEnd, trimLeft, trimRight }` methods implementation
  22178. var createMethod = function(TYPE) {
  22179. return function($this) {
  22180. var string = String(requireObjectCoercible($this));
  22181. if (TYPE & 1) string = string.replace(ltrim, '');
  22182. if (TYPE & 2) string = string.replace(rtrim, '');
  22183. return string;
  22184. };
  22185. };
  22186. module.exports = {
  22187. // `String.prototype.{ trimLeft, trimStart }` methods
  22188. // https://tc39.github.io/ecma262/#sec-string.prototype.trimstart
  22189. start: createMethod(1),
  22190. // `String.prototype.{ trimRight, trimEnd }` methods
  22191. // https://tc39.github.io/ecma262/#sec-string.prototype.trimend
  22192. end: createMethod(2),
  22193. // `String.prototype.trim` method
  22194. // https://tc39.github.io/ecma262/#sec-string.prototype.trim
  22195. trim: createMethod(3)
  22196. };
  22197. },
  22198. { '../internals/require-object-coercible': 130, '../internals/whitespaces': 164 }
  22199. ],
  22200. 145: [
  22201. function(_dereq_, module, exports) {
  22202. var global = _dereq_('../internals/global');
  22203. var fails = _dereq_('../internals/fails');
  22204. var classof = _dereq_('../internals/classof-raw');
  22205. var bind = _dereq_('../internals/function-bind-context');
  22206. var html = _dereq_('../internals/html');
  22207. var createElement = _dereq_('../internals/document-create-element');
  22208. var IS_IOS = _dereq_('../internals/engine-is-ios');
  22209. var location = global.location;
  22210. var set = global.setImmediate;
  22211. var clear = global.clearImmediate;
  22212. var process = global.process;
  22213. var MessageChannel = global.MessageChannel;
  22214. var Dispatch = global.Dispatch;
  22215. var counter = 0;
  22216. var queue = {};
  22217. var ONREADYSTATECHANGE = 'onreadystatechange';
  22218. var defer, channel, port;
  22219. var run = function(id) {
  22220. // eslint-disable-next-line no-prototype-builtins
  22221. if (queue.hasOwnProperty(id)) {
  22222. var fn = queue[id];
  22223. delete queue[id];
  22224. fn();
  22225. }
  22226. };
  22227. var runner = function(id) {
  22228. return function() {
  22229. run(id);
  22230. };
  22231. };
  22232. var listener = function(event) {
  22233. run(event.data);
  22234. };
  22235. var post = function(id) {
  22236. // old engines have not location.origin
  22237. global.postMessage(id + '', location.protocol + '//' + location.host);
  22238. };
  22239. // Node.js 0.9+ & IE10+ has setImmediate, otherwise:
  22240. if (!set || !clear) {
  22241. set = function setImmediate(fn) {
  22242. var args = [];
  22243. var i = 1;
  22244. while (arguments.length > i) args.push(arguments[i++]);
  22245. queue[++counter] = function() {
  22246. // eslint-disable-next-line no-new-func
  22247. (typeof fn == 'function' ? fn : Function(fn)).apply(undefined, args);
  22248. };
  22249. defer(counter);
  22250. return counter;
  22251. };
  22252. clear = function clearImmediate(id) {
  22253. delete queue[id];
  22254. };
  22255. // Node.js 0.8-
  22256. if (classof(process) == 'process') {
  22257. defer = function(id) {
  22258. process.nextTick(runner(id));
  22259. };
  22260. // Sphere (JS game engine) Dispatch API
  22261. } else if (Dispatch && Dispatch.now) {
  22262. defer = function(id) {
  22263. Dispatch.now(runner(id));
  22264. };
  22265. // Browsers with MessageChannel, includes WebWorkers
  22266. // except iOS - https://github.com/zloirock/core-js/issues/624
  22267. } else if (MessageChannel && !IS_IOS) {
  22268. channel = new MessageChannel();
  22269. port = channel.port2;
  22270. channel.port1.onmessage = listener;
  22271. defer = bind(port.postMessage, port, 1);
  22272. // Browsers with postMessage, skip WebWorkers
  22273. // IE8 has postMessage, but it's sync & typeof its postMessage is 'object'
  22274. } else if (
  22275. global.addEventListener &&
  22276. typeof postMessage == 'function' &&
  22277. !global.importScripts &&
  22278. !fails(post) &&
  22279. location.protocol !== 'file:'
  22280. ) {
  22281. defer = post;
  22282. global.addEventListener('message', listener, false);
  22283. // IE8-
  22284. } else if (ONREADYSTATECHANGE in createElement('script')) {
  22285. defer = function(id) {
  22286. html.appendChild(createElement('script'))[ONREADYSTATECHANGE] = function() {
  22287. html.removeChild(this);
  22288. run(id);
  22289. };
  22290. };
  22291. // Rest old browsers
  22292. } else {
  22293. defer = function(id) {
  22294. setTimeout(runner(id), 0);
  22295. };
  22296. }
  22297. }
  22298. module.exports = {
  22299. set: set,
  22300. clear: clear
  22301. };
  22302. },
  22303. {
  22304. '../internals/classof-raw': 46,
  22305. '../internals/document-create-element': 61,
  22306. '../internals/engine-is-ios': 63,
  22307. '../internals/fails': 68,
  22308. '../internals/function-bind-context': 71,
  22309. '../internals/global': 76,
  22310. '../internals/html': 80
  22311. }
  22312. ],
  22313. 146: [
  22314. function(_dereq_, module, exports) {
  22315. var classof = _dereq_('../internals/classof-raw');
  22316. // `thisNumberValue` abstract operation
  22317. // https://tc39.github.io/ecma262/#sec-thisnumbervalue
  22318. module.exports = function(value) {
  22319. if (typeof value != 'number' && classof(value) != 'Number') {
  22320. throw TypeError('Incorrect invocation');
  22321. }
  22322. return +value;
  22323. };
  22324. },
  22325. { '../internals/classof-raw': 46 }
  22326. ],
  22327. 147: [
  22328. function(_dereq_, module, exports) {
  22329. var toInteger = _dereq_('../internals/to-integer');
  22330. var max = Math.max;
  22331. var min = Math.min;
  22332. // Helper for a popular repeating case of the spec:
  22333. // Let integer be ? ToInteger(index).
  22334. // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
  22335. module.exports = function(index, length) {
  22336. var integer = toInteger(index);
  22337. return integer < 0 ? max(integer + length, 0) : min(integer, length);
  22338. };
  22339. },
  22340. { '../internals/to-integer': 150 }
  22341. ],
  22342. 148: [
  22343. function(_dereq_, module, exports) {
  22344. var toInteger = _dereq_('../internals/to-integer');
  22345. var toLength = _dereq_('../internals/to-length');
  22346. // `ToIndex` abstract operation
  22347. // https://tc39.github.io/ecma262/#sec-toindex
  22348. module.exports = function(it) {
  22349. if (it === undefined) return 0;
  22350. var number = toInteger(it);
  22351. var length = toLength(number);
  22352. if (number !== length) throw RangeError('Wrong length or index');
  22353. return length;
  22354. };
  22355. },
  22356. { '../internals/to-integer': 150, '../internals/to-length': 151 }
  22357. ],
  22358. 149: [
  22359. function(_dereq_, module, exports) {
  22360. // toObject with fallback for non-array-like ES3 strings
  22361. var IndexedObject = _dereq_('../internals/indexed-object');
  22362. var requireObjectCoercible = _dereq_('../internals/require-object-coercible');
  22363. module.exports = function(it) {
  22364. return IndexedObject(requireObjectCoercible(it));
  22365. };
  22366. },
  22367. { '../internals/indexed-object': 83, '../internals/require-object-coercible': 130 }
  22368. ],
  22369. 150: [
  22370. function(_dereq_, module, exports) {
  22371. var ceil = Math.ceil;
  22372. var floor = Math.floor;
  22373. // `ToInteger` abstract operation
  22374. // https://tc39.github.io/ecma262/#sec-tointeger
  22375. module.exports = function(argument) {
  22376. return isNaN((argument = +argument))
  22377. ? 0
  22378. : (argument > 0 ? floor : ceil)(argument);
  22379. };
  22380. },
  22381. {}
  22382. ],
  22383. 151: [
  22384. function(_dereq_, module, exports) {
  22385. var toInteger = _dereq_('../internals/to-integer');
  22386. var min = Math.min;
  22387. // `ToLength` abstract operation
  22388. // https://tc39.github.io/ecma262/#sec-tolength
  22389. module.exports = function(argument) {
  22390. return argument > 0 ? min(toInteger(argument), 0x1fffffffffffff) : 0; // 2 ** 53 - 1 == 9007199254740991
  22391. };
  22392. },
  22393. { '../internals/to-integer': 150 }
  22394. ],
  22395. 152: [
  22396. function(_dereq_, module, exports) {
  22397. var requireObjectCoercible = _dereq_('../internals/require-object-coercible');
  22398. // `ToObject` abstract operation
  22399. // https://tc39.github.io/ecma262/#sec-toobject
  22400. module.exports = function(argument) {
  22401. return Object(requireObjectCoercible(argument));
  22402. };
  22403. },
  22404. { '../internals/require-object-coercible': 130 }
  22405. ],
  22406. 153: [
  22407. function(_dereq_, module, exports) {
  22408. var toPositiveInteger = _dereq_('../internals/to-positive-integer');
  22409. module.exports = function(it, BYTES) {
  22410. var offset = toPositiveInteger(it);
  22411. if (offset % BYTES) throw RangeError('Wrong offset');
  22412. return offset;
  22413. };
  22414. },
  22415. { '../internals/to-positive-integer': 154 }
  22416. ],
  22417. 154: [
  22418. function(_dereq_, module, exports) {
  22419. var toInteger = _dereq_('../internals/to-integer');
  22420. module.exports = function(it) {
  22421. var result = toInteger(it);
  22422. if (result < 0) throw RangeError("The argument can't be less than 0");
  22423. return result;
  22424. };
  22425. },
  22426. { '../internals/to-integer': 150 }
  22427. ],
  22428. 155: [
  22429. function(_dereq_, module, exports) {
  22430. var isObject = _dereq_('../internals/is-object');
  22431. // `ToPrimitive` abstract operation
  22432. // https://tc39.github.io/ecma262/#sec-toprimitive
  22433. // instead of the ES6 spec version, we didn't implement @@toPrimitive case
  22434. // and the second argument - flag - preferred type is a string
  22435. module.exports = function(input, PREFERRED_STRING) {
  22436. if (!isObject(input)) return input;
  22437. var fn, val;
  22438. if (
  22439. PREFERRED_STRING &&
  22440. typeof (fn = input.toString) == 'function' &&
  22441. !isObject((val = fn.call(input)))
  22442. )
  22443. return val;
  22444. if (
  22445. typeof (fn = input.valueOf) == 'function' &&
  22446. !isObject((val = fn.call(input)))
  22447. )
  22448. return val;
  22449. if (
  22450. !PREFERRED_STRING &&
  22451. typeof (fn = input.toString) == 'function' &&
  22452. !isObject((val = fn.call(input)))
  22453. )
  22454. return val;
  22455. throw TypeError("Can't convert object to primitive value");
  22456. };
  22457. },
  22458. { '../internals/is-object': 91 }
  22459. ],
  22460. 156: [
  22461. function(_dereq_, module, exports) {
  22462. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  22463. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  22464. var test = {};
  22465. test[TO_STRING_TAG] = 'z';
  22466. module.exports = String(test) === '[object z]';
  22467. },
  22468. { '../internals/well-known-symbol': 163 }
  22469. ],
  22470. 157: [
  22471. function(_dereq_, module, exports) {
  22472. 'use strict';
  22473. var $ = _dereq_('../internals/export');
  22474. var global = _dereq_('../internals/global');
  22475. var DESCRIPTORS = _dereq_('../internals/descriptors');
  22476. var TYPED_ARRAYS_CONSTRUCTORS_REQUIRES_WRAPPERS = _dereq_(
  22477. '../internals/typed-array-constructors-require-wrappers'
  22478. );
  22479. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  22480. var ArrayBufferModule = _dereq_('../internals/array-buffer');
  22481. var anInstance = _dereq_('../internals/an-instance');
  22482. var createPropertyDescriptor = _dereq_('../internals/create-property-descriptor');
  22483. var createNonEnumerableProperty = _dereq_(
  22484. '../internals/create-non-enumerable-property'
  22485. );
  22486. var toLength = _dereq_('../internals/to-length');
  22487. var toIndex = _dereq_('../internals/to-index');
  22488. var toOffset = _dereq_('../internals/to-offset');
  22489. var toPrimitive = _dereq_('../internals/to-primitive');
  22490. var has = _dereq_('../internals/has');
  22491. var classof = _dereq_('../internals/classof');
  22492. var isObject = _dereq_('../internals/is-object');
  22493. var create = _dereq_('../internals/object-create');
  22494. var setPrototypeOf = _dereq_('../internals/object-set-prototype-of');
  22495. var getOwnPropertyNames = _dereq_('../internals/object-get-own-property-names').f;
  22496. var typedArrayFrom = _dereq_('../internals/typed-array-from');
  22497. var forEach = _dereq_('../internals/array-iteration').forEach;
  22498. var setSpecies = _dereq_('../internals/set-species');
  22499. var definePropertyModule = _dereq_('../internals/object-define-property');
  22500. var getOwnPropertyDescriptorModule = _dereq_(
  22501. '../internals/object-get-own-property-descriptor'
  22502. );
  22503. var InternalStateModule = _dereq_('../internals/internal-state');
  22504. var inheritIfRequired = _dereq_('../internals/inherit-if-required');
  22505. var getInternalState = InternalStateModule.get;
  22506. var setInternalState = InternalStateModule.set;
  22507. var nativeDefineProperty = definePropertyModule.f;
  22508. var nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  22509. var round = Math.round;
  22510. var RangeError = global.RangeError;
  22511. var ArrayBuffer = ArrayBufferModule.ArrayBuffer;
  22512. var DataView = ArrayBufferModule.DataView;
  22513. var NATIVE_ARRAY_BUFFER_VIEWS = ArrayBufferViewCore.NATIVE_ARRAY_BUFFER_VIEWS;
  22514. var TYPED_ARRAY_TAG = ArrayBufferViewCore.TYPED_ARRAY_TAG;
  22515. var TypedArray = ArrayBufferViewCore.TypedArray;
  22516. var TypedArrayPrototype = ArrayBufferViewCore.TypedArrayPrototype;
  22517. var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor;
  22518. var isTypedArray = ArrayBufferViewCore.isTypedArray;
  22519. var BYTES_PER_ELEMENT = 'BYTES_PER_ELEMENT';
  22520. var WRONG_LENGTH = 'Wrong length';
  22521. var fromList = function(C, list) {
  22522. var index = 0;
  22523. var length = list.length;
  22524. var result = new (aTypedArrayConstructor(C))(length);
  22525. while (length > index) result[index] = list[index++];
  22526. return result;
  22527. };
  22528. var addGetter = function(it, key) {
  22529. nativeDefineProperty(it, key, {
  22530. get: function() {
  22531. return getInternalState(this)[key];
  22532. }
  22533. });
  22534. };
  22535. var isArrayBuffer = function(it) {
  22536. var klass;
  22537. return (
  22538. it instanceof ArrayBuffer ||
  22539. (klass = classof(it)) == 'ArrayBuffer' ||
  22540. klass == 'SharedArrayBuffer'
  22541. );
  22542. };
  22543. var isTypedArrayIndex = function(target, key) {
  22544. return (
  22545. isTypedArray(target) &&
  22546. typeof key != 'symbol' &&
  22547. key in target &&
  22548. String(+key) == String(key)
  22549. );
  22550. };
  22551. var wrappedGetOwnPropertyDescriptor = function getOwnPropertyDescriptor(
  22552. target,
  22553. key
  22554. ) {
  22555. return isTypedArrayIndex(target, (key = toPrimitive(key, true)))
  22556. ? createPropertyDescriptor(2, target[key])
  22557. : nativeGetOwnPropertyDescriptor(target, key);
  22558. };
  22559. var wrappedDefineProperty = function defineProperty(target, key, descriptor) {
  22560. if (
  22561. isTypedArrayIndex(target, (key = toPrimitive(key, true))) &&
  22562. isObject(descriptor) &&
  22563. has(descriptor, 'value') &&
  22564. !has(descriptor, 'get') &&
  22565. !has(descriptor, 'set') &&
  22566. // TODO: add validation descriptor w/o calling accessors
  22567. !descriptor.configurable &&
  22568. (!has(descriptor, 'writable') || descriptor.writable) &&
  22569. (!has(descriptor, 'enumerable') || descriptor.enumerable)
  22570. ) {
  22571. target[key] = descriptor.value;
  22572. return target;
  22573. }
  22574. return nativeDefineProperty(target, key, descriptor);
  22575. };
  22576. if (DESCRIPTORS) {
  22577. if (!NATIVE_ARRAY_BUFFER_VIEWS) {
  22578. getOwnPropertyDescriptorModule.f = wrappedGetOwnPropertyDescriptor;
  22579. definePropertyModule.f = wrappedDefineProperty;
  22580. addGetter(TypedArrayPrototype, 'buffer');
  22581. addGetter(TypedArrayPrototype, 'byteOffset');
  22582. addGetter(TypedArrayPrototype, 'byteLength');
  22583. addGetter(TypedArrayPrototype, 'length');
  22584. }
  22585. $(
  22586. { target: 'Object', stat: true, forced: !NATIVE_ARRAY_BUFFER_VIEWS },
  22587. {
  22588. getOwnPropertyDescriptor: wrappedGetOwnPropertyDescriptor,
  22589. defineProperty: wrappedDefineProperty
  22590. }
  22591. );
  22592. module.exports = function(TYPE, wrapper, CLAMPED) {
  22593. var BYTES = TYPE.match(/\d+$/)[0] / 8;
  22594. var CONSTRUCTOR_NAME = TYPE + (CLAMPED ? 'Clamped' : '') + 'Array';
  22595. var GETTER = 'get' + TYPE;
  22596. var SETTER = 'set' + TYPE;
  22597. var NativeTypedArrayConstructor = global[CONSTRUCTOR_NAME];
  22598. var TypedArrayConstructor = NativeTypedArrayConstructor;
  22599. var TypedArrayConstructorPrototype =
  22600. TypedArrayConstructor && TypedArrayConstructor.prototype;
  22601. var exported = {};
  22602. var getter = function(that, index) {
  22603. var data = getInternalState(that);
  22604. return data.view[GETTER](index * BYTES + data.byteOffset, true);
  22605. };
  22606. var setter = function(that, index, value) {
  22607. var data = getInternalState(that);
  22608. if (CLAMPED)
  22609. value =
  22610. (value = round(value)) < 0 ? 0 : value > 0xff ? 0xff : value & 0xff;
  22611. data.view[SETTER](index * BYTES + data.byteOffset, value, true);
  22612. };
  22613. var addElement = function(that, index) {
  22614. nativeDefineProperty(that, index, {
  22615. get: function() {
  22616. return getter(this, index);
  22617. },
  22618. set: function(value) {
  22619. return setter(this, index, value);
  22620. },
  22621. enumerable: true
  22622. });
  22623. };
  22624. if (!NATIVE_ARRAY_BUFFER_VIEWS) {
  22625. TypedArrayConstructor = wrapper(function(that, data, offset, $length) {
  22626. anInstance(that, TypedArrayConstructor, CONSTRUCTOR_NAME);
  22627. var index = 0;
  22628. var byteOffset = 0;
  22629. var buffer, byteLength, length;
  22630. if (!isObject(data)) {
  22631. length = toIndex(data);
  22632. byteLength = length * BYTES;
  22633. buffer = new ArrayBuffer(byteLength);
  22634. } else if (isArrayBuffer(data)) {
  22635. buffer = data;
  22636. byteOffset = toOffset(offset, BYTES);
  22637. var $len = data.byteLength;
  22638. if ($length === undefined) {
  22639. if ($len % BYTES) throw RangeError(WRONG_LENGTH);
  22640. byteLength = $len - byteOffset;
  22641. if (byteLength < 0) throw RangeError(WRONG_LENGTH);
  22642. } else {
  22643. byteLength = toLength($length) * BYTES;
  22644. if (byteLength + byteOffset > $len) throw RangeError(WRONG_LENGTH);
  22645. }
  22646. length = byteLength / BYTES;
  22647. } else if (isTypedArray(data)) {
  22648. return fromList(TypedArrayConstructor, data);
  22649. } else {
  22650. return typedArrayFrom.call(TypedArrayConstructor, data);
  22651. }
  22652. setInternalState(that, {
  22653. buffer: buffer,
  22654. byteOffset: byteOffset,
  22655. byteLength: byteLength,
  22656. length: length,
  22657. view: new DataView(buffer)
  22658. });
  22659. while (index < length) addElement(that, index++);
  22660. });
  22661. if (setPrototypeOf) setPrototypeOf(TypedArrayConstructor, TypedArray);
  22662. TypedArrayConstructorPrototype = TypedArrayConstructor.prototype = create(
  22663. TypedArrayPrototype
  22664. );
  22665. } else if (TYPED_ARRAYS_CONSTRUCTORS_REQUIRES_WRAPPERS) {
  22666. TypedArrayConstructor = wrapper(function(
  22667. dummy,
  22668. data,
  22669. typedArrayOffset,
  22670. $length
  22671. ) {
  22672. anInstance(dummy, TypedArrayConstructor, CONSTRUCTOR_NAME);
  22673. return inheritIfRequired(
  22674. (function() {
  22675. if (!isObject(data))
  22676. return new NativeTypedArrayConstructor(toIndex(data));
  22677. if (isArrayBuffer(data))
  22678. return $length !== undefined
  22679. ? new NativeTypedArrayConstructor(
  22680. data,
  22681. toOffset(typedArrayOffset, BYTES),
  22682. $length
  22683. )
  22684. : typedArrayOffset !== undefined
  22685. ? new NativeTypedArrayConstructor(
  22686. data,
  22687. toOffset(typedArrayOffset, BYTES)
  22688. )
  22689. : new NativeTypedArrayConstructor(data);
  22690. if (isTypedArray(data)) return fromList(TypedArrayConstructor, data);
  22691. return typedArrayFrom.call(TypedArrayConstructor, data);
  22692. })(),
  22693. dummy,
  22694. TypedArrayConstructor
  22695. );
  22696. });
  22697. if (setPrototypeOf) setPrototypeOf(TypedArrayConstructor, TypedArray);
  22698. forEach(getOwnPropertyNames(NativeTypedArrayConstructor), function(key) {
  22699. if (!(key in TypedArrayConstructor)) {
  22700. createNonEnumerableProperty(
  22701. TypedArrayConstructor,
  22702. key,
  22703. NativeTypedArrayConstructor[key]
  22704. );
  22705. }
  22706. });
  22707. TypedArrayConstructor.prototype = TypedArrayConstructorPrototype;
  22708. }
  22709. if (TypedArrayConstructorPrototype.constructor !== TypedArrayConstructor) {
  22710. createNonEnumerableProperty(
  22711. TypedArrayConstructorPrototype,
  22712. 'constructor',
  22713. TypedArrayConstructor
  22714. );
  22715. }
  22716. if (TYPED_ARRAY_TAG) {
  22717. createNonEnumerableProperty(
  22718. TypedArrayConstructorPrototype,
  22719. TYPED_ARRAY_TAG,
  22720. CONSTRUCTOR_NAME
  22721. );
  22722. }
  22723. exported[CONSTRUCTOR_NAME] = TypedArrayConstructor;
  22724. $(
  22725. {
  22726. global: true,
  22727. forced: TypedArrayConstructor != NativeTypedArrayConstructor,
  22728. sham: !NATIVE_ARRAY_BUFFER_VIEWS
  22729. },
  22730. exported
  22731. );
  22732. if (!(BYTES_PER_ELEMENT in TypedArrayConstructor)) {
  22733. createNonEnumerableProperty(
  22734. TypedArrayConstructor,
  22735. BYTES_PER_ELEMENT,
  22736. BYTES
  22737. );
  22738. }
  22739. if (!(BYTES_PER_ELEMENT in TypedArrayConstructorPrototype)) {
  22740. createNonEnumerableProperty(
  22741. TypedArrayConstructorPrototype,
  22742. BYTES_PER_ELEMENT,
  22743. BYTES
  22744. );
  22745. }
  22746. setSpecies(CONSTRUCTOR_NAME);
  22747. };
  22748. } else
  22749. module.exports = function() {
  22750. /* empty */
  22751. };
  22752. },
  22753. {
  22754. '../internals/an-instance': 27,
  22755. '../internals/array-buffer': 31,
  22756. '../internals/array-buffer-view-core': 30,
  22757. '../internals/array-iteration': 37,
  22758. '../internals/classof': 47,
  22759. '../internals/create-non-enumerable-property': 55,
  22760. '../internals/create-property-descriptor': 56,
  22761. '../internals/descriptors': 60,
  22762. '../internals/export': 67,
  22763. '../internals/global': 76,
  22764. '../internals/has': 77,
  22765. '../internals/inherit-if-required': 84,
  22766. '../internals/internal-state': 87,
  22767. '../internals/is-object': 91,
  22768. '../internals/object-create': 107,
  22769. '../internals/object-define-property': 109,
  22770. '../internals/object-get-own-property-descriptor': 110,
  22771. '../internals/object-get-own-property-names': 112,
  22772. '../internals/object-set-prototype-of': 118,
  22773. '../internals/set-species': 133,
  22774. '../internals/to-index': 148,
  22775. '../internals/to-length': 151,
  22776. '../internals/to-offset': 153,
  22777. '../internals/to-primitive': 155,
  22778. '../internals/typed-array-constructors-require-wrappers': 158,
  22779. '../internals/typed-array-from': 159
  22780. }
  22781. ],
  22782. 158: [
  22783. function(_dereq_, module, exports) {
  22784. /* eslint-disable no-new */
  22785. var global = _dereq_('../internals/global');
  22786. var fails = _dereq_('../internals/fails');
  22787. var checkCorrectnessOfIteration = _dereq_(
  22788. '../internals/check-correctness-of-iteration'
  22789. );
  22790. var NATIVE_ARRAY_BUFFER_VIEWS = _dereq_('../internals/array-buffer-view-core')
  22791. .NATIVE_ARRAY_BUFFER_VIEWS;
  22792. var ArrayBuffer = global.ArrayBuffer;
  22793. var Int8Array = global.Int8Array;
  22794. module.exports =
  22795. !NATIVE_ARRAY_BUFFER_VIEWS ||
  22796. !fails(function() {
  22797. Int8Array(1);
  22798. }) ||
  22799. !fails(function() {
  22800. new Int8Array(-1);
  22801. }) ||
  22802. !checkCorrectnessOfIteration(function(iterable) {
  22803. new Int8Array();
  22804. new Int8Array(null);
  22805. new Int8Array(1.5);
  22806. new Int8Array(iterable);
  22807. }, true) ||
  22808. fails(function() {
  22809. // Safari (11+) bug - a reason why even Safari 13 should load a typed array polyfill
  22810. return new Int8Array(new ArrayBuffer(2), 1, undefined).length !== 1;
  22811. });
  22812. },
  22813. {
  22814. '../internals/array-buffer-view-core': 30,
  22815. '../internals/check-correctness-of-iteration': 45,
  22816. '../internals/fails': 68,
  22817. '../internals/global': 76
  22818. }
  22819. ],
  22820. 159: [
  22821. function(_dereq_, module, exports) {
  22822. var toObject = _dereq_('../internals/to-object');
  22823. var toLength = _dereq_('../internals/to-length');
  22824. var getIteratorMethod = _dereq_('../internals/get-iterator-method');
  22825. var isArrayIteratorMethod = _dereq_('../internals/is-array-iterator-method');
  22826. var bind = _dereq_('../internals/function-bind-context');
  22827. var aTypedArrayConstructor = _dereq_('../internals/array-buffer-view-core')
  22828. .aTypedArrayConstructor;
  22829. module.exports = function from(source /* , mapfn, thisArg */) {
  22830. var O = toObject(source);
  22831. var argumentsLength = arguments.length;
  22832. var mapfn = argumentsLength > 1 ? arguments[1] : undefined;
  22833. var mapping = mapfn !== undefined;
  22834. var iteratorMethod = getIteratorMethod(O);
  22835. var i, length, result, step, iterator, next;
  22836. if (iteratorMethod != undefined && !isArrayIteratorMethod(iteratorMethod)) {
  22837. iterator = iteratorMethod.call(O);
  22838. next = iterator.next;
  22839. O = [];
  22840. while (!(step = next.call(iterator)).done) {
  22841. O.push(step.value);
  22842. }
  22843. }
  22844. if (mapping && argumentsLength > 2) {
  22845. mapfn = bind(mapfn, arguments[2], 2);
  22846. }
  22847. length = toLength(O.length);
  22848. result = new (aTypedArrayConstructor(this))(length);
  22849. for (i = 0; length > i; i++) {
  22850. result[i] = mapping ? mapfn(O[i], i) : O[i];
  22851. }
  22852. return result;
  22853. };
  22854. },
  22855. {
  22856. '../internals/array-buffer-view-core': 30,
  22857. '../internals/function-bind-context': 71,
  22858. '../internals/get-iterator-method': 74,
  22859. '../internals/is-array-iterator-method': 88,
  22860. '../internals/to-length': 151,
  22861. '../internals/to-object': 152
  22862. }
  22863. ],
  22864. 160: [
  22865. function(_dereq_, module, exports) {
  22866. var id = 0;
  22867. var postfix = Math.random();
  22868. module.exports = function(key) {
  22869. return (
  22870. 'Symbol(' +
  22871. String(key === undefined ? '' : key) +
  22872. ')_' +
  22873. (++id + postfix).toString(36)
  22874. );
  22875. };
  22876. },
  22877. {}
  22878. ],
  22879. 161: [
  22880. function(_dereq_, module, exports) {
  22881. var NATIVE_SYMBOL = _dereq_('../internals/native-symbol');
  22882. module.exports =
  22883. NATIVE_SYMBOL &&
  22884. // eslint-disable-next-line no-undef
  22885. !Symbol.sham &&
  22886. // eslint-disable-next-line no-undef
  22887. typeof Symbol.iterator == 'symbol';
  22888. },
  22889. { '../internals/native-symbol': 100 }
  22890. ],
  22891. 162: [
  22892. function(_dereq_, module, exports) {
  22893. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  22894. exports.f = wellKnownSymbol;
  22895. },
  22896. { '../internals/well-known-symbol': 163 }
  22897. ],
  22898. 163: [
  22899. function(_dereq_, module, exports) {
  22900. var global = _dereq_('../internals/global');
  22901. var shared = _dereq_('../internals/shared');
  22902. var has = _dereq_('../internals/has');
  22903. var uid = _dereq_('../internals/uid');
  22904. var NATIVE_SYMBOL = _dereq_('../internals/native-symbol');
  22905. var USE_SYMBOL_AS_UID = _dereq_('../internals/use-symbol-as-uid');
  22906. var WellKnownSymbolsStore = shared('wks');
  22907. var Symbol = global.Symbol;
  22908. var createWellKnownSymbol = USE_SYMBOL_AS_UID
  22909. ? Symbol
  22910. : (Symbol && Symbol.withoutSetter) || uid;
  22911. module.exports = function(name) {
  22912. if (!has(WellKnownSymbolsStore, name)) {
  22913. if (NATIVE_SYMBOL && has(Symbol, name))
  22914. WellKnownSymbolsStore[name] = Symbol[name];
  22915. else WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name);
  22916. }
  22917. return WellKnownSymbolsStore[name];
  22918. };
  22919. },
  22920. {
  22921. '../internals/global': 76,
  22922. '../internals/has': 77,
  22923. '../internals/native-symbol': 100,
  22924. '../internals/shared': 137,
  22925. '../internals/uid': 160,
  22926. '../internals/use-symbol-as-uid': 161
  22927. }
  22928. ],
  22929. 164: [
  22930. function(_dereq_, module, exports) {
  22931. // a string of all valid unicode whitespaces
  22932. // eslint-disable-next-line max-len
  22933. module.exports =
  22934. '\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF';
  22935. },
  22936. {}
  22937. ],
  22938. 165: [
  22939. function(_dereq_, module, exports) {
  22940. 'use strict';
  22941. var $ = _dereq_('../internals/export');
  22942. var global = _dereq_('../internals/global');
  22943. var arrayBufferModule = _dereq_('../internals/array-buffer');
  22944. var setSpecies = _dereq_('../internals/set-species');
  22945. var ARRAY_BUFFER = 'ArrayBuffer';
  22946. var ArrayBuffer = arrayBufferModule[ARRAY_BUFFER];
  22947. var NativeArrayBuffer = global[ARRAY_BUFFER];
  22948. // `ArrayBuffer` constructor
  22949. // https://tc39.github.io/ecma262/#sec-arraybuffer-constructor
  22950. $(
  22951. { global: true, forced: NativeArrayBuffer !== ArrayBuffer },
  22952. {
  22953. ArrayBuffer: ArrayBuffer
  22954. }
  22955. );
  22956. setSpecies(ARRAY_BUFFER);
  22957. },
  22958. {
  22959. '../internals/array-buffer': 31,
  22960. '../internals/export': 67,
  22961. '../internals/global': 76,
  22962. '../internals/set-species': 133
  22963. }
  22964. ],
  22965. 166: [
  22966. function(_dereq_, module, exports) {
  22967. 'use strict';
  22968. var $ = _dereq_('../internals/export');
  22969. var fails = _dereq_('../internals/fails');
  22970. var isArray = _dereq_('../internals/is-array');
  22971. var isObject = _dereq_('../internals/is-object');
  22972. var toObject = _dereq_('../internals/to-object');
  22973. var toLength = _dereq_('../internals/to-length');
  22974. var createProperty = _dereq_('../internals/create-property');
  22975. var arraySpeciesCreate = _dereq_('../internals/array-species-create');
  22976. var arrayMethodHasSpeciesSupport = _dereq_(
  22977. '../internals/array-method-has-species-support'
  22978. );
  22979. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  22980. var V8_VERSION = _dereq_('../internals/engine-v8-version');
  22981. var IS_CONCAT_SPREADABLE = wellKnownSymbol('isConcatSpreadable');
  22982. var MAX_SAFE_INTEGER = 0x1fffffffffffff;
  22983. var MAXIMUM_ALLOWED_INDEX_EXCEEDED = 'Maximum allowed index exceeded';
  22984. // We can't use this feature detection in V8 since it causes
  22985. // deoptimization and serious performance degradation
  22986. // https://github.com/zloirock/core-js/issues/679
  22987. var IS_CONCAT_SPREADABLE_SUPPORT =
  22988. V8_VERSION >= 51 ||
  22989. !fails(function() {
  22990. var array = [];
  22991. array[IS_CONCAT_SPREADABLE] = false;
  22992. return array.concat()[0] !== array;
  22993. });
  22994. var SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('concat');
  22995. var isConcatSpreadable = function(O) {
  22996. if (!isObject(O)) return false;
  22997. var spreadable = O[IS_CONCAT_SPREADABLE];
  22998. return spreadable !== undefined ? !!spreadable : isArray(O);
  22999. };
  23000. var FORCED = !IS_CONCAT_SPREADABLE_SUPPORT || !SPECIES_SUPPORT;
  23001. // `Array.prototype.concat` method
  23002. // https://tc39.github.io/ecma262/#sec-array.prototype.concat
  23003. // with adding support of @@isConcatSpreadable and @@species
  23004. $(
  23005. { target: 'Array', proto: true, forced: FORCED },
  23006. {
  23007. concat: function concat(arg) {
  23008. // eslint-disable-line no-unused-vars
  23009. var O = toObject(this);
  23010. var A = arraySpeciesCreate(O, 0);
  23011. var n = 0;
  23012. var i, k, length, len, E;
  23013. for (i = -1, length = arguments.length; i < length; i++) {
  23014. E = i === -1 ? O : arguments[i];
  23015. if (isConcatSpreadable(E)) {
  23016. len = toLength(E.length);
  23017. if (n + len > MAX_SAFE_INTEGER)
  23018. throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED);
  23019. for (k = 0; k < len; k++, n++) if (k in E) createProperty(A, n, E[k]);
  23020. } else {
  23021. if (n >= MAX_SAFE_INTEGER)
  23022. throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED);
  23023. createProperty(A, n++, E);
  23024. }
  23025. }
  23026. A.length = n;
  23027. return A;
  23028. }
  23029. }
  23030. );
  23031. },
  23032. {
  23033. '../internals/array-method-has-species-support': 39,
  23034. '../internals/array-species-create': 43,
  23035. '../internals/create-property': 57,
  23036. '../internals/engine-v8-version': 65,
  23037. '../internals/export': 67,
  23038. '../internals/fails': 68,
  23039. '../internals/is-array': 89,
  23040. '../internals/is-object': 91,
  23041. '../internals/to-length': 151,
  23042. '../internals/to-object': 152,
  23043. '../internals/well-known-symbol': 163
  23044. }
  23045. ],
  23046. 167: [
  23047. function(_dereq_, module, exports) {
  23048. 'use strict';
  23049. var $ = _dereq_('../internals/export');
  23050. var $every = _dereq_('../internals/array-iteration').every;
  23051. var arrayMethodIsStrict = _dereq_('../internals/array-method-is-strict');
  23052. var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length');
  23053. var STRICT_METHOD = arrayMethodIsStrict('every');
  23054. var USES_TO_LENGTH = arrayMethodUsesToLength('every');
  23055. // `Array.prototype.every` method
  23056. // https://tc39.github.io/ecma262/#sec-array.prototype.every
  23057. $(
  23058. { target: 'Array', proto: true, forced: !STRICT_METHOD || !USES_TO_LENGTH },
  23059. {
  23060. every: function every(callbackfn /* , thisArg */) {
  23061. return $every(
  23062. this,
  23063. callbackfn,
  23064. arguments.length > 1 ? arguments[1] : undefined
  23065. );
  23066. }
  23067. }
  23068. );
  23069. },
  23070. {
  23071. '../internals/array-iteration': 37,
  23072. '../internals/array-method-is-strict': 40,
  23073. '../internals/array-method-uses-to-length': 41,
  23074. '../internals/export': 67
  23075. }
  23076. ],
  23077. 168: [
  23078. function(_dereq_, module, exports) {
  23079. var $ = _dereq_('../internals/export');
  23080. var fill = _dereq_('../internals/array-fill');
  23081. var addToUnscopables = _dereq_('../internals/add-to-unscopables');
  23082. // `Array.prototype.fill` method
  23083. // https://tc39.github.io/ecma262/#sec-array.prototype.fill
  23084. $(
  23085. { target: 'Array', proto: true },
  23086. {
  23087. fill: fill
  23088. }
  23089. );
  23090. // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
  23091. addToUnscopables('fill');
  23092. },
  23093. {
  23094. '../internals/add-to-unscopables': 25,
  23095. '../internals/array-fill': 33,
  23096. '../internals/export': 67
  23097. }
  23098. ],
  23099. 169: [
  23100. function(_dereq_, module, exports) {
  23101. 'use strict';
  23102. var $ = _dereq_('../internals/export');
  23103. var $filter = _dereq_('../internals/array-iteration').filter;
  23104. var arrayMethodHasSpeciesSupport = _dereq_(
  23105. '../internals/array-method-has-species-support'
  23106. );
  23107. var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length');
  23108. var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('filter');
  23109. // Edge 14- issue
  23110. var USES_TO_LENGTH = arrayMethodUsesToLength('filter');
  23111. // `Array.prototype.filter` method
  23112. // https://tc39.github.io/ecma262/#sec-array.prototype.filter
  23113. // with adding support of @@species
  23114. $(
  23115. {
  23116. target: 'Array',
  23117. proto: true,
  23118. forced: !HAS_SPECIES_SUPPORT || !USES_TO_LENGTH
  23119. },
  23120. {
  23121. filter: function filter(callbackfn /* , thisArg */) {
  23122. return $filter(
  23123. this,
  23124. callbackfn,
  23125. arguments.length > 1 ? arguments[1] : undefined
  23126. );
  23127. }
  23128. }
  23129. );
  23130. },
  23131. {
  23132. '../internals/array-iteration': 37,
  23133. '../internals/array-method-has-species-support': 39,
  23134. '../internals/array-method-uses-to-length': 41,
  23135. '../internals/export': 67
  23136. }
  23137. ],
  23138. 170: [
  23139. function(_dereq_, module, exports) {
  23140. 'use strict';
  23141. var $ = _dereq_('../internals/export');
  23142. var forEach = _dereq_('../internals/array-for-each');
  23143. // `Array.prototype.forEach` method
  23144. // https://tc39.github.io/ecma262/#sec-array.prototype.foreach
  23145. $(
  23146. { target: 'Array', proto: true, forced: [].forEach != forEach },
  23147. {
  23148. forEach: forEach
  23149. }
  23150. );
  23151. },
  23152. { '../internals/array-for-each': 34, '../internals/export': 67 }
  23153. ],
  23154. 171: [
  23155. function(_dereq_, module, exports) {
  23156. var $ = _dereq_('../internals/export');
  23157. var from = _dereq_('../internals/array-from');
  23158. var checkCorrectnessOfIteration = _dereq_(
  23159. '../internals/check-correctness-of-iteration'
  23160. );
  23161. var INCORRECT_ITERATION = !checkCorrectnessOfIteration(function(iterable) {
  23162. Array.from(iterable);
  23163. });
  23164. // `Array.from` method
  23165. // https://tc39.github.io/ecma262/#sec-array.from
  23166. $(
  23167. { target: 'Array', stat: true, forced: INCORRECT_ITERATION },
  23168. {
  23169. from: from
  23170. }
  23171. );
  23172. },
  23173. {
  23174. '../internals/array-from': 35,
  23175. '../internals/check-correctness-of-iteration': 45,
  23176. '../internals/export': 67
  23177. }
  23178. ],
  23179. 172: [
  23180. function(_dereq_, module, exports) {
  23181. 'use strict';
  23182. var $ = _dereq_('../internals/export');
  23183. var $includes = _dereq_('../internals/array-includes').includes;
  23184. var addToUnscopables = _dereq_('../internals/add-to-unscopables');
  23185. var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length');
  23186. var USES_TO_LENGTH = arrayMethodUsesToLength('indexOf', {
  23187. ACCESSORS: true,
  23188. 1: 0
  23189. });
  23190. // `Array.prototype.includes` method
  23191. // https://tc39.github.io/ecma262/#sec-array.prototype.includes
  23192. $(
  23193. { target: 'Array', proto: true, forced: !USES_TO_LENGTH },
  23194. {
  23195. includes: function includes(el /* , fromIndex = 0 */) {
  23196. return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
  23197. }
  23198. }
  23199. );
  23200. // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
  23201. addToUnscopables('includes');
  23202. },
  23203. {
  23204. '../internals/add-to-unscopables': 25,
  23205. '../internals/array-includes': 36,
  23206. '../internals/array-method-uses-to-length': 41,
  23207. '../internals/export': 67
  23208. }
  23209. ],
  23210. 173: [
  23211. function(_dereq_, module, exports) {
  23212. 'use strict';
  23213. var $ = _dereq_('../internals/export');
  23214. var $indexOf = _dereq_('../internals/array-includes').indexOf;
  23215. var arrayMethodIsStrict = _dereq_('../internals/array-method-is-strict');
  23216. var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length');
  23217. var nativeIndexOf = [].indexOf;
  23218. var NEGATIVE_ZERO = !!nativeIndexOf && 1 / [1].indexOf(1, -0) < 0;
  23219. var STRICT_METHOD = arrayMethodIsStrict('indexOf');
  23220. var USES_TO_LENGTH = arrayMethodUsesToLength('indexOf', {
  23221. ACCESSORS: true,
  23222. 1: 0
  23223. });
  23224. // `Array.prototype.indexOf` method
  23225. // https://tc39.github.io/ecma262/#sec-array.prototype.indexof
  23226. $(
  23227. {
  23228. target: 'Array',
  23229. proto: true,
  23230. forced: NEGATIVE_ZERO || !STRICT_METHOD || !USES_TO_LENGTH
  23231. },
  23232. {
  23233. indexOf: function indexOf(searchElement /* , fromIndex = 0 */) {
  23234. return NEGATIVE_ZERO
  23235. ? // convert -0 to +0
  23236. nativeIndexOf.apply(this, arguments) || 0
  23237. : $indexOf(
  23238. this,
  23239. searchElement,
  23240. arguments.length > 1 ? arguments[1] : undefined
  23241. );
  23242. }
  23243. }
  23244. );
  23245. },
  23246. {
  23247. '../internals/array-includes': 36,
  23248. '../internals/array-method-is-strict': 40,
  23249. '../internals/array-method-uses-to-length': 41,
  23250. '../internals/export': 67
  23251. }
  23252. ],
  23253. 174: [
  23254. function(_dereq_, module, exports) {
  23255. 'use strict';
  23256. var toIndexedObject = _dereq_('../internals/to-indexed-object');
  23257. var addToUnscopables = _dereq_('../internals/add-to-unscopables');
  23258. var Iterators = _dereq_('../internals/iterators');
  23259. var InternalStateModule = _dereq_('../internals/internal-state');
  23260. var defineIterator = _dereq_('../internals/define-iterator');
  23261. var ARRAY_ITERATOR = 'Array Iterator';
  23262. var setInternalState = InternalStateModule.set;
  23263. var getInternalState = InternalStateModule.getterFor(ARRAY_ITERATOR);
  23264. // `Array.prototype.entries` method
  23265. // https://tc39.github.io/ecma262/#sec-array.prototype.entries
  23266. // `Array.prototype.keys` method
  23267. // https://tc39.github.io/ecma262/#sec-array.prototype.keys
  23268. // `Array.prototype.values` method
  23269. // https://tc39.github.io/ecma262/#sec-array.prototype.values
  23270. // `Array.prototype[@@iterator]` method
  23271. // https://tc39.github.io/ecma262/#sec-array.prototype-@@iterator
  23272. // `CreateArrayIterator` internal method
  23273. // https://tc39.github.io/ecma262/#sec-createarrayiterator
  23274. module.exports = defineIterator(
  23275. Array,
  23276. 'Array',
  23277. function(iterated, kind) {
  23278. setInternalState(this, {
  23279. type: ARRAY_ITERATOR,
  23280. target: toIndexedObject(iterated), // target
  23281. index: 0, // next index
  23282. kind: kind // kind
  23283. });
  23284. // `%ArrayIteratorPrototype%.next` method
  23285. // https://tc39.github.io/ecma262/#sec-%arrayiteratorprototype%.next
  23286. },
  23287. function() {
  23288. var state = getInternalState(this);
  23289. var target = state.target;
  23290. var kind = state.kind;
  23291. var index = state.index++;
  23292. if (!target || index >= target.length) {
  23293. state.target = undefined;
  23294. return { value: undefined, done: true };
  23295. }
  23296. if (kind == 'keys') return { value: index, done: false };
  23297. if (kind == 'values') return { value: target[index], done: false };
  23298. return { value: [index, target[index]], done: false };
  23299. },
  23300. 'values'
  23301. );
  23302. // argumentsList[@@iterator] is %ArrayProto_values%
  23303. // https://tc39.github.io/ecma262/#sec-createunmappedargumentsobject
  23304. // https://tc39.github.io/ecma262/#sec-createmappedargumentsobject
  23305. Iterators.Arguments = Iterators.Array;
  23306. // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
  23307. addToUnscopables('keys');
  23308. addToUnscopables('values');
  23309. addToUnscopables('entries');
  23310. },
  23311. {
  23312. '../internals/add-to-unscopables': 25,
  23313. '../internals/define-iterator': 58,
  23314. '../internals/internal-state': 87,
  23315. '../internals/iterators': 96,
  23316. '../internals/to-indexed-object': 149
  23317. }
  23318. ],
  23319. 175: [
  23320. function(_dereq_, module, exports) {
  23321. 'use strict';
  23322. var $ = _dereq_('../internals/export');
  23323. var IndexedObject = _dereq_('../internals/indexed-object');
  23324. var toIndexedObject = _dereq_('../internals/to-indexed-object');
  23325. var arrayMethodIsStrict = _dereq_('../internals/array-method-is-strict');
  23326. var nativeJoin = [].join;
  23327. var ES3_STRINGS = IndexedObject != Object;
  23328. var STRICT_METHOD = arrayMethodIsStrict('join', ',');
  23329. // `Array.prototype.join` method
  23330. // https://tc39.github.io/ecma262/#sec-array.prototype.join
  23331. $(
  23332. { target: 'Array', proto: true, forced: ES3_STRINGS || !STRICT_METHOD },
  23333. {
  23334. join: function join(separator) {
  23335. return nativeJoin.call(
  23336. toIndexedObject(this),
  23337. separator === undefined ? ',' : separator
  23338. );
  23339. }
  23340. }
  23341. );
  23342. },
  23343. {
  23344. '../internals/array-method-is-strict': 40,
  23345. '../internals/export': 67,
  23346. '../internals/indexed-object': 83,
  23347. '../internals/to-indexed-object': 149
  23348. }
  23349. ],
  23350. 176: [
  23351. function(_dereq_, module, exports) {
  23352. var $ = _dereq_('../internals/export');
  23353. var lastIndexOf = _dereq_('../internals/array-last-index-of');
  23354. // `Array.prototype.lastIndexOf` method
  23355. // https://tc39.github.io/ecma262/#sec-array.prototype.lastindexof
  23356. $(
  23357. { target: 'Array', proto: true, forced: lastIndexOf !== [].lastIndexOf },
  23358. {
  23359. lastIndexOf: lastIndexOf
  23360. }
  23361. );
  23362. },
  23363. { '../internals/array-last-index-of': 38, '../internals/export': 67 }
  23364. ],
  23365. 177: [
  23366. function(_dereq_, module, exports) {
  23367. 'use strict';
  23368. var $ = _dereq_('../internals/export');
  23369. var $map = _dereq_('../internals/array-iteration').map;
  23370. var arrayMethodHasSpeciesSupport = _dereq_(
  23371. '../internals/array-method-has-species-support'
  23372. );
  23373. var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length');
  23374. var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('map');
  23375. // FF49- issue
  23376. var USES_TO_LENGTH = arrayMethodUsesToLength('map');
  23377. // `Array.prototype.map` method
  23378. // https://tc39.github.io/ecma262/#sec-array.prototype.map
  23379. // with adding support of @@species
  23380. $(
  23381. {
  23382. target: 'Array',
  23383. proto: true,
  23384. forced: !HAS_SPECIES_SUPPORT || !USES_TO_LENGTH
  23385. },
  23386. {
  23387. map: function map(callbackfn /* , thisArg */) {
  23388. return $map(
  23389. this,
  23390. callbackfn,
  23391. arguments.length > 1 ? arguments[1] : undefined
  23392. );
  23393. }
  23394. }
  23395. );
  23396. },
  23397. {
  23398. '../internals/array-iteration': 37,
  23399. '../internals/array-method-has-species-support': 39,
  23400. '../internals/array-method-uses-to-length': 41,
  23401. '../internals/export': 67
  23402. }
  23403. ],
  23404. 178: [
  23405. function(_dereq_, module, exports) {
  23406. 'use strict';
  23407. var $ = _dereq_('../internals/export');
  23408. var isObject = _dereq_('../internals/is-object');
  23409. var isArray = _dereq_('../internals/is-array');
  23410. var toAbsoluteIndex = _dereq_('../internals/to-absolute-index');
  23411. var toLength = _dereq_('../internals/to-length');
  23412. var toIndexedObject = _dereq_('../internals/to-indexed-object');
  23413. var createProperty = _dereq_('../internals/create-property');
  23414. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  23415. var arrayMethodHasSpeciesSupport = _dereq_(
  23416. '../internals/array-method-has-species-support'
  23417. );
  23418. var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length');
  23419. var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('slice');
  23420. var USES_TO_LENGTH = arrayMethodUsesToLength('slice', {
  23421. ACCESSORS: true,
  23422. 0: 0,
  23423. 1: 2
  23424. });
  23425. var SPECIES = wellKnownSymbol('species');
  23426. var nativeSlice = [].slice;
  23427. var max = Math.max;
  23428. // `Array.prototype.slice` method
  23429. // https://tc39.github.io/ecma262/#sec-array.prototype.slice
  23430. // fallback for not array-like ES3 strings and DOM objects
  23431. $(
  23432. {
  23433. target: 'Array',
  23434. proto: true,
  23435. forced: !HAS_SPECIES_SUPPORT || !USES_TO_LENGTH
  23436. },
  23437. {
  23438. slice: function slice(start, end) {
  23439. var O = toIndexedObject(this);
  23440. var length = toLength(O.length);
  23441. var k = toAbsoluteIndex(start, length);
  23442. var fin = toAbsoluteIndex(end === undefined ? length : end, length);
  23443. // inline `ArraySpeciesCreate` for usage native `Array#slice` where it's possible
  23444. var Constructor, result, n;
  23445. if (isArray(O)) {
  23446. Constructor = O.constructor;
  23447. // cross-realm fallback
  23448. if (
  23449. typeof Constructor == 'function' &&
  23450. (Constructor === Array || isArray(Constructor.prototype))
  23451. ) {
  23452. Constructor = undefined;
  23453. } else if (isObject(Constructor)) {
  23454. Constructor = Constructor[SPECIES];
  23455. if (Constructor === null) Constructor = undefined;
  23456. }
  23457. if (Constructor === Array || Constructor === undefined) {
  23458. return nativeSlice.call(O, k, fin);
  23459. }
  23460. }
  23461. result = new (Constructor === undefined ? Array : Constructor)(
  23462. max(fin - k, 0)
  23463. );
  23464. for (n = 0; k < fin; k++, n++) if (k in O) createProperty(result, n, O[k]);
  23465. result.length = n;
  23466. return result;
  23467. }
  23468. }
  23469. );
  23470. },
  23471. {
  23472. '../internals/array-method-has-species-support': 39,
  23473. '../internals/array-method-uses-to-length': 41,
  23474. '../internals/create-property': 57,
  23475. '../internals/export': 67,
  23476. '../internals/is-array': 89,
  23477. '../internals/is-object': 91,
  23478. '../internals/to-absolute-index': 147,
  23479. '../internals/to-indexed-object': 149,
  23480. '../internals/to-length': 151,
  23481. '../internals/well-known-symbol': 163
  23482. }
  23483. ],
  23484. 179: [
  23485. function(_dereq_, module, exports) {
  23486. 'use strict';
  23487. var $ = _dereq_('../internals/export');
  23488. var $some = _dereq_('../internals/array-iteration').some;
  23489. var arrayMethodIsStrict = _dereq_('../internals/array-method-is-strict');
  23490. var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length');
  23491. var STRICT_METHOD = arrayMethodIsStrict('some');
  23492. var USES_TO_LENGTH = arrayMethodUsesToLength('some');
  23493. // `Array.prototype.some` method
  23494. // https://tc39.github.io/ecma262/#sec-array.prototype.some
  23495. $(
  23496. { target: 'Array', proto: true, forced: !STRICT_METHOD || !USES_TO_LENGTH },
  23497. {
  23498. some: function some(callbackfn /* , thisArg */) {
  23499. return $some(
  23500. this,
  23501. callbackfn,
  23502. arguments.length > 1 ? arguments[1] : undefined
  23503. );
  23504. }
  23505. }
  23506. );
  23507. },
  23508. {
  23509. '../internals/array-iteration': 37,
  23510. '../internals/array-method-is-strict': 40,
  23511. '../internals/array-method-uses-to-length': 41,
  23512. '../internals/export': 67
  23513. }
  23514. ],
  23515. 180: [
  23516. function(_dereq_, module, exports) {
  23517. 'use strict';
  23518. var $ = _dereq_('../internals/export');
  23519. var toAbsoluteIndex = _dereq_('../internals/to-absolute-index');
  23520. var toInteger = _dereq_('../internals/to-integer');
  23521. var toLength = _dereq_('../internals/to-length');
  23522. var toObject = _dereq_('../internals/to-object');
  23523. var arraySpeciesCreate = _dereq_('../internals/array-species-create');
  23524. var createProperty = _dereq_('../internals/create-property');
  23525. var arrayMethodHasSpeciesSupport = _dereq_(
  23526. '../internals/array-method-has-species-support'
  23527. );
  23528. var arrayMethodUsesToLength = _dereq_('../internals/array-method-uses-to-length');
  23529. var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('splice');
  23530. var USES_TO_LENGTH = arrayMethodUsesToLength('splice', {
  23531. ACCESSORS: true,
  23532. 0: 0,
  23533. 1: 2
  23534. });
  23535. var max = Math.max;
  23536. var min = Math.min;
  23537. var MAX_SAFE_INTEGER = 0x1fffffffffffff;
  23538. var MAXIMUM_ALLOWED_LENGTH_EXCEEDED = 'Maximum allowed length exceeded';
  23539. // `Array.prototype.splice` method
  23540. // https://tc39.github.io/ecma262/#sec-array.prototype.splice
  23541. // with adding support of @@species
  23542. $(
  23543. {
  23544. target: 'Array',
  23545. proto: true,
  23546. forced: !HAS_SPECIES_SUPPORT || !USES_TO_LENGTH
  23547. },
  23548. {
  23549. splice: function splice(start, deleteCount /* , ...items */) {
  23550. var O = toObject(this);
  23551. var len = toLength(O.length);
  23552. var actualStart = toAbsoluteIndex(start, len);
  23553. var argumentsLength = arguments.length;
  23554. var insertCount, actualDeleteCount, A, k, from, to;
  23555. if (argumentsLength === 0) {
  23556. insertCount = actualDeleteCount = 0;
  23557. } else if (argumentsLength === 1) {
  23558. insertCount = 0;
  23559. actualDeleteCount = len - actualStart;
  23560. } else {
  23561. insertCount = argumentsLength - 2;
  23562. actualDeleteCount = min(
  23563. max(toInteger(deleteCount), 0),
  23564. len - actualStart
  23565. );
  23566. }
  23567. if (len + insertCount - actualDeleteCount > MAX_SAFE_INTEGER) {
  23568. throw TypeError(MAXIMUM_ALLOWED_LENGTH_EXCEEDED);
  23569. }
  23570. A = arraySpeciesCreate(O, actualDeleteCount);
  23571. for (k = 0; k < actualDeleteCount; k++) {
  23572. from = actualStart + k;
  23573. if (from in O) createProperty(A, k, O[from]);
  23574. }
  23575. A.length = actualDeleteCount;
  23576. if (insertCount < actualDeleteCount) {
  23577. for (k = actualStart; k < len - actualDeleteCount; k++) {
  23578. from = k + actualDeleteCount;
  23579. to = k + insertCount;
  23580. if (from in O) O[to] = O[from];
  23581. else delete O[to];
  23582. }
  23583. for (k = len; k > len - actualDeleteCount + insertCount; k--)
  23584. delete O[k - 1];
  23585. } else if (insertCount > actualDeleteCount) {
  23586. for (k = len - actualDeleteCount; k > actualStart; k--) {
  23587. from = k + actualDeleteCount - 1;
  23588. to = k + insertCount - 1;
  23589. if (from in O) O[to] = O[from];
  23590. else delete O[to];
  23591. }
  23592. }
  23593. for (k = 0; k < insertCount; k++) {
  23594. O[k + actualStart] = arguments[k + 2];
  23595. }
  23596. O.length = len - actualDeleteCount + insertCount;
  23597. return A;
  23598. }
  23599. }
  23600. );
  23601. },
  23602. {
  23603. '../internals/array-method-has-species-support': 39,
  23604. '../internals/array-method-uses-to-length': 41,
  23605. '../internals/array-species-create': 43,
  23606. '../internals/create-property': 57,
  23607. '../internals/export': 67,
  23608. '../internals/to-absolute-index': 147,
  23609. '../internals/to-integer': 150,
  23610. '../internals/to-length': 151,
  23611. '../internals/to-object': 152
  23612. }
  23613. ],
  23614. 181: [
  23615. function(_dereq_, module, exports) {
  23616. var DESCRIPTORS = _dereq_('../internals/descriptors');
  23617. var defineProperty = _dereq_('../internals/object-define-property').f;
  23618. var FunctionPrototype = Function.prototype;
  23619. var FunctionPrototypeToString = FunctionPrototype.toString;
  23620. var nameRE = /^\s*function ([^ (]*)/;
  23621. var NAME = 'name';
  23622. // Function instances `.name` property
  23623. // https://tc39.github.io/ecma262/#sec-function-instances-name
  23624. if (DESCRIPTORS && !(NAME in FunctionPrototype)) {
  23625. defineProperty(FunctionPrototype, NAME, {
  23626. configurable: true,
  23627. get: function() {
  23628. try {
  23629. return FunctionPrototypeToString.call(this).match(nameRE)[1];
  23630. } catch (error) {
  23631. return '';
  23632. }
  23633. }
  23634. });
  23635. }
  23636. },
  23637. { '../internals/descriptors': 60, '../internals/object-define-property': 109 }
  23638. ],
  23639. 182: [
  23640. function(_dereq_, module, exports) {
  23641. 'use strict';
  23642. var collection = _dereq_('../internals/collection');
  23643. var collectionStrong = _dereq_('../internals/collection-strong');
  23644. // `Map` constructor
  23645. // https://tc39.github.io/ecma262/#sec-map-objects
  23646. module.exports = collection(
  23647. 'Map',
  23648. function(init) {
  23649. return function Map() {
  23650. return init(this, arguments.length ? arguments[0] : undefined);
  23651. };
  23652. },
  23653. collectionStrong
  23654. );
  23655. },
  23656. { '../internals/collection': 49, '../internals/collection-strong': 48 }
  23657. ],
  23658. 183: [
  23659. function(_dereq_, module, exports) {
  23660. var $ = _dereq_('../internals/export');
  23661. var $hypot = Math.hypot;
  23662. var abs = Math.abs;
  23663. var sqrt = Math.sqrt;
  23664. // Chrome 77 bug
  23665. // https://bugs.chromium.org/p/v8/issues/detail?id=9546
  23666. var BUGGY = !!$hypot && $hypot(Infinity, NaN) !== Infinity;
  23667. // `Math.hypot` method
  23668. // https://tc39.github.io/ecma262/#sec-math.hypot
  23669. $(
  23670. { target: 'Math', stat: true, forced: BUGGY },
  23671. {
  23672. hypot: function hypot(value1, value2) {
  23673. // eslint-disable-line no-unused-vars
  23674. var sum = 0;
  23675. var i = 0;
  23676. var aLen = arguments.length;
  23677. var larg = 0;
  23678. var arg, div;
  23679. while (i < aLen) {
  23680. arg = abs(arguments[i++]);
  23681. if (larg < arg) {
  23682. div = larg / arg;
  23683. sum = sum * div * div + 1;
  23684. larg = arg;
  23685. } else if (arg > 0) {
  23686. div = arg / larg;
  23687. sum += div * div;
  23688. } else sum += arg;
  23689. }
  23690. return larg === Infinity ? Infinity : larg * sqrt(sum);
  23691. }
  23692. }
  23693. );
  23694. },
  23695. { '../internals/export': 67 }
  23696. ],
  23697. 184: [
  23698. function(_dereq_, module, exports) {
  23699. var $ = _dereq_('../internals/export');
  23700. var sign = _dereq_('../internals/math-sign');
  23701. // `Math.sign` method
  23702. // https://tc39.github.io/ecma262/#sec-math.sign
  23703. $(
  23704. { target: 'Math', stat: true },
  23705. {
  23706. sign: sign
  23707. }
  23708. );
  23709. },
  23710. { '../internals/export': 67, '../internals/math-sign': 97 }
  23711. ],
  23712. 185: [
  23713. function(_dereq_, module, exports) {
  23714. 'use strict';
  23715. var DESCRIPTORS = _dereq_('../internals/descriptors');
  23716. var global = _dereq_('../internals/global');
  23717. var isForced = _dereq_('../internals/is-forced');
  23718. var redefine = _dereq_('../internals/redefine');
  23719. var has = _dereq_('../internals/has');
  23720. var classof = _dereq_('../internals/classof-raw');
  23721. var inheritIfRequired = _dereq_('../internals/inherit-if-required');
  23722. var toPrimitive = _dereq_('../internals/to-primitive');
  23723. var fails = _dereq_('../internals/fails');
  23724. var create = _dereq_('../internals/object-create');
  23725. var getOwnPropertyNames = _dereq_('../internals/object-get-own-property-names').f;
  23726. var getOwnPropertyDescriptor = _dereq_(
  23727. '../internals/object-get-own-property-descriptor'
  23728. ).f;
  23729. var defineProperty = _dereq_('../internals/object-define-property').f;
  23730. var trim = _dereq_('../internals/string-trim').trim;
  23731. var NUMBER = 'Number';
  23732. var NativeNumber = global[NUMBER];
  23733. var NumberPrototype = NativeNumber.prototype;
  23734. // Opera ~12 has broken Object#toString
  23735. var BROKEN_CLASSOF = classof(create(NumberPrototype)) == NUMBER;
  23736. // `ToNumber` abstract operation
  23737. // https://tc39.github.io/ecma262/#sec-tonumber
  23738. var toNumber = function(argument) {
  23739. var it = toPrimitive(argument, false);
  23740. var first, third, radix, maxCode, digits, length, index, code;
  23741. if (typeof it == 'string' && it.length > 2) {
  23742. it = trim(it);
  23743. first = it.charCodeAt(0);
  23744. if (first === 43 || first === 45) {
  23745. third = it.charCodeAt(2);
  23746. if (third === 88 || third === 120) return NaN; // Number('+0x1') should be NaN, old V8 fix
  23747. } else if (first === 48) {
  23748. switch (it.charCodeAt(1)) {
  23749. case 66:
  23750. case 98:
  23751. radix = 2;
  23752. maxCode = 49;
  23753. break; // fast equal of /^0b[01]+$/i
  23754. case 79:
  23755. case 111:
  23756. radix = 8;
  23757. maxCode = 55;
  23758. break; // fast equal of /^0o[0-7]+$/i
  23759. default:
  23760. return +it;
  23761. }
  23762. digits = it.slice(2);
  23763. length = digits.length;
  23764. for (index = 0; index < length; index++) {
  23765. code = digits.charCodeAt(index);
  23766. // parseInt parses a string to a first unavailable symbol
  23767. // but ToNumber should return NaN if a string contains unavailable symbols
  23768. if (code < 48 || code > maxCode) return NaN;
  23769. }
  23770. return parseInt(digits, radix);
  23771. }
  23772. }
  23773. return +it;
  23774. };
  23775. // `Number` constructor
  23776. // https://tc39.github.io/ecma262/#sec-number-constructor
  23777. if (
  23778. isForced(
  23779. NUMBER,
  23780. !NativeNumber(' 0o1') || !NativeNumber('0b1') || NativeNumber('+0x1')
  23781. )
  23782. ) {
  23783. var NumberWrapper = function Number(value) {
  23784. var it = arguments.length < 1 ? 0 : value;
  23785. var dummy = this;
  23786. return dummy instanceof NumberWrapper &&
  23787. // check on 1..constructor(foo) case
  23788. (BROKEN_CLASSOF
  23789. ? fails(function() {
  23790. NumberPrototype.valueOf.call(dummy);
  23791. })
  23792. : classof(dummy) != NUMBER)
  23793. ? inheritIfRequired(new NativeNumber(toNumber(it)), dummy, NumberWrapper)
  23794. : toNumber(it);
  23795. };
  23796. for (
  23797. var keys = DESCRIPTORS
  23798. ? getOwnPropertyNames(NativeNumber)
  23799. : // ES3:
  23800. (
  23801. 'MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,' +
  23802. // ES2015 (in case, if modules with ES2015 Number statics required before):
  23803. 'EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,' +
  23804. 'MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger'
  23805. ).split(','),
  23806. j = 0,
  23807. key;
  23808. keys.length > j;
  23809. j++
  23810. ) {
  23811. if (has(NativeNumber, (key = keys[j])) && !has(NumberWrapper, key)) {
  23812. defineProperty(
  23813. NumberWrapper,
  23814. key,
  23815. getOwnPropertyDescriptor(NativeNumber, key)
  23816. );
  23817. }
  23818. }
  23819. NumberWrapper.prototype = NumberPrototype;
  23820. NumberPrototype.constructor = NumberWrapper;
  23821. redefine(global, NUMBER, NumberWrapper);
  23822. }
  23823. },
  23824. {
  23825. '../internals/classof-raw': 46,
  23826. '../internals/descriptors': 60,
  23827. '../internals/fails': 68,
  23828. '../internals/global': 76,
  23829. '../internals/has': 77,
  23830. '../internals/inherit-if-required': 84,
  23831. '../internals/is-forced': 90,
  23832. '../internals/object-create': 107,
  23833. '../internals/object-define-property': 109,
  23834. '../internals/object-get-own-property-descriptor': 110,
  23835. '../internals/object-get-own-property-names': 112,
  23836. '../internals/redefine': 125,
  23837. '../internals/string-trim': 144,
  23838. '../internals/to-primitive': 155
  23839. }
  23840. ],
  23841. 186: [
  23842. function(_dereq_, module, exports) {
  23843. var $ = _dereq_('../internals/export');
  23844. var numberIsFinite = _dereq_('../internals/number-is-finite');
  23845. // `Number.isFinite` method
  23846. // https://tc39.github.io/ecma262/#sec-number.isfinite
  23847. $({ target: 'Number', stat: true }, { isFinite: numberIsFinite });
  23848. },
  23849. { '../internals/export': 67, '../internals/number-is-finite': 105 }
  23850. ],
  23851. 187: [
  23852. function(_dereq_, module, exports) {
  23853. 'use strict';
  23854. var $ = _dereq_('../internals/export');
  23855. var toInteger = _dereq_('../internals/to-integer');
  23856. var thisNumberValue = _dereq_('../internals/this-number-value');
  23857. var repeat = _dereq_('../internals/string-repeat');
  23858. var fails = _dereq_('../internals/fails');
  23859. var nativeToFixed = (1.0).toFixed;
  23860. var floor = Math.floor;
  23861. var pow = function(x, n, acc) {
  23862. return n === 0
  23863. ? acc
  23864. : n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc);
  23865. };
  23866. var log = function(x) {
  23867. var n = 0;
  23868. var x2 = x;
  23869. while (x2 >= 4096) {
  23870. n += 12;
  23871. x2 /= 4096;
  23872. }
  23873. while (x2 >= 2) {
  23874. n += 1;
  23875. x2 /= 2;
  23876. }
  23877. return n;
  23878. };
  23879. var FORCED =
  23880. (nativeToFixed &&
  23881. ((0.00008).toFixed(3) !== '0.000' ||
  23882. (0.9).toFixed(0) !== '1' ||
  23883. (1.255).toFixed(2) !== '1.25' ||
  23884. (1000000000000000128.0).toFixed(0) !== '1000000000000000128')) ||
  23885. !fails(function() {
  23886. // V8 ~ Android 4.3-
  23887. nativeToFixed.call({});
  23888. });
  23889. // `Number.prototype.toFixed` method
  23890. // https://tc39.github.io/ecma262/#sec-number.prototype.tofixed
  23891. $(
  23892. { target: 'Number', proto: true, forced: FORCED },
  23893. {
  23894. // eslint-disable-next-line max-statements
  23895. toFixed: function toFixed(fractionDigits) {
  23896. var number = thisNumberValue(this);
  23897. var fractDigits = toInteger(fractionDigits);
  23898. var data = [0, 0, 0, 0, 0, 0];
  23899. var sign = '';
  23900. var result = '0';
  23901. var e, z, j, k;
  23902. var multiply = function(n, c) {
  23903. var index = -1;
  23904. var c2 = c;
  23905. while (++index < 6) {
  23906. c2 += n * data[index];
  23907. data[index] = c2 % 1e7;
  23908. c2 = floor(c2 / 1e7);
  23909. }
  23910. };
  23911. var divide = function(n) {
  23912. var index = 6;
  23913. var c = 0;
  23914. while (--index >= 0) {
  23915. c += data[index];
  23916. data[index] = floor(c / n);
  23917. c = (c % n) * 1e7;
  23918. }
  23919. };
  23920. var dataToString = function() {
  23921. var index = 6;
  23922. var s = '';
  23923. while (--index >= 0) {
  23924. if (s !== '' || index === 0 || data[index] !== 0) {
  23925. var t = String(data[index]);
  23926. s = s === '' ? t : s + repeat.call('0', 7 - t.length) + t;
  23927. }
  23928. }
  23929. return s;
  23930. };
  23931. if (fractDigits < 0 || fractDigits > 20)
  23932. throw RangeError('Incorrect fraction digits');
  23933. // eslint-disable-next-line no-self-compare
  23934. if (number != number) return 'NaN';
  23935. if (number <= -1e21 || number >= 1e21) return String(number);
  23936. if (number < 0) {
  23937. sign = '-';
  23938. number = -number;
  23939. }
  23940. if (number > 1e-21) {
  23941. e = log(number * pow(2, 69, 1)) - 69;
  23942. z = e < 0 ? number * pow(2, -e, 1) : number / pow(2, e, 1);
  23943. z *= 0x10000000000000;
  23944. e = 52 - e;
  23945. if (e > 0) {
  23946. multiply(0, z);
  23947. j = fractDigits;
  23948. while (j >= 7) {
  23949. multiply(1e7, 0);
  23950. j -= 7;
  23951. }
  23952. multiply(pow(10, j, 1), 0);
  23953. j = e - 1;
  23954. while (j >= 23) {
  23955. divide(1 << 23);
  23956. j -= 23;
  23957. }
  23958. divide(1 << j);
  23959. multiply(1, 1);
  23960. divide(2);
  23961. result = dataToString();
  23962. } else {
  23963. multiply(0, z);
  23964. multiply(1 << -e, 0);
  23965. result = dataToString() + repeat.call('0', fractDigits);
  23966. }
  23967. }
  23968. if (fractDigits > 0) {
  23969. k = result.length;
  23970. result =
  23971. sign +
  23972. (k <= fractDigits
  23973. ? '0.' + repeat.call('0', fractDigits - k) + result
  23974. : result.slice(0, k - fractDigits) +
  23975. '.' +
  23976. result.slice(k - fractDigits));
  23977. } else {
  23978. result = sign + result;
  23979. }
  23980. return result;
  23981. }
  23982. }
  23983. );
  23984. },
  23985. {
  23986. '../internals/export': 67,
  23987. '../internals/fails': 68,
  23988. '../internals/string-repeat': 142,
  23989. '../internals/this-number-value': 146,
  23990. '../internals/to-integer': 150
  23991. }
  23992. ],
  23993. 188: [
  23994. function(_dereq_, module, exports) {
  23995. var $ = _dereq_('../internals/export');
  23996. var assign = _dereq_('../internals/object-assign');
  23997. // `Object.assign` method
  23998. // https://tc39.github.io/ecma262/#sec-object.assign
  23999. $(
  24000. { target: 'Object', stat: true, forced: Object.assign !== assign },
  24001. {
  24002. assign: assign
  24003. }
  24004. );
  24005. },
  24006. { '../internals/export': 67, '../internals/object-assign': 106 }
  24007. ],
  24008. 189: [
  24009. function(_dereq_, module, exports) {
  24010. var $ = _dereq_('../internals/export');
  24011. var fails = _dereq_('../internals/fails');
  24012. var nativeGetOwnPropertyNames = _dereq_(
  24013. '../internals/object-get-own-property-names-external'
  24014. ).f;
  24015. var FAILS_ON_PRIMITIVES = fails(function() {
  24016. return !Object.getOwnPropertyNames(1);
  24017. });
  24018. // `Object.getOwnPropertyNames` method
  24019. // https://tc39.github.io/ecma262/#sec-object.getownpropertynames
  24020. $(
  24021. { target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES },
  24022. {
  24023. getOwnPropertyNames: nativeGetOwnPropertyNames
  24024. }
  24025. );
  24026. },
  24027. {
  24028. '../internals/export': 67,
  24029. '../internals/fails': 68,
  24030. '../internals/object-get-own-property-names-external': 111
  24031. }
  24032. ],
  24033. 190: [
  24034. function(_dereq_, module, exports) {
  24035. var $ = _dereq_('../internals/export');
  24036. var fails = _dereq_('../internals/fails');
  24037. var toObject = _dereq_('../internals/to-object');
  24038. var nativeGetPrototypeOf = _dereq_('../internals/object-get-prototype-of');
  24039. var CORRECT_PROTOTYPE_GETTER = _dereq_('../internals/correct-prototype-getter');
  24040. var FAILS_ON_PRIMITIVES = fails(function() {
  24041. nativeGetPrototypeOf(1);
  24042. });
  24043. // `Object.getPrototypeOf` method
  24044. // https://tc39.github.io/ecma262/#sec-object.getprototypeof
  24045. $(
  24046. {
  24047. target: 'Object',
  24048. stat: true,
  24049. forced: FAILS_ON_PRIMITIVES,
  24050. sham: !CORRECT_PROTOTYPE_GETTER
  24051. },
  24052. {
  24053. getPrototypeOf: function getPrototypeOf(it) {
  24054. return nativeGetPrototypeOf(toObject(it));
  24055. }
  24056. }
  24057. );
  24058. },
  24059. {
  24060. '../internals/correct-prototype-getter': 52,
  24061. '../internals/export': 67,
  24062. '../internals/fails': 68,
  24063. '../internals/object-get-prototype-of': 114,
  24064. '../internals/to-object': 152
  24065. }
  24066. ],
  24067. 191: [
  24068. function(_dereq_, module, exports) {
  24069. var $ = _dereq_('../internals/export');
  24070. var toObject = _dereq_('../internals/to-object');
  24071. var nativeKeys = _dereq_('../internals/object-keys');
  24072. var fails = _dereq_('../internals/fails');
  24073. var FAILS_ON_PRIMITIVES = fails(function() {
  24074. nativeKeys(1);
  24075. });
  24076. // `Object.keys` method
  24077. // https://tc39.github.io/ecma262/#sec-object.keys
  24078. $(
  24079. { target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES },
  24080. {
  24081. keys: function keys(it) {
  24082. return nativeKeys(toObject(it));
  24083. }
  24084. }
  24085. );
  24086. },
  24087. {
  24088. '../internals/export': 67,
  24089. '../internals/fails': 68,
  24090. '../internals/object-keys': 116,
  24091. '../internals/to-object': 152
  24092. }
  24093. ],
  24094. 192: [
  24095. function(_dereq_, module, exports) {
  24096. var TO_STRING_TAG_SUPPORT = _dereq_('../internals/to-string-tag-support');
  24097. var redefine = _dereq_('../internals/redefine');
  24098. var toString = _dereq_('../internals/object-to-string');
  24099. // `Object.prototype.toString` method
  24100. // https://tc39.github.io/ecma262/#sec-object.prototype.tostring
  24101. if (!TO_STRING_TAG_SUPPORT) {
  24102. redefine(Object.prototype, 'toString', toString, { unsafe: true });
  24103. }
  24104. },
  24105. {
  24106. '../internals/object-to-string': 119,
  24107. '../internals/redefine': 125,
  24108. '../internals/to-string-tag-support': 156
  24109. }
  24110. ],
  24111. 193: [
  24112. function(_dereq_, module, exports) {
  24113. 'use strict';
  24114. var $ = _dereq_('../internals/export');
  24115. var IS_PURE = _dereq_('../internals/is-pure');
  24116. var global = _dereq_('../internals/global');
  24117. var getBuiltIn = _dereq_('../internals/get-built-in');
  24118. var NativePromise = _dereq_('../internals/native-promise-constructor');
  24119. var redefine = _dereq_('../internals/redefine');
  24120. var redefineAll = _dereq_('../internals/redefine-all');
  24121. var setToStringTag = _dereq_('../internals/set-to-string-tag');
  24122. var setSpecies = _dereq_('../internals/set-species');
  24123. var isObject = _dereq_('../internals/is-object');
  24124. var aFunction = _dereq_('../internals/a-function');
  24125. var anInstance = _dereq_('../internals/an-instance');
  24126. var classof = _dereq_('../internals/classof-raw');
  24127. var inspectSource = _dereq_('../internals/inspect-source');
  24128. var iterate = _dereq_('../internals/iterate');
  24129. var checkCorrectnessOfIteration = _dereq_(
  24130. '../internals/check-correctness-of-iteration'
  24131. );
  24132. var speciesConstructor = _dereq_('../internals/species-constructor');
  24133. var task = _dereq_('../internals/task').set;
  24134. var microtask = _dereq_('../internals/microtask');
  24135. var promiseResolve = _dereq_('../internals/promise-resolve');
  24136. var hostReportErrors = _dereq_('../internals/host-report-errors');
  24137. var newPromiseCapabilityModule = _dereq_('../internals/new-promise-capability');
  24138. var perform = _dereq_('../internals/perform');
  24139. var InternalStateModule = _dereq_('../internals/internal-state');
  24140. var isForced = _dereq_('../internals/is-forced');
  24141. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  24142. var V8_VERSION = _dereq_('../internals/engine-v8-version');
  24143. var SPECIES = wellKnownSymbol('species');
  24144. var PROMISE = 'Promise';
  24145. var getInternalState = InternalStateModule.get;
  24146. var setInternalState = InternalStateModule.set;
  24147. var getInternalPromiseState = InternalStateModule.getterFor(PROMISE);
  24148. var PromiseConstructor = NativePromise;
  24149. var TypeError = global.TypeError;
  24150. var document = global.document;
  24151. var process = global.process;
  24152. var $fetch = getBuiltIn('fetch');
  24153. var newPromiseCapability = newPromiseCapabilityModule.f;
  24154. var newGenericPromiseCapability = newPromiseCapability;
  24155. var IS_NODE = classof(process) == 'process';
  24156. var DISPATCH_EVENT = !!(document && document.createEvent && global.dispatchEvent);
  24157. var UNHANDLED_REJECTION = 'unhandledrejection';
  24158. var REJECTION_HANDLED = 'rejectionhandled';
  24159. var PENDING = 0;
  24160. var FULFILLED = 1;
  24161. var REJECTED = 2;
  24162. var HANDLED = 1;
  24163. var UNHANDLED = 2;
  24164. var Internal, OwnPromiseCapability, PromiseWrapper, nativeThen;
  24165. var FORCED = isForced(PROMISE, function() {
  24166. var GLOBAL_CORE_JS_PROMISE =
  24167. inspectSource(PromiseConstructor) !== String(PromiseConstructor);
  24168. if (!GLOBAL_CORE_JS_PROMISE) {
  24169. // V8 6.6 (Node 10 and Chrome 66) have a bug with resolving custom thenables
  24170. // https://bugs.chromium.org/p/chromium/issues/detail?id=830565
  24171. // We can't detect it synchronously, so just check versions
  24172. if (V8_VERSION === 66) return true;
  24173. // Unhandled rejections tracking support, NodeJS Promise without it fails @@species test
  24174. if (!IS_NODE && typeof PromiseRejectionEvent != 'function') return true;
  24175. }
  24176. // We need Promise#finally in the pure version for preventing prototype pollution
  24177. if (IS_PURE && !PromiseConstructor.prototype['finally']) return true;
  24178. // We can't use @@species feature detection in V8 since it causes
  24179. // deoptimization and performance degradation
  24180. // https://github.com/zloirock/core-js/issues/679
  24181. if (V8_VERSION >= 51 && /native code/.test(PromiseConstructor)) return false;
  24182. // Detect correctness of subclassing with @@species support
  24183. var promise = PromiseConstructor.resolve(1);
  24184. var FakePromise = function(exec) {
  24185. exec(
  24186. function() {
  24187. /* empty */
  24188. },
  24189. function() {
  24190. /* empty */
  24191. }
  24192. );
  24193. };
  24194. var constructor = (promise.constructor = {});
  24195. constructor[SPECIES] = FakePromise;
  24196. return !(
  24197. promise.then(function() {
  24198. /* empty */
  24199. }) instanceof FakePromise
  24200. );
  24201. });
  24202. var INCORRECT_ITERATION =
  24203. FORCED ||
  24204. !checkCorrectnessOfIteration(function(iterable) {
  24205. PromiseConstructor.all(iterable)['catch'](function() {
  24206. /* empty */
  24207. });
  24208. });
  24209. // helpers
  24210. var isThenable = function(it) {
  24211. var then;
  24212. return isObject(it) && typeof (then = it.then) == 'function' ? then : false;
  24213. };
  24214. var notify = function(promise, state, isReject) {
  24215. if (state.notified) return;
  24216. state.notified = true;
  24217. var chain = state.reactions;
  24218. microtask(function() {
  24219. var value = state.value;
  24220. var ok = state.state == FULFILLED;
  24221. var index = 0;
  24222. // variable length - can't use forEach
  24223. while (chain.length > index) {
  24224. var reaction = chain[index++];
  24225. var handler = ok ? reaction.ok : reaction.fail;
  24226. var resolve = reaction.resolve;
  24227. var reject = reaction.reject;
  24228. var domain = reaction.domain;
  24229. var result, then, exited;
  24230. try {
  24231. if (handler) {
  24232. if (!ok) {
  24233. if (state.rejection === UNHANDLED) onHandleUnhandled(promise, state);
  24234. state.rejection = HANDLED;
  24235. }
  24236. if (handler === true) result = value;
  24237. else {
  24238. if (domain) domain.enter();
  24239. result = handler(value); // can throw
  24240. if (domain) {
  24241. domain.exit();
  24242. exited = true;
  24243. }
  24244. }
  24245. if (result === reaction.promise) {
  24246. reject(TypeError('Promise-chain cycle'));
  24247. } else if ((then = isThenable(result))) {
  24248. then.call(result, resolve, reject);
  24249. } else resolve(result);
  24250. } else reject(value);
  24251. } catch (error) {
  24252. if (domain && !exited) domain.exit();
  24253. reject(error);
  24254. }
  24255. }
  24256. state.reactions = [];
  24257. state.notified = false;
  24258. if (isReject && !state.rejection) onUnhandled(promise, state);
  24259. });
  24260. };
  24261. var dispatchEvent = function(name, promise, reason) {
  24262. var event, handler;
  24263. if (DISPATCH_EVENT) {
  24264. event = document.createEvent('Event');
  24265. event.promise = promise;
  24266. event.reason = reason;
  24267. event.initEvent(name, false, true);
  24268. global.dispatchEvent(event);
  24269. } else event = { promise: promise, reason: reason };
  24270. if ((handler = global['on' + name])) handler(event);
  24271. else if (name === UNHANDLED_REJECTION)
  24272. hostReportErrors('Unhandled promise rejection', reason);
  24273. };
  24274. var onUnhandled = function(promise, state) {
  24275. task.call(global, function() {
  24276. var value = state.value;
  24277. var IS_UNHANDLED = isUnhandled(state);
  24278. var result;
  24279. if (IS_UNHANDLED) {
  24280. result = perform(function() {
  24281. if (IS_NODE) {
  24282. process.emit('unhandledRejection', value, promise);
  24283. } else dispatchEvent(UNHANDLED_REJECTION, promise, value);
  24284. });
  24285. // Browsers should not trigger `rejectionHandled` event if it was handled here, NodeJS - should
  24286. state.rejection = IS_NODE || isUnhandled(state) ? UNHANDLED : HANDLED;
  24287. if (result.error) throw result.value;
  24288. }
  24289. });
  24290. };
  24291. var isUnhandled = function(state) {
  24292. return state.rejection !== HANDLED && !state.parent;
  24293. };
  24294. var onHandleUnhandled = function(promise, state) {
  24295. task.call(global, function() {
  24296. if (IS_NODE) {
  24297. process.emit('rejectionHandled', promise);
  24298. } else dispatchEvent(REJECTION_HANDLED, promise, state.value);
  24299. });
  24300. };
  24301. var bind = function(fn, promise, state, unwrap) {
  24302. return function(value) {
  24303. fn(promise, state, value, unwrap);
  24304. };
  24305. };
  24306. var internalReject = function(promise, state, value, unwrap) {
  24307. if (state.done) return;
  24308. state.done = true;
  24309. if (unwrap) state = unwrap;
  24310. state.value = value;
  24311. state.state = REJECTED;
  24312. notify(promise, state, true);
  24313. };
  24314. var internalResolve = function(promise, state, value, unwrap) {
  24315. if (state.done) return;
  24316. state.done = true;
  24317. if (unwrap) state = unwrap;
  24318. try {
  24319. if (promise === value) throw TypeError("Promise can't be resolved itself");
  24320. var then = isThenable(value);
  24321. if (then) {
  24322. microtask(function() {
  24323. var wrapper = { done: false };
  24324. try {
  24325. then.call(
  24326. value,
  24327. bind(internalResolve, promise, wrapper, state),
  24328. bind(internalReject, promise, wrapper, state)
  24329. );
  24330. } catch (error) {
  24331. internalReject(promise, wrapper, error, state);
  24332. }
  24333. });
  24334. } else {
  24335. state.value = value;
  24336. state.state = FULFILLED;
  24337. notify(promise, state, false);
  24338. }
  24339. } catch (error) {
  24340. internalReject(promise, { done: false }, error, state);
  24341. }
  24342. };
  24343. // constructor polyfill
  24344. if (FORCED) {
  24345. // 25.4.3.1 Promise(executor)
  24346. PromiseConstructor = function Promise(executor) {
  24347. anInstance(this, PromiseConstructor, PROMISE);
  24348. aFunction(executor);
  24349. Internal.call(this);
  24350. var state = getInternalState(this);
  24351. try {
  24352. executor(
  24353. bind(internalResolve, this, state),
  24354. bind(internalReject, this, state)
  24355. );
  24356. } catch (error) {
  24357. internalReject(this, state, error);
  24358. }
  24359. };
  24360. // eslint-disable-next-line no-unused-vars
  24361. Internal = function Promise(executor) {
  24362. setInternalState(this, {
  24363. type: PROMISE,
  24364. done: false,
  24365. notified: false,
  24366. parent: false,
  24367. reactions: [],
  24368. rejection: false,
  24369. state: PENDING,
  24370. value: undefined
  24371. });
  24372. };
  24373. Internal.prototype = redefineAll(PromiseConstructor.prototype, {
  24374. // `Promise.prototype.then` method
  24375. // https://tc39.github.io/ecma262/#sec-promise.prototype.then
  24376. then: function then(onFulfilled, onRejected) {
  24377. var state = getInternalPromiseState(this);
  24378. var reaction = newPromiseCapability(
  24379. speciesConstructor(this, PromiseConstructor)
  24380. );
  24381. reaction.ok = typeof onFulfilled == 'function' ? onFulfilled : true;
  24382. reaction.fail = typeof onRejected == 'function' && onRejected;
  24383. reaction.domain = IS_NODE ? process.domain : undefined;
  24384. state.parent = true;
  24385. state.reactions.push(reaction);
  24386. if (state.state != PENDING) notify(this, state, false);
  24387. return reaction.promise;
  24388. },
  24389. // `Promise.prototype.catch` method
  24390. // https://tc39.github.io/ecma262/#sec-promise.prototype.catch
  24391. catch: function(onRejected) {
  24392. return this.then(undefined, onRejected);
  24393. }
  24394. });
  24395. OwnPromiseCapability = function() {
  24396. var promise = new Internal();
  24397. var state = getInternalState(promise);
  24398. this.promise = promise;
  24399. this.resolve = bind(internalResolve, promise, state);
  24400. this.reject = bind(internalReject, promise, state);
  24401. };
  24402. newPromiseCapabilityModule.f = newPromiseCapability = function(C) {
  24403. return C === PromiseConstructor || C === PromiseWrapper
  24404. ? new OwnPromiseCapability(C)
  24405. : newGenericPromiseCapability(C);
  24406. };
  24407. if (!IS_PURE && typeof NativePromise == 'function') {
  24408. nativeThen = NativePromise.prototype.then;
  24409. // wrap native Promise#then for native async functions
  24410. redefine(
  24411. NativePromise.prototype,
  24412. 'then',
  24413. function then(onFulfilled, onRejected) {
  24414. var that = this;
  24415. return new PromiseConstructor(function(resolve, reject) {
  24416. nativeThen.call(that, resolve, reject);
  24417. }).then(onFulfilled, onRejected);
  24418. // https://github.com/zloirock/core-js/issues/640
  24419. },
  24420. { unsafe: true }
  24421. );
  24422. // wrap fetch result
  24423. if (typeof $fetch == 'function')
  24424. $(
  24425. { global: true, enumerable: true, forced: true },
  24426. {
  24427. // eslint-disable-next-line no-unused-vars
  24428. fetch: function fetch(input /* , init */) {
  24429. return promiseResolve(
  24430. PromiseConstructor,
  24431. $fetch.apply(global, arguments)
  24432. );
  24433. }
  24434. }
  24435. );
  24436. }
  24437. }
  24438. $(
  24439. { global: true, wrap: true, forced: FORCED },
  24440. {
  24441. Promise: PromiseConstructor
  24442. }
  24443. );
  24444. setToStringTag(PromiseConstructor, PROMISE, false, true);
  24445. setSpecies(PROMISE);
  24446. PromiseWrapper = getBuiltIn(PROMISE);
  24447. // statics
  24448. $(
  24449. { target: PROMISE, stat: true, forced: FORCED },
  24450. {
  24451. // `Promise.reject` method
  24452. // https://tc39.github.io/ecma262/#sec-promise.reject
  24453. reject: function reject(r) {
  24454. var capability = newPromiseCapability(this);
  24455. capability.reject.call(undefined, r);
  24456. return capability.promise;
  24457. }
  24458. }
  24459. );
  24460. $(
  24461. { target: PROMISE, stat: true, forced: IS_PURE || FORCED },
  24462. {
  24463. // `Promise.resolve` method
  24464. // https://tc39.github.io/ecma262/#sec-promise.resolve
  24465. resolve: function resolve(x) {
  24466. return promiseResolve(
  24467. IS_PURE && this === PromiseWrapper ? PromiseConstructor : this,
  24468. x
  24469. );
  24470. }
  24471. }
  24472. );
  24473. $(
  24474. { target: PROMISE, stat: true, forced: INCORRECT_ITERATION },
  24475. {
  24476. // `Promise.all` method
  24477. // https://tc39.github.io/ecma262/#sec-promise.all
  24478. all: function all(iterable) {
  24479. var C = this;
  24480. var capability = newPromiseCapability(C);
  24481. var resolve = capability.resolve;
  24482. var reject = capability.reject;
  24483. var result = perform(function() {
  24484. var $promiseResolve = aFunction(C.resolve);
  24485. var values = [];
  24486. var counter = 0;
  24487. var remaining = 1;
  24488. iterate(iterable, function(promise) {
  24489. var index = counter++;
  24490. var alreadyCalled = false;
  24491. values.push(undefined);
  24492. remaining++;
  24493. $promiseResolve.call(C, promise).then(function(value) {
  24494. if (alreadyCalled) return;
  24495. alreadyCalled = true;
  24496. values[index] = value;
  24497. --remaining || resolve(values);
  24498. }, reject);
  24499. });
  24500. --remaining || resolve(values);
  24501. });
  24502. if (result.error) reject(result.value);
  24503. return capability.promise;
  24504. },
  24505. // `Promise.race` method
  24506. // https://tc39.github.io/ecma262/#sec-promise.race
  24507. race: function race(iterable) {
  24508. var C = this;
  24509. var capability = newPromiseCapability(C);
  24510. var reject = capability.reject;
  24511. var result = perform(function() {
  24512. var $promiseResolve = aFunction(C.resolve);
  24513. iterate(iterable, function(promise) {
  24514. $promiseResolve.call(C, promise).then(capability.resolve, reject);
  24515. });
  24516. });
  24517. if (result.error) reject(result.value);
  24518. return capability.promise;
  24519. }
  24520. }
  24521. );
  24522. },
  24523. {
  24524. '../internals/a-function': 23,
  24525. '../internals/an-instance': 27,
  24526. '../internals/check-correctness-of-iteration': 45,
  24527. '../internals/classof-raw': 46,
  24528. '../internals/engine-v8-version': 65,
  24529. '../internals/export': 67,
  24530. '../internals/get-built-in': 73,
  24531. '../internals/global': 76,
  24532. '../internals/host-report-errors': 79,
  24533. '../internals/inspect-source': 85,
  24534. '../internals/internal-state': 87,
  24535. '../internals/is-forced': 90,
  24536. '../internals/is-object': 91,
  24537. '../internals/is-pure': 92,
  24538. '../internals/iterate': 94,
  24539. '../internals/microtask': 98,
  24540. '../internals/native-promise-constructor': 99,
  24541. '../internals/new-promise-capability': 103,
  24542. '../internals/perform': 122,
  24543. '../internals/promise-resolve': 123,
  24544. '../internals/redefine': 125,
  24545. '../internals/redefine-all': 124,
  24546. '../internals/set-species': 133,
  24547. '../internals/set-to-string-tag': 134,
  24548. '../internals/species-constructor': 138,
  24549. '../internals/task': 145,
  24550. '../internals/well-known-symbol': 163
  24551. }
  24552. ],
  24553. 194: [
  24554. function(_dereq_, module, exports) {
  24555. var $ = _dereq_('../internals/export');
  24556. var getBuiltIn = _dereq_('../internals/get-built-in');
  24557. var aFunction = _dereq_('../internals/a-function');
  24558. var anObject = _dereq_('../internals/an-object');
  24559. var isObject = _dereq_('../internals/is-object');
  24560. var create = _dereq_('../internals/object-create');
  24561. var bind = _dereq_('../internals/function-bind');
  24562. var fails = _dereq_('../internals/fails');
  24563. var nativeConstruct = getBuiltIn('Reflect', 'construct');
  24564. // `Reflect.construct` method
  24565. // https://tc39.github.io/ecma262/#sec-reflect.construct
  24566. // MS Edge supports only 2 arguments and argumentsList argument is optional
  24567. // FF Nightly sets third argument as `new.target`, but does not create `this` from it
  24568. var NEW_TARGET_BUG = fails(function() {
  24569. function F() {
  24570. /* empty */
  24571. }
  24572. return !(
  24573. nativeConstruct(
  24574. function() {
  24575. /* empty */
  24576. },
  24577. [],
  24578. F
  24579. ) instanceof F
  24580. );
  24581. });
  24582. var ARGS_BUG = !fails(function() {
  24583. nativeConstruct(function() {
  24584. /* empty */
  24585. });
  24586. });
  24587. var FORCED = NEW_TARGET_BUG || ARGS_BUG;
  24588. $(
  24589. { target: 'Reflect', stat: true, forced: FORCED, sham: FORCED },
  24590. {
  24591. construct: function construct(Target, args /* , newTarget */) {
  24592. aFunction(Target);
  24593. anObject(args);
  24594. var newTarget = arguments.length < 3 ? Target : aFunction(arguments[2]);
  24595. if (ARGS_BUG && !NEW_TARGET_BUG)
  24596. return nativeConstruct(Target, args, newTarget);
  24597. if (Target == newTarget) {
  24598. // w/o altered newTarget, optimization for 0-4 arguments
  24599. switch (args.length) {
  24600. case 0:
  24601. return new Target();
  24602. case 1:
  24603. return new Target(args[0]);
  24604. case 2:
  24605. return new Target(args[0], args[1]);
  24606. case 3:
  24607. return new Target(args[0], args[1], args[2]);
  24608. case 4:
  24609. return new Target(args[0], args[1], args[2], args[3]);
  24610. }
  24611. // w/o altered newTarget, lot of arguments case
  24612. var $args = [null];
  24613. $args.push.apply($args, args);
  24614. return new (bind.apply(Target, $args))();
  24615. }
  24616. // with altered newTarget, not support built-in constructors
  24617. var proto = newTarget.prototype;
  24618. var instance = create(isObject(proto) ? proto : Object.prototype);
  24619. var result = Function.apply.call(Target, instance, args);
  24620. return isObject(result) ? result : instance;
  24621. }
  24622. }
  24623. );
  24624. },
  24625. {
  24626. '../internals/a-function': 23,
  24627. '../internals/an-object': 28,
  24628. '../internals/export': 67,
  24629. '../internals/fails': 68,
  24630. '../internals/function-bind': 72,
  24631. '../internals/get-built-in': 73,
  24632. '../internals/is-object': 91,
  24633. '../internals/object-create': 107
  24634. }
  24635. ],
  24636. 195: [
  24637. function(_dereq_, module, exports) {
  24638. var DESCRIPTORS = _dereq_('../internals/descriptors');
  24639. var global = _dereq_('../internals/global');
  24640. var isForced = _dereq_('../internals/is-forced');
  24641. var inheritIfRequired = _dereq_('../internals/inherit-if-required');
  24642. var defineProperty = _dereq_('../internals/object-define-property').f;
  24643. var getOwnPropertyNames = _dereq_('../internals/object-get-own-property-names').f;
  24644. var isRegExp = _dereq_('../internals/is-regexp');
  24645. var getFlags = _dereq_('../internals/regexp-flags');
  24646. var stickyHelpers = _dereq_('../internals/regexp-sticky-helpers');
  24647. var redefine = _dereq_('../internals/redefine');
  24648. var fails = _dereq_('../internals/fails');
  24649. var setInternalState = _dereq_('../internals/internal-state').set;
  24650. var setSpecies = _dereq_('../internals/set-species');
  24651. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  24652. var MATCH = wellKnownSymbol('match');
  24653. var NativeRegExp = global.RegExp;
  24654. var RegExpPrototype = NativeRegExp.prototype;
  24655. var re1 = /a/g;
  24656. var re2 = /a/g;
  24657. // "new" should create a new object, old webkit bug
  24658. var CORRECT_NEW = new NativeRegExp(re1) !== re1;
  24659. var UNSUPPORTED_Y = stickyHelpers.UNSUPPORTED_Y;
  24660. var FORCED =
  24661. DESCRIPTORS &&
  24662. isForced(
  24663. 'RegExp',
  24664. !CORRECT_NEW ||
  24665. UNSUPPORTED_Y ||
  24666. fails(function() {
  24667. re2[MATCH] = false;
  24668. // RegExp constructor can alter flags and IsRegExp works correct with @@match
  24669. return (
  24670. NativeRegExp(re1) != re1 ||
  24671. NativeRegExp(re2) == re2 ||
  24672. NativeRegExp(re1, 'i') != '/a/i'
  24673. );
  24674. })
  24675. );
  24676. // `RegExp` constructor
  24677. // https://tc39.github.io/ecma262/#sec-regexp-constructor
  24678. if (FORCED) {
  24679. var RegExpWrapper = function RegExp(pattern, flags) {
  24680. var thisIsRegExp = this instanceof RegExpWrapper;
  24681. var patternIsRegExp = isRegExp(pattern);
  24682. var flagsAreUndefined = flags === undefined;
  24683. var sticky;
  24684. if (
  24685. !thisIsRegExp &&
  24686. patternIsRegExp &&
  24687. pattern.constructor === RegExpWrapper &&
  24688. flagsAreUndefined
  24689. ) {
  24690. return pattern;
  24691. }
  24692. if (CORRECT_NEW) {
  24693. if (patternIsRegExp && !flagsAreUndefined) pattern = pattern.source;
  24694. } else if (pattern instanceof RegExpWrapper) {
  24695. if (flagsAreUndefined) flags = getFlags.call(pattern);
  24696. pattern = pattern.source;
  24697. }
  24698. if (UNSUPPORTED_Y) {
  24699. sticky = !!flags && flags.indexOf('y') > -1;
  24700. if (sticky) flags = flags.replace(/y/g, '');
  24701. }
  24702. var result = inheritIfRequired(
  24703. CORRECT_NEW
  24704. ? new NativeRegExp(pattern, flags)
  24705. : NativeRegExp(pattern, flags),
  24706. thisIsRegExp ? this : RegExpPrototype,
  24707. RegExpWrapper
  24708. );
  24709. if (UNSUPPORTED_Y && sticky) setInternalState(result, { sticky: sticky });
  24710. return result;
  24711. };
  24712. var proxy = function(key) {
  24713. key in RegExpWrapper ||
  24714. defineProperty(RegExpWrapper, key, {
  24715. configurable: true,
  24716. get: function() {
  24717. return NativeRegExp[key];
  24718. },
  24719. set: function(it) {
  24720. NativeRegExp[key] = it;
  24721. }
  24722. });
  24723. };
  24724. var keys = getOwnPropertyNames(NativeRegExp);
  24725. var index = 0;
  24726. while (keys.length > index) proxy(keys[index++]);
  24727. RegExpPrototype.constructor = RegExpWrapper;
  24728. RegExpWrapper.prototype = RegExpPrototype;
  24729. redefine(global, 'RegExp', RegExpWrapper);
  24730. }
  24731. // https://tc39.github.io/ecma262/#sec-get-regexp-@@species
  24732. setSpecies('RegExp');
  24733. },
  24734. {
  24735. '../internals/descriptors': 60,
  24736. '../internals/fails': 68,
  24737. '../internals/global': 76,
  24738. '../internals/inherit-if-required': 84,
  24739. '../internals/internal-state': 87,
  24740. '../internals/is-forced': 90,
  24741. '../internals/is-regexp': 93,
  24742. '../internals/object-define-property': 109,
  24743. '../internals/object-get-own-property-names': 112,
  24744. '../internals/redefine': 125,
  24745. '../internals/regexp-flags': 128,
  24746. '../internals/regexp-sticky-helpers': 129,
  24747. '../internals/set-species': 133,
  24748. '../internals/well-known-symbol': 163
  24749. }
  24750. ],
  24751. 196: [
  24752. function(_dereq_, module, exports) {
  24753. 'use strict';
  24754. var $ = _dereq_('../internals/export');
  24755. var exec = _dereq_('../internals/regexp-exec');
  24756. $(
  24757. { target: 'RegExp', proto: true, forced: /./.exec !== exec },
  24758. {
  24759. exec: exec
  24760. }
  24761. );
  24762. },
  24763. { '../internals/export': 67, '../internals/regexp-exec': 127 }
  24764. ],
  24765. 197: [
  24766. function(_dereq_, module, exports) {
  24767. 'use strict';
  24768. var redefine = _dereq_('../internals/redefine');
  24769. var anObject = _dereq_('../internals/an-object');
  24770. var fails = _dereq_('../internals/fails');
  24771. var flags = _dereq_('../internals/regexp-flags');
  24772. var TO_STRING = 'toString';
  24773. var RegExpPrototype = RegExp.prototype;
  24774. var nativeToString = RegExpPrototype[TO_STRING];
  24775. var NOT_GENERIC = fails(function() {
  24776. return nativeToString.call({ source: 'a', flags: 'b' }) != '/a/b';
  24777. });
  24778. // FF44- RegExp#toString has a wrong name
  24779. var INCORRECT_NAME = nativeToString.name != TO_STRING;
  24780. // `RegExp.prototype.toString` method
  24781. // https://tc39.github.io/ecma262/#sec-regexp.prototype.tostring
  24782. if (NOT_GENERIC || INCORRECT_NAME) {
  24783. redefine(
  24784. RegExp.prototype,
  24785. TO_STRING,
  24786. function toString() {
  24787. var R = anObject(this);
  24788. var p = String(R.source);
  24789. var rf = R.flags;
  24790. var f = String(
  24791. rf === undefined && R instanceof RegExp && !('flags' in RegExpPrototype)
  24792. ? flags.call(R)
  24793. : rf
  24794. );
  24795. return '/' + p + '/' + f;
  24796. },
  24797. { unsafe: true }
  24798. );
  24799. }
  24800. },
  24801. {
  24802. '../internals/an-object': 28,
  24803. '../internals/fails': 68,
  24804. '../internals/redefine': 125,
  24805. '../internals/regexp-flags': 128
  24806. }
  24807. ],
  24808. 198: [
  24809. function(_dereq_, module, exports) {
  24810. 'use strict';
  24811. var collection = _dereq_('../internals/collection');
  24812. var collectionStrong = _dereq_('../internals/collection-strong');
  24813. // `Set` constructor
  24814. // https://tc39.github.io/ecma262/#sec-set-objects
  24815. module.exports = collection(
  24816. 'Set',
  24817. function(init) {
  24818. return function Set() {
  24819. return init(this, arguments.length ? arguments[0] : undefined);
  24820. };
  24821. },
  24822. collectionStrong
  24823. );
  24824. },
  24825. { '../internals/collection': 49, '../internals/collection-strong': 48 }
  24826. ],
  24827. 199: [
  24828. function(_dereq_, module, exports) {
  24829. 'use strict';
  24830. var $ = _dereq_('../internals/export');
  24831. var getOwnPropertyDescriptor = _dereq_(
  24832. '../internals/object-get-own-property-descriptor'
  24833. ).f;
  24834. var toLength = _dereq_('../internals/to-length');
  24835. var notARegExp = _dereq_('../internals/not-a-regexp');
  24836. var requireObjectCoercible = _dereq_('../internals/require-object-coercible');
  24837. var correctIsRegExpLogic = _dereq_('../internals/correct-is-regexp-logic');
  24838. var IS_PURE = _dereq_('../internals/is-pure');
  24839. var nativeEndsWith = ''.endsWith;
  24840. var min = Math.min;
  24841. var CORRECT_IS_REGEXP_LOGIC = correctIsRegExpLogic('endsWith');
  24842. // https://github.com/zloirock/core-js/pull/702
  24843. var MDN_POLYFILL_BUG =
  24844. !IS_PURE &&
  24845. !CORRECT_IS_REGEXP_LOGIC &&
  24846. !!(function() {
  24847. var descriptor = getOwnPropertyDescriptor(String.prototype, 'endsWith');
  24848. return descriptor && !descriptor.writable;
  24849. })();
  24850. // `String.prototype.endsWith` method
  24851. // https://tc39.github.io/ecma262/#sec-string.prototype.endswith
  24852. $(
  24853. {
  24854. target: 'String',
  24855. proto: true,
  24856. forced: !MDN_POLYFILL_BUG && !CORRECT_IS_REGEXP_LOGIC
  24857. },
  24858. {
  24859. endsWith: function endsWith(searchString /* , endPosition = @length */) {
  24860. var that = String(requireObjectCoercible(this));
  24861. notARegExp(searchString);
  24862. var endPosition = arguments.length > 1 ? arguments[1] : undefined;
  24863. var len = toLength(that.length);
  24864. var end = endPosition === undefined ? len : min(toLength(endPosition), len);
  24865. var search = String(searchString);
  24866. return nativeEndsWith
  24867. ? nativeEndsWith.call(that, search, end)
  24868. : that.slice(end - search.length, end) === search;
  24869. }
  24870. }
  24871. );
  24872. },
  24873. {
  24874. '../internals/correct-is-regexp-logic': 51,
  24875. '../internals/export': 67,
  24876. '../internals/is-pure': 92,
  24877. '../internals/not-a-regexp': 104,
  24878. '../internals/object-get-own-property-descriptor': 110,
  24879. '../internals/require-object-coercible': 130,
  24880. '../internals/to-length': 151
  24881. }
  24882. ],
  24883. 200: [
  24884. function(_dereq_, module, exports) {
  24885. 'use strict';
  24886. var $ = _dereq_('../internals/export');
  24887. var notARegExp = _dereq_('../internals/not-a-regexp');
  24888. var requireObjectCoercible = _dereq_('../internals/require-object-coercible');
  24889. var correctIsRegExpLogic = _dereq_('../internals/correct-is-regexp-logic');
  24890. // `String.prototype.includes` method
  24891. // https://tc39.github.io/ecma262/#sec-string.prototype.includes
  24892. $(
  24893. { target: 'String', proto: true, forced: !correctIsRegExpLogic('includes') },
  24894. {
  24895. includes: function includes(searchString /* , position = 0 */) {
  24896. return !!~String(requireObjectCoercible(this)).indexOf(
  24897. notARegExp(searchString),
  24898. arguments.length > 1 ? arguments[1] : undefined
  24899. );
  24900. }
  24901. }
  24902. );
  24903. },
  24904. {
  24905. '../internals/correct-is-regexp-logic': 51,
  24906. '../internals/export': 67,
  24907. '../internals/not-a-regexp': 104,
  24908. '../internals/require-object-coercible': 130
  24909. }
  24910. ],
  24911. 201: [
  24912. function(_dereq_, module, exports) {
  24913. 'use strict';
  24914. var charAt = _dereq_('../internals/string-multibyte').charAt;
  24915. var InternalStateModule = _dereq_('../internals/internal-state');
  24916. var defineIterator = _dereq_('../internals/define-iterator');
  24917. var STRING_ITERATOR = 'String Iterator';
  24918. var setInternalState = InternalStateModule.set;
  24919. var getInternalState = InternalStateModule.getterFor(STRING_ITERATOR);
  24920. // `String.prototype[@@iterator]` method
  24921. // https://tc39.github.io/ecma262/#sec-string.prototype-@@iterator
  24922. defineIterator(
  24923. String,
  24924. 'String',
  24925. function(iterated) {
  24926. setInternalState(this, {
  24927. type: STRING_ITERATOR,
  24928. string: String(iterated),
  24929. index: 0
  24930. });
  24931. // `%StringIteratorPrototype%.next` method
  24932. // https://tc39.github.io/ecma262/#sec-%stringiteratorprototype%.next
  24933. },
  24934. function next() {
  24935. var state = getInternalState(this);
  24936. var string = state.string;
  24937. var index = state.index;
  24938. var point;
  24939. if (index >= string.length) return { value: undefined, done: true };
  24940. point = charAt(string, index);
  24941. state.index += point.length;
  24942. return { value: point, done: false };
  24943. }
  24944. );
  24945. },
  24946. {
  24947. '../internals/define-iterator': 58,
  24948. '../internals/internal-state': 87,
  24949. '../internals/string-multibyte': 140
  24950. }
  24951. ],
  24952. 202: [
  24953. function(_dereq_, module, exports) {
  24954. 'use strict';
  24955. var fixRegExpWellKnownSymbolLogic = _dereq_(
  24956. '../internals/fix-regexp-well-known-symbol-logic'
  24957. );
  24958. var anObject = _dereq_('../internals/an-object');
  24959. var toLength = _dereq_('../internals/to-length');
  24960. var requireObjectCoercible = _dereq_('../internals/require-object-coercible');
  24961. var advanceStringIndex = _dereq_('../internals/advance-string-index');
  24962. var regExpExec = _dereq_('../internals/regexp-exec-abstract');
  24963. // @@match logic
  24964. fixRegExpWellKnownSymbolLogic('match', 1, function(
  24965. MATCH,
  24966. nativeMatch,
  24967. maybeCallNative
  24968. ) {
  24969. return [
  24970. // `String.prototype.match` method
  24971. // https://tc39.github.io/ecma262/#sec-string.prototype.match
  24972. function match(regexp) {
  24973. var O = requireObjectCoercible(this);
  24974. var matcher = regexp == undefined ? undefined : regexp[MATCH];
  24975. return matcher !== undefined
  24976. ? matcher.call(regexp, O)
  24977. : new RegExp(regexp)[MATCH](String(O));
  24978. },
  24979. // `RegExp.prototype[@@match]` method
  24980. // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@match
  24981. function(regexp) {
  24982. var res = maybeCallNative(nativeMatch, regexp, this);
  24983. if (res.done) return res.value;
  24984. var rx = anObject(regexp);
  24985. var S = String(this);
  24986. if (!rx.global) return regExpExec(rx, S);
  24987. var fullUnicode = rx.unicode;
  24988. rx.lastIndex = 0;
  24989. var A = [];
  24990. var n = 0;
  24991. var result;
  24992. while ((result = regExpExec(rx, S)) !== null) {
  24993. var matchStr = String(result[0]);
  24994. A[n] = matchStr;
  24995. if (matchStr === '')
  24996. rx.lastIndex = advanceStringIndex(
  24997. S,
  24998. toLength(rx.lastIndex),
  24999. fullUnicode
  25000. );
  25001. n++;
  25002. }
  25003. return n === 0 ? null : A;
  25004. }
  25005. ];
  25006. });
  25007. },
  25008. {
  25009. '../internals/advance-string-index': 26,
  25010. '../internals/an-object': 28,
  25011. '../internals/fix-regexp-well-known-symbol-logic': 69,
  25012. '../internals/regexp-exec-abstract': 126,
  25013. '../internals/require-object-coercible': 130,
  25014. '../internals/to-length': 151
  25015. }
  25016. ],
  25017. 203: [
  25018. function(_dereq_, module, exports) {
  25019. var $ = _dereq_('../internals/export');
  25020. var repeat = _dereq_('../internals/string-repeat');
  25021. // `String.prototype.repeat` method
  25022. // https://tc39.github.io/ecma262/#sec-string.prototype.repeat
  25023. $(
  25024. { target: 'String', proto: true },
  25025. {
  25026. repeat: repeat
  25027. }
  25028. );
  25029. },
  25030. { '../internals/export': 67, '../internals/string-repeat': 142 }
  25031. ],
  25032. 204: [
  25033. function(_dereq_, module, exports) {
  25034. 'use strict';
  25035. var fixRegExpWellKnownSymbolLogic = _dereq_(
  25036. '../internals/fix-regexp-well-known-symbol-logic'
  25037. );
  25038. var anObject = _dereq_('../internals/an-object');
  25039. var toObject = _dereq_('../internals/to-object');
  25040. var toLength = _dereq_('../internals/to-length');
  25041. var toInteger = _dereq_('../internals/to-integer');
  25042. var requireObjectCoercible = _dereq_('../internals/require-object-coercible');
  25043. var advanceStringIndex = _dereq_('../internals/advance-string-index');
  25044. var regExpExec = _dereq_('../internals/regexp-exec-abstract');
  25045. var max = Math.max;
  25046. var min = Math.min;
  25047. var floor = Math.floor;
  25048. var SUBSTITUTION_SYMBOLS = /\$([$&'`]|\d\d?|<[^>]*>)/g;
  25049. var SUBSTITUTION_SYMBOLS_NO_NAMED = /\$([$&'`]|\d\d?)/g;
  25050. var maybeToString = function(it) {
  25051. return it === undefined ? it : String(it);
  25052. };
  25053. // @@replace logic
  25054. fixRegExpWellKnownSymbolLogic('replace', 2, function(
  25055. REPLACE,
  25056. nativeReplace,
  25057. maybeCallNative,
  25058. reason
  25059. ) {
  25060. var REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE =
  25061. reason.REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE;
  25062. var REPLACE_KEEPS_$0 = reason.REPLACE_KEEPS_$0;
  25063. var UNSAFE_SUBSTITUTE = REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE
  25064. ? '$'
  25065. : '$0';
  25066. return [
  25067. // `String.prototype.replace` method
  25068. // https://tc39.github.io/ecma262/#sec-string.prototype.replace
  25069. function replace(searchValue, replaceValue) {
  25070. var O = requireObjectCoercible(this);
  25071. var replacer = searchValue == undefined ? undefined : searchValue[REPLACE];
  25072. return replacer !== undefined
  25073. ? replacer.call(searchValue, O, replaceValue)
  25074. : nativeReplace.call(String(O), searchValue, replaceValue);
  25075. },
  25076. // `RegExp.prototype[@@replace]` method
  25077. // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@replace
  25078. function(regexp, replaceValue) {
  25079. if (
  25080. (!REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE && REPLACE_KEEPS_$0) ||
  25081. (typeof replaceValue === 'string' &&
  25082. replaceValue.indexOf(UNSAFE_SUBSTITUTE) === -1)
  25083. ) {
  25084. var res = maybeCallNative(nativeReplace, regexp, this, replaceValue);
  25085. if (res.done) return res.value;
  25086. }
  25087. var rx = anObject(regexp);
  25088. var S = String(this);
  25089. var functionalReplace = typeof replaceValue === 'function';
  25090. if (!functionalReplace) replaceValue = String(replaceValue);
  25091. var global = rx.global;
  25092. if (global) {
  25093. var fullUnicode = rx.unicode;
  25094. rx.lastIndex = 0;
  25095. }
  25096. var results = [];
  25097. while (true) {
  25098. var result = regExpExec(rx, S);
  25099. if (result === null) break;
  25100. results.push(result);
  25101. if (!global) break;
  25102. var matchStr = String(result[0]);
  25103. if (matchStr === '')
  25104. rx.lastIndex = advanceStringIndex(
  25105. S,
  25106. toLength(rx.lastIndex),
  25107. fullUnicode
  25108. );
  25109. }
  25110. var accumulatedResult = '';
  25111. var nextSourcePosition = 0;
  25112. for (var i = 0; i < results.length; i++) {
  25113. result = results[i];
  25114. var matched = String(result[0]);
  25115. var position = max(min(toInteger(result.index), S.length), 0);
  25116. var captures = [];
  25117. // NOTE: This is equivalent to
  25118. // captures = result.slice(1).map(maybeToString)
  25119. // but for some reason `nativeSlice.call(result, 1, result.length)` (called in
  25120. // the slice polyfill when slicing native arrays) "doesn't work" in safari 9 and
  25121. // causes a crash (https://pastebin.com/N21QzeQA) when trying to debug it.
  25122. for (var j = 1; j < result.length; j++)
  25123. captures.push(maybeToString(result[j]));
  25124. var namedCaptures = result.groups;
  25125. if (functionalReplace) {
  25126. var replacerArgs = [matched].concat(captures, position, S);
  25127. if (namedCaptures !== undefined) replacerArgs.push(namedCaptures);
  25128. var replacement = String(replaceValue.apply(undefined, replacerArgs));
  25129. } else {
  25130. replacement = getSubstitution(
  25131. matched,
  25132. S,
  25133. position,
  25134. captures,
  25135. namedCaptures,
  25136. replaceValue
  25137. );
  25138. }
  25139. if (position >= nextSourcePosition) {
  25140. accumulatedResult +=
  25141. S.slice(nextSourcePosition, position) + replacement;
  25142. nextSourcePosition = position + matched.length;
  25143. }
  25144. }
  25145. return accumulatedResult + S.slice(nextSourcePosition);
  25146. }
  25147. ];
  25148. // https://tc39.github.io/ecma262/#sec-getsubstitution
  25149. function getSubstitution(
  25150. matched,
  25151. str,
  25152. position,
  25153. captures,
  25154. namedCaptures,
  25155. replacement
  25156. ) {
  25157. var tailPos = position + matched.length;
  25158. var m = captures.length;
  25159. var symbols = SUBSTITUTION_SYMBOLS_NO_NAMED;
  25160. if (namedCaptures !== undefined) {
  25161. namedCaptures = toObject(namedCaptures);
  25162. symbols = SUBSTITUTION_SYMBOLS;
  25163. }
  25164. return nativeReplace.call(replacement, symbols, function(match, ch) {
  25165. var capture;
  25166. switch (ch.charAt(0)) {
  25167. case '$':
  25168. return '$';
  25169. case '&':
  25170. return matched;
  25171. case '`':
  25172. return str.slice(0, position);
  25173. case "'":
  25174. return str.slice(tailPos);
  25175. case '<':
  25176. capture = namedCaptures[ch.slice(1, -1)];
  25177. break;
  25178. default:
  25179. // \d\d?
  25180. var n = +ch;
  25181. if (n === 0) return match;
  25182. if (n > m) {
  25183. var f = floor(n / 10);
  25184. if (f === 0) return match;
  25185. if (f <= m)
  25186. return captures[f - 1] === undefined
  25187. ? ch.charAt(1)
  25188. : captures[f - 1] + ch.charAt(1);
  25189. return match;
  25190. }
  25191. capture = captures[n - 1];
  25192. }
  25193. return capture === undefined ? '' : capture;
  25194. });
  25195. }
  25196. });
  25197. },
  25198. {
  25199. '../internals/advance-string-index': 26,
  25200. '../internals/an-object': 28,
  25201. '../internals/fix-regexp-well-known-symbol-logic': 69,
  25202. '../internals/regexp-exec-abstract': 126,
  25203. '../internals/require-object-coercible': 130,
  25204. '../internals/to-integer': 150,
  25205. '../internals/to-length': 151,
  25206. '../internals/to-object': 152
  25207. }
  25208. ],
  25209. 205: [
  25210. function(_dereq_, module, exports) {
  25211. 'use strict';
  25212. var fixRegExpWellKnownSymbolLogic = _dereq_(
  25213. '../internals/fix-regexp-well-known-symbol-logic'
  25214. );
  25215. var anObject = _dereq_('../internals/an-object');
  25216. var requireObjectCoercible = _dereq_('../internals/require-object-coercible');
  25217. var sameValue = _dereq_('../internals/same-value');
  25218. var regExpExec = _dereq_('../internals/regexp-exec-abstract');
  25219. // @@search logic
  25220. fixRegExpWellKnownSymbolLogic('search', 1, function(
  25221. SEARCH,
  25222. nativeSearch,
  25223. maybeCallNative
  25224. ) {
  25225. return [
  25226. // `String.prototype.search` method
  25227. // https://tc39.github.io/ecma262/#sec-string.prototype.search
  25228. function search(regexp) {
  25229. var O = requireObjectCoercible(this);
  25230. var searcher = regexp == undefined ? undefined : regexp[SEARCH];
  25231. return searcher !== undefined
  25232. ? searcher.call(regexp, O)
  25233. : new RegExp(regexp)[SEARCH](String(O));
  25234. },
  25235. // `RegExp.prototype[@@search]` method
  25236. // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@search
  25237. function(regexp) {
  25238. var res = maybeCallNative(nativeSearch, regexp, this);
  25239. if (res.done) return res.value;
  25240. var rx = anObject(regexp);
  25241. var S = String(this);
  25242. var previousLastIndex = rx.lastIndex;
  25243. if (!sameValue(previousLastIndex, 0)) rx.lastIndex = 0;
  25244. var result = regExpExec(rx, S);
  25245. if (!sameValue(rx.lastIndex, previousLastIndex))
  25246. rx.lastIndex = previousLastIndex;
  25247. return result === null ? -1 : result.index;
  25248. }
  25249. ];
  25250. });
  25251. },
  25252. {
  25253. '../internals/an-object': 28,
  25254. '../internals/fix-regexp-well-known-symbol-logic': 69,
  25255. '../internals/regexp-exec-abstract': 126,
  25256. '../internals/require-object-coercible': 130,
  25257. '../internals/same-value': 131
  25258. }
  25259. ],
  25260. 206: [
  25261. function(_dereq_, module, exports) {
  25262. 'use strict';
  25263. var fixRegExpWellKnownSymbolLogic = _dereq_(
  25264. '../internals/fix-regexp-well-known-symbol-logic'
  25265. );
  25266. var isRegExp = _dereq_('../internals/is-regexp');
  25267. var anObject = _dereq_('../internals/an-object');
  25268. var requireObjectCoercible = _dereq_('../internals/require-object-coercible');
  25269. var speciesConstructor = _dereq_('../internals/species-constructor');
  25270. var advanceStringIndex = _dereq_('../internals/advance-string-index');
  25271. var toLength = _dereq_('../internals/to-length');
  25272. var callRegExpExec = _dereq_('../internals/regexp-exec-abstract');
  25273. var regexpExec = _dereq_('../internals/regexp-exec');
  25274. var fails = _dereq_('../internals/fails');
  25275. var arrayPush = [].push;
  25276. var min = Math.min;
  25277. var MAX_UINT32 = 0xffffffff;
  25278. // babel-minify transpiles RegExp('x', 'y') -> /x/y and it causes SyntaxError
  25279. var SUPPORTS_Y = !fails(function() {
  25280. return !RegExp(MAX_UINT32, 'y');
  25281. });
  25282. // @@split logic
  25283. fixRegExpWellKnownSymbolLogic(
  25284. 'split',
  25285. 2,
  25286. function(SPLIT, nativeSplit, maybeCallNative) {
  25287. var internalSplit;
  25288. if (
  25289. 'abbc'.split(/(b)*/)[1] == 'c' ||
  25290. 'test'.split(/(?:)/, -1).length != 4 ||
  25291. 'ab'.split(/(?:ab)*/).length != 2 ||
  25292. '.'.split(/(.?)(.?)/).length != 4 ||
  25293. '.'.split(/()()/).length > 1 ||
  25294. ''.split(/.?/).length
  25295. ) {
  25296. // based on es5-shim implementation, need to rework it
  25297. internalSplit = function(separator, limit) {
  25298. var string = String(requireObjectCoercible(this));
  25299. var lim = limit === undefined ? MAX_UINT32 : limit >>> 0;
  25300. if (lim === 0) return [];
  25301. if (separator === undefined) return [string];
  25302. // If `separator` is not a regex, use native split
  25303. if (!isRegExp(separator)) {
  25304. return nativeSplit.call(string, separator, lim);
  25305. }
  25306. var output = [];
  25307. var flags =
  25308. (separator.ignoreCase ? 'i' : '') +
  25309. (separator.multiline ? 'm' : '') +
  25310. (separator.unicode ? 'u' : '') +
  25311. (separator.sticky ? 'y' : '');
  25312. var lastLastIndex = 0;
  25313. // Make `global` and avoid `lastIndex` issues by working with a copy
  25314. var separatorCopy = new RegExp(separator.source, flags + 'g');
  25315. var match, lastIndex, lastLength;
  25316. while ((match = regexpExec.call(separatorCopy, string))) {
  25317. lastIndex = separatorCopy.lastIndex;
  25318. if (lastIndex > lastLastIndex) {
  25319. output.push(string.slice(lastLastIndex, match.index));
  25320. if (match.length > 1 && match.index < string.length)
  25321. arrayPush.apply(output, match.slice(1));
  25322. lastLength = match[0].length;
  25323. lastLastIndex = lastIndex;
  25324. if (output.length >= lim) break;
  25325. }
  25326. if (separatorCopy.lastIndex === match.index) separatorCopy.lastIndex++; // Avoid an infinite loop
  25327. }
  25328. if (lastLastIndex === string.length) {
  25329. if (lastLength || !separatorCopy.test('')) output.push('');
  25330. } else output.push(string.slice(lastLastIndex));
  25331. return output.length > lim ? output.slice(0, lim) : output;
  25332. };
  25333. // Chakra, V8
  25334. } else if ('0'.split(undefined, 0).length) {
  25335. internalSplit = function(separator, limit) {
  25336. return separator === undefined && limit === 0
  25337. ? []
  25338. : nativeSplit.call(this, separator, limit);
  25339. };
  25340. } else internalSplit = nativeSplit;
  25341. return [
  25342. // `String.prototype.split` method
  25343. // https://tc39.github.io/ecma262/#sec-string.prototype.split
  25344. function split(separator, limit) {
  25345. var O = requireObjectCoercible(this);
  25346. var splitter = separator == undefined ? undefined : separator[SPLIT];
  25347. return splitter !== undefined
  25348. ? splitter.call(separator, O, limit)
  25349. : internalSplit.call(String(O), separator, limit);
  25350. },
  25351. // `RegExp.prototype[@@split]` method
  25352. // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@split
  25353. //
  25354. // NOTE: This cannot be properly polyfilled in engines that don't support
  25355. // the 'y' flag.
  25356. function(regexp, limit) {
  25357. var res = maybeCallNative(
  25358. internalSplit,
  25359. regexp,
  25360. this,
  25361. limit,
  25362. internalSplit !== nativeSplit
  25363. );
  25364. if (res.done) return res.value;
  25365. var rx = anObject(regexp);
  25366. var S = String(this);
  25367. var C = speciesConstructor(rx, RegExp);
  25368. var unicodeMatching = rx.unicode;
  25369. var flags =
  25370. (rx.ignoreCase ? 'i' : '') +
  25371. (rx.multiline ? 'm' : '') +
  25372. (rx.unicode ? 'u' : '') +
  25373. (SUPPORTS_Y ? 'y' : 'g');
  25374. // ^(? + rx + ) is needed, in combination with some S slicing, to
  25375. // simulate the 'y' flag.
  25376. var splitter = new C(SUPPORTS_Y ? rx : '^(?:' + rx.source + ')', flags);
  25377. var lim = limit === undefined ? MAX_UINT32 : limit >>> 0;
  25378. if (lim === 0) return [];
  25379. if (S.length === 0)
  25380. return callRegExpExec(splitter, S) === null ? [S] : [];
  25381. var p = 0;
  25382. var q = 0;
  25383. var A = [];
  25384. while (q < S.length) {
  25385. splitter.lastIndex = SUPPORTS_Y ? q : 0;
  25386. var z = callRegExpExec(splitter, SUPPORTS_Y ? S : S.slice(q));
  25387. var e;
  25388. if (
  25389. z === null ||
  25390. (e = min(
  25391. toLength(splitter.lastIndex + (SUPPORTS_Y ? 0 : q)),
  25392. S.length
  25393. )) === p
  25394. ) {
  25395. q = advanceStringIndex(S, q, unicodeMatching);
  25396. } else {
  25397. A.push(S.slice(p, q));
  25398. if (A.length === lim) return A;
  25399. for (var i = 1; i <= z.length - 1; i++) {
  25400. A.push(z[i]);
  25401. if (A.length === lim) return A;
  25402. }
  25403. q = p = e;
  25404. }
  25405. }
  25406. A.push(S.slice(p));
  25407. return A;
  25408. }
  25409. ];
  25410. },
  25411. !SUPPORTS_Y
  25412. );
  25413. },
  25414. {
  25415. '../internals/advance-string-index': 26,
  25416. '../internals/an-object': 28,
  25417. '../internals/fails': 68,
  25418. '../internals/fix-regexp-well-known-symbol-logic': 69,
  25419. '../internals/is-regexp': 93,
  25420. '../internals/regexp-exec': 127,
  25421. '../internals/regexp-exec-abstract': 126,
  25422. '../internals/require-object-coercible': 130,
  25423. '../internals/species-constructor': 138,
  25424. '../internals/to-length': 151
  25425. }
  25426. ],
  25427. 207: [
  25428. function(_dereq_, module, exports) {
  25429. 'use strict';
  25430. var $ = _dereq_('../internals/export');
  25431. var createHTML = _dereq_('../internals/create-html');
  25432. var forcedStringHTMLMethod = _dereq_('../internals/string-html-forced');
  25433. // `String.prototype.sub` method
  25434. // https://tc39.github.io/ecma262/#sec-string.prototype.sub
  25435. $(
  25436. { target: 'String', proto: true, forced: forcedStringHTMLMethod('sub') },
  25437. {
  25438. sub: function sub() {
  25439. return createHTML(this, 'sub', '', '');
  25440. }
  25441. }
  25442. );
  25443. },
  25444. {
  25445. '../internals/create-html': 53,
  25446. '../internals/export': 67,
  25447. '../internals/string-html-forced': 139
  25448. }
  25449. ],
  25450. 208: [
  25451. function(_dereq_, module, exports) {
  25452. 'use strict';
  25453. var $ = _dereq_('../internals/export');
  25454. var $trim = _dereq_('../internals/string-trim').trim;
  25455. var forcedStringTrimMethod = _dereq_('../internals/string-trim-forced');
  25456. // `String.prototype.trim` method
  25457. // https://tc39.github.io/ecma262/#sec-string.prototype.trim
  25458. $(
  25459. { target: 'String', proto: true, forced: forcedStringTrimMethod('trim') },
  25460. {
  25461. trim: function trim() {
  25462. return $trim(this);
  25463. }
  25464. }
  25465. );
  25466. },
  25467. {
  25468. '../internals/export': 67,
  25469. '../internals/string-trim': 144,
  25470. '../internals/string-trim-forced': 143
  25471. }
  25472. ],
  25473. 209: [
  25474. function(_dereq_, module, exports) {
  25475. // `Symbol.prototype.description` getter
  25476. // https://tc39.github.io/ecma262/#sec-symbol.prototype.description
  25477. 'use strict';
  25478. var $ = _dereq_('../internals/export');
  25479. var DESCRIPTORS = _dereq_('../internals/descriptors');
  25480. var global = _dereq_('../internals/global');
  25481. var has = _dereq_('../internals/has');
  25482. var isObject = _dereq_('../internals/is-object');
  25483. var defineProperty = _dereq_('../internals/object-define-property').f;
  25484. var copyConstructorProperties = _dereq_(
  25485. '../internals/copy-constructor-properties'
  25486. );
  25487. var NativeSymbol = global.Symbol;
  25488. if (
  25489. DESCRIPTORS &&
  25490. typeof NativeSymbol == 'function' &&
  25491. (!('description' in NativeSymbol.prototype) ||
  25492. // Safari 12 bug
  25493. NativeSymbol().description !== undefined)
  25494. ) {
  25495. var EmptyStringDescriptionStore = {};
  25496. // wrap Symbol constructor for correct work with undefined description
  25497. var SymbolWrapper = function Symbol() {
  25498. var description =
  25499. arguments.length < 1 || arguments[0] === undefined
  25500. ? undefined
  25501. : String(arguments[0]);
  25502. var result =
  25503. this instanceof SymbolWrapper
  25504. ? new NativeSymbol(description)
  25505. : // in Edge 13, String(Symbol(undefined)) === 'Symbol(undefined)'
  25506. description === undefined ? NativeSymbol() : NativeSymbol(description);
  25507. if (description === '') EmptyStringDescriptionStore[result] = true;
  25508. return result;
  25509. };
  25510. copyConstructorProperties(SymbolWrapper, NativeSymbol);
  25511. var symbolPrototype = (SymbolWrapper.prototype = NativeSymbol.prototype);
  25512. symbolPrototype.constructor = SymbolWrapper;
  25513. var symbolToString = symbolPrototype.toString;
  25514. var native = String(NativeSymbol('test')) == 'Symbol(test)';
  25515. var regexp = /^Symbol\((.*)\)[^)]+$/;
  25516. defineProperty(symbolPrototype, 'description', {
  25517. configurable: true,
  25518. get: function description() {
  25519. var symbol = isObject(this) ? this.valueOf() : this;
  25520. var string = symbolToString.call(symbol);
  25521. if (has(EmptyStringDescriptionStore, symbol)) return '';
  25522. var desc = native ? string.slice(7, -1) : string.replace(regexp, '$1');
  25523. return desc === '' ? undefined : desc;
  25524. }
  25525. });
  25526. $(
  25527. { global: true, forced: true },
  25528. {
  25529. Symbol: SymbolWrapper
  25530. }
  25531. );
  25532. }
  25533. },
  25534. {
  25535. '../internals/copy-constructor-properties': 50,
  25536. '../internals/descriptors': 60,
  25537. '../internals/export': 67,
  25538. '../internals/global': 76,
  25539. '../internals/has': 77,
  25540. '../internals/is-object': 91,
  25541. '../internals/object-define-property': 109
  25542. }
  25543. ],
  25544. 210: [
  25545. function(_dereq_, module, exports) {
  25546. var defineWellKnownSymbol = _dereq_('../internals/define-well-known-symbol');
  25547. // `Symbol.iterator` well-known symbol
  25548. // https://tc39.github.io/ecma262/#sec-symbol.iterator
  25549. defineWellKnownSymbol('iterator');
  25550. },
  25551. { '../internals/define-well-known-symbol': 59 }
  25552. ],
  25553. 211: [
  25554. function(_dereq_, module, exports) {
  25555. 'use strict';
  25556. var $ = _dereq_('../internals/export');
  25557. var global = _dereq_('../internals/global');
  25558. var getBuiltIn = _dereq_('../internals/get-built-in');
  25559. var IS_PURE = _dereq_('../internals/is-pure');
  25560. var DESCRIPTORS = _dereq_('../internals/descriptors');
  25561. var NATIVE_SYMBOL = _dereq_('../internals/native-symbol');
  25562. var USE_SYMBOL_AS_UID = _dereq_('../internals/use-symbol-as-uid');
  25563. var fails = _dereq_('../internals/fails');
  25564. var has = _dereq_('../internals/has');
  25565. var isArray = _dereq_('../internals/is-array');
  25566. var isObject = _dereq_('../internals/is-object');
  25567. var anObject = _dereq_('../internals/an-object');
  25568. var toObject = _dereq_('../internals/to-object');
  25569. var toIndexedObject = _dereq_('../internals/to-indexed-object');
  25570. var toPrimitive = _dereq_('../internals/to-primitive');
  25571. var createPropertyDescriptor = _dereq_('../internals/create-property-descriptor');
  25572. var nativeObjectCreate = _dereq_('../internals/object-create');
  25573. var objectKeys = _dereq_('../internals/object-keys');
  25574. var getOwnPropertyNamesModule = _dereq_(
  25575. '../internals/object-get-own-property-names'
  25576. );
  25577. var getOwnPropertyNamesExternal = _dereq_(
  25578. '../internals/object-get-own-property-names-external'
  25579. );
  25580. var getOwnPropertySymbolsModule = _dereq_(
  25581. '../internals/object-get-own-property-symbols'
  25582. );
  25583. var getOwnPropertyDescriptorModule = _dereq_(
  25584. '../internals/object-get-own-property-descriptor'
  25585. );
  25586. var definePropertyModule = _dereq_('../internals/object-define-property');
  25587. var propertyIsEnumerableModule = _dereq_(
  25588. '../internals/object-property-is-enumerable'
  25589. );
  25590. var createNonEnumerableProperty = _dereq_(
  25591. '../internals/create-non-enumerable-property'
  25592. );
  25593. var redefine = _dereq_('../internals/redefine');
  25594. var shared = _dereq_('../internals/shared');
  25595. var sharedKey = _dereq_('../internals/shared-key');
  25596. var hiddenKeys = _dereq_('../internals/hidden-keys');
  25597. var uid = _dereq_('../internals/uid');
  25598. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  25599. var wrappedWellKnownSymbolModule = _dereq_(
  25600. '../internals/well-known-symbol-wrapped'
  25601. );
  25602. var defineWellKnownSymbol = _dereq_('../internals/define-well-known-symbol');
  25603. var setToStringTag = _dereq_('../internals/set-to-string-tag');
  25604. var InternalStateModule = _dereq_('../internals/internal-state');
  25605. var $forEach = _dereq_('../internals/array-iteration').forEach;
  25606. var HIDDEN = sharedKey('hidden');
  25607. var SYMBOL = 'Symbol';
  25608. var PROTOTYPE = 'prototype';
  25609. var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
  25610. var setInternalState = InternalStateModule.set;
  25611. var getInternalState = InternalStateModule.getterFor(SYMBOL);
  25612. var ObjectPrototype = Object[PROTOTYPE];
  25613. var $Symbol = global.Symbol;
  25614. var $stringify = getBuiltIn('JSON', 'stringify');
  25615. var nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  25616. var nativeDefineProperty = definePropertyModule.f;
  25617. var nativeGetOwnPropertyNames = getOwnPropertyNamesExternal.f;
  25618. var nativePropertyIsEnumerable = propertyIsEnumerableModule.f;
  25619. var AllSymbols = shared('symbols');
  25620. var ObjectPrototypeSymbols = shared('op-symbols');
  25621. var StringToSymbolRegistry = shared('string-to-symbol-registry');
  25622. var SymbolToStringRegistry = shared('symbol-to-string-registry');
  25623. var WellKnownSymbolsStore = shared('wks');
  25624. var QObject = global.QObject;
  25625. // Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173
  25626. var USE_SETTER = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild;
  25627. // fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687
  25628. var setSymbolDescriptor =
  25629. DESCRIPTORS &&
  25630. fails(function() {
  25631. return (
  25632. nativeObjectCreate(
  25633. nativeDefineProperty({}, 'a', {
  25634. get: function() {
  25635. return nativeDefineProperty(this, 'a', { value: 7 }).a;
  25636. }
  25637. })
  25638. ).a != 7
  25639. );
  25640. })
  25641. ? function(O, P, Attributes) {
  25642. var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor(
  25643. ObjectPrototype,
  25644. P
  25645. );
  25646. if (ObjectPrototypeDescriptor) delete ObjectPrototype[P];
  25647. nativeDefineProperty(O, P, Attributes);
  25648. if (ObjectPrototypeDescriptor && O !== ObjectPrototype) {
  25649. nativeDefineProperty(ObjectPrototype, P, ObjectPrototypeDescriptor);
  25650. }
  25651. }
  25652. : nativeDefineProperty;
  25653. var wrap = function(tag, description) {
  25654. var symbol = (AllSymbols[tag] = nativeObjectCreate($Symbol[PROTOTYPE]));
  25655. setInternalState(symbol, {
  25656. type: SYMBOL,
  25657. tag: tag,
  25658. description: description
  25659. });
  25660. if (!DESCRIPTORS) symbol.description = description;
  25661. return symbol;
  25662. };
  25663. var isSymbol = USE_SYMBOL_AS_UID
  25664. ? function(it) {
  25665. return typeof it == 'symbol';
  25666. }
  25667. : function(it) {
  25668. return Object(it) instanceof $Symbol;
  25669. };
  25670. var $defineProperty = function defineProperty(O, P, Attributes) {
  25671. if (O === ObjectPrototype)
  25672. $defineProperty(ObjectPrototypeSymbols, P, Attributes);
  25673. anObject(O);
  25674. var key = toPrimitive(P, true);
  25675. anObject(Attributes);
  25676. if (has(AllSymbols, key)) {
  25677. if (!Attributes.enumerable) {
  25678. if (!has(O, HIDDEN))
  25679. nativeDefineProperty(O, HIDDEN, createPropertyDescriptor(1, {}));
  25680. O[HIDDEN][key] = true;
  25681. } else {
  25682. if (has(O, HIDDEN) && O[HIDDEN][key]) O[HIDDEN][key] = false;
  25683. Attributes = nativeObjectCreate(Attributes, {
  25684. enumerable: createPropertyDescriptor(0, false)
  25685. });
  25686. }
  25687. return setSymbolDescriptor(O, key, Attributes);
  25688. }
  25689. return nativeDefineProperty(O, key, Attributes);
  25690. };
  25691. var $defineProperties = function defineProperties(O, Properties) {
  25692. anObject(O);
  25693. var properties = toIndexedObject(Properties);
  25694. var keys = objectKeys(properties).concat($getOwnPropertySymbols(properties));
  25695. $forEach(keys, function(key) {
  25696. if (!DESCRIPTORS || $propertyIsEnumerable.call(properties, key))
  25697. $defineProperty(O, key, properties[key]);
  25698. });
  25699. return O;
  25700. };
  25701. var $create = function create(O, Properties) {
  25702. return Properties === undefined
  25703. ? nativeObjectCreate(O)
  25704. : $defineProperties(nativeObjectCreate(O), Properties);
  25705. };
  25706. var $propertyIsEnumerable = function propertyIsEnumerable(V) {
  25707. var P = toPrimitive(V, true);
  25708. var enumerable = nativePropertyIsEnumerable.call(this, P);
  25709. if (
  25710. this === ObjectPrototype &&
  25711. has(AllSymbols, P) &&
  25712. !has(ObjectPrototypeSymbols, P)
  25713. )
  25714. return false;
  25715. return enumerable ||
  25716. !has(this, P) ||
  25717. !has(AllSymbols, P) ||
  25718. (has(this, HIDDEN) && this[HIDDEN][P])
  25719. ? enumerable
  25720. : true;
  25721. };
  25722. var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(O, P) {
  25723. var it = toIndexedObject(O);
  25724. var key = toPrimitive(P, true);
  25725. if (
  25726. it === ObjectPrototype &&
  25727. has(AllSymbols, key) &&
  25728. !has(ObjectPrototypeSymbols, key)
  25729. )
  25730. return;
  25731. var descriptor = nativeGetOwnPropertyDescriptor(it, key);
  25732. if (
  25733. descriptor &&
  25734. has(AllSymbols, key) &&
  25735. !(has(it, HIDDEN) && it[HIDDEN][key])
  25736. ) {
  25737. descriptor.enumerable = true;
  25738. }
  25739. return descriptor;
  25740. };
  25741. var $getOwnPropertyNames = function getOwnPropertyNames(O) {
  25742. var names = nativeGetOwnPropertyNames(toIndexedObject(O));
  25743. var result = [];
  25744. $forEach(names, function(key) {
  25745. if (!has(AllSymbols, key) && !has(hiddenKeys, key)) result.push(key);
  25746. });
  25747. return result;
  25748. };
  25749. var $getOwnPropertySymbols = function getOwnPropertySymbols(O) {
  25750. var IS_OBJECT_PROTOTYPE = O === ObjectPrototype;
  25751. var names = nativeGetOwnPropertyNames(
  25752. IS_OBJECT_PROTOTYPE ? ObjectPrototypeSymbols : toIndexedObject(O)
  25753. );
  25754. var result = [];
  25755. $forEach(names, function(key) {
  25756. if (
  25757. has(AllSymbols, key) &&
  25758. (!IS_OBJECT_PROTOTYPE || has(ObjectPrototype, key))
  25759. ) {
  25760. result.push(AllSymbols[key]);
  25761. }
  25762. });
  25763. return result;
  25764. };
  25765. // `Symbol` constructor
  25766. // https://tc39.github.io/ecma262/#sec-symbol-constructor
  25767. if (!NATIVE_SYMBOL) {
  25768. $Symbol = function Symbol() {
  25769. if (this instanceof $Symbol) throw TypeError('Symbol is not a constructor');
  25770. var description =
  25771. !arguments.length || arguments[0] === undefined
  25772. ? undefined
  25773. : String(arguments[0]);
  25774. var tag = uid(description);
  25775. var setter = function(value) {
  25776. if (this === ObjectPrototype) setter.call(ObjectPrototypeSymbols, value);
  25777. if (has(this, HIDDEN) && has(this[HIDDEN], tag)) this[HIDDEN][tag] = false;
  25778. setSymbolDescriptor(this, tag, createPropertyDescriptor(1, value));
  25779. };
  25780. if (DESCRIPTORS && USE_SETTER)
  25781. setSymbolDescriptor(ObjectPrototype, tag, {
  25782. configurable: true,
  25783. set: setter
  25784. });
  25785. return wrap(tag, description);
  25786. };
  25787. redefine($Symbol[PROTOTYPE], 'toString', function toString() {
  25788. return getInternalState(this).tag;
  25789. });
  25790. redefine($Symbol, 'withoutSetter', function(description) {
  25791. return wrap(uid(description), description);
  25792. });
  25793. propertyIsEnumerableModule.f = $propertyIsEnumerable;
  25794. definePropertyModule.f = $defineProperty;
  25795. getOwnPropertyDescriptorModule.f = $getOwnPropertyDescriptor;
  25796. getOwnPropertyNamesModule.f = getOwnPropertyNamesExternal.f = $getOwnPropertyNames;
  25797. getOwnPropertySymbolsModule.f = $getOwnPropertySymbols;
  25798. wrappedWellKnownSymbolModule.f = function(name) {
  25799. return wrap(wellKnownSymbol(name), name);
  25800. };
  25801. if (DESCRIPTORS) {
  25802. // https://github.com/tc39/proposal-Symbol-description
  25803. nativeDefineProperty($Symbol[PROTOTYPE], 'description', {
  25804. configurable: true,
  25805. get: function description() {
  25806. return getInternalState(this).description;
  25807. }
  25808. });
  25809. if (!IS_PURE) {
  25810. redefine(ObjectPrototype, 'propertyIsEnumerable', $propertyIsEnumerable, {
  25811. unsafe: true
  25812. });
  25813. }
  25814. }
  25815. }
  25816. $(
  25817. { global: true, wrap: true, forced: !NATIVE_SYMBOL, sham: !NATIVE_SYMBOL },
  25818. {
  25819. Symbol: $Symbol
  25820. }
  25821. );
  25822. $forEach(objectKeys(WellKnownSymbolsStore), function(name) {
  25823. defineWellKnownSymbol(name);
  25824. });
  25825. $(
  25826. { target: SYMBOL, stat: true, forced: !NATIVE_SYMBOL },
  25827. {
  25828. // `Symbol.for` method
  25829. // https://tc39.github.io/ecma262/#sec-symbol.for
  25830. for: function(key) {
  25831. var string = String(key);
  25832. if (has(StringToSymbolRegistry, string))
  25833. return StringToSymbolRegistry[string];
  25834. var symbol = $Symbol(string);
  25835. StringToSymbolRegistry[string] = symbol;
  25836. SymbolToStringRegistry[symbol] = string;
  25837. return symbol;
  25838. },
  25839. // `Symbol.keyFor` method
  25840. // https://tc39.github.io/ecma262/#sec-symbol.keyfor
  25841. keyFor: function keyFor(sym) {
  25842. if (!isSymbol(sym)) throw TypeError(sym + ' is not a symbol');
  25843. if (has(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym];
  25844. },
  25845. useSetter: function() {
  25846. USE_SETTER = true;
  25847. },
  25848. useSimple: function() {
  25849. USE_SETTER = false;
  25850. }
  25851. }
  25852. );
  25853. $(
  25854. { target: 'Object', stat: true, forced: !NATIVE_SYMBOL, sham: !DESCRIPTORS },
  25855. {
  25856. // `Object.create` method
  25857. // https://tc39.github.io/ecma262/#sec-object.create
  25858. create: $create,
  25859. // `Object.defineProperty` method
  25860. // https://tc39.github.io/ecma262/#sec-object.defineproperty
  25861. defineProperty: $defineProperty,
  25862. // `Object.defineProperties` method
  25863. // https://tc39.github.io/ecma262/#sec-object.defineproperties
  25864. defineProperties: $defineProperties,
  25865. // `Object.getOwnPropertyDescriptor` method
  25866. // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptors
  25867. getOwnPropertyDescriptor: $getOwnPropertyDescriptor
  25868. }
  25869. );
  25870. $(
  25871. { target: 'Object', stat: true, forced: !NATIVE_SYMBOL },
  25872. {
  25873. // `Object.getOwnPropertyNames` method
  25874. // https://tc39.github.io/ecma262/#sec-object.getownpropertynames
  25875. getOwnPropertyNames: $getOwnPropertyNames,
  25876. // `Object.getOwnPropertySymbols` method
  25877. // https://tc39.github.io/ecma262/#sec-object.getownpropertysymbols
  25878. getOwnPropertySymbols: $getOwnPropertySymbols
  25879. }
  25880. );
  25881. // Chrome 38 and 39 `Object.getOwnPropertySymbols` fails on primitives
  25882. // https://bugs.chromium.org/p/v8/issues/detail?id=3443
  25883. $(
  25884. {
  25885. target: 'Object',
  25886. stat: true,
  25887. forced: fails(function() {
  25888. getOwnPropertySymbolsModule.f(1);
  25889. })
  25890. },
  25891. {
  25892. getOwnPropertySymbols: function getOwnPropertySymbols(it) {
  25893. return getOwnPropertySymbolsModule.f(toObject(it));
  25894. }
  25895. }
  25896. );
  25897. // `JSON.stringify` method behavior with symbols
  25898. // https://tc39.github.io/ecma262/#sec-json.stringify
  25899. if ($stringify) {
  25900. var FORCED_JSON_STRINGIFY =
  25901. !NATIVE_SYMBOL ||
  25902. fails(function() {
  25903. var symbol = $Symbol();
  25904. // MS Edge converts symbol values to JSON as {}
  25905. return (
  25906. $stringify([symbol]) != '[null]' ||
  25907. // WebKit converts symbol values to JSON as null
  25908. $stringify({ a: symbol }) != '{}' ||
  25909. // V8 throws on boxed symbols
  25910. $stringify(Object(symbol)) != '{}'
  25911. );
  25912. });
  25913. $(
  25914. { target: 'JSON', stat: true, forced: FORCED_JSON_STRINGIFY },
  25915. {
  25916. // eslint-disable-next-line no-unused-vars
  25917. stringify: function stringify(it, replacer, space) {
  25918. var args = [it];
  25919. var index = 1;
  25920. var $replacer;
  25921. while (arguments.length > index) args.push(arguments[index++]);
  25922. $replacer = replacer;
  25923. if ((!isObject(replacer) && it === undefined) || isSymbol(it)) return; // IE8 returns string on undefined
  25924. if (!isArray(replacer))
  25925. replacer = function(key, value) {
  25926. if (typeof $replacer == 'function')
  25927. value = $replacer.call(this, key, value);
  25928. if (!isSymbol(value)) return value;
  25929. };
  25930. args[1] = replacer;
  25931. return $stringify.apply(null, args);
  25932. }
  25933. }
  25934. );
  25935. }
  25936. // `Symbol.prototype[@@toPrimitive]` method
  25937. // https://tc39.github.io/ecma262/#sec-symbol.prototype-@@toprimitive
  25938. if (!$Symbol[PROTOTYPE][TO_PRIMITIVE]) {
  25939. createNonEnumerableProperty(
  25940. $Symbol[PROTOTYPE],
  25941. TO_PRIMITIVE,
  25942. $Symbol[PROTOTYPE].valueOf
  25943. );
  25944. }
  25945. // `Symbol.prototype[@@toStringTag]` property
  25946. // https://tc39.github.io/ecma262/#sec-symbol.prototype-@@tostringtag
  25947. setToStringTag($Symbol, SYMBOL);
  25948. hiddenKeys[HIDDEN] = true;
  25949. },
  25950. {
  25951. '../internals/an-object': 28,
  25952. '../internals/array-iteration': 37,
  25953. '../internals/create-non-enumerable-property': 55,
  25954. '../internals/create-property-descriptor': 56,
  25955. '../internals/define-well-known-symbol': 59,
  25956. '../internals/descriptors': 60,
  25957. '../internals/export': 67,
  25958. '../internals/fails': 68,
  25959. '../internals/get-built-in': 73,
  25960. '../internals/global': 76,
  25961. '../internals/has': 77,
  25962. '../internals/hidden-keys': 78,
  25963. '../internals/internal-state': 87,
  25964. '../internals/is-array': 89,
  25965. '../internals/is-object': 91,
  25966. '../internals/is-pure': 92,
  25967. '../internals/native-symbol': 100,
  25968. '../internals/object-create': 107,
  25969. '../internals/object-define-property': 109,
  25970. '../internals/object-get-own-property-descriptor': 110,
  25971. '../internals/object-get-own-property-names': 112,
  25972. '../internals/object-get-own-property-names-external': 111,
  25973. '../internals/object-get-own-property-symbols': 113,
  25974. '../internals/object-keys': 116,
  25975. '../internals/object-property-is-enumerable': 117,
  25976. '../internals/redefine': 125,
  25977. '../internals/set-to-string-tag': 134,
  25978. '../internals/shared': 137,
  25979. '../internals/shared-key': 135,
  25980. '../internals/to-indexed-object': 149,
  25981. '../internals/to-object': 152,
  25982. '../internals/to-primitive': 155,
  25983. '../internals/uid': 160,
  25984. '../internals/use-symbol-as-uid': 161,
  25985. '../internals/well-known-symbol': 163,
  25986. '../internals/well-known-symbol-wrapped': 162
  25987. }
  25988. ],
  25989. 212: [
  25990. function(_dereq_, module, exports) {
  25991. 'use strict';
  25992. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  25993. var $copyWithin = _dereq_('../internals/array-copy-within');
  25994. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  25995. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  25996. // `%TypedArray%.prototype.copyWithin` method
  25997. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.copywithin
  25998. exportTypedArrayMethod('copyWithin', function copyWithin(
  25999. target,
  26000. start /* , end */
  26001. ) {
  26002. return $copyWithin.call(
  26003. aTypedArray(this),
  26004. target,
  26005. start,
  26006. arguments.length > 2 ? arguments[2] : undefined
  26007. );
  26008. });
  26009. },
  26010. { '../internals/array-buffer-view-core': 30, '../internals/array-copy-within': 32 }
  26011. ],
  26012. 213: [
  26013. function(_dereq_, module, exports) {
  26014. 'use strict';
  26015. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26016. var $every = _dereq_('../internals/array-iteration').every;
  26017. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26018. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26019. // `%TypedArray%.prototype.every` method
  26020. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.every
  26021. exportTypedArrayMethod('every', function every(callbackfn /* , thisArg */) {
  26022. return $every(
  26023. aTypedArray(this),
  26024. callbackfn,
  26025. arguments.length > 1 ? arguments[1] : undefined
  26026. );
  26027. });
  26028. },
  26029. { '../internals/array-buffer-view-core': 30, '../internals/array-iteration': 37 }
  26030. ],
  26031. 214: [
  26032. function(_dereq_, module, exports) {
  26033. 'use strict';
  26034. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26035. var $fill = _dereq_('../internals/array-fill');
  26036. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26037. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26038. // `%TypedArray%.prototype.fill` method
  26039. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.fill
  26040. // eslint-disable-next-line no-unused-vars
  26041. exportTypedArrayMethod('fill', function fill(value /* , start, end */) {
  26042. return $fill.apply(aTypedArray(this), arguments);
  26043. });
  26044. },
  26045. { '../internals/array-buffer-view-core': 30, '../internals/array-fill': 33 }
  26046. ],
  26047. 215: [
  26048. function(_dereq_, module, exports) {
  26049. 'use strict';
  26050. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26051. var $filter = _dereq_('../internals/array-iteration').filter;
  26052. var speciesConstructor = _dereq_('../internals/species-constructor');
  26053. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26054. var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor;
  26055. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26056. // `%TypedArray%.prototype.filter` method
  26057. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.filter
  26058. exportTypedArrayMethod('filter', function filter(callbackfn /* , thisArg */) {
  26059. var list = $filter(
  26060. aTypedArray(this),
  26061. callbackfn,
  26062. arguments.length > 1 ? arguments[1] : undefined
  26063. );
  26064. var C = speciesConstructor(this, this.constructor);
  26065. var index = 0;
  26066. var length = list.length;
  26067. var result = new (aTypedArrayConstructor(C))(length);
  26068. while (length > index) result[index] = list[index++];
  26069. return result;
  26070. });
  26071. },
  26072. {
  26073. '../internals/array-buffer-view-core': 30,
  26074. '../internals/array-iteration': 37,
  26075. '../internals/species-constructor': 138
  26076. }
  26077. ],
  26078. 216: [
  26079. function(_dereq_, module, exports) {
  26080. 'use strict';
  26081. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26082. var $findIndex = _dereq_('../internals/array-iteration').findIndex;
  26083. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26084. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26085. // `%TypedArray%.prototype.findIndex` method
  26086. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.findindex
  26087. exportTypedArrayMethod('findIndex', function findIndex(
  26088. predicate /* , thisArg */
  26089. ) {
  26090. return $findIndex(
  26091. aTypedArray(this),
  26092. predicate,
  26093. arguments.length > 1 ? arguments[1] : undefined
  26094. );
  26095. });
  26096. },
  26097. { '../internals/array-buffer-view-core': 30, '../internals/array-iteration': 37 }
  26098. ],
  26099. 217: [
  26100. function(_dereq_, module, exports) {
  26101. 'use strict';
  26102. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26103. var $find = _dereq_('../internals/array-iteration').find;
  26104. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26105. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26106. // `%TypedArray%.prototype.find` method
  26107. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.find
  26108. exportTypedArrayMethod('find', function find(predicate /* , thisArg */) {
  26109. return $find(
  26110. aTypedArray(this),
  26111. predicate,
  26112. arguments.length > 1 ? arguments[1] : undefined
  26113. );
  26114. });
  26115. },
  26116. { '../internals/array-buffer-view-core': 30, '../internals/array-iteration': 37 }
  26117. ],
  26118. 218: [
  26119. function(_dereq_, module, exports) {
  26120. var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor');
  26121. // `Float32Array` constructor
  26122. // https://tc39.github.io/ecma262/#sec-typedarray-objects
  26123. createTypedArrayConstructor('Float32', function(init) {
  26124. return function Float32Array(data, byteOffset, length) {
  26125. return init(this, data, byteOffset, length);
  26126. };
  26127. });
  26128. },
  26129. { '../internals/typed-array-constructor': 157 }
  26130. ],
  26131. 219: [
  26132. function(_dereq_, module, exports) {
  26133. var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor');
  26134. // `Float64Array` constructor
  26135. // https://tc39.github.io/ecma262/#sec-typedarray-objects
  26136. createTypedArrayConstructor('Float64', function(init) {
  26137. return function Float64Array(data, byteOffset, length) {
  26138. return init(this, data, byteOffset, length);
  26139. };
  26140. });
  26141. },
  26142. { '../internals/typed-array-constructor': 157 }
  26143. ],
  26144. 220: [
  26145. function(_dereq_, module, exports) {
  26146. 'use strict';
  26147. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26148. var $forEach = _dereq_('../internals/array-iteration').forEach;
  26149. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26150. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26151. // `%TypedArray%.prototype.forEach` method
  26152. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.foreach
  26153. exportTypedArrayMethod('forEach', function forEach(callbackfn /* , thisArg */) {
  26154. $forEach(
  26155. aTypedArray(this),
  26156. callbackfn,
  26157. arguments.length > 1 ? arguments[1] : undefined
  26158. );
  26159. });
  26160. },
  26161. { '../internals/array-buffer-view-core': 30, '../internals/array-iteration': 37 }
  26162. ],
  26163. 221: [
  26164. function(_dereq_, module, exports) {
  26165. 'use strict';
  26166. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26167. var $includes = _dereq_('../internals/array-includes').includes;
  26168. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26169. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26170. // `%TypedArray%.prototype.includes` method
  26171. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.includes
  26172. exportTypedArrayMethod('includes', function includes(
  26173. searchElement /* , fromIndex */
  26174. ) {
  26175. return $includes(
  26176. aTypedArray(this),
  26177. searchElement,
  26178. arguments.length > 1 ? arguments[1] : undefined
  26179. );
  26180. });
  26181. },
  26182. { '../internals/array-buffer-view-core': 30, '../internals/array-includes': 36 }
  26183. ],
  26184. 222: [
  26185. function(_dereq_, module, exports) {
  26186. 'use strict';
  26187. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26188. var $indexOf = _dereq_('../internals/array-includes').indexOf;
  26189. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26190. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26191. // `%TypedArray%.prototype.indexOf` method
  26192. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.indexof
  26193. exportTypedArrayMethod('indexOf', function indexOf(
  26194. searchElement /* , fromIndex */
  26195. ) {
  26196. return $indexOf(
  26197. aTypedArray(this),
  26198. searchElement,
  26199. arguments.length > 1 ? arguments[1] : undefined
  26200. );
  26201. });
  26202. },
  26203. { '../internals/array-buffer-view-core': 30, '../internals/array-includes': 36 }
  26204. ],
  26205. 223: [
  26206. function(_dereq_, module, exports) {
  26207. var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor');
  26208. // `Int16Array` constructor
  26209. // https://tc39.github.io/ecma262/#sec-typedarray-objects
  26210. createTypedArrayConstructor('Int16', function(init) {
  26211. return function Int16Array(data, byteOffset, length) {
  26212. return init(this, data, byteOffset, length);
  26213. };
  26214. });
  26215. },
  26216. { '../internals/typed-array-constructor': 157 }
  26217. ],
  26218. 224: [
  26219. function(_dereq_, module, exports) {
  26220. var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor');
  26221. // `Int32Array` constructor
  26222. // https://tc39.github.io/ecma262/#sec-typedarray-objects
  26223. createTypedArrayConstructor('Int32', function(init) {
  26224. return function Int32Array(data, byteOffset, length) {
  26225. return init(this, data, byteOffset, length);
  26226. };
  26227. });
  26228. },
  26229. { '../internals/typed-array-constructor': 157 }
  26230. ],
  26231. 225: [
  26232. function(_dereq_, module, exports) {
  26233. 'use strict';
  26234. var global = _dereq_('../internals/global');
  26235. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26236. var ArrayIterators = _dereq_('../modules/es.array.iterator');
  26237. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  26238. var ITERATOR = wellKnownSymbol('iterator');
  26239. var Uint8Array = global.Uint8Array;
  26240. var arrayValues = ArrayIterators.values;
  26241. var arrayKeys = ArrayIterators.keys;
  26242. var arrayEntries = ArrayIterators.entries;
  26243. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26244. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26245. var nativeTypedArrayIterator = Uint8Array && Uint8Array.prototype[ITERATOR];
  26246. var CORRECT_ITER_NAME =
  26247. !!nativeTypedArrayIterator &&
  26248. (nativeTypedArrayIterator.name == 'values' ||
  26249. nativeTypedArrayIterator.name == undefined);
  26250. var typedArrayValues = function values() {
  26251. return arrayValues.call(aTypedArray(this));
  26252. };
  26253. // `%TypedArray%.prototype.entries` method
  26254. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.entries
  26255. exportTypedArrayMethod('entries', function entries() {
  26256. return arrayEntries.call(aTypedArray(this));
  26257. });
  26258. // `%TypedArray%.prototype.keys` method
  26259. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.keys
  26260. exportTypedArrayMethod('keys', function keys() {
  26261. return arrayKeys.call(aTypedArray(this));
  26262. });
  26263. // `%TypedArray%.prototype.values` method
  26264. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.values
  26265. exportTypedArrayMethod('values', typedArrayValues, !CORRECT_ITER_NAME);
  26266. // `%TypedArray%.prototype[@@iterator]` method
  26267. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype-@@iterator
  26268. exportTypedArrayMethod(ITERATOR, typedArrayValues, !CORRECT_ITER_NAME);
  26269. },
  26270. {
  26271. '../internals/array-buffer-view-core': 30,
  26272. '../internals/global': 76,
  26273. '../internals/well-known-symbol': 163,
  26274. '../modules/es.array.iterator': 174
  26275. }
  26276. ],
  26277. 226: [
  26278. function(_dereq_, module, exports) {
  26279. 'use strict';
  26280. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26281. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26282. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26283. var $join = [].join;
  26284. // `%TypedArray%.prototype.join` method
  26285. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.join
  26286. // eslint-disable-next-line no-unused-vars
  26287. exportTypedArrayMethod('join', function join(separator) {
  26288. return $join.apply(aTypedArray(this), arguments);
  26289. });
  26290. },
  26291. { '../internals/array-buffer-view-core': 30 }
  26292. ],
  26293. 227: [
  26294. function(_dereq_, module, exports) {
  26295. 'use strict';
  26296. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26297. var $lastIndexOf = _dereq_('../internals/array-last-index-of');
  26298. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26299. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26300. // `%TypedArray%.prototype.lastIndexOf` method
  26301. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.lastindexof
  26302. // eslint-disable-next-line no-unused-vars
  26303. exportTypedArrayMethod('lastIndexOf', function lastIndexOf(
  26304. searchElement /* , fromIndex */
  26305. ) {
  26306. return $lastIndexOf.apply(aTypedArray(this), arguments);
  26307. });
  26308. },
  26309. {
  26310. '../internals/array-buffer-view-core': 30,
  26311. '../internals/array-last-index-of': 38
  26312. }
  26313. ],
  26314. 228: [
  26315. function(_dereq_, module, exports) {
  26316. 'use strict';
  26317. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26318. var $map = _dereq_('../internals/array-iteration').map;
  26319. var speciesConstructor = _dereq_('../internals/species-constructor');
  26320. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26321. var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor;
  26322. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26323. // `%TypedArray%.prototype.map` method
  26324. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.map
  26325. exportTypedArrayMethod('map', function map(mapfn /* , thisArg */) {
  26326. return $map(
  26327. aTypedArray(this),
  26328. mapfn,
  26329. arguments.length > 1 ? arguments[1] : undefined,
  26330. function(O, length) {
  26331. return new (aTypedArrayConstructor(speciesConstructor(O, O.constructor)))(
  26332. length
  26333. );
  26334. }
  26335. );
  26336. });
  26337. },
  26338. {
  26339. '../internals/array-buffer-view-core': 30,
  26340. '../internals/array-iteration': 37,
  26341. '../internals/species-constructor': 138
  26342. }
  26343. ],
  26344. 229: [
  26345. function(_dereq_, module, exports) {
  26346. 'use strict';
  26347. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26348. var $reduceRight = _dereq_('../internals/array-reduce').right;
  26349. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26350. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26351. // `%TypedArray%.prototype.reduceRicht` method
  26352. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.reduceright
  26353. exportTypedArrayMethod('reduceRight', function reduceRight(
  26354. callbackfn /* , initialValue */
  26355. ) {
  26356. return $reduceRight(
  26357. aTypedArray(this),
  26358. callbackfn,
  26359. arguments.length,
  26360. arguments.length > 1 ? arguments[1] : undefined
  26361. );
  26362. });
  26363. },
  26364. { '../internals/array-buffer-view-core': 30, '../internals/array-reduce': 42 }
  26365. ],
  26366. 230: [
  26367. function(_dereq_, module, exports) {
  26368. 'use strict';
  26369. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26370. var $reduce = _dereq_('../internals/array-reduce').left;
  26371. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26372. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26373. // `%TypedArray%.prototype.reduce` method
  26374. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.reduce
  26375. exportTypedArrayMethod('reduce', function reduce(
  26376. callbackfn /* , initialValue */
  26377. ) {
  26378. return $reduce(
  26379. aTypedArray(this),
  26380. callbackfn,
  26381. arguments.length,
  26382. arguments.length > 1 ? arguments[1] : undefined
  26383. );
  26384. });
  26385. },
  26386. { '../internals/array-buffer-view-core': 30, '../internals/array-reduce': 42 }
  26387. ],
  26388. 231: [
  26389. function(_dereq_, module, exports) {
  26390. 'use strict';
  26391. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26392. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26393. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26394. var floor = Math.floor;
  26395. // `%TypedArray%.prototype.reverse` method
  26396. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.reverse
  26397. exportTypedArrayMethod('reverse', function reverse() {
  26398. var that = this;
  26399. var length = aTypedArray(that).length;
  26400. var middle = floor(length / 2);
  26401. var index = 0;
  26402. var value;
  26403. while (index < middle) {
  26404. value = that[index];
  26405. that[index++] = that[--length];
  26406. that[length] = value;
  26407. }
  26408. return that;
  26409. });
  26410. },
  26411. { '../internals/array-buffer-view-core': 30 }
  26412. ],
  26413. 232: [
  26414. function(_dereq_, module, exports) {
  26415. 'use strict';
  26416. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26417. var toLength = _dereq_('../internals/to-length');
  26418. var toOffset = _dereq_('../internals/to-offset');
  26419. var toObject = _dereq_('../internals/to-object');
  26420. var fails = _dereq_('../internals/fails');
  26421. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26422. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26423. var FORCED = fails(function() {
  26424. // eslint-disable-next-line no-undef
  26425. new Int8Array(1).set({});
  26426. });
  26427. // `%TypedArray%.prototype.set` method
  26428. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.set
  26429. exportTypedArrayMethod(
  26430. 'set',
  26431. function set(arrayLike /* , offset */) {
  26432. aTypedArray(this);
  26433. var offset = toOffset(arguments.length > 1 ? arguments[1] : undefined, 1);
  26434. var length = this.length;
  26435. var src = toObject(arrayLike);
  26436. var len = toLength(src.length);
  26437. var index = 0;
  26438. if (len + offset > length) throw RangeError('Wrong length');
  26439. while (index < len) this[offset + index] = src[index++];
  26440. },
  26441. FORCED
  26442. );
  26443. },
  26444. {
  26445. '../internals/array-buffer-view-core': 30,
  26446. '../internals/fails': 68,
  26447. '../internals/to-length': 151,
  26448. '../internals/to-object': 152,
  26449. '../internals/to-offset': 153
  26450. }
  26451. ],
  26452. 233: [
  26453. function(_dereq_, module, exports) {
  26454. 'use strict';
  26455. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26456. var speciesConstructor = _dereq_('../internals/species-constructor');
  26457. var fails = _dereq_('../internals/fails');
  26458. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26459. var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor;
  26460. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26461. var $slice = [].slice;
  26462. var FORCED = fails(function() {
  26463. // eslint-disable-next-line no-undef
  26464. new Int8Array(1).slice();
  26465. });
  26466. // `%TypedArray%.prototype.slice` method
  26467. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.slice
  26468. exportTypedArrayMethod(
  26469. 'slice',
  26470. function slice(start, end) {
  26471. var list = $slice.call(aTypedArray(this), start, end);
  26472. var C = speciesConstructor(this, this.constructor);
  26473. var index = 0;
  26474. var length = list.length;
  26475. var result = new (aTypedArrayConstructor(C))(length);
  26476. while (length > index) result[index] = list[index++];
  26477. return result;
  26478. },
  26479. FORCED
  26480. );
  26481. },
  26482. {
  26483. '../internals/array-buffer-view-core': 30,
  26484. '../internals/fails': 68,
  26485. '../internals/species-constructor': 138
  26486. }
  26487. ],
  26488. 234: [
  26489. function(_dereq_, module, exports) {
  26490. 'use strict';
  26491. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26492. var $some = _dereq_('../internals/array-iteration').some;
  26493. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26494. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26495. // `%TypedArray%.prototype.some` method
  26496. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.some
  26497. exportTypedArrayMethod('some', function some(callbackfn /* , thisArg */) {
  26498. return $some(
  26499. aTypedArray(this),
  26500. callbackfn,
  26501. arguments.length > 1 ? arguments[1] : undefined
  26502. );
  26503. });
  26504. },
  26505. { '../internals/array-buffer-view-core': 30, '../internals/array-iteration': 37 }
  26506. ],
  26507. 235: [
  26508. function(_dereq_, module, exports) {
  26509. 'use strict';
  26510. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26511. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26512. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26513. var $sort = [].sort;
  26514. // `%TypedArray%.prototype.sort` method
  26515. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.sort
  26516. exportTypedArrayMethod('sort', function sort(comparefn) {
  26517. return $sort.call(aTypedArray(this), comparefn);
  26518. });
  26519. },
  26520. { '../internals/array-buffer-view-core': 30 }
  26521. ],
  26522. 236: [
  26523. function(_dereq_, module, exports) {
  26524. 'use strict';
  26525. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26526. var toLength = _dereq_('../internals/to-length');
  26527. var toAbsoluteIndex = _dereq_('../internals/to-absolute-index');
  26528. var speciesConstructor = _dereq_('../internals/species-constructor');
  26529. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26530. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26531. // `%TypedArray%.prototype.subarray` method
  26532. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.subarray
  26533. exportTypedArrayMethod('subarray', function subarray(begin, end) {
  26534. var O = aTypedArray(this);
  26535. var length = O.length;
  26536. var beginIndex = toAbsoluteIndex(begin, length);
  26537. return new (speciesConstructor(
  26538. O,
  26539. O.constructor
  26540. ))(O.buffer, O.byteOffset + beginIndex * O.BYTES_PER_ELEMENT, toLength((end === undefined ? length : toAbsoluteIndex(end, length)) - beginIndex));
  26541. });
  26542. },
  26543. {
  26544. '../internals/array-buffer-view-core': 30,
  26545. '../internals/species-constructor': 138,
  26546. '../internals/to-absolute-index': 147,
  26547. '../internals/to-length': 151
  26548. }
  26549. ],
  26550. 237: [
  26551. function(_dereq_, module, exports) {
  26552. 'use strict';
  26553. var global = _dereq_('../internals/global');
  26554. var ArrayBufferViewCore = _dereq_('../internals/array-buffer-view-core');
  26555. var fails = _dereq_('../internals/fails');
  26556. var Int8Array = global.Int8Array;
  26557. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  26558. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  26559. var $toLocaleString = [].toLocaleString;
  26560. var $slice = [].slice;
  26561. // iOS Safari 6.x fails here
  26562. var TO_LOCALE_STRING_BUG =
  26563. !!Int8Array &&
  26564. fails(function() {
  26565. $toLocaleString.call(new Int8Array(1));
  26566. });
  26567. var FORCED =
  26568. fails(function() {
  26569. return [1, 2].toLocaleString() != new Int8Array([1, 2]).toLocaleString();
  26570. }) ||
  26571. !fails(function() {
  26572. Int8Array.prototype.toLocaleString.call([1, 2]);
  26573. });
  26574. // `%TypedArray%.prototype.toLocaleString` method
  26575. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.tolocalestring
  26576. exportTypedArrayMethod(
  26577. 'toLocaleString',
  26578. function toLocaleString() {
  26579. return $toLocaleString.apply(
  26580. TO_LOCALE_STRING_BUG ? $slice.call(aTypedArray(this)) : aTypedArray(this),
  26581. arguments
  26582. );
  26583. },
  26584. FORCED
  26585. );
  26586. },
  26587. {
  26588. '../internals/array-buffer-view-core': 30,
  26589. '../internals/fails': 68,
  26590. '../internals/global': 76
  26591. }
  26592. ],
  26593. 238: [
  26594. function(_dereq_, module, exports) {
  26595. 'use strict';
  26596. var exportTypedArrayMethod = _dereq_('../internals/array-buffer-view-core')
  26597. .exportTypedArrayMethod;
  26598. var fails = _dereq_('../internals/fails');
  26599. var global = _dereq_('../internals/global');
  26600. var Uint8Array = global.Uint8Array;
  26601. var Uint8ArrayPrototype = (Uint8Array && Uint8Array.prototype) || {};
  26602. var arrayToString = [].toString;
  26603. var arrayJoin = [].join;
  26604. if (
  26605. fails(function() {
  26606. arrayToString.call({});
  26607. })
  26608. ) {
  26609. arrayToString = function toString() {
  26610. return arrayJoin.call(this);
  26611. };
  26612. }
  26613. var IS_NOT_ARRAY_METHOD = Uint8ArrayPrototype.toString != arrayToString;
  26614. // `%TypedArray%.prototype.toString` method
  26615. // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.tostring
  26616. exportTypedArrayMethod('toString', arrayToString, IS_NOT_ARRAY_METHOD);
  26617. },
  26618. {
  26619. '../internals/array-buffer-view-core': 30,
  26620. '../internals/fails': 68,
  26621. '../internals/global': 76
  26622. }
  26623. ],
  26624. 239: [
  26625. function(_dereq_, module, exports) {
  26626. var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor');
  26627. // `Uint16Array` constructor
  26628. // https://tc39.github.io/ecma262/#sec-typedarray-objects
  26629. createTypedArrayConstructor('Uint16', function(init) {
  26630. return function Uint16Array(data, byteOffset, length) {
  26631. return init(this, data, byteOffset, length);
  26632. };
  26633. });
  26634. },
  26635. { '../internals/typed-array-constructor': 157 }
  26636. ],
  26637. 240: [
  26638. function(_dereq_, module, exports) {
  26639. var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor');
  26640. // `Uint32Array` constructor
  26641. // https://tc39.github.io/ecma262/#sec-typedarray-objects
  26642. createTypedArrayConstructor('Uint32', function(init) {
  26643. return function Uint32Array(data, byteOffset, length) {
  26644. return init(this, data, byteOffset, length);
  26645. };
  26646. });
  26647. },
  26648. { '../internals/typed-array-constructor': 157 }
  26649. ],
  26650. 241: [
  26651. function(_dereq_, module, exports) {
  26652. var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor');
  26653. // `Uint8Array` constructor
  26654. // https://tc39.github.io/ecma262/#sec-typedarray-objects
  26655. createTypedArrayConstructor('Uint8', function(init) {
  26656. return function Uint8Array(data, byteOffset, length) {
  26657. return init(this, data, byteOffset, length);
  26658. };
  26659. });
  26660. },
  26661. { '../internals/typed-array-constructor': 157 }
  26662. ],
  26663. 242: [
  26664. function(_dereq_, module, exports) {
  26665. var createTypedArrayConstructor = _dereq_('../internals/typed-array-constructor');
  26666. // `Uint8ClampedArray` constructor
  26667. // https://tc39.github.io/ecma262/#sec-typedarray-objects
  26668. createTypedArrayConstructor(
  26669. 'Uint8',
  26670. function(init) {
  26671. return function Uint8ClampedArray(data, byteOffset, length) {
  26672. return init(this, data, byteOffset, length);
  26673. };
  26674. },
  26675. true
  26676. );
  26677. },
  26678. { '../internals/typed-array-constructor': 157 }
  26679. ],
  26680. 243: [
  26681. function(_dereq_, module, exports) {
  26682. var global = _dereq_('../internals/global');
  26683. var DOMIterables = _dereq_('../internals/dom-iterables');
  26684. var forEach = _dereq_('../internals/array-for-each');
  26685. var createNonEnumerableProperty = _dereq_(
  26686. '../internals/create-non-enumerable-property'
  26687. );
  26688. for (var COLLECTION_NAME in DOMIterables) {
  26689. var Collection = global[COLLECTION_NAME];
  26690. var CollectionPrototype = Collection && Collection.prototype;
  26691. // some Chrome versions have non-configurable methods on DOMTokenList
  26692. if (CollectionPrototype && CollectionPrototype.forEach !== forEach)
  26693. try {
  26694. createNonEnumerableProperty(CollectionPrototype, 'forEach', forEach);
  26695. } catch (error) {
  26696. CollectionPrototype.forEach = forEach;
  26697. }
  26698. }
  26699. },
  26700. {
  26701. '../internals/array-for-each': 34,
  26702. '../internals/create-non-enumerable-property': 55,
  26703. '../internals/dom-iterables': 62,
  26704. '../internals/global': 76
  26705. }
  26706. ],
  26707. 244: [
  26708. function(_dereq_, module, exports) {
  26709. var global = _dereq_('../internals/global');
  26710. var DOMIterables = _dereq_('../internals/dom-iterables');
  26711. var ArrayIteratorMethods = _dereq_('../modules/es.array.iterator');
  26712. var createNonEnumerableProperty = _dereq_(
  26713. '../internals/create-non-enumerable-property'
  26714. );
  26715. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  26716. var ITERATOR = wellKnownSymbol('iterator');
  26717. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  26718. var ArrayValues = ArrayIteratorMethods.values;
  26719. for (var COLLECTION_NAME in DOMIterables) {
  26720. var Collection = global[COLLECTION_NAME];
  26721. var CollectionPrototype = Collection && Collection.prototype;
  26722. if (CollectionPrototype) {
  26723. // some Chrome versions have non-configurable methods on DOMTokenList
  26724. if (CollectionPrototype[ITERATOR] !== ArrayValues)
  26725. try {
  26726. createNonEnumerableProperty(CollectionPrototype, ITERATOR, ArrayValues);
  26727. } catch (error) {
  26728. CollectionPrototype[ITERATOR] = ArrayValues;
  26729. }
  26730. if (!CollectionPrototype[TO_STRING_TAG]) {
  26731. createNonEnumerableProperty(
  26732. CollectionPrototype,
  26733. TO_STRING_TAG,
  26734. COLLECTION_NAME
  26735. );
  26736. }
  26737. if (DOMIterables[COLLECTION_NAME])
  26738. for (var METHOD_NAME in ArrayIteratorMethods) {
  26739. // some Chrome versions have non-configurable methods on DOMTokenList
  26740. if (
  26741. CollectionPrototype[METHOD_NAME] !== ArrayIteratorMethods[METHOD_NAME]
  26742. )
  26743. try {
  26744. createNonEnumerableProperty(
  26745. CollectionPrototype,
  26746. METHOD_NAME,
  26747. ArrayIteratorMethods[METHOD_NAME]
  26748. );
  26749. } catch (error) {
  26750. CollectionPrototype[METHOD_NAME] = ArrayIteratorMethods[METHOD_NAME];
  26751. }
  26752. }
  26753. }
  26754. }
  26755. },
  26756. {
  26757. '../internals/create-non-enumerable-property': 55,
  26758. '../internals/dom-iterables': 62,
  26759. '../internals/global': 76,
  26760. '../internals/well-known-symbol': 163,
  26761. '../modules/es.array.iterator': 174
  26762. }
  26763. ],
  26764. 245: [
  26765. function(_dereq_, module, exports) {
  26766. 'use strict';
  26767. // TODO: in core-js@4, move /modules/ dependencies to public entries for better optimization by tools like `preset-env`
  26768. _dereq_('../modules/es.array.iterator');
  26769. var $ = _dereq_('../internals/export');
  26770. var getBuiltIn = _dereq_('../internals/get-built-in');
  26771. var USE_NATIVE_URL = _dereq_('../internals/native-url');
  26772. var redefine = _dereq_('../internals/redefine');
  26773. var redefineAll = _dereq_('../internals/redefine-all');
  26774. var setToStringTag = _dereq_('../internals/set-to-string-tag');
  26775. var createIteratorConstructor = _dereq_(
  26776. '../internals/create-iterator-constructor'
  26777. );
  26778. var InternalStateModule = _dereq_('../internals/internal-state');
  26779. var anInstance = _dereq_('../internals/an-instance');
  26780. var hasOwn = _dereq_('../internals/has');
  26781. var bind = _dereq_('../internals/function-bind-context');
  26782. var classof = _dereq_('../internals/classof');
  26783. var anObject = _dereq_('../internals/an-object');
  26784. var isObject = _dereq_('../internals/is-object');
  26785. var create = _dereq_('../internals/object-create');
  26786. var createPropertyDescriptor = _dereq_('../internals/create-property-descriptor');
  26787. var getIterator = _dereq_('../internals/get-iterator');
  26788. var getIteratorMethod = _dereq_('../internals/get-iterator-method');
  26789. var wellKnownSymbol = _dereq_('../internals/well-known-symbol');
  26790. var $fetch = getBuiltIn('fetch');
  26791. var Headers = getBuiltIn('Headers');
  26792. var ITERATOR = wellKnownSymbol('iterator');
  26793. var URL_SEARCH_PARAMS = 'URLSearchParams';
  26794. var URL_SEARCH_PARAMS_ITERATOR = URL_SEARCH_PARAMS + 'Iterator';
  26795. var setInternalState = InternalStateModule.set;
  26796. var getInternalParamsState = InternalStateModule.getterFor(URL_SEARCH_PARAMS);
  26797. var getInternalIteratorState = InternalStateModule.getterFor(
  26798. URL_SEARCH_PARAMS_ITERATOR
  26799. );
  26800. var plus = /\+/g;
  26801. var sequences = Array(4);
  26802. var percentSequence = function(bytes) {
  26803. return (
  26804. sequences[bytes - 1] ||
  26805. (sequences[bytes - 1] = RegExp('((?:%[\\da-f]{2}){' + bytes + '})', 'gi'))
  26806. );
  26807. };
  26808. var percentDecode = function(sequence) {
  26809. try {
  26810. return decodeURIComponent(sequence);
  26811. } catch (error) {
  26812. return sequence;
  26813. }
  26814. };
  26815. var deserialize = function(it) {
  26816. var result = it.replace(plus, ' ');
  26817. var bytes = 4;
  26818. try {
  26819. return decodeURIComponent(result);
  26820. } catch (error) {
  26821. while (bytes) {
  26822. result = result.replace(percentSequence(bytes--), percentDecode);
  26823. }
  26824. return result;
  26825. }
  26826. };
  26827. var find = /[!'()~]|%20/g;
  26828. var replace = {
  26829. '!': '%21',
  26830. "'": '%27',
  26831. '(': '%28',
  26832. ')': '%29',
  26833. '~': '%7E',
  26834. '%20': '+'
  26835. };
  26836. var replacer = function(match) {
  26837. return replace[match];
  26838. };
  26839. var serialize = function(it) {
  26840. return encodeURIComponent(it).replace(find, replacer);
  26841. };
  26842. var parseSearchParams = function(result, query) {
  26843. if (query) {
  26844. var attributes = query.split('&');
  26845. var index = 0;
  26846. var attribute, entry;
  26847. while (index < attributes.length) {
  26848. attribute = attributes[index++];
  26849. if (attribute.length) {
  26850. entry = attribute.split('=');
  26851. result.push({
  26852. key: deserialize(entry.shift()),
  26853. value: deserialize(entry.join('='))
  26854. });
  26855. }
  26856. }
  26857. }
  26858. };
  26859. var updateSearchParams = function(query) {
  26860. this.entries.length = 0;
  26861. parseSearchParams(this.entries, query);
  26862. };
  26863. var validateArgumentsLength = function(passed, required) {
  26864. if (passed < required) throw TypeError('Not enough arguments');
  26865. };
  26866. var URLSearchParamsIterator = createIteratorConstructor(
  26867. function Iterator(params, kind) {
  26868. setInternalState(this, {
  26869. type: URL_SEARCH_PARAMS_ITERATOR,
  26870. iterator: getIterator(getInternalParamsState(params).entries),
  26871. kind: kind
  26872. });
  26873. },
  26874. 'Iterator',
  26875. function next() {
  26876. var state = getInternalIteratorState(this);
  26877. var kind = state.kind;
  26878. var step = state.iterator.next();
  26879. var entry = step.value;
  26880. if (!step.done) {
  26881. step.value =
  26882. kind === 'keys'
  26883. ? entry.key
  26884. : kind === 'values' ? entry.value : [entry.key, entry.value];
  26885. }
  26886. return step;
  26887. }
  26888. );
  26889. // `URLSearchParams` constructor
  26890. // https://url.spec.whatwg.org/#interface-urlsearchparams
  26891. var URLSearchParamsConstructor = function URLSearchParams(/* init */) {
  26892. anInstance(this, URLSearchParamsConstructor, URL_SEARCH_PARAMS);
  26893. var init = arguments.length > 0 ? arguments[0] : undefined;
  26894. var that = this;
  26895. var entries = [];
  26896. var iteratorMethod,
  26897. iterator,
  26898. next,
  26899. step,
  26900. entryIterator,
  26901. entryNext,
  26902. first,
  26903. second,
  26904. key;
  26905. setInternalState(that, {
  26906. type: URL_SEARCH_PARAMS,
  26907. entries: entries,
  26908. updateURL: function() {
  26909. /* empty */
  26910. },
  26911. updateSearchParams: updateSearchParams
  26912. });
  26913. if (init !== undefined) {
  26914. if (isObject(init)) {
  26915. iteratorMethod = getIteratorMethod(init);
  26916. if (typeof iteratorMethod === 'function') {
  26917. iterator = iteratorMethod.call(init);
  26918. next = iterator.next;
  26919. while (!(step = next.call(iterator)).done) {
  26920. entryIterator = getIterator(anObject(step.value));
  26921. entryNext = entryIterator.next;
  26922. if (
  26923. (first = entryNext.call(entryIterator)).done ||
  26924. (second = entryNext.call(entryIterator)).done ||
  26925. !entryNext.call(entryIterator).done
  26926. )
  26927. throw TypeError('Expected sequence with length 2');
  26928. entries.push({ key: first.value + '', value: second.value + '' });
  26929. }
  26930. } else
  26931. for (key in init)
  26932. if (hasOwn(init, key))
  26933. entries.push({ key: key, value: init[key] + '' });
  26934. } else {
  26935. parseSearchParams(
  26936. entries,
  26937. typeof init === 'string'
  26938. ? init.charAt(0) === '?' ? init.slice(1) : init
  26939. : init + ''
  26940. );
  26941. }
  26942. }
  26943. };
  26944. var URLSearchParamsPrototype = URLSearchParamsConstructor.prototype;
  26945. redefineAll(
  26946. URLSearchParamsPrototype,
  26947. {
  26948. // `URLSearchParams.prototype.appent` method
  26949. // https://url.spec.whatwg.org/#dom-urlsearchparams-append
  26950. append: function append(name, value) {
  26951. validateArgumentsLength(arguments.length, 2);
  26952. var state = getInternalParamsState(this);
  26953. state.entries.push({ key: name + '', value: value + '' });
  26954. state.updateURL();
  26955. },
  26956. // `URLSearchParams.prototype.delete` method
  26957. // https://url.spec.whatwg.org/#dom-urlsearchparams-delete
  26958. delete: function(name) {
  26959. validateArgumentsLength(arguments.length, 1);
  26960. var state = getInternalParamsState(this);
  26961. var entries = state.entries;
  26962. var key = name + '';
  26963. var index = 0;
  26964. while (index < entries.length) {
  26965. if (entries[index].key === key) entries.splice(index, 1);
  26966. else index++;
  26967. }
  26968. state.updateURL();
  26969. },
  26970. // `URLSearchParams.prototype.get` method
  26971. // https://url.spec.whatwg.org/#dom-urlsearchparams-get
  26972. get: function get(name) {
  26973. validateArgumentsLength(arguments.length, 1);
  26974. var entries = getInternalParamsState(this).entries;
  26975. var key = name + '';
  26976. var index = 0;
  26977. for (; index < entries.length; index++) {
  26978. if (entries[index].key === key) return entries[index].value;
  26979. }
  26980. return null;
  26981. },
  26982. // `URLSearchParams.prototype.getAll` method
  26983. // https://url.spec.whatwg.org/#dom-urlsearchparams-getall
  26984. getAll: function getAll(name) {
  26985. validateArgumentsLength(arguments.length, 1);
  26986. var entries = getInternalParamsState(this).entries;
  26987. var key = name + '';
  26988. var result = [];
  26989. var index = 0;
  26990. for (; index < entries.length; index++) {
  26991. if (entries[index].key === key) result.push(entries[index].value);
  26992. }
  26993. return result;
  26994. },
  26995. // `URLSearchParams.prototype.has` method
  26996. // https://url.spec.whatwg.org/#dom-urlsearchparams-has
  26997. has: function has(name) {
  26998. validateArgumentsLength(arguments.length, 1);
  26999. var entries = getInternalParamsState(this).entries;
  27000. var key = name + '';
  27001. var index = 0;
  27002. while (index < entries.length) {
  27003. if (entries[index++].key === key) return true;
  27004. }
  27005. return false;
  27006. },
  27007. // `URLSearchParams.prototype.set` method
  27008. // https://url.spec.whatwg.org/#dom-urlsearchparams-set
  27009. set: function set(name, value) {
  27010. validateArgumentsLength(arguments.length, 1);
  27011. var state = getInternalParamsState(this);
  27012. var entries = state.entries;
  27013. var found = false;
  27014. var key = name + '';
  27015. var val = value + '';
  27016. var index = 0;
  27017. var entry;
  27018. for (; index < entries.length; index++) {
  27019. entry = entries[index];
  27020. if (entry.key === key) {
  27021. if (found) entries.splice(index--, 1);
  27022. else {
  27023. found = true;
  27024. entry.value = val;
  27025. }
  27026. }
  27027. }
  27028. if (!found) entries.push({ key: key, value: val });
  27029. state.updateURL();
  27030. },
  27031. // `URLSearchParams.prototype.sort` method
  27032. // https://url.spec.whatwg.org/#dom-urlsearchparams-sort
  27033. sort: function sort() {
  27034. var state = getInternalParamsState(this);
  27035. var entries = state.entries;
  27036. // Array#sort is not stable in some engines
  27037. var slice = entries.slice();
  27038. var entry, entriesIndex, sliceIndex;
  27039. entries.length = 0;
  27040. for (sliceIndex = 0; sliceIndex < slice.length; sliceIndex++) {
  27041. entry = slice[sliceIndex];
  27042. for (entriesIndex = 0; entriesIndex < sliceIndex; entriesIndex++) {
  27043. if (entries[entriesIndex].key > entry.key) {
  27044. entries.splice(entriesIndex, 0, entry);
  27045. break;
  27046. }
  27047. }
  27048. if (entriesIndex === sliceIndex) entries.push(entry);
  27049. }
  27050. state.updateURL();
  27051. },
  27052. // `URLSearchParams.prototype.forEach` method
  27053. forEach: function forEach(callback /* , thisArg */) {
  27054. var entries = getInternalParamsState(this).entries;
  27055. var boundFunction = bind(
  27056. callback,
  27057. arguments.length > 1 ? arguments[1] : undefined,
  27058. 3
  27059. );
  27060. var index = 0;
  27061. var entry;
  27062. while (index < entries.length) {
  27063. entry = entries[index++];
  27064. boundFunction(entry.value, entry.key, this);
  27065. }
  27066. },
  27067. // `URLSearchParams.prototype.keys` method
  27068. keys: function keys() {
  27069. return new URLSearchParamsIterator(this, 'keys');
  27070. },
  27071. // `URLSearchParams.prototype.values` method
  27072. values: function values() {
  27073. return new URLSearchParamsIterator(this, 'values');
  27074. },
  27075. // `URLSearchParams.prototype.entries` method
  27076. entries: function entries() {
  27077. return new URLSearchParamsIterator(this, 'entries');
  27078. }
  27079. },
  27080. { enumerable: true }
  27081. );
  27082. // `URLSearchParams.prototype[@@iterator]` method
  27083. redefine(URLSearchParamsPrototype, ITERATOR, URLSearchParamsPrototype.entries);
  27084. // `URLSearchParams.prototype.toString` method
  27085. // https://url.spec.whatwg.org/#urlsearchparams-stringification-behavior
  27086. redefine(
  27087. URLSearchParamsPrototype,
  27088. 'toString',
  27089. function toString() {
  27090. var entries = getInternalParamsState(this).entries;
  27091. var result = [];
  27092. var index = 0;
  27093. var entry;
  27094. while (index < entries.length) {
  27095. entry = entries[index++];
  27096. result.push(serialize(entry.key) + '=' + serialize(entry.value));
  27097. }
  27098. return result.join('&');
  27099. },
  27100. { enumerable: true }
  27101. );
  27102. setToStringTag(URLSearchParamsConstructor, URL_SEARCH_PARAMS);
  27103. $(
  27104. { global: true, forced: !USE_NATIVE_URL },
  27105. {
  27106. URLSearchParams: URLSearchParamsConstructor
  27107. }
  27108. );
  27109. // Wrap `fetch` for correct work with polyfilled `URLSearchParams`
  27110. // https://github.com/zloirock/core-js/issues/674
  27111. if (
  27112. !USE_NATIVE_URL &&
  27113. typeof $fetch == 'function' &&
  27114. typeof Headers == 'function'
  27115. ) {
  27116. $(
  27117. { global: true, enumerable: true, forced: true },
  27118. {
  27119. fetch: function fetch(input /* , init */) {
  27120. var args = [input];
  27121. var init, body, headers;
  27122. if (arguments.length > 1) {
  27123. init = arguments[1];
  27124. if (isObject(init)) {
  27125. body = init.body;
  27126. if (classof(body) === URL_SEARCH_PARAMS) {
  27127. headers = init.headers ? new Headers(init.headers) : new Headers();
  27128. if (!headers.has('content-type')) {
  27129. headers.set(
  27130. 'content-type',
  27131. 'application/x-www-form-urlencoded;charset=UTF-8'
  27132. );
  27133. }
  27134. init = create(init, {
  27135. body: createPropertyDescriptor(0, String(body)),
  27136. headers: createPropertyDescriptor(0, headers)
  27137. });
  27138. }
  27139. }
  27140. args.push(init);
  27141. }
  27142. return $fetch.apply(this, args);
  27143. }
  27144. }
  27145. );
  27146. }
  27147. module.exports = {
  27148. URLSearchParams: URLSearchParamsConstructor,
  27149. getState: getInternalParamsState
  27150. };
  27151. },
  27152. {
  27153. '../internals/an-instance': 27,
  27154. '../internals/an-object': 28,
  27155. '../internals/classof': 47,
  27156. '../internals/create-iterator-constructor': 54,
  27157. '../internals/create-property-descriptor': 56,
  27158. '../internals/export': 67,
  27159. '../internals/function-bind-context': 71,
  27160. '../internals/get-built-in': 73,
  27161. '../internals/get-iterator': 75,
  27162. '../internals/get-iterator-method': 74,
  27163. '../internals/has': 77,
  27164. '../internals/internal-state': 87,
  27165. '../internals/is-object': 91,
  27166. '../internals/native-url': 101,
  27167. '../internals/object-create': 107,
  27168. '../internals/redefine': 125,
  27169. '../internals/redefine-all': 124,
  27170. '../internals/set-to-string-tag': 134,
  27171. '../internals/well-known-symbol': 163,
  27172. '../modules/es.array.iterator': 174
  27173. }
  27174. ],
  27175. 246: [
  27176. function(_dereq_, module, exports) {
  27177. 'use strict';
  27178. // TODO: in core-js@4, move /modules/ dependencies to public entries for better optimization by tools like `preset-env`
  27179. _dereq_('../modules/es.string.iterator');
  27180. var $ = _dereq_('../internals/export');
  27181. var DESCRIPTORS = _dereq_('../internals/descriptors');
  27182. var USE_NATIVE_URL = _dereq_('../internals/native-url');
  27183. var global = _dereq_('../internals/global');
  27184. var defineProperties = _dereq_('../internals/object-define-properties');
  27185. var redefine = _dereq_('../internals/redefine');
  27186. var anInstance = _dereq_('../internals/an-instance');
  27187. var has = _dereq_('../internals/has');
  27188. var assign = _dereq_('../internals/object-assign');
  27189. var arrayFrom = _dereq_('../internals/array-from');
  27190. var codeAt = _dereq_('../internals/string-multibyte').codeAt;
  27191. var toASCII = _dereq_('../internals/string-punycode-to-ascii');
  27192. var setToStringTag = _dereq_('../internals/set-to-string-tag');
  27193. var URLSearchParamsModule = _dereq_('../modules/web.url-search-params');
  27194. var InternalStateModule = _dereq_('../internals/internal-state');
  27195. var NativeURL = global.URL;
  27196. var URLSearchParams = URLSearchParamsModule.URLSearchParams;
  27197. var getInternalSearchParamsState = URLSearchParamsModule.getState;
  27198. var setInternalState = InternalStateModule.set;
  27199. var getInternalURLState = InternalStateModule.getterFor('URL');
  27200. var floor = Math.floor;
  27201. var pow = Math.pow;
  27202. var INVALID_AUTHORITY = 'Invalid authority';
  27203. var INVALID_SCHEME = 'Invalid scheme';
  27204. var INVALID_HOST = 'Invalid host';
  27205. var INVALID_PORT = 'Invalid port';
  27206. var ALPHA = /[A-Za-z]/;
  27207. var ALPHANUMERIC = /[\d+-.A-Za-z]/;
  27208. var DIGIT = /\d/;
  27209. var HEX_START = /^(0x|0X)/;
  27210. var OCT = /^[0-7]+$/;
  27211. var DEC = /^\d+$/;
  27212. var HEX = /^[\dA-Fa-f]+$/;
  27213. // eslint-disable-next-line no-control-regex
  27214. var FORBIDDEN_HOST_CODE_POINT = /[\u0000\u0009\u000A\u000D #%/:?@[\\]]/;
  27215. // eslint-disable-next-line no-control-regex
  27216. var FORBIDDEN_HOST_CODE_POINT_EXCLUDING_PERCENT = /[\u0000\u0009\u000A\u000D #/:?@[\\]]/;
  27217. // eslint-disable-next-line no-control-regex
  27218. var LEADING_AND_TRAILING_C0_CONTROL_OR_SPACE = /^[\u0000-\u001F ]+|[\u0000-\u001F ]+$/g;
  27219. // eslint-disable-next-line no-control-regex
  27220. var TAB_AND_NEW_LINE = /[\u0009\u000A\u000D]/g;
  27221. var EOF;
  27222. var parseHost = function(url, input) {
  27223. var result, codePoints, index;
  27224. if (input.charAt(0) == '[') {
  27225. if (input.charAt(input.length - 1) != ']') return INVALID_HOST;
  27226. result = parseIPv6(input.slice(1, -1));
  27227. if (!result) return INVALID_HOST;
  27228. url.host = result;
  27229. // opaque host
  27230. } else if (!isSpecial(url)) {
  27231. if (FORBIDDEN_HOST_CODE_POINT_EXCLUDING_PERCENT.test(input))
  27232. return INVALID_HOST;
  27233. result = '';
  27234. codePoints = arrayFrom(input);
  27235. for (index = 0; index < codePoints.length; index++) {
  27236. result += percentEncode(codePoints[index], C0ControlPercentEncodeSet);
  27237. }
  27238. url.host = result;
  27239. } else {
  27240. input = toASCII(input);
  27241. if (FORBIDDEN_HOST_CODE_POINT.test(input)) return INVALID_HOST;
  27242. result = parseIPv4(input);
  27243. if (result === null) return INVALID_HOST;
  27244. url.host = result;
  27245. }
  27246. };
  27247. var parseIPv4 = function(input) {
  27248. var parts = input.split('.');
  27249. var partsLength, numbers, index, part, radix, number, ipv4;
  27250. if (parts.length && parts[parts.length - 1] == '') {
  27251. parts.pop();
  27252. }
  27253. partsLength = parts.length;
  27254. if (partsLength > 4) return input;
  27255. numbers = [];
  27256. for (index = 0; index < partsLength; index++) {
  27257. part = parts[index];
  27258. if (part == '') return input;
  27259. radix = 10;
  27260. if (part.length > 1 && part.charAt(0) == '0') {
  27261. radix = HEX_START.test(part) ? 16 : 8;
  27262. part = part.slice(radix == 8 ? 1 : 2);
  27263. }
  27264. if (part === '') {
  27265. number = 0;
  27266. } else {
  27267. if (!(radix == 10 ? DEC : radix == 8 ? OCT : HEX).test(part)) return input;
  27268. number = parseInt(part, radix);
  27269. }
  27270. numbers.push(number);
  27271. }
  27272. for (index = 0; index < partsLength; index++) {
  27273. number = numbers[index];
  27274. if (index == partsLength - 1) {
  27275. if (number >= pow(256, 5 - partsLength)) return null;
  27276. } else if (number > 255) return null;
  27277. }
  27278. ipv4 = numbers.pop();
  27279. for (index = 0; index < numbers.length; index++) {
  27280. ipv4 += numbers[index] * pow(256, 3 - index);
  27281. }
  27282. return ipv4;
  27283. };
  27284. // eslint-disable-next-line max-statements
  27285. var parseIPv6 = function(input) {
  27286. var address = [0, 0, 0, 0, 0, 0, 0, 0];
  27287. var pieceIndex = 0;
  27288. var compress = null;
  27289. var pointer = 0;
  27290. var value, length, numbersSeen, ipv4Piece, number, swaps, swap;
  27291. var char = function() {
  27292. return input.charAt(pointer);
  27293. };
  27294. if (char() == ':') {
  27295. if (input.charAt(1) != ':') return;
  27296. pointer += 2;
  27297. pieceIndex++;
  27298. compress = pieceIndex;
  27299. }
  27300. while (char()) {
  27301. if (pieceIndex == 8) return;
  27302. if (char() == ':') {
  27303. if (compress !== null) return;
  27304. pointer++;
  27305. pieceIndex++;
  27306. compress = pieceIndex;
  27307. continue;
  27308. }
  27309. value = length = 0;
  27310. while (length < 4 && HEX.test(char())) {
  27311. value = value * 16 + parseInt(char(), 16);
  27312. pointer++;
  27313. length++;
  27314. }
  27315. if (char() == '.') {
  27316. if (length == 0) return;
  27317. pointer -= length;
  27318. if (pieceIndex > 6) return;
  27319. numbersSeen = 0;
  27320. while (char()) {
  27321. ipv4Piece = null;
  27322. if (numbersSeen > 0) {
  27323. if (char() == '.' && numbersSeen < 4) pointer++;
  27324. else return;
  27325. }
  27326. if (!DIGIT.test(char())) return;
  27327. while (DIGIT.test(char())) {
  27328. number = parseInt(char(), 10);
  27329. if (ipv4Piece === null) ipv4Piece = number;
  27330. else if (ipv4Piece == 0) return;
  27331. else ipv4Piece = ipv4Piece * 10 + number;
  27332. if (ipv4Piece > 255) return;
  27333. pointer++;
  27334. }
  27335. address[pieceIndex] = address[pieceIndex] * 256 + ipv4Piece;
  27336. numbersSeen++;
  27337. if (numbersSeen == 2 || numbersSeen == 4) pieceIndex++;
  27338. }
  27339. if (numbersSeen != 4) return;
  27340. break;
  27341. } else if (char() == ':') {
  27342. pointer++;
  27343. if (!char()) return;
  27344. } else if (char()) return;
  27345. address[pieceIndex++] = value;
  27346. }
  27347. if (compress !== null) {
  27348. swaps = pieceIndex - compress;
  27349. pieceIndex = 7;
  27350. while (pieceIndex != 0 && swaps > 0) {
  27351. swap = address[pieceIndex];
  27352. address[pieceIndex--] = address[compress + swaps - 1];
  27353. address[compress + --swaps] = swap;
  27354. }
  27355. } else if (pieceIndex != 8) return;
  27356. return address;
  27357. };
  27358. var findLongestZeroSequence = function(ipv6) {
  27359. var maxIndex = null;
  27360. var maxLength = 1;
  27361. var currStart = null;
  27362. var currLength = 0;
  27363. var index = 0;
  27364. for (; index < 8; index++) {
  27365. if (ipv6[index] !== 0) {
  27366. if (currLength > maxLength) {
  27367. maxIndex = currStart;
  27368. maxLength = currLength;
  27369. }
  27370. currStart = null;
  27371. currLength = 0;
  27372. } else {
  27373. if (currStart === null) currStart = index;
  27374. ++currLength;
  27375. }
  27376. }
  27377. if (currLength > maxLength) {
  27378. maxIndex = currStart;
  27379. maxLength = currLength;
  27380. }
  27381. return maxIndex;
  27382. };
  27383. var serializeHost = function(host) {
  27384. var result, index, compress, ignore0;
  27385. // ipv4
  27386. if (typeof host == 'number') {
  27387. result = [];
  27388. for (index = 0; index < 4; index++) {
  27389. result.unshift(host % 256);
  27390. host = floor(host / 256);
  27391. }
  27392. return result.join('.');
  27393. // ipv6
  27394. } else if (typeof host == 'object') {
  27395. result = '';
  27396. compress = findLongestZeroSequence(host);
  27397. for (index = 0; index < 8; index++) {
  27398. if (ignore0 && host[index] === 0) continue;
  27399. if (ignore0) ignore0 = false;
  27400. if (compress === index) {
  27401. result += index ? ':' : '::';
  27402. ignore0 = true;
  27403. } else {
  27404. result += host[index].toString(16);
  27405. if (index < 7) result += ':';
  27406. }
  27407. }
  27408. return '[' + result + ']';
  27409. }
  27410. return host;
  27411. };
  27412. var C0ControlPercentEncodeSet = {};
  27413. var fragmentPercentEncodeSet = assign({}, C0ControlPercentEncodeSet, {
  27414. ' ': 1,
  27415. '"': 1,
  27416. '<': 1,
  27417. '>': 1,
  27418. '`': 1
  27419. });
  27420. var pathPercentEncodeSet = assign({}, fragmentPercentEncodeSet, {
  27421. '#': 1,
  27422. '?': 1,
  27423. '{': 1,
  27424. '}': 1
  27425. });
  27426. var userinfoPercentEncodeSet = assign({}, pathPercentEncodeSet, {
  27427. '/': 1,
  27428. ':': 1,
  27429. ';': 1,
  27430. '=': 1,
  27431. '@': 1,
  27432. '[': 1,
  27433. '\\': 1,
  27434. ']': 1,
  27435. '^': 1,
  27436. '|': 1
  27437. });
  27438. var percentEncode = function(char, set) {
  27439. var code = codeAt(char, 0);
  27440. return code > 0x20 && code < 0x7f && !has(set, char)
  27441. ? char
  27442. : encodeURIComponent(char);
  27443. };
  27444. var specialSchemes = {
  27445. ftp: 21,
  27446. file: null,
  27447. http: 80,
  27448. https: 443,
  27449. ws: 80,
  27450. wss: 443
  27451. };
  27452. var isSpecial = function(url) {
  27453. return has(specialSchemes, url.scheme);
  27454. };
  27455. var includesCredentials = function(url) {
  27456. return url.username != '' || url.password != '';
  27457. };
  27458. var cannotHaveUsernamePasswordPort = function(url) {
  27459. return !url.host || url.cannotBeABaseURL || url.scheme == 'file';
  27460. };
  27461. var isWindowsDriveLetter = function(string, normalized) {
  27462. var second;
  27463. return (
  27464. string.length == 2 &&
  27465. ALPHA.test(string.charAt(0)) &&
  27466. ((second = string.charAt(1)) == ':' || (!normalized && second == '|'))
  27467. );
  27468. };
  27469. var startsWithWindowsDriveLetter = function(string) {
  27470. var third;
  27471. return (
  27472. string.length > 1 &&
  27473. isWindowsDriveLetter(string.slice(0, 2)) &&
  27474. (string.length == 2 ||
  27475. ((third = string.charAt(2)) === '/' ||
  27476. third === '\\' ||
  27477. third === '?' ||
  27478. third === '#'))
  27479. );
  27480. };
  27481. var shortenURLsPath = function(url) {
  27482. var path = url.path;
  27483. var pathSize = path.length;
  27484. if (
  27485. pathSize &&
  27486. (url.scheme != 'file' ||
  27487. pathSize != 1 ||
  27488. !isWindowsDriveLetter(path[0], true))
  27489. ) {
  27490. path.pop();
  27491. }
  27492. };
  27493. var isSingleDot = function(segment) {
  27494. return segment === '.' || segment.toLowerCase() === '%2e';
  27495. };
  27496. var isDoubleDot = function(segment) {
  27497. segment = segment.toLowerCase();
  27498. return (
  27499. segment === '..' ||
  27500. segment === '%2e.' ||
  27501. segment === '.%2e' ||
  27502. segment === '%2e%2e'
  27503. );
  27504. };
  27505. // States:
  27506. var SCHEME_START = {};
  27507. var SCHEME = {};
  27508. var NO_SCHEME = {};
  27509. var SPECIAL_RELATIVE_OR_AUTHORITY = {};
  27510. var PATH_OR_AUTHORITY = {};
  27511. var RELATIVE = {};
  27512. var RELATIVE_SLASH = {};
  27513. var SPECIAL_AUTHORITY_SLASHES = {};
  27514. var SPECIAL_AUTHORITY_IGNORE_SLASHES = {};
  27515. var AUTHORITY = {};
  27516. var HOST = {};
  27517. var HOSTNAME = {};
  27518. var PORT = {};
  27519. var FILE = {};
  27520. var FILE_SLASH = {};
  27521. var FILE_HOST = {};
  27522. var PATH_START = {};
  27523. var PATH = {};
  27524. var CANNOT_BE_A_BASE_URL_PATH = {};
  27525. var QUERY = {};
  27526. var FRAGMENT = {};
  27527. // eslint-disable-next-line max-statements
  27528. var parseURL = function(url, input, stateOverride, base) {
  27529. var state = stateOverride || SCHEME_START;
  27530. var pointer = 0;
  27531. var buffer = '';
  27532. var seenAt = false;
  27533. var seenBracket = false;
  27534. var seenPasswordToken = false;
  27535. var codePoints, char, bufferCodePoints, failure;
  27536. if (!stateOverride) {
  27537. url.scheme = '';
  27538. url.username = '';
  27539. url.password = '';
  27540. url.host = null;
  27541. url.port = null;
  27542. url.path = [];
  27543. url.query = null;
  27544. url.fragment = null;
  27545. url.cannotBeABaseURL = false;
  27546. input = input.replace(LEADING_AND_TRAILING_C0_CONTROL_OR_SPACE, '');
  27547. }
  27548. input = input.replace(TAB_AND_NEW_LINE, '');
  27549. codePoints = arrayFrom(input);
  27550. while (pointer <= codePoints.length) {
  27551. char = codePoints[pointer];
  27552. switch (state) {
  27553. case SCHEME_START:
  27554. if (char && ALPHA.test(char)) {
  27555. buffer += char.toLowerCase();
  27556. state = SCHEME;
  27557. } else if (!stateOverride) {
  27558. state = NO_SCHEME;
  27559. continue;
  27560. } else return INVALID_SCHEME;
  27561. break;
  27562. case SCHEME:
  27563. if (
  27564. char &&
  27565. (ALPHANUMERIC.test(char) || char == '+' || char == '-' || char == '.')
  27566. ) {
  27567. buffer += char.toLowerCase();
  27568. } else if (char == ':') {
  27569. if (
  27570. stateOverride &&
  27571. (isSpecial(url) != has(specialSchemes, buffer) ||
  27572. (buffer == 'file' &&
  27573. (includesCredentials(url) || url.port !== null)) ||
  27574. (url.scheme == 'file' && !url.host))
  27575. )
  27576. return;
  27577. url.scheme = buffer;
  27578. if (stateOverride) {
  27579. if (isSpecial(url) && specialSchemes[url.scheme] == url.port)
  27580. url.port = null;
  27581. return;
  27582. }
  27583. buffer = '';
  27584. if (url.scheme == 'file') {
  27585. state = FILE;
  27586. } else if (isSpecial(url) && base && base.scheme == url.scheme) {
  27587. state = SPECIAL_RELATIVE_OR_AUTHORITY;
  27588. } else if (isSpecial(url)) {
  27589. state = SPECIAL_AUTHORITY_SLASHES;
  27590. } else if (codePoints[pointer + 1] == '/') {
  27591. state = PATH_OR_AUTHORITY;
  27592. pointer++;
  27593. } else {
  27594. url.cannotBeABaseURL = true;
  27595. url.path.push('');
  27596. state = CANNOT_BE_A_BASE_URL_PATH;
  27597. }
  27598. } else if (!stateOverride) {
  27599. buffer = '';
  27600. state = NO_SCHEME;
  27601. pointer = 0;
  27602. continue;
  27603. } else return INVALID_SCHEME;
  27604. break;
  27605. case NO_SCHEME:
  27606. if (!base || (base.cannotBeABaseURL && char != '#'))
  27607. return INVALID_SCHEME;
  27608. if (base.cannotBeABaseURL && char == '#') {
  27609. url.scheme = base.scheme;
  27610. url.path = base.path.slice();
  27611. url.query = base.query;
  27612. url.fragment = '';
  27613. url.cannotBeABaseURL = true;
  27614. state = FRAGMENT;
  27615. break;
  27616. }
  27617. state = base.scheme == 'file' ? FILE : RELATIVE;
  27618. continue;
  27619. case SPECIAL_RELATIVE_OR_AUTHORITY:
  27620. if (char == '/' && codePoints[pointer + 1] == '/') {
  27621. state = SPECIAL_AUTHORITY_IGNORE_SLASHES;
  27622. pointer++;
  27623. } else {
  27624. state = RELATIVE;
  27625. continue;
  27626. }
  27627. break;
  27628. case PATH_OR_AUTHORITY:
  27629. if (char == '/') {
  27630. state = AUTHORITY;
  27631. break;
  27632. } else {
  27633. state = PATH;
  27634. continue;
  27635. }
  27636. case RELATIVE:
  27637. url.scheme = base.scheme;
  27638. if (char == EOF) {
  27639. url.username = base.username;
  27640. url.password = base.password;
  27641. url.host = base.host;
  27642. url.port = base.port;
  27643. url.path = base.path.slice();
  27644. url.query = base.query;
  27645. } else if (char == '/' || (char == '\\' && isSpecial(url))) {
  27646. state = RELATIVE_SLASH;
  27647. } else if (char == '?') {
  27648. url.username = base.username;
  27649. url.password = base.password;
  27650. url.host = base.host;
  27651. url.port = base.port;
  27652. url.path = base.path.slice();
  27653. url.query = '';
  27654. state = QUERY;
  27655. } else if (char == '#') {
  27656. url.username = base.username;
  27657. url.password = base.password;
  27658. url.host = base.host;
  27659. url.port = base.port;
  27660. url.path = base.path.slice();
  27661. url.query = base.query;
  27662. url.fragment = '';
  27663. state = FRAGMENT;
  27664. } else {
  27665. url.username = base.username;
  27666. url.password = base.password;
  27667. url.host = base.host;
  27668. url.port = base.port;
  27669. url.path = base.path.slice();
  27670. url.path.pop();
  27671. state = PATH;
  27672. continue;
  27673. }
  27674. break;
  27675. case RELATIVE_SLASH:
  27676. if (isSpecial(url) && (char == '/' || char == '\\')) {
  27677. state = SPECIAL_AUTHORITY_IGNORE_SLASHES;
  27678. } else if (char == '/') {
  27679. state = AUTHORITY;
  27680. } else {
  27681. url.username = base.username;
  27682. url.password = base.password;
  27683. url.host = base.host;
  27684. url.port = base.port;
  27685. state = PATH;
  27686. continue;
  27687. }
  27688. break;
  27689. case SPECIAL_AUTHORITY_SLASHES:
  27690. state = SPECIAL_AUTHORITY_IGNORE_SLASHES;
  27691. if (char != '/' || buffer.charAt(pointer + 1) != '/') continue;
  27692. pointer++;
  27693. break;
  27694. case SPECIAL_AUTHORITY_IGNORE_SLASHES:
  27695. if (char != '/' && char != '\\') {
  27696. state = AUTHORITY;
  27697. continue;
  27698. }
  27699. break;
  27700. case AUTHORITY:
  27701. if (char == '@') {
  27702. if (seenAt) buffer = '%40' + buffer;
  27703. seenAt = true;
  27704. bufferCodePoints = arrayFrom(buffer);
  27705. for (var i = 0; i < bufferCodePoints.length; i++) {
  27706. var codePoint = bufferCodePoints[i];
  27707. if (codePoint == ':' && !seenPasswordToken) {
  27708. seenPasswordToken = true;
  27709. continue;
  27710. }
  27711. var encodedCodePoints = percentEncode(
  27712. codePoint,
  27713. userinfoPercentEncodeSet
  27714. );
  27715. if (seenPasswordToken) url.password += encodedCodePoints;
  27716. else url.username += encodedCodePoints;
  27717. }
  27718. buffer = '';
  27719. } else if (
  27720. char == EOF ||
  27721. char == '/' ||
  27722. char == '?' ||
  27723. char == '#' ||
  27724. (char == '\\' && isSpecial(url))
  27725. ) {
  27726. if (seenAt && buffer == '') return INVALID_AUTHORITY;
  27727. pointer -= arrayFrom(buffer).length + 1;
  27728. buffer = '';
  27729. state = HOST;
  27730. } else buffer += char;
  27731. break;
  27732. case HOST:
  27733. case HOSTNAME:
  27734. if (stateOverride && url.scheme == 'file') {
  27735. state = FILE_HOST;
  27736. continue;
  27737. } else if (char == ':' && !seenBracket) {
  27738. if (buffer == '') return INVALID_HOST;
  27739. failure = parseHost(url, buffer);
  27740. if (failure) return failure;
  27741. buffer = '';
  27742. state = PORT;
  27743. if (stateOverride == HOSTNAME) return;
  27744. } else if (
  27745. char == EOF ||
  27746. char == '/' ||
  27747. char == '?' ||
  27748. char == '#' ||
  27749. (char == '\\' && isSpecial(url))
  27750. ) {
  27751. if (isSpecial(url) && buffer == '') return INVALID_HOST;
  27752. if (
  27753. stateOverride &&
  27754. buffer == '' &&
  27755. (includesCredentials(url) || url.port !== null)
  27756. )
  27757. return;
  27758. failure = parseHost(url, buffer);
  27759. if (failure) return failure;
  27760. buffer = '';
  27761. state = PATH_START;
  27762. if (stateOverride) return;
  27763. continue;
  27764. } else {
  27765. if (char == '[') seenBracket = true;
  27766. else if (char == ']') seenBracket = false;
  27767. buffer += char;
  27768. }
  27769. break;
  27770. case PORT:
  27771. if (DIGIT.test(char)) {
  27772. buffer += char;
  27773. } else if (
  27774. char == EOF ||
  27775. char == '/' ||
  27776. char == '?' ||
  27777. char == '#' ||
  27778. (char == '\\' && isSpecial(url)) ||
  27779. stateOverride
  27780. ) {
  27781. if (buffer != '') {
  27782. var port = parseInt(buffer, 10);
  27783. if (port > 0xffff) return INVALID_PORT;
  27784. url.port =
  27785. isSpecial(url) && port === specialSchemes[url.scheme] ? null : port;
  27786. buffer = '';
  27787. }
  27788. if (stateOverride) return;
  27789. state = PATH_START;
  27790. continue;
  27791. } else return INVALID_PORT;
  27792. break;
  27793. case FILE:
  27794. url.scheme = 'file';
  27795. if (char == '/' || char == '\\') state = FILE_SLASH;
  27796. else if (base && base.scheme == 'file') {
  27797. if (char == EOF) {
  27798. url.host = base.host;
  27799. url.path = base.path.slice();
  27800. url.query = base.query;
  27801. } else if (char == '?') {
  27802. url.host = base.host;
  27803. url.path = base.path.slice();
  27804. url.query = '';
  27805. state = QUERY;
  27806. } else if (char == '#') {
  27807. url.host = base.host;
  27808. url.path = base.path.slice();
  27809. url.query = base.query;
  27810. url.fragment = '';
  27811. state = FRAGMENT;
  27812. } else {
  27813. if (
  27814. !startsWithWindowsDriveLetter(codePoints.slice(pointer).join(''))
  27815. ) {
  27816. url.host = base.host;
  27817. url.path = base.path.slice();
  27818. shortenURLsPath(url);
  27819. }
  27820. state = PATH;
  27821. continue;
  27822. }
  27823. } else {
  27824. state = PATH;
  27825. continue;
  27826. }
  27827. break;
  27828. case FILE_SLASH:
  27829. if (char == '/' || char == '\\') {
  27830. state = FILE_HOST;
  27831. break;
  27832. }
  27833. if (
  27834. base &&
  27835. base.scheme == 'file' &&
  27836. !startsWithWindowsDriveLetter(codePoints.slice(pointer).join(''))
  27837. ) {
  27838. if (isWindowsDriveLetter(base.path[0], true))
  27839. url.path.push(base.path[0]);
  27840. else url.host = base.host;
  27841. }
  27842. state = PATH;
  27843. continue;
  27844. case FILE_HOST:
  27845. if (
  27846. char == EOF ||
  27847. char == '/' ||
  27848. char == '\\' ||
  27849. char == '?' ||
  27850. char == '#'
  27851. ) {
  27852. if (!stateOverride && isWindowsDriveLetter(buffer)) {
  27853. state = PATH;
  27854. } else if (buffer == '') {
  27855. url.host = '';
  27856. if (stateOverride) return;
  27857. state = PATH_START;
  27858. } else {
  27859. failure = parseHost(url, buffer);
  27860. if (failure) return failure;
  27861. if (url.host == 'localhost') url.host = '';
  27862. if (stateOverride) return;
  27863. buffer = '';
  27864. state = PATH_START;
  27865. }
  27866. continue;
  27867. } else buffer += char;
  27868. break;
  27869. case PATH_START:
  27870. if (isSpecial(url)) {
  27871. state = PATH;
  27872. if (char != '/' && char != '\\') continue;
  27873. } else if (!stateOverride && char == '?') {
  27874. url.query = '';
  27875. state = QUERY;
  27876. } else if (!stateOverride && char == '#') {
  27877. url.fragment = '';
  27878. state = FRAGMENT;
  27879. } else if (char != EOF) {
  27880. state = PATH;
  27881. if (char != '/') continue;
  27882. }
  27883. break;
  27884. case PATH:
  27885. if (
  27886. char == EOF ||
  27887. char == '/' ||
  27888. (char == '\\' && isSpecial(url)) ||
  27889. (!stateOverride && (char == '?' || char == '#'))
  27890. ) {
  27891. if (isDoubleDot(buffer)) {
  27892. shortenURLsPath(url);
  27893. if (char != '/' && !(char == '\\' && isSpecial(url))) {
  27894. url.path.push('');
  27895. }
  27896. } else if (isSingleDot(buffer)) {
  27897. if (char != '/' && !(char == '\\' && isSpecial(url))) {
  27898. url.path.push('');
  27899. }
  27900. } else {
  27901. if (
  27902. url.scheme == 'file' &&
  27903. !url.path.length &&
  27904. isWindowsDriveLetter(buffer)
  27905. ) {
  27906. if (url.host) url.host = '';
  27907. buffer = buffer.charAt(0) + ':'; // normalize windows drive letter
  27908. }
  27909. url.path.push(buffer);
  27910. }
  27911. buffer = '';
  27912. if (
  27913. url.scheme == 'file' &&
  27914. (char == EOF || char == '?' || char == '#')
  27915. ) {
  27916. while (url.path.length > 1 && url.path[0] === '') {
  27917. url.path.shift();
  27918. }
  27919. }
  27920. if (char == '?') {
  27921. url.query = '';
  27922. state = QUERY;
  27923. } else if (char == '#') {
  27924. url.fragment = '';
  27925. state = FRAGMENT;
  27926. }
  27927. } else {
  27928. buffer += percentEncode(char, pathPercentEncodeSet);
  27929. }
  27930. break;
  27931. case CANNOT_BE_A_BASE_URL_PATH:
  27932. if (char == '?') {
  27933. url.query = '';
  27934. state = QUERY;
  27935. } else if (char == '#') {
  27936. url.fragment = '';
  27937. state = FRAGMENT;
  27938. } else if (char != EOF) {
  27939. url.path[0] += percentEncode(char, C0ControlPercentEncodeSet);
  27940. }
  27941. break;
  27942. case QUERY:
  27943. if (!stateOverride && char == '#') {
  27944. url.fragment = '';
  27945. state = FRAGMENT;
  27946. } else if (char != EOF) {
  27947. if (char == "'" && isSpecial(url)) url.query += '%27';
  27948. else if (char == '#') url.query += '%23';
  27949. else url.query += percentEncode(char, C0ControlPercentEncodeSet);
  27950. }
  27951. break;
  27952. case FRAGMENT:
  27953. if (char != EOF)
  27954. url.fragment += percentEncode(char, fragmentPercentEncodeSet);
  27955. break;
  27956. }
  27957. pointer++;
  27958. }
  27959. };
  27960. // `URL` constructor
  27961. // https://url.spec.whatwg.org/#url-class
  27962. var URLConstructor = function URL(url /* , base */) {
  27963. var that = anInstance(this, URLConstructor, 'URL');
  27964. var base = arguments.length > 1 ? arguments[1] : undefined;
  27965. var urlString = String(url);
  27966. var state = setInternalState(that, { type: 'URL' });
  27967. var baseState, failure;
  27968. if (base !== undefined) {
  27969. if (base instanceof URLConstructor) baseState = getInternalURLState(base);
  27970. else {
  27971. failure = parseURL((baseState = {}), String(base));
  27972. if (failure) throw TypeError(failure);
  27973. }
  27974. }
  27975. failure = parseURL(state, urlString, null, baseState);
  27976. if (failure) throw TypeError(failure);
  27977. var searchParams = (state.searchParams = new URLSearchParams());
  27978. var searchParamsState = getInternalSearchParamsState(searchParams);
  27979. searchParamsState.updateSearchParams(state.query);
  27980. searchParamsState.updateURL = function() {
  27981. state.query = String(searchParams) || null;
  27982. };
  27983. if (!DESCRIPTORS) {
  27984. that.href = serializeURL.call(that);
  27985. that.origin = getOrigin.call(that);
  27986. that.protocol = getProtocol.call(that);
  27987. that.username = getUsername.call(that);
  27988. that.password = getPassword.call(that);
  27989. that.host = getHost.call(that);
  27990. that.hostname = getHostname.call(that);
  27991. that.port = getPort.call(that);
  27992. that.pathname = getPathname.call(that);
  27993. that.search = getSearch.call(that);
  27994. that.searchParams = getSearchParams.call(that);
  27995. that.hash = getHash.call(that);
  27996. }
  27997. };
  27998. var URLPrototype = URLConstructor.prototype;
  27999. var serializeURL = function() {
  28000. var url = getInternalURLState(this);
  28001. var scheme = url.scheme;
  28002. var username = url.username;
  28003. var password = url.password;
  28004. var host = url.host;
  28005. var port = url.port;
  28006. var path = url.path;
  28007. var query = url.query;
  28008. var fragment = url.fragment;
  28009. var output = scheme + ':';
  28010. if (host !== null) {
  28011. output += '//';
  28012. if (includesCredentials(url)) {
  28013. output += username + (password ? ':' + password : '') + '@';
  28014. }
  28015. output += serializeHost(host);
  28016. if (port !== null) output += ':' + port;
  28017. } else if (scheme == 'file') output += '//';
  28018. output += url.cannotBeABaseURL
  28019. ? path[0]
  28020. : path.length ? '/' + path.join('/') : '';
  28021. if (query !== null) output += '?' + query;
  28022. if (fragment !== null) output += '#' + fragment;
  28023. return output;
  28024. };
  28025. var getOrigin = function() {
  28026. var url = getInternalURLState(this);
  28027. var scheme = url.scheme;
  28028. var port = url.port;
  28029. if (scheme == 'blob')
  28030. try {
  28031. return new URL(scheme.path[0]).origin;
  28032. } catch (error) {
  28033. return 'null';
  28034. }
  28035. if (scheme == 'file' || !isSpecial(url)) return 'null';
  28036. return (
  28037. scheme + '://' + serializeHost(url.host) + (port !== null ? ':' + port : '')
  28038. );
  28039. };
  28040. var getProtocol = function() {
  28041. return getInternalURLState(this).scheme + ':';
  28042. };
  28043. var getUsername = function() {
  28044. return getInternalURLState(this).username;
  28045. };
  28046. var getPassword = function() {
  28047. return getInternalURLState(this).password;
  28048. };
  28049. var getHost = function() {
  28050. var url = getInternalURLState(this);
  28051. var host = url.host;
  28052. var port = url.port;
  28053. return host === null
  28054. ? ''
  28055. : port === null ? serializeHost(host) : serializeHost(host) + ':' + port;
  28056. };
  28057. var getHostname = function() {
  28058. var host = getInternalURLState(this).host;
  28059. return host === null ? '' : serializeHost(host);
  28060. };
  28061. var getPort = function() {
  28062. var port = getInternalURLState(this).port;
  28063. return port === null ? '' : String(port);
  28064. };
  28065. var getPathname = function() {
  28066. var url = getInternalURLState(this);
  28067. var path = url.path;
  28068. return url.cannotBeABaseURL ? path[0] : path.length ? '/' + path.join('/') : '';
  28069. };
  28070. var getSearch = function() {
  28071. var query = getInternalURLState(this).query;
  28072. return query ? '?' + query : '';
  28073. };
  28074. var getSearchParams = function() {
  28075. return getInternalURLState(this).searchParams;
  28076. };
  28077. var getHash = function() {
  28078. var fragment = getInternalURLState(this).fragment;
  28079. return fragment ? '#' + fragment : '';
  28080. };
  28081. var accessorDescriptor = function(getter, setter) {
  28082. return { get: getter, set: setter, configurable: true, enumerable: true };
  28083. };
  28084. if (DESCRIPTORS) {
  28085. defineProperties(URLPrototype, {
  28086. // `URL.prototype.href` accessors pair
  28087. // https://url.spec.whatwg.org/#dom-url-href
  28088. href: accessorDescriptor(serializeURL, function(href) {
  28089. var url = getInternalURLState(this);
  28090. var urlString = String(href);
  28091. var failure = parseURL(url, urlString);
  28092. if (failure) throw TypeError(failure);
  28093. getInternalSearchParamsState(url.searchParams).updateSearchParams(
  28094. url.query
  28095. );
  28096. }),
  28097. // `URL.prototype.origin` getter
  28098. // https://url.spec.whatwg.org/#dom-url-origin
  28099. origin: accessorDescriptor(getOrigin),
  28100. // `URL.prototype.protocol` accessors pair
  28101. // https://url.spec.whatwg.org/#dom-url-protocol
  28102. protocol: accessorDescriptor(getProtocol, function(protocol) {
  28103. var url = getInternalURLState(this);
  28104. parseURL(url, String(protocol) + ':', SCHEME_START);
  28105. }),
  28106. // `URL.prototype.username` accessors pair
  28107. // https://url.spec.whatwg.org/#dom-url-username
  28108. username: accessorDescriptor(getUsername, function(username) {
  28109. var url = getInternalURLState(this);
  28110. var codePoints = arrayFrom(String(username));
  28111. if (cannotHaveUsernamePasswordPort(url)) return;
  28112. url.username = '';
  28113. for (var i = 0; i < codePoints.length; i++) {
  28114. url.username += percentEncode(codePoints[i], userinfoPercentEncodeSet);
  28115. }
  28116. }),
  28117. // `URL.prototype.password` accessors pair
  28118. // https://url.spec.whatwg.org/#dom-url-password
  28119. password: accessorDescriptor(getPassword, function(password) {
  28120. var url = getInternalURLState(this);
  28121. var codePoints = arrayFrom(String(password));
  28122. if (cannotHaveUsernamePasswordPort(url)) return;
  28123. url.password = '';
  28124. for (var i = 0; i < codePoints.length; i++) {
  28125. url.password += percentEncode(codePoints[i], userinfoPercentEncodeSet);
  28126. }
  28127. }),
  28128. // `URL.prototype.host` accessors pair
  28129. // https://url.spec.whatwg.org/#dom-url-host
  28130. host: accessorDescriptor(getHost, function(host) {
  28131. var url = getInternalURLState(this);
  28132. if (url.cannotBeABaseURL) return;
  28133. parseURL(url, String(host), HOST);
  28134. }),
  28135. // `URL.prototype.hostname` accessors pair
  28136. // https://url.spec.whatwg.org/#dom-url-hostname
  28137. hostname: accessorDescriptor(getHostname, function(hostname) {
  28138. var url = getInternalURLState(this);
  28139. if (url.cannotBeABaseURL) return;
  28140. parseURL(url, String(hostname), HOSTNAME);
  28141. }),
  28142. // `URL.prototype.port` accessors pair
  28143. // https://url.spec.whatwg.org/#dom-url-port
  28144. port: accessorDescriptor(getPort, function(port) {
  28145. var url = getInternalURLState(this);
  28146. if (cannotHaveUsernamePasswordPort(url)) return;
  28147. port = String(port);
  28148. if (port == '') url.port = null;
  28149. else parseURL(url, port, PORT);
  28150. }),
  28151. // `URL.prototype.pathname` accessors pair
  28152. // https://url.spec.whatwg.org/#dom-url-pathname
  28153. pathname: accessorDescriptor(getPathname, function(pathname) {
  28154. var url = getInternalURLState(this);
  28155. if (url.cannotBeABaseURL) return;
  28156. url.path = [];
  28157. parseURL(url, pathname + '', PATH_START);
  28158. }),
  28159. // `URL.prototype.search` accessors pair
  28160. // https://url.spec.whatwg.org/#dom-url-search
  28161. search: accessorDescriptor(getSearch, function(search) {
  28162. var url = getInternalURLState(this);
  28163. search = String(search);
  28164. if (search == '') {
  28165. url.query = null;
  28166. } else {
  28167. if ('?' == search.charAt(0)) search = search.slice(1);
  28168. url.query = '';
  28169. parseURL(url, search, QUERY);
  28170. }
  28171. getInternalSearchParamsState(url.searchParams).updateSearchParams(
  28172. url.query
  28173. );
  28174. }),
  28175. // `URL.prototype.searchParams` getter
  28176. // https://url.spec.whatwg.org/#dom-url-searchparams
  28177. searchParams: accessorDescriptor(getSearchParams),
  28178. // `URL.prototype.hash` accessors pair
  28179. // https://url.spec.whatwg.org/#dom-url-hash
  28180. hash: accessorDescriptor(getHash, function(hash) {
  28181. var url = getInternalURLState(this);
  28182. hash = String(hash);
  28183. if (hash == '') {
  28184. url.fragment = null;
  28185. return;
  28186. }
  28187. if ('#' == hash.charAt(0)) hash = hash.slice(1);
  28188. url.fragment = '';
  28189. parseURL(url, hash, FRAGMENT);
  28190. })
  28191. });
  28192. }
  28193. // `URL.prototype.toJSON` method
  28194. // https://url.spec.whatwg.org/#dom-url-tojson
  28195. redefine(
  28196. URLPrototype,
  28197. 'toJSON',
  28198. function toJSON() {
  28199. return serializeURL.call(this);
  28200. },
  28201. { enumerable: true }
  28202. );
  28203. // `URL.prototype.toString` method
  28204. // https://url.spec.whatwg.org/#URL-stringification-behavior
  28205. redefine(
  28206. URLPrototype,
  28207. 'toString',
  28208. function toString() {
  28209. return serializeURL.call(this);
  28210. },
  28211. { enumerable: true }
  28212. );
  28213. if (NativeURL) {
  28214. var nativeCreateObjectURL = NativeURL.createObjectURL;
  28215. var nativeRevokeObjectURL = NativeURL.revokeObjectURL;
  28216. // `URL.createObjectURL` method
  28217. // https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL
  28218. // eslint-disable-next-line no-unused-vars
  28219. if (nativeCreateObjectURL)
  28220. redefine(URLConstructor, 'createObjectURL', function createObjectURL(blob) {
  28221. return nativeCreateObjectURL.apply(NativeURL, arguments);
  28222. });
  28223. // `URL.revokeObjectURL` method
  28224. // https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL
  28225. // eslint-disable-next-line no-unused-vars
  28226. if (nativeRevokeObjectURL)
  28227. redefine(URLConstructor, 'revokeObjectURL', function revokeObjectURL(url) {
  28228. return nativeRevokeObjectURL.apply(NativeURL, arguments);
  28229. });
  28230. }
  28231. setToStringTag(URLConstructor, 'URL');
  28232. $(
  28233. { global: true, forced: !USE_NATIVE_URL, sham: !DESCRIPTORS },
  28234. {
  28235. URL: URLConstructor
  28236. }
  28237. );
  28238. },
  28239. {
  28240. '../internals/an-instance': 27,
  28241. '../internals/array-from': 35,
  28242. '../internals/descriptors': 60,
  28243. '../internals/export': 67,
  28244. '../internals/global': 76,
  28245. '../internals/has': 77,
  28246. '../internals/internal-state': 87,
  28247. '../internals/native-url': 101,
  28248. '../internals/object-assign': 106,
  28249. '../internals/object-define-properties': 108,
  28250. '../internals/redefine': 125,
  28251. '../internals/set-to-string-tag': 134,
  28252. '../internals/string-multibyte': 140,
  28253. '../internals/string-punycode-to-ascii': 141,
  28254. '../modules/es.string.iterator': 201,
  28255. '../modules/web.url-search-params': 245
  28256. }
  28257. ],
  28258. 247: [
  28259. function(_dereq_, module, exports) {
  28260. // This file can be required in Browserify and Node.js for automatic polyfill
  28261. // To use it: require('es6-promise/auto');
  28262. 'use strict';
  28263. module.exports = _dereq_('./').polyfill();
  28264. },
  28265. { './': 248 }
  28266. ],
  28267. 248: [
  28268. function(_dereq_, module, exports) {
  28269. (function(process, global) {
  28270. /*!
  28271. * @overview es6-promise - a tiny implementation of Promises/A+.
  28272. * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
  28273. * @license Licensed under MIT license
  28274. * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
  28275. * @version v4.2.8+1e68dce6
  28276. */
  28277. (function(global, factory) {
  28278. typeof exports === 'object' && typeof module !== 'undefined'
  28279. ? (module.exports = factory())
  28280. : typeof define === 'function' && define.amd
  28281. ? define(factory)
  28282. : (global.ES6Promise = factory());
  28283. })(this, function() {
  28284. 'use strict';
  28285. function objectOrFunction(x) {
  28286. var type = typeof x;
  28287. return x !== null && (type === 'object' || type === 'function');
  28288. }
  28289. function isFunction(x) {
  28290. return typeof x === 'function';
  28291. }
  28292. var _isArray = void 0;
  28293. if (Array.isArray) {
  28294. _isArray = Array.isArray;
  28295. } else {
  28296. _isArray = function(x) {
  28297. return Object.prototype.toString.call(x) === '[object Array]';
  28298. };
  28299. }
  28300. var isArray = _isArray;
  28301. var len = 0;
  28302. var vertxNext = void 0;
  28303. var customSchedulerFn = void 0;
  28304. var asap = function asap(callback, arg) {
  28305. queue[len] = callback;
  28306. queue[len + 1] = arg;
  28307. len += 2;
  28308. if (len === 2) {
  28309. // If len is 2, that means that we need to schedule an async flush.
  28310. // If additional callbacks are queued before the queue is flushed, they
  28311. // will be processed by this flush that we are scheduling.
  28312. if (customSchedulerFn) {
  28313. customSchedulerFn(flush);
  28314. } else {
  28315. scheduleFlush();
  28316. }
  28317. }
  28318. };
  28319. function setScheduler(scheduleFn) {
  28320. customSchedulerFn = scheduleFn;
  28321. }
  28322. function setAsap(asapFn) {
  28323. asap = asapFn;
  28324. }
  28325. var browserWindow = typeof window !== 'undefined' ? window : undefined;
  28326. var browserGlobal = browserWindow || {};
  28327. var BrowserMutationObserver =
  28328. browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
  28329. var isNode =
  28330. typeof self === 'undefined' &&
  28331. typeof process !== 'undefined' &&
  28332. {}.toString.call(process) === '[object process]';
  28333. // test for web worker but not in IE10
  28334. var isWorker =
  28335. typeof Uint8ClampedArray !== 'undefined' &&
  28336. typeof importScripts !== 'undefined' &&
  28337. typeof MessageChannel !== 'undefined';
  28338. // node
  28339. function useNextTick() {
  28340. // node version 0.10.x displays a deprecation warning when nextTick is used recursively
  28341. // see https://github.com/cujojs/when/issues/410 for details
  28342. return function() {
  28343. return process.nextTick(flush);
  28344. };
  28345. }
  28346. // vertx
  28347. function useVertxTimer() {
  28348. if (typeof vertxNext !== 'undefined') {
  28349. return function() {
  28350. vertxNext(flush);
  28351. };
  28352. }
  28353. return useSetTimeout();
  28354. }
  28355. function useMutationObserver() {
  28356. var iterations = 0;
  28357. var observer = new BrowserMutationObserver(flush);
  28358. var node = document.createTextNode('');
  28359. observer.observe(node, { characterData: true });
  28360. return function() {
  28361. node.data = iterations = ++iterations % 2;
  28362. };
  28363. }
  28364. // web worker
  28365. function useMessageChannel() {
  28366. var channel = new MessageChannel();
  28367. channel.port1.onmessage = flush;
  28368. return function() {
  28369. return channel.port2.postMessage(0);
  28370. };
  28371. }
  28372. function useSetTimeout() {
  28373. // Store setTimeout reference so es6-promise will be unaffected by
  28374. // other code modifying setTimeout (like sinon.useFakeTimers())
  28375. var globalSetTimeout = setTimeout;
  28376. return function() {
  28377. return globalSetTimeout(flush, 1);
  28378. };
  28379. }
  28380. var queue = new Array(1000);
  28381. function flush() {
  28382. for (var i = 0; i < len; i += 2) {
  28383. var callback = queue[i];
  28384. var arg = queue[i + 1];
  28385. callback(arg);
  28386. queue[i] = undefined;
  28387. queue[i + 1] = undefined;
  28388. }
  28389. len = 0;
  28390. }
  28391. function attemptVertx() {
  28392. try {
  28393. var vertx = Function('return this')().require('vertx');
  28394. vertxNext = vertx.runOnLoop || vertx.runOnContext;
  28395. return useVertxTimer();
  28396. } catch (e) {
  28397. return useSetTimeout();
  28398. }
  28399. }
  28400. var scheduleFlush = void 0;
  28401. // Decide what async method to use to triggering processing of queued callbacks:
  28402. if (isNode) {
  28403. scheduleFlush = useNextTick();
  28404. } else if (BrowserMutationObserver) {
  28405. scheduleFlush = useMutationObserver();
  28406. } else if (isWorker) {
  28407. scheduleFlush = useMessageChannel();
  28408. } else if (browserWindow === undefined && typeof _dereq_ === 'function') {
  28409. scheduleFlush = attemptVertx();
  28410. } else {
  28411. scheduleFlush = useSetTimeout();
  28412. }
  28413. function then(onFulfillment, onRejection) {
  28414. var parent = this;
  28415. var child = new this.constructor(noop);
  28416. if (child[PROMISE_ID] === undefined) {
  28417. makePromise(child);
  28418. }
  28419. var _state = parent._state;
  28420. if (_state) {
  28421. var callback = arguments[_state - 1];
  28422. asap(function() {
  28423. return invokeCallback(_state, child, callback, parent._result);
  28424. });
  28425. } else {
  28426. subscribe(parent, child, onFulfillment, onRejection);
  28427. }
  28428. return child;
  28429. }
  28430. /**
  28431. `Promise.resolve` returns a promise that will become resolved with the
  28432. passed `value`. It is shorthand for the following:
  28433. ```javascript
  28434. let promise = new Promise(function(resolve, reject){
  28435. resolve(1);
  28436. });
  28437. promise.then(function(value){
  28438. // value === 1
  28439. });
  28440. ```
  28441. Instead of writing the above, your code now simply becomes the following:
  28442. ```javascript
  28443. let promise = Promise.resolve(1);
  28444. promise.then(function(value){
  28445. // value === 1
  28446. });
  28447. ```
  28448. @method resolve
  28449. @static
  28450. @param {Any} value value that the returned promise will be resolved with
  28451. Useful for tooling.
  28452. @return {Promise} a promise that will become fulfilled with the given
  28453. `value`
  28454. */
  28455. function resolve$1(object) {
  28456. /*jshint validthis:true */
  28457. var Constructor = this;
  28458. if (
  28459. object &&
  28460. typeof object === 'object' &&
  28461. object.constructor === Constructor
  28462. ) {
  28463. return object;
  28464. }
  28465. var promise = new Constructor(noop);
  28466. resolve(promise, object);
  28467. return promise;
  28468. }
  28469. var PROMISE_ID = Math.random()
  28470. .toString(36)
  28471. .substring(2);
  28472. function noop() {}
  28473. var PENDING = void 0;
  28474. var FULFILLED = 1;
  28475. var REJECTED = 2;
  28476. function selfFulfillment() {
  28477. return new TypeError('You cannot resolve a promise with itself');
  28478. }
  28479. function cannotReturnOwn() {
  28480. return new TypeError(
  28481. 'A promises callback cannot return that same promise.'
  28482. );
  28483. }
  28484. function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) {
  28485. try {
  28486. then$$1.call(value, fulfillmentHandler, rejectionHandler);
  28487. } catch (e) {
  28488. return e;
  28489. }
  28490. }
  28491. function handleForeignThenable(promise, thenable, then$$1) {
  28492. asap(function(promise) {
  28493. var sealed = false;
  28494. var error = tryThen(
  28495. then$$1,
  28496. thenable,
  28497. function(value) {
  28498. if (sealed) {
  28499. return;
  28500. }
  28501. sealed = true;
  28502. if (thenable !== value) {
  28503. resolve(promise, value);
  28504. } else {
  28505. fulfill(promise, value);
  28506. }
  28507. },
  28508. function(reason) {
  28509. if (sealed) {
  28510. return;
  28511. }
  28512. sealed = true;
  28513. reject(promise, reason);
  28514. },
  28515. 'Settle: ' + (promise._label || ' unknown promise')
  28516. );
  28517. if (!sealed && error) {
  28518. sealed = true;
  28519. reject(promise, error);
  28520. }
  28521. }, promise);
  28522. }
  28523. function handleOwnThenable(promise, thenable) {
  28524. if (thenable._state === FULFILLED) {
  28525. fulfill(promise, thenable._result);
  28526. } else if (thenable._state === REJECTED) {
  28527. reject(promise, thenable._result);
  28528. } else {
  28529. subscribe(
  28530. thenable,
  28531. undefined,
  28532. function(value) {
  28533. return resolve(promise, value);
  28534. },
  28535. function(reason) {
  28536. return reject(promise, reason);
  28537. }
  28538. );
  28539. }
  28540. }
  28541. function handleMaybeThenable(promise, maybeThenable, then$$1) {
  28542. if (
  28543. maybeThenable.constructor === promise.constructor &&
  28544. then$$1 === then &&
  28545. maybeThenable.constructor.resolve === resolve$1
  28546. ) {
  28547. handleOwnThenable(promise, maybeThenable);
  28548. } else {
  28549. if (then$$1 === undefined) {
  28550. fulfill(promise, maybeThenable);
  28551. } else if (isFunction(then$$1)) {
  28552. handleForeignThenable(promise, maybeThenable, then$$1);
  28553. } else {
  28554. fulfill(promise, maybeThenable);
  28555. }
  28556. }
  28557. }
  28558. function resolve(promise, value) {
  28559. if (promise === value) {
  28560. reject(promise, selfFulfillment());
  28561. } else if (objectOrFunction(value)) {
  28562. var then$$1 = void 0;
  28563. try {
  28564. then$$1 = value.then;
  28565. } catch (error) {
  28566. reject(promise, error);
  28567. return;
  28568. }
  28569. handleMaybeThenable(promise, value, then$$1);
  28570. } else {
  28571. fulfill(promise, value);
  28572. }
  28573. }
  28574. function publishRejection(promise) {
  28575. if (promise._onerror) {
  28576. promise._onerror(promise._result);
  28577. }
  28578. publish(promise);
  28579. }
  28580. function fulfill(promise, value) {
  28581. if (promise._state !== PENDING) {
  28582. return;
  28583. }
  28584. promise._result = value;
  28585. promise._state = FULFILLED;
  28586. if (promise._subscribers.length !== 0) {
  28587. asap(publish, promise);
  28588. }
  28589. }
  28590. function reject(promise, reason) {
  28591. if (promise._state !== PENDING) {
  28592. return;
  28593. }
  28594. promise._state = REJECTED;
  28595. promise._result = reason;
  28596. asap(publishRejection, promise);
  28597. }
  28598. function subscribe(parent, child, onFulfillment, onRejection) {
  28599. var _subscribers = parent._subscribers;
  28600. var length = _subscribers.length;
  28601. parent._onerror = null;
  28602. _subscribers[length] = child;
  28603. _subscribers[length + FULFILLED] = onFulfillment;
  28604. _subscribers[length + REJECTED] = onRejection;
  28605. if (length === 0 && parent._state) {
  28606. asap(publish, parent);
  28607. }
  28608. }
  28609. function publish(promise) {
  28610. var subscribers = promise._subscribers;
  28611. var settled = promise._state;
  28612. if (subscribers.length === 0) {
  28613. return;
  28614. }
  28615. var child = void 0,
  28616. callback = void 0,
  28617. detail = promise._result;
  28618. for (var i = 0; i < subscribers.length; i += 3) {
  28619. child = subscribers[i];
  28620. callback = subscribers[i + settled];
  28621. if (child) {
  28622. invokeCallback(settled, child, callback, detail);
  28623. } else {
  28624. callback(detail);
  28625. }
  28626. }
  28627. promise._subscribers.length = 0;
  28628. }
  28629. function invokeCallback(settled, promise, callback, detail) {
  28630. var hasCallback = isFunction(callback),
  28631. value = void 0,
  28632. error = void 0,
  28633. succeeded = true;
  28634. if (hasCallback) {
  28635. try {
  28636. value = callback(detail);
  28637. } catch (e) {
  28638. succeeded = false;
  28639. error = e;
  28640. }
  28641. if (promise === value) {
  28642. reject(promise, cannotReturnOwn());
  28643. return;
  28644. }
  28645. } else {
  28646. value = detail;
  28647. }
  28648. if (promise._state !== PENDING) {
  28649. // noop
  28650. } else if (hasCallback && succeeded) {
  28651. resolve(promise, value);
  28652. } else if (succeeded === false) {
  28653. reject(promise, error);
  28654. } else if (settled === FULFILLED) {
  28655. fulfill(promise, value);
  28656. } else if (settled === REJECTED) {
  28657. reject(promise, value);
  28658. }
  28659. }
  28660. function initializePromise(promise, resolver) {
  28661. try {
  28662. resolver(
  28663. function resolvePromise(value) {
  28664. resolve(promise, value);
  28665. },
  28666. function rejectPromise(reason) {
  28667. reject(promise, reason);
  28668. }
  28669. );
  28670. } catch (e) {
  28671. reject(promise, e);
  28672. }
  28673. }
  28674. var id = 0;
  28675. function nextId() {
  28676. return id++;
  28677. }
  28678. function makePromise(promise) {
  28679. promise[PROMISE_ID] = id++;
  28680. promise._state = undefined;
  28681. promise._result = undefined;
  28682. promise._subscribers = [];
  28683. }
  28684. function validationError() {
  28685. return new Error('Array Methods must be provided an Array');
  28686. }
  28687. var Enumerator = (function() {
  28688. function Enumerator(Constructor, input) {
  28689. this._instanceConstructor = Constructor;
  28690. this.promise = new Constructor(noop);
  28691. if (!this.promise[PROMISE_ID]) {
  28692. makePromise(this.promise);
  28693. }
  28694. if (isArray(input)) {
  28695. this.length = input.length;
  28696. this._remaining = input.length;
  28697. this._result = new Array(this.length);
  28698. if (this.length === 0) {
  28699. fulfill(this.promise, this._result);
  28700. } else {
  28701. this.length = this.length || 0;
  28702. this._enumerate(input);
  28703. if (this._remaining === 0) {
  28704. fulfill(this.promise, this._result);
  28705. }
  28706. }
  28707. } else {
  28708. reject(this.promise, validationError());
  28709. }
  28710. }
  28711. Enumerator.prototype._enumerate = function _enumerate(input) {
  28712. for (var i = 0; this._state === PENDING && i < input.length; i++) {
  28713. this._eachEntry(input[i], i);
  28714. }
  28715. };
  28716. Enumerator.prototype._eachEntry = function _eachEntry(entry, i) {
  28717. var c = this._instanceConstructor;
  28718. var resolve$$1 = c.resolve;
  28719. if (resolve$$1 === resolve$1) {
  28720. var _then = void 0;
  28721. var error = void 0;
  28722. var didError = false;
  28723. try {
  28724. _then = entry.then;
  28725. } catch (e) {
  28726. didError = true;
  28727. error = e;
  28728. }
  28729. if (_then === then && entry._state !== PENDING) {
  28730. this._settledAt(entry._state, i, entry._result);
  28731. } else if (typeof _then !== 'function') {
  28732. this._remaining--;
  28733. this._result[i] = entry;
  28734. } else if (c === Promise$1) {
  28735. var promise = new c(noop);
  28736. if (didError) {
  28737. reject(promise, error);
  28738. } else {
  28739. handleMaybeThenable(promise, entry, _then);
  28740. }
  28741. this._willSettleAt(promise, i);
  28742. } else {
  28743. this._willSettleAt(
  28744. new c(function(resolve$$1) {
  28745. return resolve$$1(entry);
  28746. }),
  28747. i
  28748. );
  28749. }
  28750. } else {
  28751. this._willSettleAt(resolve$$1(entry), i);
  28752. }
  28753. };
  28754. Enumerator.prototype._settledAt = function _settledAt(state, i, value) {
  28755. var promise = this.promise;
  28756. if (promise._state === PENDING) {
  28757. this._remaining--;
  28758. if (state === REJECTED) {
  28759. reject(promise, value);
  28760. } else {
  28761. this._result[i] = value;
  28762. }
  28763. }
  28764. if (this._remaining === 0) {
  28765. fulfill(promise, this._result);
  28766. }
  28767. };
  28768. Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) {
  28769. var enumerator = this;
  28770. subscribe(
  28771. promise,
  28772. undefined,
  28773. function(value) {
  28774. return enumerator._settledAt(FULFILLED, i, value);
  28775. },
  28776. function(reason) {
  28777. return enumerator._settledAt(REJECTED, i, reason);
  28778. }
  28779. );
  28780. };
  28781. return Enumerator;
  28782. })();
  28783. /**
  28784. `Promise.all` accepts an array of promises, and returns a new promise which
  28785. is fulfilled with an array of fulfillment values for the passed promises, or
  28786. rejected with the reason of the first passed promise to be rejected. It casts all
  28787. elements of the passed iterable to promises as it runs this algorithm.
  28788. Example:
  28789. ```javascript
  28790. let promise1 = resolve(1);
  28791. let promise2 = resolve(2);
  28792. let promise3 = resolve(3);
  28793. let promises = [ promise1, promise2, promise3 ];
  28794. Promise.all(promises).then(function(array){
  28795. // The array here would be [ 1, 2, 3 ];
  28796. });
  28797. ```
  28798. If any of the `promises` given to `all` are rejected, the first promise
  28799. that is rejected will be given as an argument to the returned promises's
  28800. rejection handler. For example:
  28801. Example:
  28802. ```javascript
  28803. let promise1 = resolve(1);
  28804. let promise2 = reject(new Error("2"));
  28805. let promise3 = reject(new Error("3"));
  28806. let promises = [ promise1, promise2, promise3 ];
  28807. Promise.all(promises).then(function(array){
  28808. // Code here never runs because there are rejected promises!
  28809. }, function(error) {
  28810. // error.message === "2"
  28811. });
  28812. ```
  28813. @method all
  28814. @static
  28815. @param {Array} entries array of promises
  28816. @param {String} label optional string for labeling the promise.
  28817. Useful for tooling.
  28818. @return {Promise} promise that is fulfilled when all `promises` have been
  28819. fulfilled, or rejected if any of them become rejected.
  28820. @static
  28821. */
  28822. function all(entries) {
  28823. return new Enumerator(this, entries).promise;
  28824. }
  28825. /**
  28826. `Promise.race` returns a new promise which is settled in the same way as the
  28827. first passed promise to settle.
  28828. Example:
  28829. ```javascript
  28830. let promise1 = new Promise(function(resolve, reject){
  28831. setTimeout(function(){
  28832. resolve('promise 1');
  28833. }, 200);
  28834. });
  28835. let promise2 = new Promise(function(resolve, reject){
  28836. setTimeout(function(){
  28837. resolve('promise 2');
  28838. }, 100);
  28839. });
  28840. Promise.race([promise1, promise2]).then(function(result){
  28841. // result === 'promise 2' because it was resolved before promise1
  28842. // was resolved.
  28843. });
  28844. ```
  28845. `Promise.race` is deterministic in that only the state of the first
  28846. settled promise matters. For example, even if other promises given to the
  28847. `promises` array argument are resolved, but the first settled promise has
  28848. become rejected before the other promises became fulfilled, the returned
  28849. promise will become rejected:
  28850. ```javascript
  28851. let promise1 = new Promise(function(resolve, reject){
  28852. setTimeout(function(){
  28853. resolve('promise 1');
  28854. }, 200);
  28855. });
  28856. let promise2 = new Promise(function(resolve, reject){
  28857. setTimeout(function(){
  28858. reject(new Error('promise 2'));
  28859. }, 100);
  28860. });
  28861. Promise.race([promise1, promise2]).then(function(result){
  28862. // Code here never runs
  28863. }, function(reason){
  28864. // reason.message === 'promise 2' because promise 2 became rejected before
  28865. // promise 1 became fulfilled
  28866. });
  28867. ```
  28868. An example real-world use case is implementing timeouts:
  28869. ```javascript
  28870. Promise.race([ajax('foo.json'), timeout(5000)])
  28871. ```
  28872. @method race
  28873. @static
  28874. @param {Array} promises array of promises to observe
  28875. Useful for tooling.
  28876. @return {Promise} a promise which settles in the same way as the first passed
  28877. promise to settle.
  28878. */
  28879. function race(entries) {
  28880. /*jshint validthis:true */
  28881. var Constructor = this;
  28882. if (!isArray(entries)) {
  28883. return new Constructor(function(_, reject) {
  28884. return reject(new TypeError('You must pass an array to race.'));
  28885. });
  28886. } else {
  28887. return new Constructor(function(resolve, reject) {
  28888. var length = entries.length;
  28889. for (var i = 0; i < length; i++) {
  28890. Constructor.resolve(entries[i]).then(resolve, reject);
  28891. }
  28892. });
  28893. }
  28894. }
  28895. /**
  28896. `Promise.reject` returns a promise rejected with the passed `reason`.
  28897. It is shorthand for the following:
  28898. ```javascript
  28899. let promise = new Promise(function(resolve, reject){
  28900. reject(new Error('WHOOPS'));
  28901. });
  28902. promise.then(function(value){
  28903. // Code here doesn't run because the promise is rejected!
  28904. }, function(reason){
  28905. // reason.message === 'WHOOPS'
  28906. });
  28907. ```
  28908. Instead of writing the above, your code now simply becomes the following:
  28909. ```javascript
  28910. let promise = Promise.reject(new Error('WHOOPS'));
  28911. promise.then(function(value){
  28912. // Code here doesn't run because the promise is rejected!
  28913. }, function(reason){
  28914. // reason.message === 'WHOOPS'
  28915. });
  28916. ```
  28917. @method reject
  28918. @static
  28919. @param {Any} reason value that the returned promise will be rejected with.
  28920. Useful for tooling.
  28921. @return {Promise} a promise rejected with the given `reason`.
  28922. */
  28923. function reject$1(reason) {
  28924. /*jshint validthis:true */
  28925. var Constructor = this;
  28926. var promise = new Constructor(noop);
  28927. reject(promise, reason);
  28928. return promise;
  28929. }
  28930. function needsResolver() {
  28931. throw new TypeError(
  28932. 'You must pass a resolver function as the first argument to the promise constructor'
  28933. );
  28934. }
  28935. function needsNew() {
  28936. throw new TypeError(
  28937. "Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function."
  28938. );
  28939. }
  28940. /**
  28941. Promise objects represent the eventual result of an asynchronous operation. The
  28942. primary way of interacting with a promise is through its `then` method, which
  28943. registers callbacks to receive either a promise's eventual value or the reason
  28944. why the promise cannot be fulfilled.
  28945. Terminology
  28946. -----------
  28947. - `promise` is an object or function with a `then` method whose behavior conforms to this specification.
  28948. - `thenable` is an object or function that defines a `then` method.
  28949. - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
  28950. - `exception` is a value that is thrown using the throw statement.
  28951. - `reason` is a value that indicates why a promise was rejected.
  28952. - `settled` the final resting state of a promise, fulfilled or rejected.
  28953. A promise can be in one of three states: pending, fulfilled, or rejected.
  28954. Promises that are fulfilled have a fulfillment value and are in the fulfilled
  28955. state. Promises that are rejected have a rejection reason and are in the
  28956. rejected state. A fulfillment value is never a thenable.
  28957. Promises can also be said to *resolve* a value. If this value is also a
  28958. promise, then the original promise's settled state will match the value's
  28959. settled state. So a promise that *resolves* a promise that rejects will
  28960. itself reject, and a promise that *resolves* a promise that fulfills will
  28961. itself fulfill.
  28962. Basic Usage:
  28963. ------------
  28964. ```js
  28965. let promise = new Promise(function(resolve, reject) {
  28966. // on success
  28967. resolve(value);
  28968. // on failure
  28969. reject(reason);
  28970. });
  28971. promise.then(function(value) {
  28972. // on fulfillment
  28973. }, function(reason) {
  28974. // on rejection
  28975. });
  28976. ```
  28977. Advanced Usage:
  28978. ---------------
  28979. Promises shine when abstracting away asynchronous interactions such as
  28980. `XMLHttpRequest`s.
  28981. ```js
  28982. function getJSON(url) {
  28983. return new Promise(function(resolve, reject){
  28984. let xhr = new XMLHttpRequest();
  28985. xhr.open('GET', url);
  28986. xhr.onreadystatechange = handler;
  28987. xhr.responseType = 'json';
  28988. xhr.setRequestHeader('Accept', 'application/json');
  28989. xhr.send();
  28990. function handler() {
  28991. if (this.readyState === this.DONE) {
  28992. if (this.status === 200) {
  28993. resolve(this.response);
  28994. } else {
  28995. reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
  28996. }
  28997. }
  28998. };
  28999. });
  29000. }
  29001. getJSON('/posts.json').then(function(json) {
  29002. // on fulfillment
  29003. }, function(reason) {
  29004. // on rejection
  29005. });
  29006. ```
  29007. Unlike callbacks, promises are great composable primitives.
  29008. ```js
  29009. Promise.all([
  29010. getJSON('/posts'),
  29011. getJSON('/comments')
  29012. ]).then(function(values){
  29013. values[0] // => postsJSON
  29014. values[1] // => commentsJSON
  29015. return values;
  29016. });
  29017. ```
  29018. @class Promise
  29019. @param {Function} resolver
  29020. Useful for tooling.
  29021. @constructor
  29022. */
  29023. var Promise$1 = (function() {
  29024. function Promise(resolver) {
  29025. this[PROMISE_ID] = nextId();
  29026. this._result = this._state = undefined;
  29027. this._subscribers = [];
  29028. if (noop !== resolver) {
  29029. typeof resolver !== 'function' && needsResolver();
  29030. this instanceof Promise
  29031. ? initializePromise(this, resolver)
  29032. : needsNew();
  29033. }
  29034. }
  29035. /**
  29036. The primary way of interacting with a promise is through its `then` method,
  29037. which registers callbacks to receive either a promise's eventual value or the
  29038. reason why the promise cannot be fulfilled.
  29039. ```js
  29040. findUser().then(function(user){
  29041. // user is available
  29042. }, function(reason){
  29043. // user is unavailable, and you are given the reason why
  29044. });
  29045. ```
  29046. Chaining
  29047. --------
  29048. The return value of `then` is itself a promise. This second, 'downstream'
  29049. promise is resolved with the return value of the first promise's fulfillment
  29050. or rejection handler, or rejected if the handler throws an exception.
  29051. ```js
  29052. findUser().then(function (user) {
  29053. return user.name;
  29054. }, function (reason) {
  29055. return 'default name';
  29056. }).then(function (userName) {
  29057. // If `findUser` fulfilled, `userName` will be the user's name, otherwise it
  29058. // will be `'default name'`
  29059. });
  29060. findUser().then(function (user) {
  29061. throw new Error('Found user, but still unhappy');
  29062. }, function (reason) {
  29063. throw new Error('`findUser` rejected and we're unhappy');
  29064. }).then(function (value) {
  29065. // never reached
  29066. }, function (reason) {
  29067. // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
  29068. // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
  29069. });
  29070. ```
  29071. If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
  29072. ```js
  29073. findUser().then(function (user) {
  29074. throw new PedagogicalException('Upstream error');
  29075. }).then(function (value) {
  29076. // never reached
  29077. }).then(function (value) {
  29078. // never reached
  29079. }, function (reason) {
  29080. // The `PedgagocialException` is propagated all the way down to here
  29081. });
  29082. ```
  29083. Assimilation
  29084. ------------
  29085. Sometimes the value you want to propagate to a downstream promise can only be
  29086. retrieved asynchronously. This can be achieved by returning a promise in the
  29087. fulfillment or rejection handler. The downstream promise will then be pending
  29088. until the returned promise is settled. This is called *assimilation*.
  29089. ```js
  29090. findUser().then(function (user) {
  29091. return findCommentsByAuthor(user);
  29092. }).then(function (comments) {
  29093. // The user's comments are now available
  29094. });
  29095. ```
  29096. If the assimliated promise rejects, then the downstream promise will also reject.
  29097. ```js
  29098. findUser().then(function (user) {
  29099. return findCommentsByAuthor(user);
  29100. }).then(function (comments) {
  29101. // If `findCommentsByAuthor` fulfills, we'll have the value here
  29102. }, function (reason) {
  29103. // If `findCommentsByAuthor` rejects, we'll have the reason here
  29104. });
  29105. ```
  29106. Simple Example
  29107. --------------
  29108. Synchronous Example
  29109. ```javascript
  29110. let result;
  29111. try {
  29112. result = findResult();
  29113. // success
  29114. } catch(reason) {
  29115. // failure
  29116. }
  29117. ```
  29118. Errback Example
  29119. ```js
  29120. findResult(function(result, err){
  29121. if (err) {
  29122. // failure
  29123. } else {
  29124. // success
  29125. }
  29126. });
  29127. ```
  29128. Promise Example;
  29129. ```javascript
  29130. findResult().then(function(result){
  29131. // success
  29132. }, function(reason){
  29133. // failure
  29134. });
  29135. ```
  29136. Advanced Example
  29137. --------------
  29138. Synchronous Example
  29139. ```javascript
  29140. let author, books;
  29141. try {
  29142. author = findAuthor();
  29143. books = findBooksByAuthor(author);
  29144. // success
  29145. } catch(reason) {
  29146. // failure
  29147. }
  29148. ```
  29149. Errback Example
  29150. ```js
  29151. function foundBooks(books) {
  29152. }
  29153. function failure(reason) {
  29154. }
  29155. findAuthor(function(author, err){
  29156. if (err) {
  29157. failure(err);
  29158. // failure
  29159. } else {
  29160. try {
  29161. findBoooksByAuthor(author, function(books, err) {
  29162. if (err) {
  29163. failure(err);
  29164. } else {
  29165. try {
  29166. foundBooks(books);
  29167. } catch(reason) {
  29168. failure(reason);
  29169. }
  29170. }
  29171. });
  29172. } catch(error) {
  29173. failure(err);
  29174. }
  29175. // success
  29176. }
  29177. });
  29178. ```
  29179. Promise Example;
  29180. ```javascript
  29181. findAuthor().
  29182. then(findBooksByAuthor).
  29183. then(function(books){
  29184. // found books
  29185. }).catch(function(reason){
  29186. // something went wrong
  29187. });
  29188. ```
  29189. @method then
  29190. @param {Function} onFulfilled
  29191. @param {Function} onRejected
  29192. Useful for tooling.
  29193. @return {Promise}
  29194. */
  29195. /**
  29196. `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
  29197. as the catch block of a try/catch statement.
  29198. ```js
  29199. function findAuthor(){
  29200. throw new Error('couldn't find that author');
  29201. }
  29202. // synchronous
  29203. try {
  29204. findAuthor();
  29205. } catch(reason) {
  29206. // something went wrong
  29207. }
  29208. // async with promises
  29209. findAuthor().catch(function(reason){
  29210. // something went wrong
  29211. });
  29212. ```
  29213. @method catch
  29214. @param {Function} onRejection
  29215. Useful for tooling.
  29216. @return {Promise}
  29217. */
  29218. Promise.prototype.catch = function _catch(onRejection) {
  29219. return this.then(null, onRejection);
  29220. };
  29221. /**
  29222. `finally` will be invoked regardless of the promise's fate just as native
  29223. try/catch/finally behaves
  29224. Synchronous example:
  29225. ```js
  29226. findAuthor() {
  29227. if (Math.random() > 0.5) {
  29228. throw new Error();
  29229. }
  29230. return new Author();
  29231. }
  29232. try {
  29233. return findAuthor(); // succeed or fail
  29234. } catch(error) {
  29235. return findOtherAuther();
  29236. } finally {
  29237. // always runs
  29238. // doesn't affect the return value
  29239. }
  29240. ```
  29241. Asynchronous example:
  29242. ```js
  29243. findAuthor().catch(function(reason){
  29244. return findOtherAuther();
  29245. }).finally(function(){
  29246. // author was either found, or not
  29247. });
  29248. ```
  29249. @method finally
  29250. @param {Function} callback
  29251. @return {Promise}
  29252. */
  29253. Promise.prototype.finally = function _finally(callback) {
  29254. var promise = this;
  29255. var constructor = promise.constructor;
  29256. if (isFunction(callback)) {
  29257. return promise.then(
  29258. function(value) {
  29259. return constructor.resolve(callback()).then(function() {
  29260. return value;
  29261. });
  29262. },
  29263. function(reason) {
  29264. return constructor.resolve(callback()).then(function() {
  29265. throw reason;
  29266. });
  29267. }
  29268. );
  29269. }
  29270. return promise.then(callback, callback);
  29271. };
  29272. return Promise;
  29273. })();
  29274. Promise$1.prototype.then = then;
  29275. Promise$1.all = all;
  29276. Promise$1.race = race;
  29277. Promise$1.resolve = resolve$1;
  29278. Promise$1.reject = reject$1;
  29279. Promise$1._setScheduler = setScheduler;
  29280. Promise$1._setAsap = setAsap;
  29281. Promise$1._asap = asap;
  29282. /*global self*/
  29283. function polyfill() {
  29284. var local = void 0;
  29285. if (typeof global !== 'undefined') {
  29286. local = global;
  29287. } else if (typeof self !== 'undefined') {
  29288. local = self;
  29289. } else {
  29290. try {
  29291. local = Function('return this')();
  29292. } catch (e) {
  29293. throw new Error(
  29294. 'polyfill failed because global object is unavailable in this environment'
  29295. );
  29296. }
  29297. }
  29298. var P = local.Promise;
  29299. if (P) {
  29300. var promiseToString = null;
  29301. try {
  29302. promiseToString = Object.prototype.toString.call(P.resolve());
  29303. } catch (e) {
  29304. // silently ignored
  29305. }
  29306. if (promiseToString === '[object Promise]' && !P.cast) {
  29307. return;
  29308. }
  29309. }
  29310. local.Promise = Promise$1;
  29311. }
  29312. // Strange compat..
  29313. Promise$1.polyfill = polyfill;
  29314. Promise$1.Promise = Promise$1;
  29315. return Promise$1;
  29316. });
  29317. }.call(
  29318. this,
  29319. _dereq_('_process'),
  29320. typeof global !== 'undefined'
  29321. ? global
  29322. : typeof self !== 'undefined'
  29323. ? self
  29324. : typeof window !== 'undefined' ? window : {}
  29325. ));
  29326. },
  29327. { _process: 260 }
  29328. ],
  29329. 249: [
  29330. function(_dereq_, module, exports) {
  29331. (function(global, factory) {
  29332. if (typeof define === 'function' && define.amd) {
  29333. define(['exports', 'module'], factory);
  29334. } else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
  29335. factory(exports, module);
  29336. } else {
  29337. var mod = {
  29338. exports: {}
  29339. };
  29340. factory(mod.exports, mod);
  29341. global.fetchJsonp = mod.exports;
  29342. }
  29343. })(this, function(exports, module) {
  29344. 'use strict';
  29345. var defaultOptions = {
  29346. timeout: 5000,
  29347. jsonpCallback: 'callback',
  29348. jsonpCallbackFunction: null
  29349. };
  29350. function generateCallbackFunction() {
  29351. return 'jsonp_' + Date.now() + '_' + Math.ceil(Math.random() * 100000);
  29352. }
  29353. function clearFunction(functionName) {
  29354. // IE8 throws an exception when you try to delete a property on window
  29355. // http://stackoverflow.com/a/1824228/751089
  29356. try {
  29357. delete window[functionName];
  29358. } catch (e) {
  29359. window[functionName] = undefined;
  29360. }
  29361. }
  29362. function removeScript(scriptId) {
  29363. var script = document.getElementById(scriptId);
  29364. if (script) {
  29365. document.getElementsByTagName('head')[0].removeChild(script);
  29366. }
  29367. }
  29368. function fetchJsonp(_url) {
  29369. var options =
  29370. arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  29371. // to avoid param reassign
  29372. var url = _url;
  29373. var timeout = options.timeout || defaultOptions.timeout;
  29374. var jsonpCallback = options.jsonpCallback || defaultOptions.jsonpCallback;
  29375. var timeoutId = undefined;
  29376. return new Promise(function(resolve, reject) {
  29377. var callbackFunction =
  29378. options.jsonpCallbackFunction || generateCallbackFunction();
  29379. var scriptId = jsonpCallback + '_' + callbackFunction;
  29380. window[callbackFunction] = function(response) {
  29381. resolve({
  29382. ok: true,
  29383. // keep consistent with fetch API
  29384. json: function json() {
  29385. return Promise.resolve(response);
  29386. }
  29387. });
  29388. if (timeoutId) clearTimeout(timeoutId);
  29389. removeScript(scriptId);
  29390. clearFunction(callbackFunction);
  29391. };
  29392. // Check if the user set their own params, and if not add a ? to start a list of params
  29393. url += url.indexOf('?') === -1 ? '?' : '&';
  29394. var jsonpScript = document.createElement('script');
  29395. jsonpScript.setAttribute(
  29396. 'src',
  29397. '' + url + jsonpCallback + '=' + callbackFunction
  29398. );
  29399. if (options.charset) {
  29400. jsonpScript.setAttribute('charset', options.charset);
  29401. }
  29402. jsonpScript.id = scriptId;
  29403. document.getElementsByTagName('head')[0].appendChild(jsonpScript);
  29404. timeoutId = setTimeout(function() {
  29405. reject(new Error('JSONP request to ' + _url + ' timed out'));
  29406. clearFunction(callbackFunction);
  29407. removeScript(scriptId);
  29408. window[callbackFunction] = function() {
  29409. clearFunction(callbackFunction);
  29410. };
  29411. }, timeout);
  29412. // Caught if got 404/500
  29413. jsonpScript.onerror = function() {
  29414. reject(new Error('JSONP request to ' + _url + ' failed'));
  29415. clearFunction(callbackFunction);
  29416. removeScript(scriptId);
  29417. if (timeoutId) clearTimeout(timeoutId);
  29418. };
  29419. });
  29420. }
  29421. // export as global function
  29422. /*
  29423. let local;
  29424. if (typeof global !== 'undefined') {
  29425. local = global;
  29426. } else if (typeof self !== 'undefined') {
  29427. local = self;
  29428. } else {
  29429. try {
  29430. local = Function('return this')();
  29431. } catch (e) {
  29432. throw new Error('polyfill failed because global object is unavailable in this environment');
  29433. }
  29434. }
  29435. local.fetchJsonp = fetchJsonp;
  29436. */
  29437. module.exports = fetchJsonp;
  29438. });
  29439. },
  29440. {}
  29441. ],
  29442. 250: [
  29443. function(_dereq_, module, exports) {
  29444. /* FileSaver.js
  29445. * A saveAs() FileSaver implementation.
  29446. * 1.3.2
  29447. * 2016-06-16 18:25:19
  29448. *
  29449. * By Eli Grey, http://eligrey.com
  29450. * License: MIT
  29451. * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
  29452. */
  29453. /*global self */
  29454. /*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
  29455. /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
  29456. var saveAs =
  29457. saveAs ||
  29458. (function(view) {
  29459. 'use strict';
  29460. // IE <10 is explicitly unsupported
  29461. if (
  29462. typeof view === 'undefined' ||
  29463. (typeof navigator !== 'undefined' &&
  29464. /MSIE [1-9]\./.test(navigator.userAgent))
  29465. ) {
  29466. return;
  29467. }
  29468. var doc = view.document,
  29469. // only get URL when necessary in case Blob.js hasn't overridden it yet
  29470. get_URL = function() {
  29471. return view.URL || view.webkitURL || view;
  29472. },
  29473. save_link = doc.createElementNS('http://www.w3.org/1999/xhtml', 'a'),
  29474. can_use_save_link = 'download' in save_link,
  29475. click = function(node) {
  29476. var event = new MouseEvent('click');
  29477. node.dispatchEvent(event);
  29478. },
  29479. is_safari = /constructor/i.test(view.HTMLElement) || view.safari,
  29480. is_chrome_ios = /CriOS\/[\d]+/.test(navigator.userAgent),
  29481. throw_outside = function(ex) {
  29482. (view.setImmediate || view.setTimeout)(function() {
  29483. throw ex;
  29484. }, 0);
  29485. },
  29486. force_saveable_type = 'application/octet-stream',
  29487. // the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to
  29488. arbitrary_revoke_timeout = 1000 * 40, // in ms
  29489. revoke = function(file) {
  29490. var revoker = function() {
  29491. if (typeof file === 'string') {
  29492. // file is an object URL
  29493. get_URL().revokeObjectURL(file);
  29494. } else {
  29495. // file is a File
  29496. file.remove();
  29497. }
  29498. };
  29499. setTimeout(revoker, arbitrary_revoke_timeout);
  29500. },
  29501. dispatch = function(filesaver, event_types, event) {
  29502. event_types = [].concat(event_types);
  29503. var i = event_types.length;
  29504. while (i--) {
  29505. var listener = filesaver['on' + event_types[i]];
  29506. if (typeof listener === 'function') {
  29507. try {
  29508. listener.call(filesaver, event || filesaver);
  29509. } catch (ex) {
  29510. throw_outside(ex);
  29511. }
  29512. }
  29513. }
  29514. },
  29515. auto_bom = function(blob) {
  29516. // prepend BOM for UTF-8 XML and text/* types (including HTML)
  29517. // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
  29518. if (
  29519. /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(
  29520. blob.type
  29521. )
  29522. ) {
  29523. return new Blob([String.fromCharCode(0xfeff), blob], {
  29524. type: blob.type
  29525. });
  29526. }
  29527. return blob;
  29528. },
  29529. FileSaver = function(blob, name, no_auto_bom) {
  29530. if (!no_auto_bom) {
  29531. blob = auto_bom(blob);
  29532. }
  29533. // First try a.download, then web filesystem, then object URLs
  29534. var filesaver = this,
  29535. type = blob.type,
  29536. force = type === force_saveable_type,
  29537. object_url,
  29538. dispatch_all = function() {
  29539. dispatch(filesaver, 'writestart progress write writeend'.split(' '));
  29540. },
  29541. // on any filesys errors revert to saving with object URLs
  29542. fs_error = function() {
  29543. if ((is_chrome_ios || (force && is_safari)) && view.FileReader) {
  29544. // Safari doesn't allow downloading of blob urls
  29545. var reader = new FileReader();
  29546. reader.onloadend = function() {
  29547. var url = is_chrome_ios
  29548. ? reader.result
  29549. : reader.result.replace(
  29550. /^data:[^;]*;/,
  29551. 'data:attachment/file;'
  29552. );
  29553. var popup = view.open(url, '_blank');
  29554. if (!popup) view.location.href = url;
  29555. url = undefined; // release reference before dispatching
  29556. filesaver.readyState = filesaver.DONE;
  29557. dispatch_all();
  29558. };
  29559. reader.readAsDataURL(blob);
  29560. filesaver.readyState = filesaver.INIT;
  29561. return;
  29562. }
  29563. // don't create more object URLs than needed
  29564. if (!object_url) {
  29565. object_url = get_URL().createObjectURL(blob);
  29566. }
  29567. if (force) {
  29568. view.location.href = object_url;
  29569. } else {
  29570. var opened = view.open(object_url, '_blank');
  29571. if (!opened) {
  29572. // Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html
  29573. view.location.href = object_url;
  29574. }
  29575. }
  29576. filesaver.readyState = filesaver.DONE;
  29577. dispatch_all();
  29578. revoke(object_url);
  29579. };
  29580. filesaver.readyState = filesaver.INIT;
  29581. if (can_use_save_link) {
  29582. object_url = get_URL().createObjectURL(blob);
  29583. setTimeout(function() {
  29584. save_link.href = object_url;
  29585. save_link.download = name;
  29586. click(save_link);
  29587. dispatch_all();
  29588. revoke(object_url);
  29589. filesaver.readyState = filesaver.DONE;
  29590. });
  29591. return;
  29592. }
  29593. fs_error();
  29594. },
  29595. FS_proto = FileSaver.prototype,
  29596. saveAs = function(blob, name, no_auto_bom) {
  29597. return new FileSaver(blob, name || blob.name || 'download', no_auto_bom);
  29598. };
  29599. // IE 10+ (native saveAs)
  29600. if (typeof navigator !== 'undefined' && navigator.msSaveOrOpenBlob) {
  29601. return function(blob, name, no_auto_bom) {
  29602. name = name || blob.name || 'download';
  29603. if (!no_auto_bom) {
  29604. blob = auto_bom(blob);
  29605. }
  29606. return navigator.msSaveOrOpenBlob(blob, name);
  29607. };
  29608. }
  29609. FS_proto.abort = function() {};
  29610. FS_proto.readyState = FS_proto.INIT = 0;
  29611. FS_proto.WRITING = 1;
  29612. FS_proto.DONE = 2;
  29613. FS_proto.error = FS_proto.onwritestart = FS_proto.onprogress = FS_proto.onwrite = FS_proto.onabort = FS_proto.onerror = FS_proto.onwriteend = null;
  29614. return saveAs;
  29615. })(
  29616. (typeof self !== 'undefined' && self) ||
  29617. (typeof window !== 'undefined' && window) ||
  29618. this.content
  29619. );
  29620. // `self` is undefined in Firefox for Android content script context
  29621. // while `this` is nsIContentFrameMessageManager
  29622. // with an attribute `content` that corresponds to the window
  29623. if (typeof module !== 'undefined' && module.exports) {
  29624. module.exports.saveAs = saveAs;
  29625. } else if (
  29626. typeof define !== 'undefined' &&
  29627. define !== null &&
  29628. define.amd !== null
  29629. ) {
  29630. define('FileSaver.js', function() {
  29631. return saveAs;
  29632. });
  29633. }
  29634. },
  29635. {}
  29636. ],
  29637. 251: [
  29638. function(_dereq_, module, exports) {
  29639. 'use strict';
  29640. function _interopDefault(ex) {
  29641. return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex;
  29642. }
  29643. var _classCallCheck = _interopDefault(
  29644. _dereq_('@babel/runtime/helpers/classCallCheck')
  29645. );
  29646. var _createClass = _interopDefault(_dereq_('@babel/runtime/helpers/createClass'));
  29647. var arr = [];
  29648. var each = arr.forEach;
  29649. var slice = arr.slice;
  29650. function defaults(obj) {
  29651. each.call(slice.call(arguments, 1), function(source) {
  29652. if (source) {
  29653. for (var prop in source) {
  29654. if (obj[prop] === undefined) obj[prop] = source[prop];
  29655. }
  29656. }
  29657. });
  29658. return obj;
  29659. }
  29660. var cookie = {
  29661. create: function create(name, value, minutes, domain) {
  29662. var expires;
  29663. if (minutes) {
  29664. var date = new Date();
  29665. date.setTime(date.getTime() + minutes * 60 * 1000);
  29666. expires = '; expires=' + date.toGMTString();
  29667. } else expires = '';
  29668. domain = domain ? 'domain=' + domain + ';' : '';
  29669. document.cookie = name + '=' + value + expires + ';' + domain + 'path=/';
  29670. },
  29671. read: function read(name) {
  29672. var nameEQ = name + '=';
  29673. var ca = document.cookie.split(';');
  29674. for (var i = 0; i < ca.length; i++) {
  29675. var c = ca[i];
  29676. while (c.charAt(0) === ' ') {
  29677. c = c.substring(1, c.length);
  29678. }
  29679. if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
  29680. }
  29681. return null;
  29682. },
  29683. remove: function remove(name) {
  29684. this.create(name, '', -1);
  29685. }
  29686. };
  29687. var cookie$1 = {
  29688. name: 'cookie',
  29689. lookup: function lookup(options) {
  29690. var found;
  29691. if (options.lookupCookie && typeof document !== 'undefined') {
  29692. var c = cookie.read(options.lookupCookie);
  29693. if (c) found = c;
  29694. }
  29695. return found;
  29696. },
  29697. cacheUserLanguage: function cacheUserLanguage(lng, options) {
  29698. if (options.lookupCookie && typeof document !== 'undefined') {
  29699. cookie.create(
  29700. options.lookupCookie,
  29701. lng,
  29702. options.cookieMinutes,
  29703. options.cookieDomain
  29704. );
  29705. }
  29706. }
  29707. };
  29708. var querystring = {
  29709. name: 'querystring',
  29710. lookup: function lookup(options) {
  29711. var found;
  29712. if (typeof window !== 'undefined') {
  29713. var query = window.location.search.substring(1);
  29714. var params = query.split('&');
  29715. for (var i = 0; i < params.length; i++) {
  29716. var pos = params[i].indexOf('=');
  29717. if (pos > 0) {
  29718. var key = params[i].substring(0, pos);
  29719. if (key === options.lookupQuerystring) {
  29720. found = params[i].substring(pos + 1);
  29721. }
  29722. }
  29723. }
  29724. }
  29725. return found;
  29726. }
  29727. };
  29728. var hasLocalStorageSupport;
  29729. try {
  29730. hasLocalStorageSupport = window !== 'undefined' && window.localStorage !== null;
  29731. var testKey = 'i18next.translate.boo';
  29732. window.localStorage.setItem(testKey, 'foo');
  29733. window.localStorage.removeItem(testKey);
  29734. } catch (e) {
  29735. hasLocalStorageSupport = false;
  29736. }
  29737. var localStorage = {
  29738. name: 'localStorage',
  29739. lookup: function lookup(options) {
  29740. var found;
  29741. if (options.lookupLocalStorage && hasLocalStorageSupport) {
  29742. var lng = window.localStorage.getItem(options.lookupLocalStorage);
  29743. if (lng) found = lng;
  29744. }
  29745. return found;
  29746. },
  29747. cacheUserLanguage: function cacheUserLanguage(lng, options) {
  29748. if (options.lookupLocalStorage && hasLocalStorageSupport) {
  29749. window.localStorage.setItem(options.lookupLocalStorage, lng);
  29750. }
  29751. }
  29752. };
  29753. var navigator$1 = {
  29754. name: 'navigator',
  29755. lookup: function lookup(options) {
  29756. var found = [];
  29757. if (typeof navigator !== 'undefined') {
  29758. if (navigator.languages) {
  29759. // chrome only; not an array, so can't use .push.apply instead of iterating
  29760. for (var i = 0; i < navigator.languages.length; i++) {
  29761. found.push(navigator.languages[i]);
  29762. }
  29763. }
  29764. if (navigator.userLanguage) {
  29765. found.push(navigator.userLanguage);
  29766. }
  29767. if (navigator.language) {
  29768. found.push(navigator.language);
  29769. }
  29770. }
  29771. return found.length > 0 ? found : undefined;
  29772. }
  29773. };
  29774. var htmlTag = {
  29775. name: 'htmlTag',
  29776. lookup: function lookup(options) {
  29777. var found;
  29778. var htmlTag =
  29779. options.htmlTag ||
  29780. (typeof document !== 'undefined' ? document.documentElement : null);
  29781. if (htmlTag && typeof htmlTag.getAttribute === 'function') {
  29782. found = htmlTag.getAttribute('lang');
  29783. }
  29784. return found;
  29785. }
  29786. };
  29787. var path = {
  29788. name: 'path',
  29789. lookup: function lookup(options) {
  29790. var found;
  29791. if (typeof window !== 'undefined') {
  29792. var language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
  29793. if (language instanceof Array) {
  29794. if (typeof options.lookupFromPathIndex === 'number') {
  29795. if (typeof language[options.lookupFromPathIndex] !== 'string') {
  29796. return undefined;
  29797. }
  29798. found = language[options.lookupFromPathIndex].replace('/', '');
  29799. } else {
  29800. found = language[0].replace('/', '');
  29801. }
  29802. }
  29803. }
  29804. return found;
  29805. }
  29806. };
  29807. var subdomain = {
  29808. name: 'subdomain',
  29809. lookup: function lookup(options) {
  29810. var found;
  29811. if (typeof window !== 'undefined') {
  29812. var language = window.location.href.match(
  29813. /(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi
  29814. );
  29815. if (language instanceof Array) {
  29816. if (typeof options.lookupFromSubdomainIndex === 'number') {
  29817. found = language[options.lookupFromSubdomainIndex]
  29818. .replace('http://', '')
  29819. .replace('https://', '')
  29820. .replace('.', '');
  29821. } else {
  29822. found = language[0]
  29823. .replace('http://', '')
  29824. .replace('https://', '')
  29825. .replace('.', '');
  29826. }
  29827. }
  29828. }
  29829. return found;
  29830. }
  29831. };
  29832. function getDefaults() {
  29833. return {
  29834. order: ['querystring', 'cookie', 'localStorage', 'navigator', 'htmlTag'],
  29835. lookupQuerystring: 'lng',
  29836. lookupCookie: 'i18next',
  29837. lookupLocalStorage: 'i18nextLng',
  29838. // cache user language
  29839. caches: ['localStorage'],
  29840. excludeCacheFor: ['cimode'],
  29841. //cookieMinutes: 10,
  29842. //cookieDomain: 'myDomain'
  29843. checkWhitelist: true
  29844. };
  29845. }
  29846. var Browser =
  29847. /*#__PURE__*/
  29848. (function() {
  29849. function Browser(services) {
  29850. var options =
  29851. arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  29852. _classCallCheck(this, Browser);
  29853. this.type = 'languageDetector';
  29854. this.detectors = {};
  29855. this.init(services, options);
  29856. }
  29857. _createClass(Browser, [
  29858. {
  29859. key: 'init',
  29860. value: function init(services) {
  29861. var options =
  29862. arguments.length > 1 && arguments[1] !== undefined
  29863. ? arguments[1]
  29864. : {};
  29865. var i18nOptions =
  29866. arguments.length > 2 && arguments[2] !== undefined
  29867. ? arguments[2]
  29868. : {};
  29869. this.services = services;
  29870. this.options = defaults(options, this.options || {}, getDefaults()); // backwards compatibility
  29871. if (this.options.lookupFromUrlIndex)
  29872. this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;
  29873. this.i18nOptions = i18nOptions;
  29874. this.addDetector(cookie$1);
  29875. this.addDetector(querystring);
  29876. this.addDetector(localStorage);
  29877. this.addDetector(navigator$1);
  29878. this.addDetector(htmlTag);
  29879. this.addDetector(path);
  29880. this.addDetector(subdomain);
  29881. }
  29882. },
  29883. {
  29884. key: 'addDetector',
  29885. value: function addDetector(detector) {
  29886. this.detectors[detector.name] = detector;
  29887. }
  29888. },
  29889. {
  29890. key: 'detect',
  29891. value: function detect(detectionOrder) {
  29892. var _this = this;
  29893. if (!detectionOrder) detectionOrder = this.options.order;
  29894. var detected = [];
  29895. detectionOrder.forEach(function(detectorName) {
  29896. if (_this.detectors[detectorName]) {
  29897. var lookup = _this.detectors[detectorName].lookup(_this.options);
  29898. if (lookup && typeof lookup === 'string') lookup = [lookup];
  29899. if (lookup) detected = detected.concat(lookup);
  29900. }
  29901. });
  29902. var found;
  29903. detected.forEach(function(lng) {
  29904. if (found) return;
  29905. var cleanedLng = _this.services.languageUtils.formatLanguageCode(lng);
  29906. if (
  29907. !_this.options.checkWhitelist ||
  29908. _this.services.languageUtils.isWhitelisted(cleanedLng)
  29909. )
  29910. found = cleanedLng;
  29911. });
  29912. if (!found) {
  29913. var fallbacks = this.i18nOptions.fallbackLng;
  29914. if (typeof fallbacks === 'string') fallbacks = [fallbacks];
  29915. if (!fallbacks) fallbacks = [];
  29916. if (Object.prototype.toString.apply(fallbacks) === '[object Array]') {
  29917. found = fallbacks[0];
  29918. } else {
  29919. found =
  29920. fallbacks[0] || (fallbacks['default'] && fallbacks['default'][0]);
  29921. }
  29922. }
  29923. return found;
  29924. }
  29925. },
  29926. {
  29927. key: 'cacheUserLanguage',
  29928. value: function cacheUserLanguage(lng, caches) {
  29929. var _this2 = this;
  29930. if (!caches) caches = this.options.caches;
  29931. if (!caches) return;
  29932. if (
  29933. this.options.excludeCacheFor &&
  29934. this.options.excludeCacheFor.indexOf(lng) > -1
  29935. )
  29936. return;
  29937. caches.forEach(function(cacheName) {
  29938. if (_this2.detectors[cacheName])
  29939. _this2.detectors[cacheName].cacheUserLanguage(lng, _this2.options);
  29940. });
  29941. }
  29942. }
  29943. ]);
  29944. return Browser;
  29945. })();
  29946. Browser.type = 'languageDetector';
  29947. module.exports = Browser;
  29948. },
  29949. {
  29950. '@babel/runtime/helpers/classCallCheck': 252,
  29951. '@babel/runtime/helpers/createClass': 253
  29952. }
  29953. ],
  29954. 252: [
  29955. function(_dereq_, module, exports) {
  29956. arguments[4][5][0].apply(exports, arguments);
  29957. },
  29958. { dup: 5 }
  29959. ],
  29960. 253: [
  29961. function(_dereq_, module, exports) {
  29962. arguments[4][6][0].apply(exports, arguments);
  29963. },
  29964. { dup: 6 }
  29965. ],
  29966. 254: [
  29967. function(_dereq_, module, exports) {
  29968. 'use strict';
  29969. function _interopDefault(ex) {
  29970. return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex;
  29971. }
  29972. var _typeof = _interopDefault(_dereq_('@babel/runtime/helpers/typeof'));
  29973. var _objectSpread = _interopDefault(
  29974. _dereq_('@babel/runtime/helpers/objectSpread')
  29975. );
  29976. var _classCallCheck = _interopDefault(
  29977. _dereq_('@babel/runtime/helpers/classCallCheck')
  29978. );
  29979. var _createClass = _interopDefault(_dereq_('@babel/runtime/helpers/createClass'));
  29980. var _possibleConstructorReturn = _interopDefault(
  29981. _dereq_('@babel/runtime/helpers/possibleConstructorReturn')
  29982. );
  29983. var _getPrototypeOf = _interopDefault(
  29984. _dereq_('@babel/runtime/helpers/getPrototypeOf')
  29985. );
  29986. var _assertThisInitialized = _interopDefault(
  29987. _dereq_('@babel/runtime/helpers/assertThisInitialized')
  29988. );
  29989. var _inherits = _interopDefault(_dereq_('@babel/runtime/helpers/inherits'));
  29990. var _toConsumableArray = _interopDefault(
  29991. _dereq_('@babel/runtime/helpers/toConsumableArray')
  29992. );
  29993. var _slicedToArray = _interopDefault(
  29994. _dereq_('@babel/runtime/helpers/slicedToArray')
  29995. );
  29996. var consoleLogger = {
  29997. type: 'logger',
  29998. log: function log(args) {
  29999. this.output('log', args);
  30000. },
  30001. warn: function warn(args) {
  30002. this.output('warn', args);
  30003. },
  30004. error: function error(args) {
  30005. this.output('error', args);
  30006. },
  30007. output: function output(type, args) {
  30008. var _console;
  30009. /* eslint no-console: 0 */
  30010. if (console && console[type])
  30011. (_console = console)[type].apply(_console, _toConsumableArray(args));
  30012. }
  30013. };
  30014. var Logger =
  30015. /*#__PURE__*/
  30016. (function() {
  30017. function Logger(concreteLogger) {
  30018. var options =
  30019. arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  30020. _classCallCheck(this, Logger);
  30021. this.init(concreteLogger, options);
  30022. }
  30023. _createClass(Logger, [
  30024. {
  30025. key: 'init',
  30026. value: function init(concreteLogger) {
  30027. var options =
  30028. arguments.length > 1 && arguments[1] !== undefined
  30029. ? arguments[1]
  30030. : {};
  30031. this.prefix = options.prefix || 'i18next:';
  30032. this.logger = concreteLogger || consoleLogger;
  30033. this.options = options;
  30034. this.debug = options.debug;
  30035. }
  30036. },
  30037. {
  30038. key: 'setDebug',
  30039. value: function setDebug(bool) {
  30040. this.debug = bool;
  30041. }
  30042. },
  30043. {
  30044. key: 'log',
  30045. value: function log() {
  30046. for (
  30047. var _len = arguments.length, args = new Array(_len), _key = 0;
  30048. _key < _len;
  30049. _key++
  30050. ) {
  30051. args[_key] = arguments[_key];
  30052. }
  30053. return this.forward(args, 'log', '', true);
  30054. }
  30055. },
  30056. {
  30057. key: 'warn',
  30058. value: function warn() {
  30059. for (
  30060. var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
  30061. _key2 < _len2;
  30062. _key2++
  30063. ) {
  30064. args[_key2] = arguments[_key2];
  30065. }
  30066. return this.forward(args, 'warn', '', true);
  30067. }
  30068. },
  30069. {
  30070. key: 'error',
  30071. value: function error() {
  30072. for (
  30073. var _len3 = arguments.length, args = new Array(_len3), _key3 = 0;
  30074. _key3 < _len3;
  30075. _key3++
  30076. ) {
  30077. args[_key3] = arguments[_key3];
  30078. }
  30079. return this.forward(args, 'error', '');
  30080. }
  30081. },
  30082. {
  30083. key: 'deprecate',
  30084. value: function deprecate() {
  30085. for (
  30086. var _len4 = arguments.length, args = new Array(_len4), _key4 = 0;
  30087. _key4 < _len4;
  30088. _key4++
  30089. ) {
  30090. args[_key4] = arguments[_key4];
  30091. }
  30092. return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
  30093. }
  30094. },
  30095. {
  30096. key: 'forward',
  30097. value: function forward(args, lvl, prefix, debugOnly) {
  30098. if (debugOnly && !this.debug) return null;
  30099. if (typeof args[0] === 'string')
  30100. args[0] = ''
  30101. .concat(prefix)
  30102. .concat(this.prefix, ' ')
  30103. .concat(args[0]);
  30104. return this.logger[lvl](args);
  30105. }
  30106. },
  30107. {
  30108. key: 'create',
  30109. value: function create(moduleName) {
  30110. return new Logger(
  30111. this.logger,
  30112. _objectSpread(
  30113. {},
  30114. {
  30115. prefix: ''.concat(this.prefix, ':').concat(moduleName, ':')
  30116. },
  30117. this.options
  30118. )
  30119. );
  30120. }
  30121. }
  30122. ]);
  30123. return Logger;
  30124. })();
  30125. var baseLogger = new Logger();
  30126. var EventEmitter =
  30127. /*#__PURE__*/
  30128. (function() {
  30129. function EventEmitter() {
  30130. _classCallCheck(this, EventEmitter);
  30131. this.observers = {};
  30132. }
  30133. _createClass(EventEmitter, [
  30134. {
  30135. key: 'on',
  30136. value: function on(events, listener) {
  30137. var _this = this;
  30138. events.split(' ').forEach(function(event) {
  30139. _this.observers[event] = _this.observers[event] || [];
  30140. _this.observers[event].push(listener);
  30141. });
  30142. return this;
  30143. }
  30144. },
  30145. {
  30146. key: 'off',
  30147. value: function off(event, listener) {
  30148. if (!this.observers[event]) return;
  30149. if (!listener) {
  30150. delete this.observers[event];
  30151. return;
  30152. }
  30153. this.observers[event] = this.observers[event].filter(function(l) {
  30154. return l !== listener;
  30155. });
  30156. }
  30157. },
  30158. {
  30159. key: 'emit',
  30160. value: function emit(event) {
  30161. for (
  30162. var _len = arguments.length,
  30163. args = new Array(_len > 1 ? _len - 1 : 0),
  30164. _key = 1;
  30165. _key < _len;
  30166. _key++
  30167. ) {
  30168. args[_key - 1] = arguments[_key];
  30169. }
  30170. if (this.observers[event]) {
  30171. var cloned = [].concat(this.observers[event]);
  30172. cloned.forEach(function(observer) {
  30173. observer.apply(void 0, args);
  30174. });
  30175. }
  30176. if (this.observers['*']) {
  30177. var _cloned = [].concat(this.observers['*']);
  30178. _cloned.forEach(function(observer) {
  30179. observer.apply(observer, [event].concat(args));
  30180. });
  30181. }
  30182. }
  30183. }
  30184. ]);
  30185. return EventEmitter;
  30186. })();
  30187. // http://lea.verou.me/2016/12/resolve-promises-externally-with-this-one-weird-trick/
  30188. function defer() {
  30189. var res;
  30190. var rej;
  30191. var promise = new Promise(function(resolve, reject) {
  30192. res = resolve;
  30193. rej = reject;
  30194. });
  30195. promise.resolve = res;
  30196. promise.reject = rej;
  30197. return promise;
  30198. }
  30199. function makeString(object) {
  30200. if (object == null) return '';
  30201. /* eslint prefer-template: 0 */
  30202. return '' + object;
  30203. }
  30204. function copy(a, s, t) {
  30205. a.forEach(function(m) {
  30206. if (s[m]) t[m] = s[m];
  30207. });
  30208. }
  30209. function getLastOfPath(object, path, Empty) {
  30210. function cleanKey(key) {
  30211. return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
  30212. }
  30213. function canNotTraverseDeeper() {
  30214. return !object || typeof object === 'string';
  30215. }
  30216. var stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
  30217. while (stack.length > 1) {
  30218. if (canNotTraverseDeeper()) return {};
  30219. var key = cleanKey(stack.shift());
  30220. if (!object[key] && Empty) object[key] = new Empty();
  30221. object = object[key];
  30222. }
  30223. if (canNotTraverseDeeper()) return {};
  30224. return {
  30225. obj: object,
  30226. k: cleanKey(stack.shift())
  30227. };
  30228. }
  30229. function setPath(object, path, newValue) {
  30230. var _getLastOfPath = getLastOfPath(object, path, Object),
  30231. obj = _getLastOfPath.obj,
  30232. k = _getLastOfPath.k;
  30233. obj[k] = newValue;
  30234. }
  30235. function pushPath(object, path, newValue, concat) {
  30236. var _getLastOfPath2 = getLastOfPath(object, path, Object),
  30237. obj = _getLastOfPath2.obj,
  30238. k = _getLastOfPath2.k;
  30239. obj[k] = obj[k] || [];
  30240. if (concat) obj[k] = obj[k].concat(newValue);
  30241. if (!concat) obj[k].push(newValue);
  30242. }
  30243. function getPath(object, path) {
  30244. var _getLastOfPath3 = getLastOfPath(object, path),
  30245. obj = _getLastOfPath3.obj,
  30246. k = _getLastOfPath3.k;
  30247. if (!obj) return undefined;
  30248. return obj[k];
  30249. }
  30250. function getPathWithDefaults(data, defaultData, key) {
  30251. var value = getPath(data, key);
  30252. if (value !== undefined) {
  30253. return value;
  30254. } // Fallback to default values
  30255. return getPath(defaultData, key);
  30256. }
  30257. function deepExtend(target, source, overwrite) {
  30258. /* eslint no-restricted-syntax: 0 */
  30259. for (var prop in source) {
  30260. if (prop in target) {
  30261. // If we reached a leaf string in target or source then replace with source or skip depending on the 'overwrite' switch
  30262. if (
  30263. typeof target[prop] === 'string' ||
  30264. target[prop] instanceof String ||
  30265. typeof source[prop] === 'string' ||
  30266. source[prop] instanceof String
  30267. ) {
  30268. if (overwrite) target[prop] = source[prop];
  30269. } else {
  30270. deepExtend(target[prop], source[prop], overwrite);
  30271. }
  30272. } else {
  30273. target[prop] = source[prop];
  30274. }
  30275. }
  30276. return target;
  30277. }
  30278. function regexEscape(str) {
  30279. /* eslint no-useless-escape: 0 */
  30280. return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
  30281. }
  30282. /* eslint-disable */
  30283. var _entityMap = {
  30284. '&': '&amp;',
  30285. '<': '&lt;',
  30286. '>': '&gt;',
  30287. '"': '&quot;',
  30288. "'": '&#39;',
  30289. '/': '&#x2F;'
  30290. };
  30291. /* eslint-enable */
  30292. function escape(data) {
  30293. if (typeof data === 'string') {
  30294. return data.replace(/[&<>"'\/]/g, function(s) {
  30295. return _entityMap[s];
  30296. });
  30297. }
  30298. return data;
  30299. }
  30300. var ResourceStore =
  30301. /*#__PURE__*/
  30302. (function(_EventEmitter) {
  30303. _inherits(ResourceStore, _EventEmitter);
  30304. function ResourceStore(data) {
  30305. var _this;
  30306. var options =
  30307. arguments.length > 1 && arguments[1] !== undefined
  30308. ? arguments[1]
  30309. : {
  30310. ns: ['translation'],
  30311. defaultNS: 'translation'
  30312. };
  30313. _classCallCheck(this, ResourceStore);
  30314. _this = _possibleConstructorReturn(
  30315. this,
  30316. _getPrototypeOf(ResourceStore).call(this)
  30317. );
  30318. EventEmitter.call(_assertThisInitialized(_this)); // <=IE10 fix (unable to call parent constructor)
  30319. _this.data = data || {};
  30320. _this.options = options;
  30321. if (_this.options.keySeparator === undefined) {
  30322. _this.options.keySeparator = '.';
  30323. }
  30324. return _this;
  30325. }
  30326. _createClass(ResourceStore, [
  30327. {
  30328. key: 'addNamespaces',
  30329. value: function addNamespaces(ns) {
  30330. if (this.options.ns.indexOf(ns) < 0) {
  30331. this.options.ns.push(ns);
  30332. }
  30333. }
  30334. },
  30335. {
  30336. key: 'removeNamespaces',
  30337. value: function removeNamespaces(ns) {
  30338. var index = this.options.ns.indexOf(ns);
  30339. if (index > -1) {
  30340. this.options.ns.splice(index, 1);
  30341. }
  30342. }
  30343. },
  30344. {
  30345. key: 'getResource',
  30346. value: function getResource(lng, ns, key) {
  30347. var options =
  30348. arguments.length > 3 && arguments[3] !== undefined
  30349. ? arguments[3]
  30350. : {};
  30351. var keySeparator =
  30352. options.keySeparator !== undefined
  30353. ? options.keySeparator
  30354. : this.options.keySeparator;
  30355. var path = [lng, ns];
  30356. if (key && typeof key !== 'string') path = path.concat(key);
  30357. if (key && typeof key === 'string')
  30358. path = path.concat(keySeparator ? key.split(keySeparator) : key);
  30359. if (lng.indexOf('.') > -1) {
  30360. path = lng.split('.');
  30361. }
  30362. return getPath(this.data, path);
  30363. }
  30364. },
  30365. {
  30366. key: 'addResource',
  30367. value: function addResource(lng, ns, key, value) {
  30368. var options =
  30369. arguments.length > 4 && arguments[4] !== undefined
  30370. ? arguments[4]
  30371. : {
  30372. silent: false
  30373. };
  30374. var keySeparator = this.options.keySeparator;
  30375. if (keySeparator === undefined) keySeparator = '.';
  30376. var path = [lng, ns];
  30377. if (key)
  30378. path = path.concat(keySeparator ? key.split(keySeparator) : key);
  30379. if (lng.indexOf('.') > -1) {
  30380. path = lng.split('.');
  30381. value = ns;
  30382. ns = path[1];
  30383. }
  30384. this.addNamespaces(ns);
  30385. setPath(this.data, path, value);
  30386. if (!options.silent) this.emit('added', lng, ns, key, value);
  30387. }
  30388. },
  30389. {
  30390. key: 'addResources',
  30391. value: function addResources(lng, ns, resources) {
  30392. var options =
  30393. arguments.length > 3 && arguments[3] !== undefined
  30394. ? arguments[3]
  30395. : {
  30396. silent: false
  30397. };
  30398. /* eslint no-restricted-syntax: 0 */
  30399. for (var m in resources) {
  30400. if (
  30401. typeof resources[m] === 'string' ||
  30402. Object.prototype.toString.apply(resources[m]) === '[object Array]'
  30403. )
  30404. this.addResource(lng, ns, m, resources[m], {
  30405. silent: true
  30406. });
  30407. }
  30408. if (!options.silent) this.emit('added', lng, ns, resources);
  30409. }
  30410. },
  30411. {
  30412. key: 'addResourceBundle',
  30413. value: function addResourceBundle(lng, ns, resources, deep, overwrite) {
  30414. var options =
  30415. arguments.length > 5 && arguments[5] !== undefined
  30416. ? arguments[5]
  30417. : {
  30418. silent: false
  30419. };
  30420. var path = [lng, ns];
  30421. if (lng.indexOf('.') > -1) {
  30422. path = lng.split('.');
  30423. deep = resources;
  30424. resources = ns;
  30425. ns = path[1];
  30426. }
  30427. this.addNamespaces(ns);
  30428. var pack = getPath(this.data, path) || {};
  30429. if (deep) {
  30430. deepExtend(pack, resources, overwrite);
  30431. } else {
  30432. pack = _objectSpread({}, pack, resources);
  30433. }
  30434. setPath(this.data, path, pack);
  30435. if (!options.silent) this.emit('added', lng, ns, resources);
  30436. }
  30437. },
  30438. {
  30439. key: 'removeResourceBundle',
  30440. value: function removeResourceBundle(lng, ns) {
  30441. if (this.hasResourceBundle(lng, ns)) {
  30442. delete this.data[lng][ns];
  30443. }
  30444. this.removeNamespaces(ns);
  30445. this.emit('removed', lng, ns);
  30446. }
  30447. },
  30448. {
  30449. key: 'hasResourceBundle',
  30450. value: function hasResourceBundle(lng, ns) {
  30451. return this.getResource(lng, ns) !== undefined;
  30452. }
  30453. },
  30454. {
  30455. key: 'getResourceBundle',
  30456. value: function getResourceBundle(lng, ns) {
  30457. if (!ns) ns = this.options.defaultNS; // COMPATIBILITY: remove extend in v2.1.0
  30458. if (this.options.compatibilityAPI === 'v1')
  30459. return _objectSpread({}, {}, this.getResource(lng, ns));
  30460. return this.getResource(lng, ns);
  30461. }
  30462. },
  30463. {
  30464. key: 'getDataByLanguage',
  30465. value: function getDataByLanguage(lng) {
  30466. return this.data[lng];
  30467. }
  30468. },
  30469. {
  30470. key: 'toJSON',
  30471. value: function toJSON() {
  30472. return this.data;
  30473. }
  30474. }
  30475. ]);
  30476. return ResourceStore;
  30477. })(EventEmitter);
  30478. var postProcessor = {
  30479. processors: {},
  30480. addPostProcessor: function addPostProcessor(module) {
  30481. this.processors[module.name] = module;
  30482. },
  30483. handle: function handle(processors, value, key, options, translator) {
  30484. var _this = this;
  30485. processors.forEach(function(processor) {
  30486. if (_this.processors[processor])
  30487. value = _this.processors[processor].process(
  30488. value,
  30489. key,
  30490. options,
  30491. translator
  30492. );
  30493. });
  30494. return value;
  30495. }
  30496. };
  30497. var checkedLoadedFor = {};
  30498. var Translator =
  30499. /*#__PURE__*/
  30500. (function(_EventEmitter) {
  30501. _inherits(Translator, _EventEmitter);
  30502. function Translator(services) {
  30503. var _this;
  30504. var options =
  30505. arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  30506. _classCallCheck(this, Translator);
  30507. _this = _possibleConstructorReturn(
  30508. this,
  30509. _getPrototypeOf(Translator).call(this)
  30510. );
  30511. EventEmitter.call(_assertThisInitialized(_this)); // <=IE10 fix (unable to call parent constructor)
  30512. copy(
  30513. [
  30514. 'resourceStore',
  30515. 'languageUtils',
  30516. 'pluralResolver',
  30517. 'interpolator',
  30518. 'backendConnector',
  30519. 'i18nFormat',
  30520. 'utils'
  30521. ],
  30522. services,
  30523. _assertThisInitialized(_this)
  30524. );
  30525. _this.options = options;
  30526. if (_this.options.keySeparator === undefined) {
  30527. _this.options.keySeparator = '.';
  30528. }
  30529. _this.logger = baseLogger.create('translator');
  30530. return _this;
  30531. }
  30532. _createClass(Translator, [
  30533. {
  30534. key: 'changeLanguage',
  30535. value: function changeLanguage(lng) {
  30536. if (lng) this.language = lng;
  30537. }
  30538. },
  30539. {
  30540. key: 'exists',
  30541. value: function exists(key) {
  30542. var options =
  30543. arguments.length > 1 && arguments[1] !== undefined
  30544. ? arguments[1]
  30545. : {
  30546. interpolation: {}
  30547. };
  30548. var resolved = this.resolve(key, options);
  30549. return resolved && resolved.res !== undefined;
  30550. }
  30551. },
  30552. {
  30553. key: 'extractFromKey',
  30554. value: function extractFromKey(key, options) {
  30555. var nsSeparator = options.nsSeparator || this.options.nsSeparator;
  30556. if (nsSeparator === undefined) nsSeparator = ':';
  30557. var keySeparator =
  30558. options.keySeparator !== undefined
  30559. ? options.keySeparator
  30560. : this.options.keySeparator;
  30561. var namespaces = options.ns || this.options.defaultNS;
  30562. if (nsSeparator && key.indexOf(nsSeparator) > -1) {
  30563. var parts = key.split(nsSeparator);
  30564. if (
  30565. nsSeparator !== keySeparator ||
  30566. (nsSeparator === keySeparator &&
  30567. this.options.ns.indexOf(parts[0]) > -1)
  30568. )
  30569. namespaces = parts.shift();
  30570. key = parts.join(keySeparator);
  30571. }
  30572. if (typeof namespaces === 'string') namespaces = [namespaces];
  30573. return {
  30574. key: key,
  30575. namespaces: namespaces
  30576. };
  30577. }
  30578. },
  30579. {
  30580. key: 'translate',
  30581. value: function translate(keys, options) {
  30582. var _this2 = this;
  30583. if (
  30584. _typeof(options) !== 'object' &&
  30585. this.options.overloadTranslationOptionHandler
  30586. ) {
  30587. /* eslint prefer-rest-params: 0 */
  30588. options = this.options.overloadTranslationOptionHandler(arguments);
  30589. }
  30590. if (!options) options = {}; // non valid keys handling
  30591. if (
  30592. keys === undefined ||
  30593. keys === null
  30594. /* || keys === ''*/
  30595. )
  30596. return '';
  30597. if (!Array.isArray(keys)) keys = [String(keys)]; // separators
  30598. var keySeparator =
  30599. options.keySeparator !== undefined
  30600. ? options.keySeparator
  30601. : this.options.keySeparator; // get namespace(s)
  30602. var _this$extractFromKey = this.extractFromKey(
  30603. keys[keys.length - 1],
  30604. options
  30605. ),
  30606. key = _this$extractFromKey.key,
  30607. namespaces = _this$extractFromKey.namespaces;
  30608. var namespace = namespaces[namespaces.length - 1]; // return key on CIMode
  30609. var lng = options.lng || this.language;
  30610. var appendNamespaceToCIMode =
  30611. options.appendNamespaceToCIMode ||
  30612. this.options.appendNamespaceToCIMode;
  30613. if (lng && lng.toLowerCase() === 'cimode') {
  30614. if (appendNamespaceToCIMode) {
  30615. var nsSeparator = options.nsSeparator || this.options.nsSeparator;
  30616. return namespace + nsSeparator + key;
  30617. }
  30618. return key;
  30619. } // resolve from store
  30620. var resolved = this.resolve(keys, options);
  30621. var res = resolved && resolved.res;
  30622. var resUsedKey = (resolved && resolved.usedKey) || key;
  30623. var resExactUsedKey = (resolved && resolved.exactUsedKey) || key;
  30624. var resType = Object.prototype.toString.apply(res);
  30625. var noObject = [
  30626. '[object Number]',
  30627. '[object Function]',
  30628. '[object RegExp]'
  30629. ];
  30630. var joinArrays =
  30631. options.joinArrays !== undefined
  30632. ? options.joinArrays
  30633. : this.options.joinArrays; // object
  30634. var handleAsObjectInI18nFormat =
  30635. !this.i18nFormat || this.i18nFormat.handleAsObject;
  30636. var handleAsObject =
  30637. typeof res !== 'string' &&
  30638. typeof res !== 'boolean' &&
  30639. typeof res !== 'number';
  30640. if (
  30641. handleAsObjectInI18nFormat &&
  30642. res &&
  30643. handleAsObject &&
  30644. noObject.indexOf(resType) < 0 &&
  30645. !(typeof joinArrays === 'string' && resType === '[object Array]')
  30646. ) {
  30647. if (!options.returnObjects && !this.options.returnObjects) {
  30648. this.logger.warn(
  30649. 'accessing an object - but returnObjects options is not enabled!'
  30650. );
  30651. return this.options.returnedObjectHandler
  30652. ? this.options.returnedObjectHandler(resUsedKey, res, options)
  30653. : "key '"
  30654. .concat(key, ' (')
  30655. .concat(
  30656. this.language,
  30657. ")' returned an object instead of string."
  30658. );
  30659. } // if we got a separator we loop over children - else we just return object as is
  30660. // as having it set to false means no hierarchy so no lookup for nested values
  30661. if (keySeparator) {
  30662. var resTypeIsArray = resType === '[object Array]';
  30663. var copy$$1 = resTypeIsArray ? [] : {}; // apply child translation on a copy
  30664. /* eslint no-restricted-syntax: 0 */
  30665. var newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
  30666. for (var m in res) {
  30667. if (Object.prototype.hasOwnProperty.call(res, m)) {
  30668. var deepKey = ''
  30669. .concat(newKeyToUse)
  30670. .concat(keySeparator)
  30671. .concat(m);
  30672. copy$$1[m] = this.translate(
  30673. deepKey,
  30674. _objectSpread({}, options, {
  30675. joinArrays: false,
  30676. ns: namespaces
  30677. })
  30678. );
  30679. if (copy$$1[m] === deepKey) copy$$1[m] = res[m]; // if nothing found use orginal value as fallback
  30680. }
  30681. }
  30682. res = copy$$1;
  30683. }
  30684. } else if (
  30685. handleAsObjectInI18nFormat &&
  30686. typeof joinArrays === 'string' &&
  30687. resType === '[object Array]'
  30688. ) {
  30689. // array special treatment
  30690. res = res.join(joinArrays);
  30691. if (res) res = this.extendTranslation(res, keys, options);
  30692. } else {
  30693. // string, empty or null
  30694. var usedDefault = false;
  30695. var usedKey = false; // fallback value
  30696. if (!this.isValidLookup(res) && options.defaultValue !== undefined) {
  30697. usedDefault = true;
  30698. if (options.count !== undefined) {
  30699. var suffix = this.pluralResolver.getSuffix(lng, options.count);
  30700. res = options['defaultValue'.concat(suffix)];
  30701. }
  30702. if (!res) res = options.defaultValue;
  30703. }
  30704. if (!this.isValidLookup(res)) {
  30705. usedKey = true;
  30706. res = key;
  30707. } // save missing
  30708. var updateMissing =
  30709. options.defaultValue &&
  30710. options.defaultValue !== res &&
  30711. this.options.updateMissing;
  30712. if (usedKey || usedDefault || updateMissing) {
  30713. this.logger.log(
  30714. updateMissing ? 'updateKey' : 'missingKey',
  30715. lng,
  30716. namespace,
  30717. key,
  30718. updateMissing ? options.defaultValue : res
  30719. );
  30720. var lngs = [];
  30721. var fallbackLngs = this.languageUtils.getFallbackCodes(
  30722. this.options.fallbackLng,
  30723. options.lng || this.language
  30724. );
  30725. if (
  30726. this.options.saveMissingTo === 'fallback' &&
  30727. fallbackLngs &&
  30728. fallbackLngs[0]
  30729. ) {
  30730. for (var i = 0; i < fallbackLngs.length; i++) {
  30731. lngs.push(fallbackLngs[i]);
  30732. }
  30733. } else if (this.options.saveMissingTo === 'all') {
  30734. lngs = this.languageUtils.toResolveHierarchy(
  30735. options.lng || this.language
  30736. );
  30737. } else {
  30738. lngs.push(options.lng || this.language);
  30739. }
  30740. var send = function send(l, k) {
  30741. if (_this2.options.missingKeyHandler) {
  30742. _this2.options.missingKeyHandler(
  30743. l,
  30744. namespace,
  30745. k,
  30746. updateMissing ? options.defaultValue : res,
  30747. updateMissing,
  30748. options
  30749. );
  30750. } else if (
  30751. _this2.backendConnector &&
  30752. _this2.backendConnector.saveMissing
  30753. ) {
  30754. _this2.backendConnector.saveMissing(
  30755. l,
  30756. namespace,
  30757. k,
  30758. updateMissing ? options.defaultValue : res,
  30759. updateMissing,
  30760. options
  30761. );
  30762. }
  30763. _this2.emit('missingKey', l, namespace, k, res);
  30764. };
  30765. if (this.options.saveMissing) {
  30766. var needsPluralHandling =
  30767. options.count !== undefined &&
  30768. typeof options.count !== 'string';
  30769. if (this.options.saveMissingPlurals && needsPluralHandling) {
  30770. lngs.forEach(function(l) {
  30771. var plurals = _this2.pluralResolver.getPluralFormsOfKey(
  30772. l,
  30773. key
  30774. );
  30775. plurals.forEach(function(p) {
  30776. return send([l], p);
  30777. });
  30778. });
  30779. } else {
  30780. send(lngs, key);
  30781. }
  30782. }
  30783. } // extend
  30784. res = this.extendTranslation(res, keys, options, resolved); // append namespace if still key
  30785. if (
  30786. usedKey &&
  30787. res === key &&
  30788. this.options.appendNamespaceToMissingKey
  30789. )
  30790. res = ''.concat(namespace, ':').concat(key); // parseMissingKeyHandler
  30791. if (usedKey && this.options.parseMissingKeyHandler)
  30792. res = this.options.parseMissingKeyHandler(res);
  30793. } // return
  30794. return res;
  30795. }
  30796. },
  30797. {
  30798. key: 'extendTranslation',
  30799. value: function extendTranslation(res, key, options, resolved) {
  30800. var _this3 = this;
  30801. if (this.i18nFormat && this.i18nFormat.parse) {
  30802. res = this.i18nFormat.parse(
  30803. res,
  30804. options,
  30805. resolved.usedLng,
  30806. resolved.usedNS,
  30807. resolved.usedKey,
  30808. {
  30809. resolved: resolved
  30810. }
  30811. );
  30812. } else if (!options.skipInterpolation) {
  30813. // i18next.parsing
  30814. if (options.interpolation)
  30815. this.interpolator.init(
  30816. _objectSpread({}, options, {
  30817. interpolation: _objectSpread(
  30818. {},
  30819. this.options.interpolation,
  30820. options.interpolation
  30821. )
  30822. })
  30823. ); // interpolate
  30824. var data =
  30825. options.replace && typeof options.replace !== 'string'
  30826. ? options.replace
  30827. : options;
  30828. if (this.options.interpolation.defaultVariables)
  30829. data = _objectSpread(
  30830. {},
  30831. this.options.interpolation.defaultVariables,
  30832. data
  30833. );
  30834. res = this.interpolator.interpolate(
  30835. res,
  30836. data,
  30837. options.lng || this.language,
  30838. options
  30839. ); // nesting
  30840. if (options.nest !== false)
  30841. res = this.interpolator.nest(
  30842. res,
  30843. function() {
  30844. return _this3.translate.apply(_this3, arguments);
  30845. },
  30846. options
  30847. );
  30848. if (options.interpolation) this.interpolator.reset();
  30849. } // post process
  30850. var postProcess = options.postProcess || this.options.postProcess;
  30851. var postProcessorNames =
  30852. typeof postProcess === 'string' ? [postProcess] : postProcess;
  30853. if (
  30854. res !== undefined &&
  30855. res !== null &&
  30856. postProcessorNames &&
  30857. postProcessorNames.length &&
  30858. options.applyPostProcessor !== false
  30859. ) {
  30860. res = postProcessor.handle(
  30861. postProcessorNames,
  30862. res,
  30863. key,
  30864. this.options && this.options.postProcessPassResolved
  30865. ? _objectSpread(
  30866. {
  30867. i18nResolved: resolved
  30868. },
  30869. options
  30870. )
  30871. : options,
  30872. this
  30873. );
  30874. }
  30875. return res;
  30876. }
  30877. },
  30878. {
  30879. key: 'resolve',
  30880. value: function resolve(keys) {
  30881. var _this4 = this;
  30882. var options =
  30883. arguments.length > 1 && arguments[1] !== undefined
  30884. ? arguments[1]
  30885. : {};
  30886. var found;
  30887. var usedKey; // plain key
  30888. var exactUsedKey; // key with context / plural
  30889. var usedLng;
  30890. var usedNS;
  30891. if (typeof keys === 'string') keys = [keys]; // forEach possible key
  30892. keys.forEach(function(k) {
  30893. if (_this4.isValidLookup(found)) return;
  30894. var extracted = _this4.extractFromKey(k, options);
  30895. var key = extracted.key;
  30896. usedKey = key;
  30897. var namespaces = extracted.namespaces;
  30898. if (_this4.options.fallbackNS)
  30899. namespaces = namespaces.concat(_this4.options.fallbackNS);
  30900. var needsPluralHandling =
  30901. options.count !== undefined && typeof options.count !== 'string';
  30902. var needsContextHandling =
  30903. options.context !== undefined &&
  30904. typeof options.context === 'string' &&
  30905. options.context !== '';
  30906. var codes = options.lngs
  30907. ? options.lngs
  30908. : _this4.languageUtils.toResolveHierarchy(
  30909. options.lng || _this4.language,
  30910. options.fallbackLng
  30911. );
  30912. namespaces.forEach(function(ns) {
  30913. if (_this4.isValidLookup(found)) return;
  30914. usedNS = ns;
  30915. if (
  30916. !checkedLoadedFor[''.concat(codes[0], '-').concat(ns)] &&
  30917. _this4.utils &&
  30918. _this4.utils.hasLoadedNamespace &&
  30919. !_this4.utils.hasLoadedNamespace(usedNS)
  30920. ) {
  30921. checkedLoadedFor[''.concat(codes[0], '-').concat(ns)] = true;
  30922. _this4.logger.warn(
  30923. 'key "'
  30924. .concat(usedKey, '" for namespace "')
  30925. .concat(usedNS, '" for languages "')
  30926. .concat(
  30927. codes.join(', '),
  30928. '" won\'t get resolved as namespace was not yet loaded'
  30929. ),
  30930. 'This means something IS WRONG in your application setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!'
  30931. );
  30932. }
  30933. codes.forEach(function(code) {
  30934. if (_this4.isValidLookup(found)) return;
  30935. usedLng = code;
  30936. var finalKey = key;
  30937. var finalKeys = [finalKey];
  30938. if (_this4.i18nFormat && _this4.i18nFormat.addLookupKeys) {
  30939. _this4.i18nFormat.addLookupKeys(
  30940. finalKeys,
  30941. key,
  30942. code,
  30943. ns,
  30944. options
  30945. );
  30946. } else {
  30947. var pluralSuffix;
  30948. if (needsPluralHandling)
  30949. pluralSuffix = _this4.pluralResolver.getSuffix(
  30950. code,
  30951. options.count
  30952. ); // fallback for plural if context not found
  30953. if (needsPluralHandling && needsContextHandling)
  30954. finalKeys.push(finalKey + pluralSuffix); // get key for context if needed
  30955. if (needsContextHandling)
  30956. finalKeys.push(
  30957. (finalKey += ''
  30958. .concat(_this4.options.contextSeparator)
  30959. .concat(options.context))
  30960. ); // get key for plural if needed
  30961. if (needsPluralHandling)
  30962. finalKeys.push((finalKey += pluralSuffix));
  30963. } // iterate over finalKeys starting with most specific pluralkey (-> contextkey only) -> singularkey only
  30964. var possibleKey;
  30965. /* eslint no-cond-assign: 0 */
  30966. while ((possibleKey = finalKeys.pop())) {
  30967. if (!_this4.isValidLookup(found)) {
  30968. exactUsedKey = possibleKey;
  30969. found = _this4.getResource(code, ns, possibleKey, options);
  30970. }
  30971. }
  30972. });
  30973. });
  30974. });
  30975. return {
  30976. res: found,
  30977. usedKey: usedKey,
  30978. exactUsedKey: exactUsedKey,
  30979. usedLng: usedLng,
  30980. usedNS: usedNS
  30981. };
  30982. }
  30983. },
  30984. {
  30985. key: 'isValidLookup',
  30986. value: function isValidLookup(res) {
  30987. return (
  30988. res !== undefined &&
  30989. !(!this.options.returnNull && res === null) &&
  30990. !(!this.options.returnEmptyString && res === '')
  30991. );
  30992. }
  30993. },
  30994. {
  30995. key: 'getResource',
  30996. value: function getResource(code, ns, key) {
  30997. var options =
  30998. arguments.length > 3 && arguments[3] !== undefined
  30999. ? arguments[3]
  31000. : {};
  31001. if (this.i18nFormat && this.i18nFormat.getResource)
  31002. return this.i18nFormat.getResource(code, ns, key, options);
  31003. return this.resourceStore.getResource(code, ns, key, options);
  31004. }
  31005. }
  31006. ]);
  31007. return Translator;
  31008. })(EventEmitter);
  31009. function capitalize(string) {
  31010. return string.charAt(0).toUpperCase() + string.slice(1);
  31011. }
  31012. var LanguageUtil =
  31013. /*#__PURE__*/
  31014. (function() {
  31015. function LanguageUtil(options) {
  31016. _classCallCheck(this, LanguageUtil);
  31017. this.options = options;
  31018. this.whitelist = this.options.whitelist || false;
  31019. this.logger = baseLogger.create('languageUtils');
  31020. }
  31021. _createClass(LanguageUtil, [
  31022. {
  31023. key: 'getScriptPartFromCode',
  31024. value: function getScriptPartFromCode(code) {
  31025. if (!code || code.indexOf('-') < 0) return null;
  31026. var p = code.split('-');
  31027. if (p.length === 2) return null;
  31028. p.pop();
  31029. return this.formatLanguageCode(p.join('-'));
  31030. }
  31031. },
  31032. {
  31033. key: 'getLanguagePartFromCode',
  31034. value: function getLanguagePartFromCode(code) {
  31035. if (!code || code.indexOf('-') < 0) return code;
  31036. var p = code.split('-');
  31037. return this.formatLanguageCode(p[0]);
  31038. }
  31039. },
  31040. {
  31041. key: 'formatLanguageCode',
  31042. value: function formatLanguageCode(code) {
  31043. // http://www.iana.org/assignments/language-tags/language-tags.xhtml
  31044. if (typeof code === 'string' && code.indexOf('-') > -1) {
  31045. var specialCases = [
  31046. 'hans',
  31047. 'hant',
  31048. 'latn',
  31049. 'cyrl',
  31050. 'cans',
  31051. 'mong',
  31052. 'arab'
  31053. ];
  31054. var p = code.split('-');
  31055. if (this.options.lowerCaseLng) {
  31056. p = p.map(function(part) {
  31057. return part.toLowerCase();
  31058. });
  31059. } else if (p.length === 2) {
  31060. p[0] = p[0].toLowerCase();
  31061. p[1] = p[1].toUpperCase();
  31062. if (specialCases.indexOf(p[1].toLowerCase()) > -1)
  31063. p[1] = capitalize(p[1].toLowerCase());
  31064. } else if (p.length === 3) {
  31065. p[0] = p[0].toLowerCase(); // if lenght 2 guess it's a country
  31066. if (p[1].length === 2) p[1] = p[1].toUpperCase();
  31067. if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
  31068. if (specialCases.indexOf(p[1].toLowerCase()) > -1)
  31069. p[1] = capitalize(p[1].toLowerCase());
  31070. if (specialCases.indexOf(p[2].toLowerCase()) > -1)
  31071. p[2] = capitalize(p[2].toLowerCase());
  31072. }
  31073. return p.join('-');
  31074. }
  31075. return this.options.cleanCode || this.options.lowerCaseLng
  31076. ? code.toLowerCase()
  31077. : code;
  31078. }
  31079. },
  31080. {
  31081. key: 'isWhitelisted',
  31082. value: function isWhitelisted(code) {
  31083. if (
  31084. this.options.load === 'languageOnly' ||
  31085. this.options.nonExplicitWhitelist
  31086. ) {
  31087. code = this.getLanguagePartFromCode(code);
  31088. }
  31089. return (
  31090. !this.whitelist ||
  31091. !this.whitelist.length ||
  31092. this.whitelist.indexOf(code) > -1
  31093. );
  31094. }
  31095. },
  31096. {
  31097. key: 'getFallbackCodes',
  31098. value: function getFallbackCodes(fallbacks, code) {
  31099. if (!fallbacks) return [];
  31100. if (typeof fallbacks === 'string') fallbacks = [fallbacks];
  31101. if (Object.prototype.toString.apply(fallbacks) === '[object Array]')
  31102. return fallbacks;
  31103. if (!code) return fallbacks['default'] || []; // asume we have an object defining fallbacks
  31104. var found = fallbacks[code];
  31105. if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
  31106. if (!found) found = fallbacks[this.formatLanguageCode(code)];
  31107. if (!found) found = fallbacks['default'];
  31108. return found || [];
  31109. }
  31110. },
  31111. {
  31112. key: 'toResolveHierarchy',
  31113. value: function toResolveHierarchy(code, fallbackCode) {
  31114. var _this = this;
  31115. var fallbackCodes = this.getFallbackCodes(
  31116. fallbackCode || this.options.fallbackLng || [],
  31117. code
  31118. );
  31119. var codes = [];
  31120. var addCode = function addCode(c) {
  31121. if (!c) return;
  31122. if (_this.isWhitelisted(c)) {
  31123. codes.push(c);
  31124. } else {
  31125. _this.logger.warn(
  31126. 'rejecting non-whitelisted language code: '.concat(c)
  31127. );
  31128. }
  31129. };
  31130. if (typeof code === 'string' && code.indexOf('-') > -1) {
  31131. if (this.options.load !== 'languageOnly')
  31132. addCode(this.formatLanguageCode(code));
  31133. if (
  31134. this.options.load !== 'languageOnly' &&
  31135. this.options.load !== 'currentOnly'
  31136. )
  31137. addCode(this.getScriptPartFromCode(code));
  31138. if (this.options.load !== 'currentOnly')
  31139. addCode(this.getLanguagePartFromCode(code));
  31140. } else if (typeof code === 'string') {
  31141. addCode(this.formatLanguageCode(code));
  31142. }
  31143. fallbackCodes.forEach(function(fc) {
  31144. if (codes.indexOf(fc) < 0) addCode(_this.formatLanguageCode(fc));
  31145. });
  31146. return codes;
  31147. }
  31148. }
  31149. ]);
  31150. return LanguageUtil;
  31151. })();
  31152. /* eslint-disable */
  31153. var sets = [
  31154. {
  31155. lngs: [
  31156. 'ach',
  31157. 'ak',
  31158. 'am',
  31159. 'arn',
  31160. 'br',
  31161. 'fil',
  31162. 'gun',
  31163. 'ln',
  31164. 'mfe',
  31165. 'mg',
  31166. 'mi',
  31167. 'oc',
  31168. 'pt',
  31169. 'pt-BR',
  31170. 'tg',
  31171. 'ti',
  31172. 'tr',
  31173. 'uz',
  31174. 'wa'
  31175. ],
  31176. nr: [1, 2],
  31177. fc: 1
  31178. },
  31179. {
  31180. lngs: [
  31181. 'af',
  31182. 'an',
  31183. 'ast',
  31184. 'az',
  31185. 'bg',
  31186. 'bn',
  31187. 'ca',
  31188. 'da',
  31189. 'de',
  31190. 'dev',
  31191. 'el',
  31192. 'en',
  31193. 'eo',
  31194. 'es',
  31195. 'et',
  31196. 'eu',
  31197. 'fi',
  31198. 'fo',
  31199. 'fur',
  31200. 'fy',
  31201. 'gl',
  31202. 'gu',
  31203. 'ha',
  31204. 'hi',
  31205. 'hu',
  31206. 'hy',
  31207. 'ia',
  31208. 'it',
  31209. 'kn',
  31210. 'ku',
  31211. 'lb',
  31212. 'mai',
  31213. 'ml',
  31214. 'mn',
  31215. 'mr',
  31216. 'nah',
  31217. 'nap',
  31218. 'nb',
  31219. 'ne',
  31220. 'nl',
  31221. 'nn',
  31222. 'no',
  31223. 'nso',
  31224. 'pa',
  31225. 'pap',
  31226. 'pms',
  31227. 'ps',
  31228. 'pt-PT',
  31229. 'rm',
  31230. 'sco',
  31231. 'se',
  31232. 'si',
  31233. 'so',
  31234. 'son',
  31235. 'sq',
  31236. 'sv',
  31237. 'sw',
  31238. 'ta',
  31239. 'te',
  31240. 'tk',
  31241. 'ur',
  31242. 'yo'
  31243. ],
  31244. nr: [1, 2],
  31245. fc: 2
  31246. },
  31247. {
  31248. lngs: [
  31249. 'ay',
  31250. 'bo',
  31251. 'cgg',
  31252. 'fa',
  31253. 'id',
  31254. 'ja',
  31255. 'jbo',
  31256. 'ka',
  31257. 'kk',
  31258. 'km',
  31259. 'ko',
  31260. 'ky',
  31261. 'lo',
  31262. 'ms',
  31263. 'sah',
  31264. 'su',
  31265. 'th',
  31266. 'tt',
  31267. 'ug',
  31268. 'vi',
  31269. 'wo',
  31270. 'zh'
  31271. ],
  31272. nr: [1],
  31273. fc: 3
  31274. },
  31275. {
  31276. lngs: ['be', 'bs', 'cnr', 'dz', 'hr', 'ru', 'sr', 'uk'],
  31277. nr: [1, 2, 5],
  31278. fc: 4
  31279. },
  31280. {
  31281. lngs: ['ar'],
  31282. nr: [0, 1, 2, 3, 11, 100],
  31283. fc: 5
  31284. },
  31285. {
  31286. lngs: ['cs', 'sk'],
  31287. nr: [1, 2, 5],
  31288. fc: 6
  31289. },
  31290. {
  31291. lngs: ['csb', 'pl'],
  31292. nr: [1, 2, 5],
  31293. fc: 7
  31294. },
  31295. {
  31296. lngs: ['cy'],
  31297. nr: [1, 2, 3, 8],
  31298. fc: 8
  31299. },
  31300. {
  31301. lngs: ['fr'],
  31302. nr: [1, 2],
  31303. fc: 9
  31304. },
  31305. {
  31306. lngs: ['ga'],
  31307. nr: [1, 2, 3, 7, 11],
  31308. fc: 10
  31309. },
  31310. {
  31311. lngs: ['gd'],
  31312. nr: [1, 2, 3, 20],
  31313. fc: 11
  31314. },
  31315. {
  31316. lngs: ['is'],
  31317. nr: [1, 2],
  31318. fc: 12
  31319. },
  31320. {
  31321. lngs: ['jv'],
  31322. nr: [0, 1],
  31323. fc: 13
  31324. },
  31325. {
  31326. lngs: ['kw'],
  31327. nr: [1, 2, 3, 4],
  31328. fc: 14
  31329. },
  31330. {
  31331. lngs: ['lt'],
  31332. nr: [1, 2, 10],
  31333. fc: 15
  31334. },
  31335. {
  31336. lngs: ['lv'],
  31337. nr: [1, 2, 0],
  31338. fc: 16
  31339. },
  31340. {
  31341. lngs: ['mk'],
  31342. nr: [1, 2],
  31343. fc: 17
  31344. },
  31345. {
  31346. lngs: ['mnk'],
  31347. nr: [0, 1, 2],
  31348. fc: 18
  31349. },
  31350. {
  31351. lngs: ['mt'],
  31352. nr: [1, 2, 11, 20],
  31353. fc: 19
  31354. },
  31355. {
  31356. lngs: ['or'],
  31357. nr: [2, 1],
  31358. fc: 2
  31359. },
  31360. {
  31361. lngs: ['ro'],
  31362. nr: [1, 2, 20],
  31363. fc: 20
  31364. },
  31365. {
  31366. lngs: ['sl'],
  31367. nr: [5, 1, 2, 3],
  31368. fc: 21
  31369. },
  31370. {
  31371. lngs: ['he'],
  31372. nr: [1, 2, 20, 21],
  31373. fc: 22
  31374. }
  31375. ];
  31376. var _rulesPluralsTypes = {
  31377. 1: function _(n) {
  31378. return Number(n > 1);
  31379. },
  31380. 2: function _(n) {
  31381. return Number(n != 1);
  31382. },
  31383. 3: function _(n) {
  31384. return 0;
  31385. },
  31386. 4: function _(n) {
  31387. return Number(
  31388. n % 10 == 1 && n % 100 != 11
  31389. ? 0
  31390. : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2
  31391. );
  31392. },
  31393. 5: function _(n) {
  31394. return Number(
  31395. n === 0
  31396. ? 0
  31397. : n == 1
  31398. ? 1
  31399. : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5
  31400. );
  31401. },
  31402. 6: function _(n) {
  31403. return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
  31404. },
  31405. 7: function _(n) {
  31406. return Number(
  31407. n == 1
  31408. ? 0
  31409. : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2
  31410. );
  31411. },
  31412. 8: function _(n) {
  31413. return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
  31414. },
  31415. 9: function _(n) {
  31416. return Number(n >= 2);
  31417. },
  31418. 10: function _(n) {
  31419. return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
  31420. },
  31421. 11: function _(n) {
  31422. return Number(
  31423. n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3
  31424. );
  31425. },
  31426. 12: function _(n) {
  31427. return Number(n % 10 != 1 || n % 100 == 11);
  31428. },
  31429. 13: function _(n) {
  31430. return Number(n !== 0);
  31431. },
  31432. 14: function _(n) {
  31433. return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
  31434. },
  31435. 15: function _(n) {
  31436. return Number(
  31437. n % 10 == 1 && n % 100 != 11
  31438. ? 0
  31439. : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2
  31440. );
  31441. },
  31442. 16: function _(n) {
  31443. return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
  31444. },
  31445. 17: function _(n) {
  31446. return Number(n == 1 || n % 10 == 1 ? 0 : 1);
  31447. },
  31448. 18: function _(n) {
  31449. return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
  31450. },
  31451. 19: function _(n) {
  31452. return Number(
  31453. n == 1
  31454. ? 0
  31455. : n === 0 || (n % 100 > 1 && n % 100 < 11)
  31456. ? 1
  31457. : n % 100 > 10 && n % 100 < 20 ? 2 : 3
  31458. );
  31459. },
  31460. 20: function _(n) {
  31461. return Number(n == 1 ? 0 : n === 0 || (n % 100 > 0 && n % 100 < 20) ? 1 : 2);
  31462. },
  31463. 21: function _(n) {
  31464. return Number(
  31465. n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0
  31466. );
  31467. },
  31468. 22: function _(n) {
  31469. return Number(
  31470. n === 1 ? 0 : n === 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3
  31471. );
  31472. }
  31473. };
  31474. /* eslint-enable */
  31475. function createRules() {
  31476. var rules = {};
  31477. sets.forEach(function(set) {
  31478. set.lngs.forEach(function(l) {
  31479. rules[l] = {
  31480. numbers: set.nr,
  31481. plurals: _rulesPluralsTypes[set.fc]
  31482. };
  31483. });
  31484. });
  31485. return rules;
  31486. }
  31487. var PluralResolver =
  31488. /*#__PURE__*/
  31489. (function() {
  31490. function PluralResolver(languageUtils) {
  31491. var options =
  31492. arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  31493. _classCallCheck(this, PluralResolver);
  31494. this.languageUtils = languageUtils;
  31495. this.options = options;
  31496. this.logger = baseLogger.create('pluralResolver');
  31497. this.rules = createRules();
  31498. }
  31499. _createClass(PluralResolver, [
  31500. {
  31501. key: 'addRule',
  31502. value: function addRule(lng, obj) {
  31503. this.rules[lng] = obj;
  31504. }
  31505. },
  31506. {
  31507. key: 'getRule',
  31508. value: function getRule(code) {
  31509. return (
  31510. this.rules[code] ||
  31511. this.rules[this.languageUtils.getLanguagePartFromCode(code)]
  31512. );
  31513. }
  31514. },
  31515. {
  31516. key: 'needsPlural',
  31517. value: function needsPlural(code) {
  31518. var rule = this.getRule(code);
  31519. return rule && rule.numbers.length > 1;
  31520. }
  31521. },
  31522. {
  31523. key: 'getPluralFormsOfKey',
  31524. value: function getPluralFormsOfKey(code, key) {
  31525. var _this = this;
  31526. var ret = [];
  31527. var rule = this.getRule(code);
  31528. if (!rule) return ret;
  31529. rule.numbers.forEach(function(n) {
  31530. var suffix = _this.getSuffix(code, n);
  31531. ret.push(''.concat(key).concat(suffix));
  31532. });
  31533. return ret;
  31534. }
  31535. },
  31536. {
  31537. key: 'getSuffix',
  31538. value: function getSuffix(code, count) {
  31539. var _this2 = this;
  31540. var rule = this.getRule(code);
  31541. if (rule) {
  31542. // if (rule.numbers.length === 1) return ''; // only singular
  31543. var idx = rule.noAbs
  31544. ? rule.plurals(count)
  31545. : rule.plurals(Math.abs(count));
  31546. var suffix = rule.numbers[idx]; // special treatment for lngs only having singular and plural
  31547. if (
  31548. this.options.simplifyPluralSuffix &&
  31549. rule.numbers.length === 2 &&
  31550. rule.numbers[0] === 1
  31551. ) {
  31552. if (suffix === 2) {
  31553. suffix = 'plural';
  31554. } else if (suffix === 1) {
  31555. suffix = '';
  31556. }
  31557. }
  31558. var returnSuffix = function returnSuffix() {
  31559. return _this2.options.prepend && suffix.toString()
  31560. ? _this2.options.prepend + suffix.toString()
  31561. : suffix.toString();
  31562. }; // COMPATIBILITY JSON
  31563. // v1
  31564. if (this.options.compatibilityJSON === 'v1') {
  31565. if (suffix === 1) return '';
  31566. if (typeof suffix === 'number')
  31567. return '_plural_'.concat(suffix.toString());
  31568. return returnSuffix();
  31569. } else if (
  31570. /* v2 */
  31571. this.options.compatibilityJSON === 'v2'
  31572. ) {
  31573. return returnSuffix();
  31574. } else if (
  31575. /* v3 - gettext index */
  31576. this.options.simplifyPluralSuffix &&
  31577. rule.numbers.length === 2 &&
  31578. rule.numbers[0] === 1
  31579. ) {
  31580. return returnSuffix();
  31581. }
  31582. return this.options.prepend && idx.toString()
  31583. ? this.options.prepend + idx.toString()
  31584. : idx.toString();
  31585. }
  31586. this.logger.warn('no plural rule found for: '.concat(code));
  31587. return '';
  31588. }
  31589. }
  31590. ]);
  31591. return PluralResolver;
  31592. })();
  31593. var Interpolator =
  31594. /*#__PURE__*/
  31595. (function() {
  31596. function Interpolator() {
  31597. var options =
  31598. arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  31599. _classCallCheck(this, Interpolator);
  31600. this.logger = baseLogger.create('interpolator');
  31601. this.options = options;
  31602. this.format =
  31603. (options.interpolation && options.interpolation.format) ||
  31604. function(value) {
  31605. return value;
  31606. };
  31607. this.init(options);
  31608. }
  31609. /* eslint no-param-reassign: 0 */
  31610. _createClass(Interpolator, [
  31611. {
  31612. key: 'init',
  31613. value: function init() {
  31614. var options =
  31615. arguments.length > 0 && arguments[0] !== undefined
  31616. ? arguments[0]
  31617. : {};
  31618. if (!options.interpolation)
  31619. options.interpolation = {
  31620. escapeValue: true
  31621. };
  31622. var iOpts = options.interpolation;
  31623. this.escape = iOpts.escape !== undefined ? iOpts.escape : escape;
  31624. this.escapeValue =
  31625. iOpts.escapeValue !== undefined ? iOpts.escapeValue : true;
  31626. this.useRawValueToEscape =
  31627. iOpts.useRawValueToEscape !== undefined
  31628. ? iOpts.useRawValueToEscape
  31629. : false;
  31630. this.prefix = iOpts.prefix
  31631. ? regexEscape(iOpts.prefix)
  31632. : iOpts.prefixEscaped || '{{';
  31633. this.suffix = iOpts.suffix
  31634. ? regexEscape(iOpts.suffix)
  31635. : iOpts.suffixEscaped || '}}';
  31636. this.formatSeparator = iOpts.formatSeparator
  31637. ? iOpts.formatSeparator
  31638. : iOpts.formatSeparator || ',';
  31639. this.unescapePrefix = iOpts.unescapeSuffix
  31640. ? ''
  31641. : iOpts.unescapePrefix || '-';
  31642. this.unescapeSuffix = this.unescapePrefix
  31643. ? ''
  31644. : iOpts.unescapeSuffix || '';
  31645. this.nestingPrefix = iOpts.nestingPrefix
  31646. ? regexEscape(iOpts.nestingPrefix)
  31647. : iOpts.nestingPrefixEscaped || regexEscape('$t(');
  31648. this.nestingSuffix = iOpts.nestingSuffix
  31649. ? regexEscape(iOpts.nestingSuffix)
  31650. : iOpts.nestingSuffixEscaped || regexEscape(')');
  31651. this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1000; // the regexp
  31652. this.resetRegExp();
  31653. }
  31654. },
  31655. {
  31656. key: 'reset',
  31657. value: function reset() {
  31658. if (this.options) this.init(this.options);
  31659. }
  31660. },
  31661. {
  31662. key: 'resetRegExp',
  31663. value: function resetRegExp() {
  31664. // the regexp
  31665. var regexpStr = ''.concat(this.prefix, '(.+?)').concat(this.suffix);
  31666. this.regexp = new RegExp(regexpStr, 'g');
  31667. var regexpUnescapeStr = ''
  31668. .concat(this.prefix)
  31669. .concat(this.unescapePrefix, '(.+?)')
  31670. .concat(this.unescapeSuffix)
  31671. .concat(this.suffix);
  31672. this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g');
  31673. var nestingRegexpStr = ''
  31674. .concat(this.nestingPrefix, '(.+?)')
  31675. .concat(this.nestingSuffix);
  31676. this.nestingRegexp = new RegExp(nestingRegexpStr, 'g');
  31677. }
  31678. },
  31679. {
  31680. key: 'interpolate',
  31681. value: function interpolate(str, data, lng, options) {
  31682. var _this = this;
  31683. var match;
  31684. var value;
  31685. var replaces;
  31686. var defaultData =
  31687. (this.options &&
  31688. this.options.interpolation &&
  31689. this.options.interpolation.defaultVariables) ||
  31690. {};
  31691. function regexSafe(val) {
  31692. return val.replace(/\$/g, '$$$$');
  31693. }
  31694. var handleFormat = function handleFormat(key) {
  31695. if (key.indexOf(_this.formatSeparator) < 0) {
  31696. return getPathWithDefaults(data, defaultData, key);
  31697. }
  31698. var p = key.split(_this.formatSeparator);
  31699. var k = p.shift().trim();
  31700. var f = p.join(_this.formatSeparator).trim();
  31701. return _this.format(
  31702. getPathWithDefaults(data, defaultData, k),
  31703. f,
  31704. lng
  31705. );
  31706. };
  31707. this.resetRegExp();
  31708. var missingInterpolationHandler =
  31709. (options && options.missingInterpolationHandler) ||
  31710. this.options.missingInterpolationHandler;
  31711. replaces = 0; // unescape if has unescapePrefix/Suffix
  31712. /* eslint no-cond-assign: 0 */
  31713. while ((match = this.regexpUnescape.exec(str))) {
  31714. value = handleFormat(match[1].trim());
  31715. if (value === undefined) {
  31716. if (typeof missingInterpolationHandler === 'function') {
  31717. var temp = missingInterpolationHandler(str, match, options);
  31718. value = typeof temp === 'string' ? temp : '';
  31719. } else {
  31720. this.logger.warn(
  31721. 'missed to pass in variable '
  31722. .concat(match[1], ' for interpolating ')
  31723. .concat(str)
  31724. );
  31725. value = '';
  31726. }
  31727. } else if (typeof value !== 'string' && !this.useRawValueToEscape) {
  31728. value = makeString(value);
  31729. }
  31730. str = str.replace(match[0], regexSafe(value));
  31731. this.regexpUnescape.lastIndex = 0;
  31732. replaces++;
  31733. if (replaces >= this.maxReplaces) {
  31734. break;
  31735. }
  31736. }
  31737. replaces = 0; // regular escape on demand
  31738. while ((match = this.regexp.exec(str))) {
  31739. value = handleFormat(match[1].trim());
  31740. if (value === undefined) {
  31741. if (typeof missingInterpolationHandler === 'function') {
  31742. var _temp = missingInterpolationHandler(str, match, options);
  31743. value = typeof _temp === 'string' ? _temp : '';
  31744. } else {
  31745. this.logger.warn(
  31746. 'missed to pass in variable '
  31747. .concat(match[1], ' for interpolating ')
  31748. .concat(str)
  31749. );
  31750. value = '';
  31751. }
  31752. } else if (typeof value !== 'string' && !this.useRawValueToEscape) {
  31753. value = makeString(value);
  31754. }
  31755. value = this.escapeValue
  31756. ? regexSafe(this.escape(value))
  31757. : regexSafe(value);
  31758. str = str.replace(match[0], value);
  31759. this.regexp.lastIndex = 0;
  31760. replaces++;
  31761. if (replaces >= this.maxReplaces) {
  31762. break;
  31763. }
  31764. }
  31765. return str;
  31766. }
  31767. },
  31768. {
  31769. key: 'nest',
  31770. value: function nest(str, fc) {
  31771. var options =
  31772. arguments.length > 2 && arguments[2] !== undefined
  31773. ? arguments[2]
  31774. : {};
  31775. var match;
  31776. var value;
  31777. var clonedOptions = _objectSpread({}, options);
  31778. clonedOptions.applyPostProcessor = false; // avoid post processing on nested lookup
  31779. delete clonedOptions.defaultValue; // assert we do not get a endless loop on interpolating defaultValue again and again
  31780. // if value is something like "myKey": "lorem $(anotherKey, { "count": {{aValueInOptions}} })"
  31781. function handleHasOptions(key, inheritedOptions) {
  31782. if (key.indexOf(',') < 0) return key;
  31783. var p = key.split(',');
  31784. key = p.shift();
  31785. var optionsString = p.join(',');
  31786. optionsString = this.interpolate(optionsString, clonedOptions);
  31787. optionsString = optionsString.replace(/'/g, '"');
  31788. try {
  31789. clonedOptions = JSON.parse(optionsString);
  31790. if (inheritedOptions)
  31791. clonedOptions = _objectSpread(
  31792. {},
  31793. inheritedOptions,
  31794. clonedOptions
  31795. );
  31796. } catch (e) {
  31797. this.logger.error(
  31798. 'failed parsing options string in nesting for key '.concat(key),
  31799. e
  31800. );
  31801. } // assert we do not get a endless loop on interpolating defaultValue again and again
  31802. delete clonedOptions.defaultValue;
  31803. return key;
  31804. } // regular escape on demand
  31805. while ((match = this.nestingRegexp.exec(str))) {
  31806. value = fc(
  31807. handleHasOptions.call(this, match[1].trim(), clonedOptions),
  31808. clonedOptions
  31809. ); // is only the nesting key (key1 = '$(key2)') return the value without stringify
  31810. if (value && match[0] === str && typeof value !== 'string')
  31811. return value; // no string to include or empty
  31812. if (typeof value !== 'string') value = makeString(value);
  31813. if (!value) {
  31814. this.logger.warn(
  31815. 'missed to resolve '.concat(match[1], ' for nesting ').concat(str)
  31816. );
  31817. value = '';
  31818. } // Nested keys should not be escaped by default #854
  31819. // value = this.escapeValue ? regexSafe(utils.escape(value)) : regexSafe(value);
  31820. str = str.replace(match[0], value);
  31821. this.regexp.lastIndex = 0;
  31822. }
  31823. return str;
  31824. }
  31825. }
  31826. ]);
  31827. return Interpolator;
  31828. })();
  31829. function remove(arr, what) {
  31830. var found = arr.indexOf(what);
  31831. while (found !== -1) {
  31832. arr.splice(found, 1);
  31833. found = arr.indexOf(what);
  31834. }
  31835. }
  31836. var Connector =
  31837. /*#__PURE__*/
  31838. (function(_EventEmitter) {
  31839. _inherits(Connector, _EventEmitter);
  31840. function Connector(backend, store, services) {
  31841. var _this;
  31842. var options =
  31843. arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  31844. _classCallCheck(this, Connector);
  31845. _this = _possibleConstructorReturn(
  31846. this,
  31847. _getPrototypeOf(Connector).call(this)
  31848. );
  31849. EventEmitter.call(_assertThisInitialized(_this)); // <=IE10 fix (unable to call parent constructor)
  31850. _this.backend = backend;
  31851. _this.store = store;
  31852. _this.services = services;
  31853. _this.languageUtils = services.languageUtils;
  31854. _this.options = options;
  31855. _this.logger = baseLogger.create('backendConnector');
  31856. _this.state = {};
  31857. _this.queue = [];
  31858. if (_this.backend && _this.backend.init) {
  31859. _this.backend.init(services, options.backend, options);
  31860. }
  31861. return _this;
  31862. }
  31863. _createClass(Connector, [
  31864. {
  31865. key: 'queueLoad',
  31866. value: function queueLoad(languages, namespaces, options, callback) {
  31867. var _this2 = this;
  31868. // find what needs to be loaded
  31869. var toLoad = [];
  31870. var pending = [];
  31871. var toLoadLanguages = [];
  31872. var toLoadNamespaces = [];
  31873. languages.forEach(function(lng) {
  31874. var hasAllNamespaces = true;
  31875. namespaces.forEach(function(ns) {
  31876. var name = ''.concat(lng, '|').concat(ns);
  31877. if (!options.reload && _this2.store.hasResourceBundle(lng, ns)) {
  31878. _this2.state[name] = 2; // loaded
  31879. } else if (_this2.state[name] < 0);
  31880. else if (_this2.state[name] === 1) {
  31881. if (pending.indexOf(name) < 0) pending.push(name);
  31882. } else {
  31883. _this2.state[name] = 1; // pending
  31884. hasAllNamespaces = false;
  31885. if (pending.indexOf(name) < 0) pending.push(name);
  31886. if (toLoad.indexOf(name) < 0) toLoad.push(name);
  31887. if (toLoadNamespaces.indexOf(ns) < 0) toLoadNamespaces.push(ns);
  31888. }
  31889. });
  31890. if (!hasAllNamespaces) toLoadLanguages.push(lng);
  31891. });
  31892. if (toLoad.length || pending.length) {
  31893. this.queue.push({
  31894. pending: pending,
  31895. loaded: {},
  31896. errors: [],
  31897. callback: callback
  31898. });
  31899. }
  31900. return {
  31901. toLoad: toLoad,
  31902. pending: pending,
  31903. toLoadLanguages: toLoadLanguages,
  31904. toLoadNamespaces: toLoadNamespaces
  31905. };
  31906. }
  31907. },
  31908. {
  31909. key: 'loaded',
  31910. value: function loaded(name, err, data) {
  31911. var _name$split = name.split('|'),
  31912. _name$split2 = _slicedToArray(_name$split, 2),
  31913. lng = _name$split2[0],
  31914. ns = _name$split2[1];
  31915. if (err) this.emit('failedLoading', lng, ns, err);
  31916. if (data) {
  31917. this.store.addResourceBundle(lng, ns, data);
  31918. } // set loaded
  31919. this.state[name] = err ? -1 : 2; // consolidated loading done in this run - only emit once for a loaded namespace
  31920. var loaded = {}; // callback if ready
  31921. this.queue.forEach(function(q) {
  31922. pushPath(q.loaded, [lng], ns);
  31923. remove(q.pending, name);
  31924. if (err) q.errors.push(err);
  31925. if (q.pending.length === 0 && !q.done) {
  31926. // only do once per loaded -> this.emit('loaded', q.loaded);
  31927. Object.keys(q.loaded).forEach(function(l) {
  31928. if (!loaded[l]) loaded[l] = [];
  31929. if (q.loaded[l].length) {
  31930. q.loaded[l].forEach(function(ns) {
  31931. if (loaded[l].indexOf(ns) < 0) loaded[l].push(ns);
  31932. });
  31933. }
  31934. });
  31935. /* eslint no-param-reassign: 0 */
  31936. q.done = true;
  31937. if (q.errors.length) {
  31938. q.callback(q.errors);
  31939. } else {
  31940. q.callback();
  31941. }
  31942. }
  31943. }); // emit consolidated loaded event
  31944. this.emit('loaded', loaded); // remove done load requests
  31945. this.queue = this.queue.filter(function(q) {
  31946. return !q.done;
  31947. });
  31948. }
  31949. },
  31950. {
  31951. key: 'read',
  31952. value: function read(lng, ns, fcName) {
  31953. var _this3 = this;
  31954. var tried =
  31955. arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  31956. var wait =
  31957. arguments.length > 4 && arguments[4] !== undefined
  31958. ? arguments[4]
  31959. : 250;
  31960. var callback = arguments.length > 5 ? arguments[5] : undefined;
  31961. if (!lng.length) return callback(null, {}); // noting to load
  31962. return this.backend[fcName](lng, ns, function(err, data) {
  31963. if (
  31964. err &&
  31965. data &&
  31966. /* = retryFlag */
  31967. tried < 5
  31968. ) {
  31969. setTimeout(function() {
  31970. _this3.read.call(
  31971. _this3,
  31972. lng,
  31973. ns,
  31974. fcName,
  31975. tried + 1,
  31976. wait * 2,
  31977. callback
  31978. );
  31979. }, wait);
  31980. return;
  31981. }
  31982. callback(err, data);
  31983. });
  31984. }
  31985. /* eslint consistent-return: 0 */
  31986. },
  31987. {
  31988. key: 'prepareLoading',
  31989. value: function prepareLoading(languages, namespaces) {
  31990. var _this4 = this;
  31991. var options =
  31992. arguments.length > 2 && arguments[2] !== undefined
  31993. ? arguments[2]
  31994. : {};
  31995. var callback = arguments.length > 3 ? arguments[3] : undefined;
  31996. if (!this.backend) {
  31997. this.logger.warn(
  31998. 'No backend was added via i18next.use. Will not load resources.'
  31999. );
  32000. return callback && callback();
  32001. }
  32002. if (typeof languages === 'string')
  32003. languages = this.languageUtils.toResolveHierarchy(languages);
  32004. if (typeof namespaces === 'string') namespaces = [namespaces];
  32005. var toLoad = this.queueLoad(languages, namespaces, options, callback);
  32006. if (!toLoad.toLoad.length) {
  32007. if (!toLoad.pending.length) callback(); // nothing to load and no pendings...callback now
  32008. return null; // pendings will trigger callback
  32009. }
  32010. toLoad.toLoad.forEach(function(name) {
  32011. _this4.loadOne(name);
  32012. });
  32013. }
  32014. },
  32015. {
  32016. key: 'load',
  32017. value: function load(languages, namespaces, callback) {
  32018. this.prepareLoading(languages, namespaces, {}, callback);
  32019. }
  32020. },
  32021. {
  32022. key: 'reload',
  32023. value: function reload(languages, namespaces, callback) {
  32024. this.prepareLoading(
  32025. languages,
  32026. namespaces,
  32027. {
  32028. reload: true
  32029. },
  32030. callback
  32031. );
  32032. }
  32033. },
  32034. {
  32035. key: 'loadOne',
  32036. value: function loadOne(name) {
  32037. var _this5 = this;
  32038. var prefix =
  32039. arguments.length > 1 && arguments[1] !== undefined
  32040. ? arguments[1]
  32041. : '';
  32042. var _name$split3 = name.split('|'),
  32043. _name$split4 = _slicedToArray(_name$split3, 2),
  32044. lng = _name$split4[0],
  32045. ns = _name$split4[1];
  32046. this.read(lng, ns, 'read', null, null, function(err, data) {
  32047. if (err)
  32048. _this5.logger.warn(
  32049. ''
  32050. .concat(prefix, 'loading namespace ')
  32051. .concat(ns, ' for language ')
  32052. .concat(lng, ' failed'),
  32053. err
  32054. );
  32055. if (!err && data)
  32056. _this5.logger.log(
  32057. ''
  32058. .concat(prefix, 'loaded namespace ')
  32059. .concat(ns, ' for language ')
  32060. .concat(lng),
  32061. data
  32062. );
  32063. _this5.loaded(name, err, data);
  32064. });
  32065. }
  32066. },
  32067. {
  32068. key: 'saveMissing',
  32069. value: function saveMissing(
  32070. languages,
  32071. namespace,
  32072. key,
  32073. fallbackValue,
  32074. isUpdate
  32075. ) {
  32076. var options =
  32077. arguments.length > 5 && arguments[5] !== undefined
  32078. ? arguments[5]
  32079. : {};
  32080. if (
  32081. this.services.utils &&
  32082. this.services.utils.hasLoadedNamespace &&
  32083. !this.services.utils.hasLoadedNamespace(namespace)
  32084. ) {
  32085. this.logger.warn(
  32086. 'did not save key "'
  32087. .concat(key, '" for namespace "')
  32088. .concat(namespace, '" as the namespace was not yet loaded'),
  32089. 'This means something IS WRONG in your application setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!'
  32090. );
  32091. return;
  32092. } // ignore non valid keys
  32093. if (key === undefined || key === null || key === '') return;
  32094. if (this.backend && this.backend.create) {
  32095. this.backend.create(
  32096. languages,
  32097. namespace,
  32098. key,
  32099. fallbackValue,
  32100. null,
  32101. /* unused callback */
  32102. _objectSpread({}, options, {
  32103. isUpdate: isUpdate
  32104. })
  32105. );
  32106. } // write to store to avoid resending
  32107. if (!languages || !languages[0]) return;
  32108. this.store.addResource(languages[0], namespace, key, fallbackValue);
  32109. }
  32110. }
  32111. ]);
  32112. return Connector;
  32113. })(EventEmitter);
  32114. function get() {
  32115. return {
  32116. debug: false,
  32117. initImmediate: true,
  32118. ns: ['translation'],
  32119. defaultNS: ['translation'],
  32120. fallbackLng: ['dev'],
  32121. fallbackNS: false,
  32122. // string or array of namespaces
  32123. whitelist: false,
  32124. // array with whitelisted languages
  32125. nonExplicitWhitelist: false,
  32126. load: 'all',
  32127. // | currentOnly | languageOnly
  32128. preload: false,
  32129. // array with preload languages
  32130. simplifyPluralSuffix: true,
  32131. keySeparator: '.',
  32132. nsSeparator: ':',
  32133. pluralSeparator: '_',
  32134. contextSeparator: '_',
  32135. partialBundledLanguages: false,
  32136. // allow bundling certain languages that are not remotely fetched
  32137. saveMissing: false,
  32138. // enable to send missing values
  32139. updateMissing: false,
  32140. // enable to update default values if different from translated value (only useful on initial development, or when keeping code as source of truth)
  32141. saveMissingTo: 'fallback',
  32142. // 'current' || 'all'
  32143. saveMissingPlurals: true,
  32144. // will save all forms not only singular key
  32145. missingKeyHandler: false,
  32146. // function(lng, ns, key, fallbackValue) -> override if prefer on handling
  32147. missingInterpolationHandler: false,
  32148. // function(str, match)
  32149. postProcess: false,
  32150. // string or array of postProcessor names
  32151. postProcessPassResolved: false,
  32152. // pass resolved object into 'options.i18nResolved' for postprocessor
  32153. returnNull: true,
  32154. // allows null value as valid translation
  32155. returnEmptyString: true,
  32156. // allows empty string value as valid translation
  32157. returnObjects: false,
  32158. joinArrays: false,
  32159. // or string to join array
  32160. returnedObjectHandler: false,
  32161. // function(key, value, options) triggered if key returns object but returnObjects is set to false
  32162. parseMissingKeyHandler: false,
  32163. // function(key) parsed a key that was not found in t() before returning
  32164. appendNamespaceToMissingKey: false,
  32165. appendNamespaceToCIMode: false,
  32166. overloadTranslationOptionHandler: function handle(args) {
  32167. var ret = {};
  32168. if (_typeof(args[1]) === 'object') ret = args[1];
  32169. if (typeof args[1] === 'string') ret.defaultValue = args[1];
  32170. if (typeof args[2] === 'string') ret.tDescription = args[2];
  32171. if (_typeof(args[2]) === 'object' || _typeof(args[3]) === 'object') {
  32172. var options = args[3] || args[2];
  32173. Object.keys(options).forEach(function(key) {
  32174. ret[key] = options[key];
  32175. });
  32176. }
  32177. return ret;
  32178. },
  32179. interpolation: {
  32180. escapeValue: true,
  32181. format: function format(value, _format, lng) {
  32182. return value;
  32183. },
  32184. prefix: '{{',
  32185. suffix: '}}',
  32186. formatSeparator: ',',
  32187. // prefixEscaped: '{{',
  32188. // suffixEscaped: '}}',
  32189. // unescapeSuffix: '',
  32190. unescapePrefix: '-',
  32191. nestingPrefix: '$t(',
  32192. nestingSuffix: ')',
  32193. // nestingPrefixEscaped: '$t(',
  32194. // nestingSuffixEscaped: ')',
  32195. // defaultVariables: undefined // object that can have values to interpolate on - extends passed in interpolation data
  32196. maxReplaces: 1000 // max replaces to prevent endless loop
  32197. }
  32198. };
  32199. }
  32200. /* eslint no-param-reassign: 0 */
  32201. function transformOptions(options) {
  32202. // create namespace object if namespace is passed in as string
  32203. if (typeof options.ns === 'string') options.ns = [options.ns];
  32204. if (typeof options.fallbackLng === 'string')
  32205. options.fallbackLng = [options.fallbackLng];
  32206. if (typeof options.fallbackNS === 'string')
  32207. options.fallbackNS = [options.fallbackNS]; // extend whitelist with cimode
  32208. if (options.whitelist && options.whitelist.indexOf('cimode') < 0) {
  32209. options.whitelist = options.whitelist.concat(['cimode']);
  32210. }
  32211. return options;
  32212. }
  32213. function noop() {}
  32214. var I18n =
  32215. /*#__PURE__*/
  32216. (function(_EventEmitter) {
  32217. _inherits(I18n, _EventEmitter);
  32218. function I18n() {
  32219. var _this;
  32220. var options =
  32221. arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  32222. var callback = arguments.length > 1 ? arguments[1] : undefined;
  32223. _classCallCheck(this, I18n);
  32224. _this = _possibleConstructorReturn(this, _getPrototypeOf(I18n).call(this));
  32225. EventEmitter.call(_assertThisInitialized(_this)); // <=IE10 fix (unable to call parent constructor)
  32226. _this.options = transformOptions(options);
  32227. _this.services = {};
  32228. _this.logger = baseLogger;
  32229. _this.modules = {
  32230. external: []
  32231. };
  32232. if (callback && !_this.isInitialized && !options.isClone) {
  32233. // https://github.com/i18next/i18next/issues/879
  32234. if (!_this.options.initImmediate) {
  32235. _this.init(options, callback);
  32236. return _possibleConstructorReturn(_this, _assertThisInitialized(_this));
  32237. }
  32238. setTimeout(function() {
  32239. _this.init(options, callback);
  32240. }, 0);
  32241. }
  32242. return _this;
  32243. }
  32244. _createClass(I18n, [
  32245. {
  32246. key: 'init',
  32247. value: function init() {
  32248. var _this2 = this;
  32249. var options =
  32250. arguments.length > 0 && arguments[0] !== undefined
  32251. ? arguments[0]
  32252. : {};
  32253. var callback = arguments.length > 1 ? arguments[1] : undefined;
  32254. if (typeof options === 'function') {
  32255. callback = options;
  32256. options = {};
  32257. }
  32258. this.options = _objectSpread(
  32259. {},
  32260. get(),
  32261. this.options,
  32262. transformOptions(options)
  32263. );
  32264. this.format = this.options.interpolation.format;
  32265. if (!callback) callback = noop;
  32266. function createClassOnDemand(ClassOrObject) {
  32267. if (!ClassOrObject) return null;
  32268. if (typeof ClassOrObject === 'function') return new ClassOrObject();
  32269. return ClassOrObject;
  32270. } // init services
  32271. if (!this.options.isClone) {
  32272. if (this.modules.logger) {
  32273. baseLogger.init(
  32274. createClassOnDemand(this.modules.logger),
  32275. this.options
  32276. );
  32277. } else {
  32278. baseLogger.init(null, this.options);
  32279. }
  32280. var lu = new LanguageUtil(this.options);
  32281. this.store = new ResourceStore(this.options.resources, this.options);
  32282. var s = this.services;
  32283. s.logger = baseLogger;
  32284. s.resourceStore = this.store;
  32285. s.languageUtils = lu;
  32286. s.pluralResolver = new PluralResolver(lu, {
  32287. prepend: this.options.pluralSeparator,
  32288. compatibilityJSON: this.options.compatibilityJSON,
  32289. simplifyPluralSuffix: this.options.simplifyPluralSuffix
  32290. });
  32291. s.interpolator = new Interpolator(this.options);
  32292. s.utils = {
  32293. hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
  32294. };
  32295. s.backendConnector = new Connector(
  32296. createClassOnDemand(this.modules.backend),
  32297. s.resourceStore,
  32298. s,
  32299. this.options
  32300. ); // pipe events from backendConnector
  32301. s.backendConnector.on('*', function(event) {
  32302. for (
  32303. var _len = arguments.length,
  32304. args = new Array(_len > 1 ? _len - 1 : 0),
  32305. _key = 1;
  32306. _key < _len;
  32307. _key++
  32308. ) {
  32309. args[_key - 1] = arguments[_key];
  32310. }
  32311. _this2.emit.apply(_this2, [event].concat(args));
  32312. });
  32313. if (this.modules.languageDetector) {
  32314. s.languageDetector = createClassOnDemand(
  32315. this.modules.languageDetector
  32316. );
  32317. s.languageDetector.init(s, this.options.detection, this.options);
  32318. }
  32319. if (this.modules.i18nFormat) {
  32320. s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
  32321. if (s.i18nFormat.init) s.i18nFormat.init(this);
  32322. }
  32323. this.translator = new Translator(this.services, this.options); // pipe events from translator
  32324. this.translator.on('*', function(event) {
  32325. for (
  32326. var _len2 = arguments.length,
  32327. args = new Array(_len2 > 1 ? _len2 - 1 : 0),
  32328. _key2 = 1;
  32329. _key2 < _len2;
  32330. _key2++
  32331. ) {
  32332. args[_key2 - 1] = arguments[_key2];
  32333. }
  32334. _this2.emit.apply(_this2, [event].concat(args));
  32335. });
  32336. this.modules.external.forEach(function(m) {
  32337. if (m.init) m.init(_this2);
  32338. });
  32339. } // append api
  32340. var storeApi = [
  32341. 'getResource',
  32342. 'addResource',
  32343. 'addResources',
  32344. 'addResourceBundle',
  32345. 'removeResourceBundle',
  32346. 'hasResourceBundle',
  32347. 'getResourceBundle',
  32348. 'getDataByLanguage'
  32349. ];
  32350. storeApi.forEach(function(fcName) {
  32351. _this2[fcName] = function() {
  32352. var _this2$store;
  32353. return (_this2$store = _this2.store)[fcName].apply(
  32354. _this2$store,
  32355. arguments
  32356. );
  32357. };
  32358. });
  32359. var deferred = defer();
  32360. var load = function load() {
  32361. _this2.changeLanguage(_this2.options.lng, function(err, t) {
  32362. _this2.isInitialized = true;
  32363. _this2.logger.log('initialized', _this2.options);
  32364. _this2.emit('initialized', _this2.options);
  32365. deferred.resolve(t); // not rejecting on err (as err is only a loading translation failed warning)
  32366. callback(err, t);
  32367. });
  32368. };
  32369. if (this.options.resources || !this.options.initImmediate) {
  32370. load();
  32371. } else {
  32372. setTimeout(load, 0);
  32373. }
  32374. return deferred;
  32375. }
  32376. /* eslint consistent-return: 0 */
  32377. },
  32378. {
  32379. key: 'loadResources',
  32380. value: function loadResources(language) {
  32381. var _this3 = this;
  32382. var callback =
  32383. arguments.length > 1 && arguments[1] !== undefined
  32384. ? arguments[1]
  32385. : noop;
  32386. var usedCallback = callback;
  32387. var usedLng = typeof language === 'string' ? language : this.language;
  32388. if (typeof language === 'function') usedCallback = language;
  32389. if (!this.options.resources || this.options.partialBundledLanguages) {
  32390. if (usedLng && usedLng.toLowerCase() === 'cimode')
  32391. return usedCallback(); // avoid loading resources for cimode
  32392. var toLoad = [];
  32393. var append = function append(lng) {
  32394. if (!lng) return;
  32395. var lngs = _this3.services.languageUtils.toResolveHierarchy(lng);
  32396. lngs.forEach(function(l) {
  32397. if (toLoad.indexOf(l) < 0) toLoad.push(l);
  32398. });
  32399. };
  32400. if (!usedLng) {
  32401. // at least load fallbacks in this case
  32402. var fallbacks = this.services.languageUtils.getFallbackCodes(
  32403. this.options.fallbackLng
  32404. );
  32405. fallbacks.forEach(function(l) {
  32406. return append(l);
  32407. });
  32408. } else {
  32409. append(usedLng);
  32410. }
  32411. if (this.options.preload) {
  32412. this.options.preload.forEach(function(l) {
  32413. return append(l);
  32414. });
  32415. }
  32416. this.services.backendConnector.load(
  32417. toLoad,
  32418. this.options.ns,
  32419. usedCallback
  32420. );
  32421. } else {
  32422. usedCallback(null);
  32423. }
  32424. }
  32425. },
  32426. {
  32427. key: 'reloadResources',
  32428. value: function reloadResources(lngs, ns, callback) {
  32429. var deferred = defer();
  32430. if (!lngs) lngs = this.languages;
  32431. if (!ns) ns = this.options.ns;
  32432. if (!callback) callback = noop;
  32433. this.services.backendConnector.reload(lngs, ns, function(err) {
  32434. deferred.resolve(); // not rejecting on err (as err is only a loading translation failed warning)
  32435. callback(err);
  32436. });
  32437. return deferred;
  32438. }
  32439. },
  32440. {
  32441. key: 'use',
  32442. value: function use(module) {
  32443. if (module.type === 'backend') {
  32444. this.modules.backend = module;
  32445. }
  32446. if (
  32447. module.type === 'logger' ||
  32448. (module.log && module.warn && module.error)
  32449. ) {
  32450. this.modules.logger = module;
  32451. }
  32452. if (module.type === 'languageDetector') {
  32453. this.modules.languageDetector = module;
  32454. }
  32455. if (module.type === 'i18nFormat') {
  32456. this.modules.i18nFormat = module;
  32457. }
  32458. if (module.type === 'postProcessor') {
  32459. postProcessor.addPostProcessor(module);
  32460. }
  32461. if (module.type === '3rdParty') {
  32462. this.modules.external.push(module);
  32463. }
  32464. return this;
  32465. }
  32466. },
  32467. {
  32468. key: 'changeLanguage',
  32469. value: function changeLanguage(lng, callback) {
  32470. var _this4 = this;
  32471. this.isLanguageChangingTo = lng;
  32472. var deferred = defer();
  32473. this.emit('languageChanging', lng);
  32474. var done = function done(err, l) {
  32475. if (l) {
  32476. _this4.language = l;
  32477. _this4.languages = _this4.services.languageUtils.toResolveHierarchy(
  32478. l
  32479. );
  32480. _this4.translator.changeLanguage(l);
  32481. _this4.isLanguageChangingTo = undefined;
  32482. _this4.emit('languageChanged', l);
  32483. _this4.logger.log('languageChanged', l);
  32484. } else {
  32485. _this4.isLanguageChangingTo = undefined;
  32486. }
  32487. deferred.resolve(function() {
  32488. return _this4.t.apply(_this4, arguments);
  32489. });
  32490. if (callback)
  32491. callback(err, function() {
  32492. return _this4.t.apply(_this4, arguments);
  32493. });
  32494. };
  32495. var setLng = function setLng(l) {
  32496. if (l) {
  32497. if (!_this4.language) {
  32498. _this4.language = l;
  32499. _this4.languages = _this4.services.languageUtils.toResolveHierarchy(
  32500. l
  32501. );
  32502. }
  32503. if (!_this4.translator.language)
  32504. _this4.translator.changeLanguage(l);
  32505. if (_this4.services.languageDetector)
  32506. _this4.services.languageDetector.cacheUserLanguage(l);
  32507. }
  32508. _this4.loadResources(l, function(err) {
  32509. done(err, l);
  32510. });
  32511. };
  32512. if (
  32513. !lng &&
  32514. this.services.languageDetector &&
  32515. !this.services.languageDetector.async
  32516. ) {
  32517. setLng(this.services.languageDetector.detect());
  32518. } else if (
  32519. !lng &&
  32520. this.services.languageDetector &&
  32521. this.services.languageDetector.async
  32522. ) {
  32523. this.services.languageDetector.detect(setLng);
  32524. } else {
  32525. setLng(lng);
  32526. }
  32527. return deferred;
  32528. }
  32529. },
  32530. {
  32531. key: 'getFixedT',
  32532. value: function getFixedT(lng, ns) {
  32533. var _this5 = this;
  32534. var fixedT = function fixedT(key, opts) {
  32535. var options;
  32536. if (_typeof(opts) !== 'object') {
  32537. for (
  32538. var _len3 = arguments.length,
  32539. rest = new Array(_len3 > 2 ? _len3 - 2 : 0),
  32540. _key3 = 2;
  32541. _key3 < _len3;
  32542. _key3++
  32543. ) {
  32544. rest[_key3 - 2] = arguments[_key3];
  32545. }
  32546. options = _this5.options.overloadTranslationOptionHandler(
  32547. [key, opts].concat(rest)
  32548. );
  32549. } else {
  32550. options = _objectSpread({}, opts);
  32551. }
  32552. options.lng = options.lng || fixedT.lng;
  32553. options.lngs = options.lngs || fixedT.lngs;
  32554. options.ns = options.ns || fixedT.ns;
  32555. return _this5.t(key, options);
  32556. };
  32557. if (typeof lng === 'string') {
  32558. fixedT.lng = lng;
  32559. } else {
  32560. fixedT.lngs = lng;
  32561. }
  32562. fixedT.ns = ns;
  32563. return fixedT;
  32564. }
  32565. },
  32566. {
  32567. key: 't',
  32568. value: function t() {
  32569. var _this$translator;
  32570. return (
  32571. this.translator &&
  32572. (_this$translator = this.translator).translate.apply(
  32573. _this$translator,
  32574. arguments
  32575. )
  32576. );
  32577. }
  32578. },
  32579. {
  32580. key: 'exists',
  32581. value: function exists() {
  32582. var _this$translator2;
  32583. return (
  32584. this.translator &&
  32585. (_this$translator2 = this.translator).exists.apply(
  32586. _this$translator2,
  32587. arguments
  32588. )
  32589. );
  32590. }
  32591. },
  32592. {
  32593. key: 'setDefaultNamespace',
  32594. value: function setDefaultNamespace(ns) {
  32595. this.options.defaultNS = ns;
  32596. }
  32597. },
  32598. {
  32599. key: 'hasLoadedNamespace',
  32600. value: function hasLoadedNamespace(ns) {
  32601. var _this6 = this;
  32602. if (!this.isInitialized) {
  32603. this.logger.warn(
  32604. 'hasLoadedNamespace: i18next was not initialized',
  32605. this.languages
  32606. );
  32607. return false;
  32608. }
  32609. if (!this.languages || !this.languages.length) {
  32610. this.logger.warn(
  32611. 'hasLoadedNamespace: i18n.languages were undefined or empty',
  32612. this.languages
  32613. );
  32614. return false;
  32615. }
  32616. var lng = this.languages[0];
  32617. var fallbackLng = this.options ? this.options.fallbackLng : false;
  32618. var lastLng = this.languages[this.languages.length - 1]; // we're in cimode so this shall pass
  32619. if (lng.toLowerCase() === 'cimode') return true;
  32620. var loadNotPending = function loadNotPending(l, n) {
  32621. var loadState =
  32622. _this6.services.backendConnector.state[''.concat(l, '|').concat(n)];
  32623. return loadState === -1 || loadState === 2;
  32624. }; // loaded -> SUCCESS
  32625. if (this.hasResourceBundle(lng, ns)) return true; // were not loading at all -> SEMI SUCCESS
  32626. if (!this.services.backendConnector.backend) return true; // failed loading ns - but at least fallback is not pending -> SEMI SUCCESS
  32627. if (
  32628. loadNotPending(lng, ns) &&
  32629. (!fallbackLng || loadNotPending(lastLng, ns))
  32630. )
  32631. return true;
  32632. return false;
  32633. }
  32634. },
  32635. {
  32636. key: 'loadNamespaces',
  32637. value: function loadNamespaces(ns, callback) {
  32638. var _this7 = this;
  32639. var deferred = defer();
  32640. if (!this.options.ns) {
  32641. callback && callback();
  32642. return Promise.resolve();
  32643. }
  32644. if (typeof ns === 'string') ns = [ns];
  32645. ns.forEach(function(n) {
  32646. if (_this7.options.ns.indexOf(n) < 0) _this7.options.ns.push(n);
  32647. });
  32648. this.loadResources(function(err) {
  32649. deferred.resolve();
  32650. if (callback) callback(err);
  32651. });
  32652. return deferred;
  32653. }
  32654. },
  32655. {
  32656. key: 'loadLanguages',
  32657. value: function loadLanguages(lngs, callback) {
  32658. var deferred = defer();
  32659. if (typeof lngs === 'string') lngs = [lngs];
  32660. var preloaded = this.options.preload || [];
  32661. var newLngs = lngs.filter(function(lng) {
  32662. return preloaded.indexOf(lng) < 0;
  32663. }); // Exit early if all given languages are already preloaded
  32664. if (!newLngs.length) {
  32665. if (callback) callback();
  32666. return Promise.resolve();
  32667. }
  32668. this.options.preload = preloaded.concat(newLngs);
  32669. this.loadResources(function(err) {
  32670. deferred.resolve();
  32671. if (callback) callback(err);
  32672. });
  32673. return deferred;
  32674. }
  32675. },
  32676. {
  32677. key: 'dir',
  32678. value: function dir(lng) {
  32679. if (!lng)
  32680. lng =
  32681. this.languages && this.languages.length > 0
  32682. ? this.languages[0]
  32683. : this.language;
  32684. if (!lng) return 'rtl';
  32685. var rtlLngs = [
  32686. 'ar',
  32687. 'shu',
  32688. 'sqr',
  32689. 'ssh',
  32690. 'xaa',
  32691. 'yhd',
  32692. 'yud',
  32693. 'aao',
  32694. 'abh',
  32695. 'abv',
  32696. 'acm',
  32697. 'acq',
  32698. 'acw',
  32699. 'acx',
  32700. 'acy',
  32701. 'adf',
  32702. 'ads',
  32703. 'aeb',
  32704. 'aec',
  32705. 'afb',
  32706. 'ajp',
  32707. 'apc',
  32708. 'apd',
  32709. 'arb',
  32710. 'arq',
  32711. 'ars',
  32712. 'ary',
  32713. 'arz',
  32714. 'auz',
  32715. 'avl',
  32716. 'ayh',
  32717. 'ayl',
  32718. 'ayn',
  32719. 'ayp',
  32720. 'bbz',
  32721. 'pga',
  32722. 'he',
  32723. 'iw',
  32724. 'ps',
  32725. 'pbt',
  32726. 'pbu',
  32727. 'pst',
  32728. 'prp',
  32729. 'prd',
  32730. 'ur',
  32731. 'ydd',
  32732. 'yds',
  32733. 'yih',
  32734. 'ji',
  32735. 'yi',
  32736. 'hbo',
  32737. 'men',
  32738. 'xmn',
  32739. 'fa',
  32740. 'jpr',
  32741. 'peo',
  32742. 'pes',
  32743. 'prs',
  32744. 'dv',
  32745. 'sam'
  32746. ];
  32747. return rtlLngs.indexOf(
  32748. this.services.languageUtils.getLanguagePartFromCode(lng)
  32749. ) >= 0
  32750. ? 'rtl'
  32751. : 'ltr';
  32752. }
  32753. /* eslint class-methods-use-this: 0 */
  32754. },
  32755. {
  32756. key: 'createInstance',
  32757. value: function createInstance() {
  32758. var options =
  32759. arguments.length > 0 && arguments[0] !== undefined
  32760. ? arguments[0]
  32761. : {};
  32762. var callback = arguments.length > 1 ? arguments[1] : undefined;
  32763. return new I18n(options, callback);
  32764. }
  32765. },
  32766. {
  32767. key: 'cloneInstance',
  32768. value: function cloneInstance() {
  32769. var _this8 = this;
  32770. var options =
  32771. arguments.length > 0 && arguments[0] !== undefined
  32772. ? arguments[0]
  32773. : {};
  32774. var callback =
  32775. arguments.length > 1 && arguments[1] !== undefined
  32776. ? arguments[1]
  32777. : noop;
  32778. var mergedOptions = _objectSpread({}, this.options, options, {
  32779. isClone: true
  32780. });
  32781. var clone = new I18n(mergedOptions);
  32782. var membersToCopy = ['store', 'services', 'language'];
  32783. membersToCopy.forEach(function(m) {
  32784. clone[m] = _this8[m];
  32785. });
  32786. clone.translator = new Translator(clone.services, clone.options);
  32787. clone.translator.on('*', function(event) {
  32788. for (
  32789. var _len4 = arguments.length,
  32790. args = new Array(_len4 > 1 ? _len4 - 1 : 0),
  32791. _key4 = 1;
  32792. _key4 < _len4;
  32793. _key4++
  32794. ) {
  32795. args[_key4 - 1] = arguments[_key4];
  32796. }
  32797. clone.emit.apply(clone, [event].concat(args));
  32798. });
  32799. clone.init(mergedOptions, callback);
  32800. clone.translator.options = clone.options; // sync options
  32801. return clone;
  32802. }
  32803. }
  32804. ]);
  32805. return I18n;
  32806. })(EventEmitter);
  32807. var i18next = new I18n();
  32808. module.exports = i18next;
  32809. },
  32810. {
  32811. '@babel/runtime/helpers/assertThisInitialized': 4,
  32812. '@babel/runtime/helpers/classCallCheck': 5,
  32813. '@babel/runtime/helpers/createClass': 6,
  32814. '@babel/runtime/helpers/getPrototypeOf': 8,
  32815. '@babel/runtime/helpers/inherits': 9,
  32816. '@babel/runtime/helpers/objectSpread': 14,
  32817. '@babel/runtime/helpers/possibleConstructorReturn': 15,
  32818. '@babel/runtime/helpers/slicedToArray': 17,
  32819. '@babel/runtime/helpers/toConsumableArray': 18,
  32820. '@babel/runtime/helpers/typeof': 19
  32821. }
  32822. ],
  32823. 255: [
  32824. function(_dereq_, module, exports) {
  32825. exports.read = function(buffer, offset, isLE, mLen, nBytes) {
  32826. var e, m;
  32827. var eLen = nBytes * 8 - mLen - 1;
  32828. var eMax = (1 << eLen) - 1;
  32829. var eBias = eMax >> 1;
  32830. var nBits = -7;
  32831. var i = isLE ? nBytes - 1 : 0;
  32832. var d = isLE ? -1 : 1;
  32833. var s = buffer[offset + i];
  32834. i += d;
  32835. e = s & ((1 << -nBits) - 1);
  32836. s >>= -nBits;
  32837. nBits += eLen;
  32838. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  32839. m = e & ((1 << -nBits) - 1);
  32840. e >>= -nBits;
  32841. nBits += mLen;
  32842. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  32843. if (e === 0) {
  32844. e = 1 - eBias;
  32845. } else if (e === eMax) {
  32846. return m ? NaN : (s ? -1 : 1) * Infinity;
  32847. } else {
  32848. m = m + Math.pow(2, mLen);
  32849. e = e - eBias;
  32850. }
  32851. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  32852. };
  32853. exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
  32854. var e, m, c;
  32855. var eLen = nBytes * 8 - mLen - 1;
  32856. var eMax = (1 << eLen) - 1;
  32857. var eBias = eMax >> 1;
  32858. var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
  32859. var i = isLE ? 0 : nBytes - 1;
  32860. var d = isLE ? 1 : -1;
  32861. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  32862. value = Math.abs(value);
  32863. if (isNaN(value) || value === Infinity) {
  32864. m = isNaN(value) ? 1 : 0;
  32865. e = eMax;
  32866. } else {
  32867. e = Math.floor(Math.log(value) / Math.LN2);
  32868. if (value * (c = Math.pow(2, -e)) < 1) {
  32869. e--;
  32870. c *= 2;
  32871. }
  32872. if (e + eBias >= 1) {
  32873. value += rt / c;
  32874. } else {
  32875. value += rt * Math.pow(2, 1 - eBias);
  32876. }
  32877. if (value * c >= 2) {
  32878. e++;
  32879. c /= 2;
  32880. }
  32881. if (e + eBias >= eMax) {
  32882. m = 0;
  32883. e = eMax;
  32884. } else if (e + eBias >= 1) {
  32885. m = (value * c - 1) * Math.pow(2, mLen);
  32886. e = e + eBias;
  32887. } else {
  32888. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  32889. e = 0;
  32890. }
  32891. }
  32892. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  32893. e = (e << mLen) | m;
  32894. eLen += mLen;
  32895. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  32896. buffer[offset + i - d] |= s * 128;
  32897. };
  32898. },
  32899. {}
  32900. ],
  32901. 256: [
  32902. function(_dereq_, module, exports) {
  32903. /*
  32904. Copyright 2000, Silicon Graphics, Inc. All Rights Reserved.
  32905. Copyright 2015, Google Inc. All Rights Reserved.
  32906. Permission is hereby granted, free of charge, to any person obtaining a copy
  32907. of this software and associated documentation files (the "Software"), to
  32908. deal in the Software without restriction, including without limitation the
  32909. rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  32910. sell copies of the Software, and to permit persons to whom the Software is
  32911. furnished to do so, subject to the following conditions:
  32912. The above copyright notice including the dates of first publication and
  32913. either this permission notice or a reference to http://oss.sgi.com/projects/FreeB/
  32914. shall be included in all copies or substantial portions of the Software.
  32915. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  32916. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  32917. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  32918. SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  32919. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  32920. IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32921. Original Code. The Original Code is: OpenGL Sample Implementation,
  32922. Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
  32923. Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
  32924. Copyright in any portions created by third parties is as indicated
  32925. elsewhere herein. All Rights Reserved.
  32926. */
  32927. 'use strict';
  32928. var n;
  32929. function t(a, b) {
  32930. return a.b === b.b && a.a === b.a;
  32931. }
  32932. function u(a, b) {
  32933. return a.b < b.b || (a.b === b.b && a.a <= b.a);
  32934. }
  32935. function v(a, b, c) {
  32936. var d = b.b - a.b,
  32937. e = c.b - b.b;
  32938. return 0 < d + e
  32939. ? d < e
  32940. ? b.a - a.a + d / (d + e) * (a.a - c.a)
  32941. : b.a - c.a + e / (d + e) * (c.a - a.a)
  32942. : 0;
  32943. }
  32944. function x(a, b, c) {
  32945. var d = b.b - a.b,
  32946. e = c.b - b.b;
  32947. return 0 < d + e ? (b.a - c.a) * d + (b.a - a.a) * e : 0;
  32948. }
  32949. function z(a, b) {
  32950. return a.a < b.a || (a.a === b.a && a.b <= b.b);
  32951. }
  32952. function aa(a, b, c) {
  32953. var d = b.a - a.a,
  32954. e = c.a - b.a;
  32955. return 0 < d + e
  32956. ? d < e
  32957. ? b.b - a.b + d / (d + e) * (a.b - c.b)
  32958. : b.b - c.b + e / (d + e) * (c.b - a.b)
  32959. : 0;
  32960. }
  32961. function ba(a, b, c) {
  32962. var d = b.a - a.a,
  32963. e = c.a - b.a;
  32964. return 0 < d + e ? (b.b - c.b) * d + (b.b - a.b) * e : 0;
  32965. }
  32966. function ca(a) {
  32967. return u(a.b.a, a.a);
  32968. }
  32969. function da(a) {
  32970. return u(a.a, a.b.a);
  32971. }
  32972. function A(a, b, c, d) {
  32973. a = 0 > a ? 0 : a;
  32974. c = 0 > c ? 0 : c;
  32975. return a <= c
  32976. ? 0 === c ? (b + d) / 2 : b + a / (a + c) * (d - b)
  32977. : d + c / (a + c) * (b - d);
  32978. }
  32979. function ea(a) {
  32980. var b = B(a.b);
  32981. C(b, a.c);
  32982. C(b.b, a.c);
  32983. D(b, a.a);
  32984. return b;
  32985. }
  32986. function E(a, b) {
  32987. var c = !1,
  32988. d = !1;
  32989. a !== b &&
  32990. (b.a !== a.a && ((d = !0), F(b.a, a.a)),
  32991. b.d !== a.d && ((c = !0), G(b.d, a.d)),
  32992. H(b, a),
  32993. d || (C(b, a.a), (a.a.c = a)),
  32994. c || (D(b, a.d), (a.d.a = a)));
  32995. }
  32996. function I(a) {
  32997. var b = a.b,
  32998. c = !1;
  32999. a.d !== a.b.d && ((c = !0), G(a.d, a.b.d));
  33000. a.c === a
  33001. ? F(a.a, null)
  33002. : ((a.b.d.a = J(a)), (a.a.c = a.c), H(a, J(a)), c || D(a, a.d));
  33003. b.c === b
  33004. ? (F(b.a, null), G(b.d, null))
  33005. : ((a.d.a = J(b)), (b.a.c = b.c), H(b, J(b)));
  33006. fa(a);
  33007. }
  33008. function K(a) {
  33009. var b = B(a),
  33010. c = b.b;
  33011. H(b, a.e);
  33012. b.a = a.b.a;
  33013. C(c, b.a);
  33014. b.d = c.d = a.d;
  33015. b = b.b;
  33016. H(a.b, J(a.b));
  33017. H(a.b, b);
  33018. a.b.a = b.a;
  33019. b.b.a.c = b.b;
  33020. b.b.d = a.b.d;
  33021. b.f = a.f;
  33022. b.b.f = a.b.f;
  33023. return b;
  33024. }
  33025. function L(a, b) {
  33026. var c = !1,
  33027. d = B(a),
  33028. e = d.b;
  33029. b.d !== a.d && ((c = !0), G(b.d, a.d));
  33030. H(d, a.e);
  33031. H(e, b);
  33032. d.a = a.b.a;
  33033. e.a = b.a;
  33034. d.d = e.d = a.d;
  33035. a.d.a = e;
  33036. c || D(d, a.d);
  33037. return d;
  33038. }
  33039. function B(a) {
  33040. var b = new M(),
  33041. c = new M(),
  33042. d = a.b.h;
  33043. c.h = d;
  33044. d.b.h = b;
  33045. b.h = a;
  33046. a.b.h = c;
  33047. b.b = c;
  33048. b.c = b;
  33049. b.e = c;
  33050. c.b = b;
  33051. c.c = c;
  33052. return (c.e = b);
  33053. }
  33054. function H(a, b) {
  33055. var c = a.c,
  33056. d = b.c;
  33057. c.b.e = b;
  33058. d.b.e = a;
  33059. a.c = d;
  33060. b.c = c;
  33061. }
  33062. function C(a, b) {
  33063. var c = b.f,
  33064. d = new N(b, c);
  33065. c.e = d;
  33066. b.f = d;
  33067. c = d.c = a;
  33068. do (c.a = d), (c = c.c);
  33069. while (c !== a);
  33070. }
  33071. function D(a, b) {
  33072. var c = b.d,
  33073. d = new ga(b, c);
  33074. c.b = d;
  33075. b.d = d;
  33076. d.a = a;
  33077. d.c = b.c;
  33078. c = a;
  33079. do (c.d = d), (c = c.e);
  33080. while (c !== a);
  33081. }
  33082. function fa(a) {
  33083. var b = a.h;
  33084. a = a.b.h;
  33085. b.b.h = a;
  33086. a.b.h = b;
  33087. }
  33088. function F(a, b) {
  33089. var c = a.c,
  33090. d = c;
  33091. do (d.a = b), (d = d.c);
  33092. while (d !== c);
  33093. c = a.f;
  33094. d = a.e;
  33095. d.f = c;
  33096. c.e = d;
  33097. }
  33098. function G(a, b) {
  33099. var c = a.a,
  33100. d = c;
  33101. do (d.d = b), (d = d.e);
  33102. while (d !== c);
  33103. c = a.d;
  33104. d = a.b;
  33105. d.d = c;
  33106. c.b = d;
  33107. }
  33108. function ha(a) {
  33109. var b = 0;
  33110. Math.abs(a[1]) > Math.abs(a[0]) && (b = 1);
  33111. Math.abs(a[2]) > Math.abs(a[b]) && (b = 2);
  33112. return b;
  33113. }
  33114. var O = 4 * 1e150;
  33115. function P(a, b) {
  33116. a.f += b.f;
  33117. a.b.f += b.b.f;
  33118. }
  33119. function ia(a, b, c) {
  33120. a = a.a;
  33121. b = b.a;
  33122. c = c.a;
  33123. if (b.b.a === a)
  33124. return c.b.a === a
  33125. ? u(b.a, c.a) ? 0 >= x(c.b.a, b.a, c.a) : 0 <= x(b.b.a, c.a, b.a)
  33126. : 0 >= x(c.b.a, a, c.a);
  33127. if (c.b.a === a) return 0 <= x(b.b.a, a, b.a);
  33128. b = v(b.b.a, a, b.a);
  33129. a = v(c.b.a, a, c.a);
  33130. return b >= a;
  33131. }
  33132. function Q(a) {
  33133. a.a.i = null;
  33134. var b = a.e;
  33135. b.a.c = b.c;
  33136. b.c.a = b.a;
  33137. a.e = null;
  33138. }
  33139. function ja(a, b) {
  33140. I(a.a);
  33141. a.c = !1;
  33142. a.a = b;
  33143. b.i = a;
  33144. }
  33145. function ka(a) {
  33146. var b = a.a.a;
  33147. do a = R(a);
  33148. while (a.a.a === b);
  33149. a.c && ((b = L(S(a).a.b, a.a.e)), ja(a, b), (a = R(a)));
  33150. return a;
  33151. }
  33152. function la(a, b, c) {
  33153. var d = new ma();
  33154. d.a = c;
  33155. d.e = na(a.f, b.e, d);
  33156. return (c.i = d);
  33157. }
  33158. function oa(a, b) {
  33159. switch (a.s) {
  33160. case 100130:
  33161. return 0 !== (b & 1);
  33162. case 100131:
  33163. return 0 !== b;
  33164. case 100132:
  33165. return 0 < b;
  33166. case 100133:
  33167. return 0 > b;
  33168. case 100134:
  33169. return 2 <= b || -2 >= b;
  33170. }
  33171. return !1;
  33172. }
  33173. function pa(a) {
  33174. var b = a.a,
  33175. c = b.d;
  33176. c.c = a.d;
  33177. c.a = b;
  33178. Q(a);
  33179. }
  33180. function T(a, b, c) {
  33181. a = b;
  33182. for (b = b.a; a !== c; ) {
  33183. a.c = !1;
  33184. var d = S(a),
  33185. e = d.a;
  33186. if (e.a !== b.a) {
  33187. if (!d.c) {
  33188. pa(a);
  33189. break;
  33190. }
  33191. e = L(b.c.b, e.b);
  33192. ja(d, e);
  33193. }
  33194. b.c !== e && (E(J(e), e), E(b, e));
  33195. pa(a);
  33196. b = d.a;
  33197. a = d;
  33198. }
  33199. return b;
  33200. }
  33201. function U(a, b, c, d, e, f) {
  33202. var g = !0;
  33203. do la(a, b, c.b), (c = c.c);
  33204. while (c !== d);
  33205. for (null === e && (e = S(b).a.b.c); ; ) {
  33206. d = S(b);
  33207. c = d.a.b;
  33208. if (c.a !== e.a) break;
  33209. c.c !== e && (E(J(c), c), E(J(e), c));
  33210. d.f = b.f - c.f;
  33211. d.d = oa(a, d.f);
  33212. b.b = !0;
  33213. !g && qa(a, b) && (P(c, e), Q(b), I(e));
  33214. g = !1;
  33215. b = d;
  33216. e = c;
  33217. }
  33218. b.b = !0;
  33219. f && ra(a, b);
  33220. }
  33221. function sa(a, b, c, d, e) {
  33222. var f = [b.g[0], b.g[1], b.g[2]];
  33223. b.d = null;
  33224. b.d = a.o ? a.o(f, c, d, a.c) || null : null;
  33225. null === b.d && (e ? a.n || (V(a, 100156), (a.n = !0)) : (b.d = c[0]));
  33226. }
  33227. function ta(a, b, c) {
  33228. var d = [null, null, null, null];
  33229. d[0] = b.a.d;
  33230. d[1] = c.a.d;
  33231. sa(a, b.a, d, [0.5, 0.5, 0, 0], !1);
  33232. E(b, c);
  33233. }
  33234. function ua(a, b, c, d, e) {
  33235. var f = Math.abs(b.b - a.b) + Math.abs(b.a - a.a),
  33236. g = Math.abs(c.b - a.b) + Math.abs(c.a - a.a),
  33237. h = e + 1;
  33238. d[e] = 0.5 * g / (f + g);
  33239. d[h] = 0.5 * f / (f + g);
  33240. a.g[0] += d[e] * b.g[0] + d[h] * c.g[0];
  33241. a.g[1] += d[e] * b.g[1] + d[h] * c.g[1];
  33242. a.g[2] += d[e] * b.g[2] + d[h] * c.g[2];
  33243. }
  33244. function qa(a, b) {
  33245. var c = S(b),
  33246. d = b.a,
  33247. e = c.a;
  33248. if (u(d.a, e.a)) {
  33249. if (0 < x(e.b.a, d.a, e.a)) return !1;
  33250. if (!t(d.a, e.a)) K(e.b), E(d, J(e)), (b.b = c.b = !0);
  33251. else if (d.a !== e.a) {
  33252. var c = a.e,
  33253. f = d.a.h;
  33254. if (0 <= f) {
  33255. var c = c.b,
  33256. g = c.d,
  33257. h = c.e,
  33258. k = c.c,
  33259. l = k[f];
  33260. g[l] = g[c.a];
  33261. k[g[l]] = l;
  33262. l <= --c.a &&
  33263. (1 >= l ? W(c, l) : u(h[g[l >> 1]], h[g[l]]) ? W(c, l) : va(c, l));
  33264. h[f] = null;
  33265. k[f] = c.b;
  33266. c.b = f;
  33267. } else
  33268. for (c.c[-(f + 1)] = null; 0 < c.a && null === c.c[c.d[c.a - 1]]; ) --c.a;
  33269. ta(a, J(e), d);
  33270. }
  33271. } else {
  33272. if (0 > x(d.b.a, e.a, d.a)) return !1;
  33273. R(b).b = b.b = !0;
  33274. K(d.b);
  33275. E(J(e), d);
  33276. }
  33277. return !0;
  33278. }
  33279. function wa(a, b) {
  33280. var c = S(b),
  33281. d = b.a,
  33282. e = c.a,
  33283. f = d.a,
  33284. g = e.a,
  33285. h = d.b.a,
  33286. k = e.b.a,
  33287. l = new N();
  33288. x(h, a.a, f);
  33289. x(k, a.a, g);
  33290. if (f === g || Math.min(f.a, h.a) > Math.max(g.a, k.a)) return !1;
  33291. if (u(f, g)) {
  33292. if (0 < x(k, f, g)) return !1;
  33293. } else if (0 > x(h, g, f)) return !1;
  33294. var r = h,
  33295. p = f,
  33296. q = k,
  33297. y = g,
  33298. m,
  33299. w;
  33300. u(r, p) || ((m = r), (r = p), (p = m));
  33301. u(q, y) || ((m = q), (q = y), (y = m));
  33302. u(r, q) || ((m = r), (r = q), (q = m), (m = p), (p = y), (y = m));
  33303. u(q, p)
  33304. ? u(p, y)
  33305. ? ((m = v(r, q, p)),
  33306. (w = v(q, p, y)),
  33307. 0 > m + w && ((m = -m), (w = -w)),
  33308. (l.b = A(m, q.b, w, p.b)))
  33309. : ((m = x(r, q, p)),
  33310. (w = -x(r, y, p)),
  33311. 0 > m + w && ((m = -m), (w = -w)),
  33312. (l.b = A(m, q.b, w, y.b)))
  33313. : (l.b = (q.b + p.b) / 2);
  33314. z(r, p) || ((m = r), (r = p), (p = m));
  33315. z(q, y) || ((m = q), (q = y), (y = m));
  33316. z(r, q) || ((m = r), (r = q), (q = m), (m = p), (p = y), (y = m));
  33317. z(q, p)
  33318. ? z(p, y)
  33319. ? ((m = aa(r, q, p)),
  33320. (w = aa(q, p, y)),
  33321. 0 > m + w && ((m = -m), (w = -w)),
  33322. (l.a = A(m, q.a, w, p.a)))
  33323. : ((m = ba(r, q, p)),
  33324. (w = -ba(r, y, p)),
  33325. 0 > m + w && ((m = -m), (w = -w)),
  33326. (l.a = A(m, q.a, w, y.a)))
  33327. : (l.a = (q.a + p.a) / 2);
  33328. u(l, a.a) && ((l.b = a.a.b), (l.a = a.a.a));
  33329. r = u(f, g) ? f : g;
  33330. u(r, l) && ((l.b = r.b), (l.a = r.a));
  33331. if (t(l, f) || t(l, g)) return qa(a, b), !1;
  33332. if ((!t(h, a.a) && 0 <= x(h, a.a, l)) || (!t(k, a.a) && 0 >= x(k, a.a, l))) {
  33333. if (k === a.a)
  33334. return (
  33335. K(d.b),
  33336. E(e.b, d),
  33337. (b = ka(b)),
  33338. (d = S(b).a),
  33339. T(a, S(b), c),
  33340. U(a, b, J(d), d, d, !0),
  33341. !0
  33342. );
  33343. if (h === a.a) {
  33344. K(e.b);
  33345. E(d.e, J(e));
  33346. f = c = b;
  33347. g = f.a.b.a;
  33348. do f = R(f);
  33349. while (f.a.b.a === g);
  33350. b = f;
  33351. f = S(b).a.b.c;
  33352. c.a = J(e);
  33353. e = T(a, c, null);
  33354. U(a, b, e.c, d.b.c, f, !0);
  33355. return !0;
  33356. }
  33357. 0 <= x(h, a.a, l) &&
  33358. ((R(b).b = b.b = !0), K(d.b), (d.a.b = a.a.b), (d.a.a = a.a.a));
  33359. 0 >= x(k, a.a, l) &&
  33360. ((b.b = c.b = !0), K(e.b), (e.a.b = a.a.b), (e.a.a = a.a.a));
  33361. return !1;
  33362. }
  33363. K(d.b);
  33364. K(e.b);
  33365. E(J(e), d);
  33366. d.a.b = l.b;
  33367. d.a.a = l.a;
  33368. d.a.h = xa(a.e, d.a);
  33369. d = d.a;
  33370. e = [0, 0, 0, 0];
  33371. l = [f.d, h.d, g.d, k.d];
  33372. d.g[0] = d.g[1] = d.g[2] = 0;
  33373. ua(d, f, h, e, 0);
  33374. ua(d, g, k, e, 2);
  33375. sa(a, d, l, e, !0);
  33376. R(b).b = b.b = c.b = !0;
  33377. return !1;
  33378. }
  33379. function ra(a, b) {
  33380. for (var c = S(b); ; ) {
  33381. for (; c.b; ) (b = c), (c = S(c));
  33382. if (!b.b && ((c = b), (b = R(b)), null === b || !b.b)) break;
  33383. b.b = !1;
  33384. var d = b.a,
  33385. e = c.a,
  33386. f;
  33387. if ((f = d.b.a !== e.b.a))
  33388. a: {
  33389. f = b;
  33390. var g = S(f),
  33391. h = f.a,
  33392. k = g.a,
  33393. l = void 0;
  33394. if (u(h.b.a, k.b.a)) {
  33395. if (0 > x(h.b.a, k.b.a, h.a)) {
  33396. f = !1;
  33397. break a;
  33398. }
  33399. R(f).b = f.b = !0;
  33400. l = K(h);
  33401. E(k.b, l);
  33402. l.d.c = f.d;
  33403. } else {
  33404. if (0 < x(k.b.a, h.b.a, k.a)) {
  33405. f = !1;
  33406. break a;
  33407. }
  33408. f.b = g.b = !0;
  33409. l = K(k);
  33410. E(h.e, k.b);
  33411. l.b.d.c = f.d;
  33412. }
  33413. f = !0;
  33414. }
  33415. f &&
  33416. (c.c
  33417. ? (Q(c), I(e), (c = S(b)), (e = c.a))
  33418. : b.c && (Q(b), I(d), (b = R(c)), (d = b.a)));
  33419. if (d.a !== e.a)
  33420. if (d.b.a === e.b.a || b.c || c.c || (d.b.a !== a.a && e.b.a !== a.a))
  33421. qa(a, b);
  33422. else if (wa(a, b)) break;
  33423. d.a === e.a && d.b.a === e.b.a && (P(e, d), Q(b), I(d), (b = R(c)));
  33424. }
  33425. }
  33426. function ya(a, b) {
  33427. a.a = b;
  33428. for (var c = b.c; null === c.i; )
  33429. if (((c = c.c), c === b.c)) {
  33430. var c = a,
  33431. d = b,
  33432. e = new ma();
  33433. e.a = d.c.b;
  33434. var f = c.f,
  33435. g = f.a;
  33436. do g = g.a;
  33437. while (null !== g.b && !f.c(f.b, e, g.b));
  33438. var f = g.b,
  33439. h = S(f),
  33440. e = f.a,
  33441. g = h.a;
  33442. if (0 === x(e.b.a, d, e.a))
  33443. (e = f.a),
  33444. t(e.a, d) ||
  33445. t(e.b.a, d) ||
  33446. (K(e.b), f.c && (I(e.c), (f.c = !1)), E(d.c, e), ya(c, d));
  33447. else {
  33448. var k = u(g.b.a, e.b.a) ? f : h,
  33449. h = void 0;
  33450. f.d || k.c
  33451. ? (k === f ? (h = L(d.c.b, e.e)) : (h = L(g.b.c.b, d.c).b),
  33452. k.c
  33453. ? ja(k, h)
  33454. : ((e = c),
  33455. (f = la(c, f, h)),
  33456. (f.f = R(f).f + f.a.f),
  33457. (f.d = oa(e, f.f))),
  33458. ya(c, d))
  33459. : U(c, f, d.c, d.c, null, !0);
  33460. }
  33461. return;
  33462. }
  33463. c = ka(c.i);
  33464. e = S(c);
  33465. f = e.a;
  33466. e = T(a, e, null);
  33467. if (e.c === f) {
  33468. var f = e,
  33469. e = f.c,
  33470. g = S(c),
  33471. h = c.a,
  33472. k = g.a,
  33473. l = !1;
  33474. h.b.a !== k.b.a && wa(a, c);
  33475. t(h.a, a.a) &&
  33476. (E(J(e), h), (c = ka(c)), (e = S(c).a), T(a, S(c), g), (l = !0));
  33477. t(k.a, a.a) && (E(f, J(k)), (f = T(a, g, null)), (l = !0));
  33478. l
  33479. ? U(a, c, f.c, e, e, !0)
  33480. : (u(k.a, h.a) ? (d = J(k)) : (d = h),
  33481. (d = L(f.c.b, d)),
  33482. U(a, c, d, d.c, d.c, !1),
  33483. (d.b.i.c = !0),
  33484. ra(a, c));
  33485. } else U(a, c, e.c, f, f, !0);
  33486. }
  33487. function za(a, b) {
  33488. var c = new ma(),
  33489. d = ea(a.b);
  33490. d.a.b = O;
  33491. d.a.a = b;
  33492. d.b.a.b = -O;
  33493. d.b.a.a = b;
  33494. a.a = d.b.a;
  33495. c.a = d;
  33496. c.f = 0;
  33497. c.d = !1;
  33498. c.c = !1;
  33499. c.h = !0;
  33500. c.b = !1;
  33501. d = a.f;
  33502. d = na(d, d.a, c);
  33503. c.e = d;
  33504. }
  33505. function Aa(a) {
  33506. this.a = new Ba();
  33507. this.b = a;
  33508. this.c = ia;
  33509. }
  33510. function na(a, b, c) {
  33511. do b = b.c;
  33512. while (null !== b.b && !a.c(a.b, b.b, c));
  33513. a = new Ba(c, b.a, b);
  33514. b.a.c = a;
  33515. return (b.a = a);
  33516. }
  33517. function Ba(a, b, c) {
  33518. this.b = a || null;
  33519. this.a = b || this;
  33520. this.c = c || this;
  33521. }
  33522. function X() {
  33523. this.d = Y;
  33524. this.p = this.b = this.q = null;
  33525. this.j = [0, 0, 0];
  33526. this.s = 100130;
  33527. this.n = !1;
  33528. this.o = this.a = this.e = this.f = null;
  33529. this.m = !1;
  33530. this.c = this.r = this.i = this.k = this.l = this.h = null;
  33531. }
  33532. var Y = 0;
  33533. n = X.prototype;
  33534. n.x = function() {
  33535. Z(this, Y);
  33536. };
  33537. n.B = function(a, b) {
  33538. switch (a) {
  33539. case 100142:
  33540. return;
  33541. case 100140:
  33542. switch (b) {
  33543. case 100130:
  33544. case 100131:
  33545. case 100132:
  33546. case 100133:
  33547. case 100134:
  33548. this.s = b;
  33549. return;
  33550. }
  33551. break;
  33552. case 100141:
  33553. this.m = !!b;
  33554. return;
  33555. default:
  33556. V(this, 100900);
  33557. return;
  33558. }
  33559. V(this, 100901);
  33560. };
  33561. n.y = function(a) {
  33562. switch (a) {
  33563. case 100142:
  33564. return 0;
  33565. case 100140:
  33566. return this.s;
  33567. case 100141:
  33568. return this.m;
  33569. default:
  33570. V(this, 100900);
  33571. }
  33572. return !1;
  33573. };
  33574. n.A = function(a, b, c) {
  33575. this.j[0] = a;
  33576. this.j[1] = b;
  33577. this.j[2] = c;
  33578. };
  33579. n.z = function(a, b) {
  33580. var c = b ? b : null;
  33581. switch (a) {
  33582. case 100100:
  33583. case 100106:
  33584. this.h = c;
  33585. break;
  33586. case 100104:
  33587. case 100110:
  33588. this.l = c;
  33589. break;
  33590. case 100101:
  33591. case 100107:
  33592. this.k = c;
  33593. break;
  33594. case 100102:
  33595. case 100108:
  33596. this.i = c;
  33597. break;
  33598. case 100103:
  33599. case 100109:
  33600. this.p = c;
  33601. break;
  33602. case 100105:
  33603. case 100111:
  33604. this.o = c;
  33605. break;
  33606. case 100112:
  33607. this.r = c;
  33608. break;
  33609. default:
  33610. V(this, 100900);
  33611. }
  33612. };
  33613. n.C = function(a, b) {
  33614. var c = !1,
  33615. d = [0, 0, 0];
  33616. Z(this, 2);
  33617. for (var e = 0; 3 > e; ++e) {
  33618. var f = a[e];
  33619. -1e150 > f && ((f = -1e150), (c = !0));
  33620. 1e150 < f && ((f = 1e150), (c = !0));
  33621. d[e] = f;
  33622. }
  33623. c && V(this, 100155);
  33624. c = this.q;
  33625. null === c ? ((c = ea(this.b)), E(c, c.b)) : (K(c), (c = c.e));
  33626. c.a.d = b;
  33627. c.a.g[0] = d[0];
  33628. c.a.g[1] = d[1];
  33629. c.a.g[2] = d[2];
  33630. c.f = 1;
  33631. c.b.f = -1;
  33632. this.q = c;
  33633. };
  33634. n.u = function(a) {
  33635. Z(this, Y);
  33636. this.d = 1;
  33637. this.b = new Ca();
  33638. this.c = a;
  33639. };
  33640. n.t = function() {
  33641. Z(this, 1);
  33642. this.d = 2;
  33643. this.q = null;
  33644. };
  33645. n.v = function() {
  33646. Z(this, 2);
  33647. this.d = 1;
  33648. };
  33649. n.w = function() {
  33650. Z(this, 1);
  33651. this.d = Y;
  33652. var a = this.j[0],
  33653. b = this.j[1],
  33654. c = this.j[2],
  33655. d = !1,
  33656. e = [a, b, c];
  33657. if (0 === a && 0 === b && 0 === c) {
  33658. for (
  33659. var b = [-2 * 1e150, -2 * 1e150, -2 * 1e150],
  33660. f = [2 * 1e150, 2 * 1e150, 2 * 1e150],
  33661. c = [],
  33662. g = [],
  33663. d = this.b.c,
  33664. a = d.e;
  33665. a !== d;
  33666. a = a.e
  33667. )
  33668. for (var h = 0; 3 > h; ++h) {
  33669. var k = a.g[h];
  33670. k < f[h] && ((f[h] = k), (g[h] = a));
  33671. k > b[h] && ((b[h] = k), (c[h] = a));
  33672. }
  33673. a = 0;
  33674. b[1] - f[1] > b[0] - f[0] && (a = 1);
  33675. b[2] - f[2] > b[a] - f[a] && (a = 2);
  33676. if (f[a] >= b[a]) (e[0] = 0), (e[1] = 0), (e[2] = 1);
  33677. else {
  33678. b = 0;
  33679. f = g[a];
  33680. c = c[a];
  33681. g = [0, 0, 0];
  33682. f = [f.g[0] - c.g[0], f.g[1] - c.g[1], f.g[2] - c.g[2]];
  33683. h = [0, 0, 0];
  33684. for (a = d.e; a !== d; a = a.e)
  33685. (h[0] = a.g[0] - c.g[0]),
  33686. (h[1] = a.g[1] - c.g[1]),
  33687. (h[2] = a.g[2] - c.g[2]),
  33688. (g[0] = f[1] * h[2] - f[2] * h[1]),
  33689. (g[1] = f[2] * h[0] - f[0] * h[2]),
  33690. (g[2] = f[0] * h[1] - f[1] * h[0]),
  33691. (k = g[0] * g[0] + g[1] * g[1] + g[2] * g[2]),
  33692. k > b && ((b = k), (e[0] = g[0]), (e[1] = g[1]), (e[2] = g[2]));
  33693. 0 >= b && ((e[0] = e[1] = e[2] = 0), (e[ha(f)] = 1));
  33694. }
  33695. d = !0;
  33696. }
  33697. g = ha(e);
  33698. a = this.b.c;
  33699. b = (g + 1) % 3;
  33700. c = (g + 2) % 3;
  33701. g = 0 < e[g] ? 1 : -1;
  33702. for (e = a.e; e !== a; e = e.e) (e.b = e.g[b]), (e.a = g * e.g[c]);
  33703. if (d) {
  33704. e = 0;
  33705. d = this.b.a;
  33706. for (a = d.b; a !== d; a = a.b)
  33707. if (((b = a.a), !(0 >= b.f))) {
  33708. do (e += (b.a.b - b.b.a.b) * (b.a.a + b.b.a.a)), (b = b.e);
  33709. while (b !== a.a);
  33710. }
  33711. if (0 > e) for (e = this.b.c, d = e.e; d !== e; d = d.e) d.a = -d.a;
  33712. }
  33713. this.n = !1;
  33714. e = this.b.b;
  33715. for (a = e.h; a !== e; a = d)
  33716. if (
  33717. ((d = a.h),
  33718. (b = a.e),
  33719. t(a.a, a.b.a) && a.e.e !== a && (ta(this, b, a), I(a), (a = b), (b = a.e)),
  33720. b.e === a)
  33721. ) {
  33722. if (b !== a) {
  33723. if (b === d || b === d.b) d = d.h;
  33724. I(b);
  33725. }
  33726. if (a === d || a === d.b) d = d.h;
  33727. I(a);
  33728. }
  33729. this.e = e = new Da();
  33730. d = this.b.c;
  33731. for (a = d.e; a !== d; a = a.e) a.h = xa(e, a);
  33732. Ea(e);
  33733. this.f = new Aa(this);
  33734. za(this, -O);
  33735. for (za(this, O); null !== (e = Fa(this.e)); ) {
  33736. for (;;) {
  33737. a: if (((a = this.e), 0 === a.a)) d = Ga(a.b);
  33738. else if (
  33739. ((d = a.c[a.d[a.a - 1]]), 0 !== a.b.a && ((a = Ga(a.b)), u(a, d)))
  33740. ) {
  33741. d = a;
  33742. break a;
  33743. }
  33744. if (null === d || !t(d, e)) break;
  33745. d = Fa(this.e);
  33746. ta(this, e.c, d.c);
  33747. }
  33748. ya(this, e);
  33749. }
  33750. this.a = this.f.a.a.b.a.a;
  33751. for (e = 0; null !== (d = this.f.a.a.b); ) d.h || ++e, Q(d);
  33752. this.f = null;
  33753. e = this.e;
  33754. e.b = null;
  33755. e.d = null;
  33756. this.e = e.c = null;
  33757. e = this.b;
  33758. for (a = e.a.b; a !== e.a; a = d)
  33759. (d = a.b), (a = a.a), a.e.e === a && (P(a.c, a), I(a));
  33760. if (!this.n) {
  33761. e = this.b;
  33762. if (this.m)
  33763. for (a = e.b.h; a !== e.b; a = d)
  33764. (d = a.h), a.b.d.c !== a.d.c ? (a.f = a.d.c ? 1 : -1) : I(a);
  33765. else
  33766. for (a = e.a.b; a !== e.a; a = d)
  33767. if (((d = a.b), a.c)) {
  33768. for (a = a.a; u(a.b.a, a.a); a = a.c.b);
  33769. for (; u(a.a, a.b.a); a = a.e);
  33770. b = a.c.b;
  33771. for (c = void 0; a.e !== b; )
  33772. if (u(a.b.a, b.a)) {
  33773. for (; b.e !== a && (ca(b.e) || 0 >= x(b.a, b.b.a, b.e.b.a)); )
  33774. (c = L(b.e, b)), (b = c.b);
  33775. b = b.c.b;
  33776. } else {
  33777. for (; b.e !== a && (da(a.c.b) || 0 <= x(a.b.a, a.a, a.c.b.a)); )
  33778. (c = L(a, a.c.b)), (a = c.b);
  33779. a = a.e;
  33780. }
  33781. for (; b.e.e !== a; ) (c = L(b.e, b)), (b = c.b);
  33782. }
  33783. if (this.h || this.i || this.k || this.l)
  33784. if (this.m)
  33785. for (e = this.b, d = e.a.b; d !== e.a; d = d.b) {
  33786. if (d.c) {
  33787. this.h && this.h(2, this.c);
  33788. a = d.a;
  33789. do this.k && this.k(a.a.d, this.c), (a = a.e);
  33790. while (a !== d.a);
  33791. this.i && this.i(this.c);
  33792. }
  33793. }
  33794. else {
  33795. e = this.b;
  33796. d = !!this.l;
  33797. a = !1;
  33798. b = -1;
  33799. for (c = e.a.d; c !== e.a; c = c.d)
  33800. if (c.c) {
  33801. a || (this.h && this.h(4, this.c), (a = !0));
  33802. g = c.a;
  33803. do
  33804. d &&
  33805. ((f = g.b.d.c ? 0 : 1),
  33806. b !== f && ((b = f), this.l && this.l(!!b, this.c))),
  33807. this.k && this.k(g.a.d, this.c),
  33808. (g = g.e);
  33809. while (g !== c.a);
  33810. }
  33811. a && this.i && this.i(this.c);
  33812. }
  33813. if (this.r) {
  33814. e = this.b;
  33815. for (a = e.a.b; a !== e.a; a = d)
  33816. if (((d = a.b), !a.c)) {
  33817. b = a.a;
  33818. c = b.e;
  33819. g = void 0;
  33820. do
  33821. (g = c),
  33822. (c = g.e),
  33823. (g.d = null),
  33824. null === g.b.d &&
  33825. (g.c === g ? F(g.a, null) : ((g.a.c = g.c), H(g, J(g))),
  33826. (f = g.b),
  33827. f.c === f ? F(f.a, null) : ((f.a.c = f.c), H(f, J(f))),
  33828. fa(g));
  33829. while (g !== b);
  33830. b = a.d;
  33831. a = a.b;
  33832. a.d = b;
  33833. b.b = a;
  33834. }
  33835. this.r(this.b);
  33836. this.c = this.b = null;
  33837. return;
  33838. }
  33839. }
  33840. this.b = this.c = null;
  33841. };
  33842. function Z(a, b) {
  33843. if (a.d !== b)
  33844. for (; a.d !== b; )
  33845. if (a.d < b)
  33846. switch (a.d) {
  33847. case Y:
  33848. V(a, 100151);
  33849. a.u(null);
  33850. break;
  33851. case 1:
  33852. V(a, 100152), a.t();
  33853. }
  33854. else
  33855. switch (a.d) {
  33856. case 2:
  33857. V(a, 100154);
  33858. a.v();
  33859. break;
  33860. case 1:
  33861. V(a, 100153), a.w();
  33862. }
  33863. }
  33864. function V(a, b) {
  33865. a.p && a.p(b, a.c);
  33866. }
  33867. function ga(a, b) {
  33868. this.b = a || this;
  33869. this.d = b || this;
  33870. this.a = null;
  33871. this.c = !1;
  33872. }
  33873. function M() {
  33874. this.h = this;
  33875. this.i = this.d = this.a = this.e = this.c = this.b = null;
  33876. this.f = 0;
  33877. }
  33878. function J(a) {
  33879. return a.b.e;
  33880. }
  33881. function Ca() {
  33882. this.c = new N();
  33883. this.a = new ga();
  33884. this.b = new M();
  33885. this.d = new M();
  33886. this.b.b = this.d;
  33887. this.d.b = this.b;
  33888. }
  33889. function N(a, b) {
  33890. this.e = a || this;
  33891. this.f = b || this;
  33892. this.d = this.c = null;
  33893. this.g = [0, 0, 0];
  33894. this.h = this.a = this.b = 0;
  33895. }
  33896. function Da() {
  33897. this.c = [];
  33898. this.d = null;
  33899. this.a = 0;
  33900. this.e = !1;
  33901. this.b = new Ha();
  33902. }
  33903. function Ea(a) {
  33904. a.d = [];
  33905. for (var b = 0; b < a.a; b++) a.d[b] = b;
  33906. a.d.sort(
  33907. (function(a) {
  33908. return function(b, e) {
  33909. return u(a[b], a[e]) ? 1 : -1;
  33910. };
  33911. })(a.c)
  33912. );
  33913. a.e = !0;
  33914. Ia(a.b);
  33915. }
  33916. function xa(a, b) {
  33917. if (a.e) {
  33918. var c = a.b,
  33919. d = ++c.a;
  33920. 2 * d > c.f && ((c.f *= 2), (c.c = Ja(c.c, c.f + 1)));
  33921. var e;
  33922. 0 === c.b ? (e = d) : ((e = c.b), (c.b = c.c[c.b]));
  33923. c.e[e] = b;
  33924. c.c[e] = d;
  33925. c.d[d] = e;
  33926. c.h && va(c, d);
  33927. return e;
  33928. }
  33929. c = a.a++;
  33930. a.c[c] = b;
  33931. return -(c + 1);
  33932. }
  33933. function Fa(a) {
  33934. if (0 === a.a) return Ka(a.b);
  33935. var b = a.c[a.d[a.a - 1]];
  33936. if (0 !== a.b.a && u(Ga(a.b), b)) return Ka(a.b);
  33937. do --a.a;
  33938. while (0 < a.a && null === a.c[a.d[a.a - 1]]);
  33939. return b;
  33940. }
  33941. function Ha() {
  33942. this.d = Ja([0], 33);
  33943. this.e = [null, null];
  33944. this.c = [0, 0];
  33945. this.a = 0;
  33946. this.f = 32;
  33947. this.b = 0;
  33948. this.h = !1;
  33949. this.d[1] = 1;
  33950. }
  33951. function Ja(a, b) {
  33952. for (var c = Array(b), d = 0; d < a.length; d++) c[d] = a[d];
  33953. for (; d < b; d++) c[d] = 0;
  33954. return c;
  33955. }
  33956. function Ia(a) {
  33957. for (var b = a.a; 1 <= b; --b) W(a, b);
  33958. a.h = !0;
  33959. }
  33960. function Ga(a) {
  33961. return a.e[a.d[1]];
  33962. }
  33963. function Ka(a) {
  33964. var b = a.d,
  33965. c = a.e,
  33966. d = a.c,
  33967. e = b[1],
  33968. f = c[e];
  33969. 0 < a.a &&
  33970. ((b[1] = b[a.a]),
  33971. (d[b[1]] = 1),
  33972. (c[e] = null),
  33973. (d[e] = a.b),
  33974. (a.b = e),
  33975. 0 < --a.a && W(a, 1));
  33976. return f;
  33977. }
  33978. function W(a, b) {
  33979. for (var c = a.d, d = a.e, e = a.c, f = b, g = c[f]; ; ) {
  33980. var h = f << 1;
  33981. h < a.a && u(d[c[h + 1]], d[c[h]]) && (h += 1);
  33982. var k = c[h];
  33983. if (h > a.a || u(d[g], d[k])) {
  33984. c[f] = g;
  33985. e[g] = f;
  33986. break;
  33987. }
  33988. c[f] = k;
  33989. e[k] = f;
  33990. f = h;
  33991. }
  33992. }
  33993. function va(a, b) {
  33994. for (var c = a.d, d = a.e, e = a.c, f = b, g = c[f]; ; ) {
  33995. var h = f >> 1,
  33996. k = c[h];
  33997. if (0 === h || u(d[k], d[g])) {
  33998. c[f] = g;
  33999. e[g] = f;
  34000. break;
  34001. }
  34002. c[f] = k;
  34003. e[k] = f;
  34004. f = h;
  34005. }
  34006. }
  34007. function ma() {
  34008. this.e = this.a = null;
  34009. this.f = 0;
  34010. this.c = this.b = this.h = this.d = !1;
  34011. }
  34012. function S(a) {
  34013. return a.e.c.b;
  34014. }
  34015. function R(a) {
  34016. return a.e.a.b;
  34017. }
  34018. this.libtess = {
  34019. GluTesselator: X,
  34020. windingRule: {
  34021. GLU_TESS_WINDING_ODD: 100130,
  34022. GLU_TESS_WINDING_NONZERO: 100131,
  34023. GLU_TESS_WINDING_POSITIVE: 100132,
  34024. GLU_TESS_WINDING_NEGATIVE: 100133,
  34025. GLU_TESS_WINDING_ABS_GEQ_TWO: 100134
  34026. },
  34027. primitiveType: {
  34028. GL_LINE_LOOP: 2,
  34029. GL_TRIANGLES: 4,
  34030. GL_TRIANGLE_STRIP: 5,
  34031. GL_TRIANGLE_FAN: 6
  34032. },
  34033. errorType: {
  34034. GLU_TESS_MISSING_BEGIN_POLYGON: 100151,
  34035. GLU_TESS_MISSING_END_POLYGON: 100153,
  34036. GLU_TESS_MISSING_BEGIN_CONTOUR: 100152,
  34037. GLU_TESS_MISSING_END_CONTOUR: 100154,
  34038. GLU_TESS_COORD_TOO_LARGE: 100155,
  34039. GLU_TESS_NEED_COMBINE_CALLBACK: 100156
  34040. },
  34041. gluEnum: {
  34042. GLU_TESS_MESH: 100112,
  34043. GLU_TESS_TOLERANCE: 100142,
  34044. GLU_TESS_WINDING_RULE: 100140,
  34045. GLU_TESS_BOUNDARY_ONLY: 100141,
  34046. GLU_INVALID_ENUM: 100900,
  34047. GLU_INVALID_VALUE: 100901,
  34048. GLU_TESS_BEGIN: 100100,
  34049. GLU_TESS_VERTEX: 100101,
  34050. GLU_TESS_END: 100102,
  34051. GLU_TESS_ERROR: 100103,
  34052. GLU_TESS_EDGE_FLAG: 100104,
  34053. GLU_TESS_COMBINE: 100105,
  34054. GLU_TESS_BEGIN_DATA: 100106,
  34055. GLU_TESS_VERTEX_DATA: 100107,
  34056. GLU_TESS_END_DATA: 100108,
  34057. GLU_TESS_ERROR_DATA: 100109,
  34058. GLU_TESS_EDGE_FLAG_DATA: 100110,
  34059. GLU_TESS_COMBINE_DATA: 100111
  34060. }
  34061. };
  34062. X.prototype.gluDeleteTess = X.prototype.x;
  34063. X.prototype.gluTessProperty = X.prototype.B;
  34064. X.prototype.gluGetTessProperty = X.prototype.y;
  34065. X.prototype.gluTessNormal = X.prototype.A;
  34066. X.prototype.gluTessCallback = X.prototype.z;
  34067. X.prototype.gluTessVertex = X.prototype.C;
  34068. X.prototype.gluTessBeginPolygon = X.prototype.u;
  34069. X.prototype.gluTessBeginContour = X.prototype.t;
  34070. X.prototype.gluTessEndContour = X.prototype.v;
  34071. X.prototype.gluTessEndPolygon = X.prototype.w;
  34072. if (typeof module !== 'undefined') {
  34073. module.exports = this.libtess;
  34074. }
  34075. },
  34076. {}
  34077. ],
  34078. 257: [
  34079. function(_dereq_, module, exports) {
  34080. // (c) Dean McNamee <dean@gmail.com>, 2013.
  34081. //
  34082. // https://github.com/deanm/omggif
  34083. //
  34084. // Permission is hereby granted, free of charge, to any person obtaining a copy
  34085. // of this software and associated documentation files (the "Software"), to
  34086. // deal in the Software without restriction, including without limitation the
  34087. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  34088. // sell copies of the Software, and to permit persons to whom the Software is
  34089. // furnished to do so, subject to the following conditions:
  34090. //
  34091. // The above copyright notice and this permission notice shall be included in
  34092. // all copies or substantial portions of the Software.
  34093. //
  34094. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  34095. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  34096. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  34097. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  34098. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  34099. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  34100. // IN THE SOFTWARE.
  34101. //
  34102. // omggif is a JavaScript implementation of a GIF 89a encoder and decoder,
  34103. // including animation and compression. It does not rely on any specific
  34104. // underlying system, so should run in the browser, Node, or Plask.
  34105. 'use strict';
  34106. function GifWriter(buf, width, height, gopts) {
  34107. var p = 0;
  34108. var gopts = gopts === undefined ? {} : gopts;
  34109. var loop_count = gopts.loop === undefined ? null : gopts.loop;
  34110. var global_palette = gopts.palette === undefined ? null : gopts.palette;
  34111. if (width <= 0 || height <= 0 || width > 65535 || height > 65535)
  34112. throw new Error('Width/Height invalid.');
  34113. function check_palette_and_num_colors(palette) {
  34114. var num_colors = palette.length;
  34115. if (num_colors < 2 || num_colors > 256 || num_colors & (num_colors - 1)) {
  34116. throw new Error(
  34117. 'Invalid code/color length, must be power of 2 and 2 .. 256.'
  34118. );
  34119. }
  34120. return num_colors;
  34121. }
  34122. // - Header.
  34123. buf[p++] = 0x47;
  34124. buf[p++] = 0x49;
  34125. buf[p++] = 0x46; // GIF
  34126. buf[p++] = 0x38;
  34127. buf[p++] = 0x39;
  34128. buf[p++] = 0x61; // 89a
  34129. // Handling of Global Color Table (palette) and background index.
  34130. var gp_num_colors_pow2 = 0;
  34131. var background = 0;
  34132. if (global_palette !== null) {
  34133. var gp_num_colors = check_palette_and_num_colors(global_palette);
  34134. while ((gp_num_colors >>= 1)) ++gp_num_colors_pow2;
  34135. gp_num_colors = 1 << gp_num_colors_pow2;
  34136. --gp_num_colors_pow2;
  34137. if (gopts.background !== undefined) {
  34138. background = gopts.background;
  34139. if (background >= gp_num_colors)
  34140. throw new Error('Background index out of range.');
  34141. // The GIF spec states that a background index of 0 should be ignored, so
  34142. // this is probably a mistake and you really want to set it to another
  34143. // slot in the palette. But actually in the end most browsers, etc end
  34144. // up ignoring this almost completely (including for dispose background).
  34145. if (background === 0)
  34146. throw new Error('Background index explicitly passed as 0.');
  34147. }
  34148. }
  34149. // - Logical Screen Descriptor.
  34150. // NOTE(deanm): w/h apparently ignored by implementations, but set anyway.
  34151. buf[p++] = width & 0xff;
  34152. buf[p++] = (width >> 8) & 0xff;
  34153. buf[p++] = height & 0xff;
  34154. buf[p++] = (height >> 8) & 0xff;
  34155. // NOTE: Indicates 0-bpp original color resolution (unused?).
  34156. buf[p++] =
  34157. (global_palette !== null ? 0x80 : 0) | gp_num_colors_pow2; // Global Color Table Flag. // NOTE: No sort flag (unused?).
  34158. buf[p++] = background; // Background Color Index.
  34159. buf[p++] = 0; // Pixel aspect ratio (unused?).
  34160. // - Global Color Table
  34161. if (global_palette !== null) {
  34162. for (var i = 0, il = global_palette.length; i < il; ++i) {
  34163. var rgb = global_palette[i];
  34164. buf[p++] = (rgb >> 16) & 0xff;
  34165. buf[p++] = (rgb >> 8) & 0xff;
  34166. buf[p++] = rgb & 0xff;
  34167. }
  34168. }
  34169. if (loop_count !== null) {
  34170. // Netscape block for looping.
  34171. if (loop_count < 0 || loop_count > 65535)
  34172. throw new Error('Loop count invalid.');
  34173. // Extension code, label, and length.
  34174. buf[p++] = 0x21;
  34175. buf[p++] = 0xff;
  34176. buf[p++] = 0x0b;
  34177. // NETSCAPE2.0
  34178. buf[p++] = 0x4e;
  34179. buf[p++] = 0x45;
  34180. buf[p++] = 0x54;
  34181. buf[p++] = 0x53;
  34182. buf[p++] = 0x43;
  34183. buf[p++] = 0x41;
  34184. buf[p++] = 0x50;
  34185. buf[p++] = 0x45;
  34186. buf[p++] = 0x32;
  34187. buf[p++] = 0x2e;
  34188. buf[p++] = 0x30;
  34189. // Sub-block
  34190. buf[p++] = 0x03;
  34191. buf[p++] = 0x01;
  34192. buf[p++] = loop_count & 0xff;
  34193. buf[p++] = (loop_count >> 8) & 0xff;
  34194. buf[p++] = 0x00; // Terminator.
  34195. }
  34196. var ended = false;
  34197. this.addFrame = function(x, y, w, h, indexed_pixels, opts) {
  34198. if (ended === true) {
  34199. --p;
  34200. ended = false;
  34201. } // Un-end.
  34202. opts = opts === undefined ? {} : opts;
  34203. // TODO(deanm): Bounds check x, y. Do they need to be within the virtual
  34204. // canvas width/height, I imagine?
  34205. if (x < 0 || y < 0 || x > 65535 || y > 65535) throw new Error('x/y invalid.');
  34206. if (w <= 0 || h <= 0 || w > 65535 || h > 65535)
  34207. throw new Error('Width/Height invalid.');
  34208. if (indexed_pixels.length < w * h)
  34209. throw new Error('Not enough pixels for the frame size.');
  34210. var using_local_palette = true;
  34211. var palette = opts.palette;
  34212. if (palette === undefined || palette === null) {
  34213. using_local_palette = false;
  34214. palette = global_palette;
  34215. }
  34216. if (palette === undefined || palette === null)
  34217. throw new Error('Must supply either a local or global palette.');
  34218. var num_colors = check_palette_and_num_colors(palette);
  34219. // Compute the min_code_size (power of 2), destroying num_colors.
  34220. var min_code_size = 0;
  34221. while ((num_colors >>= 1)) ++min_code_size;
  34222. num_colors = 1 << min_code_size; // Now we can easily get it back.
  34223. var delay = opts.delay === undefined ? 0 : opts.delay;
  34224. // From the spec:
  34225. // 0 - No disposal specified. The decoder is
  34226. // not required to take any action.
  34227. // 1 - Do not dispose. The graphic is to be left
  34228. // in place.
  34229. // 2 - Restore to background color. The area used by the
  34230. // graphic must be restored to the background color.
  34231. // 3 - Restore to previous. The decoder is required to
  34232. // restore the area overwritten by the graphic with
  34233. // what was there prior to rendering the graphic.
  34234. // 4-7 - To be defined.
  34235. // NOTE(deanm): Dispose background doesn't really work, apparently most
  34236. // browsers ignore the background palette index and clear to transparency.
  34237. var disposal = opts.disposal === undefined ? 0 : opts.disposal;
  34238. if (disposal < 0 || disposal > 3)
  34239. // 4-7 is reserved.
  34240. throw new Error('Disposal out of range.');
  34241. var use_transparency = false;
  34242. var transparent_index = 0;
  34243. if (opts.transparent !== undefined && opts.transparent !== null) {
  34244. use_transparency = true;
  34245. transparent_index = opts.transparent;
  34246. if (transparent_index < 0 || transparent_index >= num_colors)
  34247. throw new Error('Transparent color index.');
  34248. }
  34249. if (disposal !== 0 || use_transparency || delay !== 0) {
  34250. // - Graphics Control Extension
  34251. buf[p++] = 0x21;
  34252. buf[p++] = 0xf9; // Extension / Label.
  34253. buf[p++] = 4; // Byte size.
  34254. buf[p++] = (disposal << 2) | (use_transparency === true ? 1 : 0);
  34255. buf[p++] = delay & 0xff;
  34256. buf[p++] = (delay >> 8) & 0xff;
  34257. buf[p++] = transparent_index; // Transparent color index.
  34258. buf[p++] = 0; // Block Terminator.
  34259. }
  34260. // - Image Descriptor
  34261. buf[p++] = 0x2c; // Image Seperator.
  34262. buf[p++] = x & 0xff;
  34263. buf[p++] = (x >> 8) & 0xff; // Left.
  34264. buf[p++] = y & 0xff;
  34265. buf[p++] = (y >> 8) & 0xff; // Top.
  34266. buf[p++] = w & 0xff;
  34267. buf[p++] = (w >> 8) & 0xff;
  34268. buf[p++] = h & 0xff;
  34269. buf[p++] = (h >> 8) & 0xff;
  34270. // NOTE: No sort flag (unused?).
  34271. // TODO(deanm): Support interlace.
  34272. buf[p++] = using_local_palette === true ? 0x80 | (min_code_size - 1) : 0;
  34273. // - Local Color Table
  34274. if (using_local_palette === true) {
  34275. for (var i = 0, il = palette.length; i < il; ++i) {
  34276. var rgb = palette[i];
  34277. buf[p++] = (rgb >> 16) & 0xff;
  34278. buf[p++] = (rgb >> 8) & 0xff;
  34279. buf[p++] = rgb & 0xff;
  34280. }
  34281. }
  34282. p = GifWriterOutputLZWCodeStream(
  34283. buf,
  34284. p,
  34285. min_code_size < 2 ? 2 : min_code_size,
  34286. indexed_pixels
  34287. );
  34288. return p;
  34289. };
  34290. this.end = function() {
  34291. if (ended === false) {
  34292. buf[p++] = 0x3b; // Trailer.
  34293. ended = true;
  34294. }
  34295. return p;
  34296. };
  34297. this.getOutputBuffer = function() {
  34298. return buf;
  34299. };
  34300. this.setOutputBuffer = function(v) {
  34301. buf = v;
  34302. };
  34303. this.getOutputBufferPosition = function() {
  34304. return p;
  34305. };
  34306. this.setOutputBufferPosition = function(v) {
  34307. p = v;
  34308. };
  34309. }
  34310. // Main compression routine, palette indexes -> LZW code stream.
  34311. // |index_stream| must have at least one entry.
  34312. function GifWriterOutputLZWCodeStream(buf, p, min_code_size, index_stream) {
  34313. buf[p++] = min_code_size;
  34314. var cur_subblock = p++; // Pointing at the length field.
  34315. var clear_code = 1 << min_code_size;
  34316. var code_mask = clear_code - 1;
  34317. var eoi_code = clear_code + 1;
  34318. var next_code = eoi_code + 1;
  34319. var cur_code_size = min_code_size + 1; // Number of bits per code.
  34320. var cur_shift = 0;
  34321. // We have at most 12-bit codes, so we should have to hold a max of 19
  34322. // bits here (and then we would write out).
  34323. var cur = 0;
  34324. function emit_bytes_to_buffer(bit_block_size) {
  34325. while (cur_shift >= bit_block_size) {
  34326. buf[p++] = cur & 0xff;
  34327. cur >>= 8;
  34328. cur_shift -= 8;
  34329. if (p === cur_subblock + 256) {
  34330. // Finished a subblock.
  34331. buf[cur_subblock] = 255;
  34332. cur_subblock = p++;
  34333. }
  34334. }
  34335. }
  34336. function emit_code(c) {
  34337. cur |= c << cur_shift;
  34338. cur_shift += cur_code_size;
  34339. emit_bytes_to_buffer(8);
  34340. }
  34341. // I am not an expert on the topic, and I don't want to write a thesis.
  34342. // However, it is good to outline here the basic algorithm and the few data
  34343. // structures and optimizations here that make this implementation fast.
  34344. // The basic idea behind LZW is to build a table of previously seen runs
  34345. // addressed by a short id (herein called output code). All data is
  34346. // referenced by a code, which represents one or more values from the
  34347. // original input stream. All input bytes can be referenced as the same
  34348. // value as an output code. So if you didn't want any compression, you
  34349. // could more or less just output the original bytes as codes (there are
  34350. // some details to this, but it is the idea). In order to achieve
  34351. // compression, values greater then the input range (codes can be up to
  34352. // 12-bit while input only 8-bit) represent a sequence of previously seen
  34353. // inputs. The decompressor is able to build the same mapping while
  34354. // decoding, so there is always a shared common knowledge between the
  34355. // encoding and decoder, which is also important for "timing" aspects like
  34356. // how to handle variable bit width code encoding.
  34357. //
  34358. // One obvious but very important consequence of the table system is there
  34359. // is always a unique id (at most 12-bits) to map the runs. 'A' might be
  34360. // 4, then 'AA' might be 10, 'AAA' 11, 'AAAA' 12, etc. This relationship
  34361. // can be used for an effecient lookup strategy for the code mapping. We
  34362. // need to know if a run has been seen before, and be able to map that run
  34363. // to the output code. Since we start with known unique ids (input bytes),
  34364. // and then from those build more unique ids (table entries), we can
  34365. // continue this chain (almost like a linked list) to always have small
  34366. // integer values that represent the current byte chains in the encoder.
  34367. // This means instead of tracking the input bytes (AAAABCD) to know our
  34368. // current state, we can track the table entry for AAAABC (it is guaranteed
  34369. // to exist by the nature of the algorithm) and the next character D.
  34370. // Therefor the tuple of (table_entry, byte) is guaranteed to also be
  34371. // unique. This allows us to create a simple lookup key for mapping input
  34372. // sequences to codes (table indices) without having to store or search
  34373. // any of the code sequences. So if 'AAAA' has a table entry of 12, the
  34374. // tuple of ('AAAA', K) for any input byte K will be unique, and can be our
  34375. // key. This leads to a integer value at most 20-bits, which can always
  34376. // fit in an SMI value and be used as a fast sparse array / object key.
  34377. // Output code for the current contents of the index buffer.
  34378. var ib_code = index_stream[0] & code_mask; // Load first input index.
  34379. var code_table = {}; // Key'd on our 20-bit "tuple".
  34380. emit_code(clear_code); // Spec says first code should be a clear code.
  34381. // First index already loaded, process the rest of the stream.
  34382. for (var i = 1, il = index_stream.length; i < il; ++i) {
  34383. var k = index_stream[i] & code_mask;
  34384. var cur_key = (ib_code << 8) | k; // (prev, k) unique tuple.
  34385. var cur_code = code_table[cur_key]; // buffer + k.
  34386. // Check if we have to create a new code table entry.
  34387. if (cur_code === undefined) {
  34388. // We don't have buffer + k.
  34389. // Emit index buffer (without k).
  34390. // This is an inline version of emit_code, because this is the core
  34391. // writing routine of the compressor (and V8 cannot inline emit_code
  34392. // because it is a closure here in a different context). Additionally
  34393. // we can call emit_byte_to_buffer less often, because we can have
  34394. // 30-bits (from our 31-bit signed SMI), and we know our codes will only
  34395. // be 12-bits, so can safely have 18-bits there without overflow.
  34396. // emit_code(ib_code);
  34397. cur |= ib_code << cur_shift;
  34398. cur_shift += cur_code_size;
  34399. while (cur_shift >= 8) {
  34400. buf[p++] = cur & 0xff;
  34401. cur >>= 8;
  34402. cur_shift -= 8;
  34403. if (p === cur_subblock + 256) {
  34404. // Finished a subblock.
  34405. buf[cur_subblock] = 255;
  34406. cur_subblock = p++;
  34407. }
  34408. }
  34409. if (next_code === 4096) {
  34410. // Table full, need a clear.
  34411. emit_code(clear_code);
  34412. next_code = eoi_code + 1;
  34413. cur_code_size = min_code_size + 1;
  34414. code_table = {};
  34415. } else {
  34416. // Table not full, insert a new entry.
  34417. // Increase our variable bit code sizes if necessary. This is a bit
  34418. // tricky as it is based on "timing" between the encoding and
  34419. // decoder. From the encoders perspective this should happen after
  34420. // we've already emitted the index buffer and are about to create the
  34421. // first table entry that would overflow our current code bit size.
  34422. if (next_code >= 1 << cur_code_size) ++cur_code_size;
  34423. code_table[cur_key] = next_code++; // Insert into code table.
  34424. }
  34425. ib_code = k; // Index buffer to single input k.
  34426. } else {
  34427. ib_code = cur_code; // Index buffer to sequence in code table.
  34428. }
  34429. }
  34430. emit_code(ib_code); // There will still be something in the index buffer.
  34431. emit_code(eoi_code); // End Of Information.
  34432. // Flush / finalize the sub-blocks stream to the buffer.
  34433. emit_bytes_to_buffer(1);
  34434. // Finish the sub-blocks, writing out any unfinished lengths and
  34435. // terminating with a sub-block of length 0. If we have already started
  34436. // but not yet used a sub-block it can just become the terminator.
  34437. if (cur_subblock + 1 === p) {
  34438. // Started but unused.
  34439. buf[cur_subblock] = 0;
  34440. } else {
  34441. // Started and used, write length and additional terminator block.
  34442. buf[cur_subblock] = p - cur_subblock - 1;
  34443. buf[p++] = 0;
  34444. }
  34445. return p;
  34446. }
  34447. function GifReader(buf) {
  34448. var p = 0;
  34449. // - Header (GIF87a or GIF89a).
  34450. if (
  34451. buf[p++] !== 0x47 ||
  34452. buf[p++] !== 0x49 ||
  34453. buf[p++] !== 0x46 ||
  34454. buf[p++] !== 0x38 ||
  34455. ((buf[p++] + 1) & 0xfd) !== 0x38 ||
  34456. buf[p++] !== 0x61
  34457. ) {
  34458. throw new Error('Invalid GIF 87a/89a header.');
  34459. }
  34460. // - Logical Screen Descriptor.
  34461. var width = buf[p++] | (buf[p++] << 8);
  34462. var height = buf[p++] | (buf[p++] << 8);
  34463. var pf0 = buf[p++]; // <Packed Fields>.
  34464. var global_palette_flag = pf0 >> 7;
  34465. var num_global_colors_pow2 = pf0 & 0x7;
  34466. var num_global_colors = 1 << (num_global_colors_pow2 + 1);
  34467. var background = buf[p++];
  34468. buf[p++]; // Pixel aspect ratio (unused?).
  34469. var global_palette_offset = null;
  34470. var global_palette_size = null;
  34471. if (global_palette_flag) {
  34472. global_palette_offset = p;
  34473. global_palette_size = num_global_colors;
  34474. p += num_global_colors * 3; // Seek past palette.
  34475. }
  34476. var no_eof = true;
  34477. var frames = [];
  34478. var delay = 0;
  34479. var transparent_index = null;
  34480. var disposal = 0; // 0 - No disposal specified.
  34481. var loop_count = null;
  34482. this.width = width;
  34483. this.height = height;
  34484. while (no_eof && p < buf.length) {
  34485. switch (buf[p++]) {
  34486. case 0x21: // Graphics Control Extension Block
  34487. switch (buf[p++]) {
  34488. case 0xff: // Application specific block
  34489. // Try if it's a Netscape block (with animation loop counter).
  34490. if (
  34491. buf[p] !== 0x0b || // 21 FF already read, check block size.
  34492. // NETSCAPE2.0
  34493. (buf[p + 1] == 0x4e &&
  34494. buf[p + 2] == 0x45 &&
  34495. buf[p + 3] == 0x54 &&
  34496. buf[p + 4] == 0x53 &&
  34497. buf[p + 5] == 0x43 &&
  34498. buf[p + 6] == 0x41 &&
  34499. buf[p + 7] == 0x50 &&
  34500. buf[p + 8] == 0x45 &&
  34501. buf[p + 9] == 0x32 &&
  34502. buf[p + 10] == 0x2e &&
  34503. buf[p + 11] == 0x30 &&
  34504. // Sub-block
  34505. buf[p + 12] == 0x03 &&
  34506. buf[p + 13] == 0x01 &&
  34507. buf[p + 16] == 0)
  34508. ) {
  34509. p += 14;
  34510. loop_count = buf[p++] | (buf[p++] << 8);
  34511. p++; // Skip terminator.
  34512. } else {
  34513. // We don't know what it is, just try to get past it.
  34514. p += 12;
  34515. while (true) {
  34516. // Seek through subblocks.
  34517. var block_size = buf[p++];
  34518. // Bad block size (ex: undefined from an out of bounds read).
  34519. if (!(block_size >= 0)) throw Error('Invalid block size');
  34520. if (block_size === 0) break; // 0 size is terminator
  34521. p += block_size;
  34522. }
  34523. }
  34524. break;
  34525. case 0xf9: // Graphics Control Extension
  34526. if (buf[p++] !== 0x4 || buf[p + 4] !== 0)
  34527. throw new Error('Invalid graphics extension block.');
  34528. var pf1 = buf[p++];
  34529. delay = buf[p++] | (buf[p++] << 8);
  34530. transparent_index = buf[p++];
  34531. if ((pf1 & 1) === 0) transparent_index = null;
  34532. disposal = (pf1 >> 2) & 0x7;
  34533. p++; // Skip terminator.
  34534. break;
  34535. case 0xfe: // Comment Extension.
  34536. while (true) {
  34537. // Seek through subblocks.
  34538. var block_size = buf[p++];
  34539. // Bad block size (ex: undefined from an out of bounds read).
  34540. if (!(block_size >= 0)) throw Error('Invalid block size');
  34541. if (block_size === 0) break; // 0 size is terminator
  34542. // console.log(buf.slice(p, p+block_size).toString('ascii'));
  34543. p += block_size;
  34544. }
  34545. break;
  34546. default:
  34547. throw new Error(
  34548. 'Unknown graphic control label: 0x' + buf[p - 1].toString(16)
  34549. );
  34550. }
  34551. break;
  34552. case 0x2c: // Image Descriptor.
  34553. var x = buf[p++] | (buf[p++] << 8);
  34554. var y = buf[p++] | (buf[p++] << 8);
  34555. var w = buf[p++] | (buf[p++] << 8);
  34556. var h = buf[p++] | (buf[p++] << 8);
  34557. var pf2 = buf[p++];
  34558. var local_palette_flag = pf2 >> 7;
  34559. var interlace_flag = (pf2 >> 6) & 1;
  34560. var num_local_colors_pow2 = pf2 & 0x7;
  34561. var num_local_colors = 1 << (num_local_colors_pow2 + 1);
  34562. var palette_offset = global_palette_offset;
  34563. var palette_size = global_palette_size;
  34564. var has_local_palette = false;
  34565. if (local_palette_flag) {
  34566. var has_local_palette = true;
  34567. palette_offset = p; // Override with local palette.
  34568. palette_size = num_local_colors;
  34569. p += num_local_colors * 3; // Seek past palette.
  34570. }
  34571. var data_offset = p;
  34572. p++; // codesize
  34573. while (true) {
  34574. var block_size = buf[p++];
  34575. // Bad block size (ex: undefined from an out of bounds read).
  34576. if (!(block_size >= 0)) throw Error('Invalid block size');
  34577. if (block_size === 0) break; // 0 size is terminator
  34578. p += block_size;
  34579. }
  34580. frames.push({
  34581. x: x,
  34582. y: y,
  34583. width: w,
  34584. height: h,
  34585. has_local_palette: has_local_palette,
  34586. palette_offset: palette_offset,
  34587. palette_size: palette_size,
  34588. data_offset: data_offset,
  34589. data_length: p - data_offset,
  34590. transparent_index: transparent_index,
  34591. interlaced: !!interlace_flag,
  34592. delay: delay,
  34593. disposal: disposal
  34594. });
  34595. break;
  34596. case 0x3b: // Trailer Marker (end of file).
  34597. no_eof = false;
  34598. break;
  34599. default:
  34600. throw new Error('Unknown gif block: 0x' + buf[p - 1].toString(16));
  34601. break;
  34602. }
  34603. }
  34604. this.numFrames = function() {
  34605. return frames.length;
  34606. };
  34607. this.loopCount = function() {
  34608. return loop_count;
  34609. };
  34610. this.frameInfo = function(frame_num) {
  34611. if (frame_num < 0 || frame_num >= frames.length)
  34612. throw new Error('Frame index out of range.');
  34613. return frames[frame_num];
  34614. };
  34615. this.decodeAndBlitFrameBGRA = function(frame_num, pixels) {
  34616. var frame = this.frameInfo(frame_num);
  34617. var num_pixels = frame.width * frame.height;
  34618. var index_stream = new Uint8Array(num_pixels); // At most 8-bit indices.
  34619. GifReaderLZWOutputIndexStream(
  34620. buf,
  34621. frame.data_offset,
  34622. index_stream,
  34623. num_pixels
  34624. );
  34625. var palette_offset = frame.palette_offset;
  34626. // NOTE(deanm): It seems to be much faster to compare index to 256 than
  34627. // to === null. Not sure why, but CompareStub_EQ_STRICT shows up high in
  34628. // the profile, not sure if it's related to using a Uint8Array.
  34629. var trans = frame.transparent_index;
  34630. if (trans === null) trans = 256;
  34631. // We are possibly just blitting to a portion of the entire frame.
  34632. // That is a subrect within the framerect, so the additional pixels
  34633. // must be skipped over after we finished a scanline.
  34634. var framewidth = frame.width;
  34635. var framestride = width - framewidth;
  34636. var xleft = framewidth; // Number of subrect pixels left in scanline.
  34637. // Output indicies of the top left and bottom right corners of the subrect.
  34638. var opbeg = (frame.y * width + frame.x) * 4;
  34639. var opend = ((frame.y + frame.height) * width + frame.x) * 4;
  34640. var op = opbeg;
  34641. var scanstride = framestride * 4;
  34642. // Use scanstride to skip past the rows when interlacing. This is skipping
  34643. // 7 rows for the first two passes, then 3 then 1.
  34644. if (frame.interlaced === true) {
  34645. scanstride += width * 4 * 7; // Pass 1.
  34646. }
  34647. var interlaceskip = 8; // Tracking the row interval in the current pass.
  34648. for (var i = 0, il = index_stream.length; i < il; ++i) {
  34649. var index = index_stream[i];
  34650. if (xleft === 0) {
  34651. // Beginning of new scan line
  34652. op += scanstride;
  34653. xleft = framewidth;
  34654. if (op >= opend) {
  34655. // Catch the wrap to switch passes when interlacing.
  34656. scanstride = framestride * 4 + width * 4 * (interlaceskip - 1);
  34657. // interlaceskip / 2 * 4 is interlaceskip << 1.
  34658. op = opbeg + (framewidth + framestride) * (interlaceskip << 1);
  34659. interlaceskip >>= 1;
  34660. }
  34661. }
  34662. if (index === trans) {
  34663. op += 4;
  34664. } else {
  34665. var r = buf[palette_offset + index * 3];
  34666. var g = buf[palette_offset + index * 3 + 1];
  34667. var b = buf[palette_offset + index * 3 + 2];
  34668. pixels[op++] = b;
  34669. pixels[op++] = g;
  34670. pixels[op++] = r;
  34671. pixels[op++] = 255;
  34672. }
  34673. --xleft;
  34674. }
  34675. };
  34676. // I will go to copy and paste hell one day...
  34677. this.decodeAndBlitFrameRGBA = function(frame_num, pixels) {
  34678. var frame = this.frameInfo(frame_num);
  34679. var num_pixels = frame.width * frame.height;
  34680. var index_stream = new Uint8Array(num_pixels); // At most 8-bit indices.
  34681. GifReaderLZWOutputIndexStream(
  34682. buf,
  34683. frame.data_offset,
  34684. index_stream,
  34685. num_pixels
  34686. );
  34687. var palette_offset = frame.palette_offset;
  34688. // NOTE(deanm): It seems to be much faster to compare index to 256 than
  34689. // to === null. Not sure why, but CompareStub_EQ_STRICT shows up high in
  34690. // the profile, not sure if it's related to using a Uint8Array.
  34691. var trans = frame.transparent_index;
  34692. if (trans === null) trans = 256;
  34693. // We are possibly just blitting to a portion of the entire frame.
  34694. // That is a subrect within the framerect, so the additional pixels
  34695. // must be skipped over after we finished a scanline.
  34696. var framewidth = frame.width;
  34697. var framestride = width - framewidth;
  34698. var xleft = framewidth; // Number of subrect pixels left in scanline.
  34699. // Output indicies of the top left and bottom right corners of the subrect.
  34700. var opbeg = (frame.y * width + frame.x) * 4;
  34701. var opend = ((frame.y + frame.height) * width + frame.x) * 4;
  34702. var op = opbeg;
  34703. var scanstride = framestride * 4;
  34704. // Use scanstride to skip past the rows when interlacing. This is skipping
  34705. // 7 rows for the first two passes, then 3 then 1.
  34706. if (frame.interlaced === true) {
  34707. scanstride += width * 4 * 7; // Pass 1.
  34708. }
  34709. var interlaceskip = 8; // Tracking the row interval in the current pass.
  34710. for (var i = 0, il = index_stream.length; i < il; ++i) {
  34711. var index = index_stream[i];
  34712. if (xleft === 0) {
  34713. // Beginning of new scan line
  34714. op += scanstride;
  34715. xleft = framewidth;
  34716. if (op >= opend) {
  34717. // Catch the wrap to switch passes when interlacing.
  34718. scanstride = framestride * 4 + width * 4 * (interlaceskip - 1);
  34719. // interlaceskip / 2 * 4 is interlaceskip << 1.
  34720. op = opbeg + (framewidth + framestride) * (interlaceskip << 1);
  34721. interlaceskip >>= 1;
  34722. }
  34723. }
  34724. if (index === trans) {
  34725. op += 4;
  34726. } else {
  34727. var r = buf[palette_offset + index * 3];
  34728. var g = buf[palette_offset + index * 3 + 1];
  34729. var b = buf[palette_offset + index * 3 + 2];
  34730. pixels[op++] = r;
  34731. pixels[op++] = g;
  34732. pixels[op++] = b;
  34733. pixels[op++] = 255;
  34734. }
  34735. --xleft;
  34736. }
  34737. };
  34738. }
  34739. function GifReaderLZWOutputIndexStream(code_stream, p, output, output_length) {
  34740. var min_code_size = code_stream[p++];
  34741. var clear_code = 1 << min_code_size;
  34742. var eoi_code = clear_code + 1;
  34743. var next_code = eoi_code + 1;
  34744. var cur_code_size = min_code_size + 1; // Number of bits per code.
  34745. // NOTE: This shares the same name as the encoder, but has a different
  34746. // meaning here. Here this masks each code coming from the code stream.
  34747. var code_mask = (1 << cur_code_size) - 1;
  34748. var cur_shift = 0;
  34749. var cur = 0;
  34750. var op = 0; // Output pointer.
  34751. var subblock_size = code_stream[p++];
  34752. // TODO(deanm): Would using a TypedArray be any faster? At least it would
  34753. // solve the fast mode / backing store uncertainty.
  34754. // var code_table = Array(4096);
  34755. var code_table = new Int32Array(4096); // Can be signed, we only use 20 bits.
  34756. var prev_code = null; // Track code-1.
  34757. while (true) {
  34758. // Read up to two bytes, making sure we always 12-bits for max sized code.
  34759. while (cur_shift < 16) {
  34760. if (subblock_size === 0) break; // No more data to be read.
  34761. cur |= code_stream[p++] << cur_shift;
  34762. cur_shift += 8;
  34763. if (subblock_size === 1) {
  34764. // Never let it get to 0 to hold logic above.
  34765. subblock_size = code_stream[p++]; // Next subblock.
  34766. } else {
  34767. --subblock_size;
  34768. }
  34769. }
  34770. // TODO(deanm): We should never really get here, we should have received
  34771. // and EOI.
  34772. if (cur_shift < cur_code_size) break;
  34773. var code = cur & code_mask;
  34774. cur >>= cur_code_size;
  34775. cur_shift -= cur_code_size;
  34776. // TODO(deanm): Maybe should check that the first code was a clear code,
  34777. // at least this is what you're supposed to do. But actually our encoder
  34778. // now doesn't emit a clear code first anyway.
  34779. if (code === clear_code) {
  34780. // We don't actually have to clear the table. This could be a good idea
  34781. // for greater error checking, but we don't really do any anyway. We
  34782. // will just track it with next_code and overwrite old entries.
  34783. next_code = eoi_code + 1;
  34784. cur_code_size = min_code_size + 1;
  34785. code_mask = (1 << cur_code_size) - 1;
  34786. // Don't update prev_code ?
  34787. prev_code = null;
  34788. continue;
  34789. } else if (code === eoi_code) {
  34790. break;
  34791. }
  34792. // We have a similar situation as the decoder, where we want to store
  34793. // variable length entries (code table entries), but we want to do in a
  34794. // faster manner than an array of arrays. The code below stores sort of a
  34795. // linked list within the code table, and then "chases" through it to
  34796. // construct the dictionary entries. When a new entry is created, just the
  34797. // last byte is stored, and the rest (prefix) of the entry is only
  34798. // referenced by its table entry. Then the code chases through the
  34799. // prefixes until it reaches a single byte code. We have to chase twice,
  34800. // first to compute the length, and then to actually copy the data to the
  34801. // output (backwards, since we know the length). The alternative would be
  34802. // storing something in an intermediate stack, but that doesn't make any
  34803. // more sense. I implemented an approach where it also stored the length
  34804. // in the code table, although it's a bit tricky because you run out of
  34805. // bits (12 + 12 + 8), but I didn't measure much improvements (the table
  34806. // entries are generally not the long). Even when I created benchmarks for
  34807. // very long table entries the complexity did not seem worth it.
  34808. // The code table stores the prefix entry in 12 bits and then the suffix
  34809. // byte in 8 bits, so each entry is 20 bits.
  34810. var chase_code = code < next_code ? code : prev_code;
  34811. // Chase what we will output, either {CODE} or {CODE-1}.
  34812. var chase_length = 0;
  34813. var chase = chase_code;
  34814. while (chase > clear_code) {
  34815. chase = code_table[chase] >> 8;
  34816. ++chase_length;
  34817. }
  34818. var k = chase;
  34819. var op_end = op + chase_length + (chase_code !== code ? 1 : 0);
  34820. if (op_end > output_length) {
  34821. console.log('Warning, gif stream longer than expected.');
  34822. return;
  34823. }
  34824. // Already have the first byte from the chase, might as well write it fast.
  34825. output[op++] = k;
  34826. op += chase_length;
  34827. var b = op; // Track pointer, writing backwards.
  34828. if (chase_code !== code)
  34829. // The case of emitting {CODE-1} + k.
  34830. output[op++] = k;
  34831. chase = chase_code;
  34832. while (chase_length--) {
  34833. chase = code_table[chase];
  34834. output[--b] = chase & 0xff; // Write backwards.
  34835. chase >>= 8; // Pull down to the prefix code.
  34836. }
  34837. if (prev_code !== null && next_code < 4096) {
  34838. code_table[next_code++] = (prev_code << 8) | k;
  34839. // TODO(deanm): Figure out this clearing vs code growth logic better. I
  34840. // have an feeling that it should just happen somewhere else, for now it
  34841. // is awkward between when we grow past the max and then hit a clear code.
  34842. // For now just check if we hit the max 12-bits (then a clear code should
  34843. // follow, also of course encoded in 12-bits).
  34844. if (next_code >= code_mask + 1 && cur_code_size < 12) {
  34845. ++cur_code_size;
  34846. code_mask = (code_mask << 1) | 1;
  34847. }
  34848. }
  34849. prev_code = code;
  34850. }
  34851. if (op !== output_length) {
  34852. console.log('Warning, gif stream shorter than expected.');
  34853. }
  34854. return output;
  34855. }
  34856. // CommonJS.
  34857. try {
  34858. exports.GifWriter = GifWriter;
  34859. exports.GifReader = GifReader;
  34860. } catch (e) {}
  34861. },
  34862. {}
  34863. ],
  34864. 258: [
  34865. function(_dereq_, module, exports) {
  34866. (function(Buffer) {
  34867. /**
  34868. * https://opentype.js.org v0.9.0 | (c) Frederik De Bleser and other contributors | MIT License | Uses tiny-inflate by Devon Govett and string.prototype.codepointat polyfill by Mathias Bynens
  34869. */
  34870. (function(global, factory) {
  34871. typeof exports === 'object' && typeof module !== 'undefined'
  34872. ? factory(exports)
  34873. : typeof define === 'function' && define.amd
  34874. ? define(['exports'], factory)
  34875. : factory((global.opentype = {}));
  34876. })(this, function(exports) {
  34877. 'use strict';
  34878. /*! https://mths.be/codepointat v0.2.0 by @mathias */
  34879. if (!String.prototype.codePointAt) {
  34880. (function() {
  34881. var defineProperty = (function() {
  34882. // IE 8 only supports `Object.defineProperty` on DOM elements
  34883. try {
  34884. var object = {};
  34885. var $defineProperty = Object.defineProperty;
  34886. var result =
  34887. $defineProperty(object, object, object) && $defineProperty;
  34888. } catch (error) {}
  34889. return result;
  34890. })();
  34891. var codePointAt = function(position) {
  34892. if (this == null) {
  34893. throw TypeError();
  34894. }
  34895. var string = String(this);
  34896. var size = string.length;
  34897. // `ToInteger`
  34898. var index = position ? Number(position) : 0;
  34899. if (index != index) {
  34900. // better `isNaN`
  34901. index = 0;
  34902. }
  34903. // Account for out-of-bounds indices:
  34904. if (index < 0 || index >= size) {
  34905. return undefined;
  34906. }
  34907. // Get the first code unit
  34908. var first = string.charCodeAt(index);
  34909. var second;
  34910. if (
  34911. // check if it’s the start of a surrogate pair
  34912. first >= 0xd800 &&
  34913. first <= 0xdbff && // high surrogate
  34914. size > index + 1 // there is a next code unit
  34915. ) {
  34916. second = string.charCodeAt(index + 1);
  34917. if (second >= 0xdc00 && second <= 0xdfff) {
  34918. // low surrogate
  34919. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  34920. return (first - 0xd800) * 0x400 + second - 0xdc00 + 0x10000;
  34921. }
  34922. }
  34923. return first;
  34924. };
  34925. if (defineProperty) {
  34926. defineProperty(String.prototype, 'codePointAt', {
  34927. value: codePointAt,
  34928. configurable: true,
  34929. writable: true
  34930. });
  34931. } else {
  34932. String.prototype.codePointAt = codePointAt;
  34933. }
  34934. })();
  34935. }
  34936. var TINF_OK = 0;
  34937. var TINF_DATA_ERROR = -3;
  34938. function Tree() {
  34939. this.table = new Uint16Array(16); /* table of code length counts */
  34940. this.trans = new Uint16Array(288); /* code -> symbol translation table */
  34941. }
  34942. function Data(source, dest) {
  34943. this.source = source;
  34944. this.sourceIndex = 0;
  34945. this.tag = 0;
  34946. this.bitcount = 0;
  34947. this.dest = dest;
  34948. this.destLen = 0;
  34949. this.ltree = new Tree(); /* dynamic length/symbol tree */
  34950. this.dtree = new Tree(); /* dynamic distance tree */
  34951. }
  34952. /* --------------------------------------------------- *
  34953. * -- uninitialized global data (static structures) -- *
  34954. * --------------------------------------------------- */
  34955. var sltree = new Tree();
  34956. var sdtree = new Tree();
  34957. /* extra bits and base tables for length codes */
  34958. var length_bits = new Uint8Array(30);
  34959. var length_base = new Uint16Array(30);
  34960. /* extra bits and base tables for distance codes */
  34961. var dist_bits = new Uint8Array(30);
  34962. var dist_base = new Uint16Array(30);
  34963. /* special ordering of code length codes */
  34964. var clcidx = new Uint8Array([
  34965. 16,
  34966. 17,
  34967. 18,
  34968. 0,
  34969. 8,
  34970. 7,
  34971. 9,
  34972. 6,
  34973. 10,
  34974. 5,
  34975. 11,
  34976. 4,
  34977. 12,
  34978. 3,
  34979. 13,
  34980. 2,
  34981. 14,
  34982. 1,
  34983. 15
  34984. ]);
  34985. /* used by tinf_decode_trees, avoids allocations every call */
  34986. var code_tree = new Tree();
  34987. var lengths = new Uint8Array(288 + 32);
  34988. /* ----------------------- *
  34989. * -- utility functions -- *
  34990. * ----------------------- */
  34991. /* build extra bits and base tables */
  34992. function tinf_build_bits_base(bits, base, delta, first) {
  34993. var i, sum;
  34994. /* build bits table */
  34995. for (i = 0; i < delta; ++i) {
  34996. bits[i] = 0;
  34997. }
  34998. for (i = 0; i < 30 - delta; ++i) {
  34999. bits[i + delta] = (i / delta) | 0;
  35000. }
  35001. /* build base table */
  35002. for (sum = first, i = 0; i < 30; ++i) {
  35003. base[i] = sum;
  35004. sum += 1 << bits[i];
  35005. }
  35006. }
  35007. /* build the fixed huffman trees */
  35008. function tinf_build_fixed_trees(lt, dt) {
  35009. var i;
  35010. /* build fixed length tree */
  35011. for (i = 0; i < 7; ++i) {
  35012. lt.table[i] = 0;
  35013. }
  35014. lt.table[7] = 24;
  35015. lt.table[8] = 152;
  35016. lt.table[9] = 112;
  35017. for (i = 0; i < 24; ++i) {
  35018. lt.trans[i] = 256 + i;
  35019. }
  35020. for (i = 0; i < 144; ++i) {
  35021. lt.trans[24 + i] = i;
  35022. }
  35023. for (i = 0; i < 8; ++i) {
  35024. lt.trans[24 + 144 + i] = 280 + i;
  35025. }
  35026. for (i = 0; i < 112; ++i) {
  35027. lt.trans[24 + 144 + 8 + i] = 144 + i;
  35028. }
  35029. /* build fixed distance tree */
  35030. for (i = 0; i < 5; ++i) {
  35031. dt.table[i] = 0;
  35032. }
  35033. dt.table[5] = 32;
  35034. for (i = 0; i < 32; ++i) {
  35035. dt.trans[i] = i;
  35036. }
  35037. }
  35038. /* given an array of code lengths, build a tree */
  35039. var offs = new Uint16Array(16);
  35040. function tinf_build_tree(t, lengths, off, num) {
  35041. var i, sum;
  35042. /* clear code length count table */
  35043. for (i = 0; i < 16; ++i) {
  35044. t.table[i] = 0;
  35045. }
  35046. /* scan symbol lengths, and sum code length counts */
  35047. for (i = 0; i < num; ++i) {
  35048. t.table[lengths[off + i]]++;
  35049. }
  35050. t.table[0] = 0;
  35051. /* compute offset table for distribution sort */
  35052. for (sum = 0, i = 0; i < 16; ++i) {
  35053. offs[i] = sum;
  35054. sum += t.table[i];
  35055. }
  35056. /* create code->symbol translation table (symbols sorted by code) */
  35057. for (i = 0; i < num; ++i) {
  35058. if (lengths[off + i]) {
  35059. t.trans[offs[lengths[off + i]]++] = i;
  35060. }
  35061. }
  35062. }
  35063. /* ---------------------- *
  35064. * -- decode functions -- *
  35065. * ---------------------- */
  35066. /* get one bit from source stream */
  35067. function tinf_getbit(d) {
  35068. /* check if tag is empty */
  35069. if (!d.bitcount--) {
  35070. /* load next tag */
  35071. d.tag = d.source[d.sourceIndex++];
  35072. d.bitcount = 7;
  35073. }
  35074. /* shift bit out of tag */
  35075. var bit = d.tag & 1;
  35076. d.tag >>>= 1;
  35077. return bit;
  35078. }
  35079. /* read a num bit value from a stream and add base */
  35080. function tinf_read_bits(d, num, base) {
  35081. if (!num) {
  35082. return base;
  35083. }
  35084. while (d.bitcount < 24) {
  35085. d.tag |= d.source[d.sourceIndex++] << d.bitcount;
  35086. d.bitcount += 8;
  35087. }
  35088. var val = d.tag & (0xffff >>> (16 - num));
  35089. d.tag >>>= num;
  35090. d.bitcount -= num;
  35091. return val + base;
  35092. }
  35093. /* given a data stream and a tree, decode a symbol */
  35094. function tinf_decode_symbol(d, t) {
  35095. while (d.bitcount < 24) {
  35096. d.tag |= d.source[d.sourceIndex++] << d.bitcount;
  35097. d.bitcount += 8;
  35098. }
  35099. var sum = 0,
  35100. cur = 0,
  35101. len = 0;
  35102. var tag = d.tag;
  35103. /* get more bits while code value is above sum */
  35104. do {
  35105. cur = 2 * cur + (tag & 1);
  35106. tag >>>= 1;
  35107. ++len;
  35108. sum += t.table[len];
  35109. cur -= t.table[len];
  35110. } while (cur >= 0);
  35111. d.tag = tag;
  35112. d.bitcount -= len;
  35113. return t.trans[sum + cur];
  35114. }
  35115. /* given a data stream, decode dynamic trees from it */
  35116. function tinf_decode_trees(d, lt, dt) {
  35117. var hlit, hdist, hclen;
  35118. var i, num, length;
  35119. /* get 5 bits HLIT (257-286) */
  35120. hlit = tinf_read_bits(d, 5, 257);
  35121. /* get 5 bits HDIST (1-32) */
  35122. hdist = tinf_read_bits(d, 5, 1);
  35123. /* get 4 bits HCLEN (4-19) */
  35124. hclen = tinf_read_bits(d, 4, 4);
  35125. for (i = 0; i < 19; ++i) {
  35126. lengths[i] = 0;
  35127. }
  35128. /* read code lengths for code length alphabet */
  35129. for (i = 0; i < hclen; ++i) {
  35130. /* get 3 bits code length (0-7) */
  35131. var clen = tinf_read_bits(d, 3, 0);
  35132. lengths[clcidx[i]] = clen;
  35133. }
  35134. /* build code length tree */
  35135. tinf_build_tree(code_tree, lengths, 0, 19);
  35136. /* decode code lengths for the dynamic trees */
  35137. for (num = 0; num < hlit + hdist; ) {
  35138. var sym = tinf_decode_symbol(d, code_tree);
  35139. switch (sym) {
  35140. case 16:
  35141. /* copy previous code length 3-6 times (read 2 bits) */
  35142. var prev = lengths[num - 1];
  35143. for (length = tinf_read_bits(d, 2, 3); length; --length) {
  35144. lengths[num++] = prev;
  35145. }
  35146. break;
  35147. case 17:
  35148. /* repeat code length 0 for 3-10 times (read 3 bits) */
  35149. for (length = tinf_read_bits(d, 3, 3); length; --length) {
  35150. lengths[num++] = 0;
  35151. }
  35152. break;
  35153. case 18:
  35154. /* repeat code length 0 for 11-138 times (read 7 bits) */
  35155. for (length = tinf_read_bits(d, 7, 11); length; --length) {
  35156. lengths[num++] = 0;
  35157. }
  35158. break;
  35159. default:
  35160. /* values 0-15 represent the actual code lengths */
  35161. lengths[num++] = sym;
  35162. break;
  35163. }
  35164. }
  35165. /* build dynamic trees */
  35166. tinf_build_tree(lt, lengths, 0, hlit);
  35167. tinf_build_tree(dt, lengths, hlit, hdist);
  35168. }
  35169. /* ----------------------------- *
  35170. * -- block inflate functions -- *
  35171. * ----------------------------- */
  35172. /* given a stream and two trees, inflate a block of data */
  35173. function tinf_inflate_block_data(d, lt, dt) {
  35174. while (1) {
  35175. var sym = tinf_decode_symbol(d, lt);
  35176. /* check for end of block */
  35177. if (sym === 256) {
  35178. return TINF_OK;
  35179. }
  35180. if (sym < 256) {
  35181. d.dest[d.destLen++] = sym;
  35182. } else {
  35183. var length, dist, offs;
  35184. var i;
  35185. sym -= 257;
  35186. /* possibly get more bits from length code */
  35187. length = tinf_read_bits(d, length_bits[sym], length_base[sym]);
  35188. dist = tinf_decode_symbol(d, dt);
  35189. /* possibly get more bits from distance code */
  35190. offs = d.destLen - tinf_read_bits(d, dist_bits[dist], dist_base[dist]);
  35191. /* copy match */
  35192. for (i = offs; i < offs + length; ++i) {
  35193. d.dest[d.destLen++] = d.dest[i];
  35194. }
  35195. }
  35196. }
  35197. }
  35198. /* inflate an uncompressed block of data */
  35199. function tinf_inflate_uncompressed_block(d) {
  35200. var length, invlength;
  35201. var i;
  35202. /* unread from bitbuffer */
  35203. while (d.bitcount > 8) {
  35204. d.sourceIndex--;
  35205. d.bitcount -= 8;
  35206. }
  35207. /* get length */
  35208. length = d.source[d.sourceIndex + 1];
  35209. length = 256 * length + d.source[d.sourceIndex];
  35210. /* get one's complement of length */
  35211. invlength = d.source[d.sourceIndex + 3];
  35212. invlength = 256 * invlength + d.source[d.sourceIndex + 2];
  35213. /* check length */
  35214. if (length !== (~invlength & 0x0000ffff)) {
  35215. return TINF_DATA_ERROR;
  35216. }
  35217. d.sourceIndex += 4;
  35218. /* copy block */
  35219. for (i = length; i; --i) {
  35220. d.dest[d.destLen++] = d.source[d.sourceIndex++];
  35221. }
  35222. /* make sure we start next block on a byte boundary */
  35223. d.bitcount = 0;
  35224. return TINF_OK;
  35225. }
  35226. /* inflate stream from source to dest */
  35227. function tinf_uncompress(source, dest) {
  35228. var d = new Data(source, dest);
  35229. var bfinal, btype, res;
  35230. do {
  35231. /* read final block flag */
  35232. bfinal = tinf_getbit(d);
  35233. /* read block type (2 bits) */
  35234. btype = tinf_read_bits(d, 2, 0);
  35235. /* decompress block */
  35236. switch (btype) {
  35237. case 0:
  35238. /* decompress uncompressed block */
  35239. res = tinf_inflate_uncompressed_block(d);
  35240. break;
  35241. case 1:
  35242. /* decompress block with fixed huffman trees */
  35243. res = tinf_inflate_block_data(d, sltree, sdtree);
  35244. break;
  35245. case 2:
  35246. /* decompress block with dynamic huffman trees */
  35247. tinf_decode_trees(d, d.ltree, d.dtree);
  35248. res = tinf_inflate_block_data(d, d.ltree, d.dtree);
  35249. break;
  35250. default:
  35251. res = TINF_DATA_ERROR;
  35252. }
  35253. if (res !== TINF_OK) {
  35254. throw new Error('Data error');
  35255. }
  35256. } while (!bfinal);
  35257. if (d.destLen < d.dest.length) {
  35258. if (typeof d.dest.slice === 'function') {
  35259. return d.dest.slice(0, d.destLen);
  35260. } else {
  35261. return d.dest.subarray(0, d.destLen);
  35262. }
  35263. }
  35264. return d.dest;
  35265. }
  35266. /* -------------------- *
  35267. * -- initialization -- *
  35268. * -------------------- */
  35269. /* build fixed huffman trees */
  35270. tinf_build_fixed_trees(sltree, sdtree);
  35271. /* build extra bits and base tables */
  35272. tinf_build_bits_base(length_bits, length_base, 4, 3);
  35273. tinf_build_bits_base(dist_bits, dist_base, 2, 1);
  35274. /* fix a special case */
  35275. length_bits[28] = 0;
  35276. length_base[28] = 258;
  35277. var tinyInflate = tinf_uncompress;
  35278. // The Bounding Box object
  35279. function derive(v0, v1, v2, v3, t) {
  35280. return (
  35281. Math.pow(1 - t, 3) * v0 +
  35282. 3 * Math.pow(1 - t, 2) * t * v1 +
  35283. 3 * (1 - t) * Math.pow(t, 2) * v2 +
  35284. Math.pow(t, 3) * v3
  35285. );
  35286. }
  35287. /**
  35288. * A bounding box is an enclosing box that describes the smallest measure within which all the points lie.
  35289. * It is used to calculate the bounding box of a glyph or text path.
  35290. *
  35291. * On initialization, x1/y1/x2/y2 will be NaN. Check if the bounding box is empty using `isEmpty()`.
  35292. *
  35293. * @exports opentype.BoundingBox
  35294. * @class
  35295. * @constructor
  35296. */
  35297. function BoundingBox() {
  35298. this.x1 = Number.NaN;
  35299. this.y1 = Number.NaN;
  35300. this.x2 = Number.NaN;
  35301. this.y2 = Number.NaN;
  35302. }
  35303. /**
  35304. * Returns true if the bounding box is empty, that is, no points have been added to the box yet.
  35305. */
  35306. BoundingBox.prototype.isEmpty = function() {
  35307. return isNaN(this.x1) || isNaN(this.y1) || isNaN(this.x2) || isNaN(this.y2);
  35308. };
  35309. /**
  35310. * Add the point to the bounding box.
  35311. * The x1/y1/x2/y2 coordinates of the bounding box will now encompass the given point.
  35312. * @param {number} x - The X coordinate of the point.
  35313. * @param {number} y - The Y coordinate of the point.
  35314. */
  35315. BoundingBox.prototype.addPoint = function(x, y) {
  35316. if (typeof x === 'number') {
  35317. if (isNaN(this.x1) || isNaN(this.x2)) {
  35318. this.x1 = x;
  35319. this.x2 = x;
  35320. }
  35321. if (x < this.x1) {
  35322. this.x1 = x;
  35323. }
  35324. if (x > this.x2) {
  35325. this.x2 = x;
  35326. }
  35327. }
  35328. if (typeof y === 'number') {
  35329. if (isNaN(this.y1) || isNaN(this.y2)) {
  35330. this.y1 = y;
  35331. this.y2 = y;
  35332. }
  35333. if (y < this.y1) {
  35334. this.y1 = y;
  35335. }
  35336. if (y > this.y2) {
  35337. this.y2 = y;
  35338. }
  35339. }
  35340. };
  35341. /**
  35342. * Add a X coordinate to the bounding box.
  35343. * This extends the bounding box to include the X coordinate.
  35344. * This function is used internally inside of addBezier.
  35345. * @param {number} x - The X coordinate of the point.
  35346. */
  35347. BoundingBox.prototype.addX = function(x) {
  35348. this.addPoint(x, null);
  35349. };
  35350. /**
  35351. * Add a Y coordinate to the bounding box.
  35352. * This extends the bounding box to include the Y coordinate.
  35353. * This function is used internally inside of addBezier.
  35354. * @param {number} y - The Y coordinate of the point.
  35355. */
  35356. BoundingBox.prototype.addY = function(y) {
  35357. this.addPoint(null, y);
  35358. };
  35359. /**
  35360. * Add a Bézier curve to the bounding box.
  35361. * This extends the bounding box to include the entire Bézier.
  35362. * @param {number} x0 - The starting X coordinate.
  35363. * @param {number} y0 - The starting Y coordinate.
  35364. * @param {number} x1 - The X coordinate of the first control point.
  35365. * @param {number} y1 - The Y coordinate of the first control point.
  35366. * @param {number} x2 - The X coordinate of the second control point.
  35367. * @param {number} y2 - The Y coordinate of the second control point.
  35368. * @param {number} x - The ending X coordinate.
  35369. * @param {number} y - The ending Y coordinate.
  35370. */
  35371. BoundingBox.prototype.addBezier = function(x0, y0, x1, y1, x2, y2, x, y) {
  35372. var this$1 = this;
  35373. // This code is based on http://nishiohirokazu.blogspot.com/2009/06/how-to-calculate-bezier-curves-bounding.html
  35374. // and https://github.com/icons8/svg-path-bounding-box
  35375. var p0 = [x0, y0];
  35376. var p1 = [x1, y1];
  35377. var p2 = [x2, y2];
  35378. var p3 = [x, y];
  35379. this.addPoint(x0, y0);
  35380. this.addPoint(x, y);
  35381. for (var i = 0; i <= 1; i++) {
  35382. var b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i];
  35383. var a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i];
  35384. var c = 3 * p1[i] - 3 * p0[i];
  35385. if (a === 0) {
  35386. if (b === 0) {
  35387. continue;
  35388. }
  35389. var t = -c / b;
  35390. if (0 < t && t < 1) {
  35391. if (i === 0) {
  35392. this$1.addX(derive(p0[i], p1[i], p2[i], p3[i], t));
  35393. }
  35394. if (i === 1) {
  35395. this$1.addY(derive(p0[i], p1[i], p2[i], p3[i], t));
  35396. }
  35397. }
  35398. continue;
  35399. }
  35400. var b2ac = Math.pow(b, 2) - 4 * c * a;
  35401. if (b2ac < 0) {
  35402. continue;
  35403. }
  35404. var t1 = (-b + Math.sqrt(b2ac)) / (2 * a);
  35405. if (0 < t1 && t1 < 1) {
  35406. if (i === 0) {
  35407. this$1.addX(derive(p0[i], p1[i], p2[i], p3[i], t1));
  35408. }
  35409. if (i === 1) {
  35410. this$1.addY(derive(p0[i], p1[i], p2[i], p3[i], t1));
  35411. }
  35412. }
  35413. var t2 = (-b - Math.sqrt(b2ac)) / (2 * a);
  35414. if (0 < t2 && t2 < 1) {
  35415. if (i === 0) {
  35416. this$1.addX(derive(p0[i], p1[i], p2[i], p3[i], t2));
  35417. }
  35418. if (i === 1) {
  35419. this$1.addY(derive(p0[i], p1[i], p2[i], p3[i], t2));
  35420. }
  35421. }
  35422. }
  35423. };
  35424. /**
  35425. * Add a quadratic curve to the bounding box.
  35426. * This extends the bounding box to include the entire quadratic curve.
  35427. * @param {number} x0 - The starting X coordinate.
  35428. * @param {number} y0 - The starting Y coordinate.
  35429. * @param {number} x1 - The X coordinate of the control point.
  35430. * @param {number} y1 - The Y coordinate of the control point.
  35431. * @param {number} x - The ending X coordinate.
  35432. * @param {number} y - The ending Y coordinate.
  35433. */
  35434. BoundingBox.prototype.addQuad = function(x0, y0, x1, y1, x, y) {
  35435. var cp1x = x0 + 2 / 3 * (x1 - x0);
  35436. var cp1y = y0 + 2 / 3 * (y1 - y0);
  35437. var cp2x = cp1x + 1 / 3 * (x - x0);
  35438. var cp2y = cp1y + 1 / 3 * (y - y0);
  35439. this.addBezier(x0, y0, cp1x, cp1y, cp2x, cp2y, x, y);
  35440. };
  35441. // Geometric objects
  35442. /**
  35443. * A bézier path containing a set of path commands similar to a SVG path.
  35444. * Paths can be drawn on a context using `draw`.
  35445. * @exports opentype.Path
  35446. * @class
  35447. * @constructor
  35448. */
  35449. function Path() {
  35450. this.commands = [];
  35451. this.fill = 'black';
  35452. this.stroke = null;
  35453. this.strokeWidth = 1;
  35454. }
  35455. /**
  35456. * @param {number} x
  35457. * @param {number} y
  35458. */
  35459. Path.prototype.moveTo = function(x, y) {
  35460. this.commands.push({
  35461. type: 'M',
  35462. x: x,
  35463. y: y
  35464. });
  35465. };
  35466. /**
  35467. * @param {number} x
  35468. * @param {number} y
  35469. */
  35470. Path.prototype.lineTo = function(x, y) {
  35471. this.commands.push({
  35472. type: 'L',
  35473. x: x,
  35474. y: y
  35475. });
  35476. };
  35477. /**
  35478. * Draws cubic curve
  35479. * @function
  35480. * curveTo
  35481. * @memberof opentype.Path.prototype
  35482. * @param {number} x1 - x of control 1
  35483. * @param {number} y1 - y of control 1
  35484. * @param {number} x2 - x of control 2
  35485. * @param {number} y2 - y of control 2
  35486. * @param {number} x - x of path point
  35487. * @param {number} y - y of path point
  35488. */
  35489. /**
  35490. * Draws cubic curve
  35491. * @function
  35492. * bezierCurveTo
  35493. * @memberof opentype.Path.prototype
  35494. * @param {number} x1 - x of control 1
  35495. * @param {number} y1 - y of control 1
  35496. * @param {number} x2 - x of control 2
  35497. * @param {number} y2 - y of control 2
  35498. * @param {number} x - x of path point
  35499. * @param {number} y - y of path point
  35500. * @see curveTo
  35501. */
  35502. Path.prototype.curveTo = Path.prototype.bezierCurveTo = function(
  35503. x1,
  35504. y1,
  35505. x2,
  35506. y2,
  35507. x,
  35508. y
  35509. ) {
  35510. this.commands.push({
  35511. type: 'C',
  35512. x1: x1,
  35513. y1: y1,
  35514. x2: x2,
  35515. y2: y2,
  35516. x: x,
  35517. y: y
  35518. });
  35519. };
  35520. /**
  35521. * Draws quadratic curve
  35522. * @function
  35523. * quadraticCurveTo
  35524. * @memberof opentype.Path.prototype
  35525. * @param {number} x1 - x of control
  35526. * @param {number} y1 - y of control
  35527. * @param {number} x - x of path point
  35528. * @param {number} y - y of path point
  35529. */
  35530. /**
  35531. * Draws quadratic curve
  35532. * @function
  35533. * quadTo
  35534. * @memberof opentype.Path.prototype
  35535. * @param {number} x1 - x of control
  35536. * @param {number} y1 - y of control
  35537. * @param {number} x - x of path point
  35538. * @param {number} y - y of path point
  35539. */
  35540. Path.prototype.quadTo = Path.prototype.quadraticCurveTo = function(
  35541. x1,
  35542. y1,
  35543. x,
  35544. y
  35545. ) {
  35546. this.commands.push({
  35547. type: 'Q',
  35548. x1: x1,
  35549. y1: y1,
  35550. x: x,
  35551. y: y
  35552. });
  35553. };
  35554. /**
  35555. * Closes the path
  35556. * @function closePath
  35557. * @memberof opentype.Path.prototype
  35558. */
  35559. /**
  35560. * Close the path
  35561. * @function close
  35562. * @memberof opentype.Path.prototype
  35563. */
  35564. Path.prototype.close = Path.prototype.closePath = function() {
  35565. this.commands.push({
  35566. type: 'Z'
  35567. });
  35568. };
  35569. /**
  35570. * Add the given path or list of commands to the commands of this path.
  35571. * @param {Array} pathOrCommands - another opentype.Path, an opentype.BoundingBox, or an array of commands.
  35572. */
  35573. Path.prototype.extend = function(pathOrCommands) {
  35574. if (pathOrCommands.commands) {
  35575. pathOrCommands = pathOrCommands.commands;
  35576. } else if (pathOrCommands instanceof BoundingBox) {
  35577. var box = pathOrCommands;
  35578. this.moveTo(box.x1, box.y1);
  35579. this.lineTo(box.x2, box.y1);
  35580. this.lineTo(box.x2, box.y2);
  35581. this.lineTo(box.x1, box.y2);
  35582. this.close();
  35583. return;
  35584. }
  35585. Array.prototype.push.apply(this.commands, pathOrCommands);
  35586. };
  35587. /**
  35588. * Calculate the bounding box of the path.
  35589. * @returns {opentype.BoundingBox}
  35590. */
  35591. Path.prototype.getBoundingBox = function() {
  35592. var this$1 = this;
  35593. var box = new BoundingBox();
  35594. var startX = 0;
  35595. var startY = 0;
  35596. var prevX = 0;
  35597. var prevY = 0;
  35598. for (var i = 0; i < this.commands.length; i++) {
  35599. var cmd = this$1.commands[i];
  35600. switch (cmd.type) {
  35601. case 'M':
  35602. box.addPoint(cmd.x, cmd.y);
  35603. startX = prevX = cmd.x;
  35604. startY = prevY = cmd.y;
  35605. break;
  35606. case 'L':
  35607. box.addPoint(cmd.x, cmd.y);
  35608. prevX = cmd.x;
  35609. prevY = cmd.y;
  35610. break;
  35611. case 'Q':
  35612. box.addQuad(prevX, prevY, cmd.x1, cmd.y1, cmd.x, cmd.y);
  35613. prevX = cmd.x;
  35614. prevY = cmd.y;
  35615. break;
  35616. case 'C':
  35617. box.addBezier(
  35618. prevX,
  35619. prevY,
  35620. cmd.x1,
  35621. cmd.y1,
  35622. cmd.x2,
  35623. cmd.y2,
  35624. cmd.x,
  35625. cmd.y
  35626. );
  35627. prevX = cmd.x;
  35628. prevY = cmd.y;
  35629. break;
  35630. case 'Z':
  35631. prevX = startX;
  35632. prevY = startY;
  35633. break;
  35634. default:
  35635. throw new Error('Unexpected path command ' + cmd.type);
  35636. }
  35637. }
  35638. if (box.isEmpty()) {
  35639. box.addPoint(0, 0);
  35640. }
  35641. return box;
  35642. };
  35643. /**
  35644. * Draw the path to a 2D context.
  35645. * @param {CanvasRenderingContext2D} ctx - A 2D drawing context.
  35646. */
  35647. Path.prototype.draw = function(ctx) {
  35648. var this$1 = this;
  35649. ctx.beginPath();
  35650. for (var i = 0; i < this.commands.length; i += 1) {
  35651. var cmd = this$1.commands[i];
  35652. if (cmd.type === 'M') {
  35653. ctx.moveTo(cmd.x, cmd.y);
  35654. } else if (cmd.type === 'L') {
  35655. ctx.lineTo(cmd.x, cmd.y);
  35656. } else if (cmd.type === 'C') {
  35657. ctx.bezierCurveTo(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y);
  35658. } else if (cmd.type === 'Q') {
  35659. ctx.quadraticCurveTo(cmd.x1, cmd.y1, cmd.x, cmd.y);
  35660. } else if (cmd.type === 'Z') {
  35661. ctx.closePath();
  35662. }
  35663. }
  35664. if (this.fill) {
  35665. ctx.fillStyle = this.fill;
  35666. ctx.fill();
  35667. }
  35668. if (this.stroke) {
  35669. ctx.strokeStyle = this.stroke;
  35670. ctx.lineWidth = this.strokeWidth;
  35671. ctx.stroke();
  35672. }
  35673. };
  35674. /**
  35675. * Convert the Path to a string of path data instructions
  35676. * See http://www.w3.org/TR/SVG/paths.html#PathData
  35677. * @param {number} [decimalPlaces=2] - The amount of decimal places for floating-point values
  35678. * @return {string}
  35679. */
  35680. Path.prototype.toPathData = function(decimalPlaces) {
  35681. var this$1 = this;
  35682. decimalPlaces = decimalPlaces !== undefined ? decimalPlaces : 2;
  35683. function floatToString(v) {
  35684. if (Math.round(v) === v) {
  35685. return '' + Math.round(v);
  35686. } else {
  35687. return v.toFixed(decimalPlaces);
  35688. }
  35689. }
  35690. function packValues() {
  35691. var arguments$1 = arguments;
  35692. var s = '';
  35693. for (var i = 0; i < arguments.length; i += 1) {
  35694. var v = arguments$1[i];
  35695. if (v >= 0 && i > 0) {
  35696. s += ' ';
  35697. }
  35698. s += floatToString(v);
  35699. }
  35700. return s;
  35701. }
  35702. var d = '';
  35703. for (var i = 0; i < this.commands.length; i += 1) {
  35704. var cmd = this$1.commands[i];
  35705. if (cmd.type === 'M') {
  35706. d += 'M' + packValues(cmd.x, cmd.y);
  35707. } else if (cmd.type === 'L') {
  35708. d += 'L' + packValues(cmd.x, cmd.y);
  35709. } else if (cmd.type === 'C') {
  35710. d += 'C' + packValues(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y);
  35711. } else if (cmd.type === 'Q') {
  35712. d += 'Q' + packValues(cmd.x1, cmd.y1, cmd.x, cmd.y);
  35713. } else if (cmd.type === 'Z') {
  35714. d += 'Z';
  35715. }
  35716. }
  35717. return d;
  35718. };
  35719. /**
  35720. * Convert the path to an SVG <path> element, as a string.
  35721. * @param {number} [decimalPlaces=2] - The amount of decimal places for floating-point values
  35722. * @return {string}
  35723. */
  35724. Path.prototype.toSVG = function(decimalPlaces) {
  35725. var svg = '<path d="';
  35726. svg += this.toPathData(decimalPlaces);
  35727. svg += '"';
  35728. if (this.fill && this.fill !== 'black') {
  35729. if (this.fill === null) {
  35730. svg += ' fill="none"';
  35731. } else {
  35732. svg += ' fill="' + this.fill + '"';
  35733. }
  35734. }
  35735. if (this.stroke) {
  35736. svg +=
  35737. ' stroke="' + this.stroke + '" stroke-width="' + this.strokeWidth + '"';
  35738. }
  35739. svg += '/>';
  35740. return svg;
  35741. };
  35742. /**
  35743. * Convert the path to a DOM element.
  35744. * @param {number} [decimalPlaces=2] - The amount of decimal places for floating-point values
  35745. * @return {SVGPathElement}
  35746. */
  35747. Path.prototype.toDOMElement = function(decimalPlaces) {
  35748. var temporaryPath = this.toPathData(decimalPlaces);
  35749. var newPath = document.createElementNS(
  35750. 'http://www.w3.org/2000/svg',
  35751. 'path'
  35752. );
  35753. newPath.setAttribute('d', temporaryPath);
  35754. return newPath;
  35755. };
  35756. // Run-time checking of preconditions.
  35757. function fail(message) {
  35758. throw new Error(message);
  35759. }
  35760. // Precondition function that checks if the given predicate is true.
  35761. // If not, it will throw an error.
  35762. function argument(predicate, message) {
  35763. if (!predicate) {
  35764. fail(message);
  35765. }
  35766. }
  35767. var check = { fail: fail, argument: argument, assert: argument };
  35768. // Data types used in the OpenType font file.
  35769. var LIMIT16 = 32768; // The limit at which a 16-bit number switches signs == 2^15
  35770. var LIMIT32 = 2147483648; // The limit at which a 32-bit number switches signs == 2 ^ 31
  35771. /**
  35772. * @exports opentype.decode
  35773. * @class
  35774. */
  35775. var decode = {};
  35776. /**
  35777. * @exports opentype.encode
  35778. * @class
  35779. */
  35780. var encode = {};
  35781. /**
  35782. * @exports opentype.sizeOf
  35783. * @class
  35784. */
  35785. var sizeOf = {};
  35786. // Return a function that always returns the same value.
  35787. function constant(v) {
  35788. return function() {
  35789. return v;
  35790. };
  35791. }
  35792. // OpenType data types //////////////////////////////////////////////////////
  35793. /**
  35794. * Convert an 8-bit unsigned integer to a list of 1 byte.
  35795. * @param {number}
  35796. * @returns {Array}
  35797. */
  35798. encode.BYTE = function(v) {
  35799. check.argument(
  35800. v >= 0 && v <= 255,
  35801. 'Byte value should be between 0 and 255.'
  35802. );
  35803. return [v];
  35804. };
  35805. /**
  35806. * @constant
  35807. * @type {number}
  35808. */
  35809. sizeOf.BYTE = constant(1);
  35810. /**
  35811. * Convert a 8-bit signed integer to a list of 1 byte.
  35812. * @param {string}
  35813. * @returns {Array}
  35814. */
  35815. encode.CHAR = function(v) {
  35816. return [v.charCodeAt(0)];
  35817. };
  35818. /**
  35819. * @constant
  35820. * @type {number}
  35821. */
  35822. sizeOf.CHAR = constant(1);
  35823. /**
  35824. * Convert an ASCII string to a list of bytes.
  35825. * @param {string}
  35826. * @returns {Array}
  35827. */
  35828. encode.CHARARRAY = function(v) {
  35829. var b = [];
  35830. for (var i = 0; i < v.length; i += 1) {
  35831. b[i] = v.charCodeAt(i);
  35832. }
  35833. return b;
  35834. };
  35835. /**
  35836. * @param {Array}
  35837. * @returns {number}
  35838. */
  35839. sizeOf.CHARARRAY = function(v) {
  35840. return v.length;
  35841. };
  35842. /**
  35843. * Convert a 16-bit unsigned integer to a list of 2 bytes.
  35844. * @param {number}
  35845. * @returns {Array}
  35846. */
  35847. encode.USHORT = function(v) {
  35848. return [(v >> 8) & 0xff, v & 0xff];
  35849. };
  35850. /**
  35851. * @constant
  35852. * @type {number}
  35853. */
  35854. sizeOf.USHORT = constant(2);
  35855. /**
  35856. * Convert a 16-bit signed integer to a list of 2 bytes.
  35857. * @param {number}
  35858. * @returns {Array}
  35859. */
  35860. encode.SHORT = function(v) {
  35861. // Two's complement
  35862. if (v >= LIMIT16) {
  35863. v = -(2 * LIMIT16 - v);
  35864. }
  35865. return [(v >> 8) & 0xff, v & 0xff];
  35866. };
  35867. /**
  35868. * @constant
  35869. * @type {number}
  35870. */
  35871. sizeOf.SHORT = constant(2);
  35872. /**
  35873. * Convert a 24-bit unsigned integer to a list of 3 bytes.
  35874. * @param {number}
  35875. * @returns {Array}
  35876. */
  35877. encode.UINT24 = function(v) {
  35878. return [(v >> 16) & 0xff, (v >> 8) & 0xff, v & 0xff];
  35879. };
  35880. /**
  35881. * @constant
  35882. * @type {number}
  35883. */
  35884. sizeOf.UINT24 = constant(3);
  35885. /**
  35886. * Convert a 32-bit unsigned integer to a list of 4 bytes.
  35887. * @param {number}
  35888. * @returns {Array}
  35889. */
  35890. encode.ULONG = function(v) {
  35891. return [(v >> 24) & 0xff, (v >> 16) & 0xff, (v >> 8) & 0xff, v & 0xff];
  35892. };
  35893. /**
  35894. * @constant
  35895. * @type {number}
  35896. */
  35897. sizeOf.ULONG = constant(4);
  35898. /**
  35899. * Convert a 32-bit unsigned integer to a list of 4 bytes.
  35900. * @param {number}
  35901. * @returns {Array}
  35902. */
  35903. encode.LONG = function(v) {
  35904. // Two's complement
  35905. if (v >= LIMIT32) {
  35906. v = -(2 * LIMIT32 - v);
  35907. }
  35908. return [(v >> 24) & 0xff, (v >> 16) & 0xff, (v >> 8) & 0xff, v & 0xff];
  35909. };
  35910. /**
  35911. * @constant
  35912. * @type {number}
  35913. */
  35914. sizeOf.LONG = constant(4);
  35915. encode.FIXED = encode.ULONG;
  35916. sizeOf.FIXED = sizeOf.ULONG;
  35917. encode.FWORD = encode.SHORT;
  35918. sizeOf.FWORD = sizeOf.SHORT;
  35919. encode.UFWORD = encode.USHORT;
  35920. sizeOf.UFWORD = sizeOf.USHORT;
  35921. /**
  35922. * Convert a 32-bit Apple Mac timestamp integer to a list of 8 bytes, 64-bit timestamp.
  35923. * @param {number}
  35924. * @returns {Array}
  35925. */
  35926. encode.LONGDATETIME = function(v) {
  35927. return [
  35928. 0,
  35929. 0,
  35930. 0,
  35931. 0,
  35932. (v >> 24) & 0xff,
  35933. (v >> 16) & 0xff,
  35934. (v >> 8) & 0xff,
  35935. v & 0xff
  35936. ];
  35937. };
  35938. /**
  35939. * @constant
  35940. * @type {number}
  35941. */
  35942. sizeOf.LONGDATETIME = constant(8);
  35943. /**
  35944. * Convert a 4-char tag to a list of 4 bytes.
  35945. * @param {string}
  35946. * @returns {Array}
  35947. */
  35948. encode.TAG = function(v) {
  35949. check.argument(v.length === 4, 'Tag should be exactly 4 ASCII characters.');
  35950. return [v.charCodeAt(0), v.charCodeAt(1), v.charCodeAt(2), v.charCodeAt(3)];
  35951. };
  35952. /**
  35953. * @constant
  35954. * @type {number}
  35955. */
  35956. sizeOf.TAG = constant(4);
  35957. // CFF data types ///////////////////////////////////////////////////////////
  35958. encode.Card8 = encode.BYTE;
  35959. sizeOf.Card8 = sizeOf.BYTE;
  35960. encode.Card16 = encode.USHORT;
  35961. sizeOf.Card16 = sizeOf.USHORT;
  35962. encode.OffSize = encode.BYTE;
  35963. sizeOf.OffSize = sizeOf.BYTE;
  35964. encode.SID = encode.USHORT;
  35965. sizeOf.SID = sizeOf.USHORT;
  35966. // Convert a numeric operand or charstring number to a variable-size list of bytes.
  35967. /**
  35968. * Convert a numeric operand or charstring number to a variable-size list of bytes.
  35969. * @param {number}
  35970. * @returns {Array}
  35971. */
  35972. encode.NUMBER = function(v) {
  35973. if (v >= -107 && v <= 107) {
  35974. return [v + 139];
  35975. } else if (v >= 108 && v <= 1131) {
  35976. v = v - 108;
  35977. return [(v >> 8) + 247, v & 0xff];
  35978. } else if (v >= -1131 && v <= -108) {
  35979. v = -v - 108;
  35980. return [(v >> 8) + 251, v & 0xff];
  35981. } else if (v >= -32768 && v <= 32767) {
  35982. return encode.NUMBER16(v);
  35983. } else {
  35984. return encode.NUMBER32(v);
  35985. }
  35986. };
  35987. /**
  35988. * @param {number}
  35989. * @returns {number}
  35990. */
  35991. sizeOf.NUMBER = function(v) {
  35992. return encode.NUMBER(v).length;
  35993. };
  35994. /**
  35995. * Convert a signed number between -32768 and +32767 to a three-byte value.
  35996. * This ensures we always use three bytes, but is not the most compact format.
  35997. * @param {number}
  35998. * @returns {Array}
  35999. */
  36000. encode.NUMBER16 = function(v) {
  36001. return [28, (v >> 8) & 0xff, v & 0xff];
  36002. };
  36003. /**
  36004. * @constant
  36005. * @type {number}
  36006. */
  36007. sizeOf.NUMBER16 = constant(3);
  36008. /**
  36009. * Convert a signed number between -(2^31) and +(2^31-1) to a five-byte value.
  36010. * This is useful if you want to be sure you always use four bytes,
  36011. * at the expense of wasting a few bytes for smaller numbers.
  36012. * @param {number}
  36013. * @returns {Array}
  36014. */
  36015. encode.NUMBER32 = function(v) {
  36016. return [29, (v >> 24) & 0xff, (v >> 16) & 0xff, (v >> 8) & 0xff, v & 0xff];
  36017. };
  36018. /**
  36019. * @constant
  36020. * @type {number}
  36021. */
  36022. sizeOf.NUMBER32 = constant(5);
  36023. /**
  36024. * @param {number}
  36025. * @returns {Array}
  36026. */
  36027. encode.REAL = function(v) {
  36028. var value = v.toString();
  36029. // Some numbers use an epsilon to encode the value. (e.g. JavaScript will store 0.0000001 as 1e-7)
  36030. // This code converts it back to a number without the epsilon.
  36031. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  36032. if (m) {
  36033. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  36034. value = (Math.round(v * epsilon) / epsilon).toString();
  36035. }
  36036. var nibbles = '';
  36037. for (var i = 0, ii = value.length; i < ii; i += 1) {
  36038. var c = value[i];
  36039. if (c === 'e') {
  36040. nibbles += value[++i] === '-' ? 'c' : 'b';
  36041. } else if (c === '.') {
  36042. nibbles += 'a';
  36043. } else if (c === '-') {
  36044. nibbles += 'e';
  36045. } else {
  36046. nibbles += c;
  36047. }
  36048. }
  36049. nibbles += nibbles.length & 1 ? 'f' : 'ff';
  36050. var out = [30];
  36051. for (var i$1 = 0, ii$1 = nibbles.length; i$1 < ii$1; i$1 += 2) {
  36052. out.push(parseInt(nibbles.substr(i$1, 2), 16));
  36053. }
  36054. return out;
  36055. };
  36056. /**
  36057. * @param {number}
  36058. * @returns {number}
  36059. */
  36060. sizeOf.REAL = function(v) {
  36061. return encode.REAL(v).length;
  36062. };
  36063. encode.NAME = encode.CHARARRAY;
  36064. sizeOf.NAME = sizeOf.CHARARRAY;
  36065. encode.STRING = encode.CHARARRAY;
  36066. sizeOf.STRING = sizeOf.CHARARRAY;
  36067. /**
  36068. * @param {DataView} data
  36069. * @param {number} offset
  36070. * @param {number} numBytes
  36071. * @returns {string}
  36072. */
  36073. decode.UTF8 = function(data, offset, numBytes) {
  36074. var codePoints = [];
  36075. var numChars = numBytes;
  36076. for (var j = 0; j < numChars; j++, offset += 1) {
  36077. codePoints[j] = data.getUint8(offset);
  36078. }
  36079. return String.fromCharCode.apply(null, codePoints);
  36080. };
  36081. /**
  36082. * @param {DataView} data
  36083. * @param {number} offset
  36084. * @param {number} numBytes
  36085. * @returns {string}
  36086. */
  36087. decode.UTF16 = function(data, offset, numBytes) {
  36088. var codePoints = [];
  36089. var numChars = numBytes / 2;
  36090. for (var j = 0; j < numChars; j++, offset += 2) {
  36091. codePoints[j] = data.getUint16(offset);
  36092. }
  36093. return String.fromCharCode.apply(null, codePoints);
  36094. };
  36095. /**
  36096. * Convert a JavaScript string to UTF16-BE.
  36097. * @param {string}
  36098. * @returns {Array}
  36099. */
  36100. encode.UTF16 = function(v) {
  36101. var b = [];
  36102. for (var i = 0; i < v.length; i += 1) {
  36103. var codepoint = v.charCodeAt(i);
  36104. b[b.length] = (codepoint >> 8) & 0xff;
  36105. b[b.length] = codepoint & 0xff;
  36106. }
  36107. return b;
  36108. };
  36109. /**
  36110. * @param {string}
  36111. * @returns {number}
  36112. */
  36113. sizeOf.UTF16 = function(v) {
  36114. return v.length * 2;
  36115. };
  36116. // Data for converting old eight-bit Macintosh encodings to Unicode.
  36117. // This representation is optimized for decoding; encoding is slower
  36118. // and needs more memory. The assumption is that all opentype.js users
  36119. // want to open fonts, but saving a font will be comparatively rare
  36120. // so it can be more expensive. Keyed by IANA character set name.
  36121. //
  36122. // Python script for generating these strings:
  36123. //
  36124. // s = u''.join([chr(c).decode('mac_greek') for c in range(128, 256)])
  36125. // print(s.encode('utf-8'))
  36126. /**
  36127. * @private
  36128. */
  36129. var eightBitMacEncodings = {
  36130. // Python: 'mac_croatian'
  36131. 'x-mac-croatian':
  36132. 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®Š™´¨≠ŽØ∞±≤≥∆µ∂∑∏š∫ªºΩžø' +
  36133. '¿¡¬√ƒ≈ƫȅ ÀÃÕŒœĐ—“”‘’÷◊©⁄€‹›Æ»–·‚„‰ÂćÁčÈÍÎÏÌÓÔđÒÚÛÙıˆ˜¯πË˚¸Êæˇ',
  36134. // Python: 'mac_cyrillic'
  36135. 'x-mac-cyrillic':
  36136. 'АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњ' +
  36137. 'јЅ¬√ƒ≈∆«»… ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю',
  36138. // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/GAELIC.TXT
  36139. 'x-mac-gaelic':
  36140. 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØḂ±≤≥ḃĊċḊḋḞḟĠġṀæø' +
  36141. 'ṁṖṗɼƒſṠ«»… ÀÃÕŒœ–—“”‘’ṡẛÿŸṪ€‹›Ŷŷṫ·Ỳỳ⁊ÂÊÁËÈÍÎÏÌÓÔ♣ÒÚÛÙıÝýŴŵẄẅẀẁẂẃ',
  36142. // Python: 'mac_greek'
  36143. 'x-mac-greek':
  36144. 'Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩ' +
  36145. 'άΝ¬ΟΡ≈Τ«»… ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ\u00AD',
  36146. // Python: 'mac_iceland'
  36147. 'x-mac-icelandic':
  36148. 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüݰ¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +
  36149. '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€ÐðÞþý·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',
  36150. // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/INUIT.TXT
  36151. 'x-mac-inuit':
  36152. 'ᐃᐄᐅᐆᐊᐋᐱᐲᐳᐴᐸᐹᑉᑎᑏᑐᑑᑕᑖᑦᑭᑮᑯᑰᑲᑳᒃᒋᒌᒍᒎᒐᒑ°ᒡᒥᒦ•¶ᒧ®©™ᒨᒪᒫᒻᓂᓃᓄᓅᓇᓈᓐᓯᓰᓱᓲᓴᓵᔅᓕᓖᓗ' +
  36153. 'ᓘᓚᓛᓪᔨᔩᔪᔫᔭ… ᔮᔾᕕᕖᕗ–—“”‘’ᕘᕙᕚᕝᕆᕇᕈᕉᕋᕌᕐᕿᖀᖁᖂᖃᖄᖅᖏᖐᖑᖒᖓᖔᖕᙱᙲᙳᙴᙵᙶᖖᖠᖡᖢᖣᖤᖥᖦᕼŁł',
  36154. // Python: 'mac_latin2'
  36155. 'x-mac-ce':
  36156. 'ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅ' +
  36157. 'ņѬ√ńŇ∆«»… ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ',
  36158. // Python: 'mac_roman'
  36159. macintosh:
  36160. 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +
  36161. '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',
  36162. // Python: 'mac_romanian'
  36163. 'x-mac-romanian':
  36164. 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ĂȘ∞±≤≥¥µ∂∑∏π∫ªºΩăș' +
  36165. '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›Țț‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',
  36166. // Python: 'mac_turkish'
  36167. 'x-mac-turkish':
  36168. 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +
  36169. '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ'
  36170. };
  36171. /**
  36172. * Decodes an old-style Macintosh string. Returns either a Unicode JavaScript
  36173. * string, or 'undefined' if the encoding is unsupported. For example, we do
  36174. * not support Chinese, Japanese or Korean because these would need large
  36175. * mapping tables.
  36176. * @param {DataView} dataView
  36177. * @param {number} offset
  36178. * @param {number} dataLength
  36179. * @param {string} encoding
  36180. * @returns {string}
  36181. */
  36182. decode.MACSTRING = function(dataView, offset, dataLength, encoding) {
  36183. var table = eightBitMacEncodings[encoding];
  36184. if (table === undefined) {
  36185. return undefined;
  36186. }
  36187. var result = '';
  36188. for (var i = 0; i < dataLength; i++) {
  36189. var c = dataView.getUint8(offset + i);
  36190. // In all eight-bit Mac encodings, the characters 0x00..0x7F are
  36191. // mapped to U+0000..U+007F; we only need to look up the others.
  36192. if (c <= 0x7f) {
  36193. result += String.fromCharCode(c);
  36194. } else {
  36195. result += table[c & 0x7f];
  36196. }
  36197. }
  36198. return result;
  36199. };
  36200. // Helper function for encode.MACSTRING. Returns a dictionary for mapping
  36201. // Unicode character codes to their 8-bit MacOS equivalent. This table
  36202. // is not exactly a super cheap data structure, but we do not care because
  36203. // encoding Macintosh strings is only rarely needed in typical applications.
  36204. var macEncodingTableCache = typeof WeakMap === 'function' && new WeakMap();
  36205. var macEncodingCacheKeys;
  36206. var getMacEncodingTable = function(encoding) {
  36207. // Since we use encoding as a cache key for WeakMap, it has to be
  36208. // a String object and not a literal. And at least on NodeJS 2.10.1,
  36209. // WeakMap requires that the same String instance is passed for cache hits.
  36210. if (!macEncodingCacheKeys) {
  36211. macEncodingCacheKeys = {};
  36212. for (var e in eightBitMacEncodings) {
  36213. /*jshint -W053 */ // Suppress "Do not use String as a constructor."
  36214. macEncodingCacheKeys[e] = new String(e);
  36215. }
  36216. }
  36217. var cacheKey = macEncodingCacheKeys[encoding];
  36218. if (cacheKey === undefined) {
  36219. return undefined;
  36220. }
  36221. // We can't do "if (cache.has(key)) {return cache.get(key)}" here:
  36222. // since garbage collection may run at any time, it could also kick in
  36223. // between the calls to cache.has() and cache.get(). In that case,
  36224. // we would return 'undefined' even though we do support the encoding.
  36225. if (macEncodingTableCache) {
  36226. var cachedTable = macEncodingTableCache.get(cacheKey);
  36227. if (cachedTable !== undefined) {
  36228. return cachedTable;
  36229. }
  36230. }
  36231. var decodingTable = eightBitMacEncodings[encoding];
  36232. if (decodingTable === undefined) {
  36233. return undefined;
  36234. }
  36235. var encodingTable = {};
  36236. for (var i = 0; i < decodingTable.length; i++) {
  36237. encodingTable[decodingTable.charCodeAt(i)] = i + 0x80;
  36238. }
  36239. if (macEncodingTableCache) {
  36240. macEncodingTableCache.set(cacheKey, encodingTable);
  36241. }
  36242. return encodingTable;
  36243. };
  36244. /**
  36245. * Encodes an old-style Macintosh string. Returns a byte array upon success.
  36246. * If the requested encoding is unsupported, or if the input string contains
  36247. * a character that cannot be expressed in the encoding, the function returns
  36248. * 'undefined'.
  36249. * @param {string} str
  36250. * @param {string} encoding
  36251. * @returns {Array}
  36252. */
  36253. encode.MACSTRING = function(str, encoding) {
  36254. var table = getMacEncodingTable(encoding);
  36255. if (table === undefined) {
  36256. return undefined;
  36257. }
  36258. var result = [];
  36259. for (var i = 0; i < str.length; i++) {
  36260. var c = str.charCodeAt(i);
  36261. // In all eight-bit Mac encodings, the characters 0x00..0x7F are
  36262. // mapped to U+0000..U+007F; we only need to look up the others.
  36263. if (c >= 0x80) {
  36264. c = table[c];
  36265. if (c === undefined) {
  36266. // str contains a Unicode character that cannot be encoded
  36267. // in the requested encoding.
  36268. return undefined;
  36269. }
  36270. }
  36271. result[i] = c;
  36272. // result.push(c);
  36273. }
  36274. return result;
  36275. };
  36276. /**
  36277. * @param {string} str
  36278. * @param {string} encoding
  36279. * @returns {number}
  36280. */
  36281. sizeOf.MACSTRING = function(str, encoding) {
  36282. var b = encode.MACSTRING(str, encoding);
  36283. if (b !== undefined) {
  36284. return b.length;
  36285. } else {
  36286. return 0;
  36287. }
  36288. };
  36289. // Helper for encode.VARDELTAS
  36290. function isByteEncodable(value) {
  36291. return value >= -128 && value <= 127;
  36292. }
  36293. // Helper for encode.VARDELTAS
  36294. function encodeVarDeltaRunAsZeroes(deltas, pos, result) {
  36295. var runLength = 0;
  36296. var numDeltas = deltas.length;
  36297. while (pos < numDeltas && runLength < 64 && deltas[pos] === 0) {
  36298. ++pos;
  36299. ++runLength;
  36300. }
  36301. result.push(0x80 | (runLength - 1));
  36302. return pos;
  36303. }
  36304. // Helper for encode.VARDELTAS
  36305. function encodeVarDeltaRunAsBytes(deltas, offset, result) {
  36306. var runLength = 0;
  36307. var numDeltas = deltas.length;
  36308. var pos = offset;
  36309. while (pos < numDeltas && runLength < 64) {
  36310. var value = deltas[pos];
  36311. if (!isByteEncodable(value)) {
  36312. break;
  36313. }
  36314. // Within a byte-encoded run of deltas, a single zero is best
  36315. // stored literally as 0x00 value. However, if we have two or
  36316. // more zeroes in a sequence, it is better to start a new run.
  36317. // Fore example, the sequence of deltas [15, 15, 0, 15, 15]
  36318. // becomes 6 bytes (04 0F 0F 00 0F 0F) when storing the zero
  36319. // within the current run, but 7 bytes (01 0F 0F 80 01 0F 0F)
  36320. // when starting a new run.
  36321. if (value === 0 && pos + 1 < numDeltas && deltas[pos + 1] === 0) {
  36322. break;
  36323. }
  36324. ++pos;
  36325. ++runLength;
  36326. }
  36327. result.push(runLength - 1);
  36328. for (var i = offset; i < pos; ++i) {
  36329. result.push((deltas[i] + 256) & 0xff);
  36330. }
  36331. return pos;
  36332. }
  36333. // Helper for encode.VARDELTAS
  36334. function encodeVarDeltaRunAsWords(deltas, offset, result) {
  36335. var runLength = 0;
  36336. var numDeltas = deltas.length;
  36337. var pos = offset;
  36338. while (pos < numDeltas && runLength < 64) {
  36339. var value = deltas[pos];
  36340. // Within a word-encoded run of deltas, it is easiest to start
  36341. // a new run (with a different encoding) whenever we encounter
  36342. // a zero value. For example, the sequence [0x6666, 0, 0x7777]
  36343. // needs 7 bytes when storing the zero inside the current run
  36344. // (42 66 66 00 00 77 77), and equally 7 bytes when starting a
  36345. // new run (40 66 66 80 40 77 77).
  36346. if (value === 0) {
  36347. break;
  36348. }
  36349. // Within a word-encoded run of deltas, a single value in the
  36350. // range (-128..127) should be encoded within the current run
  36351. // because it is more compact. For example, the sequence
  36352. // [0x6666, 2, 0x7777] becomes 7 bytes when storing the value
  36353. // literally (42 66 66 00 02 77 77), but 8 bytes when starting
  36354. // a new run (40 66 66 00 02 40 77 77).
  36355. if (
  36356. isByteEncodable(value) &&
  36357. pos + 1 < numDeltas &&
  36358. isByteEncodable(deltas[pos + 1])
  36359. ) {
  36360. break;
  36361. }
  36362. ++pos;
  36363. ++runLength;
  36364. }
  36365. result.push(0x40 | (runLength - 1));
  36366. for (var i = offset; i < pos; ++i) {
  36367. var val = deltas[i];
  36368. result.push(((val + 0x10000) >> 8) & 0xff, (val + 0x100) & 0xff);
  36369. }
  36370. return pos;
  36371. }
  36372. /**
  36373. * Encode a list of variation adjustment deltas.
  36374. *
  36375. * Variation adjustment deltas are used in ‘gvar’ and ‘cvar’ tables.
  36376. * They indicate how points (in ‘gvar’) or values (in ‘cvar’) get adjusted
  36377. * when generating instances of variation fonts.
  36378. *
  36379. * @see https://www.microsoft.com/typography/otspec/gvar.htm
  36380. * @see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6gvar.html
  36381. * @param {Array}
  36382. * @return {Array}
  36383. */
  36384. encode.VARDELTAS = function(deltas) {
  36385. var pos = 0;
  36386. var result = [];
  36387. while (pos < deltas.length) {
  36388. var value = deltas[pos];
  36389. if (value === 0) {
  36390. pos = encodeVarDeltaRunAsZeroes(deltas, pos, result);
  36391. } else if (value >= -128 && value <= 127) {
  36392. pos = encodeVarDeltaRunAsBytes(deltas, pos, result);
  36393. } else {
  36394. pos = encodeVarDeltaRunAsWords(deltas, pos, result);
  36395. }
  36396. }
  36397. return result;
  36398. };
  36399. // Convert a list of values to a CFF INDEX structure.
  36400. // The values should be objects containing name / type / value.
  36401. /**
  36402. * @param {Array} l
  36403. * @returns {Array}
  36404. */
  36405. encode.INDEX = function(l) {
  36406. //var offset, offsets, offsetEncoder, encodedOffsets, encodedOffset, data,
  36407. // i, v;
  36408. // Because we have to know which data type to use to encode the offsets,
  36409. // we have to go through the values twice: once to encode the data and
  36410. // calculate the offsets, then again to encode the offsets using the fitting data type.
  36411. var offset = 1; // First offset is always 1.
  36412. var offsets = [offset];
  36413. var data = [];
  36414. for (var i = 0; i < l.length; i += 1) {
  36415. var v = encode.OBJECT(l[i]);
  36416. Array.prototype.push.apply(data, v);
  36417. offset += v.length;
  36418. offsets.push(offset);
  36419. }
  36420. if (data.length === 0) {
  36421. return [0, 0];
  36422. }
  36423. var encodedOffsets = [];
  36424. var offSize = (1 + Math.floor(Math.log(offset) / Math.log(2)) / 8) | 0;
  36425. var offsetEncoder = [
  36426. undefined,
  36427. encode.BYTE,
  36428. encode.USHORT,
  36429. encode.UINT24,
  36430. encode.ULONG
  36431. ][offSize];
  36432. for (var i$1 = 0; i$1 < offsets.length; i$1 += 1) {
  36433. var encodedOffset = offsetEncoder(offsets[i$1]);
  36434. Array.prototype.push.apply(encodedOffsets, encodedOffset);
  36435. }
  36436. return Array.prototype.concat(
  36437. encode.Card16(l.length),
  36438. encode.OffSize(offSize),
  36439. encodedOffsets,
  36440. data
  36441. );
  36442. };
  36443. /**
  36444. * @param {Array}
  36445. * @returns {number}
  36446. */
  36447. sizeOf.INDEX = function(v) {
  36448. return encode.INDEX(v).length;
  36449. };
  36450. /**
  36451. * Convert an object to a CFF DICT structure.
  36452. * The keys should be numeric.
  36453. * The values should be objects containing name / type / value.
  36454. * @param {Object} m
  36455. * @returns {Array}
  36456. */
  36457. encode.DICT = function(m) {
  36458. var d = [];
  36459. var keys = Object.keys(m);
  36460. var length = keys.length;
  36461. for (var i = 0; i < length; i += 1) {
  36462. // Object.keys() return string keys, but our keys are always numeric.
  36463. var k = parseInt(keys[i], 0);
  36464. var v = m[k];
  36465. // Value comes before the key.
  36466. d = d.concat(encode.OPERAND(v.value, v.type));
  36467. d = d.concat(encode.OPERATOR(k));
  36468. }
  36469. return d;
  36470. };
  36471. /**
  36472. * @param {Object}
  36473. * @returns {number}
  36474. */
  36475. sizeOf.DICT = function(m) {
  36476. return encode.DICT(m).length;
  36477. };
  36478. /**
  36479. * @param {number}
  36480. * @returns {Array}
  36481. */
  36482. encode.OPERATOR = function(v) {
  36483. if (v < 1200) {
  36484. return [v];
  36485. } else {
  36486. return [12, v - 1200];
  36487. }
  36488. };
  36489. /**
  36490. * @param {Array} v
  36491. * @param {string}
  36492. * @returns {Array}
  36493. */
  36494. encode.OPERAND = function(v, type) {
  36495. var d = [];
  36496. if (Array.isArray(type)) {
  36497. for (var i = 0; i < type.length; i += 1) {
  36498. check.argument(
  36499. v.length === type.length,
  36500. 'Not enough arguments given for type' + type
  36501. );
  36502. d = d.concat(encode.OPERAND(v[i], type[i]));
  36503. }
  36504. } else {
  36505. if (type === 'SID') {
  36506. d = d.concat(encode.NUMBER(v));
  36507. } else if (type === 'offset') {
  36508. // We make it easy for ourselves and always encode offsets as
  36509. // 4 bytes. This makes offset calculation for the top dict easier.
  36510. d = d.concat(encode.NUMBER32(v));
  36511. } else if (type === 'number') {
  36512. d = d.concat(encode.NUMBER(v));
  36513. } else if (type === 'real') {
  36514. d = d.concat(encode.REAL(v));
  36515. } else {
  36516. throw new Error('Unknown operand type ' + type);
  36517. // FIXME Add support for booleans
  36518. }
  36519. }
  36520. return d;
  36521. };
  36522. encode.OP = encode.BYTE;
  36523. sizeOf.OP = sizeOf.BYTE;
  36524. // memoize charstring encoding using WeakMap if available
  36525. var wmm = typeof WeakMap === 'function' && new WeakMap();
  36526. /**
  36527. * Convert a list of CharString operations to bytes.
  36528. * @param {Array}
  36529. * @returns {Array}
  36530. */
  36531. encode.CHARSTRING = function(ops) {
  36532. // See encode.MACSTRING for why we don't do "if (wmm && wmm.has(ops))".
  36533. if (wmm) {
  36534. var cachedValue = wmm.get(ops);
  36535. if (cachedValue !== undefined) {
  36536. return cachedValue;
  36537. }
  36538. }
  36539. var d = [];
  36540. var length = ops.length;
  36541. for (var i = 0; i < length; i += 1) {
  36542. var op = ops[i];
  36543. d = d.concat(encode[op.type](op.value));
  36544. }
  36545. if (wmm) {
  36546. wmm.set(ops, d);
  36547. }
  36548. return d;
  36549. };
  36550. /**
  36551. * @param {Array}
  36552. * @returns {number}
  36553. */
  36554. sizeOf.CHARSTRING = function(ops) {
  36555. return encode.CHARSTRING(ops).length;
  36556. };
  36557. // Utility functions ////////////////////////////////////////////////////////
  36558. /**
  36559. * Convert an object containing name / type / value to bytes.
  36560. * @param {Object}
  36561. * @returns {Array}
  36562. */
  36563. encode.OBJECT = function(v) {
  36564. var encodingFunction = encode[v.type];
  36565. check.argument(
  36566. encodingFunction !== undefined,
  36567. 'No encoding function for type ' + v.type
  36568. );
  36569. return encodingFunction(v.value);
  36570. };
  36571. /**
  36572. * @param {Object}
  36573. * @returns {number}
  36574. */
  36575. sizeOf.OBJECT = function(v) {
  36576. var sizeOfFunction = sizeOf[v.type];
  36577. check.argument(
  36578. sizeOfFunction !== undefined,
  36579. 'No sizeOf function for type ' + v.type
  36580. );
  36581. return sizeOfFunction(v.value);
  36582. };
  36583. /**
  36584. * Convert a table object to bytes.
  36585. * A table contains a list of fields containing the metadata (name, type and default value).
  36586. * The table itself has the field values set as attributes.
  36587. * @param {opentype.Table}
  36588. * @returns {Array}
  36589. */
  36590. encode.TABLE = function(table) {
  36591. var d = [];
  36592. var length = table.fields.length;
  36593. var subtables = [];
  36594. var subtableOffsets = [];
  36595. for (var i = 0; i < length; i += 1) {
  36596. var field = table.fields[i];
  36597. var encodingFunction = encode[field.type];
  36598. check.argument(
  36599. encodingFunction !== undefined,
  36600. 'No encoding function for field type ' +
  36601. field.type +
  36602. ' (' +
  36603. field.name +
  36604. ')'
  36605. );
  36606. var value = table[field.name];
  36607. if (value === undefined) {
  36608. value = field.value;
  36609. }
  36610. var bytes = encodingFunction(value);
  36611. if (field.type === 'TABLE') {
  36612. subtableOffsets.push(d.length);
  36613. d = d.concat([0, 0]);
  36614. subtables.push(bytes);
  36615. } else {
  36616. d = d.concat(bytes);
  36617. }
  36618. }
  36619. for (var i$1 = 0; i$1 < subtables.length; i$1 += 1) {
  36620. var o = subtableOffsets[i$1];
  36621. var offset = d.length;
  36622. check.argument(offset < 65536, 'Table ' + table.tableName + ' too big.');
  36623. d[o] = offset >> 8;
  36624. d[o + 1] = offset & 0xff;
  36625. d = d.concat(subtables[i$1]);
  36626. }
  36627. return d;
  36628. };
  36629. /**
  36630. * @param {opentype.Table}
  36631. * @returns {number}
  36632. */
  36633. sizeOf.TABLE = function(table) {
  36634. var numBytes = 0;
  36635. var length = table.fields.length;
  36636. for (var i = 0; i < length; i += 1) {
  36637. var field = table.fields[i];
  36638. var sizeOfFunction = sizeOf[field.type];
  36639. check.argument(
  36640. sizeOfFunction !== undefined,
  36641. 'No sizeOf function for field type ' +
  36642. field.type +
  36643. ' (' +
  36644. field.name +
  36645. ')'
  36646. );
  36647. var value = table[field.name];
  36648. if (value === undefined) {
  36649. value = field.value;
  36650. }
  36651. numBytes += sizeOfFunction(value);
  36652. // Subtables take 2 more bytes for offsets.
  36653. if (field.type === 'TABLE') {
  36654. numBytes += 2;
  36655. }
  36656. }
  36657. return numBytes;
  36658. };
  36659. encode.RECORD = encode.TABLE;
  36660. sizeOf.RECORD = sizeOf.TABLE;
  36661. // Merge in a list of bytes.
  36662. encode.LITERAL = function(v) {
  36663. return v;
  36664. };
  36665. sizeOf.LITERAL = function(v) {
  36666. return v.length;
  36667. };
  36668. // Table metadata
  36669. /**
  36670. * @exports opentype.Table
  36671. * @class
  36672. * @param {string} tableName
  36673. * @param {Array} fields
  36674. * @param {Object} options
  36675. * @constructor
  36676. */
  36677. function Table(tableName, fields, options) {
  36678. var this$1 = this;
  36679. for (var i = 0; i < fields.length; i += 1) {
  36680. var field = fields[i];
  36681. this$1[field.name] = field.value;
  36682. }
  36683. this.tableName = tableName;
  36684. this.fields = fields;
  36685. if (options) {
  36686. var optionKeys = Object.keys(options);
  36687. for (var i$1 = 0; i$1 < optionKeys.length; i$1 += 1) {
  36688. var k = optionKeys[i$1];
  36689. var v = options[k];
  36690. if (this$1[k] !== undefined) {
  36691. this$1[k] = v;
  36692. }
  36693. }
  36694. }
  36695. }
  36696. /**
  36697. * Encodes the table and returns an array of bytes
  36698. * @return {Array}
  36699. */
  36700. Table.prototype.encode = function() {
  36701. return encode.TABLE(this);
  36702. };
  36703. /**
  36704. * Get the size of the table.
  36705. * @return {number}
  36706. */
  36707. Table.prototype.sizeOf = function() {
  36708. return sizeOf.TABLE(this);
  36709. };
  36710. /**
  36711. * @private
  36712. */
  36713. function ushortList(itemName, list, count) {
  36714. if (count === undefined) {
  36715. count = list.length;
  36716. }
  36717. var fields = new Array(list.length + 1);
  36718. fields[0] = { name: itemName + 'Count', type: 'USHORT', value: count };
  36719. for (var i = 0; i < list.length; i++) {
  36720. fields[i + 1] = { name: itemName + i, type: 'USHORT', value: list[i] };
  36721. }
  36722. return fields;
  36723. }
  36724. /**
  36725. * @private
  36726. */
  36727. function tableList(itemName, records, itemCallback) {
  36728. var count = records.length;
  36729. var fields = new Array(count + 1);
  36730. fields[0] = { name: itemName + 'Count', type: 'USHORT', value: count };
  36731. for (var i = 0; i < count; i++) {
  36732. fields[i + 1] = {
  36733. name: itemName + i,
  36734. type: 'TABLE',
  36735. value: itemCallback(records[i], i)
  36736. };
  36737. }
  36738. return fields;
  36739. }
  36740. /**
  36741. * @private
  36742. */
  36743. function recordList(itemName, records, itemCallback) {
  36744. var count = records.length;
  36745. var fields = [];
  36746. fields[0] = { name: itemName + 'Count', type: 'USHORT', value: count };
  36747. for (var i = 0; i < count; i++) {
  36748. fields = fields.concat(itemCallback(records[i], i));
  36749. }
  36750. return fields;
  36751. }
  36752. // Common Layout Tables
  36753. /**
  36754. * @exports opentype.Coverage
  36755. * @class
  36756. * @param {opentype.Table}
  36757. * @constructor
  36758. * @extends opentype.Table
  36759. */
  36760. function Coverage(coverageTable) {
  36761. if (coverageTable.format === 1) {
  36762. Table.call(
  36763. this,
  36764. 'coverageTable',
  36765. [{ name: 'coverageFormat', type: 'USHORT', value: 1 }].concat(
  36766. ushortList('glyph', coverageTable.glyphs)
  36767. )
  36768. );
  36769. } else {
  36770. check.assert(false, "Can't create coverage table format 2 yet.");
  36771. }
  36772. }
  36773. Coverage.prototype = Object.create(Table.prototype);
  36774. Coverage.prototype.constructor = Coverage;
  36775. function ScriptList(scriptListTable) {
  36776. Table.call(
  36777. this,
  36778. 'scriptListTable',
  36779. recordList('scriptRecord', scriptListTable, function(scriptRecord, i) {
  36780. var script = scriptRecord.script;
  36781. var defaultLangSys = script.defaultLangSys;
  36782. check.assert(
  36783. !!defaultLangSys,
  36784. 'Unable to write GSUB: script ' +
  36785. scriptRecord.tag +
  36786. ' has no default language system.'
  36787. );
  36788. return [
  36789. { name: 'scriptTag' + i, type: 'TAG', value: scriptRecord.tag },
  36790. {
  36791. name: 'script' + i,
  36792. type: 'TABLE',
  36793. value: new Table(
  36794. 'scriptTable',
  36795. [
  36796. {
  36797. name: 'defaultLangSys',
  36798. type: 'TABLE',
  36799. value: new Table(
  36800. 'defaultLangSys',
  36801. [
  36802. { name: 'lookupOrder', type: 'USHORT', value: 0 },
  36803. {
  36804. name: 'reqFeatureIndex',
  36805. type: 'USHORT',
  36806. value: defaultLangSys.reqFeatureIndex
  36807. }
  36808. ].concat(
  36809. ushortList('featureIndex', defaultLangSys.featureIndexes)
  36810. )
  36811. )
  36812. }
  36813. ].concat(
  36814. recordList('langSys', script.langSysRecords, function(
  36815. langSysRecord,
  36816. i
  36817. ) {
  36818. var langSys = langSysRecord.langSys;
  36819. return [
  36820. {
  36821. name: 'langSysTag' + i,
  36822. type: 'TAG',
  36823. value: langSysRecord.tag
  36824. },
  36825. {
  36826. name: 'langSys' + i,
  36827. type: 'TABLE',
  36828. value: new Table(
  36829. 'langSys',
  36830. [
  36831. { name: 'lookupOrder', type: 'USHORT', value: 0 },
  36832. {
  36833. name: 'reqFeatureIndex',
  36834. type: 'USHORT',
  36835. value: langSys.reqFeatureIndex
  36836. }
  36837. ].concat(
  36838. ushortList('featureIndex', langSys.featureIndexes)
  36839. )
  36840. )
  36841. }
  36842. ];
  36843. })
  36844. )
  36845. )
  36846. }
  36847. ];
  36848. })
  36849. );
  36850. }
  36851. ScriptList.prototype = Object.create(Table.prototype);
  36852. ScriptList.prototype.constructor = ScriptList;
  36853. /**
  36854. * @exports opentype.FeatureList
  36855. * @class
  36856. * @param {opentype.Table}
  36857. * @constructor
  36858. * @extends opentype.Table
  36859. */
  36860. function FeatureList(featureListTable) {
  36861. Table.call(
  36862. this,
  36863. 'featureListTable',
  36864. recordList('featureRecord', featureListTable, function(featureRecord, i) {
  36865. var feature = featureRecord.feature;
  36866. return [
  36867. { name: 'featureTag' + i, type: 'TAG', value: featureRecord.tag },
  36868. {
  36869. name: 'feature' + i,
  36870. type: 'TABLE',
  36871. value: new Table(
  36872. 'featureTable',
  36873. [
  36874. {
  36875. name: 'featureParams',
  36876. type: 'USHORT',
  36877. value: feature.featureParams
  36878. }
  36879. ].concat(ushortList('lookupListIndex', feature.lookupListIndexes))
  36880. )
  36881. }
  36882. ];
  36883. })
  36884. );
  36885. }
  36886. FeatureList.prototype = Object.create(Table.prototype);
  36887. FeatureList.prototype.constructor = FeatureList;
  36888. /**
  36889. * @exports opentype.LookupList
  36890. * @class
  36891. * @param {opentype.Table}
  36892. * @param {Object}
  36893. * @constructor
  36894. * @extends opentype.Table
  36895. */
  36896. function LookupList(lookupListTable, subtableMakers) {
  36897. Table.call(
  36898. this,
  36899. 'lookupListTable',
  36900. tableList('lookup', lookupListTable, function(lookupTable) {
  36901. var subtableCallback = subtableMakers[lookupTable.lookupType];
  36902. check.assert(
  36903. !!subtableCallback,
  36904. 'Unable to write GSUB lookup type ' +
  36905. lookupTable.lookupType +
  36906. ' tables.'
  36907. );
  36908. return new Table(
  36909. 'lookupTable',
  36910. [
  36911. {
  36912. name: 'lookupType',
  36913. type: 'USHORT',
  36914. value: lookupTable.lookupType
  36915. },
  36916. {
  36917. name: 'lookupFlag',
  36918. type: 'USHORT',
  36919. value: lookupTable.lookupFlag
  36920. }
  36921. ].concat(
  36922. tableList('subtable', lookupTable.subtables, subtableCallback)
  36923. )
  36924. );
  36925. })
  36926. );
  36927. }
  36928. LookupList.prototype = Object.create(Table.prototype);
  36929. LookupList.prototype.constructor = LookupList;
  36930. // Record = same as Table, but inlined (a Table has an offset and its data is further in the stream)
  36931. // Don't use offsets inside Records (probable bug), only in Tables.
  36932. var table = {
  36933. Table: Table,
  36934. Record: Table,
  36935. Coverage: Coverage,
  36936. ScriptList: ScriptList,
  36937. FeatureList: FeatureList,
  36938. LookupList: LookupList,
  36939. ushortList: ushortList,
  36940. tableList: tableList,
  36941. recordList: recordList
  36942. };
  36943. // Parsing utility functions
  36944. // Retrieve an unsigned byte from the DataView.
  36945. function getByte(dataView, offset) {
  36946. return dataView.getUint8(offset);
  36947. }
  36948. // Retrieve an unsigned 16-bit short from the DataView.
  36949. // The value is stored in big endian.
  36950. function getUShort(dataView, offset) {
  36951. return dataView.getUint16(offset, false);
  36952. }
  36953. // Retrieve a signed 16-bit short from the DataView.
  36954. // The value is stored in big endian.
  36955. function getShort(dataView, offset) {
  36956. return dataView.getInt16(offset, false);
  36957. }
  36958. // Retrieve an unsigned 32-bit long from the DataView.
  36959. // The value is stored in big endian.
  36960. function getULong(dataView, offset) {
  36961. return dataView.getUint32(offset, false);
  36962. }
  36963. // Retrieve a 32-bit signed fixed-point number (16.16) from the DataView.
  36964. // The value is stored in big endian.
  36965. function getFixed(dataView, offset) {
  36966. var decimal = dataView.getInt16(offset, false);
  36967. var fraction = dataView.getUint16(offset + 2, false);
  36968. return decimal + fraction / 65535;
  36969. }
  36970. // Retrieve a 4-character tag from the DataView.
  36971. // Tags are used to identify tables.
  36972. function getTag(dataView, offset) {
  36973. var tag = '';
  36974. for (var i = offset; i < offset + 4; i += 1) {
  36975. tag += String.fromCharCode(dataView.getInt8(i));
  36976. }
  36977. return tag;
  36978. }
  36979. // Retrieve an offset from the DataView.
  36980. // Offsets are 1 to 4 bytes in length, depending on the offSize argument.
  36981. function getOffset(dataView, offset, offSize) {
  36982. var v = 0;
  36983. for (var i = 0; i < offSize; i += 1) {
  36984. v <<= 8;
  36985. v += dataView.getUint8(offset + i);
  36986. }
  36987. return v;
  36988. }
  36989. // Retrieve a number of bytes from start offset to the end offset from the DataView.
  36990. function getBytes(dataView, startOffset, endOffset) {
  36991. var bytes = [];
  36992. for (var i = startOffset; i < endOffset; i += 1) {
  36993. bytes.push(dataView.getUint8(i));
  36994. }
  36995. return bytes;
  36996. }
  36997. // Convert the list of bytes to a string.
  36998. function bytesToString(bytes) {
  36999. var s = '';
  37000. for (var i = 0; i < bytes.length; i += 1) {
  37001. s += String.fromCharCode(bytes[i]);
  37002. }
  37003. return s;
  37004. }
  37005. var typeOffsets = {
  37006. byte: 1,
  37007. uShort: 2,
  37008. short: 2,
  37009. uLong: 4,
  37010. fixed: 4,
  37011. longDateTime: 8,
  37012. tag: 4
  37013. };
  37014. // A stateful parser that changes the offset whenever a value is retrieved.
  37015. // The data is a DataView.
  37016. function Parser(data, offset) {
  37017. this.data = data;
  37018. this.offset = offset;
  37019. this.relativeOffset = 0;
  37020. }
  37021. Parser.prototype.parseByte = function() {
  37022. var v = this.data.getUint8(this.offset + this.relativeOffset);
  37023. this.relativeOffset += 1;
  37024. return v;
  37025. };
  37026. Parser.prototype.parseChar = function() {
  37027. var v = this.data.getInt8(this.offset + this.relativeOffset);
  37028. this.relativeOffset += 1;
  37029. return v;
  37030. };
  37031. Parser.prototype.parseCard8 = Parser.prototype.parseByte;
  37032. Parser.prototype.parseUShort = function() {
  37033. var v = this.data.getUint16(this.offset + this.relativeOffset);
  37034. this.relativeOffset += 2;
  37035. return v;
  37036. };
  37037. Parser.prototype.parseCard16 = Parser.prototype.parseUShort;
  37038. Parser.prototype.parseSID = Parser.prototype.parseUShort;
  37039. Parser.prototype.parseOffset16 = Parser.prototype.parseUShort;
  37040. Parser.prototype.parseShort = function() {
  37041. var v = this.data.getInt16(this.offset + this.relativeOffset);
  37042. this.relativeOffset += 2;
  37043. return v;
  37044. };
  37045. Parser.prototype.parseF2Dot14 = function() {
  37046. var v = this.data.getInt16(this.offset + this.relativeOffset) / 16384;
  37047. this.relativeOffset += 2;
  37048. return v;
  37049. };
  37050. Parser.prototype.parseULong = function() {
  37051. var v = getULong(this.data, this.offset + this.relativeOffset);
  37052. this.relativeOffset += 4;
  37053. return v;
  37054. };
  37055. Parser.prototype.parseOffset32 = Parser.prototype.parseULong;
  37056. Parser.prototype.parseFixed = function() {
  37057. var v = getFixed(this.data, this.offset + this.relativeOffset);
  37058. this.relativeOffset += 4;
  37059. return v;
  37060. };
  37061. Parser.prototype.parseString = function(length) {
  37062. var dataView = this.data;
  37063. var offset = this.offset + this.relativeOffset;
  37064. var string = '';
  37065. this.relativeOffset += length;
  37066. for (var i = 0; i < length; i++) {
  37067. string += String.fromCharCode(dataView.getUint8(offset + i));
  37068. }
  37069. return string;
  37070. };
  37071. Parser.prototype.parseTag = function() {
  37072. return this.parseString(4);
  37073. };
  37074. // LONGDATETIME is a 64-bit integer.
  37075. // JavaScript and unix timestamps traditionally use 32 bits, so we
  37076. // only take the last 32 bits.
  37077. // + Since until 2038 those bits will be filled by zeros we can ignore them.
  37078. Parser.prototype.parseLongDateTime = function() {
  37079. var v = getULong(this.data, this.offset + this.relativeOffset + 4);
  37080. // Subtract seconds between 01/01/1904 and 01/01/1970
  37081. // to convert Apple Mac timestamp to Standard Unix timestamp
  37082. v -= 2082844800;
  37083. this.relativeOffset += 8;
  37084. return v;
  37085. };
  37086. Parser.prototype.parseVersion = function(minorBase) {
  37087. var major = getUShort(this.data, this.offset + this.relativeOffset);
  37088. // How to interpret the minor version is very vague in the spec. 0x5000 is 5, 0x1000 is 1
  37089. // Default returns the correct number if minor = 0xN000 where N is 0-9
  37090. // Set minorBase to 1 for tables that use minor = N where N is 0-9
  37091. var minor = getUShort(this.data, this.offset + this.relativeOffset + 2);
  37092. this.relativeOffset += 4;
  37093. if (minorBase === undefined) {
  37094. minorBase = 0x1000;
  37095. }
  37096. return major + minor / minorBase / 10;
  37097. };
  37098. Parser.prototype.skip = function(type, amount) {
  37099. if (amount === undefined) {
  37100. amount = 1;
  37101. }
  37102. this.relativeOffset += typeOffsets[type] * amount;
  37103. };
  37104. ///// Parsing lists and records ///////////////////////////////
  37105. // Parse a list of 32 bit unsigned integers.
  37106. Parser.prototype.parseULongList = function(count) {
  37107. if (count === undefined) {
  37108. count = this.parseULong();
  37109. }
  37110. var offsets = new Array(count);
  37111. var dataView = this.data;
  37112. var offset = this.offset + this.relativeOffset;
  37113. for (var i = 0; i < count; i++) {
  37114. offsets[i] = dataView.getUint32(offset);
  37115. offset += 4;
  37116. }
  37117. this.relativeOffset += count * 4;
  37118. return offsets;
  37119. };
  37120. // Parse a list of 16 bit unsigned integers. The length of the list can be read on the stream
  37121. // or provided as an argument.
  37122. Parser.prototype.parseOffset16List = Parser.prototype.parseUShortList = function(
  37123. count
  37124. ) {
  37125. if (count === undefined) {
  37126. count = this.parseUShort();
  37127. }
  37128. var offsets = new Array(count);
  37129. var dataView = this.data;
  37130. var offset = this.offset + this.relativeOffset;
  37131. for (var i = 0; i < count; i++) {
  37132. offsets[i] = dataView.getUint16(offset);
  37133. offset += 2;
  37134. }
  37135. this.relativeOffset += count * 2;
  37136. return offsets;
  37137. };
  37138. // Parses a list of 16 bit signed integers.
  37139. Parser.prototype.parseShortList = function(count) {
  37140. var list = new Array(count);
  37141. var dataView = this.data;
  37142. var offset = this.offset + this.relativeOffset;
  37143. for (var i = 0; i < count; i++) {
  37144. list[i] = dataView.getInt16(offset);
  37145. offset += 2;
  37146. }
  37147. this.relativeOffset += count * 2;
  37148. return list;
  37149. };
  37150. // Parses a list of bytes.
  37151. Parser.prototype.parseByteList = function(count) {
  37152. var list = new Array(count);
  37153. var dataView = this.data;
  37154. var offset = this.offset + this.relativeOffset;
  37155. for (var i = 0; i < count; i++) {
  37156. list[i] = dataView.getUint8(offset++);
  37157. }
  37158. this.relativeOffset += count;
  37159. return list;
  37160. };
  37161. /**
  37162. * Parse a list of items.
  37163. * Record count is optional, if omitted it is read from the stream.
  37164. * itemCallback is one of the Parser methods.
  37165. */
  37166. Parser.prototype.parseList = function(count, itemCallback) {
  37167. var this$1 = this;
  37168. if (!itemCallback) {
  37169. itemCallback = count;
  37170. count = this.parseUShort();
  37171. }
  37172. var list = new Array(count);
  37173. for (var i = 0; i < count; i++) {
  37174. list[i] = itemCallback.call(this$1);
  37175. }
  37176. return list;
  37177. };
  37178. Parser.prototype.parseList32 = function(count, itemCallback) {
  37179. var this$1 = this;
  37180. if (!itemCallback) {
  37181. itemCallback = count;
  37182. count = this.parseULong();
  37183. }
  37184. var list = new Array(count);
  37185. for (var i = 0; i < count; i++) {
  37186. list[i] = itemCallback.call(this$1);
  37187. }
  37188. return list;
  37189. };
  37190. /**
  37191. * Parse a list of records.
  37192. * Record count is optional, if omitted it is read from the stream.
  37193. * Example of recordDescription: { sequenceIndex: Parser.uShort, lookupListIndex: Parser.uShort }
  37194. */
  37195. Parser.prototype.parseRecordList = function(count, recordDescription) {
  37196. var this$1 = this;
  37197. // If the count argument is absent, read it in the stream.
  37198. if (!recordDescription) {
  37199. recordDescription = count;
  37200. count = this.parseUShort();
  37201. }
  37202. var records = new Array(count);
  37203. var fields = Object.keys(recordDescription);
  37204. for (var i = 0; i < count; i++) {
  37205. var rec = {};
  37206. for (var j = 0; j < fields.length; j++) {
  37207. var fieldName = fields[j];
  37208. var fieldType = recordDescription[fieldName];
  37209. rec[fieldName] = fieldType.call(this$1);
  37210. }
  37211. records[i] = rec;
  37212. }
  37213. return records;
  37214. };
  37215. Parser.prototype.parseRecordList32 = function(count, recordDescription) {
  37216. var this$1 = this;
  37217. // If the count argument is absent, read it in the stream.
  37218. if (!recordDescription) {
  37219. recordDescription = count;
  37220. count = this.parseULong();
  37221. }
  37222. var records = new Array(count);
  37223. var fields = Object.keys(recordDescription);
  37224. for (var i = 0; i < count; i++) {
  37225. var rec = {};
  37226. for (var j = 0; j < fields.length; j++) {
  37227. var fieldName = fields[j];
  37228. var fieldType = recordDescription[fieldName];
  37229. rec[fieldName] = fieldType.call(this$1);
  37230. }
  37231. records[i] = rec;
  37232. }
  37233. return records;
  37234. };
  37235. // Parse a data structure into an object
  37236. // Example of description: { sequenceIndex: Parser.uShort, lookupListIndex: Parser.uShort }
  37237. Parser.prototype.parseStruct = function(description) {
  37238. var this$1 = this;
  37239. if (typeof description === 'function') {
  37240. return description.call(this);
  37241. } else {
  37242. var fields = Object.keys(description);
  37243. var struct = {};
  37244. for (var j = 0; j < fields.length; j++) {
  37245. var fieldName = fields[j];
  37246. var fieldType = description[fieldName];
  37247. struct[fieldName] = fieldType.call(this$1);
  37248. }
  37249. return struct;
  37250. }
  37251. };
  37252. /**
  37253. * Parse a GPOS valueRecord
  37254. * https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#value-record
  37255. * valueFormat is optional, if omitted it is read from the stream.
  37256. */
  37257. Parser.prototype.parseValueRecord = function(valueFormat) {
  37258. if (valueFormat === undefined) {
  37259. valueFormat = this.parseUShort();
  37260. }
  37261. if (valueFormat === 0) {
  37262. // valueFormat2 in kerning pairs is most often 0
  37263. // in this case return undefined instead of an empty object, to save space
  37264. return;
  37265. }
  37266. var valueRecord = {};
  37267. if (valueFormat & 0x0001) {
  37268. valueRecord.xPlacement = this.parseShort();
  37269. }
  37270. if (valueFormat & 0x0002) {
  37271. valueRecord.yPlacement = this.parseShort();
  37272. }
  37273. if (valueFormat & 0x0004) {
  37274. valueRecord.xAdvance = this.parseShort();
  37275. }
  37276. if (valueFormat & 0x0008) {
  37277. valueRecord.yAdvance = this.parseShort();
  37278. }
  37279. // Device table (non-variable font) / VariationIndex table (variable font) not supported
  37280. // https://docs.microsoft.com/fr-fr/typography/opentype/spec/chapter2#devVarIdxTbls
  37281. if (valueFormat & 0x0010) {
  37282. valueRecord.xPlaDevice = undefined;
  37283. this.parseShort();
  37284. }
  37285. if (valueFormat & 0x0020) {
  37286. valueRecord.yPlaDevice = undefined;
  37287. this.parseShort();
  37288. }
  37289. if (valueFormat & 0x0040) {
  37290. valueRecord.xAdvDevice = undefined;
  37291. this.parseShort();
  37292. }
  37293. if (valueFormat & 0x0080) {
  37294. valueRecord.yAdvDevice = undefined;
  37295. this.parseShort();
  37296. }
  37297. return valueRecord;
  37298. };
  37299. /**
  37300. * Parse a list of GPOS valueRecords
  37301. * https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#value-record
  37302. * valueFormat and valueCount are read from the stream.
  37303. */
  37304. Parser.prototype.parseValueRecordList = function() {
  37305. var this$1 = this;
  37306. var valueFormat = this.parseUShort();
  37307. var valueCount = this.parseUShort();
  37308. var values = new Array(valueCount);
  37309. for (var i = 0; i < valueCount; i++) {
  37310. values[i] = this$1.parseValueRecord(valueFormat);
  37311. }
  37312. return values;
  37313. };
  37314. Parser.prototype.parsePointer = function(description) {
  37315. var structOffset = this.parseOffset16();
  37316. if (structOffset > 0) {
  37317. // NULL offset => return undefined
  37318. return new Parser(this.data, this.offset + structOffset).parseStruct(
  37319. description
  37320. );
  37321. }
  37322. return undefined;
  37323. };
  37324. Parser.prototype.parsePointer32 = function(description) {
  37325. var structOffset = this.parseOffset32();
  37326. if (structOffset > 0) {
  37327. // NULL offset => return undefined
  37328. return new Parser(this.data, this.offset + structOffset).parseStruct(
  37329. description
  37330. );
  37331. }
  37332. return undefined;
  37333. };
  37334. /**
  37335. * Parse a list of offsets to lists of 16-bit integers,
  37336. * or a list of offsets to lists of offsets to any kind of items.
  37337. * If itemCallback is not provided, a list of list of UShort is assumed.
  37338. * If provided, itemCallback is called on each item and must parse the item.
  37339. * See examples in tables/gsub.js
  37340. */
  37341. Parser.prototype.parseListOfLists = function(itemCallback) {
  37342. var this$1 = this;
  37343. var offsets = this.parseOffset16List();
  37344. var count = offsets.length;
  37345. var relativeOffset = this.relativeOffset;
  37346. var list = new Array(count);
  37347. for (var i = 0; i < count; i++) {
  37348. var start = offsets[i];
  37349. if (start === 0) {
  37350. // NULL offset
  37351. // Add i as owned property to list. Convenient with assert.
  37352. list[i] = undefined;
  37353. continue;
  37354. }
  37355. this$1.relativeOffset = start;
  37356. if (itemCallback) {
  37357. var subOffsets = this$1.parseOffset16List();
  37358. var subList = new Array(subOffsets.length);
  37359. for (var j = 0; j < subOffsets.length; j++) {
  37360. this$1.relativeOffset = start + subOffsets[j];
  37361. subList[j] = itemCallback.call(this$1);
  37362. }
  37363. list[i] = subList;
  37364. } else {
  37365. list[i] = this$1.parseUShortList();
  37366. }
  37367. }
  37368. this.relativeOffset = relativeOffset;
  37369. return list;
  37370. };
  37371. ///// Complex tables parsing //////////////////////////////////
  37372. // Parse a coverage table in a GSUB, GPOS or GDEF table.
  37373. // https://www.microsoft.com/typography/OTSPEC/chapter2.htm
  37374. // parser.offset must point to the start of the table containing the coverage.
  37375. Parser.prototype.parseCoverage = function() {
  37376. var this$1 = this;
  37377. var startOffset = this.offset + this.relativeOffset;
  37378. var format = this.parseUShort();
  37379. var count = this.parseUShort();
  37380. if (format === 1) {
  37381. return {
  37382. format: 1,
  37383. glyphs: this.parseUShortList(count)
  37384. };
  37385. } else if (format === 2) {
  37386. var ranges = new Array(count);
  37387. for (var i = 0; i < count; i++) {
  37388. ranges[i] = {
  37389. start: this$1.parseUShort(),
  37390. end: this$1.parseUShort(),
  37391. index: this$1.parseUShort()
  37392. };
  37393. }
  37394. return {
  37395. format: 2,
  37396. ranges: ranges
  37397. };
  37398. }
  37399. throw new Error(
  37400. '0x' + startOffset.toString(16) + ': Coverage format must be 1 or 2.'
  37401. );
  37402. };
  37403. // Parse a Class Definition Table in a GSUB, GPOS or GDEF table.
  37404. // https://www.microsoft.com/typography/OTSPEC/chapter2.htm
  37405. Parser.prototype.parseClassDef = function() {
  37406. var startOffset = this.offset + this.relativeOffset;
  37407. var format = this.parseUShort();
  37408. if (format === 1) {
  37409. return {
  37410. format: 1,
  37411. startGlyph: this.parseUShort(),
  37412. classes: this.parseUShortList()
  37413. };
  37414. } else if (format === 2) {
  37415. return {
  37416. format: 2,
  37417. ranges: this.parseRecordList({
  37418. start: Parser.uShort,
  37419. end: Parser.uShort,
  37420. classId: Parser.uShort
  37421. })
  37422. };
  37423. }
  37424. throw new Error(
  37425. '0x' + startOffset.toString(16) + ': ClassDef format must be 1 or 2.'
  37426. );
  37427. };
  37428. ///// Static methods ///////////////////////////////////
  37429. // These convenience methods can be used as callbacks and should be called with "this" context set to a Parser instance.
  37430. Parser.list = function(count, itemCallback) {
  37431. return function() {
  37432. return this.parseList(count, itemCallback);
  37433. };
  37434. };
  37435. Parser.list32 = function(count, itemCallback) {
  37436. return function() {
  37437. return this.parseList32(count, itemCallback);
  37438. };
  37439. };
  37440. Parser.recordList = function(count, recordDescription) {
  37441. return function() {
  37442. return this.parseRecordList(count, recordDescription);
  37443. };
  37444. };
  37445. Parser.recordList32 = function(count, recordDescription) {
  37446. return function() {
  37447. return this.parseRecordList32(count, recordDescription);
  37448. };
  37449. };
  37450. Parser.pointer = function(description) {
  37451. return function() {
  37452. return this.parsePointer(description);
  37453. };
  37454. };
  37455. Parser.pointer32 = function(description) {
  37456. return function() {
  37457. return this.parsePointer32(description);
  37458. };
  37459. };
  37460. Parser.tag = Parser.prototype.parseTag;
  37461. Parser.byte = Parser.prototype.parseByte;
  37462. Parser.uShort = Parser.offset16 = Parser.prototype.parseUShort;
  37463. Parser.uShortList = Parser.prototype.parseUShortList;
  37464. Parser.uLong = Parser.offset32 = Parser.prototype.parseULong;
  37465. Parser.uLongList = Parser.prototype.parseULongList;
  37466. Parser.struct = Parser.prototype.parseStruct;
  37467. Parser.coverage = Parser.prototype.parseCoverage;
  37468. Parser.classDef = Parser.prototype.parseClassDef;
  37469. ///// Script, Feature, Lookup lists ///////////////////////////////////////////////
  37470. // https://www.microsoft.com/typography/OTSPEC/chapter2.htm
  37471. var langSysTable = {
  37472. reserved: Parser.uShort,
  37473. reqFeatureIndex: Parser.uShort,
  37474. featureIndexes: Parser.uShortList
  37475. };
  37476. Parser.prototype.parseScriptList = function() {
  37477. return (
  37478. this.parsePointer(
  37479. Parser.recordList({
  37480. tag: Parser.tag,
  37481. script: Parser.pointer({
  37482. defaultLangSys: Parser.pointer(langSysTable),
  37483. langSysRecords: Parser.recordList({
  37484. tag: Parser.tag,
  37485. langSys: Parser.pointer(langSysTable)
  37486. })
  37487. })
  37488. })
  37489. ) || []
  37490. );
  37491. };
  37492. Parser.prototype.parseFeatureList = function() {
  37493. return (
  37494. this.parsePointer(
  37495. Parser.recordList({
  37496. tag: Parser.tag,
  37497. feature: Parser.pointer({
  37498. featureParams: Parser.offset16,
  37499. lookupListIndexes: Parser.uShortList
  37500. })
  37501. })
  37502. ) || []
  37503. );
  37504. };
  37505. Parser.prototype.parseLookupList = function(lookupTableParsers) {
  37506. return (
  37507. this.parsePointer(
  37508. Parser.list(
  37509. Parser.pointer(function() {
  37510. var lookupType = this.parseUShort();
  37511. check.argument(
  37512. 1 <= lookupType && lookupType <= 9,
  37513. 'GPOS/GSUB lookup type ' + lookupType + ' unknown.'
  37514. );
  37515. var lookupFlag = this.parseUShort();
  37516. var useMarkFilteringSet = lookupFlag & 0x10;
  37517. return {
  37518. lookupType: lookupType,
  37519. lookupFlag: lookupFlag,
  37520. subtables: this.parseList(
  37521. Parser.pointer(lookupTableParsers[lookupType])
  37522. ),
  37523. markFilteringSet: useMarkFilteringSet
  37524. ? this.parseUShort()
  37525. : undefined
  37526. };
  37527. })
  37528. )
  37529. ) || []
  37530. );
  37531. };
  37532. Parser.prototype.parseFeatureVariationsList = function() {
  37533. return (
  37534. this.parsePointer32(function() {
  37535. var majorVersion = this.parseUShort();
  37536. var minorVersion = this.parseUShort();
  37537. check.argument(
  37538. majorVersion === 1 && minorVersion < 1,
  37539. 'GPOS/GSUB feature variations table unknown.'
  37540. );
  37541. var featureVariations = this.parseRecordList32({
  37542. conditionSetOffset: Parser.offset32,
  37543. featureTableSubstitutionOffset: Parser.offset32
  37544. });
  37545. return featureVariations;
  37546. }) || []
  37547. );
  37548. };
  37549. var parse = {
  37550. getByte: getByte,
  37551. getCard8: getByte,
  37552. getUShort: getUShort,
  37553. getCard16: getUShort,
  37554. getShort: getShort,
  37555. getULong: getULong,
  37556. getFixed: getFixed,
  37557. getTag: getTag,
  37558. getOffset: getOffset,
  37559. getBytes: getBytes,
  37560. bytesToString: bytesToString,
  37561. Parser: Parser
  37562. };
  37563. // The `cmap` table stores the mappings from characters to glyphs.
  37564. function parseCmapTableFormat12(cmap, p) {
  37565. //Skip reserved.
  37566. p.parseUShort();
  37567. // Length in bytes of the sub-tables.
  37568. cmap.length = p.parseULong();
  37569. cmap.language = p.parseULong();
  37570. var groupCount;
  37571. cmap.groupCount = groupCount = p.parseULong();
  37572. cmap.glyphIndexMap = {};
  37573. for (var i = 0; i < groupCount; i += 1) {
  37574. var startCharCode = p.parseULong();
  37575. var endCharCode = p.parseULong();
  37576. var startGlyphId = p.parseULong();
  37577. for (var c = startCharCode; c <= endCharCode; c += 1) {
  37578. cmap.glyphIndexMap[c] = startGlyphId;
  37579. startGlyphId++;
  37580. }
  37581. }
  37582. }
  37583. function parseCmapTableFormat4(cmap, p, data, start, offset) {
  37584. // Length in bytes of the sub-tables.
  37585. cmap.length = p.parseUShort();
  37586. cmap.language = p.parseUShort();
  37587. // segCount is stored x 2.
  37588. var segCount;
  37589. cmap.segCount = segCount = p.parseUShort() >> 1;
  37590. // Skip searchRange, entrySelector, rangeShift.
  37591. p.skip('uShort', 3);
  37592. // The "unrolled" mapping from character codes to glyph indices.
  37593. cmap.glyphIndexMap = {};
  37594. var endCountParser = new parse.Parser(data, start + offset + 14);
  37595. var startCountParser = new parse.Parser(
  37596. data,
  37597. start + offset + 16 + segCount * 2
  37598. );
  37599. var idDeltaParser = new parse.Parser(
  37600. data,
  37601. start + offset + 16 + segCount * 4
  37602. );
  37603. var idRangeOffsetParser = new parse.Parser(
  37604. data,
  37605. start + offset + 16 + segCount * 6
  37606. );
  37607. var glyphIndexOffset = start + offset + 16 + segCount * 8;
  37608. for (var i = 0; i < segCount - 1; i += 1) {
  37609. var glyphIndex = void 0;
  37610. var endCount = endCountParser.parseUShort();
  37611. var startCount = startCountParser.parseUShort();
  37612. var idDelta = idDeltaParser.parseShort();
  37613. var idRangeOffset = idRangeOffsetParser.parseUShort();
  37614. for (var c = startCount; c <= endCount; c += 1) {
  37615. if (idRangeOffset !== 0) {
  37616. // The idRangeOffset is relative to the current position in the idRangeOffset array.
  37617. // Take the current offset in the idRangeOffset array.
  37618. glyphIndexOffset =
  37619. idRangeOffsetParser.offset + idRangeOffsetParser.relativeOffset - 2;
  37620. // Add the value of the idRangeOffset, which will move us into the glyphIndex array.
  37621. glyphIndexOffset += idRangeOffset;
  37622. // Then add the character index of the current segment, multiplied by 2 for USHORTs.
  37623. glyphIndexOffset += (c - startCount) * 2;
  37624. glyphIndex = parse.getUShort(data, glyphIndexOffset);
  37625. if (glyphIndex !== 0) {
  37626. glyphIndex = (glyphIndex + idDelta) & 0xffff;
  37627. }
  37628. } else {
  37629. glyphIndex = (c + idDelta) & 0xffff;
  37630. }
  37631. cmap.glyphIndexMap[c] = glyphIndex;
  37632. }
  37633. }
  37634. }
  37635. // Parse the `cmap` table. This table stores the mappings from characters to glyphs.
  37636. // There are many available formats, but we only support the Windows format 4 and 12.
  37637. // This function returns a `CmapEncoding` object or null if no supported format could be found.
  37638. function parseCmapTable(data, start) {
  37639. var cmap = {};
  37640. cmap.version = parse.getUShort(data, start);
  37641. check.argument(cmap.version === 0, 'cmap table version should be 0.');
  37642. // The cmap table can contain many sub-tables, each with their own format.
  37643. // We're only interested in a "platform 0" (Unicode format) and "platform 3" (Windows format) table.
  37644. cmap.numTables = parse.getUShort(data, start + 2);
  37645. var offset = -1;
  37646. for (var i = cmap.numTables - 1; i >= 0; i -= 1) {
  37647. var platformId = parse.getUShort(data, start + 4 + i * 8);
  37648. var encodingId = parse.getUShort(data, start + 4 + i * 8 + 2);
  37649. if (
  37650. (platformId === 3 &&
  37651. (encodingId === 0 || encodingId === 1 || encodingId === 10)) ||
  37652. (platformId === 0 &&
  37653. (encodingId === 0 ||
  37654. encodingId === 1 ||
  37655. encodingId === 2 ||
  37656. encodingId === 3 ||
  37657. encodingId === 4))
  37658. ) {
  37659. offset = parse.getULong(data, start + 4 + i * 8 + 4);
  37660. break;
  37661. }
  37662. }
  37663. if (offset === -1) {
  37664. // There is no cmap table in the font that we support.
  37665. throw new Error('No valid cmap sub-tables found.');
  37666. }
  37667. var p = new parse.Parser(data, start + offset);
  37668. cmap.format = p.parseUShort();
  37669. if (cmap.format === 12) {
  37670. parseCmapTableFormat12(cmap, p);
  37671. } else if (cmap.format === 4) {
  37672. parseCmapTableFormat4(cmap, p, data, start, offset);
  37673. } else {
  37674. throw new Error(
  37675. 'Only format 4 and 12 cmap tables are supported (found format ' +
  37676. cmap.format +
  37677. ').'
  37678. );
  37679. }
  37680. return cmap;
  37681. }
  37682. function addSegment(t, code, glyphIndex) {
  37683. t.segments.push({
  37684. end: code,
  37685. start: code,
  37686. delta: -(code - glyphIndex),
  37687. offset: 0,
  37688. glyphIndex: glyphIndex
  37689. });
  37690. }
  37691. function addTerminatorSegment(t) {
  37692. t.segments.push({
  37693. end: 0xffff,
  37694. start: 0xffff,
  37695. delta: 1,
  37696. offset: 0
  37697. });
  37698. }
  37699. // Make cmap table, format 4 by default, 12 if needed only
  37700. function makeCmapTable(glyphs) {
  37701. // Plan 0 is the base Unicode Plan but emojis, for example are on another plan, and needs cmap 12 format (with 32bit)
  37702. var isPlan0Only = true;
  37703. var i;
  37704. // Check if we need to add cmap format 12 or if format 4 only is fine
  37705. for (i = glyphs.length - 1; i > 0; i -= 1) {
  37706. var g = glyphs.get(i);
  37707. if (g.unicode > 65535) {
  37708. console.log('Adding CMAP format 12 (needed!)');
  37709. isPlan0Only = false;
  37710. break;
  37711. }
  37712. }
  37713. var cmapTable = [
  37714. { name: 'version', type: 'USHORT', value: 0 },
  37715. { name: 'numTables', type: 'USHORT', value: isPlan0Only ? 1 : 2 },
  37716. // CMAP 4 header
  37717. { name: 'platformID', type: 'USHORT', value: 3 },
  37718. { name: 'encodingID', type: 'USHORT', value: 1 },
  37719. { name: 'offset', type: 'ULONG', value: isPlan0Only ? 12 : 12 + 8 }
  37720. ];
  37721. if (!isPlan0Only) {
  37722. cmapTable = cmapTable.concat([
  37723. // CMAP 12 header
  37724. { name: 'cmap12PlatformID', type: 'USHORT', value: 3 }, // We encode only for PlatformID = 3 (Windows) because it is supported everywhere
  37725. { name: 'cmap12EncodingID', type: 'USHORT', value: 10 },
  37726. { name: 'cmap12Offset', type: 'ULONG', value: 0 }
  37727. ]);
  37728. }
  37729. cmapTable = cmapTable.concat([
  37730. // CMAP 4 Subtable
  37731. { name: 'format', type: 'USHORT', value: 4 },
  37732. { name: 'cmap4Length', type: 'USHORT', value: 0 },
  37733. { name: 'language', type: 'USHORT', value: 0 },
  37734. { name: 'segCountX2', type: 'USHORT', value: 0 },
  37735. { name: 'searchRange', type: 'USHORT', value: 0 },
  37736. { name: 'entrySelector', type: 'USHORT', value: 0 },
  37737. { name: 'rangeShift', type: 'USHORT', value: 0 }
  37738. ]);
  37739. var t = new table.Table('cmap', cmapTable);
  37740. t.segments = [];
  37741. for (i = 0; i < glyphs.length; i += 1) {
  37742. var glyph = glyphs.get(i);
  37743. for (var j = 0; j < glyph.unicodes.length; j += 1) {
  37744. addSegment(t, glyph.unicodes[j], i);
  37745. }
  37746. t.segments = t.segments.sort(function(a, b) {
  37747. return a.start - b.start;
  37748. });
  37749. }
  37750. addTerminatorSegment(t);
  37751. var segCount = t.segments.length;
  37752. var segCountToRemove = 0;
  37753. // CMAP 4
  37754. // Set up parallel segment arrays.
  37755. var endCounts = [];
  37756. var startCounts = [];
  37757. var idDeltas = [];
  37758. var idRangeOffsets = [];
  37759. var glyphIds = [];
  37760. // CMAP 12
  37761. var cmap12Groups = [];
  37762. // Reminder this loop is not following the specification at 100%
  37763. // The specification -> find suites of characters and make a group
  37764. // Here we're doing one group for each letter
  37765. // Doing as the spec can save 8 times (or more) space
  37766. for (i = 0; i < segCount; i += 1) {
  37767. var segment = t.segments[i];
  37768. // CMAP 4
  37769. if (segment.end <= 65535 && segment.start <= 65535) {
  37770. endCounts = endCounts.concat({
  37771. name: 'end_' + i,
  37772. type: 'USHORT',
  37773. value: segment.end
  37774. });
  37775. startCounts = startCounts.concat({
  37776. name: 'start_' + i,
  37777. type: 'USHORT',
  37778. value: segment.start
  37779. });
  37780. idDeltas = idDeltas.concat({
  37781. name: 'idDelta_' + i,
  37782. type: 'SHORT',
  37783. value: segment.delta
  37784. });
  37785. idRangeOffsets = idRangeOffsets.concat({
  37786. name: 'idRangeOffset_' + i,
  37787. type: 'USHORT',
  37788. value: segment.offset
  37789. });
  37790. if (segment.glyphId !== undefined) {
  37791. glyphIds = glyphIds.concat({
  37792. name: 'glyph_' + i,
  37793. type: 'USHORT',
  37794. value: segment.glyphId
  37795. });
  37796. }
  37797. } else {
  37798. // Skip Unicode > 65535 (16bit unsigned max) for CMAP 4, will be added in CMAP 12
  37799. segCountToRemove += 1;
  37800. }
  37801. // CMAP 12
  37802. // Skip Terminator Segment
  37803. if (!isPlan0Only && segment.glyphIndex !== undefined) {
  37804. cmap12Groups = cmap12Groups.concat({
  37805. name: 'cmap12Start_' + i,
  37806. type: 'ULONG',
  37807. value: segment.start
  37808. });
  37809. cmap12Groups = cmap12Groups.concat({
  37810. name: 'cmap12End_' + i,
  37811. type: 'ULONG',
  37812. value: segment.end
  37813. });
  37814. cmap12Groups = cmap12Groups.concat({
  37815. name: 'cmap12Glyph_' + i,
  37816. type: 'ULONG',
  37817. value: segment.glyphIndex
  37818. });
  37819. }
  37820. }
  37821. // CMAP 4 Subtable
  37822. t.segCountX2 = (segCount - segCountToRemove) * 2;
  37823. t.searchRange =
  37824. Math.pow(
  37825. 2,
  37826. Math.floor(Math.log(segCount - segCountToRemove) / Math.log(2))
  37827. ) * 2;
  37828. t.entrySelector = Math.log(t.searchRange / 2) / Math.log(2);
  37829. t.rangeShift = t.segCountX2 - t.searchRange;
  37830. t.fields = t.fields.concat(endCounts);
  37831. t.fields.push({ name: 'reservedPad', type: 'USHORT', value: 0 });
  37832. t.fields = t.fields.concat(startCounts);
  37833. t.fields = t.fields.concat(idDeltas);
  37834. t.fields = t.fields.concat(idRangeOffsets);
  37835. t.fields = t.fields.concat(glyphIds);
  37836. t.cmap4Length =
  37837. 14 + // Subtable header
  37838. endCounts.length * 2 +
  37839. 2 + // reservedPad
  37840. startCounts.length * 2 +
  37841. idDeltas.length * 2 +
  37842. idRangeOffsets.length * 2 +
  37843. glyphIds.length * 2;
  37844. if (!isPlan0Only) {
  37845. // CMAP 12 Subtable
  37846. var cmap12Length =
  37847. 16 + // Subtable header
  37848. cmap12Groups.length * 4;
  37849. t.cmap12Offset = 12 + 2 * 2 + 4 + t.cmap4Length;
  37850. t.fields = t.fields.concat([
  37851. { name: 'cmap12Format', type: 'USHORT', value: 12 },
  37852. { name: 'cmap12Reserved', type: 'USHORT', value: 0 },
  37853. { name: 'cmap12Length', type: 'ULONG', value: cmap12Length },
  37854. { name: 'cmap12Language', type: 'ULONG', value: 0 },
  37855. { name: 'cmap12nGroups', type: 'ULONG', value: cmap12Groups.length / 3 }
  37856. ]);
  37857. t.fields = t.fields.concat(cmap12Groups);
  37858. }
  37859. return t;
  37860. }
  37861. var cmap = { parse: parseCmapTable, make: makeCmapTable };
  37862. // Glyph encoding
  37863. var cffStandardStrings = [
  37864. '.notdef',
  37865. 'space',
  37866. 'exclam',
  37867. 'quotedbl',
  37868. 'numbersign',
  37869. 'dollar',
  37870. 'percent',
  37871. 'ampersand',
  37872. 'quoteright',
  37873. 'parenleft',
  37874. 'parenright',
  37875. 'asterisk',
  37876. 'plus',
  37877. 'comma',
  37878. 'hyphen',
  37879. 'period',
  37880. 'slash',
  37881. 'zero',
  37882. 'one',
  37883. 'two',
  37884. 'three',
  37885. 'four',
  37886. 'five',
  37887. 'six',
  37888. 'seven',
  37889. 'eight',
  37890. 'nine',
  37891. 'colon',
  37892. 'semicolon',
  37893. 'less',
  37894. 'equal',
  37895. 'greater',
  37896. 'question',
  37897. 'at',
  37898. 'A',
  37899. 'B',
  37900. 'C',
  37901. 'D',
  37902. 'E',
  37903. 'F',
  37904. 'G',
  37905. 'H',
  37906. 'I',
  37907. 'J',
  37908. 'K',
  37909. 'L',
  37910. 'M',
  37911. 'N',
  37912. 'O',
  37913. 'P',
  37914. 'Q',
  37915. 'R',
  37916. 'S',
  37917. 'T',
  37918. 'U',
  37919. 'V',
  37920. 'W',
  37921. 'X',
  37922. 'Y',
  37923. 'Z',
  37924. 'bracketleft',
  37925. 'backslash',
  37926. 'bracketright',
  37927. 'asciicircum',
  37928. 'underscore',
  37929. 'quoteleft',
  37930. 'a',
  37931. 'b',
  37932. 'c',
  37933. 'd',
  37934. 'e',
  37935. 'f',
  37936. 'g',
  37937. 'h',
  37938. 'i',
  37939. 'j',
  37940. 'k',
  37941. 'l',
  37942. 'm',
  37943. 'n',
  37944. 'o',
  37945. 'p',
  37946. 'q',
  37947. 'r',
  37948. 's',
  37949. 't',
  37950. 'u',
  37951. 'v',
  37952. 'w',
  37953. 'x',
  37954. 'y',
  37955. 'z',
  37956. 'braceleft',
  37957. 'bar',
  37958. 'braceright',
  37959. 'asciitilde',
  37960. 'exclamdown',
  37961. 'cent',
  37962. 'sterling',
  37963. 'fraction',
  37964. 'yen',
  37965. 'florin',
  37966. 'section',
  37967. 'currency',
  37968. 'quotesingle',
  37969. 'quotedblleft',
  37970. 'guillemotleft',
  37971. 'guilsinglleft',
  37972. 'guilsinglright',
  37973. 'fi',
  37974. 'fl',
  37975. 'endash',
  37976. 'dagger',
  37977. 'daggerdbl',
  37978. 'periodcentered',
  37979. 'paragraph',
  37980. 'bullet',
  37981. 'quotesinglbase',
  37982. 'quotedblbase',
  37983. 'quotedblright',
  37984. 'guillemotright',
  37985. 'ellipsis',
  37986. 'perthousand',
  37987. 'questiondown',
  37988. 'grave',
  37989. 'acute',
  37990. 'circumflex',
  37991. 'tilde',
  37992. 'macron',
  37993. 'breve',
  37994. 'dotaccent',
  37995. 'dieresis',
  37996. 'ring',
  37997. 'cedilla',
  37998. 'hungarumlaut',
  37999. 'ogonek',
  38000. 'caron',
  38001. 'emdash',
  38002. 'AE',
  38003. 'ordfeminine',
  38004. 'Lslash',
  38005. 'Oslash',
  38006. 'OE',
  38007. 'ordmasculine',
  38008. 'ae',
  38009. 'dotlessi',
  38010. 'lslash',
  38011. 'oslash',
  38012. 'oe',
  38013. 'germandbls',
  38014. 'onesuperior',
  38015. 'logicalnot',
  38016. 'mu',
  38017. 'trademark',
  38018. 'Eth',
  38019. 'onehalf',
  38020. 'plusminus',
  38021. 'Thorn',
  38022. 'onequarter',
  38023. 'divide',
  38024. 'brokenbar',
  38025. 'degree',
  38026. 'thorn',
  38027. 'threequarters',
  38028. 'twosuperior',
  38029. 'registered',
  38030. 'minus',
  38031. 'eth',
  38032. 'multiply',
  38033. 'threesuperior',
  38034. 'copyright',
  38035. 'Aacute',
  38036. 'Acircumflex',
  38037. 'Adieresis',
  38038. 'Agrave',
  38039. 'Aring',
  38040. 'Atilde',
  38041. 'Ccedilla',
  38042. 'Eacute',
  38043. 'Ecircumflex',
  38044. 'Edieresis',
  38045. 'Egrave',
  38046. 'Iacute',
  38047. 'Icircumflex',
  38048. 'Idieresis',
  38049. 'Igrave',
  38050. 'Ntilde',
  38051. 'Oacute',
  38052. 'Ocircumflex',
  38053. 'Odieresis',
  38054. 'Ograve',
  38055. 'Otilde',
  38056. 'Scaron',
  38057. 'Uacute',
  38058. 'Ucircumflex',
  38059. 'Udieresis',
  38060. 'Ugrave',
  38061. 'Yacute',
  38062. 'Ydieresis',
  38063. 'Zcaron',
  38064. 'aacute',
  38065. 'acircumflex',
  38066. 'adieresis',
  38067. 'agrave',
  38068. 'aring',
  38069. 'atilde',
  38070. 'ccedilla',
  38071. 'eacute',
  38072. 'ecircumflex',
  38073. 'edieresis',
  38074. 'egrave',
  38075. 'iacute',
  38076. 'icircumflex',
  38077. 'idieresis',
  38078. 'igrave',
  38079. 'ntilde',
  38080. 'oacute',
  38081. 'ocircumflex',
  38082. 'odieresis',
  38083. 'ograve',
  38084. 'otilde',
  38085. 'scaron',
  38086. 'uacute',
  38087. 'ucircumflex',
  38088. 'udieresis',
  38089. 'ugrave',
  38090. 'yacute',
  38091. 'ydieresis',
  38092. 'zcaron',
  38093. 'exclamsmall',
  38094. 'Hungarumlautsmall',
  38095. 'dollaroldstyle',
  38096. 'dollarsuperior',
  38097. 'ampersandsmall',
  38098. 'Acutesmall',
  38099. 'parenleftsuperior',
  38100. 'parenrightsuperior',
  38101. '266 ff',
  38102. 'onedotenleader',
  38103. 'zerooldstyle',
  38104. 'oneoldstyle',
  38105. 'twooldstyle',
  38106. 'threeoldstyle',
  38107. 'fouroldstyle',
  38108. 'fiveoldstyle',
  38109. 'sixoldstyle',
  38110. 'sevenoldstyle',
  38111. 'eightoldstyle',
  38112. 'nineoldstyle',
  38113. 'commasuperior',
  38114. 'threequartersemdash',
  38115. 'periodsuperior',
  38116. 'questionsmall',
  38117. 'asuperior',
  38118. 'bsuperior',
  38119. 'centsuperior',
  38120. 'dsuperior',
  38121. 'esuperior',
  38122. 'isuperior',
  38123. 'lsuperior',
  38124. 'msuperior',
  38125. 'nsuperior',
  38126. 'osuperior',
  38127. 'rsuperior',
  38128. 'ssuperior',
  38129. 'tsuperior',
  38130. 'ff',
  38131. 'ffi',
  38132. 'ffl',
  38133. 'parenleftinferior',
  38134. 'parenrightinferior',
  38135. 'Circumflexsmall',
  38136. 'hyphensuperior',
  38137. 'Gravesmall',
  38138. 'Asmall',
  38139. 'Bsmall',
  38140. 'Csmall',
  38141. 'Dsmall',
  38142. 'Esmall',
  38143. 'Fsmall',
  38144. 'Gsmall',
  38145. 'Hsmall',
  38146. 'Ismall',
  38147. 'Jsmall',
  38148. 'Ksmall',
  38149. 'Lsmall',
  38150. 'Msmall',
  38151. 'Nsmall',
  38152. 'Osmall',
  38153. 'Psmall',
  38154. 'Qsmall',
  38155. 'Rsmall',
  38156. 'Ssmall',
  38157. 'Tsmall',
  38158. 'Usmall',
  38159. 'Vsmall',
  38160. 'Wsmall',
  38161. 'Xsmall',
  38162. 'Ysmall',
  38163. 'Zsmall',
  38164. 'colonmonetary',
  38165. 'onefitted',
  38166. 'rupiah',
  38167. 'Tildesmall',
  38168. 'exclamdownsmall',
  38169. 'centoldstyle',
  38170. 'Lslashsmall',
  38171. 'Scaronsmall',
  38172. 'Zcaronsmall',
  38173. 'Dieresissmall',
  38174. 'Brevesmall',
  38175. 'Caronsmall',
  38176. 'Dotaccentsmall',
  38177. 'Macronsmall',
  38178. 'figuredash',
  38179. 'hypheninferior',
  38180. 'Ogoneksmall',
  38181. 'Ringsmall',
  38182. 'Cedillasmall',
  38183. 'questiondownsmall',
  38184. 'oneeighth',
  38185. 'threeeighths',
  38186. 'fiveeighths',
  38187. 'seveneighths',
  38188. 'onethird',
  38189. 'twothirds',
  38190. 'zerosuperior',
  38191. 'foursuperior',
  38192. 'fivesuperior',
  38193. 'sixsuperior',
  38194. 'sevensuperior',
  38195. 'eightsuperior',
  38196. 'ninesuperior',
  38197. 'zeroinferior',
  38198. 'oneinferior',
  38199. 'twoinferior',
  38200. 'threeinferior',
  38201. 'fourinferior',
  38202. 'fiveinferior',
  38203. 'sixinferior',
  38204. 'seveninferior',
  38205. 'eightinferior',
  38206. 'nineinferior',
  38207. 'centinferior',
  38208. 'dollarinferior',
  38209. 'periodinferior',
  38210. 'commainferior',
  38211. 'Agravesmall',
  38212. 'Aacutesmall',
  38213. 'Acircumflexsmall',
  38214. 'Atildesmall',
  38215. 'Adieresissmall',
  38216. 'Aringsmall',
  38217. 'AEsmall',
  38218. 'Ccedillasmall',
  38219. 'Egravesmall',
  38220. 'Eacutesmall',
  38221. 'Ecircumflexsmall',
  38222. 'Edieresissmall',
  38223. 'Igravesmall',
  38224. 'Iacutesmall',
  38225. 'Icircumflexsmall',
  38226. 'Idieresissmall',
  38227. 'Ethsmall',
  38228. 'Ntildesmall',
  38229. 'Ogravesmall',
  38230. 'Oacutesmall',
  38231. 'Ocircumflexsmall',
  38232. 'Otildesmall',
  38233. 'Odieresissmall',
  38234. 'OEsmall',
  38235. 'Oslashsmall',
  38236. 'Ugravesmall',
  38237. 'Uacutesmall',
  38238. 'Ucircumflexsmall',
  38239. 'Udieresissmall',
  38240. 'Yacutesmall',
  38241. 'Thornsmall',
  38242. 'Ydieresissmall',
  38243. '001.000',
  38244. '001.001',
  38245. '001.002',
  38246. '001.003',
  38247. 'Black',
  38248. 'Bold',
  38249. 'Book',
  38250. 'Light',
  38251. 'Medium',
  38252. 'Regular',
  38253. 'Roman',
  38254. 'Semibold'
  38255. ];
  38256. var cffStandardEncoding = [
  38257. '',
  38258. '',
  38259. '',
  38260. '',
  38261. '',
  38262. '',
  38263. '',
  38264. '',
  38265. '',
  38266. '',
  38267. '',
  38268. '',
  38269. '',
  38270. '',
  38271. '',
  38272. '',
  38273. '',
  38274. '',
  38275. '',
  38276. '',
  38277. '',
  38278. '',
  38279. '',
  38280. '',
  38281. '',
  38282. '',
  38283. '',
  38284. '',
  38285. '',
  38286. '',
  38287. '',
  38288. '',
  38289. 'space',
  38290. 'exclam',
  38291. 'quotedbl',
  38292. 'numbersign',
  38293. 'dollar',
  38294. 'percent',
  38295. 'ampersand',
  38296. 'quoteright',
  38297. 'parenleft',
  38298. 'parenright',
  38299. 'asterisk',
  38300. 'plus',
  38301. 'comma',
  38302. 'hyphen',
  38303. 'period',
  38304. 'slash',
  38305. 'zero',
  38306. 'one',
  38307. 'two',
  38308. 'three',
  38309. 'four',
  38310. 'five',
  38311. 'six',
  38312. 'seven',
  38313. 'eight',
  38314. 'nine',
  38315. 'colon',
  38316. 'semicolon',
  38317. 'less',
  38318. 'equal',
  38319. 'greater',
  38320. 'question',
  38321. 'at',
  38322. 'A',
  38323. 'B',
  38324. 'C',
  38325. 'D',
  38326. 'E',
  38327. 'F',
  38328. 'G',
  38329. 'H',
  38330. 'I',
  38331. 'J',
  38332. 'K',
  38333. 'L',
  38334. 'M',
  38335. 'N',
  38336. 'O',
  38337. 'P',
  38338. 'Q',
  38339. 'R',
  38340. 'S',
  38341. 'T',
  38342. 'U',
  38343. 'V',
  38344. 'W',
  38345. 'X',
  38346. 'Y',
  38347. 'Z',
  38348. 'bracketleft',
  38349. 'backslash',
  38350. 'bracketright',
  38351. 'asciicircum',
  38352. 'underscore',
  38353. 'quoteleft',
  38354. 'a',
  38355. 'b',
  38356. 'c',
  38357. 'd',
  38358. 'e',
  38359. 'f',
  38360. 'g',
  38361. 'h',
  38362. 'i',
  38363. 'j',
  38364. 'k',
  38365. 'l',
  38366. 'm',
  38367. 'n',
  38368. 'o',
  38369. 'p',
  38370. 'q',
  38371. 'r',
  38372. 's',
  38373. 't',
  38374. 'u',
  38375. 'v',
  38376. 'w',
  38377. 'x',
  38378. 'y',
  38379. 'z',
  38380. 'braceleft',
  38381. 'bar',
  38382. 'braceright',
  38383. 'asciitilde',
  38384. '',
  38385. '',
  38386. '',
  38387. '',
  38388. '',
  38389. '',
  38390. '',
  38391. '',
  38392. '',
  38393. '',
  38394. '',
  38395. '',
  38396. '',
  38397. '',
  38398. '',
  38399. '',
  38400. '',
  38401. '',
  38402. '',
  38403. '',
  38404. '',
  38405. '',
  38406. '',
  38407. '',
  38408. '',
  38409. '',
  38410. '',
  38411. '',
  38412. '',
  38413. '',
  38414. '',
  38415. '',
  38416. '',
  38417. '',
  38418. 'exclamdown',
  38419. 'cent',
  38420. 'sterling',
  38421. 'fraction',
  38422. 'yen',
  38423. 'florin',
  38424. 'section',
  38425. 'currency',
  38426. 'quotesingle',
  38427. 'quotedblleft',
  38428. 'guillemotleft',
  38429. 'guilsinglleft',
  38430. 'guilsinglright',
  38431. 'fi',
  38432. 'fl',
  38433. '',
  38434. 'endash',
  38435. 'dagger',
  38436. 'daggerdbl',
  38437. 'periodcentered',
  38438. '',
  38439. 'paragraph',
  38440. 'bullet',
  38441. 'quotesinglbase',
  38442. 'quotedblbase',
  38443. 'quotedblright',
  38444. 'guillemotright',
  38445. 'ellipsis',
  38446. 'perthousand',
  38447. '',
  38448. 'questiondown',
  38449. '',
  38450. 'grave',
  38451. 'acute',
  38452. 'circumflex',
  38453. 'tilde',
  38454. 'macron',
  38455. 'breve',
  38456. 'dotaccent',
  38457. 'dieresis',
  38458. '',
  38459. 'ring',
  38460. 'cedilla',
  38461. '',
  38462. 'hungarumlaut',
  38463. 'ogonek',
  38464. 'caron',
  38465. 'emdash',
  38466. '',
  38467. '',
  38468. '',
  38469. '',
  38470. '',
  38471. '',
  38472. '',
  38473. '',
  38474. '',
  38475. '',
  38476. '',
  38477. '',
  38478. '',
  38479. '',
  38480. '',
  38481. '',
  38482. 'AE',
  38483. '',
  38484. 'ordfeminine',
  38485. '',
  38486. '',
  38487. '',
  38488. '',
  38489. 'Lslash',
  38490. 'Oslash',
  38491. 'OE',
  38492. 'ordmasculine',
  38493. '',
  38494. '',
  38495. '',
  38496. '',
  38497. '',
  38498. 'ae',
  38499. '',
  38500. '',
  38501. '',
  38502. 'dotlessi',
  38503. '',
  38504. '',
  38505. 'lslash',
  38506. 'oslash',
  38507. 'oe',
  38508. 'germandbls'
  38509. ];
  38510. var cffExpertEncoding = [
  38511. '',
  38512. '',
  38513. '',
  38514. '',
  38515. '',
  38516. '',
  38517. '',
  38518. '',
  38519. '',
  38520. '',
  38521. '',
  38522. '',
  38523. '',
  38524. '',
  38525. '',
  38526. '',
  38527. '',
  38528. '',
  38529. '',
  38530. '',
  38531. '',
  38532. '',
  38533. '',
  38534. '',
  38535. '',
  38536. '',
  38537. '',
  38538. '',
  38539. '',
  38540. '',
  38541. '',
  38542. '',
  38543. 'space',
  38544. 'exclamsmall',
  38545. 'Hungarumlautsmall',
  38546. '',
  38547. 'dollaroldstyle',
  38548. 'dollarsuperior',
  38549. 'ampersandsmall',
  38550. 'Acutesmall',
  38551. 'parenleftsuperior',
  38552. 'parenrightsuperior',
  38553. 'twodotenleader',
  38554. 'onedotenleader',
  38555. 'comma',
  38556. 'hyphen',
  38557. 'period',
  38558. 'fraction',
  38559. 'zerooldstyle',
  38560. 'oneoldstyle',
  38561. 'twooldstyle',
  38562. 'threeoldstyle',
  38563. 'fouroldstyle',
  38564. 'fiveoldstyle',
  38565. 'sixoldstyle',
  38566. 'sevenoldstyle',
  38567. 'eightoldstyle',
  38568. 'nineoldstyle',
  38569. 'colon',
  38570. 'semicolon',
  38571. 'commasuperior',
  38572. 'threequartersemdash',
  38573. 'periodsuperior',
  38574. 'questionsmall',
  38575. '',
  38576. 'asuperior',
  38577. 'bsuperior',
  38578. 'centsuperior',
  38579. 'dsuperior',
  38580. 'esuperior',
  38581. '',
  38582. '',
  38583. 'isuperior',
  38584. '',
  38585. '',
  38586. 'lsuperior',
  38587. 'msuperior',
  38588. 'nsuperior',
  38589. 'osuperior',
  38590. '',
  38591. '',
  38592. 'rsuperior',
  38593. 'ssuperior',
  38594. 'tsuperior',
  38595. '',
  38596. 'ff',
  38597. 'fi',
  38598. 'fl',
  38599. 'ffi',
  38600. 'ffl',
  38601. 'parenleftinferior',
  38602. '',
  38603. 'parenrightinferior',
  38604. 'Circumflexsmall',
  38605. 'hyphensuperior',
  38606. 'Gravesmall',
  38607. 'Asmall',
  38608. 'Bsmall',
  38609. 'Csmall',
  38610. 'Dsmall',
  38611. 'Esmall',
  38612. 'Fsmall',
  38613. 'Gsmall',
  38614. 'Hsmall',
  38615. 'Ismall',
  38616. 'Jsmall',
  38617. 'Ksmall',
  38618. 'Lsmall',
  38619. 'Msmall',
  38620. 'Nsmall',
  38621. 'Osmall',
  38622. 'Psmall',
  38623. 'Qsmall',
  38624. 'Rsmall',
  38625. 'Ssmall',
  38626. 'Tsmall',
  38627. 'Usmall',
  38628. 'Vsmall',
  38629. 'Wsmall',
  38630. 'Xsmall',
  38631. 'Ysmall',
  38632. 'Zsmall',
  38633. 'colonmonetary',
  38634. 'onefitted',
  38635. 'rupiah',
  38636. 'Tildesmall',
  38637. '',
  38638. '',
  38639. '',
  38640. '',
  38641. '',
  38642. '',
  38643. '',
  38644. '',
  38645. '',
  38646. '',
  38647. '',
  38648. '',
  38649. '',
  38650. '',
  38651. '',
  38652. '',
  38653. '',
  38654. '',
  38655. '',
  38656. '',
  38657. '',
  38658. '',
  38659. '',
  38660. '',
  38661. '',
  38662. '',
  38663. '',
  38664. '',
  38665. '',
  38666. '',
  38667. '',
  38668. '',
  38669. '',
  38670. '',
  38671. 'exclamdownsmall',
  38672. 'centoldstyle',
  38673. 'Lslashsmall',
  38674. '',
  38675. '',
  38676. 'Scaronsmall',
  38677. 'Zcaronsmall',
  38678. 'Dieresissmall',
  38679. 'Brevesmall',
  38680. 'Caronsmall',
  38681. '',
  38682. 'Dotaccentsmall',
  38683. '',
  38684. '',
  38685. 'Macronsmall',
  38686. '',
  38687. '',
  38688. 'figuredash',
  38689. 'hypheninferior',
  38690. '',
  38691. '',
  38692. 'Ogoneksmall',
  38693. 'Ringsmall',
  38694. 'Cedillasmall',
  38695. '',
  38696. '',
  38697. '',
  38698. 'onequarter',
  38699. 'onehalf',
  38700. 'threequarters',
  38701. 'questiondownsmall',
  38702. 'oneeighth',
  38703. 'threeeighths',
  38704. 'fiveeighths',
  38705. 'seveneighths',
  38706. 'onethird',
  38707. 'twothirds',
  38708. '',
  38709. '',
  38710. 'zerosuperior',
  38711. 'onesuperior',
  38712. 'twosuperior',
  38713. 'threesuperior',
  38714. 'foursuperior',
  38715. 'fivesuperior',
  38716. 'sixsuperior',
  38717. 'sevensuperior',
  38718. 'eightsuperior',
  38719. 'ninesuperior',
  38720. 'zeroinferior',
  38721. 'oneinferior',
  38722. 'twoinferior',
  38723. 'threeinferior',
  38724. 'fourinferior',
  38725. 'fiveinferior',
  38726. 'sixinferior',
  38727. 'seveninferior',
  38728. 'eightinferior',
  38729. 'nineinferior',
  38730. 'centinferior',
  38731. 'dollarinferior',
  38732. 'periodinferior',
  38733. 'commainferior',
  38734. 'Agravesmall',
  38735. 'Aacutesmall',
  38736. 'Acircumflexsmall',
  38737. 'Atildesmall',
  38738. 'Adieresissmall',
  38739. 'Aringsmall',
  38740. 'AEsmall',
  38741. 'Ccedillasmall',
  38742. 'Egravesmall',
  38743. 'Eacutesmall',
  38744. 'Ecircumflexsmall',
  38745. 'Edieresissmall',
  38746. 'Igravesmall',
  38747. 'Iacutesmall',
  38748. 'Icircumflexsmall',
  38749. 'Idieresissmall',
  38750. 'Ethsmall',
  38751. 'Ntildesmall',
  38752. 'Ogravesmall',
  38753. 'Oacutesmall',
  38754. 'Ocircumflexsmall',
  38755. 'Otildesmall',
  38756. 'Odieresissmall',
  38757. 'OEsmall',
  38758. 'Oslashsmall',
  38759. 'Ugravesmall',
  38760. 'Uacutesmall',
  38761. 'Ucircumflexsmall',
  38762. 'Udieresissmall',
  38763. 'Yacutesmall',
  38764. 'Thornsmall',
  38765. 'Ydieresissmall'
  38766. ];
  38767. var standardNames = [
  38768. '.notdef',
  38769. '.null',
  38770. 'nonmarkingreturn',
  38771. 'space',
  38772. 'exclam',
  38773. 'quotedbl',
  38774. 'numbersign',
  38775. 'dollar',
  38776. 'percent',
  38777. 'ampersand',
  38778. 'quotesingle',
  38779. 'parenleft',
  38780. 'parenright',
  38781. 'asterisk',
  38782. 'plus',
  38783. 'comma',
  38784. 'hyphen',
  38785. 'period',
  38786. 'slash',
  38787. 'zero',
  38788. 'one',
  38789. 'two',
  38790. 'three',
  38791. 'four',
  38792. 'five',
  38793. 'six',
  38794. 'seven',
  38795. 'eight',
  38796. 'nine',
  38797. 'colon',
  38798. 'semicolon',
  38799. 'less',
  38800. 'equal',
  38801. 'greater',
  38802. 'question',
  38803. 'at',
  38804. 'A',
  38805. 'B',
  38806. 'C',
  38807. 'D',
  38808. 'E',
  38809. 'F',
  38810. 'G',
  38811. 'H',
  38812. 'I',
  38813. 'J',
  38814. 'K',
  38815. 'L',
  38816. 'M',
  38817. 'N',
  38818. 'O',
  38819. 'P',
  38820. 'Q',
  38821. 'R',
  38822. 'S',
  38823. 'T',
  38824. 'U',
  38825. 'V',
  38826. 'W',
  38827. 'X',
  38828. 'Y',
  38829. 'Z',
  38830. 'bracketleft',
  38831. 'backslash',
  38832. 'bracketright',
  38833. 'asciicircum',
  38834. 'underscore',
  38835. 'grave',
  38836. 'a',
  38837. 'b',
  38838. 'c',
  38839. 'd',
  38840. 'e',
  38841. 'f',
  38842. 'g',
  38843. 'h',
  38844. 'i',
  38845. 'j',
  38846. 'k',
  38847. 'l',
  38848. 'm',
  38849. 'n',
  38850. 'o',
  38851. 'p',
  38852. 'q',
  38853. 'r',
  38854. 's',
  38855. 't',
  38856. 'u',
  38857. 'v',
  38858. 'w',
  38859. 'x',
  38860. 'y',
  38861. 'z',
  38862. 'braceleft',
  38863. 'bar',
  38864. 'braceright',
  38865. 'asciitilde',
  38866. 'Adieresis',
  38867. 'Aring',
  38868. 'Ccedilla',
  38869. 'Eacute',
  38870. 'Ntilde',
  38871. 'Odieresis',
  38872. 'Udieresis',
  38873. 'aacute',
  38874. 'agrave',
  38875. 'acircumflex',
  38876. 'adieresis',
  38877. 'atilde',
  38878. 'aring',
  38879. 'ccedilla',
  38880. 'eacute',
  38881. 'egrave',
  38882. 'ecircumflex',
  38883. 'edieresis',
  38884. 'iacute',
  38885. 'igrave',
  38886. 'icircumflex',
  38887. 'idieresis',
  38888. 'ntilde',
  38889. 'oacute',
  38890. 'ograve',
  38891. 'ocircumflex',
  38892. 'odieresis',
  38893. 'otilde',
  38894. 'uacute',
  38895. 'ugrave',
  38896. 'ucircumflex',
  38897. 'udieresis',
  38898. 'dagger',
  38899. 'degree',
  38900. 'cent',
  38901. 'sterling',
  38902. 'section',
  38903. 'bullet',
  38904. 'paragraph',
  38905. 'germandbls',
  38906. 'registered',
  38907. 'copyright',
  38908. 'trademark',
  38909. 'acute',
  38910. 'dieresis',
  38911. 'notequal',
  38912. 'AE',
  38913. 'Oslash',
  38914. 'infinity',
  38915. 'plusminus',
  38916. 'lessequal',
  38917. 'greaterequal',
  38918. 'yen',
  38919. 'mu',
  38920. 'partialdiff',
  38921. 'summation',
  38922. 'product',
  38923. 'pi',
  38924. 'integral',
  38925. 'ordfeminine',
  38926. 'ordmasculine',
  38927. 'Omega',
  38928. 'ae',
  38929. 'oslash',
  38930. 'questiondown',
  38931. 'exclamdown',
  38932. 'logicalnot',
  38933. 'radical',
  38934. 'florin',
  38935. 'approxequal',
  38936. 'Delta',
  38937. 'guillemotleft',
  38938. 'guillemotright',
  38939. 'ellipsis',
  38940. 'nonbreakingspace',
  38941. 'Agrave',
  38942. 'Atilde',
  38943. 'Otilde',
  38944. 'OE',
  38945. 'oe',
  38946. 'endash',
  38947. 'emdash',
  38948. 'quotedblleft',
  38949. 'quotedblright',
  38950. 'quoteleft',
  38951. 'quoteright',
  38952. 'divide',
  38953. 'lozenge',
  38954. 'ydieresis',
  38955. 'Ydieresis',
  38956. 'fraction',
  38957. 'currency',
  38958. 'guilsinglleft',
  38959. 'guilsinglright',
  38960. 'fi',
  38961. 'fl',
  38962. 'daggerdbl',
  38963. 'periodcentered',
  38964. 'quotesinglbase',
  38965. 'quotedblbase',
  38966. 'perthousand',
  38967. 'Acircumflex',
  38968. 'Ecircumflex',
  38969. 'Aacute',
  38970. 'Edieresis',
  38971. 'Egrave',
  38972. 'Iacute',
  38973. 'Icircumflex',
  38974. 'Idieresis',
  38975. 'Igrave',
  38976. 'Oacute',
  38977. 'Ocircumflex',
  38978. 'apple',
  38979. 'Ograve',
  38980. 'Uacute',
  38981. 'Ucircumflex',
  38982. 'Ugrave',
  38983. 'dotlessi',
  38984. 'circumflex',
  38985. 'tilde',
  38986. 'macron',
  38987. 'breve',
  38988. 'dotaccent',
  38989. 'ring',
  38990. 'cedilla',
  38991. 'hungarumlaut',
  38992. 'ogonek',
  38993. 'caron',
  38994. 'Lslash',
  38995. 'lslash',
  38996. 'Scaron',
  38997. 'scaron',
  38998. 'Zcaron',
  38999. 'zcaron',
  39000. 'brokenbar',
  39001. 'Eth',
  39002. 'eth',
  39003. 'Yacute',
  39004. 'yacute',
  39005. 'Thorn',
  39006. 'thorn',
  39007. 'minus',
  39008. 'multiply',
  39009. 'onesuperior',
  39010. 'twosuperior',
  39011. 'threesuperior',
  39012. 'onehalf',
  39013. 'onequarter',
  39014. 'threequarters',
  39015. 'franc',
  39016. 'Gbreve',
  39017. 'gbreve',
  39018. 'Idotaccent',
  39019. 'Scedilla',
  39020. 'scedilla',
  39021. 'Cacute',
  39022. 'cacute',
  39023. 'Ccaron',
  39024. 'ccaron',
  39025. 'dcroat'
  39026. ];
  39027. /**
  39028. * This is the encoding used for fonts created from scratch.
  39029. * It loops through all glyphs and finds the appropriate unicode value.
  39030. * Since it's linear time, other encodings will be faster.
  39031. * @exports opentype.DefaultEncoding
  39032. * @class
  39033. * @constructor
  39034. * @param {opentype.Font}
  39035. */
  39036. function DefaultEncoding(font) {
  39037. this.font = font;
  39038. }
  39039. DefaultEncoding.prototype.charToGlyphIndex = function(c) {
  39040. var code = c.codePointAt(0);
  39041. var glyphs = this.font.glyphs;
  39042. if (glyphs) {
  39043. for (var i = 0; i < glyphs.length; i += 1) {
  39044. var glyph = glyphs.get(i);
  39045. for (var j = 0; j < glyph.unicodes.length; j += 1) {
  39046. if (glyph.unicodes[j] === code) {
  39047. return i;
  39048. }
  39049. }
  39050. }
  39051. }
  39052. return null;
  39053. };
  39054. /**
  39055. * @exports opentype.CmapEncoding
  39056. * @class
  39057. * @constructor
  39058. * @param {Object} cmap - a object with the cmap encoded data
  39059. */
  39060. function CmapEncoding(cmap) {
  39061. this.cmap = cmap;
  39062. }
  39063. /**
  39064. * @param {string} c - the character
  39065. * @return {number} The glyph index.
  39066. */
  39067. CmapEncoding.prototype.charToGlyphIndex = function(c) {
  39068. return this.cmap.glyphIndexMap[c.codePointAt(0)] || 0;
  39069. };
  39070. /**
  39071. * @exports opentype.CffEncoding
  39072. * @class
  39073. * @constructor
  39074. * @param {string} encoding - The encoding
  39075. * @param {Array} charset - The character set.
  39076. */
  39077. function CffEncoding(encoding, charset) {
  39078. this.encoding = encoding;
  39079. this.charset = charset;
  39080. }
  39081. /**
  39082. * @param {string} s - The character
  39083. * @return {number} The index.
  39084. */
  39085. CffEncoding.prototype.charToGlyphIndex = function(s) {
  39086. var code = s.codePointAt(0);
  39087. var charName = this.encoding[code];
  39088. return this.charset.indexOf(charName);
  39089. };
  39090. /**
  39091. * @exports opentype.GlyphNames
  39092. * @class
  39093. * @constructor
  39094. * @param {Object} post
  39095. */
  39096. function GlyphNames(post) {
  39097. var this$1 = this;
  39098. switch (post.version) {
  39099. case 1:
  39100. this.names = standardNames.slice();
  39101. break;
  39102. case 2:
  39103. this.names = new Array(post.numberOfGlyphs);
  39104. for (var i = 0; i < post.numberOfGlyphs; i++) {
  39105. if (post.glyphNameIndex[i] < standardNames.length) {
  39106. this$1.names[i] = standardNames[post.glyphNameIndex[i]];
  39107. } else {
  39108. this$1.names[i] =
  39109. post.names[post.glyphNameIndex[i] - standardNames.length];
  39110. }
  39111. }
  39112. break;
  39113. case 2.5:
  39114. this.names = new Array(post.numberOfGlyphs);
  39115. for (var i$1 = 0; i$1 < post.numberOfGlyphs; i$1++) {
  39116. this$1.names[i$1] = standardNames[i$1 + post.glyphNameIndex[i$1]];
  39117. }
  39118. break;
  39119. case 3:
  39120. this.names = [];
  39121. break;
  39122. default:
  39123. this.names = [];
  39124. break;
  39125. }
  39126. }
  39127. /**
  39128. * Gets the index of a glyph by name.
  39129. * @param {string} name - The glyph name
  39130. * @return {number} The index
  39131. */
  39132. GlyphNames.prototype.nameToGlyphIndex = function(name) {
  39133. return this.names.indexOf(name);
  39134. };
  39135. /**
  39136. * @param {number} gid
  39137. * @return {string}
  39138. */
  39139. GlyphNames.prototype.glyphIndexToName = function(gid) {
  39140. return this.names[gid];
  39141. };
  39142. /**
  39143. * @alias opentype.addGlyphNames
  39144. * @param {opentype.Font}
  39145. */
  39146. function addGlyphNames(font) {
  39147. var glyph;
  39148. var glyphIndexMap = font.tables.cmap.glyphIndexMap;
  39149. var charCodes = Object.keys(glyphIndexMap);
  39150. for (var i = 0; i < charCodes.length; i += 1) {
  39151. var c = charCodes[i];
  39152. var glyphIndex = glyphIndexMap[c];
  39153. glyph = font.glyphs.get(glyphIndex);
  39154. glyph.addUnicode(parseInt(c));
  39155. }
  39156. for (var i$1 = 0; i$1 < font.glyphs.length; i$1 += 1) {
  39157. glyph = font.glyphs.get(i$1);
  39158. if (font.cffEncoding) {
  39159. if (font.isCIDFont) {
  39160. glyph.name = 'gid' + i$1;
  39161. } else {
  39162. glyph.name = font.cffEncoding.charset[i$1];
  39163. }
  39164. } else if (font.glyphNames.names) {
  39165. glyph.name = font.glyphNames.glyphIndexToName(i$1);
  39166. }
  39167. }
  39168. }
  39169. // Drawing utility functions.
  39170. // Draw a line on the given context from point `x1,y1` to point `x2,y2`.
  39171. function line(ctx, x1, y1, x2, y2) {
  39172. ctx.beginPath();
  39173. ctx.moveTo(x1, y1);
  39174. ctx.lineTo(x2, y2);
  39175. ctx.stroke();
  39176. }
  39177. var draw = { line: line };
  39178. // The Glyph object
  39179. // import glyf from './tables/glyf' Can't be imported here, because it's a circular dependency
  39180. function getPathDefinition(glyph, path) {
  39181. var _path = path || new Path();
  39182. return {
  39183. configurable: true,
  39184. get: function() {
  39185. if (typeof _path === 'function') {
  39186. _path = _path();
  39187. }
  39188. return _path;
  39189. },
  39190. set: function(p) {
  39191. _path = p;
  39192. }
  39193. };
  39194. }
  39195. /**
  39196. * @typedef GlyphOptions
  39197. * @type Object
  39198. * @property {string} [name] - The glyph name
  39199. * @property {number} [unicode]
  39200. * @property {Array} [unicodes]
  39201. * @property {number} [xMin]
  39202. * @property {number} [yMin]
  39203. * @property {number} [xMax]
  39204. * @property {number} [yMax]
  39205. * @property {number} [advanceWidth]
  39206. */
  39207. // A Glyph is an individual mark that often corresponds to a character.
  39208. // Some glyphs, such as ligatures, are a combination of many characters.
  39209. // Glyphs are the basic building blocks of a font.
  39210. //
  39211. // The `Glyph` class contains utility methods for drawing the path and its points.
  39212. /**
  39213. * @exports opentype.Glyph
  39214. * @class
  39215. * @param {GlyphOptions}
  39216. * @constructor
  39217. */
  39218. function Glyph(options) {
  39219. // By putting all the code on a prototype function (which is only declared once)
  39220. // we reduce the memory requirements for larger fonts by some 2%
  39221. this.bindConstructorValues(options);
  39222. }
  39223. /**
  39224. * @param {GlyphOptions}
  39225. */
  39226. Glyph.prototype.bindConstructorValues = function(options) {
  39227. this.index = options.index || 0;
  39228. // These three values cannot be deferred for memory optimization:
  39229. this.name = options.name || null;
  39230. this.unicode = options.unicode || undefined;
  39231. this.unicodes =
  39232. options.unicodes || options.unicode !== undefined
  39233. ? [options.unicode]
  39234. : [];
  39235. // But by binding these values only when necessary, we reduce can
  39236. // the memory requirements by almost 3% for larger fonts.
  39237. if (options.xMin) {
  39238. this.xMin = options.xMin;
  39239. }
  39240. if (options.yMin) {
  39241. this.yMin = options.yMin;
  39242. }
  39243. if (options.xMax) {
  39244. this.xMax = options.xMax;
  39245. }
  39246. if (options.yMax) {
  39247. this.yMax = options.yMax;
  39248. }
  39249. if (options.advanceWidth) {
  39250. this.advanceWidth = options.advanceWidth;
  39251. }
  39252. // The path for a glyph is the most memory intensive, and is bound as a value
  39253. // with a getter/setter to ensure we actually do path parsing only once the
  39254. // path is actually needed by anything.
  39255. Object.defineProperty(this, 'path', getPathDefinition(this, options.path));
  39256. };
  39257. /**
  39258. * @param {number}
  39259. */
  39260. Glyph.prototype.addUnicode = function(unicode) {
  39261. if (this.unicodes.length === 0) {
  39262. this.unicode = unicode;
  39263. }
  39264. this.unicodes.push(unicode);
  39265. };
  39266. /**
  39267. * Calculate the minimum bounding box for this glyph.
  39268. * @return {opentype.BoundingBox}
  39269. */
  39270. Glyph.prototype.getBoundingBox = function() {
  39271. return this.path.getBoundingBox();
  39272. };
  39273. /**
  39274. * Convert the glyph to a Path we can draw on a drawing context.
  39275. * @param {number} [x=0] - Horizontal position of the beginning of the text.
  39276. * @param {number} [y=0] - Vertical position of the *baseline* of the text.
  39277. * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
  39278. * @param {Object=} options - xScale, yScale to stretch the glyph.
  39279. * @param {opentype.Font} if hinting is to be used, the font
  39280. * @return {opentype.Path}
  39281. */
  39282. Glyph.prototype.getPath = function(x, y, fontSize, options, font) {
  39283. x = x !== undefined ? x : 0;
  39284. y = y !== undefined ? y : 0;
  39285. fontSize = fontSize !== undefined ? fontSize : 72;
  39286. var commands;
  39287. var hPoints;
  39288. if (!options) {
  39289. options = {};
  39290. }
  39291. var xScale = options.xScale;
  39292. var yScale = options.yScale;
  39293. if (options.hinting && font && font.hinting) {
  39294. // in case of hinting, the hinting engine takes care
  39295. // of scaling the points (not the path) before hinting.
  39296. hPoints = this.path && font.hinting.exec(this, fontSize);
  39297. // in case the hinting engine failed hPoints is undefined
  39298. // and thus reverts to plain rending
  39299. }
  39300. if (hPoints) {
  39301. // Call font.hinting.getCommands instead of `glyf.getPath(hPoints).commands` to avoid a circular dependency
  39302. commands = font.hinting.getCommands(hPoints);
  39303. x = Math.round(x);
  39304. y = Math.round(y);
  39305. // TODO in case of hinting xyScaling is not yet supported
  39306. xScale = yScale = 1;
  39307. } else {
  39308. commands = this.path.commands;
  39309. var scale = 1 / this.path.unitsPerEm * fontSize;
  39310. if (xScale === undefined) {
  39311. xScale = scale;
  39312. }
  39313. if (yScale === undefined) {
  39314. yScale = scale;
  39315. }
  39316. }
  39317. var p = new Path();
  39318. for (var i = 0; i < commands.length; i += 1) {
  39319. var cmd = commands[i];
  39320. if (cmd.type === 'M') {
  39321. p.moveTo(x + cmd.x * xScale, y + -cmd.y * yScale);
  39322. } else if (cmd.type === 'L') {
  39323. p.lineTo(x + cmd.x * xScale, y + -cmd.y * yScale);
  39324. } else if (cmd.type === 'Q') {
  39325. p.quadraticCurveTo(
  39326. x + cmd.x1 * xScale,
  39327. y + -cmd.y1 * yScale,
  39328. x + cmd.x * xScale,
  39329. y + -cmd.y * yScale
  39330. );
  39331. } else if (cmd.type === 'C') {
  39332. p.curveTo(
  39333. x + cmd.x1 * xScale,
  39334. y + -cmd.y1 * yScale,
  39335. x + cmd.x2 * xScale,
  39336. y + -cmd.y2 * yScale,
  39337. x + cmd.x * xScale,
  39338. y + -cmd.y * yScale
  39339. );
  39340. } else if (cmd.type === 'Z') {
  39341. p.closePath();
  39342. }
  39343. }
  39344. return p;
  39345. };
  39346. /**
  39347. * Split the glyph into contours.
  39348. * This function is here for backwards compatibility, and to
  39349. * provide raw access to the TrueType glyph outlines.
  39350. * @return {Array}
  39351. */
  39352. Glyph.prototype.getContours = function() {
  39353. var this$1 = this;
  39354. if (this.points === undefined) {
  39355. return [];
  39356. }
  39357. var contours = [];
  39358. var currentContour = [];
  39359. for (var i = 0; i < this.points.length; i += 1) {
  39360. var pt = this$1.points[i];
  39361. currentContour.push(pt);
  39362. if (pt.lastPointOfContour) {
  39363. contours.push(currentContour);
  39364. currentContour = [];
  39365. }
  39366. }
  39367. check.argument(
  39368. currentContour.length === 0,
  39369. 'There are still points left in the current contour.'
  39370. );
  39371. return contours;
  39372. };
  39373. /**
  39374. * Calculate the xMin/yMin/xMax/yMax/lsb/rsb for a Glyph.
  39375. * @return {Object}
  39376. */
  39377. Glyph.prototype.getMetrics = function() {
  39378. var commands = this.path.commands;
  39379. var xCoords = [];
  39380. var yCoords = [];
  39381. for (var i = 0; i < commands.length; i += 1) {
  39382. var cmd = commands[i];
  39383. if (cmd.type !== 'Z') {
  39384. xCoords.push(cmd.x);
  39385. yCoords.push(cmd.y);
  39386. }
  39387. if (cmd.type === 'Q' || cmd.type === 'C') {
  39388. xCoords.push(cmd.x1);
  39389. yCoords.push(cmd.y1);
  39390. }
  39391. if (cmd.type === 'C') {
  39392. xCoords.push(cmd.x2);
  39393. yCoords.push(cmd.y2);
  39394. }
  39395. }
  39396. var metrics = {
  39397. xMin: Math.min.apply(null, xCoords),
  39398. yMin: Math.min.apply(null, yCoords),
  39399. xMax: Math.max.apply(null, xCoords),
  39400. yMax: Math.max.apply(null, yCoords),
  39401. leftSideBearing: this.leftSideBearing
  39402. };
  39403. if (!isFinite(metrics.xMin)) {
  39404. metrics.xMin = 0;
  39405. }
  39406. if (!isFinite(metrics.xMax)) {
  39407. metrics.xMax = this.advanceWidth;
  39408. }
  39409. if (!isFinite(metrics.yMin)) {
  39410. metrics.yMin = 0;
  39411. }
  39412. if (!isFinite(metrics.yMax)) {
  39413. metrics.yMax = 0;
  39414. }
  39415. metrics.rightSideBearing =
  39416. this.advanceWidth -
  39417. metrics.leftSideBearing -
  39418. (metrics.xMax - metrics.xMin);
  39419. return metrics;
  39420. };
  39421. /**
  39422. * Draw the glyph on the given context.
  39423. * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.
  39424. * @param {number} [x=0] - Horizontal position of the beginning of the text.
  39425. * @param {number} [y=0] - Vertical position of the *baseline* of the text.
  39426. * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
  39427. * @param {Object=} options - xScale, yScale to stretch the glyph.
  39428. */
  39429. Glyph.prototype.draw = function(ctx, x, y, fontSize, options) {
  39430. this.getPath(x, y, fontSize, options).draw(ctx);
  39431. };
  39432. /**
  39433. * Draw the points of the glyph.
  39434. * On-curve points will be drawn in blue, off-curve points will be drawn in red.
  39435. * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.
  39436. * @param {number} [x=0] - Horizontal position of the beginning of the text.
  39437. * @param {number} [y=0] - Vertical position of the *baseline* of the text.
  39438. * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
  39439. */
  39440. Glyph.prototype.drawPoints = function(ctx, x, y, fontSize) {
  39441. function drawCircles(l, x, y, scale) {
  39442. var PI_SQ = Math.PI * 2;
  39443. ctx.beginPath();
  39444. for (var j = 0; j < l.length; j += 1) {
  39445. ctx.moveTo(x + l[j].x * scale, y + l[j].y * scale);
  39446. ctx.arc(x + l[j].x * scale, y + l[j].y * scale, 2, 0, PI_SQ, false);
  39447. }
  39448. ctx.closePath();
  39449. ctx.fill();
  39450. }
  39451. x = x !== undefined ? x : 0;
  39452. y = y !== undefined ? y : 0;
  39453. fontSize = fontSize !== undefined ? fontSize : 24;
  39454. var scale = 1 / this.path.unitsPerEm * fontSize;
  39455. var blueCircles = [];
  39456. var redCircles = [];
  39457. var path = this.path;
  39458. for (var i = 0; i < path.commands.length; i += 1) {
  39459. var cmd = path.commands[i];
  39460. if (cmd.x !== undefined) {
  39461. blueCircles.push({ x: cmd.x, y: -cmd.y });
  39462. }
  39463. if (cmd.x1 !== undefined) {
  39464. redCircles.push({ x: cmd.x1, y: -cmd.y1 });
  39465. }
  39466. if (cmd.x2 !== undefined) {
  39467. redCircles.push({ x: cmd.x2, y: -cmd.y2 });
  39468. }
  39469. }
  39470. ctx.fillStyle = 'blue';
  39471. drawCircles(blueCircles, x, y, scale);
  39472. ctx.fillStyle = 'red';
  39473. drawCircles(redCircles, x, y, scale);
  39474. };
  39475. /**
  39476. * Draw lines indicating important font measurements.
  39477. * Black lines indicate the origin of the coordinate system (point 0,0).
  39478. * Blue lines indicate the glyph bounding box.
  39479. * Green line indicates the advance width of the glyph.
  39480. * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.
  39481. * @param {number} [x=0] - Horizontal position of the beginning of the text.
  39482. * @param {number} [y=0] - Vertical position of the *baseline* of the text.
  39483. * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
  39484. */
  39485. Glyph.prototype.drawMetrics = function(ctx, x, y, fontSize) {
  39486. var scale;
  39487. x = x !== undefined ? x : 0;
  39488. y = y !== undefined ? y : 0;
  39489. fontSize = fontSize !== undefined ? fontSize : 24;
  39490. scale = 1 / this.path.unitsPerEm * fontSize;
  39491. ctx.lineWidth = 1;
  39492. // Draw the origin
  39493. ctx.strokeStyle = 'black';
  39494. draw.line(ctx, x, -10000, x, 10000);
  39495. draw.line(ctx, -10000, y, 10000, y);
  39496. // This code is here due to memory optimization: by not using
  39497. // defaults in the constructor, we save a notable amount of memory.
  39498. var xMin = this.xMin || 0;
  39499. var yMin = this.yMin || 0;
  39500. var xMax = this.xMax || 0;
  39501. var yMax = this.yMax || 0;
  39502. var advanceWidth = this.advanceWidth || 0;
  39503. // Draw the glyph box
  39504. ctx.strokeStyle = 'blue';
  39505. draw.line(ctx, x + xMin * scale, -10000, x + xMin * scale, 10000);
  39506. draw.line(ctx, x + xMax * scale, -10000, x + xMax * scale, 10000);
  39507. draw.line(ctx, -10000, y + -yMin * scale, 10000, y + -yMin * scale);
  39508. draw.line(ctx, -10000, y + -yMax * scale, 10000, y + -yMax * scale);
  39509. // Draw the advance width
  39510. ctx.strokeStyle = 'green';
  39511. draw.line(
  39512. ctx,
  39513. x + advanceWidth * scale,
  39514. -10000,
  39515. x + advanceWidth * scale,
  39516. 10000
  39517. );
  39518. };
  39519. // The GlyphSet object
  39520. // Define a property on the glyph that depends on the path being loaded.
  39521. function defineDependentProperty(glyph, externalName, internalName) {
  39522. Object.defineProperty(glyph, externalName, {
  39523. get: function() {
  39524. // Request the path property to make sure the path is loaded.
  39525. glyph.path; // jshint ignore:line
  39526. return glyph[internalName];
  39527. },
  39528. set: function(newValue) {
  39529. glyph[internalName] = newValue;
  39530. },
  39531. enumerable: true,
  39532. configurable: true
  39533. });
  39534. }
  39535. /**
  39536. * A GlyphSet represents all glyphs available in the font, but modelled using
  39537. * a deferred glyph loader, for retrieving glyphs only once they are absolutely
  39538. * necessary, to keep the memory footprint down.
  39539. * @exports opentype.GlyphSet
  39540. * @class
  39541. * @param {opentype.Font}
  39542. * @param {Array}
  39543. */
  39544. function GlyphSet(font, glyphs) {
  39545. var this$1 = this;
  39546. this.font = font;
  39547. this.glyphs = {};
  39548. if (Array.isArray(glyphs)) {
  39549. for (var i = 0; i < glyphs.length; i++) {
  39550. this$1.glyphs[i] = glyphs[i];
  39551. }
  39552. }
  39553. this.length = (glyphs && glyphs.length) || 0;
  39554. }
  39555. /**
  39556. * @param {number} index
  39557. * @return {opentype.Glyph}
  39558. */
  39559. GlyphSet.prototype.get = function(index) {
  39560. if (typeof this.glyphs[index] === 'function') {
  39561. this.glyphs[index] = this.glyphs[index]();
  39562. }
  39563. return this.glyphs[index];
  39564. };
  39565. /**
  39566. * @param {number} index
  39567. * @param {Object}
  39568. */
  39569. GlyphSet.prototype.push = function(index, loader) {
  39570. this.glyphs[index] = loader;
  39571. this.length++;
  39572. };
  39573. /**
  39574. * @alias opentype.glyphLoader
  39575. * @param {opentype.Font} font
  39576. * @param {number} index
  39577. * @return {opentype.Glyph}
  39578. */
  39579. function glyphLoader(font, index) {
  39580. return new Glyph({ index: index, font: font });
  39581. }
  39582. /**
  39583. * Generate a stub glyph that can be filled with all metadata *except*
  39584. * the "points" and "path" properties, which must be loaded only once
  39585. * the glyph's path is actually requested for text shaping.
  39586. * @alias opentype.ttfGlyphLoader
  39587. * @param {opentype.Font} font
  39588. * @param {number} index
  39589. * @param {Function} parseGlyph
  39590. * @param {Object} data
  39591. * @param {number} position
  39592. * @param {Function} buildPath
  39593. * @return {opentype.Glyph}
  39594. */
  39595. function ttfGlyphLoader(font, index, parseGlyph, data, position, buildPath) {
  39596. return function() {
  39597. var glyph = new Glyph({ index: index, font: font });
  39598. glyph.path = function() {
  39599. parseGlyph(glyph, data, position);
  39600. var path = buildPath(font.glyphs, glyph);
  39601. path.unitsPerEm = font.unitsPerEm;
  39602. return path;
  39603. };
  39604. defineDependentProperty(glyph, 'xMin', '_xMin');
  39605. defineDependentProperty(glyph, 'xMax', '_xMax');
  39606. defineDependentProperty(glyph, 'yMin', '_yMin');
  39607. defineDependentProperty(glyph, 'yMax', '_yMax');
  39608. return glyph;
  39609. };
  39610. }
  39611. /**
  39612. * @alias opentype.cffGlyphLoader
  39613. * @param {opentype.Font} font
  39614. * @param {number} index
  39615. * @param {Function} parseCFFCharstring
  39616. * @param {string} charstring
  39617. * @return {opentype.Glyph}
  39618. */
  39619. function cffGlyphLoader(font, index, parseCFFCharstring, charstring) {
  39620. return function() {
  39621. var glyph = new Glyph({ index: index, font: font });
  39622. glyph.path = function() {
  39623. var path = parseCFFCharstring(font, glyph, charstring);
  39624. path.unitsPerEm = font.unitsPerEm;
  39625. return path;
  39626. };
  39627. return glyph;
  39628. };
  39629. }
  39630. var glyphset = {
  39631. GlyphSet: GlyphSet,
  39632. glyphLoader: glyphLoader,
  39633. ttfGlyphLoader: ttfGlyphLoader,
  39634. cffGlyphLoader: cffGlyphLoader
  39635. };
  39636. // The `CFF` table contains the glyph outlines in PostScript format.
  39637. // Custom equals function that can also check lists.
  39638. function equals(a, b) {
  39639. if (a === b) {
  39640. return true;
  39641. } else if (Array.isArray(a) && Array.isArray(b)) {
  39642. if (a.length !== b.length) {
  39643. return false;
  39644. }
  39645. for (var i = 0; i < a.length; i += 1) {
  39646. if (!equals(a[i], b[i])) {
  39647. return false;
  39648. }
  39649. }
  39650. return true;
  39651. } else {
  39652. return false;
  39653. }
  39654. }
  39655. // Subroutines are encoded using the negative half of the number space.
  39656. // See type 2 chapter 4.7 "Subroutine operators".
  39657. function calcCFFSubroutineBias(subrs) {
  39658. var bias;
  39659. if (subrs.length < 1240) {
  39660. bias = 107;
  39661. } else if (subrs.length < 33900) {
  39662. bias = 1131;
  39663. } else {
  39664. bias = 32768;
  39665. }
  39666. return bias;
  39667. }
  39668. // Parse a `CFF` INDEX array.
  39669. // An index array consists of a list of offsets, then a list of objects at those offsets.
  39670. function parseCFFIndex(data, start, conversionFn) {
  39671. var offsets = [];
  39672. var objects = [];
  39673. var count = parse.getCard16(data, start);
  39674. var objectOffset;
  39675. var endOffset;
  39676. if (count !== 0) {
  39677. var offsetSize = parse.getByte(data, start + 2);
  39678. objectOffset = start + (count + 1) * offsetSize + 2;
  39679. var pos = start + 3;
  39680. for (var i = 0; i < count + 1; i += 1) {
  39681. offsets.push(parse.getOffset(data, pos, offsetSize));
  39682. pos += offsetSize;
  39683. }
  39684. // The total size of the index array is 4 header bytes + the value of the last offset.
  39685. endOffset = objectOffset + offsets[count];
  39686. } else {
  39687. endOffset = start + 2;
  39688. }
  39689. for (var i$1 = 0; i$1 < offsets.length - 1; i$1 += 1) {
  39690. var value = parse.getBytes(
  39691. data,
  39692. objectOffset + offsets[i$1],
  39693. objectOffset + offsets[i$1 + 1]
  39694. );
  39695. if (conversionFn) {
  39696. value = conversionFn(value);
  39697. }
  39698. objects.push(value);
  39699. }
  39700. return { objects: objects, startOffset: start, endOffset: endOffset };
  39701. }
  39702. // Parse a `CFF` DICT real value.
  39703. function parseFloatOperand(parser) {
  39704. var s = '';
  39705. var eof = 15;
  39706. var lookup = [
  39707. '0',
  39708. '1',
  39709. '2',
  39710. '3',
  39711. '4',
  39712. '5',
  39713. '6',
  39714. '7',
  39715. '8',
  39716. '9',
  39717. '.',
  39718. 'E',
  39719. 'E-',
  39720. null,
  39721. '-'
  39722. ];
  39723. while (true) {
  39724. var b = parser.parseByte();
  39725. var n1 = b >> 4;
  39726. var n2 = b & 15;
  39727. if (n1 === eof) {
  39728. break;
  39729. }
  39730. s += lookup[n1];
  39731. if (n2 === eof) {
  39732. break;
  39733. }
  39734. s += lookup[n2];
  39735. }
  39736. return parseFloat(s);
  39737. }
  39738. // Parse a `CFF` DICT operand.
  39739. function parseOperand(parser, b0) {
  39740. var b1;
  39741. var b2;
  39742. var b3;
  39743. var b4;
  39744. if (b0 === 28) {
  39745. b1 = parser.parseByte();
  39746. b2 = parser.parseByte();
  39747. return (b1 << 8) | b2;
  39748. }
  39749. if (b0 === 29) {
  39750. b1 = parser.parseByte();
  39751. b2 = parser.parseByte();
  39752. b3 = parser.parseByte();
  39753. b4 = parser.parseByte();
  39754. return (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
  39755. }
  39756. if (b0 === 30) {
  39757. return parseFloatOperand(parser);
  39758. }
  39759. if (b0 >= 32 && b0 <= 246) {
  39760. return b0 - 139;
  39761. }
  39762. if (b0 >= 247 && b0 <= 250) {
  39763. b1 = parser.parseByte();
  39764. return (b0 - 247) * 256 + b1 + 108;
  39765. }
  39766. if (b0 >= 251 && b0 <= 254) {
  39767. b1 = parser.parseByte();
  39768. return -(b0 - 251) * 256 - b1 - 108;
  39769. }
  39770. throw new Error('Invalid b0 ' + b0);
  39771. }
  39772. // Convert the entries returned by `parseDict` to a proper dictionary.
  39773. // If a value is a list of one, it is unpacked.
  39774. function entriesToObject(entries) {
  39775. var o = {};
  39776. for (var i = 0; i < entries.length; i += 1) {
  39777. var key = entries[i][0];
  39778. var values = entries[i][1];
  39779. var value = void 0;
  39780. if (values.length === 1) {
  39781. value = values[0];
  39782. } else {
  39783. value = values;
  39784. }
  39785. if (o.hasOwnProperty(key) && !isNaN(o[key])) {
  39786. throw new Error('Object ' + o + ' already has key ' + key);
  39787. }
  39788. o[key] = value;
  39789. }
  39790. return o;
  39791. }
  39792. // Parse a `CFF` DICT object.
  39793. // A dictionary contains key-value pairs in a compact tokenized format.
  39794. function parseCFFDict(data, start, size) {
  39795. start = start !== undefined ? start : 0;
  39796. var parser = new parse.Parser(data, start);
  39797. var entries = [];
  39798. var operands = [];
  39799. size = size !== undefined ? size : data.length;
  39800. while (parser.relativeOffset < size) {
  39801. var op = parser.parseByte();
  39802. // The first byte for each dict item distinguishes between operator (key) and operand (value).
  39803. // Values <= 21 are operators.
  39804. if (op <= 21) {
  39805. // Two-byte operators have an initial escape byte of 12.
  39806. if (op === 12) {
  39807. op = 1200 + parser.parseByte();
  39808. }
  39809. entries.push([op, operands]);
  39810. operands = [];
  39811. } else {
  39812. // Since the operands (values) come before the operators (keys), we store all operands in a list
  39813. // until we encounter an operator.
  39814. operands.push(parseOperand(parser, op));
  39815. }
  39816. }
  39817. return entriesToObject(entries);
  39818. }
  39819. // Given a String Index (SID), return the value of the string.
  39820. // Strings below index 392 are standard CFF strings and are not encoded in the font.
  39821. function getCFFString(strings, index) {
  39822. if (index <= 390) {
  39823. index = cffStandardStrings[index];
  39824. } else {
  39825. index = strings[index - 391];
  39826. }
  39827. return index;
  39828. }
  39829. // Interpret a dictionary and return a new dictionary with readable keys and values for missing entries.
  39830. // This function takes `meta` which is a list of objects containing `operand`, `name` and `default`.
  39831. function interpretDict(dict, meta, strings) {
  39832. var newDict = {};
  39833. var value;
  39834. // Because we also want to include missing values, we start out from the meta list
  39835. // and lookup values in the dict.
  39836. for (var i = 0; i < meta.length; i += 1) {
  39837. var m = meta[i];
  39838. if (Array.isArray(m.type)) {
  39839. var values = [];
  39840. values.length = m.type.length;
  39841. for (var j = 0; j < m.type.length; j++) {
  39842. value = dict[m.op] !== undefined ? dict[m.op][j] : undefined;
  39843. if (value === undefined) {
  39844. value =
  39845. m.value !== undefined && m.value[j] !== undefined
  39846. ? m.value[j]
  39847. : null;
  39848. }
  39849. if (m.type[j] === 'SID') {
  39850. value = getCFFString(strings, value);
  39851. }
  39852. values[j] = value;
  39853. }
  39854. newDict[m.name] = values;
  39855. } else {
  39856. value = dict[m.op];
  39857. if (value === undefined) {
  39858. value = m.value !== undefined ? m.value : null;
  39859. }
  39860. if (m.type === 'SID') {
  39861. value = getCFFString(strings, value);
  39862. }
  39863. newDict[m.name] = value;
  39864. }
  39865. }
  39866. return newDict;
  39867. }
  39868. // Parse the CFF header.
  39869. function parseCFFHeader(data, start) {
  39870. var header = {};
  39871. header.formatMajor = parse.getCard8(data, start);
  39872. header.formatMinor = parse.getCard8(data, start + 1);
  39873. header.size = parse.getCard8(data, start + 2);
  39874. header.offsetSize = parse.getCard8(data, start + 3);
  39875. header.startOffset = start;
  39876. header.endOffset = start + 4;
  39877. return header;
  39878. }
  39879. var TOP_DICT_META = [
  39880. { name: 'version', op: 0, type: 'SID' },
  39881. { name: 'notice', op: 1, type: 'SID' },
  39882. { name: 'copyright', op: 1200, type: 'SID' },
  39883. { name: 'fullName', op: 2, type: 'SID' },
  39884. { name: 'familyName', op: 3, type: 'SID' },
  39885. { name: 'weight', op: 4, type: 'SID' },
  39886. { name: 'isFixedPitch', op: 1201, type: 'number', value: 0 },
  39887. { name: 'italicAngle', op: 1202, type: 'number', value: 0 },
  39888. { name: 'underlinePosition', op: 1203, type: 'number', value: -100 },
  39889. { name: 'underlineThickness', op: 1204, type: 'number', value: 50 },
  39890. { name: 'paintType', op: 1205, type: 'number', value: 0 },
  39891. { name: 'charstringType', op: 1206, type: 'number', value: 2 },
  39892. {
  39893. name: 'fontMatrix',
  39894. op: 1207,
  39895. type: ['real', 'real', 'real', 'real', 'real', 'real'],
  39896. value: [0.001, 0, 0, 0.001, 0, 0]
  39897. },
  39898. { name: 'uniqueId', op: 13, type: 'number' },
  39899. {
  39900. name: 'fontBBox',
  39901. op: 5,
  39902. type: ['number', 'number', 'number', 'number'],
  39903. value: [0, 0, 0, 0]
  39904. },
  39905. { name: 'strokeWidth', op: 1208, type: 'number', value: 0 },
  39906. { name: 'xuid', op: 14, type: [], value: null },
  39907. { name: 'charset', op: 15, type: 'offset', value: 0 },
  39908. { name: 'encoding', op: 16, type: 'offset', value: 0 },
  39909. { name: 'charStrings', op: 17, type: 'offset', value: 0 },
  39910. { name: 'private', op: 18, type: ['number', 'offset'], value: [0, 0] },
  39911. { name: 'ros', op: 1230, type: ['SID', 'SID', 'number'] },
  39912. { name: 'cidFontVersion', op: 1231, type: 'number', value: 0 },
  39913. { name: 'cidFontRevision', op: 1232, type: 'number', value: 0 },
  39914. { name: 'cidFontType', op: 1233, type: 'number', value: 0 },
  39915. { name: 'cidCount', op: 1234, type: 'number', value: 8720 },
  39916. { name: 'uidBase', op: 1235, type: 'number' },
  39917. { name: 'fdArray', op: 1236, type: 'offset' },
  39918. { name: 'fdSelect', op: 1237, type: 'offset' },
  39919. { name: 'fontName', op: 1238, type: 'SID' }
  39920. ];
  39921. var PRIVATE_DICT_META = [
  39922. { name: 'subrs', op: 19, type: 'offset', value: 0 },
  39923. { name: 'defaultWidthX', op: 20, type: 'number', value: 0 },
  39924. { name: 'nominalWidthX', op: 21, type: 'number', value: 0 }
  39925. ];
  39926. // Parse the CFF top dictionary. A CFF table can contain multiple fonts, each with their own top dictionary.
  39927. // The top dictionary contains the essential metadata for the font, together with the private dictionary.
  39928. function parseCFFTopDict(data, strings) {
  39929. var dict = parseCFFDict(data, 0, data.byteLength);
  39930. return interpretDict(dict, TOP_DICT_META, strings);
  39931. }
  39932. // Parse the CFF private dictionary. We don't fully parse out all the values, only the ones we need.
  39933. function parseCFFPrivateDict(data, start, size, strings) {
  39934. var dict = parseCFFDict(data, start, size);
  39935. return interpretDict(dict, PRIVATE_DICT_META, strings);
  39936. }
  39937. // Returns a list of "Top DICT"s found using an INDEX list.
  39938. // Used to read both the usual high-level Top DICTs and also the FDArray
  39939. // discovered inside CID-keyed fonts. When a Top DICT has a reference to
  39940. // a Private DICT that is read and saved into the Top DICT.
  39941. //
  39942. // In addition to the expected/optional values as outlined in TOP_DICT_META
  39943. // the following values might be saved into the Top DICT.
  39944. //
  39945. // _subrs [] array of local CFF subroutines from Private DICT
  39946. // _subrsBias bias value computed from number of subroutines
  39947. // (see calcCFFSubroutineBias() and parseCFFCharstring())
  39948. // _defaultWidthX default widths for CFF characters
  39949. // _nominalWidthX bias added to width embedded within glyph description
  39950. //
  39951. // _privateDict saved copy of parsed Private DICT from Top DICT
  39952. function gatherCFFTopDicts(data, start, cffIndex, strings) {
  39953. var topDictArray = [];
  39954. for (var iTopDict = 0; iTopDict < cffIndex.length; iTopDict += 1) {
  39955. var topDictData = new DataView(new Uint8Array(cffIndex[iTopDict]).buffer);
  39956. var topDict = parseCFFTopDict(topDictData, strings);
  39957. topDict._subrs = [];
  39958. topDict._subrsBias = 0;
  39959. var privateSize = topDict.private[0];
  39960. var privateOffset = topDict.private[1];
  39961. if (privateSize !== 0 && privateOffset !== 0) {
  39962. var privateDict = parseCFFPrivateDict(
  39963. data,
  39964. privateOffset + start,
  39965. privateSize,
  39966. strings
  39967. );
  39968. topDict._defaultWidthX = privateDict.defaultWidthX;
  39969. topDict._nominalWidthX = privateDict.nominalWidthX;
  39970. if (privateDict.subrs !== 0) {
  39971. var subrOffset = privateOffset + privateDict.subrs;
  39972. var subrIndex = parseCFFIndex(data, subrOffset + start);
  39973. topDict._subrs = subrIndex.objects;
  39974. topDict._subrsBias = calcCFFSubroutineBias(topDict._subrs);
  39975. }
  39976. topDict._privateDict = privateDict;
  39977. }
  39978. topDictArray.push(topDict);
  39979. }
  39980. return topDictArray;
  39981. }
  39982. // Parse the CFF charset table, which contains internal names for all the glyphs.
  39983. // This function will return a list of glyph names.
  39984. // See Adobe TN #5176 chapter 13, "Charsets".
  39985. function parseCFFCharset(data, start, nGlyphs, strings) {
  39986. var sid;
  39987. var count;
  39988. var parser = new parse.Parser(data, start);
  39989. // The .notdef glyph is not included, so subtract 1.
  39990. nGlyphs -= 1;
  39991. var charset = ['.notdef'];
  39992. var format = parser.parseCard8();
  39993. if (format === 0) {
  39994. for (var i = 0; i < nGlyphs; i += 1) {
  39995. sid = parser.parseSID();
  39996. charset.push(getCFFString(strings, sid));
  39997. }
  39998. } else if (format === 1) {
  39999. while (charset.length <= nGlyphs) {
  40000. sid = parser.parseSID();
  40001. count = parser.parseCard8();
  40002. for (var i$1 = 0; i$1 <= count; i$1 += 1) {
  40003. charset.push(getCFFString(strings, sid));
  40004. sid += 1;
  40005. }
  40006. }
  40007. } else if (format === 2) {
  40008. while (charset.length <= nGlyphs) {
  40009. sid = parser.parseSID();
  40010. count = parser.parseCard16();
  40011. for (var i$2 = 0; i$2 <= count; i$2 += 1) {
  40012. charset.push(getCFFString(strings, sid));
  40013. sid += 1;
  40014. }
  40015. }
  40016. } else {
  40017. throw new Error('Unknown charset format ' + format);
  40018. }
  40019. return charset;
  40020. }
  40021. // Parse the CFF encoding data. Only one encoding can be specified per font.
  40022. // See Adobe TN #5176 chapter 12, "Encodings".
  40023. function parseCFFEncoding(data, start, charset) {
  40024. var code;
  40025. var enc = {};
  40026. var parser = new parse.Parser(data, start);
  40027. var format = parser.parseCard8();
  40028. if (format === 0) {
  40029. var nCodes = parser.parseCard8();
  40030. for (var i = 0; i < nCodes; i += 1) {
  40031. code = parser.parseCard8();
  40032. enc[code] = i;
  40033. }
  40034. } else if (format === 1) {
  40035. var nRanges = parser.parseCard8();
  40036. code = 1;
  40037. for (var i$1 = 0; i$1 < nRanges; i$1 += 1) {
  40038. var first = parser.parseCard8();
  40039. var nLeft = parser.parseCard8();
  40040. for (var j = first; j <= first + nLeft; j += 1) {
  40041. enc[j] = code;
  40042. code += 1;
  40043. }
  40044. }
  40045. } else {
  40046. throw new Error('Unknown encoding format ' + format);
  40047. }
  40048. return new CffEncoding(enc, charset);
  40049. }
  40050. // Take in charstring code and return a Glyph object.
  40051. // The encoding is described in the Type 2 Charstring Format
  40052. // https://www.microsoft.com/typography/OTSPEC/charstr2.htm
  40053. function parseCFFCharstring(font, glyph, code) {
  40054. var c1x;
  40055. var c1y;
  40056. var c2x;
  40057. var c2y;
  40058. var p = new Path();
  40059. var stack = [];
  40060. var nStems = 0;
  40061. var haveWidth = false;
  40062. var open = false;
  40063. var x = 0;
  40064. var y = 0;
  40065. var subrs;
  40066. var subrsBias;
  40067. var defaultWidthX;
  40068. var nominalWidthX;
  40069. if (font.isCIDFont) {
  40070. var fdIndex = font.tables.cff.topDict._fdSelect[glyph.index];
  40071. var fdDict = font.tables.cff.topDict._fdArray[fdIndex];
  40072. subrs = fdDict._subrs;
  40073. subrsBias = fdDict._subrsBias;
  40074. defaultWidthX = fdDict._defaultWidthX;
  40075. nominalWidthX = fdDict._nominalWidthX;
  40076. } else {
  40077. subrs = font.tables.cff.topDict._subrs;
  40078. subrsBias = font.tables.cff.topDict._subrsBias;
  40079. defaultWidthX = font.tables.cff.topDict._defaultWidthX;
  40080. nominalWidthX = font.tables.cff.topDict._nominalWidthX;
  40081. }
  40082. var width = defaultWidthX;
  40083. function newContour(x, y) {
  40084. if (open) {
  40085. p.closePath();
  40086. }
  40087. p.moveTo(x, y);
  40088. open = true;
  40089. }
  40090. function parseStems() {
  40091. var hasWidthArg;
  40092. // The number of stem operators on the stack is always even.
  40093. // If the value is uneven, that means a width is specified.
  40094. hasWidthArg = stack.length % 2 !== 0;
  40095. if (hasWidthArg && !haveWidth) {
  40096. width = stack.shift() + nominalWidthX;
  40097. }
  40098. nStems += stack.length >> 1;
  40099. stack.length = 0;
  40100. haveWidth = true;
  40101. }
  40102. function parse$$1(code) {
  40103. var b1;
  40104. var b2;
  40105. var b3;
  40106. var b4;
  40107. var codeIndex;
  40108. var subrCode;
  40109. var jpx;
  40110. var jpy;
  40111. var c3x;
  40112. var c3y;
  40113. var c4x;
  40114. var c4y;
  40115. var i = 0;
  40116. while (i < code.length) {
  40117. var v = code[i];
  40118. i += 1;
  40119. switch (v) {
  40120. case 1: // hstem
  40121. parseStems();
  40122. break;
  40123. case 3: // vstem
  40124. parseStems();
  40125. break;
  40126. case 4: // vmoveto
  40127. if (stack.length > 1 && !haveWidth) {
  40128. width = stack.shift() + nominalWidthX;
  40129. haveWidth = true;
  40130. }
  40131. y += stack.pop();
  40132. newContour(x, y);
  40133. break;
  40134. case 5: // rlineto
  40135. while (stack.length > 0) {
  40136. x += stack.shift();
  40137. y += stack.shift();
  40138. p.lineTo(x, y);
  40139. }
  40140. break;
  40141. case 6: // hlineto
  40142. while (stack.length > 0) {
  40143. x += stack.shift();
  40144. p.lineTo(x, y);
  40145. if (stack.length === 0) {
  40146. break;
  40147. }
  40148. y += stack.shift();
  40149. p.lineTo(x, y);
  40150. }
  40151. break;
  40152. case 7: // vlineto
  40153. while (stack.length > 0) {
  40154. y += stack.shift();
  40155. p.lineTo(x, y);
  40156. if (stack.length === 0) {
  40157. break;
  40158. }
  40159. x += stack.shift();
  40160. p.lineTo(x, y);
  40161. }
  40162. break;
  40163. case 8: // rrcurveto
  40164. while (stack.length > 0) {
  40165. c1x = x + stack.shift();
  40166. c1y = y + stack.shift();
  40167. c2x = c1x + stack.shift();
  40168. c2y = c1y + stack.shift();
  40169. x = c2x + stack.shift();
  40170. y = c2y + stack.shift();
  40171. p.curveTo(c1x, c1y, c2x, c2y, x, y);
  40172. }
  40173. break;
  40174. case 10: // callsubr
  40175. codeIndex = stack.pop() + subrsBias;
  40176. subrCode = subrs[codeIndex];
  40177. if (subrCode) {
  40178. parse$$1(subrCode);
  40179. }
  40180. break;
  40181. case 11: // return
  40182. return;
  40183. case 12: // flex operators
  40184. v = code[i];
  40185. i += 1;
  40186. switch (v) {
  40187. case 35: // flex
  40188. // |- dx1 dy1 dx2 dy2 dx3 dy3 dx4 dy4 dx5 dy5 dx6 dy6 fd flex (12 35) |-
  40189. c1x = x + stack.shift(); // dx1
  40190. c1y = y + stack.shift(); // dy1
  40191. c2x = c1x + stack.shift(); // dx2
  40192. c2y = c1y + stack.shift(); // dy2
  40193. jpx = c2x + stack.shift(); // dx3
  40194. jpy = c2y + stack.shift(); // dy3
  40195. c3x = jpx + stack.shift(); // dx4
  40196. c3y = jpy + stack.shift(); // dy4
  40197. c4x = c3x + stack.shift(); // dx5
  40198. c4y = c3y + stack.shift(); // dy5
  40199. x = c4x + stack.shift(); // dx6
  40200. y = c4y + stack.shift(); // dy6
  40201. stack.shift(); // flex depth
  40202. p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy);
  40203. p.curveTo(c3x, c3y, c4x, c4y, x, y);
  40204. break;
  40205. case 34: // hflex
  40206. // |- dx1 dx2 dy2 dx3 dx4 dx5 dx6 hflex (12 34) |-
  40207. c1x = x + stack.shift(); // dx1
  40208. c1y = y; // dy1
  40209. c2x = c1x + stack.shift(); // dx2
  40210. c2y = c1y + stack.shift(); // dy2
  40211. jpx = c2x + stack.shift(); // dx3
  40212. jpy = c2y; // dy3
  40213. c3x = jpx + stack.shift(); // dx4
  40214. c3y = c2y; // dy4
  40215. c4x = c3x + stack.shift(); // dx5
  40216. c4y = y; // dy5
  40217. x = c4x + stack.shift(); // dx6
  40218. p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy);
  40219. p.curveTo(c3x, c3y, c4x, c4y, x, y);
  40220. break;
  40221. case 36: // hflex1
  40222. // |- dx1 dy1 dx2 dy2 dx3 dx4 dx5 dy5 dx6 hflex1 (12 36) |-
  40223. c1x = x + stack.shift(); // dx1
  40224. c1y = y + stack.shift(); // dy1
  40225. c2x = c1x + stack.shift(); // dx2
  40226. c2y = c1y + stack.shift(); // dy2
  40227. jpx = c2x + stack.shift(); // dx3
  40228. jpy = c2y; // dy3
  40229. c3x = jpx + stack.shift(); // dx4
  40230. c3y = c2y; // dy4
  40231. c4x = c3x + stack.shift(); // dx5
  40232. c4y = c3y + stack.shift(); // dy5
  40233. x = c4x + stack.shift(); // dx6
  40234. p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy);
  40235. p.curveTo(c3x, c3y, c4x, c4y, x, y);
  40236. break;
  40237. case 37: // flex1
  40238. // |- dx1 dy1 dx2 dy2 dx3 dy3 dx4 dy4 dx5 dy5 d6 flex1 (12 37) |-
  40239. c1x = x + stack.shift(); // dx1
  40240. c1y = y + stack.shift(); // dy1
  40241. c2x = c1x + stack.shift(); // dx2
  40242. c2y = c1y + stack.shift(); // dy2
  40243. jpx = c2x + stack.shift(); // dx3
  40244. jpy = c2y + stack.shift(); // dy3
  40245. c3x = jpx + stack.shift(); // dx4
  40246. c3y = jpy + stack.shift(); // dy4
  40247. c4x = c3x + stack.shift(); // dx5
  40248. c4y = c3y + stack.shift(); // dy5
  40249. if (Math.abs(c4x - x) > Math.abs(c4y - y)) {
  40250. x = c4x + stack.shift();
  40251. } else {
  40252. y = c4y + stack.shift();
  40253. }
  40254. p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy);
  40255. p.curveTo(c3x, c3y, c4x, c4y, x, y);
  40256. break;
  40257. default:
  40258. console.log(
  40259. 'Glyph ' + glyph.index + ': unknown operator ' + 1200 + v
  40260. );
  40261. stack.length = 0;
  40262. }
  40263. break;
  40264. case 14: // endchar
  40265. if (stack.length > 0 && !haveWidth) {
  40266. width = stack.shift() + nominalWidthX;
  40267. haveWidth = true;
  40268. }
  40269. if (open) {
  40270. p.closePath();
  40271. open = false;
  40272. }
  40273. break;
  40274. case 18: // hstemhm
  40275. parseStems();
  40276. break;
  40277. case 19: // hintmask
  40278. case 20: // cntrmask
  40279. parseStems();
  40280. i += (nStems + 7) >> 3;
  40281. break;
  40282. case 21: // rmoveto
  40283. if (stack.length > 2 && !haveWidth) {
  40284. width = stack.shift() + nominalWidthX;
  40285. haveWidth = true;
  40286. }
  40287. y += stack.pop();
  40288. x += stack.pop();
  40289. newContour(x, y);
  40290. break;
  40291. case 22: // hmoveto
  40292. if (stack.length > 1 && !haveWidth) {
  40293. width = stack.shift() + nominalWidthX;
  40294. haveWidth = true;
  40295. }
  40296. x += stack.pop();
  40297. newContour(x, y);
  40298. break;
  40299. case 23: // vstemhm
  40300. parseStems();
  40301. break;
  40302. case 24: // rcurveline
  40303. while (stack.length > 2) {
  40304. c1x = x + stack.shift();
  40305. c1y = y + stack.shift();
  40306. c2x = c1x + stack.shift();
  40307. c2y = c1y + stack.shift();
  40308. x = c2x + stack.shift();
  40309. y = c2y + stack.shift();
  40310. p.curveTo(c1x, c1y, c2x, c2y, x, y);
  40311. }
  40312. x += stack.shift();
  40313. y += stack.shift();
  40314. p.lineTo(x, y);
  40315. break;
  40316. case 25: // rlinecurve
  40317. while (stack.length > 6) {
  40318. x += stack.shift();
  40319. y += stack.shift();
  40320. p.lineTo(x, y);
  40321. }
  40322. c1x = x + stack.shift();
  40323. c1y = y + stack.shift();
  40324. c2x = c1x + stack.shift();
  40325. c2y = c1y + stack.shift();
  40326. x = c2x + stack.shift();
  40327. y = c2y + stack.shift();
  40328. p.curveTo(c1x, c1y, c2x, c2y, x, y);
  40329. break;
  40330. case 26: // vvcurveto
  40331. if (stack.length % 2) {
  40332. x += stack.shift();
  40333. }
  40334. while (stack.length > 0) {
  40335. c1x = x;
  40336. c1y = y + stack.shift();
  40337. c2x = c1x + stack.shift();
  40338. c2y = c1y + stack.shift();
  40339. x = c2x;
  40340. y = c2y + stack.shift();
  40341. p.curveTo(c1x, c1y, c2x, c2y, x, y);
  40342. }
  40343. break;
  40344. case 27: // hhcurveto
  40345. if (stack.length % 2) {
  40346. y += stack.shift();
  40347. }
  40348. while (stack.length > 0) {
  40349. c1x = x + stack.shift();
  40350. c1y = y;
  40351. c2x = c1x + stack.shift();
  40352. c2y = c1y + stack.shift();
  40353. x = c2x + stack.shift();
  40354. y = c2y;
  40355. p.curveTo(c1x, c1y, c2x, c2y, x, y);
  40356. }
  40357. break;
  40358. case 28: // shortint
  40359. b1 = code[i];
  40360. b2 = code[i + 1];
  40361. stack.push(((b1 << 24) | (b2 << 16)) >> 16);
  40362. i += 2;
  40363. break;
  40364. case 29: // callgsubr
  40365. codeIndex = stack.pop() + font.gsubrsBias;
  40366. subrCode = font.gsubrs[codeIndex];
  40367. if (subrCode) {
  40368. parse$$1(subrCode);
  40369. }
  40370. break;
  40371. case 30: // vhcurveto
  40372. while (stack.length > 0) {
  40373. c1x = x;
  40374. c1y = y + stack.shift();
  40375. c2x = c1x + stack.shift();
  40376. c2y = c1y + stack.shift();
  40377. x = c2x + stack.shift();
  40378. y = c2y + (stack.length === 1 ? stack.shift() : 0);
  40379. p.curveTo(c1x, c1y, c2x, c2y, x, y);
  40380. if (stack.length === 0) {
  40381. break;
  40382. }
  40383. c1x = x + stack.shift();
  40384. c1y = y;
  40385. c2x = c1x + stack.shift();
  40386. c2y = c1y + stack.shift();
  40387. y = c2y + stack.shift();
  40388. x = c2x + (stack.length === 1 ? stack.shift() : 0);
  40389. p.curveTo(c1x, c1y, c2x, c2y, x, y);
  40390. }
  40391. break;
  40392. case 31: // hvcurveto
  40393. while (stack.length > 0) {
  40394. c1x = x + stack.shift();
  40395. c1y = y;
  40396. c2x = c1x + stack.shift();
  40397. c2y = c1y + stack.shift();
  40398. y = c2y + stack.shift();
  40399. x = c2x + (stack.length === 1 ? stack.shift() : 0);
  40400. p.curveTo(c1x, c1y, c2x, c2y, x, y);
  40401. if (stack.length === 0) {
  40402. break;
  40403. }
  40404. c1x = x;
  40405. c1y = y + stack.shift();
  40406. c2x = c1x + stack.shift();
  40407. c2y = c1y + stack.shift();
  40408. x = c2x + stack.shift();
  40409. y = c2y + (stack.length === 1 ? stack.shift() : 0);
  40410. p.curveTo(c1x, c1y, c2x, c2y, x, y);
  40411. }
  40412. break;
  40413. default:
  40414. if (v < 32) {
  40415. console.log('Glyph ' + glyph.index + ': unknown operator ' + v);
  40416. } else if (v < 247) {
  40417. stack.push(v - 139);
  40418. } else if (v < 251) {
  40419. b1 = code[i];
  40420. i += 1;
  40421. stack.push((v - 247) * 256 + b1 + 108);
  40422. } else if (v < 255) {
  40423. b1 = code[i];
  40424. i += 1;
  40425. stack.push(-(v - 251) * 256 - b1 - 108);
  40426. } else {
  40427. b1 = code[i];
  40428. b2 = code[i + 1];
  40429. b3 = code[i + 2];
  40430. b4 = code[i + 3];
  40431. i += 4;
  40432. stack.push(((b1 << 24) | (b2 << 16) | (b3 << 8) | b4) / 65536);
  40433. }
  40434. }
  40435. }
  40436. }
  40437. parse$$1(code);
  40438. glyph.advanceWidth = width;
  40439. return p;
  40440. }
  40441. function parseCFFFDSelect(data, start, nGlyphs, fdArrayCount) {
  40442. var fdSelect = [];
  40443. var fdIndex;
  40444. var parser = new parse.Parser(data, start);
  40445. var format = parser.parseCard8();
  40446. if (format === 0) {
  40447. // Simple list of nGlyphs elements
  40448. for (var iGid = 0; iGid < nGlyphs; iGid++) {
  40449. fdIndex = parser.parseCard8();
  40450. if (fdIndex >= fdArrayCount) {
  40451. throw new Error(
  40452. 'CFF table CID Font FDSelect has bad FD index value ' +
  40453. fdIndex +
  40454. ' (FD count ' +
  40455. fdArrayCount +
  40456. ')'
  40457. );
  40458. }
  40459. fdSelect.push(fdIndex);
  40460. }
  40461. } else if (format === 3) {
  40462. // Ranges
  40463. var nRanges = parser.parseCard16();
  40464. var first = parser.parseCard16();
  40465. if (first !== 0) {
  40466. throw new Error(
  40467. 'CFF Table CID Font FDSelect format 3 range has bad initial GID ' +
  40468. first
  40469. );
  40470. }
  40471. var next;
  40472. for (var iRange = 0; iRange < nRanges; iRange++) {
  40473. fdIndex = parser.parseCard8();
  40474. next = parser.parseCard16();
  40475. if (fdIndex >= fdArrayCount) {
  40476. throw new Error(
  40477. 'CFF table CID Font FDSelect has bad FD index value ' +
  40478. fdIndex +
  40479. ' (FD count ' +
  40480. fdArrayCount +
  40481. ')'
  40482. );
  40483. }
  40484. if (next > nGlyphs) {
  40485. throw new Error(
  40486. 'CFF Table CID Font FDSelect format 3 range has bad GID ' + next
  40487. );
  40488. }
  40489. for (; first < next; first++) {
  40490. fdSelect.push(fdIndex);
  40491. }
  40492. first = next;
  40493. }
  40494. if (next !== nGlyphs) {
  40495. throw new Error(
  40496. 'CFF Table CID Font FDSelect format 3 range has bad final GID ' + next
  40497. );
  40498. }
  40499. } else {
  40500. throw new Error(
  40501. 'CFF Table CID Font FDSelect table has unsupported format ' + format
  40502. );
  40503. }
  40504. return fdSelect;
  40505. }
  40506. // Parse the `CFF` table, which contains the glyph outlines in PostScript format.
  40507. function parseCFFTable(data, start, font) {
  40508. font.tables.cff = {};
  40509. var header = parseCFFHeader(data, start);
  40510. var nameIndex = parseCFFIndex(data, header.endOffset, parse.bytesToString);
  40511. var topDictIndex = parseCFFIndex(data, nameIndex.endOffset);
  40512. var stringIndex = parseCFFIndex(
  40513. data,
  40514. topDictIndex.endOffset,
  40515. parse.bytesToString
  40516. );
  40517. var globalSubrIndex = parseCFFIndex(data, stringIndex.endOffset);
  40518. font.gsubrs = globalSubrIndex.objects;
  40519. font.gsubrsBias = calcCFFSubroutineBias(font.gsubrs);
  40520. var topDictArray = gatherCFFTopDicts(
  40521. data,
  40522. start,
  40523. topDictIndex.objects,
  40524. stringIndex.objects
  40525. );
  40526. if (topDictArray.length !== 1) {
  40527. throw new Error(
  40528. "CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = " +
  40529. topDictArray.length
  40530. );
  40531. }
  40532. var topDict = topDictArray[0];
  40533. font.tables.cff.topDict = topDict;
  40534. if (topDict._privateDict) {
  40535. font.defaultWidthX = topDict._privateDict.defaultWidthX;
  40536. font.nominalWidthX = topDict._privateDict.nominalWidthX;
  40537. }
  40538. if (topDict.ros[0] !== undefined && topDict.ros[1] !== undefined) {
  40539. font.isCIDFont = true;
  40540. }
  40541. if (font.isCIDFont) {
  40542. var fdArrayOffset = topDict.fdArray;
  40543. var fdSelectOffset = topDict.fdSelect;
  40544. if (fdArrayOffset === 0 || fdSelectOffset === 0) {
  40545. throw new Error(
  40546. 'Font is marked as a CID font, but FDArray and/or FDSelect information is missing'
  40547. );
  40548. }
  40549. fdArrayOffset += start;
  40550. var fdArrayIndex = parseCFFIndex(data, fdArrayOffset);
  40551. var fdArray = gatherCFFTopDicts(
  40552. data,
  40553. start,
  40554. fdArrayIndex.objects,
  40555. stringIndex.objects
  40556. );
  40557. topDict._fdArray = fdArray;
  40558. fdSelectOffset += start;
  40559. topDict._fdSelect = parseCFFFDSelect(
  40560. data,
  40561. fdSelectOffset,
  40562. font.numGlyphs,
  40563. fdArray.length
  40564. );
  40565. }
  40566. var privateDictOffset = start + topDict.private[1];
  40567. var privateDict = parseCFFPrivateDict(
  40568. data,
  40569. privateDictOffset,
  40570. topDict.private[0],
  40571. stringIndex.objects
  40572. );
  40573. font.defaultWidthX = privateDict.defaultWidthX;
  40574. font.nominalWidthX = privateDict.nominalWidthX;
  40575. if (privateDict.subrs !== 0) {
  40576. var subrOffset = privateDictOffset + privateDict.subrs;
  40577. var subrIndex = parseCFFIndex(data, subrOffset);
  40578. font.subrs = subrIndex.objects;
  40579. font.subrsBias = calcCFFSubroutineBias(font.subrs);
  40580. } else {
  40581. font.subrs = [];
  40582. font.subrsBias = 0;
  40583. }
  40584. // Offsets in the top dict are relative to the beginning of the CFF data, so add the CFF start offset.
  40585. var charStringsIndex = parseCFFIndex(data, start + topDict.charStrings);
  40586. font.nGlyphs = charStringsIndex.objects.length;
  40587. var charset = parseCFFCharset(
  40588. data,
  40589. start + topDict.charset,
  40590. font.nGlyphs,
  40591. stringIndex.objects
  40592. );
  40593. if (topDict.encoding === 0) {
  40594. // Standard encoding
  40595. font.cffEncoding = new CffEncoding(cffStandardEncoding, charset);
  40596. } else if (topDict.encoding === 1) {
  40597. // Expert encoding
  40598. font.cffEncoding = new CffEncoding(cffExpertEncoding, charset);
  40599. } else {
  40600. font.cffEncoding = parseCFFEncoding(
  40601. data,
  40602. start + topDict.encoding,
  40603. charset
  40604. );
  40605. }
  40606. // Prefer the CMAP encoding to the CFF encoding.
  40607. font.encoding = font.encoding || font.cffEncoding;
  40608. font.glyphs = new glyphset.GlyphSet(font);
  40609. for (var i = 0; i < font.nGlyphs; i += 1) {
  40610. var charString = charStringsIndex.objects[i];
  40611. font.glyphs.push(
  40612. i,
  40613. glyphset.cffGlyphLoader(font, i, parseCFFCharstring, charString)
  40614. );
  40615. }
  40616. }
  40617. // Convert a string to a String ID (SID).
  40618. // The list of strings is modified in place.
  40619. function encodeString(s, strings) {
  40620. var sid;
  40621. // Is the string in the CFF standard strings?
  40622. var i = cffStandardStrings.indexOf(s);
  40623. if (i >= 0) {
  40624. sid = i;
  40625. }
  40626. // Is the string already in the string index?
  40627. i = strings.indexOf(s);
  40628. if (i >= 0) {
  40629. sid = i + cffStandardStrings.length;
  40630. } else {
  40631. sid = cffStandardStrings.length + strings.length;
  40632. strings.push(s);
  40633. }
  40634. return sid;
  40635. }
  40636. function makeHeader() {
  40637. return new table.Record('Header', [
  40638. { name: 'major', type: 'Card8', value: 1 },
  40639. { name: 'minor', type: 'Card8', value: 0 },
  40640. { name: 'hdrSize', type: 'Card8', value: 4 },
  40641. { name: 'major', type: 'Card8', value: 1 }
  40642. ]);
  40643. }
  40644. function makeNameIndex(fontNames) {
  40645. var t = new table.Record('Name INDEX', [
  40646. { name: 'names', type: 'INDEX', value: [] }
  40647. ]);
  40648. t.names = [];
  40649. for (var i = 0; i < fontNames.length; i += 1) {
  40650. t.names.push({ name: 'name_' + i, type: 'NAME', value: fontNames[i] });
  40651. }
  40652. return t;
  40653. }
  40654. // Given a dictionary's metadata, create a DICT structure.
  40655. function makeDict(meta, attrs, strings) {
  40656. var m = {};
  40657. for (var i = 0; i < meta.length; i += 1) {
  40658. var entry = meta[i];
  40659. var value = attrs[entry.name];
  40660. if (value !== undefined && !equals(value, entry.value)) {
  40661. if (entry.type === 'SID') {
  40662. value = encodeString(value, strings);
  40663. }
  40664. m[entry.op] = { name: entry.name, type: entry.type, value: value };
  40665. }
  40666. }
  40667. return m;
  40668. }
  40669. // The Top DICT houses the global font attributes.
  40670. function makeTopDict(attrs, strings) {
  40671. var t = new table.Record('Top DICT', [
  40672. { name: 'dict', type: 'DICT', value: {} }
  40673. ]);
  40674. t.dict = makeDict(TOP_DICT_META, attrs, strings);
  40675. return t;
  40676. }
  40677. function makeTopDictIndex(topDict) {
  40678. var t = new table.Record('Top DICT INDEX', [
  40679. { name: 'topDicts', type: 'INDEX', value: [] }
  40680. ]);
  40681. t.topDicts = [{ name: 'topDict_0', type: 'TABLE', value: topDict }];
  40682. return t;
  40683. }
  40684. function makeStringIndex(strings) {
  40685. var t = new table.Record('String INDEX', [
  40686. { name: 'strings', type: 'INDEX', value: [] }
  40687. ]);
  40688. t.strings = [];
  40689. for (var i = 0; i < strings.length; i += 1) {
  40690. t.strings.push({
  40691. name: 'string_' + i,
  40692. type: 'STRING',
  40693. value: strings[i]
  40694. });
  40695. }
  40696. return t;
  40697. }
  40698. function makeGlobalSubrIndex() {
  40699. // Currently we don't use subroutines.
  40700. return new table.Record('Global Subr INDEX', [
  40701. { name: 'subrs', type: 'INDEX', value: [] }
  40702. ]);
  40703. }
  40704. function makeCharsets(glyphNames, strings) {
  40705. var t = new table.Record('Charsets', [
  40706. { name: 'format', type: 'Card8', value: 0 }
  40707. ]);
  40708. for (var i = 0; i < glyphNames.length; i += 1) {
  40709. var glyphName = glyphNames[i];
  40710. var glyphSID = encodeString(glyphName, strings);
  40711. t.fields.push({ name: 'glyph_' + i, type: 'SID', value: glyphSID });
  40712. }
  40713. return t;
  40714. }
  40715. function glyphToOps(glyph) {
  40716. var ops = [];
  40717. var path = glyph.path;
  40718. ops.push({ name: 'width', type: 'NUMBER', value: glyph.advanceWidth });
  40719. var x = 0;
  40720. var y = 0;
  40721. for (var i = 0; i < path.commands.length; i += 1) {
  40722. var dx = void 0;
  40723. var dy = void 0;
  40724. var cmd = path.commands[i];
  40725. if (cmd.type === 'Q') {
  40726. // CFF only supports bézier curves, so convert the quad to a bézier.
  40727. var _13 = 1 / 3;
  40728. var _23 = 2 / 3;
  40729. // We're going to create a new command so we don't change the original path.
  40730. cmd = {
  40731. type: 'C',
  40732. x: cmd.x,
  40733. y: cmd.y,
  40734. x1: _13 * x + _23 * cmd.x1,
  40735. y1: _13 * y + _23 * cmd.y1,
  40736. x2: _13 * cmd.x + _23 * cmd.x1,
  40737. y2: _13 * cmd.y + _23 * cmd.y1
  40738. };
  40739. }
  40740. if (cmd.type === 'M') {
  40741. dx = Math.round(cmd.x - x);
  40742. dy = Math.round(cmd.y - y);
  40743. ops.push({ name: 'dx', type: 'NUMBER', value: dx });
  40744. ops.push({ name: 'dy', type: 'NUMBER', value: dy });
  40745. ops.push({ name: 'rmoveto', type: 'OP', value: 21 });
  40746. x = Math.round(cmd.x);
  40747. y = Math.round(cmd.y);
  40748. } else if (cmd.type === 'L') {
  40749. dx = Math.round(cmd.x - x);
  40750. dy = Math.round(cmd.y - y);
  40751. ops.push({ name: 'dx', type: 'NUMBER', value: dx });
  40752. ops.push({ name: 'dy', type: 'NUMBER', value: dy });
  40753. ops.push({ name: 'rlineto', type: 'OP', value: 5 });
  40754. x = Math.round(cmd.x);
  40755. y = Math.round(cmd.y);
  40756. } else if (cmd.type === 'C') {
  40757. var dx1 = Math.round(cmd.x1 - x);
  40758. var dy1 = Math.round(cmd.y1 - y);
  40759. var dx2 = Math.round(cmd.x2 - cmd.x1);
  40760. var dy2 = Math.round(cmd.y2 - cmd.y1);
  40761. dx = Math.round(cmd.x - cmd.x2);
  40762. dy = Math.round(cmd.y - cmd.y2);
  40763. ops.push({ name: 'dx1', type: 'NUMBER', value: dx1 });
  40764. ops.push({ name: 'dy1', type: 'NUMBER', value: dy1 });
  40765. ops.push({ name: 'dx2', type: 'NUMBER', value: dx2 });
  40766. ops.push({ name: 'dy2', type: 'NUMBER', value: dy2 });
  40767. ops.push({ name: 'dx', type: 'NUMBER', value: dx });
  40768. ops.push({ name: 'dy', type: 'NUMBER', value: dy });
  40769. ops.push({ name: 'rrcurveto', type: 'OP', value: 8 });
  40770. x = Math.round(cmd.x);
  40771. y = Math.round(cmd.y);
  40772. }
  40773. // Contours are closed automatically.
  40774. }
  40775. ops.push({ name: 'endchar', type: 'OP', value: 14 });
  40776. return ops;
  40777. }
  40778. function makeCharStringsIndex(glyphs) {
  40779. var t = new table.Record('CharStrings INDEX', [
  40780. { name: 'charStrings', type: 'INDEX', value: [] }
  40781. ]);
  40782. for (var i = 0; i < glyphs.length; i += 1) {
  40783. var glyph = glyphs.get(i);
  40784. var ops = glyphToOps(glyph);
  40785. t.charStrings.push({ name: glyph.name, type: 'CHARSTRING', value: ops });
  40786. }
  40787. return t;
  40788. }
  40789. function makePrivateDict(attrs, strings) {
  40790. var t = new table.Record('Private DICT', [
  40791. { name: 'dict', type: 'DICT', value: {} }
  40792. ]);
  40793. t.dict = makeDict(PRIVATE_DICT_META, attrs, strings);
  40794. return t;
  40795. }
  40796. function makeCFFTable(glyphs, options) {
  40797. var t = new table.Table('CFF ', [
  40798. { name: 'header', type: 'RECORD' },
  40799. { name: 'nameIndex', type: 'RECORD' },
  40800. { name: 'topDictIndex', type: 'RECORD' },
  40801. { name: 'stringIndex', type: 'RECORD' },
  40802. { name: 'globalSubrIndex', type: 'RECORD' },
  40803. { name: 'charsets', type: 'RECORD' },
  40804. { name: 'charStringsIndex', type: 'RECORD' },
  40805. { name: 'privateDict', type: 'RECORD' }
  40806. ]);
  40807. var fontScale = 1 / options.unitsPerEm;
  40808. // We use non-zero values for the offsets so that the DICT encodes them.
  40809. // This is important because the size of the Top DICT plays a role in offset calculation,
  40810. // and the size shouldn't change after we've written correct offsets.
  40811. var attrs = {
  40812. version: options.version,
  40813. fullName: options.fullName,
  40814. familyName: options.familyName,
  40815. weight: options.weightName,
  40816. fontBBox: options.fontBBox || [0, 0, 0, 0],
  40817. fontMatrix: [fontScale, 0, 0, fontScale, 0, 0],
  40818. charset: 999,
  40819. encoding: 0,
  40820. charStrings: 999,
  40821. private: [0, 999]
  40822. };
  40823. var privateAttrs = {};
  40824. var glyphNames = [];
  40825. var glyph;
  40826. // Skip first glyph (.notdef)
  40827. for (var i = 1; i < glyphs.length; i += 1) {
  40828. glyph = glyphs.get(i);
  40829. glyphNames.push(glyph.name);
  40830. }
  40831. var strings = [];
  40832. t.header = makeHeader();
  40833. t.nameIndex = makeNameIndex([options.postScriptName]);
  40834. var topDict = makeTopDict(attrs, strings);
  40835. t.topDictIndex = makeTopDictIndex(topDict);
  40836. t.globalSubrIndex = makeGlobalSubrIndex();
  40837. t.charsets = makeCharsets(glyphNames, strings);
  40838. t.charStringsIndex = makeCharStringsIndex(glyphs);
  40839. t.privateDict = makePrivateDict(privateAttrs, strings);
  40840. // Needs to come at the end, to encode all custom strings used in the font.
  40841. t.stringIndex = makeStringIndex(strings);
  40842. var startOffset =
  40843. t.header.sizeOf() +
  40844. t.nameIndex.sizeOf() +
  40845. t.topDictIndex.sizeOf() +
  40846. t.stringIndex.sizeOf() +
  40847. t.globalSubrIndex.sizeOf();
  40848. attrs.charset = startOffset;
  40849. // We use the CFF standard encoding; proper encoding will be handled in cmap.
  40850. attrs.encoding = 0;
  40851. attrs.charStrings = attrs.charset + t.charsets.sizeOf();
  40852. attrs.private[1] = attrs.charStrings + t.charStringsIndex.sizeOf();
  40853. // Recreate the Top DICT INDEX with the correct offsets.
  40854. topDict = makeTopDict(attrs, strings);
  40855. t.topDictIndex = makeTopDictIndex(topDict);
  40856. return t;
  40857. }
  40858. var cff = { parse: parseCFFTable, make: makeCFFTable };
  40859. // The `head` table contains global information about the font.
  40860. // Parse the header `head` table
  40861. function parseHeadTable(data, start) {
  40862. var head = {};
  40863. var p = new parse.Parser(data, start);
  40864. head.version = p.parseVersion();
  40865. head.fontRevision = Math.round(p.parseFixed() * 1000) / 1000;
  40866. head.checkSumAdjustment = p.parseULong();
  40867. head.magicNumber = p.parseULong();
  40868. check.argument(
  40869. head.magicNumber === 0x5f0f3cf5,
  40870. 'Font header has wrong magic number.'
  40871. );
  40872. head.flags = p.parseUShort();
  40873. head.unitsPerEm = p.parseUShort();
  40874. head.created = p.parseLongDateTime();
  40875. head.modified = p.parseLongDateTime();
  40876. head.xMin = p.parseShort();
  40877. head.yMin = p.parseShort();
  40878. head.xMax = p.parseShort();
  40879. head.yMax = p.parseShort();
  40880. head.macStyle = p.parseUShort();
  40881. head.lowestRecPPEM = p.parseUShort();
  40882. head.fontDirectionHint = p.parseShort();
  40883. head.indexToLocFormat = p.parseShort();
  40884. head.glyphDataFormat = p.parseShort();
  40885. return head;
  40886. }
  40887. function makeHeadTable(options) {
  40888. // Apple Mac timestamp epoch is 01/01/1904 not 01/01/1970
  40889. var timestamp = Math.round(new Date().getTime() / 1000) + 2082844800;
  40890. var createdTimestamp = timestamp;
  40891. if (options.createdTimestamp) {
  40892. createdTimestamp = options.createdTimestamp + 2082844800;
  40893. }
  40894. return new table.Table(
  40895. 'head',
  40896. [
  40897. { name: 'version', type: 'FIXED', value: 0x00010000 },
  40898. { name: 'fontRevision', type: 'FIXED', value: 0x00010000 },
  40899. { name: 'checkSumAdjustment', type: 'ULONG', value: 0 },
  40900. { name: 'magicNumber', type: 'ULONG', value: 0x5f0f3cf5 },
  40901. { name: 'flags', type: 'USHORT', value: 0 },
  40902. { name: 'unitsPerEm', type: 'USHORT', value: 1000 },
  40903. { name: 'created', type: 'LONGDATETIME', value: createdTimestamp },
  40904. { name: 'modified', type: 'LONGDATETIME', value: timestamp },
  40905. { name: 'xMin', type: 'SHORT', value: 0 },
  40906. { name: 'yMin', type: 'SHORT', value: 0 },
  40907. { name: 'xMax', type: 'SHORT', value: 0 },
  40908. { name: 'yMax', type: 'SHORT', value: 0 },
  40909. { name: 'macStyle', type: 'USHORT', value: 0 },
  40910. { name: 'lowestRecPPEM', type: 'USHORT', value: 0 },
  40911. { name: 'fontDirectionHint', type: 'SHORT', value: 2 },
  40912. { name: 'indexToLocFormat', type: 'SHORT', value: 0 },
  40913. { name: 'glyphDataFormat', type: 'SHORT', value: 0 }
  40914. ],
  40915. options
  40916. );
  40917. }
  40918. var head = { parse: parseHeadTable, make: makeHeadTable };
  40919. // The `hhea` table contains information for horizontal layout.
  40920. // Parse the horizontal header `hhea` table
  40921. function parseHheaTable(data, start) {
  40922. var hhea = {};
  40923. var p = new parse.Parser(data, start);
  40924. hhea.version = p.parseVersion();
  40925. hhea.ascender = p.parseShort();
  40926. hhea.descender = p.parseShort();
  40927. hhea.lineGap = p.parseShort();
  40928. hhea.advanceWidthMax = p.parseUShort();
  40929. hhea.minLeftSideBearing = p.parseShort();
  40930. hhea.minRightSideBearing = p.parseShort();
  40931. hhea.xMaxExtent = p.parseShort();
  40932. hhea.caretSlopeRise = p.parseShort();
  40933. hhea.caretSlopeRun = p.parseShort();
  40934. hhea.caretOffset = p.parseShort();
  40935. p.relativeOffset += 8;
  40936. hhea.metricDataFormat = p.parseShort();
  40937. hhea.numberOfHMetrics = p.parseUShort();
  40938. return hhea;
  40939. }
  40940. function makeHheaTable(options) {
  40941. return new table.Table(
  40942. 'hhea',
  40943. [
  40944. { name: 'version', type: 'FIXED', value: 0x00010000 },
  40945. { name: 'ascender', type: 'FWORD', value: 0 },
  40946. { name: 'descender', type: 'FWORD', value: 0 },
  40947. { name: 'lineGap', type: 'FWORD', value: 0 },
  40948. { name: 'advanceWidthMax', type: 'UFWORD', value: 0 },
  40949. { name: 'minLeftSideBearing', type: 'FWORD', value: 0 },
  40950. { name: 'minRightSideBearing', type: 'FWORD', value: 0 },
  40951. { name: 'xMaxExtent', type: 'FWORD', value: 0 },
  40952. { name: 'caretSlopeRise', type: 'SHORT', value: 1 },
  40953. { name: 'caretSlopeRun', type: 'SHORT', value: 0 },
  40954. { name: 'caretOffset', type: 'SHORT', value: 0 },
  40955. { name: 'reserved1', type: 'SHORT', value: 0 },
  40956. { name: 'reserved2', type: 'SHORT', value: 0 },
  40957. { name: 'reserved3', type: 'SHORT', value: 0 },
  40958. { name: 'reserved4', type: 'SHORT', value: 0 },
  40959. { name: 'metricDataFormat', type: 'SHORT', value: 0 },
  40960. { name: 'numberOfHMetrics', type: 'USHORT', value: 0 }
  40961. ],
  40962. options
  40963. );
  40964. }
  40965. var hhea = { parse: parseHheaTable, make: makeHheaTable };
  40966. // The `hmtx` table contains the horizontal metrics for all glyphs.
  40967. // Parse the `hmtx` table, which contains the horizontal metrics for all glyphs.
  40968. // This function augments the glyph array, adding the advanceWidth and leftSideBearing to each glyph.
  40969. function parseHmtxTable(data, start, numMetrics, numGlyphs, glyphs) {
  40970. var advanceWidth;
  40971. var leftSideBearing;
  40972. var p = new parse.Parser(data, start);
  40973. for (var i = 0; i < numGlyphs; i += 1) {
  40974. // If the font is monospaced, only one entry is needed. This last entry applies to all subsequent glyphs.
  40975. if (i < numMetrics) {
  40976. advanceWidth = p.parseUShort();
  40977. leftSideBearing = p.parseShort();
  40978. }
  40979. var glyph = glyphs.get(i);
  40980. glyph.advanceWidth = advanceWidth;
  40981. glyph.leftSideBearing = leftSideBearing;
  40982. }
  40983. }
  40984. function makeHmtxTable(glyphs) {
  40985. var t = new table.Table('hmtx', []);
  40986. for (var i = 0; i < glyphs.length; i += 1) {
  40987. var glyph = glyphs.get(i);
  40988. var advanceWidth = glyph.advanceWidth || 0;
  40989. var leftSideBearing = glyph.leftSideBearing || 0;
  40990. t.fields.push({
  40991. name: 'advanceWidth_' + i,
  40992. type: 'USHORT',
  40993. value: advanceWidth
  40994. });
  40995. t.fields.push({
  40996. name: 'leftSideBearing_' + i,
  40997. type: 'SHORT',
  40998. value: leftSideBearing
  40999. });
  41000. }
  41001. return t;
  41002. }
  41003. var hmtx = { parse: parseHmtxTable, make: makeHmtxTable };
  41004. // The `ltag` table stores IETF BCP-47 language tags. It allows supporting
  41005. function makeLtagTable(tags) {
  41006. var result = new table.Table('ltag', [
  41007. { name: 'version', type: 'ULONG', value: 1 },
  41008. { name: 'flags', type: 'ULONG', value: 0 },
  41009. { name: 'numTags', type: 'ULONG', value: tags.length }
  41010. ]);
  41011. var stringPool = '';
  41012. var stringPoolOffset = 12 + tags.length * 4;
  41013. for (var i = 0; i < tags.length; ++i) {
  41014. var pos = stringPool.indexOf(tags[i]);
  41015. if (pos < 0) {
  41016. pos = stringPool.length;
  41017. stringPool += tags[i];
  41018. }
  41019. result.fields.push({
  41020. name: 'offset ' + i,
  41021. type: 'USHORT',
  41022. value: stringPoolOffset + pos
  41023. });
  41024. result.fields.push({
  41025. name: 'length ' + i,
  41026. type: 'USHORT',
  41027. value: tags[i].length
  41028. });
  41029. }
  41030. result.fields.push({
  41031. name: 'stringPool',
  41032. type: 'CHARARRAY',
  41033. value: stringPool
  41034. });
  41035. return result;
  41036. }
  41037. function parseLtagTable(data, start) {
  41038. var p = new parse.Parser(data, start);
  41039. var tableVersion = p.parseULong();
  41040. check.argument(tableVersion === 1, 'Unsupported ltag table version.');
  41041. // The 'ltag' specification does not define any flags; skip the field.
  41042. p.skip('uLong', 1);
  41043. var numTags = p.parseULong();
  41044. var tags = [];
  41045. for (var i = 0; i < numTags; i++) {
  41046. var tag = '';
  41047. var offset = start + p.parseUShort();
  41048. var length = p.parseUShort();
  41049. for (var j = offset; j < offset + length; ++j) {
  41050. tag += String.fromCharCode(data.getInt8(j));
  41051. }
  41052. tags.push(tag);
  41053. }
  41054. return tags;
  41055. }
  41056. var ltag = { make: makeLtagTable, parse: parseLtagTable };
  41057. // The `maxp` table establishes the memory requirements for the font.
  41058. // Parse the maximum profile `maxp` table.
  41059. function parseMaxpTable(data, start) {
  41060. var maxp = {};
  41061. var p = new parse.Parser(data, start);
  41062. maxp.version = p.parseVersion();
  41063. maxp.numGlyphs = p.parseUShort();
  41064. if (maxp.version === 1.0) {
  41065. maxp.maxPoints = p.parseUShort();
  41066. maxp.maxContours = p.parseUShort();
  41067. maxp.maxCompositePoints = p.parseUShort();
  41068. maxp.maxCompositeContours = p.parseUShort();
  41069. maxp.maxZones = p.parseUShort();
  41070. maxp.maxTwilightPoints = p.parseUShort();
  41071. maxp.maxStorage = p.parseUShort();
  41072. maxp.maxFunctionDefs = p.parseUShort();
  41073. maxp.maxInstructionDefs = p.parseUShort();
  41074. maxp.maxStackElements = p.parseUShort();
  41075. maxp.maxSizeOfInstructions = p.parseUShort();
  41076. maxp.maxComponentElements = p.parseUShort();
  41077. maxp.maxComponentDepth = p.parseUShort();
  41078. }
  41079. return maxp;
  41080. }
  41081. function makeMaxpTable(numGlyphs) {
  41082. return new table.Table('maxp', [
  41083. { name: 'version', type: 'FIXED', value: 0x00005000 },
  41084. { name: 'numGlyphs', type: 'USHORT', value: numGlyphs }
  41085. ]);
  41086. }
  41087. var maxp = { parse: parseMaxpTable, make: makeMaxpTable };
  41088. // The `name` naming table.
  41089. // NameIDs for the name table.
  41090. var nameTableNames = [
  41091. 'copyright', // 0
  41092. 'fontFamily', // 1
  41093. 'fontSubfamily', // 2
  41094. 'uniqueID', // 3
  41095. 'fullName', // 4
  41096. 'version', // 5
  41097. 'postScriptName', // 6
  41098. 'trademark', // 7
  41099. 'manufacturer', // 8
  41100. 'designer', // 9
  41101. 'description', // 10
  41102. 'manufacturerURL', // 11
  41103. 'designerURL', // 12
  41104. 'license', // 13
  41105. 'licenseURL', // 14
  41106. 'reserved', // 15
  41107. 'preferredFamily', // 16
  41108. 'preferredSubfamily', // 17
  41109. 'compatibleFullName', // 18
  41110. 'sampleText', // 19
  41111. 'postScriptFindFontName', // 20
  41112. 'wwsFamily', // 21
  41113. 'wwsSubfamily' // 22
  41114. ];
  41115. var macLanguages = {
  41116. 0: 'en',
  41117. 1: 'fr',
  41118. 2: 'de',
  41119. 3: 'it',
  41120. 4: 'nl',
  41121. 5: 'sv',
  41122. 6: 'es',
  41123. 7: 'da',
  41124. 8: 'pt',
  41125. 9: 'no',
  41126. 10: 'he',
  41127. 11: 'ja',
  41128. 12: 'ar',
  41129. 13: 'fi',
  41130. 14: 'el',
  41131. 15: 'is',
  41132. 16: 'mt',
  41133. 17: 'tr',
  41134. 18: 'hr',
  41135. 19: 'zh-Hant',
  41136. 20: 'ur',
  41137. 21: 'hi',
  41138. 22: 'th',
  41139. 23: 'ko',
  41140. 24: 'lt',
  41141. 25: 'pl',
  41142. 26: 'hu',
  41143. 27: 'es',
  41144. 28: 'lv',
  41145. 29: 'se',
  41146. 30: 'fo',
  41147. 31: 'fa',
  41148. 32: 'ru',
  41149. 33: 'zh',
  41150. 34: 'nl-BE',
  41151. 35: 'ga',
  41152. 36: 'sq',
  41153. 37: 'ro',
  41154. 38: 'cz',
  41155. 39: 'sk',
  41156. 40: 'si',
  41157. 41: 'yi',
  41158. 42: 'sr',
  41159. 43: 'mk',
  41160. 44: 'bg',
  41161. 45: 'uk',
  41162. 46: 'be',
  41163. 47: 'uz',
  41164. 48: 'kk',
  41165. 49: 'az-Cyrl',
  41166. 50: 'az-Arab',
  41167. 51: 'hy',
  41168. 52: 'ka',
  41169. 53: 'mo',
  41170. 54: 'ky',
  41171. 55: 'tg',
  41172. 56: 'tk',
  41173. 57: 'mn-CN',
  41174. 58: 'mn',
  41175. 59: 'ps',
  41176. 60: 'ks',
  41177. 61: 'ku',
  41178. 62: 'sd',
  41179. 63: 'bo',
  41180. 64: 'ne',
  41181. 65: 'sa',
  41182. 66: 'mr',
  41183. 67: 'bn',
  41184. 68: 'as',
  41185. 69: 'gu',
  41186. 70: 'pa',
  41187. 71: 'or',
  41188. 72: 'ml',
  41189. 73: 'kn',
  41190. 74: 'ta',
  41191. 75: 'te',
  41192. 76: 'si',
  41193. 77: 'my',
  41194. 78: 'km',
  41195. 79: 'lo',
  41196. 80: 'vi',
  41197. 81: 'id',
  41198. 82: 'tl',
  41199. 83: 'ms',
  41200. 84: 'ms-Arab',
  41201. 85: 'am',
  41202. 86: 'ti',
  41203. 87: 'om',
  41204. 88: 'so',
  41205. 89: 'sw',
  41206. 90: 'rw',
  41207. 91: 'rn',
  41208. 92: 'ny',
  41209. 93: 'mg',
  41210. 94: 'eo',
  41211. 128: 'cy',
  41212. 129: 'eu',
  41213. 130: 'ca',
  41214. 131: 'la',
  41215. 132: 'qu',
  41216. 133: 'gn',
  41217. 134: 'ay',
  41218. 135: 'tt',
  41219. 136: 'ug',
  41220. 137: 'dz',
  41221. 138: 'jv',
  41222. 139: 'su',
  41223. 140: 'gl',
  41224. 141: 'af',
  41225. 142: 'br',
  41226. 143: 'iu',
  41227. 144: 'gd',
  41228. 145: 'gv',
  41229. 146: 'ga',
  41230. 147: 'to',
  41231. 148: 'el-polyton',
  41232. 149: 'kl',
  41233. 150: 'az',
  41234. 151: 'nn'
  41235. };
  41236. // MacOS language ID → MacOS script ID
  41237. //
  41238. // Note that the script ID is not sufficient to determine what encoding
  41239. // to use in TrueType files. For some languages, MacOS used a modification
  41240. // of a mainstream script. For example, an Icelandic name would be stored
  41241. // with smRoman in the TrueType naming table, but the actual encoding
  41242. // is a special Icelandic version of the normal Macintosh Roman encoding.
  41243. // As another example, Inuktitut uses an 8-bit encoding for Canadian Aboriginal
  41244. // Syllables but MacOS had run out of available script codes, so this was
  41245. // done as a (pretty radical) "modification" of Ethiopic.
  41246. //
  41247. // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt
  41248. var macLanguageToScript = {
  41249. 0: 0, // langEnglish → smRoman
  41250. 1: 0, // langFrench → smRoman
  41251. 2: 0, // langGerman → smRoman
  41252. 3: 0, // langItalian → smRoman
  41253. 4: 0, // langDutch → smRoman
  41254. 5: 0, // langSwedish → smRoman
  41255. 6: 0, // langSpanish → smRoman
  41256. 7: 0, // langDanish → smRoman
  41257. 8: 0, // langPortuguese → smRoman
  41258. 9: 0, // langNorwegian → smRoman
  41259. 10: 5, // langHebrew → smHebrew
  41260. 11: 1, // langJapanese → smJapanese
  41261. 12: 4, // langArabic → smArabic
  41262. 13: 0, // langFinnish → smRoman
  41263. 14: 6, // langGreek → smGreek
  41264. 15: 0, // langIcelandic → smRoman (modified)
  41265. 16: 0, // langMaltese → smRoman
  41266. 17: 0, // langTurkish → smRoman (modified)
  41267. 18: 0, // langCroatian → smRoman (modified)
  41268. 19: 2, // langTradChinese → smTradChinese
  41269. 20: 4, // langUrdu → smArabic
  41270. 21: 9, // langHindi → smDevanagari
  41271. 22: 21, // langThai → smThai
  41272. 23: 3, // langKorean → smKorean
  41273. 24: 29, // langLithuanian → smCentralEuroRoman
  41274. 25: 29, // langPolish → smCentralEuroRoman
  41275. 26: 29, // langHungarian → smCentralEuroRoman
  41276. 27: 29, // langEstonian → smCentralEuroRoman
  41277. 28: 29, // langLatvian → smCentralEuroRoman
  41278. 29: 0, // langSami → smRoman
  41279. 30: 0, // langFaroese → smRoman (modified)
  41280. 31: 4, // langFarsi → smArabic (modified)
  41281. 32: 7, // langRussian → smCyrillic
  41282. 33: 25, // langSimpChinese → smSimpChinese
  41283. 34: 0, // langFlemish → smRoman
  41284. 35: 0, // langIrishGaelic → smRoman (modified)
  41285. 36: 0, // langAlbanian → smRoman
  41286. 37: 0, // langRomanian → smRoman (modified)
  41287. 38: 29, // langCzech → smCentralEuroRoman
  41288. 39: 29, // langSlovak → smCentralEuroRoman
  41289. 40: 0, // langSlovenian → smRoman (modified)
  41290. 41: 5, // langYiddish → smHebrew
  41291. 42: 7, // langSerbian → smCyrillic
  41292. 43: 7, // langMacedonian → smCyrillic
  41293. 44: 7, // langBulgarian → smCyrillic
  41294. 45: 7, // langUkrainian → smCyrillic (modified)
  41295. 46: 7, // langByelorussian → smCyrillic
  41296. 47: 7, // langUzbek → smCyrillic
  41297. 48: 7, // langKazakh → smCyrillic
  41298. 49: 7, // langAzerbaijani → smCyrillic
  41299. 50: 4, // langAzerbaijanAr → smArabic
  41300. 51: 24, // langArmenian → smArmenian
  41301. 52: 23, // langGeorgian → smGeorgian
  41302. 53: 7, // langMoldavian → smCyrillic
  41303. 54: 7, // langKirghiz → smCyrillic
  41304. 55: 7, // langTajiki → smCyrillic
  41305. 56: 7, // langTurkmen → smCyrillic
  41306. 57: 27, // langMongolian → smMongolian
  41307. 58: 7, // langMongolianCyr → smCyrillic
  41308. 59: 4, // langPashto → smArabic
  41309. 60: 4, // langKurdish → smArabic
  41310. 61: 4, // langKashmiri → smArabic
  41311. 62: 4, // langSindhi → smArabic
  41312. 63: 26, // langTibetan → smTibetan
  41313. 64: 9, // langNepali → smDevanagari
  41314. 65: 9, // langSanskrit → smDevanagari
  41315. 66: 9, // langMarathi → smDevanagari
  41316. 67: 13, // langBengali → smBengali
  41317. 68: 13, // langAssamese → smBengali
  41318. 69: 11, // langGujarati → smGujarati
  41319. 70: 10, // langPunjabi → smGurmukhi
  41320. 71: 12, // langOriya → smOriya
  41321. 72: 17, // langMalayalam → smMalayalam
  41322. 73: 16, // langKannada → smKannada
  41323. 74: 14, // langTamil → smTamil
  41324. 75: 15, // langTelugu → smTelugu
  41325. 76: 18, // langSinhalese → smSinhalese
  41326. 77: 19, // langBurmese → smBurmese
  41327. 78: 20, // langKhmer → smKhmer
  41328. 79: 22, // langLao → smLao
  41329. 80: 30, // langVietnamese → smVietnamese
  41330. 81: 0, // langIndonesian → smRoman
  41331. 82: 0, // langTagalog → smRoman
  41332. 83: 0, // langMalayRoman → smRoman
  41333. 84: 4, // langMalayArabic → smArabic
  41334. 85: 28, // langAmharic → smEthiopic
  41335. 86: 28, // langTigrinya → smEthiopic
  41336. 87: 28, // langOromo → smEthiopic
  41337. 88: 0, // langSomali → smRoman
  41338. 89: 0, // langSwahili → smRoman
  41339. 90: 0, // langKinyarwanda → smRoman
  41340. 91: 0, // langRundi → smRoman
  41341. 92: 0, // langNyanja → smRoman
  41342. 93: 0, // langMalagasy → smRoman
  41343. 94: 0, // langEsperanto → smRoman
  41344. 128: 0, // langWelsh → smRoman (modified)
  41345. 129: 0, // langBasque → smRoman
  41346. 130: 0, // langCatalan → smRoman
  41347. 131: 0, // langLatin → smRoman
  41348. 132: 0, // langQuechua → smRoman
  41349. 133: 0, // langGuarani → smRoman
  41350. 134: 0, // langAymara → smRoman
  41351. 135: 7, // langTatar → smCyrillic
  41352. 136: 4, // langUighur → smArabic
  41353. 137: 26, // langDzongkha → smTibetan
  41354. 138: 0, // langJavaneseRom → smRoman
  41355. 139: 0, // langSundaneseRom → smRoman
  41356. 140: 0, // langGalician → smRoman
  41357. 141: 0, // langAfrikaans → smRoman
  41358. 142: 0, // langBreton → smRoman (modified)
  41359. 143: 28, // langInuktitut → smEthiopic (modified)
  41360. 144: 0, // langScottishGaelic → smRoman (modified)
  41361. 145: 0, // langManxGaelic → smRoman (modified)
  41362. 146: 0, // langIrishGaelicScript → smRoman (modified)
  41363. 147: 0, // langTongan → smRoman
  41364. 148: 6, // langGreekAncient → smRoman
  41365. 149: 0, // langGreenlandic → smRoman
  41366. 150: 0, // langAzerbaijanRoman → smRoman
  41367. 151: 0 // langNynorsk → smRoman
  41368. };
  41369. // While Microsoft indicates a region/country for all its language
  41370. // IDs, we omit the region code if it's equal to the "most likely
  41371. // region subtag" according to Unicode CLDR. For scripts, we omit
  41372. // the subtag if it is equal to the Suppress-Script entry in the
  41373. // IANA language subtag registry for IETF BCP 47.
  41374. //
  41375. // For example, Microsoft states that its language code 0x041A is
  41376. // Croatian in Croatia. We transform this to the BCP 47 language code 'hr'
  41377. // and not 'hr-HR' because Croatia is the default country for Croatian,
  41378. // according to Unicode CLDR. As another example, Microsoft states
  41379. // that 0x101A is Croatian (Latin) in Bosnia-Herzegovina. We transform
  41380. // this to 'hr-BA' and not 'hr-Latn-BA' because Latin is the default script
  41381. // for the Croatian language, according to IANA.
  41382. //
  41383. // http://www.unicode.org/cldr/charts/latest/supplemental/likely_subtags.html
  41384. // http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
  41385. var windowsLanguages = {
  41386. 0x0436: 'af',
  41387. 0x041c: 'sq',
  41388. 0x0484: 'gsw',
  41389. 0x045e: 'am',
  41390. 0x1401: 'ar-DZ',
  41391. 0x3c01: 'ar-BH',
  41392. 0x0c01: 'ar',
  41393. 0x0801: 'ar-IQ',
  41394. 0x2c01: 'ar-JO',
  41395. 0x3401: 'ar-KW',
  41396. 0x3001: 'ar-LB',
  41397. 0x1001: 'ar-LY',
  41398. 0x1801: 'ary',
  41399. 0x2001: 'ar-OM',
  41400. 0x4001: 'ar-QA',
  41401. 0x0401: 'ar-SA',
  41402. 0x2801: 'ar-SY',
  41403. 0x1c01: 'aeb',
  41404. 0x3801: 'ar-AE',
  41405. 0x2401: 'ar-YE',
  41406. 0x042b: 'hy',
  41407. 0x044d: 'as',
  41408. 0x082c: 'az-Cyrl',
  41409. 0x042c: 'az',
  41410. 0x046d: 'ba',
  41411. 0x042d: 'eu',
  41412. 0x0423: 'be',
  41413. 0x0845: 'bn',
  41414. 0x0445: 'bn-IN',
  41415. 0x201a: 'bs-Cyrl',
  41416. 0x141a: 'bs',
  41417. 0x047e: 'br',
  41418. 0x0402: 'bg',
  41419. 0x0403: 'ca',
  41420. 0x0c04: 'zh-HK',
  41421. 0x1404: 'zh-MO',
  41422. 0x0804: 'zh',
  41423. 0x1004: 'zh-SG',
  41424. 0x0404: 'zh-TW',
  41425. 0x0483: 'co',
  41426. 0x041a: 'hr',
  41427. 0x101a: 'hr-BA',
  41428. 0x0405: 'cs',
  41429. 0x0406: 'da',
  41430. 0x048c: 'prs',
  41431. 0x0465: 'dv',
  41432. 0x0813: 'nl-BE',
  41433. 0x0413: 'nl',
  41434. 0x0c09: 'en-AU',
  41435. 0x2809: 'en-BZ',
  41436. 0x1009: 'en-CA',
  41437. 0x2409: 'en-029',
  41438. 0x4009: 'en-IN',
  41439. 0x1809: 'en-IE',
  41440. 0x2009: 'en-JM',
  41441. 0x4409: 'en-MY',
  41442. 0x1409: 'en-NZ',
  41443. 0x3409: 'en-PH',
  41444. 0x4809: 'en-SG',
  41445. 0x1c09: 'en-ZA',
  41446. 0x2c09: 'en-TT',
  41447. 0x0809: 'en-GB',
  41448. 0x0409: 'en',
  41449. 0x3009: 'en-ZW',
  41450. 0x0425: 'et',
  41451. 0x0438: 'fo',
  41452. 0x0464: 'fil',
  41453. 0x040b: 'fi',
  41454. 0x080c: 'fr-BE',
  41455. 0x0c0c: 'fr-CA',
  41456. 0x040c: 'fr',
  41457. 0x140c: 'fr-LU',
  41458. 0x180c: 'fr-MC',
  41459. 0x100c: 'fr-CH',
  41460. 0x0462: 'fy',
  41461. 0x0456: 'gl',
  41462. 0x0437: 'ka',
  41463. 0x0c07: 'de-AT',
  41464. 0x0407: 'de',
  41465. 0x1407: 'de-LI',
  41466. 0x1007: 'de-LU',
  41467. 0x0807: 'de-CH',
  41468. 0x0408: 'el',
  41469. 0x046f: 'kl',
  41470. 0x0447: 'gu',
  41471. 0x0468: 'ha',
  41472. 0x040d: 'he',
  41473. 0x0439: 'hi',
  41474. 0x040e: 'hu',
  41475. 0x040f: 'is',
  41476. 0x0470: 'ig',
  41477. 0x0421: 'id',
  41478. 0x045d: 'iu',
  41479. 0x085d: 'iu-Latn',
  41480. 0x083c: 'ga',
  41481. 0x0434: 'xh',
  41482. 0x0435: 'zu',
  41483. 0x0410: 'it',
  41484. 0x0810: 'it-CH',
  41485. 0x0411: 'ja',
  41486. 0x044b: 'kn',
  41487. 0x043f: 'kk',
  41488. 0x0453: 'km',
  41489. 0x0486: 'quc',
  41490. 0x0487: 'rw',
  41491. 0x0441: 'sw',
  41492. 0x0457: 'kok',
  41493. 0x0412: 'ko',
  41494. 0x0440: 'ky',
  41495. 0x0454: 'lo',
  41496. 0x0426: 'lv',
  41497. 0x0427: 'lt',
  41498. 0x082e: 'dsb',
  41499. 0x046e: 'lb',
  41500. 0x042f: 'mk',
  41501. 0x083e: 'ms-BN',
  41502. 0x043e: 'ms',
  41503. 0x044c: 'ml',
  41504. 0x043a: 'mt',
  41505. 0x0481: 'mi',
  41506. 0x047a: 'arn',
  41507. 0x044e: 'mr',
  41508. 0x047c: 'moh',
  41509. 0x0450: 'mn',
  41510. 0x0850: 'mn-CN',
  41511. 0x0461: 'ne',
  41512. 0x0414: 'nb',
  41513. 0x0814: 'nn',
  41514. 0x0482: 'oc',
  41515. 0x0448: 'or',
  41516. 0x0463: 'ps',
  41517. 0x0415: 'pl',
  41518. 0x0416: 'pt',
  41519. 0x0816: 'pt-PT',
  41520. 0x0446: 'pa',
  41521. 0x046b: 'qu-BO',
  41522. 0x086b: 'qu-EC',
  41523. 0x0c6b: 'qu',
  41524. 0x0418: 'ro',
  41525. 0x0417: 'rm',
  41526. 0x0419: 'ru',
  41527. 0x243b: 'smn',
  41528. 0x103b: 'smj-NO',
  41529. 0x143b: 'smj',
  41530. 0x0c3b: 'se-FI',
  41531. 0x043b: 'se',
  41532. 0x083b: 'se-SE',
  41533. 0x203b: 'sms',
  41534. 0x183b: 'sma-NO',
  41535. 0x1c3b: 'sms',
  41536. 0x044f: 'sa',
  41537. 0x1c1a: 'sr-Cyrl-BA',
  41538. 0x0c1a: 'sr',
  41539. 0x181a: 'sr-Latn-BA',
  41540. 0x081a: 'sr-Latn',
  41541. 0x046c: 'nso',
  41542. 0x0432: 'tn',
  41543. 0x045b: 'si',
  41544. 0x041b: 'sk',
  41545. 0x0424: 'sl',
  41546. 0x2c0a: 'es-AR',
  41547. 0x400a: 'es-BO',
  41548. 0x340a: 'es-CL',
  41549. 0x240a: 'es-CO',
  41550. 0x140a: 'es-CR',
  41551. 0x1c0a: 'es-DO',
  41552. 0x300a: 'es-EC',
  41553. 0x440a: 'es-SV',
  41554. 0x100a: 'es-GT',
  41555. 0x480a: 'es-HN',
  41556. 0x080a: 'es-MX',
  41557. 0x4c0a: 'es-NI',
  41558. 0x180a: 'es-PA',
  41559. 0x3c0a: 'es-PY',
  41560. 0x280a: 'es-PE',
  41561. 0x500a: 'es-PR',
  41562. // Microsoft has defined two different language codes for
  41563. // “Spanish with modern sorting” and “Spanish with traditional
  41564. // sorting”. This makes sense for collation APIs, and it would be
  41565. // possible to express this in BCP 47 language tags via Unicode
  41566. // extensions (eg., es-u-co-trad is Spanish with traditional
  41567. // sorting). However, for storing names in fonts, the distinction
  41568. // does not make sense, so we give “es” in both cases.
  41569. 0x0c0a: 'es',
  41570. 0x040a: 'es',
  41571. 0x540a: 'es-US',
  41572. 0x380a: 'es-UY',
  41573. 0x200a: 'es-VE',
  41574. 0x081d: 'sv-FI',
  41575. 0x041d: 'sv',
  41576. 0x045a: 'syr',
  41577. 0x0428: 'tg',
  41578. 0x085f: 'tzm',
  41579. 0x0449: 'ta',
  41580. 0x0444: 'tt',
  41581. 0x044a: 'te',
  41582. 0x041e: 'th',
  41583. 0x0451: 'bo',
  41584. 0x041f: 'tr',
  41585. 0x0442: 'tk',
  41586. 0x0480: 'ug',
  41587. 0x0422: 'uk',
  41588. 0x042e: 'hsb',
  41589. 0x0420: 'ur',
  41590. 0x0843: 'uz-Cyrl',
  41591. 0x0443: 'uz',
  41592. 0x042a: 'vi',
  41593. 0x0452: 'cy',
  41594. 0x0488: 'wo',
  41595. 0x0485: 'sah',
  41596. 0x0478: 'ii',
  41597. 0x046a: 'yo'
  41598. };
  41599. // Returns a IETF BCP 47 language code, for example 'zh-Hant'
  41600. // for 'Chinese in the traditional script'.
  41601. function getLanguageCode(platformID, languageID, ltag) {
  41602. switch (platformID) {
  41603. case 0: // Unicode
  41604. if (languageID === 0xffff) {
  41605. return 'und';
  41606. } else if (ltag) {
  41607. return ltag[languageID];
  41608. }
  41609. break;
  41610. case 1: // Macintosh
  41611. return macLanguages[languageID];
  41612. case 3: // Windows
  41613. return windowsLanguages[languageID];
  41614. }
  41615. return undefined;
  41616. }
  41617. var utf16 = 'utf-16';
  41618. // MacOS script ID → encoding. This table stores the default case,
  41619. // which can be overridden by macLanguageEncodings.
  41620. var macScriptEncodings = {
  41621. 0: 'macintosh', // smRoman
  41622. 1: 'x-mac-japanese', // smJapanese
  41623. 2: 'x-mac-chinesetrad', // smTradChinese
  41624. 3: 'x-mac-korean', // smKorean
  41625. 6: 'x-mac-greek', // smGreek
  41626. 7: 'x-mac-cyrillic', // smCyrillic
  41627. 9: 'x-mac-devanagai', // smDevanagari
  41628. 10: 'x-mac-gurmukhi', // smGurmukhi
  41629. 11: 'x-mac-gujarati', // smGujarati
  41630. 12: 'x-mac-oriya', // smOriya
  41631. 13: 'x-mac-bengali', // smBengali
  41632. 14: 'x-mac-tamil', // smTamil
  41633. 15: 'x-mac-telugu', // smTelugu
  41634. 16: 'x-mac-kannada', // smKannada
  41635. 17: 'x-mac-malayalam', // smMalayalam
  41636. 18: 'x-mac-sinhalese', // smSinhalese
  41637. 19: 'x-mac-burmese', // smBurmese
  41638. 20: 'x-mac-khmer', // smKhmer
  41639. 21: 'x-mac-thai', // smThai
  41640. 22: 'x-mac-lao', // smLao
  41641. 23: 'x-mac-georgian', // smGeorgian
  41642. 24: 'x-mac-armenian', // smArmenian
  41643. 25: 'x-mac-chinesesimp', // smSimpChinese
  41644. 26: 'x-mac-tibetan', // smTibetan
  41645. 27: 'x-mac-mongolian', // smMongolian
  41646. 28: 'x-mac-ethiopic', // smEthiopic
  41647. 29: 'x-mac-ce', // smCentralEuroRoman
  41648. 30: 'x-mac-vietnamese', // smVietnamese
  41649. 31: 'x-mac-extarabic' // smExtArabic
  41650. };
  41651. // MacOS language ID → encoding. This table stores the exceptional
  41652. // cases, which override macScriptEncodings. For writing MacOS naming
  41653. // tables, we need to emit a MacOS script ID. Therefore, we cannot
  41654. // merge macScriptEncodings into macLanguageEncodings.
  41655. //
  41656. // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt
  41657. var macLanguageEncodings = {
  41658. 15: 'x-mac-icelandic', // langIcelandic
  41659. 17: 'x-mac-turkish', // langTurkish
  41660. 18: 'x-mac-croatian', // langCroatian
  41661. 24: 'x-mac-ce', // langLithuanian
  41662. 25: 'x-mac-ce', // langPolish
  41663. 26: 'x-mac-ce', // langHungarian
  41664. 27: 'x-mac-ce', // langEstonian
  41665. 28: 'x-mac-ce', // langLatvian
  41666. 30: 'x-mac-icelandic', // langFaroese
  41667. 37: 'x-mac-romanian', // langRomanian
  41668. 38: 'x-mac-ce', // langCzech
  41669. 39: 'x-mac-ce', // langSlovak
  41670. 40: 'x-mac-ce', // langSlovenian
  41671. 143: 'x-mac-inuit', // langInuktitut
  41672. 146: 'x-mac-gaelic' // langIrishGaelicScript
  41673. };
  41674. function getEncoding(platformID, encodingID, languageID) {
  41675. switch (platformID) {
  41676. case 0: // Unicode
  41677. return utf16;
  41678. case 1: // Apple Macintosh
  41679. return (
  41680. macLanguageEncodings[languageID] || macScriptEncodings[encodingID]
  41681. );
  41682. case 3: // Microsoft Windows
  41683. if (encodingID === 1 || encodingID === 10) {
  41684. return utf16;
  41685. }
  41686. break;
  41687. }
  41688. return undefined;
  41689. }
  41690. // Parse the naming `name` table.
  41691. // FIXME: Format 1 additional fields are not supported yet.
  41692. // ltag is the content of the `ltag' table, such as ['en', 'zh-Hans', 'de-CH-1904'].
  41693. function parseNameTable(data, start, ltag) {
  41694. var name = {};
  41695. var p = new parse.Parser(data, start);
  41696. var format = p.parseUShort();
  41697. var count = p.parseUShort();
  41698. var stringOffset = p.offset + p.parseUShort();
  41699. for (var i = 0; i < count; i++) {
  41700. var platformID = p.parseUShort();
  41701. var encodingID = p.parseUShort();
  41702. var languageID = p.parseUShort();
  41703. var nameID = p.parseUShort();
  41704. var property = nameTableNames[nameID] || nameID;
  41705. var byteLength = p.parseUShort();
  41706. var offset = p.parseUShort();
  41707. var language = getLanguageCode(platformID, languageID, ltag);
  41708. var encoding = getEncoding(platformID, encodingID, languageID);
  41709. if (encoding !== undefined && language !== undefined) {
  41710. var text = void 0;
  41711. if (encoding === utf16) {
  41712. text = decode.UTF16(data, stringOffset + offset, byteLength);
  41713. } else {
  41714. text = decode.MACSTRING(
  41715. data,
  41716. stringOffset + offset,
  41717. byteLength,
  41718. encoding
  41719. );
  41720. }
  41721. if (text) {
  41722. var translations = name[property];
  41723. if (translations === undefined) {
  41724. translations = name[property] = {};
  41725. }
  41726. translations[language] = text;
  41727. }
  41728. }
  41729. }
  41730. var langTagCount = 0;
  41731. if (format === 1) {
  41732. // FIXME: Also handle Microsoft's 'name' table 1.
  41733. langTagCount = p.parseUShort();
  41734. }
  41735. return name;
  41736. }
  41737. // {23: 'foo'} → {'foo': 23}
  41738. // ['bar', 'baz'] → {'bar': 0, 'baz': 1}
  41739. function reverseDict(dict) {
  41740. var result = {};
  41741. for (var key in dict) {
  41742. result[dict[key]] = parseInt(key);
  41743. }
  41744. return result;
  41745. }
  41746. function makeNameRecord(
  41747. platformID,
  41748. encodingID,
  41749. languageID,
  41750. nameID,
  41751. length,
  41752. offset
  41753. ) {
  41754. return new table.Record('NameRecord', [
  41755. { name: 'platformID', type: 'USHORT', value: platformID },
  41756. { name: 'encodingID', type: 'USHORT', value: encodingID },
  41757. { name: 'languageID', type: 'USHORT', value: languageID },
  41758. { name: 'nameID', type: 'USHORT', value: nameID },
  41759. { name: 'length', type: 'USHORT', value: length },
  41760. { name: 'offset', type: 'USHORT', value: offset }
  41761. ]);
  41762. }
  41763. // Finds the position of needle in haystack, or -1 if not there.
  41764. // Like String.indexOf(), but for arrays.
  41765. function findSubArray(needle, haystack) {
  41766. var needleLength = needle.length;
  41767. var limit = haystack.length - needleLength + 1;
  41768. loop: for (var pos = 0; pos < limit; pos++) {
  41769. for (; pos < limit; pos++) {
  41770. for (var k = 0; k < needleLength; k++) {
  41771. if (haystack[pos + k] !== needle[k]) {
  41772. continue loop;
  41773. }
  41774. }
  41775. return pos;
  41776. }
  41777. }
  41778. return -1;
  41779. }
  41780. function addStringToPool(s, pool) {
  41781. var offset = findSubArray(s, pool);
  41782. if (offset < 0) {
  41783. offset = pool.length;
  41784. var i = 0;
  41785. var len = s.length;
  41786. for (; i < len; ++i) {
  41787. pool.push(s[i]);
  41788. }
  41789. }
  41790. return offset;
  41791. }
  41792. function makeNameTable(names, ltag) {
  41793. var nameID;
  41794. var nameIDs = [];
  41795. var namesWithNumericKeys = {};
  41796. var nameTableIds = reverseDict(nameTableNames);
  41797. for (var key in names) {
  41798. var id = nameTableIds[key];
  41799. if (id === undefined) {
  41800. id = key;
  41801. }
  41802. nameID = parseInt(id);
  41803. if (isNaN(nameID)) {
  41804. throw new Error(
  41805. 'Name table entry "' +
  41806. key +
  41807. '" does not exist, see nameTableNames for complete list.'
  41808. );
  41809. }
  41810. namesWithNumericKeys[nameID] = names[key];
  41811. nameIDs.push(nameID);
  41812. }
  41813. var macLanguageIds = reverseDict(macLanguages);
  41814. var windowsLanguageIds = reverseDict(windowsLanguages);
  41815. var nameRecords = [];
  41816. var stringPool = [];
  41817. for (var i = 0; i < nameIDs.length; i++) {
  41818. nameID = nameIDs[i];
  41819. var translations = namesWithNumericKeys[nameID];
  41820. for (var lang in translations) {
  41821. var text = translations[lang];
  41822. // For MacOS, we try to emit the name in the form that was introduced
  41823. // in the initial version of the TrueType spec (in the late 1980s).
  41824. // However, this can fail for various reasons: the requested BCP 47
  41825. // language code might not have an old-style Mac equivalent;
  41826. // we might not have a codec for the needed character encoding;
  41827. // or the name might contain characters that cannot be expressed
  41828. // in the old-style Macintosh encoding. In case of failure, we emit
  41829. // the name in a more modern fashion (Unicode encoding with BCP 47
  41830. // language tags) that is recognized by MacOS 10.5, released in 2009.
  41831. // If fonts were only read by operating systems, we could simply
  41832. // emit all names in the modern form; this would be much easier.
  41833. // However, there are many applications and libraries that read
  41834. // 'name' tables directly, and these will usually only recognize
  41835. // the ancient form (silently skipping the unrecognized names).
  41836. var macPlatform = 1; // Macintosh
  41837. var macLanguage = macLanguageIds[lang];
  41838. var macScript = macLanguageToScript[macLanguage];
  41839. var macEncoding = getEncoding(macPlatform, macScript, macLanguage);
  41840. var macName = encode.MACSTRING(text, macEncoding);
  41841. if (macName === undefined) {
  41842. macPlatform = 0; // Unicode
  41843. macLanguage = ltag.indexOf(lang);
  41844. if (macLanguage < 0) {
  41845. macLanguage = ltag.length;
  41846. ltag.push(lang);
  41847. }
  41848. macScript = 4; // Unicode 2.0 and later
  41849. macName = encode.UTF16(text);
  41850. }
  41851. var macNameOffset = addStringToPool(macName, stringPool);
  41852. nameRecords.push(
  41853. makeNameRecord(
  41854. macPlatform,
  41855. macScript,
  41856. macLanguage,
  41857. nameID,
  41858. macName.length,
  41859. macNameOffset
  41860. )
  41861. );
  41862. var winLanguage = windowsLanguageIds[lang];
  41863. if (winLanguage !== undefined) {
  41864. var winName = encode.UTF16(text);
  41865. var winNameOffset = addStringToPool(winName, stringPool);
  41866. nameRecords.push(
  41867. makeNameRecord(
  41868. 3,
  41869. 1,
  41870. winLanguage,
  41871. nameID,
  41872. winName.length,
  41873. winNameOffset
  41874. )
  41875. );
  41876. }
  41877. }
  41878. }
  41879. nameRecords.sort(function(a, b) {
  41880. return (
  41881. a.platformID - b.platformID ||
  41882. a.encodingID - b.encodingID ||
  41883. a.languageID - b.languageID ||
  41884. a.nameID - b.nameID
  41885. );
  41886. });
  41887. var t = new table.Table('name', [
  41888. { name: 'format', type: 'USHORT', value: 0 },
  41889. { name: 'count', type: 'USHORT', value: nameRecords.length },
  41890. {
  41891. name: 'stringOffset',
  41892. type: 'USHORT',
  41893. value: 6 + nameRecords.length * 12
  41894. }
  41895. ]);
  41896. for (var r = 0; r < nameRecords.length; r++) {
  41897. t.fields.push({
  41898. name: 'record_' + r,
  41899. type: 'RECORD',
  41900. value: nameRecords[r]
  41901. });
  41902. }
  41903. t.fields.push({ name: 'strings', type: 'LITERAL', value: stringPool });
  41904. return t;
  41905. }
  41906. var _name = { parse: parseNameTable, make: makeNameTable };
  41907. // The `OS/2` table contains metrics required in OpenType fonts.
  41908. var unicodeRanges = [
  41909. { begin: 0x0000, end: 0x007f }, // Basic Latin
  41910. { begin: 0x0080, end: 0x00ff }, // Latin-1 Supplement
  41911. { begin: 0x0100, end: 0x017f }, // Latin Extended-A
  41912. { begin: 0x0180, end: 0x024f }, // Latin Extended-B
  41913. { begin: 0x0250, end: 0x02af }, // IPA Extensions
  41914. { begin: 0x02b0, end: 0x02ff }, // Spacing Modifier Letters
  41915. { begin: 0x0300, end: 0x036f }, // Combining Diacritical Marks
  41916. { begin: 0x0370, end: 0x03ff }, // Greek and Coptic
  41917. { begin: 0x2c80, end: 0x2cff }, // Coptic
  41918. { begin: 0x0400, end: 0x04ff }, // Cyrillic
  41919. { begin: 0x0530, end: 0x058f }, // Armenian
  41920. { begin: 0x0590, end: 0x05ff }, // Hebrew
  41921. { begin: 0xa500, end: 0xa63f }, // Vai
  41922. { begin: 0x0600, end: 0x06ff }, // Arabic
  41923. { begin: 0x07c0, end: 0x07ff }, // NKo
  41924. { begin: 0x0900, end: 0x097f }, // Devanagari
  41925. { begin: 0x0980, end: 0x09ff }, // Bengali
  41926. { begin: 0x0a00, end: 0x0a7f }, // Gurmukhi
  41927. { begin: 0x0a80, end: 0x0aff }, // Gujarati
  41928. { begin: 0x0b00, end: 0x0b7f }, // Oriya
  41929. { begin: 0x0b80, end: 0x0bff }, // Tamil
  41930. { begin: 0x0c00, end: 0x0c7f }, // Telugu
  41931. { begin: 0x0c80, end: 0x0cff }, // Kannada
  41932. { begin: 0x0d00, end: 0x0d7f }, // Malayalam
  41933. { begin: 0x0e00, end: 0x0e7f }, // Thai
  41934. { begin: 0x0e80, end: 0x0eff }, // Lao
  41935. { begin: 0x10a0, end: 0x10ff }, // Georgian
  41936. { begin: 0x1b00, end: 0x1b7f }, // Balinese
  41937. { begin: 0x1100, end: 0x11ff }, // Hangul Jamo
  41938. { begin: 0x1e00, end: 0x1eff }, // Latin Extended Additional
  41939. { begin: 0x1f00, end: 0x1fff }, // Greek Extended
  41940. { begin: 0x2000, end: 0x206f }, // General Punctuation
  41941. { begin: 0x2070, end: 0x209f }, // Superscripts And Subscripts
  41942. { begin: 0x20a0, end: 0x20cf }, // Currency Symbol
  41943. { begin: 0x20d0, end: 0x20ff }, // Combining Diacritical Marks For Symbols
  41944. { begin: 0x2100, end: 0x214f }, // Letterlike Symbols
  41945. { begin: 0x2150, end: 0x218f }, // Number Forms
  41946. { begin: 0x2190, end: 0x21ff }, // Arrows
  41947. { begin: 0x2200, end: 0x22ff }, // Mathematical Operators
  41948. { begin: 0x2300, end: 0x23ff }, // Miscellaneous Technical
  41949. { begin: 0x2400, end: 0x243f }, // Control Pictures
  41950. { begin: 0x2440, end: 0x245f }, // Optical Character Recognition
  41951. { begin: 0x2460, end: 0x24ff }, // Enclosed Alphanumerics
  41952. { begin: 0x2500, end: 0x257f }, // Box Drawing
  41953. { begin: 0x2580, end: 0x259f }, // Block Elements
  41954. { begin: 0x25a0, end: 0x25ff }, // Geometric Shapes
  41955. { begin: 0x2600, end: 0x26ff }, // Miscellaneous Symbols
  41956. { begin: 0x2700, end: 0x27bf }, // Dingbats
  41957. { begin: 0x3000, end: 0x303f }, // CJK Symbols And Punctuation
  41958. { begin: 0x3040, end: 0x309f }, // Hiragana
  41959. { begin: 0x30a0, end: 0x30ff }, // Katakana
  41960. { begin: 0x3100, end: 0x312f }, // Bopomofo
  41961. { begin: 0x3130, end: 0x318f }, // Hangul Compatibility Jamo
  41962. { begin: 0xa840, end: 0xa87f }, // Phags-pa
  41963. { begin: 0x3200, end: 0x32ff }, // Enclosed CJK Letters And Months
  41964. { begin: 0x3300, end: 0x33ff }, // CJK Compatibility
  41965. { begin: 0xac00, end: 0xd7af }, // Hangul Syllables
  41966. { begin: 0xd800, end: 0xdfff }, // Non-Plane 0 *
  41967. { begin: 0x10900, end: 0x1091f }, // Phoenicia
  41968. { begin: 0x4e00, end: 0x9fff }, // CJK Unified Ideographs
  41969. { begin: 0xe000, end: 0xf8ff }, // Private Use Area (plane 0)
  41970. { begin: 0x31c0, end: 0x31ef }, // CJK Strokes
  41971. { begin: 0xfb00, end: 0xfb4f }, // Alphabetic Presentation Forms
  41972. { begin: 0xfb50, end: 0xfdff }, // Arabic Presentation Forms-A
  41973. { begin: 0xfe20, end: 0xfe2f }, // Combining Half Marks
  41974. { begin: 0xfe10, end: 0xfe1f }, // Vertical Forms
  41975. { begin: 0xfe50, end: 0xfe6f }, // Small Form Variants
  41976. { begin: 0xfe70, end: 0xfeff }, // Arabic Presentation Forms-B
  41977. { begin: 0xff00, end: 0xffef }, // Halfwidth And Fullwidth Forms
  41978. { begin: 0xfff0, end: 0xffff }, // Specials
  41979. { begin: 0x0f00, end: 0x0fff }, // Tibetan
  41980. { begin: 0x0700, end: 0x074f }, // Syriac
  41981. { begin: 0x0780, end: 0x07bf }, // Thaana
  41982. { begin: 0x0d80, end: 0x0dff }, // Sinhala
  41983. { begin: 0x1000, end: 0x109f }, // Myanmar
  41984. { begin: 0x1200, end: 0x137f }, // Ethiopic
  41985. { begin: 0x13a0, end: 0x13ff }, // Cherokee
  41986. { begin: 0x1400, end: 0x167f }, // Unified Canadian Aboriginal Syllabics
  41987. { begin: 0x1680, end: 0x169f }, // Ogham
  41988. { begin: 0x16a0, end: 0x16ff }, // Runic
  41989. { begin: 0x1780, end: 0x17ff }, // Khmer
  41990. { begin: 0x1800, end: 0x18af }, // Mongolian
  41991. { begin: 0x2800, end: 0x28ff }, // Braille Patterns
  41992. { begin: 0xa000, end: 0xa48f }, // Yi Syllables
  41993. { begin: 0x1700, end: 0x171f }, // Tagalog
  41994. { begin: 0x10300, end: 0x1032f }, // Old Italic
  41995. { begin: 0x10330, end: 0x1034f }, // Gothic
  41996. { begin: 0x10400, end: 0x1044f }, // Deseret
  41997. { begin: 0x1d000, end: 0x1d0ff }, // Byzantine Musical Symbols
  41998. { begin: 0x1d400, end: 0x1d7ff }, // Mathematical Alphanumeric Symbols
  41999. { begin: 0xff000, end: 0xffffd }, // Private Use (plane 15)
  42000. { begin: 0xfe00, end: 0xfe0f }, // Variation Selectors
  42001. { begin: 0xe0000, end: 0xe007f }, // Tags
  42002. { begin: 0x1900, end: 0x194f }, // Limbu
  42003. { begin: 0x1950, end: 0x197f }, // Tai Le
  42004. { begin: 0x1980, end: 0x19df }, // New Tai Lue
  42005. { begin: 0x1a00, end: 0x1a1f }, // Buginese
  42006. { begin: 0x2c00, end: 0x2c5f }, // Glagolitic
  42007. { begin: 0x2d30, end: 0x2d7f }, // Tifinagh
  42008. { begin: 0x4dc0, end: 0x4dff }, // Yijing Hexagram Symbols
  42009. { begin: 0xa800, end: 0xa82f }, // Syloti Nagri
  42010. { begin: 0x10000, end: 0x1007f }, // Linear B Syllabary
  42011. { begin: 0x10140, end: 0x1018f }, // Ancient Greek Numbers
  42012. { begin: 0x10380, end: 0x1039f }, // Ugaritic
  42013. { begin: 0x103a0, end: 0x103df }, // Old Persian
  42014. { begin: 0x10450, end: 0x1047f }, // Shavian
  42015. { begin: 0x10480, end: 0x104af }, // Osmanya
  42016. { begin: 0x10800, end: 0x1083f }, // Cypriot Syllabary
  42017. { begin: 0x10a00, end: 0x10a5f }, // Kharoshthi
  42018. { begin: 0x1d300, end: 0x1d35f }, // Tai Xuan Jing Symbols
  42019. { begin: 0x12000, end: 0x123ff }, // Cuneiform
  42020. { begin: 0x1d360, end: 0x1d37f }, // Counting Rod Numerals
  42021. { begin: 0x1b80, end: 0x1bbf }, // Sundanese
  42022. { begin: 0x1c00, end: 0x1c4f }, // Lepcha
  42023. { begin: 0x1c50, end: 0x1c7f }, // Ol Chiki
  42024. { begin: 0xa880, end: 0xa8df }, // Saurashtra
  42025. { begin: 0xa900, end: 0xa92f }, // Kayah Li
  42026. { begin: 0xa930, end: 0xa95f }, // Rejang
  42027. { begin: 0xaa00, end: 0xaa5f }, // Cham
  42028. { begin: 0x10190, end: 0x101cf }, // Ancient Symbols
  42029. { begin: 0x101d0, end: 0x101ff }, // Phaistos Disc
  42030. { begin: 0x102a0, end: 0x102df }, // Carian
  42031. { begin: 0x1f030, end: 0x1f09f } // Domino Tiles
  42032. ];
  42033. function getUnicodeRange(unicode) {
  42034. for (var i = 0; i < unicodeRanges.length; i += 1) {
  42035. var range = unicodeRanges[i];
  42036. if (unicode >= range.begin && unicode < range.end) {
  42037. return i;
  42038. }
  42039. }
  42040. return -1;
  42041. }
  42042. // Parse the OS/2 and Windows metrics `OS/2` table
  42043. function parseOS2Table(data, start) {
  42044. var os2 = {};
  42045. var p = new parse.Parser(data, start);
  42046. os2.version = p.parseUShort();
  42047. os2.xAvgCharWidth = p.parseShort();
  42048. os2.usWeightClass = p.parseUShort();
  42049. os2.usWidthClass = p.parseUShort();
  42050. os2.fsType = p.parseUShort();
  42051. os2.ySubscriptXSize = p.parseShort();
  42052. os2.ySubscriptYSize = p.parseShort();
  42053. os2.ySubscriptXOffset = p.parseShort();
  42054. os2.ySubscriptYOffset = p.parseShort();
  42055. os2.ySuperscriptXSize = p.parseShort();
  42056. os2.ySuperscriptYSize = p.parseShort();
  42057. os2.ySuperscriptXOffset = p.parseShort();
  42058. os2.ySuperscriptYOffset = p.parseShort();
  42059. os2.yStrikeoutSize = p.parseShort();
  42060. os2.yStrikeoutPosition = p.parseShort();
  42061. os2.sFamilyClass = p.parseShort();
  42062. os2.panose = [];
  42063. for (var i = 0; i < 10; i++) {
  42064. os2.panose[i] = p.parseByte();
  42065. }
  42066. os2.ulUnicodeRange1 = p.parseULong();
  42067. os2.ulUnicodeRange2 = p.parseULong();
  42068. os2.ulUnicodeRange3 = p.parseULong();
  42069. os2.ulUnicodeRange4 = p.parseULong();
  42070. os2.achVendID = String.fromCharCode(
  42071. p.parseByte(),
  42072. p.parseByte(),
  42073. p.parseByte(),
  42074. p.parseByte()
  42075. );
  42076. os2.fsSelection = p.parseUShort();
  42077. os2.usFirstCharIndex = p.parseUShort();
  42078. os2.usLastCharIndex = p.parseUShort();
  42079. os2.sTypoAscender = p.parseShort();
  42080. os2.sTypoDescender = p.parseShort();
  42081. os2.sTypoLineGap = p.parseShort();
  42082. os2.usWinAscent = p.parseUShort();
  42083. os2.usWinDescent = p.parseUShort();
  42084. if (os2.version >= 1) {
  42085. os2.ulCodePageRange1 = p.parseULong();
  42086. os2.ulCodePageRange2 = p.parseULong();
  42087. }
  42088. if (os2.version >= 2) {
  42089. os2.sxHeight = p.parseShort();
  42090. os2.sCapHeight = p.parseShort();
  42091. os2.usDefaultChar = p.parseUShort();
  42092. os2.usBreakChar = p.parseUShort();
  42093. os2.usMaxContent = p.parseUShort();
  42094. }
  42095. return os2;
  42096. }
  42097. function makeOS2Table(options) {
  42098. return new table.Table(
  42099. 'OS/2',
  42100. [
  42101. { name: 'version', type: 'USHORT', value: 0x0003 },
  42102. { name: 'xAvgCharWidth', type: 'SHORT', value: 0 },
  42103. { name: 'usWeightClass', type: 'USHORT', value: 0 },
  42104. { name: 'usWidthClass', type: 'USHORT', value: 0 },
  42105. { name: 'fsType', type: 'USHORT', value: 0 },
  42106. { name: 'ySubscriptXSize', type: 'SHORT', value: 650 },
  42107. { name: 'ySubscriptYSize', type: 'SHORT', value: 699 },
  42108. { name: 'ySubscriptXOffset', type: 'SHORT', value: 0 },
  42109. { name: 'ySubscriptYOffset', type: 'SHORT', value: 140 },
  42110. { name: 'ySuperscriptXSize', type: 'SHORT', value: 650 },
  42111. { name: 'ySuperscriptYSize', type: 'SHORT', value: 699 },
  42112. { name: 'ySuperscriptXOffset', type: 'SHORT', value: 0 },
  42113. { name: 'ySuperscriptYOffset', type: 'SHORT', value: 479 },
  42114. { name: 'yStrikeoutSize', type: 'SHORT', value: 49 },
  42115. { name: 'yStrikeoutPosition', type: 'SHORT', value: 258 },
  42116. { name: 'sFamilyClass', type: 'SHORT', value: 0 },
  42117. { name: 'bFamilyType', type: 'BYTE', value: 0 },
  42118. { name: 'bSerifStyle', type: 'BYTE', value: 0 },
  42119. { name: 'bWeight', type: 'BYTE', value: 0 },
  42120. { name: 'bProportion', type: 'BYTE', value: 0 },
  42121. { name: 'bContrast', type: 'BYTE', value: 0 },
  42122. { name: 'bStrokeVariation', type: 'BYTE', value: 0 },
  42123. { name: 'bArmStyle', type: 'BYTE', value: 0 },
  42124. { name: 'bLetterform', type: 'BYTE', value: 0 },
  42125. { name: 'bMidline', type: 'BYTE', value: 0 },
  42126. { name: 'bXHeight', type: 'BYTE', value: 0 },
  42127. { name: 'ulUnicodeRange1', type: 'ULONG', value: 0 },
  42128. { name: 'ulUnicodeRange2', type: 'ULONG', value: 0 },
  42129. { name: 'ulUnicodeRange3', type: 'ULONG', value: 0 },
  42130. { name: 'ulUnicodeRange4', type: 'ULONG', value: 0 },
  42131. { name: 'achVendID', type: 'CHARARRAY', value: 'XXXX' },
  42132. { name: 'fsSelection', type: 'USHORT', value: 0 },
  42133. { name: 'usFirstCharIndex', type: 'USHORT', value: 0 },
  42134. { name: 'usLastCharIndex', type: 'USHORT', value: 0 },
  42135. { name: 'sTypoAscender', type: 'SHORT', value: 0 },
  42136. { name: 'sTypoDescender', type: 'SHORT', value: 0 },
  42137. { name: 'sTypoLineGap', type: 'SHORT', value: 0 },
  42138. { name: 'usWinAscent', type: 'USHORT', value: 0 },
  42139. { name: 'usWinDescent', type: 'USHORT', value: 0 },
  42140. { name: 'ulCodePageRange1', type: 'ULONG', value: 0 },
  42141. { name: 'ulCodePageRange2', type: 'ULONG', value: 0 },
  42142. { name: 'sxHeight', type: 'SHORT', value: 0 },
  42143. { name: 'sCapHeight', type: 'SHORT', value: 0 },
  42144. { name: 'usDefaultChar', type: 'USHORT', value: 0 },
  42145. { name: 'usBreakChar', type: 'USHORT', value: 0 },
  42146. { name: 'usMaxContext', type: 'USHORT', value: 0 }
  42147. ],
  42148. options
  42149. );
  42150. }
  42151. var os2 = {
  42152. parse: parseOS2Table,
  42153. make: makeOS2Table,
  42154. unicodeRanges: unicodeRanges,
  42155. getUnicodeRange: getUnicodeRange
  42156. };
  42157. // The `post` table stores additional PostScript information, such as glyph names.
  42158. // Parse the PostScript `post` table
  42159. function parsePostTable(data, start) {
  42160. var post = {};
  42161. var p = new parse.Parser(data, start);
  42162. post.version = p.parseVersion();
  42163. post.italicAngle = p.parseFixed();
  42164. post.underlinePosition = p.parseShort();
  42165. post.underlineThickness = p.parseShort();
  42166. post.isFixedPitch = p.parseULong();
  42167. post.minMemType42 = p.parseULong();
  42168. post.maxMemType42 = p.parseULong();
  42169. post.minMemType1 = p.parseULong();
  42170. post.maxMemType1 = p.parseULong();
  42171. switch (post.version) {
  42172. case 1:
  42173. post.names = standardNames.slice();
  42174. break;
  42175. case 2:
  42176. post.numberOfGlyphs = p.parseUShort();
  42177. post.glyphNameIndex = new Array(post.numberOfGlyphs);
  42178. for (var i = 0; i < post.numberOfGlyphs; i++) {
  42179. post.glyphNameIndex[i] = p.parseUShort();
  42180. }
  42181. post.names = [];
  42182. for (var i$1 = 0; i$1 < post.numberOfGlyphs; i$1++) {
  42183. if (post.glyphNameIndex[i$1] >= standardNames.length) {
  42184. var nameLength = p.parseChar();
  42185. post.names.push(p.parseString(nameLength));
  42186. }
  42187. }
  42188. break;
  42189. case 2.5:
  42190. post.numberOfGlyphs = p.parseUShort();
  42191. post.offset = new Array(post.numberOfGlyphs);
  42192. for (var i$2 = 0; i$2 < post.numberOfGlyphs; i$2++) {
  42193. post.offset[i$2] = p.parseChar();
  42194. }
  42195. break;
  42196. }
  42197. return post;
  42198. }
  42199. function makePostTable() {
  42200. return new table.Table('post', [
  42201. { name: 'version', type: 'FIXED', value: 0x00030000 },
  42202. { name: 'italicAngle', type: 'FIXED', value: 0 },
  42203. { name: 'underlinePosition', type: 'FWORD', value: 0 },
  42204. { name: 'underlineThickness', type: 'FWORD', value: 0 },
  42205. { name: 'isFixedPitch', type: 'ULONG', value: 0 },
  42206. { name: 'minMemType42', type: 'ULONG', value: 0 },
  42207. { name: 'maxMemType42', type: 'ULONG', value: 0 },
  42208. { name: 'minMemType1', type: 'ULONG', value: 0 },
  42209. { name: 'maxMemType1', type: 'ULONG', value: 0 }
  42210. ]);
  42211. }
  42212. var post = { parse: parsePostTable, make: makePostTable };
  42213. // The `GSUB` table contains ligatures, among other things.
  42214. var subtableParsers = new Array(9); // subtableParsers[0] is unused
  42215. // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#SS
  42216. subtableParsers[1] = function parseLookup1() {
  42217. var start = this.offset + this.relativeOffset;
  42218. var substFormat = this.parseUShort();
  42219. if (substFormat === 1) {
  42220. return {
  42221. substFormat: 1,
  42222. coverage: this.parsePointer(Parser.coverage),
  42223. deltaGlyphId: this.parseUShort()
  42224. };
  42225. } else if (substFormat === 2) {
  42226. return {
  42227. substFormat: 2,
  42228. coverage: this.parsePointer(Parser.coverage),
  42229. substitute: this.parseOffset16List()
  42230. };
  42231. }
  42232. check.assert(
  42233. false,
  42234. '0x' + start.toString(16) + ': lookup type 1 format must be 1 or 2.'
  42235. );
  42236. };
  42237. // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#MS
  42238. subtableParsers[2] = function parseLookup2() {
  42239. var substFormat = this.parseUShort();
  42240. check.argument(
  42241. substFormat === 1,
  42242. 'GSUB Multiple Substitution Subtable identifier-format must be 1'
  42243. );
  42244. return {
  42245. substFormat: substFormat,
  42246. coverage: this.parsePointer(Parser.coverage),
  42247. sequences: this.parseListOfLists()
  42248. };
  42249. };
  42250. // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#AS
  42251. subtableParsers[3] = function parseLookup3() {
  42252. var substFormat = this.parseUShort();
  42253. check.argument(
  42254. substFormat === 1,
  42255. 'GSUB Alternate Substitution Subtable identifier-format must be 1'
  42256. );
  42257. return {
  42258. substFormat: substFormat,
  42259. coverage: this.parsePointer(Parser.coverage),
  42260. alternateSets: this.parseListOfLists()
  42261. };
  42262. };
  42263. // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#LS
  42264. subtableParsers[4] = function parseLookup4() {
  42265. var substFormat = this.parseUShort();
  42266. check.argument(
  42267. substFormat === 1,
  42268. 'GSUB ligature table identifier-format must be 1'
  42269. );
  42270. return {
  42271. substFormat: substFormat,
  42272. coverage: this.parsePointer(Parser.coverage),
  42273. ligatureSets: this.parseListOfLists(function() {
  42274. return {
  42275. ligGlyph: this.parseUShort(),
  42276. components: this.parseUShortList(this.parseUShort() - 1)
  42277. };
  42278. })
  42279. };
  42280. };
  42281. var lookupRecordDesc = {
  42282. sequenceIndex: Parser.uShort,
  42283. lookupListIndex: Parser.uShort
  42284. };
  42285. // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#CSF
  42286. subtableParsers[5] = function parseLookup5() {
  42287. var start = this.offset + this.relativeOffset;
  42288. var substFormat = this.parseUShort();
  42289. if (substFormat === 1) {
  42290. return {
  42291. substFormat: substFormat,
  42292. coverage: this.parsePointer(Parser.coverage),
  42293. ruleSets: this.parseListOfLists(function() {
  42294. var glyphCount = this.parseUShort();
  42295. var substCount = this.parseUShort();
  42296. return {
  42297. input: this.parseUShortList(glyphCount - 1),
  42298. lookupRecords: this.parseRecordList(substCount, lookupRecordDesc)
  42299. };
  42300. })
  42301. };
  42302. } else if (substFormat === 2) {
  42303. return {
  42304. substFormat: substFormat,
  42305. coverage: this.parsePointer(Parser.coverage),
  42306. classDef: this.parsePointer(Parser.classDef),
  42307. classSets: this.parseListOfLists(function() {
  42308. var glyphCount = this.parseUShort();
  42309. var substCount = this.parseUShort();
  42310. return {
  42311. classes: this.parseUShortList(glyphCount - 1),
  42312. lookupRecords: this.parseRecordList(substCount, lookupRecordDesc)
  42313. };
  42314. })
  42315. };
  42316. } else if (substFormat === 3) {
  42317. var glyphCount = this.parseUShort();
  42318. var substCount = this.parseUShort();
  42319. return {
  42320. substFormat: substFormat,
  42321. coverages: this.parseList(glyphCount, Parser.pointer(Parser.coverage)),
  42322. lookupRecords: this.parseRecordList(substCount, lookupRecordDesc)
  42323. };
  42324. }
  42325. check.assert(
  42326. false,
  42327. '0x' + start.toString(16) + ': lookup type 5 format must be 1, 2 or 3.'
  42328. );
  42329. };
  42330. // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#CC
  42331. subtableParsers[6] = function parseLookup6() {
  42332. var start = this.offset + this.relativeOffset;
  42333. var substFormat = this.parseUShort();
  42334. if (substFormat === 1) {
  42335. return {
  42336. substFormat: 1,
  42337. coverage: this.parsePointer(Parser.coverage),
  42338. chainRuleSets: this.parseListOfLists(function() {
  42339. return {
  42340. backtrack: this.parseUShortList(),
  42341. input: this.parseUShortList(this.parseShort() - 1),
  42342. lookahead: this.parseUShortList(),
  42343. lookupRecords: this.parseRecordList(lookupRecordDesc)
  42344. };
  42345. })
  42346. };
  42347. } else if (substFormat === 2) {
  42348. return {
  42349. substFormat: 2,
  42350. coverage: this.parsePointer(Parser.coverage),
  42351. backtrackClassDef: this.parsePointer(Parser.classDef),
  42352. inputClassDef: this.parsePointer(Parser.classDef),
  42353. lookaheadClassDef: this.parsePointer(Parser.classDef),
  42354. chainClassSet: this.parseListOfLists(function() {
  42355. return {
  42356. backtrack: this.parseUShortList(),
  42357. input: this.parseUShortList(this.parseShort() - 1),
  42358. lookahead: this.parseUShortList(),
  42359. lookupRecords: this.parseRecordList(lookupRecordDesc)
  42360. };
  42361. })
  42362. };
  42363. } else if (substFormat === 3) {
  42364. return {
  42365. substFormat: 3,
  42366. backtrackCoverage: this.parseList(Parser.pointer(Parser.coverage)),
  42367. inputCoverage: this.parseList(Parser.pointer(Parser.coverage)),
  42368. lookaheadCoverage: this.parseList(Parser.pointer(Parser.coverage)),
  42369. lookupRecords: this.parseRecordList(lookupRecordDesc)
  42370. };
  42371. }
  42372. check.assert(
  42373. false,
  42374. '0x' + start.toString(16) + ': lookup type 6 format must be 1, 2 or 3.'
  42375. );
  42376. };
  42377. // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#ES
  42378. subtableParsers[7] = function parseLookup7() {
  42379. // Extension Substitution subtable
  42380. var substFormat = this.parseUShort();
  42381. check.argument(
  42382. substFormat === 1,
  42383. 'GSUB Extension Substitution subtable identifier-format must be 1'
  42384. );
  42385. var extensionLookupType = this.parseUShort();
  42386. var extensionParser = new Parser(
  42387. this.data,
  42388. this.offset + this.parseULong()
  42389. );
  42390. return {
  42391. substFormat: 1,
  42392. lookupType: extensionLookupType,
  42393. extension: subtableParsers[extensionLookupType].call(extensionParser)
  42394. };
  42395. };
  42396. // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#RCCS
  42397. subtableParsers[8] = function parseLookup8() {
  42398. var substFormat = this.parseUShort();
  42399. check.argument(
  42400. substFormat === 1,
  42401. 'GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1'
  42402. );
  42403. return {
  42404. substFormat: substFormat,
  42405. coverage: this.parsePointer(Parser.coverage),
  42406. backtrackCoverage: this.parseList(Parser.pointer(Parser.coverage)),
  42407. lookaheadCoverage: this.parseList(Parser.pointer(Parser.coverage)),
  42408. substitutes: this.parseUShortList()
  42409. };
  42410. };
  42411. // https://www.microsoft.com/typography/OTSPEC/gsub.htm
  42412. function parseGsubTable(data, start) {
  42413. start = start || 0;
  42414. var p = new Parser(data, start);
  42415. var tableVersion = p.parseVersion(1);
  42416. check.argument(
  42417. tableVersion === 1 || tableVersion === 1.1,
  42418. 'Unsupported GSUB table version.'
  42419. );
  42420. if (tableVersion === 1) {
  42421. return {
  42422. version: tableVersion,
  42423. scripts: p.parseScriptList(),
  42424. features: p.parseFeatureList(),
  42425. lookups: p.parseLookupList(subtableParsers)
  42426. };
  42427. } else {
  42428. return {
  42429. version: tableVersion,
  42430. scripts: p.parseScriptList(),
  42431. features: p.parseFeatureList(),
  42432. lookups: p.parseLookupList(subtableParsers),
  42433. variations: p.parseFeatureVariationsList()
  42434. };
  42435. }
  42436. }
  42437. // GSUB Writing //////////////////////////////////////////////
  42438. var subtableMakers = new Array(9);
  42439. subtableMakers[1] = function makeLookup1(subtable) {
  42440. if (subtable.substFormat === 1) {
  42441. return new table.Table('substitutionTable', [
  42442. { name: 'substFormat', type: 'USHORT', value: 1 },
  42443. {
  42444. name: 'coverage',
  42445. type: 'TABLE',
  42446. value: new table.Coverage(subtable.coverage)
  42447. },
  42448. { name: 'deltaGlyphID', type: 'USHORT', value: subtable.deltaGlyphId }
  42449. ]);
  42450. } else {
  42451. return new table.Table(
  42452. 'substitutionTable',
  42453. [
  42454. { name: 'substFormat', type: 'USHORT', value: 2 },
  42455. {
  42456. name: 'coverage',
  42457. type: 'TABLE',
  42458. value: new table.Coverage(subtable.coverage)
  42459. }
  42460. ].concat(table.ushortList('substitute', subtable.substitute))
  42461. );
  42462. }
  42463. check.fail('Lookup type 1 substFormat must be 1 or 2.');
  42464. };
  42465. subtableMakers[3] = function makeLookup3(subtable) {
  42466. check.assert(
  42467. subtable.substFormat === 1,
  42468. 'Lookup type 3 substFormat must be 1.'
  42469. );
  42470. return new table.Table(
  42471. 'substitutionTable',
  42472. [
  42473. { name: 'substFormat', type: 'USHORT', value: 1 },
  42474. {
  42475. name: 'coverage',
  42476. type: 'TABLE',
  42477. value: new table.Coverage(subtable.coverage)
  42478. }
  42479. ].concat(
  42480. table.tableList('altSet', subtable.alternateSets, function(
  42481. alternateSet
  42482. ) {
  42483. return new table.Table(
  42484. 'alternateSetTable',
  42485. table.ushortList('alternate', alternateSet)
  42486. );
  42487. })
  42488. )
  42489. );
  42490. };
  42491. subtableMakers[4] = function makeLookup4(subtable) {
  42492. check.assert(
  42493. subtable.substFormat === 1,
  42494. 'Lookup type 4 substFormat must be 1.'
  42495. );
  42496. return new table.Table(
  42497. 'substitutionTable',
  42498. [
  42499. { name: 'substFormat', type: 'USHORT', value: 1 },
  42500. {
  42501. name: 'coverage',
  42502. type: 'TABLE',
  42503. value: new table.Coverage(subtable.coverage)
  42504. }
  42505. ].concat(
  42506. table.tableList('ligSet', subtable.ligatureSets, function(ligatureSet) {
  42507. return new table.Table(
  42508. 'ligatureSetTable',
  42509. table.tableList('ligature', ligatureSet, function(ligature) {
  42510. return new table.Table(
  42511. 'ligatureTable',
  42512. [
  42513. { name: 'ligGlyph', type: 'USHORT', value: ligature.ligGlyph }
  42514. ].concat(
  42515. table.ushortList(
  42516. 'component',
  42517. ligature.components,
  42518. ligature.components.length + 1
  42519. )
  42520. )
  42521. );
  42522. })
  42523. );
  42524. })
  42525. )
  42526. );
  42527. };
  42528. function makeGsubTable(gsub) {
  42529. return new table.Table('GSUB', [
  42530. { name: 'version', type: 'ULONG', value: 0x10000 },
  42531. {
  42532. name: 'scripts',
  42533. type: 'TABLE',
  42534. value: new table.ScriptList(gsub.scripts)
  42535. },
  42536. {
  42537. name: 'features',
  42538. type: 'TABLE',
  42539. value: new table.FeatureList(gsub.features)
  42540. },
  42541. {
  42542. name: 'lookups',
  42543. type: 'TABLE',
  42544. value: new table.LookupList(gsub.lookups, subtableMakers)
  42545. }
  42546. ]);
  42547. }
  42548. var gsub = { parse: parseGsubTable, make: makeGsubTable };
  42549. // The `GPOS` table contains kerning pairs, among other things.
  42550. // Parse the metadata `meta` table.
  42551. // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6meta.html
  42552. function parseMetaTable(data, start) {
  42553. var p = new parse.Parser(data, start);
  42554. var tableVersion = p.parseULong();
  42555. check.argument(tableVersion === 1, 'Unsupported META table version.');
  42556. p.parseULong(); // flags - currently unused and set to 0
  42557. p.parseULong(); // tableOffset
  42558. var numDataMaps = p.parseULong();
  42559. var tags = {};
  42560. for (var i = 0; i < numDataMaps; i++) {
  42561. var tag = p.parseTag();
  42562. var dataOffset = p.parseULong();
  42563. var dataLength = p.parseULong();
  42564. var text = decode.UTF8(data, start + dataOffset, dataLength);
  42565. tags[tag] = text;
  42566. }
  42567. return tags;
  42568. }
  42569. function makeMetaTable(tags) {
  42570. var numTags = Object.keys(tags).length;
  42571. var stringPool = '';
  42572. var stringPoolOffset = 16 + numTags * 12;
  42573. var result = new table.Table('meta', [
  42574. { name: 'version', type: 'ULONG', value: 1 },
  42575. { name: 'flags', type: 'ULONG', value: 0 },
  42576. { name: 'offset', type: 'ULONG', value: stringPoolOffset },
  42577. { name: 'numTags', type: 'ULONG', value: numTags }
  42578. ]);
  42579. for (var tag in tags) {
  42580. var pos = stringPool.length;
  42581. stringPool += tags[tag];
  42582. result.fields.push({ name: 'tag ' + tag, type: 'TAG', value: tag });
  42583. result.fields.push({
  42584. name: 'offset ' + tag,
  42585. type: 'ULONG',
  42586. value: stringPoolOffset + pos
  42587. });
  42588. result.fields.push({
  42589. name: 'length ' + tag,
  42590. type: 'ULONG',
  42591. value: tags[tag].length
  42592. });
  42593. }
  42594. result.fields.push({
  42595. name: 'stringPool',
  42596. type: 'CHARARRAY',
  42597. value: stringPool
  42598. });
  42599. return result;
  42600. }
  42601. var meta = { parse: parseMetaTable, make: makeMetaTable };
  42602. // The `sfnt` wrapper provides organization for the tables in the font.
  42603. function log2(v) {
  42604. return (Math.log(v) / Math.log(2)) | 0;
  42605. }
  42606. function computeCheckSum(bytes) {
  42607. while (bytes.length % 4 !== 0) {
  42608. bytes.push(0);
  42609. }
  42610. var sum = 0;
  42611. for (var i = 0; i < bytes.length; i += 4) {
  42612. sum +=
  42613. (bytes[i] << 24) +
  42614. (bytes[i + 1] << 16) +
  42615. (bytes[i + 2] << 8) +
  42616. bytes[i + 3];
  42617. }
  42618. sum %= Math.pow(2, 32);
  42619. return sum;
  42620. }
  42621. function makeTableRecord(tag, checkSum, offset, length) {
  42622. return new table.Record('Table Record', [
  42623. { name: 'tag', type: 'TAG', value: tag !== undefined ? tag : '' },
  42624. {
  42625. name: 'checkSum',
  42626. type: 'ULONG',
  42627. value: checkSum !== undefined ? checkSum : 0
  42628. },
  42629. {
  42630. name: 'offset',
  42631. type: 'ULONG',
  42632. value: offset !== undefined ? offset : 0
  42633. },
  42634. {
  42635. name: 'length',
  42636. type: 'ULONG',
  42637. value: length !== undefined ? length : 0
  42638. }
  42639. ]);
  42640. }
  42641. function makeSfntTable(tables) {
  42642. var sfnt = new table.Table('sfnt', [
  42643. { name: 'version', type: 'TAG', value: 'OTTO' },
  42644. { name: 'numTables', type: 'USHORT', value: 0 },
  42645. { name: 'searchRange', type: 'USHORT', value: 0 },
  42646. { name: 'entrySelector', type: 'USHORT', value: 0 },
  42647. { name: 'rangeShift', type: 'USHORT', value: 0 }
  42648. ]);
  42649. sfnt.tables = tables;
  42650. sfnt.numTables = tables.length;
  42651. var highestPowerOf2 = Math.pow(2, log2(sfnt.numTables));
  42652. sfnt.searchRange = 16 * highestPowerOf2;
  42653. sfnt.entrySelector = log2(highestPowerOf2);
  42654. sfnt.rangeShift = sfnt.numTables * 16 - sfnt.searchRange;
  42655. var recordFields = [];
  42656. var tableFields = [];
  42657. var offset = sfnt.sizeOf() + makeTableRecord().sizeOf() * sfnt.numTables;
  42658. while (offset % 4 !== 0) {
  42659. offset += 1;
  42660. tableFields.push({ name: 'padding', type: 'BYTE', value: 0 });
  42661. }
  42662. for (var i = 0; i < tables.length; i += 1) {
  42663. var t = tables[i];
  42664. check.argument(
  42665. t.tableName.length === 4,
  42666. 'Table name' + t.tableName + ' is invalid.'
  42667. );
  42668. var tableLength = t.sizeOf();
  42669. var tableRecord = makeTableRecord(
  42670. t.tableName,
  42671. computeCheckSum(t.encode()),
  42672. offset,
  42673. tableLength
  42674. );
  42675. recordFields.push({
  42676. name: tableRecord.tag + ' Table Record',
  42677. type: 'RECORD',
  42678. value: tableRecord
  42679. });
  42680. tableFields.push({
  42681. name: t.tableName + ' table',
  42682. type: 'RECORD',
  42683. value: t
  42684. });
  42685. offset += tableLength;
  42686. check.argument(
  42687. !isNaN(offset),
  42688. 'Something went wrong calculating the offset.'
  42689. );
  42690. while (offset % 4 !== 0) {
  42691. offset += 1;
  42692. tableFields.push({ name: 'padding', type: 'BYTE', value: 0 });
  42693. }
  42694. }
  42695. // Table records need to be sorted alphabetically.
  42696. recordFields.sort(function(r1, r2) {
  42697. if (r1.value.tag > r2.value.tag) {
  42698. return 1;
  42699. } else {
  42700. return -1;
  42701. }
  42702. });
  42703. sfnt.fields = sfnt.fields.concat(recordFields);
  42704. sfnt.fields = sfnt.fields.concat(tableFields);
  42705. return sfnt;
  42706. }
  42707. // Get the metrics for a character. If the string has more than one character
  42708. // this function returns metrics for the first available character.
  42709. // You can provide optional fallback metrics if no characters are available.
  42710. function metricsForChar(font, chars, notFoundMetrics) {
  42711. for (var i = 0; i < chars.length; i += 1) {
  42712. var glyphIndex = font.charToGlyphIndex(chars[i]);
  42713. if (glyphIndex > 0) {
  42714. var glyph = font.glyphs.get(glyphIndex);
  42715. return glyph.getMetrics();
  42716. }
  42717. }
  42718. return notFoundMetrics;
  42719. }
  42720. function average(vs) {
  42721. var sum = 0;
  42722. for (var i = 0; i < vs.length; i += 1) {
  42723. sum += vs[i];
  42724. }
  42725. return sum / vs.length;
  42726. }
  42727. // Convert the font object to a SFNT data structure.
  42728. // This structure contains all the necessary tables and metadata to create a binary OTF file.
  42729. function fontToSfntTable(font) {
  42730. var xMins = [];
  42731. var yMins = [];
  42732. var xMaxs = [];
  42733. var yMaxs = [];
  42734. var advanceWidths = [];
  42735. var leftSideBearings = [];
  42736. var rightSideBearings = [];
  42737. var firstCharIndex;
  42738. var lastCharIndex = 0;
  42739. var ulUnicodeRange1 = 0;
  42740. var ulUnicodeRange2 = 0;
  42741. var ulUnicodeRange3 = 0;
  42742. var ulUnicodeRange4 = 0;
  42743. for (var i = 0; i < font.glyphs.length; i += 1) {
  42744. var glyph = font.glyphs.get(i);
  42745. var unicode = glyph.unicode | 0;
  42746. if (isNaN(glyph.advanceWidth)) {
  42747. throw new Error(
  42748. 'Glyph ' + glyph.name + ' (' + i + '): advanceWidth is not a number.'
  42749. );
  42750. }
  42751. if (firstCharIndex > unicode || firstCharIndex === undefined) {
  42752. // ignore .notdef char
  42753. if (unicode > 0) {
  42754. firstCharIndex = unicode;
  42755. }
  42756. }
  42757. if (lastCharIndex < unicode) {
  42758. lastCharIndex = unicode;
  42759. }
  42760. var position = os2.getUnicodeRange(unicode);
  42761. if (position < 32) {
  42762. ulUnicodeRange1 |= 1 << position;
  42763. } else if (position < 64) {
  42764. ulUnicodeRange2 |= 1 << (position - 32);
  42765. } else if (position < 96) {
  42766. ulUnicodeRange3 |= 1 << (position - 64);
  42767. } else if (position < 123) {
  42768. ulUnicodeRange4 |= 1 << (position - 96);
  42769. } else {
  42770. throw new Error(
  42771. 'Unicode ranges bits > 123 are reserved for internal usage'
  42772. );
  42773. }
  42774. // Skip non-important characters.
  42775. if (glyph.name === '.notdef') {
  42776. continue;
  42777. }
  42778. var metrics = glyph.getMetrics();
  42779. xMins.push(metrics.xMin);
  42780. yMins.push(metrics.yMin);
  42781. xMaxs.push(metrics.xMax);
  42782. yMaxs.push(metrics.yMax);
  42783. leftSideBearings.push(metrics.leftSideBearing);
  42784. rightSideBearings.push(metrics.rightSideBearing);
  42785. advanceWidths.push(glyph.advanceWidth);
  42786. }
  42787. var globals = {
  42788. xMin: Math.min.apply(null, xMins),
  42789. yMin: Math.min.apply(null, yMins),
  42790. xMax: Math.max.apply(null, xMaxs),
  42791. yMax: Math.max.apply(null, yMaxs),
  42792. advanceWidthMax: Math.max.apply(null, advanceWidths),
  42793. advanceWidthAvg: average(advanceWidths),
  42794. minLeftSideBearing: Math.min.apply(null, leftSideBearings),
  42795. maxLeftSideBearing: Math.max.apply(null, leftSideBearings),
  42796. minRightSideBearing: Math.min.apply(null, rightSideBearings)
  42797. };
  42798. globals.ascender = font.ascender;
  42799. globals.descender = font.descender;
  42800. var headTable = head.make({
  42801. flags: 3, // 00000011 (baseline for font at y=0; left sidebearing point at x=0)
  42802. unitsPerEm: font.unitsPerEm,
  42803. xMin: globals.xMin,
  42804. yMin: globals.yMin,
  42805. xMax: globals.xMax,
  42806. yMax: globals.yMax,
  42807. lowestRecPPEM: 3,
  42808. createdTimestamp: font.createdTimestamp
  42809. });
  42810. var hheaTable = hhea.make({
  42811. ascender: globals.ascender,
  42812. descender: globals.descender,
  42813. advanceWidthMax: globals.advanceWidthMax,
  42814. minLeftSideBearing: globals.minLeftSideBearing,
  42815. minRightSideBearing: globals.minRightSideBearing,
  42816. xMaxExtent: globals.maxLeftSideBearing + (globals.xMax - globals.xMin),
  42817. numberOfHMetrics: font.glyphs.length
  42818. });
  42819. var maxpTable = maxp.make(font.glyphs.length);
  42820. var os2Table = os2.make({
  42821. xAvgCharWidth: Math.round(globals.advanceWidthAvg),
  42822. usWeightClass: font.tables.os2.usWeightClass,
  42823. usWidthClass: font.tables.os2.usWidthClass,
  42824. usFirstCharIndex: firstCharIndex,
  42825. usLastCharIndex: lastCharIndex,
  42826. ulUnicodeRange1: ulUnicodeRange1,
  42827. ulUnicodeRange2: ulUnicodeRange2,
  42828. ulUnicodeRange3: ulUnicodeRange3,
  42829. ulUnicodeRange4: ulUnicodeRange4,
  42830. fsSelection: font.tables.os2.fsSelection, // REGULAR
  42831. // See http://typophile.com/node/13081 for more info on vertical metrics.
  42832. // We get metrics for typical characters (such as "x" for xHeight).
  42833. // We provide some fallback characters if characters are unavailable: their
  42834. // ordering was chosen experimentally.
  42835. sTypoAscender: globals.ascender,
  42836. sTypoDescender: globals.descender,
  42837. sTypoLineGap: 0,
  42838. usWinAscent: globals.yMax,
  42839. usWinDescent: Math.abs(globals.yMin),
  42840. ulCodePageRange1: 1, // FIXME: hard-code Latin 1 support for now
  42841. sxHeight: metricsForChar(font, 'xyvw', {
  42842. yMax: Math.round(globals.ascender / 2)
  42843. }).yMax,
  42844. sCapHeight: metricsForChar(font, 'HIKLEFJMNTZBDPRAGOQSUVWXY', globals)
  42845. .yMax,
  42846. usDefaultChar: font.hasChar(' ') ? 32 : 0, // Use space as the default character, if available.
  42847. usBreakChar: font.hasChar(' ') ? 32 : 0 // Use space as the break character, if available.
  42848. });
  42849. var hmtxTable = hmtx.make(font.glyphs);
  42850. var cmapTable = cmap.make(font.glyphs);
  42851. var englishFamilyName = font.getEnglishName('fontFamily');
  42852. var englishStyleName = font.getEnglishName('fontSubfamily');
  42853. var englishFullName = englishFamilyName + ' ' + englishStyleName;
  42854. var postScriptName = font.getEnglishName('postScriptName');
  42855. if (!postScriptName) {
  42856. postScriptName =
  42857. englishFamilyName.replace(/\s/g, '') + '-' + englishStyleName;
  42858. }
  42859. var names = {};
  42860. for (var n in font.names) {
  42861. names[n] = font.names[n];
  42862. }
  42863. if (!names.uniqueID) {
  42864. names.uniqueID = {
  42865. en: font.getEnglishName('manufacturer') + ':' + englishFullName
  42866. };
  42867. }
  42868. if (!names.postScriptName) {
  42869. names.postScriptName = { en: postScriptName };
  42870. }
  42871. if (!names.preferredFamily) {
  42872. names.preferredFamily = font.names.fontFamily;
  42873. }
  42874. if (!names.preferredSubfamily) {
  42875. names.preferredSubfamily = font.names.fontSubfamily;
  42876. }
  42877. var languageTags = [];
  42878. var nameTable = _name.make(names, languageTags);
  42879. var ltagTable =
  42880. languageTags.length > 0 ? ltag.make(languageTags) : undefined;
  42881. var postTable = post.make();
  42882. var cffTable = cff.make(font.glyphs, {
  42883. version: font.getEnglishName('version'),
  42884. fullName: englishFullName,
  42885. familyName: englishFamilyName,
  42886. weightName: englishStyleName,
  42887. postScriptName: postScriptName,
  42888. unitsPerEm: font.unitsPerEm,
  42889. fontBBox: [0, globals.yMin, globals.ascender, globals.advanceWidthMax]
  42890. });
  42891. var metaTable =
  42892. font.metas && Object.keys(font.metas).length > 0
  42893. ? meta.make(font.metas)
  42894. : undefined;
  42895. // The order does not matter because makeSfntTable() will sort them.
  42896. var tables = [
  42897. headTable,
  42898. hheaTable,
  42899. maxpTable,
  42900. os2Table,
  42901. nameTable,
  42902. cmapTable,
  42903. postTable,
  42904. cffTable,
  42905. hmtxTable
  42906. ];
  42907. if (ltagTable) {
  42908. tables.push(ltagTable);
  42909. }
  42910. // Optional tables
  42911. if (font.tables.gsub) {
  42912. tables.push(gsub.make(font.tables.gsub));
  42913. }
  42914. if (metaTable) {
  42915. tables.push(metaTable);
  42916. }
  42917. var sfntTable = makeSfntTable(tables);
  42918. // Compute the font's checkSum and store it in head.checkSumAdjustment.
  42919. var bytes = sfntTable.encode();
  42920. var checkSum = computeCheckSum(bytes);
  42921. var tableFields = sfntTable.fields;
  42922. var checkSumAdjusted = false;
  42923. for (var i$1 = 0; i$1 < tableFields.length; i$1 += 1) {
  42924. if (tableFields[i$1].name === 'head table') {
  42925. tableFields[i$1].value.checkSumAdjustment = 0xb1b0afba - checkSum;
  42926. checkSumAdjusted = true;
  42927. break;
  42928. }
  42929. }
  42930. if (!checkSumAdjusted) {
  42931. throw new Error('Could not find head table with checkSum to adjust.');
  42932. }
  42933. return sfntTable;
  42934. }
  42935. var sfnt = {
  42936. make: makeSfntTable,
  42937. fontToTable: fontToSfntTable,
  42938. computeCheckSum: computeCheckSum
  42939. };
  42940. // The Layout object is the prototype of Substitution objects, and provides
  42941. function searchTag(arr, tag) {
  42942. /* jshint bitwise: false */
  42943. var imin = 0;
  42944. var imax = arr.length - 1;
  42945. while (imin <= imax) {
  42946. var imid = (imin + imax) >>> 1;
  42947. var val = arr[imid].tag;
  42948. if (val === tag) {
  42949. return imid;
  42950. } else if (val < tag) {
  42951. imin = imid + 1;
  42952. } else {
  42953. imax = imid - 1;
  42954. }
  42955. }
  42956. // Not found: return -1-insertion point
  42957. return -imin - 1;
  42958. }
  42959. function binSearch(arr, value) {
  42960. /* jshint bitwise: false */
  42961. var imin = 0;
  42962. var imax = arr.length - 1;
  42963. while (imin <= imax) {
  42964. var imid = (imin + imax) >>> 1;
  42965. var val = arr[imid];
  42966. if (val === value) {
  42967. return imid;
  42968. } else if (val < value) {
  42969. imin = imid + 1;
  42970. } else {
  42971. imax = imid - 1;
  42972. }
  42973. }
  42974. // Not found: return -1-insertion point
  42975. return -imin - 1;
  42976. }
  42977. // binary search in a list of ranges (coverage, class definition)
  42978. function searchRange(ranges, value) {
  42979. // jshint bitwise: false
  42980. var range;
  42981. var imin = 0;
  42982. var imax = ranges.length - 1;
  42983. while (imin <= imax) {
  42984. var imid = (imin + imax) >>> 1;
  42985. range = ranges[imid];
  42986. var start = range.start;
  42987. if (start === value) {
  42988. return range;
  42989. } else if (start < value) {
  42990. imin = imid + 1;
  42991. } else {
  42992. imax = imid - 1;
  42993. }
  42994. }
  42995. if (imin > 0) {
  42996. range = ranges[imin - 1];
  42997. if (value > range.end) {
  42998. return 0;
  42999. }
  43000. return range;
  43001. }
  43002. }
  43003. /**
  43004. * @exports opentype.Layout
  43005. * @class
  43006. */
  43007. function Layout(font, tableName) {
  43008. this.font = font;
  43009. this.tableName = tableName;
  43010. }
  43011. Layout.prototype = {
  43012. /**
  43013. * Binary search an object by "tag" property
  43014. * @instance
  43015. * @function searchTag
  43016. * @memberof opentype.Layout
  43017. * @param {Array} arr
  43018. * @param {string} tag
  43019. * @return {number}
  43020. */
  43021. searchTag: searchTag,
  43022. /**
  43023. * Binary search in a list of numbers
  43024. * @instance
  43025. * @function binSearch
  43026. * @memberof opentype.Layout
  43027. * @param {Array} arr
  43028. * @param {number} value
  43029. * @return {number}
  43030. */
  43031. binSearch: binSearch,
  43032. /**
  43033. * Get or create the Layout table (GSUB, GPOS etc).
  43034. * @param {boolean} create - Whether to create a new one.
  43035. * @return {Object} The GSUB or GPOS table.
  43036. */
  43037. getTable: function(create) {
  43038. var layout = this.font.tables[this.tableName];
  43039. if (!layout && create) {
  43040. layout = this.font.tables[this.tableName] = this.createDefaultTable();
  43041. }
  43042. return layout;
  43043. },
  43044. /**
  43045. * Returns all scripts in the substitution table.
  43046. * @instance
  43047. * @return {Array}
  43048. */
  43049. getScriptNames: function() {
  43050. var layout = this.getTable();
  43051. if (!layout) {
  43052. return [];
  43053. }
  43054. return layout.scripts.map(function(script) {
  43055. return script.tag;
  43056. });
  43057. },
  43058. /**
  43059. * Returns the best bet for a script name.
  43060. * Returns 'DFLT' if it exists.
  43061. * If not, returns 'latn' if it exists.
  43062. * If neither exist, returns undefined.
  43063. */
  43064. getDefaultScriptName: function() {
  43065. var layout = this.getTable();
  43066. if (!layout) {
  43067. return;
  43068. }
  43069. var hasLatn = false;
  43070. for (var i = 0; i < layout.scripts.length; i++) {
  43071. var name = layout.scripts[i].tag;
  43072. if (name === 'DFLT') {
  43073. return name;
  43074. }
  43075. if (name === 'latn') {
  43076. hasLatn = true;
  43077. }
  43078. }
  43079. if (hasLatn) {
  43080. return 'latn';
  43081. }
  43082. },
  43083. /**
  43084. * Returns all LangSysRecords in the given script.
  43085. * @instance
  43086. * @param {string} [script='DFLT']
  43087. * @param {boolean} create - forces the creation of this script table if it doesn't exist.
  43088. * @return {Object} An object with tag and script properties.
  43089. */
  43090. getScriptTable: function(script, create) {
  43091. var layout = this.getTable(create);
  43092. if (layout) {
  43093. script = script || 'DFLT';
  43094. var scripts = layout.scripts;
  43095. var pos = searchTag(layout.scripts, script);
  43096. if (pos >= 0) {
  43097. return scripts[pos].script;
  43098. } else if (create) {
  43099. var scr = {
  43100. tag: script,
  43101. script: {
  43102. defaultLangSys: {
  43103. reserved: 0,
  43104. reqFeatureIndex: 0xffff,
  43105. featureIndexes: []
  43106. },
  43107. langSysRecords: []
  43108. }
  43109. };
  43110. scripts.splice(-1 - pos, 0, scr);
  43111. return scr.script;
  43112. }
  43113. }
  43114. },
  43115. /**
  43116. * Returns a language system table
  43117. * @instance
  43118. * @param {string} [script='DFLT']
  43119. * @param {string} [language='dlft']
  43120. * @param {boolean} create - forces the creation of this langSysTable if it doesn't exist.
  43121. * @return {Object}
  43122. */
  43123. getLangSysTable: function(script, language, create) {
  43124. var scriptTable = this.getScriptTable(script, create);
  43125. if (scriptTable) {
  43126. if (!language || language === 'dflt' || language === 'DFLT') {
  43127. return scriptTable.defaultLangSys;
  43128. }
  43129. var pos = searchTag(scriptTable.langSysRecords, language);
  43130. if (pos >= 0) {
  43131. return scriptTable.langSysRecords[pos].langSys;
  43132. } else if (create) {
  43133. var langSysRecord = {
  43134. tag: language,
  43135. langSys: {
  43136. reserved: 0,
  43137. reqFeatureIndex: 0xffff,
  43138. featureIndexes: []
  43139. }
  43140. };
  43141. scriptTable.langSysRecords.splice(-1 - pos, 0, langSysRecord);
  43142. return langSysRecord.langSys;
  43143. }
  43144. }
  43145. },
  43146. /**
  43147. * Get a specific feature table.
  43148. * @instance
  43149. * @param {string} [script='DFLT']
  43150. * @param {string} [language='dlft']
  43151. * @param {string} feature - One of the codes listed at https://www.microsoft.com/typography/OTSPEC/featurelist.htm
  43152. * @param {boolean} create - forces the creation of the feature table if it doesn't exist.
  43153. * @return {Object}
  43154. */
  43155. getFeatureTable: function(script, language, feature, create) {
  43156. var langSysTable = this.getLangSysTable(script, language, create);
  43157. if (langSysTable) {
  43158. var featureRecord;
  43159. var featIndexes = langSysTable.featureIndexes;
  43160. var allFeatures = this.font.tables[this.tableName].features;
  43161. // The FeatureIndex array of indices is in arbitrary order,
  43162. // even if allFeatures is sorted alphabetically by feature tag.
  43163. for (var i = 0; i < featIndexes.length; i++) {
  43164. featureRecord = allFeatures[featIndexes[i]];
  43165. if (featureRecord.tag === feature) {
  43166. return featureRecord.feature;
  43167. }
  43168. }
  43169. if (create) {
  43170. var index = allFeatures.length;
  43171. // Automatic ordering of features would require to shift feature indexes in the script list.
  43172. check.assert(
  43173. index === 0 || feature >= allFeatures[index - 1].tag,
  43174. 'Features must be added in alphabetical order.'
  43175. );
  43176. featureRecord = {
  43177. tag: feature,
  43178. feature: { params: 0, lookupListIndexes: [] }
  43179. };
  43180. allFeatures.push(featureRecord);
  43181. featIndexes.push(index);
  43182. return featureRecord.feature;
  43183. }
  43184. }
  43185. },
  43186. /**
  43187. * Get the lookup tables of a given type for a script/language/feature.
  43188. * @instance
  43189. * @param {string} [script='DFLT']
  43190. * @param {string} [language='dlft']
  43191. * @param {string} feature - 4-letter feature code
  43192. * @param {number} lookupType - 1 to 9
  43193. * @param {boolean} create - forces the creation of the lookup table if it doesn't exist, with no subtables.
  43194. * @return {Object[]}
  43195. */
  43196. getLookupTables: function(script, language, feature, lookupType, create) {
  43197. var featureTable = this.getFeatureTable(
  43198. script,
  43199. language,
  43200. feature,
  43201. create
  43202. );
  43203. var tables = [];
  43204. if (featureTable) {
  43205. var lookupTable;
  43206. var lookupListIndexes = featureTable.lookupListIndexes;
  43207. var allLookups = this.font.tables[this.tableName].lookups;
  43208. // lookupListIndexes are in no particular order, so use naive search.
  43209. for (var i = 0; i < lookupListIndexes.length; i++) {
  43210. lookupTable = allLookups[lookupListIndexes[i]];
  43211. if (lookupTable.lookupType === lookupType) {
  43212. tables.push(lookupTable);
  43213. }
  43214. }
  43215. if (tables.length === 0 && create) {
  43216. lookupTable = {
  43217. lookupType: lookupType,
  43218. lookupFlag: 0,
  43219. subtables: [],
  43220. markFilteringSet: undefined
  43221. };
  43222. var index = allLookups.length;
  43223. allLookups.push(lookupTable);
  43224. lookupListIndexes.push(index);
  43225. return [lookupTable];
  43226. }
  43227. }
  43228. return tables;
  43229. },
  43230. /**
  43231. * Find a glyph in a class definition table
  43232. * https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#class-definition-table
  43233. * @param {object} classDefTable - an OpenType Layout class definition table
  43234. * @param {number} glyphIndex - the index of the glyph to find
  43235. * @returns {number} -1 if not found
  43236. */
  43237. getGlyphClass: function(classDefTable, glyphIndex) {
  43238. switch (classDefTable.format) {
  43239. case 1:
  43240. if (
  43241. classDefTable.startGlyph <= glyphIndex &&
  43242. glyphIndex < classDefTable.startGlyph + classDefTable.classes.length
  43243. ) {
  43244. return classDefTable.classes[glyphIndex - classDefTable.startGlyph];
  43245. }
  43246. return 0;
  43247. case 2:
  43248. var range = searchRange(classDefTable.ranges, glyphIndex);
  43249. return range ? range.classId : 0;
  43250. }
  43251. },
  43252. /**
  43253. * Find a glyph in a coverage table
  43254. * https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#coverage-table
  43255. * @param {object} coverageTable - an OpenType Layout coverage table
  43256. * @param {number} glyphIndex - the index of the glyph to find
  43257. * @returns {number} -1 if not found
  43258. */
  43259. getCoverageIndex: function(coverageTable, glyphIndex) {
  43260. switch (coverageTable.format) {
  43261. case 1:
  43262. var index = binSearch(coverageTable.glyphs, glyphIndex);
  43263. return index >= 0 ? index : -1;
  43264. case 2:
  43265. var range = searchRange(coverageTable.ranges, glyphIndex);
  43266. return range ? range.index + glyphIndex - range.start : -1;
  43267. }
  43268. },
  43269. /**
  43270. * Returns the list of glyph indexes of a coverage table.
  43271. * Format 1: the list is stored raw
  43272. * Format 2: compact list as range records.
  43273. * @instance
  43274. * @param {Object} coverageTable
  43275. * @return {Array}
  43276. */
  43277. expandCoverage: function(coverageTable) {
  43278. if (coverageTable.format === 1) {
  43279. return coverageTable.glyphs;
  43280. } else {
  43281. var glyphs = [];
  43282. var ranges = coverageTable.ranges;
  43283. for (var i = 0; i < ranges.length; i++) {
  43284. var range = ranges[i];
  43285. var start = range.start;
  43286. var end = range.end;
  43287. for (var j = start; j <= end; j++) {
  43288. glyphs.push(j);
  43289. }
  43290. }
  43291. return glyphs;
  43292. }
  43293. }
  43294. };
  43295. // The Position object provides utility methods to manipulate
  43296. /**
  43297. * @exports opentype.Position
  43298. * @class
  43299. * @extends opentype.Layout
  43300. * @param {opentype.Font}
  43301. * @constructor
  43302. */
  43303. function Position(font) {
  43304. Layout.call(this, font, 'gpos');
  43305. }
  43306. Position.prototype = Layout.prototype;
  43307. /**
  43308. * Init some data for faster and easier access later.
  43309. */
  43310. Position.prototype.init = function() {
  43311. var script = this.getDefaultScriptName();
  43312. this.defaultKerningTables = this.getKerningTables(script);
  43313. };
  43314. /**
  43315. * Find a glyph pair in a list of lookup tables of type 2 and retrieve the xAdvance kerning value.
  43316. *
  43317. * @param {integer} leftIndex - left glyph index
  43318. * @param {integer} rightIndex - right glyph index
  43319. * @returns {integer}
  43320. */
  43321. Position.prototype.getKerningValue = function(
  43322. kerningLookups,
  43323. leftIndex,
  43324. rightIndex
  43325. ) {
  43326. var this$1 = this;
  43327. for (var i = 0; i < kerningLookups.length; i++) {
  43328. var subtables = kerningLookups[i].subtables;
  43329. for (var j = 0; j < subtables.length; j++) {
  43330. var subtable = subtables[j];
  43331. var covIndex = this$1.getCoverageIndex(subtable.coverage, leftIndex);
  43332. if (covIndex < 0) {
  43333. continue;
  43334. }
  43335. switch (subtable.posFormat) {
  43336. case 1:
  43337. // Search Pair Adjustment Positioning Format 1
  43338. var pairSet = subtable.pairSets[covIndex];
  43339. for (var k = 0; k < pairSet.length; k++) {
  43340. var pair = pairSet[k];
  43341. if (pair.secondGlyph === rightIndex) {
  43342. return (pair.value1 && pair.value1.xAdvance) || 0;
  43343. }
  43344. }
  43345. break; // left glyph found, not right glyph - try next subtable
  43346. case 2:
  43347. // Search Pair Adjustment Positioning Format 2
  43348. var class1 = this$1.getGlyphClass(subtable.classDef1, leftIndex);
  43349. var class2 = this$1.getGlyphClass(subtable.classDef2, rightIndex);
  43350. var pair$1 = subtable.classRecords[class1][class2];
  43351. return (pair$1.value1 && pair$1.value1.xAdvance) || 0;
  43352. }
  43353. }
  43354. }
  43355. return 0;
  43356. };
  43357. /**
  43358. * List all kerning lookup tables.
  43359. *
  43360. * @param {string} [script='DFLT'] - use font.position.getDefaultScriptName() for a better default value
  43361. * @param {string} [language='dflt']
  43362. * @return {object[]} The list of kerning lookup tables (may be empty), or undefined if there is no GPOS table (and we should use the kern table)
  43363. */
  43364. Position.prototype.getKerningTables = function(script, language) {
  43365. if (this.font.tables.gpos) {
  43366. return this.getLookupTables(script, language, 'kern', 2);
  43367. }
  43368. };
  43369. // The Substitution object provides utility methods to manipulate
  43370. /**
  43371. * @exports opentype.Substitution
  43372. * @class
  43373. * @extends opentype.Layout
  43374. * @param {opentype.Font}
  43375. * @constructor
  43376. */
  43377. function Substitution(font) {
  43378. Layout.call(this, font, 'gsub');
  43379. }
  43380. // Check if 2 arrays of primitives are equal.
  43381. function arraysEqual(ar1, ar2) {
  43382. var n = ar1.length;
  43383. if (n !== ar2.length) {
  43384. return false;
  43385. }
  43386. for (var i = 0; i < n; i++) {
  43387. if (ar1[i] !== ar2[i]) {
  43388. return false;
  43389. }
  43390. }
  43391. return true;
  43392. }
  43393. // Find the first subtable of a lookup table in a particular format.
  43394. function getSubstFormat(lookupTable, format, defaultSubtable) {
  43395. var subtables = lookupTable.subtables;
  43396. for (var i = 0; i < subtables.length; i++) {
  43397. var subtable = subtables[i];
  43398. if (subtable.substFormat === format) {
  43399. return subtable;
  43400. }
  43401. }
  43402. if (defaultSubtable) {
  43403. subtables.push(defaultSubtable);
  43404. return defaultSubtable;
  43405. }
  43406. return undefined;
  43407. }
  43408. Substitution.prototype = Layout.prototype;
  43409. /**
  43410. * Create a default GSUB table.
  43411. * @return {Object} gsub - The GSUB table.
  43412. */
  43413. Substitution.prototype.createDefaultTable = function() {
  43414. // Generate a default empty GSUB table with just a DFLT script and dflt lang sys.
  43415. return {
  43416. version: 1,
  43417. scripts: [
  43418. {
  43419. tag: 'DFLT',
  43420. script: {
  43421. defaultLangSys: {
  43422. reserved: 0,
  43423. reqFeatureIndex: 0xffff,
  43424. featureIndexes: []
  43425. },
  43426. langSysRecords: []
  43427. }
  43428. }
  43429. ],
  43430. features: [],
  43431. lookups: []
  43432. };
  43433. };
  43434. /**
  43435. * List all single substitutions (lookup type 1) for a given script, language, and feature.
  43436. * @param {string} [script='DFLT']
  43437. * @param {string} [language='dflt']
  43438. * @param {string} feature - 4-character feature name ('aalt', 'salt', 'ss01'...)
  43439. * @return {Array} substitutions - The list of substitutions.
  43440. */
  43441. Substitution.prototype.getSingle = function(feature, script, language) {
  43442. var this$1 = this;
  43443. var substitutions = [];
  43444. var lookupTables = this.getLookupTables(script, language, feature, 1);
  43445. for (var idx = 0; idx < lookupTables.length; idx++) {
  43446. var subtables = lookupTables[idx].subtables;
  43447. for (var i = 0; i < subtables.length; i++) {
  43448. var subtable = subtables[i];
  43449. var glyphs = this$1.expandCoverage(subtable.coverage);
  43450. var j = void 0;
  43451. if (subtable.substFormat === 1) {
  43452. var delta = subtable.deltaGlyphId;
  43453. for (j = 0; j < glyphs.length; j++) {
  43454. var glyph = glyphs[j];
  43455. substitutions.push({ sub: glyph, by: glyph + delta });
  43456. }
  43457. } else {
  43458. var substitute = subtable.substitute;
  43459. for (j = 0; j < glyphs.length; j++) {
  43460. substitutions.push({ sub: glyphs[j], by: substitute[j] });
  43461. }
  43462. }
  43463. }
  43464. }
  43465. return substitutions;
  43466. };
  43467. /**
  43468. * List all alternates (lookup type 3) for a given script, language, and feature.
  43469. * @param {string} [script='DFLT']
  43470. * @param {string} [language='dflt']
  43471. * @param {string} feature - 4-character feature name ('aalt', 'salt'...)
  43472. * @return {Array} alternates - The list of alternates
  43473. */
  43474. Substitution.prototype.getAlternates = function(feature, script, language) {
  43475. var this$1 = this;
  43476. var alternates = [];
  43477. var lookupTables = this.getLookupTables(script, language, feature, 3);
  43478. for (var idx = 0; idx < lookupTables.length; idx++) {
  43479. var subtables = lookupTables[idx].subtables;
  43480. for (var i = 0; i < subtables.length; i++) {
  43481. var subtable = subtables[i];
  43482. var glyphs = this$1.expandCoverage(subtable.coverage);
  43483. var alternateSets = subtable.alternateSets;
  43484. for (var j = 0; j < glyphs.length; j++) {
  43485. alternates.push({ sub: glyphs[j], by: alternateSets[j] });
  43486. }
  43487. }
  43488. }
  43489. return alternates;
  43490. };
  43491. /**
  43492. * List all ligatures (lookup type 4) for a given script, language, and feature.
  43493. * The result is an array of ligature objects like { sub: [ids], by: id }
  43494. * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...)
  43495. * @param {string} [script='DFLT']
  43496. * @param {string} [language='dflt']
  43497. * @return {Array} ligatures - The list of ligatures.
  43498. */
  43499. Substitution.prototype.getLigatures = function(feature, script, language) {
  43500. var this$1 = this;
  43501. var ligatures = [];
  43502. var lookupTables = this.getLookupTables(script, language, feature, 4);
  43503. for (var idx = 0; idx < lookupTables.length; idx++) {
  43504. var subtables = lookupTables[idx].subtables;
  43505. for (var i = 0; i < subtables.length; i++) {
  43506. var subtable = subtables[i];
  43507. var glyphs = this$1.expandCoverage(subtable.coverage);
  43508. var ligatureSets = subtable.ligatureSets;
  43509. for (var j = 0; j < glyphs.length; j++) {
  43510. var startGlyph = glyphs[j];
  43511. var ligSet = ligatureSets[j];
  43512. for (var k = 0; k < ligSet.length; k++) {
  43513. var lig = ligSet[k];
  43514. ligatures.push({
  43515. sub: [startGlyph].concat(lig.components),
  43516. by: lig.ligGlyph
  43517. });
  43518. }
  43519. }
  43520. }
  43521. }
  43522. return ligatures;
  43523. };
  43524. /**
  43525. * Add or modify a single substitution (lookup type 1)
  43526. * Format 2, more flexible, is always used.
  43527. * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...)
  43528. * @param {Object} substitution - { sub: id, delta: number } for format 1 or { sub: id, by: id } for format 2.
  43529. * @param {string} [script='DFLT']
  43530. * @param {string} [language='dflt']
  43531. */
  43532. Substitution.prototype.addSingle = function(
  43533. feature,
  43534. substitution,
  43535. script,
  43536. language
  43537. ) {
  43538. var lookupTable = this.getLookupTables(
  43539. script,
  43540. language,
  43541. feature,
  43542. 1,
  43543. true
  43544. )[0];
  43545. var subtable = getSubstFormat(lookupTable, 2, {
  43546. // lookup type 1 subtable, format 2, coverage format 1
  43547. substFormat: 2,
  43548. coverage: { format: 1, glyphs: [] },
  43549. substitute: []
  43550. });
  43551. check.assert(
  43552. subtable.coverage.format === 1,
  43553. 'Ligature: unable to modify coverage table format ' +
  43554. subtable.coverage.format
  43555. );
  43556. var coverageGlyph = substitution.sub;
  43557. var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);
  43558. if (pos < 0) {
  43559. pos = -1 - pos;
  43560. subtable.coverage.glyphs.splice(pos, 0, coverageGlyph);
  43561. subtable.substitute.splice(pos, 0, 0);
  43562. }
  43563. subtable.substitute[pos] = substitution.by;
  43564. };
  43565. /**
  43566. * Add or modify an alternate substitution (lookup type 1)
  43567. * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...)
  43568. * @param {Object} substitution - { sub: id, by: [ids] }
  43569. * @param {string} [script='DFLT']
  43570. * @param {string} [language='dflt']
  43571. */
  43572. Substitution.prototype.addAlternate = function(
  43573. feature,
  43574. substitution,
  43575. script,
  43576. language
  43577. ) {
  43578. var lookupTable = this.getLookupTables(
  43579. script,
  43580. language,
  43581. feature,
  43582. 3,
  43583. true
  43584. )[0];
  43585. var subtable = getSubstFormat(lookupTable, 1, {
  43586. // lookup type 3 subtable, format 1, coverage format 1
  43587. substFormat: 1,
  43588. coverage: { format: 1, glyphs: [] },
  43589. alternateSets: []
  43590. });
  43591. check.assert(
  43592. subtable.coverage.format === 1,
  43593. 'Ligature: unable to modify coverage table format ' +
  43594. subtable.coverage.format
  43595. );
  43596. var coverageGlyph = substitution.sub;
  43597. var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);
  43598. if (pos < 0) {
  43599. pos = -1 - pos;
  43600. subtable.coverage.glyphs.splice(pos, 0, coverageGlyph);
  43601. subtable.alternateSets.splice(pos, 0, 0);
  43602. }
  43603. subtable.alternateSets[pos] = substitution.by;
  43604. };
  43605. /**
  43606. * Add a ligature (lookup type 4)
  43607. * Ligatures with more components must be stored ahead of those with fewer components in order to be found
  43608. * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...)
  43609. * @param {Object} ligature - { sub: [ids], by: id }
  43610. * @param {string} [script='DFLT']
  43611. * @param {string} [language='dflt']
  43612. */
  43613. Substitution.prototype.addLigature = function(
  43614. feature,
  43615. ligature,
  43616. script,
  43617. language
  43618. ) {
  43619. var lookupTable = this.getLookupTables(
  43620. script,
  43621. language,
  43622. feature,
  43623. 4,
  43624. true
  43625. )[0];
  43626. var subtable = lookupTable.subtables[0];
  43627. if (!subtable) {
  43628. subtable = {
  43629. // lookup type 4 subtable, format 1, coverage format 1
  43630. substFormat: 1,
  43631. coverage: { format: 1, glyphs: [] },
  43632. ligatureSets: []
  43633. };
  43634. lookupTable.subtables[0] = subtable;
  43635. }
  43636. check.assert(
  43637. subtable.coverage.format === 1,
  43638. 'Ligature: unable to modify coverage table format ' +
  43639. subtable.coverage.format
  43640. );
  43641. var coverageGlyph = ligature.sub[0];
  43642. var ligComponents = ligature.sub.slice(1);
  43643. var ligatureTable = {
  43644. ligGlyph: ligature.by,
  43645. components: ligComponents
  43646. };
  43647. var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);
  43648. if (pos >= 0) {
  43649. // ligatureSet already exists
  43650. var ligatureSet = subtable.ligatureSets[pos];
  43651. for (var i = 0; i < ligatureSet.length; i++) {
  43652. // If ligature already exists, return.
  43653. if (arraysEqual(ligatureSet[i].components, ligComponents)) {
  43654. return;
  43655. }
  43656. }
  43657. // ligature does not exist: add it.
  43658. ligatureSet.push(ligatureTable);
  43659. } else {
  43660. // Create a new ligatureSet and add coverage for the first glyph.
  43661. pos = -1 - pos;
  43662. subtable.coverage.glyphs.splice(pos, 0, coverageGlyph);
  43663. subtable.ligatureSets.splice(pos, 0, [ligatureTable]);
  43664. }
  43665. };
  43666. /**
  43667. * List all feature data for a given script and language.
  43668. * @param {string} feature - 4-letter feature name
  43669. * @param {string} [script='DFLT']
  43670. * @param {string} [language='dflt']
  43671. * @return {Array} substitutions - The list of substitutions.
  43672. */
  43673. Substitution.prototype.getFeature = function(feature, script, language) {
  43674. if (/ss\d\d/.test(feature)) {
  43675. // ss01 - ss20
  43676. return this.getSingle(feature, script, language);
  43677. }
  43678. switch (feature) {
  43679. case 'aalt':
  43680. case 'salt':
  43681. return this.getSingle(feature, script, language).concat(
  43682. this.getAlternates(feature, script, language)
  43683. );
  43684. case 'dlig':
  43685. case 'liga':
  43686. case 'rlig':
  43687. return this.getLigatures(feature, script, language);
  43688. }
  43689. return undefined;
  43690. };
  43691. /**
  43692. * Add a substitution to a feature for a given script and language.
  43693. * @param {string} feature - 4-letter feature name
  43694. * @param {Object} sub - the substitution to add (an object like { sub: id or [ids], by: id or [ids] })
  43695. * @param {string} [script='DFLT']
  43696. * @param {string} [language='dflt']
  43697. */
  43698. Substitution.prototype.add = function(feature, sub, script, language) {
  43699. if (/ss\d\d/.test(feature)) {
  43700. // ss01 - ss20
  43701. return this.addSingle(feature, sub, script, language);
  43702. }
  43703. switch (feature) {
  43704. case 'aalt':
  43705. case 'salt':
  43706. if (typeof sub.by === 'number') {
  43707. return this.addSingle(feature, sub, script, language);
  43708. }
  43709. return this.addAlternate(feature, sub, script, language);
  43710. case 'dlig':
  43711. case 'liga':
  43712. case 'rlig':
  43713. return this.addLigature(feature, sub, script, language);
  43714. }
  43715. return undefined;
  43716. };
  43717. function isBrowser() {
  43718. return typeof window !== 'undefined';
  43719. }
  43720. function nodeBufferToArrayBuffer(buffer) {
  43721. var ab = new ArrayBuffer(buffer.length);
  43722. var view = new Uint8Array(ab);
  43723. for (var i = 0; i < buffer.length; ++i) {
  43724. view[i] = buffer[i];
  43725. }
  43726. return ab;
  43727. }
  43728. function arrayBufferToNodeBuffer(ab) {
  43729. var buffer = new Buffer(ab.byteLength);
  43730. var view = new Uint8Array(ab);
  43731. for (var i = 0; i < buffer.length; ++i) {
  43732. buffer[i] = view[i];
  43733. }
  43734. return buffer;
  43735. }
  43736. function checkArgument(expression, message) {
  43737. if (!expression) {
  43738. throw message;
  43739. }
  43740. }
  43741. // The `glyf` table describes the glyphs in TrueType outline format.
  43742. // Parse the coordinate data for a glyph.
  43743. function parseGlyphCoordinate(
  43744. p,
  43745. flag,
  43746. previousValue,
  43747. shortVectorBitMask,
  43748. sameBitMask
  43749. ) {
  43750. var v;
  43751. if ((flag & shortVectorBitMask) > 0) {
  43752. // The coordinate is 1 byte long.
  43753. v = p.parseByte();
  43754. // The `same` bit is re-used for short values to signify the sign of the value.
  43755. if ((flag & sameBitMask) === 0) {
  43756. v = -v;
  43757. }
  43758. v = previousValue + v;
  43759. } else {
  43760. // The coordinate is 2 bytes long.
  43761. // If the `same` bit is set, the coordinate is the same as the previous coordinate.
  43762. if ((flag & sameBitMask) > 0) {
  43763. v = previousValue;
  43764. } else {
  43765. // Parse the coordinate as a signed 16-bit delta value.
  43766. v = previousValue + p.parseShort();
  43767. }
  43768. }
  43769. return v;
  43770. }
  43771. // Parse a TrueType glyph.
  43772. function parseGlyph(glyph, data, start) {
  43773. var p = new parse.Parser(data, start);
  43774. glyph.numberOfContours = p.parseShort();
  43775. glyph._xMin = p.parseShort();
  43776. glyph._yMin = p.parseShort();
  43777. glyph._xMax = p.parseShort();
  43778. glyph._yMax = p.parseShort();
  43779. var flags;
  43780. var flag;
  43781. if (glyph.numberOfContours > 0) {
  43782. // This glyph is not a composite.
  43783. var endPointIndices = (glyph.endPointIndices = []);
  43784. for (var i = 0; i < glyph.numberOfContours; i += 1) {
  43785. endPointIndices.push(p.parseUShort());
  43786. }
  43787. glyph.instructionLength = p.parseUShort();
  43788. glyph.instructions = [];
  43789. for (var i$1 = 0; i$1 < glyph.instructionLength; i$1 += 1) {
  43790. glyph.instructions.push(p.parseByte());
  43791. }
  43792. var numberOfCoordinates = endPointIndices[endPointIndices.length - 1] + 1;
  43793. flags = [];
  43794. for (var i$2 = 0; i$2 < numberOfCoordinates; i$2 += 1) {
  43795. flag = p.parseByte();
  43796. flags.push(flag);
  43797. // If bit 3 is set, we repeat this flag n times, where n is the next byte.
  43798. if ((flag & 8) > 0) {
  43799. var repeatCount = p.parseByte();
  43800. for (var j = 0; j < repeatCount; j += 1) {
  43801. flags.push(flag);
  43802. i$2 += 1;
  43803. }
  43804. }
  43805. }
  43806. check.argument(flags.length === numberOfCoordinates, 'Bad flags.');
  43807. if (endPointIndices.length > 0) {
  43808. var points = [];
  43809. var point;
  43810. // X/Y coordinates are relative to the previous point, except for the first point which is relative to 0,0.
  43811. if (numberOfCoordinates > 0) {
  43812. for (var i$3 = 0; i$3 < numberOfCoordinates; i$3 += 1) {
  43813. flag = flags[i$3];
  43814. point = {};
  43815. point.onCurve = !!(flag & 1);
  43816. point.lastPointOfContour = endPointIndices.indexOf(i$3) >= 0;
  43817. points.push(point);
  43818. }
  43819. var px = 0;
  43820. for (var i$4 = 0; i$4 < numberOfCoordinates; i$4 += 1) {
  43821. flag = flags[i$4];
  43822. point = points[i$4];
  43823. point.x = parseGlyphCoordinate(p, flag, px, 2, 16);
  43824. px = point.x;
  43825. }
  43826. var py = 0;
  43827. for (var i$5 = 0; i$5 < numberOfCoordinates; i$5 += 1) {
  43828. flag = flags[i$5];
  43829. point = points[i$5];
  43830. point.y = parseGlyphCoordinate(p, flag, py, 4, 32);
  43831. py = point.y;
  43832. }
  43833. }
  43834. glyph.points = points;
  43835. } else {
  43836. glyph.points = [];
  43837. }
  43838. } else if (glyph.numberOfContours === 0) {
  43839. glyph.points = [];
  43840. } else {
  43841. glyph.isComposite = true;
  43842. glyph.points = [];
  43843. glyph.components = [];
  43844. var moreComponents = true;
  43845. while (moreComponents) {
  43846. flags = p.parseUShort();
  43847. var component = {
  43848. glyphIndex: p.parseUShort(),
  43849. xScale: 1,
  43850. scale01: 0,
  43851. scale10: 0,
  43852. yScale: 1,
  43853. dx: 0,
  43854. dy: 0
  43855. };
  43856. if ((flags & 1) > 0) {
  43857. // The arguments are words
  43858. if ((flags & 2) > 0) {
  43859. // values are offset
  43860. component.dx = p.parseShort();
  43861. component.dy = p.parseShort();
  43862. } else {
  43863. // values are matched points
  43864. component.matchedPoints = [p.parseUShort(), p.parseUShort()];
  43865. }
  43866. } else {
  43867. // The arguments are bytes
  43868. if ((flags & 2) > 0) {
  43869. // values are offset
  43870. component.dx = p.parseChar();
  43871. component.dy = p.parseChar();
  43872. } else {
  43873. // values are matched points
  43874. component.matchedPoints = [p.parseByte(), p.parseByte()];
  43875. }
  43876. }
  43877. if ((flags & 8) > 0) {
  43878. // We have a scale
  43879. component.xScale = component.yScale = p.parseF2Dot14();
  43880. } else if ((flags & 64) > 0) {
  43881. // We have an X / Y scale
  43882. component.xScale = p.parseF2Dot14();
  43883. component.yScale = p.parseF2Dot14();
  43884. } else if ((flags & 128) > 0) {
  43885. // We have a 2x2 transformation
  43886. component.xScale = p.parseF2Dot14();
  43887. component.scale01 = p.parseF2Dot14();
  43888. component.scale10 = p.parseF2Dot14();
  43889. component.yScale = p.parseF2Dot14();
  43890. }
  43891. glyph.components.push(component);
  43892. moreComponents = !!(flags & 32);
  43893. }
  43894. if (flags & 0x100) {
  43895. // We have instructions
  43896. glyph.instructionLength = p.parseUShort();
  43897. glyph.instructions = [];
  43898. for (var i$6 = 0; i$6 < glyph.instructionLength; i$6 += 1) {
  43899. glyph.instructions.push(p.parseByte());
  43900. }
  43901. }
  43902. }
  43903. }
  43904. // Transform an array of points and return a new array.
  43905. function transformPoints(points, transform) {
  43906. var newPoints = [];
  43907. for (var i = 0; i < points.length; i += 1) {
  43908. var pt = points[i];
  43909. var newPt = {
  43910. x: transform.xScale * pt.x + transform.scale01 * pt.y + transform.dx,
  43911. y: transform.scale10 * pt.x + transform.yScale * pt.y + transform.dy,
  43912. onCurve: pt.onCurve,
  43913. lastPointOfContour: pt.lastPointOfContour
  43914. };
  43915. newPoints.push(newPt);
  43916. }
  43917. return newPoints;
  43918. }
  43919. function getContours(points) {
  43920. var contours = [];
  43921. var currentContour = [];
  43922. for (var i = 0; i < points.length; i += 1) {
  43923. var pt = points[i];
  43924. currentContour.push(pt);
  43925. if (pt.lastPointOfContour) {
  43926. contours.push(currentContour);
  43927. currentContour = [];
  43928. }
  43929. }
  43930. check.argument(
  43931. currentContour.length === 0,
  43932. 'There are still points left in the current contour.'
  43933. );
  43934. return contours;
  43935. }
  43936. // Convert the TrueType glyph outline to a Path.
  43937. function getPath(points) {
  43938. var p = new Path();
  43939. if (!points) {
  43940. return p;
  43941. }
  43942. var contours = getContours(points);
  43943. for (var contourIndex = 0; contourIndex < contours.length; ++contourIndex) {
  43944. var contour = contours[contourIndex];
  43945. var prev = null;
  43946. var curr = contour[contour.length - 1];
  43947. var next = contour[0];
  43948. if (curr.onCurve) {
  43949. p.moveTo(curr.x, curr.y);
  43950. } else {
  43951. if (next.onCurve) {
  43952. p.moveTo(next.x, next.y);
  43953. } else {
  43954. // If both first and last points are off-curve, start at their middle.
  43955. var start = {
  43956. x: (curr.x + next.x) * 0.5,
  43957. y: (curr.y + next.y) * 0.5
  43958. };
  43959. p.moveTo(start.x, start.y);
  43960. }
  43961. }
  43962. for (var i = 0; i < contour.length; ++i) {
  43963. prev = curr;
  43964. curr = next;
  43965. next = contour[(i + 1) % contour.length];
  43966. if (curr.onCurve) {
  43967. // This is a straight line.
  43968. p.lineTo(curr.x, curr.y);
  43969. } else {
  43970. var prev2 = prev;
  43971. var next2 = next;
  43972. if (!prev.onCurve) {
  43973. prev2 = { x: (curr.x + prev.x) * 0.5, y: (curr.y + prev.y) * 0.5 };
  43974. }
  43975. if (!next.onCurve) {
  43976. next2 = { x: (curr.x + next.x) * 0.5, y: (curr.y + next.y) * 0.5 };
  43977. }
  43978. p.quadraticCurveTo(curr.x, curr.y, next2.x, next2.y);
  43979. }
  43980. }
  43981. p.closePath();
  43982. }
  43983. return p;
  43984. }
  43985. function buildPath(glyphs, glyph) {
  43986. if (glyph.isComposite) {
  43987. for (var j = 0; j < glyph.components.length; j += 1) {
  43988. var component = glyph.components[j];
  43989. var componentGlyph = glyphs.get(component.glyphIndex);
  43990. // Force the ttfGlyphLoader to parse the glyph.
  43991. componentGlyph.getPath();
  43992. if (componentGlyph.points) {
  43993. var transformedPoints = void 0;
  43994. if (component.matchedPoints === undefined) {
  43995. // component positioned by offset
  43996. transformedPoints = transformPoints(
  43997. componentGlyph.points,
  43998. component
  43999. );
  44000. } else {
  44001. // component positioned by matched points
  44002. if (
  44003. component.matchedPoints[0] > glyph.points.length - 1 ||
  44004. component.matchedPoints[1] > componentGlyph.points.length - 1
  44005. ) {
  44006. throw Error('Matched points out of range in ' + glyph.name);
  44007. }
  44008. var firstPt = glyph.points[component.matchedPoints[0]];
  44009. var secondPt = componentGlyph.points[component.matchedPoints[1]];
  44010. var transform = {
  44011. xScale: component.xScale,
  44012. scale01: component.scale01,
  44013. scale10: component.scale10,
  44014. yScale: component.yScale,
  44015. dx: 0,
  44016. dy: 0
  44017. };
  44018. secondPt = transformPoints([secondPt], transform)[0];
  44019. transform.dx = firstPt.x - secondPt.x;
  44020. transform.dy = firstPt.y - secondPt.y;
  44021. transformedPoints = transformPoints(
  44022. componentGlyph.points,
  44023. transform
  44024. );
  44025. }
  44026. glyph.points = glyph.points.concat(transformedPoints);
  44027. }
  44028. }
  44029. }
  44030. return getPath(glyph.points);
  44031. }
  44032. // Parse all the glyphs according to the offsets from the `loca` table.
  44033. function parseGlyfTable(data, start, loca, font) {
  44034. var glyphs = new glyphset.GlyphSet(font);
  44035. // The last element of the loca table is invalid.
  44036. for (var i = 0; i < loca.length - 1; i += 1) {
  44037. var offset = loca[i];
  44038. var nextOffset = loca[i + 1];
  44039. if (offset !== nextOffset) {
  44040. glyphs.push(
  44041. i,
  44042. glyphset.ttfGlyphLoader(
  44043. font,
  44044. i,
  44045. parseGlyph,
  44046. data,
  44047. start + offset,
  44048. buildPath
  44049. )
  44050. );
  44051. } else {
  44052. glyphs.push(i, glyphset.glyphLoader(font, i));
  44053. }
  44054. }
  44055. return glyphs;
  44056. }
  44057. var glyf = { getPath: getPath, parse: parseGlyfTable };
  44058. /* A TrueType font hinting interpreter.
  44059. *
  44060. * (c) 2017 Axel Kittenberger
  44061. *
  44062. * This interpreter has been implemented according to this documentation:
  44063. * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM05/Chap5.html
  44064. *
  44065. * According to the documentation F24DOT6 values are used for pixels.
  44066. * That means calculation is 1/64 pixel accurate and uses integer operations.
  44067. * However, Javascript has floating point operations by default and only
  44068. * those are available. One could make a case to simulate the 1/64 accuracy
  44069. * exactly by truncating after every division operation
  44070. * (for example with << 0) to get pixel exactly results as other TrueType
  44071. * implementations. It may make sense since some fonts are pixel optimized
  44072. * by hand using DELTAP instructions. The current implementation doesn't
  44073. * and rather uses full floating point precision.
  44074. *
  44075. * xScale, yScale and rotation is currently ignored.
  44076. *
  44077. * A few non-trivial instructions are missing as I didn't encounter yet
  44078. * a font that used them to test a possible implementation.
  44079. *
  44080. * Some fonts seem to use undocumented features regarding the twilight zone.
  44081. * Only some of them are implemented as they were encountered.
  44082. *
  44083. * The exports.DEBUG statements are removed on the minified distribution file.
  44084. */
  44085. var instructionTable;
  44086. var exec;
  44087. var execGlyph;
  44088. var execComponent;
  44089. /*
  44090. * Creates a hinting object.
  44091. *
  44092. * There ought to be exactly one
  44093. * for each truetype font that is used for hinting.
  44094. */
  44095. function Hinting(font) {
  44096. // the font this hinting object is for
  44097. this.font = font;
  44098. this.getCommands = function(hPoints) {
  44099. return glyf.getPath(hPoints).commands;
  44100. };
  44101. // cached states
  44102. this._fpgmState = this._prepState = undefined;
  44103. // errorState
  44104. // 0 ... all okay
  44105. // 1 ... had an error in a glyf,
  44106. // continue working but stop spamming
  44107. // the console
  44108. // 2 ... error at prep, stop hinting at this ppem
  44109. // 3 ... error at fpeg, stop hinting for this font at all
  44110. this._errorState = 0;
  44111. }
  44112. /*
  44113. * Not rounding.
  44114. */
  44115. function roundOff(v) {
  44116. return v;
  44117. }
  44118. /*
  44119. * Rounding to grid.
  44120. */
  44121. function roundToGrid(v) {
  44122. //Rounding in TT is supposed to "symmetrical around zero"
  44123. return Math.sign(v) * Math.round(Math.abs(v));
  44124. }
  44125. /*
  44126. * Rounding to double grid.
  44127. */
  44128. function roundToDoubleGrid(v) {
  44129. return Math.sign(v) * Math.round(Math.abs(v * 2)) / 2;
  44130. }
  44131. /*
  44132. * Rounding to half grid.
  44133. */
  44134. function roundToHalfGrid(v) {
  44135. return Math.sign(v) * (Math.round(Math.abs(v) + 0.5) - 0.5);
  44136. }
  44137. /*
  44138. * Rounding to up to grid.
  44139. */
  44140. function roundUpToGrid(v) {
  44141. return Math.sign(v) * Math.ceil(Math.abs(v));
  44142. }
  44143. /*
  44144. * Rounding to down to grid.
  44145. */
  44146. function roundDownToGrid(v) {
  44147. return Math.sign(v) * Math.floor(Math.abs(v));
  44148. }
  44149. /*
  44150. * Super rounding.
  44151. */
  44152. var roundSuper = function(v) {
  44153. var period = this.srPeriod;
  44154. var phase = this.srPhase;
  44155. var threshold = this.srThreshold;
  44156. var sign = 1;
  44157. if (v < 0) {
  44158. v = -v;
  44159. sign = -1;
  44160. }
  44161. v += threshold - phase;
  44162. v = Math.trunc(v / period) * period;
  44163. v += phase;
  44164. // according to http://xgridfit.sourceforge.net/round.html
  44165. if (v < 0) {
  44166. return phase * sign;
  44167. }
  44168. return v * sign;
  44169. };
  44170. /*
  44171. * Unit vector of x-axis.
  44172. */
  44173. var xUnitVector = {
  44174. x: 1,
  44175. y: 0,
  44176. axis: 'x',
  44177. // Gets the projected distance between two points.
  44178. // o1/o2 ... if true, respective original position is used.
  44179. distance: function(p1, p2, o1, o2) {
  44180. return (o1 ? p1.xo : p1.x) - (o2 ? p2.xo : p2.x);
  44181. },
  44182. // Moves point p so the moved position has the same relative
  44183. // position to the moved positions of rp1 and rp2 than the
  44184. // original positions had.
  44185. //
  44186. // See APPENDIX on INTERPOLATE at the bottom of this file.
  44187. interpolate: function(p, rp1, rp2, pv) {
  44188. var do1;
  44189. var do2;
  44190. var doa1;
  44191. var doa2;
  44192. var dm1;
  44193. var dm2;
  44194. var dt;
  44195. if (!pv || pv === this) {
  44196. do1 = p.xo - rp1.xo;
  44197. do2 = p.xo - rp2.xo;
  44198. dm1 = rp1.x - rp1.xo;
  44199. dm2 = rp2.x - rp2.xo;
  44200. doa1 = Math.abs(do1);
  44201. doa2 = Math.abs(do2);
  44202. dt = doa1 + doa2;
  44203. if (dt === 0) {
  44204. p.x = p.xo + (dm1 + dm2) / 2;
  44205. return;
  44206. }
  44207. p.x = p.xo + (dm1 * doa2 + dm2 * doa1) / dt;
  44208. return;
  44209. }
  44210. do1 = pv.distance(p, rp1, true, true);
  44211. do2 = pv.distance(p, rp2, true, true);
  44212. dm1 = pv.distance(rp1, rp1, false, true);
  44213. dm2 = pv.distance(rp2, rp2, false, true);
  44214. doa1 = Math.abs(do1);
  44215. doa2 = Math.abs(do2);
  44216. dt = doa1 + doa2;
  44217. if (dt === 0) {
  44218. xUnitVector.setRelative(p, p, (dm1 + dm2) / 2, pv, true);
  44219. return;
  44220. }
  44221. xUnitVector.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true);
  44222. },
  44223. // Slope of line normal to this
  44224. normalSlope: Number.NEGATIVE_INFINITY,
  44225. // Sets the point 'p' relative to point 'rp'
  44226. // by the distance 'd'.
  44227. //
  44228. // See APPENDIX on SETRELATIVE at the bottom of this file.
  44229. //
  44230. // p ... point to set
  44231. // rp ... reference point
  44232. // d ... distance on projection vector
  44233. // pv ... projection vector (undefined = this)
  44234. // org ... if true, uses the original position of rp as reference.
  44235. setRelative: function(p, rp, d, pv, org) {
  44236. if (!pv || pv === this) {
  44237. p.x = (org ? rp.xo : rp.x) + d;
  44238. return;
  44239. }
  44240. var rpx = org ? rp.xo : rp.x;
  44241. var rpy = org ? rp.yo : rp.y;
  44242. var rpdx = rpx + d * pv.x;
  44243. var rpdy = rpy + d * pv.y;
  44244. p.x = rpdx + (p.y - rpdy) / pv.normalSlope;
  44245. },
  44246. // Slope of vector line.
  44247. slope: 0,
  44248. // Touches the point p.
  44249. touch: function(p) {
  44250. p.xTouched = true;
  44251. },
  44252. // Tests if a point p is touched.
  44253. touched: function(p) {
  44254. return p.xTouched;
  44255. },
  44256. // Untouches the point p.
  44257. untouch: function(p) {
  44258. p.xTouched = false;
  44259. }
  44260. };
  44261. /*
  44262. * Unit vector of y-axis.
  44263. */
  44264. var yUnitVector = {
  44265. x: 0,
  44266. y: 1,
  44267. axis: 'y',
  44268. // Gets the projected distance between two points.
  44269. // o1/o2 ... if true, respective original position is used.
  44270. distance: function(p1, p2, o1, o2) {
  44271. return (o1 ? p1.yo : p1.y) - (o2 ? p2.yo : p2.y);
  44272. },
  44273. // Moves point p so the moved position has the same relative
  44274. // position to the moved positions of rp1 and rp2 than the
  44275. // original positions had.
  44276. //
  44277. // See APPENDIX on INTERPOLATE at the bottom of this file.
  44278. interpolate: function(p, rp1, rp2, pv) {
  44279. var do1;
  44280. var do2;
  44281. var doa1;
  44282. var doa2;
  44283. var dm1;
  44284. var dm2;
  44285. var dt;
  44286. if (!pv || pv === this) {
  44287. do1 = p.yo - rp1.yo;
  44288. do2 = p.yo - rp2.yo;
  44289. dm1 = rp1.y - rp1.yo;
  44290. dm2 = rp2.y - rp2.yo;
  44291. doa1 = Math.abs(do1);
  44292. doa2 = Math.abs(do2);
  44293. dt = doa1 + doa2;
  44294. if (dt === 0) {
  44295. p.y = p.yo + (dm1 + dm2) / 2;
  44296. return;
  44297. }
  44298. p.y = p.yo + (dm1 * doa2 + dm2 * doa1) / dt;
  44299. return;
  44300. }
  44301. do1 = pv.distance(p, rp1, true, true);
  44302. do2 = pv.distance(p, rp2, true, true);
  44303. dm1 = pv.distance(rp1, rp1, false, true);
  44304. dm2 = pv.distance(rp2, rp2, false, true);
  44305. doa1 = Math.abs(do1);
  44306. doa2 = Math.abs(do2);
  44307. dt = doa1 + doa2;
  44308. if (dt === 0) {
  44309. yUnitVector.setRelative(p, p, (dm1 + dm2) / 2, pv, true);
  44310. return;
  44311. }
  44312. yUnitVector.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true);
  44313. },
  44314. // Slope of line normal to this.
  44315. normalSlope: 0,
  44316. // Sets the point 'p' relative to point 'rp'
  44317. // by the distance 'd'
  44318. //
  44319. // See APPENDIX on SETRELATIVE at the bottom of this file.
  44320. //
  44321. // p ... point to set
  44322. // rp ... reference point
  44323. // d ... distance on projection vector
  44324. // pv ... projection vector (undefined = this)
  44325. // org ... if true, uses the original position of rp as reference.
  44326. setRelative: function(p, rp, d, pv, org) {
  44327. if (!pv || pv === this) {
  44328. p.y = (org ? rp.yo : rp.y) + d;
  44329. return;
  44330. }
  44331. var rpx = org ? rp.xo : rp.x;
  44332. var rpy = org ? rp.yo : rp.y;
  44333. var rpdx = rpx + d * pv.x;
  44334. var rpdy = rpy + d * pv.y;
  44335. p.y = rpdy + pv.normalSlope * (p.x - rpdx);
  44336. },
  44337. // Slope of vector line.
  44338. slope: Number.POSITIVE_INFINITY,
  44339. // Touches the point p.
  44340. touch: function(p) {
  44341. p.yTouched = true;
  44342. },
  44343. // Tests if a point p is touched.
  44344. touched: function(p) {
  44345. return p.yTouched;
  44346. },
  44347. // Untouches the point p.
  44348. untouch: function(p) {
  44349. p.yTouched = false;
  44350. }
  44351. };
  44352. Object.freeze(xUnitVector);
  44353. Object.freeze(yUnitVector);
  44354. /*
  44355. * Creates a unit vector that is not x- or y-axis.
  44356. */
  44357. function UnitVector(x, y) {
  44358. this.x = x;
  44359. this.y = y;
  44360. this.axis = undefined;
  44361. this.slope = y / x;
  44362. this.normalSlope = -x / y;
  44363. Object.freeze(this);
  44364. }
  44365. /*
  44366. * Gets the projected distance between two points.
  44367. * o1/o2 ... if true, respective original position is used.
  44368. */
  44369. UnitVector.prototype.distance = function(p1, p2, o1, o2) {
  44370. return (
  44371. this.x * xUnitVector.distance(p1, p2, o1, o2) +
  44372. this.y * yUnitVector.distance(p1, p2, o1, o2)
  44373. );
  44374. };
  44375. /*
  44376. * Moves point p so the moved position has the same relative
  44377. * position to the moved positions of rp1 and rp2 than the
  44378. * original positions had.
  44379. *
  44380. * See APPENDIX on INTERPOLATE at the bottom of this file.
  44381. */
  44382. UnitVector.prototype.interpolate = function(p, rp1, rp2, pv) {
  44383. var dm1;
  44384. var dm2;
  44385. var do1;
  44386. var do2;
  44387. var doa1;
  44388. var doa2;
  44389. var dt;
  44390. do1 = pv.distance(p, rp1, true, true);
  44391. do2 = pv.distance(p, rp2, true, true);
  44392. dm1 = pv.distance(rp1, rp1, false, true);
  44393. dm2 = pv.distance(rp2, rp2, false, true);
  44394. doa1 = Math.abs(do1);
  44395. doa2 = Math.abs(do2);
  44396. dt = doa1 + doa2;
  44397. if (dt === 0) {
  44398. this.setRelative(p, p, (dm1 + dm2) / 2, pv, true);
  44399. return;
  44400. }
  44401. this.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true);
  44402. };
  44403. /*
  44404. * Sets the point 'p' relative to point 'rp'
  44405. * by the distance 'd'
  44406. *
  44407. * See APPENDIX on SETRELATIVE at the bottom of this file.
  44408. *
  44409. * p ... point to set
  44410. * rp ... reference point
  44411. * d ... distance on projection vector
  44412. * pv ... projection vector (undefined = this)
  44413. * org ... if true, uses the original position of rp as reference.
  44414. */
  44415. UnitVector.prototype.setRelative = function(p, rp, d, pv, org) {
  44416. pv = pv || this;
  44417. var rpx = org ? rp.xo : rp.x;
  44418. var rpy = org ? rp.yo : rp.y;
  44419. var rpdx = rpx + d * pv.x;
  44420. var rpdy = rpy + d * pv.y;
  44421. var pvns = pv.normalSlope;
  44422. var fvs = this.slope;
  44423. var px = p.x;
  44424. var py = p.y;
  44425. p.x = (fvs * px - pvns * rpdx + rpdy - py) / (fvs - pvns);
  44426. p.y = fvs * (p.x - px) + py;
  44427. };
  44428. /*
  44429. * Touches the point p.
  44430. */
  44431. UnitVector.prototype.touch = function(p) {
  44432. p.xTouched = true;
  44433. p.yTouched = true;
  44434. };
  44435. /*
  44436. * Returns a unit vector with x/y coordinates.
  44437. */
  44438. function getUnitVector(x, y) {
  44439. var d = Math.sqrt(x * x + y * y);
  44440. x /= d;
  44441. y /= d;
  44442. if (x === 1 && y === 0) {
  44443. return xUnitVector;
  44444. } else if (x === 0 && y === 1) {
  44445. return yUnitVector;
  44446. } else {
  44447. return new UnitVector(x, y);
  44448. }
  44449. }
  44450. /*
  44451. * Creates a point in the hinting engine.
  44452. */
  44453. function HPoint(x, y, lastPointOfContour, onCurve) {
  44454. this.x = this.xo = Math.round(x * 64) / 64; // hinted x value and original x-value
  44455. this.y = this.yo = Math.round(y * 64) / 64; // hinted y value and original y-value
  44456. this.lastPointOfContour = lastPointOfContour;
  44457. this.onCurve = onCurve;
  44458. this.prevPointOnContour = undefined;
  44459. this.nextPointOnContour = undefined;
  44460. this.xTouched = false;
  44461. this.yTouched = false;
  44462. Object.preventExtensions(this);
  44463. }
  44464. /*
  44465. * Returns the next touched point on the contour.
  44466. *
  44467. * v ... unit vector to test touch axis.
  44468. */
  44469. HPoint.prototype.nextTouched = function(v) {
  44470. var p = this.nextPointOnContour;
  44471. while (!v.touched(p) && p !== this) {
  44472. p = p.nextPointOnContour;
  44473. }
  44474. return p;
  44475. };
  44476. /*
  44477. * Returns the previous touched point on the contour
  44478. *
  44479. * v ... unit vector to test touch axis.
  44480. */
  44481. HPoint.prototype.prevTouched = function(v) {
  44482. var p = this.prevPointOnContour;
  44483. while (!v.touched(p) && p !== this) {
  44484. p = p.prevPointOnContour;
  44485. }
  44486. return p;
  44487. };
  44488. /*
  44489. * The zero point.
  44490. */
  44491. var HPZero = Object.freeze(new HPoint(0, 0));
  44492. /*
  44493. * The default state of the interpreter.
  44494. *
  44495. * Note: Freezing the defaultState and then deriving from it
  44496. * makes the V8 Javascript engine going awkward,
  44497. * so this is avoided, albeit the defaultState shouldn't
  44498. * ever change.
  44499. */
  44500. var defaultState = {
  44501. cvCutIn: 17 / 16, // control value cut in
  44502. deltaBase: 9,
  44503. deltaShift: 0.125,
  44504. loop: 1, // loops some instructions
  44505. minDis: 1, // minimum distance
  44506. autoFlip: true
  44507. };
  44508. /*
  44509. * The current state of the interpreter.
  44510. *
  44511. * env ... 'fpgm' or 'prep' or 'glyf'
  44512. * prog ... the program
  44513. */
  44514. function State(env, prog) {
  44515. this.env = env;
  44516. this.stack = [];
  44517. this.prog = prog;
  44518. switch (env) {
  44519. case 'glyf':
  44520. this.zp0 = this.zp1 = this.zp2 = 1;
  44521. this.rp0 = this.rp1 = this.rp2 = 0;
  44522. /* fall through */
  44523. case 'prep':
  44524. this.fv = this.pv = this.dpv = xUnitVector;
  44525. this.round = roundToGrid;
  44526. }
  44527. }
  44528. /*
  44529. * Executes a glyph program.
  44530. *
  44531. * This does the hinting for each glyph.
  44532. *
  44533. * Returns an array of moved points.
  44534. *
  44535. * glyph: the glyph to hint
  44536. * ppem: the size the glyph is rendered for
  44537. */
  44538. Hinting.prototype.exec = function(glyph, ppem) {
  44539. if (typeof ppem !== 'number') {
  44540. throw new Error('Point size is not a number!');
  44541. }
  44542. // Received a fatal error, don't do any hinting anymore.
  44543. if (this._errorState > 2) {
  44544. return;
  44545. }
  44546. var font = this.font;
  44547. var prepState = this._prepState;
  44548. if (!prepState || prepState.ppem !== ppem) {
  44549. var fpgmState = this._fpgmState;
  44550. if (!fpgmState) {
  44551. // Executes the fpgm state.
  44552. // This is used by fonts to define functions.
  44553. State.prototype = defaultState;
  44554. fpgmState = this._fpgmState = new State('fpgm', font.tables.fpgm);
  44555. fpgmState.funcs = [];
  44556. fpgmState.font = font;
  44557. if (exports.DEBUG) {
  44558. console.log('---EXEC FPGM---');
  44559. fpgmState.step = -1;
  44560. }
  44561. try {
  44562. exec(fpgmState);
  44563. } catch (e) {
  44564. console.log('Hinting error in FPGM:' + e);
  44565. this._errorState = 3;
  44566. return;
  44567. }
  44568. }
  44569. // Executes the prep program for this ppem setting.
  44570. // This is used by fonts to set cvt values
  44571. // depending on to be rendered font size.
  44572. State.prototype = fpgmState;
  44573. prepState = this._prepState = new State('prep', font.tables.prep);
  44574. prepState.ppem = ppem;
  44575. // Creates a copy of the cvt table
  44576. // and scales it to the current ppem setting.
  44577. var oCvt = font.tables.cvt;
  44578. if (oCvt) {
  44579. var cvt = (prepState.cvt = new Array(oCvt.length));
  44580. var scale = ppem / font.unitsPerEm;
  44581. for (var c = 0; c < oCvt.length; c++) {
  44582. cvt[c] = oCvt[c] * scale;
  44583. }
  44584. } else {
  44585. prepState.cvt = [];
  44586. }
  44587. if (exports.DEBUG) {
  44588. console.log('---EXEC PREP---');
  44589. prepState.step = -1;
  44590. }
  44591. try {
  44592. exec(prepState);
  44593. } catch (e) {
  44594. if (this._errorState < 2) {
  44595. console.log('Hinting error in PREP:' + e);
  44596. }
  44597. this._errorState = 2;
  44598. }
  44599. }
  44600. if (this._errorState > 1) {
  44601. return;
  44602. }
  44603. try {
  44604. return execGlyph(glyph, prepState);
  44605. } catch (e) {
  44606. if (this._errorState < 1) {
  44607. console.log('Hinting error:' + e);
  44608. console.log('Note: further hinting errors are silenced');
  44609. }
  44610. this._errorState = 1;
  44611. return undefined;
  44612. }
  44613. };
  44614. /*
  44615. * Executes the hinting program for a glyph.
  44616. */
  44617. execGlyph = function(glyph, prepState) {
  44618. // original point positions
  44619. var xScale = prepState.ppem / prepState.font.unitsPerEm;
  44620. var yScale = xScale;
  44621. var components = glyph.components;
  44622. var contours;
  44623. var gZone;
  44624. var state;
  44625. State.prototype = prepState;
  44626. if (!components) {
  44627. state = new State('glyf', glyph.instructions);
  44628. if (exports.DEBUG) {
  44629. console.log('---EXEC GLYPH---');
  44630. state.step = -1;
  44631. }
  44632. execComponent(glyph, state, xScale, yScale);
  44633. gZone = state.gZone;
  44634. } else {
  44635. var font = prepState.font;
  44636. gZone = [];
  44637. contours = [];
  44638. for (var i = 0; i < components.length; i++) {
  44639. var c = components[i];
  44640. var cg = font.glyphs.get(c.glyphIndex);
  44641. state = new State('glyf', cg.instructions);
  44642. if (exports.DEBUG) {
  44643. console.log('---EXEC COMP ' + i + '---');
  44644. state.step = -1;
  44645. }
  44646. execComponent(cg, state, xScale, yScale);
  44647. // appends the computed points to the result array
  44648. // post processes the component points
  44649. var dx = Math.round(c.dx * xScale);
  44650. var dy = Math.round(c.dy * yScale);
  44651. var gz = state.gZone;
  44652. var cc = state.contours;
  44653. for (var pi = 0; pi < gz.length; pi++) {
  44654. var p = gz[pi];
  44655. p.xTouched = p.yTouched = false;
  44656. p.xo = p.x = p.x + dx;
  44657. p.yo = p.y = p.y + dy;
  44658. }
  44659. var gLen = gZone.length;
  44660. gZone.push.apply(gZone, gz);
  44661. for (var j = 0; j < cc.length; j++) {
  44662. contours.push(cc[j] + gLen);
  44663. }
  44664. }
  44665. if (glyph.instructions && !state.inhibitGridFit) {
  44666. // the composite has instructions on its own
  44667. state = new State('glyf', glyph.instructions);
  44668. state.gZone = state.z0 = state.z1 = state.z2 = gZone;
  44669. state.contours = contours;
  44670. // note: HPZero cannot be used here, since
  44671. // the point might be modified
  44672. gZone.push(
  44673. new HPoint(0, 0),
  44674. new HPoint(Math.round(glyph.advanceWidth * xScale), 0)
  44675. );
  44676. if (exports.DEBUG) {
  44677. console.log('---EXEC COMPOSITE---');
  44678. state.step = -1;
  44679. }
  44680. exec(state);
  44681. gZone.length -= 2;
  44682. }
  44683. }
  44684. return gZone;
  44685. };
  44686. /*
  44687. * Executes the hinting program for a component of a multi-component glyph
  44688. * or of the glyph itself for a non-component glyph.
  44689. */
  44690. execComponent = function(glyph, state, xScale, yScale) {
  44691. var points = glyph.points || [];
  44692. var pLen = points.length;
  44693. var gZone = (state.gZone = state.z0 = state.z1 = state.z2 = []);
  44694. var contours = (state.contours = []);
  44695. // Scales the original points and
  44696. // makes copies for the hinted points.
  44697. var cp; // current point
  44698. for (var i = 0; i < pLen; i++) {
  44699. cp = points[i];
  44700. gZone[i] = new HPoint(
  44701. cp.x * xScale,
  44702. cp.y * yScale,
  44703. cp.lastPointOfContour,
  44704. cp.onCurve
  44705. );
  44706. }
  44707. // Chain links the contours.
  44708. var sp; // start point
  44709. var np; // next point
  44710. for (var i$1 = 0; i$1 < pLen; i$1++) {
  44711. cp = gZone[i$1];
  44712. if (!sp) {
  44713. sp = cp;
  44714. contours.push(i$1);
  44715. }
  44716. if (cp.lastPointOfContour) {
  44717. cp.nextPointOnContour = sp;
  44718. sp.prevPointOnContour = cp;
  44719. sp = undefined;
  44720. } else {
  44721. np = gZone[i$1 + 1];
  44722. cp.nextPointOnContour = np;
  44723. np.prevPointOnContour = cp;
  44724. }
  44725. }
  44726. if (state.inhibitGridFit) {
  44727. return;
  44728. }
  44729. if (exports.DEBUG) {
  44730. console.log('PROCESSING GLYPH', state.stack);
  44731. for (var i$2 = 0; i$2 < pLen; i$2++) {
  44732. console.log(i$2, gZone[i$2].x, gZone[i$2].y);
  44733. }
  44734. }
  44735. gZone.push(
  44736. new HPoint(0, 0),
  44737. new HPoint(Math.round(glyph.advanceWidth * xScale), 0)
  44738. );
  44739. exec(state);
  44740. // Removes the extra points.
  44741. gZone.length -= 2;
  44742. if (exports.DEBUG) {
  44743. console.log('FINISHED GLYPH', state.stack);
  44744. for (var i$3 = 0; i$3 < pLen; i$3++) {
  44745. console.log(i$3, gZone[i$3].x, gZone[i$3].y);
  44746. }
  44747. }
  44748. };
  44749. /*
  44750. * Executes the program loaded in state.
  44751. */
  44752. exec = function(state) {
  44753. var prog = state.prog;
  44754. if (!prog) {
  44755. return;
  44756. }
  44757. var pLen = prog.length;
  44758. var ins;
  44759. for (state.ip = 0; state.ip < pLen; state.ip++) {
  44760. if (exports.DEBUG) {
  44761. state.step++;
  44762. }
  44763. ins = instructionTable[prog[state.ip]];
  44764. if (!ins) {
  44765. throw new Error(
  44766. 'unknown instruction: 0x' + Number(prog[state.ip]).toString(16)
  44767. );
  44768. }
  44769. ins(state);
  44770. // very extensive debugging for each step
  44771. /*
  44772. if (exports.DEBUG) {
  44773. var da;
  44774. if (state.gZone) {
  44775. da = [];
  44776. for (let i = 0; i < state.gZone.length; i++)
  44777. {
  44778. da.push(i + ' ' +
  44779. state.gZone[i].x * 64 + ' ' +
  44780. state.gZone[i].y * 64 + ' ' +
  44781. (state.gZone[i].xTouched ? 'x' : '') +
  44782. (state.gZone[i].yTouched ? 'y' : '')
  44783. );
  44784. }
  44785. console.log('GZ', da);
  44786. }
  44787. if (state.tZone) {
  44788. da = [];
  44789. for (let i = 0; i < state.tZone.length; i++) {
  44790. da.push(i + ' ' +
  44791. state.tZone[i].x * 64 + ' ' +
  44792. state.tZone[i].y * 64 + ' ' +
  44793. (state.tZone[i].xTouched ? 'x' : '') +
  44794. (state.tZone[i].yTouched ? 'y' : '')
  44795. );
  44796. }
  44797. console.log('TZ', da);
  44798. }
  44799. if (state.stack.length > 10) {
  44800. console.log(
  44801. state.stack.length,
  44802. '...', state.stack.slice(state.stack.length - 10)
  44803. );
  44804. } else {
  44805. console.log(state.stack.length, state.stack);
  44806. }
  44807. }
  44808. */
  44809. }
  44810. };
  44811. /*
  44812. * Initializes the twilight zone.
  44813. *
  44814. * This is only done if a SZPx instruction
  44815. * refers to the twilight zone.
  44816. */
  44817. function initTZone(state) {
  44818. var tZone = (state.tZone = new Array(state.gZone.length));
  44819. // no idea if this is actually correct...
  44820. for (var i = 0; i < tZone.length; i++) {
  44821. tZone[i] = new HPoint(0, 0);
  44822. }
  44823. }
  44824. /*
  44825. * Skips the instruction pointer ahead over an IF/ELSE block.
  44826. * handleElse .. if true breaks on matching ELSE
  44827. */
  44828. function skip(state, handleElse) {
  44829. var prog = state.prog;
  44830. var ip = state.ip;
  44831. var nesting = 1;
  44832. var ins;
  44833. do {
  44834. ins = prog[++ip];
  44835. if (ins === 0x58) {
  44836. // IF
  44837. nesting++;
  44838. } else if (ins === 0x59) {
  44839. // EIF
  44840. nesting--;
  44841. } else if (ins === 0x40) {
  44842. // NPUSHB
  44843. ip += prog[ip + 1] + 1;
  44844. } else if (ins === 0x41) {
  44845. // NPUSHW
  44846. ip += 2 * prog[ip + 1] + 1;
  44847. } else if (ins >= 0xb0 && ins <= 0xb7) {
  44848. // PUSHB
  44849. ip += ins - 0xb0 + 1;
  44850. } else if (ins >= 0xb8 && ins <= 0xbf) {
  44851. // PUSHW
  44852. ip += (ins - 0xb8 + 1) * 2;
  44853. } else if (handleElse && nesting === 1 && ins === 0x1b) {
  44854. // ELSE
  44855. break;
  44856. }
  44857. } while (nesting > 0);
  44858. state.ip = ip;
  44859. }
  44860. /*----------------------------------------------------------*
  44861. * And then a lot of instructions... *
  44862. *----------------------------------------------------------*/
  44863. // SVTCA[a] Set freedom and projection Vectors To Coordinate Axis
  44864. // 0x00-0x01
  44865. function SVTCA(v, state) {
  44866. if (exports.DEBUG) {
  44867. console.log(state.step, 'SVTCA[' + v.axis + ']');
  44868. }
  44869. state.fv = state.pv = state.dpv = v;
  44870. }
  44871. // SPVTCA[a] Set Projection Vector to Coordinate Axis
  44872. // 0x02-0x03
  44873. function SPVTCA(v, state) {
  44874. if (exports.DEBUG) {
  44875. console.log(state.step, 'SPVTCA[' + v.axis + ']');
  44876. }
  44877. state.pv = state.dpv = v;
  44878. }
  44879. // SFVTCA[a] Set Freedom Vector to Coordinate Axis
  44880. // 0x04-0x05
  44881. function SFVTCA(v, state) {
  44882. if (exports.DEBUG) {
  44883. console.log(state.step, 'SFVTCA[' + v.axis + ']');
  44884. }
  44885. state.fv = v;
  44886. }
  44887. // SPVTL[a] Set Projection Vector To Line
  44888. // 0x06-0x07
  44889. function SPVTL(a, state) {
  44890. var stack = state.stack;
  44891. var p2i = stack.pop();
  44892. var p1i = stack.pop();
  44893. var p2 = state.z2[p2i];
  44894. var p1 = state.z1[p1i];
  44895. if (exports.DEBUG) {
  44896. console.log('SPVTL[' + a + ']', p2i, p1i);
  44897. }
  44898. var dx;
  44899. var dy;
  44900. if (!a) {
  44901. dx = p1.x - p2.x;
  44902. dy = p1.y - p2.y;
  44903. } else {
  44904. dx = p2.y - p1.y;
  44905. dy = p1.x - p2.x;
  44906. }
  44907. state.pv = state.dpv = getUnitVector(dx, dy);
  44908. }
  44909. // SFVTL[a] Set Freedom Vector To Line
  44910. // 0x08-0x09
  44911. function SFVTL(a, state) {
  44912. var stack = state.stack;
  44913. var p2i = stack.pop();
  44914. var p1i = stack.pop();
  44915. var p2 = state.z2[p2i];
  44916. var p1 = state.z1[p1i];
  44917. if (exports.DEBUG) {
  44918. console.log('SFVTL[' + a + ']', p2i, p1i);
  44919. }
  44920. var dx;
  44921. var dy;
  44922. if (!a) {
  44923. dx = p1.x - p2.x;
  44924. dy = p1.y - p2.y;
  44925. } else {
  44926. dx = p2.y - p1.y;
  44927. dy = p1.x - p2.x;
  44928. }
  44929. state.fv = getUnitVector(dx, dy);
  44930. }
  44931. // SPVFS[] Set Projection Vector From Stack
  44932. // 0x0A
  44933. function SPVFS(state) {
  44934. var stack = state.stack;
  44935. var y = stack.pop();
  44936. var x = stack.pop();
  44937. if (exports.DEBUG) {
  44938. console.log(state.step, 'SPVFS[]', y, x);
  44939. }
  44940. state.pv = state.dpv = getUnitVector(x, y);
  44941. }
  44942. // SFVFS[] Set Freedom Vector From Stack
  44943. // 0x0B
  44944. function SFVFS(state) {
  44945. var stack = state.stack;
  44946. var y = stack.pop();
  44947. var x = stack.pop();
  44948. if (exports.DEBUG) {
  44949. console.log(state.step, 'SPVFS[]', y, x);
  44950. }
  44951. state.fv = getUnitVector(x, y);
  44952. }
  44953. // GPV[] Get Projection Vector
  44954. // 0x0C
  44955. function GPV(state) {
  44956. var stack = state.stack;
  44957. var pv = state.pv;
  44958. if (exports.DEBUG) {
  44959. console.log(state.step, 'GPV[]');
  44960. }
  44961. stack.push(pv.x * 0x4000);
  44962. stack.push(pv.y * 0x4000);
  44963. }
  44964. // GFV[] Get Freedom Vector
  44965. // 0x0C
  44966. function GFV(state) {
  44967. var stack = state.stack;
  44968. var fv = state.fv;
  44969. if (exports.DEBUG) {
  44970. console.log(state.step, 'GFV[]');
  44971. }
  44972. stack.push(fv.x * 0x4000);
  44973. stack.push(fv.y * 0x4000);
  44974. }
  44975. // SFVTPV[] Set Freedom Vector To Projection Vector
  44976. // 0x0E
  44977. function SFVTPV(state) {
  44978. state.fv = state.pv;
  44979. if (exports.DEBUG) {
  44980. console.log(state.step, 'SFVTPV[]');
  44981. }
  44982. }
  44983. // ISECT[] moves point p to the InterSECTion of two lines
  44984. // 0x0F
  44985. function ISECT(state) {
  44986. var stack = state.stack;
  44987. var pa0i = stack.pop();
  44988. var pa1i = stack.pop();
  44989. var pb0i = stack.pop();
  44990. var pb1i = stack.pop();
  44991. var pi = stack.pop();
  44992. var z0 = state.z0;
  44993. var z1 = state.z1;
  44994. var pa0 = z0[pa0i];
  44995. var pa1 = z0[pa1i];
  44996. var pb0 = z1[pb0i];
  44997. var pb1 = z1[pb1i];
  44998. var p = state.z2[pi];
  44999. if (exports.DEBUG) {
  45000. console.log('ISECT[], ', pa0i, pa1i, pb0i, pb1i, pi);
  45001. }
  45002. // math from
  45003. // en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line
  45004. var x1 = pa0.x;
  45005. var y1 = pa0.y;
  45006. var x2 = pa1.x;
  45007. var y2 = pa1.y;
  45008. var x3 = pb0.x;
  45009. var y3 = pb0.y;
  45010. var x4 = pb1.x;
  45011. var y4 = pb1.y;
  45012. var div = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  45013. var f1 = x1 * y2 - y1 * x2;
  45014. var f2 = x3 * y4 - y3 * x4;
  45015. p.x = (f1 * (x3 - x4) - f2 * (x1 - x2)) / div;
  45016. p.y = (f1 * (y3 - y4) - f2 * (y1 - y2)) / div;
  45017. }
  45018. // SRP0[] Set Reference Point 0
  45019. // 0x10
  45020. function SRP0(state) {
  45021. state.rp0 = state.stack.pop();
  45022. if (exports.DEBUG) {
  45023. console.log(state.step, 'SRP0[]', state.rp0);
  45024. }
  45025. }
  45026. // SRP1[] Set Reference Point 1
  45027. // 0x11
  45028. function SRP1(state) {
  45029. state.rp1 = state.stack.pop();
  45030. if (exports.DEBUG) {
  45031. console.log(state.step, 'SRP1[]', state.rp1);
  45032. }
  45033. }
  45034. // SRP1[] Set Reference Point 2
  45035. // 0x12
  45036. function SRP2(state) {
  45037. state.rp2 = state.stack.pop();
  45038. if (exports.DEBUG) {
  45039. console.log(state.step, 'SRP2[]', state.rp2);
  45040. }
  45041. }
  45042. // SZP0[] Set Zone Pointer 0
  45043. // 0x13
  45044. function SZP0(state) {
  45045. var n = state.stack.pop();
  45046. if (exports.DEBUG) {
  45047. console.log(state.step, 'SZP0[]', n);
  45048. }
  45049. state.zp0 = n;
  45050. switch (n) {
  45051. case 0:
  45052. if (!state.tZone) {
  45053. initTZone(state);
  45054. }
  45055. state.z0 = state.tZone;
  45056. break;
  45057. case 1:
  45058. state.z0 = state.gZone;
  45059. break;
  45060. default:
  45061. throw new Error('Invalid zone pointer');
  45062. }
  45063. }
  45064. // SZP1[] Set Zone Pointer 1
  45065. // 0x14
  45066. function SZP1(state) {
  45067. var n = state.stack.pop();
  45068. if (exports.DEBUG) {
  45069. console.log(state.step, 'SZP1[]', n);
  45070. }
  45071. state.zp1 = n;
  45072. switch (n) {
  45073. case 0:
  45074. if (!state.tZone) {
  45075. initTZone(state);
  45076. }
  45077. state.z1 = state.tZone;
  45078. break;
  45079. case 1:
  45080. state.z1 = state.gZone;
  45081. break;
  45082. default:
  45083. throw new Error('Invalid zone pointer');
  45084. }
  45085. }
  45086. // SZP2[] Set Zone Pointer 2
  45087. // 0x15
  45088. function SZP2(state) {
  45089. var n = state.stack.pop();
  45090. if (exports.DEBUG) {
  45091. console.log(state.step, 'SZP2[]', n);
  45092. }
  45093. state.zp2 = n;
  45094. switch (n) {
  45095. case 0:
  45096. if (!state.tZone) {
  45097. initTZone(state);
  45098. }
  45099. state.z2 = state.tZone;
  45100. break;
  45101. case 1:
  45102. state.z2 = state.gZone;
  45103. break;
  45104. default:
  45105. throw new Error('Invalid zone pointer');
  45106. }
  45107. }
  45108. // SZPS[] Set Zone PointerS
  45109. // 0x16
  45110. function SZPS(state) {
  45111. var n = state.stack.pop();
  45112. if (exports.DEBUG) {
  45113. console.log(state.step, 'SZPS[]', n);
  45114. }
  45115. state.zp0 = state.zp1 = state.zp2 = n;
  45116. switch (n) {
  45117. case 0:
  45118. if (!state.tZone) {
  45119. initTZone(state);
  45120. }
  45121. state.z0 = state.z1 = state.z2 = state.tZone;
  45122. break;
  45123. case 1:
  45124. state.z0 = state.z1 = state.z2 = state.gZone;
  45125. break;
  45126. default:
  45127. throw new Error('Invalid zone pointer');
  45128. }
  45129. }
  45130. // SLOOP[] Set LOOP variable
  45131. // 0x17
  45132. function SLOOP(state) {
  45133. state.loop = state.stack.pop();
  45134. if (exports.DEBUG) {
  45135. console.log(state.step, 'SLOOP[]', state.loop);
  45136. }
  45137. }
  45138. // RTG[] Round To Grid
  45139. // 0x18
  45140. function RTG(state) {
  45141. if (exports.DEBUG) {
  45142. console.log(state.step, 'RTG[]');
  45143. }
  45144. state.round = roundToGrid;
  45145. }
  45146. // RTHG[] Round To Half Grid
  45147. // 0x19
  45148. function RTHG(state) {
  45149. if (exports.DEBUG) {
  45150. console.log(state.step, 'RTHG[]');
  45151. }
  45152. state.round = roundToHalfGrid;
  45153. }
  45154. // SMD[] Set Minimum Distance
  45155. // 0x1A
  45156. function SMD(state) {
  45157. var d = state.stack.pop();
  45158. if (exports.DEBUG) {
  45159. console.log(state.step, 'SMD[]', d);
  45160. }
  45161. state.minDis = d / 0x40;
  45162. }
  45163. // ELSE[] ELSE clause
  45164. // 0x1B
  45165. function ELSE(state) {
  45166. // This instruction has been reached by executing a then branch
  45167. // so it just skips ahead until matching EIF.
  45168. //
  45169. // In case the IF was negative the IF[] instruction already
  45170. // skipped forward over the ELSE[]
  45171. if (exports.DEBUG) {
  45172. console.log(state.step, 'ELSE[]');
  45173. }
  45174. skip(state, false);
  45175. }
  45176. // JMPR[] JuMP Relative
  45177. // 0x1C
  45178. function JMPR(state) {
  45179. var o = state.stack.pop();
  45180. if (exports.DEBUG) {
  45181. console.log(state.step, 'JMPR[]', o);
  45182. }
  45183. // A jump by 1 would do nothing.
  45184. state.ip += o - 1;
  45185. }
  45186. // SCVTCI[] Set Control Value Table Cut-In
  45187. // 0x1D
  45188. function SCVTCI(state) {
  45189. var n = state.stack.pop();
  45190. if (exports.DEBUG) {
  45191. console.log(state.step, 'SCVTCI[]', n);
  45192. }
  45193. state.cvCutIn = n / 0x40;
  45194. }
  45195. // DUP[] DUPlicate top stack element
  45196. // 0x20
  45197. function DUP(state) {
  45198. var stack = state.stack;
  45199. if (exports.DEBUG) {
  45200. console.log(state.step, 'DUP[]');
  45201. }
  45202. stack.push(stack[stack.length - 1]);
  45203. }
  45204. // POP[] POP top stack element
  45205. // 0x21
  45206. function POP(state) {
  45207. if (exports.DEBUG) {
  45208. console.log(state.step, 'POP[]');
  45209. }
  45210. state.stack.pop();
  45211. }
  45212. // CLEAR[] CLEAR the stack
  45213. // 0x22
  45214. function CLEAR(state) {
  45215. if (exports.DEBUG) {
  45216. console.log(state.step, 'CLEAR[]');
  45217. }
  45218. state.stack.length = 0;
  45219. }
  45220. // SWAP[] SWAP the top two elements on the stack
  45221. // 0x23
  45222. function SWAP(state) {
  45223. var stack = state.stack;
  45224. var a = stack.pop();
  45225. var b = stack.pop();
  45226. if (exports.DEBUG) {
  45227. console.log(state.step, 'SWAP[]');
  45228. }
  45229. stack.push(a);
  45230. stack.push(b);
  45231. }
  45232. // DEPTH[] DEPTH of the stack
  45233. // 0x24
  45234. function DEPTH(state) {
  45235. var stack = state.stack;
  45236. if (exports.DEBUG) {
  45237. console.log(state.step, 'DEPTH[]');
  45238. }
  45239. stack.push(stack.length);
  45240. }
  45241. // LOOPCALL[] LOOPCALL function
  45242. // 0x2A
  45243. function LOOPCALL(state) {
  45244. var stack = state.stack;
  45245. var fn = stack.pop();
  45246. var c = stack.pop();
  45247. if (exports.DEBUG) {
  45248. console.log(state.step, 'LOOPCALL[]', fn, c);
  45249. }
  45250. // saves callers program
  45251. var cip = state.ip;
  45252. var cprog = state.prog;
  45253. state.prog = state.funcs[fn];
  45254. // executes the function
  45255. for (var i = 0; i < c; i++) {
  45256. exec(state);
  45257. if (exports.DEBUG) {
  45258. console.log(
  45259. ++state.step,
  45260. i + 1 < c ? 'next loopcall' : 'done loopcall',
  45261. i
  45262. );
  45263. }
  45264. }
  45265. // restores the callers program
  45266. state.ip = cip;
  45267. state.prog = cprog;
  45268. }
  45269. // CALL[] CALL function
  45270. // 0x2B
  45271. function CALL(state) {
  45272. var fn = state.stack.pop();
  45273. if (exports.DEBUG) {
  45274. console.log(state.step, 'CALL[]', fn);
  45275. }
  45276. // saves callers program
  45277. var cip = state.ip;
  45278. var cprog = state.prog;
  45279. state.prog = state.funcs[fn];
  45280. // executes the function
  45281. exec(state);
  45282. // restores the callers program
  45283. state.ip = cip;
  45284. state.prog = cprog;
  45285. if (exports.DEBUG) {
  45286. console.log(++state.step, 'returning from', fn);
  45287. }
  45288. }
  45289. // CINDEX[] Copy the INDEXed element to the top of the stack
  45290. // 0x25
  45291. function CINDEX(state) {
  45292. var stack = state.stack;
  45293. var k = stack.pop();
  45294. if (exports.DEBUG) {
  45295. console.log(state.step, 'CINDEX[]', k);
  45296. }
  45297. // In case of k == 1, it copies the last element after popping
  45298. // thus stack.length - k.
  45299. stack.push(stack[stack.length - k]);
  45300. }
  45301. // MINDEX[] Move the INDEXed element to the top of the stack
  45302. // 0x26
  45303. function MINDEX(state) {
  45304. var stack = state.stack;
  45305. var k = stack.pop();
  45306. if (exports.DEBUG) {
  45307. console.log(state.step, 'MINDEX[]', k);
  45308. }
  45309. stack.push(stack.splice(stack.length - k, 1)[0]);
  45310. }
  45311. // FDEF[] Function DEFinition
  45312. // 0x2C
  45313. function FDEF(state) {
  45314. if (state.env !== 'fpgm') {
  45315. throw new Error('FDEF not allowed here');
  45316. }
  45317. var stack = state.stack;
  45318. var prog = state.prog;
  45319. var ip = state.ip;
  45320. var fn = stack.pop();
  45321. var ipBegin = ip;
  45322. if (exports.DEBUG) {
  45323. console.log(state.step, 'FDEF[]', fn);
  45324. }
  45325. while (prog[++ip] !== 0x2d) {}
  45326. state.ip = ip;
  45327. state.funcs[fn] = prog.slice(ipBegin + 1, ip);
  45328. }
  45329. // MDAP[a] Move Direct Absolute Point
  45330. // 0x2E-0x2F
  45331. function MDAP(round, state) {
  45332. var pi = state.stack.pop();
  45333. var p = state.z0[pi];
  45334. var fv = state.fv;
  45335. var pv = state.pv;
  45336. if (exports.DEBUG) {
  45337. console.log(state.step, 'MDAP[' + round + ']', pi);
  45338. }
  45339. var d = pv.distance(p, HPZero);
  45340. if (round) {
  45341. d = state.round(d);
  45342. }
  45343. fv.setRelative(p, HPZero, d, pv);
  45344. fv.touch(p);
  45345. state.rp0 = state.rp1 = pi;
  45346. }
  45347. // IUP[a] Interpolate Untouched Points through the outline
  45348. // 0x30
  45349. function IUP(v, state) {
  45350. var z2 = state.z2;
  45351. var pLen = z2.length - 2;
  45352. var cp;
  45353. var pp;
  45354. var np;
  45355. if (exports.DEBUG) {
  45356. console.log(state.step, 'IUP[' + v.axis + ']');
  45357. }
  45358. for (var i = 0; i < pLen; i++) {
  45359. cp = z2[i]; // current point
  45360. // if this point has been touched go on
  45361. if (v.touched(cp)) {
  45362. continue;
  45363. }
  45364. pp = cp.prevTouched(v);
  45365. // no point on the contour has been touched?
  45366. if (pp === cp) {
  45367. continue;
  45368. }
  45369. np = cp.nextTouched(v);
  45370. if (pp === np) {
  45371. // only one point on the contour has been touched
  45372. // so simply moves the point like that
  45373. v.setRelative(cp, cp, v.distance(pp, pp, false, true), v, true);
  45374. }
  45375. v.interpolate(cp, pp, np, v);
  45376. }
  45377. }
  45378. // SHP[] SHift Point using reference point
  45379. // 0x32-0x33
  45380. function SHP(a, state) {
  45381. var stack = state.stack;
  45382. var rpi = a ? state.rp1 : state.rp2;
  45383. var rp = (a ? state.z0 : state.z1)[rpi];
  45384. var fv = state.fv;
  45385. var pv = state.pv;
  45386. var loop = state.loop;
  45387. var z2 = state.z2;
  45388. while (loop--) {
  45389. var pi = stack.pop();
  45390. var p = z2[pi];
  45391. var d = pv.distance(rp, rp, false, true);
  45392. fv.setRelative(p, p, d, pv);
  45393. fv.touch(p);
  45394. if (exports.DEBUG) {
  45395. console.log(
  45396. state.step,
  45397. (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') +
  45398. 'SHP[' +
  45399. (a ? 'rp1' : 'rp2') +
  45400. ']',
  45401. pi
  45402. );
  45403. }
  45404. }
  45405. state.loop = 1;
  45406. }
  45407. // SHC[] SHift Contour using reference point
  45408. // 0x36-0x37
  45409. function SHC(a, state) {
  45410. var stack = state.stack;
  45411. var rpi = a ? state.rp1 : state.rp2;
  45412. var rp = (a ? state.z0 : state.z1)[rpi];
  45413. var fv = state.fv;
  45414. var pv = state.pv;
  45415. var ci = stack.pop();
  45416. var sp = state.z2[state.contours[ci]];
  45417. var p = sp;
  45418. if (exports.DEBUG) {
  45419. console.log(state.step, 'SHC[' + a + ']', ci);
  45420. }
  45421. var d = pv.distance(rp, rp, false, true);
  45422. do {
  45423. if (p !== rp) {
  45424. fv.setRelative(p, p, d, pv);
  45425. }
  45426. p = p.nextPointOnContour;
  45427. } while (p !== sp);
  45428. }
  45429. // SHZ[] SHift Zone using reference point
  45430. // 0x36-0x37
  45431. function SHZ(a, state) {
  45432. var stack = state.stack;
  45433. var rpi = a ? state.rp1 : state.rp2;
  45434. var rp = (a ? state.z0 : state.z1)[rpi];
  45435. var fv = state.fv;
  45436. var pv = state.pv;
  45437. var e = stack.pop();
  45438. if (exports.DEBUG) {
  45439. console.log(state.step, 'SHZ[' + a + ']', e);
  45440. }
  45441. var z;
  45442. switch (e) {
  45443. case 0:
  45444. z = state.tZone;
  45445. break;
  45446. case 1:
  45447. z = state.gZone;
  45448. break;
  45449. default:
  45450. throw new Error('Invalid zone');
  45451. }
  45452. var p;
  45453. var d = pv.distance(rp, rp, false, true);
  45454. var pLen = z.length - 2;
  45455. for (var i = 0; i < pLen; i++) {
  45456. p = z[i];
  45457. fv.setRelative(p, p, d, pv);
  45458. //if (p !== rp) fv.setRelative(p, p, d, pv);
  45459. }
  45460. }
  45461. // SHPIX[] SHift point by a PIXel amount
  45462. // 0x38
  45463. function SHPIX(state) {
  45464. var stack = state.stack;
  45465. var loop = state.loop;
  45466. var fv = state.fv;
  45467. var d = stack.pop() / 0x40;
  45468. var z2 = state.z2;
  45469. while (loop--) {
  45470. var pi = stack.pop();
  45471. var p = z2[pi];
  45472. if (exports.DEBUG) {
  45473. console.log(
  45474. state.step,
  45475. (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') +
  45476. 'SHPIX[]',
  45477. pi,
  45478. d
  45479. );
  45480. }
  45481. fv.setRelative(p, p, d);
  45482. fv.touch(p);
  45483. }
  45484. state.loop = 1;
  45485. }
  45486. // IP[] Interpolate Point
  45487. // 0x39
  45488. function IP(state) {
  45489. var stack = state.stack;
  45490. var rp1i = state.rp1;
  45491. var rp2i = state.rp2;
  45492. var loop = state.loop;
  45493. var rp1 = state.z0[rp1i];
  45494. var rp2 = state.z1[rp2i];
  45495. var fv = state.fv;
  45496. var pv = state.dpv;
  45497. var z2 = state.z2;
  45498. while (loop--) {
  45499. var pi = stack.pop();
  45500. var p = z2[pi];
  45501. if (exports.DEBUG) {
  45502. console.log(
  45503. state.step,
  45504. (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') + 'IP[]',
  45505. pi,
  45506. rp1i,
  45507. '<->',
  45508. rp2i
  45509. );
  45510. }
  45511. fv.interpolate(p, rp1, rp2, pv);
  45512. fv.touch(p);
  45513. }
  45514. state.loop = 1;
  45515. }
  45516. // MSIRP[a] Move Stack Indirect Relative Point
  45517. // 0x3A-0x3B
  45518. function MSIRP(a, state) {
  45519. var stack = state.stack;
  45520. var d = stack.pop() / 64;
  45521. var pi = stack.pop();
  45522. var p = state.z1[pi];
  45523. var rp0 = state.z0[state.rp0];
  45524. var fv = state.fv;
  45525. var pv = state.pv;
  45526. fv.setRelative(p, rp0, d, pv);
  45527. fv.touch(p);
  45528. if (exports.DEBUG) {
  45529. console.log(state.step, 'MSIRP[' + a + ']', d, pi);
  45530. }
  45531. state.rp1 = state.rp0;
  45532. state.rp2 = pi;
  45533. if (a) {
  45534. state.rp0 = pi;
  45535. }
  45536. }
  45537. // ALIGNRP[] Align to reference point.
  45538. // 0x3C
  45539. function ALIGNRP(state) {
  45540. var stack = state.stack;
  45541. var rp0i = state.rp0;
  45542. var rp0 = state.z0[rp0i];
  45543. var loop = state.loop;
  45544. var fv = state.fv;
  45545. var pv = state.pv;
  45546. var z1 = state.z1;
  45547. while (loop--) {
  45548. var pi = stack.pop();
  45549. var p = z1[pi];
  45550. if (exports.DEBUG) {
  45551. console.log(
  45552. state.step,
  45553. (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') +
  45554. 'ALIGNRP[]',
  45555. pi
  45556. );
  45557. }
  45558. fv.setRelative(p, rp0, 0, pv);
  45559. fv.touch(p);
  45560. }
  45561. state.loop = 1;
  45562. }
  45563. // RTG[] Round To Double Grid
  45564. // 0x3D
  45565. function RTDG(state) {
  45566. if (exports.DEBUG) {
  45567. console.log(state.step, 'RTDG[]');
  45568. }
  45569. state.round = roundToDoubleGrid;
  45570. }
  45571. // MIAP[a] Move Indirect Absolute Point
  45572. // 0x3E-0x3F
  45573. function MIAP(round, state) {
  45574. var stack = state.stack;
  45575. var n = stack.pop();
  45576. var pi = stack.pop();
  45577. var p = state.z0[pi];
  45578. var fv = state.fv;
  45579. var pv = state.pv;
  45580. var cv = state.cvt[n];
  45581. if (exports.DEBUG) {
  45582. console.log(state.step, 'MIAP[' + round + ']', n, '(', cv, ')', pi);
  45583. }
  45584. var d = pv.distance(p, HPZero);
  45585. if (round) {
  45586. if (Math.abs(d - cv) < state.cvCutIn) {
  45587. d = cv;
  45588. }
  45589. d = state.round(d);
  45590. }
  45591. fv.setRelative(p, HPZero, d, pv);
  45592. if (state.zp0 === 0) {
  45593. p.xo = p.x;
  45594. p.yo = p.y;
  45595. }
  45596. fv.touch(p);
  45597. state.rp0 = state.rp1 = pi;
  45598. }
  45599. // NPUSB[] PUSH N Bytes
  45600. // 0x40
  45601. function NPUSHB(state) {
  45602. var prog = state.prog;
  45603. var ip = state.ip;
  45604. var stack = state.stack;
  45605. var n = prog[++ip];
  45606. if (exports.DEBUG) {
  45607. console.log(state.step, 'NPUSHB[]', n);
  45608. }
  45609. for (var i = 0; i < n; i++) {
  45610. stack.push(prog[++ip]);
  45611. }
  45612. state.ip = ip;
  45613. }
  45614. // NPUSHW[] PUSH N Words
  45615. // 0x41
  45616. function NPUSHW(state) {
  45617. var ip = state.ip;
  45618. var prog = state.prog;
  45619. var stack = state.stack;
  45620. var n = prog[++ip];
  45621. if (exports.DEBUG) {
  45622. console.log(state.step, 'NPUSHW[]', n);
  45623. }
  45624. for (var i = 0; i < n; i++) {
  45625. var w = (prog[++ip] << 8) | prog[++ip];
  45626. if (w & 0x8000) {
  45627. w = -((w ^ 0xffff) + 1);
  45628. }
  45629. stack.push(w);
  45630. }
  45631. state.ip = ip;
  45632. }
  45633. // WS[] Write Store
  45634. // 0x42
  45635. function WS(state) {
  45636. var stack = state.stack;
  45637. var store = state.store;
  45638. if (!store) {
  45639. store = state.store = [];
  45640. }
  45641. var v = stack.pop();
  45642. var l = stack.pop();
  45643. if (exports.DEBUG) {
  45644. console.log(state.step, 'WS', v, l);
  45645. }
  45646. store[l] = v;
  45647. }
  45648. // RS[] Read Store
  45649. // 0x43
  45650. function RS(state) {
  45651. var stack = state.stack;
  45652. var store = state.store;
  45653. var l = stack.pop();
  45654. if (exports.DEBUG) {
  45655. console.log(state.step, 'RS', l);
  45656. }
  45657. var v = (store && store[l]) || 0;
  45658. stack.push(v);
  45659. }
  45660. // WCVTP[] Write Control Value Table in Pixel units
  45661. // 0x44
  45662. function WCVTP(state) {
  45663. var stack = state.stack;
  45664. var v = stack.pop();
  45665. var l = stack.pop();
  45666. if (exports.DEBUG) {
  45667. console.log(state.step, 'WCVTP', v, l);
  45668. }
  45669. state.cvt[l] = v / 0x40;
  45670. }
  45671. // RCVT[] Read Control Value Table entry
  45672. // 0x45
  45673. function RCVT(state) {
  45674. var stack = state.stack;
  45675. var cvte = stack.pop();
  45676. if (exports.DEBUG) {
  45677. console.log(state.step, 'RCVT', cvte);
  45678. }
  45679. stack.push(state.cvt[cvte] * 0x40);
  45680. }
  45681. // GC[] Get Coordinate projected onto the projection vector
  45682. // 0x46-0x47
  45683. function GC(a, state) {
  45684. var stack = state.stack;
  45685. var pi = stack.pop();
  45686. var p = state.z2[pi];
  45687. if (exports.DEBUG) {
  45688. console.log(state.step, 'GC[' + a + ']', pi);
  45689. }
  45690. stack.push(state.dpv.distance(p, HPZero, a, false) * 0x40);
  45691. }
  45692. // MD[a] Measure Distance
  45693. // 0x49-0x4A
  45694. function MD(a, state) {
  45695. var stack = state.stack;
  45696. var pi2 = stack.pop();
  45697. var pi1 = stack.pop();
  45698. var p2 = state.z1[pi2];
  45699. var p1 = state.z0[pi1];
  45700. var d = state.dpv.distance(p1, p2, a, a);
  45701. if (exports.DEBUG) {
  45702. console.log(state.step, 'MD[' + a + ']', pi2, pi1, '->', d);
  45703. }
  45704. state.stack.push(Math.round(d * 64));
  45705. }
  45706. // MPPEM[] Measure Pixels Per EM
  45707. // 0x4B
  45708. function MPPEM(state) {
  45709. if (exports.DEBUG) {
  45710. console.log(state.step, 'MPPEM[]');
  45711. }
  45712. state.stack.push(state.ppem);
  45713. }
  45714. // FLIPON[] set the auto FLIP Boolean to ON
  45715. // 0x4D
  45716. function FLIPON(state) {
  45717. if (exports.DEBUG) {
  45718. console.log(state.step, 'FLIPON[]');
  45719. }
  45720. state.autoFlip = true;
  45721. }
  45722. // LT[] Less Than
  45723. // 0x50
  45724. function LT(state) {
  45725. var stack = state.stack;
  45726. var e2 = stack.pop();
  45727. var e1 = stack.pop();
  45728. if (exports.DEBUG) {
  45729. console.log(state.step, 'LT[]', e2, e1);
  45730. }
  45731. stack.push(e1 < e2 ? 1 : 0);
  45732. }
  45733. // LTEQ[] Less Than or EQual
  45734. // 0x53
  45735. function LTEQ(state) {
  45736. var stack = state.stack;
  45737. var e2 = stack.pop();
  45738. var e1 = stack.pop();
  45739. if (exports.DEBUG) {
  45740. console.log(state.step, 'LTEQ[]', e2, e1);
  45741. }
  45742. stack.push(e1 <= e2 ? 1 : 0);
  45743. }
  45744. // GTEQ[] Greater Than
  45745. // 0x52
  45746. function GT(state) {
  45747. var stack = state.stack;
  45748. var e2 = stack.pop();
  45749. var e1 = stack.pop();
  45750. if (exports.DEBUG) {
  45751. console.log(state.step, 'GT[]', e2, e1);
  45752. }
  45753. stack.push(e1 > e2 ? 1 : 0);
  45754. }
  45755. // GTEQ[] Greater Than or EQual
  45756. // 0x53
  45757. function GTEQ(state) {
  45758. var stack = state.stack;
  45759. var e2 = stack.pop();
  45760. var e1 = stack.pop();
  45761. if (exports.DEBUG) {
  45762. console.log(state.step, 'GTEQ[]', e2, e1);
  45763. }
  45764. stack.push(e1 >= e2 ? 1 : 0);
  45765. }
  45766. // EQ[] EQual
  45767. // 0x54
  45768. function EQ(state) {
  45769. var stack = state.stack;
  45770. var e2 = stack.pop();
  45771. var e1 = stack.pop();
  45772. if (exports.DEBUG) {
  45773. console.log(state.step, 'EQ[]', e2, e1);
  45774. }
  45775. stack.push(e2 === e1 ? 1 : 0);
  45776. }
  45777. // NEQ[] Not EQual
  45778. // 0x55
  45779. function NEQ(state) {
  45780. var stack = state.stack;
  45781. var e2 = stack.pop();
  45782. var e1 = stack.pop();
  45783. if (exports.DEBUG) {
  45784. console.log(state.step, 'NEQ[]', e2, e1);
  45785. }
  45786. stack.push(e2 !== e1 ? 1 : 0);
  45787. }
  45788. // ODD[] ODD
  45789. // 0x56
  45790. function ODD(state) {
  45791. var stack = state.stack;
  45792. var n = stack.pop();
  45793. if (exports.DEBUG) {
  45794. console.log(state.step, 'ODD[]', n);
  45795. }
  45796. stack.push(Math.trunc(n) % 2 ? 1 : 0);
  45797. }
  45798. // EVEN[] EVEN
  45799. // 0x57
  45800. function EVEN(state) {
  45801. var stack = state.stack;
  45802. var n = stack.pop();
  45803. if (exports.DEBUG) {
  45804. console.log(state.step, 'EVEN[]', n);
  45805. }
  45806. stack.push(Math.trunc(n) % 2 ? 0 : 1);
  45807. }
  45808. // IF[] IF test
  45809. // 0x58
  45810. function IF(state) {
  45811. var test = state.stack.pop();
  45812. if (exports.DEBUG) {
  45813. console.log(state.step, 'IF[]', test);
  45814. }
  45815. // if test is true it just continues
  45816. // if not the ip is skipped until matching ELSE or EIF
  45817. if (!test) {
  45818. skip(state, true);
  45819. if (exports.DEBUG) {
  45820. console.log(state.step, 'EIF[]');
  45821. }
  45822. }
  45823. }
  45824. // EIF[] End IF
  45825. // 0x59
  45826. function EIF(state) {
  45827. // this can be reached normally when
  45828. // executing an else branch.
  45829. // -> just ignore it
  45830. if (exports.DEBUG) {
  45831. console.log(state.step, 'EIF[]');
  45832. }
  45833. }
  45834. // AND[] logical AND
  45835. // 0x5A
  45836. function AND(state) {
  45837. var stack = state.stack;
  45838. var e2 = stack.pop();
  45839. var e1 = stack.pop();
  45840. if (exports.DEBUG) {
  45841. console.log(state.step, 'AND[]', e2, e1);
  45842. }
  45843. stack.push(e2 && e1 ? 1 : 0);
  45844. }
  45845. // OR[] logical OR
  45846. // 0x5B
  45847. function OR(state) {
  45848. var stack = state.stack;
  45849. var e2 = stack.pop();
  45850. var e1 = stack.pop();
  45851. if (exports.DEBUG) {
  45852. console.log(state.step, 'OR[]', e2, e1);
  45853. }
  45854. stack.push(e2 || e1 ? 1 : 0);
  45855. }
  45856. // NOT[] logical NOT
  45857. // 0x5C
  45858. function NOT(state) {
  45859. var stack = state.stack;
  45860. var e = stack.pop();
  45861. if (exports.DEBUG) {
  45862. console.log(state.step, 'NOT[]', e);
  45863. }
  45864. stack.push(e ? 0 : 1);
  45865. }
  45866. // DELTAP1[] DELTA exception P1
  45867. // DELTAP2[] DELTA exception P2
  45868. // DELTAP3[] DELTA exception P3
  45869. // 0x5D, 0x71, 0x72
  45870. function DELTAP123(b, state) {
  45871. var stack = state.stack;
  45872. var n = stack.pop();
  45873. var fv = state.fv;
  45874. var pv = state.pv;
  45875. var ppem = state.ppem;
  45876. var base = state.deltaBase + (b - 1) * 16;
  45877. var ds = state.deltaShift;
  45878. var z0 = state.z0;
  45879. if (exports.DEBUG) {
  45880. console.log(state.step, 'DELTAP[' + b + ']', n, stack);
  45881. }
  45882. for (var i = 0; i < n; i++) {
  45883. var pi = stack.pop();
  45884. var arg = stack.pop();
  45885. var appem = base + ((arg & 0xf0) >> 4);
  45886. if (appem !== ppem) {
  45887. continue;
  45888. }
  45889. var mag = (arg & 0x0f) - 8;
  45890. if (mag >= 0) {
  45891. mag++;
  45892. }
  45893. if (exports.DEBUG) {
  45894. console.log(state.step, 'DELTAPFIX', pi, 'by', mag * ds);
  45895. }
  45896. var p = z0[pi];
  45897. fv.setRelative(p, p, mag * ds, pv);
  45898. }
  45899. }
  45900. // SDB[] Set Delta Base in the graphics state
  45901. // 0x5E
  45902. function SDB(state) {
  45903. var stack = state.stack;
  45904. var n = stack.pop();
  45905. if (exports.DEBUG) {
  45906. console.log(state.step, 'SDB[]', n);
  45907. }
  45908. state.deltaBase = n;
  45909. }
  45910. // SDS[] Set Delta Shift in the graphics state
  45911. // 0x5F
  45912. function SDS(state) {
  45913. var stack = state.stack;
  45914. var n = stack.pop();
  45915. if (exports.DEBUG) {
  45916. console.log(state.step, 'SDS[]', n);
  45917. }
  45918. state.deltaShift = Math.pow(0.5, n);
  45919. }
  45920. // ADD[] ADD
  45921. // 0x60
  45922. function ADD(state) {
  45923. var stack = state.stack;
  45924. var n2 = stack.pop();
  45925. var n1 = stack.pop();
  45926. if (exports.DEBUG) {
  45927. console.log(state.step, 'ADD[]', n2, n1);
  45928. }
  45929. stack.push(n1 + n2);
  45930. }
  45931. // SUB[] SUB
  45932. // 0x61
  45933. function SUB(state) {
  45934. var stack = state.stack;
  45935. var n2 = stack.pop();
  45936. var n1 = stack.pop();
  45937. if (exports.DEBUG) {
  45938. console.log(state.step, 'SUB[]', n2, n1);
  45939. }
  45940. stack.push(n1 - n2);
  45941. }
  45942. // DIV[] DIV
  45943. // 0x62
  45944. function DIV(state) {
  45945. var stack = state.stack;
  45946. var n2 = stack.pop();
  45947. var n1 = stack.pop();
  45948. if (exports.DEBUG) {
  45949. console.log(state.step, 'DIV[]', n2, n1);
  45950. }
  45951. stack.push(n1 * 64 / n2);
  45952. }
  45953. // MUL[] MUL
  45954. // 0x63
  45955. function MUL(state) {
  45956. var stack = state.stack;
  45957. var n2 = stack.pop();
  45958. var n1 = stack.pop();
  45959. if (exports.DEBUG) {
  45960. console.log(state.step, 'MUL[]', n2, n1);
  45961. }
  45962. stack.push(n1 * n2 / 64);
  45963. }
  45964. // ABS[] ABSolute value
  45965. // 0x64
  45966. function ABS(state) {
  45967. var stack = state.stack;
  45968. var n = stack.pop();
  45969. if (exports.DEBUG) {
  45970. console.log(state.step, 'ABS[]', n);
  45971. }
  45972. stack.push(Math.abs(n));
  45973. }
  45974. // NEG[] NEGate
  45975. // 0x65
  45976. function NEG(state) {
  45977. var stack = state.stack;
  45978. var n = stack.pop();
  45979. if (exports.DEBUG) {
  45980. console.log(state.step, 'NEG[]', n);
  45981. }
  45982. stack.push(-n);
  45983. }
  45984. // FLOOR[] FLOOR
  45985. // 0x66
  45986. function FLOOR(state) {
  45987. var stack = state.stack;
  45988. var n = stack.pop();
  45989. if (exports.DEBUG) {
  45990. console.log(state.step, 'FLOOR[]', n);
  45991. }
  45992. stack.push(Math.floor(n / 0x40) * 0x40);
  45993. }
  45994. // CEILING[] CEILING
  45995. // 0x67
  45996. function CEILING(state) {
  45997. var stack = state.stack;
  45998. var n = stack.pop();
  45999. if (exports.DEBUG) {
  46000. console.log(state.step, 'CEILING[]', n);
  46001. }
  46002. stack.push(Math.ceil(n / 0x40) * 0x40);
  46003. }
  46004. // ROUND[ab] ROUND value
  46005. // 0x68-0x6B
  46006. function ROUND(dt, state) {
  46007. var stack = state.stack;
  46008. var n = stack.pop();
  46009. if (exports.DEBUG) {
  46010. console.log(state.step, 'ROUND[]');
  46011. }
  46012. stack.push(state.round(n / 0x40) * 0x40);
  46013. }
  46014. // WCVTF[] Write Control Value Table in Funits
  46015. // 0x70
  46016. function WCVTF(state) {
  46017. var stack = state.stack;
  46018. var v = stack.pop();
  46019. var l = stack.pop();
  46020. if (exports.DEBUG) {
  46021. console.log(state.step, 'WCVTF[]', v, l);
  46022. }
  46023. state.cvt[l] = v * state.ppem / state.font.unitsPerEm;
  46024. }
  46025. // DELTAC1[] DELTA exception C1
  46026. // DELTAC2[] DELTA exception C2
  46027. // DELTAC3[] DELTA exception C3
  46028. // 0x73, 0x74, 0x75
  46029. function DELTAC123(b, state) {
  46030. var stack = state.stack;
  46031. var n = stack.pop();
  46032. var ppem = state.ppem;
  46033. var base = state.deltaBase + (b - 1) * 16;
  46034. var ds = state.deltaShift;
  46035. if (exports.DEBUG) {
  46036. console.log(state.step, 'DELTAC[' + b + ']', n, stack);
  46037. }
  46038. for (var i = 0; i < n; i++) {
  46039. var c = stack.pop();
  46040. var arg = stack.pop();
  46041. var appem = base + ((arg & 0xf0) >> 4);
  46042. if (appem !== ppem) {
  46043. continue;
  46044. }
  46045. var mag = (arg & 0x0f) - 8;
  46046. if (mag >= 0) {
  46047. mag++;
  46048. }
  46049. var delta = mag * ds;
  46050. if (exports.DEBUG) {
  46051. console.log(state.step, 'DELTACFIX', c, 'by', delta);
  46052. }
  46053. state.cvt[c] += delta;
  46054. }
  46055. }
  46056. // SROUND[] Super ROUND
  46057. // 0x76
  46058. function SROUND(state) {
  46059. var n = state.stack.pop();
  46060. if (exports.DEBUG) {
  46061. console.log(state.step, 'SROUND[]', n);
  46062. }
  46063. state.round = roundSuper;
  46064. var period;
  46065. switch (n & 0xc0) {
  46066. case 0x00:
  46067. period = 0.5;
  46068. break;
  46069. case 0x40:
  46070. period = 1;
  46071. break;
  46072. case 0x80:
  46073. period = 2;
  46074. break;
  46075. default:
  46076. throw new Error('invalid SROUND value');
  46077. }
  46078. state.srPeriod = period;
  46079. switch (n & 0x30) {
  46080. case 0x00:
  46081. state.srPhase = 0;
  46082. break;
  46083. case 0x10:
  46084. state.srPhase = 0.25 * period;
  46085. break;
  46086. case 0x20:
  46087. state.srPhase = 0.5 * period;
  46088. break;
  46089. case 0x30:
  46090. state.srPhase = 0.75 * period;
  46091. break;
  46092. default:
  46093. throw new Error('invalid SROUND value');
  46094. }
  46095. n &= 0x0f;
  46096. if (n === 0) {
  46097. state.srThreshold = 0;
  46098. } else {
  46099. state.srThreshold = (n / 8 - 0.5) * period;
  46100. }
  46101. }
  46102. // S45ROUND[] Super ROUND 45 degrees
  46103. // 0x77
  46104. function S45ROUND(state) {
  46105. var n = state.stack.pop();
  46106. if (exports.DEBUG) {
  46107. console.log(state.step, 'S45ROUND[]', n);
  46108. }
  46109. state.round = roundSuper;
  46110. var period;
  46111. switch (n & 0xc0) {
  46112. case 0x00:
  46113. period = Math.sqrt(2) / 2;
  46114. break;
  46115. case 0x40:
  46116. period = Math.sqrt(2);
  46117. break;
  46118. case 0x80:
  46119. period = 2 * Math.sqrt(2);
  46120. break;
  46121. default:
  46122. throw new Error('invalid S45ROUND value');
  46123. }
  46124. state.srPeriod = period;
  46125. switch (n & 0x30) {
  46126. case 0x00:
  46127. state.srPhase = 0;
  46128. break;
  46129. case 0x10:
  46130. state.srPhase = 0.25 * period;
  46131. break;
  46132. case 0x20:
  46133. state.srPhase = 0.5 * period;
  46134. break;
  46135. case 0x30:
  46136. state.srPhase = 0.75 * period;
  46137. break;
  46138. default:
  46139. throw new Error('invalid S45ROUND value');
  46140. }
  46141. n &= 0x0f;
  46142. if (n === 0) {
  46143. state.srThreshold = 0;
  46144. } else {
  46145. state.srThreshold = (n / 8 - 0.5) * period;
  46146. }
  46147. }
  46148. // ROFF[] Round Off
  46149. // 0x7A
  46150. function ROFF(state) {
  46151. if (exports.DEBUG) {
  46152. console.log(state.step, 'ROFF[]');
  46153. }
  46154. state.round = roundOff;
  46155. }
  46156. // RUTG[] Round Up To Grid
  46157. // 0x7C
  46158. function RUTG(state) {
  46159. if (exports.DEBUG) {
  46160. console.log(state.step, 'RUTG[]');
  46161. }
  46162. state.round = roundUpToGrid;
  46163. }
  46164. // RDTG[] Round Down To Grid
  46165. // 0x7D
  46166. function RDTG(state) {
  46167. if (exports.DEBUG) {
  46168. console.log(state.step, 'RDTG[]');
  46169. }
  46170. state.round = roundDownToGrid;
  46171. }
  46172. // SCANCTRL[] SCAN conversion ConTRoL
  46173. // 0x85
  46174. function SCANCTRL(state) {
  46175. var n = state.stack.pop();
  46176. // ignored by opentype.js
  46177. if (exports.DEBUG) {
  46178. console.log(state.step, 'SCANCTRL[]', n);
  46179. }
  46180. }
  46181. // SDPVTL[a] Set Dual Projection Vector To Line
  46182. // 0x86-0x87
  46183. function SDPVTL(a, state) {
  46184. var stack = state.stack;
  46185. var p2i = stack.pop();
  46186. var p1i = stack.pop();
  46187. var p2 = state.z2[p2i];
  46188. var p1 = state.z1[p1i];
  46189. if (exports.DEBUG) {
  46190. console.log(state.step, 'SDPVTL[' + a + ']', p2i, p1i);
  46191. }
  46192. var dx;
  46193. var dy;
  46194. if (!a) {
  46195. dx = p1.x - p2.x;
  46196. dy = p1.y - p2.y;
  46197. } else {
  46198. dx = p2.y - p1.y;
  46199. dy = p1.x - p2.x;
  46200. }
  46201. state.dpv = getUnitVector(dx, dy);
  46202. }
  46203. // GETINFO[] GET INFOrmation
  46204. // 0x88
  46205. function GETINFO(state) {
  46206. var stack = state.stack;
  46207. var sel = stack.pop();
  46208. var r = 0;
  46209. if (exports.DEBUG) {
  46210. console.log(state.step, 'GETINFO[]', sel);
  46211. }
  46212. // v35 as in no subpixel hinting
  46213. if (sel & 0x01) {
  46214. r = 35;
  46215. }
  46216. // TODO rotation and stretch currently not supported
  46217. // and thus those GETINFO are always 0.
  46218. // opentype.js is always gray scaling
  46219. if (sel & 0x20) {
  46220. r |= 0x1000;
  46221. }
  46222. stack.push(r);
  46223. }
  46224. // ROLL[] ROLL the top three stack elements
  46225. // 0x8A
  46226. function ROLL(state) {
  46227. var stack = state.stack;
  46228. var a = stack.pop();
  46229. var b = stack.pop();
  46230. var c = stack.pop();
  46231. if (exports.DEBUG) {
  46232. console.log(state.step, 'ROLL[]');
  46233. }
  46234. stack.push(b);
  46235. stack.push(a);
  46236. stack.push(c);
  46237. }
  46238. // MAX[] MAXimum of top two stack elements
  46239. // 0x8B
  46240. function MAX(state) {
  46241. var stack = state.stack;
  46242. var e2 = stack.pop();
  46243. var e1 = stack.pop();
  46244. if (exports.DEBUG) {
  46245. console.log(state.step, 'MAX[]', e2, e1);
  46246. }
  46247. stack.push(Math.max(e1, e2));
  46248. }
  46249. // MIN[] MINimum of top two stack elements
  46250. // 0x8C
  46251. function MIN(state) {
  46252. var stack = state.stack;
  46253. var e2 = stack.pop();
  46254. var e1 = stack.pop();
  46255. if (exports.DEBUG) {
  46256. console.log(state.step, 'MIN[]', e2, e1);
  46257. }
  46258. stack.push(Math.min(e1, e2));
  46259. }
  46260. // SCANTYPE[] SCANTYPE
  46261. // 0x8D
  46262. function SCANTYPE(state) {
  46263. var n = state.stack.pop();
  46264. // ignored by opentype.js
  46265. if (exports.DEBUG) {
  46266. console.log(state.step, 'SCANTYPE[]', n);
  46267. }
  46268. }
  46269. // INSTCTRL[] INSTCTRL
  46270. // 0x8D
  46271. function INSTCTRL(state) {
  46272. var s = state.stack.pop();
  46273. var v = state.stack.pop();
  46274. if (exports.DEBUG) {
  46275. console.log(state.step, 'INSTCTRL[]', s, v);
  46276. }
  46277. switch (s) {
  46278. case 1:
  46279. state.inhibitGridFit = !!v;
  46280. return;
  46281. case 2:
  46282. state.ignoreCvt = !!v;
  46283. return;
  46284. default:
  46285. throw new Error('invalid INSTCTRL[] selector');
  46286. }
  46287. }
  46288. // PUSHB[abc] PUSH Bytes
  46289. // 0xB0-0xB7
  46290. function PUSHB(n, state) {
  46291. var stack = state.stack;
  46292. var prog = state.prog;
  46293. var ip = state.ip;
  46294. if (exports.DEBUG) {
  46295. console.log(state.step, 'PUSHB[' + n + ']');
  46296. }
  46297. for (var i = 0; i < n; i++) {
  46298. stack.push(prog[++ip]);
  46299. }
  46300. state.ip = ip;
  46301. }
  46302. // PUSHW[abc] PUSH Words
  46303. // 0xB8-0xBF
  46304. function PUSHW(n, state) {
  46305. var ip = state.ip;
  46306. var prog = state.prog;
  46307. var stack = state.stack;
  46308. if (exports.DEBUG) {
  46309. console.log(state.ip, 'PUSHW[' + n + ']');
  46310. }
  46311. for (var i = 0; i < n; i++) {
  46312. var w = (prog[++ip] << 8) | prog[++ip];
  46313. if (w & 0x8000) {
  46314. w = -((w ^ 0xffff) + 1);
  46315. }
  46316. stack.push(w);
  46317. }
  46318. state.ip = ip;
  46319. }
  46320. // MDRP[abcde] Move Direct Relative Point
  46321. // 0xD0-0xEF
  46322. // (if indirect is 0)
  46323. //
  46324. // and
  46325. //
  46326. // MIRP[abcde] Move Indirect Relative Point
  46327. // 0xE0-0xFF
  46328. // (if indirect is 1)
  46329. function MDRP_MIRP(indirect, setRp0, keepD, ro, dt, state) {
  46330. var stack = state.stack;
  46331. var cvte = indirect && stack.pop();
  46332. var pi = stack.pop();
  46333. var rp0i = state.rp0;
  46334. var rp = state.z0[rp0i];
  46335. var p = state.z1[pi];
  46336. var md = state.minDis;
  46337. var fv = state.fv;
  46338. var pv = state.dpv;
  46339. var od; // original distance
  46340. var d; // moving distance
  46341. var sign; // sign of distance
  46342. var cv;
  46343. d = od = pv.distance(p, rp, true, true);
  46344. sign = d >= 0 ? 1 : -1; // Math.sign would be 0 in case of 0
  46345. // TODO consider autoFlip
  46346. d = Math.abs(d);
  46347. if (indirect) {
  46348. cv = state.cvt[cvte];
  46349. if (ro && Math.abs(d - cv) < state.cvCutIn) {
  46350. d = cv;
  46351. }
  46352. }
  46353. if (keepD && d < md) {
  46354. d = md;
  46355. }
  46356. if (ro) {
  46357. d = state.round(d);
  46358. }
  46359. fv.setRelative(p, rp, sign * d, pv);
  46360. fv.touch(p);
  46361. if (exports.DEBUG) {
  46362. console.log(
  46363. state.step,
  46364. (indirect ? 'MIRP[' : 'MDRP[') +
  46365. (setRp0 ? 'M' : 'm') +
  46366. (keepD ? '>' : '_') +
  46367. (ro ? 'R' : '_') +
  46368. (dt === 0 ? 'Gr' : dt === 1 ? 'Bl' : dt === 2 ? 'Wh' : '') +
  46369. ']',
  46370. indirect ? cvte + '(' + state.cvt[cvte] + ',' + cv + ')' : '',
  46371. pi,
  46372. '(d =',
  46373. od,
  46374. '->',
  46375. sign * d,
  46376. ')'
  46377. );
  46378. }
  46379. state.rp1 = state.rp0;
  46380. state.rp2 = pi;
  46381. if (setRp0) {
  46382. state.rp0 = pi;
  46383. }
  46384. }
  46385. /*
  46386. * The instruction table.
  46387. */
  46388. instructionTable = [
  46389. /* 0x00 */ SVTCA.bind(undefined, yUnitVector),
  46390. /* 0x01 */ SVTCA.bind(undefined, xUnitVector),
  46391. /* 0x02 */ SPVTCA.bind(undefined, yUnitVector),
  46392. /* 0x03 */ SPVTCA.bind(undefined, xUnitVector),
  46393. /* 0x04 */ SFVTCA.bind(undefined, yUnitVector),
  46394. /* 0x05 */ SFVTCA.bind(undefined, xUnitVector),
  46395. /* 0x06 */ SPVTL.bind(undefined, 0),
  46396. /* 0x07 */ SPVTL.bind(undefined, 1),
  46397. /* 0x08 */ SFVTL.bind(undefined, 0),
  46398. /* 0x09 */ SFVTL.bind(undefined, 1),
  46399. /* 0x0A */ SPVFS,
  46400. /* 0x0B */ SFVFS,
  46401. /* 0x0C */ GPV,
  46402. /* 0x0D */ GFV,
  46403. /* 0x0E */ SFVTPV,
  46404. /* 0x0F */ ISECT,
  46405. /* 0x10 */ SRP0,
  46406. /* 0x11 */ SRP1,
  46407. /* 0x12 */ SRP2,
  46408. /* 0x13 */ SZP0,
  46409. /* 0x14 */ SZP1,
  46410. /* 0x15 */ SZP2,
  46411. /* 0x16 */ SZPS,
  46412. /* 0x17 */ SLOOP,
  46413. /* 0x18 */ RTG,
  46414. /* 0x19 */ RTHG,
  46415. /* 0x1A */ SMD,
  46416. /* 0x1B */ ELSE,
  46417. /* 0x1C */ JMPR,
  46418. /* 0x1D */ SCVTCI,
  46419. /* 0x1E */ undefined, // TODO SSWCI
  46420. /* 0x1F */ undefined, // TODO SSW
  46421. /* 0x20 */ DUP,
  46422. /* 0x21 */ POP,
  46423. /* 0x22 */ CLEAR,
  46424. /* 0x23 */ SWAP,
  46425. /* 0x24 */ DEPTH,
  46426. /* 0x25 */ CINDEX,
  46427. /* 0x26 */ MINDEX,
  46428. /* 0x27 */ undefined, // TODO ALIGNPTS
  46429. /* 0x28 */ undefined,
  46430. /* 0x29 */ undefined, // TODO UTP
  46431. /* 0x2A */ LOOPCALL,
  46432. /* 0x2B */ CALL,
  46433. /* 0x2C */ FDEF,
  46434. /* 0x2D */ undefined, // ENDF (eaten by FDEF)
  46435. /* 0x2E */ MDAP.bind(undefined, 0),
  46436. /* 0x2F */ MDAP.bind(undefined, 1),
  46437. /* 0x30 */ IUP.bind(undefined, yUnitVector),
  46438. /* 0x31 */ IUP.bind(undefined, xUnitVector),
  46439. /* 0x32 */ SHP.bind(undefined, 0),
  46440. /* 0x33 */ SHP.bind(undefined, 1),
  46441. /* 0x34 */ SHC.bind(undefined, 0),
  46442. /* 0x35 */ SHC.bind(undefined, 1),
  46443. /* 0x36 */ SHZ.bind(undefined, 0),
  46444. /* 0x37 */ SHZ.bind(undefined, 1),
  46445. /* 0x38 */ SHPIX,
  46446. /* 0x39 */ IP,
  46447. /* 0x3A */ MSIRP.bind(undefined, 0),
  46448. /* 0x3B */ MSIRP.bind(undefined, 1),
  46449. /* 0x3C */ ALIGNRP,
  46450. /* 0x3D */ RTDG,
  46451. /* 0x3E */ MIAP.bind(undefined, 0),
  46452. /* 0x3F */ MIAP.bind(undefined, 1),
  46453. /* 0x40 */ NPUSHB,
  46454. /* 0x41 */ NPUSHW,
  46455. /* 0x42 */ WS,
  46456. /* 0x43 */ RS,
  46457. /* 0x44 */ WCVTP,
  46458. /* 0x45 */ RCVT,
  46459. /* 0x46 */ GC.bind(undefined, 0),
  46460. /* 0x47 */ GC.bind(undefined, 1),
  46461. /* 0x48 */ undefined, // TODO SCFS
  46462. /* 0x49 */ MD.bind(undefined, 0),
  46463. /* 0x4A */ MD.bind(undefined, 1),
  46464. /* 0x4B */ MPPEM,
  46465. /* 0x4C */ undefined, // TODO MPS
  46466. /* 0x4D */ FLIPON,
  46467. /* 0x4E */ undefined, // TODO FLIPOFF
  46468. /* 0x4F */ undefined, // TODO DEBUG
  46469. /* 0x50 */ LT,
  46470. /* 0x51 */ LTEQ,
  46471. /* 0x52 */ GT,
  46472. /* 0x53 */ GTEQ,
  46473. /* 0x54 */ EQ,
  46474. /* 0x55 */ NEQ,
  46475. /* 0x56 */ ODD,
  46476. /* 0x57 */ EVEN,
  46477. /* 0x58 */ IF,
  46478. /* 0x59 */ EIF,
  46479. /* 0x5A */ AND,
  46480. /* 0x5B */ OR,
  46481. /* 0x5C */ NOT,
  46482. /* 0x5D */ DELTAP123.bind(undefined, 1),
  46483. /* 0x5E */ SDB,
  46484. /* 0x5F */ SDS,
  46485. /* 0x60 */ ADD,
  46486. /* 0x61 */ SUB,
  46487. /* 0x62 */ DIV,
  46488. /* 0x63 */ MUL,
  46489. /* 0x64 */ ABS,
  46490. /* 0x65 */ NEG,
  46491. /* 0x66 */ FLOOR,
  46492. /* 0x67 */ CEILING,
  46493. /* 0x68 */ ROUND.bind(undefined, 0),
  46494. /* 0x69 */ ROUND.bind(undefined, 1),
  46495. /* 0x6A */ ROUND.bind(undefined, 2),
  46496. /* 0x6B */ ROUND.bind(undefined, 3),
  46497. /* 0x6C */ undefined, // TODO NROUND[ab]
  46498. /* 0x6D */ undefined, // TODO NROUND[ab]
  46499. /* 0x6E */ undefined, // TODO NROUND[ab]
  46500. /* 0x6F */ undefined, // TODO NROUND[ab]
  46501. /* 0x70 */ WCVTF,
  46502. /* 0x71 */ DELTAP123.bind(undefined, 2),
  46503. /* 0x72 */ DELTAP123.bind(undefined, 3),
  46504. /* 0x73 */ DELTAC123.bind(undefined, 1),
  46505. /* 0x74 */ DELTAC123.bind(undefined, 2),
  46506. /* 0x75 */ DELTAC123.bind(undefined, 3),
  46507. /* 0x76 */ SROUND,
  46508. /* 0x77 */ S45ROUND,
  46509. /* 0x78 */ undefined, // TODO JROT[]
  46510. /* 0x79 */ undefined, // TODO JROF[]
  46511. /* 0x7A */ ROFF,
  46512. /* 0x7B */ undefined,
  46513. /* 0x7C */ RUTG,
  46514. /* 0x7D */ RDTG,
  46515. /* 0x7E */ POP, // actually SANGW, supposed to do only a pop though
  46516. /* 0x7F */ POP, // actually AA, supposed to do only a pop though
  46517. /* 0x80 */ undefined, // TODO FLIPPT
  46518. /* 0x81 */ undefined, // TODO FLIPRGON
  46519. /* 0x82 */ undefined, // TODO FLIPRGOFF
  46520. /* 0x83 */ undefined,
  46521. /* 0x84 */ undefined,
  46522. /* 0x85 */ SCANCTRL,
  46523. /* 0x86 */ SDPVTL.bind(undefined, 0),
  46524. /* 0x87 */ SDPVTL.bind(undefined, 1),
  46525. /* 0x88 */ GETINFO,
  46526. /* 0x89 */ undefined, // TODO IDEF
  46527. /* 0x8A */ ROLL,
  46528. /* 0x8B */ MAX,
  46529. /* 0x8C */ MIN,
  46530. /* 0x8D */ SCANTYPE,
  46531. /* 0x8E */ INSTCTRL,
  46532. /* 0x8F */ undefined,
  46533. /* 0x90 */ undefined,
  46534. /* 0x91 */ undefined,
  46535. /* 0x92 */ undefined,
  46536. /* 0x93 */ undefined,
  46537. /* 0x94 */ undefined,
  46538. /* 0x95 */ undefined,
  46539. /* 0x96 */ undefined,
  46540. /* 0x97 */ undefined,
  46541. /* 0x98 */ undefined,
  46542. /* 0x99 */ undefined,
  46543. /* 0x9A */ undefined,
  46544. /* 0x9B */ undefined,
  46545. /* 0x9C */ undefined,
  46546. /* 0x9D */ undefined,
  46547. /* 0x9E */ undefined,
  46548. /* 0x9F */ undefined,
  46549. /* 0xA0 */ undefined,
  46550. /* 0xA1 */ undefined,
  46551. /* 0xA2 */ undefined,
  46552. /* 0xA3 */ undefined,
  46553. /* 0xA4 */ undefined,
  46554. /* 0xA5 */ undefined,
  46555. /* 0xA6 */ undefined,
  46556. /* 0xA7 */ undefined,
  46557. /* 0xA8 */ undefined,
  46558. /* 0xA9 */ undefined,
  46559. /* 0xAA */ undefined,
  46560. /* 0xAB */ undefined,
  46561. /* 0xAC */ undefined,
  46562. /* 0xAD */ undefined,
  46563. /* 0xAE */ undefined,
  46564. /* 0xAF */ undefined,
  46565. /* 0xB0 */ PUSHB.bind(undefined, 1),
  46566. /* 0xB1 */ PUSHB.bind(undefined, 2),
  46567. /* 0xB2 */ PUSHB.bind(undefined, 3),
  46568. /* 0xB3 */ PUSHB.bind(undefined, 4),
  46569. /* 0xB4 */ PUSHB.bind(undefined, 5),
  46570. /* 0xB5 */ PUSHB.bind(undefined, 6),
  46571. /* 0xB6 */ PUSHB.bind(undefined, 7),
  46572. /* 0xB7 */ PUSHB.bind(undefined, 8),
  46573. /* 0xB8 */ PUSHW.bind(undefined, 1),
  46574. /* 0xB9 */ PUSHW.bind(undefined, 2),
  46575. /* 0xBA */ PUSHW.bind(undefined, 3),
  46576. /* 0xBB */ PUSHW.bind(undefined, 4),
  46577. /* 0xBC */ PUSHW.bind(undefined, 5),
  46578. /* 0xBD */ PUSHW.bind(undefined, 6),
  46579. /* 0xBE */ PUSHW.bind(undefined, 7),
  46580. /* 0xBF */ PUSHW.bind(undefined, 8),
  46581. /* 0xC0 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 0),
  46582. /* 0xC1 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 1),
  46583. /* 0xC2 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 2),
  46584. /* 0xC3 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 3),
  46585. /* 0xC4 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 0),
  46586. /* 0xC5 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 1),
  46587. /* 0xC6 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 2),
  46588. /* 0xC7 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 3),
  46589. /* 0xC8 */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 0),
  46590. /* 0xC9 */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 1),
  46591. /* 0xCA */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 2),
  46592. /* 0xCB */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 3),
  46593. /* 0xCC */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 0),
  46594. /* 0xCD */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 1),
  46595. /* 0xCE */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 2),
  46596. /* 0xCF */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 3),
  46597. /* 0xD0 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 0),
  46598. /* 0xD1 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 1),
  46599. /* 0xD2 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 2),
  46600. /* 0xD3 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 3),
  46601. /* 0xD4 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 0),
  46602. /* 0xD5 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 1),
  46603. /* 0xD6 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 2),
  46604. /* 0xD7 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 3),
  46605. /* 0xD8 */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 0),
  46606. /* 0xD9 */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 1),
  46607. /* 0xDA */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 2),
  46608. /* 0xDB */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 3),
  46609. /* 0xDC */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 0),
  46610. /* 0xDD */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 1),
  46611. /* 0xDE */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 2),
  46612. /* 0xDF */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 3),
  46613. /* 0xE0 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 0),
  46614. /* 0xE1 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 1),
  46615. /* 0xE2 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 2),
  46616. /* 0xE3 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 3),
  46617. /* 0xE4 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 0),
  46618. /* 0xE5 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 1),
  46619. /* 0xE6 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 2),
  46620. /* 0xE7 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 3),
  46621. /* 0xE8 */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 0),
  46622. /* 0xE9 */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 1),
  46623. /* 0xEA */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 2),
  46624. /* 0xEB */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 3),
  46625. /* 0xEC */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 0),
  46626. /* 0xED */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 1),
  46627. /* 0xEE */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 2),
  46628. /* 0xEF */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 3),
  46629. /* 0xF0 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 0),
  46630. /* 0xF1 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 1),
  46631. /* 0xF2 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 2),
  46632. /* 0xF3 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 3),
  46633. /* 0xF4 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 0),
  46634. /* 0xF5 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 1),
  46635. /* 0xF6 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 2),
  46636. /* 0xF7 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 3),
  46637. /* 0xF8 */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 0),
  46638. /* 0xF9 */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 1),
  46639. /* 0xFA */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 2),
  46640. /* 0xFB */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 3),
  46641. /* 0xFC */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 0),
  46642. /* 0xFD */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 1),
  46643. /* 0xFE */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 2),
  46644. /* 0xFF */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 3)
  46645. ];
  46646. /*****************************
  46647. Mathematical Considerations
  46648. ******************************
  46649. fv ... refers to freedom vector
  46650. pv ... refers to projection vector
  46651. rp ... refers to reference point
  46652. p ... refers to to point being operated on
  46653. d ... refers to distance
  46654. SETRELATIVE:
  46655. ============
  46656. case freedom vector == x-axis:
  46657. ------------------------------
  46658. (pv)
  46659. .-'
  46660. rpd .-'
  46661. .-*
  46662. d .-'90°'
  46663. .-' '
  46664. .-' '
  46665. *-' ' b
  46666. rp '
  46667. '
  46668. '
  46669. p *----------*-------------- (fv)
  46670. pm
  46671. rpdx = rpx + d * pv.x
  46672. rpdy = rpy + d * pv.y
  46673. equation of line b
  46674. y - rpdy = pvns * (x- rpdx)
  46675. y = p.y
  46676. x = rpdx + ( p.y - rpdy ) / pvns
  46677. case freedom vector == y-axis:
  46678. ------------------------------
  46679. * pm
  46680. |\
  46681. | \
  46682. | \
  46683. | \
  46684. | \
  46685. | \
  46686. | \
  46687. | \
  46688. | \
  46689. | \ b
  46690. | \
  46691. | \
  46692. | \ .-' (pv)
  46693. | 90° \.-'
  46694. | .-'* rpd
  46695. | .-'
  46696. * *-' d
  46697. p rp
  46698. rpdx = rpx + d * pv.x
  46699. rpdy = rpy + d * pv.y
  46700. equation of line b:
  46701. pvns ... normal slope to pv
  46702. y - rpdy = pvns * (x - rpdx)
  46703. x = p.x
  46704. y = rpdy + pvns * (p.x - rpdx)
  46705. generic case:
  46706. -------------
  46707. .'(fv)
  46708. .'
  46709. .* pm
  46710. .' !
  46711. .' .
  46712. .' !
  46713. .' . b
  46714. .' !
  46715. * .
  46716. p !
  46717. 90° . ... (pv)
  46718. ...-*-'''
  46719. ...---''' rpd
  46720. ...---''' d
  46721. *--'''
  46722. rp
  46723. rpdx = rpx + d * pv.x
  46724. rpdy = rpy + d * pv.y
  46725. equation of line b:
  46726. pvns... normal slope to pv
  46727. y - rpdy = pvns * (x - rpdx)
  46728. equation of freedom vector line:
  46729. fvs ... slope of freedom vector (=fy/fx)
  46730. y - py = fvs * (x - px)
  46731. on pm both equations are true for same x/y
  46732. y - rpdy = pvns * (x - rpdx)
  46733. y - py = fvs * (x - px)
  46734. form to y and set equal:
  46735. pvns * (x - rpdx) + rpdy = fvs * (x - px) + py
  46736. expand:
  46737. pvns * x - pvns * rpdx + rpdy = fvs * x - fvs * px + py
  46738. switch:
  46739. fvs * x - fvs * px + py = pvns * x - pvns * rpdx + rpdy
  46740. solve for x:
  46741. fvs * x - pvns * x = fvs * px - pvns * rpdx - py + rpdy
  46742. fvs * px - pvns * rpdx + rpdy - py
  46743. x = -----------------------------------
  46744. fvs - pvns
  46745. and:
  46746. y = fvs * (x - px) + py
  46747. INTERPOLATE:
  46748. ============
  46749. Examples of point interpolation.
  46750. The weight of the movement of the reference point gets bigger
  46751. the further the other reference point is away, thus the safest
  46752. option (that is avoiding 0/0 divisions) is to weight the
  46753. original distance of the other point by the sum of both distances.
  46754. If the sum of both distances is 0, then move the point by the
  46755. arithmetic average of the movement of both reference points.
  46756. (+6)
  46757. rp1o *---->*rp1
  46758. . . (+12)
  46759. . . rp2o *---------->* rp2
  46760. . . . .
  46761. . . . .
  46762. . 10 20 . .
  46763. |.........|...................| .
  46764. . . .
  46765. . . (+8) .
  46766. po *------>*p .
  46767. . . .
  46768. . 12 . 24 .
  46769. |...........|.......................|
  46770. 36
  46771. -------
  46772. (+10)
  46773. rp1o *-------->*rp1
  46774. . . (-10)
  46775. . . rp2 *<---------* rpo2
  46776. . . . .
  46777. . . . .
  46778. . 10 . 30 . .
  46779. |.........|.............................|
  46780. . .
  46781. . (+5) .
  46782. po *--->* p .
  46783. . . .
  46784. . . 20 .
  46785. |....|..............|
  46786. 5 15
  46787. -------
  46788. (+10)
  46789. rp1o *-------->*rp1
  46790. . .
  46791. . .
  46792. rp2o *-------->*rp2
  46793. (+10)
  46794. po *-------->* p
  46795. -------
  46796. (+10)
  46797. rp1o *-------->*rp1
  46798. . .
  46799. . .(+30)
  46800. rp2o *---------------------------->*rp2
  46801. (+25)
  46802. po *----------------------->* p
  46803. vim: set ts=4 sw=4 expandtab:
  46804. *****/
  46805. // The Font object
  46806. // This code is based on Array.from implementation for strings in https://github.com/mathiasbynens/Array.from
  46807. var arrayFromString =
  46808. Array.from ||
  46809. function(s) {
  46810. return (
  46811. s.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]?|[^\uD800-\uDFFF]|./g) || []
  46812. );
  46813. };
  46814. /**
  46815. * @typedef FontOptions
  46816. * @type Object
  46817. * @property {Boolean} empty - whether to create a new empty font
  46818. * @property {string} familyName
  46819. * @property {string} styleName
  46820. * @property {string=} fullName
  46821. * @property {string=} postScriptName
  46822. * @property {string=} designer
  46823. * @property {string=} designerURL
  46824. * @property {string=} manufacturer
  46825. * @property {string=} manufacturerURL
  46826. * @property {string=} license
  46827. * @property {string=} licenseURL
  46828. * @property {string=} version
  46829. * @property {string=} description
  46830. * @property {string=} copyright
  46831. * @property {string=} trademark
  46832. * @property {Number} unitsPerEm
  46833. * @property {Number} ascender
  46834. * @property {Number} descender
  46835. * @property {Number} createdTimestamp
  46836. * @property {string=} weightClass
  46837. * @property {string=} widthClass
  46838. * @property {string=} fsSelection
  46839. */
  46840. /**
  46841. * A Font represents a loaded OpenType font file.
  46842. * It contains a set of glyphs and methods to draw text on a drawing context,
  46843. * or to get a path representing the text.
  46844. * @exports opentype.Font
  46845. * @class
  46846. * @param {FontOptions}
  46847. * @constructor
  46848. */
  46849. function Font(options) {
  46850. options = options || {};
  46851. if (!options.empty) {
  46852. // Check that we've provided the minimum set of names.
  46853. checkArgument(
  46854. options.familyName,
  46855. 'When creating a new Font object, familyName is required.'
  46856. );
  46857. checkArgument(
  46858. options.styleName,
  46859. 'When creating a new Font object, styleName is required.'
  46860. );
  46861. checkArgument(
  46862. options.unitsPerEm,
  46863. 'When creating a new Font object, unitsPerEm is required.'
  46864. );
  46865. checkArgument(
  46866. options.ascender,
  46867. 'When creating a new Font object, ascender is required.'
  46868. );
  46869. checkArgument(
  46870. options.descender,
  46871. 'When creating a new Font object, descender is required.'
  46872. );
  46873. checkArgument(
  46874. options.descender < 0,
  46875. 'Descender should be negative (e.g. -512).'
  46876. );
  46877. // OS X will complain if the names are empty, so we put a single space everywhere by default.
  46878. this.names = {
  46879. fontFamily: { en: options.familyName || ' ' },
  46880. fontSubfamily: { en: options.styleName || ' ' },
  46881. fullName: {
  46882. en: options.fullName || options.familyName + ' ' + options.styleName
  46883. },
  46884. // postScriptName may not contain any whitespace
  46885. postScriptName: {
  46886. en:
  46887. options.postScriptName ||
  46888. (options.familyName + options.styleName).replace(/\s/g, '')
  46889. },
  46890. designer: { en: options.designer || ' ' },
  46891. designerURL: { en: options.designerURL || ' ' },
  46892. manufacturer: { en: options.manufacturer || ' ' },
  46893. manufacturerURL: { en: options.manufacturerURL || ' ' },
  46894. license: { en: options.license || ' ' },
  46895. licenseURL: { en: options.licenseURL || ' ' },
  46896. version: { en: options.version || 'Version 0.1' },
  46897. description: { en: options.description || ' ' },
  46898. copyright: { en: options.copyright || ' ' },
  46899. trademark: { en: options.trademark || ' ' }
  46900. };
  46901. this.unitsPerEm = options.unitsPerEm || 1000;
  46902. this.ascender = options.ascender;
  46903. this.descender = options.descender;
  46904. this.createdTimestamp = options.createdTimestamp;
  46905. this.tables = {
  46906. os2: {
  46907. usWeightClass: options.weightClass || this.usWeightClasses.MEDIUM,
  46908. usWidthClass: options.widthClass || this.usWidthClasses.MEDIUM,
  46909. fsSelection: options.fsSelection || this.fsSelectionValues.REGULAR
  46910. }
  46911. };
  46912. }
  46913. this.supported = true; // Deprecated: parseBuffer will throw an error if font is not supported.
  46914. this.glyphs = new glyphset.GlyphSet(this, options.glyphs || []);
  46915. this.encoding = new DefaultEncoding(this);
  46916. this.position = new Position(this);
  46917. this.substitution = new Substitution(this);
  46918. this.tables = this.tables || {};
  46919. Object.defineProperty(this, 'hinting', {
  46920. get: function() {
  46921. if (this._hinting) {
  46922. return this._hinting;
  46923. }
  46924. if (this.outlinesFormat === 'truetype') {
  46925. return (this._hinting = new Hinting(this));
  46926. }
  46927. }
  46928. });
  46929. }
  46930. /**
  46931. * Check if the font has a glyph for the given character.
  46932. * @param {string}
  46933. * @return {Boolean}
  46934. */
  46935. Font.prototype.hasChar = function(c) {
  46936. return this.encoding.charToGlyphIndex(c) !== null;
  46937. };
  46938. /**
  46939. * Convert the given character to a single glyph index.
  46940. * Note that this function assumes that there is a one-to-one mapping between
  46941. * the given character and a glyph; for complex scripts this might not be the case.
  46942. * @param {string}
  46943. * @return {Number}
  46944. */
  46945. Font.prototype.charToGlyphIndex = function(s) {
  46946. return this.encoding.charToGlyphIndex(s);
  46947. };
  46948. /**
  46949. * Convert the given character to a single Glyph object.
  46950. * Note that this function assumes that there is a one-to-one mapping between
  46951. * the given character and a glyph; for complex scripts this might not be the case.
  46952. * @param {string}
  46953. * @return {opentype.Glyph}
  46954. */
  46955. Font.prototype.charToGlyph = function(c) {
  46956. var glyphIndex = this.charToGlyphIndex(c);
  46957. var glyph = this.glyphs.get(glyphIndex);
  46958. if (!glyph) {
  46959. // .notdef
  46960. glyph = this.glyphs.get(0);
  46961. }
  46962. return glyph;
  46963. };
  46964. /**
  46965. * Convert the given text to a list of Glyph objects.
  46966. * Note that there is no strict one-to-one mapping between characters and
  46967. * glyphs, so the list of returned glyphs can be larger or smaller than the
  46968. * length of the given string.
  46969. * @param {string}
  46970. * @param {GlyphRenderOptions} [options]
  46971. * @return {opentype.Glyph[]}
  46972. */
  46973. Font.prototype.stringToGlyphs = function(s, options) {
  46974. var this$1 = this;
  46975. options = options || this.defaultRenderOptions;
  46976. // Get glyph indexes
  46977. var chars = arrayFromString(s);
  46978. var indexes = [];
  46979. for (var i = 0; i < chars.length; i += 1) {
  46980. var c = chars[i];
  46981. indexes.push(this$1.charToGlyphIndex(c));
  46982. }
  46983. var length = indexes.length;
  46984. // Apply substitutions on glyph indexes
  46985. if (options.features) {
  46986. var script = options.script || this.substitution.getDefaultScriptName();
  46987. var manyToOne = [];
  46988. if (options.features.liga) {
  46989. manyToOne = manyToOne.concat(
  46990. this.substitution.getFeature('liga', script, options.language)
  46991. );
  46992. }
  46993. if (options.features.rlig) {
  46994. manyToOne = manyToOne.concat(
  46995. this.substitution.getFeature('rlig', script, options.language)
  46996. );
  46997. }
  46998. for (var i$1 = 0; i$1 < length; i$1 += 1) {
  46999. for (var j = 0; j < manyToOne.length; j++) {
  47000. var ligature = manyToOne[j];
  47001. var components = ligature.sub;
  47002. var compCount = components.length;
  47003. var k = 0;
  47004. while (k < compCount && components[k] === indexes[i$1 + k]) {
  47005. k++;
  47006. }
  47007. if (k === compCount) {
  47008. indexes.splice(i$1, compCount, ligature.by);
  47009. length = length - compCount + 1;
  47010. }
  47011. }
  47012. }
  47013. }
  47014. // convert glyph indexes to glyph objects
  47015. var glyphs = new Array(length);
  47016. var notdef = this.glyphs.get(0);
  47017. for (var i$2 = 0; i$2 < length; i$2 += 1) {
  47018. glyphs[i$2] = this$1.glyphs.get(indexes[i$2]) || notdef;
  47019. }
  47020. return glyphs;
  47021. };
  47022. /**
  47023. * @param {string}
  47024. * @return {Number}
  47025. */
  47026. Font.prototype.nameToGlyphIndex = function(name) {
  47027. return this.glyphNames.nameToGlyphIndex(name);
  47028. };
  47029. /**
  47030. * @param {string}
  47031. * @return {opentype.Glyph}
  47032. */
  47033. Font.prototype.nameToGlyph = function(name) {
  47034. var glyphIndex = this.nameToGlyphIndex(name);
  47035. var glyph = this.glyphs.get(glyphIndex);
  47036. if (!glyph) {
  47037. // .notdef
  47038. glyph = this.glyphs.get(0);
  47039. }
  47040. return glyph;
  47041. };
  47042. /**
  47043. * @param {Number}
  47044. * @return {String}
  47045. */
  47046. Font.prototype.glyphIndexToName = function(gid) {
  47047. if (!this.glyphNames.glyphIndexToName) {
  47048. return '';
  47049. }
  47050. return this.glyphNames.glyphIndexToName(gid);
  47051. };
  47052. /**
  47053. * Retrieve the value of the kerning pair between the left glyph (or its index)
  47054. * and the right glyph (or its index). If no kerning pair is found, return 0.
  47055. * The kerning value gets added to the advance width when calculating the spacing
  47056. * between glyphs.
  47057. * For GPOS kerning, this method uses the default script and language, which covers
  47058. * most use cases. To have greater control, use font.position.getKerningValue .
  47059. * @param {opentype.Glyph} leftGlyph
  47060. * @param {opentype.Glyph} rightGlyph
  47061. * @return {Number}
  47062. */
  47063. Font.prototype.getKerningValue = function(leftGlyph, rightGlyph) {
  47064. leftGlyph = leftGlyph.index || leftGlyph;
  47065. rightGlyph = rightGlyph.index || rightGlyph;
  47066. var gposKerning = this.position.defaultKerningTables;
  47067. if (gposKerning) {
  47068. return this.position.getKerningValue(gposKerning, leftGlyph, rightGlyph);
  47069. }
  47070. // "kern" table
  47071. return this.kerningPairs[leftGlyph + ',' + rightGlyph] || 0;
  47072. };
  47073. /**
  47074. * @typedef GlyphRenderOptions
  47075. * @type Object
  47076. * @property {string} [script] - script used to determine which features to apply. By default, 'DFLT' or 'latn' is used.
  47077. * See https://www.microsoft.com/typography/otspec/scripttags.htm
  47078. * @property {string} [language='dflt'] - language system used to determine which features to apply.
  47079. * See https://www.microsoft.com/typography/developers/opentype/languagetags.aspx
  47080. * @property {boolean} [kerning=true] - whether to include kerning values
  47081. * @property {object} [features] - OpenType Layout feature tags. Used to enable or disable the features of the given script/language system.
  47082. * See https://www.microsoft.com/typography/otspec/featuretags.htm
  47083. */
  47084. Font.prototype.defaultRenderOptions = {
  47085. kerning: true,
  47086. features: {
  47087. liga: true,
  47088. rlig: true
  47089. }
  47090. };
  47091. /**
  47092. * Helper function that invokes the given callback for each glyph in the given text.
  47093. * The callback gets `(glyph, x, y, fontSize, options)`.* @param {string} text
  47094. * @param {string} text - The text to apply.
  47095. * @param {number} [x=0] - Horizontal position of the beginning of the text.
  47096. * @param {number} [y=0] - Vertical position of the *baseline* of the text.
  47097. * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
  47098. * @param {GlyphRenderOptions=} options
  47099. * @param {Function} callback
  47100. */
  47101. Font.prototype.forEachGlyph = function(
  47102. text,
  47103. x,
  47104. y,
  47105. fontSize,
  47106. options,
  47107. callback
  47108. ) {
  47109. var this$1 = this;
  47110. x = x !== undefined ? x : 0;
  47111. y = y !== undefined ? y : 0;
  47112. fontSize = fontSize !== undefined ? fontSize : 72;
  47113. options = options || this.defaultRenderOptions;
  47114. var fontScale = 1 / this.unitsPerEm * fontSize;
  47115. var glyphs = this.stringToGlyphs(text, options);
  47116. var kerningLookups;
  47117. if (options.kerning) {
  47118. var script = options.script || this.position.getDefaultScriptName();
  47119. kerningLookups = this.position.getKerningTables(script, options.language);
  47120. }
  47121. for (var i = 0; i < glyphs.length; i += 1) {
  47122. var glyph = glyphs[i];
  47123. callback.call(this$1, glyph, x, y, fontSize, options);
  47124. if (glyph.advanceWidth) {
  47125. x += glyph.advanceWidth * fontScale;
  47126. }
  47127. if (options.kerning && i < glyphs.length - 1) {
  47128. // We should apply position adjustment lookups in a more generic way.
  47129. // Here we only use the xAdvance value.
  47130. var kerningValue = kerningLookups
  47131. ? this$1.position.getKerningValue(
  47132. kerningLookups,
  47133. glyph.index,
  47134. glyphs[i + 1].index
  47135. )
  47136. : this$1.getKerningValue(glyph, glyphs[i + 1]);
  47137. x += kerningValue * fontScale;
  47138. }
  47139. if (options.letterSpacing) {
  47140. x += options.letterSpacing * fontSize;
  47141. } else if (options.tracking) {
  47142. x += options.tracking / 1000 * fontSize;
  47143. }
  47144. }
  47145. return x;
  47146. };
  47147. /**
  47148. * Create a Path object that represents the given text.
  47149. * @param {string} text - The text to create.
  47150. * @param {number} [x=0] - Horizontal position of the beginning of the text.
  47151. * @param {number} [y=0] - Vertical position of the *baseline* of the text.
  47152. * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
  47153. * @param {GlyphRenderOptions=} options
  47154. * @return {opentype.Path}
  47155. */
  47156. Font.prototype.getPath = function(text, x, y, fontSize, options) {
  47157. var fullPath = new Path();
  47158. this.forEachGlyph(text, x, y, fontSize, options, function(
  47159. glyph,
  47160. gX,
  47161. gY,
  47162. gFontSize
  47163. ) {
  47164. var glyphPath = glyph.getPath(gX, gY, gFontSize, options, this);
  47165. fullPath.extend(glyphPath);
  47166. });
  47167. return fullPath;
  47168. };
  47169. /**
  47170. * Create an array of Path objects that represent the glyphs of a given text.
  47171. * @param {string} text - The text to create.
  47172. * @param {number} [x=0] - Horizontal position of the beginning of the text.
  47173. * @param {number} [y=0] - Vertical position of the *baseline* of the text.
  47174. * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
  47175. * @param {GlyphRenderOptions=} options
  47176. * @return {opentype.Path[]}
  47177. */
  47178. Font.prototype.getPaths = function(text, x, y, fontSize, options) {
  47179. var glyphPaths = [];
  47180. this.forEachGlyph(text, x, y, fontSize, options, function(
  47181. glyph,
  47182. gX,
  47183. gY,
  47184. gFontSize
  47185. ) {
  47186. var glyphPath = glyph.getPath(gX, gY, gFontSize, options, this);
  47187. glyphPaths.push(glyphPath);
  47188. });
  47189. return glyphPaths;
  47190. };
  47191. /**
  47192. * Returns the advance width of a text.
  47193. *
  47194. * This is something different than Path.getBoundingBox() as for example a
  47195. * suffixed whitespace increases the advanceWidth but not the bounding box
  47196. * or an overhanging letter like a calligraphic 'f' might have a quite larger
  47197. * bounding box than its advance width.
  47198. *
  47199. * This corresponds to canvas2dContext.measureText(text).width
  47200. *
  47201. * @param {string} text - The text to create.
  47202. * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
  47203. * @param {GlyphRenderOptions=} options
  47204. * @return advance width
  47205. */
  47206. Font.prototype.getAdvanceWidth = function(text, fontSize, options) {
  47207. return this.forEachGlyph(text, 0, 0, fontSize, options, function() {});
  47208. };
  47209. /**
  47210. * Draw the text on the given drawing context.
  47211. * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.
  47212. * @param {string} text - The text to create.
  47213. * @param {number} [x=0] - Horizontal position of the beginning of the text.
  47214. * @param {number} [y=0] - Vertical position of the *baseline* of the text.
  47215. * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
  47216. * @param {GlyphRenderOptions=} options
  47217. */
  47218. Font.prototype.draw = function(ctx, text, x, y, fontSize, options) {
  47219. this.getPath(text, x, y, fontSize, options).draw(ctx);
  47220. };
  47221. /**
  47222. * Draw the points of all glyphs in the text.
  47223. * On-curve points will be drawn in blue, off-curve points will be drawn in red.
  47224. * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.
  47225. * @param {string} text - The text to create.
  47226. * @param {number} [x=0] - Horizontal position of the beginning of the text.
  47227. * @param {number} [y=0] - Vertical position of the *baseline* of the text.
  47228. * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
  47229. * @param {GlyphRenderOptions=} options
  47230. */
  47231. Font.prototype.drawPoints = function(ctx, text, x, y, fontSize, options) {
  47232. this.forEachGlyph(text, x, y, fontSize, options, function(
  47233. glyph,
  47234. gX,
  47235. gY,
  47236. gFontSize
  47237. ) {
  47238. glyph.drawPoints(ctx, gX, gY, gFontSize);
  47239. });
  47240. };
  47241. /**
  47242. * Draw lines indicating important font measurements for all glyphs in the text.
  47243. * Black lines indicate the origin of the coordinate system (point 0,0).
  47244. * Blue lines indicate the glyph bounding box.
  47245. * Green line indicates the advance width of the glyph.
  47246. * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.
  47247. * @param {string} text - The text to create.
  47248. * @param {number} [x=0] - Horizontal position of the beginning of the text.
  47249. * @param {number} [y=0] - Vertical position of the *baseline* of the text.
  47250. * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
  47251. * @param {GlyphRenderOptions=} options
  47252. */
  47253. Font.prototype.drawMetrics = function(ctx, text, x, y, fontSize, options) {
  47254. this.forEachGlyph(text, x, y, fontSize, options, function(
  47255. glyph,
  47256. gX,
  47257. gY,
  47258. gFontSize
  47259. ) {
  47260. glyph.drawMetrics(ctx, gX, gY, gFontSize);
  47261. });
  47262. };
  47263. /**
  47264. * @param {string}
  47265. * @return {string}
  47266. */
  47267. Font.prototype.getEnglishName = function(name) {
  47268. var translations = this.names[name];
  47269. if (translations) {
  47270. return translations.en;
  47271. }
  47272. };
  47273. /**
  47274. * Validate
  47275. */
  47276. Font.prototype.validate = function() {
  47277. var _this = this;
  47278. function assert(predicate, message) {}
  47279. function assertNamePresent(name) {
  47280. var englishName = _this.getEnglishName(name);
  47281. assert(
  47282. englishName && englishName.trim().length > 0,
  47283. 'No English ' + name + ' specified.'
  47284. );
  47285. }
  47286. // Identification information
  47287. assertNamePresent('fontFamily');
  47288. assertNamePresent('weightName');
  47289. assertNamePresent('manufacturer');
  47290. assertNamePresent('copyright');
  47291. assertNamePresent('version');
  47292. // Dimension information
  47293. assert(this.unitsPerEm > 0, 'No unitsPerEm specified.');
  47294. };
  47295. /**
  47296. * Convert the font object to a SFNT data structure.
  47297. * This structure contains all the necessary tables and metadata to create a binary OTF file.
  47298. * @return {opentype.Table}
  47299. */
  47300. Font.prototype.toTables = function() {
  47301. return sfnt.fontToTable(this);
  47302. };
  47303. /**
  47304. * @deprecated Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.
  47305. */
  47306. Font.prototype.toBuffer = function() {
  47307. console.warn(
  47308. 'Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.'
  47309. );
  47310. return this.toArrayBuffer();
  47311. };
  47312. /**
  47313. * Converts a `opentype.Font` into an `ArrayBuffer`
  47314. * @return {ArrayBuffer}
  47315. */
  47316. Font.prototype.toArrayBuffer = function() {
  47317. var sfntTable = this.toTables();
  47318. var bytes = sfntTable.encode();
  47319. var buffer = new ArrayBuffer(bytes.length);
  47320. var intArray = new Uint8Array(buffer);
  47321. for (var i = 0; i < bytes.length; i++) {
  47322. intArray[i] = bytes[i];
  47323. }
  47324. return buffer;
  47325. };
  47326. /**
  47327. * Initiate a download of the OpenType font.
  47328. */
  47329. Font.prototype.download = function(fileName) {
  47330. var familyName = this.getEnglishName('fontFamily');
  47331. var styleName = this.getEnglishName('fontSubfamily');
  47332. fileName =
  47333. fileName || familyName.replace(/\s/g, '') + '-' + styleName + '.otf';
  47334. var arrayBuffer = this.toArrayBuffer();
  47335. if (isBrowser()) {
  47336. window.requestFileSystem =
  47337. window.requestFileSystem || window.webkitRequestFileSystem;
  47338. window.requestFileSystem(
  47339. window.TEMPORARY,
  47340. arrayBuffer.byteLength,
  47341. function(fs) {
  47342. fs.root.getFile(fileName, { create: true }, function(fileEntry) {
  47343. fileEntry.createWriter(function(writer) {
  47344. var dataView = new DataView(arrayBuffer);
  47345. var blob = new Blob([dataView], { type: 'font/opentype' });
  47346. writer.write(blob);
  47347. writer.addEventListener(
  47348. 'writeend',
  47349. function() {
  47350. // Navigating to the file will download it.
  47351. location.href = fileEntry.toURL();
  47352. },
  47353. false
  47354. );
  47355. });
  47356. });
  47357. },
  47358. function(err) {
  47359. throw new Error(err.name + ': ' + err.message);
  47360. }
  47361. );
  47362. } else {
  47363. var fs = _dereq_('fs');
  47364. var buffer = arrayBufferToNodeBuffer(arrayBuffer);
  47365. fs.writeFileSync(fileName, buffer);
  47366. }
  47367. };
  47368. /**
  47369. * @private
  47370. */
  47371. Font.prototype.fsSelectionValues = {
  47372. ITALIC: 0x001, //1
  47373. UNDERSCORE: 0x002, //2
  47374. NEGATIVE: 0x004, //4
  47375. OUTLINED: 0x008, //8
  47376. STRIKEOUT: 0x010, //16
  47377. BOLD: 0x020, //32
  47378. REGULAR: 0x040, //64
  47379. USER_TYPO_METRICS: 0x080, //128
  47380. WWS: 0x100, //256
  47381. OBLIQUE: 0x200 //512
  47382. };
  47383. /**
  47384. * @private
  47385. */
  47386. Font.prototype.usWidthClasses = {
  47387. ULTRA_CONDENSED: 1,
  47388. EXTRA_CONDENSED: 2,
  47389. CONDENSED: 3,
  47390. SEMI_CONDENSED: 4,
  47391. MEDIUM: 5,
  47392. SEMI_EXPANDED: 6,
  47393. EXPANDED: 7,
  47394. EXTRA_EXPANDED: 8,
  47395. ULTRA_EXPANDED: 9
  47396. };
  47397. /**
  47398. * @private
  47399. */
  47400. Font.prototype.usWeightClasses = {
  47401. THIN: 100,
  47402. EXTRA_LIGHT: 200,
  47403. LIGHT: 300,
  47404. NORMAL: 400,
  47405. MEDIUM: 500,
  47406. SEMI_BOLD: 600,
  47407. BOLD: 700,
  47408. EXTRA_BOLD: 800,
  47409. BLACK: 900
  47410. };
  47411. // The `fvar` table stores font variation axes and instances.
  47412. function addName(name, names) {
  47413. var nameString = JSON.stringify(name);
  47414. var nameID = 256;
  47415. for (var nameKey in names) {
  47416. var n = parseInt(nameKey);
  47417. if (!n || n < 256) {
  47418. continue;
  47419. }
  47420. if (JSON.stringify(names[nameKey]) === nameString) {
  47421. return n;
  47422. }
  47423. if (nameID <= n) {
  47424. nameID = n + 1;
  47425. }
  47426. }
  47427. names[nameID] = name;
  47428. return nameID;
  47429. }
  47430. function makeFvarAxis(n, axis, names) {
  47431. var nameID = addName(axis.name, names);
  47432. return [
  47433. { name: 'tag_' + n, type: 'TAG', value: axis.tag },
  47434. { name: 'minValue_' + n, type: 'FIXED', value: axis.minValue << 16 },
  47435. {
  47436. name: 'defaultValue_' + n,
  47437. type: 'FIXED',
  47438. value: axis.defaultValue << 16
  47439. },
  47440. { name: 'maxValue_' + n, type: 'FIXED', value: axis.maxValue << 16 },
  47441. { name: 'flags_' + n, type: 'USHORT', value: 0 },
  47442. { name: 'nameID_' + n, type: 'USHORT', value: nameID }
  47443. ];
  47444. }
  47445. function parseFvarAxis(data, start, names) {
  47446. var axis = {};
  47447. var p = new parse.Parser(data, start);
  47448. axis.tag = p.parseTag();
  47449. axis.minValue = p.parseFixed();
  47450. axis.defaultValue = p.parseFixed();
  47451. axis.maxValue = p.parseFixed();
  47452. p.skip('uShort', 1); // reserved for flags; no values defined
  47453. axis.name = names[p.parseUShort()] || {};
  47454. return axis;
  47455. }
  47456. function makeFvarInstance(n, inst, axes, names) {
  47457. var nameID = addName(inst.name, names);
  47458. var fields = [
  47459. { name: 'nameID_' + n, type: 'USHORT', value: nameID },
  47460. { name: 'flags_' + n, type: 'USHORT', value: 0 }
  47461. ];
  47462. for (var i = 0; i < axes.length; ++i) {
  47463. var axisTag = axes[i].tag;
  47464. fields.push({
  47465. name: 'axis_' + n + ' ' + axisTag,
  47466. type: 'FIXED',
  47467. value: inst.coordinates[axisTag] << 16
  47468. });
  47469. }
  47470. return fields;
  47471. }
  47472. function parseFvarInstance(data, start, axes, names) {
  47473. var inst = {};
  47474. var p = new parse.Parser(data, start);
  47475. inst.name = names[p.parseUShort()] || {};
  47476. p.skip('uShort', 1); // reserved for flags; no values defined
  47477. inst.coordinates = {};
  47478. for (var i = 0; i < axes.length; ++i) {
  47479. inst.coordinates[axes[i].tag] = p.parseFixed();
  47480. }
  47481. return inst;
  47482. }
  47483. function makeFvarTable(fvar, names) {
  47484. var result = new table.Table('fvar', [
  47485. { name: 'version', type: 'ULONG', value: 0x10000 },
  47486. { name: 'offsetToData', type: 'USHORT', value: 0 },
  47487. { name: 'countSizePairs', type: 'USHORT', value: 2 },
  47488. { name: 'axisCount', type: 'USHORT', value: fvar.axes.length },
  47489. { name: 'axisSize', type: 'USHORT', value: 20 },
  47490. { name: 'instanceCount', type: 'USHORT', value: fvar.instances.length },
  47491. { name: 'instanceSize', type: 'USHORT', value: 4 + fvar.axes.length * 4 }
  47492. ]);
  47493. result.offsetToData = result.sizeOf();
  47494. for (var i = 0; i < fvar.axes.length; i++) {
  47495. result.fields = result.fields.concat(
  47496. makeFvarAxis(i, fvar.axes[i], names)
  47497. );
  47498. }
  47499. for (var j = 0; j < fvar.instances.length; j++) {
  47500. result.fields = result.fields.concat(
  47501. makeFvarInstance(j, fvar.instances[j], fvar.axes, names)
  47502. );
  47503. }
  47504. return result;
  47505. }
  47506. function parseFvarTable(data, start, names) {
  47507. var p = new parse.Parser(data, start);
  47508. var tableVersion = p.parseULong();
  47509. check.argument(
  47510. tableVersion === 0x00010000,
  47511. 'Unsupported fvar table version.'
  47512. );
  47513. var offsetToData = p.parseOffset16();
  47514. // Skip countSizePairs.
  47515. p.skip('uShort', 1);
  47516. var axisCount = p.parseUShort();
  47517. var axisSize = p.parseUShort();
  47518. var instanceCount = p.parseUShort();
  47519. var instanceSize = p.parseUShort();
  47520. var axes = [];
  47521. for (var i = 0; i < axisCount; i++) {
  47522. axes.push(
  47523. parseFvarAxis(data, start + offsetToData + i * axisSize, names)
  47524. );
  47525. }
  47526. var instances = [];
  47527. var instanceStart = start + offsetToData + axisCount * axisSize;
  47528. for (var j = 0; j < instanceCount; j++) {
  47529. instances.push(
  47530. parseFvarInstance(data, instanceStart + j * instanceSize, axes, names)
  47531. );
  47532. }
  47533. return { axes: axes, instances: instances };
  47534. }
  47535. var fvar = { make: makeFvarTable, parse: parseFvarTable };
  47536. // The `GPOS` table contains kerning pairs, among other things.
  47537. var subtableParsers$1 = new Array(10); // subtableParsers[0] is unused
  47538. // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-1-single-adjustment-positioning-subtable
  47539. // this = Parser instance
  47540. subtableParsers$1[1] = function parseLookup1() {
  47541. var start = this.offset + this.relativeOffset;
  47542. var posformat = this.parseUShort();
  47543. if (posformat === 1) {
  47544. return {
  47545. posFormat: 1,
  47546. coverage: this.parsePointer(Parser.coverage),
  47547. value: this.parseValueRecord()
  47548. };
  47549. } else if (posformat === 2) {
  47550. return {
  47551. posFormat: 2,
  47552. coverage: this.parsePointer(Parser.coverage),
  47553. values: this.parseValueRecordList()
  47554. };
  47555. }
  47556. check.assert(
  47557. false,
  47558. '0x' + start.toString(16) + ': GPOS lookup type 1 format must be 1 or 2.'
  47559. );
  47560. };
  47561. // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-2-pair-adjustment-positioning-subtable
  47562. subtableParsers$1[2] = function parseLookup2() {
  47563. var start = this.offset + this.relativeOffset;
  47564. var posFormat = this.parseUShort();
  47565. check.assert(
  47566. posFormat === 1 || posFormat === 2,
  47567. '0x' + start.toString(16) + ': GPOS lookup type 2 format must be 1 or 2.'
  47568. );
  47569. var coverage = this.parsePointer(Parser.coverage);
  47570. var valueFormat1 = this.parseUShort();
  47571. var valueFormat2 = this.parseUShort();
  47572. if (posFormat === 1) {
  47573. // Adjustments for Glyph Pairs
  47574. return {
  47575. posFormat: posFormat,
  47576. coverage: coverage,
  47577. valueFormat1: valueFormat1,
  47578. valueFormat2: valueFormat2,
  47579. pairSets: this.parseList(
  47580. Parser.pointer(
  47581. Parser.list(function() {
  47582. return {
  47583. // pairValueRecord
  47584. secondGlyph: this.parseUShort(),
  47585. value1: this.parseValueRecord(valueFormat1),
  47586. value2: this.parseValueRecord(valueFormat2)
  47587. };
  47588. })
  47589. )
  47590. )
  47591. };
  47592. } else if (posFormat === 2) {
  47593. var classDef1 = this.parsePointer(Parser.classDef);
  47594. var classDef2 = this.parsePointer(Parser.classDef);
  47595. var class1Count = this.parseUShort();
  47596. var class2Count = this.parseUShort();
  47597. return {
  47598. // Class Pair Adjustment
  47599. posFormat: posFormat,
  47600. coverage: coverage,
  47601. valueFormat1: valueFormat1,
  47602. valueFormat2: valueFormat2,
  47603. classDef1: classDef1,
  47604. classDef2: classDef2,
  47605. class1Count: class1Count,
  47606. class2Count: class2Count,
  47607. classRecords: this.parseList(
  47608. class1Count,
  47609. Parser.list(class2Count, function() {
  47610. return {
  47611. value1: this.parseValueRecord(valueFormat1),
  47612. value2: this.parseValueRecord(valueFormat2)
  47613. };
  47614. })
  47615. )
  47616. };
  47617. }
  47618. };
  47619. subtableParsers$1[3] = function parseLookup3() {
  47620. return { error: 'GPOS Lookup 3 not supported' };
  47621. };
  47622. subtableParsers$1[4] = function parseLookup4() {
  47623. return { error: 'GPOS Lookup 4 not supported' };
  47624. };
  47625. subtableParsers$1[5] = function parseLookup5() {
  47626. return { error: 'GPOS Lookup 5 not supported' };
  47627. };
  47628. subtableParsers$1[6] = function parseLookup6() {
  47629. return { error: 'GPOS Lookup 6 not supported' };
  47630. };
  47631. subtableParsers$1[7] = function parseLookup7() {
  47632. return { error: 'GPOS Lookup 7 not supported' };
  47633. };
  47634. subtableParsers$1[8] = function parseLookup8() {
  47635. return { error: 'GPOS Lookup 8 not supported' };
  47636. };
  47637. subtableParsers$1[9] = function parseLookup9() {
  47638. return { error: 'GPOS Lookup 9 not supported' };
  47639. };
  47640. // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos
  47641. function parseGposTable(data, start) {
  47642. start = start || 0;
  47643. var p = new Parser(data, start);
  47644. var tableVersion = p.parseVersion(1);
  47645. check.argument(
  47646. tableVersion === 1 || tableVersion === 1.1,
  47647. 'Unsupported GPOS table version ' + tableVersion
  47648. );
  47649. if (tableVersion === 1) {
  47650. return {
  47651. version: tableVersion,
  47652. scripts: p.parseScriptList(),
  47653. features: p.parseFeatureList(),
  47654. lookups: p.parseLookupList(subtableParsers$1)
  47655. };
  47656. } else {
  47657. return {
  47658. version: tableVersion,
  47659. scripts: p.parseScriptList(),
  47660. features: p.parseFeatureList(),
  47661. lookups: p.parseLookupList(subtableParsers$1),
  47662. variations: p.parseFeatureVariationsList()
  47663. };
  47664. }
  47665. }
  47666. // GPOS Writing //////////////////////////////////////////////
  47667. // NOT SUPPORTED
  47668. var subtableMakers$1 = new Array(10);
  47669. function makeGposTable(gpos) {
  47670. return new table.Table('GPOS', [
  47671. { name: 'version', type: 'ULONG', value: 0x10000 },
  47672. {
  47673. name: 'scripts',
  47674. type: 'TABLE',
  47675. value: new table.ScriptList(gpos.scripts)
  47676. },
  47677. {
  47678. name: 'features',
  47679. type: 'TABLE',
  47680. value: new table.FeatureList(gpos.features)
  47681. },
  47682. {
  47683. name: 'lookups',
  47684. type: 'TABLE',
  47685. value: new table.LookupList(gpos.lookups, subtableMakers$1)
  47686. }
  47687. ]);
  47688. }
  47689. var gpos = { parse: parseGposTable, make: makeGposTable };
  47690. // The `kern` table contains kerning pairs.
  47691. function parseWindowsKernTable(p) {
  47692. var pairs = {};
  47693. // Skip nTables.
  47694. p.skip('uShort');
  47695. var subtableVersion = p.parseUShort();
  47696. check.argument(
  47697. subtableVersion === 0,
  47698. 'Unsupported kern sub-table version.'
  47699. );
  47700. // Skip subtableLength, subtableCoverage
  47701. p.skip('uShort', 2);
  47702. var nPairs = p.parseUShort();
  47703. // Skip searchRange, entrySelector, rangeShift.
  47704. p.skip('uShort', 3);
  47705. for (var i = 0; i < nPairs; i += 1) {
  47706. var leftIndex = p.parseUShort();
  47707. var rightIndex = p.parseUShort();
  47708. var value = p.parseShort();
  47709. pairs[leftIndex + ',' + rightIndex] = value;
  47710. }
  47711. return pairs;
  47712. }
  47713. function parseMacKernTable(p) {
  47714. var pairs = {};
  47715. // The Mac kern table stores the version as a fixed (32 bits) but we only loaded the first 16 bits.
  47716. // Skip the rest.
  47717. p.skip('uShort');
  47718. var nTables = p.parseULong();
  47719. //check.argument(nTables === 1, 'Only 1 subtable is supported (got ' + nTables + ').');
  47720. if (nTables > 1) {
  47721. console.warn('Only the first kern subtable is supported.');
  47722. }
  47723. p.skip('uLong');
  47724. var coverage = p.parseUShort();
  47725. var subtableVersion = coverage & 0xff;
  47726. p.skip('uShort');
  47727. if (subtableVersion === 0) {
  47728. var nPairs = p.parseUShort();
  47729. // Skip searchRange, entrySelector, rangeShift.
  47730. p.skip('uShort', 3);
  47731. for (var i = 0; i < nPairs; i += 1) {
  47732. var leftIndex = p.parseUShort();
  47733. var rightIndex = p.parseUShort();
  47734. var value = p.parseShort();
  47735. pairs[leftIndex + ',' + rightIndex] = value;
  47736. }
  47737. }
  47738. return pairs;
  47739. }
  47740. // Parse the `kern` table which contains kerning pairs.
  47741. function parseKernTable(data, start) {
  47742. var p = new parse.Parser(data, start);
  47743. var tableVersion = p.parseUShort();
  47744. if (tableVersion === 0) {
  47745. return parseWindowsKernTable(p);
  47746. } else if (tableVersion === 1) {
  47747. return parseMacKernTable(p);
  47748. } else {
  47749. throw new Error('Unsupported kern table version (' + tableVersion + ').');
  47750. }
  47751. }
  47752. var kern = { parse: parseKernTable };
  47753. // The `loca` table stores the offsets to the locations of the glyphs in the font.
  47754. // Parse the `loca` table. This table stores the offsets to the locations of the glyphs in the font,
  47755. // relative to the beginning of the glyphData table.
  47756. // The number of glyphs stored in the `loca` table is specified in the `maxp` table (under numGlyphs)
  47757. // The loca table has two versions: a short version where offsets are stored as uShorts, and a long
  47758. // version where offsets are stored as uLongs. The `head` table specifies which version to use
  47759. // (under indexToLocFormat).
  47760. function parseLocaTable(data, start, numGlyphs, shortVersion) {
  47761. var p = new parse.Parser(data, start);
  47762. var parseFn = shortVersion ? p.parseUShort : p.parseULong;
  47763. // There is an extra entry after the last index element to compute the length of the last glyph.
  47764. // That's why we use numGlyphs + 1.
  47765. var glyphOffsets = [];
  47766. for (var i = 0; i < numGlyphs + 1; i += 1) {
  47767. var glyphOffset = parseFn.call(p);
  47768. if (shortVersion) {
  47769. // The short table version stores the actual offset divided by 2.
  47770. glyphOffset *= 2;
  47771. }
  47772. glyphOffsets.push(glyphOffset);
  47773. }
  47774. return glyphOffsets;
  47775. }
  47776. var loca = { parse: parseLocaTable };
  47777. // opentype.js
  47778. /**
  47779. * The opentype library.
  47780. * @namespace opentype
  47781. */
  47782. // File loaders /////////////////////////////////////////////////////////
  47783. /**
  47784. * Loads a font from a file. The callback throws an error message as the first parameter if it fails
  47785. * and the font as an ArrayBuffer in the second parameter if it succeeds.
  47786. * @param {string} path - The path of the file
  47787. * @param {Function} callback - The function to call when the font load completes
  47788. */
  47789. function loadFromFile(path, callback) {
  47790. var fs = _dereq_('fs');
  47791. fs.readFile(path, function(err, buffer) {
  47792. if (err) {
  47793. return callback(err.message);
  47794. }
  47795. callback(null, nodeBufferToArrayBuffer(buffer));
  47796. });
  47797. }
  47798. /**
  47799. * Loads a font from a URL. The callback throws an error message as the first parameter if it fails
  47800. * and the font as an ArrayBuffer in the second parameter if it succeeds.
  47801. * @param {string} url - The URL of the font file.
  47802. * @param {Function} callback - The function to call when the font load completes
  47803. */
  47804. function loadFromUrl(url, callback) {
  47805. var request = new XMLHttpRequest();
  47806. request.open('get', url, true);
  47807. request.responseType = 'arraybuffer';
  47808. request.onload = function() {
  47809. if (request.response) {
  47810. return callback(null, request.response);
  47811. } else {
  47812. return callback('Font could not be loaded: ' + request.statusText);
  47813. }
  47814. };
  47815. request.onerror = function() {
  47816. callback('Font could not be loaded');
  47817. };
  47818. request.send();
  47819. }
  47820. // Table Directory Entries //////////////////////////////////////////////
  47821. /**
  47822. * Parses OpenType table entries.
  47823. * @param {DataView}
  47824. * @param {Number}
  47825. * @return {Object[]}
  47826. */
  47827. function parseOpenTypeTableEntries(data, numTables) {
  47828. var tableEntries = [];
  47829. var p = 12;
  47830. for (var i = 0; i < numTables; i += 1) {
  47831. var tag = parse.getTag(data, p);
  47832. var checksum = parse.getULong(data, p + 4);
  47833. var offset = parse.getULong(data, p + 8);
  47834. var length = parse.getULong(data, p + 12);
  47835. tableEntries.push({
  47836. tag: tag,
  47837. checksum: checksum,
  47838. offset: offset,
  47839. length: length,
  47840. compression: false
  47841. });
  47842. p += 16;
  47843. }
  47844. return tableEntries;
  47845. }
  47846. /**
  47847. * Parses WOFF table entries.
  47848. * @param {DataView}
  47849. * @param {Number}
  47850. * @return {Object[]}
  47851. */
  47852. function parseWOFFTableEntries(data, numTables) {
  47853. var tableEntries = [];
  47854. var p = 44; // offset to the first table directory entry.
  47855. for (var i = 0; i < numTables; i += 1) {
  47856. var tag = parse.getTag(data, p);
  47857. var offset = parse.getULong(data, p + 4);
  47858. var compLength = parse.getULong(data, p + 8);
  47859. var origLength = parse.getULong(data, p + 12);
  47860. var compression = void 0;
  47861. if (compLength < origLength) {
  47862. compression = 'WOFF';
  47863. } else {
  47864. compression = false;
  47865. }
  47866. tableEntries.push({
  47867. tag: tag,
  47868. offset: offset,
  47869. compression: compression,
  47870. compressedLength: compLength,
  47871. length: origLength
  47872. });
  47873. p += 20;
  47874. }
  47875. return tableEntries;
  47876. }
  47877. /**
  47878. * @typedef TableData
  47879. * @type Object
  47880. * @property {DataView} data - The DataView
  47881. * @property {number} offset - The data offset.
  47882. */
  47883. /**
  47884. * @param {DataView}
  47885. * @param {Object}
  47886. * @return {TableData}
  47887. */
  47888. function uncompressTable(data, tableEntry) {
  47889. if (tableEntry.compression === 'WOFF') {
  47890. var inBuffer = new Uint8Array(
  47891. data.buffer,
  47892. tableEntry.offset + 2,
  47893. tableEntry.compressedLength - 2
  47894. );
  47895. var outBuffer = new Uint8Array(tableEntry.length);
  47896. tinyInflate(inBuffer, outBuffer);
  47897. if (outBuffer.byteLength !== tableEntry.length) {
  47898. throw new Error(
  47899. 'Decompression error: ' +
  47900. tableEntry.tag +
  47901. " decompressed length doesn't match recorded length"
  47902. );
  47903. }
  47904. var view = new DataView(outBuffer.buffer, 0);
  47905. return { data: view, offset: 0 };
  47906. } else {
  47907. return { data: data, offset: tableEntry.offset };
  47908. }
  47909. }
  47910. // Public API ///////////////////////////////////////////////////////////
  47911. /**
  47912. * Parse the OpenType file data (as an ArrayBuffer) and return a Font object.
  47913. * Throws an error if the font could not be parsed.
  47914. * @param {ArrayBuffer}
  47915. * @return {opentype.Font}
  47916. */
  47917. function parseBuffer(buffer) {
  47918. var indexToLocFormat;
  47919. var ltagTable;
  47920. // Since the constructor can also be called to create new fonts from scratch, we indicate this
  47921. // should be an empty font that we'll fill with our own data.
  47922. var font = new Font({ empty: true });
  47923. // OpenType fonts use big endian byte ordering.
  47924. // We can't rely on typed array view types, because they operate with the endianness of the host computer.
  47925. // Instead we use DataViews where we can specify endianness.
  47926. var data = new DataView(buffer, 0);
  47927. var numTables;
  47928. var tableEntries = [];
  47929. var signature = parse.getTag(data, 0);
  47930. if (
  47931. signature === String.fromCharCode(0, 1, 0, 0) ||
  47932. signature === 'true' ||
  47933. signature === 'typ1'
  47934. ) {
  47935. font.outlinesFormat = 'truetype';
  47936. numTables = parse.getUShort(data, 4);
  47937. tableEntries = parseOpenTypeTableEntries(data, numTables);
  47938. } else if (signature === 'OTTO') {
  47939. font.outlinesFormat = 'cff';
  47940. numTables = parse.getUShort(data, 4);
  47941. tableEntries = parseOpenTypeTableEntries(data, numTables);
  47942. } else if (signature === 'wOFF') {
  47943. var flavor = parse.getTag(data, 4);
  47944. if (flavor === String.fromCharCode(0, 1, 0, 0)) {
  47945. font.outlinesFormat = 'truetype';
  47946. } else if (flavor === 'OTTO') {
  47947. font.outlinesFormat = 'cff';
  47948. } else {
  47949. throw new Error('Unsupported OpenType flavor ' + signature);
  47950. }
  47951. numTables = parse.getUShort(data, 12);
  47952. tableEntries = parseWOFFTableEntries(data, numTables);
  47953. } else {
  47954. throw new Error('Unsupported OpenType signature ' + signature);
  47955. }
  47956. var cffTableEntry;
  47957. var fvarTableEntry;
  47958. var glyfTableEntry;
  47959. var gposTableEntry;
  47960. var gsubTableEntry;
  47961. var hmtxTableEntry;
  47962. var kernTableEntry;
  47963. var locaTableEntry;
  47964. var nameTableEntry;
  47965. var metaTableEntry;
  47966. var p;
  47967. for (var i = 0; i < numTables; i += 1) {
  47968. var tableEntry = tableEntries[i];
  47969. var table = void 0;
  47970. switch (tableEntry.tag) {
  47971. case 'cmap':
  47972. table = uncompressTable(data, tableEntry);
  47973. font.tables.cmap = cmap.parse(table.data, table.offset);
  47974. font.encoding = new CmapEncoding(font.tables.cmap);
  47975. break;
  47976. case 'cvt ':
  47977. table = uncompressTable(data, tableEntry);
  47978. p = new parse.Parser(table.data, table.offset);
  47979. font.tables.cvt = p.parseShortList(tableEntry.length / 2);
  47980. break;
  47981. case 'fvar':
  47982. fvarTableEntry = tableEntry;
  47983. break;
  47984. case 'fpgm':
  47985. table = uncompressTable(data, tableEntry);
  47986. p = new parse.Parser(table.data, table.offset);
  47987. font.tables.fpgm = p.parseByteList(tableEntry.length);
  47988. break;
  47989. case 'head':
  47990. table = uncompressTable(data, tableEntry);
  47991. font.tables.head = head.parse(table.data, table.offset);
  47992. font.unitsPerEm = font.tables.head.unitsPerEm;
  47993. indexToLocFormat = font.tables.head.indexToLocFormat;
  47994. break;
  47995. case 'hhea':
  47996. table = uncompressTable(data, tableEntry);
  47997. font.tables.hhea = hhea.parse(table.data, table.offset);
  47998. font.ascender = font.tables.hhea.ascender;
  47999. font.descender = font.tables.hhea.descender;
  48000. font.numberOfHMetrics = font.tables.hhea.numberOfHMetrics;
  48001. break;
  48002. case 'hmtx':
  48003. hmtxTableEntry = tableEntry;
  48004. break;
  48005. case 'ltag':
  48006. table = uncompressTable(data, tableEntry);
  48007. ltagTable = ltag.parse(table.data, table.offset);
  48008. break;
  48009. case 'maxp':
  48010. table = uncompressTable(data, tableEntry);
  48011. font.tables.maxp = maxp.parse(table.data, table.offset);
  48012. font.numGlyphs = font.tables.maxp.numGlyphs;
  48013. break;
  48014. case 'name':
  48015. nameTableEntry = tableEntry;
  48016. break;
  48017. case 'OS/2':
  48018. table = uncompressTable(data, tableEntry);
  48019. font.tables.os2 = os2.parse(table.data, table.offset);
  48020. break;
  48021. case 'post':
  48022. table = uncompressTable(data, tableEntry);
  48023. font.tables.post = post.parse(table.data, table.offset);
  48024. font.glyphNames = new GlyphNames(font.tables.post);
  48025. break;
  48026. case 'prep':
  48027. table = uncompressTable(data, tableEntry);
  48028. p = new parse.Parser(table.data, table.offset);
  48029. font.tables.prep = p.parseByteList(tableEntry.length);
  48030. break;
  48031. case 'glyf':
  48032. glyfTableEntry = tableEntry;
  48033. break;
  48034. case 'loca':
  48035. locaTableEntry = tableEntry;
  48036. break;
  48037. case 'CFF ':
  48038. cffTableEntry = tableEntry;
  48039. break;
  48040. case 'kern':
  48041. kernTableEntry = tableEntry;
  48042. break;
  48043. case 'GPOS':
  48044. gposTableEntry = tableEntry;
  48045. break;
  48046. case 'GSUB':
  48047. gsubTableEntry = tableEntry;
  48048. break;
  48049. case 'meta':
  48050. metaTableEntry = tableEntry;
  48051. break;
  48052. }
  48053. }
  48054. var nameTable = uncompressTable(data, nameTableEntry);
  48055. font.tables.name = _name.parse(nameTable.data, nameTable.offset, ltagTable);
  48056. font.names = font.tables.name;
  48057. if (glyfTableEntry && locaTableEntry) {
  48058. var shortVersion = indexToLocFormat === 0;
  48059. var locaTable = uncompressTable(data, locaTableEntry);
  48060. var locaOffsets = loca.parse(
  48061. locaTable.data,
  48062. locaTable.offset,
  48063. font.numGlyphs,
  48064. shortVersion
  48065. );
  48066. var glyfTable = uncompressTable(data, glyfTableEntry);
  48067. font.glyphs = glyf.parse(
  48068. glyfTable.data,
  48069. glyfTable.offset,
  48070. locaOffsets,
  48071. font
  48072. );
  48073. } else if (cffTableEntry) {
  48074. var cffTable = uncompressTable(data, cffTableEntry);
  48075. cff.parse(cffTable.data, cffTable.offset, font);
  48076. } else {
  48077. throw new Error("Font doesn't contain TrueType or CFF outlines.");
  48078. }
  48079. var hmtxTable = uncompressTable(data, hmtxTableEntry);
  48080. hmtx.parse(
  48081. hmtxTable.data,
  48082. hmtxTable.offset,
  48083. font.numberOfHMetrics,
  48084. font.numGlyphs,
  48085. font.glyphs
  48086. );
  48087. addGlyphNames(font);
  48088. if (kernTableEntry) {
  48089. var kernTable = uncompressTable(data, kernTableEntry);
  48090. font.kerningPairs = kern.parse(kernTable.data, kernTable.offset);
  48091. } else {
  48092. font.kerningPairs = {};
  48093. }
  48094. if (gposTableEntry) {
  48095. var gposTable = uncompressTable(data, gposTableEntry);
  48096. font.tables.gpos = gpos.parse(gposTable.data, gposTable.offset);
  48097. font.position.init();
  48098. }
  48099. if (gsubTableEntry) {
  48100. var gsubTable = uncompressTable(data, gsubTableEntry);
  48101. font.tables.gsub = gsub.parse(gsubTable.data, gsubTable.offset);
  48102. }
  48103. if (fvarTableEntry) {
  48104. var fvarTable = uncompressTable(data, fvarTableEntry);
  48105. font.tables.fvar = fvar.parse(
  48106. fvarTable.data,
  48107. fvarTable.offset,
  48108. font.names
  48109. );
  48110. }
  48111. if (metaTableEntry) {
  48112. var metaTable = uncompressTable(data, metaTableEntry);
  48113. font.tables.meta = meta.parse(metaTable.data, metaTable.offset);
  48114. font.metas = font.tables.meta;
  48115. }
  48116. return font;
  48117. }
  48118. /**
  48119. * Asynchronously load the font from a URL or a filesystem. When done, call the callback
  48120. * with two arguments `(err, font)`. The `err` will be null on success,
  48121. * the `font` is a Font object.
  48122. * We use the node.js callback convention so that
  48123. * opentype.js can integrate with frameworks like async.js.
  48124. * @alias opentype.load
  48125. * @param {string} url - The URL of the font to load.
  48126. * @param {Function} callback - The callback.
  48127. */
  48128. function load(url, callback) {
  48129. var isNode$$1 = typeof window === 'undefined';
  48130. var loadFn = isNode$$1 ? loadFromFile : loadFromUrl;
  48131. loadFn(url, function(err, arrayBuffer) {
  48132. if (err) {
  48133. return callback(err);
  48134. }
  48135. var font;
  48136. try {
  48137. font = parseBuffer(arrayBuffer);
  48138. } catch (e) {
  48139. return callback(e, null);
  48140. }
  48141. return callback(null, font);
  48142. });
  48143. }
  48144. /**
  48145. * Synchronously load the font from a URL or file.
  48146. * When done, returns the font object or throws an error.
  48147. * @alias opentype.loadSync
  48148. * @param {string} url - The URL of the font to load.
  48149. * @return {opentype.Font}
  48150. */
  48151. function loadSync(url) {
  48152. var fs = _dereq_('fs');
  48153. var buffer = fs.readFileSync(url);
  48154. return parseBuffer(nodeBufferToArrayBuffer(buffer));
  48155. }
  48156. exports.Font = Font;
  48157. exports.Glyph = Glyph;
  48158. exports.Path = Path;
  48159. exports.BoundingBox = BoundingBox;
  48160. exports._parse = parse;
  48161. exports.parse = parseBuffer;
  48162. exports.load = load;
  48163. exports.loadSync = loadSync;
  48164. Object.defineProperty(exports, '__esModule', { value: true });
  48165. });
  48166. }.call(this, _dereq_('buffer').Buffer));
  48167. },
  48168. { buffer: 22, fs: 21 }
  48169. ],
  48170. 259: [
  48171. function(_dereq_, module, exports) {
  48172. (function(process) {
  48173. // .dirname, .basename, and .extname methods are extracted from Node.js v8.11.1,
  48174. // backported and transplited with Babel, with backwards-compat fixes
  48175. // Copyright Joyent, Inc. and other Node contributors.
  48176. //
  48177. // Permission is hereby granted, free of charge, to any person obtaining a
  48178. // copy of this software and associated documentation files (the
  48179. // "Software"), to deal in the Software without restriction, including
  48180. // without limitation the rights to use, copy, modify, merge, publish,
  48181. // distribute, sublicense, and/or sell copies of the Software, and to permit
  48182. // persons to whom the Software is furnished to do so, subject to the
  48183. // following conditions:
  48184. //
  48185. // The above copyright notice and this permission notice shall be included
  48186. // in all copies or substantial portions of the Software.
  48187. //
  48188. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  48189. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  48190. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  48191. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  48192. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  48193. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  48194. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  48195. // resolves . and .. elements in a path array with directory names there
  48196. // must be no slashes, empty elements, or device names (c:\) in the array
  48197. // (so also no leading and trailing slashes - it does not distinguish
  48198. // relative and absolute paths)
  48199. function normalizeArray(parts, allowAboveRoot) {
  48200. // if the path tries to go above the root, `up` ends up > 0
  48201. var up = 0;
  48202. for (var i = parts.length - 1; i >= 0; i--) {
  48203. var last = parts[i];
  48204. if (last === '.') {
  48205. parts.splice(i, 1);
  48206. } else if (last === '..') {
  48207. parts.splice(i, 1);
  48208. up++;
  48209. } else if (up) {
  48210. parts.splice(i, 1);
  48211. up--;
  48212. }
  48213. }
  48214. // if the path is allowed to go above the root, restore leading ..s
  48215. if (allowAboveRoot) {
  48216. for (; up--; up) {
  48217. parts.unshift('..');
  48218. }
  48219. }
  48220. return parts;
  48221. }
  48222. // path.resolve([from ...], to)
  48223. // posix version
  48224. exports.resolve = function() {
  48225. var resolvedPath = '',
  48226. resolvedAbsolute = false;
  48227. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  48228. var path = i >= 0 ? arguments[i] : process.cwd();
  48229. // Skip empty and invalid entries
  48230. if (typeof path !== 'string') {
  48231. throw new TypeError('Arguments to path.resolve must be strings');
  48232. } else if (!path) {
  48233. continue;
  48234. }
  48235. resolvedPath = path + '/' + resolvedPath;
  48236. resolvedAbsolute = path.charAt(0) === '/';
  48237. }
  48238. // At this point the path should be resolved to a full absolute path, but
  48239. // handle relative paths to be safe (might happen when process.cwd() fails)
  48240. // Normalize the path
  48241. resolvedPath = normalizeArray(
  48242. filter(resolvedPath.split('/'), function(p) {
  48243. return !!p;
  48244. }),
  48245. !resolvedAbsolute
  48246. ).join('/');
  48247. return (resolvedAbsolute ? '/' : '') + resolvedPath || '.';
  48248. };
  48249. // path.normalize(path)
  48250. // posix version
  48251. exports.normalize = function(path) {
  48252. var isAbsolute = exports.isAbsolute(path),
  48253. trailingSlash = substr(path, -1) === '/';
  48254. // Normalize the path
  48255. path = normalizeArray(
  48256. filter(path.split('/'), function(p) {
  48257. return !!p;
  48258. }),
  48259. !isAbsolute
  48260. ).join('/');
  48261. if (!path && !isAbsolute) {
  48262. path = '.';
  48263. }
  48264. if (path && trailingSlash) {
  48265. path += '/';
  48266. }
  48267. return (isAbsolute ? '/' : '') + path;
  48268. };
  48269. // posix version
  48270. exports.isAbsolute = function(path) {
  48271. return path.charAt(0) === '/';
  48272. };
  48273. // posix version
  48274. exports.join = function() {
  48275. var paths = Array.prototype.slice.call(arguments, 0);
  48276. return exports.normalize(
  48277. filter(paths, function(p, index) {
  48278. if (typeof p !== 'string') {
  48279. throw new TypeError('Arguments to path.join must be strings');
  48280. }
  48281. return p;
  48282. }).join('/')
  48283. );
  48284. };
  48285. // path.relative(from, to)
  48286. // posix version
  48287. exports.relative = function(from, to) {
  48288. from = exports.resolve(from).substr(1);
  48289. to = exports.resolve(to).substr(1);
  48290. function trim(arr) {
  48291. var start = 0;
  48292. for (; start < arr.length; start++) {
  48293. if (arr[start] !== '') break;
  48294. }
  48295. var end = arr.length - 1;
  48296. for (; end >= 0; end--) {
  48297. if (arr[end] !== '') break;
  48298. }
  48299. if (start > end) return [];
  48300. return arr.slice(start, end - start + 1);
  48301. }
  48302. var fromParts = trim(from.split('/'));
  48303. var toParts = trim(to.split('/'));
  48304. var length = Math.min(fromParts.length, toParts.length);
  48305. var samePartsLength = length;
  48306. for (var i = 0; i < length; i++) {
  48307. if (fromParts[i] !== toParts[i]) {
  48308. samePartsLength = i;
  48309. break;
  48310. }
  48311. }
  48312. var outputParts = [];
  48313. for (var i = samePartsLength; i < fromParts.length; i++) {
  48314. outputParts.push('..');
  48315. }
  48316. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  48317. return outputParts.join('/');
  48318. };
  48319. exports.sep = '/';
  48320. exports.delimiter = ':';
  48321. exports.dirname = function(path) {
  48322. if (typeof path !== 'string') path = path + '';
  48323. if (path.length === 0) return '.';
  48324. var code = path.charCodeAt(0);
  48325. var hasRoot = code === 47 /*/*/;
  48326. var end = -1;
  48327. var matchedSlash = true;
  48328. for (var i = path.length - 1; i >= 1; --i) {
  48329. code = path.charCodeAt(i);
  48330. if (code === 47 /*/*/) {
  48331. if (!matchedSlash) {
  48332. end = i;
  48333. break;
  48334. }
  48335. } else {
  48336. // We saw the first non-path separator
  48337. matchedSlash = false;
  48338. }
  48339. }
  48340. if (end === -1) return hasRoot ? '/' : '.';
  48341. if (hasRoot && end === 1) {
  48342. // return '//';
  48343. // Backwards-compat fix:
  48344. return '/';
  48345. }
  48346. return path.slice(0, end);
  48347. };
  48348. function basename(path) {
  48349. if (typeof path !== 'string') path = path + '';
  48350. var start = 0;
  48351. var end = -1;
  48352. var matchedSlash = true;
  48353. var i;
  48354. for (i = path.length - 1; i >= 0; --i) {
  48355. if (path.charCodeAt(i) === 47 /*/*/) {
  48356. // If we reached a path separator that was not part of a set of path
  48357. // separators at the end of the string, stop now
  48358. if (!matchedSlash) {
  48359. start = i + 1;
  48360. break;
  48361. }
  48362. } else if (end === -1) {
  48363. // We saw the first non-path separator, mark this as the end of our
  48364. // path component
  48365. matchedSlash = false;
  48366. end = i + 1;
  48367. }
  48368. }
  48369. if (end === -1) return '';
  48370. return path.slice(start, end);
  48371. }
  48372. // Uses a mixed approach for backwards-compatibility, as ext behavior changed
  48373. // in new Node.js versions, so only basename() above is backported here
  48374. exports.basename = function(path, ext) {
  48375. var f = basename(path);
  48376. if (ext && f.substr(-1 * ext.length) === ext) {
  48377. f = f.substr(0, f.length - ext.length);
  48378. }
  48379. return f;
  48380. };
  48381. exports.extname = function(path) {
  48382. if (typeof path !== 'string') path = path + '';
  48383. var startDot = -1;
  48384. var startPart = 0;
  48385. var end = -1;
  48386. var matchedSlash = true;
  48387. // Track the state of characters (if any) we see before our first dot and
  48388. // after any path separator we find
  48389. var preDotState = 0;
  48390. for (var i = path.length - 1; i >= 0; --i) {
  48391. var code = path.charCodeAt(i);
  48392. if (code === 47 /*/*/) {
  48393. // If we reached a path separator that was not part of a set of path
  48394. // separators at the end of the string, stop now
  48395. if (!matchedSlash) {
  48396. startPart = i + 1;
  48397. break;
  48398. }
  48399. continue;
  48400. }
  48401. if (end === -1) {
  48402. // We saw the first non-path separator, mark this as the end of our
  48403. // extension
  48404. matchedSlash = false;
  48405. end = i + 1;
  48406. }
  48407. if (code === 46 /*.*/) {
  48408. // If this is our first dot, mark it as the start of our extension
  48409. if (startDot === -1) startDot = i;
  48410. else if (preDotState !== 1) preDotState = 1;
  48411. } else if (startDot !== -1) {
  48412. // We saw a non-dot and non-path separator before our dot, so we should
  48413. // have a good chance at having a non-empty extension
  48414. preDotState = -1;
  48415. }
  48416. }
  48417. if (
  48418. startDot === -1 ||
  48419. end === -1 ||
  48420. // We saw a non-dot character immediately before the dot
  48421. preDotState === 0 ||
  48422. // The (right-most) trimmed path component is exactly '..'
  48423. (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
  48424. ) {
  48425. return '';
  48426. }
  48427. return path.slice(startDot, end);
  48428. };
  48429. function filter(xs, f) {
  48430. if (xs.filter) return xs.filter(f);
  48431. var res = [];
  48432. for (var i = 0; i < xs.length; i++) {
  48433. if (f(xs[i], i, xs)) res.push(xs[i]);
  48434. }
  48435. return res;
  48436. }
  48437. // String.prototype.substr - negative index don't work in IE8
  48438. var substr =
  48439. 'ab'.substr(-1) === 'b'
  48440. ? function(str, start, len) {
  48441. return str.substr(start, len);
  48442. }
  48443. : function(str, start, len) {
  48444. if (start < 0) start = str.length + start;
  48445. return str.substr(start, len);
  48446. };
  48447. }.call(this, _dereq_('_process')));
  48448. },
  48449. { _process: 260 }
  48450. ],
  48451. 260: [
  48452. function(_dereq_, module, exports) {
  48453. // shim for using process in browser
  48454. var process = (module.exports = {});
  48455. // cached from whatever global is present so that test runners that stub it
  48456. // don't break things. But we need to wrap it in a try catch in case it is
  48457. // wrapped in strict mode code which doesn't define any globals. It's inside a
  48458. // function because try/catches deoptimize in certain engines.
  48459. var cachedSetTimeout;
  48460. var cachedClearTimeout;
  48461. function defaultSetTimout() {
  48462. throw new Error('setTimeout has not been defined');
  48463. }
  48464. function defaultClearTimeout() {
  48465. throw new Error('clearTimeout has not been defined');
  48466. }
  48467. (function() {
  48468. try {
  48469. if (typeof setTimeout === 'function') {
  48470. cachedSetTimeout = setTimeout;
  48471. } else {
  48472. cachedSetTimeout = defaultSetTimout;
  48473. }
  48474. } catch (e) {
  48475. cachedSetTimeout = defaultSetTimout;
  48476. }
  48477. try {
  48478. if (typeof clearTimeout === 'function') {
  48479. cachedClearTimeout = clearTimeout;
  48480. } else {
  48481. cachedClearTimeout = defaultClearTimeout;
  48482. }
  48483. } catch (e) {
  48484. cachedClearTimeout = defaultClearTimeout;
  48485. }
  48486. })();
  48487. function runTimeout(fun) {
  48488. if (cachedSetTimeout === setTimeout) {
  48489. //normal enviroments in sane situations
  48490. return setTimeout(fun, 0);
  48491. }
  48492. // if setTimeout wasn't available but was latter defined
  48493. if (
  48494. (cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) &&
  48495. setTimeout
  48496. ) {
  48497. cachedSetTimeout = setTimeout;
  48498. return setTimeout(fun, 0);
  48499. }
  48500. try {
  48501. // when when somebody has screwed with setTimeout but no I.E. maddness
  48502. return cachedSetTimeout(fun, 0);
  48503. } catch (e) {
  48504. try {
  48505. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  48506. return cachedSetTimeout.call(null, fun, 0);
  48507. } catch (e) {
  48508. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  48509. return cachedSetTimeout.call(this, fun, 0);
  48510. }
  48511. }
  48512. }
  48513. function runClearTimeout(marker) {
  48514. if (cachedClearTimeout === clearTimeout) {
  48515. //normal enviroments in sane situations
  48516. return clearTimeout(marker);
  48517. }
  48518. // if clearTimeout wasn't available but was latter defined
  48519. if (
  48520. (cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) &&
  48521. clearTimeout
  48522. ) {
  48523. cachedClearTimeout = clearTimeout;
  48524. return clearTimeout(marker);
  48525. }
  48526. try {
  48527. // when when somebody has screwed with setTimeout but no I.E. maddness
  48528. return cachedClearTimeout(marker);
  48529. } catch (e) {
  48530. try {
  48531. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  48532. return cachedClearTimeout.call(null, marker);
  48533. } catch (e) {
  48534. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  48535. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  48536. return cachedClearTimeout.call(this, marker);
  48537. }
  48538. }
  48539. }
  48540. var queue = [];
  48541. var draining = false;
  48542. var currentQueue;
  48543. var queueIndex = -1;
  48544. function cleanUpNextTick() {
  48545. if (!draining || !currentQueue) {
  48546. return;
  48547. }
  48548. draining = false;
  48549. if (currentQueue.length) {
  48550. queue = currentQueue.concat(queue);
  48551. } else {
  48552. queueIndex = -1;
  48553. }
  48554. if (queue.length) {
  48555. drainQueue();
  48556. }
  48557. }
  48558. function drainQueue() {
  48559. if (draining) {
  48560. return;
  48561. }
  48562. var timeout = runTimeout(cleanUpNextTick);
  48563. draining = true;
  48564. var len = queue.length;
  48565. while (len) {
  48566. currentQueue = queue;
  48567. queue = [];
  48568. while (++queueIndex < len) {
  48569. if (currentQueue) {
  48570. currentQueue[queueIndex].run();
  48571. }
  48572. }
  48573. queueIndex = -1;
  48574. len = queue.length;
  48575. }
  48576. currentQueue = null;
  48577. draining = false;
  48578. runClearTimeout(timeout);
  48579. }
  48580. process.nextTick = function(fun) {
  48581. var args = new Array(arguments.length - 1);
  48582. if (arguments.length > 1) {
  48583. for (var i = 1; i < arguments.length; i++) {
  48584. args[i - 1] = arguments[i];
  48585. }
  48586. }
  48587. queue.push(new Item(fun, args));
  48588. if (queue.length === 1 && !draining) {
  48589. runTimeout(drainQueue);
  48590. }
  48591. };
  48592. // v8 likes predictible objects
  48593. function Item(fun, array) {
  48594. this.fun = fun;
  48595. this.array = array;
  48596. }
  48597. Item.prototype.run = function() {
  48598. this.fun.apply(null, this.array);
  48599. };
  48600. process.title = 'browser';
  48601. process.browser = true;
  48602. process.env = {};
  48603. process.argv = [];
  48604. process.version = ''; // empty string to avoid regexp issues
  48605. process.versions = {};
  48606. function noop() {}
  48607. process.on = noop;
  48608. process.addListener = noop;
  48609. process.once = noop;
  48610. process.off = noop;
  48611. process.removeListener = noop;
  48612. process.removeAllListeners = noop;
  48613. process.emit = noop;
  48614. process.prependListener = noop;
  48615. process.prependOnceListener = noop;
  48616. process.listeners = function(name) {
  48617. return [];
  48618. };
  48619. process.binding = function(name) {
  48620. throw new Error('process.binding is not supported');
  48621. };
  48622. process.cwd = function() {
  48623. return '/';
  48624. };
  48625. process.chdir = function(dir) {
  48626. throw new Error('process.chdir is not supported');
  48627. };
  48628. process.umask = function() {
  48629. return 0;
  48630. };
  48631. },
  48632. {}
  48633. ],
  48634. 261: [
  48635. function(_dereq_, module, exports) {
  48636. (function(self) {
  48637. 'use strict';
  48638. if (self.fetch) {
  48639. return;
  48640. }
  48641. var support = {
  48642. searchParams: 'URLSearchParams' in self,
  48643. iterable: 'Symbol' in self && 'iterator' in Symbol,
  48644. blob:
  48645. 'FileReader' in self &&
  48646. 'Blob' in self &&
  48647. (function() {
  48648. try {
  48649. new Blob();
  48650. return true;
  48651. } catch (e) {
  48652. return false;
  48653. }
  48654. })(),
  48655. formData: 'FormData' in self,
  48656. arrayBuffer: 'ArrayBuffer' in self
  48657. };
  48658. if (support.arrayBuffer) {
  48659. var viewClasses = [
  48660. '[object Int8Array]',
  48661. '[object Uint8Array]',
  48662. '[object Uint8ClampedArray]',
  48663. '[object Int16Array]',
  48664. '[object Uint16Array]',
  48665. '[object Int32Array]',
  48666. '[object Uint32Array]',
  48667. '[object Float32Array]',
  48668. '[object Float64Array]'
  48669. ];
  48670. var isDataView = function(obj) {
  48671. return obj && DataView.prototype.isPrototypeOf(obj);
  48672. };
  48673. var isArrayBufferView =
  48674. ArrayBuffer.isView ||
  48675. function(obj) {
  48676. return (
  48677. obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
  48678. );
  48679. };
  48680. }
  48681. function normalizeName(name) {
  48682. if (typeof name !== 'string') {
  48683. name = String(name);
  48684. }
  48685. if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
  48686. throw new TypeError('Invalid character in header field name');
  48687. }
  48688. return name.toLowerCase();
  48689. }
  48690. function normalizeValue(value) {
  48691. if (typeof value !== 'string') {
  48692. value = String(value);
  48693. }
  48694. return value;
  48695. }
  48696. // Build a destructive iterator for the value list
  48697. function iteratorFor(items) {
  48698. var iterator = {
  48699. next: function() {
  48700. var value = items.shift();
  48701. return { done: value === undefined, value: value };
  48702. }
  48703. };
  48704. if (support.iterable) {
  48705. iterator[Symbol.iterator] = function() {
  48706. return iterator;
  48707. };
  48708. }
  48709. return iterator;
  48710. }
  48711. function Headers(headers) {
  48712. this.map = {};
  48713. if (headers instanceof Headers) {
  48714. headers.forEach(function(value, name) {
  48715. this.append(name, value);
  48716. }, this);
  48717. } else if (Array.isArray(headers)) {
  48718. headers.forEach(function(header) {
  48719. this.append(header[0], header[1]);
  48720. }, this);
  48721. } else if (headers) {
  48722. Object.getOwnPropertyNames(headers).forEach(function(name) {
  48723. this.append(name, headers[name]);
  48724. }, this);
  48725. }
  48726. }
  48727. Headers.prototype.append = function(name, value) {
  48728. name = normalizeName(name);
  48729. value = normalizeValue(value);
  48730. var oldValue = this.map[name];
  48731. this.map[name] = oldValue ? oldValue + ',' + value : value;
  48732. };
  48733. Headers.prototype['delete'] = function(name) {
  48734. delete this.map[normalizeName(name)];
  48735. };
  48736. Headers.prototype.get = function(name) {
  48737. name = normalizeName(name);
  48738. return this.has(name) ? this.map[name] : null;
  48739. };
  48740. Headers.prototype.has = function(name) {
  48741. return this.map.hasOwnProperty(normalizeName(name));
  48742. };
  48743. Headers.prototype.set = function(name, value) {
  48744. this.map[normalizeName(name)] = normalizeValue(value);
  48745. };
  48746. Headers.prototype.forEach = function(callback, thisArg) {
  48747. for (var name in this.map) {
  48748. if (this.map.hasOwnProperty(name)) {
  48749. callback.call(thisArg, this.map[name], name, this);
  48750. }
  48751. }
  48752. };
  48753. Headers.prototype.keys = function() {
  48754. var items = [];
  48755. this.forEach(function(value, name) {
  48756. items.push(name);
  48757. });
  48758. return iteratorFor(items);
  48759. };
  48760. Headers.prototype.values = function() {
  48761. var items = [];
  48762. this.forEach(function(value) {
  48763. items.push(value);
  48764. });
  48765. return iteratorFor(items);
  48766. };
  48767. Headers.prototype.entries = function() {
  48768. var items = [];
  48769. this.forEach(function(value, name) {
  48770. items.push([name, value]);
  48771. });
  48772. return iteratorFor(items);
  48773. };
  48774. if (support.iterable) {
  48775. Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
  48776. }
  48777. function consumed(body) {
  48778. if (body.bodyUsed) {
  48779. return Promise.reject(new TypeError('Already read'));
  48780. }
  48781. body.bodyUsed = true;
  48782. }
  48783. function fileReaderReady(reader) {
  48784. return new Promise(function(resolve, reject) {
  48785. reader.onload = function() {
  48786. resolve(reader.result);
  48787. };
  48788. reader.onerror = function() {
  48789. reject(reader.error);
  48790. };
  48791. });
  48792. }
  48793. function readBlobAsArrayBuffer(blob) {
  48794. var reader = new FileReader();
  48795. var promise = fileReaderReady(reader);
  48796. reader.readAsArrayBuffer(blob);
  48797. return promise;
  48798. }
  48799. function readBlobAsText(blob) {
  48800. var reader = new FileReader();
  48801. var promise = fileReaderReady(reader);
  48802. reader.readAsText(blob);
  48803. return promise;
  48804. }
  48805. function readArrayBufferAsText(buf) {
  48806. var view = new Uint8Array(buf);
  48807. var chars = new Array(view.length);
  48808. for (var i = 0; i < view.length; i++) {
  48809. chars[i] = String.fromCharCode(view[i]);
  48810. }
  48811. return chars.join('');
  48812. }
  48813. function bufferClone(buf) {
  48814. if (buf.slice) {
  48815. return buf.slice(0);
  48816. } else {
  48817. var view = new Uint8Array(buf.byteLength);
  48818. view.set(new Uint8Array(buf));
  48819. return view.buffer;
  48820. }
  48821. }
  48822. function Body() {
  48823. this.bodyUsed = false;
  48824. this._initBody = function(body) {
  48825. this._bodyInit = body;
  48826. if (!body) {
  48827. this._bodyText = '';
  48828. } else if (typeof body === 'string') {
  48829. this._bodyText = body;
  48830. } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
  48831. this._bodyBlob = body;
  48832. } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
  48833. this._bodyFormData = body;
  48834. } else if (
  48835. support.searchParams &&
  48836. URLSearchParams.prototype.isPrototypeOf(body)
  48837. ) {
  48838. this._bodyText = body.toString();
  48839. } else if (support.arrayBuffer && support.blob && isDataView(body)) {
  48840. this._bodyArrayBuffer = bufferClone(body.buffer);
  48841. // IE 10-11 can't handle a DataView body.
  48842. this._bodyInit = new Blob([this._bodyArrayBuffer]);
  48843. } else if (
  48844. support.arrayBuffer &&
  48845. (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))
  48846. ) {
  48847. this._bodyArrayBuffer = bufferClone(body);
  48848. } else {
  48849. throw new Error('unsupported BodyInit type');
  48850. }
  48851. if (!this.headers.get('content-type')) {
  48852. if (typeof body === 'string') {
  48853. this.headers.set('content-type', 'text/plain;charset=UTF-8');
  48854. } else if (this._bodyBlob && this._bodyBlob.type) {
  48855. this.headers.set('content-type', this._bodyBlob.type);
  48856. } else if (
  48857. support.searchParams &&
  48858. URLSearchParams.prototype.isPrototypeOf(body)
  48859. ) {
  48860. this.headers.set(
  48861. 'content-type',
  48862. 'application/x-www-form-urlencoded;charset=UTF-8'
  48863. );
  48864. }
  48865. }
  48866. };
  48867. if (support.blob) {
  48868. this.blob = function() {
  48869. var rejected = consumed(this);
  48870. if (rejected) {
  48871. return rejected;
  48872. }
  48873. if (this._bodyBlob) {
  48874. return Promise.resolve(this._bodyBlob);
  48875. } else if (this._bodyArrayBuffer) {
  48876. return Promise.resolve(new Blob([this._bodyArrayBuffer]));
  48877. } else if (this._bodyFormData) {
  48878. throw new Error('could not read FormData body as blob');
  48879. } else {
  48880. return Promise.resolve(new Blob([this._bodyText]));
  48881. }
  48882. };
  48883. this.arrayBuffer = function() {
  48884. if (this._bodyArrayBuffer) {
  48885. return consumed(this) || Promise.resolve(this._bodyArrayBuffer);
  48886. } else {
  48887. return this.blob().then(readBlobAsArrayBuffer);
  48888. }
  48889. };
  48890. }
  48891. this.text = function() {
  48892. var rejected = consumed(this);
  48893. if (rejected) {
  48894. return rejected;
  48895. }
  48896. if (this._bodyBlob) {
  48897. return readBlobAsText(this._bodyBlob);
  48898. } else if (this._bodyArrayBuffer) {
  48899. return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer));
  48900. } else if (this._bodyFormData) {
  48901. throw new Error('could not read FormData body as text');
  48902. } else {
  48903. return Promise.resolve(this._bodyText);
  48904. }
  48905. };
  48906. if (support.formData) {
  48907. this.formData = function() {
  48908. return this.text().then(decode);
  48909. };
  48910. }
  48911. this.json = function() {
  48912. return this.text().then(JSON.parse);
  48913. };
  48914. return this;
  48915. }
  48916. // HTTP methods whose capitalization should be normalized
  48917. var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
  48918. function normalizeMethod(method) {
  48919. var upcased = method.toUpperCase();
  48920. return methods.indexOf(upcased) > -1 ? upcased : method;
  48921. }
  48922. function Request(input, options) {
  48923. options = options || {};
  48924. var body = options.body;
  48925. if (input instanceof Request) {
  48926. if (input.bodyUsed) {
  48927. throw new TypeError('Already read');
  48928. }
  48929. this.url = input.url;
  48930. this.credentials = input.credentials;
  48931. if (!options.headers) {
  48932. this.headers = new Headers(input.headers);
  48933. }
  48934. this.method = input.method;
  48935. this.mode = input.mode;
  48936. if (!body && input._bodyInit != null) {
  48937. body = input._bodyInit;
  48938. input.bodyUsed = true;
  48939. }
  48940. } else {
  48941. this.url = String(input);
  48942. }
  48943. this.credentials = options.credentials || this.credentials || 'omit';
  48944. if (options.headers || !this.headers) {
  48945. this.headers = new Headers(options.headers);
  48946. }
  48947. this.method = normalizeMethod(options.method || this.method || 'GET');
  48948. this.mode = options.mode || this.mode || null;
  48949. this.referrer = null;
  48950. if ((this.method === 'GET' || this.method === 'HEAD') && body) {
  48951. throw new TypeError('Body not allowed for GET or HEAD requests');
  48952. }
  48953. this._initBody(body);
  48954. }
  48955. Request.prototype.clone = function() {
  48956. return new Request(this, { body: this._bodyInit });
  48957. };
  48958. function decode(body) {
  48959. var form = new FormData();
  48960. body
  48961. .trim()
  48962. .split('&')
  48963. .forEach(function(bytes) {
  48964. if (bytes) {
  48965. var split = bytes.split('=');
  48966. var name = split.shift().replace(/\+/g, ' ');
  48967. var value = split.join('=').replace(/\+/g, ' ');
  48968. form.append(decodeURIComponent(name), decodeURIComponent(value));
  48969. }
  48970. });
  48971. return form;
  48972. }
  48973. function parseHeaders(rawHeaders) {
  48974. var headers = new Headers();
  48975. // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
  48976. // https://tools.ietf.org/html/rfc7230#section-3.2
  48977. var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
  48978. preProcessedHeaders.split(/\r?\n/).forEach(function(line) {
  48979. var parts = line.split(':');
  48980. var key = parts.shift().trim();
  48981. if (key) {
  48982. var value = parts.join(':').trim();
  48983. headers.append(key, value);
  48984. }
  48985. });
  48986. return headers;
  48987. }
  48988. Body.call(Request.prototype);
  48989. function Response(bodyInit, options) {
  48990. if (!options) {
  48991. options = {};
  48992. }
  48993. this.type = 'default';
  48994. this.status = options.status === undefined ? 200 : options.status;
  48995. this.ok = this.status >= 200 && this.status < 300;
  48996. this.statusText = 'statusText' in options ? options.statusText : 'OK';
  48997. this.headers = new Headers(options.headers);
  48998. this.url = options.url || '';
  48999. this._initBody(bodyInit);
  49000. }
  49001. Body.call(Response.prototype);
  49002. Response.prototype.clone = function() {
  49003. return new Response(this._bodyInit, {
  49004. status: this.status,
  49005. statusText: this.statusText,
  49006. headers: new Headers(this.headers),
  49007. url: this.url
  49008. });
  49009. };
  49010. Response.error = function() {
  49011. var response = new Response(null, { status: 0, statusText: '' });
  49012. response.type = 'error';
  49013. return response;
  49014. };
  49015. var redirectStatuses = [301, 302, 303, 307, 308];
  49016. Response.redirect = function(url, status) {
  49017. if (redirectStatuses.indexOf(status) === -1) {
  49018. throw new RangeError('Invalid status code');
  49019. }
  49020. return new Response(null, { status: status, headers: { location: url } });
  49021. };
  49022. self.Headers = Headers;
  49023. self.Request = Request;
  49024. self.Response = Response;
  49025. self.fetch = function(input, init) {
  49026. return new Promise(function(resolve, reject) {
  49027. var request = new Request(input, init);
  49028. var xhr = new XMLHttpRequest();
  49029. xhr.onload = function() {
  49030. var options = {
  49031. status: xhr.status,
  49032. statusText: xhr.statusText,
  49033. headers: parseHeaders(xhr.getAllResponseHeaders() || '')
  49034. };
  49035. options.url =
  49036. 'responseURL' in xhr
  49037. ? xhr.responseURL
  49038. : options.headers.get('X-Request-URL');
  49039. var body = 'response' in xhr ? xhr.response : xhr.responseText;
  49040. resolve(new Response(body, options));
  49041. };
  49042. xhr.onerror = function() {
  49043. reject(new TypeError('Network request failed'));
  49044. };
  49045. xhr.ontimeout = function() {
  49046. reject(new TypeError('Network request failed'));
  49047. };
  49048. xhr.open(request.method, request.url, true);
  49049. if (request.credentials === 'include') {
  49050. xhr.withCredentials = true;
  49051. } else if (request.credentials === 'omit') {
  49052. xhr.withCredentials = false;
  49053. }
  49054. if ('responseType' in xhr && support.blob) {
  49055. xhr.responseType = 'blob';
  49056. }
  49057. request.headers.forEach(function(value, name) {
  49058. xhr.setRequestHeader(name, value);
  49059. });
  49060. xhr.send(
  49061. typeof request._bodyInit === 'undefined' ? null : request._bodyInit
  49062. );
  49063. });
  49064. };
  49065. self.fetch.polyfill = true;
  49066. })(typeof self !== 'undefined' ? self : this);
  49067. },
  49068. {}
  49069. ],
  49070. 262: [
  49071. function(_dereq_, module, exports) {
  49072. 'use strict';
  49073. _dereq_('core-js/modules/es.function.name');
  49074. _dereq_('core-js/modules/es.object.to-string');
  49075. _dereq_('core-js/modules/es.regexp.exec');
  49076. _dereq_('core-js/modules/es.regexp.to-string');
  49077. _dereq_('core-js/modules/es.string.split');
  49078. Object.defineProperty(exports, '__esModule', { value: true });
  49079. exports.default = void 0;
  49080. var _main = _interopRequireDefault(_dereq_('../core/main'));
  49081. var _color_conversion = _interopRequireDefault(
  49082. _dereq_('../color/color_conversion')
  49083. );
  49084. function _interopRequireDefault(obj) {
  49085. return obj && obj.__esModule ? obj : { default: obj };
  49086. } /** //stores the original hsb values
  49087. * @module Environment
  49088. * @submodule Environment
  49089. * @for p5
  49090. * @requires core
  49091. */
  49092. var originalHSB; //stores values for color name exceptions
  49093. var colorExceptions = [
  49094. {
  49095. h: 0,
  49096. s: 0,
  49097. b: 0.8275,
  49098. name: 'gray'
  49099. },
  49100. {
  49101. h: 0,
  49102. s: 0,
  49103. b: 0.8627,
  49104. name: 'gray'
  49105. },
  49106. {
  49107. h: 0,
  49108. s: 0,
  49109. b: 0.7529,
  49110. name: 'gray'
  49111. },
  49112. {
  49113. h: 0.0167,
  49114. s: 0.1176,
  49115. b: 1,
  49116. name: 'light pink'
  49117. }
  49118. ];
  49119. //stores values for color names
  49120. var colorLookUp = [
  49121. {
  49122. h: 0,
  49123. s: 0,
  49124. b: 0,
  49125. name: 'black'
  49126. },
  49127. {
  49128. h: 0,
  49129. s: 0,
  49130. b: 0.5,
  49131. name: 'gray'
  49132. },
  49133. {
  49134. h: 0,
  49135. s: 0,
  49136. b: 1,
  49137. name: 'white'
  49138. },
  49139. {
  49140. h: 0,
  49141. s: 0.5,
  49142. b: 0.5,
  49143. name: 'dark maroon'
  49144. },
  49145. {
  49146. h: 0,
  49147. s: 0.5,
  49148. b: 1,
  49149. name: 'salmon pink'
  49150. },
  49151. {
  49152. h: 0,
  49153. s: 1,
  49154. b: 0,
  49155. name: 'black'
  49156. },
  49157. {
  49158. h: 0,
  49159. s: 1,
  49160. b: 0.5,
  49161. name: 'dark red'
  49162. },
  49163. {
  49164. h: 0,
  49165. s: 1,
  49166. b: 1,
  49167. name: 'red'
  49168. },
  49169. {
  49170. h: 5,
  49171. s: 0,
  49172. b: 1,
  49173. name: 'very light peach'
  49174. },
  49175. {
  49176. h: 5,
  49177. s: 0.5,
  49178. b: 0.5,
  49179. name: 'brown'
  49180. },
  49181. {
  49182. h: 5,
  49183. s: 0.5,
  49184. b: 1,
  49185. name: 'peach'
  49186. },
  49187. {
  49188. h: 5,
  49189. s: 1,
  49190. b: 0.5,
  49191. name: 'brick red'
  49192. },
  49193. {
  49194. h: 5,
  49195. s: 1,
  49196. b: 1,
  49197. name: 'crimson'
  49198. },
  49199. {
  49200. h: 10,
  49201. s: 0,
  49202. b: 1,
  49203. name: 'light peach'
  49204. },
  49205. {
  49206. h: 10,
  49207. s: 0.5,
  49208. b: 0.5,
  49209. name: 'brown'
  49210. },
  49211. {
  49212. h: 10,
  49213. s: 0.5,
  49214. b: 1,
  49215. name: 'light orange'
  49216. },
  49217. {
  49218. h: 10,
  49219. s: 1,
  49220. b: 0.5,
  49221. name: 'brown'
  49222. },
  49223. {
  49224. h: 10,
  49225. s: 1,
  49226. b: 1,
  49227. name: 'orange'
  49228. },
  49229. {
  49230. h: 15,
  49231. s: 0,
  49232. b: 1,
  49233. name: 'very light yellow'
  49234. },
  49235. {
  49236. h: 15,
  49237. s: 0.5,
  49238. b: 0.5,
  49239. name: 'olive green'
  49240. },
  49241. {
  49242. h: 15,
  49243. s: 0.5,
  49244. b: 1,
  49245. name: 'light yellow'
  49246. },
  49247. {
  49248. h: 15,
  49249. s: 1,
  49250. b: 0,
  49251. name: 'dark olive green'
  49252. },
  49253. {
  49254. h: 15,
  49255. s: 1,
  49256. b: 0.5,
  49257. name: 'olive green'
  49258. },
  49259. {
  49260. h: 15,
  49261. s: 1,
  49262. b: 1,
  49263. name: 'yellow'
  49264. },
  49265. {
  49266. h: 20,
  49267. s: 0,
  49268. b: 1,
  49269. name: 'very light yellow'
  49270. },
  49271. {
  49272. h: 20,
  49273. s: 0.5,
  49274. b: 0.5,
  49275. name: 'olive green'
  49276. },
  49277. {
  49278. h: 20,
  49279. s: 0.5,
  49280. b: 1,
  49281. name: 'light yellow green'
  49282. },
  49283. {
  49284. h: 20,
  49285. s: 1,
  49286. b: 0,
  49287. name: 'dark olive green'
  49288. },
  49289. {
  49290. h: 20,
  49291. s: 1,
  49292. b: 0.5,
  49293. name: 'dark yellow green'
  49294. },
  49295. {
  49296. h: 20,
  49297. s: 1,
  49298. b: 1,
  49299. name: 'yellow green'
  49300. },
  49301. {
  49302. h: 25,
  49303. s: 0.5,
  49304. b: 0.5,
  49305. name: 'dark yellow green'
  49306. },
  49307. {
  49308. h: 25,
  49309. s: 0.5,
  49310. b: 1,
  49311. name: 'light green'
  49312. },
  49313. {
  49314. h: 25,
  49315. s: 1,
  49316. b: 0.5,
  49317. name: 'dark green'
  49318. },
  49319. {
  49320. h: 25,
  49321. s: 1,
  49322. b: 1,
  49323. name: 'green'
  49324. },
  49325. {
  49326. h: 30,
  49327. s: 0.5,
  49328. b: 1,
  49329. name: 'light green'
  49330. },
  49331. {
  49332. h: 30,
  49333. s: 1,
  49334. b: 0.5,
  49335. name: 'dark green'
  49336. },
  49337. {
  49338. h: 30,
  49339. s: 1,
  49340. b: 1,
  49341. name: 'green'
  49342. },
  49343. {
  49344. h: 35,
  49345. s: 0,
  49346. b: 0.5,
  49347. name: 'light green'
  49348. },
  49349. {
  49350. h: 35,
  49351. s: 0,
  49352. b: 1,
  49353. name: 'very light green'
  49354. },
  49355. {
  49356. h: 35,
  49357. s: 0.5,
  49358. b: 0.5,
  49359. name: 'dark green'
  49360. },
  49361. {
  49362. h: 35,
  49363. s: 0.5,
  49364. b: 1,
  49365. name: 'light green'
  49366. },
  49367. {
  49368. h: 35,
  49369. s: 1,
  49370. b: 0,
  49371. name: 'very dark green'
  49372. },
  49373. {
  49374. h: 35,
  49375. s: 1,
  49376. b: 0.5,
  49377. name: 'dark green'
  49378. },
  49379. {
  49380. h: 35,
  49381. s: 1,
  49382. b: 1,
  49383. name: 'green'
  49384. },
  49385. {
  49386. h: 40,
  49387. s: 0,
  49388. b: 1,
  49389. name: 'very light green'
  49390. },
  49391. {
  49392. h: 40,
  49393. s: 0.5,
  49394. b: 0.5,
  49395. name: 'dark green'
  49396. },
  49397. {
  49398. h: 40,
  49399. s: 0.5,
  49400. b: 1,
  49401. name: 'light green'
  49402. },
  49403. {
  49404. h: 40,
  49405. s: 1,
  49406. b: 0.5,
  49407. name: 'dark green'
  49408. },
  49409. {
  49410. h: 40,
  49411. s: 1,
  49412. b: 1,
  49413. name: 'green'
  49414. },
  49415. {
  49416. h: 45,
  49417. s: 0.5,
  49418. b: 1,
  49419. name: 'light turquoise'
  49420. },
  49421. {
  49422. h: 45,
  49423. s: 1,
  49424. b: 0.5,
  49425. name: 'dark turquoise'
  49426. },
  49427. {
  49428. h: 45,
  49429. s: 1,
  49430. b: 1,
  49431. name: 'turquoise'
  49432. },
  49433. {
  49434. h: 50,
  49435. s: 0,
  49436. b: 1,
  49437. name: 'light sky blue'
  49438. },
  49439. {
  49440. h: 50,
  49441. s: 0.5,
  49442. b: 0.5,
  49443. name: 'dark cyan'
  49444. },
  49445. {
  49446. h: 50,
  49447. s: 0.5,
  49448. b: 1,
  49449. name: 'light cyan'
  49450. },
  49451. {
  49452. h: 50,
  49453. s: 1,
  49454. b: 0.5,
  49455. name: 'dark cyan'
  49456. },
  49457. {
  49458. h: 50,
  49459. s: 1,
  49460. b: 1,
  49461. name: 'cyan'
  49462. },
  49463. {
  49464. h: 55,
  49465. s: 0,
  49466. b: 1,
  49467. name: 'light sky blue'
  49468. },
  49469. {
  49470. h: 55,
  49471. s: 0.5,
  49472. b: 1,
  49473. name: 'light sky blue'
  49474. },
  49475. {
  49476. h: 55,
  49477. s: 1,
  49478. b: 0.5,
  49479. name: 'dark blue'
  49480. },
  49481. {
  49482. h: 55,
  49483. s: 1,
  49484. b: 1,
  49485. name: 'sky blue'
  49486. },
  49487. {
  49488. h: 60,
  49489. s: 0,
  49490. b: 0.5,
  49491. name: 'gray'
  49492. },
  49493. {
  49494. h: 60,
  49495. s: 0,
  49496. b: 1,
  49497. name: 'very light blue'
  49498. },
  49499. {
  49500. h: 60,
  49501. s: 0.5,
  49502. b: 0.5,
  49503. name: 'blue'
  49504. },
  49505. {
  49506. h: 60,
  49507. s: 0.5,
  49508. b: 1,
  49509. name: 'light blue'
  49510. },
  49511. {
  49512. h: 60,
  49513. s: 1,
  49514. b: 0.5,
  49515. name: 'navy blue'
  49516. },
  49517. {
  49518. h: 60,
  49519. s: 1,
  49520. b: 1,
  49521. name: 'blue'
  49522. },
  49523. {
  49524. h: 65,
  49525. s: 0,
  49526. b: 1,
  49527. name: 'lavender'
  49528. },
  49529. {
  49530. h: 65,
  49531. s: 0.5,
  49532. b: 0.5,
  49533. name: 'navy blue'
  49534. },
  49535. {
  49536. h: 65,
  49537. s: 0.5,
  49538. b: 1,
  49539. name: 'light purple'
  49540. },
  49541. {
  49542. h: 65,
  49543. s: 1,
  49544. b: 0.5,
  49545. name: 'dark navy blue'
  49546. },
  49547. {
  49548. h: 65,
  49549. s: 1,
  49550. b: 1,
  49551. name: 'blue'
  49552. },
  49553. {
  49554. h: 70,
  49555. s: 0,
  49556. b: 1,
  49557. name: 'lavender'
  49558. },
  49559. {
  49560. h: 70,
  49561. s: 0.5,
  49562. b: 0.5,
  49563. name: 'navy blue'
  49564. },
  49565. {
  49566. h: 70,
  49567. s: 0.5,
  49568. b: 1,
  49569. name: 'lavender blue'
  49570. },
  49571. {
  49572. h: 70,
  49573. s: 1,
  49574. b: 0.5,
  49575. name: 'dark navy blue'
  49576. },
  49577. {
  49578. h: 70,
  49579. s: 1,
  49580. b: 1,
  49581. name: 'blue'
  49582. },
  49583. {
  49584. h: 75,
  49585. s: 0.5,
  49586. b: 1,
  49587. name: 'lavender'
  49588. },
  49589. {
  49590. h: 75,
  49591. s: 1,
  49592. b: 0.5,
  49593. name: 'dark purple'
  49594. },
  49595. {
  49596. h: 75,
  49597. s: 1,
  49598. b: 1,
  49599. name: 'purple'
  49600. },
  49601. {
  49602. h: 80,
  49603. s: 0.5,
  49604. b: 1,
  49605. name: 'pinkish purple'
  49606. },
  49607. {
  49608. h: 80,
  49609. s: 1,
  49610. b: 0.5,
  49611. name: 'dark purple'
  49612. },
  49613. {
  49614. h: 80,
  49615. s: 1,
  49616. b: 1,
  49617. name: 'purple'
  49618. },
  49619. {
  49620. h: 85,
  49621. s: 0,
  49622. b: 1,
  49623. name: 'light pink'
  49624. },
  49625. {
  49626. h: 85,
  49627. s: 0.5,
  49628. b: 0.5,
  49629. name: 'purple'
  49630. },
  49631. {
  49632. h: 85,
  49633. s: 0.5,
  49634. b: 1,
  49635. name: 'light fuchsia'
  49636. },
  49637. {
  49638. h: 85,
  49639. s: 1,
  49640. b: 0.5,
  49641. name: 'dark fuchsia'
  49642. },
  49643. {
  49644. h: 85,
  49645. s: 1,
  49646. b: 1,
  49647. name: 'fuchsia'
  49648. },
  49649. {
  49650. h: 90,
  49651. s: 0.5,
  49652. b: 0.5,
  49653. name: 'dark fuchsia'
  49654. },
  49655. {
  49656. h: 90,
  49657. s: 0.5,
  49658. b: 1,
  49659. name: 'hot pink'
  49660. },
  49661. {
  49662. h: 90,
  49663. s: 1,
  49664. b: 0.5,
  49665. name: 'dark fuchsia'
  49666. },
  49667. {
  49668. h: 90,
  49669. s: 1,
  49670. b: 1,
  49671. name: 'fuchsia'
  49672. },
  49673. {
  49674. h: 95,
  49675. s: 0,
  49676. b: 1,
  49677. name: 'pink'
  49678. },
  49679. {
  49680. h: 95,
  49681. s: 0.5,
  49682. b: 1,
  49683. name: 'light pink'
  49684. },
  49685. {
  49686. h: 95,
  49687. s: 1,
  49688. b: 0.5,
  49689. name: 'dark magenta'
  49690. },
  49691. {
  49692. h: 95,
  49693. s: 1,
  49694. b: 1,
  49695. name: 'magenta'
  49696. }
  49697. ];
  49698. //returns text with color name
  49699. function _calculateColor(hsb) {
  49700. var colortext;
  49701. //round hue
  49702. if (hsb[0] !== 0) {
  49703. hsb[0] = Math.round(hsb[0] * 100);
  49704. var hue = hsb[0].toString().split('');
  49705. var last = hue.length - 1;
  49706. hue[last] = parseInt(hue[last]);
  49707. //if last digit of hue is < 2.5 make it 0
  49708. if (hue[last] < 2.5) {
  49709. hue[last] = 0;
  49710. //if last digit of hue is >= 2.5 and less than 7.5 make it 5
  49711. } else if (hue[last] >= 2.5 && hue[last] < 7.5) {
  49712. hue[last] = 5;
  49713. }
  49714. //if hue only has two digits
  49715. if (hue.length === 2) {
  49716. hue[0] = parseInt(hue[0]);
  49717. //if last is greater than 7.5
  49718. if (hue[last] >= 7.5) {
  49719. //add one to the tens
  49720. hue[last] = 0;
  49721. hue[0] = hue[0] + 1;
  49722. }
  49723. hsb[0] = hue[0] * 10 + hue[1];
  49724. } else {
  49725. if (hue[last] >= 7.5) {
  49726. hsb[0] = 10;
  49727. } else {
  49728. hsb[0] = hue[last];
  49729. }
  49730. }
  49731. }
  49732. //map brightness from 0 to 1
  49733. hsb[2] = hsb[2] / 255;
  49734. //round saturation and brightness
  49735. for (var i = hsb.length - 1; i >= 1; i--) {
  49736. if (hsb[i] <= 0.25) {
  49737. hsb[i] = 0;
  49738. } else if (hsb[i] > 0.25 && hsb[i] < 0.75) {
  49739. hsb[i] = 0.5;
  49740. } else {
  49741. hsb[i] = 1;
  49742. }
  49743. }
  49744. //after rounding, if the values are hue 0, saturation 0 and brightness 1
  49745. //look at color exceptions which includes several tones from white to gray
  49746. if (hsb[0] === 0 && hsb[1] === 0 && hsb[2] === 1) {
  49747. //round original hsb values
  49748. for (var _i = 2; _i >= 0; _i--) {
  49749. originalHSB[_i] = Math.round(originalHSB[_i] * 10000) / 10000;
  49750. }
  49751. //compare with the values in the colorExceptions array
  49752. for (var e = 0; e < colorExceptions.length; e++) {
  49753. if (
  49754. colorExceptions[e].h === originalHSB[0] &&
  49755. colorExceptions[e].s === originalHSB[1] &&
  49756. colorExceptions[e].b === originalHSB[2]
  49757. ) {
  49758. colortext = colorExceptions[e].name;
  49759. break;
  49760. } else {
  49761. //if there is no match return white
  49762. colortext = 'white';
  49763. }
  49764. }
  49765. } else {
  49766. //otherwise, compare with values in colorLookUp
  49767. for (var _i2 = 0; _i2 < colorLookUp.length; _i2++) {
  49768. if (
  49769. colorLookUp[_i2].h === hsb[0] &&
  49770. colorLookUp[_i2].s === hsb[1] &&
  49771. colorLookUp[_i2].b === hsb[2]
  49772. ) {
  49773. colortext = colorLookUp[_i2].name;
  49774. break;
  49775. }
  49776. }
  49777. }
  49778. return colortext;
  49779. }
  49780. //gets rgba and returs a color name
  49781. _main.default.prototype._rgbColorName = function(arg) {
  49782. //conversts rgba to hsb
  49783. var hsb = _color_conversion.default._rgbaToHSBA(arg);
  49784. //stores hsb in global variable
  49785. originalHSB = hsb;
  49786. //calculate color name
  49787. return _calculateColor([hsb[0], hsb[1], hsb[2]]);
  49788. };
  49789. var _default = _main.default;
  49790. exports.default = _default;
  49791. },
  49792. {
  49793. '../color/color_conversion': 268,
  49794. '../core/main': 283,
  49795. 'core-js/modules/es.function.name': 181,
  49796. 'core-js/modules/es.object.to-string': 192,
  49797. 'core-js/modules/es.regexp.exec': 196,
  49798. 'core-js/modules/es.regexp.to-string': 197,
  49799. 'core-js/modules/es.string.split': 206
  49800. }
  49801. ],
  49802. 263: [
  49803. function(_dereq_, module, exports) {
  49804. 'use strict';
  49805. _dereq_('core-js/modules/es.array.concat');
  49806. _dereq_('core-js/modules/es.regexp.exec');
  49807. _dereq_('core-js/modules/es.string.ends-with');
  49808. _dereq_('core-js/modules/es.string.replace');
  49809. Object.defineProperty(exports, '__esModule', { value: true });
  49810. exports.default = void 0;
  49811. var _main = _interopRequireDefault(_dereq_('../core/main'));
  49812. function _interopRequireDefault(obj) {
  49813. return obj && obj.__esModule ? obj : { default: obj };
  49814. }
  49815. /**
  49816. * @module Environment
  49817. * @submodule Environment
  49818. * @for p5
  49819. * @requires core
  49820. */ var descContainer = '_Description'; //Fallback container
  49821. var fallbackDescId = '_fallbackDesc'; //Fallback description
  49822. var fallbackTableId = '_fallbackTable'; //Fallback Table
  49823. var fallbackTableElId = '_fte_'; //Fallback Table Element
  49824. var labelContainer = '_Label'; //Label container
  49825. var labelDescId = '_labelDesc'; //Label description
  49826. var labelTableId = '_labelTable'; //Label Table
  49827. var labelTableElId = '_lte_'; //Label Table Element
  49828. /**
  49829. * Creates a screen reader accessible description for the canvas.
  49830. * The first parameter should be a string with a description of the canvas.
  49831. * The second parameter is optional. If specified, it determines how the
  49832. * description is displayed.
  49833. *
  49834. * <code class="language-javascript">describe(text, LABEL)</code> displays
  49835. * the description to all users as a <a
  49836. * href="https://en.wikipedia.org/wiki/Museum_label" target="_blank">
  49837. * tombstone or exhibit label/caption</a> in a div
  49838. * adjacent to the canvas. You can style it as you wish in your CSS.
  49839. *
  49840. * <code class="language-javascript">describe(text, FALLBACK)</code> makes the
  49841. * description accessible to screen-reader users only, in
  49842. * <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Hit_regions_and_accessibility" target="_blank">
  49843. * a sub DOM inside the canvas element</a>. If a second parameter is not
  49844. * specified, by default, the description will only be available to
  49845. * screen-reader users.
  49846. *
  49847. * @method describe
  49848. * @param {String} text description of the canvas
  49849. * @param {Constant} [display] either LABEL or FALLBACK
  49850. *
  49851. * @example
  49852. * <div>
  49853. * <code>
  49854. * describe('pink square with red heart in the bottom right corner');
  49855. * background('pink');
  49856. * fill('red');
  49857. * noStroke();
  49858. * ellipse(67, 67, 20, 20);
  49859. * ellipse(83, 67, 20, 20);
  49860. * triangle(91, 73, 75, 95, 59, 73);
  49861. * </code>
  49862. * </div>
  49863. *
  49864. * <div>
  49865. * <code>
  49866. * let x = 0;
  49867. * function draw() {
  49868. * if (x > 100) {
  49869. * x = 0;
  49870. * }
  49871. * background(220);
  49872. * fill(0, 255, 0);
  49873. * ellipse(x, 50, 40, 40);
  49874. * x = x + 0.1;
  49875. * describe('green circle at x pos ' + round(x) + ' moving to the right');
  49876. * }
  49877. * </code>
  49878. * </div>
  49879. *
  49880. */ _main.default.prototype.describe = function(text, display) {
  49881. _main.default._validateParameters('describe', arguments);
  49882. if (typeof text !== 'string') {
  49883. return;
  49884. }
  49885. var cnvId = this.canvas.id;
  49886. //calls function that adds punctuation for better screen reading
  49887. text = _descriptionText(text);
  49888. //if there is no dummyDOM
  49889. if (!this.dummyDOM) {
  49890. this.dummyDOM = document.getElementById(cnvId).parentNode;
  49891. }
  49892. if (!this.descriptions) {
  49893. this.descriptions = {};
  49894. }
  49895. //check if html structure for description is ready
  49896. if (this.descriptions.fallback) {
  49897. //check if text is different from current description
  49898. if (this.descriptions.fallback.innerHTML !== text) {
  49899. //update description
  49900. this.descriptions.fallback.innerHTML = text;
  49901. }
  49902. } else {
  49903. //create fallback html structure
  49904. this._describeHTML('fallback', text);
  49905. }
  49906. //if display is LABEL
  49907. if (display === this.LABEL) {
  49908. //check if html structure for label is ready
  49909. if (this.descriptions.label) {
  49910. //check if text is different from current label
  49911. if (this.descriptions.label.innerHTML !== text) {
  49912. //update label description
  49913. this.descriptions.label.innerHTML = text;
  49914. }
  49915. } else {
  49916. //create label html structure
  49917. this._describeHTML('label', text);
  49918. }
  49919. }
  49920. };
  49921. /**
  49922. * This function creates a screen-reader accessible
  49923. * description for elements —shapes or groups of shapes that create
  49924. * meaning together— in the canvas. The first paramater should
  49925. * be the name of the element. The second parameter should be a string
  49926. * with a description of the element. The third parameter is optional.
  49927. * If specified, it determines how the element description is displayed.
  49928. *
  49929. * <code class="language-javascript">describeElement(name, text, LABEL)</code>
  49930. * displays the element description to all users as a
  49931. * <a href="https://en.wikipedia.org/wiki/Museum_label" target="_blank">
  49932. * tombstone or exhibit label/caption</a> in a div
  49933. * adjacent to the canvas. You can style it as you wish in your CSS.
  49934. *
  49935. * <code class="language-javascript">describeElement(name, text, FALLBACK)</code>
  49936. * makes the element description accessible to screen-reader users
  49937. * only, in <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Hit_regions_and_accessibility" target="_blank">
  49938. * a sub DOM inside the canvas element</a>. If a second parameter is not
  49939. * specified, by default, the element description will only be available
  49940. * to screen-reader users.
  49941. *
  49942. * @method describeElement
  49943. * @param {String} name name of the element
  49944. * @param {String} text description of the element
  49945. * @param {Constant} [display] either LABEL or FALLBACK
  49946. *
  49947. * @example
  49948. * <div>
  49949. * <code>
  49950. * describe('Heart and yellow circle over pink background');
  49951. * noStroke();
  49952. * background('pink');
  49953. * describeElement('Circle', 'Yellow circle in the top left corner');
  49954. * fill('yellow');
  49955. * ellipse(25, 25, 40, 40);
  49956. * describeElement('Heart', 'red heart in the bottom right corner');
  49957. * fill('red');
  49958. * ellipse(66.6, 66.6, 20, 20);
  49959. * ellipse(83.2, 66.6, 20, 20);
  49960. * triangle(91.2, 72.6, 75, 95, 58.6, 72.6);
  49961. * </code>
  49962. * </div>
  49963. */
  49964. _main.default.prototype.describeElement = function(name, text, display) {
  49965. _main.default._validateParameters('describeElement', arguments);
  49966. if (typeof text !== 'string' || typeof name !== 'string') {
  49967. return;
  49968. }
  49969. var cnvId = this.canvas.id;
  49970. //calls function that adds punctuation for better screen reading
  49971. text = _descriptionText(text);
  49972. //calls function that adds punctuation for better screen reading
  49973. var elementName = _elementName(name);
  49974. //remove any special characters from name to use it as html id
  49975. name = name.replace(/[^a-zA-Z0-9]/g, '');
  49976. //store element description
  49977. var inner = '<th scope="row">'
  49978. .concat(elementName, '</th><td>')
  49979. .concat(text, '</td>');
  49980. //if there is no dummyDOM
  49981. if (!this.dummyDOM) {
  49982. this.dummyDOM = document.getElementById(cnvId).parentNode;
  49983. }
  49984. if (!this.descriptions) {
  49985. this.descriptions = { fallbackElements: {} };
  49986. } else if (!this.descriptions.fallbackElements) {
  49987. this.descriptions.fallbackElements = {};
  49988. }
  49989. //check if html structure for element description is ready
  49990. if (this.descriptions.fallbackElements[name]) {
  49991. //if current element description is not the same as inner
  49992. if (this.descriptions.fallbackElements[name].innerHTML !== inner) {
  49993. //update element description
  49994. this.descriptions.fallbackElements[name].innerHTML = inner;
  49995. }
  49996. } else {
  49997. //create fallback html structure
  49998. this._describeElementHTML('fallback', name, inner);
  49999. }
  50000. //if display is LABEL
  50001. if (display === this.LABEL) {
  50002. if (!this.descriptions.labelElements) {
  50003. this.descriptions.labelElements = {};
  50004. }
  50005. //if html structure for label element description is ready
  50006. if (this.descriptions.labelElements[name]) {
  50007. //if label element description is different
  50008. if (this.descriptions.labelElements[name].innerHTML !== inner) {
  50009. //update label element description
  50010. this.descriptions.labelElements[name].innerHTML = inner;
  50011. }
  50012. } else {
  50013. //create label element html structure
  50014. this._describeElementHTML('label', name, inner);
  50015. }
  50016. }
  50017. };
  50018. /*
  50019. *
  50020. * Helper functions for describe() and describeElement().
  50021. *
  50022. */
  50023. // check that text is not LABEL or FALLBACK and ensure text ends with punctuation mark
  50024. function _descriptionText(text) {
  50025. if (text === 'label' || text === 'fallback') {
  50026. throw new Error('description should not be LABEL or FALLBACK');
  50027. }
  50028. //if string does not end with '.'
  50029. if (
  50030. !text.endsWith('.') &&
  50031. !text.endsWith(';') &&
  50032. !text.endsWith(',') &&
  50033. !text.endsWith('?') &&
  50034. !text.endsWith('!')
  50035. ) {
  50036. //add '.' to the end of string
  50037. text = text + '.';
  50038. }
  50039. return text;
  50040. }
  50041. /*
  50042. * Helper functions for describe()
  50043. */
  50044. //creates HTML structure for canvas descriptions
  50045. _main.default.prototype._describeHTML = function(type, text) {
  50046. var cnvId = this.canvas.id;
  50047. if (type === 'fallback') {
  50048. //if there is no description container
  50049. if (!this.dummyDOM.querySelector('#'.concat(cnvId + descContainer))) {
  50050. //if there are no accessible outputs (see textOutput() and gridOutput())
  50051. var html = '<div id="'
  50052. .concat(cnvId)
  50053. .concat(
  50054. descContainer,
  50055. '" role="region" aria-label="Canvas Description"><p id="'
  50056. )
  50057. .concat(cnvId)
  50058. .concat(fallbackDescId, '"></p></div>');
  50059. if (!this.dummyDOM.querySelector('#'.concat(cnvId, 'accessibleOutput'))) {
  50060. //create description container + <p> for fallback description
  50061. this.dummyDOM.querySelector('#'.concat(cnvId)).innerHTML = html;
  50062. } else {
  50063. //create description container + <p> for fallback description before outputs
  50064. this.dummyDOM
  50065. .querySelector('#'.concat(cnvId, 'accessibleOutput'))
  50066. .insertAdjacentHTML('beforebegin', html);
  50067. }
  50068. } else {
  50069. //if describeElement() has already created the container and added a table of elements
  50070. //create fallback description <p> before the table
  50071. this.dummyDOM
  50072. .querySelector('#' + cnvId + fallbackTableId)
  50073. .insertAdjacentHTML(
  50074. 'beforebegin',
  50075. '<p id="'.concat(cnvId + fallbackDescId, '"></p>')
  50076. );
  50077. }
  50078. //if the container for the description exists
  50079. this.descriptions.fallback = this.dummyDOM.querySelector(
  50080. '#'.concat(cnvId).concat(fallbackDescId)
  50081. );
  50082. this.descriptions.fallback.innerHTML = text;
  50083. return;
  50084. } else if (type === 'label') {
  50085. //if there is no label container
  50086. if (!this.dummyDOM.querySelector('#'.concat(cnvId + labelContainer))) {
  50087. var _html = '<div id="'
  50088. .concat(cnvId)
  50089. .concat(labelContainer, '" class="p5Label"><p id="')
  50090. .concat(cnvId)
  50091. .concat(labelDescId, '"></p></div>');
  50092. //if there are no accessible outputs (see textOutput() and gridOutput())
  50093. if (
  50094. !this.dummyDOM.querySelector('#'.concat(cnvId, 'accessibleOutputLabel'))
  50095. ) {
  50096. //create label container + <p> for label description
  50097. this.dummyDOM
  50098. .querySelector('#' + cnvId)
  50099. .insertAdjacentHTML('afterend', _html);
  50100. } else {
  50101. //create label container + <p> for label description before outputs
  50102. this.dummyDOM
  50103. .querySelector('#'.concat(cnvId, 'accessibleOutputLabel'))
  50104. .insertAdjacentHTML('beforebegin', _html);
  50105. }
  50106. } else if (this.dummyDOM.querySelector('#'.concat(cnvId + labelTableId))) {
  50107. //if describeElement() has already created the container and added a table of elements
  50108. //create label description <p> before the table
  50109. this.dummyDOM
  50110. .querySelector('#'.concat(cnvId + labelTableId))
  50111. .insertAdjacentHTML(
  50112. 'beforebegin',
  50113. '<p id="'.concat(cnvId).concat(labelDescId, '"></p>')
  50114. );
  50115. }
  50116. this.descriptions.label = this.dummyDOM.querySelector(
  50117. '#' + cnvId + labelDescId
  50118. );
  50119. this.descriptions.label.innerHTML = text;
  50120. return;
  50121. }
  50122. };
  50123. /*
  50124. * Helper functions for describeElement().
  50125. */
  50126. //check that name is not LABEL or FALLBACK and ensure text ends with colon
  50127. function _elementName(name) {
  50128. if (name === 'label' || name === 'fallback') {
  50129. throw new Error('element name should not be LABEL or FALLBACK');
  50130. }
  50131. //check if last character of string n is '.', ';', or ','
  50132. if (name.endsWith('.') || name.endsWith(';') || name.endsWith(',')) {
  50133. //replace last character with ':'
  50134. name = name.replace(/.$/, ':');
  50135. } else if (!name.endsWith(':')) {
  50136. //if string n does not end with ':'
  50137. //add ':'' at the end of string
  50138. name = name + ':';
  50139. }
  50140. return name;
  50141. }
  50142. //creates HTML structure for element descriptions
  50143. _main.default.prototype._describeElementHTML = function(type, name, text) {
  50144. var cnvId = this.canvas.id;
  50145. if (type === 'fallback') {
  50146. //if there is no description container
  50147. if (!this.dummyDOM.querySelector('#'.concat(cnvId + descContainer))) {
  50148. //if there are no accessible outputs (see textOutput() and gridOutput())
  50149. var html = '<div id="'
  50150. .concat(cnvId)
  50151. .concat(
  50152. descContainer,
  50153. '" role="region" aria-label="Canvas Description"><table id="'
  50154. )
  50155. .concat(cnvId)
  50156. .concat(
  50157. fallbackTableId,
  50158. '"><caption>Canvas elements and their descriptions</caption></table></div>'
  50159. );
  50160. if (!this.dummyDOM.querySelector('#'.concat(cnvId, 'accessibleOutput'))) {
  50161. //create container + table for element descriptions
  50162. this.dummyDOM.querySelector('#' + cnvId).innerHTML = html;
  50163. } else {
  50164. //create container + table for element descriptions before outputs
  50165. this.dummyDOM
  50166. .querySelector('#'.concat(cnvId, 'accessibleOutput'))
  50167. .insertAdjacentHTML('beforebegin', html);
  50168. }
  50169. } else if (!this.dummyDOM.querySelector('#' + cnvId + fallbackTableId)) {
  50170. //if describe() has already created the container and added a description
  50171. //and there is no table create fallback table for element description after
  50172. //fallback description
  50173. this.dummyDOM
  50174. .querySelector('#' + cnvId + fallbackDescId)
  50175. .insertAdjacentHTML(
  50176. 'afterend',
  50177. '<table id="'
  50178. .concat(cnvId)
  50179. .concat(
  50180. fallbackTableId,
  50181. '"><caption>Canvas elements and their descriptions</caption></table>'
  50182. )
  50183. );
  50184. }
  50185. //create a table row for the element
  50186. var tableRow = document.createElement('tr');
  50187. tableRow.id = cnvId + fallbackTableElId + name;
  50188. this.dummyDOM
  50189. .querySelector('#' + cnvId + fallbackTableId)
  50190. .appendChild(tableRow);
  50191. //update element description
  50192. this.descriptions.fallbackElements[name] = this.dummyDOM.querySelector(
  50193. '#'
  50194. .concat(cnvId)
  50195. .concat(fallbackTableElId)
  50196. .concat(name)
  50197. );
  50198. this.descriptions.fallbackElements[name].innerHTML = text;
  50199. return;
  50200. } else if (type === 'label') {
  50201. //If display is LABEL creates a div adjacent to the canvas element with
  50202. //a table, a row header cell with the name of the elements,
  50203. //and adds the description of the element in adjecent cell.
  50204. //if there is no label description container
  50205. if (!this.dummyDOM.querySelector('#'.concat(cnvId + labelContainer))) {
  50206. //if there are no accessible outputs (see textOutput() and gridOutput())
  50207. var _html2 = '<div id="'
  50208. .concat(cnvId)
  50209. .concat(labelContainer, '" class="p5Label"><table id="')
  50210. .concat(cnvId)
  50211. .concat(labelTableId, '"></table></div>');
  50212. if (
  50213. !this.dummyDOM.querySelector('#'.concat(cnvId, 'accessibleOutputLabel'))
  50214. ) {
  50215. //create container + table for element descriptions
  50216. this.dummyDOM
  50217. .querySelector('#' + cnvId)
  50218. .insertAdjacentHTML('afterend', _html2);
  50219. } else {
  50220. //create container + table for element descriptions before outputs
  50221. this.dummyDOM
  50222. .querySelector('#'.concat(cnvId, 'accessibleOutputLabel'))
  50223. .insertAdjacentHTML('beforebegin', _html2);
  50224. }
  50225. } else if (!this.dummyDOM.querySelector('#'.concat(cnvId + labelTableId))) {
  50226. //if describe() has already created the label container and added a description
  50227. //and there is no table create label table for element description after
  50228. //label description
  50229. this.dummyDOM
  50230. .querySelector('#' + cnvId + labelDescId)
  50231. .insertAdjacentHTML(
  50232. 'afterend',
  50233. '<table id="'.concat(cnvId + labelTableId, '"></table>')
  50234. );
  50235. }
  50236. //create a table row for the element label description
  50237. var _tableRow = document.createElement('tr');
  50238. _tableRow.id = cnvId + labelTableElId + name;
  50239. this.dummyDOM
  50240. .querySelector('#' + cnvId + labelTableId)
  50241. .appendChild(_tableRow);
  50242. //update element label description
  50243. this.descriptions.labelElements[name] = this.dummyDOM.querySelector(
  50244. '#'
  50245. .concat(cnvId)
  50246. .concat(labelTableElId)
  50247. .concat(name)
  50248. );
  50249. this.descriptions.labelElements[name].innerHTML = text;
  50250. }
  50251. };
  50252. var _default = _main.default;
  50253. exports.default = _default;
  50254. },
  50255. {
  50256. '../core/main': 283,
  50257. 'core-js/modules/es.array.concat': 166,
  50258. 'core-js/modules/es.regexp.exec': 196,
  50259. 'core-js/modules/es.string.ends-with': 199,
  50260. 'core-js/modules/es.string.replace': 204
  50261. }
  50262. ],
  50263. 264: [
  50264. function(_dereq_, module, exports) {
  50265. 'use strict';
  50266. _dereq_('core-js/modules/es.array.concat');
  50267. _dereq_('core-js/modules/es.array.map');
  50268. Object.defineProperty(exports, '__esModule', { value: true });
  50269. exports.default = void 0;
  50270. var _main = _interopRequireDefault(_dereq_('../core/main'));
  50271. function _interopRequireDefault(obj) {
  50272. return obj && obj.__esModule ? obj : { default: obj };
  50273. } /** //the functions in this file support updating the grid output
  50274. * @module Environment
  50275. * @submodule Environment
  50276. * @for p5
  50277. * @requires core
  50278. */
  50279. //updates gridOutput
  50280. _main.default.prototype._updateGridOutput = function(idT) {
  50281. //if html structure is not there yet
  50282. if (!this.dummyDOM.querySelector('#'.concat(idT, '_summary'))) {
  50283. return;
  50284. }
  50285. var current = this._accessibleOutputs[idT];
  50286. //create shape details list
  50287. var innerShapeDetails = _gridShapeDetails(idT, this.ingredients.shapes);
  50288. //create summary
  50289. var innerSummary = _gridSummary(
  50290. innerShapeDetails.numShapes,
  50291. this.ingredients.colors.background,
  50292. this.width,
  50293. this.height
  50294. );
  50295. //create grid map
  50296. var innerMap = _gridMap(idT, this.ingredients.shapes);
  50297. //if it is different from current summary
  50298. if (innerSummary !== current.summary.innerHTML) {
  50299. //update
  50300. current.summary.innerHTML = innerSummary;
  50301. }
  50302. //if it is different from current map
  50303. if (innerMap !== current.map.innerHTML) {
  50304. //update
  50305. current.map.innerHTML = innerMap;
  50306. }
  50307. //if it is different from current shape details
  50308. if (innerShapeDetails.details !== current.shapeDetails.innerHTML) {
  50309. //update
  50310. current.shapeDetails.innerHTML = innerShapeDetails.details;
  50311. }
  50312. this._accessibleOutputs[idT] = current;
  50313. };
  50314. //creates spatial grid that maps the location of shapes
  50315. function _gridMap(idT, ingredients) {
  50316. var shapeNumber = 0;
  50317. var table = '';
  50318. //create an array of arrays 10*10 of empty cells
  50319. var cells = Array.apply(null, Array(10)).map(function() {});
  50320. for (var r in cells) {
  50321. cells[r] = Array.apply(null, Array(10)).map(function() {});
  50322. }
  50323. for (var x in ingredients) {
  50324. for (var y in ingredients[x]) {
  50325. var fill = void 0;
  50326. if (x !== 'line') {
  50327. fill = '<a href="#'
  50328. .concat(idT, 'shape')
  50329. .concat(shapeNumber, '">')
  50330. .concat(ingredients[x][y].color, ' ')
  50331. .concat(x, '</a>');
  50332. } else {
  50333. fill = '<a href="#'
  50334. .concat(idT, 'shape')
  50335. .concat(shapeNumber, '">')
  50336. .concat(ingredients[x][y].color, ' ')
  50337. .concat(x, ' midpoint</a>');
  50338. }
  50339. //if empty cell of location of shape is undefined
  50340. if (!cells[ingredients[x][y].loc.locY][ingredients[x][y].loc.locX]) {
  50341. //fill it with shape info
  50342. cells[ingredients[x][y].loc.locY][ingredients[x][y].loc.locX] = fill;
  50343. //if a shape is already in that location
  50344. } else {
  50345. //add it
  50346. cells[ingredients[x][y].loc.locY][ingredients[x][y].loc.locX] =
  50347. cells[ingredients[x][y].loc.locY][ingredients[x][y].loc.locX] +
  50348. ' ' +
  50349. fill;
  50350. }
  50351. shapeNumber++;
  50352. }
  50353. }
  50354. //make table based on array
  50355. for (var _r in cells) {
  50356. var row = '<tr>';
  50357. for (var c in cells[_r]) {
  50358. row = row + '<td>';
  50359. if (cells[_r][c] !== undefined) {
  50360. row = row + cells[_r][c];
  50361. }
  50362. row = row + '</td>';
  50363. }
  50364. table = table + row + '</tr>';
  50365. }
  50366. return table;
  50367. }
  50368. //creates grid summary
  50369. function _gridSummary(numShapes, background, width, height) {
  50370. var text = ''
  50371. .concat(background, ' canvas, ')
  50372. .concat(width, ' by ')
  50373. .concat(height, ' pixels, contains ')
  50374. .concat(numShapes[0]);
  50375. if (numShapes[0] === 1) {
  50376. text = ''.concat(text, ' shape: ').concat(numShapes[1]);
  50377. } else {
  50378. text = ''.concat(text, ' shapes: ').concat(numShapes[1]);
  50379. }
  50380. return text;
  50381. }
  50382. //creates list of shapes
  50383. function _gridShapeDetails(idT, ingredients) {
  50384. var shapeDetails = '';
  50385. var shapes = '';
  50386. var totalShapes = 0;
  50387. //goes trhough every shape type in ingredients
  50388. for (var x in ingredients) {
  50389. var shapeNum = 0;
  50390. for (var y in ingredients[x]) {
  50391. //it creates a line in a list
  50392. var line = '<li id="'
  50393. .concat(idT, 'shape')
  50394. .concat(totalShapes, '">')
  50395. .concat(ingredients[x][y].color, ' ')
  50396. .concat(x, ',');
  50397. if (x === 'line') {
  50398. line =
  50399. line +
  50400. ' location = '
  50401. .concat(ingredients[x][y].pos, ', length = ')
  50402. .concat(ingredients[x][y].length, ' pixels');
  50403. } else {
  50404. line = line + ' location = '.concat(ingredients[x][y].pos);
  50405. if (x !== 'point') {
  50406. line = line + ', area = '.concat(ingredients[x][y].area, ' %');
  50407. }
  50408. line = line + '</li>';
  50409. }
  50410. shapeDetails = shapeDetails + line;
  50411. shapeNum++;
  50412. totalShapes++;
  50413. }
  50414. if (shapeNum > 1) {
  50415. shapes = ''
  50416. .concat(shapes, ' ')
  50417. .concat(shapeNum, ' ')
  50418. .concat(x, 's');
  50419. } else {
  50420. shapes = ''
  50421. .concat(shapes, ' ')
  50422. .concat(shapeNum, ' ')
  50423. .concat(x);
  50424. }
  50425. }
  50426. return { numShapes: [totalShapes, shapes], details: shapeDetails };
  50427. }
  50428. var _default = _main.default;
  50429. exports.default = _default;
  50430. },
  50431. {
  50432. '../core/main': 283,
  50433. 'core-js/modules/es.array.concat': 166,
  50434. 'core-js/modules/es.array.map': 177
  50435. }
  50436. ],
  50437. 265: [
  50438. function(_dereq_, module, exports) {
  50439. 'use strict';
  50440. _dereq_('core-js/modules/es.array.concat');
  50441. _dereq_('core-js/modules/es.array.fill');
  50442. _dereq_('core-js/modules/es.array.map');
  50443. _dereq_('core-js/modules/es.number.to-fixed');
  50444. Object.defineProperty(exports, '__esModule', { value: true });
  50445. exports.default = void 0;
  50446. var _main = _interopRequireDefault(_dereq_('../core/main'));
  50447. function _interopRequireDefault(obj) {
  50448. return obj && obj.__esModule ? obj : { default: obj };
  50449. }
  50450. /**
  50451. * @module Environment
  50452. * @submodule Environment
  50453. * @for p5
  50454. * @requires core
  50455. */ /**
  50456. * <code class="language-javascript">textOutput()</code> creates a screenreader
  50457. * accessible output that describes the shapes present on the canvas.
  50458. * The general description of the canvas includes canvas size,
  50459. * canvas color, and number of elements in the canvas
  50460. * (example: 'Your output is a, 400 by 400 pixels, lavender blue
  50461. * canvas containing the following 4 shapes:'). This description
  50462. * is followed by a list of shapes where the color, position, and area
  50463. * of each shape are described (example: "orange ellipse at top left
  50464. * covering 1% of the canvas"). Each element can be selected to get
  50465. * more details. A table of elements is also provided. In this table,
  50466. * shape, color, location, coordinates and area are described
  50467. * (example: "orange ellipse location=top left area=2").
  50468. *
  50469. * <code class="language-javascript">textOutput()</code> and <code class="language-javascript">textOutput(FALLBACK)</code>
  50470. * make the output available in <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Hit_regions_and_accessibility" target="_blank">
  50471. * a sub DOM inside the canvas element</a> which is accessible to screen readers.
  50472. * <code class="language-javascript">textOutput(LABEL)</code> creates an
  50473. * additional div with the output adjacent to the canvas, this is useful
  50474. * for non-screen reader users that might want to display the output outside
  50475. * of the canvas' sub DOM as they code. However, using LABEL will create
  50476. * unnecessary redundancy for screen reader users. We recommend using LABEL
  50477. * only as part of the development process of a sketch and removing it before
  50478. * publishing or sharing with screen reader users.
  50479. *
  50480. * @method textOutput
  50481. * @param {Constant} [display] either FALLBACK or LABEL
  50482. *
  50483. * @example
  50484. * <div>
  50485. * <code>
  50486. * textOutput();
  50487. * background(148, 196, 0);
  50488. * fill(255, 0, 0);
  50489. * ellipse(20, 20, 20, 20);
  50490. * fill(0, 0, 255);
  50491. * rect(50, 50, 50, 50);
  50492. * </code>
  50493. * </div>
  50494. *
  50495. *
  50496. * <div>
  50497. * <code>
  50498. * let x = 0;
  50499. * function draw() {
  50500. * textOutput();
  50501. * background(148, 196, 0);
  50502. * fill(255, 0, 0);
  50503. * ellipse(x, 20, 20, 20);
  50504. * fill(0, 0, 255);
  50505. * rect(50, 50, 50, 50);
  50506. * ellipse(20, 20, 20, 20);
  50507. * x += 0.1;
  50508. * }
  50509. * </code>
  50510. * </div>
  50511. *
  50512. */ _main.default.prototype.textOutput = function(display) {
  50513. _main.default._validateParameters('textOutput', arguments);
  50514. //if textOutput is already true
  50515. if (this._accessibleOutputs.text) {
  50516. return;
  50517. } else {
  50518. //make textOutput true
  50519. this._accessibleOutputs.text = true;
  50520. //create output for fallback
  50521. this._createOutput('textOutput', 'Fallback');
  50522. if (display === this.LABEL) {
  50523. //make textOutput label true
  50524. this._accessibleOutputs.textLabel = true;
  50525. //create output for label
  50526. this._createOutput('textOutput', 'Label');
  50527. }
  50528. }
  50529. };
  50530. /**
  50531. * <code class="language-javascript">gridOutput()</code> lays out the
  50532. * content of the canvas in the form of a grid (html table) based
  50533. * on the spatial location of each shape. A brief
  50534. * description of the canvas is available before the table output.
  50535. * This description includes: color of the background, size of the canvas,
  50536. * number of objects, and object types (example: "lavender blue canvas is
  50537. * 200 by 200 and contains 4 objects - 3 ellipses 1 rectangle"). The grid
  50538. * describes the content spatially, each element is placed on a cell of the
  50539. * table depending on its position. Within each cell an element the color
  50540. * and type of shape of that element are available (example: "orange ellipse").
  50541. * These descriptions can be selected individually to get more details.
  50542. * A list of elements where shape, color, location, and area are described
  50543. * (example: "orange ellipse location=top left area=1%") is also available.
  50544. *
  50545. * <code class="language-javascript">gridOutput()</code> and <code class="language-javascript">gridOutput(FALLBACK)</code>
  50546. * make the output available in <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Hit_regions_and_accessibility" target="_blank">
  50547. * a sub DOM inside the canvas element</a> which is accessible to screen readers.
  50548. * <code class="language-javascript">gridOutput(LABEL)</code> creates an
  50549. * additional div with the output adjacent to the canvas, this is useful
  50550. * for non-screen reader users that might want to display the output outside
  50551. * of the canvas' sub DOM as they code. However, using LABEL will create
  50552. * unnecessary redundancy for screen reader users. We recommend using LABEL
  50553. * only as part of the development process of a sketch and removing it before
  50554. * publishing or sharing with screen reader users.
  50555. *
  50556. * @method gridOutput
  50557. * @param {Constant} [display] either FALLBACK or LABEL
  50558. *
  50559. * @example
  50560. * <div>
  50561. * <code>
  50562. * gridOutput();
  50563. * background(148, 196, 0);
  50564. * fill(255, 0, 0);
  50565. * ellipse(20, 20, 20, 20);
  50566. * fill(0, 0, 255);
  50567. * rect(50, 50, 50, 50);
  50568. * </code>
  50569. * </div>
  50570. *
  50571. *
  50572. * <div>
  50573. * <code>
  50574. * let x = 0;
  50575. * function draw() {
  50576. * gridOutput();
  50577. * background(148, 196, 0);
  50578. * fill(255, 0, 0);
  50579. * ellipse(x, 20, 20, 20);
  50580. * fill(0, 0, 255);
  50581. * rect(50, 50, 50, 50);
  50582. * ellipse(20, 20, 20, 20);
  50583. * x += 0.1;
  50584. * }
  50585. * </code>
  50586. * </div>
  50587. *
  50588. */
  50589. _main.default.prototype.gridOutput = function(display) {
  50590. _main.default._validateParameters('gridOutput', arguments);
  50591. //if gridOutput is already true
  50592. if (this._accessibleOutputs.grid) {
  50593. return;
  50594. } else {
  50595. //make gridOutput true
  50596. this._accessibleOutputs.grid = true;
  50597. //create output for fallback
  50598. this._createOutput('gridOutput', 'Fallback');
  50599. if (display === this.LABEL) {
  50600. //make gridOutput label true
  50601. this._accessibleOutputs.gridLabel = true;
  50602. //create output for label
  50603. this._createOutput('gridOutput', 'Label');
  50604. }
  50605. }
  50606. };
  50607. //helper function returns true when accessible outputs are true
  50608. _main.default.prototype._addAccsOutput = function() {
  50609. //if there are no accessible outputs create object with all false
  50610. if (!this._accessibleOutputs) {
  50611. this._accessibleOutputs = {
  50612. text: false,
  50613. grid: false,
  50614. textLabel: false,
  50615. gridLabel: false
  50616. };
  50617. }
  50618. return this._accessibleOutputs.grid || this._accessibleOutputs.text;
  50619. };
  50620. //helper function that creates html structure for accessible outputs
  50621. _main.default.prototype._createOutput = function(type, display) {
  50622. var cnvId = this.canvas.id;
  50623. //if there are no ingredients create object. this object stores data for the outputs
  50624. if (!this.ingredients) {
  50625. this.ingredients = {
  50626. shapes: {},
  50627. colors: { background: 'white', fill: 'white', stroke: 'black' },
  50628. pShapes: ''
  50629. };
  50630. }
  50631. //if there is no dummyDOM create it
  50632. if (!this.dummyDOM) {
  50633. this.dummyDOM = document.getElementById(cnvId).parentNode;
  50634. }
  50635. var cIdT, container, inner;
  50636. var query = '';
  50637. if (display === 'Fallback') {
  50638. cIdT = cnvId + type;
  50639. container = cnvId + 'accessibleOutput';
  50640. if (!this.dummyDOM.querySelector('#'.concat(container))) {
  50641. //if there is no canvas description (see describe() and describeElement())
  50642. if (!this.dummyDOM.querySelector('#'.concat(cnvId, '_Description'))) {
  50643. //create html structure inside of canvas
  50644. this.dummyDOM.querySelector(
  50645. '#'.concat(cnvId)
  50646. ).innerHTML = '<div id="'.concat(
  50647. container,
  50648. '" role="region" aria-label="Canvas Outputs"></div>'
  50649. );
  50650. } else {
  50651. //create html structure after canvas description container
  50652. this.dummyDOM
  50653. .querySelector('#'.concat(cnvId, '_Description'))
  50654. .insertAdjacentHTML(
  50655. 'afterend',
  50656. '<div id="'.concat(
  50657. container,
  50658. '" role="region" aria-label="Canvas Outputs"></div>'
  50659. )
  50660. );
  50661. }
  50662. }
  50663. } else if (display === 'Label') {
  50664. query = display;
  50665. cIdT = cnvId + type + display;
  50666. container = cnvId + 'accessibleOutput' + display;
  50667. if (!this.dummyDOM.querySelector('#'.concat(container))) {
  50668. //if there is no canvas description label (see describe() and describeElement())
  50669. if (!this.dummyDOM.querySelector('#'.concat(cnvId, '_Label'))) {
  50670. //create html structure adjacent to canvas
  50671. this.dummyDOM
  50672. .querySelector('#'.concat(cnvId))
  50673. .insertAdjacentHTML(
  50674. 'afterend',
  50675. '<div id="'.concat(container, '"></div>')
  50676. );
  50677. } else {
  50678. //create html structure after canvas label
  50679. this.dummyDOM
  50680. .querySelector('#'.concat(cnvId, '_Label'))
  50681. .insertAdjacentHTML(
  50682. 'afterend',
  50683. '<div id="'.concat(container, '"></div>')
  50684. );
  50685. }
  50686. }
  50687. }
  50688. //create an object to store the latest output. this object is used in _updateTextOutput() and _updateGridOutput()
  50689. this._accessibleOutputs[cIdT] = {};
  50690. if (type === 'textOutput') {
  50691. query = '#'.concat(cnvId, 'gridOutput').concat(query); //query is used to check if gridOutput already exists
  50692. inner = '<div id="'
  50693. .concat(cIdT, '">Text Output<div id="')
  50694. .concat(cIdT, 'Summary" aria-label="text output summary"><p id="')
  50695. .concat(cIdT, '_summary"></p><ul id="')
  50696. .concat(cIdT, '_list"></ul></div><table id="')
  50697. .concat(
  50698. cIdT,
  50699. '_shapeDetails" summary="text output shape details"></table></div>'
  50700. );
  50701. //if gridOutput already exists
  50702. if (this.dummyDOM.querySelector(query)) {
  50703. //create textOutput before gridOutput
  50704. this.dummyDOM.querySelector(query).insertAdjacentHTML('beforebegin', inner);
  50705. } else {
  50706. //create output inside of container
  50707. this.dummyDOM.querySelector('#'.concat(container)).innerHTML = inner;
  50708. }
  50709. //store output html elements
  50710. this._accessibleOutputs[cIdT].list = this.dummyDOM.querySelector(
  50711. '#'.concat(cIdT, '_list')
  50712. );
  50713. } else if (type === 'gridOutput') {
  50714. query = '#'.concat(cnvId, 'textOutput').concat(query); //query is used to check if textOutput already exists
  50715. inner = '<div id="'
  50716. .concat(cIdT, '">Grid Output<p id="')
  50717. .concat(cIdT, '_summary" aria-label="grid output summary"><table id="')
  50718. .concat(cIdT, '_map" summary="grid output content"></table><ul id="')
  50719. .concat(
  50720. cIdT,
  50721. '_shapeDetails" aria-label="grid output shape details"></ul></div>'
  50722. );
  50723. //if textOutput already exists
  50724. if (this.dummyDOM.querySelector(query)) {
  50725. //create gridOutput after textOutput
  50726. this.dummyDOM.querySelector(query).insertAdjacentHTML('afterend', inner);
  50727. } else {
  50728. //create output inside of container
  50729. this.dummyDOM.querySelector('#'.concat(container)).innerHTML = inner;
  50730. }
  50731. //store output html elements
  50732. this._accessibleOutputs[cIdT].map = this.dummyDOM.querySelector(
  50733. '#'.concat(cIdT, '_map')
  50734. );
  50735. }
  50736. this._accessibleOutputs[cIdT].shapeDetails = this.dummyDOM.querySelector(
  50737. '#'.concat(cIdT, '_shapeDetails')
  50738. );
  50739. this._accessibleOutputs[cIdT].summary = this.dummyDOM.querySelector(
  50740. '#'.concat(cIdT, '_summary')
  50741. );
  50742. };
  50743. //this function is called at the end of setup and draw if using
  50744. //accessibleOutputs and calls update functions of outputs
  50745. _main.default.prototype._updateAccsOutput = function() {
  50746. var cnvId = this.canvas.id;
  50747. //if the shapes are not the same as before
  50748. if (JSON.stringify(this.ingredients.shapes) !== this.ingredients.pShapes) {
  50749. //save current shapes as string in pShapes
  50750. this.ingredients.pShapes = JSON.stringify(this.ingredients.shapes);
  50751. if (this._accessibleOutputs.text) {
  50752. this._updateTextOutput(cnvId + 'textOutput');
  50753. }
  50754. if (this._accessibleOutputs.grid) {
  50755. this._updateGridOutput(cnvId + 'gridOutput');
  50756. }
  50757. if (this._accessibleOutputs.textLabel) {
  50758. this._updateTextOutput(cnvId + 'textOutputLabel');
  50759. }
  50760. if (this._accessibleOutputs.gridLabel) {
  50761. this._updateGridOutput(cnvId + 'gridOutputLabel');
  50762. }
  50763. }
  50764. };
  50765. //helper function that resets all ingredients when background is called
  50766. //and saves background color name
  50767. _main.default.prototype._accsBackground = function(args) {
  50768. //save current shapes as string in pShapes
  50769. this.ingredients.pShapes = JSON.stringify(this.ingredients.shapes);
  50770. //empty shapes JSON
  50771. this.ingredients.shapes = {};
  50772. //update background different
  50773. if (this.ingredients.colors.backgroundRGBA !== args) {
  50774. this.ingredients.colors.backgroundRGBA = args;
  50775. this.ingredients.colors.background = this._rgbColorName(args);
  50776. }
  50777. };
  50778. //helper function that gets fill and stroke of shapes
  50779. _main.default.prototype._accsCanvasColors = function(f, args) {
  50780. if (f === 'fill') {
  50781. //update fill different
  50782. if (this.ingredients.colors.fillRGBA !== args) {
  50783. this.ingredients.colors.fillRGBA = args;
  50784. this.ingredients.colors.fill = this._rgbColorName(args);
  50785. }
  50786. } else if (f === 'stroke') {
  50787. //update stroke if different
  50788. if (this.ingredients.colors.strokeRGBA !== args) {
  50789. this.ingredients.colors.strokeRGBA = args;
  50790. this.ingredients.colors.stroke = this._rgbColorName(args);
  50791. }
  50792. }
  50793. };
  50794. //builds ingredients.shapes used for building outputs
  50795. _main.default.prototype._accsOutput = function(f, args) {
  50796. if (f === 'ellipse' && args[2] === args[3]) {
  50797. f = 'circle';
  50798. } else if (f === 'rectangle' && args[2] === args[3]) {
  50799. f = 'square';
  50800. }
  50801. var include = {};
  50802. var add = true;
  50803. var middle = _getMiddle(f, args);
  50804. if (f === 'line') {
  50805. //make color stroke
  50806. include.color = this.ingredients.colors.stroke;
  50807. //get lenght
  50808. include.length = Math.round(this.dist(args[0], args[1], args[2], args[3]));
  50809. //get position of end points
  50810. var p1 = _getPos([args[0], [1]], this.width, this.height);
  50811. var p2 = _getPos([args[2], [3]], this.width, this.height);
  50812. include.loc = _canvasLocator(middle, this.width, this.height);
  50813. if (p1 === p2) {
  50814. include.pos = 'at '.concat(p1);
  50815. } else {
  50816. include.pos = 'from '.concat(p1, ' to ').concat(p2);
  50817. }
  50818. } else {
  50819. if (f === 'point') {
  50820. //make color stroke
  50821. include.color = this.ingredients.colors.stroke;
  50822. } else {
  50823. //make color fill
  50824. include.color = this.ingredients.colors.fill;
  50825. //get area of shape
  50826. include.area = _getArea(f, args, this.width, this.height);
  50827. }
  50828. //get middle of shapes
  50829. //calculate position using middle of shape
  50830. include.pos = _getPos(middle, this.width, this.height);
  50831. //calculate location using middle of shape
  50832. include.loc = _canvasLocator(middle, this.width, this.height);
  50833. }
  50834. //if it is the first time this shape is created
  50835. if (!this.ingredients.shapes[f]) {
  50836. this.ingredients.shapes[f] = [include];
  50837. //if other shapes of this type have been created
  50838. } else if (this.ingredients.shapes[f] !== [include]) {
  50839. //for every shape of this type
  50840. for (var y in this.ingredients.shapes[f]) {
  50841. //compare it with current shape and if it already exists make add false
  50842. if (
  50843. JSON.stringify(this.ingredients.shapes[f][y]) === JSON.stringify(include)
  50844. ) {
  50845. add = false;
  50846. }
  50847. }
  50848. //add shape by pushing it to the end
  50849. if (add === true) {
  50850. this.ingredients.shapes[f].push(include);
  50851. }
  50852. }
  50853. };
  50854. //gets middle point / centroid of shape
  50855. function _getMiddle(f, args) {
  50856. var x, y;
  50857. if (
  50858. f === 'rectangle' ||
  50859. f === 'ellipse' ||
  50860. f === 'arc' ||
  50861. f === 'circle' ||
  50862. f === 'square'
  50863. ) {
  50864. x = Math.round(args[0] + args[2] / 2);
  50865. y = Math.round(args[1] + args[3] / 2);
  50866. } else if (f === 'triangle') {
  50867. x = (args[0] + args[2] + args[4]) / 3;
  50868. y = (args[1] + args[3] + args[5]) / 3;
  50869. } else if (f === 'quadrilateral') {
  50870. x = (args[0] + args[2] + args[4] + args[6]) / 4;
  50871. y = (args[1] + args[3] + args[5] + args[7]) / 4;
  50872. } else if (f === 'line') {
  50873. x = (args[0] + args[2]) / 2;
  50874. y = (args[1] + args[3]) / 2;
  50875. } else {
  50876. x = args[0];
  50877. y = args[1];
  50878. }
  50879. return [x, y];
  50880. }
  50881. //gets position of shape in the canvas
  50882. function _getPos(args, canvasWidth, canvasHeight) {
  50883. if (args[0] < 0.4 * canvasWidth) {
  50884. if (args[1] < 0.4 * canvasHeight) {
  50885. return 'top left';
  50886. } else if (args[1] > 0.6 * canvasHeight) {
  50887. return 'bottom left';
  50888. } else {
  50889. return 'mid left';
  50890. }
  50891. } else if (args[0] > 0.6 * canvasWidth) {
  50892. if (args[1] < 0.4 * canvasHeight) {
  50893. return 'top right';
  50894. } else if (args[1] > 0.6 * canvasHeight) {
  50895. return 'bottom right';
  50896. } else {
  50897. return 'mid right';
  50898. }
  50899. } else {
  50900. if (args[1] < 0.4 * canvasHeight) {
  50901. return 'top middle';
  50902. } else if (args[1] > 0.6 * canvasHeight) {
  50903. return 'bottom middle';
  50904. } else {
  50905. return 'middle';
  50906. }
  50907. }
  50908. }
  50909. //locates shape in a 10*10 grid
  50910. function _canvasLocator(args, canvasWidth, canvasHeight) {
  50911. var noRows = 10;
  50912. var noCols = 10;
  50913. var locX = Math.floor(args[0] / canvasWidth * noRows);
  50914. var locY = Math.floor(args[1] / canvasHeight * noCols);
  50915. if (locX === noRows) {
  50916. locX = locX - 1;
  50917. }
  50918. if (locY === noCols) {
  50919. locY = locY - 1;
  50920. }
  50921. return {
  50922. locX: locX,
  50923. locY: locY
  50924. };
  50925. }
  50926. //calculates area of shape
  50927. function _getArea(objectType, shapeArgs, canvasWidth, canvasHeight) {
  50928. var objectArea = 0;
  50929. if (objectType === 'arc') {
  50930. // area of full ellipse = PI * horizontal radius * vertical radius.
  50931. // therefore, area of arc = difference bet. arc's start and end radians * horizontal radius * vertical radius.
  50932. // the below expression is adjusted for negative values and differences in arc's start and end radians over PI*2
  50933. var arcSizeInRadians =
  50934. ((shapeArgs[5] - shapeArgs[4]) % (Math.PI * 2) + Math.PI * 2) %
  50935. (Math.PI * 2);
  50936. objectArea = arcSizeInRadians * shapeArgs[2] * shapeArgs[3] / 8;
  50937. if (shapeArgs[6] === 'open' || shapeArgs[6] === 'chord') {
  50938. // when the arc's mode is OPEN or CHORD, we need to account for the area of the triangle that is formed to close the arc
  50939. // (Ax( By − Cy) + Bx(Cy − Ay) + Cx(Ay − By ) )/2
  50940. var Ax = shapeArgs[0];
  50941. var Ay = shapeArgs[1];
  50942. var Bx =
  50943. shapeArgs[0] + shapeArgs[2] / 2 * Math.cos(shapeArgs[4]).toFixed(2);
  50944. var By =
  50945. shapeArgs[1] + shapeArgs[3] / 2 * Math.sin(shapeArgs[4]).toFixed(2);
  50946. var Cx =
  50947. shapeArgs[0] + shapeArgs[2] / 2 * Math.cos(shapeArgs[5]).toFixed(2);
  50948. var Cy =
  50949. shapeArgs[1] + shapeArgs[3] / 2 * Math.sin(shapeArgs[5]).toFixed(2);
  50950. var areaOfExtraTriangle =
  50951. Math.abs(Ax * (By - Cy) + Bx * (Cy - Ay) + Cx * (Ay - By)) / 2;
  50952. if (arcSizeInRadians > Math.PI) {
  50953. objectArea = objectArea + areaOfExtraTriangle;
  50954. } else {
  50955. objectArea = objectArea - areaOfExtraTriangle;
  50956. }
  50957. }
  50958. } else if (objectType === 'ellipse' || objectType === 'circle') {
  50959. objectArea = 3.14 * shapeArgs[2] / 2 * shapeArgs[3] / 2;
  50960. } else if (objectType === 'line') {
  50961. objectArea = 0;
  50962. } else if (objectType === 'point') {
  50963. objectArea = 0;
  50964. } else if (objectType === 'quadrilateral') {
  50965. // ((x4+x1)*(y4-y1)+(x1+x2)*(y1-y2)+(x2+x3)*(y2-y3)+(x3+x4)*(y3-y4))/2
  50966. objectArea =
  50967. Math.abs(
  50968. (shapeArgs[6] + shapeArgs[0]) * (shapeArgs[7] - shapeArgs[1]) +
  50969. (shapeArgs[0] + shapeArgs[2]) * (shapeArgs[1] - shapeArgs[3]) +
  50970. (shapeArgs[2] + shapeArgs[4]) * (shapeArgs[3] - shapeArgs[5]) +
  50971. (shapeArgs[4] + shapeArgs[6]) * (shapeArgs[5] - shapeArgs[7])
  50972. ) / 2;
  50973. } else if (objectType === 'rectangle' || objectType === 'square') {
  50974. objectArea = shapeArgs[2] * shapeArgs[3];
  50975. } else if (objectType === 'triangle') {
  50976. objectArea =
  50977. Math.abs(
  50978. shapeArgs[0] * (shapeArgs[3] - shapeArgs[5]) +
  50979. shapeArgs[2] * (shapeArgs[5] - shapeArgs[1]) +
  50980. shapeArgs[4] * (shapeArgs[1] - shapeArgs[3])
  50981. ) / 2;
  50982. // (Ax( By − Cy) + Bx(Cy − Ay) + Cx(Ay − By ))/2
  50983. }
  50984. return Math.round(objectArea * 100 / (canvasWidth * canvasHeight));
  50985. }
  50986. var _default = _main.default;
  50987. exports.default = _default;
  50988. },
  50989. {
  50990. '../core/main': 283,
  50991. 'core-js/modules/es.array.concat': 166,
  50992. 'core-js/modules/es.array.fill': 168,
  50993. 'core-js/modules/es.array.map': 177,
  50994. 'core-js/modules/es.number.to-fixed': 187
  50995. }
  50996. ],
  50997. 266: [
  50998. function(_dereq_, module, exports) {
  50999. 'use strict';
  51000. _dereq_('core-js/modules/es.array.concat');
  51001. Object.defineProperty(exports, '__esModule', { value: true });
  51002. exports.default = void 0;
  51003. var _main = _interopRequireDefault(_dereq_('../core/main'));
  51004. function _interopRequireDefault(obj) {
  51005. return obj && obj.__esModule ? obj : { default: obj };
  51006. } /** //the functions in this file support updating the text output
  51007. * @module Environment
  51008. * @submodule Environment
  51009. * @for p5
  51010. * @requires core
  51011. */
  51012. //updates textOutput
  51013. _main.default.prototype._updateTextOutput = function(idT) {
  51014. //if html structure is not there yet
  51015. if (!this.dummyDOM.querySelector('#'.concat(idT, '_summary'))) {
  51016. return;
  51017. }
  51018. var current = this._accessibleOutputs[idT];
  51019. //create shape list
  51020. var innerList = _shapeList(idT, this.ingredients.shapes);
  51021. //create output summary
  51022. var innerSummary = _textSummary(
  51023. innerList.numShapes,
  51024. this.ingredients.colors.background,
  51025. this.width,
  51026. this.height
  51027. );
  51028. //create shape details
  51029. var innerShapeDetails = _shapeDetails(idT, this.ingredients.shapes);
  51030. //if it is different from current summary
  51031. if (innerSummary !== current.summary.innerHTML) {
  51032. //update
  51033. current.summary.innerHTML = innerSummary;
  51034. }
  51035. //if it is different from current shape list
  51036. if (innerList.listShapes !== current.list.innerHTML) {
  51037. //update
  51038. current.list.innerHTML = innerList.listShapes;
  51039. }
  51040. //if it is different from current shape details
  51041. if (innerShapeDetails !== current.shapeDetails.innerHTML) {
  51042. //update
  51043. current.shapeDetails.innerHTML = innerShapeDetails;
  51044. }
  51045. this._accessibleOutputs[idT] = current;
  51046. };
  51047. //Builds textOutput summary
  51048. function _textSummary(numShapes, background, width, height) {
  51049. var text = 'Your output is a, '
  51050. .concat(width, ' by ')
  51051. .concat(height, ' pixels, ')
  51052. .concat(background, ' canvas containing the following');
  51053. if (numShapes === 1) {
  51054. text = ''.concat(text, ' shape:');
  51055. } else {
  51056. text = ''.concat(text, ' ').concat(numShapes, ' shapes:');
  51057. }
  51058. return text;
  51059. }
  51060. //Builds textOutput table with shape details
  51061. function _shapeDetails(idT, ingredients) {
  51062. var shapeDetails = '';
  51063. var shapeNumber = 0;
  51064. //goes trhough every shape type in ingredients
  51065. for (var x in ingredients) {
  51066. //and for every shape
  51067. for (var y in ingredients[x]) {
  51068. //it creates a table row
  51069. var row = '<tr id="'
  51070. .concat(idT, 'shape')
  51071. .concat(shapeNumber, '"><th>')
  51072. .concat(ingredients[x][y].color, ' ')
  51073. .concat(x, '</th>');
  51074. if (x === 'line') {
  51075. row =
  51076. row +
  51077. '<td>location = '
  51078. .concat(ingredients[x][y].pos, '</td><td>length = ')
  51079. .concat(ingredients[x][y].length, ' pixels</td></tr>');
  51080. } else {
  51081. row = row + '<td>location = '.concat(ingredients[x][y].pos, '</td>');
  51082. if (x !== 'point') {
  51083. row = row + '<td> area = '.concat(ingredients[x][y].area, '%</td>');
  51084. }
  51085. row = row + '</tr>';
  51086. }
  51087. shapeDetails = shapeDetails + row;
  51088. shapeNumber++;
  51089. }
  51090. }
  51091. return shapeDetails;
  51092. }
  51093. //Builds textOutput shape list
  51094. function _shapeList(idT, ingredients) {
  51095. var shapeList = '';
  51096. var shapeNumber = 0;
  51097. //goes trhough every shape type in ingredients
  51098. for (var x in ingredients) {
  51099. for (var y in ingredients[x]) {
  51100. //it creates a line in a list
  51101. var _line = '<li><a href="#'
  51102. .concat(idT, 'shape')
  51103. .concat(shapeNumber, '">')
  51104. .concat(ingredients[x][y].color, ' ')
  51105. .concat(x, '</a>');
  51106. if (x === 'line') {
  51107. _line =
  51108. _line +
  51109. ', '
  51110. .concat(ingredients[x][y].pos, ', ')
  51111. .concat(ingredients[x][y].length, ' pixels long.</li>');
  51112. } else {
  51113. _line = _line + ', at '.concat(ingredients[x][y].pos);
  51114. if (x !== 'point') {
  51115. _line =
  51116. _line +
  51117. ', covering '.concat(ingredients[x][y].area, '% of the canvas');
  51118. }
  51119. _line = _line + '.</li>';
  51120. }
  51121. shapeList = shapeList + _line;
  51122. shapeNumber++;
  51123. }
  51124. }
  51125. return { numShapes: shapeNumber, listShapes: shapeList };
  51126. }
  51127. var _default = _main.default;
  51128. exports.default = _default;
  51129. },
  51130. { '../core/main': 283, 'core-js/modules/es.array.concat': 166 }
  51131. ],
  51132. 267: [
  51133. function(_dereq_, module, exports) {
  51134. 'use strict';
  51135. var _main = _interopRequireDefault(_dereq_('./core/main'));
  51136. _dereq_('./core/constants');
  51137. _dereq_('./core/environment');
  51138. _dereq_('./core/friendly_errors/stacktrace');
  51139. _dereq_('./core/friendly_errors/validate_params');
  51140. _dereq_('./core/friendly_errors/file_errors');
  51141. _dereq_('./core/friendly_errors/fes_core');
  51142. _dereq_('./core/helpers');
  51143. _dereq_('./core/legacy');
  51144. _dereq_('./core/preload');
  51145. _dereq_('./core/p5.Element');
  51146. _dereq_('./core/p5.Graphics');
  51147. _dereq_('./core/p5.Renderer');
  51148. _dereq_('./core/p5.Renderer2D');
  51149. _dereq_('./core/rendering');
  51150. _dereq_('./core/shim');
  51151. _dereq_('./core/structure');
  51152. _dereq_('./core/transform');
  51153. _dereq_('./core/shape/2d_primitives');
  51154. _dereq_('./core/shape/attributes');
  51155. _dereq_('./core/shape/curves');
  51156. _dereq_('./core/shape/vertex');
  51157. _dereq_('./accessibility/outputs');
  51158. _dereq_('./accessibility/textOutput');
  51159. _dereq_('./accessibility/gridOutput');
  51160. _dereq_('./accessibility/color_namer');
  51161. _dereq_('./color/color_conversion');
  51162. _dereq_('./color/creating_reading');
  51163. _dereq_('./color/p5.Color');
  51164. _dereq_('./color/setting');
  51165. _dereq_('./data/p5.TypedDict');
  51166. _dereq_('./data/local_storage.js');
  51167. _dereq_('./dom/dom');
  51168. _dereq_('./accessibility/describe');
  51169. _dereq_('./events/acceleration');
  51170. _dereq_('./events/keyboard');
  51171. _dereq_('./events/mouse');
  51172. _dereq_('./events/touch');
  51173. _dereq_('./image/filters');
  51174. _dereq_('./image/image');
  51175. _dereq_('./image/loading_displaying');
  51176. _dereq_('./image/p5.Image');
  51177. _dereq_('./image/pixels');
  51178. _dereq_('./io/files');
  51179. _dereq_('./io/p5.Table');
  51180. _dereq_('./io/p5.TableRow');
  51181. _dereq_('./io/p5.XML');
  51182. _dereq_('./math/calculation');
  51183. _dereq_('./math/math');
  51184. _dereq_('./math/noise');
  51185. _dereq_('./math/p5.Vector');
  51186. _dereq_('./math/random');
  51187. _dereq_('./math/trigonometry');
  51188. _dereq_('./typography/attributes');
  51189. _dereq_('./typography/loading_displaying');
  51190. _dereq_('./typography/p5.Font');
  51191. _dereq_('./utilities/array_functions');
  51192. _dereq_('./utilities/conversion');
  51193. _dereq_('./utilities/string_functions');
  51194. _dereq_('./utilities/time_date');
  51195. _dereq_('./webgl/3d_primitives');
  51196. _dereq_('./webgl/interaction');
  51197. _dereq_('./webgl/light');
  51198. _dereq_('./webgl/loading');
  51199. _dereq_('./webgl/material');
  51200. _dereq_('./webgl/p5.Camera');
  51201. _dereq_('./webgl/p5.Geometry');
  51202. _dereq_('./webgl/p5.Matrix');
  51203. _dereq_('./webgl/p5.RendererGL.Immediate');
  51204. _dereq_('./webgl/p5.RendererGL');
  51205. _dereq_('./webgl/p5.RendererGL.Retained');
  51206. _dereq_('./webgl/p5.Shader');
  51207. _dereq_('./webgl/p5.RenderBuffer');
  51208. _dereq_('./webgl/p5.Texture');
  51209. _dereq_('./webgl/text');
  51210. _dereq_('./core/init');
  51211. function _interopRequireDefault(obj) {
  51212. return obj && obj.__esModule ? obj : { default: obj };
  51213. } // core
  51214. //accessibility
  51215. // color
  51216. // data
  51217. // DOM
  51218. // accessibility
  51219. // events
  51220. // image
  51221. // io
  51222. // math
  51223. // typography
  51224. // utilities
  51225. // webgl
  51226. module.exports = _main.default;
  51227. },
  51228. {
  51229. './accessibility/color_namer': 262,
  51230. './accessibility/describe': 263,
  51231. './accessibility/gridOutput': 264,
  51232. './accessibility/outputs': 265,
  51233. './accessibility/textOutput': 266,
  51234. './color/color_conversion': 268,
  51235. './color/creating_reading': 269,
  51236. './color/p5.Color': 270,
  51237. './color/setting': 271,
  51238. './core/constants': 272,
  51239. './core/environment': 273,
  51240. './core/friendly_errors/fes_core': 275,
  51241. './core/friendly_errors/file_errors': 276,
  51242. './core/friendly_errors/stacktrace': 277,
  51243. './core/friendly_errors/validate_params': 278,
  51244. './core/helpers': 279,
  51245. './core/init': 280,
  51246. './core/legacy': 282,
  51247. './core/main': 283,
  51248. './core/p5.Element': 284,
  51249. './core/p5.Graphics': 285,
  51250. './core/p5.Renderer': 286,
  51251. './core/p5.Renderer2D': 287,
  51252. './core/preload': 288,
  51253. './core/rendering': 289,
  51254. './core/shape/2d_primitives': 290,
  51255. './core/shape/attributes': 291,
  51256. './core/shape/curves': 292,
  51257. './core/shape/vertex': 293,
  51258. './core/shim': 294,
  51259. './core/structure': 295,
  51260. './core/transform': 296,
  51261. './data/local_storage.js': 297,
  51262. './data/p5.TypedDict': 298,
  51263. './dom/dom': 299,
  51264. './events/acceleration': 300,
  51265. './events/keyboard': 301,
  51266. './events/mouse': 302,
  51267. './events/touch': 303,
  51268. './image/filters': 304,
  51269. './image/image': 305,
  51270. './image/loading_displaying': 306,
  51271. './image/p5.Image': 307,
  51272. './image/pixels': 308,
  51273. './io/files': 309,
  51274. './io/p5.Table': 310,
  51275. './io/p5.TableRow': 311,
  51276. './io/p5.XML': 312,
  51277. './math/calculation': 313,
  51278. './math/math': 314,
  51279. './math/noise': 315,
  51280. './math/p5.Vector': 316,
  51281. './math/random': 317,
  51282. './math/trigonometry': 318,
  51283. './typography/attributes': 319,
  51284. './typography/loading_displaying': 320,
  51285. './typography/p5.Font': 321,
  51286. './utilities/array_functions': 322,
  51287. './utilities/conversion': 323,
  51288. './utilities/string_functions': 324,
  51289. './utilities/time_date': 325,
  51290. './webgl/3d_primitives': 326,
  51291. './webgl/interaction': 327,
  51292. './webgl/light': 328,
  51293. './webgl/loading': 329,
  51294. './webgl/material': 330,
  51295. './webgl/p5.Camera': 331,
  51296. './webgl/p5.Geometry': 332,
  51297. './webgl/p5.Matrix': 333,
  51298. './webgl/p5.RenderBuffer': 334,
  51299. './webgl/p5.RendererGL': 337,
  51300. './webgl/p5.RendererGL.Immediate': 335,
  51301. './webgl/p5.RendererGL.Retained': 336,
  51302. './webgl/p5.Shader': 338,
  51303. './webgl/p5.Texture': 339,
  51304. './webgl/text': 340
  51305. }
  51306. ],
  51307. 268: [
  51308. function(_dereq_, module, exports) {
  51309. 'use strict';
  51310. Object.defineProperty(exports, '__esModule', { value: true });
  51311. exports.default = void 0;
  51312. var _main = _interopRequireDefault(_dereq_('../core/main'));
  51313. function _interopRequireDefault(obj) {
  51314. return obj && obj.__esModule ? obj : { default: obj };
  51315. }
  51316. /**
  51317. * @module Color
  51318. * @submodule Color Conversion
  51319. * @for p5
  51320. * @requires core
  51321. */ /**
  51322. * Conversions adapted from <http://www.easyrgb.com/en/math.php>.
  51323. *
  51324. * In these functions, hue is always in the range [0, 1], just like all other
  51325. * components are in the range [0, 1]. 'Brightness' and 'value' are used
  51326. * interchangeably.
  51327. */ _main.default.ColorConversion = {};
  51328. /**
  51329. * Convert an HSBA array to HSLA.
  51330. */ _main.default.ColorConversion._hsbaToHSLA = function(hsba) {
  51331. var hue = hsba[0];
  51332. var sat = hsba[1];
  51333. var val = hsba[2]; // Calculate lightness.
  51334. var li = (2 - sat) * val / 2; // Convert saturation.
  51335. if (li !== 0) {
  51336. if (li === 1) {
  51337. sat = 0;
  51338. } else if (li < 0.5) {
  51339. sat = sat / (2 - sat);
  51340. } else {
  51341. sat = sat * val / (2 - li * 2);
  51342. }
  51343. }
  51344. // Hue and alpha stay the same.
  51345. return [hue, sat, li, hsba[3]];
  51346. };
  51347. /**
  51348. * Convert an HSBA array to RGBA.
  51349. */
  51350. _main.default.ColorConversion._hsbaToRGBA = function(hsba) {
  51351. var hue = hsba[0] * 6; // We will split hue into 6 sectors.
  51352. var sat = hsba[1];
  51353. var val = hsba[2];
  51354. var RGBA = [];
  51355. if (sat === 0) {
  51356. RGBA = [val, val, val, hsba[3]]; // Return early if grayscale.
  51357. } else {
  51358. var sector = Math.floor(hue);
  51359. var tint1 = val * (1 - sat);
  51360. var tint2 = val * (1 - sat * (hue - sector));
  51361. var tint3 = val * (1 - sat * (1 + sector - hue));
  51362. var red, green, blue;
  51363. if (sector === 1) {
  51364. // Yellow to green.
  51365. red = tint2;
  51366. green = val;
  51367. blue = tint1;
  51368. } else if (sector === 2) {
  51369. // Green to cyan.
  51370. red = tint1;
  51371. green = val;
  51372. blue = tint3;
  51373. } else if (sector === 3) {
  51374. // Cyan to blue.
  51375. red = tint1;
  51376. green = tint2;
  51377. blue = val;
  51378. } else if (sector === 4) {
  51379. // Blue to magenta.
  51380. red = tint3;
  51381. green = tint1;
  51382. blue = val;
  51383. } else if (sector === 5) {
  51384. // Magenta to red.
  51385. red = val;
  51386. green = tint1;
  51387. blue = tint2;
  51388. } else {
  51389. // Red to yellow (sector could be 0 or 6).
  51390. red = val;
  51391. green = tint3;
  51392. blue = tint1;
  51393. }
  51394. RGBA = [red, green, blue, hsba[3]];
  51395. }
  51396. return RGBA;
  51397. };
  51398. /**
  51399. * Convert an HSLA array to HSBA.
  51400. */
  51401. _main.default.ColorConversion._hslaToHSBA = function(hsla) {
  51402. var hue = hsla[0];
  51403. var sat = hsla[1];
  51404. var li = hsla[2];
  51405. // Calculate brightness.
  51406. var val;
  51407. if (li < 0.5) {
  51408. val = (1 + sat) * li;
  51409. } else {
  51410. val = li + sat - li * sat;
  51411. }
  51412. // Convert saturation.
  51413. sat = 2 * (val - li) / val;
  51414. // Hue and alpha stay the same.
  51415. return [hue, sat, val, hsla[3]];
  51416. };
  51417. /**
  51418. * Convert an HSLA array to RGBA.
  51419. *
  51420. * We need to change basis from HSLA to something that can be more easily be
  51421. * projected onto RGBA. We will choose hue and brightness as our first two
  51422. * components, and pick a convenient third one ('zest') so that we don't need
  51423. * to calculate formal HSBA saturation.
  51424. */
  51425. _main.default.ColorConversion._hslaToRGBA = function(hsla) {
  51426. var hue = hsla[0] * 6; // We will split hue into 6 sectors.
  51427. var sat = hsla[1];
  51428. var li = hsla[2];
  51429. var RGBA = [];
  51430. if (sat === 0) {
  51431. RGBA = [li, li, li, hsla[3]]; // Return early if grayscale.
  51432. } else {
  51433. // Calculate brightness.
  51434. var val;
  51435. if (li < 0.5) {
  51436. val = (1 + sat) * li;
  51437. } else {
  51438. val = li + sat - li * sat;
  51439. }
  51440. // Define zest.
  51441. var zest = 2 * li - val;
  51442. // Implement projection (project onto green by default).
  51443. var hzvToRGB = function hzvToRGB(hue, zest, val) {
  51444. if (hue < 0) {
  51445. // Hue must wrap to allow projection onto red and blue.
  51446. hue += 6;
  51447. } else if (hue >= 6) {
  51448. hue -= 6;
  51449. }
  51450. if (hue < 1) {
  51451. // Red to yellow (increasing green).
  51452. return zest + (val - zest) * hue;
  51453. } else if (hue < 3) {
  51454. // Yellow to cyan (greatest green).
  51455. return val;
  51456. } else if (hue < 4) {
  51457. // Cyan to blue (decreasing green).
  51458. return zest + (val - zest) * (4 - hue);
  51459. } else {
  51460. // Blue to red (least green).
  51461. return zest;
  51462. }
  51463. };
  51464. // Perform projections, offsetting hue as necessary.
  51465. RGBA = [
  51466. hzvToRGB(hue + 2, zest, val),
  51467. hzvToRGB(hue, zest, val),
  51468. hzvToRGB(hue - 2, zest, val),
  51469. hsla[3]
  51470. ];
  51471. }
  51472. return RGBA;
  51473. };
  51474. /**
  51475. * Convert an RGBA array to HSBA.
  51476. */
  51477. _main.default.ColorConversion._rgbaToHSBA = function(rgba) {
  51478. var red = rgba[0];
  51479. var green = rgba[1];
  51480. var blue = rgba[2];
  51481. var val = Math.max(red, green, blue);
  51482. var chroma = val - Math.min(red, green, blue);
  51483. var hue, sat;
  51484. if (chroma === 0) {
  51485. // Return early if grayscale.
  51486. hue = 0;
  51487. sat = 0;
  51488. } else {
  51489. sat = chroma / val;
  51490. if (red === val) {
  51491. // Magenta to yellow.
  51492. hue = (green - blue) / chroma;
  51493. } else if (green === val) {
  51494. // Yellow to cyan.
  51495. hue = 2 + (blue - red) / chroma;
  51496. } else if (blue === val) {
  51497. // Cyan to magenta.
  51498. hue = 4 + (red - green) / chroma;
  51499. }
  51500. if (hue < 0) {
  51501. // Confine hue to the interval [0, 1).
  51502. hue += 6;
  51503. } else if (hue >= 6) {
  51504. hue -= 6;
  51505. }
  51506. }
  51507. return [hue / 6, sat, val, rgba[3]];
  51508. };
  51509. /**
  51510. * Convert an RGBA array to HSLA.
  51511. */
  51512. _main.default.ColorConversion._rgbaToHSLA = function(rgba) {
  51513. var red = rgba[0];
  51514. var green = rgba[1];
  51515. var blue = rgba[2];
  51516. var val = Math.max(red, green, blue);
  51517. var min = Math.min(red, green, blue);
  51518. var li = val + min; // We will halve this later.
  51519. var chroma = val - min;
  51520. var hue, sat;
  51521. if (chroma === 0) {
  51522. // Return early if grayscale.
  51523. hue = 0;
  51524. sat = 0;
  51525. } else {
  51526. if (li < 1) {
  51527. sat = chroma / li;
  51528. } else {
  51529. sat = chroma / (2 - li);
  51530. }
  51531. if (red === val) {
  51532. // Magenta to yellow.
  51533. hue = (green - blue) / chroma;
  51534. } else if (green === val) {
  51535. // Yellow to cyan.
  51536. hue = 2 + (blue - red) / chroma;
  51537. } else if (blue === val) {
  51538. // Cyan to magenta.
  51539. hue = 4 + (red - green) / chroma;
  51540. }
  51541. if (hue < 0) {
  51542. // Confine hue to the interval [0, 1).
  51543. hue += 6;
  51544. } else if (hue >= 6) {
  51545. hue -= 6;
  51546. }
  51547. }
  51548. return [hue / 6, sat, li / 2, rgba[3]];
  51549. };
  51550. var _default = _main.default.ColorConversion;
  51551. exports.default = _default;
  51552. },
  51553. { '../core/main': 283 }
  51554. ],
  51555. 269: [
  51556. function(_dereq_, module, exports) {
  51557. 'use strict';
  51558. function _typeof(obj) {
  51559. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  51560. _typeof = function _typeof(obj) {
  51561. return typeof obj;
  51562. };
  51563. } else {
  51564. _typeof = function _typeof(obj) {
  51565. return obj &&
  51566. typeof Symbol === 'function' &&
  51567. obj.constructor === Symbol &&
  51568. obj !== Symbol.prototype
  51569. ? 'symbol'
  51570. : typeof obj;
  51571. };
  51572. }
  51573. return _typeof(obj);
  51574. }
  51575. _dereq_('core-js/modules/es.array.map');
  51576. Object.defineProperty(exports, '__esModule', { value: true });
  51577. exports.default = void 0;
  51578. var _main = _interopRequireDefault(_dereq_('../core/main'));
  51579. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  51580. _dereq_('./p5.Color');
  51581. _dereq_('../core/friendly_errors/validate_params');
  51582. _dereq_('../core/friendly_errors/file_errors');
  51583. _dereq_('../core/friendly_errors/fes_core');
  51584. function _getRequireWildcardCache() {
  51585. if (typeof WeakMap !== 'function') return null;
  51586. var cache = new WeakMap();
  51587. _getRequireWildcardCache = function _getRequireWildcardCache() {
  51588. return cache;
  51589. };
  51590. return cache;
  51591. }
  51592. function _interopRequireWildcard(obj) {
  51593. if (obj && obj.__esModule) {
  51594. return obj;
  51595. }
  51596. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  51597. return { default: obj };
  51598. }
  51599. var cache = _getRequireWildcardCache();
  51600. if (cache && cache.has(obj)) {
  51601. return cache.get(obj);
  51602. }
  51603. var newObj = {};
  51604. var hasPropertyDescriptor =
  51605. Object.defineProperty && Object.getOwnPropertyDescriptor;
  51606. for (var key in obj) {
  51607. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  51608. var desc = hasPropertyDescriptor
  51609. ? Object.getOwnPropertyDescriptor(obj, key)
  51610. : null;
  51611. if (desc && (desc.get || desc.set)) {
  51612. Object.defineProperty(newObj, key, desc);
  51613. } else {
  51614. newObj[key] = obj[key];
  51615. }
  51616. }
  51617. }
  51618. newObj.default = obj;
  51619. if (cache) {
  51620. cache.set(obj, newObj);
  51621. }
  51622. return newObj;
  51623. }
  51624. function _interopRequireDefault(obj) {
  51625. return obj && obj.__esModule ? obj : { default: obj };
  51626. }
  51627. /**
  51628. * @module Color
  51629. * @submodule Creating & Reading
  51630. * @for p5
  51631. * @requires core
  51632. * @requires constants
  51633. */ /**
  51634. * Extracts the alpha value from a color or pixel array.
  51635. *
  51636. * @method alpha
  51637. * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components,
  51638. * or CSS color
  51639. * @return {Number} the alpha value
  51640. *
  51641. * @example
  51642. * <div>
  51643. * <code>
  51644. * noStroke();
  51645. * let c = color(0, 126, 255, 102);
  51646. * fill(c);
  51647. * rect(15, 15, 35, 70);
  51648. * let value = alpha(c); // Sets 'value' to 102
  51649. * fill(value);
  51650. * rect(50, 15, 35, 70);
  51651. * </code>
  51652. * </div>
  51653. *
  51654. * @alt
  51655. * Left half of canvas light blue and right half light charcoal grey.
  51656. */ _main.default.prototype.alpha = function(c) {
  51657. _main.default._validateParameters('alpha', arguments);
  51658. return this.color(c)._getAlpha();
  51659. };
  51660. /**
  51661. * Extracts the blue value from a color or pixel array.
  51662. *
  51663. * @method blue
  51664. * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components,
  51665. * or CSS color
  51666. * @return {Number} the blue value
  51667. * @example
  51668. * <div>
  51669. * <code>
  51670. * let c = color(175, 100, 220);
  51671. * fill(c);
  51672. * rect(15, 20, 35, 60); // Draw left rectangle
  51673. * let blueValue = blue(c);
  51674. * fill(0, 0, blueValue);
  51675. * rect(50, 20, 35, 60); // Draw right rectangle
  51676. * </code>
  51677. * </div>
  51678. *
  51679. * @alt
  51680. * Left half of canvas light purple and right half a royal blue.
  51681. */
  51682. _main.default.prototype.blue = function(c) {
  51683. _main.default._validateParameters('blue', arguments);
  51684. return this.color(c)._getBlue();
  51685. };
  51686. /**
  51687. * Extracts the HSB brightness value from a color or pixel array.
  51688. *
  51689. * @method brightness
  51690. * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components,
  51691. * or CSS color
  51692. * @return {Number} the brightness value
  51693. *
  51694. * @example
  51695. * <div>
  51696. * <code>
  51697. * noStroke();
  51698. * colorMode(HSB, 255);
  51699. * let c = color(0, 126, 255);
  51700. * fill(c);
  51701. * rect(15, 20, 35, 60);
  51702. * let value = brightness(c); // Sets 'value' to 255
  51703. * fill(value);
  51704. * rect(50, 20, 35, 60);
  51705. * </code>
  51706. * </div>
  51707. *
  51708. * <div>
  51709. * <code>
  51710. * noStroke();
  51711. * colorMode(HSB, 255);
  51712. * let c = color('hsb(60, 100%, 50%)');
  51713. * fill(c);
  51714. * rect(15, 20, 35, 60);
  51715. * let value = brightness(c); // A 'value' of 50% is 127.5
  51716. * fill(value);
  51717. * rect(50, 20, 35, 60);
  51718. * </code>
  51719. * </div>
  51720. *
  51721. * @alt
  51722. * Left half of canvas salmon pink and the right half with it's brightness colored white.
  51723. * Left half of canvas olive colored and the right half with it's brightness color gray.
  51724. */
  51725. _main.default.prototype.brightness = function(c) {
  51726. _main.default._validateParameters('brightness', arguments);
  51727. return this.color(c)._getBrightness();
  51728. };
  51729. /**
  51730. * Creates colors for storing in variables of the color datatype. The
  51731. * parameters are interpreted as RGB or HSB values depending on the
  51732. * current <a href="#/p5/colorMode">colorMode()</a>. The default mode is RGB values from 0 to 255
  51733. * and, therefore, the function call color(255, 204, 0) will return a
  51734. * bright yellow color.
  51735. *
  51736. * Note that if only one value is provided to <a href="#/p5/color">color()</a>, it will be interpreted
  51737. * as a grayscale value. Add a second value, and it will be used for alpha
  51738. * transparency. When three values are specified, they are interpreted as
  51739. * either RGB or HSB values. Adding a fourth value applies alpha
  51740. * transparency.
  51741. *
  51742. * If a single string argument is provided, RGB, RGBA and Hex CSS color
  51743. * strings and all named color strings are supported. In this case, an alpha
  51744. * number value as a second argument is not supported, the RGBA form should be
  51745. * used.
  51746. *
  51747. * @method color
  51748. * @param {Number} gray number specifying value between white and black.
  51749. * @param {Number} [alpha] alpha value relative to current color range
  51750. * (default is 0-255)
  51751. * @return {p5.Color} resulting color
  51752. *
  51753. * @example
  51754. * <div>
  51755. * <code>
  51756. * let c = color(255, 204, 0);
  51757. * fill(c);
  51758. * noStroke();
  51759. * rect(30, 20, 55, 55);
  51760. * </code>
  51761. * </div>
  51762. *
  51763. * <div>
  51764. * <code>
  51765. * let c = color(255, 204, 0);
  51766. * fill(c);
  51767. * noStroke();
  51768. * ellipse(25, 25, 80, 80); // Draw left circle
  51769. * // Using only one value generates a grayscale value.
  51770. * c = color(65);
  51771. * fill(c);
  51772. * ellipse(75, 75, 80, 80);
  51773. * </code>
  51774. * </div>
  51775. *
  51776. * <div>
  51777. * <code>
  51778. * // You can use named SVG & CSS colors
  51779. * let c = color('magenta');
  51780. * fill(c);
  51781. * noStroke();
  51782. * rect(20, 20, 60, 60);
  51783. * </code>
  51784. * </div>
  51785. *
  51786. * <div>
  51787. * <code>
  51788. * // Example of hex color codes
  51789. * noStroke();
  51790. * let c = color('#0f0');
  51791. * fill(c);
  51792. * rect(0, 10, 45, 80);
  51793. * c = color('#00ff00');
  51794. * fill(c);
  51795. * rect(55, 10, 45, 80);
  51796. * </code>
  51797. * </div>
  51798. *
  51799. * <div>
  51800. * <code>
  51801. * // RGB and RGBA color strings are also supported
  51802. * // these all set to the same color (solid blue)
  51803. * let c;
  51804. * noStroke();
  51805. * c = color('rgb(0,0,255)');
  51806. * fill(c);
  51807. * rect(10, 10, 35, 35); // Draw rectangle
  51808. * c = color('rgb(0%, 0%, 100%)');
  51809. * fill(c);
  51810. * rect(55, 10, 35, 35); // Draw rectangle
  51811. * c = color('rgba(0, 0, 255, 1)');
  51812. * fill(c);
  51813. * rect(10, 55, 35, 35); // Draw rectangle
  51814. * c = color('rgba(0%, 0%, 100%, 1)');
  51815. * fill(c);
  51816. * rect(55, 55, 35, 35); // Draw rectangle
  51817. * </code>
  51818. * </div>
  51819. *
  51820. * <div>
  51821. * <code>
  51822. * // HSL color can also be specified by value
  51823. * let c = color('hsl(160, 100%, 50%)');
  51824. * noStroke();
  51825. * fill(c);
  51826. * rect(0, 10, 45, 80); // Draw rectangle
  51827. * c = color('hsla(160, 100%, 50%, 0.5)');
  51828. * fill(c);
  51829. * rect(55, 10, 45, 80); // Draw rectangle
  51830. * </code>
  51831. * </div>
  51832. *
  51833. * <div>
  51834. * <code>
  51835. * // HSB color can also be specified
  51836. * let c = color('hsb(160, 100%, 50%)');
  51837. * noStroke();
  51838. * fill(c);
  51839. * rect(0, 10, 45, 80); // Draw rectangle
  51840. * c = color('hsba(160, 100%, 50%, 0.5)');
  51841. * fill(c);
  51842. * rect(55, 10, 45, 80); // Draw rectangle
  51843. * </code>
  51844. * </div>
  51845. *
  51846. * <div>
  51847. * <code>
  51848. * noStroke();
  51849. * let c = color(50, 55, 100);
  51850. * fill(c);
  51851. * rect(0, 10, 45, 80); // Draw left rect
  51852. * colorMode(HSB, 100);
  51853. * c = color(50, 55, 100);
  51854. * fill(c);
  51855. * rect(55, 10, 45, 80);
  51856. * </code>
  51857. * </div>
  51858. *
  51859. * @alt
  51860. * Yellow rect in middle right of canvas, with 55 pixel width and height.
  51861. * Yellow ellipse in top left of canvas, black ellipse in bottom right,both 80x80.
  51862. * Bright fuchsia rect in middle of canvas, 60 pixel width and height.
  51863. * Two bright green rects on opposite sides of the canvas, both 45x80.
  51864. * Four blue rects in each corner of the canvas, each are 35x35.
  51865. * Bright sea green rect on left and darker rect on right of canvas, both 45x80.
  51866. * Dark green rect on left and lighter green rect on right of canvas, both 45x80.
  51867. * Dark blue rect on left and light teal rect on right of canvas, both 45x80.
  51868. */
  51869. /**
  51870. * @method color
  51871. * @param {Number} v1 red or hue value relative to
  51872. * the current color range
  51873. * @param {Number} v2 green or saturation value
  51874. * relative to the current color range
  51875. * @param {Number} v3 blue or brightness value
  51876. * relative to the current color range
  51877. * @param {Number} [alpha]
  51878. * @return {p5.Color}
  51879. */
  51880. /**
  51881. * @method color
  51882. * @param {String} value a color string
  51883. * @return {p5.Color}
  51884. */
  51885. /**
  51886. * @method color
  51887. * @param {Number[]} values an array containing the red,green,blue &
  51888. * and alpha components of the color
  51889. * @return {p5.Color}
  51890. */
  51891. /**
  51892. * @method color
  51893. * @param {p5.Color} color
  51894. * @return {p5.Color}
  51895. */
  51896. _main.default.prototype.color = function() {
  51897. _main.default._validateParameters('color', arguments);
  51898. if (arguments[0] instanceof _main.default.Color) {
  51899. return arguments[0]; // Do nothing if argument is already a color object.
  51900. }
  51901. var args = arguments[0] instanceof Array ? arguments[0] : arguments;
  51902. return new _main.default.Color(this, args);
  51903. };
  51904. /**
  51905. * Extracts the green value from a color or pixel array.
  51906. *
  51907. * @method green
  51908. * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components,
  51909. * or CSS color
  51910. * @return {Number} the green value
  51911. * @example
  51912. * <div>
  51913. * <code>
  51914. * let c = color(20, 75, 200); // Define color 'c'
  51915. * fill(c); // Use color variable 'c' as fill color
  51916. * rect(15, 20, 35, 60); // Draw left rectangle
  51917. *
  51918. * let greenValue = green(c); // Get green in 'c'
  51919. * print(greenValue); // Print "75.0"
  51920. * fill(0, greenValue, 0); // Use 'greenValue' in new fill
  51921. * rect(50, 20, 35, 60); // Draw right rectangle
  51922. * </code>
  51923. * </div>
  51924. *
  51925. * @alt
  51926. * blue rect on left and green on right, both with black outlines & 35x60.
  51927. */
  51928. _main.default.prototype.green = function(c) {
  51929. _main.default._validateParameters('green', arguments);
  51930. return this.color(c)._getGreen();
  51931. };
  51932. /**
  51933. * Extracts the hue value from a color or pixel array.
  51934. *
  51935. * Hue exists in both HSB and HSL. This function will return the
  51936. * HSB-normalized hue when supplied with an HSB color object (or when supplied
  51937. * with a pixel array while the color mode is HSB), but will default to the
  51938. * HSL-normalized hue otherwise. (The values will only be different if the
  51939. * maximum hue setting for each system is different.)
  51940. *
  51941. * @method hue
  51942. * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components,
  51943. * or CSS color
  51944. * @return {Number} the hue
  51945. * @example
  51946. * <div>
  51947. * <code>
  51948. * noStroke();
  51949. * colorMode(HSB, 255);
  51950. * let c = color(0, 126, 255);
  51951. * fill(c);
  51952. * rect(15, 20, 35, 60);
  51953. * let value = hue(c); // Sets 'value' to "0"
  51954. * fill(value);
  51955. * rect(50, 20, 35, 60);
  51956. * </code>
  51957. * </div>
  51958. *
  51959. * @alt
  51960. * salmon pink rect on left and black on right, both 35x60.
  51961. */
  51962. _main.default.prototype.hue = function(c) {
  51963. _main.default._validateParameters('hue', arguments);
  51964. return this.color(c)._getHue();
  51965. };
  51966. /**
  51967. * Blends two colors to find a third color somewhere between them. The amt
  51968. * parameter is the amount to interpolate between the two values where 0.0
  51969. * is equal to the first color, 0.1 is very near the first color, 0.5 is halfway
  51970. * in between, etc. An amount below 0 will be treated as 0. Likewise, amounts
  51971. * above 1 will be capped at 1. This is different from the behavior of <a href="#/p5/lerp">lerp()</a>,
  51972. * but necessary because otherwise numbers outside the range will produce
  51973. * strange and unexpected colors.
  51974. *
  51975. * The way that colors are interpolated depends on the current color mode.
  51976. *
  51977. * @method lerpColor
  51978. * @param {p5.Color} c1 interpolate from this color
  51979. * @param {p5.Color} c2 interpolate to this color
  51980. * @param {Number} amt number between 0 and 1
  51981. * @return {p5.Color} interpolated color
  51982. *
  51983. * @example
  51984. * <div>
  51985. * <code>
  51986. * colorMode(RGB);
  51987. * stroke(255);
  51988. * background(51);
  51989. * let from = color(218, 165, 32);
  51990. * let to = color(72, 61, 139);
  51991. * colorMode(RGB); // Try changing to HSB.
  51992. * let interA = lerpColor(from, to, 0.33);
  51993. * let interB = lerpColor(from, to, 0.66);
  51994. * fill(from);
  51995. * rect(10, 20, 20, 60);
  51996. * fill(interA);
  51997. * rect(30, 20, 20, 60);
  51998. * fill(interB);
  51999. * rect(50, 20, 20, 60);
  52000. * fill(to);
  52001. * rect(70, 20, 20, 60);
  52002. * </code>
  52003. * </div>
  52004. *
  52005. * @alt
  52006. * 4 rects one tan, brown, brownish purple, purple, with white outlines & 20x60
  52007. */
  52008. _main.default.prototype.lerpColor = function(c1, c2, amt) {
  52009. _main.default._validateParameters('lerpColor', arguments);
  52010. var mode = this._colorMode;
  52011. var maxes = this._colorMaxes;
  52012. var l0, l1, l2, l3;
  52013. var fromArray, toArray;
  52014. if (mode === constants.RGB) {
  52015. fromArray = c1.levels.map(function(level) {
  52016. return level / 255;
  52017. });
  52018. toArray = c2.levels.map(function(level) {
  52019. return level / 255;
  52020. });
  52021. } else if (mode === constants.HSB) {
  52022. c1._getBrightness(); // Cache hsba so it definitely exists.
  52023. c2._getBrightness();
  52024. fromArray = c1.hsba;
  52025. toArray = c2.hsba;
  52026. } else if (mode === constants.HSL) {
  52027. c1._getLightness(); // Cache hsla so it definitely exists.
  52028. c2._getLightness();
  52029. fromArray = c1.hsla;
  52030. toArray = c2.hsla;
  52031. } else {
  52032. throw new Error(''.concat(mode, 'cannot be used for interpolation.'));
  52033. }
  52034. // Prevent extrapolation.
  52035. amt = Math.max(Math.min(amt, 1), 0);
  52036. // Define lerp here itself if user isn't using math module.
  52037. // Maintains the definition as found in math/calculation.js
  52038. if (typeof this.lerp === 'undefined') {
  52039. this.lerp = function(start, stop, amt) {
  52040. return amt * (stop - start) + start;
  52041. };
  52042. }
  52043. // Perform interpolation.
  52044. l0 = this.lerp(fromArray[0], toArray[0], amt);
  52045. l1 = this.lerp(fromArray[1], toArray[1], amt);
  52046. l2 = this.lerp(fromArray[2], toArray[2], amt);
  52047. l3 = this.lerp(fromArray[3], toArray[3], amt);
  52048. // Scale components.
  52049. l0 *= maxes[mode][0];
  52050. l1 *= maxes[mode][1];
  52051. l2 *= maxes[mode][2];
  52052. l3 *= maxes[mode][3];
  52053. return this.color(l0, l1, l2, l3);
  52054. };
  52055. /**
  52056. * Extracts the HSL lightness value from a color or pixel array.
  52057. *
  52058. * @method lightness
  52059. * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components,
  52060. * or CSS color
  52061. * @return {Number} the lightness
  52062. *
  52063. * @example
  52064. * <div>
  52065. * <code>
  52066. * noStroke();
  52067. * colorMode(HSL);
  52068. * let c = color(156, 100, 50, 1);
  52069. * fill(c);
  52070. * rect(15, 20, 35, 60);
  52071. * let value = lightness(c); // Sets 'value' to 50
  52072. * fill(value);
  52073. * rect(50, 20, 35, 60);
  52074. * </code>
  52075. * </div>
  52076. *
  52077. * @alt
  52078. * light pastel green rect on left and dark grey rect on right, both 35x60.
  52079. */
  52080. _main.default.prototype.lightness = function(c) {
  52081. _main.default._validateParameters('lightness', arguments);
  52082. return this.color(c)._getLightness();
  52083. };
  52084. /**
  52085. * Extracts the red value from a color or pixel array.
  52086. *
  52087. * @method red
  52088. * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components,
  52089. * or CSS color
  52090. * @return {Number} the red value
  52091. * @example
  52092. * <div>
  52093. * <code>
  52094. * let c = color(255, 204, 0); // Define color 'c'
  52095. * fill(c); // Use color variable 'c' as fill color
  52096. * rect(15, 20, 35, 60); // Draw left rectangle
  52097. *
  52098. * let redValue = red(c); // Get red in 'c'
  52099. * print(redValue); // Print "255.0"
  52100. * fill(redValue, 0, 0); // Use 'redValue' in new fill
  52101. * rect(50, 20, 35, 60); // Draw right rectangle
  52102. * </code>
  52103. * </div>
  52104. *
  52105. * <div class="norender">
  52106. * <code>
  52107. * colorMode(RGB, 255); // Sets the range for red, green, and blue to 255
  52108. * let c = color(127, 255, 0);
  52109. * colorMode(RGB, 1); // Sets the range for red, green, and blue to 1
  52110. * let myColor = red(c);
  52111. * print(myColor); // 0.4980392156862745
  52112. * </code>
  52113. * </div>
  52114. *
  52115. * @alt
  52116. * yellow rect on left and red rect on right, both with black outlines and 35x60.
  52117. * grey canvas
  52118. */
  52119. _main.default.prototype.red = function(c) {
  52120. _main.default._validateParameters('red', arguments);
  52121. return this.color(c)._getRed();
  52122. };
  52123. /**
  52124. * Extracts the saturation value from a color or pixel array.
  52125. *
  52126. * Saturation is scaled differently in HSB and HSL. This function will return
  52127. * the HSB saturation when supplied with an HSB color object (or when supplied
  52128. * with a pixel array while the color mode is HSB), but will default to the
  52129. * HSL saturation otherwise.
  52130. *
  52131. * @method saturation
  52132. * @param {p5.Color|Number[]|String} color <a href="#/p5.Color">p5.Color</a> object, color components,
  52133. * or CSS color
  52134. * @return {Number} the saturation value
  52135. * @example
  52136. * <div>
  52137. * <code>
  52138. * noStroke();
  52139. * colorMode(HSB, 255);
  52140. * let c = color(0, 126, 255);
  52141. * fill(c);
  52142. * rect(15, 20, 35, 60);
  52143. * let value = saturation(c); // Sets 'value' to 126
  52144. * fill(value);
  52145. * rect(50, 20, 35, 60);
  52146. * </code>
  52147. * </div>
  52148. *
  52149. * @alt
  52150. *deep pink rect on left and grey rect on right, both 35x60.
  52151. */
  52152. _main.default.prototype.saturation = function(c) {
  52153. _main.default._validateParameters('saturation', arguments);
  52154. return this.color(c)._getSaturation();
  52155. };
  52156. var _default = _main.default;
  52157. exports.default = _default;
  52158. },
  52159. {
  52160. '../core/constants': 272,
  52161. '../core/friendly_errors/fes_core': 275,
  52162. '../core/friendly_errors/file_errors': 276,
  52163. '../core/friendly_errors/validate_params': 278,
  52164. '../core/main': 283,
  52165. './p5.Color': 270,
  52166. 'core-js/modules/es.array.map': 177
  52167. }
  52168. ],
  52169. 270: [
  52170. function(_dereq_, module, exports) {
  52171. 'use strict';
  52172. function _typeof(obj) {
  52173. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  52174. _typeof = function _typeof(obj) {
  52175. return typeof obj;
  52176. };
  52177. } else {
  52178. _typeof = function _typeof(obj) {
  52179. return obj &&
  52180. typeof Symbol === 'function' &&
  52181. obj.constructor === Symbol &&
  52182. obj !== Symbol.prototype
  52183. ? 'symbol'
  52184. : typeof obj;
  52185. };
  52186. }
  52187. return _typeof(obj);
  52188. }
  52189. _dereq_('core-js/modules/es.array.join');
  52190. _dereq_('core-js/modules/es.array.map');
  52191. _dereq_('core-js/modules/es.array.slice');
  52192. _dereq_('core-js/modules/es.object.to-string');
  52193. _dereq_('core-js/modules/es.regexp.constructor');
  52194. _dereq_('core-js/modules/es.regexp.exec');
  52195. _dereq_('core-js/modules/es.regexp.to-string');
  52196. _dereq_('core-js/modules/es.string.trim');
  52197. Object.defineProperty(exports, '__esModule', { value: true });
  52198. exports.default = void 0;
  52199. var _main = _interopRequireDefault(_dereq_('../core/main'));
  52200. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  52201. var _color_conversion = _interopRequireDefault(_dereq_('./color_conversion'));
  52202. function _getRequireWildcardCache() {
  52203. if (typeof WeakMap !== 'function') return null;
  52204. var cache = new WeakMap();
  52205. _getRequireWildcardCache = function _getRequireWildcardCache() {
  52206. return cache;
  52207. };
  52208. return cache;
  52209. }
  52210. function _interopRequireWildcard(obj) {
  52211. if (obj && obj.__esModule) {
  52212. return obj;
  52213. }
  52214. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  52215. return { default: obj };
  52216. }
  52217. var cache = _getRequireWildcardCache();
  52218. if (cache && cache.has(obj)) {
  52219. return cache.get(obj);
  52220. }
  52221. var newObj = {};
  52222. var hasPropertyDescriptor =
  52223. Object.defineProperty && Object.getOwnPropertyDescriptor;
  52224. for (var key in obj) {
  52225. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  52226. var desc = hasPropertyDescriptor
  52227. ? Object.getOwnPropertyDescriptor(obj, key)
  52228. : null;
  52229. if (desc && (desc.get || desc.set)) {
  52230. Object.defineProperty(newObj, key, desc);
  52231. } else {
  52232. newObj[key] = obj[key];
  52233. }
  52234. }
  52235. }
  52236. newObj.default = obj;
  52237. if (cache) {
  52238. cache.set(obj, newObj);
  52239. }
  52240. return newObj;
  52241. }
  52242. function _interopRequireDefault(obj) {
  52243. return obj && obj.__esModule ? obj : { default: obj };
  52244. }
  52245. /**
  52246. * @module Color
  52247. * @submodule Creating & Reading
  52248. * @for p5
  52249. * @requires core
  52250. * @requires constants
  52251. * @requires color_conversion
  52252. */ /**
  52253. * Each color stores the color mode and level maxes that was applied at the
  52254. * time of its construction. These are used to interpret the input arguments
  52255. * (at construction and later for that instance of color) and to format the
  52256. * output e.g. when <a href="#/p5/saturation">saturation()</a> is requested.
  52257. *
  52258. * Internally, we store an array representing the ideal RGBA values in floating
  52259. * point form, normalized from 0 to 1. From this we calculate the closest
  52260. * screen color (RGBA levels from 0 to 255) and expose this to the renderer.
  52261. *
  52262. * We also cache normalized, floating point components of the color in various
  52263. * representations as they are calculated. This is done to prevent repeating a
  52264. * conversion that has already been performed.
  52265. *
  52266. * @class p5.Color
  52267. * @constructor
  52268. */ _main.default.Color = function(pInst, vals) {
  52269. // Record color mode and maxes at time of construction.
  52270. this._storeModeAndMaxes(pInst._colorMode, pInst._colorMaxes); // Calculate normalized RGBA values.
  52271. if (
  52272. this.mode !== constants.RGB &&
  52273. this.mode !== constants.HSL &&
  52274. this.mode !== constants.HSB
  52275. ) {
  52276. throw new Error(''.concat(this.mode, ' is an invalid colorMode.'));
  52277. } else {
  52278. this._array = _main.default.Color._parseInputs.apply(this, vals);
  52279. }
  52280. // Expose closest screen color.
  52281. this._calculateLevels();
  52282. return this;
  52283. };
  52284. /**
  52285. * This function returns the color formatted as a string. This can be useful
  52286. * for debugging, or for using p5.js with other libraries.
  52287. *
  52288. * @method toString
  52289. * @param {String} [format] How the color string will be formatted.
  52290. * Leaving this empty formats the string as rgba(r, g, b, a).
  52291. * '#rgb' '#rgba' '#rrggbb' and '#rrggbbaa' format as hexadecimal color codes.
  52292. * 'rgb' 'hsb' and 'hsl' return the color formatted in the specified color mode.
  52293. * 'rgba' 'hsba' and 'hsla' are the same as above but with alpha channels.
  52294. * 'rgb%' 'hsb%' 'hsl%' 'rgba%' 'hsba%' and 'hsla%' format as percentages.
  52295. * @return {String} the formatted string
  52296. *
  52297. * @example
  52298. * <div>
  52299. * <code>
  52300. * createCanvas(200, 100);
  52301. * let myColor;
  52302. * stroke(255);
  52303. * myColor = color(100, 100, 250);
  52304. * fill(myColor);
  52305. * rotate(HALF_PI);
  52306. * text(myColor.toString(), 0, -5);
  52307. * text(myColor.toString('#rrggbb'), 0, -30);
  52308. * text(myColor.toString('rgba%'), 0, -55);
  52309. * </code>
  52310. * </div>
  52311. *
  52312. * <div>
  52313. * <code>
  52314. * let myColor = color(100, 130, 250);
  52315. * text(myColor.toString('#rrggbb'), 25, 25);
  52316. * </code>
  52317. * </div>
  52318. *
  52319. * @alt
  52320. * A canvas with 3 text representation of their color.
  52321. */
  52322. _main.default.Color.prototype.toString = function(format) {
  52323. var a = this.levels;
  52324. var f = this._array;
  52325. var alpha = f[3]; // String representation uses normalized alpha
  52326. switch (format) {
  52327. case '#rrggbb':
  52328. return '#'.concat(
  52329. a[0] < 16 ? '0'.concat(a[0].toString(16)) : a[0].toString(16),
  52330. a[1] < 16 ? '0'.concat(a[1].toString(16)) : a[1].toString(16),
  52331. a[2] < 16 ? '0'.concat(a[2].toString(16)) : a[2].toString(16)
  52332. );
  52333. case '#rrggbbaa':
  52334. return '#'.concat(
  52335. a[0] < 16 ? '0'.concat(a[0].toString(16)) : a[0].toString(16),
  52336. a[1] < 16 ? '0'.concat(a[1].toString(16)) : a[1].toString(16),
  52337. a[2] < 16 ? '0'.concat(a[2].toString(16)) : a[2].toString(16),
  52338. a[3] < 16 ? '0'.concat(a[3].toString(16)) : a[3].toString(16)
  52339. );
  52340. case '#rgb':
  52341. return '#'.concat(
  52342. Math.round(f[0] * 15).toString(16),
  52343. Math.round(f[1] * 15).toString(16),
  52344. Math.round(f[2] * 15).toString(16)
  52345. );
  52346. case '#rgba':
  52347. return '#'.concat(
  52348. Math.round(f[0] * 15).toString(16),
  52349. Math.round(f[1] * 15).toString(16),
  52350. Math.round(f[2] * 15).toString(16),
  52351. Math.round(f[3] * 15).toString(16)
  52352. );
  52353. case 'rgb':
  52354. return 'rgb('.concat(a[0], ', ', a[1], ', ', a[2], ')');
  52355. case 'rgb%':
  52356. return 'rgb('.concat(
  52357. (100 * f[0]).toPrecision(3),
  52358. '%, ',
  52359. (100 * f[1]).toPrecision(3),
  52360. '%, ',
  52361. (100 * f[2]).toPrecision(3),
  52362. '%)'
  52363. );
  52364. case 'rgba%':
  52365. return 'rgba('.concat(
  52366. (100 * f[0]).toPrecision(3),
  52367. '%, ',
  52368. (100 * f[1]).toPrecision(3),
  52369. '%, ',
  52370. (100 * f[2]).toPrecision(3),
  52371. '%, ',
  52372. (100 * f[3]).toPrecision(3),
  52373. '%)'
  52374. );
  52375. case 'hsb':
  52376. case 'hsv':
  52377. if (!this.hsba)
  52378. this.hsba = _color_conversion.default._rgbaToHSBA(this._array);
  52379. return 'hsb('.concat(
  52380. this.hsba[0] * this.maxes[constants.HSB][0],
  52381. ', ',
  52382. this.hsba[1] * this.maxes[constants.HSB][1],
  52383. ', ',
  52384. this.hsba[2] * this.maxes[constants.HSB][2],
  52385. ')'
  52386. );
  52387. case 'hsb%':
  52388. case 'hsv%':
  52389. if (!this.hsba)
  52390. this.hsba = _color_conversion.default._rgbaToHSBA(this._array);
  52391. return 'hsb('.concat(
  52392. (100 * this.hsba[0]).toPrecision(3),
  52393. '%, ',
  52394. (100 * this.hsba[1]).toPrecision(3),
  52395. '%, ',
  52396. (100 * this.hsba[2]).toPrecision(3),
  52397. '%)'
  52398. );
  52399. case 'hsba':
  52400. case 'hsva':
  52401. if (!this.hsba)
  52402. this.hsba = _color_conversion.default._rgbaToHSBA(this._array);
  52403. return 'hsba('.concat(
  52404. this.hsba[0] * this.maxes[constants.HSB][0],
  52405. ', ',
  52406. this.hsba[1] * this.maxes[constants.HSB][1],
  52407. ', ',
  52408. this.hsba[2] * this.maxes[constants.HSB][2],
  52409. ', ',
  52410. alpha,
  52411. ')'
  52412. );
  52413. case 'hsba%':
  52414. case 'hsva%':
  52415. if (!this.hsba)
  52416. this.hsba = _color_conversion.default._rgbaToHSBA(this._array);
  52417. return 'hsba('.concat(
  52418. (100 * this.hsba[0]).toPrecision(3),
  52419. '%, ',
  52420. (100 * this.hsba[1]).toPrecision(3),
  52421. '%, ',
  52422. (100 * this.hsba[2]).toPrecision(3),
  52423. '%, ',
  52424. (100 * alpha).toPrecision(3),
  52425. '%)'
  52426. );
  52427. case 'hsl':
  52428. if (!this.hsla)
  52429. this.hsla = _color_conversion.default._rgbaToHSLA(this._array);
  52430. return 'hsl('.concat(
  52431. this.hsla[0] * this.maxes[constants.HSL][0],
  52432. ', ',
  52433. this.hsla[1] * this.maxes[constants.HSL][1],
  52434. ', ',
  52435. this.hsla[2] * this.maxes[constants.HSL][2],
  52436. ')'
  52437. );
  52438. case 'hsl%':
  52439. if (!this.hsla)
  52440. this.hsla = _color_conversion.default._rgbaToHSLA(this._array);
  52441. return 'hsl('.concat(
  52442. (100 * this.hsla[0]).toPrecision(3),
  52443. '%, ',
  52444. (100 * this.hsla[1]).toPrecision(3),
  52445. '%, ',
  52446. (100 * this.hsla[2]).toPrecision(3),
  52447. '%)'
  52448. );
  52449. case 'hsla':
  52450. if (!this.hsla)
  52451. this.hsla = _color_conversion.default._rgbaToHSLA(this._array);
  52452. return 'hsla('.concat(
  52453. this.hsla[0] * this.maxes[constants.HSL][0],
  52454. ', ',
  52455. this.hsla[1] * this.maxes[constants.HSL][1],
  52456. ', ',
  52457. this.hsla[2] * this.maxes[constants.HSL][2],
  52458. ', ',
  52459. alpha,
  52460. ')'
  52461. );
  52462. case 'hsla%':
  52463. if (!this.hsla)
  52464. this.hsla = _color_conversion.default._rgbaToHSLA(this._array);
  52465. return 'hsl('.concat(
  52466. (100 * this.hsla[0]).toPrecision(3),
  52467. '%, ',
  52468. (100 * this.hsla[1]).toPrecision(3),
  52469. '%, ',
  52470. (100 * this.hsla[2]).toPrecision(3),
  52471. '%, ',
  52472. (100 * alpha).toPrecision(3),
  52473. '%)'
  52474. );
  52475. case 'rgba':
  52476. default:
  52477. return 'rgba('.concat(a[0], ',', a[1], ',', a[2], ',', alpha, ')');
  52478. }
  52479. };
  52480. /**
  52481. * The setRed function sets the red component of a color.
  52482. * The range depends on your color mode, in the default RGB mode it's between 0 and 255.
  52483. * @method setRed
  52484. * @param {Number} red the new red value
  52485. * @example
  52486. * <div>
  52487. * <code>
  52488. * let backgroundColor;
  52489. *
  52490. * function setup() {
  52491. * backgroundColor = color(100, 50, 150);
  52492. * }
  52493. *
  52494. * function draw() {
  52495. * backgroundColor.setRed(128 + 128 * sin(millis() / 1000));
  52496. * background(backgroundColor);
  52497. * }
  52498. * </code>
  52499. * </div>
  52500. *
  52501. * @alt
  52502. * canvas with gradually changing background color
  52503. */
  52504. _main.default.Color.prototype.setRed = function(new_red) {
  52505. this._array[0] = new_red / this.maxes[constants.RGB][0];
  52506. this._calculateLevels();
  52507. };
  52508. /**
  52509. * The setGreen function sets the green component of a color.
  52510. * The range depends on your color mode, in the default RGB mode it's between 0 and 255.
  52511. * @method setGreen
  52512. * @param {Number} green the new green value
  52513. * @example
  52514. * <div>
  52515. * <code>
  52516. * let backgroundColor = color(100, 50, 150);
  52517. * function draw() {
  52518. * backgroundColor.setGreen(128 + 128 * sin(millis() / 1000));
  52519. * background(backgroundColor);
  52520. * }
  52521. * </code>
  52522. * </div>
  52523. *
  52524. * @alt
  52525. * canvas with gradually changing background color
  52526. **/
  52527. _main.default.Color.prototype.setGreen = function(new_green) {
  52528. this._array[1] = new_green / this.maxes[constants.RGB][1];
  52529. this._calculateLevels();
  52530. };
  52531. /**
  52532. * The setBlue function sets the blue component of a color.
  52533. * The range depends on your color mode, in the default RGB mode it's between 0 and 255.
  52534. * @method setBlue
  52535. * @param {Number} blue the new blue value
  52536. * @example
  52537. * <div>
  52538. * <code>
  52539. * let backgroundColor = color(100, 50, 150);
  52540. * function draw() {
  52541. * backgroundColor.setBlue(128 + 128 * sin(millis() / 1000));
  52542. * background(backgroundColor);
  52543. * }
  52544. * </code>
  52545. * </div>
  52546. *
  52547. * @alt
  52548. * canvas with gradually changing background color
  52549. **/
  52550. _main.default.Color.prototype.setBlue = function(new_blue) {
  52551. this._array[2] = new_blue / this.maxes[constants.RGB][2];
  52552. this._calculateLevels();
  52553. };
  52554. /**
  52555. * The setAlpha function sets the transparency (alpha) value of a color.
  52556. * The range depends on your color mode, in the default RGB mode it's between 0 and 255.
  52557. * @method setAlpha
  52558. * @param {Number} alpha the new alpha value
  52559. * @example
  52560. * <div>
  52561. * <code>
  52562. * function draw() {
  52563. * clear();
  52564. * background(200);
  52565. * squareColor = color(100, 50, 100);
  52566. * squareColor.setAlpha(128 + 128 * sin(millis() / 1000));
  52567. * fill(squareColor);
  52568. * rect(13, 13, width - 26, height - 26);
  52569. * }
  52570. * </code>
  52571. * </div>
  52572. *
  52573. * @alt
  52574. * a square with gradually changing opacity on a gray background
  52575. **/
  52576. _main.default.Color.prototype.setAlpha = function(new_alpha) {
  52577. this._array[3] = new_alpha / this.maxes[this.mode][3];
  52578. this._calculateLevels();
  52579. };
  52580. // calculates and stores the closest screen levels
  52581. _main.default.Color.prototype._calculateLevels = function() {
  52582. var array = this._array;
  52583. // (loop backwards for performance)
  52584. var levels = (this.levels = new Array(array.length));
  52585. for (var i = array.length - 1; i >= 0; --i) {
  52586. levels[i] = Math.round(array[i] * 255);
  52587. }
  52588. };
  52589. _main.default.Color.prototype._getAlpha = function() {
  52590. return this._array[3] * this.maxes[this.mode][3];
  52591. };
  52592. // stores the color mode and maxes in this instance of Color
  52593. // for later use (by _parseInputs())
  52594. _main.default.Color.prototype._storeModeAndMaxes = function(new_mode, new_maxes) {
  52595. this.mode = new_mode;
  52596. this.maxes = new_maxes;
  52597. };
  52598. _main.default.Color.prototype._getMode = function() {
  52599. return this.mode;
  52600. };
  52601. _main.default.Color.prototype._getMaxes = function() {
  52602. return this.maxes;
  52603. };
  52604. _main.default.Color.prototype._getBlue = function() {
  52605. return this._array[2] * this.maxes[constants.RGB][2];
  52606. };
  52607. _main.default.Color.prototype._getBrightness = function() {
  52608. if (!this.hsba) {
  52609. this.hsba = _color_conversion.default._rgbaToHSBA(this._array);
  52610. }
  52611. return this.hsba[2] * this.maxes[constants.HSB][2];
  52612. };
  52613. _main.default.Color.prototype._getGreen = function() {
  52614. return this._array[1] * this.maxes[constants.RGB][1];
  52615. };
  52616. /**
  52617. * Hue is the same in HSB and HSL, but the maximum value may be different.
  52618. * This function will return the HSB-normalized saturation when supplied with
  52619. * an HSB color object, but will default to the HSL-normalized saturation
  52620. * otherwise.
  52621. */
  52622. _main.default.Color.prototype._getHue = function() {
  52623. if (this.mode === constants.HSB) {
  52624. if (!this.hsba) {
  52625. this.hsba = _color_conversion.default._rgbaToHSBA(this._array);
  52626. }
  52627. return this.hsba[0] * this.maxes[constants.HSB][0];
  52628. } else {
  52629. if (!this.hsla) {
  52630. this.hsla = _color_conversion.default._rgbaToHSLA(this._array);
  52631. }
  52632. return this.hsla[0] * this.maxes[constants.HSL][0];
  52633. }
  52634. };
  52635. _main.default.Color.prototype._getLightness = function() {
  52636. if (!this.hsla) {
  52637. this.hsla = _color_conversion.default._rgbaToHSLA(this._array);
  52638. }
  52639. return this.hsla[2] * this.maxes[constants.HSL][2];
  52640. };
  52641. _main.default.Color.prototype._getRed = function() {
  52642. return this._array[0] * this.maxes[constants.RGB][0];
  52643. };
  52644. /**
  52645. * Saturation is scaled differently in HSB and HSL. This function will return
  52646. * the HSB saturation when supplied with an HSB color object, but will default
  52647. * to the HSL saturation otherwise.
  52648. */
  52649. _main.default.Color.prototype._getSaturation = function() {
  52650. if (this.mode === constants.HSB) {
  52651. if (!this.hsba) {
  52652. this.hsba = _color_conversion.default._rgbaToHSBA(this._array);
  52653. }
  52654. return this.hsba[1] * this.maxes[constants.HSB][1];
  52655. } else {
  52656. if (!this.hsla) {
  52657. this.hsla = _color_conversion.default._rgbaToHSLA(this._array);
  52658. }
  52659. return this.hsla[1] * this.maxes[constants.HSL][1];
  52660. }
  52661. };
  52662. /**
  52663. * CSS named colors.
  52664. */
  52665. var namedColors = {
  52666. aliceblue: '#f0f8ff',
  52667. antiquewhite: '#faebd7',
  52668. aqua: '#00ffff',
  52669. aquamarine: '#7fffd4',
  52670. azure: '#f0ffff',
  52671. beige: '#f5f5dc',
  52672. bisque: '#ffe4c4',
  52673. black: '#000000',
  52674. blanchedalmond: '#ffebcd',
  52675. blue: '#0000ff',
  52676. blueviolet: '#8a2be2',
  52677. brown: '#a52a2a',
  52678. burlywood: '#deb887',
  52679. cadetblue: '#5f9ea0',
  52680. chartreuse: '#7fff00',
  52681. chocolate: '#d2691e',
  52682. coral: '#ff7f50',
  52683. cornflowerblue: '#6495ed',
  52684. cornsilk: '#fff8dc',
  52685. crimson: '#dc143c',
  52686. cyan: '#00ffff',
  52687. darkblue: '#00008b',
  52688. darkcyan: '#008b8b',
  52689. darkgoldenrod: '#b8860b',
  52690. darkgray: '#a9a9a9',
  52691. darkgreen: '#006400',
  52692. darkgrey: '#a9a9a9',
  52693. darkkhaki: '#bdb76b',
  52694. darkmagenta: '#8b008b',
  52695. darkolivegreen: '#556b2f',
  52696. darkorange: '#ff8c00',
  52697. darkorchid: '#9932cc',
  52698. darkred: '#8b0000',
  52699. darksalmon: '#e9967a',
  52700. darkseagreen: '#8fbc8f',
  52701. darkslateblue: '#483d8b',
  52702. darkslategray: '#2f4f4f',
  52703. darkslategrey: '#2f4f4f',
  52704. darkturquoise: '#00ced1',
  52705. darkviolet: '#9400d3',
  52706. deeppink: '#ff1493',
  52707. deepskyblue: '#00bfff',
  52708. dimgray: '#696969',
  52709. dimgrey: '#696969',
  52710. dodgerblue: '#1e90ff',
  52711. firebrick: '#b22222',
  52712. floralwhite: '#fffaf0',
  52713. forestgreen: '#228b22',
  52714. fuchsia: '#ff00ff',
  52715. gainsboro: '#dcdcdc',
  52716. ghostwhite: '#f8f8ff',
  52717. gold: '#ffd700',
  52718. goldenrod: '#daa520',
  52719. gray: '#808080',
  52720. green: '#008000',
  52721. greenyellow: '#adff2f',
  52722. grey: '#808080',
  52723. honeydew: '#f0fff0',
  52724. hotpink: '#ff69b4',
  52725. indianred: '#cd5c5c',
  52726. indigo: '#4b0082',
  52727. ivory: '#fffff0',
  52728. khaki: '#f0e68c',
  52729. lavender: '#e6e6fa',
  52730. lavenderblush: '#fff0f5',
  52731. lawngreen: '#7cfc00',
  52732. lemonchiffon: '#fffacd',
  52733. lightblue: '#add8e6',
  52734. lightcoral: '#f08080',
  52735. lightcyan: '#e0ffff',
  52736. lightgoldenrodyellow: '#fafad2',
  52737. lightgray: '#d3d3d3',
  52738. lightgreen: '#90ee90',
  52739. lightgrey: '#d3d3d3',
  52740. lightpink: '#ffb6c1',
  52741. lightsalmon: '#ffa07a',
  52742. lightseagreen: '#20b2aa',
  52743. lightskyblue: '#87cefa',
  52744. lightslategray: '#778899',
  52745. lightslategrey: '#778899',
  52746. lightsteelblue: '#b0c4de',
  52747. lightyellow: '#ffffe0',
  52748. lime: '#00ff00',
  52749. limegreen: '#32cd32',
  52750. linen: '#faf0e6',
  52751. magenta: '#ff00ff',
  52752. maroon: '#800000',
  52753. mediumaquamarine: '#66cdaa',
  52754. mediumblue: '#0000cd',
  52755. mediumorchid: '#ba55d3',
  52756. mediumpurple: '#9370db',
  52757. mediumseagreen: '#3cb371',
  52758. mediumslateblue: '#7b68ee',
  52759. mediumspringgreen: '#00fa9a',
  52760. mediumturquoise: '#48d1cc',
  52761. mediumvioletred: '#c71585',
  52762. midnightblue: '#191970',
  52763. mintcream: '#f5fffa',
  52764. mistyrose: '#ffe4e1',
  52765. moccasin: '#ffe4b5',
  52766. navajowhite: '#ffdead',
  52767. navy: '#000080',
  52768. oldlace: '#fdf5e6',
  52769. olive: '#808000',
  52770. olivedrab: '#6b8e23',
  52771. orange: '#ffa500',
  52772. orangered: '#ff4500',
  52773. orchid: '#da70d6',
  52774. palegoldenrod: '#eee8aa',
  52775. palegreen: '#98fb98',
  52776. paleturquoise: '#afeeee',
  52777. palevioletred: '#db7093',
  52778. papayawhip: '#ffefd5',
  52779. peachpuff: '#ffdab9',
  52780. peru: '#cd853f',
  52781. pink: '#ffc0cb',
  52782. plum: '#dda0dd',
  52783. powderblue: '#b0e0e6',
  52784. purple: '#800080',
  52785. rebeccapurple: '#663399',
  52786. red: '#ff0000',
  52787. rosybrown: '#bc8f8f',
  52788. royalblue: '#4169e1',
  52789. saddlebrown: '#8b4513',
  52790. salmon: '#fa8072',
  52791. sandybrown: '#f4a460',
  52792. seagreen: '#2e8b57',
  52793. seashell: '#fff5ee',
  52794. sienna: '#a0522d',
  52795. silver: '#c0c0c0',
  52796. skyblue: '#87ceeb',
  52797. slateblue: '#6a5acd',
  52798. slategray: '#708090',
  52799. slategrey: '#708090',
  52800. snow: '#fffafa',
  52801. springgreen: '#00ff7f',
  52802. steelblue: '#4682b4',
  52803. tan: '#d2b48c',
  52804. teal: '#008080',
  52805. thistle: '#d8bfd8',
  52806. tomato: '#ff6347',
  52807. turquoise: '#40e0d0',
  52808. violet: '#ee82ee',
  52809. wheat: '#f5deb3',
  52810. white: '#ffffff',
  52811. whitesmoke: '#f5f5f5',
  52812. yellow: '#ffff00',
  52813. yellowgreen: '#9acd32'
  52814. };
  52815. /**
  52816. * These regular expressions are used to build up the patterns for matching
  52817. * viable CSS color strings: fragmenting the regexes in this way increases the
  52818. * legibility and comprehensibility of the code.
  52819. *
  52820. * Note that RGB values of .9 are not parsed by IE, but are supported here for
  52821. * color string consistency.
  52822. */
  52823. var WHITESPACE = /\s*/; // Match zero or more whitespace characters.
  52824. var INTEGER = /(\d{1,3})/; // Match integers: 79, 255, etc.
  52825. var DECIMAL = /((?:\d+(?:\.\d+)?)|(?:\.\d+))/; // Match 129.6, 79, .9, etc.
  52826. var PERCENT = new RegExp(''.concat(DECIMAL.source, '%')); // Match 12.9%, 79%, .9%, etc.
  52827. /**
  52828. * Full color string patterns. The capture groups are necessary.
  52829. */
  52830. var colorPatterns = {
  52831. // Match colors in format #XXX, e.g. #416.
  52832. HEX3: /^#([a-f0-9])([a-f0-9])([a-f0-9])$/i,
  52833. // Match colors in format #XXXX, e.g. #5123.
  52834. HEX4: /^#([a-f0-9])([a-f0-9])([a-f0-9])([a-f0-9])$/i,
  52835. // Match colors in format #XXXXXX, e.g. #b4d455.
  52836. HEX6: /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i,
  52837. // Match colors in format #XXXXXXXX, e.g. #b4d45535.
  52838. HEX8: /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i,
  52839. // Match colors in format rgb(R, G, B), e.g. rgb(255, 0, 128).
  52840. RGB: new RegExp(
  52841. [
  52842. '^rgb\\(',
  52843. INTEGER.source,
  52844. ',',
  52845. INTEGER.source,
  52846. ',',
  52847. INTEGER.source,
  52848. '\\)$'
  52849. ].join(WHITESPACE.source),
  52850. 'i'
  52851. ),
  52852. // Match colors in format rgb(R%, G%, B%), e.g. rgb(100%, 0%, 28.9%).
  52853. RGB_PERCENT: new RegExp(
  52854. [
  52855. '^rgb\\(',
  52856. PERCENT.source,
  52857. ',',
  52858. PERCENT.source,
  52859. ',',
  52860. PERCENT.source,
  52861. '\\)$'
  52862. ].join(WHITESPACE.source),
  52863. 'i'
  52864. ),
  52865. // Match colors in format rgb(R, G, B, A), e.g. rgb(255, 0, 128, 0.25).
  52866. RGBA: new RegExp(
  52867. [
  52868. '^rgba\\(',
  52869. INTEGER.source,
  52870. ',',
  52871. INTEGER.source,
  52872. ',',
  52873. INTEGER.source,
  52874. ',',
  52875. DECIMAL.source,
  52876. '\\)$'
  52877. ].join(WHITESPACE.source),
  52878. 'i'
  52879. ),
  52880. // Match colors in format rgb(R%, G%, B%, A), e.g. rgb(100%, 0%, 28.9%, 0.5).
  52881. RGBA_PERCENT: new RegExp(
  52882. [
  52883. '^rgba\\(',
  52884. PERCENT.source,
  52885. ',',
  52886. PERCENT.source,
  52887. ',',
  52888. PERCENT.source,
  52889. ',',
  52890. DECIMAL.source,
  52891. '\\)$'
  52892. ].join(WHITESPACE.source),
  52893. 'i'
  52894. ),
  52895. // Match colors in format hsla(H, S%, L%), e.g. hsl(100, 40%, 28.9%).
  52896. HSL: new RegExp(
  52897. [
  52898. '^hsl\\(',
  52899. INTEGER.source,
  52900. ',',
  52901. PERCENT.source,
  52902. ',',
  52903. PERCENT.source,
  52904. '\\)$'
  52905. ].join(WHITESPACE.source),
  52906. 'i'
  52907. ),
  52908. // Match colors in format hsla(H, S%, L%, A), e.g. hsla(100, 40%, 28.9%, 0.5).
  52909. HSLA: new RegExp(
  52910. [
  52911. '^hsla\\(',
  52912. INTEGER.source,
  52913. ',',
  52914. PERCENT.source,
  52915. ',',
  52916. PERCENT.source,
  52917. ',',
  52918. DECIMAL.source,
  52919. '\\)$'
  52920. ].join(WHITESPACE.source),
  52921. 'i'
  52922. ),
  52923. // Match colors in format hsb(H, S%, B%), e.g. hsb(100, 40%, 28.9%).
  52924. HSB: new RegExp(
  52925. [
  52926. '^hsb\\(',
  52927. INTEGER.source,
  52928. ',',
  52929. PERCENT.source,
  52930. ',',
  52931. PERCENT.source,
  52932. '\\)$'
  52933. ].join(WHITESPACE.source),
  52934. 'i'
  52935. ),
  52936. // Match colors in format hsba(H, S%, B%, A), e.g. hsba(100, 40%, 28.9%, 0.5).
  52937. HSBA: new RegExp(
  52938. [
  52939. '^hsba\\(',
  52940. INTEGER.source,
  52941. ',',
  52942. PERCENT.source,
  52943. ',',
  52944. PERCENT.source,
  52945. ',',
  52946. DECIMAL.source,
  52947. '\\)$'
  52948. ].join(WHITESPACE.source),
  52949. 'i'
  52950. )
  52951. };
  52952. /**
  52953. * For a number of different inputs, returns a color formatted as [r, g, b, a]
  52954. * arrays, with each component normalized between 0 and 1.
  52955. *
  52956. * @private
  52957. * @param {Array} [...args] An 'array-like' object that represents a list of
  52958. * arguments
  52959. * @return {Number[]} a color formatted as [r, g, b, a]
  52960. * Example:
  52961. * input ==> output
  52962. * g ==> [g, g, g, 255]
  52963. * g,a ==> [g, g, g, a]
  52964. * r, g, b ==> [r, g, b, 255]
  52965. * r, g, b, a ==> [r, g, b, a]
  52966. * [g] ==> [g, g, g, 255]
  52967. * [g, a] ==> [g, g, g, a]
  52968. * [r, g, b] ==> [r, g, b, 255]
  52969. * [r, g, b, a] ==> [r, g, b, a]
  52970. * @example
  52971. * <div>
  52972. * <code>
  52973. * // todo
  52974. * </code>
  52975. * </div>
  52976. *
  52977. * @alt
  52978. * //todo
  52979. */
  52980. _main.default.Color._parseInputs = function(r, g, b, a) {
  52981. var numArgs = arguments.length;
  52982. var mode = this.mode;
  52983. var maxes = this.maxes[mode];
  52984. var results = [];
  52985. var i;
  52986. if (numArgs >= 3) {
  52987. // Argument is a list of component values.
  52988. results[0] = r / maxes[0];
  52989. results[1] = g / maxes[1];
  52990. results[2] = b / maxes[2];
  52991. // Alpha may be undefined, so default it to 100%.
  52992. if (typeof a === 'number') {
  52993. results[3] = a / maxes[3];
  52994. } else {
  52995. results[3] = 1;
  52996. }
  52997. // Constrain components to the range [0,1].
  52998. // (loop backwards for performance)
  52999. for (i = results.length - 1; i >= 0; --i) {
  53000. var result = results[i];
  53001. if (result < 0) {
  53002. results[i] = 0;
  53003. } else if (result > 1) {
  53004. results[i] = 1;
  53005. }
  53006. }
  53007. // Convert to RGBA and return.
  53008. if (mode === constants.HSL) {
  53009. return _color_conversion.default._hslaToRGBA(results);
  53010. } else if (mode === constants.HSB) {
  53011. return _color_conversion.default._hsbaToRGBA(results);
  53012. } else {
  53013. return results;
  53014. }
  53015. } else if (numArgs === 1 && typeof r === 'string') {
  53016. var str = r.trim().toLowerCase();
  53017. // Return if string is a named colour.
  53018. if (namedColors[str]) {
  53019. return _main.default.Color._parseInputs.call(this, namedColors[str]);
  53020. }
  53021. // Try RGBA pattern matching.
  53022. if (colorPatterns.HEX3.test(str)) {
  53023. // #rgb
  53024. results = colorPatterns.HEX3.exec(str)
  53025. .slice(1)
  53026. .map(function(color) {
  53027. return parseInt(color + color, 16) / 255;
  53028. });
  53029. results[3] = 1;
  53030. return results;
  53031. } else if (colorPatterns.HEX6.test(str)) {
  53032. // #rrggbb
  53033. results = colorPatterns.HEX6.exec(str)
  53034. .slice(1)
  53035. .map(function(color) {
  53036. return parseInt(color, 16) / 255;
  53037. });
  53038. results[3] = 1;
  53039. return results;
  53040. } else if (colorPatterns.HEX4.test(str)) {
  53041. // #rgba
  53042. results = colorPatterns.HEX4.exec(str)
  53043. .slice(1)
  53044. .map(function(color) {
  53045. return parseInt(color + color, 16) / 255;
  53046. });
  53047. return results;
  53048. } else if (colorPatterns.HEX8.test(str)) {
  53049. // #rrggbbaa
  53050. results = colorPatterns.HEX8.exec(str)
  53051. .slice(1)
  53052. .map(function(color) {
  53053. return parseInt(color, 16) / 255;
  53054. });
  53055. return results;
  53056. } else if (colorPatterns.RGB.test(str)) {
  53057. // rgb(R,G,B)
  53058. results = colorPatterns.RGB.exec(str)
  53059. .slice(1)
  53060. .map(function(color) {
  53061. return color / 255;
  53062. });
  53063. results[3] = 1;
  53064. return results;
  53065. } else if (colorPatterns.RGB_PERCENT.test(str)) {
  53066. // rgb(R%,G%,B%)
  53067. results = colorPatterns.RGB_PERCENT.exec(str)
  53068. .slice(1)
  53069. .map(function(color) {
  53070. return parseFloat(color) / 100;
  53071. });
  53072. results[3] = 1;
  53073. return results;
  53074. } else if (colorPatterns.RGBA.test(str)) {
  53075. // rgba(R,G,B,A)
  53076. results = colorPatterns.RGBA.exec(str)
  53077. .slice(1)
  53078. .map(function(color, idx) {
  53079. if (idx === 3) {
  53080. return parseFloat(color);
  53081. }
  53082. return color / 255;
  53083. });
  53084. return results;
  53085. } else if (colorPatterns.RGBA_PERCENT.test(str)) {
  53086. // rgba(R%,G%,B%,A%)
  53087. results = colorPatterns.RGBA_PERCENT.exec(str)
  53088. .slice(1)
  53089. .map(function(color, idx) {
  53090. if (idx === 3) {
  53091. return parseFloat(color);
  53092. }
  53093. return parseFloat(color) / 100;
  53094. });
  53095. return results;
  53096. }
  53097. // Try HSLA pattern matching.
  53098. if (colorPatterns.HSL.test(str)) {
  53099. // hsl(H,S,L)
  53100. results = colorPatterns.HSL.exec(str)
  53101. .slice(1)
  53102. .map(function(color, idx) {
  53103. if (idx === 0) {
  53104. return parseInt(color, 10) / 360;
  53105. }
  53106. return parseInt(color, 10) / 100;
  53107. });
  53108. results[3] = 1;
  53109. } else if (colorPatterns.HSLA.test(str)) {
  53110. // hsla(H,S,L,A)
  53111. results = colorPatterns.HSLA.exec(str)
  53112. .slice(1)
  53113. .map(function(color, idx) {
  53114. if (idx === 0) {
  53115. return parseInt(color, 10) / 360;
  53116. } else if (idx === 3) {
  53117. return parseFloat(color);
  53118. }
  53119. return parseInt(color, 10) / 100;
  53120. });
  53121. }
  53122. results = results.map(function(value) {
  53123. return Math.max(Math.min(value, 1), 0);
  53124. });
  53125. if (results.length) {
  53126. return _color_conversion.default._hslaToRGBA(results);
  53127. }
  53128. // Try HSBA pattern matching.
  53129. if (colorPatterns.HSB.test(str)) {
  53130. // hsb(H,S,B)
  53131. results = colorPatterns.HSB.exec(str)
  53132. .slice(1)
  53133. .map(function(color, idx) {
  53134. if (idx === 0) {
  53135. return parseInt(color, 10) / 360;
  53136. }
  53137. return parseInt(color, 10) / 100;
  53138. });
  53139. results[3] = 1;
  53140. } else if (colorPatterns.HSBA.test(str)) {
  53141. // hsba(H,S,B,A)
  53142. results = colorPatterns.HSBA.exec(str)
  53143. .slice(1)
  53144. .map(function(color, idx) {
  53145. if (idx === 0) {
  53146. return parseInt(color, 10) / 360;
  53147. } else if (idx === 3) {
  53148. return parseFloat(color);
  53149. }
  53150. return parseInt(color, 10) / 100;
  53151. });
  53152. }
  53153. if (results.length) {
  53154. // (loop backwards for performance)
  53155. for (i = results.length - 1; i >= 0; --i) {
  53156. results[i] = Math.max(Math.min(results[i], 1), 0);
  53157. }
  53158. return _color_conversion.default._hsbaToRGBA(results);
  53159. }
  53160. // Input did not match any CSS color pattern: default to white.
  53161. results = [1, 1, 1, 1];
  53162. } else if ((numArgs === 1 || numArgs === 2) && typeof r === 'number') {
  53163. // 'Grayscale' mode.
  53164. /**
  53165. * For HSB and HSL, interpret the gray level as a brightness/lightness
  53166. * value (they are equivalent when chroma is zero). For RGB, normalize the
  53167. * gray level according to the blue maximum.
  53168. */
  53169. results[0] = r / maxes[2];
  53170. results[1] = r / maxes[2];
  53171. results[2] = r / maxes[2];
  53172. // Alpha may be undefined, so default it to 100%.
  53173. if (typeof g === 'number') {
  53174. results[3] = g / maxes[3];
  53175. } else {
  53176. results[3] = 1;
  53177. }
  53178. // Constrain components to the range [0,1].
  53179. results = results.map(function(value) {
  53180. return Math.max(Math.min(value, 1), 0);
  53181. });
  53182. } else {
  53183. throw new Error(''.concat(arguments, 'is not a valid color representation.'));
  53184. }
  53185. return results;
  53186. };
  53187. var _default = _main.default.Color;
  53188. exports.default = _default;
  53189. },
  53190. {
  53191. '../core/constants': 272,
  53192. '../core/main': 283,
  53193. './color_conversion': 268,
  53194. 'core-js/modules/es.array.join': 175,
  53195. 'core-js/modules/es.array.map': 177,
  53196. 'core-js/modules/es.array.slice': 178,
  53197. 'core-js/modules/es.object.to-string': 192,
  53198. 'core-js/modules/es.regexp.constructor': 195,
  53199. 'core-js/modules/es.regexp.exec': 196,
  53200. 'core-js/modules/es.regexp.to-string': 197,
  53201. 'core-js/modules/es.string.trim': 208
  53202. }
  53203. ],
  53204. 271: [
  53205. function(_dereq_, module, exports) {
  53206. 'use strict';
  53207. function _typeof(obj) {
  53208. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  53209. _typeof = function _typeof(obj) {
  53210. return typeof obj;
  53211. };
  53212. } else {
  53213. _typeof = function _typeof(obj) {
  53214. return obj &&
  53215. typeof Symbol === 'function' &&
  53216. obj.constructor === Symbol &&
  53217. obj !== Symbol.prototype
  53218. ? 'symbol'
  53219. : typeof obj;
  53220. };
  53221. }
  53222. return _typeof(obj);
  53223. }
  53224. _dereq_('core-js/modules/es.array.fill');
  53225. Object.defineProperty(exports, '__esModule', { value: true });
  53226. exports.default = void 0;
  53227. var _main = _interopRequireDefault(_dereq_('../core/main'));
  53228. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  53229. _dereq_('./p5.Color');
  53230. function _getRequireWildcardCache() {
  53231. if (typeof WeakMap !== 'function') return null;
  53232. var cache = new WeakMap();
  53233. _getRequireWildcardCache = function _getRequireWildcardCache() {
  53234. return cache;
  53235. };
  53236. return cache;
  53237. }
  53238. function _interopRequireWildcard(obj) {
  53239. if (obj && obj.__esModule) {
  53240. return obj;
  53241. }
  53242. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  53243. return { default: obj };
  53244. }
  53245. var cache = _getRequireWildcardCache();
  53246. if (cache && cache.has(obj)) {
  53247. return cache.get(obj);
  53248. }
  53249. var newObj = {};
  53250. var hasPropertyDescriptor =
  53251. Object.defineProperty && Object.getOwnPropertyDescriptor;
  53252. for (var key in obj) {
  53253. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  53254. var desc = hasPropertyDescriptor
  53255. ? Object.getOwnPropertyDescriptor(obj, key)
  53256. : null;
  53257. if (desc && (desc.get || desc.set)) {
  53258. Object.defineProperty(newObj, key, desc);
  53259. } else {
  53260. newObj[key] = obj[key];
  53261. }
  53262. }
  53263. }
  53264. newObj.default = obj;
  53265. if (cache) {
  53266. cache.set(obj, newObj);
  53267. }
  53268. return newObj;
  53269. }
  53270. function _interopRequireDefault(obj) {
  53271. return obj && obj.__esModule ? obj : { default: obj };
  53272. } /**
  53273. * @method background
  53274. * @param {Number} gray specifies a value between white and black
  53275. * @param {Number} [a]
  53276. * @chainable
  53277. */ /**
  53278. * @module Color
  53279. * @submodule Setting
  53280. * @for p5
  53281. * @requires core
  53282. * @requires constants
  53283. */ /**
  53284. * The <a href="#/p5/background">background()</a> function sets the color used
  53285. * for the background of the p5.js canvas. The default background is transparent.
  53286. * This function is typically used within <a href="#/p5/draw">draw()</a> to clear
  53287. * the display window at the beginning of each frame, but it can be used inside
  53288. * <a href="#/p5/setup">setup()</a> to set the background on the first frame of
  53289. * animation or if the background need only be set once.
  53290. *
  53291. * The color is either specified in terms of the RGB, HSB, or HSL color depending
  53292. * on the current <a href="#/p5/colorMode">colorMode</a>. (The default color space
  53293. * is RGB, with each value in the range from 0 to 255). The alpha range by default
  53294. * is also 0 to 255.<br><br>
  53295. *
  53296. * If a single string argument is provided, RGB, RGBA and Hex CSS color strings
  53297. * and all named color strings are supported. In this case, an alpha number
  53298. * value as a second argument is not supported, the RGBA form should be used.
  53299. *
  53300. * A <a href="#/p5.Color">p5.Color</a> object can also be provided to set the background color.
  53301. *
  53302. * A <a href="#/p5.Image">p5.Image</a> can also be provided to set the background image.
  53303. *
  53304. * @method background
  53305. * @param {p5.Color} color any value created by the <a href="#/p5/color">color()</a> function
  53306. * @chainable
  53307. *
  53308. * @example
  53309. * <div>
  53310. * <code>
  53311. * // Grayscale integer value
  53312. * background(51);
  53313. * </code>
  53314. * </div>
  53315. *
  53316. * <div>
  53317. * <code>
  53318. * // R, G & B integer values
  53319. * background(255, 204, 0);
  53320. * </code>
  53321. * </div>
  53322. *
  53323. * <div>
  53324. * <code>
  53325. * // H, S & B integer values
  53326. * colorMode(HSB);
  53327. * background(255, 204, 100);
  53328. * </code>
  53329. * </div>
  53330. *
  53331. * <div>
  53332. * <code>
  53333. * // Named SVG/CSS color string
  53334. * background('red');
  53335. * </code>
  53336. * </div>
  53337. *
  53338. * <div>
  53339. * <code>
  53340. * // three-digit hexadecimal RGB notation
  53341. * background('#fae');
  53342. * </code>
  53343. * </div>
  53344. *
  53345. * <div>
  53346. * <code>
  53347. * // six-digit hexadecimal RGB notation
  53348. * background('#222222');
  53349. * </code>
  53350. * </div>
  53351. *
  53352. * <div>
  53353. * <code>
  53354. * // integer RGB notation
  53355. * background('rgb(0,255,0)');
  53356. * </code>
  53357. * </div>
  53358. *
  53359. * <div>
  53360. * <code>
  53361. * // integer RGBA notation
  53362. * background('rgba(0,255,0, 0.25)');
  53363. * </code>
  53364. * </div>
  53365. *
  53366. * <div>
  53367. * <code>
  53368. * // percentage RGB notation
  53369. * background('rgb(100%,0%,10%)');
  53370. * </code>
  53371. * </div>
  53372. *
  53373. * <div>
  53374. * <code>
  53375. * // percentage RGBA notation
  53376. * background('rgba(100%,0%,100%,0.5)');
  53377. * </code>
  53378. * </div>
  53379. *
  53380. * <div>
  53381. * <code>
  53382. * // p5 Color object
  53383. * background(color(0, 0, 255));
  53384. * </code>
  53385. * </div>
  53386. *
  53387. * @alt
  53388. * canvas with darkest charcoal grey background.
  53389. * canvas with yellow background.
  53390. * canvas with royal blue background.
  53391. * canvas with red background.
  53392. * canvas with pink background.
  53393. * canvas with black background.
  53394. * canvas with bright green background.
  53395. * canvas with soft green background.
  53396. * canvas with red background.
  53397. * canvas with light purple background.
  53398. * canvas with blue background.
  53399. */ /**
  53400. * @method background
  53401. * @param {String} colorstring color string, possible formats include: integer
  53402. * rgb() or rgba(), percentage rgb() or rgba(),
  53403. * 3-digit hex, 6-digit hex
  53404. * @param {Number} [a] opacity of the background relative to current
  53405. * color range (default is 0-255)
  53406. * @chainable
  53407. */
  53408. /**
  53409. * @method background
  53410. * @param {Number} v1 red or hue value (depending on the current color
  53411. * mode)
  53412. * @param {Number} v2 green or saturation value (depending on the current
  53413. * color mode)
  53414. * @param {Number} v3 blue or brightness value (depending on the current
  53415. * color mode)
  53416. * @param {Number} [a]
  53417. * @chainable
  53418. */
  53419. /**
  53420. * @method background
  53421. * @param {Number[]} values an array containing the red, green, blue
  53422. * and alpha components of the color
  53423. * @chainable
  53424. */
  53425. /**
  53426. * @method background
  53427. * @param {p5.Image} image image created with <a href="#/p5/loadImage">loadImage()</a> or <a href="#/p5/createImage">createImage()</a>,
  53428. * to set as background
  53429. * (must be same size as the sketch window)
  53430. * @param {Number} [a]
  53431. * @chainable
  53432. */
  53433. _main.default.prototype.background = function() {
  53434. var _this$_renderer;
  53435. (_this$_renderer = this._renderer).background.apply(_this$_renderer, arguments);
  53436. return this;
  53437. };
  53438. /**
  53439. * Clears the pixels within a buffer. This function only clears the canvas.
  53440. * It will not clear objects created by createX() methods such as
  53441. * <a href="#/p5/createVideo">createVideo()</a> or <a href="#/p5/createDiv">createDiv()</a>.
  53442. * Unlike the main graphics context, pixels in additional graphics areas created
  53443. * with <a href="#/p5/createGraphics">createGraphics()</a> can be entirely
  53444. * or partially transparent. This function clears everything to make all of
  53445. * the pixels 100% transparent.
  53446. *
  53447. * @method clear
  53448. * @chainable
  53449. * @example
  53450. * <div>
  53451. * <code>
  53452. * // Clear the screen on mouse press.
  53453. * function draw() {
  53454. * ellipse(mouseX, mouseY, 20, 20);
  53455. * }
  53456. * function mousePressed() {
  53457. * clear();
  53458. * background(128);
  53459. * }
  53460. * </code>
  53461. * </div>
  53462. *
  53463. * @alt
  53464. * small white ellipses are continually drawn at mouse's x and y coordinates.
  53465. */
  53466. _main.default.prototype.clear = function() {
  53467. this._renderer.clear();
  53468. return this;
  53469. };
  53470. /**
  53471. * <a href="#/p5/colorMode">colorMode()</a> changes the way p5.js interprets
  53472. * color data. By default, the parameters for <a href="#/p5/fill">fill()</a>,
  53473. * <a href="#/p5/stroke">stroke()</a>, <a href="#/p5/background">background()</a>,
  53474. * and <a href="#/p5/color">color()</a> are defined by values between 0 and 255
  53475. * using the RGB color model. This is equivalent to setting colorMode(RGB, 255).
  53476. * Setting colorMode(HSB) lets you use the HSB system instead. By default, this
  53477. * is colorMode(HSB, 360, 100, 100, 1). You can also use HSL.
  53478. *
  53479. * Note: existing color objects remember the mode that they were created in,
  53480. * so you can change modes as you like without affecting their appearance.
  53481. *
  53482. * @method colorMode
  53483. * @param {Constant} mode either RGB, HSB or HSL, corresponding to
  53484. * Red/Green/Blue and Hue/Saturation/Brightness
  53485. * (or Lightness)
  53486. * @param {Number} [max] range for all values
  53487. * @chainable
  53488. *
  53489. * @example
  53490. * <div>
  53491. * <code>
  53492. * noStroke();
  53493. * colorMode(RGB, 100);
  53494. * for (let i = 0; i < 100; i++) {
  53495. * for (let j = 0; j < 100; j++) {
  53496. * stroke(i, j, 0);
  53497. * point(i, j);
  53498. * }
  53499. * }
  53500. * </code>
  53501. * </div>
  53502. *
  53503. * <div>
  53504. * <code>
  53505. * noStroke();
  53506. * colorMode(HSB, 100);
  53507. * for (let i = 0; i < 100; i++) {
  53508. * for (let j = 0; j < 100; j++) {
  53509. * stroke(i, j, 100);
  53510. * point(i, j);
  53511. * }
  53512. * }
  53513. * </code>
  53514. * </div>
  53515. *
  53516. * <div>
  53517. * <code>
  53518. * colorMode(RGB, 255);
  53519. * let c = color(127, 255, 0);
  53520. * colorMode(RGB, 1);
  53521. * let myColor = c._getRed();
  53522. * text(myColor, 10, 10, 80, 80);
  53523. * </code>
  53524. * </div>
  53525. *
  53526. * <div>
  53527. * <code>
  53528. * noFill();
  53529. * colorMode(RGB, 255, 255, 255, 1);
  53530. * background(255);
  53531. * strokeWeight(4);
  53532. * stroke(255, 0, 10, 0.3);
  53533. * ellipse(40, 40, 50, 50);
  53534. * ellipse(50, 50, 40, 40);
  53535. * </code>
  53536. * </div>
  53537. *
  53538. * @alt
  53539. *Green to red gradient from bottom L to top R. shading originates from top left.
  53540. *Rainbow gradient from left to right. Brightness increasing to white at top.
  53541. *unknown image.
  53542. *50x50 ellipse at middle L & 40x40 ellipse at center. Translucent pink outlines.
  53543. */
  53544. /**
  53545. * @method colorMode
  53546. * @param {Constant} mode
  53547. * @param {Number} max1 range for the red or hue depending on the
  53548. * current color mode
  53549. * @param {Number} max2 range for the green or saturation depending
  53550. * on the current color mode
  53551. * @param {Number} max3 range for the blue or brightness/lightness
  53552. * depending on the current color mode
  53553. * @param {Number} [maxA] range for the alpha
  53554. * @chainable
  53555. */
  53556. _main.default.prototype.colorMode = function(mode, max1, max2, max3, maxA) {
  53557. _main.default._validateParameters('colorMode', arguments);
  53558. if (
  53559. mode === constants.RGB ||
  53560. mode === constants.HSB ||
  53561. mode === constants.HSL
  53562. ) {
  53563. // Set color mode.
  53564. this._colorMode = mode;
  53565. // Set color maxes.
  53566. var maxes = this._colorMaxes[mode];
  53567. if (arguments.length === 2) {
  53568. maxes[0] = max1; // Red
  53569. maxes[1] = max1; // Green
  53570. maxes[2] = max1; // Blue
  53571. maxes[3] = max1; // Alpha
  53572. } else if (arguments.length === 4) {
  53573. maxes[0] = max1; // Red
  53574. maxes[1] = max2; // Green
  53575. maxes[2] = max3; // Blue
  53576. } else if (arguments.length === 5) {
  53577. maxes[0] = max1; // Red
  53578. maxes[1] = max2; // Green
  53579. maxes[2] = max3; // Blue
  53580. maxes[3] = maxA; // Alpha
  53581. }
  53582. }
  53583. return this;
  53584. };
  53585. /**
  53586. * Sets the color used to fill shapes. For example, if you run fill(204, 102, 0),
  53587. * all shapes drawn after the fill command will be filled with the color orange.
  53588. * This color is either specified in terms of the RGB or HSB color depending on
  53589. * the current <a href="#/p5/colorMode">colorMode()</a>. (The default color space
  53590. * is RGB, with each value in the range from 0 to 255). The alpha range by default
  53591. * is also 0 to 255.
  53592. *
  53593. * If a single string argument is provided, RGB, RGBA and Hex CSS color strings
  53594. * and all named color strings are supported. In this case, an alpha number
  53595. * value as a second argument is not supported, the RGBA form should be used.
  53596. *
  53597. * A p5 <a href="#/p5.Color">Color</a> object can also be provided to set the fill color.
  53598. *
  53599. * @method fill
  53600. * @param {Number} v1 red or hue value relative to
  53601. * the current color range
  53602. * @param {Number} v2 green or saturation value
  53603. * relative to the current color range
  53604. * @param {Number} v3 blue or brightness value
  53605. * relative to the current color range
  53606. * @param {Number} [alpha]
  53607. * @chainable
  53608. * @example
  53609. * <div>
  53610. * <code>
  53611. * // Grayscale integer value
  53612. * fill(51);
  53613. * rect(20, 20, 60, 60);
  53614. * </code>
  53615. * </div>
  53616. *
  53617. * <div>
  53618. * <code>
  53619. * // R, G & B integer values
  53620. * fill(255, 204, 0);
  53621. * rect(20, 20, 60, 60);
  53622. * </code>
  53623. * </div>
  53624. *
  53625. * <div>
  53626. * <code>
  53627. * // H, S & B integer values
  53628. * colorMode(HSB);
  53629. * fill(255, 204, 100);
  53630. * rect(20, 20, 60, 60);
  53631. * </code>
  53632. * </div>
  53633. *
  53634. * <div>
  53635. * <code>
  53636. * // Named SVG/CSS color string
  53637. * fill('red');
  53638. * rect(20, 20, 60, 60);
  53639. * </code>
  53640. * </div>
  53641. *
  53642. * <div>
  53643. * <code>
  53644. * // three-digit hexadecimal RGB notation
  53645. * fill('#fae');
  53646. * rect(20, 20, 60, 60);
  53647. * </code>
  53648. * </div>
  53649. *
  53650. * <div>
  53651. * <code>
  53652. * // six-digit hexadecimal RGB notation
  53653. * fill('#222222');
  53654. * rect(20, 20, 60, 60);
  53655. * </code>
  53656. * </div>
  53657. *
  53658. * <div>
  53659. * <code>
  53660. * // integer RGB notation
  53661. * fill('rgb(0,255,0)');
  53662. * rect(20, 20, 60, 60);
  53663. * </code>
  53664. * </div>
  53665. *
  53666. * <div>
  53667. * <code>
  53668. * // integer RGBA notation
  53669. * fill('rgba(0,255,0, 0.25)');
  53670. * rect(20, 20, 60, 60);
  53671. * </code>
  53672. * </div>
  53673. *
  53674. * <div>
  53675. * <code>
  53676. * // percentage RGB notation
  53677. * fill('rgb(100%,0%,10%)');
  53678. * rect(20, 20, 60, 60);
  53679. * </code>
  53680. * </div>
  53681. *
  53682. * <div>
  53683. * <code>
  53684. * // percentage RGBA notation
  53685. * fill('rgba(100%,0%,100%,0.5)');
  53686. * rect(20, 20, 60, 60);
  53687. * </code>
  53688. * </div>
  53689. *
  53690. * <div>
  53691. * <code>
  53692. * // p5 Color object
  53693. * fill(color(0, 0, 255));
  53694. * rect(20, 20, 60, 60);
  53695. * </code>
  53696. * </div>
  53697. *
  53698. * @alt
  53699. * 60x60 dark charcoal grey rect with black outline in center of canvas.
  53700. * 60x60 yellow rect with black outline in center of canvas.
  53701. * 60x60 royal blue rect with black outline in center of canvas.
  53702. * 60x60 red rect with black outline in center of canvas.
  53703. * 60x60 pink rect with black outline in center of canvas.
  53704. * 60x60 black rect with black outline in center of canvas.
  53705. * 60x60 light green rect with black outline in center of canvas.
  53706. * 60x60 soft green rect with black outline in center of canvas.
  53707. * 60x60 red rect with black outline in center of canvas.
  53708. * 60x60 dark fuchsia rect with black outline in center of canvas.
  53709. * 60x60 blue rect with black outline in center of canvas.
  53710. */
  53711. /**
  53712. * @method fill
  53713. * @param {String} value a color string
  53714. * @chainable
  53715. */
  53716. /**
  53717. * @method fill
  53718. * @param {Number} gray a gray value
  53719. * @param {Number} [alpha]
  53720. * @chainable
  53721. */
  53722. /**
  53723. * @method fill
  53724. * @param {Number[]} values an array containing the red,green,blue &
  53725. * and alpha components of the color
  53726. * @chainable
  53727. */
  53728. /**
  53729. * @method fill
  53730. * @param {p5.Color} color the fill color
  53731. * @chainable
  53732. */
  53733. _main.default.prototype.fill = function() {
  53734. var _this$_renderer2;
  53735. this._renderer._setProperty('_fillSet', true);
  53736. this._renderer._setProperty('_doFill', true);
  53737. (_this$_renderer2 = this._renderer).fill.apply(_this$_renderer2, arguments);
  53738. return this;
  53739. };
  53740. /**
  53741. * Disables filling geometry. If both <a href="#/p5/noStroke">noStroke()</a> and <a href="#/p5/noFill">noFill()</a> are called,
  53742. * nothing will be drawn to the screen.
  53743. *
  53744. * @method noFill
  53745. * @chainable
  53746. * @example
  53747. * <div>
  53748. * <code>
  53749. * rect(15, 10, 55, 55);
  53750. * noFill();
  53751. * rect(20, 20, 60, 60);
  53752. * </code>
  53753. * </div>
  53754. *
  53755. * <div modernizr='webgl'>
  53756. * <code>
  53757. * function setup() {
  53758. * createCanvas(100, 100, WEBGL);
  53759. * }
  53760. *
  53761. * function draw() {
  53762. * background(0);
  53763. * noFill();
  53764. * stroke(100, 100, 240);
  53765. * rotateX(frameCount * 0.01);
  53766. * rotateY(frameCount * 0.01);
  53767. * box(45, 45, 45);
  53768. * }
  53769. * </code>
  53770. * </div>
  53771. *
  53772. * @alt
  53773. * white rect top middle and noFill rect center. Both 60x60 with black outlines.
  53774. * black canvas with purple cube wireframe spinning
  53775. */
  53776. _main.default.prototype.noFill = function() {
  53777. this._renderer._setProperty('_doFill', false);
  53778. return this;
  53779. };
  53780. /**
  53781. * Disables drawing the stroke (outline). If both <a href="#/p5/noStroke">noStroke()</a> and <a href="#/p5/noFill">noFill()</a>
  53782. * are called, nothing will be drawn to the screen.
  53783. *
  53784. * @method noStroke
  53785. * @chainable
  53786. * @example
  53787. * <div>
  53788. * <code>
  53789. * noStroke();
  53790. * rect(20, 20, 60, 60);
  53791. * </code>
  53792. * </div>
  53793. *
  53794. * <div modernizr='webgl'>
  53795. * <code>
  53796. * function setup() {
  53797. * createCanvas(100, 100, WEBGL);
  53798. * }
  53799. *
  53800. * function draw() {
  53801. * background(0);
  53802. * noStroke();
  53803. * fill(240, 150, 150);
  53804. * rotateX(frameCount * 0.01);
  53805. * rotateY(frameCount * 0.01);
  53806. * box(45, 45, 45);
  53807. * }
  53808. * </code>
  53809. * </div>
  53810. *
  53811. * @alt
  53812. * 60x60 white rect at center. no outline.
  53813. * black canvas with pink cube spinning
  53814. */
  53815. _main.default.prototype.noStroke = function() {
  53816. this._renderer._setProperty('_doStroke', false);
  53817. return this;
  53818. };
  53819. /**
  53820. * Sets the color used to draw lines and borders around shapes. This color
  53821. * is either specified in terms of the RGB or HSB color depending on the
  53822. * current <a href="#/p5/colorMode">colorMode()</a> (the default color space
  53823. * is RGB, with each value in the range from 0 to 255). The alpha range by
  53824. * default is also 0 to 255.
  53825. *
  53826. * If a single string argument is provided, RGB, RGBA and Hex CSS color
  53827. * strings and all named color strings are supported. In this case, an alpha
  53828. * number value as a second argument is not supported, the RGBA form should be
  53829. * used.
  53830. *
  53831. * A p5 <a href="#/p5.Color">Color</a> object can also be provided to set the stroke color.
  53832. *
  53833. * @method stroke
  53834. * @param {Number} v1 red or hue value relative to
  53835. * the current color range
  53836. * @param {Number} v2 green or saturation value
  53837. * relative to the current color range
  53838. * @param {Number} v3 blue or brightness value
  53839. * relative to the current color range
  53840. * @param {Number} [alpha]
  53841. * @chainable
  53842. *
  53843. * @example
  53844. * <div>
  53845. * <code>
  53846. * // Grayscale integer value
  53847. * strokeWeight(4);
  53848. * stroke(51);
  53849. * rect(20, 20, 60, 60);
  53850. * </code>
  53851. * </div>
  53852. *
  53853. * <div>
  53854. * <code>
  53855. * // R, G & B integer values
  53856. * stroke(255, 204, 0);
  53857. * strokeWeight(4);
  53858. * rect(20, 20, 60, 60);
  53859. * </code>
  53860. * </div>
  53861. *
  53862. * <div>
  53863. * <code>
  53864. * // H, S & B integer values
  53865. * colorMode(HSB);
  53866. * strokeWeight(4);
  53867. * stroke(255, 204, 100);
  53868. * rect(20, 20, 60, 60);
  53869. * </code>
  53870. * </div>
  53871. *
  53872. * <div>
  53873. * <code>
  53874. * // Named SVG/CSS color string
  53875. * stroke('red');
  53876. * strokeWeight(4);
  53877. * rect(20, 20, 60, 60);
  53878. * </code>
  53879. * </div>
  53880. *
  53881. * <div>
  53882. * <code>
  53883. * // three-digit hexadecimal RGB notation
  53884. * stroke('#fae');
  53885. * strokeWeight(4);
  53886. * rect(20, 20, 60, 60);
  53887. * </code>
  53888. * </div>
  53889. *
  53890. * <div>
  53891. * <code>
  53892. * // six-digit hexadecimal RGB notation
  53893. * stroke('#222222');
  53894. * strokeWeight(4);
  53895. * rect(20, 20, 60, 60);
  53896. * </code>
  53897. * </div>
  53898. *
  53899. * <div>
  53900. * <code>
  53901. * // integer RGB notation
  53902. * stroke('rgb(0,255,0)');
  53903. * strokeWeight(4);
  53904. * rect(20, 20, 60, 60);
  53905. * </code>
  53906. * </div>
  53907. *
  53908. * <div>
  53909. * <code>
  53910. * // integer RGBA notation
  53911. * stroke('rgba(0,255,0,0.25)');
  53912. * strokeWeight(4);
  53913. * rect(20, 20, 60, 60);
  53914. * </code>
  53915. * </div>
  53916. *
  53917. * <div>
  53918. * <code>
  53919. * // percentage RGB notation
  53920. * stroke('rgb(100%,0%,10%)');
  53921. * strokeWeight(4);
  53922. * rect(20, 20, 60, 60);
  53923. * </code>
  53924. * </div>
  53925. *
  53926. * <div>
  53927. * <code>
  53928. * // percentage RGBA notation
  53929. * stroke('rgba(100%,0%,100%,0.5)');
  53930. * strokeWeight(4);
  53931. * rect(20, 20, 60, 60);
  53932. * </code>
  53933. * </div>
  53934. *
  53935. * <div>
  53936. * <code>
  53937. * // p5 Color object
  53938. * stroke(color(0, 0, 255));
  53939. * strokeWeight(4);
  53940. * rect(20, 20, 60, 60);
  53941. * </code>
  53942. * </div>
  53943. *
  53944. * @alt
  53945. * 60x60 white rect at center. Dark charcoal grey outline.
  53946. * 60x60 white rect at center. Yellow outline.
  53947. * 60x60 white rect at center. Royal blue outline.
  53948. * 60x60 white rect at center. Red outline.
  53949. * 60x60 white rect at center. Pink outline.
  53950. * 60x60 white rect at center. Black outline.
  53951. * 60x60 white rect at center. Bright green outline.
  53952. * 60x60 white rect at center. Soft green outline.
  53953. * 60x60 white rect at center. Red outline.
  53954. * 60x60 white rect at center. Dark fuchsia outline.
  53955. * 60x60 white rect at center. Blue outline.
  53956. */
  53957. /**
  53958. * @method stroke
  53959. * @param {String} value a color string
  53960. * @chainable
  53961. */
  53962. /**
  53963. * @method stroke
  53964. * @param {Number} gray a gray value
  53965. * @param {Number} [alpha]
  53966. * @chainable
  53967. */
  53968. /**
  53969. * @method stroke
  53970. * @param {Number[]} values an array containing the red,green,blue &
  53971. * and alpha components of the color
  53972. * @chainable
  53973. */
  53974. /**
  53975. * @method stroke
  53976. * @param {p5.Color} color the stroke color
  53977. * @chainable
  53978. */
  53979. _main.default.prototype.stroke = function() {
  53980. var _this$_renderer3;
  53981. this._renderer._setProperty('_strokeSet', true);
  53982. this._renderer._setProperty('_doStroke', true);
  53983. (_this$_renderer3 = this._renderer).stroke.apply(_this$_renderer3, arguments);
  53984. return this;
  53985. };
  53986. /**
  53987. * All drawing that follows <a href="#/p5/erase">erase()</a> will subtract from
  53988. * the canvas.Erased areas will reveal the web page underneath the canvas.Erasing
  53989. * can be canceled with <a href="#/p5/noErase">noErase()</a>.
  53990. *
  53991. * Drawing done with <a href="#/p5/image">image()</a> and <a href="#/p5/background">
  53992. * background()</a> in between <a href="#/p5/erase">erase()</a> and
  53993. * <a href="#/p5/noErase">noErase()</a> will not erase the canvas but works as usual.
  53994. *
  53995. * @method erase
  53996. * @param {Number} [strengthFill] A number (0-255) for the strength of erasing for a shape's fill.
  53997. * This will default to 255 when no argument is given, which
  53998. * is full strength.
  53999. * @param {Number} [strengthStroke] A number (0-255) for the strength of erasing for a shape's stroke.
  54000. * This will default to 255 when no argument is given, which
  54001. * is full strength.
  54002. *
  54003. * @chainable
  54004. * @example
  54005. * <div>
  54006. * <code>
  54007. * background(100, 100, 250);
  54008. * fill(250, 100, 100);
  54009. * rect(20, 20, 60, 60);
  54010. * erase();
  54011. * ellipse(25, 30, 30);
  54012. * noErase();
  54013. * </code>
  54014. * </div>
  54015. *
  54016. * <div>
  54017. * <code>
  54018. * background(150, 250, 150);
  54019. * fill(100, 100, 250);
  54020. * rect(20, 20, 60, 60);
  54021. * strokeWeight(5);
  54022. * erase(150, 255);
  54023. * triangle(50, 10, 70, 50, 90, 10);
  54024. * noErase();
  54025. * </code>
  54026. * </div>
  54027. *
  54028. * <div>
  54029. * <code>
  54030. * function setup() {
  54031. * smooth();
  54032. * createCanvas(100, 100, WEBGL);
  54033. * // Make a &lt;p&gt; element and put it behind the canvas
  54034. * let p = createP('I am a dom element');
  54035. * p.center();
  54036. * p.style('font-size', '20px');
  54037. * p.style('text-align', 'center');
  54038. * p.style('z-index', '-9999');
  54039. * }
  54040. *
  54041. * function draw() {
  54042. * background(250, 250, 150);
  54043. * fill(15, 195, 185);
  54044. * noStroke();
  54045. * sphere(30);
  54046. * erase();
  54047. * rotateY(frameCount * 0.02);
  54048. * translate(0, 0, 40);
  54049. * torus(15, 5);
  54050. * noErase();
  54051. * }
  54052. * </code>
  54053. * </div>
  54054. *
  54055. * @alt
  54056. * 60x60 centered pink rect, purple background. Elliptical area in top-left of rect is erased white.
  54057. * 60x60 centered purple rect, mint green background. Triangle in top-right is partially erased with fully erased outline.
  54058. * 60x60 centered teal sphere, yellow background. Torus rotating around sphere erases to reveal black text underneath.
  54059. */
  54060. _main.default.prototype.erase = function() {
  54061. var opacityFill =
  54062. arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 255;
  54063. var opacityStroke =
  54064. arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 255;
  54065. this._renderer.erase(opacityFill, opacityStroke);
  54066. return this;
  54067. };
  54068. /**
  54069. * Ends erasing that was started with <a href="#/p5/erase">erase()</a>.
  54070. * The <a href="#/p5/fill">fill()</a>, <a href="#/p5/stroke">stroke()</a>, and
  54071. * <a href="#/p5/blendMode">blendMode()</a> settings will return to what they were
  54072. * prior to calling <a href="#/p5/erase">erase()</a>.
  54073. *
  54074. * @method noErase
  54075. * @chainable
  54076. * @example
  54077. * <div>
  54078. * <code>
  54079. * background(235, 145, 15);
  54080. * noStroke();
  54081. * fill(30, 45, 220);
  54082. * rect(30, 10, 10, 80);
  54083. * erase();
  54084. * ellipse(50, 50, 60);
  54085. * noErase();
  54086. * rect(70, 10, 10, 80);
  54087. * </code>
  54088. * </div>
  54089. *
  54090. * @alt
  54091. * Orange background, with two tall blue rectangles. A centered ellipse erased the first blue rect but not the second.
  54092. */
  54093. _main.default.prototype.noErase = function() {
  54094. this._renderer.noErase();
  54095. return this;
  54096. };
  54097. var _default = _main.default;
  54098. exports.default = _default;
  54099. },
  54100. {
  54101. '../core/constants': 272,
  54102. '../core/main': 283,
  54103. './p5.Color': 270,
  54104. 'core-js/modules/es.array.fill': 168
  54105. }
  54106. ],
  54107. 272: [
  54108. function(_dereq_, module, exports) {
  54109. 'use strict';
  54110. Object.defineProperty(exports, '__esModule', { value: true });
  54111. exports.BEZIER = exports.QUADRATIC = exports.LINEAR = exports._CTX_MIDDLE = exports._DEFAULT_LEADMULT = exports._DEFAULT_TEXT_FILL = exports.WORD = exports.CHAR = exports.BOLDITALIC = exports.BOLD = exports.ITALIC = exports.NORMAL = exports.BLUR = exports.ERODE = exports.DILATE = exports.POSTERIZE = exports.INVERT = exports.OPAQUE = exports.GRAY = exports.THRESHOLD = exports.BURN = exports.DODGE = exports.SOFT_LIGHT = exports.HARD_LIGHT = exports.OVERLAY = exports.REPLACE = exports.SCREEN = exports.MULTIPLY = exports.EXCLUSION = exports.SUBTRACT = exports.DIFFERENCE = exports.LIGHTEST = exports.DARKEST = exports.ADD = exports.REMOVE = exports.BLEND = exports.UP_ARROW = exports.TAB = exports.SHIFT = exports.RIGHT_ARROW = exports.RETURN = exports.OPTION = exports.LEFT_ARROW = exports.ESCAPE = exports.ENTER = exports.DOWN_ARROW = exports.DELETE = exports.CONTROL = exports.BACKSPACE = exports.ALT = exports.AUTO = exports.HSL = exports.HSB = exports.RGB = exports.MITER = exports.BEVEL = exports.ROUND = exports.SQUARE = exports.PROJECT = exports.PIE = exports.CHORD = exports.OPEN = exports.CLOSE = exports.TESS = exports.QUAD_STRIP = exports.QUADS = exports.TRIANGLE_STRIP = exports.TRIANGLE_FAN = exports.TRIANGLES = exports.LINE_LOOP = exports.LINE_STRIP = exports.LINES = exports.POINTS = exports.BASELINE = exports.BOTTOM = exports.TOP = exports.CENTER = exports.LEFT = exports.RIGHT = exports.RADIUS = exports.CORNERS = exports.CORNER = exports.RAD_TO_DEG = exports.DEG_TO_RAD = exports.RADIANS = exports.DEGREES = exports.TWO_PI = exports.TAU = exports.QUARTER_PI = exports.PI = exports.HALF_PI = exports.WAIT = exports.TEXT = exports.MOVE = exports.HAND = exports.CROSS = exports.ARROW = exports.WEBGL = exports.P2D = exports.VERSION = void 0;
  54112. exports.FALLBACK = exports.LABEL = exports.AXES = exports.GRID = exports._DEFAULT_FILL = exports._DEFAULT_STROKE = exports.PORTRAIT = exports.LANDSCAPE = exports.MIRROR = exports.CLAMP = exports.REPEAT = exports.NEAREST = exports.IMAGE = exports.IMMEDIATE = exports.TEXTURE = exports.FILL = exports.STROKE = exports.CURVE = void 0; /**
  54113. * @module Constants
  54114. * @submodule Constants
  54115. * @for p5
  54116. */
  54117. var _PI = Math.PI;
  54118. /**
  54119. * Version of this p5.js.
  54120. * @property {String} VERSION
  54121. * @final
  54122. */
  54123. var VERSION = '1.4.0';
  54124. // GRAPHICS RENDERER
  54125. /**
  54126. * The default, two-dimensional renderer.
  54127. * @property {String} P2D
  54128. * @final
  54129. */ exports.VERSION = VERSION;
  54130. var P2D = 'p2d';
  54131. /**
  54132. * One of the two render modes in p5.js: P2D (default renderer) and WEBGL
  54133. * Enables 3D render by introducing the third dimension: Z
  54134. * @property {String} WEBGL
  54135. * @final
  54136. */ exports.P2D = P2D;
  54137. var WEBGL = 'webgl';
  54138. // ENVIRONMENT
  54139. /**
  54140. * @property {String} ARROW
  54141. * @final
  54142. */ exports.WEBGL = WEBGL;
  54143. var ARROW = 'default';
  54144. /**
  54145. * @property {String} CROSS
  54146. * @final
  54147. */ exports.ARROW = ARROW;
  54148. var CROSS = 'crosshair';
  54149. /**
  54150. * @property {String} HAND
  54151. * @final
  54152. */ exports.CROSS = CROSS;
  54153. var HAND = 'pointer';
  54154. /**
  54155. * @property {String} MOVE
  54156. * @final
  54157. */ exports.HAND = HAND;
  54158. var MOVE = 'move';
  54159. /**
  54160. * @property {String} TEXT
  54161. * @final
  54162. */ exports.MOVE = MOVE;
  54163. var TEXT = 'text';
  54164. /**
  54165. * @property {String} WAIT
  54166. * @final
  54167. */ exports.TEXT = TEXT;
  54168. var WAIT = 'wait';
  54169. // TRIGONOMETRY
  54170. /**
  54171. * HALF_PI is a mathematical constant with the value
  54172. * 1.57079632679489661923. It is half the ratio of the
  54173. * circumference of a circle to its diameter. It is useful in
  54174. * combination with the trigonometric functions <a href="#/p5/sin">sin()</a> and <a href="#/p5/cos">cos()</a>.
  54175. *
  54176. * @property {Number} HALF_PI
  54177. * @final
  54178. *
  54179. * @example
  54180. * <div><code>
  54181. * arc(50, 50, 80, 80, 0, HALF_PI);
  54182. * </code></div>
  54183. *
  54184. * @alt
  54185. * 80x80 white quarter-circle with curve toward bottom right of canvas.
  54186. */ exports.WAIT = WAIT;
  54187. var HALF_PI = _PI / 2;
  54188. /**
  54189. * PI is a mathematical constant with the value
  54190. * 3.14159265358979323846. It is the ratio of the circumference
  54191. * of a circle to its diameter. It is useful in combination with
  54192. * the trigonometric functions <a href="#/p5/sin">sin()</a> and <a href="#/p5/cos">cos()</a>.
  54193. *
  54194. * @property {Number} PI
  54195. * @final
  54196. *
  54197. * @example
  54198. * <div><code>
  54199. * arc(50, 50, 80, 80, 0, PI);
  54200. * </code></div>
  54201. *
  54202. * @alt
  54203. * white half-circle with curve toward bottom of canvas.
  54204. */ exports.HALF_PI = HALF_PI;
  54205. var PI = _PI;
  54206. /**
  54207. * QUARTER_PI is a mathematical constant with the value 0.7853982.
  54208. * It is one quarter the ratio of the circumference of a circle to
  54209. * its diameter. It is useful in combination with the trigonometric
  54210. * functions <a href="#/p5/sin">sin()</a> and <a href="#/p5/cos">cos()</a>.
  54211. *
  54212. * @property {Number} QUARTER_PI
  54213. * @final
  54214. *
  54215. * @example
  54216. * <div><code>
  54217. * arc(50, 50, 80, 80, 0, QUARTER_PI);
  54218. * </code></div>
  54219. *
  54220. * @alt
  54221. * white eighth-circle rotated about 40 degrees with curve bottom right canvas.
  54222. */ exports.PI = PI;
  54223. var QUARTER_PI = _PI / 4;
  54224. /**
  54225. * TAU is an alias for TWO_PI, a mathematical constant with the
  54226. * value 6.28318530717958647693. It is twice the ratio of the
  54227. * circumference of a circle to its diameter. It is useful in
  54228. * combination with the trigonometric functions <a href="#/p5/sin">sin()</a> and <a href="#/p5/cos">cos()</a>.
  54229. *
  54230. * @property {Number} TAU
  54231. * @final
  54232. *
  54233. * @example
  54234. * <div><code>
  54235. * arc(50, 50, 80, 80, 0, TAU);
  54236. * </code></div>
  54237. *
  54238. * @alt
  54239. * 80x80 white ellipse shape in center of canvas.
  54240. */ exports.QUARTER_PI = QUARTER_PI;
  54241. var TAU = _PI * 2;
  54242. /**
  54243. * TWO_PI is a mathematical constant with the value
  54244. * 6.28318530717958647693. It is twice the ratio of the
  54245. * circumference of a circle to its diameter. It is useful in
  54246. * combination with the trigonometric functions <a href="#/p5/sin">sin()</a> and <a href="#/p5/cos">cos()</a>.
  54247. *
  54248. * @property {Number} TWO_PI
  54249. * @final
  54250. *
  54251. * @example
  54252. * <div><code>
  54253. * arc(50, 50, 80, 80, 0, TWO_PI);
  54254. * </code></div>
  54255. *
  54256. * @alt
  54257. * 80x80 white ellipse shape in center of canvas.
  54258. */ exports.TAU = TAU;
  54259. var TWO_PI = _PI * 2;
  54260. /**
  54261. * Constant to be used with <a href="#/p5/angleMode">angleMode()</a> function, to set the mode which
  54262. * p5.js interprets and calculates angles (either DEGREES or RADIANS).
  54263. * @property {String} DEGREES
  54264. * @final
  54265. *
  54266. * @example
  54267. * <div class='norender'><code>
  54268. * function setup() {
  54269. * angleMode(DEGREES);
  54270. * }
  54271. * </code></div>
  54272. */ exports.TWO_PI = TWO_PI;
  54273. var DEGREES = 'degrees';
  54274. /**
  54275. * Constant to be used with <a href="#/p5/angleMode">angleMode()</a> function, to set the mode which
  54276. * p5.js interprets and calculates angles (either RADIANS or DEGREES).
  54277. * @property {String} RADIANS
  54278. * @final
  54279. *
  54280. * @example
  54281. * <div class='norender'><code>
  54282. * function setup() {
  54283. * angleMode(RADIANS);
  54284. * }
  54285. * </code></div>
  54286. */ exports.DEGREES = DEGREES;
  54287. var RADIANS = 'radians';
  54288. exports.RADIANS = RADIANS;
  54289. var DEG_TO_RAD = _PI / 180.0;
  54290. exports.DEG_TO_RAD = DEG_TO_RAD;
  54291. var RAD_TO_DEG = 180.0 / _PI;
  54292. // SHAPE
  54293. /**
  54294. * @property {String} CORNER
  54295. * @final
  54296. */ exports.RAD_TO_DEG = RAD_TO_DEG;
  54297. var CORNER = 'corner';
  54298. /**
  54299. * @property {String} CORNERS
  54300. * @final
  54301. */ exports.CORNER = CORNER;
  54302. var CORNERS = 'corners';
  54303. /**
  54304. * @property {String} RADIUS
  54305. * @final
  54306. */ exports.CORNERS = CORNERS;
  54307. var RADIUS = 'radius';
  54308. /**
  54309. * @property {String} RIGHT
  54310. * @final
  54311. */ exports.RADIUS = RADIUS;
  54312. var RIGHT = 'right';
  54313. /**
  54314. * @property {String} LEFT
  54315. * @final
  54316. */ exports.RIGHT = RIGHT;
  54317. var LEFT = 'left';
  54318. /**
  54319. * @property {String} CENTER
  54320. * @final
  54321. */ exports.LEFT = LEFT;
  54322. var CENTER = 'center';
  54323. /**
  54324. * @property {String} TOP
  54325. * @final
  54326. */ exports.CENTER = CENTER;
  54327. var TOP = 'top';
  54328. /**
  54329. * @property {String} BOTTOM
  54330. * @final
  54331. */ exports.TOP = TOP;
  54332. var BOTTOM = 'bottom';
  54333. /**
  54334. * @property {String} BASELINE
  54335. * @final
  54336. * @default alphabetic
  54337. */ exports.BOTTOM = BOTTOM;
  54338. var BASELINE = 'alphabetic';
  54339. /**
  54340. * @property {Number} POINTS
  54341. * @final
  54342. * @default 0x0000
  54343. */ exports.BASELINE = BASELINE;
  54344. var POINTS = 0x0000;
  54345. /**
  54346. * @property {Number} LINES
  54347. * @final
  54348. * @default 0x0001
  54349. */ exports.POINTS = POINTS;
  54350. var LINES = 0x0001;
  54351. /**
  54352. * @property {Number} LINE_STRIP
  54353. * @final
  54354. * @default 0x0003
  54355. */ exports.LINES = LINES;
  54356. var LINE_STRIP = 0x0003;
  54357. /**
  54358. * @property {Number} LINE_LOOP
  54359. * @final
  54360. * @default 0x0002
  54361. */ exports.LINE_STRIP = LINE_STRIP;
  54362. var LINE_LOOP = 0x0002;
  54363. /**
  54364. * @property {Number} TRIANGLES
  54365. * @final
  54366. * @default 0x0004
  54367. */ exports.LINE_LOOP = LINE_LOOP;
  54368. var TRIANGLES = 0x0004;
  54369. /**
  54370. * @property {Number} TRIANGLE_FAN
  54371. * @final
  54372. * @default 0x0006
  54373. */ exports.TRIANGLES = TRIANGLES;
  54374. var TRIANGLE_FAN = 0x0006;
  54375. /**
  54376. * @property {Number} TRIANGLE_STRIP
  54377. * @final
  54378. * @default 0x0005
  54379. */ exports.TRIANGLE_FAN = TRIANGLE_FAN;
  54380. var TRIANGLE_STRIP = 0x0005;
  54381. /**
  54382. * @property {String} QUADS
  54383. * @final
  54384. */ exports.TRIANGLE_STRIP = TRIANGLE_STRIP;
  54385. var QUADS = 'quads';
  54386. /**
  54387. * @property {String} QUAD_STRIP
  54388. * @final
  54389. * @default quad_strip
  54390. */ exports.QUADS = QUADS;
  54391. var QUAD_STRIP = 'quad_strip';
  54392. /**
  54393. * @property {String} TESS
  54394. * @final
  54395. * @default tess
  54396. */ exports.QUAD_STRIP = QUAD_STRIP;
  54397. var TESS = 'tess';
  54398. /**
  54399. * @property {String} CLOSE
  54400. * @final
  54401. */ exports.TESS = TESS;
  54402. var CLOSE = 'close';
  54403. /**
  54404. * @property {String} OPEN
  54405. * @final
  54406. */ exports.CLOSE = CLOSE;
  54407. var OPEN = 'open';
  54408. /**
  54409. * @property {String} CHORD
  54410. * @final
  54411. */ exports.OPEN = OPEN;
  54412. var CHORD = 'chord';
  54413. /**
  54414. * @property {String} PIE
  54415. * @final
  54416. */ exports.CHORD = CHORD;
  54417. var PIE = 'pie';
  54418. /**
  54419. * @property {String} PROJECT
  54420. * @final
  54421. * @default square
  54422. */ exports.PIE = PIE;
  54423. var PROJECT = 'square'; // PEND: careful this is counterintuitive
  54424. /**
  54425. * @property {String} SQUARE
  54426. * @final
  54427. * @default butt
  54428. */ exports.PROJECT = PROJECT;
  54429. var SQUARE = 'butt';
  54430. /**
  54431. * @property {String} ROUND
  54432. * @final
  54433. */ exports.SQUARE = SQUARE;
  54434. var ROUND = 'round';
  54435. /**
  54436. * @property {String} BEVEL
  54437. * @final
  54438. */ exports.ROUND = ROUND;
  54439. var BEVEL = 'bevel';
  54440. /**
  54441. * @property {String} MITER
  54442. * @final
  54443. */ exports.BEVEL = BEVEL;
  54444. var MITER = 'miter';
  54445. // COLOR
  54446. /**
  54447. * @property {String} RGB
  54448. * @final
  54449. */ exports.MITER = MITER;
  54450. var RGB = 'rgb';
  54451. /**
  54452. * HSB (hue, saturation, brightness) is a type of color model.
  54453. * You can learn more about it at
  54454. * <a href="https://learnui.design/blog/the-hsb-color-system-practicioners-primer.html">HSB</a>.
  54455. *
  54456. * @property {String} HSB
  54457. * @final
  54458. */ exports.RGB = RGB;
  54459. var HSB = 'hsb';
  54460. /**
  54461. * @property {String} HSL
  54462. * @final
  54463. */ exports.HSB = HSB;
  54464. var HSL = 'hsl';
  54465. // DOM EXTENSION
  54466. /**
  54467. * AUTO allows us to automatically set the width or height of an element (but not both),
  54468. * based on the current height and width of the element. Only one parameter can
  54469. * be passed to the <a href="/#/p5.Element/size">size</a> function as AUTO, at a time.
  54470. *
  54471. * @property {String} AUTO
  54472. * @final
  54473. */ exports.HSL = HSL;
  54474. var AUTO = 'auto';
  54475. /**
  54476. * @property {Number} ALT
  54477. * @final
  54478. */
  54479. // INPUT
  54480. exports.AUTO = AUTO;
  54481. var ALT = 18;
  54482. /**
  54483. * @property {Number} BACKSPACE
  54484. * @final
  54485. */ exports.ALT = ALT;
  54486. var BACKSPACE = 8;
  54487. /**
  54488. * @property {Number} CONTROL
  54489. * @final
  54490. */ exports.BACKSPACE = BACKSPACE;
  54491. var CONTROL = 17;
  54492. /**
  54493. * @property {Number} DELETE
  54494. * @final
  54495. */ exports.CONTROL = CONTROL;
  54496. var DELETE = 46;
  54497. /**
  54498. * @property {Number} DOWN_ARROW
  54499. * @final
  54500. */ exports.DELETE = DELETE;
  54501. var DOWN_ARROW = 40;
  54502. /**
  54503. * @property {Number} ENTER
  54504. * @final
  54505. */ exports.DOWN_ARROW = DOWN_ARROW;
  54506. var ENTER = 13;
  54507. /**
  54508. * @property {Number} ESCAPE
  54509. * @final
  54510. */ exports.ENTER = ENTER;
  54511. var ESCAPE = 27;
  54512. /**
  54513. * @property {Number} LEFT_ARROW
  54514. * @final
  54515. */ exports.ESCAPE = ESCAPE;
  54516. var LEFT_ARROW = 37;
  54517. /**
  54518. * @property {Number} OPTION
  54519. * @final
  54520. */ exports.LEFT_ARROW = LEFT_ARROW;
  54521. var OPTION = 18;
  54522. /**
  54523. * @property {Number} RETURN
  54524. * @final
  54525. */ exports.OPTION = OPTION;
  54526. var RETURN = 13;
  54527. /**
  54528. * @property {Number} RIGHT_ARROW
  54529. * @final
  54530. */ exports.RETURN = RETURN;
  54531. var RIGHT_ARROW = 39;
  54532. /**
  54533. * @property {Number} SHIFT
  54534. * @final
  54535. */ exports.RIGHT_ARROW = RIGHT_ARROW;
  54536. var SHIFT = 16;
  54537. /**
  54538. * @property {Number} TAB
  54539. * @final
  54540. */ exports.SHIFT = SHIFT;
  54541. var TAB = 9;
  54542. /**
  54543. * @property {Number} UP_ARROW
  54544. * @final
  54545. */ exports.TAB = TAB;
  54546. var UP_ARROW = 38;
  54547. // RENDERING
  54548. /**
  54549. * @property {String} BLEND
  54550. * @final
  54551. * @default source-over
  54552. */ exports.UP_ARROW = UP_ARROW;
  54553. var BLEND = 'source-over';
  54554. /**
  54555. * @property {String} REMOVE
  54556. * @final
  54557. * @default destination-out
  54558. */ exports.BLEND = BLEND;
  54559. var REMOVE = 'destination-out';
  54560. /**
  54561. * @property {String} ADD
  54562. * @final
  54563. * @default lighter
  54564. */ exports.REMOVE = REMOVE;
  54565. var ADD = 'lighter';
  54566. //ADD: 'add', //
  54567. //SUBTRACT: 'subtract', //
  54568. /**
  54569. * @property {String} DARKEST
  54570. * @final
  54571. */ exports.ADD = ADD;
  54572. var DARKEST = 'darken';
  54573. /**
  54574. * @property {String} LIGHTEST
  54575. * @final
  54576. * @default lighten
  54577. */ exports.DARKEST = DARKEST;
  54578. var LIGHTEST = 'lighten';
  54579. /**
  54580. * @property {String} DIFFERENCE
  54581. * @final
  54582. */ exports.LIGHTEST = LIGHTEST;
  54583. var DIFFERENCE = 'difference';
  54584. /**
  54585. * @property {String} SUBTRACT
  54586. * @final
  54587. */ exports.DIFFERENCE = DIFFERENCE;
  54588. var SUBTRACT = 'subtract';
  54589. /**
  54590. * @property {String} EXCLUSION
  54591. * @final
  54592. */ exports.SUBTRACT = SUBTRACT;
  54593. var EXCLUSION = 'exclusion';
  54594. /**
  54595. * @property {String} MULTIPLY
  54596. * @final
  54597. */ exports.EXCLUSION = EXCLUSION;
  54598. var MULTIPLY = 'multiply';
  54599. /**
  54600. * @property {String} SCREEN
  54601. * @final
  54602. */ exports.MULTIPLY = MULTIPLY;
  54603. var SCREEN = 'screen';
  54604. /**
  54605. * @property {String} REPLACE
  54606. * @final
  54607. * @default copy
  54608. */ exports.SCREEN = SCREEN;
  54609. var REPLACE = 'copy';
  54610. /**
  54611. * @property {String} OVERLAY
  54612. * @final
  54613. */ exports.REPLACE = REPLACE;
  54614. var OVERLAY = 'overlay';
  54615. /**
  54616. * @property {String} HARD_LIGHT
  54617. * @final
  54618. */ exports.OVERLAY = OVERLAY;
  54619. var HARD_LIGHT = 'hard-light';
  54620. /**
  54621. * @property {String} SOFT_LIGHT
  54622. * @final
  54623. */ exports.HARD_LIGHT = HARD_LIGHT;
  54624. var SOFT_LIGHT = 'soft-light';
  54625. /**
  54626. * @property {String} DODGE
  54627. * @final
  54628. * @default color-dodge
  54629. */ exports.SOFT_LIGHT = SOFT_LIGHT;
  54630. var DODGE = 'color-dodge';
  54631. /**
  54632. * @property {String} BURN
  54633. * @final
  54634. * @default color-burn
  54635. */ exports.DODGE = DODGE;
  54636. var BURN = 'color-burn';
  54637. // FILTERS
  54638. /**
  54639. * @property {String} THRESHOLD
  54640. * @final
  54641. */ exports.BURN = BURN;
  54642. var THRESHOLD = 'threshold';
  54643. /**
  54644. * @property {String} GRAY
  54645. * @final
  54646. */ exports.THRESHOLD = THRESHOLD;
  54647. var GRAY = 'gray';
  54648. /**
  54649. * @property {String} OPAQUE
  54650. * @final
  54651. */ exports.GRAY = GRAY;
  54652. var OPAQUE = 'opaque';
  54653. /**
  54654. * @property {String} INVERT
  54655. * @final
  54656. */ exports.OPAQUE = OPAQUE;
  54657. var INVERT = 'invert';
  54658. /**
  54659. * @property {String} POSTERIZE
  54660. * @final
  54661. */ exports.INVERT = INVERT;
  54662. var POSTERIZE = 'posterize';
  54663. /**
  54664. * @property {String} DILATE
  54665. * @final
  54666. */ exports.POSTERIZE = POSTERIZE;
  54667. var DILATE = 'dilate';
  54668. /**
  54669. * @property {String} ERODE
  54670. * @final
  54671. */ exports.DILATE = DILATE;
  54672. var ERODE = 'erode';
  54673. /**
  54674. * @property {String} BLUR
  54675. * @final
  54676. */ exports.ERODE = ERODE;
  54677. var BLUR = 'blur';
  54678. // TYPOGRAPHY
  54679. /**
  54680. * @property {String} NORMAL
  54681. * @final
  54682. */ exports.BLUR = BLUR;
  54683. var NORMAL = 'normal';
  54684. /**
  54685. * @property {String} ITALIC
  54686. * @final
  54687. */ exports.NORMAL = NORMAL;
  54688. var ITALIC = 'italic';
  54689. /**
  54690. * @property {String} BOLD
  54691. * @final
  54692. */ exports.ITALIC = ITALIC;
  54693. var BOLD = 'bold';
  54694. /**
  54695. * @property {String} BOLDITALIC
  54696. * @final
  54697. */ exports.BOLD = BOLD;
  54698. var BOLDITALIC = 'bold italic';
  54699. /**
  54700. * @property {String} CHAR
  54701. * @final
  54702. */ exports.BOLDITALIC = BOLDITALIC;
  54703. var CHAR = 'CHAR';
  54704. /**
  54705. * @property {String} WORD
  54706. * @final
  54707. */ exports.CHAR = CHAR;
  54708. var WORD = 'WORD';
  54709. // TYPOGRAPHY-INTERNAL
  54710. exports.WORD = WORD;
  54711. var _DEFAULT_TEXT_FILL = '#000000';
  54712. exports._DEFAULT_TEXT_FILL = _DEFAULT_TEXT_FILL;
  54713. var _DEFAULT_LEADMULT = 1.25;
  54714. exports._DEFAULT_LEADMULT = _DEFAULT_LEADMULT;
  54715. var _CTX_MIDDLE = 'middle';
  54716. // VERTICES
  54717. /**
  54718. * @property {String} LINEAR
  54719. * @final
  54720. */ exports._CTX_MIDDLE = _CTX_MIDDLE;
  54721. var LINEAR = 'linear';
  54722. /**
  54723. * @property {String} QUADRATIC
  54724. * @final
  54725. */ exports.LINEAR = LINEAR;
  54726. var QUADRATIC = 'quadratic';
  54727. /**
  54728. * @property {String} BEZIER
  54729. * @final
  54730. */ exports.QUADRATIC = QUADRATIC;
  54731. var BEZIER = 'bezier';
  54732. /**
  54733. * @property {String} CURVE
  54734. * @final
  54735. */ exports.BEZIER = BEZIER;
  54736. var CURVE = 'curve';
  54737. // WEBGL DRAWMODES
  54738. /**
  54739. * @property {String} STROKE
  54740. * @final
  54741. */ exports.CURVE = CURVE;
  54742. var STROKE = 'stroke';
  54743. /**
  54744. * @property {String} FILL
  54745. * @final
  54746. */ exports.STROKE = STROKE;
  54747. var FILL = 'fill';
  54748. /**
  54749. * @property {String} TEXTURE
  54750. * @final
  54751. */ exports.FILL = FILL;
  54752. var TEXTURE = 'texture';
  54753. /**
  54754. * @property {String} IMMEDIATE
  54755. * @final
  54756. */ exports.TEXTURE = TEXTURE;
  54757. var IMMEDIATE = 'immediate';
  54758. // WEBGL TEXTURE MODE
  54759. // NORMAL already exists for typography
  54760. /**
  54761. * @property {String} IMAGE
  54762. * @final
  54763. */ exports.IMMEDIATE = IMMEDIATE;
  54764. var IMAGE = 'image';
  54765. // WEBGL TEXTURE WRAP AND FILTERING
  54766. // LINEAR already exists above
  54767. /**
  54768. * @property {String} NEAREST
  54769. * @final
  54770. */ exports.IMAGE = IMAGE;
  54771. var NEAREST = 'nearest';
  54772. /**
  54773. * @property {String} REPEAT
  54774. * @final
  54775. */ exports.NEAREST = NEAREST;
  54776. var REPEAT = 'repeat';
  54777. /**
  54778. * @property {String} CLAMP
  54779. * @final
  54780. */ exports.REPEAT = REPEAT;
  54781. var CLAMP = 'clamp';
  54782. /**
  54783. * @property {String} MIRROR
  54784. * @final
  54785. */ exports.CLAMP = CLAMP;
  54786. var MIRROR = 'mirror';
  54787. // DEVICE-ORIENTATION
  54788. /**
  54789. * @property {String} LANDSCAPE
  54790. * @final
  54791. */ exports.MIRROR = MIRROR;
  54792. var LANDSCAPE = 'landscape';
  54793. /**
  54794. * @property {String} PORTRAIT
  54795. * @final
  54796. */ exports.LANDSCAPE = LANDSCAPE;
  54797. var PORTRAIT = 'portrait';
  54798. // DEFAULTS
  54799. exports.PORTRAIT = PORTRAIT;
  54800. var _DEFAULT_STROKE = '#000000';
  54801. exports._DEFAULT_STROKE = _DEFAULT_STROKE;
  54802. var _DEFAULT_FILL = '#FFFFFF';
  54803. /**
  54804. * @property {String} GRID
  54805. * @final
  54806. */ exports._DEFAULT_FILL = _DEFAULT_FILL;
  54807. var GRID = 'grid';
  54808. /**
  54809. * @property {String} AXES
  54810. * @final
  54811. */ exports.GRID = GRID;
  54812. var AXES = 'axes';
  54813. /**
  54814. * @property {String} LABEL
  54815. * @final
  54816. */ exports.AXES = AXES;
  54817. var LABEL = 'label';
  54818. /**
  54819. * @property {String} FALLBACK
  54820. * @final
  54821. */ exports.LABEL = LABEL;
  54822. var FALLBACK = 'fallback';
  54823. exports.FALLBACK = FALLBACK;
  54824. },
  54825. {}
  54826. ],
  54827. 273: [
  54828. function(_dereq_, module, exports) {
  54829. 'use strict';
  54830. function _typeof(obj) {
  54831. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  54832. _typeof = function _typeof(obj) {
  54833. return typeof obj;
  54834. };
  54835. } else {
  54836. _typeof = function _typeof(obj) {
  54837. return obj &&
  54838. typeof Symbol === 'function' &&
  54839. obj.constructor === Symbol &&
  54840. obj !== Symbol.prototype
  54841. ? 'symbol'
  54842. : typeof obj;
  54843. };
  54844. }
  54845. return _typeof(obj);
  54846. }
  54847. _dereq_('core-js/modules/es.array.concat');
  54848. _dereq_('core-js/modules/es.array.filter');
  54849. _dereq_('core-js/modules/es.array.includes');
  54850. _dereq_('core-js/modules/es.regexp.exec');
  54851. _dereq_('core-js/modules/es.string.includes');
  54852. _dereq_('core-js/modules/es.string.search');
  54853. _dereq_('core-js/modules/es.string.split');
  54854. Object.defineProperty(exports, '__esModule', { value: true });
  54855. exports.default = void 0;
  54856. var _main = _interopRequireDefault(_dereq_('./main'));
  54857. var C = _interopRequireWildcard(_dereq_('./constants'));
  54858. function _getRequireWildcardCache() {
  54859. if (typeof WeakMap !== 'function') return null;
  54860. var cache = new WeakMap();
  54861. _getRequireWildcardCache = function _getRequireWildcardCache() {
  54862. return cache;
  54863. };
  54864. return cache;
  54865. }
  54866. function _interopRequireWildcard(obj) {
  54867. if (obj && obj.__esModule) {
  54868. return obj;
  54869. }
  54870. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  54871. return { default: obj };
  54872. }
  54873. var cache = _getRequireWildcardCache();
  54874. if (cache && cache.has(obj)) {
  54875. return cache.get(obj);
  54876. }
  54877. var newObj = {};
  54878. var hasPropertyDescriptor =
  54879. Object.defineProperty && Object.getOwnPropertyDescriptor;
  54880. for (var key in obj) {
  54881. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  54882. var desc = hasPropertyDescriptor
  54883. ? Object.getOwnPropertyDescriptor(obj, key)
  54884. : null;
  54885. if (desc && (desc.get || desc.set)) {
  54886. Object.defineProperty(newObj, key, desc);
  54887. } else {
  54888. newObj[key] = obj[key];
  54889. }
  54890. }
  54891. }
  54892. newObj.default = obj;
  54893. if (cache) {
  54894. cache.set(obj, newObj);
  54895. }
  54896. return newObj;
  54897. }
  54898. function _interopRequireDefault(obj) {
  54899. return obj && obj.__esModule ? obj : { default: obj };
  54900. }
  54901. /**
  54902. * @module Environment
  54903. * @submodule Environment
  54904. * @for p5
  54905. * @requires core
  54906. * @requires constants
  54907. */ var standardCursors = [C.ARROW, C.CROSS, C.HAND, C.MOVE, C.TEXT, C.WAIT];
  54908. _main.default.prototype._frameRate = 0;
  54909. _main.default.prototype._lastFrameTime = window.performance.now();
  54910. _main.default.prototype._targetFrameRate = 60;
  54911. var _windowPrint = window.print;
  54912. /**
  54913. * The <a href="#/p5/print">print()</a> function writes to the console area of
  54914. * your browser. This function is often helpful for looking at the data a program
  54915. * is producing. This function creates a new line of text for each call to
  54916. * the function. Individual elements can be separated with quotes ("") and joined
  54917. * with the addition operator (+).
  54918. *
  54919. * Note that calling print() without any arguments invokes the window.print()
  54920. * function which opens the browser's print dialog. To print a blank line
  54921. * to console you can write print('\n').
  54922. *
  54923. * @method print
  54924. * @param {Any} contents any combination of Number, String, Object, Boolean,
  54925. * Array to print
  54926. * @example
  54927. * <div><code class='norender'>
  54928. * let x = 10;
  54929. * print('The value of x is ' + x);
  54930. * // prints "The value of x is 10"
  54931. * </code></div>
  54932. *
  54933. * @alt
  54934. * default grey canvas
  54935. */
  54936. _main.default.prototype.print = function() {
  54937. if (!arguments.length) {
  54938. _windowPrint();
  54939. } else {
  54940. var _console;
  54941. (_console = console).log.apply(_console, arguments);
  54942. }
  54943. };
  54944. /**
  54945. * The system variable <a href="#/p5/frameCount">frameCount</a> contains the
  54946. * number of frames that have been displayed since the program started. Inside
  54947. * <a href="#/p5/setup">setup()</a> the value is 0, after the first iteration
  54948. * of draw it is 1, etc.
  54949. *
  54950. * @property {Integer} frameCount
  54951. * @readOnly
  54952. * @example
  54953. * <div><code>
  54954. * function setup() {
  54955. * frameRate(30);
  54956. * textSize(30);
  54957. * textAlign(CENTER);
  54958. * }
  54959. *
  54960. * function draw() {
  54961. * background(200);
  54962. * text(frameCount, width / 2, height / 2);
  54963. * }
  54964. * </code></div>
  54965. *
  54966. * @alt
  54967. * numbers rapidly counting upward with frame count set to 30.
  54968. */
  54969. _main.default.prototype.frameCount = 0;
  54970. /**
  54971. * The system variable <a href="#/p5/deltaTime">deltaTime</a> contains the time
  54972. * difference between the beginning of the previous frame and the beginning
  54973. * of the current frame in milliseconds.
  54974. *
  54975. * This variable is useful for creating time sensitive animation or physics
  54976. * calculation that should stay constant regardless of frame rate.
  54977. *
  54978. * @property {Integer} deltaTime
  54979. * @readOnly
  54980. * @example
  54981. * <div><code>
  54982. * let rectX = 0;
  54983. * let fr = 30; //starting FPS
  54984. * let clr;
  54985. *
  54986. * function setup() {
  54987. * background(200);
  54988. * frameRate(fr); // Attempt to refresh at starting FPS
  54989. * clr = color(255, 0, 0);
  54990. * }
  54991. *
  54992. * function draw() {
  54993. * background(200);
  54994. * rectX = rectX + 1 * (deltaTime / 50); // Move Rectangle in relation to deltaTime
  54995. *
  54996. * if (rectX >= width) {
  54997. * // If you go off screen.
  54998. * if (fr === 30) {
  54999. * clr = color(0, 0, 255);
  55000. * fr = 10;
  55001. * frameRate(fr); // make frameRate 10 FPS
  55002. * } else {
  55003. * clr = color(255, 0, 0);
  55004. * fr = 30;
  55005. * frameRate(fr); // make frameRate 30 FPS
  55006. * }
  55007. * rectX = 0;
  55008. * }
  55009. * fill(clr);
  55010. * rect(rectX, 40, 20, 20);
  55011. * }
  55012. * </code></div>
  55013. *
  55014. * @alt
  55015. * red rect moves left to right, followed by blue rect moving at the same speed
  55016. * with a lower frame rate. Loops.
  55017. */
  55018. _main.default.prototype.deltaTime = 0;
  55019. /**
  55020. * Confirms if the window a p5.js program is in is "focused," meaning that
  55021. * the sketch will accept mouse or keyboard input. This variable is
  55022. * "true" if the window is focused and "false" if not.
  55023. *
  55024. * @property {Boolean} focused
  55025. * @readOnly
  55026. * @example
  55027. * <div><code>
  55028. * // To demonstrate, put two windows side by side.
  55029. * // Click on the window that the p5 sketch isn't in!
  55030. * function draw() {
  55031. * background(200);
  55032. * noStroke();
  55033. * fill(0, 200, 0);
  55034. * ellipse(25, 25, 50, 50);
  55035. *
  55036. * if (!focused) {
  55037. // or "if (focused === false)"
  55038. * stroke(200, 0, 0);
  55039. * line(0, 0, 100, 100);
  55040. * line(100, 0, 0, 100);
  55041. * }
  55042. * }
  55043. * </code></div>
  55044. *
  55045. * @alt
  55046. * green 50x50 ellipse at top left. Red X covers canvas when page focus changes
  55047. */
  55048. _main.default.prototype.focused = document.hasFocus();
  55049. /**
  55050. * Sets the cursor to a predefined symbol or an image, or makes it visible
  55051. * if already hidden. If you are trying to set an image as the cursor, the
  55052. * recommended size is 16x16 or 32x32 pixels. The values for parameters x and y
  55053. * must be less than the dimensions of the image.
  55054. *
  55055. * @method cursor
  55056. * @param {String|Constant} type Built-In: either ARROW, CROSS, HAND, MOVE, TEXT and WAIT
  55057. * Native CSS properties: 'grab', 'progress', 'cell' etc.
  55058. * External: path for cursor's images
  55059. * (Allowed File extensions: .cur, .gif, .jpg, .jpeg, .png)
  55060. * For more information on Native CSS cursors and url visit:
  55061. * https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
  55062. * @param {Number} [x] the horizontal active spot of the cursor (must be less than 32)
  55063. * @param {Number} [y] the vertical active spot of the cursor (must be less than 32)
  55064. * @example
  55065. * <div><code>
  55066. * // Move the mouse across the quadrants
  55067. * // to see the cursor change
  55068. * function draw() {
  55069. * line(width / 2, 0, width / 2, height);
  55070. * line(0, height / 2, width, height / 2);
  55071. * if (mouseX < 50 && mouseY < 50) {
  55072. * cursor(CROSS);
  55073. * } else if (mouseX > 50 && mouseY < 50) {
  55074. * cursor('progress');
  55075. * } else if (mouseX > 50 && mouseY > 50) {
  55076. * cursor('https://avatars0.githubusercontent.com/u/1617169?s=16');
  55077. * } else {
  55078. * cursor('grab');
  55079. * }
  55080. * }
  55081. * </code></div>
  55082. *
  55083. * @alt
  55084. * canvas is divided into four quadrants. cursor on first is a cross, second is a progress,
  55085. * third is a custom cursor using path to the cursor and fourth is a grab.
  55086. */
  55087. _main.default.prototype.cursor = function(type, x, y) {
  55088. var cursor = 'auto';
  55089. var canvas = this._curElement.elt;
  55090. if (standardCursors.includes(type)) {
  55091. // Standard css cursor
  55092. cursor = type;
  55093. } else if (typeof type === 'string') {
  55094. var coords = '';
  55095. if (x && y && typeof x === 'number' && typeof y === 'number') {
  55096. // Note that x and y values must be unit-less positive integers < 32
  55097. // https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
  55098. coords = ''.concat(x, ' ').concat(y);
  55099. }
  55100. if (
  55101. type.substring(0, 7) === 'http://' ||
  55102. type.substring(0, 8) === 'https://'
  55103. ) {
  55104. // Image (absolute url)
  55105. cursor = 'url('.concat(type, ') ').concat(coords, ', auto');
  55106. } else if (/\.(cur|jpg|jpeg|gif|png|CUR|JPG|JPEG|GIF|PNG)$/.test(type)) {
  55107. // Image file (relative path) - Separated for performance reasons
  55108. cursor = 'url('.concat(type, ') ').concat(coords, ', auto');
  55109. } else {
  55110. // Any valid string for the css cursor property
  55111. cursor = type;
  55112. }
  55113. }
  55114. canvas.style.cursor = cursor;
  55115. };
  55116. /**
  55117. * Specifies the number of frames to be displayed every second. For example,
  55118. * the function call frameRate(30) will attempt to refresh 30 times a second.
  55119. * If the processor is not fast enough to maintain the specified rate, the
  55120. * frame rate will not be achieved. Setting the frame rate within
  55121. * <a href="#/p5/setup">setup()</a> is recommended. The default frame rate is
  55122. * based on the frame rate of the display (here also called "refresh rate"),
  55123. * which is set to 60 frames per second on most computers. A frame rate of 24
  55124. * frames per second (usual for movies) or above will be enough for smooth
  55125. * animations. This is the same as setFrameRate(val).
  55126. *
  55127. * Calling <a href="#/p5/frameRate">frameRate()</a> with no arguments returns
  55128. * the current framerate. The draw function must run at least once before it will
  55129. * return a value. This is the same as <a href="#/p5/getFrameRate">getFrameRate()</a>.
  55130. *
  55131. * Calling <a href="#/p5/frameRate">frameRate()</a> with arguments that are not
  55132. * of the type numbers or are non positive also returns current framerate.
  55133. *
  55134. * @method frameRate
  55135. * @param {Number} fps number of frames to be displayed every second
  55136. * @chainable
  55137. *
  55138. * @example
  55139. *
  55140. * <div><code>
  55141. * let rectX = 0;
  55142. * let fr = 30; //starting FPS
  55143. * let clr;
  55144. *
  55145. * function setup() {
  55146. * background(200);
  55147. * frameRate(fr); // Attempt to refresh at starting FPS
  55148. * clr = color(255, 0, 0);
  55149. * }
  55150. *
  55151. * function draw() {
  55152. * background(200);
  55153. * rectX = rectX += 1; // Move Rectangle
  55154. *
  55155. * if (rectX >= width) {
  55156. // If you go off screen.
  55157. * if (fr === 30) {
  55158. * clr = color(0, 0, 255);
  55159. * fr = 10;
  55160. * frameRate(fr); // make frameRate 10 FPS
  55161. * } else {
  55162. * clr = color(255, 0, 0);
  55163. * fr = 30;
  55164. * frameRate(fr); // make frameRate 30 FPS
  55165. * }
  55166. * rectX = 0;
  55167. * }
  55168. * fill(clr);
  55169. * rect(rectX, 40, 20, 20);
  55170. * }
  55171. * </code></div>
  55172. *
  55173. * @alt
  55174. * blue rect moves left to right, followed by red rect moving faster. Loops.
  55175. */
  55176. /**
  55177. * @method frameRate
  55178. * @return {Number} current frameRate
  55179. */
  55180. _main.default.prototype.frameRate = function(fps) {
  55181. _main.default._validateParameters('frameRate', arguments);
  55182. if (typeof fps !== 'number' || fps < 0) {
  55183. return this._frameRate;
  55184. } else {
  55185. this._setProperty('_targetFrameRate', fps);
  55186. if (fps === 0) {
  55187. this._setProperty('_frameRate', fps);
  55188. }
  55189. return this;
  55190. }
  55191. };
  55192. /**
  55193. * Returns the current framerate.
  55194. *
  55195. * @private
  55196. * @return {Number} current frameRate
  55197. */
  55198. _main.default.prototype.getFrameRate = function() {
  55199. return this.frameRate();
  55200. };
  55201. /**
  55202. * Specifies the number of frames to be displayed every second. For example,
  55203. * the function call frameRate(30) will attempt to refresh 30 times a second.
  55204. * If the processor is not fast enough to maintain the specified rate, the
  55205. * frame rate will not be achieved. Setting the frame rate within <a href="#/p5/setup">setup()</a> is
  55206. * recommended. The default rate is 60 frames per second.
  55207. *
  55208. * Calling <a href="#/p5/frameRate">frameRate()</a> with no arguments returns the current framerate.
  55209. *
  55210. * @private
  55211. * @param {Number} [fps] number of frames to be displayed every second
  55212. */
  55213. _main.default.prototype.setFrameRate = function(fps) {
  55214. return this.frameRate(fps);
  55215. };
  55216. /**
  55217. * Hides the cursor from view.
  55218. *
  55219. * @method noCursor
  55220. * @example
  55221. * <div><code>
  55222. * function setup() {
  55223. * noCursor();
  55224. * }
  55225. *
  55226. * function draw() {
  55227. * background(200);
  55228. * ellipse(mouseX, mouseY, 10, 10);
  55229. * }
  55230. * </code></div>
  55231. *
  55232. * @alt
  55233. * cursor becomes 10x 10 white ellipse the moves with mouse x and y.
  55234. */
  55235. _main.default.prototype.noCursor = function() {
  55236. this._curElement.elt.style.cursor = 'none';
  55237. };
  55238. /**
  55239. * System variable that stores the width of the screen display according to The
  55240. * default <a href="#/p5/pixelDensity">pixelDensity</a>. This is used to run a
  55241. * full-screen program on any display size. To return actual screen size,
  55242. * multiply this by pixelDensity.
  55243. *
  55244. * @property {Number} displayWidth
  55245. * @readOnly
  55246. * @example
  55247. * <div class="norender"><code>
  55248. * createCanvas(displayWidth, displayHeight);
  55249. * </code></div>
  55250. *
  55251. * @alt
  55252. * This example does not render anything.
  55253. */
  55254. _main.default.prototype.displayWidth = screen.width;
  55255. /**
  55256. * System variable that stores the height of the screen display according to The
  55257. * default <a href="#/p5/pixelDensity">pixelDensity</a>. This is used to run a
  55258. * full-screen program on any display size. To return actual screen size,
  55259. * multiply this by pixelDensity.
  55260. *
  55261. * @property {Number} displayHeight
  55262. * @readOnly
  55263. * @example
  55264. * <div class="norender"><code>
  55265. * createCanvas(displayWidth, displayHeight);
  55266. * </code></div>
  55267. *
  55268. * @alt
  55269. * This example does not render anything.
  55270. */
  55271. _main.default.prototype.displayHeight = screen.height;
  55272. /**
  55273. * System variable that stores the width of the inner window, it maps to
  55274. * window.innerWidth.
  55275. *
  55276. * @property {Number} windowWidth
  55277. * @readOnly
  55278. * @example
  55279. * <div class="norender"><code>
  55280. * createCanvas(windowWidth, windowHeight);
  55281. * </code></div>
  55282. *
  55283. * @alt
  55284. * This example does not render anything.
  55285. */
  55286. _main.default.prototype.windowWidth = getWindowWidth();
  55287. /**
  55288. * System variable that stores the height of the inner window, it maps to
  55289. * window.innerHeight.
  55290. *
  55291. * @property {Number} windowHeight
  55292. * @readOnly
  55293. * @example
  55294. * <div class="norender"><code>
  55295. * createCanvas(windowWidth, windowHeight);
  55296. * </code></div>
  55297. *
  55298. * @alt
  55299. * This example does not render anything.
  55300. */
  55301. _main.default.prototype.windowHeight = getWindowHeight();
  55302. /**
  55303. * The <a href="#/p5/windowResized">windowResized()</a> function is called once
  55304. * every time the browser window is resized. This is a good place to resize the
  55305. * canvas or do any other adjustments to accommodate the new window size.
  55306. *
  55307. * @method windowResized
  55308. * @param {Object} [event] optional Event callback argument.
  55309. * @example
  55310. * <div class="norender"><code>
  55311. * function setup() {
  55312. * createCanvas(windowWidth, windowHeight);
  55313. * }
  55314. *
  55315. * function draw() {
  55316. * background(0, 100, 200);
  55317. * }
  55318. *
  55319. * function windowResized() {
  55320. * resizeCanvas(windowWidth, windowHeight);
  55321. * }
  55322. * </code></div>
  55323. * @alt
  55324. * This example does not render anything.
  55325. */
  55326. _main.default.prototype._onresize = function(e) {
  55327. this._setProperty('windowWidth', getWindowWidth());
  55328. this._setProperty('windowHeight', getWindowHeight());
  55329. var context = this._isGlobal ? window : this;
  55330. var executeDefault;
  55331. if (typeof context.windowResized === 'function') {
  55332. executeDefault = context.windowResized(e);
  55333. if (executeDefault !== undefined && !executeDefault) {
  55334. e.preventDefault();
  55335. }
  55336. }
  55337. };
  55338. function getWindowWidth() {
  55339. return (
  55340. window.innerWidth ||
  55341. (document.documentElement && document.documentElement.clientWidth) ||
  55342. (document.body && document.body.clientWidth) ||
  55343. 0
  55344. );
  55345. }
  55346. function getWindowHeight() {
  55347. return (
  55348. window.innerHeight ||
  55349. (document.documentElement && document.documentElement.clientHeight) ||
  55350. (document.body && document.body.clientHeight) ||
  55351. 0
  55352. );
  55353. }
  55354. /**
  55355. * System variable that stores the width of the drawing canvas. This value
  55356. * is set by the first parameter of the <a href="#/p5/createCanvas">createCanvas()</a> function.
  55357. * For example, the function call createCanvas(320, 240) sets the width
  55358. * variable to the value 320. The value of width defaults to 100 if
  55359. * <a href="#/p5/createCanvas">createCanvas()</a> is not used in a program.
  55360. *
  55361. * @property {Number} width
  55362. * @readOnly
  55363. */
  55364. _main.default.prototype.width = 0;
  55365. /**
  55366. * System variable that stores the height of the drawing canvas. This value
  55367. * is set by the second parameter of the <a href="#/p5/createCanvas">createCanvas()</a> function. For
  55368. * example, the function call createCanvas(320, 240) sets the height
  55369. * variable to the value 240. The value of height defaults to 100 if
  55370. * <a href="#/p5/createCanvas">createCanvas()</a> is not used in a program.
  55371. *
  55372. * @property {Number} height
  55373. * @readOnly
  55374. */
  55375. _main.default.prototype.height = 0;
  55376. /**
  55377. * If argument is given, sets the sketch to fullscreen or not based on the
  55378. * value of the argument. If no argument is given, returns the current
  55379. * fullscreen state. Note that due to browser restrictions this can only
  55380. * be called on user input, for example, on mouse press like the example
  55381. * below.
  55382. *
  55383. * @method fullscreen
  55384. * @param {Boolean} [val] whether the sketch should be in fullscreen mode
  55385. * or not
  55386. * @return {Boolean} current fullscreen state
  55387. * @example
  55388. * <div>
  55389. * <code>
  55390. * // Clicking in the box toggles fullscreen on and off.
  55391. * function setup() {
  55392. * background(200);
  55393. * }
  55394. * function mousePressed() {
  55395. * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
  55396. * let fs = fullscreen();
  55397. * fullscreen(!fs);
  55398. * }
  55399. * }
  55400. * </code>
  55401. * </div>
  55402. *
  55403. * @alt
  55404. * This example does not render anything.
  55405. */
  55406. _main.default.prototype.fullscreen = function(val) {
  55407. _main.default._validateParameters('fullscreen', arguments);
  55408. // no arguments, return fullscreen or not
  55409. if (typeof val === 'undefined') {
  55410. return (
  55411. document.fullscreenElement ||
  55412. document.webkitFullscreenElement ||
  55413. document.mozFullScreenElement ||
  55414. document.msFullscreenElement
  55415. );
  55416. } else {
  55417. // otherwise set to fullscreen or not
  55418. if (val) {
  55419. launchFullscreen(document.documentElement);
  55420. } else {
  55421. exitFullscreen();
  55422. }
  55423. }
  55424. };
  55425. /**
  55426. * Sets the pixel scaling for high pixel density displays. By default
  55427. * pixel density is set to match display density, call pixelDensity(1)
  55428. * to turn this off. Calling <a href="#/p5/pixelDensity">pixelDensity()</a> with no arguments returns
  55429. * the current pixel density of the sketch.
  55430. *
  55431. * @method pixelDensity
  55432. * @param {Number} val whether or how much the sketch should scale
  55433. * @chainable
  55434. * @example
  55435. * <div>
  55436. * <code>
  55437. * function setup() {
  55438. * pixelDensity(1);
  55439. * createCanvas(100, 100);
  55440. * background(200);
  55441. * ellipse(width / 2, height / 2, 50, 50);
  55442. * }
  55443. * </code>
  55444. * </div>
  55445. *
  55446. * <div>
  55447. * <code>
  55448. * function setup() {
  55449. * pixelDensity(3.0);
  55450. * createCanvas(100, 100);
  55451. * background(200);
  55452. * ellipse(width / 2, height / 2, 50, 50);
  55453. * }
  55454. * </code>
  55455. * </div>
  55456. *
  55457. * @alt
  55458. * fuzzy 50x50 white ellipse with black outline in center of canvas.
  55459. * sharp 50x50 white ellipse with black outline in center of canvas.
  55460. */
  55461. /**
  55462. * @method pixelDensity
  55463. * @returns {Number} current pixel density of the sketch
  55464. */
  55465. _main.default.prototype.pixelDensity = function(val) {
  55466. _main.default._validateParameters('pixelDensity', arguments);
  55467. var returnValue;
  55468. if (typeof val === 'number') {
  55469. if (val !== this._pixelDensity) {
  55470. this._pixelDensity = val;
  55471. }
  55472. returnValue = this;
  55473. this.resizeCanvas(this.width, this.height, true); // as a side effect, it will clear the canvas
  55474. } else {
  55475. returnValue = this._pixelDensity;
  55476. }
  55477. return returnValue;
  55478. };
  55479. /**
  55480. * Returns the pixel density of the current display the sketch is running on.
  55481. *
  55482. * @method displayDensity
  55483. * @returns {Number} current pixel density of the display
  55484. * @example
  55485. * <div>
  55486. * <code>
  55487. * function setup() {
  55488. * let density = displayDensity();
  55489. * pixelDensity(density);
  55490. * createCanvas(100, 100);
  55491. * background(200);
  55492. * ellipse(width / 2, height / 2, 50, 50);
  55493. * }
  55494. * </code>
  55495. * </div>
  55496. *
  55497. * @alt
  55498. * 50x50 white ellipse with black outline in center of canvas.
  55499. */
  55500. _main.default.prototype.displayDensity = function() {
  55501. return window.devicePixelRatio;
  55502. };
  55503. function launchFullscreen(element) {
  55504. var enabled =
  55505. document.fullscreenEnabled ||
  55506. document.webkitFullscreenEnabled ||
  55507. document.mozFullScreenEnabled ||
  55508. document.msFullscreenEnabled;
  55509. if (!enabled) {
  55510. throw new Error('Fullscreen not enabled in this browser.');
  55511. }
  55512. if (element.requestFullscreen) {
  55513. element.requestFullscreen();
  55514. } else if (element.mozRequestFullScreen) {
  55515. element.mozRequestFullScreen();
  55516. } else if (element.webkitRequestFullscreen) {
  55517. element.webkitRequestFullscreen();
  55518. } else if (element.msRequestFullscreen) {
  55519. element.msRequestFullscreen();
  55520. }
  55521. }
  55522. function exitFullscreen() {
  55523. if (document.exitFullscreen) {
  55524. document.exitFullscreen();
  55525. } else if (document.mozCancelFullScreen) {
  55526. document.mozCancelFullScreen();
  55527. } else if (document.webkitExitFullscreen) {
  55528. document.webkitExitFullscreen();
  55529. } else if (document.msExitFullscreen) {
  55530. document.msExitFullscreen();
  55531. }
  55532. }
  55533. /**
  55534. * Gets the current URL. Note: when using the
  55535. * p5 Editor, this will return an empty object because the sketch
  55536. * is embedded in an iframe. It will work correctly if you view the
  55537. * sketch using the editor's present or share URLs.
  55538. * @method getURL
  55539. * @return {String} url
  55540. * @example
  55541. * <div>
  55542. * <code>
  55543. * let url;
  55544. * let x = 100;
  55545. *
  55546. * function setup() {
  55547. * fill(0);
  55548. * noStroke();
  55549. * url = getURL();
  55550. * }
  55551. *
  55552. * function draw() {
  55553. * background(200);
  55554. * text(url, x, height / 2);
  55555. * x--;
  55556. * }
  55557. * </code>
  55558. * </div>
  55559. *
  55560. * @alt
  55561. * current url (http://p5js.org/reference/#/p5/getURL) moves right to left.
  55562. */
  55563. _main.default.prototype.getURL = function() {
  55564. return location.href;
  55565. };
  55566. /**
  55567. * Gets the current URL path as an array. Note: when using the
  55568. * p5 Editor, this will return an empty object because the sketch
  55569. * is embedded in an iframe. It will work correctly if you view the
  55570. * sketch using the editor's present or share URLs.
  55571. * @method getURLPath
  55572. * @return {String[]} path components
  55573. * @example
  55574. * <div class='norender'><code>
  55575. * function setup() {
  55576. * let urlPath = getURLPath();
  55577. * for (let i = 0; i < urlPath.length; i++) {
  55578. * text(urlPath[i], 10, i * 20 + 20);
  55579. * }
  55580. * }
  55581. * </code></div>
  55582. *
  55583. * @alt
  55584. * This example does not render anything.
  55585. */
  55586. _main.default.prototype.getURLPath = function() {
  55587. return location.pathname.split('/').filter(function(v) {
  55588. return v !== '';
  55589. });
  55590. };
  55591. /**
  55592. * Gets the current URL params as an Object. Note: when using the
  55593. * p5 Editor, this will return an empty object because the sketch
  55594. * is embedded in an iframe. It will work correctly if you view the
  55595. * sketch using the editor's present or share URLs.
  55596. * @method getURLParams
  55597. * @return {Object} URL params
  55598. * @example
  55599. * <div class='norender notest'>
  55600. * <code>
  55601. * // Example: http://p5js.org?year=2014&month=May&day=15
  55602. *
  55603. * function setup() {
  55604. * let params = getURLParams();
  55605. * text(params.day, 10, 20);
  55606. * text(params.month, 10, 40);
  55607. * text(params.year, 10, 60);
  55608. * }
  55609. * </code>
  55610. * </div>
  55611. *
  55612. * @alt
  55613. * This example does not render anything.
  55614. */
  55615. _main.default.prototype.getURLParams = function() {
  55616. var re = /[?&]([^&=]+)(?:[&=])([^&=]+)/gim;
  55617. var m;
  55618. var v = {};
  55619. while ((m = re.exec(location.search)) != null) {
  55620. if (m.index === re.lastIndex) {
  55621. re.lastIndex++;
  55622. }
  55623. v[m[1]] = m[2];
  55624. }
  55625. return v;
  55626. };
  55627. var _default = _main.default;
  55628. exports.default = _default;
  55629. },
  55630. {
  55631. './constants': 272,
  55632. './main': 283,
  55633. 'core-js/modules/es.array.concat': 166,
  55634. 'core-js/modules/es.array.filter': 169,
  55635. 'core-js/modules/es.array.includes': 172,
  55636. 'core-js/modules/es.regexp.exec': 196,
  55637. 'core-js/modules/es.string.includes': 200,
  55638. 'core-js/modules/es.string.search': 205,
  55639. 'core-js/modules/es.string.split': 206
  55640. }
  55641. ],
  55642. 274: [
  55643. function(_dereq_, module, exports) {
  55644. 'use strict';
  55645. Object.defineProperty(exports, '__esModule', { value: true });
  55646. exports.default = void 0; // Different browsers may use different error strings for the same error.
  55647. // Extracting info from them is much easier and cleaner if we have a predefined
  55648. // lookup against which we try and match the errors obtained from the browser,
  55649. // classify them into types and extract the required information. The contents
  55650. // of this file serve as that lookup. The FES can use this to give a simplified
  55651. // explanation for all kinds of errors.
  55652. var strings = {
  55653. ReferenceError: [
  55654. {
  55655. msg: '{{}} is not defined',
  55656. type: 'NOTDEFINED',
  55657. browser: 'all'
  55658. },
  55659. {
  55660. msg: "Can't find variable: {{}}",
  55661. type: 'NOTDEFINED',
  55662. browser: 'Safari'
  55663. }
  55664. ],
  55665. SyntaxError: [
  55666. {
  55667. msg: 'illegal character',
  55668. type: 'INVALIDTOKEN',
  55669. browser: 'Firefox'
  55670. },
  55671. {
  55672. msg: 'Invalid character',
  55673. type: 'INVALIDTOKEN',
  55674. browser: 'Safari'
  55675. },
  55676. {
  55677. msg: 'Invalid or unexpected token',
  55678. type: 'INVALIDTOKEN',
  55679. browser: 'Chrome'
  55680. },
  55681. {
  55682. msg: "Unexpected token '{{.}}'",
  55683. type: 'UNEXPECTEDTOKEN',
  55684. browser: 'Chrome'
  55685. },
  55686. {
  55687. msg: "expected {{.}}, got '{{.}}'",
  55688. type: 'UNEXPECTEDTOKEN',
  55689. browser: 'Chrome'
  55690. }
  55691. ],
  55692. TypeError: [
  55693. {
  55694. msg: '{{.}} is not a function',
  55695. type: 'NOTFUNC',
  55696. browser: 'all'
  55697. }
  55698. ]
  55699. };
  55700. var _default = strings;
  55701. exports.default = _default;
  55702. },
  55703. {}
  55704. ],
  55705. 275: [
  55706. function(_dereq_, module, exports) {
  55707. 'use strict';
  55708. _dereq_('core-js/modules/es.symbol');
  55709. _dereq_('core-js/modules/es.symbol.description');
  55710. _dereq_('core-js/modules/es.symbol.iterator');
  55711. _dereq_('core-js/modules/es.array.concat');
  55712. _dereq_('core-js/modules/es.array.filter');
  55713. _dereq_('core-js/modules/es.array.for-each');
  55714. _dereq_('core-js/modules/es.array.includes');
  55715. _dereq_('core-js/modules/es.array.iterator');
  55716. _dereq_('core-js/modules/es.array.join');
  55717. _dereq_('core-js/modules/es.array.map');
  55718. _dereq_('core-js/modules/es.array.slice');
  55719. _dereq_('core-js/modules/es.array.some');
  55720. _dereq_('core-js/modules/es.function.name');
  55721. _dereq_('core-js/modules/es.object.assign');
  55722. _dereq_('core-js/modules/es.object.get-own-property-names');
  55723. _dereq_('core-js/modules/es.object.keys');
  55724. _dereq_('core-js/modules/es.object.to-string');
  55725. _dereq_('core-js/modules/es.regexp.constructor');
  55726. _dereq_('core-js/modules/es.regexp.exec');
  55727. _dereq_('core-js/modules/es.regexp.to-string');
  55728. _dereq_('core-js/modules/es.string.iterator');
  55729. _dereq_('core-js/modules/es.string.match');
  55730. _dereq_('core-js/modules/es.string.replace');
  55731. _dereq_('core-js/modules/es.string.search');
  55732. _dereq_('core-js/modules/es.string.split');
  55733. _dereq_('core-js/modules/web.dom-collections.for-each');
  55734. _dereq_('core-js/modules/web.dom-collections.iterator');
  55735. Object.defineProperty(exports, '__esModule', { value: true });
  55736. exports.default = void 0;
  55737. var _main = _interopRequireDefault(_dereq_('../main'));
  55738. var _internationalization = _dereq_('../internationalization');
  55739. function _interopRequireDefault(obj) {
  55740. return obj && obj.__esModule ? obj : { default: obj };
  55741. }
  55742. function _slicedToArray(arr, i) {
  55743. return (
  55744. _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest()
  55745. );
  55746. }
  55747. function _nonIterableRest() {
  55748. throw new TypeError('Invalid attempt to destructure non-iterable instance');
  55749. }
  55750. function _iterableToArrayLimit(arr, i) {
  55751. if (
  55752. !(
  55753. Symbol.iterator in Object(arr) ||
  55754. Object.prototype.toString.call(arr) === '[object Arguments]'
  55755. )
  55756. ) {
  55757. return;
  55758. }
  55759. var _arr = [];
  55760. var _n = true;
  55761. var _d = false;
  55762. var _e = undefined;
  55763. try {
  55764. for (
  55765. var _i = arr[Symbol.iterator](), _s;
  55766. !(_n = (_s = _i.next()).done);
  55767. _n = true
  55768. ) {
  55769. _arr.push(_s.value);
  55770. if (i && _arr.length === i) break;
  55771. }
  55772. } catch (err) {
  55773. _d = true;
  55774. _e = err;
  55775. } finally {
  55776. try {
  55777. if (!_n && _i['return'] != null) _i['return']();
  55778. } finally {
  55779. if (_d) throw _e;
  55780. }
  55781. }
  55782. return _arr;
  55783. }
  55784. function _arrayWithHoles(arr) {
  55785. if (Array.isArray(arr)) return arr;
  55786. }
  55787. function _typeof(obj) {
  55788. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  55789. _typeof = function _typeof(obj) {
  55790. return typeof obj;
  55791. };
  55792. } else {
  55793. _typeof = function _typeof(obj) {
  55794. return obj &&
  55795. typeof Symbol === 'function' &&
  55796. obj.constructor === Symbol &&
  55797. obj !== Symbol.prototype
  55798. ? 'symbol'
  55799. : typeof obj;
  55800. };
  55801. }
  55802. return _typeof(obj);
  55803. }
  55804. // p5.js blue, p5.js orange, auto dark green; fallback p5.js darkened magenta
  55805. // See testColors below for all the color codes and names
  55806. var typeColors = ['#2D7BB6', '#EE9900', '#4DB200', '#C83C00'];
  55807. var misusedAtTopLevelCode = null;
  55808. var defineMisusedAtTopLevelCode = null;
  55809. // the threshold for the maximum allowed levenshtein distance
  55810. // used in misspelling detection
  55811. var EDIT_DIST_THRESHOLD = 2;
  55812. // to enable or disable styling (color, font-size, etc. ) for fes messages
  55813. var ENABLE_FES_STYLING = false;
  55814. if (typeof IS_MINIFIED !== 'undefined') {
  55815. _main.default._friendlyError = _main.default._checkForUserDefinedFunctions = _main.default._fesErrorMonitor = function() {};
  55816. } else {
  55817. var doFriendlyWelcome = false; // TEMP until we get it all working LM
  55818. var errorTable = _dereq_('./browser_errors').default;
  55819. // -- Borrowed from jQuery 1.11.3 --
  55820. var class2type = {};
  55821. var _toString = class2type.toString;
  55822. var names = [
  55823. 'Boolean',
  55824. 'Number',
  55825. 'String',
  55826. 'Function',
  55827. 'Array',
  55828. 'Date',
  55829. 'RegExp',
  55830. 'Object',
  55831. 'Error'
  55832. ];
  55833. for (var n = 0; n < names.length; n++) {
  55834. class2type['[object '.concat(names[n], ']')] = names[n].toLowerCase();
  55835. }
  55836. var getType = function getType(obj) {
  55837. if (obj == null) {
  55838. return ''.concat(obj);
  55839. }
  55840. return _typeof(obj) === 'object' || typeof obj === 'function'
  55841. ? class2type[_toString.call(obj)] || 'object'
  55842. : _typeof(obj);
  55843. };
  55844. // -- End borrow --
  55845. // entry points into user-defined code
  55846. var entryPoints = [
  55847. 'setup',
  55848. 'draw',
  55849. 'preload',
  55850. 'deviceMoved',
  55851. 'deviceTurned',
  55852. 'deviceShaken',
  55853. 'doubleClicked',
  55854. 'mousePressed',
  55855. 'mouseReleased',
  55856. 'mouseMoved',
  55857. 'mouseDragged',
  55858. 'mouseClicked',
  55859. 'mouseWheel',
  55860. 'touchStarted',
  55861. 'touchMoved',
  55862. 'touchEnded',
  55863. 'keyPressed',
  55864. 'keyReleased',
  55865. 'keyTyped',
  55866. 'windowResized'
  55867. ];
  55868. var friendlyWelcome = function friendlyWelcome() {
  55869. // p5.js brand - magenta: #ED225D
  55870. //const astrixBgColor = 'transparent';
  55871. //const astrixTxtColor = '#ED225D';
  55872. //const welcomeBgColor = '#ED225D';
  55873. //const welcomeTextColor = 'white';
  55874. var welcomeMessage = (0, _internationalization.translator)('fes.pre', {
  55875. message: (0, _internationalization.translator)('fes.welcome')
  55876. });
  55877. console.log(
  55878. ' _ \n' +
  55879. ' /\\| |/\\ \n' +
  55880. " \\ ` ' / \n" +
  55881. ' / , . \\ \n' +
  55882. ' \\/|_|\\/ ' +
  55883. '\n\n' +
  55884. welcomeMessage
  55885. );
  55886. };
  55887. /**
  55888. * Takes a message and a p5 function func, and adds a link pointing to
  55889. * the reference documentation of func at the end of the message
  55890. *
  55891. * @method mapToReference
  55892. * @private
  55893. * @param {String} message the words to be said
  55894. * @param {String} [func] the name of the function to link
  55895. *
  55896. * @returns {String}
  55897. */
  55898. var mapToReference = function mapToReference(message, func) {
  55899. var msgWithReference = '';
  55900. if (func == null || func.substring(0, 4) === 'load') {
  55901. msgWithReference = message;
  55902. } else {
  55903. var methodParts = func.split('.');
  55904. var referenceSection =
  55905. methodParts.length > 1
  55906. ? ''.concat(methodParts[0], '.').concat(methodParts[1])
  55907. : 'p5';
  55908. var funcName =
  55909. methodParts.length === 1 ? func : methodParts.slice(2).join('/');
  55910. msgWithReference = ''
  55911. .concat(message, ' (http://p5js.org/reference/#/')
  55912. .concat(referenceSection, '/')
  55913. .concat(funcName, ')');
  55914. }
  55915. return msgWithReference;
  55916. };
  55917. /**
  55918. * Prints out a fancy, colorful message to the console log
  55919. *
  55920. * @method _report
  55921. * @private
  55922. * @param {String} message the words to be said
  55923. * @param {String} [func] the name of the function to link
  55924. * @param {Number|String} [color] CSS color string or error type
  55925. *
  55926. * @return console logs
  55927. */
  55928. _main.default._report = function(message, func, color) {
  55929. // if p5._fesLogger is set ( i.e we are running tests ), use that
  55930. // instead of console.log
  55931. var log =
  55932. _main.default._fesLogger == null
  55933. ? console.log.bind(console)
  55934. : _main.default._fesLogger;
  55935. if (doFriendlyWelcome) {
  55936. friendlyWelcome();
  55937. doFriendlyWelcome = false;
  55938. }
  55939. if ('undefined' === getType(color)) {
  55940. color = '#B40033'; // dark magenta
  55941. } else if (getType(color) === 'number') {
  55942. // Type to color
  55943. color = typeColors[color];
  55944. }
  55945. // Add a link to the reference docs of func at the end of the message
  55946. message = mapToReference(message, func);
  55947. var style = [
  55948. 'color: '.concat(color),
  55949. 'font-family: Arial',
  55950. 'font-size: larger'
  55951. ];
  55952. var prefixedMsg = (0, _internationalization.translator)('fes.pre', {
  55953. message: message
  55954. });
  55955. if (ENABLE_FES_STYLING) {
  55956. log('%c' + prefixedMsg, style.join(';'));
  55957. } else {
  55958. log(prefixedMsg);
  55959. }
  55960. };
  55961. /**
  55962. * This is a generic method that can be called from anywhere in the p5
  55963. * library to alert users to a common error.
  55964. *
  55965. * @method _friendlyError
  55966. * @private
  55967. * @param {Number} message message to be printed
  55968. * @param {String} [method] name of method
  55969. * @param {Number|String} [color] CSS color string or error type
  55970. */
  55971. _main.default._friendlyError = function(message, method, color) {
  55972. _main.default._report(message, method, color);
  55973. };
  55974. /**
  55975. * This is called internally if there is a error with autoplay.
  55976. *
  55977. * @method _friendlyAutoplayError
  55978. * @private
  55979. */
  55980. _main.default._friendlyAutoplayError = function(src) {
  55981. var message = (0, _internationalization.translator)('fes.autoplay', {
  55982. src: src,
  55983. link: 'https://developer.mozilla.org/docs/Web/Media/Autoplay_guide'
  55984. });
  55985. console.log(
  55986. (0, _internationalization.translator)('fes.pre', { message: message })
  55987. );
  55988. };
  55989. /**
  55990. * An implementation of
  55991. * https://en.wikipedia.org/wiki/Wagner%E2%80%93Fischer_algorithm to
  55992. * compute the Levenshtein distance. It gives a measure of how dissimilar
  55993. * two strings are. If the "distance" between them is small enough, it is
  55994. * reasonable to think that one is the misspelled version of the other.
  55995. * @method computeEditDistance
  55996. * @private
  55997. * @param {String} w1 the first word
  55998. * @param {String} w2 the second word
  55999. *
  56000. * @returns {Number} the "distance" between the two words, a smaller value
  56001. * indicates that the words are similar
  56002. */
  56003. var computeEditDistance = function computeEditDistance(w1, w2) {
  56004. var l1 = w1.length,
  56005. l2 = w2.length;
  56006. if (l1 === 0) return w2;
  56007. if (l2 === 0) return w1;
  56008. var prev = [];
  56009. var cur = [];
  56010. for (var j = 0; j < l2 + 1; j++) {
  56011. cur[j] = j;
  56012. }
  56013. prev = cur;
  56014. for (var i = 1; i < l1 + 1; i++) {
  56015. cur = [];
  56016. for (var _j = 0; _j < l2 + 1; _j++) {
  56017. if (_j === 0) {
  56018. cur[_j] = i;
  56019. } else {
  56020. var a1 = w1[i - 1],
  56021. a2 = w2[_j - 1];
  56022. var temp = 999999;
  56023. var cost = a1.toLowerCase() === a2.toLowerCase() ? 0 : 1;
  56024. temp = temp > cost + prev[_j - 1] ? cost + prev[_j - 1] : temp;
  56025. temp = temp > 1 + cur[_j - 1] ? 1 + cur[_j - 1] : temp;
  56026. temp = temp > 1 + prev[_j] ? 1 + prev[_j] : temp;
  56027. cur[_j] = temp;
  56028. }
  56029. }
  56030. prev = cur;
  56031. }
  56032. return cur[l2];
  56033. };
  56034. /**
  56035. * checks if the various functions such as setup, draw, preload have been
  56036. * defined with capitalization mistakes
  56037. * @method checkForUserDefinedFunctions
  56038. * @private
  56039. * @param {*} context The current default context. It's set to window in
  56040. * "global mode" and to a p5 instance in "instance mode"
  56041. */
  56042. var checkForUserDefinedFunctions = function checkForUserDefinedFunctions(
  56043. context
  56044. ) {
  56045. if (_main.default.disableFriendlyErrors) return;
  56046. // if using instance mode, this function would be called with the current
  56047. // instance as context
  56048. var instanceMode = context instanceof _main.default;
  56049. context = instanceMode ? context : window;
  56050. var fnNames = entryPoints;
  56051. var fxns = {};
  56052. // lowercasename -> actualName mapping
  56053. fnNames.forEach(function(symbol) {
  56054. fxns[symbol.toLowerCase()] = symbol;
  56055. });
  56056. for (
  56057. var _i = 0, _Object$keys = Object.keys(context);
  56058. _i < _Object$keys.length;
  56059. _i++
  56060. ) {
  56061. var prop = _Object$keys[_i];
  56062. var lowercase = prop.toLowerCase();
  56063. // check if the lowercase property name has an entry in fxns, if the
  56064. // actual name with correct capitalization doesnt exist in context,
  56065. // and if the user-defined symbol is of the type function
  56066. if (
  56067. fxns[lowercase] &&
  56068. !context[fxns[lowercase]] &&
  56069. typeof context[prop] === 'function'
  56070. ) {
  56071. var msg = (0, _internationalization.translator)(
  56072. 'fes.checkUserDefinedFns',
  56073. {
  56074. name: prop,
  56075. actualName: fxns[lowercase]
  56076. }
  56077. );
  56078. _main.default._friendlyError(msg, fxns[lowercase]);
  56079. }
  56080. }
  56081. };
  56082. /**
  56083. * compares the the symbol caught in the ReferenceErrror to everything
  56084. * in misusedAtTopLevel ( all public p5 properties ). The use of
  56085. * misusedAtTopLevel here is for convenience as it was an array that was
  56086. * already defined when spelling check was implemented. For this particular
  56087. * use-case, it's a misnomer.
  56088. *
  56089. * @method handleMisspelling
  56090. * @private
  56091. * @param {String} errSym the symbol to whose spelling to check
  56092. * @param {Error} error the ReferenceError object
  56093. *
  56094. * @returns {Boolean} a boolean value indicating if this error was likely due
  56095. * to a mis-spelling
  56096. */
  56097. var handleMisspelling = function handleMisspelling(errSym, error) {
  56098. if (!misusedAtTopLevelCode) {
  56099. defineMisusedAtTopLevelCode();
  56100. }
  56101. var distanceMap = {};
  56102. var min = 999999;
  56103. // compute the levenshtein distance for the symbol against all known
  56104. // public p5 properties. Find the property with the minimum distance
  56105. misusedAtTopLevelCode.forEach(function(symbol) {
  56106. var dist = computeEditDistance(errSym, symbol.name);
  56107. if (distanceMap[dist]) distanceMap[dist].push(symbol);
  56108. else distanceMap[dist] = [symbol];
  56109. if (dist < min) min = dist;
  56110. });
  56111. // if the closest match has more "distance" than the max allowed threshold
  56112. if (min > Math.min(EDIT_DIST_THRESHOLD, errSym.length)) return false;
  56113. // Show a message only if the caught symbol and the matched property name
  56114. // differ in their name ( either letter difference or difference of case )
  56115. var matchedSymbols = distanceMap[min].filter(function(symbol) {
  56116. return symbol.name !== errSym;
  56117. });
  56118. if (matchedSymbols.length !== 0) {
  56119. var parsed = _main.default._getErrorStackParser().parse(error);
  56120. var locationObj;
  56121. if (
  56122. parsed &&
  56123. parsed[0] &&
  56124. parsed[0].fileName &&
  56125. parsed[0].lineNumber &&
  56126. parsed[0].columnNumber
  56127. ) {
  56128. locationObj = {
  56129. location: ''
  56130. .concat(parsed[0].fileName, ':')
  56131. .concat(parsed[0].lineNumber, ':')
  56132. .concat(parsed[0].columnNumber),
  56133. file: parsed[0].fileName.split('/').slice(-1),
  56134. line: parsed[0].lineNumber
  56135. };
  56136. }
  56137. var msg;
  56138. if (matchedSymbols.length === 1) {
  56139. // To be used when there is only one closest match. The count parameter
  56140. // allows i18n to pick between the keys "fes.misspelling" and
  56141. // "fes.misspelling__plural"
  56142. msg = (0, _internationalization.translator)('fes.misspelling', {
  56143. name: errSym,
  56144. actualName: matchedSymbols[0].name,
  56145. type: matchedSymbols[0].type,
  56146. location: locationObj
  56147. ? (0, _internationalization.translator)('fes.location', locationObj)
  56148. : '',
  56149. count: matchedSymbols.length
  56150. });
  56151. } else {
  56152. // To be used when there are multiple closest matches. Gives each
  56153. // suggestion on its own line, the function name followed by a link to
  56154. // reference documentation
  56155. var suggestions = matchedSymbols
  56156. .map(function(symbol) {
  56157. var message =
  56158. '▶️ ' + symbol.name + (symbol.type === 'function' ? '()' : '');
  56159. return mapToReference(message, symbol.name);
  56160. })
  56161. .join('\n');
  56162. msg = (0, _internationalization.translator)('fes.misspelling', {
  56163. name: errSym,
  56164. suggestions: suggestions,
  56165. location: locationObj
  56166. ? (0, _internationalization.translator)('fes.location', locationObj)
  56167. : '',
  56168. count: matchedSymbols.length
  56169. });
  56170. }
  56171. // If there is only one closest match, tell _friendlyError to also add
  56172. // a link to the reference documentation. In case of multiple matches,
  56173. // this is already done in the suggestions variable, one link for each
  56174. // suggestion.
  56175. _main.default._friendlyError(
  56176. msg,
  56177. matchedSymbols.length === 1 ? matchedSymbols[0].name : undefined
  56178. );
  56179. return true;
  56180. }
  56181. return false;
  56182. };
  56183. /**
  56184. * prints a friendly stacktrace which only includes user-written functions
  56185. * and is easier for newcomers to understand
  56186. * @method printFriendlyStack
  56187. * @private
  56188. * @param {Array} friendlyStack
  56189. */
  56190. var printFriendlyStack = function printFriendlyStack(friendlyStack) {
  56191. var log =
  56192. _main.default._fesLogger && typeof _main.default._fesLogger === 'function'
  56193. ? _main.default._fesLogger
  56194. : console.log.bind(console);
  56195. if (friendlyStack.length > 1) {
  56196. var stacktraceMsg = '';
  56197. friendlyStack.forEach(function(frame, idx) {
  56198. var location = ''
  56199. .concat(frame.fileName, ':')
  56200. .concat(frame.lineNumber, ':')
  56201. .concat(frame.columnNumber);
  56202. var frameMsg,
  56203. translationObj = {
  56204. func: frame.functionName,
  56205. line: frame.lineNumber,
  56206. location: location,
  56207. file: frame.fileName.split('/').slice(-1)
  56208. };
  56209. if (idx === 0) {
  56210. frameMsg = (0, _internationalization.translator)(
  56211. 'fes.globalErrors.stackTop',
  56212. translationObj
  56213. );
  56214. } else {
  56215. frameMsg = (0, _internationalization.translator)(
  56216. 'fes.globalErrors.stackSubseq',
  56217. translationObj
  56218. );
  56219. }
  56220. stacktraceMsg += frameMsg;
  56221. });
  56222. log(stacktraceMsg);
  56223. }
  56224. };
  56225. /**
  56226. * Takes a stacktrace array and filters out all frames that show internal p5
  56227. * details. It also uses this processed stack to figure out if the error
  56228. * error happened internally within the library, and if the error was due to
  56229. * a non-loadX() method being used in preload
  56230. * "Internally" here means that the error exact location of the error (the
  56231. * top of the stack) is a piece of code write in the p5.js library (which may
  56232. * or may not have been called from the user's sketch)
  56233. *
  56234. * @method processStack
  56235. * @private
  56236. * @param {Error} error
  56237. * @param {Array} stacktrace
  56238. *
  56239. * @returns {Array} An array with two elements, [isInternal, friendlyStack]
  56240. * isInternal: a boolean indicating if the error happened internally
  56241. * friendlyStack: the simplified stacktrace, with internal details filtered
  56242. */
  56243. var processStack = function processStack(error, stacktrace) {
  56244. // cannot process a stacktrace that doesn't exist
  56245. if (!stacktrace) return [false, null];
  56246. stacktrace.forEach(function(frame) {
  56247. frame.functionName = frame.functionName || '';
  56248. });
  56249. // isInternal - Did this error happen inside the library
  56250. var isInternal = false;
  56251. var p5FileName, friendlyStack, currentEntryPoint;
  56252. for (var i = stacktrace.length - 1; i >= 0; i--) {
  56253. var splitted = stacktrace[i].functionName.split('.');
  56254. if (entryPoints.includes(splitted[splitted.length - 1])) {
  56255. // remove everything below an entry point function (setup, draw, etc).
  56256. // (it's usually the internal initialization calls)
  56257. friendlyStack = stacktrace.slice(0, i + 1);
  56258. currentEntryPoint = splitted[splitted.length - 1];
  56259. for (var j = 0; j < i; j++) {
  56260. // Due to the current build process, all p5 functions have
  56261. // _main.default in their names in the final build. This is the
  56262. // easiest way to check if a function is inside the p5 library
  56263. if (stacktrace[j].functionName.search('_main.default') !== -1) {
  56264. isInternal = true;
  56265. p5FileName = stacktrace[j].fileName;
  56266. break;
  56267. }
  56268. }
  56269. break;
  56270. }
  56271. }
  56272. // in some cases ( errors in promises, callbacks, etc), no entry-point
  56273. // function may be found in the stacktrace. In that case just use the
  56274. // entire stacktrace for friendlyStack
  56275. if (!friendlyStack) friendlyStack = stacktrace;
  56276. if (isInternal) {
  56277. // the frameIndex property is added before the filter, so frameIndex
  56278. // corresponds to the index of a frame in the original stacktrace.
  56279. // Then we filter out all frames which belong to the file that contains
  56280. // the p5 library
  56281. friendlyStack = friendlyStack
  56282. .map(function(frame, index) {
  56283. frame.frameIndex = index;
  56284. return frame;
  56285. })
  56286. .filter(function(frame) {
  56287. return frame.fileName !== p5FileName;
  56288. });
  56289. // a weird case, if for some reason we can't identify the function called
  56290. // from user's code
  56291. if (friendlyStack.length === 0) return [true, null];
  56292. // get the function just above the topmost frame in the friendlyStack.
  56293. // i.e the name of the library function called from user's code
  56294. var func = stacktrace[friendlyStack[0].frameIndex - 1].functionName
  56295. .split('.')
  56296. .slice(-1)[0];
  56297. // Try and get the location (line no.) from the top element of the stack
  56298. var locationObj;
  56299. if (
  56300. friendlyStack[0].fileName &&
  56301. friendlyStack[0].lineNumber &&
  56302. friendlyStack[0].columnNumber
  56303. ) {
  56304. locationObj = {
  56305. location: ''
  56306. .concat(friendlyStack[0].fileName, ':')
  56307. .concat(friendlyStack[0].lineNumber, ':')
  56308. .concat(friendlyStack[0].columnNumber),
  56309. file: friendlyStack[0].fileName.split('/').slice(-1),
  56310. line: friendlyStack[0].lineNumber
  56311. };
  56312. // if already handled by another part of the FES, don't handle again
  56313. if (_main.default._fesLogCache[locationObj.location]) return [true, null];
  56314. }
  56315. // Check if the error is due to a non loadX method being used incorrectly
  56316. // in preload
  56317. if (
  56318. currentEntryPoint === 'preload' &&
  56319. _main.default.prototype._preloadMethods[func] == null
  56320. ) {
  56321. _main.default._friendlyError(
  56322. (0, _internationalization.translator)('fes.wrongPreload', {
  56323. func: func,
  56324. location: locationObj
  56325. ? (0, _internationalization.translator)('fes.location', locationObj)
  56326. : '',
  56327. error: error.message
  56328. }),
  56329. 'preload'
  56330. );
  56331. } else {
  56332. // Library error
  56333. _main.default._friendlyError(
  56334. (0, _internationalization.translator)('fes.libraryError', {
  56335. func: func,
  56336. location: locationObj
  56337. ? (0, _internationalization.translator)('fes.location', locationObj)
  56338. : '',
  56339. error: error.message
  56340. }),
  56341. func
  56342. );
  56343. }
  56344. // Finally, if it's an internal error, print the friendlyStack
  56345. // ( fesErrorMonitor won't handle this error )
  56346. if (friendlyStack && friendlyStack.length) {
  56347. printFriendlyStack(friendlyStack);
  56348. }
  56349. }
  56350. return [isInternal, friendlyStack];
  56351. };
  56352. /**
  56353. * The main function for handling global errors. Called when an error
  56354. * happens and is responsible for detecting the type of error that
  56355. * has happened and showing the appropriate message
  56356. *
  56357. * @method fesErrorMonitor
  56358. * @private
  56359. * @param {*} e The object to extract error details from
  56360. */
  56361. var fesErrorMonitor = function fesErrorMonitor(e) {
  56362. if (_main.default.disableFriendlyErrors) return;
  56363. // Try to get the error object from e
  56364. var error;
  56365. if (e instanceof Error) {
  56366. error = e;
  56367. } else if (e instanceof ErrorEvent) {
  56368. error = e.error;
  56369. } else if (e instanceof PromiseRejectionEvent) {
  56370. error = e.reason;
  56371. if (!(error instanceof Error)) return;
  56372. }
  56373. if (!error) return;
  56374. var stacktrace = _main.default._getErrorStackParser().parse(error);
  56375. // process the stacktrace from the browser and simplify it to give
  56376. // friendlyStack.
  56377. var _processStack = processStack(error, stacktrace),
  56378. _processStack2 = _slicedToArray(_processStack, 2),
  56379. isInternal = _processStack2[0],
  56380. friendlyStack = _processStack2[1];
  56381. // if this is an internal library error, the type of the error is not relevant,
  56382. // only the user code that lead to it is.
  56383. if (isInternal) {
  56384. return;
  56385. }
  56386. var errList = errorTable[error.name];
  56387. if (!errList) return; // this type of error can't be handled yet
  56388. var matchedError;
  56389. var _iteratorNormalCompletion = true;
  56390. var _didIteratorError = false;
  56391. var _iteratorError = undefined;
  56392. try {
  56393. for (
  56394. var _iterator = errList[Symbol.iterator](), _step;
  56395. !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
  56396. _iteratorNormalCompletion = true
  56397. ) {
  56398. var obj = _step.value;
  56399. var string = obj.msg;
  56400. // capture the primary symbol mentioned in the error
  56401. string = string.replace(new RegExp('{{}}', 'g'), '([a-zA-Z0-9_]+)');
  56402. string = string.replace(new RegExp('{{.}}', 'g'), '(.+)');
  56403. string = string.replace(new RegExp('{}', 'g'), '(?:[a-zA-Z0-9_]+)');
  56404. var matched = error.message.match(string);
  56405. if (matched) {
  56406. matchedError = Object.assign({}, obj);
  56407. matchedError.match = matched;
  56408. break;
  56409. }
  56410. }
  56411. } catch (err) {
  56412. _didIteratorError = true;
  56413. _iteratorError = err;
  56414. } finally {
  56415. try {
  56416. if (!_iteratorNormalCompletion && _iterator.return != null) {
  56417. _iterator.return();
  56418. }
  56419. } finally {
  56420. if (_didIteratorError) {
  56421. throw _iteratorError;
  56422. }
  56423. }
  56424. }
  56425. if (!matchedError) return;
  56426. // Try and get the location from the top element of the stack
  56427. var locationObj;
  56428. if (
  56429. stacktrace &&
  56430. stacktrace[0].fileName &&
  56431. stacktrace[0].lineNumber &&
  56432. stacktrace[0].columnNumber
  56433. ) {
  56434. locationObj = {
  56435. location: ''
  56436. .concat(stacktrace[0].fileName, ':')
  56437. .concat(stacktrace[0].lineNumber, ':')
  56438. .concat(stacktrace[0].columnNumber),
  56439. file: stacktrace[0].fileName.split('/').slice(-1),
  56440. line: friendlyStack[0].lineNumber
  56441. };
  56442. }
  56443. switch (error.name) {
  56444. case 'SyntaxError': {
  56445. // We can't really do much with syntax errors other than try to use
  56446. // a simpler framing of the error message. The stack isn't available
  56447. // for syntax errors
  56448. switch (matchedError.type) {
  56449. case 'INVALIDTOKEN': {
  56450. var url =
  56451. 'https://developer.mozilla.org/docs/Web/JavaScript/Reference/Errors/Illegal_character#What_went_wrong';
  56452. _main.default._friendlyError(
  56453. (0, _internationalization.translator)(
  56454. 'fes.globalErrors.syntax.invalidToken',
  56455. {
  56456. url: url
  56457. }
  56458. )
  56459. );
  56460. break;
  56461. }
  56462. case 'UNEXPECTEDTOKEN': {
  56463. var _url =
  56464. 'https://developer.mozilla.org/docs/Web/JavaScript/Reference/Errors/Unexpected_token#What_went_wrong';
  56465. _main.default._friendlyError(
  56466. (0, _internationalization.translator)(
  56467. 'fes.globalErrors.syntax.unexpectedToken',
  56468. {
  56469. url: _url
  56470. }
  56471. )
  56472. );
  56473. break;
  56474. }
  56475. }
  56476. break;
  56477. }
  56478. case 'ReferenceError': {
  56479. switch (matchedError.type) {
  56480. case 'NOTDEFINED': {
  56481. var errSym = matchedError.match[1];
  56482. if (errSym && handleMisspelling(errSym, error)) {
  56483. break;
  56484. }
  56485. // if the flow gets this far, this is likely not a misspelling
  56486. // of a p5 property/function
  56487. var url1 = 'https://p5js.org/examples/data-variable-scope.html';
  56488. var url2 =
  56489. 'https://developer.mozilla.org/docs/Web/JavaScript/Reference/Errors/Not_Defined#What_went_wrong';
  56490. _main.default._friendlyError(
  56491. (0, _internationalization.translator)(
  56492. 'fes.globalErrors.reference.notDefined',
  56493. {
  56494. url1: url1,
  56495. url2: url2,
  56496. symbol: errSym,
  56497. location: locationObj
  56498. ? (0, _internationalization.translator)(
  56499. 'fes.location',
  56500. locationObj
  56501. )
  56502. : ''
  56503. }
  56504. )
  56505. );
  56506. if (friendlyStack) printFriendlyStack(friendlyStack);
  56507. break;
  56508. }
  56509. }
  56510. break;
  56511. }
  56512. case 'TypeError': {
  56513. switch (matchedError.type) {
  56514. case 'NOTFUNC': {
  56515. var _errSym = matchedError.match[1];
  56516. var splitSym = _errSym.split('.');
  56517. var _url2 =
  56518. 'https://developer.mozilla.org/docs/Web/JavaScript/Reference/Errors/Not_a_function#What_went_wrong';
  56519. // if errSym is aa.bb.cc , symbol would be cc and obj would aa.bb
  56520. var translationObj = {
  56521. url: _url2,
  56522. symbol: splitSym[splitSym.length - 1],
  56523. obj: splitSym.slice(0, splitSym.length - 1).join('.'),
  56524. location: locationObj
  56525. ? (0, _internationalization.translator)(
  56526. 'fes.location',
  56527. locationObj
  56528. )
  56529. : ''
  56530. };
  56531. // There are two cases to handle here. When the function is called
  56532. // as a property of an object and when it's called independently.
  56533. // Both have different explanations.
  56534. if (splitSym.length > 1) {
  56535. _main.default._friendlyError(
  56536. (0, _internationalization.translator)(
  56537. 'fes.globalErrors.type.notfuncObj',
  56538. translationObj
  56539. )
  56540. );
  56541. } else {
  56542. _main.default._friendlyError(
  56543. (0, _internationalization.translator)(
  56544. 'fes.globalErrors.type.notfunc',
  56545. translationObj
  56546. )
  56547. );
  56548. }
  56549. if (friendlyStack) printFriendlyStack(friendlyStack);
  56550. break;
  56551. }
  56552. }
  56553. }
  56554. }
  56555. };
  56556. _main.default._fesErrorMonitor = fesErrorMonitor;
  56557. _main.default._checkForUserDefinedFunctions = checkForUserDefinedFunctions;
  56558. // logger for testing purposes.
  56559. _main.default._fesLogger = null;
  56560. _main.default._fesLogCache = {};
  56561. window.addEventListener('load', checkForUserDefinedFunctions, false);
  56562. window.addEventListener('error', _main.default._fesErrorMonitor, false);
  56563. window.addEventListener(
  56564. 'unhandledrejection',
  56565. _main.default._fesErrorMonitor,
  56566. false
  56567. );
  56568. /**
  56569. * Prints out all the colors in the color pallete with white text.
  56570. * For color blindness testing.
  56571. */
  56572. /* function testColors() {
  56573. const str = 'A box of biscuits, a box of mixed biscuits and a biscuit mixer';
  56574. p5._friendlyError(str, 'print', '#ED225D'); // p5.js magenta
  56575. p5._friendlyError(str, 'print', '#2D7BB6'); // p5.js blue
  56576. p5._friendlyError(str, 'print', '#EE9900'); // p5.js orange
  56577. p5._friendlyError(str, 'print', '#A67F59'); // p5.js light brown
  56578. p5._friendlyError(str, 'print', '#704F21'); // p5.js gold
  56579. p5._friendlyError(str, 'print', '#1CC581'); // auto cyan
  56580. p5._friendlyError(str, 'print', '#FF6625'); // auto orange
  56581. p5._friendlyError(str, 'print', '#79EB22'); // auto green
  56582. p5._friendlyError(str, 'print', '#B40033'); // p5.js darkened magenta
  56583. p5._friendlyError(str, 'print', '#084B7F'); // p5.js darkened blue
  56584. p5._friendlyError(str, 'print', '#945F00'); // p5.js darkened orange
  56585. p5._friendlyError(str, 'print', '#6B441D'); // p5.js darkened brown
  56586. p5._friendlyError(str, 'print', '#2E1B00'); // p5.js darkened gold
  56587. p5._friendlyError(str, 'print', '#008851'); // auto dark cyan
  56588. p5._friendlyError(str, 'print', '#C83C00'); // auto dark orange
  56589. p5._friendlyError(str, 'print', '#4DB200'); // auto dark green
  56590. } */
  56591. }
  56592. // This is a lazily-defined list of p5 symbols that may be
  56593. // misused by beginners at top-level code, outside of setup/draw. We'd like
  56594. // to detect these errors and help the user by suggesting they move them
  56595. // into setup/draw.
  56596. //
  56597. // For more details, see https://github.com/processing/p5.js/issues/1121.
  56598. misusedAtTopLevelCode = null;
  56599. var FAQ_URL =
  56600. 'https://github.com/processing/p5.js/wiki/p5.js-overview#why-cant-i-assign-variables-using-p5-functions-and-variables-before-setup';
  56601. defineMisusedAtTopLevelCode = function defineMisusedAtTopLevelCode() {
  56602. var uniqueNamesFound = {};
  56603. var getSymbols = function getSymbols(obj) {
  56604. return Object.getOwnPropertyNames(obj)
  56605. .filter(function(name) {
  56606. if (name[0] === '_') {
  56607. return false;
  56608. }
  56609. if (name in uniqueNamesFound) {
  56610. return false;
  56611. }
  56612. uniqueNamesFound[name] = true;
  56613. return true;
  56614. })
  56615. .map(function(name) {
  56616. var type;
  56617. if (typeof obj[name] === 'function') {
  56618. type = 'function';
  56619. } else if (name === name.toUpperCase()) {
  56620. type = 'constant';
  56621. } else {
  56622. type = 'variable';
  56623. }
  56624. return { name: name, type: type };
  56625. });
  56626. };
  56627. misusedAtTopLevelCode = [].concat(
  56628. getSymbols(_main.default.prototype),
  56629. // At present, p5 only adds its constants to p5.prototype during
  56630. // construction, which may not have happened at the time a
  56631. // ReferenceError is thrown, so we'll manually add them to our list.
  56632. getSymbols(_dereq_('../constants'))
  56633. );
  56634. // This will ultimately ensure that we report the most specific error
  56635. // possible to the user, e.g. advising them about HALF_PI instead of PI
  56636. // when their code misuses the former.
  56637. misusedAtTopLevelCode.sort(function(a, b) {
  56638. return b.name.length - a.name.length;
  56639. });
  56640. };
  56641. var helpForMisusedAtTopLevelCode = function helpForMisusedAtTopLevelCode(e, log) {
  56642. if (!log) {
  56643. log = console.log.bind(console);
  56644. }
  56645. if (!misusedAtTopLevelCode) {
  56646. defineMisusedAtTopLevelCode();
  56647. }
  56648. // If we find that we're logging lots of false positives, we can
  56649. // uncomment the following code to avoid displaying anything if the
  56650. // user's code isn't likely to be using p5's global mode. (Note that
  56651. // setup/draw are more likely to be defined due to JS function hoisting.)
  56652. //
  56653. //if (!('setup' in window || 'draw' in window)) {
  56654. // return;
  56655. //}
  56656. misusedAtTopLevelCode.some(function(symbol) {
  56657. // Note that while just checking for the occurrence of the
  56658. // symbol name in the error message could result in false positives,
  56659. // a more rigorous test is difficult because different browsers
  56660. // log different messages, and the format of those messages may
  56661. // change over time.
  56662. //
  56663. // For example, if the user uses 'PI' in their code, it may result
  56664. // in any one of the following messages:
  56665. //
  56666. // * 'PI' is undefined (Microsoft Edge)
  56667. // * ReferenceError: PI is undefined (Firefox)
  56668. // * Uncaught ReferenceError: PI is not defined (Chrome)
  56669. if (
  56670. e.message &&
  56671. e.message.match('\\W?'.concat(symbol.name, '\\W')) !== null
  56672. ) {
  56673. var symbolName =
  56674. symbol.type === 'function' ? ''.concat(symbol.name, '()') : symbol.name;
  56675. if (typeof IS_MINIFIED !== 'undefined') {
  56676. log(
  56677. "Did you just try to use p5.js's "
  56678. .concat(symbolName, ' ')
  56679. .concat(
  56680. symbol.type,
  56681. "? If so, you may want to move it into your sketch's setup() function.\n\nFor more details, see: "
  56682. )
  56683. .concat(FAQ_URL)
  56684. );
  56685. } else {
  56686. log(
  56687. (0, _internationalization.translator)('fes.misusedTopLevel', {
  56688. symbolName: symbolName,
  56689. symbolType: symbol.type,
  56690. link: FAQ_URL
  56691. })
  56692. );
  56693. }
  56694. return true;
  56695. }
  56696. });
  56697. };
  56698. // Exposing this primarily for unit testing.
  56699. _main.default.prototype._helpForMisusedAtTopLevelCode = helpForMisusedAtTopLevelCode;
  56700. if (document.readyState !== 'complete') {
  56701. window.addEventListener('error', helpForMisusedAtTopLevelCode, false);
  56702. // Our job is only to catch ReferenceErrors that are thrown when
  56703. // global (non-instance mode) p5 APIs are used at the top-level
  56704. // scope of a file, so we'll unbind our error listener now to make
  56705. // sure we don't log false positives later.
  56706. window.addEventListener('load', function() {
  56707. window.removeEventListener('error', helpForMisusedAtTopLevelCode, false);
  56708. });
  56709. }
  56710. var _default = _main.default;
  56711. exports.default = _default;
  56712. },
  56713. {
  56714. '../constants': 272,
  56715. '../internationalization': 281,
  56716. '../main': 283,
  56717. './browser_errors': 274,
  56718. 'core-js/modules/es.array.concat': 166,
  56719. 'core-js/modules/es.array.filter': 169,
  56720. 'core-js/modules/es.array.for-each': 170,
  56721. 'core-js/modules/es.array.includes': 172,
  56722. 'core-js/modules/es.array.iterator': 174,
  56723. 'core-js/modules/es.array.join': 175,
  56724. 'core-js/modules/es.array.map': 177,
  56725. 'core-js/modules/es.array.slice': 178,
  56726. 'core-js/modules/es.array.some': 179,
  56727. 'core-js/modules/es.function.name': 181,
  56728. 'core-js/modules/es.object.assign': 188,
  56729. 'core-js/modules/es.object.get-own-property-names': 189,
  56730. 'core-js/modules/es.object.keys': 191,
  56731. 'core-js/modules/es.object.to-string': 192,
  56732. 'core-js/modules/es.regexp.constructor': 195,
  56733. 'core-js/modules/es.regexp.exec': 196,
  56734. 'core-js/modules/es.regexp.to-string': 197,
  56735. 'core-js/modules/es.string.iterator': 201,
  56736. 'core-js/modules/es.string.match': 202,
  56737. 'core-js/modules/es.string.replace': 204,
  56738. 'core-js/modules/es.string.search': 205,
  56739. 'core-js/modules/es.string.split': 206,
  56740. 'core-js/modules/es.symbol': 211,
  56741. 'core-js/modules/es.symbol.description': 209,
  56742. 'core-js/modules/es.symbol.iterator': 210,
  56743. 'core-js/modules/web.dom-collections.for-each': 243,
  56744. 'core-js/modules/web.dom-collections.iterator': 244
  56745. }
  56746. ],
  56747. 276: [
  56748. function(_dereq_, module, exports) {
  56749. 'use strict';
  56750. Object.defineProperty(exports, '__esModule', { value: true });
  56751. exports.default = void 0;
  56752. var _main = _interopRequireDefault(_dereq_('../main'));
  56753. var _internationalization = _dereq_('../internationalization');
  56754. function _interopRequireDefault(obj) {
  56755. return obj && obj.__esModule ? obj : { default: obj };
  56756. }
  56757. /**
  56758. * @for p5
  56759. * @requires core
  56760. *
  56761. * This file contains the part of the FES responsible for dealing with
  56762. * file load errors
  56763. */ if (typeof IS_MINIFIED !== 'undefined') {
  56764. _main.default._friendlyFileLoadError = function() {};
  56765. } else {
  56766. // mapping used by `_friendlyFileLoadError`
  56767. var fileLoadErrorCases = function fileLoadErrorCases(num, filePath) {
  56768. var suggestion = (0, _internationalization.translator)(
  56769. 'fes.fileLoadError.suggestion',
  56770. {
  56771. filePath: filePath,
  56772. link: 'https://github.com/processing/p5.js/wiki/Local-server'
  56773. }
  56774. );
  56775. switch (num) {
  56776. case 0:
  56777. return {
  56778. message: (0, _internationalization.translator)(
  56779. 'fes.fileLoadError.image',
  56780. {
  56781. suggestion: suggestion
  56782. }
  56783. ),
  56784. method: 'loadImage'
  56785. };
  56786. case 1:
  56787. return {
  56788. message: (0, _internationalization.translator)(
  56789. 'fes.fileLoadError.xml',
  56790. {
  56791. suggestion: suggestion
  56792. }
  56793. ),
  56794. method: 'loadXML'
  56795. };
  56796. case 2:
  56797. return {
  56798. message: (0, _internationalization.translator)(
  56799. 'fes.fileLoadError.table',
  56800. {
  56801. suggestion: suggestion
  56802. }
  56803. ),
  56804. method: 'loadTable'
  56805. };
  56806. case 3:
  56807. return {
  56808. message: (0, _internationalization.translator)(
  56809. 'fes.fileLoadError.strings',
  56810. {
  56811. suggestion: suggestion
  56812. }
  56813. ),
  56814. method: 'loadStrings'
  56815. };
  56816. case 4:
  56817. return {
  56818. message: (0, _internationalization.translator)(
  56819. 'fes.fileLoadError.font',
  56820. {
  56821. suggestion: suggestion
  56822. }
  56823. ),
  56824. method: 'loadFont'
  56825. };
  56826. case 5:
  56827. return {
  56828. message: (0, _internationalization.translator)(
  56829. 'fes.fileLoadError.json',
  56830. {
  56831. suggestion: suggestion
  56832. }
  56833. ),
  56834. method: 'loadJSON'
  56835. };
  56836. case 6:
  56837. return {
  56838. message: (0, _internationalization.translator)(
  56839. 'fes.fileLoadError.bytes',
  56840. {
  56841. suggestion: suggestion
  56842. }
  56843. ),
  56844. method: 'loadBytes'
  56845. };
  56846. case 7:
  56847. return {
  56848. message: (0, _internationalization.translator)(
  56849. 'fes.fileLoadError.large'
  56850. ),
  56851. method: 'loadX'
  56852. };
  56853. case 8:
  56854. return {
  56855. message: (0, _internationalization.translator)('fes.fileLoadError.gif'),
  56856. method: 'loadImage'
  56857. };
  56858. }
  56859. };
  56860. /**
  56861. * This is called internally if there is a error during file loading.
  56862. *
  56863. * @method _friendlyFileLoadError
  56864. * @private
  56865. * @param {Number} errorType
  56866. * @param {String} filePath
  56867. */
  56868. _main.default._friendlyFileLoadError = function(errorType, filePath) {
  56869. var _fileLoadErrorCases = fileLoadErrorCases(errorType, filePath),
  56870. message = _fileLoadErrorCases.message,
  56871. method = _fileLoadErrorCases.method;
  56872. _main.default._friendlyError(message, method, 3);
  56873. };
  56874. }
  56875. var _default = _main.default;
  56876. exports.default = _default;
  56877. },
  56878. { '../internationalization': 281, '../main': 283 }
  56879. ],
  56880. 277: [
  56881. function(_dereq_, module, exports) {
  56882. 'use strict';
  56883. _dereq_('core-js/modules/es.array.filter');
  56884. _dereq_('core-js/modules/es.array.index-of');
  56885. _dereq_('core-js/modules/es.array.join');
  56886. _dereq_('core-js/modules/es.array.map');
  56887. _dereq_('core-js/modules/es.array.slice');
  56888. _dereq_('core-js/modules/es.regexp.exec');
  56889. _dereq_('core-js/modules/es.string.match');
  56890. _dereq_('core-js/modules/es.string.replace');
  56891. _dereq_('core-js/modules/es.string.split');
  56892. Object.defineProperty(exports, '__esModule', { value: true });
  56893. exports.default = void 0;
  56894. var _main = _interopRequireDefault(_dereq_('../main'));
  56895. function _interopRequireDefault(obj) {
  56896. return obj && obj.__esModule ? obj : { default: obj };
  56897. } /** // Borrow from stacktracejs https://github.com/stacktracejs/stacktrace.js with
  56898. * @for p5
  56899. * @requires core
  56900. */
  56901. // minor modifications. The license for the same and the code is included below
  56902. // Copyright (c) 2017 Eric Wendelin and other contributors
  56903. // Permission is hereby granted, free of charge, to any person obtaining a copy of
  56904. // this software and associated documentation files (the "Software"), to deal in
  56905. // the Software without restriction, including without limitation the rights to
  56906. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  56907. // of the Software, and to permit persons to whom the Software is furnished to do
  56908. // so, subject to the following conditions:
  56909. // The above copyright notice and this permission notice shall be included in all
  56910. // copies or substantial portions of the Software.
  56911. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  56912. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  56913. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  56914. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  56915. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  56916. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  56917. // SOFTWARE.
  56918. function ErrorStackParser() {
  56919. 'use strict';
  56920. var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+:\d+/;
  56921. var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m;
  56922. var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code])?$/;
  56923. return {
  56924. /**
  56925. * Given an Error object, extract the most information from it.
  56926. * @private
  56927. * @param {Error} error object
  56928. * @return {Array} of stack frames
  56929. */
  56930. parse: function ErrorStackParser$$parse(error) {
  56931. if (
  56932. typeof error.stacktrace !== 'undefined' ||
  56933. typeof error['opera#sourceloc'] !== 'undefined'
  56934. ) {
  56935. return this.parseOpera(error);
  56936. } else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) {
  56937. return this.parseV8OrIE(error);
  56938. } else if (error.stack) {
  56939. return this.parseFFOrSafari(error);
  56940. } else {
  56941. // throw new Error('Cannot parse given Error object');
  56942. }
  56943. },
  56944. // Separate line and column numbers from a string of the form: (URI:Line:Column)
  56945. extractLocation: function ErrorStackParser$$extractLocation(urlLike) {
  56946. // Fail-fast but return locations like "(native)"
  56947. if (urlLike.indexOf(':') === -1) {
  56948. return [urlLike];
  56949. }
  56950. var regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
  56951. var parts = regExp.exec(urlLike.replace(/[()]/g, ''));
  56952. return [parts[1], parts[2] || undefined, parts[3] || undefined];
  56953. },
  56954. parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) {
  56955. var filtered = error.stack.split('\n').filter(function(line) {
  56956. return !!line.match(CHROME_IE_STACK_REGEXP);
  56957. }, this);
  56958. return filtered.map(function(line) {
  56959. if (line.indexOf('(eval ') > -1) {
  56960. // Throw away eval information until we implement stacktrace.js/stackframe#8
  56961. line = line
  56962. .replace(/eval code/g, 'eval')
  56963. .replace(/(\(eval at [^()]*)|(\),.*$)/g, '');
  56964. }
  56965. var sanitizedLine = line.replace(/^\s+/, '').replace(/\(eval code/g, '(');
  56966. // capture and preseve the parenthesized location "(/foo/my bar.js:12:87)" in
  56967. // case it has spaces in it, as the string is split on \s+ later on
  56968. var location = sanitizedLine.match(/ (\((.+):(\d+):(\d+)\)$)/);
  56969. // remove the parenthesized location from the line, if it was matched
  56970. sanitizedLine = location
  56971. ? sanitizedLine.replace(location[0], '')
  56972. : sanitizedLine;
  56973. var tokens = sanitizedLine.split(/\s+/).slice(1);
  56974. // if a location was matched, pass it to extractLocation() otherwise pop the last token
  56975. var locationParts = this.extractLocation(
  56976. location ? location[1] : tokens.pop()
  56977. );
  56978. var functionName = tokens.join(' ') || undefined;
  56979. var fileName =
  56980. ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1
  56981. ? undefined
  56982. : locationParts[0];
  56983. return {
  56984. functionName: functionName,
  56985. fileName: fileName,
  56986. lineNumber: locationParts[1],
  56987. columnNumber: locationParts[2],
  56988. source: line
  56989. };
  56990. }, this);
  56991. },
  56992. parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) {
  56993. var filtered = error.stack.split('\n').filter(function(line) {
  56994. return !line.match(SAFARI_NATIVE_CODE_REGEXP);
  56995. }, this);
  56996. return filtered.map(function(line) {
  56997. // Throw away eval information until we implement stacktrace.js/stackframe#8
  56998. if (line.indexOf(' > eval') > -1) {
  56999. line = line.replace(
  57000. / line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,
  57001. ':$1'
  57002. );
  57003. }
  57004. if (line.indexOf('@') === -1 && line.indexOf(':') === -1) {
  57005. // Safari eval frames only have function names and nothing else
  57006. return {
  57007. functionName: line
  57008. };
  57009. } else {
  57010. var functionNameRegex = /((.*".+"[^@]*)?[^@]*)(?:@)/;
  57011. var matches = line.match(functionNameRegex);
  57012. var functionName = matches && matches[1] ? matches[1] : undefined;
  57013. var locationParts = this.extractLocation(
  57014. line.replace(functionNameRegex, '')
  57015. );
  57016. return {
  57017. functionName: functionName,
  57018. fileName: locationParts[0],
  57019. lineNumber: locationParts[1],
  57020. columnNumber: locationParts[2],
  57021. source: line
  57022. };
  57023. }
  57024. }, this);
  57025. },
  57026. parseOpera: function ErrorStackParser$$parseOpera(e) {
  57027. if (
  57028. !e.stacktrace ||
  57029. (e.message.indexOf('\n') > -1 &&
  57030. e.message.split('\n').length > e.stacktrace.split('\n').length)
  57031. ) {
  57032. return this.parseOpera9(e);
  57033. } else if (!e.stack) {
  57034. return this.parseOpera10(e);
  57035. } else {
  57036. return this.parseOpera11(e);
  57037. }
  57038. },
  57039. parseOpera9: function ErrorStackParser$$parseOpera9(e) {
  57040. var lineRE = /Line (\d+).*script (?:in )?(\S+)/i;
  57041. var lines = e.message.split('\n');
  57042. var result = [];
  57043. for (var i = 2, len = lines.length; i < len; i += 2) {
  57044. var match = lineRE.exec(lines[i]);
  57045. if (match) {
  57046. result.push({
  57047. fileName: match[2],
  57048. lineNumber: match[1],
  57049. source: lines[i]
  57050. });
  57051. }
  57052. }
  57053. return result;
  57054. },
  57055. parseOpera10: function ErrorStackParser$$parseOpera10(e) {
  57056. var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i;
  57057. var lines = e.stacktrace.split('\n');
  57058. var result = [];
  57059. for (var i = 0, len = lines.length; i < len; i += 2) {
  57060. var match = lineRE.exec(lines[i]);
  57061. if (match) {
  57062. result.push({
  57063. functionName: match[3] || undefined,
  57064. fileName: match[2],
  57065. lineNumber: match[1],
  57066. source: lines[i]
  57067. });
  57068. }
  57069. }
  57070. return result;
  57071. },
  57072. // Opera 10.65+ Error.stack very similar to FF/Safari
  57073. parseOpera11: function ErrorStackParser$$parseOpera11(error) {
  57074. var filtered = error.stack.split('\n').filter(function(line) {
  57075. return (
  57076. !!line.match(FIREFOX_SAFARI_STACK_REGEXP) &&
  57077. !line.match(/^Error created at/)
  57078. );
  57079. }, this);
  57080. return filtered.map(function(line) {
  57081. var tokens = line.split('@');
  57082. var locationParts = this.extractLocation(tokens.pop());
  57083. var functionCall = tokens.shift() || '';
  57084. var functionName =
  57085. functionCall
  57086. .replace(/<anonymous function(: (\w+))?>/, '$2')
  57087. .replace(/\([^)]*\)/g, '') || undefined;
  57088. var argsRaw;
  57089. if (functionCall.match(/\(([^)]*)\)/)) {
  57090. argsRaw = functionCall.replace(/^[^(]+\(([^)]*)\)$/, '$1');
  57091. }
  57092. var args =
  57093. argsRaw === undefined || argsRaw === '[arguments not available]'
  57094. ? undefined
  57095. : argsRaw.split(',');
  57096. return {
  57097. functionName: functionName,
  57098. args: args,
  57099. fileName: locationParts[0],
  57100. lineNumber: locationParts[1],
  57101. columnNumber: locationParts[2],
  57102. source: line
  57103. };
  57104. }, this);
  57105. }
  57106. };
  57107. }
  57108. // End borrow
  57109. // wrapper exposing ErrorStackParser
  57110. _main.default._getErrorStackParser = function getErrorStackParser() {
  57111. return new ErrorStackParser();
  57112. };
  57113. var _default = _main.default;
  57114. exports.default = _default;
  57115. },
  57116. {
  57117. '../main': 283,
  57118. 'core-js/modules/es.array.filter': 169,
  57119. 'core-js/modules/es.array.index-of': 173,
  57120. 'core-js/modules/es.array.join': 175,
  57121. 'core-js/modules/es.array.map': 177,
  57122. 'core-js/modules/es.array.slice': 178,
  57123. 'core-js/modules/es.regexp.exec': 196,
  57124. 'core-js/modules/es.string.match': 202,
  57125. 'core-js/modules/es.string.replace': 204,
  57126. 'core-js/modules/es.string.split': 206
  57127. }
  57128. ],
  57129. 278: [
  57130. function(_dereq_, module, exports) {
  57131. 'use strict';
  57132. _dereq_('core-js/modules/es.symbol');
  57133. _dereq_('core-js/modules/es.symbol.description');
  57134. _dereq_('core-js/modules/es.symbol.iterator');
  57135. _dereq_('core-js/modules/es.array.concat');
  57136. _dereq_('core-js/modules/es.array.for-each');
  57137. _dereq_('core-js/modules/es.array.includes');
  57138. _dereq_('core-js/modules/es.array.index-of');
  57139. _dereq_('core-js/modules/es.array.iterator');
  57140. _dereq_('core-js/modules/es.array.join');
  57141. _dereq_('core-js/modules/es.array.last-index-of');
  57142. _dereq_('core-js/modules/es.array.map');
  57143. _dereq_('core-js/modules/es.array.slice');
  57144. _dereq_('core-js/modules/es.function.name');
  57145. _dereq_('core-js/modules/es.map');
  57146. _dereq_('core-js/modules/es.number.constructor');
  57147. _dereq_('core-js/modules/es.object.get-prototype-of');
  57148. _dereq_('core-js/modules/es.object.keys');
  57149. _dereq_('core-js/modules/es.object.to-string');
  57150. _dereq_('core-js/modules/es.reflect.construct');
  57151. _dereq_('core-js/modules/es.regexp.exec');
  57152. _dereq_('core-js/modules/es.regexp.to-string');
  57153. _dereq_('core-js/modules/es.set');
  57154. _dereq_('core-js/modules/es.string.includes');
  57155. _dereq_('core-js/modules/es.string.iterator');
  57156. _dereq_('core-js/modules/es.string.split');
  57157. _dereq_('core-js/modules/web.dom-collections.for-each');
  57158. _dereq_('core-js/modules/web.dom-collections.iterator');
  57159. Object.defineProperty(exports, '__esModule', { value: true });
  57160. exports.default = void 0;
  57161. var _main = _interopRequireDefault(_dereq_('../main'));
  57162. var constants = _interopRequireWildcard(_dereq_('../constants'));
  57163. var _internationalization = _dereq_('../internationalization');
  57164. function _getRequireWildcardCache() {
  57165. if (typeof WeakMap !== 'function') return null;
  57166. var cache = new WeakMap();
  57167. _getRequireWildcardCache = function _getRequireWildcardCache() {
  57168. return cache;
  57169. };
  57170. return cache;
  57171. }
  57172. function _interopRequireWildcard(obj) {
  57173. if (obj && obj.__esModule) {
  57174. return obj;
  57175. }
  57176. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  57177. return { default: obj };
  57178. }
  57179. var cache = _getRequireWildcardCache();
  57180. if (cache && cache.has(obj)) {
  57181. return cache.get(obj);
  57182. }
  57183. var newObj = {};
  57184. var hasPropertyDescriptor =
  57185. Object.defineProperty && Object.getOwnPropertyDescriptor;
  57186. for (var key in obj) {
  57187. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  57188. var desc = hasPropertyDescriptor
  57189. ? Object.getOwnPropertyDescriptor(obj, key)
  57190. : null;
  57191. if (desc && (desc.get || desc.set)) {
  57192. Object.defineProperty(newObj, key, desc);
  57193. } else {
  57194. newObj[key] = obj[key];
  57195. }
  57196. }
  57197. }
  57198. newObj.default = obj;
  57199. if (cache) {
  57200. cache.set(obj, newObj);
  57201. }
  57202. return newObj;
  57203. }
  57204. function _interopRequireDefault(obj) {
  57205. return obj && obj.__esModule ? obj : { default: obj };
  57206. }
  57207. function _classCallCheck(instance, Constructor) {
  57208. if (!(instance instanceof Constructor)) {
  57209. throw new TypeError('Cannot call a class as a function');
  57210. }
  57211. }
  57212. function _inherits(subClass, superClass) {
  57213. if (typeof superClass !== 'function' && superClass !== null) {
  57214. throw new TypeError('Super expression must either be null or a function');
  57215. }
  57216. subClass.prototype = Object.create(superClass && superClass.prototype, {
  57217. constructor: { value: subClass, writable: true, configurable: true }
  57218. });
  57219. if (superClass) _setPrototypeOf(subClass, superClass);
  57220. }
  57221. function _createSuper(Derived) {
  57222. function isNativeReflectConstruct() {
  57223. if (typeof Reflect === 'undefined' || !Reflect.construct) return false;
  57224. if (Reflect.construct.sham) return false;
  57225. if (typeof Proxy === 'function') return true;
  57226. try {
  57227. Date.prototype.toString.call(Reflect.construct(Date, [], function() {}));
  57228. return true;
  57229. } catch (e) {
  57230. return false;
  57231. }
  57232. }
  57233. return function() {
  57234. var Super = _getPrototypeOf(Derived),
  57235. result;
  57236. if (isNativeReflectConstruct()) {
  57237. var NewTarget = _getPrototypeOf(this).constructor;
  57238. result = Reflect.construct(Super, arguments, NewTarget);
  57239. } else {
  57240. result = Super.apply(this, arguments);
  57241. }
  57242. return _possibleConstructorReturn(this, result);
  57243. };
  57244. }
  57245. function _possibleConstructorReturn(self, call) {
  57246. if (call && (_typeof(call) === 'object' || typeof call === 'function')) {
  57247. return call;
  57248. }
  57249. return _assertThisInitialized(self);
  57250. }
  57251. function _assertThisInitialized(self) {
  57252. if (self === void 0) {
  57253. throw new ReferenceError(
  57254. "this hasn't been initialised - super() hasn't been called"
  57255. );
  57256. }
  57257. return self;
  57258. }
  57259. function _wrapNativeSuper(Class) {
  57260. var _cache = typeof Map === 'function' ? new Map() : undefined;
  57261. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  57262. if (Class === null || !_isNativeFunction(Class)) return Class;
  57263. if (typeof Class !== 'function') {
  57264. throw new TypeError('Super expression must either be null or a function');
  57265. }
  57266. if (typeof _cache !== 'undefined') {
  57267. if (_cache.has(Class)) return _cache.get(Class);
  57268. _cache.set(Class, Wrapper);
  57269. }
  57270. function Wrapper() {
  57271. return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  57272. }
  57273. Wrapper.prototype = Object.create(Class.prototype, {
  57274. constructor: {
  57275. value: Wrapper,
  57276. enumerable: false,
  57277. writable: true,
  57278. configurable: true
  57279. }
  57280. });
  57281. return _setPrototypeOf(Wrapper, Class);
  57282. };
  57283. return _wrapNativeSuper(Class);
  57284. }
  57285. function isNativeReflectConstruct() {
  57286. if (typeof Reflect === 'undefined' || !Reflect.construct) return false;
  57287. if (Reflect.construct.sham) return false;
  57288. if (typeof Proxy === 'function') return true;
  57289. try {
  57290. Date.prototype.toString.call(Reflect.construct(Date, [], function() {}));
  57291. return true;
  57292. } catch (e) {
  57293. return false;
  57294. }
  57295. }
  57296. function _construct(Parent, args, Class) {
  57297. if (isNativeReflectConstruct()) {
  57298. _construct = Reflect.construct;
  57299. } else {
  57300. _construct = function _construct(Parent, args, Class) {
  57301. var a = [null];
  57302. a.push.apply(a, args);
  57303. var Constructor = Function.bind.apply(Parent, a);
  57304. var instance = new Constructor();
  57305. if (Class) _setPrototypeOf(instance, Class.prototype);
  57306. return instance;
  57307. };
  57308. }
  57309. return _construct.apply(null, arguments);
  57310. }
  57311. function _isNativeFunction(fn) {
  57312. return Function.toString.call(fn).indexOf('[native code]') !== -1;
  57313. }
  57314. function _setPrototypeOf(o, p) {
  57315. _setPrototypeOf =
  57316. Object.setPrototypeOf ||
  57317. function _setPrototypeOf(o, p) {
  57318. o.__proto__ = p;
  57319. return o;
  57320. };
  57321. return _setPrototypeOf(o, p);
  57322. }
  57323. function _getPrototypeOf(o) {
  57324. _getPrototypeOf = Object.setPrototypeOf
  57325. ? Object.getPrototypeOf
  57326. : function _getPrototypeOf(o) {
  57327. return o.__proto__ || Object.getPrototypeOf(o);
  57328. };
  57329. return _getPrototypeOf(o);
  57330. }
  57331. function _typeof(obj) {
  57332. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  57333. _typeof = function _typeof(obj) {
  57334. return typeof obj;
  57335. };
  57336. } else {
  57337. _typeof = function _typeof(obj) {
  57338. return obj &&
  57339. typeof Symbol === 'function' &&
  57340. obj.constructor === Symbol &&
  57341. obj !== Symbol.prototype
  57342. ? 'symbol'
  57343. : typeof obj;
  57344. };
  57345. }
  57346. return _typeof(obj);
  57347. }
  57348. if (typeof IS_MINIFIED !== 'undefined') {
  57349. _main.default._validateParameters = _main.default._clearValidateParamsCache = function() {};
  57350. } else {
  57351. // for parameter validation
  57352. var dataDoc = _dereq_('../../../docs/parameterData.json');
  57353. var arrDoc = JSON.parse(JSON.stringify(dataDoc));
  57354. var docCache = {};
  57355. var builtinTypes = new Set([
  57356. 'null',
  57357. 'number',
  57358. 'string',
  57359. 'boolean',
  57360. 'constant',
  57361. 'function',
  57362. 'any',
  57363. 'integer'
  57364. ]);
  57365. var basicTypes = {
  57366. number: true,
  57367. boolean: true,
  57368. string: true,
  57369. function: true,
  57370. undefined: true
  57371. };
  57372. // reverse map of all constants
  57373. var constantsReverseMap = {};
  57374. for (var key in constants) {
  57375. constantsReverseMap[constants[key]] = key;
  57376. }
  57377. // mapping names of p5 types to their constructor function
  57378. // p5Constructors:
  57379. // - Color: f()
  57380. // - Graphics: f()
  57381. // - Vector: f()
  57382. // and so on
  57383. var p5Constructors = {};
  57384. // For speedup over many runs. funcSpecificConstructors[func] only has the
  57385. // constructors for types which were seen earlier as args of "func"
  57386. var funcSpecificConstructors = {};
  57387. window.addEventListener('load', function() {
  57388. // Make a list of all p5 classes to be used for argument validation
  57389. // This must be done only when everything has loaded otherwise we get
  57390. // an empty array
  57391. for (
  57392. var _i = 0, _Object$keys = Object.keys(_main.default);
  57393. _i < _Object$keys.length;
  57394. _i++
  57395. ) {
  57396. var _key = _Object$keys[_i];
  57397. // Get a list of all constructors in p5. They are functions whose names
  57398. // start with a capital letter
  57399. if (
  57400. typeof _main.default[_key] === 'function' &&
  57401. _key[0] !== _key[0].toLowerCase()
  57402. ) {
  57403. p5Constructors[_key] = _main.default[_key];
  57404. }
  57405. }
  57406. });
  57407. var argumentTree = {};
  57408. // The following two functions are responsible for querying and inserting
  57409. // into the argument tree. It stores the types of arguments that each
  57410. // function has seen so far. It is used to query if a sequence of
  57411. // arguments seen in validate parameters was seen before.
  57412. // Lets consider that the following segment of code runs repeatedly, perhaps
  57413. // in a loop or in draw()
  57414. // color(10, 10, 10);
  57415. // color(10, 10);
  57416. // color('r', 'g', 'b');
  57417. // After the first of run the code segment, the argument tree looks like
  57418. // - color
  57419. // - number
  57420. // - number
  57421. // - number
  57422. // - seen: true
  57423. // - seen: true
  57424. // - string
  57425. // - string
  57426. // - string
  57427. // - seen: true
  57428. // seen: true signifies that this argument was also seen as the last
  57429. // argument in a call. Now in the second run of the sketch, it would traverse
  57430. // the existing tree and see seen: true, i.e this sequence was seen
  57431. // before and so scoring can be skipped. This also prevents logging multiple
  57432. // validation messages for the same thing.
  57433. // These two functions would be called repeatedly over and over again,
  57434. // so they need to be as optimized for performance as possible
  57435. var addType = function addType(value, obj, func) {
  57436. var type = _typeof(value);
  57437. if (basicTypes[type]) {
  57438. if (constantsReverseMap[value]) {
  57439. // check if the value is a p5 constant and if it is, we would want the
  57440. // value itself to be stored in the tree instead of the type
  57441. obj = obj[value] || (obj[value] = {});
  57442. } else {
  57443. obj = obj[type] || (obj[type] = {});
  57444. }
  57445. } else if (value === null) {
  57446. // typeof null -> "object". don't want that
  57447. obj = obj['null'] || (obj['null'] = {});
  57448. } else {
  57449. // objects which are instances of p5 classes have nameless constructors.
  57450. // native objects have a constructor named "Object". This check
  57451. // differentiates between the two so that we dont waste time finding the
  57452. // p5 class if we just have a native object
  57453. if (value.constructor && value.constructor.name) {
  57454. obj = obj[value.constructor.name] || (obj[value.constructor.name] = {});
  57455. return obj;
  57456. }
  57457. // constructors for types defined in p5 do not have a name property.
  57458. // e.constructor.name gives "". Code in this segment is a workaround for it
  57459. // p5C will only have the name: constructor mapping for types
  57460. // which were already seen as args of "func"
  57461. var p5C = funcSpecificConstructors[func];
  57462. // p5C would contain much fewer items than p5Constructors. if we find our
  57463. // answer in p5C, we don't have to scan through p5Constructors
  57464. if (p5C === undefined) {
  57465. // if there isn't an entry yet for func
  57466. // make an entry of empty object
  57467. p5C = funcSpecificConstructors[func] = {};
  57468. }
  57469. for (var _key2 in p5C) {
  57470. // search on the constructors we have already seen (smaller search space)
  57471. if (value instanceof p5C[_key2]) {
  57472. obj = obj[_key2] || (obj[_key2] = {});
  57473. return obj;
  57474. }
  57475. }
  57476. for (var _key3 in p5Constructors) {
  57477. // if the above search didn't work, search on all p5 constructors
  57478. if (value instanceof p5Constructors[_key3]) {
  57479. obj = obj[_key3] || (obj[_key3] = {});
  57480. // if found, add to known constructors for this function
  57481. p5C[_key3] = p5Constructors[_key3];
  57482. return obj;
  57483. }
  57484. }
  57485. // nothing worked, put the type as is
  57486. obj = obj[type] || (obj[type] = {});
  57487. }
  57488. return obj;
  57489. };
  57490. var buildArgTypeCache = function buildArgTypeCache(func, arr) {
  57491. // get the if an argument tree for current function already exists
  57492. var obj = argumentTree[func];
  57493. if (obj === undefined) {
  57494. // if it doesn't, create an empty tree
  57495. obj = argumentTree[func] = {};
  57496. }
  57497. for (var i = 0, len = arr.length; i < len; ++i) {
  57498. var value = arr[i];
  57499. if (value instanceof Array) {
  57500. // an array is passed as an argument, expand it and get the type of
  57501. // each of its element. We distinguish the start of an array with 'as'
  57502. // or arraystart. This would help distinguish between the arguments
  57503. // (number, number, number) and (number, [number, number])
  57504. obj = obj['as'] || (obj['as'] = {});
  57505. for (var j = 0, lenA = value.length; j < lenA; ++j) {
  57506. obj = addType(value[j], obj, func);
  57507. }
  57508. } else {
  57509. obj = addType(value, obj, func);
  57510. }
  57511. }
  57512. return obj;
  57513. };
  57514. // validateParameters() helper functions:
  57515. // lookupParamDoc() for querying data.json
  57516. var lookupParamDoc = function lookupParamDoc(func) {
  57517. // look for the docs in the `data.json` datastructure
  57518. var ichDot = func.lastIndexOf('.');
  57519. var funcName = func.substr(ichDot + 1);
  57520. var funcClass = func.substr(0, ichDot) || 'p5';
  57521. var classitems = arrDoc;
  57522. var queryResult = classitems[funcClass][funcName];
  57523. // different JSON structure for funct with multi-format
  57524. var overloads = [];
  57525. if (queryResult.hasOwnProperty('overloads')) {
  57526. // add all the overloads
  57527. for (var i = 0; i < queryResult.overloads.length; i++) {
  57528. overloads.push({ formats: queryResult.overloads[i].params });
  57529. }
  57530. } else {
  57531. // no overloads, just add the main method definition
  57532. overloads.push({ formats: queryResult.params || [] });
  57533. }
  57534. // parse the parameter types for each overload
  57535. var mapConstants = {};
  57536. var maxParams = 0;
  57537. overloads.forEach(function(overload) {
  57538. var formats = overload.formats;
  57539. // keep a record of the maximum number of arguments
  57540. // this method requires.
  57541. if (maxParams < formats.length) {
  57542. maxParams = formats.length;
  57543. }
  57544. // calculate the minimum number of arguments
  57545. // this overload requires.
  57546. var minParams = formats.length;
  57547. while (minParams > 0 && formats[minParams - 1].optional) {
  57548. minParams--;
  57549. }
  57550. overload.minParams = minParams;
  57551. // loop through each parameter position, and parse its types
  57552. formats.forEach(function(format) {
  57553. // split this parameter's types
  57554. format.types = format.type.split('|').map(function ct(type) {
  57555. // array
  57556. if (type.substr(type.length - 2, 2) === '[]') {
  57557. return {
  57558. name: type,
  57559. array: ct(type.substr(0, type.length - 2))
  57560. };
  57561. }
  57562. var lowerType = type.toLowerCase();
  57563. // contant
  57564. if (lowerType === 'constant') {
  57565. var constant;
  57566. if (mapConstants.hasOwnProperty(format.name)) {
  57567. constant = mapConstants[format.name];
  57568. } else {
  57569. // parse possible constant values from description
  57570. var myRe = /either\s+(?:[A-Z0-9_]+\s*,?\s*(?:or)?\s*)+/g;
  57571. var values = {};
  57572. var names = [];
  57573. constant = mapConstants[format.name] = {
  57574. values: values,
  57575. names: names
  57576. };
  57577. var myArray = myRe.exec(format.description);
  57578. if (func === 'endShape' && format.name === 'mode') {
  57579. values[constants.CLOSE] = true;
  57580. names.push('CLOSE');
  57581. } else {
  57582. var match = myArray[0];
  57583. var reConst = /[A-Z0-9_]+/g;
  57584. var matchConst;
  57585. while ((matchConst = reConst.exec(match)) !== null) {
  57586. var name = matchConst[0];
  57587. if (constants.hasOwnProperty(name)) {
  57588. values[constants[name]] = true;
  57589. names.push(name);
  57590. }
  57591. }
  57592. }
  57593. }
  57594. return {
  57595. name: type,
  57596. builtin: lowerType,
  57597. names: constant.names,
  57598. values: constant.values
  57599. };
  57600. }
  57601. // function
  57602. if (lowerType.substr(0, 'function'.length) === 'function') {
  57603. lowerType = 'function';
  57604. }
  57605. // builtin
  57606. if (builtinTypes.has(lowerType)) {
  57607. return { name: type, builtin: lowerType };
  57608. }
  57609. // find type's prototype
  57610. var t = window;
  57611. var typeParts = type.split('.');
  57612. // special-case 'p5' since it may be non-global
  57613. if (typeParts[0] === 'p5') {
  57614. t = _main.default;
  57615. typeParts.shift();
  57616. }
  57617. typeParts.forEach(function(p) {
  57618. t = t && t[p];
  57619. });
  57620. if (t) {
  57621. return { name: type, prototype: t };
  57622. }
  57623. return { name: type, type: lowerType };
  57624. });
  57625. });
  57626. });
  57627. return {
  57628. overloads: overloads,
  57629. maxParams: maxParams
  57630. };
  57631. };
  57632. var isNumber = function isNumber(param) {
  57633. switch (_typeof(param)) {
  57634. case 'number':
  57635. return true;
  57636. case 'string':
  57637. return !isNaN(param);
  57638. default:
  57639. return false;
  57640. }
  57641. };
  57642. var testParamType = function testParamType(param, type) {
  57643. var isArray = param instanceof Array;
  57644. var matches = true;
  57645. if (type.array && isArray) {
  57646. for (var i = 0; i < param.length; i++) {
  57647. var error = testParamType(param[i], type.array);
  57648. if (error) return error / 2; // half error for elements
  57649. }
  57650. } else if (type.prototype) {
  57651. matches = param instanceof type.prototype;
  57652. } else if (type.builtin) {
  57653. switch (type.builtin) {
  57654. case 'number':
  57655. matches = isNumber(param);
  57656. break;
  57657. case 'integer':
  57658. matches = isNumber(param) && Number(param) === Math.floor(param);
  57659. break;
  57660. case 'boolean':
  57661. case 'any':
  57662. matches = true;
  57663. break;
  57664. case 'array':
  57665. matches = isArray;
  57666. break;
  57667. case 'string':
  57668. matches = /*typeof param === 'number' ||*/ typeof param === 'string';
  57669. break;
  57670. case 'constant':
  57671. matches = type.values.hasOwnProperty(param);
  57672. break;
  57673. case 'function':
  57674. matches = param instanceof Function;
  57675. break;
  57676. case 'null':
  57677. matches = param === null;
  57678. break;
  57679. }
  57680. } else {
  57681. matches = _typeof(param) === type.t;
  57682. }
  57683. return matches ? 0 : 1;
  57684. };
  57685. // testType() for non-object type parameter validation
  57686. var testParamTypes = function testParamTypes(param, types) {
  57687. var minScore = 9999;
  57688. for (var i = 0; minScore > 0 && i < types.length; i++) {
  57689. var score = testParamType(param, types[i]);
  57690. if (minScore > score) minScore = score;
  57691. }
  57692. return minScore;
  57693. };
  57694. // generate a score (higher is worse) for applying these args to
  57695. // this overload.
  57696. var scoreOverload = function scoreOverload(args, argCount, overload, minScore) {
  57697. var score = 0;
  57698. var formats = overload.formats;
  57699. var minParams = overload.minParams;
  57700. // check for too few/many args
  57701. // the score is double number of extra/missing args
  57702. if (argCount < minParams) {
  57703. score = (minParams - argCount) * 2;
  57704. } else if (argCount > formats.length) {
  57705. score = (argCount - formats.length) * 2;
  57706. }
  57707. // loop through the formats, adding up the error score for each arg.
  57708. // quit early if the score gets higher than the previous best overload.
  57709. for (var p = 0; score <= minScore && p < formats.length; p++) {
  57710. var arg = args[p];
  57711. var format = formats[p];
  57712. // '== null' checks for 'null' and typeof 'undefined'
  57713. if (arg == null) {
  57714. // handle undefined args
  57715. if (!format.optional || p < minParams || p < argCount) {
  57716. score += 1;
  57717. }
  57718. } else {
  57719. score += testParamTypes(arg, format.types);
  57720. }
  57721. }
  57722. return score;
  57723. };
  57724. // gets a list of errors for this overload
  57725. var getOverloadErrors = function getOverloadErrors(args, argCount, overload) {
  57726. var formats = overload.formats;
  57727. var minParams = overload.minParams;
  57728. // check for too few/many args
  57729. if (argCount < minParams) {
  57730. return [
  57731. {
  57732. type: 'TOO_FEW_ARGUMENTS',
  57733. argCount: argCount,
  57734. minParams: minParams
  57735. }
  57736. ];
  57737. } else if (argCount > formats.length) {
  57738. return [
  57739. {
  57740. type: 'TOO_MANY_ARGUMENTS',
  57741. argCount: argCount,
  57742. maxParams: formats.length
  57743. }
  57744. ];
  57745. }
  57746. var errorArray = [];
  57747. for (var p = 0; p < formats.length; p++) {
  57748. var arg = args[p];
  57749. var format = formats[p];
  57750. // '== null' checks for 'null' and typeof 'undefined'
  57751. if (arg == null) {
  57752. // handle undefined args
  57753. if (!format.optional || p < minParams || p < argCount) {
  57754. errorArray.push({
  57755. type: 'EMPTY_VAR',
  57756. position: p,
  57757. format: format
  57758. });
  57759. }
  57760. } else if (testParamTypes(arg, format.types) > 0) {
  57761. errorArray.push({
  57762. type: 'WRONG_TYPE',
  57763. position: p,
  57764. format: format,
  57765. arg: arg
  57766. });
  57767. }
  57768. }
  57769. return errorArray;
  57770. };
  57771. // a custom error type, used by the mocha
  57772. // tests when expecting validation errors
  57773. _main.default.ValidationError = (function(name) {
  57774. var err = /*#__PURE__*/ (function(_Error) {
  57775. _inherits(err, _Error);
  57776. var _super = _createSuper(err);
  57777. function err(message, func, type) {
  57778. var _this;
  57779. _classCallCheck(this, err);
  57780. _this = _super.call(this);
  57781. _this.message = message;
  57782. _this.func = func;
  57783. _this.type = type;
  57784. if ('captureStackTrace' in Error)
  57785. Error.captureStackTrace(_assertThisInitialized(_this), err);
  57786. else _this.stack = new Error().stack;
  57787. return _this;
  57788. }
  57789. return err;
  57790. })(/*#__PURE__*/ _wrapNativeSuper(Error));
  57791. err.prototype.name = name;
  57792. return err;
  57793. })('ValidationError');
  57794. // function for generating console.log() msg
  57795. _main.default._friendlyParamError = function(errorObj, func) {
  57796. var message;
  57797. var translationObj;
  57798. function formatType() {
  57799. var format = errorObj.format;
  57800. return format.types
  57801. .map(function(type) {
  57802. return type.names ? type.names.join('|') : type.name;
  57803. })
  57804. .join('|');
  57805. }
  57806. switch (errorObj.type) {
  57807. case 'EMPTY_VAR': {
  57808. translationObj = {
  57809. func: func,
  57810. formatType: formatType(),
  57811. // It needs to be this way for i18next-extract to work. The comment
  57812. // specifies the values that the context can take so that it can
  57813. // statically prepare the translation files with them.
  57814. /* i18next-extract-mark-context-next-line ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"] */
  57815. position: (0, _internationalization.translator)('fes.positions.p', {
  57816. context: (errorObj.position + 1).toString(),
  57817. defaultValue: (errorObj.position + 1).toString()
  57818. }),
  57819. link: '[https://p5js.org/examples/data-variable-scope.html]'
  57820. };
  57821. break;
  57822. }
  57823. case 'WRONG_TYPE': {
  57824. var arg = errorObj.arg;
  57825. var argType =
  57826. arg instanceof Array
  57827. ? 'array'
  57828. : arg === null ? 'null' : arg.name || _typeof(arg);
  57829. translationObj = {
  57830. func: func,
  57831. formatType: formatType(),
  57832. argType: argType,
  57833. /* i18next-extract-mark-context-next-line ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"] */
  57834. position: (0, _internationalization.translator)('fes.positions.p', {
  57835. context: (errorObj.position + 1).toString(),
  57836. defaultValue: (errorObj.position + 1).toString()
  57837. })
  57838. };
  57839. break;
  57840. }
  57841. case 'TOO_FEW_ARGUMENTS': {
  57842. translationObj = {
  57843. func: func,
  57844. minParams: errorObj.minParams,
  57845. argCount: errorObj.argCount
  57846. };
  57847. break;
  57848. }
  57849. case 'TOO_MANY_ARGUMENTS': {
  57850. translationObj = {
  57851. func: func,
  57852. maxParams: errorObj.maxParams,
  57853. argCount: errorObj.argCount
  57854. };
  57855. break;
  57856. }
  57857. }
  57858. if (translationObj) {
  57859. try {
  57860. // const re = /Function\.validateParameters.*[\r\n].*[\r\n].*\(([^)]*)/;
  57861. var myError = new Error();
  57862. var parsed = _main.default._getErrorStackParser().parse(myError);
  57863. if (
  57864. parsed[3] &&
  57865. parsed[3].functionName &&
  57866. parsed[3].functionName.includes('.') &&
  57867. _main.default.prototype[parsed[3].functionName.split('.').slice(-1)[0]]
  57868. ) {
  57869. return;
  57870. }
  57871. if (_main.default._throwValidationErrors) {
  57872. throw new _main.default.ValidationError(message, func, errorObj.type);
  57873. }
  57874. // try to extract the location from where the function was called
  57875. if (
  57876. parsed[3] &&
  57877. parsed[3].fileName &&
  57878. parsed[3].lineNumber &&
  57879. parsed[3].columnNumber
  57880. ) {
  57881. var location = ''
  57882. .concat(parsed[3].fileName, ':')
  57883. .concat(parsed[3].lineNumber, ':')
  57884. .concat(parsed[3].columnNumber);
  57885. translationObj.location = (0, _internationalization.translator)(
  57886. 'fes.location',
  57887. {
  57888. location: location,
  57889. // for e.g. get "sketch.js" from "https://example.com/abc/sketch.js"
  57890. file: parsed[3].fileName.split('/').slice(-1),
  57891. line: parsed[3].lineNumber
  57892. }
  57893. );
  57894. // tell fesErrorMonitor that we have already given a friendly message
  57895. // for this line, so it need not to do the same in case of an error
  57896. _main.default._fesLogCache[location] = true;
  57897. }
  57898. } catch (err) {
  57899. if (err instanceof _main.default.ValidationError) {
  57900. throw err;
  57901. }
  57902. }
  57903. translationObj.context = errorObj.type;
  57904. // i18next-extract-mark-context-next-line ["EMPTY_VAR", "TOO_MANY_ARGUMENTS", "TOO_FEW_ARGUMENTS", "WRONG_TYPE"]
  57905. message = (0, _internationalization.translator)(
  57906. 'fes.friendlyParamError.type',
  57907. translationObj
  57908. );
  57909. _main.default._friendlyError(''.concat(message, '.'), func, 3);
  57910. }
  57911. };
  57912. // if a function is called with some set of wrong arguments, and then called
  57913. // again with the same set of arguments, the messages due to the second call
  57914. // will be supressed. If two tests test on the same wrong arguments, the
  57915. // second test won't see the validationError. clearing argumentTree solves it
  57916. _main.default._clearValidateParamsCache = function clearValidateParamsCache() {
  57917. for (
  57918. var _i2 = 0, _Object$keys2 = Object.keys(argumentTree);
  57919. _i2 < _Object$keys2.length;
  57920. _i2++
  57921. ) {
  57922. var _key4 = _Object$keys2[_i2];
  57923. delete argumentTree[_key4];
  57924. }
  57925. };
  57926. // allowing access to argumentTree for testing
  57927. _main.default._getValidateParamsArgTree = function getValidateParamsArgTree() {
  57928. return argumentTree;
  57929. };
  57930. /**
  57931. * Validates parameters
  57932. * param {String} func the name of the function
  57933. * param {Array} args user input arguments
  57934. *
  57935. * example:
  57936. * const a;
  57937. * ellipse(10,10,a,5);
  57938. * console ouput:
  57939. * "It looks like ellipse received an empty variable in spot #2."
  57940. *
  57941. * example:
  57942. * ellipse(10,"foo",5,5);
  57943. * console output:
  57944. * "ellipse was expecting a number for parameter #1,
  57945. * received "foo" instead."
  57946. */
  57947. _main.default._validateParameters = function validateParameters(func, args) {
  57948. if (_main.default.disableFriendlyErrors) {
  57949. return; // skip FES
  57950. }
  57951. // query / build the argument type tree and check if this sequence
  57952. // has already been seen before.
  57953. var obj = buildArgTypeCache(func, args);
  57954. if (obj.seen) {
  57955. return;
  57956. }
  57957. // mark this sequence as seen
  57958. obj.seen = true;
  57959. // lookup the docs in the 'data.json' file
  57960. var docs = docCache[func] || (docCache[func] = lookupParamDoc(func));
  57961. var overloads = docs.overloads;
  57962. var argCount = args.length;
  57963. // the following line ignores trailing undefined arguments, commenting
  57964. // it to resolve https://github.com/processing/p5.js/issues/4571
  57965. // '== null' checks for 'null' and typeof 'undefined'
  57966. // while (argCount > 0 && args[argCount - 1] == null) argCount--;
  57967. // find the overload with the best score
  57968. var minScore = 99999;
  57969. var minOverload;
  57970. for (var i = 0; i < overloads.length; i++) {
  57971. var score = scoreOverload(args, argCount, overloads[i], minScore);
  57972. if (score === 0) {
  57973. return; // done!
  57974. } else if (minScore > score) {
  57975. // this score is better that what we have so far...
  57976. minScore = score;
  57977. minOverload = i;
  57978. }
  57979. }
  57980. // this should _always_ be true here...
  57981. if (minScore > 0) {
  57982. // get the errors for the best overload
  57983. var errorArray = getOverloadErrors(args, argCount, overloads[minOverload]);
  57984. // generate err msg
  57985. for (var n = 0; n < errorArray.length; n++) {
  57986. _main.default._friendlyParamError(errorArray[n], func);
  57987. }
  57988. }
  57989. };
  57990. _main.default.prototype._validateParameters = _main.default.validateParameters;
  57991. }
  57992. var _default = _main.default;
  57993. exports.default = _default;
  57994. },
  57995. {
  57996. '../../../docs/parameterData.json': 1,
  57997. '../constants': 272,
  57998. '../internationalization': 281,
  57999. '../main': 283,
  58000. 'core-js/modules/es.array.concat': 166,
  58001. 'core-js/modules/es.array.for-each': 170,
  58002. 'core-js/modules/es.array.includes': 172,
  58003. 'core-js/modules/es.array.index-of': 173,
  58004. 'core-js/modules/es.array.iterator': 174,
  58005. 'core-js/modules/es.array.join': 175,
  58006. 'core-js/modules/es.array.last-index-of': 176,
  58007. 'core-js/modules/es.array.map': 177,
  58008. 'core-js/modules/es.array.slice': 178,
  58009. 'core-js/modules/es.function.name': 181,
  58010. 'core-js/modules/es.map': 182,
  58011. 'core-js/modules/es.number.constructor': 185,
  58012. 'core-js/modules/es.object.get-prototype-of': 190,
  58013. 'core-js/modules/es.object.keys': 191,
  58014. 'core-js/modules/es.object.to-string': 192,
  58015. 'core-js/modules/es.reflect.construct': 194,
  58016. 'core-js/modules/es.regexp.exec': 196,
  58017. 'core-js/modules/es.regexp.to-string': 197,
  58018. 'core-js/modules/es.set': 198,
  58019. 'core-js/modules/es.string.includes': 200,
  58020. 'core-js/modules/es.string.iterator': 201,
  58021. 'core-js/modules/es.string.split': 206,
  58022. 'core-js/modules/es.symbol': 211,
  58023. 'core-js/modules/es.symbol.description': 209,
  58024. 'core-js/modules/es.symbol.iterator': 210,
  58025. 'core-js/modules/web.dom-collections.for-each': 243,
  58026. 'core-js/modules/web.dom-collections.iterator': 244
  58027. }
  58028. ],
  58029. 279: [
  58030. function(_dereq_, module, exports) {
  58031. 'use strict';
  58032. function _typeof(obj) {
  58033. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  58034. _typeof = function _typeof(obj) {
  58035. return typeof obj;
  58036. };
  58037. } else {
  58038. _typeof = function _typeof(obj) {
  58039. return obj &&
  58040. typeof Symbol === 'function' &&
  58041. obj.constructor === Symbol &&
  58042. obj !== Symbol.prototype
  58043. ? 'symbol'
  58044. : typeof obj;
  58045. };
  58046. }
  58047. return _typeof(obj);
  58048. }
  58049. Object.defineProperty(exports, '__esModule', { value: true });
  58050. exports.default = void 0;
  58051. var constants = _interopRequireWildcard(_dereq_('./constants'));
  58052. function _getRequireWildcardCache() {
  58053. if (typeof WeakMap !== 'function') return null;
  58054. var cache = new WeakMap();
  58055. _getRequireWildcardCache = function _getRequireWildcardCache() {
  58056. return cache;
  58057. };
  58058. return cache;
  58059. }
  58060. function _interopRequireWildcard(obj) {
  58061. if (obj && obj.__esModule) {
  58062. return obj;
  58063. }
  58064. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  58065. return { default: obj };
  58066. }
  58067. var cache = _getRequireWildcardCache();
  58068. if (cache && cache.has(obj)) {
  58069. return cache.get(obj);
  58070. }
  58071. var newObj = {};
  58072. var hasPropertyDescriptor =
  58073. Object.defineProperty && Object.getOwnPropertyDescriptor;
  58074. for (var key in obj) {
  58075. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  58076. var desc = hasPropertyDescriptor
  58077. ? Object.getOwnPropertyDescriptor(obj, key)
  58078. : null;
  58079. if (desc && (desc.get || desc.set)) {
  58080. Object.defineProperty(newObj, key, desc);
  58081. } else {
  58082. newObj[key] = obj[key];
  58083. }
  58084. }
  58085. }
  58086. newObj.default = obj;
  58087. if (cache) {
  58088. cache.set(obj, newObj);
  58089. }
  58090. return newObj;
  58091. }
  58092. /**
  58093. * @requires constants
  58094. */ function modeAdjust(a, b, c, d, mode) {
  58095. if (mode === constants.CORNER) {
  58096. return { x: a, y: b, w: c, h: d };
  58097. } else if (mode === constants.CORNERS) {
  58098. return { x: a, y: b, w: c - a, h: d - b };
  58099. } else if (mode === constants.RADIUS) {
  58100. return { x: a - c, y: b - d, w: 2 * c, h: 2 * d };
  58101. } else if (mode === constants.CENTER) {
  58102. return { x: a - c * 0.5, y: b - d * 0.5, w: c, h: d };
  58103. }
  58104. }
  58105. var _default = { modeAdjust: modeAdjust };
  58106. exports.default = _default;
  58107. },
  58108. { './constants': 272 }
  58109. ],
  58110. 280: [
  58111. function(_dereq_, module, exports) {
  58112. 'use strict';
  58113. _dereq_('core-js/modules/es.array.iterator');
  58114. _dereq_('core-js/modules/es.object.to-string');
  58115. _dereq_('core-js/modules/es.promise');
  58116. _dereq_('core-js/modules/es.string.iterator');
  58117. _dereq_('core-js/modules/web.dom-collections.iterator');
  58118. var _main = _interopRequireDefault(_dereq_('../core/main'));
  58119. var _internationalization = _dereq_('./internationalization');
  58120. function _interopRequireDefault(obj) {
  58121. return obj && obj.__esModule ? obj : { default: obj };
  58122. }
  58123. /**
  58124. * _globalInit
  58125. *
  58126. * TODO: ???
  58127. * if sketch is on window
  58128. * assume "global" mode
  58129. * and instantiate p5 automatically
  58130. * otherwise do nothing
  58131. *
  58132. * @private
  58133. * @return {Undefined}
  58134. */
  58135. var _globalInit = function _globalInit() {
  58136. // Could have been any property defined within the p5 constructor.
  58137. // If that property is already a part of the global object,
  58138. // this code has already run before, likely due to a duplicate import
  58139. if (typeof window._setupDone !== 'undefined') {
  58140. console.warn(
  58141. 'p5.js seems to have been imported multiple times. Please remove the duplicate import'
  58142. );
  58143. return;
  58144. }
  58145. if (!window.mocha) {
  58146. // If there is a setup or draw function on the window
  58147. // then instantiate p5 in "global" mode
  58148. if (
  58149. ((window.setup && typeof window.setup === 'function') ||
  58150. (window.draw && typeof window.draw === 'function')) &&
  58151. !_main.default.instance
  58152. ) {
  58153. new _main.default();
  58154. }
  58155. }
  58156. };
  58157. // make a promise that resolves when the document is ready
  58158. var waitForDocumentReady = function waitForDocumentReady() {
  58159. return new Promise(function(resolve, reject) {
  58160. // if the page is ready, initialize p5 immediately
  58161. if (document.readyState === 'complete') {
  58162. resolve();
  58163. // if the page is still loading, add an event listener
  58164. // and initialize p5 as soon as it finishes loading
  58165. } else {
  58166. window.addEventListener('load', resolve, false);
  58167. }
  58168. });
  58169. };
  58170. // only load translations if we're using the full, un-minified library
  58171. var waitingForTranslator =
  58172. typeof IS_MINIFIED === 'undefined'
  58173. ? (0, _internationalization.initialize)()
  58174. : Promise.resolve();
  58175. Promise.all([waitForDocumentReady(), waitingForTranslator]).then(_globalInit);
  58176. },
  58177. {
  58178. '../core/main': 283,
  58179. './internationalization': 281,
  58180. 'core-js/modules/es.array.iterator': 174,
  58181. 'core-js/modules/es.object.to-string': 192,
  58182. 'core-js/modules/es.promise': 193,
  58183. 'core-js/modules/es.string.iterator': 201,
  58184. 'core-js/modules/web.dom-collections.iterator': 244
  58185. }
  58186. ],
  58187. 281: [
  58188. function(_dereq_, module, exports) {
  58189. 'use strict';
  58190. _dereq_('core-js/modules/es.array.includes');
  58191. _dereq_('core-js/modules/es.array.iterator');
  58192. _dereq_('core-js/modules/es.array.join');
  58193. _dereq_('core-js/modules/es.array.slice');
  58194. _dereq_('core-js/modules/es.object.keys');
  58195. _dereq_('core-js/modules/es.object.to-string');
  58196. _dereq_('core-js/modules/es.promise');
  58197. _dereq_('core-js/modules/es.regexp.exec');
  58198. _dereq_('core-js/modules/es.string.includes');
  58199. _dereq_('core-js/modules/es.string.iterator');
  58200. _dereq_('core-js/modules/es.string.split');
  58201. _dereq_('core-js/modules/web.dom-collections.iterator');
  58202. Object.defineProperty(exports, '__esModule', { value: true });
  58203. exports.initialize = exports.translator = void 0;
  58204. var _i18next = _interopRequireDefault(_dereq_('i18next'));
  58205. var _i18nextBrowserLanguagedetector = _interopRequireDefault(
  58206. _dereq_('i18next-browser-languagedetector')
  58207. );
  58208. function _interopRequireDefault(obj) {
  58209. return obj && obj.__esModule ? obj : { default: obj };
  58210. }
  58211. function _classCallCheck(instance, Constructor) {
  58212. if (!(instance instanceof Constructor)) {
  58213. throw new TypeError('Cannot call a class as a function');
  58214. }
  58215. }
  58216. function _defineProperties(target, props) {
  58217. for (var i = 0; i < props.length; i++) {
  58218. var descriptor = props[i];
  58219. descriptor.enumerable = descriptor.enumerable || false;
  58220. descriptor.configurable = true;
  58221. if ('value' in descriptor) descriptor.writable = true;
  58222. Object.defineProperty(target, descriptor.key, descriptor);
  58223. }
  58224. }
  58225. function _createClass(Constructor, protoProps, staticProps) {
  58226. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  58227. if (staticProps) _defineProperties(Constructor, staticProps);
  58228. return Constructor;
  58229. }
  58230. var fallbackResources, languages;
  58231. if (typeof IS_MINIFIED === 'undefined') {
  58232. // internationalization is only for the unminified build
  58233. var translationsModule = _dereq_('../../translations');
  58234. fallbackResources = translationsModule.default;
  58235. languages = translationsModule.languages;
  58236. if (typeof P5_DEV_BUILD !== 'undefined') {
  58237. // When the library is built in development mode ( using npm run dev )
  58238. // we want to use the current translation files on the disk, which may have
  58239. // been updated but not yet pushed to the CDN.
  58240. var completeResources = _dereq_('../../translations/dev');
  58241. for (
  58242. var _i = 0, _Object$keys = Object.keys(completeResources);
  58243. _i < _Object$keys.length;
  58244. _i++
  58245. ) {
  58246. var language = _Object$keys[_i];
  58247. // In es_translation, language is es and namespace is translation
  58248. // In es_MX_translation, language is es-MX and namespace is translation
  58249. var parts = language.split('_');
  58250. var lng = parts.slice(0, parts.length - 1).join('-');
  58251. var ns = parts[parts.length - 1];
  58252. fallbackResources[lng] = fallbackResources[lng] || {};
  58253. fallbackResources[lng][ns] = completeResources[language];
  58254. }
  58255. }
  58256. }
  58257. /**
  58258. * This is our i18next "backend" plugin. It tries to fetch languages
  58259. * from a CDN.
  58260. */ var FetchResources = /*#__PURE__*/ (function() {
  58261. function FetchResources(services, options) {
  58262. _classCallCheck(this, FetchResources);
  58263. this.init(services, options);
  58264. }
  58265. // run fetch with a timeout. Automatically rejects on timeout
  58266. // default timeout = 2000 ms
  58267. _createClass(FetchResources, [
  58268. {
  58269. key: 'fetchWithTimeout',
  58270. value: function fetchWithTimeout(url, options) {
  58271. var timeout =
  58272. arguments.length > 2 && arguments[2] !== undefined
  58273. ? arguments[2]
  58274. : 2000;
  58275. return Promise.race([
  58276. fetch(url, options),
  58277. new Promise(function(_, reject) {
  58278. return setTimeout(function() {
  58279. return reject(new Error('timeout'));
  58280. }, timeout);
  58281. })
  58282. ]);
  58283. }
  58284. },
  58285. {
  58286. key: 'init',
  58287. value: function init(services) {
  58288. var options =
  58289. arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  58290. this.services = services;
  58291. this.options = options;
  58292. }
  58293. },
  58294. {
  58295. key: 'read',
  58296. value: function read(language, namespace, callback) {
  58297. var loadPath = this.options.loadPath;
  58298. if (language === this.options.fallback) {
  58299. // if the default language of the user is the same as our inbuilt fallback,
  58300. // there's no need to fetch resources from the cdn. This won't actually
  58301. // need to run when we use "partialBundledLanguages" in the init
  58302. // function.
  58303. callback(null, fallbackResources[language][namespace]);
  58304. } else if (languages.includes(language)) {
  58305. // The user's language is included in the list of languages
  58306. // that we so far added translations for.
  58307. var url = this.services.interpolator.interpolate(loadPath, {
  58308. lng: language,
  58309. ns: namespace
  58310. });
  58311. this.loadUrl(url, callback);
  58312. } else {
  58313. // We don't have translations for this language. i18next will use
  58314. // the default language instead.
  58315. callback('Not found', false);
  58316. }
  58317. }
  58318. },
  58319. {
  58320. key: 'loadUrl',
  58321. value: function loadUrl(url, callback) {
  58322. this.fetchWithTimeout(url)
  58323. .then(
  58324. function(response) {
  58325. var ok = response.ok;
  58326. if (!ok) {
  58327. // caught in the catch() below
  58328. throw new Error('failed loading '.concat(url));
  58329. }
  58330. return response.json();
  58331. },
  58332. function() {
  58333. // caught in the catch() below
  58334. throw new Error('failed loading '.concat(url));
  58335. }
  58336. )
  58337. .then(function(data) {
  58338. return callback(null, data);
  58339. })
  58340. .catch(callback);
  58341. }
  58342. }
  58343. ]);
  58344. return FetchResources;
  58345. })();
  58346. FetchResources.type = 'backend';
  58347. /**
  58348. * This is our translation function. Give it a key and
  58349. * it will retrieve the appropriate string
  58350. * (within supported languages) according to the
  58351. * user's browser's language settings.
  58352. * @function translator
  58353. * @param {String} key a key that corresponds to a message in our translation files
  58354. * @param {Object} values values for use in the message under the given `key`
  58355. * @returns {String} message (with values inserted) in the user's browser language
  58356. * @private
  58357. */
  58358. var translator = function translator(key, values) {
  58359. console.debug('p5.js translator called before translations were loaded');
  58360. // Certain FES functionality may trigger before translations are downloaded.
  58361. // Using "partialBundledLanguages" option during initialization, we can
  58362. // still use our fallback language to display messages
  58363. _i18next.default.t(key, values); /* i18next-extract-disable-line */
  58364. };
  58365. // (We'll set this to a real value in the init function below!)
  58366. /**
  58367. * Set up our translation function, with loaded languages
  58368. */ exports.translator = translator;
  58369. var initialize = function initialize() {
  58370. var i18init = _i18next.default
  58371. .use(_i18nextBrowserLanguagedetector.default)
  58372. .use(FetchResources)
  58373. .init({
  58374. fallbackLng: 'en',
  58375. nestingPrefix: '$tr(',
  58376. nestingSuffix: ')',
  58377. defaultNS: 'translation',
  58378. returnEmptyString: false,
  58379. interpolation: {
  58380. escapeValue: false
  58381. },
  58382. detection: {
  58383. checkWhitelist: false,
  58384. // prevent storing or locating language from cookie or localStorage
  58385. // more info on https://github.com/processing/p5.js/issues/4862
  58386. order: ['querystring', 'navigator', 'htmlTag', 'path', 'subdomain'],
  58387. caches: []
  58388. },
  58389. backend: {
  58390. fallback: 'en',
  58391. loadPath:
  58392. 'https://cdn.jsdelivr.net/npm/p5/translations/{{lng}}/{{ns}}.json'
  58393. },
  58394. partialBundledLanguages: true,
  58395. resources: fallbackResources
  58396. })
  58397. .then(
  58398. function(translateFn) {
  58399. exports.translator = translator = translateFn;
  58400. },
  58401. function(e) {
  58402. return console.debug('Translations failed to load ('.concat(e, ')'));
  58403. }
  58404. );
  58405. // i18next.init() returns a promise that resolves when the translations
  58406. // are loaded. We use this in core/init.js to hold p5 initialization until
  58407. // we have the translation files.
  58408. return i18init;
  58409. };
  58410. exports.initialize = initialize;
  58411. },
  58412. {
  58413. '../../translations': 342,
  58414. '../../translations/dev': undefined,
  58415. 'core-js/modules/es.array.includes': 172,
  58416. 'core-js/modules/es.array.iterator': 174,
  58417. 'core-js/modules/es.array.join': 175,
  58418. 'core-js/modules/es.array.slice': 178,
  58419. 'core-js/modules/es.object.keys': 191,
  58420. 'core-js/modules/es.object.to-string': 192,
  58421. 'core-js/modules/es.promise': 193,
  58422. 'core-js/modules/es.regexp.exec': 196,
  58423. 'core-js/modules/es.string.includes': 200,
  58424. 'core-js/modules/es.string.iterator': 201,
  58425. 'core-js/modules/es.string.split': 206,
  58426. 'core-js/modules/web.dom-collections.iterator': 244,
  58427. i18next: 254,
  58428. 'i18next-browser-languagedetector': 251
  58429. }
  58430. ],
  58431. 282: [
  58432. function(_dereq_, module, exports) {
  58433. 'use strict';
  58434. Object.defineProperty(exports, '__esModule', { value: true });
  58435. exports.default = void 0;
  58436. var _main = _interopRequireDefault(_dereq_('./main'));
  58437. function _interopRequireDefault(obj) {
  58438. return obj && obj.__esModule ? obj : { default: obj };
  58439. }
  58440. /**
  58441. * @for p5
  58442. * @requires core
  58443. * These are functions that are part of the Processing API but are not part of
  58444. * the p5.js API. In some cases they have a new name, in others, they are
  58445. * removed completely. Not all unsupported Processing functions are listed here
  58446. * but we try to include ones that a user coming from Processing might likely
  58447. * call.
  58448. */ _main.default.prototype.pushStyle = function() {
  58449. throw new Error('pushStyle() not used, see push()');
  58450. };
  58451. _main.default.prototype.popStyle = function() {
  58452. throw new Error('popStyle() not used, see pop()');
  58453. };
  58454. _main.default.prototype.popMatrix = function() {
  58455. throw new Error('popMatrix() not used, see pop()');
  58456. };
  58457. _main.default.prototype.pushMatrix = function() {
  58458. throw new Error('pushMatrix() not used, see push()');
  58459. };
  58460. var _default = _main.default;
  58461. exports.default = _default;
  58462. },
  58463. { './main': 283 }
  58464. ],
  58465. 283: [
  58466. function(_dereq_, module, exports) {
  58467. 'use strict';
  58468. function _typeof(obj) {
  58469. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  58470. _typeof = function _typeof(obj) {
  58471. return typeof obj;
  58472. };
  58473. } else {
  58474. _typeof = function _typeof(obj) {
  58475. return obj &&
  58476. typeof Symbol === 'function' &&
  58477. obj.constructor === Symbol &&
  58478. obj !== Symbol.prototype
  58479. ? 'symbol'
  58480. : typeof obj;
  58481. };
  58482. }
  58483. return _typeof(obj);
  58484. }
  58485. _dereq_('core-js/modules/es.symbol');
  58486. _dereq_('core-js/modules/es.symbol.description');
  58487. _dereq_('core-js/modules/es.symbol.iterator');
  58488. _dereq_('core-js/modules/es.array.for-each');
  58489. _dereq_('core-js/modules/es.array.iterator');
  58490. _dereq_('core-js/modules/es.array.slice');
  58491. _dereq_('core-js/modules/es.object.get-own-property-names');
  58492. _dereq_('core-js/modules/es.object.to-string');
  58493. _dereq_('core-js/modules/es.string.iterator');
  58494. _dereq_('core-js/modules/web.dom-collections.for-each');
  58495. _dereq_('core-js/modules/web.dom-collections.iterator');
  58496. Object.defineProperty(exports, '__esModule', { value: true });
  58497. exports.default = void 0;
  58498. _dereq_('./shim');
  58499. var constants = _interopRequireWildcard(_dereq_('./constants'));
  58500. function _getRequireWildcardCache() {
  58501. if (typeof WeakMap !== 'function') return null;
  58502. var cache = new WeakMap();
  58503. _getRequireWildcardCache = function _getRequireWildcardCache() {
  58504. return cache;
  58505. };
  58506. return cache;
  58507. }
  58508. function _interopRequireWildcard(obj) {
  58509. if (obj && obj.__esModule) {
  58510. return obj;
  58511. }
  58512. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  58513. return { default: obj };
  58514. }
  58515. var cache = _getRequireWildcardCache();
  58516. if (cache && cache.has(obj)) {
  58517. return cache.get(obj);
  58518. }
  58519. var newObj = {};
  58520. var hasPropertyDescriptor =
  58521. Object.defineProperty && Object.getOwnPropertyDescriptor;
  58522. for (var key in obj) {
  58523. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  58524. var desc = hasPropertyDescriptor
  58525. ? Object.getOwnPropertyDescriptor(obj, key)
  58526. : null;
  58527. if (desc && (desc.get || desc.set)) {
  58528. Object.defineProperty(newObj, key, desc);
  58529. } else {
  58530. newObj[key] = obj[key];
  58531. }
  58532. }
  58533. }
  58534. newObj.default = obj;
  58535. if (cache) {
  58536. cache.set(obj, newObj);
  58537. }
  58538. return newObj;
  58539. }
  58540. function _classCallCheck(instance, Constructor) {
  58541. if (!(instance instanceof Constructor)) {
  58542. throw new TypeError('Cannot call a class as a function');
  58543. }
  58544. }
  58545. function _defineProperties(target, props) {
  58546. for (var i = 0; i < props.length; i++) {
  58547. var descriptor = props[i];
  58548. descriptor.enumerable = descriptor.enumerable || false;
  58549. descriptor.configurable = true;
  58550. if ('value' in descriptor) descriptor.writable = true;
  58551. Object.defineProperty(target, descriptor.key, descriptor);
  58552. }
  58553. }
  58554. function _createClass(Constructor, protoProps, staticProps) {
  58555. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  58556. if (staticProps) _defineProperties(Constructor, staticProps);
  58557. return Constructor;
  58558. }
  58559. /**
  58560. * This is the p5 instance constructor.
  58561. *
  58562. * A p5 instance holds all the properties and methods related to
  58563. * a p5 sketch. It expects an incoming sketch closure and it can also
  58564. * take an optional node parameter for attaching the generated p5 canvas
  58565. * to a node. The sketch closure takes the newly created p5 instance as
  58566. * its sole argument and may optionally set <a href="#/p5/preload">preload()</a>,
  58567. * <a href="#/p5/setup">setup()</a>, and/or
  58568. * <a href="#/p5/draw">draw()</a> properties on it for running a sketch.
  58569. *
  58570. * A p5 sketch can run in "global" or "instance" mode:
  58571. * "global" - all properties and methods are attached to the window
  58572. * "instance" - all properties and methods are bound to this p5 object
  58573. *
  58574. * @class p5
  58575. * @constructor
  58576. * @param {function} sketch a closure that can set optional <a href="#/p5/preload">preload()</a>,
  58577. * <a href="#/p5/setup">setup()</a>, and/or <a href="#/p5/draw">draw()</a> properties on the
  58578. * given p5 instance
  58579. * @param {HTMLElement} [node] element to attach canvas to
  58580. * @return {p5} a p5 instance
  58581. */ var p5 = /*#__PURE__*/ (function() {
  58582. function p5(sketch, node, sync) {
  58583. var _this = this;
  58584. _classCallCheck(this, p5);
  58585. //////////////////////////////////////////////
  58586. // PUBLIC p5 PROPERTIES AND METHODS
  58587. //////////////////////////////////////////////
  58588. /**
  58589. * Called directly before <a href="#/p5/setup">setup()</a>, the <a href="#/p5/preload">preload()</a> function is used to handle
  58590. * asynchronous loading of external files in a blocking way. If a preload
  58591. * function is defined, <a href="#/p5/setup">setup()</a> will wait until any load calls within have
  58592. * finished. Nothing besides load calls (<a href="#/p5/loadImage">loadImage</a>, <a href="#/p5/loadJSON">loadJSON</a>, <a href="#/p5/loadFont">loadFont</a>,
  58593. * <a href="#/p5/loadStrings">loadStrings</a>, etc.) should be inside the preload function. If asynchronous
  58594. * loading is preferred, the load methods can instead be called in <a href="#/p5/setup">setup()</a>
  58595. * or anywhere else with the use of a callback parameter.
  58596. *
  58597. * By default the text "loading..." will be displayed. To make your own
  58598. * loading page, include an HTML element with id "p5_loading" in your
  58599. * page. More information <a href="http://bit.ly/2kQ6Nio">here</a>.
  58600. *
  58601. * @method preload
  58602. * @example
  58603. * <div><code>
  58604. * let img;
  58605. * let c;
  58606. * function preload() {
  58607. * // preload() runs once
  58608. * img = loadImage('assets/laDefense.jpg');
  58609. * }
  58610. *
  58611. * function setup() {
  58612. * // setup() waits until preload() is done
  58613. * img.loadPixels();
  58614. * // get color of middle pixel
  58615. * c = img.get(img.width / 2, img.height / 2);
  58616. * }
  58617. *
  58618. * function draw() {
  58619. * background(c);
  58620. * image(img, 25, 25, 50, 50);
  58621. * }
  58622. * </code></div>
  58623. *
  58624. * @alt
  58625. * nothing displayed
  58626. *
  58627. */
  58628. /**
  58629. * The <a href="#/p5/setup">setup()</a> function is called once when the program starts. It's used to
  58630. * define initial environment properties such as screen size and background
  58631. * color and to load media such as images and fonts as the program starts.
  58632. * There can only be one <a href="#/p5/setup">setup()</a> function for each program and it shouldn't
  58633. * be called again after its initial execution.
  58634. *
  58635. * Note: Variables declared within <a href="#/p5/setup">setup()</a> are not accessible within other
  58636. * functions, including <a href="#/p5/draw">draw()</a>.
  58637. *
  58638. * @method setup
  58639. * @example
  58640. * <div><code>
  58641. * let a = 0;
  58642. *
  58643. * function setup() {
  58644. * background(0);
  58645. * noStroke();
  58646. * fill(102);
  58647. * }
  58648. *
  58649. * function draw() {
  58650. * rect(a++ % width, 10, 2, 80);
  58651. * }
  58652. * </code></div>
  58653. *
  58654. * @alt
  58655. * nothing displayed
  58656. *
  58657. */
  58658. /**
  58659. * Called directly after <a href="#/p5/setup">setup()</a>, the <a href="#/p5/draw">draw()</a> function continuously executes
  58660. * the lines of code contained inside its block until the program is stopped
  58661. * or <a href="#/p5/noLoop">noLoop()</a> is called. Note if <a href="#/p5/noLoop">noLoop()</a> is called in <a href="#/p5/setup">setup()</a>, <a href="#/p5/draw">draw()</a> will
  58662. * still be executed once before stopping. <a href="#/p5/draw">draw()</a> is called automatically and
  58663. * should never be called explicitly.
  58664. *
  58665. * It should always be controlled with <a href="#/p5/noLoop">noLoop()</a>, <a href="#/p5/redraw">redraw()</a> and <a href="#/p5/loop">loop()</a>. After
  58666. * <a href="#/p5/noLoop">noLoop()</a> stops the code in <a href="#/p5/draw">draw()</a> from executing, <a href="#/p5/redraw">redraw()</a> causes the
  58667. * code inside <a href="#/p5/draw">draw()</a> to execute once, and <a href="#/p5/loop">loop()</a> will cause the code
  58668. * inside <a href="#/p5/draw">draw()</a> to resume executing continuously.
  58669. *
  58670. * The number of times <a href="#/p5/draw">draw()</a> executes in each second may be controlled with
  58671. * the <a href="#/p5/frameRate">frameRate()</a> function.
  58672. *
  58673. * There can only be one <a href="#/p5/draw">draw()</a> function for each sketch, and <a href="#/p5/draw">draw()</a> must
  58674. * exist if you want the code to run continuously, or to process events such
  58675. * as <a href="#/p5/mousePressed">mousePressed()</a>. Sometimes, you might have an empty call to <a href="#/p5/draw">draw()</a> in
  58676. * your program, as shown in the above example.
  58677. *
  58678. * It is important to note that the drawing coordinate system will be reset
  58679. * at the beginning of each <a href="#/p5/draw">draw()</a> call. If any transformations are performed
  58680. * within <a href="#/p5/draw">draw()</a> (ex: scale, rotate, translate), their effects will be
  58681. * undone at the beginning of <a href="#/p5/draw">draw()</a>, so transformations will not accumulate
  58682. * over time. On the other hand, styling applied (ex: fill, stroke, etc) will
  58683. * remain in effect.
  58684. *
  58685. * @method draw
  58686. * @example
  58687. * <div><code>
  58688. * let yPos = 0;
  58689. * function setup() {
  58690. * // setup() runs once
  58691. * frameRate(30);
  58692. * }
  58693. * function draw() {
  58694. * // draw() loops forever, until stopped
  58695. * background(204);
  58696. * yPos = yPos - 1;
  58697. * if (yPos < 0) {
  58698. * yPos = height;
  58699. * }
  58700. * line(0, yPos, width, yPos);
  58701. * }
  58702. * </code></div>
  58703. *
  58704. * @alt
  58705. * nothing displayed
  58706. *
  58707. */
  58708. //////////////////////////////////////////////
  58709. // PRIVATE p5 PROPERTIES AND METHODS
  58710. //////////////////////////////////////////////
  58711. this._setupDone = false;
  58712. // for handling hidpi
  58713. this._pixelDensity = Math.ceil(window.devicePixelRatio) || 1;
  58714. this._userNode = node;
  58715. this._curElement = null;
  58716. this._elements = [];
  58717. this._glAttributes = null;
  58718. this._requestAnimId = 0;
  58719. this._preloadCount = 0;
  58720. this._isGlobal = false;
  58721. this._loop = true;
  58722. this._initializeInstanceVariables();
  58723. this._defaultCanvasSize = {
  58724. width: 100,
  58725. height: 100
  58726. };
  58727. this._events = {
  58728. // keep track of user-events for unregistering later
  58729. mousemove: null,
  58730. mousedown: null,
  58731. mouseup: null,
  58732. dragend: null,
  58733. dragover: null,
  58734. click: null,
  58735. dblclick: null,
  58736. mouseover: null,
  58737. mouseout: null,
  58738. keydown: null,
  58739. keyup: null,
  58740. keypress: null,
  58741. touchstart: null,
  58742. touchmove: null,
  58743. touchend: null,
  58744. resize: null,
  58745. blur: null
  58746. };
  58747. this._millisStart = -1;
  58748. // States used in the custom random generators
  58749. this._lcg_random_state = null;
  58750. this._gaussian_previous = false;
  58751. this._events.wheel = null;
  58752. this._loadingScreenId = 'p5_loading';
  58753. // Allows methods to be registered on an instance that
  58754. // are instance-specific.
  58755. this._registeredMethods = {};
  58756. var methods = Object.getOwnPropertyNames(p5.prototype._registeredMethods);
  58757. var _iteratorNormalCompletion = true;
  58758. var _didIteratorError = false;
  58759. var _iteratorError = undefined;
  58760. try {
  58761. for (
  58762. var _iterator = methods[Symbol.iterator](), _step;
  58763. !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
  58764. _iteratorNormalCompletion = true
  58765. ) {
  58766. var prop = _step.value;
  58767. this._registeredMethods[prop] = p5.prototype._registeredMethods[
  58768. prop
  58769. ].slice();
  58770. }
  58771. } catch (err) {
  58772. _didIteratorError = true;
  58773. _iteratorError = err;
  58774. } finally {
  58775. try {
  58776. if (!_iteratorNormalCompletion && _iterator.return != null) {
  58777. _iterator.return();
  58778. }
  58779. } finally {
  58780. if (_didIteratorError) {
  58781. throw _iteratorError;
  58782. }
  58783. }
  58784. }
  58785. if (window.DeviceOrientationEvent) {
  58786. this._events.deviceorientation = null;
  58787. }
  58788. if (window.DeviceMotionEvent && !window._isNodeWebkit) {
  58789. this._events.devicemotion = null;
  58790. }
  58791. this._start = function() {
  58792. // Find node if id given
  58793. if (_this._userNode) {
  58794. if (typeof _this._userNode === 'string') {
  58795. _this._userNode = document.getElementById(_this._userNode);
  58796. }
  58797. }
  58798. var context = _this._isGlobal ? window : _this;
  58799. if (context.preload) {
  58800. // Setup loading screen
  58801. // Set loading screen into dom if not present
  58802. // Otherwise displays and removes user provided loading screen
  58803. var loadingScreen = document.getElementById(_this._loadingScreenId);
  58804. if (!loadingScreen) {
  58805. loadingScreen = document.createElement('div');
  58806. loadingScreen.innerHTML = 'Loading...';
  58807. loadingScreen.style.position = 'absolute';
  58808. loadingScreen.id = _this._loadingScreenId;
  58809. var _node = _this._userNode || document.body;
  58810. _node.appendChild(loadingScreen);
  58811. }
  58812. var _methods = _this._preloadMethods;
  58813. for (var method in _methods) {
  58814. // default to p5 if no object defined
  58815. _methods[method] = _methods[method] || p5;
  58816. var obj = _methods[method];
  58817. //it's p5, check if it's global or instance
  58818. if (obj === p5.prototype || obj === p5) {
  58819. if (_this._isGlobal) {
  58820. window[method] = _this._wrapPreload(_this, method);
  58821. }
  58822. obj = _this;
  58823. }
  58824. _this._registeredPreloadMethods[method] = obj[method];
  58825. obj[method] = _this._wrapPreload(obj, method);
  58826. }
  58827. context.preload();
  58828. _this._runIfPreloadsAreDone();
  58829. } else {
  58830. _this._setup();
  58831. _this._draw();
  58832. }
  58833. };
  58834. this._runIfPreloadsAreDone = function() {
  58835. var context = this._isGlobal ? window : this;
  58836. if (context._preloadCount === 0) {
  58837. var loadingScreen = document.getElementById(context._loadingScreenId);
  58838. if (loadingScreen) {
  58839. loadingScreen.parentNode.removeChild(loadingScreen);
  58840. }
  58841. if (!this._setupDone) {
  58842. this._lastFrameTime = window.performance.now();
  58843. context._setup();
  58844. context._draw();
  58845. }
  58846. }
  58847. };
  58848. this._decrementPreload = function() {
  58849. var context = this._isGlobal ? window : this;
  58850. if (typeof context.preload === 'function') {
  58851. context._setProperty('_preloadCount', context._preloadCount - 1);
  58852. context._runIfPreloadsAreDone();
  58853. }
  58854. };
  58855. this._wrapPreload = function(obj, fnName) {
  58856. var _this2 = this;
  58857. return function() {
  58858. //increment counter
  58859. _this2._incrementPreload();
  58860. //call original function
  58861. for (
  58862. var _len = arguments.length, args = new Array(_len), _key = 0;
  58863. _key < _len;
  58864. _key++
  58865. ) {
  58866. args[_key] = arguments[_key];
  58867. }
  58868. return _this2._registeredPreloadMethods[fnName].apply(obj, args);
  58869. };
  58870. };
  58871. this._incrementPreload = function() {
  58872. var context = this._isGlobal ? window : this;
  58873. context._setProperty('_preloadCount', context._preloadCount + 1);
  58874. };
  58875. this._setup = function() {
  58876. // Always create a default canvas.
  58877. // Later on if the user calls createCanvas, this default one
  58878. // will be replaced
  58879. _this.createCanvas(
  58880. _this._defaultCanvasSize.width,
  58881. _this._defaultCanvasSize.height,
  58882. 'p2d'
  58883. );
  58884. // return preload functions to their normal vals if switched by preload
  58885. var context = _this._isGlobal ? window : _this;
  58886. if (typeof context.preload === 'function') {
  58887. for (var f in _this._preloadMethods) {
  58888. context[f] = _this._preloadMethods[f][f];
  58889. if (context[f] && _this) {
  58890. context[f] = context[f].bind(_this);
  58891. }
  58892. }
  58893. }
  58894. // Record the time when sketch starts
  58895. _this._millisStart = window.performance.now();
  58896. // Short-circuit on this, in case someone used the library in "global"
  58897. // mode earlier
  58898. if (typeof context.setup === 'function') {
  58899. context.setup();
  58900. }
  58901. // unhide any hidden canvases that were created
  58902. var canvases = document.getElementsByTagName('canvas');
  58903. var _iteratorNormalCompletion2 = true;
  58904. var _didIteratorError2 = false;
  58905. var _iteratorError2 = undefined;
  58906. try {
  58907. for (
  58908. var _iterator2 = canvases[Symbol.iterator](), _step2;
  58909. !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);
  58910. _iteratorNormalCompletion2 = true
  58911. ) {
  58912. var k = _step2.value;
  58913. if (k.dataset.hidden === 'true') {
  58914. k.style.visibility = '';
  58915. delete k.dataset.hidden;
  58916. }
  58917. }
  58918. } catch (err) {
  58919. _didIteratorError2 = true;
  58920. _iteratorError2 = err;
  58921. } finally {
  58922. try {
  58923. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  58924. _iterator2.return();
  58925. }
  58926. } finally {
  58927. if (_didIteratorError2) {
  58928. throw _iteratorError2;
  58929. }
  58930. }
  58931. }
  58932. _this._lastFrameTime = window.performance.now();
  58933. _this._setupDone = true;
  58934. if (_this._accessibleOutputs.grid || _this._accessibleOutputs.text) {
  58935. _this._updateAccsOutput();
  58936. }
  58937. };
  58938. this._draw = function() {
  58939. var now = window.performance.now();
  58940. var time_since_last = now - _this._lastFrameTime;
  58941. var target_time_between_frames = 1000 / _this._targetFrameRate;
  58942. // only draw if we really need to; don't overextend the browser.
  58943. // draw if we're within 5ms of when our next frame should paint
  58944. // (this will prevent us from giving up opportunities to draw
  58945. // again when it's really about time for us to do so). fixes an
  58946. // issue where the frameRate is too low if our refresh loop isn't
  58947. // in sync with the browser. note that we have to draw once even
  58948. // if looping is off, so we bypass the time delay if that
  58949. // is the case.
  58950. var epsilon = 5;
  58951. if (
  58952. !_this._loop ||
  58953. time_since_last >= target_time_between_frames - epsilon
  58954. ) {
  58955. //mandatory update values(matrixes and stack)
  58956. _this.redraw();
  58957. _this._frameRate = 1000.0 / (now - _this._lastFrameTime);
  58958. _this.deltaTime = now - _this._lastFrameTime;
  58959. _this._setProperty('deltaTime', _this.deltaTime);
  58960. _this._lastFrameTime = now;
  58961. // If the user is actually using mouse module, then update
  58962. // coordinates, otherwise skip. We can test this by simply
  58963. // checking if any of the mouse functions are available or not.
  58964. // NOTE : This reflects only in complete build or modular build.
  58965. if (typeof _this._updateMouseCoords !== 'undefined') {
  58966. _this._updateMouseCoords();
  58967. //reset delta values so they reset even if there is no mouse event to set them
  58968. // for example if the mouse is outside the screen
  58969. _this._setProperty('movedX', 0);
  58970. _this._setProperty('movedY', 0);
  58971. }
  58972. }
  58973. // get notified the next time the browser gives us
  58974. // an opportunity to draw.
  58975. if (_this._loop) {
  58976. _this._requestAnimId = window.requestAnimationFrame(_this._draw);
  58977. }
  58978. };
  58979. this._setProperty = function(prop, value) {
  58980. _this[prop] = value;
  58981. if (_this._isGlobal) {
  58982. window[prop] = value;
  58983. }
  58984. };
  58985. /**
  58986. * Removes the entire p5 sketch. This will remove the canvas and any
  58987. * elements created by p5.js. It will also stop the draw loop and unbind
  58988. * any properties or methods from the window global scope. It will
  58989. * leave a variable p5 in case you wanted to create a new p5 sketch.
  58990. * If you like, you can set p5 = null to erase it. While all functions and
  58991. * variables and objects created by the p5 library will be removed, any
  58992. * other global variables created by your code will remain.
  58993. *
  58994. * @method remove
  58995. * @example
  58996. * <div class='norender'><code>
  58997. * function draw() {
  58998. * ellipse(50, 50, 10, 10);
  58999. * }
  59000. *
  59001. * function mousePressed() {
  59002. * remove(); // remove whole sketch on mouse press
  59003. * }
  59004. * </code></div>
  59005. *
  59006. * @alt
  59007. * nothing displayed
  59008. *
  59009. */
  59010. this.remove = function() {
  59011. var loadingScreen = document.getElementById(_this._loadingScreenId);
  59012. if (loadingScreen) {
  59013. loadingScreen.parentNode.removeChild(loadingScreen);
  59014. // Add 1 to preload counter to prevent the sketch ever executing setup()
  59015. _this._incrementPreload();
  59016. }
  59017. if (_this._curElement) {
  59018. // stop draw
  59019. _this._loop = false;
  59020. if (_this._requestAnimId) {
  59021. window.cancelAnimationFrame(_this._requestAnimId);
  59022. }
  59023. // unregister events sketch-wide
  59024. for (var ev in _this._events) {
  59025. window.removeEventListener(ev, _this._events[ev]);
  59026. }
  59027. // remove DOM elements created by p5, and listeners
  59028. var _iteratorNormalCompletion3 = true;
  59029. var _didIteratorError3 = false;
  59030. var _iteratorError3 = undefined;
  59031. try {
  59032. for (
  59033. var _iterator3 = _this._elements[Symbol.iterator](), _step3;
  59034. !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done);
  59035. _iteratorNormalCompletion3 = true
  59036. ) {
  59037. var e = _step3.value;
  59038. if (e.elt && e.elt.parentNode) {
  59039. e.elt.parentNode.removeChild(e.elt);
  59040. }
  59041. for (var elt_ev in e._events) {
  59042. e.elt.removeEventListener(elt_ev, e._events[elt_ev]);
  59043. }
  59044. }
  59045. // call any registered remove functions
  59046. } catch (err) {
  59047. _didIteratorError3 = true;
  59048. _iteratorError3 = err;
  59049. } finally {
  59050. try {
  59051. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  59052. _iterator3.return();
  59053. }
  59054. } finally {
  59055. if (_didIteratorError3) {
  59056. throw _iteratorError3;
  59057. }
  59058. }
  59059. }
  59060. var self = _this;
  59061. _this._registeredMethods.remove.forEach(function(f) {
  59062. if (typeof f !== 'undefined') {
  59063. f.call(self);
  59064. }
  59065. });
  59066. }
  59067. // remove window bound properties and methods
  59068. if (_this._isGlobal) {
  59069. for (var p in p5.prototype) {
  59070. try {
  59071. delete window[p];
  59072. } catch (x) {
  59073. window[p] = undefined;
  59074. }
  59075. }
  59076. for (var p2 in _this) {
  59077. if (_this.hasOwnProperty(p2)) {
  59078. try {
  59079. delete window[p2];
  59080. } catch (x) {
  59081. window[p2] = undefined;
  59082. }
  59083. }
  59084. }
  59085. p5.instance = null;
  59086. }
  59087. };
  59088. // call any registered init functions
  59089. this._registeredMethods.init.forEach(function(f) {
  59090. if (typeof f !== 'undefined') {
  59091. f.call(this);
  59092. }
  59093. }, this);
  59094. // Set up promise preloads
  59095. this._setupPromisePreloads();
  59096. var friendlyBindGlobal = this._createFriendlyGlobalFunctionBinder();
  59097. // If the user has created a global setup or draw function,
  59098. // assume "global" mode and make everything global (i.e. on the window)
  59099. if (!sketch) {
  59100. this._isGlobal = true;
  59101. p5.instance = this;
  59102. // Loop through methods on the prototype and attach them to the window
  59103. for (var p in p5.prototype) {
  59104. if (typeof p5.prototype[p] === 'function') {
  59105. var ev = p.substring(2);
  59106. if (!this._events.hasOwnProperty(ev)) {
  59107. if (Math.hasOwnProperty(p) && Math[p] === p5.prototype[p]) {
  59108. // Multiple p5 methods are just native Math functions. These can be
  59109. // called without any binding.
  59110. friendlyBindGlobal(p, p5.prototype[p]);
  59111. } else {
  59112. friendlyBindGlobal(p, p5.prototype[p].bind(this));
  59113. }
  59114. }
  59115. } else {
  59116. friendlyBindGlobal(p, p5.prototype[p]);
  59117. }
  59118. }
  59119. // Attach its properties to the window
  59120. for (var p2 in this) {
  59121. if (this.hasOwnProperty(p2)) {
  59122. friendlyBindGlobal(p2, this[p2]);
  59123. }
  59124. }
  59125. } else {
  59126. // Else, the user has passed in a sketch closure that may set
  59127. // user-provided 'setup', 'draw', etc. properties on this instance of p5
  59128. sketch(this);
  59129. // Run a check to see if the user has misspelled 'setup', 'draw', etc
  59130. // detects capitalization mistakes only ( Setup, SETUP, MouseClicked, etc)
  59131. p5._checkForUserDefinedFunctions(this);
  59132. }
  59133. // Bind events to window (not using container div bc key events don't work)
  59134. for (var e in this._events) {
  59135. var f = this['_on'.concat(e)];
  59136. if (f) {
  59137. var m = f.bind(this);
  59138. window.addEventListener(e, m, { passive: false });
  59139. this._events[e] = m;
  59140. }
  59141. }
  59142. var focusHandler = function focusHandler() {
  59143. _this._setProperty('focused', true);
  59144. };
  59145. var blurHandler = function blurHandler() {
  59146. _this._setProperty('focused', false);
  59147. };
  59148. window.addEventListener('focus', focusHandler);
  59149. window.addEventListener('blur', blurHandler);
  59150. this.registerMethod('remove', function() {
  59151. window.removeEventListener('focus', focusHandler);
  59152. window.removeEventListener('blur', blurHandler);
  59153. });
  59154. if (document.readyState === 'complete') {
  59155. this._start();
  59156. } else {
  59157. window.addEventListener('load', this._start.bind(this), false);
  59158. }
  59159. }
  59160. _createClass(p5, [
  59161. {
  59162. key: '_initializeInstanceVariables',
  59163. value: function _initializeInstanceVariables() {
  59164. this._accessibleOutputs = {
  59165. text: false,
  59166. grid: false,
  59167. textLabel: false,
  59168. gridLabel: false
  59169. };
  59170. this._styles = [];
  59171. this._bezierDetail = 20;
  59172. this._curveDetail = 20;
  59173. this._colorMode = constants.RGB;
  59174. this._colorMaxes = {
  59175. rgb: [255, 255, 255, 255],
  59176. hsb: [360, 100, 100, 1],
  59177. hsl: [360, 100, 100, 1]
  59178. };
  59179. this._downKeys = {}; //Holds the key codes of currently pressed keys
  59180. }
  59181. },
  59182. {
  59183. key: 'registerPreloadMethod',
  59184. value: function registerPreloadMethod(fnString, obj) {
  59185. // obj = obj || p5.prototype;
  59186. if (!p5.prototype._preloadMethods.hasOwnProperty(fnString)) {
  59187. p5.prototype._preloadMethods[fnString] = obj;
  59188. }
  59189. }
  59190. },
  59191. {
  59192. key: 'registerMethod',
  59193. value: function registerMethod(name, m) {
  59194. var target = this || p5.prototype;
  59195. if (!target._registeredMethods.hasOwnProperty(name)) {
  59196. target._registeredMethods[name] = [];
  59197. }
  59198. target._registeredMethods[name].push(m);
  59199. }
  59200. // create a function which provides a standardized process for binding
  59201. // globals; this is implemented as a factory primarily so that there's a
  59202. // way to redefine what "global" means for the binding function so it
  59203. // can be used in scenarios like unit testing where the window object
  59204. // might not exist
  59205. },
  59206. {
  59207. key: '_createFriendlyGlobalFunctionBinder',
  59208. value: function _createFriendlyGlobalFunctionBinder() {
  59209. var options =
  59210. arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  59211. var globalObject = options.globalObject || window;
  59212. var log = options.log || console.log.bind(console);
  59213. var propsToForciblyOverwrite = {
  59214. // p5.print actually always overwrites an existing global function,
  59215. // albeit one that is very unlikely to be used:
  59216. //
  59217. // https://developer.mozilla.org/en-US/docs/Web/API/Window/print
  59218. print: true
  59219. };
  59220. return function(prop, value) {
  59221. if (
  59222. !p5.disableFriendlyErrors &&
  59223. typeof IS_MINIFIED === 'undefined' &&
  59224. typeof value === 'function' &&
  59225. !(prop in p5.prototype._preloadMethods)
  59226. ) {
  59227. try {
  59228. // Because p5 has so many common function names, it's likely
  59229. // that users may accidentally overwrite global p5 functions with
  59230. // their own variables. Let's allow this but log a warning to
  59231. // help users who may be doing this unintentionally.
  59232. //
  59233. // For more information, see:
  59234. //
  59235. // https://github.com/processing/p5.js/issues/1317
  59236. if (prop in globalObject && !(prop in propsToForciblyOverwrite)) {
  59237. throw new Error('global "'.concat(prop, '" already exists'));
  59238. }
  59239. // It's possible that this might throw an error because there
  59240. // are a lot of edge-cases in which `Object.defineProperty` might
  59241. // not succeed; since this functionality is only intended to
  59242. // help beginners anyways, we'll just catch such an exception
  59243. // if it occurs, and fall back to legacy behavior.
  59244. Object.defineProperty(globalObject, prop, {
  59245. configurable: true,
  59246. enumerable: true,
  59247. get: function get() {
  59248. return value;
  59249. },
  59250. set: function set(newValue) {
  59251. Object.defineProperty(globalObject, prop, {
  59252. configurable: true,
  59253. enumerable: true,
  59254. value: newValue,
  59255. writable: true
  59256. });
  59257. log(
  59258. 'You just changed the value of "'.concat(
  59259. prop,
  59260. '", which was a p5 function. This could cause problems later if you\'re not careful.'
  59261. )
  59262. );
  59263. }
  59264. });
  59265. } catch (e) {
  59266. var message = 'p5 had problems creating the global function "'.concat(
  59267. prop,
  59268. '", possibly because your code is already using that name as a variable. You may want to rename your variable to something else.'
  59269. );
  59270. p5._friendlyError(message, prop);
  59271. globalObject[prop] = value;
  59272. }
  59273. } else {
  59274. globalObject[prop] = value;
  59275. }
  59276. };
  59277. }
  59278. }
  59279. ]);
  59280. return p5;
  59281. })();
  59282. // This is a pointer to our global mode p5 instance, if we're in
  59283. // global mode.
  59284. p5.instance = null;
  59285. /**
  59286. * Allows for the friendly error system (FES) to be turned off when creating a sketch,
  59287. * which can give a significant boost to performance when needed.
  59288. * See <a href='https://github.com/processing/p5.js/wiki/Optimizing-p5.js-Code-for-Performance#disable-the-friendly-error-system-fes'>
  59289. * disabling the friendly error system</a>.
  59290. *
  59291. * @property {Boolean} disableFriendlyErrors
  59292. * @example
  59293. * <div class="norender notest"><code>
  59294. * p5.disableFriendlyErrors = true;
  59295. *
  59296. * function setup() {
  59297. * createCanvas(100, 50);
  59298. * }
  59299. * </code></div>
  59300. */
  59301. p5.disableFriendlyErrors = false;
  59302. // attach constants to p5 prototype
  59303. for (var k in constants) {
  59304. p5.prototype[k] = constants[k];
  59305. }
  59306. // functions that cause preload to wait
  59307. // more can be added by using registerPreloadMethod(func)
  59308. p5.prototype._preloadMethods = {
  59309. loadJSON: p5.prototype,
  59310. loadImage: p5.prototype,
  59311. loadStrings: p5.prototype,
  59312. loadXML: p5.prototype,
  59313. loadBytes: p5.prototype,
  59314. loadTable: p5.prototype,
  59315. loadFont: p5.prototype,
  59316. loadModel: p5.prototype,
  59317. loadShader: p5.prototype
  59318. };
  59319. p5.prototype._registeredMethods = { init: [], pre: [], post: [], remove: [] };
  59320. p5.prototype._registeredPreloadMethods = {};
  59321. var _default = p5;
  59322. exports.default = _default;
  59323. },
  59324. {
  59325. './constants': 272,
  59326. './shim': 294,
  59327. 'core-js/modules/es.array.for-each': 170,
  59328. 'core-js/modules/es.array.iterator': 174,
  59329. 'core-js/modules/es.array.slice': 178,
  59330. 'core-js/modules/es.object.get-own-property-names': 189,
  59331. 'core-js/modules/es.object.to-string': 192,
  59332. 'core-js/modules/es.string.iterator': 201,
  59333. 'core-js/modules/es.symbol': 211,
  59334. 'core-js/modules/es.symbol.description': 209,
  59335. 'core-js/modules/es.symbol.iterator': 210,
  59336. 'core-js/modules/web.dom-collections.for-each': 243,
  59337. 'core-js/modules/web.dom-collections.iterator': 244
  59338. }
  59339. ],
  59340. 284: [
  59341. function(_dereq_, module, exports) {
  59342. 'use strict';
  59343. Object.defineProperty(exports, '__esModule', { value: true });
  59344. exports.default = void 0;
  59345. var _main = _interopRequireDefault(_dereq_('./main'));
  59346. function _interopRequireDefault(obj) {
  59347. return obj && obj.__esModule ? obj : { default: obj };
  59348. }
  59349. /**
  59350. * @module DOM
  59351. * @submodule DOM
  59352. * @for p5.Element
  59353. */ /**
  59354. * Base class for all elements added to a sketch, including canvas,
  59355. * graphics buffers, and other HTML elements. It is not called directly, but <a href="#/p5.Element">p5.Element</a>
  59356. * objects are created by calling <a href="#/p5/createCanvas">createCanvas</a>, <a href="#/p5/createGraphics">createGraphics</a>,
  59357. * <a href="#/p5/createDiv">createDiv</a>, <a href="#/p5/createImg">createImg</a>, <a href="#/p5/createInput">createInput</a>, etc.
  59358. *
  59359. * @class p5.Element
  59360. * @constructor
  59361. * @param {String} elt DOM node that is wrapped
  59362. * @param {p5} [pInst] pointer to p5 instance
  59363. */ _main.default.Element = function(elt, pInst) {
  59364. /**
  59365. * Underlying HTML element. All normal HTML methods can be called on this.
  59366. * @example
  59367. * <div>
  59368. * <code>
  59369. * function setup() {
  59370. * let c = createCanvas(50, 50);
  59371. * c.elt.style.border = '5px solid red';
  59372. * }
  59373. *
  59374. * function draw() {
  59375. * background(220);
  59376. * }
  59377. * </code>
  59378. * </div>
  59379. *
  59380. * @property elt
  59381. * @readOnly
  59382. */
  59383. this.elt = elt;
  59384. this._pInst = this._pixelsState = pInst;
  59385. this._events = {};
  59386. this.width = this.elt.offsetWidth;
  59387. this.height = this.elt.offsetHeight;
  59388. };
  59389. /**
  59390. *
  59391. * Attaches the element to the parent specified. A way of setting
  59392. * the container for the element. Accepts either a string ID, DOM
  59393. * node, or <a href="#/p5.Element">p5.Element</a>. If no arguments given, parent node is returned.
  59394. * For more ways to position the canvas, see the
  59395. * <a href='https://github.com/processing/p5.js/wiki/Positioning-your-canvas'>
  59396. * positioning the canvas</a> wiki page.
  59397. *
  59398. * @method parent
  59399. * @param {String|p5.Element|Object} parent the ID, DOM node, or <a href="#/p5.Element">p5.Element</a>
  59400. * of desired parent element
  59401. * @chainable
  59402. *
  59403. * @example
  59404. * <div class="norender notest"><code>
  59405. * // Add the following comment to html file.
  59406. * // &lt;div id="myContainer">&lt;/div>
  59407. *
  59408. * // The js code
  59409. * let cnv = createCanvas(100, 100);
  59410. * cnv.parent('myContainer');
  59411. * </code></div>
  59412. *
  59413. * <div class='norender'><code>
  59414. * let div0 = createDiv('this is the parent');
  59415. * let div1 = createDiv('this is the child');
  59416. * div1.parent(div0); // use p5.Element
  59417. * </code></div>
  59418. *
  59419. * <div class='norender'><code>
  59420. * let div0 = createDiv('this is the parent');
  59421. * div0.id('apples');
  59422. * let div1 = createDiv('this is the child');
  59423. * div1.parent('apples'); // use id
  59424. * </code></div>
  59425. *
  59426. * <div class='norender notest'><code>
  59427. * let elt = document.getElementById('myParentDiv');
  59428. * let div1 = createDiv('this is the child');
  59429. * div1.parent(elt); // use element from page
  59430. * </code></div>
  59431. *
  59432. * @alt
  59433. * no display.
  59434. */
  59435. /**
  59436. * @method parent
  59437. * @return {p5.Element}
  59438. */
  59439. _main.default.Element.prototype.parent = function(p) {
  59440. if (typeof p === 'undefined') {
  59441. return this.elt.parentNode;
  59442. }
  59443. if (typeof p === 'string') {
  59444. if (p[0] === '#') {
  59445. p = p.substring(1);
  59446. }
  59447. p = document.getElementById(p);
  59448. } else if (p instanceof _main.default.Element) {
  59449. p = p.elt;
  59450. }
  59451. p.appendChild(this.elt);
  59452. return this;
  59453. };
  59454. /**
  59455. *
  59456. * Sets the ID of the element. If no ID argument is passed in, it instead
  59457. * returns the current ID of the element.
  59458. * Note that only one element can have a particular id in a page.
  59459. * The <a href="#/p5.Element/class">.class()</a> function can be used
  59460. * to identify multiple elements with the same class name.
  59461. *
  59462. * @method id
  59463. * @param {String} id ID of the element
  59464. * @chainable
  59465. *
  59466. * @example
  59467. * <div class='norender'><code>
  59468. * function setup() {
  59469. * let cnv = createCanvas(100, 100);
  59470. * // Assigns a CSS selector ID to
  59471. * // the canvas element.
  59472. * cnv.id('mycanvas');
  59473. * }
  59474. * </code></div>
  59475. *
  59476. * @alt
  59477. * no display.
  59478. */
  59479. /**
  59480. * @method id
  59481. * @return {String} the id of the element
  59482. */
  59483. _main.default.Element.prototype.id = function(id) {
  59484. if (typeof id === 'undefined') {
  59485. return this.elt.id;
  59486. }
  59487. this.elt.id = id;
  59488. this.width = this.elt.offsetWidth;
  59489. this.height = this.elt.offsetHeight;
  59490. return this;
  59491. };
  59492. /**
  59493. *
  59494. * Adds given class to the element. If no class argument is passed in, it
  59495. * instead returns a string containing the current class(es) of the element.
  59496. *
  59497. * @method class
  59498. * @param {String} class class to add
  59499. * @chainable
  59500. *
  59501. * @example
  59502. * <div class='norender'><code>
  59503. * function setup() {
  59504. * let cnv = createCanvas(100, 100);
  59505. * // Assigns a CSS selector class 'small'
  59506. * // to the canvas element.
  59507. * cnv.class('small');
  59508. * }
  59509. * </code></div>
  59510. *
  59511. * @alt
  59512. * no display.
  59513. */
  59514. /**
  59515. * @method class
  59516. * @return {String} the class of the element
  59517. */
  59518. _main.default.Element.prototype.class = function(c) {
  59519. if (typeof c === 'undefined') {
  59520. return this.elt.className;
  59521. }
  59522. this.elt.className = c;
  59523. return this;
  59524. };
  59525. /**
  59526. * The .<a href="#/p5.Element/mousePressed">mousePressed()</a> function is called
  59527. * once after every time a mouse button is pressed over the element. Some mobile
  59528. * browsers may also trigger this event on a touch screen, if the user performs
  59529. * a quick tap. This can be used to attach element specific event listeners.
  59530. *
  59531. * @method mousePressed
  59532. * @param {Function|Boolean} fxn function to be fired when mouse is
  59533. * pressed over the element.
  59534. * if `false` is passed instead, the previously
  59535. * firing function will no longer fire.
  59536. * @chainable
  59537. * @example
  59538. * <div class='norender'><code>
  59539. * let cnv, d, g;
  59540. * function setup() {
  59541. * cnv = createCanvas(100, 100);
  59542. * cnv.mousePressed(changeGray); // attach listener for
  59543. * // canvas click only
  59544. * d = 10;
  59545. * g = 100;
  59546. * }
  59547. *
  59548. * function draw() {
  59549. * background(g);
  59550. * ellipse(width / 2, height / 2, d, d);
  59551. * }
  59552. *
  59553. * // this function fires with any click anywhere
  59554. * function mousePressed() {
  59555. * d = d + 10;
  59556. * }
  59557. *
  59558. * // this function fires only when cnv is clicked
  59559. * function changeGray() {
  59560. * g = random(0, 255);
  59561. * }
  59562. * </code></div>
  59563. *
  59564. * @alt
  59565. * no display.
  59566. */
  59567. _main.default.Element.prototype.mousePressed = function(fxn) {
  59568. // Prepend the mouse property setters to the event-listener.
  59569. // This is required so that mouseButton is set correctly prior to calling the callback (fxn).
  59570. // For details, see https://github.com/processing/p5.js/issues/3087.
  59571. var eventPrependedFxn = function eventPrependedFxn(event) {
  59572. this._pInst._setProperty('mouseIsPressed', true);
  59573. this._pInst._setMouseButton(event);
  59574. // Pass along the return-value of the callback:
  59575. return fxn.call(this);
  59576. };
  59577. // Pass along the event-prepended form of the callback.
  59578. _main.default.Element._adjustListener('mousedown', eventPrependedFxn, this);
  59579. return this;
  59580. };
  59581. /**
  59582. * The .<a href="#/p5.Element/doubleClicked">doubleClicked()</a> function is called once after every time a
  59583. * mouse button is pressed twice over the element. This can be used to
  59584. * attach element and action specific event listeners.
  59585. *
  59586. * @method doubleClicked
  59587. * @param {Function|Boolean} fxn function to be fired when mouse is
  59588. * double clicked over the element.
  59589. * if `false` is passed instead, the previously
  59590. * firing function will no longer fire.
  59591. * @return {p5.Element}
  59592. * @example
  59593. * <div class='norender'><code>
  59594. * let cnv, d, g;
  59595. * function setup() {
  59596. * cnv = createCanvas(100, 100);
  59597. * cnv.doubleClicked(changeGray); // attach listener for
  59598. * // canvas double click only
  59599. * d = 10;
  59600. * g = 100;
  59601. * }
  59602. *
  59603. * function draw() {
  59604. * background(g);
  59605. * ellipse(width / 2, height / 2, d, d);
  59606. * }
  59607. *
  59608. * // this function fires with any double click anywhere
  59609. * function doubleClicked() {
  59610. * d = d + 10;
  59611. * }
  59612. *
  59613. * // this function fires only when cnv is double clicked
  59614. * function changeGray() {
  59615. * g = random(0, 255);
  59616. * }
  59617. * </code></div>
  59618. *
  59619. * @alt
  59620. * no display.
  59621. */
  59622. _main.default.Element.prototype.doubleClicked = function(fxn) {
  59623. _main.default.Element._adjustListener('dblclick', fxn, this);
  59624. return this;
  59625. };
  59626. /**
  59627. * The <a href="#/p5.Element/mouseWheel">mouseWheel()</a> function is called
  59628. * once after every time a mouse wheel is scrolled over the element. This can
  59629. * be used to attach element specific event listeners.
  59630. *
  59631. * The function accepts a callback function as argument which will be executed
  59632. * when the `wheel` event is triggered on the element, the callback function is
  59633. * passed one argument `event`. The `event.deltaY` property returns negative
  59634. * values if the mouse wheel is rotated up or away from the user and positive
  59635. * in the other direction. The `event.deltaX` does the same as `event.deltaY`
  59636. * except it reads the horizontal wheel scroll of the mouse wheel.
  59637. *
  59638. * On OS X with "natural" scrolling enabled, the `event.deltaY` values are
  59639. * reversed.
  59640. *
  59641. * @method mouseWheel
  59642. * @param {Function|Boolean} fxn function to be fired when mouse is
  59643. * scrolled over the element.
  59644. * if `false` is passed instead, the previously
  59645. * firing function will no longer fire.
  59646. * @chainable
  59647. * @example
  59648. * <div class='norender'><code>
  59649. * let cnv, d, g;
  59650. * function setup() {
  59651. * cnv = createCanvas(100, 100);
  59652. * cnv.mouseWheel(changeSize); // attach listener for
  59653. * // activity on canvas only
  59654. * d = 10;
  59655. * g = 100;
  59656. * }
  59657. *
  59658. * function draw() {
  59659. * background(g);
  59660. * ellipse(width / 2, height / 2, d, d);
  59661. * }
  59662. *
  59663. * // this function fires with mousewheel movement
  59664. * // anywhere on screen
  59665. * function mouseWheel() {
  59666. * g = g + 10;
  59667. * }
  59668. *
  59669. * // this function fires with mousewheel movement
  59670. * // over canvas only
  59671. * function changeSize(event) {
  59672. * if (event.deltaY > 0) {
  59673. * d = d + 10;
  59674. * } else {
  59675. * d = d - 10;
  59676. * }
  59677. * }
  59678. * </code></div>
  59679. *
  59680. * @alt
  59681. * no display.
  59682. */
  59683. _main.default.Element.prototype.mouseWheel = function(fxn) {
  59684. _main.default.Element._adjustListener('wheel', fxn, this);
  59685. return this;
  59686. };
  59687. /**
  59688. * The <a href="#/p5.Element/mouseReleased">mouseReleased()</a> function is
  59689. * called once after every time a mouse button is released over the element.
  59690. * Some mobile browsers may also trigger this event on a touch screen, if the
  59691. * user performs a quick tap. This can be used to attach element specific event listeners.
  59692. *
  59693. * @method mouseReleased
  59694. * @param {Function|Boolean} fxn function to be fired when mouse is
  59695. * released over the element.
  59696. * if `false` is passed instead, the previously
  59697. * firing function will no longer fire.
  59698. * @chainable
  59699. * @example
  59700. * <div class='norender'><code>
  59701. * let cnv, d, g;
  59702. * function setup() {
  59703. * cnv = createCanvas(100, 100);
  59704. * cnv.mouseReleased(changeGray); // attach listener for
  59705. * // activity on canvas only
  59706. * d = 10;
  59707. * g = 100;
  59708. * }
  59709. *
  59710. * function draw() {
  59711. * background(g);
  59712. * ellipse(width / 2, height / 2, d, d);
  59713. * }
  59714. *
  59715. * // this function fires after the mouse has been
  59716. * // released
  59717. * function mouseReleased() {
  59718. * d = d + 10;
  59719. * }
  59720. *
  59721. * // this function fires after the mouse has been
  59722. * // released while on canvas
  59723. * function changeGray() {
  59724. * g = random(0, 255);
  59725. * }
  59726. * </code></div>
  59727. *
  59728. * @alt
  59729. * no display.
  59730. */
  59731. _main.default.Element.prototype.mouseReleased = function(fxn) {
  59732. _main.default.Element._adjustListener('mouseup', fxn, this);
  59733. return this;
  59734. };
  59735. /**
  59736. * The .<a href="#/p5.Element/mouseClicked">mouseClicked()</a> function is
  59737. * called once after a mouse button is pressed and released over the element.
  59738. * Some mobile browsers may also trigger this event on a touch screen, if the
  59739. * user performs a quick tap.This can be used to attach element specific event listeners.
  59740. *
  59741. * @method mouseClicked
  59742. * @param {Function|Boolean} fxn function to be fired when mouse is
  59743. * clicked over the element.
  59744. * if `false` is passed instead, the previously
  59745. * firing function will no longer fire.
  59746. * @chainable
  59747. * @example
  59748. * <div class="norender">
  59749. * <code>
  59750. * let cnv, d, g;
  59751. * function setup() {
  59752. * cnv = createCanvas(100, 100);
  59753. * cnv.mouseClicked(changeGray); // attach listener for
  59754. * // activity on canvas only
  59755. * d = 10;
  59756. * g = 100;
  59757. * }
  59758. *
  59759. * function draw() {
  59760. * background(g);
  59761. * ellipse(width / 2, height / 2, d, d);
  59762. * }
  59763. *
  59764. * // this function fires after the mouse has been
  59765. * // clicked anywhere
  59766. * function mouseClicked() {
  59767. * d = d + 10;
  59768. * }
  59769. *
  59770. * // this function fires after the mouse has been
  59771. * // clicked on canvas
  59772. * function changeGray() {
  59773. * g = random(0, 255);
  59774. * }
  59775. * </code>
  59776. * </div>
  59777. *
  59778. * @alt
  59779. * no display.
  59780. */
  59781. _main.default.Element.prototype.mouseClicked = function(fxn) {
  59782. _main.default.Element._adjustListener('click', fxn, this);
  59783. return this;
  59784. };
  59785. /**
  59786. * The .<a href="#/p5.Element/mouseMoved">mouseMoved()</a> function is called once every time a
  59787. * mouse moves over the element. This can be used to attach an
  59788. * element specific event listener.
  59789. *
  59790. * @method mouseMoved
  59791. * @param {Function|Boolean} fxn function to be fired when a mouse moves
  59792. * over the element.
  59793. * if `false` is passed instead, the previously
  59794. * firing function will no longer fire.
  59795. * @chainable
  59796. * @example
  59797. * <div class='norender'><code>
  59798. * let cnv;
  59799. * let d = 30;
  59800. * let g;
  59801. * function setup() {
  59802. * cnv = createCanvas(100, 100);
  59803. * cnv.mouseMoved(changeSize); // attach listener for
  59804. * // activity on canvas only
  59805. * d = 10;
  59806. * g = 100;
  59807. * }
  59808. *
  59809. * function draw() {
  59810. * background(g);
  59811. * fill(200);
  59812. * ellipse(width / 2, height / 2, d, d);
  59813. * }
  59814. *
  59815. * // this function fires when mouse moves anywhere on
  59816. * // page
  59817. * function mouseMoved() {
  59818. * g = g + 5;
  59819. * if (g > 255) {
  59820. * g = 0;
  59821. * }
  59822. * }
  59823. *
  59824. * // this function fires when mouse moves over canvas
  59825. * function changeSize() {
  59826. * d = d + 2;
  59827. * if (d > 100) {
  59828. * d = 0;
  59829. * }
  59830. * }
  59831. * </code></div>
  59832. *
  59833. * @alt
  59834. * no display.
  59835. */
  59836. _main.default.Element.prototype.mouseMoved = function(fxn) {
  59837. _main.default.Element._adjustListener('mousemove', fxn, this);
  59838. return this;
  59839. };
  59840. /**
  59841. * The .<a href="#/p5.Element/mouseOver">mouseOver()</a> function is called once after every time a
  59842. * mouse moves onto the element. This can be used to attach an
  59843. * element specific event listener.
  59844. *
  59845. * @method mouseOver
  59846. * @param {Function|Boolean} fxn function to be fired when a mouse moves
  59847. * onto the element.
  59848. * if `false` is passed instead, the previously
  59849. * firing function will no longer fire.
  59850. * @chainable
  59851. * @example
  59852. * <div class='norender'><code>
  59853. * let cnv;
  59854. * let d;
  59855. * function setup() {
  59856. * cnv = createCanvas(100, 100);
  59857. * cnv.mouseOver(changeGray);
  59858. * d = 10;
  59859. * }
  59860. *
  59861. * function draw() {
  59862. * ellipse(width / 2, height / 2, d, d);
  59863. * }
  59864. *
  59865. * function changeGray() {
  59866. * d = d + 10;
  59867. * if (d > 100) {
  59868. * d = 0;
  59869. * }
  59870. * }
  59871. * </code></div>
  59872. *
  59873. * @alt
  59874. * no display.
  59875. */
  59876. _main.default.Element.prototype.mouseOver = function(fxn) {
  59877. _main.default.Element._adjustListener('mouseover', fxn, this);
  59878. return this;
  59879. };
  59880. /**
  59881. * The .<a href="#/p5.Element/mouseOut">mouseOut()</a> function is called once after every time a
  59882. * mouse moves off the element. This can be used to attach an
  59883. * element specific event listener.
  59884. *
  59885. * @method mouseOut
  59886. * @param {Function|Boolean} fxn function to be fired when a mouse
  59887. * moves off of an element.
  59888. * if `false` is passed instead, the previously
  59889. * firing function will no longer fire.
  59890. * @chainable
  59891. * @example
  59892. * <div class='norender'><code>
  59893. * let cnv;
  59894. * let d;
  59895. * function setup() {
  59896. * cnv = createCanvas(100, 100);
  59897. * cnv.mouseOut(changeGray);
  59898. * d = 10;
  59899. * }
  59900. *
  59901. * function draw() {
  59902. * ellipse(width / 2, height / 2, d, d);
  59903. * }
  59904. *
  59905. * function changeGray() {
  59906. * d = d + 10;
  59907. * if (d > 100) {
  59908. * d = 0;
  59909. * }
  59910. * }
  59911. * </code></div>
  59912. *
  59913. * @alt
  59914. * no display.
  59915. */
  59916. _main.default.Element.prototype.mouseOut = function(fxn) {
  59917. _main.default.Element._adjustListener('mouseout', fxn, this);
  59918. return this;
  59919. };
  59920. /**
  59921. * The .<a href="#/p5.Element/touchStarted">touchStarted()</a> function is called once after every time a touch is
  59922. * registered. This can be used to attach element specific event listeners.
  59923. *
  59924. * @method touchStarted
  59925. * @param {Function|Boolean} fxn function to be fired when a touch
  59926. * starts over the element.
  59927. * if `false` is passed instead, the previously
  59928. * firing function will no longer fire.
  59929. * @chainable
  59930. * @example
  59931. * <div class='norender'><code>
  59932. * let cnv;
  59933. * let d;
  59934. * let g;
  59935. * function setup() {
  59936. * cnv = createCanvas(100, 100);
  59937. * cnv.touchStarted(changeGray); // attach listener for
  59938. * // canvas click only
  59939. * d = 10;
  59940. * g = 100;
  59941. * }
  59942. *
  59943. * function draw() {
  59944. * background(g);
  59945. * ellipse(width / 2, height / 2, d, d);
  59946. * }
  59947. *
  59948. * // this function fires with any touch anywhere
  59949. * function touchStarted() {
  59950. * d = d + 10;
  59951. * }
  59952. *
  59953. * // this function fires only when cnv is clicked
  59954. * function changeGray() {
  59955. * g = random(0, 255);
  59956. * }
  59957. * </code></div>
  59958. *
  59959. * @alt
  59960. * no display.
  59961. */
  59962. _main.default.Element.prototype.touchStarted = function(fxn) {
  59963. _main.default.Element._adjustListener('touchstart', fxn, this);
  59964. return this;
  59965. };
  59966. /**
  59967. * The .<a href="#/p5.Element/touchMoved">touchMoved()</a> function is called once after every time a touch move is
  59968. * registered. This can be used to attach element specific event listeners.
  59969. *
  59970. * @method touchMoved
  59971. * @param {Function|Boolean} fxn function to be fired when a touch moves over
  59972. * the element.
  59973. * if `false` is passed instead, the previously
  59974. * firing function will no longer fire.
  59975. * @chainable
  59976. * @example
  59977. * <div class='norender'><code>
  59978. * let cnv;
  59979. * let g;
  59980. * function setup() {
  59981. * cnv = createCanvas(100, 100);
  59982. * cnv.touchMoved(changeGray); // attach listener for
  59983. * // canvas click only
  59984. * g = 100;
  59985. * }
  59986. *
  59987. * function draw() {
  59988. * background(g);
  59989. * }
  59990. *
  59991. * // this function fires only when cnv is clicked
  59992. * function changeGray() {
  59993. * g = random(0, 255);
  59994. * }
  59995. * </code></div>
  59996. *
  59997. * @alt
  59998. * no display.
  59999. */
  60000. _main.default.Element.prototype.touchMoved = function(fxn) {
  60001. _main.default.Element._adjustListener('touchmove', fxn, this);
  60002. return this;
  60003. };
  60004. /**
  60005. * The .<a href="#/p5.Element/touchEnded">touchEnded()</a> function is called once after every time a touch is
  60006. * registered. This can be used to attach element specific event listeners.
  60007. *
  60008. * @method touchEnded
  60009. * @param {Function|Boolean} fxn function to be fired when a touch ends
  60010. * over the element.
  60011. * if `false` is passed instead, the previously
  60012. * firing function will no longer fire.
  60013. * @chainable
  60014. * @example
  60015. * <div class='norender'><code>
  60016. * let cnv;
  60017. * let d;
  60018. * let g;
  60019. * function setup() {
  60020. * cnv = createCanvas(100, 100);
  60021. * cnv.touchEnded(changeGray); // attach listener for
  60022. * // canvas click only
  60023. * d = 10;
  60024. * g = 100;
  60025. * }
  60026. *
  60027. * function draw() {
  60028. * background(g);
  60029. * ellipse(width / 2, height / 2, d, d);
  60030. * }
  60031. *
  60032. * // this function fires with any touch anywhere
  60033. * function touchEnded() {
  60034. * d = d + 10;
  60035. * }
  60036. *
  60037. * // this function fires only when cnv is clicked
  60038. * function changeGray() {
  60039. * g = random(0, 255);
  60040. * }
  60041. * </code></div>
  60042. *
  60043. * @alt
  60044. * no display.
  60045. */
  60046. _main.default.Element.prototype.touchEnded = function(fxn) {
  60047. _main.default.Element._adjustListener('touchend', fxn, this);
  60048. return this;
  60049. };
  60050. /**
  60051. * The .<a href="#/p5.Element/dragOver">dragOver()</a> function is called once after every time a
  60052. * file is dragged over the element. This can be used to attach an
  60053. * element specific event listener.
  60054. *
  60055. * @method dragOver
  60056. * @param {Function|Boolean} fxn function to be fired when a file is
  60057. * dragged over the element.
  60058. * if `false` is passed instead, the previously
  60059. * firing function will no longer fire.
  60060. * @chainable
  60061. * @example
  60062. * <div><code>
  60063. * // To test this sketch, simply drag a
  60064. * // file over the canvas
  60065. * function setup() {
  60066. * let c = createCanvas(100, 100);
  60067. * background(200);
  60068. * textAlign(CENTER);
  60069. * text('Drag file', width / 2, height / 2);
  60070. * c.dragOver(dragOverCallback);
  60071. * }
  60072. *
  60073. * // This function will be called whenever
  60074. * // a file is dragged over the canvas
  60075. * function dragOverCallback() {
  60076. * background(240);
  60077. * text('Dragged over', width / 2, height / 2);
  60078. * }
  60079. * </code></div>
  60080. * @alt
  60081. * nothing displayed
  60082. */
  60083. _main.default.Element.prototype.dragOver = function(fxn) {
  60084. _main.default.Element._adjustListener('dragover', fxn, this);
  60085. return this;
  60086. };
  60087. /**
  60088. * The .dragLeave() function is called once after every time a
  60089. * dragged file leaves the element area. This can be used to attach an
  60090. * element specific event listener.
  60091. *
  60092. * @method dragLeave
  60093. * @param {Function|Boolean} fxn function to be fired when a file is
  60094. * dragged off the element.
  60095. * if `false` is passed instead, the previously
  60096. * firing function will no longer fire.
  60097. * @chainable
  60098. * @example
  60099. * <div><code>
  60100. * // To test this sketch, simply drag a file
  60101. * // over and then out of the canvas area
  60102. * function setup() {
  60103. * let c = createCanvas(100, 100);
  60104. * background(200);
  60105. * textAlign(CENTER);
  60106. * text('Drag file', width / 2, height / 2);
  60107. * c.dragLeave(dragLeaveCallback);
  60108. * }
  60109. *
  60110. * // This function will be called whenever
  60111. * // a file is dragged out of the canvas
  60112. * function dragLeaveCallback() {
  60113. * background(240);
  60114. * text('Dragged off', width / 2, height / 2);
  60115. * }
  60116. * </code></div>
  60117. * @alt
  60118. * nothing displayed
  60119. */
  60120. _main.default.Element.prototype.dragLeave = function(fxn) {
  60121. _main.default.Element._adjustListener('dragleave', fxn, this);
  60122. return this;
  60123. };
  60124. // General handler for event attaching and detaching
  60125. _main.default.Element._adjustListener = function(ev, fxn, ctx) {
  60126. if (fxn === false) {
  60127. _main.default.Element._detachListener(ev, ctx);
  60128. } else {
  60129. _main.default.Element._attachListener(ev, fxn, ctx);
  60130. }
  60131. return this;
  60132. };
  60133. _main.default.Element._attachListener = function(ev, fxn, ctx) {
  60134. // detach the old listener if there was one
  60135. if (ctx._events[ev]) {
  60136. _main.default.Element._detachListener(ev, ctx);
  60137. }
  60138. var f = fxn.bind(ctx);
  60139. ctx.elt.addEventListener(ev, f, false);
  60140. ctx._events[ev] = f;
  60141. };
  60142. _main.default.Element._detachListener = function(ev, ctx) {
  60143. var f = ctx._events[ev];
  60144. ctx.elt.removeEventListener(ev, f, false);
  60145. ctx._events[ev] = null;
  60146. };
  60147. /**
  60148. * Helper fxn for sharing pixel methods
  60149. */
  60150. _main.default.Element.prototype._setProperty = function(prop, value) {
  60151. this[prop] = value;
  60152. };
  60153. var _default = _main.default.Element;
  60154. exports.default = _default;
  60155. },
  60156. { './main': 283 }
  60157. ],
  60158. 285: [
  60159. function(_dereq_, module, exports) {
  60160. 'use strict';
  60161. function _typeof(obj) {
  60162. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  60163. _typeof = function _typeof(obj) {
  60164. return typeof obj;
  60165. };
  60166. } else {
  60167. _typeof = function _typeof(obj) {
  60168. return obj &&
  60169. typeof Symbol === 'function' &&
  60170. obj.constructor === Symbol &&
  60171. obj !== Symbol.prototype
  60172. ? 'symbol'
  60173. : typeof obj;
  60174. };
  60175. }
  60176. return _typeof(obj);
  60177. }
  60178. _dereq_('core-js/modules/es.array.index-of');
  60179. _dereq_('core-js/modules/es.array.splice');
  60180. Object.defineProperty(exports, '__esModule', { value: true });
  60181. exports.default = void 0;
  60182. var _main = _interopRequireDefault(_dereq_('./main'));
  60183. var constants = _interopRequireWildcard(_dereq_('./constants'));
  60184. function _getRequireWildcardCache() {
  60185. if (typeof WeakMap !== 'function') return null;
  60186. var cache = new WeakMap();
  60187. _getRequireWildcardCache = function _getRequireWildcardCache() {
  60188. return cache;
  60189. };
  60190. return cache;
  60191. }
  60192. function _interopRequireWildcard(obj) {
  60193. if (obj && obj.__esModule) {
  60194. return obj;
  60195. }
  60196. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  60197. return { default: obj };
  60198. }
  60199. var cache = _getRequireWildcardCache();
  60200. if (cache && cache.has(obj)) {
  60201. return cache.get(obj);
  60202. }
  60203. var newObj = {};
  60204. var hasPropertyDescriptor =
  60205. Object.defineProperty && Object.getOwnPropertyDescriptor;
  60206. for (var key in obj) {
  60207. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  60208. var desc = hasPropertyDescriptor
  60209. ? Object.getOwnPropertyDescriptor(obj, key)
  60210. : null;
  60211. if (desc && (desc.get || desc.set)) {
  60212. Object.defineProperty(newObj, key, desc);
  60213. } else {
  60214. newObj[key] = obj[key];
  60215. }
  60216. }
  60217. }
  60218. newObj.default = obj;
  60219. if (cache) {
  60220. cache.set(obj, newObj);
  60221. }
  60222. return newObj;
  60223. }
  60224. function _interopRequireDefault(obj) {
  60225. return obj && obj.__esModule ? obj : { default: obj };
  60226. }
  60227. /**
  60228. * @module Rendering
  60229. * @submodule Rendering
  60230. * @for p5
  60231. */ /**
  60232. * Thin wrapper around a renderer, to be used for creating a
  60233. * graphics buffer object. Use this class if you need
  60234. * to draw into an off-screen graphics buffer. The two parameters define the
  60235. * width and height in pixels. The fields and methods for this class are
  60236. * extensive, but mirror the normal drawing API for p5.
  60237. *
  60238. * @class p5.Graphics
  60239. * @constructor
  60240. * @extends p5.Element
  60241. * @param {Number} w width
  60242. * @param {Number} h height
  60243. * @param {Constant} renderer the renderer to use, either P2D or WEBGL
  60244. * @param {p5} [pInst] pointer to p5 instance
  60245. */ _main.default.Graphics = function(w, h, renderer, pInst) {
  60246. var r = renderer || constants.P2D;
  60247. this.canvas = document.createElement('canvas');
  60248. var node = pInst._userNode || document.body;
  60249. node.appendChild(this.canvas);
  60250. _main.default.Element.call(this, this.canvas, pInst);
  60251. // bind methods and props of p5 to the new object
  60252. for (var p in _main.default.prototype) {
  60253. if (!this[p]) {
  60254. if (typeof _main.default.prototype[p] === 'function') {
  60255. this[p] = _main.default.prototype[p].bind(this);
  60256. } else {
  60257. this[p] = _main.default.prototype[p];
  60258. }
  60259. }
  60260. }
  60261. _main.default.prototype._initializeInstanceVariables.apply(this);
  60262. this.width = w;
  60263. this.height = h;
  60264. this._pixelDensity = pInst._pixelDensity;
  60265. if (r === constants.WEBGL) {
  60266. this._renderer = new _main.default.RendererGL(this.canvas, this, false);
  60267. } else {
  60268. this._renderer = new _main.default.Renderer2D(this.canvas, this, false);
  60269. }
  60270. pInst._elements.push(this);
  60271. Object.defineProperty(this, 'deltaTime', {
  60272. get: function get() {
  60273. return this._pInst.deltaTime;
  60274. }
  60275. });
  60276. this._renderer.resize(w, h);
  60277. this._renderer._applyDefaults();
  60278. return this;
  60279. };
  60280. _main.default.Graphics.prototype = Object.create(_main.default.Element.prototype);
  60281. /**
  60282. * Resets certain values such as those modified by functions in the Transform category
  60283. * and in the Lights category that are not automatically reset
  60284. * with graphics buffer objects. Calling this in <a href='#/p5/draw'>draw()</a> will copy the behavior
  60285. * of the standard canvas.
  60286. *
  60287. * @method reset
  60288. * @example
  60289. *
  60290. * <div><code>
  60291. * let pg;
  60292. * function setup() {
  60293. * createCanvas(100, 100);
  60294. * background(0);
  60295. * pg = createGraphics(50, 100);
  60296. * pg.fill(0);
  60297. * frameRate(5);
  60298. * }
  60299. *
  60300. * function draw() {
  60301. * image(pg, width / 2, 0);
  60302. * pg.background(255);
  60303. * // p5.Graphics object behave a bit differently in some cases
  60304. * // The normal canvas on the left resets the translate
  60305. * // with every loop through draw()
  60306. * // the graphics object on the right doesn't automatically reset
  60307. * // so translate() is additive and it moves down the screen
  60308. * rect(0, 0, width / 2, 5);
  60309. * pg.rect(0, 0, width / 2, 5);
  60310. * translate(0, 5, 0);
  60311. * pg.translate(0, 5, 0);
  60312. * }
  60313. * function mouseClicked() {
  60314. * // if you click you will see that
  60315. * // reset() resets the translate back to the initial state
  60316. * // of the Graphics object
  60317. * pg.reset();
  60318. * }
  60319. * </code></div>
  60320. *
  60321. * @alt
  60322. * A white line on a black background stays still on the top-left half.
  60323. * A black line animates from top to bottom on a white background on the right half.
  60324. * When clicked, the black line starts back over at the top.
  60325. */
  60326. _main.default.Graphics.prototype.reset = function() {
  60327. this._renderer.resetMatrix();
  60328. if (this._renderer.isP3D) {
  60329. this._renderer._update();
  60330. }
  60331. };
  60332. /**
  60333. * Removes a Graphics object from the page and frees any resources
  60334. * associated with it.
  60335. *
  60336. * @method remove
  60337. *
  60338. * @example
  60339. * <div class='norender'><code>
  60340. * let bg;
  60341. * function setup() {
  60342. * bg = createCanvas(100, 100);
  60343. * bg.background(0);
  60344. * image(bg, 0, 0);
  60345. * bg.remove();
  60346. * }
  60347. * </code></div>
  60348. *
  60349. * <div><code>
  60350. * let bg;
  60351. * function setup() {
  60352. * pixelDensity(1);
  60353. * createCanvas(100, 100);
  60354. * stroke(255);
  60355. * fill(0);
  60356. *
  60357. * // create and draw the background image
  60358. * bg = createGraphics(100, 100);
  60359. * bg.background(200);
  60360. * bg.ellipse(50, 50, 80, 80);
  60361. * }
  60362. * function draw() {
  60363. * let t = millis() / 1000;
  60364. * // draw the background
  60365. * if (bg) {
  60366. * image(bg, frameCount % 100, 0);
  60367. * image(bg, frameCount % 100 - 100, 0);
  60368. * }
  60369. * // draw the foreground
  60370. * let p = p5.Vector.fromAngle(t, 35).add(50, 50);
  60371. * ellipse(p.x, p.y, 30);
  60372. * }
  60373. * function mouseClicked() {
  60374. * // remove the background
  60375. * if (bg) {
  60376. * bg.remove();
  60377. * bg = null;
  60378. * }
  60379. * }
  60380. * </code></div>
  60381. *
  60382. * @alt
  60383. * no image
  60384. * a multi-colored circle moving back and forth over a scrolling background.
  60385. */
  60386. _main.default.Graphics.prototype.remove = function() {
  60387. if (this.elt.parentNode) {
  60388. this.elt.parentNode.removeChild(this.elt);
  60389. }
  60390. var idx = this._pInst._elements.indexOf(this);
  60391. if (idx !== -1) {
  60392. this._pInst._elements.splice(idx, 1);
  60393. }
  60394. for (var elt_ev in this._events) {
  60395. this.elt.removeEventListener(elt_ev, this._events[elt_ev]);
  60396. }
  60397. };
  60398. var _default = _main.default.Graphics;
  60399. exports.default = _default;
  60400. },
  60401. {
  60402. './constants': 272,
  60403. './main': 283,
  60404. 'core-js/modules/es.array.index-of': 173,
  60405. 'core-js/modules/es.array.splice': 180
  60406. }
  60407. ],
  60408. 286: [
  60409. function(_dereq_, module, exports) {
  60410. 'use strict';
  60411. _dereq_('core-js/modules/es.symbol');
  60412. _dereq_('core-js/modules/es.symbol.description');
  60413. _dereq_('core-js/modules/es.symbol.iterator');
  60414. _dereq_('core-js/modules/es.array.iterator');
  60415. _dereq_('core-js/modules/es.number.constructor');
  60416. _dereq_('core-js/modules/es.object.assign');
  60417. _dereq_('core-js/modules/es.object.to-string');
  60418. _dereq_('core-js/modules/es.regexp.exec');
  60419. _dereq_('core-js/modules/es.regexp.to-string');
  60420. _dereq_('core-js/modules/es.string.iterator');
  60421. _dereq_('core-js/modules/es.string.replace');
  60422. _dereq_('core-js/modules/es.string.split');
  60423. _dereq_('core-js/modules/web.dom-collections.iterator');
  60424. Object.defineProperty(exports, '__esModule', { value: true });
  60425. exports.default = void 0;
  60426. var _main = _interopRequireDefault(_dereq_('./main'));
  60427. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  60428. function _getRequireWildcardCache() {
  60429. if (typeof WeakMap !== 'function') return null;
  60430. var cache = new WeakMap();
  60431. _getRequireWildcardCache = function _getRequireWildcardCache() {
  60432. return cache;
  60433. };
  60434. return cache;
  60435. }
  60436. function _interopRequireWildcard(obj) {
  60437. if (obj && obj.__esModule) {
  60438. return obj;
  60439. }
  60440. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  60441. return { default: obj };
  60442. }
  60443. var cache = _getRequireWildcardCache();
  60444. if (cache && cache.has(obj)) {
  60445. return cache.get(obj);
  60446. }
  60447. var newObj = {};
  60448. var hasPropertyDescriptor =
  60449. Object.defineProperty && Object.getOwnPropertyDescriptor;
  60450. for (var key in obj) {
  60451. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  60452. var desc = hasPropertyDescriptor
  60453. ? Object.getOwnPropertyDescriptor(obj, key)
  60454. : null;
  60455. if (desc && (desc.get || desc.set)) {
  60456. Object.defineProperty(newObj, key, desc);
  60457. } else {
  60458. newObj[key] = obj[key];
  60459. }
  60460. }
  60461. }
  60462. newObj.default = obj;
  60463. if (cache) {
  60464. cache.set(obj, newObj);
  60465. }
  60466. return newObj;
  60467. }
  60468. function _interopRequireDefault(obj) {
  60469. return obj && obj.__esModule ? obj : { default: obj };
  60470. }
  60471. function _typeof(obj) {
  60472. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  60473. _typeof = function _typeof(obj) {
  60474. return typeof obj;
  60475. };
  60476. } else {
  60477. _typeof = function _typeof(obj) {
  60478. return obj &&
  60479. typeof Symbol === 'function' &&
  60480. obj.constructor === Symbol &&
  60481. obj !== Symbol.prototype
  60482. ? 'symbol'
  60483. : typeof obj;
  60484. };
  60485. }
  60486. return _typeof(obj);
  60487. }
  60488. /**
  60489. * Main graphics and rendering context, as well as the base API
  60490. * implementation for p5.js "core". To be used as the superclass for
  60491. * Renderer2D and Renderer3D classes, respectively.
  60492. *
  60493. * @class p5.Renderer
  60494. * @constructor
  60495. * @extends p5.Element
  60496. * @param {String} elt DOM node that is wrapped
  60497. * @param {p5} [pInst] pointer to p5 instance
  60498. * @param {Boolean} [isMainCanvas] whether we're using it as main canvas
  60499. */
  60500. _main.default.Renderer = function(elt, pInst, isMainCanvas) {
  60501. _main.default.Element.call(this, elt, pInst);
  60502. this.canvas = elt;
  60503. this._pixelsState = pInst;
  60504. if (isMainCanvas) {
  60505. this._isMainCanvas = true;
  60506. // for pixel method sharing with pimage
  60507. this._pInst._setProperty('_curElement', this);
  60508. this._pInst._setProperty('canvas', this.canvas);
  60509. this._pInst._setProperty('width', this.width);
  60510. this._pInst._setProperty('height', this.height);
  60511. } else {
  60512. // hide if offscreen buffer by default
  60513. this.canvas.style.display = 'none';
  60514. this._styles = []; // non-main elt styles stored in p5.Renderer
  60515. }
  60516. this._textSize = 12;
  60517. this._textLeading = 15;
  60518. this._textFont = 'sans-serif';
  60519. this._textStyle = constants.NORMAL;
  60520. this._textAscent = null;
  60521. this._textDescent = null;
  60522. this._textAlign = constants.LEFT;
  60523. this._textBaseline = constants.BASELINE;
  60524. this._textWrap = constants.WORD;
  60525. this._rectMode = constants.CORNER;
  60526. this._ellipseMode = constants.CENTER;
  60527. this._curveTightness = 0;
  60528. this._imageMode = constants.CORNER;
  60529. this._tint = null;
  60530. this._doStroke = true;
  60531. this._doFill = true;
  60532. this._strokeSet = false;
  60533. this._fillSet = false;
  60534. this._leadingSet = false;
  60535. };
  60536. _main.default.Renderer.prototype = Object.create(_main.default.Element.prototype);
  60537. // the renderer should return a 'style' object that it wishes to
  60538. // store on the push stack.
  60539. _main.default.Renderer.prototype.push = function() {
  60540. return {
  60541. properties: {
  60542. _doStroke: this._doStroke,
  60543. _strokeSet: this._strokeSet,
  60544. _doFill: this._doFill,
  60545. _fillSet: this._fillSet,
  60546. _tint: this._tint,
  60547. _imageMode: this._imageMode,
  60548. _rectMode: this._rectMode,
  60549. _ellipseMode: this._ellipseMode,
  60550. _textFont: this._textFont,
  60551. _textLeading: this._textLeading,
  60552. _leadingSet: this._leadingSet,
  60553. _textSize: this._textSize,
  60554. _textAlign: this._textAlign,
  60555. _textBaseline: this._textBaseline,
  60556. _textStyle: this._textStyle,
  60557. _textWrap: this._textWrap
  60558. }
  60559. };
  60560. };
  60561. // a pop() operation is in progress
  60562. // the renderer is passed the 'style' object that it returned
  60563. // from its push() method.
  60564. _main.default.Renderer.prototype.pop = function(style) {
  60565. if (style.properties) {
  60566. // copy the style properties back into the renderer
  60567. Object.assign(this, style.properties);
  60568. }
  60569. };
  60570. /**
  60571. * Resize our canvas element.
  60572. */
  60573. _main.default.Renderer.prototype.resize = function(w, h) {
  60574. this.width = w;
  60575. this.height = h;
  60576. this.elt.width = w * this._pInst._pixelDensity;
  60577. this.elt.height = h * this._pInst._pixelDensity;
  60578. this.elt.style.width = ''.concat(w, 'px');
  60579. this.elt.style.height = ''.concat(h, 'px');
  60580. if (this._isMainCanvas) {
  60581. this._pInst._setProperty('width', this.width);
  60582. this._pInst._setProperty('height', this.height);
  60583. }
  60584. };
  60585. _main.default.Renderer.prototype.get = function(x, y, w, h) {
  60586. var pixelsState = this._pixelsState;
  60587. var pd = pixelsState._pixelDensity;
  60588. var canvas = this.canvas;
  60589. if (typeof x === 'undefined' && typeof y === 'undefined') {
  60590. // get()
  60591. x = y = 0;
  60592. w = pixelsState.width;
  60593. h = pixelsState.height;
  60594. } else {
  60595. x *= pd;
  60596. y *= pd;
  60597. if (typeof w === 'undefined' && typeof h === 'undefined') {
  60598. // get(x,y)
  60599. if (x < 0 || y < 0 || x >= canvas.width || y >= canvas.height) {
  60600. return [0, 0, 0, 0];
  60601. }
  60602. return this._getPixel(x, y);
  60603. }
  60604. // get(x,y,w,h)
  60605. }
  60606. var region = new _main.default.Image(w, h);
  60607. region.canvas
  60608. .getContext('2d')
  60609. .drawImage(canvas, x, y, w * pd, h * pd, 0, 0, w, h);
  60610. return region;
  60611. };
  60612. _main.default.Renderer.prototype.textLeading = function(l) {
  60613. if (typeof l === 'number') {
  60614. this._setProperty('_leadingSet', true);
  60615. this._setProperty('_textLeading', l);
  60616. return this._pInst;
  60617. }
  60618. return this._textLeading;
  60619. };
  60620. _main.default.Renderer.prototype.textSize = function(s) {
  60621. if (typeof s === 'number') {
  60622. this._setProperty('_textSize', s);
  60623. if (!this._leadingSet) {
  60624. // only use a default value if not previously set (#5181)
  60625. this._setProperty('_textLeading', s * constants._DEFAULT_LEADMULT);
  60626. }
  60627. return this._applyTextProperties();
  60628. }
  60629. return this._textSize;
  60630. };
  60631. _main.default.Renderer.prototype.textStyle = function(s) {
  60632. if (s) {
  60633. if (
  60634. s === constants.NORMAL ||
  60635. s === constants.ITALIC ||
  60636. s === constants.BOLD ||
  60637. s === constants.BOLDITALIC
  60638. ) {
  60639. this._setProperty('_textStyle', s);
  60640. }
  60641. return this._applyTextProperties();
  60642. }
  60643. return this._textStyle;
  60644. };
  60645. _main.default.Renderer.prototype.textAscent = function() {
  60646. if (this._textAscent === null) {
  60647. this._updateTextMetrics();
  60648. }
  60649. return this._textAscent;
  60650. };
  60651. _main.default.Renderer.prototype.textDescent = function() {
  60652. if (this._textDescent === null) {
  60653. this._updateTextMetrics();
  60654. }
  60655. return this._textDescent;
  60656. };
  60657. _main.default.Renderer.prototype.textAlign = function(h, v) {
  60658. if (typeof h !== 'undefined') {
  60659. this._setProperty('_textAlign', h);
  60660. if (typeof v !== 'undefined') {
  60661. this._setProperty('_textBaseline', v);
  60662. }
  60663. return this._applyTextProperties();
  60664. } else {
  60665. return {
  60666. horizontal: this._textAlign,
  60667. vertical: this._textBaseline
  60668. };
  60669. }
  60670. };
  60671. _main.default.Renderer.prototype.textWrap = function(wrapStyle) {
  60672. this._setProperty('_textWrap', wrapStyle);
  60673. return this._textWrap;
  60674. };
  60675. _main.default.Renderer.prototype.text = function(str, x, y, maxWidth, maxHeight) {
  60676. var p = this._pInst;
  60677. var textWrapStyle = this._textWrap;
  60678. var lines;
  60679. var line;
  60680. var testLine;
  60681. var testWidth;
  60682. var words;
  60683. var chars;
  60684. var shiftedY;
  60685. var finalMaxHeight = Number.MAX_VALUE;
  60686. if (!(this._doFill || this._doStroke)) {
  60687. return;
  60688. }
  60689. if (typeof str === 'undefined') {
  60690. return;
  60691. } else if (typeof str !== 'string') {
  60692. str = str.toString();
  60693. }
  60694. // Replaces tabs with double-spaces and splits string at any line breaks present in the original string
  60695. str = str.replace(/(\t)/g, ' ');
  60696. lines = str.split('\n');
  60697. if (typeof maxWidth !== 'undefined') {
  60698. if (this._rectMode === constants.CENTER) {
  60699. x -= maxWidth / 2;
  60700. }
  60701. switch (this._textAlign) {
  60702. case constants.CENTER:
  60703. x += maxWidth / 2;
  60704. break;
  60705. case constants.RIGHT:
  60706. x += maxWidth;
  60707. break;
  60708. }
  60709. var baselineHacked = false;
  60710. if (typeof maxHeight !== 'undefined') {
  60711. if (this._rectMode === constants.CENTER) {
  60712. y -= maxHeight / 2;
  60713. }
  60714. switch (this._textBaseline) {
  60715. case constants.BOTTOM:
  60716. shiftedY = y + (maxHeight - totalHeight);
  60717. y = Math.max(shiftedY, y);
  60718. break;
  60719. case constants.CENTER:
  60720. shiftedY = y + (maxHeight - totalHeight) / 2;
  60721. y = Math.max(shiftedY, y);
  60722. break;
  60723. case constants.BASELINE:
  60724. baselineHacked = true;
  60725. this._textBaseline = constants.TOP;
  60726. break;
  60727. }
  60728. // remember the max-allowed y-position for any line (fix to #928)
  60729. finalMaxHeight = y + maxHeight - p.textAscent();
  60730. }
  60731. // Render lines of text according to settings of textWrap
  60732. // Splits lines at spaces, for loop adds one word + space at a time and tests length with next word added
  60733. if (textWrapStyle === constants.WORD) {
  60734. for (var lineIndex = 0; lineIndex < lines.length; lineIndex++) {
  60735. line = '';
  60736. words = lines[lineIndex].split(' ');
  60737. for (var wordIndex = 0; wordIndex < words.length; wordIndex++) {
  60738. testLine = ''.concat(line + words[wordIndex]) + ' ';
  60739. testWidth = this.textWidth(testLine);
  60740. if (testWidth > maxWidth && line.length > 0) {
  60741. this._renderText(p, line, x, y, finalMaxHeight);
  60742. line = ''.concat(words[wordIndex]) + ' ';
  60743. y += p.textLeading();
  60744. } else {
  60745. line = testLine;
  60746. }
  60747. }
  60748. this._renderText(p, line, x, y, finalMaxHeight);
  60749. y += p.textLeading();
  60750. if (baselineHacked) {
  60751. this._textBaseline = constants.BASELINE;
  60752. }
  60753. }
  60754. } else {
  60755. // Splits lines at characters, for loop adds one char at a time and tests length with next char added
  60756. for (var _lineIndex = 0; _lineIndex < lines.length; _lineIndex++) {
  60757. line = '';
  60758. chars = lines[_lineIndex].split('');
  60759. for (var charIndex = 0; charIndex < chars.length; charIndex++) {
  60760. testLine = ''.concat(line + chars[charIndex]);
  60761. testWidth = this.textWidth(testLine);
  60762. if (testWidth <= maxWidth) {
  60763. line += chars[charIndex];
  60764. } else if (testWidth > maxWidth && line.length > 0) {
  60765. this._renderText(p, line, x, y, finalMaxHeight);
  60766. y += p.textLeading();
  60767. line = ''.concat(chars[charIndex]);
  60768. }
  60769. }
  60770. }
  60771. this._renderText(p, line, x, y, finalMaxHeight);
  60772. y += p.textLeading();
  60773. if (baselineHacked) {
  60774. this._textBaseline = constants.BASELINE;
  60775. }
  60776. }
  60777. } else {
  60778. // Offset to account for vertically centering multiple lines of text - no
  60779. // need to adjust anything for vertical align top or baseline
  60780. var offset = 0;
  60781. var vAlign = p.textAlign().vertical;
  60782. if (vAlign === constants.CENTER) {
  60783. offset = (lines.length - 1) * p.textLeading() / 2;
  60784. } else if (vAlign === constants.BOTTOM) {
  60785. offset = (lines.length - 1) * p.textLeading();
  60786. }
  60787. // Renders lines of text at any line breaks present in the original string
  60788. for (var i = 0; i < lines.length; i++) {
  60789. this._renderText(p, lines[i], x, y - offset, finalMaxHeight);
  60790. y += p.textLeading();
  60791. }
  60792. }
  60793. return p;
  60794. };
  60795. _main.default.Renderer.prototype._applyDefaults = function() {
  60796. return this;
  60797. };
  60798. /**
  60799. * Helper fxn to check font type (system or otf)
  60800. */
  60801. _main.default.Renderer.prototype._isOpenType = function() {
  60802. var f =
  60803. arguments.length > 0 && arguments[0] !== undefined
  60804. ? arguments[0]
  60805. : this._textFont;
  60806. return _typeof(f) === 'object' && f.font && f.font.supported;
  60807. };
  60808. _main.default.Renderer.prototype._updateTextMetrics = function() {
  60809. if (this._isOpenType()) {
  60810. this._setProperty('_textAscent', this._textFont._textAscent());
  60811. this._setProperty('_textDescent', this._textFont._textDescent());
  60812. return this;
  60813. }
  60814. // Adapted from http://stackoverflow.com/a/25355178
  60815. var text = document.createElement('span');
  60816. text.style.fontFamily = this._textFont;
  60817. text.style.fontSize = ''.concat(this._textSize, 'px');
  60818. text.innerHTML = 'ABCjgq|';
  60819. var block = document.createElement('div');
  60820. block.style.display = 'inline-block';
  60821. block.style.width = '1px';
  60822. block.style.height = '0px';
  60823. var container = document.createElement('div');
  60824. container.appendChild(text);
  60825. container.appendChild(block);
  60826. container.style.height = '0px';
  60827. container.style.overflow = 'hidden';
  60828. document.body.appendChild(container);
  60829. block.style.verticalAlign = 'baseline';
  60830. var blockOffset = calculateOffset(block);
  60831. var textOffset = calculateOffset(text);
  60832. var ascent = blockOffset[1] - textOffset[1];
  60833. block.style.verticalAlign = 'bottom';
  60834. blockOffset = calculateOffset(block);
  60835. textOffset = calculateOffset(text);
  60836. var height = blockOffset[1] - textOffset[1];
  60837. var descent = height - ascent;
  60838. document.body.removeChild(container);
  60839. this._setProperty('_textAscent', ascent);
  60840. this._setProperty('_textDescent', descent);
  60841. return this;
  60842. };
  60843. /**
  60844. * Helper fxn to measure ascent and descent.
  60845. * Adapted from http://stackoverflow.com/a/25355178
  60846. */
  60847. function calculateOffset(object) {
  60848. var currentLeft = 0,
  60849. currentTop = 0;
  60850. if (object.offsetParent) {
  60851. do {
  60852. currentLeft += object.offsetLeft;
  60853. currentTop += object.offsetTop;
  60854. } while ((object = object.offsetParent));
  60855. } else {
  60856. currentLeft += object.offsetLeft;
  60857. currentTop += object.offsetTop;
  60858. }
  60859. return [currentLeft, currentTop];
  60860. }
  60861. var _default = _main.default.Renderer;
  60862. exports.default = _default;
  60863. },
  60864. {
  60865. '../core/constants': 272,
  60866. './main': 283,
  60867. 'core-js/modules/es.array.iterator': 174,
  60868. 'core-js/modules/es.number.constructor': 185,
  60869. 'core-js/modules/es.object.assign': 188,
  60870. 'core-js/modules/es.object.to-string': 192,
  60871. 'core-js/modules/es.regexp.exec': 196,
  60872. 'core-js/modules/es.regexp.to-string': 197,
  60873. 'core-js/modules/es.string.iterator': 201,
  60874. 'core-js/modules/es.string.replace': 204,
  60875. 'core-js/modules/es.string.split': 206,
  60876. 'core-js/modules/es.symbol': 211,
  60877. 'core-js/modules/es.symbol.description': 209,
  60878. 'core-js/modules/es.symbol.iterator': 210,
  60879. 'core-js/modules/web.dom-collections.iterator': 244
  60880. }
  60881. ],
  60882. 287: [
  60883. function(_dereq_, module, exports) {
  60884. 'use strict';
  60885. function _typeof(obj) {
  60886. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  60887. _typeof = function _typeof(obj) {
  60888. return typeof obj;
  60889. };
  60890. } else {
  60891. _typeof = function _typeof(obj) {
  60892. return obj &&
  60893. typeof Symbol === 'function' &&
  60894. obj.constructor === Symbol &&
  60895. obj !== Symbol.prototype
  60896. ? 'symbol'
  60897. : typeof obj;
  60898. };
  60899. }
  60900. return _typeof(obj);
  60901. }
  60902. _dereq_('core-js/modules/es.array.concat');
  60903. _dereq_('core-js/modules/es.array.fill');
  60904. _dereq_('core-js/modules/es.array.for-each');
  60905. _dereq_('core-js/modules/es.array.slice');
  60906. _dereq_('core-js/modules/es.function.name');
  60907. _dereq_('core-js/modules/es.number.to-fixed');
  60908. _dereq_('core-js/modules/es.object.to-string');
  60909. _dereq_('core-js/modules/es.regexp.to-string');
  60910. Object.defineProperty(exports, '__esModule', { value: true });
  60911. exports.default = void 0;
  60912. var _main = _interopRequireDefault(_dereq_('./main'));
  60913. var constants = _interopRequireWildcard(_dereq_('./constants'));
  60914. var _filters = _interopRequireDefault(_dereq_('../image/filters'));
  60915. _dereq_('./p5.Renderer');
  60916. function _getRequireWildcardCache() {
  60917. if (typeof WeakMap !== 'function') return null;
  60918. var cache = new WeakMap();
  60919. _getRequireWildcardCache = function _getRequireWildcardCache() {
  60920. return cache;
  60921. };
  60922. return cache;
  60923. }
  60924. function _interopRequireWildcard(obj) {
  60925. if (obj && obj.__esModule) {
  60926. return obj;
  60927. }
  60928. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  60929. return { default: obj };
  60930. }
  60931. var cache = _getRequireWildcardCache();
  60932. if (cache && cache.has(obj)) {
  60933. return cache.get(obj);
  60934. }
  60935. var newObj = {};
  60936. var hasPropertyDescriptor =
  60937. Object.defineProperty && Object.getOwnPropertyDescriptor;
  60938. for (var key in obj) {
  60939. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  60940. var desc = hasPropertyDescriptor
  60941. ? Object.getOwnPropertyDescriptor(obj, key)
  60942. : null;
  60943. if (desc && (desc.get || desc.set)) {
  60944. Object.defineProperty(newObj, key, desc);
  60945. } else {
  60946. newObj[key] = obj[key];
  60947. }
  60948. }
  60949. }
  60950. newObj.default = obj;
  60951. if (cache) {
  60952. cache.set(obj, newObj);
  60953. }
  60954. return newObj;
  60955. }
  60956. function _interopRequireDefault(obj) {
  60957. return obj && obj.__esModule ? obj : { default: obj };
  60958. }
  60959. /**
  60960. * p5.Renderer2D
  60961. * The 2D graphics canvas renderer class.
  60962. * extends p5.Renderer
  60963. */
  60964. var styleEmpty = 'rgba(0,0,0,0)';
  60965. // const alphaThreshold = 0.00125; // minimum visible
  60966. _main.default.Renderer2D = function(elt, pInst, isMainCanvas) {
  60967. _main.default.Renderer.call(this, elt, pInst, isMainCanvas);
  60968. this.drawingContext = this.canvas.getContext('2d');
  60969. this._pInst._setProperty('drawingContext', this.drawingContext);
  60970. return this;
  60971. };
  60972. _main.default.Renderer2D.prototype = Object.create(
  60973. _main.default.Renderer.prototype
  60974. );
  60975. _main.default.Renderer2D.prototype._applyDefaults = function() {
  60976. this._cachedFillStyle = this._cachedStrokeStyle = undefined;
  60977. this._cachedBlendMode = constants.BLEND;
  60978. this._setFill(constants._DEFAULT_FILL);
  60979. this._setStroke(constants._DEFAULT_STROKE);
  60980. this.drawingContext.lineCap = constants.ROUND;
  60981. this.drawingContext.font = 'normal 12px sans-serif';
  60982. };
  60983. _main.default.Renderer2D.prototype.resize = function(w, h) {
  60984. _main.default.Renderer.prototype.resize.call(this, w, h);
  60985. this.drawingContext.scale(this._pInst._pixelDensity, this._pInst._pixelDensity);
  60986. };
  60987. //////////////////////////////////////////////
  60988. // COLOR | Setting
  60989. //////////////////////////////////////////////
  60990. _main.default.Renderer2D.prototype.background = function() {
  60991. this.drawingContext.save();
  60992. this.resetMatrix();
  60993. if (
  60994. (arguments.length <= 0 ? undefined : arguments[0]) instanceof
  60995. _main.default.Image
  60996. ) {
  60997. this._pInst.image(
  60998. arguments.length <= 0 ? undefined : arguments[0],
  60999. 0,
  61000. 0,
  61001. this.width,
  61002. this.height
  61003. );
  61004. } else {
  61005. var _this$_pInst;
  61006. var curFill = this._getFill();
  61007. // create background rect
  61008. var color = (_this$_pInst = this._pInst).color.apply(_this$_pInst, arguments);
  61009. //accessible Outputs
  61010. if (this._pInst._addAccsOutput()) {
  61011. this._pInst._accsBackground(color.levels);
  61012. }
  61013. var newFill = color.toString();
  61014. this._setFill(newFill);
  61015. if (this._isErasing) {
  61016. this.blendMode(this._cachedBlendMode);
  61017. }
  61018. this.drawingContext.fillRect(0, 0, this.width, this.height);
  61019. // reset fill
  61020. this._setFill(curFill);
  61021. if (this._isErasing) {
  61022. this._pInst.erase();
  61023. }
  61024. }
  61025. this.drawingContext.restore();
  61026. };
  61027. _main.default.Renderer2D.prototype.clear = function() {
  61028. this.drawingContext.save();
  61029. this.resetMatrix();
  61030. this.drawingContext.clearRect(0, 0, this.width, this.height);
  61031. this.drawingContext.restore();
  61032. };
  61033. _main.default.Renderer2D.prototype.fill = function() {
  61034. var _this$_pInst2;
  61035. var color = (_this$_pInst2 = this._pInst).color.apply(_this$_pInst2, arguments);
  61036. this._setFill(color.toString());
  61037. //accessible Outputs
  61038. if (this._pInst._addAccsOutput()) {
  61039. this._pInst._accsCanvasColors('fill', color.levels);
  61040. }
  61041. };
  61042. _main.default.Renderer2D.prototype.stroke = function() {
  61043. var _this$_pInst3;
  61044. var color = (_this$_pInst3 = this._pInst).color.apply(_this$_pInst3, arguments);
  61045. this._setStroke(color.toString());
  61046. //accessible Outputs
  61047. if (this._pInst._addAccsOutput()) {
  61048. this._pInst._accsCanvasColors('stroke', color.levels);
  61049. }
  61050. };
  61051. _main.default.Renderer2D.prototype.erase = function(opacityFill, opacityStroke) {
  61052. if (!this._isErasing) {
  61053. // cache the fill style
  61054. this._cachedFillStyle = this.drawingContext.fillStyle;
  61055. var newFill = this._pInst.color(255, opacityFill).toString();
  61056. this.drawingContext.fillStyle = newFill;
  61057. //cache the stroke style
  61058. this._cachedStrokeStyle = this.drawingContext.strokeStyle;
  61059. var newStroke = this._pInst.color(255, opacityStroke).toString();
  61060. this.drawingContext.strokeStyle = newStroke;
  61061. //cache blendMode
  61062. var tempBlendMode = this._cachedBlendMode;
  61063. this.blendMode(constants.REMOVE);
  61064. this._cachedBlendMode = tempBlendMode;
  61065. this._isErasing = true;
  61066. }
  61067. };
  61068. _main.default.Renderer2D.prototype.noErase = function() {
  61069. if (this._isErasing) {
  61070. this.drawingContext.fillStyle = this._cachedFillStyle;
  61071. this.drawingContext.strokeStyle = this._cachedStrokeStyle;
  61072. this.blendMode(this._cachedBlendMode);
  61073. this._isErasing = false;
  61074. }
  61075. };
  61076. //////////////////////////////////////////////
  61077. // IMAGE | Loading & Displaying
  61078. //////////////////////////////////////////////
  61079. _main.default.Renderer2D.prototype.image = function(
  61080. img,
  61081. sx,
  61082. sy,
  61083. sWidth,
  61084. sHeight,
  61085. dx,
  61086. dy,
  61087. dWidth,
  61088. dHeight
  61089. ) {
  61090. var cnv;
  61091. if (img.gifProperties) {
  61092. img._animateGif(this._pInst);
  61093. }
  61094. try {
  61095. if (this._tint) {
  61096. if (
  61097. _main.default.MediaElement &&
  61098. img instanceof _main.default.MediaElement
  61099. ) {
  61100. img.loadPixels();
  61101. }
  61102. if (img.canvas) {
  61103. cnv = this._getTintedImageCanvas(img);
  61104. }
  61105. }
  61106. if (!cnv) {
  61107. cnv = img.canvas || img.elt;
  61108. }
  61109. var s = 1;
  61110. if (img.width && img.width > 0) {
  61111. s = cnv.width / img.width;
  61112. }
  61113. if (this._isErasing) {
  61114. this.blendMode(this._cachedBlendMode);
  61115. }
  61116. this.drawingContext.drawImage(
  61117. cnv,
  61118. s * sx,
  61119. s * sy,
  61120. s * sWidth,
  61121. s * sHeight,
  61122. dx,
  61123. dy,
  61124. dWidth,
  61125. dHeight
  61126. );
  61127. if (this._isErasing) {
  61128. this._pInst.erase();
  61129. }
  61130. } catch (e) {
  61131. if (e.name !== 'NS_ERROR_NOT_AVAILABLE') {
  61132. throw e;
  61133. }
  61134. }
  61135. };
  61136. _main.default.Renderer2D.prototype._getTintedImageCanvas = function(img) {
  61137. if (!img.canvas) {
  61138. return img;
  61139. }
  61140. var pixels = _filters.default._toPixels(img.canvas);
  61141. var tmpCanvas = document.createElement('canvas');
  61142. tmpCanvas.width = img.canvas.width;
  61143. tmpCanvas.height = img.canvas.height;
  61144. var tmpCtx = tmpCanvas.getContext('2d');
  61145. var id = tmpCtx.createImageData(img.canvas.width, img.canvas.height);
  61146. var newPixels = id.data;
  61147. for (var i = 0; i < pixels.length; i += 4) {
  61148. var r = pixels[i];
  61149. var g = pixels[i + 1];
  61150. var b = pixels[i + 2];
  61151. var a = pixels[i + 3];
  61152. newPixels[i] = r * this._tint[0] / 255;
  61153. newPixels[i + 1] = g * this._tint[1] / 255;
  61154. newPixels[i + 2] = b * this._tint[2] / 255;
  61155. newPixels[i + 3] = a * this._tint[3] / 255;
  61156. }
  61157. tmpCtx.putImageData(id, 0, 0);
  61158. return tmpCanvas;
  61159. };
  61160. //////////////////////////////////////////////
  61161. // IMAGE | Pixels
  61162. //////////////////////////////////////////////
  61163. _main.default.Renderer2D.prototype.blendMode = function(mode) {
  61164. if (mode === constants.SUBTRACT) {
  61165. console.warn('blendMode(SUBTRACT) only works in WEBGL mode.');
  61166. } else if (
  61167. mode === constants.BLEND ||
  61168. mode === constants.REMOVE ||
  61169. mode === constants.DARKEST ||
  61170. mode === constants.LIGHTEST ||
  61171. mode === constants.DIFFERENCE ||
  61172. mode === constants.MULTIPLY ||
  61173. mode === constants.EXCLUSION ||
  61174. mode === constants.SCREEN ||
  61175. mode === constants.REPLACE ||
  61176. mode === constants.OVERLAY ||
  61177. mode === constants.HARD_LIGHT ||
  61178. mode === constants.SOFT_LIGHT ||
  61179. mode === constants.DODGE ||
  61180. mode === constants.BURN ||
  61181. mode === constants.ADD
  61182. ) {
  61183. this._cachedBlendMode = mode;
  61184. this.drawingContext.globalCompositeOperation = mode;
  61185. } else {
  61186. throw new Error('Mode '.concat(mode, ' not recognized.'));
  61187. }
  61188. };
  61189. _main.default.Renderer2D.prototype.blend = function() {
  61190. var currBlend = this.drawingContext.globalCompositeOperation;
  61191. for (
  61192. var _len = arguments.length, args = new Array(_len), _key = 0;
  61193. _key < _len;
  61194. _key++
  61195. ) {
  61196. args[_key] = arguments[_key];
  61197. }
  61198. var blendMode = args[args.length - 1];
  61199. var copyArgs = Array.prototype.slice.call(args, 0, args.length - 1);
  61200. this.drawingContext.globalCompositeOperation = blendMode;
  61201. _main.default.prototype.copy.apply(this, copyArgs);
  61202. this.drawingContext.globalCompositeOperation = currBlend;
  61203. };
  61204. // p5.Renderer2D.prototype.get = p5.Renderer.prototype.get;
  61205. // .get() is not overridden
  61206. // x,y are canvas-relative (pre-scaled by _pixelDensity)
  61207. _main.default.Renderer2D.prototype._getPixel = function(x, y) {
  61208. var imageData, index;
  61209. imageData = this.drawingContext.getImageData(x, y, 1, 1).data;
  61210. index = 0;
  61211. return [
  61212. imageData[index + 0],
  61213. imageData[index + 1],
  61214. imageData[index + 2],
  61215. imageData[index + 3]
  61216. ];
  61217. };
  61218. _main.default.Renderer2D.prototype.loadPixels = function() {
  61219. var pixelsState = this._pixelsState; // if called by p5.Image
  61220. var pd = pixelsState._pixelDensity;
  61221. var w = this.width * pd;
  61222. var h = this.height * pd;
  61223. var imageData = this.drawingContext.getImageData(0, 0, w, h);
  61224. // @todo this should actually set pixels per object, so diff buffers can
  61225. // have diff pixel arrays.
  61226. pixelsState._setProperty('imageData', imageData);
  61227. pixelsState._setProperty('pixels', imageData.data);
  61228. };
  61229. _main.default.Renderer2D.prototype.set = function(x, y, imgOrCol) {
  61230. // round down to get integer numbers
  61231. x = Math.floor(x);
  61232. y = Math.floor(y);
  61233. var pixelsState = this._pixelsState;
  61234. if (imgOrCol instanceof _main.default.Image) {
  61235. this.drawingContext.save();
  61236. this.drawingContext.setTransform(1, 0, 0, 1, 0, 0);
  61237. this.drawingContext.scale(
  61238. pixelsState._pixelDensity,
  61239. pixelsState._pixelDensity
  61240. );
  61241. this.drawingContext.clearRect(x, y, imgOrCol.width, imgOrCol.height);
  61242. this.drawingContext.drawImage(imgOrCol.canvas, x, y);
  61243. this.drawingContext.restore();
  61244. } else {
  61245. var r = 0,
  61246. g = 0,
  61247. b = 0,
  61248. a = 0;
  61249. var idx =
  61250. 4 *
  61251. (y * pixelsState._pixelDensity * (this.width * pixelsState._pixelDensity) +
  61252. x * pixelsState._pixelDensity);
  61253. if (!pixelsState.imageData) {
  61254. pixelsState.loadPixels.call(pixelsState);
  61255. }
  61256. if (typeof imgOrCol === 'number') {
  61257. if (idx < pixelsState.pixels.length) {
  61258. r = imgOrCol;
  61259. g = imgOrCol;
  61260. b = imgOrCol;
  61261. a = 255;
  61262. //this.updatePixels.call(this);
  61263. }
  61264. } else if (imgOrCol instanceof Array) {
  61265. if (imgOrCol.length < 4) {
  61266. throw new Error('pixel array must be of the form [R, G, B, A]');
  61267. }
  61268. if (idx < pixelsState.pixels.length) {
  61269. r = imgOrCol[0];
  61270. g = imgOrCol[1];
  61271. b = imgOrCol[2];
  61272. a = imgOrCol[3];
  61273. //this.updatePixels.call(this);
  61274. }
  61275. } else if (imgOrCol instanceof _main.default.Color) {
  61276. if (idx < pixelsState.pixels.length) {
  61277. r = imgOrCol.levels[0];
  61278. g = imgOrCol.levels[1];
  61279. b = imgOrCol.levels[2];
  61280. a = imgOrCol.levels[3];
  61281. //this.updatePixels.call(this);
  61282. }
  61283. }
  61284. // loop over pixelDensity * pixelDensity
  61285. for (var i = 0; i < pixelsState._pixelDensity; i++) {
  61286. for (var j = 0; j < pixelsState._pixelDensity; j++) {
  61287. // loop over
  61288. idx =
  61289. 4 *
  61290. ((y * pixelsState._pixelDensity + j) *
  61291. this.width *
  61292. pixelsState._pixelDensity +
  61293. (x * pixelsState._pixelDensity + i));
  61294. pixelsState.pixels[idx] = r;
  61295. pixelsState.pixels[idx + 1] = g;
  61296. pixelsState.pixels[idx + 2] = b;
  61297. pixelsState.pixels[idx + 3] = a;
  61298. }
  61299. }
  61300. }
  61301. };
  61302. _main.default.Renderer2D.prototype.updatePixels = function(x, y, w, h) {
  61303. var pixelsState = this._pixelsState;
  61304. var pd = pixelsState._pixelDensity;
  61305. if (x === undefined && y === undefined && w === undefined && h === undefined) {
  61306. x = 0;
  61307. y = 0;
  61308. w = this.width;
  61309. h = this.height;
  61310. }
  61311. x *= pd;
  61312. y *= pd;
  61313. w *= pd;
  61314. h *= pd;
  61315. if (this.gifProperties) {
  61316. this.gifProperties.frames[this.gifProperties.displayIndex].image =
  61317. pixelsState.imageData;
  61318. }
  61319. this.drawingContext.putImageData(pixelsState.imageData, x, y, 0, 0, w, h);
  61320. };
  61321. //////////////////////////////////////////////
  61322. // SHAPE | 2D Primitives
  61323. //////////////////////////////////////////////
  61324. /**
  61325. * Generate a cubic Bezier representing an arc on the unit circle of total
  61326. * angle `size` radians, beginning `start` radians above the x-axis. Up to
  61327. * four of these curves are combined to make a full arc.
  61328. *
  61329. * See www.joecridge.me/bezier.pdf for an explanation of the method.
  61330. */
  61331. _main.default.Renderer2D.prototype._acuteArcToBezier = function _acuteArcToBezier(
  61332. start,
  61333. size
  61334. ) {
  61335. // Evaluate constants.
  61336. var alpha = size / 2.0,
  61337. cos_alpha = Math.cos(alpha),
  61338. sin_alpha = Math.sin(alpha),
  61339. cot_alpha = 1.0 / Math.tan(alpha),
  61340. // This is how far the arc needs to be rotated.
  61341. phi = start + alpha,
  61342. cos_phi = Math.cos(phi),
  61343. sin_phi = Math.sin(phi),
  61344. lambda = (4.0 - cos_alpha) / 3.0,
  61345. mu = sin_alpha + (cos_alpha - lambda) * cot_alpha;
  61346. // Return rotated waypoints.
  61347. return {
  61348. ax: Math.cos(start).toFixed(7),
  61349. ay: Math.sin(start).toFixed(7),
  61350. bx: (lambda * cos_phi + mu * sin_phi).toFixed(7),
  61351. by: (lambda * sin_phi - mu * cos_phi).toFixed(7),
  61352. cx: (lambda * cos_phi - mu * sin_phi).toFixed(7),
  61353. cy: (lambda * sin_phi + mu * cos_phi).toFixed(7),
  61354. dx: Math.cos(start + size).toFixed(7),
  61355. dy: Math.sin(start + size).toFixed(7)
  61356. };
  61357. };
  61358. /*
  61359. * This function requires that:
  61360. *
  61361. * 0 <= start < TWO_PI
  61362. *
  61363. * start <= stop < start + TWO_PI
  61364. */
  61365. _main.default.Renderer2D.prototype.arc = function(x, y, w, h, start, stop, mode) {
  61366. var ctx = this.drawingContext;
  61367. var rx = w / 2.0;
  61368. var ry = h / 2.0;
  61369. var epsilon = 0.00001; // Smallest visible angle on displays up to 4K.
  61370. var arcToDraw = 0;
  61371. var curves = [];
  61372. x += rx;
  61373. y += ry;
  61374. // Create curves
  61375. while (stop - start >= epsilon) {
  61376. arcToDraw = Math.min(stop - start, constants.HALF_PI);
  61377. curves.push(this._acuteArcToBezier(start, arcToDraw));
  61378. start += arcToDraw;
  61379. }
  61380. // Fill curves
  61381. if (this._doFill) {
  61382. ctx.beginPath();
  61383. curves.forEach(function(curve, index) {
  61384. if (index === 0) {
  61385. ctx.moveTo(x + curve.ax * rx, y + curve.ay * ry);
  61386. }
  61387. // prettier-ignore
  61388. ctx.bezierCurveTo(x + curve.bx * rx, y + curve.by * ry,
  61389. x + curve.cx * rx, y + curve.cy * ry,
  61390. x + curve.dx * rx, y + curve.dy * ry);
  61391. });
  61392. if (mode === constants.PIE || mode == null) {
  61393. ctx.lineTo(x, y);
  61394. }
  61395. ctx.closePath();
  61396. ctx.fill();
  61397. }
  61398. // Stroke curves
  61399. if (this._doStroke) {
  61400. ctx.beginPath();
  61401. curves.forEach(function(curve, index) {
  61402. if (index === 0) {
  61403. ctx.moveTo(x + curve.ax * rx, y + curve.ay * ry);
  61404. }
  61405. // prettier-ignore
  61406. ctx.bezierCurveTo(x + curve.bx * rx, y + curve.by * ry,
  61407. x + curve.cx * rx, y + curve.cy * ry,
  61408. x + curve.dx * rx, y + curve.dy * ry);
  61409. });
  61410. if (mode === constants.PIE) {
  61411. ctx.lineTo(x, y);
  61412. ctx.closePath();
  61413. } else if (mode === constants.CHORD) {
  61414. ctx.closePath();
  61415. }
  61416. ctx.stroke();
  61417. }
  61418. return this;
  61419. };
  61420. _main.default.Renderer2D.prototype.ellipse = function(args) {
  61421. var ctx = this.drawingContext;
  61422. var doFill = this._doFill,
  61423. doStroke = this._doStroke;
  61424. var x = parseFloat(args[0]),
  61425. y = parseFloat(args[1]),
  61426. w = parseFloat(args[2]),
  61427. h = parseFloat(args[3]);
  61428. if (doFill && !doStroke) {
  61429. if (this._getFill() === styleEmpty) {
  61430. return this;
  61431. }
  61432. } else if (!doFill && doStroke) {
  61433. if (this._getStroke() === styleEmpty) {
  61434. return this;
  61435. }
  61436. }
  61437. var kappa = 0.5522847498,
  61438. // control point offset horizontal
  61439. ox = w / 2 * kappa,
  61440. // control point offset vertical
  61441. oy = h / 2 * kappa,
  61442. // x-end
  61443. xe = x + w,
  61444. // y-end
  61445. ye = y + h,
  61446. // x-middle
  61447. xm = x + w / 2,
  61448. ym = y + h / 2; // y-middle
  61449. ctx.beginPath();
  61450. ctx.moveTo(x, ym);
  61451. ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
  61452. ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
  61453. ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
  61454. ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
  61455. if (doFill) {
  61456. ctx.fill();
  61457. }
  61458. if (doStroke) {
  61459. ctx.stroke();
  61460. }
  61461. };
  61462. _main.default.Renderer2D.prototype.line = function(x1, y1, x2, y2) {
  61463. var ctx = this.drawingContext;
  61464. if (!this._doStroke) {
  61465. return this;
  61466. } else if (this._getStroke() === styleEmpty) {
  61467. return this;
  61468. }
  61469. ctx.beginPath();
  61470. ctx.moveTo(x1, y1);
  61471. ctx.lineTo(x2, y2);
  61472. ctx.stroke();
  61473. return this;
  61474. };
  61475. _main.default.Renderer2D.prototype.point = function(x, y) {
  61476. var ctx = this.drawingContext;
  61477. if (!this._doStroke) {
  61478. return this;
  61479. } else if (this._getStroke() === styleEmpty) {
  61480. return this;
  61481. }
  61482. var s = this._getStroke();
  61483. var f = this._getFill();
  61484. // swapping fill color to stroke and back after for correct point rendering
  61485. this._setFill(s);
  61486. ctx.beginPath();
  61487. ctx.arc(x, y, ctx.lineWidth / 2, 0, constants.TWO_PI, false);
  61488. ctx.fill();
  61489. this._setFill(f);
  61490. };
  61491. _main.default.Renderer2D.prototype.quad = function(
  61492. x1,
  61493. y1,
  61494. x2,
  61495. y2,
  61496. x3,
  61497. y3,
  61498. x4,
  61499. y4
  61500. ) {
  61501. var ctx = this.drawingContext;
  61502. var doFill = this._doFill,
  61503. doStroke = this._doStroke;
  61504. if (doFill && !doStroke) {
  61505. if (this._getFill() === styleEmpty) {
  61506. return this;
  61507. }
  61508. } else if (!doFill && doStroke) {
  61509. if (this._getStroke() === styleEmpty) {
  61510. return this;
  61511. }
  61512. }
  61513. ctx.beginPath();
  61514. ctx.moveTo(x1, y1);
  61515. ctx.lineTo(x2, y2);
  61516. ctx.lineTo(x3, y3);
  61517. ctx.lineTo(x4, y4);
  61518. ctx.closePath();
  61519. if (doFill) {
  61520. ctx.fill();
  61521. }
  61522. if (doStroke) {
  61523. ctx.stroke();
  61524. }
  61525. return this;
  61526. };
  61527. _main.default.Renderer2D.prototype.rect = function(args) {
  61528. var x = args[0];
  61529. var y = args[1];
  61530. var w = args[2];
  61531. var h = args[3];
  61532. var tl = args[4];
  61533. var tr = args[5];
  61534. var br = args[6];
  61535. var bl = args[7];
  61536. var ctx = this.drawingContext;
  61537. var doFill = this._doFill,
  61538. doStroke = this._doStroke;
  61539. if (doFill && !doStroke) {
  61540. if (this._getFill() === styleEmpty) {
  61541. return this;
  61542. }
  61543. } else if (!doFill && doStroke) {
  61544. if (this._getStroke() === styleEmpty) {
  61545. return this;
  61546. }
  61547. }
  61548. ctx.beginPath();
  61549. if (typeof tl === 'undefined') {
  61550. // No rounded corners
  61551. ctx.rect(x, y, w, h);
  61552. } else {
  61553. // At least one rounded corner
  61554. // Set defaults when not specified
  61555. if (typeof tr === 'undefined') {
  61556. tr = tl;
  61557. }
  61558. if (typeof br === 'undefined') {
  61559. br = tr;
  61560. }
  61561. if (typeof bl === 'undefined') {
  61562. bl = br;
  61563. }
  61564. // corner rounding must always be positive
  61565. var absW = Math.abs(w);
  61566. var absH = Math.abs(h);
  61567. var hw = absW / 2;
  61568. var hh = absH / 2;
  61569. // Clip radii
  61570. if (absW < 2 * tl) {
  61571. tl = hw;
  61572. }
  61573. if (absH < 2 * tl) {
  61574. tl = hh;
  61575. }
  61576. if (absW < 2 * tr) {
  61577. tr = hw;
  61578. }
  61579. if (absH < 2 * tr) {
  61580. tr = hh;
  61581. }
  61582. if (absW < 2 * br) {
  61583. br = hw;
  61584. }
  61585. if (absH < 2 * br) {
  61586. br = hh;
  61587. }
  61588. if (absW < 2 * bl) {
  61589. bl = hw;
  61590. }
  61591. if (absH < 2 * bl) {
  61592. bl = hh;
  61593. }
  61594. // Draw shape
  61595. ctx.beginPath();
  61596. ctx.moveTo(x + tl, y);
  61597. ctx.arcTo(x + w, y, x + w, y + h, tr);
  61598. ctx.arcTo(x + w, y + h, x, y + h, br);
  61599. ctx.arcTo(x, y + h, x, y, bl);
  61600. ctx.arcTo(x, y, x + w, y, tl);
  61601. ctx.closePath();
  61602. }
  61603. if (this._doFill) {
  61604. ctx.fill();
  61605. }
  61606. if (this._doStroke) {
  61607. ctx.stroke();
  61608. }
  61609. return this;
  61610. };
  61611. _main.default.Renderer2D.prototype.triangle = function(args) {
  61612. var ctx = this.drawingContext;
  61613. var doFill = this._doFill,
  61614. doStroke = this._doStroke;
  61615. var x1 = args[0],
  61616. y1 = args[1];
  61617. var x2 = args[2],
  61618. y2 = args[3];
  61619. var x3 = args[4],
  61620. y3 = args[5];
  61621. if (doFill && !doStroke) {
  61622. if (this._getFill() === styleEmpty) {
  61623. return this;
  61624. }
  61625. } else if (!doFill && doStroke) {
  61626. if (this._getStroke() === styleEmpty) {
  61627. return this;
  61628. }
  61629. }
  61630. ctx.beginPath();
  61631. ctx.moveTo(x1, y1);
  61632. ctx.lineTo(x2, y2);
  61633. ctx.lineTo(x3, y3);
  61634. ctx.closePath();
  61635. if (doFill) {
  61636. ctx.fill();
  61637. }
  61638. if (doStroke) {
  61639. ctx.stroke();
  61640. }
  61641. };
  61642. _main.default.Renderer2D.prototype.endShape = function(
  61643. mode,
  61644. vertices,
  61645. isCurve,
  61646. isBezier,
  61647. isQuadratic,
  61648. isContour,
  61649. shapeKind
  61650. ) {
  61651. if (vertices.length === 0) {
  61652. return this;
  61653. }
  61654. if (!this._doStroke && !this._doFill) {
  61655. return this;
  61656. }
  61657. var closeShape = mode === constants.CLOSE;
  61658. var v;
  61659. if (closeShape && !isContour) {
  61660. vertices.push(vertices[0]);
  61661. }
  61662. var i, j;
  61663. var numVerts = vertices.length;
  61664. if (isCurve && (shapeKind === constants.POLYGON || shapeKind === null)) {
  61665. if (numVerts > 3) {
  61666. var b = [],
  61667. s = 1 - this._curveTightness;
  61668. this.drawingContext.beginPath();
  61669. this.drawingContext.moveTo(vertices[1][0], vertices[1][1]);
  61670. for (i = 1; i + 2 < numVerts; i++) {
  61671. v = vertices[i];
  61672. b[0] = [v[0], v[1]];
  61673. b[1] = [
  61674. v[0] + (s * vertices[i + 1][0] - s * vertices[i - 1][0]) / 6,
  61675. v[1] + (s * vertices[i + 1][1] - s * vertices[i - 1][1]) / 6
  61676. ];
  61677. b[2] = [
  61678. vertices[i + 1][0] + (s * vertices[i][0] - s * vertices[i + 2][0]) / 6,
  61679. vertices[i + 1][1] + (s * vertices[i][1] - s * vertices[i + 2][1]) / 6
  61680. ];
  61681. b[3] = [vertices[i + 1][0], vertices[i + 1][1]];
  61682. this.drawingContext.bezierCurveTo(
  61683. b[1][0],
  61684. b[1][1],
  61685. b[2][0],
  61686. b[2][1],
  61687. b[3][0],
  61688. b[3][1]
  61689. );
  61690. }
  61691. if (closeShape) {
  61692. this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]);
  61693. }
  61694. this._doFillStrokeClose(closeShape);
  61695. }
  61696. } else if (
  61697. isBezier &&
  61698. (shapeKind === constants.POLYGON || shapeKind === null)
  61699. ) {
  61700. this.drawingContext.beginPath();
  61701. for (i = 0; i < numVerts; i++) {
  61702. if (vertices[i].isVert) {
  61703. if (vertices[i].moveTo) {
  61704. this.drawingContext.moveTo(vertices[i][0], vertices[i][1]);
  61705. } else {
  61706. this.drawingContext.lineTo(vertices[i][0], vertices[i][1]);
  61707. }
  61708. } else {
  61709. this.drawingContext.bezierCurveTo(
  61710. vertices[i][0],
  61711. vertices[i][1],
  61712. vertices[i][2],
  61713. vertices[i][3],
  61714. vertices[i][4],
  61715. vertices[i][5]
  61716. );
  61717. }
  61718. }
  61719. this._doFillStrokeClose(closeShape);
  61720. } else if (
  61721. isQuadratic &&
  61722. (shapeKind === constants.POLYGON || shapeKind === null)
  61723. ) {
  61724. this.drawingContext.beginPath();
  61725. for (i = 0; i < numVerts; i++) {
  61726. if (vertices[i].isVert) {
  61727. if (vertices[i].moveTo) {
  61728. this.drawingContext.moveTo(vertices[i][0], vertices[i][1]);
  61729. } else {
  61730. this.drawingContext.lineTo(vertices[i][0], vertices[i][1]);
  61731. }
  61732. } else {
  61733. this.drawingContext.quadraticCurveTo(
  61734. vertices[i][0],
  61735. vertices[i][1],
  61736. vertices[i][2],
  61737. vertices[i][3]
  61738. );
  61739. }
  61740. }
  61741. this._doFillStrokeClose(closeShape);
  61742. } else {
  61743. if (shapeKind === constants.POINTS) {
  61744. for (i = 0; i < numVerts; i++) {
  61745. v = vertices[i];
  61746. if (this._doStroke) {
  61747. this._pInst.stroke(v[6]);
  61748. }
  61749. this._pInst.point(v[0], v[1]);
  61750. }
  61751. } else if (shapeKind === constants.LINES) {
  61752. for (i = 0; i + 1 < numVerts; i += 2) {
  61753. v = vertices[i];
  61754. if (this._doStroke) {
  61755. this._pInst.stroke(vertices[i + 1][6]);
  61756. }
  61757. this._pInst.line(v[0], v[1], vertices[i + 1][0], vertices[i + 1][1]);
  61758. }
  61759. } else if (shapeKind === constants.TRIANGLES) {
  61760. for (i = 0; i + 2 < numVerts; i += 3) {
  61761. v = vertices[i];
  61762. this.drawingContext.beginPath();
  61763. this.drawingContext.moveTo(v[0], v[1]);
  61764. this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]);
  61765. this.drawingContext.lineTo(vertices[i + 2][0], vertices[i + 2][1]);
  61766. this.drawingContext.closePath();
  61767. if (this._doFill) {
  61768. this._pInst.fill(vertices[i + 2][5]);
  61769. this.drawingContext.fill();
  61770. }
  61771. if (this._doStroke) {
  61772. this._pInst.stroke(vertices[i + 2][6]);
  61773. this.drawingContext.stroke();
  61774. }
  61775. }
  61776. } else if (shapeKind === constants.TRIANGLE_STRIP) {
  61777. for (i = 0; i + 1 < numVerts; i++) {
  61778. v = vertices[i];
  61779. this.drawingContext.beginPath();
  61780. this.drawingContext.moveTo(vertices[i + 1][0], vertices[i + 1][1]);
  61781. this.drawingContext.lineTo(v[0], v[1]);
  61782. if (this._doStroke) {
  61783. this._pInst.stroke(vertices[i + 1][6]);
  61784. }
  61785. if (this._doFill) {
  61786. this._pInst.fill(vertices[i + 1][5]);
  61787. }
  61788. if (i + 2 < numVerts) {
  61789. this.drawingContext.lineTo(vertices[i + 2][0], vertices[i + 2][1]);
  61790. if (this._doStroke) {
  61791. this._pInst.stroke(vertices[i + 2][6]);
  61792. }
  61793. if (this._doFill) {
  61794. this._pInst.fill(vertices[i + 2][5]);
  61795. }
  61796. }
  61797. this._doFillStrokeClose(closeShape);
  61798. }
  61799. } else if (shapeKind === constants.TRIANGLE_FAN) {
  61800. if (numVerts > 2) {
  61801. // For performance reasons, try to batch as many of the
  61802. // fill and stroke calls as possible.
  61803. this.drawingContext.beginPath();
  61804. for (i = 2; i < numVerts; i++) {
  61805. v = vertices[i];
  61806. this.drawingContext.moveTo(vertices[0][0], vertices[0][1]);
  61807. this.drawingContext.lineTo(vertices[i - 1][0], vertices[i - 1][1]);
  61808. this.drawingContext.lineTo(v[0], v[1]);
  61809. this.drawingContext.lineTo(vertices[0][0], vertices[0][1]);
  61810. // If the next colour is going to be different, stroke / fill now
  61811. if (i < numVerts - 1) {
  61812. if (
  61813. (this._doFill && v[5] !== vertices[i + 1][5]) ||
  61814. (this._doStroke && v[6] !== vertices[i + 1][6])
  61815. ) {
  61816. if (this._doFill) {
  61817. this._pInst.fill(v[5]);
  61818. this.drawingContext.fill();
  61819. this._pInst.fill(vertices[i + 1][5]);
  61820. }
  61821. if (this._doStroke) {
  61822. this._pInst.stroke(v[6]);
  61823. this.drawingContext.stroke();
  61824. this._pInst.stroke(vertices[i + 1][6]);
  61825. }
  61826. this.drawingContext.closePath();
  61827. this.drawingContext.beginPath(); // Begin the next one
  61828. }
  61829. }
  61830. }
  61831. this._doFillStrokeClose(closeShape);
  61832. }
  61833. } else if (shapeKind === constants.QUADS) {
  61834. for (i = 0; i + 3 < numVerts; i += 4) {
  61835. v = vertices[i];
  61836. this.drawingContext.beginPath();
  61837. this.drawingContext.moveTo(v[0], v[1]);
  61838. for (j = 1; j < 4; j++) {
  61839. this.drawingContext.lineTo(vertices[i + j][0], vertices[i + j][1]);
  61840. }
  61841. this.drawingContext.lineTo(v[0], v[1]);
  61842. if (this._doFill) {
  61843. this._pInst.fill(vertices[i + 3][5]);
  61844. }
  61845. if (this._doStroke) {
  61846. this._pInst.stroke(vertices[i + 3][6]);
  61847. }
  61848. this._doFillStrokeClose(closeShape);
  61849. }
  61850. } else if (shapeKind === constants.QUAD_STRIP) {
  61851. if (numVerts > 3) {
  61852. for (i = 0; i + 1 < numVerts; i += 2) {
  61853. v = vertices[i];
  61854. this.drawingContext.beginPath();
  61855. if (i + 3 < numVerts) {
  61856. this.drawingContext.moveTo(vertices[i + 2][0], vertices[i + 2][1]);
  61857. this.drawingContext.lineTo(v[0], v[1]);
  61858. this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]);
  61859. this.drawingContext.lineTo(vertices[i + 3][0], vertices[i + 3][1]);
  61860. if (this._doFill) {
  61861. this._pInst.fill(vertices[i + 3][5]);
  61862. }
  61863. if (this._doStroke) {
  61864. this._pInst.stroke(vertices[i + 3][6]);
  61865. }
  61866. } else {
  61867. this.drawingContext.moveTo(v[0], v[1]);
  61868. this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]);
  61869. }
  61870. this._doFillStrokeClose(closeShape);
  61871. }
  61872. }
  61873. } else {
  61874. this.drawingContext.beginPath();
  61875. this.drawingContext.moveTo(vertices[0][0], vertices[0][1]);
  61876. for (i = 1; i < numVerts; i++) {
  61877. v = vertices[i];
  61878. if (v.isVert) {
  61879. if (v.moveTo) {
  61880. this.drawingContext.moveTo(v[0], v[1]);
  61881. } else {
  61882. this.drawingContext.lineTo(v[0], v[1]);
  61883. }
  61884. }
  61885. }
  61886. this._doFillStrokeClose(closeShape);
  61887. }
  61888. }
  61889. isCurve = false;
  61890. isBezier = false;
  61891. isQuadratic = false;
  61892. isContour = false;
  61893. if (closeShape) {
  61894. vertices.pop();
  61895. }
  61896. return this;
  61897. };
  61898. //////////////////////////////////////////////
  61899. // SHAPE | Attributes
  61900. //////////////////////////////////////////////
  61901. _main.default.Renderer2D.prototype.strokeCap = function(cap) {
  61902. if (
  61903. cap === constants.ROUND ||
  61904. cap === constants.SQUARE ||
  61905. cap === constants.PROJECT
  61906. ) {
  61907. this.drawingContext.lineCap = cap;
  61908. }
  61909. return this;
  61910. };
  61911. _main.default.Renderer2D.prototype.strokeJoin = function(join) {
  61912. if (
  61913. join === constants.ROUND ||
  61914. join === constants.BEVEL ||
  61915. join === constants.MITER
  61916. ) {
  61917. this.drawingContext.lineJoin = join;
  61918. }
  61919. return this;
  61920. };
  61921. _main.default.Renderer2D.prototype.strokeWeight = function(w) {
  61922. if (typeof w === 'undefined' || w === 0) {
  61923. // hack because lineWidth 0 doesn't work
  61924. this.drawingContext.lineWidth = 0.0001;
  61925. } else {
  61926. this.drawingContext.lineWidth = w;
  61927. }
  61928. return this;
  61929. };
  61930. _main.default.Renderer2D.prototype._getFill = function() {
  61931. if (!this._cachedFillStyle) {
  61932. this._cachedFillStyle = this.drawingContext.fillStyle;
  61933. }
  61934. return this._cachedFillStyle;
  61935. };
  61936. _main.default.Renderer2D.prototype._setFill = function(fillStyle) {
  61937. if (fillStyle !== this._cachedFillStyle) {
  61938. this.drawingContext.fillStyle = fillStyle;
  61939. this._cachedFillStyle = fillStyle;
  61940. }
  61941. };
  61942. _main.default.Renderer2D.prototype._getStroke = function() {
  61943. if (!this._cachedStrokeStyle) {
  61944. this._cachedStrokeStyle = this.drawingContext.strokeStyle;
  61945. }
  61946. return this._cachedStrokeStyle;
  61947. };
  61948. _main.default.Renderer2D.prototype._setStroke = function(strokeStyle) {
  61949. if (strokeStyle !== this._cachedStrokeStyle) {
  61950. this.drawingContext.strokeStyle = strokeStyle;
  61951. this._cachedStrokeStyle = strokeStyle;
  61952. }
  61953. };
  61954. //////////////////////////////////////////////
  61955. // SHAPE | Curves
  61956. //////////////////////////////////////////////
  61957. _main.default.Renderer2D.prototype.bezier = function(
  61958. x1,
  61959. y1,
  61960. x2,
  61961. y2,
  61962. x3,
  61963. y3,
  61964. x4,
  61965. y4
  61966. ) {
  61967. this._pInst.beginShape();
  61968. this._pInst.vertex(x1, y1);
  61969. this._pInst.bezierVertex(x2, y2, x3, y3, x4, y4);
  61970. this._pInst.endShape();
  61971. return this;
  61972. };
  61973. _main.default.Renderer2D.prototype.curve = function(
  61974. x1,
  61975. y1,
  61976. x2,
  61977. y2,
  61978. x3,
  61979. y3,
  61980. x4,
  61981. y4
  61982. ) {
  61983. this._pInst.beginShape();
  61984. this._pInst.curveVertex(x1, y1);
  61985. this._pInst.curveVertex(x2, y2);
  61986. this._pInst.curveVertex(x3, y3);
  61987. this._pInst.curveVertex(x4, y4);
  61988. this._pInst.endShape();
  61989. return this;
  61990. };
  61991. //////////////////////////////////////////////
  61992. // SHAPE | Vertex
  61993. //////////////////////////////////////////////
  61994. _main.default.Renderer2D.prototype._doFillStrokeClose = function(closeShape) {
  61995. if (closeShape) {
  61996. this.drawingContext.closePath();
  61997. }
  61998. if (this._doFill) {
  61999. this.drawingContext.fill();
  62000. }
  62001. if (this._doStroke) {
  62002. this.drawingContext.stroke();
  62003. }
  62004. };
  62005. //////////////////////////////////////////////
  62006. // TRANSFORM
  62007. //////////////////////////////////////////////
  62008. _main.default.Renderer2D.prototype.applyMatrix = function(a, b, c, d, e, f) {
  62009. this.drawingContext.transform(a, b, c, d, e, f);
  62010. };
  62011. _main.default.Renderer2D.prototype.resetMatrix = function() {
  62012. this.drawingContext.setTransform(1, 0, 0, 1, 0, 0);
  62013. this.drawingContext.scale(this._pInst._pixelDensity, this._pInst._pixelDensity);
  62014. return this;
  62015. };
  62016. _main.default.Renderer2D.prototype.rotate = function(rad) {
  62017. this.drawingContext.rotate(rad);
  62018. };
  62019. _main.default.Renderer2D.prototype.scale = function(x, y) {
  62020. this.drawingContext.scale(x, y);
  62021. return this;
  62022. };
  62023. _main.default.Renderer2D.prototype.translate = function(x, y) {
  62024. // support passing a vector as the 1st parameter
  62025. if (x instanceof _main.default.Vector) {
  62026. y = x.y;
  62027. x = x.x;
  62028. }
  62029. this.drawingContext.translate(x, y);
  62030. return this;
  62031. };
  62032. //////////////////////////////////////////////
  62033. // TYPOGRAPHY
  62034. //
  62035. //////////////////////////////////////////////
  62036. _main.default.Renderer2D.prototype.text = function(
  62037. str,
  62038. x,
  62039. y,
  62040. maxWidth,
  62041. maxHeight
  62042. ) {
  62043. var baselineHacked;
  62044. // baselineHacked: (HACK)
  62045. // A temporary fix to conform to Processing's implementation
  62046. // of BASELINE vertical alignment in a bounding box
  62047. if (typeof maxWidth !== 'undefined') {
  62048. if (this.drawingContext.textBaseline === constants.BASELINE) {
  62049. baselineHacked = true;
  62050. this.drawingContext.textBaseline = constants.TOP;
  62051. }
  62052. }
  62053. var p = _main.default.Renderer.prototype.text.apply(this, arguments);
  62054. if (baselineHacked) {
  62055. this.drawingContext.textBaseline = constants.BASELINE;
  62056. }
  62057. return p;
  62058. };
  62059. _main.default.Renderer2D.prototype._renderText = function(p, line, x, y, maxY) {
  62060. if (y >= maxY) {
  62061. return; // don't render lines beyond our maxY position
  62062. }
  62063. p.push(); // fix to #803
  62064. if (!this._isOpenType()) {
  62065. // a system/browser font
  62066. // no stroke unless specified by user
  62067. if (this._doStroke && this._strokeSet) {
  62068. this.drawingContext.strokeText(line, x, y);
  62069. }
  62070. if (this._doFill) {
  62071. // if fill hasn't been set by user, use default text fill
  62072. if (!this._fillSet) {
  62073. this._setFill(constants._DEFAULT_TEXT_FILL);
  62074. }
  62075. this.drawingContext.fillText(line, x, y);
  62076. }
  62077. } else {
  62078. // an opentype font, let it handle the rendering
  62079. this._textFont._renderPath(line, x, y, { renderer: this });
  62080. }
  62081. p.pop();
  62082. return p;
  62083. };
  62084. _main.default.Renderer2D.prototype.textWidth = function(s) {
  62085. if (this._isOpenType()) {
  62086. return this._textFont._textWidth(s, this._textSize);
  62087. }
  62088. return this.drawingContext.measureText(s).width;
  62089. };
  62090. _main.default.Renderer2D.prototype._applyTextProperties = function() {
  62091. var font;
  62092. var p = this._pInst;
  62093. this._setProperty('_textAscent', null);
  62094. this._setProperty('_textDescent', null);
  62095. font = this._textFont;
  62096. if (this._isOpenType()) {
  62097. font = this._textFont.font.familyName;
  62098. this._setProperty('_textStyle', this._textFont.font.styleName);
  62099. }
  62100. this.drawingContext.font = ''
  62101. .concat(this._textStyle || 'normal', ' ')
  62102. .concat(this._textSize || 12, 'px ')
  62103. .concat(font || 'sans-serif');
  62104. this.drawingContext.textAlign = this._textAlign;
  62105. if (this._textBaseline === constants.CENTER) {
  62106. this.drawingContext.textBaseline = constants._CTX_MIDDLE;
  62107. } else {
  62108. this.drawingContext.textBaseline = this._textBaseline;
  62109. }
  62110. return p;
  62111. };
  62112. //////////////////////////////////////////////
  62113. // STRUCTURE
  62114. //////////////////////////////////////////////
  62115. // a push() operation is in progress.
  62116. // the renderer should return a 'style' object that it wishes to
  62117. // store on the push stack.
  62118. // derived renderers should call the base class' push() method
  62119. // to fetch the base style object.
  62120. _main.default.Renderer2D.prototype.push = function() {
  62121. this.drawingContext.save();
  62122. // get the base renderer style
  62123. return _main.default.Renderer.prototype.push.apply(this);
  62124. };
  62125. // a pop() operation is in progress
  62126. // the renderer is passed the 'style' object that it returned
  62127. // from its push() method.
  62128. // derived renderers should pass this object to their base
  62129. // class' pop method
  62130. _main.default.Renderer2D.prototype.pop = function(style) {
  62131. this.drawingContext.restore();
  62132. // Re-cache the fill / stroke state
  62133. this._cachedFillStyle = this.drawingContext.fillStyle;
  62134. this._cachedStrokeStyle = this.drawingContext.strokeStyle;
  62135. _main.default.Renderer.prototype.pop.call(this, style);
  62136. };
  62137. var _default = _main.default.Renderer2D;
  62138. exports.default = _default;
  62139. },
  62140. {
  62141. '../image/filters': 304,
  62142. './constants': 272,
  62143. './main': 283,
  62144. './p5.Renderer': 286,
  62145. 'core-js/modules/es.array.concat': 166,
  62146. 'core-js/modules/es.array.fill': 168,
  62147. 'core-js/modules/es.array.for-each': 170,
  62148. 'core-js/modules/es.array.slice': 178,
  62149. 'core-js/modules/es.function.name': 181,
  62150. 'core-js/modules/es.number.to-fixed': 187,
  62151. 'core-js/modules/es.object.to-string': 192,
  62152. 'core-js/modules/es.regexp.to-string': 197
  62153. }
  62154. ],
  62155. 288: [
  62156. function(_dereq_, module, exports) {
  62157. 'use strict';
  62158. _dereq_('core-js/modules/es.symbol');
  62159. _dereq_('core-js/modules/es.symbol.description');
  62160. _dereq_('core-js/modules/es.symbol.iterator');
  62161. _dereq_('core-js/modules/es.array.iterator');
  62162. _dereq_('core-js/modules/es.object.assign');
  62163. _dereq_('core-js/modules/es.object.to-string');
  62164. _dereq_('core-js/modules/es.promise');
  62165. _dereq_('core-js/modules/es.string.iterator');
  62166. _dereq_('core-js/modules/web.dom-collections.iterator');
  62167. var _main = _interopRequireDefault(_dereq_('./main'));
  62168. function _interopRequireDefault(obj) {
  62169. return obj && obj.__esModule ? obj : { default: obj };
  62170. }
  62171. _main.default.prototype._promisePreloads = [
  62172. /* Example object
  62173. {
  62174. target: p5.prototype, // The target object to have the method modified
  62175. method: 'loadXAsync', // The name of the preload function to wrap
  62176. addCallbacks: true, // Whether to automatically handle the p5 callbacks
  62177. legacyPreloadSetup: { // Optional object to generate a legacy-style preload
  62178. method: 'loadX', // The name of the legacy preload function to generate
  62179. createBaseObject: function() {
  62180. return {};
  62181. } // An optional function to create the base object for the legacy preload.
  62182. }
  62183. }
  62184. */
  62185. ];
  62186. _main.default.prototype.registerPromisePreload = function(setup) {
  62187. _main.default.prototype._promisePreloads.push(setup);
  62188. };
  62189. var initialSetupRan = false;
  62190. _main.default.prototype._setupPromisePreloads = function() {
  62191. var _iteratorNormalCompletion = true;
  62192. var _didIteratorError = false;
  62193. var _iteratorError = undefined;
  62194. try {
  62195. for (
  62196. var _iterator = this._promisePreloads[Symbol.iterator](), _step;
  62197. !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
  62198. _iteratorNormalCompletion = true
  62199. ) {
  62200. var preloadSetup = _step.value;
  62201. var thisValue = this;
  62202. var method = preloadSetup.method,
  62203. addCallbacks = preloadSetup.addCallbacks,
  62204. legacyPreloadSetup = preloadSetup.legacyPreloadSetup;
  62205. // Get the target object that the preload gets assigned to by default,
  62206. // that is the current object.
  62207. var target = preloadSetup.target || this;
  62208. var sourceFunction = target[method].bind(target);
  62209. // If the target is the p5 prototype, then only set it up on the first run per page
  62210. if (target === _main.default.prototype) {
  62211. if (initialSetupRan) {
  62212. continue;
  62213. }
  62214. thisValue = null;
  62215. sourceFunction = target[method];
  62216. }
  62217. // Replace the original method with a wrapped version
  62218. target[method] = this._wrapPromisePreload(
  62219. thisValue,
  62220. sourceFunction,
  62221. addCallbacks
  62222. );
  62223. // If a legacy preload is required
  62224. if (legacyPreloadSetup) {
  62225. // What is the name for this legacy preload
  62226. var legacyMethod = legacyPreloadSetup.method;
  62227. // Wrap the already wrapped Promise-returning method with the legacy setup
  62228. target[legacyMethod] = this._legacyPreloadGenerator(
  62229. thisValue,
  62230. legacyPreloadSetup,
  62231. target[method]
  62232. );
  62233. }
  62234. }
  62235. } catch (err) {
  62236. _didIteratorError = true;
  62237. _iteratorError = err;
  62238. } finally {
  62239. try {
  62240. if (!_iteratorNormalCompletion && _iterator.return != null) {
  62241. _iterator.return();
  62242. }
  62243. } finally {
  62244. if (_didIteratorError) {
  62245. throw _iteratorError;
  62246. }
  62247. }
  62248. }
  62249. initialSetupRan = true;
  62250. };
  62251. _main.default.prototype._wrapPromisePreload = function(
  62252. thisValue,
  62253. fn,
  62254. addCallbacks
  62255. ) {
  62256. var replacementFunction = function replacementFunction() {
  62257. var _this = this;
  62258. // Uses the current preload counting mechanism for now.
  62259. this._incrementPreload();
  62260. // A variable for the callback function if specified
  62261. var callback = null;
  62262. // A variable for the errorCallback function if specified
  62263. var errorCallback = null;
  62264. for (
  62265. var _len = arguments.length, args = new Array(_len), _key = 0;
  62266. _key < _len;
  62267. _key++
  62268. ) {
  62269. args[_key] = arguments[_key];
  62270. }
  62271. if (addCallbacks) {
  62272. // Loop from the end of the args array, pulling up to two functions off of
  62273. // the end and putting them in fns
  62274. for (var i = args.length - 1; i >= 0 && !errorCallback; i--) {
  62275. if (typeof args[i] !== 'function') {
  62276. break;
  62277. }
  62278. errorCallback = callback;
  62279. callback = args.pop();
  62280. }
  62281. }
  62282. // Call the underlying function and pass it to Promise.resolve,
  62283. // so that even if it didn't return a promise we can still
  62284. // act on the result as if it did.
  62285. var promise = Promise.resolve(fn.apply(this, args));
  62286. // Add the optional callbacks
  62287. if (callback) {
  62288. promise.then(callback);
  62289. }
  62290. if (errorCallback) {
  62291. promise.catch(errorCallback);
  62292. }
  62293. // Decrement the preload counter only if the promise resolved
  62294. promise.then(function() {
  62295. return _this._decrementPreload();
  62296. });
  62297. // Return the original promise so that neither callback changes the result.
  62298. return promise;
  62299. };
  62300. if (thisValue) {
  62301. replacementFunction = replacementFunction.bind(thisValue);
  62302. }
  62303. return replacementFunction;
  62304. };
  62305. var objectCreator = function objectCreator() {
  62306. return {};
  62307. };
  62308. _main.default.prototype._legacyPreloadGenerator = function(
  62309. thisValue,
  62310. legacyPreloadSetup,
  62311. fn
  62312. ) {
  62313. // Create a function that will generate an object before the preload is
  62314. // launched. For example, if the object should be an array or be an instance
  62315. // of a specific class.
  62316. var baseValueGenerator = legacyPreloadSetup.createBaseObject || objectCreator;
  62317. var returnedFunction = function returnedFunction() {
  62318. var _this2 = this;
  62319. // Our then clause needs to run before setup, so we also increment the preload counter
  62320. this._incrementPreload();
  62321. // Generate the return value based on the generator.
  62322. var returnValue = baseValueGenerator.apply(this, arguments);
  62323. // Run the original wrapper
  62324. fn.apply(this, arguments).then(function(data) {
  62325. // Copy each key from the resolved value into returnValue
  62326. Object.assign(returnValue, data);
  62327. // Decrement the preload counter, to allow setup to continue.
  62328. _this2._decrementPreload();
  62329. });
  62330. return returnValue;
  62331. };
  62332. if (thisValue) {
  62333. returnedFunction = returnedFunction.bind(thisValue);
  62334. }
  62335. return returnedFunction;
  62336. };
  62337. },
  62338. {
  62339. './main': 283,
  62340. 'core-js/modules/es.array.iterator': 174,
  62341. 'core-js/modules/es.object.assign': 188,
  62342. 'core-js/modules/es.object.to-string': 192,
  62343. 'core-js/modules/es.promise': 193,
  62344. 'core-js/modules/es.string.iterator': 201,
  62345. 'core-js/modules/es.symbol': 211,
  62346. 'core-js/modules/es.symbol.description': 209,
  62347. 'core-js/modules/es.symbol.iterator': 210,
  62348. 'core-js/modules/web.dom-collections.iterator': 244
  62349. }
  62350. ],
  62351. 289: [
  62352. function(_dereq_, module, exports) {
  62353. 'use strict';
  62354. _dereq_('core-js/modules/es.symbol');
  62355. _dereq_('core-js/modules/es.symbol.description');
  62356. _dereq_('core-js/modules/es.symbol.iterator');
  62357. _dereq_('core-js/modules/es.array.filter');
  62358. _dereq_('core-js/modules/es.array.iterator');
  62359. _dereq_('core-js/modules/es.object.to-string');
  62360. _dereq_('core-js/modules/es.string.iterator');
  62361. _dereq_('core-js/modules/web.dom-collections.iterator');
  62362. Object.defineProperty(exports, '__esModule', { value: true });
  62363. exports.default = void 0;
  62364. var _main = _interopRequireDefault(_dereq_('./main'));
  62365. var constants = _interopRequireWildcard(_dereq_('./constants'));
  62366. _dereq_('./p5.Graphics');
  62367. _dereq_('./p5.Renderer2D');
  62368. _dereq_('../webgl/p5.RendererGL');
  62369. function _getRequireWildcardCache() {
  62370. if (typeof WeakMap !== 'function') return null;
  62371. var cache = new WeakMap();
  62372. _getRequireWildcardCache = function _getRequireWildcardCache() {
  62373. return cache;
  62374. };
  62375. return cache;
  62376. }
  62377. function _interopRequireWildcard(obj) {
  62378. if (obj && obj.__esModule) {
  62379. return obj;
  62380. }
  62381. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  62382. return { default: obj };
  62383. }
  62384. var cache = _getRequireWildcardCache();
  62385. if (cache && cache.has(obj)) {
  62386. return cache.get(obj);
  62387. }
  62388. var newObj = {};
  62389. var hasPropertyDescriptor =
  62390. Object.defineProperty && Object.getOwnPropertyDescriptor;
  62391. for (var key in obj) {
  62392. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  62393. var desc = hasPropertyDescriptor
  62394. ? Object.getOwnPropertyDescriptor(obj, key)
  62395. : null;
  62396. if (desc && (desc.get || desc.set)) {
  62397. Object.defineProperty(newObj, key, desc);
  62398. } else {
  62399. newObj[key] = obj[key];
  62400. }
  62401. }
  62402. }
  62403. newObj.default = obj;
  62404. if (cache) {
  62405. cache.set(obj, newObj);
  62406. }
  62407. return newObj;
  62408. }
  62409. function _interopRequireDefault(obj) {
  62410. return obj && obj.__esModule ? obj : { default: obj };
  62411. }
  62412. function _typeof(obj) {
  62413. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  62414. _typeof = function _typeof(obj) {
  62415. return typeof obj;
  62416. };
  62417. } else {
  62418. _typeof = function _typeof(obj) {
  62419. return obj &&
  62420. typeof Symbol === 'function' &&
  62421. obj.constructor === Symbol &&
  62422. obj !== Symbol.prototype
  62423. ? 'symbol'
  62424. : typeof obj;
  62425. };
  62426. }
  62427. return _typeof(obj);
  62428. }
  62429. var defaultId = 'defaultCanvas0'; // this gets set again in createCanvas
  62430. var defaultClass = 'p5Canvas';
  62431. /**
  62432. * Creates a canvas element in the document, and sets the dimensions of it
  62433. * in pixels. This method should be called only once at the start of setup.
  62434. * Calling <a href="#/p5/createCanvas">createCanvas</a> more than once in a
  62435. * sketch will result in very unpredictable behavior. If you want more than
  62436. * one drawing canvas you could use <a href="#/p5/createGraphics">createGraphics</a>
  62437. * (hidden by default but it can be shown).
  62438. *
  62439. * Important note: in 2D mode (i.e. when `p5.Renderer` is not set) the origin (0,0)
  62440. * is positioned at the top left of the screen. In 3D mode (i.e. when `p5.Renderer`
  62441. * is set to `WEBGL`), the origin is positioned at the center of the canvas.
  62442. * See [this issue](https://github.com/processing/p5.js/issues/1545) for more information.
  62443. *
  62444. * The system variables width and height are set by the parameters passed to this
  62445. * function. If <a href="#/p5/createCanvas">createCanvas()</a> is not used, the
  62446. * window will be given a default size of 100x100 pixels.
  62447. *
  62448. * For more ways to position the canvas, see the
  62449. * <a href='https://github.com/processing/p5.js/wiki/Positioning-your-canvas'>
  62450. * positioning the canvas</a> wiki page.
  62451. *
  62452. * @method createCanvas
  62453. * @param {Number} w width of the canvas
  62454. * @param {Number} h height of the canvas
  62455. * @param {Constant} [renderer] either P2D or WEBGL
  62456. * @return {p5.Renderer}
  62457. * @example
  62458. * <div>
  62459. * <code>
  62460. * function setup() {
  62461. * createCanvas(100, 50);
  62462. * background(153);
  62463. * line(0, 0, width, height);
  62464. * }
  62465. * </code>
  62466. * </div>
  62467. *
  62468. * @alt
  62469. * Black line extending from top-left of canvas to bottom right.
  62470. */
  62471. _main.default.prototype.createCanvas = function(w, h, renderer) {
  62472. _main.default._validateParameters('createCanvas', arguments);
  62473. //optional: renderer, otherwise defaults to p2d
  62474. var r = renderer || constants.P2D;
  62475. var c;
  62476. if (r === constants.WEBGL) {
  62477. c = document.getElementById(defaultId);
  62478. if (c) {
  62479. //if defaultCanvas already exists
  62480. c.parentNode.removeChild(c); //replace the existing defaultCanvas
  62481. var thisRenderer = this._renderer;
  62482. this._elements = this._elements.filter(function(e) {
  62483. return e !== thisRenderer;
  62484. });
  62485. }
  62486. c = document.createElement('canvas');
  62487. c.id = defaultId;
  62488. c.classList.add(defaultClass);
  62489. } else {
  62490. if (!this._defaultGraphicsCreated) {
  62491. c = document.createElement('canvas');
  62492. var i = 0;
  62493. while (document.getElementById('defaultCanvas'.concat(i))) {
  62494. i++;
  62495. }
  62496. defaultId = 'defaultCanvas'.concat(i);
  62497. c.id = defaultId;
  62498. c.classList.add(defaultClass);
  62499. } else {
  62500. // resize the default canvas if new one is created
  62501. c = this.canvas;
  62502. }
  62503. }
  62504. // set to invisible if still in setup (to prevent flashing with manipulate)
  62505. if (!this._setupDone) {
  62506. c.dataset.hidden = true; // tag to show later
  62507. c.style.visibility = 'hidden';
  62508. }
  62509. if (this._userNode) {
  62510. // user input node case
  62511. this._userNode.appendChild(c);
  62512. } else {
  62513. //create main element
  62514. if (document.getElementsByTagName('main').length === 0) {
  62515. var m = document.createElement('main');
  62516. document.body.appendChild(m);
  62517. }
  62518. //append canvas to main
  62519. document.getElementsByTagName('main')[0].appendChild(c);
  62520. }
  62521. // Init our graphics renderer
  62522. //webgl mode
  62523. if (r === constants.WEBGL) {
  62524. this._setProperty('_renderer', new _main.default.RendererGL(c, this, true));
  62525. this._elements.push(this._renderer);
  62526. } else {
  62527. //P2D mode
  62528. if (!this._defaultGraphicsCreated) {
  62529. this._setProperty('_renderer', new _main.default.Renderer2D(c, this, true));
  62530. this._defaultGraphicsCreated = true;
  62531. this._elements.push(this._renderer);
  62532. }
  62533. }
  62534. this._renderer.resize(w, h);
  62535. this._renderer._applyDefaults();
  62536. return this._renderer;
  62537. };
  62538. /**
  62539. * Resizes the canvas to given width and height. The canvas will be cleared
  62540. * and draw will be called immediately, allowing the sketch to re-render itself
  62541. * in the resized canvas.
  62542. * @method resizeCanvas
  62543. * @param {Number} w width of the canvas
  62544. * @param {Number} h height of the canvas
  62545. * @param {Boolean} [noRedraw] don't redraw the canvas immediately
  62546. * @example
  62547. * <div class="norender"><code>
  62548. * function setup() {
  62549. * createCanvas(windowWidth, windowHeight);
  62550. * }
  62551. *
  62552. * function draw() {
  62553. * background(0, 100, 200);
  62554. * }
  62555. *
  62556. * function windowResized() {
  62557. * resizeCanvas(windowWidth, windowHeight);
  62558. * }
  62559. * </code></div>
  62560. *
  62561. * @alt
  62562. * No image displayed.
  62563. */
  62564. _main.default.prototype.resizeCanvas = function(w, h, noRedraw) {
  62565. _main.default._validateParameters('resizeCanvas', arguments);
  62566. if (this._renderer) {
  62567. // save canvas properties
  62568. var props = {};
  62569. for (var key in this.drawingContext) {
  62570. var val = this.drawingContext[key];
  62571. if (_typeof(val) !== 'object' && typeof val !== 'function') {
  62572. props[key] = val;
  62573. }
  62574. }
  62575. this._renderer.resize(w, h);
  62576. this.width = w;
  62577. this.height = h;
  62578. // reset canvas properties
  62579. for (var savedKey in props) {
  62580. try {
  62581. this.drawingContext[savedKey] = props[savedKey];
  62582. } catch (err) {
  62583. // ignore read-only property errors
  62584. }
  62585. }
  62586. if (!noRedraw) {
  62587. this.redraw();
  62588. }
  62589. }
  62590. //accessible Outputs
  62591. if (this._addAccsOutput()) {
  62592. this._updateAccsOutput();
  62593. }
  62594. };
  62595. /**
  62596. * Removes the default canvas for a p5 sketch that doesn't require a canvas
  62597. * @method noCanvas
  62598. * @example
  62599. * <div>
  62600. * <code>
  62601. * function setup() {
  62602. * noCanvas();
  62603. * }
  62604. * </code>
  62605. * </div>
  62606. *
  62607. * @alt
  62608. * no image displayed
  62609. */
  62610. _main.default.prototype.noCanvas = function() {
  62611. if (this.canvas) {
  62612. this.canvas.parentNode.removeChild(this.canvas);
  62613. }
  62614. };
  62615. /**
  62616. * Creates and returns a new p5.Renderer object. Use this class if you need
  62617. * to draw into an off-screen graphics buffer. The two parameters define the
  62618. * width and height in pixels.
  62619. *
  62620. * @method createGraphics
  62621. * @param {Number} w width of the offscreen graphics buffer
  62622. * @param {Number} h height of the offscreen graphics buffer
  62623. * @param {Constant} [renderer] either P2D or WEBGL
  62624. * undefined defaults to p2d
  62625. * @return {p5.Graphics} offscreen graphics buffer
  62626. * @example
  62627. * <div>
  62628. * <code>
  62629. * let pg;
  62630. * function setup() {
  62631. * createCanvas(100, 100);
  62632. * pg = createGraphics(100, 100);
  62633. * }
  62634. *
  62635. * function draw() {
  62636. * background(200);
  62637. * pg.background(100);
  62638. * pg.noStroke();
  62639. * pg.ellipse(pg.width / 2, pg.height / 2, 50, 50);
  62640. * image(pg, 50, 50);
  62641. * image(pg, 0, 0, 50, 50);
  62642. * }
  62643. * </code>
  62644. * </div>
  62645. *
  62646. * @alt
  62647. * 4 grey squares alternating light and dark grey. White quarter circle mid-left.
  62648. */
  62649. _main.default.prototype.createGraphics = function(w, h, renderer) {
  62650. _main.default._validateParameters('createGraphics', arguments);
  62651. return new _main.default.Graphics(w, h, renderer, this);
  62652. };
  62653. /**
  62654. * Blends the pixels in the display window according to the defined mode.
  62655. * There is a choice of the following modes to blend the source pixels (A)
  62656. * with the ones of pixels already in the display window (B):
  62657. * <ul>
  62658. * <li><code>BLEND</code> - linear interpolation of colours: C =
  62659. * A*factor + B. <b>This is the default blending mode.</b></li>
  62660. * <li><code>ADD</code> - sum of A and B</li>
  62661. * <li><code>DARKEST</code> - only the darkest colour succeeds: C =
  62662. * min(A*factor, B).</li>
  62663. * <li><code>LIGHTEST</code> - only the lightest colour succeeds: C =
  62664. * max(A*factor, B).</li>
  62665. * <li><code>DIFFERENCE</code> - subtract colors from underlying image.</li>
  62666. * <li><code>EXCLUSION</code> - similar to <code>DIFFERENCE</code>, but less
  62667. * extreme.</li>
  62668. * <li><code>MULTIPLY</code> - multiply the colors, result will always be
  62669. * darker.</li>
  62670. * <li><code>SCREEN</code> - opposite multiply, uses inverse values of the
  62671. * colors.</li>
  62672. * <li><code>REPLACE</code> - the pixels entirely replace the others and
  62673. * don't utilize alpha (transparency) values.</li>
  62674. * <li><code>REMOVE</code> - removes pixels from B with the alpha strength of A.</li>
  62675. * <li><code>OVERLAY</code> - mix of <code>MULTIPLY</code> and <code>SCREEN
  62676. * </code>. Multiplies dark values, and screens light values. <em>(2D)</em></li>
  62677. * <li><code>HARD_LIGHT</code> - <code>SCREEN</code> when greater than 50%
  62678. * gray, <code>MULTIPLY</code> when lower. <em>(2D)</em></li>
  62679. * <li><code>SOFT_LIGHT</code> - mix of <code>DARKEST</code> and
  62680. * <code>LIGHTEST</code>. Works like <code>OVERLAY</code>, but not as harsh. <em>(2D)</em>
  62681. * </li>
  62682. * <li><code>DODGE</code> - lightens light tones and increases contrast,
  62683. * ignores darks. <em>(2D)</em></li>
  62684. * <li><code>BURN</code> - darker areas are applied, increasing contrast,
  62685. * ignores lights. <em>(2D)</em></li>
  62686. * <li><code>SUBTRACT</code> - remainder of A and B <em>(3D)</em></li>
  62687. * </ul>
  62688. *
  62689. * <em>(2D)</em> indicates that this blend mode <b>only</b> works in the 2D renderer.<br>
  62690. * <em>(3D)</em> indicates that this blend mode <b>only</b> works in the WEBGL renderer.
  62691. *
  62692. * @method blendMode
  62693. * @param {Constant} mode blend mode to set for canvas.
  62694. * either BLEND, DARKEST, LIGHTEST, DIFFERENCE, MULTIPLY,
  62695. * EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,
  62696. * SOFT_LIGHT, DODGE, BURN, ADD, REMOVE or SUBTRACT
  62697. * @example
  62698. * <div>
  62699. * <code>
  62700. * blendMode(LIGHTEST);
  62701. * strokeWeight(30);
  62702. * stroke(80, 150, 255);
  62703. * line(25, 25, 75, 75);
  62704. * stroke(255, 50, 50);
  62705. * line(75, 25, 25, 75);
  62706. * </code>
  62707. * </div>
  62708. *
  62709. * <div>
  62710. * <code>
  62711. * blendMode(MULTIPLY);
  62712. * strokeWeight(30);
  62713. * stroke(80, 150, 255);
  62714. * line(25, 25, 75, 75);
  62715. * stroke(255, 50, 50);
  62716. * line(75, 25, 25, 75);
  62717. * </code>
  62718. * </div>
  62719. *
  62720. * @alt
  62721. * translucent image thick red & blue diagonal rounded lines intersecting center
  62722. * Thick red & blue diagonal rounded lines intersecting center. dark at overlap
  62723. */
  62724. _main.default.prototype.blendMode = function(mode) {
  62725. _main.default._validateParameters('blendMode', arguments);
  62726. if (mode === constants.NORMAL) {
  62727. // Warning added 3/26/19, can be deleted in future (1.0 release?)
  62728. console.warn(
  62729. 'NORMAL has been deprecated for use in blendMode. defaulting to BLEND instead.'
  62730. );
  62731. mode = constants.BLEND;
  62732. }
  62733. this._renderer.blendMode(mode);
  62734. };
  62735. /**
  62736. * The p5.js API provides a lot of functionality for creating graphics, but there is
  62737. * some native HTML5 Canvas functionality that is not exposed by p5. You can still call
  62738. * it directly using the variable `drawingContext`, as in the example shown. This is
  62739. * the equivalent of calling `canvas.getContext('2d');` or `canvas.getContext('webgl');`.
  62740. * See this
  62741. * <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D">
  62742. * reference for the native canvas API</a> for possible drawing functions you can call.
  62743. *
  62744. * @property drawingContext
  62745. * @example
  62746. * <div>
  62747. * <code>
  62748. * function setup() {
  62749. * drawingContext.shadowOffsetX = 5;
  62750. * drawingContext.shadowOffsetY = -5;
  62751. * drawingContext.shadowBlur = 10;
  62752. * drawingContext.shadowColor = 'black';
  62753. * background(200);
  62754. * ellipse(width / 2, height / 2, 50, 50);
  62755. * }
  62756. * </code>
  62757. * </div>
  62758. *
  62759. * @alt
  62760. * white ellipse with shadow blur effect around edges
  62761. */ var _default = _main.default;
  62762. exports.default = _default;
  62763. },
  62764. {
  62765. '../webgl/p5.RendererGL': 337,
  62766. './constants': 272,
  62767. './main': 283,
  62768. './p5.Graphics': 285,
  62769. './p5.Renderer2D': 287,
  62770. 'core-js/modules/es.array.filter': 169,
  62771. 'core-js/modules/es.array.iterator': 174,
  62772. 'core-js/modules/es.object.to-string': 192,
  62773. 'core-js/modules/es.string.iterator': 201,
  62774. 'core-js/modules/es.symbol': 211,
  62775. 'core-js/modules/es.symbol.description': 209,
  62776. 'core-js/modules/es.symbol.iterator': 210,
  62777. 'core-js/modules/web.dom-collections.iterator': 244
  62778. }
  62779. ],
  62780. 290: [
  62781. function(_dereq_, module, exports) {
  62782. 'use strict';
  62783. function _typeof(obj) {
  62784. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  62785. _typeof = function _typeof(obj) {
  62786. return typeof obj;
  62787. };
  62788. } else {
  62789. _typeof = function _typeof(obj) {
  62790. return obj &&
  62791. typeof Symbol === 'function' &&
  62792. obj.constructor === Symbol &&
  62793. obj !== Symbol.prototype
  62794. ? 'symbol'
  62795. : typeof obj;
  62796. };
  62797. }
  62798. return _typeof(obj);
  62799. }
  62800. _dereq_('core-js/modules/es.array.slice');
  62801. Object.defineProperty(exports, '__esModule', { value: true });
  62802. exports.default = void 0;
  62803. var _main = _interopRequireDefault(_dereq_('../main'));
  62804. var constants = _interopRequireWildcard(_dereq_('../constants'));
  62805. var _helpers = _interopRequireDefault(_dereq_('../helpers'));
  62806. _dereq_('../friendly_errors/fes_core');
  62807. _dereq_('../friendly_errors/file_errors');
  62808. _dereq_('../friendly_errors/validate_params');
  62809. function _getRequireWildcardCache() {
  62810. if (typeof WeakMap !== 'function') return null;
  62811. var cache = new WeakMap();
  62812. _getRequireWildcardCache = function _getRequireWildcardCache() {
  62813. return cache;
  62814. };
  62815. return cache;
  62816. }
  62817. function _interopRequireWildcard(obj) {
  62818. if (obj && obj.__esModule) {
  62819. return obj;
  62820. }
  62821. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  62822. return { default: obj };
  62823. }
  62824. var cache = _getRequireWildcardCache();
  62825. if (cache && cache.has(obj)) {
  62826. return cache.get(obj);
  62827. }
  62828. var newObj = {};
  62829. var hasPropertyDescriptor =
  62830. Object.defineProperty && Object.getOwnPropertyDescriptor;
  62831. for (var key in obj) {
  62832. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  62833. var desc = hasPropertyDescriptor
  62834. ? Object.getOwnPropertyDescriptor(obj, key)
  62835. : null;
  62836. if (desc && (desc.get || desc.set)) {
  62837. Object.defineProperty(newObj, key, desc);
  62838. } else {
  62839. newObj[key] = obj[key];
  62840. }
  62841. }
  62842. }
  62843. newObj.default = obj;
  62844. if (cache) {
  62845. cache.set(obj, newObj);
  62846. }
  62847. return newObj;
  62848. }
  62849. function _interopRequireDefault(obj) {
  62850. return obj && obj.__esModule ? obj : { default: obj };
  62851. }
  62852. /**
  62853. * @module Shape
  62854. * @submodule 2D Primitives
  62855. * @for p5
  62856. * @requires core
  62857. * @requires constants
  62858. */ /**
  62859. * This function does 3 things:
  62860. *
  62861. * 1. Bounds the desired start/stop angles for an arc (in radians) so that:
  62862. *
  62863. * 0 <= start < TWO_PI ; start <= stop < start + TWO_PI
  62864. *
  62865. * This means that the arc rendering functions don't have to be concerned
  62866. * with what happens if stop is smaller than start, or if the arc 'goes
  62867. * round more than once', etc.: they can just start at start and increase
  62868. * until stop and the correct arc will be drawn.
  62869. *
  62870. * 2. Optionally adjusts the angles within each quadrant to counter the naive
  62871. * scaling of the underlying ellipse up from the unit circle. Without
  62872. * this, the angles become arbitrary when width != height: 45 degrees
  62873. * might be drawn at 5 degrees on a 'wide' ellipse, or at 85 degrees on
  62874. * a 'tall' ellipse.
  62875. *
  62876. * 3. Flags up when start and stop correspond to the same place on the
  62877. * underlying ellipse. This is useful if you want to do something special
  62878. * there (like rendering a whole ellipse instead).
  62879. */ _main.default.prototype._normalizeArcAngles = function(
  62880. start,
  62881. stop,
  62882. width,
  62883. height,
  62884. correctForScaling
  62885. ) {
  62886. var epsilon = 0.00001; // Smallest visible angle on displays up to 4K.
  62887. var separation;
  62888. // The order of the steps is important here: each one builds upon the
  62889. // adjustments made in the steps that precede it.
  62890. // Constrain both start and stop to [0,TWO_PI).
  62891. start = start - constants.TWO_PI * Math.floor(start / constants.TWO_PI);
  62892. stop = stop - constants.TWO_PI * Math.floor(stop / constants.TWO_PI);
  62893. // Get the angular separation between the requested start and stop points.
  62894. //
  62895. // Technically this separation only matches what gets drawn if
  62896. // correctForScaling is enabled. We could add a more complicated calculation
  62897. // for when the scaling is uncorrected (in which case the drawn points could
  62898. // end up pushed together or pulled apart quite dramatically relative to what
  62899. // was requested), but it would make things more opaque for little practical
  62900. // benefit.
  62901. //
  62902. // (If you do disable correctForScaling and find that correspondToSamePoint
  62903. // is set too aggressively, the easiest thing to do is probably to just make
  62904. // epsilon smaller...)
  62905. separation = Math.min(
  62906. Math.abs(start - stop),
  62907. constants.TWO_PI - Math.abs(start - stop)
  62908. );
  62909. // Optionally adjust the angles to counter linear scaling.
  62910. if (correctForScaling) {
  62911. if (start <= constants.HALF_PI) {
  62912. start = Math.atan(width / height * Math.tan(start));
  62913. } else if (start > constants.HALF_PI && start <= 3 * constants.HALF_PI) {
  62914. start = Math.atan(width / height * Math.tan(start)) + constants.PI;
  62915. } else {
  62916. start = Math.atan(width / height * Math.tan(start)) + constants.TWO_PI;
  62917. }
  62918. if (stop <= constants.HALF_PI) {
  62919. stop = Math.atan(width / height * Math.tan(stop));
  62920. } else if (stop > constants.HALF_PI && stop <= 3 * constants.HALF_PI) {
  62921. stop = Math.atan(width / height * Math.tan(stop)) + constants.PI;
  62922. } else {
  62923. stop = Math.atan(width / height * Math.tan(stop)) + constants.TWO_PI;
  62924. }
  62925. }
  62926. // Ensure that start <= stop < start + TWO_PI.
  62927. if (start > stop) {
  62928. stop += constants.TWO_PI;
  62929. }
  62930. return {
  62931. start: start,
  62932. stop: stop,
  62933. correspondToSamePoint: separation < epsilon
  62934. };
  62935. };
  62936. /**
  62937. * Draw an arc to the screen. If called with only x, y, w, h, start and stop,
  62938. * the arc will be drawn and filled as an open pie segment. If a mode parameter
  62939. * is provided, the arc will be filled like an open semi-circle (OPEN), a closed
  62940. * semi-circle (CHORD), or as a closed pie segment (PIE). The origin may be changed
  62941. * with the <a href="#/p5/ellipseMode">ellipseMode()</a> function.
  62942. *
  62943. * The arc is always drawn clockwise from wherever start falls to wherever stop
  62944. * falls on the ellipse. Adding or subtracting TWO_PI to either angle does not
  62945. * change where they fall. If both start and stop fall at the same place, a full
  62946. * ellipse will be drawn. Be aware that the y-axis increases in the downward
  62947. * direction, therefore angles are measured clockwise from the positive
  62948. * x-direction ("3 o'clock").
  62949. *
  62950. * @method arc
  62951. * @param {Number} x x-coordinate of the arc's ellipse
  62952. * @param {Number} y y-coordinate of the arc's ellipse
  62953. * @param {Number} w width of the arc's ellipse by default
  62954. * @param {Number} h height of the arc's ellipse by default
  62955. * @param {Number} start angle to start the arc, specified in radians
  62956. * @param {Number} stop angle to stop the arc, specified in radians
  62957. * @param {Constant} [mode] optional parameter to determine the way of drawing
  62958. * the arc. either CHORD, PIE or OPEN
  62959. * @param {Integer} [detail] optional parameter for WebGL mode only. This is to
  62960. * specify the number of vertices that makes up the
  62961. * perimeter of the arc. Default value is 25. Won't
  62962. * draw a stroke for a detail of more than 50.
  62963. * @chainable
  62964. *
  62965. * @example
  62966. * <div>
  62967. * <code>
  62968. * arc(50, 55, 50, 50, 0, HALF_PI);
  62969. * noFill();
  62970. * arc(50, 55, 60, 60, HALF_PI, PI);
  62971. * arc(50, 55, 70, 70, PI, PI + QUARTER_PI);
  62972. * arc(50, 55, 80, 80, PI + QUARTER_PI, TWO_PI);
  62973. * </code>
  62974. * </div>
  62975. *
  62976. * <div>
  62977. * <code>
  62978. * arc(50, 50, 80, 80, 0, PI + QUARTER_PI);
  62979. * </code>
  62980. * </div>
  62981. *
  62982. * <div>
  62983. * <code>
  62984. * arc(50, 50, 80, 80, 0, PI + QUARTER_PI, OPEN);
  62985. * </code>
  62986. * </div>
  62987. *
  62988. * <div>
  62989. * <code>
  62990. * arc(50, 50, 80, 80, 0, PI + QUARTER_PI, CHORD);
  62991. * </code>
  62992. * </div>
  62993. *
  62994. * <div>
  62995. * <code>
  62996. * arc(50, 50, 80, 80, 0, PI + QUARTER_PI, PIE);
  62997. * </code>
  62998. * </div>
  62999. *
  63000. * @alt
  63001. *shattered outline of an ellipse with a quarter of a white circle bottom-right.
  63002. *white ellipse with top right quarter missing.
  63003. *white ellipse with black outline with top right missing.
  63004. *white ellipse with top right missing with black outline around shape.
  63005. *white ellipse with top right quarter missing with black outline around the shape.
  63006. */
  63007. _main.default.prototype.arc = function(x, y, w, h, start, stop, mode, detail) {
  63008. _main.default._validateParameters('arc', arguments);
  63009. // if the current stroke and fill settings wouldn't result in something
  63010. // visible, exit immediately
  63011. if (!this._renderer._doStroke && !this._renderer._doFill) {
  63012. return this;
  63013. }
  63014. if (start === stop) {
  63015. return this;
  63016. }
  63017. start = this._toRadians(start);
  63018. stop = this._toRadians(stop);
  63019. // p5 supports negative width and heights for ellipses
  63020. w = Math.abs(w);
  63021. h = Math.abs(h);
  63022. var vals = _helpers.default.modeAdjust(x, y, w, h, this._renderer._ellipseMode);
  63023. var angles = this._normalizeArcAngles(start, stop, vals.w, vals.h, true);
  63024. if (angles.correspondToSamePoint) {
  63025. // If the arc starts and ends at (near enough) the same place, we choose to
  63026. // draw an ellipse instead. This is preferable to faking an ellipse (by
  63027. // making stop ever-so-slightly less than start + TWO_PI) because the ends
  63028. // join up to each other rather than at a vertex at the centre (leaving
  63029. // an unwanted spike in the stroke/fill).
  63030. this._renderer.ellipse([vals.x, vals.y, vals.w, vals.h, detail]);
  63031. } else {
  63032. this._renderer.arc(
  63033. vals.x,
  63034. vals.y,
  63035. vals.w,
  63036. vals.h,
  63037. angles.start, // [0, TWO_PI)
  63038. angles.stop, // [start, start + TWO_PI)
  63039. mode,
  63040. detail
  63041. );
  63042. //accessible Outputs
  63043. if (this._accessibleOutputs.grid || this._accessibleOutputs.text) {
  63044. this._accsOutput('arc', [
  63045. vals.x,
  63046. vals.y,
  63047. vals.w,
  63048. vals.h,
  63049. angles.start,
  63050. angles.stop,
  63051. mode
  63052. ]);
  63053. }
  63054. }
  63055. return this;
  63056. };
  63057. /**
  63058. * Draws an ellipse (oval) to the screen. By default, the first two parameters
  63059. * set the location of the center of the ellipse, and the third and fourth
  63060. * parameters set the shape's width and height. If no height is specified, the
  63061. * value of width is used for both the width and height. If a negative height or
  63062. * width is specified, the absolute value is taken.
  63063. *
  63064. * An ellipse with equal width and height is a circle. The origin may be changed
  63065. * with the <a href="#/p5/ellipseMode">ellipseMode()</a> function.
  63066. *
  63067. * @method ellipse
  63068. * @param {Number} x x-coordinate of the center of ellipse.
  63069. * @param {Number} y y-coordinate of the center of ellipse.
  63070. * @param {Number} w width of the ellipse.
  63071. * @param {Number} [h] height of the ellipse.
  63072. * @chainable
  63073. * @example
  63074. * <div>
  63075. * <code>
  63076. * ellipse(56, 46, 55, 55);
  63077. * </code>
  63078. * </div>
  63079. *
  63080. * @alt
  63081. *white ellipse with black outline in middle-right of canvas that is 55x55
  63082. */
  63083. /**
  63084. * @method ellipse
  63085. * @param {Number} x
  63086. * @param {Number} y
  63087. * @param {Number} w
  63088. * @param {Number} h
  63089. * @param {Integer} [detail] optional parameter for WebGL mode only. This is to
  63090. * specify the number of vertices that makes up the
  63091. * perimeter of the ellipse. Default value is 25. Won't
  63092. * draw a stroke for a detail of more than 50.
  63093. */
  63094. _main.default.prototype.ellipse = function(x, y, w, h, detailX) {
  63095. _main.default._validateParameters('ellipse', arguments);
  63096. return this._renderEllipse.apply(this, arguments);
  63097. };
  63098. /**
  63099. * Draws a circle to the screen. A circle is a simple closed shape. It is the set
  63100. * of all points in a plane that are at a given distance from a given point,
  63101. * the centre. This function is a special case of the ellipse() function, where
  63102. * the width and height of the ellipse are the same. Height and width of the
  63103. * ellipse correspond to the diameter of the circle. By default, the first two
  63104. * parameters set the location of the centre of the circle, the third sets the
  63105. * diameter of the circle.
  63106. *
  63107. * @method circle
  63108. * @param {Number} x x-coordinate of the centre of the circle.
  63109. * @param {Number} y y-coordinate of the centre of the circle.
  63110. * @param {Number} d diameter of the circle.
  63111. * @chainable
  63112. * @example
  63113. * <div>
  63114. * <code>
  63115. * // Draw a circle at location (30, 30) with a diameter of 20.
  63116. * circle(30, 30, 20);
  63117. * </code>
  63118. * </div>
  63119. *
  63120. * @alt
  63121. * white circle with black outline in mid of canvas that is 55x55.
  63122. */
  63123. _main.default.prototype.circle = function() {
  63124. _main.default._validateParameters('circle', arguments);
  63125. var args = Array.prototype.slice.call(arguments, 0, 2);
  63126. args.push(arguments[2]);
  63127. args.push(arguments[2]);
  63128. return this._renderEllipse.apply(this, args);
  63129. };
  63130. // internal method for drawing ellipses (without parameter validation)
  63131. _main.default.prototype._renderEllipse = function(x, y, w, h, detailX) {
  63132. // if the current stroke and fill settings wouldn't result in something
  63133. // visible, exit immediately
  63134. if (!this._renderer._doStroke && !this._renderer._doFill) {
  63135. return this;
  63136. }
  63137. // p5 supports negative width and heights for rects
  63138. if (w < 0) {
  63139. w = Math.abs(w);
  63140. }
  63141. if (typeof h === 'undefined') {
  63142. // Duplicate 3rd argument if only 3 given.
  63143. h = w;
  63144. } else if (h < 0) {
  63145. h = Math.abs(h);
  63146. }
  63147. var vals = _helpers.default.modeAdjust(x, y, w, h, this._renderer._ellipseMode);
  63148. this._renderer.ellipse([vals.x, vals.y, vals.w, vals.h, detailX]);
  63149. //accessible Outputs
  63150. if (this._accessibleOutputs.grid || this._accessibleOutputs.text) {
  63151. this._accsOutput('ellipse', [vals.x, vals.y, vals.w, vals.h]);
  63152. }
  63153. return this;
  63154. };
  63155. /**
  63156. * Draws a line (a direct path between two points) to the screen. If called with
  63157. * only 4 parameters, it will draw a line in 2D with a default width of 1 pixel.
  63158. * This width can be modified by using the <a href="#/p5/strokeWeight">
  63159. * strokeWeight()</a> function. A line cannot be filled, therefore the <a
  63160. * href="#/p5/fill">fill()</a> function will not affect the color of a line. So to
  63161. * color a line, use the <a href="#/p5/stroke">stroke()</a> function.
  63162. *
  63163. * @method line
  63164. * @param {Number} x1 the x-coordinate of the first point
  63165. * @param {Number} y1 the y-coordinate of the first point
  63166. * @param {Number} x2 the x-coordinate of the second point
  63167. * @param {Number} y2 the y-coordinate of the second point
  63168. * @chainable
  63169. * @example
  63170. * <div>
  63171. * <code>
  63172. * line(30, 20, 85, 75);
  63173. * </code>
  63174. * </div>
  63175. *
  63176. * <div>
  63177. * <code>
  63178. * line(30, 20, 85, 20);
  63179. * stroke(126);
  63180. * line(85, 20, 85, 75);
  63181. * stroke(255);
  63182. * line(85, 75, 30, 75);
  63183. * </code>
  63184. * </div>
  63185. *
  63186. * @alt
  63187. * An example showing a line 78 pixels long running from mid-top to bottom-right of canvas.
  63188. * An example showing 3 lines of various stroke sizes. Form top, bottom and right sides of a square.
  63189. */
  63190. /**
  63191. * @method line
  63192. * @param {Number} x1
  63193. * @param {Number} y1
  63194. * @param {Number} z1 the z-coordinate of the first point
  63195. * @param {Number} x2
  63196. * @param {Number} y2
  63197. * @param {Number} z2 the z-coordinate of the second point
  63198. * @chainable
  63199. */
  63200. _main.default.prototype.line = function() {
  63201. for (
  63202. var _len = arguments.length, args = new Array(_len), _key = 0;
  63203. _key < _len;
  63204. _key++
  63205. ) {
  63206. args[_key] = arguments[_key];
  63207. }
  63208. _main.default._validateParameters('line', args);
  63209. if (this._renderer._doStroke) {
  63210. var _this$_renderer;
  63211. (_this$_renderer = this._renderer).line.apply(_this$_renderer, args);
  63212. }
  63213. //accessible Outputs
  63214. if (this._accessibleOutputs.grid || this._accessibleOutputs.text) {
  63215. this._accsOutput('line', args);
  63216. }
  63217. return this;
  63218. };
  63219. /**
  63220. * Draws a point, a coordinate in space at the dimension of one pixel.
  63221. * The first parameter is the horizontal value for the point, the second
  63222. * param is the vertical value for the point. The color of the point is
  63223. * changed with the <a href="#/p5/stroke">stroke()</a> function. The size of the point
  63224. * can be changed with the <a href="#/p5/strokeWeight">strokeWeight()</a> function.
  63225. *
  63226. * @method point
  63227. * @param {Number} x the x-coordinate
  63228. * @param {Number} y the y-coordinate
  63229. * @param {Number} [z] the z-coordinate (for WebGL mode)
  63230. * @chainable
  63231. * @example
  63232. * <div>
  63233. * <code>
  63234. * point(30, 20);
  63235. * point(85, 20);
  63236. * point(85, 75);
  63237. * point(30, 75);
  63238. * </code>
  63239. * </div>
  63240. *
  63241. * <div>
  63242. * <code>
  63243. * point(30, 20);
  63244. * point(85, 20);
  63245. * stroke('purple'); // Change the color
  63246. * strokeWeight(10); // Make the points 10 pixels in size
  63247. * point(85, 75);
  63248. * point(30, 75);
  63249. * </code>
  63250. * </div>
  63251. *
  63252. * <div>
  63253. * <code>
  63254. * let a = createVector(10, 10);
  63255. * point(a);
  63256. * let b = createVector(10, 20);
  63257. * point(b);
  63258. * point(createVector(20, 10));
  63259. * point(createVector(20, 20));
  63260. * </code>
  63261. * </div>
  63262. *
  63263. * @alt
  63264. * 4 points centered in the middle-right of the canvas.
  63265. * 2 large points and 2 large purple points centered in the middle-right of the canvas.
  63266. * Vertices of a square of length 10 pixels towards the top-left of the canvas.
  63267. */
  63268. /**
  63269. * @method point
  63270. * @param {p5.Vector} coordinate_vector the coordinate vector
  63271. * @chainable
  63272. */
  63273. _main.default.prototype.point = function() {
  63274. for (
  63275. var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
  63276. _key2 < _len2;
  63277. _key2++
  63278. ) {
  63279. args[_key2] = arguments[_key2];
  63280. }
  63281. _main.default._validateParameters('point', args);
  63282. if (this._renderer._doStroke) {
  63283. if (args.length === 1 && args[0] instanceof _main.default.Vector) {
  63284. this._renderer.point.call(this._renderer, args[0].x, args[0].y, args[0].z);
  63285. } else {
  63286. var _this$_renderer2;
  63287. (_this$_renderer2 = this._renderer).point.apply(_this$_renderer2, args);
  63288. //accessible Outputs
  63289. if (this._accessibleOutputs.grid || this._accessibleOutputs.text) {
  63290. this._accsOutput('point', args);
  63291. }
  63292. }
  63293. }
  63294. return this;
  63295. };
  63296. /**
  63297. * Draws a quad on the canvas. A quad is a quadrilateral, a four sided polygon. It is
  63298. * similar to a rectangle, but the angles between its edges are not
  63299. * constrained to ninety degrees. The first pair of parameters (x1,y1)
  63300. * sets the first vertex and the subsequent pairs should proceed
  63301. * clockwise or counter-clockwise around the defined shape.
  63302. * z-arguments only work when quad() is used in WEBGL mode.
  63303. *
  63304. * @method quad
  63305. * @param {Number} x1 the x-coordinate of the first point
  63306. * @param {Number} y1 the y-coordinate of the first point
  63307. * @param {Number} x2 the x-coordinate of the second point
  63308. * @param {Number} y2 the y-coordinate of the second point
  63309. * @param {Number} x3 the x-coordinate of the third point
  63310. * @param {Number} y3 the y-coordinate of the third point
  63311. * @param {Number} x4 the x-coordinate of the fourth point
  63312. * @param {Number} y4 the y-coordinate of the fourth point
  63313. * @param {Integer} [detailX] number of segments in the x-direction
  63314. * @param {Integer} [detailY] number of segments in the y-direction
  63315. * @chainable
  63316. * @example
  63317. * <div>
  63318. * <code>
  63319. * quad(38, 31, 86, 20, 69, 63, 30, 76);
  63320. * </code>
  63321. * </div>
  63322. *
  63323. * @alt
  63324. *irregular white quadrilateral shape with black outline mid-right of canvas.
  63325. */
  63326. /**
  63327. * @method quad
  63328. * @param {Number} x1
  63329. * @param {Number} y1
  63330. * @param {Number} z1 the z-coordinate of the first point
  63331. * @param {Number} x2
  63332. * @param {Number} y2
  63333. * @param {Number} z2 the z-coordinate of the second point
  63334. * @param {Number} x3
  63335. * @param {Number} y3
  63336. * @param {Number} z3 the z-coordinate of the third point
  63337. * @param {Number} x4
  63338. * @param {Number} y4
  63339. * @param {Number} z4 the z-coordinate of the fourth point
  63340. * @param {Integer} [detailX]
  63341. * @param {Integer} [detailY]
  63342. * @chainable
  63343. */
  63344. _main.default.prototype.quad = function() {
  63345. for (
  63346. var _len3 = arguments.length, args = new Array(_len3), _key3 = 0;
  63347. _key3 < _len3;
  63348. _key3++
  63349. ) {
  63350. args[_key3] = arguments[_key3];
  63351. }
  63352. _main.default._validateParameters('quad', args);
  63353. if (this._renderer._doStroke || this._renderer._doFill) {
  63354. if (this._renderer.isP3D && args.length <= 12) {
  63355. // if 3D and we weren't passed 12 args, assume Z is 0
  63356. // prettier-ignore
  63357. this._renderer.quad.call(
  63358. this._renderer,
  63359. args[0], args[1], 0,
  63360. args[2], args[3], 0,
  63361. args[4], args[5], 0,
  63362. args[6], args[7], 0,
  63363. args[8], args[9]);
  63364. } else {
  63365. var _this$_renderer3;
  63366. (_this$_renderer3 = this._renderer).quad.apply(_this$_renderer3, args);
  63367. //accessibile outputs
  63368. if (this._accessibleOutputs.grid || this._accessibleOutputs.text) {
  63369. this._accsOutput('quadrilateral', args);
  63370. }
  63371. }
  63372. }
  63373. return this;
  63374. };
  63375. /**
  63376. * Draws a rectangle on the canvas. A rectangle is a four-sided closed shape with
  63377. * every angle at ninety degrees. By default, the first two parameters set
  63378. * the location of the upper-left corner, the third sets the width, and the
  63379. * fourth sets the height. The way these parameters are interpreted, may be
  63380. * changed with the <a href="#/p5/rectMode">rectMode()</a> function.
  63381. *
  63382. * The fifth, sixth, seventh and eighth parameters, if specified,
  63383. * determine corner radius for the top-left, top-right, lower-right and
  63384. * lower-left corners, respectively. An omitted corner radius parameter is set
  63385. * to the value of the previously specified radius value in the parameter list.
  63386. *
  63387. * @method rect
  63388. * @param {Number} x x-coordinate of the rectangle.
  63389. * @param {Number} y y-coordinate of the rectangle.
  63390. * @param {Number} w width of the rectangle.
  63391. * @param {Number} [h] height of the rectangle.
  63392. * @param {Number} [tl] optional radius of top-left corner.
  63393. * @param {Number} [tr] optional radius of top-right corner.
  63394. * @param {Number} [br] optional radius of bottom-right corner.
  63395. * @param {Number} [bl] optional radius of bottom-left corner.
  63396. * @chainable
  63397. * @example
  63398. * <div>
  63399. * <code>
  63400. * // Draw a rectangle at location (30, 20) with a width and height of 55.
  63401. * rect(30, 20, 55, 55);
  63402. * </code>
  63403. * </div>
  63404. *
  63405. * <div>
  63406. * <code>
  63407. * // Draw a rectangle with rounded corners, each having a radius of 20.
  63408. * rect(30, 20, 55, 55, 20);
  63409. * </code>
  63410. * </div>
  63411. *
  63412. * <div>
  63413. * <code>
  63414. * // Draw a rectangle with rounded corners having the following radii:
  63415. * // top-left = 20, top-right = 15, bottom-right = 10, bottom-left = 5.
  63416. * rect(30, 20, 55, 55, 20, 15, 10, 5);
  63417. * </code>
  63418. * </div>
  63419. *
  63420. * @alt
  63421. * 55x55 white rect with black outline in mid-right of canvas.
  63422. * 55x55 white rect with black outline and rounded edges in mid-right of canvas.
  63423. * 55x55 white rect with black outline and rounded edges of different radii.
  63424. */
  63425. /**
  63426. * @method rect
  63427. * @param {Number} x
  63428. * @param {Number} y
  63429. * @param {Number} w
  63430. * @param {Number} h
  63431. * @param {Integer} [detailX] number of segments in the x-direction (for WebGL mode)
  63432. * @param {Integer} [detailY] number of segments in the y-direction (for WebGL mode)
  63433. * @chainable
  63434. */
  63435. _main.default.prototype.rect = function() {
  63436. _main.default._validateParameters('rect', arguments);
  63437. return this._renderRect.apply(this, arguments);
  63438. };
  63439. /**
  63440. * Draws a square to the screen. A square is a four-sided shape with every angle
  63441. * at ninety degrees, and equal side size. This function is a special case of the
  63442. * rect() function, where the width and height are the same, and the parameter
  63443. * is called "s" for side size. By default, the first two parameters set the
  63444. * location of the upper-left corner, the third sets the side size of the square.
  63445. * The way these parameters are interpreted, may be changed with the <a
  63446. * href="#/p5/rectMode">rectMode()</a> function.
  63447. *
  63448. * The fourth, fifth, sixth and seventh parameters, if specified,
  63449. * determine corner radius for the top-left, top-right, lower-right and
  63450. * lower-left corners, respectively. An omitted corner radius parameter is set
  63451. * to the value of the previously specified radius value in the parameter list.
  63452. *
  63453. * @method square
  63454. * @param {Number} x x-coordinate of the square.
  63455. * @param {Number} y y-coordinate of the square.
  63456. * @param {Number} s side size of the square.
  63457. * @param {Number} [tl] optional radius of top-left corner.
  63458. * @param {Number} [tr] optional radius of top-right corner.
  63459. * @param {Number} [br] optional radius of bottom-right corner.
  63460. * @param {Number} [bl] optional radius of bottom-left corner.
  63461. * @chainable
  63462. * @example
  63463. * <div>
  63464. * <code>
  63465. * // Draw a square at location (30, 20) with a side size of 55.
  63466. * square(30, 20, 55);
  63467. * </code>
  63468. * </div>
  63469. *
  63470. * <div>
  63471. * <code>
  63472. * // Draw a square with rounded corners, each having a radius of 20.
  63473. * square(30, 20, 55, 20);
  63474. * </code>
  63475. * </div>
  63476. *
  63477. * <div>
  63478. * <code>
  63479. * // Draw a square with rounded corners having the following radii:
  63480. * // top-left = 20, top-right = 15, bottom-right = 10, bottom-left = 5.
  63481. * square(30, 20, 55, 20, 15, 10, 5);
  63482. * </code>
  63483. * </div>
  63484. *
  63485. * @alt
  63486. * 55x55 white square with black outline in mid-right of canvas.
  63487. * 55x55 white square with black outline and rounded edges in mid-right of canvas.
  63488. * 55x55 white square with black outline and rounded edges of different radii.
  63489. */
  63490. _main.default.prototype.square = function(x, y, s, tl, tr, br, bl) {
  63491. _main.default._validateParameters('square', arguments);
  63492. // duplicate width for height in case of square
  63493. return this._renderRect.call(this, x, y, s, s, tl, tr, br, bl);
  63494. };
  63495. // internal method to have renderer draw a rectangle
  63496. _main.default.prototype._renderRect = function() {
  63497. if (this._renderer._doStroke || this._renderer._doFill) {
  63498. // duplicate width for height in case only 3 arguments is provided
  63499. if (arguments.length === 3) {
  63500. arguments[3] = arguments[2];
  63501. }
  63502. var vals = _helpers.default.modeAdjust(
  63503. arguments[0],
  63504. arguments[1],
  63505. arguments[2],
  63506. arguments[3],
  63507. this._renderer._rectMode
  63508. );
  63509. var args = [vals.x, vals.y, vals.w, vals.h];
  63510. // append the additional arguments (either cornder radii, or
  63511. // segment details) to the argument list
  63512. for (var i = 4; i < arguments.length; i++) {
  63513. args[i] = arguments[i];
  63514. }
  63515. this._renderer.rect(args);
  63516. //accessible outputs
  63517. if (this._accessibleOutputs.grid || this._accessibleOutputs.text) {
  63518. this._accsOutput('rectangle', [vals.x, vals.y, vals.w, vals.h]);
  63519. }
  63520. }
  63521. return this;
  63522. };
  63523. /**
  63524. * Draws a triangle to the canvas. A triangle is a plane created by connecting
  63525. * three points. The first two arguments specify the first point, the middle two
  63526. * arguments specify the second point, and the last two arguments specify the
  63527. * third point.
  63528. *
  63529. * @method triangle
  63530. * @param {Number} x1 x-coordinate of the first point
  63531. * @param {Number} y1 y-coordinate of the first point
  63532. * @param {Number} x2 x-coordinate of the second point
  63533. * @param {Number} y2 y-coordinate of the second point
  63534. * @param {Number} x3 x-coordinate of the third point
  63535. * @param {Number} y3 y-coordinate of the third point
  63536. * @chainable
  63537. * @example
  63538. * <div>
  63539. * <code>
  63540. * triangle(30, 75, 58, 20, 86, 75);
  63541. * </code>
  63542. * </div>
  63543. *
  63544. *@alt
  63545. * white triangle with black outline in mid-right of canvas.
  63546. */
  63547. _main.default.prototype.triangle = function() {
  63548. for (
  63549. var _len4 = arguments.length, args = new Array(_len4), _key4 = 0;
  63550. _key4 < _len4;
  63551. _key4++
  63552. ) {
  63553. args[_key4] = arguments[_key4];
  63554. }
  63555. _main.default._validateParameters('triangle', args);
  63556. if (this._renderer._doStroke || this._renderer._doFill) {
  63557. this._renderer.triangle(args);
  63558. }
  63559. //accessible outputs
  63560. if (this._accessibleOutputs.grid || this._accessibleOutputs.text) {
  63561. this._accsOutput('triangle', args);
  63562. }
  63563. return this;
  63564. };
  63565. var _default = _main.default;
  63566. exports.default = _default;
  63567. },
  63568. {
  63569. '../constants': 272,
  63570. '../friendly_errors/fes_core': 275,
  63571. '../friendly_errors/file_errors': 276,
  63572. '../friendly_errors/validate_params': 278,
  63573. '../helpers': 279,
  63574. '../main': 283,
  63575. 'core-js/modules/es.array.slice': 178
  63576. }
  63577. ],
  63578. 291: [
  63579. function(_dereq_, module, exports) {
  63580. 'use strict';
  63581. function _typeof(obj) {
  63582. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  63583. _typeof = function _typeof(obj) {
  63584. return typeof obj;
  63585. };
  63586. } else {
  63587. _typeof = function _typeof(obj) {
  63588. return obj &&
  63589. typeof Symbol === 'function' &&
  63590. obj.constructor === Symbol &&
  63591. obj !== Symbol.prototype
  63592. ? 'symbol'
  63593. : typeof obj;
  63594. };
  63595. }
  63596. return _typeof(obj);
  63597. }
  63598. Object.defineProperty(exports, '__esModule', { value: true });
  63599. exports.default = void 0;
  63600. var _main = _interopRequireDefault(_dereq_('../main'));
  63601. var constants = _interopRequireWildcard(_dereq_('../constants'));
  63602. function _getRequireWildcardCache() {
  63603. if (typeof WeakMap !== 'function') return null;
  63604. var cache = new WeakMap();
  63605. _getRequireWildcardCache = function _getRequireWildcardCache() {
  63606. return cache;
  63607. };
  63608. return cache;
  63609. }
  63610. function _interopRequireWildcard(obj) {
  63611. if (obj && obj.__esModule) {
  63612. return obj;
  63613. }
  63614. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  63615. return { default: obj };
  63616. }
  63617. var cache = _getRequireWildcardCache();
  63618. if (cache && cache.has(obj)) {
  63619. return cache.get(obj);
  63620. }
  63621. var newObj = {};
  63622. var hasPropertyDescriptor =
  63623. Object.defineProperty && Object.getOwnPropertyDescriptor;
  63624. for (var key in obj) {
  63625. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  63626. var desc = hasPropertyDescriptor
  63627. ? Object.getOwnPropertyDescriptor(obj, key)
  63628. : null;
  63629. if (desc && (desc.get || desc.set)) {
  63630. Object.defineProperty(newObj, key, desc);
  63631. } else {
  63632. newObj[key] = obj[key];
  63633. }
  63634. }
  63635. }
  63636. newObj.default = obj;
  63637. if (cache) {
  63638. cache.set(obj, newObj);
  63639. }
  63640. return newObj;
  63641. }
  63642. function _interopRequireDefault(obj) {
  63643. return obj && obj.__esModule ? obj : { default: obj };
  63644. }
  63645. /**
  63646. * @module Shape
  63647. * @submodule Attributes
  63648. * @for p5
  63649. * @requires core
  63650. * @requires constants
  63651. */ /**
  63652. * Modifies the location from which ellipses are drawn by changing the way in
  63653. * which parameters given to <a href="#/p5/ellipse">ellipse()</a>,
  63654. * <a href="#/p5/circle">circle()</a> and <a href="#/p5/arc">arc()</a> are interpreted.
  63655. *
  63656. * The default mode is CENTER, in which the first two parameters are interpreted
  63657. * as the shape's center point's x and y coordinates respectively, while the third
  63658. * and fourth parameters are its width and height.
  63659. *
  63660. * ellipseMode(RADIUS) also uses the first two parameters as the shape's center
  63661. * point's x and y coordinates, but uses the third and fourth parameters to
  63662. * specify half of the shapes's width and height.
  63663. *
  63664. * ellipseMode(CORNER) interprets the first two parameters as the upper-left
  63665. * corner of the shape, while the third and fourth parameters are its width
  63666. * and height.
  63667. *
  63668. * ellipseMode(CORNERS) interprets the first two parameters as the location of
  63669. * one corner of the ellipse's bounding box, and the third and fourth parameters
  63670. * as the location of the opposite corner.
  63671. *
  63672. * The parameter to this method must be written in ALL CAPS because they are
  63673. * predefined as constants in ALL CAPS and Javascript is a case-sensitive language.
  63674. *
  63675. * @method ellipseMode
  63676. * @param {Constant} mode either CENTER, RADIUS, CORNER, or CORNERS
  63677. * @chainable
  63678. * @example
  63679. * <div>
  63680. * <code>
  63681. * // Example showing RADIUS and CENTER ellipsemode with 2 overlaying ellipses
  63682. * ellipseMode(RADIUS);
  63683. * fill(255);
  63684. * ellipse(50, 50, 30, 30); // Outer white ellipse
  63685. * ellipseMode(CENTER);
  63686. * fill(100);
  63687. * ellipse(50, 50, 30, 30); // Inner gray ellipse
  63688. * </code>
  63689. * </div>
  63690. *
  63691. * <div>
  63692. * <code>
  63693. * // Example showing CORNER and CORNERS ellipseMode with 2 overlaying ellipses
  63694. * ellipseMode(CORNER);
  63695. * fill(255);
  63696. * ellipse(25, 25, 50, 50); // Outer white ellipse
  63697. * ellipseMode(CORNERS);
  63698. * fill(100);
  63699. * ellipse(25, 25, 50, 50); // Inner gray ellipse
  63700. * </code>
  63701. * </div>
  63702. *
  63703. * @alt
  63704. * 60x60 white ellipse and 30x30 grey ellipse with black outlines at center.
  63705. * 60x60 white ellipse and 30x30 grey ellipse top-right with black outlines.
  63706. */ _main.default.prototype.ellipseMode = function(m) {
  63707. _main.default._validateParameters('ellipseMode', arguments);
  63708. if (
  63709. m === constants.CORNER ||
  63710. m === constants.CORNERS ||
  63711. m === constants.RADIUS ||
  63712. m === constants.CENTER
  63713. ) {
  63714. this._renderer._ellipseMode = m;
  63715. }
  63716. return this;
  63717. };
  63718. /**
  63719. * Draws all geometry with jagged (aliased) edges. Note that <a href="#/p5/smooth">smooth()</a> is
  63720. * active by default in 2D mode, so it is necessary to call <a href="#/p5/noSmooth">noSmooth()</a> to disable
  63721. * smoothing of geometry, images, and fonts. In 3D mode, <a href="#/p5/noSmooth">noSmooth()</a> is enabled
  63722. * by default, so it is necessary to call <a href="#/p5/smooth">smooth()</a> if you would like
  63723. * smooth (antialiased) edges on your geometry.
  63724. *
  63725. * @method noSmooth
  63726. * @chainable
  63727. * @example
  63728. * <div>
  63729. * <code>
  63730. * background(0);
  63731. * noStroke();
  63732. * smooth();
  63733. * ellipse(30, 48, 36, 36);
  63734. * noSmooth();
  63735. * ellipse(70, 48, 36, 36);
  63736. * </code>
  63737. * </div>
  63738. *
  63739. * @alt
  63740. * 2 pixelated 36x36 white ellipses to left & right of center, black background
  63741. */
  63742. _main.default.prototype.noSmooth = function() {
  63743. this.setAttributes('antialias', false);
  63744. if (!this._renderer.isP3D) {
  63745. if ('imageSmoothingEnabled' in this.drawingContext) {
  63746. this.drawingContext.imageSmoothingEnabled = false;
  63747. }
  63748. }
  63749. return this;
  63750. };
  63751. /**
  63752. * Modifies the location from which rectangles are drawn by changing the way
  63753. * in which parameters given to <a href="#/p5/rect">rect()</a> are interpreted.
  63754. *
  63755. * The default mode is CORNER, which interprets the first two parameters as the
  63756. * upper-left corner of the shape, while the third and fourth parameters are its
  63757. * width and height.
  63758. *
  63759. * rectMode(CORNERS) interprets the first two parameters as the location of
  63760. * one of the corners, and the third and fourth parameters as the location of
  63761. * the diagonally opposite corner. Note, the rectangle is drawn between the
  63762. * coordinates, so it is not neccesary that the first corner be the upper left
  63763. * corner.
  63764. *
  63765. * rectMode(CENTER) interprets the first two parameters as the shape's center
  63766. * point, while the third and fourth parameters are its width and height.
  63767. *
  63768. * rectMode(RADIUS) also uses the first two parameters as the shape's center
  63769. * point, but uses the third and fourth parameters to specify half of the shape's
  63770. * width and height respectively.
  63771. *
  63772. * The parameter to this method must be written in ALL CAPS because they are
  63773. * predefined as constants in ALL CAPS and Javascript is a case-sensitive language.
  63774. *
  63775. * @method rectMode
  63776. * @param {Constant} mode either CORNER, CORNERS, CENTER, or RADIUS
  63777. * @chainable
  63778. * @example
  63779. * <div>
  63780. * <code>
  63781. * rectMode(CORNER);
  63782. * fill(255);
  63783. * rect(25, 25, 50, 50); // Draw white rectangle using CORNER mode
  63784. *
  63785. * rectMode(CORNERS);
  63786. * fill(100);
  63787. * rect(25, 25, 50, 50); // Draw gray rectangle using CORNERS mode
  63788. * </code>
  63789. * </div>
  63790. *
  63791. * <div>
  63792. * <code>
  63793. * rectMode(RADIUS);
  63794. * fill(255);
  63795. * rect(50, 50, 30, 30); // Draw white rectangle using RADIUS mode
  63796. *
  63797. * rectMode(CENTER);
  63798. * fill(100);
  63799. * rect(50, 50, 30, 30); // Draw gray rectangle using CENTER mode
  63800. * </code>
  63801. * </div>
  63802. *
  63803. * @alt
  63804. * 50x50 white rect at center and 25x25 grey rect in the top left of the other.
  63805. * 50x50 white rect at center and 25x25 grey rect in the center of the other.
  63806. */
  63807. _main.default.prototype.rectMode = function(m) {
  63808. _main.default._validateParameters('rectMode', arguments);
  63809. if (
  63810. m === constants.CORNER ||
  63811. m === constants.CORNERS ||
  63812. m === constants.RADIUS ||
  63813. m === constants.CENTER
  63814. ) {
  63815. this._renderer._rectMode = m;
  63816. }
  63817. return this;
  63818. };
  63819. /**
  63820. * Draws all geometry with smooth (anti-aliased) edges. <a href="#/p5/smooth">smooth()</a> will also
  63821. * improve image quality of resized images. Note that <a href="#/p5/smooth">smooth()</a> is active by
  63822. * default in 2D mode; <a href="#/p5/noSmooth">noSmooth()</a> can be used to disable smoothing of geometry,
  63823. * images, and fonts. In 3D mode, <a href="#/p5/noSmooth">noSmooth()</a> is enabled
  63824. * by default, so it is necessary to call <a href="#/p5/smooth">smooth()</a> if you would like
  63825. * smooth (antialiased) edges on your geometry.
  63826. *
  63827. * @method smooth
  63828. * @chainable
  63829. * @example
  63830. * <div>
  63831. * <code>
  63832. * background(0);
  63833. * noStroke();
  63834. * smooth();
  63835. * ellipse(30, 48, 36, 36);
  63836. * noSmooth();
  63837. * ellipse(70, 48, 36, 36);
  63838. * </code>
  63839. * </div>
  63840. *
  63841. * @alt
  63842. * 2 pixelated 36x36 white ellipses one left one right of center. On black.
  63843. */
  63844. _main.default.prototype.smooth = function() {
  63845. this.setAttributes('antialias', true);
  63846. if (!this._renderer.isP3D) {
  63847. if ('imageSmoothingEnabled' in this.drawingContext) {
  63848. this.drawingContext.imageSmoothingEnabled = true;
  63849. }
  63850. }
  63851. return this;
  63852. };
  63853. /**
  63854. * Sets the style for rendering line endings. These ends are either rounded,
  63855. * squared or extended, each of which specified with the corresponding
  63856. * parameters: ROUND, SQUARE and PROJECT. The default cap is ROUND.
  63857. *
  63858. * The parameter to this method must be written in ALL CAPS because they are
  63859. * predefined as constants in ALL CAPS and Javascript is a case-sensitive language.
  63860. *
  63861. * @method strokeCap
  63862. * @param {Constant} cap either ROUND, SQUARE or PROJECT
  63863. * @chainable
  63864. * @example
  63865. * <div>
  63866. * <code>
  63867. * // Example of different strokeCaps
  63868. * strokeWeight(12.0);
  63869. * strokeCap(ROUND);
  63870. * line(20, 30, 80, 30);
  63871. * strokeCap(SQUARE);
  63872. * line(20, 50, 80, 50);
  63873. * strokeCap(PROJECT);
  63874. * line(20, 70, 80, 70);
  63875. * </code>
  63876. * </div>
  63877. *
  63878. * @alt
  63879. * 3 lines. Top line: rounded ends, mid: squared, bottom:longer squared ends.
  63880. */
  63881. _main.default.prototype.strokeCap = function(cap) {
  63882. _main.default._validateParameters('strokeCap', arguments);
  63883. if (
  63884. cap === constants.ROUND ||
  63885. cap === constants.SQUARE ||
  63886. cap === constants.PROJECT
  63887. ) {
  63888. this._renderer.strokeCap(cap);
  63889. }
  63890. return this;
  63891. };
  63892. /**
  63893. * Sets the style of the joints which connect line segments. These joints
  63894. * are either mitered, beveled or rounded and specified with the
  63895. * corresponding parameters MITER, BEVEL and ROUND. The default joint is
  63896. * MITER.
  63897. *
  63898. * The parameter to this method must be written in ALL CAPS because they are
  63899. * predefined as constants in ALL CAPS and Javascript is a case-sensitive language.
  63900. *
  63901. * @method strokeJoin
  63902. * @param {Constant} join either MITER, BEVEL, ROUND
  63903. * @chainable
  63904. * @example
  63905. * <div>
  63906. * <code>
  63907. * // Example of MITER type of joints
  63908. * noFill();
  63909. * strokeWeight(10.0);
  63910. * strokeJoin(MITER);
  63911. * beginShape();
  63912. * vertex(35, 20);
  63913. * vertex(65, 50);
  63914. * vertex(35, 80);
  63915. * endShape();
  63916. * </code>
  63917. * </div>
  63918. *
  63919. * <div>
  63920. * <code>
  63921. * // Example of BEVEL type of joints
  63922. * noFill();
  63923. * strokeWeight(10.0);
  63924. * strokeJoin(BEVEL);
  63925. * beginShape();
  63926. * vertex(35, 20);
  63927. * vertex(65, 50);
  63928. * vertex(35, 80);
  63929. * endShape();
  63930. * </code>
  63931. * </div>
  63932. *
  63933. * <div>
  63934. * <code>
  63935. * // Example of ROUND type of joints
  63936. * noFill();
  63937. * strokeWeight(10.0);
  63938. * strokeJoin(ROUND);
  63939. * beginShape();
  63940. * vertex(35, 20);
  63941. * vertex(65, 50);
  63942. * vertex(35, 80);
  63943. * endShape();
  63944. * </code>
  63945. * </div>
  63946. *
  63947. * @alt
  63948. * Right-facing arrowhead shape with pointed tip in center of canvas.
  63949. * Right-facing arrowhead shape with flat tip in center of canvas.
  63950. * Right-facing arrowhead shape with rounded tip in center of canvas.
  63951. */
  63952. _main.default.prototype.strokeJoin = function(join) {
  63953. _main.default._validateParameters('strokeJoin', arguments);
  63954. if (
  63955. join === constants.ROUND ||
  63956. join === constants.BEVEL ||
  63957. join === constants.MITER
  63958. ) {
  63959. this._renderer.strokeJoin(join);
  63960. }
  63961. return this;
  63962. };
  63963. /**
  63964. * Sets the width of the stroke used for lines, points and the border around
  63965. * shapes. All widths are set in units of pixels.
  63966. *
  63967. * @method strokeWeight
  63968. * @param {Number} weight the weight of the stroke (in pixels)
  63969. * @chainable
  63970. * @example
  63971. * <div>
  63972. * <code>
  63973. * // Example of different stroke weights
  63974. * strokeWeight(1); // Default
  63975. * line(20, 20, 80, 20);
  63976. * strokeWeight(4); // Thicker
  63977. * line(20, 40, 80, 40);
  63978. * strokeWeight(10); // Beastly
  63979. * line(20, 70, 80, 70);
  63980. * </code>
  63981. * </div>
  63982. *
  63983. * @alt
  63984. * 3 horizontal black lines. Top line: thin, mid: medium, bottom:thick.
  63985. */
  63986. _main.default.prototype.strokeWeight = function(w) {
  63987. _main.default._validateParameters('strokeWeight', arguments);
  63988. this._renderer.strokeWeight(w);
  63989. return this;
  63990. };
  63991. var _default = _main.default;
  63992. exports.default = _default;
  63993. },
  63994. { '../constants': 272, '../main': 283 }
  63995. ],
  63996. 292: [
  63997. function(_dereq_, module, exports) {
  63998. 'use strict';
  63999. Object.defineProperty(exports, '__esModule', { value: true });
  64000. exports.default = void 0;
  64001. var _main = _interopRequireDefault(_dereq_('../main'));
  64002. _dereq_('../friendly_errors/fes_core');
  64003. _dereq_('../friendly_errors/file_errors');
  64004. _dereq_('../friendly_errors/validate_params');
  64005. function _interopRequireDefault(obj) {
  64006. return obj && obj.__esModule ? obj : { default: obj };
  64007. }
  64008. /**
  64009. * @module Shape
  64010. * @submodule Curves
  64011. * @for p5
  64012. * @requires core
  64013. */ /**
  64014. * Draws a cubic Bezier curve on the screen. These curves are defined by a
  64015. * series of anchor and control points. The first two parameters specify
  64016. * the first anchor point and the last two parameters specify the other
  64017. * anchor point, which become the first and last points on the curve. The
  64018. * middle parameters specify the two control points which define the shape
  64019. * of the curve. Approximately speaking, control points "pull" the curve
  64020. * towards them.
  64021. *
  64022. * Bezier curves were developed by French automotive engineer Pierre Bezier,
  64023. * and are commonly used in computer graphics to define gently sloping curves.
  64024. * See also <a href="#/p5/curve">curve()</a>.
  64025. *
  64026. * @method bezier
  64027. * @param {Number} x1 x-coordinate for the first anchor point
  64028. * @param {Number} y1 y-coordinate for the first anchor point
  64029. * @param {Number} x2 x-coordinate for the first control point
  64030. * @param {Number} y2 y-coordinate for the first control point
  64031. * @param {Number} x3 x-coordinate for the second control point
  64032. * @param {Number} y3 y-coordinate for the second control point
  64033. * @param {Number} x4 x-coordinate for the second anchor point
  64034. * @param {Number} y4 y-coordinate for the second anchor point
  64035. * @chainable
  64036. * @example
  64037. * <div>
  64038. * <code>
  64039. * noFill();
  64040. * stroke(255, 102, 0);
  64041. * line(85, 20, 10, 10);
  64042. * line(90, 90, 15, 80);
  64043. * stroke(0, 0, 0);
  64044. * bezier(85, 20, 10, 10, 90, 90, 15, 80);
  64045. * </code>
  64046. * </div>
  64047. *
  64048. * <div>
  64049. * <code>
  64050. * background(0, 0, 0);
  64051. * noFill();
  64052. * stroke(255);
  64053. * bezier(250, 250, 0, 100, 100, 0, 100, 0, 0, 0, 100, 0);
  64054. * </code>
  64055. * </div>
  64056. *
  64057. * @alt
  64058. * stretched black s-shape in center with orange lines extending from end points.
  64059. * a white colored curve on black background from the upper-right corner to the lower right corner.
  64060. */ /**
  64061. * @method bezier
  64062. * @param {Number} x1
  64063. * @param {Number} y1
  64064. * @param {Number} z1 z-coordinate for the first anchor point
  64065. * @param {Number} x2
  64066. * @param {Number} y2
  64067. * @param {Number} z2 z-coordinate for the first control point
  64068. * @param {Number} x3
  64069. * @param {Number} y3
  64070. * @param {Number} z3 z-coordinate for the second control point
  64071. * @param {Number} x4
  64072. * @param {Number} y4
  64073. * @param {Number} z4 z-coordinate for the second anchor point
  64074. * @chainable
  64075. */ _main.default.prototype.bezier = function() {
  64076. var _this$_renderer;
  64077. for (
  64078. var _len = arguments.length, args = new Array(_len), _key = 0;
  64079. _key < _len;
  64080. _key++
  64081. ) {
  64082. args[_key] = arguments[_key];
  64083. }
  64084. _main.default._validateParameters('bezier', args);
  64085. // if the current stroke and fill settings wouldn't result in something
  64086. // visible, exit immediately
  64087. if (!this._renderer._doStroke && !this._renderer._doFill) {
  64088. return this;
  64089. }
  64090. (_this$_renderer = this._renderer).bezier.apply(_this$_renderer, args);
  64091. return this;
  64092. };
  64093. /**
  64094. * Sets the resolution at which Bezier's curve is displayed. The default value is 20.
  64095. *
  64096. * Note, This function is only useful when using the WEBGL renderer
  64097. * as the default canvas renderer does not use this information.
  64098. *
  64099. * @method bezierDetail
  64100. * @param {Number} detail resolution of the curves
  64101. * @chainable
  64102. * @example
  64103. * <div modernizr='webgl'>
  64104. * <code>
  64105. * function setup() {
  64106. * createCanvas(100, 100, WEBGL);
  64107. * noFill();
  64108. * bezierDetail(5);
  64109. * }
  64110. *
  64111. * function draw() {
  64112. * background(200);
  64113. * // prettier-ignore
  64114. * bezier(-40, -40, 0,
  64115. * 90, -40, 0,
  64116. * -90, 40, 0,
  64117. * 40, 40, 0);
  64118. * }
  64119. * </code>
  64120. * </div>
  64121. *
  64122. * @alt
  64123. * stretched black s-shape with a low level of bezier detail
  64124. */
  64125. _main.default.prototype.bezierDetail = function(d) {
  64126. _main.default._validateParameters('bezierDetail', arguments);
  64127. this._bezierDetail = d;
  64128. return this;
  64129. };
  64130. /**
  64131. * Given the x or y co-ordinate values of control and anchor points of a bezier
  64132. * curve, it evaluates the x or y coordinate of the bezier at position t. The
  64133. * parameters a and d are the x or y coordinates of first and last points on the
  64134. * curve while b and c are of the control points.The final parameter t is the
  64135. * position of the resultant point which is given between 0 and 1.
  64136. * This can be done once with the x coordinates and a second time
  64137. * with the y coordinates to get the location of a bezier curve at t.
  64138. *
  64139. * @method bezierPoint
  64140. * @param {Number} a coordinate of first point on the curve
  64141. * @param {Number} b coordinate of first control point
  64142. * @param {Number} c coordinate of second control point
  64143. * @param {Number} d coordinate of second point on the curve
  64144. * @param {Number} t value between 0 and 1
  64145. * @return {Number} the value of the Bezier at position t
  64146. * @example
  64147. * <div>
  64148. * <code>
  64149. * noFill();
  64150. * let x1 = 85,
  64151. x2 = 10,
  64152. x3 = 90,
  64153. x4 = 15;
  64154. * let y1 = 20,
  64155. y2 = 10,
  64156. y3 = 90,
  64157. y4 = 80;
  64158. * bezier(x1, y1, x2, y2, x3, y3, x4, y4);
  64159. * fill(255);
  64160. * let steps = 10;
  64161. * for (let i = 0; i <= steps; i++) {
  64162. * let t = i / steps;
  64163. * let x = bezierPoint(x1, x2, x3, x4, t);
  64164. * let y = bezierPoint(y1, y2, y3, y4, t);
  64165. * circle(x, y, 5);
  64166. * }
  64167. * </code>
  64168. * </div>
  64169. *
  64170. * @alt
  64171. * 10 points plotted on a given bezier at equal distances.
  64172. */
  64173. _main.default.prototype.bezierPoint = function(a, b, c, d, t) {
  64174. _main.default._validateParameters('bezierPoint', arguments);
  64175. var adjustedT = 1 - t;
  64176. return (
  64177. Math.pow(adjustedT, 3) * a +
  64178. 3 * Math.pow(adjustedT, 2) * t * b +
  64179. 3 * adjustedT * Math.pow(t, 2) * c +
  64180. Math.pow(t, 3) * d
  64181. );
  64182. };
  64183. /**
  64184. * Evaluates the tangent to the Bezier at position t for points a, b, c, d.
  64185. * The parameters a and d are the first and last points
  64186. * on the curve, and b and c are the control points.
  64187. * The final parameter t varies between 0 and 1.
  64188. *
  64189. * @method bezierTangent
  64190. * @param {Number} a coordinate of first point on the curve
  64191. * @param {Number} b coordinate of first control point
  64192. * @param {Number} c coordinate of second control point
  64193. * @param {Number} d coordinate of second point on the curve
  64194. * @param {Number} t value between 0 and 1
  64195. * @return {Number} the tangent at position t
  64196. * @example
  64197. * <div>
  64198. * <code>
  64199. * noFill();
  64200. * bezier(85, 20, 10, 10, 90, 90, 15, 80);
  64201. * let steps = 6;
  64202. * fill(255);
  64203. * for (let i = 0; i <= steps; i++) {
  64204. * let t = i / steps;
  64205. * // Get the location of the point
  64206. * let x = bezierPoint(85, 10, 90, 15, t);
  64207. * let y = bezierPoint(20, 10, 90, 80, t);
  64208. * // Get the tangent points
  64209. * let tx = bezierTangent(85, 10, 90, 15, t);
  64210. * let ty = bezierTangent(20, 10, 90, 80, t);
  64211. * // Calculate an angle from the tangent points
  64212. * let a = atan2(ty, tx);
  64213. * a += PI;
  64214. * stroke(255, 102, 0);
  64215. * line(x, y, cos(a) * 30 + x, sin(a) * 30 + y);
  64216. * // The following line of code makes a line
  64217. * // inverse of the above line
  64218. * //line(x, y, cos(a)*-30 + x, sin(a)*-30 + y);
  64219. * stroke(0);
  64220. * ellipse(x, y, 5, 5);
  64221. * }
  64222. * </code>
  64223. * </div>
  64224. *
  64225. * <div>
  64226. * <code>
  64227. * noFill();
  64228. * bezier(85, 20, 10, 10, 90, 90, 15, 80);
  64229. * stroke(255, 102, 0);
  64230. * let steps = 16;
  64231. * for (let i = 0; i <= steps; i++) {
  64232. * let t = i / steps;
  64233. * let x = bezierPoint(85, 10, 90, 15, t);
  64234. * let y = bezierPoint(20, 10, 90, 80, t);
  64235. * let tx = bezierTangent(85, 10, 90, 15, t);
  64236. * let ty = bezierTangent(20, 10, 90, 80, t);
  64237. * let a = atan2(ty, tx);
  64238. * a -= HALF_PI;
  64239. * line(x, y, cos(a) * 8 + x, sin(a) * 8 + y);
  64240. * }
  64241. * </code>
  64242. * </div>
  64243. *
  64244. * @alt
  64245. * s-shaped line with 6 short orange lines showing the tangents at those points.
  64246. * s-shaped line with 6 short orange lines showing lines coming out the underside of the bezier.
  64247. */
  64248. _main.default.prototype.bezierTangent = function(a, b, c, d, t) {
  64249. _main.default._validateParameters('bezierTangent', arguments);
  64250. var adjustedT = 1 - t;
  64251. return (
  64252. 3 * d * Math.pow(t, 2) -
  64253. 3 * c * Math.pow(t, 2) +
  64254. 6 * c * adjustedT * t -
  64255. 6 * b * adjustedT * t +
  64256. 3 * b * Math.pow(adjustedT, 2) -
  64257. 3 * a * Math.pow(adjustedT, 2)
  64258. );
  64259. };
  64260. /**
  64261. * Draws a curved line on the screen between two points, given as the
  64262. * middle four parameters. The first two parameters are a control point, as
  64263. * if the curve came from this point even though it's not drawn. The last
  64264. * two parameters similarly describe the other control point. <br /><br />
  64265. * Longer curves can be created by putting a series of <a href="#/p5/curve">curve()</a> functions
  64266. * together or using <a href="#/p5/curveVertex">curveVertex()</a>. An additional function called
  64267. * <a href="#/p5/curveTightness">curveTightness()</a> provides control for the visual quality of the curve.
  64268. * The <a href="#/p5/curve">curve()</a> function is an implementation of Catmull-Rom splines.
  64269. *
  64270. * @method curve
  64271. * @param {Number} x1 x-coordinate for the beginning control point
  64272. * @param {Number} y1 y-coordinate for the beginning control point
  64273. * @param {Number} x2 x-coordinate for the first point
  64274. * @param {Number} y2 y-coordinate for the first point
  64275. * @param {Number} x3 x-coordinate for the second point
  64276. * @param {Number} y3 y-coordinate for the second point
  64277. * @param {Number} x4 x-coordinate for the ending control point
  64278. * @param {Number} y4 y-coordinate for the ending control point
  64279. * @chainable
  64280. * @example
  64281. * <div>
  64282. * <code>
  64283. * noFill();
  64284. * stroke(255, 102, 0);
  64285. * curve(5, 26, 5, 26, 73, 24, 73, 61);
  64286. * stroke(0);
  64287. * curve(5, 26, 73, 24, 73, 61, 15, 65);
  64288. * stroke(255, 102, 0);
  64289. * curve(73, 24, 73, 61, 15, 65, 15, 65);
  64290. * </code>
  64291. * </div>
  64292. *
  64293. * <div>
  64294. * <code>
  64295. * // Define the curve points as JavaScript objects
  64296. * let p1 = { x: 5, y: 26 };
  64297. * let p2 = { x: 73, y: 24 };
  64298. * let p3 = { x: 73, y: 61 };
  64299. * let p4 = { x: 15, y: 65 };
  64300. * noFill();
  64301. * stroke(255, 102, 0);
  64302. * curve(p1.x, p1.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
  64303. * stroke(0);
  64304. * curve(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y);
  64305. * stroke(255, 102, 0);
  64306. * curve(p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, p4.x, p4.y);
  64307. * </code>
  64308. * </div>
  64309. *
  64310. * <div>
  64311. * <code>
  64312. * noFill();
  64313. * stroke(255, 102, 0);
  64314. * curve(5, 26, 0, 5, 26, 0, 73, 24, 0, 73, 61, 0);
  64315. * stroke(0);
  64316. * curve(5, 26, 0, 73, 24, 0, 73, 61, 0, 15, 65, 0);
  64317. * stroke(255, 102, 0);
  64318. * curve(73, 24, 0, 73, 61, 0, 15, 65, 0, 15, 65, 0);
  64319. * </code>
  64320. * </div>
  64321. *
  64322. * @alt
  64323. * horseshoe shape with orange ends facing left and black curved center.
  64324. * horseshoe shape with orange ends facing left and black curved center.
  64325. * curving black and orange lines.
  64326. */
  64327. /**
  64328. * @method curve
  64329. * @param {Number} x1
  64330. * @param {Number} y1
  64331. * @param {Number} z1 z-coordinate for the beginning control point
  64332. * @param {Number} x2
  64333. * @param {Number} y2
  64334. * @param {Number} z2 z-coordinate for the first point
  64335. * @param {Number} x3
  64336. * @param {Number} y3
  64337. * @param {Number} z3 z-coordinate for the second point
  64338. * @param {Number} x4
  64339. * @param {Number} y4
  64340. * @param {Number} z4 z-coordinate for the ending control point
  64341. * @chainable
  64342. */
  64343. _main.default.prototype.curve = function() {
  64344. for (
  64345. var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
  64346. _key2 < _len2;
  64347. _key2++
  64348. ) {
  64349. args[_key2] = arguments[_key2];
  64350. }
  64351. _main.default._validateParameters('curve', args);
  64352. if (this._renderer._doStroke) {
  64353. var _this$_renderer2;
  64354. (_this$_renderer2 = this._renderer).curve.apply(_this$_renderer2, args);
  64355. }
  64356. return this;
  64357. };
  64358. /**
  64359. * Sets the resolution at which curves display. The default value is 20 while
  64360. * the minimum value is 3.
  64361. *
  64362. * This function is only useful when using the WEBGL renderer
  64363. * as the default canvas renderer does not use this
  64364. * information.
  64365. *
  64366. * @method curveDetail
  64367. * @param {Number} resolution resolution of the curves
  64368. * @chainable
  64369. * @example
  64370. * <div modernizr='webgl'>
  64371. * <code>
  64372. * function setup() {
  64373. * createCanvas(100, 100, WEBGL);
  64374. *
  64375. * curveDetail(5);
  64376. * }
  64377. * function draw() {
  64378. * background(200);
  64379. *
  64380. * curve(250, 600, 0, -30, 40, 0, 30, 30, 0, -250, 600, 0);
  64381. * }
  64382. * </code>
  64383. * </div>
  64384. *
  64385. * @alt
  64386. * white arch shape with a low level of curve detail.
  64387. */
  64388. _main.default.prototype.curveDetail = function(d) {
  64389. _main.default._validateParameters('curveDetail', arguments);
  64390. if (d < 3) {
  64391. this._curveDetail = 3;
  64392. } else {
  64393. this._curveDetail = d;
  64394. }
  64395. return this;
  64396. };
  64397. /**
  64398. * Modifies the quality of forms created with <a href="#/p5/curve">curve()</a>
  64399. * and <a href="#/p5/curveVertex">curveVertex()</a>.The parameter tightness
  64400. * determines how the curve fits to the vertex points. The value 0.0 is the
  64401. * default value for tightness (this value defines the curves to be Catmull-Rom
  64402. * splines) and the value 1.0 connects all the points with straight lines.
  64403. * Values within the range -5.0 and 5.0 will deform the curves but will leave
  64404. * them recognizable and as values increase in magnitude, they will continue to deform.
  64405. *
  64406. * @method curveTightness
  64407. * @param {Number} amount amount of deformation from the original vertices
  64408. * @chainable
  64409. * @example
  64410. * <div>
  64411. * <code>
  64412. * // Move the mouse left and right to see the curve change
  64413. * function setup() {
  64414. * createCanvas(100, 100);
  64415. * noFill();
  64416. * }
  64417. *
  64418. * function draw() {
  64419. * background(204);
  64420. * let t = map(mouseX, 0, width, -5, 5);
  64421. * curveTightness(t);
  64422. * beginShape();
  64423. * curveVertex(10, 26);
  64424. * curveVertex(10, 26);
  64425. * curveVertex(83, 24);
  64426. * curveVertex(83, 61);
  64427. * curveVertex(25, 65);
  64428. * curveVertex(25, 65);
  64429. * endShape();
  64430. * }
  64431. * </code>
  64432. * </div>
  64433. *
  64434. * @alt
  64435. * Line shaped like right-facing arrow,points move with mouse-x and warp shape.
  64436. */
  64437. _main.default.prototype.curveTightness = function(t) {
  64438. _main.default._validateParameters('curveTightness', arguments);
  64439. this._renderer._curveTightness = t;
  64440. return this;
  64441. };
  64442. /**
  64443. * Evaluates the curve at position t for points a, b, c, d.
  64444. * The parameter t varies between 0 and 1, a and d are control points
  64445. * of the curve, and b and c are the start and end points of the curve.
  64446. * This can be done once with the x coordinates and a second time
  64447. * with the y coordinates to get the location of a curve at t.
  64448. *
  64449. * @method curvePoint
  64450. * @param {Number} a coordinate of first control point of the curve
  64451. * @param {Number} b coordinate of first point
  64452. * @param {Number} c coordinate of second point
  64453. * @param {Number} d coordinate of second control point
  64454. * @param {Number} t value between 0 and 1
  64455. * @return {Number} bezier value at position t
  64456. * @example
  64457. * <div>
  64458. * <code>
  64459. * noFill();
  64460. * curve(5, 26, 5, 26, 73, 24, 73, 61);
  64461. * curve(5, 26, 73, 24, 73, 61, 15, 65);
  64462. * fill(255);
  64463. * ellipseMode(CENTER);
  64464. * let steps = 6;
  64465. * for (let i = 0; i <= steps; i++) {
  64466. * let t = i / steps;
  64467. * let x = curvePoint(5, 5, 73, 73, t);
  64468. * let y = curvePoint(26, 26, 24, 61, t);
  64469. * ellipse(x, y, 5, 5);
  64470. * x = curvePoint(5, 73, 73, 15, t);
  64471. * y = curvePoint(26, 24, 61, 65, t);
  64472. * ellipse(x, y, 5, 5);
  64473. * }
  64474. * </code>
  64475. * </div>
  64476. *
  64477. *line hooking down to right-bottom with 13 5x5 white ellipse points
  64478. */
  64479. _main.default.prototype.curvePoint = function(a, b, c, d, t) {
  64480. _main.default._validateParameters('curvePoint', arguments);
  64481. var t3 = t * t * t,
  64482. t2 = t * t,
  64483. f1 = -0.5 * t3 + t2 - 0.5 * t,
  64484. f2 = 1.5 * t3 - 2.5 * t2 + 1.0,
  64485. f3 = -1.5 * t3 + 2.0 * t2 + 0.5 * t,
  64486. f4 = 0.5 * t3 - 0.5 * t2;
  64487. return a * f1 + b * f2 + c * f3 + d * f4;
  64488. };
  64489. /**
  64490. * Evaluates the tangent to the curve at position t for points a, b, c, d.
  64491. * The parameter t varies between 0 and 1, a and d are points on the curve,
  64492. * and b and c are the control points.
  64493. *
  64494. * @method curveTangent
  64495. * @param {Number} a coordinate of first control point
  64496. * @param {Number} b coordinate of first point on the curve
  64497. * @param {Number} c coordinate of second point on the curve
  64498. * @param {Number} d coordinate of second conrol point
  64499. * @param {Number} t value between 0 and 1
  64500. * @return {Number} the tangent at position t
  64501. * @example
  64502. * <div>
  64503. * <code>
  64504. * noFill();
  64505. * curve(5, 26, 73, 24, 73, 61, 15, 65);
  64506. * let steps = 6;
  64507. * for (let i = 0; i <= steps; i++) {
  64508. * let t = i / steps;
  64509. * let x = curvePoint(5, 73, 73, 15, t);
  64510. * let y = curvePoint(26, 24, 61, 65, t);
  64511. * //ellipse(x, y, 5, 5);
  64512. * let tx = curveTangent(5, 73, 73, 15, t);
  64513. * let ty = curveTangent(26, 24, 61, 65, t);
  64514. * let a = atan2(ty, tx);
  64515. * a -= PI / 2.0;
  64516. * line(x, y, cos(a) * 8 + x, sin(a) * 8 + y);
  64517. * }
  64518. * </code>
  64519. * </div>
  64520. *
  64521. * @alt
  64522. * right curving line mid-right of canvas with 7 short lines radiating from it.
  64523. */
  64524. _main.default.prototype.curveTangent = function(a, b, c, d, t) {
  64525. _main.default._validateParameters('curveTangent', arguments);
  64526. var t2 = t * t,
  64527. f1 = -3 * t2 / 2 + 2 * t - 0.5,
  64528. f2 = 9 * t2 / 2 - 5 * t,
  64529. f3 = -9 * t2 / 2 + 4 * t + 0.5,
  64530. f4 = 3 * t2 / 2 - t;
  64531. return a * f1 + b * f2 + c * f3 + d * f4;
  64532. };
  64533. var _default = _main.default;
  64534. exports.default = _default;
  64535. },
  64536. {
  64537. '../friendly_errors/fes_core': 275,
  64538. '../friendly_errors/file_errors': 276,
  64539. '../friendly_errors/validate_params': 278,
  64540. '../main': 283
  64541. }
  64542. ],
  64543. 293: [
  64544. function(_dereq_, module, exports) {
  64545. 'use strict';
  64546. function _typeof(obj) {
  64547. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  64548. _typeof = function _typeof(obj) {
  64549. return typeof obj;
  64550. };
  64551. } else {
  64552. _typeof = function _typeof(obj) {
  64553. return obj &&
  64554. typeof Symbol === 'function' &&
  64555. obj.constructor === Symbol &&
  64556. obj !== Symbol.prototype
  64557. ? 'symbol'
  64558. : typeof obj;
  64559. };
  64560. }
  64561. return _typeof(obj);
  64562. }
  64563. _dereq_('core-js/modules/es.array.slice');
  64564. Object.defineProperty(exports, '__esModule', { value: true });
  64565. exports.default = void 0;
  64566. var _main = _interopRequireDefault(_dereq_('../main'));
  64567. var constants = _interopRequireWildcard(_dereq_('../constants'));
  64568. function _getRequireWildcardCache() {
  64569. if (typeof WeakMap !== 'function') return null;
  64570. var cache = new WeakMap();
  64571. _getRequireWildcardCache = function _getRequireWildcardCache() {
  64572. return cache;
  64573. };
  64574. return cache;
  64575. }
  64576. function _interopRequireWildcard(obj) {
  64577. if (obj && obj.__esModule) {
  64578. return obj;
  64579. }
  64580. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  64581. return { default: obj };
  64582. }
  64583. var cache = _getRequireWildcardCache();
  64584. if (cache && cache.has(obj)) {
  64585. return cache.get(obj);
  64586. }
  64587. var newObj = {};
  64588. var hasPropertyDescriptor =
  64589. Object.defineProperty && Object.getOwnPropertyDescriptor;
  64590. for (var key in obj) {
  64591. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  64592. var desc = hasPropertyDescriptor
  64593. ? Object.getOwnPropertyDescriptor(obj, key)
  64594. : null;
  64595. if (desc && (desc.get || desc.set)) {
  64596. Object.defineProperty(newObj, key, desc);
  64597. } else {
  64598. newObj[key] = obj[key];
  64599. }
  64600. }
  64601. }
  64602. newObj.default = obj;
  64603. if (cache) {
  64604. cache.set(obj, newObj);
  64605. }
  64606. return newObj;
  64607. }
  64608. function _interopRequireDefault(obj) {
  64609. return obj && obj.__esModule ? obj : { default: obj };
  64610. }
  64611. /**
  64612. * @module Shape
  64613. * @submodule Vertex
  64614. * @for p5
  64615. * @requires core
  64616. * @requires constants
  64617. */ var shapeKind = null;
  64618. var vertices = [];
  64619. var contourVertices = [];
  64620. var isBezier = false;
  64621. var isCurve = false;
  64622. var isQuadratic = false;
  64623. var isContour = false;
  64624. var isFirstContour = true;
  64625. /**
  64626. * Use the <a href="#/p5/beginContour">beginContour()</a> and
  64627. * <a href="#/p5/endContour">endContour()</a> functions to create negative shapes
  64628. * within shapes such as the center of the letter 'O'. <a href="#/p5/beginContour">beginContour()</a>
  64629. * begins recording vertices for the shape and <a href="#/p5/endContour">endContour()</a> stops recording.
  64630. * The vertices that define a negative shape must "wind" in the opposite direction
  64631. * from the exterior shape. First draw vertices for the exterior clockwise order, then for internal shapes, draw vertices
  64632. * shape in counter-clockwise.
  64633. *
  64634. * These functions can only be used within a <a href="#/p5/beginShape">beginShape()</a>/<a href="#/p5/endShape">endShape()</a> pair and
  64635. * transformations such as <a href="#/p5/translate">translate()</a>, <a href="#/p5/rotate">rotate()</a>, and <a href="#/p5/scale">scale()</a> do not work
  64636. * within a <a href="#/p5/beginContour">beginContour()</a>/<a href="#/p5/endContour">endContour()</a> pair. It is also not possible to use
  64637. * other shapes, such as <a href="#/p5/ellipse">ellipse()</a> or <a href="#/p5/rect">rect()</a> within.
  64638. *
  64639. * @method beginContour
  64640. * @chainable
  64641. * @example
  64642. * <div>
  64643. * <code>
  64644. * translate(50, 50);
  64645. * stroke(255, 0, 0);
  64646. * beginShape();
  64647. * // Exterior part of shape, clockwise winding
  64648. * vertex(-40, -40);
  64649. * vertex(40, -40);
  64650. * vertex(40, 40);
  64651. * vertex(-40, 40);
  64652. * // Interior part of shape, counter-clockwise winding
  64653. * beginContour();
  64654. * vertex(-20, -20);
  64655. * vertex(-20, 20);
  64656. * vertex(20, 20);
  64657. * vertex(20, -20);
  64658. * endContour();
  64659. * endShape(CLOSE);
  64660. * </code>
  64661. * </div>
  64662. *
  64663. * @alt
  64664. * white rect and smaller grey rect with red outlines in center of canvas.
  64665. */
  64666. _main.default.prototype.beginContour = function() {
  64667. contourVertices = [];
  64668. isContour = true;
  64669. return this;
  64670. };
  64671. /**
  64672. * Using the <a href="#/p5/beginShape">beginShape()</a> and <a href="#/p5/endShape">endShape()</a> functions allow creating more
  64673. * complex forms. <a href="#/p5/beginShape">beginShape()</a> begins recording vertices for a shape and
  64674. * <a href="#/p5/endShape">endShape()</a> stops recording. The value of the kind parameter tells it which
  64675. * types of shapes to create from the provided vertices. With no mode
  64676. * specified, the shape can be any irregular polygon.
  64677. *
  64678. * The parameters available for <a href="#/p5/beginShape">beginShape()</a> are:
  64679. *
  64680. * POINTS
  64681. * Draw a series of points
  64682. *
  64683. * LINES
  64684. * Draw a series of unconnected line segments (individual lines)
  64685. *
  64686. * TRIANGLES
  64687. * Draw a series of separate triangles
  64688. *
  64689. * TRIANGLE_FAN
  64690. * Draw a series of connected triangles sharing the first vertex in a fan-like fashion
  64691. *
  64692. * TRIANGLE_STRIP
  64693. * Draw a series of connected triangles in strip fashion
  64694. *
  64695. * QUADS
  64696. * Draw a series of seperate quad
  64697. *
  64698. * QUAD_STRIP
  64699. * Draw quad strip using adjacent edges to form the next quad
  64700. *
  64701. * TESS (WebGl only)
  64702. * Handle irregular polygon for filling curve by explicit tessellation
  64703. *
  64704. * After calling the <a href="#/p5/beginShape">beginShape()</a> function, a series of <a href="#/p5/vertex">vertex()</a> commands must follow. To stop
  64705. * drawing the shape, call <a href="#/p5/endShape">endShape()</a>. Each shape will be outlined with the
  64706. * current stroke color and filled with the fill color.
  64707. *
  64708. * Transformations such as <a href="#/p5/translate">translate()</a>, <a href="#/p5/rotate">rotate()</a>, and <a href="#/p5/scale">scale()</a> do not work
  64709. * within <a href="#/p5/beginShape">beginShape()</a>. It is also not possible to use other shapes, such as
  64710. * <a href="#/p5/ellipse">ellipse()</a> or <a href="#/p5/rect">rect()</a> within <a href="#/p5/beginShape">beginShape()</a>.
  64711. *
  64712. * @method beginShape
  64713. * @param {Constant} [kind] either POINTS, LINES, TRIANGLES, TRIANGLE_FAN
  64714. * TRIANGLE_STRIP, QUADS, QUAD_STRIP or TESS
  64715. * @chainable
  64716. * @example
  64717. * <div>
  64718. * <code>
  64719. * beginShape();
  64720. * vertex(30, 20);
  64721. * vertex(85, 20);
  64722. * vertex(85, 75);
  64723. * vertex(30, 75);
  64724. * endShape(CLOSE);
  64725. * </code>
  64726. * </div>
  64727. *
  64728. * <div>
  64729. * <code>
  64730. * beginShape(POINTS);
  64731. * vertex(30, 20);
  64732. * vertex(85, 20);
  64733. * vertex(85, 75);
  64734. * vertex(30, 75);
  64735. * endShape();
  64736. * </code>
  64737. * </div>
  64738. *
  64739. * <div>
  64740. * <code>
  64741. * beginShape(LINES);
  64742. * vertex(30, 20);
  64743. * vertex(85, 20);
  64744. * vertex(85, 75);
  64745. * vertex(30, 75);
  64746. * endShape();
  64747. * </code>
  64748. * </div>
  64749. *
  64750. * <div>
  64751. * <code>
  64752. * noFill();
  64753. * beginShape();
  64754. * vertex(30, 20);
  64755. * vertex(85, 20);
  64756. * vertex(85, 75);
  64757. * vertex(30, 75);
  64758. * endShape();
  64759. * </code>
  64760. * </div>
  64761. *
  64762. * <div>
  64763. * <code>
  64764. * noFill();
  64765. * beginShape();
  64766. * vertex(30, 20);
  64767. * vertex(85, 20);
  64768. * vertex(85, 75);
  64769. * vertex(30, 75);
  64770. * endShape(CLOSE);
  64771. * </code>
  64772. * </div>
  64773. *
  64774. * <div>
  64775. * <code>
  64776. * beginShape(TRIANGLES);
  64777. * vertex(30, 75);
  64778. * vertex(40, 20);
  64779. * vertex(50, 75);
  64780. * vertex(60, 20);
  64781. * vertex(70, 75);
  64782. * vertex(80, 20);
  64783. * endShape();
  64784. * </code>
  64785. * </div>
  64786. *
  64787. * <div>
  64788. * <code>
  64789. * beginShape(TRIANGLE_STRIP);
  64790. * vertex(30, 75);
  64791. * vertex(40, 20);
  64792. * vertex(50, 75);
  64793. * vertex(60, 20);
  64794. * vertex(70, 75);
  64795. * vertex(80, 20);
  64796. * vertex(90, 75);
  64797. * endShape();
  64798. * </code>
  64799. * </div>
  64800. *
  64801. * <div>
  64802. * <code>
  64803. * beginShape(TRIANGLE_FAN);
  64804. * vertex(57.5, 50);
  64805. * vertex(57.5, 15);
  64806. * vertex(92, 50);
  64807. * vertex(57.5, 85);
  64808. * vertex(22, 50);
  64809. * vertex(57.5, 15);
  64810. * endShape();
  64811. * </code>
  64812. * </div>
  64813. *
  64814. * <div>
  64815. * <code>
  64816. * beginShape(QUADS);
  64817. * vertex(30, 20);
  64818. * vertex(30, 75);
  64819. * vertex(50, 75);
  64820. * vertex(50, 20);
  64821. * vertex(65, 20);
  64822. * vertex(65, 75);
  64823. * vertex(85, 75);
  64824. * vertex(85, 20);
  64825. * endShape();
  64826. * </code>
  64827. * </div>
  64828. *
  64829. * <div>
  64830. * <code>
  64831. * beginShape(QUAD_STRIP);
  64832. * vertex(30, 20);
  64833. * vertex(30, 75);
  64834. * vertex(50, 20);
  64835. * vertex(50, 75);
  64836. * vertex(65, 20);
  64837. * vertex(65, 75);
  64838. * vertex(85, 20);
  64839. * vertex(85, 75);
  64840. * endShape();
  64841. * </code>
  64842. * </div>
  64843. *
  64844. * <div>
  64845. * <code>
  64846. * beginShape(TESS);
  64847. * vertex(20, 20);
  64848. * vertex(80, 20);
  64849. * vertex(80, 40);
  64850. * vertex(40, 40);
  64851. * vertex(40, 60);
  64852. * vertex(80, 60);
  64853. * vertex(80, 80);
  64854. * vertex(20, 80);
  64855. * endShape(CLOSE);
  64856. * </code>
  64857. * </div>
  64858. *
  64859. * @alt
  64860. * white square-shape with black outline in middle-right of canvas.
  64861. * 4 black points in a square shape in middle-right of canvas.
  64862. * 2 horizontal black lines. In the top-right and bottom-right of canvas.
  64863. * 3 line shape with horizontal on top, vertical in middle and horizontal bottom.
  64864. * square line shape in middle-right of canvas.
  64865. * 2 white triangle shapes mid-right canvas. left one pointing up and right down.
  64866. * 5 horizontal interlocking and alternating white triangles in mid-right canvas.
  64867. * 4 interlocking white triangles in 45 degree rotated square-shape.
  64868. * 2 white rectangle shapes in mid-right canvas. Both 20x55.
  64869. * 3 side-by-side white rectangles center rect is smaller in mid-right canvas.
  64870. * Thick white l-shape with black outline mid-top-left of canvas.
  64871. */
  64872. _main.default.prototype.beginShape = function(kind) {
  64873. _main.default._validateParameters('beginShape', arguments);
  64874. if (this._renderer.isP3D) {
  64875. var _this$_renderer;
  64876. (_this$_renderer = this._renderer).beginShape.apply(
  64877. _this$_renderer,
  64878. arguments
  64879. );
  64880. } else {
  64881. if (
  64882. kind === constants.POINTS ||
  64883. kind === constants.LINES ||
  64884. kind === constants.TRIANGLES ||
  64885. kind === constants.TRIANGLE_FAN ||
  64886. kind === constants.TRIANGLE_STRIP ||
  64887. kind === constants.QUADS ||
  64888. kind === constants.QUAD_STRIP
  64889. ) {
  64890. shapeKind = kind;
  64891. } else {
  64892. shapeKind = null;
  64893. }
  64894. vertices = [];
  64895. contourVertices = [];
  64896. }
  64897. return this;
  64898. };
  64899. /**
  64900. * Specifies vertex coordinates for Bezier curves. Each call to
  64901. * bezierVertex() defines the position of two control points and
  64902. * one anchor point of a Bezier curve, adding a new segment to a
  64903. * line or shape. For WebGL mode bezierVertex() can be used in 2D
  64904. * as well as 3D mode. 2D mode expects 6 parameters, while 3D mode
  64905. * expects 9 parameters (including z coordinates).
  64906. *
  64907. * The first time bezierVertex() is used within a <a href="#/p5/beginShape">beginShape()</a>
  64908. * call, it must be prefaced with a call to <a href="#/p5/vertex">vertex()</a> to set the first anchor
  64909. * point. This function must be used between <a href="#/p5/beginShape">beginShape()</a> and <a href="#/p5/endShape">endShape()</a>
  64910. * and only when there is no MODE or POINTS parameter specified to
  64911. * <a href="#/p5/beginShape">beginShape()</a>.
  64912. *
  64913. * @method bezierVertex
  64914. * @param {Number} x2 x-coordinate for the first control point
  64915. * @param {Number} y2 y-coordinate for the first control point
  64916. * @param {Number} x3 x-coordinate for the second control point
  64917. * @param {Number} y3 y-coordinate for the second control point
  64918. * @param {Number} x4 x-coordinate for the anchor point
  64919. * @param {Number} y4 y-coordinate for the anchor point
  64920. * @chainable
  64921. *
  64922. * @example
  64923. * <div>
  64924. * <code>
  64925. * noFill();
  64926. * beginShape();
  64927. * vertex(30, 20);
  64928. * bezierVertex(80, 0, 80, 75, 30, 75);
  64929. * endShape();
  64930. * </code>
  64931. * </div>
  64932. *
  64933. * <div>
  64934. * <code>
  64935. * beginShape();
  64936. * vertex(30, 20);
  64937. * bezierVertex(80, 0, 80, 75, 30, 75);
  64938. * bezierVertex(50, 80, 60, 25, 30, 20);
  64939. * endShape();
  64940. * </code>
  64941. * </div>
  64942. *
  64943. * <div>
  64944. * <code>
  64945. * function setup() {
  64946. * createCanvas(100, 100, WEBGL);
  64947. * setAttributes('antialias', true);
  64948. * }
  64949. * function draw() {
  64950. * orbitControl();
  64951. * background(50);
  64952. * strokeWeight(4);
  64953. * stroke(255);
  64954. * point(-25, 30);
  64955. * point(25, 30);
  64956. * point(25, -30);
  64957. * point(-25, -30);
  64958. *
  64959. * strokeWeight(1);
  64960. * noFill();
  64961. *
  64962. * beginShape();
  64963. * vertex(-25, 30);
  64964. * bezierVertex(25, 30, 25, -30, -25, -30);
  64965. * endShape();
  64966. *
  64967. * beginShape();
  64968. * vertex(-25, 30, 20);
  64969. * bezierVertex(25, 30, 20, 25, -30, 20, -25, -30, 20);
  64970. * endShape();
  64971. * }
  64972. * </code>
  64973. * </div>
  64974. *
  64975. * @alt
  64976. * crescent-shaped line in middle of canvas. Points facing left.
  64977. * white crescent shape in middle of canvas. Points facing left.
  64978. * crescent shape in middle of canvas with another crescent shape on positive z-axis.
  64979. */
  64980. /**
  64981. * @method bezierVertex
  64982. * @param {Number} x2
  64983. * @param {Number} y2
  64984. * @param {Number} z2 z-coordinate for the first control point (for WebGL mode)
  64985. * @param {Number} x3
  64986. * @param {Number} y3
  64987. * @param {Number} z3 z-coordinate for the second control point (for WebGL mode)
  64988. * @param {Number} x4
  64989. * @param {Number} y4
  64990. * @param {Number} z4 z-coordinate for the anchor point (for WebGL mode)
  64991. * @chainable
  64992. */
  64993. _main.default.prototype.bezierVertex = function() {
  64994. for (
  64995. var _len = arguments.length, args = new Array(_len), _key = 0;
  64996. _key < _len;
  64997. _key++
  64998. ) {
  64999. args[_key] = arguments[_key];
  65000. }
  65001. _main.default._validateParameters('bezierVertex', args);
  65002. if (this._renderer.isP3D) {
  65003. var _this$_renderer2;
  65004. (_this$_renderer2 = this._renderer).bezierVertex.apply(
  65005. _this$_renderer2,
  65006. args
  65007. );
  65008. } else {
  65009. if (vertices.length === 0) {
  65010. _main.default._friendlyError(
  65011. 'vertex() must be used once before calling bezierVertex()',
  65012. 'bezierVertex'
  65013. );
  65014. } else {
  65015. isBezier = true;
  65016. var vert = [];
  65017. for (var i = 0; i < args.length; i++) {
  65018. vert[i] = args[i];
  65019. }
  65020. vert.isVert = false;
  65021. if (isContour) {
  65022. contourVertices.push(vert);
  65023. } else {
  65024. vertices.push(vert);
  65025. }
  65026. }
  65027. }
  65028. return this;
  65029. };
  65030. /**
  65031. * Specifies vertex coordinates for curves. This function may only
  65032. * be used between <a href="#/p5/beginShape">beginShape()</a> and <a href="#/p5/endShape">endShape()</a> and only when there
  65033. * is no MODE parameter specified to <a href="#/p5/beginShape">beginShape()</a>.
  65034. * For WebGL mode curveVertex() can be used in 2D as well as 3D mode.
  65035. * 2D mode expects 2 parameters, while 3D mode expects 3 parameters.
  65036. *
  65037. * The first and last points in a series of curveVertex() lines will be used to
  65038. * guide the beginning and end of a the curve. A minimum of four
  65039. * points is required to draw a tiny curve between the second and
  65040. * third points. Adding a fifth point with curveVertex() will draw
  65041. * the curve between the second, third, and fourth points. The
  65042. * curveVertex() function is an implementation of Catmull-Rom
  65043. * splines.
  65044. *
  65045. * @method curveVertex
  65046. * @param {Number} x x-coordinate of the vertex
  65047. * @param {Number} y y-coordinate of the vertex
  65048. * @chainable
  65049. * @example
  65050. * <div>
  65051. * <code>
  65052. * strokeWeight(5);
  65053. * point(84, 91);
  65054. * point(68, 19);
  65055. * point(21, 17);
  65056. * point(32, 91);
  65057. * strokeWeight(1);
  65058. *
  65059. * noFill();
  65060. * beginShape();
  65061. * curveVertex(84, 91);
  65062. * curveVertex(84, 91);
  65063. * curveVertex(68, 19);
  65064. * curveVertex(21, 17);
  65065. * curveVertex(32, 91);
  65066. * curveVertex(32, 91);
  65067. * endShape();
  65068. * </code>
  65069. * </div>
  65070. *
  65071. * @alt
  65072. * Upside-down u-shape line, mid canvas. left point extends beyond canvas view.
  65073. */
  65074. /**
  65075. * @method curveVertex
  65076. * @param {Number} x
  65077. * @param {Number} y
  65078. * @param {Number} [z] z-coordinate of the vertex (for WebGL mode)
  65079. * @chainable
  65080. * @example
  65081. * <div>
  65082. * <code>
  65083. * function setup() {
  65084. * createCanvas(100, 100, WEBGL);
  65085. * setAttributes('antialias', true);
  65086. * }
  65087. * function draw() {
  65088. * orbitControl();
  65089. * background(50);
  65090. * strokeWeight(4);
  65091. * stroke(255);
  65092. *
  65093. * point(-25, 25);
  65094. * point(-25, 25);
  65095. * point(-25, -25);
  65096. * point(25, -25);
  65097. * point(25, 25);
  65098. * point(25, 25);
  65099. *
  65100. * strokeWeight(1);
  65101. * noFill();
  65102. *
  65103. * beginShape();
  65104. * curveVertex(-25, 25);
  65105. * curveVertex(-25, 25);
  65106. * curveVertex(-25, -25);
  65107. * curveVertex(25, -25);
  65108. * curveVertex(25, 25);
  65109. * curveVertex(25, 25);
  65110. * endShape();
  65111. *
  65112. * beginShape();
  65113. * curveVertex(-25, 25, 20);
  65114. * curveVertex(-25, 25, 20);
  65115. * curveVertex(-25, -25, 20);
  65116. * curveVertex(25, -25, 20);
  65117. * curveVertex(25, 25, 20);
  65118. * curveVertex(25, 25, 20);
  65119. * endShape();
  65120. * }
  65121. * </code>
  65122. * </div>
  65123. *
  65124. * @alt
  65125. * Upside-down u-shape line, mid canvas with the same shape in positive z-axis.
  65126. */
  65127. _main.default.prototype.curveVertex = function() {
  65128. for (
  65129. var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
  65130. _key2 < _len2;
  65131. _key2++
  65132. ) {
  65133. args[_key2] = arguments[_key2];
  65134. }
  65135. _main.default._validateParameters('curveVertex', args);
  65136. if (this._renderer.isP3D) {
  65137. var _this$_renderer3;
  65138. (_this$_renderer3 = this._renderer).curveVertex.apply(_this$_renderer3, args);
  65139. } else {
  65140. isCurve = true;
  65141. this.vertex(args[0], args[1]);
  65142. }
  65143. return this;
  65144. };
  65145. /**
  65146. * Use the <a href="#/p5/beginContour">beginContour()</a> and <a href="#/p5/endContour">endContour()</a> functions to create negative
  65147. * shapes within shapes such as the center of the letter 'O'. <a href="#/p5/beginContour">beginContour()</a>
  65148. * begins recording vertices for the shape and <a href="#/p5/endContour">endContour()</a> stops recording.
  65149. * The vertices that define a negative shape must "wind" in the opposite
  65150. * direction from the exterior shape. First draw vertices for the exterior
  65151. * clockwise order, then for internal shapes, draw vertices
  65152. * shape in counter-clockwise.
  65153. *
  65154. * These functions can only be used within a <a href="#/p5/beginShape">beginShape()</a>/<a href="#/p5/endShape">endShape()</a> pair and
  65155. * transformations such as <a href="#/p5/translate">translate()</a>, <a href="#/p5/rotate">rotate()</a>, and <a href="#/p5/scale">scale()</a> do not work
  65156. * within a <a href="#/p5/beginContour">beginContour()</a>/<a href="#/p5/endContour">endContour()</a> pair. It is also not possible to use
  65157. * other shapes, such as <a href="#/p5/ellipse">ellipse()</a> or <a href="#/p5/rect">rect()</a> within.
  65158. *
  65159. * @method endContour
  65160. * @chainable
  65161. * @example
  65162. * <div>
  65163. * <code>
  65164. * translate(50, 50);
  65165. * stroke(255, 0, 0);
  65166. * beginShape();
  65167. * // Exterior part of shape, clockwise winding
  65168. * vertex(-40, -40);
  65169. * vertex(40, -40);
  65170. * vertex(40, 40);
  65171. * vertex(-40, 40);
  65172. * // Interior part of shape, counter-clockwise winding
  65173. * beginContour();
  65174. * vertex(-20, -20);
  65175. * vertex(-20, 20);
  65176. * vertex(20, 20);
  65177. * vertex(20, -20);
  65178. * endContour();
  65179. * endShape(CLOSE);
  65180. * </code>
  65181. * </div>
  65182. *
  65183. * @alt
  65184. * white rect and smaller grey rect with red outlines in center of canvas.
  65185. */
  65186. _main.default.prototype.endContour = function() {
  65187. var vert = contourVertices[0].slice(); // copy all data
  65188. vert.isVert = contourVertices[0].isVert;
  65189. vert.moveTo = false;
  65190. contourVertices.push(vert);
  65191. // prevent stray lines with multiple contours
  65192. if (isFirstContour) {
  65193. vertices.push(vertices[0]);
  65194. isFirstContour = false;
  65195. }
  65196. for (var i = 0; i < contourVertices.length; i++) {
  65197. vertices.push(contourVertices[i]);
  65198. }
  65199. return this;
  65200. };
  65201. /**
  65202. * The <a href="#/p5/endShape">endShape()</a> function is the companion to <a href="#/p5/beginShape">beginShape()</a> and may only be
  65203. * called after <a href="#/p5/beginShape">beginShape()</a>. When <a href="#/p5/endshape">endShape()</a> is called, all of image data
  65204. * defined since the previous call to <a href="#/p5/beginShape">beginShape()</a> is written into the image
  65205. * buffer. The constant CLOSE as the value for the MODE parameter to close
  65206. * the shape (to connect the beginning and the end).
  65207. *
  65208. * @method endShape
  65209. * @param {Constant} [mode] use CLOSE to close the shape
  65210. * @chainable
  65211. * @example
  65212. * <div>
  65213. * <code>
  65214. * noFill();
  65215. *
  65216. * beginShape();
  65217. * vertex(20, 20);
  65218. * vertex(45, 20);
  65219. * vertex(45, 80);
  65220. * endShape(CLOSE);
  65221. *
  65222. * beginShape();
  65223. * vertex(50, 20);
  65224. * vertex(75, 20);
  65225. * vertex(75, 80);
  65226. * endShape();
  65227. * </code>
  65228. * </div>
  65229. *
  65230. * @alt
  65231. * Triangle line shape with smallest interior angle on bottom and upside-down L.
  65232. */
  65233. _main.default.prototype.endShape = function(mode) {
  65234. _main.default._validateParameters('endShape', arguments);
  65235. if (this._renderer.isP3D) {
  65236. this._renderer.endShape(
  65237. mode,
  65238. isCurve,
  65239. isBezier,
  65240. isQuadratic,
  65241. isContour,
  65242. shapeKind
  65243. );
  65244. } else {
  65245. if (vertices.length === 0) {
  65246. return this;
  65247. }
  65248. if (!this._renderer._doStroke && !this._renderer._doFill) {
  65249. return this;
  65250. }
  65251. var closeShape = mode === constants.CLOSE;
  65252. // if the shape is closed, the first element is also the last element
  65253. if (closeShape && !isContour) {
  65254. vertices.push(vertices[0]);
  65255. }
  65256. this._renderer.endShape(
  65257. mode,
  65258. vertices,
  65259. isCurve,
  65260. isBezier,
  65261. isQuadratic,
  65262. isContour,
  65263. shapeKind
  65264. );
  65265. // Reset some settings
  65266. isCurve = false;
  65267. isBezier = false;
  65268. isQuadratic = false;
  65269. isContour = false;
  65270. isFirstContour = true;
  65271. // If the shape is closed, the first element was added as last element.
  65272. // We must remove it again to prevent the list of vertices from growing
  65273. // over successive calls to endShape(CLOSE)
  65274. if (closeShape) {
  65275. vertices.pop();
  65276. }
  65277. }
  65278. return this;
  65279. };
  65280. /**
  65281. * Specifies vertex coordinates for quadratic Bezier curves. Each call to
  65282. * quadraticVertex() defines the position of one control points and one
  65283. * anchor point of a Bezier curve, adding a new segment to a line or shape.
  65284. * The first time quadraticVertex() is used within a <a href="#/p5/beginShape">beginShape()</a> call, it
  65285. * must be prefaced with a call to <a href="#/p5/vertex">vertex()</a> to set the first anchor point.
  65286. * For WebGL mode quadraticVertex() can be used in 2D as well as 3D mode.
  65287. * 2D mode expects 4 parameters, while 3D mode expects 6 parameters
  65288. * (including z coordinates).
  65289. *
  65290. * This function must be used between <a href="#/p5/beginShape">beginShape()</a> and <a href="#/p5/endShape">endShape()</a>
  65291. * and only when there is no MODE or POINTS parameter specified to
  65292. * <a href="#/p5/beginShape">beginShape()</a>.
  65293. *
  65294. * @method quadraticVertex
  65295. * @param {Number} cx x-coordinate for the control point
  65296. * @param {Number} cy y-coordinate for the control point
  65297. * @param {Number} x3 x-coordinate for the anchor point
  65298. * @param {Number} y3 y-coordinate for the anchor point
  65299. * @chainable
  65300. *
  65301. * @example
  65302. * <div>
  65303. * <code>
  65304. * strokeWeight(5);
  65305. * point(20, 20);
  65306. * point(80, 20);
  65307. * point(50, 50);
  65308. *
  65309. * noFill();
  65310. * strokeWeight(1);
  65311. * beginShape();
  65312. * vertex(20, 20);
  65313. * quadraticVertex(80, 20, 50, 50);
  65314. * endShape();
  65315. * </code>
  65316. * </div>
  65317. *
  65318. * <div>
  65319. * <code>
  65320. * strokeWeight(5);
  65321. * point(20, 20);
  65322. * point(80, 20);
  65323. * point(50, 50);
  65324. *
  65325. * point(20, 80);
  65326. * point(80, 80);
  65327. * point(80, 60);
  65328. *
  65329. * noFill();
  65330. * strokeWeight(1);
  65331. * beginShape();
  65332. * vertex(20, 20);
  65333. * quadraticVertex(80, 20, 50, 50);
  65334. * quadraticVertex(20, 80, 80, 80);
  65335. * vertex(80, 60);
  65336. * endShape();
  65337. * </code>
  65338. * </div>
  65339. *
  65340. * @alt
  65341. * arched-shaped black line with 4 pixel thick stroke weight.
  65342. * backwards s-shaped black line with 4 pixel thick stroke weight.
  65343. */
  65344. /**
  65345. * @method quadraticVertex
  65346. * @param {Number} cx
  65347. * @param {Number} cy
  65348. * @param {Number} cz z-coordinate for the control point (for WebGL mode)
  65349. * @param {Number} x3
  65350. * @param {Number} y3
  65351. * @param {Number} z3 z-coordinate for the anchor point (for WebGL mode)
  65352. * @chainable
  65353. *
  65354. * @example
  65355. * <div>
  65356. * <code>
  65357. * function setup() {
  65358. * createCanvas(100, 100, WEBGL);
  65359. * setAttributes('antialias', true);
  65360. * }
  65361. * function draw() {
  65362. * orbitControl();
  65363. * background(50);
  65364. * strokeWeight(4);
  65365. * stroke(255);
  65366. *
  65367. * point(-35, -35);
  65368. * point(35, -35);
  65369. * point(0, 0);
  65370. * point(-35, 35);
  65371. * point(35, 35);
  65372. * point(35, 10);
  65373. *
  65374. * strokeWeight(1);
  65375. * noFill();
  65376. *
  65377. * beginShape();
  65378. * vertex(-35, -35);
  65379. * quadraticVertex(35, -35, 0, 0);
  65380. * quadraticVertex(-35, 35, 35, 35);
  65381. * vertex(35, 10);
  65382. * endShape();
  65383. *
  65384. * beginShape();
  65385. * vertex(-35, -35, 20);
  65386. * quadraticVertex(35, -35, 20, 0, 0, 20);
  65387. * quadraticVertex(-35, 35, 20, 35, 35, 20);
  65388. * vertex(35, 10, 20);
  65389. * endShape();
  65390. * }
  65391. * </code>
  65392. * </div>
  65393. *
  65394. * @alt
  65395. * backwards s-shaped black line with the same s-shaped line in postive z-axis.
  65396. */
  65397. _main.default.prototype.quadraticVertex = function() {
  65398. for (
  65399. var _len3 = arguments.length, args = new Array(_len3), _key3 = 0;
  65400. _key3 < _len3;
  65401. _key3++
  65402. ) {
  65403. args[_key3] = arguments[_key3];
  65404. }
  65405. _main.default._validateParameters('quadraticVertex', args);
  65406. if (this._renderer.isP3D) {
  65407. var _this$_renderer4;
  65408. (_this$_renderer4 = this._renderer).quadraticVertex.apply(
  65409. _this$_renderer4,
  65410. args
  65411. );
  65412. } else {
  65413. //if we're drawing a contour, put the points into an
  65414. // array for inside drawing
  65415. if (this._contourInited) {
  65416. var pt = {};
  65417. pt.x = args[0];
  65418. pt.y = args[1];
  65419. pt.x3 = args[2];
  65420. pt.y3 = args[3];
  65421. pt.type = constants.QUADRATIC;
  65422. this._contourVertices.push(pt);
  65423. return this;
  65424. }
  65425. if (vertices.length > 0) {
  65426. isQuadratic = true;
  65427. var vert = [];
  65428. for (var i = 0; i < args.length; i++) {
  65429. vert[i] = args[i];
  65430. }
  65431. vert.isVert = false;
  65432. if (isContour) {
  65433. contourVertices.push(vert);
  65434. } else {
  65435. vertices.push(vert);
  65436. }
  65437. } else {
  65438. _main.default._friendlyError(
  65439. 'vertex() must be used once before calling quadraticVertex()',
  65440. 'quadraticVertex'
  65441. );
  65442. }
  65443. }
  65444. return this;
  65445. };
  65446. /**
  65447. * All shapes are constructed by connecting a series of vertices. <a href="#/p5/vertex">vertex()</a>
  65448. * is used to specify the vertex coordinates for points, lines, triangles,
  65449. * quads, and polygons. It is used exclusively within the <a href="#/p5/beginShape">beginShape()</a> and
  65450. * <a href="#/p5/endShape">endShape()</a> functions.
  65451. *
  65452. * @method vertex
  65453. * @param {Number} x x-coordinate of the vertex
  65454. * @param {Number} y y-coordinate of the vertex
  65455. * @chainable
  65456. * @example
  65457. * <div>
  65458. * <code>
  65459. * strokeWeight(3);
  65460. * beginShape(POINTS);
  65461. * vertex(30, 20);
  65462. * vertex(85, 20);
  65463. * vertex(85, 75);
  65464. * vertex(30, 75);
  65465. * endShape();
  65466. * </code>
  65467. * </div>
  65468. *
  65469. * <div>
  65470. * <code>
  65471. * createCanvas(100, 100, WEBGL);
  65472. * background(240, 240, 240);
  65473. * fill(237, 34, 93);
  65474. * noStroke();
  65475. * beginShape();
  65476. * vertex(0, 35);
  65477. * vertex(35, 0);
  65478. * vertex(0, -35);
  65479. * vertex(-35, 0);
  65480. * endShape();
  65481. * </code>
  65482. * </div>
  65483. *
  65484. * <div>
  65485. * <code>
  65486. * createCanvas(100, 100, WEBGL);
  65487. * background(240, 240, 240);
  65488. * fill(237, 34, 93);
  65489. * noStroke();
  65490. * beginShape();
  65491. * vertex(-10, 10);
  65492. * vertex(0, 35);
  65493. * vertex(10, 10);
  65494. * vertex(35, 0);
  65495. * vertex(10, -8);
  65496. * vertex(0, -35);
  65497. * vertex(-10, -8);
  65498. * vertex(-35, 0);
  65499. * endShape();
  65500. * </code>
  65501. * </div>
  65502. *
  65503. * <div>
  65504. * <code>
  65505. * strokeWeight(3);
  65506. * stroke(237, 34, 93);
  65507. * beginShape(LINES);
  65508. * vertex(10, 35);
  65509. * vertex(90, 35);
  65510. * vertex(10, 65);
  65511. * vertex(90, 65);
  65512. * vertex(35, 10);
  65513. * vertex(35, 90);
  65514. * vertex(65, 10);
  65515. * vertex(65, 90);
  65516. * endShape();
  65517. * </code>
  65518. * </div>
  65519. *
  65520. * <div>
  65521. * <code>
  65522. * // Click to change the number of sides.
  65523. * // In WebGL mode, custom shapes will only
  65524. * // display hollow fill sections when
  65525. * // all calls to vertex() use the same z-value.
  65526. *
  65527. * let sides = 3;
  65528. * let angle, px, py;
  65529. *
  65530. * function setup() {
  65531. * createCanvas(100, 100, WEBGL);
  65532. * setAttributes('antialias', true);
  65533. * fill(237, 34, 93);
  65534. * strokeWeight(3);
  65535. * }
  65536. *
  65537. * function draw() {
  65538. * background(200);
  65539. * rotateX(frameCount * 0.01);
  65540. * rotateZ(frameCount * 0.01);
  65541. * ngon(sides, 0, 0, 80);
  65542. * }
  65543. *
  65544. * function mouseClicked() {
  65545. * if (sides > 6) {
  65546. * sides = 3;
  65547. * } else {
  65548. * sides++;
  65549. * }
  65550. * }
  65551. *
  65552. * function ngon(n, x, y, d) {
  65553. * beginShape(TESS);
  65554. * for (let i = 0; i < n + 1; i++) {
  65555. * angle = TWO_PI / n * i;
  65556. * px = x + sin(angle) * d / 2;
  65557. * py = y - cos(angle) * d / 2;
  65558. * vertex(px, py, 0);
  65559. * }
  65560. * for (let i = 0; i < n + 1; i++) {
  65561. * angle = TWO_PI / n * i;
  65562. * px = x + sin(angle) * d / 4;
  65563. * py = y - cos(angle) * d / 4;
  65564. * vertex(px, py, 0);
  65565. * }
  65566. * endShape();
  65567. * }
  65568. * </code>
  65569. * </div>
  65570. * @alt
  65571. * 4 black points in a square shape in middle-right of canvas.
  65572. * 4 points making a diamond shape.
  65573. * 8 points making a star.
  65574. * 8 points making 4 lines.
  65575. * A rotating 3D shape with a hollow section in the middle.
  65576. */
  65577. /**
  65578. * @method vertex
  65579. * @param {Number} x
  65580. * @param {Number} y
  65581. * @param {Number} z z-coordinate of the vertex.
  65582. * Defaults to 0 if not specified.
  65583. * @chainable
  65584. */
  65585. /**
  65586. * @method vertex
  65587. * @param {Number} x
  65588. * @param {Number} y
  65589. * @param {Number} [z]
  65590. * @param {Number} u the vertex's texture u-coordinate
  65591. * @param {Number} v the vertex's texture v-coordinate
  65592. * @chainable
  65593. */
  65594. _main.default.prototype.vertex = function(x, y, moveTo, u, v) {
  65595. if (this._renderer.isP3D) {
  65596. var _this$_renderer5;
  65597. (_this$_renderer5 = this._renderer).vertex.apply(_this$_renderer5, arguments);
  65598. } else {
  65599. var vert = [];
  65600. vert.isVert = true;
  65601. vert[0] = x;
  65602. vert[1] = y;
  65603. vert[2] = 0;
  65604. vert[3] = 0;
  65605. vert[4] = 0;
  65606. vert[5] = this._renderer._getFill();
  65607. vert[6] = this._renderer._getStroke();
  65608. if (moveTo) {
  65609. vert.moveTo = moveTo;
  65610. }
  65611. if (isContour) {
  65612. if (contourVertices.length === 0) {
  65613. vert.moveTo = true;
  65614. }
  65615. contourVertices.push(vert);
  65616. } else {
  65617. vertices.push(vert);
  65618. }
  65619. }
  65620. return this;
  65621. };
  65622. /**
  65623. * Sets the 3d vertex normal to use for subsequent vertices drawn with
  65624. * <a href="#/p5/vertex">vertex()</a>. A normal is a vector that is generally
  65625. * nearly perpendicular to a shape's surface which controls how much light will
  65626. * be reflected from that part of the surface.
  65627. *
  65628. * @method normal
  65629. * @param {Vector} vector A p5.Vector representing the vertex normal.
  65630. * @chainable
  65631. * @example
  65632. * <div>
  65633. * <code>
  65634. * function setup() {
  65635. * createCanvas(100, 100, WEBGL);
  65636. * noStroke();
  65637. * }
  65638. *
  65639. * function draw() {
  65640. * background(255);
  65641. * rotateY(frameCount / 100);
  65642. * normalMaterial();
  65643. * beginShape(TRIANGLE_STRIP);
  65644. * normal(-0.4, 0.4, 0.8);
  65645. * vertex(-30, 30, 0);
  65646. *
  65647. * normal(0, 0, 1);
  65648. * vertex(-30, -30, 30);
  65649. * vertex(30, 30, 30);
  65650. *
  65651. * normal(0.4, -0.4, 0.8);
  65652. * vertex(30, -30, 0);
  65653. * endShape();
  65654. * }
  65655. * </code>
  65656. * </div>
  65657. */
  65658. /**
  65659. * @method normal
  65660. * @param {Number} x The x component of the vertex normal.
  65661. * @param {Number} y The y component of the vertex normal.
  65662. * @param {Number} z The z component of the vertex normal.
  65663. * @chainable
  65664. */
  65665. _main.default.prototype.normal = function(x, y, z) {
  65666. var _this$_renderer6;
  65667. this._assert3d('normal');
  65668. _main.default._validateParameters('normal', arguments);
  65669. (_this$_renderer6 = this._renderer).normal.apply(_this$_renderer6, arguments);
  65670. return this;
  65671. };
  65672. var _default = _main.default;
  65673. exports.default = _default;
  65674. },
  65675. { '../constants': 272, '../main': 283, 'core-js/modules/es.array.slice': 178 }
  65676. ],
  65677. 294: [
  65678. function(_dereq_, module, exports) {
  65679. 'use strict';
  65680. _dereq_('core-js/modules/es.symbol');
  65681. _dereq_('core-js/modules/es.symbol.description');
  65682. _dereq_('core-js/modules/es.symbol.iterator');
  65683. _dereq_('core-js/modules/es.array.filter');
  65684. _dereq_('core-js/modules/es.array.iterator');
  65685. _dereq_('core-js/modules/es.array.slice');
  65686. _dereq_('core-js/modules/es.object.assign');
  65687. _dereq_('core-js/modules/es.object.keys');
  65688. _dereq_('core-js/modules/es.object.to-string');
  65689. _dereq_('core-js/modules/es.string.iterator');
  65690. _dereq_('core-js/modules/es.typed-array.uint8-clamped-array');
  65691. _dereq_('core-js/modules/es.typed-array.copy-within');
  65692. _dereq_('core-js/modules/es.typed-array.every');
  65693. _dereq_('core-js/modules/es.typed-array.fill');
  65694. _dereq_('core-js/modules/es.typed-array.filter');
  65695. _dereq_('core-js/modules/es.typed-array.find');
  65696. _dereq_('core-js/modules/es.typed-array.find-index');
  65697. _dereq_('core-js/modules/es.typed-array.for-each');
  65698. _dereq_('core-js/modules/es.typed-array.includes');
  65699. _dereq_('core-js/modules/es.typed-array.index-of');
  65700. _dereq_('core-js/modules/es.typed-array.iterator');
  65701. _dereq_('core-js/modules/es.typed-array.join');
  65702. _dereq_('core-js/modules/es.typed-array.last-index-of');
  65703. _dereq_('core-js/modules/es.typed-array.map');
  65704. _dereq_('core-js/modules/es.typed-array.reduce');
  65705. _dereq_('core-js/modules/es.typed-array.reduce-right');
  65706. _dereq_('core-js/modules/es.typed-array.reverse');
  65707. _dereq_('core-js/modules/es.typed-array.set');
  65708. _dereq_('core-js/modules/es.typed-array.slice');
  65709. _dereq_('core-js/modules/es.typed-array.some');
  65710. _dereq_('core-js/modules/es.typed-array.sort');
  65711. _dereq_('core-js/modules/es.typed-array.subarray');
  65712. _dereq_('core-js/modules/es.typed-array.to-locale-string');
  65713. _dereq_('core-js/modules/es.typed-array.to-string');
  65714. _dereq_('core-js/modules/web.dom-collections.iterator');
  65715. function _typeof(obj) {
  65716. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  65717. _typeof = function _typeof(obj) {
  65718. return typeof obj;
  65719. };
  65720. } else {
  65721. _typeof = function _typeof(obj) {
  65722. return obj &&
  65723. typeof Symbol === 'function' &&
  65724. obj.constructor === Symbol &&
  65725. obj !== Symbol.prototype
  65726. ? 'symbol'
  65727. : typeof obj;
  65728. };
  65729. }
  65730. return _typeof(obj);
  65731. } // requestAnim shim layer by Paul Irish
  65732. // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
  65733. // http://my.opera.com/emoller/blog/2011/12/20/
  65734. // requestanimationframe-for-smart-er-animating
  65735. // requestAnimationFrame polyfill by Erik Möller
  65736. // fixes from Paul Irish and Tino Zijdel
  65737. window.requestAnimationFrame = (function() {
  65738. return (
  65739. window.requestAnimationFrame ||
  65740. window.webkitRequestAnimationFrame ||
  65741. window.mozRequestAnimationFrame ||
  65742. window.oRequestAnimationFrame ||
  65743. window.msRequestAnimationFrame ||
  65744. function(callback, element) {
  65745. // should '60' here be framerate?
  65746. window.setTimeout(callback, 1000 / 60);
  65747. }
  65748. );
  65749. })();
  65750. /**
  65751. * shim for Uint8ClampedArray.slice
  65752. * (allows arrayCopy to work with pixels[])
  65753. * with thanks to http://halfpapstudios.com/blog/tag/html5-canvas/
  65754. * Enumerable set to false to protect for...in from
  65755. * Uint8ClampedArray.prototype pollution.
  65756. */
  65757. (function() {
  65758. if (
  65759. typeof Uint8ClampedArray !== 'undefined' &&
  65760. !Uint8ClampedArray.prototype.slice
  65761. ) {
  65762. Object.defineProperty(Uint8ClampedArray.prototype, 'slice', {
  65763. value: Array.prototype.slice,
  65764. writable: true,
  65765. configurable: true,
  65766. enumerable: false
  65767. });
  65768. }
  65769. })();
  65770. /**
  65771. * this is implementation of Object.assign() which is unavailable in
  65772. * IE11 and (non-Chrome) Android browsers.
  65773. * The assign() method is used to copy the values of all enumerable
  65774. * own properties from one or more source objects to a target object.
  65775. * It will return the target object.
  65776. * Modified from https://github.com/ljharb/object.assign
  65777. */
  65778. (function() {
  65779. if (!Object.assign) {
  65780. var keys = Object.keys;
  65781. var defineProperty = Object.defineProperty;
  65782. var canBeObject = function canBeObject(obj) {
  65783. return typeof obj !== 'undefined' && obj !== null;
  65784. };
  65785. var hasSymbols =
  65786. typeof Symbol === 'function' && _typeof(Symbol()) === 'symbol';
  65787. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  65788. var isEnumerableOn = function isEnumerableOn(obj) {
  65789. return function isEnumerable(prop) {
  65790. return propIsEnumerable.call(obj, prop);
  65791. };
  65792. };
  65793. // per ES6 spec, this function has to have a length of 2
  65794. var assignShim = function assign(target, source1) {
  65795. if (!canBeObject(target)) {
  65796. throw new TypeError('target must be an object');
  65797. }
  65798. var objTarget = Object(target);
  65799. var s, source, i, props;
  65800. for (s = 1; s < arguments.length; ++s) {
  65801. source = Object(arguments[s]);
  65802. props = keys(source);
  65803. if (hasSymbols && Object.getOwnPropertySymbols) {
  65804. props.push.apply(
  65805. props,
  65806. Object.getOwnPropertySymbols(source).filter(isEnumerableOn(source))
  65807. );
  65808. }
  65809. for (i = 0; i < props.length; ++i) {
  65810. objTarget[props[i]] = source[props[i]];
  65811. }
  65812. }
  65813. return objTarget;
  65814. };
  65815. defineProperty(Object, 'assign', {
  65816. value: assignShim,
  65817. configurable: true,
  65818. enumerable: false,
  65819. writable: true
  65820. });
  65821. }
  65822. })();
  65823. },
  65824. {
  65825. 'core-js/modules/es.array.filter': 169,
  65826. 'core-js/modules/es.array.iterator': 174,
  65827. 'core-js/modules/es.array.slice': 178,
  65828. 'core-js/modules/es.object.assign': 188,
  65829. 'core-js/modules/es.object.keys': 191,
  65830. 'core-js/modules/es.object.to-string': 192,
  65831. 'core-js/modules/es.string.iterator': 201,
  65832. 'core-js/modules/es.symbol': 211,
  65833. 'core-js/modules/es.symbol.description': 209,
  65834. 'core-js/modules/es.symbol.iterator': 210,
  65835. 'core-js/modules/es.typed-array.copy-within': 212,
  65836. 'core-js/modules/es.typed-array.every': 213,
  65837. 'core-js/modules/es.typed-array.fill': 214,
  65838. 'core-js/modules/es.typed-array.filter': 215,
  65839. 'core-js/modules/es.typed-array.find': 217,
  65840. 'core-js/modules/es.typed-array.find-index': 216,
  65841. 'core-js/modules/es.typed-array.for-each': 220,
  65842. 'core-js/modules/es.typed-array.includes': 221,
  65843. 'core-js/modules/es.typed-array.index-of': 222,
  65844. 'core-js/modules/es.typed-array.iterator': 225,
  65845. 'core-js/modules/es.typed-array.join': 226,
  65846. 'core-js/modules/es.typed-array.last-index-of': 227,
  65847. 'core-js/modules/es.typed-array.map': 228,
  65848. 'core-js/modules/es.typed-array.reduce': 230,
  65849. 'core-js/modules/es.typed-array.reduce-right': 229,
  65850. 'core-js/modules/es.typed-array.reverse': 231,
  65851. 'core-js/modules/es.typed-array.set': 232,
  65852. 'core-js/modules/es.typed-array.slice': 233,
  65853. 'core-js/modules/es.typed-array.some': 234,
  65854. 'core-js/modules/es.typed-array.sort': 235,
  65855. 'core-js/modules/es.typed-array.subarray': 236,
  65856. 'core-js/modules/es.typed-array.to-locale-string': 237,
  65857. 'core-js/modules/es.typed-array.to-string': 238,
  65858. 'core-js/modules/es.typed-array.uint8-clamped-array': 242,
  65859. 'core-js/modules/web.dom-collections.iterator': 244
  65860. }
  65861. ],
  65862. 295: [
  65863. function(_dereq_, module, exports) {
  65864. 'use strict';
  65865. _dereq_('core-js/modules/es.array.for-each');
  65866. _dereq_('core-js/modules/es.object.assign');
  65867. _dereq_('core-js/modules/web.dom-collections.for-each');
  65868. Object.defineProperty(exports, '__esModule', { value: true });
  65869. exports.default = void 0;
  65870. var _main = _interopRequireDefault(_dereq_('./main'));
  65871. function _interopRequireDefault(obj) {
  65872. return obj && obj.__esModule ? obj : { default: obj };
  65873. }
  65874. /**
  65875. * @module Structure
  65876. * @submodule Structure
  65877. * @for p5
  65878. * @requires core
  65879. */ /**
  65880. * Stops p5.js from continuously executing the code within <a href="#/p5/draw">draw()</a>.
  65881. * If <a href="#/p5/loop">loop()</a> is called, the code in <a href="#/p5/draw">draw()</a>
  65882. * begins to run continuously again. If using <a href="#/p5/noLoop">noLoop()</a>
  65883. * in <a href="#/p5/setup">setup()</a>, it should be the last line inside the block.
  65884. *
  65885. * When <a href="#/p5/noLoop">noLoop()</a> is used, it's not possible to manipulate
  65886. * or access the screen inside event handling functions such as
  65887. * <a href="#/p5/mousePressed">mousePressed()</a> or
  65888. * <a href="#/p5/keyPressed">keyPressed()</a>. Instead, use those functions to
  65889. * call <a href="#/p5/redraw">redraw()</a> or <a href="#/p5/loop">loop()</a>,
  65890. * which will run <a href="#/p5/draw">draw()</a>, which can update the screen
  65891. * properly. This means that when <a href="#/p5/noLoop">noLoop()</a> has been
  65892. * called, no drawing can happen, and functions like <a href="#/p5/saveFrames">saveFrames()</a>
  65893. * or <a href="#/p5/loadPixels">loadPixels()</a> may not be used.
  65894. *
  65895. * Note that if the sketch is resized, <a href="#/p5/redraw">redraw()</a> will
  65896. * be called to update the sketch, even after <a href="#/p5/noLoop">noLoop()</a>
  65897. * has been specified. Otherwise, the sketch would enter an odd state until
  65898. * <a href="#/p5/loop">loop()</a> was called.
  65899. *
  65900. * Use <a href="#/p5/isLooping">isLooping()</a> to check current state of loop().
  65901. *
  65902. * @method noLoop
  65903. * @example
  65904. * <div>
  65905. * <code>
  65906. * function setup() {
  65907. * createCanvas(100, 100);
  65908. * background(200);
  65909. * noLoop();
  65910. * }
  65911. * function draw() {
  65912. * line(10, 10, 90, 90);
  65913. * }
  65914. * </code>
  65915. * </div>
  65916. *
  65917. * <div>
  65918. * <code>
  65919. * let x = 0;
  65920. * function setup() {
  65921. * createCanvas(100, 100);
  65922. * }
  65923. *
  65924. * function draw() {
  65925. * background(204);
  65926. * x = x + 0.1;
  65927. * if (x > width) {
  65928. * x = 0;
  65929. * }
  65930. * line(x, 0, x, height);
  65931. * }
  65932. *
  65933. * function mousePressed() {
  65934. * noLoop();
  65935. * }
  65936. *
  65937. * function mouseReleased() {
  65938. * loop();
  65939. * }
  65940. * </code>
  65941. * </div>
  65942. *
  65943. * @alt
  65944. * 113 pixel long line extending from top-left to bottom right of canvas.
  65945. * horizontal line moves slowly from left. Loops but stops on mouse press.
  65946. */ _main.default.prototype.noLoop = function() {
  65947. this._loop = false;
  65948. };
  65949. /**
  65950. * By default, p5.js loops through draw() continuously, executing the code within
  65951. * it. However, the <a href="#/p5/draw">draw()</a> loop may be stopped by calling
  65952. * <a href="#/p5/noLoop">noLoop()</a>. In that case, the <a href="#/p5/draw">draw()</a>
  65953. * loop can be resumed with loop().
  65954. *
  65955. * Avoid calling loop() from inside setup().
  65956. *
  65957. * Use <a href="#/p5/isLooping">isLooping()</a> to check current state of loop().
  65958. *
  65959. * @method loop
  65960. * @example
  65961. * <div>
  65962. * <code>
  65963. * let x = 0;
  65964. * function setup() {
  65965. * createCanvas(100, 100);
  65966. * noLoop();
  65967. * }
  65968. *
  65969. * function draw() {
  65970. * background(204);
  65971. * x = x + 0.1;
  65972. * if (x > width) {
  65973. * x = 0;
  65974. * }
  65975. * line(x, 0, x, height);
  65976. * }
  65977. *
  65978. * function mousePressed() {
  65979. * loop();
  65980. * }
  65981. *
  65982. * function mouseReleased() {
  65983. * noLoop();
  65984. * }
  65985. * </code>
  65986. * </div>
  65987. *
  65988. * @alt
  65989. * horizontal line moves slowly from left. Loops but stops on mouse press.
  65990. */
  65991. _main.default.prototype.loop = function() {
  65992. if (!this._loop) {
  65993. this._loop = true;
  65994. if (this._setupDone) {
  65995. this._draw();
  65996. }
  65997. }
  65998. };
  65999. /**
  66000. * By default, p5.js loops through <a href="#/p5/draw">draw()</a> continuously,
  66001. * executing the code within it. If the sketch is stopped with
  66002. * <a href="#/p5/noLoop">noLoop()</a> or resumed with <a href="#/p5/loop">loop()</a>,
  66003. * isLooping() returns the current state for use within custom event handlers.
  66004. *
  66005. * @method isLooping
  66006. * @example
  66007. * <div>
  66008. * <code>
  66009. * let checkbox, button, colBG, colFill;
  66010. *
  66011. * function setup() {
  66012. * createCanvas(100, 100);
  66013. *
  66014. * button = createButton('Colorize if loop()');
  66015. * button.position(0, 120);
  66016. * button.mousePressed(changeBG);
  66017. *
  66018. * checkbox = createCheckbox('loop()', true);
  66019. * checkbox.changed(checkLoop);
  66020. *
  66021. * colBG = color(0);
  66022. * colFill = color(255);
  66023. * }
  66024. *
  66025. * function changeBG() {
  66026. * if (isLooping()) {
  66027. * colBG = color(random(255), random(255), random(255));
  66028. * colFill = color(random(255), random(255), random(255));
  66029. * }
  66030. * }
  66031. *
  66032. * function checkLoop() {
  66033. * if (this.checked()) {
  66034. * loop();
  66035. * } else {
  66036. * noLoop();
  66037. * }
  66038. * }
  66039. *
  66040. * function draw() {
  66041. * background(colBG);
  66042. * fill(colFill);
  66043. * ellipse(frameCount % width, height / 2, 50);
  66044. * }
  66045. * </code>
  66046. * </div>
  66047. *
  66048. * @alt
  66049. * Ellipse moves slowly from left. Checkbox toggles loop()/noLoop().
  66050. * Button colorizes sketch if isLooping().
  66051. *
  66052. */
  66053. _main.default.prototype.isLooping = function() {
  66054. return this._loop;
  66055. };
  66056. /**
  66057. * The <a href="#/p5/push">push()</a> function saves the current drawing style
  66058. * settings and transformations, while <a href="#/p5/pop">pop()</a> restores these
  66059. * settings. Note that these functions are always used together. They allow you to
  66060. * change the style and transformation settings and later return to what you had.
  66061. * When a new state is started with <a href="#/p5/push">push()</a>, it builds on
  66062. * the current style and transform information. The <a href="#/p5/push">push()</a>
  66063. * and <a href="#/p5/pop">pop()</a> functions can be embedded to provide more
  66064. * control. (See the second example for a demonstration.)
  66065. *
  66066. * <a href="#/p5/push">push()</a> stores information related to the current transformation state
  66067. * and style settings controlled by the following functions:
  66068. * <a href="#/p5/fill">fill()</a>,
  66069. * <a href="#/p5/noFill">noFill()</a>,
  66070. * <a href="#/p5/noStroke">noStroke()</a>,
  66071. * <a href="#/p5/stroke">stroke()</a>,
  66072. * <a href="#/p5/tint">tint()</a>,
  66073. * <a href="#/p5/noTint">noTint()</a>,
  66074. * <a href="#/p5/strokeWeight">strokeWeight()</a>,
  66075. * <a href="#/p5/strokeCap">strokeCap()</a>,
  66076. * <a href="#/p5/strokeJoin">strokeJoin()</a>,
  66077. * <a href="#/p5/imageMode">imageMode()</a>,
  66078. * <a href="#/p5/rectMode">rectMode()</a>,
  66079. * <a href="#/p5/ellipseMode">ellipseMode()</a>,
  66080. * <a href="#/p5/colorMode">colorMode()</a>,
  66081. * <a href="#/p5/textAlign">textAlign()</a>,
  66082. * <a href="#/p5/textFont">textFont()</a>,
  66083. * <a href="#/p5/textSize">textSize()</a>,
  66084. * <a href="#/p5/textLeading">textLeading()</a>,
  66085. * <a href="#/p5/applyMatrix">applyMatrix()</a>,
  66086. * <a href="#/p5/resetMatrix">resetMatrix()</a>,
  66087. * <a href="#/p5/rotate">rotate()</a>,
  66088. * <a href="#/p5/scale">scale()</a>,
  66089. * <a href="#/p5/shearX">shearX()</a>,
  66090. * <a href="#/p5/shearY">shearY()</a>,
  66091. * <a href="#/p5/translate">translate()</a>,
  66092. * <a href="#/p5/noiseSeed">noiseSeed()</a>.
  66093. *
  66094. * In WEBGL mode additional style settings are stored. These are controlled by the
  66095. * following functions: <a href="#/p5/setCamera">setCamera()</a>,
  66096. * <a href="#/p5/ambientLight">ambientLight()</a>,
  66097. * <a href="#/p5/directionalLight">directionalLight()</a>,
  66098. * <a href="#/p5/pointLight">pointLight()</a>, <a href="#/p5/texture">texture()</a>,
  66099. * <a href="#/p5/specularMaterial">specularMaterial()</a>,
  66100. * <a href="#/p5/shininess">shininess()</a>,
  66101. * <a href="#/p5/normalMaterial">normalMaterial()</a>
  66102. * and <a href="#/p5/shader">shader()</a>.
  66103. *
  66104. * @method push
  66105. * @example
  66106. * <div>
  66107. * <code>
  66108. * ellipse(0, 50, 33, 33); // Left circle
  66109. *
  66110. * push(); // Start a new drawing state
  66111. * strokeWeight(10);
  66112. * fill(204, 153, 0);
  66113. * translate(50, 0);
  66114. * ellipse(0, 50, 33, 33); // Middle circle
  66115. * pop(); // Restore original state
  66116. *
  66117. * ellipse(100, 50, 33, 33); // Right circle
  66118. * </code>
  66119. * </div>
  66120. *
  66121. * <div>
  66122. * <code>
  66123. * ellipse(0, 50, 33, 33); // Left circle
  66124. *
  66125. * push(); // Start a new drawing state
  66126. * strokeWeight(10);
  66127. * fill(204, 153, 0);
  66128. * ellipse(33, 50, 33, 33); // Left-middle circle
  66129. *
  66130. * push(); // Start another new drawing state
  66131. * stroke(0, 102, 153);
  66132. * ellipse(66, 50, 33, 33); // Right-middle circle
  66133. * pop(); // Restore previous state
  66134. *
  66135. * pop(); // Restore original state
  66136. *
  66137. * ellipse(100, 50, 33, 33); // Right circle
  66138. * </code>
  66139. * </div>
  66140. *
  66141. * @alt
  66142. * Gold ellipse + thick black outline @center 2 white ellipses on left and right.
  66143. * 2 Gold ellipses left black right blue stroke. 2 white ellipses on left+right.
  66144. */
  66145. _main.default.prototype.push = function() {
  66146. this._styles.push({
  66147. props: {
  66148. _colorMode: this._colorMode
  66149. },
  66150. renderer: this._renderer.push()
  66151. });
  66152. };
  66153. /**
  66154. * The <a href="#/p5/push">push()</a> function saves the current drawing style
  66155. * settings and transformations, while <a href="#/p5/pop">pop()</a> restores
  66156. * these settings. Note that these functions are always used together. They allow
  66157. * you to change the style and transformation settings and later return to what
  66158. * you had. When a new state is started with <a href="#/p5/push">push()</a>, it
  66159. * builds on the current style and transform information. The <a href="#/p5/push">push()</a>
  66160. * and <a href="#/p5/pop">pop()</a> functions can be embedded to provide more
  66161. * control. (See the second example for a demonstration.)
  66162. *
  66163. * <a href="#/p5/push">push()</a> stores information related to the current transformation state
  66164. * and style settings controlled by the following functions:
  66165. * <a href="#/p5/fill">fill()</a>,
  66166. * <a href="#/p5/noFill">noFill()</a>,
  66167. * <a href="#/p5/noStroke">noStroke()</a>,
  66168. * <a href="#/p5/stroke">stroke()</a>,
  66169. * <a href="#/p5/tint">tint()</a>,
  66170. * <a href="#/p5/noTint">noTint()</a>,
  66171. * <a href="#/p5/strokeWeight">strokeWeight()</a>,
  66172. * <a href="#/p5/strokeCap">strokeCap()</a>,
  66173. * <a href="#/p5/strokeJoin">strokeJoin()</a>,
  66174. * <a href="#/p5/imageMode">imageMode()</a>,
  66175. * <a href="#/p5/rectMode">rectMode()</a>,
  66176. * <a href="#/p5/ellipseMode">ellipseMode()</a>,
  66177. * <a href="#/p5/colorMode">colorMode()</a>,
  66178. * <a href="#/p5/textAlign">textAlign()</a>,
  66179. * <a href="#/p5/textFont">textFont()</a>,
  66180. * <a href="#/p5/textSize">textSize()</a>,
  66181. * <a href="#/p5/textLeading">textLeading()</a>,
  66182. * <a href="#/p5/applyMatrix">applyMatrix()</a>,
  66183. * <a href="#/p5/resetMatrix">resetMatrix()</a>,
  66184. * <a href="#/p5/rotate">rotate()</a>,
  66185. * <a href="#/p5/scale">scale()</a>,
  66186. * <a href="#/p5/shearX">shearX()</a>,
  66187. * <a href="#/p5/shearY">shearY()</a>,
  66188. * <a href="#/p5/translate">translate()</a>,
  66189. * <a href="#/p5/noiseSeed">noiseSeed()</a>.
  66190. *
  66191. * In WEBGL mode additional style settings are stored. These are controlled by
  66192. * the following functions:
  66193. * <a href="#/p5/setCamera">setCamera()</a>,
  66194. * <a href="#/p5/ambientLight">ambientLight()</a>,
  66195. * <a href="#/p5/directionalLight">directionalLight()</a>,
  66196. * <a href="#/p5/pointLight">pointLight()</a>,
  66197. * <a href="#/p5/texture">texture()</a>,
  66198. * <a href="#/p5/specularMaterial">specularMaterial()</a>,
  66199. * <a href="#/p5/shininess">shininess()</a>,
  66200. * <a href="#/p5/normalMaterial">normalMaterial()</a> and
  66201. * <a href="#/p5/shader">shader()</a>.
  66202. *
  66203. * @method pop
  66204. * @example
  66205. * <div>
  66206. * <code>
  66207. * ellipse(0, 50, 33, 33); // Left circle
  66208. *
  66209. * push(); // Start a new drawing state
  66210. * translate(50, 0);
  66211. * strokeWeight(10);
  66212. * fill(204, 153, 0);
  66213. * ellipse(0, 50, 33, 33); // Middle circle
  66214. * pop(); // Restore original state
  66215. *
  66216. * ellipse(100, 50, 33, 33); // Right circle
  66217. * </code>
  66218. * </div>
  66219. *
  66220. * <div>
  66221. * <code>
  66222. * ellipse(0, 50, 33, 33); // Left circle
  66223. *
  66224. * push(); // Start a new drawing state
  66225. * strokeWeight(10);
  66226. * fill(204, 153, 0);
  66227. * ellipse(33, 50, 33, 33); // Left-middle circle
  66228. *
  66229. * push(); // Start another new drawing state
  66230. * stroke(0, 102, 153);
  66231. * ellipse(66, 50, 33, 33); // Right-middle circle
  66232. * pop(); // Restore previous state
  66233. *
  66234. * pop(); // Restore original state
  66235. *
  66236. * ellipse(100, 50, 33, 33); // Right circle
  66237. * </code>
  66238. * </div>
  66239. *
  66240. * @alt
  66241. * Gold ellipse + thick black outline @center 2 white ellipses on left and right.
  66242. * 2 Gold ellipses left black right blue stroke. 2 white ellipses on left+right.
  66243. */
  66244. _main.default.prototype.pop = function() {
  66245. var style = this._styles.pop();
  66246. if (style) {
  66247. this._renderer.pop(style.renderer);
  66248. Object.assign(this, style.props);
  66249. } else {
  66250. console.warn('pop() was called without matching push()');
  66251. }
  66252. };
  66253. /**
  66254. * Executes the code within <a href="#/p5/draw">draw()</a> one time. This
  66255. * function allows the program to update the display window only when necessary,
  66256. * for example when an event registered by <a href="#/p5/mousePressed">mousePressed()</a>
  66257. * or <a href="#/p5/keyPressed">keyPressed()</a> occurs.
  66258. *
  66259. * In structuring a program, it only makes sense to call <a href="#/p5/redraw">redraw()</a>
  66260. * within events such as <a href="#/p5/mousePressed">mousePressed()</a>. This
  66261. * is because <a href="#/p5/redraw">redraw()</a> does not run
  66262. * <a href="#/p5/draw">draw()</a> immediately (it only sets a flag that indicates
  66263. * an update is needed).
  66264. *
  66265. * The <a href="#/p5/redraw">redraw()</a> function does not work properly when
  66266. * called inside <a href="#/p5/draw">draw()</a>.To enable/disable animations,
  66267. * use <a href="#/p5/loop">loop()</a> and <a href="#/p5/noLoop">noLoop()</a>.
  66268. *
  66269. * In addition you can set the number of redraws per method call. Just
  66270. * add an integer as single parameter for the number of redraws.
  66271. *
  66272. * @method redraw
  66273. * @param {Integer} [n] Redraw for n-times. The default value is 1.
  66274. * @example
  66275. * <div><code>
  66276. * let x = 0;
  66277. *
  66278. * function setup() {
  66279. * createCanvas(100, 100);
  66280. * noLoop();
  66281. * }
  66282. *
  66283. * function draw() {
  66284. * background(204);
  66285. * line(x, 0, x, height);
  66286. * }
  66287. *
  66288. * function mousePressed() {
  66289. * x += 1;
  66290. * redraw();
  66291. * }
  66292. * </code>
  66293. * </div>
  66294. *
  66295. * <div class='norender'>
  66296. * <code>
  66297. * let x = 0;
  66298. *
  66299. * function setup() {
  66300. * createCanvas(100, 100);
  66301. * noLoop();
  66302. * }
  66303. *
  66304. * function draw() {
  66305. * background(204);
  66306. * x += 1;
  66307. * line(x, 0, x, height);
  66308. * }
  66309. *
  66310. * function mousePressed() {
  66311. * redraw(5);
  66312. * }
  66313. * </code>
  66314. * </div>
  66315. *
  66316. * @alt
  66317. * black line on far left of canvas
  66318. * black line on far left of canvas
  66319. */
  66320. _main.default.prototype.redraw = function(n) {
  66321. if (this._inUserDraw || !this._setupDone) {
  66322. return;
  66323. }
  66324. var numberOfRedraws = parseInt(n);
  66325. if (isNaN(numberOfRedraws) || numberOfRedraws < 1) {
  66326. numberOfRedraws = 1;
  66327. }
  66328. var context = this._isGlobal ? window : this;
  66329. if (typeof context.draw === 'function') {
  66330. if (typeof context.setup === 'undefined') {
  66331. context.scale(context._pixelDensity, context._pixelDensity);
  66332. }
  66333. var callMethod = function callMethod(f) {
  66334. f.call(context);
  66335. };
  66336. for (var idxRedraw = 0; idxRedraw < numberOfRedraws; idxRedraw++) {
  66337. context.resetMatrix();
  66338. if (this._accessibleOutputs.grid || this._accessibleOutputs.text) {
  66339. this._updateAccsOutput();
  66340. }
  66341. if (context._renderer.isP3D) {
  66342. context._renderer._update();
  66343. }
  66344. context._setProperty('frameCount', context.frameCount + 1);
  66345. context._registeredMethods.pre.forEach(callMethod);
  66346. this._inUserDraw = true;
  66347. try {
  66348. context.draw();
  66349. } finally {
  66350. this._inUserDraw = false;
  66351. }
  66352. context._registeredMethods.post.forEach(callMethod);
  66353. }
  66354. }
  66355. };
  66356. /**
  66357. * The `p5()` constructor enables you to activate "instance mode" instead of normal
  66358. * "global mode". This is an advanced topic. A short description and example is
  66359. * included below. Please see
  66360. * <a target="blank" href="https://www.youtube.com/watch?v=Su792jEauZg&feature=youtu.be">
  66361. * Dan Shiffman's Coding Train video tutorial</a> or this
  66362. * <a target="blank" href="https://github.com/processing/p5.js/wiki/p5.js-overview#instantiation--namespace">tutorial page</a>
  66363. * for more info.
  66364. *
  66365. * By default, all p5.js functions are in the global namespace (i.e. bound to the window
  66366. * object), meaning you can call them simply `ellipse()`, `fill()`, etc. However, this
  66367. * might be inconvenient if you are mixing with other JS libraries (synchronously or
  66368. * asynchronously) or writing long programs of your own. p5.js currently supports a
  66369. * way around this problem called "instance mode". In instance mode, all p5 functions
  66370. * are bound up in a single variable instead of polluting your global namespace.
  66371. *
  66372. * Optionally, you can specify a default container for the canvas and any other elements
  66373. * to append to with a second argument. You can give the ID of an element in your html,
  66374. * or an html node itself.
  66375. *
  66376. * Note that creating instances like this also allows you to have more than one p5 sketch on
  66377. * a single web page, as they will each be wrapped up with their own set up variables. Of
  66378. * course, you could also use iframes to have multiple sketches in global mode.
  66379. *
  66380. * @method p5
  66381. * @param {Object} sketch a function containing a p5.js sketch
  66382. * @param {String|Object} node ID or pointer to HTML DOM node to contain sketch in
  66383. * @example
  66384. * <div class='norender'><code>
  66385. * const s = p => {
  66386. * let x = 100;
  66387. * let y = 100;
  66388. *
  66389. * p.setup = function() {
  66390. * p.createCanvas(700, 410);
  66391. * };
  66392. *
  66393. * p.draw = function() {
  66394. * p.background(0);
  66395. * p.fill(255);
  66396. * p.rect(x, y, 50, 50);
  66397. * };
  66398. * };
  66399. *
  66400. * new p5(s); // invoke p5
  66401. * </code></div>
  66402. *
  66403. * @alt
  66404. * white rectangle on black background
  66405. */ var _default = _main.default;
  66406. exports.default = _default;
  66407. },
  66408. {
  66409. './main': 283,
  66410. 'core-js/modules/es.array.for-each': 170,
  66411. 'core-js/modules/es.object.assign': 188,
  66412. 'core-js/modules/web.dom-collections.for-each': 243
  66413. }
  66414. ],
  66415. 296: [
  66416. function(_dereq_, module, exports) {
  66417. 'use strict';
  66418. _dereq_('core-js/modules/es.symbol');
  66419. _dereq_('core-js/modules/es.symbol.description');
  66420. _dereq_('core-js/modules/es.symbol.iterator');
  66421. _dereq_('core-js/modules/es.array.from');
  66422. _dereq_('core-js/modules/es.array.iterator');
  66423. _dereq_('core-js/modules/es.object.get-prototype-of');
  66424. _dereq_('core-js/modules/es.object.to-string');
  66425. _dereq_('core-js/modules/es.regexp.to-string');
  66426. _dereq_('core-js/modules/es.string.iterator');
  66427. _dereq_('core-js/modules/es.typed-array.uint8-array');
  66428. _dereq_('core-js/modules/es.typed-array.copy-within');
  66429. _dereq_('core-js/modules/es.typed-array.every');
  66430. _dereq_('core-js/modules/es.typed-array.fill');
  66431. _dereq_('core-js/modules/es.typed-array.filter');
  66432. _dereq_('core-js/modules/es.typed-array.find');
  66433. _dereq_('core-js/modules/es.typed-array.find-index');
  66434. _dereq_('core-js/modules/es.typed-array.for-each');
  66435. _dereq_('core-js/modules/es.typed-array.includes');
  66436. _dereq_('core-js/modules/es.typed-array.index-of');
  66437. _dereq_('core-js/modules/es.typed-array.iterator');
  66438. _dereq_('core-js/modules/es.typed-array.join');
  66439. _dereq_('core-js/modules/es.typed-array.last-index-of');
  66440. _dereq_('core-js/modules/es.typed-array.map');
  66441. _dereq_('core-js/modules/es.typed-array.reduce');
  66442. _dereq_('core-js/modules/es.typed-array.reduce-right');
  66443. _dereq_('core-js/modules/es.typed-array.reverse');
  66444. _dereq_('core-js/modules/es.typed-array.set');
  66445. _dereq_('core-js/modules/es.typed-array.slice');
  66446. _dereq_('core-js/modules/es.typed-array.some');
  66447. _dereq_('core-js/modules/es.typed-array.sort');
  66448. _dereq_('core-js/modules/es.typed-array.subarray');
  66449. _dereq_('core-js/modules/es.typed-array.to-locale-string');
  66450. _dereq_('core-js/modules/es.typed-array.to-string');
  66451. _dereq_('core-js/modules/web.dom-collections.iterator');
  66452. Object.defineProperty(exports, '__esModule', { value: true });
  66453. exports.default = void 0;
  66454. var _main = _interopRequireDefault(_dereq_('./main'));
  66455. function _interopRequireDefault(obj) {
  66456. return obj && obj.__esModule ? obj : { default: obj };
  66457. }
  66458. function _toConsumableArray(arr) {
  66459. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
  66460. }
  66461. function _nonIterableSpread() {
  66462. throw new TypeError('Invalid attempt to spread non-iterable instance');
  66463. }
  66464. function _iterableToArray(iter) {
  66465. if (
  66466. Symbol.iterator in Object(iter) ||
  66467. Object.prototype.toString.call(iter) === '[object Arguments]'
  66468. )
  66469. return Array.from(iter);
  66470. }
  66471. function _arrayWithoutHoles(arr) {
  66472. if (Array.isArray(arr)) {
  66473. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  66474. arr2[i] = arr[i];
  66475. }
  66476. return arr2;
  66477. }
  66478. }
  66479. /**
  66480. * Multiplies the current matrix by the one specified through the parameters.
  66481. * This is a powerful operation that can perform the equivalent of translate,
  66482. * scale, shear and rotate all at once. You can learn more about transformation
  66483. * matrices on <a href="https://en.wikipedia.org/wiki/Transformation_matrix">
  66484. * Wikipedia</a>.
  66485. *
  66486. * The naming of the arguments here follows the naming of the <a href=
  66487. * "https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-transform">
  66488. * WHATWG specification</a> and corresponds to a
  66489. * transformation matrix of the
  66490. * form:
  66491. *
  66492. * > <img style="max-width: 150px" src="assets/transformation-matrix.png"
  66493. * alt="The transformation matrix used when applyMatrix is called"/>
  66494. *
  66495. * @method applyMatrix
  66496. * @param {Number|Array} a numbers which define the 2x3 matrix to be multiplied, or an array of numbers
  66497. * @param {Number} b numbers which define the 2x3 matrix to be multiplied
  66498. * @param {Number} c numbers which define the 2x3 matrix to be multiplied
  66499. * @param {Number} d numbers which define the 2x3 matrix to be multiplied
  66500. * @param {Number} e numbers which define the 2x3 matrix to be multiplied
  66501. * @param {Number} f numbers which define the 2x3 matrix to be multiplied
  66502. * @chainable
  66503. * @example
  66504. * <div>
  66505. * <code>
  66506. * function setup() {
  66507. * frameRate(10);
  66508. * rectMode(CENTER);
  66509. * }
  66510. *
  66511. * function draw() {
  66512. * let step = frameCount % 20;
  66513. * background(200);
  66514. * // Equivalent to translate(x, y);
  66515. * applyMatrix(1, 0, 0, 1, 40 + step, 50);
  66516. * rect(0, 0, 50, 50);
  66517. * }
  66518. * </code>
  66519. * </div>
  66520. *
  66521. * <div>
  66522. * <code>
  66523. * function setup() {
  66524. * frameRate(10);
  66525. * rectMode(CENTER);
  66526. * }
  66527. *
  66528. * function draw() {
  66529. * let step = frameCount % 20;
  66530. * background(200);
  66531. * translate(50, 50);
  66532. * // Equivalent to scale(x, y);
  66533. * applyMatrix(1 / step, 0, 0, 1 / step, 0, 0);
  66534. * rect(0, 0, 50, 50);
  66535. * }
  66536. * </code>
  66537. * </div>
  66538. *
  66539. * <div>
  66540. * <code>
  66541. * function setup() {
  66542. * frameRate(10);
  66543. * rectMode(CENTER);
  66544. * }
  66545. *
  66546. * function draw() {
  66547. * let step = frameCount % 20;
  66548. * let angle = map(step, 0, 20, 0, TWO_PI);
  66549. * let cos_a = cos(angle);
  66550. * let sin_a = sin(angle);
  66551. * background(200);
  66552. * translate(50, 50);
  66553. * // Equivalent to rotate(angle);
  66554. * applyMatrix(cos_a, sin_a, -sin_a, cos_a, 0, 0);
  66555. * rect(0, 0, 50, 50);
  66556. * }
  66557. * </code>
  66558. * </div>
  66559. *
  66560. * <div>
  66561. * <code>
  66562. * function setup() {
  66563. * frameRate(10);
  66564. * rectMode(CENTER);
  66565. * }
  66566. *
  66567. * function draw() {
  66568. * let step = frameCount % 20;
  66569. * let angle = map(step, 0, 20, -PI / 4, PI / 4);
  66570. * background(200);
  66571. * translate(50, 50);
  66572. * // equivalent to shearX(angle);
  66573. * let shear_factor = 1 / tan(PI / 2 - angle);
  66574. * applyMatrix(1, 0, shear_factor, 1, 0, 0);
  66575. * rect(0, 0, 50, 50);
  66576. * }
  66577. * </code>
  66578. * </div>
  66579. *
  66580. * <div modernizr='webgl'>
  66581. * <code>
  66582. * function setup() {
  66583. * createCanvas(100, 100, WEBGL);
  66584. * noFill();
  66585. * }
  66586. *
  66587. * function draw() {
  66588. * background(200);
  66589. * rotateY(PI / 6);
  66590. * stroke(153);
  66591. * box(35);
  66592. * let rad = millis() / 1000;
  66593. * // Set rotation angles
  66594. * let ct = cos(rad);
  66595. * let st = sin(rad);
  66596. * // Matrix for rotation around the Y axis
  66597. * // prettier-ignore
  66598. * applyMatrix( ct, 0.0, st, 0.0,
  66599. * 0.0, 1.0, 0.0, 0.0,
  66600. * -st, 0.0, ct, 0.0,
  66601. * 0.0, 0.0, 0.0, 1.0);
  66602. * stroke(255);
  66603. * box(50);
  66604. * }
  66605. * </code>
  66606. * </div>
  66607. *
  66608. * <div>
  66609. * <code>
  66610. * function draw() {
  66611. * background(200);
  66612. * let testMatrix = [1, 0, 0, 1, 0, 0];
  66613. * applyMatrix(testMatrix);
  66614. * rect(0, 0, 50, 50);
  66615. * }
  66616. * </code>
  66617. * </div>
  66618. *
  66619. * @alt
  66620. * A rectangle translating to the right
  66621. * A rectangle shrinking to the center
  66622. * A rectangle rotating clockwise about the center
  66623. * A rectangle shearing
  66624. * A rectangle in the upper left corner
  66625. */
  66626. _main.default.prototype.applyMatrix = function() {
  66627. var isTypedArray = arguments[0] instanceof Object.getPrototypeOf(Uint8Array);
  66628. if (Array.isArray(arguments[0]) || isTypedArray) {
  66629. var _this$_renderer;
  66630. (_this$_renderer = this._renderer).applyMatrix.apply(
  66631. _this$_renderer,
  66632. _toConsumableArray(arguments[0])
  66633. );
  66634. } else {
  66635. var _this$_renderer2;
  66636. (_this$_renderer2 = this._renderer).applyMatrix.apply(
  66637. _this$_renderer2,
  66638. arguments
  66639. );
  66640. }
  66641. return this;
  66642. };
  66643. /**
  66644. * Replaces the current matrix with the identity matrix.
  66645. *
  66646. * @method resetMatrix
  66647. * @chainable
  66648. * @example
  66649. * <div>
  66650. * <code>
  66651. * translate(50, 50);
  66652. * applyMatrix(0.5, 0.5, -0.5, 0.5, 0, 0);
  66653. * rect(0, 0, 20, 20);
  66654. * // Note that the translate is also reset.
  66655. * resetMatrix();
  66656. * rect(0, 0, 20, 20);
  66657. * </code>
  66658. * </div>
  66659. *
  66660. * @alt
  66661. * A rotated rectangle in the center with another at the top left corner
  66662. */
  66663. _main.default.prototype.resetMatrix = function() {
  66664. this._renderer.resetMatrix();
  66665. return this;
  66666. };
  66667. /**
  66668. * Rotates a shape by the amount specified by the angle parameter. This
  66669. * function accounts for <a href="#/p5/angleMode">angleMode</a>, so angles
  66670. * can be entered in either RADIANS or DEGREES.
  66671. *
  66672. * Objects are always rotated around their relative position to the
  66673. * origin and positive numbers rotate objects in a clockwise direction.
  66674. * Transformations apply to everything that happens after and subsequent
  66675. * calls to the function accumulates the effect. For example, calling
  66676. * rotate(HALF_PI) and then rotate(HALF_PI) is the same as rotate(PI).
  66677. * All transformations are reset when <a href="#/p5/draw">draw()</a> begins again.
  66678. *
  66679. * Technically, <a href="#/p5/rotate">rotate()</a> multiplies the current transformation matrix
  66680. * by a rotation matrix. This function can be further controlled by
  66681. * the <a href="#/p5/push">push()</a> and <a href="#/p5/pop">pop()</a>.
  66682. *
  66683. * @method rotate
  66684. * @param {Number} angle the angle of rotation, specified in radians
  66685. * or degrees, depending on current angleMode
  66686. * @param {p5.Vector|Number[]} [axis] (in 3d) the axis to rotate around
  66687. * @chainable
  66688. * @example
  66689. * <div>
  66690. * <code>
  66691. * translate(width / 2, height / 2);
  66692. * rotate(PI / 3.0);
  66693. * rect(-26, -26, 52, 52);
  66694. * </code>
  66695. * </div>
  66696. *
  66697. * @alt
  66698. * white 52x52 rect with black outline at center rotated counter 45 degrees
  66699. */
  66700. _main.default.prototype.rotate = function(angle, axis) {
  66701. _main.default._validateParameters('rotate', arguments);
  66702. this._renderer.rotate(this._toRadians(angle), axis);
  66703. return this;
  66704. };
  66705. /**
  66706. * Rotates a shape around X axis by the amount specified in angle parameter.
  66707. * The angles can be entered in either RADIANS or DEGREES.
  66708. *
  66709. * Objects are always rotated around their relative position to the
  66710. * origin and positive numbers rotate objects in a clockwise direction.
  66711. * All transformations are reset when <a href="#/p5/draw">draw()</a> begins again.
  66712. *
  66713. * @method rotateX
  66714. * @param {Number} angle the angle of rotation, specified in radians
  66715. * or degrees, depending on current angleMode
  66716. * @chainable
  66717. * @example
  66718. * <div modernizr='webgl'>
  66719. * <code>
  66720. * function setup() {
  66721. * createCanvas(100, 100, WEBGL);
  66722. * }
  66723. * function draw() {
  66724. * background(255);
  66725. * rotateX(millis() / 1000);
  66726. * box();
  66727. * }
  66728. * </code>
  66729. * </div>
  66730. *
  66731. * @alt
  66732. * 3d box rotating around the x axis.
  66733. */
  66734. _main.default.prototype.rotateX = function(angle) {
  66735. this._assert3d('rotateX');
  66736. _main.default._validateParameters('rotateX', arguments);
  66737. this._renderer.rotateX(this._toRadians(angle));
  66738. return this;
  66739. };
  66740. /**
  66741. * Rotates a shape around Y axis by the amount specified in angle parameter.
  66742. * The angles can be entered in either RADIANS or DEGREES.
  66743. *
  66744. * Objects are always rotated around their relative position to the
  66745. * origin and positive numbers rotate objects in a clockwise direction.
  66746. * All transformations are reset when <a href="#/p5/draw">draw()</a> begins again.
  66747. *
  66748. * @method rotateY
  66749. * @param {Number} angle the angle of rotation, specified in radians
  66750. * or degrees, depending on current angleMode
  66751. * @chainable
  66752. * @example
  66753. * <div modernizr='webgl'>
  66754. * <code>
  66755. * function setup() {
  66756. * createCanvas(100, 100, WEBGL);
  66757. * }
  66758. * function draw() {
  66759. * background(255);
  66760. * rotateY(millis() / 1000);
  66761. * box();
  66762. * }
  66763. * </code>
  66764. * </div>
  66765. *
  66766. * @alt
  66767. * 3d box rotating around the y axis.
  66768. */
  66769. _main.default.prototype.rotateY = function(angle) {
  66770. this._assert3d('rotateY');
  66771. _main.default._validateParameters('rotateY', arguments);
  66772. this._renderer.rotateY(this._toRadians(angle));
  66773. return this;
  66774. };
  66775. /**
  66776. * Rotates a shape around Z axis by the amount specified in angle parameter.
  66777. * The angles can be entered in either RADIANS or DEGREES.
  66778. *
  66779. * This method works in WEBGL mode only.
  66780. *
  66781. * Objects are always rotated around their relative position to the
  66782. * origin and positive numbers rotate objects in a clockwise direction.
  66783. * All transformations are reset when <a href="#/p5/draw">draw()</a> begins again.
  66784. *
  66785. * @method rotateZ
  66786. * @param {Number} angle the angle of rotation, specified in radians
  66787. * or degrees, depending on current angleMode
  66788. * @chainable
  66789. * @example
  66790. * <div modernizr='webgl'>
  66791. * <code>
  66792. * function setup() {
  66793. * createCanvas(100, 100, WEBGL);
  66794. * }
  66795. * function draw() {
  66796. * background(255);
  66797. * rotateZ(millis() / 1000);
  66798. * box();
  66799. * }
  66800. * </code>
  66801. * </div>
  66802. *
  66803. * @alt
  66804. * 3d box rotating around the z axis.
  66805. */
  66806. _main.default.prototype.rotateZ = function(angle) {
  66807. this._assert3d('rotateZ');
  66808. _main.default._validateParameters('rotateZ', arguments);
  66809. this._renderer.rotateZ(this._toRadians(angle));
  66810. return this;
  66811. };
  66812. /**
  66813. * Increases or decreases the size of a shape by expanding or contracting
  66814. * vertices. Objects always scale from their relative origin to the
  66815. * coordinate system. Scale values are specified as decimal percentages.
  66816. * For example, the function call scale(2.0) increases the dimension of a
  66817. * shape by 200%.
  66818. *
  66819. * Transformations apply to everything that happens after and subsequent
  66820. * calls to the function multiply the effect. For example, calling scale(2.0)
  66821. * and then scale(1.5) is the same as scale(3.0). If <a href="#/p5/scale">scale()</a> is called
  66822. * within <a href="#/p5/draw">draw()</a>, the transformation is reset when the loop begins again.
  66823. *
  66824. * Using this function with the z parameter is only available in WEBGL mode.
  66825. * This function can be further controlled with <a href="#/p5/push">push()</a> and <a href="#/p5/pop">pop()</a>.
  66826. *
  66827. * @method scale
  66828. * @param {Number|p5.Vector|Number[]} s
  66829. * percent to scale the object, or percentage to
  66830. * scale the object in the x-axis if multiple arguments
  66831. * are given
  66832. * @param {Number} [y] percent to scale the object in the y-axis
  66833. * @param {Number} [z] percent to scale the object in the z-axis (webgl only)
  66834. * @chainable
  66835. * @example
  66836. * <div>
  66837. * <code>
  66838. * rect(30, 20, 50, 50);
  66839. * scale(0.5);
  66840. * rect(30, 20, 50, 50);
  66841. * </code>
  66842. * </div>
  66843. *
  66844. * <div>
  66845. * <code>
  66846. * rect(30, 20, 50, 50);
  66847. * scale(0.5, 1.3);
  66848. * rect(30, 20, 50, 50);
  66849. * </code>
  66850. * </div>
  66851. *
  66852. * @alt
  66853. * white 52x52 rect with black outline at center rotated counter 45 degrees
  66854. * 2 white rects with black outline- 1 50x50 at center. other 25x65 bottom left
  66855. */
  66856. /**
  66857. * @method scale
  66858. * @param {p5.Vector|Number[]} scales per-axis percents to scale the object
  66859. * @chainable
  66860. */
  66861. _main.default.prototype.scale = function(x, y, z) {
  66862. _main.default._validateParameters('scale', arguments);
  66863. // Only check for Vector argument type if Vector is available
  66864. if (x instanceof _main.default.Vector) {
  66865. var v = x;
  66866. x = v.x;
  66867. y = v.y;
  66868. z = v.z;
  66869. } else if (x instanceof Array) {
  66870. var rg = x;
  66871. x = rg[0];
  66872. y = rg[1];
  66873. z = rg[2] || 1;
  66874. }
  66875. if (isNaN(y)) {
  66876. y = z = x;
  66877. } else if (isNaN(z)) {
  66878. z = 1;
  66879. }
  66880. this._renderer.scale.call(this._renderer, x, y, z);
  66881. return this;
  66882. };
  66883. /**
  66884. * Shears a shape around the x-axis by the amount specified by the angle
  66885. * parameter. Angles should be specified in the current angleMode.
  66886. * Objects are always sheared around their relative position to the origin
  66887. * and positive numbers shear objects in a clockwise direction.
  66888. *
  66889. * Transformations apply to everything that happens after and subsequent
  66890. * calls to the function accumulates the effect. For example, calling
  66891. * shearX(PI/2) and then shearX(PI/2) is the same as shearX(PI).
  66892. * If <a href="#/p5/shearX">shearX()</a> is called within the <a href="#/p5/draw">draw()</a>,
  66893. * the transformation is reset when the loop begins again.
  66894. *
  66895. * Technically, <a href="#/p5/shearX">shearX()</a> multiplies the current
  66896. * transformation matrix by a rotation matrix. This function can be further
  66897. * controlled by the <a href="#/p5/push">push()</a> and <a href="#/p5/pop">pop()</a> functions.
  66898. *
  66899. * @method shearX
  66900. * @param {Number} angle angle of shear specified in radians or degrees,
  66901. * depending on current angleMode
  66902. * @chainable
  66903. * @example
  66904. * <div>
  66905. * <code>
  66906. * translate(width / 4, height / 4);
  66907. * shearX(PI / 4.0);
  66908. * rect(0, 0, 30, 30);
  66909. * </code>
  66910. * </div>
  66911. *
  66912. * @alt
  66913. * white irregular quadrilateral with black outline at top middle.
  66914. */
  66915. _main.default.prototype.shearX = function(angle) {
  66916. _main.default._validateParameters('shearX', arguments);
  66917. var rad = this._toRadians(angle);
  66918. this._renderer.applyMatrix(1, 0, Math.tan(rad), 1, 0, 0);
  66919. return this;
  66920. };
  66921. /**
  66922. * Shears a shape around the y-axis the amount specified by the angle
  66923. * parameter. Angles should be specified in the current angleMode. Objects
  66924. * are always sheared around their relative position to the origin and
  66925. * positive numbers shear objects in a clockwise direction.
  66926. *
  66927. * Transformations apply to everything that happens after and subsequent
  66928. * calls to the function accumulates the effect. For example, calling
  66929. * shearY(PI/2) and then shearY(PI/2) is the same as shearY(PI). If
  66930. * <a href="#/p5/shearY">shearY()</a> is called within the <a href="#/p5/draw">draw()</a>, the transformation is reset when
  66931. * the loop begins again.
  66932. *
  66933. * Technically, <a href="#/p5/shearY">shearY()</a> multiplies the current transformation matrix by a
  66934. * rotation matrix. This function can be further controlled by the
  66935. * <a href="#/p5/push">push()</a> and <a href="#/p5/pop">pop()</a> functions.
  66936. *
  66937. * @method shearY
  66938. * @param {Number} angle angle of shear specified in radians or degrees,
  66939. * depending on current angleMode
  66940. * @chainable
  66941. * @example
  66942. * <div>
  66943. * <code>
  66944. * translate(width / 4, height / 4);
  66945. * shearY(PI / 4.0);
  66946. * rect(0, 0, 30, 30);
  66947. * </code>
  66948. * </div>
  66949. *
  66950. * @alt
  66951. * white irregular quadrilateral with black outline at middle bottom.
  66952. */
  66953. _main.default.prototype.shearY = function(angle) {
  66954. _main.default._validateParameters('shearY', arguments);
  66955. var rad = this._toRadians(angle);
  66956. this._renderer.applyMatrix(1, Math.tan(rad), 0, 1, 0, 0);
  66957. return this;
  66958. };
  66959. /**
  66960. * Specifies an amount to displace objects within the display window.
  66961. * The x parameter specifies left/right translation, the y parameter
  66962. * specifies up/down translation.
  66963. *
  66964. * Transformations are cumulative and apply to everything that happens after
  66965. * and subsequent calls to the function accumulates the effect. For example,
  66966. * calling translate(50, 0) and then translate(20, 0) is the same as
  66967. * translate(70, 0). If <a href="#/p5/translate">translate()</a> is called within <a href="#/p5/draw">draw()</a>, the
  66968. * transformation is reset when the loop begins again. This function can be
  66969. * further controlled by using <a href="#/p5/push">push()</a> and <a href="#/p5/pop">pop()</a>.
  66970. *
  66971. * @method translate
  66972. * @param {Number} x left/right translation
  66973. * @param {Number} y up/down translation
  66974. * @param {Number} [z] forward/backward translation (webgl only)
  66975. * @chainable
  66976. * @example
  66977. * <div>
  66978. * <code>
  66979. * translate(30, 20);
  66980. * rect(0, 0, 55, 55);
  66981. * </code>
  66982. * </div>
  66983. *
  66984. * <div>
  66985. * <code>
  66986. * rect(0, 0, 55, 55); // Draw rect at original 0,0
  66987. * translate(30, 20);
  66988. * rect(0, 0, 55, 55); // Draw rect at new 0,0
  66989. * translate(14, 14);
  66990. * rect(0, 0, 55, 55); // Draw rect at new 0,0
  66991. * </code>
  66992. * </div>
  66993. *
  66994. * <div>
  66995. * <code>
  66996. * function draw() {
  66997. * background(200);
  66998. * rectMode(CENTER);
  66999. * translate(width / 2, height / 2);
  67000. * translate(p5.Vector.fromAngle(millis() / 1000, 40));
  67001. * rect(0, 0, 20, 20);
  67002. * }
  67003. * </code>
  67004. * </div>
  67005. *
  67006. * @alt
  67007. * white 55x55 rect with black outline at center right.
  67008. * 3 white 55x55 rects with black outlines at top-l, center-r and bottom-r.
  67009. * a 20x20 white rect moving in a circle around the canvas
  67010. */
  67011. /**
  67012. * @method translate
  67013. * @param {p5.Vector} vector the vector to translate by
  67014. * @chainable
  67015. */
  67016. _main.default.prototype.translate = function(x, y, z) {
  67017. _main.default._validateParameters('translate', arguments);
  67018. if (this._renderer.isP3D) {
  67019. this._renderer.translate(x, y, z);
  67020. } else {
  67021. this._renderer.translate(x, y);
  67022. }
  67023. return this;
  67024. };
  67025. var _default = _main.default;
  67026. exports.default = _default;
  67027. },
  67028. {
  67029. './main': 283,
  67030. 'core-js/modules/es.array.from': 171,
  67031. 'core-js/modules/es.array.iterator': 174,
  67032. 'core-js/modules/es.object.get-prototype-of': 190,
  67033. 'core-js/modules/es.object.to-string': 192,
  67034. 'core-js/modules/es.regexp.to-string': 197,
  67035. 'core-js/modules/es.string.iterator': 201,
  67036. 'core-js/modules/es.symbol': 211,
  67037. 'core-js/modules/es.symbol.description': 209,
  67038. 'core-js/modules/es.symbol.iterator': 210,
  67039. 'core-js/modules/es.typed-array.copy-within': 212,
  67040. 'core-js/modules/es.typed-array.every': 213,
  67041. 'core-js/modules/es.typed-array.fill': 214,
  67042. 'core-js/modules/es.typed-array.filter': 215,
  67043. 'core-js/modules/es.typed-array.find': 217,
  67044. 'core-js/modules/es.typed-array.find-index': 216,
  67045. 'core-js/modules/es.typed-array.for-each': 220,
  67046. 'core-js/modules/es.typed-array.includes': 221,
  67047. 'core-js/modules/es.typed-array.index-of': 222,
  67048. 'core-js/modules/es.typed-array.iterator': 225,
  67049. 'core-js/modules/es.typed-array.join': 226,
  67050. 'core-js/modules/es.typed-array.last-index-of': 227,
  67051. 'core-js/modules/es.typed-array.map': 228,
  67052. 'core-js/modules/es.typed-array.reduce': 230,
  67053. 'core-js/modules/es.typed-array.reduce-right': 229,
  67054. 'core-js/modules/es.typed-array.reverse': 231,
  67055. 'core-js/modules/es.typed-array.set': 232,
  67056. 'core-js/modules/es.typed-array.slice': 233,
  67057. 'core-js/modules/es.typed-array.some': 234,
  67058. 'core-js/modules/es.typed-array.sort': 235,
  67059. 'core-js/modules/es.typed-array.subarray': 236,
  67060. 'core-js/modules/es.typed-array.to-locale-string': 237,
  67061. 'core-js/modules/es.typed-array.to-string': 238,
  67062. 'core-js/modules/es.typed-array.uint8-array': 241,
  67063. 'core-js/modules/web.dom-collections.iterator': 244
  67064. }
  67065. ],
  67066. 297: [
  67067. function(_dereq_, module, exports) {
  67068. 'use strict';
  67069. _dereq_('core-js/modules/es.symbol');
  67070. _dereq_('core-js/modules/es.symbol.description');
  67071. _dereq_('core-js/modules/es.symbol.iterator');
  67072. _dereq_('core-js/modules/es.array.from');
  67073. _dereq_('core-js/modules/es.array.iterator');
  67074. _dereq_('core-js/modules/es.object.to-string');
  67075. _dereq_('core-js/modules/es.regexp.to-string');
  67076. _dereq_('core-js/modules/es.string.ends-with');
  67077. _dereq_('core-js/modules/es.string.iterator');
  67078. _dereq_('core-js/modules/web.dom-collections.iterator');
  67079. var _main = _interopRequireDefault(_dereq_('../core/main'));
  67080. function _interopRequireDefault(obj) {
  67081. return obj && obj.__esModule ? obj : { default: obj };
  67082. }
  67083. function _toConsumableArray(arr) {
  67084. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
  67085. }
  67086. function _nonIterableSpread() {
  67087. throw new TypeError('Invalid attempt to spread non-iterable instance');
  67088. }
  67089. function _iterableToArray(iter) {
  67090. if (
  67091. Symbol.iterator in Object(iter) ||
  67092. Object.prototype.toString.call(iter) === '[object Arguments]'
  67093. )
  67094. return Array.from(iter);
  67095. }
  67096. function _arrayWithoutHoles(arr) {
  67097. if (Array.isArray(arr)) {
  67098. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  67099. arr2[i] = arr[i];
  67100. }
  67101. return arr2;
  67102. }
  67103. }
  67104. function _typeof(obj) {
  67105. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  67106. _typeof = function _typeof(obj) {
  67107. return typeof obj;
  67108. };
  67109. } else {
  67110. _typeof = function _typeof(obj) {
  67111. return obj &&
  67112. typeof Symbol === 'function' &&
  67113. obj.constructor === Symbol &&
  67114. obj !== Symbol.prototype
  67115. ? 'symbol'
  67116. : typeof obj;
  67117. };
  67118. }
  67119. return _typeof(obj);
  67120. }
  67121. /**
  67122. *
  67123. * Stores a value in local storage under the key name.
  67124. * Local storage is saved in the browser and persists
  67125. * between browsing sessions and page reloads.
  67126. * The key can be the name of the variable but doesn't
  67127. * have to be. To retrieve stored items
  67128. * see <a href="#/p5/getItem">getItem</a>.
  67129. *
  67130. * Sensitive data such as passwords or personal information
  67131. * should not be stored in local storage.
  67132. *
  67133. * @method storeItem
  67134. * @for p5
  67135. * @param {String} key
  67136. * @param {String|Number|Object|Boolean|p5.Color|p5.Vector} value
  67137. *
  67138. * @example
  67139. * <div><code>
  67140. * // Type to change the letter in the
  67141. * // center of the canvas.
  67142. * // If you reload the page, it will
  67143. * // still display the last key you entered
  67144. *
  67145. * let myText;
  67146. *
  67147. * function setup() {
  67148. * createCanvas(100, 100);
  67149. * myText = getItem('myText');
  67150. * if (myText === null) {
  67151. * myText = '';
  67152. * }
  67153. * }
  67154. *
  67155. * function draw() {
  67156. * textSize(40);
  67157. * background(255);
  67158. * text(myText, width / 2, height / 2);
  67159. * }
  67160. *
  67161. * function keyPressed() {
  67162. * myText = key;
  67163. * storeItem('myText', myText);
  67164. * }
  67165. * </code></div>
  67166. *
  67167. * @alt
  67168. * When you type the key name is displayed as black text on white background.
  67169. * If you reload the page, the last letter typed is still displaying.
  67170. */
  67171. _main.default.prototype.storeItem = function(key, value) {
  67172. if (typeof key !== 'string') {
  67173. console.log(
  67174. 'The argument that you passed to storeItem() - '.concat(
  67175. key,
  67176. ' is not a string.'
  67177. )
  67178. );
  67179. }
  67180. if (key.endsWith('p5TypeID')) {
  67181. console.log(
  67182. 'The argument that you passed to storeItem() - '.concat(
  67183. key,
  67184. " must not end with 'p5TypeID'."
  67185. )
  67186. );
  67187. }
  67188. if (typeof value === 'undefined') {
  67189. console.log('You cannot store undefined variables using storeItem().');
  67190. }
  67191. var type = _typeof(value);
  67192. switch (type) {
  67193. case 'number':
  67194. case 'boolean':
  67195. value = value.toString();
  67196. break;
  67197. case 'object':
  67198. if (value instanceof _main.default.Color) {
  67199. type = 'p5.Color';
  67200. } else if (value instanceof _main.default.Vector) {
  67201. type = 'p5.Vector';
  67202. var coord = [value.x, value.y, value.z];
  67203. value = coord;
  67204. }
  67205. value = JSON.stringify(value);
  67206. break;
  67207. case 'string':
  67208. default:
  67209. break;
  67210. }
  67211. localStorage.setItem(key, value);
  67212. var typeKey = ''.concat(key, 'p5TypeID');
  67213. localStorage.setItem(typeKey, type);
  67214. };
  67215. /**
  67216. *
  67217. * Returns the value of an item that was stored in local storage
  67218. * using storeItem()
  67219. *
  67220. * @method getItem
  67221. * @for p5
  67222. * @param {String} key name that you wish to use to store in local storage
  67223. * @return {Number|Object|String|Boolean|p5.Color|p5.Vector} Value of stored item
  67224. *
  67225. * @example
  67226. * <div><code>
  67227. * // Click the mouse to change
  67228. * // the color of the background
  67229. * // Once you have changed the color
  67230. * // it will stay changed even when you
  67231. * // reload the page.
  67232. *
  67233. * let myColor;
  67234. *
  67235. * function setup() {
  67236. * createCanvas(100, 100);
  67237. * myColor = getItem('myColor');
  67238. * }
  67239. *
  67240. * function draw() {
  67241. * if (myColor !== null) {
  67242. * background(myColor);
  67243. * }
  67244. * }
  67245. *
  67246. * function mousePressed() {
  67247. * myColor = color(random(255), random(255), random(255));
  67248. * storeItem('myColor', myColor);
  67249. * }
  67250. * </code></div>
  67251. *
  67252. * @alt
  67253. * If you click, the canvas changes to a random color.
  67254. * If you reload the page, the canvas is still the color it
  67255. * was when the page was previously loaded.
  67256. */
  67257. _main.default.prototype.getItem = function(key) {
  67258. var value = localStorage.getItem(key);
  67259. var type = localStorage.getItem(''.concat(key, 'p5TypeID'));
  67260. if (typeof type === 'undefined') {
  67261. console.log(
  67262. 'Unable to determine type of item stored under '.concat(
  67263. key,
  67264. 'in local storage. Did you save the item with something other than setItem()?'
  67265. )
  67266. );
  67267. } else if (value !== null) {
  67268. switch (type) {
  67269. case 'number':
  67270. value = parseFloat(value);
  67271. break;
  67272. case 'boolean':
  67273. value = value === 'true';
  67274. break;
  67275. case 'object':
  67276. value = JSON.parse(value);
  67277. break;
  67278. case 'p5.Color':
  67279. value = JSON.parse(value);
  67280. value = this.color.apply(this, _toConsumableArray(value.levels));
  67281. break;
  67282. case 'p5.Vector':
  67283. value = JSON.parse(value);
  67284. value = this.createVector.apply(this, _toConsumableArray(value));
  67285. break;
  67286. case 'string':
  67287. default:
  67288. break;
  67289. }
  67290. }
  67291. return value;
  67292. };
  67293. /**
  67294. *
  67295. * Clears all local storage items set with storeItem()
  67296. * for the current domain.
  67297. *
  67298. * @method clearStorage
  67299. * @for p5
  67300. *
  67301. * @example
  67302. * <div class="norender">
  67303. * <code>
  67304. * function setup() {
  67305. * let myNum = 10;
  67306. * let myBool = false;
  67307. * storeItem('myNum', myNum);
  67308. * storeItem('myBool', myBool);
  67309. * print(getItem('myNum')); // logs 10 to the console
  67310. * print(getItem('myBool')); // logs false to the console
  67311. * clearStorage();
  67312. * print(getItem('myNum')); // logs null to the console
  67313. * print(getItem('myBool')); // logs null to the console
  67314. * }
  67315. * </code></div>
  67316. */
  67317. _main.default.prototype.clearStorage = function() {
  67318. localStorage.clear();
  67319. };
  67320. /**
  67321. *
  67322. * Removes an item that was stored with storeItem()
  67323. *
  67324. * @method removeItem
  67325. * @param {String} key
  67326. * @for p5
  67327. *
  67328. * @example
  67329. * <div class="norender">
  67330. * <code>
  67331. * function setup() {
  67332. * let myVar = 10;
  67333. * storeItem('myVar', myVar);
  67334. * print(getItem('myVar')); // logs 10 to the console
  67335. * removeItem('myVar');
  67336. * print(getItem('myVar')); // logs null to the console
  67337. * }
  67338. * </code></div>
  67339. */
  67340. _main.default.prototype.removeItem = function(key) {
  67341. if (typeof key !== 'string') {
  67342. console.log(
  67343. 'The argument that you passed to removeItem() - '.concat(
  67344. key,
  67345. ' is not a string.'
  67346. )
  67347. );
  67348. }
  67349. localStorage.removeItem(key);
  67350. localStorage.removeItem(''.concat(key, 'p5TypeID'));
  67351. };
  67352. },
  67353. {
  67354. '../core/main': 283,
  67355. 'core-js/modules/es.array.from': 171,
  67356. 'core-js/modules/es.array.iterator': 174,
  67357. 'core-js/modules/es.object.to-string': 192,
  67358. 'core-js/modules/es.regexp.to-string': 197,
  67359. 'core-js/modules/es.string.ends-with': 199,
  67360. 'core-js/modules/es.string.iterator': 201,
  67361. 'core-js/modules/es.symbol': 211,
  67362. 'core-js/modules/es.symbol.description': 209,
  67363. 'core-js/modules/es.symbol.iterator': 210,
  67364. 'core-js/modules/web.dom-collections.iterator': 244
  67365. }
  67366. ],
  67367. 298: [
  67368. function(_dereq_, module, exports) {
  67369. 'use strict';
  67370. _dereq_('core-js/modules/es.array.concat');
  67371. _dereq_('core-js/modules/es.object.keys');
  67372. _dereq_('core-js/modules/es.string.sub');
  67373. Object.defineProperty(exports, '__esModule', { value: true });
  67374. exports.default = void 0;
  67375. var _main = _interopRequireDefault(_dereq_('../core/main'));
  67376. function _interopRequireDefault(obj) {
  67377. return obj && obj.__esModule ? obj : { default: obj };
  67378. }
  67379. /**
  67380. * @module Data
  67381. * @submodule Dictionary
  67382. * @for p5.TypedDict
  67383. * @requires core
  67384. *
  67385. * This module defines the p5 methods for the p5 Dictionary classes.
  67386. * The classes StringDict and NumberDict are for storing and working
  67387. * with key-value pairs.
  67388. */ /**
  67389. *
  67390. * Creates a new instance of p5.StringDict using the key-value pair
  67391. * or the object you provide.
  67392. *
  67393. * @method createStringDict
  67394. * @for p5
  67395. * @param {String} key
  67396. * @param {String} value
  67397. * @return {p5.StringDict}
  67398. *
  67399. * @example
  67400. * <div class="norender">
  67401. * <code>
  67402. * function setup() {
  67403. * let myDictionary = createStringDict('p5', 'js');
  67404. * print(myDictionary.hasKey('p5')); // logs true to console
  67405. *
  67406. * let anotherDictionary = createStringDict({ happy: 'coding' });
  67407. * print(anotherDictionary.hasKey('happy')); // logs true to console
  67408. * }
  67409. * </code></div>
  67410. */ /**
  67411. * @method createStringDict
  67412. * @param {Object} object object
  67413. * @return {p5.StringDict}
  67414. */ _main.default.prototype.createStringDict = function(key, value) {
  67415. _main.default._validateParameters('createStringDict', arguments);
  67416. return new _main.default.StringDict(key, value);
  67417. };
  67418. /**
  67419. *
  67420. * Creates a new instance of <a href="#/p5.NumberDict">p5.NumberDict</a> using the key-value pair
  67421. * or object you provide.
  67422. *
  67423. * @method createNumberDict
  67424. * @for p5
  67425. * @param {Number} key
  67426. * @param {Number} value
  67427. * @return {p5.NumberDict}
  67428. *
  67429. * @example
  67430. * <div class="norender">
  67431. * <code>
  67432. * function setup() {
  67433. * let myDictionary = createNumberDict(100, 42);
  67434. * print(myDictionary.hasKey(100)); // logs true to console
  67435. *
  67436. * let anotherDictionary = createNumberDict({ 200: 84 });
  67437. * print(anotherDictionary.hasKey(200)); // logs true to console
  67438. * }
  67439. * </code></div>
  67440. */
  67441. /**
  67442. * @method createNumberDict
  67443. * @param {Object} object object
  67444. * @return {p5.NumberDict}
  67445. */
  67446. _main.default.prototype.createNumberDict = function(key, value) {
  67447. _main.default._validateParameters('createNumberDict', arguments);
  67448. return new _main.default.NumberDict(key, value);
  67449. };
  67450. /**
  67451. *
  67452. * Base class for all p5.Dictionary types. Specifically
  67453. * typed Dictionary classes inherit from this class.
  67454. *
  67455. * @class p5.TypedDict
  67456. * @constructor
  67457. */
  67458. _main.default.TypedDict = function(key, value) {
  67459. if (key instanceof Object) {
  67460. this.data = key;
  67461. } else {
  67462. this.data = {};
  67463. this.data[key] = value;
  67464. }
  67465. return this;
  67466. };
  67467. /**
  67468. * Returns the number of key-value pairs currently stored in the Dictionary.
  67469. *
  67470. * @method size
  67471. * @return {Integer} the number of key-value pairs in the Dictionary
  67472. *
  67473. * @example
  67474. * <div class="norender">
  67475. * <code>
  67476. * function setup() {
  67477. * let myDictionary = createNumberDict(1, 10);
  67478. * myDictionary.create(2, 20);
  67479. * myDictionary.create(3, 30);
  67480. * print(myDictionary.size()); // logs 3 to the console
  67481. * }
  67482. * </code></div>
  67483. */
  67484. _main.default.TypedDict.prototype.size = function() {
  67485. return Object.keys(this.data).length;
  67486. };
  67487. /**
  67488. * Returns true if the given key exists in the Dictionary,
  67489. * otherwise returns false.
  67490. *
  67491. * @method hasKey
  67492. * @param {Number|String} key that you want to look up
  67493. * @return {Boolean} whether that key exists in Dictionary
  67494. *
  67495. * @example
  67496. * <div class="norender">
  67497. * <code>
  67498. * function setup() {
  67499. * let myDictionary = createStringDict('p5', 'js');
  67500. * print(myDictionary.hasKey('p5')); // logs true to console
  67501. * }
  67502. * </code></div>
  67503. */
  67504. _main.default.TypedDict.prototype.hasKey = function(key) {
  67505. return this.data.hasOwnProperty(key);
  67506. };
  67507. /**
  67508. * Returns the value stored at the given key.
  67509. *
  67510. * @method get
  67511. * @param {Number|String} the key you want to access
  67512. * @return {Number|String} the value stored at that key
  67513. *
  67514. * @example
  67515. * <div class="norender">
  67516. * <code>
  67517. * function setup() {
  67518. * let myDictionary = createStringDict('p5', 'js');
  67519. * let myValue = myDictionary.get('p5');
  67520. * print(myValue === 'js'); // logs true to console
  67521. * }
  67522. * </code></div>
  67523. */
  67524. _main.default.TypedDict.prototype.get = function(key) {
  67525. if (this.data.hasOwnProperty(key)) {
  67526. return this.data[key];
  67527. } else {
  67528. console.log(''.concat(key, ' does not exist in this Dictionary'));
  67529. }
  67530. };
  67531. /**
  67532. * Updates the value associated with the given key in case it already exists
  67533. * in the Dictionary. Otherwise a new key-value pair is added.
  67534. *
  67535. * @method set
  67536. * @param {Number|String} key
  67537. * @param {Number|String} value
  67538. *
  67539. * @example
  67540. * <div class="norender">
  67541. * <code>
  67542. * function setup() {
  67543. * let myDictionary = createStringDict('p5', 'js');
  67544. * myDictionary.set('p5', 'JS');
  67545. * myDictionary.print(); // logs "key: p5 - value: JS" to console
  67546. * }
  67547. * </code></div>
  67548. */
  67549. _main.default.TypedDict.prototype.set = function(key, value) {
  67550. if (this._validate(value)) {
  67551. this.data[key] = value;
  67552. } else {
  67553. console.log('Those values dont work for this dictionary type.');
  67554. }
  67555. };
  67556. /**
  67557. * private helper function to handle the user passing in objects
  67558. * during construction or calls to create()
  67559. */
  67560. _main.default.TypedDict.prototype._addObj = function(obj) {
  67561. for (var key in obj) {
  67562. this.set(key, obj[key]);
  67563. }
  67564. };
  67565. /**
  67566. * Creates a new key-value pair in the Dictionary.
  67567. *
  67568. * @method create
  67569. * @param {Number|String} key
  67570. * @param {Number|String} value
  67571. *
  67572. * @example
  67573. * <div class="norender">
  67574. * <code>
  67575. * function setup() {
  67576. * let myDictionary = createStringDict('p5', 'js');
  67577. * myDictionary.create('happy', 'coding');
  67578. * myDictionary.print();
  67579. * // above logs "key: p5 - value: js, key: happy - value: coding" to console
  67580. * }
  67581. * </code></div>
  67582. */
  67583. /**
  67584. * @method create
  67585. * @param {Object} obj key/value pair
  67586. */
  67587. _main.default.TypedDict.prototype.create = function(key, value) {
  67588. if (key instanceof Object && typeof value === 'undefined') {
  67589. this._addObj(key);
  67590. } else if (typeof key !== 'undefined') {
  67591. this.set(key, value);
  67592. } else {
  67593. console.log(
  67594. 'In order to create a new Dictionary entry you must pass ' +
  67595. 'an object or a key, value pair'
  67596. );
  67597. }
  67598. };
  67599. /**
  67600. * Removes all previously stored key-value pairs from the Dictionary.
  67601. *
  67602. * @method clear
  67603. * @example
  67604. * <div class="norender">
  67605. * <code>
  67606. * function setup() {
  67607. * let myDictionary = createStringDict('p5', 'js');
  67608. * print(myDictionary.hasKey('p5')); // prints 'true'
  67609. * myDictionary.clear();
  67610. * print(myDictionary.hasKey('p5')); // prints 'false'
  67611. * }
  67612. * </code>
  67613. * </div>
  67614. */
  67615. _main.default.TypedDict.prototype.clear = function() {
  67616. this.data = {};
  67617. };
  67618. /**
  67619. * Removes the key-value pair stored at the given key from the Dictionary.
  67620. *
  67621. * @method remove
  67622. * @param {Number|String} key for the pair to remove
  67623. *
  67624. * @example
  67625. * <div class="norender">
  67626. * <code>
  67627. * function setup() {
  67628. * let myDictionary = createStringDict('p5', 'js');
  67629. * myDictionary.create('happy', 'coding');
  67630. * myDictionary.print();
  67631. * // above logs "key: p5 - value: js, key: happy - value: coding" to console
  67632. * myDictionary.remove('p5');
  67633. * myDictionary.print();
  67634. * // above logs "key: happy value: coding" to console
  67635. * }
  67636. * </code></div>
  67637. */
  67638. _main.default.TypedDict.prototype.remove = function(key) {
  67639. if (this.data.hasOwnProperty(key)) {
  67640. delete this.data[key];
  67641. } else {
  67642. throw new Error(''.concat(key, ' does not exist in this Dictionary'));
  67643. }
  67644. };
  67645. /**
  67646. * Logs the set of items currently stored in the Dictionary to the console.
  67647. *
  67648. * @method print
  67649. *
  67650. * @example
  67651. * <div class="norender">
  67652. * <code>
  67653. * function setup() {
  67654. * let myDictionary = createStringDict('p5', 'js');
  67655. * myDictionary.create('happy', 'coding');
  67656. * myDictionary.print();
  67657. * // above logs "key: p5 - value: js, key: happy - value: coding" to console
  67658. * }
  67659. * </code>
  67660. * </div>
  67661. */
  67662. _main.default.TypedDict.prototype.print = function() {
  67663. for (var item in this.data) {
  67664. console.log('key:'.concat(item, ' value:').concat(this.data[item]));
  67665. }
  67666. };
  67667. /**
  67668. * Converts the Dictionary into a CSV file for local download.
  67669. *
  67670. * @method saveTable
  67671. * @example
  67672. * <div>
  67673. * <code>
  67674. * function setup() {
  67675. * createCanvas(100, 100);
  67676. * background(200);
  67677. * text('click here to save', 10, 10, 70, 80);
  67678. * }
  67679. *
  67680. * function mousePressed() {
  67681. * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
  67682. * createStringDict({
  67683. * john: 1940,
  67684. * paul: 1942,
  67685. * george: 1943,
  67686. * ringo: 1940
  67687. * }).saveTable('beatles');
  67688. * }
  67689. * }
  67690. * </code>
  67691. * </div>
  67692. */
  67693. _main.default.TypedDict.prototype.saveTable = function(filename) {
  67694. var output = '';
  67695. for (var key in this.data) {
  67696. output += ''.concat(key, ',').concat(this.data[key], '\n');
  67697. }
  67698. var blob = new Blob([output], { type: 'text/csv' });
  67699. _main.default.prototype.downloadFile(blob, filename || 'mycsv', 'csv');
  67700. };
  67701. /**
  67702. * Converts the Dictionary into a JSON file for local download.
  67703. *
  67704. * @method saveJSON
  67705. * @example
  67706. * <div>
  67707. * <code>
  67708. * function setup() {
  67709. * createCanvas(100, 100);
  67710. * background(200);
  67711. * text('click here to save', 10, 10, 70, 80);
  67712. * }
  67713. *
  67714. * function mousePressed() {
  67715. * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
  67716. * createStringDict({
  67717. * john: 1940,
  67718. * paul: 1942,
  67719. * george: 1943,
  67720. * ringo: 1940
  67721. * }).saveJSON('beatles');
  67722. * }
  67723. * }
  67724. * </code>
  67725. * </div>
  67726. */
  67727. _main.default.TypedDict.prototype.saveJSON = function(filename, opt) {
  67728. _main.default.prototype.saveJSON(this.data, filename, opt);
  67729. };
  67730. /**
  67731. * private helper function to ensure that the user passed in valid
  67732. * values for the Dictionary type
  67733. */
  67734. _main.default.TypedDict.prototype._validate = function(value) {
  67735. return true;
  67736. };
  67737. /**
  67738. *
  67739. * A simple Dictionary class for Strings.
  67740. *
  67741. * @class p5.StringDict
  67742. * @extends p5.TypedDict
  67743. */
  67744. _main.default.StringDict = function() {
  67745. for (
  67746. var _len = arguments.length, args = new Array(_len), _key = 0;
  67747. _key < _len;
  67748. _key++
  67749. ) {
  67750. args[_key] = arguments[_key];
  67751. }
  67752. _main.default.TypedDict.apply(this, args);
  67753. };
  67754. _main.default.StringDict.prototype = Object.create(
  67755. _main.default.TypedDict.prototype
  67756. );
  67757. _main.default.StringDict.prototype._validate = function(value) {
  67758. return typeof value === 'string';
  67759. };
  67760. /**
  67761. *
  67762. * A simple Dictionary class for Numbers.
  67763. *
  67764. * @class p5.NumberDict
  67765. * @constructor
  67766. * @extends p5.TypedDict
  67767. */
  67768. _main.default.NumberDict = function() {
  67769. for (
  67770. var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
  67771. _key2 < _len2;
  67772. _key2++
  67773. ) {
  67774. args[_key2] = arguments[_key2];
  67775. }
  67776. _main.default.TypedDict.apply(this, args);
  67777. };
  67778. _main.default.NumberDict.prototype = Object.create(
  67779. _main.default.TypedDict.prototype
  67780. );
  67781. /**
  67782. * private helper function to ensure that the user passed in valid
  67783. * values for the Dictionary type
  67784. */
  67785. _main.default.NumberDict.prototype._validate = function(value) {
  67786. return typeof value === 'number';
  67787. };
  67788. /**
  67789. * Add the given number to the value currently stored at the given key.
  67790. * The sum then replaces the value previously stored in the Dictionary.
  67791. *
  67792. * @method add
  67793. * @param {Number} Key for the value you wish to add to
  67794. * @param {Number} Number to add to the value
  67795. * @example
  67796. * <div class='norender'>
  67797. * <code>
  67798. * function setup() {
  67799. * let myDictionary = createNumberDict(2, 5);
  67800. * myDictionary.add(2, 2);
  67801. * print(myDictionary.get(2)); // logs 7 to console.
  67802. * }
  67803. * </code></div>
  67804. *
  67805. */
  67806. _main.default.NumberDict.prototype.add = function(key, amount) {
  67807. if (this.data.hasOwnProperty(key)) {
  67808. this.data[key] += amount;
  67809. } else {
  67810. console.log('The key - '.concat(key, ' does not exist in this dictionary.'));
  67811. }
  67812. };
  67813. /**
  67814. * Subtract the given number from the value currently stored at the given key.
  67815. * The difference then replaces the value previously stored in the Dictionary.
  67816. *
  67817. * @method sub
  67818. * @param {Number} Key for the value you wish to subtract from
  67819. * @param {Number} Number to subtract from the value
  67820. * @example
  67821. * <div class='norender'>
  67822. * <code>
  67823. * function setup() {
  67824. * let myDictionary = createNumberDict(2, 5);
  67825. * myDictionary.sub(2, 2);
  67826. * print(myDictionary.get(2)); // logs 3 to console.
  67827. * }
  67828. * </code></div>
  67829. *
  67830. */
  67831. _main.default.NumberDict.prototype.sub = function(key, amount) {
  67832. this.add(key, -amount);
  67833. };
  67834. /**
  67835. * Multiply the given number with the value currently stored at the given key.
  67836. * The product then replaces the value previously stored in the Dictionary.
  67837. *
  67838. * @method mult
  67839. * @param {Number} Key for value you wish to multiply
  67840. * @param {Number} Amount to multiply the value by
  67841. * @example
  67842. * <div class='norender'>
  67843. * <code>
  67844. * function setup() {
  67845. * let myDictionary = createNumberDict(2, 4);
  67846. * myDictionary.mult(2, 2);
  67847. * print(myDictionary.get(2)); // logs 8 to console.
  67848. * }
  67849. * </code></div>
  67850. *
  67851. */
  67852. _main.default.NumberDict.prototype.mult = function(key, amount) {
  67853. if (this.data.hasOwnProperty(key)) {
  67854. this.data[key] *= amount;
  67855. } else {
  67856. console.log('The key - '.concat(key, ' does not exist in this dictionary.'));
  67857. }
  67858. };
  67859. /**
  67860. * Divide the given number with the value currently stored at the given key.
  67861. * The quotient then replaces the value previously stored in the Dictionary.
  67862. *
  67863. * @method div
  67864. * @param {Number} Key for value you wish to divide
  67865. * @param {Number} Amount to divide the value by
  67866. * @example
  67867. * <div class='norender'>
  67868. * <code>
  67869. * function setup() {
  67870. * let myDictionary = createNumberDict(2, 8);
  67871. * myDictionary.div(2, 2);
  67872. * print(myDictionary.get(2)); // logs 4 to console.
  67873. * }
  67874. * </code></div>
  67875. *
  67876. */
  67877. _main.default.NumberDict.prototype.div = function(key, amount) {
  67878. if (this.data.hasOwnProperty(key)) {
  67879. this.data[key] /= amount;
  67880. } else {
  67881. console.log('The key - '.concat(key, ' does not exist in this dictionary.'));
  67882. }
  67883. };
  67884. /**
  67885. * private helper function for finding lowest or highest value
  67886. * the argument 'flip' is used to flip the comparison arrow
  67887. * from 'less than' to 'greater than'
  67888. */
  67889. _main.default.NumberDict.prototype._valueTest = function(flip) {
  67890. if (Object.keys(this.data).length === 0) {
  67891. throw new Error(
  67892. 'Unable to search for a minimum or maximum value on an empty NumberDict'
  67893. );
  67894. } else if (Object.keys(this.data).length === 1) {
  67895. return this.data[Object.keys(this.data)[0]];
  67896. } else {
  67897. var result = this.data[Object.keys(this.data)[0]];
  67898. for (var key in this.data) {
  67899. if (this.data[key] * flip < result * flip) {
  67900. result = this.data[key];
  67901. }
  67902. }
  67903. return result;
  67904. }
  67905. };
  67906. /**
  67907. * Return the lowest number currently stored in the Dictionary.
  67908. *
  67909. * @method minValue
  67910. * @return {Number}
  67911. * @example
  67912. * <div class='norender'>
  67913. * <code>
  67914. * function setup() {
  67915. * let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 });
  67916. * let lowestValue = myDictionary.minValue(); // value is -10
  67917. * print(lowestValue);
  67918. * }
  67919. * </code></div>
  67920. */
  67921. _main.default.NumberDict.prototype.minValue = function() {
  67922. return this._valueTest(1);
  67923. };
  67924. /**
  67925. * Return the highest number currently stored in the Dictionary.
  67926. *
  67927. * @method maxValue
  67928. * @return {Number}
  67929. * @example
  67930. * <div class='norender'>
  67931. * <code>
  67932. * function setup() {
  67933. * let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 });
  67934. * let highestValue = myDictionary.maxValue(); // value is 3
  67935. * print(highestValue);
  67936. * }
  67937. * </code></div>
  67938. */
  67939. _main.default.NumberDict.prototype.maxValue = function() {
  67940. return this._valueTest(-1);
  67941. };
  67942. /**
  67943. * private helper function for finding lowest or highest key
  67944. * the argument 'flip' is used to flip the comparison arrow
  67945. * from 'less than' to 'greater than'
  67946. */
  67947. _main.default.NumberDict.prototype._keyTest = function(flip) {
  67948. if (Object.keys(this.data).length === 0) {
  67949. throw new Error('Unable to use minValue on an empty NumberDict');
  67950. } else if (Object.keys(this.data).length === 1) {
  67951. return Object.keys(this.data)[0];
  67952. } else {
  67953. var result = Object.keys(this.data)[0];
  67954. for (var i = 1; i < Object.keys(this.data).length; i++) {
  67955. if (Object.keys(this.data)[i] * flip < result * flip) {
  67956. result = Object.keys(this.data)[i];
  67957. }
  67958. }
  67959. return result;
  67960. }
  67961. };
  67962. /**
  67963. * Return the lowest key currently used in the Dictionary.
  67964. *
  67965. * @method minKey
  67966. * @return {Number}
  67967. * @example
  67968. * <div class='norender'>
  67969. * <code>
  67970. * function setup() {
  67971. * let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 });
  67972. * let lowestKey = myDictionary.minKey(); // value is 1.2
  67973. * print(lowestKey);
  67974. * }
  67975. * </code></div>
  67976. */
  67977. _main.default.NumberDict.prototype.minKey = function() {
  67978. return this._keyTest(1);
  67979. };
  67980. /**
  67981. * Return the highest key currently used in the Dictionary.
  67982. *
  67983. * @method maxKey
  67984. * @return {Number}
  67985. * @example
  67986. * <div class='norender'>
  67987. * <code>
  67988. * function setup() {
  67989. * let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 });
  67990. * let highestKey = myDictionary.maxKey(); // value is 4
  67991. * print(highestKey);
  67992. * }
  67993. * </code></div>
  67994. */
  67995. _main.default.NumberDict.prototype.maxKey = function() {
  67996. return this._keyTest(-1);
  67997. };
  67998. var _default = _main.default.TypedDict;
  67999. exports.default = _default;
  68000. },
  68001. {
  68002. '../core/main': 283,
  68003. 'core-js/modules/es.array.concat': 166,
  68004. 'core-js/modules/es.object.keys': 191,
  68005. 'core-js/modules/es.string.sub': 207
  68006. }
  68007. ],
  68008. 299: [
  68009. function(_dereq_, module, exports) {
  68010. 'use strict';
  68011. _dereq_('core-js/modules/es.symbol');
  68012. _dereq_('core-js/modules/es.symbol.description');
  68013. _dereq_('core-js/modules/es.symbol.iterator');
  68014. _dereq_('core-js/modules/es.array.every');
  68015. _dereq_('core-js/modules/es.array.filter');
  68016. _dereq_('core-js/modules/es.array.for-each');
  68017. _dereq_('core-js/modules/es.array.from');
  68018. _dereq_('core-js/modules/es.array.index-of');
  68019. _dereq_('core-js/modules/es.array.iterator');
  68020. _dereq_('core-js/modules/es.array.map');
  68021. _dereq_('core-js/modules/es.array.slice');
  68022. _dereq_('core-js/modules/es.array.splice');
  68023. _dereq_('core-js/modules/es.function.name');
  68024. _dereq_('core-js/modules/es.object.to-string');
  68025. _dereq_('core-js/modules/es.promise');
  68026. _dereq_('core-js/modules/es.regexp.exec');
  68027. _dereq_('core-js/modules/es.regexp.to-string');
  68028. _dereq_('core-js/modules/es.string.iterator');
  68029. _dereq_('core-js/modules/es.string.replace');
  68030. _dereq_('core-js/modules/es.string.split');
  68031. _dereq_('core-js/modules/es.string.trim');
  68032. _dereq_('core-js/modules/web.dom-collections.for-each');
  68033. _dereq_('core-js/modules/web.dom-collections.iterator');
  68034. _dereq_('core-js/modules/web.url');
  68035. Object.defineProperty(exports, '__esModule', { value: true });
  68036. exports.default = void 0;
  68037. var _main = _interopRequireDefault(_dereq_('../core/main'));
  68038. function _interopRequireDefault(obj) {
  68039. return obj && obj.__esModule ? obj : { default: obj };
  68040. }
  68041. function _typeof(obj) {
  68042. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  68043. _typeof = function _typeof(obj) {
  68044. return typeof obj;
  68045. };
  68046. } else {
  68047. _typeof = function _typeof(obj) {
  68048. return obj &&
  68049. typeof Symbol === 'function' &&
  68050. obj.constructor === Symbol &&
  68051. obj !== Symbol.prototype
  68052. ? 'symbol'
  68053. : typeof obj;
  68054. };
  68055. }
  68056. return _typeof(obj);
  68057. }
  68058. /**
  68059. * Searches the page for the first element that matches the given CSS selector string (can be an
  68060. * ID, class, tag name or a combination) and returns it as a <a href="#/p5.Element">p5.Element</a>.
  68061. * The DOM node itself can be accessed with .elt.
  68062. * Returns null if none found. You can also specify a container to search within.
  68063. *
  68064. * @method select
  68065. * @param {String} selectors CSS selector string of element to search for
  68066. * @param {String|p5.Element|HTMLElement} [container] CSS selector string, <a href="#/p5.Element">p5.Element</a>, or
  68067. * HTML element to search within
  68068. * @return {p5.Element|null} <a href="#/p5.Element">p5.Element</a> containing node found
  68069. * @example
  68070. * <div><code>
  68071. * function setup() {
  68072. * createCanvas(50, 50);
  68073. * background(30);
  68074. * // move canvas down and right
  68075. * select('canvas').position(10, 30);
  68076. * }
  68077. * </code></div>
  68078. *
  68079. * <div class="norender"><code>
  68080. * // select using ID
  68081. * let a = select('#container');
  68082. * let b = select('#beep', '#container');
  68083. * let c;
  68084. * if (a) {
  68085. * // select using class
  68086. * c = select('.boop', a);
  68087. * }
  68088. * // select using CSS selector string
  68089. * let d = select('#container #bleep');
  68090. * let e = select('#container p');
  68091. * [a, b, c, d, e]; // unused
  68092. * </code></div>
  68093. */
  68094. _main.default.prototype.select = function(e, p) {
  68095. _main.default._validateParameters('select', arguments);
  68096. var container = this._getContainer(p);
  68097. var res = container.querySelector(e);
  68098. if (res) {
  68099. return this._wrapElement(res);
  68100. } else {
  68101. return null;
  68102. }
  68103. };
  68104. /**
  68105. * Searches the page for elements that match the given CSS selector string (can be an ID a class,
  68106. * tag name or a combination) and returns them as <a href="#/p5.Element">p5.Element</a>s in
  68107. * an array.
  68108. * The DOM node itself can be accessed with .elt.
  68109. * Returns an empty array if none found.
  68110. * You can also specify a container to search within.
  68111. *
  68112. * @method selectAll
  68113. * @param {String} selectors CSS selector string of elements to search for
  68114. * @param {String|p5.Element|HTMLElement} [container] CSS selector string, <a href="#/p5.Element">p5.Element</a>
  68115. * , or HTML element to search within
  68116. * @return {p5.Element[]} Array of <a href="#/p5.Element">p5.Element</a>s containing nodes found
  68117. * @example
  68118. * <div><code>
  68119. * function setup() {
  68120. * createButton('btn');
  68121. * createButton('2nd btn');
  68122. * createButton('3rd btn');
  68123. * let buttons = selectAll('button');
  68124. *
  68125. * for (let i = 0; i < 3; i++) {
  68126. * buttons[i].size(100);
  68127. * buttons[i].position(0, i * 30);
  68128. * }
  68129. * }
  68130. * </code></div>
  68131. * <div><code>
  68132. * // these are all valid calls to selectAll()
  68133. * let a = selectAll('.beep');
  68134. * a = selectAll('div');
  68135. * a = selectAll('button', '#container');
  68136. *
  68137. * let b = createDiv();
  68138. * b.id('container');
  68139. * let c = select('#container');
  68140. * a = selectAll('p', c);
  68141. * a = selectAll('#container p');
  68142. *
  68143. * let d = document.getElementById('container');
  68144. * a = selectAll('.boop', d);
  68145. * a = selectAll('#container .boop');
  68146. * console.log(a);
  68147. * </code></div>
  68148. */
  68149. _main.default.prototype.selectAll = function(e, p) {
  68150. _main.default._validateParameters('selectAll', arguments);
  68151. var arr = [];
  68152. var container = this._getContainer(p);
  68153. var res = container.querySelectorAll(e);
  68154. if (res) {
  68155. for (var j = 0; j < res.length; j++) {
  68156. var obj = this._wrapElement(res[j]);
  68157. arr.push(obj);
  68158. }
  68159. }
  68160. return arr;
  68161. };
  68162. /**
  68163. * Helper function for select and selectAll
  68164. */
  68165. _main.default.prototype._getContainer = function(p) {
  68166. var container = document;
  68167. if (typeof p === 'string') {
  68168. container = document.querySelector(p) || document;
  68169. } else if (p instanceof _main.default.Element) {
  68170. container = p.elt;
  68171. } else if (p instanceof HTMLElement) {
  68172. container = p;
  68173. }
  68174. return container;
  68175. };
  68176. /**
  68177. * Helper function for getElement and getElements.
  68178. */
  68179. _main.default.prototype._wrapElement = function(elt) {
  68180. var children = Array.prototype.slice.call(elt.children);
  68181. if (elt.tagName === 'INPUT' && elt.type === 'checkbox') {
  68182. var converted = new _main.default.Element(elt, this);
  68183. converted.checked = function() {
  68184. if (arguments.length === 0) {
  68185. return this.elt.checked;
  68186. } else if (arguments[0]) {
  68187. this.elt.checked = true;
  68188. } else {
  68189. this.elt.checked = false;
  68190. }
  68191. return this;
  68192. };
  68193. return converted;
  68194. } else if (elt.tagName === 'VIDEO' || elt.tagName === 'AUDIO') {
  68195. return new _main.default.MediaElement(elt, this);
  68196. } else if (elt.tagName === 'SELECT') {
  68197. return this.createSelect(new _main.default.Element(elt, this));
  68198. } else if (
  68199. children.length > 0 &&
  68200. children.every(function(c) {
  68201. return c.tagName === 'INPUT' || c.tagName === 'LABEL';
  68202. })
  68203. ) {
  68204. return this.createRadio(new _main.default.Element(elt, this));
  68205. } else {
  68206. return new _main.default.Element(elt, this);
  68207. }
  68208. };
  68209. /**
  68210. * Removes all elements created by p5, except any canvas / graphics
  68211. * elements created by <a href="#/p5/createCanvas">createCanvas</a> or <a href="#/p5/createGraphics">createGraphics</a>.
  68212. * Event handlers are removed, and element is removed from the DOM.
  68213. * @method removeElements
  68214. * @example
  68215. * <div><code>
  68216. * function setup() {
  68217. * createCanvas(100, 100);
  68218. * background('grey');
  68219. * let div = createDiv('this is some text');
  68220. * let p = createP('this is a paragraph');
  68221. * div.style('font-size', '16px');
  68222. * p.style('font-size', '16px');
  68223. * }
  68224. * function mousePressed() {
  68225. * removeElements(); // this will remove the div and p, not canvas
  68226. * }
  68227. * </code></div>
  68228. */
  68229. _main.default.prototype.removeElements = function(e) {
  68230. _main.default._validateParameters('removeElements', arguments);
  68231. // el.remove splices from this._elements, so don't mix iteration with it
  68232. var isNotCanvasElement = function isNotCanvasElement(el) {
  68233. return !(el.elt instanceof HTMLCanvasElement);
  68234. };
  68235. var removeableElements = this._elements.filter(isNotCanvasElement);
  68236. removeableElements.map(function(el) {
  68237. return el.remove();
  68238. });
  68239. };
  68240. /**
  68241. * The .<a href="#/p5.Element/changed">changed()</a> function is called when the value of an
  68242. * element changes.
  68243. * This can be used to attach an element specific event listener.
  68244. *
  68245. * @method changed
  68246. * @param {Function|Boolean} fxn function to be fired when the value of
  68247. * an element changes.
  68248. * if `false` is passed instead, the previously
  68249. * firing function will no longer fire.
  68250. * @chainable
  68251. * @example
  68252. * <div><code>
  68253. * let sel;
  68254. *
  68255. * function setup() {
  68256. * textAlign(CENTER);
  68257. * background(200);
  68258. * sel = createSelect();
  68259. * sel.position(10, 10);
  68260. * sel.option('pear');
  68261. * sel.option('kiwi');
  68262. * sel.option('grape');
  68263. * sel.changed(mySelectEvent);
  68264. * }
  68265. *
  68266. * function mySelectEvent() {
  68267. * let item = sel.value();
  68268. * background(200);
  68269. * text("it's a " + item + '!', 50, 50);
  68270. * }
  68271. * </code></div>
  68272. *
  68273. * <div><code>
  68274. * let checkbox;
  68275. * let cnv;
  68276. *
  68277. * function setup() {
  68278. * checkbox = createCheckbox(' fill');
  68279. * checkbox.changed(changeFill);
  68280. * cnv = createCanvas(100, 100);
  68281. * cnv.position(0, 30);
  68282. * noFill();
  68283. * }
  68284. *
  68285. * function draw() {
  68286. * background(200);
  68287. * ellipse(50, 50, 50, 50);
  68288. * }
  68289. *
  68290. * function changeFill() {
  68291. * if (checkbox.checked()) {
  68292. * fill(0);
  68293. * } else {
  68294. * noFill();
  68295. * }
  68296. * }
  68297. * </code></div>
  68298. *
  68299. * @alt
  68300. * dropdown: pear, kiwi, grape. When selected text "its a" + selection shown.
  68301. */
  68302. _main.default.Element.prototype.changed = function(fxn) {
  68303. _main.default.Element._adjustListener('change', fxn, this);
  68304. return this;
  68305. };
  68306. /**
  68307. * The .<a href="#/p5.Element/input">input()</a> function is called when any user input is
  68308. * detected with an element. The input event is often used
  68309. * to detect keystrokes in a input element, or changes on a
  68310. * slider element. This can be used to attach an element specific
  68311. * event listener.
  68312. *
  68313. * @method input
  68314. * @param {Function|Boolean} fxn function to be fired when any user input is
  68315. * detected within the element.
  68316. * if `false` is passed instead, the previously
  68317. * firing function will no longer fire.
  68318. * @chainable
  68319. * @example
  68320. * <div><code>
  68321. * // Open your console to see the output
  68322. * function setup() {
  68323. * createCanvas(100, 100);
  68324. * background('grey');
  68325. * let inp = createInput('');
  68326. * inp.position(0, 0);
  68327. * inp.size(100);
  68328. * inp.input(myInputEvent);
  68329. * }
  68330. *
  68331. * function myInputEvent() {
  68332. * console.log('you are typing: ', this.value());
  68333. * }
  68334. * </code></div>
  68335. *
  68336. * @alt
  68337. * no display.
  68338. */
  68339. _main.default.Element.prototype.input = function(fxn) {
  68340. _main.default.Element._adjustListener('input', fxn, this);
  68341. return this;
  68342. };
  68343. /**
  68344. * Helpers for create methods.
  68345. */
  68346. function addElement(elt, pInst, media) {
  68347. var node = pInst._userNode ? pInst._userNode : document.body;
  68348. node.appendChild(elt);
  68349. var c = media
  68350. ? new _main.default.MediaElement(elt, pInst)
  68351. : new _main.default.Element(elt, pInst);
  68352. pInst._elements.push(c);
  68353. return c;
  68354. }
  68355. /**
  68356. * Creates a `&lt;div&gt;&lt;/div&gt;` element in the DOM with given inner HTML.
  68357. *
  68358. * @method createDiv
  68359. * @param {String} [html] inner HTML for element created
  68360. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  68361. * @example
  68362. * <div><code>
  68363. * let div = createDiv('this is some text');
  68364. * div.style('font-size', '16px');
  68365. * div.position(10, 0);
  68366. * </code></div>
  68367. */
  68368. _main.default.prototype.createDiv = function() {
  68369. var html =
  68370. arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  68371. var elt = document.createElement('div');
  68372. elt.innerHTML = html;
  68373. return addElement(elt, this);
  68374. };
  68375. /**
  68376. * Creates a `&lt;p&gt;&lt;/p&gt;` element in the DOM with given inner HTML. Used
  68377. * for paragraph length text.
  68378. *
  68379. * @method createP
  68380. * @param {String} [html] inner HTML for element created
  68381. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  68382. * @example
  68383. * <div><code>
  68384. * let p = createP('this is some text');
  68385. * p.style('font-size', '16px');
  68386. * p.position(10, 0);
  68387. * </code></div>
  68388. */
  68389. _main.default.prototype.createP = function() {
  68390. var html =
  68391. arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  68392. var elt = document.createElement('p');
  68393. elt.innerHTML = html;
  68394. return addElement(elt, this);
  68395. };
  68396. /**
  68397. * Creates a `&lt;span&gt;&lt;/span&gt;` element in the DOM with given inner HTML.
  68398. *
  68399. * @method createSpan
  68400. * @param {String} [html] inner HTML for element created
  68401. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  68402. * @example
  68403. * <div><code>
  68404. * let span = createSpan('this is some text');
  68405. * span.position(0, 0);
  68406. * </code></div>
  68407. */
  68408. _main.default.prototype.createSpan = function() {
  68409. var html =
  68410. arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  68411. var elt = document.createElement('span');
  68412. elt.innerHTML = html;
  68413. return addElement(elt, this);
  68414. };
  68415. /**
  68416. * Creates an `&lt;img&gt;` element in the DOM with given src and
  68417. * alternate text.
  68418. *
  68419. * @method createImg
  68420. * @param {String} src src path or url for image
  68421. * @param {String} alt <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Img#Attributes">alternate text</a> to be used if image does not load. You can use also an empty string (`""`) if that an image is not intended to be viewed.
  68422. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  68423. * @example
  68424. * <div><code>
  68425. * let img = createImg(
  68426. * 'https://p5js.org/assets/img/asterisk-01.png',
  68427. * 'the p5 magenta asterisk'
  68428. * );
  68429. * img.position(0, -10);
  68430. * </code></div>
  68431. */
  68432. /**
  68433. * @method createImg
  68434. * @param {String} src
  68435. * @param {String} alt
  68436. * @param {String} crossOrigin <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes">crossOrigin property</a> of the `img` element; use either 'anonymous' or 'use-credentials' to retrieve the image with cross-origin access (for later use with `canvas`. if an empty string(`""`) is passed, CORS is not used
  68437. * @param {Function} [successCallback] callback to be called once image data is loaded with the <a href="#/p5.Element">p5.Element</a> as argument
  68438. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  68439. */
  68440. _main.default.prototype.createImg = function() {
  68441. _main.default._validateParameters('createImg', arguments);
  68442. var elt = document.createElement('img');
  68443. var args = arguments;
  68444. var self;
  68445. if (args.length > 1 && typeof args[1] === 'string') {
  68446. elt.alt = args[1];
  68447. }
  68448. if (args.length > 2 && typeof args[2] === 'string') {
  68449. elt.crossOrigin = args[2];
  68450. }
  68451. elt.src = args[0];
  68452. self = addElement(elt, this);
  68453. elt.addEventListener('load', function() {
  68454. self.width = elt.offsetWidth || elt.width;
  68455. self.height = elt.offsetHeight || elt.height;
  68456. var last = args[args.length - 1];
  68457. if (typeof last === 'function') last(self);
  68458. });
  68459. return self;
  68460. };
  68461. /**
  68462. * Creates an `&lt;a&gt;&lt;/a&gt;` element in the DOM for including a hyperlink.
  68463. *
  68464. * @method createA
  68465. * @param {String} href url of page to link to
  68466. * @param {String} html inner html of link element to display
  68467. * @param {String} [target] target where new link should open,
  68468. * could be _blank, _self, _parent, _top.
  68469. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  68470. * @example
  68471. * <div><code>
  68472. * let a = createA('http://p5js.org/', 'this is a link');
  68473. * a.position(0, 0);
  68474. * </code></div>
  68475. */
  68476. _main.default.prototype.createA = function(href, html, target) {
  68477. _main.default._validateParameters('createA', arguments);
  68478. var elt = document.createElement('a');
  68479. elt.href = href;
  68480. elt.innerHTML = html;
  68481. if (target) elt.target = target;
  68482. return addElement(elt, this);
  68483. };
  68484. /** INPUT **/
  68485. /**
  68486. * Creates a slider `&lt;input&gt;&lt;/input&gt;` element in the DOM.
  68487. * Use .size() to set the display length of the slider.
  68488. *
  68489. * @method createSlider
  68490. * @param {Number} min minimum value of the slider
  68491. * @param {Number} max maximum value of the slider
  68492. * @param {Number} [value] default value of the slider
  68493. * @param {Number} [step] step size for each tick of the slider (if step is set to 0, the slider will move continuously from the minimum to the maximum value)
  68494. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  68495. * @example
  68496. * <div><code>
  68497. * let slider;
  68498. * function setup() {
  68499. * slider = createSlider(0, 255, 100);
  68500. * slider.position(10, 10);
  68501. * slider.style('width', '80px');
  68502. * }
  68503. *
  68504. * function draw() {
  68505. * let val = slider.value();
  68506. * background(val);
  68507. * }
  68508. * </code></div>
  68509. *
  68510. * <div><code>
  68511. * let slider;
  68512. * function setup() {
  68513. * colorMode(HSB);
  68514. * slider = createSlider(0, 360, 60, 40);
  68515. * slider.position(10, 10);
  68516. * slider.style('width', '80px');
  68517. * }
  68518. *
  68519. * function draw() {
  68520. * let val = slider.value();
  68521. * background(val, 100, 100, 1);
  68522. * }
  68523. * </code></div>
  68524. */
  68525. _main.default.prototype.createSlider = function(min, max, value, step) {
  68526. _main.default._validateParameters('createSlider', arguments);
  68527. var elt = document.createElement('input');
  68528. elt.type = 'range';
  68529. elt.min = min;
  68530. elt.max = max;
  68531. if (step === 0) {
  68532. elt.step = 0.000000000000000001; // smallest valid step
  68533. } else if (step) {
  68534. elt.step = step;
  68535. }
  68536. if (typeof value === 'number') elt.value = value;
  68537. return addElement(elt, this);
  68538. };
  68539. /**
  68540. * Creates a `&lt;button&gt;&lt;/button&gt;` element in the DOM.
  68541. * Use .size() to set the display size of the button.
  68542. * Use .mousePressed() to specify behavior on press.
  68543. *
  68544. * @method createButton
  68545. * @param {String} label label displayed on the button
  68546. * @param {String} [value] value of the button
  68547. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  68548. * @example
  68549. * <div><code>
  68550. * let button;
  68551. * function setup() {
  68552. * createCanvas(100, 100);
  68553. * background(0);
  68554. * button = createButton('click me');
  68555. * button.position(0, 0);
  68556. * button.mousePressed(changeBG);
  68557. * }
  68558. *
  68559. * function changeBG() {
  68560. * let val = random(255);
  68561. * background(val);
  68562. * }
  68563. * </code></div>
  68564. */
  68565. _main.default.prototype.createButton = function(label, value) {
  68566. _main.default._validateParameters('createButton', arguments);
  68567. var elt = document.createElement('button');
  68568. elt.innerHTML = label;
  68569. if (value) elt.value = value;
  68570. return addElement(elt, this);
  68571. };
  68572. /**
  68573. * Creates a checkbox `&lt;input&gt;&lt;/input&gt;` element in the DOM.
  68574. * Calling .checked() on a checkbox returns if it is checked or not
  68575. *
  68576. * @method createCheckbox
  68577. * @param {String} [label] label displayed after checkbox
  68578. * @param {boolean} [value] value of the checkbox; checked is true, unchecked is false
  68579. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  68580. * @example
  68581. * <div><code>
  68582. * let checkbox;
  68583. *
  68584. * function setup() {
  68585. * checkbox = createCheckbox('label', false);
  68586. * checkbox.changed(myCheckedEvent);
  68587. * }
  68588. *
  68589. * function myCheckedEvent() {
  68590. * if (this.checked()) {
  68591. * console.log('Checking!');
  68592. * } else {
  68593. * console.log('Unchecking!');
  68594. * }
  68595. * }
  68596. * </code></div>
  68597. */
  68598. _main.default.prototype.createCheckbox = function() {
  68599. _main.default._validateParameters('createCheckbox', arguments);
  68600. var elt = document.createElement('div');
  68601. var checkbox = document.createElement('input');
  68602. checkbox.type = 'checkbox';
  68603. elt.appendChild(checkbox);
  68604. //checkbox must be wrapped in p5.Element before label so that label appears after
  68605. var self = addElement(elt, this);
  68606. self.checked = function() {
  68607. var cb = self.elt.getElementsByTagName('input')[0];
  68608. if (cb) {
  68609. if (arguments.length === 0) {
  68610. return cb.checked;
  68611. } else if (arguments[0]) {
  68612. cb.checked = true;
  68613. } else {
  68614. cb.checked = false;
  68615. }
  68616. }
  68617. return self;
  68618. };
  68619. this.value = function(val) {
  68620. self.value = val;
  68621. return this;
  68622. };
  68623. if (arguments[0]) {
  68624. var ran = Math.random()
  68625. .toString(36)
  68626. .slice(2);
  68627. var label = document.createElement('label');
  68628. checkbox.setAttribute('id', ran);
  68629. label.htmlFor = ran;
  68630. self.value(arguments[0]);
  68631. label.appendChild(document.createTextNode(arguments[0]));
  68632. elt.appendChild(label);
  68633. }
  68634. if (arguments[1]) {
  68635. checkbox.checked = true;
  68636. }
  68637. return self;
  68638. };
  68639. /**
  68640. * Creates a dropdown menu `&lt;select&gt;&lt;/select&gt;` element in the DOM.
  68641. * It also helps to assign select-box methods to <a href="#/p5.Element">p5.Element</a> when selecting existing select box.
  68642. * - `.option(name, [value])` can be used to set options for the select after it is created.
  68643. * - `.value()` will return the currently selected option.
  68644. * - `.selected()` will return current dropdown element which is an instance of <a href="#/p5.Element">p5.Element</a>
  68645. * - `.selected(value)` can be used to make given option selected by default when the page first loads.
  68646. * - `.disable()` marks whole of dropdown element as disabled.
  68647. * - `.disable(value)` marks given option as disabled
  68648. *
  68649. * @method createSelect
  68650. * @param {boolean} [multiple] true if dropdown should support multiple selections
  68651. * @return {p5.Element}
  68652. * @example
  68653. * <div><code>
  68654. * let sel;
  68655. *
  68656. * function setup() {
  68657. * textAlign(CENTER);
  68658. * background(200);
  68659. * sel = createSelect();
  68660. * sel.position(10, 10);
  68661. * sel.option('pear');
  68662. * sel.option('kiwi');
  68663. * sel.option('grape');
  68664. * sel.selected('kiwi');
  68665. * sel.changed(mySelectEvent);
  68666. * }
  68667. *
  68668. * function mySelectEvent() {
  68669. * let item = sel.value();
  68670. * background(200);
  68671. * text('It is a ' + item + '!', 50, 50);
  68672. * }
  68673. * </code></div>
  68674. *
  68675. * <div><code>
  68676. * let sel;
  68677. *
  68678. * function setup() {
  68679. * textAlign(CENTER);
  68680. * background(200);
  68681. * sel = createSelect();
  68682. * sel.position(10, 10);
  68683. * sel.option('oil');
  68684. * sel.option('milk');
  68685. * sel.option('bread');
  68686. * sel.disable('milk');
  68687. * }
  68688. * </code></div>
  68689. */
  68690. /**
  68691. * @method createSelect
  68692. * @param {Object} existing DOM select element
  68693. * @return {p5.Element}
  68694. */
  68695. _main.default.prototype.createSelect = function() {
  68696. _main.default._validateParameters('createSelect', arguments);
  68697. var self;
  68698. var arg = arguments[0];
  68699. if (
  68700. arg instanceof _main.default.Element &&
  68701. arg.elt instanceof HTMLSelectElement
  68702. ) {
  68703. // If given argument is p5.Element of select type
  68704. self = arg;
  68705. this.elt = arg.elt;
  68706. } else if (arg instanceof HTMLSelectElement) {
  68707. self = addElement(arg, this);
  68708. this.elt = arg;
  68709. } else {
  68710. var elt = document.createElement('select');
  68711. if (arg && typeof arg === 'boolean') {
  68712. elt.setAttribute('multiple', 'true');
  68713. }
  68714. self = addElement(elt, this);
  68715. this.elt = elt;
  68716. }
  68717. self.option = function(name, value) {
  68718. var index;
  68719. // if no name is passed, return
  68720. if (name === undefined) {
  68721. return;
  68722. }
  68723. //see if there is already an option with this name
  68724. for (var i = 0; i < this.elt.length; i += 1) {
  68725. if (this.elt[i].innerHTML === name) {
  68726. index = i;
  68727. break;
  68728. }
  68729. }
  68730. //if there is an option with this name we will modify it
  68731. if (index !== undefined) {
  68732. //if the user passed in false then delete that option
  68733. if (value === false) {
  68734. this.elt.remove(index);
  68735. } else {
  68736. // Update the option at index with the value
  68737. this.elt[index].value = value;
  68738. }
  68739. } else {
  68740. //if it doesn't exist create it
  68741. var opt = document.createElement('option');
  68742. opt.innerHTML = name;
  68743. opt.value = value === undefined ? name : value;
  68744. this.elt.appendChild(opt);
  68745. this._pInst._elements.push(opt);
  68746. }
  68747. };
  68748. self.selected = function(value) {
  68749. // Update selected status of option
  68750. if (value !== undefined) {
  68751. for (var i = 0; i < this.elt.length; i += 1) {
  68752. if (this.elt[i].value.toString() === value.toString()) {
  68753. this.elt.selectedIndex = i;
  68754. }
  68755. }
  68756. return this;
  68757. } else {
  68758. if (this.elt.getAttribute('multiple')) {
  68759. var arr = [];
  68760. var _iteratorNormalCompletion = true;
  68761. var _didIteratorError = false;
  68762. var _iteratorError = undefined;
  68763. try {
  68764. for (
  68765. var _iterator = this.elt.selectedOptions[Symbol.iterator](), _step;
  68766. !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
  68767. _iteratorNormalCompletion = true
  68768. ) {
  68769. var selectedOption = _step.value;
  68770. arr.push(selectedOption.value);
  68771. }
  68772. } catch (err) {
  68773. _didIteratorError = true;
  68774. _iteratorError = err;
  68775. } finally {
  68776. try {
  68777. if (!_iteratorNormalCompletion && _iterator.return != null) {
  68778. _iterator.return();
  68779. }
  68780. } finally {
  68781. if (_didIteratorError) {
  68782. throw _iteratorError;
  68783. }
  68784. }
  68785. }
  68786. return arr;
  68787. } else {
  68788. return this.elt.value;
  68789. }
  68790. }
  68791. };
  68792. self.disable = function(value) {
  68793. if (typeof value === 'string') {
  68794. for (var i = 0; i < this.elt.length; i++) {
  68795. if (this.elt[i].value.toString() === value) {
  68796. this.elt[i].disabled = true;
  68797. this.elt[i].selected = false;
  68798. }
  68799. }
  68800. } else {
  68801. this.elt.disabled = true;
  68802. }
  68803. return this;
  68804. };
  68805. return self;
  68806. };
  68807. /**
  68808. * Creates a radio button element in the DOM.It also helps existing radio buttons
  68809. * assign methods of <a href="#/p5.Element/">p5.Element</a>.
  68810. * - `.option(value, [label])` can be used to create a new option for the
  68811. * element. If an option with a value already exists, it will be returned.
  68812. * Optionally, a label can be provided as second argument for the option.
  68813. * - `.remove(value)` can be used to remove an option for the element.
  68814. * - `.value()` method will return the currently selected value.
  68815. * - `.selected()` method will return the currently selected input element.
  68816. * - `.selected(value)` method will select the option and return it.
  68817. * - `.disable(Boolean)` method will enable/disable the whole radio button element.
  68818. *
  68819. * @method createRadio
  68820. * @param {Object} containerElement An container HTML Element either a div
  68821. * or span inside which all existing radio inputs will be considered as options.
  68822. * @param {string} [name] A name parameter for each Input Element.
  68823. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  68824. * @example
  68825. * <div><code>
  68826. * let radio;
  68827. *
  68828. * function setup() {
  68829. * radio = createRadio();
  68830. * radio.option('black');
  68831. * radio.option('white');
  68832. * radio.option('gray');
  68833. * radio.style('width', '60px');
  68834. * textAlign(CENTER);
  68835. * fill(255, 0, 0);
  68836. * }
  68837. *
  68838. * function draw() {
  68839. * let val = radio.value();
  68840. * background(val);
  68841. * text(val, width / 2, height / 2);
  68842. * }
  68843. * </code></div>
  68844. * <div><code>
  68845. * let radio;
  68846. *
  68847. * function setup() {
  68848. * radio = createRadio();
  68849. * radio.option(1, 'apple');
  68850. * radio.option(2, 'bread');
  68851. * radio.option(3, 'juice');
  68852. * radio.style('width', '30px');
  68853. * textAlign(CENTER);
  68854. * }
  68855. *
  68856. * function draw() {
  68857. * background(200);
  68858. * let val = radio.value();
  68859. * if (val) {
  68860. * text('item cost is $' + val, width / 2, height / 2);
  68861. * }
  68862. * }
  68863. * </code></div>
  68864. */
  68865. /**
  68866. * @method createRadio
  68867. * @param {String} name
  68868. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  68869. */
  68870. /**
  68871. * @method createRadio
  68872. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  68873. */
  68874. _main.default.prototype.createRadio = function() {
  68875. // Creates a div, adds each option as an individual input inside it.
  68876. // If already given with a containerEl, will search for all input[radio]
  68877. // it, create a p5.Element out of it, add options to it and return the p5.Element.
  68878. var radioElement;
  68879. var name;
  68880. var arg0 = arguments[0];
  68881. // If existing radio Element is provided as argument 0
  68882. if (arg0 instanceof HTMLDivElement || arg0 instanceof HTMLSpanElement) {
  68883. radioElement = arg0;
  68884. if (typeof arguments[1] === 'string') name = arguments[1];
  68885. } else {
  68886. if (typeof arg0 === 'string') name = arg0;
  68887. radioElement = document.createElement('div');
  68888. }
  68889. this.elt = radioElement;
  68890. var self = addElement(radioElement, this);
  68891. self._name = name || 'radioOption';
  68892. // setup member functions
  68893. var isRadioInput = function isRadioInput(el) {
  68894. return el instanceof HTMLInputElement && el.type === 'radio';
  68895. };
  68896. var isNextLabel = function isNextLabel(el) {
  68897. return el.nextElementSibling instanceof HTMLLabelElement;
  68898. };
  68899. self._getOptionsArray = function() {
  68900. return Array.from(this.elt.children).filter(isRadioInput);
  68901. };
  68902. self.option = function(value, label) {
  68903. // return an option with this value, create if not exists.
  68904. var optionEl;
  68905. var _iteratorNormalCompletion2 = true;
  68906. var _didIteratorError2 = false;
  68907. var _iteratorError2 = undefined;
  68908. try {
  68909. for (
  68910. var _iterator2 = self._getOptionsArray()[Symbol.iterator](), _step2;
  68911. !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);
  68912. _iteratorNormalCompletion2 = true
  68913. ) {
  68914. var option = _step2.value;
  68915. if (option.value === value) {
  68916. optionEl = option;
  68917. break;
  68918. }
  68919. }
  68920. // Create a new option, add it to radioElement and return it.
  68921. } catch (err) {
  68922. _didIteratorError2 = true;
  68923. _iteratorError2 = err;
  68924. } finally {
  68925. try {
  68926. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  68927. _iterator2.return();
  68928. }
  68929. } finally {
  68930. if (_didIteratorError2) {
  68931. throw _iteratorError2;
  68932. }
  68933. }
  68934. }
  68935. if (optionEl === undefined) {
  68936. optionEl = document.createElement('input');
  68937. optionEl.setAttribute('type', 'radio');
  68938. optionEl.setAttribute('value', value);
  68939. this.elt.appendChild(optionEl);
  68940. }
  68941. // Check if label element exists, else create it
  68942. var labelElement;
  68943. if (!isNextLabel(optionEl)) {
  68944. labelElement = document.createElement('label');
  68945. optionEl.insertAdjacentElement('afterend', labelElement);
  68946. } else {
  68947. labelElement = optionEl.nextElementSibling;
  68948. }
  68949. labelElement.innerHTML = label === undefined ? value : label;
  68950. optionEl.setAttribute('name', self._name);
  68951. return optionEl;
  68952. };
  68953. self.remove = function(value) {
  68954. var _iteratorNormalCompletion3 = true;
  68955. var _didIteratorError3 = false;
  68956. var _iteratorError3 = undefined;
  68957. try {
  68958. for (
  68959. var _iterator3 = self._getOptionsArray()[Symbol.iterator](), _step3;
  68960. !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done);
  68961. _iteratorNormalCompletion3 = true
  68962. ) {
  68963. var optionEl = _step3.value;
  68964. if (optionEl.value === value) {
  68965. if (isNextLabel(optionEl)) optionEl.nextElementSibling.remove();
  68966. optionEl.remove();
  68967. return;
  68968. }
  68969. }
  68970. } catch (err) {
  68971. _didIteratorError3 = true;
  68972. _iteratorError3 = err;
  68973. } finally {
  68974. try {
  68975. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  68976. _iterator3.return();
  68977. }
  68978. } finally {
  68979. if (_didIteratorError3) {
  68980. throw _iteratorError3;
  68981. }
  68982. }
  68983. }
  68984. };
  68985. self.value = function() {
  68986. var result = '';
  68987. var _iteratorNormalCompletion4 = true;
  68988. var _didIteratorError4 = false;
  68989. var _iteratorError4 = undefined;
  68990. try {
  68991. for (
  68992. var _iterator4 = self._getOptionsArray()[Symbol.iterator](), _step4;
  68993. !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done);
  68994. _iteratorNormalCompletion4 = true
  68995. ) {
  68996. var option = _step4.value;
  68997. if (option.checked) {
  68998. result = option.value;
  68999. break;
  69000. }
  69001. }
  69002. } catch (err) {
  69003. _didIteratorError4 = true;
  69004. _iteratorError4 = err;
  69005. } finally {
  69006. try {
  69007. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  69008. _iterator4.return();
  69009. }
  69010. } finally {
  69011. if (_didIteratorError4) {
  69012. throw _iteratorError4;
  69013. }
  69014. }
  69015. }
  69016. return result;
  69017. };
  69018. self.selected = function(value) {
  69019. var result = null;
  69020. if (value === undefined) {
  69021. var _iteratorNormalCompletion5 = true;
  69022. var _didIteratorError5 = false;
  69023. var _iteratorError5 = undefined;
  69024. try {
  69025. for (
  69026. var _iterator5 = self._getOptionsArray()[Symbol.iterator](), _step5;
  69027. !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done);
  69028. _iteratorNormalCompletion5 = true
  69029. ) {
  69030. var option = _step5.value;
  69031. if (option.checked) {
  69032. result = option;
  69033. break;
  69034. }
  69035. }
  69036. } catch (err) {
  69037. _didIteratorError5 = true;
  69038. _iteratorError5 = err;
  69039. } finally {
  69040. try {
  69041. if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
  69042. _iterator5.return();
  69043. }
  69044. } finally {
  69045. if (_didIteratorError5) {
  69046. throw _iteratorError5;
  69047. }
  69048. }
  69049. }
  69050. } else {
  69051. var _iteratorNormalCompletion6 = true;
  69052. var _didIteratorError6 = false;
  69053. var _iteratorError6 = undefined;
  69054. try {
  69055. for (
  69056. var _iterator6 = self._getOptionsArray()[Symbol.iterator](), _step6;
  69057. !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done);
  69058. _iteratorNormalCompletion6 = true
  69059. ) {
  69060. var _option = _step6.value;
  69061. if (_option.value === value) {
  69062. _option.setAttribute('checked', true);
  69063. result = _option;
  69064. }
  69065. }
  69066. } catch (err) {
  69067. _didIteratorError6 = true;
  69068. _iteratorError6 = err;
  69069. } finally {
  69070. try {
  69071. if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
  69072. _iterator6.return();
  69073. }
  69074. } finally {
  69075. if (_didIteratorError6) {
  69076. throw _iteratorError6;
  69077. }
  69078. }
  69079. }
  69080. }
  69081. return result;
  69082. };
  69083. self.disable = function() {
  69084. var shouldDisable =
  69085. arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  69086. var _iteratorNormalCompletion7 = true;
  69087. var _didIteratorError7 = false;
  69088. var _iteratorError7 = undefined;
  69089. try {
  69090. for (
  69091. var _iterator7 = self._getOptionsArray()[Symbol.iterator](), _step7;
  69092. !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done);
  69093. _iteratorNormalCompletion7 = true
  69094. ) {
  69095. var radioInput = _step7.value;
  69096. radioInput.setAttribute('disabled', shouldDisable);
  69097. }
  69098. } catch (err) {
  69099. _didIteratorError7 = true;
  69100. _iteratorError7 = err;
  69101. } finally {
  69102. try {
  69103. if (!_iteratorNormalCompletion7 && _iterator7.return != null) {
  69104. _iterator7.return();
  69105. }
  69106. } finally {
  69107. if (_didIteratorError7) {
  69108. throw _iteratorError7;
  69109. }
  69110. }
  69111. }
  69112. };
  69113. return self;
  69114. };
  69115. /**
  69116. * Creates a colorPicker element in the DOM for color input.
  69117. * The .value() method will return a hex string (#rrggbb) of the color.
  69118. * The .color() method will return a p5.Color object with the current chosen color.
  69119. *
  69120. * @method createColorPicker
  69121. * @param {String|p5.Color} [value] default color of element
  69122. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  69123. * @example
  69124. * <div><code>
  69125. * let colorPicker;
  69126. * function setup() {
  69127. * createCanvas(100, 100);
  69128. * colorPicker = createColorPicker('#ed225d');
  69129. * colorPicker.position(0, height + 5);
  69130. * }
  69131. *
  69132. * function draw() {
  69133. * background(colorPicker.color());
  69134. * }
  69135. * </code></div>
  69136. * <div><code>
  69137. * let inp1, inp2;
  69138. * function setup() {
  69139. * createCanvas(100, 100);
  69140. * background('grey');
  69141. * inp1 = createColorPicker('#ff0000');
  69142. * inp1.position(0, height + 5);
  69143. * inp1.input(setShade1);
  69144. * inp2 = createColorPicker(color('yellow'));
  69145. * inp2.position(0, height + 30);
  69146. * inp2.input(setShade2);
  69147. * setMidShade();
  69148. * }
  69149. *
  69150. * function setMidShade() {
  69151. * // Finding a shade between the two
  69152. * let commonShade = lerpColor(inp1.color(), inp2.color(), 0.5);
  69153. * fill(commonShade);
  69154. * rect(20, 20, 60, 60);
  69155. * }
  69156. *
  69157. * function setShade1() {
  69158. * setMidShade();
  69159. * console.log('You are choosing shade 1 to be : ', this.value());
  69160. * }
  69161. * function setShade2() {
  69162. * setMidShade();
  69163. * console.log('You are choosing shade 2 to be : ', this.value());
  69164. * }
  69165. * </code></div>
  69166. */
  69167. _main.default.prototype.createColorPicker = function(value) {
  69168. _main.default._validateParameters('createColorPicker', arguments);
  69169. var elt = document.createElement('input');
  69170. var self;
  69171. elt.type = 'color';
  69172. if (value) {
  69173. if (value instanceof _main.default.Color) {
  69174. elt.value = value.toString('#rrggbb');
  69175. } else {
  69176. _main.default.prototype._colorMode = 'rgb';
  69177. _main.default.prototype._colorMaxes = {
  69178. rgb: [255, 255, 255, 255],
  69179. hsb: [360, 100, 100, 1],
  69180. hsl: [360, 100, 100, 1]
  69181. };
  69182. elt.value = _main.default.prototype.color(value).toString('#rrggbb');
  69183. }
  69184. } else {
  69185. elt.value = '#000000';
  69186. }
  69187. self = addElement(elt, this);
  69188. // Method to return a p5.Color object for the given color.
  69189. self.color = function() {
  69190. if (value) {
  69191. if (value.mode) {
  69192. _main.default.prototype._colorMode = value.mode;
  69193. }
  69194. if (value.maxes) {
  69195. _main.default.prototype._colorMaxes = value.maxes;
  69196. }
  69197. }
  69198. return _main.default.prototype.color(this.elt.value);
  69199. };
  69200. return self;
  69201. };
  69202. /**
  69203. * Creates an `&lt;input&gt;&lt;/input&gt;` element in the DOM for text input.
  69204. * Use .<a href="#/p5.Element/size">size()</a> to set the display length of the box.
  69205. *
  69206. * @method createInput
  69207. * @param {String} value default value of the input box
  69208. * @param {String} [type] type of text, ie text, password etc. Defaults to text.
  69209. * Needs a value to be specified first.
  69210. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  69211. * @example
  69212. * <div><code>
  69213. * function setup() {
  69214. * createCanvas(100, 100);
  69215. * background('grey');
  69216. * let inp = createInput('');
  69217. * inp.position(0, 0);
  69218. * inp.size(100);
  69219. * inp.input(myInputEvent);
  69220. * }
  69221. *
  69222. * function myInputEvent() {
  69223. * console.log('you are typing: ', this.value());
  69224. * }
  69225. * </code></div>
  69226. */
  69227. /**
  69228. * @method createInput
  69229. * @param {String} [value]
  69230. * @return {p5.Element}
  69231. */
  69232. _main.default.prototype.createInput = function() {
  69233. var value =
  69234. arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  69235. var type =
  69236. arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'text';
  69237. _main.default._validateParameters('createInput', arguments);
  69238. var elt = document.createElement('input');
  69239. elt.setAttribute('value', value);
  69240. elt.setAttribute('type', type);
  69241. return addElement(elt, this);
  69242. };
  69243. /**
  69244. * Creates an `&lt;input&gt;&lt;/input&gt;` element in the DOM of type 'file'.
  69245. * This allows users to select local files for use in a sketch.
  69246. *
  69247. * @method createFileInput
  69248. * @param {Function} callback callback function for when a file is loaded
  69249. * @param {Boolean} [multiple] optional, to allow multiple files to be selected
  69250. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created DOM element
  69251. * @example
  69252. * <div><code>
  69253. * let input;
  69254. * let img;
  69255. *
  69256. * function setup() {
  69257. * input = createFileInput(handleFile);
  69258. * input.position(0, 0);
  69259. * }
  69260. *
  69261. * function draw() {
  69262. * background(255);
  69263. * if (img) {
  69264. * image(img, 0, 0, width, height);
  69265. * }
  69266. * }
  69267. *
  69268. * function handleFile(file) {
  69269. * print(file);
  69270. * if (file.type === 'image') {
  69271. * img = createImg(file.data, '');
  69272. * img.hide();
  69273. * } else {
  69274. * img = null;
  69275. * }
  69276. * }
  69277. * </code></div>
  69278. */
  69279. _main.default.prototype.createFileInput = function(callback) {
  69280. var multiple =
  69281. arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  69282. _main.default._validateParameters('createFileInput', arguments);
  69283. var handleFileSelect = function handleFileSelect(event) {
  69284. var _iteratorNormalCompletion8 = true;
  69285. var _didIteratorError8 = false;
  69286. var _iteratorError8 = undefined;
  69287. try {
  69288. for (
  69289. var _iterator8 = event.target.files[Symbol.iterator](), _step8;
  69290. !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done);
  69291. _iteratorNormalCompletion8 = true
  69292. ) {
  69293. var file = _step8.value;
  69294. _main.default.File._load(file, callback);
  69295. }
  69296. } catch (err) {
  69297. _didIteratorError8 = true;
  69298. _iteratorError8 = err;
  69299. } finally {
  69300. try {
  69301. if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
  69302. _iterator8.return();
  69303. }
  69304. } finally {
  69305. if (_didIteratorError8) {
  69306. throw _iteratorError8;
  69307. }
  69308. }
  69309. }
  69310. };
  69311. // If File API's are not supported, throw Error
  69312. if (!(window.File && window.FileReader && window.FileList && window.Blob)) {
  69313. console.log(
  69314. 'The File APIs are not fully supported in this browser. Cannot create element.'
  69315. );
  69316. return;
  69317. }
  69318. var fileInput = document.createElement('input');
  69319. fileInput.setAttribute('type', 'file');
  69320. if (multiple) fileInput.setAttribute('multiple', true);
  69321. fileInput.addEventListener('change', handleFileSelect, false);
  69322. return addElement(fileInput, this);
  69323. };
  69324. /** VIDEO STUFF **/
  69325. // Helps perform similar tasks for media element methods.
  69326. function createMedia(pInst, type, src, callback) {
  69327. var elt = document.createElement(type);
  69328. // Create source elements from given sources
  69329. src = src || '';
  69330. if (typeof src === 'string') {
  69331. src = [src];
  69332. }
  69333. var _iteratorNormalCompletion9 = true;
  69334. var _didIteratorError9 = false;
  69335. var _iteratorError9 = undefined;
  69336. try {
  69337. for (
  69338. var _iterator9 = src[Symbol.iterator](), _step9;
  69339. !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done);
  69340. _iteratorNormalCompletion9 = true
  69341. ) {
  69342. var mediaSource = _step9.value;
  69343. var sourceEl = document.createElement('source');
  69344. sourceEl.setAttribute('src', mediaSource);
  69345. elt.appendChild(sourceEl);
  69346. }
  69347. // If callback is provided, attach to element
  69348. } catch (err) {
  69349. _didIteratorError9 = true;
  69350. _iteratorError9 = err;
  69351. } finally {
  69352. try {
  69353. if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
  69354. _iterator9.return();
  69355. }
  69356. } finally {
  69357. if (_didIteratorError9) {
  69358. throw _iteratorError9;
  69359. }
  69360. }
  69361. }
  69362. if (typeof callback === 'function') {
  69363. var callbackHandler = function callbackHandler() {
  69364. callback();
  69365. elt.removeEventListener('canplaythrough', callbackHandler);
  69366. };
  69367. elt.addEventListener('canplaythrough', callbackHandler);
  69368. }
  69369. var mediaEl = addElement(elt, pInst, true);
  69370. mediaEl.loadedmetadata = false;
  69371. // set width and height onload metadata
  69372. elt.addEventListener('loadedmetadata', function() {
  69373. mediaEl.width = elt.videoWidth;
  69374. mediaEl.height = elt.videoHeight;
  69375. // set elt width and height if not set
  69376. if (mediaEl.elt.width === 0) mediaEl.elt.width = elt.videoWidth;
  69377. if (mediaEl.elt.height === 0) mediaEl.elt.height = elt.videoHeight;
  69378. if (mediaEl.presetPlaybackRate) {
  69379. mediaEl.elt.playbackRate = mediaEl.presetPlaybackRate;
  69380. delete mediaEl.presetPlaybackRate;
  69381. }
  69382. mediaEl.loadedmetadata = true;
  69383. });
  69384. return mediaEl;
  69385. }
  69386. /**
  69387. * Creates an HTML5 `&lt;video&gt;` element in the DOM for simple playback
  69388. * of audio/video. Shown by default, can be hidden with .<a href="#/p5.Element/hide">hide()</a>
  69389. * and drawn into canvas using <a href="#/p5/image">image()</a>. The first parameter
  69390. * can be either a single string path to a video file, or an array of string
  69391. * paths to different formats of the same video. This is useful for ensuring
  69392. * that your video can play across different browsers, as each supports
  69393. * different formats. See <a href='https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats'>this
  69394. * page</a> for further information about supported formats.
  69395. *
  69396. * @method createVideo
  69397. * @param {String|String[]} src path to a video file, or array of paths for
  69398. * supporting different browsers
  69399. * @param {Function} [callback] callback function to be called upon
  69400. * 'canplaythrough' event fire, that is, when the
  69401. * browser can play the media, and estimates that
  69402. * enough data has been loaded to play the media
  69403. * up to its end without having to stop for
  69404. * further buffering of content
  69405. * @return {p5.MediaElement} pointer to video <a href="#/p5.Element">p5.Element</a>
  69406. * @example
  69407. * <div><code>
  69408. * let vid;
  69409. * function setup() {
  69410. * noCanvas();
  69411. *
  69412. * vid = createVideo(
  69413. * ['assets/small.mp4', 'assets/small.ogv', 'assets/small.webm'],
  69414. * vidLoad
  69415. * );
  69416. *
  69417. * vid.size(100, 100);
  69418. * }
  69419. *
  69420. * // This function is called when the video loads
  69421. * function vidLoad() {
  69422. * vid.loop();
  69423. * vid.volume(0);
  69424. * }
  69425. * </code></div>
  69426. */
  69427. _main.default.prototype.createVideo = function(src, callback) {
  69428. _main.default._validateParameters('createVideo', arguments);
  69429. return createMedia(this, 'video', src, callback);
  69430. };
  69431. /** AUDIO STUFF **/
  69432. /**
  69433. * Creates a hidden HTML5 `&lt;audio&gt;` element in the DOM for simple audio
  69434. * playback. The first parameter can be either a single string path to a
  69435. * audio file, or an array of string paths to different formats of the same
  69436. * audio. This is useful for ensuring that your audio can play across
  69437. * different browsers, as each supports different formats.
  69438. * See <a href='https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats'>this
  69439. * page for further information about supported formats</a>.
  69440. *
  69441. * @method createAudio
  69442. * @param {String|String[]} [src] path to an audio file, or array of paths
  69443. * for supporting different browsers
  69444. * @param {Function} [callback] callback function to be called upon
  69445. * 'canplaythrough' event fire, that is, when the
  69446. * browser can play the media, and estimates that
  69447. * enough data has been loaded to play the media
  69448. * up to its end without having to stop for
  69449. * further buffering of content
  69450. * @return {p5.MediaElement} pointer to audio <a href="#/p5.Element">p5.Element</a>
  69451. * @example
  69452. * <div><code>
  69453. * let ele;
  69454. * function setup() {
  69455. * ele = createAudio('assets/beat.mp3');
  69456. *
  69457. * // here we set the element to autoplay
  69458. * // The element will play as soon
  69459. * // as it is able to do so.
  69460. * ele.autoplay(true);
  69461. * }
  69462. * </code></div>
  69463. */
  69464. _main.default.prototype.createAudio = function(src, callback) {
  69465. _main.default._validateParameters('createAudio', arguments);
  69466. return createMedia(this, 'audio', src, callback);
  69467. };
  69468. /** CAMERA STUFF **/
  69469. /**
  69470. * @property {String} VIDEO
  69471. * @final
  69472. * @category Constants
  69473. */
  69474. _main.default.prototype.VIDEO = 'video';
  69475. /**
  69476. * @property {String} AUDIO
  69477. * @final
  69478. * @category Constants
  69479. */
  69480. _main.default.prototype.AUDIO = 'audio';
  69481. // from: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
  69482. // Older browsers might not implement mediaDevices at all, so we set an empty object first
  69483. if (navigator.mediaDevices === undefined) {
  69484. navigator.mediaDevices = {};
  69485. }
  69486. // Some browsers partially implement mediaDevices. We can't just assign an object
  69487. // with getUserMedia as it would overwrite existing properties.
  69488. // Here, we will just add the getUserMedia property if it's missing.
  69489. if (navigator.mediaDevices.getUserMedia === undefined) {
  69490. navigator.mediaDevices.getUserMedia = function(constraints) {
  69491. // First get ahold of the legacy getUserMedia, if present
  69492. var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
  69493. // Some browsers just don't implement it - return a rejected promise with an error
  69494. // to keep a consistent interface
  69495. if (!getUserMedia) {
  69496. return Promise.reject(
  69497. new Error('getUserMedia is not implemented in this browser')
  69498. );
  69499. }
  69500. // Otherwise, wrap the call to the old navigator.getUserMedia with a Promise
  69501. return new Promise(function(resolve, reject) {
  69502. getUserMedia.call(navigator, constraints, resolve, reject);
  69503. });
  69504. };
  69505. }
  69506. /**
  69507. * Creates a new HTML5 `&lt;video&gt;` element that contains the audio/video feed
  69508. * from a webcam. The element is separate from the canvas and is displayed by
  69509. * default. The element can be hidden using .<a href="#/p5.Element/hide">hide()</a>.
  69510. * The feed can be drawn onto the canvas using <a href="#/p5/image">image()</a>.
  69511. * The loadedmetadata property can be used to detect when the element has fully
  69512. * loaded (see second example).
  69513. *
  69514. * More specific properties of the feed can be passing in a Constraints object.
  69515. * See the <a href='http://w3c.github.io/mediacapture-main/getusermedia.html#media-track-constraints'>
  69516. * W3C spec</a> for possible properties. Note that not all of these are supported
  69517. * by all browsers.
  69518. *
  69519. * <em>Security note</em>: A new browser security specification requires that
  69520. * getUserMedia, which is behind <a href="#/p5/createCapture">createCapture()</a>,
  69521. * only works when you're running the code locally, or on HTTPS. Learn more
  69522. * <a href='http://stackoverflow.com/questions/34197653/getusermedia-in-chrome-47-without-using-https'>here</a>
  69523. * and <a href='https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia'>here</a>.
  69524. *
  69525. * @method createCapture
  69526. * @param {String|Constant|Object} type type of capture, either VIDEO or
  69527. * AUDIO if none specified, default both,
  69528. * or a Constraints object
  69529. * @param {Function} [callback] function to be called once
  69530. * stream has loaded
  69531. * @return {p5.Element} capture video <a href="#/p5.Element">p5.Element</a>
  69532. * @example
  69533. * <div class='notest'>
  69534. * <code>
  69535. * let capture;
  69536. *
  69537. * function setup() {
  69538. * createCanvas(100, 100);
  69539. * capture = createCapture(VIDEO);
  69540. * capture.hide();
  69541. * }
  69542. *
  69543. * function draw() {
  69544. * image(capture, 0, 0, width, width * capture.height / capture.width);
  69545. * filter(INVERT);
  69546. * }
  69547. * </code>
  69548. * </div>
  69549. *
  69550. * <div class='notest norender'>
  69551. * <code>
  69552. * function setup() {
  69553. * createCanvas(480, 120);
  69554. * let constraints = {
  69555. * video: {
  69556. * mandatory: {
  69557. * minWidth: 1280,
  69558. * minHeight: 720
  69559. * },
  69560. * optional: [{ maxFrameRate: 10 }]
  69561. * },
  69562. * audio: true
  69563. * };
  69564. * createCapture(constraints, function(stream) {
  69565. * console.log(stream);
  69566. * });
  69567. * }
  69568. * </code>
  69569. * </div>
  69570. * <div class='notest norender'>
  69571. * <code>
  69572. * let capture;
  69573. *
  69574. * function setup() {
  69575. * createCanvas(640, 480);
  69576. * capture = createCapture(VIDEO);
  69577. * }
  69578. * function draw() {
  69579. * background(0);
  69580. * if (capture.loadedmetadata) {
  69581. * let c = capture.get(0, 0, 100, 100);
  69582. * image(c, 0, 0);
  69583. * }
  69584. * }
  69585. * </code>
  69586. * </div>
  69587. */
  69588. _main.default.prototype.createCapture = function() {
  69589. _main.default._validateParameters('createCapture', arguments);
  69590. // return if getUserMedia is not supported by browser
  69591. if (!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia)) {
  69592. throw new DOMException('getUserMedia not supported in this browser');
  69593. }
  69594. var useVideo = true;
  69595. var useAudio = true;
  69596. var constraints;
  69597. var callback;
  69598. var _iteratorNormalCompletion10 = true;
  69599. var _didIteratorError10 = false;
  69600. var _iteratorError10 = undefined;
  69601. try {
  69602. for (
  69603. var _iterator10 = arguments[Symbol.iterator](), _step10;
  69604. !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done);
  69605. _iteratorNormalCompletion10 = true
  69606. ) {
  69607. var arg = _step10.value;
  69608. if (arg === _main.default.prototype.VIDEO) useAudio = false;
  69609. else if (arg === _main.default.prototype.AUDIO) useVideo = false;
  69610. else if (_typeof(arg) === 'object') constraints = arg;
  69611. else if (typeof arg === 'function') callback = arg;
  69612. }
  69613. } catch (err) {
  69614. _didIteratorError10 = true;
  69615. _iteratorError10 = err;
  69616. } finally {
  69617. try {
  69618. if (!_iteratorNormalCompletion10 && _iterator10.return != null) {
  69619. _iterator10.return();
  69620. }
  69621. } finally {
  69622. if (_didIteratorError10) {
  69623. throw _iteratorError10;
  69624. }
  69625. }
  69626. }
  69627. if (!constraints) constraints = { video: useVideo, audio: useAudio };
  69628. var domElement = document.createElement('video');
  69629. // required to work in iOS 11 & up:
  69630. domElement.setAttribute('playsinline', '');
  69631. navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {
  69632. try {
  69633. if ('srcObject' in domElement) {
  69634. domElement.srcObject = stream;
  69635. } else {
  69636. domElement.src = window.URL.createObjectURL(stream);
  69637. }
  69638. } catch (err) {
  69639. domElement.src = stream;
  69640. }
  69641. }, console.log);
  69642. var videoEl = addElement(domElement, this, true);
  69643. videoEl.loadedmetadata = false;
  69644. // set width and height onload metadata
  69645. domElement.addEventListener('loadedmetadata', function() {
  69646. domElement.play();
  69647. if (domElement.width) {
  69648. videoEl.width = domElement.width;
  69649. videoEl.height = domElement.height;
  69650. } else {
  69651. videoEl.width = videoEl.elt.width = domElement.videoWidth;
  69652. videoEl.height = videoEl.elt.height = domElement.videoHeight;
  69653. }
  69654. videoEl.loadedmetadata = true;
  69655. if (callback) callback(domElement.srcObject);
  69656. });
  69657. return videoEl;
  69658. };
  69659. /**
  69660. * Creates element with given tag in the DOM with given content.
  69661. *
  69662. * @method createElement
  69663. * @param {String} tag tag for the new element
  69664. * @param {String} [content] html content to be inserted into the element
  69665. * @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
  69666. * @example
  69667. * <div><code>
  69668. * let h5 = createElement('h5', 'im an h5 p5.element!');
  69669. * h5.style('color', '#00a1d3');
  69670. * h5.position(0, 0);
  69671. * </code></div>
  69672. */
  69673. _main.default.prototype.createElement = function(tag, content) {
  69674. _main.default._validateParameters('createElement', arguments);
  69675. var elt = document.createElement(tag);
  69676. if (typeof content !== 'undefined') {
  69677. elt.innerHTML = content;
  69678. }
  69679. return addElement(elt, this);
  69680. };
  69681. // =============================================================================
  69682. // p5.Element additions
  69683. // =============================================================================
  69684. /**
  69685. *
  69686. * Adds specified class to the element.
  69687. *
  69688. * @for p5.Element
  69689. * @method addClass
  69690. * @param {String} class name of class to add
  69691. * @chainable
  69692. * @example
  69693. * <div class='norender'><code>
  69694. * let div = createDiv('div');
  69695. * div.addClass('myClass');
  69696. * </code></div>
  69697. */
  69698. _main.default.Element.prototype.addClass = function(c) {
  69699. if (this.elt.className) {
  69700. if (!this.hasClass(c)) {
  69701. this.elt.className = this.elt.className + ' ' + c;
  69702. }
  69703. } else {
  69704. this.elt.className = c;
  69705. }
  69706. return this;
  69707. };
  69708. /**
  69709. *
  69710. * Removes specified class from the element.
  69711. *
  69712. * @method removeClass
  69713. * @param {String} class name of class to remove
  69714. * @chainable
  69715. * @example
  69716. * <div class='norender'><code>
  69717. * // In this example, a class is set when the div is created
  69718. * // and removed when mouse is pressed. This could link up
  69719. * // with a CSS style rule to toggle style properties.
  69720. *
  69721. * let div;
  69722. *
  69723. * function setup() {
  69724. * div = createDiv('div');
  69725. * div.addClass('myClass');
  69726. * }
  69727. *
  69728. * function mousePressed() {
  69729. * div.removeClass('myClass');
  69730. * }
  69731. * </code></div>
  69732. */
  69733. _main.default.Element.prototype.removeClass = function(c) {
  69734. // Note: Removing a class that does not exist does NOT throw an error in classList.remove method
  69735. this.elt.classList.remove(c);
  69736. return this;
  69737. };
  69738. /**
  69739. *
  69740. * Checks if specified class already set to element
  69741. *
  69742. * @method hasClass
  69743. * @returns {boolean} a boolean value if element has specified class
  69744. * @param c {String} class name of class to check
  69745. * @example
  69746. * <div class='norender'><code>
  69747. * let div;
  69748. *
  69749. * function setup() {
  69750. * div = createDiv('div');
  69751. * div.addClass('show');
  69752. * }
  69753. *
  69754. * function mousePressed() {
  69755. * if (div.hasClass('show')) {
  69756. * div.addClass('show');
  69757. * } else {
  69758. * div.removeClass('show');
  69759. * }
  69760. * }
  69761. * </code></div>
  69762. */
  69763. _main.default.Element.prototype.hasClass = function(c) {
  69764. return this.elt.classList.contains(c);
  69765. };
  69766. /**
  69767. *
  69768. * Toggles element class
  69769. *
  69770. * @method toggleClass
  69771. * @param c {String} class name to toggle
  69772. * @chainable
  69773. * @example
  69774. * <div class='norender'><code>
  69775. * let div;
  69776. *
  69777. * function setup() {
  69778. * div = createDiv('div');
  69779. * div.addClass('show');
  69780. * }
  69781. *
  69782. * function mousePressed() {
  69783. * div.toggleClass('show');
  69784. * }
  69785. * </code></div>
  69786. */
  69787. _main.default.Element.prototype.toggleClass = function(c) {
  69788. // classList also has a toggle() method, but we cannot use that yet as support is unclear.
  69789. // See https://github.com/processing/p5.js/issues/3631
  69790. // this.elt.classList.toggle(c);
  69791. if (this.elt.classList.contains(c)) {
  69792. this.elt.classList.remove(c);
  69793. } else {
  69794. this.elt.classList.add(c);
  69795. }
  69796. return this;
  69797. };
  69798. /**
  69799. *
  69800. * Attaches the element as a child to the parent specified.
  69801. * Accepts either a string ID, DOM node, or <a href="#/p5.Element">p5.Element</a>.
  69802. * If no argument is specified, an array of children DOM nodes is returned.
  69803. *
  69804. * @method child
  69805. * @returns {Node[]} an array of child nodes
  69806. * @example
  69807. * <div class='norender'><code>
  69808. * let div0 = createDiv('this is the parent');
  69809. * let div1 = createDiv('this is the child');
  69810. * div0.child(div1); // use p5.Element
  69811. * </code></div>
  69812. * <div class='norender'><code>
  69813. * let div0 = createDiv('this is the parent');
  69814. * let div1 = createDiv('this is the child');
  69815. * div1.id('apples');
  69816. * div0.child('apples'); // use id
  69817. * </code></div>
  69818. * <div class='norender notest'><code>
  69819. * // this example assumes there is a div already on the page
  69820. * // with id "myChildDiv"
  69821. * let div0 = createDiv('this is the parent');
  69822. * let elt = document.getElementById('myChildDiv');
  69823. * div0.child(elt); // use element from page
  69824. * </code></div>
  69825. */
  69826. /**
  69827. * @method child
  69828. * @param {String|p5.Element} [child] the ID, DOM node, or <a href="#/p5.Element">p5.Element</a>
  69829. * to add to the current element
  69830. * @chainable
  69831. */
  69832. _main.default.Element.prototype.child = function(childNode) {
  69833. if (typeof childNode === 'undefined') {
  69834. return this.elt.childNodes;
  69835. }
  69836. if (typeof childNode === 'string') {
  69837. if (childNode[0] === '#') {
  69838. childNode = childNode.substring(1);
  69839. }
  69840. childNode = document.getElementById(childNode);
  69841. } else if (childNode instanceof _main.default.Element) {
  69842. childNode = childNode.elt;
  69843. }
  69844. if (childNode instanceof HTMLElement) {
  69845. this.elt.appendChild(childNode);
  69846. }
  69847. return this;
  69848. };
  69849. /**
  69850. * Centers a p5 Element either vertically, horizontally,
  69851. * or both, relative to its parent or according to
  69852. * the body if the Element has no parent. If no argument is passed
  69853. * the Element is aligned both vertically and horizontally.
  69854. *
  69855. * @method center
  69856. * @param {String} [align] passing 'vertical', 'horizontal' aligns element accordingly
  69857. * @chainable
  69858. *
  69859. * @example
  69860. * <div><code>
  69861. * function setup() {
  69862. * let div = createDiv('').size(10, 10);
  69863. * div.style('background-color', 'orange');
  69864. * div.center();
  69865. * }
  69866. * </code></div>
  69867. */
  69868. _main.default.Element.prototype.center = function(align) {
  69869. var style = this.elt.style.display;
  69870. var hidden = this.elt.style.display === 'none';
  69871. var parentHidden = this.parent().style.display === 'none';
  69872. var pos = { x: this.elt.offsetLeft, y: this.elt.offsetTop };
  69873. if (hidden) this.show();
  69874. if (parentHidden) this.parent().show();
  69875. this.elt.style.display = 'block';
  69876. this.position(0, 0);
  69877. var wOffset = Math.abs(this.parent().offsetWidth - this.elt.offsetWidth);
  69878. var hOffset = Math.abs(this.parent().offsetHeight - this.elt.offsetHeight);
  69879. if (align === 'both' || align === undefined) {
  69880. this.position(
  69881. wOffset / 2 + this.parent().offsetLeft,
  69882. hOffset / 2 + this.parent().offsetTop
  69883. );
  69884. } else if (align === 'horizontal') {
  69885. this.position(wOffset / 2 + this.parent().offsetLeft, pos.y);
  69886. } else if (align === 'vertical') {
  69887. this.position(pos.x, hOffset / 2 + this.parent().offsetTop);
  69888. }
  69889. this.style('display', style);
  69890. if (hidden) this.hide();
  69891. if (parentHidden) this.parent().hide();
  69892. return this;
  69893. };
  69894. /**
  69895. *
  69896. * If an argument is given, sets the inner HTML of the element,
  69897. * replacing any existing html. If true is included as a second
  69898. * argument, html is appended instead of replacing existing html.
  69899. * If no arguments are given, returns
  69900. * the inner HTML of the element.
  69901. *
  69902. * @for p5.Element
  69903. * @method html
  69904. * @returns {String} the inner HTML of the element
  69905. * @example
  69906. * <div class='norender'><code>
  69907. * let div = createDiv('').size(100, 100);
  69908. * div.html('hi');
  69909. * </code></div>
  69910. * <div class='norender'><code>
  69911. * let div = createDiv('Hello ').size(100, 100);
  69912. * div.html('World', true);
  69913. * </code></div>
  69914. */
  69915. /**
  69916. * @method html
  69917. * @param {String} [html] the HTML to be placed inside the element
  69918. * @param {boolean} [append] whether to append HTML to existing
  69919. * @chainable
  69920. */
  69921. _main.default.Element.prototype.html = function() {
  69922. if (arguments.length === 0) {
  69923. return this.elt.innerHTML;
  69924. } else if (arguments[1]) {
  69925. this.elt.insertAdjacentHTML('beforeend', arguments[0]);
  69926. return this;
  69927. } else {
  69928. this.elt.innerHTML = arguments[0];
  69929. return this;
  69930. }
  69931. };
  69932. /**
  69933. *
  69934. * Sets the position of the element. If no position type argument is given, the
  69935. * position will be relative to (0, 0) of the window.
  69936. * Essentially, this sets position:absolute and left and top
  69937. * properties of style. If an optional third argument specifying position type is given,
  69938. * the x and y coordinates will be interpreted based on the <a target="_blank"
  69939. * href="https://developer.mozilla.org/en-US/docs/Web/CSS/position">positioning scheme</a>.
  69940. * If no arguments given, the function returns the x and y position of the element.
  69941. *
  69942. * found documentation on how to be more specific with object type
  69943. * https://stackoverflow.com/questions/14714314/how-do-i-comment-object-literals-in-yuidoc
  69944. *
  69945. * @method position
  69946. * @returns {Object} object of form { x: 0, y: 0 } containing the position of the element in an object
  69947. * @example
  69948. * <div><code class='norender'>
  69949. * function setup() {
  69950. * let cnv = createCanvas(100, 100);
  69951. * // positions canvas 50px to the right and 100px
  69952. * // below upper left corner of the window
  69953. * cnv.position(50, 100);
  69954. * }
  69955. * </code></div>
  69956. * <div><code class='norender'>
  69957. * function setup() {
  69958. * let cnv = createCanvas(100, 100);
  69959. * // positions canvas 50px to the right and 100px
  69960. * // below upper left corner of the window
  69961. * cnv.position(0, 0, 'fixed');
  69962. * }
  69963. * </code></div>
  69964. */
  69965. /**
  69966. * @method position
  69967. * @param {Number} [x] x-position relative to upper left of window (optional)
  69968. * @param {Number} [y] y-position relative to upper left of window (optional)
  69969. * @param {String} positionType it can be static, fixed, relative, sticky, initial or inherit (optional)
  69970. * @chainable
  69971. */
  69972. _main.default.Element.prototype.position = function() {
  69973. if (arguments.length === 0) {
  69974. return { x: this.elt.offsetLeft, y: this.elt.offsetTop };
  69975. } else {
  69976. var positionType = 'absolute';
  69977. if (
  69978. arguments[2] === 'static' ||
  69979. arguments[2] === 'fixed' ||
  69980. arguments[2] === 'relative' ||
  69981. arguments[2] === 'sticky' ||
  69982. arguments[2] === 'initial' ||
  69983. arguments[2] === 'inherit'
  69984. ) {
  69985. positionType = arguments[2];
  69986. }
  69987. this.elt.style.position = positionType;
  69988. this.elt.style.left = arguments[0] + 'px';
  69989. this.elt.style.top = arguments[1] + 'px';
  69990. this.x = arguments[0];
  69991. this.y = arguments[1];
  69992. return this;
  69993. }
  69994. };
  69995. /* Helper method called by p5.Element.style() */
  69996. _main.default.Element.prototype._translate = function() {
  69997. this.elt.style.position = 'absolute';
  69998. // save out initial non-translate transform styling
  69999. var transform = '';
  70000. if (this.elt.style.transform) {
  70001. transform = this.elt.style.transform.replace(/translate3d\(.*\)/g, '');
  70002. transform = transform.replace(/translate[X-Z]?\(.*\)/g, '');
  70003. }
  70004. if (arguments.length === 2) {
  70005. this.elt.style.transform =
  70006. 'translate(' + arguments[0] + 'px, ' + arguments[1] + 'px)';
  70007. } else if (arguments.length > 2) {
  70008. this.elt.style.transform =
  70009. 'translate3d(' +
  70010. arguments[0] +
  70011. 'px,' +
  70012. arguments[1] +
  70013. 'px,' +
  70014. arguments[2] +
  70015. 'px)';
  70016. if (arguments.length === 3) {
  70017. this.elt.parentElement.style.perspective = '1000px';
  70018. } else {
  70019. this.elt.parentElement.style.perspective = arguments[3] + 'px';
  70020. }
  70021. }
  70022. // add any extra transform styling back on end
  70023. this.elt.style.transform += transform;
  70024. return this;
  70025. };
  70026. /* Helper method called by p5.Element.style() */
  70027. _main.default.Element.prototype._rotate = function() {
  70028. // save out initial non-rotate transform styling
  70029. var transform = '';
  70030. if (this.elt.style.transform) {
  70031. transform = this.elt.style.transform.replace(/rotate3d\(.*\)/g, '');
  70032. transform = transform.replace(/rotate[X-Z]?\(.*\)/g, '');
  70033. }
  70034. if (arguments.length === 1) {
  70035. this.elt.style.transform = 'rotate(' + arguments[0] + 'deg)';
  70036. } else if (arguments.length === 2) {
  70037. this.elt.style.transform =
  70038. 'rotate(' + arguments[0] + 'deg, ' + arguments[1] + 'deg)';
  70039. } else if (arguments.length === 3) {
  70040. this.elt.style.transform = 'rotateX(' + arguments[0] + 'deg)';
  70041. this.elt.style.transform += 'rotateY(' + arguments[1] + 'deg)';
  70042. this.elt.style.transform += 'rotateZ(' + arguments[2] + 'deg)';
  70043. }
  70044. // add remaining transform back on
  70045. this.elt.style.transform += transform;
  70046. return this;
  70047. };
  70048. /**
  70049. * Sets the given style (css) property (1st arg) of the element with the
  70050. * given value (2nd arg). If a single argument is given, .style()
  70051. * returns the value of the given property; however, if the single argument
  70052. * is given in css syntax ('text-align:center'), .style() sets the css
  70053. * appropriately.
  70054. *
  70055. * @method style
  70056. * @param {String} property property to be set
  70057. * @returns {String} value of property
  70058. * @example
  70059. * <div><code class='norender'>
  70060. * let myDiv = createDiv('I like pandas.');
  70061. * myDiv.style('font-size', '18px');
  70062. * myDiv.style('color', '#ff0000');
  70063. * myDiv.position(0, 0);
  70064. * </code></div>
  70065. * <div><code class='norender'>
  70066. * let col = color(25, 23, 200, 50);
  70067. * let button = createButton('button');
  70068. * button.style('background-color', col);
  70069. * button.position(0, 0);
  70070. * </code></div>
  70071. * <div><code class='norender'>
  70072. * let myDiv, fontSize;
  70073. * function setup() {
  70074. * background(200);
  70075. * myDiv = createDiv('I like gray.');
  70076. * myDiv.position(0, 0);
  70077. * myDiv.style('z-index', 10);
  70078. * }
  70079. *
  70080. * function draw() {
  70081. * fontSize = min(mouseX, 90);
  70082. * myDiv.style('font-size', fontSize + 'px');
  70083. * }
  70084. * </code></div>
  70085. */
  70086. /**
  70087. * @method style
  70088. * @param {String} property
  70089. * @param {String|p5.Color} value value to assign to property
  70090. * @return {String} current value of property, if no value is given as second argument
  70091. * @chainable
  70092. */
  70093. _main.default.Element.prototype.style = function(prop, val) {
  70094. var self = this;
  70095. if (val instanceof _main.default.Color) {
  70096. val =
  70097. 'rgba(' +
  70098. val.levels[0] +
  70099. ',' +
  70100. val.levels[1] +
  70101. ',' +
  70102. val.levels[2] +
  70103. ',' +
  70104. val.levels[3] / 255 +
  70105. ')';
  70106. }
  70107. if (typeof val === 'undefined') {
  70108. if (prop.indexOf(':') === -1) {
  70109. // no value set, so assume requesting a value
  70110. var styles = window.getComputedStyle(self.elt);
  70111. var style = styles.getPropertyValue(prop);
  70112. return style;
  70113. } else {
  70114. // value set using `:` in a single line string
  70115. var attrs = prop.split(';');
  70116. for (var i = 0; i < attrs.length; i++) {
  70117. var parts = attrs[i].split(':');
  70118. if (parts[0] && parts[1]) {
  70119. this.elt.style[parts[0].trim()] = parts[1].trim();
  70120. }
  70121. }
  70122. }
  70123. } else {
  70124. // input provided as key,val pair
  70125. this.elt.style[prop] = val;
  70126. if (
  70127. prop === 'width' ||
  70128. prop === 'height' ||
  70129. prop === 'left' ||
  70130. prop === 'top'
  70131. ) {
  70132. var _styles = window.getComputedStyle(self.elt);
  70133. var styleVal = _styles.getPropertyValue(prop);
  70134. var numVal = styleVal.replace(/\D+/g, '');
  70135. this[prop] = parseInt(numVal, 10);
  70136. }
  70137. }
  70138. return this;
  70139. };
  70140. /**
  70141. *
  70142. * Adds a new attribute or changes the value of an existing attribute
  70143. * on the specified element. If no value is specified, returns the
  70144. * value of the given attribute, or null if attribute is not set.
  70145. *
  70146. * @method attribute
  70147. * @return {String} value of attribute
  70148. *
  70149. * @example
  70150. * <div class='norender'><code>
  70151. * let myDiv = createDiv('I like pandas.');
  70152. * myDiv.attribute('align', 'center');
  70153. * </code></div>
  70154. */
  70155. /**
  70156. * @method attribute
  70157. * @param {String} attr attribute to set
  70158. * @param {String} value value to assign to attribute
  70159. * @chainable
  70160. */
  70161. _main.default.Element.prototype.attribute = function(attr, value) {
  70162. //handling for checkboxes and radios to ensure options get
  70163. //attributes not divs
  70164. if (
  70165. this.elt.firstChild != null &&
  70166. (this.elt.firstChild.type === 'checkbox' ||
  70167. this.elt.firstChild.type === 'radio')
  70168. ) {
  70169. if (typeof value === 'undefined') {
  70170. return this.elt.firstChild.getAttribute(attr);
  70171. } else {
  70172. for (var i = 0; i < this.elt.childNodes.length; i++) {
  70173. this.elt.childNodes[i].setAttribute(attr, value);
  70174. }
  70175. }
  70176. } else if (typeof value === 'undefined') {
  70177. return this.elt.getAttribute(attr);
  70178. } else {
  70179. this.elt.setAttribute(attr, value);
  70180. return this;
  70181. }
  70182. };
  70183. /**
  70184. *
  70185. * Removes an attribute on the specified element.
  70186. *
  70187. * @method removeAttribute
  70188. * @param {String} attr attribute to remove
  70189. * @chainable
  70190. *
  70191. * @example
  70192. * <div><code>
  70193. * let button;
  70194. * let checkbox;
  70195. *
  70196. * function setup() {
  70197. * checkbox = createCheckbox('enable', true);
  70198. * checkbox.changed(enableButton);
  70199. * button = createButton('button');
  70200. * button.position(10, 10);
  70201. * }
  70202. *
  70203. * function enableButton() {
  70204. * if (this.checked()) {
  70205. * // Re-enable the button
  70206. * button.removeAttribute('disabled');
  70207. * } else {
  70208. * // Disable the button
  70209. * button.attribute('disabled', '');
  70210. * }
  70211. * }
  70212. * </code></div>
  70213. */
  70214. _main.default.Element.prototype.removeAttribute = function(attr) {
  70215. if (
  70216. this.elt.firstChild != null &&
  70217. (this.elt.firstChild.type === 'checkbox' ||
  70218. this.elt.firstChild.type === 'radio')
  70219. ) {
  70220. for (var i = 0; i < this.elt.childNodes.length; i++) {
  70221. this.elt.childNodes[i].removeAttribute(attr);
  70222. }
  70223. }
  70224. this.elt.removeAttribute(attr);
  70225. return this;
  70226. };
  70227. /**
  70228. * Either returns the value of the element if no arguments
  70229. * given, or sets the value of the element.
  70230. *
  70231. * @method value
  70232. * @return {String|Number} value of the element
  70233. * @example
  70234. * <div class='norender'><code>
  70235. * // gets the value
  70236. * let inp;
  70237. * function setup() {
  70238. * inp = createInput('');
  70239. * }
  70240. *
  70241. * function mousePressed() {
  70242. * print(inp.value());
  70243. * }
  70244. * </code></div>
  70245. * <div class='norender'><code>
  70246. * // sets the value
  70247. * let inp;
  70248. * function setup() {
  70249. * inp = createInput('myValue');
  70250. * }
  70251. *
  70252. * function mousePressed() {
  70253. * inp.value('myValue');
  70254. * }
  70255. * </code></div>
  70256. */
  70257. /**
  70258. * @method value
  70259. * @param {String|Number} value
  70260. * @chainable
  70261. */
  70262. _main.default.Element.prototype.value = function() {
  70263. if (arguments.length > 0) {
  70264. this.elt.value = arguments[0];
  70265. return this;
  70266. } else {
  70267. if (this.elt.type === 'range') {
  70268. return parseFloat(this.elt.value);
  70269. } else return this.elt.value;
  70270. }
  70271. };
  70272. /**
  70273. *
  70274. * Shows the current element. Essentially, setting display:block for the style.
  70275. *
  70276. * @method show
  70277. * @chainable
  70278. * @example
  70279. * <div class='norender'><code>
  70280. * let div = createDiv('div');
  70281. * div.style('display', 'none');
  70282. * div.show(); // turns display to block
  70283. * </code></div>
  70284. */
  70285. _main.default.Element.prototype.show = function() {
  70286. this.elt.style.display = 'block';
  70287. return this;
  70288. };
  70289. /**
  70290. * Hides the current element. Essentially, setting display:none for the style.
  70291. *
  70292. * @method hide
  70293. * @chainable
  70294. * @example
  70295. * <div class='norender'><code>
  70296. * let div = createDiv('this is a div');
  70297. * div.hide();
  70298. * </code></div>
  70299. */
  70300. _main.default.Element.prototype.hide = function() {
  70301. this.elt.style.display = 'none';
  70302. return this;
  70303. };
  70304. /**
  70305. *
  70306. * Sets the width and height of the element. AUTO can be used to
  70307. * only adjust one dimension at a time. If no arguments are given, it
  70308. * returns the width and height of the element in an object. In case of
  70309. * elements which need to be loaded, such as images, it is recommended
  70310. * to call the function after the element has finished loading.
  70311. *
  70312. * @method size
  70313. * @return {Object} the width and height of the element in an object
  70314. * @example
  70315. * <div class='norender'><code>
  70316. * let div = createDiv('this is a div');
  70317. * div.size(100, 100);
  70318. * let img = createImg(
  70319. * 'assets/rockies.jpg',
  70320. * 'A tall mountain with a small forest and field in front of it on a sunny day',
  70321. * '',
  70322. * () => {
  70323. * img.size(10, AUTO);
  70324. * }
  70325. * );
  70326. * </code></div>
  70327. */
  70328. /**
  70329. * @method size
  70330. * @param {Number|Constant} w width of the element, either AUTO, or a number
  70331. * @param {Number|Constant} [h] height of the element, either AUTO, or a number
  70332. * @chainable
  70333. */
  70334. _main.default.Element.prototype.size = function(w, h) {
  70335. if (arguments.length === 0) {
  70336. return { width: this.elt.offsetWidth, height: this.elt.offsetHeight };
  70337. } else {
  70338. var aW = w;
  70339. var aH = h;
  70340. var AUTO = _main.default.prototype.AUTO;
  70341. if (aW !== AUTO || aH !== AUTO) {
  70342. if (aW === AUTO) {
  70343. aW = h * this.width / this.height;
  70344. } else if (aH === AUTO) {
  70345. aH = w * this.height / this.width;
  70346. }
  70347. // set diff for cnv vs normal div
  70348. if (this.elt instanceof HTMLCanvasElement) {
  70349. var j = {};
  70350. var k = this.elt.getContext('2d');
  70351. var prop;
  70352. for (prop in k) {
  70353. j[prop] = k[prop];
  70354. }
  70355. this.elt.setAttribute('width', aW * this._pInst._pixelDensity);
  70356. this.elt.setAttribute('height', aH * this._pInst._pixelDensity);
  70357. this.elt.style.width = aW + 'px';
  70358. this.elt.style.height = aH + 'px';
  70359. this._pInst.scale(this._pInst._pixelDensity, this._pInst._pixelDensity);
  70360. for (prop in j) {
  70361. this.elt.getContext('2d')[prop] = j[prop];
  70362. }
  70363. } else {
  70364. this.elt.style.width = aW + 'px';
  70365. this.elt.style.height = aH + 'px';
  70366. this.elt.width = aW;
  70367. this.elt.height = aH;
  70368. }
  70369. this.width = this.elt.offsetWidth;
  70370. this.height = this.elt.offsetHeight;
  70371. if (this._pInst && this._pInst._curElement) {
  70372. // main canvas associated with p5 instance
  70373. if (this._pInst._curElement.elt === this.elt) {
  70374. this._pInst._setProperty('width', this.elt.offsetWidth);
  70375. this._pInst._setProperty('height', this.elt.offsetHeight);
  70376. }
  70377. }
  70378. }
  70379. return this;
  70380. }
  70381. };
  70382. /**
  70383. * Removes the element, stops all media streams, and deregisters all listeners.
  70384. * @method remove
  70385. * @example
  70386. * <div class='norender'><code>
  70387. * let myDiv = createDiv('this is some text');
  70388. * myDiv.remove();
  70389. * </code></div>
  70390. */
  70391. _main.default.Element.prototype.remove = function() {
  70392. // stop all audios/videos and detach all devices like microphone/camera etc
  70393. // used as input/output for audios/videos.
  70394. if (this instanceof _main.default.MediaElement) {
  70395. this.stop();
  70396. var sources = this.elt.srcObject;
  70397. if (sources !== null) {
  70398. var tracks = sources.getTracks();
  70399. tracks.forEach(function(track) {
  70400. track.stop();
  70401. });
  70402. }
  70403. }
  70404. // delete the reference in this._pInst._elements
  70405. var index = this._pInst._elements.indexOf(this);
  70406. if (index !== -1) {
  70407. this._pInst._elements.splice(index, 1);
  70408. }
  70409. // deregister events
  70410. for (var ev in this._events) {
  70411. this.elt.removeEventListener(ev, this._events[ev]);
  70412. }
  70413. if (this.elt && this.elt.parentNode) {
  70414. this.elt.parentNode.removeChild(this.elt);
  70415. }
  70416. };
  70417. /**
  70418. * Registers a callback that gets called every time a file that is
  70419. * dropped on the element has been loaded.
  70420. * p5 will load every dropped file into memory and pass it as a p5.File object to the callback.
  70421. * Multiple files dropped at the same time will result in multiple calls to the callback.
  70422. *
  70423. * You can optionally pass a second callback which will be registered to the raw
  70424. * <a href="https://developer.mozilla.org/en-US/docs/Web/Events/drop">drop</a> event.
  70425. * The callback will thus be provided the original
  70426. * <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent">DragEvent</a>.
  70427. * Dropping multiple files at the same time will trigger the second callback once per drop,
  70428. * whereas the first callback will trigger for each loaded file.
  70429. *
  70430. * @method drop
  70431. * @param {Function} callback callback to receive loaded file, called for each file dropped.
  70432. * @param {Function} [fxn] callback triggered once when files are dropped with the drop event.
  70433. * @chainable
  70434. * @example
  70435. * <div><code>
  70436. * function setup() {
  70437. * let c = createCanvas(100, 100);
  70438. * background(200);
  70439. * textAlign(CENTER);
  70440. * text('drop file', width / 2, height / 2);
  70441. * c.drop(gotFile);
  70442. * }
  70443. *
  70444. * function gotFile(file) {
  70445. * background(200);
  70446. * text('received file:', width / 2, height / 2);
  70447. * text(file.name, width / 2, height / 2 + 50);
  70448. * }
  70449. * </code></div>
  70450. *
  70451. * <div><code>
  70452. * let img;
  70453. *
  70454. * function setup() {
  70455. * let c = createCanvas(100, 100);
  70456. * background(200);
  70457. * textAlign(CENTER);
  70458. * text('drop image', width / 2, height / 2);
  70459. * c.drop(gotFile);
  70460. * }
  70461. *
  70462. * function draw() {
  70463. * if (img) {
  70464. * image(img, 0, 0, width, height);
  70465. * }
  70466. * }
  70467. *
  70468. * function gotFile(file) {
  70469. * img = createImg(file.data, '').hide();
  70470. * }
  70471. * </code></div>
  70472. *
  70473. * @alt
  70474. * Canvas turns into whatever image is dragged/dropped onto it.
  70475. */
  70476. _main.default.Element.prototype.drop = function(callback, fxn) {
  70477. // Is the file stuff supported?
  70478. if (window.File && window.FileReader && window.FileList && window.Blob) {
  70479. if (!this._dragDisabled) {
  70480. this._dragDisabled = true;
  70481. var preventDefault = function preventDefault(evt) {
  70482. evt.preventDefault();
  70483. };
  70484. // If you want to be able to drop you've got to turn off
  70485. // a lot of default behavior.
  70486. // avoid `attachListener` here, since it overrides other handlers.
  70487. this.elt.addEventListener('dragover', preventDefault);
  70488. // If this is a drag area we need to turn off the default behavior
  70489. this.elt.addEventListener('dragleave', preventDefault);
  70490. }
  70491. // Deal with the files
  70492. _main.default.Element._attachListener(
  70493. 'drop',
  70494. function(evt) {
  70495. evt.preventDefault();
  70496. // Call the second argument as a callback that receives the raw drop event
  70497. if (typeof fxn === 'function') {
  70498. fxn.call(this, evt);
  70499. }
  70500. // A FileList
  70501. var files = evt.dataTransfer.files;
  70502. // Load each one and trigger the callback
  70503. for (var i = 0; i < files.length; i++) {
  70504. var f = files[i];
  70505. _main.default.File._load(f, callback);
  70506. }
  70507. },
  70508. this
  70509. );
  70510. } else {
  70511. console.log('The File APIs are not fully supported in this browser.');
  70512. }
  70513. return this;
  70514. };
  70515. // =============================================================================
  70516. // p5.MediaElement additions
  70517. // =============================================================================
  70518. /**
  70519. * Extends <a href="#/p5.Element">p5.Element</a> to handle audio and video. In addition to the methods
  70520. * of <a href="#/p5.Element">p5.Element</a>, it also contains methods for controlling media. It is not
  70521. * called directly, but <a href="#/p5.MediaElement">p5.MediaElement</a>s are created by calling <a href="#/p5/createVideo">createVideo</a>,
  70522. * <a href="#/p5/createAudio">createAudio</a>, and <a href="#/p5/createCapture">createCapture</a>.
  70523. *
  70524. * @class p5.MediaElement
  70525. * @constructor
  70526. * @param {String} elt DOM node that is wrapped
  70527. */
  70528. _main.default.MediaElement = function(elt, pInst) {
  70529. _main.default.Element.call(this, elt, pInst);
  70530. var self = this;
  70531. this.elt.crossOrigin = 'anonymous';
  70532. this._prevTime = 0;
  70533. this._cueIDCounter = 0;
  70534. this._cues = [];
  70535. this._pixelsState = this;
  70536. this._pixelDensity = 1;
  70537. this._modified = false;
  70538. /**
  70539. * Path to the media element source.
  70540. *
  70541. * @property src
  70542. * @return {String} src
  70543. * @example
  70544. * <div><code>
  70545. * let ele;
  70546. *
  70547. * function setup() {
  70548. * background(250);
  70549. *
  70550. * //p5.MediaElement objects are usually created
  70551. * //by calling the createAudio(), createVideo(),
  70552. * //and createCapture() functions.
  70553. *
  70554. * //In this example we create
  70555. * //a new p5.MediaElement via createAudio().
  70556. * ele = createAudio('assets/beat.mp3');
  70557. *
  70558. * //We'll set up our example so that
  70559. * //when you click on the text,
  70560. * //an alert box displays the MediaElement's
  70561. * //src field.
  70562. * textAlign(CENTER);
  70563. * text('Click Me!', width / 2, height / 2);
  70564. * }
  70565. *
  70566. * function mouseClicked() {
  70567. * //here we test if the mouse is over the
  70568. * //canvas element when it's clicked
  70569. * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {
  70570. * //Show our p5.MediaElement's src field
  70571. * alert(ele.src);
  70572. * }
  70573. * }
  70574. * </code></div>
  70575. */
  70576. Object.defineProperty(self, 'src', {
  70577. get: function get() {
  70578. var firstChildSrc = self.elt.children[0].src;
  70579. var srcVal = self.elt.src === window.location.href ? '' : self.elt.src;
  70580. var ret = firstChildSrc === window.location.href ? srcVal : firstChildSrc;
  70581. return ret;
  70582. },
  70583. set: function set(newValue) {
  70584. for (var i = 0; i < self.elt.children.length; i++) {
  70585. self.elt.removeChild(self.elt.children[i]);
  70586. }
  70587. var source = document.createElement('source');
  70588. source.src = newValue;
  70589. elt.appendChild(source);
  70590. self.elt.src = newValue;
  70591. self.modified = true;
  70592. }
  70593. });
  70594. // private _onended callback, set by the method: onended(callback)
  70595. self._onended = function() {};
  70596. self.elt.onended = function() {
  70597. self._onended(self);
  70598. };
  70599. };
  70600. _main.default.MediaElement.prototype = Object.create(
  70601. _main.default.Element.prototype
  70602. );
  70603. /**
  70604. * Play an HTML5 media element.
  70605. *
  70606. * @method play
  70607. * @chainable
  70608. * @example
  70609. * <div><code>
  70610. * let ele;
  70611. *
  70612. * function setup() {
  70613. * //p5.MediaElement objects are usually created
  70614. * //by calling the createAudio(), createVideo(),
  70615. * //and createCapture() functions.
  70616. *
  70617. * //In this example we create
  70618. * //a new p5.MediaElement via createAudio().
  70619. * ele = createAudio('assets/beat.mp3');
  70620. *
  70621. * background(250);
  70622. * textAlign(CENTER);
  70623. * text('Click to Play!', width / 2, height / 2);
  70624. * }
  70625. *
  70626. * function mouseClicked() {
  70627. * //here we test if the mouse is over the
  70628. * //canvas element when it's clicked
  70629. * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {
  70630. * //Here we call the play() function on
  70631. * //the p5.MediaElement we created above.
  70632. * //This will start the audio sample.
  70633. * ele.play();
  70634. *
  70635. * background(200);
  70636. * text('You clicked Play!', width / 2, height / 2);
  70637. * }
  70638. * }
  70639. * </code></div>
  70640. */
  70641. _main.default.MediaElement.prototype.play = function() {
  70642. var _this = this;
  70643. if (this.elt.currentTime === this.elt.duration) {
  70644. this.elt.currentTime = 0;
  70645. }
  70646. var promise;
  70647. if (this.elt.readyState > 1) {
  70648. promise = this.elt.play();
  70649. } else {
  70650. // in Chrome, playback cannot resume after being stopped and must reload
  70651. this.elt.load();
  70652. promise = this.elt.play();
  70653. }
  70654. if (promise && promise.catch) {
  70655. promise.catch(function(e) {
  70656. // if it's an autoplay failure error
  70657. if (e.name === 'NotAllowedError') {
  70658. _main.default._friendlyAutoplayError(_this.src);
  70659. } else {
  70660. // any other kind of error
  70661. console.error('Media play method encountered an unexpected error', e);
  70662. }
  70663. });
  70664. }
  70665. return this;
  70666. };
  70667. /**
  70668. * Stops an HTML5 media element (sets current time to zero).
  70669. *
  70670. * @method stop
  70671. * @chainable
  70672. * @example
  70673. * <div><code>
  70674. * //This example both starts
  70675. * //and stops a sound sample
  70676. * //when the user clicks the canvas
  70677. *
  70678. * //We will store the p5.MediaElement
  70679. * //object in here
  70680. * let ele;
  70681. *
  70682. * //while our audio is playing,
  70683. * //this will be set to true
  70684. * let sampleIsPlaying = false;
  70685. *
  70686. * function setup() {
  70687. * //Here we create a p5.MediaElement object
  70688. * //using the createAudio() function.
  70689. * ele = createAudio('assets/beat.mp3');
  70690. * background(200);
  70691. * textAlign(CENTER);
  70692. * text('Click to play!', width / 2, height / 2);
  70693. * }
  70694. *
  70695. * function mouseClicked() {
  70696. * //here we test if the mouse is over the
  70697. * //canvas element when it's clicked
  70698. * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {
  70699. * background(200);
  70700. *
  70701. * if (sampleIsPlaying) {
  70702. * //if the sample is currently playing
  70703. * //calling the stop() function on
  70704. * //our p5.MediaElement will stop
  70705. * //it and reset its current
  70706. * //time to 0 (i.e. it will start
  70707. * //at the beginning the next time
  70708. * //you play it)
  70709. * ele.stop();
  70710. *
  70711. * sampleIsPlaying = false;
  70712. * text('Click to play!', width / 2, height / 2);
  70713. * } else {
  70714. * //loop our sound element until we
  70715. * //call ele.stop() on it.
  70716. * ele.loop();
  70717. *
  70718. * sampleIsPlaying = true;
  70719. * text('Click to stop!', width / 2, height / 2);
  70720. * }
  70721. * }
  70722. * }
  70723. * </code></div>
  70724. */
  70725. _main.default.MediaElement.prototype.stop = function() {
  70726. this.elt.pause();
  70727. this.elt.currentTime = 0;
  70728. return this;
  70729. };
  70730. /**
  70731. * Pauses an HTML5 media element.
  70732. *
  70733. * @method pause
  70734. * @chainable
  70735. * @example
  70736. * <div><code>
  70737. * //This example both starts
  70738. * //and pauses a sound sample
  70739. * //when the user clicks the canvas
  70740. *
  70741. * //We will store the p5.MediaElement
  70742. * //object in here
  70743. * let ele;
  70744. *
  70745. * //while our audio is playing,
  70746. * //this will be set to true
  70747. * let sampleIsPlaying = false;
  70748. *
  70749. * function setup() {
  70750. * //Here we create a p5.MediaElement object
  70751. * //using the createAudio() function.
  70752. * ele = createAudio('assets/lucky_dragons.mp3');
  70753. * background(200);
  70754. * textAlign(CENTER);
  70755. * text('Click to play!', width / 2, height / 2);
  70756. * }
  70757. *
  70758. * function mouseClicked() {
  70759. * //here we test if the mouse is over the
  70760. * //canvas element when it's clicked
  70761. * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {
  70762. * background(200);
  70763. *
  70764. * if (sampleIsPlaying) {
  70765. * //Calling pause() on our
  70766. * //p5.MediaElement will stop it
  70767. * //playing, but when we call the
  70768. * //loop() or play() functions
  70769. * //the sample will start from
  70770. * //where we paused it.
  70771. * ele.pause();
  70772. *
  70773. * sampleIsPlaying = false;
  70774. * text('Click to resume!', width / 2, height / 2);
  70775. * } else {
  70776. * //loop our sound element until we
  70777. * //call ele.pause() on it.
  70778. * ele.loop();
  70779. *
  70780. * sampleIsPlaying = true;
  70781. * text('Click to pause!', width / 2, height / 2);
  70782. * }
  70783. * }
  70784. * }
  70785. * </code></div>
  70786. */
  70787. _main.default.MediaElement.prototype.pause = function() {
  70788. this.elt.pause();
  70789. return this;
  70790. };
  70791. /**
  70792. * Set 'loop' to true for an HTML5 media element, and starts playing.
  70793. *
  70794. * @method loop
  70795. * @chainable
  70796. * @example
  70797. * <div><code>
  70798. * //Clicking the canvas will loop
  70799. * //the audio sample until the user
  70800. * //clicks again to stop it
  70801. *
  70802. * //We will store the p5.MediaElement
  70803. * //object in here
  70804. * let ele;
  70805. *
  70806. * //while our audio is playing,
  70807. * //this will be set to true
  70808. * let sampleIsLooping = false;
  70809. *
  70810. * function setup() {
  70811. * //Here we create a p5.MediaElement object
  70812. * //using the createAudio() function.
  70813. * ele = createAudio('assets/lucky_dragons.mp3');
  70814. * background(200);
  70815. * textAlign(CENTER);
  70816. * text('Click to loop!', width / 2, height / 2);
  70817. * }
  70818. *
  70819. * function mouseClicked() {
  70820. * //here we test if the mouse is over the
  70821. * //canvas element when it's clicked
  70822. * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {
  70823. * background(200);
  70824. *
  70825. * if (!sampleIsLooping) {
  70826. * //loop our sound element until we
  70827. * //call ele.stop() on it.
  70828. * ele.loop();
  70829. *
  70830. * sampleIsLooping = true;
  70831. * text('Click to stop!', width / 2, height / 2);
  70832. * } else {
  70833. * ele.stop();
  70834. *
  70835. * sampleIsLooping = false;
  70836. * text('Click to loop!', width / 2, height / 2);
  70837. * }
  70838. * }
  70839. * }
  70840. * </code></div>
  70841. */
  70842. _main.default.MediaElement.prototype.loop = function() {
  70843. this.elt.setAttribute('loop', true);
  70844. this.play();
  70845. return this;
  70846. };
  70847. /**
  70848. * Set 'loop' to false for an HTML5 media element. Element will stop
  70849. * when it reaches the end.
  70850. *
  70851. * @method noLoop
  70852. * @chainable
  70853. * @example
  70854. * <div><code>
  70855. * //This example both starts
  70856. * //and stops loop of sound sample
  70857. * //when the user clicks the canvas
  70858. *
  70859. * //We will store the p5.MediaElement
  70860. * //object in here
  70861. * let ele;
  70862. * //while our audio is playing,
  70863. * //this will be set to true
  70864. * let sampleIsPlaying = false;
  70865. *
  70866. * function setup() {
  70867. * //Here we create a p5.MediaElement object
  70868. * //using the createAudio() function.
  70869. * ele = createAudio('assets/beat.mp3');
  70870. * background(200);
  70871. * textAlign(CENTER);
  70872. * text('Click to play!', width / 2, height / 2);
  70873. * }
  70874. *
  70875. * function mouseClicked() {
  70876. * //here we test if the mouse is over the
  70877. * //canvas element when it's clicked
  70878. * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {
  70879. * background(200);
  70880. *
  70881. * if (sampleIsPlaying) {
  70882. * ele.noLoop();
  70883. * sampleIsPlaying = false;
  70884. * text('No more Loops!', width / 2, height / 2);
  70885. * } else {
  70886. * ele.loop();
  70887. * sampleIsPlaying = true;
  70888. * text('Click to stop looping!', width / 2, height / 2);
  70889. * }
  70890. * }
  70891. * }
  70892. * </code></div>
  70893. */
  70894. _main.default.MediaElement.prototype.noLoop = function() {
  70895. this.elt.removeAttribute('loop');
  70896. return this;
  70897. };
  70898. /**
  70899. * Sets up logic to check that autoplay succeeded.
  70900. *
  70901. * @method setupAutoplayFailDetection
  70902. * @private
  70903. */
  70904. _main.default.MediaElement.prototype._setupAutoplayFailDetection = function() {
  70905. var _this2 = this;
  70906. var timeout = setTimeout(function() {
  70907. return _main.default._friendlyAutoplayError(_this2.src);
  70908. }, 500);
  70909. this.elt.addEventListener(
  70910. 'play',
  70911. function() {
  70912. return clearTimeout(timeout);
  70913. },
  70914. {
  70915. passive: true,
  70916. once: true
  70917. }
  70918. );
  70919. };
  70920. /**
  70921. * Set HTML5 media element to autoplay or not. If no argument is specified, by
  70922. * default it will autoplay.
  70923. *
  70924. * @method autoplay
  70925. * @param {Boolean} shouldAutoplay whether the element should autoplay
  70926. * @chainable
  70927. * @example
  70928. * <div><code>
  70929. * let videoElement;
  70930. * function setup() {
  70931. * noCanvas();
  70932. * videoElement = createVideo(['assets/small.mp4'], onVideoLoad);
  70933. * }
  70934. * function onVideoLoad() {
  70935. * // The media will play as soon as it is loaded.
  70936. * videoElement.autoplay();
  70937. * videoElement.volume(0);
  70938. * videoElement.size(100, 100);
  70939. * }
  70940. * </code></div>
  70941. *
  70942. * <div><code>
  70943. * let videoElement;
  70944. * function setup() {
  70945. * noCanvas();
  70946. * videoElement = createVideo(['assets/small.mp4'], onVideoLoad);
  70947. * }
  70948. * function onVideoLoad() {
  70949. * // The media will not play untill some explicitly triggered.
  70950. * videoElement.autoplay(false);
  70951. * videoElement.volume(0);
  70952. * videoElement.size(100, 100);
  70953. * }
  70954. *
  70955. * function mouseClicked() {
  70956. * videoElement.play();
  70957. * }
  70958. * </code></div>
  70959. *
  70960. * @alt
  70961. * An example of a video element which autoplays after it is loaded.
  70962. * An example of a video element which waits for a trigger for playing.
  70963. */
  70964. _main.default.MediaElement.prototype.autoplay = function(val) {
  70965. var _this3 = this;
  70966. var oldVal = this.elt.getAttribute('autoplay');
  70967. this.elt.setAttribute('autoplay', val);
  70968. // if we turned on autoplay
  70969. if (val && !oldVal) {
  70970. // bind method to this scope
  70971. var setupAutoplayFailDetection = function setupAutoplayFailDetection() {
  70972. return _this3._setupAutoplayFailDetection();
  70973. };
  70974. // if media is ready to play, schedule check now
  70975. if (this.elt.readyState === 4) {
  70976. setupAutoplayFailDetection();
  70977. } else {
  70978. // otherwise, schedule check whenever it is ready
  70979. this.elt.addEventListener('canplay', setupAutoplayFailDetection, {
  70980. passive: true,
  70981. once: true
  70982. });
  70983. }
  70984. }
  70985. return this;
  70986. };
  70987. /**
  70988. * Sets volume for this HTML5 media element. If no argument is given,
  70989. * returns the current volume.
  70990. *
  70991. * @method volume
  70992. * @return {Number} current volume
  70993. *
  70994. * @example
  70995. * <div><code>
  70996. * let ele;
  70997. * function setup() {
  70998. * // p5.MediaElement objects are usually created
  70999. * // by calling the createAudio(), createVideo(),
  71000. * // and createCapture() functions.
  71001. * // In this example we create
  71002. * // a new p5.MediaElement via createAudio().
  71003. * ele = createAudio('assets/lucky_dragons.mp3');
  71004. * background(250);
  71005. * textAlign(CENTER);
  71006. * text('Click to Play!', width / 2, height / 2);
  71007. * }
  71008. * function mouseClicked() {
  71009. * // Here we call the volume() function
  71010. * // on the sound element to set its volume
  71011. * // Volume must be between 0.0 and 1.0
  71012. * ele.volume(0.2);
  71013. * ele.play();
  71014. * background(200);
  71015. * text('You clicked Play!', width / 2, height / 2);
  71016. * }
  71017. * </code></div>
  71018. * <div><code>
  71019. * let audio;
  71020. * let counter = 0;
  71021. *
  71022. * function loaded() {
  71023. * audio.play();
  71024. * }
  71025. *
  71026. * function setup() {
  71027. * audio = createAudio('assets/lucky_dragons.mp3', loaded);
  71028. * textAlign(CENTER);
  71029. * }
  71030. *
  71031. * function draw() {
  71032. * if (counter === 0) {
  71033. * background(0, 255, 0);
  71034. * text('volume(0.9)', width / 2, height / 2);
  71035. * } else if (counter === 1) {
  71036. * background(255, 255, 0);
  71037. * text('volume(0.5)', width / 2, height / 2);
  71038. * } else if (counter === 2) {
  71039. * background(255, 0, 0);
  71040. * text('volume(0.1)', width / 2, height / 2);
  71041. * }
  71042. * }
  71043. *
  71044. * function mousePressed() {
  71045. * counter++;
  71046. * if (counter === 0) {
  71047. * audio.volume(0.9);
  71048. * } else if (counter === 1) {
  71049. * audio.volume(0.5);
  71050. * } else if (counter === 2) {
  71051. * audio.volume(0.1);
  71052. * } else {
  71053. * counter = 0;
  71054. * audio.volume(0.9);
  71055. * }
  71056. * }
  71057. * </code>
  71058. * </div>
  71059. */
  71060. /**
  71061. * @method volume
  71062. * @param {Number} val volume between 0.0 and 1.0
  71063. * @chainable
  71064. */
  71065. _main.default.MediaElement.prototype.volume = function(val) {
  71066. if (typeof val === 'undefined') {
  71067. return this.elt.volume;
  71068. } else {
  71069. this.elt.volume = val;
  71070. }
  71071. };
  71072. /**
  71073. * If no arguments are given, returns the current playback speed of the
  71074. * element. The speed parameter sets the speed where 2.0 will play the
  71075. * element twice as fast, 0.5 will play at half the speed, and -1 will play
  71076. * the element in normal speed in reverse.(Note that not all browsers support
  71077. * backward playback and even if they do, playback might not be smooth.)
  71078. *
  71079. * @method speed
  71080. * @return {Number} current playback speed of the element
  71081. *
  71082. * @example
  71083. * <div class='norender notest'><code>
  71084. * //Clicking the canvas will loop
  71085. * //the audio sample until the user
  71086. * //clicks again to stop it
  71087. *
  71088. * //We will store the p5.MediaElement
  71089. * //object in here
  71090. * let ele;
  71091. * let button;
  71092. *
  71093. * function setup() {
  71094. * createCanvas(710, 400);
  71095. * //Here we create a p5.MediaElement object
  71096. * //using the createAudio() function.
  71097. * ele = createAudio('assets/beat.mp3');
  71098. * ele.loop();
  71099. * background(200);
  71100. *
  71101. * button = createButton('2x speed');
  71102. * button.position(100, 68);
  71103. * button.mousePressed(twice_speed);
  71104. *
  71105. * button = createButton('half speed');
  71106. * button.position(200, 68);
  71107. * button.mousePressed(half_speed);
  71108. *
  71109. * button = createButton('reverse play');
  71110. * button.position(300, 68);
  71111. * button.mousePressed(reverse_speed);
  71112. *
  71113. * button = createButton('STOP');
  71114. * button.position(400, 68);
  71115. * button.mousePressed(stop_song);
  71116. *
  71117. * button = createButton('PLAY!');
  71118. * button.position(500, 68);
  71119. * button.mousePressed(play_speed);
  71120. * }
  71121. *
  71122. * function twice_speed() {
  71123. * ele.speed(2);
  71124. * }
  71125. *
  71126. * function half_speed() {
  71127. * ele.speed(0.5);
  71128. * }
  71129. *
  71130. * function reverse_speed() {
  71131. * ele.speed(-1);
  71132. * }
  71133. *
  71134. * function stop_song() {
  71135. * ele.stop();
  71136. * }
  71137. *
  71138. * function play_speed() {
  71139. * ele.play();
  71140. * }
  71141. * </code></div>
  71142. */
  71143. /**
  71144. * @method speed
  71145. * @param {Number} speed speed multiplier for element playback
  71146. * @chainable
  71147. */
  71148. _main.default.MediaElement.prototype.speed = function(val) {
  71149. if (typeof val === 'undefined') {
  71150. return this.presetPlaybackRate || this.elt.playbackRate;
  71151. } else {
  71152. if (this.loadedmetadata) {
  71153. this.elt.playbackRate = val;
  71154. } else {
  71155. this.presetPlaybackRate = val;
  71156. }
  71157. }
  71158. };
  71159. /**
  71160. * If no arguments are given, returns the current time of the element.
  71161. * If an argument is given the current time of the element is set to it.
  71162. *
  71163. * @method time
  71164. * @return {Number} current time (in seconds)
  71165. *
  71166. * @example
  71167. * <div><code>
  71168. * let ele;
  71169. * let beginning = true;
  71170. * function setup() {
  71171. * //p5.MediaElement objects are usually created
  71172. * //by calling the createAudio(), createVideo(),
  71173. * //and createCapture() functions.
  71174. *
  71175. * //In this example we create
  71176. * //a new p5.MediaElement via createAudio().
  71177. * ele = createAudio('assets/lucky_dragons.mp3');
  71178. * background(250);
  71179. * textAlign(CENTER);
  71180. * text('start at beginning', width / 2, height / 2);
  71181. * }
  71182. *
  71183. * // this function fires with click anywhere
  71184. * function mousePressed() {
  71185. * if (beginning === true) {
  71186. * // here we start the sound at the beginning
  71187. * // time(0) is not necessary here
  71188. * // as this produces the same result as
  71189. * // play()
  71190. * ele.play().time(0);
  71191. * background(200);
  71192. * text('jump 2 sec in', width / 2, height / 2);
  71193. * beginning = false;
  71194. * } else {
  71195. * // here we jump 2 seconds into the sound
  71196. * ele.play().time(2);
  71197. * background(250);
  71198. * text('start at beginning', width / 2, height / 2);
  71199. * beginning = true;
  71200. * }
  71201. * }
  71202. * </code></div>
  71203. */
  71204. /**
  71205. * @method time
  71206. * @param {Number} time time to jump to (in seconds)
  71207. * @chainable
  71208. */
  71209. _main.default.MediaElement.prototype.time = function(val) {
  71210. if (typeof val === 'undefined') {
  71211. return this.elt.currentTime;
  71212. } else {
  71213. this.elt.currentTime = val;
  71214. return this;
  71215. }
  71216. };
  71217. /**
  71218. * Returns the duration of the HTML5 media element.
  71219. *
  71220. * @method duration
  71221. * @return {Number} duration
  71222. *
  71223. * @example
  71224. * <div><code>
  71225. * let ele;
  71226. * function setup() {
  71227. * //p5.MediaElement objects are usually created
  71228. * //by calling the createAudio(), createVideo(),
  71229. * //and createCapture() functions.
  71230. * //In this example we create
  71231. * //a new p5.MediaElement via createAudio().
  71232. * ele = createAudio('assets/doorbell.mp3');
  71233. * background(250);
  71234. * textAlign(CENTER);
  71235. * text('Click to know the duration!', 10, 25, 70, 80);
  71236. * }
  71237. * function mouseClicked() {
  71238. * ele.play();
  71239. * background(200);
  71240. * //ele.duration dislpays the duration
  71241. * text(ele.duration() + ' seconds', width / 2, height / 2);
  71242. * }
  71243. * </code></div>
  71244. */
  71245. _main.default.MediaElement.prototype.duration = function() {
  71246. return this.elt.duration;
  71247. };
  71248. _main.default.MediaElement.prototype.pixels = [];
  71249. _main.default.MediaElement.prototype._ensureCanvas = function() {
  71250. if (!this.canvas) {
  71251. this.canvas = document.createElement('canvas');
  71252. this.drawingContext = this.canvas.getContext('2d');
  71253. this.setModified(true);
  71254. }
  71255. if (this.loadedmetadata) {
  71256. // wait for metadata for w/h
  71257. if (this.canvas.width !== this.elt.width) {
  71258. this.canvas.width = this.elt.width;
  71259. this.canvas.height = this.elt.height;
  71260. this.width = this.canvas.width;
  71261. this.height = this.canvas.height;
  71262. }
  71263. this.drawingContext.drawImage(
  71264. this.elt,
  71265. 0,
  71266. 0,
  71267. this.canvas.width,
  71268. this.canvas.height
  71269. );
  71270. this.setModified(true);
  71271. }
  71272. };
  71273. _main.default.MediaElement.prototype.loadPixels = function() {
  71274. this._ensureCanvas();
  71275. return _main.default.Renderer2D.prototype.loadPixels.apply(this, arguments);
  71276. };
  71277. _main.default.MediaElement.prototype.updatePixels = function(x, y, w, h) {
  71278. if (this.loadedmetadata) {
  71279. // wait for metadata
  71280. this._ensureCanvas();
  71281. _main.default.Renderer2D.prototype.updatePixels.call(this, x, y, w, h);
  71282. }
  71283. this.setModified(true);
  71284. return this;
  71285. };
  71286. _main.default.MediaElement.prototype.get = function() {
  71287. this._ensureCanvas();
  71288. return _main.default.Renderer2D.prototype.get.apply(this, arguments);
  71289. };
  71290. _main.default.MediaElement.prototype._getPixel = function() {
  71291. this.loadPixels();
  71292. return _main.default.Renderer2D.prototype._getPixel.apply(this, arguments);
  71293. };
  71294. _main.default.MediaElement.prototype.set = function(x, y, imgOrCol) {
  71295. if (this.loadedmetadata) {
  71296. // wait for metadata
  71297. this._ensureCanvas();
  71298. _main.default.Renderer2D.prototype.set.call(this, x, y, imgOrCol);
  71299. this.setModified(true);
  71300. }
  71301. };
  71302. _main.default.MediaElement.prototype.copy = function() {
  71303. this._ensureCanvas();
  71304. _main.default.prototype.copy.apply(this, arguments);
  71305. };
  71306. _main.default.MediaElement.prototype.mask = function() {
  71307. this.loadPixels();
  71308. this.setModified(true);
  71309. _main.default.Image.prototype.mask.apply(this, arguments);
  71310. };
  71311. /**
  71312. * helper method for web GL mode to figure out if the element
  71313. * has been modified and might need to be re-uploaded to texture
  71314. * memory between frames.
  71315. * @method isModified
  71316. * @private
  71317. * @return {boolean} a boolean indicating whether or not the
  71318. * image has been updated or modified since last texture upload.
  71319. */
  71320. _main.default.MediaElement.prototype.isModified = function() {
  71321. return this._modified;
  71322. };
  71323. /**
  71324. * helper method for web GL mode to indicate that an element has been
  71325. * changed or unchanged since last upload. gl texture upload will
  71326. * set this value to false after uploading the texture; or might set
  71327. * it to true if metadata has become available but there is no actual
  71328. * texture data available yet..
  71329. * @method setModified
  71330. * @param {boolean} val sets whether or not the element has been
  71331. * modified.
  71332. * @private
  71333. */
  71334. _main.default.MediaElement.prototype.setModified = function(value) {
  71335. this._modified = value;
  71336. };
  71337. /**
  71338. * Schedule an event to be called when the audio or video
  71339. * element reaches the end. If the element is looping,
  71340. * this will not be called. The element is passed in
  71341. * as the argument to the onended callback.
  71342. *
  71343. * @method onended
  71344. * @param {Function} callback function to call when the
  71345. * soundfile has ended. The
  71346. * media element will be passed
  71347. * in as the argument to the
  71348. * callback.
  71349. * @chainable
  71350. * @example
  71351. * <div><code>
  71352. * function setup() {
  71353. * let audioEl = createAudio('assets/beat.mp3');
  71354. * audioEl.showControls();
  71355. * audioEl.onended(sayDone);
  71356. * }
  71357. *
  71358. * function sayDone(elt) {
  71359. * alert('done playing ' + elt.src);
  71360. * }
  71361. * </code></div>
  71362. */
  71363. _main.default.MediaElement.prototype.onended = function(callback) {
  71364. this._onended = callback;
  71365. return this;
  71366. };
  71367. /*** CONNECT TO WEB AUDIO API / p5.sound.js ***/
  71368. /**
  71369. * Send the audio output of this element to a specified audioNode or
  71370. * p5.sound object. If no element is provided, connects to p5's main
  71371. * output. That connection is established when this method is first called.
  71372. * All connections are removed by the .disconnect() method.
  71373. *
  71374. * This method is meant to be used with the p5.sound.js addon library.
  71375. *
  71376. * @method connect
  71377. * @param {AudioNode|Object} audioNode AudioNode from the Web Audio API,
  71378. * or an object from the p5.sound library
  71379. */
  71380. _main.default.MediaElement.prototype.connect = function(obj) {
  71381. var audioContext, mainOutput;
  71382. // if p5.sound exists, same audio context
  71383. if (typeof _main.default.prototype.getAudioContext === 'function') {
  71384. audioContext = _main.default.prototype.getAudioContext();
  71385. mainOutput = _main.default.soundOut.input;
  71386. } else {
  71387. try {
  71388. audioContext = obj.context;
  71389. mainOutput = audioContext.destination;
  71390. } catch (e) {
  71391. throw 'connect() is meant to be used with Web Audio API or p5.sound.js';
  71392. }
  71393. }
  71394. // create a Web Audio MediaElementAudioSourceNode if none already exists
  71395. if (!this.audioSourceNode) {
  71396. this.audioSourceNode = audioContext.createMediaElementSource(this.elt);
  71397. // connect to main output when this method is first called
  71398. this.audioSourceNode.connect(mainOutput);
  71399. }
  71400. // connect to object if provided
  71401. if (obj) {
  71402. if (obj.input) {
  71403. this.audioSourceNode.connect(obj.input);
  71404. } else {
  71405. this.audioSourceNode.connect(obj);
  71406. }
  71407. } else {
  71408. // otherwise connect to main output of p5.sound / AudioContext
  71409. this.audioSourceNode.connect(mainOutput);
  71410. }
  71411. };
  71412. /**
  71413. * Disconnect all Web Audio routing, including to main output.
  71414. * This is useful if you want to re-route the output through
  71415. * audio effects, for example.
  71416. *
  71417. * @method disconnect
  71418. */
  71419. _main.default.MediaElement.prototype.disconnect = function() {
  71420. if (this.audioSourceNode) {
  71421. this.audioSourceNode.disconnect();
  71422. } else {
  71423. throw 'nothing to disconnect';
  71424. }
  71425. };
  71426. /*** SHOW / HIDE CONTROLS ***/
  71427. /**
  71428. * Show the default MediaElement controls, as determined by the web browser.
  71429. *
  71430. * @method showControls
  71431. * @example
  71432. * <div><code>
  71433. * let ele;
  71434. * function setup() {
  71435. * //p5.MediaElement objects are usually created
  71436. * //by calling the createAudio(), createVideo(),
  71437. * //and createCapture() functions.
  71438. * //In this example we create
  71439. * //a new p5.MediaElement via createAudio()
  71440. * ele = createAudio('assets/lucky_dragons.mp3');
  71441. * background(200);
  71442. * textAlign(CENTER);
  71443. * text('Click to Show Controls!', 10, 25, 70, 80);
  71444. * }
  71445. * function mousePressed() {
  71446. * ele.showControls();
  71447. * background(200);
  71448. * text('Controls Shown', width / 2, height / 2);
  71449. * }
  71450. * </code></div>
  71451. */
  71452. _main.default.MediaElement.prototype.showControls = function() {
  71453. // must set style for the element to show on the page
  71454. this.elt.style['text-align'] = 'inherit';
  71455. this.elt.controls = true;
  71456. };
  71457. /**
  71458. * Hide the default mediaElement controls.
  71459. * @method hideControls
  71460. * @example
  71461. * <div><code>
  71462. * let ele;
  71463. * function setup() {
  71464. * //p5.MediaElement objects are usually created
  71465. * //by calling the createAudio(), createVideo(),
  71466. * //and createCapture() functions.
  71467. * //In this example we create
  71468. * //a new p5.MediaElement via createAudio()
  71469. * ele = createAudio('assets/lucky_dragons.mp3');
  71470. * ele.showControls();
  71471. * background(200);
  71472. * textAlign(CENTER);
  71473. * text('Click to hide Controls!', 10, 25, 70, 80);
  71474. * }
  71475. * function mousePressed() {
  71476. * ele.hideControls();
  71477. * background(200);
  71478. * text('Controls hidden', width / 2, height / 2);
  71479. * }
  71480. * </code></div>
  71481. */
  71482. _main.default.MediaElement.prototype.hideControls = function() {
  71483. this.elt.controls = false;
  71484. };
  71485. /*** SCHEDULE EVENTS ***/
  71486. // Cue inspired by JavaScript setTimeout, and the
  71487. // Tone.js Transport Timeline Event, MIT License Yotam Mann 2015 tonejs.org
  71488. var Cue = function Cue(callback, time, id, val) {
  71489. this.callback = callback;
  71490. this.time = time;
  71491. this.id = id;
  71492. this.val = val;
  71493. };
  71494. /**
  71495. * Schedule events to trigger every time a MediaElement
  71496. * (audio/video) reaches a playback cue point.
  71497. *
  71498. * Accepts a callback function, a time (in seconds) at which to trigger
  71499. * the callback, and an optional parameter for the callback.
  71500. *
  71501. * Time will be passed as the first parameter to the callback function,
  71502. * and param will be the second parameter.
  71503. *
  71504. * @method addCue
  71505. * @param {Number} time Time in seconds, relative to this media
  71506. * element's playback. For example, to trigger
  71507. * an event every time playback reaches two
  71508. * seconds, pass in the number 2. This will be
  71509. * passed as the first parameter to
  71510. * the callback function.
  71511. * @param {Function} callback Name of a function that will be
  71512. * called at the given time. The callback will
  71513. * receive time and (optionally) param as its
  71514. * two parameters.
  71515. * @param {Object} [value] An object to be passed as the
  71516. * second parameter to the
  71517. * callback function.
  71518. * @return {Number} id ID of this cue,
  71519. * useful for removeCue(id)
  71520. * @example
  71521. * <div><code>
  71522. * //
  71523. * //
  71524. * function setup() {
  71525. * createCanvas(200, 200);
  71526. *
  71527. * let audioEl = createAudio('assets/beat.mp3');
  71528. * audioEl.showControls();
  71529. *
  71530. * // schedule three calls to changeBackground
  71531. * audioEl.addCue(0.5, changeBackground, color(255, 0, 0));
  71532. * audioEl.addCue(1.0, changeBackground, color(0, 255, 0));
  71533. * audioEl.addCue(2.5, changeBackground, color(0, 0, 255));
  71534. * audioEl.addCue(3.0, changeBackground, color(0, 255, 255));
  71535. * audioEl.addCue(4.2, changeBackground, color(255, 255, 0));
  71536. * audioEl.addCue(5.0, changeBackground, color(255, 255, 0));
  71537. * }
  71538. *
  71539. * function changeBackground(val) {
  71540. * background(val);
  71541. * }
  71542. * </code></div>
  71543. */
  71544. _main.default.MediaElement.prototype.addCue = function(time, callback, val) {
  71545. var id = this._cueIDCounter++;
  71546. var cue = new Cue(callback, time, id, val);
  71547. this._cues.push(cue);
  71548. if (!this.elt.ontimeupdate) {
  71549. this.elt.ontimeupdate = this._onTimeUpdate.bind(this);
  71550. }
  71551. return id;
  71552. };
  71553. /**
  71554. * Remove a callback based on its ID. The ID is returned by the
  71555. * addCue method.
  71556. * @method removeCue
  71557. * @param {Number} id ID of the cue, as returned by addCue
  71558. * @example
  71559. * <div><code>
  71560. * let audioEl, id1, id2;
  71561. * function setup() {
  71562. * background(255, 255, 255);
  71563. * audioEl = createAudio('assets/beat.mp3');
  71564. * audioEl.showControls();
  71565. * // schedule five calls to changeBackground
  71566. * id1 = audioEl.addCue(0.5, changeBackground, color(255, 0, 0));
  71567. * audioEl.addCue(1.0, changeBackground, color(0, 255, 0));
  71568. * audioEl.addCue(2.5, changeBackground, color(0, 0, 255));
  71569. * audioEl.addCue(3.0, changeBackground, color(0, 255, 255));
  71570. * id2 = audioEl.addCue(4.2, changeBackground, color(255, 255, 0));
  71571. * text('Click to remove first and last Cue!', 10, 25, 70, 80);
  71572. * }
  71573. * function mousePressed() {
  71574. * audioEl.removeCue(id1);
  71575. * audioEl.removeCue(id2);
  71576. * }
  71577. * function changeBackground(val) {
  71578. * background(val);
  71579. * }
  71580. * </code></div>
  71581. */
  71582. _main.default.MediaElement.prototype.removeCue = function(id) {
  71583. for (var i = 0; i < this._cues.length; i++) {
  71584. if (this._cues[i].id === id) {
  71585. console.log(id);
  71586. this._cues.splice(i, 1);
  71587. }
  71588. }
  71589. if (this._cues.length === 0) {
  71590. this.elt.ontimeupdate = null;
  71591. }
  71592. };
  71593. /**
  71594. * Remove all of the callbacks that had originally been scheduled
  71595. * via the addCue method.
  71596. * @method clearCues
  71597. * @param {Number} id ID of the cue, as returned by addCue
  71598. * @example
  71599. * <div><code>
  71600. * let audioEl;
  71601. * function setup() {
  71602. * background(255, 255, 255);
  71603. * audioEl = createAudio('assets/beat.mp3');
  71604. * //Show the default MediaElement controls, as determined by the web browser
  71605. * audioEl.showControls();
  71606. * // schedule calls to changeBackground
  71607. * background(200);
  71608. * text('Click to change Cue!', 10, 25, 70, 80);
  71609. * audioEl.addCue(0.5, changeBackground, color(255, 0, 0));
  71610. * audioEl.addCue(1.0, changeBackground, color(0, 255, 0));
  71611. * audioEl.addCue(2.5, changeBackground, color(0, 0, 255));
  71612. * audioEl.addCue(3.0, changeBackground, color(0, 255, 255));
  71613. * audioEl.addCue(4.2, changeBackground, color(255, 255, 0));
  71614. * }
  71615. * function mousePressed() {
  71616. * // here we clear the scheduled callbacks
  71617. * audioEl.clearCues();
  71618. * // then we add some more callbacks
  71619. * audioEl.addCue(1, changeBackground, color(2, 2, 2));
  71620. * audioEl.addCue(3, changeBackground, color(255, 255, 0));
  71621. * }
  71622. * function changeBackground(val) {
  71623. * background(val);
  71624. * }
  71625. * </code></div>
  71626. */
  71627. _main.default.MediaElement.prototype.clearCues = function() {
  71628. this._cues = [];
  71629. this.elt.ontimeupdate = null;
  71630. };
  71631. // private method that checks for cues to be fired if events
  71632. // have been scheduled using addCue(callback, time).
  71633. _main.default.MediaElement.prototype._onTimeUpdate = function() {
  71634. var playbackTime = this.time();
  71635. for (var i = 0; i < this._cues.length; i++) {
  71636. var callbackTime = this._cues[i].time;
  71637. var val = this._cues[i].val;
  71638. if (this._prevTime < callbackTime && callbackTime <= playbackTime) {
  71639. // pass the scheduled callbackTime as parameter to the callback
  71640. this._cues[i].callback(val);
  71641. }
  71642. }
  71643. this._prevTime = playbackTime;
  71644. };
  71645. /**
  71646. * Base class for a file.
  71647. * Used for Element.drop and createFileInput.
  71648. *
  71649. * @class p5.File
  71650. * @constructor
  71651. * @param {File} file File that is wrapped
  71652. */
  71653. _main.default.File = function(file, pInst) {
  71654. /**
  71655. * Underlying File object. All normal File methods can be called on this.
  71656. *
  71657. * @property file
  71658. */
  71659. this.file = file;
  71660. this._pInst = pInst;
  71661. // Splitting out the file type into two components
  71662. // This makes determining if image or text etc simpler
  71663. var typeList = file.type.split('/');
  71664. /**
  71665. * File type (image, text, etc.)
  71666. *
  71667. * @property type
  71668. */
  71669. this.type = typeList[0];
  71670. /**
  71671. * File subtype (usually the file extension jpg, png, xml, etc.)
  71672. *
  71673. * @property subtype
  71674. */
  71675. this.subtype = typeList[1];
  71676. /**
  71677. * File name
  71678. *
  71679. * @property name
  71680. */
  71681. this.name = file.name;
  71682. /**
  71683. * File size
  71684. *
  71685. * @property size
  71686. */
  71687. this.size = file.size;
  71688. /**
  71689. * URL string containing either image data, the text contents of the file or
  71690. * a parsed object if file is JSON and p5.XML if XML
  71691. *
  71692. * @property data
  71693. */
  71694. this.data = undefined;
  71695. };
  71696. _main.default.File._createLoader = function(theFile, callback) {
  71697. var reader = new FileReader();
  71698. reader.onload = function(e) {
  71699. var p5file = new _main.default.File(theFile);
  71700. if (p5file.file.type === 'application/json') {
  71701. // Parse JSON and store the result in data
  71702. p5file.data = JSON.parse(e.target.result);
  71703. } else if (p5file.file.type === 'text/xml') {
  71704. // Parse XML, wrap it in p5.XML and store the result in data
  71705. var parser = new DOMParser();
  71706. var xml = parser.parseFromString(e.target.result, 'text/xml');
  71707. p5file.data = new _main.default.XML(xml.documentElement);
  71708. } else {
  71709. p5file.data = e.target.result;
  71710. }
  71711. callback(p5file);
  71712. };
  71713. return reader;
  71714. };
  71715. _main.default.File._load = function(f, callback) {
  71716. // Text or data?
  71717. // This should likely be improved
  71718. if (/^text\//.test(f.type) || f.type === 'application/json') {
  71719. _main.default.File._createLoader(f, callback).readAsText(f);
  71720. } else if (!/^(video|audio)\//.test(f.type)) {
  71721. _main.default.File._createLoader(f, callback).readAsDataURL(f);
  71722. } else {
  71723. var file = new _main.default.File(f);
  71724. file.data = URL.createObjectURL(f);
  71725. callback(file);
  71726. }
  71727. };
  71728. var _default = _main.default;
  71729. exports.default = _default;
  71730. },
  71731. {
  71732. '../core/main': 283,
  71733. 'core-js/modules/es.array.every': 167,
  71734. 'core-js/modules/es.array.filter': 169,
  71735. 'core-js/modules/es.array.for-each': 170,
  71736. 'core-js/modules/es.array.from': 171,
  71737. 'core-js/modules/es.array.index-of': 173,
  71738. 'core-js/modules/es.array.iterator': 174,
  71739. 'core-js/modules/es.array.map': 177,
  71740. 'core-js/modules/es.array.slice': 178,
  71741. 'core-js/modules/es.array.splice': 180,
  71742. 'core-js/modules/es.function.name': 181,
  71743. 'core-js/modules/es.object.to-string': 192,
  71744. 'core-js/modules/es.promise': 193,
  71745. 'core-js/modules/es.regexp.exec': 196,
  71746. 'core-js/modules/es.regexp.to-string': 197,
  71747. 'core-js/modules/es.string.iterator': 201,
  71748. 'core-js/modules/es.string.replace': 204,
  71749. 'core-js/modules/es.string.split': 206,
  71750. 'core-js/modules/es.string.trim': 208,
  71751. 'core-js/modules/es.symbol': 211,
  71752. 'core-js/modules/es.symbol.description': 209,
  71753. 'core-js/modules/es.symbol.iterator': 210,
  71754. 'core-js/modules/web.dom-collections.for-each': 243,
  71755. 'core-js/modules/web.dom-collections.iterator': 244,
  71756. 'core-js/modules/web.url': 246
  71757. }
  71758. ],
  71759. 300: [
  71760. function(_dereq_, module, exports) {
  71761. 'use strict';
  71762. function _typeof(obj) {
  71763. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  71764. _typeof = function _typeof(obj) {
  71765. return typeof obj;
  71766. };
  71767. } else {
  71768. _typeof = function _typeof(obj) {
  71769. return obj &&
  71770. typeof Symbol === 'function' &&
  71771. obj.constructor === Symbol &&
  71772. obj !== Symbol.prototype
  71773. ? 'symbol'
  71774. : typeof obj;
  71775. };
  71776. }
  71777. return _typeof(obj);
  71778. }
  71779. Object.defineProperty(exports, '__esModule', { value: true });
  71780. exports.default = void 0;
  71781. var _main = _interopRequireDefault(_dereq_('../core/main'));
  71782. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  71783. function _getRequireWildcardCache() {
  71784. if (typeof WeakMap !== 'function') return null;
  71785. var cache = new WeakMap();
  71786. _getRequireWildcardCache = function _getRequireWildcardCache() {
  71787. return cache;
  71788. };
  71789. return cache;
  71790. }
  71791. function _interopRequireWildcard(obj) {
  71792. if (obj && obj.__esModule) {
  71793. return obj;
  71794. }
  71795. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  71796. return { default: obj };
  71797. }
  71798. var cache = _getRequireWildcardCache();
  71799. if (cache && cache.has(obj)) {
  71800. return cache.get(obj);
  71801. }
  71802. var newObj = {};
  71803. var hasPropertyDescriptor =
  71804. Object.defineProperty && Object.getOwnPropertyDescriptor;
  71805. for (var key in obj) {
  71806. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  71807. var desc = hasPropertyDescriptor
  71808. ? Object.getOwnPropertyDescriptor(obj, key)
  71809. : null;
  71810. if (desc && (desc.get || desc.set)) {
  71811. Object.defineProperty(newObj, key, desc);
  71812. } else {
  71813. newObj[key] = obj[key];
  71814. }
  71815. }
  71816. }
  71817. newObj.default = obj;
  71818. if (cache) {
  71819. cache.set(obj, newObj);
  71820. }
  71821. return newObj;
  71822. }
  71823. function _interopRequireDefault(obj) {
  71824. return obj && obj.__esModule ? obj : { default: obj };
  71825. }
  71826. /**
  71827. * @module Events
  71828. * @submodule Acceleration
  71829. * @for p5
  71830. * @requires core
  71831. */ /**
  71832. * The system variable deviceOrientation always contains the orientation of
  71833. * the device. The value of this variable will either be set 'landscape'
  71834. * or 'portrait'. If no data is available it will be set to 'undefined'.
  71835. * either LANDSCAPE or PORTRAIT.
  71836. *
  71837. * @property {Constant} deviceOrientation
  71838. * @readOnly
  71839. */ _main.default.prototype.deviceOrientation =
  71840. window.innerWidth / window.innerHeight > 1.0 ? 'landscape' : 'portrait';
  71841. /**
  71842. * The system variable accelerationX always contains the acceleration of the
  71843. * device along the x axis. Value is represented as meters per second squared.
  71844. *
  71845. * @property {Number} accelerationX
  71846. * @readOnly
  71847. * @example
  71848. * <div>
  71849. * <code>
  71850. * // Move a touchscreen device to register
  71851. * // acceleration changes.
  71852. * function draw() {
  71853. * background(220, 50);
  71854. * fill('magenta');
  71855. * ellipse(width / 2, height / 2, accelerationX);
  71856. * }
  71857. * </code>
  71858. * </div>
  71859. * @alt
  71860. * Magnitude of device acceleration is displayed as ellipse size
  71861. */
  71862. _main.default.prototype.accelerationX = 0;
  71863. /**
  71864. * The system variable accelerationY always contains the acceleration of the
  71865. * device along the y axis. Value is represented as meters per second squared.
  71866. *
  71867. * @property {Number} accelerationY
  71868. * @readOnly
  71869. * @example
  71870. * <div>
  71871. * <code>
  71872. * // Move a touchscreen device to register
  71873. * // acceleration changes.
  71874. * function draw() {
  71875. * background(220, 50);
  71876. * fill('magenta');
  71877. * ellipse(width / 2, height / 2, accelerationY);
  71878. * }
  71879. * </code>
  71880. * </div>
  71881. * @alt
  71882. * Magnitude of device acceleration is displayed as ellipse size
  71883. */
  71884. _main.default.prototype.accelerationY = 0;
  71885. /**
  71886. * The system variable accelerationZ always contains the acceleration of the
  71887. * device along the z axis. Value is represented as meters per second squared.
  71888. *
  71889. * @property {Number} accelerationZ
  71890. * @readOnly
  71891. *
  71892. * @example
  71893. * <div>
  71894. * <code>
  71895. * // Move a touchscreen device to register
  71896. * // acceleration changes.
  71897. * function draw() {
  71898. * background(220, 50);
  71899. * fill('magenta');
  71900. * ellipse(width / 2, height / 2, accelerationZ);
  71901. * }
  71902. * </code>
  71903. * </div>
  71904. *
  71905. * @alt
  71906. * Magnitude of device acceleration is displayed as ellipse size
  71907. */
  71908. _main.default.prototype.accelerationZ = 0;
  71909. /**
  71910. * The system variable pAccelerationX always contains the acceleration of the
  71911. * device along the x axis in the frame previous to the current frame. Value
  71912. * is represented as meters per second squared.
  71913. *
  71914. * @property {Number} pAccelerationX
  71915. * @readOnly
  71916. */
  71917. _main.default.prototype.pAccelerationX = 0;
  71918. /**
  71919. * The system variable pAccelerationY always contains the acceleration of the
  71920. * device along the y axis in the frame previous to the current frame. Value
  71921. * is represented as meters per second squared.
  71922. *
  71923. * @property {Number} pAccelerationY
  71924. * @readOnly
  71925. */
  71926. _main.default.prototype.pAccelerationY = 0;
  71927. /**
  71928. * The system variable pAccelerationZ always contains the acceleration of the
  71929. * device along the z axis in the frame previous to the current frame. Value
  71930. * is represented as meters per second squared.
  71931. *
  71932. * @property {Number} pAccelerationZ
  71933. * @readOnly
  71934. */
  71935. _main.default.prototype.pAccelerationZ = 0;
  71936. /**
  71937. * _updatePAccelerations updates the pAcceleration values
  71938. *
  71939. * @private
  71940. */
  71941. _main.default.prototype._updatePAccelerations = function() {
  71942. this._setProperty('pAccelerationX', this.accelerationX);
  71943. this._setProperty('pAccelerationY', this.accelerationY);
  71944. this._setProperty('pAccelerationZ', this.accelerationZ);
  71945. };
  71946. /**
  71947. * The system variable rotationX always contains the rotation of the
  71948. * device along the x axis. If the sketch <a href="#/p5/angleMode">
  71949. * angleMode()</a> is set to DEGREES, the value will be -180 to 180. If
  71950. * it is set to RADIANS, the value will be -PI to PI.
  71951. *
  71952. * Note: The order the rotations are called is important, ie. if used
  71953. * together, it must be called in the order Z-X-Y or there might be
  71954. * unexpected behaviour.
  71955. *
  71956. * @property {Number} rotationX
  71957. * @readOnly
  71958. * @example
  71959. * <div>
  71960. * <code>
  71961. * function setup() {
  71962. * createCanvas(100, 100, WEBGL);
  71963. * }
  71964. *
  71965. * function draw() {
  71966. * background(200);
  71967. * //rotateZ(radians(rotationZ));
  71968. * rotateX(radians(rotationX));
  71969. * //rotateY(radians(rotationY));
  71970. * box(200, 200, 200);
  71971. * }
  71972. * </code>
  71973. * </div>
  71974. * @alt
  71975. * red horizontal line right, green vertical line bottom. black background.
  71976. */
  71977. _main.default.prototype.rotationX = 0;
  71978. /**
  71979. * The system variable rotationY always contains the rotation of the
  71980. * device along the y axis. If the sketch <a href="#/p5/angleMode">
  71981. * angleMode()</a> is set to DEGREES, the value will be -90 to 90. If
  71982. * it is set to RADIANS, the value will be -PI/2 to PI/2.
  71983. *
  71984. * Note: The order the rotations are called is important, ie. if used
  71985. * together, it must be called in the order Z-X-Y or there might be
  71986. * unexpected behaviour.
  71987. *
  71988. * @property {Number} rotationY
  71989. * @readOnly
  71990. * @example
  71991. * <div>
  71992. * <code>
  71993. * function setup() {
  71994. * createCanvas(100, 100, WEBGL);
  71995. * }
  71996. *
  71997. * function draw() {
  71998. * background(200);
  71999. * //rotateZ(radians(rotationZ));
  72000. * //rotateX(radians(rotationX));
  72001. * rotateY(radians(rotationY));
  72002. * box(200, 200, 200);
  72003. * }
  72004. * </code>
  72005. * </div>
  72006. * @alt
  72007. * red horizontal line right, green vertical line bottom. black background.
  72008. */
  72009. _main.default.prototype.rotationY = 0;
  72010. /**
  72011. * The system variable rotationZ always contains the rotation of the
  72012. * device along the z axis. If the sketch <a href="#/p5/angleMode">
  72013. * angleMode()</a> is set to DEGREES, the value will be 0 to 360. If
  72014. * it is set to RADIANS, the value will be 0 to 2*PI.
  72015. *
  72016. * Unlike rotationX and rotationY, this variable is available for devices
  72017. * with a built-in compass only.
  72018. *
  72019. * Note: The order the rotations are called is important, ie. if used
  72020. * together, it must be called in the order Z-X-Y or there might be
  72021. * unexpected behaviour.
  72022. *
  72023. * @example
  72024. * <div>
  72025. * <code>
  72026. * function setup() {
  72027. * createCanvas(100, 100, WEBGL);
  72028. * }
  72029. *
  72030. * function draw() {
  72031. * background(200);
  72032. * rotateZ(radians(rotationZ));
  72033. * //rotateX(radians(rotationX));
  72034. * //rotateY(radians(rotationY));
  72035. * box(200, 200, 200);
  72036. * }
  72037. * </code>
  72038. * </div>
  72039. *
  72040. * @property {Number} rotationZ
  72041. * @readOnly
  72042. *
  72043. * @alt
  72044. * red horizontal line right, green vertical line bottom. black background.
  72045. */
  72046. _main.default.prototype.rotationZ = 0;
  72047. /**
  72048. * The system variable pRotationX always contains the rotation of the
  72049. * device along the x axis in the frame previous to the current frame.
  72050. * If the sketch <a href="#/p5/angleMode"> angleMode()</a> is set to DEGREES,
  72051. * the value will be -180 to 180. If it is set to RADIANS, the value will
  72052. * be -PI to PI.
  72053. *
  72054. * pRotationX can also be used with rotationX to determine the rotate
  72055. * direction of the device along the X-axis.
  72056. * @example
  72057. * <div class='norender'>
  72058. * <code>
  72059. * // A simple if statement looking at whether
  72060. * // rotationX - pRotationX < 0 is true or not will be
  72061. * // sufficient for determining the rotate direction
  72062. * // in most cases.
  72063. *
  72064. * // Some extra logic is needed to account for cases where
  72065. * // the angles wrap around.
  72066. * let rotateDirection = 'clockwise';
  72067. *
  72068. * // Simple range conversion to make things simpler.
  72069. * // This is not absolutely necessary but the logic
  72070. * // will be different in that case.
  72071. *
  72072. * let rX = rotationX + 180;
  72073. * let pRX = pRotationX + 180;
  72074. *
  72075. * if ((rX - pRX > 0 && rX - pRX < 270) || rX - pRX < -270) {
  72076. * rotateDirection = 'clockwise';
  72077. * } else if (rX - pRX < 0 || rX - pRX > 270) {
  72078. * rotateDirection = 'counter-clockwise';
  72079. * }
  72080. *
  72081. * print(rotateDirection);
  72082. * </code>
  72083. * </div>
  72084. *
  72085. * @alt
  72086. * no image to display.
  72087. *
  72088. * @property {Number} pRotationX
  72089. * @readOnly
  72090. */
  72091. _main.default.prototype.pRotationX = 0;
  72092. /**
  72093. * The system variable pRotationY always contains the rotation of the
  72094. * device along the y axis in the frame previous to the current frame.
  72095. * If the sketch <a href="#/p5/angleMode"> angleMode()</a> is set to DEGREES,
  72096. * the value will be -90 to 90. If it is set to RADIANS, the value will
  72097. * be -PI/2 to PI/2.
  72098. *
  72099. * pRotationY can also be used with rotationY to determine the rotate
  72100. * direction of the device along the Y-axis.
  72101. * @example
  72102. * <div class='norender'>
  72103. * <code>
  72104. * // A simple if statement looking at whether
  72105. * // rotationY - pRotationY < 0 is true or not will be
  72106. * // sufficient for determining the rotate direction
  72107. * // in most cases.
  72108. *
  72109. * // Some extra logic is needed to account for cases where
  72110. * // the angles wrap around.
  72111. * let rotateDirection = 'clockwise';
  72112. *
  72113. * // Simple range conversion to make things simpler.
  72114. * // This is not absolutely necessary but the logic
  72115. * // will be different in that case.
  72116. *
  72117. * let rY = rotationY + 180;
  72118. * let pRY = pRotationY + 180;
  72119. *
  72120. * if ((rY - pRY > 0 && rY - pRY < 270) || rY - pRY < -270) {
  72121. * rotateDirection = 'clockwise';
  72122. * } else if (rY - pRY < 0 || rY - pRY > 270) {
  72123. * rotateDirection = 'counter-clockwise';
  72124. * }
  72125. * print(rotateDirection);
  72126. * </code>
  72127. * </div>
  72128. *
  72129. * @alt
  72130. * no image to display.
  72131. *
  72132. * @property {Number} pRotationY
  72133. * @readOnly
  72134. */
  72135. _main.default.prototype.pRotationY = 0;
  72136. /**
  72137. * The system variable pRotationZ always contains the rotation of the
  72138. * device along the z axis in the frame previous to the current frame.
  72139. * If the sketch <a href="#/p5/angleMode"> angleMode()</a> is set to DEGREES,
  72140. * the value will be 0 to 360. If it is set to RADIANS, the value will
  72141. * be 0 to 2*PI.
  72142. *
  72143. * pRotationZ can also be used with rotationZ to determine the rotate
  72144. * direction of the device along the Z-axis.
  72145. * @example
  72146. * <div class='norender'>
  72147. * <code>
  72148. * // A simple if statement looking at whether
  72149. * // rotationZ - pRotationZ < 0 is true or not will be
  72150. * // sufficient for determining the rotate direction
  72151. * // in most cases.
  72152. *
  72153. * // Some extra logic is needed to account for cases where
  72154. * // the angles wrap around.
  72155. * let rotateDirection = 'clockwise';
  72156. *
  72157. * if (
  72158. * (rotationZ - pRotationZ > 0 && rotationZ - pRotationZ < 270) ||
  72159. * rotationZ - pRotationZ < -270
  72160. * ) {
  72161. * rotateDirection = 'clockwise';
  72162. * } else if (rotationZ - pRotationZ < 0 || rotationZ - pRotationZ > 270) {
  72163. * rotateDirection = 'counter-clockwise';
  72164. * }
  72165. * print(rotateDirection);
  72166. * </code>
  72167. * </div>
  72168. *
  72169. * @alt
  72170. * no image to display.
  72171. *
  72172. * @property {Number} pRotationZ
  72173. * @readOnly
  72174. */
  72175. _main.default.prototype.pRotationZ = 0;
  72176. var startAngleX = 0;
  72177. var startAngleY = 0;
  72178. var startAngleZ = 0;
  72179. var rotateDirectionX = 'clockwise';
  72180. var rotateDirectionY = 'clockwise';
  72181. var rotateDirectionZ = 'clockwise';
  72182. _main.default.prototype.pRotateDirectionX = undefined;
  72183. _main.default.prototype.pRotateDirectionY = undefined;
  72184. _main.default.prototype.pRotateDirectionZ = undefined;
  72185. _main.default.prototype._updatePRotations = function() {
  72186. this._setProperty('pRotationX', this.rotationX);
  72187. this._setProperty('pRotationY', this.rotationY);
  72188. this._setProperty('pRotationZ', this.rotationZ);
  72189. };
  72190. /**
  72191. * When a device is rotated, the axis that triggers the <a href="#/p5/deviceTurned">deviceTurned()</a>
  72192. * method is stored in the turnAxis variable. The turnAxis variable is only defined within
  72193. * the scope of deviceTurned().
  72194. * @property {String} turnAxis
  72195. * @readOnly
  72196. * @example
  72197. * <div>
  72198. * <code>
  72199. * // Run this example on a mobile device
  72200. * // Rotate the device by 90 degrees in the
  72201. * // X-axis to change the value.
  72202. *
  72203. * let value = 0;
  72204. * function draw() {
  72205. * fill(value);
  72206. * rect(25, 25, 50, 50);
  72207. * }
  72208. * function deviceTurned() {
  72209. * if (turnAxis === 'X') {
  72210. * if (value === 0) {
  72211. * value = 255;
  72212. * } else if (value === 255) {
  72213. * value = 0;
  72214. * }
  72215. * }
  72216. * }
  72217. * </code>
  72218. * </div>
  72219. *
  72220. * @alt
  72221. * 50x50 black rect in center of canvas. turns white on mobile when device turns
  72222. * 50x50 black rect in center of canvas. turns white on mobile when x-axis turns
  72223. */
  72224. _main.default.prototype.turnAxis = undefined;
  72225. var move_threshold = 0.5;
  72226. var shake_threshold = 30;
  72227. /**
  72228. * The <a href="#/p5/setMoveThreshold">setMoveThreshold()</a> function is used to set the movement threshold for
  72229. * the <a href="#/p5/deviceMoved">deviceMoved()</a> function. The default threshold is set to 0.5.
  72230. *
  72231. * @method setMoveThreshold
  72232. * @param {number} value The threshold value
  72233. * @example
  72234. * <div class="norender">
  72235. * <code>
  72236. * // Run this example on a mobile device
  72237. * // You will need to move the device incrementally further
  72238. * // the closer the square's color gets to white in order to change the value.
  72239. *
  72240. * let value = 0;
  72241. * let threshold = 0.5;
  72242. * function setup() {
  72243. * setMoveThreshold(threshold);
  72244. * }
  72245. * function draw() {
  72246. * fill(value);
  72247. * rect(25, 25, 50, 50);
  72248. * }
  72249. * function deviceMoved() {
  72250. * value = value + 5;
  72251. * threshold = threshold + 0.1;
  72252. * if (value > 255) {
  72253. * value = 0;
  72254. * threshold = 30;
  72255. * }
  72256. * setMoveThreshold(threshold);
  72257. * }
  72258. * </code>
  72259. * </div>
  72260. *
  72261. * @alt
  72262. * 50x50 black rect in center of canvas. turns white on mobile when device moves
  72263. */
  72264. _main.default.prototype.setMoveThreshold = function(val) {
  72265. _main.default._validateParameters('setMoveThreshold', arguments);
  72266. move_threshold = val;
  72267. };
  72268. /**
  72269. * The <a href="#/p5/setShakeThreshold">setShakeThreshold()</a> function is used to set the movement threshold for
  72270. * the <a href="#/p5/deviceShaken">deviceShaken()</a> function. The default threshold is set to 30.
  72271. *
  72272. * @method setShakeThreshold
  72273. * @param {number} value The threshold value
  72274. * @example
  72275. * <div class="norender">
  72276. * <code>
  72277. * // Run this example on a mobile device
  72278. * // You will need to shake the device more firmly
  72279. * // the closer the box's fill gets to white in order to change the value.
  72280. *
  72281. * let value = 0;
  72282. * let threshold = 30;
  72283. * function setup() {
  72284. * setShakeThreshold(threshold);
  72285. * }
  72286. * function draw() {
  72287. * fill(value);
  72288. * rect(25, 25, 50, 50);
  72289. * }
  72290. * function deviceMoved() {
  72291. * value = value + 5;
  72292. * threshold = threshold + 5;
  72293. * if (value > 255) {
  72294. * value = 0;
  72295. * threshold = 30;
  72296. * }
  72297. * setShakeThreshold(threshold);
  72298. * }
  72299. * </code>
  72300. * </div>
  72301. *
  72302. * @alt
  72303. * 50x50 black rect in center of canvas. turns white on mobile when device
  72304. * is being shaked
  72305. */
  72306. _main.default.prototype.setShakeThreshold = function(val) {
  72307. _main.default._validateParameters('setShakeThreshold', arguments);
  72308. shake_threshold = val;
  72309. };
  72310. /**
  72311. * The <a href="#/p5/deviceMoved">deviceMoved()</a> function is called when the device is moved by more than
  72312. * the threshold value along X, Y or Z axis. The default threshold is set to 0.5.
  72313. * The threshold value can be changed using <a href="https://p5js.org/reference/#/p5/setMoveThreshold">setMoveThreshold()</a>.
  72314. *
  72315. * @method deviceMoved
  72316. * @example
  72317. * <div class="norender">
  72318. * <code>
  72319. * // Run this example on a mobile device
  72320. * // Move the device around
  72321. * // to change the value.
  72322. *
  72323. * let value = 0;
  72324. * function draw() {
  72325. * fill(value);
  72326. * rect(25, 25, 50, 50);
  72327. * }
  72328. * function deviceMoved() {
  72329. * value = value + 5;
  72330. * if (value > 255) {
  72331. * value = 0;
  72332. * }
  72333. * }
  72334. * </code>
  72335. * </div>
  72336. *
  72337. * @alt
  72338. * 50x50 black rect in center of canvas. turns white on mobile when device moves
  72339. */
  72340. /**
  72341. * The <a href="#/p5/deviceTurned">deviceTurned()</a> function is called when the device rotates by
  72342. * more than 90 degrees continuously.
  72343. *
  72344. * The axis that triggers the <a href="#/p5/deviceTurned">deviceTurned()</a> method is stored in the turnAxis
  72345. * variable. The <a href="#/p5/deviceTurned">deviceTurned()</a> method can be locked to trigger on any axis:
  72346. * X, Y or Z by comparing the turnAxis variable to 'X', 'Y' or 'Z'.
  72347. *
  72348. * @method deviceTurned
  72349. * @example
  72350. * <div class="norender">
  72351. * <code>
  72352. * // Run this example on a mobile device
  72353. * // Rotate the device by 90 degrees
  72354. * // to change the value.
  72355. *
  72356. * let value = 0;
  72357. * function draw() {
  72358. * fill(value);
  72359. * rect(25, 25, 50, 50);
  72360. * }
  72361. * function deviceTurned() {
  72362. * if (value === 0) {
  72363. * value = 255;
  72364. * } else if (value === 255) {
  72365. * value = 0;
  72366. * }
  72367. * }
  72368. * </code>
  72369. * </div>
  72370. * <div>
  72371. * <code>
  72372. * // Run this example on a mobile device
  72373. * // Rotate the device by 90 degrees in the
  72374. * // X-axis to change the value.
  72375. *
  72376. * let value = 0;
  72377. * function draw() {
  72378. * fill(value);
  72379. * rect(25, 25, 50, 50);
  72380. * }
  72381. * function deviceTurned() {
  72382. * if (turnAxis === 'X') {
  72383. * if (value === 0) {
  72384. * value = 255;
  72385. * } else if (value === 255) {
  72386. * value = 0;
  72387. * }
  72388. * }
  72389. * }
  72390. * </code>
  72391. * </div>
  72392. *
  72393. * @alt
  72394. * 50x50 black rect in center of canvas. turns white on mobile when device turns
  72395. * 50x50 black rect in center of canvas. turns white on mobile when x-axis turns
  72396. */
  72397. /**
  72398. * The <a href="#/p5/deviceShaken">deviceShaken()</a> function is called when the device total acceleration
  72399. * changes of accelerationX and accelerationY values is more than
  72400. * the threshold value. The default threshold is set to 30.
  72401. * The threshold value can be changed using <a href="https://p5js.org/reference/#/p5/setShakeThreshold">setShakeThreshold()</a>.
  72402. *
  72403. * @method deviceShaken
  72404. * @example
  72405. * <div class="norender">
  72406. * <code>
  72407. * // Run this example on a mobile device
  72408. * // Shake the device to change the value.
  72409. *
  72410. * let value = 0;
  72411. * function draw() {
  72412. * fill(value);
  72413. * rect(25, 25, 50, 50);
  72414. * }
  72415. * function deviceShaken() {
  72416. * value = value + 5;
  72417. * if (value > 255) {
  72418. * value = 0;
  72419. * }
  72420. * }
  72421. * </code>
  72422. * </div>
  72423. *
  72424. * @alt
  72425. * 50x50 black rect in center of canvas. turns white on mobile when device shakes
  72426. */
  72427. _main.default.prototype._ondeviceorientation = function(e) {
  72428. this._updatePRotations();
  72429. if (this._angleMode === constants.radians) {
  72430. e.beta = e.beta * (_PI / 180.0);
  72431. e.gamma = e.gamma * (_PI / 180.0);
  72432. e.alpha = e.alpha * (_PI / 180.0);
  72433. }
  72434. this._setProperty('rotationX', e.beta);
  72435. this._setProperty('rotationY', e.gamma);
  72436. this._setProperty('rotationZ', e.alpha);
  72437. this._handleMotion();
  72438. };
  72439. _main.default.prototype._ondevicemotion = function(e) {
  72440. this._updatePAccelerations();
  72441. this._setProperty('accelerationX', e.acceleration.x * 2);
  72442. this._setProperty('accelerationY', e.acceleration.y * 2);
  72443. this._setProperty('accelerationZ', e.acceleration.z * 2);
  72444. this._handleMotion();
  72445. };
  72446. _main.default.prototype._handleMotion = function() {
  72447. if (window.orientation === 90 || window.orientation === -90) {
  72448. this._setProperty('deviceOrientation', 'landscape');
  72449. } else if (window.orientation === 0) {
  72450. this._setProperty('deviceOrientation', 'portrait');
  72451. } else if (window.orientation === undefined) {
  72452. this._setProperty('deviceOrientation', 'undefined');
  72453. }
  72454. var context = this._isGlobal ? window : this;
  72455. if (typeof context.deviceMoved === 'function') {
  72456. if (
  72457. Math.abs(this.accelerationX - this.pAccelerationX) > move_threshold ||
  72458. Math.abs(this.accelerationY - this.pAccelerationY) > move_threshold ||
  72459. Math.abs(this.accelerationZ - this.pAccelerationZ) > move_threshold
  72460. ) {
  72461. context.deviceMoved();
  72462. }
  72463. }
  72464. if (typeof context.deviceTurned === 'function') {
  72465. // The angles given by rotationX etc is from range -180 to 180.
  72466. // The following will convert them to 0 to 360 for ease of calculation
  72467. // of cases when the angles wrapped around.
  72468. // _startAngleX will be converted back at the end and updated.
  72469. var wRX = this.rotationX + 180;
  72470. var wPRX = this.pRotationX + 180;
  72471. var wSAX = startAngleX + 180;
  72472. if ((wRX - wPRX > 0 && wRX - wPRX < 270) || wRX - wPRX < -270) {
  72473. rotateDirectionX = 'clockwise';
  72474. } else if (wRX - wPRX < 0 || wRX - wPRX > 270) {
  72475. rotateDirectionX = 'counter-clockwise';
  72476. }
  72477. if (rotateDirectionX !== this.pRotateDirectionX) {
  72478. wSAX = wRX;
  72479. }
  72480. if (Math.abs(wRX - wSAX) > 90 && Math.abs(wRX - wSAX) < 270) {
  72481. wSAX = wRX;
  72482. this._setProperty('turnAxis', 'X');
  72483. context.deviceTurned();
  72484. }
  72485. this.pRotateDirectionX = rotateDirectionX;
  72486. startAngleX = wSAX - 180;
  72487. // Y-axis is identical to X-axis except for changing some names.
  72488. var wRY = this.rotationY + 180;
  72489. var wPRY = this.pRotationY + 180;
  72490. var wSAY = startAngleY + 180;
  72491. if ((wRY - wPRY > 0 && wRY - wPRY < 270) || wRY - wPRY < -270) {
  72492. rotateDirectionY = 'clockwise';
  72493. } else if (wRY - wPRY < 0 || wRY - this.pRotationY > 270) {
  72494. rotateDirectionY = 'counter-clockwise';
  72495. }
  72496. if (rotateDirectionY !== this.pRotateDirectionY) {
  72497. wSAY = wRY;
  72498. }
  72499. if (Math.abs(wRY - wSAY) > 90 && Math.abs(wRY - wSAY) < 270) {
  72500. wSAY = wRY;
  72501. this._setProperty('turnAxis', 'Y');
  72502. context.deviceTurned();
  72503. }
  72504. this.pRotateDirectionY = rotateDirectionY;
  72505. startAngleY = wSAY - 180;
  72506. // Z-axis is already in the range 0 to 360
  72507. // so no conversion is needed.
  72508. if (
  72509. (this.rotationZ - this.pRotationZ > 0 &&
  72510. this.rotationZ - this.pRotationZ < 270) ||
  72511. this.rotationZ - this.pRotationZ < -270
  72512. ) {
  72513. rotateDirectionZ = 'clockwise';
  72514. } else if (
  72515. this.rotationZ - this.pRotationZ < 0 ||
  72516. this.rotationZ - this.pRotationZ > 270
  72517. ) {
  72518. rotateDirectionZ = 'counter-clockwise';
  72519. }
  72520. if (rotateDirectionZ !== this.pRotateDirectionZ) {
  72521. startAngleZ = this.rotationZ;
  72522. }
  72523. if (
  72524. Math.abs(this.rotationZ - startAngleZ) > 90 &&
  72525. Math.abs(this.rotationZ - startAngleZ) < 270
  72526. ) {
  72527. startAngleZ = this.rotationZ;
  72528. this._setProperty('turnAxis', 'Z');
  72529. context.deviceTurned();
  72530. }
  72531. this.pRotateDirectionZ = rotateDirectionZ;
  72532. this._setProperty('turnAxis', undefined);
  72533. }
  72534. if (typeof context.deviceShaken === 'function') {
  72535. var accelerationChangeX;
  72536. var accelerationChangeY;
  72537. // Add accelerationChangeZ if acceleration change on Z is needed
  72538. if (this.pAccelerationX !== null) {
  72539. accelerationChangeX = Math.abs(this.accelerationX - this.pAccelerationX);
  72540. accelerationChangeY = Math.abs(this.accelerationY - this.pAccelerationY);
  72541. }
  72542. if (accelerationChangeX + accelerationChangeY > shake_threshold) {
  72543. context.deviceShaken();
  72544. }
  72545. }
  72546. };
  72547. var _default = _main.default;
  72548. exports.default = _default;
  72549. },
  72550. { '../core/constants': 272, '../core/main': 283 }
  72551. ],
  72552. 301: [
  72553. function(_dereq_, module, exports) {
  72554. 'use strict';
  72555. Object.defineProperty(exports, '__esModule', { value: true });
  72556. exports.default = void 0;
  72557. var _main = _interopRequireDefault(_dereq_('../core/main'));
  72558. function _interopRequireDefault(obj) {
  72559. return obj && obj.__esModule ? obj : { default: obj };
  72560. }
  72561. /**
  72562. * @module Events
  72563. * @submodule Keyboard
  72564. * @for p5
  72565. * @requires core
  72566. */ /**
  72567. * The boolean system variable <a href="#/p5/keyIsPressed">keyIsPressed</a> is true if any key is pressed
  72568. * and false if no keys are pressed.
  72569. *
  72570. * @property {Boolean} keyIsPressed
  72571. * @readOnly
  72572. * @example
  72573. * <div>
  72574. * <code>
  72575. * function draw() {
  72576. * if (keyIsPressed === true) {
  72577. * fill(0);
  72578. * } else {
  72579. * fill(255);
  72580. * }
  72581. * rect(25, 25, 50, 50);
  72582. * }
  72583. * </code>
  72584. * </div>
  72585. *
  72586. * @alt
  72587. * 50x50 white rect that turns black on keypress.
  72588. */ _main.default.prototype.isKeyPressed = false;
  72589. _main.default.prototype.keyIsPressed = false; // khan
  72590. /**
  72591. * The system variable key always contains the value of the most recent
  72592. * key on the keyboard that was typed. To get the proper capitalization, it
  72593. * is best to use it within <a href="#/p5/keyTyped">keyTyped()</a>. For non-ASCII keys, use the <a href="#/p5/keyCode">keyCode</a>
  72594. * variable.
  72595. *
  72596. * @property {String} key
  72597. * @readOnly
  72598. * @example
  72599. * <div><code>
  72600. * // Click any key to display it!
  72601. * // (Not Guaranteed to be Case Sensitive)
  72602. * function setup() {
  72603. * fill(245, 123, 158);
  72604. * textSize(50);
  72605. * }
  72606. *
  72607. * function draw() {
  72608. * background(200);
  72609. * text(key, 33, 65); // Display last key pressed.
  72610. * }
  72611. * </code></div>
  72612. *
  72613. * @alt
  72614. * canvas displays any key value that is pressed in pink font.
  72615. */
  72616. _main.default.prototype.key = '';
  72617. /**
  72618. * The variable keyCode is used to detect special keys such as BACKSPACE,
  72619. * DELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL, OPTION, ALT, UP_ARROW,
  72620. * DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW.
  72621. * You can also check for custom keys by looking up the keyCode of any key
  72622. * on a site like this: <a href="http://keycode.info/">keycode.info</a>.
  72623. *
  72624. * @property {Integer} keyCode
  72625. * @readOnly
  72626. * @example
  72627. * <div><code>
  72628. * let fillVal = 126;
  72629. * function draw() {
  72630. * fill(fillVal);
  72631. * rect(25, 25, 50, 50);
  72632. * }
  72633. *
  72634. * function keyPressed() {
  72635. * if (keyCode === UP_ARROW) {
  72636. * fillVal = 255;
  72637. * } else if (keyCode === DOWN_ARROW) {
  72638. * fillVal = 0;
  72639. * }
  72640. * }
  72641. * </code></div>
  72642. * <div><code>
  72643. * function draw() {}
  72644. * function keyPressed() {
  72645. * background('yellow');
  72646. * text(`${key} ${keyCode}`, 10, 40);
  72647. * print(key, ' ', keyCode);
  72648. * }
  72649. * </code></div>
  72650. * @alt
  72651. * Grey rect center. turns white when up arrow pressed and black when down
  72652. * Display key pressed and its keyCode in a yellow box
  72653. */
  72654. _main.default.prototype.keyCode = 0;
  72655. /**
  72656. * The <a href="#/p5/keyPressed">keyPressed()</a> function is called once every time a key is pressed. The
  72657. * keyCode for the key that was pressed is stored in the <a href="#/p5/keyCode">keyCode</a> variable.
  72658. *
  72659. * For non-ASCII keys, use the keyCode variable. You can check if the keyCode
  72660. * equals BACKSPACE, DELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL,
  72661. * OPTION, ALT, UP_ARROW, DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW.
  72662. *
  72663. * For ASCII keys, the key that was pressed is stored in the key variable. However, it
  72664. * does not distinguish between uppercase and lowercase. For this reason, it
  72665. * is recommended to use <a href="#/p5/keyTyped">keyTyped()</a> to read the key variable, in which the
  72666. * case of the variable will be distinguished.
  72667. *
  72668. * Because of how operating systems handle key repeats, holding down a key
  72669. * may cause multiple calls to <a href="#/p5/keyTyped">keyTyped()</a> (and <a href="#/p5/keyReleased">keyReleased()</a> as well). The
  72670. * rate of repeat is set by the operating system and how each computer is
  72671. * configured.<br><br>
  72672. * Browsers may have different default
  72673. * behaviors attached to various key events. To prevent any default
  72674. * behavior for this event, add "return false" to the end of the method.
  72675. *
  72676. * @method keyPressed
  72677. * @param {Object} [event] optional KeyboardEvent callback argument.
  72678. * @example
  72679. * <div>
  72680. * <code>
  72681. * let value = 0;
  72682. * function draw() {
  72683. * fill(value);
  72684. * rect(25, 25, 50, 50);
  72685. * }
  72686. * function keyPressed() {
  72687. * if (value === 0) {
  72688. * value = 255;
  72689. * } else {
  72690. * value = 0;
  72691. * }
  72692. * }
  72693. * </code>
  72694. * </div>
  72695. * <div>
  72696. * <code>
  72697. * let value = 0;
  72698. * function draw() {
  72699. * fill(value);
  72700. * rect(25, 25, 50, 50);
  72701. * }
  72702. * function keyPressed() {
  72703. * if (keyCode === LEFT_ARROW) {
  72704. * value = 255;
  72705. * } else if (keyCode === RIGHT_ARROW) {
  72706. * value = 0;
  72707. * }
  72708. * }
  72709. * </code>
  72710. * </div>
  72711. * <div class="norender">
  72712. * <code>
  72713. * function keyPressed() {
  72714. * // Do something
  72715. * return false; // prevent any default behaviour
  72716. * }
  72717. * </code>
  72718. * </div>
  72719. *
  72720. * @alt
  72721. * black rect center. turns white when key pressed and black when released
  72722. * black rect center. turns white when left arrow pressed and black when right.
  72723. */
  72724. _main.default.prototype._onkeydown = function(e) {
  72725. if (this._downKeys[e.which]) {
  72726. // prevent multiple firings
  72727. return;
  72728. }
  72729. this._setProperty('isKeyPressed', true);
  72730. this._setProperty('keyIsPressed', true);
  72731. this._setProperty('keyCode', e.which);
  72732. this._downKeys[e.which] = true;
  72733. this._setProperty('key', e.key || String.fromCharCode(e.which) || e.which);
  72734. var context = this._isGlobal ? window : this;
  72735. if (typeof context.keyPressed === 'function' && !e.charCode) {
  72736. var executeDefault = context.keyPressed(e);
  72737. if (executeDefault === false) {
  72738. e.preventDefault();
  72739. }
  72740. }
  72741. };
  72742. /**
  72743. * The <a href="#/p5/keyReleased">keyReleased()</a> function is called once every time a key is released.
  72744. * See <a href="#/p5/key">key</a> and <a href="#/p5/keyCode">keyCode</a> for more information.<br><br>
  72745. * Browsers may have different default
  72746. * behaviors attached to various key events. To prevent any default
  72747. * behavior for this event, add "return false" to the end of the method.
  72748. *
  72749. * @method keyReleased
  72750. * @param {Object} [event] optional KeyboardEvent callback argument.
  72751. * @example
  72752. * <div>
  72753. * <code>
  72754. * let value = 0;
  72755. * function draw() {
  72756. * fill(value);
  72757. * rect(25, 25, 50, 50);
  72758. * }
  72759. * function keyReleased() {
  72760. * if (value === 0) {
  72761. * value = 255;
  72762. * } else {
  72763. * value = 0;
  72764. * }
  72765. * return false; // prevent any default behavior
  72766. * }
  72767. * </code>
  72768. * </div>
  72769. *
  72770. * @alt
  72771. * black rect center. turns white when key pressed and black when pressed again
  72772. */
  72773. _main.default.prototype._onkeyup = function(e) {
  72774. this._downKeys[e.which] = false;
  72775. if (!this._areDownKeys()) {
  72776. this._setProperty('isKeyPressed', false);
  72777. this._setProperty('keyIsPressed', false);
  72778. }
  72779. this._setProperty('_lastKeyCodeTyped', null);
  72780. this._setProperty('key', e.key || String.fromCharCode(e.which) || e.which);
  72781. this._setProperty('keyCode', e.which);
  72782. var context = this._isGlobal ? window : this;
  72783. if (typeof context.keyReleased === 'function') {
  72784. var executeDefault = context.keyReleased(e);
  72785. if (executeDefault === false) {
  72786. e.preventDefault();
  72787. }
  72788. }
  72789. };
  72790. /**
  72791. * The <a href="#/p5/keyTyped">keyTyped()</a> function is called once every time a key is pressed, but
  72792. * action keys such as Backspace, Delete, Ctrl, Shift, and Alt are ignored. If you are trying to detect
  72793. * a keyCode for one of these keys, use the <a href="#/p5/keyPressed">keyPressed()</a> function instead.
  72794. * The most recent key typed will be stored in the key variable.
  72795. *
  72796. * Because of how operating systems handle key repeats, holding down a key
  72797. * will cause multiple calls to <a href="#/p5/keyTyped">keyTyped()</a> (and <a href="#/p5/keyReleased">keyReleased()</a> as well). The
  72798. * rate of repeat is set by the operating system and how each computer is
  72799. * configured.<br><br>
  72800. * Browsers may have different default behaviors attached to various key
  72801. * events. To prevent any default behavior for this event, add "return false"
  72802. * to the end of the method.
  72803. *
  72804. * @method keyTyped
  72805. * @param {Object} [event] optional KeyboardEvent callback argument.
  72806. * @example
  72807. * <div>
  72808. * <code>
  72809. * let value = 0;
  72810. * function draw() {
  72811. * fill(value);
  72812. * rect(25, 25, 50, 50);
  72813. * }
  72814. * function keyTyped() {
  72815. * if (key === 'a') {
  72816. * value = 255;
  72817. * } else if (key === 'b') {
  72818. * value = 0;
  72819. * }
  72820. * // uncomment to prevent any default behavior
  72821. * // return false;
  72822. * }
  72823. * </code>
  72824. * </div>
  72825. *
  72826. * @alt
  72827. * black rect center. turns white when 'a' key typed and black when 'b' pressed
  72828. */
  72829. _main.default.prototype._onkeypress = function(e) {
  72830. if (e.which === this._lastKeyCodeTyped) {
  72831. // prevent multiple firings
  72832. return;
  72833. }
  72834. this._setProperty('_lastKeyCodeTyped', e.which); // track last keyCode
  72835. this._setProperty('key', e.key || String.fromCharCode(e.which) || e.which);
  72836. var context = this._isGlobal ? window : this;
  72837. if (typeof context.keyTyped === 'function') {
  72838. var executeDefault = context.keyTyped(e);
  72839. if (executeDefault === false) {
  72840. e.preventDefault();
  72841. }
  72842. }
  72843. };
  72844. /**
  72845. * The onblur function is called when the user is no longer focused
  72846. * on the p5 element. Because the keyup events will not fire if the user is
  72847. * not focused on the element we must assume all keys currently down have
  72848. * been released.
  72849. */
  72850. _main.default.prototype._onblur = function(e) {
  72851. this._downKeys = {};
  72852. };
  72853. /**
  72854. * The <a href="#/p5/keyIsDown">keyIsDown()</a> function checks if the key is currently down, i.e. pressed.
  72855. * It can be used if you have an object that moves, and you want several keys
  72856. * to be able to affect its behaviour simultaneously, such as moving a
  72857. * sprite diagonally. You can put in any number representing the keyCode of
  72858. * the key, or use any of the variable <a href="#/p5/keyCode">keyCode</a> names listed
  72859. * <a href="http://p5js.org/reference/#p5/keyCode">here</a>.
  72860. *
  72861. * @method keyIsDown
  72862. * @param {Number} code The key to check for.
  72863. * @return {Boolean} whether key is down or not
  72864. * @example
  72865. * <div><code>
  72866. * let x = 100;
  72867. * let y = 100;
  72868. *
  72869. * function setup() {
  72870. * createCanvas(512, 512);
  72871. * fill(255, 0, 0);
  72872. * }
  72873. *
  72874. * function draw() {
  72875. * if (keyIsDown(LEFT_ARROW)) {
  72876. * x -= 5;
  72877. * }
  72878. *
  72879. * if (keyIsDown(RIGHT_ARROW)) {
  72880. * x += 5;
  72881. * }
  72882. *
  72883. * if (keyIsDown(UP_ARROW)) {
  72884. * y -= 5;
  72885. * }
  72886. *
  72887. * if (keyIsDown(DOWN_ARROW)) {
  72888. * y += 5;
  72889. * }
  72890. *
  72891. * clear();
  72892. * ellipse(x, y, 50, 50);
  72893. * }
  72894. * </code></div>
  72895. *
  72896. * <div><code>
  72897. * let diameter = 50;
  72898. *
  72899. * function setup() {
  72900. * createCanvas(512, 512);
  72901. * }
  72902. *
  72903. * function draw() {
  72904. * // 107 and 187 are keyCodes for "+"
  72905. * if (keyIsDown(107) || keyIsDown(187)) {
  72906. * diameter += 1;
  72907. * }
  72908. *
  72909. * // 109 and 189 are keyCodes for "-"
  72910. * if (keyIsDown(109) || keyIsDown(189)) {
  72911. * diameter -= 1;
  72912. * }
  72913. *
  72914. * clear();
  72915. * fill(255, 0, 0);
  72916. * ellipse(50, 50, diameter, diameter);
  72917. * }
  72918. * </code></div>
  72919. *
  72920. * @alt
  72921. * 50x50 red ellipse moves left, right, up and down with arrow presses.
  72922. * 50x50 red ellipse gets bigger or smaller when + or - are pressed.
  72923. */
  72924. _main.default.prototype.keyIsDown = function(code) {
  72925. _main.default._validateParameters('keyIsDown', arguments);
  72926. return this._downKeys[code] || false;
  72927. };
  72928. /**
  72929. * The _areDownKeys function returns a boolean true if any keys pressed
  72930. * and a false if no keys are currently pressed.
  72931. * Helps avoid instances where multiple keys are pressed simultaneously and
  72932. * releasing a single key will then switch the
  72933. * keyIsPressed property to true.
  72934. * @private
  72935. **/
  72936. _main.default.prototype._areDownKeys = function() {
  72937. for (var key in this._downKeys) {
  72938. if (this._downKeys.hasOwnProperty(key) && this._downKeys[key] === true) {
  72939. return true;
  72940. }
  72941. }
  72942. return false;
  72943. };
  72944. var _default = _main.default;
  72945. exports.default = _default;
  72946. },
  72947. { '../core/main': 283 }
  72948. ],
  72949. 302: [
  72950. function(_dereq_, module, exports) {
  72951. 'use strict';
  72952. function _typeof(obj) {
  72953. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  72954. _typeof = function _typeof(obj) {
  72955. return typeof obj;
  72956. };
  72957. } else {
  72958. _typeof = function _typeof(obj) {
  72959. return obj &&
  72960. typeof Symbol === 'function' &&
  72961. obj.constructor === Symbol &&
  72962. obj !== Symbol.prototype
  72963. ? 'symbol'
  72964. : typeof obj;
  72965. };
  72966. }
  72967. return _typeof(obj);
  72968. }
  72969. _dereq_('core-js/modules/es.array.includes');
  72970. _dereq_('core-js/modules/es.string.includes');
  72971. Object.defineProperty(exports, '__esModule', { value: true });
  72972. exports.default = void 0;
  72973. var _main = _interopRequireDefault(_dereq_('../core/main'));
  72974. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  72975. function _getRequireWildcardCache() {
  72976. if (typeof WeakMap !== 'function') return null;
  72977. var cache = new WeakMap();
  72978. _getRequireWildcardCache = function _getRequireWildcardCache() {
  72979. return cache;
  72980. };
  72981. return cache;
  72982. }
  72983. function _interopRequireWildcard(obj) {
  72984. if (obj && obj.__esModule) {
  72985. return obj;
  72986. }
  72987. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  72988. return { default: obj };
  72989. }
  72990. var cache = _getRequireWildcardCache();
  72991. if (cache && cache.has(obj)) {
  72992. return cache.get(obj);
  72993. }
  72994. var newObj = {};
  72995. var hasPropertyDescriptor =
  72996. Object.defineProperty && Object.getOwnPropertyDescriptor;
  72997. for (var key in obj) {
  72998. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  72999. var desc = hasPropertyDescriptor
  73000. ? Object.getOwnPropertyDescriptor(obj, key)
  73001. : null;
  73002. if (desc && (desc.get || desc.set)) {
  73003. Object.defineProperty(newObj, key, desc);
  73004. } else {
  73005. newObj[key] = obj[key];
  73006. }
  73007. }
  73008. }
  73009. newObj.default = obj;
  73010. if (cache) {
  73011. cache.set(obj, newObj);
  73012. }
  73013. return newObj;
  73014. }
  73015. function _interopRequireDefault(obj) {
  73016. return obj && obj.__esModule ? obj : { default: obj };
  73017. }
  73018. /**
  73019. * @module Events
  73020. * @submodule Mouse
  73021. * @for p5
  73022. * @requires core
  73023. * @requires constants
  73024. */ /**
  73025. *
  73026. * The variable movedX contains the horizontal movement of the mouse since the last frame
  73027. * @property {Number} movedX
  73028. * @readOnly
  73029. * @example
  73030. * <div class="notest">
  73031. * <code>
  73032. * let x = 50;
  73033. * function setup() {
  73034. * rectMode(CENTER);
  73035. * }
  73036. *
  73037. * function draw() {
  73038. * if (x > 48) {
  73039. * x -= 2;
  73040. * } else if (x < 48) {
  73041. * x += 2;
  73042. * }
  73043. * x += floor(movedX / 5);
  73044. * background(237, 34, 93);
  73045. * fill(0);
  73046. * rect(x, 50, 50, 50);
  73047. * }
  73048. * </code>
  73049. * </div>
  73050. * @alt
  73051. * box moves left and right according to mouse movement then slowly back towards the center
  73052. */ _main.default.prototype.movedX = 0;
  73053. /**
  73054. * The variable movedY contains the vertical movement of the mouse since the last frame
  73055. * @property {Number} movedY
  73056. * @readOnly
  73057. * @example
  73058. * <div class="notest">
  73059. * <code>
  73060. * let y = 50;
  73061. * function setup() {
  73062. * rectMode(CENTER);
  73063. * }
  73064. *
  73065. * function draw() {
  73066. * if (y > 48) {
  73067. * y -= 2;
  73068. * } else if (y < 48) {
  73069. * y += 2;
  73070. * }
  73071. * y += floor(movedY / 5);
  73072. * background(237, 34, 93);
  73073. * fill(0);
  73074. * rect(y, 50, 50, 50);
  73075. * }
  73076. * </code>
  73077. * </div>
  73078. * @alt
  73079. * box moves up and down according to mouse movement then slowly back towards the center
  73080. */ _main.default.prototype.movedY = 0;
  73081. /*
  73082. * This is a flag which is false until the first time
  73083. * we receive a mouse event. The pmouseX and pmouseY
  73084. * values will match the mouseX and mouseY values until
  73085. * this interaction takes place.
  73086. */
  73087. _main.default.prototype._hasMouseInteracted = false;
  73088. /**
  73089. * The system variable mouseX always contains the current horizontal
  73090. * position of the mouse, relative to (0, 0) of the canvas. The value at
  73091. * the top-left corner is (0, 0) for 2-D and (-width/2, -height/2) for WebGL.
  73092. * If touch is used instead of mouse input, mouseX will hold the x value
  73093. * of the most recent touch point.
  73094. *
  73095. * @property {Number} mouseX
  73096. * @readOnly
  73097. *
  73098. * @example
  73099. * <div>
  73100. * <code>
  73101. * // Move the mouse across the canvas
  73102. * function draw() {
  73103. * background(244, 248, 252);
  73104. * line(mouseX, 0, mouseX, 100);
  73105. * }
  73106. * </code>
  73107. * </div>
  73108. *
  73109. * @alt
  73110. * horizontal black line moves left and right with mouse x-position
  73111. */
  73112. _main.default.prototype.mouseX = 0;
  73113. /**
  73114. * The system variable mouseY always contains the current vertical
  73115. * position of the mouse, relative to (0, 0) of the canvas. The value at
  73116. * the top-left corner is (0, 0) for 2-D and (-width/2, -height/2) for WebGL.
  73117. * If touch is used instead of mouse input, mouseY will hold the y value
  73118. * of the most recent touch point.
  73119. *
  73120. * @property {Number} mouseY
  73121. * @readOnly
  73122. *
  73123. * @example
  73124. * <div>
  73125. * <code>
  73126. * // Move the mouse across the canvas
  73127. * function draw() {
  73128. * background(244, 248, 252);
  73129. * line(0, mouseY, 100, mouseY);
  73130. * }
  73131. * </code>
  73132. * </div>
  73133. *
  73134. * @alt
  73135. * vertical black line moves up and down with mouse y-position
  73136. */
  73137. _main.default.prototype.mouseY = 0;
  73138. /**
  73139. * The system variable pmouseX always contains the horizontal position of
  73140. * the mouse or finger in the frame previous to the current frame, relative to
  73141. * (0, 0) of the canvas. The value at the top-left corner is (0, 0) for 2-D and
  73142. * (-width/2, -height/2) for WebGL. Note: pmouseX will be reset to the current mouseX
  73143. * value at the start of each touch event.
  73144. *
  73145. * @property {Number} pmouseX
  73146. * @readOnly
  73147. *
  73148. * @example
  73149. * <div>
  73150. * <code>
  73151. * // Move the mouse across the canvas to leave a trail
  73152. * function setup() {
  73153. * //slow down the frameRate to make it more visible
  73154. * frameRate(10);
  73155. * }
  73156. *
  73157. * function draw() {
  73158. * background(244, 248, 252);
  73159. * line(mouseX, mouseY, pmouseX, pmouseY);
  73160. * print(pmouseX + ' -> ' + mouseX);
  73161. * }
  73162. * </code>
  73163. * </div>
  73164. *
  73165. * @alt
  73166. * line trail is created from cursor movements. faster movement make longer line.
  73167. */
  73168. _main.default.prototype.pmouseX = 0;
  73169. /**
  73170. * The system variable pmouseY always contains the vertical position of
  73171. * the mouse or finger in the frame previous to the current frame, relative to
  73172. * (0, 0) of the canvas. The value at the top-left corner is (0, 0) for 2-D and
  73173. * (-width/2, -height/2) for WebGL. Note: pmouseY will be reset to the current mouseY
  73174. * value at the start of each touch event.
  73175. *
  73176. * @property {Number} pmouseY
  73177. * @readOnly
  73178. *
  73179. * @example
  73180. * <div>
  73181. * <code>
  73182. * function draw() {
  73183. * background(237, 34, 93);
  73184. * fill(0);
  73185. * //draw a square only if the mouse is not moving
  73186. * if (mouseY === pmouseY && mouseX === pmouseX) {
  73187. * rect(20, 20, 60, 60);
  73188. * }
  73189. *
  73190. * print(pmouseY + ' -> ' + mouseY);
  73191. * }
  73192. * </code>
  73193. * </div>
  73194. *
  73195. * @alt
  73196. * 60x60 black rect center, fuchsia background. rect flickers on mouse movement
  73197. */
  73198. _main.default.prototype.pmouseY = 0;
  73199. /**
  73200. * The system variable winMouseX always contains the current horizontal
  73201. * position of the mouse, relative to (0, 0) of the window.
  73202. *
  73203. * @property {Number} winMouseX
  73204. * @readOnly
  73205. *
  73206. * @example
  73207. * <div>
  73208. * <code>
  73209. * let myCanvas;
  73210. *
  73211. * function setup() {
  73212. * //use a variable to store a pointer to the canvas
  73213. * myCanvas = createCanvas(100, 100);
  73214. * let body = document.getElementsByTagName('body')[0];
  73215. * myCanvas.parent(body);
  73216. * }
  73217. *
  73218. * function draw() {
  73219. * background(237, 34, 93);
  73220. * fill(0);
  73221. *
  73222. * //move the canvas to the horizontal mouse position
  73223. * //relative to the window
  73224. * myCanvas.position(winMouseX + 1, windowHeight / 2);
  73225. *
  73226. * //the y of the square is relative to the canvas
  73227. * rect(20, mouseY, 60, 60);
  73228. * }
  73229. * </code>
  73230. * </div>
  73231. *
  73232. * @alt
  73233. * 60x60 black rect y moves with mouse y and fuchsia canvas moves with mouse x
  73234. */
  73235. _main.default.prototype.winMouseX = 0;
  73236. /**
  73237. * The system variable winMouseY always contains the current vertical
  73238. * position of the mouse, relative to (0, 0) of the window.
  73239. *
  73240. * @property {Number} winMouseY
  73241. * @readOnly
  73242. *
  73243. * @example
  73244. * <div>
  73245. * <code>
  73246. * let myCanvas;
  73247. *
  73248. * function setup() {
  73249. * //use a variable to store a pointer to the canvas
  73250. * myCanvas = createCanvas(100, 100);
  73251. * let body = document.getElementsByTagName('body')[0];
  73252. * myCanvas.parent(body);
  73253. * }
  73254. *
  73255. * function draw() {
  73256. * background(237, 34, 93);
  73257. * fill(0);
  73258. *
  73259. * //move the canvas to the vertical mouse position
  73260. * //relative to the window
  73261. * myCanvas.position(windowWidth / 2, winMouseY + 1);
  73262. *
  73263. * //the x of the square is relative to the canvas
  73264. * rect(mouseX, 20, 60, 60);
  73265. * }
  73266. * </code>
  73267. * </div>
  73268. *
  73269. * @alt
  73270. * 60x60 black rect x moves with mouse x and fuchsia canvas y moves with mouse y
  73271. */
  73272. _main.default.prototype.winMouseY = 0;
  73273. /**
  73274. * The system variable pwinMouseX always contains the horizontal position
  73275. * of the mouse in the frame previous to the current frame, relative to
  73276. * (0, 0) of the window. Note: pwinMouseX will be reset to the current winMouseX
  73277. * value at the start of each touch event.
  73278. *
  73279. * @property {Number} pwinMouseX
  73280. * @readOnly
  73281. *
  73282. * @example
  73283. * <div>
  73284. * <code>
  73285. * let myCanvas;
  73286. *
  73287. * function setup() {
  73288. * //use a variable to store a pointer to the canvas
  73289. * myCanvas = createCanvas(100, 100);
  73290. * noStroke();
  73291. * fill(237, 34, 93);
  73292. * }
  73293. *
  73294. * function draw() {
  73295. * clear();
  73296. * //the difference between previous and
  73297. * //current x position is the horizontal mouse speed
  73298. * let speed = abs(winMouseX - pwinMouseX);
  73299. * //change the size of the circle
  73300. * //according to the horizontal speed
  73301. * ellipse(50, 50, 10 + speed * 5, 10 + speed * 5);
  73302. * //move the canvas to the mouse position
  73303. * myCanvas.position(winMouseX + 1, winMouseY + 1);
  73304. * }
  73305. * </code>
  73306. * </div>
  73307. *
  73308. * @alt
  73309. * fuchsia ellipse moves with mouse x and y. Grows and shrinks with mouse speed
  73310. */
  73311. _main.default.prototype.pwinMouseX = 0;
  73312. /**
  73313. * The system variable pwinMouseY always contains the vertical position of
  73314. * the mouse in the frame previous to the current frame, relative to (0, 0)
  73315. * of the window. Note: pwinMouseY will be reset to the current winMouseY
  73316. * value at the start of each touch event.
  73317. *
  73318. * @property {Number} pwinMouseY
  73319. * @readOnly
  73320. *
  73321. * @example
  73322. * <div>
  73323. * <code>
  73324. * let myCanvas;
  73325. *
  73326. * function setup() {
  73327. * //use a variable to store a pointer to the canvas
  73328. * myCanvas = createCanvas(100, 100);
  73329. * noStroke();
  73330. * fill(237, 34, 93);
  73331. * }
  73332. *
  73333. * function draw() {
  73334. * clear();
  73335. * //the difference between previous and
  73336. * //current y position is the vertical mouse speed
  73337. * let speed = abs(winMouseY - pwinMouseY);
  73338. * //change the size of the circle
  73339. * //according to the vertical speed
  73340. * ellipse(50, 50, 10 + speed * 5, 10 + speed * 5);
  73341. * //move the canvas to the mouse position
  73342. * myCanvas.position(winMouseX + 1, winMouseY + 1);
  73343. * }
  73344. * </code>
  73345. * </div>
  73346. *
  73347. * @alt
  73348. * fuchsia ellipse moves with mouse x and y. Grows and shrinks with mouse speed
  73349. */
  73350. _main.default.prototype.pwinMouseY = 0;
  73351. /**
  73352. * p5 automatically tracks if the mouse button is pressed and which
  73353. * button is pressed. The value of the system variable mouseButton is either
  73354. * LEFT, RIGHT, or CENTER depending on which button was pressed last.
  73355. * Warning: different browsers may track mouseButton differently.
  73356. *
  73357. * @property {Constant} mouseButton
  73358. * @readOnly
  73359. *
  73360. * @example
  73361. * <div>
  73362. * <code>
  73363. * function draw() {
  73364. * background(237, 34, 93);
  73365. * fill(0);
  73366. *
  73367. * if (mouseIsPressed) {
  73368. * if (mouseButton === LEFT) {
  73369. * ellipse(50, 50, 50, 50);
  73370. * }
  73371. * if (mouseButton === RIGHT) {
  73372. * rect(25, 25, 50, 50);
  73373. * }
  73374. * if (mouseButton === CENTER) {
  73375. * triangle(23, 75, 50, 20, 78, 75);
  73376. * }
  73377. * }
  73378. *
  73379. * print(mouseButton);
  73380. * }
  73381. * </code>
  73382. * </div>
  73383. *
  73384. * @alt
  73385. * 50x50 black ellipse appears on center of fuchsia canvas on mouse click/press.
  73386. */
  73387. _main.default.prototype.mouseButton = 0;
  73388. /**
  73389. * The boolean system variable mouseIsPressed is true if the mouse is pressed
  73390. * and false if not.
  73391. *
  73392. * @property {Boolean} mouseIsPressed
  73393. * @readOnly
  73394. *
  73395. * @example
  73396. * <div>
  73397. * <code>
  73398. * function draw() {
  73399. * background(237, 34, 93);
  73400. * fill(0);
  73401. *
  73402. * if (mouseIsPressed) {
  73403. * ellipse(50, 50, 50, 50);
  73404. * } else {
  73405. * rect(25, 25, 50, 50);
  73406. * }
  73407. *
  73408. * print(mouseIsPressed);
  73409. * }
  73410. * </code>
  73411. * </div>
  73412. *
  73413. * @alt
  73414. * black 50x50 rect becomes ellipse with mouse click/press. fuchsia background.
  73415. */
  73416. _main.default.prototype.mouseIsPressed = false;
  73417. _main.default.prototype._updateNextMouseCoords = function(e) {
  73418. if (this._curElement !== null && (!e.touches || e.touches.length > 0)) {
  73419. var mousePos = getMousePos(this._curElement.elt, this.width, this.height, e);
  73420. this._setProperty('movedX', e.movementX);
  73421. this._setProperty('movedY', e.movementY);
  73422. this._setProperty('mouseX', mousePos.x);
  73423. this._setProperty('mouseY', mousePos.y);
  73424. this._setProperty('winMouseX', mousePos.winX);
  73425. this._setProperty('winMouseY', mousePos.winY);
  73426. }
  73427. if (!this._hasMouseInteracted) {
  73428. // For first draw, make previous and next equal
  73429. this._updateMouseCoords();
  73430. this._setProperty('_hasMouseInteracted', true);
  73431. }
  73432. };
  73433. _main.default.prototype._updateMouseCoords = function() {
  73434. this._setProperty('pmouseX', this.mouseX);
  73435. this._setProperty('pmouseY', this.mouseY);
  73436. this._setProperty('pwinMouseX', this.winMouseX);
  73437. this._setProperty('pwinMouseY', this.winMouseY);
  73438. this._setProperty('_pmouseWheelDeltaY', this._mouseWheelDeltaY);
  73439. };
  73440. function getMousePos(canvas, w, h, evt) {
  73441. if (evt && !evt.clientX) {
  73442. // use touches if touch and not mouse
  73443. if (evt.touches) {
  73444. evt = evt.touches[0];
  73445. } else if (evt.changedTouches) {
  73446. evt = evt.changedTouches[0];
  73447. }
  73448. }
  73449. var rect = canvas.getBoundingClientRect();
  73450. var sx = canvas.scrollWidth / w || 1;
  73451. var sy = canvas.scrollHeight / h || 1;
  73452. return {
  73453. x: (evt.clientX - rect.left) / sx,
  73454. y: (evt.clientY - rect.top) / sy,
  73455. winX: evt.clientX,
  73456. winY: evt.clientY,
  73457. id: evt.identifier
  73458. };
  73459. }
  73460. _main.default.prototype._setMouseButton = function(e) {
  73461. if (e.button === 1) {
  73462. this._setProperty('mouseButton', constants.CENTER);
  73463. } else if (e.button === 2) {
  73464. this._setProperty('mouseButton', constants.RIGHT);
  73465. } else {
  73466. this._setProperty('mouseButton', constants.LEFT);
  73467. }
  73468. };
  73469. /**
  73470. * The <a href="#/p5/mouseMoved">mouseMoved()</a> function is called every time the mouse moves and a mouse
  73471. * button is not pressed.<br><br>
  73472. * Browsers may have different default
  73473. * behaviors attached to various mouse events. To prevent any default
  73474. * behavior for this event, add "return false" to the end of the method.
  73475. *
  73476. * @method mouseMoved
  73477. * @param {Object} [event] optional MouseEvent callback argument.
  73478. * @example
  73479. * <div>
  73480. * <code>
  73481. * // Move the mouse across the page
  73482. * // to change its value
  73483. *
  73484. * let value = 0;
  73485. * function draw() {
  73486. * fill(value);
  73487. * rect(25, 25, 50, 50);
  73488. * }
  73489. * function mouseMoved() {
  73490. * value = value + 5;
  73491. * if (value > 255) {
  73492. * value = 0;
  73493. * }
  73494. * }
  73495. * </code>
  73496. * </div>
  73497. *
  73498. * <div class="norender">
  73499. * <code>
  73500. * function mouseMoved() {
  73501. * ellipse(mouseX, mouseY, 5, 5);
  73502. * // prevent default
  73503. * return false;
  73504. * }
  73505. * </code>
  73506. * </div>
  73507. *
  73508. * <div class="norender">
  73509. * <code>
  73510. * // returns a MouseEvent object
  73511. * // as a callback argument
  73512. * function mouseMoved(event) {
  73513. * console.log(event);
  73514. * }
  73515. * </code>
  73516. * </div>
  73517. *
  73518. * @alt
  73519. * black 50x50 rect becomes lighter with mouse movements until white then resets
  73520. * no image displayed
  73521. */
  73522. /**
  73523. * The <a href="#/p5/mouseDragged">mouseDragged()</a> function is called once every time the mouse moves and
  73524. * a mouse button is pressed. If no <a href="#/p5/mouseDragged">mouseDragged()</a> function is defined, the
  73525. * <a href="#/p5/touchMoved">touchMoved()</a> function will be called instead if it is defined.<br><br>
  73526. * Browsers may have different default
  73527. * behaviors attached to various mouse events. To prevent any default
  73528. * behavior for this event, add "return false" to the end of the method.
  73529. *
  73530. * @method mouseDragged
  73531. * @param {Object} [event] optional MouseEvent callback argument.
  73532. * @example
  73533. * <div>
  73534. * <code>
  73535. * // Drag the mouse across the page
  73536. * // to change its value
  73537. *
  73538. * let value = 0;
  73539. * function draw() {
  73540. * fill(value);
  73541. * rect(25, 25, 50, 50);
  73542. * }
  73543. * function mouseDragged() {
  73544. * value = value + 5;
  73545. * if (value > 255) {
  73546. * value = 0;
  73547. * }
  73548. * }
  73549. * </code>
  73550. * </div>
  73551. *
  73552. * <div class="norender">
  73553. * <code>
  73554. * function mouseDragged() {
  73555. * ellipse(mouseX, mouseY, 5, 5);
  73556. * // prevent default
  73557. * return false;
  73558. * }
  73559. * </code>
  73560. * </div>
  73561. *
  73562. * <div class="norender">
  73563. * <code>
  73564. * // returns a MouseEvent object
  73565. * // as a callback argument
  73566. * function mouseDragged(event) {
  73567. * console.log(event);
  73568. * }
  73569. * </code>
  73570. * </div>
  73571. *
  73572. * @alt
  73573. * black 50x50 rect turns lighter with mouse click and drag until white, resets
  73574. * no image displayed
  73575. */
  73576. _main.default.prototype._onmousemove = function(e) {
  73577. var context = this._isGlobal ? window : this;
  73578. var executeDefault;
  73579. this._updateNextMouseCoords(e);
  73580. if (!this.mouseIsPressed) {
  73581. if (typeof context.mouseMoved === 'function') {
  73582. executeDefault = context.mouseMoved(e);
  73583. if (executeDefault === false) {
  73584. e.preventDefault();
  73585. }
  73586. }
  73587. } else {
  73588. if (typeof context.mouseDragged === 'function') {
  73589. executeDefault = context.mouseDragged(e);
  73590. if (executeDefault === false) {
  73591. e.preventDefault();
  73592. }
  73593. } else if (typeof context.touchMoved === 'function') {
  73594. executeDefault = context.touchMoved(e);
  73595. if (executeDefault === false) {
  73596. e.preventDefault();
  73597. }
  73598. }
  73599. }
  73600. };
  73601. /**
  73602. * The <a href="#/p5/mousePressed">mousePressed()</a> function is called once after every time a mouse button
  73603. * is pressed. The mouseButton variable (see the related reference entry)
  73604. * can be used to determine which button has been pressed. If no
  73605. * <a href="#/p5/mousePressed">mousePressed()</a> function is defined, the <a href="#/p5/touchStarted">touchStarted()</a> function will be
  73606. * called instead if it is defined.<br><br>
  73607. * Browsers may have different default
  73608. * behaviors attached to various mouse events. To prevent any default
  73609. * behavior for this event, add "return false" to the end of the method.
  73610. *
  73611. * @method mousePressed
  73612. * @param {Object} [event] optional MouseEvent callback argument.
  73613. * @example
  73614. * <div>
  73615. * <code>
  73616. * // Click within the image to change
  73617. * // the value of the rectangle
  73618. *
  73619. * let value = 0;
  73620. * function draw() {
  73621. * fill(value);
  73622. * rect(25, 25, 50, 50);
  73623. * }
  73624. * function mousePressed() {
  73625. * if (value === 0) {
  73626. * value = 255;
  73627. * } else {
  73628. * value = 0;
  73629. * }
  73630. * }
  73631. * </code>
  73632. * </div>
  73633. *
  73634. * <div class="norender">
  73635. * <code>
  73636. * function mousePressed() {
  73637. * ellipse(mouseX, mouseY, 5, 5);
  73638. * // prevent default
  73639. * return false;
  73640. * }
  73641. * </code>
  73642. * </div>
  73643. *
  73644. * <div class="norender">
  73645. * <code>
  73646. * // returns a MouseEvent object
  73647. * // as a callback argument
  73648. * function mousePressed(event) {
  73649. * console.log(event);
  73650. * }
  73651. * </code>
  73652. * </div>
  73653. *
  73654. * @alt
  73655. * black 50x50 rect turns white with mouse click/press.
  73656. * no image displayed
  73657. */
  73658. _main.default.prototype._onmousedown = function(e) {
  73659. var context = this._isGlobal ? window : this;
  73660. var executeDefault;
  73661. this._setProperty('mouseIsPressed', true);
  73662. this._setMouseButton(e);
  73663. this._updateNextMouseCoords(e);
  73664. if (typeof context.mousePressed === 'function') {
  73665. executeDefault = context.mousePressed(e);
  73666. if (executeDefault === false) {
  73667. e.preventDefault();
  73668. }
  73669. // only safari needs this manual fallback for consistency
  73670. } else if (
  73671. navigator.userAgent.toLowerCase().includes('safari') &&
  73672. typeof context.touchStarted === 'function'
  73673. ) {
  73674. executeDefault = context.touchStarted(e);
  73675. if (executeDefault === false) {
  73676. e.preventDefault();
  73677. }
  73678. }
  73679. };
  73680. /**
  73681. * The <a href="#/p5/mouseReleased">mouseReleased()</a> function is called every time a mouse button is
  73682. * released. If no <a href="#/p5/mouseReleased">mouseReleased()</a> function is defined, the <a href="#/p5/touchEnded">touchEnded()</a>
  73683. * function will be called instead if it is defined.<br><br>
  73684. * Browsers may have different default
  73685. * behaviors attached to various mouse events. To prevent any default
  73686. * behavior for this event, add "return false" to the end of the method.
  73687. *
  73688. * @method mouseReleased
  73689. * @param {Object} [event] optional MouseEvent callback argument.
  73690. * @example
  73691. * <div>
  73692. * <code>
  73693. * // Click within the image to change
  73694. * // the value of the rectangle
  73695. * // after the mouse has been clicked
  73696. *
  73697. * let value = 0;
  73698. * function draw() {
  73699. * fill(value);
  73700. * rect(25, 25, 50, 50);
  73701. * }
  73702. * function mouseReleased() {
  73703. * if (value === 0) {
  73704. * value = 255;
  73705. * } else {
  73706. * value = 0;
  73707. * }
  73708. * }
  73709. * </code>
  73710. * </div>
  73711. *
  73712. * <div class="norender">
  73713. * <code>
  73714. * function mouseReleased() {
  73715. * ellipse(mouseX, mouseY, 5, 5);
  73716. * // prevent default
  73717. * return false;
  73718. * }
  73719. * </code>
  73720. * </div>
  73721. *
  73722. * <div class="norender">
  73723. * <code>
  73724. * // returns a MouseEvent object
  73725. * // as a callback argument
  73726. * function mouseReleased(event) {
  73727. * console.log(event);
  73728. * }
  73729. * </code>
  73730. * </div>
  73731. *
  73732. * @alt
  73733. * black 50x50 rect turns white with mouse click/press.
  73734. * no image displayed
  73735. */
  73736. _main.default.prototype._onmouseup = function(e) {
  73737. var context = this._isGlobal ? window : this;
  73738. var executeDefault;
  73739. this._setProperty('mouseIsPressed', false);
  73740. if (typeof context.mouseReleased === 'function') {
  73741. executeDefault = context.mouseReleased(e);
  73742. if (executeDefault === false) {
  73743. e.preventDefault();
  73744. }
  73745. } else if (typeof context.touchEnded === 'function') {
  73746. executeDefault = context.touchEnded(e);
  73747. if (executeDefault === false) {
  73748. e.preventDefault();
  73749. }
  73750. }
  73751. };
  73752. _main.default.prototype._ondragend = _main.default.prototype._onmouseup;
  73753. _main.default.prototype._ondragover = _main.default.prototype._onmousemove;
  73754. /**
  73755. * The <a href="#/p5/mouseClicked">mouseClicked()</a> function is called once after a mouse button has been
  73756. * pressed and then released.<br><br>
  73757. * Browsers handle clicks differently, so this function is only guaranteed to be
  73758. * run when the left mouse button is clicked. To handle other mouse buttons
  73759. * being pressed or released, see <a href="#/p5/mousePressed">mousePressed()</a> or <a href="#/p5/mouseReleased">mouseReleased()</a>.<br><br>
  73760. * Browsers may have different default
  73761. * behaviors attached to various mouse events. To prevent any default
  73762. * behavior for this event, add "return false" to the end of the method.
  73763. *
  73764. * @method mouseClicked
  73765. * @param {Object} [event] optional MouseEvent callback argument.
  73766. * @example
  73767. * <div>
  73768. * <code>
  73769. * // Click within the image to change
  73770. * // the value of the rectangle
  73771. * // after the mouse has been clicked
  73772. *
  73773. * let value = 0;
  73774. * function draw() {
  73775. * fill(value);
  73776. * rect(25, 25, 50, 50);
  73777. * }
  73778. *
  73779. * function mouseClicked() {
  73780. * if (value === 0) {
  73781. * value = 255;
  73782. * } else {
  73783. * value = 0;
  73784. * }
  73785. * }
  73786. * </code>
  73787. * </div>
  73788. *
  73789. * <div class="norender">
  73790. * <code>
  73791. * function mouseClicked() {
  73792. * ellipse(mouseX, mouseY, 5, 5);
  73793. * // prevent default
  73794. * return false;
  73795. * }
  73796. * </code>
  73797. * </div>
  73798. *
  73799. * <div class="norender">
  73800. * <code>
  73801. * // returns a MouseEvent object
  73802. * // as a callback argument
  73803. * function mouseClicked(event) {
  73804. * console.log(event);
  73805. * }
  73806. * </code>
  73807. * </div>
  73808. *
  73809. * @alt
  73810. * black 50x50 rect turns white with mouse click/press.
  73811. * no image displayed
  73812. */
  73813. _main.default.prototype._onclick = function(e) {
  73814. var context = this._isGlobal ? window : this;
  73815. if (typeof context.mouseClicked === 'function') {
  73816. var executeDefault = context.mouseClicked(e);
  73817. if (executeDefault === false) {
  73818. e.preventDefault();
  73819. }
  73820. }
  73821. };
  73822. /**
  73823. * The <a href="#/p5/doubleClicked">doubleClicked()</a> function is executed every time a event
  73824. * listener has detected a dblclick event which is a part of the
  73825. * DOM L3 specification. The doubleClicked event is fired when a
  73826. * pointing device button (usually a mouse's primary button)
  73827. * is clicked twice on a single element. For more info on the
  73828. * dblclick event refer to mozilla's documentation here:
  73829. * https://developer.mozilla.org/en-US/docs/Web/Events/dblclick
  73830. *
  73831. * @method doubleClicked
  73832. * @param {Object} [event] optional MouseEvent callback argument.
  73833. * @example
  73834. * <div>
  73835. * <code>
  73836. * // Click within the image to change
  73837. * // the value of the rectangle
  73838. * // after the mouse has been double clicked
  73839. *
  73840. * let value = 0;
  73841. * function draw() {
  73842. * fill(value);
  73843. * rect(25, 25, 50, 50);
  73844. * }
  73845. *
  73846. * function doubleClicked() {
  73847. * if (value === 0) {
  73848. * value = 255;
  73849. * } else {
  73850. * value = 0;
  73851. * }
  73852. * }
  73853. * </code>
  73854. * </div>
  73855. *
  73856. * <div class="norender">
  73857. * <code>
  73858. * function doubleClicked() {
  73859. * ellipse(mouseX, mouseY, 5, 5);
  73860. * // prevent default
  73861. * return false;
  73862. * }
  73863. * </code>
  73864. * </div>
  73865. *
  73866. * <div class="norender">
  73867. * <code>
  73868. * // returns a MouseEvent object
  73869. * // as a callback argument
  73870. * function doubleClicked(event) {
  73871. * console.log(event);
  73872. * }
  73873. * </code>
  73874. * </div>
  73875. *
  73876. * @alt
  73877. * black 50x50 rect turns white with mouse doubleClick/press.
  73878. * no image displayed
  73879. */
  73880. _main.default.prototype._ondblclick = function(e) {
  73881. var context = this._isGlobal ? window : this;
  73882. if (typeof context.doubleClicked === 'function') {
  73883. var executeDefault = context.doubleClicked(e);
  73884. if (executeDefault === false) {
  73885. e.preventDefault();
  73886. }
  73887. }
  73888. };
  73889. /**
  73890. * For use with WebGL orbitControl.
  73891. * @property {Number} _mouseWheelDeltaY
  73892. * @readOnly
  73893. * @private
  73894. */
  73895. _main.default.prototype._mouseWheelDeltaY = 0;
  73896. /**
  73897. * For use with WebGL orbitControl.
  73898. * @property {Number} _pmouseWheelDeltaY
  73899. * @readOnly
  73900. * @private
  73901. */
  73902. _main.default.prototype._pmouseWheelDeltaY = 0;
  73903. /**
  73904. * The function <a href="#/p5/mouseWheel">mouseWheel()</a> is executed every time a vertical mouse wheel
  73905. * event is detected either triggered by an actual mouse wheel or by a
  73906. * touchpad.<br><br>
  73907. * The event.delta property returns the amount the mouse wheel
  73908. * have scrolled. The values can be positive or negative depending on the
  73909. * scroll direction (on OS X with "natural" scrolling enabled, the signs
  73910. * are inverted).<br><br>
  73911. * Browsers may have different default behaviors attached to various
  73912. * mouse events. To prevent any default behavior for this event, add
  73913. * "return false" to the end of the method.<br><br>
  73914. * Due to the current support of the "wheel" event on Safari, the function
  73915. * may only work as expected if "return false" is included while using Safari.
  73916. *
  73917. * @method mouseWheel
  73918. * @param {Object} [event] optional WheelEvent callback argument.
  73919. *
  73920. * @example
  73921. * <div>
  73922. * <code>
  73923. * let pos = 25;
  73924. *
  73925. * function draw() {
  73926. * background(237, 34, 93);
  73927. * fill(0);
  73928. * rect(25, pos, 50, 50);
  73929. * }
  73930. *
  73931. * function mouseWheel(event) {
  73932. * print(event.delta);
  73933. * //move the square according to the vertical scroll amount
  73934. * pos += event.delta;
  73935. * //uncomment to block page scrolling
  73936. * //return false;
  73937. * }
  73938. * </code>
  73939. * </div>
  73940. *
  73941. * @alt
  73942. * black 50x50 rect moves up and down with vertical scroll. fuchsia background
  73943. */
  73944. _main.default.prototype._onwheel = function(e) {
  73945. var context = this._isGlobal ? window : this;
  73946. this._setProperty('_mouseWheelDeltaY', e.deltaY);
  73947. if (typeof context.mouseWheel === 'function') {
  73948. e.delta = e.deltaY;
  73949. var executeDefault = context.mouseWheel(e);
  73950. if (executeDefault === false) {
  73951. e.preventDefault();
  73952. }
  73953. }
  73954. };
  73955. /**
  73956. * The function <a href="#/p5/requestPointerLock">requestPointerLock()</a>
  73957. * locks the pointer to its current position and makes it invisible.
  73958. * Use <a href="#/p5/movedX">movedX</a> and <a href="#/p5/movedY">movedY</a> to get the difference the mouse was moved since
  73959. * the last call of draw.
  73960. * Note that not all browsers support this feature.
  73961. * This enables you to create experiences that aren't limited by the mouse moving out of the screen
  73962. * even if it is repeatedly moved into one direction.
  73963. * For example, a first person perspective experience.
  73964. *
  73965. * @method requestPointerLock
  73966. * @example
  73967. * <div class="notest">
  73968. * <code>
  73969. * let cam;
  73970. * function setup() {
  73971. * createCanvas(100, 100, WEBGL);
  73972. * requestPointerLock();
  73973. * cam = createCamera();
  73974. * }
  73975. *
  73976. * function draw() {
  73977. * background(255);
  73978. * cam.pan(-movedX * 0.001);
  73979. * cam.tilt(movedY * 0.001);
  73980. * sphere(25);
  73981. * }
  73982. * </code>
  73983. * </div>
  73984. *
  73985. * @alt
  73986. * 3D scene moves according to mouse mouse movement in a first person perspective
  73987. */
  73988. _main.default.prototype.requestPointerLock = function() {
  73989. // pointer lock object forking for cross browser
  73990. var canvas = this._curElement.elt;
  73991. canvas.requestPointerLock =
  73992. canvas.requestPointerLock || canvas.mozRequestPointerLock;
  73993. if (!canvas.requestPointerLock) {
  73994. console.log('requestPointerLock is not implemented in this browser');
  73995. return false;
  73996. }
  73997. canvas.requestPointerLock();
  73998. return true;
  73999. };
  74000. /**
  74001. * The function <a href="#/p5/exitPointerLock">exitPointerLock()</a>
  74002. * exits a previously triggered <a href="#/p5/requestPointerLock">pointer Lock</a>
  74003. * for example to make ui elements usable etc
  74004. *
  74005. * @method exitPointerLock
  74006. * @example
  74007. * <div class="notest">
  74008. * <code>
  74009. * //click the canvas to lock the pointer
  74010. * //click again to exit (otherwise escape)
  74011. * let locked = false;
  74012. * function draw() {
  74013. * background(237, 34, 93);
  74014. * }
  74015. * function mouseClicked() {
  74016. * if (!locked) {
  74017. * locked = true;
  74018. * requestPointerLock();
  74019. * } else {
  74020. * exitPointerLock();
  74021. * locked = false;
  74022. * }
  74023. * }
  74024. * </code>
  74025. * </div>
  74026. *
  74027. * @alt
  74028. * cursor gets locked / unlocked on mouse-click
  74029. */
  74030. _main.default.prototype.exitPointerLock = function() {
  74031. document.exitPointerLock();
  74032. };
  74033. var _default = _main.default;
  74034. exports.default = _default;
  74035. },
  74036. {
  74037. '../core/constants': 272,
  74038. '../core/main': 283,
  74039. 'core-js/modules/es.array.includes': 172,
  74040. 'core-js/modules/es.string.includes': 200
  74041. }
  74042. ],
  74043. 303: [
  74044. function(_dereq_, module, exports) {
  74045. 'use strict';
  74046. _dereq_('core-js/modules/es.array.includes');
  74047. _dereq_('core-js/modules/es.string.includes');
  74048. Object.defineProperty(exports, '__esModule', { value: true });
  74049. exports.default = void 0;
  74050. var _main = _interopRequireDefault(_dereq_('../core/main'));
  74051. function _interopRequireDefault(obj) {
  74052. return obj && obj.__esModule ? obj : { default: obj };
  74053. }
  74054. /**
  74055. * @module Events
  74056. * @submodule Touch
  74057. * @for p5
  74058. * @requires core
  74059. */ /**
  74060. * The system variable touches[] contains an array of the positions of all
  74061. * current touch points, relative to (0, 0) of the canvas, and IDs identifying a
  74062. * unique touch as it moves. Each element in the array is an object with x, y,
  74063. * and id properties.
  74064. *
  74065. * The touches[] array is not supported on Safari and IE on touch-based
  74066. * desktops (laptops).
  74067. *
  74068. * @property {Object[]} touches
  74069. * @readOnly
  74070. *
  74071. * @example
  74072. * <div>
  74073. * <code>
  74074. * // On a touchscreen device, touch
  74075. * // the canvas using one or more fingers
  74076. * // at the same time
  74077. * function draw() {
  74078. * clear();
  74079. * let display = touches.length + ' touches';
  74080. * text(display, 5, 10);
  74081. * }
  74082. * </code>
  74083. * </div>
  74084. *
  74085. * @alt
  74086. * Number of touches currently registered are displayed on the canvas
  74087. */ _main.default.prototype.touches = [];
  74088. _main.default.prototype._updateTouchCoords = function(e) {
  74089. if (this._curElement !== null) {
  74090. var touches = [];
  74091. for (var i = 0; i < e.touches.length; i++) {
  74092. touches[i] = getTouchInfo(
  74093. this._curElement.elt,
  74094. this.width,
  74095. this.height,
  74096. e,
  74097. i
  74098. );
  74099. }
  74100. this._setProperty('touches', touches);
  74101. }
  74102. };
  74103. function getTouchInfo(canvas, w, h, e) {
  74104. var i = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
  74105. var rect = canvas.getBoundingClientRect();
  74106. var sx = canvas.scrollWidth / w || 1;
  74107. var sy = canvas.scrollHeight / h || 1;
  74108. var touch = e.touches[i] || e.changedTouches[i];
  74109. return {
  74110. x: (touch.clientX - rect.left) / sx,
  74111. y: (touch.clientY - rect.top) / sy,
  74112. winX: touch.clientX,
  74113. winY: touch.clientY,
  74114. id: touch.identifier
  74115. };
  74116. }
  74117. /**
  74118. * The touchStarted() function is called once after every time a touch is
  74119. * registered. If no <a href="#/p5/touchStarted">touchStarted()</a> function is defined, the <a href="#/p5/mousePressed">mousePressed()</a>
  74120. * function will be called instead if it is defined.<br><br>
  74121. * Browsers may have different default behaviors attached to various touch
  74122. * events. To prevent any default behavior for this event, add "return false"
  74123. * to the end of the method.
  74124. *
  74125. * @method touchStarted
  74126. * @param {Object} [event] optional TouchEvent callback argument.
  74127. * @example
  74128. * <div>
  74129. * <code>
  74130. * // Touch within the image to change
  74131. * // the value of the rectangle
  74132. *
  74133. * let value = 0;
  74134. * function draw() {
  74135. * fill(value);
  74136. * rect(25, 25, 50, 50);
  74137. * }
  74138. * function touchStarted() {
  74139. * if (value === 0) {
  74140. * value = 255;
  74141. * } else {
  74142. * value = 0;
  74143. * }
  74144. * }
  74145. * </code>
  74146. * </div>
  74147. *
  74148. * <div class="norender">
  74149. * <code>
  74150. * function touchStarted() {
  74151. * ellipse(mouseX, mouseY, 5, 5);
  74152. * // prevent default
  74153. * return false;
  74154. * }
  74155. * </code>
  74156. * </div>
  74157. *
  74158. * <div class="norender">
  74159. * <code>
  74160. * // returns a TouchEvent object
  74161. * // as a callback argument
  74162. * function touchStarted(event) {
  74163. * console.log(event);
  74164. * }
  74165. * </code>
  74166. * </div>
  74167. *
  74168. * @alt
  74169. * 50x50 black rect turns white with touch event.
  74170. * no image displayed
  74171. */
  74172. _main.default.prototype._ontouchstart = function(e) {
  74173. var context = this._isGlobal ? window : this;
  74174. var executeDefault;
  74175. this._setProperty('mouseIsPressed', true);
  74176. this._updateTouchCoords(e);
  74177. this._updateNextMouseCoords(e);
  74178. this._updateMouseCoords(); // reset pmouseXY at the start of each touch event
  74179. if (typeof context.touchStarted === 'function') {
  74180. executeDefault = context.touchStarted(e);
  74181. if (executeDefault === false) {
  74182. e.preventDefault();
  74183. }
  74184. // only safari needs this manual fallback for consistency
  74185. } else if (
  74186. navigator.userAgent.toLowerCase().includes('safari') &&
  74187. typeof context.mousePressed === 'function'
  74188. ) {
  74189. executeDefault = context.mousePressed(e);
  74190. if (executeDefault === false) {
  74191. e.preventDefault();
  74192. }
  74193. }
  74194. };
  74195. /**
  74196. * The <a href="#/p5/touchMoved">touchMoved()</a> function is called every time a touch move is registered.
  74197. * If no <a href="#/p5/touchMoved">touchMoved()</a> function is defined, the <a href="#/p5/mouseDragged">mouseDragged()</a> function will
  74198. * be called instead if it is defined.<br><br>
  74199. * Browsers may have different default behaviors attached to various touch
  74200. * events. To prevent any default behavior for this event, add "return false"
  74201. * to the end of the method.
  74202. *
  74203. * @method touchMoved
  74204. * @param {Object} [event] optional TouchEvent callback argument.
  74205. * @example
  74206. * <div>
  74207. * <code>
  74208. * // Move your finger across the page
  74209. * // to change its value
  74210. *
  74211. * let value = 0;
  74212. * function draw() {
  74213. * fill(value);
  74214. * rect(25, 25, 50, 50);
  74215. * }
  74216. * function touchMoved() {
  74217. * value = value + 5;
  74218. * if (value > 255) {
  74219. * value = 0;
  74220. * }
  74221. * }
  74222. * </code>
  74223. * </div>
  74224. *
  74225. * <div class="norender">
  74226. * <code>
  74227. * function touchMoved() {
  74228. * ellipse(mouseX, mouseY, 5, 5);
  74229. * // prevent default
  74230. * return false;
  74231. * }
  74232. * </code>
  74233. * </div>
  74234. *
  74235. * <div class="norender">
  74236. * <code>
  74237. * // returns a TouchEvent object
  74238. * // as a callback argument
  74239. * function touchMoved(event) {
  74240. * console.log(event);
  74241. * }
  74242. * </code>
  74243. * </div>
  74244. *
  74245. * @alt
  74246. * 50x50 black rect turns lighter with touch until white. resets
  74247. * no image displayed
  74248. */
  74249. _main.default.prototype._ontouchmove = function(e) {
  74250. var context = this._isGlobal ? window : this;
  74251. var executeDefault;
  74252. this._updateTouchCoords(e);
  74253. this._updateNextMouseCoords(e);
  74254. if (typeof context.touchMoved === 'function') {
  74255. executeDefault = context.touchMoved(e);
  74256. if (executeDefault === false) {
  74257. e.preventDefault();
  74258. }
  74259. } else if (typeof context.mouseDragged === 'function') {
  74260. executeDefault = context.mouseDragged(e);
  74261. if (executeDefault === false) {
  74262. e.preventDefault();
  74263. }
  74264. }
  74265. };
  74266. /**
  74267. * The <a href="#/p5/touchEnded">touchEnded()</a> function is called every time a touch ends. If no
  74268. * <a href="#/p5/touchEnded">touchEnded()</a> function is defined, the <a href="#/p5/mouseReleased">mouseReleased()</a> function will be
  74269. * called instead if it is defined.<br><br>
  74270. * Browsers may have different default behaviors attached to various touch
  74271. * events. To prevent any default behavior for this event, add "return false"
  74272. * to the end of the method.
  74273. *
  74274. * @method touchEnded
  74275. * @param {Object} [event] optional TouchEvent callback argument.
  74276. * @example
  74277. * <div>
  74278. * <code>
  74279. * // Release touch within the image to
  74280. * // change the value of the rectangle
  74281. *
  74282. * let value = 0;
  74283. * function draw() {
  74284. * fill(value);
  74285. * rect(25, 25, 50, 50);
  74286. * }
  74287. * function touchEnded() {
  74288. * if (value === 0) {
  74289. * value = 255;
  74290. * } else {
  74291. * value = 0;
  74292. * }
  74293. * }
  74294. * </code>
  74295. * </div>
  74296. *
  74297. * <div class="norender">
  74298. * <code>
  74299. * function touchEnded() {
  74300. * ellipse(mouseX, mouseY, 5, 5);
  74301. * // prevent default
  74302. * return false;
  74303. * }
  74304. * </code>
  74305. * </div>
  74306. *
  74307. * <div class="norender">
  74308. * <code>
  74309. * // returns a TouchEvent object
  74310. * // as a callback argument
  74311. * function touchEnded(event) {
  74312. * console.log(event);
  74313. * }
  74314. * </code>
  74315. * </div>
  74316. *
  74317. * @alt
  74318. * 50x50 black rect turns white with touch.
  74319. * no image displayed
  74320. */
  74321. _main.default.prototype._ontouchend = function(e) {
  74322. this._setProperty('mouseIsPressed', false);
  74323. this._updateTouchCoords(e);
  74324. this._updateNextMouseCoords(e);
  74325. var context = this._isGlobal ? window : this;
  74326. var executeDefault;
  74327. if (typeof context.touchEnded === 'function') {
  74328. executeDefault = context.touchEnded(e);
  74329. if (executeDefault === false) {
  74330. e.preventDefault();
  74331. }
  74332. } else if (typeof context.mouseReleased === 'function') {
  74333. executeDefault = context.mouseReleased(e);
  74334. if (executeDefault === false) {
  74335. e.preventDefault();
  74336. }
  74337. }
  74338. };
  74339. var _default = _main.default;
  74340. exports.default = _default;
  74341. },
  74342. {
  74343. '../core/main': 283,
  74344. 'core-js/modules/es.array.includes': 172,
  74345. 'core-js/modules/es.string.includes': 200
  74346. }
  74347. ],
  74348. 304: [
  74349. function(_dereq_, module, exports) {
  74350. 'use strict';
  74351. _dereq_('core-js/modules/es.array.iterator');
  74352. _dereq_('core-js/modules/es.object.to-string');
  74353. _dereq_('core-js/modules/es.typed-array.int32-array');
  74354. _dereq_('core-js/modules/es.typed-array.uint8-array');
  74355. _dereq_('core-js/modules/es.typed-array.copy-within');
  74356. _dereq_('core-js/modules/es.typed-array.every');
  74357. _dereq_('core-js/modules/es.typed-array.fill');
  74358. _dereq_('core-js/modules/es.typed-array.filter');
  74359. _dereq_('core-js/modules/es.typed-array.find');
  74360. _dereq_('core-js/modules/es.typed-array.find-index');
  74361. _dereq_('core-js/modules/es.typed-array.for-each');
  74362. _dereq_('core-js/modules/es.typed-array.includes');
  74363. _dereq_('core-js/modules/es.typed-array.index-of');
  74364. _dereq_('core-js/modules/es.typed-array.iterator');
  74365. _dereq_('core-js/modules/es.typed-array.join');
  74366. _dereq_('core-js/modules/es.typed-array.last-index-of');
  74367. _dereq_('core-js/modules/es.typed-array.map');
  74368. _dereq_('core-js/modules/es.typed-array.reduce');
  74369. _dereq_('core-js/modules/es.typed-array.reduce-right');
  74370. _dereq_('core-js/modules/es.typed-array.reverse');
  74371. _dereq_('core-js/modules/es.typed-array.set');
  74372. _dereq_('core-js/modules/es.typed-array.slice');
  74373. _dereq_('core-js/modules/es.typed-array.some');
  74374. _dereq_('core-js/modules/es.typed-array.sort');
  74375. _dereq_('core-js/modules/es.typed-array.subarray');
  74376. _dereq_('core-js/modules/es.typed-array.to-locale-string');
  74377. _dereq_('core-js/modules/es.typed-array.to-string');
  74378. Object.defineProperty(exports, '__esModule', { value: true });
  74379. exports.default = void 0; /*global ImageData:false */
  74380. /**
  74381. * This module defines the filters for use with image buffers.
  74382. *
  74383. * This module is basically a collection of functions stored in an object
  74384. * as opposed to modules. The functions are destructive, modifying
  74385. * the passed in canvas rather than creating a copy.
  74386. *
  74387. * Generally speaking users of this module will use the Filters.apply method
  74388. * on a canvas to create an effect.
  74389. *
  74390. * A number of functions are borrowed/adapted from
  74391. * http://www.html5rocks.com/en/tutorials/canvas/imagefilters/
  74392. * or the java processing implementation.
  74393. */
  74394. var Filters = {};
  74395. /*
  74396. * Helper functions
  74397. */
  74398. /**
  74399. * Returns the pixel buffer for a canvas
  74400. *
  74401. * @private
  74402. *
  74403. * @param {Canvas|ImageData} canvas the canvas to get pixels from
  74404. * @return {Uint8ClampedArray} a one-dimensional array containing
  74405. * the data in thc RGBA order, with integer
  74406. * values between 0 and 255
  74407. */
  74408. Filters._toPixels = function(canvas) {
  74409. if (canvas instanceof ImageData) {
  74410. return canvas.data;
  74411. } else {
  74412. if (canvas.getContext('2d')) {
  74413. return canvas
  74414. .getContext('2d')
  74415. .getImageData(0, 0, canvas.width, canvas.height).data;
  74416. } else if (canvas.getContext('webgl')) {
  74417. var gl = canvas.getContext('webgl');
  74418. var len = gl.drawingBufferWidth * gl.drawingBufferHeight * 4;
  74419. var data = new Uint8Array(len);
  74420. gl.readPixels(
  74421. 0,
  74422. 0,
  74423. canvas.width,
  74424. canvas.height,
  74425. gl.RGBA,
  74426. gl.UNSIGNED_BYTE,
  74427. data
  74428. );
  74429. return data;
  74430. }
  74431. }
  74432. };
  74433. /**
  74434. * Returns a 32 bit number containing ARGB data at ith pixel in the
  74435. * 1D array containing pixels data.
  74436. *
  74437. * @private
  74438. *
  74439. * @param {Uint8ClampedArray} data array returned by _toPixels()
  74440. * @param {Integer} i index of a 1D Image Array
  74441. * @return {Integer} 32 bit integer value representing
  74442. * ARGB value.
  74443. */
  74444. Filters._getARGB = function(data, i) {
  74445. var offset = i * 4;
  74446. return (
  74447. ((data[offset + 3] << 24) & 0xff000000) |
  74448. ((data[offset] << 16) & 0x00ff0000) |
  74449. ((data[offset + 1] << 8) & 0x0000ff00) |
  74450. (data[offset + 2] & 0x000000ff)
  74451. );
  74452. };
  74453. /**
  74454. * Modifies pixels RGBA values to values contained in the data object.
  74455. *
  74456. * @private
  74457. *
  74458. * @param {Uint8ClampedArray} pixels array returned by _toPixels()
  74459. * @param {Int32Array} data source 1D array where each value
  74460. * represents ARGB values
  74461. */
  74462. Filters._setPixels = function(pixels, data) {
  74463. var offset = 0;
  74464. for (var i = 0, al = pixels.length; i < al; i++) {
  74465. offset = i * 4;
  74466. pixels[offset + 0] = (data[i] & 0x00ff0000) >>> 16;
  74467. pixels[offset + 1] = (data[i] & 0x0000ff00) >>> 8;
  74468. pixels[offset + 2] = data[i] & 0x000000ff;
  74469. pixels[offset + 3] = (data[i] & 0xff000000) >>> 24;
  74470. }
  74471. };
  74472. /**
  74473. * Returns the ImageData object for a canvas
  74474. * https://developer.mozilla.org/en-US/docs/Web/API/ImageData
  74475. *
  74476. * @private
  74477. *
  74478. * @param {Canvas|ImageData} canvas canvas to get image data from
  74479. * @return {ImageData} Holder of pixel data (and width and
  74480. * height) for a canvas
  74481. */
  74482. Filters._toImageData = function(canvas) {
  74483. if (canvas instanceof ImageData) {
  74484. return canvas;
  74485. } else {
  74486. return canvas
  74487. .getContext('2d')
  74488. .getImageData(0, 0, canvas.width, canvas.height);
  74489. }
  74490. };
  74491. /**
  74492. * Returns a blank ImageData object.
  74493. *
  74494. * @private
  74495. *
  74496. * @param {Integer} width
  74497. * @param {Integer} height
  74498. * @return {ImageData}
  74499. */
  74500. Filters._createImageData = function(width, height) {
  74501. Filters._tmpCanvas = document.createElement('canvas');
  74502. Filters._tmpCtx = Filters._tmpCanvas.getContext('2d');
  74503. return this._tmpCtx.createImageData(width, height);
  74504. };
  74505. /**
  74506. * Applys a filter function to a canvas.
  74507. *
  74508. * The difference between this and the actual filter functions defined below
  74509. * is that the filter functions generally modify the pixel buffer but do
  74510. * not actually put that data back to the canvas (where it would actually
  74511. * update what is visible). By contrast this method does make the changes
  74512. * actually visible in the canvas.
  74513. *
  74514. * The apply method is the method that callers of this module would generally
  74515. * use. It has been separated from the actual filters to support an advanced
  74516. * use case of creating a filter chain that executes without actually updating
  74517. * the canvas in between everystep.
  74518. *
  74519. * @private
  74520. * @param {HTMLCanvasElement} canvas [description]
  74521. * @param {function(ImageData,Object)} func [description]
  74522. * @param {Object} filterParam [description]
  74523. */
  74524. Filters.apply = function(canvas, func, filterParam) {
  74525. var pixelsState = canvas.getContext('2d');
  74526. var imageData = pixelsState.getImageData(0, 0, canvas.width, canvas.height);
  74527. //Filters can either return a new ImageData object, or just modify
  74528. //the one they received.
  74529. var newImageData = func(imageData, filterParam);
  74530. if (newImageData instanceof ImageData) {
  74531. pixelsState.putImageData(
  74532. newImageData,
  74533. 0,
  74534. 0,
  74535. 0,
  74536. 0,
  74537. canvas.width,
  74538. canvas.height
  74539. );
  74540. } else {
  74541. pixelsState.putImageData(imageData, 0, 0, 0, 0, canvas.width, canvas.height);
  74542. }
  74543. };
  74544. /*
  74545. * Filters
  74546. */
  74547. /**
  74548. * Converts the image to black and white pixels depending if they are above or
  74549. * below the threshold defined by the level parameter. The parameter must be
  74550. * between 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used.
  74551. *
  74552. * Borrowed from http://www.html5rocks.com/en/tutorials/canvas/imagefilters/
  74553. *
  74554. * @private
  74555. * @param {Canvas} canvas
  74556. * @param {Float} level
  74557. */
  74558. Filters.threshold = function(canvas, level) {
  74559. var pixels = Filters._toPixels(canvas);
  74560. if (level === undefined) {
  74561. level = 0.5;
  74562. }
  74563. var thresh = Math.floor(level * 255);
  74564. for (var i = 0; i < pixels.length; i += 4) {
  74565. var r = pixels[i];
  74566. var g = pixels[i + 1];
  74567. var b = pixels[i + 2];
  74568. var gray = 0.2126 * r + 0.7152 * g + 0.0722 * b;
  74569. var val = void 0;
  74570. if (gray >= thresh) {
  74571. val = 255;
  74572. } else {
  74573. val = 0;
  74574. }
  74575. pixels[i] = pixels[i + 1] = pixels[i + 2] = val;
  74576. }
  74577. };
  74578. /**
  74579. * Converts any colors in the image to grayscale equivalents.
  74580. * No parameter is used.
  74581. *
  74582. * Borrowed from http://www.html5rocks.com/en/tutorials/canvas/imagefilters/
  74583. *
  74584. * @private
  74585. * @param {Canvas} canvas
  74586. */
  74587. Filters.gray = function(canvas) {
  74588. var pixels = Filters._toPixels(canvas);
  74589. for (var i = 0; i < pixels.length; i += 4) {
  74590. var r = pixels[i];
  74591. var g = pixels[i + 1];
  74592. var b = pixels[i + 2];
  74593. // CIE luminance for RGB
  74594. var gray = 0.2126 * r + 0.7152 * g + 0.0722 * b;
  74595. pixels[i] = pixels[i + 1] = pixels[i + 2] = gray;
  74596. }
  74597. };
  74598. /**
  74599. * Sets the alpha channel to entirely opaque. No parameter is used.
  74600. *
  74601. * @private
  74602. * @param {Canvas} canvas
  74603. */
  74604. Filters.opaque = function(canvas) {
  74605. var pixels = Filters._toPixels(canvas);
  74606. for (var i = 0; i < pixels.length; i += 4) {
  74607. pixels[i + 3] = 255;
  74608. }
  74609. return pixels;
  74610. };
  74611. /**
  74612. * Sets each pixel to its inverse value. No parameter is used.
  74613. * @private
  74614. * @param {Canvas} canvas
  74615. */
  74616. Filters.invert = function(canvas) {
  74617. var pixels = Filters._toPixels(canvas);
  74618. for (var i = 0; i < pixels.length; i += 4) {
  74619. pixels[i] = 255 - pixels[i];
  74620. pixels[i + 1] = 255 - pixels[i + 1];
  74621. pixels[i + 2] = 255 - pixels[i + 2];
  74622. }
  74623. };
  74624. /**
  74625. * Limits each channel of the image to the number of colors specified as
  74626. * the parameter. The parameter can be set to values between 2 and 255, but
  74627. * results are most noticeable in the lower ranges.
  74628. *
  74629. * Adapted from java based processing implementation
  74630. *
  74631. * @private
  74632. * @param {Canvas} canvas
  74633. * @param {Integer} level
  74634. */
  74635. Filters.posterize = function(canvas, level) {
  74636. var pixels = Filters._toPixels(canvas);
  74637. if (level < 2 || level > 255) {
  74638. throw new Error(
  74639. 'Level must be greater than 2 and less than 255 for posterize'
  74640. );
  74641. }
  74642. var levels1 = level - 1;
  74643. for (var i = 0; i < pixels.length; i += 4) {
  74644. var rlevel = pixels[i];
  74645. var glevel = pixels[i + 1];
  74646. var blevel = pixels[i + 2];
  74647. pixels[i] = ((rlevel * level) >> 8) * 255 / levels1;
  74648. pixels[i + 1] = ((glevel * level) >> 8) * 255 / levels1;
  74649. pixels[i + 2] = ((blevel * level) >> 8) * 255 / levels1;
  74650. }
  74651. };
  74652. /**
  74653. * reduces the bright areas in an image
  74654. * @private
  74655. * @param {Canvas} canvas
  74656. */
  74657. Filters.dilate = function(canvas) {
  74658. var pixels = Filters._toPixels(canvas);
  74659. var currIdx = 0;
  74660. var maxIdx = pixels.length ? pixels.length / 4 : 0;
  74661. var out = new Int32Array(maxIdx);
  74662. var currRowIdx, maxRowIdx, colOrig, colOut, currLum;
  74663. var idxRight, idxLeft, idxUp, idxDown;
  74664. var colRight, colLeft, colUp, colDown;
  74665. var lumRight, lumLeft, lumUp, lumDown;
  74666. while (currIdx < maxIdx) {
  74667. currRowIdx = currIdx;
  74668. maxRowIdx = currIdx + canvas.width;
  74669. while (currIdx < maxRowIdx) {
  74670. colOrig = colOut = Filters._getARGB(pixels, currIdx);
  74671. idxLeft = currIdx - 1;
  74672. idxRight = currIdx + 1;
  74673. idxUp = currIdx - canvas.width;
  74674. idxDown = currIdx + canvas.width;
  74675. if (idxLeft < currRowIdx) {
  74676. idxLeft = currIdx;
  74677. }
  74678. if (idxRight >= maxRowIdx) {
  74679. idxRight = currIdx;
  74680. }
  74681. if (idxUp < 0) {
  74682. idxUp = 0;
  74683. }
  74684. if (idxDown >= maxIdx) {
  74685. idxDown = currIdx;
  74686. }
  74687. colUp = Filters._getARGB(pixels, idxUp);
  74688. colLeft = Filters._getARGB(pixels, idxLeft);
  74689. colDown = Filters._getARGB(pixels, idxDown);
  74690. colRight = Filters._getARGB(pixels, idxRight);
  74691. //compute luminance
  74692. currLum =
  74693. 77 * ((colOrig >> 16) & 0xff) +
  74694. 151 * ((colOrig >> 8) & 0xff) +
  74695. 28 * (colOrig & 0xff);
  74696. lumLeft =
  74697. 77 * ((colLeft >> 16) & 0xff) +
  74698. 151 * ((colLeft >> 8) & 0xff) +
  74699. 28 * (colLeft & 0xff);
  74700. lumRight =
  74701. 77 * ((colRight >> 16) & 0xff) +
  74702. 151 * ((colRight >> 8) & 0xff) +
  74703. 28 * (colRight & 0xff);
  74704. lumUp =
  74705. 77 * ((colUp >> 16) & 0xff) +
  74706. 151 * ((colUp >> 8) & 0xff) +
  74707. 28 * (colUp & 0xff);
  74708. lumDown =
  74709. 77 * ((colDown >> 16) & 0xff) +
  74710. 151 * ((colDown >> 8) & 0xff) +
  74711. 28 * (colDown & 0xff);
  74712. if (lumLeft > currLum) {
  74713. colOut = colLeft;
  74714. currLum = lumLeft;
  74715. }
  74716. if (lumRight > currLum) {
  74717. colOut = colRight;
  74718. currLum = lumRight;
  74719. }
  74720. if (lumUp > currLum) {
  74721. colOut = colUp;
  74722. currLum = lumUp;
  74723. }
  74724. if (lumDown > currLum) {
  74725. colOut = colDown;
  74726. currLum = lumDown;
  74727. }
  74728. out[currIdx++] = colOut;
  74729. }
  74730. }
  74731. Filters._setPixels(pixels, out);
  74732. };
  74733. /**
  74734. * increases the bright areas in an image
  74735. * @private
  74736. * @param {Canvas} canvas
  74737. */
  74738. Filters.erode = function(canvas) {
  74739. var pixels = Filters._toPixels(canvas);
  74740. var currIdx = 0;
  74741. var maxIdx = pixels.length ? pixels.length / 4 : 0;
  74742. var out = new Int32Array(maxIdx);
  74743. var currRowIdx, maxRowIdx, colOrig, colOut, currLum;
  74744. var idxRight, idxLeft, idxUp, idxDown;
  74745. var colRight, colLeft, colUp, colDown;
  74746. var lumRight, lumLeft, lumUp, lumDown;
  74747. while (currIdx < maxIdx) {
  74748. currRowIdx = currIdx;
  74749. maxRowIdx = currIdx + canvas.width;
  74750. while (currIdx < maxRowIdx) {
  74751. colOrig = colOut = Filters._getARGB(pixels, currIdx);
  74752. idxLeft = currIdx - 1;
  74753. idxRight = currIdx + 1;
  74754. idxUp = currIdx - canvas.width;
  74755. idxDown = currIdx + canvas.width;
  74756. if (idxLeft < currRowIdx) {
  74757. idxLeft = currIdx;
  74758. }
  74759. if (idxRight >= maxRowIdx) {
  74760. idxRight = currIdx;
  74761. }
  74762. if (idxUp < 0) {
  74763. idxUp = 0;
  74764. }
  74765. if (idxDown >= maxIdx) {
  74766. idxDown = currIdx;
  74767. }
  74768. colUp = Filters._getARGB(pixels, idxUp);
  74769. colLeft = Filters._getARGB(pixels, idxLeft);
  74770. colDown = Filters._getARGB(pixels, idxDown);
  74771. colRight = Filters._getARGB(pixels, idxRight);
  74772. //compute luminance
  74773. currLum =
  74774. 77 * ((colOrig >> 16) & 0xff) +
  74775. 151 * ((colOrig >> 8) & 0xff) +
  74776. 28 * (colOrig & 0xff);
  74777. lumLeft =
  74778. 77 * ((colLeft >> 16) & 0xff) +
  74779. 151 * ((colLeft >> 8) & 0xff) +
  74780. 28 * (colLeft & 0xff);
  74781. lumRight =
  74782. 77 * ((colRight >> 16) & 0xff) +
  74783. 151 * ((colRight >> 8) & 0xff) +
  74784. 28 * (colRight & 0xff);
  74785. lumUp =
  74786. 77 * ((colUp >> 16) & 0xff) +
  74787. 151 * ((colUp >> 8) & 0xff) +
  74788. 28 * (colUp & 0xff);
  74789. lumDown =
  74790. 77 * ((colDown >> 16) & 0xff) +
  74791. 151 * ((colDown >> 8) & 0xff) +
  74792. 28 * (colDown & 0xff);
  74793. if (lumLeft < currLum) {
  74794. colOut = colLeft;
  74795. currLum = lumLeft;
  74796. }
  74797. if (lumRight < currLum) {
  74798. colOut = colRight;
  74799. currLum = lumRight;
  74800. }
  74801. if (lumUp < currLum) {
  74802. colOut = colUp;
  74803. currLum = lumUp;
  74804. }
  74805. if (lumDown < currLum) {
  74806. colOut = colDown;
  74807. currLum = lumDown;
  74808. }
  74809. out[currIdx++] = colOut;
  74810. }
  74811. }
  74812. Filters._setPixels(pixels, out);
  74813. };
  74814. // BLUR
  74815. // internal kernel stuff for the gaussian blur filter
  74816. var blurRadius;
  74817. var blurKernelSize;
  74818. var blurKernel;
  74819. var blurMult;
  74820. /*
  74821. * Port of https://github.com/processing/processing/blob/
  74822. * main/core/src/processing/core/PImage.java#L1250
  74823. *
  74824. * Optimized code for building the blur kernel.
  74825. * further optimized blur code (approx. 15% for radius=20)
  74826. * bigger speed gains for larger radii (~30%)
  74827. * added support for various image types (ALPHA, RGB, ARGB)
  74828. * [toxi 050728]
  74829. */
  74830. function buildBlurKernel(r) {
  74831. var radius = (r * 3.5) | 0;
  74832. radius = radius < 1 ? 1 : radius < 248 ? radius : 248;
  74833. if (blurRadius !== radius) {
  74834. blurRadius = radius;
  74835. blurKernelSize = (1 + blurRadius) << 1;
  74836. blurKernel = new Int32Array(blurKernelSize);
  74837. blurMult = new Array(blurKernelSize);
  74838. for (var l = 0; l < blurKernelSize; l++) {
  74839. blurMult[l] = new Int32Array(256);
  74840. }
  74841. var bk, bki;
  74842. var bm, bmi;
  74843. for (var i = 1, radiusi = radius - 1; i < radius; i++) {
  74844. blurKernel[radius + i] = blurKernel[radiusi] = bki = radiusi * radiusi;
  74845. bm = blurMult[radius + i];
  74846. bmi = blurMult[radiusi--];
  74847. for (var j = 0; j < 256; j++) {
  74848. bm[j] = bmi[j] = bki * j;
  74849. }
  74850. }
  74851. bk = blurKernel[radius] = radius * radius;
  74852. bm = blurMult[radius];
  74853. for (var k = 0; k < 256; k++) {
  74854. bm[k] = bk * k;
  74855. }
  74856. }
  74857. }
  74858. // Port of https://github.com/processing/processing/blob/
  74859. // main/core/src/processing/core/PImage.java#L1433
  74860. function blurARGB(canvas, radius) {
  74861. var pixels = Filters._toPixels(canvas);
  74862. var width = canvas.width;
  74863. var height = canvas.height;
  74864. var numPackedPixels = width * height;
  74865. var argb = new Int32Array(numPackedPixels);
  74866. for (var j = 0; j < numPackedPixels; j++) {
  74867. argb[j] = Filters._getARGB(pixels, j);
  74868. }
  74869. var sum, cr, cg, cb, ca;
  74870. var read, ri, ym, ymi, bk0;
  74871. var a2 = new Int32Array(numPackedPixels);
  74872. var r2 = new Int32Array(numPackedPixels);
  74873. var g2 = new Int32Array(numPackedPixels);
  74874. var b2 = new Int32Array(numPackedPixels);
  74875. var yi = 0;
  74876. buildBlurKernel(radius);
  74877. var x, y, i;
  74878. var bm;
  74879. for (y = 0; y < height; y++) {
  74880. for (x = 0; x < width; x++) {
  74881. cb = cg = cr = ca = sum = 0;
  74882. read = x - blurRadius;
  74883. if (read < 0) {
  74884. bk0 = -read;
  74885. read = 0;
  74886. } else {
  74887. if (read >= width) {
  74888. break;
  74889. }
  74890. bk0 = 0;
  74891. }
  74892. for (i = bk0; i < blurKernelSize; i++) {
  74893. if (read >= width) {
  74894. break;
  74895. }
  74896. var c = argb[read + yi];
  74897. bm = blurMult[i];
  74898. ca += bm[(c & -16777216) >>> 24];
  74899. cr += bm[(c & 16711680) >> 16];
  74900. cg += bm[(c & 65280) >> 8];
  74901. cb += bm[c & 255];
  74902. sum += blurKernel[i];
  74903. read++;
  74904. }
  74905. ri = yi + x;
  74906. a2[ri] = ca / sum;
  74907. r2[ri] = cr / sum;
  74908. g2[ri] = cg / sum;
  74909. b2[ri] = cb / sum;
  74910. }
  74911. yi += width;
  74912. }
  74913. yi = 0;
  74914. ym = -blurRadius;
  74915. ymi = ym * width;
  74916. for (y = 0; y < height; y++) {
  74917. for (x = 0; x < width; x++) {
  74918. cb = cg = cr = ca = sum = 0;
  74919. if (ym < 0) {
  74920. bk0 = ri = -ym;
  74921. read = x;
  74922. } else {
  74923. if (ym >= height) {
  74924. break;
  74925. }
  74926. bk0 = 0;
  74927. ri = ym;
  74928. read = x + ymi;
  74929. }
  74930. for (i = bk0; i < blurKernelSize; i++) {
  74931. if (ri >= height) {
  74932. break;
  74933. }
  74934. bm = blurMult[i];
  74935. ca += bm[a2[read]];
  74936. cr += bm[r2[read]];
  74937. cg += bm[g2[read]];
  74938. cb += bm[b2[read]];
  74939. sum += blurKernel[i];
  74940. ri++;
  74941. read += width;
  74942. }
  74943. argb[x + yi] =
  74944. ((ca / sum) << 24) | ((cr / sum) << 16) | ((cg / sum) << 8) | (cb / sum);
  74945. }
  74946. yi += width;
  74947. ymi += width;
  74948. ym++;
  74949. }
  74950. Filters._setPixels(pixels, argb);
  74951. }
  74952. Filters.blur = function(canvas, radius) {
  74953. blurARGB(canvas, radius);
  74954. };
  74955. var _default = Filters;
  74956. exports.default = _default;
  74957. },
  74958. {
  74959. 'core-js/modules/es.array.iterator': 174,
  74960. 'core-js/modules/es.object.to-string': 192,
  74961. 'core-js/modules/es.typed-array.copy-within': 212,
  74962. 'core-js/modules/es.typed-array.every': 213,
  74963. 'core-js/modules/es.typed-array.fill': 214,
  74964. 'core-js/modules/es.typed-array.filter': 215,
  74965. 'core-js/modules/es.typed-array.find': 217,
  74966. 'core-js/modules/es.typed-array.find-index': 216,
  74967. 'core-js/modules/es.typed-array.for-each': 220,
  74968. 'core-js/modules/es.typed-array.includes': 221,
  74969. 'core-js/modules/es.typed-array.index-of': 222,
  74970. 'core-js/modules/es.typed-array.int32-array': 224,
  74971. 'core-js/modules/es.typed-array.iterator': 225,
  74972. 'core-js/modules/es.typed-array.join': 226,
  74973. 'core-js/modules/es.typed-array.last-index-of': 227,
  74974. 'core-js/modules/es.typed-array.map': 228,
  74975. 'core-js/modules/es.typed-array.reduce': 230,
  74976. 'core-js/modules/es.typed-array.reduce-right': 229,
  74977. 'core-js/modules/es.typed-array.reverse': 231,
  74978. 'core-js/modules/es.typed-array.set': 232,
  74979. 'core-js/modules/es.typed-array.slice': 233,
  74980. 'core-js/modules/es.typed-array.some': 234,
  74981. 'core-js/modules/es.typed-array.sort': 235,
  74982. 'core-js/modules/es.typed-array.subarray': 236,
  74983. 'core-js/modules/es.typed-array.to-locale-string': 237,
  74984. 'core-js/modules/es.typed-array.to-string': 238,
  74985. 'core-js/modules/es.typed-array.uint8-array': 241
  74986. }
  74987. ],
  74988. 305: [
  74989. function(_dereq_, module, exports) {
  74990. 'use strict';
  74991. _dereq_('core-js/modules/es.symbol');
  74992. _dereq_('core-js/modules/es.symbol.description');
  74993. _dereq_('core-js/modules/es.symbol.iterator');
  74994. _dereq_('core-js/modules/es.array.concat');
  74995. _dereq_('core-js/modules/es.array.filter');
  74996. _dereq_('core-js/modules/es.array.from');
  74997. _dereq_('core-js/modules/es.array.iterator');
  74998. _dereq_('core-js/modules/es.array.map');
  74999. _dereq_('core-js/modules/es.array.slice');
  75000. _dereq_('core-js/modules/es.object.keys');
  75001. _dereq_('core-js/modules/es.object.to-string');
  75002. _dereq_('core-js/modules/es.regexp.exec');
  75003. _dereq_('core-js/modules/es.regexp.to-string');
  75004. _dereq_('core-js/modules/es.set');
  75005. _dereq_('core-js/modules/es.string.iterator');
  75006. _dereq_('core-js/modules/es.string.replace');
  75007. _dereq_('core-js/modules/es.string.split');
  75008. _dereq_('core-js/modules/es.typed-array.uint8-array');
  75009. _dereq_('core-js/modules/es.typed-array.uint32-array');
  75010. _dereq_('core-js/modules/es.typed-array.copy-within');
  75011. _dereq_('core-js/modules/es.typed-array.every');
  75012. _dereq_('core-js/modules/es.typed-array.fill');
  75013. _dereq_('core-js/modules/es.typed-array.filter');
  75014. _dereq_('core-js/modules/es.typed-array.find');
  75015. _dereq_('core-js/modules/es.typed-array.find-index');
  75016. _dereq_('core-js/modules/es.typed-array.for-each');
  75017. _dereq_('core-js/modules/es.typed-array.includes');
  75018. _dereq_('core-js/modules/es.typed-array.index-of');
  75019. _dereq_('core-js/modules/es.typed-array.iterator');
  75020. _dereq_('core-js/modules/es.typed-array.join');
  75021. _dereq_('core-js/modules/es.typed-array.last-index-of');
  75022. _dereq_('core-js/modules/es.typed-array.map');
  75023. _dereq_('core-js/modules/es.typed-array.reduce');
  75024. _dereq_('core-js/modules/es.typed-array.reduce-right');
  75025. _dereq_('core-js/modules/es.typed-array.reverse');
  75026. _dereq_('core-js/modules/es.typed-array.set');
  75027. _dereq_('core-js/modules/es.typed-array.slice');
  75028. _dereq_('core-js/modules/es.typed-array.some');
  75029. _dereq_('core-js/modules/es.typed-array.sort');
  75030. _dereq_('core-js/modules/es.typed-array.subarray');
  75031. _dereq_('core-js/modules/es.typed-array.to-locale-string');
  75032. _dereq_('core-js/modules/es.typed-array.to-string');
  75033. _dereq_('core-js/modules/web.dom-collections.iterator');
  75034. Object.defineProperty(exports, '__esModule', { value: true });
  75035. exports.default = void 0;
  75036. var _main = _interopRequireDefault(_dereq_('../core/main'));
  75037. var _omggif = _interopRequireDefault(_dereq_('omggif'));
  75038. function _interopRequireDefault(obj) {
  75039. return obj && obj.__esModule ? obj : { default: obj };
  75040. }
  75041. function _toConsumableArray(arr) {
  75042. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
  75043. }
  75044. function _nonIterableSpread() {
  75045. throw new TypeError('Invalid attempt to spread non-iterable instance');
  75046. }
  75047. function _iterableToArray(iter) {
  75048. if (
  75049. Symbol.iterator in Object(iter) ||
  75050. Object.prototype.toString.call(iter) === '[object Arguments]'
  75051. )
  75052. return Array.from(iter);
  75053. }
  75054. function _arrayWithoutHoles(arr) {
  75055. if (Array.isArray(arr)) {
  75056. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  75057. arr2[i] = arr[i];
  75058. }
  75059. return arr2;
  75060. }
  75061. }
  75062. /**
  75063. * Creates a new <a href="#/p5.Image">p5.Image</a> (the datatype for storing images). This provides a
  75064. * fresh buffer of pixels to play with. Set the size of the buffer with the
  75065. * width and height parameters.
  75066. *
  75067. * .<a href="#/p5.Image/pixels">pixels</a> gives access to an array containing the values for all the pixels
  75068. * in the display window.
  75069. * These values are numbers. This array is the size (including an appropriate
  75070. * factor for the <a href="#/p5/pixelDensity">pixelDensity</a>) of the display window x4,
  75071. * representing the R, G, B, A values in order for each pixel, moving from
  75072. * left to right across each row, then down each column. See .<a href="#/p5.Image/pixels">pixels</a> for
  75073. * more info. It may also be simpler to use <a href="#/p5.Image/set">set()</a> or <a href="#/p5.Image/get">get()</a>.
  75074. *
  75075. * Before accessing the pixels of an image, the data must loaded with the
  75076. * <a href="#/p5.Image/loadPixels">loadPixels()</a> function. After the array data has been modified, the
  75077. * <a href="#/p5.Image/updatePixels">updatePixels()</a> function must be run to update the changes.
  75078. *
  75079. * @method createImage
  75080. * @param {Integer} width width in pixels
  75081. * @param {Integer} height height in pixels
  75082. * @return {p5.Image} the <a href="#/p5.Image">p5.Image</a> object
  75083. * @example
  75084. * <div>
  75085. * <code>
  75086. * let img = createImage(66, 66);
  75087. * img.loadPixels();
  75088. * for (let i = 0; i < img.width; i++) {
  75089. * for (let j = 0; j < img.height; j++) {
  75090. * img.set(i, j, color(0, 90, 102));
  75091. * }
  75092. * }
  75093. * img.updatePixels();
  75094. * image(img, 17, 17);
  75095. * </code>
  75096. * </div>
  75097. *
  75098. * <div>
  75099. * <code>
  75100. * let img = createImage(66, 66);
  75101. * img.loadPixels();
  75102. * for (let i = 0; i < img.width; i++) {
  75103. * for (let j = 0; j < img.height; j++) {
  75104. * img.set(i, j, color(0, 90, 102, (i % img.width) * 2));
  75105. * }
  75106. * }
  75107. * img.updatePixels();
  75108. * image(img, 17, 17);
  75109. * image(img, 34, 34);
  75110. * </code>
  75111. * </div>
  75112. *
  75113. * <div>
  75114. * <code>
  75115. * let pink = color(255, 102, 204);
  75116. * let img = createImage(66, 66);
  75117. * img.loadPixels();
  75118. * let d = pixelDensity();
  75119. * let halfImage = 4 * (img.width * d) * (img.height / 2 * d);
  75120. * for (let i = 0; i < halfImage; i += 4) {
  75121. * img.pixels[i] = red(pink);
  75122. * img.pixels[i + 1] = green(pink);
  75123. * img.pixels[i + 2] = blue(pink);
  75124. * img.pixels[i + 3] = alpha(pink);
  75125. * }
  75126. * img.updatePixels();
  75127. * image(img, 17, 17);
  75128. * </code>
  75129. * </div>
  75130. *
  75131. * @alt
  75132. * 66x66 dark turquoise rect in center of canvas.
  75133. * 2 gradated dark turquoise rects fade left. 1 center 1 bottom right of canvas
  75134. * no image displayed
  75135. */
  75136. _main.default.prototype.createImage = function(width, height) {
  75137. _main.default._validateParameters('createImage', arguments);
  75138. return new _main.default.Image(width, height);
  75139. };
  75140. /**
  75141. * Save the current canvas as an image. The browser will either save the
  75142. * file immediately, or prompt the user with a dialogue window.
  75143. *
  75144. * @method saveCanvas
  75145. * @param {p5.Element|HTMLCanvasElement} selectedCanvas a variable
  75146. * representing a specific html5 canvas (optional)
  75147. * @param {String} [filename]
  75148. * @param {String} [extension] 'jpg' or 'png'
  75149. *
  75150. * @example
  75151. * <div class='norender notest'><code>
  75152. * function setup() {
  75153. * let c = createCanvas(100, 100);
  75154. * background(255, 0, 0);
  75155. * saveCanvas(c, 'myCanvas', 'jpg');
  75156. * }
  75157. * </code></div>
  75158. * <div class='norender notest'><code>
  75159. * // note that this example has the same result as above
  75160. * // if no canvas is specified, defaults to main canvas
  75161. * function setup() {
  75162. * let c = createCanvas(100, 100);
  75163. * background(255, 0, 0);
  75164. * saveCanvas('myCanvas', 'jpg');
  75165. *
  75166. * // all of the following are valid
  75167. * saveCanvas(c, 'myCanvas', 'jpg');
  75168. * saveCanvas(c, 'myCanvas.jpg');
  75169. * saveCanvas(c, 'myCanvas');
  75170. * saveCanvas(c);
  75171. * saveCanvas('myCanvas', 'png');
  75172. * saveCanvas('myCanvas');
  75173. * saveCanvas();
  75174. * }
  75175. * </code></div>
  75176. *
  75177. * @alt
  75178. * no image displayed
  75179. * no image displayed
  75180. * no image displayed
  75181. */
  75182. /**
  75183. * @method saveCanvas
  75184. * @param {String} [filename]
  75185. * @param {String} [extension]
  75186. */
  75187. _main.default.prototype.saveCanvas = function() {
  75188. _main.default._validateParameters('saveCanvas', arguments);
  75189. // copy arguments to array
  75190. var args = [].slice.call(arguments);
  75191. var htmlCanvas, filename, extension;
  75192. if (arguments[0] instanceof HTMLCanvasElement) {
  75193. htmlCanvas = arguments[0];
  75194. args.shift();
  75195. } else if (arguments[0] instanceof _main.default.Element) {
  75196. htmlCanvas = arguments[0].elt;
  75197. args.shift();
  75198. } else {
  75199. htmlCanvas = this._curElement && this._curElement.elt;
  75200. }
  75201. if (args.length >= 1) {
  75202. filename = args[0];
  75203. }
  75204. if (args.length >= 2) {
  75205. extension = args[1];
  75206. }
  75207. extension =
  75208. extension ||
  75209. _main.default.prototype._checkFileExtension(filename, extension)[1] ||
  75210. 'png';
  75211. var mimeType;
  75212. switch (extension) {
  75213. default:
  75214. //case 'png':
  75215. mimeType = 'image/png';
  75216. break;
  75217. case 'jpeg':
  75218. case 'jpg':
  75219. mimeType = 'image/jpeg';
  75220. break;
  75221. }
  75222. htmlCanvas.toBlob(function(blob) {
  75223. _main.default.prototype.downloadFile(blob, filename, extension);
  75224. }, mimeType);
  75225. };
  75226. _main.default.prototype.saveGif = function(pImg, filename) {
  75227. var props = pImg.gifProperties;
  75228. //convert loopLimit back into Netscape Block formatting
  75229. var loopLimit = props.loopLimit;
  75230. if (loopLimit === 1) {
  75231. loopLimit = null;
  75232. } else if (loopLimit === null) {
  75233. loopLimit = 0;
  75234. }
  75235. var buffer = new Uint8Array(pImg.width * pImg.height * props.numFrames);
  75236. var allFramesPixelColors = [];
  75237. // Used to determine the occurrence of unique palettes and the frames
  75238. // which use them
  75239. var paletteFreqsAndFrames = {};
  75240. // Pass 1:
  75241. //loop over frames and get the frequency of each palette
  75242. for (var i = 0; i < props.numFrames; i++) {
  75243. var paletteSet = new Set();
  75244. var data = props.frames[i].image.data;
  75245. var dataLength = data.length;
  75246. // The color for each pixel in this frame ( for easier lookup later )
  75247. var pixelColors = new Uint32Array(pImg.width * pImg.height);
  75248. for (var j = 0, k = 0; j < dataLength; j += 4, k++) {
  75249. var r = data[j + 0];
  75250. var g = data[j + 1];
  75251. var b = data[j + 2];
  75252. var color = (r << 16) | (g << 8) | (b << 0);
  75253. paletteSet.add(color);
  75254. // What color does this pixel have in this frame ?
  75255. pixelColors[k] = color;
  75256. }
  75257. // A way to put use the entire palette as an object key
  75258. var paletteStr = _toConsumableArray(paletteSet)
  75259. .sort()
  75260. .toString();
  75261. if (paletteFreqsAndFrames[paletteStr] === undefined) {
  75262. paletteFreqsAndFrames[paletteStr] = { freq: 1, frames: [i] };
  75263. } else {
  75264. paletteFreqsAndFrames[paletteStr].freq += 1;
  75265. paletteFreqsAndFrames[paletteStr].frames.push(i);
  75266. }
  75267. allFramesPixelColors.push(pixelColors);
  75268. }
  75269. var framesUsingGlobalPalette = [];
  75270. // Now to build the global palette
  75271. // Sort all the unique palettes in descending order of their occurence
  75272. var palettesSortedByFreq = Object.keys(paletteFreqsAndFrames).sort(function(
  75273. a,
  75274. b
  75275. ) {
  75276. return paletteFreqsAndFrames[b].freq - paletteFreqsAndFrames[a].freq;
  75277. });
  75278. // The initial global palette is the one with the most occurence
  75279. var globalPalette = palettesSortedByFreq[0].split(',').map(function(a) {
  75280. return parseInt(a);
  75281. });
  75282. framesUsingGlobalPalette = framesUsingGlobalPalette.concat(
  75283. paletteFreqsAndFrames[globalPalette].frames
  75284. );
  75285. var globalPaletteSet = new Set(globalPalette);
  75286. // Build a more complete global palette
  75287. // Iterate over the remaining palettes in the order of
  75288. // their occurence and see if the colors in this palette which are
  75289. // not in the global palette can be added there, while keeping the length
  75290. // of the global palette <= 256
  75291. for (var _i = 1; _i < palettesSortedByFreq.length; _i++) {
  75292. var palette = palettesSortedByFreq[_i].split(',').map(function(a) {
  75293. return parseInt(a);
  75294. });
  75295. var difference = palette.filter(function(x) {
  75296. return !globalPaletteSet.has(x);
  75297. });
  75298. if (globalPalette.length + difference.length <= 256) {
  75299. for (var _j = 0; _j < difference.length; _j++) {
  75300. globalPalette.push(difference[_j]);
  75301. globalPaletteSet.add(difference[_j]);
  75302. }
  75303. // All frames using this palette now use the global palette
  75304. framesUsingGlobalPalette = framesUsingGlobalPalette.concat(
  75305. paletteFreqsAndFrames[palettesSortedByFreq[_i]].frames
  75306. );
  75307. }
  75308. }
  75309. framesUsingGlobalPalette = new Set(framesUsingGlobalPalette);
  75310. // Build a lookup table of the index of each color in the global palette
  75311. // Maps a color to its index
  75312. var globalIndicesLookup = {};
  75313. for (var _i2 = 0; _i2 < globalPalette.length; _i2++) {
  75314. if (!globalIndicesLookup[globalPalette[_i2]]) {
  75315. globalIndicesLookup[globalPalette[_i2]] = _i2;
  75316. }
  75317. }
  75318. // force palette to be power of 2
  75319. var powof2 = 1;
  75320. while (powof2 < globalPalette.length) {
  75321. powof2 <<= 1;
  75322. }
  75323. globalPalette.length = powof2;
  75324. // global opts
  75325. var opts = {
  75326. loop: loopLimit,
  75327. palette: new Uint32Array(globalPalette)
  75328. };
  75329. var gifWriter = new _omggif.default.GifWriter(
  75330. buffer,
  75331. pImg.width,
  75332. pImg.height,
  75333. opts
  75334. );
  75335. var previousFrame = {};
  75336. // Pass 2
  75337. // Determine if the frame needs a local palette
  75338. // Also apply transparency optimization. This function will often blow up
  75339. // the size of a GIF if not for transparency. If a pixel in one frame has
  75340. // the same color in the previous frame, that pixel can be marked as
  75341. // transparent. We decide one particular color as transparent and make all
  75342. // transparent pixels take this color. This helps in later in compression.
  75343. var _loop = function _loop(_i3) {
  75344. var localPaletteRequired = !framesUsingGlobalPalette.has(_i3);
  75345. var palette = localPaletteRequired ? [] : globalPalette;
  75346. var pixelPaletteIndex = new Uint8Array(pImg.width * pImg.height);
  75347. // Lookup table mapping color to its indices
  75348. var colorIndicesLookup = {};
  75349. // All the colors that cannot be marked transparent in this frame
  75350. var cannotBeTransparent = new Set();
  75351. for (var _k = 0; _k < allFramesPixelColors[_i3].length; _k++) {
  75352. var _color = allFramesPixelColors[_i3][_k];
  75353. if (localPaletteRequired) {
  75354. if (colorIndicesLookup[_color] === undefined) {
  75355. colorIndicesLookup[_color] = palette.length;
  75356. palette.push(_color);
  75357. }
  75358. pixelPaletteIndex[_k] = colorIndicesLookup[_color];
  75359. } else {
  75360. pixelPaletteIndex[_k] = globalIndicesLookup[_color];
  75361. }
  75362. if (_i3 > 0) {
  75363. // If even one pixel of this color has changed in this frame
  75364. // from the previous frame, we cannot mark it as transparent
  75365. if (allFramesPixelColors[_i3 - 1][_k] !== _color) {
  75366. cannotBeTransparent.add(_color);
  75367. }
  75368. }
  75369. }
  75370. var frameOpts = {};
  75371. // Transparency optimization
  75372. var canBeTransparent = palette.filter(function(a) {
  75373. return !cannotBeTransparent.has(a);
  75374. });
  75375. if (canBeTransparent.length > 0) {
  75376. // Select a color to mark as transparent
  75377. var transparent = canBeTransparent[0];
  75378. var transparentIndex = localPaletteRequired
  75379. ? colorIndicesLookup[transparent]
  75380. : globalIndicesLookup[transparent];
  75381. if (_i3 > 0) {
  75382. for (var _k2 = 0; _k2 < allFramesPixelColors[_i3].length; _k2++) {
  75383. // If this pixel in this frame has the same color in previous frame
  75384. if (
  75385. allFramesPixelColors[_i3 - 1][_k2] === allFramesPixelColors[_i3][_k2]
  75386. ) {
  75387. pixelPaletteIndex[_k2] = transparentIndex;
  75388. }
  75389. }
  75390. frameOpts.transparent = transparentIndex;
  75391. // If this frame has any transparency, do not dispose the previous frame
  75392. previousFrame.frameOpts.disposal = 1;
  75393. }
  75394. }
  75395. frameOpts.delay = props.frames[_i3].delay / 10; // Move timing back into GIF formatting
  75396. if (localPaletteRequired) {
  75397. // force palette to be power of 2
  75398. var _powof = 1;
  75399. while (_powof < palette.length) {
  75400. _powof <<= 1;
  75401. }
  75402. palette.length = _powof;
  75403. frameOpts.palette = new Uint32Array(palette);
  75404. }
  75405. if (_i3 > 0) {
  75406. // add the frame that came before the current one
  75407. gifWriter.addFrame(
  75408. 0,
  75409. 0,
  75410. pImg.width,
  75411. pImg.height,
  75412. previousFrame.pixelPaletteIndex,
  75413. previousFrame.frameOpts
  75414. );
  75415. }
  75416. // previous frame object should now have details of this frame
  75417. previousFrame = {
  75418. pixelPaletteIndex: pixelPaletteIndex,
  75419. frameOpts: frameOpts
  75420. };
  75421. };
  75422. for (var _i3 = 0; _i3 < props.numFrames; _i3++) {
  75423. _loop(_i3);
  75424. }
  75425. previousFrame.frameOpts.disposal = 1;
  75426. // add the last frame
  75427. gifWriter.addFrame(
  75428. 0,
  75429. 0,
  75430. pImg.width,
  75431. pImg.height,
  75432. previousFrame.pixelPaletteIndex,
  75433. previousFrame.frameOpts
  75434. );
  75435. var extension = 'gif';
  75436. var blob = new Blob([buffer.slice(0, gifWriter.end())], {
  75437. type: 'image/gif'
  75438. });
  75439. _main.default.prototype.downloadFile(blob, filename, extension);
  75440. };
  75441. /**
  75442. * Capture a sequence of frames that can be used to create a movie.
  75443. * Accepts a callback. For example, you may wish to send the frames
  75444. * to a server where they can be stored or converted into a movie.
  75445. * If no callback is provided, the browser will pop up save dialogues in an
  75446. * attempt to download all of the images that have just been created. With the
  75447. * callback provided the image data isn't saved by default but instead passed
  75448. * as an argument to the callback function as an array of objects, with the
  75449. * size of array equal to the total number of frames.
  75450. *
  75451. * Note that <a href="#/p5.Image/saveFrames">saveFrames()</a> will only save the first 15 frames of an animation.
  75452. * To export longer animations, you might look into a library like
  75453. * <a href="https://github.com/spite/ccapture.js/">ccapture.js</a>.
  75454. *
  75455. * @method saveFrames
  75456. * @param {String} filename
  75457. * @param {String} extension 'jpg' or 'png'
  75458. * @param {Number} duration Duration in seconds to save the frames for.
  75459. * @param {Number} framerate Framerate to save the frames in.
  75460. * @param {function(Array)} [callback] A callback function that will be executed
  75461. to handle the image data. This function
  75462. should accept an array as argument. The
  75463. array will contain the specified number of
  75464. frames of objects. Each object has three
  75465. properties: imageData - an
  75466. image/octet-stream, filename and extension.
  75467. * @example
  75468. * <div><code>
  75469. * function draw() {
  75470. * background(mouseX);
  75471. * }
  75472. *
  75473. * function mousePressed() {
  75474. * saveFrames('out', 'png', 1, 25, data => {
  75475. * print(data);
  75476. * });
  75477. * }
  75478. </code></div>
  75479. *
  75480. * @alt
  75481. * canvas background goes from light to dark with mouse x.
  75482. */
  75483. _main.default.prototype.saveFrames = function(
  75484. fName,
  75485. ext,
  75486. _duration,
  75487. _fps,
  75488. callback
  75489. ) {
  75490. _main.default._validateParameters('saveFrames', arguments);
  75491. var duration = _duration || 3;
  75492. duration = _main.default.prototype.constrain(duration, 0, 15);
  75493. duration = duration * 1000;
  75494. var fps = _fps || 15;
  75495. fps = _main.default.prototype.constrain(fps, 0, 22);
  75496. var count = 0;
  75497. var makeFrame = _main.default.prototype._makeFrame;
  75498. var cnv = this._curElement.elt;
  75499. var frames = [];
  75500. var frameFactory = setInterval(function() {
  75501. frames.push(makeFrame(fName + count, ext, cnv));
  75502. count++;
  75503. }, 1000 / fps);
  75504. setTimeout(function() {
  75505. clearInterval(frameFactory);
  75506. if (callback) {
  75507. callback(frames);
  75508. } else {
  75509. var _iteratorNormalCompletion = true;
  75510. var _didIteratorError = false;
  75511. var _iteratorError = undefined;
  75512. try {
  75513. for (
  75514. var _iterator = frames[Symbol.iterator](), _step;
  75515. !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
  75516. _iteratorNormalCompletion = true
  75517. ) {
  75518. var f = _step.value;
  75519. _main.default.prototype.downloadFile(f.imageData, f.filename, f.ext);
  75520. }
  75521. } catch (err) {
  75522. _didIteratorError = true;
  75523. _iteratorError = err;
  75524. } finally {
  75525. try {
  75526. if (!_iteratorNormalCompletion && _iterator.return != null) {
  75527. _iterator.return();
  75528. }
  75529. } finally {
  75530. if (_didIteratorError) {
  75531. throw _iteratorError;
  75532. }
  75533. }
  75534. }
  75535. }
  75536. frames = []; // clear frames
  75537. }, duration + 0.01);
  75538. };
  75539. _main.default.prototype._makeFrame = function(filename, extension, _cnv) {
  75540. var cnv;
  75541. if (this) {
  75542. cnv = this._curElement.elt;
  75543. } else {
  75544. cnv = _cnv;
  75545. }
  75546. var mimeType;
  75547. if (!extension) {
  75548. extension = 'png';
  75549. mimeType = 'image/png';
  75550. } else {
  75551. switch (extension.toLowerCase()) {
  75552. case 'png':
  75553. mimeType = 'image/png';
  75554. break;
  75555. case 'jpeg':
  75556. mimeType = 'image/jpeg';
  75557. break;
  75558. case 'jpg':
  75559. mimeType = 'image/jpeg';
  75560. break;
  75561. default:
  75562. mimeType = 'image/png';
  75563. break;
  75564. }
  75565. }
  75566. var downloadMime = 'image/octet-stream';
  75567. var imageData = cnv.toDataURL(mimeType);
  75568. imageData = imageData.replace(mimeType, downloadMime);
  75569. var thisFrame = {};
  75570. thisFrame.imageData = imageData;
  75571. thisFrame.filename = filename;
  75572. thisFrame.ext = extension;
  75573. return thisFrame;
  75574. };
  75575. var _default = _main.default;
  75576. exports.default = _default;
  75577. },
  75578. {
  75579. '../core/main': 283,
  75580. 'core-js/modules/es.array.concat': 166,
  75581. 'core-js/modules/es.array.filter': 169,
  75582. 'core-js/modules/es.array.from': 171,
  75583. 'core-js/modules/es.array.iterator': 174,
  75584. 'core-js/modules/es.array.map': 177,
  75585. 'core-js/modules/es.array.slice': 178,
  75586. 'core-js/modules/es.object.keys': 191,
  75587. 'core-js/modules/es.object.to-string': 192,
  75588. 'core-js/modules/es.regexp.exec': 196,
  75589. 'core-js/modules/es.regexp.to-string': 197,
  75590. 'core-js/modules/es.set': 198,
  75591. 'core-js/modules/es.string.iterator': 201,
  75592. 'core-js/modules/es.string.replace': 204,
  75593. 'core-js/modules/es.string.split': 206,
  75594. 'core-js/modules/es.symbol': 211,
  75595. 'core-js/modules/es.symbol.description': 209,
  75596. 'core-js/modules/es.symbol.iterator': 210,
  75597. 'core-js/modules/es.typed-array.copy-within': 212,
  75598. 'core-js/modules/es.typed-array.every': 213,
  75599. 'core-js/modules/es.typed-array.fill': 214,
  75600. 'core-js/modules/es.typed-array.filter': 215,
  75601. 'core-js/modules/es.typed-array.find': 217,
  75602. 'core-js/modules/es.typed-array.find-index': 216,
  75603. 'core-js/modules/es.typed-array.for-each': 220,
  75604. 'core-js/modules/es.typed-array.includes': 221,
  75605. 'core-js/modules/es.typed-array.index-of': 222,
  75606. 'core-js/modules/es.typed-array.iterator': 225,
  75607. 'core-js/modules/es.typed-array.join': 226,
  75608. 'core-js/modules/es.typed-array.last-index-of': 227,
  75609. 'core-js/modules/es.typed-array.map': 228,
  75610. 'core-js/modules/es.typed-array.reduce': 230,
  75611. 'core-js/modules/es.typed-array.reduce-right': 229,
  75612. 'core-js/modules/es.typed-array.reverse': 231,
  75613. 'core-js/modules/es.typed-array.set': 232,
  75614. 'core-js/modules/es.typed-array.slice': 233,
  75615. 'core-js/modules/es.typed-array.some': 234,
  75616. 'core-js/modules/es.typed-array.sort': 235,
  75617. 'core-js/modules/es.typed-array.subarray': 236,
  75618. 'core-js/modules/es.typed-array.to-locale-string': 237,
  75619. 'core-js/modules/es.typed-array.to-string': 238,
  75620. 'core-js/modules/es.typed-array.uint32-array': 240,
  75621. 'core-js/modules/es.typed-array.uint8-array': 241,
  75622. 'core-js/modules/web.dom-collections.iterator': 244,
  75623. omggif: 257
  75624. }
  75625. ],
  75626. 306: [
  75627. function(_dereq_, module, exports) {
  75628. 'use strict';
  75629. function _typeof(obj) {
  75630. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  75631. _typeof = function _typeof(obj) {
  75632. return typeof obj;
  75633. };
  75634. } else {
  75635. _typeof = function _typeof(obj) {
  75636. return obj &&
  75637. typeof Symbol === 'function' &&
  75638. obj.constructor === Symbol &&
  75639. obj !== Symbol.prototype
  75640. ? 'symbol'
  75641. : typeof obj;
  75642. };
  75643. }
  75644. return _typeof(obj);
  75645. }
  75646. _dereq_('core-js/modules/es.array.includes');
  75647. _dereq_('core-js/modules/es.array.index-of');
  75648. _dereq_('core-js/modules/es.array.iterator');
  75649. _dereq_('core-js/modules/es.array.slice');
  75650. _dereq_('core-js/modules/es.object.to-string');
  75651. _dereq_('core-js/modules/es.promise');
  75652. _dereq_('core-js/modules/es.string.includes');
  75653. _dereq_('core-js/modules/es.typed-array.uint8-array');
  75654. _dereq_('core-js/modules/es.typed-array.uint8-clamped-array');
  75655. _dereq_('core-js/modules/es.typed-array.copy-within');
  75656. _dereq_('core-js/modules/es.typed-array.every');
  75657. _dereq_('core-js/modules/es.typed-array.fill');
  75658. _dereq_('core-js/modules/es.typed-array.filter');
  75659. _dereq_('core-js/modules/es.typed-array.find');
  75660. _dereq_('core-js/modules/es.typed-array.find-index');
  75661. _dereq_('core-js/modules/es.typed-array.for-each');
  75662. _dereq_('core-js/modules/es.typed-array.includes');
  75663. _dereq_('core-js/modules/es.typed-array.index-of');
  75664. _dereq_('core-js/modules/es.typed-array.iterator');
  75665. _dereq_('core-js/modules/es.typed-array.join');
  75666. _dereq_('core-js/modules/es.typed-array.last-index-of');
  75667. _dereq_('core-js/modules/es.typed-array.map');
  75668. _dereq_('core-js/modules/es.typed-array.reduce');
  75669. _dereq_('core-js/modules/es.typed-array.reduce-right');
  75670. _dereq_('core-js/modules/es.typed-array.reverse');
  75671. _dereq_('core-js/modules/es.typed-array.set');
  75672. _dereq_('core-js/modules/es.typed-array.slice');
  75673. _dereq_('core-js/modules/es.typed-array.some');
  75674. _dereq_('core-js/modules/es.typed-array.sort');
  75675. _dereq_('core-js/modules/es.typed-array.subarray');
  75676. _dereq_('core-js/modules/es.typed-array.to-locale-string');
  75677. _dereq_('core-js/modules/es.typed-array.to-string');
  75678. Object.defineProperty(exports, '__esModule', { value: true });
  75679. exports.default = void 0;
  75680. var _main = _interopRequireDefault(_dereq_('../core/main'));
  75681. var _filters = _interopRequireDefault(_dereq_('./filters'));
  75682. var _helpers = _interopRequireDefault(_dereq_('../core/helpers'));
  75683. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  75684. var _omggif = _interopRequireDefault(_dereq_('omggif'));
  75685. _dereq_('../core/friendly_errors/validate_params');
  75686. _dereq_('../core/friendly_errors/file_errors');
  75687. _dereq_('../core/friendly_errors/fes_core');
  75688. function _getRequireWildcardCache() {
  75689. if (typeof WeakMap !== 'function') return null;
  75690. var cache = new WeakMap();
  75691. _getRequireWildcardCache = function _getRequireWildcardCache() {
  75692. return cache;
  75693. };
  75694. return cache;
  75695. }
  75696. function _interopRequireWildcard(obj) {
  75697. if (obj && obj.__esModule) {
  75698. return obj;
  75699. }
  75700. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  75701. return { default: obj };
  75702. }
  75703. var cache = _getRequireWildcardCache();
  75704. if (cache && cache.has(obj)) {
  75705. return cache.get(obj);
  75706. }
  75707. var newObj = {};
  75708. var hasPropertyDescriptor =
  75709. Object.defineProperty && Object.getOwnPropertyDescriptor;
  75710. for (var key in obj) {
  75711. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  75712. var desc = hasPropertyDescriptor
  75713. ? Object.getOwnPropertyDescriptor(obj, key)
  75714. : null;
  75715. if (desc && (desc.get || desc.set)) {
  75716. Object.defineProperty(newObj, key, desc);
  75717. } else {
  75718. newObj[key] = obj[key];
  75719. }
  75720. }
  75721. }
  75722. newObj.default = obj;
  75723. if (cache) {
  75724. cache.set(obj, newObj);
  75725. }
  75726. return newObj;
  75727. }
  75728. function _interopRequireDefault(obj) {
  75729. return obj && obj.__esModule ? obj : { default: obj };
  75730. }
  75731. /**
  75732. * @module Image
  75733. * @submodule Loading & Displaying
  75734. * @for p5
  75735. * @requires core
  75736. */ /**
  75737. * Loads an image from a path and creates a <a href="#/p5.Image">p5.Image</a> from it.
  75738. *
  75739. * The image may not be immediately available for rendering.
  75740. * If you want to ensure that the image is ready before doing
  75741. * anything with it, place the <a href="#/p5/loadImage">loadImage()</a> call in <a href="#/p5/preload">preload()</a>.
  75742. * You may also supply a callback function to handle the image when it's ready.
  75743. *
  75744. * The path to the image should be relative to the HTML file
  75745. * that links in your sketch. Loading an image from a URL or other
  75746. * remote location may be blocked due to your browser's built-in
  75747. * security.
  75748. * You can also pass in a string of a base64 encoded image as an alternative to the file path.
  75749. * Remember to add "data:image/png;base64," in front of the string.
  75750. *
  75751. * @method loadImage
  75752. * @param {String} path Path of the image to be loaded
  75753. * @param {function(p5.Image)} [successCallback] Function to be called once
  75754. * the image is loaded. Will be passed the
  75755. * <a href="#/p5.Image">p5.Image</a>.
  75756. * @param {function(Event)} [failureCallback] called with event error if
  75757. * the image fails to load.
  75758. * @return {p5.Image} the <a href="#/p5.Image">p5.Image</a> object
  75759. * @example
  75760. * <div>
  75761. * <code>
  75762. * let img;
  75763. * function preload() {
  75764. * img = loadImage('assets/laDefense.jpg');
  75765. * }
  75766. * function setup() {
  75767. * image(img, 0, 0);
  75768. * }
  75769. * </code>
  75770. * </div>
  75771. * <div>
  75772. * <code>
  75773. * function setup() {
  75774. * // here we use a callback to display the image after loading
  75775. * loadImage('assets/laDefense.jpg', img => {
  75776. * image(img, 0, 0);
  75777. * });
  75778. * }
  75779. * </code>
  75780. * </div>
  75781. *
  75782. * @alt
  75783. * image of the underside of a white umbrella and grided ceililng above
  75784. * image of the underside of a white umbrella and grided ceililng above
  75785. */ _main.default.prototype.loadImage = function(
  75786. path,
  75787. successCallback,
  75788. failureCallback
  75789. ) {
  75790. _main.default._validateParameters('loadImage', arguments);
  75791. var pImg = new _main.default.Image(1, 1, this);
  75792. var self = this;
  75793. var req = new Request(path, {
  75794. method: 'GET',
  75795. mode: 'cors'
  75796. });
  75797. fetch(path, req)
  75798. .then(function(response) {
  75799. // GIF section
  75800. var contentType = response.headers.get('content-type');
  75801. if (contentType === null) {
  75802. console.warn(
  75803. 'The image you loaded does not have a Content-Type header. If you are using the online editor consider reuploading the asset.'
  75804. );
  75805. }
  75806. if (contentType && contentType.includes('image/gif')) {
  75807. response.arrayBuffer().then(
  75808. function(arrayBuffer) {
  75809. if (arrayBuffer) {
  75810. var byteArray = new Uint8Array(arrayBuffer);
  75811. _createGif(
  75812. byteArray,
  75813. pImg,
  75814. successCallback,
  75815. failureCallback,
  75816. function(pImg) {
  75817. self._decrementPreload();
  75818. }.bind(self)
  75819. );
  75820. }
  75821. },
  75822. function(e) {
  75823. if (typeof failureCallback === 'function') {
  75824. failureCallback(e);
  75825. } else {
  75826. console.error(e);
  75827. }
  75828. }
  75829. );
  75830. } else {
  75831. // Non-GIF Section
  75832. var img = new Image();
  75833. img.onload = function() {
  75834. pImg.width = pImg.canvas.width = img.width;
  75835. pImg.height = pImg.canvas.height = img.height;
  75836. // Draw the image into the backing canvas of the p5.Image
  75837. pImg.drawingContext.drawImage(img, 0, 0);
  75838. pImg.modified = true;
  75839. if (typeof successCallback === 'function') {
  75840. successCallback(pImg);
  75841. }
  75842. self._decrementPreload();
  75843. };
  75844. img.onerror = function(e) {
  75845. _main.default._friendlyFileLoadError(0, img.src);
  75846. if (typeof failureCallback === 'function') {
  75847. failureCallback(e);
  75848. } else {
  75849. console.error(e);
  75850. }
  75851. };
  75852. // Set crossOrigin in case image is served with CORS headers.
  75853. // This will let us draw to the canvas without tainting it.
  75854. // See https://developer.mozilla.org/en-US/docs/HTML/CORS_Enabled_Image
  75855. // When using data-uris the file will be loaded locally
  75856. // so we don't need to worry about crossOrigin with base64 file types.
  75857. if (path.indexOf('data:image/') !== 0) {
  75858. img.crossOrigin = 'Anonymous';
  75859. }
  75860. // start loading the image
  75861. img.src = path;
  75862. }
  75863. pImg.modified = true;
  75864. })
  75865. .catch(function(e) {
  75866. _main.default._friendlyFileLoadError(0, path);
  75867. if (typeof failureCallback === 'function') {
  75868. failureCallback(e);
  75869. } else {
  75870. console.error(e);
  75871. }
  75872. });
  75873. return pImg;
  75874. };
  75875. /**
  75876. * Helper function for loading GIF-based images
  75877. */
  75878. function _createGif(
  75879. arrayBuffer,
  75880. pImg,
  75881. successCallback,
  75882. failureCallback,
  75883. finishCallback
  75884. ) {
  75885. var gifReader = new _omggif.default.GifReader(arrayBuffer);
  75886. pImg.width = pImg.canvas.width = gifReader.width;
  75887. pImg.height = pImg.canvas.height = gifReader.height;
  75888. var frames = [];
  75889. var numFrames = gifReader.numFrames();
  75890. var framePixels = new Uint8ClampedArray(pImg.width * pImg.height * 4);
  75891. if (numFrames > 1) {
  75892. var loadGIFFrameIntoImage = function loadGIFFrameIntoImage(
  75893. frameNum,
  75894. gifReader
  75895. ) {
  75896. try {
  75897. gifReader.decodeAndBlitFrameRGBA(frameNum, framePixels);
  75898. } catch (e) {
  75899. _main.default._friendlyFileLoadError(8, pImg.src);
  75900. if (typeof failureCallback === 'function') {
  75901. failureCallback(e);
  75902. } else {
  75903. console.error(e);
  75904. }
  75905. }
  75906. };
  75907. for (var j = 0; j < numFrames; j++) {
  75908. var frameInfo = gifReader.frameInfo(j);
  75909. var prevFrameData = pImg.drawingContext.getImageData(
  75910. 0,
  75911. 0,
  75912. pImg.width,
  75913. pImg.height
  75914. );
  75915. framePixels = prevFrameData.data.slice();
  75916. loadGIFFrameIntoImage(j, gifReader);
  75917. var imageData = new ImageData(framePixels, pImg.width, pImg.height);
  75918. pImg.drawingContext.putImageData(imageData, 0, 0);
  75919. var frameDelay = frameInfo.delay;
  75920. // To maintain the default of 10FPS when frameInfo.delay equals to 0
  75921. if (frameDelay === 0) {
  75922. frameDelay = 10;
  75923. }
  75924. frames.push({
  75925. image: pImg.drawingContext.getImageData(0, 0, pImg.width, pImg.height),
  75926. delay: frameDelay * 10 //GIF stores delay in one-hundredth of a second, shift to ms
  75927. });
  75928. // Some GIFs are encoded so that they expect the previous frame
  75929. // to be under the current frame. This can occur at a sub-frame level
  75930. //
  75931. // Values : 0 - No disposal specified. The decoder is
  75932. // not required to take any action.
  75933. // 1 - Do not dispose. The graphic is to be left
  75934. // in place.
  75935. // 2 - Restore to background color. The area used by the
  75936. // graphic must be restored to the background color.
  75937. // 3 - Restore to previous. The decoder is required to
  75938. // restore the area overwritten by the graphic with
  75939. // what was there prior to rendering the graphic.
  75940. // 4-7 - To be defined.
  75941. if (frameInfo.disposal === 2) {
  75942. // Restore background color
  75943. pImg.drawingContext.clearRect(
  75944. frameInfo.x,
  75945. frameInfo.y,
  75946. frameInfo.width,
  75947. frameInfo.height
  75948. );
  75949. } else if (frameInfo.disposal === 3) {
  75950. // Restore previous
  75951. pImg.drawingContext.putImageData(
  75952. prevFrameData,
  75953. 0,
  75954. 0,
  75955. frameInfo.x,
  75956. frameInfo.y,
  75957. frameInfo.width,
  75958. frameInfo.height
  75959. );
  75960. }
  75961. }
  75962. //Uses Netscape block encoding
  75963. //to repeat forever, this will be 0
  75964. //to repeat just once, this will be null
  75965. //to repeat N times (1<N), should contain integer for loop number
  75966. //this is changed to more usable values for us
  75967. //to repeat forever, loopCount = null
  75968. //everything else is just the number of loops
  75969. var loopLimit = gifReader.loopCount();
  75970. if (loopLimit === null) {
  75971. loopLimit = 1;
  75972. } else if (loopLimit === 0) {
  75973. loopLimit = null;
  75974. }
  75975. // we used the pImg for painting and saving during load
  75976. // so we have to reset it to the first frame
  75977. pImg.drawingContext.putImageData(frames[0].image, 0, 0);
  75978. pImg.gifProperties = {
  75979. displayIndex: 0,
  75980. loopLimit: loopLimit,
  75981. loopCount: 0,
  75982. frames: frames,
  75983. numFrames: numFrames,
  75984. playing: true,
  75985. timeDisplayed: 0,
  75986. lastChangeTime: 0
  75987. };
  75988. }
  75989. if (typeof successCallback === 'function') {
  75990. successCallback(pImg);
  75991. }
  75992. finishCallback();
  75993. }
  75994. /**
  75995. * Validates clipping params. Per drawImage spec sWidth and sHight cannot be
  75996. * negative or greater than image intrinsic width and height
  75997. * @private
  75998. * @param {Number} sVal
  75999. * @param {Number} iVal
  76000. * @returns {Number}
  76001. * @private
  76002. */
  76003. function _sAssign(sVal, iVal) {
  76004. if (sVal > 0 && sVal < iVal) {
  76005. return sVal;
  76006. } else {
  76007. return iVal;
  76008. }
  76009. }
  76010. /**
  76011. * Draw an image to the p5.js canvas.
  76012. *
  76013. * This function can be used with different numbers of parameters. The
  76014. * simplest use requires only three parameters: img, x, and y—where (x, y) is
  76015. * the position of the image. Two more parameters can optionally be added to
  76016. * specify the width and height of the image.
  76017. *
  76018. * This function can also be used with all eight Number parameters. To
  76019. * differentiate between all these parameters, p5.js uses the language of
  76020. * "destination rectangle" (which corresponds to "dx", "dy", etc.) and "source
  76021. * image" (which corresponds to "sx", "sy", etc.) below. Specifying the
  76022. * "source image" dimensions can be useful when you want to display a
  76023. * subsection of the source image instead of the whole thing. Here's a diagram
  76024. * to explain further:
  76025. * <img src="assets/drawImage.png"></img>
  76026. *
  76027. * @method image
  76028. * @param {p5.Image|p5.Element} img the image to display
  76029. * @param {Number} x the x-coordinate of the top-left corner of the image
  76030. * @param {Number} y the y-coordinate of the top-left corner of the image
  76031. * @param {Number} [width] the width to draw the image
  76032. * @param {Number} [height] the height to draw the image
  76033. * @example
  76034. * <div>
  76035. * <code>
  76036. * let img;
  76037. * function preload() {
  76038. * img = loadImage('assets/laDefense.jpg');
  76039. * }
  76040. * function setup() {
  76041. * // Top-left corner of the img is at (0, 0)
  76042. * // Width and height are the img's original width and height
  76043. * image(img, 0, 0);
  76044. * }
  76045. * </code>
  76046. * </div>
  76047. * <div>
  76048. * <code>
  76049. * let img;
  76050. * function preload() {
  76051. * img = loadImage('assets/laDefense.jpg');
  76052. * }
  76053. * function setup() {
  76054. * background(50);
  76055. * // Top-left corner of the img is at (10, 10)
  76056. * // Width and height are 50 x 50
  76057. * image(img, 10, 10, 50, 50);
  76058. * }
  76059. * </code>
  76060. * </div>
  76061. * <div>
  76062. * <code>
  76063. * function setup() {
  76064. * // Here, we use a callback to display the image after loading
  76065. * loadImage('assets/laDefense.jpg', img => {
  76066. * image(img, 0, 0);
  76067. * });
  76068. * }
  76069. * </code>
  76070. * </div>
  76071. * <div>
  76072. * <code>
  76073. * let img;
  76074. * function preload() {
  76075. * img = loadImage('assets/gradient.png');
  76076. * }
  76077. * function setup() {
  76078. * // 1. Background image
  76079. * // Top-left corner of the img is at (0, 0)
  76080. * // Width and height are the img's original width and height, 100 x 100
  76081. * image(img, 0, 0);
  76082. * // 2. Top right image
  76083. * // Top-left corner of destination rectangle is at (50, 0)
  76084. * // Destination rectangle width and height are 40 x 20
  76085. * // The next parameters are relative to the source image:
  76086. * // - Starting at position (50, 50) on the source image, capture a 50 x 50
  76087. * // subsection
  76088. * // - Draw this subsection to fill the dimensions of the destination rectangle
  76089. * image(img, 50, 0, 40, 20, 50, 50, 50, 50);
  76090. * }
  76091. * </code>
  76092. * </div>
  76093. * @alt
  76094. * image of the underside of a white umbrella and gridded ceiling above
  76095. * image of the underside of a white umbrella and gridded ceiling above
  76096. */
  76097. /**
  76098. * @method image
  76099. * @param {p5.Image|p5.Element} img
  76100. * @param {Number} dx the x-coordinate of the destination
  76101. * rectangle in which to draw the source image
  76102. * @param {Number} dy the y-coordinate of the destination
  76103. * rectangle in which to draw the source image
  76104. * @param {Number} dWidth the width of the destination rectangle
  76105. * @param {Number} dHeight the height of the destination rectangle
  76106. * @param {Number} sx the x-coordinate of the subsection of the source
  76107. * image to draw into the destination rectangle
  76108. * @param {Number} sy the y-coordinate of the subsection of the source
  76109. * image to draw into the destination rectangle
  76110. * @param {Number} [sWidth] the width of the subsection of the
  76111. * source image to draw into the destination
  76112. * rectangle
  76113. * @param {Number} [sHeight] the height of the subsection of the
  76114. * source image to draw into the destination rectangle
  76115. */
  76116. _main.default.prototype.image = function(
  76117. img,
  76118. dx,
  76119. dy,
  76120. dWidth,
  76121. dHeight,
  76122. sx,
  76123. sy,
  76124. sWidth,
  76125. sHeight
  76126. ) {
  76127. // set defaults per spec: https://goo.gl/3ykfOq
  76128. _main.default._validateParameters('image', arguments);
  76129. var defW = img.width;
  76130. var defH = img.height;
  76131. if (img.elt && img.elt.videoWidth && !img.canvas) {
  76132. // video no canvas
  76133. defW = img.elt.videoWidth;
  76134. defH = img.elt.videoHeight;
  76135. }
  76136. var _dx = dx;
  76137. var _dy = dy;
  76138. var _dw = dWidth || defW;
  76139. var _dh = dHeight || defH;
  76140. var _sx = sx || 0;
  76141. var _sy = sy || 0;
  76142. var _sw = sWidth || defW;
  76143. var _sh = sHeight || defH;
  76144. _sw = _sAssign(_sw, defW);
  76145. _sh = _sAssign(_sh, defH);
  76146. // This part needs cleanup and unit tests
  76147. // see issues https://github.com/processing/p5.js/issues/1741
  76148. // and https://github.com/processing/p5.js/issues/1673
  76149. var pd = 1;
  76150. if (img.elt && !img.canvas && img.elt.style.width) {
  76151. //if img is video and img.elt.size() has been used and
  76152. //no width passed to image()
  76153. if (img.elt.videoWidth && !dWidth) {
  76154. pd = img.elt.videoWidth;
  76155. } else {
  76156. //all other cases
  76157. pd = img.elt.width;
  76158. }
  76159. pd /= parseInt(img.elt.style.width, 10);
  76160. }
  76161. _sx *= pd;
  76162. _sy *= pd;
  76163. _sh *= pd;
  76164. _sw *= pd;
  76165. var vals = _helpers.default.modeAdjust(
  76166. _dx,
  76167. _dy,
  76168. _dw,
  76169. _dh,
  76170. this._renderer._imageMode
  76171. );
  76172. // tint the image if there is a tint
  76173. this._renderer.image(img, _sx, _sy, _sw, _sh, vals.x, vals.y, vals.w, vals.h);
  76174. };
  76175. /**
  76176. * Sets the fill value for displaying images. Images can be tinted to
  76177. * specified colors or made transparent by including an alpha value.
  76178. *
  76179. * To apply transparency to an image without affecting its color, use
  76180. * white as the tint color and specify an alpha value. For instance,
  76181. * tint(255, 128) will make an image 50% transparent (assuming the default
  76182. * alpha range of 0-255, which can be changed with <a href="#/p5/colorMode">colorMode()</a>).
  76183. *
  76184. * The value for the gray parameter must be less than or equal to the current
  76185. * maximum value as specified by <a href="#/p5/colorMode">colorMode()</a>. The default maximum value is
  76186. * 255.
  76187. *
  76188. * @method tint
  76189. * @param {Number} v1 red or hue value relative to
  76190. * the current color range
  76191. * @param {Number} v2 green or saturation value
  76192. * relative to the current color range
  76193. * @param {Number} v3 blue or brightness value
  76194. * relative to the current color range
  76195. * @param {Number} [alpha]
  76196. *
  76197. * @example
  76198. * <div>
  76199. * <code>
  76200. * let img;
  76201. * function preload() {
  76202. * img = loadImage('assets/laDefense.jpg');
  76203. * }
  76204. * function setup() {
  76205. * image(img, 0, 0);
  76206. * tint(0, 153, 204); // Tint blue
  76207. * image(img, 50, 0);
  76208. * }
  76209. * </code>
  76210. * </div>
  76211. *
  76212. * <div>
  76213. * <code>
  76214. * let img;
  76215. * function preload() {
  76216. * img = loadImage('assets/laDefense.jpg');
  76217. * }
  76218. * function setup() {
  76219. * image(img, 0, 0);
  76220. * tint(0, 153, 204, 126); // Tint blue and set transparency
  76221. * image(img, 50, 0);
  76222. * }
  76223. * </code>
  76224. * </div>
  76225. *
  76226. * <div>
  76227. * <code>
  76228. * let img;
  76229. * function preload() {
  76230. * img = loadImage('assets/laDefense.jpg');
  76231. * }
  76232. * function setup() {
  76233. * image(img, 0, 0);
  76234. * tint(255, 126); // Apply transparency without changing color
  76235. * image(img, 50, 0);
  76236. * }
  76237. * </code>
  76238. * </div>
  76239. *
  76240. * @alt
  76241. * 2 side by side images of umbrella and ceiling, one image with blue tint
  76242. * Images of umbrella and ceiling, one half of image with blue tint
  76243. * 2 side by side images of umbrella and ceiling, one image translucent
  76244. */
  76245. /**
  76246. * @method tint
  76247. * @param {String} value a color string
  76248. */
  76249. /**
  76250. * @method tint
  76251. * @param {Number} gray a gray value
  76252. * @param {Number} [alpha]
  76253. */
  76254. /**
  76255. * @method tint
  76256. * @param {Number[]} values an array containing the red,green,blue &
  76257. * and alpha components of the color
  76258. */
  76259. /**
  76260. * @method tint
  76261. * @param {p5.Color} color the tint color
  76262. */
  76263. _main.default.prototype.tint = function() {
  76264. for (
  76265. var _len = arguments.length, args = new Array(_len), _key = 0;
  76266. _key < _len;
  76267. _key++
  76268. ) {
  76269. args[_key] = arguments[_key];
  76270. }
  76271. _main.default._validateParameters('tint', args);
  76272. var c = this.color.apply(this, args);
  76273. this._renderer._tint = c.levels;
  76274. };
  76275. /**
  76276. * Removes the current fill value for displaying images and reverts to
  76277. * displaying images with their original hues.
  76278. *
  76279. * @method noTint
  76280. * @example
  76281. * <div>
  76282. * <code>
  76283. * let img;
  76284. * function preload() {
  76285. * img = loadImage('assets/bricks.jpg');
  76286. * }
  76287. * function setup() {
  76288. * tint(0, 153, 204); // Tint blue
  76289. * image(img, 0, 0);
  76290. * noTint(); // Disable tint
  76291. * image(img, 50, 0);
  76292. * }
  76293. * </code>
  76294. * </div>
  76295. *
  76296. * @alt
  76297. * 2 side by side images of bricks, left image with blue tint
  76298. */
  76299. _main.default.prototype.noTint = function() {
  76300. this._renderer._tint = null;
  76301. };
  76302. /**
  76303. * Apply the current tint color to the input image, return the resulting
  76304. * canvas.
  76305. *
  76306. * @private
  76307. * @param {p5.Image} The image to be tinted
  76308. * @return {canvas} The resulting tinted canvas
  76309. */
  76310. _main.default.prototype._getTintedImageCanvas = function(img) {
  76311. if (!img.canvas) {
  76312. return img;
  76313. }
  76314. var pixels = _filters.default._toPixels(img.canvas);
  76315. var tmpCanvas = document.createElement('canvas');
  76316. tmpCanvas.width = img.canvas.width;
  76317. tmpCanvas.height = img.canvas.height;
  76318. var tmpCtx = tmpCanvas.getContext('2d');
  76319. var id = tmpCtx.createImageData(img.canvas.width, img.canvas.height);
  76320. var newPixels = id.data;
  76321. for (var i = 0; i < pixels.length; i += 4) {
  76322. var r = pixels[i];
  76323. var g = pixels[i + 1];
  76324. var b = pixels[i + 2];
  76325. var a = pixels[i + 3];
  76326. newPixels[i] = r * this._renderer._tint[0] / 255;
  76327. newPixels[i + 1] = g * this._renderer._tint[1] / 255;
  76328. newPixels[i + 2] = b * this._renderer._tint[2] / 255;
  76329. newPixels[i + 3] = a * this._renderer._tint[3] / 255;
  76330. }
  76331. tmpCtx.putImageData(id, 0, 0);
  76332. return tmpCanvas;
  76333. };
  76334. /**
  76335. * Set image mode. Modifies the location from which images are drawn by
  76336. * changing the way in which parameters given to <a href="#/p5/image">image()</a> are interpreted.
  76337. * The default mode is imageMode(CORNER), which interprets the second and
  76338. * third parameters of <a href="#/p5/image">image()</a> as the upper-left corner of the image. If
  76339. * two additional parameters are specified, they are used to set the image's
  76340. * width and height.
  76341. *
  76342. * imageMode(CORNERS) interprets the second and third parameters of <a href="#/p5/image">image()</a>
  76343. * as the location of one corner, and the fourth and fifth parameters as the
  76344. * opposite corner.
  76345. *
  76346. * imageMode(CENTER) interprets the second and third parameters of <a href="#/p5/image">image()</a>
  76347. * as the image's center point. If two additional parameters are specified,
  76348. * they are used to set the image's width and height.
  76349. *
  76350. * @method imageMode
  76351. * @param {Constant} mode either CORNER, CORNERS, or CENTER
  76352. * @example
  76353. *
  76354. * <div>
  76355. * <code>
  76356. * let img;
  76357. * function preload() {
  76358. * img = loadImage('assets/bricks.jpg');
  76359. * }
  76360. * function setup() {
  76361. * imageMode(CORNER);
  76362. * image(img, 10, 10, 50, 50);
  76363. * }
  76364. * </code>
  76365. * </div>
  76366. *
  76367. * <div>
  76368. * <code>
  76369. * let img;
  76370. * function preload() {
  76371. * img = loadImage('assets/bricks.jpg');
  76372. * }
  76373. * function setup() {
  76374. * imageMode(CORNERS);
  76375. * image(img, 10, 10, 90, 40);
  76376. * }
  76377. * </code>
  76378. * </div>
  76379. *
  76380. * <div>
  76381. * <code>
  76382. * let img;
  76383. * function preload() {
  76384. * img = loadImage('assets/bricks.jpg');
  76385. * }
  76386. * function setup() {
  76387. * imageMode(CENTER);
  76388. * image(img, 50, 50, 80, 80);
  76389. * }
  76390. * </code>
  76391. * </div>
  76392. *
  76393. * @alt
  76394. * small square image of bricks
  76395. * horizontal rectangle image of bricks
  76396. * large square image of bricks
  76397. */
  76398. _main.default.prototype.imageMode = function(m) {
  76399. _main.default._validateParameters('imageMode', arguments);
  76400. if (
  76401. m === constants.CORNER ||
  76402. m === constants.CORNERS ||
  76403. m === constants.CENTER
  76404. ) {
  76405. this._renderer._imageMode = m;
  76406. }
  76407. };
  76408. var _default = _main.default;
  76409. exports.default = _default;
  76410. },
  76411. {
  76412. '../core/constants': 272,
  76413. '../core/friendly_errors/fes_core': 275,
  76414. '../core/friendly_errors/file_errors': 276,
  76415. '../core/friendly_errors/validate_params': 278,
  76416. '../core/helpers': 279,
  76417. '../core/main': 283,
  76418. './filters': 304,
  76419. 'core-js/modules/es.array.includes': 172,
  76420. 'core-js/modules/es.array.index-of': 173,
  76421. 'core-js/modules/es.array.iterator': 174,
  76422. 'core-js/modules/es.array.slice': 178,
  76423. 'core-js/modules/es.object.to-string': 192,
  76424. 'core-js/modules/es.promise': 193,
  76425. 'core-js/modules/es.string.includes': 200,
  76426. 'core-js/modules/es.typed-array.copy-within': 212,
  76427. 'core-js/modules/es.typed-array.every': 213,
  76428. 'core-js/modules/es.typed-array.fill': 214,
  76429. 'core-js/modules/es.typed-array.filter': 215,
  76430. 'core-js/modules/es.typed-array.find': 217,
  76431. 'core-js/modules/es.typed-array.find-index': 216,
  76432. 'core-js/modules/es.typed-array.for-each': 220,
  76433. 'core-js/modules/es.typed-array.includes': 221,
  76434. 'core-js/modules/es.typed-array.index-of': 222,
  76435. 'core-js/modules/es.typed-array.iterator': 225,
  76436. 'core-js/modules/es.typed-array.join': 226,
  76437. 'core-js/modules/es.typed-array.last-index-of': 227,
  76438. 'core-js/modules/es.typed-array.map': 228,
  76439. 'core-js/modules/es.typed-array.reduce': 230,
  76440. 'core-js/modules/es.typed-array.reduce-right': 229,
  76441. 'core-js/modules/es.typed-array.reverse': 231,
  76442. 'core-js/modules/es.typed-array.set': 232,
  76443. 'core-js/modules/es.typed-array.slice': 233,
  76444. 'core-js/modules/es.typed-array.some': 234,
  76445. 'core-js/modules/es.typed-array.sort': 235,
  76446. 'core-js/modules/es.typed-array.subarray': 236,
  76447. 'core-js/modules/es.typed-array.to-locale-string': 237,
  76448. 'core-js/modules/es.typed-array.to-string': 238,
  76449. 'core-js/modules/es.typed-array.uint8-array': 241,
  76450. 'core-js/modules/es.typed-array.uint8-clamped-array': 242,
  76451. omggif: 257
  76452. }
  76453. ],
  76454. 307: [
  76455. function(_dereq_, module, exports) {
  76456. 'use strict';
  76457. _dereq_('core-js/modules/es.symbol');
  76458. _dereq_('core-js/modules/es.symbol.description');
  76459. _dereq_('core-js/modules/es.symbol.iterator');
  76460. _dereq_('core-js/modules/es.array.filter');
  76461. _dereq_('core-js/modules/es.array.iterator');
  76462. _dereq_('core-js/modules/es.object.to-string');
  76463. _dereq_('core-js/modules/es.string.iterator');
  76464. _dereq_('core-js/modules/web.dom-collections.iterator');
  76465. Object.defineProperty(exports, '__esModule', { value: true });
  76466. exports.default = void 0;
  76467. var _main = _interopRequireDefault(_dereq_('../core/main'));
  76468. var _filters = _interopRequireDefault(_dereq_('./filters'));
  76469. function _interopRequireDefault(obj) {
  76470. return obj && obj.__esModule ? obj : { default: obj };
  76471. }
  76472. /**
  76473. * @module Image
  76474. * @submodule Image
  76475. * @requires core
  76476. * @requires constants
  76477. * @requires filters
  76478. */ /**
  76479. * This module defines the <a href="#/p5.Image">p5.Image</a> class and P5 methods for
  76480. * drawing images to the main display canvas.
  76481. */ /*
  76482. * Class methods
  76483. */ /**
  76484. * Creates a new <a href="#/p5.Image">p5.Image</a>. A <a href="#/p5.Image">p5.Image</a> is a canvas backed representation of an
  76485. * image.
  76486. *
  76487. * p5 can display .gif, .jpg and .png images. Images may be displayed
  76488. * in 2D and 3D space. Before an image is used, it must be loaded with the
  76489. * <a href="#/p5/loadImage">loadImage()</a> function. The <a href="#/p5.Image">p5.Image</a> class contains fields for the width and
  76490. * height of the image, as well as an array called <a href="#/p5.Image/pixels">pixels[]</a> that contains the
  76491. * values for every pixel in the image.
  76492. *
  76493. * The methods described below allow easy access to the image's pixels and
  76494. * alpha channel and simplify the process of compositing.
  76495. *
  76496. * Before using the <a href="#/p5.Image/pixels">pixels[]</a> array, be sure to use the <a href="#/p5.Image/loadPixels">loadPixels()</a> method on
  76497. * the image to make sure that the pixel data is properly loaded.
  76498. * @example
  76499. * <div><code>
  76500. * function setup() {
  76501. * let img = createImage(100, 100); // same as new p5.Image(100, 100);
  76502. * img.loadPixels();
  76503. * createCanvas(100, 100);
  76504. * background(0);
  76505. *
  76506. * // helper for writing color to array
  76507. * function writeColor(image, x, y, red, green, blue, alpha) {
  76508. * let index = (x + y * width) * 4;
  76509. * image.pixels[index] = red;
  76510. * image.pixels[index + 1] = green;
  76511. * image.pixels[index + 2] = blue;
  76512. * image.pixels[index + 3] = alpha;
  76513. * }
  76514. *
  76515. * let x, y;
  76516. * // fill with random colors
  76517. * for (y = 0; y < img.height; y++) {
  76518. * for (x = 0; x < img.width; x++) {
  76519. * let red = random(255);
  76520. * let green = random(255);
  76521. * let blue = random(255);
  76522. * let alpha = 255;
  76523. * writeColor(img, x, y, red, green, blue, alpha);
  76524. * }
  76525. * }
  76526. *
  76527. * // draw a red line
  76528. * y = 0;
  76529. * for (x = 0; x < img.width; x++) {
  76530. * writeColor(img, x, y, 255, 0, 0, 255);
  76531. * }
  76532. *
  76533. * // draw a green line
  76534. * y = img.height - 1;
  76535. * for (x = 0; x < img.width; x++) {
  76536. * writeColor(img, x, y, 0, 255, 0, 255);
  76537. * }
  76538. *
  76539. * img.updatePixels();
  76540. * image(img, 0, 0);
  76541. * }
  76542. * </code></div>
  76543. *
  76544. * @class p5.Image
  76545. * @constructor
  76546. * @param {Number} width
  76547. * @param {Number} height
  76548. */ _main.default.Image = function(width, height) {
  76549. /**
  76550. * Image width.
  76551. * @property {Number} width
  76552. * @readOnly
  76553. * @example
  76554. * <div><code>
  76555. * let img;
  76556. * function preload() {
  76557. * img = loadImage('assets/rockies.jpg');
  76558. * }
  76559. *
  76560. * function setup() {
  76561. * createCanvas(100, 100);
  76562. * image(img, 0, 0);
  76563. * for (let i = 0; i < img.width; i++) {
  76564. * let c = img.get(i, img.height / 2);
  76565. * stroke(c);
  76566. * line(i, height / 2, i, height);
  76567. * }
  76568. * }
  76569. * </code></div>
  76570. *
  76571. * @alt
  76572. * rocky mountains in top and horizontal lines in corresponding colors in bottom.
  76573. *
  76574. */ this.width = width;
  76575. /**
  76576. * Image height.
  76577. * @property {Number} height
  76578. * @readOnly
  76579. * @example
  76580. * <div><code>
  76581. * let img;
  76582. * function preload() {
  76583. * img = loadImage('assets/rockies.jpg');
  76584. * }
  76585. *
  76586. * function setup() {
  76587. * createCanvas(100, 100);
  76588. * image(img, 0, 0);
  76589. * for (let i = 0; i < img.height; i++) {
  76590. * let c = img.get(img.width / 2, i);
  76591. * stroke(c);
  76592. * line(0, i, width / 2, i);
  76593. * }
  76594. * }
  76595. * </code></div>
  76596. *
  76597. * @alt
  76598. * rocky mountains on right and vertical lines in corresponding colors on left.
  76599. *
  76600. */ this.height = height;
  76601. this.canvas = document.createElement('canvas');
  76602. this.canvas.width = this.width;
  76603. this.canvas.height = this.height;
  76604. this.drawingContext = this.canvas.getContext('2d');
  76605. this._pixelsState = this;
  76606. this._pixelDensity = 1;
  76607. //Object for working with GIFs, defaults to null
  76608. this.gifProperties = null;
  76609. //For WebGL Texturing only: used to determine whether to reupload texture to GPU
  76610. this._modified = false;
  76611. /**
  76612. * Array containing the values for all the pixels in the display window.
  76613. * These values are numbers. This array is the size (include an appropriate
  76614. * factor for pixelDensity) of the display window x4,
  76615. * representing the R, G, B, A values in order for each pixel, moving from
  76616. * left to right across each row, then down each column. Retina and other
  76617. * high density displays may have more pixels (by a factor of
  76618. * pixelDensity^2).
  76619. * For example, if the image is 100x100 pixels, there will be 40,000. With
  76620. * pixelDensity = 2, there will be 160,000. The first four values
  76621. * (indices 0-3) in the array will be the R, G, B, A values of the pixel at
  76622. * (0, 0). The second four values (indices 4-7) will contain the R, G, B, A
  76623. * values of the pixel at (1, 0). More generally, to set values for a pixel
  76624. * at (x, y):
  76625. * ```javascript
  76626. * let d = pixelDensity();
  76627. * for (let i = 0; i < d; i++) {
  76628. * for (let j = 0; j < d; j++) {
  76629. * // loop over
  76630. * index = 4 * ((y * d + j) * width * d + (x * d + i));
  76631. * pixels[index] = r;
  76632. * pixels[index+1] = g;
  76633. * pixels[index+2] = b;
  76634. * pixels[index+3] = a;
  76635. * }
  76636. * }
  76637. * ```
  76638. *
  76639. * Before accessing this array, the data must loaded with the <a href="#/p5.Image/loadPixels">loadPixels()</a>
  76640. * function. After the array data has been modified, the <a href="#/p5.Image/updatePixels">updatePixels()</a>
  76641. * function must be run to update the changes.
  76642. * @property {Number[]} pixels
  76643. * @example
  76644. * <div>
  76645. * <code>
  76646. * let img = createImage(66, 66);
  76647. * img.loadPixels();
  76648. * for (let i = 0; i < img.width; i++) {
  76649. * for (let j = 0; j < img.height; j++) {
  76650. * img.set(i, j, color(0, 90, 102));
  76651. * }
  76652. * }
  76653. * img.updatePixels();
  76654. * image(img, 17, 17);
  76655. * </code>
  76656. * </div>
  76657. * <div>
  76658. * <code>
  76659. * let pink = color(255, 102, 204);
  76660. * let img = createImage(66, 66);
  76661. * img.loadPixels();
  76662. * for (let i = 0; i < 4 * (width * height / 2); i += 4) {
  76663. * img.pixels[i] = red(pink);
  76664. * img.pixels[i + 1] = green(pink);
  76665. * img.pixels[i + 2] = blue(pink);
  76666. * img.pixels[i + 3] = alpha(pink);
  76667. * }
  76668. * img.updatePixels();
  76669. * image(img, 17, 17);
  76670. * </code>
  76671. * </div>
  76672. *
  76673. * @alt
  76674. * 66x66 turquoise rect in center of canvas
  76675. * 66x66 pink rect in center of canvas
  76676. *
  76677. */
  76678. this.pixels = [];
  76679. };
  76680. /**
  76681. * Helper function for animating GIF-based images with time
  76682. */
  76683. _main.default.Image.prototype._animateGif = function(pInst) {
  76684. var props = this.gifProperties;
  76685. var curTime = pInst._lastFrameTime + pInst.deltaTime;
  76686. if (props.lastChangeTime === 0) {
  76687. props.lastChangeTime = curTime;
  76688. }
  76689. if (props.playing) {
  76690. props.timeDisplayed = curTime - props.lastChangeTime;
  76691. var curDelay = props.frames[props.displayIndex].delay;
  76692. if (props.timeDisplayed >= curDelay) {
  76693. //GIF is bound to 'realtime' so can skip frames
  76694. var skips = Math.floor(props.timeDisplayed / curDelay);
  76695. props.timeDisplayed = 0;
  76696. props.lastChangeTime = curTime;
  76697. props.displayIndex += skips;
  76698. props.loopCount = Math.floor(props.displayIndex / props.numFrames);
  76699. if (props.loopLimit !== null && props.loopCount >= props.loopLimit) {
  76700. props.playing = false;
  76701. } else {
  76702. var ind = props.displayIndex % props.numFrames;
  76703. this.drawingContext.putImageData(props.frames[ind].image, 0, 0);
  76704. props.displayIndex = ind;
  76705. this.setModified(true);
  76706. }
  76707. }
  76708. }
  76709. };
  76710. /**
  76711. * Helper fxn for sharing pixel methods
  76712. */
  76713. _main.default.Image.prototype._setProperty = function(prop, value) {
  76714. this[prop] = value;
  76715. this.setModified(true);
  76716. };
  76717. /**
  76718. * Loads the pixels data for this image into the [pixels] attribute.
  76719. *
  76720. * @method loadPixels
  76721. * @example
  76722. * <div><code>
  76723. * let myImage;
  76724. * let halfImage;
  76725. *
  76726. * function preload() {
  76727. * myImage = loadImage('assets/rockies.jpg');
  76728. * }
  76729. *
  76730. * function setup() {
  76731. * myImage.loadPixels();
  76732. * halfImage = 4 * myImage.width * myImage.height / 2;
  76733. * for (let i = 0; i < halfImage; i++) {
  76734. * myImage.pixels[i + halfImage] = myImage.pixels[i];
  76735. * }
  76736. * myImage.updatePixels();
  76737. * }
  76738. *
  76739. * function draw() {
  76740. * image(myImage, 0, 0, width, height);
  76741. * }
  76742. * </code></div>
  76743. *
  76744. * @alt
  76745. * 2 images of rocky mountains vertically stacked
  76746. */
  76747. _main.default.Image.prototype.loadPixels = function() {
  76748. _main.default.Renderer2D.prototype.loadPixels.call(this);
  76749. this.setModified(true);
  76750. };
  76751. /**
  76752. * Updates the backing canvas for this image with the contents of
  76753. * the [pixels] array.
  76754. *
  76755. * If this image is an animated GIF then the pixels will be updated
  76756. * in the frame that is currently displayed.
  76757. *
  76758. * @method updatePixels
  76759. * @param {Integer} x x-offset of the target update area for the
  76760. * underlying canvas
  76761. * @param {Integer} y y-offset of the target update area for the
  76762. * underlying canvas
  76763. * @param {Integer} w height of the target update area for the
  76764. * underlying canvas
  76765. * @param {Integer} h height of the target update area for the
  76766. * underlying canvas
  76767. * @example
  76768. * <div><code>
  76769. * let myImage;
  76770. * let halfImage;
  76771. *
  76772. * function preload() {
  76773. * myImage = loadImage('assets/rockies.jpg');
  76774. * }
  76775. *
  76776. * function setup() {
  76777. * myImage.loadPixels();
  76778. * halfImage = 4 * myImage.width * myImage.height / 2;
  76779. * for (let i = 0; i < halfImage; i++) {
  76780. * myImage.pixels[i + halfImage] = myImage.pixels[i];
  76781. * }
  76782. * myImage.updatePixels();
  76783. * }
  76784. *
  76785. * function draw() {
  76786. * image(myImage, 0, 0, width, height);
  76787. * }
  76788. * </code></div>
  76789. *
  76790. * @alt
  76791. * 2 images of rocky mountains vertically stacked
  76792. */
  76793. /**
  76794. * @method updatePixels
  76795. */
  76796. _main.default.Image.prototype.updatePixels = function(x, y, w, h) {
  76797. _main.default.Renderer2D.prototype.updatePixels.call(this, x, y, w, h);
  76798. this.setModified(true);
  76799. };
  76800. /**
  76801. * Get a region of pixels from an image.
  76802. *
  76803. * If no params are passed, the whole image is returned.
  76804. * If x and y are the only params passed a single pixel is extracted.
  76805. * If all params are passed a rectangle region is extracted and a <a href="#/p5.Image">p5.Image</a>
  76806. * is returned.
  76807. *
  76808. * @method get
  76809. * @param {Number} x x-coordinate of the pixel
  76810. * @param {Number} y y-coordinate of the pixel
  76811. * @param {Number} w width
  76812. * @param {Number} h height
  76813. * @return {p5.Image} the rectangle <a href="#/p5.Image">p5.Image</a>
  76814. * @example
  76815. * <div><code>
  76816. * let myImage;
  76817. * let c;
  76818. *
  76819. * function preload() {
  76820. * myImage = loadImage('assets/rockies.jpg');
  76821. * }
  76822. *
  76823. * function setup() {
  76824. * background(myImage);
  76825. * noStroke();
  76826. * c = myImage.get(60, 90);
  76827. * fill(c);
  76828. * rect(25, 25, 50, 50);
  76829. * }
  76830. *
  76831. * //get() returns color here
  76832. * </code></div>
  76833. *
  76834. * @alt
  76835. * image of rocky mountains with 50x50 green rect in front
  76836. */
  76837. /**
  76838. * @method get
  76839. * @return {p5.Image} the whole <a href="#/p5.Image">p5.Image</a>
  76840. */
  76841. /**
  76842. * @method get
  76843. * @param {Number} x
  76844. * @param {Number} y
  76845. * @return {Number[]} color of pixel at x,y in array format [R, G, B, A]
  76846. */
  76847. _main.default.Image.prototype.get = function(x, y, w, h) {
  76848. _main.default._validateParameters('p5.Image.get', arguments);
  76849. return _main.default.Renderer2D.prototype.get.apply(this, arguments);
  76850. };
  76851. _main.default.Image.prototype._getPixel =
  76852. _main.default.Renderer2D.prototype._getPixel;
  76853. /**
  76854. * Set the color of a single pixel or write an image into
  76855. * this <a href="#/p5.Image">p5.Image</a>.
  76856. *
  76857. * Note that for a large number of pixels this will
  76858. * be slower than directly manipulating the pixels array
  76859. * and then calling <a href="#/p5.Image/updatePixels">updatePixels()</a>.
  76860. *
  76861. * @method set
  76862. * @param {Number} x x-coordinate of the pixel
  76863. * @param {Number} y y-coordinate of the pixel
  76864. * @param {Number|Number[]|Object} a grayscale value | pixel array |
  76865. * a <a href="#/p5.Color">p5.Color</a> | image to copy
  76866. * @example
  76867. * <div>
  76868. * <code>
  76869. * let img = createImage(66, 66);
  76870. * img.loadPixels();
  76871. * for (let i = 0; i < img.width; i++) {
  76872. * for (let j = 0; j < img.height; j++) {
  76873. * img.set(i, j, color(0, 90, 102, (i % img.width) * 2));
  76874. * }
  76875. * }
  76876. * img.updatePixels();
  76877. * image(img, 17, 17);
  76878. * image(img, 34, 34);
  76879. * </code>
  76880. * </div>
  76881. *
  76882. * @alt
  76883. * 2 gradated dark turquoise rects fade left. 1 center 1 bottom right of canvas
  76884. */
  76885. _main.default.Image.prototype.set = function(x, y, imgOrCol) {
  76886. _main.default.Renderer2D.prototype.set.call(this, x, y, imgOrCol);
  76887. this.setModified(true);
  76888. };
  76889. /**
  76890. * Resize the image to a new width and height. To make the image scale
  76891. * proportionally, use 0 as the value for the wide or high parameter.
  76892. * For instance, to make the width of an image 150 pixels, and change
  76893. * the height using the same proportion, use resize(150, 0).
  76894. *
  76895. * @method resize
  76896. * @param {Number} width the resized image width
  76897. * @param {Number} height the resized image height
  76898. * @example
  76899. * <div><code>
  76900. * let img;
  76901. *
  76902. * function preload() {
  76903. * img = loadImage('assets/rockies.jpg');
  76904. * }
  76905. * function draw() {
  76906. * image(img, 0, 0);
  76907. * }
  76908. *
  76909. * function mousePressed() {
  76910. * img.resize(50, 100);
  76911. * }
  76912. * </code></div>
  76913. *
  76914. * @alt
  76915. * image of rocky mountains. zoomed in
  76916. */
  76917. _main.default.Image.prototype.resize = function(width, height) {
  76918. // Copy contents to a temporary canvas, resize the original
  76919. // and then copy back.
  76920. //
  76921. // There is a faster approach that involves just one copy and swapping the
  76922. // this.canvas reference. We could switch to that approach if (as i think
  76923. // is the case) there an expectation that the user would not hold a
  76924. // reference to the backing canvas of a p5.Image. But since we do not
  76925. // enforce that at the moment, I am leaving in the slower, but safer
  76926. // implementation.
  76927. // auto-resize
  76928. if (width === 0 && height === 0) {
  76929. width = this.canvas.width;
  76930. height = this.canvas.height;
  76931. } else if (width === 0) {
  76932. width = this.canvas.width * height / this.canvas.height;
  76933. } else if (height === 0) {
  76934. height = this.canvas.height * width / this.canvas.width;
  76935. }
  76936. width = Math.floor(width);
  76937. height = Math.floor(height);
  76938. var tempCanvas = document.createElement('canvas');
  76939. tempCanvas.width = width;
  76940. tempCanvas.height = height;
  76941. if (this.gifProperties) {
  76942. var props = this.gifProperties;
  76943. //adapted from github.com/LinusU/resize-image-data
  76944. var nearestNeighbor = function nearestNeighbor(src, dst) {
  76945. var pos = 0;
  76946. for (var y = 0; y < dst.height; y++) {
  76947. for (var x = 0; x < dst.width; x++) {
  76948. var srcX = Math.floor(x * src.width / dst.width);
  76949. var srcY = Math.floor(y * src.height / dst.height);
  76950. var srcPos = (srcY * src.width + srcX) * 4;
  76951. dst.data[pos++] = src.data[srcPos++]; // R
  76952. dst.data[pos++] = src.data[srcPos++]; // G
  76953. dst.data[pos++] = src.data[srcPos++]; // B
  76954. dst.data[pos++] = src.data[srcPos++]; // A
  76955. }
  76956. }
  76957. };
  76958. for (var i = 0; i < props.numFrames; i++) {
  76959. var resizedImageData = this.drawingContext.createImageData(width, height);
  76960. nearestNeighbor(props.frames[i].image, resizedImageData);
  76961. props.frames[i].image = resizedImageData;
  76962. }
  76963. }
  76964. // prettier-ignore
  76965. tempCanvas.getContext('2d').drawImage(
  76966. this.canvas,
  76967. 0, 0, this.canvas.width, this.canvas.height,
  76968. 0, 0, tempCanvas.width, tempCanvas.height);
  76969. // Resize the original canvas, which will clear its contents
  76970. this.canvas.width = this.width = width;
  76971. this.canvas.height = this.height = height;
  76972. //Copy the image back
  76973. // prettier-ignore
  76974. this.drawingContext.drawImage(
  76975. tempCanvas,
  76976. 0, 0, width, height,
  76977. 0, 0, width, height);
  76978. if (this.pixels.length > 0) {
  76979. this.loadPixels();
  76980. }
  76981. this.setModified(true);
  76982. };
  76983. /**
  76984. * Copies a region of pixels from one image to another. If no
  76985. * srcImage is specified this is used as the source. If the source
  76986. * and destination regions aren't the same size, it will
  76987. * automatically resize source pixels to fit the specified
  76988. * target region.
  76989. *
  76990. * @method copy
  76991. * @param {p5.Image|p5.Element} srcImage source image
  76992. * @param {Integer} sx X coordinate of the source's upper left corner
  76993. * @param {Integer} sy Y coordinate of the source's upper left corner
  76994. * @param {Integer} sw source image width
  76995. * @param {Integer} sh source image height
  76996. * @param {Integer} dx X coordinate of the destination's upper left corner
  76997. * @param {Integer} dy Y coordinate of the destination's upper left corner
  76998. * @param {Integer} dw destination image width
  76999. * @param {Integer} dh destination image height
  77000. * @example
  77001. * <div><code>
  77002. * let photo;
  77003. * let bricks;
  77004. * let x;
  77005. * let y;
  77006. *
  77007. * function preload() {
  77008. * photo = loadImage('assets/rockies.jpg');
  77009. * bricks = loadImage('assets/bricks.jpg');
  77010. * }
  77011. *
  77012. * function setup() {
  77013. * x = bricks.width / 2;
  77014. * y = bricks.height / 2;
  77015. * photo.copy(bricks, 0, 0, x, y, 0, 0, x, y);
  77016. * image(photo, 0, 0);
  77017. * }
  77018. * </code></div>
  77019. *
  77020. * @alt
  77021. * image of rocky mountains and smaller image on top of bricks at top left
  77022. */
  77023. /**
  77024. * @method copy
  77025. * @param {Integer} sx
  77026. * @param {Integer} sy
  77027. * @param {Integer} sw
  77028. * @param {Integer} sh
  77029. * @param {Integer} dx
  77030. * @param {Integer} dy
  77031. * @param {Integer} dw
  77032. * @param {Integer} dh
  77033. */
  77034. _main.default.Image.prototype.copy = function() {
  77035. for (
  77036. var _len = arguments.length, args = new Array(_len), _key = 0;
  77037. _key < _len;
  77038. _key++
  77039. ) {
  77040. args[_key] = arguments[_key];
  77041. }
  77042. _main.default.prototype.copy.apply(this, args);
  77043. };
  77044. /**
  77045. * Masks part of an image from displaying by loading another
  77046. * image and using its alpha channel as an alpha channel for
  77047. * this image. Masks are cumulative, one applied to an image
  77048. * object, they cannot be removed.
  77049. *
  77050. * @method mask
  77051. * @param {p5.Image} srcImage source image
  77052. * @example
  77053. * <div><code>
  77054. * let photo, maskImage;
  77055. * function preload() {
  77056. * photo = loadImage('assets/rockies.jpg');
  77057. * maskImage = loadImage('assets/mask2.png');
  77058. * }
  77059. *
  77060. * function setup() {
  77061. * createCanvas(100, 100);
  77062. * photo.mask(maskImage);
  77063. * image(photo, 0, 0);
  77064. * }
  77065. * </code></div>
  77066. *
  77067. * @alt
  77068. * image of rocky mountains with white at right
  77069. *
  77070. * http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/
  77071. */
  77072. // TODO: - Accept an array of alpha values.
  77073. // - Use other channels of an image. p5 uses the
  77074. // blue channel (which feels kind of arbitrary). Note: at the
  77075. // moment this method does not match native processing's original
  77076. // functionality exactly.
  77077. _main.default.Image.prototype.mask = function(p5Image) {
  77078. if (p5Image === undefined) {
  77079. p5Image = this;
  77080. }
  77081. var currBlend = this.drawingContext.globalCompositeOperation;
  77082. var scaleFactor = 1;
  77083. if (p5Image instanceof _main.default.Renderer) {
  77084. scaleFactor = p5Image._pInst._pixelDensity;
  77085. }
  77086. var copyArgs = [
  77087. p5Image,
  77088. 0,
  77089. 0,
  77090. scaleFactor * p5Image.width,
  77091. scaleFactor * p5Image.height,
  77092. 0,
  77093. 0,
  77094. this.width,
  77095. this.height
  77096. ];
  77097. this.drawingContext.globalCompositeOperation = 'destination-in';
  77098. _main.default.Image.prototype.copy.apply(this, copyArgs);
  77099. this.drawingContext.globalCompositeOperation = currBlend;
  77100. this.setModified(true);
  77101. };
  77102. /**
  77103. * Applies an image filter to a <a href="#/p5.Image">p5.Image</a>
  77104. *
  77105. * THRESHOLD
  77106. * Converts the image to black and white pixels depending if they are above or
  77107. * below the threshold defined by the level parameter. The parameter must be
  77108. * between 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used.
  77109. *
  77110. * GRAY
  77111. * Converts any colors in the image to grayscale equivalents. No parameter
  77112. * is used.
  77113. *
  77114. * OPAQUE
  77115. * Sets the alpha channel to entirely opaque. No parameter is used.
  77116. *
  77117. * INVERT
  77118. * Sets each pixel to its inverse value. No parameter is used.
  77119. *
  77120. * POSTERIZE
  77121. * Limits each channel of the image to the number of colors specified as the
  77122. * parameter. The parameter can be set to values between 2 and 255, but
  77123. * results are most noticeable in the lower ranges.
  77124. *
  77125. * BLUR
  77126. * Executes a Gaussian blur with the level parameter specifying the extent
  77127. * of the blurring. If no parameter is used, the blur is equivalent to
  77128. * Gaussian blur of radius 1. Larger values increase the blur.
  77129. *
  77130. * ERODE
  77131. * Reduces the light areas. No parameter is used.
  77132. *
  77133. * DILATE
  77134. * Increases the light areas. No parameter is used.
  77135. *
  77136. * filter() does not work in WEBGL mode.
  77137. * A similar effect can be achieved in WEBGL mode using custom
  77138. * shaders. Adam Ferriss has written
  77139. * a <a href="https://github.com/aferriss/p5jsShaderExamples"
  77140. * target='_blank'>selection of shader examples</a> that contains many
  77141. * of the effects present in the filter examples.
  77142. *
  77143. * @method filter
  77144. * @param {Constant} filterType either THRESHOLD, GRAY, OPAQUE, INVERT,
  77145. * POSTERIZE, ERODE, DILATE or BLUR.
  77146. * See Filters.js for docs on
  77147. * each available filter
  77148. * @param {Number} [filterParam] an optional parameter unique
  77149. * to each filter, see above
  77150. * @example
  77151. * <div><code>
  77152. * let photo1;
  77153. * let photo2;
  77154. *
  77155. * function preload() {
  77156. * photo1 = loadImage('assets/rockies.jpg');
  77157. * photo2 = loadImage('assets/rockies.jpg');
  77158. * }
  77159. *
  77160. * function setup() {
  77161. * photo2.filter(GRAY);
  77162. * image(photo1, 0, 0);
  77163. * image(photo2, width / 2, 0);
  77164. * }
  77165. * </code></div>
  77166. *
  77167. * @alt
  77168. * 2 images of rocky mountains left one in color, right in black and white
  77169. */
  77170. _main.default.Image.prototype.filter = function(operation, value) {
  77171. _filters.default.apply(this.canvas, _filters.default[operation], value);
  77172. this.setModified(true);
  77173. };
  77174. /**
  77175. * Copies a region of pixels from one image to another, using a specified
  77176. * blend mode to do the operation.
  77177. *
  77178. * @method blend
  77179. * @param {p5.Image} srcImage source image
  77180. * @param {Integer} sx X coordinate of the source's upper left corner
  77181. * @param {Integer} sy Y coordinate of the source's upper left corner
  77182. * @param {Integer} sw source image width
  77183. * @param {Integer} sh source image height
  77184. * @param {Integer} dx X coordinate of the destination's upper left corner
  77185. * @param {Integer} dy Y coordinate of the destination's upper left corner
  77186. * @param {Integer} dw destination image width
  77187. * @param {Integer} dh destination image height
  77188. * @param {Constant} blendMode the blend mode. either
  77189. * BLEND, DARKEST, LIGHTEST, DIFFERENCE,
  77190. * MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,
  77191. * SOFT_LIGHT, DODGE, BURN, ADD or NORMAL.
  77192. *
  77193. * Available blend modes are: normal | multiply | screen | overlay |
  77194. * darken | lighten | color-dodge | color-burn | hard-light |
  77195. * soft-light | difference | exclusion | hue | saturation |
  77196. * color | luminosity
  77197. *
  77198. * http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/
  77199. * @example
  77200. * <div><code>
  77201. * let mountains;
  77202. * let bricks;
  77203. *
  77204. * function preload() {
  77205. * mountains = loadImage('assets/rockies.jpg');
  77206. * bricks = loadImage('assets/bricks_third.jpg');
  77207. * }
  77208. *
  77209. * function setup() {
  77210. * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, ADD);
  77211. * image(mountains, 0, 0);
  77212. * image(bricks, 0, 0);
  77213. * }
  77214. * </code></div>
  77215. * <div><code>
  77216. * let mountains;
  77217. * let bricks;
  77218. *
  77219. * function preload() {
  77220. * mountains = loadImage('assets/rockies.jpg');
  77221. * bricks = loadImage('assets/bricks_third.jpg');
  77222. * }
  77223. *
  77224. * function setup() {
  77225. * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);
  77226. * image(mountains, 0, 0);
  77227. * image(bricks, 0, 0);
  77228. * }
  77229. * </code></div>
  77230. * <div><code>
  77231. * let mountains;
  77232. * let bricks;
  77233. *
  77234. * function preload() {
  77235. * mountains = loadImage('assets/rockies.jpg');
  77236. * bricks = loadImage('assets/bricks_third.jpg');
  77237. * }
  77238. *
  77239. * function setup() {
  77240. * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);
  77241. * image(mountains, 0, 0);
  77242. * image(bricks, 0, 0);
  77243. * }
  77244. * </code></div>
  77245. *
  77246. * @alt
  77247. * image of rocky mountains. Brick images on left and right. Right overexposed
  77248. * image of rockies. Brickwall images on left and right. Right mortar transparent
  77249. * image of rockies. Brickwall images on left and right. Right translucent
  77250. */
  77251. /**
  77252. * @method blend
  77253. * @param {Integer} sx
  77254. * @param {Integer} sy
  77255. * @param {Integer} sw
  77256. * @param {Integer} sh
  77257. * @param {Integer} dx
  77258. * @param {Integer} dy
  77259. * @param {Integer} dw
  77260. * @param {Integer} dh
  77261. * @param {Constant} blendMode
  77262. */
  77263. _main.default.Image.prototype.blend = function() {
  77264. for (
  77265. var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
  77266. _key2 < _len2;
  77267. _key2++
  77268. ) {
  77269. args[_key2] = arguments[_key2];
  77270. }
  77271. _main.default._validateParameters('p5.Image.blend', arguments);
  77272. _main.default.prototype.blend.apply(this, args);
  77273. this.setModified(true);
  77274. };
  77275. /**
  77276. * helper method for web GL mode to indicate that an image has been
  77277. * changed or unchanged since last upload. gl texture upload will
  77278. * set this value to false after uploading the texture.
  77279. * @method setModified
  77280. * @param {boolean} val sets whether or not the image has been
  77281. * modified.
  77282. * @private
  77283. */
  77284. _main.default.Image.prototype.setModified = function(val) {
  77285. this._modified = val; //enforce boolean?
  77286. };
  77287. /**
  77288. * helper method for web GL mode to figure out if the image
  77289. * has been modified and might need to be re-uploaded to texture
  77290. * memory between frames.
  77291. * @method isModified
  77292. * @private
  77293. * @return {boolean} a boolean indicating whether or not the
  77294. * image has been updated or modified since last texture upload.
  77295. */
  77296. _main.default.Image.prototype.isModified = function() {
  77297. return this._modified;
  77298. };
  77299. /**
  77300. * Saves the image to a file and force the browser to download it.
  77301. * Accepts two strings for filename and file extension
  77302. * Supports png (default), jpg, and gif
  77303. *<br><br>
  77304. * Note that the file will only be downloaded as an animated GIF
  77305. * if the p5.Image was loaded from a GIF file.
  77306. * @method save
  77307. * @param {String} filename give your file a name
  77308. * @param {String} extension 'png' or 'jpg'
  77309. * @example
  77310. * <div><code>
  77311. * let photo;
  77312. *
  77313. * function preload() {
  77314. * photo = loadImage('assets/rockies.jpg');
  77315. * }
  77316. *
  77317. * function draw() {
  77318. * image(photo, 0, 0);
  77319. * }
  77320. *
  77321. * function keyTyped() {
  77322. * if (key === 's') {
  77323. * photo.save('photo', 'png');
  77324. * }
  77325. * }
  77326. * </code></div>
  77327. *
  77328. * @alt
  77329. * image of rocky mountains.
  77330. */
  77331. _main.default.Image.prototype.save = function(filename, extension) {
  77332. if (this.gifProperties) {
  77333. _main.default.prototype.saveGif(this, filename);
  77334. } else {
  77335. _main.default.prototype.saveCanvas(this.canvas, filename, extension);
  77336. }
  77337. };
  77338. // GIF Section
  77339. /**
  77340. * Starts an animated GIF over at the beginning state.
  77341. *
  77342. * @method reset
  77343. * @example
  77344. * <div><code>
  77345. * let gif;
  77346. *
  77347. * function preload() {
  77348. * gif = loadImage('assets/arnott-wallace-wink-loop-once.gif');
  77349. * }
  77350. *
  77351. * function draw() {
  77352. * background(255);
  77353. * // The GIF file that we loaded only loops once
  77354. * // so it freezes on the last frame after playing through
  77355. * image(gif, 0, 0);
  77356. * }
  77357. *
  77358. * function mousePressed() {
  77359. * // Click to reset the GIF and begin playback from start
  77360. * gif.reset();
  77361. * }
  77362. * </code></div>
  77363. * @alt
  77364. * Animated image of a cartoon face that winks once and then freezes
  77365. * When you click it animates again, winks once and freezes
  77366. */
  77367. _main.default.Image.prototype.reset = function() {
  77368. if (this.gifProperties) {
  77369. var props = this.gifProperties;
  77370. props.playing = true;
  77371. props.timeSinceStart = 0;
  77372. props.timeDisplayed = 0;
  77373. props.lastChangeTime = 0;
  77374. props.loopCount = 0;
  77375. props.displayIndex = 0;
  77376. this.drawingContext.putImageData(props.frames[0].image, 0, 0);
  77377. }
  77378. };
  77379. /**
  77380. * Gets the index for the frame that is currently visible in an animated GIF.
  77381. *
  77382. * @method getCurrentFrame
  77383. * @return {Number} The index for the currently displaying frame in animated GIF
  77384. * @example
  77385. * <div><code>
  77386. * let gif;
  77387. *
  77388. * function preload() {
  77389. * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
  77390. * }
  77391. *
  77392. * function draw() {
  77393. * let frame = gif.getCurrentFrame();
  77394. * image(gif, 0, 0);
  77395. * text(frame, 10, 90);
  77396. * }
  77397. * </code></div>
  77398. * @alt
  77399. * Animated image of a cartoon eye looking around and then
  77400. * looking outwards, in the lower-left hand corner a number counts
  77401. * up quickly to 124 and then starts back over at 0
  77402. */
  77403. _main.default.Image.prototype.getCurrentFrame = function() {
  77404. if (this.gifProperties) {
  77405. var props = this.gifProperties;
  77406. return props.displayIndex % props.numFrames;
  77407. }
  77408. };
  77409. /**
  77410. * Sets the index of the frame that is currently visible in an animated GIF
  77411. *
  77412. * @method setFrame
  77413. * @param {Number} index the index for the frame that should be displayed
  77414. * @example
  77415. * <div><code>
  77416. * let gif;
  77417. *
  77418. * function preload() {
  77419. * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
  77420. * }
  77421. *
  77422. * // Move your mouse up and down over canvas to see the GIF
  77423. * // frames animate
  77424. * function draw() {
  77425. * gif.pause();
  77426. * image(gif, 0, 0);
  77427. * // Get the highest frame number which is the number of frames - 1
  77428. * let maxFrame = gif.numFrames() - 1;
  77429. * // Set the current frame that is mapped to be relative to mouse position
  77430. * let frameNumber = floor(map(mouseY, 0, height, 0, maxFrame, true));
  77431. * gif.setFrame(frameNumber);
  77432. * }
  77433. * </code></div>
  77434. * @alt
  77435. * A still image of a cartoon eye that looks around when you move your mouse
  77436. * up and down over the canvas
  77437. */
  77438. _main.default.Image.prototype.setFrame = function(index) {
  77439. if (this.gifProperties) {
  77440. var props = this.gifProperties;
  77441. if (index < props.numFrames && index >= 0) {
  77442. props.timeDisplayed = 0;
  77443. props.lastChangeTime = 0;
  77444. props.displayIndex = index;
  77445. this.drawingContext.putImageData(props.frames[index].image, 0, 0);
  77446. } else {
  77447. console.log(
  77448. 'Cannot set GIF to a frame number that is higher than total number of frames or below zero.'
  77449. );
  77450. }
  77451. }
  77452. };
  77453. /**
  77454. * Returns the number of frames in an animated GIF
  77455. *
  77456. * @method numFrames
  77457. * @return {Number}
  77458. * @example The number of frames in the animated GIF
  77459. * <div><code>
  77460. * let gif;
  77461. *
  77462. * function preload() {
  77463. * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
  77464. * }
  77465. *
  77466. * // Move your mouse up and down over canvas to see the GIF
  77467. * // frames animate
  77468. * function draw() {
  77469. * gif.pause();
  77470. * image(gif, 0, 0);
  77471. * // Get the highest frame number which is the number of frames - 1
  77472. * let maxFrame = gif.numFrames() - 1;
  77473. * // Set the current frame that is mapped to be relative to mouse position
  77474. * let frameNumber = floor(map(mouseY, 0, height, 0, maxFrame, true));
  77475. * gif.setFrame(frameNumber);
  77476. * }
  77477. * </code></div>
  77478. * @alt
  77479. * A still image of a cartoon eye that looks around when you move your mouse
  77480. * up and down over the canvas
  77481. */
  77482. _main.default.Image.prototype.numFrames = function() {
  77483. if (this.gifProperties) {
  77484. return this.gifProperties.numFrames;
  77485. }
  77486. };
  77487. /**
  77488. * Plays an animated GIF that was paused with
  77489. * <a href="#/p5.Image/pause">pause()</a>
  77490. *
  77491. * @method play
  77492. * @example
  77493. * <div><code>
  77494. * let gif;
  77495. *
  77496. * function preload() {
  77497. * gif = loadImage('assets/nancy-liang-wind-loop-forever.gif');
  77498. * }
  77499. *
  77500. * function draw() {
  77501. * background(255);
  77502. * image(gif, 0, 0);
  77503. * }
  77504. *
  77505. * function mousePressed() {
  77506. * gif.pause();
  77507. * }
  77508. *
  77509. * function mouseReleased() {
  77510. * gif.play();
  77511. * }
  77512. * </code></div>
  77513. * @alt
  77514. * An animated GIF of a drawing of small child with
  77515. * hair blowing in the wind, when you click the image
  77516. * freezes when you release it animates again
  77517. */
  77518. _main.default.Image.prototype.play = function() {
  77519. if (this.gifProperties) {
  77520. this.gifProperties.playing = true;
  77521. }
  77522. };
  77523. /**
  77524. * Pauses an animated GIF.
  77525. *
  77526. * @method pause
  77527. * @example
  77528. * <div><code>
  77529. * let gif;
  77530. *
  77531. * function preload() {
  77532. * gif = loadImage('assets/nancy-liang-wind-loop-forever.gif');
  77533. * }
  77534. *
  77535. * function draw() {
  77536. * background(255);
  77537. * image(gif, 0, 0);
  77538. * }
  77539. *
  77540. * function mousePressed() {
  77541. * gif.pause();
  77542. * }
  77543. *
  77544. * function mouseReleased() {
  77545. * gif.play();
  77546. * }
  77547. * </code></div>
  77548. * @alt
  77549. * An animated GIF of a drawing of small child with
  77550. * hair blowing in the wind, when you click the image
  77551. * freezes when you release it animates again
  77552. */
  77553. _main.default.Image.prototype.pause = function() {
  77554. if (this.gifProperties) {
  77555. this.gifProperties.playing = false;
  77556. }
  77557. };
  77558. /**
  77559. * Changes the delay between frames in an animated GIF. There is an optional second parameter that
  77560. * indicates an index for a specific frame that should have its delay modified. If no index is given, all frames
  77561. * will have the new delay.
  77562. *
  77563. * @method delay
  77564. * @param {Number} d the amount in milliseconds to delay between switching frames
  77565. * @param {Number} [index] the index of the frame that should have the new delay value {optional}
  77566. * @example
  77567. * <div><code>
  77568. * let gifFast, gifSlow;
  77569. *
  77570. * function preload() {
  77571. * gifFast = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
  77572. * gifSlow = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
  77573. * }
  77574. *
  77575. * function setup() {
  77576. * gifFast.resize(width / 2, height / 2);
  77577. * gifSlow.resize(width / 2, height / 2);
  77578. *
  77579. * //Change the delay here
  77580. * gifFast.delay(10);
  77581. * gifSlow.delay(100);
  77582. * }
  77583. *
  77584. * function draw() {
  77585. * background(255);
  77586. * image(gifFast, 0, 0);
  77587. * image(gifSlow, width / 2, 0);
  77588. * }
  77589. * </code></div>
  77590. * @alt
  77591. * Two animated gifs of cartoon eyes looking around
  77592. * The gif on the left animates quickly, on the right
  77593. * the animation is much slower
  77594. */
  77595. _main.default.Image.prototype.delay = function(d, index) {
  77596. if (this.gifProperties) {
  77597. var props = this.gifProperties;
  77598. if (index < props.numFrames && index >= 0) {
  77599. props.frames[index].delay = d;
  77600. } else {
  77601. // change all frames
  77602. var _iteratorNormalCompletion = true;
  77603. var _didIteratorError = false;
  77604. var _iteratorError = undefined;
  77605. try {
  77606. for (
  77607. var _iterator = props.frames[Symbol.iterator](), _step;
  77608. !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
  77609. _iteratorNormalCompletion = true
  77610. ) {
  77611. var frame = _step.value;
  77612. frame.delay = d;
  77613. }
  77614. } catch (err) {
  77615. _didIteratorError = true;
  77616. _iteratorError = err;
  77617. } finally {
  77618. try {
  77619. if (!_iteratorNormalCompletion && _iterator.return != null) {
  77620. _iterator.return();
  77621. }
  77622. } finally {
  77623. if (_didIteratorError) {
  77624. throw _iteratorError;
  77625. }
  77626. }
  77627. }
  77628. }
  77629. }
  77630. };
  77631. var _default = _main.default.Image;
  77632. exports.default = _default;
  77633. },
  77634. {
  77635. '../core/main': 283,
  77636. './filters': 304,
  77637. 'core-js/modules/es.array.filter': 169,
  77638. 'core-js/modules/es.array.iterator': 174,
  77639. 'core-js/modules/es.object.to-string': 192,
  77640. 'core-js/modules/es.string.iterator': 201,
  77641. 'core-js/modules/es.symbol': 211,
  77642. 'core-js/modules/es.symbol.description': 209,
  77643. 'core-js/modules/es.symbol.iterator': 210,
  77644. 'core-js/modules/web.dom-collections.iterator': 244
  77645. }
  77646. ],
  77647. 308: [
  77648. function(_dereq_, module, exports) {
  77649. 'use strict';
  77650. _dereq_('core-js/modules/es.array.filter');
  77651. Object.defineProperty(exports, '__esModule', { value: true });
  77652. exports.default = void 0;
  77653. var _main = _interopRequireDefault(_dereq_('../core/main'));
  77654. var _filters = _interopRequireDefault(_dereq_('./filters'));
  77655. _dereq_('../color/p5.Color');
  77656. function _interopRequireDefault(obj) {
  77657. return obj && obj.__esModule ? obj : { default: obj };
  77658. }
  77659. /**
  77660. * @module Image
  77661. * @submodule Pixels
  77662. * @for p5
  77663. * @requires core
  77664. */ /**
  77665. * <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
  77666. * /Global_Objects/Uint8ClampedArray' target='_blank'>Uint8ClampedArray</a>
  77667. * containing the values for all the pixels in the display window.
  77668. * These values are numbers. This array is the size (include an appropriate
  77669. * factor for <a href="#/p5/pixelDensity">pixelDensity</a>) of the display window x4,
  77670. * representing the R, G, B, A values in order for each pixel, moving from
  77671. * left to right across each row, then down each column. Retina and other
  77672. * high density displays will have more pixels[] (by a factor of
  77673. * pixelDensity^2).
  77674. * For example, if the image is 100x100 pixels, there will be 40,000. On a
  77675. * retina display, there will be 160,000.
  77676. *
  77677. * The first four values (indices 0-3) in the array will be the R, G, B, A
  77678. * values of the pixel at (0, 0). The second four values (indices 4-7) will
  77679. * contain the R, G, B, A values of the pixel at (1, 0). More generally, to
  77680. * set values for a pixel at (x, y):
  77681. * ```javascript
  77682. * let d = pixelDensity();
  77683. * for (let i = 0; i < d; i++) {
  77684. * for (let j = 0; j < d; j++) {
  77685. * // loop over
  77686. * index = 4 * ((y * d + j) * width * d + (x * d + i));
  77687. * pixels[index] = r;
  77688. * pixels[index+1] = g;
  77689. * pixels[index+2] = b;
  77690. * pixels[index+3] = a;
  77691. * }
  77692. * }
  77693. * ```
  77694. * While the above method is complex, it is flexible enough to work with
  77695. * any pixelDensity. Note that <a href="#/p5/set">set()</a> will automatically take care of
  77696. * setting all the appropriate values in <a href="#/p5/pixels">pixels[]</a> for a given (x, y) at
  77697. * any pixelDensity, but the performance may not be as fast when lots of
  77698. * modifications are made to the pixel array.
  77699. *
  77700. * Before accessing this array, the data must loaded with the <a href="#/p5/loadPixels">loadPixels()</a>
  77701. * function. After the array data has been modified, the <a href="#/p5/updatePixels">updatePixels()</a>
  77702. * function must be run to update the changes.
  77703. *
  77704. * Note that this is not a standard javascript array. This means that
  77705. * standard javascript functions such as <a href="#/p5/slice">slice()</a> or
  77706. * <a href="#/p5/arrayCopy">arrayCopy()</a> do not
  77707. * work.
  77708. *
  77709. * @property {Number[]} pixels
  77710. * @example
  77711. * <div>
  77712. * <code>
  77713. * let pink = color(255, 102, 204);
  77714. * loadPixels();
  77715. * let d = pixelDensity();
  77716. * let halfImage = 4 * (width * d) * (height / 2 * d);
  77717. * for (let i = 0; i < halfImage; i += 4) {
  77718. * pixels[i] = red(pink);
  77719. * pixels[i + 1] = green(pink);
  77720. * pixels[i + 2] = blue(pink);
  77721. * pixels[i + 3] = alpha(pink);
  77722. * }
  77723. * updatePixels();
  77724. * </code>
  77725. * </div>
  77726. *
  77727. * @alt
  77728. * top half of canvas pink, bottom grey
  77729. */ _main.default.prototype.pixels = []; /**
  77730. * Copies a region of pixels from one image to another, using a specified
  77731. * blend mode to do the operation.
  77732. *
  77733. * @method blend
  77734. * @param {p5.Image} srcImage source image
  77735. * @param {Integer} sx X coordinate of the source's upper left corner
  77736. * @param {Integer} sy Y coordinate of the source's upper left corner
  77737. * @param {Integer} sw source image width
  77738. * @param {Integer} sh source image height
  77739. * @param {Integer} dx X coordinate of the destination's upper left corner
  77740. * @param {Integer} dy Y coordinate of the destination's upper left corner
  77741. * @param {Integer} dw destination image width
  77742. * @param {Integer} dh destination image height
  77743. * @param {Constant} blendMode the blend mode. either
  77744. * BLEND, DARKEST, LIGHTEST, DIFFERENCE,
  77745. * MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,
  77746. * SOFT_LIGHT, DODGE, BURN, ADD or NORMAL.
  77747. *
  77748. * @example
  77749. * <div><code>
  77750. * let img0;
  77751. * let img1;
  77752. *
  77753. * function preload() {
  77754. * img0 = loadImage('assets/rockies.jpg');
  77755. * img1 = loadImage('assets/bricks_third.jpg');
  77756. * }
  77757. *
  77758. * function setup() {
  77759. * background(img0);
  77760. * image(img1, 0, 0);
  77761. * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);
  77762. * }
  77763. * </code></div>
  77764. * <div><code>
  77765. * let img0;
  77766. * let img1;
  77767. *
  77768. * function preload() {
  77769. * img0 = loadImage('assets/rockies.jpg');
  77770. * img1 = loadImage('assets/bricks_third.jpg');
  77771. * }
  77772. *
  77773. * function setup() {
  77774. * background(img0);
  77775. * image(img1, 0, 0);
  77776. * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);
  77777. * }
  77778. * </code></div>
  77779. * <div><code>
  77780. * let img0;
  77781. * let img1;
  77782. *
  77783. * function preload() {
  77784. * img0 = loadImage('assets/rockies.jpg');
  77785. * img1 = loadImage('assets/bricks_third.jpg');
  77786. * }
  77787. *
  77788. * function setup() {
  77789. * background(img0);
  77790. * image(img1, 0, 0);
  77791. * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, ADD);
  77792. * }
  77793. * </code></div>
  77794. *
  77795. * @alt
  77796. * image of rocky mountains. Brick images on left and right. Right overexposed
  77797. * image of rockies. Brickwall images on left and right. Right mortar transparent
  77798. * image of rockies. Brickwall images on left and right. Right translucent
  77799. *
  77800. */
  77801. /**
  77802. * @method blend
  77803. * @param {Integer} sx
  77804. * @param {Integer} sy
  77805. * @param {Integer} sw
  77806. * @param {Integer} sh
  77807. * @param {Integer} dx
  77808. * @param {Integer} dy
  77809. * @param {Integer} dw
  77810. * @param {Integer} dh
  77811. * @param {Constant} blendMode
  77812. */
  77813. _main.default.prototype.blend = function() {
  77814. for (
  77815. var _len = arguments.length, args = new Array(_len), _key = 0;
  77816. _key < _len;
  77817. _key++
  77818. ) {
  77819. args[_key] = arguments[_key];
  77820. }
  77821. _main.default._validateParameters('blend', args);
  77822. if (this._renderer) {
  77823. var _this$_renderer;
  77824. (_this$_renderer = this._renderer).blend.apply(_this$_renderer, args);
  77825. } else {
  77826. _main.default.Renderer2D.prototype.blend.apply(this, args);
  77827. }
  77828. };
  77829. /**
  77830. * Copies a region of the canvas to another region of the canvas
  77831. * and copies a region of pixels from an image used as the srcImg parameter
  77832. * into the canvas srcImage is specified this is used as the source. If
  77833. * the source and destination regions aren't the same size, it will
  77834. * automatically resize source pixels to fit the specified
  77835. * target region.
  77836. *
  77837. * @method copy
  77838. * @param {p5.Image|p5.Element} srcImage source image
  77839. * @param {Integer} sx X coordinate of the source's upper left corner
  77840. * @param {Integer} sy Y coordinate of the source's upper left corner
  77841. * @param {Integer} sw source image width
  77842. * @param {Integer} sh source image height
  77843. * @param {Integer} dx X coordinate of the destination's upper left corner
  77844. * @param {Integer} dy Y coordinate of the destination's upper left corner
  77845. * @param {Integer} dw destination image width
  77846. * @param {Integer} dh destination image height
  77847. *
  77848. * @example
  77849. * <div><code>
  77850. * let img;
  77851. *
  77852. * function preload() {
  77853. * img = loadImage('assets/rockies.jpg');
  77854. * }
  77855. *
  77856. * function setup() {
  77857. * background(img);
  77858. * copy(img, 7, 22, 10, 10, 35, 25, 50, 50);
  77859. * stroke(255);
  77860. * noFill();
  77861. * // Rectangle shows area being copied
  77862. * rect(7, 22, 10, 10);
  77863. * }
  77864. * </code></div>
  77865. *
  77866. * @alt
  77867. * image of rocky mountains. Brick images on left and right. Right overexposed
  77868. * image of rockies. Brickwall images on left and right. Right mortar transparent
  77869. * image of rockies. Brickwall images on left and right. Right translucent
  77870. */
  77871. /**
  77872. * @method copy
  77873. * @param {Integer} sx
  77874. * @param {Integer} sy
  77875. * @param {Integer} sw
  77876. * @param {Integer} sh
  77877. * @param {Integer} dx
  77878. * @param {Integer} dy
  77879. * @param {Integer} dw
  77880. * @param {Integer} dh
  77881. */
  77882. _main.default.prototype.copy = function() {
  77883. for (
  77884. var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
  77885. _key2 < _len2;
  77886. _key2++
  77887. ) {
  77888. args[_key2] = arguments[_key2];
  77889. }
  77890. _main.default._validateParameters('copy', args);
  77891. var srcImage, sx, sy, sw, sh, dx, dy, dw, dh;
  77892. if (args.length === 9) {
  77893. srcImage = args[0];
  77894. sx = args[1];
  77895. sy = args[2];
  77896. sw = args[3];
  77897. sh = args[4];
  77898. dx = args[5];
  77899. dy = args[6];
  77900. dw = args[7];
  77901. dh = args[8];
  77902. } else if (args.length === 8) {
  77903. srcImage = this;
  77904. sx = args[0];
  77905. sy = args[1];
  77906. sw = args[2];
  77907. sh = args[3];
  77908. dx = args[4];
  77909. dy = args[5];
  77910. dw = args[6];
  77911. dh = args[7];
  77912. } else {
  77913. throw new Error('Signature not supported');
  77914. }
  77915. _main.default.prototype._copyHelper(
  77916. this,
  77917. srcImage,
  77918. sx,
  77919. sy,
  77920. sw,
  77921. sh,
  77922. dx,
  77923. dy,
  77924. dw,
  77925. dh
  77926. );
  77927. };
  77928. _main.default.prototype._copyHelper = function(
  77929. dstImage,
  77930. srcImage,
  77931. sx,
  77932. sy,
  77933. sw,
  77934. sh,
  77935. dx,
  77936. dy,
  77937. dw,
  77938. dh
  77939. ) {
  77940. srcImage.loadPixels();
  77941. var s = srcImage.canvas.width / srcImage.width;
  77942. // adjust coord system for 3D when renderer
  77943. // ie top-left = -width/2, -height/2
  77944. var sxMod = 0;
  77945. var syMod = 0;
  77946. if (srcImage._renderer && srcImage._renderer.isP3D) {
  77947. sxMod = srcImage.width / 2;
  77948. syMod = srcImage.height / 2;
  77949. }
  77950. if (dstImage._renderer && dstImage._renderer.isP3D) {
  77951. _main.default.RendererGL.prototype.image.call(
  77952. dstImage._renderer,
  77953. srcImage,
  77954. sx + sxMod,
  77955. sy + syMod,
  77956. sw,
  77957. sh,
  77958. dx,
  77959. dy,
  77960. dw,
  77961. dh
  77962. );
  77963. } else {
  77964. dstImage.drawingContext.drawImage(
  77965. srcImage.canvas,
  77966. s * (sx + sxMod),
  77967. s * (sy + syMod),
  77968. s * sw,
  77969. s * sh,
  77970. dx,
  77971. dy,
  77972. dw,
  77973. dh
  77974. );
  77975. }
  77976. };
  77977. /**
  77978. * Applies a filter to the canvas. The presets options are:
  77979. *
  77980. * THRESHOLD
  77981. * Converts the image to black and white pixels depending if they are above or
  77982. * below the threshold defined by the level parameter. The parameter must be
  77983. * between 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used.
  77984. *
  77985. * GRAY
  77986. * Converts any colors in the image to grayscale equivalents. No parameter
  77987. * is used.
  77988. *
  77989. * OPAQUE
  77990. * Sets the alpha channel to entirely opaque. No parameter is used.
  77991. *
  77992. * INVERT
  77993. * Sets each pixel to its inverse value. No parameter is used.
  77994. *
  77995. * POSTERIZE
  77996. * Limits each channel of the image to the number of colors specified as the
  77997. * parameter. The parameter can be set to values between 2 and 255, but
  77998. * results are most noticeable in the lower ranges.
  77999. *
  78000. * BLUR
  78001. * Executes a Gaussian blur with the level parameter specifying the extent
  78002. * of the blurring. If no parameter is used, the blur is equivalent to
  78003. * Gaussian blur of radius 1. Larger values increase the blur.
  78004. *
  78005. * ERODE
  78006. * Reduces the light areas. No parameter is used.
  78007. *
  78008. * DILATE
  78009. * Increases the light areas. No parameter is used.
  78010. *
  78011. * filter() does not work in WEBGL mode.
  78012. * A similar effect can be achieved in WEBGL mode using custom
  78013. * shaders. Adam Ferriss has written
  78014. * a <a href="https://github.com/aferriss/p5jsShaderExamples"
  78015. * target='_blank'>selection of shader examples</a> that contains many
  78016. * of the effects present in the filter examples.
  78017. *
  78018. * @method filter
  78019. * @param {Constant} filterType either THRESHOLD, GRAY, OPAQUE, INVERT,
  78020. * POSTERIZE, BLUR, ERODE, DILATE or BLUR.
  78021. * See Filters.js for docs on
  78022. * each available filter
  78023. * @param {Number} [filterParam] an optional parameter unique
  78024. * to each filter, see above
  78025. *
  78026. * @example
  78027. * <div>
  78028. * <code>
  78029. * let img;
  78030. * function preload() {
  78031. * img = loadImage('assets/bricks.jpg');
  78032. * }
  78033. * function setup() {
  78034. * image(img, 0, 0);
  78035. * filter(THRESHOLD);
  78036. * }
  78037. * </code>
  78038. * </div>
  78039. *
  78040. * <div>
  78041. * <code>
  78042. * let img;
  78043. * function preload() {
  78044. * img = loadImage('assets/bricks.jpg');
  78045. * }
  78046. * function setup() {
  78047. * image(img, 0, 0);
  78048. * filter(GRAY);
  78049. * }
  78050. * </code>
  78051. * </div>
  78052. *
  78053. * <div>
  78054. * <code>
  78055. * let img;
  78056. * function preload() {
  78057. * img = loadImage('assets/bricks.jpg');
  78058. * }
  78059. * function setup() {
  78060. * image(img, 0, 0);
  78061. * filter(OPAQUE);
  78062. * }
  78063. * </code>
  78064. * </div>
  78065. *
  78066. * <div>
  78067. * <code>
  78068. * let img;
  78069. * function preload() {
  78070. * img = loadImage('assets/bricks.jpg');
  78071. * }
  78072. * function setup() {
  78073. * image(img, 0, 0);
  78074. * filter(INVERT);
  78075. * }
  78076. * </code>
  78077. * </div>
  78078. *
  78079. * <div>
  78080. * <code>
  78081. * let img;
  78082. * function preload() {
  78083. * img = loadImage('assets/bricks.jpg');
  78084. * }
  78085. * function setup() {
  78086. * image(img, 0, 0);
  78087. * filter(POSTERIZE, 3);
  78088. * }
  78089. * </code>
  78090. * </div>
  78091. *
  78092. * <div>
  78093. * <code>
  78094. * let img;
  78095. * function preload() {
  78096. * img = loadImage('assets/bricks.jpg');
  78097. * }
  78098. * function setup() {
  78099. * image(img, 0, 0);
  78100. * filter(DILATE);
  78101. * }
  78102. * </code>
  78103. * </div>
  78104. *
  78105. * <div>
  78106. * <code>
  78107. * let img;
  78108. * function preload() {
  78109. * img = loadImage('assets/bricks.jpg');
  78110. * }
  78111. * function setup() {
  78112. * image(img, 0, 0);
  78113. * filter(BLUR, 3);
  78114. * }
  78115. * </code>
  78116. * </div>
  78117. *
  78118. * <div>
  78119. * <code>
  78120. * let img;
  78121. * function preload() {
  78122. * img = loadImage('assets/bricks.jpg');
  78123. * }
  78124. * function setup() {
  78125. * image(img, 0, 0);
  78126. * filter(ERODE);
  78127. * }
  78128. * </code>
  78129. * </div>
  78130. *
  78131. * @alt
  78132. * black and white image of a brick wall.
  78133. * greyscale image of a brickwall
  78134. * image of a brickwall
  78135. * jade colored image of a brickwall
  78136. * red and pink image of a brickwall
  78137. * image of a brickwall
  78138. * blurry image of a brickwall
  78139. * image of a brickwall
  78140. * image of a brickwall with less detail
  78141. */
  78142. _main.default.prototype.filter = function(operation, value) {
  78143. _main.default._validateParameters('filter', arguments);
  78144. if (this.canvas !== undefined) {
  78145. _filters.default.apply(this.canvas, _filters.default[operation], value);
  78146. } else {
  78147. _filters.default.apply(this.elt, _filters.default[operation], value);
  78148. }
  78149. };
  78150. /**
  78151. * Get a region of pixels, or a single pixel, from the canvas.
  78152. *
  78153. * Returns an array of [R,G,B,A] values for any pixel or grabs a section of
  78154. * an image. If no parameters are specified, the entire image is returned.
  78155. * Use the x and y parameters to get the value of one pixel. Get a section of
  78156. * the display window by specifying additional w and h parameters. When
  78157. * getting an image, the x and y parameters define the coordinates for the
  78158. * upper-left corner of the image, regardless of the current <a href="#/p5/imageMode">imageMode()</a>.
  78159. *
  78160. * Getting the color of a single pixel with get(x, y) is easy, but not as fast
  78161. * as grabbing the data directly from <a href="#/p5/pixels">pixels[]</a>. The equivalent statement to
  78162. * get(x, y) using <a href="#/p5/pixels">pixels[]</a> with pixel density d is
  78163. * ```javascript
  78164. * let x, y, d; // set these to the coordinates
  78165. * let off = (y * width + x) * d * 4;
  78166. * let components = [
  78167. * pixels[off],
  78168. * pixels[off + 1],
  78169. * pixels[off + 2],
  78170. * pixels[off + 3]
  78171. * ];
  78172. * print(components);
  78173. * ```
  78174. * See the reference for <a href="#/p5/pixels">pixels[]</a> for more information.
  78175. *
  78176. * If you want to extract an array of colors or a subimage from an p5.Image object,
  78177. * take a look at <a href="#/p5.Image/get">p5.Image.get()</a>
  78178. *
  78179. * @method get
  78180. * @param {Number} x x-coordinate of the pixel
  78181. * @param {Number} y y-coordinate of the pixel
  78182. * @param {Number} w width
  78183. * @param {Number} h height
  78184. * @return {p5.Image} the rectangle <a href="#/p5.Image">p5.Image</a>
  78185. * @example
  78186. * <div>
  78187. * <code>
  78188. * let img;
  78189. * function preload() {
  78190. * img = loadImage('assets/rockies.jpg');
  78191. * }
  78192. * function setup() {
  78193. * image(img, 0, 0);
  78194. * let c = get();
  78195. * image(c, width / 2, 0);
  78196. * }
  78197. * </code>
  78198. * </div>
  78199. *
  78200. * <div>
  78201. * <code>
  78202. * let img;
  78203. * function preload() {
  78204. * img = loadImage('assets/rockies.jpg');
  78205. * }
  78206. * function setup() {
  78207. * image(img, 0, 0);
  78208. * let c = get(50, 90);
  78209. * fill(c);
  78210. * noStroke();
  78211. * rect(25, 25, 50, 50);
  78212. * }
  78213. * </code>
  78214. * </div>
  78215. *
  78216. * @alt
  78217. * 2 images of the rocky mountains, side-by-side
  78218. * Image of the rocky mountains with 50x50 green rect in center of canvas
  78219. */
  78220. /**
  78221. * @method get
  78222. * @return {p5.Image} the whole <a href="#/p5.Image">p5.Image</a>
  78223. */
  78224. /**
  78225. * @method get
  78226. * @param {Number} x
  78227. * @param {Number} y
  78228. * @return {Number[]} color of pixel at x,y in array format [R, G, B, A]
  78229. */
  78230. _main.default.prototype.get = function(x, y, w, h) {
  78231. var _this$_renderer2;
  78232. _main.default._validateParameters('get', arguments);
  78233. return (_this$_renderer2 = this._renderer).get.apply(
  78234. _this$_renderer2,
  78235. arguments
  78236. );
  78237. };
  78238. /**
  78239. * Loads the pixel data for the display window into the <a href="#/p5/pixels">pixels[]</a> array. This
  78240. * function must always be called before reading from or writing to <a href="#/p5/pixels">pixels[]</a>.
  78241. * Note that only changes made with <a href="#/p5/set">set()</a> or direct manipulation of <a href="#/p5/pixels">pixels[]</a>
  78242. * will occur.
  78243. *
  78244. * @method loadPixels
  78245. * @example
  78246. * <div>
  78247. * <code>
  78248. * let img;
  78249. * function preload() {
  78250. * img = loadImage('assets/rockies.jpg');
  78251. * }
  78252. *
  78253. * function setup() {
  78254. * image(img, 0, 0, width, height);
  78255. * let d = pixelDensity();
  78256. * let halfImage = 4 * (width * d) * (height * d / 2);
  78257. * loadPixels();
  78258. * for (let i = 0; i < halfImage; i++) {
  78259. * pixels[i + halfImage] = pixels[i];
  78260. * }
  78261. * updatePixels();
  78262. * }
  78263. * </code>
  78264. * </div>
  78265. *
  78266. * @alt
  78267. * two images of the rocky mountains. one on top, one on bottom of canvas.
  78268. */
  78269. _main.default.prototype.loadPixels = function() {
  78270. for (
  78271. var _len3 = arguments.length, args = new Array(_len3), _key3 = 0;
  78272. _key3 < _len3;
  78273. _key3++
  78274. ) {
  78275. args[_key3] = arguments[_key3];
  78276. }
  78277. _main.default._validateParameters('loadPixels', args);
  78278. this._renderer.loadPixels();
  78279. };
  78280. /**
  78281. * Changes the color of any pixel, or writes an image directly to the
  78282. * display window.
  78283. * The x and y parameters specify the pixel to change and the c parameter
  78284. * specifies the color value. This can be a <a href="#/p5.Color">p5.Color</a> object, or [R, G, B, A]
  78285. * pixel array. It can also be a single grayscale value.
  78286. * When setting an image, the x and y parameters define the coordinates for
  78287. * the upper-left corner of the image, regardless of the current <a href="#/p5/imageMode">imageMode()</a>.
  78288. *
  78289. * After using <a href="#/p5/set">set()</a>, you must call <a href="#/p5/updatePixels">updatePixels()</a> for your changes to appear.
  78290. * This should be called once all pixels have been set, and must be called before
  78291. * calling .<a href="#/p5/get">get()</a> or drawing the image.
  78292. *
  78293. * Setting the color of a single pixel with set(x, y) is easy, but not as
  78294. * fast as putting the data directly into <a href="#/p5/pixels">pixels[]</a>. Setting the <a href="#/p5/pixels">pixels[]</a>
  78295. * values directly may be complicated when working with a retina display,
  78296. * but will perform better when lots of pixels need to be set directly on
  78297. * every loop. See the reference for <a href="#/p5/pixels">pixels[]</a> for more information.
  78298. *
  78299. * @method set
  78300. * @param {Number} x x-coordinate of the pixel
  78301. * @param {Number} y y-coordinate of the pixel
  78302. * @param {Number|Number[]|Object} c insert a grayscale value | a pixel array |
  78303. * a <a href="#/p5.Color">p5.Color</a> object | a <a href="#/p5.Image">p5.Image</a> to copy
  78304. * @example
  78305. * <div>
  78306. * <code>
  78307. * let black = color(0);
  78308. * set(30, 20, black);
  78309. * set(85, 20, black);
  78310. * set(85, 75, black);
  78311. * set(30, 75, black);
  78312. * updatePixels();
  78313. * </code>
  78314. * </div>
  78315. *
  78316. * <div>
  78317. * <code>
  78318. * for (let i = 30; i < width - 15; i++) {
  78319. * for (let j = 20; j < height - 25; j++) {
  78320. * let c = color(204 - j, 153 - i, 0);
  78321. * set(i, j, c);
  78322. * }
  78323. * }
  78324. * updatePixels();
  78325. * </code>
  78326. * </div>
  78327. *
  78328. * <div>
  78329. * <code>
  78330. * let img;
  78331. * function preload() {
  78332. * img = loadImage('assets/rockies.jpg');
  78333. * }
  78334. *
  78335. * function setup() {
  78336. * set(0, 0, img);
  78337. * updatePixels();
  78338. * line(0, 0, width, height);
  78339. * line(0, height, width, 0);
  78340. * }
  78341. * </code>
  78342. * </div>
  78343. *
  78344. * @alt
  78345. * 4 black points in the shape of a square middle-right of canvas.
  78346. * square with orangey-brown gradient lightening at bottom right.
  78347. * image of the rocky mountains. with lines like an 'x' through the center.
  78348. */
  78349. _main.default.prototype.set = function(x, y, imgOrCol) {
  78350. this._renderer.set(x, y, imgOrCol);
  78351. };
  78352. /**
  78353. * Updates the display window with the data in the <a href="#/p5/pixels">pixels[]</a> array.
  78354. * Use in conjunction with <a href="#/p5/loadPixels">loadPixels()</a>. If you're only reading pixels from
  78355. * the array, there's no need to call <a href="#/p5/updatePixels">updatePixels()</a> — updating is only
  78356. * necessary to apply changes. <a href="#/p5/updatePixels">updatePixels()</a> should be called anytime the
  78357. * pixels array is manipulated or <a href="#/p5/set">set()</a> is called, and only changes made with
  78358. * <a href="#/p5/set">set()</a> or direct changes to <a href="#/p5/pixels">pixels[]</a> will occur.
  78359. *
  78360. * @method updatePixels
  78361. * @param {Number} [x] x-coordinate of the upper-left corner of region
  78362. * to update
  78363. * @param {Number} [y] y-coordinate of the upper-left corner of region
  78364. * to update
  78365. * @param {Number} [w] width of region to update
  78366. * @param {Number} [h] height of region to update
  78367. * @example
  78368. * <div>
  78369. * <code>
  78370. * let img;
  78371. * function preload() {
  78372. * img = loadImage('assets/rockies.jpg');
  78373. * }
  78374. *
  78375. * function setup() {
  78376. * image(img, 0, 0, width, height);
  78377. * let d = pixelDensity();
  78378. * let halfImage = 4 * (width * d) * (height * d / 2);
  78379. * loadPixels();
  78380. * for (let i = 0; i < halfImage; i++) {
  78381. * pixels[i + halfImage] = pixels[i];
  78382. * }
  78383. * updatePixels();
  78384. * }
  78385. * </code>
  78386. * </div>
  78387. * @alt
  78388. * two images of the rocky mountains. one on top, one on bottom of canvas.
  78389. */
  78390. _main.default.prototype.updatePixels = function(x, y, w, h) {
  78391. _main.default._validateParameters('updatePixels', arguments);
  78392. // graceful fail - if loadPixels() or set() has not been called, pixel
  78393. // array will be empty, ignore call to updatePixels()
  78394. if (this.pixels.length === 0) {
  78395. return;
  78396. }
  78397. this._renderer.updatePixels(x, y, w, h);
  78398. };
  78399. var _default = _main.default;
  78400. exports.default = _default;
  78401. },
  78402. {
  78403. '../color/p5.Color': 270,
  78404. '../core/main': 283,
  78405. './filters': 304,
  78406. 'core-js/modules/es.array.filter': 169
  78407. }
  78408. ],
  78409. 309: [
  78410. function(_dereq_, module, exports) {
  78411. 'use strict';
  78412. _dereq_('core-js/modules/es.symbol');
  78413. _dereq_('core-js/modules/es.symbol.description');
  78414. _dereq_('core-js/modules/es.symbol.iterator');
  78415. _dereq_('core-js/modules/es.array.concat');
  78416. _dereq_('core-js/modules/es.array.includes');
  78417. _dereq_('core-js/modules/es.array.index-of');
  78418. _dereq_('core-js/modules/es.array.iterator');
  78419. _dereq_('core-js/modules/es.array.last-index-of');
  78420. _dereq_('core-js/modules/es.array.slice');
  78421. _dereq_('core-js/modules/es.array.splice');
  78422. _dereq_('core-js/modules/es.function.name');
  78423. _dereq_('core-js/modules/es.object.to-string');
  78424. _dereq_('core-js/modules/es.promise');
  78425. _dereq_('core-js/modules/es.regexp.exec');
  78426. _dereq_('core-js/modules/es.regexp.to-string');
  78427. _dereq_('core-js/modules/es.string.includes');
  78428. _dereq_('core-js/modules/es.string.iterator');
  78429. _dereq_('core-js/modules/es.string.replace');
  78430. _dereq_('core-js/modules/es.string.split');
  78431. _dereq_('core-js/modules/es.typed-array.uint8-array');
  78432. _dereq_('core-js/modules/es.typed-array.copy-within');
  78433. _dereq_('core-js/modules/es.typed-array.every');
  78434. _dereq_('core-js/modules/es.typed-array.fill');
  78435. _dereq_('core-js/modules/es.typed-array.filter');
  78436. _dereq_('core-js/modules/es.typed-array.find');
  78437. _dereq_('core-js/modules/es.typed-array.find-index');
  78438. _dereq_('core-js/modules/es.typed-array.for-each');
  78439. _dereq_('core-js/modules/es.typed-array.includes');
  78440. _dereq_('core-js/modules/es.typed-array.index-of');
  78441. _dereq_('core-js/modules/es.typed-array.iterator');
  78442. _dereq_('core-js/modules/es.typed-array.join');
  78443. _dereq_('core-js/modules/es.typed-array.last-index-of');
  78444. _dereq_('core-js/modules/es.typed-array.map');
  78445. _dereq_('core-js/modules/es.typed-array.reduce');
  78446. _dereq_('core-js/modules/es.typed-array.reduce-right');
  78447. _dereq_('core-js/modules/es.typed-array.reverse');
  78448. _dereq_('core-js/modules/es.typed-array.set');
  78449. _dereq_('core-js/modules/es.typed-array.slice');
  78450. _dereq_('core-js/modules/es.typed-array.some');
  78451. _dereq_('core-js/modules/es.typed-array.sort');
  78452. _dereq_('core-js/modules/es.typed-array.subarray');
  78453. _dereq_('core-js/modules/es.typed-array.to-locale-string');
  78454. _dereq_('core-js/modules/es.typed-array.to-string');
  78455. _dereq_('core-js/modules/web.dom-collections.iterator');
  78456. _dereq_('core-js/modules/web.url');
  78457. Object.defineProperty(exports, '__esModule', { value: true });
  78458. exports.default = void 0;
  78459. var _main = _interopRequireDefault(_dereq_('../core/main'));
  78460. _dereq_('whatwg-fetch');
  78461. _dereq_('es6-promise/auto');
  78462. var _fetchJsonp = _interopRequireDefault(_dereq_('fetch-jsonp'));
  78463. var _fileSaver = _interopRequireDefault(_dereq_('file-saver'));
  78464. _dereq_('../core/friendly_errors/validate_params');
  78465. _dereq_('../core/friendly_errors/file_errors');
  78466. _dereq_('../core/friendly_errors/fes_core');
  78467. function _interopRequireDefault(obj) {
  78468. return obj && obj.__esModule ? obj : { default: obj };
  78469. }
  78470. function _typeof(obj) {
  78471. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  78472. _typeof = function _typeof(obj) {
  78473. return typeof obj;
  78474. };
  78475. } else {
  78476. _typeof = function _typeof(obj) {
  78477. return obj &&
  78478. typeof Symbol === 'function' &&
  78479. obj.constructor === Symbol &&
  78480. obj !== Symbol.prototype
  78481. ? 'symbol'
  78482. : typeof obj;
  78483. };
  78484. }
  78485. return _typeof(obj);
  78486. }
  78487. /**
  78488. * Loads a JSON file from a file or a URL, and returns an Object.
  78489. * Note that even if the JSON file contains an Array, an Object will be
  78490. * returned with index numbers as keys.
  78491. *
  78492. * This method is asynchronous, meaning it may not finish before the next
  78493. * line in your sketch is executed. JSONP is supported via a polyfill and you
  78494. * can pass in as the second argument an object with definitions of the json
  78495. * callback following the syntax specified <a href="https://github.com/camsong/
  78496. * fetch-jsonp">here</a>.
  78497. *
  78498. * This method is suitable for fetching files up to size of 64MB.
  78499. * @method loadJSON
  78500. * @param {String} path name of the file or url to load
  78501. * @param {Object} [jsonpOptions] options object for jsonp related settings
  78502. * @param {String} [datatype] "json" or "jsonp"
  78503. * @param {function} [callback] function to be executed after
  78504. * <a href="#/p5/loadJSON">loadJSON()</a> completes, data is passed
  78505. * in as first argument
  78506. * @param {function} [errorCallback] function to be executed if
  78507. * there is an error, response is passed
  78508. * in as first argument
  78509. * @return {Object|Array} JSON data
  78510. * @example
  78511. *
  78512. * Calling <a href="#/p5/loadJSON">loadJSON()</a> inside <a href="#/p5/preload">preload()</a> guarantees to complete the
  78513. * operation before <a href="#/p5/setup">setup()</a> and <a href="#/p5/draw">draw()</a> are called.
  78514. *
  78515. * <div><code>
  78516. * // Examples use USGS Earthquake API:
  78517. * // https://earthquake.usgs.gov/fdsnws/event/1/#methods
  78518. * let earthquakes;
  78519. * function preload() {
  78520. * // Get the most recent earthquake in the database
  78521. * let url =
  78522. 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/' +
  78523. * 'summary/all_day.geojson';
  78524. * earthquakes = loadJSON(url);
  78525. * }
  78526. *
  78527. * function setup() {
  78528. * noLoop();
  78529. * }
  78530. *
  78531. * function draw() {
  78532. * background(200);
  78533. * // Get the magnitude and name of the earthquake out of the loaded JSON
  78534. * let earthquakeMag = earthquakes.features[0].properties.mag;
  78535. * let earthquakeName = earthquakes.features[0].properties.place;
  78536. * ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10);
  78537. * textAlign(CENTER);
  78538. * text(earthquakeName, 0, height - 30, width, 30);
  78539. * }
  78540. * </code></div>
  78541. *
  78542. * Outside of preload(), you may supply a callback function to handle the
  78543. * object:
  78544. * <div><code>
  78545. * function setup() {
  78546. * noLoop();
  78547. * let url =
  78548. 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/' +
  78549. * 'summary/all_day.geojson';
  78550. * loadJSON(url, drawEarthquake);
  78551. * }
  78552. *
  78553. * function draw() {
  78554. * background(200);
  78555. * }
  78556. *
  78557. * function drawEarthquake(earthquakes) {
  78558. * // Get the magnitude and name of the earthquake out of the loaded JSON
  78559. * let earthquakeMag = earthquakes.features[0].properties.mag;
  78560. * let earthquakeName = earthquakes.features[0].properties.place;
  78561. * ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10);
  78562. * textAlign(CENTER);
  78563. * text(earthquakeName, 0, height - 30, width, 30);
  78564. * }
  78565. * </code></div>
  78566. *
  78567. * @alt
  78568. * 50x50 ellipse that changes from black to white depending on the current humidity
  78569. * 50x50 ellipse that changes from black to white depending on the current humidity
  78570. */
  78571. /**
  78572. * @method loadJSON
  78573. * @param {String} path
  78574. * @param {String} datatype
  78575. * @param {function} [callback]
  78576. * @param {function} [errorCallback]
  78577. * @return {Object|Array}
  78578. */
  78579. /**
  78580. * @method loadJSON
  78581. * @param {String} path
  78582. * @param {function} callback
  78583. * @param {function} [errorCallback]
  78584. * @return {Object|Array}
  78585. */
  78586. _main.default.prototype.loadJSON = function() {
  78587. for (
  78588. var _len = arguments.length, args = new Array(_len), _key = 0;
  78589. _key < _len;
  78590. _key++
  78591. ) {
  78592. args[_key] = arguments[_key];
  78593. }
  78594. _main.default._validateParameters('loadJSON', args);
  78595. var path = args[0];
  78596. var callback;
  78597. var errorCallback;
  78598. var options;
  78599. var ret = {}; // object needed for preload
  78600. var t = 'json';
  78601. // check for explicit data type argument
  78602. for (var i = 1; i < args.length; i++) {
  78603. var arg = args[i];
  78604. if (typeof arg === 'string') {
  78605. if (arg === 'jsonp' || arg === 'json') {
  78606. t = arg;
  78607. }
  78608. } else if (typeof arg === 'function') {
  78609. if (!callback) {
  78610. callback = arg;
  78611. } else {
  78612. errorCallback = arg;
  78613. }
  78614. } else if (
  78615. _typeof(arg) === 'object' &&
  78616. (arg.hasOwnProperty('jsonpCallback') ||
  78617. arg.hasOwnProperty('jsonpCallbackFunction'))
  78618. ) {
  78619. t = 'jsonp';
  78620. options = arg;
  78621. }
  78622. }
  78623. var self = this;
  78624. this.httpDo(
  78625. path,
  78626. 'GET',
  78627. options,
  78628. t,
  78629. function(resp) {
  78630. for (var k in resp) {
  78631. ret[k] = resp[k];
  78632. }
  78633. if (typeof callback !== 'undefined') {
  78634. callback(resp);
  78635. }
  78636. self._decrementPreload();
  78637. },
  78638. function(err) {
  78639. // Error handling
  78640. _main.default._friendlyFileLoadError(5, path);
  78641. if (errorCallback) {
  78642. errorCallback(err);
  78643. } else {
  78644. throw err;
  78645. }
  78646. }
  78647. );
  78648. return ret;
  78649. };
  78650. /**
  78651. * Reads the contents of a file and creates a String array of its individual
  78652. * lines. If the name of the file is used as the parameter, as in the above
  78653. * example, the file must be located in the sketch directory/folder.
  78654. *
  78655. * Alternatively, the file maybe be loaded from anywhere on the local
  78656. * computer using an absolute path (something that starts with / on Unix and
  78657. * Linux, or a drive letter on Windows), or the filename parameter can be a
  78658. * URL for a file found on a network.
  78659. *
  78660. * This method is asynchronous, meaning it may not finish before the next
  78661. * line in your sketch is executed.
  78662. *
  78663. * This method is suitable for fetching files up to size of 64MB.
  78664. * @method loadStrings
  78665. * @param {String} filename name of the file or url to load
  78666. * @param {function} [callback] function to be executed after <a href="#/p5/loadStrings">loadStrings()</a>
  78667. * completes, Array is passed in as first
  78668. * argument
  78669. * @param {function} [errorCallback] function to be executed if
  78670. * there is an error, response is passed
  78671. * in as first argument
  78672. * @return {String[]} Array of Strings
  78673. * @example
  78674. *
  78675. * Calling loadStrings() inside <a href="#/p5/preload">preload()</a> guarantees to complete the
  78676. * operation before <a href="#/p5/setup">setup()</a> and <a href="#/p5/draw">draw()</a> are called.
  78677. *
  78678. * <div><code>
  78679. * let result;
  78680. * function preload() {
  78681. * result = loadStrings('assets/test.txt');
  78682. * }
  78683. * function setup() {
  78684. * background(200);
  78685. * text(random(result), 10, 10, 80, 80);
  78686. * }
  78687. * </code></div>
  78688. *
  78689. * Outside of preload(), you may supply a callback function to handle the
  78690. * object:
  78691. *
  78692. * <div><code>
  78693. * function setup() {
  78694. * loadStrings('assets/test.txt', pickString);
  78695. * }
  78696. *
  78697. * function pickString(result) {
  78698. * background(200);
  78699. * text(random(result), 10, 10, 80, 80);
  78700. * }
  78701. * </code></div>
  78702. *
  78703. * @alt
  78704. * randomly generated text from a file, for example "i smell like butter"
  78705. * randomly generated text from a file, for example "i have three feet"
  78706. */
  78707. _main.default.prototype.loadStrings = function() {
  78708. for (
  78709. var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
  78710. _key2 < _len2;
  78711. _key2++
  78712. ) {
  78713. args[_key2] = arguments[_key2];
  78714. }
  78715. _main.default._validateParameters('loadStrings', args);
  78716. var ret = [];
  78717. var callback, errorCallback;
  78718. for (var i = 1; i < args.length; i++) {
  78719. var arg = args[i];
  78720. if (typeof arg === 'function') {
  78721. if (typeof callback === 'undefined') {
  78722. callback = arg;
  78723. } else if (typeof errorCallback === 'undefined') {
  78724. errorCallback = arg;
  78725. }
  78726. }
  78727. }
  78728. var self = this;
  78729. _main.default.prototype.httpDo.call(
  78730. this,
  78731. args[0],
  78732. 'GET',
  78733. 'text',
  78734. function(data) {
  78735. // split lines handling mac/windows/linux endings
  78736. var lines = data
  78737. .replace(/\r\n/g, '\r')
  78738. .replace(/\n/g, '\r')
  78739. .split(/\r/);
  78740. // safe insert approach which will not blow up stack when inserting
  78741. // >100k lines, but still be faster than iterating line-by-line. based on
  78742. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply#Examples
  78743. var QUANTUM = 32768;
  78744. for (var _i = 0, len = lines.length; _i < len; _i += QUANTUM) {
  78745. Array.prototype.push.apply(
  78746. ret,
  78747. lines.slice(_i, Math.min(_i + QUANTUM, len))
  78748. );
  78749. }
  78750. if (typeof callback !== 'undefined') {
  78751. callback(ret);
  78752. }
  78753. self._decrementPreload();
  78754. },
  78755. function(err) {
  78756. // Error handling
  78757. _main.default._friendlyFileLoadError(3, arguments[0]);
  78758. if (errorCallback) {
  78759. errorCallback(err);
  78760. } else {
  78761. throw err;
  78762. }
  78763. }
  78764. );
  78765. return ret;
  78766. };
  78767. /**
  78768. * Reads the contents of a file or URL and creates a <a href="#/p5.Table">p5.Table</a> object with
  78769. * its values. If a file is specified, it must be located in the sketch's
  78770. * "data" folder. The filename parameter can also be a URL to a file found
  78771. * online. By default, the file is assumed to be comma-separated (in CSV
  78772. * format). Table only looks for a header row if the 'header' option is
  78773. * included.
  78774. *
  78775. * This method is asynchronous, meaning it may not finish before the next
  78776. * line in your sketch is executed. Calling <a href="#/p5/loadTable">loadTable()</a> inside <a href="#/p5/preload">preload()</a>
  78777. * guarantees to complete the operation before <a href="#/p5/setup">setup()</a> and <a href="#/p5/draw">draw()</a> are called.
  78778. * Outside of <a href="#/p5/preload">preload()</a>, you may supply a callback function to handle the
  78779. * object:
  78780. *
  78781. * All files loaded and saved use UTF-8 encoding. This method is suitable for fetching files up to size of 64MB.
  78782. * @method loadTable
  78783. * @param {String} filename name of the file or URL to load
  78784. * @param {String} [extension] parse the table by comma-separated values "csv", semicolon-separated
  78785. * values "ssv", or tab-separated values "tsv"
  78786. * @param {String} [header] "header" to indicate table has header row
  78787. * @param {function} [callback] function to be executed after
  78788. * <a href="#/p5/loadTable">loadTable()</a> completes. On success, the
  78789. * <a href="#/p5.Table">Table</a> object is passed in as the
  78790. * first argument.
  78791. * @param {function} [errorCallback] function to be executed if
  78792. * there is an error, response is passed
  78793. * in as first argument
  78794. * @return {Object} <a href="#/p5.Table">Table</a> object containing data
  78795. *
  78796. * @example
  78797. * <div class='norender'>
  78798. * <code>
  78799. * // Given the following CSV file called "mammals.csv"
  78800. * // located in the project's "assets" folder:
  78801. * //
  78802. * // id,species,name
  78803. * // 0,Capra hircus,Goat
  78804. * // 1,Panthera pardus,Leopard
  78805. * // 2,Equus zebra,Zebra
  78806. *
  78807. * let table;
  78808. *
  78809. * function preload() {
  78810. * //my table is comma separated value "csv"
  78811. * //and has a header specifying the columns labels
  78812. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  78813. * //the file can be remote
  78814. * //table = loadTable("http://p5js.org/reference/assets/mammals.csv",
  78815. * // "csv", "header");
  78816. * }
  78817. *
  78818. * function setup() {
  78819. * //count the columns
  78820. * print(table.getRowCount() + ' total rows in table');
  78821. * print(table.getColumnCount() + ' total columns in table');
  78822. *
  78823. * print(table.getColumn('name'));
  78824. * //["Goat", "Leopard", "Zebra"]
  78825. *
  78826. * //cycle through the table
  78827. * for (let r = 0; r < table.getRowCount(); r++)
  78828. * for (let c = 0; c < table.getColumnCount(); c++) {
  78829. * print(table.getString(r, c));
  78830. * }
  78831. * }
  78832. * </code>
  78833. * </div>
  78834. *
  78835. * @alt
  78836. * randomly generated text from a file, for example "i smell like butter"
  78837. * randomly generated text from a file, for example "i have three feet"
  78838. */
  78839. _main.default.prototype.loadTable = function(path) {
  78840. // p5._validateParameters('loadTable', arguments);
  78841. var callback;
  78842. var errorCallback;
  78843. var options = [];
  78844. var header = false;
  78845. var ext = path.substring(path.lastIndexOf('.') + 1, path.length);
  78846. var sep;
  78847. if (ext === 'csv') {
  78848. sep = ',';
  78849. } else if (ext === 'ssv') {
  78850. sep = ';';
  78851. } else if (ext === 'tsv') {
  78852. sep = '\t';
  78853. }
  78854. for (var i = 1; i < arguments.length; i++) {
  78855. if (typeof arguments[i] === 'function') {
  78856. if (typeof callback === 'undefined') {
  78857. callback = arguments[i];
  78858. } else if (typeof errorCallback === 'undefined') {
  78859. errorCallback = arguments[i];
  78860. }
  78861. } else if (typeof arguments[i] === 'string') {
  78862. options.push(arguments[i]);
  78863. if (arguments[i] === 'header') {
  78864. header = true;
  78865. }
  78866. if (arguments[i] === 'csv') {
  78867. sep = ',';
  78868. } else if (arguments[i] === 'ssv') {
  78869. sep = ';';
  78870. } else if (arguments[i] === 'tsv') {
  78871. sep = '\t';
  78872. }
  78873. }
  78874. }
  78875. var t = new _main.default.Table();
  78876. var self = this;
  78877. this.httpDo(
  78878. path,
  78879. 'GET',
  78880. 'table',
  78881. function(resp) {
  78882. var state = {};
  78883. // define constants
  78884. var PRE_TOKEN = 0,
  78885. MID_TOKEN = 1,
  78886. POST_TOKEN = 2,
  78887. POST_RECORD = 4;
  78888. var QUOTE = '"',
  78889. CR = '\r',
  78890. LF = '\n';
  78891. var records = [];
  78892. var offset = 0;
  78893. var currentRecord = null;
  78894. var currentChar;
  78895. var tokenBegin = function tokenBegin() {
  78896. state.currentState = PRE_TOKEN;
  78897. state.token = '';
  78898. };
  78899. var tokenEnd = function tokenEnd() {
  78900. currentRecord.push(state.token);
  78901. tokenBegin();
  78902. };
  78903. var recordBegin = function recordBegin() {
  78904. state.escaped = false;
  78905. currentRecord = [];
  78906. tokenBegin();
  78907. };
  78908. var recordEnd = function recordEnd() {
  78909. state.currentState = POST_RECORD;
  78910. records.push(currentRecord);
  78911. currentRecord = null;
  78912. };
  78913. for (;;) {
  78914. currentChar = resp[offset++];
  78915. // EOF
  78916. if (currentChar == null) {
  78917. if (state.escaped) {
  78918. throw new Error('Unclosed quote in file.');
  78919. }
  78920. if (currentRecord) {
  78921. tokenEnd();
  78922. recordEnd();
  78923. break;
  78924. }
  78925. }
  78926. if (currentRecord === null) {
  78927. recordBegin();
  78928. }
  78929. // Handle opening quote
  78930. if (state.currentState === PRE_TOKEN) {
  78931. if (currentChar === QUOTE) {
  78932. state.escaped = true;
  78933. state.currentState = MID_TOKEN;
  78934. continue;
  78935. }
  78936. state.currentState = MID_TOKEN;
  78937. }
  78938. // mid-token and escaped, look for sequences and end quote
  78939. if (state.currentState === MID_TOKEN && state.escaped) {
  78940. if (currentChar === QUOTE) {
  78941. if (resp[offset] === QUOTE) {
  78942. state.token += QUOTE;
  78943. offset++;
  78944. } else {
  78945. state.escaped = false;
  78946. state.currentState = POST_TOKEN;
  78947. }
  78948. } else if (currentChar === CR) {
  78949. continue;
  78950. } else {
  78951. state.token += currentChar;
  78952. }
  78953. continue;
  78954. }
  78955. // fall-through: mid-token or post-token, not escaped
  78956. if (currentChar === CR) {
  78957. if (resp[offset] === LF) {
  78958. offset++;
  78959. }
  78960. tokenEnd();
  78961. recordEnd();
  78962. } else if (currentChar === LF) {
  78963. tokenEnd();
  78964. recordEnd();
  78965. } else if (currentChar === sep) {
  78966. tokenEnd();
  78967. } else if (state.currentState === MID_TOKEN) {
  78968. state.token += currentChar;
  78969. }
  78970. }
  78971. // set up column names
  78972. if (header) {
  78973. t.columns = records.shift();
  78974. } else {
  78975. for (var _i2 = 0; _i2 < records[0].length; _i2++) {
  78976. t.columns[_i2] = 'null';
  78977. }
  78978. }
  78979. var row;
  78980. for (var _i3 = 0; _i3 < records.length; _i3++) {
  78981. //Handles row of 'undefined' at end of some CSVs
  78982. if (records[_i3].length === 1) {
  78983. if (records[_i3][0] === 'undefined' || records[_i3][0] === '') {
  78984. continue;
  78985. }
  78986. }
  78987. row = new _main.default.TableRow();
  78988. row.arr = records[_i3];
  78989. row.obj = makeObject(records[_i3], t.columns);
  78990. t.addRow(row);
  78991. }
  78992. if (typeof callback === 'function') {
  78993. callback(t);
  78994. }
  78995. self._decrementPreload();
  78996. },
  78997. function(err) {
  78998. // Error handling
  78999. _main.default._friendlyFileLoadError(2, path);
  79000. if (errorCallback) {
  79001. errorCallback(err);
  79002. } else {
  79003. console.error(err);
  79004. }
  79005. }
  79006. );
  79007. return t;
  79008. };
  79009. // helper function to turn a row into a JSON object
  79010. function makeObject(row, headers) {
  79011. var ret = {};
  79012. headers = headers || [];
  79013. if (typeof headers === 'undefined') {
  79014. for (var j = 0; j < row.length; j++) {
  79015. headers[j.toString()] = j;
  79016. }
  79017. }
  79018. for (var i = 0; i < headers.length; i++) {
  79019. var key = headers[i];
  79020. var val = row[i];
  79021. ret[key] = val;
  79022. }
  79023. return ret;
  79024. }
  79025. /**
  79026. * Reads the contents of a file and creates an XML object with its values.
  79027. * If the name of the file is used as the parameter, as in the above example,
  79028. * the file must be located in the sketch directory/folder.
  79029. *
  79030. * Alternatively, the file maybe be loaded from anywhere on the local
  79031. * computer using an absolute path (something that starts with / on Unix and
  79032. * Linux, or a drive letter on Windows), or the filename parameter can be a
  79033. * URL for a file found on a network.
  79034. *
  79035. * This method is asynchronous, meaning it may not finish before the next
  79036. * line in your sketch is executed. Calling <a href="#/p5/loadXML">loadXML()</a> inside <a href="#/p5/preload">preload()</a>
  79037. * guarantees to complete the operation before <a href="#/p5/setup">setup()</a> and <a href="#/p5/draw">draw()</a> are called.
  79038. *
  79039. * Outside of <a href="#/p5/preload">preload()</a>, you may supply a callback function to handle the
  79040. * object.
  79041. *
  79042. * This method is suitable for fetching files up to size of 64MB.
  79043. * @method loadXML
  79044. * @param {String} filename name of the file or URL to load
  79045. * @param {function} [callback] function to be executed after <a href="#/p5/loadXML">loadXML()</a>
  79046. * completes, XML object is passed in as
  79047. * first argument
  79048. * @param {function} [errorCallback] function to be executed if
  79049. * there is an error, response is passed
  79050. * in as first argument
  79051. * @return {Object} XML object containing data
  79052. * @example
  79053. * <div class='norender'><code>
  79054. * // The following short XML file called "mammals.xml" is parsed
  79055. * // in the code below.
  79056. * //
  79057. * // <?xml version="1.0"?>
  79058. * // &lt;mammals&gt;
  79059. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  79060. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  79061. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  79062. * // &lt;/mammals&gt;
  79063. *
  79064. * let xml;
  79065. *
  79066. * function preload() {
  79067. * xml = loadXML('assets/mammals.xml');
  79068. * }
  79069. *
  79070. * function setup() {
  79071. * let children = xml.getChildren('animal');
  79072. *
  79073. * for (let i = 0; i < children.length; i++) {
  79074. * let id = children[i].getNum('id');
  79075. * let coloring = children[i].getString('species');
  79076. * let name = children[i].getContent();
  79077. * print(id + ', ' + coloring + ', ' + name);
  79078. * }
  79079. * }
  79080. *
  79081. * // Sketch prints:
  79082. * // 0, Capra hircus, Goat
  79083. * // 1, Panthera pardus, Leopard
  79084. * // 2, Equus zebra, Zebra
  79085. * </code></div>
  79086. *
  79087. * @alt
  79088. * no image displayed
  79089. */
  79090. _main.default.prototype.loadXML = function() {
  79091. for (
  79092. var _len3 = arguments.length, args = new Array(_len3), _key3 = 0;
  79093. _key3 < _len3;
  79094. _key3++
  79095. ) {
  79096. args[_key3] = arguments[_key3];
  79097. }
  79098. var ret = new _main.default.XML();
  79099. var callback, errorCallback;
  79100. for (var i = 1; i < args.length; i++) {
  79101. var arg = args[i];
  79102. if (typeof arg === 'function') {
  79103. if (typeof callback === 'undefined') {
  79104. callback = arg;
  79105. } else if (typeof errorCallback === 'undefined') {
  79106. errorCallback = arg;
  79107. }
  79108. }
  79109. }
  79110. var self = this;
  79111. this.httpDo(
  79112. args[0],
  79113. 'GET',
  79114. 'xml',
  79115. function(xml) {
  79116. for (var key in xml) {
  79117. ret[key] = xml[key];
  79118. }
  79119. if (typeof callback !== 'undefined') {
  79120. callback(ret);
  79121. }
  79122. self._decrementPreload();
  79123. },
  79124. function(err) {
  79125. // Error handling
  79126. _main.default._friendlyFileLoadError(1, arguments[0]);
  79127. if (errorCallback) {
  79128. errorCallback(err);
  79129. } else {
  79130. throw err;
  79131. }
  79132. }
  79133. );
  79134. return ret;
  79135. };
  79136. /**
  79137. * This method is suitable for fetching files up to size of 64MB.
  79138. * @method loadBytes
  79139. * @param {string} file name of the file or URL to load
  79140. * @param {function} [callback] function to be executed after <a href="#/p5/loadBytes">loadBytes()</a>
  79141. * completes
  79142. * @param {function} [errorCallback] function to be executed if there
  79143. * is an error
  79144. * @returns {Object} an object whose 'bytes' property will be the loaded buffer
  79145. *
  79146. * @example
  79147. * <div class='norender'><code>
  79148. * let data;
  79149. *
  79150. * function preload() {
  79151. * data = loadBytes('assets/mammals.xml');
  79152. * }
  79153. *
  79154. * function setup() {
  79155. * for (let i = 0; i < 5; i++) {
  79156. * console.log(data.bytes[i].toString(16));
  79157. * }
  79158. * }
  79159. * </code></div>
  79160. *
  79161. * @alt
  79162. * no image displayed
  79163. */
  79164. _main.default.prototype.loadBytes = function(file, callback, errorCallback) {
  79165. var ret = {};
  79166. var self = this;
  79167. this.httpDo(
  79168. file,
  79169. 'GET',
  79170. 'arrayBuffer',
  79171. function(arrayBuffer) {
  79172. ret.bytes = new Uint8Array(arrayBuffer);
  79173. if (typeof callback === 'function') {
  79174. callback(ret);
  79175. }
  79176. self._decrementPreload();
  79177. },
  79178. function(err) {
  79179. // Error handling
  79180. _main.default._friendlyFileLoadError(6, file);
  79181. if (errorCallback) {
  79182. errorCallback(err);
  79183. } else {
  79184. throw err;
  79185. }
  79186. }
  79187. );
  79188. return ret;
  79189. };
  79190. /**
  79191. * Method for executing an HTTP GET request. If data type is not specified,
  79192. * p5 will try to guess based on the URL, defaulting to text. This is equivalent to
  79193. * calling <code>httpDo(path, 'GET')</code>. The 'binary' datatype will return
  79194. * a Blob object, and the 'arrayBuffer' datatype will return an ArrayBuffer
  79195. * which can be used to initialize typed arrays (such as Uint8Array).
  79196. *
  79197. * @method httpGet
  79198. * @param {String} path name of the file or url to load
  79199. * @param {String} [datatype] "json", "jsonp", "binary", "arrayBuffer",
  79200. * "xml", or "text"
  79201. * @param {Object|Boolean} [data] param data passed sent with request
  79202. * @param {function} [callback] function to be executed after
  79203. * <a href="#/p5/httpGet">httpGet()</a> completes, data is passed in
  79204. * as first argument
  79205. * @param {function} [errorCallback] function to be executed if
  79206. * there is an error, response is passed
  79207. * in as first argument
  79208. * @return {Promise} A promise that resolves with the data when the operation
  79209. * completes successfully or rejects with the error after
  79210. * one occurs.
  79211. * @example
  79212. * <div class='norender'><code>
  79213. * // Examples use USGS Earthquake API:
  79214. * // https://earthquake.usgs.gov/fdsnws/event/1/#methods
  79215. * let earthquakes;
  79216. * function preload() {
  79217. * // Get the most recent earthquake in the database
  79218. * let url =
  79219. 'https://earthquake.usgs.gov/fdsnws/event/1/query?' +
  79220. * 'format=geojson&limit=1&orderby=time';
  79221. * httpGet(url, 'jsonp', false, function(response) {
  79222. * // when the HTTP request completes, populate the variable that holds the
  79223. * // earthquake data used in the visualization.
  79224. * earthquakes = response;
  79225. * });
  79226. * }
  79227. *
  79228. * function draw() {
  79229. * if (!earthquakes) {
  79230. * // Wait until the earthquake data has loaded before drawing.
  79231. * return;
  79232. * }
  79233. * background(200);
  79234. * // Get the magnitude and name of the earthquake out of the loaded JSON
  79235. * let earthquakeMag = earthquakes.features[0].properties.mag;
  79236. * let earthquakeName = earthquakes.features[0].properties.place;
  79237. * ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10);
  79238. * textAlign(CENTER);
  79239. * text(earthquakeName, 0, height - 30, width, 30);
  79240. * noLoop();
  79241. * }
  79242. * </code></div>
  79243. */
  79244. /**
  79245. * @method httpGet
  79246. * @param {String} path
  79247. * @param {Object|Boolean} data
  79248. * @param {function} [callback]
  79249. * @param {function} [errorCallback]
  79250. * @return {Promise}
  79251. */
  79252. /**
  79253. * @method httpGet
  79254. * @param {String} path
  79255. * @param {function} callback
  79256. * @param {function} [errorCallback]
  79257. * @return {Promise}
  79258. */
  79259. _main.default.prototype.httpGet = function() {
  79260. _main.default._validateParameters('httpGet', arguments);
  79261. var args = Array.prototype.slice.call(arguments);
  79262. args.splice(1, 0, 'GET');
  79263. return _main.default.prototype.httpDo.apply(this, args);
  79264. };
  79265. /**
  79266. * Method for executing an HTTP POST request. If data type is not specified,
  79267. * p5 will try to guess based on the URL, defaulting to text. This is equivalent to
  79268. * calling <code>httpDo(path, 'POST')</code>.
  79269. *
  79270. * @method httpPost
  79271. * @param {String} path name of the file or url to load
  79272. * @param {String} [datatype] "json", "jsonp", "xml", or "text".
  79273. * If omitted, <a href="#/p5/httpPost">httpPost()</a> will guess.
  79274. * @param {Object|Boolean} [data] param data passed sent with request
  79275. * @param {function} [callback] function to be executed after
  79276. * <a href="#/p5/httpPost">httpPost()</a> completes, data is passed in
  79277. * as first argument
  79278. * @param {function} [errorCallback] function to be executed if
  79279. * there is an error, response is passed
  79280. * in as first argument
  79281. * @return {Promise} A promise that resolves with the data when the operation
  79282. * completes successfully or rejects with the error after
  79283. * one occurs.
  79284. *
  79285. * @example
  79286. * <div>
  79287. * <code>
  79288. * // Examples use jsonplaceholder.typicode.com for a Mock Data API
  79289. *
  79290. * let url = 'https://jsonplaceholder.typicode.com/posts';
  79291. * let postData = { userId: 1, title: 'p5 Clicked!', body: 'p5.js is very cool.' };
  79292. *
  79293. * function setup() {
  79294. * createCanvas(100, 100);
  79295. * background(200);
  79296. * }
  79297. *
  79298. * function mousePressed() {
  79299. * httpPost(url, 'json', postData, function(result) {
  79300. * strokeWeight(2);
  79301. * text(result.body, mouseX, mouseY);
  79302. * });
  79303. * }
  79304. * </code>
  79305. * </div>
  79306. *
  79307. * <div><code>
  79308. * let url = 'ttps://invalidURL'; // A bad URL that will cause errors
  79309. * let postData = { title: 'p5 Clicked!', body: 'p5.js is very cool.' };
  79310. *
  79311. * function setup() {
  79312. * createCanvas(100, 100);
  79313. * background(200);
  79314. * }
  79315. *
  79316. * function mousePressed() {
  79317. * httpPost(
  79318. * url,
  79319. * 'json',
  79320. * postData,
  79321. * function(result) {
  79322. * // ... won't be called
  79323. * },
  79324. * function(error) {
  79325. * strokeWeight(2);
  79326. * text(error.toString(), mouseX, mouseY);
  79327. * }
  79328. * );
  79329. * }
  79330. * </code></div>
  79331. */
  79332. /**
  79333. * @method httpPost
  79334. * @param {String} path
  79335. * @param {Object|Boolean} data
  79336. * @param {function} [callback]
  79337. * @param {function} [errorCallback]
  79338. * @return {Promise}
  79339. */
  79340. /**
  79341. * @method httpPost
  79342. * @param {String} path
  79343. * @param {function} callback
  79344. * @param {function} [errorCallback]
  79345. * @return {Promise}
  79346. */
  79347. _main.default.prototype.httpPost = function() {
  79348. _main.default._validateParameters('httpPost', arguments);
  79349. var args = Array.prototype.slice.call(arguments);
  79350. args.splice(1, 0, 'POST');
  79351. return _main.default.prototype.httpDo.apply(this, args);
  79352. };
  79353. /**
  79354. * Method for executing an HTTP request. If data type is not specified,
  79355. * p5 will try to guess based on the URL, defaulting to text.<br><br>
  79356. * For more advanced use, you may also pass in the path as the first argument
  79357. * and a object as the second argument, the signature follows the one specified
  79358. * in the Fetch API specification.
  79359. * This method is suitable for fetching files up to size of 64MB when "GET" is used.
  79360. *
  79361. * @method httpDo
  79362. * @param {String} path name of the file or url to load
  79363. * @param {String} [method] either "GET", "POST", or "PUT",
  79364. * defaults to "GET"
  79365. * @param {String} [datatype] "json", "jsonp", "xml", or "text"
  79366. * @param {Object} [data] param data passed sent with request
  79367. * @param {function} [callback] function to be executed after
  79368. * <a href="#/p5/httpGet">httpGet()</a> completes, data is passed in
  79369. * as first argument
  79370. * @param {function} [errorCallback] function to be executed if
  79371. * there is an error, response is passed
  79372. * in as first argument
  79373. * @return {Promise} A promise that resolves with the data when the operation
  79374. * completes successfully or rejects with the error after
  79375. * one occurs.
  79376. *
  79377. * @example
  79378. * <div>
  79379. * <code>
  79380. * // Examples use USGS Earthquake API:
  79381. * // https://earthquake.usgs.gov/fdsnws/event/1/#methods
  79382. *
  79383. * // displays an animation of all USGS earthquakes
  79384. * let earthquakes;
  79385. * let eqFeatureIndex = 0;
  79386. *
  79387. * function preload() {
  79388. * let url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson';
  79389. * httpDo(
  79390. * url,
  79391. * {
  79392. * method: 'GET',
  79393. * // Other Request options, like special headers for apis
  79394. * headers: { authorization: 'Bearer secretKey' }
  79395. * },
  79396. * function(res) {
  79397. * earthquakes = res;
  79398. * }
  79399. * );
  79400. * }
  79401. *
  79402. * function draw() {
  79403. * // wait until the data is loaded
  79404. * if (!earthquakes || !earthquakes.features[eqFeatureIndex]) {
  79405. * return;
  79406. * }
  79407. * clear();
  79408. *
  79409. * let feature = earthquakes.features[eqFeatureIndex];
  79410. * let mag = feature.properties.mag;
  79411. * let rad = mag / 11 * ((width + height) / 2);
  79412. * fill(255, 0, 0, 100);
  79413. * ellipse(width / 2 + random(-2, 2), height / 2 + random(-2, 2), rad, rad);
  79414. *
  79415. * if (eqFeatureIndex >= earthquakes.features.length) {
  79416. * eqFeatureIndex = 0;
  79417. * } else {
  79418. * eqFeatureIndex += 1;
  79419. * }
  79420. * }
  79421. * </code>
  79422. * </div>
  79423. */
  79424. /**
  79425. * @method httpDo
  79426. * @param {String} path
  79427. * @param {Object} options Request object options as documented in the
  79428. * "fetch" API
  79429. * <a href="https://developer.mozilla.org/en/docs/Web/API/Fetch_API">reference</a>
  79430. * @param {function} [callback]
  79431. * @param {function} [errorCallback]
  79432. * @return {Promise}
  79433. */
  79434. _main.default.prototype.httpDo = function() {
  79435. var type;
  79436. var callback;
  79437. var errorCallback;
  79438. var request;
  79439. var promise;
  79440. var jsonpOptions = {};
  79441. var cbCount = 0;
  79442. var contentType = 'text/plain';
  79443. // Trim the callbacks off the end to get an idea of how many arguments are passed
  79444. for (var i = arguments.length - 1; i > 0; i--) {
  79445. if (
  79446. typeof (i < 0 || arguments.length <= i ? undefined : arguments[i]) ===
  79447. 'function'
  79448. ) {
  79449. cbCount++;
  79450. } else {
  79451. break;
  79452. }
  79453. }
  79454. // The number of arguments minus callbacks
  79455. var argsCount = arguments.length - cbCount;
  79456. var path = arguments.length <= 0 ? undefined : arguments[0];
  79457. if (
  79458. argsCount === 2 &&
  79459. typeof path === 'string' &&
  79460. _typeof(arguments.length <= 1 ? undefined : arguments[1]) === 'object'
  79461. ) {
  79462. // Intended for more advanced use, pass in Request parameters directly
  79463. request = new Request(path, arguments.length <= 1 ? undefined : arguments[1]);
  79464. callback = arguments.length <= 2 ? undefined : arguments[2];
  79465. errorCallback = arguments.length <= 3 ? undefined : arguments[3];
  79466. } else {
  79467. // Provided with arguments
  79468. var method = 'GET';
  79469. var data;
  79470. for (var j = 1; j < arguments.length; j++) {
  79471. var a = j < 0 || arguments.length <= j ? undefined : arguments[j];
  79472. if (typeof a === 'string') {
  79473. if (a === 'GET' || a === 'POST' || a === 'PUT' || a === 'DELETE') {
  79474. method = a;
  79475. } else if (
  79476. a === 'json' ||
  79477. a === 'jsonp' ||
  79478. a === 'binary' ||
  79479. a === 'arrayBuffer' ||
  79480. a === 'xml' ||
  79481. a === 'text' ||
  79482. a === 'table'
  79483. ) {
  79484. type = a;
  79485. } else {
  79486. data = a;
  79487. }
  79488. } else if (typeof a === 'number') {
  79489. data = a.toString();
  79490. } else if (_typeof(a) === 'object') {
  79491. if (
  79492. a.hasOwnProperty('jsonpCallback') ||
  79493. a.hasOwnProperty('jsonpCallbackFunction')
  79494. ) {
  79495. for (var attr in a) {
  79496. jsonpOptions[attr] = a[attr];
  79497. }
  79498. } else if (a instanceof _main.default.XML) {
  79499. data = a.serialize();
  79500. contentType = 'application/xml';
  79501. } else {
  79502. data = JSON.stringify(a);
  79503. contentType = 'application/json';
  79504. }
  79505. } else if (typeof a === 'function') {
  79506. if (!callback) {
  79507. callback = a;
  79508. } else {
  79509. errorCallback = a;
  79510. }
  79511. }
  79512. }
  79513. var headers =
  79514. method === 'GET'
  79515. ? new Headers()
  79516. : new Headers({ 'Content-Type': contentType });
  79517. request = new Request(path, {
  79518. method: method,
  79519. mode: 'cors',
  79520. body: data,
  79521. headers: headers
  79522. });
  79523. }
  79524. // do some sort of smart type checking
  79525. if (!type) {
  79526. if (path.includes('json')) {
  79527. type = 'json';
  79528. } else if (path.includes('xml')) {
  79529. type = 'xml';
  79530. } else {
  79531. type = 'text';
  79532. }
  79533. }
  79534. if (type === 'jsonp') {
  79535. promise = (0, _fetchJsonp.default)(path, jsonpOptions);
  79536. } else {
  79537. promise = fetch(request);
  79538. }
  79539. promise = promise.then(function(res) {
  79540. if (!res.ok) {
  79541. var err = new Error(res.body);
  79542. err.status = res.status;
  79543. err.ok = false;
  79544. throw err;
  79545. } else {
  79546. var fileSize = 0;
  79547. if (type !== 'jsonp') {
  79548. fileSize = res.headers.get('content-length');
  79549. }
  79550. if (fileSize && fileSize > 64000000) {
  79551. _main.default._friendlyFileLoadError(7, path);
  79552. }
  79553. switch (type) {
  79554. case 'json':
  79555. case 'jsonp':
  79556. return res.json();
  79557. case 'binary':
  79558. return res.blob();
  79559. case 'arrayBuffer':
  79560. return res.arrayBuffer();
  79561. case 'xml':
  79562. return res.text().then(function(text) {
  79563. var parser = new DOMParser();
  79564. var xml = parser.parseFromString(text, 'text/xml');
  79565. return new _main.default.XML(xml.documentElement);
  79566. });
  79567. default:
  79568. return res.text();
  79569. }
  79570. }
  79571. });
  79572. promise.then(callback || function() {});
  79573. promise.catch(errorCallback || console.error);
  79574. return promise;
  79575. };
  79576. /**
  79577. * @module IO
  79578. * @submodule Output
  79579. * @for p5
  79580. */
  79581. window.URL = window.URL || window.webkitURL;
  79582. // private array of p5.PrintWriter objects
  79583. _main.default.prototype._pWriters = [];
  79584. /**
  79585. * @method createWriter
  79586. * @param {String} name name of the file to be created
  79587. * @param {String} [extension]
  79588. * @return {p5.PrintWriter}
  79589. * @example
  79590. * <div>
  79591. * <code>
  79592. * function setup() {
  79593. * createCanvas(100, 100);
  79594. * background(200);
  79595. * text('click here to save', 10, 10, 70, 80);
  79596. * }
  79597. *
  79598. * function mousePressed() {
  79599. * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
  79600. * const writer = createWriter('squares.txt');
  79601. * for (let i = 0; i < 10; i++) {
  79602. * writer.print(i * i);
  79603. * }
  79604. * writer.close();
  79605. * writer.clear();
  79606. * }
  79607. * }
  79608. * </code>
  79609. * </div>
  79610. */
  79611. _main.default.prototype.createWriter = function(name, extension) {
  79612. var newPW;
  79613. // check that it doesn't already exist
  79614. for (var i in _main.default.prototype._pWriters) {
  79615. if (_main.default.prototype._pWriters[i].name === name) {
  79616. // if a p5.PrintWriter w/ this name already exists...
  79617. // return p5.prototype._pWriters[i]; // return it w/ contents intact.
  79618. // or, could return a new, empty one with a unique name:
  79619. newPW = new _main.default.PrintWriter(name + this.millis(), extension);
  79620. _main.default.prototype._pWriters.push(newPW);
  79621. return newPW;
  79622. }
  79623. }
  79624. newPW = new _main.default.PrintWriter(name, extension);
  79625. _main.default.prototype._pWriters.push(newPW);
  79626. return newPW;
  79627. };
  79628. /**
  79629. * @class p5.PrintWriter
  79630. * @param {String} filename
  79631. * @param {String} [extension]
  79632. */
  79633. _main.default.PrintWriter = function(filename, extension) {
  79634. var self = this;
  79635. this.name = filename;
  79636. this.content = '';
  79637. //Changed to write because it was being overloaded by function below.
  79638. /**
  79639. * Writes data to the PrintWriter stream
  79640. * @method write
  79641. * @param {Array} data all data to be written by the PrintWriter
  79642. * @example
  79643. * <div class="norender notest">
  79644. * <code>
  79645. * // creates a file called 'newFile.txt'
  79646. * let writer = createWriter('newFile.txt');
  79647. * // write 'Hello world!'' to the file
  79648. * writer.write(['Hello world!']);
  79649. * // close the PrintWriter and save the file
  79650. * writer.close();
  79651. * </code>
  79652. * </div>
  79653. * <div class='norender notest'>
  79654. * <code>
  79655. * // creates a file called 'newFile2.txt'
  79656. * let writer = createWriter('newFile2.txt');
  79657. * // write 'apples,bananas,123' to the file
  79658. * writer.write(['apples', 'bananas', 123]);
  79659. * // close the PrintWriter and save the file
  79660. * writer.close();
  79661. * </code>
  79662. * </div>
  79663. * <div class='norender notest'>
  79664. * <code>
  79665. * // creates a file called 'newFile3.txt'
  79666. * let writer = createWriter('newFile3.txt');
  79667. * // write 'My name is: Teddy' to the file
  79668. * writer.write('My name is:');
  79669. * writer.write(' Teddy');
  79670. * // close the PrintWriter and save the file
  79671. * writer.close();
  79672. * </code>
  79673. * </div>
  79674. * <div>
  79675. * <code>
  79676. * function setup() {
  79677. * createCanvas(100, 100);
  79678. * button = createButton('SAVE FILE');
  79679. * button.position(21, 40);
  79680. * button.mousePressed(createFile);
  79681. * }
  79682. *
  79683. * function createFile() {
  79684. * // creates a file called 'newFile.txt'
  79685. * let writer = createWriter('newFile.txt');
  79686. * // write 'Hello world!'' to the file
  79687. * writer.write(['Hello world!']);
  79688. * // close the PrintWriter and save the file
  79689. * writer.close();
  79690. * }
  79691. * </code>
  79692. * </div>
  79693. */
  79694. this.write = function(data) {
  79695. this.content += data;
  79696. };
  79697. /**
  79698. * Writes data to the PrintWriter stream, and adds a new line at the end
  79699. * @method print
  79700. * @param {Array} data all data to be printed by the PrintWriter
  79701. * @example
  79702. * <div class='norender notest'>
  79703. * <code>
  79704. * // creates a file called 'newFile.txt'
  79705. * let writer = createWriter('newFile.txt');
  79706. * // creates a file containing
  79707. * // My name is:
  79708. * // Teddy
  79709. * writer.print('My name is:');
  79710. * writer.print('Teddy');
  79711. * // close the PrintWriter and save the file
  79712. * writer.close();
  79713. * </code>
  79714. * </div>
  79715. * <div class='norender notest'>
  79716. * <code>
  79717. * let writer;
  79718. *
  79719. * function setup() {
  79720. * createCanvas(400, 400);
  79721. * // create a PrintWriter
  79722. * writer = createWriter('newFile.txt');
  79723. * }
  79724. *
  79725. * function draw() {
  79726. * writer.print([mouseX, mouseY]);
  79727. * }
  79728. *
  79729. * function mouseClicked() {
  79730. * writer.close();
  79731. * }
  79732. * </code>
  79733. * </div>
  79734. */
  79735. this.print = function(data) {
  79736. this.content += ''.concat(data, '\n');
  79737. };
  79738. /**
  79739. * Clears the data already written to the PrintWriter object
  79740. * @method clear
  79741. * @example
  79742. * <div class ="norender notest"><code>
  79743. * // create writer object
  79744. * let writer = createWriter('newFile.txt');
  79745. * writer.write(['clear me']);
  79746. * // clear writer object here
  79747. * writer.clear();
  79748. * // close writer
  79749. * writer.close();
  79750. * </code></div>
  79751. * <div>
  79752. * <code>
  79753. * function setup() {
  79754. * button = createButton('CLEAR ME');
  79755. * button.position(21, 40);
  79756. * button.mousePressed(createFile);
  79757. * }
  79758. *
  79759. * function createFile() {
  79760. * let writer = createWriter('newFile.txt');
  79761. * writer.write(['clear me']);
  79762. * writer.clear();
  79763. * writer.close();
  79764. * }
  79765. * </code>
  79766. * </div>
  79767. *
  79768. */
  79769. this.clear = function() {
  79770. this.content = '';
  79771. };
  79772. /**
  79773. * Closes the PrintWriter
  79774. * @method close
  79775. * @example
  79776. * <div class="norender notest">
  79777. * <code>
  79778. * // create a file called 'newFile.txt'
  79779. * let writer = createWriter('newFile.txt');
  79780. * // close the PrintWriter and save the file
  79781. * writer.close();
  79782. * </code>
  79783. * </div>
  79784. * <div class='norender notest'>
  79785. * <code>
  79786. * // create a file called 'newFile2.txt'
  79787. * let writer = createWriter('newFile2.txt');
  79788. * // write some data to the file
  79789. * writer.write([100, 101, 102]);
  79790. * // close the PrintWriter and save the file
  79791. * writer.close();
  79792. * </code>
  79793. * </div>
  79794. */
  79795. this.close = function() {
  79796. // convert String to Array for the writeFile Blob
  79797. var arr = [];
  79798. arr.push(this.content);
  79799. _main.default.prototype.writeFile(arr, filename, extension);
  79800. // remove from _pWriters array and delete self
  79801. for (var i in _main.default.prototype._pWriters) {
  79802. if (_main.default.prototype._pWriters[i].name === this.name) {
  79803. // remove from _pWriters array
  79804. _main.default.prototype._pWriters.splice(i, 1);
  79805. }
  79806. }
  79807. self.clear();
  79808. self = {};
  79809. };
  79810. };
  79811. /**
  79812. * @module IO
  79813. * @submodule Output
  79814. * @for p5
  79815. */
  79816. // object, filename, options --> saveJSON, saveStrings,
  79817. // filename, [extension] [canvas] --> saveImage
  79818. /**
  79819. * Saves a given element(image, text, json, csv, wav, or html) to the client's
  79820. * computer. The first parameter can be a pointer to element we want to save.
  79821. * The element can be one of <a href="#/p5.Element">p5.Element</a>,an Array of
  79822. * Strings, an Array of JSON, a JSON object, a <a href="#/p5.Table">p5.Table
  79823. * </a>, a <a href="#/p5.Image">p5.Image</a>, or a p5.SoundFile (requires
  79824. * p5.sound). The second parameter is a filename (including extension).The
  79825. * third parameter is for options specific to this type of object. This method
  79826. * will save a file that fits the given parameters.
  79827. * If it is called without specifying an element, by default it will save the
  79828. * whole canvas as an image file. You can optionally specify a filename as
  79829. * the first parameter in such a case.
  79830. * **Note that it is not recommended to
  79831. * call this method within draw, as it will open a new save dialog on every
  79832. * render.**
  79833. *
  79834. * @method save
  79835. * @param {Object|String} [objectOrFilename] If filename is provided, will
  79836. * save canvas as an image with
  79837. * either png or jpg extension
  79838. * depending on the filename.
  79839. * If object is provided, will
  79840. * save depending on the object
  79841. * and filename (see examples
  79842. * above).
  79843. * @param {String} [filename] If an object is provided as the first
  79844. * parameter, then the second parameter
  79845. * indicates the filename,
  79846. * and should include an appropriate
  79847. * file extension (see examples above).
  79848. * @param {Boolean|String} [options] Additional options depend on
  79849. * filetype. For example, when saving JSON,
  79850. * <code>true</code> indicates that the
  79851. * output will be optimized for filesize,
  79852. * rather than readability.
  79853. *
  79854. * @example
  79855. * <div class="norender"><code>
  79856. * // Saves the canvas as an image
  79857. * cnv = createCanvas(300, 300);
  79858. * save(cnv, 'myCanvas.jpg');
  79859. *
  79860. * // Saves the canvas as an image by default
  79861. * save('myCanvas.jpg');
  79862. * </code></div>
  79863. *
  79864. * <div class="norender"><code>
  79865. * // Saves p5.Image as an image
  79866. * img = createImage(10, 10);
  79867. * save(img, 'myImage.png');
  79868. * </code></div>
  79869. *
  79870. * <div class="norender"><code>
  79871. * // Saves p5.Renderer object as an image
  79872. * obj = createGraphics(100, 100);
  79873. * save(obj, 'myObject.png');
  79874. * </code></div>
  79875. *
  79876. * <div class="norender"><code>
  79877. * let myTable = new p5.Table();
  79878. * // Saves table as html file
  79879. * save(myTable, 'myTable.html');
  79880. *
  79881. * // Comma Separated Values
  79882. * save(myTable, 'myTable.csv');
  79883. *
  79884. * // Tab Separated Values
  79885. * save(myTable, 'myTable.tsv');
  79886. * </code></div>
  79887. *
  79888. * <div class="norender"><code>
  79889. * let myJSON = { a: 1, b: true };
  79890. *
  79891. * // Saves pretty JSON
  79892. * save(myJSON, 'my.json');
  79893. *
  79894. * // Optimizes JSON filesize
  79895. * save(myJSON, 'my.json', true);
  79896. * </code></div>
  79897. *
  79898. * <div class="norender"><code>
  79899. * // Saves array of strings to text file with line breaks after each item
  79900. * let arrayOfStrings = ['a', 'b'];
  79901. * save(arrayOfStrings, 'my.txt');
  79902. * </code></div>
  79903. *
  79904. * @alt
  79905. * An example for saving a canvas as an image.
  79906. * An example for saving a p5.Image element as an image.
  79907. * An example for saving a p5.Renderer element.
  79908. * An example showing how to save a table in formats of HTML, CSV and TSV.
  79909. * An example for saving JSON to a txt file with some extra arguments.
  79910. * An example for saving an array of strings to text file with line breaks.
  79911. */
  79912. _main.default.prototype.save = function(object, _filename, _options) {
  79913. // parse the arguments and figure out which things we are saving
  79914. var args = arguments;
  79915. // =================================================
  79916. // OPTION 1: saveCanvas...
  79917. // if no arguments are provided, save canvas
  79918. var cnv = this._curElement ? this._curElement.elt : this.elt;
  79919. if (args.length === 0) {
  79920. _main.default.prototype.saveCanvas(cnv);
  79921. return;
  79922. } else if (
  79923. args[0] instanceof _main.default.Renderer ||
  79924. args[0] instanceof _main.default.Graphics
  79925. ) {
  79926. // otherwise, parse the arguments
  79927. // if first param is a p5Graphics, then saveCanvas
  79928. _main.default.prototype.saveCanvas(args[0].elt, args[1], args[2]);
  79929. return;
  79930. } else if (args.length === 1 && typeof args[0] === 'string') {
  79931. // if 1st param is String and only one arg, assume it is canvas filename
  79932. _main.default.prototype.saveCanvas(cnv, args[0]);
  79933. } else {
  79934. // =================================================
  79935. // OPTION 2: extension clarifies saveStrings vs. saveJSON
  79936. var extension = _checkFileExtension(args[1], args[2])[1];
  79937. switch (extension) {
  79938. case 'json':
  79939. _main.default.prototype.saveJSON(args[0], args[1], args[2]);
  79940. return;
  79941. case 'txt':
  79942. _main.default.prototype.saveStrings(args[0], args[1], args[2]);
  79943. return;
  79944. // =================================================
  79945. // OPTION 3: decide based on object...
  79946. default:
  79947. if (args[0] instanceof Array) {
  79948. _main.default.prototype.saveStrings(args[0], args[1], args[2]);
  79949. } else if (args[0] instanceof _main.default.Table) {
  79950. _main.default.prototype.saveTable(args[0], args[1], args[2]);
  79951. } else if (args[0] instanceof _main.default.Image) {
  79952. _main.default.prototype.saveCanvas(args[0].canvas, args[1]);
  79953. } else if (args[0] instanceof _main.default.SoundFile) {
  79954. _main.default.prototype.saveSound(args[0], args[1], args[2], args[3]);
  79955. }
  79956. }
  79957. }
  79958. };
  79959. /**
  79960. * Writes the contents of an Array or a JSON object to a .json file.
  79961. * The file saving process and location of the saved file will
  79962. * vary between web browsers.
  79963. *
  79964. * @method saveJSON
  79965. * @param {Array|Object} json
  79966. * @param {String} filename
  79967. * @param {Boolean} [optimize] If true, removes line breaks
  79968. * and spaces from the output
  79969. * file to optimize filesize
  79970. * (but not readability).
  79971. * @example
  79972. * <div><code>
  79973. * let json = {}; // new JSON Object
  79974. *
  79975. * json.id = 0;
  79976. * json.species = 'Panthera leo';
  79977. * json.name = 'Lion';
  79978. *
  79979. * function setup() {
  79980. * createCanvas(100, 100);
  79981. * background(200);
  79982. * text('click here to save', 10, 10, 70, 80);
  79983. * }
  79984. *
  79985. * function mousePressed() {
  79986. * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
  79987. * saveJSON(json, 'lion.json');
  79988. * }
  79989. * }
  79990. *
  79991. * // saves the following to a file called "lion.json":
  79992. * // {
  79993. * // "id": 0,
  79994. * // "species": "Panthera leo",
  79995. * // "name": "Lion"
  79996. * // }
  79997. * </code></div>
  79998. *
  79999. * @alt
  80000. * no image displayed
  80001. */
  80002. _main.default.prototype.saveJSON = function(json, filename, opt) {
  80003. _main.default._validateParameters('saveJSON', arguments);
  80004. var stringify;
  80005. if (opt) {
  80006. stringify = JSON.stringify(json);
  80007. } else {
  80008. stringify = JSON.stringify(json, undefined, 2);
  80009. }
  80010. this.saveStrings(stringify.split('\n'), filename, 'json');
  80011. };
  80012. _main.default.prototype.saveJSONObject = _main.default.prototype.saveJSON;
  80013. _main.default.prototype.saveJSONArray = _main.default.prototype.saveJSON;
  80014. /**
  80015. * Writes an array of Strings to a text file, one line per String.
  80016. * The file saving process and location of the saved file will
  80017. * vary between web browsers.
  80018. *
  80019. * @method saveStrings
  80020. * @param {String[]} list string array to be written
  80021. * @param {String} filename filename for output
  80022. * @param {String} [extension] the filename's extension
  80023. * @param {Boolean} [isCRLF] if true, change line-break to CRLF
  80024. * @example
  80025. * <div><code>
  80026. * let words = 'apple bear cat dog';
  80027. *
  80028. * // .split() outputs an Array
  80029. * let list = split(words, ' ');
  80030. *
  80031. * function setup() {
  80032. * createCanvas(100, 100);
  80033. * background(200);
  80034. * text('click here to save', 10, 10, 70, 80);
  80035. * }
  80036. *
  80037. * function mousePressed() {
  80038. * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
  80039. * saveStrings(list, 'nouns.txt');
  80040. * }
  80041. * }
  80042. *
  80043. * // Saves the following to a file called 'nouns.txt':
  80044. * //
  80045. * // apple
  80046. * // bear
  80047. * // cat
  80048. * // dog
  80049. * </code></div>
  80050. *
  80051. * @alt
  80052. * no image displayed
  80053. */
  80054. _main.default.prototype.saveStrings = function(
  80055. list,
  80056. filename,
  80057. extension,
  80058. isCRLF
  80059. ) {
  80060. _main.default._validateParameters('saveStrings', arguments);
  80061. var ext = extension || 'txt';
  80062. var pWriter = this.createWriter(filename, ext);
  80063. for (var i = 0; i < list.length; i++) {
  80064. isCRLF ? pWriter.write(list[i] + '\r\n') : pWriter.write(list[i] + '\n');
  80065. }
  80066. pWriter.close();
  80067. pWriter.clear();
  80068. };
  80069. // =======
  80070. // HELPERS
  80071. // =======
  80072. function escapeHelper(content) {
  80073. return content
  80074. .replace(/&/g, '&amp;')
  80075. .replace(/</g, '&lt;')
  80076. .replace(/>/g, '&gt;')
  80077. .replace(/"/g, '&quot;')
  80078. .replace(/'/g, '&#039;');
  80079. }
  80080. /**
  80081. * Writes the contents of a <a href="#/p5.Table">Table</a> object to a file. Defaults to a
  80082. * text file with comma-separated-values ('csv') but can also
  80083. * use tab separation ('tsv'), or generate an HTML table ('html').
  80084. * The file saving process and location of the saved file will
  80085. * vary between web browsers.
  80086. *
  80087. * @method saveTable
  80088. * @param {p5.Table} Table the <a href="#/p5.Table">Table</a> object to save to a file
  80089. * @param {String} filename the filename to which the Table should be saved
  80090. * @param {String} [options] can be one of "tsv", "csv", or "html"
  80091. * @example
  80092. * <div><code>
  80093. * let table;
  80094. *
  80095. * function setup() {
  80096. * table = new p5.Table();
  80097. *
  80098. * table.addColumn('id');
  80099. * table.addColumn('species');
  80100. * table.addColumn('name');
  80101. *
  80102. * let newRow = table.addRow();
  80103. * newRow.setNum('id', table.getRowCount() - 1);
  80104. * newRow.setString('species', 'Panthera leo');
  80105. * newRow.setString('name', 'Lion');
  80106. *
  80107. * // To save, un-comment next line then click 'run'
  80108. * // saveTable(table, 'new.csv');
  80109. * }
  80110. *
  80111. * // Saves the following to a file called 'new.csv':
  80112. * // id,species,name
  80113. * // 0,Panthera leo,Lion
  80114. * </code></div>
  80115. *
  80116. * @alt
  80117. * no image displayed
  80118. */
  80119. _main.default.prototype.saveTable = function(table, filename, options) {
  80120. _main.default._validateParameters('saveTable', arguments);
  80121. var ext;
  80122. if (options === undefined) {
  80123. ext = filename.substring(filename.lastIndexOf('.') + 1, filename.length);
  80124. } else {
  80125. ext = options;
  80126. }
  80127. var pWriter = this.createWriter(filename, ext);
  80128. var header = table.columns;
  80129. var sep = ','; // default to CSV
  80130. if (ext === 'tsv') {
  80131. sep = '\t';
  80132. }
  80133. if (ext !== 'html') {
  80134. // make header if it has values
  80135. if (header[0] !== '0') {
  80136. for (var h = 0; h < header.length; h++) {
  80137. if (h < header.length - 1) {
  80138. pWriter.write(header[h] + sep);
  80139. } else {
  80140. pWriter.write(header[h]);
  80141. }
  80142. }
  80143. pWriter.write('\n');
  80144. }
  80145. // make rows
  80146. for (var i = 0; i < table.rows.length; i++) {
  80147. var j = void 0;
  80148. for (j = 0; j < table.rows[i].arr.length; j++) {
  80149. if (j < table.rows[i].arr.length - 1) {
  80150. //double quotes should be inserted in csv only if contains comma separated single value
  80151. if (ext === 'csv' && String(table.rows[i].arr[j]).includes(',')) {
  80152. pWriter.write('"' + table.rows[i].arr[j] + '"' + sep);
  80153. } else {
  80154. pWriter.write(table.rows[i].arr[j] + sep);
  80155. }
  80156. } else {
  80157. //double quotes should be inserted in csv only if contains comma separated single value
  80158. if (ext === 'csv' && String(table.rows[i].arr[j]).includes(',')) {
  80159. pWriter.write('"' + table.rows[i].arr[j] + '"');
  80160. } else {
  80161. pWriter.write(table.rows[i].arr[j]);
  80162. }
  80163. }
  80164. }
  80165. pWriter.write('\n');
  80166. }
  80167. } else {
  80168. // otherwise, make HTML
  80169. pWriter.print('<html>');
  80170. pWriter.print('<head>');
  80171. var str = ' <meta http-equiv="content-type" content';
  80172. str += '="text/html;charset=utf-8" />';
  80173. pWriter.print(str);
  80174. pWriter.print('</head>');
  80175. pWriter.print('<body>');
  80176. pWriter.print(' <table>');
  80177. // make header if it has values
  80178. if (header[0] !== '0') {
  80179. pWriter.print(' <tr>');
  80180. for (var k = 0; k < header.length; k++) {
  80181. var e = escapeHelper(header[k]);
  80182. pWriter.print(' <td>'.concat(e));
  80183. pWriter.print(' </td>');
  80184. }
  80185. pWriter.print(' </tr>');
  80186. }
  80187. // make rows
  80188. for (var row = 0; row < table.rows.length; row++) {
  80189. pWriter.print(' <tr>');
  80190. for (var col = 0; col < table.columns.length; col++) {
  80191. var entry = table.rows[row].getString(col);
  80192. var htmlEntry = escapeHelper(entry);
  80193. pWriter.print(' <td>'.concat(htmlEntry));
  80194. pWriter.print(' </td>');
  80195. }
  80196. pWriter.print(' </tr>');
  80197. }
  80198. pWriter.print(' </table>');
  80199. pWriter.print('</body>');
  80200. pWriter.print('</html>');
  80201. }
  80202. // close and clear the pWriter
  80203. pWriter.close();
  80204. pWriter.clear();
  80205. }; // end saveTable()
  80206. /**
  80207. * Generate a blob of file data as a url to prepare for download.
  80208. * Accepts an array of data, a filename, and an extension (optional).
  80209. * This is a private function because it does not do any formatting,
  80210. * but it is used by <a href="#/p5/saveStrings">saveStrings</a>, <a href="#/p5/saveJSON">saveJSON</a>, <a href="#/p5/saveTable">saveTable</a> etc.
  80211. *
  80212. * @param {Array} dataToDownload
  80213. * @param {String} filename
  80214. * @param {String} [extension]
  80215. * @private
  80216. */
  80217. _main.default.prototype.writeFile = function(
  80218. dataToDownload,
  80219. filename,
  80220. extension
  80221. ) {
  80222. var type = 'application/octet-stream';
  80223. if (_main.default.prototype._isSafari()) {
  80224. type = 'text/plain';
  80225. }
  80226. var blob = new Blob(dataToDownload, {
  80227. type: type
  80228. });
  80229. _main.default.prototype.downloadFile(blob, filename, extension);
  80230. };
  80231. /**
  80232. * Forces download. Accepts a url to filedata/blob, a filename,
  80233. * and an extension (optional).
  80234. * This is a private function because it does not do any formatting,
  80235. * but it is used by <a href="#/p5/saveStrings">saveStrings</a>, <a href="#/p5/saveJSON">saveJSON</a>, <a href="#/p5/saveTable">saveTable</a> etc.
  80236. *
  80237. * @method downloadFile
  80238. * @private
  80239. * @param {String|Blob} data either an href generated by createObjectURL,
  80240. * or a Blob object containing the data
  80241. * @param {String} [filename]
  80242. * @param {String} [extension]
  80243. */
  80244. _main.default.prototype.downloadFile = function(data, fName, extension) {
  80245. var fx = _checkFileExtension(fName, extension);
  80246. var filename = fx[0];
  80247. if (data instanceof Blob) {
  80248. _fileSaver.default.saveAs(data, filename);
  80249. return;
  80250. }
  80251. var a = document.createElement('a');
  80252. a.href = data;
  80253. a.download = filename;
  80254. // Firefox requires the link to be added to the DOM before click()
  80255. a.onclick = function(e) {
  80256. destroyClickedElement(e);
  80257. e.stopPropagation();
  80258. };
  80259. a.style.display = 'none';
  80260. document.body.appendChild(a);
  80261. // Safari will open this file in the same page as a confusing Blob.
  80262. if (_main.default.prototype._isSafari()) {
  80263. var aText = 'Hello, Safari user! To download this file...\n';
  80264. aText += '1. Go to File --> Save As.\n';
  80265. aText += '2. Choose "Page Source" as the Format.\n';
  80266. aText += '3. Name it with this extension: ."'.concat(fx[1], '"');
  80267. alert(aText);
  80268. }
  80269. a.click();
  80270. };
  80271. /**
  80272. * Returns a file extension, or another string
  80273. * if the provided parameter has no extension.
  80274. *
  80275. * @param {String} filename
  80276. * @param {String} [extension]
  80277. * @return {String[]} [fileName, fileExtension]
  80278. *
  80279. * @private
  80280. */
  80281. function _checkFileExtension(filename, extension) {
  80282. if (!extension || extension === true || extension === 'true') {
  80283. extension = '';
  80284. }
  80285. if (!filename) {
  80286. filename = 'untitled';
  80287. }
  80288. var ext = '';
  80289. // make sure the file will have a name, see if filename needs extension
  80290. if (filename && filename.includes('.')) {
  80291. ext = filename.split('.').pop();
  80292. }
  80293. // append extension if it doesn't exist
  80294. if (extension) {
  80295. if (ext !== extension) {
  80296. ext = extension;
  80297. filename = ''.concat(filename, '.').concat(ext);
  80298. }
  80299. }
  80300. return [filename, ext];
  80301. }
  80302. _main.default.prototype._checkFileExtension = _checkFileExtension;
  80303. /**
  80304. * Returns true if the browser is Safari, false if not.
  80305. * Safari makes trouble for downloading files.
  80306. *
  80307. * @return {Boolean} [description]
  80308. * @private
  80309. */
  80310. _main.default.prototype._isSafari = function() {
  80311. var x = Object.prototype.toString.call(window.HTMLElement);
  80312. return x.indexOf('Constructor') > 0;
  80313. };
  80314. /**
  80315. * Helper function, a callback for download that deletes
  80316. * an invisible anchor element from the DOM once the file
  80317. * has been automatically downloaded.
  80318. *
  80319. * @private
  80320. */
  80321. function destroyClickedElement(event) {
  80322. document.body.removeChild(event.target);
  80323. }
  80324. var _default = _main.default;
  80325. exports.default = _default;
  80326. },
  80327. {
  80328. '../core/friendly_errors/fes_core': 275,
  80329. '../core/friendly_errors/file_errors': 276,
  80330. '../core/friendly_errors/validate_params': 278,
  80331. '../core/main': 283,
  80332. 'core-js/modules/es.array.concat': 166,
  80333. 'core-js/modules/es.array.includes': 172,
  80334. 'core-js/modules/es.array.index-of': 173,
  80335. 'core-js/modules/es.array.iterator': 174,
  80336. 'core-js/modules/es.array.last-index-of': 176,
  80337. 'core-js/modules/es.array.slice': 178,
  80338. 'core-js/modules/es.array.splice': 180,
  80339. 'core-js/modules/es.function.name': 181,
  80340. 'core-js/modules/es.object.to-string': 192,
  80341. 'core-js/modules/es.promise': 193,
  80342. 'core-js/modules/es.regexp.exec': 196,
  80343. 'core-js/modules/es.regexp.to-string': 197,
  80344. 'core-js/modules/es.string.includes': 200,
  80345. 'core-js/modules/es.string.iterator': 201,
  80346. 'core-js/modules/es.string.replace': 204,
  80347. 'core-js/modules/es.string.split': 206,
  80348. 'core-js/modules/es.symbol': 211,
  80349. 'core-js/modules/es.symbol.description': 209,
  80350. 'core-js/modules/es.symbol.iterator': 210,
  80351. 'core-js/modules/es.typed-array.copy-within': 212,
  80352. 'core-js/modules/es.typed-array.every': 213,
  80353. 'core-js/modules/es.typed-array.fill': 214,
  80354. 'core-js/modules/es.typed-array.filter': 215,
  80355. 'core-js/modules/es.typed-array.find': 217,
  80356. 'core-js/modules/es.typed-array.find-index': 216,
  80357. 'core-js/modules/es.typed-array.for-each': 220,
  80358. 'core-js/modules/es.typed-array.includes': 221,
  80359. 'core-js/modules/es.typed-array.index-of': 222,
  80360. 'core-js/modules/es.typed-array.iterator': 225,
  80361. 'core-js/modules/es.typed-array.join': 226,
  80362. 'core-js/modules/es.typed-array.last-index-of': 227,
  80363. 'core-js/modules/es.typed-array.map': 228,
  80364. 'core-js/modules/es.typed-array.reduce': 230,
  80365. 'core-js/modules/es.typed-array.reduce-right': 229,
  80366. 'core-js/modules/es.typed-array.reverse': 231,
  80367. 'core-js/modules/es.typed-array.set': 232,
  80368. 'core-js/modules/es.typed-array.slice': 233,
  80369. 'core-js/modules/es.typed-array.some': 234,
  80370. 'core-js/modules/es.typed-array.sort': 235,
  80371. 'core-js/modules/es.typed-array.subarray': 236,
  80372. 'core-js/modules/es.typed-array.to-locale-string': 237,
  80373. 'core-js/modules/es.typed-array.to-string': 238,
  80374. 'core-js/modules/es.typed-array.uint8-array': 241,
  80375. 'core-js/modules/web.dom-collections.iterator': 244,
  80376. 'core-js/modules/web.url': 246,
  80377. 'es6-promise/auto': 247,
  80378. 'fetch-jsonp': 249,
  80379. 'file-saver': 250,
  80380. 'whatwg-fetch': 261
  80381. }
  80382. ],
  80383. 310: [
  80384. function(_dereq_, module, exports) {
  80385. 'use strict';
  80386. _dereq_('core-js/modules/es.array.concat');
  80387. _dereq_('core-js/modules/es.array.index-of');
  80388. _dereq_('core-js/modules/es.array.join');
  80389. _dereq_('core-js/modules/es.array.splice');
  80390. _dereq_('core-js/modules/es.regexp.constructor');
  80391. _dereq_('core-js/modules/es.regexp.exec');
  80392. _dereq_('core-js/modules/es.regexp.to-string');
  80393. _dereq_('core-js/modules/es.string.match');
  80394. _dereq_('core-js/modules/es.string.replace');
  80395. _dereq_('core-js/modules/es.string.trim');
  80396. Object.defineProperty(exports, '__esModule', { value: true });
  80397. exports.default = void 0;
  80398. var _main = _interopRequireDefault(_dereq_('../core/main'));
  80399. function _interopRequireDefault(obj) {
  80400. return obj && obj.__esModule ? obj : { default: obj };
  80401. } /**
  80402. * <a href="#/p5.Table">Table</a> objects store data with multiple rows and columns, much
  80403. * like in a traditional spreadsheet. Tables can be generated from
  80404. * scratch, dynamically, or using data from an existing file.
  80405. *
  80406. * @class p5.Table
  80407. * @constructor
  80408. * @param {p5.TableRow[]} [rows] An array of p5.TableRow objects
  80409. */ /**
  80410. * @module IO
  80411. * @submodule Table
  80412. * @requires core
  80413. */ /**
  80414. * Table Options
  80415. * Generic class for handling tabular data, typically from a
  80416. * CSV, TSV, or other sort of spreadsheet file.
  80417. * CSV files are
  80418. * <a href="http://en.wikipedia.org/wiki/Comma-separated_values">
  80419. * comma separated values</a>, often with the data in quotes. TSV
  80420. * files use tabs as separators, and usually don't bother with the
  80421. * quotes.
  80422. * File names should end with .csv if they're comma separated.
  80423. * A rough "spec" for CSV can be found
  80424. * <a href="http://tools.ietf.org/html/rfc4180">here</a>.
  80425. * To load files, use the <a href="#/p5/loadTable">loadTable</a> method.
  80426. * To save tables to your computer, use the <a href="#/p5/save">save</a> method
  80427. * or the <a href="#/p5/saveTable">saveTable</a> method.
  80428. *
  80429. * Possible options include:
  80430. * <ul>
  80431. * <li>csv - parse the table as comma-separated values
  80432. * <li>tsv - parse the table as tab-separated values
  80433. * <li>header - this table has a header (title) row
  80434. * </ul>
  80435. */
  80436. _main.default.Table = function(rows) {
  80437. /**
  80438. * An array containing the names of the columns in the table, if the "header" the table is
  80439. * loaded with the "header" parameter.
  80440. * @property columns {String[]}
  80441. * @example
  80442. * <div class="norender">
  80443. * <code>
  80444. * // Given the CSV file "mammals.csv"
  80445. * // in the project's "assets" folder:
  80446. * //
  80447. * // id,species,name
  80448. * // 0,Capra hircus,Goat
  80449. * // 1,Panthera pardus,Leopard
  80450. * // 2,Equus zebra,Zebra
  80451. *
  80452. * let table;
  80453. *
  80454. * function preload() {
  80455. * //my table is comma separated value "csv"
  80456. * //and has a header specifying the columns labels
  80457. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  80458. * }
  80459. *
  80460. * function setup() {
  80461. * //print the column names
  80462. * for (let c = 0; c < table.getColumnCount(); c++) {
  80463. * print('column ' + c + ' is named ' + table.columns[c]);
  80464. * }
  80465. * }
  80466. * </code>
  80467. * </div>
  80468. */
  80469. this.columns = [];
  80470. /**
  80471. * An array containing the <a href="#/p5.Table">p5.TableRow</a> objects that make up the
  80472. * rows of the table. The same result as calling <a href="#/p5/getRows">getRows()</a>
  80473. * @property rows {p5.TableRow[]}
  80474. */
  80475. this.rows = [];
  80476. };
  80477. /**
  80478. * Use <a href="#/p5/addRow">addRow()</a> to add a new row of data to a <a href="#/p5.Table">p5.Table</a> object. By default,
  80479. * an empty row is created. Typically, you would store a reference to
  80480. * the new row in a TableRow object (see newRow in the example above),
  80481. * and then set individual values using <a href="#/p5/set">set()</a>.
  80482. *
  80483. * If a <a href="#/p5.TableRow">p5.TableRow</a> object is included as a parameter, then that row is
  80484. * duplicated and added to the table.
  80485. *
  80486. * @method addRow
  80487. * @param {p5.TableRow} [row] row to be added to the table
  80488. * @return {p5.TableRow} the row that was added
  80489. *
  80490. * @example
  80491. * <div class="norender">
  80492. * <code>
  80493. * // Given the CSV file "mammals.csv"
  80494. * // in the project's "assets" folder:
  80495. * //
  80496. * // id,species,name
  80497. * // 0,Capra hircus,Goat
  80498. * // 1,Panthera pardus,Leopard
  80499. * // 2,Equus zebra,Zebra
  80500. *
  80501. * let table;
  80502. *
  80503. * function preload() {
  80504. * //my table is comma separated value "csv"
  80505. * //and has a header specifying the columns labels
  80506. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  80507. * }
  80508. *
  80509. * function setup() {
  80510. * //add a row
  80511. * let newRow = table.addRow();
  80512. * newRow.setString('id', table.getRowCount() - 1);
  80513. * newRow.setString('species', 'Canis Lupus');
  80514. * newRow.setString('name', 'Wolf');
  80515. *
  80516. * //print the results
  80517. * for (let r = 0; r < table.getRowCount(); r++)
  80518. * for (let c = 0; c < table.getColumnCount(); c++)
  80519. * print(table.getString(r, c));
  80520. * }
  80521. * </code>
  80522. * </div>
  80523. *
  80524. * @alt
  80525. * no image displayed
  80526. */
  80527. _main.default.Table.prototype.addRow = function(row) {
  80528. // make sure it is a valid TableRow
  80529. var r = row || new _main.default.TableRow();
  80530. if (typeof r.arr === 'undefined' || typeof r.obj === 'undefined') {
  80531. //r = new p5.prototype.TableRow(r);
  80532. throw new Error('invalid TableRow: '.concat(r));
  80533. }
  80534. r.table = this;
  80535. this.rows.push(r);
  80536. return r;
  80537. };
  80538. /**
  80539. * Removes a row from the table object.
  80540. *
  80541. * @method removeRow
  80542. * @param {Integer} id ID number of the row to remove
  80543. *
  80544. * @example
  80545. * <div class="norender">
  80546. * <code>
  80547. * // Given the CSV file "mammals.csv"
  80548. * // in the project's "assets" folder:
  80549. * //
  80550. * // id,species,name
  80551. * // 0,Capra hircus,Goat
  80552. * // 1,Panthera pardus,Leopard
  80553. * // 2,Equus zebra,Zebra
  80554. *
  80555. * let table;
  80556. *
  80557. * function preload() {
  80558. * //my table is comma separated value "csv"
  80559. * //and has a header specifying the columns labels
  80560. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  80561. * }
  80562. *
  80563. * function setup() {
  80564. * //remove the first row
  80565. * table.removeRow(0);
  80566. *
  80567. * //print the results
  80568. * for (let r = 0; r < table.getRowCount(); r++)
  80569. * for (let c = 0; c < table.getColumnCount(); c++)
  80570. * print(table.getString(r, c));
  80571. * }
  80572. * </code>
  80573. * </div>
  80574. *
  80575. * @alt
  80576. * no image displayed
  80577. */
  80578. _main.default.Table.prototype.removeRow = function(id) {
  80579. this.rows[id].table = null; // remove reference to table
  80580. var chunk = this.rows.splice(id + 1, this.rows.length);
  80581. this.rows.pop();
  80582. this.rows = this.rows.concat(chunk);
  80583. };
  80584. /**
  80585. * Returns a reference to the specified <a href="#/p5.TableRow">p5.TableRow</a>. The reference
  80586. * can then be used to get and set values of the selected row.
  80587. *
  80588. * @method getRow
  80589. * @param {Integer} rowID ID number of the row to get
  80590. * @return {p5.TableRow} <a href="#/p5.TableRow">p5.TableRow</a> object
  80591. *
  80592. * @example
  80593. * <div class="norender">
  80594. * <code>
  80595. * // Given the CSV file "mammals.csv"
  80596. * // in the project's "assets" folder:
  80597. * //
  80598. * // id,species,name
  80599. * // 0,Capra hircus,Goat
  80600. * // 1,Panthera pardus,Leopard
  80601. * // 2,Equus zebra,Zebra
  80602. *
  80603. * let table;
  80604. *
  80605. * function preload() {
  80606. * //my table is comma separated value "csv"
  80607. * //and has a header specifying the columns labels
  80608. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  80609. * }
  80610. *
  80611. * function setup() {
  80612. * let row = table.getRow(1);
  80613. * //print it column by column
  80614. * //note: a row is an object, not an array
  80615. * for (let c = 0; c < table.getColumnCount(); c++) {
  80616. * print(row.getString(c));
  80617. * }
  80618. * }
  80619. * </code>
  80620. * </div>
  80621. *
  80622. *@alt
  80623. * no image displayed
  80624. */
  80625. _main.default.Table.prototype.getRow = function(r) {
  80626. return this.rows[r];
  80627. };
  80628. /**
  80629. * Gets all rows from the table. Returns an array of <a href="#/p5.TableRow">p5.TableRow</a>s.
  80630. *
  80631. * @method getRows
  80632. * @return {p5.TableRow[]} Array of <a href="#/p5.TableRow">p5.TableRow</a>s
  80633. *
  80634. * @example
  80635. * <div class="norender">
  80636. * <code>
  80637. * // Given the CSV file "mammals.csv"
  80638. * // in the project's "assets" folder:
  80639. * //
  80640. * // id,species,name
  80641. * // 0,Capra hircus,Goat
  80642. * // 1,Panthera pardus,Leopard
  80643. * // 2,Equus zebra,Zebra
  80644. *
  80645. * let table;
  80646. *
  80647. * function preload() {
  80648. * //my table is comma separated value "csv"
  80649. * //and has a header specifying the columns labels
  80650. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  80651. * }
  80652. *
  80653. * function setup() {
  80654. * let rows = table.getRows();
  80655. *
  80656. * //warning: rows is an array of objects
  80657. * for (let r = 0; r < rows.length; r++) {
  80658. * rows[r].set('name', 'Unicorn');
  80659. * }
  80660. *
  80661. * //print the results
  80662. * for (let r = 0; r < table.getRowCount(); r++)
  80663. * for (let c = 0; c < table.getColumnCount(); c++)
  80664. * print(table.getString(r, c));
  80665. * }
  80666. * </code>
  80667. * </div>
  80668. *
  80669. * @alt
  80670. * no image displayed
  80671. */
  80672. _main.default.Table.prototype.getRows = function() {
  80673. return this.rows;
  80674. };
  80675. /**
  80676. * Finds the first row in the Table that contains the value
  80677. * provided, and returns a reference to that row. Even if
  80678. * multiple rows are possible matches, only the first matching
  80679. * row is returned. The column to search may be specified by
  80680. * either its ID or title.
  80681. *
  80682. * @method findRow
  80683. * @param {String} value The value to match
  80684. * @param {Integer|String} column ID number or title of the
  80685. * column to search
  80686. * @return {p5.TableRow}
  80687. *
  80688. * @example
  80689. * <div class="norender">
  80690. * <code>
  80691. * // Given the CSV file "mammals.csv"
  80692. * // in the project's "assets" folder:
  80693. * //
  80694. * // id,species,name
  80695. * // 0,Capra hircus,Goat
  80696. * // 1,Panthera pardus,Leopard
  80697. * // 2,Equus zebra,Zebra
  80698. *
  80699. * let table;
  80700. *
  80701. * function preload() {
  80702. * //my table is comma separated value "csv"
  80703. * //and has a header specifying the columns labels
  80704. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  80705. * }
  80706. *
  80707. * function setup() {
  80708. * //find the animal named zebra
  80709. * let row = table.findRow('Zebra', 'name');
  80710. * //find the corresponding species
  80711. * print(row.getString('species'));
  80712. * }
  80713. * </code>
  80714. * </div>
  80715. *
  80716. * @alt
  80717. * no image displayed
  80718. */
  80719. _main.default.Table.prototype.findRow = function(value, column) {
  80720. // try the Object
  80721. if (typeof column === 'string') {
  80722. for (var i = 0; i < this.rows.length; i++) {
  80723. if (this.rows[i].obj[column] === value) {
  80724. return this.rows[i];
  80725. }
  80726. }
  80727. } else {
  80728. // try the Array
  80729. for (var j = 0; j < this.rows.length; j++) {
  80730. if (this.rows[j].arr[column] === value) {
  80731. return this.rows[j];
  80732. }
  80733. }
  80734. }
  80735. // otherwise...
  80736. return null;
  80737. };
  80738. /**
  80739. * Finds the rows in the Table that contain the value
  80740. * provided, and returns references to those rows. Returns an
  80741. * Array, so for must be used to iterate through all the rows,
  80742. * as shown in the example above. The column to search may be
  80743. * specified by either its ID or title.
  80744. *
  80745. * @method findRows
  80746. * @param {String} value The value to match
  80747. * @param {Integer|String} column ID number or title of the
  80748. * column to search
  80749. * @return {p5.TableRow[]} An Array of TableRow objects
  80750. *
  80751. * @example
  80752. * <div class="norender">
  80753. * <code>
  80754. * // Given the CSV file "mammals.csv"
  80755. * // in the project's "assets" folder:
  80756. * //
  80757. * // id,species,name
  80758. * // 0,Capra hircus,Goat
  80759. * // 1,Panthera pardus,Leopard
  80760. * // 2,Equus zebra,Zebra
  80761. *
  80762. * let table;
  80763. *
  80764. * function preload() {
  80765. * //my table is comma separated value "csv"
  80766. * //and has a header specifying the columns labels
  80767. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  80768. * }
  80769. *
  80770. * function setup() {
  80771. * //add another goat
  80772. * let newRow = table.addRow();
  80773. * newRow.setString('id', table.getRowCount() - 1);
  80774. * newRow.setString('species', 'Scape Goat');
  80775. * newRow.setString('name', 'Goat');
  80776. *
  80777. * //find the rows containing animals named Goat
  80778. * let rows = table.findRows('Goat', 'name');
  80779. * print(rows.length + ' Goats found');
  80780. * }
  80781. * </code>
  80782. * </div>
  80783. *
  80784. *@alt
  80785. * no image displayed
  80786. */
  80787. _main.default.Table.prototype.findRows = function(value, column) {
  80788. var ret = [];
  80789. if (typeof column === 'string') {
  80790. for (var i = 0; i < this.rows.length; i++) {
  80791. if (this.rows[i].obj[column] === value) {
  80792. ret.push(this.rows[i]);
  80793. }
  80794. }
  80795. } else {
  80796. // try the Array
  80797. for (var j = 0; j < this.rows.length; j++) {
  80798. if (this.rows[j].arr[column] === value) {
  80799. ret.push(this.rows[j]);
  80800. }
  80801. }
  80802. }
  80803. return ret;
  80804. };
  80805. /**
  80806. * Finds the first row in the Table that matches the regular
  80807. * expression provided, and returns a reference to that row.
  80808. * Even if multiple rows are possible matches, only the first
  80809. * matching row is returned. The column to search may be
  80810. * specified by either its ID or title.
  80811. *
  80812. * @method matchRow
  80813. * @param {String|RegExp} regexp The regular expression to match
  80814. * @param {String|Integer} column The column ID (number) or
  80815. * title (string)
  80816. * @return {p5.TableRow} TableRow object
  80817. *
  80818. * @example
  80819. * <div class="norender">
  80820. * <code>
  80821. * // Given the CSV file "mammals.csv"
  80822. * // in the project's "assets" folder:
  80823. * //
  80824. * // id,species,name
  80825. * // 0,Capra hircus,Goat
  80826. * // 1,Panthera pardus,Leopard
  80827. * // 2,Equus zebra,Zebra
  80828. *
  80829. * let table;
  80830. *
  80831. * function preload() {
  80832. * //my table is comma separated value "csv"
  80833. * //and has a header specifying the columns labels
  80834. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  80835. * }
  80836. *
  80837. * function setup() {
  80838. * //Search using specified regex on a given column, return TableRow object
  80839. * let mammal = table.matchRow(new RegExp('ant'), 1);
  80840. * print(mammal.getString(1));
  80841. * //Output "Panthera pardus"
  80842. * }
  80843. * </code>
  80844. * </div>
  80845. */
  80846. _main.default.Table.prototype.matchRow = function(regexp, column) {
  80847. if (typeof column === 'number') {
  80848. for (var j = 0; j < this.rows.length; j++) {
  80849. if (this.rows[j].arr[column].match(regexp)) {
  80850. return this.rows[j];
  80851. }
  80852. }
  80853. } else {
  80854. for (var i = 0; i < this.rows.length; i++) {
  80855. if (this.rows[i].obj[column].match(regexp)) {
  80856. return this.rows[i];
  80857. }
  80858. }
  80859. }
  80860. return null;
  80861. };
  80862. /**
  80863. * Finds the rows in the Table that match the regular expression provided,
  80864. * and returns references to those rows. Returns an array, so for must be
  80865. * used to iterate through all the rows, as shown in the example. The
  80866. * column to search may be specified by either its ID or title.
  80867. *
  80868. * @method matchRows
  80869. * @param {String} regexp The regular expression to match
  80870. * @param {String|Integer} [column] The column ID (number) or
  80871. * title (string)
  80872. * @return {p5.TableRow[]} An Array of TableRow objects
  80873. * @example
  80874. * <div class="norender">
  80875. * <code>
  80876. * let table;
  80877. *
  80878. * function setup() {
  80879. * table = new p5.Table();
  80880. *
  80881. * table.addColumn('name');
  80882. * table.addColumn('type');
  80883. *
  80884. * let newRow = table.addRow();
  80885. * newRow.setString('name', 'Lion');
  80886. * newRow.setString('type', 'Mammal');
  80887. *
  80888. * newRow = table.addRow();
  80889. * newRow.setString('name', 'Snake');
  80890. * newRow.setString('type', 'Reptile');
  80891. *
  80892. * newRow = table.addRow();
  80893. * newRow.setString('name', 'Mosquito');
  80894. * newRow.setString('type', 'Insect');
  80895. *
  80896. * newRow = table.addRow();
  80897. * newRow.setString('name', 'Lizard');
  80898. * newRow.setString('type', 'Reptile');
  80899. *
  80900. * let rows = table.matchRows('R.*', 'type');
  80901. * for (let i = 0; i < rows.length; i++) {
  80902. * print(rows[i].getString('name') + ': ' + rows[i].getString('type'));
  80903. * }
  80904. * }
  80905. * // Sketch prints:
  80906. * // Snake: Reptile
  80907. * // Lizard: Reptile
  80908. * </code>
  80909. * </div>
  80910. */
  80911. _main.default.Table.prototype.matchRows = function(regexp, column) {
  80912. var ret = [];
  80913. if (typeof column === 'number') {
  80914. for (var j = 0; j < this.rows.length; j++) {
  80915. if (this.rows[j].arr[column].match(regexp)) {
  80916. ret.push(this.rows[j]);
  80917. }
  80918. }
  80919. } else {
  80920. for (var i = 0; i < this.rows.length; i++) {
  80921. if (this.rows[i].obj[column].match(regexp)) {
  80922. ret.push(this.rows[i]);
  80923. }
  80924. }
  80925. }
  80926. return ret;
  80927. };
  80928. /**
  80929. * Retrieves all values in the specified column, and returns them
  80930. * as an array. The column may be specified by either its ID or title.
  80931. *
  80932. * @method getColumn
  80933. * @param {String|Number} column String or Number of the column to return
  80934. * @return {Array} Array of column values
  80935. *
  80936. * @example
  80937. * <div class="norender">
  80938. * <code>
  80939. * // Given the CSV file "mammals.csv"
  80940. * // in the project's "assets" folder:
  80941. * //
  80942. * // id,species,name
  80943. * // 0,Capra hircus,Goat
  80944. * // 1,Panthera pardus,Leopard
  80945. * // 2,Equus zebra,Zebra
  80946. *
  80947. * let table;
  80948. *
  80949. * function preload() {
  80950. * //my table is comma separated value "csv"
  80951. * //and has a header specifying the columns labels
  80952. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  80953. * }
  80954. *
  80955. * function setup() {
  80956. * //getColumn returns an array that can be printed directly
  80957. * print(table.getColumn('species'));
  80958. * //outputs ["Capra hircus", "Panthera pardus", "Equus zebra"]
  80959. * }
  80960. * </code>
  80961. * </div>
  80962. *
  80963. *@alt
  80964. * no image displayed
  80965. */
  80966. _main.default.Table.prototype.getColumn = function(value) {
  80967. var ret = [];
  80968. if (typeof value === 'string') {
  80969. for (var i = 0; i < this.rows.length; i++) {
  80970. ret.push(this.rows[i].obj[value]);
  80971. }
  80972. } else {
  80973. for (var j = 0; j < this.rows.length; j++) {
  80974. ret.push(this.rows[j].arr[value]);
  80975. }
  80976. }
  80977. return ret;
  80978. };
  80979. /**
  80980. * Removes all rows from a Table. While all rows are removed,
  80981. * columns and column titles are maintained.
  80982. *
  80983. * @method clearRows
  80984. *
  80985. * @example
  80986. * <div class="norender">
  80987. * <code>
  80988. * // Given the CSV file "mammals.csv"
  80989. * // in the project's "assets" folder:
  80990. * //
  80991. * // id,species,name
  80992. * // 0,Capra hircus,Goat
  80993. * // 1,Panthera pardus,Leopard
  80994. * // 2,Equus zebra,Zebra
  80995. *
  80996. * let table;
  80997. *
  80998. * function preload() {
  80999. * //my table is comma separated value "csv"
  81000. * //and has a header specifying the columns labels
  81001. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81002. * }
  81003. *
  81004. * function setup() {
  81005. * table.clearRows();
  81006. * print(table.getRowCount() + ' total rows in table');
  81007. * print(table.getColumnCount() + ' total columns in table');
  81008. * }
  81009. * </code>
  81010. * </div>
  81011. *
  81012. *@alt
  81013. * no image displayed
  81014. */
  81015. _main.default.Table.prototype.clearRows = function() {
  81016. delete this.rows;
  81017. this.rows = [];
  81018. };
  81019. /**
  81020. * Use <a href="#/p5/addColumn">addColumn()</a> to add a new column to a <a href="#/p5.Table">Table</a> object.
  81021. * Typically, you will want to specify a title, so the column
  81022. * may be easily referenced later by name. (If no title is
  81023. * specified, the new column's title will be null.)
  81024. *
  81025. * @method addColumn
  81026. * @param {String} [title] title of the given column
  81027. *
  81028. * @example
  81029. * <div class="norender">
  81030. * <code>
  81031. * // Given the CSV file "mammals.csv"
  81032. * // in the project's "assets" folder:
  81033. * //
  81034. * // id,species,name
  81035. * // 0,Capra hircus,Goat
  81036. * // 1,Panthera pardus,Leopard
  81037. * // 2,Equus zebra,Zebra
  81038. *
  81039. * let table;
  81040. *
  81041. * function preload() {
  81042. * //my table is comma separated value "csv"
  81043. * //and has a header specifying the columns labels
  81044. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81045. * }
  81046. *
  81047. * function setup() {
  81048. * table.addColumn('carnivore');
  81049. * table.set(0, 'carnivore', 'no');
  81050. * table.set(1, 'carnivore', 'yes');
  81051. * table.set(2, 'carnivore', 'no');
  81052. *
  81053. * //print the results
  81054. * for (let r = 0; r < table.getRowCount(); r++)
  81055. * for (let c = 0; c < table.getColumnCount(); c++)
  81056. * print(table.getString(r, c));
  81057. * }
  81058. * </code>
  81059. * </div>
  81060. *
  81061. *@alt
  81062. * no image displayed
  81063. */
  81064. _main.default.Table.prototype.addColumn = function(title) {
  81065. var t = title || null;
  81066. this.columns.push(t);
  81067. };
  81068. /**
  81069. * Returns the total number of columns in a Table.
  81070. *
  81071. * @method getColumnCount
  81072. * @return {Integer} Number of columns in this table
  81073. * @example
  81074. * <div>
  81075. * <code>
  81076. * // given the cvs file "blobs.csv" in /assets directory
  81077. * // ID, Name, Flavor, Shape, Color
  81078. * // Blob1, Blobby, Sweet, Blob, Pink
  81079. * // Blob2, Saddy, Savory, Blob, Blue
  81080. *
  81081. * let table;
  81082. *
  81083. * function preload() {
  81084. * table = loadTable('assets/blobs.csv');
  81085. * }
  81086. *
  81087. * function setup() {
  81088. * createCanvas(200, 100);
  81089. * textAlign(CENTER);
  81090. * background(255);
  81091. * }
  81092. *
  81093. * function draw() {
  81094. * let numOfColumn = table.getColumnCount();
  81095. * text('There are ' + numOfColumn + ' columns in the table.', 100, 50);
  81096. * }
  81097. * </code>
  81098. * </div>
  81099. */
  81100. _main.default.Table.prototype.getColumnCount = function() {
  81101. return this.columns.length;
  81102. };
  81103. /**
  81104. * Returns the total number of rows in a Table.
  81105. *
  81106. * @method getRowCount
  81107. * @return {Integer} Number of rows in this table
  81108. * @example
  81109. * <div>
  81110. * <code>
  81111. * // given the cvs file "blobs.csv" in /assets directory
  81112. * //
  81113. * // ID, Name, Flavor, Shape, Color
  81114. * // Blob1, Blobby, Sweet, Blob, Pink
  81115. * // Blob2, Saddy, Savory, Blob, Blue
  81116. *
  81117. * let table;
  81118. *
  81119. * function preload() {
  81120. * table = loadTable('assets/blobs.csv');
  81121. * }
  81122. *
  81123. * function setup() {
  81124. * createCanvas(200, 100);
  81125. * textAlign(CENTER);
  81126. * background(255);
  81127. * }
  81128. *
  81129. * function draw() {
  81130. * text('There are ' + table.getRowCount() + ' rows in the table.', 100, 50);
  81131. * }
  81132. * </code>
  81133. * </div>
  81134. */
  81135. _main.default.Table.prototype.getRowCount = function() {
  81136. return this.rows.length;
  81137. };
  81138. /**
  81139. * Removes any of the specified characters (or "tokens").
  81140. *
  81141. * If no column is specified, then the values in all columns and
  81142. * rows are processed. A specific column may be referenced by
  81143. * either its ID or title.
  81144. *
  81145. * @method removeTokens
  81146. * @param {String} chars String listing characters to be removed
  81147. * @param {String|Integer} [column] Column ID (number)
  81148. * or name (string)
  81149. *
  81150. * @example
  81151. * <div class="norender"><code>
  81152. * function setup() {
  81153. * let table = new p5.Table();
  81154. *
  81155. * table.addColumn('name');
  81156. * table.addColumn('type');
  81157. *
  81158. * let newRow = table.addRow();
  81159. * newRow.setString('name', ' $Lion ,');
  81160. * newRow.setString('type', ',,,Mammal');
  81161. *
  81162. * newRow = table.addRow();
  81163. * newRow.setString('name', '$Snake ');
  81164. * newRow.setString('type', ',,,Reptile');
  81165. *
  81166. * table.removeTokens(',$ ');
  81167. * print(table.getArray());
  81168. * }
  81169. *
  81170. * // prints:
  81171. * // 0 "Lion" "Mamal"
  81172. * // 1 "Snake" "Reptile"
  81173. * </code></div>
  81174. */
  81175. _main.default.Table.prototype.removeTokens = function(chars, column) {
  81176. var escape = function escape(s) {
  81177. return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
  81178. };
  81179. var charArray = [];
  81180. for (var i = 0; i < chars.length; i++) {
  81181. charArray.push(escape(chars.charAt(i)));
  81182. }
  81183. var regex = new RegExp(charArray.join('|'), 'g');
  81184. if (typeof column === 'undefined') {
  81185. for (var c = 0; c < this.columns.length; c++) {
  81186. for (var d = 0; d < this.rows.length; d++) {
  81187. var s = this.rows[d].arr[c];
  81188. s = s.replace(regex, '');
  81189. this.rows[d].arr[c] = s;
  81190. this.rows[d].obj[this.columns[c]] = s;
  81191. }
  81192. }
  81193. } else if (typeof column === 'string') {
  81194. for (var j = 0; j < this.rows.length; j++) {
  81195. var val = this.rows[j].obj[column];
  81196. val = val.replace(regex, '');
  81197. this.rows[j].obj[column] = val;
  81198. var pos = this.columns.indexOf(column);
  81199. this.rows[j].arr[pos] = val;
  81200. }
  81201. } else {
  81202. for (var k = 0; k < this.rows.length; k++) {
  81203. var str = this.rows[k].arr[column];
  81204. str = str.replace(regex, '');
  81205. this.rows[k].arr[column] = str;
  81206. this.rows[k].obj[this.columns[column]] = str;
  81207. }
  81208. }
  81209. };
  81210. /**
  81211. * Trims leading and trailing whitespace, such as spaces and tabs,
  81212. * from String table values. If no column is specified, then the
  81213. * values in all columns and rows are trimmed. A specific column
  81214. * may be referenced by either its ID or title.
  81215. *
  81216. * @method trim
  81217. * @param {String|Integer} [column] Column ID (number)
  81218. * or name (string)
  81219. * @example
  81220. * <div class="norender"><code>
  81221. * function setup() {
  81222. * let table = new p5.Table();
  81223. *
  81224. * table.addColumn('name');
  81225. * table.addColumn('type');
  81226. *
  81227. * let newRow = table.addRow();
  81228. * newRow.setString('name', ' Lion ,');
  81229. * newRow.setString('type', ' Mammal ');
  81230. *
  81231. * newRow = table.addRow();
  81232. * newRow.setString('name', ' Snake ');
  81233. * newRow.setString('type', ' Reptile ');
  81234. *
  81235. * table.trim();
  81236. * print(table.getArray());
  81237. * }
  81238. *
  81239. * // prints:
  81240. * // 0 "Lion" "Mamal"
  81241. * // 1 "Snake" "Reptile"
  81242. * </code></div>
  81243. */
  81244. _main.default.Table.prototype.trim = function(column) {
  81245. var regex = new RegExp(' ', 'g');
  81246. if (typeof column === 'undefined') {
  81247. for (var c = 0; c < this.columns.length; c++) {
  81248. for (var d = 0; d < this.rows.length; d++) {
  81249. var s = this.rows[d].arr[c];
  81250. s = s.replace(regex, '');
  81251. this.rows[d].arr[c] = s;
  81252. this.rows[d].obj[this.columns[c]] = s;
  81253. }
  81254. }
  81255. } else if (typeof column === 'string') {
  81256. for (var j = 0; j < this.rows.length; j++) {
  81257. var val = this.rows[j].obj[column];
  81258. val = val.replace(regex, '');
  81259. this.rows[j].obj[column] = val;
  81260. var pos = this.columns.indexOf(column);
  81261. this.rows[j].arr[pos] = val;
  81262. }
  81263. } else {
  81264. for (var k = 0; k < this.rows.length; k++) {
  81265. var str = this.rows[k].arr[column];
  81266. str = str.replace(regex, '');
  81267. this.rows[k].arr[column] = str;
  81268. this.rows[k].obj[this.columns[column]] = str;
  81269. }
  81270. }
  81271. };
  81272. /**
  81273. * Use <a href="#/p5/removeColumn">removeColumn()</a> to remove an existing column from a Table
  81274. * object. The column to be removed may be identified by either
  81275. * its title (a String) or its index value (an int).
  81276. * removeColumn(0) would remove the first column, removeColumn(1)
  81277. * would remove the second column, and so on.
  81278. *
  81279. * @method removeColumn
  81280. * @param {String|Integer} column columnName (string) or ID (number)
  81281. *
  81282. * @example
  81283. * <div class="norender">
  81284. * <code>
  81285. * // Given the CSV file "mammals.csv"
  81286. * // in the project's "assets" folder:
  81287. * //
  81288. * // id,species,name
  81289. * // 0,Capra hircus,Goat
  81290. * // 1,Panthera pardus,Leopard
  81291. * // 2,Equus zebra,Zebra
  81292. *
  81293. * let table;
  81294. *
  81295. * function preload() {
  81296. * //my table is comma separated value "csv"
  81297. * //and has a header specifying the columns labels
  81298. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81299. * }
  81300. *
  81301. * function setup() {
  81302. * table.removeColumn('id');
  81303. * print(table.getColumnCount());
  81304. * }
  81305. * </code>
  81306. * </div>
  81307. *
  81308. *@alt
  81309. * no image displayed
  81310. */
  81311. _main.default.Table.prototype.removeColumn = function(c) {
  81312. var cString;
  81313. var cNumber;
  81314. if (typeof c === 'string') {
  81315. // find the position of c in the columns
  81316. cString = c;
  81317. cNumber = this.columns.indexOf(c);
  81318. } else {
  81319. cNumber = c;
  81320. cString = this.columns[c];
  81321. }
  81322. var chunk = this.columns.splice(cNumber + 1, this.columns.length);
  81323. this.columns.pop();
  81324. this.columns = this.columns.concat(chunk);
  81325. for (var i = 0; i < this.rows.length; i++) {
  81326. var tempR = this.rows[i].arr;
  81327. var chip = tempR.splice(cNumber + 1, tempR.length);
  81328. tempR.pop();
  81329. this.rows[i].arr = tempR.concat(chip);
  81330. delete this.rows[i].obj[cString];
  81331. }
  81332. };
  81333. /**
  81334. * Stores a value in the Table's specified row and column.
  81335. * The row is specified by its ID, while the column may be specified
  81336. * by either its ID or title.
  81337. *
  81338. * @method set
  81339. * @param {Integer} row row ID
  81340. * @param {String|Integer} column column ID (Number)
  81341. * or title (String)
  81342. * @param {String|Number} value value to assign
  81343. *
  81344. * @example
  81345. * <div class="norender">
  81346. * <code>
  81347. * // Given the CSV file "mammals.csv"
  81348. * // in the project's "assets" folder:
  81349. * //
  81350. * // id,species,name
  81351. * // 0,Capra hircus,Goat
  81352. * // 1,Panthera pardus,Leopard
  81353. * // 2,Equus zebra,Zebra
  81354. *
  81355. * let table;
  81356. *
  81357. * function preload() {
  81358. * //my table is comma separated value "csv"
  81359. * //and has a header specifying the columns labels
  81360. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81361. * }
  81362. *
  81363. * function setup() {
  81364. * table.set(0, 'species', 'Canis Lupus');
  81365. * table.set(0, 'name', 'Wolf');
  81366. *
  81367. * //print the results
  81368. * for (let r = 0; r < table.getRowCount(); r++)
  81369. * for (let c = 0; c < table.getColumnCount(); c++)
  81370. * print(table.getString(r, c));
  81371. * }
  81372. * </code>
  81373. * </div>
  81374. *
  81375. *@alt
  81376. * no image displayed
  81377. */
  81378. _main.default.Table.prototype.set = function(row, column, value) {
  81379. this.rows[row].set(column, value);
  81380. };
  81381. /**
  81382. * Stores a Float value in the Table's specified row and column.
  81383. * The row is specified by its ID, while the column may be specified
  81384. * by either its ID or title.
  81385. *
  81386. * @method setNum
  81387. * @param {Integer} row row ID
  81388. * @param {String|Integer} column column ID (Number)
  81389. * or title (String)
  81390. * @param {Number} value value to assign
  81391. *
  81392. * @example
  81393. * <div class="norender">
  81394. * <code>
  81395. * // Given the CSV file "mammals.csv"
  81396. * // in the project's "assets" folder:
  81397. * //
  81398. * // id,species,name
  81399. * // 0,Capra hircus,Goat
  81400. * // 1,Panthera pardus,Leopard
  81401. * // 2,Equus zebra,Zebra
  81402. *
  81403. * let table;
  81404. *
  81405. * function preload() {
  81406. * //my table is comma separated value "csv"
  81407. * //and has a header specifying the columns labels
  81408. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81409. * }
  81410. *
  81411. * function setup() {
  81412. * table.setNum(1, 'id', 1);
  81413. *
  81414. * print(table.getColumn(0));
  81415. * //["0", 1, "2"]
  81416. * }
  81417. * </code>
  81418. * </div>
  81419. *
  81420. *@alt
  81421. * no image displayed
  81422. */
  81423. _main.default.Table.prototype.setNum = function(row, column, value) {
  81424. this.rows[row].setNum(column, value);
  81425. };
  81426. /**
  81427. * Stores a String value in the Table's specified row and column.
  81428. * The row is specified by its ID, while the column may be specified
  81429. * by either its ID or title.
  81430. *
  81431. * @method setString
  81432. * @param {Integer} row row ID
  81433. * @param {String|Integer} column column ID (Number)
  81434. * or title (String)
  81435. * @param {String} value value to assign
  81436. * @example
  81437. * <div class="norender"><code>
  81438. * // Given the CSV file "mammals.csv" in the project's "assets" folder:
  81439. * //
  81440. * // id,species,name
  81441. * // 0,Capra hircus,Goat
  81442. * // 1,Panthera pardus,Leopard
  81443. * // 2,Equus zebra,Zebra
  81444. *
  81445. * let table;
  81446. *
  81447. * function preload() {
  81448. * //my table is comma separated value "csv"
  81449. * //and has a header specifying the columns labels
  81450. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81451. * }
  81452. *
  81453. * function setup() {
  81454. * //add a row
  81455. * let newRow = table.addRow();
  81456. * newRow.setString('id', table.getRowCount() - 1);
  81457. * newRow.setString('species', 'Canis Lupus');
  81458. * newRow.setString('name', 'Wolf');
  81459. *
  81460. * print(table.getArray());
  81461. * }
  81462. * </code></div>
  81463. *
  81464. * @alt
  81465. * no image displayed
  81466. */
  81467. _main.default.Table.prototype.setString = function(row, column, value) {
  81468. this.rows[row].setString(column, value);
  81469. };
  81470. /**
  81471. * Retrieves a value from the Table's specified row and column.
  81472. * The row is specified by its ID, while the column may be specified by
  81473. * either its ID or title.
  81474. *
  81475. * @method get
  81476. * @param {Integer} row row ID
  81477. * @param {String|Integer} column columnName (string) or
  81478. * ID (number)
  81479. * @return {String|Number}
  81480. *
  81481. * @example
  81482. * <div class="norender">
  81483. * <code>
  81484. * // Given the CSV file "mammals.csv"
  81485. * // in the project's "assets" folder:
  81486. * //
  81487. * // id,species,name
  81488. * // 0,Capra hircus,Goat
  81489. * // 1,Panthera pardus,Leopard
  81490. * // 2,Equus zebra,Zebra
  81491. *
  81492. * let table;
  81493. *
  81494. * function preload() {
  81495. * //my table is comma separated value "csv"
  81496. * //and has a header specifying the columns labels
  81497. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81498. * }
  81499. *
  81500. * function setup() {
  81501. * print(table.get(0, 1));
  81502. * //Capra hircus
  81503. * print(table.get(0, 'species'));
  81504. * //Capra hircus
  81505. * }
  81506. * </code>
  81507. * </div>
  81508. *
  81509. *@alt
  81510. * no image displayed
  81511. */
  81512. _main.default.Table.prototype.get = function(row, column) {
  81513. return this.rows[row].get(column);
  81514. };
  81515. /**
  81516. * Retrieves a Float value from the Table's specified row and column.
  81517. * The row is specified by its ID, while the column may be specified by
  81518. * either its ID or title.
  81519. *
  81520. * @method getNum
  81521. * @param {Integer} row row ID
  81522. * @param {String|Integer} column columnName (string) or
  81523. * ID (number)
  81524. * @return {Number}
  81525. *
  81526. * @example
  81527. * <div class="norender">
  81528. * <code>
  81529. * // Given the CSV file "mammals.csv"
  81530. * // in the project's "assets" folder:
  81531. * //
  81532. * // id,species,name
  81533. * // 0,Capra hircus,Goat
  81534. * // 1,Panthera pardus,Leopard
  81535. * // 2,Equus zebra,Zebra
  81536. *
  81537. * let table;
  81538. *
  81539. * function preload() {
  81540. * //my table is comma separated value "csv"
  81541. * //and has a header specifying the columns labels
  81542. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81543. * }
  81544. *
  81545. * function setup() {
  81546. * print(table.getNum(1, 0) + 100);
  81547. * //id 1 + 100 = 101
  81548. * }
  81549. * </code>
  81550. * </div>
  81551. *
  81552. *@alt
  81553. * no image displayed
  81554. */
  81555. _main.default.Table.prototype.getNum = function(row, column) {
  81556. return this.rows[row].getNum(column);
  81557. };
  81558. /**
  81559. * Retrieves a String value from the Table's specified row and column.
  81560. * The row is specified by its ID, while the column may be specified by
  81561. * either its ID or title.
  81562. *
  81563. * @method getString
  81564. * @param {Integer} row row ID
  81565. * @param {String|Integer} column columnName (string) or
  81566. * ID (number)
  81567. * @return {String}
  81568. *
  81569. * @example
  81570. * <div class="norender">
  81571. * <code>
  81572. * // Given the CSV file "mammals.csv"
  81573. * // in the project's "assets" folder:
  81574. * //
  81575. * // id,species,name
  81576. * // 0,Capra hircus,Goat
  81577. * // 1,Panthera pardus,Leopard
  81578. * // 2,Equus zebra,Zebra
  81579. *
  81580. * let table;
  81581. *
  81582. * function preload() {
  81583. * // table is comma separated value "CSV"
  81584. * // and has specifiying header for column labels
  81585. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81586. * }
  81587. *
  81588. * function setup() {
  81589. * print(table.getString(0, 0)); // 0
  81590. * print(table.getString(0, 1)); // Capra hircus
  81591. * print(table.getString(0, 2)); // Goat
  81592. * print(table.getString(1, 0)); // 1
  81593. * print(table.getString(1, 1)); // Panthera pardus
  81594. * print(table.getString(1, 2)); // Leopard
  81595. * print(table.getString(2, 0)); // 2
  81596. * print(table.getString(2, 1)); // Equus zebra
  81597. * print(table.getString(2, 2)); // Zebra
  81598. * }
  81599. * </code>
  81600. * </div>
  81601. *
  81602. *@alt
  81603. * no image displayed
  81604. */
  81605. _main.default.Table.prototype.getString = function(row, column) {
  81606. return this.rows[row].getString(column);
  81607. };
  81608. /**
  81609. * Retrieves all table data and returns as an object. If a column name is
  81610. * passed in, each row object will be stored with that attribute as its
  81611. * title.
  81612. *
  81613. * @method getObject
  81614. * @param {String} [headerColumn] Name of the column which should be used to
  81615. * title each row object (optional)
  81616. * @return {Object}
  81617. *
  81618. * @example
  81619. * <div class="norender">
  81620. * <code>
  81621. * // Given the CSV file "mammals.csv"
  81622. * // in the project's "assets" folder:
  81623. * //
  81624. * // id,species,name
  81625. * // 0,Capra hircus,Goat
  81626. * // 1,Panthera pardus,Leopard
  81627. * // 2,Equus zebra,Zebra
  81628. *
  81629. * let table;
  81630. *
  81631. * function preload() {
  81632. * //my table is comma separated value "csv"
  81633. * //and has a header specifying the columns labels
  81634. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81635. * }
  81636. *
  81637. * function setup() {
  81638. * let tableObject = table.getObject();
  81639. *
  81640. * print(tableObject);
  81641. * //outputs an object
  81642. * }
  81643. * </code>
  81644. * </div>
  81645. *
  81646. *@alt
  81647. * no image displayed
  81648. */
  81649. _main.default.Table.prototype.getObject = function(headerColumn) {
  81650. var tableObject = {};
  81651. var obj, cPos, index;
  81652. for (var i = 0; i < this.rows.length; i++) {
  81653. obj = this.rows[i].obj;
  81654. if (typeof headerColumn === 'string') {
  81655. cPos = this.columns.indexOf(headerColumn); // index of columnID
  81656. if (cPos >= 0) {
  81657. index = obj[headerColumn];
  81658. tableObject[index] = obj;
  81659. } else {
  81660. throw new Error(
  81661. 'This table has no column named "'.concat(headerColumn, '"')
  81662. );
  81663. }
  81664. } else {
  81665. tableObject[i] = this.rows[i].obj;
  81666. }
  81667. }
  81668. return tableObject;
  81669. };
  81670. /**
  81671. * Retrieves all table data and returns it as a multidimensional array.
  81672. *
  81673. * @method getArray
  81674. * @return {Array}
  81675. *
  81676. * @example
  81677. * <div class="norender">
  81678. * <code>
  81679. * // Given the CSV file "mammals.csv"
  81680. * // in the project's "assets" folder
  81681. * //
  81682. * // id,species,name
  81683. * // 0,Capra hircus,Goat
  81684. * // 1,Panthera pardus,Leoperd
  81685. * // 2,Equus zebra,Zebra
  81686. *
  81687. * let table;
  81688. *
  81689. * function preload() {
  81690. * // table is comma separated value "CSV"
  81691. * // and has specifiying header for column labels
  81692. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81693. * }
  81694. *
  81695. * function setup() {
  81696. * let tableArray = table.getArray();
  81697. * for (let i = 0; i < tableArray.length; i++) {
  81698. * print(tableArray[i]);
  81699. * }
  81700. * }
  81701. * </code>
  81702. * </div>
  81703. *
  81704. *@alt
  81705. * no image displayed
  81706. */
  81707. _main.default.Table.prototype.getArray = function() {
  81708. var tableArray = [];
  81709. for (var i = 0; i < this.rows.length; i++) {
  81710. tableArray.push(this.rows[i].arr);
  81711. }
  81712. return tableArray;
  81713. };
  81714. var _default = _main.default;
  81715. exports.default = _default;
  81716. },
  81717. {
  81718. '../core/main': 283,
  81719. 'core-js/modules/es.array.concat': 166,
  81720. 'core-js/modules/es.array.index-of': 173,
  81721. 'core-js/modules/es.array.join': 175,
  81722. 'core-js/modules/es.array.splice': 180,
  81723. 'core-js/modules/es.regexp.constructor': 195,
  81724. 'core-js/modules/es.regexp.exec': 196,
  81725. 'core-js/modules/es.regexp.to-string': 197,
  81726. 'core-js/modules/es.string.match': 202,
  81727. 'core-js/modules/es.string.replace': 204,
  81728. 'core-js/modules/es.string.trim': 208
  81729. }
  81730. ],
  81731. 311: [
  81732. function(_dereq_, module, exports) {
  81733. 'use strict';
  81734. _dereq_('core-js/modules/es.array.index-of');
  81735. _dereq_('core-js/modules/es.object.to-string');
  81736. _dereq_('core-js/modules/es.regexp.exec');
  81737. _dereq_('core-js/modules/es.regexp.to-string');
  81738. _dereq_('core-js/modules/es.string.split');
  81739. Object.defineProperty(exports, '__esModule', { value: true });
  81740. exports.default = void 0;
  81741. var _main = _interopRequireDefault(_dereq_('../core/main'));
  81742. function _interopRequireDefault(obj) {
  81743. return obj && obj.__esModule ? obj : { default: obj };
  81744. }
  81745. /**
  81746. * @module IO
  81747. * @submodule Table
  81748. * @requires core
  81749. */ /**
  81750. * A TableRow object represents a single row of data values,
  81751. * stored in columns, from a table.
  81752. *
  81753. * A Table Row contains both an ordered array, and an unordered
  81754. * JSON object.
  81755. *
  81756. * @class p5.TableRow
  81757. * @constructor
  81758. * @param {String} [str] optional: populate the row with a
  81759. * string of values, separated by the
  81760. * separator
  81761. * @param {String} [separator] comma separated values (csv) by default
  81762. */ _main.default.TableRow = function(str, separator) {
  81763. var arr = [];
  81764. var obj = {};
  81765. if (str) {
  81766. separator = separator || ',';
  81767. arr = str.split(separator);
  81768. }
  81769. for (var i = 0; i < arr.length; i++) {
  81770. var key = i;
  81771. var val = arr[i];
  81772. obj[key] = val;
  81773. }
  81774. this.arr = arr;
  81775. this.obj = obj;
  81776. this.table = null;
  81777. };
  81778. /**
  81779. * Stores a value in the TableRow's specified column.
  81780. * The column may be specified by either its ID or title.
  81781. *
  81782. * @method set
  81783. * @param {String|Integer} column Column ID (Number)
  81784. * or Title (String)
  81785. * @param {String|Number} value The value to be stored
  81786. *
  81787. * @example
  81788. * <div class="norender"><code>
  81789. * // Given the CSV file "mammals.csv" in the project's "assets" folder:
  81790. * //
  81791. * // id,species,name
  81792. * // 0,Capra hircus,Goat
  81793. * // 1,Panthera pardus,Leopard
  81794. * // 2,Equus zebra,Zebra
  81795. *
  81796. * let table;
  81797. *
  81798. * function preload() {
  81799. * //my table is comma separated value "csv"
  81800. * //and has a header specifying the columns labels
  81801. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81802. * }
  81803. *
  81804. * function setup() {
  81805. * let rows = table.getRows();
  81806. * for (let r = 0; r < rows.length; r++) {
  81807. * rows[r].set('name', 'Unicorn');
  81808. * }
  81809. *
  81810. * //print the results
  81811. * print(table.getArray());
  81812. * }
  81813. * </code></div>
  81814. *
  81815. * @alt
  81816. * no image displayed
  81817. */
  81818. _main.default.TableRow.prototype.set = function(column, value) {
  81819. // if typeof column is string, use .obj
  81820. if (typeof column === 'string') {
  81821. var cPos = this.table.columns.indexOf(column); // index of columnID
  81822. if (cPos >= 0) {
  81823. this.obj[column] = value;
  81824. this.arr[cPos] = value;
  81825. } else {
  81826. throw new Error('This table has no column named "'.concat(column, '"'));
  81827. }
  81828. } else {
  81829. // if typeof column is number, use .arr
  81830. if (column < this.table.columns.length) {
  81831. this.arr[column] = value;
  81832. var cTitle = this.table.columns[column];
  81833. this.obj[cTitle] = value;
  81834. } else {
  81835. throw new Error(
  81836. 'Column #'.concat(column, ' is out of the range of this table')
  81837. );
  81838. }
  81839. }
  81840. };
  81841. /**
  81842. * Stores a Float value in the TableRow's specified column.
  81843. * The column may be specified by either its ID or title.
  81844. *
  81845. * @method setNum
  81846. * @param {String|Integer} column Column ID (Number)
  81847. * or Title (String)
  81848. * @param {Number|String} value The value to be stored
  81849. * as a Float
  81850. * @example
  81851. * <div class="norender"><code>
  81852. * // Given the CSV file "mammals.csv" in the project's "assets" folder:
  81853. * //
  81854. * // id,species,name
  81855. * // 0,Capra hircus,Goat
  81856. * // 1,Panthera pardus,Leopard
  81857. * // 2,Equus zebra,Zebra
  81858. *
  81859. * let table;
  81860. *
  81861. * function preload() {
  81862. * //my table is comma separated value "csv"
  81863. * //and has a header specifying the columns labels
  81864. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81865. * }
  81866. *
  81867. * function setup() {
  81868. * let rows = table.getRows();
  81869. * for (let r = 0; r < rows.length; r++) {
  81870. * rows[r].setNum('id', r + 10);
  81871. * }
  81872. *
  81873. * print(table.getArray());
  81874. * }
  81875. * </code></div>
  81876. *
  81877. * @alt
  81878. * no image displayed
  81879. */
  81880. _main.default.TableRow.prototype.setNum = function(column, value) {
  81881. var floatVal = parseFloat(value);
  81882. this.set(column, floatVal);
  81883. };
  81884. /**
  81885. * Stores a String value in the TableRow's specified column.
  81886. * The column may be specified by either its ID or title.
  81887. *
  81888. * @method setString
  81889. * @param {String|Integer} column Column ID (Number)
  81890. * or Title (String)
  81891. * @param {String|Number|Boolean|Object} value The value to be stored
  81892. * as a String
  81893. * @example
  81894. * <div class="norender"><code>
  81895. * // Given the CSV file "mammals.csv" in the project's "assets" folder:
  81896. * //
  81897. * // id,species,name
  81898. * // 0,Capra hircus,Goat
  81899. * // 1,Panthera pardus,Leopard
  81900. * // 2,Equus zebra,Zebra
  81901. *
  81902. * let table;
  81903. *
  81904. * function preload() {
  81905. * //my table is comma separated value "csv"
  81906. * //and has a header specifying the columns labels
  81907. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81908. * }
  81909. *
  81910. * function setup() {
  81911. * let rows = table.getRows();
  81912. * for (let r = 0; r < rows.length; r++) {
  81913. * let name = rows[r].getString('name');
  81914. * rows[r].setString('name', 'A ' + name + ' named George');
  81915. * }
  81916. *
  81917. * print(table.getArray());
  81918. * }
  81919. * </code></div>
  81920. *
  81921. * @alt
  81922. * no image displayed
  81923. */
  81924. _main.default.TableRow.prototype.setString = function(column, value) {
  81925. var stringVal = value.toString();
  81926. this.set(column, stringVal);
  81927. };
  81928. /**
  81929. * Retrieves a value from the TableRow's specified column.
  81930. * The column may be specified by either its ID or title.
  81931. *
  81932. * @method get
  81933. * @param {String|Integer} column columnName (string) or
  81934. * ID (number)
  81935. * @return {String|Number}
  81936. *
  81937. * @example
  81938. * <div class="norender"><code>
  81939. * // Given the CSV file "mammals.csv" in the project's "assets" folder:
  81940. * //
  81941. * // id,species,name
  81942. * // 0,Capra hircus,Goat
  81943. * // 1,Panthera pardus,Leopard
  81944. * // 2,Equus zebra,Zebra
  81945. *
  81946. * let table;
  81947. *
  81948. * function preload() {
  81949. * //my table is comma separated value "csv"
  81950. * //and has a header specifying the columns labels
  81951. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81952. * }
  81953. *
  81954. * function setup() {
  81955. * let names = [];
  81956. * let rows = table.getRows();
  81957. * for (let r = 0; r < rows.length; r++) {
  81958. * names.push(rows[r].get('name'));
  81959. * }
  81960. *
  81961. * print(names);
  81962. * }
  81963. * </code></div>
  81964. *
  81965. * @alt
  81966. * no image displayed
  81967. */
  81968. _main.default.TableRow.prototype.get = function(column) {
  81969. if (typeof column === 'string') {
  81970. return this.obj[column];
  81971. } else {
  81972. return this.arr[column];
  81973. }
  81974. };
  81975. /**
  81976. * Retrieves a Float value from the TableRow's specified
  81977. * column. The column may be specified by either its ID or
  81978. * title.
  81979. *
  81980. * @method getNum
  81981. * @param {String|Integer} column columnName (string) or
  81982. * ID (number)
  81983. * @return {Number} Float Floating point number
  81984. * @example
  81985. * <div class="norender"><code>
  81986. * // Given the CSV file "mammals.csv" in the project's "assets" folder:
  81987. * //
  81988. * // id,species,name
  81989. * // 0,Capra hircus,Goat
  81990. * // 1,Panthera pardus,Leopard
  81991. * // 2,Equus zebra,Zebra
  81992. *
  81993. * let table;
  81994. *
  81995. * function preload() {
  81996. * //my table is comma separated value "csv"
  81997. * //and has a header specifying the columns labels
  81998. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  81999. * }
  82000. *
  82001. * function setup() {
  82002. * let rows = table.getRows();
  82003. * let minId = Infinity;
  82004. * let maxId = -Infinity;
  82005. * for (let r = 0; r < rows.length; r++) {
  82006. * let id = rows[r].getNum('id');
  82007. * minId = min(minId, id);
  82008. * maxId = min(maxId, id);
  82009. * }
  82010. * print('minimum id = ' + minId + ', maximum id = ' + maxId);
  82011. * }
  82012. * </code></div>
  82013. *
  82014. * @alt
  82015. * no image displayed
  82016. */
  82017. _main.default.TableRow.prototype.getNum = function(column) {
  82018. var ret;
  82019. if (typeof column === 'string') {
  82020. ret = parseFloat(this.obj[column]);
  82021. } else {
  82022. ret = parseFloat(this.arr[column]);
  82023. }
  82024. if (ret.toString() === 'NaN') {
  82025. throw 'Error: '.concat(this.obj[column], ' is NaN (Not a Number)');
  82026. }
  82027. return ret;
  82028. };
  82029. /**
  82030. * Retrieves an String value from the TableRow's specified
  82031. * column. The column may be specified by either its ID or
  82032. * title.
  82033. *
  82034. * @method getString
  82035. * @param {String|Integer} column columnName (string) or
  82036. * ID (number)
  82037. * @return {String} String
  82038. * @example
  82039. * <div class="norender"><code>
  82040. * // Given the CSV file "mammals.csv" in the project's "assets" folder:
  82041. * //
  82042. * // id,species,name
  82043. * // 0,Capra hircus,Goat
  82044. * // 1,Panthera pardus,Leopard
  82045. * // 2,Equus zebra,Zebra
  82046. *
  82047. * let table;
  82048. *
  82049. * function preload() {
  82050. * //my table is comma separated value "csv"
  82051. * //and has a header specifying the columns labels
  82052. * table = loadTable('assets/mammals.csv', 'csv', 'header');
  82053. * }
  82054. *
  82055. * function setup() {
  82056. * let rows = table.getRows();
  82057. * let longest = '';
  82058. * for (let r = 0; r < rows.length; r++) {
  82059. * let species = rows[r].getString('species');
  82060. * if (longest.length < species.length) {
  82061. * longest = species;
  82062. * }
  82063. * }
  82064. *
  82065. * print('longest: ' + longest);
  82066. * }
  82067. * </code></div>
  82068. *
  82069. * @alt
  82070. * no image displayed
  82071. */
  82072. _main.default.TableRow.prototype.getString = function(column) {
  82073. if (typeof column === 'string') {
  82074. return this.obj[column].toString();
  82075. } else {
  82076. return this.arr[column].toString();
  82077. }
  82078. };
  82079. var _default = _main.default;
  82080. exports.default = _default;
  82081. },
  82082. {
  82083. '../core/main': 283,
  82084. 'core-js/modules/es.array.index-of': 173,
  82085. 'core-js/modules/es.object.to-string': 192,
  82086. 'core-js/modules/es.regexp.exec': 196,
  82087. 'core-js/modules/es.regexp.to-string': 197,
  82088. 'core-js/modules/es.string.split': 206
  82089. }
  82090. ],
  82091. 312: [
  82092. function(_dereq_, module, exports) {
  82093. 'use strict';
  82094. _dereq_('core-js/modules/es.symbol');
  82095. _dereq_('core-js/modules/es.symbol.description');
  82096. _dereq_('core-js/modules/es.symbol.iterator');
  82097. _dereq_('core-js/modules/es.array.iterator');
  82098. _dereq_('core-js/modules/es.number.constructor');
  82099. _dereq_('core-js/modules/es.object.to-string');
  82100. _dereq_('core-js/modules/es.regexp.exec');
  82101. _dereq_('core-js/modules/es.string.iterator');
  82102. _dereq_('core-js/modules/es.string.replace');
  82103. _dereq_('core-js/modules/web.dom-collections.iterator');
  82104. Object.defineProperty(exports, '__esModule', { value: true });
  82105. exports.default = void 0;
  82106. var _main = _interopRequireDefault(_dereq_('../core/main'));
  82107. function _interopRequireDefault(obj) {
  82108. return obj && obj.__esModule ? obj : { default: obj };
  82109. }
  82110. /**
  82111. * @module IO
  82112. * @submodule Input
  82113. * @requires core
  82114. */ /**
  82115. * XML is a representation of an XML object, able to parse XML code. Use
  82116. * <a href="#/p5/loadXML">loadXML()</a> to load external XML files and create XML objects.
  82117. *
  82118. * @class p5.XML
  82119. * @constructor
  82120. * @example
  82121. * <div class='norender'><code>
  82122. * // The following short XML file called "mammals.xml" is parsed
  82123. * // in the code below.
  82124. * //
  82125. * // <?xml version="1.0"?>
  82126. * // &lt;mammals&gt;
  82127. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82128. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82129. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82130. * // &lt;/mammals&gt;
  82131. *
  82132. * let xml;
  82133. *
  82134. * function preload() {
  82135. * xml = loadXML('assets/mammals.xml');
  82136. * }
  82137. *
  82138. * function setup() {
  82139. * let children = xml.getChildren('animal');
  82140. *
  82141. * for (let i = 0; i < children.length; i++) {
  82142. * let id = children[i].getNum('id');
  82143. * let coloring = children[i].getString('species');
  82144. * let name = children[i].getContent();
  82145. * print(id + ', ' + coloring + ', ' + name);
  82146. * }
  82147. * }
  82148. *
  82149. * // Sketch prints:
  82150. * // 0, Capra hircus, Goat
  82151. * // 1, Panthera pardus, Leopard
  82152. * // 2, Equus zebra, Zebra
  82153. * </code></div>
  82154. *
  82155. * @alt
  82156. * no image displayed
  82157. */ _main.default.XML = function(DOM) {
  82158. if (!DOM) {
  82159. var xmlDoc = document.implementation.createDocument(null, 'doc');
  82160. this.DOM = xmlDoc.createElement('root');
  82161. } else {
  82162. this.DOM = DOM;
  82163. }
  82164. };
  82165. /**
  82166. * Gets a copy of the element's parent. Returns the parent as another
  82167. * <a href="#/p5.XML">p5.XML</a> object.
  82168. *
  82169. * @method getParent
  82170. * @return {p5.XML} element parent
  82171. * @example
  82172. * <div class='norender'><code>
  82173. * // The following short XML file called "mammals.xml" is parsed
  82174. * // in the code below.
  82175. * //
  82176. * // <?xml version="1.0"?>
  82177. * // &lt;mammals&gt;
  82178. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82179. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82180. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82181. * // &lt;/mammals&gt;
  82182. *
  82183. * let xml;
  82184. *
  82185. * function preload() {
  82186. * xml = loadXML('assets/mammals.xml');
  82187. * }
  82188. *
  82189. * function setup() {
  82190. * let children = xml.getChildren('animal');
  82191. * let parent = children[1].getParent();
  82192. * print(parent.getName());
  82193. * }
  82194. *
  82195. * // Sketch prints:
  82196. * // mammals
  82197. * </code></div>
  82198. */
  82199. _main.default.XML.prototype.getParent = function() {
  82200. return new _main.default.XML(this.DOM.parentElement);
  82201. };
  82202. /**
  82203. * Gets the element's full name, which is returned as a String.
  82204. *
  82205. * @method getName
  82206. * @return {String} the name of the node
  82207. * @example&lt;animal
  82208. * <div class='norender'><code>
  82209. * // The following short XML file called "mammals.xml" is parsed
  82210. * // in the code below.
  82211. * //
  82212. * // <?xml version="1.0"?>
  82213. * // &lt;mammals&gt;
  82214. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82215. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82216. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82217. * // &lt;/mammals&gt;
  82218. *
  82219. * let xml;
  82220. *
  82221. * function preload() {
  82222. * xml = loadXML('assets/mammals.xml');
  82223. * }
  82224. *
  82225. * function setup() {
  82226. * print(xml.getName());
  82227. * }
  82228. *
  82229. * // Sketch prints:
  82230. * // mammals
  82231. * </code></div>
  82232. */
  82233. _main.default.XML.prototype.getName = function() {
  82234. return this.DOM.tagName;
  82235. };
  82236. /**
  82237. * Sets the element's name, which is specified as a String.
  82238. *
  82239. * @method setName
  82240. * @param {String} the new name of the node
  82241. * @example&lt;animal
  82242. * <div class='norender'><code>
  82243. * // The following short XML file called "mammals.xml" is parsed
  82244. * // in the code below.
  82245. * //
  82246. * // <?xml version="1.0"?>
  82247. * // &lt;mammals&gt;
  82248. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82249. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82250. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82251. * // &lt;/mammals&gt;
  82252. *
  82253. * let xml;
  82254. *
  82255. * function preload() {
  82256. * xml = loadXML('assets/mammals.xml');
  82257. * }
  82258. *
  82259. * function setup() {
  82260. * print(xml.getName());
  82261. * xml.setName('fish');
  82262. * print(xml.getName());
  82263. * }
  82264. *
  82265. * // Sketch prints:
  82266. * // mammals
  82267. * // fish
  82268. * </code></div>
  82269. */
  82270. _main.default.XML.prototype.setName = function(name) {
  82271. var content = this.DOM.innerHTML;
  82272. var attributes = this.DOM.attributes;
  82273. var xmlDoc = document.implementation.createDocument(null, 'default');
  82274. var newDOM = xmlDoc.createElement(name);
  82275. newDOM.innerHTML = content;
  82276. for (var i = 0; i < attributes.length; i++) {
  82277. newDOM.setAttribute(attributes[i].nodeName, attributes.nodeValue);
  82278. }
  82279. this.DOM = newDOM;
  82280. };
  82281. /**
  82282. * Checks whether or not the element has any children, and returns the result
  82283. * as a boolean.
  82284. *
  82285. * @method hasChildren
  82286. * @return {boolean}
  82287. * @example&lt;animal
  82288. * <div class='norender'><code>
  82289. * // The following short XML file called "mammals.xml" is parsed
  82290. * // in the code below.
  82291. * //
  82292. * // <?xml version="1.0"?>
  82293. * // &lt;mammals&gt;
  82294. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82295. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82296. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82297. * // &lt;/mammals&gt;
  82298. *
  82299. * let xml;
  82300. *
  82301. * function preload() {
  82302. * xml = loadXML('assets/mammals.xml');
  82303. * }
  82304. *
  82305. * function setup() {
  82306. * print(xml.hasChildren());
  82307. * }
  82308. *
  82309. * // Sketch prints:
  82310. * // true
  82311. * </code></div>
  82312. */
  82313. _main.default.XML.prototype.hasChildren = function() {
  82314. return this.DOM.children.length > 0;
  82315. };
  82316. /**
  82317. * Get the names of all of the element's children, and returns the names as an
  82318. * array of Strings. This is the same as looping through and calling <a href="#/p5.XML/getName">getName()</a>
  82319. * on each child element individually.
  82320. *
  82321. * @method listChildren
  82322. * @return {String[]} names of the children of the element
  82323. * @example&lt;animal
  82324. * <div class='norender'><code>
  82325. * // The following short XML file called "mammals.xml" is parsed
  82326. * // in the code below.
  82327. * //
  82328. * // <?xml version="1.0"?>
  82329. * // &lt;mammals&gt;
  82330. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82331. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82332. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82333. * // &lt;/mammals&gt;
  82334. *
  82335. * let xml;
  82336. *
  82337. * function preload() {
  82338. * xml = loadXML('assets/mammals.xml');
  82339. * }
  82340. *
  82341. * function setup() {
  82342. * print(xml.listChildren());
  82343. * }
  82344. *
  82345. * // Sketch prints:
  82346. * // ["animal", "animal", "animal"]
  82347. * </code></div>
  82348. */
  82349. _main.default.XML.prototype.listChildren = function() {
  82350. var arr = [];
  82351. for (var i = 0; i < this.DOM.childNodes.length; i++) {
  82352. arr.push(this.DOM.childNodes[i].nodeName);
  82353. }
  82354. return arr;
  82355. };
  82356. /**
  82357. * Returns all of the element's children as an array of <a href="#/p5.XML">p5.XML</a> objects. When
  82358. * the name parameter is specified, then it will return all children that match
  82359. * that name.
  82360. *
  82361. * @method getChildren
  82362. * @param {String} [name] element name
  82363. * @return {p5.XML[]} children of the element
  82364. * @example&lt;animal
  82365. * <div class='norender'><code>
  82366. * // The following short XML file called "mammals.xml" is parsed
  82367. * // in the code below.
  82368. * //
  82369. * // <?xml version="1.0"?>
  82370. * // &lt;mammals&gt;
  82371. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82372. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82373. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82374. * // &lt;/mammals&gt;
  82375. *
  82376. * let xml;
  82377. *
  82378. * function preload() {
  82379. * xml = loadXML('assets/mammals.xml');
  82380. * }
  82381. *
  82382. * function setup() {
  82383. * let animals = xml.getChildren('animal');
  82384. *
  82385. * for (let i = 0; i < animals.length; i++) {
  82386. * print(animals[i].getContent());
  82387. * }
  82388. * }
  82389. *
  82390. * // Sketch prints:
  82391. * // "Goat"
  82392. * // "Leopard"
  82393. * // "Zebra"
  82394. * </code></div>
  82395. */
  82396. _main.default.XML.prototype.getChildren = function(param) {
  82397. if (param) {
  82398. return elementsToP5XML(this.DOM.getElementsByTagName(param));
  82399. } else {
  82400. return elementsToP5XML(this.DOM.children);
  82401. }
  82402. };
  82403. function elementsToP5XML(elements) {
  82404. var arr = [];
  82405. for (var i = 0; i < elements.length; i++) {
  82406. arr.push(new _main.default.XML(elements[i]));
  82407. }
  82408. return arr;
  82409. }
  82410. /**
  82411. * Returns the first of the element's children that matches the name parameter
  82412. * or the child of the given index.It returns undefined if no matching
  82413. * child is found.
  82414. *
  82415. * @method getChild
  82416. * @param {String|Integer} name element name or index
  82417. * @return {p5.XML}
  82418. * @example&lt;animal
  82419. * <div class='norender'><code>
  82420. * // The following short XML file called "mammals.xml" is parsed
  82421. * // in the code below.
  82422. * //
  82423. * // <?xml version="1.0"?>
  82424. * // &lt;mammals&gt;
  82425. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82426. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82427. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82428. * // &lt;/mammals&gt;
  82429. *
  82430. * let xml;
  82431. *
  82432. * function preload() {
  82433. * xml = loadXML('assets/mammals.xml');
  82434. * }
  82435. *
  82436. * function setup() {
  82437. * let firstChild = xml.getChild('animal');
  82438. * print(firstChild.getContent());
  82439. * }
  82440. *
  82441. * // Sketch prints:
  82442. * // "Goat"
  82443. * </code></div>
  82444. * <div class='norender'><code>
  82445. * let xml;
  82446. *
  82447. * function preload() {
  82448. * xml = loadXML('assets/mammals.xml');
  82449. * }
  82450. *
  82451. * function setup() {
  82452. * let secondChild = xml.getChild(1);
  82453. * print(secondChild.getContent());
  82454. * }
  82455. *
  82456. * // Sketch prints:
  82457. * // "Leopard"
  82458. * </code></div>
  82459. */
  82460. _main.default.XML.prototype.getChild = function(param) {
  82461. if (typeof param === 'string') {
  82462. var _iteratorNormalCompletion = true;
  82463. var _didIteratorError = false;
  82464. var _iteratorError = undefined;
  82465. try {
  82466. for (
  82467. var _iterator = this.DOM.children[Symbol.iterator](), _step;
  82468. !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
  82469. _iteratorNormalCompletion = true
  82470. ) {
  82471. var child = _step.value;
  82472. if (child.tagName === param) return new _main.default.XML(child);
  82473. }
  82474. } catch (err) {
  82475. _didIteratorError = true;
  82476. _iteratorError = err;
  82477. } finally {
  82478. try {
  82479. if (!_iteratorNormalCompletion && _iterator.return != null) {
  82480. _iterator.return();
  82481. }
  82482. } finally {
  82483. if (_didIteratorError) {
  82484. throw _iteratorError;
  82485. }
  82486. }
  82487. }
  82488. } else {
  82489. return new _main.default.XML(this.DOM.children[param]);
  82490. }
  82491. };
  82492. /**
  82493. * Appends a new child to the element. The child can be specified with
  82494. * either a String, which will be used as the new tag's name, or as a
  82495. * reference to an existing <a href="#/p5.XML">p5.XML</a> object.
  82496. * A reference to the newly created child is returned as an <a href="#/p5.XML">p5.XML</a> object.
  82497. *
  82498. * @method addChild
  82499. * @param {p5.XML} node a <a href="#/p5.XML">p5.XML</a> Object which will be the child to be added
  82500. * @example
  82501. * <div class='norender'><code>
  82502. * // The following short XML file called "mammals.xml" is parsed
  82503. * // in the code below.
  82504. * //
  82505. * // <?xml version="1.0"?>
  82506. * // &lt;mammals&gt;
  82507. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82508. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82509. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82510. * // &lt;/mammals&gt;
  82511. *
  82512. * let xml;
  82513. *
  82514. * function preload() {
  82515. * xml = loadXML('assets/mammals.xml');
  82516. * }
  82517. *
  82518. * function setup() {
  82519. * let child = new p5.XML();
  82520. * child.setName('animal');
  82521. * child.setAttribute('id', '3');
  82522. * child.setAttribute('species', 'Ornithorhynchus anatinus');
  82523. * child.setContent('Platypus');
  82524. * xml.addChild(child);
  82525. *
  82526. * let animals = xml.getChildren('animal');
  82527. * print(animals[animals.length - 1].getContent());
  82528. * }
  82529. *
  82530. * // Sketch prints:
  82531. * // "Goat"
  82532. * // "Leopard"
  82533. * // "Zebra"
  82534. * </code></div>
  82535. */
  82536. _main.default.XML.prototype.addChild = function(node) {
  82537. if (node instanceof _main.default.XML) {
  82538. this.DOM.appendChild(node.DOM);
  82539. } else {
  82540. // PEND
  82541. }
  82542. };
  82543. /**
  82544. * Removes the element specified by name or index.
  82545. *
  82546. * @method removeChild
  82547. * @param {String|Integer} name element name or index
  82548. * @example
  82549. * <div class='norender'><code>
  82550. * // The following short XML file called "mammals.xml" is parsed
  82551. * // in the code below.
  82552. * //
  82553. * // <?xml version="1.0"?>
  82554. * // &lt;mammals&gt;
  82555. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82556. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82557. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82558. * // &lt;/mammals&gt;
  82559. *
  82560. * let xml;
  82561. *
  82562. * function preload() {
  82563. * xml = loadXML('assets/mammals.xml');
  82564. * }
  82565. *
  82566. * function setup() {
  82567. * xml.removeChild('animal');
  82568. * let children = xml.getChildren();
  82569. * for (let i = 0; i < children.length; i++) {
  82570. * print(children[i].getContent());
  82571. * }
  82572. * }
  82573. *
  82574. * // Sketch prints:
  82575. * // "Leopard"
  82576. * // "Zebra"
  82577. * </code></div>
  82578. * <div class='norender'><code>
  82579. * let xml;
  82580. *
  82581. * function preload() {
  82582. * xml = loadXML('assets/mammals.xml');
  82583. * }
  82584. *
  82585. * function setup() {
  82586. * xml.removeChild(1);
  82587. * let children = xml.getChildren();
  82588. * for (let i = 0; i < children.length; i++) {
  82589. * print(children[i].getContent());
  82590. * }
  82591. * }
  82592. *
  82593. * // Sketch prints:
  82594. * // "Goat"
  82595. * // "Zebra"
  82596. * </code></div>
  82597. */
  82598. _main.default.XML.prototype.removeChild = function(param) {
  82599. var ind = -1;
  82600. if (typeof param === 'string') {
  82601. for (var i = 0; i < this.DOM.children.length; i++) {
  82602. if (this.DOM.children[i].tagName === param) {
  82603. ind = i;
  82604. break;
  82605. }
  82606. }
  82607. } else {
  82608. ind = param;
  82609. }
  82610. if (ind !== -1) {
  82611. this.DOM.removeChild(this.DOM.children[ind]);
  82612. }
  82613. };
  82614. /**
  82615. * Counts the specified element's number of attributes, returned as an Number.
  82616. *
  82617. * @method getAttributeCount
  82618. * @return {Integer}
  82619. * @example
  82620. * <div class='norender'><code>
  82621. * // The following short XML file called "mammals.xml" is parsed
  82622. * // in the code below.
  82623. * //
  82624. * // <?xml version="1.0"?>
  82625. * // &lt;mammals&gt;
  82626. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82627. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82628. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82629. * // &lt;/mammals&gt;
  82630. *
  82631. * let xml;
  82632. *
  82633. * function preload() {
  82634. * xml = loadXML('assets/mammals.xml');
  82635. * }
  82636. *
  82637. * function setup() {
  82638. * let firstChild = xml.getChild('animal');
  82639. * print(firstChild.getAttributeCount());
  82640. * }
  82641. *
  82642. * // Sketch prints:
  82643. * // 2
  82644. * </code></div>
  82645. */
  82646. _main.default.XML.prototype.getAttributeCount = function() {
  82647. return this.DOM.attributes.length;
  82648. };
  82649. /**
  82650. * Gets all of the specified element's attributes, and returns them as an
  82651. * array of Strings.
  82652. *
  82653. * @method listAttributes
  82654. * @return {String[]} an array of strings containing the names of attributes
  82655. * @example
  82656. * <div class='norender'><code>
  82657. * // The following short XML file called "mammals.xml" is parsed
  82658. * // in the code below.
  82659. * //
  82660. * // <?xml version="1.0"?>
  82661. * // &lt;mammals&gt;
  82662. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82663. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82664. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82665. * // &lt;/mammals&gt;
  82666. *
  82667. * let xml;
  82668. *
  82669. * function preload() {
  82670. * xml = loadXML('assets/mammals.xml');
  82671. * }
  82672. *
  82673. * function setup() {
  82674. * let firstChild = xml.getChild('animal');
  82675. * print(firstChild.listAttributes());
  82676. * }
  82677. *
  82678. * // Sketch prints:
  82679. * // ["id", "species"]
  82680. * </code></div>
  82681. */
  82682. _main.default.XML.prototype.listAttributes = function() {
  82683. var arr = [];
  82684. var _iteratorNormalCompletion2 = true;
  82685. var _didIteratorError2 = false;
  82686. var _iteratorError2 = undefined;
  82687. try {
  82688. for (
  82689. var _iterator2 = this.DOM.attributes[Symbol.iterator](), _step2;
  82690. !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);
  82691. _iteratorNormalCompletion2 = true
  82692. ) {
  82693. var attribute = _step2.value;
  82694. arr.push(attribute.nodeName);
  82695. }
  82696. } catch (err) {
  82697. _didIteratorError2 = true;
  82698. _iteratorError2 = err;
  82699. } finally {
  82700. try {
  82701. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  82702. _iterator2.return();
  82703. }
  82704. } finally {
  82705. if (_didIteratorError2) {
  82706. throw _iteratorError2;
  82707. }
  82708. }
  82709. }
  82710. return arr;
  82711. };
  82712. /**
  82713. * Checks whether or not an element has the specified attribute.
  82714. *
  82715. * @method hasAttribute
  82716. * @param {String} the attribute to be checked
  82717. * @return {boolean} true if attribute found else false
  82718. * @example
  82719. * <div class='norender'><code>
  82720. * // The following short XML file called "mammals.xml" is parsed
  82721. * // in the code below.
  82722. * //
  82723. * // <?xml version="1.0"?>
  82724. * // &lt;mammals&gt;
  82725. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82726. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82727. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82728. * // &lt;/mammals&gt;
  82729. *
  82730. * let xml;
  82731. *
  82732. * function preload() {
  82733. * xml = loadXML('assets/mammals.xml');
  82734. * }
  82735. *
  82736. * function setup() {
  82737. * let firstChild = xml.getChild('animal');
  82738. * print(firstChild.hasAttribute('species'));
  82739. * print(firstChild.hasAttribute('color'));
  82740. * }
  82741. *
  82742. * // Sketch prints:
  82743. * // true
  82744. * // false
  82745. * </code></div>
  82746. */
  82747. _main.default.XML.prototype.hasAttribute = function(name) {
  82748. var obj = {};
  82749. var _iteratorNormalCompletion3 = true;
  82750. var _didIteratorError3 = false;
  82751. var _iteratorError3 = undefined;
  82752. try {
  82753. for (
  82754. var _iterator3 = this.DOM.attributes[Symbol.iterator](), _step3;
  82755. !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done);
  82756. _iteratorNormalCompletion3 = true
  82757. ) {
  82758. var attribute = _step3.value;
  82759. obj[attribute.nodeName] = attribute.nodeValue;
  82760. }
  82761. } catch (err) {
  82762. _didIteratorError3 = true;
  82763. _iteratorError3 = err;
  82764. } finally {
  82765. try {
  82766. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  82767. _iterator3.return();
  82768. }
  82769. } finally {
  82770. if (_didIteratorError3) {
  82771. throw _iteratorError3;
  82772. }
  82773. }
  82774. }
  82775. return obj[name] ? true : false;
  82776. };
  82777. /**
  82778. * Returns an attribute value of the element as an Number. If the defaultValue
  82779. * parameter is specified and the attribute doesn't exist, then defaultValue
  82780. * is returned. If no defaultValue is specified and the attribute doesn't
  82781. * exist, the value 0 is returned.
  82782. *
  82783. * @method getNum
  82784. * @param {String} name the non-null full name of the attribute
  82785. * @param {Number} [defaultValue] the default value of the attribute
  82786. * @return {Number}
  82787. * @example
  82788. * <div class='norender'><code>
  82789. * // The following short XML file called "mammals.xml" is parsed
  82790. * // in the code below.
  82791. * //
  82792. * // <?xml version="1.0"?>
  82793. * // &lt;mammals&gt;
  82794. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82795. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82796. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82797. * // &lt;/mammals&gt;
  82798. *
  82799. * let xml;
  82800. *
  82801. * function preload() {
  82802. * xml = loadXML('assets/mammals.xml');
  82803. * }
  82804. *
  82805. * function setup() {
  82806. * let firstChild = xml.getChild('animal');
  82807. * print(firstChild.getNum('id'));
  82808. * }
  82809. *
  82810. * // Sketch prints:
  82811. * // 0
  82812. * </code></div>
  82813. */
  82814. _main.default.XML.prototype.getNum = function(name, defaultValue) {
  82815. var obj = {};
  82816. var _iteratorNormalCompletion4 = true;
  82817. var _didIteratorError4 = false;
  82818. var _iteratorError4 = undefined;
  82819. try {
  82820. for (
  82821. var _iterator4 = this.DOM.attributes[Symbol.iterator](), _step4;
  82822. !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done);
  82823. _iteratorNormalCompletion4 = true
  82824. ) {
  82825. var attribute = _step4.value;
  82826. obj[attribute.nodeName] = attribute.nodeValue;
  82827. }
  82828. } catch (err) {
  82829. _didIteratorError4 = true;
  82830. _iteratorError4 = err;
  82831. } finally {
  82832. try {
  82833. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  82834. _iterator4.return();
  82835. }
  82836. } finally {
  82837. if (_didIteratorError4) {
  82838. throw _iteratorError4;
  82839. }
  82840. }
  82841. }
  82842. return Number(obj[name]) || defaultValue || 0;
  82843. };
  82844. /**
  82845. * Returns an attribute value of the element as an String. If the defaultValue
  82846. * parameter is specified and the attribute doesn't exist, then defaultValue
  82847. * is returned. If no defaultValue is specified and the attribute doesn't
  82848. * exist, null is returned.
  82849. *
  82850. * @method getString
  82851. * @param {String} name the non-null full name of the attribute
  82852. * @param {Number} [defaultValue] the default value of the attribute
  82853. * @return {String}
  82854. * @example
  82855. * <div class='norender'><code>
  82856. * // The following short XML file called "mammals.xml" is parsed
  82857. * // in the code below.
  82858. * //
  82859. * // <?xml version="1.0"?>
  82860. * // &lt;mammals&gt;
  82861. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82862. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82863. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82864. * // &lt;/mammals&gt;
  82865. *
  82866. * let xml;
  82867. *
  82868. * function preload() {
  82869. * xml = loadXML('assets/mammals.xml');
  82870. * }
  82871. *
  82872. * function setup() {
  82873. * let firstChild = xml.getChild('animal');
  82874. * print(firstChild.getString('species'));
  82875. * }
  82876. *
  82877. * // Sketch prints:
  82878. * // "Capra hircus"
  82879. * </code></div>
  82880. */
  82881. _main.default.XML.prototype.getString = function(name, defaultValue) {
  82882. var obj = {};
  82883. var _iteratorNormalCompletion5 = true;
  82884. var _didIteratorError5 = false;
  82885. var _iteratorError5 = undefined;
  82886. try {
  82887. for (
  82888. var _iterator5 = this.DOM.attributes[Symbol.iterator](), _step5;
  82889. !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done);
  82890. _iteratorNormalCompletion5 = true
  82891. ) {
  82892. var attribute = _step5.value;
  82893. obj[attribute.nodeName] = attribute.nodeValue;
  82894. }
  82895. } catch (err) {
  82896. _didIteratorError5 = true;
  82897. _iteratorError5 = err;
  82898. } finally {
  82899. try {
  82900. if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
  82901. _iterator5.return();
  82902. }
  82903. } finally {
  82904. if (_didIteratorError5) {
  82905. throw _iteratorError5;
  82906. }
  82907. }
  82908. }
  82909. return obj[name] ? String(obj[name]) : defaultValue || null;
  82910. };
  82911. /**
  82912. * Sets the content of an element's attribute. The first parameter specifies
  82913. * the attribute name, while the second specifies the new content.
  82914. *
  82915. * @method setAttribute
  82916. * @param {String} name the full name of the attribute
  82917. * @param {Number|String|Boolean} value the value of the attribute
  82918. * @example
  82919. * <div class='norender'><code>
  82920. * // The following short XML file called "mammals.xml" is parsed
  82921. * // in the code below.
  82922. * //
  82923. * // <?xml version="1.0"?>
  82924. * // &lt;mammals&gt;
  82925. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82926. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82927. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82928. * // &lt;/mammals&gt;
  82929. *
  82930. * let xml;
  82931. *
  82932. * function preload() {
  82933. * xml = loadXML('assets/mammals.xml');
  82934. * }
  82935. *
  82936. * function setup() {
  82937. * let firstChild = xml.getChild('animal');
  82938. * print(firstChild.getString('species'));
  82939. * firstChild.setAttribute('species', 'Jamides zebra');
  82940. * print(firstChild.getString('species'));
  82941. * }
  82942. *
  82943. * // Sketch prints:
  82944. * // "Capra hircus"
  82945. * // "Jamides zebra"
  82946. * </code></div>
  82947. */
  82948. _main.default.XML.prototype.setAttribute = function(name, value) {
  82949. this.DOM.setAttribute(name, value);
  82950. };
  82951. /**
  82952. * Returns the content of an element. If there is no such content,
  82953. * defaultValue is returned if specified, otherwise null is returned.
  82954. *
  82955. * @method getContent
  82956. * @param {String} [defaultValue] value returned if no content is found
  82957. * @return {String}
  82958. * @example
  82959. * <div class='norender'><code>
  82960. * // The following short XML file called "mammals.xml" is parsed
  82961. * // in the code below.
  82962. * //
  82963. * // <?xml version="1.0"?>
  82964. * // &lt;mammals&gt;
  82965. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  82966. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  82967. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  82968. * // &lt;/mammals&gt;
  82969. *
  82970. * let xml;
  82971. *
  82972. * function preload() {
  82973. * xml = loadXML('assets/mammals.xml');
  82974. * }
  82975. *
  82976. * function setup() {
  82977. * let firstChild = xml.getChild('animal');
  82978. * print(firstChild.getContent());
  82979. * }
  82980. *
  82981. * // Sketch prints:
  82982. * // "Goat"
  82983. * </code></div>
  82984. */
  82985. _main.default.XML.prototype.getContent = function(defaultValue) {
  82986. var str;
  82987. str = this.DOM.textContent;
  82988. str = str.replace(/\s\s+/g, ',');
  82989. return str || defaultValue || null;
  82990. };
  82991. /**
  82992. * Sets the element's content.
  82993. *
  82994. * @method setContent
  82995. * @param {String} text the new content
  82996. * @example
  82997. * <div class='norender'><code>
  82998. * // The following short XML file called "mammals.xml" is parsed
  82999. * // in the code below.
  83000. * //
  83001. * // <?xml version="1.0"?>
  83002. * // &lt;mammals&gt;
  83003. * // &lt;animal id="0" species="Capra hircus">Goat&lt;/animal&gt;
  83004. * // &lt;animal id="1" species="Panthera pardus">Leopard&lt;/animal&gt;
  83005. * // &lt;animal id="2" species="Equus zebra">Zebra&lt;/animal&gt;
  83006. * // &lt;/mammals&gt;
  83007. *
  83008. * let xml;
  83009. *
  83010. * function preload() {
  83011. * xml = loadXML('assets/mammals.xml');
  83012. * }
  83013. *
  83014. * function setup() {
  83015. * let firstChild = xml.getChild('animal');
  83016. * print(firstChild.getContent());
  83017. * firstChild.setContent('Mountain Goat');
  83018. * print(firstChild.getContent());
  83019. * }
  83020. *
  83021. * // Sketch prints:
  83022. * // "Goat"
  83023. * // "Mountain Goat"
  83024. * </code></div>
  83025. */
  83026. _main.default.XML.prototype.setContent = function(content) {
  83027. if (!this.DOM.children.length) {
  83028. this.DOM.textContent = content;
  83029. }
  83030. };
  83031. /**
  83032. * Serializes the element into a string. This function is useful for preparing
  83033. * the content to be sent over a http request or saved to file.
  83034. *
  83035. * @method serialize
  83036. * @return {String} Serialized string of the element
  83037. * @example
  83038. * <div class='norender'><code>
  83039. * let xml;
  83040. *
  83041. * function preload() {
  83042. * xml = loadXML('assets/mammals.xml');
  83043. * }
  83044. *
  83045. * function setup() {
  83046. * print(xml.serialize());
  83047. * }
  83048. *
  83049. * // Sketch prints:
  83050. * // <mammals>
  83051. * // <animal id="0" species="Capra hircus">Goat</animal>
  83052. * // <animal id="1" species="Panthera pardus">Leopard</animal>
  83053. * // <animal id="2" species="Equus zebra">Zebra</animal>
  83054. * // </mammals>
  83055. * </code></div>
  83056. */
  83057. _main.default.XML.prototype.serialize = function() {
  83058. var xmlSerializer = new XMLSerializer();
  83059. return xmlSerializer.serializeToString(this.DOM);
  83060. };
  83061. var _default = _main.default;
  83062. exports.default = _default;
  83063. },
  83064. {
  83065. '../core/main': 283,
  83066. 'core-js/modules/es.array.iterator': 174,
  83067. 'core-js/modules/es.number.constructor': 185,
  83068. 'core-js/modules/es.object.to-string': 192,
  83069. 'core-js/modules/es.regexp.exec': 196,
  83070. 'core-js/modules/es.string.iterator': 201,
  83071. 'core-js/modules/es.string.replace': 204,
  83072. 'core-js/modules/es.symbol': 211,
  83073. 'core-js/modules/es.symbol.description': 209,
  83074. 'core-js/modules/es.symbol.iterator': 210,
  83075. 'core-js/modules/web.dom-collections.iterator': 244
  83076. }
  83077. ],
  83078. 313: [
  83079. function(_dereq_, module, exports) {
  83080. 'use strict';
  83081. _dereq_('core-js/modules/es.array.includes');
  83082. _dereq_('core-js/modules/es.array.index-of');
  83083. _dereq_('core-js/modules/es.array.map');
  83084. _dereq_('core-js/modules/es.array.slice');
  83085. _dereq_('core-js/modules/es.math.hypot');
  83086. _dereq_('core-js/modules/es.number.constructor');
  83087. _dereq_('core-js/modules/es.string.includes');
  83088. Object.defineProperty(exports, '__esModule', { value: true });
  83089. exports.default = void 0;
  83090. var _main = _interopRequireDefault(_dereq_('../core/main'));
  83091. function _interopRequireDefault(obj) {
  83092. return obj && obj.__esModule ? obj : { default: obj };
  83093. }
  83094. /**
  83095. * @module Math
  83096. * @submodule Calculation
  83097. * @for p5
  83098. * @requires core
  83099. */ /**
  83100. * Calculates the absolute value (magnitude) of a number. Maps to Math.abs().
  83101. * The absolute value of a number is always positive.
  83102. *
  83103. * @method abs
  83104. * @param {Number} n number to compute
  83105. * @return {Number} absolute value of given number
  83106. * @example
  83107. * <div class = "norender"><code>
  83108. * function setup() {
  83109. * let x = -3;
  83110. * let y = abs(x);
  83111. *
  83112. * print(x); // -3
  83113. * print(y); // 3
  83114. * }
  83115. * </code></div>
  83116. *
  83117. * @alt
  83118. * no image displayed
  83119. */ _main.default.prototype.abs = Math.abs; /**
  83120. * Calculates the closest int value that is greater than or equal to the
  83121. * value of the parameter. Maps to Math.ceil(). For example, ceil(9.03)
  83122. * returns the value 10.
  83123. *
  83124. * @method ceil
  83125. * @param {Number} n number to round up
  83126. * @return {Integer} rounded up number
  83127. * @example
  83128. * <div><code>
  83129. * function draw() {
  83130. * background(200);
  83131. * // map, mouseX between 0 and 5.
  83132. * let ax = map(mouseX, 0, 100, 0, 5);
  83133. * let ay = 66;
  83134. *
  83135. * //Get the ceiling of the mapped number.
  83136. * let bx = ceil(map(mouseX, 0, 100, 0, 5));
  83137. * let by = 33;
  83138. *
  83139. * // Multiply the mapped numbers by 20 to more easily
  83140. * // see the changes.
  83141. * stroke(0);
  83142. * fill(0);
  83143. * line(0, ay, ax * 20, ay);
  83144. * line(0, by, bx * 20, by);
  83145. *
  83146. * // Reformat the float returned by map and draw it.
  83147. * noStroke();
  83148. * text(nfc(ax, 2), ax, ay - 5);
  83149. * text(nfc(bx, 1), bx, by - 5);
  83150. * }
  83151. * </code></div>
  83152. *
  83153. * @alt
  83154. * 2 horizontal lines & number sets. increase with mouse x. bottom to 2 decimals
  83155. */
  83156. _main.default.prototype.ceil = Math.ceil;
  83157. /**
  83158. * Constrains a value between a minimum and maximum value.
  83159. *
  83160. * @method constrain
  83161. * @param {Number} n number to constrain
  83162. * @param {Number} low minimum limit
  83163. * @param {Number} high maximum limit
  83164. * @return {Number} constrained number
  83165. * @example
  83166. * <div><code>
  83167. * function draw() {
  83168. * background(200);
  83169. *
  83170. * let leftWall = 25;
  83171. * let rightWall = 75;
  83172. *
  83173. * // xm is just the mouseX, while
  83174. * // xc is the mouseX, but constrained
  83175. * // between the leftWall and rightWall!
  83176. * let xm = mouseX;
  83177. * let xc = constrain(mouseX, leftWall, rightWall);
  83178. *
  83179. * // Draw the walls.
  83180. * stroke(150);
  83181. * line(leftWall, 0, leftWall, height);
  83182. * line(rightWall, 0, rightWall, height);
  83183. *
  83184. * // Draw xm and xc as circles.
  83185. * noStroke();
  83186. * fill(150);
  83187. * ellipse(xm, 33, 9, 9); // Not Constrained
  83188. * fill(0);
  83189. * ellipse(xc, 66, 9, 9); // Constrained
  83190. * }
  83191. * </code></div>
  83192. *
  83193. * @alt
  83194. * 2 vertical lines. 2 ellipses move with mouse X 1 does not move passed lines
  83195. */
  83196. _main.default.prototype.constrain = function(n, low, high) {
  83197. _main.default._validateParameters('constrain', arguments);
  83198. return Math.max(Math.min(n, high), low);
  83199. };
  83200. /**
  83201. * Calculates the distance between two points, in either two or three dimensions.
  83202. * If you looking for distance between two vectors see <a herf="#/p5.Vector/dist">dist()</a>
  83203. *
  83204. * @method dist
  83205. * @param {Number} x1 x-coordinate of the first point
  83206. * @param {Number} y1 y-coordinate of the first point
  83207. * @param {Number} x2 x-coordinate of the second point
  83208. * @param {Number} y2 y-coordinate of the second point
  83209. * @return {Number} distance between the two points
  83210. *
  83211. * @example
  83212. * <div><code>
  83213. * // Move your mouse inside the canvas to see the
  83214. * // change in distance between two points!
  83215. * function draw() {
  83216. * background(200);
  83217. * fill(0);
  83218. *
  83219. * let x1 = 10;
  83220. * let y1 = 90;
  83221. * let x2 = mouseX;
  83222. * let y2 = mouseY;
  83223. *
  83224. * line(x1, y1, x2, y2);
  83225. * ellipse(x1, y1, 7, 7);
  83226. * ellipse(x2, y2, 7, 7);
  83227. *
  83228. * // d is the length of the line
  83229. * // the distance from point 1 to point 2.
  83230. * let d = dist(x1, y1, x2, y2);
  83231. *
  83232. * // Let's write d along the line we are drawing!
  83233. * push();
  83234. * translate((x1 + x2) / 2, (y1 + y2) / 2);
  83235. * rotate(atan2(y2 - y1, x2 - x1));
  83236. * text(nfc(d, 1), 0, -5);
  83237. * pop();
  83238. * // Fancy!
  83239. * }
  83240. * </code></div>
  83241. *
  83242. * @alt
  83243. * 2 ellipses joined by line. 1 ellipse moves with mouse X&Y. Distance displayed.
  83244. */
  83245. /**
  83246. * @method dist
  83247. * @param {Number} x1
  83248. * @param {Number} y1
  83249. * @param {Number} z1 z-coordinate of the first point
  83250. * @param {Number} x2
  83251. * @param {Number} y2
  83252. * @param {Number} z2 z-coordinate of the second point
  83253. * @return {Number} distance between the two points
  83254. */
  83255. _main.default.prototype.dist = function() {
  83256. for (
  83257. var _len = arguments.length, args = new Array(_len), _key = 0;
  83258. _key < _len;
  83259. _key++
  83260. ) {
  83261. args[_key] = arguments[_key];
  83262. }
  83263. _main.default._validateParameters('dist', args);
  83264. if (args.length === 4) {
  83265. //2D
  83266. return hypot(args[2] - args[0], args[3] - args[1]);
  83267. } else if (args.length === 6) {
  83268. //3D
  83269. return hypot(args[3] - args[0], args[4] - args[1], args[5] - args[2]);
  83270. }
  83271. };
  83272. /**
  83273. * Returns Euler's number e (2.71828...) raised to the power of the n
  83274. * parameter. Maps to Math.exp().
  83275. *
  83276. * @method exp
  83277. * @param {Number} n exponent to raise
  83278. * @return {Number} e^n
  83279. * @example
  83280. * <div><code>
  83281. * function draw() {
  83282. * background(200);
  83283. *
  83284. * // Compute the exp() function with a value between 0 and 2
  83285. * let xValue = map(mouseX, 0, width, 0, 2);
  83286. * let yValue = exp(xValue);
  83287. *
  83288. * let y = map(yValue, 0, 8, height, 0);
  83289. *
  83290. * let legend = 'exp (' + nfc(xValue, 3) + ')\n= ' + nf(yValue, 1, 4);
  83291. * stroke(150);
  83292. * line(mouseX, y, mouseX, height);
  83293. * fill(0);
  83294. * text(legend, 5, 15);
  83295. * noStroke();
  83296. * ellipse(mouseX, y, 7, 7);
  83297. *
  83298. * // Draw the exp(x) curve,
  83299. * // over the domain of x from 0 to 2
  83300. * noFill();
  83301. * stroke(0);
  83302. * beginShape();
  83303. * for (let x = 0; x < width; x++) {
  83304. * xValue = map(x, 0, width, 0, 2);
  83305. * yValue = exp(xValue);
  83306. * y = map(yValue, 0, 8, height, 0);
  83307. * vertex(x, y);
  83308. * }
  83309. *
  83310. * endShape();
  83311. * line(0, 0, 0, height);
  83312. * line(0, height - 1, width, height - 1);
  83313. * }
  83314. * </code></div>
  83315. *
  83316. * @alt
  83317. * ellipse moves along a curve with mouse x. e^n displayed.
  83318. */
  83319. _main.default.prototype.exp = Math.exp;
  83320. /**
  83321. * Calculates the closest int value that is less than or equal to the
  83322. * value of the parameter. Maps to Math.floor().
  83323. *
  83324. * @method floor
  83325. * @param {Number} n number to round down
  83326. * @return {Integer} rounded down number
  83327. * @example
  83328. * <div><code>
  83329. * function draw() {
  83330. * background(200);
  83331. * //map, mouseX between 0 and 5.
  83332. * let ax = map(mouseX, 0, 100, 0, 5);
  83333. * let ay = 66;
  83334. *
  83335. * //Get the floor of the mapped number.
  83336. * let bx = floor(map(mouseX, 0, 100, 0, 5));
  83337. * let by = 33;
  83338. *
  83339. * // Multiply the mapped numbers by 20 to more easily
  83340. * // see the changes.
  83341. * stroke(0);
  83342. * fill(0);
  83343. * line(0, ay, ax * 20, ay);
  83344. * line(0, by, bx * 20, by);
  83345. *
  83346. * // Reformat the float returned by map and draw it.
  83347. * noStroke();
  83348. * text(nfc(ax, 2), ax, ay - 5);
  83349. * text(nfc(bx, 1), bx, by - 5);
  83350. * }
  83351. * </code></div>
  83352. *
  83353. * @alt
  83354. * 2 horizontal lines & number sets. increase with mouse x. bottom to 2 decimals
  83355. */
  83356. _main.default.prototype.floor = Math.floor;
  83357. /**
  83358. * Calculates a number between two numbers at a specific increment. The amt
  83359. * parameter is the amount to interpolate between the two values where 0.0
  83360. * equal to the first point, 0.1 is very near the first point, 0.5 is
  83361. * half-way in between, and 1.0 is equal to the second point. If the
  83362. * value of amt is more than 1.0 or less than 0.0, the number will be
  83363. * calculated accordingly in the ratio of the two given numbers. The lerp
  83364. * function is convenient for creating motion along a straight
  83365. * path and for drawing dotted lines.
  83366. *
  83367. * @method lerp
  83368. * @param {Number} start first value
  83369. * @param {Number} stop second value
  83370. * @param {Number} amt number
  83371. * @return {Number} lerped value
  83372. * @example
  83373. * <div><code>
  83374. * function setup() {
  83375. * background(200);
  83376. * let a = 20;
  83377. * let b = 80;
  83378. * let c = lerp(a, b, 0.2);
  83379. * let d = lerp(a, b, 0.5);
  83380. * let e = lerp(a, b, 0.8);
  83381. *
  83382. * let y = 50;
  83383. *
  83384. * strokeWeight(5);
  83385. * stroke(0); // Draw the original points in black
  83386. * point(a, y);
  83387. * point(b, y);
  83388. *
  83389. * stroke(100); // Draw the lerp points in gray
  83390. * point(c, y);
  83391. * point(d, y);
  83392. * point(e, y);
  83393. * }
  83394. * </code></div>
  83395. *
  83396. * @alt
  83397. * 5 points horizontally staggered mid-canvas. mid 3 are grey, outer black
  83398. */
  83399. _main.default.prototype.lerp = function(start, stop, amt) {
  83400. _main.default._validateParameters('lerp', arguments);
  83401. return amt * (stop - start) + start;
  83402. };
  83403. /**
  83404. * Calculates the natural logarithm (the base-e logarithm) of a number. This
  83405. * function expects the n parameter to be a value greater than 0.0. Maps to
  83406. * Math.log().
  83407. *
  83408. * @method log
  83409. * @param {Number} n number greater than 0
  83410. * @return {Number} natural logarithm of n
  83411. * @example
  83412. * <div><code>
  83413. * function draw() {
  83414. * background(200);
  83415. * let maxX = 2.8;
  83416. * let maxY = 1.5;
  83417. *
  83418. * // Compute the natural log of a value between 0 and maxX
  83419. * let xValue = map(mouseX, 0, width, 0, maxX);
  83420. * let yValue, y;
  83421. * if (xValue > 0) {
  83422. // Cannot take the log of a negative number.
  83423. * yValue = log(xValue);
  83424. * y = map(yValue, -maxY, maxY, height, 0);
  83425. *
  83426. * // Display the calculation occurring.
  83427. * let legend = 'log(' + nf(xValue, 1, 2) + ')\n= ' + nf(yValue, 1, 3);
  83428. * stroke(150);
  83429. * line(mouseX, y, mouseX, height);
  83430. * fill(0);
  83431. * text(legend, 5, 15);
  83432. * noStroke();
  83433. * ellipse(mouseX, y, 7, 7);
  83434. * }
  83435. *
  83436. * // Draw the log(x) curve,
  83437. * // over the domain of x from 0 to maxX
  83438. * noFill();
  83439. * stroke(0);
  83440. * beginShape();
  83441. * for (let x = 0; x < width; x++) {
  83442. * xValue = map(x, 0, width, 0, maxX);
  83443. * yValue = log(xValue);
  83444. * y = map(yValue, -maxY, maxY, height, 0);
  83445. * vertex(x, y);
  83446. * }
  83447. * endShape();
  83448. * line(0, 0, 0, height);
  83449. * line(0, height / 2, width, height / 2);
  83450. * }
  83451. * </code></div>
  83452. *
  83453. * @alt
  83454. * ellipse moves along a curve with mouse x. natural logarithm of n displayed.
  83455. */
  83456. _main.default.prototype.log = Math.log;
  83457. /**
  83458. * Calculates the magnitude (or length) of a vector. A vector is a direction
  83459. * in space commonly used in computer graphics and linear algebra. Because it
  83460. * has no "start" position, the magnitude of a vector can be thought of as
  83461. * the distance from the coordinate 0,0 to its x,y value. Therefore, <a href="#/p5/mag">mag()</a> is
  83462. * a shortcut for writing dist(0, 0, x, y).
  83463. *
  83464. * @method mag
  83465. * @param {Number} a first value
  83466. * @param {Number} b second value
  83467. * @return {Number} magnitude of vector from (0,0) to (a,b)
  83468. * @example
  83469. * <div><code>
  83470. * function setup() {
  83471. * let x1 = 20;
  83472. * let x2 = 80;
  83473. * let y1 = 30;
  83474. * let y2 = 70;
  83475. *
  83476. * line(0, 0, x1, y1);
  83477. * print(mag(x1, y1)); // Prints "36.05551275463989"
  83478. * line(0, 0, x2, y1);
  83479. * print(mag(x2, y1)); // Prints "85.44003745317531"
  83480. * line(0, 0, x1, y2);
  83481. * print(mag(x1, y2)); // Prints "72.80109889280519"
  83482. * line(0, 0, x2, y2);
  83483. * print(mag(x2, y2)); // Prints "106.3014581273465"
  83484. * }
  83485. * </code></div>
  83486. *
  83487. * @alt
  83488. * 4 lines of different length radiate from top left of canvas.
  83489. */
  83490. _main.default.prototype.mag = function(x, y) {
  83491. _main.default._validateParameters('mag', arguments);
  83492. return hypot(x, y);
  83493. };
  83494. /**
  83495. * Re-maps a number from one range to another.
  83496. *
  83497. * In the first example above, the number 25 is converted from a value in the
  83498. * range of 0 to 100 into a value that ranges from the left edge of the
  83499. * window (0) to the right edge (width).
  83500. *
  83501. * @method map
  83502. * @param {Number} value the incoming value to be converted
  83503. * @param {Number} start1 lower bound of the value's current range
  83504. * @param {Number} stop1 upper bound of the value's current range
  83505. * @param {Number} start2 lower bound of the value's target range
  83506. * @param {Number} stop2 upper bound of the value's target range
  83507. * @param {Boolean} [withinBounds] constrain the value to the newly mapped range
  83508. * @return {Number} remapped number
  83509. * @example
  83510. * <div><code>
  83511. * let value = 25;
  83512. * let m = map(value, 0, 100, 0, width);
  83513. * ellipse(m, 50, 10, 10);
  83514. </code></div>
  83515. *
  83516. * <div><code>
  83517. * function setup() {
  83518. * noStroke();
  83519. * }
  83520. *
  83521. * function draw() {
  83522. * background(204);
  83523. * let x1 = map(mouseX, 0, width, 25, 75);
  83524. * ellipse(x1, 25, 25, 25);
  83525. * //This ellipse is constrained to the 0-100 range
  83526. * //after setting withinBounds to true
  83527. * let x2 = map(mouseX, 0, width, 0, 100, true);
  83528. * ellipse(x2, 75, 25, 25);
  83529. * }
  83530. </code></div>
  83531. *
  83532. * @alt
  83533. * 10 by 10 white ellipse with in mid left canvas
  83534. * 2 25 by 25 white ellipses move with mouse x. Bottom has more range from X
  83535. */
  83536. _main.default.prototype.map = function(
  83537. n,
  83538. start1,
  83539. stop1,
  83540. start2,
  83541. stop2,
  83542. withinBounds
  83543. ) {
  83544. _main.default._validateParameters('map', arguments);
  83545. var newval = (n - start1) / (stop1 - start1) * (stop2 - start2) + start2;
  83546. if (!withinBounds) {
  83547. return newval;
  83548. }
  83549. if (start2 < stop2) {
  83550. return this.constrain(newval, start2, stop2);
  83551. } else {
  83552. return this.constrain(newval, stop2, start2);
  83553. }
  83554. };
  83555. /**
  83556. * Determines the largest value in a sequence of numbers, and then returns
  83557. * that value. <a href="#/p5/max">max()</a> accepts any number of Number parameters, or an Array
  83558. * of any length.
  83559. *
  83560. * @method max
  83561. * @param {Number} n0 Number to compare
  83562. * @param {Number} n1 Number to compare
  83563. * @return {Number} maximum Number
  83564. * @example
  83565. * <div><code>
  83566. * function setup() {
  83567. * // Change the elements in the array and run the sketch
  83568. * // to show how max() works!
  83569. * let numArray = [2, 1, 5, 4, 8, 9];
  83570. * fill(0);
  83571. * noStroke();
  83572. * text('Array Elements', 0, 10);
  83573. * // Draw all numbers in the array
  83574. * let spacing = 15;
  83575. * let elemsY = 25;
  83576. * for (let i = 0; i < numArray.length; i++) {
  83577. * text(numArray[i], i * spacing, elemsY);
  83578. * }
  83579. * let maxX = 33;
  83580. * let maxY = 80;
  83581. * // Draw the Maximum value in the array.
  83582. * textSize(32);
  83583. * text(max(numArray), maxX, maxY);
  83584. * }
  83585. * </code></div>
  83586. *
  83587. * @alt
  83588. * Small text at top reads: Array Elements 2 1 5 4 8 9. Large text at center: 9
  83589. */
  83590. /**
  83591. * @method max
  83592. * @param {Number[]} nums Numbers to compare
  83593. * @return {Number}
  83594. */
  83595. _main.default.prototype.max = function() {
  83596. for (
  83597. var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
  83598. _key2 < _len2;
  83599. _key2++
  83600. ) {
  83601. args[_key2] = arguments[_key2];
  83602. }
  83603. if (args[0] instanceof Array) {
  83604. return Math.max.apply(null, args[0]);
  83605. } else {
  83606. return Math.max.apply(null, args);
  83607. }
  83608. };
  83609. /**
  83610. * Determines the smallest value in a sequence of numbers, and then returns
  83611. * that value. <a href="#/p5/min">min()</a> accepts any number of Number parameters, or an Array
  83612. * of any length.
  83613. *
  83614. * @method min
  83615. * @param {Number} n0 Number to compare
  83616. * @param {Number} n1 Number to compare
  83617. * @return {Number} minimum Number
  83618. * @example
  83619. * <div><code>
  83620. * function setup() {
  83621. * // Change the elements in the array and run the sketch
  83622. * // to show how min() works!
  83623. * let numArray = [2, 1, 5, 4, 8, 9];
  83624. * fill(0);
  83625. * noStroke();
  83626. * text('Array Elements', 0, 10);
  83627. * // Draw all numbers in the array
  83628. * let spacing = 15;
  83629. * let elemsY = 25;
  83630. * for (let i = 0; i < numArray.length; i++) {
  83631. * text(numArray[i], i * spacing, elemsY);
  83632. * }
  83633. * let maxX = 33;
  83634. * let maxY = 80;
  83635. * // Draw the Minimum value in the array.
  83636. * textSize(32);
  83637. * text(min(numArray), maxX, maxY);
  83638. * }
  83639. * </code></div>
  83640. *
  83641. * @alt
  83642. * Small text at top reads: Array Elements 2 1 5 4 8 9. Large text at center: 1
  83643. */
  83644. /**
  83645. * @method min
  83646. * @param {Number[]} nums Numbers to compare
  83647. * @return {Number}
  83648. */
  83649. _main.default.prototype.min = function() {
  83650. for (
  83651. var _len3 = arguments.length, args = new Array(_len3), _key3 = 0;
  83652. _key3 < _len3;
  83653. _key3++
  83654. ) {
  83655. args[_key3] = arguments[_key3];
  83656. }
  83657. if (args[0] instanceof Array) {
  83658. return Math.min.apply(null, args[0]);
  83659. } else {
  83660. return Math.min.apply(null, args);
  83661. }
  83662. };
  83663. /**
  83664. * Normalizes a number from another range into a value between 0 and 1.
  83665. * Identical to map(value, low, high, 0, 1).
  83666. * Numbers outside of the range are not clamped to 0 and 1, because
  83667. * out-of-range values are often intentional and useful. (See the example above.)
  83668. *
  83669. * @method norm
  83670. * @param {Number} value incoming value to be normalized
  83671. * @param {Number} start lower bound of the value's current range
  83672. * @param {Number} stop upper bound of the value's current range
  83673. * @return {Number} normalized number
  83674. * @example
  83675. * <div><code>
  83676. * function draw() {
  83677. * background(200);
  83678. * let currentNum = mouseX;
  83679. * let lowerBound = 0;
  83680. * let upperBound = width; //100;
  83681. * let normalized = norm(currentNum, lowerBound, upperBound);
  83682. * let lineY = 70;
  83683. * stroke(3);
  83684. * line(0, lineY, width, lineY);
  83685. * //Draw an ellipse mapped to the non-normalized value.
  83686. * noStroke();
  83687. * fill(50);
  83688. * let s = 7; // ellipse size
  83689. * ellipse(currentNum, lineY, s, s);
  83690. *
  83691. * // Draw the guide
  83692. * let guideY = lineY + 15;
  83693. * text('0', 0, guideY);
  83694. * textAlign(RIGHT);
  83695. * text('100', width, guideY);
  83696. *
  83697. * // Draw the normalized value
  83698. * textAlign(LEFT);
  83699. * fill(0);
  83700. * textSize(32);
  83701. * let normalY = 40;
  83702. * let normalX = 20;
  83703. * text(normalized, normalX, normalY);
  83704. * }
  83705. * </code></div>
  83706. *
  83707. * @alt
  83708. * ellipse moves with mouse. 0 shown left & 100 right and updating values center
  83709. */
  83710. _main.default.prototype.norm = function(n, start, stop) {
  83711. _main.default._validateParameters('norm', arguments);
  83712. return this.map(n, start, stop, 0, 1);
  83713. };
  83714. /**
  83715. * Facilitates exponential expressions. The <a href="#/p5/pow">pow()</a> function is an efficient
  83716. * way of multiplying numbers by themselves (or their reciprocals) in large
  83717. * quantities. For example, pow(3, 5) is equivalent to the expression
  83718. * 3 &times; 3 &times; 3 &times; 3 &times; 3 and pow(3, -5) is equivalent to 1 /
  83719. * 3 &times; 3 &times; 3 &times; 3 &times; 3. Maps to
  83720. * Math.pow().
  83721. *
  83722. * @method pow
  83723. * @param {Number} n base of the exponential expression
  83724. * @param {Number} e power by which to raise the base
  83725. * @return {Number} n^e
  83726. * @example
  83727. * <div><code>
  83728. * function setup() {
  83729. * //Exponentially increase the size of an ellipse.
  83730. * let eSize = 3; // Original Size
  83731. * let eLoc = 10; // Original Location
  83732. *
  83733. * ellipse(eLoc, eLoc, eSize, eSize);
  83734. *
  83735. * ellipse(eLoc * 2, eLoc * 2, pow(eSize, 2), pow(eSize, 2));
  83736. *
  83737. * ellipse(eLoc * 4, eLoc * 4, pow(eSize, 3), pow(eSize, 3));
  83738. *
  83739. * ellipse(eLoc * 8, eLoc * 8, pow(eSize, 4), pow(eSize, 4));
  83740. * }
  83741. * </code></div>
  83742. *
  83743. * @alt
  83744. * small to large ellipses radiating from top left of canvas
  83745. */
  83746. _main.default.prototype.pow = Math.pow;
  83747. /**
  83748. * Calculates the integer closest to the n parameter. For example,
  83749. * round(133.8) returns the value 134. Maps to Math.round().
  83750. *
  83751. * @method round
  83752. * @param {Number} n number to round
  83753. * @param {Number} [decimals] number of decimal places to round to, default is 0
  83754. * @return {Integer} rounded number
  83755. * @example
  83756. * <div><code>
  83757. * let x = round(3.7);
  83758. * text(x, width / 2, height / 2);
  83759. * </code></div>
  83760. * <div><code>
  83761. * let x = round(12.782383, 2);
  83762. * text(x, width / 2, height / 2);
  83763. * </code></div>
  83764. * <div><code>
  83765. * function draw() {
  83766. * background(200);
  83767. * //map, mouseX between 0 and 5.
  83768. * let ax = map(mouseX, 0, 100, 0, 5);
  83769. * let ay = 66;
  83770. *
  83771. * // Round the mapped number.
  83772. * let bx = round(map(mouseX, 0, 100, 0, 5));
  83773. * let by = 33;
  83774. *
  83775. * // Multiply the mapped numbers by 20 to more easily
  83776. * // see the changes.
  83777. * stroke(0);
  83778. * fill(0);
  83779. * line(0, ay, ax * 20, ay);
  83780. * line(0, by, bx * 20, by);
  83781. *
  83782. * // Reformat the float returned by map and draw it.
  83783. * noStroke();
  83784. * text(nfc(ax, 2), ax, ay - 5);
  83785. * text(nfc(bx, 1), bx, by - 5);
  83786. * }
  83787. * </code></div>
  83788. *
  83789. * @alt
  83790. * "4" written in middle of canvas
  83791. * "12.78" written in middle of canvas
  83792. * two horizontal lines rounded values displayed on top.
  83793. */
  83794. _main.default.prototype.round = function(n, decimals) {
  83795. if (!decimals) {
  83796. return Math.round(n);
  83797. }
  83798. return Number(Math.round(n + 'e' + decimals) + 'e-' + decimals);
  83799. };
  83800. /**
  83801. * Squares a number (multiplies a number by itself). The result is always a
  83802. * positive number, as multiplying two negative numbers always yields a
  83803. * positive result. For example, -1 * -1 = 1.
  83804. *
  83805. * @method sq
  83806. * @param {Number} n number to square
  83807. * @return {Number} squared number
  83808. * @example
  83809. * <div><code>
  83810. * function draw() {
  83811. * background(200);
  83812. * let eSize = 7;
  83813. * let x1 = map(mouseX, 0, width, 0, 10);
  83814. * let y1 = 80;
  83815. * let x2 = sq(x1);
  83816. * let y2 = 20;
  83817. *
  83818. * // Draw the non-squared.
  83819. * line(0, y1, width, y1);
  83820. * ellipse(x1, y1, eSize, eSize);
  83821. *
  83822. * // Draw the squared.
  83823. * line(0, y2, width, y2);
  83824. * ellipse(x2, y2, eSize, eSize);
  83825. *
  83826. * // Draw dividing line.
  83827. * stroke(100);
  83828. * line(0, height / 2, width, height / 2);
  83829. *
  83830. * // Draw text.
  83831. * let spacing = 15;
  83832. * noStroke();
  83833. * fill(0);
  83834. * text('x = ' + x1, 0, y1 + spacing);
  83835. * text('sq(x) = ' + x2, 0, y2 + spacing);
  83836. * }
  83837. * </code></div>
  83838. *
  83839. * @alt
  83840. * horizontal center line squared values displayed on top and regular on bottom.
  83841. */
  83842. _main.default.prototype.sq = function(n) {
  83843. return n * n;
  83844. };
  83845. /**
  83846. * Calculates the square root of a number. The square root of a number is
  83847. * always positive, even though there may be a valid negative root. The
  83848. * square root s of number a is such that s*s = a. It is the opposite of
  83849. * squaring. Maps to Math.sqrt().
  83850. *
  83851. * @method sqrt
  83852. * @param {Number} n non-negative number to square root
  83853. * @return {Number} square root of number
  83854. * @example
  83855. * <div><code>
  83856. * function draw() {
  83857. * background(200);
  83858. * let eSize = 7;
  83859. * let x1 = mouseX;
  83860. * let y1 = 80;
  83861. * let x2 = sqrt(x1);
  83862. * let y2 = 20;
  83863. *
  83864. * // Draw the non-squared.
  83865. * line(0, y1, width, y1);
  83866. * ellipse(x1, y1, eSize, eSize);
  83867. *
  83868. * // Draw the squared.
  83869. * line(0, y2, width, y2);
  83870. * ellipse(x2, y2, eSize, eSize);
  83871. *
  83872. * // Draw dividing line.
  83873. * stroke(100);
  83874. * line(0, height / 2, width, height / 2);
  83875. *
  83876. * // Draw text.
  83877. * noStroke();
  83878. * fill(0);
  83879. * let spacing = 15;
  83880. * text('x = ' + x1, 0, y1 + spacing);
  83881. * text('sqrt(x) = ' + x2, 0, y2 + spacing);
  83882. * }
  83883. * </code></div>
  83884. *
  83885. * @alt
  83886. * horizontal center line squareroot values displayed on top and regular on bottom.
  83887. */
  83888. _main.default.prototype.sqrt = Math.sqrt;
  83889. // Calculate the length of the hypotenuse of a right triangle
  83890. // This won't under- or overflow in intermediate steps
  83891. // https://en.wikipedia.org/wiki/Hypot
  83892. function hypot(x, y, z) {
  83893. // Use the native implementation if it's available
  83894. if (typeof Math.hypot === 'function') {
  83895. return Math.hypot.apply(null, arguments);
  83896. }
  83897. // Otherwise use the V8 implementation
  83898. // https://github.com/v8/v8/blob/8cd3cf297287e581a49e487067f5cbd991b27123/src/js/math.js#L217
  83899. var length = arguments.length;
  83900. var args = [];
  83901. var max = 0;
  83902. for (var i = 0; i < length; i++) {
  83903. var n = arguments[i];
  83904. n = +n;
  83905. if (n === Infinity || n === -Infinity) {
  83906. return Infinity;
  83907. }
  83908. n = Math.abs(n);
  83909. if (n > max) {
  83910. max = n;
  83911. }
  83912. args[i] = n;
  83913. }
  83914. if (max === 0) {
  83915. max = 1;
  83916. }
  83917. var sum = 0;
  83918. var compensation = 0;
  83919. for (var j = 0; j < length; j++) {
  83920. var m = args[j] / max;
  83921. var summand = m * m - compensation;
  83922. var preliminary = sum + summand;
  83923. compensation = preliminary - sum - summand;
  83924. sum = preliminary;
  83925. }
  83926. return Math.sqrt(sum) * max;
  83927. }
  83928. /**
  83929. * Calculates the fractional part of a number.
  83930. *
  83931. * @method fract
  83932. * @param {Number} num Number whose fractional part needs to be found out
  83933. * @returns {Number} fractional part of x, i.e, {x}
  83934. * @example
  83935. * <div><code>
  83936. * text(7345.73472742, 10, 25);
  83937. * text(fract(7345.73472742), 10, 75);
  83938. * </code></div>
  83939. *
  83940. * <div><code>
  83941. * text(1.4215e-15, 10, 25);
  83942. * text(fract(1.4215e-15), 10, 75);
  83943. * </code></div>
  83944. *
  83945. * @alt
  83946. * first row having a number and the second having the fractional part of the number
  83947. * first row having a number expressed in scientific notation and the second having the fractional part of the number
  83948. */
  83949. _main.default.prototype.fract = function(toConvert) {
  83950. _main.default._validateParameters('fract', arguments);
  83951. var sign = 0;
  83952. var num = Number(toConvert);
  83953. if (isNaN(num) || Math.abs(num) === Infinity) {
  83954. return num;
  83955. } else if (num < 0) {
  83956. num = -num;
  83957. sign = 1;
  83958. }
  83959. if (String(num).includes('.') && !String(num).includes('e')) {
  83960. var toFract = String(num);
  83961. toFract = Number('0' + toFract.slice(toFract.indexOf('.')));
  83962. return Math.abs(sign - toFract);
  83963. } else if (num < 1) {
  83964. return Math.abs(sign - num);
  83965. } else {
  83966. return 0;
  83967. }
  83968. };
  83969. var _default = _main.default;
  83970. exports.default = _default;
  83971. },
  83972. {
  83973. '../core/main': 283,
  83974. 'core-js/modules/es.array.includes': 172,
  83975. 'core-js/modules/es.array.index-of': 173,
  83976. 'core-js/modules/es.array.map': 177,
  83977. 'core-js/modules/es.array.slice': 178,
  83978. 'core-js/modules/es.math.hypot': 183,
  83979. 'core-js/modules/es.number.constructor': 185,
  83980. 'core-js/modules/es.string.includes': 200
  83981. }
  83982. ],
  83983. 314: [
  83984. function(_dereq_, module, exports) {
  83985. 'use strict';
  83986. Object.defineProperty(exports, '__esModule', { value: true });
  83987. exports.default = void 0;
  83988. var _main = _interopRequireDefault(_dereq_('../core/main'));
  83989. function _interopRequireDefault(obj) {
  83990. return obj && obj.__esModule ? obj : { default: obj };
  83991. }
  83992. /**
  83993. * @module Math
  83994. * @submodule Vector
  83995. * @for p5
  83996. * @requires core
  83997. */ /**
  83998. * Creates a new <a href="#/p5.Vector">p5.Vector</a> (the datatype for storing vectors). This provides a
  83999. * two or three dimensional vector, specifically a Euclidean (also known as
  84000. * geometric) vector. A vector is an entity that has both magnitude and
  84001. * direction.
  84002. *
  84003. * @method createVector
  84004. * @param {Number} [x] x component of the vector
  84005. * @param {Number} [y] y component of the vector
  84006. * @param {Number} [z] z component of the vector
  84007. * @return {p5.Vector}
  84008. * @example
  84009. * <div><code>
  84010. * let v1;
  84011. * function setup() {
  84012. * createCanvas(100, 100);
  84013. * stroke(255, 0, 255);
  84014. * v1 = createVector(width / 2, height / 2);
  84015. * }
  84016. *
  84017. * function draw() {
  84018. * background(255);
  84019. * line(v1.x, v1.y, mouseX, mouseY);
  84020. * }
  84021. * </code></div>
  84022. *
  84023. * @alt
  84024. * draws a line from center of canvas to mouse pointer position.
  84025. */ _main.default.prototype.createVector = function(x, y, z) {
  84026. if (this instanceof _main.default) {
  84027. return new _main.default.Vector(this, arguments);
  84028. } else {
  84029. return new _main.default.Vector(x, y, z);
  84030. }
  84031. };
  84032. var _default = _main.default;
  84033. exports.default = _default;
  84034. },
  84035. { '../core/main': 283 }
  84036. ],
  84037. 315: [
  84038. function(_dereq_, module, exports) {
  84039. 'use strict';
  84040. Object.defineProperty(exports, '__esModule', { value: true });
  84041. exports.default = void 0;
  84042. var _main = _interopRequireDefault(_dereq_('../core/main'));
  84043. function _interopRequireDefault(obj) {
  84044. return obj && obj.__esModule ? obj : { default: obj };
  84045. } //////////////////////////////////////////////////////////////
  84046. // http://mrl.nyu.edu/~perlin/noise/
  84047. // Adapting from PApplet.java
  84048. // which was adapted from toxi
  84049. // which was adapted from the german demo group farbrausch
  84050. // as used in their demo "art": http://www.farb-rausch.de/fr010src.zip
  84051. // someday we might consider using "improved noise"
  84052. // http://mrl.nyu.edu/~perlin/paper445.pdf
  84053. // See: https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js/
  84054. // blob/main/introduction/Noise1D/noise.js
  84055. /**
  84056. * @module Math
  84057. * @submodule Noise
  84058. * @for p5
  84059. * @requires core
  84060. */ var PERLIN_YWRAPB = 4;
  84061. var PERLIN_YWRAP = 1 << PERLIN_YWRAPB;
  84062. var PERLIN_ZWRAPB = 8;
  84063. var PERLIN_ZWRAP = 1 << PERLIN_ZWRAPB;
  84064. var PERLIN_SIZE = 4095;
  84065. var perlin_octaves = 4; // default to medium smooth
  84066. var perlin_amp_falloff = 0.5; // 50% reduction/octave
  84067. var scaled_cosine = function scaled_cosine(i) {
  84068. return 0.5 * (1.0 - Math.cos(i * Math.PI));
  84069. };
  84070. var perlin; // will be initialized lazily by noise() or noiseSeed()
  84071. /**
  84072. * Returns the Perlin noise value at specified coordinates. Perlin noise is
  84073. * a random sequence generator producing a more naturally ordered, harmonic
  84074. * succession of numbers compared to the standard <b>random()</b> function.
  84075. * It was invented by Ken Perlin in the 1980s and been used since in
  84076. * graphical applications to produce procedural textures, natural motion,
  84077. * shapes, terrains etc.<br /><br /> The main difference to the
  84078. * <b>random()</b> function is that Perlin noise is defined in an infinite
  84079. * n-dimensional space where each pair of coordinates corresponds to a
  84080. * fixed semi-random value (fixed only for the lifespan of the program; see
  84081. * the <a href="#/p5/noiseSeed">noiseSeed()</a> function). p5.js can compute 1D, 2D and 3D noise,
  84082. * depending on the number of coordinates given. The resulting value will
  84083. * always be between 0.0 and 1.0. The noise value can be animated by moving
  84084. * through the noise space as demonstrated in the example above. The 2nd
  84085. * and 3rd dimension can also be interpreted as time.<br /><br />The actual
  84086. * noise is structured similar to an audio signal, in respect to the
  84087. * function's use of frequencies. Similar to the concept of harmonics in
  84088. * physics, perlin noise is computed over several octaves which are added
  84089. * together for the final result. <br /><br />Another way to adjust the
  84090. * character of the resulting sequence is the scale of the input
  84091. * coordinates. As the function works within an infinite space the value of
  84092. * the coordinates doesn't matter as such, only the distance between
  84093. * successive coordinates does (eg. when using <b>noise()</b> within a
  84094. * loop). As a general rule the smaller the difference between coordinates,
  84095. * the smoother the resulting noise sequence will be. Steps of 0.005-0.03
  84096. * work best for most applications, but this will differ depending on use.
  84097. *
  84098. * @method noise
  84099. * @param {Number} x x-coordinate in noise space
  84100. * @param {Number} [y] y-coordinate in noise space
  84101. * @param {Number} [z] z-coordinate in noise space
  84102. * @return {Number} Perlin noise value (between 0 and 1) at specified
  84103. * coordinates
  84104. * @example
  84105. * <div>
  84106. * <code>
  84107. * let xoff = 0.0;
  84108. *
  84109. * function draw() {
  84110. * background(204);
  84111. * xoff = xoff + 0.01;
  84112. * let n = noise(xoff) * width;
  84113. * line(n, 0, n, height);
  84114. * }
  84115. * </code>
  84116. * </div>
  84117. * <div>
  84118. * <code>let noiseScale=0.02;
  84119. *
  84120. * function draw() {
  84121. * background(0);
  84122. * for (let x=0; x < width; x++) {
  84123. * let noiseVal = noise((mouseX+x)*noiseScale, mouseY*noiseScale);
  84124. * stroke(noiseVal*255);
  84125. * line(x, mouseY+noiseVal*80, x, height);
  84126. * }
  84127. * }
  84128. * </code>
  84129. * </div>
  84130. *
  84131. * @alt
  84132. * vertical line moves left to right with updating noise values.
  84133. * horizontal wave pattern effected by mouse x-position & updating noise values.
  84134. */ _main.default.prototype.noise = function(x) {
  84135. var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  84136. var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  84137. if (perlin == null) {
  84138. perlin = new Array(PERLIN_SIZE + 1);
  84139. for (var i = 0; i < PERLIN_SIZE + 1; i++) {
  84140. perlin[i] = Math.random();
  84141. }
  84142. }
  84143. if (x < 0) {
  84144. x = -x;
  84145. }
  84146. if (y < 0) {
  84147. y = -y;
  84148. }
  84149. if (z < 0) {
  84150. z = -z;
  84151. }
  84152. var xi = Math.floor(x),
  84153. yi = Math.floor(y),
  84154. zi = Math.floor(z);
  84155. var xf = x - xi;
  84156. var yf = y - yi;
  84157. var zf = z - zi;
  84158. var rxf, ryf;
  84159. var r = 0;
  84160. var ampl = 0.5;
  84161. var n1, n2, n3;
  84162. for (var o = 0; o < perlin_octaves; o++) {
  84163. var of = xi + (yi << PERLIN_YWRAPB) + (zi << PERLIN_ZWRAPB);
  84164. rxf = scaled_cosine(xf);
  84165. ryf = scaled_cosine(yf);
  84166. n1 = perlin[of & PERLIN_SIZE];
  84167. n1 += rxf * (perlin[(of + 1) & PERLIN_SIZE] - n1);
  84168. n2 = perlin[(of + PERLIN_YWRAP) & PERLIN_SIZE];
  84169. n2 += rxf * (perlin[(of + PERLIN_YWRAP + 1) & PERLIN_SIZE] - n2);
  84170. n1 += ryf * (n2 - n1);
  84171. of += PERLIN_ZWRAP;
  84172. n2 = perlin[of & PERLIN_SIZE];
  84173. n2 += rxf * (perlin[(of + 1) & PERLIN_SIZE] - n2);
  84174. n3 = perlin[(of + PERLIN_YWRAP) & PERLIN_SIZE];
  84175. n3 += rxf * (perlin[(of + PERLIN_YWRAP + 1) & PERLIN_SIZE] - n3);
  84176. n2 += ryf * (n3 - n2);
  84177. n1 += scaled_cosine(zf) * (n2 - n1);
  84178. r += n1 * ampl;
  84179. ampl *= perlin_amp_falloff;
  84180. xi <<= 1;
  84181. xf *= 2;
  84182. yi <<= 1;
  84183. yf *= 2;
  84184. zi <<= 1;
  84185. zf *= 2;
  84186. if (xf >= 1.0) {
  84187. xi++;
  84188. xf--;
  84189. }
  84190. if (yf >= 1.0) {
  84191. yi++;
  84192. yf--;
  84193. }
  84194. if (zf >= 1.0) {
  84195. zi++;
  84196. zf--;
  84197. }
  84198. }
  84199. return r;
  84200. };
  84201. /**
  84202. *
  84203. * Adjusts the character and level of detail produced by the Perlin noise
  84204. * function. Similar to harmonics in physics, noise is computed over
  84205. * several octaves. Lower octaves contribute more to the output signal and
  84206. * as such define the overall intensity of the noise, whereas higher octaves
  84207. * create finer grained details in the noise sequence.
  84208. *
  84209. * By default, noise is computed over 4 octaves with each octave contributing
  84210. * exactly half than its predecessor, starting at 50% strength for the 1st
  84211. * octave. This falloff amount can be changed by adding an additional function
  84212. * parameter. Eg. a falloff factor of 0.75 means each octave will now have
  84213. * 75% impact (25% less) of the previous lower octave. Any value between
  84214. * 0.0 and 1.0 is valid, however note that values greater than 0.5 might
  84215. * result in greater than 1.0 values returned by <b>noise()</b>.
  84216. *
  84217. * By changing these parameters, the signal created by the <b>noise()</b>
  84218. * function can be adapted to fit very specific needs and characteristics.
  84219. *
  84220. * @method noiseDetail
  84221. * @param {Number} lod number of octaves to be used by the noise
  84222. * @param {Number} falloff falloff factor for each octave
  84223. * @example
  84224. * <div>
  84225. * <code>
  84226. * let noiseVal;
  84227. * let noiseScale = 0.02;
  84228. *
  84229. * function setup() {
  84230. * createCanvas(100, 100);
  84231. * }
  84232. *
  84233. * function draw() {
  84234. * background(0);
  84235. * for (let y = 0; y < height; y++) {
  84236. * for (let x = 0; x < width / 2; x++) {
  84237. * noiseDetail(2, 0.2);
  84238. * noiseVal = noise((mouseX + x) * noiseScale, (mouseY + y) * noiseScale);
  84239. * stroke(noiseVal * 255);
  84240. * point(x, y);
  84241. * noiseDetail(8, 0.65);
  84242. * noiseVal = noise(
  84243. * (mouseX + x + width / 2) * noiseScale,
  84244. * (mouseY + y) * noiseScale
  84245. * );
  84246. * stroke(noiseVal * 255);
  84247. * point(x + width / 2, y);
  84248. * }
  84249. * }
  84250. * }
  84251. * </code>
  84252. * </div>
  84253. *
  84254. * @alt
  84255. * 2 vertical grey smokey patterns affected my mouse x-position and noise.
  84256. */
  84257. _main.default.prototype.noiseDetail = function(lod, falloff) {
  84258. if (lod > 0) {
  84259. perlin_octaves = lod;
  84260. }
  84261. if (falloff > 0) {
  84262. perlin_amp_falloff = falloff;
  84263. }
  84264. };
  84265. /**
  84266. * Sets the seed value for <b>noise()</b>. By default, <b>noise()</b>
  84267. * produces different results each time the program is run. Set the
  84268. * <b>value</b> parameter to a constant to return the same pseudo-random
  84269. * numbers each time the software is run.
  84270. *
  84271. * @method noiseSeed
  84272. * @param {Number} seed the seed value
  84273. * @example
  84274. * <div>
  84275. * <code>let xoff = 0.0;
  84276. *
  84277. * function setup() {
  84278. * noiseSeed(99);
  84279. * stroke(0, 10);
  84280. * }
  84281. *
  84282. * function draw() {
  84283. * xoff = xoff + .01;
  84284. * let n = noise(xoff) * width;
  84285. * line(n, 0, n, height);
  84286. * }
  84287. * </code>
  84288. * </div>
  84289. *
  84290. * @alt
  84291. * vertical grey lines drawing in pattern affected by noise.
  84292. */
  84293. _main.default.prototype.noiseSeed = function(seed) {
  84294. // Linear Congruential Generator
  84295. // Variant of a Lehman Generator
  84296. var lcg = (function() {
  84297. // Set to values from http://en.wikipedia.org/wiki/Numerical_Recipes
  84298. // m is basically chosen to be large (as it is the max period)
  84299. // and for its relationships to a and c
  84300. var m = 4294967296;
  84301. // a - 1 should be divisible by m's prime factors
  84302. var a = 1664525;
  84303. // c and m should be co-prime
  84304. var c = 1013904223;
  84305. var seed, z;
  84306. return {
  84307. setSeed: function setSeed(val) {
  84308. // pick a random seed if val is undefined or null
  84309. // the >>> 0 casts the seed to an unsigned 32-bit integer
  84310. z = seed = (val == null ? Math.random() * m : val) >>> 0;
  84311. },
  84312. getSeed: function getSeed() {
  84313. return seed;
  84314. },
  84315. rand: function rand() {
  84316. // define the recurrence relationship
  84317. z = (a * z + c) % m;
  84318. // return a float in [0, 1)
  84319. // if z = m then z / m = 0 therefore (z % m) / m < 1 always
  84320. return z / m;
  84321. }
  84322. };
  84323. })();
  84324. lcg.setSeed(seed);
  84325. perlin = new Array(PERLIN_SIZE + 1);
  84326. for (var i = 0; i < PERLIN_SIZE + 1; i++) {
  84327. perlin[i] = lcg.rand();
  84328. }
  84329. };
  84330. var _default = _main.default;
  84331. exports.default = _default;
  84332. },
  84333. { '../core/main': 283 }
  84334. ],
  84335. 316: [
  84336. function(_dereq_, module, exports) {
  84337. 'use strict';
  84338. function _typeof(obj) {
  84339. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  84340. _typeof = function _typeof(obj) {
  84341. return typeof obj;
  84342. };
  84343. } else {
  84344. _typeof = function _typeof(obj) {
  84345. return obj &&
  84346. typeof Symbol === 'function' &&
  84347. obj.constructor === Symbol &&
  84348. obj !== Symbol.prototype
  84349. ? 'symbol'
  84350. : typeof obj;
  84351. };
  84352. }
  84353. return _typeof(obj);
  84354. }
  84355. _dereq_('core-js/modules/es.array.concat');
  84356. _dereq_('core-js/modules/es.array.every');
  84357. _dereq_('core-js/modules/es.array.slice');
  84358. _dereq_('core-js/modules/es.array.some');
  84359. _dereq_('core-js/modules/es.math.sign');
  84360. _dereq_('core-js/modules/es.number.constructor');
  84361. _dereq_('core-js/modules/es.number.is-finite');
  84362. _dereq_('core-js/modules/es.object.to-string');
  84363. _dereq_('core-js/modules/es.regexp.to-string');
  84364. _dereq_('core-js/modules/es.string.sub');
  84365. Object.defineProperty(exports, '__esModule', { value: true });
  84366. exports.default = void 0;
  84367. var _main = _interopRequireDefault(_dereq_('../core/main'));
  84368. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  84369. function _getRequireWildcardCache() {
  84370. if (typeof WeakMap !== 'function') return null;
  84371. var cache = new WeakMap();
  84372. _getRequireWildcardCache = function _getRequireWildcardCache() {
  84373. return cache;
  84374. };
  84375. return cache;
  84376. }
  84377. function _interopRequireWildcard(obj) {
  84378. if (obj && obj.__esModule) {
  84379. return obj;
  84380. }
  84381. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  84382. return { default: obj };
  84383. }
  84384. var cache = _getRequireWildcardCache();
  84385. if (cache && cache.has(obj)) {
  84386. return cache.get(obj);
  84387. }
  84388. var newObj = {};
  84389. var hasPropertyDescriptor =
  84390. Object.defineProperty && Object.getOwnPropertyDescriptor;
  84391. for (var key in obj) {
  84392. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  84393. var desc = hasPropertyDescriptor
  84394. ? Object.getOwnPropertyDescriptor(obj, key)
  84395. : null;
  84396. if (desc && (desc.get || desc.set)) {
  84397. Object.defineProperty(newObj, key, desc);
  84398. } else {
  84399. newObj[key] = obj[key];
  84400. }
  84401. }
  84402. }
  84403. newObj.default = obj;
  84404. if (cache) {
  84405. cache.set(obj, newObj);
  84406. }
  84407. return newObj;
  84408. }
  84409. function _interopRequireDefault(obj) {
  84410. return obj && obj.__esModule ? obj : { default: obj };
  84411. }
  84412. /**
  84413. * @module Math
  84414. * @submodule Vector
  84415. * @requires constants
  84416. */ /**
  84417. * A class to describe a two or three dimensional vector, specifically
  84418. * a Euclidean (also known as geometric) vector. A vector is an entity
  84419. * that has both magnitude and direction. The datatype, however, stores
  84420. * the components of the vector (x, y for 2D, and x, y, z for 3D). The magnitude
  84421. * and direction can be accessed via the methods <a href="#/p5.Vector/mag">mag()</a> and <a href="#/p5.Vector/heading">heading()</a>.
  84422. *
  84423. * In many of the p5.js examples, you will see <a href="#/p5.Vector">p5.Vector</a> used to describe a
  84424. * position, velocity, or acceleration. For example, if you consider a rectangle
  84425. * moving across the screen, at any given instant it has a position (a vector
  84426. * that points from the origin to its location), a velocity (the rate at which
  84427. * the object's position changes per time unit, expressed as a vector), and
  84428. * acceleration (the rate at which the object's velocity changes per time
  84429. * unit, expressed as a vector).
  84430. *
  84431. * Since vectors represent groupings of values, we cannot simply use
  84432. * traditional addition/multiplication/etc. Instead, we'll need to do some
  84433. * "vector" math, which is made easy by the methods inside the <a href="#/p5.Vector">p5.Vector</a> class.
  84434. *
  84435. * @class p5.Vector
  84436. * @constructor
  84437. * @param {Number} [x] x component of the vector
  84438. * @param {Number} [y] y component of the vector
  84439. * @param {Number} [z] z component of the vector
  84440. * @example
  84441. * <div>
  84442. * <code>
  84443. * let v1 = createVector(40, 50);
  84444. * let v2 = createVector(40, 50);
  84445. *
  84446. * ellipse(v1.x, v1.y, 50, 50);
  84447. * ellipse(v2.x, v2.y, 50, 50);
  84448. * v1.add(v2);
  84449. * ellipse(v1.x, v1.y, 50, 50);
  84450. * </code>
  84451. * </div>
  84452. *
  84453. * @alt
  84454. * 2 white ellipses. One center-left the other bottom right and off canvas
  84455. */ _main.default.Vector = function Vector() {
  84456. var x, y, z;
  84457. // This is how it comes in with createVector()
  84458. if (arguments[0] instanceof _main.default) {
  84459. // save reference to p5 if passed in
  84460. this.p5 = arguments[0];
  84461. x = arguments[1][0] || 0;
  84462. y = arguments[1][1] || 0;
  84463. z = arguments[1][2] || 0;
  84464. // This is what we'll get with new p5.Vector()
  84465. } else {
  84466. x = arguments[0] || 0;
  84467. y = arguments[1] || 0;
  84468. z = arguments[2] || 0;
  84469. }
  84470. /**
  84471. * The x component of the vector
  84472. * @property x {Number}
  84473. */
  84474. this.x = x;
  84475. /**
  84476. * The y component of the vector
  84477. * @property y {Number}
  84478. */
  84479. this.y = y;
  84480. /**
  84481. * The z component of the vector
  84482. * @property z {Number}
  84483. */
  84484. this.z = z;
  84485. };
  84486. /**
  84487. * Returns a string representation of a vector v by calling String(v)
  84488. * or v.toString(). This method is useful for logging vectors in the
  84489. * console.
  84490. * @method toString
  84491. * @return {String}
  84492. * @example
  84493. * <div class = "norender">
  84494. * <code>
  84495. * function setup() {
  84496. * let v = createVector(20, 30);
  84497. * print(String(v)); // prints "p5.Vector Object : [20, 30, 0]"
  84498. * }
  84499. * </code>
  84500. * </div>
  84501. *
  84502. * <div>
  84503. * <code>
  84504. * function draw() {
  84505. * background(240);
  84506. *
  84507. * let v0 = createVector(0, 0);
  84508. * let v1 = createVector(mouseX, mouseY);
  84509. * drawArrow(v0, v1, 'black');
  84510. *
  84511. * noStroke();
  84512. * text(v1.toString(), 10, 25, 90, 75);
  84513. * }
  84514. *
  84515. * // draw an arrow for a vector at a given base position
  84516. * function drawArrow(base, vec, myColor) {
  84517. * push();
  84518. * stroke(myColor);
  84519. * strokeWeight(3);
  84520. * fill(myColor);
  84521. * translate(base.x, base.y);
  84522. * line(0, 0, vec.x, vec.y);
  84523. * rotate(vec.heading());
  84524. * let arrowSize = 7;
  84525. * translate(vec.mag() - arrowSize, 0);
  84526. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  84527. * pop();
  84528. * }
  84529. * </code>
  84530. * </div>
  84531. */
  84532. _main.default.Vector.prototype.toString = function p5VectorToString() {
  84533. return 'p5.Vector Object : ['
  84534. .concat(this.x, ', ')
  84535. .concat(this.y, ', ')
  84536. .concat(this.z, ']');
  84537. };
  84538. /**
  84539. * Sets the x, y, and z component of the vector using two or three separate
  84540. * variables, the data from a <a href="#/p5.Vector">p5.Vector</a>, or the values from a float array.
  84541. * @method set
  84542. * @param {Number} [x] the x component of the vector
  84543. * @param {Number} [y] the y component of the vector
  84544. * @param {Number} [z] the z component of the vector
  84545. * @chainable
  84546. * @example
  84547. * <div class="norender">
  84548. * <code>
  84549. * function setup() {
  84550. * let v = createVector(1, 2, 3);
  84551. * v.set(4, 5, 6); // Sets vector to [4, 5, 6]
  84552. *
  84553. * let v1 = createVector(0, 0, 0);
  84554. * let arr = [1, 2, 3];
  84555. * v1.set(arr); // Sets vector to [1, 2, 3]
  84556. * }
  84557. * </code>
  84558. * </div>
  84559. *
  84560. * <div>
  84561. * <code>
  84562. * let v0, v1;
  84563. * function setup() {
  84564. * createCanvas(100, 100);
  84565. *
  84566. * v0 = createVector(0, 0);
  84567. * v1 = createVector(50, 50);
  84568. * }
  84569. *
  84570. * function draw() {
  84571. * background(240);
  84572. *
  84573. * drawArrow(v0, v1, 'black');
  84574. * v1.set(v1.x + random(-1, 1), v1.y + random(-1, 1));
  84575. *
  84576. * noStroke();
  84577. * text('x: ' + round(v1.x) + ' y: ' + round(v1.y), 20, 90);
  84578. * }
  84579. *
  84580. * // draw an arrow for a vector at a given base position
  84581. * function drawArrow(base, vec, myColor) {
  84582. * push();
  84583. * stroke(myColor);
  84584. * strokeWeight(3);
  84585. * fill(myColor);
  84586. * translate(base.x, base.y);
  84587. * line(0, 0, vec.x, vec.y);
  84588. * rotate(vec.heading());
  84589. * let arrowSize = 7;
  84590. * translate(vec.mag() - arrowSize, 0);
  84591. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  84592. * pop();
  84593. * }
  84594. * </code>
  84595. * </div>
  84596. */
  84597. /**
  84598. * @method set
  84599. * @param {p5.Vector|Number[]} value the vector to set
  84600. * @chainable
  84601. */
  84602. _main.default.Vector.prototype.set = function set(x, y, z) {
  84603. if (x instanceof _main.default.Vector) {
  84604. this.x = x.x || 0;
  84605. this.y = x.y || 0;
  84606. this.z = x.z || 0;
  84607. return this;
  84608. }
  84609. if (x instanceof Array) {
  84610. this.x = x[0] || 0;
  84611. this.y = x[1] || 0;
  84612. this.z = x[2] || 0;
  84613. return this;
  84614. }
  84615. this.x = x || 0;
  84616. this.y = y || 0;
  84617. this.z = z || 0;
  84618. return this;
  84619. };
  84620. /**
  84621. * Gets a copy of the vector, returns a <a href="#/p5.Vector">p5.Vector</a> object.
  84622. *
  84623. * @method copy
  84624. * @return {p5.Vector} the copy of the <a href="#/p5.Vector">p5.Vector</a> object
  84625. * @example
  84626. * <div class="norender">
  84627. * <code>
  84628. * let v1 = createVector(1, 2, 3);
  84629. * let v2 = v1.copy();
  84630. * print(v1.x === v2.x && v1.y === v2.y && v1.z === v2.z);
  84631. * // Prints "true"
  84632. * </code>
  84633. * </div>
  84634. */
  84635. _main.default.Vector.prototype.copy = function copy() {
  84636. if (this.p5) {
  84637. return new _main.default.Vector(this.p5, [this.x, this.y, this.z]);
  84638. } else {
  84639. return new _main.default.Vector(this.x, this.y, this.z);
  84640. }
  84641. };
  84642. /**
  84643. * Adds x, y, and z components to a vector, adds one vector to another, or
  84644. * adds two independent vectors together. The version of the method that adds
  84645. * two vectors together is a static method and returns a <a href="#/p5.Vector">p5.Vector</a>, the others
  84646. * acts directly on the vector. Additionally, you may provide arguments to this function as an array.
  84647. * See the examples for more context.
  84648. *
  84649. * @method add
  84650. * @param {Number} x the x component of the vector to be added
  84651. * @param {Number} [y] the y component of the vector to be added
  84652. * @param {Number} [z] the z component of the vector to be added
  84653. * @chainable
  84654. * @example
  84655. * <div class="norender">
  84656. * <code>
  84657. * let v = createVector(1, 2, 3);
  84658. * v.add(4, 5, 6);
  84659. * // v's components are set to [5, 7, 9]
  84660. * </code>
  84661. * </div>
  84662. *
  84663. * <div class="norender">
  84664. * <code>
  84665. * let v = createVector(1, 2, 3);
  84666. * // Provide arguments as an array
  84667. * let arr = [4, 5, 6];
  84668. * v.add(arr);
  84669. * // v's components are set to [5, 7, 9]
  84670. * </code>
  84671. * </div>
  84672. *
  84673. * <div class="norender">
  84674. * <code>
  84675. * // Static method
  84676. * let v1 = createVector(1, 2, 3);
  84677. * let v2 = createVector(2, 3, 4);
  84678. *
  84679. * let v3 = p5.Vector.add(v1, v2);
  84680. * // v3 has components [3, 5, 7]
  84681. * print(v3);
  84682. * </code>
  84683. * </div>
  84684. *
  84685. * <div>
  84686. * <code>
  84687. * // red vector + blue vector = purple vector
  84688. * function draw() {
  84689. * background(240);
  84690. *
  84691. * let v0 = createVector(0, 0);
  84692. * let v1 = createVector(mouseX, mouseY);
  84693. * drawArrow(v0, v1, 'red');
  84694. *
  84695. * let v2 = createVector(-30, 20);
  84696. * drawArrow(v1, v2, 'blue');
  84697. *
  84698. * let v3 = p5.Vector.add(v1, v2);
  84699. * drawArrow(v0, v3, 'purple');
  84700. * }
  84701. *
  84702. * // draw an arrow for a vector at a given base position
  84703. * function drawArrow(base, vec, myColor) {
  84704. * push();
  84705. * stroke(myColor);
  84706. * strokeWeight(3);
  84707. * fill(myColor);
  84708. * translate(base.x, base.y);
  84709. * line(0, 0, vec.x, vec.y);
  84710. * rotate(vec.heading());
  84711. * let arrowSize = 7;
  84712. * translate(vec.mag() - arrowSize, 0);
  84713. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  84714. * pop();
  84715. * }
  84716. * </code>
  84717. * </div>
  84718. */
  84719. /**
  84720. * @method add
  84721. * @param {p5.Vector|Number[]} value the vector to add
  84722. * @chainable
  84723. */
  84724. _main.default.Vector.prototype.add = function add(x, y, z) {
  84725. if (x instanceof _main.default.Vector) {
  84726. this.x += x.x || 0;
  84727. this.y += x.y || 0;
  84728. this.z += x.z || 0;
  84729. return this;
  84730. }
  84731. if (x instanceof Array) {
  84732. this.x += x[0] || 0;
  84733. this.y += x[1] || 0;
  84734. this.z += x[2] || 0;
  84735. return this;
  84736. }
  84737. this.x += x || 0;
  84738. this.y += y || 0;
  84739. this.z += z || 0;
  84740. return this;
  84741. };
  84742. /// HELPERS FOR REMAINDER METHOD
  84743. var calculateRemainder2D = function calculateRemainder2D(xComponent, yComponent) {
  84744. if (xComponent !== 0) {
  84745. this.x = this.x % xComponent;
  84746. }
  84747. if (yComponent !== 0) {
  84748. this.y = this.y % yComponent;
  84749. }
  84750. return this;
  84751. };
  84752. var calculateRemainder3D = function calculateRemainder3D(
  84753. xComponent,
  84754. yComponent,
  84755. zComponent
  84756. ) {
  84757. if (xComponent !== 0) {
  84758. this.x = this.x % xComponent;
  84759. }
  84760. if (yComponent !== 0) {
  84761. this.y = this.y % yComponent;
  84762. }
  84763. if (zComponent !== 0) {
  84764. this.z = this.z % zComponent;
  84765. }
  84766. return this;
  84767. };
  84768. /**
  84769. * Gives remainder of a vector when it is divided by another vector.
  84770. * See examples for more context.
  84771. *
  84772. * @method rem
  84773. * @param {Number} x the x component of divisor vector
  84774. * @param {Number} y the y component of divisor vector
  84775. * @param {Number} z the z component of divisor vector
  84776. * @chainable
  84777. * @example
  84778. * <div class='norender'>
  84779. * <code>
  84780. * let v = createVector(3, 4, 5);
  84781. * v.rem(2, 3, 4);
  84782. * // v's components are set to [1, 1, 1]
  84783. * </code>
  84784. * </div>
  84785. * <div class="norender">
  84786. * <code>
  84787. * // Static method
  84788. * let v1 = createVector(3, 4, 5);
  84789. * let v2 = createVector(2, 3, 4);
  84790. *
  84791. * let v3 = p5.Vector.rem(v1, v2);
  84792. * // v3 has components [1, 1, 1]
  84793. * print(v3);
  84794. * </code>
  84795. * </div>
  84796. */
  84797. /**
  84798. * @method rem
  84799. * @param {p5.Vector | Number[]} value divisor vector
  84800. * @chainable
  84801. */
  84802. _main.default.Vector.prototype.rem = function rem(x, y, z) {
  84803. if (x instanceof _main.default.Vector) {
  84804. if (Number.isFinite(x.x) && Number.isFinite(x.y) && Number.isFinite(x.z)) {
  84805. var xComponent = parseFloat(x.x);
  84806. var yComponent = parseFloat(x.y);
  84807. var zComponent = parseFloat(x.z);
  84808. calculateRemainder3D.call(this, xComponent, yComponent, zComponent);
  84809. }
  84810. } else if (x instanceof Array) {
  84811. if (
  84812. x.every(function(element) {
  84813. return Number.isFinite(element);
  84814. })
  84815. ) {
  84816. if (x.length === 2) {
  84817. calculateRemainder2D.call(this, x[0], x[1]);
  84818. }
  84819. if (x.length === 3) {
  84820. calculateRemainder3D.call(this, x[0], x[1], x[2]);
  84821. }
  84822. }
  84823. } else if (arguments.length === 1) {
  84824. if (Number.isFinite(arguments[0]) && arguments[0] !== 0) {
  84825. this.x = this.x % arguments[0];
  84826. this.y = this.y % arguments[0];
  84827. this.z = this.z % arguments[0];
  84828. return this;
  84829. }
  84830. } else if (arguments.length === 2) {
  84831. var vectorComponents = Array.prototype.slice.call(arguments);
  84832. if (
  84833. vectorComponents.every(function(element) {
  84834. return Number.isFinite(element);
  84835. })
  84836. ) {
  84837. if (vectorComponents.length === 2) {
  84838. calculateRemainder2D.call(this, vectorComponents[0], vectorComponents[1]);
  84839. }
  84840. }
  84841. } else if (arguments.length === 3) {
  84842. var _vectorComponents = Array.prototype.slice.call(arguments);
  84843. if (
  84844. _vectorComponents.every(function(element) {
  84845. return Number.isFinite(element);
  84846. })
  84847. ) {
  84848. if (_vectorComponents.length === 3) {
  84849. calculateRemainder3D.call(
  84850. this,
  84851. _vectorComponents[0],
  84852. _vectorComponents[1],
  84853. _vectorComponents[2]
  84854. );
  84855. }
  84856. }
  84857. }
  84858. };
  84859. /**
  84860. * Subtracts x, y, and z components from a vector, subtracts one vector from
  84861. * another, or subtracts two independent vectors. The version of the method
  84862. * that subtracts two vectors is a static method and returns a <a href="#/p5.Vector">p5.Vector</a>, the
  84863. * other acts directly on the vector. Additionally, you may provide arguments to this function as an array.
  84864. * See the examples for more context.
  84865. *
  84866. * @method sub
  84867. * @param {Number} x the x component of the vector to subtract
  84868. * @param {Number} [y] the y component of the vector to subtract
  84869. * @param {Number} [z] the z component of the vector to subtract
  84870. * @chainable
  84871. * @example
  84872. * <div class="norender">
  84873. * <code>
  84874. * let v = createVector(4, 5, 6);
  84875. * v.sub(1, 1, 1);
  84876. * // v's components are set to [3, 4, 5]
  84877. * </code>
  84878. * </div>
  84879. *
  84880. * <div class="norender">
  84881. * <code>
  84882. * let v = createVector(4, 5, 6);
  84883. * // Provide arguments as an array
  84884. * let arr = [1, 1, 1];
  84885. * v.sub(arr);
  84886. * // v's components are set to [3, 4, 5]
  84887. * </code>
  84888. * </div>
  84889. *
  84890. * <div class="norender">
  84891. * <code>
  84892. * // Static method
  84893. * let v1 = createVector(2, 3, 4);
  84894. * let v2 = createVector(1, 2, 3);
  84895. *
  84896. * let v3 = p5.Vector.sub(v1, v2);
  84897. * // v3 has components [1, 1, 1]
  84898. * print(v3);
  84899. * </code>
  84900. * </div>
  84901. *
  84902. * <div>
  84903. * <code>
  84904. * // red vector - blue vector = purple vector
  84905. * function draw() {
  84906. * background(240);
  84907. *
  84908. * let v0 = createVector(0, 0);
  84909. * let v1 = createVector(70, 50);
  84910. * drawArrow(v0, v1, 'red');
  84911. *
  84912. * let v2 = createVector(mouseX, mouseY);
  84913. * drawArrow(v0, v2, 'blue');
  84914. *
  84915. * let v3 = p5.Vector.sub(v1, v2);
  84916. * drawArrow(v2, v3, 'purple');
  84917. * }
  84918. *
  84919. * // draw an arrow for a vector at a given base position
  84920. * function drawArrow(base, vec, myColor) {
  84921. * push();
  84922. * stroke(myColor);
  84923. * strokeWeight(3);
  84924. * fill(myColor);
  84925. * translate(base.x, base.y);
  84926. * line(0, 0, vec.x, vec.y);
  84927. * rotate(vec.heading());
  84928. * let arrowSize = 7;
  84929. * translate(vec.mag() - arrowSize, 0);
  84930. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  84931. * pop();
  84932. * }
  84933. * </code>
  84934. * </div>
  84935. */
  84936. /**
  84937. * @method sub
  84938. * @param {p5.Vector|Number[]} value the vector to subtract
  84939. * @chainable
  84940. */
  84941. _main.default.Vector.prototype.sub = function sub(x, y, z) {
  84942. if (x instanceof _main.default.Vector) {
  84943. this.x -= x.x || 0;
  84944. this.y -= x.y || 0;
  84945. this.z -= x.z || 0;
  84946. return this;
  84947. }
  84948. if (x instanceof Array) {
  84949. this.x -= x[0] || 0;
  84950. this.y -= x[1] || 0;
  84951. this.z -= x[2] || 0;
  84952. return this;
  84953. }
  84954. this.x -= x || 0;
  84955. this.y -= y || 0;
  84956. this.z -= z || 0;
  84957. return this;
  84958. };
  84959. /**
  84960. * Multiplies the vector by a scalar, multiplies the x, y, and z components from a vector, or multiplies
  84961. * the x, y, and z components of two independent vectors. When multiplying a vector by a scalar, the x, y,
  84962. * and z components of the vector are all multiplied by the scalar. When multiplying a vector by a vector,
  84963. * the x, y, z components of both vectors are multiplied by each other
  84964. * (for example, with two vectors a and b: a.x * b.x, a.y * b.y, a.z * b.z). The static version of this method
  84965. * creates a new <a href="#/p5.Vector">p5.Vector</a> while the non static version acts on the vector
  84966. * directly. Additionally, you may provide arguments to this function as an array.
  84967. * See the examples for more context.
  84968. *
  84969. * @method mult
  84970. * @param {Number} n The number to multiply with the vector
  84971. * @chainable
  84972. * @example
  84973. * <div class="norender">
  84974. * <code>
  84975. * let v = createVector(1, 2, 3);
  84976. * v.mult(2);
  84977. * // v's components are set to [2, 4, 6]
  84978. * </code>
  84979. * </div>
  84980. *
  84981. * <div class="norender">
  84982. * <code>
  84983. * let v0 = createVector(1, 2, 3);
  84984. * let v1 = createVector(2, 3, 4);
  84985. * v0.mult(v1); // v0's components are set to [2, 6, 12]
  84986. * </code>
  84987. * </div>
  84988. *
  84989. * <div class="norender">
  84990. * <code>
  84991. * let v0 = createVector(1, 2, 3);
  84992. * // Provide arguments as an array
  84993. * let arr = [2, 3, 4];
  84994. * v0.mult(arr); // v0's components are set to [2, 6, 12]
  84995. * </code>
  84996. * </div>
  84997. *
  84998. * <div class="norender">
  84999. * <code>
  85000. * let v0 = createVector(1, 2, 3);
  85001. * let v1 = createVector(2, 3, 4);
  85002. * const result = p5.Vector.mult(v0, v1);
  85003. * print(result); // result's components are set to [2, 6, 12]
  85004. * </code>
  85005. * </div>
  85006. *
  85007. * <div class="norender">
  85008. * <code>
  85009. * // Static method
  85010. * let v1 = createVector(1, 2, 3);
  85011. * let v2 = p5.Vector.mult(v1, 2);
  85012. * // v2 has components [2, 4, 6]
  85013. * print(v2);
  85014. * </code>
  85015. * </div>
  85016. *
  85017. * <div>
  85018. * <code>
  85019. * function draw() {
  85020. * background(240);
  85021. *
  85022. * let v0 = createVector(50, 50);
  85023. * let v1 = createVector(25, -25);
  85024. * drawArrow(v0, v1, 'red');
  85025. *
  85026. * let num = map(mouseX, 0, width, -2, 2, true);
  85027. * let v2 = p5.Vector.mult(v1, num);
  85028. * drawArrow(v0, v2, 'blue');
  85029. *
  85030. * noStroke();
  85031. * text('multiplied by ' + num.toFixed(2), 5, 90);
  85032. * }
  85033. *
  85034. * // draw an arrow for a vector at a given base position
  85035. * function drawArrow(base, vec, myColor) {
  85036. * push();
  85037. * stroke(myColor);
  85038. * strokeWeight(3);
  85039. * fill(myColor);
  85040. * translate(base.x, base.y);
  85041. * line(0, 0, vec.x, vec.y);
  85042. * rotate(vec.heading());
  85043. * let arrowSize = 7;
  85044. * translate(vec.mag() - arrowSize, 0);
  85045. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  85046. * pop();
  85047. * }
  85048. * </code>
  85049. * </div>
  85050. */
  85051. /**
  85052. * @method mult
  85053. * @param {Number} x The number to multiply with the x component of the vector
  85054. * @param {Number} y The number to multiply with the y component of the vector
  85055. * @param {Number} [z] The number to multiply with the z component of the vector
  85056. * @chainable
  85057. */
  85058. /**
  85059. * @method mult
  85060. * @param {Number[]} arr The array to multiply with the components of the vector
  85061. * @chainable
  85062. */
  85063. /**
  85064. * @method mult
  85065. * @param {p5.Vector} v The vector to multiply with the components of the original vector
  85066. * @chainable
  85067. */
  85068. _main.default.Vector.prototype.mult = function mult(x, y, z) {
  85069. if (x instanceof _main.default.Vector) {
  85070. // new p5.Vector will check that values are valid upon construction but it's possible
  85071. // that someone could change the value of a component after creation, which is why we still
  85072. // perform this check
  85073. if (
  85074. Number.isFinite(x.x) &&
  85075. Number.isFinite(x.y) &&
  85076. Number.isFinite(x.z) &&
  85077. typeof x.x === 'number' &&
  85078. typeof x.y === 'number' &&
  85079. typeof x.z === 'number'
  85080. ) {
  85081. this.x *= x.x;
  85082. this.y *= x.y;
  85083. this.z *= x.z;
  85084. } else {
  85085. console.warn(
  85086. 'p5.Vector.prototype.mult:',
  85087. 'x contains components that are either undefined or not finite numbers'
  85088. );
  85089. }
  85090. return this;
  85091. }
  85092. if (x instanceof Array) {
  85093. if (
  85094. x.every(function(element) {
  85095. return Number.isFinite(element);
  85096. }) &&
  85097. x.every(function(element) {
  85098. return typeof element === 'number';
  85099. })
  85100. ) {
  85101. if (x.length === 1) {
  85102. this.x *= x[0];
  85103. this.y *= x[0];
  85104. this.z *= x[0];
  85105. } else if (x.length === 2) {
  85106. this.x *= x[0];
  85107. this.y *= x[1];
  85108. } else if (x.length === 3) {
  85109. this.x *= x[0];
  85110. this.y *= x[1];
  85111. this.z *= x[2];
  85112. }
  85113. } else {
  85114. console.warn(
  85115. 'p5.Vector.prototype.mult:',
  85116. 'x contains elements that are either undefined or not finite numbers'
  85117. );
  85118. }
  85119. return this;
  85120. }
  85121. var vectorComponents = Array.prototype.slice.call(arguments);
  85122. if (
  85123. vectorComponents.every(function(element) {
  85124. return Number.isFinite(element);
  85125. }) &&
  85126. vectorComponents.every(function(element) {
  85127. return typeof element === 'number';
  85128. })
  85129. ) {
  85130. if (arguments.length === 1) {
  85131. this.x *= x;
  85132. this.y *= x;
  85133. this.z *= x;
  85134. }
  85135. if (arguments.length === 2) {
  85136. this.x *= x;
  85137. this.y *= y;
  85138. }
  85139. if (arguments.length === 3) {
  85140. this.x *= x;
  85141. this.y *= y;
  85142. this.z *= z;
  85143. }
  85144. } else {
  85145. console.warn(
  85146. 'p5.Vector.prototype.mult:',
  85147. 'x, y, or z arguments are either undefined or not a finite number'
  85148. );
  85149. }
  85150. return this;
  85151. };
  85152. /**
  85153. * Divides the vector by a scalar, divides a vector by the x, y, and z arguments, or divides the x, y, and
  85154. * z components of two vectors against each other. When dividing a vector by a scalar, the x, y,
  85155. * and z components of the vector are all divided by the scalar. When dividing a vector by a vector,
  85156. * the x, y, z components of the source vector are treated as the dividend, and the x, y, z components
  85157. * of the argument is treated as the divisor (for example with two vectors a and b: a.x / b.x, a.y / b.y, a.z / b.z).
  85158. * The static version of this method creates a
  85159. * new <a href="#/p5.Vector">p5.Vector</a> while the non static version acts on the vector directly.
  85160. * Additionally, you may provide arguments to this function as an array.
  85161. * See the examples for more context.
  85162. *
  85163. * @method div
  85164. * @param {number} n The number to divide the vector by
  85165. * @chainable
  85166. * @example
  85167. * <div class="norender">
  85168. * <code>
  85169. * let v = createVector(6, 4, 2);
  85170. * v.div(2); //v's components are set to [3, 2, 1]
  85171. * </code>
  85172. * </div>
  85173. *
  85174. * <div class="norender">
  85175. * <code>
  85176. * let v0 = createVector(9, 4, 2);
  85177. * let v1 = createVector(3, 2, 4);
  85178. * v0.div(v1); // v0's components are set to [3, 2, 0.5]
  85179. * </code>
  85180. * </div>
  85181. *
  85182. * <div class="norender">
  85183. * <code>
  85184. * let v0 = createVector(9, 4, 2);
  85185. * // Provide arguments as an array
  85186. * let arr = [3, 2, 4];
  85187. * v0.div(arr); // v0's components are set to [3, 2, 0.5]
  85188. * </code>
  85189. * </div>
  85190. *
  85191. * <div class="norender">
  85192. * <code>
  85193. * let v0 = createVector(9, 4, 2);
  85194. * let v1 = createVector(3, 2, 4);
  85195. * let result = p5.Vector.div(v0, v1);
  85196. * print(result); // result's components are set to [3, 2, 0.5]
  85197. * </code>
  85198. * </div>
  85199. *
  85200. * <div class="norender">
  85201. * <code>
  85202. * // Static method
  85203. * let v1 = createVector(6, 4, 2);
  85204. * let v2 = p5.Vector.div(v1, 2);
  85205. * // v2 has components [3, 2, 1]
  85206. * print(v2);
  85207. * </code>
  85208. * </div>
  85209. *
  85210. * <div>
  85211. * <code>
  85212. * function draw() {
  85213. * background(240);
  85214. *
  85215. * let v0 = createVector(0, 100);
  85216. * let v1 = createVector(50, -50);
  85217. * drawArrow(v0, v1, 'red');
  85218. *
  85219. * let num = map(mouseX, 0, width, 10, 0.5, true);
  85220. * let v2 = p5.Vector.div(v1, num);
  85221. * drawArrow(v0, v2, 'blue');
  85222. *
  85223. * noStroke();
  85224. * text('divided by ' + num.toFixed(2), 10, 90);
  85225. * }
  85226. *
  85227. * // draw an arrow for a vector at a given base position
  85228. * function drawArrow(base, vec, myColor) {
  85229. * push();
  85230. * stroke(myColor);
  85231. * strokeWeight(3);
  85232. * fill(myColor);
  85233. * translate(base.x, base.y);
  85234. * line(0, 0, vec.x, vec.y);
  85235. * rotate(vec.heading());
  85236. * let arrowSize = 7;
  85237. * translate(vec.mag() - arrowSize, 0);
  85238. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  85239. * pop();
  85240. * }
  85241. * </code>
  85242. * </div>
  85243. */
  85244. /**
  85245. * @method div
  85246. * @param {Number} x The number to divide with the x component of the vector
  85247. * @param {Number} y The number to divide with the y component of the vector
  85248. * @param {Number} [z] The number to divide with the z component of the vector
  85249. * @chainable
  85250. */
  85251. /**
  85252. * @method div
  85253. * @param {Number[]} arr The array to divide the components of the vector by
  85254. * @chainable
  85255. */
  85256. /**
  85257. * @method div
  85258. * @param {p5.Vector} v The vector to divide the components of the original vector by
  85259. * @chainable
  85260. */
  85261. _main.default.Vector.prototype.div = function div(x, y, z) {
  85262. if (x instanceof _main.default.Vector) {
  85263. // new p5.Vector will check that values are valid upon construction but it's possible
  85264. // that someone could change the value of a component after creation, which is why we still
  85265. // perform this check
  85266. if (
  85267. Number.isFinite(x.x) &&
  85268. Number.isFinite(x.y) &&
  85269. Number.isFinite(x.z) &&
  85270. typeof x.x === 'number' &&
  85271. typeof x.y === 'number' &&
  85272. typeof x.z === 'number'
  85273. ) {
  85274. if (x.x === 0 || x.y === 0 || x.z === 0) {
  85275. console.warn('p5.Vector.prototype.div:', 'divide by 0');
  85276. return this;
  85277. }
  85278. this.x /= x.x;
  85279. this.y /= x.y;
  85280. this.z /= x.z;
  85281. } else {
  85282. console.warn(
  85283. 'p5.Vector.prototype.div:',
  85284. 'x contains components that are either undefined or not finite numbers'
  85285. );
  85286. }
  85287. return this;
  85288. }
  85289. if (x instanceof Array) {
  85290. if (
  85291. x.every(function(element) {
  85292. return Number.isFinite(element);
  85293. }) &&
  85294. x.every(function(element) {
  85295. return typeof element === 'number';
  85296. })
  85297. ) {
  85298. if (
  85299. x.some(function(element) {
  85300. return element === 0;
  85301. })
  85302. ) {
  85303. console.warn('p5.Vector.prototype.div:', 'divide by 0');
  85304. return this;
  85305. }
  85306. if (x.length === 1) {
  85307. this.x /= x[0];
  85308. this.y /= x[0];
  85309. this.z /= x[0];
  85310. } else if (x.length === 2) {
  85311. this.x /= x[0];
  85312. this.y /= x[1];
  85313. } else if (x.length === 3) {
  85314. this.x /= x[0];
  85315. this.y /= x[1];
  85316. this.z /= x[2];
  85317. }
  85318. } else {
  85319. console.warn(
  85320. 'p5.Vector.prototype.div:',
  85321. 'x contains components that are either undefined or not finite numbers'
  85322. );
  85323. }
  85324. return this;
  85325. }
  85326. var vectorComponents = Array.prototype.slice.call(arguments);
  85327. if (
  85328. vectorComponents.every(function(element) {
  85329. return Number.isFinite(element);
  85330. }) &&
  85331. vectorComponents.every(function(element) {
  85332. return typeof element === 'number';
  85333. })
  85334. ) {
  85335. if (
  85336. vectorComponents.some(function(element) {
  85337. return element === 0;
  85338. })
  85339. ) {
  85340. console.warn('p5.Vector.prototype.div:', 'divide by 0');
  85341. return this;
  85342. }
  85343. if (arguments.length === 1) {
  85344. this.x /= x;
  85345. this.y /= x;
  85346. this.z /= x;
  85347. }
  85348. if (arguments.length === 2) {
  85349. this.x /= x;
  85350. this.y /= y;
  85351. }
  85352. if (arguments.length === 3) {
  85353. this.x /= x;
  85354. this.y /= y;
  85355. this.z /= z;
  85356. }
  85357. } else {
  85358. console.warn(
  85359. 'p5.Vector.prototype.div:',
  85360. 'x, y, or z arguments are either undefined or not a finite number'
  85361. );
  85362. }
  85363. return this;
  85364. };
  85365. /**
  85366. * Calculates the magnitude (length) of the vector and returns the result as
  85367. * a float (this is simply the equation sqrt(x\*x + y\*y + z\*z).)
  85368. *
  85369. * @method mag
  85370. * @return {Number} magnitude of the vector
  85371. * @example
  85372. * <div>
  85373. * <code>
  85374. * function draw() {
  85375. * background(240);
  85376. *
  85377. * let v0 = createVector(0, 0);
  85378. * let v1 = createVector(mouseX, mouseY);
  85379. * drawArrow(v0, v1, 'black');
  85380. *
  85381. * noStroke();
  85382. * text('vector length: ' + v1.mag().toFixed(2), 10, 70, 90, 30);
  85383. * }
  85384. *
  85385. * // draw an arrow for a vector at a given base position
  85386. * function drawArrow(base, vec, myColor) {
  85387. * push();
  85388. * stroke(myColor);
  85389. * strokeWeight(3);
  85390. * fill(myColor);
  85391. * translate(base.x, base.y);
  85392. * line(0, 0, vec.x, vec.y);
  85393. * rotate(vec.heading());
  85394. * let arrowSize = 7;
  85395. * translate(vec.mag() - arrowSize, 0);
  85396. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  85397. * pop();
  85398. * }
  85399. * </code>
  85400. * </div>
  85401. * <div class="norender">
  85402. * <code>
  85403. * let v = createVector(20.0, 30.0, 40.0);
  85404. * let m = v.mag();
  85405. * print(m); // Prints "53.85164807134504"
  85406. * </code>
  85407. * </div>
  85408. */
  85409. _main.default.Vector.prototype.mag = function mag() {
  85410. return Math.sqrt(this.magSq());
  85411. };
  85412. /**
  85413. * Calculates the squared magnitude of the vector and returns the result
  85414. * as a float (this is simply the equation <em>(x\*x + y\*y + z\*z)</em>.)
  85415. * Faster if the real length is not required in the
  85416. * case of comparing vectors, etc.
  85417. *
  85418. * @method magSq
  85419. * @return {number} squared magnitude of the vector
  85420. * @example
  85421. * <div class="norender">
  85422. * <code>
  85423. * // Static method
  85424. * let v1 = createVector(6, 4, 2);
  85425. * print(v1.magSq()); // Prints "56"
  85426. * </code>
  85427. * </div>
  85428. *
  85429. * <div>
  85430. * <code>
  85431. * function draw() {
  85432. * background(240);
  85433. *
  85434. * let v0 = createVector(0, 0);
  85435. * let v1 = createVector(mouseX, mouseY);
  85436. * drawArrow(v0, v1, 'black');
  85437. *
  85438. * noStroke();
  85439. * text('vector length squared: ' + v1.magSq().toFixed(2), 10, 45, 90, 55);
  85440. * }
  85441. *
  85442. * // draw an arrow for a vector at a given base position
  85443. * function drawArrow(base, vec, myColor) {
  85444. * push();
  85445. * stroke(myColor);
  85446. * strokeWeight(3);
  85447. * fill(myColor);
  85448. * translate(base.x, base.y);
  85449. * line(0, 0, vec.x, vec.y);
  85450. * rotate(vec.heading());
  85451. * let arrowSize = 7;
  85452. * translate(vec.mag() - arrowSize, 0);
  85453. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  85454. * pop();
  85455. * }
  85456. * </code>
  85457. * </div>
  85458. */
  85459. _main.default.Vector.prototype.magSq = function magSq() {
  85460. var x = this.x;
  85461. var y = this.y;
  85462. var z = this.z;
  85463. return x * x + y * y + z * z;
  85464. };
  85465. /**
  85466. * Calculates the dot product of two vectors. The version of the method
  85467. * that computes the dot product of two independent vectors is a static
  85468. * method. See the examples for more context.
  85469. *
  85470. * @method dot
  85471. * @param {Number} x x component of the vector
  85472. * @param {Number} [y] y component of the vector
  85473. * @param {Number} [z] z component of the vector
  85474. * @return {Number} the dot product
  85475. *
  85476. * @example
  85477. * <div class="norender">
  85478. * <code>
  85479. * let v1 = createVector(1, 2, 3);
  85480. * let v2 = createVector(2, 3, 4);
  85481. *
  85482. * print(v1.dot(v2)); // Prints "20"
  85483. * </code>
  85484. * </div>
  85485. *
  85486. * <div class="norender">
  85487. * <code>
  85488. * //Static method
  85489. * let v1 = createVector(1, 2, 3);
  85490. * let v2 = createVector(3, 2, 1);
  85491. * print(p5.Vector.dot(v1, v2)); // Prints "10"
  85492. * </code>
  85493. * </div>
  85494. */
  85495. /**
  85496. * @method dot
  85497. * @param {p5.Vector} value value component of the vector or a <a href="#/p5.Vector">p5.Vector</a>
  85498. * @return {Number}
  85499. */
  85500. _main.default.Vector.prototype.dot = function dot(x, y, z) {
  85501. if (x instanceof _main.default.Vector) {
  85502. return this.dot(x.x, x.y, x.z);
  85503. }
  85504. return this.x * (x || 0) + this.y * (y || 0) + this.z * (z || 0);
  85505. };
  85506. /**
  85507. * Calculates and returns a vector composed of the cross product between
  85508. * two vectors. Both the static and non static methods return a new <a href="#/p5.Vector">p5.Vector</a>.
  85509. * See the examples for more context.
  85510. *
  85511. * @method cross
  85512. * @param {p5.Vector} v <a href="#/p5.Vector">p5.Vector</a> to be crossed
  85513. * @return {p5.Vector} <a href="#/p5.Vector">p5.Vector</a> composed of cross product
  85514. * @example
  85515. * <div class="norender">
  85516. * <code>
  85517. * let v1 = createVector(1, 2, 3);
  85518. * let v2 = createVector(1, 2, 3);
  85519. *
  85520. * let v = v1.cross(v2); // v's components are [0, 0, 0]
  85521. * print(v);
  85522. * </code>
  85523. * </div>
  85524. *
  85525. * <div class="norender">
  85526. * <code>
  85527. * // Static method
  85528. * let v1 = createVector(1, 0, 0);
  85529. * let v2 = createVector(0, 1, 0);
  85530. *
  85531. * let crossProduct = p5.Vector.cross(v1, v2);
  85532. * // crossProduct has components [0, 0, 1]
  85533. * print(crossProduct);
  85534. * </code>
  85535. * </div>
  85536. */
  85537. _main.default.Vector.prototype.cross = function cross(v) {
  85538. var x = this.y * v.z - this.z * v.y;
  85539. var y = this.z * v.x - this.x * v.z;
  85540. var z = this.x * v.y - this.y * v.x;
  85541. if (this.p5) {
  85542. return new _main.default.Vector(this.p5, [x, y, z]);
  85543. } else {
  85544. return new _main.default.Vector(x, y, z);
  85545. }
  85546. };
  85547. /**
  85548. * Calculates the Euclidean distance between two points (considering a
  85549. * point as a vector object).
  85550. * If you are looking to calculate distance with 2 points see <a href="#/p5/dist">dist()</a>
  85551. *
  85552. * @method dist
  85553. * @param {p5.Vector} v the x, y, and z coordinates of a <a href="#/p5.Vector">p5.Vector</a>
  85554. * @return {Number} the distance
  85555. * @example
  85556. * <div class="norender">
  85557. * <code>
  85558. * let v1 = createVector(1, 0, 0);
  85559. * let v2 = createVector(0, 1, 0);
  85560. *
  85561. * let distance = v1.dist(v2); // distance is 1.4142...
  85562. * print(distance);
  85563. * </code>
  85564. * </div>
  85565. *
  85566. * <div class="norender">
  85567. * <code>
  85568. * // Static method
  85569. * let v1 = createVector(1, 0, 0);
  85570. * let v2 = createVector(0, 1, 0);
  85571. *
  85572. * let distance = p5.Vector.dist(v1, v2);
  85573. * // distance is 1.4142...
  85574. * print(distance);
  85575. * </code>
  85576. * </div>
  85577. *
  85578. * <div>
  85579. * <code>
  85580. * function draw() {
  85581. * background(240);
  85582. *
  85583. * let v0 = createVector(0, 0);
  85584. *
  85585. * let v1 = createVector(70, 50);
  85586. * drawArrow(v0, v1, 'red');
  85587. *
  85588. * let v2 = createVector(mouseX, mouseY);
  85589. * drawArrow(v0, v2, 'blue');
  85590. *
  85591. * noStroke();
  85592. * text('distance between vectors: ' + v2.dist(v1).toFixed(2), 5, 50, 95, 50);
  85593. * }
  85594. *
  85595. * // draw an arrow for a vector at a given base position
  85596. * function drawArrow(base, vec, myColor) {
  85597. * push();
  85598. * stroke(myColor);
  85599. * strokeWeight(3);
  85600. * fill(myColor);
  85601. * translate(base.x, base.y);
  85602. * line(0, 0, vec.x, vec.y);
  85603. * rotate(vec.heading());
  85604. * let arrowSize = 7;
  85605. * translate(vec.mag() - arrowSize, 0);
  85606. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  85607. * pop();
  85608. * }
  85609. * </code>
  85610. * </div>
  85611. */
  85612. _main.default.Vector.prototype.dist = function dist(v) {
  85613. return v
  85614. .copy()
  85615. .sub(this)
  85616. .mag();
  85617. };
  85618. /**
  85619. * Normalize the vector to length 1 (make it a unit vector).
  85620. *
  85621. * @method normalize
  85622. * @return {p5.Vector} normalized <a href="#/p5.Vector">p5.Vector</a>
  85623. * @example
  85624. * <div class="norender">
  85625. * <code>
  85626. * let v = createVector(10, 20, 2);
  85627. * // v has components [10.0, 20.0, 2.0]
  85628. * v.normalize();
  85629. * // v's components are set to
  85630. * // [0.4454354, 0.8908708, 0.089087084]
  85631. * </code>
  85632. * </div>
  85633. *
  85634. * <div class="norender">
  85635. * <code>
  85636. * // Static method
  85637. * let v_initial = createVector(10, 20, 2);
  85638. * // v_initial has components [10.0, 20.0, 2.0]
  85639. * let v_normalized = p5.Vector.normalize(v_initial);
  85640. * print(v_normalized);
  85641. * // returns a new vector with components set to
  85642. * // [0.4454354, 0.8908708, 0.089087084]
  85643. * // v_initial remains unchanged
  85644. * </code>
  85645. * </div>
  85646. *
  85647. * <div>
  85648. * <code>
  85649. * function draw() {
  85650. * background(240);
  85651. *
  85652. * let v0 = createVector(50, 50);
  85653. * let v1 = createVector(mouseX - 50, mouseY - 50);
  85654. *
  85655. * drawArrow(v0, v1, 'red');
  85656. * v1.normalize();
  85657. * drawArrow(v0, v1.mult(35), 'blue');
  85658. *
  85659. * noFill();
  85660. * ellipse(50, 50, 35 * 2);
  85661. * }
  85662. *
  85663. * // draw an arrow for a vector at a given base position
  85664. * function drawArrow(base, vec, myColor) {
  85665. * push();
  85666. * stroke(myColor);
  85667. * strokeWeight(3);
  85668. * fill(myColor);
  85669. * translate(base.x, base.y);
  85670. * line(0, 0, vec.x, vec.y);
  85671. * rotate(vec.heading());
  85672. * let arrowSize = 7;
  85673. * translate(vec.mag() - arrowSize, 0);
  85674. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  85675. * pop();
  85676. * }
  85677. * </code>
  85678. * </div>
  85679. */
  85680. _main.default.Vector.prototype.normalize = function normalize() {
  85681. var len = this.mag();
  85682. // here we multiply by the reciprocal instead of calling 'div()'
  85683. // since div duplicates this zero check.
  85684. if (len !== 0) this.mult(1 / len);
  85685. return this;
  85686. };
  85687. /**
  85688. * Limit the magnitude of this vector to the value used for the <b>max</b>
  85689. * parameter.
  85690. *
  85691. * @method limit
  85692. * @param {Number} max the maximum magnitude for the vector
  85693. * @chainable
  85694. * @example
  85695. * <div class="norender">
  85696. * <code>
  85697. * let v = createVector(10, 20, 2);
  85698. * // v has components [10.0, 20.0, 2.0]
  85699. * v.limit(5);
  85700. * // v's components are set to
  85701. * // [2.2271771, 4.4543543, 0.4454354]
  85702. * </code>
  85703. * </div>
  85704. * <div>
  85705. * <code>
  85706. * function draw() {
  85707. * background(240);
  85708. *
  85709. * let v0 = createVector(50, 50);
  85710. * let v1 = createVector(mouseX - 50, mouseY - 50);
  85711. *
  85712. * drawArrow(v0, v1, 'red');
  85713. * drawArrow(v0, v1.limit(35), 'blue');
  85714. *
  85715. * noFill();
  85716. * ellipse(50, 50, 35 * 2);
  85717. * }
  85718. *
  85719. * // draw an arrow for a vector at a given base position
  85720. * function drawArrow(base, vec, myColor) {
  85721. * push();
  85722. * stroke(myColor);
  85723. * strokeWeight(3);
  85724. * fill(myColor);
  85725. * translate(base.x, base.y);
  85726. * line(0, 0, vec.x, vec.y);
  85727. * rotate(vec.heading());
  85728. * let arrowSize = 7;
  85729. * translate(vec.mag() - arrowSize, 0);
  85730. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  85731. * pop();
  85732. * }
  85733. * </code>
  85734. * </div>
  85735. */
  85736. _main.default.Vector.prototype.limit = function limit(max) {
  85737. var mSq = this.magSq();
  85738. if (mSq > max * max) {
  85739. this.div(Math.sqrt(mSq)) //normalize it
  85740. .mult(max);
  85741. }
  85742. return this;
  85743. };
  85744. /**
  85745. * Set the magnitude of this vector to the value used for the <b>len</b>
  85746. * parameter.
  85747. *
  85748. * @method setMag
  85749. * @param {number} len the new length for this vector
  85750. * @chainable
  85751. * @example
  85752. * <div class="norender">
  85753. * <code>
  85754. * let v = createVector(10, 20, 2);
  85755. * // v has components [10.0, 20.0, 2.0]
  85756. * v.setMag(10);
  85757. * // v's components are set to [6.0, 8.0, 0.0]
  85758. * </code>
  85759. * </div>
  85760. *
  85761. * <div>
  85762. * <code>
  85763. * function draw() {
  85764. * background(240);
  85765. *
  85766. * let v0 = createVector(0, 0);
  85767. * let v1 = createVector(50, 50);
  85768. *
  85769. * drawArrow(v0, v1, 'red');
  85770. *
  85771. * let length = map(mouseX, 0, width, 0, 141, true);
  85772. * v1.setMag(length);
  85773. * drawArrow(v0, v1, 'blue');
  85774. *
  85775. * noStroke();
  85776. * text('magnitude set to: ' + length.toFixed(2), 10, 70, 90, 30);
  85777. * }
  85778. *
  85779. * // draw an arrow for a vector at a given base position
  85780. * function drawArrow(base, vec, myColor) {
  85781. * push();
  85782. * stroke(myColor);
  85783. * strokeWeight(3);
  85784. * fill(myColor);
  85785. * translate(base.x, base.y);
  85786. * line(0, 0, vec.x, vec.y);
  85787. * rotate(vec.heading());
  85788. * let arrowSize = 7;
  85789. * translate(vec.mag() - arrowSize, 0);
  85790. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  85791. * pop();
  85792. * }
  85793. * </code>
  85794. * </div>
  85795. */
  85796. _main.default.Vector.prototype.setMag = function setMag(n) {
  85797. return this.normalize().mult(n);
  85798. };
  85799. /**
  85800. * Calculate the angle of rotation for this vector(only 2D vectors).
  85801. * p5.Vectors created using <a href="#/p5/createVector">createVector()</a>
  85802. * will take the current <a href="#/p5/angleMode">angleMode</a> into
  85803. * consideration, and give the angle in radians or degree accordingly.
  85804. *
  85805. * @method heading
  85806. * @return {Number} the angle of rotation
  85807. * @example
  85808. * <div class = "norender">
  85809. * <code>
  85810. * function setup() {
  85811. * let v1 = createVector(30, 50);
  85812. * print(v1.heading()); // 1.0303768265243125
  85813. *
  85814. * v1 = createVector(40, 50);
  85815. * print(v1.heading()); // 0.8960553845713439
  85816. *
  85817. * v1 = createVector(30, 70);
  85818. * print(v1.heading()); // 1.1659045405098132
  85819. * }
  85820. * </code>
  85821. * </div>
  85822. *
  85823. * <div>
  85824. * <code>
  85825. * function draw() {
  85826. * background(240);
  85827. *
  85828. * let v0 = createVector(50, 50);
  85829. * let v1 = createVector(mouseX - 50, mouseY - 50);
  85830. *
  85831. * drawArrow(v0, v1, 'black');
  85832. *
  85833. * let myHeading = v1.heading();
  85834. * noStroke();
  85835. * text(
  85836. * 'vector heading: ' +
  85837. * myHeading.toFixed(2) +
  85838. * ' radians or ' +
  85839. * degrees(myHeading).toFixed(2) +
  85840. * ' degrees',
  85841. * 10,
  85842. * 50,
  85843. * 90,
  85844. * 50
  85845. * );
  85846. * }
  85847. *
  85848. * // draw an arrow for a vector at a given base position
  85849. * function drawArrow(base, vec, myColor) {
  85850. * push();
  85851. * stroke(myColor);
  85852. * strokeWeight(3);
  85853. * fill(myColor);
  85854. * translate(base.x, base.y);
  85855. * line(0, 0, vec.x, vec.y);
  85856. * rotate(vec.heading());
  85857. * let arrowSize = 7;
  85858. * translate(vec.mag() - arrowSize, 0);
  85859. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  85860. * pop();
  85861. * }
  85862. * </code>
  85863. * </div>
  85864. */
  85865. _main.default.Vector.prototype.heading = function heading() {
  85866. var h = Math.atan2(this.y, this.x);
  85867. if (this.p5) return this.p5._fromRadians(h);
  85868. return h;
  85869. };
  85870. /**
  85871. * Rotate the vector to a specific angle (only 2D vectors), magnitude remains the
  85872. * same
  85873. *
  85874. * @method setHeading
  85875. * @param {number} angle the angle of rotation
  85876. * @chainable
  85877. * @example
  85878. * <div class="norender">
  85879. * <code>
  85880. * let v = createVector(10.0, 20.0);
  85881. * // result of v.heading() is 1.1071487177940904
  85882. * v.setHeading(Math.PI);
  85883. * // result of v.heading() is now 3.141592653589793
  85884. * </code>
  85885. * </div>
  85886. */
  85887. _main.default.Vector.prototype.setHeading = function setHeading(a) {
  85888. var m = this.mag();
  85889. this.x = m * Math.cos(a);
  85890. this.y = m * Math.sin(a);
  85891. return this;
  85892. };
  85893. /**
  85894. * Rotate the vector by an angle (only 2D vectors), magnitude remains the
  85895. * same
  85896. *
  85897. * @method rotate
  85898. * @param {number} angle the angle of rotation
  85899. * @chainable
  85900. * @example
  85901. * <div class="norender">
  85902. * <code>
  85903. * let v = createVector(10.0, 20.0);
  85904. * // v has components [10.0, 20.0, 0.0]
  85905. * v.rotate(HALF_PI);
  85906. * // v's components are set to [-20.0, 9.999999, 0.0]
  85907. * </code>
  85908. * </div>
  85909. *
  85910. * <div class="norender">
  85911. * <code>
  85912. * // static function implementation
  85913. * let v = createVector(10.0, 20.0);
  85914. * // v has components [10.0, 20.0, 0.0]
  85915. * let rotated_v = p5.Vector.rotate(v, HALF_PI);
  85916. * console.log(rotated_v);
  85917. * // rotated_v's components are set to [-20.0, 9.999999, 0.0]
  85918. * console.log(v);
  85919. * // v's components remains the same (i.e, [10.0, 20.0, 0.0])
  85920. * </code>
  85921. * </div>
  85922. *
  85923. * <div>
  85924. * <code>
  85925. * let angle = 0;
  85926. * function draw() {
  85927. * background(240);
  85928. *
  85929. * let v0 = createVector(50, 50);
  85930. * let v1 = createVector(50, 0);
  85931. *
  85932. * drawArrow(v0, v1.rotate(angle), 'black');
  85933. * angle += 0.01;
  85934. * }
  85935. *
  85936. * // draw an arrow for a vector at a given base position
  85937. * function drawArrow(base, vec, myColor) {
  85938. * push();
  85939. * stroke(myColor);
  85940. * strokeWeight(3);
  85941. * fill(myColor);
  85942. * translate(base.x, base.y);
  85943. * line(0, 0, vec.x, vec.y);
  85944. * rotate(vec.heading());
  85945. * let arrowSize = 7;
  85946. * translate(vec.mag() - arrowSize, 0);
  85947. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  85948. * pop();
  85949. * }
  85950. * </code>
  85951. * </div>
  85952. */
  85953. _main.default.Vector.prototype.rotate = function rotate(a) {
  85954. var newHeading = this.heading() + a;
  85955. if (this.p5) newHeading = this.p5._toRadians(newHeading);
  85956. var mag = this.mag();
  85957. this.x = Math.cos(newHeading) * mag;
  85958. this.y = Math.sin(newHeading) * mag;
  85959. return this;
  85960. };
  85961. /**
  85962. * Calculates and returns the angle between two vectors. This function will take
  85963. * the current <a href="#/p5/angleMode">angleMode</a> into consideration, and
  85964. * give the angle in radians or degree accordingly.
  85965. *
  85966. * @method angleBetween
  85967. * @param {p5.Vector} value the x, y, and z components of a <a href="#/p5.Vector">p5.Vector</a>
  85968. * @return {Number} the angle between (in radians)
  85969. * @example
  85970. * <div class="norender">
  85971. * <code>
  85972. * let v1 = createVector(1, 0, 0);
  85973. * let v2 = createVector(0, 1, 0);
  85974. *
  85975. * let angle = v1.angleBetween(v2);
  85976. * // angle is PI/2
  85977. * print(angle);
  85978. * </code>
  85979. * </div>
  85980. *
  85981. * <div>
  85982. * <code>
  85983. * function draw() {
  85984. * background(240);
  85985. * let v0 = createVector(50, 50);
  85986. *
  85987. * let v1 = createVector(50, 0);
  85988. * drawArrow(v0, v1, 'red');
  85989. *
  85990. * let v2 = createVector(mouseX - 50, mouseY - 50);
  85991. * drawArrow(v0, v2, 'blue');
  85992. *
  85993. * let angleBetween = v1.angleBetween(v2);
  85994. * noStroke();
  85995. * text(
  85996. * 'angle between: ' +
  85997. * angleBetween.toFixed(2) +
  85998. * ' radians or ' +
  85999. * degrees(angleBetween).toFixed(2) +
  86000. * ' degrees',
  86001. * 10,
  86002. * 50,
  86003. * 90,
  86004. * 50
  86005. * );
  86006. * }
  86007. *
  86008. * // draw an arrow for a vector at a given base position
  86009. * function drawArrow(base, vec, myColor) {
  86010. * push();
  86011. * stroke(myColor);
  86012. * strokeWeight(3);
  86013. * fill(myColor);
  86014. * translate(base.x, base.y);
  86015. * line(0, 0, vec.x, vec.y);
  86016. * rotate(vec.heading());
  86017. * let arrowSize = 7;
  86018. * translate(vec.mag() - arrowSize, 0);
  86019. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  86020. * pop();
  86021. * }
  86022. * </code>
  86023. * </div>
  86024. */
  86025. _main.default.Vector.prototype.angleBetween = function angleBetween(v) {
  86026. var dotmagmag = this.dot(v) / (this.mag() * v.mag());
  86027. // Mathematically speaking: the dotmagmag variable will be between -1 and 1
  86028. // inclusive. Practically though it could be slightly outside this range due
  86029. // to floating-point rounding issues. This can make Math.acos return NaN.
  86030. //
  86031. // Solution: we'll clamp the value to the -1,1 range
  86032. var angle;
  86033. angle = Math.acos(Math.min(1, Math.max(-1, dotmagmag)));
  86034. angle = angle * Math.sign(this.cross(v).z || 1);
  86035. if (this.p5) {
  86036. angle = this.p5._fromRadians(angle);
  86037. }
  86038. return angle;
  86039. };
  86040. /**
  86041. * Linear interpolate the vector to another vector
  86042. *
  86043. * @method lerp
  86044. * @param {Number} x the x component
  86045. * @param {Number} y the y component
  86046. * @param {Number} z the z component
  86047. * @param {Number} amt the amount of interpolation; some value between 0.0
  86048. * (old vector) and 1.0 (new vector). 0.9 is very near
  86049. * the new vector. 0.5 is halfway in between.
  86050. * @chainable
  86051. *
  86052. * @example
  86053. * <div class="norender">
  86054. * <code>
  86055. * let v = createVector(1, 1, 0);
  86056. *
  86057. * v.lerp(3, 3, 0, 0.5); // v now has components [2,2,0]
  86058. * </code>
  86059. * </div>
  86060. *
  86061. * <div class="norender">
  86062. * <code>
  86063. * let v1 = createVector(0, 0, 0);
  86064. * let v2 = createVector(100, 100, 0);
  86065. *
  86066. * let v3 = p5.Vector.lerp(v1, v2, 0.5);
  86067. * // v3 has components [50,50,0]
  86068. * print(v3);
  86069. * </code>
  86070. * </div>
  86071. *
  86072. * <div>
  86073. * <code>
  86074. * let step = 0.01;
  86075. * let amount = 0;
  86076. *
  86077. * function draw() {
  86078. * background(240);
  86079. * let v0 = createVector(0, 0);
  86080. *
  86081. * let v1 = createVector(mouseX, mouseY);
  86082. * drawArrow(v0, v1, 'red');
  86083. *
  86084. * let v2 = createVector(90, 90);
  86085. * drawArrow(v0, v2, 'blue');
  86086. *
  86087. * if (amount > 1 || amount < 0) {
  86088. * step *= -1;
  86089. * }
  86090. * amount += step;
  86091. * let v3 = p5.Vector.lerp(v1, v2, amount);
  86092. *
  86093. * drawArrow(v0, v3, 'purple');
  86094. * }
  86095. *
  86096. * // draw an arrow for a vector at a given base position
  86097. * function drawArrow(base, vec, myColor) {
  86098. * push();
  86099. * stroke(myColor);
  86100. * strokeWeight(3);
  86101. * fill(myColor);
  86102. * translate(base.x, base.y);
  86103. * line(0, 0, vec.x, vec.y);
  86104. * rotate(vec.heading());
  86105. * let arrowSize = 7;
  86106. * translate(vec.mag() - arrowSize, 0);
  86107. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  86108. * pop();
  86109. * }
  86110. * </code>
  86111. * </div>
  86112. */
  86113. /**
  86114. * @method lerp
  86115. * @param {p5.Vector} v the <a href="#/p5.Vector">p5.Vector</a> to lerp to
  86116. * @param {Number} amt
  86117. * @chainable
  86118. */
  86119. _main.default.Vector.prototype.lerp = function lerp(x, y, z, amt) {
  86120. if (x instanceof _main.default.Vector) {
  86121. return this.lerp(x.x, x.y, x.z, y);
  86122. }
  86123. this.x += (x - this.x) * amt || 0;
  86124. this.y += (y - this.y) * amt || 0;
  86125. this.z += (z - this.z) * amt || 0;
  86126. return this;
  86127. };
  86128. /**
  86129. * Reflect the incoming vector about a normal to a line in 2D, or about a normal to a plane in 3D
  86130. * This method acts on the vector directly
  86131. *
  86132. * @method reflect
  86133. * @param {p5.Vector} surfaceNormal the <a href="#/p5.Vector">p5.Vector</a> to reflect about, will be normalized by this method
  86134. * @chainable
  86135. * @example
  86136. * <div class="norender">
  86137. * <code>
  86138. * let v = createVector(4, 6); // incoming vector, this example vector is heading to the right and downward
  86139. * let n = createVector(0, -1); // surface normal to a plane (this example normal points directly upwards)
  86140. * v.reflect(n); // v is reflected about the surface normal n. v's components are now set to [4, -6]
  86141. * </code>
  86142. * </div>
  86143. *
  86144. * <div>
  86145. * <code>
  86146. * function draw() {
  86147. * background(240);
  86148. *
  86149. * let v0 = createVector(0, 0);
  86150. * let v1 = createVector(mouseX, mouseY);
  86151. * drawArrow(v0, v1, 'red');
  86152. *
  86153. * let n = createVector(0, -30);
  86154. * drawArrow(v1, n, 'blue');
  86155. *
  86156. * let r = v1.copy();
  86157. * r.reflect(n);
  86158. * drawArrow(v1, r, 'purple');
  86159. * }
  86160. *
  86161. * // draw an arrow for a vector at a given base position
  86162. * function drawArrow(base, vec, myColor) {
  86163. * push();
  86164. * stroke(myColor);
  86165. * strokeWeight(3);
  86166. * fill(myColor);
  86167. * translate(base.x, base.y);
  86168. * line(0, 0, vec.x, vec.y);
  86169. * rotate(vec.heading());
  86170. * let arrowSize = 7;
  86171. * translate(vec.mag() - arrowSize, 0);
  86172. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  86173. * pop();
  86174. * }
  86175. * </code>
  86176. * </div>
  86177. */
  86178. _main.default.Vector.prototype.reflect = function reflect(surfaceNormal) {
  86179. surfaceNormal.normalize();
  86180. return this.sub(surfaceNormal.mult(2 * this.dot(surfaceNormal)));
  86181. };
  86182. /**
  86183. * Return a representation of this vector as a float array. This is only
  86184. * for temporary use. If used in any other fashion, the contents should be
  86185. * copied by using the <b>p5.Vector.<a href="#/p5.Vector/copy">copy()</a></b> method to copy into your own
  86186. * array.
  86187. *
  86188. * @method array
  86189. * @return {Number[]} an Array with the 3 values
  86190. * @example
  86191. * <div class = "norender">
  86192. * <code>
  86193. * function setup() {
  86194. * let v = createVector(20, 30);
  86195. * print(v.array()); // Prints : Array [20, 30, 0]
  86196. * }
  86197. * </code>
  86198. * </div>
  86199. *
  86200. * <div class="norender">
  86201. * <code>
  86202. * let v = createVector(10.0, 20.0, 30.0);
  86203. * let f = v.array();
  86204. * print(f[0]); // Prints "10.0"
  86205. * print(f[1]); // Prints "20.0"
  86206. * print(f[2]); // Prints "30.0"
  86207. * </code>
  86208. * </div>
  86209. */
  86210. _main.default.Vector.prototype.array = function array() {
  86211. return [this.x || 0, this.y || 0, this.z || 0];
  86212. };
  86213. /**
  86214. * Equality check against a <a href="#/p5.Vector">p5.Vector</a>
  86215. *
  86216. * @method equals
  86217. * @param {Number} [x] the x component of the vector
  86218. * @param {Number} [y] the y component of the vector
  86219. * @param {Number} [z] the z component of the vector
  86220. * @return {Boolean} whether the vectors are equals
  86221. * @example
  86222. * <div class = "norender">
  86223. * <code>
  86224. * let v1 = createVector(5, 10, 20);
  86225. * let v2 = createVector(5, 10, 20);
  86226. * let v3 = createVector(13, 10, 19);
  86227. *
  86228. * print(v1.equals(v2.x, v2.y, v2.z)); // true
  86229. * print(v1.equals(v3.x, v3.y, v3.z)); // false
  86230. * </code>
  86231. * </div>
  86232. *
  86233. * <div class="norender">
  86234. * <code>
  86235. * let v1 = createVector(10.0, 20.0, 30.0);
  86236. * let v2 = createVector(10.0, 20.0, 30.0);
  86237. * let v3 = createVector(0.0, 0.0, 0.0);
  86238. * print(v1.equals(v2)); // true
  86239. * print(v1.equals(v3)); // false
  86240. * </code>
  86241. * </div>
  86242. */
  86243. /**
  86244. * @method equals
  86245. * @param {p5.Vector|Array} value the vector to compare
  86246. * @return {Boolean}
  86247. */
  86248. _main.default.Vector.prototype.equals = function equals(x, y, z) {
  86249. var a, b, c;
  86250. if (x instanceof _main.default.Vector) {
  86251. a = x.x || 0;
  86252. b = x.y || 0;
  86253. c = x.z || 0;
  86254. } else if (x instanceof Array) {
  86255. a = x[0] || 0;
  86256. b = x[1] || 0;
  86257. c = x[2] || 0;
  86258. } else {
  86259. a = x || 0;
  86260. b = y || 0;
  86261. c = z || 0;
  86262. }
  86263. return this.x === a && this.y === b && this.z === c;
  86264. };
  86265. // Static Methods
  86266. /**
  86267. * Make a new 2D vector from an angle
  86268. *
  86269. * @method fromAngle
  86270. * @static
  86271. * @param {Number} angle the desired angle, in radians (unaffected by <a href="#/p5/angleMode">angleMode</a>)
  86272. * @param {Number} [length] the length of the new vector (defaults to 1)
  86273. * @return {p5.Vector} the new <a href="#/p5.Vector">p5.Vector</a> object
  86274. * @example
  86275. * <div>
  86276. * <code>
  86277. * function draw() {
  86278. * background(200);
  86279. *
  86280. * // Create a variable, proportional to the mouseX,
  86281. * // varying from 0-360, to represent an angle in degrees.
  86282. * let myDegrees = map(mouseX, 0, width, 0, 360);
  86283. *
  86284. * // Display that variable in an onscreen text.
  86285. * // (Note the nfc() function to truncate additional decimal places,
  86286. * // and the "\xB0" character for the degree symbol.)
  86287. * let readout = 'angle = ' + nfc(myDegrees, 1) + '\xB0';
  86288. * noStroke();
  86289. * fill(0);
  86290. * text(readout, 5, 15);
  86291. *
  86292. * // Create a p5.Vector using the fromAngle function,
  86293. * // and extract its x and y components.
  86294. * let v = p5.Vector.fromAngle(radians(myDegrees), 30);
  86295. * let vx = v.x;
  86296. * let vy = v.y;
  86297. *
  86298. * push();
  86299. * translate(width / 2, height / 2);
  86300. * noFill();
  86301. * stroke(150);
  86302. * line(0, 0, 30, 0);
  86303. * stroke(0);
  86304. * line(0, 0, vx, vy);
  86305. * pop();
  86306. * }
  86307. * </code>
  86308. * </div>
  86309. */
  86310. _main.default.Vector.fromAngle = function fromAngle(angle, length) {
  86311. if (typeof length === 'undefined') {
  86312. length = 1;
  86313. }
  86314. return new _main.default.Vector(
  86315. length * Math.cos(angle),
  86316. length * Math.sin(angle),
  86317. 0
  86318. );
  86319. };
  86320. /**
  86321. * Make a new 3D vector from a pair of ISO spherical angles
  86322. *
  86323. * @method fromAngles
  86324. * @static
  86325. * @param {Number} theta the polar angle, in radians (zero is up)
  86326. * @param {Number} phi the azimuthal angle, in radians
  86327. * (zero is out of the screen)
  86328. * @param {Number} [length] the length of the new vector (defaults to 1)
  86329. * @return {p5.Vector} the new <a href="#/p5.Vector">p5.Vector</a> object
  86330. * @example
  86331. * <div modernizr='webgl'>
  86332. * <code>
  86333. * function setup() {
  86334. * createCanvas(100, 100, WEBGL);
  86335. * fill(255);
  86336. * noStroke();
  86337. * }
  86338. * function draw() {
  86339. * background(255);
  86340. *
  86341. * let t = millis() / 1000;
  86342. *
  86343. * // add three point lights
  86344. * pointLight(color('#f00'), p5.Vector.fromAngles(t * 1.0, t * 1.3, 100));
  86345. * pointLight(color('#0f0'), p5.Vector.fromAngles(t * 1.1, t * 1.2, 100));
  86346. * pointLight(color('#00f'), p5.Vector.fromAngles(t * 1.2, t * 1.1, 100));
  86347. *
  86348. * sphere(35);
  86349. * }
  86350. * </code>
  86351. * </div>
  86352. */
  86353. _main.default.Vector.fromAngles = function(theta, phi, length) {
  86354. if (typeof length === 'undefined') {
  86355. length = 1;
  86356. }
  86357. var cosPhi = Math.cos(phi);
  86358. var sinPhi = Math.sin(phi);
  86359. var cosTheta = Math.cos(theta);
  86360. var sinTheta = Math.sin(theta);
  86361. return new _main.default.Vector(
  86362. length * sinTheta * sinPhi,
  86363. -length * cosTheta,
  86364. length * sinTheta * cosPhi
  86365. );
  86366. };
  86367. /**
  86368. * Make a new 2D unit vector from a random angle
  86369. *
  86370. * @method random2D
  86371. * @static
  86372. * @return {p5.Vector} the new <a href="#/p5.Vector">p5.Vector</a> object
  86373. * @example
  86374. * <div class="norender">
  86375. * <code>
  86376. * let v = p5.Vector.random2D();
  86377. * // May make v's attributes something like:
  86378. * // [0.61554617, -0.51195765, 0.0] or
  86379. * // [-0.4695841, -0.14366731, 0.0] or
  86380. * // [0.6091097, -0.22805278, 0.0]
  86381. * print(v);
  86382. * </code>
  86383. * </div>
  86384. *
  86385. * <div>
  86386. * <code>
  86387. * function setup() {
  86388. * frameRate(1);
  86389. * }
  86390. *
  86391. * function draw() {
  86392. * background(240);
  86393. *
  86394. * let v0 = createVector(50, 50);
  86395. * let v1 = p5.Vector.random2D();
  86396. * drawArrow(v0, v1.mult(50), 'black');
  86397. * }
  86398. *
  86399. * // draw an arrow for a vector at a given base position
  86400. * function drawArrow(base, vec, myColor) {
  86401. * push();
  86402. * stroke(myColor);
  86403. * strokeWeight(3);
  86404. * fill(myColor);
  86405. * translate(base.x, base.y);
  86406. * line(0, 0, vec.x, vec.y);
  86407. * rotate(vec.heading());
  86408. * let arrowSize = 7;
  86409. * translate(vec.mag() - arrowSize, 0);
  86410. * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
  86411. * pop();
  86412. * }
  86413. * </code>
  86414. * </div>
  86415. */
  86416. _main.default.Vector.random2D = function random2D() {
  86417. return this.fromAngle(Math.random() * constants.TWO_PI);
  86418. };
  86419. /**
  86420. * Make a new random 3D unit vector.
  86421. *
  86422. * @method random3D
  86423. * @static
  86424. * @return {p5.Vector} the new <a href="#/p5.Vector">p5.Vector</a> object
  86425. * @example
  86426. * <div class="norender">
  86427. * <code>
  86428. * let v = p5.Vector.random3D();
  86429. * // May make v's attributes something like:
  86430. * // [0.61554617, -0.51195765, 0.599168] or
  86431. * // [-0.4695841, -0.14366731, -0.8711202] or
  86432. * // [0.6091097, -0.22805278, -0.7595902]
  86433. * print(v);
  86434. * </code>
  86435. * </div>
  86436. */
  86437. _main.default.Vector.random3D = function random3D() {
  86438. var angle = Math.random() * constants.TWO_PI;
  86439. var vz = Math.random() * 2 - 1;
  86440. var vzBase = Math.sqrt(1 - vz * vz);
  86441. var vx = vzBase * Math.cos(angle);
  86442. var vy = vzBase * Math.sin(angle);
  86443. return new _main.default.Vector(vx, vy, vz);
  86444. };
  86445. // Adds two vectors together and returns a new one.
  86446. /**
  86447. * @method add
  86448. * @static
  86449. * @param {p5.Vector} v1 a <a href="#/p5.Vector">p5.Vector</a> to add
  86450. * @param {p5.Vector} v2 a <a href="#/p5.Vector">p5.Vector</a> to add
  86451. * @param {p5.Vector} [target] the vector to receive the result
  86452. * @return {p5.Vector} the resulting <a href="#/p5.Vector">p5.Vector</a>
  86453. */
  86454. _main.default.Vector.add = function add(v1, v2, target) {
  86455. if (!target) {
  86456. target = v1.copy();
  86457. if (arguments.length === 3) {
  86458. _main.default._friendlyError(
  86459. 'The target parameter is undefined, it should be of type p5.Vector',
  86460. 'p5.Vector.add'
  86461. );
  86462. }
  86463. } else {
  86464. target.set(v1);
  86465. }
  86466. target.add(v2);
  86467. return target;
  86468. };
  86469. // Returns a vector remainder when it is divided by another vector
  86470. /**
  86471. * @method rem
  86472. * @static
  86473. * @param {p5.Vector} v1 dividend <a href="#/p5.Vector">p5.Vector</a>
  86474. * @param {p5.Vector} v2 divisor <a href="#/p5.Vector">p5.Vector</a>
  86475. */
  86476. /**
  86477. * @method rem
  86478. * @static
  86479. * @param {p5.Vector} v1
  86480. * @param {p5.Vector} v2
  86481. * @return {p5.Vector} the resulting <a href="#/p5.Vector">p5.Vector</a>
  86482. */
  86483. _main.default.Vector.rem = function rem(v1, v2) {
  86484. if (v1 instanceof _main.default.Vector && v2 instanceof _main.default.Vector) {
  86485. var target = v1.copy();
  86486. target.rem(v2);
  86487. return target;
  86488. }
  86489. };
  86490. /*
  86491. * Subtracts one <a href="#/p5.Vector">p5.Vector</a> from another and returns a new one. The second
  86492. * vector (v2) is subtracted from the first (v1), resulting in v1-v2.
  86493. */
  86494. /**
  86495. * @method sub
  86496. * @static
  86497. * @param {p5.Vector} v1 a <a href="#/p5.Vector">p5.Vector</a> to subtract from
  86498. * @param {p5.Vector} v2 a <a href="#/p5.Vector">p5.Vector</a> to subtract
  86499. * @param {p5.Vector} [target] the vector to receive the result
  86500. * @return {p5.Vector} the resulting <a href="#/p5.Vector">p5.Vector</a>
  86501. */
  86502. _main.default.Vector.sub = function sub(v1, v2, target) {
  86503. if (!target) {
  86504. target = v1.copy();
  86505. if (arguments.length === 3) {
  86506. _main.default._friendlyError(
  86507. 'The target parameter is undefined, it should be of type p5.Vector',
  86508. 'p5.Vector.sub'
  86509. );
  86510. }
  86511. } else {
  86512. target.set(v1);
  86513. }
  86514. target.sub(v2);
  86515. return target;
  86516. };
  86517. /**
  86518. * Multiplies a vector by a scalar and returns a new vector.
  86519. */
  86520. /**
  86521. * @method mult
  86522. * @static
  86523. * @param {Number} x
  86524. * @param {Number} y
  86525. * @param {Number} [z]
  86526. * @return {p5.Vector} The resulting new <a href="#/p5.Vector">p5.Vector</a>
  86527. */
  86528. /**
  86529. * @method mult
  86530. * @static
  86531. * @param {p5.Vector} v
  86532. * @param {Number} n
  86533. * @param {p5.Vector} [target] the vector to receive the result
  86534. */
  86535. /**
  86536. * @method mult
  86537. * @static
  86538. * @param {p5.Vector} v0
  86539. * @param {p5.Vector} v1
  86540. * @param {p5.Vector} [target]
  86541. */
  86542. /**
  86543. * @method mult
  86544. * @static
  86545. * @param {p5.Vector} v0
  86546. * @param {Number[]} arr
  86547. * @param {p5.Vector} [target]
  86548. */
  86549. _main.default.Vector.mult = function mult(v, n, target) {
  86550. if (!target) {
  86551. target = v.copy();
  86552. if (arguments.length === 3) {
  86553. _main.default._friendlyError(
  86554. 'The target parameter is undefined, it should be of type p5.Vector',
  86555. 'p5.Vector.mult'
  86556. );
  86557. }
  86558. } else {
  86559. target.set(v);
  86560. }
  86561. target.mult(n);
  86562. return target;
  86563. };
  86564. /**
  86565. * Rotates the vector (only 2D vectors) by the given angle, magnitude remains the same and returns a new vector.
  86566. */
  86567. /**
  86568. * @method rotate
  86569. * @static
  86570. * @param {p5.Vector} v
  86571. * @param {Number} angle
  86572. * @param {p5.Vector} [target] the vector to receive the result
  86573. */
  86574. _main.default.Vector.rotate = function rotate(v, a, target) {
  86575. if (arguments.length === 2) {
  86576. target = v.copy();
  86577. } else {
  86578. if (!(target instanceof _main.default.Vector)) {
  86579. _main.default._friendlyError(
  86580. 'The target parameter should be of type p5.Vector',
  86581. 'p5.Vector.rotate'
  86582. );
  86583. }
  86584. target.set(v);
  86585. }
  86586. target.rotate(a);
  86587. return target;
  86588. };
  86589. /**
  86590. * Divides a vector by a scalar and returns a new vector.
  86591. */
  86592. /**
  86593. * @method div
  86594. * @static
  86595. * @param {Number} x
  86596. * @param {Number} y
  86597. * @param {Number} [z]
  86598. * @return {p5.Vector} The resulting new <a href="#/p5.Vector">p5.Vector</a>
  86599. */
  86600. /**
  86601. * @method div
  86602. * @static
  86603. * @param {p5.Vector} v
  86604. * @param {Number} n
  86605. * @param {p5.Vector} [target] the vector to receive the result
  86606. */
  86607. /**
  86608. * @method div
  86609. * @static
  86610. * @param {p5.Vector} v0
  86611. * @param {p5.Vector} v1
  86612. * @param {p5.Vector} [target]
  86613. */
  86614. /**
  86615. * @method div
  86616. * @static
  86617. * @param {p5.Vector} v0
  86618. * @param {Number[]} arr
  86619. * @param {p5.Vector} [target]
  86620. */
  86621. _main.default.Vector.div = function div(v, n, target) {
  86622. if (!target) {
  86623. target = v.copy();
  86624. if (arguments.length === 3) {
  86625. _main.default._friendlyError(
  86626. 'The target parameter is undefined, it should be of type p5.Vector',
  86627. 'p5.Vector.div'
  86628. );
  86629. }
  86630. } else {
  86631. target.set(v);
  86632. }
  86633. target.div(n);
  86634. return target;
  86635. };
  86636. /**
  86637. * Calculates the dot product of two vectors.
  86638. */
  86639. /**
  86640. * @method dot
  86641. * @static
  86642. * @param {p5.Vector} v1 the first <a href="#/p5.Vector">p5.Vector</a>
  86643. * @param {p5.Vector} v2 the second <a href="#/p5.Vector">p5.Vector</a>
  86644. * @return {Number} the dot product
  86645. */
  86646. _main.default.Vector.dot = function dot(v1, v2) {
  86647. return v1.dot(v2);
  86648. };
  86649. /**
  86650. * Calculates the cross product of two vectors.
  86651. */
  86652. /**
  86653. * @method cross
  86654. * @static
  86655. * @param {p5.Vector} v1 the first <a href="#/p5.Vector">p5.Vector</a>
  86656. * @param {p5.Vector} v2 the second <a href="#/p5.Vector">p5.Vector</a>
  86657. * @return {Number} the cross product
  86658. */
  86659. _main.default.Vector.cross = function cross(v1, v2) {
  86660. return v1.cross(v2);
  86661. };
  86662. /**
  86663. * Calculates the Euclidean distance between two points (considering a
  86664. * point as a vector object).
  86665. */
  86666. /**
  86667. * @method dist
  86668. * @static
  86669. * @param {p5.Vector} v1 the first <a href="#/p5.Vector">p5.Vector</a>
  86670. * @param {p5.Vector} v2 the second <a href="#/p5.Vector">p5.Vector</a>
  86671. * @return {Number} the distance
  86672. */
  86673. _main.default.Vector.dist = function dist(v1, v2) {
  86674. return v1.dist(v2);
  86675. };
  86676. /**
  86677. * Linear interpolate a vector to another vector and return the result as a
  86678. * new vector.
  86679. */
  86680. /**
  86681. * @method lerp
  86682. * @static
  86683. * @param {p5.Vector} v1
  86684. * @param {p5.Vector} v2
  86685. * @param {Number} amt
  86686. * @param {p5.Vector} [target] the vector to receive the result
  86687. * @return {p5.Vector} the lerped value
  86688. */
  86689. _main.default.Vector.lerp = function lerp(v1, v2, amt, target) {
  86690. if (!target) {
  86691. target = v1.copy();
  86692. if (arguments.length === 4) {
  86693. _main.default._friendlyError(
  86694. 'The target parameter is undefined, it should be of type p5.Vector',
  86695. 'p5.Vector.lerp'
  86696. );
  86697. }
  86698. } else {
  86699. target.set(v1);
  86700. }
  86701. target.lerp(v2, amt);
  86702. return target;
  86703. };
  86704. /**
  86705. * Calculates the magnitude (length) of the vector and returns the result as
  86706. * a float (this is simply the equation sqrt(x\*x + y\*y + z\*z).)
  86707. */
  86708. /**
  86709. * @method mag
  86710. * @static
  86711. * @param {p5.Vector} vecT the vector to return the magnitude of
  86712. * @return {Number} the magnitude of vecT
  86713. */
  86714. _main.default.Vector.mag = function mag(vecT) {
  86715. var x = vecT.x,
  86716. y = vecT.y,
  86717. z = vecT.z;
  86718. var magSq = x * x + y * y + z * z;
  86719. return Math.sqrt(magSq);
  86720. };
  86721. /**
  86722. * Normalize the vector to length 1 (make it a unit vector).
  86723. */
  86724. /**
  86725. * @method normalize
  86726. * @static
  86727. * @param {p5.Vector} v the vector to normalize
  86728. * @param {p5.Vector} [target] the vector to receive the result
  86729. * @return {p5.Vector} v normalized to a length of 1
  86730. */
  86731. _main.default.Vector.normalize = function normalize(v, target) {
  86732. if (arguments.length < 2) {
  86733. target = v.copy();
  86734. } else {
  86735. if (!(target instanceof _main.default.Vector)) {
  86736. _main.default._friendlyError(
  86737. 'The target parameter should be of type p5.Vector',
  86738. 'p5.Vector.normalize'
  86739. );
  86740. }
  86741. target.set(v);
  86742. }
  86743. return target.normalize();
  86744. };
  86745. var _default = _main.default.Vector;
  86746. exports.default = _default;
  86747. },
  86748. {
  86749. '../core/constants': 272,
  86750. '../core/main': 283,
  86751. 'core-js/modules/es.array.concat': 166,
  86752. 'core-js/modules/es.array.every': 167,
  86753. 'core-js/modules/es.array.slice': 178,
  86754. 'core-js/modules/es.array.some': 179,
  86755. 'core-js/modules/es.math.sign': 184,
  86756. 'core-js/modules/es.number.constructor': 185,
  86757. 'core-js/modules/es.number.is-finite': 186,
  86758. 'core-js/modules/es.object.to-string': 192,
  86759. 'core-js/modules/es.regexp.to-string': 197,
  86760. 'core-js/modules/es.string.sub': 207
  86761. }
  86762. ],
  86763. 317: [
  86764. function(_dereq_, module, exports) {
  86765. 'use strict';
  86766. Object.defineProperty(exports, '__esModule', { value: true });
  86767. exports.default = void 0;
  86768. var _main = _interopRequireDefault(_dereq_('../core/main'));
  86769. function _interopRequireDefault(obj) {
  86770. return obj && obj.__esModule ? obj : { default: obj };
  86771. } /** // variables used for random number generators
  86772. * @module Math
  86773. * @submodule Random
  86774. * @for p5
  86775. * @requires core
  86776. */
  86777. var randomStateProp = '_lcg_random_state'; // Set to values from http://en.wikipedia.org/wiki/Numerical_Recipes
  86778. // m is basically chosen to be large (as it is the max period)
  86779. // and for its relationships to a and c
  86780. var m = 4294967296; // a - 1 should be divisible by m's prime factors
  86781. var a = 1664525; // c and m should be co-prime
  86782. var c = 1013904223;
  86783. var y2 = 0;
  86784. // Linear Congruential Generator that stores its state at instance[stateProperty]
  86785. _main.default.prototype._lcg = function(stateProperty) {
  86786. // define the recurrence relationship
  86787. this[stateProperty] = (a * this[stateProperty] + c) % m;
  86788. // return a float in [0, 1)
  86789. // we've just used % m, so / m is always < 1
  86790. return this[stateProperty] / m;
  86791. };
  86792. _main.default.prototype._lcgSetSeed = function(stateProperty, val) {
  86793. // pick a random seed if val is undefined or null
  86794. // the >>> 0 casts the seed to an unsigned 32-bit integer
  86795. this[stateProperty] = (val == null ? Math.random() * m : val) >>> 0;
  86796. };
  86797. /**
  86798. * Sets the seed value for <a href="#/p5/random">random()</a>.
  86799. *
  86800. * By default, <a href="#/p5/random">random()</a> produces different results each time the program
  86801. * is run. Set the seed parameter to a constant to return the same
  86802. * pseudo-random numbers each time the software is run.
  86803. *
  86804. * @method randomSeed
  86805. * @param {Number} seed the seed value
  86806. * @example
  86807. * <div>
  86808. * <code>
  86809. * randomSeed(99);
  86810. * for (let i = 0; i < 100; i++) {
  86811. * let r = random(0, 255);
  86812. * stroke(r);
  86813. * line(i, 0, i, 100);
  86814. * }
  86815. * </code>
  86816. * </div>
  86817. *
  86818. * @alt
  86819. * many vertical lines drawn in white, black or grey.
  86820. */
  86821. _main.default.prototype.randomSeed = function(seed) {
  86822. this._lcgSetSeed(randomStateProp, seed);
  86823. this._gaussian_previous = false;
  86824. };
  86825. /**
  86826. * Return a random floating-point number.
  86827. *
  86828. * Takes either 0, 1 or 2 arguments.
  86829. *
  86830. * If no argument is given, returns a random number from 0
  86831. * up to (but not including) 1.
  86832. *
  86833. * If one argument is given and it is a number, returns a random number from 0
  86834. * up to (but not including) the number.
  86835. *
  86836. * If one argument is given and it is an array, returns a random element from
  86837. * that array.
  86838. *
  86839. * If two arguments are given, returns a random number from the
  86840. * first argument up to (but not including) the second argument.
  86841. *
  86842. * @method random
  86843. * @param {Number} [min] the lower bound (inclusive)
  86844. * @param {Number} [max] the upper bound (exclusive)
  86845. * @return {Number} the random number
  86846. * @example
  86847. * <div>
  86848. * <code>
  86849. * for (let i = 0; i < 100; i++) {
  86850. * let r = random(50);
  86851. * stroke(r * 5);
  86852. * line(50, i, 50 + r, i);
  86853. * }
  86854. * </code>
  86855. * </div>
  86856. * <div>
  86857. * <code>
  86858. * for (let i = 0; i < 100; i++) {
  86859. * let r = random(-50, 50);
  86860. * line(50, i, 50 + r, i);
  86861. * }
  86862. * </code>
  86863. * </div>
  86864. * <div>
  86865. * <code>
  86866. * // Get a random element from an array using the random(Array) syntax
  86867. * let words = ['apple', 'bear', 'cat', 'dog'];
  86868. * let word = random(words); // select random word
  86869. * text(word, 10, 50); // draw the word
  86870. * </code>
  86871. * </div>
  86872. *
  86873. * @alt
  86874. * 100 horizontal lines from center canvas to right. size+fill change each time
  86875. * 100 horizontal lines from center of canvas. height & side change each render
  86876. * word displayed at random. Either apple, bear, cat, or dog
  86877. */
  86878. /**
  86879. * @method random
  86880. * @param {Array} choices the array to choose from
  86881. * @return {*} the random element from the array
  86882. * @example
  86883. */
  86884. _main.default.prototype.random = function(min, max) {
  86885. _main.default._validateParameters('random', arguments);
  86886. var rand;
  86887. if (this[randomStateProp] != null) {
  86888. rand = this._lcg(randomStateProp);
  86889. } else {
  86890. rand = Math.random();
  86891. }
  86892. if (typeof min === 'undefined') {
  86893. return rand;
  86894. } else if (typeof max === 'undefined') {
  86895. if (min instanceof Array) {
  86896. return min[Math.floor(rand * min.length)];
  86897. } else {
  86898. return rand * min;
  86899. }
  86900. } else {
  86901. if (min > max) {
  86902. var tmp = min;
  86903. min = max;
  86904. max = tmp;
  86905. }
  86906. return rand * (max - min) + min;
  86907. }
  86908. };
  86909. /**
  86910. *
  86911. * Returns a random number fitting a Gaussian, or
  86912. * normal, distribution. There is theoretically no minimum or maximum
  86913. * value that <a href="#/p5/randomGaussian">randomGaussian()</a> might return. Rather, there is
  86914. * just a very low probability that values far from the mean will be
  86915. * returned; and a higher probability that numbers near the mean will
  86916. * be returned.
  86917. *
  86918. * Takes either 0, 1 or 2 arguments.<br>
  86919. * If no args, returns a mean of 0 and standard deviation of 1.<br>
  86920. * If one arg, that arg is the mean (standard deviation is 1).<br>
  86921. * If two args, first is mean, second is standard deviation.
  86922. *
  86923. * @method randomGaussian
  86924. * @param {Number} [mean] the mean
  86925. * @param {Number} [sd] the standard deviation
  86926. * @return {Number} the random number
  86927. * @example
  86928. * <div>
  86929. * <code>
  86930. * for (let y = 0; y < 100; y++) {
  86931. * let x = randomGaussian(50, 15);
  86932. * line(50, y, x, y);
  86933. * }
  86934. * </code>
  86935. * </div>
  86936. * <div>
  86937. * <code>
  86938. * let distribution = new Array(360);
  86939. *
  86940. * function setup() {
  86941. * createCanvas(100, 100);
  86942. * for (let i = 0; i < distribution.length; i++) {
  86943. * distribution[i] = floor(randomGaussian(0, 15));
  86944. * }
  86945. * }
  86946. *
  86947. * function draw() {
  86948. * background(204);
  86949. *
  86950. * translate(width / 2, width / 2);
  86951. *
  86952. * for (let i = 0; i < distribution.length; i++) {
  86953. * rotate(TWO_PI / distribution.length);
  86954. * stroke(0);
  86955. * let dist = abs(distribution[i]);
  86956. * line(0, 0, dist, 0);
  86957. * }
  86958. * }
  86959. * </code>
  86960. * </div>
  86961. * @alt
  86962. * 100 horizontal lines from center of canvas. height & side change each render
  86963. * black lines radiate from center of canvas. size determined each render
  86964. */
  86965. _main.default.prototype.randomGaussian = function(mean) {
  86966. var sd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  86967. var y1, x1, x2, w;
  86968. if (this._gaussian_previous) {
  86969. y1 = y2;
  86970. this._gaussian_previous = false;
  86971. } else {
  86972. do {
  86973. x1 = this.random(2) - 1;
  86974. x2 = this.random(2) - 1;
  86975. w = x1 * x1 + x2 * x2;
  86976. } while (w >= 1);
  86977. w = Math.sqrt(-2 * Math.log(w) / w);
  86978. y1 = x1 * w;
  86979. y2 = x2 * w;
  86980. this._gaussian_previous = true;
  86981. }
  86982. var m = mean || 0;
  86983. return y1 * sd + m;
  86984. };
  86985. var _default = _main.default;
  86986. exports.default = _default;
  86987. },
  86988. { '../core/main': 283 }
  86989. ],
  86990. 318: [
  86991. function(_dereq_, module, exports) {
  86992. 'use strict';
  86993. function _typeof(obj) {
  86994. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  86995. _typeof = function _typeof(obj) {
  86996. return typeof obj;
  86997. };
  86998. } else {
  86999. _typeof = function _typeof(obj) {
  87000. return obj &&
  87001. typeof Symbol === 'function' &&
  87002. obj.constructor === Symbol &&
  87003. obj !== Symbol.prototype
  87004. ? 'symbol'
  87005. : typeof obj;
  87006. };
  87007. }
  87008. return _typeof(obj);
  87009. }
  87010. Object.defineProperty(exports, '__esModule', { value: true });
  87011. exports.default = void 0;
  87012. var _main = _interopRequireDefault(_dereq_('../core/main'));
  87013. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  87014. function _getRequireWildcardCache() {
  87015. if (typeof WeakMap !== 'function') return null;
  87016. var cache = new WeakMap();
  87017. _getRequireWildcardCache = function _getRequireWildcardCache() {
  87018. return cache;
  87019. };
  87020. return cache;
  87021. }
  87022. function _interopRequireWildcard(obj) {
  87023. if (obj && obj.__esModule) {
  87024. return obj;
  87025. }
  87026. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  87027. return { default: obj };
  87028. }
  87029. var cache = _getRequireWildcardCache();
  87030. if (cache && cache.has(obj)) {
  87031. return cache.get(obj);
  87032. }
  87033. var newObj = {};
  87034. var hasPropertyDescriptor =
  87035. Object.defineProperty && Object.getOwnPropertyDescriptor;
  87036. for (var key in obj) {
  87037. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  87038. var desc = hasPropertyDescriptor
  87039. ? Object.getOwnPropertyDescriptor(obj, key)
  87040. : null;
  87041. if (desc && (desc.get || desc.set)) {
  87042. Object.defineProperty(newObj, key, desc);
  87043. } else {
  87044. newObj[key] = obj[key];
  87045. }
  87046. }
  87047. }
  87048. newObj.default = obj;
  87049. if (cache) {
  87050. cache.set(obj, newObj);
  87051. }
  87052. return newObj;
  87053. }
  87054. function _interopRequireDefault(obj) {
  87055. return obj && obj.__esModule ? obj : { default: obj };
  87056. }
  87057. /**
  87058. * @module Math
  87059. * @submodule Trigonometry
  87060. * @for p5
  87061. * @requires core
  87062. * @requires constants
  87063. */ /*
  87064. * all DEGREES/RADIANS conversion should be done in the p5 instance
  87065. * if possible, using the p5._toRadians(), p5._fromRadians() methods.
  87066. */ _main.default.prototype._angleMode =
  87067. constants.RADIANS;
  87068. /**
  87069. * The inverse of <a href="#/p5/cos">cos()</a>, returns the arc cosine of a value.
  87070. * This function expects the values in the range of -1 to 1 and values are returned in
  87071. * the range 0 to PI (3.1415927) if the angleMode is RADIANS or 0 to 180 if the
  87072. * angle mode is DEGREES.
  87073. *
  87074. * @method acos
  87075. * @param {Number} value the value whose arc cosine is to be returned
  87076. * @return {Number} the arc cosine of the given value
  87077. *
  87078. * @example
  87079. * <div class= “norender">
  87080. * <code>
  87081. * let a = PI;
  87082. * let c = cos(a);
  87083. * let ac = acos(c);
  87084. * // Prints: "3.1415927 : -1.0 : 3.1415927"
  87085. * print(a + ' : ' + c + ' : ' + ac);
  87086. * </code>
  87087. * </div>
  87088. *
  87089. * <div class= “norender">
  87090. * <code>
  87091. * let a = PI + PI / 4.0;
  87092. * let c = cos(a);
  87093. * let ac = acos(c);
  87094. * // Prints: "3.926991 : -0.70710665 : 2.3561943"
  87095. * print(a + ' : ' + c + ' : ' + ac);
  87096. * </code>
  87097. * </div>
  87098. */ _main.default.prototype.acos = function(ratio) {
  87099. return this._fromRadians(Math.acos(ratio));
  87100. };
  87101. /**
  87102. * The inverse of <a href="#/p5/sin">sin()</a>, returns the arc sine of a value.
  87103. * This function expects the values in the range of -1 to 1 and values are returned
  87104. * in the range -PI/2 to PI/2 if the angleMode is RADIANS or -90 to 90 if the angle
  87105. * mode is DEGREES.
  87106. *
  87107. * @method asin
  87108. * @param {Number} value the value whose arc sine is to be returned
  87109. * @return {Number} the arc sine of the given value
  87110. *
  87111. * @example
  87112. * <div class= “norender">
  87113. * <code>
  87114. * let a = PI / 3.0;
  87115. * let s = sin(a);
  87116. * let as = asin(s);
  87117. * // Prints: "1.0471975 : 0.86602540 : 1.0471975"
  87118. * print(a + ' : ' + s + ' : ' + as);
  87119. * </code>
  87120. * </div>
  87121. *
  87122. * <div class= “norender">
  87123. * <code>
  87124. * let a = PI + PI / 3.0;
  87125. * let s = sin(a);
  87126. * let as = asin(s);
  87127. * // Prints: "4.1887902 : -0.86602540 : -1.0471975"
  87128. * print(a + ' : ' + s + ' : ' + as);
  87129. * </code>
  87130. * </div>
  87131. */
  87132. _main.default.prototype.asin = function(ratio) {
  87133. return this._fromRadians(Math.asin(ratio));
  87134. };
  87135. /**
  87136. * The inverse of <a href="#/p5/tan">tan()</a>, returns the arc tangent of a value.
  87137. * This function expects the values in the range of -Infinity to Infinity (exclusive) and
  87138. * values are returned in the range -PI/2 to PI/2 if the angleMode is RADIANS or
  87139. * -90 to 90 if the angle mode is DEGREES.
  87140. *
  87141. * @method atan
  87142. * @param {Number} value the value whose arc tangent is to be returned
  87143. * @return {Number} the arc tangent of the given value
  87144. *
  87145. * @example
  87146. * <div class= “norender">
  87147. * <code>
  87148. * let a = PI / 3.0;
  87149. * let t = tan(a);
  87150. * let at = atan(t);
  87151. * // Prints: "1.0471975 : 1.7320508 : 1.0471975"
  87152. * print(a + ' : ' + t + ' : ' + at);
  87153. * </code>
  87154. * </div>
  87155. *
  87156. * <div class= “norender">
  87157. * <code>
  87158. * let a = PI + PI / 3.0;
  87159. * let t = tan(a);
  87160. * let at = atan(t);
  87161. * // Prints: "4.1887902 : 1.7320508 : 1.0471975"
  87162. * print(a + ' : ' + t + ' : ' + at);
  87163. * </code>
  87164. * </div>
  87165. */
  87166. _main.default.prototype.atan = function(ratio) {
  87167. return this._fromRadians(Math.atan(ratio));
  87168. };
  87169. /**
  87170. * Calculates the angle (in radians) from a specified point to the coordinate
  87171. * origin as measured from the positive x-axis. Values are returned as a
  87172. * float in the range from PI to -PI if the angleMode is RADIANS or 180 to
  87173. * -180 if the angleMode is DEGREES. The atan2<a href="#/p5/">()</a> function is
  87174. * most often used for orienting geometry to the position of the cursor.
  87175. *
  87176. * Note: The y-coordinate of the point is the first parameter, and the
  87177. * x-coordinate is the second parameter, due the the structure of calculating
  87178. * the tangent.
  87179. *
  87180. * @method atan2
  87181. * @param {Number} y y-coordinate of the point
  87182. * @param {Number} x x-coordinate of the point
  87183. * @return {Number} the arc tangent of the given point
  87184. *
  87185. * @example
  87186. * <div>
  87187. * <code>
  87188. * function draw() {
  87189. * background(204);
  87190. * translate(width / 2, height / 2);
  87191. * let a = atan2(mouseY - height / 2, mouseX - width / 2);
  87192. * rotate(a);
  87193. * rect(-30, -5, 60, 10);
  87194. * }
  87195. * </code>
  87196. * </div>
  87197. *
  87198. * @alt
  87199. * 60 by 10 rect at center of canvas rotates with mouse movements
  87200. */
  87201. _main.default.prototype.atan2 = function(y, x) {
  87202. return this._fromRadians(Math.atan2(y, x));
  87203. };
  87204. /**
  87205. * Calculates the cosine of an angle. This function takes into account the
  87206. * current <a href="#/p5/angleMode">angleMode</a>. Values are returned in the range -1 to 1.
  87207. *
  87208. * @method cos
  87209. * @param {Number} angle the angle
  87210. * @return {Number} the cosine of the angle
  87211. *
  87212. * @example
  87213. * <div>
  87214. * <code>
  87215. * let a = 0.0;
  87216. * let inc = TWO_PI / 25.0;
  87217. * for (let i = 0; i < 25; i++) {
  87218. * line(i * 4, 50, i * 4, 50 + cos(a) * 40.0);
  87219. * a = a + inc;
  87220. * }
  87221. * </code>
  87222. * </div>
  87223. *
  87224. * @alt
  87225. * vertical black lines form wave patterns, extend-down on left and right side
  87226. */
  87227. _main.default.prototype.cos = function(angle) {
  87228. return Math.cos(this._toRadians(angle));
  87229. };
  87230. /**
  87231. * Calculates the sine of an angle. This function takes into account the
  87232. * current <a href="#/p5/angleMode">angleMode</a>. Values are returned in the range -1 to 1.
  87233. *
  87234. * @method sin
  87235. * @param {Number} angle the angle
  87236. * @return {Number} the sine of the angle
  87237. *
  87238. * @example
  87239. * <div>
  87240. * <code>
  87241. * let a = 0.0;
  87242. * let inc = TWO_PI / 25.0;
  87243. * for (let i = 0; i < 25; i++) {
  87244. * line(i * 4, 50, i * 4, 50 + sin(a) * 40.0);
  87245. * a = a + inc;
  87246. * }
  87247. * </code>
  87248. * </div>
  87249. *
  87250. * @alt
  87251. * vertical black lines extend down and up from center to form wave pattern
  87252. */
  87253. _main.default.prototype.sin = function(angle) {
  87254. return Math.sin(this._toRadians(angle));
  87255. };
  87256. /**
  87257. * Calculates the tangent of an angle. This function takes into account
  87258. * the current <a href="#/p5/angleMode">angleMode</a>. Values are returned in the range of all real numbers.
  87259. *
  87260. * @method tan
  87261. * @param {Number} angle the angle
  87262. * @return {Number} the tangent of the angle
  87263. *
  87264. * @example
  87265. * <div>
  87266. * <code>
  87267. * let a = 0.0;
  87268. * let inc = TWO_PI / 50.0;
  87269. * for (let i = 0; i < 100; i = i + 2) {
  87270. * line(i, 50, i, 50 + tan(a) * 2.0);
  87271. * a = a + inc;
  87272. * }
  87273. * </code>
  87274. *
  87275. * @alt
  87276. * vertical black lines end down and up from center to form spike pattern
  87277. */
  87278. _main.default.prototype.tan = function(angle) {
  87279. return Math.tan(this._toRadians(angle));
  87280. };
  87281. /**
  87282. * Converts a radian measurement to its corresponding value in degrees.
  87283. * Radians and degrees are two ways of measuring the same thing. There are
  87284. * 360 degrees in a circle and 2*PI radians in a circle. For example,
  87285. * 90° = PI/2 = 1.5707964. This function does not take into account the
  87286. * current <a href="#/p5/angleMode">angleMode</a>.
  87287. *
  87288. * @method degrees
  87289. * @param {Number} radians the radians value to convert to degrees
  87290. * @return {Number} the converted angle
  87291. *
  87292. * @example
  87293. * <div class= “norender">
  87294. * <code>
  87295. * let rad = PI / 4;
  87296. * let deg = degrees(rad);
  87297. * print(rad + ' radians is ' + deg + ' degrees');
  87298. * // Prints: 0.7853981633974483 radians is 45 degrees
  87299. * </code>
  87300. * </div>
  87301. */
  87302. _main.default.prototype.degrees = function(angle) {
  87303. return angle * constants.RAD_TO_DEG;
  87304. };
  87305. /**
  87306. * Converts a degree measurement to its corresponding value in radians.
  87307. * Radians and degrees are two ways of measuring the same thing. There are
  87308. * 360 degrees in a circle and 2*PI radians in a circle. For example,
  87309. * 90° = PI/2 = 1.5707964. This function does not take into account the
  87310. * current <a href="#/p5/angleMode">angleMode</a>.
  87311. *
  87312. * @method radians
  87313. * @param {Number} degrees the degree value to convert to radians
  87314. * @return {Number} the converted angle
  87315. *
  87316. * @example
  87317. * <div class= “norender">
  87318. * <code>
  87319. * let deg = 45.0;
  87320. * let rad = radians(deg);
  87321. * print(deg + ' degrees is ' + rad + ' radians');
  87322. * // Prints: 45 degrees is 0.7853981633974483 radians
  87323. * </code>
  87324. * </div>
  87325. */
  87326. _main.default.prototype.radians = function(angle) {
  87327. return angle * constants.DEG_TO_RAD;
  87328. };
  87329. /**
  87330. * Sets the current mode of p5 to given mode. Default mode is RADIANS.
  87331. *
  87332. * @method angleMode
  87333. * @param {Constant} mode either RADIANS or DEGREES
  87334. *
  87335. * @example
  87336. * <div>
  87337. * <code>
  87338. * function draw() {
  87339. * background(204);
  87340. * angleMode(DEGREES); // Change the mode to DEGREES
  87341. * let a = atan2(mouseY - height / 2, mouseX - width / 2);
  87342. * translate(width / 2, height / 2);
  87343. * push();
  87344. * rotate(a);
  87345. * rect(-20, -5, 40, 10); // Larger rectangle is rotating in degrees
  87346. * pop();
  87347. * angleMode(RADIANS); // Change the mode to RADIANS
  87348. * rotate(a); // variable a stays the same
  87349. * rect(-40, -5, 20, 10); // Smaller rectangle is rotating in radians
  87350. * }
  87351. * </code>
  87352. * </div>
  87353. *
  87354. * @alt
  87355. * 40 by 10 rect in center rotates with mouse moves. 20 by 10 rect moves faster.
  87356. *
  87357. */
  87358. _main.default.prototype.angleMode = function(mode) {
  87359. if (mode === constants.DEGREES || mode === constants.RADIANS) {
  87360. this._angleMode = mode;
  87361. }
  87362. };
  87363. /**
  87364. * converts angles from the current angleMode to RADIANS
  87365. *
  87366. * @method _toRadians
  87367. * @private
  87368. * @param {Number} angle
  87369. * @returns {Number}
  87370. */
  87371. _main.default.prototype._toRadians = function(angle) {
  87372. if (this._angleMode === constants.DEGREES) {
  87373. return angle * constants.DEG_TO_RAD;
  87374. }
  87375. return angle;
  87376. };
  87377. /**
  87378. * converts angles from the current angleMode to DEGREES
  87379. *
  87380. * @method _toDegrees
  87381. * @private
  87382. * @param {Number} angle
  87383. * @returns {Number}
  87384. */
  87385. _main.default.prototype._toDegrees = function(angle) {
  87386. if (this._angleMode === constants.RADIANS) {
  87387. return angle * constants.RAD_TO_DEG;
  87388. }
  87389. return angle;
  87390. };
  87391. /**
  87392. * converts angles from RADIANS into the current angleMode
  87393. *
  87394. * @method _fromRadians
  87395. * @private
  87396. * @param {Number} angle
  87397. * @returns {Number}
  87398. */
  87399. _main.default.prototype._fromRadians = function(angle) {
  87400. if (this._angleMode === constants.DEGREES) {
  87401. return angle * constants.RAD_TO_DEG;
  87402. }
  87403. return angle;
  87404. };
  87405. var _default = _main.default;
  87406. exports.default = _default;
  87407. },
  87408. { '../core/constants': 272, '../core/main': 283 }
  87409. ],
  87410. 319: [
  87411. function(_dereq_, module, exports) {
  87412. 'use strict';
  87413. Object.defineProperty(exports, '__esModule', { value: true });
  87414. exports.default = void 0;
  87415. var _main = _interopRequireDefault(_dereq_('../core/main'));
  87416. function _interopRequireDefault(obj) {
  87417. return obj && obj.__esModule ? obj : { default: obj };
  87418. }
  87419. /**
  87420. * @module Typography
  87421. * @submodule Attributes
  87422. * @for p5
  87423. * @requires core
  87424. * @requires constants
  87425. */ /**
  87426. * Sets the current alignment for drawing text. Accepts two
  87427. * arguments: horizAlign (LEFT, CENTER, or RIGHT) and
  87428. * vertAlign (TOP, BOTTOM, CENTER, or BASELINE).
  87429. *
  87430. * The horizAlign parameter is in reference to the x value
  87431. * of the <a href="#/p5/text">text()</a> function, while the vertAlign parameter
  87432. * is in reference to the y value.
  87433. *
  87434. * So if you write textAlign(LEFT), you are aligning the left
  87435. * edge of your text to the x value you give in <a href="#/p5/text">text()</a>.
  87436. * If you write textAlign(RIGHT, TOP), you are aligning the right edge
  87437. * of your text to the x value and the top of edge of the text
  87438. * to the y value.
  87439. *
  87440. * @method textAlign
  87441. * @param {Constant} horizAlign horizontal alignment, either LEFT,
  87442. * CENTER, or RIGHT
  87443. * @param {Constant} [vertAlign] vertical alignment, either TOP,
  87444. * BOTTOM, CENTER, or BASELINE
  87445. * @chainable
  87446. * @example
  87447. * <div>
  87448. * <code>
  87449. * textSize(16);
  87450. * textAlign(RIGHT);
  87451. * text('ABCD', 50, 30);
  87452. * textAlign(CENTER);
  87453. * text('EFGH', 50, 50);
  87454. * textAlign(LEFT);
  87455. * text('IJKL', 50, 70);
  87456. * </code>
  87457. * </div>
  87458. *
  87459. * <div>
  87460. * <code>
  87461. * textSize(16);
  87462. * strokeWeight(0.5);
  87463. *
  87464. * line(0, 12, width, 12);
  87465. * textAlign(CENTER, TOP);
  87466. * text('TOP', 0, 12, width);
  87467. *
  87468. * line(0, 37, width, 37);
  87469. * textAlign(CENTER, CENTER);
  87470. * text('CENTER', 0, 37, width);
  87471. *
  87472. * line(0, 62, width, 62);
  87473. * textAlign(CENTER, BASELINE);
  87474. * text('BASELINE', 0, 62, width);
  87475. *
  87476. * line(0, 87, width, 87);
  87477. * textAlign(CENTER, BOTTOM);
  87478. * text('BOTTOM', 0, 87, width);
  87479. * </code>
  87480. * </div>
  87481. *
  87482. * @alt
  87483. * Letters ABCD displayed at top left, EFGH at center and IJKL at bottom right.
  87484. * The names of the four vertical alignments (TOP, CENTER, BASELINE & BOTTOM) rendered each showing that alignment's placement relative to a horizontal line.
  87485. */ /**
  87486. * @method textAlign
  87487. * @return {Object}
  87488. */ _main.default.prototype.textAlign = function(horizAlign, vertAlign) {
  87489. var _this$_renderer;
  87490. _main.default._validateParameters('textAlign', arguments);
  87491. return (_this$_renderer = this._renderer).textAlign.apply(
  87492. _this$_renderer,
  87493. arguments
  87494. );
  87495. };
  87496. /**
  87497. * Sets/gets the spacing, in pixels, between lines of text. This setting will be
  87498. * used in all subsequent calls to the <a href="#/p5/text">text()</a> function.
  87499. *
  87500. * @method textLeading
  87501. * @param {Number} leading the size in pixels for spacing between lines
  87502. * @chainable
  87503. *
  87504. * @example
  87505. * <div>
  87506. * <code>
  87507. * let lines = 'L1\nL2\nL3'; // "\n" is a "new line" character
  87508. * textSize(12);
  87509. *
  87510. * textLeading(10);
  87511. * text(lines, 10, 25);
  87512. *
  87513. * textLeading(20);
  87514. * text(lines, 40, 25);
  87515. *
  87516. * textLeading(30);
  87517. * text(lines, 70, 25);
  87518. * </code>
  87519. * </div>
  87520. *
  87521. * @alt
  87522. * A set of L1 L2 & L3 displayed vertically 3 times. spacing increases for each set
  87523. */
  87524. /**
  87525. * @method textLeading
  87526. * @return {Number}
  87527. */
  87528. _main.default.prototype.textLeading = function(theLeading) {
  87529. var _this$_renderer2;
  87530. _main.default._validateParameters('textLeading', arguments);
  87531. return (_this$_renderer2 = this._renderer).textLeading.apply(
  87532. _this$_renderer2,
  87533. arguments
  87534. );
  87535. };
  87536. /**
  87537. * Sets/gets the current font size. This size will be used in all subsequent
  87538. * calls to the <a href="#/p5/text">text()</a> function. Font size is measured in pixels.
  87539. *
  87540. * @method textSize
  87541. * @param {Number} theSize the size of the letters in units of pixels
  87542. * @chainable
  87543. *
  87544. * @example
  87545. * <div>
  87546. * <code>
  87547. * textSize(12);
  87548. * text('Font Size 12', 10, 30);
  87549. * textSize(14);
  87550. * text('Font Size 14', 10, 60);
  87551. * textSize(16);
  87552. * text('Font Size 16', 10, 90);
  87553. * </code>
  87554. * </div>
  87555. *
  87556. * @alt
  87557. * 'Font Size 12' displayed small, 'Font Size 14' medium & 'Font Size 16' large
  87558. */
  87559. /**
  87560. * @method textSize
  87561. * @return {Number}
  87562. */
  87563. _main.default.prototype.textSize = function(theSize) {
  87564. var _this$_renderer3;
  87565. _main.default._validateParameters('textSize', arguments);
  87566. return (_this$_renderer3 = this._renderer).textSize.apply(
  87567. _this$_renderer3,
  87568. arguments
  87569. );
  87570. };
  87571. /**
  87572. * Sets/gets the style of the text for system fonts to NORMAL, ITALIC, BOLD or BOLDITALIC.
  87573. * Note: this may be is overridden by CSS styling. For non-system fonts
  87574. * (opentype, truetype, etc.) please load styled fonts instead.
  87575. *
  87576. * @method textStyle
  87577. * @param {Constant} theStyle styling for text, either NORMAL,
  87578. * ITALIC, BOLD or BOLDITALIC
  87579. * @chainable
  87580. * @example
  87581. * <div>
  87582. * <code>
  87583. * strokeWeight(0);
  87584. * textSize(12);
  87585. * textStyle(NORMAL);
  87586. * text('Font Style Normal', 10, 15);
  87587. * textStyle(ITALIC);
  87588. * text('Font Style Italic', 10, 40);
  87589. * textStyle(BOLD);
  87590. * text('Font Style Bold', 10, 65);
  87591. * textStyle(BOLDITALIC);
  87592. * text('Font Style Bold Italic', 10, 90);
  87593. * </code>
  87594. * </div>
  87595. *
  87596. * @alt
  87597. * Words Font Style Normal displayed normally, Italic in italic, bold in bold and bold italic in bold italics.
  87598. */
  87599. /**
  87600. * @method textStyle
  87601. * @return {String}
  87602. */
  87603. _main.default.prototype.textStyle = function(theStyle) {
  87604. var _this$_renderer4;
  87605. _main.default._validateParameters('textStyle', arguments);
  87606. return (_this$_renderer4 = this._renderer).textStyle.apply(
  87607. _this$_renderer4,
  87608. arguments
  87609. );
  87610. };
  87611. /**
  87612. * Calculates and returns the width of any character or text string.
  87613. *
  87614. * @method textWidth
  87615. * @param {String} theText the String of characters to measure
  87616. * @return {Number} the calculated width
  87617. * @example
  87618. * <div>
  87619. * <code>
  87620. * textSize(28);
  87621. *
  87622. * let aChar = 'P';
  87623. * let cWidth = textWidth(aChar);
  87624. * text(aChar, 0, 40);
  87625. * line(cWidth, 0, cWidth, 50);
  87626. *
  87627. * let aString = 'p5.js';
  87628. * let sWidth = textWidth(aString);
  87629. * text(aString, 0, 85);
  87630. * line(sWidth, 50, sWidth, 100);
  87631. * </code>
  87632. * </div>
  87633. *
  87634. * @alt
  87635. * Letter P and p5.js are displayed with vertical lines at end.
  87636. */
  87637. _main.default.prototype.textWidth = function() {
  87638. var _this$_renderer5;
  87639. for (
  87640. var _len = arguments.length, args = new Array(_len), _key = 0;
  87641. _key < _len;
  87642. _key++
  87643. ) {
  87644. args[_key] = arguments[_key];
  87645. }
  87646. args[0] += '';
  87647. _main.default._validateParameters('textWidth', args);
  87648. if (args[0].length === 0) {
  87649. return 0;
  87650. }
  87651. return (_this$_renderer5 = this._renderer).textWidth.apply(
  87652. _this$_renderer5,
  87653. args
  87654. );
  87655. };
  87656. /**
  87657. * Returns the ascent of the current font at its current size. The ascent
  87658. * represents the distance, in pixels, of the tallest character above
  87659. * the baseline.
  87660. * @method textAscent
  87661. * @return {Number}
  87662. * @example
  87663. * <div>
  87664. * <code>
  87665. * let base = height * 0.75;
  87666. * let scalar = 0.8; // Different for each font
  87667. *
  87668. * textSize(32); // Set initial text size
  87669. * let asc = textAscent() * scalar; // Calc ascent
  87670. * line(0, base - asc, width, base - asc);
  87671. * text('dp', 0, base); // Draw text on baseline
  87672. *
  87673. * textSize(64); // Increase text size
  87674. * asc = textAscent() * scalar; // Recalc ascent
  87675. * line(40, base - asc, width, base - asc);
  87676. * text('dp', 40, base); // Draw text on baseline
  87677. * </code>
  87678. * </div>
  87679. */
  87680. _main.default.prototype.textAscent = function() {
  87681. for (
  87682. var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
  87683. _key2 < _len2;
  87684. _key2++
  87685. ) {
  87686. args[_key2] = arguments[_key2];
  87687. }
  87688. _main.default._validateParameters('textAscent', args);
  87689. return this._renderer.textAscent();
  87690. };
  87691. /**
  87692. * Returns the descent of the current font at its current size. The descent
  87693. * represents the distance, in pixels, of the character with the longest
  87694. * descender below the baseline.
  87695. * @method textDescent
  87696. * @return {Number}
  87697. * @example
  87698. * <div>
  87699. * <code>
  87700. * let base = height * 0.75;
  87701. * let scalar = 0.8; // Different for each font
  87702. *
  87703. * textSize(32); // Set initial text size
  87704. * let desc = textDescent() * scalar; // Calc descent
  87705. * line(0, base + desc, width, base + desc);
  87706. * text('dp', 0, base); // Draw text on baseline
  87707. *
  87708. * textSize(64); // Increase text size
  87709. * desc = textDescent() * scalar; // Recalc descent
  87710. * line(40, base + desc, width, base + desc);
  87711. * text('dp', 40, base); // Draw text on baseline
  87712. * </code>
  87713. * </div>
  87714. */
  87715. _main.default.prototype.textDescent = function() {
  87716. for (
  87717. var _len3 = arguments.length, args = new Array(_len3), _key3 = 0;
  87718. _key3 < _len3;
  87719. _key3++
  87720. ) {
  87721. args[_key3] = arguments[_key3];
  87722. }
  87723. _main.default._validateParameters('textDescent', args);
  87724. return this._renderer.textDescent();
  87725. };
  87726. /**
  87727. * Helper function to measure ascent and descent.
  87728. */
  87729. _main.default.prototype._updateTextMetrics = function() {
  87730. return this._renderer._updateTextMetrics();
  87731. };
  87732. /**
  87733. * Specifies how lines of text are wrapped within a text box. This requires a max-width set on the text area, specified in <a href="#/p5/text">text()</a> as parameter `x2`.
  87734. *
  87735. * WORD wrap style only breaks lines at spaces. A single string without spaces that exceeds the boundaries of the canvas or text area is not truncated, and will overflow the desired area, disappearing at the canvas edge.
  87736. *
  87737. * CHAR wrap style breaks lines wherever needed to stay within the text box.
  87738. *
  87739. * WORD is the default wrap style, and both styles will still break lines at any line breaks (`\n`) specified in the original text. The text area max-height parameter (`y2`) also still applies to wrapped text in both styles, lines of text that do not fit within the text area will not be drawn to the screen.
  87740. *
  87741. * @method textWrap
  87742. * @param {Constant} wrapStyle text wrapping style, either WORD or CHAR
  87743. * @return {String} wrapStyle
  87744. * @example
  87745. * <div>
  87746. * <code>
  87747. * textSize(20);
  87748. * textWrap(WORD);
  87749. * text('Have a wonderful day', 0, 10, 100);
  87750. * </code>
  87751. * </div>
  87752. * <div>
  87753. * <code>
  87754. * textSize(20);
  87755. * textWrap(CHAR);
  87756. * text('Have a wonderful day', 0, 10, 100);
  87757. * </code>
  87758. * </div>
  87759. * <div>
  87760. * <code>
  87761. * textSize(20);
  87762. * textWrap(CHAR);
  87763. * text('祝你有美好的一天', 0, 10, 100);
  87764. * </code>
  87765. * </div>
  87766. * <div>
  87767. * <code>
  87768. * const scream = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
  87769. * textSize(20);
  87770. * textWrap(WORD);
  87771. * text(scream, 0, 0, 100);
  87772. * fill(0, 0, 0, 75);
  87773. * text(scream, 0, 20, 100);
  87774. * fill(0, 0, 0, 50);
  87775. * text(scream, 0, 40, 100);
  87776. * fill(0, 0, 0, 25);
  87777. * text(scream, 0, 60, 100);
  87778. * strokeWeight(2);
  87779. * ellipseMode(CENTER);
  87780. * fill(255);
  87781. * ellipse(15, 50, 15, 15);
  87782. * fill(0);
  87783. * ellipse(11, 47, 1, 1);
  87784. * ellipse(19, 47, 1, 1);
  87785. * ellipse(15, 52, 5, 5);
  87786. * line(15, 60, 15, 70);
  87787. * line(15, 65, 5, 55);
  87788. * line(15, 65, 25, 55);
  87789. * line(15, 70, 10, 80);
  87790. * line(15, 70, 20, 80);
  87791. * </code>
  87792. * </div>
  87793. */
  87794. _main.default.prototype.textWrap = function(wrapStyle) {
  87795. if (wrapStyle !== 'WORD' && wrapStyle !== 'CHAR') {
  87796. throw 'Error: textWrap accepts only WORD or CHAR';
  87797. }
  87798. return this._renderer.textWrap(wrapStyle);
  87799. };
  87800. var _default = _main.default;
  87801. exports.default = _default;
  87802. },
  87803. { '../core/main': 283 }
  87804. ],
  87805. 320: [
  87806. function(_dereq_, module, exports) {
  87807. 'use strict';
  87808. function _typeof(obj) {
  87809. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  87810. _typeof = function _typeof(obj) {
  87811. return typeof obj;
  87812. };
  87813. } else {
  87814. _typeof = function _typeof(obj) {
  87815. return obj &&
  87816. typeof Symbol === 'function' &&
  87817. obj.constructor === Symbol &&
  87818. obj !== Symbol.prototype
  87819. ? 'symbol'
  87820. : typeof obj;
  87821. };
  87822. }
  87823. return _typeof(obj);
  87824. }
  87825. _dereq_('core-js/modules/es.array.concat');
  87826. _dereq_('core-js/modules/es.array.includes');
  87827. _dereq_('core-js/modules/es.array.last-index-of');
  87828. _dereq_('core-js/modules/es.regexp.exec');
  87829. _dereq_('core-js/modules/es.string.split');
  87830. Object.defineProperty(exports, '__esModule', { value: true });
  87831. exports.default = void 0;
  87832. var _main = _interopRequireDefault(_dereq_('../core/main'));
  87833. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  87834. var opentype = _interopRequireWildcard(_dereq_('opentype.js'));
  87835. _dereq_('../core/friendly_errors/validate_params');
  87836. _dereq_('../core/friendly_errors/file_errors');
  87837. _dereq_('../core/friendly_errors/fes_core');
  87838. function _getRequireWildcardCache() {
  87839. if (typeof WeakMap !== 'function') return null;
  87840. var cache = new WeakMap();
  87841. _getRequireWildcardCache = function _getRequireWildcardCache() {
  87842. return cache;
  87843. };
  87844. return cache;
  87845. }
  87846. function _interopRequireWildcard(obj) {
  87847. if (obj && obj.__esModule) {
  87848. return obj;
  87849. }
  87850. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  87851. return { default: obj };
  87852. }
  87853. var cache = _getRequireWildcardCache();
  87854. if (cache && cache.has(obj)) {
  87855. return cache.get(obj);
  87856. }
  87857. var newObj = {};
  87858. var hasPropertyDescriptor =
  87859. Object.defineProperty && Object.getOwnPropertyDescriptor;
  87860. for (var key in obj) {
  87861. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  87862. var desc = hasPropertyDescriptor
  87863. ? Object.getOwnPropertyDescriptor(obj, key)
  87864. : null;
  87865. if (desc && (desc.get || desc.set)) {
  87866. Object.defineProperty(newObj, key, desc);
  87867. } else {
  87868. newObj[key] = obj[key];
  87869. }
  87870. }
  87871. }
  87872. newObj.default = obj;
  87873. if (cache) {
  87874. cache.set(obj, newObj);
  87875. }
  87876. return newObj;
  87877. }
  87878. function _interopRequireDefault(obj) {
  87879. return obj && obj.__esModule ? obj : { default: obj };
  87880. }
  87881. /**
  87882. * @module Typography
  87883. * @submodule Loading & Displaying
  87884. * @for p5
  87885. * @requires core
  87886. */ /**
  87887. * Loads an opentype font file (.otf, .ttf) from a file or a URL,
  87888. * and returns a PFont Object. This method is asynchronous,
  87889. * meaning it may not finish before the next line in your sketch
  87890. * is executed.
  87891. *
  87892. * The path to the font should be relative to the HTML file
  87893. * that links in your sketch. Loading fonts from a URL or other
  87894. * remote location may be blocked due to your browser's built-in
  87895. * security.
  87896. *
  87897. * @method loadFont
  87898. * @param {String} path name of the file or url to load
  87899. * @param {Function} [callback] function to be executed after
  87900. * <a href="#/p5/loadFont">loadFont()</a> completes
  87901. * @param {Function} [onError] function to be executed if
  87902. * an error occurs
  87903. * @return {p5.Font} <a href="#/p5.Font">p5.Font</a> object
  87904. * @example
  87905. *
  87906. * Calling loadFont() inside <a href="#/p5/preload">preload()</a> guarantees
  87907. * that the load operation will have completed before <a href="#/p5/setup">setup()</a>
  87908. * and <a href="#/p5/draw">draw()</a> are called.
  87909. *
  87910. * <div><code>
  87911. * let myFont;
  87912. * function preload() {
  87913. * myFont = loadFont('assets/inconsolata.otf');
  87914. * }
  87915. *
  87916. * function setup() {
  87917. * fill('#ED225D');
  87918. * textFont(myFont);
  87919. * textSize(36);
  87920. * text('p5*js', 10, 50);
  87921. * }
  87922. * </code></div>
  87923. *
  87924. * Outside of <a href="#/p5/preload">preload()</a>, you may supply a
  87925. * callback function to handle the object:
  87926. *
  87927. * <div><code>
  87928. * function setup() {
  87929. * loadFont('assets/inconsolata.otf', drawText);
  87930. * }
  87931. *
  87932. * function drawText(font) {
  87933. * fill('#ED225D');
  87934. * textFont(font, 36);
  87935. * text('p5*js', 10, 50);
  87936. * }
  87937. * </code></div>
  87938. *
  87939. * You can also use the font filename string (without the file extension) to
  87940. * style other HTML elements.
  87941. *
  87942. * <div><code>
  87943. * function preload() {
  87944. * loadFont('assets/inconsolata.otf');
  87945. * }
  87946. *
  87947. * function setup() {
  87948. * let myDiv = createDiv('hello there');
  87949. * myDiv.style('font-family', 'Inconsolata');
  87950. * }
  87951. * </code></div>
  87952. *
  87953. * @alt
  87954. * p5*js in p5's theme dark pink
  87955. * p5*js in p5's theme dark pink
  87956. */ _main.default.prototype.loadFont = function(path, onSuccess, onError) {
  87957. _main.default._validateParameters('loadFont', arguments);
  87958. var p5Font = new _main.default.Font(this);
  87959. var self = this;
  87960. opentype.load(path, function(err, font) {
  87961. if (err) {
  87962. _main.default._friendlyFileLoadError(4, path);
  87963. if (typeof onError !== 'undefined') {
  87964. return onError(err);
  87965. }
  87966. console.error(err, path);
  87967. return;
  87968. }
  87969. p5Font.font = font;
  87970. if (typeof onSuccess !== 'undefined') {
  87971. onSuccess(p5Font);
  87972. }
  87973. self._decrementPreload();
  87974. // check that we have an acceptable font type
  87975. var validFontTypes = ['ttf', 'otf', 'woff', 'woff2'];
  87976. var fileNoPath = path
  87977. .split('\\')
  87978. .pop()
  87979. .split('/')
  87980. .pop();
  87981. var lastDotIdx = fileNoPath.lastIndexOf('.');
  87982. var fontFamily;
  87983. var newStyle;
  87984. var fileExt = lastDotIdx < 1 ? null : fileNoPath.substr(lastDotIdx + 1);
  87985. // if so, add it to the DOM (name-only) for use with DOM module
  87986. if (validFontTypes.includes(fileExt)) {
  87987. fontFamily = fileNoPath.substr(0, lastDotIdx);
  87988. newStyle = document.createElement('style');
  87989. newStyle.appendChild(
  87990. document.createTextNode(
  87991. '\n@font-face {\nfont-family: '
  87992. .concat(fontFamily, ';\nsrc: url(')
  87993. .concat(path, ');\n}\n')
  87994. )
  87995. );
  87996. document.head.appendChild(newStyle);
  87997. }
  87998. });
  87999. return p5Font;
  88000. };
  88001. /**
  88002. * Draws text to the screen. Displays the information specified in the first
  88003. * parameter on the screen in the position specified by the additional
  88004. * parameters. A default font will be used unless a font is set with the
  88005. * <a href="#/p5/textFont">textFont()</a> function and a default size will be
  88006. * used unless a font is set with <a href="#/p5/textSize">textSize()</a>. Change
  88007. * the color of the text with the <a href="#/p5/fill">fill()</a> function. Change
  88008. * the outline of the text with the <a href="#/p5/stroke">stroke()</a> and
  88009. * <a href="#/p5/strokeWeight">strokeWeight()</a> functions.
  88010. *
  88011. * The text displays in relation to the <a href="#/p5/textAlign">textAlign()</a>
  88012. * function, which gives the option to draw to the left, right, and center of the
  88013. * coordinates.
  88014. *
  88015. * The x2 and y2 parameters define a rectangular area to display within and
  88016. * may only be used with string data. When these parameters are specified,
  88017. * they are interpreted based on the current <a href="#/p5/rectMode">rectMode()</a>
  88018. * setting. Text that does not fit completely within the rectangle specified will
  88019. * not be drawn to the screen. If x2 and y2 are not specified, the baseline
  88020. * alignment is the default, which means that the text will be drawn upwards
  88021. * from x and y.
  88022. *
  88023. * <b>WEBGL</b>: Only opentype/truetype fonts are supported. You must load a font
  88024. * using the <a href="#/p5/loadFont">loadFont()</a> method (see the example above).
  88025. * <a href="#/p5/stroke">stroke()</a> currently has no effect in webgl mode.
  88026. *
  88027. * @method text
  88028. * @param {String|Object|Array|Number|Boolean} str the alphanumeric
  88029. * symbols to be displayed
  88030. * @param {Number} x x-coordinate of text
  88031. * @param {Number} y y-coordinate of text
  88032. * @param {Number} [x2] by default, the width of the text box,
  88033. * see <a href="#/p5/rectMode">rectMode()</a> for more info
  88034. * @param {Number} [y2] by default, the height of the text box,
  88035. * see <a href="#/p5/rectMode">rectMode()</a> for more info
  88036. * @chainable
  88037. * @example
  88038. * <div>
  88039. * <code>
  88040. * textSize(32);
  88041. * text('word', 10, 30);
  88042. * fill(0, 102, 153);
  88043. * text('word', 10, 60);
  88044. * fill(0, 102, 153, 51);
  88045. * text('word', 10, 90);
  88046. * </code>
  88047. * </div>
  88048. * <div>
  88049. * <code>
  88050. * let s = 'The quick brown fox jumped over the lazy dog.';
  88051. * fill(50);
  88052. * text(s, 10, 10, 70, 80); // Text wraps within text box
  88053. * </code>
  88054. * </div>
  88055. *
  88056. * <div modernizr='webgl'>
  88057. * <code>
  88058. * let inconsolata;
  88059. * function preload() {
  88060. * inconsolata = loadFont('assets/inconsolata.otf');
  88061. * }
  88062. * function setup() {
  88063. * createCanvas(100, 100, WEBGL);
  88064. * textFont(inconsolata);
  88065. * textSize(width / 3);
  88066. * textAlign(CENTER, CENTER);
  88067. * }
  88068. * function draw() {
  88069. * background(0);
  88070. * let time = millis();
  88071. * rotateX(time / 1000);
  88072. * rotateZ(time / 1234);
  88073. * text('p5.js', 0, 0);
  88074. * }
  88075. * </code>
  88076. * </div>
  88077. *
  88078. * @alt
  88079. * 'word' displayed 3 times going from black, blue to translucent blue
  88080. * The text 'The quick brown fox jumped over the lazy dog' displayed.
  88081. * The text 'p5.js' spinning in 3d
  88082. */
  88083. _main.default.prototype.text = function(str, x, y, maxWidth, maxHeight) {
  88084. var _this$_renderer;
  88085. _main.default._validateParameters('text', arguments);
  88086. return !(this._renderer._doFill || this._renderer._doStroke)
  88087. ? this
  88088. : (_this$_renderer = this._renderer).text.apply(_this$_renderer, arguments);
  88089. };
  88090. /**
  88091. * Sets the current font that will be drawn with the <a href="#/p5/text">text()</a> function.
  88092. * If textFont() is called without any argument, it will return the current font if one has
  88093. * been set already. If not, it will return the name of the default font as a string.
  88094. * If textFont() is called with a font to use, it will return the p5 object.
  88095. *
  88096. * <b>WEBGL</b>: Only fonts loaded via <a href="#/p5/loadFont">loadFont()</a> are supported.
  88097. *
  88098. * @method textFont
  88099. * @return {Object} the current font / p5 Object
  88100. *
  88101. * @example
  88102. * <div>
  88103. * <code>
  88104. * fill(0);
  88105. * textSize(12);
  88106. * textFont('Georgia');
  88107. * text('Georgia', 12, 30);
  88108. * textFont('Helvetica');
  88109. * text('Helvetica', 12, 60);
  88110. * </code>
  88111. * </div>
  88112. * <div>
  88113. * <code>
  88114. * let fontRegular, fontItalic, fontBold;
  88115. * function preload() {
  88116. * fontRegular = loadFont('assets/Regular.otf');
  88117. * fontItalic = loadFont('assets/Italic.ttf');
  88118. * fontBold = loadFont('assets/Bold.ttf');
  88119. * }
  88120. * function setup() {
  88121. * background(210);
  88122. * fill(0)
  88123. .strokeWeight(0)
  88124. .textSize(10);
  88125. * textFont(fontRegular);
  88126. * text('Font Style Normal', 10, 30);
  88127. * textFont(fontItalic);
  88128. * text('Font Style Italic', 10, 50);
  88129. * textFont(fontBold);
  88130. * text('Font Style Bold', 10, 70);
  88131. * }
  88132. * </code>
  88133. * </div>
  88134. *
  88135. * @alt
  88136. * word 'Georgia' displayed in font Georgia and 'Helvetica' in font Helvetica
  88137. * words Font Style Normal displayed normally, Italic in italic and bold in bold
  88138. */
  88139. /**
  88140. * @method textFont
  88141. * @param {Object|String} font a font loaded via <a href="#/p5/loadFont">loadFont()</a>,
  88142. * or a String representing a <a href="https://mzl.la/2dOw8WD">web safe font</a>
  88143. * (a font that is generally available across all systems)
  88144. * @param {Number} [size] the font size to use
  88145. * @chainable
  88146. */
  88147. _main.default.prototype.textFont = function(theFont, theSize) {
  88148. _main.default._validateParameters('textFont', arguments);
  88149. if (arguments.length) {
  88150. if (!theFont) {
  88151. throw new Error('null font passed to textFont');
  88152. }
  88153. this._renderer._setProperty('_textFont', theFont);
  88154. if (theSize) {
  88155. this._renderer._setProperty('_textSize', theSize);
  88156. if (!this._renderer._leadingSet) {
  88157. // only use a default value if not previously set (#5181)
  88158. this._renderer._setProperty(
  88159. '_textLeading',
  88160. theSize * constants._DEFAULT_LEADMULT
  88161. );
  88162. }
  88163. }
  88164. return this._renderer._applyTextProperties();
  88165. }
  88166. return this._renderer._textFont;
  88167. };
  88168. var _default = _main.default;
  88169. exports.default = _default;
  88170. },
  88171. {
  88172. '../core/constants': 272,
  88173. '../core/friendly_errors/fes_core': 275,
  88174. '../core/friendly_errors/file_errors': 276,
  88175. '../core/friendly_errors/validate_params': 278,
  88176. '../core/main': 283,
  88177. 'core-js/modules/es.array.concat': 166,
  88178. 'core-js/modules/es.array.includes': 172,
  88179. 'core-js/modules/es.array.last-index-of': 176,
  88180. 'core-js/modules/es.regexp.exec': 196,
  88181. 'core-js/modules/es.string.split': 206,
  88182. 'opentype.js': 258
  88183. }
  88184. ],
  88185. 321: [
  88186. function(_dereq_, module, exports) {
  88187. 'use strict';
  88188. _dereq_('core-js/modules/es.symbol');
  88189. _dereq_('core-js/modules/es.symbol.description');
  88190. _dereq_('core-js/modules/es.symbol.iterator');
  88191. _dereq_('core-js/modules/es.array.concat');
  88192. _dereq_('core-js/modules/es.array.fill');
  88193. _dereq_('core-js/modules/es.array.iterator');
  88194. _dereq_('core-js/modules/es.array.join');
  88195. _dereq_('core-js/modules/es.array.slice');
  88196. _dereq_('core-js/modules/es.array.splice');
  88197. _dereq_('core-js/modules/es.function.name');
  88198. _dereq_('core-js/modules/es.number.to-fixed');
  88199. _dereq_('core-js/modules/es.object.to-string');
  88200. _dereq_('core-js/modules/es.regexp.exec');
  88201. _dereq_('core-js/modules/es.string.iterator');
  88202. _dereq_('core-js/modules/es.string.split');
  88203. _dereq_('core-js/modules/web.dom-collections.iterator');
  88204. Object.defineProperty(exports, '__esModule', { value: true });
  88205. exports.default = void 0;
  88206. var _main = _interopRequireDefault(_dereq_('../core/main'));
  88207. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  88208. function _getRequireWildcardCache() {
  88209. if (typeof WeakMap !== 'function') return null;
  88210. var cache = new WeakMap();
  88211. _getRequireWildcardCache = function _getRequireWildcardCache() {
  88212. return cache;
  88213. };
  88214. return cache;
  88215. }
  88216. function _interopRequireWildcard(obj) {
  88217. if (obj && obj.__esModule) {
  88218. return obj;
  88219. }
  88220. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  88221. return { default: obj };
  88222. }
  88223. var cache = _getRequireWildcardCache();
  88224. if (cache && cache.has(obj)) {
  88225. return cache.get(obj);
  88226. }
  88227. var newObj = {};
  88228. var hasPropertyDescriptor =
  88229. Object.defineProperty && Object.getOwnPropertyDescriptor;
  88230. for (var key in obj) {
  88231. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  88232. var desc = hasPropertyDescriptor
  88233. ? Object.getOwnPropertyDescriptor(obj, key)
  88234. : null;
  88235. if (desc && (desc.get || desc.set)) {
  88236. Object.defineProperty(newObj, key, desc);
  88237. } else {
  88238. newObj[key] = obj[key];
  88239. }
  88240. }
  88241. }
  88242. newObj.default = obj;
  88243. if (cache) {
  88244. cache.set(obj, newObj);
  88245. }
  88246. return newObj;
  88247. }
  88248. function _interopRequireDefault(obj) {
  88249. return obj && obj.__esModule ? obj : { default: obj };
  88250. }
  88251. function _typeof(obj) {
  88252. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  88253. _typeof = function _typeof(obj) {
  88254. return typeof obj;
  88255. };
  88256. } else {
  88257. _typeof = function _typeof(obj) {
  88258. return obj &&
  88259. typeof Symbol === 'function' &&
  88260. obj.constructor === Symbol &&
  88261. obj !== Symbol.prototype
  88262. ? 'symbol'
  88263. : typeof obj;
  88264. };
  88265. }
  88266. return _typeof(obj);
  88267. }
  88268. /**
  88269. * Base class for font handling
  88270. * @class p5.Font
  88271. * @constructor
  88272. * @param {p5} [pInst] pointer to p5 instance
  88273. */
  88274. _main.default.Font = function(p) {
  88275. this.parent = p;
  88276. this.cache = {};
  88277. /**
  88278. * Underlying opentype font implementation
  88279. * @property font
  88280. */
  88281. this.font = undefined;
  88282. };
  88283. /**
  88284. * Returns a tight bounding box for the given text string using this
  88285. * font
  88286. *
  88287. * @method textBounds
  88288. * @param {String} line a line of text
  88289. * @param {Number} x x-position
  88290. * @param {Number} y y-position
  88291. * @param {Number} [fontSize] font size to use (optional) Default is 12.
  88292. * @param {Object} [options] opentype options (optional)
  88293. * opentype fonts contains alignment and baseline options.
  88294. * Default is 'LEFT' and 'alphabetic'
  88295. *
  88296. * @return {Object} a rectangle object with properties: x, y, w, h
  88297. *
  88298. * @example
  88299. * <div>
  88300. * <code>
  88301. * let font;
  88302. * let textString = 'Lorem ipsum dolor sit amet.';
  88303. * function preload() {
  88304. * font = loadFont('./assets/Regular.otf');
  88305. * }
  88306. * function setup() {
  88307. * background(210);
  88308. *
  88309. * let bbox = font.textBounds(textString, 10, 30, 12);
  88310. * fill(255);
  88311. * stroke(0);
  88312. * rect(bbox.x, bbox.y, bbox.w, bbox.h);
  88313. * fill(0);
  88314. * noStroke();
  88315. *
  88316. * textFont(font);
  88317. * textSize(12);
  88318. * text(textString, 10, 30);
  88319. * }
  88320. * </code>
  88321. * </div>
  88322. *
  88323. * @alt
  88324. *words Lorem ipsum dol go off canvas and contained by white bounding box
  88325. */
  88326. _main.default.Font.prototype.textBounds = function(str) {
  88327. var x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  88328. var y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  88329. var fontSize = arguments.length > 3 ? arguments[3] : undefined;
  88330. var opts = arguments.length > 4 ? arguments[4] : undefined;
  88331. // Check cache for existing bounds. Take into consideration the text alignment
  88332. // settings. Default alignment should match opentype's origin: left-aligned &
  88333. // alphabetic baseline.
  88334. var p = (opts && opts.renderer && opts.renderer._pInst) || this.parent;
  88335. var ctx = p._renderer.drawingContext;
  88336. var alignment = ctx.textAlign || constants.LEFT;
  88337. var baseline = ctx.textBaseline || constants.BASELINE;
  88338. var cacheResults = false;
  88339. var result;
  88340. var key;
  88341. fontSize = fontSize || p._renderer._textSize;
  88342. // NOTE: cache disabled for now pending further discussion of #3436
  88343. if (cacheResults) {
  88344. key = cacheKey('textBounds', str, x, y, fontSize, alignment, baseline);
  88345. result = this.cache[key];
  88346. }
  88347. if (!result) {
  88348. var minX = [];
  88349. var minY;
  88350. var maxX = [];
  88351. var maxY;
  88352. var pos;
  88353. var xCoords = [];
  88354. xCoords[0] = [];
  88355. var yCoords = [];
  88356. var scale = this._scale(fontSize);
  88357. var lineHeight = p._renderer.textLeading();
  88358. var lineCount = 0;
  88359. this.font.forEachGlyph(str, x, y, fontSize, opts, function(
  88360. glyph,
  88361. gX,
  88362. gY,
  88363. gFontSize
  88364. ) {
  88365. var gm = glyph.getMetrics();
  88366. if (glyph.index === 0 || glyph.index === 10) {
  88367. lineCount += 1;
  88368. xCoords[lineCount] = [];
  88369. } else {
  88370. xCoords[lineCount].push(gX + gm.xMin * scale);
  88371. xCoords[lineCount].push(gX + gm.xMax * scale);
  88372. yCoords.push(gY + lineCount * lineHeight + -gm.yMin * scale);
  88373. yCoords.push(gY + lineCount * lineHeight + -gm.yMax * scale);
  88374. }
  88375. });
  88376. if (xCoords[lineCount].length > 0) {
  88377. minX[lineCount] = Math.min.apply(null, xCoords[lineCount]);
  88378. maxX[lineCount] = Math.max.apply(null, xCoords[lineCount]);
  88379. }
  88380. var finalMaxX = 0;
  88381. for (var i = 0; i <= lineCount; i++) {
  88382. minX[i] = Math.min.apply(null, xCoords[i]);
  88383. maxX[i] = Math.max.apply(null, xCoords[i]);
  88384. var lineLength = maxX[i] - minX[i];
  88385. if (lineLength > finalMaxX) {
  88386. finalMaxX = lineLength;
  88387. }
  88388. }
  88389. var finalMinX = Math.min.apply(null, minX);
  88390. minY = Math.min.apply(null, yCoords);
  88391. maxY = Math.max.apply(null, yCoords);
  88392. result = {
  88393. x: finalMinX,
  88394. y: minY,
  88395. h: maxY - minY,
  88396. w: finalMaxX,
  88397. advance: finalMinX - x
  88398. };
  88399. // Bounds are now calculated, so shift the x & y to match alignment settings
  88400. pos = this._handleAlignment(
  88401. p._renderer,
  88402. str,
  88403. result.x,
  88404. result.y,
  88405. result.w + result.advance
  88406. );
  88407. result.x = pos.x;
  88408. result.y = pos.y;
  88409. if (cacheResults) {
  88410. this.cache[key] = result;
  88411. }
  88412. }
  88413. return result;
  88414. };
  88415. /**
  88416. * Computes an array of points following the path for specified text
  88417. *
  88418. * @method textToPoints
  88419. * @param {String} txt a line of text
  88420. * @param {Number} x x-position
  88421. * @param {Number} y y-position
  88422. * @param {Number} fontSize font size to use (optional)
  88423. * @param {Object} [options] an (optional) object that can contain:
  88424. *
  88425. * <br>sampleFactor - the ratio of path-length to number of samples
  88426. * (default=.1); higher values yield more points and are therefore
  88427. * more precise
  88428. *
  88429. * <br>simplifyThreshold - if set to a non-zero value, collinear points will be
  88430. * be removed from the polygon; the value represents the threshold angle to use
  88431. * when determining whether two edges are collinear
  88432. *
  88433. * @return {Array} an array of points, each with x, y, alpha (the path angle)
  88434. * @example
  88435. * <div>
  88436. * <code>
  88437. * let font;
  88438. * function preload() {
  88439. * font = loadFont('assets/inconsolata.otf');
  88440. * }
  88441. *
  88442. * let points;
  88443. * let bounds;
  88444. * function setup() {
  88445. * createCanvas(100, 100);
  88446. * stroke(0);
  88447. * fill(255, 104, 204);
  88448. *
  88449. * points = font.textToPoints('p5', 0, 0, 10, {
  88450. * sampleFactor: 5,
  88451. * simplifyThreshold: 0
  88452. * });
  88453. * bounds = font.textBounds(' p5 ', 0, 0, 10);
  88454. * }
  88455. *
  88456. * function draw() {
  88457. * background(255);
  88458. * beginShape();
  88459. * translate(-bounds.x * width / bounds.w, -bounds.y * height / bounds.h);
  88460. * for (let i = 0; i < points.length; i++) {
  88461. * let p = points[i];
  88462. * vertex(
  88463. * p.x * width / bounds.w +
  88464. * sin(20 * p.y / bounds.h + millis() / 1000) * width / 30,
  88465. * p.y * height / bounds.h
  88466. * );
  88467. * }
  88468. * endShape(CLOSE);
  88469. * }
  88470. * </code>
  88471. * </div>
  88472. */
  88473. _main.default.Font.prototype.textToPoints = function(
  88474. txt,
  88475. x,
  88476. y,
  88477. fontSize,
  88478. options
  88479. ) {
  88480. var xoff = 0;
  88481. var result = [];
  88482. var glyphs = this._getGlyphs(txt);
  88483. function isSpace(i) {
  88484. return (
  88485. (glyphs[i].name && glyphs[i].name === 'space') ||
  88486. (txt.length === glyphs.length && txt[i] === ' ') ||
  88487. (glyphs[i].index && glyphs[i].index === 3)
  88488. );
  88489. }
  88490. fontSize = fontSize || this.parent._renderer._textSize;
  88491. for (var i = 0; i < glyphs.length; i++) {
  88492. if (!isSpace(i)) {
  88493. // fix to #1817, #2069
  88494. var gpath = glyphs[i].getPath(x, y, fontSize),
  88495. paths = splitPaths(gpath.commands);
  88496. for (var j = 0; j < paths.length; j++) {
  88497. var pts = pathToPoints(paths[j], options);
  88498. for (var k = 0; k < pts.length; k++) {
  88499. pts[k].x += xoff;
  88500. result.push(pts[k]);
  88501. }
  88502. }
  88503. }
  88504. xoff += glyphs[i].advanceWidth * this._scale(fontSize);
  88505. }
  88506. return result;
  88507. };
  88508. // ----------------------------- End API ------------------------------
  88509. /**
  88510. * Returns the set of opentype glyphs for the supplied string.
  88511. *
  88512. * Note that there is not a strict one-to-one mapping between characters
  88513. * and glyphs, so the list of returned glyphs can be larger or smaller
  88514. * than the length of the given string.
  88515. *
  88516. * @private
  88517. * @param {String} str the string to be converted
  88518. * @return {Array} the opentype glyphs
  88519. */
  88520. _main.default.Font.prototype._getGlyphs = function(str) {
  88521. return this.font.stringToGlyphs(str);
  88522. };
  88523. /**
  88524. * Returns an opentype path for the supplied string and position.
  88525. *
  88526. * @private
  88527. * @param {String} line a line of text
  88528. * @param {Number} x x-position
  88529. * @param {Number} y y-position
  88530. * @param {Object} options opentype options (optional)
  88531. * @return {Object} the opentype path
  88532. */
  88533. _main.default.Font.prototype._getPath = function(line, x, y, options) {
  88534. var p = (options && options.renderer && options.renderer._pInst) || this.parent,
  88535. renderer = p._renderer,
  88536. pos = this._handleAlignment(renderer, line, x, y);
  88537. return this.font.getPath(line, pos.x, pos.y, renderer._textSize, options);
  88538. };
  88539. /*
  88540. * Creates an SVG-formatted path-data string
  88541. * (See http://www.w3.org/TR/SVG/paths.html#PathData)
  88542. * from the given opentype path or string/position
  88543. *
  88544. * @param {Object} path an opentype path, OR the following:
  88545. *
  88546. * @param {String} line a line of text
  88547. * @param {Number} x x-position
  88548. * @param {Number} y y-position
  88549. * @param {Object} options opentype options (optional), set options.decimals
  88550. * to set the decimal precision of the path-data
  88551. *
  88552. * @return {Object} this p5.Font object
  88553. */
  88554. _main.default.Font.prototype._getPathData = function(line, x, y, options) {
  88555. var decimals = 3;
  88556. // create path from string/position
  88557. if (typeof line === 'string' && arguments.length > 2) {
  88558. line = this._getPath(line, x, y, options);
  88559. } else if (_typeof(x) === 'object') {
  88560. // handle options specified in 2nd arg
  88561. options = x;
  88562. }
  88563. // handle svg arguments
  88564. if (options && typeof options.decimals === 'number') {
  88565. decimals = options.decimals;
  88566. }
  88567. return line.toPathData(decimals);
  88568. };
  88569. /*
  88570. * Creates an SVG <path> element, as a string,
  88571. * from the given opentype path or string/position
  88572. *
  88573. * @param {Object} path an opentype path, OR the following:
  88574. *
  88575. * @param {String} line a line of text
  88576. * @param {Number} x x-position
  88577. * @param {Number} y y-position
  88578. * @param {Object} options opentype options (optional), set options.decimals
  88579. * to set the decimal precision of the path-data in the <path> element,
  88580. * options.fill to set the fill color for the <path> element,
  88581. * options.stroke to set the stroke color for the <path> element,
  88582. * options.strokeWidth to set the strokeWidth for the <path> element.
  88583. *
  88584. * @return {Object} this p5.Font object
  88585. */
  88586. _main.default.Font.prototype._getSVG = function(line, x, y, options) {
  88587. var decimals = 3;
  88588. // create path from string/position
  88589. if (typeof line === 'string' && arguments.length > 2) {
  88590. line = this._getPath(line, x, y, options);
  88591. } else if (_typeof(x) === 'object') {
  88592. // handle options specified in 2nd arg
  88593. options = x;
  88594. }
  88595. // handle svg arguments
  88596. if (options) {
  88597. if (typeof options.decimals === 'number') {
  88598. decimals = options.decimals;
  88599. }
  88600. if (typeof options.strokeWidth === 'number') {
  88601. line.strokeWidth = options.strokeWidth;
  88602. }
  88603. if (typeof options.fill !== 'undefined') {
  88604. line.fill = options.fill;
  88605. }
  88606. if (typeof options.stroke !== 'undefined') {
  88607. line.stroke = options.stroke;
  88608. }
  88609. }
  88610. return line.toSVG(decimals);
  88611. };
  88612. /*
  88613. * Renders an opentype path or string/position
  88614. * to the current graphics context
  88615. *
  88616. * @param {Object} path an opentype path, OR the following:
  88617. *
  88618. * @param {String} line a line of text
  88619. * @param {Number} x x-position
  88620. * @param {Number} y y-position
  88621. * @param {Object} options opentype options (optional)
  88622. *
  88623. * @return {p5.Font} this p5.Font object
  88624. */
  88625. _main.default.Font.prototype._renderPath = function(line, x, y, options) {
  88626. var pdata;
  88627. var pg = (options && options.renderer) || this.parent._renderer;
  88628. var ctx = pg.drawingContext;
  88629. if (_typeof(line) === 'object' && line.commands) {
  88630. pdata = line.commands;
  88631. } else {
  88632. //pos = handleAlignment(p, ctx, line, x, y);
  88633. pdata = this._getPath(line, x, y, options).commands;
  88634. }
  88635. ctx.beginPath();
  88636. var _iteratorNormalCompletion = true;
  88637. var _didIteratorError = false;
  88638. var _iteratorError = undefined;
  88639. try {
  88640. for (
  88641. var _iterator = pdata[Symbol.iterator](), _step;
  88642. !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
  88643. _iteratorNormalCompletion = true
  88644. ) {
  88645. var cmd = _step.value;
  88646. if (cmd.type === 'M') {
  88647. ctx.moveTo(cmd.x, cmd.y);
  88648. } else if (cmd.type === 'L') {
  88649. ctx.lineTo(cmd.x, cmd.y);
  88650. } else if (cmd.type === 'C') {
  88651. ctx.bezierCurveTo(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y);
  88652. } else if (cmd.type === 'Q') {
  88653. ctx.quadraticCurveTo(cmd.x1, cmd.y1, cmd.x, cmd.y);
  88654. } else if (cmd.type === 'Z') {
  88655. ctx.closePath();
  88656. }
  88657. }
  88658. // only draw stroke if manually set by user
  88659. } catch (err) {
  88660. _didIteratorError = true;
  88661. _iteratorError = err;
  88662. } finally {
  88663. try {
  88664. if (!_iteratorNormalCompletion && _iterator.return != null) {
  88665. _iterator.return();
  88666. }
  88667. } finally {
  88668. if (_didIteratorError) {
  88669. throw _iteratorError;
  88670. }
  88671. }
  88672. }
  88673. if (pg._doStroke && pg._strokeSet) {
  88674. ctx.stroke();
  88675. }
  88676. if (pg._doFill) {
  88677. // if fill hasn't been set by user, use default-text-fill
  88678. if (!pg._fillSet) {
  88679. pg._setFill(constants._DEFAULT_TEXT_FILL);
  88680. }
  88681. ctx.fill();
  88682. }
  88683. return this;
  88684. };
  88685. _main.default.Font.prototype._textWidth = function(str, fontSize) {
  88686. return this.font.getAdvanceWidth(str, fontSize);
  88687. };
  88688. _main.default.Font.prototype._textAscent = function(fontSize) {
  88689. return this.font.ascender * this._scale(fontSize);
  88690. };
  88691. _main.default.Font.prototype._textDescent = function(fontSize) {
  88692. return -this.font.descender * this._scale(fontSize);
  88693. };
  88694. _main.default.Font.prototype._scale = function(fontSize) {
  88695. return 1 / this.font.unitsPerEm * (fontSize || this.parent._renderer._textSize);
  88696. };
  88697. _main.default.Font.prototype._handleAlignment = function(
  88698. renderer,
  88699. line,
  88700. x,
  88701. y,
  88702. textWidth
  88703. ) {
  88704. var fontSize = renderer._textSize;
  88705. if (typeof textWidth === 'undefined') {
  88706. textWidth = this._textWidth(line, fontSize);
  88707. }
  88708. switch (renderer._textAlign) {
  88709. case constants.CENTER:
  88710. x -= textWidth / 2;
  88711. break;
  88712. case constants.RIGHT:
  88713. x -= textWidth;
  88714. break;
  88715. }
  88716. switch (renderer._textBaseline) {
  88717. case constants.TOP:
  88718. y += this._textAscent(fontSize);
  88719. break;
  88720. case constants.CENTER:
  88721. y += this._textAscent(fontSize) / 2;
  88722. break;
  88723. case constants.BOTTOM:
  88724. y -= this._textDescent(fontSize);
  88725. break;
  88726. }
  88727. return { x: x, y: y };
  88728. };
  88729. // path-utils
  88730. function pathToPoints(cmds, options) {
  88731. var opts = parseOpts(options, {
  88732. sampleFactor: 0.1,
  88733. simplifyThreshold: 0
  88734. });
  88735. var // total-length
  88736. len = pointAtLength(cmds, 0, 1),
  88737. t = len / (len * opts.sampleFactor),
  88738. pts = [];
  88739. for (var i = 0; i < len; i += t) {
  88740. pts.push(pointAtLength(cmds, i));
  88741. }
  88742. if (opts.simplifyThreshold) {
  88743. simplify(pts, opts.simplifyThreshold);
  88744. }
  88745. return pts;
  88746. }
  88747. function simplify(pts) {
  88748. var angle =
  88749. arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  88750. var num = 0;
  88751. for (var i = pts.length - 1; pts.length > 3 && i >= 0; --i) {
  88752. if (collinear(at(pts, i - 1), at(pts, i), at(pts, i + 1), angle)) {
  88753. // Remove the middle point
  88754. pts.splice(i % pts.length, 1);
  88755. num++;
  88756. }
  88757. }
  88758. return num;
  88759. }
  88760. function splitPaths(cmds) {
  88761. var paths = [];
  88762. var current;
  88763. for (var i = 0; i < cmds.length; i++) {
  88764. if (cmds[i].type === 'M') {
  88765. if (current) {
  88766. paths.push(current);
  88767. }
  88768. current = [];
  88769. }
  88770. current.push(cmdToArr(cmds[i]));
  88771. }
  88772. paths.push(current);
  88773. return paths;
  88774. }
  88775. function cmdToArr(cmd) {
  88776. var arr = [cmd.type];
  88777. if (cmd.type === 'M' || cmd.type === 'L') {
  88778. // moveto or lineto
  88779. arr.push(cmd.x, cmd.y);
  88780. } else if (cmd.type === 'C') {
  88781. arr.push(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y);
  88782. } else if (cmd.type === 'Q') {
  88783. arr.push(cmd.x1, cmd.y1, cmd.x, cmd.y);
  88784. }
  88785. // else if (cmd.type === 'Z') { /* no-op */ }
  88786. return arr;
  88787. }
  88788. function parseOpts(options, defaults) {
  88789. if (_typeof(options) !== 'object') {
  88790. options = defaults;
  88791. } else {
  88792. for (var key in defaults) {
  88793. if (typeof options[key] === 'undefined') {
  88794. options[key] = defaults[key];
  88795. }
  88796. }
  88797. }
  88798. return options;
  88799. }
  88800. //////////////////////// Helpers ////////////////////////////
  88801. function at(v, i) {
  88802. var s = v.length;
  88803. return v[i < 0 ? i % s + s : i % s];
  88804. }
  88805. function collinear(a, b, c, thresholdAngle) {
  88806. if (!thresholdAngle) {
  88807. return areaTriangle(a, b, c) === 0;
  88808. }
  88809. if (typeof collinear.tmpPoint1 === 'undefined') {
  88810. collinear.tmpPoint1 = [];
  88811. collinear.tmpPoint2 = [];
  88812. }
  88813. var ab = collinear.tmpPoint1,
  88814. bc = collinear.tmpPoint2;
  88815. ab.x = b.x - a.x;
  88816. ab.y = b.y - a.y;
  88817. bc.x = c.x - b.x;
  88818. bc.y = c.y - b.y;
  88819. var dot = ab.x * bc.x + ab.y * bc.y,
  88820. magA = Math.sqrt(ab.x * ab.x + ab.y * ab.y),
  88821. magB = Math.sqrt(bc.x * bc.x + bc.y * bc.y),
  88822. angle = Math.acos(dot / (magA * magB));
  88823. return angle < thresholdAngle;
  88824. }
  88825. function areaTriangle(a, b, c) {
  88826. return (b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1]);
  88827. }
  88828. // Portions of below code copyright 2008 Dmitry Baranovskiy (via MIT license)
  88829. function findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  88830. var t1 = 1 - t;
  88831. var t13 = Math.pow(t1, 3);
  88832. var t12 = Math.pow(t1, 2);
  88833. var t2 = t * t;
  88834. var t3 = t2 * t;
  88835. var x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x;
  88836. var y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y;
  88837. var mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x);
  88838. var my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y);
  88839. var nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x);
  88840. var ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y);
  88841. var ax = t1 * p1x + t * c1x;
  88842. var ay = t1 * p1y + t * c1y;
  88843. var cx = t1 * c2x + t * p2x;
  88844. var cy = t1 * c2y + t * p2y;
  88845. var alpha = 90 - Math.atan2(mx - nx, my - ny) * 180 / Math.PI;
  88846. if (mx > nx || my < ny) {
  88847. alpha += 180;
  88848. }
  88849. return {
  88850. x: x,
  88851. y: y,
  88852. m: { x: mx, y: my },
  88853. n: { x: nx, y: ny },
  88854. start: { x: ax, y: ay },
  88855. end: { x: cx, y: cy },
  88856. alpha: alpha
  88857. };
  88858. }
  88859. function getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
  88860. return length == null
  88861. ? bezlen(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y)
  88862. : findDotsAtSegment(
  88863. p1x,
  88864. p1y,
  88865. c1x,
  88866. c1y,
  88867. c2x,
  88868. c2y,
  88869. p2x,
  88870. p2y,
  88871. getTatLen(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length)
  88872. );
  88873. }
  88874. function pointAtLength(path, length, istotal) {
  88875. path = path2curve(path);
  88876. var x;
  88877. var y;
  88878. var p;
  88879. var l;
  88880. var sp = '';
  88881. var subpaths = {};
  88882. var point;
  88883. var len = 0;
  88884. for (var i = 0, ii = path.length; i < ii; i++) {
  88885. p = path[i];
  88886. if (p[0] === 'M') {
  88887. x = +p[1];
  88888. y = +p[2];
  88889. } else {
  88890. l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
  88891. if (len + l > length) {
  88892. if (!istotal) {
  88893. point = getPointAtSegmentLength(
  88894. x,
  88895. y,
  88896. p[1],
  88897. p[2],
  88898. p[3],
  88899. p[4],
  88900. p[5],
  88901. p[6],
  88902. length - len
  88903. );
  88904. return { x: point.x, y: point.y, alpha: point.alpha };
  88905. }
  88906. }
  88907. len += l;
  88908. x = +p[5];
  88909. y = +p[6];
  88910. }
  88911. sp += p.shift() + p;
  88912. }
  88913. subpaths.end = sp;
  88914. point = istotal
  88915. ? len
  88916. : findDotsAtSegment(x, y, p[0], p[1], p[2], p[3], p[4], p[5], 1);
  88917. if (point.alpha) {
  88918. point = { x: point.x, y: point.y, alpha: point.alpha };
  88919. }
  88920. return point;
  88921. }
  88922. function pathToAbsolute(pathArray) {
  88923. var res = [],
  88924. x = 0,
  88925. y = 0,
  88926. mx = 0,
  88927. my = 0,
  88928. start = 0;
  88929. if (!pathArray) {
  88930. // console.warn("Unexpected state: undefined pathArray"); // shouldn't happen
  88931. return res;
  88932. }
  88933. if (pathArray[0][0] === 'M') {
  88934. x = +pathArray[0][1];
  88935. y = +pathArray[0][2];
  88936. mx = x;
  88937. my = y;
  88938. start++;
  88939. res[0] = ['M', x, y];
  88940. }
  88941. var dots;
  88942. var crz =
  88943. pathArray.length === 3 &&
  88944. pathArray[0][0] === 'M' &&
  88945. pathArray[1][0].toUpperCase() === 'R' &&
  88946. pathArray[2][0].toUpperCase() === 'Z';
  88947. for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) {
  88948. res.push((r = []));
  88949. pa = pathArray[i];
  88950. if (pa[0] !== String.prototype.toUpperCase.call(pa[0])) {
  88951. r[0] = String.prototype.toUpperCase.call(pa[0]);
  88952. switch (r[0]) {
  88953. case 'A':
  88954. r[1] = pa[1];
  88955. r[2] = pa[2];
  88956. r[3] = pa[3];
  88957. r[4] = pa[4];
  88958. r[5] = pa[5];
  88959. r[6] = +(pa[6] + x);
  88960. r[7] = +(pa[7] + y);
  88961. break;
  88962. case 'V':
  88963. r[1] = +pa[1] + y;
  88964. break;
  88965. case 'H':
  88966. r[1] = +pa[1] + x;
  88967. break;
  88968. case 'R':
  88969. dots = [x, y].concat(pa.slice(1));
  88970. for (var j = 2, jj = dots.length; j < jj; j++) {
  88971. dots[j] = +dots[j] + x;
  88972. dots[++j] = +dots[j] + y;
  88973. }
  88974. res.pop();
  88975. res = res.concat(catmullRom2bezier(dots, crz));
  88976. break;
  88977. case 'M':
  88978. mx = +pa[1] + x;
  88979. my = +pa[2] + y;
  88980. break;
  88981. default:
  88982. for (var _j = 1, _jj = pa.length; _j < _jj; _j++) {
  88983. r[_j] = +pa[_j] + (_j % 2 ? x : y);
  88984. }
  88985. }
  88986. } else if (pa[0] === 'R') {
  88987. dots = [x, y].concat(pa.slice(1));
  88988. res.pop();
  88989. res = res.concat(catmullRom2bezier(dots, crz));
  88990. r = ['R'].concat(pa.slice(-2));
  88991. } else {
  88992. for (var k = 0, kk = pa.length; k < kk; k++) {
  88993. r[k] = pa[k];
  88994. }
  88995. }
  88996. switch (r[0]) {
  88997. case 'Z':
  88998. x = mx;
  88999. y = my;
  89000. break;
  89001. case 'H':
  89002. x = r[1];
  89003. break;
  89004. case 'V':
  89005. y = r[1];
  89006. break;
  89007. case 'M':
  89008. mx = r[r.length - 2];
  89009. my = r[r.length - 1];
  89010. break;
  89011. default:
  89012. x = r[r.length - 2];
  89013. y = r[r.length - 1];
  89014. }
  89015. }
  89016. return res;
  89017. }
  89018. function path2curve(path, path2) {
  89019. var p = pathToAbsolute(path),
  89020. p2 = path2 && pathToAbsolute(path2);
  89021. var attrs = { x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null };
  89022. var attrs2 = { x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null };
  89023. var pcoms1 = []; // path commands of original path p
  89024. var pcoms2 = []; // path commands of original path p2
  89025. var ii;
  89026. var processPath = function processPath(path, d, pcom) {
  89027. var nx;
  89028. var ny;
  89029. var tq = { T: 1, Q: 1 };
  89030. if (!path) {
  89031. return ['C', d.x, d.y, d.x, d.y, d.x, d.y];
  89032. }
  89033. if (!(path[0] in tq)) {
  89034. d.qx = d.qy = null;
  89035. }
  89036. switch (path[0]) {
  89037. case 'M':
  89038. d.X = path[1];
  89039. d.Y = path[2];
  89040. break;
  89041. case 'A':
  89042. path = ['C'].concat(a2c.apply(0, [d.x, d.y].concat(path.slice(1))));
  89043. break;
  89044. case 'S':
  89045. if (pcom === 'C' || pcom === 'S') {
  89046. nx = d.x * 2 - d.bx;
  89047. ny = d.y * 2 - d.by;
  89048. } else {
  89049. nx = d.x;
  89050. ny = d.y;
  89051. }
  89052. path = ['C', nx, ny].concat(path.slice(1));
  89053. break;
  89054. case 'T':
  89055. if (pcom === 'Q' || pcom === 'T') {
  89056. d.qx = d.x * 2 - d.qx;
  89057. d.qy = d.y * 2 - d.qy;
  89058. } else {
  89059. d.qx = d.x;
  89060. d.qy = d.y;
  89061. }
  89062. path = ['C'].concat(q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
  89063. break;
  89064. case 'Q':
  89065. d.qx = path[1];
  89066. d.qy = path[2];
  89067. path = ['C'].concat(q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
  89068. break;
  89069. case 'L':
  89070. path = ['C'].concat(l2c(d.x, d.y, path[1], path[2]));
  89071. break;
  89072. case 'H':
  89073. path = ['C'].concat(l2c(d.x, d.y, path[1], d.y));
  89074. break;
  89075. case 'V':
  89076. path = ['C'].concat(l2c(d.x, d.y, d.x, path[1]));
  89077. break;
  89078. case 'Z':
  89079. path = ['C'].concat(l2c(d.x, d.y, d.X, d.Y));
  89080. break;
  89081. }
  89082. return path;
  89083. },
  89084. fixArc = function fixArc(pp, i) {
  89085. if (pp[i].length > 7) {
  89086. pp[i].shift();
  89087. var pi = pp[i];
  89088. while (pi.length) {
  89089. pcoms1[i] = 'A';
  89090. if (p2) {
  89091. pcoms2[i] = 'A';
  89092. }
  89093. pp.splice(i++, 0, ['C'].concat(pi.splice(0, 6)));
  89094. }
  89095. pp.splice(i, 1);
  89096. ii = Math.max(p.length, (p2 && p2.length) || 0);
  89097. }
  89098. },
  89099. fixM = function fixM(path1, path2, a1, a2, i) {
  89100. if (path1 && path2 && path1[i][0] === 'M' && path2[i][0] !== 'M') {
  89101. path2.splice(i, 0, ['M', a2.x, a2.y]);
  89102. a1.bx = 0;
  89103. a1.by = 0;
  89104. a1.x = path1[i][1];
  89105. a1.y = path1[i][2];
  89106. ii = Math.max(p.length, (p2 && p2.length) || 0);
  89107. }
  89108. };
  89109. var pfirst = ''; // temporary holder for original path command
  89110. var pcom = ''; // holder for previous path command of original path
  89111. ii = Math.max(p.length, (p2 && p2.length) || 0);
  89112. for (var i = 0; i < ii; i++) {
  89113. if (p[i]) {
  89114. pfirst = p[i][0];
  89115. } // save current path command
  89116. if (pfirst !== 'C') {
  89117. pcoms1[i] = pfirst; // Save current path command
  89118. if (i) {
  89119. pcom = pcoms1[i - 1];
  89120. } // Get previous path command pcom
  89121. }
  89122. p[i] = processPath(p[i], attrs, pcom);
  89123. if (pcoms1[i] !== 'A' && pfirst === 'C') {
  89124. pcoms1[i] = 'C';
  89125. }
  89126. fixArc(p, i); // fixArc adds also the right amount of A:s to pcoms1
  89127. if (p2) {
  89128. // the same procedures is done to p2
  89129. if (p2[i]) {
  89130. pfirst = p2[i][0];
  89131. }
  89132. if (pfirst !== 'C') {
  89133. pcoms2[i] = pfirst;
  89134. if (i) {
  89135. pcom = pcoms2[i - 1];
  89136. }
  89137. }
  89138. p2[i] = processPath(p2[i], attrs2, pcom);
  89139. if (pcoms2[i] !== 'A' && pfirst === 'C') {
  89140. pcoms2[i] = 'C';
  89141. }
  89142. fixArc(p2, i);
  89143. }
  89144. fixM(p, p2, attrs, attrs2, i);
  89145. fixM(p2, p, attrs2, attrs, i);
  89146. var seg = p[i],
  89147. seg2 = p2 && p2[i],
  89148. seglen = seg.length,
  89149. seg2len = p2 && seg2.length;
  89150. attrs.x = seg[seglen - 2];
  89151. attrs.y = seg[seglen - 1];
  89152. attrs.bx = parseFloat(seg[seglen - 4]) || attrs.x;
  89153. attrs.by = parseFloat(seg[seglen - 3]) || attrs.y;
  89154. attrs2.bx = p2 && (parseFloat(seg2[seg2len - 4]) || attrs2.x);
  89155. attrs2.by = p2 && (parseFloat(seg2[seg2len - 3]) || attrs2.y);
  89156. attrs2.x = p2 && seg2[seg2len - 2];
  89157. attrs2.y = p2 && seg2[seg2len - 1];
  89158. }
  89159. return p2 ? [p, p2] : p;
  89160. }
  89161. function a2c(x1, y1, rx, ry, angle, lac, sweep_flag, x2, y2, recursive) {
  89162. // for more information of where this Math came from visit:
  89163. // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
  89164. var PI = Math.PI;
  89165. var _120 = PI * 120 / 180;
  89166. var f1;
  89167. var f2;
  89168. var cx;
  89169. var cy;
  89170. var rad = PI / 180 * (+angle || 0);
  89171. var res = [];
  89172. var xy;
  89173. var rotate = function rotate(x, y, rad) {
  89174. var X = x * Math.cos(rad) - y * Math.sin(rad),
  89175. Y = x * Math.sin(rad) + y * Math.cos(rad);
  89176. return { x: X, y: Y };
  89177. };
  89178. if (!recursive) {
  89179. xy = rotate(x1, y1, -rad);
  89180. x1 = xy.x;
  89181. y1 = xy.y;
  89182. xy = rotate(x2, y2, -rad);
  89183. x2 = xy.x;
  89184. y2 = xy.y;
  89185. var x = (x1 - x2) / 2;
  89186. var y = (y1 - y2) / 2;
  89187. var h = x * x / (rx * rx) + y * y / (ry * ry);
  89188. if (h > 1) {
  89189. h = Math.sqrt(h);
  89190. rx = h * rx;
  89191. ry = h * ry;
  89192. }
  89193. var rx2 = rx * rx,
  89194. ry2 = ry * ry;
  89195. var k =
  89196. (lac === sweep_flag ? -1 : 1) *
  89197. Math.sqrt(
  89198. Math.abs(
  89199. (rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x)
  89200. )
  89201. );
  89202. cx = k * rx * y / ry + (x1 + x2) / 2;
  89203. cy = k * -ry * x / rx + (y1 + y2) / 2;
  89204. f1 = Math.asin(((y1 - cy) / ry).toFixed(9));
  89205. f2 = Math.asin(((y2 - cy) / ry).toFixed(9));
  89206. f1 = x1 < cx ? PI - f1 : f1;
  89207. f2 = x2 < cx ? PI - f2 : f2;
  89208. if (f1 < 0) {
  89209. f1 = PI * 2 + f1;
  89210. }
  89211. if (f2 < 0) {
  89212. f2 = PI * 2 + f2;
  89213. }
  89214. if (sweep_flag && f1 > f2) {
  89215. f1 = f1 - PI * 2;
  89216. }
  89217. if (!sweep_flag && f2 > f1) {
  89218. f2 = f2 - PI * 2;
  89219. }
  89220. } else {
  89221. f1 = recursive[0];
  89222. f2 = recursive[1];
  89223. cx = recursive[2];
  89224. cy = recursive[3];
  89225. }
  89226. var df = f2 - f1;
  89227. if (Math.abs(df) > _120) {
  89228. var f2old = f2,
  89229. x2old = x2,
  89230. y2old = y2;
  89231. f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
  89232. x2 = cx + rx * Math.cos(f2);
  89233. y2 = cy + ry * Math.sin(f2);
  89234. res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [
  89235. f2,
  89236. f2old,
  89237. cx,
  89238. cy
  89239. ]);
  89240. }
  89241. df = f2 - f1;
  89242. var c1 = Math.cos(f1),
  89243. s1 = Math.sin(f1),
  89244. c2 = Math.cos(f2),
  89245. s2 = Math.sin(f2),
  89246. t = Math.tan(df / 4),
  89247. hx = 4 / 3 * rx * t,
  89248. hy = 4 / 3 * ry * t,
  89249. m1 = [x1, y1],
  89250. m2 = [x1 + hx * s1, y1 - hy * c1],
  89251. m3 = [x2 + hx * s2, y2 - hy * c2],
  89252. m4 = [x2, y2];
  89253. m2[0] = 2 * m1[0] - m2[0];
  89254. m2[1] = 2 * m1[1] - m2[1];
  89255. if (recursive) {
  89256. return [m2, m3, m4].concat(res);
  89257. } else {
  89258. res = [m2, m3, m4]
  89259. .concat(res)
  89260. .join()
  89261. .split(',');
  89262. var newres = [];
  89263. for (var i = 0, ii = res.length; i < ii; i++) {
  89264. newres[i] =
  89265. i % 2
  89266. ? rotate(res[i - 1], res[i], rad).y
  89267. : rotate(res[i], res[i + 1], rad).x;
  89268. }
  89269. return newres;
  89270. }
  89271. }
  89272. // http://schepers.cc/getting-to-the-point
  89273. function catmullRom2bezier(crp, z) {
  89274. var d = [];
  89275. for (var i = 0, iLen = crp.length; iLen - 2 * !z > i; i += 2) {
  89276. var p = [
  89277. {
  89278. x: +crp[i - 2],
  89279. y: +crp[i - 1]
  89280. },
  89281. {
  89282. x: +crp[i],
  89283. y: +crp[i + 1]
  89284. },
  89285. {
  89286. x: +crp[i + 2],
  89287. y: +crp[i + 3]
  89288. },
  89289. {
  89290. x: +crp[i + 4],
  89291. y: +crp[i + 5]
  89292. }
  89293. ];
  89294. if (z) {
  89295. if (!i) {
  89296. p[0] = {
  89297. x: +crp[iLen - 2],
  89298. y: +crp[iLen - 1]
  89299. };
  89300. } else if (iLen - 4 === i) {
  89301. p[3] = {
  89302. x: +crp[0],
  89303. y: +crp[1]
  89304. };
  89305. } else if (iLen - 2 === i) {
  89306. p[2] = {
  89307. x: +crp[0],
  89308. y: +crp[1]
  89309. };
  89310. p[3] = {
  89311. x: +crp[2],
  89312. y: +crp[3]
  89313. };
  89314. }
  89315. } else {
  89316. if (iLen - 4 === i) {
  89317. p[3] = p[2];
  89318. } else if (!i) {
  89319. p[0] = {
  89320. x: +crp[i],
  89321. y: +crp[i + 1]
  89322. };
  89323. }
  89324. }
  89325. d.push([
  89326. 'C',
  89327. (-p[0].x + 6 * p[1].x + p[2].x) / 6,
  89328. (-p[0].y + 6 * p[1].y + p[2].y) / 6,
  89329. (p[1].x + 6 * p[2].x - p[3].x) / 6,
  89330. (p[1].y + 6 * p[2].y - p[3].y) / 6,
  89331. p[2].x,
  89332. p[2].y
  89333. ]);
  89334. }
  89335. return d;
  89336. }
  89337. function l2c(x1, y1, x2, y2) {
  89338. return [x1, y1, x2, y2, x2, y2];
  89339. }
  89340. function q2c(x1, y1, ax, ay, x2, y2) {
  89341. var _13 = 1 / 3,
  89342. _23 = 2 / 3;
  89343. return [
  89344. _13 * x1 + _23 * ax,
  89345. _13 * y1 + _23 * ay,
  89346. _13 * x2 + _23 * ax,
  89347. _13 * y2 + _23 * ay,
  89348. x2,
  89349. y2
  89350. ];
  89351. }
  89352. function bezlen(x1, y1, x2, y2, x3, y3, x4, y4, z) {
  89353. if (z == null) {
  89354. z = 1;
  89355. }
  89356. z = z > 1 ? 1 : z < 0 ? 0 : z;
  89357. var z2 = z / 2;
  89358. var n = 12;
  89359. var Tvalues = [
  89360. -0.1252,
  89361. 0.1252,
  89362. -0.3678,
  89363. 0.3678,
  89364. -0.5873,
  89365. 0.5873,
  89366. -0.7699,
  89367. 0.7699,
  89368. -0.9041,
  89369. 0.9041,
  89370. -0.9816,
  89371. 0.9816
  89372. ];
  89373. var sum = 0;
  89374. var Cvalues = [
  89375. 0.2491,
  89376. 0.2491,
  89377. 0.2335,
  89378. 0.2335,
  89379. 0.2032,
  89380. 0.2032,
  89381. 0.1601,
  89382. 0.1601,
  89383. 0.1069,
  89384. 0.1069,
  89385. 0.0472,
  89386. 0.0472
  89387. ];
  89388. for (var i = 0; i < n; i++) {
  89389. var ct = z2 * Tvalues[i] + z2,
  89390. xbase = base3(ct, x1, x2, x3, x4),
  89391. ybase = base3(ct, y1, y2, y3, y4),
  89392. comb = xbase * xbase + ybase * ybase;
  89393. sum += Cvalues[i] * Math.sqrt(comb);
  89394. }
  89395. return z2 * sum;
  89396. }
  89397. function getTatLen(x1, y1, x2, y2, x3, y3, x4, y4, ll) {
  89398. if (ll < 0 || bezlen(x1, y1, x2, y2, x3, y3, x4, y4) < ll) {
  89399. return;
  89400. }
  89401. var t = 1;
  89402. var step = t / 2;
  89403. var t2 = t - step;
  89404. var l;
  89405. var e = 0.01;
  89406. l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2);
  89407. while (Math.abs(l - ll) > e) {
  89408. step /= 2;
  89409. t2 += (l < ll ? 1 : -1) * step;
  89410. l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2);
  89411. }
  89412. return t2;
  89413. }
  89414. function base3(t, p1, p2, p3, p4) {
  89415. var t1 = -3 * p1 + 9 * p2 - 9 * p3 + 3 * p4,
  89416. t2 = t * t1 + 6 * p1 - 12 * p2 + 6 * p3;
  89417. return t * t2 - 3 * p1 + 3 * p2;
  89418. }
  89419. function cacheKey() {
  89420. var hash = '';
  89421. for (var i = arguments.length - 1; i >= 0; --i) {
  89422. hash += '\uFF1F'.concat(
  89423. i < 0 || arguments.length <= i ? undefined : arguments[i]
  89424. );
  89425. }
  89426. return hash;
  89427. }
  89428. var _default = _main.default;
  89429. exports.default = _default;
  89430. },
  89431. {
  89432. '../core/constants': 272,
  89433. '../core/main': 283,
  89434. 'core-js/modules/es.array.concat': 166,
  89435. 'core-js/modules/es.array.fill': 168,
  89436. 'core-js/modules/es.array.iterator': 174,
  89437. 'core-js/modules/es.array.join': 175,
  89438. 'core-js/modules/es.array.slice': 178,
  89439. 'core-js/modules/es.array.splice': 180,
  89440. 'core-js/modules/es.function.name': 181,
  89441. 'core-js/modules/es.number.to-fixed': 187,
  89442. 'core-js/modules/es.object.to-string': 192,
  89443. 'core-js/modules/es.regexp.exec': 196,
  89444. 'core-js/modules/es.string.iterator': 201,
  89445. 'core-js/modules/es.string.split': 206,
  89446. 'core-js/modules/es.symbol': 211,
  89447. 'core-js/modules/es.symbol.description': 209,
  89448. 'core-js/modules/es.symbol.iterator': 210,
  89449. 'core-js/modules/web.dom-collections.iterator': 244
  89450. }
  89451. ],
  89452. 322: [
  89453. function(_dereq_, module, exports) {
  89454. 'use strict';
  89455. _dereq_('core-js/modules/es.array.concat');
  89456. _dereq_('core-js/modules/es.array.slice');
  89457. _dereq_('core-js/modules/es.array.splice');
  89458. _dereq_('core-js/modules/es.array-buffer.constructor');
  89459. _dereq_('core-js/modules/es.object.to-string');
  89460. Object.defineProperty(exports, '__esModule', { value: true });
  89461. exports.default = void 0;
  89462. var _main = _interopRequireDefault(_dereq_('../core/main'));
  89463. function _interopRequireDefault(obj) {
  89464. return obj && obj.__esModule ? obj : { default: obj };
  89465. }
  89466. /**
  89467. * @module Data
  89468. * @submodule Array Functions
  89469. * @for p5
  89470. * @requires core
  89471. */ /**
  89472. * Adds a value to the end of an array. Extends the length of
  89473. * the array by one. Maps to Array.push().
  89474. *
  89475. * @method append
  89476. * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push">array.push(value)</a> instead.
  89477. * @param {Array} array Array to append
  89478. * @param {any} value to be added to the Array
  89479. * @return {Array} the array that was appended to
  89480. * @example
  89481. * <div class='norender'><code>
  89482. * function setup() {
  89483. * let myArray = ['Mango', 'Apple', 'Papaya'];
  89484. * print(myArray); // ['Mango', 'Apple', 'Papaya']
  89485. *
  89486. * append(myArray, 'Peach');
  89487. * print(myArray); // ['Mango', 'Apple', 'Papaya', 'Peach']
  89488. * }
  89489. * </code></div>
  89490. */ _main.default.prototype.append = function(array, value) {
  89491. array.push(value);
  89492. return array;
  89493. };
  89494. /**
  89495. * Copies an array (or part of an array) to another array. The src array is
  89496. * copied to the dst array, beginning at the position specified by
  89497. * srcPosition and into the position specified by dstPosition. The number of
  89498. * elements to copy is determined by length. Note that copying values
  89499. * overwrites existing values in the destination array. To append values
  89500. * instead of overwriting them, use <a href="#/p5/concat">concat()</a>.
  89501. *
  89502. * The simplified version with only two arguments, arrayCopy(src, dst),
  89503. * copies an entire array to another of the same size. It is equivalent to
  89504. * arrayCopy(src, 0, dst, 0, src.length).
  89505. *
  89506. * Using this function is far more efficient for copying array data than
  89507. * iterating through a for() loop and copying each element individually.
  89508. *
  89509. * @method arrayCopy
  89510. * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin">arr1.copyWithin(arr2)</a> instead.
  89511. * @param {Array} src the source Array
  89512. * @param {Integer} srcPosition starting position in the source Array
  89513. * @param {Array} dst the destination Array
  89514. * @param {Integer} dstPosition starting position in the destination Array
  89515. * @param {Integer} length number of Array elements to be copied
  89516. *
  89517. * @example
  89518. * <div class='norender'><code>
  89519. * let src = ['A', 'B', 'C'];
  89520. * let dst = [1, 2, 3];
  89521. * let srcPosition = 1;
  89522. * let dstPosition = 0;
  89523. * let length = 2;
  89524. *
  89525. * print(src); // ['A', 'B', 'C']
  89526. * print(dst); // [ 1 , 2 , 3 ]
  89527. *
  89528. * arrayCopy(src, srcPosition, dst, dstPosition, length);
  89529. * print(dst); // ['B', 'C', 3]
  89530. * </code></div>
  89531. */
  89532. /**
  89533. * @method arrayCopy
  89534. * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin">arr1.copyWithin(arr2)</a> instead.
  89535. * @param {Array} src
  89536. * @param {Array} dst
  89537. * @param {Integer} [length]
  89538. */
  89539. _main.default.prototype.arrayCopy = function(
  89540. src,
  89541. srcPosition,
  89542. dst,
  89543. dstPosition,
  89544. length
  89545. ) {
  89546. // the index to begin splicing from dst array
  89547. var start;
  89548. var end;
  89549. if (typeof length !== 'undefined') {
  89550. end = Math.min(length, src.length);
  89551. start = dstPosition;
  89552. src = src.slice(srcPosition, end + srcPosition);
  89553. } else {
  89554. if (typeof dst !== 'undefined') {
  89555. // src, dst, length
  89556. // rename so we don't get confused
  89557. end = dst;
  89558. end = Math.min(end, src.length);
  89559. } else {
  89560. // src, dst
  89561. end = src.length;
  89562. }
  89563. start = 0;
  89564. // rename so we don't get confused
  89565. dst = srcPosition;
  89566. src = src.slice(0, end);
  89567. }
  89568. // Since we are not returning the array and JavaScript is pass by reference
  89569. // we must modify the actual values of the array
  89570. // instead of reassigning arrays
  89571. Array.prototype.splice.apply(dst, [start, end].concat(src));
  89572. };
  89573. /**
  89574. * Concatenates two arrays, maps to Array.concat(). Does not modify the
  89575. * input arrays.
  89576. *
  89577. * @method concat
  89578. * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat">arr1.concat(arr2)</a> instead.
  89579. * @param {Array} a first Array to concatenate
  89580. * @param {Array} b second Array to concatenate
  89581. * @return {Array} concatenated array
  89582. *
  89583. * @example
  89584. * <div class = 'norender'><code>
  89585. * function setup() {
  89586. * let arr1 = ['A', 'B', 'C'];
  89587. * let arr2 = [1, 2, 3];
  89588. *
  89589. * print(arr1); // ['A','B','C']
  89590. * print(arr2); // [1,2,3]
  89591. *
  89592. * let arr3 = concat(arr1, arr2);
  89593. *
  89594. * print(arr1); // ['A','B','C']
  89595. * print(arr2); // [1, 2, 3]
  89596. * print(arr3); // ['A','B','C', 1, 2, 3]
  89597. * }
  89598. * </code></div>
  89599. */
  89600. _main.default.prototype.concat = function(list0, list1) {
  89601. return list0.concat(list1);
  89602. };
  89603. /**
  89604. * Reverses the order of an array, maps to Array.reverse()
  89605. *
  89606. * @method reverse
  89607. * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse">array.reverse()</a> instead.
  89608. * @param {Array} list Array to reverse
  89609. * @return {Array} the reversed list
  89610. * @example
  89611. * <div class='norender'><code>
  89612. * function setup() {
  89613. * let myArray = ['A', 'B', 'C'];
  89614. * print(myArray); // ['A','B','C']
  89615. *
  89616. * reverse(myArray);
  89617. * print(myArray); // ['C','B','A']
  89618. * }
  89619. * </code></div>
  89620. */
  89621. _main.default.prototype.reverse = function(list) {
  89622. return list.reverse();
  89623. };
  89624. /**
  89625. * Decreases an array by one element and returns the shortened array,
  89626. * maps to Array.pop().
  89627. *
  89628. * @method shorten
  89629. * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop">array.pop()</a> instead.
  89630. * @param {Array} list Array to shorten
  89631. * @return {Array} shortened Array
  89632. * @example
  89633. * <div class = 'norender'><code>
  89634. * function setup() {
  89635. * let myArray = ['A', 'B', 'C'];
  89636. * print(myArray); // ['A', 'B', 'C']
  89637. * let newArray = shorten(myArray);
  89638. * print(myArray); // ['A','B','C']
  89639. * print(newArray); // ['A','B']
  89640. * }
  89641. * </code></div>
  89642. */
  89643. _main.default.prototype.shorten = function(list) {
  89644. list.pop();
  89645. return list;
  89646. };
  89647. /**
  89648. * Randomizes the order of the elements of an array. Implements
  89649. * <a href='http://Bost.Ocks.org/mike/shuffle/' target=_blank>
  89650. * Fisher-Yates Shuffle Algorithm</a>.
  89651. *
  89652. * @method shuffle
  89653. * @param {Array} array Array to shuffle
  89654. * @param {Boolean} [bool] modify passed array
  89655. * @return {Array} shuffled Array
  89656. * @example
  89657. * <div><code>
  89658. * function setup() {
  89659. * let regularArr = ['ABC', 'def', createVector(), TAU, Math.E];
  89660. * print(regularArr);
  89661. * shuffle(regularArr, true); // force modifications to passed array
  89662. * print(regularArr);
  89663. *
  89664. * // By default shuffle() returns a shuffled cloned array:
  89665. * let newArr = shuffle(regularArr);
  89666. * print(regularArr);
  89667. * print(newArr);
  89668. * }
  89669. * </code></div>
  89670. */
  89671. _main.default.prototype.shuffle = function(arr, bool) {
  89672. var isView = ArrayBuffer && ArrayBuffer.isView && ArrayBuffer.isView(arr);
  89673. arr = bool || isView ? arr : arr.slice();
  89674. var rnd,
  89675. tmp,
  89676. idx = arr.length;
  89677. while (idx > 1) {
  89678. rnd = (this.random(0, 1) * idx) | 0;
  89679. tmp = arr[--idx];
  89680. arr[idx] = arr[rnd];
  89681. arr[rnd] = tmp;
  89682. }
  89683. return arr;
  89684. };
  89685. /**
  89686. * Sorts an array of numbers from smallest to largest, or puts an array of
  89687. * words in alphabetical order. The original array is not modified; a
  89688. * re-ordered array is returned. The count parameter states the number of
  89689. * elements to sort. For example, if there are 12 elements in an array and
  89690. * count is set to 5, only the first 5 elements in the array will be sorted.
  89691. *
  89692. * @method sort
  89693. * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort">array.sort()</a> instead.
  89694. * @param {Array} list Array to sort
  89695. * @param {Integer} [count] number of elements to sort, starting from 0
  89696. * @return {Array} the sorted list
  89697. *
  89698. * @example
  89699. * <div class = 'norender'><code>
  89700. * function setup() {
  89701. * let words = ['banana', 'apple', 'pear', 'lime'];
  89702. * print(words); // ['banana', 'apple', 'pear', 'lime']
  89703. * let count = 4; // length of array
  89704. *
  89705. * words = sort(words, count);
  89706. * print(words); // ['apple', 'banana', 'lime', 'pear']
  89707. * }
  89708. * </code></div>
  89709. * <div class = 'norender'><code>
  89710. * function setup() {
  89711. * let numbers = [2, 6, 1, 5, 14, 9, 8, 12];
  89712. * print(numbers); // [2, 6, 1, 5, 14, 9, 8, 12]
  89713. * let count = 5; // Less than the length of the array
  89714. *
  89715. * numbers = sort(numbers, count);
  89716. * print(numbers); // [1,2,5,6,14,9,8,12]
  89717. * }
  89718. * </code></div>
  89719. */
  89720. _main.default.prototype.sort = function(list, count) {
  89721. var arr = count ? list.slice(0, Math.min(count, list.length)) : list;
  89722. var rest = count ? list.slice(Math.min(count, list.length)) : [];
  89723. if (typeof arr[0] === 'string') {
  89724. arr = arr.sort();
  89725. } else {
  89726. arr = arr.sort(function(a, b) {
  89727. return a - b;
  89728. });
  89729. }
  89730. return arr.concat(rest);
  89731. };
  89732. /**
  89733. * Inserts a value or an array of values into an existing array. The first
  89734. * parameter specifies the initial array to be modified, and the second
  89735. * parameter defines the data to be inserted. The third parameter is an index
  89736. * value which specifies the array position from which to insert data.
  89737. * (Remember that array index numbering starts at zero, so the first position
  89738. * is 0, the second position is 1, and so on.)
  89739. *
  89740. * @method splice
  89741. * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice">array.splice()</a> instead.
  89742. * @param {Array} list Array to splice into
  89743. * @param {any} value value to be spliced in
  89744. * @param {Integer} position in the array from which to insert data
  89745. * @return {Array} the list
  89746. *
  89747. * @example
  89748. * <div class = 'norender'><code>
  89749. * function setup() {
  89750. * let myArray = [0, 1, 2, 3, 4];
  89751. * let insArray = ['A', 'B', 'C'];
  89752. * print(myArray); // [0, 1, 2, 3, 4]
  89753. * print(insArray); // ['A','B','C']
  89754. *
  89755. * splice(myArray, insArray, 3);
  89756. * print(myArray); // [0,1,2,'A','B','C',3,4]
  89757. * }
  89758. * </code></div>
  89759. */
  89760. _main.default.prototype.splice = function(list, value, index) {
  89761. // note that splice returns spliced elements and not an array
  89762. Array.prototype.splice.apply(list, [index, 0].concat(value));
  89763. return list;
  89764. };
  89765. /**
  89766. * Extracts an array of elements from an existing array. The list parameter
  89767. * defines the array from which the elements will be copied, and the start
  89768. * and count parameters specify which elements to extract. If no count is
  89769. * given, elements will be extracted from the start to the end of the array.
  89770. * When specifying the start, remember that the first array element is 0.
  89771. * This function does not change the source array.
  89772. *
  89773. * @method subset
  89774. * @deprecated Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice">array.slice()</a> instead.
  89775. * @param {Array} list Array to extract from
  89776. * @param {Integer} start position to begin
  89777. * @param {Integer} [count] number of values to extract
  89778. * @return {Array} Array of extracted elements
  89779. *
  89780. * @example
  89781. * <div class = 'norender'><code>
  89782. * function setup() {
  89783. * let myArray = [1, 2, 3, 4, 5];
  89784. * print(myArray); // [1, 2, 3, 4, 5]
  89785. *
  89786. * let sub1 = subset(myArray, 0, 3);
  89787. * let sub2 = subset(myArray, 2, 2);
  89788. * print(sub1); // [1,2,3]
  89789. * print(sub2); // [3,4]
  89790. * }
  89791. * </code></div>
  89792. */
  89793. _main.default.prototype.subset = function(list, start, count) {
  89794. if (typeof count !== 'undefined') {
  89795. return list.slice(start, start + count);
  89796. } else {
  89797. return list.slice(start, list.length);
  89798. }
  89799. };
  89800. var _default = _main.default;
  89801. exports.default = _default;
  89802. },
  89803. {
  89804. '../core/main': 283,
  89805. 'core-js/modules/es.array-buffer.constructor': 165,
  89806. 'core-js/modules/es.array.concat': 166,
  89807. 'core-js/modules/es.array.slice': 178,
  89808. 'core-js/modules/es.array.splice': 180,
  89809. 'core-js/modules/es.object.to-string': 192
  89810. }
  89811. ],
  89812. 323: [
  89813. function(_dereq_, module, exports) {
  89814. 'use strict';
  89815. _dereq_('core-js/modules/es.array.map');
  89816. _dereq_('core-js/modules/es.number.constructor');
  89817. _dereq_('core-js/modules/es.object.to-string');
  89818. _dereq_('core-js/modules/es.regexp.to-string');
  89819. _dereq_('core-js/modules/es.string.repeat');
  89820. Object.defineProperty(exports, '__esModule', { value: true });
  89821. exports.default = void 0;
  89822. var _main = _interopRequireDefault(_dereq_('../core/main'));
  89823. function _interopRequireDefault(obj) {
  89824. return obj && obj.__esModule ? obj : { default: obj };
  89825. }
  89826. /**
  89827. * @module Data
  89828. * @submodule Conversion
  89829. * @for p5
  89830. * @requires core
  89831. */ /**
  89832. * Converts a string to its floating point representation. The contents of a
  89833. * string must resemble a number, or NaN (not a number) will be returned.
  89834. * For example, float("1234.56") evaluates to 1234.56, but float("giraffe")
  89835. * will return NaN.
  89836. *
  89837. * When an array of values is passed in, then an array of floats of the same
  89838. * length is returned.
  89839. *
  89840. * @method float
  89841. * @param {String} str float string to parse
  89842. * @return {Number} floating point representation of string
  89843. * @example
  89844. * <div><code>
  89845. * let str = '20';
  89846. * let diameter = float(str);
  89847. * ellipse(width / 2, height / 2, diameter, diameter);
  89848. * </code></div>
  89849. * <div class='norender'><code>
  89850. * print(float('10.31')); // 10.31
  89851. * print(float('Infinity')); // Infinity
  89852. * print(float('-Infinity')); // -Infinity
  89853. * </code></div>
  89854. *
  89855. * @alt
  89856. * 20 by 20 white ellipse in the center of the canvas
  89857. */ _main.default.prototype.float = function(str) {
  89858. if (str instanceof Array) {
  89859. return str.map(parseFloat);
  89860. }
  89861. return parseFloat(str);
  89862. };
  89863. /**
  89864. * Converts a boolean, string, or float to its integer representation.
  89865. * When an array of values is passed in, then an int array of the same length
  89866. * is returned.
  89867. *
  89868. * @method int
  89869. * @param {String|Boolean|Number} n value to parse
  89870. * @param {Integer} [radix] the radix to convert to (default: 10)
  89871. * @return {Number} integer representation of value
  89872. *
  89873. * @example
  89874. * <div class='norender'><code>
  89875. * print(int('10')); // 10
  89876. * print(int(10.31)); // 10
  89877. * print(int(-10)); // -10
  89878. * print(int(true)); // 1
  89879. * print(int(false)); // 0
  89880. * print(int([false, true, '10.3', 9.8])); // [0, 1, 10, 9]
  89881. * print(int(Infinity)); // Infinity
  89882. * print(int('-Infinity')); // -Infinity
  89883. * </code></div>
  89884. */
  89885. /**
  89886. * @method int
  89887. * @param {Array} ns values to parse
  89888. * @param {Integer} [radix]
  89889. * @return {Number[]} integer representation of values
  89890. */
  89891. _main.default.prototype.int = function(n) {
  89892. var radix =
  89893. arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
  89894. if (n === Infinity || n === 'Infinity') {
  89895. return Infinity;
  89896. } else if (n === -Infinity || n === '-Infinity') {
  89897. return -Infinity;
  89898. } else if (typeof n === 'string') {
  89899. return parseInt(n, radix);
  89900. } else if (typeof n === 'number') {
  89901. return n | 0;
  89902. } else if (typeof n === 'boolean') {
  89903. return n ? 1 : 0;
  89904. } else if (n instanceof Array) {
  89905. return n.map(function(n) {
  89906. return _main.default.prototype.int(n, radix);
  89907. });
  89908. }
  89909. };
  89910. /**
  89911. * Converts a boolean, string or number to its string representation.
  89912. * When an array of values is passed in, then an array of strings of the same
  89913. * length is returned.
  89914. *
  89915. * @method str
  89916. * @param {String|Boolean|Number|Array} n value to parse
  89917. * @return {String} string representation of value
  89918. * @example
  89919. * <div class='norender'><code>
  89920. * print(str('10')); // "10"
  89921. * print(str(10.31)); // "10.31"
  89922. * print(str(-10)); // "-10"
  89923. * print(str(true)); // "true"
  89924. * print(str(false)); // "false"
  89925. * print(str([true, '10.3', 9.8])); // [ "true", "10.3", "9.8" ]
  89926. * </code></div>
  89927. */
  89928. _main.default.prototype.str = function(n) {
  89929. if (n instanceof Array) {
  89930. return n.map(_main.default.prototype.str);
  89931. } else {
  89932. return String(n);
  89933. }
  89934. };
  89935. /**
  89936. * Converts a number or string to its boolean representation.
  89937. * For a number, any non-zero value (positive or negative) evaluates to true,
  89938. * while zero evaluates to false. For a string, the value "true" evaluates to
  89939. * true, while any other value evaluates to false. When an array of number or
  89940. * string values is passed in, then a array of booleans of the same length is
  89941. * returned.
  89942. *
  89943. * @method boolean
  89944. * @param {String|Boolean|Number|Array} n value to parse
  89945. * @return {Boolean} boolean representation of value
  89946. * @example
  89947. * <div class='norender'><code>
  89948. * print(boolean(0)); // false
  89949. * print(boolean(1)); // true
  89950. * print(boolean('true')); // true
  89951. * print(boolean('abcd')); // false
  89952. * print(boolean([0, 12, 'true'])); // [false, true, true]
  89953. * </code></div>
  89954. */
  89955. _main.default.prototype.boolean = function(n) {
  89956. if (typeof n === 'number') {
  89957. return n !== 0;
  89958. } else if (typeof n === 'string') {
  89959. return n.toLowerCase() === 'true';
  89960. } else if (typeof n === 'boolean') {
  89961. return n;
  89962. } else if (n instanceof Array) {
  89963. return n.map(_main.default.prototype.boolean);
  89964. }
  89965. };
  89966. /**
  89967. * Converts a number, string representation of a number, or boolean to its byte
  89968. * representation. A byte can be only a whole number between -128 and 127, so
  89969. * when a value outside of this range is converted, it wraps around to the
  89970. * corresponding byte representation. When an array of number, string or boolean
  89971. * values is passed in, then an array of bytes the same length is returned.
  89972. *
  89973. * @method byte
  89974. * @param {String|Boolean|Number} n value to parse
  89975. * @return {Number} byte representation of value
  89976. *
  89977. * @example
  89978. * <div class='norender'><code>
  89979. * print(byte(127)); // 127
  89980. * print(byte(128)); // -128
  89981. * print(byte(23.4)); // 23
  89982. * print(byte('23.4')); // 23
  89983. * print(byte('hello')); // NaN
  89984. * print(byte(true)); // 1
  89985. * print(byte([0, 255, '100'])); // [0, -1, 100]
  89986. * </code></div>
  89987. */
  89988. /**
  89989. * @method byte
  89990. * @param {Array} ns values to parse
  89991. * @return {Number[]} array of byte representation of values
  89992. */
  89993. _main.default.prototype.byte = function(n) {
  89994. var nn = _main.default.prototype.int(n, 10);
  89995. if (typeof nn === 'number') {
  89996. return (nn + 128) % 256 - 128;
  89997. } else if (nn instanceof Array) {
  89998. return nn.map(_main.default.prototype.byte);
  89999. }
  90000. };
  90001. /**
  90002. * Converts a number or string to its corresponding single-character
  90003. * string representation. If a string parameter is provided, it is first
  90004. * parsed as an integer and then translated into a single-character string.
  90005. * When an array of number or string values is passed in, then an array of
  90006. * single-character strings of the same length is returned.
  90007. *
  90008. * @method char
  90009. * @param {String|Number} n value to parse
  90010. * @return {String} string representation of value
  90011. *
  90012. * @example
  90013. * <div class='norender'><code>
  90014. * print(char(65)); // "A"
  90015. * print(char('65')); // "A"
  90016. * print(char([65, 66, 67])); // [ "A", "B", "C" ]
  90017. * print(join(char([65, 66, 67]), '')); // "ABC"
  90018. * </code></div>
  90019. */
  90020. /**
  90021. * @method char
  90022. * @param {Array} ns values to parse
  90023. * @return {String[]} array of string representation of values
  90024. */
  90025. _main.default.prototype.char = function(n) {
  90026. if (typeof n === 'number' && !isNaN(n)) {
  90027. return String.fromCharCode(n);
  90028. } else if (n instanceof Array) {
  90029. return n.map(_main.default.prototype.char);
  90030. } else if (typeof n === 'string') {
  90031. return _main.default.prototype.char(parseInt(n, 10));
  90032. }
  90033. };
  90034. /**
  90035. * Converts a single-character string to its corresponding integer
  90036. * representation. When an array of single-character string values is passed
  90037. * in, then an array of integers of the same length is returned.
  90038. *
  90039. * @method unchar
  90040. * @param {String} n value to parse
  90041. * @return {Number} integer representation of value
  90042. *
  90043. * @example
  90044. * <div class='norender'><code>
  90045. * print(unchar('A')); // 65
  90046. * print(unchar(['A', 'B', 'C'])); // [ 65, 66, 67 ]
  90047. * print(unchar(split('ABC', ''))); // [ 65, 66, 67 ]
  90048. * </code></div>
  90049. */
  90050. /**
  90051. * @method unchar
  90052. * @param {Array} ns values to parse
  90053. * @return {Number[]} integer representation of values
  90054. */
  90055. _main.default.prototype.unchar = function(n) {
  90056. if (typeof n === 'string' && n.length === 1) {
  90057. return n.charCodeAt(0);
  90058. } else if (n instanceof Array) {
  90059. return n.map(_main.default.prototype.unchar);
  90060. }
  90061. };
  90062. /**
  90063. * Converts a number to a string in its equivalent hexadecimal notation. If a
  90064. * second parameter is passed, it is used to set the number of characters to
  90065. * generate in the hexadecimal notation. When an array is passed in, an
  90066. * array of strings in hexadecimal notation of the same length is returned.
  90067. *
  90068. * @method hex
  90069. * @param {Number} n value to parse
  90070. * @param {Number} [digits]
  90071. * @return {String} hexadecimal string representation of value
  90072. *
  90073. * @example
  90074. * <div class='norender'><code>
  90075. * print(hex(255)); // "000000FF"
  90076. * print(hex(255, 6)); // "0000FF"
  90077. * print(hex([0, 127, 255], 6)); // [ "000000", "00007F", "0000FF" ]
  90078. * print(Infinity); // "FFFFFFFF"
  90079. * print(-Infinity); // "00000000"
  90080. * </code></div>
  90081. */
  90082. /**
  90083. * @method hex
  90084. * @param {Number[]} ns array of values to parse
  90085. * @param {Number} [digits]
  90086. * @return {String[]} hexadecimal string representation of values
  90087. */
  90088. _main.default.prototype.hex = function(n, digits) {
  90089. digits = digits === undefined || digits === null ? (digits = 8) : digits;
  90090. if (n instanceof Array) {
  90091. return n.map(function(n) {
  90092. return _main.default.prototype.hex(n, digits);
  90093. });
  90094. } else if (n === Infinity || n === -Infinity) {
  90095. var c = n === Infinity ? 'F' : '0';
  90096. return c.repeat(digits);
  90097. } else if (typeof n === 'number') {
  90098. if (n < 0) {
  90099. n = 0xffffffff + n + 1;
  90100. }
  90101. var hex = Number(n)
  90102. .toString(16)
  90103. .toUpperCase();
  90104. while (hex.length < digits) {
  90105. hex = '0'.concat(hex);
  90106. }
  90107. if (hex.length >= digits) {
  90108. hex = hex.substring(hex.length - digits, hex.length);
  90109. }
  90110. return hex;
  90111. }
  90112. };
  90113. /**
  90114. * Converts a string representation of a hexadecimal number to its equivalent
  90115. * integer value. When an array of strings in hexadecimal notation is passed
  90116. * in, an array of integers of the same length is returned.
  90117. *
  90118. * @method unhex
  90119. * @param {String} n value to parse
  90120. * @return {Number} integer representation of hexadecimal value
  90121. *
  90122. * @example
  90123. * <div class='norender'><code>
  90124. * print(unhex('A')); // 10
  90125. * print(unhex('FF')); // 255
  90126. * print(unhex(['FF', 'AA', '00'])); // [ 255, 170, 0 ]
  90127. * </code></div>
  90128. */
  90129. /**
  90130. * @method unhex
  90131. * @param {Array} ns values to parse
  90132. * @return {Number[]} integer representations of hexadecimal value
  90133. */
  90134. _main.default.prototype.unhex = function(n) {
  90135. if (n instanceof Array) {
  90136. return n.map(_main.default.prototype.unhex);
  90137. } else {
  90138. return parseInt('0x'.concat(n), 16);
  90139. }
  90140. };
  90141. var _default = _main.default;
  90142. exports.default = _default;
  90143. },
  90144. {
  90145. '../core/main': 283,
  90146. 'core-js/modules/es.array.map': 177,
  90147. 'core-js/modules/es.number.constructor': 185,
  90148. 'core-js/modules/es.object.to-string': 192,
  90149. 'core-js/modules/es.regexp.to-string': 197,
  90150. 'core-js/modules/es.string.repeat': 203
  90151. }
  90152. ],
  90153. 324: [
  90154. function(_dereq_, module, exports) {
  90155. 'use strict';
  90156. _dereq_('core-js/modules/es.array.filter');
  90157. _dereq_('core-js/modules/es.array.index-of');
  90158. _dereq_('core-js/modules/es.array.join');
  90159. _dereq_('core-js/modules/es.array.map');
  90160. _dereq_('core-js/modules/es.array.slice');
  90161. _dereq_('core-js/modules/es.object.to-string');
  90162. _dereq_('core-js/modules/es.regexp.constructor');
  90163. _dereq_('core-js/modules/es.regexp.exec');
  90164. _dereq_('core-js/modules/es.regexp.to-string');
  90165. _dereq_('core-js/modules/es.string.match');
  90166. _dereq_('core-js/modules/es.string.replace');
  90167. _dereq_('core-js/modules/es.string.split');
  90168. _dereq_('core-js/modules/es.string.trim');
  90169. Object.defineProperty(exports, '__esModule', { value: true });
  90170. exports.default = void 0;
  90171. var _main = _interopRequireDefault(_dereq_('../core/main'));
  90172. _dereq_('../core/friendly_errors/validate_params');
  90173. _dereq_('../core/friendly_errors/file_errors');
  90174. _dereq_('../core/friendly_errors/fes_core');
  90175. function _interopRequireDefault(obj) {
  90176. return obj && obj.__esModule ? obj : { default: obj };
  90177. } /** //return p5; //LM is this a mistake?
  90178. * @module Data
  90179. * @submodule String Functions
  90180. * @for p5
  90181. * @requires core
  90182. */
  90183. /**
  90184. * Combines an array of Strings into one String, each separated by the
  90185. * character(s) used for the separator parameter. To join arrays of ints or
  90186. * floats, it's necessary to first convert them to Strings using <a href="#/p5/nf">nf()</a> or
  90187. * nfs().
  90188. *
  90189. * @method join
  90190. * @param {Array} list array of Strings to be joined
  90191. * @param {String} separator String to be placed between each item
  90192. * @return {String} joined String
  90193. * @example
  90194. * <div>
  90195. * <code>
  90196. * let array = ['Hello', 'world!'];
  90197. * let separator = ' ';
  90198. * let message = join(array, separator);
  90199. * text(message, 5, 50);
  90200. * </code>
  90201. * </div>
  90202. *
  90203. * @alt
  90204. * "hello world!" displayed middle left of canvas.
  90205. */ _main.default.prototype.join = function(list, separator) {
  90206. _main.default._validateParameters('join', arguments);
  90207. return list.join(separator);
  90208. };
  90209. /**
  90210. * This function is used to apply a regular expression to a piece of text,
  90211. * and return matching groups (elements found inside parentheses) as a
  90212. * String array. If there are no matches, a null value will be returned.
  90213. * If no groups are specified in the regular expression, but the sequence
  90214. * matches, an array of length 1 (with the matched text as the first element
  90215. * of the array) will be returned.
  90216. *
  90217. * To use the function, first check to see if the result is null. If the
  90218. * result is null, then the sequence did not match at all. If the sequence
  90219. * did match, an array is returned.
  90220. *
  90221. * If there are groups (specified by sets of parentheses) in the regular
  90222. * expression, then the contents of each will be returned in the array.
  90223. * Element [0] of a regular expression match returns the entire matching
  90224. * string, and the match groups start at element [1] (the first group is [1],
  90225. * the second [2], and so on).
  90226. *
  90227. * @method match
  90228. * @param {String} str the String to be searched
  90229. * @param {String} regexp the regexp to be used for matching
  90230. * @return {String[]} Array of Strings found
  90231. * @example
  90232. * <div>
  90233. * <code>
  90234. * let string = 'Hello p5js*!';
  90235. * let regexp = 'p5js\\*';
  90236. * let m = match(string, regexp);
  90237. * text(m, 5, 50);
  90238. * </code>
  90239. * </div>
  90240. *
  90241. * @alt
  90242. * "p5js*" displayed middle left of canvas.
  90243. */
  90244. _main.default.prototype.match = function(str, reg) {
  90245. _main.default._validateParameters('match', arguments);
  90246. return str.match(reg);
  90247. };
  90248. /**
  90249. * This function is used to apply a regular expression to a piece of text,
  90250. * and return a list of matching groups (elements found inside parentheses)
  90251. * as a two-dimensional String array. If there are no matches, a null value
  90252. * will be returned. If no groups are specified in the regular expression,
  90253. * but the sequence matches, a two dimensional array is still returned, but
  90254. * the second dimension is only of length one.
  90255. *
  90256. * To use the function, first check to see if the result is null. If the
  90257. * result is null, then the sequence did not match at all. If the sequence
  90258. * did match, a 2D array is returned.
  90259. *
  90260. * If there are groups (specified by sets of parentheses) in the regular
  90261. * expression, then the contents of each will be returned in the array.
  90262. * Assuming a loop with counter variable i, element [i][0] of a regular
  90263. * expression match returns the entire matching string, and the match groups
  90264. * start at element [i][1] (the first group is [i][1], the second [i][2],
  90265. * and so on).
  90266. *
  90267. * @method matchAll
  90268. * @param {String} str the String to be searched
  90269. * @param {String} regexp the regexp to be used for matching
  90270. * @return {String[]} 2d Array of Strings found
  90271. * @example
  90272. * <div class="norender">
  90273. * <code>
  90274. * let string = 'Hello p5js*! Hello world!';
  90275. * let regexp = 'Hello';
  90276. * matchAll(string, regexp);
  90277. * </code>
  90278. * </div>
  90279. */
  90280. _main.default.prototype.matchAll = function(str, reg) {
  90281. _main.default._validateParameters('matchAll', arguments);
  90282. var re = new RegExp(reg, 'g');
  90283. var match = re.exec(str);
  90284. var matches = [];
  90285. while (match !== null) {
  90286. matches.push(match);
  90287. // matched text: match[0]
  90288. // match start: match.index
  90289. // capturing group n: match[n]
  90290. match = re.exec(str);
  90291. }
  90292. return matches;
  90293. };
  90294. /**
  90295. * Utility function for formatting numbers into strings. There are two
  90296. * versions: one for formatting floats, and one for formatting ints.
  90297. * The values for the digits, left, and right parameters should always
  90298. * be positive integers.
  90299. * (NOTE): Be cautious when using left and right parameters as it prepends numbers of 0's if the parameter
  90300. * if greater than the current length of the number.
  90301. * For example if number is 123.2 and left parameter passed is 4 which is greater than length of 123
  90302. * (integer part) i.e 3 than result will be 0123.2. Same case for right parameter i.e. if right is 3 than
  90303. * the result will be 123.200.
  90304. *
  90305. * @method nf
  90306. * @param {Number|String} num the Number to format
  90307. * @param {Integer|String} [left] number of digits to the left of the
  90308. * decimal point
  90309. * @param {Integer|String} [right] number of digits to the right of the
  90310. * decimal point
  90311. * @return {String} formatted String
  90312. *
  90313. * @example
  90314. * <div>
  90315. * <code>
  90316. * let myFont;
  90317. * function preload() {
  90318. * myFont = loadFont('assets/fonts/inconsolata.ttf');
  90319. * }
  90320. * function setup() {
  90321. * background(200);
  90322. * let num1 = 321;
  90323. * let num2 = -1321;
  90324. *
  90325. * noStroke();
  90326. * fill(0);
  90327. * textFont(myFont);
  90328. * textSize(22);
  90329. *
  90330. * text(nf(num1, 4, 2), 10, 30);
  90331. * text(nf(num2, 4, 2), 10, 80);
  90332. * // Draw dividing line
  90333. * stroke(120);
  90334. * line(0, 50, width, 50);
  90335. * }
  90336. * </code>
  90337. * </div>
  90338. *
  90339. * @alt
  90340. * "0321.00" middle top, -1321.00" middle bottom canvas
  90341. */
  90342. /**
  90343. * @method nf
  90344. * @param {Array} nums the Numbers to format
  90345. * @param {Integer|String} [left]
  90346. * @param {Integer|String} [right]
  90347. * @return {String[]} formatted Strings
  90348. */
  90349. _main.default.prototype.nf = function(nums, left, right) {
  90350. _main.default._validateParameters('nf', arguments);
  90351. if (nums instanceof Array) {
  90352. return nums.map(function(x) {
  90353. return doNf(x, left, right);
  90354. });
  90355. } else {
  90356. var typeOfFirst = Object.prototype.toString.call(nums);
  90357. if (typeOfFirst === '[object Arguments]') {
  90358. if (nums.length === 3) {
  90359. return this.nf(nums[0], nums[1], nums[2]);
  90360. } else if (nums.length === 2) {
  90361. return this.nf(nums[0], nums[1]);
  90362. } else {
  90363. return this.nf(nums[0]);
  90364. }
  90365. } else {
  90366. return doNf(nums, left, right);
  90367. }
  90368. }
  90369. };
  90370. function doNf(num, left, right) {
  90371. var neg = num < 0;
  90372. var n = neg ? num.toString().substring(1) : num.toString();
  90373. var decimalInd = n.indexOf('.');
  90374. var intPart = decimalInd !== -1 ? n.substring(0, decimalInd) : n;
  90375. var decPart = decimalInd !== -1 ? n.substring(decimalInd + 1) : '';
  90376. var str = neg ? '-' : '';
  90377. if (typeof right !== 'undefined') {
  90378. var decimal = '';
  90379. if (decimalInd !== -1 || right - decPart.length > 0) {
  90380. decimal = '.';
  90381. }
  90382. if (decPart.length > right) {
  90383. decPart = decPart.substring(0, right);
  90384. }
  90385. for (var i = 0; i < left - intPart.length; i++) {
  90386. str += '0';
  90387. }
  90388. str += intPart;
  90389. str += decimal;
  90390. str += decPart;
  90391. for (var j = 0; j < right - decPart.length; j++) {
  90392. str += '0';
  90393. }
  90394. return str;
  90395. } else {
  90396. for (var k = 0; k < Math.max(left - intPart.length, 0); k++) {
  90397. str += '0';
  90398. }
  90399. str += n;
  90400. return str;
  90401. }
  90402. }
  90403. /**
  90404. * Utility function for formatting numbers into strings and placing
  90405. * appropriate commas to mark units of 1000. There are two versions: one
  90406. * for formatting ints, and one for formatting an array of ints. The value
  90407. * for the right parameter should always be a positive integer.
  90408. *
  90409. * @method nfc
  90410. * @param {Number|String} num the Number to format
  90411. * @param {Integer|String} [right] number of digits to the right of the
  90412. * decimal point
  90413. * @return {String} formatted String
  90414. *
  90415. * @example
  90416. * <div>
  90417. * <code>
  90418. * function setup() {
  90419. * background(200);
  90420. * let num = 11253106.115;
  90421. * let numArr = [1, 1, 2];
  90422. *
  90423. * noStroke();
  90424. * fill(0);
  90425. * textSize(12);
  90426. *
  90427. * // Draw formatted numbers
  90428. * text(nfc(num, 4), 10, 30);
  90429. * text(nfc(numArr, 2), 10, 80);
  90430. *
  90431. * // Draw dividing line
  90432. * stroke(120);
  90433. * line(0, 50, width, 50);
  90434. * }
  90435. * </code>
  90436. * </div>
  90437. *
  90438. * @alt
  90439. * "11,253,106.115" top middle and "1.00,1.00,2.00" displayed bottom mid
  90440. */
  90441. /**
  90442. * @method nfc
  90443. * @param {Array} nums the Numbers to format
  90444. * @param {Integer|String} [right]
  90445. * @return {String[]} formatted Strings
  90446. */
  90447. _main.default.prototype.nfc = function(num, right) {
  90448. _main.default._validateParameters('nfc', arguments);
  90449. if (num instanceof Array) {
  90450. return num.map(function(x) {
  90451. return doNfc(x, right);
  90452. });
  90453. } else {
  90454. return doNfc(num, right);
  90455. }
  90456. };
  90457. function doNfc(num, right) {
  90458. num = num.toString();
  90459. var dec = num.indexOf('.');
  90460. var rem = dec !== -1 ? num.substring(dec) : '';
  90461. var n = dec !== -1 ? num.substring(0, dec) : num;
  90462. n = n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  90463. if (right === 0) {
  90464. rem = '';
  90465. } else if (typeof right !== 'undefined') {
  90466. if (right > rem.length) {
  90467. rem += dec === -1 ? '.' : '';
  90468. var len = right - rem.length + 1;
  90469. for (var i = 0; i < len; i++) {
  90470. rem += '0';
  90471. }
  90472. } else {
  90473. rem = rem.substring(0, right + 1);
  90474. }
  90475. }
  90476. return n + rem;
  90477. }
  90478. /**
  90479. * Utility function for formatting numbers into strings. Similar to <a href="#/p5/nf">nf()</a> but
  90480. * puts a "+" in front of positive numbers and a "-" in front of negative
  90481. * numbers. There are two versions: one for formatting floats, and one for
  90482. * formatting ints. The values for left, and right parameters
  90483. * should always be positive integers.
  90484. *
  90485. * @method nfp
  90486. * @param {Number} num the Number to format
  90487. * @param {Integer} [left] number of digits to the left of the decimal
  90488. * point
  90489. * @param {Integer} [right] number of digits to the right of the
  90490. * decimal point
  90491. * @return {String} formatted String
  90492. *
  90493. * @example
  90494. * <div>
  90495. * <code>
  90496. * function setup() {
  90497. * background(200);
  90498. * let num1 = 11253106.115;
  90499. * let num2 = -11253106.115;
  90500. *
  90501. * noStroke();
  90502. * fill(0);
  90503. * textSize(12);
  90504. *
  90505. * // Draw formatted numbers
  90506. * text(nfp(num1, 4, 2), 10, 30);
  90507. * text(nfp(num2, 4, 2), 10, 80);
  90508. *
  90509. * // Draw dividing line
  90510. * stroke(120);
  90511. * line(0, 50, width, 50);
  90512. * }
  90513. * </code>
  90514. * </div>
  90515. *
  90516. * @alt
  90517. * "+11253106.11" top middle and "-11253106.11" displayed bottom middle
  90518. */
  90519. /**
  90520. * @method nfp
  90521. * @param {Number[]} nums the Numbers to format
  90522. * @param {Integer} [left]
  90523. * @param {Integer} [right]
  90524. * @return {String[]} formatted Strings
  90525. */
  90526. _main.default.prototype.nfp = function() {
  90527. for (
  90528. var _len = arguments.length, args = new Array(_len), _key = 0;
  90529. _key < _len;
  90530. _key++
  90531. ) {
  90532. args[_key] = arguments[_key];
  90533. }
  90534. _main.default._validateParameters('nfp', args);
  90535. var nfRes = _main.default.prototype.nf.apply(this, args);
  90536. if (nfRes instanceof Array) {
  90537. return nfRes.map(addNfp);
  90538. } else {
  90539. return addNfp(nfRes);
  90540. }
  90541. };
  90542. function addNfp(num) {
  90543. return parseFloat(num) > 0 ? '+'.concat(num.toString()) : num.toString();
  90544. }
  90545. /**
  90546. * Utility function for formatting numbers into strings. Similar to <a href="#/p5/nf">nf()</a> but
  90547. * puts an additional "_" (space) in front of positive numbers just in case to align it with negative
  90548. * numbers which includes "-" (minus) sign.
  90549. * The main usecase of nfs() can be seen when one wants to align the digits (place values) of a non-negative
  90550. * number with some negative number (See the example to get a clear picture).
  90551. * There are two versions: one for formatting float, and one for formatting int.
  90552. * The values for the digits, left, and right parameters should always be positive integers.
  90553. * (IMP): The result on the canvas basically the expected alignment can vary based on the typeface you are using.
  90554. * (NOTE): Be cautious when using left and right parameters as it prepends numbers of 0's if the parameter
  90555. * if greater than the current length of the number.
  90556. * For example if number is 123.2 and left parameter passed is 4 which is greater than length of 123
  90557. * (integer part) i.e 3 than result will be 0123.2. Same case for right parameter i.e. if right is 3 than
  90558. * the result will be 123.200.
  90559. *
  90560. * @method nfs
  90561. * @param {Number} num the Number to format
  90562. * @param {Integer} [left] number of digits to the left of the decimal
  90563. * point
  90564. * @param {Integer} [right] number of digits to the right of the
  90565. * decimal point
  90566. * @return {String} formatted String
  90567. *
  90568. * @example
  90569. * <div>
  90570. * <code>
  90571. * let myFont;
  90572. * function preload() {
  90573. * myFont = loadFont('assets/fonts/inconsolata.ttf');
  90574. * }
  90575. * function setup() {
  90576. * background(200);
  90577. * let num1 = 321;
  90578. * let num2 = -1321;
  90579. *
  90580. * noStroke();
  90581. * fill(0);
  90582. * textFont(myFont);
  90583. * textSize(22);
  90584. *
  90585. * // nfs() aligns num1 (positive number) with num2 (negative number) by
  90586. * // adding a blank space in front of the num1 (positive number)
  90587. * // [left = 4] in num1 add one 0 in front, to align the digits with num2
  90588. * // [right = 2] in num1 and num2 adds two 0's after both numbers
  90589. * // To see the differences check the example of nf() too.
  90590. * text(nfs(num1, 4, 2), 10, 30);
  90591. * text(nfs(num2, 4, 2), 10, 80);
  90592. * // Draw dividing line
  90593. * stroke(120);
  90594. * line(0, 50, width, 50);
  90595. * }
  90596. * </code>
  90597. * </div>
  90598. *
  90599. * @alt
  90600. * "0321.00" top middle and "-1321.00" displayed bottom middle
  90601. */
  90602. /**
  90603. * @method nfs
  90604. * @param {Array} nums the Numbers to format
  90605. * @param {Integer} [left]
  90606. * @param {Integer} [right]
  90607. * @return {String[]} formatted Strings
  90608. */
  90609. _main.default.prototype.nfs = function() {
  90610. for (
  90611. var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
  90612. _key2 < _len2;
  90613. _key2++
  90614. ) {
  90615. args[_key2] = arguments[_key2];
  90616. }
  90617. _main.default._validateParameters('nfs', args);
  90618. var nfRes = _main.default.prototype.nf.apply(this, args);
  90619. if (nfRes instanceof Array) {
  90620. return nfRes.map(addNfs);
  90621. } else {
  90622. return addNfs(nfRes);
  90623. }
  90624. };
  90625. function addNfs(num) {
  90626. return parseFloat(num) >= 0 ? ' '.concat(num.toString()) : num.toString();
  90627. }
  90628. /**
  90629. * The <a href="#/p5/split">split()</a> function maps to String.split(), it breaks a String into
  90630. * pieces using a character or string as the delimiter. The delim parameter
  90631. * specifies the character or characters that mark the boundaries between
  90632. * each piece. A String[] array is returned that contains each of the pieces.
  90633. *
  90634. * The <a href="#/p5/splitTokens">splitTokens()</a> function works in a similar fashion, except that it
  90635. * splits using a range of characters instead of a specific character or
  90636. * sequence.
  90637. *
  90638. * @method split
  90639. * @param {String} value the String to be split
  90640. * @param {String} delim the String used to separate the data
  90641. * @return {String[]} Array of Strings
  90642. * @example
  90643. * <div>
  90644. * <code>
  90645. * let names = 'Pat,Xio,Alex';
  90646. * let splitString = split(names, ',');
  90647. * text(splitString[0], 5, 30);
  90648. * text(splitString[1], 5, 50);
  90649. * text(splitString[2], 5, 70);
  90650. * </code>
  90651. * </div>
  90652. *
  90653. * @alt
  90654. * "pat" top left, "Xio" mid left and "Alex" displayed bottom left
  90655. */
  90656. _main.default.prototype.split = function(str, delim) {
  90657. _main.default._validateParameters('split', arguments);
  90658. return str.split(delim);
  90659. };
  90660. /**
  90661. * The <a href="#/p5/splitTokens">splitTokens()</a> function splits a String at one or many character
  90662. * delimiters or "tokens." The delim parameter specifies the character or
  90663. * characters to be used as a boundary.
  90664. *
  90665. * If no delim characters are specified, any whitespace character is used to
  90666. * split. Whitespace characters include tab (\t), line feed (\n), carriage
  90667. * return (\r), form feed (\f), and space.
  90668. *
  90669. * @method splitTokens
  90670. * @param {String} value the String to be split
  90671. * @param {String} [delim] list of individual Strings that will be used as
  90672. * separators
  90673. * @return {String[]} Array of Strings
  90674. * @example
  90675. * <div class = "norender">
  90676. * <code>
  90677. * function setup() {
  90678. * let myStr = 'Mango, Banana, Lime';
  90679. * let myStrArr = splitTokens(myStr, ',');
  90680. *
  90681. * print(myStrArr); // prints : ["Mango"," Banana"," Lime"]
  90682. * }
  90683. * </code>
  90684. * </div>
  90685. */
  90686. _main.default.prototype.splitTokens = function(value, delims) {
  90687. _main.default._validateParameters('splitTokens', arguments);
  90688. var d;
  90689. if (typeof delims !== 'undefined') {
  90690. var str = delims;
  90691. var sqc = /\]/g.exec(str);
  90692. var sqo = /\[/g.exec(str);
  90693. if (sqo && sqc) {
  90694. str = str.slice(0, sqc.index) + str.slice(sqc.index + 1);
  90695. sqo = /\[/g.exec(str);
  90696. str = str.slice(0, sqo.index) + str.slice(sqo.index + 1);
  90697. d = new RegExp('[\\['.concat(str, '\\]]'), 'g');
  90698. } else if (sqc) {
  90699. str = str.slice(0, sqc.index) + str.slice(sqc.index + 1);
  90700. d = new RegExp('['.concat(str, '\\]]'), 'g');
  90701. } else if (sqo) {
  90702. str = str.slice(0, sqo.index) + str.slice(sqo.index + 1);
  90703. d = new RegExp('['.concat(str, '\\[]'), 'g');
  90704. } else {
  90705. d = new RegExp('['.concat(str, ']'), 'g');
  90706. }
  90707. } else {
  90708. d = /\s/g;
  90709. }
  90710. return value.split(d).filter(function(n) {
  90711. return n;
  90712. });
  90713. };
  90714. /**
  90715. * Removes whitespace characters from the beginning and end of a String. In
  90716. * addition to standard whitespace characters such as space, carriage return,
  90717. * and tab, this function also removes the Unicode "nbsp" character.
  90718. *
  90719. * @method trim
  90720. * @param {String} str a String to be trimmed
  90721. * @return {String} a trimmed String
  90722. *
  90723. * @example
  90724. * <div>
  90725. * <code>
  90726. * let string = trim(' No new lines\n ');
  90727. * text(string + ' here', 2, 50);
  90728. * </code>
  90729. * </div>
  90730. *
  90731. * @alt
  90732. * "No new lines here" displayed center canvas
  90733. */
  90734. /**
  90735. * @method trim
  90736. * @param {Array} strs an Array of Strings to be trimmed
  90737. * @return {String[]} an Array of trimmed Strings
  90738. */
  90739. _main.default.prototype.trim = function(str) {
  90740. _main.default._validateParameters('trim', arguments);
  90741. if (str instanceof Array) {
  90742. return str.map(this.trim);
  90743. } else {
  90744. return str.trim();
  90745. }
  90746. };
  90747. var _default = _main.default;
  90748. exports.default = _default;
  90749. },
  90750. {
  90751. '../core/friendly_errors/fes_core': 275,
  90752. '../core/friendly_errors/file_errors': 276,
  90753. '../core/friendly_errors/validate_params': 278,
  90754. '../core/main': 283,
  90755. 'core-js/modules/es.array.filter': 169,
  90756. 'core-js/modules/es.array.index-of': 173,
  90757. 'core-js/modules/es.array.join': 175,
  90758. 'core-js/modules/es.array.map': 177,
  90759. 'core-js/modules/es.array.slice': 178,
  90760. 'core-js/modules/es.object.to-string': 192,
  90761. 'core-js/modules/es.regexp.constructor': 195,
  90762. 'core-js/modules/es.regexp.exec': 196,
  90763. 'core-js/modules/es.regexp.to-string': 197,
  90764. 'core-js/modules/es.string.match': 202,
  90765. 'core-js/modules/es.string.replace': 204,
  90766. 'core-js/modules/es.string.split': 206,
  90767. 'core-js/modules/es.string.trim': 208
  90768. }
  90769. ],
  90770. 325: [
  90771. function(_dereq_, module, exports) {
  90772. 'use strict';
  90773. Object.defineProperty(exports, '__esModule', { value: true });
  90774. exports.default = void 0;
  90775. var _main = _interopRequireDefault(_dereq_('../core/main'));
  90776. function _interopRequireDefault(obj) {
  90777. return obj && obj.__esModule ? obj : { default: obj };
  90778. }
  90779. /**
  90780. * @module IO
  90781. * @submodule Time & Date
  90782. * @for p5
  90783. * @requires core
  90784. */ /**
  90785. * p5.js communicates with the clock on your computer. The <a href="#/p5/day">day()</a> function
  90786. * returns the current day as a value from 1 - 31.
  90787. *
  90788. * @method day
  90789. * @return {Integer} the current day
  90790. * @example
  90791. * <div>
  90792. * <code>
  90793. * let d = day();
  90794. * text('Current day: \n' + d, 5, 50);
  90795. * </code>
  90796. * </div>
  90797. *
  90798. * @alt
  90799. * Current day is displayed
  90800. */ _main.default.prototype.day = function() {
  90801. return new Date().getDate();
  90802. };
  90803. /**
  90804. * p5.js communicates with the clock on your computer. The <a href="#/p5/hour">hour()</a> function
  90805. * returns the current hour as a value from 0 - 23.
  90806. *
  90807. * @method hour
  90808. * @return {Integer} the current hour
  90809. * @example
  90810. * <div>
  90811. * <code>
  90812. * let h = hour();
  90813. * text('Current hour:\n' + h, 5, 50);
  90814. * </code>
  90815. * </div>
  90816. *
  90817. * @alt
  90818. * Current hour is displayed
  90819. */
  90820. _main.default.prototype.hour = function() {
  90821. return new Date().getHours();
  90822. };
  90823. /**
  90824. * p5.js communicates with the clock on your computer. The <a href="#/p5/minute">minute()</a> function
  90825. * returns the current minute as a value from 0 - 59.
  90826. *
  90827. * @method minute
  90828. * @return {Integer} the current minute
  90829. * @example
  90830. * <div>
  90831. * <code>
  90832. * let m = minute();
  90833. * text('Current minute: \n' + m, 5, 50);
  90834. * </code>
  90835. * </div>
  90836. *
  90837. * @alt
  90838. * Current minute is displayed
  90839. */
  90840. _main.default.prototype.minute = function() {
  90841. return new Date().getMinutes();
  90842. };
  90843. /**
  90844. * Returns the number of milliseconds (thousandths of a second) since
  90845. * starting the sketch (when `setup()` is called). This information is often
  90846. * used for timing events and animation sequences.
  90847. *
  90848. * @method millis
  90849. * @return {Number} the number of milliseconds since starting the sketch
  90850. * @example
  90851. * <div>
  90852. * <code>
  90853. * let millisecond = millis();
  90854. * text('Milliseconds \nrunning: \n' + millisecond, 5, 40);
  90855. * </code>
  90856. * </div>
  90857. *
  90858. * @alt
  90859. * number of milliseconds since sketch has started displayed
  90860. */
  90861. _main.default.prototype.millis = function() {
  90862. if (this._millisStart === -1) {
  90863. // Sketch has not started
  90864. return 0;
  90865. } else {
  90866. return window.performance.now() - this._millisStart;
  90867. }
  90868. };
  90869. /**
  90870. * p5.js communicates with the clock on your computer. The <a href="#/p5/month">month()</a> function
  90871. * returns the current month as a value from 1 - 12.
  90872. *
  90873. * @method month
  90874. * @return {Integer} the current month
  90875. * @example
  90876. * <div>
  90877. * <code>
  90878. * let m = month();
  90879. * text('Current month: \n' + m, 5, 50);
  90880. * </code>
  90881. * </div>
  90882. *
  90883. * @alt
  90884. * Current month is displayed
  90885. */
  90886. _main.default.prototype.month = function() {
  90887. //January is 0!
  90888. return new Date().getMonth() + 1;
  90889. };
  90890. /**
  90891. * p5.js communicates with the clock on your computer. The <a href="#/p5/second">second()</a> function
  90892. * returns the current second as a value from 0 - 59.
  90893. *
  90894. * @method second
  90895. * @return {Integer} the current second
  90896. * @example
  90897. * <div>
  90898. * <code>
  90899. * let s = second();
  90900. * text('Current second: \n' + s, 5, 50);
  90901. * </code>
  90902. * </div>
  90903. *
  90904. * @alt
  90905. * Current second is displayed
  90906. */
  90907. _main.default.prototype.second = function() {
  90908. return new Date().getSeconds();
  90909. };
  90910. /**
  90911. * p5.js communicates with the clock on your computer. The <a href="#/p5/year">year()</a> function
  90912. * returns the current year as an integer (2014, 2015, 2016, etc).
  90913. *
  90914. * @method year
  90915. * @return {Integer} the current year
  90916. * @example
  90917. * <div>
  90918. * <code>
  90919. * let y = year();
  90920. * text('Current year: \n' + y, 5, 50);
  90921. * </code>
  90922. * </div>
  90923. *
  90924. * @alt
  90925. * Current year is displayed
  90926. */
  90927. _main.default.prototype.year = function() {
  90928. return new Date().getFullYear();
  90929. };
  90930. var _default = _main.default;
  90931. exports.default = _default;
  90932. },
  90933. { '../core/main': 283 }
  90934. ],
  90935. 326: [
  90936. function(_dereq_, module, exports) {
  90937. 'use strict';
  90938. function _typeof(obj) {
  90939. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  90940. _typeof = function _typeof(obj) {
  90941. return typeof obj;
  90942. };
  90943. } else {
  90944. _typeof = function _typeof(obj) {
  90945. return obj &&
  90946. typeof Symbol === 'function' &&
  90947. obj.constructor === Symbol &&
  90948. obj !== Symbol.prototype
  90949. ? 'symbol'
  90950. : typeof obj;
  90951. };
  90952. }
  90953. return _typeof(obj);
  90954. }
  90955. _dereq_('core-js/modules/es.array.concat');
  90956. _dereq_('core-js/modules/es.number.to-fixed');
  90957. Object.defineProperty(exports, '__esModule', { value: true });
  90958. exports.default = void 0;
  90959. var _main = _interopRequireDefault(_dereq_('../core/main'));
  90960. _dereq_('./p5.Geometry');
  90961. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  90962. function _getRequireWildcardCache() {
  90963. if (typeof WeakMap !== 'function') return null;
  90964. var cache = new WeakMap();
  90965. _getRequireWildcardCache = function _getRequireWildcardCache() {
  90966. return cache;
  90967. };
  90968. return cache;
  90969. }
  90970. function _interopRequireWildcard(obj) {
  90971. if (obj && obj.__esModule) {
  90972. return obj;
  90973. }
  90974. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  90975. return { default: obj };
  90976. }
  90977. var cache = _getRequireWildcardCache();
  90978. if (cache && cache.has(obj)) {
  90979. return cache.get(obj);
  90980. }
  90981. var newObj = {};
  90982. var hasPropertyDescriptor =
  90983. Object.defineProperty && Object.getOwnPropertyDescriptor;
  90984. for (var key in obj) {
  90985. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  90986. var desc = hasPropertyDescriptor
  90987. ? Object.getOwnPropertyDescriptor(obj, key)
  90988. : null;
  90989. if (desc && (desc.get || desc.set)) {
  90990. Object.defineProperty(newObj, key, desc);
  90991. } else {
  90992. newObj[key] = obj[key];
  90993. }
  90994. }
  90995. }
  90996. newObj.default = obj;
  90997. if (cache) {
  90998. cache.set(obj, newObj);
  90999. }
  91000. return newObj;
  91001. }
  91002. function _interopRequireDefault(obj) {
  91003. return obj && obj.__esModule ? obj : { default: obj };
  91004. }
  91005. /**
  91006. * @module Shape
  91007. * @submodule 3D Primitives
  91008. * @for p5
  91009. * @requires core
  91010. * @requires p5.Geometry
  91011. */ /**
  91012. * Draw a plane with given a width and height
  91013. * @method plane
  91014. * @param {Number} [width] width of the plane
  91015. * @param {Number} [height] height of the plane
  91016. * @param {Integer} [detailX] Optional number of triangle
  91017. * subdivisions in x-dimension
  91018. * @param {Integer} [detailY] Optional number of triangle
  91019. * subdivisions in y-dimension
  91020. * @chainable
  91021. * @example
  91022. * <div>
  91023. * <code>
  91024. * // draw a plane
  91025. * // with width 50 and height 50
  91026. * function setup() {
  91027. * createCanvas(100, 100, WEBGL);
  91028. * }
  91029. *
  91030. * function draw() {
  91031. * background(200);
  91032. * plane(50, 50);
  91033. * }
  91034. * </code>
  91035. * </div>
  91036. *
  91037. * @alt
  91038. * Nothing displayed on canvas
  91039. * Rotating interior view of a box with sides that change color.
  91040. * 3d red and green gradient.
  91041. * Rotating interior view of a cylinder with sides that change color.
  91042. * Rotating view of a cylinder with sides that change color.
  91043. * 3d red and green gradient.
  91044. * rotating view of a multi-colored cylinder with concave sides.
  91045. */ _main.default.prototype.plane = function(width, height, detailX, detailY) {
  91046. this._assert3d('plane');
  91047. _main.default._validateParameters('plane', arguments);
  91048. if (typeof width === 'undefined') {
  91049. width = 50;
  91050. }
  91051. if (typeof height === 'undefined') {
  91052. height = width;
  91053. }
  91054. if (typeof detailX === 'undefined') {
  91055. detailX = 1;
  91056. }
  91057. if (typeof detailY === 'undefined') {
  91058. detailY = 1;
  91059. }
  91060. var gId = 'plane|'.concat(detailX, '|').concat(detailY);
  91061. if (!this._renderer.geometryInHash(gId)) {
  91062. var _plane = function _plane() {
  91063. var u, v, p;
  91064. for (var i = 0; i <= this.detailY; i++) {
  91065. v = i / this.detailY;
  91066. for (var j = 0; j <= this.detailX; j++) {
  91067. u = j / this.detailX;
  91068. p = new _main.default.Vector(u - 0.5, v - 0.5, 0);
  91069. this.vertices.push(p);
  91070. this.uvs.push(u, v);
  91071. }
  91072. }
  91073. };
  91074. var planeGeom = new _main.default.Geometry(detailX, detailY, _plane);
  91075. planeGeom.computeFaces().computeNormals();
  91076. if (detailX <= 1 && detailY <= 1) {
  91077. planeGeom._makeTriangleEdges()._edgesToVertices();
  91078. } else if (this._renderer._doStroke) {
  91079. console.log(
  91080. 'Cannot draw stroke on plane objects with more' +
  91081. ' than 1 detailX or 1 detailY'
  91082. );
  91083. }
  91084. this._renderer.createBuffers(gId, planeGeom);
  91085. }
  91086. this._renderer.drawBuffersScaled(gId, width, height, 1);
  91087. return this;
  91088. };
  91089. /**
  91090. * Draw a box with given width, height and depth
  91091. * @method box
  91092. * @param {Number} [width] width of the box
  91093. * @param {Number} [Height] height of the box
  91094. * @param {Number} [depth] depth of the box
  91095. * @param {Integer} [detailX] Optional number of triangle
  91096. * subdivisions in x-dimension
  91097. * @param {Integer} [detailY] Optional number of triangle
  91098. * subdivisions in y-dimension
  91099. * @chainable
  91100. * @example
  91101. * <div>
  91102. * <code>
  91103. * // draw a spinning box
  91104. * // with width, height and depth of 50
  91105. * function setup() {
  91106. * createCanvas(100, 100, WEBGL);
  91107. * }
  91108. *
  91109. * function draw() {
  91110. * background(200);
  91111. * rotateX(frameCount * 0.01);
  91112. * rotateY(frameCount * 0.01);
  91113. * box(50);
  91114. * }
  91115. * </code>
  91116. * </div>
  91117. */
  91118. _main.default.prototype.box = function(width, height, depth, detailX, detailY) {
  91119. this._assert3d('box');
  91120. _main.default._validateParameters('box', arguments);
  91121. if (typeof width === 'undefined') {
  91122. width = 50;
  91123. }
  91124. if (typeof height === 'undefined') {
  91125. height = width;
  91126. }
  91127. if (typeof depth === 'undefined') {
  91128. depth = height;
  91129. }
  91130. var perPixelLighting =
  91131. this._renderer.attributes && this._renderer.attributes.perPixelLighting;
  91132. if (typeof detailX === 'undefined') {
  91133. detailX = perPixelLighting ? 1 : 4;
  91134. }
  91135. if (typeof detailY === 'undefined') {
  91136. detailY = perPixelLighting ? 1 : 4;
  91137. }
  91138. var gId = 'box|'.concat(detailX, '|').concat(detailY);
  91139. if (!this._renderer.geometryInHash(gId)) {
  91140. var _box = function _box() {
  91141. var cubeIndices = [
  91142. [0, 4, 2, 6], // -1, 0, 0],// -x
  91143. [1, 3, 5, 7], // +1, 0, 0],// +x
  91144. [0, 1, 4, 5], // 0, -1, 0],// -y
  91145. [2, 6, 3, 7], // 0, +1, 0],// +y
  91146. [0, 2, 1, 3], // 0, 0, -1],// -z
  91147. [4, 5, 6, 7] // 0, 0, +1] // +z
  91148. ];
  91149. //using strokeIndices instead of faces for strokes
  91150. //to avoid diagonal stroke lines across face of box
  91151. this.strokeIndices = [
  91152. [0, 1],
  91153. [1, 3],
  91154. [3, 2],
  91155. [6, 7],
  91156. [8, 9],
  91157. [9, 11],
  91158. [14, 15],
  91159. [16, 17],
  91160. [17, 19],
  91161. [18, 19],
  91162. [20, 21],
  91163. [22, 23]
  91164. ];
  91165. for (var i = 0; i < cubeIndices.length; i++) {
  91166. var cubeIndex = cubeIndices[i];
  91167. var v = i * 4;
  91168. for (var j = 0; j < 4; j++) {
  91169. var d = cubeIndex[j];
  91170. //inspired by lightgl:
  91171. //https://github.com/evanw/lightgl.js
  91172. //octants:https://en.wikipedia.org/wiki/Octant_(solid_geometry)
  91173. var octant = new _main.default.Vector(
  91174. ((d & 1) * 2 - 1) / 2,
  91175. ((d & 2) - 1) / 2,
  91176. ((d & 4) / 2 - 1) / 2
  91177. );
  91178. this.vertices.push(octant);
  91179. this.uvs.push(j & 1, (j & 2) / 2);
  91180. }
  91181. this.faces.push([v, v + 1, v + 2]);
  91182. this.faces.push([v + 2, v + 1, v + 3]);
  91183. }
  91184. };
  91185. var boxGeom = new _main.default.Geometry(detailX, detailY, _box);
  91186. boxGeom.computeNormals();
  91187. if (detailX <= 4 && detailY <= 4) {
  91188. boxGeom._makeTriangleEdges()._edgesToVertices();
  91189. } else if (this._renderer._doStroke) {
  91190. console.log(
  91191. 'Cannot draw stroke on box objects with more' +
  91192. ' than 4 detailX or 4 detailY'
  91193. );
  91194. }
  91195. //initialize our geometry buffer with
  91196. //the key val pair:
  91197. //geometry Id, Geom object
  91198. this._renderer.createBuffers(gId, boxGeom);
  91199. }
  91200. this._renderer.drawBuffersScaled(gId, width, height, depth);
  91201. return this;
  91202. };
  91203. /**
  91204. * Draw a sphere with given radius.
  91205. *
  91206. * DetailX and detailY determines the number of subdivisions in the x-dimension
  91207. * and the y-dimension of a sphere. More subdivisions make the sphere seem
  91208. * smoother. The recommended maximum values are both 24. Using a value greater
  91209. * than 24 may cause a warning or slow down the browser.
  91210. * @method sphere
  91211. * @param {Number} [radius] radius of circle
  91212. * @param {Integer} [detailX] optional number of subdivisions in x-dimension
  91213. * @param {Integer} [detailY] optional number of subdivisions in y-dimension
  91214. *
  91215. * @chainable
  91216. * @example
  91217. * <div>
  91218. * <code>
  91219. * // draw a sphere with radius 40
  91220. * function setup() {
  91221. * createCanvas(100, 100, WEBGL);
  91222. * }
  91223. *
  91224. * function draw() {
  91225. * background(205, 102, 94);
  91226. * sphere(40);
  91227. * }
  91228. * </code>
  91229. * </div>
  91230. *
  91231. * @example
  91232. * <div>
  91233. * <code>
  91234. * let detailX;
  91235. * // slide to see how detailX works
  91236. * function setup() {
  91237. * createCanvas(100, 100, WEBGL);
  91238. * detailX = createSlider(3, 24, 3);
  91239. * detailX.position(10, height + 5);
  91240. * detailX.style('width', '80px');
  91241. * }
  91242. *
  91243. * function draw() {
  91244. * background(205, 105, 94);
  91245. * rotateY(millis() / 1000);
  91246. * sphere(40, detailX.value(), 16);
  91247. * }
  91248. * </code>
  91249. * </div>
  91250. *
  91251. * @example
  91252. * <div>
  91253. * <code>
  91254. * let detailY;
  91255. * // slide to see how detailY works
  91256. * function setup() {
  91257. * createCanvas(100, 100, WEBGL);
  91258. * detailY = createSlider(3, 16, 3);
  91259. * detailY.position(10, height + 5);
  91260. * detailY.style('width', '80px');
  91261. * }
  91262. *
  91263. * function draw() {
  91264. * background(205, 105, 94);
  91265. * rotateY(millis() / 1000);
  91266. * sphere(40, 16, detailY.value());
  91267. * }
  91268. * </code>
  91269. * </div>
  91270. */
  91271. _main.default.prototype.sphere = function(radius, detailX, detailY) {
  91272. this._assert3d('sphere');
  91273. _main.default._validateParameters('sphere', arguments);
  91274. if (typeof radius === 'undefined') {
  91275. radius = 50;
  91276. }
  91277. if (typeof detailX === 'undefined') {
  91278. detailX = 24;
  91279. }
  91280. if (typeof detailY === 'undefined') {
  91281. detailY = 16;
  91282. }
  91283. this.ellipsoid(radius, radius, radius, detailX, detailY);
  91284. return this;
  91285. };
  91286. /**
  91287. * @private
  91288. * Helper function for creating both cones and cylinders
  91289. * Will only generate well-defined geometry when bottomRadius, height > 0
  91290. * and topRadius >= 0
  91291. * If topRadius == 0, topCap should be false
  91292. */
  91293. var _truncatedCone = function _truncatedCone(
  91294. bottomRadius,
  91295. topRadius,
  91296. height,
  91297. detailX,
  91298. detailY,
  91299. bottomCap,
  91300. topCap
  91301. ) {
  91302. bottomRadius = bottomRadius <= 0 ? 1 : bottomRadius;
  91303. topRadius = topRadius < 0 ? 0 : topRadius;
  91304. height = height <= 0 ? bottomRadius : height;
  91305. detailX = detailX < 3 ? 3 : detailX;
  91306. detailY = detailY < 1 ? 1 : detailY;
  91307. bottomCap = bottomCap === undefined ? true : bottomCap;
  91308. topCap = topCap === undefined ? topRadius !== 0 : topCap;
  91309. var start = bottomCap ? -2 : 0;
  91310. var end = detailY + (topCap ? 2 : 0);
  91311. //ensure constant slant for interior vertex normals
  91312. var slant = Math.atan2(bottomRadius - topRadius, height);
  91313. var sinSlant = Math.sin(slant);
  91314. var cosSlant = Math.cos(slant);
  91315. var yy, ii, jj;
  91316. for (yy = start; yy <= end; ++yy) {
  91317. var v = yy / detailY;
  91318. var y = height * v;
  91319. var ringRadius = void 0;
  91320. if (yy < 0) {
  91321. //for the bottomCap edge
  91322. y = 0;
  91323. v = 0;
  91324. ringRadius = bottomRadius;
  91325. } else if (yy > detailY) {
  91326. //for the topCap edge
  91327. y = height;
  91328. v = 1;
  91329. ringRadius = topRadius;
  91330. } else {
  91331. //for the middle
  91332. ringRadius = bottomRadius + (topRadius - bottomRadius) * v;
  91333. }
  91334. if (yy === -2 || yy === detailY + 2) {
  91335. //center of bottom or top caps
  91336. ringRadius = 0;
  91337. }
  91338. y -= height / 2; //shift coordiate origin to the center of object
  91339. for (ii = 0; ii < detailX; ++ii) {
  91340. var u = ii / (detailX - 1);
  91341. var ur = 2 * Math.PI * u;
  91342. var sur = Math.sin(ur);
  91343. var cur = Math.cos(ur);
  91344. //VERTICES
  91345. this.vertices.push(
  91346. new _main.default.Vector(sur * ringRadius, y, cur * ringRadius)
  91347. );
  91348. //VERTEX NORMALS
  91349. var vertexNormal = void 0;
  91350. if (yy < 0) {
  91351. vertexNormal = new _main.default.Vector(0, -1, 0);
  91352. } else if (yy > detailY && topRadius) {
  91353. vertexNormal = new _main.default.Vector(0, 1, 0);
  91354. } else {
  91355. vertexNormal = new _main.default.Vector(
  91356. sur * cosSlant,
  91357. sinSlant,
  91358. cur * cosSlant
  91359. );
  91360. }
  91361. this.vertexNormals.push(vertexNormal);
  91362. //UVs
  91363. this.uvs.push(u, v);
  91364. }
  91365. }
  91366. var startIndex = 0;
  91367. if (bottomCap) {
  91368. for (jj = 0; jj < detailX; ++jj) {
  91369. var nextjj = (jj + 1) % detailX;
  91370. this.faces.push([
  91371. startIndex + jj,
  91372. startIndex + detailX + nextjj,
  91373. startIndex + detailX + jj
  91374. ]);
  91375. }
  91376. startIndex += detailX * 2;
  91377. }
  91378. for (yy = 0; yy < detailY; ++yy) {
  91379. for (ii = 0; ii < detailX; ++ii) {
  91380. var nextii = (ii + 1) % detailX;
  91381. this.faces.push([
  91382. startIndex + ii,
  91383. startIndex + nextii,
  91384. startIndex + detailX + nextii
  91385. ]);
  91386. this.faces.push([
  91387. startIndex + ii,
  91388. startIndex + detailX + nextii,
  91389. startIndex + detailX + ii
  91390. ]);
  91391. }
  91392. startIndex += detailX;
  91393. }
  91394. if (topCap) {
  91395. startIndex += detailX;
  91396. for (ii = 0; ii < detailX; ++ii) {
  91397. this.faces.push([
  91398. startIndex + ii,
  91399. startIndex + (ii + 1) % detailX,
  91400. startIndex + detailX
  91401. ]);
  91402. }
  91403. }
  91404. };
  91405. /**
  91406. * Draw a cylinder with given radius and height
  91407. *
  91408. * DetailX and detailY determines the number of subdivisions in the x-dimension
  91409. * and the y-dimension of a cylinder. More subdivisions make the cylinder seem smoother.
  91410. * The recommended maximum value for detailX is 24. Using a value greater than 24
  91411. * may cause a warning or slow down the browser.
  91412. *
  91413. * @method cylinder
  91414. * @param {Number} [radius] radius of the surface
  91415. * @param {Number} [height] height of the cylinder
  91416. * @param {Integer} [detailX] number of subdivisions in x-dimension;
  91417. * default is 24
  91418. * @param {Integer} [detailY] number of subdivisions in y-dimension;
  91419. * default is 1
  91420. * @param {Boolean} [bottomCap] whether to draw the bottom of the cylinder
  91421. * @param {Boolean} [topCap] whether to draw the top of the cylinder
  91422. * @chainable
  91423. * @example
  91424. * <div>
  91425. * <code>
  91426. * // draw a spinning cylinder
  91427. * // with radius 20 and height 50
  91428. * function setup() {
  91429. * createCanvas(100, 100, WEBGL);
  91430. * }
  91431. *
  91432. * function draw() {
  91433. * background(205, 105, 94);
  91434. * rotateX(frameCount * 0.01);
  91435. * rotateZ(frameCount * 0.01);
  91436. * cylinder(20, 50);
  91437. * }
  91438. * </code>
  91439. * </div>
  91440. *
  91441. * @example
  91442. * <div>
  91443. * <code>
  91444. * // slide to see how detailX works
  91445. * let detailX;
  91446. * function setup() {
  91447. * createCanvas(100, 100, WEBGL);
  91448. * detailX = createSlider(3, 24, 3);
  91449. * detailX.position(10, height + 5);
  91450. * detailX.style('width', '80px');
  91451. * }
  91452. *
  91453. * function draw() {
  91454. * background(205, 105, 94);
  91455. * rotateY(millis() / 1000);
  91456. * cylinder(20, 75, detailX.value(), 1);
  91457. * }
  91458. * </code>
  91459. * </div>
  91460. *
  91461. * @example
  91462. * <div>
  91463. * <code>
  91464. * // slide to see how detailY works
  91465. * let detailY;
  91466. * function setup() {
  91467. * createCanvas(100, 100, WEBGL);
  91468. * detailY = createSlider(1, 16, 1);
  91469. * detailY.position(10, height + 5);
  91470. * detailY.style('width', '80px');
  91471. * }
  91472. *
  91473. * function draw() {
  91474. * background(205, 105, 94);
  91475. * rotateY(millis() / 1000);
  91476. * cylinder(20, 75, 16, detailY.value());
  91477. * }
  91478. * </code>
  91479. * </div>
  91480. */
  91481. _main.default.prototype.cylinder = function(
  91482. radius,
  91483. height,
  91484. detailX,
  91485. detailY,
  91486. bottomCap,
  91487. topCap
  91488. ) {
  91489. this._assert3d('cylinder');
  91490. _main.default._validateParameters('cylinder', arguments);
  91491. if (typeof radius === 'undefined') {
  91492. radius = 50;
  91493. }
  91494. if (typeof height === 'undefined') {
  91495. height = radius;
  91496. }
  91497. if (typeof detailX === 'undefined') {
  91498. detailX = 24;
  91499. }
  91500. if (typeof detailY === 'undefined') {
  91501. detailY = 1;
  91502. }
  91503. if (typeof topCap === 'undefined') {
  91504. topCap = true;
  91505. }
  91506. if (typeof bottomCap === 'undefined') {
  91507. bottomCap = true;
  91508. }
  91509. var gId = 'cylinder|'
  91510. .concat(detailX, '|')
  91511. .concat(detailY, '|')
  91512. .concat(bottomCap, '|')
  91513. .concat(topCap);
  91514. if (!this._renderer.geometryInHash(gId)) {
  91515. var cylinderGeom = new _main.default.Geometry(detailX, detailY);
  91516. _truncatedCone.call(
  91517. cylinderGeom,
  91518. 1,
  91519. 1,
  91520. 1,
  91521. detailX,
  91522. detailY,
  91523. bottomCap,
  91524. topCap
  91525. );
  91526. // normals are computed in call to _truncatedCone
  91527. if (detailX <= 24 && detailY <= 16) {
  91528. cylinderGeom._makeTriangleEdges()._edgesToVertices();
  91529. } else if (this._renderer._doStroke) {
  91530. console.log(
  91531. 'Cannot draw stroke on cylinder objects with more' +
  91532. ' than 24 detailX or 16 detailY'
  91533. );
  91534. }
  91535. this._renderer.createBuffers(gId, cylinderGeom);
  91536. }
  91537. this._renderer.drawBuffersScaled(gId, radius, height, radius);
  91538. return this;
  91539. };
  91540. /**
  91541. * Draw a cone with given radius and height
  91542. *
  91543. * DetailX and detailY determine the number of subdivisions in the x-dimension and
  91544. * the y-dimension of a cone. More subdivisions make the cone seem smoother. The
  91545. * recommended maximum value for detailX is 24. Using a value greater than 24
  91546. * may cause a warning or slow down the browser.
  91547. * @method cone
  91548. * @param {Number} [radius] radius of the bottom surface
  91549. * @param {Number} [height] height of the cone
  91550. * @param {Integer} [detailX] number of segments,
  91551. * the more segments the smoother geometry
  91552. * default is 24
  91553. * @param {Integer} [detailY] number of segments,
  91554. * the more segments the smoother geometry
  91555. * default is 1
  91556. * @param {Boolean} [cap] whether to draw the base of the cone
  91557. * @chainable
  91558. * @example
  91559. * <div>
  91560. * <code>
  91561. * // draw a spinning cone
  91562. * // with radius 40 and height 70
  91563. * function setup() {
  91564. * createCanvas(100, 100, WEBGL);
  91565. * }
  91566. *
  91567. * function draw() {
  91568. * background(200);
  91569. * rotateX(frameCount * 0.01);
  91570. * rotateZ(frameCount * 0.01);
  91571. * cone(40, 70);
  91572. * }
  91573. * </code>
  91574. * </div>
  91575. *
  91576. * @example
  91577. * <div>
  91578. * <code>
  91579. * // slide to see how detailx works
  91580. * let detailX;
  91581. * function setup() {
  91582. * createCanvas(100, 100, WEBGL);
  91583. * detailX = createSlider(3, 16, 3);
  91584. * detailX.position(10, height + 5);
  91585. * detailX.style('width', '80px');
  91586. * }
  91587. *
  91588. * function draw() {
  91589. * background(205, 102, 94);
  91590. * rotateY(millis() / 1000);
  91591. * cone(30, 65, detailX.value(), 16);
  91592. * }
  91593. * </code>
  91594. * </div>
  91595. *
  91596. * @example
  91597. * <div>
  91598. * <code>
  91599. * // slide to see how detailY works
  91600. * let detailY;
  91601. * function setup() {
  91602. * createCanvas(100, 100, WEBGL);
  91603. * detailY = createSlider(3, 16, 3);
  91604. * detailY.position(10, height + 5);
  91605. * detailY.style('width', '80px');
  91606. * }
  91607. *
  91608. * function draw() {
  91609. * background(205, 102, 94);
  91610. * rotateY(millis() / 1000);
  91611. * cone(30, 65, 16, detailY.value());
  91612. * }
  91613. * </code>
  91614. * </div>
  91615. */
  91616. _main.default.prototype.cone = function(radius, height, detailX, detailY, cap) {
  91617. this._assert3d('cone');
  91618. _main.default._validateParameters('cone', arguments);
  91619. if (typeof radius === 'undefined') {
  91620. radius = 50;
  91621. }
  91622. if (typeof height === 'undefined') {
  91623. height = radius;
  91624. }
  91625. if (typeof detailX === 'undefined') {
  91626. detailX = 24;
  91627. }
  91628. if (typeof detailY === 'undefined') {
  91629. detailY = 1;
  91630. }
  91631. if (typeof cap === 'undefined') {
  91632. cap = true;
  91633. }
  91634. var gId = 'cone|'
  91635. .concat(detailX, '|')
  91636. .concat(detailY, '|')
  91637. .concat(cap);
  91638. if (!this._renderer.geometryInHash(gId)) {
  91639. var coneGeom = new _main.default.Geometry(detailX, detailY);
  91640. _truncatedCone.call(coneGeom, 1, 0, 1, detailX, detailY, cap, false);
  91641. if (detailX <= 24 && detailY <= 16) {
  91642. coneGeom._makeTriangleEdges()._edgesToVertices();
  91643. } else if (this._renderer._doStroke) {
  91644. console.log(
  91645. 'Cannot draw stroke on cone objects with more' +
  91646. ' than 24 detailX or 16 detailY'
  91647. );
  91648. }
  91649. this._renderer.createBuffers(gId, coneGeom);
  91650. }
  91651. this._renderer.drawBuffersScaled(gId, radius, height, radius);
  91652. return this;
  91653. };
  91654. /**
  91655. * Draw an ellipsoid with given radius
  91656. *
  91657. * DetailX and detailY determine the number of subdivisions in the x-dimension and
  91658. * the y-dimension of a cone. More subdivisions make the ellipsoid appear to be smoother.
  91659. * Avoid detail number above 150, it may crash the browser.
  91660. * @method ellipsoid
  91661. * @param {Number} [radiusx] x-radius of ellipsoid
  91662. * @param {Number} [radiusy] y-radius of ellipsoid
  91663. * @param {Number} [radiusz] z-radius of ellipsoid
  91664. * @param {Integer} [detailX] number of segments,
  91665. * the more segments the smoother geometry
  91666. * default is 24. Avoid detail number above
  91667. * 150, it may crash the browser.
  91668. * @param {Integer} [detailY] number of segments,
  91669. * the more segments the smoother geometry
  91670. * default is 16. Avoid detail number above
  91671. * 150, it may crash the browser.
  91672. * @chainable
  91673. * @example
  91674. * <div>
  91675. * <code>
  91676. * // draw an ellipsoid
  91677. * // with radius 30, 40 and 40.
  91678. * function setup() {
  91679. * createCanvas(100, 100, WEBGL);
  91680. * }
  91681. *
  91682. * function draw() {
  91683. * background(205, 105, 94);
  91684. * ellipsoid(30, 40, 40);
  91685. * }
  91686. * </code>
  91687. * </div>
  91688. *
  91689. * @example
  91690. * <div>
  91691. * <code>
  91692. * // slide to see how detailX works
  91693. * let detailX;
  91694. * function setup() {
  91695. * createCanvas(100, 100, WEBGL);
  91696. * detailX = createSlider(2, 24, 12);
  91697. * detailX.position(10, height + 5);
  91698. * detailX.style('width', '80px');
  91699. * }
  91700. *
  91701. * function draw() {
  91702. * background(205, 105, 94);
  91703. * rotateY(millis() / 1000);
  91704. * ellipsoid(30, 40, 40, detailX.value(), 8);
  91705. * }
  91706. * </code>
  91707. * </div>
  91708. *
  91709. * @example
  91710. * <div>
  91711. * <code>
  91712. * // slide to see how detailY works
  91713. * let detailY;
  91714. * function setup() {
  91715. * createCanvas(100, 100, WEBGL);
  91716. * detailY = createSlider(2, 24, 6);
  91717. * detailY.position(10, height + 5);
  91718. * detailY.style('width', '80px');
  91719. * }
  91720. *
  91721. * function draw() {
  91722. * background(205, 105, 9);
  91723. * rotateY(millis() / 1000);
  91724. * ellipsoid(30, 40, 40, 12, detailY.value());
  91725. * }
  91726. * </code>
  91727. * </div>
  91728. */
  91729. _main.default.prototype.ellipsoid = function(
  91730. radiusX,
  91731. radiusY,
  91732. radiusZ,
  91733. detailX,
  91734. detailY
  91735. ) {
  91736. this._assert3d('ellipsoid');
  91737. _main.default._validateParameters('ellipsoid', arguments);
  91738. if (typeof radiusX === 'undefined') {
  91739. radiusX = 50;
  91740. }
  91741. if (typeof radiusY === 'undefined') {
  91742. radiusY = radiusX;
  91743. }
  91744. if (typeof radiusZ === 'undefined') {
  91745. radiusZ = radiusX;
  91746. }
  91747. if (typeof detailX === 'undefined') {
  91748. detailX = 24;
  91749. }
  91750. if (typeof detailY === 'undefined') {
  91751. detailY = 16;
  91752. }
  91753. var gId = 'ellipsoid|'.concat(detailX, '|').concat(detailY);
  91754. if (!this._renderer.geometryInHash(gId)) {
  91755. var _ellipsoid = function _ellipsoid() {
  91756. for (var i = 0; i <= this.detailY; i++) {
  91757. var v = i / this.detailY;
  91758. var phi = Math.PI * v - Math.PI / 2;
  91759. var cosPhi = Math.cos(phi);
  91760. var sinPhi = Math.sin(phi);
  91761. for (var j = 0; j <= this.detailX; j++) {
  91762. var u = j / this.detailX;
  91763. var theta = 2 * Math.PI * u;
  91764. var cosTheta = Math.cos(theta);
  91765. var sinTheta = Math.sin(theta);
  91766. var p = new _main.default.Vector(
  91767. cosPhi * sinTheta,
  91768. sinPhi,
  91769. cosPhi * cosTheta
  91770. );
  91771. this.vertices.push(p);
  91772. this.vertexNormals.push(p);
  91773. this.uvs.push(u, v);
  91774. }
  91775. }
  91776. };
  91777. var ellipsoidGeom = new _main.default.Geometry(detailX, detailY, _ellipsoid);
  91778. ellipsoidGeom.computeFaces();
  91779. if (detailX <= 24 && detailY <= 24) {
  91780. ellipsoidGeom._makeTriangleEdges()._edgesToVertices();
  91781. } else if (this._renderer._doStroke) {
  91782. console.log(
  91783. 'Cannot draw stroke on ellipsoids with more' +
  91784. ' than 24 detailX or 24 detailY'
  91785. );
  91786. }
  91787. this._renderer.createBuffers(gId, ellipsoidGeom);
  91788. }
  91789. this._renderer.drawBuffersScaled(gId, radiusX, radiusY, radiusZ);
  91790. return this;
  91791. };
  91792. /**
  91793. * Draw a torus with given radius and tube radius
  91794. *
  91795. * DetailX and detailY determine the number of subdivisions in the x-dimension and
  91796. * the y-dimension of a torus. More subdivisions make the torus appear to be smoother.
  91797. * The default and maximum values for detailX and detailY are 24 and 16, respectively.
  91798. * Setting them to relatively small values like 4 and 6 allows you to create new
  91799. * shapes other than a torus.
  91800. * @method torus
  91801. * @param {Number} [radius] radius of the whole ring
  91802. * @param {Number} [tubeRadius] radius of the tube
  91803. * @param {Integer} [detailX] number of segments in x-dimension,
  91804. * the more segments the smoother geometry
  91805. * default is 24
  91806. * @param {Integer} [detailY] number of segments in y-dimension,
  91807. * the more segments the smoother geometry
  91808. * default is 16
  91809. * @chainable
  91810. * @example
  91811. * <div>
  91812. * <code>
  91813. * // draw a spinning torus
  91814. * // with ring radius 30 and tube radius 15
  91815. * function setup() {
  91816. * createCanvas(100, 100, WEBGL);
  91817. * }
  91818. *
  91819. * function draw() {
  91820. * background(205, 102, 94);
  91821. * rotateX(frameCount * 0.01);
  91822. * rotateY(frameCount * 0.01);
  91823. * torus(30, 15);
  91824. * }
  91825. * </code>
  91826. * </div>
  91827. *
  91828. * @example
  91829. * <div>
  91830. * <code>
  91831. * // slide to see how detailX works
  91832. * let detailX;
  91833. * function setup() {
  91834. * createCanvas(100, 100, WEBGL);
  91835. * detailX = createSlider(3, 24, 3);
  91836. * detailX.position(10, height + 5);
  91837. * detailX.style('width', '80px');
  91838. * }
  91839. *
  91840. * function draw() {
  91841. * background(205, 102, 94);
  91842. * rotateY(millis() / 1000);
  91843. * torus(30, 15, detailX.value(), 12);
  91844. * }
  91845. * </code>
  91846. * </div>
  91847. *
  91848. * @example
  91849. * <div>
  91850. * <code>
  91851. * // slide to see how detailY works
  91852. * let detailY;
  91853. * function setup() {
  91854. * createCanvas(100, 100, WEBGL);
  91855. * detailY = createSlider(3, 16, 3);
  91856. * detailY.position(10, height + 5);
  91857. * detailY.style('width', '80px');
  91858. * }
  91859. *
  91860. * function draw() {
  91861. * background(205, 102, 94);
  91862. * rotateY(millis() / 1000);
  91863. * torus(30, 15, 16, detailY.value());
  91864. * }
  91865. * </code>
  91866. * </div>
  91867. */
  91868. _main.default.prototype.torus = function(radius, tubeRadius, detailX, detailY) {
  91869. this._assert3d('torus');
  91870. _main.default._validateParameters('torus', arguments);
  91871. if (typeof radius === 'undefined') {
  91872. radius = 50;
  91873. } else if (!radius) {
  91874. return; // nothing to draw
  91875. }
  91876. if (typeof tubeRadius === 'undefined') {
  91877. tubeRadius = 10;
  91878. } else if (!tubeRadius) {
  91879. return; // nothing to draw
  91880. }
  91881. if (typeof detailX === 'undefined') {
  91882. detailX = 24;
  91883. }
  91884. if (typeof detailY === 'undefined') {
  91885. detailY = 16;
  91886. }
  91887. var tubeRatio = (tubeRadius / radius).toPrecision(4);
  91888. var gId = 'torus|'
  91889. .concat(tubeRatio, '|')
  91890. .concat(detailX, '|')
  91891. .concat(detailY);
  91892. if (!this._renderer.geometryInHash(gId)) {
  91893. var _torus = function _torus() {
  91894. for (var i = 0; i <= this.detailY; i++) {
  91895. var v = i / this.detailY;
  91896. var phi = 2 * Math.PI * v;
  91897. var cosPhi = Math.cos(phi);
  91898. var sinPhi = Math.sin(phi);
  91899. var r = 1 + tubeRatio * cosPhi;
  91900. for (var j = 0; j <= this.detailX; j++) {
  91901. var u = j / this.detailX;
  91902. var theta = 2 * Math.PI * u;
  91903. var cosTheta = Math.cos(theta);
  91904. var sinTheta = Math.sin(theta);
  91905. var p = new _main.default.Vector(
  91906. r * cosTheta,
  91907. r * sinTheta,
  91908. tubeRatio * sinPhi
  91909. );
  91910. var n = new _main.default.Vector(
  91911. cosPhi * cosTheta,
  91912. cosPhi * sinTheta,
  91913. sinPhi
  91914. );
  91915. this.vertices.push(p);
  91916. this.vertexNormals.push(n);
  91917. this.uvs.push(u, v);
  91918. }
  91919. }
  91920. };
  91921. var torusGeom = new _main.default.Geometry(detailX, detailY, _torus);
  91922. torusGeom.computeFaces();
  91923. if (detailX <= 24 && detailY <= 16) {
  91924. torusGeom._makeTriangleEdges()._edgesToVertices();
  91925. } else if (this._renderer._doStroke) {
  91926. console.log(
  91927. 'Cannot draw strokes on torus object with more' +
  91928. ' than 24 detailX or 16 detailY'
  91929. );
  91930. }
  91931. this._renderer.createBuffers(gId, torusGeom);
  91932. }
  91933. this._renderer.drawBuffersScaled(gId, radius, radius, radius);
  91934. return this;
  91935. };
  91936. ///////////////////////
  91937. /// 2D primitives
  91938. /////////////////////////
  91939. /**
  91940. * Draws a point, a coordinate in space at the dimension of one pixel,
  91941. * given x, y and z coordinates. The color of the point is determined
  91942. * by the current stroke, while the point size is determined by current
  91943. * stroke weight.
  91944. * @private
  91945. * @param {Number} x x-coordinate of point
  91946. * @param {Number} y y-coordinate of point
  91947. * @param {Number} z z-coordinate of point
  91948. * @chainable
  91949. * @example
  91950. * <div>
  91951. * <code>
  91952. * function setup() {
  91953. * createCanvas(100, 100, WEBGL);
  91954. * }
  91955. *
  91956. * function draw() {
  91957. * background(50);
  91958. * stroke(255);
  91959. * strokeWeight(4);
  91960. * point(25, 0);
  91961. * strokeWeight(3);
  91962. * point(-25, 0);
  91963. * strokeWeight(2);
  91964. * point(0, 25);
  91965. * strokeWeight(1);
  91966. * point(0, -25);
  91967. * }
  91968. * </code>
  91969. * </div>
  91970. */
  91971. _main.default.RendererGL.prototype.point = function(x, y, z) {
  91972. if (typeof z === 'undefined') {
  91973. z = 0;
  91974. }
  91975. var _vertex = [];
  91976. _vertex.push(new _main.default.Vector(x, y, z));
  91977. this._drawPoints(_vertex, this.immediateMode.buffers.point);
  91978. return this;
  91979. };
  91980. _main.default.RendererGL.prototype.triangle = function(args) {
  91981. var x1 = args[0],
  91982. y1 = args[1];
  91983. var x2 = args[2],
  91984. y2 = args[3];
  91985. var x3 = args[4],
  91986. y3 = args[5];
  91987. var gId = 'tri';
  91988. if (!this.geometryInHash(gId)) {
  91989. var _triangle = function _triangle() {
  91990. var vertices = [];
  91991. vertices.push(new _main.default.Vector(0, 0, 0));
  91992. vertices.push(new _main.default.Vector(0, 1, 0));
  91993. vertices.push(new _main.default.Vector(1, 0, 0));
  91994. this.strokeIndices = [[0, 1], [1, 2], [2, 0]];
  91995. this.vertices = vertices;
  91996. this.faces = [[0, 1, 2]];
  91997. this.uvs = [0, 0, 0, 1, 1, 1];
  91998. };
  91999. var triGeom = new _main.default.Geometry(1, 1, _triangle);
  92000. triGeom._makeTriangleEdges()._edgesToVertices();
  92001. triGeom.computeNormals();
  92002. this.createBuffers(gId, triGeom);
  92003. }
  92004. // only one triangle is cached, one point is at the origin, and the
  92005. // two adjacent sides are tne unit vectors along the X & Y axes.
  92006. //
  92007. // this matrix multiplication transforms those two unit vectors
  92008. // onto the required vector prior to rendering, and moves the
  92009. // origin appropriately.
  92010. var uMVMatrix = this.uMVMatrix.copy();
  92011. try {
  92012. // prettier-ignore
  92013. var mult = new _main.default.Matrix([
  92014. x2 - x1, y2 - y1, 0, 0, // the resulting unit X-axis
  92015. x3 - x1, y3 - y1, 0, 0, // the resulting unit Y-axis
  92016. 0, 0, 1, 0, // the resulting unit Z-axis (unchanged)
  92017. x1, y1, 0, 1 // the resulting origin
  92018. ]).mult(this.uMVMatrix);
  92019. this.uMVMatrix = mult;
  92020. this.drawBuffers(gId);
  92021. } finally {
  92022. this.uMVMatrix = uMVMatrix;
  92023. }
  92024. return this;
  92025. };
  92026. _main.default.RendererGL.prototype.ellipse = function(args) {
  92027. this.arc(
  92028. args[0],
  92029. args[1],
  92030. args[2],
  92031. args[3],
  92032. 0,
  92033. constants.TWO_PI,
  92034. constants.OPEN,
  92035. args[4]
  92036. );
  92037. };
  92038. _main.default.RendererGL.prototype.arc = function(args) {
  92039. var x = arguments[0];
  92040. var y = arguments[1];
  92041. var width = arguments[2];
  92042. var height = arguments[3];
  92043. var start = arguments[4];
  92044. var stop = arguments[5];
  92045. var mode = arguments[6];
  92046. var detail = arguments[7] || 25;
  92047. var shape;
  92048. var gId;
  92049. // check if it is an ellipse or an arc
  92050. if (Math.abs(stop - start) >= constants.TWO_PI) {
  92051. shape = 'ellipse';
  92052. gId = ''.concat(shape, '|').concat(detail, '|');
  92053. } else {
  92054. shape = 'arc';
  92055. gId = ''
  92056. .concat(shape, '|')
  92057. .concat(start, '|')
  92058. .concat(stop, '|')
  92059. .concat(mode, '|')
  92060. .concat(detail, '|');
  92061. }
  92062. if (!this.geometryInHash(gId)) {
  92063. var _arc = function _arc() {
  92064. this.strokeIndices = [];
  92065. // if the start and stop angles are not the same, push vertices to the array
  92066. if (start.toFixed(10) !== stop.toFixed(10)) {
  92067. // if the mode specified is PIE or null, push the mid point of the arc in vertices
  92068. if (mode === constants.PIE || typeof mode === 'undefined') {
  92069. this.vertices.push(new _main.default.Vector(0.5, 0.5, 0));
  92070. this.uvs.push([0.5, 0.5]);
  92071. }
  92072. // vertices for the perimeter of the circle
  92073. for (var i = 0; i <= detail; i++) {
  92074. var u = i / detail;
  92075. var theta = (stop - start) * u + start;
  92076. var _x = 0.5 + Math.cos(theta) / 2;
  92077. var _y = 0.5 + Math.sin(theta) / 2;
  92078. this.vertices.push(new _main.default.Vector(_x, _y, 0));
  92079. this.uvs.push([_x, _y]);
  92080. if (i < detail - 1) {
  92081. this.faces.push([0, i + 1, i + 2]);
  92082. this.strokeIndices.push([i + 1, i + 2]);
  92083. }
  92084. }
  92085. // check the mode specified in order to push vertices and faces, different for each mode
  92086. switch (mode) {
  92087. case constants.PIE:
  92088. this.faces.push([
  92089. 0,
  92090. this.vertices.length - 2,
  92091. this.vertices.length - 1
  92092. ]);
  92093. this.strokeIndices.push([0, 1]);
  92094. this.strokeIndices.push([
  92095. this.vertices.length - 2,
  92096. this.vertices.length - 1
  92097. ]);
  92098. this.strokeIndices.push([0, this.vertices.length - 1]);
  92099. break;
  92100. case constants.CHORD:
  92101. this.strokeIndices.push([0, 1]);
  92102. this.strokeIndices.push([0, this.vertices.length - 1]);
  92103. break;
  92104. case constants.OPEN:
  92105. this.strokeIndices.push([0, 1]);
  92106. break;
  92107. default:
  92108. this.faces.push([
  92109. 0,
  92110. this.vertices.length - 2,
  92111. this.vertices.length - 1
  92112. ]);
  92113. this.strokeIndices.push([
  92114. this.vertices.length - 2,
  92115. this.vertices.length - 1
  92116. ]);
  92117. }
  92118. }
  92119. };
  92120. var arcGeom = new _main.default.Geometry(detail, 1, _arc);
  92121. arcGeom.computeNormals();
  92122. if (detail <= 50) {
  92123. arcGeom._makeTriangleEdges()._edgesToVertices(arcGeom);
  92124. } else if (this._doStroke) {
  92125. console.log(
  92126. 'Cannot apply a stroke to an '.concat(shape, ' with more than 50 detail')
  92127. );
  92128. }
  92129. this.createBuffers(gId, arcGeom);
  92130. }
  92131. var uMVMatrix = this.uMVMatrix.copy();
  92132. try {
  92133. this.uMVMatrix.translate([x, y, 0]);
  92134. this.uMVMatrix.scale(width, height, 1);
  92135. this.drawBuffers(gId);
  92136. } finally {
  92137. this.uMVMatrix = uMVMatrix;
  92138. }
  92139. return this;
  92140. };
  92141. _main.default.RendererGL.prototype.rect = function(args) {
  92142. var perPixelLighting = this._pInst._glAttributes.perPixelLighting;
  92143. var x = args[0];
  92144. var y = args[1];
  92145. var width = args[2];
  92146. var height = args[3];
  92147. var detailX = args[4] || (perPixelLighting ? 1 : 24);
  92148. var detailY = args[5] || (perPixelLighting ? 1 : 16);
  92149. var gId = 'rect|'.concat(detailX, '|').concat(detailY);
  92150. if (!this.geometryInHash(gId)) {
  92151. var _rect = function _rect() {
  92152. for (var i = 0; i <= this.detailY; i++) {
  92153. var v = i / this.detailY;
  92154. for (var j = 0; j <= this.detailX; j++) {
  92155. var u = j / this.detailX;
  92156. var p = new _main.default.Vector(u, v, 0);
  92157. this.vertices.push(p);
  92158. this.uvs.push(u, v);
  92159. }
  92160. }
  92161. // using stroke indices to avoid stroke over face(s) of rectangle
  92162. if (detailX > 0 && detailY > 0) {
  92163. this.strokeIndices = [
  92164. [0, detailX],
  92165. [detailX, (detailX + 1) * (detailY + 1) - 1],
  92166. [(detailX + 1) * (detailY + 1) - 1, (detailX + 1) * detailY],
  92167. [(detailX + 1) * detailY, 0]
  92168. ];
  92169. }
  92170. };
  92171. var rectGeom = new _main.default.Geometry(detailX, detailY, _rect);
  92172. rectGeom
  92173. .computeFaces()
  92174. .computeNormals()
  92175. ._makeTriangleEdges()
  92176. ._edgesToVertices();
  92177. this.createBuffers(gId, rectGeom);
  92178. }
  92179. // only a single rectangle (of a given detail) is cached: a square with
  92180. // opposite corners at (0,0) & (1,1).
  92181. //
  92182. // before rendering, this square is scaled & moved to the required location.
  92183. var uMVMatrix = this.uMVMatrix.copy();
  92184. try {
  92185. this.uMVMatrix.translate([x, y, 0]);
  92186. this.uMVMatrix.scale(width, height, 1);
  92187. this.drawBuffers(gId);
  92188. } finally {
  92189. this.uMVMatrix = uMVMatrix;
  92190. }
  92191. return this;
  92192. };
  92193. // prettier-ignore
  92194. _main.default.RendererGL.prototype.quad = function (x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, detailX, detailY) {
  92195. if (typeof detailX === 'undefined') {
  92196. detailX = 2;
  92197. }
  92198. if (typeof detailY === 'undefined') {
  92199. detailY = 2;
  92200. }
  92201. var gId = "quad|".concat(
  92202. x1, "|").concat(y1, "|").concat(z1, "|").concat(x2, "|").concat(y2, "|").concat(z2, "|").concat(x3, "|").concat(y3, "|").concat(z3, "|").concat(x4, "|").concat(y4, "|").concat(z4, "|").concat(detailX, "|").concat(detailY);
  92203. if (!this.geometryInHash(gId)) {
  92204. var quadGeom = new _main.default.Geometry(detailX, detailY, function () {
  92205. //algorithm adapted from c++ to js
  92206. //https://stackoverflow.com/questions/16989181/whats-the-correct-way-to-draw-a-distorted-plane-in-opengl/16993202#16993202
  92207. var xRes = 1.0 / (this.detailX - 1);
  92208. var yRes = 1.0 / (this.detailY - 1);
  92209. for (var y = 0; y < this.detailY; y++) {
  92210. for (var x = 0; x < this.detailX; x++) {
  92211. var pctx = x * xRes;
  92212. var pcty = y * yRes;
  92213. var linePt0x = (1 - pcty) * x1 + pcty * x4;
  92214. var linePt0y = (1 - pcty) * y1 + pcty * y4;
  92215. var linePt0z = (1 - pcty) * z1 + pcty * z4;
  92216. var linePt1x = (1 - pcty) * x2 + pcty * x3;
  92217. var linePt1y = (1 - pcty) * y2 + pcty * y3;
  92218. var linePt1z = (1 - pcty) * z2 + pcty * z3;
  92219. var ptx = (1 - pctx) * linePt0x + pctx * linePt1x;
  92220. var pty = (1 - pctx) * linePt0y + pctx * linePt1y;
  92221. var ptz = (1 - pctx) * linePt0z + pctx * linePt1z;
  92222. this.vertices.push(new _main.default.Vector(ptx, pty, ptz));
  92223. this.uvs.push([pctx, pcty]);
  92224. }
  92225. }
  92226. });
  92227. quadGeom.faces = [];
  92228. for (var y = 0; y < detailY - 1; y++) {
  92229. for (var x = 0; x < detailX - 1; x++) {
  92230. var pt0 = x + y * detailX;
  92231. var pt1 = x + 1 + y * detailX;
  92232. var pt2 = x + 1 + (y + 1) * detailX;
  92233. var pt3 = x + (y + 1) * detailX;
  92234. quadGeom.faces.push([pt0, pt1, pt2]);
  92235. quadGeom.faces.push([pt0, pt2, pt3]);
  92236. }
  92237. }
  92238. quadGeom.
  92239. computeNormals().
  92240. _makeTriangleEdges().
  92241. _edgesToVertices();
  92242. this.createBuffers(gId, quadGeom);
  92243. }
  92244. this.drawBuffers(gId);
  92245. return this;
  92246. };
  92247. //this implementation of bezier curve
  92248. //is based on Bernstein polynomial
  92249. // pretier-ignore
  92250. _main.default.RendererGL.prototype.bezier = function(
  92251. x1,
  92252. y1,
  92253. z1, // x2
  92254. x2, // y2
  92255. y2, // x3
  92256. z2, // y3
  92257. x3, // x4
  92258. y3, // y4
  92259. z3,
  92260. x4,
  92261. y4,
  92262. z4
  92263. ) {
  92264. if (arguments.length === 8) {
  92265. y4 = y3;
  92266. x4 = x3;
  92267. y3 = z2;
  92268. x3 = y2;
  92269. y2 = x2;
  92270. x2 = z1;
  92271. z1 = z2 = z3 = z4 = 0;
  92272. }
  92273. var bezierDetail = this._pInst._bezierDetail || 20; //value of Bezier detail
  92274. this.beginShape();
  92275. for (var i = 0; i <= bezierDetail; i++) {
  92276. var c1 = Math.pow(1 - i / bezierDetail, 3);
  92277. var c2 = 3 * (i / bezierDetail) * Math.pow(1 - i / bezierDetail, 2);
  92278. var c3 = 3 * Math.pow(i / bezierDetail, 2) * (1 - i / bezierDetail);
  92279. var c4 = Math.pow(i / bezierDetail, 3);
  92280. this.vertex(
  92281. x1 * c1 + x2 * c2 + x3 * c3 + x4 * c4,
  92282. y1 * c1 + y2 * c2 + y3 * c3 + y4 * c4,
  92283. z1 * c1 + z2 * c2 + z3 * c3 + z4 * c4
  92284. );
  92285. }
  92286. this.endShape();
  92287. return this;
  92288. };
  92289. // pretier-ignore
  92290. _main.default.RendererGL.prototype.curve = function(
  92291. x1,
  92292. y1,
  92293. z1, // x2
  92294. x2, // y2
  92295. y2, // x3
  92296. z2, // y3
  92297. x3, // x4
  92298. y3, // y4
  92299. z3,
  92300. x4,
  92301. y4,
  92302. z4
  92303. ) {
  92304. if (arguments.length === 8) {
  92305. x4 = x3;
  92306. y4 = y3;
  92307. x3 = y2;
  92308. y3 = x2;
  92309. x2 = z1;
  92310. y2 = x2;
  92311. z1 = z2 = z3 = z4 = 0;
  92312. }
  92313. var curveDetail = this._pInst._curveDetail;
  92314. this.beginShape();
  92315. for (var i = 0; i <= curveDetail; i++) {
  92316. var c1 = Math.pow(i / curveDetail, 3) * 0.5;
  92317. var c2 = Math.pow(i / curveDetail, 2) * 0.5;
  92318. var c3 = i / curveDetail * 0.5;
  92319. var c4 = 0.5;
  92320. var vx =
  92321. c1 * (-x1 + 3 * x2 - 3 * x3 + x4) +
  92322. c2 * (2 * x1 - 5 * x2 + 4 * x3 - x4) +
  92323. c3 * (-x1 + x3) +
  92324. c4 * (2 * x2);
  92325. var vy =
  92326. c1 * (-y1 + 3 * y2 - 3 * y3 + y4) +
  92327. c2 * (2 * y1 - 5 * y2 + 4 * y3 - y4) +
  92328. c3 * (-y1 + y3) +
  92329. c4 * (2 * y2);
  92330. var vz =
  92331. c1 * (-z1 + 3 * z2 - 3 * z3 + z4) +
  92332. c2 * (2 * z1 - 5 * z2 + 4 * z3 - z4) +
  92333. c3 * (-z1 + z3) +
  92334. c4 * (2 * z2);
  92335. this.vertex(vx, vy, vz);
  92336. }
  92337. this.endShape();
  92338. return this;
  92339. };
  92340. /**
  92341. * Draw a line given two points
  92342. * @private
  92343. * @param {Number} x0 x-coordinate of first vertex
  92344. * @param {Number} y0 y-coordinate of first vertex
  92345. * @param {Number} z0 z-coordinate of first vertex
  92346. * @param {Number} x1 x-coordinate of second vertex
  92347. * @param {Number} y1 y-coordinate of second vertex
  92348. * @param {Number} z1 z-coordinate of second vertex
  92349. * @chainable
  92350. * @example
  92351. * <div>
  92352. * <code>
  92353. * //draw a line
  92354. * function setup() {
  92355. * createCanvas(100, 100, WEBGL);
  92356. * }
  92357. *
  92358. * function draw() {
  92359. * background(200);
  92360. * rotateX(frameCount * 0.01);
  92361. * rotateY(frameCount * 0.01);
  92362. * // Use fill instead of stroke to change the color of shape.
  92363. * fill(255, 0, 0);
  92364. * line(10, 10, 0, 60, 60, 20);
  92365. * }
  92366. * </code>
  92367. * </div>
  92368. */
  92369. _main.default.RendererGL.prototype.line = function() {
  92370. if (arguments.length === 6) {
  92371. this.beginShape(constants.LINES);
  92372. this.vertex(
  92373. arguments.length <= 0 ? undefined : arguments[0],
  92374. arguments.length <= 1 ? undefined : arguments[1],
  92375. arguments.length <= 2 ? undefined : arguments[2]
  92376. );
  92377. this.vertex(
  92378. arguments.length <= 3 ? undefined : arguments[3],
  92379. arguments.length <= 4 ? undefined : arguments[4],
  92380. arguments.length <= 5 ? undefined : arguments[5]
  92381. );
  92382. this.endShape();
  92383. } else if (arguments.length === 4) {
  92384. this.beginShape(constants.LINES);
  92385. this.vertex(
  92386. arguments.length <= 0 ? undefined : arguments[0],
  92387. arguments.length <= 1 ? undefined : arguments[1],
  92388. 0
  92389. );
  92390. this.vertex(
  92391. arguments.length <= 2 ? undefined : arguments[2],
  92392. arguments.length <= 3 ? undefined : arguments[3],
  92393. 0
  92394. );
  92395. this.endShape();
  92396. }
  92397. return this;
  92398. };
  92399. _main.default.RendererGL.prototype.bezierVertex = function() {
  92400. if (this.immediateMode._bezierVertex.length === 0) {
  92401. throw Error('vertex() must be used once before calling bezierVertex()');
  92402. } else {
  92403. var w_x = [];
  92404. var w_y = [];
  92405. var w_z = [];
  92406. var t, _x, _y, _z, i;
  92407. var argLength = arguments.length;
  92408. t = 0;
  92409. if (
  92410. this._lookUpTableBezier.length === 0 ||
  92411. this._lutBezierDetail !== this._pInst._curveDetail
  92412. ) {
  92413. this._lookUpTableBezier = [];
  92414. this._lutBezierDetail = this._pInst._curveDetail;
  92415. var step = 1 / this._lutBezierDetail;
  92416. var start = 0;
  92417. var end = 1;
  92418. var j = 0;
  92419. while (start < 1) {
  92420. t = parseFloat(start.toFixed(6));
  92421. this._lookUpTableBezier[j] = this._bezierCoefficients(t);
  92422. if (end.toFixed(6) === step.toFixed(6)) {
  92423. t = parseFloat(end.toFixed(6)) + parseFloat(start.toFixed(6));
  92424. ++j;
  92425. this._lookUpTableBezier[j] = this._bezierCoefficients(t);
  92426. break;
  92427. }
  92428. start += step;
  92429. end -= step;
  92430. ++j;
  92431. }
  92432. }
  92433. var LUTLength = this._lookUpTableBezier.length;
  92434. if (argLength === 6) {
  92435. this.isBezier = true;
  92436. w_x = [
  92437. this.immediateMode._bezierVertex[0],
  92438. arguments.length <= 0 ? undefined : arguments[0],
  92439. arguments.length <= 2 ? undefined : arguments[2],
  92440. arguments.length <= 4 ? undefined : arguments[4]
  92441. ];
  92442. w_y = [
  92443. this.immediateMode._bezierVertex[1],
  92444. arguments.length <= 1 ? undefined : arguments[1],
  92445. arguments.length <= 3 ? undefined : arguments[3],
  92446. arguments.length <= 5 ? undefined : arguments[5]
  92447. ];
  92448. for (i = 0; i < LUTLength; i++) {
  92449. _x =
  92450. w_x[0] * this._lookUpTableBezier[i][0] +
  92451. w_x[1] * this._lookUpTableBezier[i][1] +
  92452. w_x[2] * this._lookUpTableBezier[i][2] +
  92453. w_x[3] * this._lookUpTableBezier[i][3];
  92454. _y =
  92455. w_y[0] * this._lookUpTableBezier[i][0] +
  92456. w_y[1] * this._lookUpTableBezier[i][1] +
  92457. w_y[2] * this._lookUpTableBezier[i][2] +
  92458. w_y[3] * this._lookUpTableBezier[i][3];
  92459. this.vertex(_x, _y);
  92460. }
  92461. this.immediateMode._bezierVertex[0] =
  92462. arguments.length <= 4 ? undefined : arguments[4];
  92463. this.immediateMode._bezierVertex[1] =
  92464. arguments.length <= 5 ? undefined : arguments[5];
  92465. } else if (argLength === 9) {
  92466. this.isBezier = true;
  92467. w_x = [
  92468. this.immediateMode._bezierVertex[0],
  92469. arguments.length <= 0 ? undefined : arguments[0],
  92470. arguments.length <= 3 ? undefined : arguments[3],
  92471. arguments.length <= 6 ? undefined : arguments[6]
  92472. ];
  92473. w_y = [
  92474. this.immediateMode._bezierVertex[1],
  92475. arguments.length <= 1 ? undefined : arguments[1],
  92476. arguments.length <= 4 ? undefined : arguments[4],
  92477. arguments.length <= 7 ? undefined : arguments[7]
  92478. ];
  92479. w_z = [
  92480. this.immediateMode._bezierVertex[2],
  92481. arguments.length <= 2 ? undefined : arguments[2],
  92482. arguments.length <= 5 ? undefined : arguments[5],
  92483. arguments.length <= 8 ? undefined : arguments[8]
  92484. ];
  92485. for (i = 0; i < LUTLength; i++) {
  92486. _x =
  92487. w_x[0] * this._lookUpTableBezier[i][0] +
  92488. w_x[1] * this._lookUpTableBezier[i][1] +
  92489. w_x[2] * this._lookUpTableBezier[i][2] +
  92490. w_x[3] * this._lookUpTableBezier[i][3];
  92491. _y =
  92492. w_y[0] * this._lookUpTableBezier[i][0] +
  92493. w_y[1] * this._lookUpTableBezier[i][1] +
  92494. w_y[2] * this._lookUpTableBezier[i][2] +
  92495. w_y[3] * this._lookUpTableBezier[i][3];
  92496. _z =
  92497. w_z[0] * this._lookUpTableBezier[i][0] +
  92498. w_z[1] * this._lookUpTableBezier[i][1] +
  92499. w_z[2] * this._lookUpTableBezier[i][2] +
  92500. w_z[3] * this._lookUpTableBezier[i][3];
  92501. this.vertex(_x, _y, _z);
  92502. }
  92503. this.immediateMode._bezierVertex[0] =
  92504. arguments.length <= 6 ? undefined : arguments[6];
  92505. this.immediateMode._bezierVertex[1] =
  92506. arguments.length <= 7 ? undefined : arguments[7];
  92507. this.immediateMode._bezierVertex[2] =
  92508. arguments.length <= 8 ? undefined : arguments[8];
  92509. }
  92510. }
  92511. };
  92512. _main.default.RendererGL.prototype.quadraticVertex = function() {
  92513. if (this.immediateMode._quadraticVertex.length === 0) {
  92514. throw Error('vertex() must be used once before calling quadraticVertex()');
  92515. } else {
  92516. var w_x = [];
  92517. var w_y = [];
  92518. var w_z = [];
  92519. var t, _x, _y, _z, i;
  92520. var argLength = arguments.length;
  92521. t = 0;
  92522. if (
  92523. this._lookUpTableQuadratic.length === 0 ||
  92524. this._lutQuadraticDetail !== this._pInst._curveDetail
  92525. ) {
  92526. this._lookUpTableQuadratic = [];
  92527. this._lutQuadraticDetail = this._pInst._curveDetail;
  92528. var step = 1 / this._lutQuadraticDetail;
  92529. var start = 0;
  92530. var end = 1;
  92531. var j = 0;
  92532. while (start < 1) {
  92533. t = parseFloat(start.toFixed(6));
  92534. this._lookUpTableQuadratic[j] = this._quadraticCoefficients(t);
  92535. if (end.toFixed(6) === step.toFixed(6)) {
  92536. t = parseFloat(end.toFixed(6)) + parseFloat(start.toFixed(6));
  92537. ++j;
  92538. this._lookUpTableQuadratic[j] = this._quadraticCoefficients(t);
  92539. break;
  92540. }
  92541. start += step;
  92542. end -= step;
  92543. ++j;
  92544. }
  92545. }
  92546. var LUTLength = this._lookUpTableQuadratic.length;
  92547. if (argLength === 4) {
  92548. this.isQuadratic = true;
  92549. w_x = [
  92550. this.immediateMode._quadraticVertex[0],
  92551. arguments.length <= 0 ? undefined : arguments[0],
  92552. arguments.length <= 2 ? undefined : arguments[2]
  92553. ];
  92554. w_y = [
  92555. this.immediateMode._quadraticVertex[1],
  92556. arguments.length <= 1 ? undefined : arguments[1],
  92557. arguments.length <= 3 ? undefined : arguments[3]
  92558. ];
  92559. for (i = 0; i < LUTLength; i++) {
  92560. _x =
  92561. w_x[0] * this._lookUpTableQuadratic[i][0] +
  92562. w_x[1] * this._lookUpTableQuadratic[i][1] +
  92563. w_x[2] * this._lookUpTableQuadratic[i][2];
  92564. _y =
  92565. w_y[0] * this._lookUpTableQuadratic[i][0] +
  92566. w_y[1] * this._lookUpTableQuadratic[i][1] +
  92567. w_y[2] * this._lookUpTableQuadratic[i][2];
  92568. this.vertex(_x, _y);
  92569. }
  92570. this.immediateMode._quadraticVertex[0] =
  92571. arguments.length <= 2 ? undefined : arguments[2];
  92572. this.immediateMode._quadraticVertex[1] =
  92573. arguments.length <= 3 ? undefined : arguments[3];
  92574. } else if (argLength === 6) {
  92575. this.isQuadratic = true;
  92576. w_x = [
  92577. this.immediateMode._quadraticVertex[0],
  92578. arguments.length <= 0 ? undefined : arguments[0],
  92579. arguments.length <= 3 ? undefined : arguments[3]
  92580. ];
  92581. w_y = [
  92582. this.immediateMode._quadraticVertex[1],
  92583. arguments.length <= 1 ? undefined : arguments[1],
  92584. arguments.length <= 4 ? undefined : arguments[4]
  92585. ];
  92586. w_z = [
  92587. this.immediateMode._quadraticVertex[2],
  92588. arguments.length <= 2 ? undefined : arguments[2],
  92589. arguments.length <= 5 ? undefined : arguments[5]
  92590. ];
  92591. for (i = 0; i < LUTLength; i++) {
  92592. _x =
  92593. w_x[0] * this._lookUpTableQuadratic[i][0] +
  92594. w_x[1] * this._lookUpTableQuadratic[i][1] +
  92595. w_x[2] * this._lookUpTableQuadratic[i][2];
  92596. _y =
  92597. w_y[0] * this._lookUpTableQuadratic[i][0] +
  92598. w_y[1] * this._lookUpTableQuadratic[i][1] +
  92599. w_y[2] * this._lookUpTableQuadratic[i][2];
  92600. _z =
  92601. w_z[0] * this._lookUpTableQuadratic[i][0] +
  92602. w_z[1] * this._lookUpTableQuadratic[i][1] +
  92603. w_z[2] * this._lookUpTableQuadratic[i][2];
  92604. this.vertex(_x, _y, _z);
  92605. }
  92606. this.immediateMode._quadraticVertex[0] =
  92607. arguments.length <= 3 ? undefined : arguments[3];
  92608. this.immediateMode._quadraticVertex[1] =
  92609. arguments.length <= 4 ? undefined : arguments[4];
  92610. this.immediateMode._quadraticVertex[2] =
  92611. arguments.length <= 5 ? undefined : arguments[5];
  92612. }
  92613. }
  92614. };
  92615. _main.default.RendererGL.prototype.curveVertex = function() {
  92616. var w_x = [];
  92617. var w_y = [];
  92618. var w_z = [];
  92619. var t, _x, _y, _z, i;
  92620. t = 0;
  92621. var argLength = arguments.length;
  92622. if (
  92623. this._lookUpTableBezier.length === 0 ||
  92624. this._lutBezierDetail !== this._pInst._curveDetail
  92625. ) {
  92626. this._lookUpTableBezier = [];
  92627. this._lutBezierDetail = this._pInst._curveDetail;
  92628. var step = 1 / this._lutBezierDetail;
  92629. var start = 0;
  92630. var end = 1;
  92631. var j = 0;
  92632. while (start < 1) {
  92633. t = parseFloat(start.toFixed(6));
  92634. this._lookUpTableBezier[j] = this._bezierCoefficients(t);
  92635. if (end.toFixed(6) === step.toFixed(6)) {
  92636. t = parseFloat(end.toFixed(6)) + parseFloat(start.toFixed(6));
  92637. ++j;
  92638. this._lookUpTableBezier[j] = this._bezierCoefficients(t);
  92639. break;
  92640. }
  92641. start += step;
  92642. end -= step;
  92643. ++j;
  92644. }
  92645. }
  92646. var LUTLength = this._lookUpTableBezier.length;
  92647. if (argLength === 2) {
  92648. this.immediateMode._curveVertex.push(
  92649. arguments.length <= 0 ? undefined : arguments[0]
  92650. );
  92651. this.immediateMode._curveVertex.push(
  92652. arguments.length <= 1 ? undefined : arguments[1]
  92653. );
  92654. if (this.immediateMode._curveVertex.length === 8) {
  92655. this.isCurve = true;
  92656. w_x = this._bezierToCatmull([
  92657. this.immediateMode._curveVertex[0],
  92658. this.immediateMode._curveVertex[2],
  92659. this.immediateMode._curveVertex[4],
  92660. this.immediateMode._curveVertex[6]
  92661. ]);
  92662. w_y = this._bezierToCatmull([
  92663. this.immediateMode._curveVertex[1],
  92664. this.immediateMode._curveVertex[3],
  92665. this.immediateMode._curveVertex[5],
  92666. this.immediateMode._curveVertex[7]
  92667. ]);
  92668. for (i = 0; i < LUTLength; i++) {
  92669. _x =
  92670. w_x[0] * this._lookUpTableBezier[i][0] +
  92671. w_x[1] * this._lookUpTableBezier[i][1] +
  92672. w_x[2] * this._lookUpTableBezier[i][2] +
  92673. w_x[3] * this._lookUpTableBezier[i][3];
  92674. _y =
  92675. w_y[0] * this._lookUpTableBezier[i][0] +
  92676. w_y[1] * this._lookUpTableBezier[i][1] +
  92677. w_y[2] * this._lookUpTableBezier[i][2] +
  92678. w_y[3] * this._lookUpTableBezier[i][3];
  92679. this.vertex(_x, _y);
  92680. }
  92681. for (i = 0; i < argLength; i++) {
  92682. this.immediateMode._curveVertex.shift();
  92683. }
  92684. }
  92685. } else if (argLength === 3) {
  92686. this.immediateMode._curveVertex.push(
  92687. arguments.length <= 0 ? undefined : arguments[0]
  92688. );
  92689. this.immediateMode._curveVertex.push(
  92690. arguments.length <= 1 ? undefined : arguments[1]
  92691. );
  92692. this.immediateMode._curveVertex.push(
  92693. arguments.length <= 2 ? undefined : arguments[2]
  92694. );
  92695. if (this.immediateMode._curveVertex.length === 12) {
  92696. this.isCurve = true;
  92697. w_x = this._bezierToCatmull([
  92698. this.immediateMode._curveVertex[0],
  92699. this.immediateMode._curveVertex[3],
  92700. this.immediateMode._curveVertex[6],
  92701. this.immediateMode._curveVertex[9]
  92702. ]);
  92703. w_y = this._bezierToCatmull([
  92704. this.immediateMode._curveVertex[1],
  92705. this.immediateMode._curveVertex[4],
  92706. this.immediateMode._curveVertex[7],
  92707. this.immediateMode._curveVertex[10]
  92708. ]);
  92709. w_z = this._bezierToCatmull([
  92710. this.immediateMode._curveVertex[2],
  92711. this.immediateMode._curveVertex[5],
  92712. this.immediateMode._curveVertex[8],
  92713. this.immediateMode._curveVertex[11]
  92714. ]);
  92715. for (i = 0; i < LUTLength; i++) {
  92716. _x =
  92717. w_x[0] * this._lookUpTableBezier[i][0] +
  92718. w_x[1] * this._lookUpTableBezier[i][1] +
  92719. w_x[2] * this._lookUpTableBezier[i][2] +
  92720. w_x[3] * this._lookUpTableBezier[i][3];
  92721. _y =
  92722. w_y[0] * this._lookUpTableBezier[i][0] +
  92723. w_y[1] * this._lookUpTableBezier[i][1] +
  92724. w_y[2] * this._lookUpTableBezier[i][2] +
  92725. w_y[3] * this._lookUpTableBezier[i][3];
  92726. _z =
  92727. w_z[0] * this._lookUpTableBezier[i][0] +
  92728. w_z[1] * this._lookUpTableBezier[i][1] +
  92729. w_z[2] * this._lookUpTableBezier[i][2] +
  92730. w_z[3] * this._lookUpTableBezier[i][3];
  92731. this.vertex(_x, _y, _z);
  92732. }
  92733. for (i = 0; i < argLength; i++) {
  92734. this.immediateMode._curveVertex.shift();
  92735. }
  92736. }
  92737. }
  92738. };
  92739. _main.default.RendererGL.prototype.image = function(
  92740. img,
  92741. sx,
  92742. sy,
  92743. sWidth,
  92744. sHeight,
  92745. dx,
  92746. dy,
  92747. dWidth,
  92748. dHeight
  92749. ) {
  92750. if (this._isErasing) {
  92751. this.blendMode(this._cachedBlendMode);
  92752. }
  92753. this._pInst.push();
  92754. this._pInst.noLights();
  92755. this._pInst.texture(img);
  92756. this._pInst.textureMode(constants.NORMAL);
  92757. var u0 = 0;
  92758. if (sx <= img.width) {
  92759. u0 = sx / img.width;
  92760. }
  92761. var u1 = 1;
  92762. if (sx + sWidth <= img.width) {
  92763. u1 = (sx + sWidth) / img.width;
  92764. }
  92765. var v0 = 0;
  92766. if (sy <= img.height) {
  92767. v0 = sy / img.height;
  92768. }
  92769. var v1 = 1;
  92770. if (sy + sHeight <= img.height) {
  92771. v1 = (sy + sHeight) / img.height;
  92772. }
  92773. this.beginShape();
  92774. this.vertex(dx, dy, 0, u0, v0);
  92775. this.vertex(dx + dWidth, dy, 0, u1, v0);
  92776. this.vertex(dx + dWidth, dy + dHeight, 0, u1, v1);
  92777. this.vertex(dx, dy + dHeight, 0, u0, v1);
  92778. this.endShape(constants.CLOSE);
  92779. this._pInst.pop();
  92780. if (this._isErasing) {
  92781. this.blendMode(constants.REMOVE);
  92782. }
  92783. };
  92784. var _default = _main.default;
  92785. exports.default = _default;
  92786. },
  92787. {
  92788. '../core/constants': 272,
  92789. '../core/main': 283,
  92790. './p5.Geometry': 332,
  92791. 'core-js/modules/es.array.concat': 166,
  92792. 'core-js/modules/es.number.to-fixed': 187
  92793. }
  92794. ],
  92795. 327: [
  92796. function(_dereq_, module, exports) {
  92797. 'use strict';
  92798. function _typeof(obj) {
  92799. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  92800. _typeof = function _typeof(obj) {
  92801. return typeof obj;
  92802. };
  92803. } else {
  92804. _typeof = function _typeof(obj) {
  92805. return obj &&
  92806. typeof Symbol === 'function' &&
  92807. obj.constructor === Symbol &&
  92808. obj !== Symbol.prototype
  92809. ? 'symbol'
  92810. : typeof obj;
  92811. };
  92812. }
  92813. return _typeof(obj);
  92814. }
  92815. _dereq_('core-js/modules/es.array.splice');
  92816. _dereq_('core-js/modules/es.object.to-string');
  92817. _dereq_('core-js/modules/es.regexp.to-string');
  92818. Object.defineProperty(exports, '__esModule', { value: true });
  92819. exports.default = void 0;
  92820. var _main = _interopRequireDefault(_dereq_('../core/main'));
  92821. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  92822. function _getRequireWildcardCache() {
  92823. if (typeof WeakMap !== 'function') return null;
  92824. var cache = new WeakMap();
  92825. _getRequireWildcardCache = function _getRequireWildcardCache() {
  92826. return cache;
  92827. };
  92828. return cache;
  92829. }
  92830. function _interopRequireWildcard(obj) {
  92831. if (obj && obj.__esModule) {
  92832. return obj;
  92833. }
  92834. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  92835. return { default: obj };
  92836. }
  92837. var cache = _getRequireWildcardCache();
  92838. if (cache && cache.has(obj)) {
  92839. return cache.get(obj);
  92840. }
  92841. var newObj = {};
  92842. var hasPropertyDescriptor =
  92843. Object.defineProperty && Object.getOwnPropertyDescriptor;
  92844. for (var key in obj) {
  92845. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  92846. var desc = hasPropertyDescriptor
  92847. ? Object.getOwnPropertyDescriptor(obj, key)
  92848. : null;
  92849. if (desc && (desc.get || desc.set)) {
  92850. Object.defineProperty(newObj, key, desc);
  92851. } else {
  92852. newObj[key] = obj[key];
  92853. }
  92854. }
  92855. }
  92856. newObj.default = obj;
  92857. if (cache) {
  92858. cache.set(obj, newObj);
  92859. }
  92860. return newObj;
  92861. }
  92862. function _interopRequireDefault(obj) {
  92863. return obj && obj.__esModule ? obj : { default: obj };
  92864. } /** // implementation based on three.js 'orbitControls':
  92865. * @module Lights, Camera
  92866. * @submodule Interaction
  92867. * @for p5
  92868. * @requires core
  92869. */ /**
  92870. * Allows movement around a 3D sketch using a mouse or trackpad. Left-clicking
  92871. * and dragging will rotate the camera position about the center of the sketch,
  92872. * right-clicking and dragging will pan the camera position without rotation,
  92873. * and using the mouse wheel (scrolling) will move the camera closer or further
  92874. * from the center of the sketch. This function can be called with parameters
  92875. * dictating sensitivity to mouse movement along the X and Y axes. Calling
  92876. * this function without parameters is equivalent to calling orbitControl(1,1).
  92877. * To reverse direction of movement in either axis, enter a negative number
  92878. * for sensitivity.
  92879. * @method orbitControl
  92880. * @for p5
  92881. * @param {Number} [sensitivityX] sensitivity to mouse movement along X axis
  92882. * @param {Number} [sensitivityY] sensitivity to mouse movement along Y axis
  92883. * @param {Number} [sensitivityZ] sensitivity to scroll movement along Z axis
  92884. * @chainable
  92885. * @example
  92886. * <div>
  92887. * <code>
  92888. * function setup() {
  92889. * createCanvas(100, 100, WEBGL);
  92890. * normalMaterial();
  92891. * }
  92892. * function draw() {
  92893. * background(200);
  92894. * orbitControl();
  92895. * rotateY(0.5);
  92896. * box(30, 50);
  92897. * }
  92898. * </code>
  92899. * </div>
  92900. *
  92901. * @alt
  92902. * Camera orbits around a box when mouse is hold-clicked & then moved.
  92903. */
  92904. // https://github.com/mrdoob/three.js/blob/dev/examples/js/controls/OrbitControls.js
  92905. _main.default.prototype.orbitControl = function(
  92906. sensitivityX,
  92907. sensitivityY,
  92908. sensitivityZ
  92909. ) {
  92910. this._assert3d('orbitControl');
  92911. _main.default._validateParameters('orbitControl', arguments);
  92912. // If the mouse is not in bounds of the canvas, disable all behaviors:
  92913. var mouseInCanvas =
  92914. this.mouseX < this.width &&
  92915. this.mouseX > 0 &&
  92916. this.mouseY < this.height &&
  92917. this.mouseY > 0;
  92918. if (!mouseInCanvas) return;
  92919. var cam = this._renderer._curCamera;
  92920. if (typeof sensitivityX === 'undefined') {
  92921. sensitivityX = 1;
  92922. }
  92923. if (typeof sensitivityY === 'undefined') {
  92924. sensitivityY = sensitivityX;
  92925. }
  92926. if (typeof sensitivityZ === 'undefined') {
  92927. sensitivityZ = 0.5;
  92928. }
  92929. // default right-mouse and mouse-wheel behaviors (context menu and scrolling,
  92930. // respectively) are disabled here to allow use of those events for panning and
  92931. // zooming
  92932. // disable context menu for canvas element and add 'contextMenuDisabled'
  92933. // flag to p5 instance
  92934. if (this.contextMenuDisabled !== true) {
  92935. this.canvas.oncontextmenu = function() {
  92936. return false;
  92937. };
  92938. this._setProperty('contextMenuDisabled', true);
  92939. }
  92940. // disable default scrolling behavior on the canvas element and add
  92941. // 'wheelDefaultDisabled' flag to p5 instance
  92942. if (this.wheelDefaultDisabled !== true) {
  92943. this.canvas.onwheel = function() {
  92944. return false;
  92945. };
  92946. this._setProperty('wheelDefaultDisabled', true);
  92947. }
  92948. var scaleFactor = this.height < this.width ? this.height : this.width;
  92949. // ZOOM if there is a change in mouseWheelDelta
  92950. if (this._mouseWheelDeltaY !== this._pmouseWheelDeltaY) {
  92951. // zoom according to direction of mouseWheelDeltaY rather than value
  92952. if (this._mouseWheelDeltaY > 0) {
  92953. this._renderer._curCamera._orbit(0, 0, sensitivityZ * scaleFactor);
  92954. } else {
  92955. this._renderer._curCamera._orbit(0, 0, -sensitivityZ * scaleFactor);
  92956. }
  92957. }
  92958. if (this.mouseIsPressed) {
  92959. // ORBIT BEHAVIOR
  92960. if (this.mouseButton === this.LEFT) {
  92961. var deltaTheta = -sensitivityX * (this.mouseX - this.pmouseX) / scaleFactor;
  92962. var deltaPhi = sensitivityY * (this.mouseY - this.pmouseY) / scaleFactor;
  92963. this._renderer._curCamera._orbit(deltaTheta, deltaPhi, 0);
  92964. } else if (this.mouseButton === this.RIGHT) {
  92965. // PANNING BEHAVIOR along X/Z camera axes and restricted to X/Z plane
  92966. // in world space
  92967. var local = cam._getLocalAxes();
  92968. // normalize portions along X/Z axes
  92969. var xmag = Math.sqrt(local.x[0] * local.x[0] + local.x[2] * local.x[2]);
  92970. if (xmag !== 0) {
  92971. local.x[0] /= xmag;
  92972. local.x[2] /= xmag;
  92973. }
  92974. // normalize portions along X/Z axes
  92975. var ymag = Math.sqrt(local.y[0] * local.y[0] + local.y[2] * local.y[2]);
  92976. if (ymag !== 0) {
  92977. local.y[0] /= ymag;
  92978. local.y[2] /= ymag;
  92979. }
  92980. // move along those vectors by amount controlled by mouseX, pmouseY
  92981. var dx = -1 * sensitivityX * (this.mouseX - this.pmouseX);
  92982. var dz = -1 * sensitivityY * (this.mouseY - this.pmouseY);
  92983. // restrict movement to XZ plane in world space
  92984. cam.setPosition(
  92985. cam.eyeX + dx * local.x[0] + dz * local.z[0],
  92986. cam.eyeY,
  92987. cam.eyeZ + dx * local.x[2] + dz * local.z[2]
  92988. );
  92989. }
  92990. }
  92991. return this;
  92992. };
  92993. /**
  92994. * debugMode() helps visualize 3D space by adding a grid to indicate where the
  92995. * ‘ground’ is in a sketch and an axes icon which indicates the +X, +Y, and +Z
  92996. * directions. This function can be called without parameters to create a
  92997. * default grid and axes icon, or it can be called according to the examples
  92998. * above to customize the size and position of the grid and/or axes icon. The
  92999. * grid is drawn using the most recently set stroke color and weight. To
  93000. * specify these parameters, add a call to stroke() and strokeWeight()
  93001. * just before the end of the draw() loop.
  93002. *
  93003. * By default, the grid will run through the origin (0,0,0) of the sketch
  93004. * along the XZ plane
  93005. * and the axes icon will be offset from the origin. Both the grid and axes
  93006. * icon will be sized according to the current canvas size. Note that because the
  93007. * grid runs parallel to the default camera view, it is often helpful to use
  93008. * debugMode along with orbitControl to allow full view of the grid.
  93009. * @method debugMode
  93010. * @example
  93011. * <div>
  93012. * <code>
  93013. * function setup() {
  93014. * createCanvas(100, 100, WEBGL);
  93015. * camera(0, -30, 100, 0, 0, 0, 0, 1, 0);
  93016. * normalMaterial();
  93017. * debugMode();
  93018. * }
  93019. *
  93020. * function draw() {
  93021. * background(200);
  93022. * orbitControl();
  93023. * box(15, 30);
  93024. * // Press the spacebar to turn debugMode off!
  93025. * if (keyIsDown(32)) {
  93026. * noDebugMode();
  93027. * }
  93028. * }
  93029. * </code>
  93030. * </div>
  93031. * @alt
  93032. * a 3D box is centered on a grid in a 3D sketch. an icon
  93033. * indicates the direction of each axis: a red line points +X,
  93034. * a green line +Y, and a blue line +Z. the grid and icon disappear when the
  93035. * spacebar is pressed.
  93036. *
  93037. * @example
  93038. * <div>
  93039. * <code>
  93040. * function setup() {
  93041. * createCanvas(100, 100, WEBGL);
  93042. * camera(0, -30, 100, 0, 0, 0, 0, 1, 0);
  93043. * normalMaterial();
  93044. * debugMode(GRID);
  93045. * }
  93046. *
  93047. * function draw() {
  93048. * background(200);
  93049. * orbitControl();
  93050. * box(15, 30);
  93051. * }
  93052. * </code>
  93053. * </div>
  93054. * @alt
  93055. * a 3D box is centered on a grid in a 3D sketch.
  93056. *
  93057. * @example
  93058. * <div>
  93059. * <code>
  93060. * function setup() {
  93061. * createCanvas(100, 100, WEBGL);
  93062. * camera(0, -30, 100, 0, 0, 0, 0, 1, 0);
  93063. * normalMaterial();
  93064. * debugMode(AXES);
  93065. * }
  93066. *
  93067. * function draw() {
  93068. * background(200);
  93069. * orbitControl();
  93070. * box(15, 30);
  93071. * }
  93072. * </code>
  93073. * </div>
  93074. * @alt
  93075. * a 3D box is centered in a 3D sketch. an icon
  93076. * indicates the direction of each axis: a red line points +X,
  93077. * a green line +Y, and a blue line +Z.
  93078. *
  93079. * @example
  93080. * <div>
  93081. * <code>
  93082. * function setup() {
  93083. * createCanvas(100, 100, WEBGL);
  93084. * camera(0, -30, 100, 0, 0, 0, 0, 1, 0);
  93085. * normalMaterial();
  93086. * debugMode(GRID, 100, 10, 0, 0, 0);
  93087. * }
  93088. *
  93089. * function draw() {
  93090. * background(200);
  93091. * orbitControl();
  93092. * box(15, 30);
  93093. * }
  93094. * </code>
  93095. * </div>
  93096. * @alt
  93097. * a 3D box is centered on a grid in a 3D sketch
  93098. *
  93099. * @example
  93100. * <div>
  93101. * <code>
  93102. * function setup() {
  93103. * createCanvas(100, 100, WEBGL);
  93104. * camera(0, -30, 100, 0, 0, 0, 0, 1, 0);
  93105. * normalMaterial();
  93106. * debugMode(100, 10, 0, 0, 0, 20, 0, -40, 0);
  93107. * }
  93108. *
  93109. * function draw() {
  93110. * noStroke();
  93111. * background(200);
  93112. * orbitControl();
  93113. * box(15, 30);
  93114. * // set the stroke color and weight for the grid!
  93115. * stroke(255, 0, 150);
  93116. * strokeWeight(0.8);
  93117. * }
  93118. * </code>
  93119. * </div>
  93120. * @alt
  93121. * a 3D box is centered on a grid in a 3D sketch. an icon
  93122. * indicates the direction of each axis: a red line points +X,
  93123. * a green line +Y, and a blue line +Z.
  93124. */
  93125. /**
  93126. * @method debugMode
  93127. * @param {Constant} mode either GRID or AXES
  93128. */
  93129. /**
  93130. * @method debugMode
  93131. * @param {Constant} mode
  93132. * @param {Number} [gridSize] size of one side of the grid
  93133. * @param {Number} [gridDivisions] number of divisions in the grid
  93134. * @param {Number} [xOff] X axis offset from origin (0,0,0)
  93135. * @param {Number} [yOff] Y axis offset from origin (0,0,0)
  93136. * @param {Number} [zOff] Z axis offset from origin (0,0,0)
  93137. */
  93138. /**
  93139. * @method debugMode
  93140. * @param {Constant} mode
  93141. * @param {Number} [axesSize] size of axes icon
  93142. * @param {Number} [xOff]
  93143. * @param {Number} [yOff]
  93144. * @param {Number} [zOff]
  93145. */
  93146. /**
  93147. * @method debugMode
  93148. * @param {Number} [gridSize]
  93149. * @param {Number} [gridDivisions]
  93150. * @param {Number} [gridXOff]
  93151. * @param {Number} [gridYOff]
  93152. * @param {Number} [gridZOff]
  93153. * @param {Number} [axesSize]
  93154. * @param {Number} [axesXOff]
  93155. * @param {Number} [axesYOff]
  93156. * @param {Number} [axesZOff]
  93157. */
  93158. _main.default.prototype.debugMode = function() {
  93159. this._assert3d('debugMode');
  93160. for (
  93161. var _len = arguments.length, args = new Array(_len), _key = 0;
  93162. _key < _len;
  93163. _key++
  93164. ) {
  93165. args[_key] = arguments[_key];
  93166. }
  93167. _main.default._validateParameters('debugMode', args);
  93168. // start by removing existing 'post' registered debug methods
  93169. for (var i = this._registeredMethods.post.length - 1; i >= 0; i--) {
  93170. // test for equality...
  93171. if (
  93172. this._registeredMethods.post[i].toString() === this._grid().toString() ||
  93173. this._registeredMethods.post[i].toString() === this._axesIcon().toString()
  93174. ) {
  93175. this._registeredMethods.post.splice(i, 1);
  93176. }
  93177. }
  93178. // then add new debugMode functions according to the argument list
  93179. if (args[0] === constants.GRID) {
  93180. this.registerMethod(
  93181. 'post',
  93182. this._grid.call(this, args[1], args[2], args[3], args[4], args[5])
  93183. );
  93184. } else if (args[0] === constants.AXES) {
  93185. this.registerMethod(
  93186. 'post',
  93187. this._axesIcon.call(this, args[1], args[2], args[3], args[4])
  93188. );
  93189. } else {
  93190. this.registerMethod(
  93191. 'post',
  93192. this._grid.call(this, args[0], args[1], args[2], args[3], args[4])
  93193. );
  93194. this.registerMethod(
  93195. 'post',
  93196. this._axesIcon.call(this, args[5], args[6], args[7], args[8])
  93197. );
  93198. }
  93199. };
  93200. /**
  93201. * Turns off debugMode() in a 3D sketch.
  93202. * @method noDebugMode
  93203. * @example
  93204. * <div>
  93205. * <code>
  93206. * function setup() {
  93207. * createCanvas(100, 100, WEBGL);
  93208. * camera(0, -30, 100, 0, 0, 0, 0, 1, 0);
  93209. * normalMaterial();
  93210. * debugMode();
  93211. * }
  93212. *
  93213. * function draw() {
  93214. * background(200);
  93215. * orbitControl();
  93216. * box(15, 30);
  93217. * // Press the spacebar to turn debugMode off!
  93218. * if (keyIsDown(32)) {
  93219. * noDebugMode();
  93220. * }
  93221. * }
  93222. * </code>
  93223. * </div>
  93224. * @alt
  93225. * a 3D box is centered on a grid in a 3D sketch. an icon
  93226. * indicates the direction of each axis: a red line points +X,
  93227. * a green line +Y, and a blue line +Z. the grid and icon disappear when the
  93228. * spacebar is pressed.
  93229. */
  93230. _main.default.prototype.noDebugMode = function() {
  93231. this._assert3d('noDebugMode');
  93232. // start by removing existing 'post' registered debug methods
  93233. for (var i = this._registeredMethods.post.length - 1; i >= 0; i--) {
  93234. // test for equality...
  93235. if (
  93236. this._registeredMethods.post[i].toString() === this._grid().toString() ||
  93237. this._registeredMethods.post[i].toString() === this._axesIcon().toString()
  93238. ) {
  93239. this._registeredMethods.post.splice(i, 1);
  93240. }
  93241. }
  93242. };
  93243. /**
  93244. * For use with debugMode
  93245. * @private
  93246. * @method _grid
  93247. * @param {Number} [size] size of grid sides
  93248. * @param {Number} [div] number of grid divisions
  93249. * @param {Number} [xOff] offset of grid center from origin in X axis
  93250. * @param {Number} [yOff] offset of grid center from origin in Y axis
  93251. * @param {Number} [zOff] offset of grid center from origin in Z axis
  93252. */
  93253. _main.default.prototype._grid = function(size, numDivs, xOff, yOff, zOff) {
  93254. if (typeof size === 'undefined') {
  93255. size = this.width / 2;
  93256. }
  93257. if (typeof numDivs === 'undefined') {
  93258. // ensure at least 2 divisions
  93259. numDivs = Math.round(size / 30) < 4 ? 4 : Math.round(size / 30);
  93260. }
  93261. if (typeof xOff === 'undefined') {
  93262. xOff = 0;
  93263. }
  93264. if (typeof yOff === 'undefined') {
  93265. yOff = 0;
  93266. }
  93267. if (typeof zOff === 'undefined') {
  93268. zOff = 0;
  93269. }
  93270. var spacing = size / numDivs;
  93271. var halfSize = size / 2;
  93272. return function() {
  93273. this.push();
  93274. this.stroke(
  93275. this._renderer.curStrokeColor[0] * 255,
  93276. this._renderer.curStrokeColor[1] * 255,
  93277. this._renderer.curStrokeColor[2] * 255
  93278. );
  93279. this._renderer.uMVMatrix.set(
  93280. this._renderer._curCamera.cameraMatrix.mat4[0],
  93281. this._renderer._curCamera.cameraMatrix.mat4[1],
  93282. this._renderer._curCamera.cameraMatrix.mat4[2],
  93283. this._renderer._curCamera.cameraMatrix.mat4[3],
  93284. this._renderer._curCamera.cameraMatrix.mat4[4],
  93285. this._renderer._curCamera.cameraMatrix.mat4[5],
  93286. this._renderer._curCamera.cameraMatrix.mat4[6],
  93287. this._renderer._curCamera.cameraMatrix.mat4[7],
  93288. this._renderer._curCamera.cameraMatrix.mat4[8],
  93289. this._renderer._curCamera.cameraMatrix.mat4[9],
  93290. this._renderer._curCamera.cameraMatrix.mat4[10],
  93291. this._renderer._curCamera.cameraMatrix.mat4[11],
  93292. this._renderer._curCamera.cameraMatrix.mat4[12],
  93293. this._renderer._curCamera.cameraMatrix.mat4[13],
  93294. this._renderer._curCamera.cameraMatrix.mat4[14],
  93295. this._renderer._curCamera.cameraMatrix.mat4[15]
  93296. );
  93297. // Lines along X axis
  93298. for (var q = 0; q <= numDivs; q++) {
  93299. this.beginShape(this.LINES);
  93300. this.vertex(-halfSize + xOff, yOff, q * spacing - halfSize + zOff);
  93301. this.vertex(+halfSize + xOff, yOff, q * spacing - halfSize + zOff);
  93302. this.endShape();
  93303. }
  93304. // Lines along Z axis
  93305. for (var i = 0; i <= numDivs; i++) {
  93306. this.beginShape(this.LINES);
  93307. this.vertex(i * spacing - halfSize + xOff, yOff, -halfSize + zOff);
  93308. this.vertex(i * spacing - halfSize + xOff, yOff, +halfSize + zOff);
  93309. this.endShape();
  93310. }
  93311. this.pop();
  93312. };
  93313. };
  93314. /**
  93315. * For use with debugMode
  93316. * @private
  93317. * @method _axesIcon
  93318. * @param {Number} [size] size of axes icon lines
  93319. * @param {Number} [xOff] offset of icon from origin in X axis
  93320. * @param {Number} [yOff] offset of icon from origin in Y axis
  93321. * @param {Number} [zOff] offset of icon from origin in Z axis
  93322. */
  93323. _main.default.prototype._axesIcon = function(size, xOff, yOff, zOff) {
  93324. if (typeof size === 'undefined') {
  93325. size = this.width / 20 > 40 ? this.width / 20 : 40;
  93326. }
  93327. if (typeof xOff === 'undefined') {
  93328. xOff = -this.width / 4;
  93329. }
  93330. if (typeof yOff === 'undefined') {
  93331. yOff = xOff;
  93332. }
  93333. if (typeof zOff === 'undefined') {
  93334. zOff = xOff;
  93335. }
  93336. return function() {
  93337. this.push();
  93338. this._renderer.uMVMatrix.set(
  93339. this._renderer._curCamera.cameraMatrix.mat4[0],
  93340. this._renderer._curCamera.cameraMatrix.mat4[1],
  93341. this._renderer._curCamera.cameraMatrix.mat4[2],
  93342. this._renderer._curCamera.cameraMatrix.mat4[3],
  93343. this._renderer._curCamera.cameraMatrix.mat4[4],
  93344. this._renderer._curCamera.cameraMatrix.mat4[5],
  93345. this._renderer._curCamera.cameraMatrix.mat4[6],
  93346. this._renderer._curCamera.cameraMatrix.mat4[7],
  93347. this._renderer._curCamera.cameraMatrix.mat4[8],
  93348. this._renderer._curCamera.cameraMatrix.mat4[9],
  93349. this._renderer._curCamera.cameraMatrix.mat4[10],
  93350. this._renderer._curCamera.cameraMatrix.mat4[11],
  93351. this._renderer._curCamera.cameraMatrix.mat4[12],
  93352. this._renderer._curCamera.cameraMatrix.mat4[13],
  93353. this._renderer._curCamera.cameraMatrix.mat4[14],
  93354. this._renderer._curCamera.cameraMatrix.mat4[15]
  93355. );
  93356. // X axis
  93357. this.strokeWeight(2);
  93358. this.stroke(255, 0, 0);
  93359. this.beginShape(this.LINES);
  93360. this.vertex(xOff, yOff, zOff);
  93361. this.vertex(xOff + size, yOff, zOff);
  93362. this.endShape();
  93363. // Y axis
  93364. this.stroke(0, 255, 0);
  93365. this.beginShape(this.LINES);
  93366. this.vertex(xOff, yOff, zOff);
  93367. this.vertex(xOff, yOff + size, zOff);
  93368. this.endShape();
  93369. // Z axis
  93370. this.stroke(0, 0, 255);
  93371. this.beginShape(this.LINES);
  93372. this.vertex(xOff, yOff, zOff);
  93373. this.vertex(xOff, yOff, zOff + size);
  93374. this.endShape();
  93375. this.pop();
  93376. };
  93377. };
  93378. var _default = _main.default;
  93379. exports.default = _default;
  93380. },
  93381. {
  93382. '../core/constants': 272,
  93383. '../core/main': 283,
  93384. 'core-js/modules/es.array.splice': 180,
  93385. 'core-js/modules/es.object.to-string': 192,
  93386. 'core-js/modules/es.regexp.to-string': 197
  93387. }
  93388. ],
  93389. 328: [
  93390. function(_dereq_, module, exports) {
  93391. 'use strict';
  93392. function _typeof(obj) {
  93393. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  93394. _typeof = function _typeof(obj) {
  93395. return typeof obj;
  93396. };
  93397. } else {
  93398. _typeof = function _typeof(obj) {
  93399. return obj &&
  93400. typeof Symbol === 'function' &&
  93401. obj.constructor === Symbol &&
  93402. obj !== Symbol.prototype
  93403. ? 'symbol'
  93404. : typeof obj;
  93405. };
  93406. }
  93407. return _typeof(obj);
  93408. }
  93409. Object.defineProperty(exports, '__esModule', { value: true });
  93410. exports.default = void 0;
  93411. var _main = _interopRequireDefault(_dereq_('../core/main'));
  93412. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  93413. function _getRequireWildcardCache() {
  93414. if (typeof WeakMap !== 'function') return null;
  93415. var cache = new WeakMap();
  93416. _getRequireWildcardCache = function _getRequireWildcardCache() {
  93417. return cache;
  93418. };
  93419. return cache;
  93420. }
  93421. function _interopRequireWildcard(obj) {
  93422. if (obj && obj.__esModule) {
  93423. return obj;
  93424. }
  93425. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  93426. return { default: obj };
  93427. }
  93428. var cache = _getRequireWildcardCache();
  93429. if (cache && cache.has(obj)) {
  93430. return cache.get(obj);
  93431. }
  93432. var newObj = {};
  93433. var hasPropertyDescriptor =
  93434. Object.defineProperty && Object.getOwnPropertyDescriptor;
  93435. for (var key in obj) {
  93436. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  93437. var desc = hasPropertyDescriptor
  93438. ? Object.getOwnPropertyDescriptor(obj, key)
  93439. : null;
  93440. if (desc && (desc.get || desc.set)) {
  93441. Object.defineProperty(newObj, key, desc);
  93442. } else {
  93443. newObj[key] = obj[key];
  93444. }
  93445. }
  93446. }
  93447. newObj.default = obj;
  93448. if (cache) {
  93449. cache.set(obj, newObj);
  93450. }
  93451. return newObj;
  93452. }
  93453. function _interopRequireDefault(obj) {
  93454. return obj && obj.__esModule ? obj : { default: obj };
  93455. } /**
  93456. * @method ambientLight
  93457. * @param {String} value a color string
  93458. * @chainable
  93459. */ /**
  93460. * @module Lights, Camera
  93461. * @submodule Lights
  93462. * @for p5
  93463. * @requires core
  93464. */ /**
  93465. * Creates an ambient light with a color. Ambient light is light that comes from everywhere on the canvas.
  93466. * It has no particular source.
  93467. * @method ambientLight
  93468. * @param {Number} v1 red or hue value relative to
  93469. * the current color range
  93470. * @param {Number} v2 green or saturation value
  93471. * relative to the current color range
  93472. * @param {Number} v3 blue or brightness value
  93473. * relative to the current color range
  93474. * @param {Number} [alpha] the alpha value
  93475. * @chainable
  93476. *
  93477. * @example
  93478. * <div>
  93479. * <code>
  93480. * createCanvas(100, 100, WEBGL);
  93481. * ambientLight(0);
  93482. * ambientMaterial(250);
  93483. * sphere(40);
  93484. * </code>
  93485. * </div>
  93486. * <div>
  93487. * <code>
  93488. * function setup() {
  93489. * createCanvas(100, 100, WEBGL);
  93490. * }
  93491. * function draw() {
  93492. * background(51);
  93493. * ambientLight(100); // white light
  93494. * ambientMaterial(255, 102, 94); // magenta material
  93495. * box(30);
  93496. * }
  93497. * </code>
  93498. * </div>
  93499. * @alt
  93500. * evenly distributed light across a sphere
  93501. * evenly distributed light across a rotating sphere
  93502. */
  93503. /**
  93504. * @method ambientLight
  93505. * @param {Number} gray a gray value
  93506. * @param {Number} [alpha]
  93507. * @chainable
  93508. */
  93509. /**
  93510. * @method ambientLight
  93511. * @param {Number[]} values an array containing the red,green,blue &
  93512. * and alpha components of the color
  93513. * @chainable
  93514. */
  93515. /**
  93516. * @method ambientLight
  93517. * @param {p5.Color} color the ambient light color
  93518. * @chainable
  93519. */
  93520. _main.default.prototype.ambientLight = function(v1, v2, v3, a) {
  93521. this._assert3d('ambientLight');
  93522. _main.default._validateParameters('ambientLight', arguments);
  93523. var color = this.color.apply(this, arguments);
  93524. this._renderer.ambientLightColors.push(
  93525. color._array[0],
  93526. color._array[1],
  93527. color._array[2]
  93528. );
  93529. this._renderer._enableLighting = true;
  93530. return this;
  93531. };
  93532. /**
  93533. * Set's the color of the specular highlight when using a specular material and
  93534. * specular light.
  93535. *
  93536. * This method can be combined with specularMaterial() and shininess()
  93537. * functions to set specular highlights. The default color is white, ie
  93538. * (255, 255, 255), which is used if this method is not called before
  93539. * specularMaterial(). If this method is called without specularMaterial(),
  93540. * There will be no effect.
  93541. *
  93542. * Note: specularColor is equivalent to the processing function
  93543. * <a href="https://processing.org/reference/lightSpecular_.html">lightSpecular</a>.
  93544. *
  93545. * @method specularColor
  93546. * @param {Number} v1 red or hue value relative to
  93547. * the current color range
  93548. * @param {Number} v2 green or saturation value
  93549. * relative to the current color range
  93550. * @param {Number} v3 blue or brightness value
  93551. * relative to the current color range
  93552. * @chainable
  93553. * @example
  93554. * <div>
  93555. * <code>
  93556. * function setup() {
  93557. * createCanvas(100, 100, WEBGL);
  93558. * noStroke();
  93559. * }
  93560. *
  93561. * function draw() {
  93562. * background(0);
  93563. * shininess(20);
  93564. * ambientLight(50);
  93565. * specularColor(255, 0, 0);
  93566. * pointLight(255, 0, 0, 0, -50, 50);
  93567. * specularColor(0, 255, 0);
  93568. * pointLight(0, 255, 0, 0, 50, 50);
  93569. * specularMaterial(255);
  93570. * sphere(40);
  93571. * }
  93572. * </code>
  93573. * </div>
  93574. *
  93575. * @alt
  93576. * different specular light sources from top and bottom of canvas
  93577. */
  93578. /**
  93579. * @method specularColor
  93580. * @param {String} value a color string
  93581. * @chainable
  93582. */
  93583. /**
  93584. * @method specularColor
  93585. * @param {Number} gray a gray value
  93586. * @chainable
  93587. */
  93588. /**
  93589. * @method specularColor
  93590. * @param {Number[]} values an array containing the red,green,blue &
  93591. * and alpha components of the color
  93592. * @chainable
  93593. */
  93594. /**
  93595. * @method specularColor
  93596. * @param {p5.Color} color the ambient light color
  93597. * @chainable
  93598. */
  93599. _main.default.prototype.specularColor = function(v1, v2, v3) {
  93600. this._assert3d('specularColor');
  93601. _main.default._validateParameters('specularColor', arguments);
  93602. var color = this.color.apply(this, arguments);
  93603. this._renderer.specularColors = [
  93604. color._array[0],
  93605. color._array[1],
  93606. color._array[2]
  93607. ];
  93608. return this;
  93609. };
  93610. /**
  93611. * Creates a directional light with a color and a direction
  93612. *
  93613. * A maximum of 5 directionalLight can be active at one time
  93614. * @method directionalLight
  93615. * @param {Number} v1 red or hue value (depending on the current
  93616. * color mode),
  93617. * @param {Number} v2 green or saturation value
  93618. * @param {Number} v3 blue or brightness value
  93619. * @param {p5.Vector} position the direction of the light
  93620. * @chainable
  93621. * @example
  93622. * <div>
  93623. * <code>
  93624. * function setup() {
  93625. * createCanvas(100, 100, WEBGL);
  93626. * }
  93627. * function draw() {
  93628. * background(0);
  93629. * //move your mouse to change light direction
  93630. * let dirX = (mouseX / width - 0.5) * 2;
  93631. * let dirY = (mouseY / height - 0.5) * 2;
  93632. * directionalLight(250, 250, 250, -dirX, -dirY, -1);
  93633. * noStroke();
  93634. * sphere(40);
  93635. * }
  93636. * </code>
  93637. * </div>
  93638. *
  93639. * @alt
  93640. * light source on canvas changeable with mouse position
  93641. */
  93642. /**
  93643. * @method directionalLight
  93644. * @param {Number[]|String|p5.Color} color color Array, CSS color string,
  93645. * or <a href="#/p5.Color">p5.Color</a> value
  93646. * @param {Number} x x axis direction
  93647. * @param {Number} y y axis direction
  93648. * @param {Number} z z axis direction
  93649. * @chainable
  93650. */
  93651. /**
  93652. * @method directionalLight
  93653. * @param {Number[]|String|p5.Color} color
  93654. * @param {p5.Vector} position
  93655. * @chainable
  93656. */
  93657. /**
  93658. * @method directionalLight
  93659. * @param {Number} v1
  93660. * @param {Number} v2
  93661. * @param {Number} v3
  93662. * @param {Number} x
  93663. * @param {Number} y
  93664. * @param {Number} z
  93665. * @chainable
  93666. */
  93667. _main.default.prototype.directionalLight = function(v1, v2, v3, x, y, z) {
  93668. this._assert3d('directionalLight');
  93669. _main.default._validateParameters('directionalLight', arguments);
  93670. //@TODO: check parameters number
  93671. var color;
  93672. if (v1 instanceof _main.default.Color) {
  93673. color = v1;
  93674. } else {
  93675. color = this.color(v1, v2, v3);
  93676. }
  93677. var _x, _y, _z;
  93678. var v = arguments[arguments.length - 1];
  93679. if (typeof v === 'number') {
  93680. _x = arguments[arguments.length - 3];
  93681. _y = arguments[arguments.length - 2];
  93682. _z = arguments[arguments.length - 1];
  93683. } else {
  93684. _x = v.x;
  93685. _y = v.y;
  93686. _z = v.z;
  93687. }
  93688. // normalize direction
  93689. var l = Math.sqrt(_x * _x + _y * _y + _z * _z);
  93690. this._renderer.directionalLightDirections.push(_x / l, _y / l, _z / l);
  93691. this._renderer.directionalLightDiffuseColors.push(
  93692. color._array[0],
  93693. color._array[1],
  93694. color._array[2]
  93695. );
  93696. Array.prototype.push.apply(
  93697. this._renderer.directionalLightSpecularColors,
  93698. this._renderer.specularColors
  93699. );
  93700. this._renderer._enableLighting = true;
  93701. return this;
  93702. };
  93703. /**
  93704. * Creates a point light with a color and a light position
  93705. *
  93706. * A maximum of 5 pointLight can be active at one time
  93707. * @method pointLight
  93708. * @param {Number} v1 red or hue value (depending on the current
  93709. * color mode),
  93710. * @param {Number} v2 green or saturation value
  93711. * @param {Number} v3 blue or brightness value
  93712. * @param {Number} x x axis position
  93713. * @param {Number} y y axis position
  93714. * @param {Number} z z axis position
  93715. * @chainable
  93716. * @example
  93717. * <div>
  93718. * <code>
  93719. * function setup() {
  93720. * createCanvas(100, 100, WEBGL);
  93721. * }
  93722. * function draw() {
  93723. * background(0);
  93724. * //move your mouse to change light position
  93725. * let locX = mouseX - width / 2;
  93726. * let locY = mouseY - height / 2;
  93727. * // to set the light position,
  93728. * // think of the world's coordinate as:
  93729. * // -width/2,-height/2 -------- width/2,-height/2
  93730. * // | |
  93731. * // | 0,0 |
  93732. * // | |
  93733. * // -width/2,height/2--------width/2,height/2
  93734. * pointLight(250, 250, 250, locX, locY, 50);
  93735. * noStroke();
  93736. * sphere(40);
  93737. * }
  93738. * </code>
  93739. * </div>
  93740. *
  93741. * @alt
  93742. * spot light on canvas changes position with mouse
  93743. */
  93744. /**
  93745. * @method pointLight
  93746. * @param {Number} v1
  93747. * @param {Number} v2
  93748. * @param {Number} v3
  93749. * @param {p5.Vector} position the position of the light
  93750. * @chainable
  93751. */
  93752. /**
  93753. * @method pointLight
  93754. * @param {Number[]|String|p5.Color} color color Array, CSS color string,
  93755. * or <a href="#/p5.Color">p5.Color</a> value
  93756. * @param {Number} x
  93757. * @param {Number} y
  93758. * @param {Number} z
  93759. * @chainable
  93760. */
  93761. /**
  93762. * @method pointLight
  93763. * @param {Number[]|String|p5.Color} color
  93764. * @param {p5.Vector} position
  93765. * @chainable
  93766. */
  93767. _main.default.prototype.pointLight = function(v1, v2, v3, x, y, z) {
  93768. this._assert3d('pointLight');
  93769. _main.default._validateParameters('pointLight', arguments);
  93770. //@TODO: check parameters number
  93771. var color;
  93772. if (v1 instanceof _main.default.Color) {
  93773. color = v1;
  93774. } else {
  93775. color = this.color(v1, v2, v3);
  93776. }
  93777. var _x, _y, _z;
  93778. var v = arguments[arguments.length - 1];
  93779. if (typeof v === 'number') {
  93780. _x = arguments[arguments.length - 3];
  93781. _y = arguments[arguments.length - 2];
  93782. _z = arguments[arguments.length - 1];
  93783. } else {
  93784. _x = v.x;
  93785. _y = v.y;
  93786. _z = v.z;
  93787. }
  93788. this._renderer.pointLightPositions.push(_x, _y, _z);
  93789. this._renderer.pointLightDiffuseColors.push(
  93790. color._array[0],
  93791. color._array[1],
  93792. color._array[2]
  93793. );
  93794. Array.prototype.push.apply(
  93795. this._renderer.pointLightSpecularColors,
  93796. this._renderer.specularColors
  93797. );
  93798. this._renderer._enableLighting = true;
  93799. return this;
  93800. };
  93801. /**
  93802. * Sets the default ambient and directional light. The defaults are <a href="#/p5/ambientLight">ambientLight(128, 128, 128)</a> and <a href="#/p5/directionalLight">directionalLight(128, 128, 128, 0, 0, -1)</a>. Lights need to be included in the <a href="#/p5/draw">draw()</a> to remain persistent in a looping program. Placing them in the <a href="#/p5/setup">setup()</a> of a looping program will cause them to only have an effect the first time through the loop.
  93803. * @method lights
  93804. * @chainable
  93805. * @example
  93806. * <div>
  93807. * <code>
  93808. * function setup() {
  93809. * createCanvas(100, 100, WEBGL);
  93810. * }
  93811. * function draw() {
  93812. * background(0);
  93813. * lights();
  93814. * rotateX(millis() / 1000);
  93815. * rotateY(millis() / 1000);
  93816. * rotateZ(millis() / 1000);
  93817. * box();
  93818. * }
  93819. * </code>
  93820. * </div>
  93821. *
  93822. * @alt
  93823. * the light is partially ambient and partially directional
  93824. */
  93825. _main.default.prototype.lights = function() {
  93826. this._assert3d('lights');
  93827. // only restore the colorMode to default if it is not in default already
  93828. if (this._colorMode === constants.RGB) {
  93829. this.ambientLight(128, 128, 128);
  93830. this.directionalLight(128, 128, 128, 0, 0, -1);
  93831. } else {
  93832. var maxBright = this._colorMaxes[this._colorMode][2];
  93833. this.ambientLight(0, 0, maxBright);
  93834. this.directionalLight(0, 0, maxBright, 0, 0, -1);
  93835. }
  93836. return this;
  93837. };
  93838. /**
  93839. * Sets the falloff rates for point lights. It affects only the elements which are created after it in the code.
  93840. * The default value is lightFalloff(1.0, 0.0, 0.0), and the parameters are used to calculate the falloff with the following equation:
  93841. *
  93842. * d = distance from light position to vertex position
  93843. *
  93844. * falloff = 1 / (CONSTANT + d \* LINEAR + ( d \* d ) \* QUADRATIC)
  93845. *
  93846. * @method lightFalloff
  93847. * @param {Number} constant constant value for determining falloff
  93848. * @param {Number} linear linear value for determining falloff
  93849. * @param {Number} quadratic quadratic value for determining falloff
  93850. * @chainable
  93851. * @example
  93852. * <div>
  93853. * <code>
  93854. * function setup() {
  93855. * createCanvas(100, 100, WEBGL);
  93856. * noStroke();
  93857. * }
  93858. * function draw() {
  93859. * background(0);
  93860. * let locX = mouseX - width / 2;
  93861. * let locY = mouseY - height / 2;
  93862. * translate(-25, 0, 0);
  93863. * lightFalloff(1, 0, 0);
  93864. * pointLight(250, 250, 250, locX, locY, 50);
  93865. * sphere(20);
  93866. * translate(50, 0, 0);
  93867. * lightFalloff(0.9, 0.01, 0);
  93868. * pointLight(250, 250, 250, locX, locY, 50);
  93869. * sphere(20);
  93870. * }
  93871. * </code>
  93872. * </div>
  93873. *
  93874. * @alt
  93875. * Two spheres with different falloff values show different intensity of light
  93876. */
  93877. _main.default.prototype.lightFalloff = function(
  93878. constantAttenuation,
  93879. linearAttenuation,
  93880. quadraticAttenuation
  93881. ) {
  93882. this._assert3d('lightFalloff');
  93883. _main.default._validateParameters('lightFalloff', arguments);
  93884. if (constantAttenuation < 0) {
  93885. constantAttenuation = 0;
  93886. console.warn(
  93887. 'Value of constant argument in lightFalloff() should be never be negative. Set to 0.'
  93888. );
  93889. }
  93890. if (linearAttenuation < 0) {
  93891. linearAttenuation = 0;
  93892. console.warn(
  93893. 'Value of linear argument in lightFalloff() should be never be negative. Set to 0.'
  93894. );
  93895. }
  93896. if (quadraticAttenuation < 0) {
  93897. quadraticAttenuation = 0;
  93898. console.warn(
  93899. 'Value of quadratic argument in lightFalloff() should be never be negative. Set to 0.'
  93900. );
  93901. }
  93902. if (
  93903. constantAttenuation === 0 &&
  93904. linearAttenuation === 0 &&
  93905. quadraticAttenuation === 0
  93906. ) {
  93907. constantAttenuation = 1;
  93908. console.warn(
  93909. 'Either one of the three arguments in lightFalloff() should be greater than zero. Set constant argument to 1.'
  93910. );
  93911. }
  93912. this._renderer.constantAttenuation = constantAttenuation;
  93913. this._renderer.linearAttenuation = linearAttenuation;
  93914. this._renderer.quadraticAttenuation = quadraticAttenuation;
  93915. return this;
  93916. };
  93917. /**
  93918. * Creates a spotlight with a given color, position, direction of light,
  93919. * angle and concentration. Here, angle refers to the opening or aperture
  93920. * of the cone of the spotlight, and concentration is used to focus the
  93921. * light towards the center. Both angle and concentration are optional, but if
  93922. * you want to provide concentration, you will also have to specify the angle.
  93923. *
  93924. * A maximum of 5 spotLight can be active at one time
  93925. * @method spotLight
  93926. * @param {Number} v1 red or hue value (depending on the current
  93927. * color mode),
  93928. * @param {Number} v2 green or saturation value
  93929. * @param {Number} v3 blue or brightness value
  93930. * @param {Number} x x axis position
  93931. * @param {Number} y y axis position
  93932. * @param {Number} z z axis position
  93933. * @param {Number} rx x axis direction of light
  93934. * @param {Number} ry y axis direction of light
  93935. * @param {Number} rz z axis direction of light
  93936. * @param {Number} [angle] optional parameter for angle. Defaults to PI/3
  93937. * @param {Number} [conc] optional parameter for concentration. Defaults to 100
  93938. * @chainable
  93939. *
  93940. * @example
  93941. * <div>
  93942. * <code>
  93943. * function setup() {
  93944. * createCanvas(100, 100, WEBGL);
  93945. * }
  93946. * function draw() {
  93947. * background(0);
  93948. * //move your mouse to change light position
  93949. * let locX = mouseX - width / 2;
  93950. * let locY = mouseY - height / 2;
  93951. * // to set the light position,
  93952. * // think of the world's coordinate as:
  93953. * // -width/2,-height/2 -------- width/2,-height/2
  93954. * // | |
  93955. * // | 0,0 |
  93956. * // | |
  93957. * // -width/2,height/2--------width/2,height/2
  93958. * ambientLight(50);
  93959. * spotLight(0, 250, 0, locX, locY, 100, 0, 0, -1, Math.PI / 16);
  93960. * noStroke();
  93961. * sphere(40);
  93962. * }
  93963. * </code>
  93964. * </div>
  93965. *
  93966. * @alt
  93967. * Spot light on a sphere which changes position with mouse
  93968. */
  93969. /**
  93970. * @method spotLight
  93971. * @param {Number[]|String|p5.Color} color color Array, CSS color string,
  93972. * or <a href="#/p5.Color">p5.Color</a> value
  93973. * @param {p5.Vector} position the position of the light
  93974. * @param {p5.Vector} direction the direction of the light
  93975. * @param {Number} [angle]
  93976. * @param {Number} [conc]
  93977. */
  93978. /**
  93979. * @method spotLight
  93980. * @param {Number} v1
  93981. * @param {Number} v2
  93982. * @param {Number} v3
  93983. * @param {p5.Vector} position
  93984. * @param {p5.Vector} direction
  93985. * @param {Number} [angle]
  93986. * @param {Number} [conc]
  93987. */
  93988. /**
  93989. * @method spotLight
  93990. * @param {Number[]|String|p5.Color} color
  93991. * @param {Number} x
  93992. * @param {Number} y
  93993. * @param {Number} z
  93994. * @param {p5.Vector} direction
  93995. * @param {Number} [angle]
  93996. * @param {Number} [conc]
  93997. */
  93998. /**
  93999. * @method spotLight
  94000. * @param {Number[]|String|p5.Color} color
  94001. * @param {p5.Vector} position
  94002. * @param {Number} rx
  94003. * @param {Number} ry
  94004. * @param {Number} rz
  94005. * @param {Number} [angle]
  94006. * @param {Number} [conc]
  94007. */
  94008. /**
  94009. * @method spotLight
  94010. * @param {Number} v1
  94011. * @param {Number} v2
  94012. * @param {Number} v3
  94013. * @param {Number} x
  94014. * @param {Number} y
  94015. * @param {Number} z
  94016. * @param {p5.Vector} direction
  94017. * @param {Number} [angle]
  94018. * @param {Number} [conc]
  94019. */
  94020. /**
  94021. * @method spotLight
  94022. * @param {Number} v1
  94023. * @param {Number} v2
  94024. * @param {Number} v3
  94025. * @param {p5.Vector} position
  94026. * @param {Number} rx
  94027. * @param {Number} ry
  94028. * @param {Number} rz
  94029. * @param {Number} [angle]
  94030. * @param {Number} [conc]
  94031. */
  94032. /**
  94033. * @method spotLight
  94034. * @param {Number[]|String|p5.Color} color
  94035. * @param {Number} x
  94036. * @param {Number} y
  94037. * @param {Number} z
  94038. * @param {Number} rx
  94039. * @param {Number} ry
  94040. * @param {Number} rz
  94041. * @param {Number} [angle]
  94042. * @param {Number} [conc]
  94043. */
  94044. _main.default.prototype.spotLight = function(
  94045. v1,
  94046. v2,
  94047. v3,
  94048. x,
  94049. y,
  94050. z,
  94051. nx,
  94052. ny,
  94053. nz,
  94054. angle,
  94055. concentration
  94056. ) {
  94057. this._assert3d('spotLight');
  94058. _main.default._validateParameters('spotLight', arguments);
  94059. var color, position, direction;
  94060. var length = arguments.length;
  94061. switch (length) {
  94062. case 11:
  94063. case 10:
  94064. color = this.color(v1, v2, v3);
  94065. position = new _main.default.Vector(x, y, z);
  94066. direction = new _main.default.Vector(nx, ny, nz);
  94067. break;
  94068. case 9:
  94069. if (v1 instanceof _main.default.Color) {
  94070. color = v1;
  94071. position = new _main.default.Vector(v2, v3, x);
  94072. direction = new _main.default.Vector(y, z, nx);
  94073. angle = ny;
  94074. concentration = nz;
  94075. } else if (x instanceof _main.default.Vector) {
  94076. color = this.color(v1, v2, v3);
  94077. position = x;
  94078. direction = new _main.default.Vector(y, z, nx);
  94079. angle = ny;
  94080. concentration = nz;
  94081. } else if (nx instanceof _main.default.Vector) {
  94082. color = this.color(v1, v2, v3);
  94083. position = new _main.default.Vector(x, y, z);
  94084. direction = nx;
  94085. angle = ny;
  94086. concentration = nz;
  94087. } else {
  94088. color = this.color(v1, v2, v3);
  94089. position = new _main.default.Vector(x, y, z);
  94090. direction = new _main.default.Vector(nx, ny, nz);
  94091. }
  94092. break;
  94093. case 8:
  94094. if (v1 instanceof _main.default.Color) {
  94095. color = v1;
  94096. position = new _main.default.Vector(v2, v3, x);
  94097. direction = new _main.default.Vector(y, z, nx);
  94098. angle = ny;
  94099. } else if (x instanceof _main.default.Vector) {
  94100. color = this.color(v1, v2, v3);
  94101. position = x;
  94102. direction = new _main.default.Vector(y, z, nx);
  94103. angle = ny;
  94104. } else {
  94105. color = this.color(v1, v2, v3);
  94106. position = new _main.default.Vector(x, y, z);
  94107. direction = nx;
  94108. angle = ny;
  94109. }
  94110. break;
  94111. case 7:
  94112. if (
  94113. v1 instanceof _main.default.Color &&
  94114. v2 instanceof _main.default.Vector
  94115. ) {
  94116. color = v1;
  94117. position = v2;
  94118. direction = new _main.default.Vector(v3, x, y);
  94119. angle = z;
  94120. concentration = nx;
  94121. } else if (
  94122. v1 instanceof _main.default.Color &&
  94123. y instanceof _main.default.Vector
  94124. ) {
  94125. color = v1;
  94126. position = new _main.default.Vector(v2, v3, x);
  94127. direction = y;
  94128. angle = z;
  94129. concentration = nx;
  94130. } else if (
  94131. x instanceof _main.default.Vector &&
  94132. y instanceof _main.default.Vector
  94133. ) {
  94134. color = this.color(v1, v2, v3);
  94135. position = x;
  94136. direction = y;
  94137. angle = z;
  94138. concentration = nx;
  94139. } else if (v1 instanceof _main.default.Color) {
  94140. color = v1;
  94141. position = new _main.default.Vector(v2, v3, x);
  94142. direction = new _main.default.Vector(y, z, nx);
  94143. } else if (x instanceof _main.default.Vector) {
  94144. color = this.color(v1, v2, v3);
  94145. position = x;
  94146. direction = new _main.default.Vector(y, z, nx);
  94147. } else {
  94148. color = this.color(v1, v2, v3);
  94149. position = new _main.default.Vector(x, y, z);
  94150. direction = nx;
  94151. }
  94152. break;
  94153. case 6:
  94154. if (
  94155. x instanceof _main.default.Vector &&
  94156. y instanceof _main.default.Vector
  94157. ) {
  94158. color = this.color(v1, v2, v3);
  94159. position = x;
  94160. direction = y;
  94161. angle = z;
  94162. } else if (
  94163. v1 instanceof _main.default.Color &&
  94164. y instanceof _main.default.Vector
  94165. ) {
  94166. color = v1;
  94167. position = new _main.default.Vector(v2, v3, x);
  94168. direction = y;
  94169. angle = z;
  94170. } else if (
  94171. v1 instanceof _main.default.Color &&
  94172. v2 instanceof _main.default.Vector
  94173. ) {
  94174. color = v1;
  94175. position = v2;
  94176. direction = new _main.default.Vector(v3, x, y);
  94177. angle = z;
  94178. }
  94179. break;
  94180. case 5:
  94181. if (
  94182. v1 instanceof _main.default.Color &&
  94183. v2 instanceof _main.default.Vector &&
  94184. v3 instanceof _main.default.Vector
  94185. ) {
  94186. color = v1;
  94187. position = v2;
  94188. direction = v3;
  94189. angle = x;
  94190. concentration = y;
  94191. } else if (
  94192. x instanceof _main.default.Vector &&
  94193. y instanceof _main.default.Vector
  94194. ) {
  94195. color = this.color(v1, v2, v3);
  94196. position = x;
  94197. direction = y;
  94198. } else if (
  94199. v1 instanceof _main.default.Color &&
  94200. y instanceof _main.default.Vector
  94201. ) {
  94202. color = v1;
  94203. position = new _main.default.Vector(v2, v3, x);
  94204. direction = y;
  94205. } else if (
  94206. v1 instanceof _main.default.Color &&
  94207. v2 instanceof _main.default.Vector
  94208. ) {
  94209. color = v1;
  94210. position = v2;
  94211. direction = new _main.default.Vector(v3, x, y);
  94212. }
  94213. break;
  94214. case 4:
  94215. color = v1;
  94216. position = v2;
  94217. direction = v3;
  94218. angle = x;
  94219. break;
  94220. case 3:
  94221. color = v1;
  94222. position = v2;
  94223. direction = v3;
  94224. break;
  94225. default:
  94226. console.warn(
  94227. 'Sorry, input for spotlight() is not in prescribed format. Too '.concat(
  94228. length < 3 ? 'few' : 'many',
  94229. ' arguments were provided'
  94230. )
  94231. );
  94232. return this;
  94233. }
  94234. this._renderer.spotLightDiffuseColors.push(
  94235. color._array[0],
  94236. color._array[1],
  94237. color._array[2]
  94238. );
  94239. Array.prototype.push.apply(
  94240. this._renderer.spotLightSpecularColors,
  94241. this._renderer.specularColors
  94242. );
  94243. this._renderer.spotLightPositions.push(position.x, position.y, position.z);
  94244. direction.normalize();
  94245. this._renderer.spotLightDirections.push(direction.x, direction.y, direction.z);
  94246. if (angle === undefined) {
  94247. angle = Math.PI / 3;
  94248. }
  94249. if (concentration !== undefined && concentration < 1) {
  94250. concentration = 1;
  94251. console.warn(
  94252. 'Value of concentration needs to be greater than 1. Setting it to 1'
  94253. );
  94254. } else if (concentration === undefined) {
  94255. concentration = 100;
  94256. }
  94257. angle = this._renderer._pInst._toRadians(angle);
  94258. this._renderer.spotLightAngle.push(Math.cos(angle));
  94259. this._renderer.spotLightConc.push(concentration);
  94260. this._renderer._enableLighting = true;
  94261. return this;
  94262. };
  94263. /**
  94264. * This function will remove all the lights from the sketch for the
  94265. * subsequent materials rendered. It affects all the subsequent methods.
  94266. * Calls to lighting methods made after noLights() will re-enable lights
  94267. * in the sketch.
  94268. * @method noLights
  94269. * @chainable
  94270. * @example
  94271. * <div>
  94272. * <code>
  94273. * function setup() {
  94274. * createCanvas(100, 100, WEBGL);
  94275. * }
  94276. * function draw() {
  94277. * background(0);
  94278. * noStroke();
  94279. *
  94280. * ambientLight(150, 0, 0);
  94281. * translate(-25, 0, 0);
  94282. * ambientMaterial(250);
  94283. * sphere(20);
  94284. *
  94285. * noLights();
  94286. * ambientLight(0, 150, 0);
  94287. * translate(50, 0, 0);
  94288. * ambientMaterial(250);
  94289. * sphere(20);
  94290. * }
  94291. * </code>
  94292. * </div>
  94293. *
  94294. * @alt
  94295. * Two spheres showing different colors
  94296. */
  94297. _main.default.prototype.noLights = function() {
  94298. this._assert3d('noLights');
  94299. _main.default._validateParameters('noLights', arguments);
  94300. this._renderer._enableLighting = false;
  94301. this._renderer.ambientLightColors.length = 0;
  94302. this._renderer.specularColors = [1, 1, 1];
  94303. this._renderer.directionalLightDirections.length = 0;
  94304. this._renderer.directionalLightDiffuseColors.length = 0;
  94305. this._renderer.directionalLightSpecularColors.length = 0;
  94306. this._renderer.pointLightPositions.length = 0;
  94307. this._renderer.pointLightDiffuseColors.length = 0;
  94308. this._renderer.pointLightSpecularColors.length = 0;
  94309. this._renderer.spotLightPositions.length = 0;
  94310. this._renderer.spotLightDirections.length = 0;
  94311. this._renderer.spotLightDiffuseColors.length = 0;
  94312. this._renderer.spotLightSpecularColors.length = 0;
  94313. this._renderer.spotLightAngle.length = 0;
  94314. this._renderer.spotLightConc.length = 0;
  94315. this._renderer.constantAttenuation = 1;
  94316. this._renderer.linearAttenuation = 0;
  94317. this._renderer.quadraticAttenuation = 0;
  94318. this._renderer._useShininess = 1;
  94319. return this;
  94320. };
  94321. var _default = _main.default;
  94322. exports.default = _default;
  94323. },
  94324. { '../core/constants': 272, '../core/main': 283 }
  94325. ],
  94326. 329: [
  94327. function(_dereq_, module, exports) {
  94328. 'use strict';
  94329. _dereq_('core-js/modules/es.array.concat');
  94330. _dereq_('core-js/modules/es.array.index-of');
  94331. _dereq_('core-js/modules/es.array.slice');
  94332. _dereq_('core-js/modules/es.array.splice');
  94333. _dereq_('core-js/modules/es.object.to-string');
  94334. _dereq_('core-js/modules/es.regexp.exec');
  94335. _dereq_('core-js/modules/es.string.match');
  94336. _dereq_('core-js/modules/es.string.split');
  94337. _dereq_('core-js/modules/es.string.trim');
  94338. Object.defineProperty(exports, '__esModule', { value: true });
  94339. exports.default = void 0;
  94340. var _main = _interopRequireDefault(_dereq_('../core/main'));
  94341. _dereq_('./p5.Geometry');
  94342. function _interopRequireDefault(obj) {
  94343. return obj && obj.__esModule ? obj : { default: obj };
  94344. }
  94345. /**
  94346. * @module Shape
  94347. * @submodule 3D Models
  94348. * @for p5
  94349. * @requires core
  94350. * @requires p5.Geometry
  94351. */ /**
  94352. * Load a 3d model from an OBJ or STL file.
  94353. *
  94354. * <a href="#/p5/loadModel">loadModel()</a> should be placed inside of <a href="#/p5/preload">preload()</a>.
  94355. * This allows the model to load fully before the rest of your code is run.
  94356. *
  94357. * One of the limitations of the OBJ and STL format is that it doesn't have a built-in
  94358. * sense of scale. This means that models exported from different programs might
  94359. * be very different sizes. If your model isn't displaying, try calling
  94360. * <a href="#/p5/loadModel">loadModel()</a> with the normalized parameter set to true. This will resize the
  94361. * model to a scale appropriate for p5. You can also make additional changes to
  94362. * the final size of your model with the <a href="#/p5/scale">scale()</a> function.
  94363. *
  94364. * Also, the support for colored STL files is not present. STL files with color will be
  94365. * rendered without color properties.
  94366. *
  94367. * @method loadModel
  94368. * @param {String} path Path of the model to be loaded
  94369. * @param {Boolean} normalize If true, scale the model to a
  94370. * standardized size when loading
  94371. * @param {function(p5.Geometry)} [successCallback] Function to be called
  94372. * once the model is loaded. Will be passed
  94373. * the 3D model object.
  94374. * @param {function(Event)} [failureCallback] called with event error if
  94375. * the model fails to load.
  94376. * @param {String} [fileType] The file extension of the model
  94377. * (<code>.stl</code>, <code>.obj</code>).
  94378. * @return {p5.Geometry} the <a href="#/p5.Geometry">p5.Geometry</a> object
  94379. *
  94380. * @example
  94381. * <div>
  94382. * <code>
  94383. * //draw a spinning octahedron
  94384. * let octahedron;
  94385. *
  94386. * function preload() {
  94387. * octahedron = loadModel('assets/octahedron.obj');
  94388. * }
  94389. *
  94390. * function setup() {
  94391. * createCanvas(100, 100, WEBGL);
  94392. * }
  94393. *
  94394. * function draw() {
  94395. * background(200);
  94396. * rotateX(frameCount * 0.01);
  94397. * rotateY(frameCount * 0.01);
  94398. * model(octahedron);
  94399. * }
  94400. * </code>
  94401. * </div>
  94402. *
  94403. * @alt
  94404. * Vertically rotating 3-d octahedron.
  94405. *
  94406. * @example
  94407. * <div>
  94408. * <code>
  94409. * //draw a spinning teapot
  94410. * let teapot;
  94411. *
  94412. * function preload() {
  94413. * // Load model with normalise parameter set to true
  94414. * teapot = loadModel('assets/teapot.obj', true);
  94415. * }
  94416. *
  94417. * function setup() {
  94418. * createCanvas(100, 100, WEBGL);
  94419. * }
  94420. *
  94421. * function draw() {
  94422. * background(200);
  94423. * scale(0.4); // Scaled to make model fit into canvas
  94424. * rotateX(frameCount * 0.01);
  94425. * rotateY(frameCount * 0.01);
  94426. * normalMaterial(); // For effect
  94427. * model(teapot);
  94428. * }
  94429. * </code>
  94430. * </div>
  94431. *
  94432. * @alt
  94433. * Vertically rotating 3-d teapot with red, green and blue gradient.
  94434. */ /**
  94435. * @method loadModel
  94436. * @param {String} path
  94437. * @param {function(p5.Geometry)} [successCallback]
  94438. * @param {function(Event)} [failureCallback]
  94439. * @param {String} [fileType]
  94440. * @return {p5.Geometry} the <a href="#/p5.Geometry">p5.Geometry</a> object
  94441. */ _main.default.prototype.loadModel = function(path) {
  94442. _main.default._validateParameters('loadModel', arguments);
  94443. var normalize;
  94444. var successCallback;
  94445. var failureCallback;
  94446. var fileType = path.slice(-4);
  94447. if (typeof arguments[1] === 'boolean') {
  94448. normalize = arguments[1];
  94449. successCallback = arguments[2];
  94450. failureCallback = arguments[3];
  94451. if (typeof arguments[4] !== 'undefined') {
  94452. fileType = arguments[4];
  94453. }
  94454. } else {
  94455. normalize = false;
  94456. successCallback = arguments[1];
  94457. failureCallback = arguments[2];
  94458. if (typeof arguments[3] !== 'undefined') {
  94459. fileType = arguments[3];
  94460. }
  94461. }
  94462. var model = new _main.default.Geometry();
  94463. model.gid = ''.concat(path, '|').concat(normalize);
  94464. var self = this;
  94465. if (fileType.match(/\.stl$/i)) {
  94466. this.httpDo(
  94467. path,
  94468. 'GET',
  94469. 'arrayBuffer',
  94470. function(arrayBuffer) {
  94471. parseSTL(model, arrayBuffer);
  94472. if (normalize) {
  94473. model.normalize();
  94474. }
  94475. self._decrementPreload();
  94476. if (typeof successCallback === 'function') {
  94477. successCallback(model);
  94478. }
  94479. },
  94480. failureCallback
  94481. );
  94482. } else if (fileType.match(/\.obj$/i)) {
  94483. this.loadStrings(
  94484. path,
  94485. function(strings) {
  94486. parseObj(model, strings);
  94487. if (normalize) {
  94488. model.normalize();
  94489. }
  94490. self._decrementPreload();
  94491. if (typeof successCallback === 'function') {
  94492. successCallback(model);
  94493. }
  94494. },
  94495. failureCallback
  94496. );
  94497. } else {
  94498. _main.default._friendlyFileLoadError(3, path);
  94499. if (failureCallback) {
  94500. failureCallback();
  94501. } else {
  94502. console.error(
  94503. 'Sorry, the file type is invalid. Only OBJ and STL files are supported.'
  94504. );
  94505. }
  94506. }
  94507. return model;
  94508. };
  94509. /**
  94510. * Parse OBJ lines into model. For reference, this is what a simple model of a
  94511. * square might look like:
  94512. *
  94513. * v -0.5 -0.5 0.5
  94514. * v -0.5 -0.5 -0.5
  94515. * v -0.5 0.5 -0.5
  94516. * v -0.5 0.5 0.5
  94517. *
  94518. * f 4 3 2 1
  94519. */
  94520. function parseObj(model, lines) {
  94521. // OBJ allows a face to specify an index for a vertex (in the above example),
  94522. // but it also allows you to specify a custom combination of vertex, UV
  94523. // coordinate, and vertex normal. So, "3/4/3" would mean, "use vertex 3 with
  94524. // UV coordinate 4 and vertex normal 3". In WebGL, every vertex with different
  94525. // parameters must be a different vertex, so loadedVerts is used to
  94526. // temporarily store the parsed vertices, normals, etc., and indexedVerts is
  94527. // used to map a specific combination (keyed on, for example, the string
  94528. // "3/4/3"), to the actual index of the newly created vertex in the final
  94529. // object.
  94530. var loadedVerts = {
  94531. v: [],
  94532. vt: [],
  94533. vn: []
  94534. };
  94535. var indexedVerts = {};
  94536. for (var line = 0; line < lines.length; ++line) {
  94537. // Each line is a separate object (vertex, face, vertex normal, etc)
  94538. // For each line, split it into tokens on whitespace. The first token
  94539. // describes the type.
  94540. var tokens = lines[line].trim().split(/\b\s+/);
  94541. if (tokens.length > 0) {
  94542. if (tokens[0] === 'v' || tokens[0] === 'vn') {
  94543. // Check if this line describes a vertex or vertex normal.
  94544. // It will have three numeric parameters.
  94545. var vertex = new _main.default.Vector(
  94546. parseFloat(tokens[1]),
  94547. parseFloat(tokens[2]),
  94548. parseFloat(tokens[3])
  94549. );
  94550. loadedVerts[tokens[0]].push(vertex);
  94551. } else if (tokens[0] === 'vt') {
  94552. // Check if this line describes a texture coordinate.
  94553. // It will have two numeric parameters U and V (W is omitted).
  94554. // Because of WebGL texture coordinates rendering behaviour, the V
  94555. // coordinate is inversed.
  94556. var texVertex = [parseFloat(tokens[1]), 1 - parseFloat(tokens[2])];
  94557. loadedVerts[tokens[0]].push(texVertex);
  94558. } else if (tokens[0] === 'f') {
  94559. // Check if this line describes a face.
  94560. // OBJ faces can have more than three points. Triangulate points.
  94561. for (var tri = 3; tri < tokens.length; ++tri) {
  94562. var face = [];
  94563. var vertexTokens = [1, tri - 1, tri];
  94564. for (var tokenInd = 0; tokenInd < vertexTokens.length; ++tokenInd) {
  94565. // Now, convert the given token into an index
  94566. var vertString = tokens[vertexTokens[tokenInd]];
  94567. var vertIndex = 0;
  94568. // TODO: Faces can technically use negative numbers to refer to the
  94569. // previous nth vertex. I haven't seen this used in practice, but
  94570. // it might be good to implement this in the future.
  94571. if (indexedVerts[vertString] !== undefined) {
  94572. vertIndex = indexedVerts[vertString];
  94573. } else {
  94574. var vertParts = vertString.split('/');
  94575. for (var i = 0; i < vertParts.length; i++) {
  94576. vertParts[i] = parseInt(vertParts[i]) - 1;
  94577. }
  94578. vertIndex = indexedVerts[vertString] = model.vertices.length;
  94579. model.vertices.push(loadedVerts.v[vertParts[0]].copy());
  94580. if (loadedVerts.vt[vertParts[1]]) {
  94581. model.uvs.push(loadedVerts.vt[vertParts[1]].slice());
  94582. } else {
  94583. model.uvs.push([0, 0]);
  94584. }
  94585. if (loadedVerts.vn[vertParts[2]]) {
  94586. model.vertexNormals.push(loadedVerts.vn[vertParts[2]].copy());
  94587. }
  94588. }
  94589. face.push(vertIndex);
  94590. }
  94591. if (face[0] !== face[1] && face[0] !== face[2] && face[1] !== face[2]) {
  94592. model.faces.push(face);
  94593. }
  94594. }
  94595. }
  94596. }
  94597. }
  94598. // If the model doesn't have normals, compute the normals
  94599. if (model.vertexNormals.length === 0) {
  94600. model.computeNormals();
  94601. }
  94602. return model;
  94603. }
  94604. /**
  94605. * STL files can be of two types, ASCII and Binary,
  94606. *
  94607. * We need to convert the arrayBuffer to an array of strings,
  94608. * to parse it as an ASCII file.
  94609. */
  94610. function parseSTL(model, buffer) {
  94611. if (isBinary(buffer)) {
  94612. parseBinarySTL(model, buffer);
  94613. } else {
  94614. var reader = new DataView(buffer);
  94615. if (!('TextDecoder' in window)) {
  94616. console.warn(
  94617. 'Sorry, ASCII STL loading only works in browsers that support TextDecoder (https://caniuse.com/#feat=textencoder)'
  94618. );
  94619. return model;
  94620. }
  94621. var decoder = new TextDecoder('utf-8');
  94622. var lines = decoder.decode(reader);
  94623. var lineArray = lines.split('\n');
  94624. parseASCIISTL(model, lineArray);
  94625. }
  94626. return model;
  94627. }
  94628. /**
  94629. * This function checks if the file is in ASCII format or in Binary format
  94630. *
  94631. * It is done by searching keyword `solid` at the start of the file.
  94632. *
  94633. * An ASCII STL data must begin with `solid` as the first six bytes.
  94634. * However, ASCII STLs lacking the SPACE after the `d` are known to be
  94635. * plentiful. So, check the first 5 bytes for `solid`.
  94636. *
  94637. * Several encodings, such as UTF-8, precede the text with up to 5 bytes:
  94638. * https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
  94639. * Search for `solid` to start anywhere after those prefixes.
  94640. */
  94641. function isBinary(data) {
  94642. var reader = new DataView(data);
  94643. // US-ASCII ordinal values for `s`, `o`, `l`, `i`, `d`
  94644. var solid = [115, 111, 108, 105, 100];
  94645. for (var off = 0; off < 5; off++) {
  94646. // If "solid" text is matched to the current offset, declare it to be an ASCII STL.
  94647. if (matchDataViewAt(solid, reader, off)) return false;
  94648. }
  94649. // Couldn't find "solid" text at the beginning; it is binary STL.
  94650. return true;
  94651. }
  94652. /**
  94653. * This function matches the `query` at the provided `offset`
  94654. */
  94655. function matchDataViewAt(query, reader, offset) {
  94656. // Check if each byte in query matches the corresponding byte from the current offset
  94657. for (var i = 0, il = query.length; i < il; i++) {
  94658. if (query[i] !== reader.getUint8(offset + i, false)) return false;
  94659. }
  94660. return true;
  94661. }
  94662. /**
  94663. * This function parses the Binary STL files.
  94664. * https://en.wikipedia.org/wiki/STL_%28file_format%29#Binary_STL
  94665. *
  94666. * Currently there is no support for the colors provided in STL files.
  94667. */
  94668. function parseBinarySTL(model, buffer) {
  94669. var reader = new DataView(buffer);
  94670. // Number of faces is present following the header
  94671. var faces = reader.getUint32(80, true);
  94672. var r,
  94673. g,
  94674. b,
  94675. hasColors = false,
  94676. colors;
  94677. var defaultR, defaultG, defaultB;
  94678. // Binary files contain 80-byte header, which is generally ignored.
  94679. for (var index = 0; index < 80 - 10; index++) {
  94680. // Check for `COLOR=`
  94681. if (
  94682. reader.getUint32(index, false) === 0x434f4c4f /*COLO*/ &&
  94683. reader.getUint8(index + 4) === 0x52 /*'R'*/ &&
  94684. reader.getUint8(index + 5) === 0x3d /*'='*/
  94685. ) {
  94686. hasColors = true;
  94687. colors = [];
  94688. defaultR = reader.getUint8(index + 6) / 255;
  94689. defaultG = reader.getUint8(index + 7) / 255;
  94690. defaultB = reader.getUint8(index + 8) / 255;
  94691. // To be used when color support is added
  94692. // alpha = reader.getUint8(index + 9) / 255;
  94693. }
  94694. }
  94695. var dataOffset = 84;
  94696. var faceLength = 12 * 4 + 2;
  94697. // Iterate the faces
  94698. for (var face = 0; face < faces; face++) {
  94699. var start = dataOffset + face * faceLength;
  94700. var normalX = reader.getFloat32(start, true);
  94701. var normalY = reader.getFloat32(start + 4, true);
  94702. var normalZ = reader.getFloat32(start + 8, true);
  94703. if (hasColors) {
  94704. var packedColor = reader.getUint16(start + 48, true);
  94705. if ((packedColor & 0x8000) === 0) {
  94706. // facet has its own unique color
  94707. r = (packedColor & 0x1f) / 31;
  94708. g = ((packedColor >> 5) & 0x1f) / 31;
  94709. b = ((packedColor >> 10) & 0x1f) / 31;
  94710. } else {
  94711. r = defaultR;
  94712. g = defaultG;
  94713. b = defaultB;
  94714. }
  94715. }
  94716. var newNormal = new _main.default.Vector(normalX, normalY, normalZ);
  94717. for (var i = 1; i <= 3; i++) {
  94718. var vertexstart = start + i * 12;
  94719. var newVertex = new _main.default.Vector(
  94720. reader.getFloat32(vertexstart, true),
  94721. reader.getFloat32(vertexstart + 4, true),
  94722. reader.getFloat32(vertexstart + 8, true)
  94723. );
  94724. model.vertices.push(newVertex);
  94725. model.vertexNormals.push(newNormal);
  94726. if (hasColors) {
  94727. colors.push(r, g, b);
  94728. }
  94729. }
  94730. model.faces.push([3 * face, 3 * face + 1, 3 * face + 2]);
  94731. model.uvs.push([0, 0], [0, 0], [0, 0]);
  94732. }
  94733. if (hasColors) {
  94734. // add support for colors here.
  94735. }
  94736. return model;
  94737. }
  94738. /**
  94739. * ASCII STL file starts with `solid 'nameOfFile'`
  94740. * Then contain the normal of the face, starting with `facet normal`
  94741. * Next contain a keyword indicating the start of face vertex, `outer loop`
  94742. * Next comes the three vertex, starting with `vertex x y z`
  94743. * Vertices ends with `endloop`
  94744. * Face ends with `endfacet`
  94745. * Next face starts with `facet normal`
  94746. * The end of the file is indicated by `endsolid`
  94747. */
  94748. function parseASCIISTL(model, lines) {
  94749. var state = '';
  94750. var curVertexIndex = [];
  94751. var newNormal, newVertex;
  94752. for (var iterator = 0; iterator < lines.length; ++iterator) {
  94753. var line = lines[iterator].trim();
  94754. var parts = line.split(' ');
  94755. for (var partsiterator = 0; partsiterator < parts.length; ++partsiterator) {
  94756. if (parts[partsiterator] === '') {
  94757. // Ignoring multiple whitespaces
  94758. parts.splice(partsiterator, 1);
  94759. }
  94760. }
  94761. if (parts.length === 0) {
  94762. // Remove newline
  94763. continue;
  94764. }
  94765. switch (state) {
  94766. case '': // First run
  94767. if (parts[0] !== 'solid') {
  94768. // Invalid state
  94769. console.error(line);
  94770. console.error(
  94771. 'Invalid state "'.concat(parts[0], '", should be "solid"')
  94772. );
  94773. return;
  94774. } else {
  94775. state = 'solid';
  94776. }
  94777. break;
  94778. case 'solid': // First face
  94779. if (parts[0] !== 'facet' || parts[1] !== 'normal') {
  94780. // Invalid state
  94781. console.error(line);
  94782. console.error(
  94783. 'Invalid state "'.concat(parts[0], '", should be "facet normal"')
  94784. );
  94785. return;
  94786. } else {
  94787. // Push normal for first face
  94788. newNormal = new _main.default.Vector(
  94789. parseFloat(parts[2]),
  94790. parseFloat(parts[3]),
  94791. parseFloat(parts[4])
  94792. );
  94793. model.vertexNormals.push(newNormal, newNormal, newNormal);
  94794. state = 'facet normal';
  94795. }
  94796. break;
  94797. case 'facet normal': // After normal is defined
  94798. if (parts[0] !== 'outer' || parts[1] !== 'loop') {
  94799. // Invalid State
  94800. console.error(line);
  94801. console.error(
  94802. 'Invalid state "'.concat(parts[0], '", should be "outer loop"')
  94803. );
  94804. return;
  94805. } else {
  94806. // Next should be vertices
  94807. state = 'vertex';
  94808. }
  94809. break;
  94810. case 'vertex':
  94811. if (parts[0] === 'vertex') {
  94812. //Vertex of triangle
  94813. newVertex = new _main.default.Vector(
  94814. parseFloat(parts[1]),
  94815. parseFloat(parts[2]),
  94816. parseFloat(parts[3])
  94817. );
  94818. model.vertices.push(newVertex);
  94819. model.uvs.push([0, 0]);
  94820. curVertexIndex.push(model.vertices.indexOf(newVertex));
  94821. } else if (parts[0] === 'endloop') {
  94822. // End of vertices
  94823. model.faces.push(curVertexIndex);
  94824. curVertexIndex = [];
  94825. state = 'endloop';
  94826. } else {
  94827. // Invalid State
  94828. console.error(line);
  94829. console.error(
  94830. 'Invalid state "'.concat(
  94831. parts[0],
  94832. '", should be "vertex" or "endloop"'
  94833. )
  94834. );
  94835. return;
  94836. }
  94837. break;
  94838. case 'endloop':
  94839. if (parts[0] !== 'endfacet') {
  94840. // End of face
  94841. console.error(line);
  94842. console.error(
  94843. 'Invalid state "'.concat(parts[0], '", should be "endfacet"')
  94844. );
  94845. return;
  94846. } else {
  94847. state = 'endfacet';
  94848. }
  94849. break;
  94850. case 'endfacet':
  94851. if (parts[0] === 'endsolid') {
  94852. // End of solid
  94853. } else if (parts[0] === 'facet' && parts[1] === 'normal') {
  94854. // Next face
  94855. newNormal = new _main.default.Vector(
  94856. parseFloat(parts[2]),
  94857. parseFloat(parts[3]),
  94858. parseFloat(parts[4])
  94859. );
  94860. model.vertexNormals.push(newNormal, newNormal, newNormal);
  94861. state = 'facet normal';
  94862. } else {
  94863. // Invalid State
  94864. console.error(line);
  94865. console.error(
  94866. 'Invalid state "'.concat(
  94867. parts[0],
  94868. '", should be "endsolid" or "facet normal"'
  94869. )
  94870. );
  94871. return;
  94872. }
  94873. break;
  94874. default:
  94875. console.error('Invalid state "'.concat(state, '"'));
  94876. break;
  94877. }
  94878. }
  94879. return model;
  94880. }
  94881. /**
  94882. * Render a 3d model to the screen.
  94883. *
  94884. * @method model
  94885. * @param {p5.Geometry} model Loaded 3d model to be rendered
  94886. * @example
  94887. * <div>
  94888. * <code>
  94889. * //draw a spinning octahedron
  94890. * let octahedron;
  94891. *
  94892. * function preload() {
  94893. * octahedron = loadModel('assets/octahedron.obj');
  94894. * }
  94895. *
  94896. * function setup() {
  94897. * createCanvas(100, 100, WEBGL);
  94898. * }
  94899. *
  94900. * function draw() {
  94901. * background(200);
  94902. * rotateX(frameCount * 0.01);
  94903. * rotateY(frameCount * 0.01);
  94904. * model(octahedron);
  94905. * }
  94906. * </code>
  94907. * </div>
  94908. *
  94909. * @alt
  94910. * Vertically rotating 3-d octahedron.
  94911. */
  94912. _main.default.prototype.model = function(model) {
  94913. this._assert3d('model');
  94914. _main.default._validateParameters('model', arguments);
  94915. if (model.vertices.length > 0) {
  94916. if (!this._renderer.geometryInHash(model.gid)) {
  94917. model._makeTriangleEdges()._edgesToVertices();
  94918. this._renderer.createBuffers(model.gid, model);
  94919. }
  94920. this._renderer.drawBuffers(model.gid);
  94921. }
  94922. };
  94923. var _default = _main.default;
  94924. exports.default = _default;
  94925. },
  94926. {
  94927. '../core/main': 283,
  94928. './p5.Geometry': 332,
  94929. 'core-js/modules/es.array.concat': 166,
  94930. 'core-js/modules/es.array.index-of': 173,
  94931. 'core-js/modules/es.array.slice': 178,
  94932. 'core-js/modules/es.array.splice': 180,
  94933. 'core-js/modules/es.object.to-string': 192,
  94934. 'core-js/modules/es.regexp.exec': 196,
  94935. 'core-js/modules/es.string.match': 202,
  94936. 'core-js/modules/es.string.split': 206,
  94937. 'core-js/modules/es.string.trim': 208
  94938. }
  94939. ],
  94940. 330: [
  94941. function(_dereq_, module, exports) {
  94942. 'use strict';
  94943. function _typeof(obj) {
  94944. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  94945. _typeof = function _typeof(obj) {
  94946. return typeof obj;
  94947. };
  94948. } else {
  94949. _typeof = function _typeof(obj) {
  94950. return obj &&
  94951. typeof Symbol === 'function' &&
  94952. obj.constructor === Symbol &&
  94953. obj !== Symbol.prototype
  94954. ? 'symbol'
  94955. : typeof obj;
  94956. };
  94957. }
  94958. return _typeof(obj);
  94959. }
  94960. _dereq_('core-js/modules/es.array.join');
  94961. Object.defineProperty(exports, '__esModule', { value: true });
  94962. exports.default = void 0;
  94963. var _main = _interopRequireDefault(_dereq_('../core/main'));
  94964. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  94965. _dereq_('./p5.Texture');
  94966. function _getRequireWildcardCache() {
  94967. if (typeof WeakMap !== 'function') return null;
  94968. var cache = new WeakMap();
  94969. _getRequireWildcardCache = function _getRequireWildcardCache() {
  94970. return cache;
  94971. };
  94972. return cache;
  94973. }
  94974. function _interopRequireWildcard(obj) {
  94975. if (obj && obj.__esModule) {
  94976. return obj;
  94977. }
  94978. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  94979. return { default: obj };
  94980. }
  94981. var cache = _getRequireWildcardCache();
  94982. if (cache && cache.has(obj)) {
  94983. return cache.get(obj);
  94984. }
  94985. var newObj = {};
  94986. var hasPropertyDescriptor =
  94987. Object.defineProperty && Object.getOwnPropertyDescriptor;
  94988. for (var key in obj) {
  94989. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  94990. var desc = hasPropertyDescriptor
  94991. ? Object.getOwnPropertyDescriptor(obj, key)
  94992. : null;
  94993. if (desc && (desc.get || desc.set)) {
  94994. Object.defineProperty(newObj, key, desc);
  94995. } else {
  94996. newObj[key] = obj[key];
  94997. }
  94998. }
  94999. }
  95000. newObj.default = obj;
  95001. if (cache) {
  95002. cache.set(obj, newObj);
  95003. }
  95004. return newObj;
  95005. }
  95006. function _interopRequireDefault(obj) {
  95007. return obj && obj.__esModule ? obj : { default: obj };
  95008. }
  95009. /**
  95010. * @module Lights, Camera
  95011. * @submodule Material
  95012. * @for p5
  95013. * @requires core
  95014. */ /**
  95015. * Loads a custom shader from the provided vertex and fragment
  95016. * shader paths. The shader files are loaded asynchronously in the
  95017. * background, so this method should be used in <a href="#/p5/preload">preload()</a>.
  95018. *
  95019. * For now, there are three main types of shaders. p5 will automatically
  95020. * supply appropriate vertices, normals, colors, and lighting attributes
  95021. * if the parameters defined in the shader match the names.
  95022. *
  95023. * @method loadShader
  95024. * @param {String} vertFilename path to file containing vertex shader
  95025. * source code
  95026. * @param {String} fragFilename path to file containing fragment shader
  95027. * source code
  95028. * @param {function} [callback] callback to be executed after loadShader
  95029. * completes. On success, the Shader object is passed as the first argument.
  95030. * @param {function} [errorCallback] callback to be executed when an error
  95031. * occurs inside loadShader. On error, the error is passed as the first
  95032. * argument.
  95033. * @return {p5.Shader} a shader object created from the provided
  95034. * vertex and fragment shader files.
  95035. *
  95036. * @example
  95037. * <div modernizr='webgl'>
  95038. * <code>
  95039. * let mandel;
  95040. * function preload() {
  95041. * // load the shader definitions from files
  95042. * mandel = loadShader('assets/shader.vert', 'assets/shader.frag');
  95043. * }
  95044. * function setup() {
  95045. * createCanvas(100, 100, WEBGL);
  95046. * // use the shader
  95047. * shader(mandel);
  95048. * noStroke();
  95049. * mandel.setUniform('p', [-0.74364388703, 0.13182590421]);
  95050. * }
  95051. *
  95052. * function draw() {
  95053. * mandel.setUniform('r', 1.5 * exp(-6.5 * (1 + sin(millis() / 2000))));
  95054. * quad(-1, -1, 1, -1, 1, 1, -1, 1);
  95055. * }
  95056. * </code>
  95057. * </div>
  95058. *
  95059. * @alt
  95060. * zooming Mandelbrot set. a colorful, infinitely detailed fractal.
  95061. */ _main.default.prototype.loadShader = function(
  95062. vertFilename,
  95063. fragFilename,
  95064. callback,
  95065. errorCallback
  95066. ) {
  95067. _main.default._validateParameters('loadShader', arguments);
  95068. if (!errorCallback) {
  95069. errorCallback = console.error;
  95070. }
  95071. var loadedShader = new _main.default.Shader();
  95072. var self = this;
  95073. var loadedFrag = false;
  95074. var loadedVert = false;
  95075. var onLoad = function onLoad() {
  95076. self._decrementPreload();
  95077. if (callback) {
  95078. callback(loadedShader);
  95079. }
  95080. };
  95081. this.loadStrings(
  95082. vertFilename,
  95083. function(result) {
  95084. loadedShader._vertSrc = result.join('\n');
  95085. loadedVert = true;
  95086. if (loadedFrag) {
  95087. onLoad();
  95088. }
  95089. },
  95090. errorCallback
  95091. );
  95092. this.loadStrings(
  95093. fragFilename,
  95094. function(result) {
  95095. loadedShader._fragSrc = result.join('\n');
  95096. loadedFrag = true;
  95097. if (loadedVert) {
  95098. onLoad();
  95099. }
  95100. },
  95101. errorCallback
  95102. );
  95103. return loadedShader;
  95104. };
  95105. /**
  95106. * @method createShader
  95107. * @param {String} vertSrc source code for the vertex shader
  95108. * @param {String} fragSrc source code for the fragment shader
  95109. * @returns {p5.Shader} a shader object created from the provided
  95110. * vertex and fragment shaders.
  95111. *
  95112. * @example
  95113. * <div modernizr='webgl'>
  95114. * <code>
  95115. * // the 'varying's are shared between both vertex & fragment shaders
  95116. * let varying = 'precision highp float; varying vec2 vPos;';
  95117. *
  95118. * // the vertex shader is called for each vertex
  95119. * let vs =
  95120. * varying +
  95121. * 'attribute vec3 aPosition;' +
  95122. * 'void main() { vPos = (gl_Position = vec4(aPosition,1.0)).xy; }';
  95123. *
  95124. * // the fragment shader is called for each pixel
  95125. * let fs =
  95126. * varying +
  95127. * 'uniform vec2 p;' +
  95128. * 'uniform float r;' +
  95129. * 'const int I = 500;' +
  95130. * 'void main() {' +
  95131. * ' vec2 c = p + vPos * r, z = c;' +
  95132. * ' float n = 0.0;' +
  95133. * ' for (int i = I; i > 0; i --) {' +
  95134. * ' if(z.x*z.x+z.y*z.y > 4.0) {' +
  95135. * ' n = float(i)/float(I);' +
  95136. * ' break;' +
  95137. * ' }' +
  95138. * ' z = vec2(z.x*z.x-z.y*z.y, 2.0*z.x*z.y) + c;' +
  95139. * ' }' +
  95140. * ' gl_FragColor = vec4(0.5-cos(n*17.0)/2.0,0.5-cos(n*13.0)/2.0,0.5-cos(n*23.0)/2.0,1.0);' +
  95141. * '}';
  95142. *
  95143. * let mandel;
  95144. * function setup() {
  95145. * createCanvas(100, 100, WEBGL);
  95146. *
  95147. * // create and initialize the shader
  95148. * mandel = createShader(vs, fs);
  95149. * shader(mandel);
  95150. * noStroke();
  95151. *
  95152. * // 'p' is the center point of the Mandelbrot image
  95153. * mandel.setUniform('p', [-0.74364388703, 0.13182590421]);
  95154. * }
  95155. *
  95156. * function draw() {
  95157. * // 'r' is the size of the image in Mandelbrot-space
  95158. * mandel.setUniform('r', 1.5 * exp(-6.5 * (1 + sin(millis() / 2000))));
  95159. * quad(-1, -1, 1, -1, 1, 1, -1, 1);
  95160. * }
  95161. * </code>
  95162. * </div>
  95163. *
  95164. * @alt
  95165. * zooming Mandelbrot set. a colorful, infinitely detailed fractal.
  95166. */
  95167. _main.default.prototype.createShader = function(vertSrc, fragSrc) {
  95168. this._assert3d('createShader');
  95169. _main.default._validateParameters('createShader', arguments);
  95170. return new _main.default.Shader(this._renderer, vertSrc, fragSrc);
  95171. };
  95172. /**
  95173. * The <a href="#/p5/shader">shader()</a> function lets the user provide a custom shader
  95174. * to fill in shapes in WEBGL mode. Users can create their
  95175. * own shaders by loading vertex and fragment shaders with
  95176. * <a href="#/p5/loadShader">loadShader()</a>.
  95177. *
  95178. * @method shader
  95179. * @chainable
  95180. * @param {p5.Shader} [s] the desired <a href="#/p5.Shader">p5.Shader</a> to use for rendering
  95181. * shapes.
  95182. *
  95183. * @example
  95184. * <div modernizr='webgl'>
  95185. * <code>
  95186. * // Click within the image to toggle
  95187. * // the shader used by the quad shape
  95188. * // Note: for an alternative approach to the same example,
  95189. * // involving changing uniforms please refer to:
  95190. * // https://p5js.org/reference/#/p5.Shader/setUniform
  95191. *
  95192. * let redGreen;
  95193. * let orangeBlue;
  95194. * let showRedGreen = false;
  95195. *
  95196. * function preload() {
  95197. * // note that we are using two instances
  95198. * // of the same vertex and fragment shaders
  95199. * redGreen = loadShader('assets/shader.vert', 'assets/shader-gradient.frag');
  95200. * orangeBlue = loadShader('assets/shader.vert', 'assets/shader-gradient.frag');
  95201. * }
  95202. *
  95203. * function setup() {
  95204. * createCanvas(100, 100, WEBGL);
  95205. *
  95206. * // initialize the colors for redGreen shader
  95207. * shader(redGreen);
  95208. * redGreen.setUniform('colorCenter', [1.0, 0.0, 0.0]);
  95209. * redGreen.setUniform('colorBackground', [0.0, 1.0, 0.0]);
  95210. *
  95211. * // initialize the colors for orangeBlue shader
  95212. * shader(orangeBlue);
  95213. * orangeBlue.setUniform('colorCenter', [1.0, 0.5, 0.0]);
  95214. * orangeBlue.setUniform('colorBackground', [0.226, 0.0, 0.615]);
  95215. *
  95216. * noStroke();
  95217. * }
  95218. *
  95219. * function draw() {
  95220. * // update the offset values for each shader,
  95221. * // moving orangeBlue in vertical and redGreen
  95222. * // in horizontal direction
  95223. * orangeBlue.setUniform('offset', [0, sin(millis() / 2000) + 1]);
  95224. * redGreen.setUniform('offset', [sin(millis() / 2000), 1]);
  95225. *
  95226. * if (showRedGreen === true) {
  95227. * shader(redGreen);
  95228. * } else {
  95229. * shader(orangeBlue);
  95230. * }
  95231. * quad(-1, -1, 1, -1, 1, 1, -1, 1);
  95232. * }
  95233. *
  95234. * function mouseClicked() {
  95235. * showRedGreen = !showRedGreen;
  95236. * }
  95237. * </code>
  95238. * </div>
  95239. *
  95240. * @alt
  95241. * canvas toggles between a circular gradient of orange and blue vertically. and a circular gradient of red and green moving horizontally when mouse is clicked/pressed.
  95242. */
  95243. _main.default.prototype.shader = function(s) {
  95244. this._assert3d('shader');
  95245. _main.default._validateParameters('shader', arguments);
  95246. if (s._renderer === undefined) {
  95247. s._renderer = this._renderer;
  95248. }
  95249. s.init();
  95250. if (s.isStrokeShader()) {
  95251. this._renderer.userStrokeShader = s;
  95252. } else {
  95253. this._renderer.userFillShader = s;
  95254. this._renderer._useNormalMaterial = false;
  95255. }
  95256. return this;
  95257. };
  95258. /**
  95259. * This function restores the default shaders in WEBGL mode. Code that runs
  95260. * after resetShader() will not be affected by previously defined
  95261. * shaders. Should be run after <a href="#/p5/shader">shader()</a>.
  95262. *
  95263. * @method resetShader
  95264. * @chainable
  95265. */
  95266. _main.default.prototype.resetShader = function() {
  95267. this._renderer.userFillShader = this._renderer.userStrokeShader = null;
  95268. return this;
  95269. };
  95270. /**
  95271. * Texture for geometry. You can view other possible materials in this
  95272. * <a href="https://p5js.org/examples/3d-materials.html">example</a>.
  95273. * @method texture
  95274. * @param {p5.Image|p5.MediaElement|p5.Graphics} tex 2-dimensional graphics
  95275. * to render as texture
  95276. * @chainable
  95277. * @example
  95278. * <div>
  95279. * <code>
  95280. * let img;
  95281. * function preload() {
  95282. * img = loadImage('assets/laDefense.jpg');
  95283. * }
  95284. *
  95285. * function setup() {
  95286. * createCanvas(100, 100, WEBGL);
  95287. * }
  95288. *
  95289. * function draw() {
  95290. * background(0);
  95291. * rotateZ(frameCount * 0.01);
  95292. * rotateX(frameCount * 0.01);
  95293. * rotateY(frameCount * 0.01);
  95294. * //pass image as texture
  95295. * texture(img);
  95296. * box(width / 2);
  95297. * }
  95298. * </code>
  95299. * </div>
  95300. *
  95301. * <div>
  95302. * <code>
  95303. * let pg;
  95304. *
  95305. * function setup() {
  95306. * createCanvas(100, 100, WEBGL);
  95307. * pg = createGraphics(200, 200);
  95308. * pg.textSize(75);
  95309. * }
  95310. *
  95311. * function draw() {
  95312. * background(0);
  95313. * pg.background(255);
  95314. * pg.text('hello!', 0, 100);
  95315. * //pass image as texture
  95316. * texture(pg);
  95317. * rotateX(0.5);
  95318. * noStroke();
  95319. * plane(50);
  95320. * }
  95321. * </code>
  95322. * </div>
  95323. *
  95324. * <div>
  95325. * <code>
  95326. * let vid;
  95327. * function preload() {
  95328. * vid = createVideo('assets/fingers.mov');
  95329. * vid.hide();
  95330. * }
  95331. * function setup() {
  95332. * createCanvas(100, 100, WEBGL);
  95333. * }
  95334. *
  95335. * function draw() {
  95336. * background(0);
  95337. * //pass video frame as texture
  95338. * texture(vid);
  95339. * rect(-40, -40, 80, 80);
  95340. * }
  95341. *
  95342. * function mousePressed() {
  95343. * vid.loop();
  95344. * }
  95345. * </code>
  95346. * </div>
  95347. *
  95348. * @alt
  95349. * Rotating view of many images umbrella and grid roof on a 3d plane
  95350. * black canvas
  95351. * black canvas
  95352. */
  95353. _main.default.prototype.texture = function(tex) {
  95354. this._assert3d('texture');
  95355. _main.default._validateParameters('texture', arguments);
  95356. if (tex.gifProperties) {
  95357. tex._animateGif(this);
  95358. }
  95359. this._renderer.drawMode = constants.TEXTURE;
  95360. this._renderer._useSpecularMaterial = false;
  95361. this._renderer._useEmissiveMaterial = false;
  95362. this._renderer._useNormalMaterial = false;
  95363. this._renderer._tex = tex;
  95364. this._renderer._setProperty('_doFill', true);
  95365. return this;
  95366. };
  95367. /**
  95368. * Sets the coordinate space for texture mapping. The default mode is IMAGE
  95369. * which refers to the actual coordinates of the image.
  95370. * NORMAL refers to a normalized space of values ranging from 0 to 1.
  95371. * This function only works in WEBGL mode.
  95372. *
  95373. * With IMAGE, if an image is 100 x 200 pixels, mapping the image onto the entire
  95374. * size of a quad would require the points (0,0) (100, 0) (100,200) (0,200).
  95375. * The same mapping in NORMAL is (0,0) (1,0) (1,1) (0,1).
  95376. * @method textureMode
  95377. * @param {Constant} mode either IMAGE or NORMAL
  95378. * @example
  95379. * <div>
  95380. * <code>
  95381. * let img;
  95382. *
  95383. * function preload() {
  95384. * img = loadImage('assets/laDefense.jpg');
  95385. * }
  95386. *
  95387. * function setup() {
  95388. * createCanvas(100, 100, WEBGL);
  95389. * }
  95390. *
  95391. * function draw() {
  95392. * texture(img);
  95393. * textureMode(NORMAL);
  95394. * beginShape();
  95395. * vertex(-50, -50, 0, 0);
  95396. * vertex(50, -50, 1, 0);
  95397. * vertex(50, 50, 1, 1);
  95398. * vertex(-50, 50, 0, 1);
  95399. * endShape();
  95400. * }
  95401. * </code>
  95402. * </div>
  95403. *
  95404. * @alt
  95405. * the underside of a white umbrella and gridded ceiling above
  95406. *
  95407. * <div>
  95408. * <code>
  95409. * let img;
  95410. *
  95411. * function preload() {
  95412. * img = loadImage('assets/laDefense.jpg');
  95413. * }
  95414. *
  95415. * function setup() {
  95416. * createCanvas(100, 100, WEBGL);
  95417. * }
  95418. *
  95419. * function draw() {
  95420. * texture(img);
  95421. * textureMode(NORMAL);
  95422. * beginShape();
  95423. * vertex(-50, -50, 0, 0);
  95424. * vertex(50, -50, img.width, 0);
  95425. * vertex(50, 50, img.width, img.height);
  95426. * vertex(-50, 50, 0, img.height);
  95427. * endShape();
  95428. * }
  95429. * </code>
  95430. * </div>
  95431. *
  95432. * @alt
  95433. * the underside of a white umbrella and gridded ceiling above
  95434. */
  95435. _main.default.prototype.textureMode = function(mode) {
  95436. if (mode !== constants.IMAGE && mode !== constants.NORMAL) {
  95437. console.warn(
  95438. 'You tried to set '.concat(
  95439. mode,
  95440. ' textureMode only supports IMAGE & NORMAL '
  95441. )
  95442. );
  95443. } else {
  95444. this._renderer.textureMode = mode;
  95445. }
  95446. };
  95447. /**
  95448. * Sets the global texture wrapping mode. This controls how textures behave
  95449. * when their uv's go outside of the 0 - 1 range. There are three options:
  95450. * CLAMP, REPEAT, and MIRROR.
  95451. *
  95452. * CLAMP causes the pixels at the edge of the texture to extend to the bounds
  95453. * REPEAT causes the texture to tile repeatedly until reaching the bounds
  95454. * MIRROR works similarly to REPEAT but it flips the texture with every new tile
  95455. *
  95456. * REPEAT & MIRROR are only available if the texture
  95457. * is a power of two size (128, 256, 512, 1024, etc.).
  95458. *
  95459. * This method will affect all textures in your sketch until a subsequent
  95460. * textureWrap call is made.
  95461. *
  95462. * If only one argument is provided, it will be applied to both the
  95463. * horizontal and vertical axes.
  95464. * @method textureWrap
  95465. * @param {Constant} wrapX either CLAMP, REPEAT, or MIRROR
  95466. * @param {Constant} [wrapY] either CLAMP, REPEAT, or MIRROR
  95467. * @example
  95468. * <div>
  95469. * <code>
  95470. * let img;
  95471. * function preload() {
  95472. * img = loadImage('assets/rockies128.jpg');
  95473. * }
  95474. *
  95475. * function setup() {
  95476. * createCanvas(100, 100, WEBGL);
  95477. * textureWrap(MIRROR);
  95478. * }
  95479. *
  95480. * function draw() {
  95481. * background(0);
  95482. *
  95483. * let dX = mouseX;
  95484. * let dY = mouseY;
  95485. *
  95486. * let u = lerp(1.0, 2.0, dX);
  95487. * let v = lerp(1.0, 2.0, dY);
  95488. *
  95489. * scale(width / 2);
  95490. *
  95491. * texture(img);
  95492. *
  95493. * beginShape(TRIANGLES);
  95494. * vertex(-1, -1, 0, 0, 0);
  95495. * vertex(1, -1, 0, u, 0);
  95496. * vertex(1, 1, 0, u, v);
  95497. *
  95498. * vertex(1, 1, 0, u, v);
  95499. * vertex(-1, 1, 0, 0, v);
  95500. * vertex(-1, -1, 0, 0, 0);
  95501. * endShape();
  95502. * }
  95503. * </code>
  95504. * </div>
  95505. *
  95506. * @alt
  95507. * an image of the rocky mountains repeated in mirrored tiles
  95508. */
  95509. _main.default.prototype.textureWrap = function(wrapX) {
  95510. var wrapY =
  95511. arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : wrapX;
  95512. this._renderer.textureWrapX = wrapX;
  95513. this._renderer.textureWrapY = wrapY;
  95514. var textures = this._renderer.textures;
  95515. for (var i = 0; i < textures.length; i++) {
  95516. textures[i].setWrapMode(wrapX, wrapY);
  95517. }
  95518. };
  95519. /**
  95520. * Normal material for geometry is a material that is not affected by light.
  95521. * It is not reflective and is a placeholder material often used for debugging.
  95522. * Surfaces facing the X-axis, become red, those facing the Y-axis, become green and those facing the Z-axis, become blue.
  95523. * You can view all possible materials in this
  95524. * <a href="https://p5js.org/examples/3d-materials.html">example</a>.
  95525. * @method normalMaterial
  95526. * @chainable
  95527. * @example
  95528. * <div>
  95529. * <code>
  95530. * function setup() {
  95531. * createCanvas(100, 100, WEBGL);
  95532. * }
  95533. *
  95534. * function draw() {
  95535. * background(200);
  95536. * normalMaterial();
  95537. * sphere(40);
  95538. * }
  95539. * </code>
  95540. * </div>
  95541. * @alt
  95542. * Red, green and blue gradient.
  95543. */
  95544. _main.default.prototype.normalMaterial = function() {
  95545. this._assert3d('normalMaterial');
  95546. for (
  95547. var _len = arguments.length, args = new Array(_len), _key = 0;
  95548. _key < _len;
  95549. _key++
  95550. ) {
  95551. args[_key] = arguments[_key];
  95552. }
  95553. _main.default._validateParameters('normalMaterial', args);
  95554. this._renderer.drawMode = constants.FILL;
  95555. this._renderer._useSpecularMaterial = false;
  95556. this._renderer._useEmissiveMaterial = false;
  95557. this._renderer._useNormalMaterial = true;
  95558. this._renderer.curFillColor = [1, 1, 1, 1];
  95559. this._renderer._setProperty('_doFill', true);
  95560. this.noStroke();
  95561. return this;
  95562. };
  95563. /**
  95564. * Ambient material for geometry with a given color. Ambient material defines the color the object reflects under any lighting.
  95565. * For example, if the ambient material of an object is pure red, but the ambient lighting only contains green, the object will not reflect any light.
  95566. * Here's an <a href="https://p5js.org/examples/3d-materials.html">example containing all possible materials</a>.
  95567. * @method ambientMaterial
  95568. * @param {Number} v1 gray value, red or hue value
  95569. * (depending on the current color mode),
  95570. * @param {Number} [v2] green or saturation value
  95571. * @param {Number} [v3] blue or brightness value
  95572. * @chainable
  95573. * @example
  95574. * <div>
  95575. * <code>
  95576. * function setup() {
  95577. * createCanvas(100, 100, WEBGL);
  95578. * }
  95579. * function draw() {
  95580. * background(0);
  95581. * noStroke();
  95582. * ambientLight(200);
  95583. * ambientMaterial(70, 130, 230);
  95584. * sphere(40);
  95585. * }
  95586. * </code>
  95587. * </div>
  95588. * <div>
  95589. * <code>
  95590. * // ambientLight is both red and blue (magenta),
  95591. * // so object only reflects it's red and blue components
  95592. * function setup() {
  95593. * createCanvas(100, 100, WEBGL);
  95594. * }
  95595. * function draw() {
  95596. * background(70);
  95597. * ambientLight(100); // white light
  95598. * ambientMaterial(255, 0, 255); // pink material
  95599. * box(30);
  95600. * }
  95601. * </code>
  95602. * </div>
  95603. * <div>
  95604. * <code>
  95605. * // ambientLight is green. Since object does not contain
  95606. * // green, it does not reflect any light
  95607. * function setup() {
  95608. * createCanvas(100, 100, WEBGL);
  95609. * }
  95610. * function draw() {
  95611. * background(70);
  95612. * ambientLight(0, 255, 0); // green light
  95613. * ambientMaterial(255, 0, 255); // pink material
  95614. * box(30);
  95615. * }
  95616. * </code>
  95617. * </div>
  95618. * @alt
  95619. * radiating light source from top right of canvas
  95620. * box reflecting only red and blue light
  95621. * box reflecting no light
  95622. */
  95623. /**
  95624. * @method ambientMaterial
  95625. * @param {Number[]|String|p5.Color} color color, color Array, or CSS color string
  95626. * @chainable
  95627. */
  95628. _main.default.prototype.ambientMaterial = function(v1, v2, v3) {
  95629. this._assert3d('ambientMaterial');
  95630. _main.default._validateParameters('ambientMaterial', arguments);
  95631. var color = _main.default.prototype.color.apply(this, arguments);
  95632. this._renderer.curFillColor = color._array;
  95633. this._renderer._useSpecularMaterial = false;
  95634. this._renderer._useEmissiveMaterial = false;
  95635. this._renderer._useNormalMaterial = false;
  95636. this._renderer._enableLighting = true;
  95637. this._renderer._tex = null;
  95638. return this;
  95639. };
  95640. /**
  95641. * Sets the emissive color of the material used for geometry drawn to
  95642. * the screen. This is a misnomer in the sense that the material does not
  95643. * actually emit light that effects surrounding polygons. Instead,
  95644. * it gives the appearance that the object is glowing. An emissive material
  95645. * will display at full strength even if there is no light for it to reflect.
  95646. * @method emissiveMaterial
  95647. * @param {Number} v1 gray value, red or hue value
  95648. * (depending on the current color mode),
  95649. * @param {Number} [v2] green or saturation value
  95650. * @param {Number} [v3] blue or brightness value
  95651. * @param {Number} [a] opacity
  95652. * @chainable
  95653. * @example
  95654. * <div>
  95655. * <code>
  95656. * function setup() {
  95657. * createCanvas(100, 100, WEBGL);
  95658. * }
  95659. * function draw() {
  95660. * background(0);
  95661. * noStroke();
  95662. * ambientLight(0);
  95663. * emissiveMaterial(130, 230, 0);
  95664. * sphere(40);
  95665. * }
  95666. * </code>
  95667. * </div>
  95668. *
  95669. * @alt
  95670. * radiating light source from top right of canvas
  95671. */
  95672. /**
  95673. * @method emissiveMaterial
  95674. * @param {Number[]|String|p5.Color} color color, color Array, or CSS color string
  95675. * @chainable
  95676. */
  95677. _main.default.prototype.emissiveMaterial = function(v1, v2, v3, a) {
  95678. this._assert3d('emissiveMaterial');
  95679. _main.default._validateParameters('emissiveMaterial', arguments);
  95680. var color = _main.default.prototype.color.apply(this, arguments);
  95681. this._renderer.curFillColor = color._array;
  95682. this._renderer._useSpecularMaterial = false;
  95683. this._renderer._useEmissiveMaterial = true;
  95684. this._renderer._useNormalMaterial = false;
  95685. this._renderer._enableLighting = true;
  95686. this._renderer._tex = null;
  95687. return this;
  95688. };
  95689. /**
  95690. * Specular material for geometry with a given color. Specular material is a shiny reflective material.
  95691. * Like ambient material it also defines the color the object reflects under ambient lighting.
  95692. * For example, if the specular material of an object is pure red, but the ambient lighting only contains green, the object will not reflect any light.
  95693. * For all other types of light like point and directional light, a specular material will reflect the color of the light source to the viewer.
  95694. * Here's an <a href="https://p5js.org/examples/3d-materials.html">example containing all possible materials</a>.
  95695. *
  95696. * @method specularMaterial
  95697. * @param {Number} gray number specifying value between white and black.
  95698. * @param {Number} [alpha] alpha value relative to current color range
  95699. * (default is 0-255)
  95700. * @chainable
  95701. *
  95702. * @example
  95703. * <div>
  95704. * <code>
  95705. * function setup() {
  95706. * createCanvas(100, 100, WEBGL);
  95707. * noStroke();
  95708. * }
  95709. *
  95710. * function draw() {
  95711. * background(0);
  95712. *
  95713. * ambientLight(60);
  95714. *
  95715. * // add point light to showcase specular material
  95716. * let locX = mouseX - width / 2;
  95717. * let locY = mouseY - height / 2;
  95718. * pointLight(255, 255, 255, locX, locY, 50);
  95719. *
  95720. * specularMaterial(250);
  95721. * shininess(50);
  95722. * torus(30, 10, 64, 64);
  95723. * }
  95724. * </code>
  95725. * </div>
  95726. * @alt
  95727. * torus with specular material
  95728. */
  95729. /**
  95730. * @method specularMaterial
  95731. * @param {Number} v1 red or hue value relative to
  95732. * the current color range
  95733. * @param {Number} v2 green or saturation value
  95734. * relative to the current color range
  95735. * @param {Number} v3 blue or brightness value
  95736. * relative to the current color range
  95737. * @param {Number} [alpha]
  95738. * @chainable
  95739. */
  95740. /**
  95741. * @method specularMaterial
  95742. * @param {Number[]|String|p5.Color} color color Array, or CSS color string
  95743. * @chainable
  95744. */
  95745. _main.default.prototype.specularMaterial = function(v1, v2, v3, alpha) {
  95746. this._assert3d('specularMaterial');
  95747. _main.default._validateParameters('specularMaterial', arguments);
  95748. var color = _main.default.prototype.color.apply(this, arguments);
  95749. this._renderer.curFillColor = color._array;
  95750. this._renderer._useSpecularMaterial = true;
  95751. this._renderer._useEmissiveMaterial = false;
  95752. this._renderer._useNormalMaterial = false;
  95753. this._renderer._enableLighting = true;
  95754. this._renderer._tex = null;
  95755. return this;
  95756. };
  95757. /**
  95758. * Sets the amount of gloss in the surface of shapes.
  95759. * Used in combination with specularMaterial() in setting
  95760. * the material properties of shapes. The default and minimum value is 1.
  95761. * @method shininess
  95762. * @param {Number} shine Degree of Shininess.
  95763. * Defaults to 1.
  95764. * @chainable
  95765. * @example
  95766. * <div>
  95767. * <code>
  95768. * function setup() {
  95769. * createCanvas(100, 100, WEBGL);
  95770. * }
  95771. * function draw() {
  95772. * background(0);
  95773. * noStroke();
  95774. * let locX = mouseX - width / 2;
  95775. * let locY = mouseY - height / 2;
  95776. * ambientLight(60, 60, 60);
  95777. * pointLight(255, 255, 255, locX, locY, 50);
  95778. * specularMaterial(250);
  95779. * translate(-25, 0, 0);
  95780. * shininess(1);
  95781. * sphere(20);
  95782. * translate(50, 0, 0);
  95783. * shininess(20);
  95784. * sphere(20);
  95785. * }
  95786. * </code>
  95787. * </div>
  95788. * @alt
  95789. * Shininess on Camera changes position with mouse
  95790. */
  95791. _main.default.prototype.shininess = function(shine) {
  95792. this._assert3d('shininess');
  95793. _main.default._validateParameters('shininess', arguments);
  95794. if (shine < 1) {
  95795. shine = 1;
  95796. }
  95797. this._renderer._useShininess = shine;
  95798. return this;
  95799. };
  95800. /**
  95801. * @private blends colors according to color components.
  95802. * If alpha value is less than 1, or non-standard blendMode
  95803. * we need to enable blending on our gl context.
  95804. * @param {Number[]} color [description]
  95805. * @return {Number[]]} Normalized numbers array
  95806. */
  95807. _main.default.RendererGL.prototype._applyColorBlend = function(colors) {
  95808. var gl = this.GL;
  95809. var isTexture = this.drawMode === constants.TEXTURE;
  95810. var doBlend = isTexture || colors[colors.length - 1] < 1.0 || this._isErasing;
  95811. if (doBlend !== this._isBlending) {
  95812. if (
  95813. doBlend ||
  95814. (this.curBlendMode !== constants.BLEND &&
  95815. this.curBlendMode !== constants.ADD)
  95816. ) {
  95817. gl.enable(gl.BLEND);
  95818. } else {
  95819. gl.disable(gl.BLEND);
  95820. }
  95821. gl.depthMask(true);
  95822. this._isBlending = doBlend;
  95823. }
  95824. this._applyBlendMode();
  95825. return colors;
  95826. };
  95827. /**
  95828. * @private sets blending in gl context to curBlendMode
  95829. * @param {Number[]} color [description]
  95830. * @return {Number[]]} Normalized numbers array
  95831. */
  95832. _main.default.RendererGL.prototype._applyBlendMode = function() {
  95833. if (this._cachedBlendMode === this.curBlendMode) {
  95834. return;
  95835. }
  95836. var gl = this.GL;
  95837. switch (this.curBlendMode) {
  95838. case constants.BLEND:
  95839. case constants.ADD:
  95840. gl.blendEquation(gl.FUNC_ADD);
  95841. gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
  95842. break;
  95843. case constants.REMOVE:
  95844. gl.blendEquation(gl.FUNC_REVERSE_SUBTRACT);
  95845. gl.blendFunc(gl.SRC_ALPHA, gl.DST_ALPHA);
  95846. break;
  95847. case constants.MULTIPLY:
  95848. gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
  95849. gl.blendFuncSeparate(gl.ZERO, gl.SRC_COLOR, gl.ONE, gl.ONE);
  95850. break;
  95851. case constants.SCREEN:
  95852. gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
  95853. gl.blendFuncSeparate(gl.ONE_MINUS_DST_COLOR, gl.ONE, gl.ONE, gl.ONE);
  95854. break;
  95855. case constants.EXCLUSION:
  95856. gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
  95857. gl.blendFuncSeparate(
  95858. gl.ONE_MINUS_DST_COLOR,
  95859. gl.ONE_MINUS_SRC_COLOR,
  95860. gl.ONE,
  95861. gl.ONE
  95862. );
  95863. break;
  95864. case constants.REPLACE:
  95865. gl.blendEquation(gl.FUNC_ADD);
  95866. gl.blendFunc(gl.ONE, gl.ZERO);
  95867. break;
  95868. case constants.SUBTRACT:
  95869. gl.blendEquationSeparate(gl.FUNC_REVERSE_SUBTRACT, gl.FUNC_ADD);
  95870. gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE);
  95871. break;
  95872. case constants.DARKEST:
  95873. if (this.blendExt) {
  95874. gl.blendEquationSeparate(this.blendExt.MIN_EXT, gl.FUNC_ADD);
  95875. gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE);
  95876. } else {
  95877. console.warn(
  95878. 'blendMode(DARKEST) does not work in your browser in WEBGL mode.'
  95879. );
  95880. }
  95881. break;
  95882. case constants.LIGHTEST:
  95883. if (this.blendExt) {
  95884. gl.blendEquationSeparate(this.blendExt.MAX_EXT, gl.FUNC_ADD);
  95885. gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE);
  95886. } else {
  95887. console.warn(
  95888. 'blendMode(LIGHTEST) does not work in your browser in WEBGL mode.'
  95889. );
  95890. }
  95891. break;
  95892. default:
  95893. console.error(
  95894. 'Oops! Somehow RendererGL set curBlendMode to an unsupported mode.'
  95895. );
  95896. break;
  95897. }
  95898. if (!this._isErasing) {
  95899. this._cachedBlendMode = this.curBlendMode;
  95900. }
  95901. };
  95902. var _default = _main.default;
  95903. exports.default = _default;
  95904. },
  95905. {
  95906. '../core/constants': 272,
  95907. '../core/main': 283,
  95908. './p5.Texture': 339,
  95909. 'core-js/modules/es.array.join': 175
  95910. }
  95911. ],
  95912. 331: [
  95913. function(_dereq_, module, exports) {
  95914. 'use strict';
  95915. Object.defineProperty(exports, '__esModule', { value: true });
  95916. exports.default = void 0;
  95917. var _main = _interopRequireDefault(_dereq_('../core/main'));
  95918. function _interopRequireDefault(obj) {
  95919. return obj && obj.__esModule ? obj : { default: obj };
  95920. } /** ////////////////////////////////////////////////////////////////////////////////
  95921. * @module Lights, Camera
  95922. * @submodule Camera
  95923. * @requires core
  95924. */
  95925. // p5.Prototype Methods
  95926. ////////////////////////////////////////////////////////////////////////////////
  95927. /**
  95928. * Sets the position of the current camera in a 3D sketch.
  95929. * Parameters for this function define the camera's position,
  95930. * the center of the sketch (where the camera is pointing),
  95931. * and an up direction (the orientation of the camera).
  95932. *
  95933. * This function simulates the movements of the camera, allowing objects to be
  95934. * viewed from various angles. Remember, it does not move the objects themselves
  95935. * but the camera instead. For example when the centerX value is positive,
  95936. * and the camera is rotating to the right side of the sketch,
  95937. * the object will seem like it's moving to the left.
  95938. *
  95939. * See this <a href = "https://www.openprocessing.org/sketch/740258">example</a>
  95940. * to view the position of your camera.
  95941. *
  95942. * If no parameters are given, the following default is used:
  95943. * camera(0, 0, (height/2) / tan(PI/6), 0, 0, 0, 0, 1, 0)
  95944. * @method camera
  95945. * @constructor
  95946. * @for p5
  95947. * @param {Number} [x] camera position value on x axis
  95948. * @param {Number} [y] camera position value on y axis
  95949. * @param {Number} [z] camera position value on z axis
  95950. * @param {Number} [centerX] x coordinate representing center of the sketch
  95951. * @param {Number} [centerY] y coordinate representing center of the sketch
  95952. * @param {Number} [centerZ] z coordinate representing center of the sketch
  95953. * @param {Number} [upX] x component of direction 'up' from camera
  95954. * @param {Number} [upY] y component of direction 'up' from camera
  95955. * @param {Number} [upZ] z component of direction 'up' from camera
  95956. * @chainable
  95957. * @example
  95958. * <div>
  95959. * <code>
  95960. * function setup() {
  95961. * createCanvas(100, 100, WEBGL);
  95962. * }
  95963. * function draw() {
  95964. * background(204);
  95965. * //move the camera away from the plane by a sin wave
  95966. * camera(0, 0, 20 + sin(frameCount * 0.01) * 10, 0, 0, 0, 0, 1, 0);
  95967. * plane(10, 10);
  95968. * }
  95969. * </code>
  95970. * </div>
  95971. *
  95972. * @example
  95973. * <div>
  95974. * <code>
  95975. * //move slider to see changes!
  95976. * //sliders control the first 6 parameters of camera()
  95977. * let sliderGroup = [];
  95978. * let X;
  95979. * let Y;
  95980. * let Z;
  95981. * let centerX;
  95982. * let centerY;
  95983. * let centerZ;
  95984. * let h = 20;
  95985. *
  95986. * function setup() {
  95987. * createCanvas(100, 100, WEBGL);
  95988. * //create sliders
  95989. * for (var i = 0; i < 6; i++) {
  95990. * if (i === 2) {
  95991. * sliderGroup[i] = createSlider(10, 400, 200);
  95992. * } else {
  95993. * sliderGroup[i] = createSlider(-400, 400, 0);
  95994. * }
  95995. * h = map(i, 0, 6, 5, 85);
  95996. * sliderGroup[i].position(10, height + h);
  95997. * sliderGroup[i].style('width', '80px');
  95998. * }
  95999. * }
  96000. *
  96001. * function draw() {
  96002. * background(60);
  96003. * // assigning sliders' value to each parameters
  96004. * X = sliderGroup[0].value();
  96005. * Y = sliderGroup[1].value();
  96006. * Z = sliderGroup[2].value();
  96007. * centerX = sliderGroup[3].value();
  96008. * centerY = sliderGroup[4].value();
  96009. * centerZ = sliderGroup[5].value();
  96010. * camera(X, Y, Z, centerX, centerY, centerZ, 0, 1, 0);
  96011. * stroke(255);
  96012. * fill(255, 102, 94);
  96013. * box(85);
  96014. * }
  96015. * </code>
  96016. * </div>
  96017. * @alt
  96018. * White square repeatedly grows to fill canvas and then shrinks.
  96019. * An interactive example of a red cube with 3 sliders for moving it across x, y,
  96020. * z axis and 3 sliders for shifting it's center.
  96021. */ _main.default.prototype.camera = function() {
  96022. var _this$_renderer$_curC;
  96023. this._assert3d('camera');
  96024. for (
  96025. var _len = arguments.length, args = new Array(_len), _key = 0;
  96026. _key < _len;
  96027. _key++
  96028. ) {
  96029. args[_key] = arguments[_key];
  96030. }
  96031. _main.default._validateParameters('camera', args);
  96032. (_this$_renderer$_curC = this._renderer._curCamera).camera.apply(
  96033. _this$_renderer$_curC,
  96034. args
  96035. );
  96036. return this;
  96037. };
  96038. /**
  96039. * Sets a perspective projection for the current camera in a 3D sketch.
  96040. * This projection represents depth through foreshortening: objects
  96041. * that are close to the camera appear their actual size while those
  96042. * that are further away from the camera appear smaller.
  96043. *
  96044. * The parameters to this function define the viewing frustum
  96045. * (the truncated pyramid within which objects are seen by the camera) through
  96046. * vertical field of view, aspect ratio (usually width/height), and near and far
  96047. * clipping planes.
  96048. *
  96049. * If no parameters are given, the following default is used:
  96050. * perspective(PI/3, width/height, eyeZ/10, eyeZ*10),
  96051. * where eyeZ is equal to ((height/2) / tan(PI/6)).
  96052. * @method perspective
  96053. * @for p5
  96054. * @param {Number} [fovy] camera frustum vertical field of view,
  96055. * from bottom to top of view, in <a href="#/p5/angleMode">angleMode</a> units
  96056. * @param {Number} [aspect] camera frustum aspect ratio
  96057. * @param {Number} [near] frustum near plane length
  96058. * @param {Number} [far] frustum far plane length
  96059. * @chainable
  96060. * @example
  96061. * <div>
  96062. * <code>
  96063. * //drag the mouse to look around!
  96064. * function setup() {
  96065. * createCanvas(100, 100, WEBGL);
  96066. * perspective(PI / 3.0, width / height, 0.1, 500);
  96067. * }
  96068. * function draw() {
  96069. * background(200);
  96070. * orbitControl();
  96071. * normalMaterial();
  96072. *
  96073. * rotateX(-0.3);
  96074. * rotateY(-0.2);
  96075. * translate(0, 0, -50);
  96076. *
  96077. * push();
  96078. * translate(-15, 0, sin(frameCount / 30) * 95);
  96079. * box(30);
  96080. * pop();
  96081. * push();
  96082. * translate(15, 0, sin(frameCount / 30 + PI) * 95);
  96083. * box(30);
  96084. * pop();
  96085. * }
  96086. * </code>
  96087. * </div>
  96088. *
  96089. * @alt
  96090. * two colored 3D boxes move back and forth, rotating as mouse is dragged.
  96091. */
  96092. _main.default.prototype.perspective = function() {
  96093. var _this$_renderer$_curC2;
  96094. this._assert3d('perspective');
  96095. for (
  96096. var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
  96097. _key2 < _len2;
  96098. _key2++
  96099. ) {
  96100. args[_key2] = arguments[_key2];
  96101. }
  96102. _main.default._validateParameters('perspective', args);
  96103. (_this$_renderer$_curC2 = this._renderer._curCamera).perspective.apply(
  96104. _this$_renderer$_curC2,
  96105. args
  96106. );
  96107. return this;
  96108. };
  96109. /**
  96110. * Sets an orthographic projection for the current camera in a 3D sketch
  96111. * and defines a box-shaped viewing frustum within which objects are seen.
  96112. * In this projection, all objects with the same dimension appear the same
  96113. * size, regardless of whether they are near or far from the camera.
  96114. *
  96115. * The parameters to this function specify the viewing frustum where
  96116. * left and right are the minimum and maximum x values, top and bottom are
  96117. * the minimum and maximum y values, and near and far are the minimum and
  96118. * maximum z values.
  96119. *
  96120. * If no parameters are given, the following default is used:
  96121. * ortho(-width/2, width/2, -height/2, height/2).
  96122. * @method ortho
  96123. * @for p5
  96124. * @param {Number} [left] camera frustum left plane
  96125. * @param {Number} [right] camera frustum right plane
  96126. * @param {Number} [bottom] camera frustum bottom plane
  96127. * @param {Number} [top] camera frustum top plane
  96128. * @param {Number} [near] camera frustum near plane
  96129. * @param {Number} [far] camera frustum far plane
  96130. * @chainable
  96131. * @example
  96132. * <div>
  96133. * <code>
  96134. * //drag the mouse to look around!
  96135. * //there's no vanishing point
  96136. * function setup() {
  96137. * createCanvas(100, 100, WEBGL);
  96138. * ortho(-width / 2, width / 2, height / 2, -height / 2, 0, 500);
  96139. * }
  96140. * function draw() {
  96141. * background(200);
  96142. * orbitControl();
  96143. * normalMaterial();
  96144. *
  96145. * rotateX(0.2);
  96146. * rotateY(-0.2);
  96147. * push();
  96148. * translate(-15, 0, sin(frameCount / 30) * 65);
  96149. * box(30);
  96150. * pop();
  96151. * push();
  96152. * translate(15, 0, sin(frameCount / 30 + PI) * 65);
  96153. * box(30);
  96154. * pop();
  96155. * }
  96156. * </code>
  96157. * </div>
  96158. *
  96159. * @alt
  96160. * two 3D boxes move back and forth along same plane, rotating as mouse is dragged.
  96161. */
  96162. _main.default.prototype.ortho = function() {
  96163. var _this$_renderer$_curC3;
  96164. this._assert3d('ortho');
  96165. for (
  96166. var _len3 = arguments.length, args = new Array(_len3), _key3 = 0;
  96167. _key3 < _len3;
  96168. _key3++
  96169. ) {
  96170. args[_key3] = arguments[_key3];
  96171. }
  96172. _main.default._validateParameters('ortho', args);
  96173. (_this$_renderer$_curC3 = this._renderer._curCamera).ortho.apply(
  96174. _this$_renderer$_curC3,
  96175. args
  96176. );
  96177. return this;
  96178. };
  96179. /**
  96180. * Sets the frustum of the current camera as defined by
  96181. * the parameters.
  96182. *
  96183. * A frustum is a geometric form: a pyramid with its top
  96184. * cut off. With the viewer's eye at the imaginary top of
  96185. * the pyramid, the six planes of the frustum act as clipping
  96186. * planes when rendering a 3D view. Thus, any form inside the
  96187. * clipping planes is visible; anything outside
  96188. * those planes is not visible.
  96189. *
  96190. * Setting the frustum changes the perspective of the scene being rendered.
  96191. * This can be achieved more simply in many cases by using
  96192. * <a href="https://p5js.org/reference/#/p5/perspective">perspective()</a>.
  96193. *
  96194. * If no parameters are given, the following default is used:
  96195. * frustum(-width/2, width/2, -height/2, height/2, 0, max(width, height)).
  96196. * @method frustum
  96197. * @for p5
  96198. * @param {Number} [left] camera frustum left plane
  96199. * @param {Number} [right] camera frustum right plane
  96200. * @param {Number} [bottom] camera frustum bottom plane
  96201. * @param {Number} [top] camera frustum top plane
  96202. * @param {Number} [near] camera frustum near plane
  96203. * @param {Number} [far] camera frustum far plane
  96204. * @chainable
  96205. * @example
  96206. * <div>
  96207. * <code>
  96208. * function setup() {
  96209. * createCanvas(100, 100, WEBGL);
  96210. * setAttributes('antialias', true);
  96211. * frustum(-0.1, 0.1, -0.1, 0.1, 0.1, 200);
  96212. * }
  96213. * function draw() {
  96214. * background(200);
  96215. * orbitControl();
  96216. * normalMaterial();
  96217. *
  96218. * rotateY(-0.2);
  96219. * rotateX(-0.3);
  96220. * push();
  96221. * translate(-15, 0, sin(frameCount / 30) * 25);
  96222. * box(30);
  96223. * pop();
  96224. * push();
  96225. * translate(15, 0, sin(frameCount / 30 + PI) * 25);
  96226. * box(30);
  96227. * pop();
  96228. * }
  96229. * </code>
  96230. * </div>
  96231. *
  96232. * @alt
  96233. * two 3D boxes move back and forth along same plane, rotating as mouse is dragged.
  96234. */
  96235. _main.default.prototype.frustum = function() {
  96236. var _this$_renderer$_curC4;
  96237. this._assert3d('frustum');
  96238. for (
  96239. var _len4 = arguments.length, args = new Array(_len4), _key4 = 0;
  96240. _key4 < _len4;
  96241. _key4++
  96242. ) {
  96243. args[_key4] = arguments[_key4];
  96244. }
  96245. _main.default._validateParameters('frustum', args);
  96246. (_this$_renderer$_curC4 = this._renderer._curCamera).frustum.apply(
  96247. _this$_renderer$_curC4,
  96248. args
  96249. );
  96250. return this;
  96251. };
  96252. ////////////////////////////////////////////////////////////////////////////////
  96253. // p5.Camera
  96254. ////////////////////////////////////////////////////////////////////////////////
  96255. /**
  96256. * Creates a new <a href="#/p5.Camera">p5.Camera</a> object and sets it
  96257. * as the current (active) camera.
  96258. *
  96259. * The new camera is initialized with a default position
  96260. * (see <a href="#/p5.Camera/camera">camera()</a>)
  96261. * and a default perspective projection
  96262. * (see <a href="#/p5.Camera/perspective">perspective()</a>).
  96263. * Its properties can be controlled with the <a href="#/p5.Camera">p5.Camera</a>
  96264. * methods.
  96265. *
  96266. * Note: Every 3D sketch starts with a default camera initialized.
  96267. * This camera can be controlled with the global methods
  96268. * <a href="#/p5/camera">camera()</a>,
  96269. * <a href="#/p5/perspective">perspective()</a>, <a href="#/p5/ortho">ortho()</a>,
  96270. * and <a href="#/p5/frustum">frustum()</a> if it is the only camera
  96271. * in the scene.
  96272. * @method createCamera
  96273. * @return {p5.Camera} The newly created camera object.
  96274. * @for p5
  96275. * @example
  96276. * <div><code>
  96277. * // Creates a camera object and animates it around a box.
  96278. * let camera;
  96279. * function setup() {
  96280. * createCanvas(100, 100, WEBGL);
  96281. * background(0);
  96282. * camera = createCamera();
  96283. * }
  96284. *
  96285. * function draw() {
  96286. * camera.lookAt(0, 0, 0);
  96287. * camera.setPosition(sin(frameCount / 60) * 200, 0, 100);
  96288. * box(20);
  96289. * }
  96290. * </code></div>
  96291. *
  96292. * @alt
  96293. * An example that creates a camera and moves it around the box.
  96294. */
  96295. _main.default.prototype.createCamera = function() {
  96296. this._assert3d('createCamera');
  96297. var _cam = new _main.default.Camera(this._renderer);
  96298. // compute default camera settings, then set a default camera
  96299. _cam._computeCameraDefaultSettings();
  96300. _cam._setDefaultCamera();
  96301. // set renderer current camera to the new camera
  96302. this._renderer._curCamera = _cam;
  96303. return _cam;
  96304. };
  96305. /**
  96306. * This class describes a camera for use in p5's
  96307. * <a href="https://github.com/processing/p5.js/wiki/Getting-started-with-WebGL-in-p5">
  96308. * WebGL mode</a>. It contains camera position, orientation, and projection
  96309. * information necessary for rendering a 3D scene.
  96310. *
  96311. * New p5.Camera objects can be made through the
  96312. * <a href="#/p5/createCamera">createCamera()</a> function and controlled through
  96313. * the methods described below. A camera created in this way will use a default
  96314. * position in the scene and a default perspective projection until these
  96315. * properties are changed through the various methods available. It is possible
  96316. * to create multiple cameras, in which case the current camera
  96317. * can be set through the <a href="#/p5/setCamera">setCamera()</a> method.
  96318. *
  96319. * Note:
  96320. * The methods below operate in two coordinate systems: the 'world' coordinate
  96321. * system describe positions in terms of their relationship to the origin along
  96322. * the X, Y and Z axes whereas the camera's 'local' coordinate system
  96323. * describes positions from the camera's point of view: left-right, up-down,
  96324. * and forward-backward. The <a href="#/p5.Camera/move">move()</a> method,
  96325. * for instance, moves the camera along its own axes, whereas the
  96326. * <a href="#/p5.Camera/setPosition">setPosition()</a>
  96327. * method sets the camera's position in world-space.
  96328. *
  96329. * The camera object propreties
  96330. * <code>eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ</code>
  96331. * which describes camera position, orientation, and projection
  96332. * are also accessible via the camera object generated using
  96333. * <a href="#/p5/createCamera">createCamera()</a>
  96334. *
  96335. * @class p5.Camera
  96336. * @param {rendererGL} rendererGL instance of WebGL renderer
  96337. * @example
  96338. * <div>
  96339. * <code>
  96340. * let cam;
  96341. * let delta = 0.01;
  96342. *
  96343. * function setup() {
  96344. * createCanvas(100, 100, WEBGL);
  96345. * normalMaterial();
  96346. * cam = createCamera();
  96347. * // set initial pan angle
  96348. * cam.pan(-0.8);
  96349. * }
  96350. *
  96351. * function draw() {
  96352. * background(200);
  96353. *
  96354. * // pan camera according to angle 'delta'
  96355. * cam.pan(delta);
  96356. *
  96357. * // every 160 frames, switch direction
  96358. * if (frameCount % 160 === 0) {
  96359. * delta *= -1;
  96360. * }
  96361. *
  96362. * rotateX(frameCount * 0.01);
  96363. * translate(-100, 0, 0);
  96364. * box(20);
  96365. * translate(35, 0, 0);
  96366. * box(20);
  96367. * translate(35, 0, 0);
  96368. * box(20);
  96369. * translate(35, 0, 0);
  96370. * box(20);
  96371. * translate(35, 0, 0);
  96372. * box(20);
  96373. * translate(35, 0, 0);
  96374. * box(20);
  96375. * translate(35, 0, 0);
  96376. * box(20);
  96377. * }
  96378. * </code>
  96379. * </div>
  96380. *
  96381. * @alt
  96382. * camera view pans left and right across a series of rotating 3D boxes.
  96383. */
  96384. _main.default.Camera = function(renderer) {
  96385. this._renderer = renderer;
  96386. this.cameraType = 'default';
  96387. this.cameraMatrix = new _main.default.Matrix();
  96388. this.projMatrix = new _main.default.Matrix();
  96389. };
  96390. /**
  96391. * camera position value on x axis
  96392. * @property {Number} eyeX
  96393. * @readonly
  96394. * @example
  96395. *
  96396. * <div class='norender'><code>
  96397. * let cam, div;
  96398. * function setup() {
  96399. * createCanvas(100, 100, WEBGL);
  96400. * background(0);
  96401. * cam = createCamera();
  96402. * div = createDiv();
  96403. * div.position(0, 0);
  96404. * }
  96405. *
  96406. * function draw() {
  96407. * orbitControl();
  96408. * box(10);
  96409. * div.html('eyeX = ' + cam.eyeX);
  96410. * }
  96411. * </code></div>
  96412. *
  96413. * @alt
  96414. * An example showing the use of camera object properties
  96415. *
  96416. */
  96417. /**
  96418. * camera position value on y axis
  96419. * @property {Number} eyeY
  96420. * @readonly
  96421. * @example
  96422. * <div class='norender'><code>
  96423. * let cam, div;
  96424. * function setup() {
  96425. * createCanvas(100, 100, WEBGL);
  96426. * background(0);
  96427. * cam = createCamera();
  96428. * div = createDiv();
  96429. * div.position(0, 0);
  96430. * }
  96431. *
  96432. * function draw() {
  96433. * orbitControl();
  96434. * box(10);
  96435. * div.html('eyeY = ' + cam.eyeY);
  96436. * }
  96437. * </code></div>
  96438. *
  96439. * @alt
  96440. * An example showing the use of camera object properties
  96441. *
  96442. */
  96443. /**
  96444. * camera position value on z axis
  96445. * @property {Number} eyeZ
  96446. * @readonly
  96447. * @example
  96448. * <div class='norender'><code>
  96449. * let cam, div;
  96450. * function setup() {
  96451. * createCanvas(100, 100, WEBGL);
  96452. * background(0);
  96453. * cam = createCamera();
  96454. * div = createDiv();
  96455. * div.position(0, 0);
  96456. * }
  96457. *
  96458. * function draw() {
  96459. * orbitControl();
  96460. * box(10);
  96461. * div.html('eyeZ = ' + cam.eyeZ);
  96462. * }
  96463. * </code></div>
  96464. *
  96465. * @alt
  96466. * An example showing the use of camera object properties
  96467. *
  96468. */
  96469. /**
  96470. * x coordinate representing center of the sketch
  96471. * @property {Number} centerX
  96472. * @readonly
  96473. * @example
  96474. * <div class='norender'><code>
  96475. * let cam, div;
  96476. * function setup() {
  96477. * createCanvas(100, 100, WEBGL);
  96478. * background(255);
  96479. * cam = createCamera();
  96480. * cam.lookAt(1, 0, 0);
  96481. * div = createDiv('centerX = ' + cam.centerX);
  96482. * div.position(0, 0);
  96483. * div.style('color', 'white');
  96484. * }
  96485. *
  96486. * function draw() {
  96487. * orbitControl();
  96488. * box(10);
  96489. * }
  96490. * </code></div>
  96491. *
  96492. * @alt
  96493. * An example showing the use of camera object properties
  96494. *
  96495. */
  96496. /**
  96497. * y coordinate representing center of the sketch
  96498. * @property {Number} centerY
  96499. * @readonly
  96500. * @example
  96501. * <div class='norender'><code>
  96502. * let cam, div;
  96503. * function setup() {
  96504. * createCanvas(100, 100, WEBGL);
  96505. * background(255);
  96506. * cam = createCamera();
  96507. * cam.lookAt(0, 1, 0);
  96508. * div = createDiv('centerY = ' + cam.centerY);
  96509. * div.position(0, 0);
  96510. * div.style('color', 'white');
  96511. * }
  96512. *
  96513. * function draw() {
  96514. * orbitControl();
  96515. * box(10);
  96516. * }
  96517. * </code></div>
  96518. *
  96519. * @alt
  96520. * An example showing the use of camera object properties
  96521. *
  96522. */
  96523. /**
  96524. * z coordinate representing center of the sketch
  96525. * @property {Number} centerZ
  96526. * @readonly
  96527. * @example
  96528. * <div class='norender'><code>
  96529. * let cam, div;
  96530. * function setup() {
  96531. * createCanvas(100, 100, WEBGL);
  96532. * background(255);
  96533. * cam = createCamera();
  96534. * cam.lookAt(0, 0, 1);
  96535. * div = createDiv('centerZ = ' + cam.centerZ);
  96536. * div.position(0, 0);
  96537. * div.style('color', 'white');
  96538. * }
  96539. *
  96540. * function draw() {
  96541. * orbitControl();
  96542. * box(10);
  96543. * }
  96544. * </code></div>
  96545. *
  96546. * @alt
  96547. * An example showing the use of camera object properties
  96548. *
  96549. */
  96550. /**
  96551. * x component of direction 'up' from camera
  96552. * @property {Number} upX
  96553. * @readonly
  96554. * @example
  96555. * <div class='norender'><code>
  96556. * let cam, div;
  96557. * function setup() {
  96558. * createCanvas(100, 100, WEBGL);
  96559. * background(255);
  96560. * cam = createCamera();
  96561. * div = createDiv('upX = ' + cam.upX);
  96562. * div.position(0, 0);
  96563. * div.style('color', 'blue');
  96564. * div.style('font-size', '18px');
  96565. * }
  96566. * </code></div>
  96567. *
  96568. * @alt
  96569. * An example showing the use of camera object properties
  96570. *
  96571. */
  96572. /**
  96573. * y component of direction 'up' from camera
  96574. * @property {Number} upY
  96575. * @readonly
  96576. * @example
  96577. * <div class='norender'><code>
  96578. * let cam, div;
  96579. * function setup() {
  96580. * createCanvas(100, 100, WEBGL);
  96581. * background(255);
  96582. * cam = createCamera();
  96583. * div = createDiv('upY = ' + cam.upY);
  96584. * div.position(0, 0);
  96585. * div.style('color', 'blue');
  96586. * div.style('font-size', '18px');
  96587. * }
  96588. * </code></div>
  96589. *
  96590. * @alt
  96591. * An example showing the use of camera object properties
  96592. *
  96593. */
  96594. /**
  96595. * z component of direction 'up' from camera
  96596. * @property {Number} upZ
  96597. * @readonly
  96598. * @example
  96599. * <div class='norender'><code>
  96600. * let cam, div;
  96601. * function setup() {
  96602. * createCanvas(100, 100, WEBGL);
  96603. * background(255);
  96604. * cam = createCamera();
  96605. * div = createDiv('upZ = ' + cam.upZ);
  96606. * div.position(0, 0);
  96607. * div.style('color', 'blue');
  96608. * div.style('font-size', '18px');
  96609. * }
  96610. * </code></div>
  96611. *
  96612. * @alt
  96613. * An example showing the use of camera object properties
  96614. *
  96615. */
  96616. ////////////////////////////////////////////////////////////////////////////////
  96617. // Camera Projection Methods
  96618. ////////////////////////////////////////////////////////////////////////////////
  96619. /**
  96620. * Sets a perspective projection.
  96621. * Accepts the same parameters as the global
  96622. * <a href="#/p5/perspective">perspective()</a>.
  96623. * More information on this function can be found there.
  96624. * @method perspective
  96625. * @for p5.Camera
  96626. * @example
  96627. * <div>
  96628. * <code>
  96629. * // drag the mouse to look around!
  96630. *
  96631. * let cam;
  96632. *
  96633. * function setup() {
  96634. * createCanvas(100, 100, WEBGL);
  96635. * // create a camera
  96636. * cam = createCamera();
  96637. * // give it a perspective projection
  96638. * cam.perspective(PI / 3.0, width / height, 0.1, 500);
  96639. * }
  96640. *
  96641. * function draw() {
  96642. * background(200);
  96643. * orbitControl();
  96644. * normalMaterial();
  96645. *
  96646. * rotateX(-0.3);
  96647. * rotateY(-0.2);
  96648. * translate(0, 0, -50);
  96649. *
  96650. * push();
  96651. * translate(-15, 0, sin(frameCount / 30) * 95);
  96652. * box(30);
  96653. * pop();
  96654. * push();
  96655. * translate(15, 0, sin(frameCount / 30 + PI) * 95);
  96656. * box(30);
  96657. * pop();
  96658. * }
  96659. * </code>
  96660. * </div>
  96661. * @alt
  96662. * two colored 3D boxes move back and forth, rotating as mouse is dragged.
  96663. */
  96664. _main.default.Camera.prototype.perspective = function(fovy, aspect, near, far) {
  96665. this.cameraType = arguments.length > 0 ? 'custom' : 'default';
  96666. if (typeof fovy === 'undefined') {
  96667. fovy = this.defaultCameraFOV;
  96668. // this avoids issue where setting angleMode(DEGREES) before calling
  96669. // perspective leads to a smaller than expected FOV (because
  96670. // _computeCameraDefaultSettings computes in radians)
  96671. this.cameraFOV = fovy;
  96672. } else {
  96673. this.cameraFOV = this._renderer._pInst._toRadians(fovy);
  96674. }
  96675. if (typeof aspect === 'undefined') {
  96676. aspect = this.defaultAspectRatio;
  96677. }
  96678. if (typeof near === 'undefined') {
  96679. near = this.defaultCameraNear;
  96680. }
  96681. if (typeof far === 'undefined') {
  96682. far = this.defaultCameraFar;
  96683. }
  96684. if (near <= 0.0001) {
  96685. near = 0.01;
  96686. console.log(
  96687. 'Avoid perspective near plane values close to or below 0. ' +
  96688. 'Setting value to 0.01.'
  96689. );
  96690. }
  96691. if (far < near) {
  96692. console.log(
  96693. 'Perspective far plane value is less than near plane value. ' +
  96694. 'Nothing will be shown.'
  96695. );
  96696. }
  96697. this.aspectRatio = aspect;
  96698. this.cameraNear = near;
  96699. this.cameraFar = far;
  96700. this.projMatrix = _main.default.Matrix.identity();
  96701. var f = 1.0 / Math.tan(this.cameraFOV / 2);
  96702. var nf = 1.0 / (this.cameraNear - this.cameraFar);
  96703. // prettier-ignore
  96704. this.projMatrix.set(f / aspect, 0, 0, 0,
  96705. 0, -f, 0, 0,
  96706. 0, 0, (far + near) * nf, -1,
  96707. 0, 0, 2 * far * near * nf, 0);
  96708. if (this._isActive()) {
  96709. this._renderer.uPMatrix.set(
  96710. this.projMatrix.mat4[0],
  96711. this.projMatrix.mat4[1],
  96712. this.projMatrix.mat4[2],
  96713. this.projMatrix.mat4[3],
  96714. this.projMatrix.mat4[4],
  96715. this.projMatrix.mat4[5],
  96716. this.projMatrix.mat4[6],
  96717. this.projMatrix.mat4[7],
  96718. this.projMatrix.mat4[8],
  96719. this.projMatrix.mat4[9],
  96720. this.projMatrix.mat4[10],
  96721. this.projMatrix.mat4[11],
  96722. this.projMatrix.mat4[12],
  96723. this.projMatrix.mat4[13],
  96724. this.projMatrix.mat4[14],
  96725. this.projMatrix.mat4[15]
  96726. );
  96727. }
  96728. };
  96729. /**
  96730. * Sets an orthographic projection.
  96731. * Accepts the same parameters as the global
  96732. * <a href="#/p5/ortho">ortho()</a>.
  96733. * More information on this function can be found there.
  96734. * @method ortho
  96735. * @for p5.Camera
  96736. * @example
  96737. * <div>
  96738. * <code>
  96739. * // drag the mouse to look around!
  96740. * // there's no vanishing point
  96741. *
  96742. * let cam;
  96743. *
  96744. * function setup() {
  96745. * createCanvas(100, 100, WEBGL);
  96746. * // create a camera
  96747. * cam = createCamera();
  96748. * // give it an orthographic projection
  96749. * cam.ortho(-width / 2, width / 2, height / 2, -height / 2, 0, 500);
  96750. * }
  96751. * function draw() {
  96752. * background(200);
  96753. * orbitControl();
  96754. * normalMaterial();
  96755. *
  96756. * rotateX(0.2);
  96757. * rotateY(-0.2);
  96758. * push();
  96759. * translate(-15, 0, sin(frameCount / 30) * 65);
  96760. * box(30);
  96761. * pop();
  96762. * push();
  96763. * translate(15, 0, sin(frameCount / 30 + PI) * 65);
  96764. * box(30);
  96765. * pop();
  96766. * }
  96767. * </code>
  96768. * </div>
  96769. * @alt
  96770. * two 3D boxes move back and forth along same plane, rotating as mouse is dragged.
  96771. */
  96772. _main.default.Camera.prototype.ortho = function(
  96773. left,
  96774. right,
  96775. bottom,
  96776. top,
  96777. near,
  96778. far
  96779. ) {
  96780. if (left === undefined) left = -this._renderer.width / 2;
  96781. if (right === undefined) right = +this._renderer.width / 2;
  96782. if (bottom === undefined) bottom = -this._renderer.height / 2;
  96783. if (top === undefined) top = +this._renderer.height / 2;
  96784. if (near === undefined) near = 0;
  96785. if (far === undefined)
  96786. far = Math.max(this._renderer.width, this._renderer.height);
  96787. var w = right - left;
  96788. var h = top - bottom;
  96789. var d = far - near;
  96790. var x = +2.0 / w;
  96791. var y = +2.0 / h;
  96792. var z = -2.0 / d;
  96793. var tx = -(right + left) / w;
  96794. var ty = -(top + bottom) / h;
  96795. var tz = -(far + near) / d;
  96796. this.projMatrix = _main.default.Matrix.identity();
  96797. // prettier-ignore
  96798. this.projMatrix.set(x, 0, 0, 0,
  96799. 0, -y, 0, 0,
  96800. 0, 0, z, 0,
  96801. tx, ty, tz, 1);
  96802. if (this._isActive()) {
  96803. this._renderer.uPMatrix.set(
  96804. this.projMatrix.mat4[0],
  96805. this.projMatrix.mat4[1],
  96806. this.projMatrix.mat4[2],
  96807. this.projMatrix.mat4[3],
  96808. this.projMatrix.mat4[4],
  96809. this.projMatrix.mat4[5],
  96810. this.projMatrix.mat4[6],
  96811. this.projMatrix.mat4[7],
  96812. this.projMatrix.mat4[8],
  96813. this.projMatrix.mat4[9],
  96814. this.projMatrix.mat4[10],
  96815. this.projMatrix.mat4[11],
  96816. this.projMatrix.mat4[12],
  96817. this.projMatrix.mat4[13],
  96818. this.projMatrix.mat4[14],
  96819. this.projMatrix.mat4[15]
  96820. );
  96821. }
  96822. this.cameraType = 'custom';
  96823. };
  96824. /**
  96825. * Sets the camera's frustum.
  96826. * Accepts the same parameters as the global
  96827. * <a href="#/p5/frustum">frustum()</a>.
  96828. * More information on this function can be found there.
  96829. * @method frustum
  96830. * @for p5.Camera
  96831. * @example
  96832. * <div>
  96833. * <code>
  96834. * let cam;
  96835. *
  96836. * function setup() {
  96837. * x = createCanvas(100, 100, WEBGL);
  96838. * setAttributes('antialias', true);
  96839. * // create a camera
  96840. * cam = createCamera();
  96841. * // set its frustum
  96842. * cam.frustum(-0.1, 0.1, -0.1, 0.1, 0.1, 200);
  96843. * }
  96844. *
  96845. * function draw() {
  96846. * background(200);
  96847. * orbitControl();
  96848. * normalMaterial();
  96849. *
  96850. * rotateY(-0.2);
  96851. * rotateX(-0.3);
  96852. * push();
  96853. * translate(-15, 0, sin(frameCount / 30) * 25);
  96854. * box(30);
  96855. * pop();
  96856. * push();
  96857. * translate(15, 0, sin(frameCount / 30 + PI) * 25);
  96858. * box(30);
  96859. * pop();
  96860. * }
  96861. * </code>
  96862. * </div>
  96863. * @alt
  96864. * two 3D boxes move back and forth along same plane, rotating as mouse is dragged.
  96865. */
  96866. _main.default.Camera.prototype.frustum = function(
  96867. left,
  96868. right,
  96869. bottom,
  96870. top,
  96871. near,
  96872. far
  96873. ) {
  96874. if (left === undefined) left = -this._renderer.width / 2;
  96875. if (right === undefined) right = +this._renderer.width / 2;
  96876. if (bottom === undefined) bottom = -this._renderer.height / 2;
  96877. if (top === undefined) top = +this._renderer.height / 2;
  96878. if (near === undefined) near = 0;
  96879. if (far === undefined)
  96880. far = Math.max(this._renderer.width, this._renderer.height);
  96881. var w = right - left;
  96882. var h = top - bottom;
  96883. var d = far - near;
  96884. var x = +(2.0 * near) / w;
  96885. var y = +(2.0 * near) / h;
  96886. var z = -(2.0 * far * near) / d;
  96887. var tx = (right + left) / w;
  96888. var ty = (top + bottom) / h;
  96889. var tz = -(far + near) / d;
  96890. this.projMatrix = _main.default.Matrix.identity();
  96891. // prettier-ignore
  96892. this.projMatrix.set(x, 0, 0, 0,
  96893. 0, y, 0, 0,
  96894. tx, ty, tz, -1,
  96895. 0, 0, z, 0);
  96896. if (this._isActive()) {
  96897. this._renderer.uPMatrix.set(
  96898. this.projMatrix.mat4[0],
  96899. this.projMatrix.mat4[1],
  96900. this.projMatrix.mat4[2],
  96901. this.projMatrix.mat4[3],
  96902. this.projMatrix.mat4[4],
  96903. this.projMatrix.mat4[5],
  96904. this.projMatrix.mat4[6],
  96905. this.projMatrix.mat4[7],
  96906. this.projMatrix.mat4[8],
  96907. this.projMatrix.mat4[9],
  96908. this.projMatrix.mat4[10],
  96909. this.projMatrix.mat4[11],
  96910. this.projMatrix.mat4[12],
  96911. this.projMatrix.mat4[13],
  96912. this.projMatrix.mat4[14],
  96913. this.projMatrix.mat4[15]
  96914. );
  96915. }
  96916. this.cameraType = 'custom';
  96917. };
  96918. ////////////////////////////////////////////////////////////////////////////////
  96919. // Camera Orientation Methods
  96920. ////////////////////////////////////////////////////////////////////////////////
  96921. /**
  96922. * Rotate camera view about arbitrary axis defined by x,y,z
  96923. * based on http://learnwebgl.brown37.net/07_cameras/camera_rotating_motion.html
  96924. * @method _rotateView
  96925. * @private
  96926. */
  96927. _main.default.Camera.prototype._rotateView = function(a, x, y, z) {
  96928. var centerX = this.centerX;
  96929. var centerY = this.centerY;
  96930. var centerZ = this.centerZ;
  96931. // move center by eye position such that rotation happens around eye position
  96932. centerX -= this.eyeX;
  96933. centerY -= this.eyeY;
  96934. centerZ -= this.eyeZ;
  96935. var rotation = _main.default.Matrix.identity(this._renderer._pInst);
  96936. rotation.rotate(this._renderer._pInst._toRadians(a), x, y, z);
  96937. // prettier-ignore
  96938. var rotatedCenter = [
  96939. centerX * rotation.mat4[0] + centerY * rotation.mat4[4] + centerZ * rotation.mat4[8],
  96940. centerX * rotation.mat4[1] + centerY * rotation.mat4[5] + centerZ * rotation.mat4[9],
  96941. centerX * rotation.mat4[2] + centerY * rotation.mat4[6] + centerZ * rotation.mat4[10]];
  96942. // add eye position back into center
  96943. rotatedCenter[0] += this.eyeX;
  96944. rotatedCenter[1] += this.eyeY;
  96945. rotatedCenter[2] += this.eyeZ;
  96946. this.camera(
  96947. this.eyeX,
  96948. this.eyeY,
  96949. this.eyeZ,
  96950. rotatedCenter[0],
  96951. rotatedCenter[1],
  96952. rotatedCenter[2],
  96953. this.upX,
  96954. this.upY,
  96955. this.upZ
  96956. );
  96957. };
  96958. /**
  96959. * Panning rotates the camera view to the left and right.
  96960. * @method pan
  96961. * @param {Number} angle amount to rotate camera in current
  96962. * <a href="#/p5/angleMode">angleMode</a> units.
  96963. * Greater than 0 values rotate counterclockwise (to the left).
  96964. * @example
  96965. * <div>
  96966. * <code>
  96967. * let cam;
  96968. * let delta = 0.01;
  96969. *
  96970. * function setup() {
  96971. * createCanvas(100, 100, WEBGL);
  96972. * normalMaterial();
  96973. * cam = createCamera();
  96974. * // set initial pan angle
  96975. * cam.pan(-0.8);
  96976. * }
  96977. *
  96978. * function draw() {
  96979. * background(200);
  96980. *
  96981. * // pan camera according to angle 'delta'
  96982. * cam.pan(delta);
  96983. *
  96984. * // every 160 frames, switch direction
  96985. * if (frameCount % 160 === 0) {
  96986. * delta *= -1;
  96987. * }
  96988. *
  96989. * rotateX(frameCount * 0.01);
  96990. * translate(-100, 0, 0);
  96991. * box(20);
  96992. * translate(35, 0, 0);
  96993. * box(20);
  96994. * translate(35, 0, 0);
  96995. * box(20);
  96996. * translate(35, 0, 0);
  96997. * box(20);
  96998. * translate(35, 0, 0);
  96999. * box(20);
  97000. * translate(35, 0, 0);
  97001. * box(20);
  97002. * translate(35, 0, 0);
  97003. * box(20);
  97004. * }
  97005. * </code>
  97006. * </div>
  97007. *
  97008. * @alt
  97009. * camera view pans left and right across a series of rotating 3D boxes.
  97010. */
  97011. _main.default.Camera.prototype.pan = function(amount) {
  97012. var local = this._getLocalAxes();
  97013. this._rotateView(amount, local.y[0], local.y[1], local.y[2]);
  97014. };
  97015. /**
  97016. * Tilting rotates the camera view up and down.
  97017. * @method tilt
  97018. * @param {Number} angle amount to rotate camera in current
  97019. * <a href="#/p5/angleMode">angleMode</a> units.
  97020. * Greater than 0 values rotate counterclockwise (to the left).
  97021. * @example
  97022. * <div>
  97023. * <code>
  97024. * let cam;
  97025. * let delta = 0.01;
  97026. *
  97027. * function setup() {
  97028. * createCanvas(100, 100, WEBGL);
  97029. * normalMaterial();
  97030. * cam = createCamera();
  97031. * // set initial tilt
  97032. * cam.tilt(-0.8);
  97033. * }
  97034. *
  97035. * function draw() {
  97036. * background(200);
  97037. *
  97038. * // pan camera according to angle 'delta'
  97039. * cam.tilt(delta);
  97040. *
  97041. * // every 160 frames, switch direction
  97042. * if (frameCount % 160 === 0) {
  97043. * delta *= -1;
  97044. * }
  97045. *
  97046. * rotateY(frameCount * 0.01);
  97047. * translate(0, -100, 0);
  97048. * box(20);
  97049. * translate(0, 35, 0);
  97050. * box(20);
  97051. * translate(0, 35, 0);
  97052. * box(20);
  97053. * translate(0, 35, 0);
  97054. * box(20);
  97055. * translate(0, 35, 0);
  97056. * box(20);
  97057. * translate(0, 35, 0);
  97058. * box(20);
  97059. * translate(0, 35, 0);
  97060. * box(20);
  97061. * }
  97062. * </code>
  97063. * </div>
  97064. *
  97065. * @alt
  97066. * camera view tilts up and down across a series of rotating 3D boxes.
  97067. */
  97068. _main.default.Camera.prototype.tilt = function(amount) {
  97069. var local = this._getLocalAxes();
  97070. this._rotateView(amount, local.x[0], local.x[1], local.x[2]);
  97071. };
  97072. /**
  97073. * Reorients the camera to look at a position in world space.
  97074. * @method lookAt
  97075. * @for p5.Camera
  97076. * @param {Number} x x position of a point in world space
  97077. * @param {Number} y y position of a point in world space
  97078. * @param {Number} z z position of a point in world space
  97079. * @example
  97080. * <div>
  97081. * <code>
  97082. * let cam;
  97083. *
  97084. * function setup() {
  97085. * createCanvas(100, 100, WEBGL);
  97086. * normalMaterial();
  97087. * cam = createCamera();
  97088. * }
  97089. *
  97090. * function draw() {
  97091. * background(200);
  97092. *
  97093. * // look at a new random point every 60 frames
  97094. * if (frameCount % 60 === 0) {
  97095. * cam.lookAt(random(-100, 100), random(-50, 50), 0);
  97096. * }
  97097. *
  97098. * rotateX(frameCount * 0.01);
  97099. * translate(-100, 0, 0);
  97100. * box(20);
  97101. * translate(35, 0, 0);
  97102. * box(20);
  97103. * translate(35, 0, 0);
  97104. * box(20);
  97105. * translate(35, 0, 0);
  97106. * box(20);
  97107. * translate(35, 0, 0);
  97108. * box(20);
  97109. * translate(35, 0, 0);
  97110. * box(20);
  97111. * translate(35, 0, 0);
  97112. * box(20);
  97113. * }
  97114. * </code>
  97115. * </div>
  97116. *
  97117. * @alt
  97118. * camera view of rotating 3D cubes changes to look at a new random
  97119. * point every second .
  97120. */
  97121. _main.default.Camera.prototype.lookAt = function(x, y, z) {
  97122. this.camera(
  97123. this.eyeX,
  97124. this.eyeY,
  97125. this.eyeZ,
  97126. x,
  97127. y,
  97128. z,
  97129. this.upX,
  97130. this.upY,
  97131. this.upZ
  97132. );
  97133. };
  97134. ////////////////////////////////////////////////////////////////////////////////
  97135. // Camera Position Methods
  97136. ////////////////////////////////////////////////////////////////////////////////
  97137. /**
  97138. * Sets the camera's position and orientation.
  97139. * Accepts the same parameters as the global
  97140. * <a href="#/p5/camera">camera()</a>.
  97141. * More information on this function can be found there.
  97142. * @method camera
  97143. * @for p5.Camera
  97144. * @example
  97145. * <div>
  97146. * <code>
  97147. * let cam;
  97148. *
  97149. * function setup() {
  97150. * createCanvas(100, 100, WEBGL);
  97151. * // Create a camera.
  97152. * // createCamera() sets the newly created camera as
  97153. * // the current (active) camera.
  97154. * cam = createCamera();
  97155. * }
  97156. *
  97157. * function draw() {
  97158. * background(204);
  97159. * // Move the camera away from the plane by a sin wave
  97160. * cam.camera(0, 0, 20 + sin(frameCount * 0.01) * 10, 0, 0, 0, 0, 1, 0);
  97161. * plane(10, 10);
  97162. * }
  97163. * </code>
  97164. * </div>
  97165. * @alt
  97166. * White square repeatedly grows to fill canvas and then shrinks.
  97167. *
  97168. * @example
  97169. * <div>
  97170. * <code>
  97171. * // move slider to see changes!
  97172. * // sliders control the first 6 parameters of camera()
  97173. *
  97174. * let sliderGroup = [];
  97175. * let X;
  97176. * let Y;
  97177. * let Z;
  97178. * let centerX;
  97179. * let centerY;
  97180. * let centerZ;
  97181. * let h = 20;
  97182. * let cam;
  97183. *
  97184. * function setup() {
  97185. * createCanvas(100, 100, WEBGL);
  97186. * // create a camera
  97187. * cam = createCamera();
  97188. * // create sliders
  97189. * for (var i = 0; i < 6; i++) {
  97190. * if (i === 2) {
  97191. * sliderGroup[i] = createSlider(10, 400, 200);
  97192. * } else {
  97193. * sliderGroup[i] = createSlider(-400, 400, 0);
  97194. * }
  97195. * h = map(i, 0, 6, 5, 85);
  97196. * sliderGroup[i].position(10, height + h);
  97197. * sliderGroup[i].style('width', '80px');
  97198. * }
  97199. * }
  97200. *
  97201. * function draw() {
  97202. * background(60);
  97203. * // assigning sliders' value to each parameters
  97204. * X = sliderGroup[0].value();
  97205. * Y = sliderGroup[1].value();
  97206. * Z = sliderGroup[2].value();
  97207. * centerX = sliderGroup[3].value();
  97208. * centerY = sliderGroup[4].value();
  97209. * centerZ = sliderGroup[5].value();
  97210. * cam.camera(X, Y, Z, centerX, centerY, centerZ, 0, 1, 0);
  97211. * stroke(255);
  97212. * fill(255, 102, 94);
  97213. * box(85);
  97214. * }
  97215. * </code>
  97216. * </div>
  97217. * @alt
  97218. * An interactive example of a red cube with 3 sliders for moving it across x, y,
  97219. * z axis and 3 sliders for shifting it's center.
  97220. */
  97221. _main.default.Camera.prototype.camera = function(
  97222. eyeX,
  97223. eyeY,
  97224. eyeZ,
  97225. centerX,
  97226. centerY,
  97227. centerZ,
  97228. upX,
  97229. upY,
  97230. upZ
  97231. ) {
  97232. if (typeof eyeX === 'undefined') {
  97233. eyeX = this.defaultEyeX;
  97234. eyeY = this.defaultEyeY;
  97235. eyeZ = this.defaultEyeZ;
  97236. centerX = eyeX;
  97237. centerY = eyeY;
  97238. centerZ = 0;
  97239. upX = 0;
  97240. upY = 1;
  97241. upZ = 0;
  97242. }
  97243. this.eyeX = eyeX;
  97244. this.eyeY = eyeY;
  97245. this.eyeZ = eyeZ;
  97246. if (typeof centerX !== 'undefined') {
  97247. this.centerX = centerX;
  97248. this.centerY = centerY;
  97249. this.centerZ = centerZ;
  97250. }
  97251. if (typeof upX !== 'undefined') {
  97252. this.upX = upX;
  97253. this.upY = upY;
  97254. this.upZ = upZ;
  97255. }
  97256. var local = this._getLocalAxes();
  97257. // the camera affects the model view matrix, insofar as it
  97258. // inverse translates the world to the eye position of the camera
  97259. // and rotates it.
  97260. // prettier-ignore
  97261. this.cameraMatrix.set(local.x[0], local.y[0], local.z[0], 0,
  97262. local.x[1], local.y[1], local.z[1], 0,
  97263. local.x[2], local.y[2], local.z[2], 0,
  97264. 0, 0, 0, 1);
  97265. var tx = -eyeX;
  97266. var ty = -eyeY;
  97267. var tz = -eyeZ;
  97268. this.cameraMatrix.translate([tx, ty, tz]);
  97269. if (this._isActive()) {
  97270. this._renderer.uMVMatrix.set(
  97271. this.cameraMatrix.mat4[0],
  97272. this.cameraMatrix.mat4[1],
  97273. this.cameraMatrix.mat4[2],
  97274. this.cameraMatrix.mat4[3],
  97275. this.cameraMatrix.mat4[4],
  97276. this.cameraMatrix.mat4[5],
  97277. this.cameraMatrix.mat4[6],
  97278. this.cameraMatrix.mat4[7],
  97279. this.cameraMatrix.mat4[8],
  97280. this.cameraMatrix.mat4[9],
  97281. this.cameraMatrix.mat4[10],
  97282. this.cameraMatrix.mat4[11],
  97283. this.cameraMatrix.mat4[12],
  97284. this.cameraMatrix.mat4[13],
  97285. this.cameraMatrix.mat4[14],
  97286. this.cameraMatrix.mat4[15]
  97287. );
  97288. }
  97289. return this;
  97290. };
  97291. /**
  97292. * Move camera along its local axes while maintaining current camera orientation.
  97293. * @method move
  97294. * @param {Number} x amount to move along camera's left-right axis
  97295. * @param {Number} y amount to move along camera's up-down axis
  97296. * @param {Number} z amount to move along camera's forward-backward axis
  97297. * @example
  97298. * <div>
  97299. * <code>
  97300. * // see the camera move along its own axes while maintaining its orientation
  97301. * let cam;
  97302. * let delta = 0.5;
  97303. *
  97304. * function setup() {
  97305. * createCanvas(100, 100, WEBGL);
  97306. * normalMaterial();
  97307. * cam = createCamera();
  97308. * }
  97309. *
  97310. * function draw() {
  97311. * background(200);
  97312. *
  97313. * // move the camera along its local axes
  97314. * cam.move(delta, delta, 0);
  97315. *
  97316. * // every 100 frames, switch direction
  97317. * if (frameCount % 150 === 0) {
  97318. * delta *= -1;
  97319. * }
  97320. *
  97321. * translate(-10, -10, 0);
  97322. * box(50, 8, 50);
  97323. * translate(15, 15, 0);
  97324. * box(50, 8, 50);
  97325. * translate(15, 15, 0);
  97326. * box(50, 8, 50);
  97327. * translate(15, 15, 0);
  97328. * box(50, 8, 50);
  97329. * translate(15, 15, 0);
  97330. * box(50, 8, 50);
  97331. * translate(15, 15, 0);
  97332. * box(50, 8, 50);
  97333. * }
  97334. * </code>
  97335. * </div>
  97336. *
  97337. * @alt
  97338. * camera view moves along a series of 3D boxes, maintaining the same
  97339. * orientation throughout the move
  97340. */
  97341. _main.default.Camera.prototype.move = function(x, y, z) {
  97342. var local = this._getLocalAxes();
  97343. // scale local axes by movement amounts
  97344. // based on http://learnwebgl.brown37.net/07_cameras/camera_linear_motion.html
  97345. var dx = [local.x[0] * x, local.x[1] * x, local.x[2] * x];
  97346. var dy = [local.y[0] * y, local.y[1] * y, local.y[2] * y];
  97347. var dz = [local.z[0] * z, local.z[1] * z, local.z[2] * z];
  97348. this.camera(
  97349. this.eyeX + dx[0] + dy[0] + dz[0],
  97350. this.eyeY + dx[1] + dy[1] + dz[1],
  97351. this.eyeZ + dx[2] + dy[2] + dz[2],
  97352. this.centerX + dx[0] + dy[0] + dz[0],
  97353. this.centerY + dx[1] + dy[1] + dz[1],
  97354. this.centerZ + dx[2] + dy[2] + dz[2],
  97355. 0,
  97356. 1,
  97357. 0
  97358. );
  97359. };
  97360. /**
  97361. * Set camera position in world-space while maintaining current camera
  97362. * orientation.
  97363. * @method setPosition
  97364. * @param {Number} x x position of a point in world space
  97365. * @param {Number} y y position of a point in world space
  97366. * @param {Number} z z position of a point in world space
  97367. * @example
  97368. * <div>
  97369. * <code>
  97370. * // press '1' '2' or '3' keys to set camera position
  97371. *
  97372. * let cam;
  97373. *
  97374. * function setup() {
  97375. * createCanvas(100, 100, WEBGL);
  97376. * normalMaterial();
  97377. * cam = createCamera();
  97378. * }
  97379. *
  97380. * function draw() {
  97381. * background(200);
  97382. *
  97383. * // '1' key
  97384. * if (keyIsDown(49)) {
  97385. * cam.setPosition(30, 0, 80);
  97386. * }
  97387. * // '2' key
  97388. * if (keyIsDown(50)) {
  97389. * cam.setPosition(0, 0, 80);
  97390. * }
  97391. * // '3' key
  97392. * if (keyIsDown(51)) {
  97393. * cam.setPosition(-30, 0, 80);
  97394. * }
  97395. *
  97396. * box(20);
  97397. * }
  97398. * </code>
  97399. * </div>
  97400. *
  97401. * @alt
  97402. * camera position changes as the user presses keys, altering view of a 3D box
  97403. */
  97404. _main.default.Camera.prototype.setPosition = function(x, y, z) {
  97405. var diffX = x - this.eyeX;
  97406. var diffY = y - this.eyeY;
  97407. var diffZ = z - this.eyeZ;
  97408. this.camera(
  97409. x,
  97410. y,
  97411. z,
  97412. this.centerX + diffX,
  97413. this.centerY + diffY,
  97414. this.centerZ + diffZ,
  97415. 0,
  97416. 1,
  97417. 0
  97418. );
  97419. };
  97420. ////////////////////////////////////////////////////////////////////////////////
  97421. // Camera Helper Methods
  97422. ////////////////////////////////////////////////////////////////////////////////
  97423. // @TODO: combine this function with _setDefaultCamera to compute these values
  97424. // as-needed
  97425. _main.default.Camera.prototype._computeCameraDefaultSettings = function() {
  97426. this.defaultCameraFOV = 60 / 180 * Math.PI;
  97427. this.defaultAspectRatio = this._renderer.width / this._renderer.height;
  97428. this.defaultEyeX = 0;
  97429. this.defaultEyeY = 0;
  97430. this.defaultEyeZ =
  97431. this._renderer.height / 2.0 / Math.tan(this.defaultCameraFOV / 2.0);
  97432. this.defaultCenterX = 0;
  97433. this.defaultCenterY = 0;
  97434. this.defaultCenterZ = 0;
  97435. this.defaultCameraNear = this.defaultEyeZ * 0.1;
  97436. this.defaultCameraFar = this.defaultEyeZ * 10;
  97437. };
  97438. //detect if user didn't set the camera
  97439. //then call this function below
  97440. _main.default.Camera.prototype._setDefaultCamera = function() {
  97441. this.cameraFOV = this.defaultCameraFOV;
  97442. this.aspectRatio = this.defaultAspectRatio;
  97443. this.eyeX = this.defaultEyeX;
  97444. this.eyeY = this.defaultEyeY;
  97445. this.eyeZ = this.defaultEyeZ;
  97446. this.centerX = this.defaultCenterX;
  97447. this.centerY = this.defaultCenterY;
  97448. this.centerZ = this.defaultCenterZ;
  97449. this.upX = 0;
  97450. this.upY = 1;
  97451. this.upZ = 0;
  97452. this.cameraNear = this.defaultCameraNear;
  97453. this.cameraFar = this.defaultCameraFar;
  97454. this.perspective();
  97455. this.camera();
  97456. this.cameraType = 'default';
  97457. };
  97458. _main.default.Camera.prototype._resize = function() {
  97459. // If we're using the default camera, update the aspect ratio
  97460. if (this.cameraType === 'default') {
  97461. this._computeCameraDefaultSettings();
  97462. this._setDefaultCamera();
  97463. } else {
  97464. this.perspective(
  97465. this.cameraFOV,
  97466. this._renderer.width / this._renderer.height
  97467. );
  97468. }
  97469. };
  97470. /**
  97471. * Returns a copy of a camera.
  97472. * @method copy
  97473. * @private
  97474. */
  97475. _main.default.Camera.prototype.copy = function() {
  97476. var _cam = new _main.default.Camera(this._renderer);
  97477. _cam.cameraFOV = this.cameraFOV;
  97478. _cam.aspectRatio = this.aspectRatio;
  97479. _cam.eyeX = this.eyeX;
  97480. _cam.eyeY = this.eyeY;
  97481. _cam.eyeZ = this.eyeZ;
  97482. _cam.centerX = this.centerX;
  97483. _cam.centerY = this.centerY;
  97484. _cam.centerZ = this.centerZ;
  97485. _cam.cameraNear = this.cameraNear;
  97486. _cam.cameraFar = this.cameraFar;
  97487. _cam.cameraType = this.cameraType;
  97488. _cam.cameraMatrix = this.cameraMatrix.copy();
  97489. _cam.projMatrix = this.projMatrix.copy();
  97490. return _cam;
  97491. };
  97492. /**
  97493. * Returns a camera's local axes: left-right, up-down, and forward-backward,
  97494. * as defined by vectors in world-space.
  97495. * @method _getLocalAxes
  97496. * @private
  97497. */
  97498. _main.default.Camera.prototype._getLocalAxes = function() {
  97499. // calculate camera local Z vector
  97500. var z0 = this.eyeX - this.centerX;
  97501. var z1 = this.eyeY - this.centerY;
  97502. var z2 = this.eyeZ - this.centerZ;
  97503. // normalize camera local Z vector
  97504. var eyeDist = Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
  97505. if (eyeDist !== 0) {
  97506. z0 /= eyeDist;
  97507. z1 /= eyeDist;
  97508. z2 /= eyeDist;
  97509. }
  97510. // calculate camera Y vector
  97511. var y0 = this.upX;
  97512. var y1 = this.upY;
  97513. var y2 = this.upZ;
  97514. // compute camera local X vector as up vector (local Y) cross local Z
  97515. var x0 = y1 * z2 - y2 * z1;
  97516. var x1 = -y0 * z2 + y2 * z0;
  97517. var x2 = y0 * z1 - y1 * z0;
  97518. // recompute y = z cross x
  97519. y0 = z1 * x2 - z2 * x1;
  97520. y1 = -z0 * x2 + z2 * x0;
  97521. y2 = z0 * x1 - z1 * x0;
  97522. // cross product gives area of parallelogram, which is < 1.0 for
  97523. // non-perpendicular unit-length vectors; so normalize x, y here:
  97524. var xmag = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
  97525. if (xmag !== 0) {
  97526. x0 /= xmag;
  97527. x1 /= xmag;
  97528. x2 /= xmag;
  97529. }
  97530. var ymag = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
  97531. if (ymag !== 0) {
  97532. y0 /= ymag;
  97533. y1 /= ymag;
  97534. y2 /= ymag;
  97535. }
  97536. return {
  97537. x: [x0, x1, x2],
  97538. y: [y0, y1, y2],
  97539. z: [z0, z1, z2]
  97540. };
  97541. };
  97542. /**
  97543. * Orbits the camera about center point. For use with orbitControl().
  97544. * @method _orbit
  97545. * @private
  97546. * @param {Number} dTheta change in spherical coordinate theta
  97547. * @param {Number} dPhi change in spherical coordinate phi
  97548. * @param {Number} dRadius change in radius
  97549. */
  97550. _main.default.Camera.prototype._orbit = function(dTheta, dPhi, dRadius) {
  97551. var diffX = this.eyeX - this.centerX;
  97552. var diffY = this.eyeY - this.centerY;
  97553. var diffZ = this.eyeZ - this.centerZ;
  97554. // get spherical coorinates for current camera position about origin
  97555. var camRadius = Math.sqrt(diffX * diffX + diffY * diffY + diffZ * diffZ);
  97556. // from https://github.com/mrdoob/three.js/blob/dev/src/math/Spherical.js#L72-L73
  97557. var camTheta = Math.atan2(diffX, diffZ); // equatorial angle
  97558. var camPhi = Math.acos(Math.max(-1, Math.min(1, diffY / camRadius))); // polar angle
  97559. // add change
  97560. camTheta += dTheta;
  97561. camPhi += dPhi;
  97562. camRadius += dRadius;
  97563. // prevent zooming through the center:
  97564. if (camRadius < 0) {
  97565. camRadius = 0.1;
  97566. }
  97567. // prevent rotation over the zenith / under bottom
  97568. if (camPhi > Math.PI) {
  97569. camPhi = Math.PI;
  97570. } else if (camPhi <= 0) {
  97571. camPhi = 0.001;
  97572. }
  97573. // from https://github.com/mrdoob/three.js/blob/dev/src/math/Vector3.js#L628-L632
  97574. var _x = Math.sin(camPhi) * camRadius * Math.sin(camTheta);
  97575. var _y = Math.cos(camPhi) * camRadius;
  97576. var _z = Math.sin(camPhi) * camRadius * Math.cos(camTheta);
  97577. this.camera(
  97578. _x + this.centerX,
  97579. _y + this.centerY,
  97580. _z + this.centerZ,
  97581. this.centerX,
  97582. this.centerY,
  97583. this.centerZ,
  97584. 0,
  97585. 1,
  97586. 0
  97587. );
  97588. };
  97589. /**
  97590. * Returns true if camera is currently attached to renderer.
  97591. * @method _isActive
  97592. * @private
  97593. */
  97594. _main.default.Camera.prototype._isActive = function() {
  97595. return this === this._renderer._curCamera;
  97596. };
  97597. /**
  97598. * Sets the current (active) camera of a 3D sketch.
  97599. * Allows for switching between multiple cameras.
  97600. * @method setCamera
  97601. * @param {p5.Camera} cam p5.Camera object
  97602. * @for p5
  97603. * @example
  97604. * <div>
  97605. * <code>
  97606. * let cam1, cam2;
  97607. * let currentCamera;
  97608. *
  97609. * function setup() {
  97610. * createCanvas(100, 100, WEBGL);
  97611. * normalMaterial();
  97612. *
  97613. * cam1 = createCamera();
  97614. * cam2 = createCamera();
  97615. * cam2.setPosition(30, 0, 50);
  97616. * cam2.lookAt(0, 0, 0);
  97617. * cam2.ortho();
  97618. *
  97619. * // set variable for previously active camera:
  97620. * currentCamera = 1;
  97621. * }
  97622. *
  97623. * function draw() {
  97624. * background(200);
  97625. *
  97626. * // camera 1:
  97627. * cam1.lookAt(0, 0, 0);
  97628. * cam1.setPosition(sin(frameCount / 60) * 200, 0, 100);
  97629. *
  97630. * // every 100 frames, switch between the two cameras
  97631. * if (frameCount % 100 === 0) {
  97632. * if (currentCamera === 1) {
  97633. * setCamera(cam1);
  97634. * currentCamera = 0;
  97635. * } else {
  97636. * setCamera(cam2);
  97637. * currentCamera = 1;
  97638. * }
  97639. * }
  97640. *
  97641. * drawBoxes();
  97642. * }
  97643. *
  97644. * function drawBoxes() {
  97645. * rotateX(frameCount * 0.01);
  97646. * translate(-100, 0, 0);
  97647. * box(20);
  97648. * translate(35, 0, 0);
  97649. * box(20);
  97650. * translate(35, 0, 0);
  97651. * box(20);
  97652. * translate(35, 0, 0);
  97653. * box(20);
  97654. * translate(35, 0, 0);
  97655. * box(20);
  97656. * translate(35, 0, 0);
  97657. * box(20);
  97658. * translate(35, 0, 0);
  97659. * box(20);
  97660. * }
  97661. * </code>
  97662. * </div>
  97663. *
  97664. * @alt
  97665. * Canvas switches between two camera views, each showing a series of spinning
  97666. * 3D boxes.
  97667. */
  97668. _main.default.prototype.setCamera = function(cam) {
  97669. this._renderer._curCamera = cam;
  97670. // set the projection matrix (which is not normally updated each frame)
  97671. this._renderer.uPMatrix.set(
  97672. cam.projMatrix.mat4[0],
  97673. cam.projMatrix.mat4[1],
  97674. cam.projMatrix.mat4[2],
  97675. cam.projMatrix.mat4[3],
  97676. cam.projMatrix.mat4[4],
  97677. cam.projMatrix.mat4[5],
  97678. cam.projMatrix.mat4[6],
  97679. cam.projMatrix.mat4[7],
  97680. cam.projMatrix.mat4[8],
  97681. cam.projMatrix.mat4[9],
  97682. cam.projMatrix.mat4[10],
  97683. cam.projMatrix.mat4[11],
  97684. cam.projMatrix.mat4[12],
  97685. cam.projMatrix.mat4[13],
  97686. cam.projMatrix.mat4[14],
  97687. cam.projMatrix.mat4[15]
  97688. );
  97689. };
  97690. var _default = _main.default.Camera;
  97691. exports.default = _default;
  97692. },
  97693. { '../core/main': 283 }
  97694. ],
  97695. 332: [
  97696. function(_dereq_, module, exports) {
  97697. 'use strict';
  97698. _dereq_('core-js/modules/es.string.sub');
  97699. Object.defineProperty(exports, '__esModule', { value: true });
  97700. exports.default = void 0;
  97701. var _main = _interopRequireDefault(_dereq_('../core/main'));
  97702. function _interopRequireDefault(obj) {
  97703. return obj && obj.__esModule ? obj : { default: obj };
  97704. } /** //some of the functions are adjusted from Three.js(http://threejs.org)
  97705. * @module Shape
  97706. * @submodule 3D Primitives
  97707. * @for p5
  97708. * @requires core
  97709. * @requires p5.Geometry
  97710. */
  97711. /**
  97712. * p5 Geometry class
  97713. * @class p5.Geometry
  97714. * @constructor
  97715. * @param {Integer} [detailX] number of vertices on horizontal surface
  97716. * @param {Integer} [detailY] number of vertices on horizontal surface
  97717. * @param {function} [callback] function to call upon object instantiation.
  97718. */ _main.default.Geometry = function(detailX, detailY, callback) {
  97719. //an array containing every vertex
  97720. //@type [p5.Vector]
  97721. this.vertices = []; //an array containing every vertex for stroke drawing
  97722. this.lineVertices = []; //an array 1 normal per lineVertex with
  97723. //final position representing which direction to
  97724. //displace for strokeWeight
  97725. //[[0,0,-1,1], [0,1,0,-1] ...];
  97726. this.lineNormals = [];
  97727. //an array containing 1 normal per vertex
  97728. //@type [p5.Vector]
  97729. //[p5.Vector, p5.Vector, p5.Vector,p5.Vector, p5.Vector, p5.Vector,...]
  97730. this.vertexNormals = [];
  97731. //an array containing each three vertex indices that form a face
  97732. //[[0, 1, 2], [2, 1, 3], ...]
  97733. this.faces = [];
  97734. //a 2D array containing uvs for every vertex
  97735. //[[0.0,0.0],[1.0,0.0], ...]
  97736. this.uvs = [];
  97737. // a 2D array containing edge connectivity pattern for create line vertices
  97738. //based on faces for most objects;
  97739. this.edges = [];
  97740. this.vertexColors = [];
  97741. this.detailX = detailX !== undefined ? detailX : 1;
  97742. this.detailY = detailY !== undefined ? detailY : 1;
  97743. this.dirtyFlags = {};
  97744. if (callback instanceof Function) {
  97745. callback.call(this);
  97746. }
  97747. return this; // TODO: is this a constructor?
  97748. };
  97749. _main.default.Geometry.prototype.reset = function() {
  97750. this.lineVertices.length = 0;
  97751. this.lineNormals.length = 0;
  97752. this.vertices.length = 0;
  97753. this.edges.length = 0;
  97754. this.vertexColors.length = 0;
  97755. this.vertexNormals.length = 0;
  97756. this.uvs.length = 0;
  97757. this.dirtyFlags = {};
  97758. };
  97759. /**
  97760. * computes faces for geometry objects based on the vertices.
  97761. * @method computeFaces
  97762. * @chainable
  97763. */
  97764. _main.default.Geometry.prototype.computeFaces = function() {
  97765. this.faces.length = 0;
  97766. var sliceCount = this.detailX + 1;
  97767. var a, b, c, d;
  97768. for (var i = 0; i < this.detailY; i++) {
  97769. for (var j = 0; j < this.detailX; j++) {
  97770. a = i * sliceCount + j; // + offset;
  97771. b = i * sliceCount + j + 1; // + offset;
  97772. c = (i + 1) * sliceCount + j + 1; // + offset;
  97773. d = (i + 1) * sliceCount + j; // + offset;
  97774. this.faces.push([a, b, d]);
  97775. this.faces.push([d, b, c]);
  97776. }
  97777. }
  97778. return this;
  97779. };
  97780. _main.default.Geometry.prototype._getFaceNormal = function(faceId) {
  97781. //This assumes that vA->vB->vC is a counter-clockwise ordering
  97782. var face = this.faces[faceId];
  97783. var vA = this.vertices[face[0]];
  97784. var vB = this.vertices[face[1]];
  97785. var vC = this.vertices[face[2]];
  97786. var ab = _main.default.Vector.sub(vB, vA);
  97787. var ac = _main.default.Vector.sub(vC, vA);
  97788. var n = _main.default.Vector.cross(ab, ac);
  97789. var ln = _main.default.Vector.mag(n);
  97790. var sinAlpha =
  97791. ln / (_main.default.Vector.mag(ab) * _main.default.Vector.mag(ac));
  97792. if (sinAlpha === 0 || isNaN(sinAlpha)) {
  97793. console.warn(
  97794. 'p5.Geometry.prototype._getFaceNormal:',
  97795. 'face has colinear sides or a repeated vertex'
  97796. );
  97797. return n;
  97798. }
  97799. if (sinAlpha > 1) sinAlpha = 1; // handle float rounding error
  97800. return n.mult(Math.asin(sinAlpha) / ln);
  97801. };
  97802. /**
  97803. * computes smooth normals per vertex as an average of each
  97804. * face.
  97805. * @method computeNormals
  97806. * @chainable
  97807. */
  97808. _main.default.Geometry.prototype.computeNormals = function() {
  97809. var vertexNormals = this.vertexNormals;
  97810. var vertices = this.vertices;
  97811. var faces = this.faces;
  97812. var iv;
  97813. // initialize the vertexNormals array with empty vectors
  97814. vertexNormals.length = 0;
  97815. for (iv = 0; iv < vertices.length; ++iv) {
  97816. vertexNormals.push(new _main.default.Vector());
  97817. }
  97818. // loop through all the faces adding its normal to the normal
  97819. // of each of its vertices
  97820. for (var f = 0; f < faces.length; ++f) {
  97821. var face = faces[f];
  97822. var faceNormal = this._getFaceNormal(f);
  97823. // all three vertices get the normal added
  97824. for (var fv = 0; fv < 3; ++fv) {
  97825. var vertexIndex = face[fv];
  97826. vertexNormals[vertexIndex].add(faceNormal);
  97827. }
  97828. }
  97829. // normalize the normals
  97830. for (iv = 0; iv < vertices.length; ++iv) {
  97831. vertexNormals[iv].normalize();
  97832. }
  97833. return this;
  97834. };
  97835. /**
  97836. * Averages the vertex normals. Used in curved
  97837. * surfaces
  97838. * @method averageNormals
  97839. * @chainable
  97840. */
  97841. _main.default.Geometry.prototype.averageNormals = function() {
  97842. for (var i = 0; i <= this.detailY; i++) {
  97843. var offset = this.detailX + 1;
  97844. var temp = _main.default.Vector.add(
  97845. this.vertexNormals[i * offset],
  97846. this.vertexNormals[i * offset + this.detailX]
  97847. );
  97848. temp = _main.default.Vector.div(temp, 2);
  97849. this.vertexNormals[i * offset] = temp;
  97850. this.vertexNormals[i * offset + this.detailX] = temp;
  97851. }
  97852. return this;
  97853. };
  97854. /**
  97855. * Averages pole normals. Used in spherical primitives
  97856. * @method averagePoleNormals
  97857. * @chainable
  97858. */
  97859. _main.default.Geometry.prototype.averagePoleNormals = function() {
  97860. //average the north pole
  97861. var sum = new _main.default.Vector(0, 0, 0);
  97862. for (var i = 0; i < this.detailX; i++) {
  97863. sum.add(this.vertexNormals[i]);
  97864. }
  97865. sum = _main.default.Vector.div(sum, this.detailX);
  97866. for (var _i = 0; _i < this.detailX; _i++) {
  97867. this.vertexNormals[_i] = sum;
  97868. }
  97869. //average the south pole
  97870. sum = new _main.default.Vector(0, 0, 0);
  97871. for (
  97872. var _i2 = this.vertices.length - 1;
  97873. _i2 > this.vertices.length - 1 - this.detailX;
  97874. _i2--
  97875. ) {
  97876. sum.add(this.vertexNormals[_i2]);
  97877. }
  97878. sum = _main.default.Vector.div(sum, this.detailX);
  97879. for (
  97880. var _i3 = this.vertices.length - 1;
  97881. _i3 > this.vertices.length - 1 - this.detailX;
  97882. _i3--
  97883. ) {
  97884. this.vertexNormals[_i3] = sum;
  97885. }
  97886. return this;
  97887. };
  97888. /**
  97889. * Create a 2D array for establishing stroke connections
  97890. * @private
  97891. * @chainable
  97892. */
  97893. _main.default.Geometry.prototype._makeTriangleEdges = function() {
  97894. this.edges.length = 0;
  97895. if (Array.isArray(this.strokeIndices)) {
  97896. for (var i = 0, max = this.strokeIndices.length; i < max; i++) {
  97897. this.edges.push(this.strokeIndices[i]);
  97898. }
  97899. } else {
  97900. for (var j = 0; j < this.faces.length; j++) {
  97901. this.edges.push([this.faces[j][0], this.faces[j][1]]);
  97902. this.edges.push([this.faces[j][1], this.faces[j][2]]);
  97903. this.edges.push([this.faces[j][2], this.faces[j][0]]);
  97904. }
  97905. }
  97906. return this;
  97907. };
  97908. /**
  97909. * Create 4 vertices for each stroke line, two at the beginning position
  97910. * and two at the end position. These vertices are displaced relative to
  97911. * that line's normal on the GPU
  97912. * @private
  97913. * @chainable
  97914. */
  97915. _main.default.Geometry.prototype._edgesToVertices = function() {
  97916. this.lineVertices.length = 0;
  97917. this.lineNormals.length = 0;
  97918. for (var i = 0; i < this.edges.length; i++) {
  97919. var begin = this.vertices[this.edges[i][0]];
  97920. var end = this.vertices[this.edges[i][1]];
  97921. var dir = end
  97922. .copy()
  97923. .sub(begin)
  97924. .normalize();
  97925. var a = begin.array();
  97926. var b = begin.array();
  97927. var c = end.array();
  97928. var d = end.array();
  97929. var dirAdd = dir.array();
  97930. var dirSub = dir.array();
  97931. // below is used to displace the pair of vertices at beginning and end
  97932. // in opposite directions
  97933. dirAdd.push(1);
  97934. dirSub.push(-1);
  97935. this.lineNormals.push(dirAdd, dirSub, dirAdd, dirAdd, dirSub, dirSub);
  97936. this.lineVertices.push(a, b, c, c, b, d);
  97937. }
  97938. return this;
  97939. };
  97940. /**
  97941. * Modifies all vertices to be centered within the range -100 to 100.
  97942. * @method normalize
  97943. * @chainable
  97944. */
  97945. _main.default.Geometry.prototype.normalize = function() {
  97946. if (this.vertices.length > 0) {
  97947. // Find the corners of our bounding box
  97948. var maxPosition = this.vertices[0].copy();
  97949. var minPosition = this.vertices[0].copy();
  97950. for (var i = 0; i < this.vertices.length; i++) {
  97951. maxPosition.x = Math.max(maxPosition.x, this.vertices[i].x);
  97952. minPosition.x = Math.min(minPosition.x, this.vertices[i].x);
  97953. maxPosition.y = Math.max(maxPosition.y, this.vertices[i].y);
  97954. minPosition.y = Math.min(minPosition.y, this.vertices[i].y);
  97955. maxPosition.z = Math.max(maxPosition.z, this.vertices[i].z);
  97956. minPosition.z = Math.min(minPosition.z, this.vertices[i].z);
  97957. }
  97958. var center = _main.default.Vector.lerp(maxPosition, minPosition, 0.5);
  97959. var dist = _main.default.Vector.sub(maxPosition, minPosition);
  97960. var longestDist = Math.max(Math.max(dist.x, dist.y), dist.z);
  97961. var scale = 200 / longestDist;
  97962. for (var _i4 = 0; _i4 < this.vertices.length; _i4++) {
  97963. this.vertices[_i4].sub(center);
  97964. this.vertices[_i4].mult(scale);
  97965. }
  97966. }
  97967. return this;
  97968. };
  97969. var _default = _main.default.Geometry;
  97970. exports.default = _default;
  97971. },
  97972. { '../core/main': 283, 'core-js/modules/es.string.sub': 207 }
  97973. ],
  97974. 333: [
  97975. function(_dereq_, module, exports) {
  97976. 'use strict';
  97977. _dereq_('core-js/modules/es.array.iterator');
  97978. _dereq_('core-js/modules/es.object.to-string');
  97979. _dereq_('core-js/modules/es.typed-array.float32-array');
  97980. _dereq_('core-js/modules/es.typed-array.copy-within');
  97981. _dereq_('core-js/modules/es.typed-array.every');
  97982. _dereq_('core-js/modules/es.typed-array.fill');
  97983. _dereq_('core-js/modules/es.typed-array.filter');
  97984. _dereq_('core-js/modules/es.typed-array.find');
  97985. _dereq_('core-js/modules/es.typed-array.find-index');
  97986. _dereq_('core-js/modules/es.typed-array.for-each');
  97987. _dereq_('core-js/modules/es.typed-array.includes');
  97988. _dereq_('core-js/modules/es.typed-array.index-of');
  97989. _dereq_('core-js/modules/es.typed-array.iterator');
  97990. _dereq_('core-js/modules/es.typed-array.join');
  97991. _dereq_('core-js/modules/es.typed-array.last-index-of');
  97992. _dereq_('core-js/modules/es.typed-array.map');
  97993. _dereq_('core-js/modules/es.typed-array.reduce');
  97994. _dereq_('core-js/modules/es.typed-array.reduce-right');
  97995. _dereq_('core-js/modules/es.typed-array.reverse');
  97996. _dereq_('core-js/modules/es.typed-array.set');
  97997. _dereq_('core-js/modules/es.typed-array.slice');
  97998. _dereq_('core-js/modules/es.typed-array.some');
  97999. _dereq_('core-js/modules/es.typed-array.sort');
  98000. _dereq_('core-js/modules/es.typed-array.subarray');
  98001. _dereq_('core-js/modules/es.typed-array.to-locale-string');
  98002. _dereq_('core-js/modules/es.typed-array.to-string');
  98003. Object.defineProperty(exports, '__esModule', { value: true });
  98004. exports.default = void 0;
  98005. var _main = _interopRequireDefault(_dereq_('../core/main'));
  98006. function _interopRequireDefault(obj) {
  98007. return obj && obj.__esModule ? obj : { default: obj };
  98008. }
  98009. /**
  98010. * @requires constants
  98011. * @todo see methods below needing further implementation.
  98012. * future consideration: implement SIMD optimizations
  98013. * when browser compatibility becomes available
  98014. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/
  98015. * Reference/Global_Objects/SIMD
  98016. */ var GLMAT_ARRAY_TYPE = Array;
  98017. var isMatrixArray = function isMatrixArray(x) {
  98018. return x instanceof Array;
  98019. };
  98020. if (typeof Float32Array !== 'undefined') {
  98021. GLMAT_ARRAY_TYPE = Float32Array;
  98022. isMatrixArray = function isMatrixArray(x) {
  98023. return x instanceof Array || x instanceof Float32Array;
  98024. };
  98025. }
  98026. /**
  98027. * A class to describe a 4x4 matrix
  98028. * for model and view matrix manipulation in the p5js webgl renderer.
  98029. * @class p5.Matrix
  98030. * @private
  98031. * @constructor
  98032. * @param {Array} [mat4] array literal of our 4x4 matrix
  98033. */
  98034. _main.default.Matrix = function() {
  98035. var args = new Array(arguments.length);
  98036. for (var i = 0; i < args.length; ++i) {
  98037. args[i] = arguments[i];
  98038. }
  98039. // This is default behavior when object
  98040. // instantiated using createMatrix()
  98041. // @todo implement createMatrix() in core/math.js
  98042. if (args.length && args[args.length - 1] instanceof _main.default) {
  98043. this.p5 = args[args.length - 1];
  98044. }
  98045. if (args[0] === 'mat3') {
  98046. this.mat3 = Array.isArray(args[1])
  98047. ? args[1]
  98048. : new GLMAT_ARRAY_TYPE([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  98049. } else {
  98050. this.mat4 = Array.isArray(args[0])
  98051. ? args[0]
  98052. : new GLMAT_ARRAY_TYPE([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
  98053. }
  98054. return this;
  98055. };
  98056. /**
  98057. * Sets the x, y, and z component of the vector using two or three separate
  98058. * variables, the data from a p5.Matrix, or the values from a float array.
  98059. *
  98060. * @method set
  98061. * @param {p5.Matrix|Float32Array|Number[]} [inMatrix] the input p5.Matrix or
  98062. * an Array of length 16
  98063. * @chainable
  98064. */
  98065. /**
  98066. * @method set
  98067. * @param {Number[]} elements 16 numbers passed by value to avoid
  98068. * array copying.
  98069. * @chainable
  98070. */
  98071. _main.default.Matrix.prototype.set = function(inMatrix) {
  98072. if (inMatrix instanceof _main.default.Matrix) {
  98073. this.mat4 = inMatrix.mat4;
  98074. return this;
  98075. } else if (isMatrixArray(inMatrix)) {
  98076. this.mat4 = inMatrix;
  98077. return this;
  98078. } else if (arguments.length === 16) {
  98079. this.mat4[0] = arguments[0];
  98080. this.mat4[1] = arguments[1];
  98081. this.mat4[2] = arguments[2];
  98082. this.mat4[3] = arguments[3];
  98083. this.mat4[4] = arguments[4];
  98084. this.mat4[5] = arguments[5];
  98085. this.mat4[6] = arguments[6];
  98086. this.mat4[7] = arguments[7];
  98087. this.mat4[8] = arguments[8];
  98088. this.mat4[9] = arguments[9];
  98089. this.mat4[10] = arguments[10];
  98090. this.mat4[11] = arguments[11];
  98091. this.mat4[12] = arguments[12];
  98092. this.mat4[13] = arguments[13];
  98093. this.mat4[14] = arguments[14];
  98094. this.mat4[15] = arguments[15];
  98095. }
  98096. return this;
  98097. };
  98098. /**
  98099. * Gets a copy of the vector, returns a p5.Matrix object.
  98100. *
  98101. * @method get
  98102. * @return {p5.Matrix} the copy of the p5.Matrix object
  98103. */
  98104. _main.default.Matrix.prototype.get = function() {
  98105. return new _main.default.Matrix(this.mat4, this.p5);
  98106. };
  98107. /**
  98108. * return a copy of a matrix
  98109. * @method copy
  98110. * @return {p5.Matrix} the result matrix
  98111. */
  98112. _main.default.Matrix.prototype.copy = function() {
  98113. var copied = new _main.default.Matrix(this.p5);
  98114. copied.mat4[0] = this.mat4[0];
  98115. copied.mat4[1] = this.mat4[1];
  98116. copied.mat4[2] = this.mat4[2];
  98117. copied.mat4[3] = this.mat4[3];
  98118. copied.mat4[4] = this.mat4[4];
  98119. copied.mat4[5] = this.mat4[5];
  98120. copied.mat4[6] = this.mat4[6];
  98121. copied.mat4[7] = this.mat4[7];
  98122. copied.mat4[8] = this.mat4[8];
  98123. copied.mat4[9] = this.mat4[9];
  98124. copied.mat4[10] = this.mat4[10];
  98125. copied.mat4[11] = this.mat4[11];
  98126. copied.mat4[12] = this.mat4[12];
  98127. copied.mat4[13] = this.mat4[13];
  98128. copied.mat4[14] = this.mat4[14];
  98129. copied.mat4[15] = this.mat4[15];
  98130. return copied;
  98131. };
  98132. /**
  98133. * return an identity matrix
  98134. * @method identity
  98135. * @return {p5.Matrix} the result matrix
  98136. */
  98137. _main.default.Matrix.identity = function(pInst) {
  98138. return new _main.default.Matrix(pInst);
  98139. };
  98140. /**
  98141. * transpose according to a given matrix
  98142. * @method transpose
  98143. * @param {p5.Matrix|Float32Array|Number[]} a the matrix to be
  98144. * based on to transpose
  98145. * @chainable
  98146. */
  98147. _main.default.Matrix.prototype.transpose = function(a) {
  98148. var a01, a02, a03, a12, a13, a23;
  98149. if (a instanceof _main.default.Matrix) {
  98150. a01 = a.mat4[1];
  98151. a02 = a.mat4[2];
  98152. a03 = a.mat4[3];
  98153. a12 = a.mat4[6];
  98154. a13 = a.mat4[7];
  98155. a23 = a.mat4[11];
  98156. this.mat4[0] = a.mat4[0];
  98157. this.mat4[1] = a.mat4[4];
  98158. this.mat4[2] = a.mat4[8];
  98159. this.mat4[3] = a.mat4[12];
  98160. this.mat4[4] = a01;
  98161. this.mat4[5] = a.mat4[5];
  98162. this.mat4[6] = a.mat4[9];
  98163. this.mat4[7] = a.mat4[13];
  98164. this.mat4[8] = a02;
  98165. this.mat4[9] = a12;
  98166. this.mat4[10] = a.mat4[10];
  98167. this.mat4[11] = a.mat4[14];
  98168. this.mat4[12] = a03;
  98169. this.mat4[13] = a13;
  98170. this.mat4[14] = a23;
  98171. this.mat4[15] = a.mat4[15];
  98172. } else if (isMatrixArray(a)) {
  98173. a01 = a[1];
  98174. a02 = a[2];
  98175. a03 = a[3];
  98176. a12 = a[6];
  98177. a13 = a[7];
  98178. a23 = a[11];
  98179. this.mat4[0] = a[0];
  98180. this.mat4[1] = a[4];
  98181. this.mat4[2] = a[8];
  98182. this.mat4[3] = a[12];
  98183. this.mat4[4] = a01;
  98184. this.mat4[5] = a[5];
  98185. this.mat4[6] = a[9];
  98186. this.mat4[7] = a[13];
  98187. this.mat4[8] = a02;
  98188. this.mat4[9] = a12;
  98189. this.mat4[10] = a[10];
  98190. this.mat4[11] = a[14];
  98191. this.mat4[12] = a03;
  98192. this.mat4[13] = a13;
  98193. this.mat4[14] = a23;
  98194. this.mat4[15] = a[15];
  98195. }
  98196. return this;
  98197. };
  98198. /**
  98199. * invert matrix according to a give matrix
  98200. * @method invert
  98201. * @param {p5.Matrix|Float32Array|Number[]} a the matrix to be
  98202. * based on to invert
  98203. * @chainable
  98204. */
  98205. _main.default.Matrix.prototype.invert = function(a) {
  98206. var a00, a01, a02, a03, a10, a11, a12, a13;
  98207. var a20, a21, a22, a23, a30, a31, a32, a33;
  98208. if (a instanceof _main.default.Matrix) {
  98209. a00 = a.mat4[0];
  98210. a01 = a.mat4[1];
  98211. a02 = a.mat4[2];
  98212. a03 = a.mat4[3];
  98213. a10 = a.mat4[4];
  98214. a11 = a.mat4[5];
  98215. a12 = a.mat4[6];
  98216. a13 = a.mat4[7];
  98217. a20 = a.mat4[8];
  98218. a21 = a.mat4[9];
  98219. a22 = a.mat4[10];
  98220. a23 = a.mat4[11];
  98221. a30 = a.mat4[12];
  98222. a31 = a.mat4[13];
  98223. a32 = a.mat4[14];
  98224. a33 = a.mat4[15];
  98225. } else if (isMatrixArray(a)) {
  98226. a00 = a[0];
  98227. a01 = a[1];
  98228. a02 = a[2];
  98229. a03 = a[3];
  98230. a10 = a[4];
  98231. a11 = a[5];
  98232. a12 = a[6];
  98233. a13 = a[7];
  98234. a20 = a[8];
  98235. a21 = a[9];
  98236. a22 = a[10];
  98237. a23 = a[11];
  98238. a30 = a[12];
  98239. a31 = a[13];
  98240. a32 = a[14];
  98241. a33 = a[15];
  98242. }
  98243. var b00 = a00 * a11 - a01 * a10;
  98244. var b01 = a00 * a12 - a02 * a10;
  98245. var b02 = a00 * a13 - a03 * a10;
  98246. var b03 = a01 * a12 - a02 * a11;
  98247. var b04 = a01 * a13 - a03 * a11;
  98248. var b05 = a02 * a13 - a03 * a12;
  98249. var b06 = a20 * a31 - a21 * a30;
  98250. var b07 = a20 * a32 - a22 * a30;
  98251. var b08 = a20 * a33 - a23 * a30;
  98252. var b09 = a21 * a32 - a22 * a31;
  98253. var b10 = a21 * a33 - a23 * a31;
  98254. var b11 = a22 * a33 - a23 * a32;
  98255. // Calculate the determinant
  98256. var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
  98257. if (!det) {
  98258. return null;
  98259. }
  98260. det = 1.0 / det;
  98261. this.mat4[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
  98262. this.mat4[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
  98263. this.mat4[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
  98264. this.mat4[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
  98265. this.mat4[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
  98266. this.mat4[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
  98267. this.mat4[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
  98268. this.mat4[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
  98269. this.mat4[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
  98270. this.mat4[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
  98271. this.mat4[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
  98272. this.mat4[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
  98273. this.mat4[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
  98274. this.mat4[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
  98275. this.mat4[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
  98276. this.mat4[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
  98277. return this;
  98278. };
  98279. /**
  98280. * Inverts a 3x3 matrix
  98281. * @method invert3x3
  98282. * @chainable
  98283. */
  98284. _main.default.Matrix.prototype.invert3x3 = function() {
  98285. var a00 = this.mat3[0];
  98286. var a01 = this.mat3[1];
  98287. var a02 = this.mat3[2];
  98288. var a10 = this.mat3[3];
  98289. var a11 = this.mat3[4];
  98290. var a12 = this.mat3[5];
  98291. var a20 = this.mat3[6];
  98292. var a21 = this.mat3[7];
  98293. var a22 = this.mat3[8];
  98294. var b01 = a22 * a11 - a12 * a21;
  98295. var b11 = -a22 * a10 + a12 * a20;
  98296. var b21 = a21 * a10 - a11 * a20;
  98297. // Calculate the determinant
  98298. var det = a00 * b01 + a01 * b11 + a02 * b21;
  98299. if (!det) {
  98300. return null;
  98301. }
  98302. det = 1.0 / det;
  98303. this.mat3[0] = b01 * det;
  98304. this.mat3[1] = (-a22 * a01 + a02 * a21) * det;
  98305. this.mat3[2] = (a12 * a01 - a02 * a11) * det;
  98306. this.mat3[3] = b11 * det;
  98307. this.mat3[4] = (a22 * a00 - a02 * a20) * det;
  98308. this.mat3[5] = (-a12 * a00 + a02 * a10) * det;
  98309. this.mat3[6] = b21 * det;
  98310. this.mat3[7] = (-a21 * a00 + a01 * a20) * det;
  98311. this.mat3[8] = (a11 * a00 - a01 * a10) * det;
  98312. return this;
  98313. };
  98314. /**
  98315. * transposes a 3x3 p5.Matrix by a mat3
  98316. * @method transpose3x3
  98317. * @param {Number[]} mat3 1-dimensional array
  98318. * @chainable
  98319. */
  98320. _main.default.Matrix.prototype.transpose3x3 = function(mat3) {
  98321. var a01 = mat3[1],
  98322. a02 = mat3[2],
  98323. a12 = mat3[5];
  98324. this.mat3[1] = mat3[3];
  98325. this.mat3[2] = mat3[6];
  98326. this.mat3[3] = a01;
  98327. this.mat3[5] = mat3[7];
  98328. this.mat3[6] = a02;
  98329. this.mat3[7] = a12;
  98330. return this;
  98331. };
  98332. /**
  98333. * converts a 4x4 matrix to its 3x3 inverse transform
  98334. * commonly used in MVMatrix to NMatrix conversions.
  98335. * @method invertTranspose
  98336. * @param {p5.Matrix} mat4 the matrix to be based on to invert
  98337. * @chainable
  98338. * @todo finish implementation
  98339. */
  98340. _main.default.Matrix.prototype.inverseTranspose = function(matrix) {
  98341. if (this.mat3 === undefined) {
  98342. console.error('sorry, this function only works with mat3');
  98343. } else {
  98344. //convert mat4 -> mat3
  98345. this.mat3[0] = matrix.mat4[0];
  98346. this.mat3[1] = matrix.mat4[1];
  98347. this.mat3[2] = matrix.mat4[2];
  98348. this.mat3[3] = matrix.mat4[4];
  98349. this.mat3[4] = matrix.mat4[5];
  98350. this.mat3[5] = matrix.mat4[6];
  98351. this.mat3[6] = matrix.mat4[8];
  98352. this.mat3[7] = matrix.mat4[9];
  98353. this.mat3[8] = matrix.mat4[10];
  98354. }
  98355. var inverse = this.invert3x3();
  98356. // check inverse succeeded
  98357. if (inverse) {
  98358. inverse.transpose3x3(this.mat3);
  98359. } else {
  98360. // in case of singularity, just zero the matrix
  98361. for (var i = 0; i < 9; i++) {
  98362. this.mat3[i] = 0;
  98363. }
  98364. }
  98365. return this;
  98366. };
  98367. /**
  98368. * inspired by Toji's mat4 determinant
  98369. * @method determinant
  98370. * @return {Number} Determinant of our 4x4 matrix
  98371. */
  98372. _main.default.Matrix.prototype.determinant = function() {
  98373. var d00 = this.mat4[0] * this.mat4[5] - this.mat4[1] * this.mat4[4],
  98374. d01 = this.mat4[0] * this.mat4[6] - this.mat4[2] * this.mat4[4],
  98375. d02 = this.mat4[0] * this.mat4[7] - this.mat4[3] * this.mat4[4],
  98376. d03 = this.mat4[1] * this.mat4[6] - this.mat4[2] * this.mat4[5],
  98377. d04 = this.mat4[1] * this.mat4[7] - this.mat4[3] * this.mat4[5],
  98378. d05 = this.mat4[2] * this.mat4[7] - this.mat4[3] * this.mat4[6],
  98379. d06 = this.mat4[8] * this.mat4[13] - this.mat4[9] * this.mat4[12],
  98380. d07 = this.mat4[8] * this.mat4[14] - this.mat4[10] * this.mat4[12],
  98381. d08 = this.mat4[8] * this.mat4[15] - this.mat4[11] * this.mat4[12],
  98382. d09 = this.mat4[9] * this.mat4[14] - this.mat4[10] * this.mat4[13],
  98383. d10 = this.mat4[9] * this.mat4[15] - this.mat4[11] * this.mat4[13],
  98384. d11 = this.mat4[10] * this.mat4[15] - this.mat4[11] * this.mat4[14];
  98385. // Calculate the determinant
  98386. return d00 * d11 - d01 * d10 + d02 * d09 + d03 * d08 - d04 * d07 + d05 * d06;
  98387. };
  98388. /**
  98389. * multiply two mat4s
  98390. * @method mult
  98391. * @param {p5.Matrix|Float32Array|Number[]} multMatrix The matrix
  98392. * we want to multiply by
  98393. * @chainable
  98394. */
  98395. _main.default.Matrix.prototype.mult = function(multMatrix) {
  98396. var _src;
  98397. if (multMatrix === this || multMatrix === this.mat4) {
  98398. _src = this.copy().mat4; // only need to allocate in this rare case
  98399. } else if (multMatrix instanceof _main.default.Matrix) {
  98400. _src = multMatrix.mat4;
  98401. } else if (isMatrixArray(multMatrix)) {
  98402. _src = multMatrix;
  98403. } else if (arguments.length === 16) {
  98404. _src = arguments;
  98405. } else {
  98406. return; // nothing to do.
  98407. }
  98408. // each row is used for the multiplier
  98409. var b0 = this.mat4[0],
  98410. b1 = this.mat4[1],
  98411. b2 = this.mat4[2],
  98412. b3 = this.mat4[3];
  98413. this.mat4[0] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12];
  98414. this.mat4[1] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13];
  98415. this.mat4[2] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14];
  98416. this.mat4[3] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15];
  98417. b0 = this.mat4[4];
  98418. b1 = this.mat4[5];
  98419. b2 = this.mat4[6];
  98420. b3 = this.mat4[7];
  98421. this.mat4[4] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12];
  98422. this.mat4[5] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13];
  98423. this.mat4[6] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14];
  98424. this.mat4[7] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15];
  98425. b0 = this.mat4[8];
  98426. b1 = this.mat4[9];
  98427. b2 = this.mat4[10];
  98428. b3 = this.mat4[11];
  98429. this.mat4[8] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12];
  98430. this.mat4[9] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13];
  98431. this.mat4[10] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14];
  98432. this.mat4[11] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15];
  98433. b0 = this.mat4[12];
  98434. b1 = this.mat4[13];
  98435. b2 = this.mat4[14];
  98436. b3 = this.mat4[15];
  98437. this.mat4[12] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12];
  98438. this.mat4[13] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13];
  98439. this.mat4[14] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14];
  98440. this.mat4[15] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15];
  98441. return this;
  98442. };
  98443. _main.default.Matrix.prototype.apply = function(multMatrix) {
  98444. var _src;
  98445. if (multMatrix === this || multMatrix === this.mat4) {
  98446. _src = this.copy().mat4; // only need to allocate in this rare case
  98447. } else if (multMatrix instanceof _main.default.Matrix) {
  98448. _src = multMatrix.mat4;
  98449. } else if (isMatrixArray(multMatrix)) {
  98450. _src = multMatrix;
  98451. } else if (arguments.length === 16) {
  98452. _src = arguments;
  98453. } else {
  98454. return; // nothing to do.
  98455. }
  98456. var mat4 = this.mat4;
  98457. // each row is used for the multiplier
  98458. var m0 = mat4[0];
  98459. var m4 = mat4[4];
  98460. var m8 = mat4[8];
  98461. var m12 = mat4[12];
  98462. mat4[0] = _src[0] * m0 + _src[1] * m4 + _src[2] * m8 + _src[3] * m12;
  98463. mat4[4] = _src[4] * m0 + _src[5] * m4 + _src[6] * m8 + _src[7] * m12;
  98464. mat4[8] = _src[8] * m0 + _src[9] * m4 + _src[10] * m8 + _src[11] * m12;
  98465. mat4[12] = _src[12] * m0 + _src[13] * m4 + _src[14] * m8 + _src[15] * m12;
  98466. var m1 = mat4[1];
  98467. var m5 = mat4[5];
  98468. var m9 = mat4[9];
  98469. var m13 = mat4[13];
  98470. mat4[1] = _src[0] * m1 + _src[1] * m5 + _src[2] * m9 + _src[3] * m13;
  98471. mat4[5] = _src[4] * m1 + _src[5] * m5 + _src[6] * m9 + _src[7] * m13;
  98472. mat4[9] = _src[8] * m1 + _src[9] * m5 + _src[10] * m9 + _src[11] * m13;
  98473. mat4[13] = _src[12] * m1 + _src[13] * m5 + _src[14] * m9 + _src[15] * m13;
  98474. var m2 = mat4[2];
  98475. var m6 = mat4[6];
  98476. var m10 = mat4[10];
  98477. var m14 = mat4[14];
  98478. mat4[2] = _src[0] * m2 + _src[1] * m6 + _src[2] * m10 + _src[3] * m14;
  98479. mat4[6] = _src[4] * m2 + _src[5] * m6 + _src[6] * m10 + _src[7] * m14;
  98480. mat4[10] = _src[8] * m2 + _src[9] * m6 + _src[10] * m10 + _src[11] * m14;
  98481. mat4[14] = _src[12] * m2 + _src[13] * m6 + _src[14] * m10 + _src[15] * m14;
  98482. var m3 = mat4[3];
  98483. var m7 = mat4[7];
  98484. var m11 = mat4[11];
  98485. var m15 = mat4[15];
  98486. mat4[3] = _src[0] * m3 + _src[1] * m7 + _src[2] * m11 + _src[3] * m15;
  98487. mat4[7] = _src[4] * m3 + _src[5] * m7 + _src[6] * m11 + _src[7] * m15;
  98488. mat4[11] = _src[8] * m3 + _src[9] * m7 + _src[10] * m11 + _src[11] * m15;
  98489. mat4[15] = _src[12] * m3 + _src[13] * m7 + _src[14] * m11 + _src[15] * m15;
  98490. return this;
  98491. };
  98492. /**
  98493. * scales a p5.Matrix by scalars or a vector
  98494. * @method scale
  98495. * @param {p5.Vector|Float32Array|Number[]} s vector to scale by
  98496. * @chainable
  98497. */
  98498. _main.default.Matrix.prototype.scale = function(x, y, z) {
  98499. if (x instanceof _main.default.Vector) {
  98500. // x is a vector, extract the components from it.
  98501. y = x.y;
  98502. z = x.z;
  98503. x = x.x; // must be last
  98504. } else if (x instanceof Array) {
  98505. // x is an array, extract the components from it.
  98506. y = x[1];
  98507. z = x[2];
  98508. x = x[0]; // must be last
  98509. }
  98510. this.mat4[0] *= x;
  98511. this.mat4[1] *= x;
  98512. this.mat4[2] *= x;
  98513. this.mat4[3] *= x;
  98514. this.mat4[4] *= y;
  98515. this.mat4[5] *= y;
  98516. this.mat4[6] *= y;
  98517. this.mat4[7] *= y;
  98518. this.mat4[8] *= z;
  98519. this.mat4[9] *= z;
  98520. this.mat4[10] *= z;
  98521. this.mat4[11] *= z;
  98522. return this;
  98523. };
  98524. /**
  98525. * rotate our Matrix around an axis by the given angle.
  98526. * @method rotate
  98527. * @param {Number} a The angle of rotation in radians
  98528. * @param {p5.Vector|Number[]} axis the axis(es) to rotate around
  98529. * @chainable
  98530. * inspired by Toji's gl-matrix lib, mat4 rotation
  98531. */
  98532. _main.default.Matrix.prototype.rotate = function(a, x, y, z) {
  98533. if (x instanceof _main.default.Vector) {
  98534. // x is a vector, extract the components from it.
  98535. y = x.y;
  98536. z = x.z;
  98537. x = x.x; //must be last
  98538. } else if (x instanceof Array) {
  98539. // x is an array, extract the components from it.
  98540. y = x[1];
  98541. z = x[2];
  98542. x = x[0]; //must be last
  98543. }
  98544. var len = Math.sqrt(x * x + y * y + z * z);
  98545. x *= 1 / len;
  98546. y *= 1 / len;
  98547. z *= 1 / len;
  98548. var a00 = this.mat4[0];
  98549. var a01 = this.mat4[1];
  98550. var a02 = this.mat4[2];
  98551. var a03 = this.mat4[3];
  98552. var a10 = this.mat4[4];
  98553. var a11 = this.mat4[5];
  98554. var a12 = this.mat4[6];
  98555. var a13 = this.mat4[7];
  98556. var a20 = this.mat4[8];
  98557. var a21 = this.mat4[9];
  98558. var a22 = this.mat4[10];
  98559. var a23 = this.mat4[11];
  98560. //sin,cos, and tan of respective angle
  98561. var sA = Math.sin(a);
  98562. var cA = Math.cos(a);
  98563. var tA = 1 - cA;
  98564. // Construct the elements of the rotation matrix
  98565. var b00 = x * x * tA + cA;
  98566. var b01 = y * x * tA + z * sA;
  98567. var b02 = z * x * tA - y * sA;
  98568. var b10 = x * y * tA - z * sA;
  98569. var b11 = y * y * tA + cA;
  98570. var b12 = z * y * tA + x * sA;
  98571. var b20 = x * z * tA + y * sA;
  98572. var b21 = y * z * tA - x * sA;
  98573. var b22 = z * z * tA + cA;
  98574. // rotation-specific matrix multiplication
  98575. this.mat4[0] = a00 * b00 + a10 * b01 + a20 * b02;
  98576. this.mat4[1] = a01 * b00 + a11 * b01 + a21 * b02;
  98577. this.mat4[2] = a02 * b00 + a12 * b01 + a22 * b02;
  98578. this.mat4[3] = a03 * b00 + a13 * b01 + a23 * b02;
  98579. this.mat4[4] = a00 * b10 + a10 * b11 + a20 * b12;
  98580. this.mat4[5] = a01 * b10 + a11 * b11 + a21 * b12;
  98581. this.mat4[6] = a02 * b10 + a12 * b11 + a22 * b12;
  98582. this.mat4[7] = a03 * b10 + a13 * b11 + a23 * b12;
  98583. this.mat4[8] = a00 * b20 + a10 * b21 + a20 * b22;
  98584. this.mat4[9] = a01 * b20 + a11 * b21 + a21 * b22;
  98585. this.mat4[10] = a02 * b20 + a12 * b21 + a22 * b22;
  98586. this.mat4[11] = a03 * b20 + a13 * b21 + a23 * b22;
  98587. return this;
  98588. };
  98589. /**
  98590. * @todo finish implementing this method!
  98591. * translates
  98592. * @method translate
  98593. * @param {Number[]} v vector to translate by
  98594. * @chainable
  98595. */
  98596. _main.default.Matrix.prototype.translate = function(v) {
  98597. var x = v[0],
  98598. y = v[1],
  98599. z = v[2] || 0;
  98600. this.mat4[12] += this.mat4[0] * x + this.mat4[4] * y + this.mat4[8] * z;
  98601. this.mat4[13] += this.mat4[1] * x + this.mat4[5] * y + this.mat4[9] * z;
  98602. this.mat4[14] += this.mat4[2] * x + this.mat4[6] * y + this.mat4[10] * z;
  98603. this.mat4[15] += this.mat4[3] * x + this.mat4[7] * y + this.mat4[11] * z;
  98604. };
  98605. _main.default.Matrix.prototype.rotateX = function(a) {
  98606. this.rotate(a, 1, 0, 0);
  98607. };
  98608. _main.default.Matrix.prototype.rotateY = function(a) {
  98609. this.rotate(a, 0, 1, 0);
  98610. };
  98611. _main.default.Matrix.prototype.rotateZ = function(a) {
  98612. this.rotate(a, 0, 0, 1);
  98613. };
  98614. /**
  98615. * sets the perspective matrix
  98616. * @method perspective
  98617. * @param {Number} fovy [description]
  98618. * @param {Number} aspect [description]
  98619. * @param {Number} near near clipping plane
  98620. * @param {Number} far far clipping plane
  98621. * @chainable
  98622. */
  98623. _main.default.Matrix.prototype.perspective = function(fovy, aspect, near, far) {
  98624. var f = 1.0 / Math.tan(fovy / 2),
  98625. nf = 1 / (near - far);
  98626. this.mat4[0] = f / aspect;
  98627. this.mat4[1] = 0;
  98628. this.mat4[2] = 0;
  98629. this.mat4[3] = 0;
  98630. this.mat4[4] = 0;
  98631. this.mat4[5] = f;
  98632. this.mat4[6] = 0;
  98633. this.mat4[7] = 0;
  98634. this.mat4[8] = 0;
  98635. this.mat4[9] = 0;
  98636. this.mat4[10] = (far + near) * nf;
  98637. this.mat4[11] = -1;
  98638. this.mat4[12] = 0;
  98639. this.mat4[13] = 0;
  98640. this.mat4[14] = 2 * far * near * nf;
  98641. this.mat4[15] = 0;
  98642. return this;
  98643. };
  98644. /**
  98645. * sets the ortho matrix
  98646. * @method ortho
  98647. * @param {Number} left [description]
  98648. * @param {Number} right [description]
  98649. * @param {Number} bottom [description]
  98650. * @param {Number} top [description]
  98651. * @param {Number} near near clipping plane
  98652. * @param {Number} far far clipping plane
  98653. * @chainable
  98654. */
  98655. _main.default.Matrix.prototype.ortho = function(
  98656. left,
  98657. right,
  98658. bottom,
  98659. top,
  98660. near,
  98661. far
  98662. ) {
  98663. var lr = 1 / (left - right),
  98664. bt = 1 / (bottom - top),
  98665. nf = 1 / (near - far);
  98666. this.mat4[0] = -2 * lr;
  98667. this.mat4[1] = 0;
  98668. this.mat4[2] = 0;
  98669. this.mat4[3] = 0;
  98670. this.mat4[4] = 0;
  98671. this.mat4[5] = -2 * bt;
  98672. this.mat4[6] = 0;
  98673. this.mat4[7] = 0;
  98674. this.mat4[8] = 0;
  98675. this.mat4[9] = 0;
  98676. this.mat4[10] = 2 * nf;
  98677. this.mat4[11] = 0;
  98678. this.mat4[12] = (left + right) * lr;
  98679. this.mat4[13] = (top + bottom) * bt;
  98680. this.mat4[14] = (far + near) * nf;
  98681. this.mat4[15] = 1;
  98682. return this;
  98683. };
  98684. /**
  98685. * PRIVATE
  98686. */
  98687. // matrix methods adapted from:
  98688. // https://developer.mozilla.org/en-US/docs/Web/WebGL/
  98689. // gluPerspective
  98690. //
  98691. // function _makePerspective(fovy, aspect, znear, zfar){
  98692. // const ymax = znear * Math.tan(fovy * Math.PI / 360.0);
  98693. // const ymin = -ymax;
  98694. // const xmin = ymin * aspect;
  98695. // const xmax = ymax * aspect;
  98696. // return _makeFrustum(xmin, xmax, ymin, ymax, znear, zfar);
  98697. // }
  98698. ////
  98699. //// glFrustum
  98700. ////
  98701. //function _makeFrustum(left, right, bottom, top, znear, zfar){
  98702. // const X = 2*znear/(right-left);
  98703. // const Y = 2*znear/(top-bottom);
  98704. // const A = (right+left)/(right-left);
  98705. // const B = (top+bottom)/(top-bottom);
  98706. // const C = -(zfar+znear)/(zfar-znear);
  98707. // const D = -2*zfar*znear/(zfar-znear);
  98708. // const frustrumMatrix =[
  98709. // X, 0, A, 0,
  98710. // 0, Y, B, 0,
  98711. // 0, 0, C, D,
  98712. // 0, 0, -1, 0
  98713. //];
  98714. //return frustrumMatrix;
  98715. // }
  98716. // function _setMVPMatrices(){
  98717. ////an identity matrix
  98718. ////@TODO use the p5.Matrix class to abstract away our MV matrices and
  98719. ///other math
  98720. //const _mvMatrix =
  98721. //[
  98722. // 1.0,0.0,0.0,0.0,
  98723. // 0.0,1.0,0.0,0.0,
  98724. // 0.0,0.0,1.0,0.0,
  98725. // 0.0,0.0,0.0,1.0
  98726. //];
  98727. var _default = _main.default.Matrix;
  98728. exports.default = _default;
  98729. },
  98730. {
  98731. '../core/main': 283,
  98732. 'core-js/modules/es.array.iterator': 174,
  98733. 'core-js/modules/es.object.to-string': 192,
  98734. 'core-js/modules/es.typed-array.copy-within': 212,
  98735. 'core-js/modules/es.typed-array.every': 213,
  98736. 'core-js/modules/es.typed-array.fill': 214,
  98737. 'core-js/modules/es.typed-array.filter': 215,
  98738. 'core-js/modules/es.typed-array.find': 217,
  98739. 'core-js/modules/es.typed-array.find-index': 216,
  98740. 'core-js/modules/es.typed-array.float32-array': 218,
  98741. 'core-js/modules/es.typed-array.for-each': 220,
  98742. 'core-js/modules/es.typed-array.includes': 221,
  98743. 'core-js/modules/es.typed-array.index-of': 222,
  98744. 'core-js/modules/es.typed-array.iterator': 225,
  98745. 'core-js/modules/es.typed-array.join': 226,
  98746. 'core-js/modules/es.typed-array.last-index-of': 227,
  98747. 'core-js/modules/es.typed-array.map': 228,
  98748. 'core-js/modules/es.typed-array.reduce': 230,
  98749. 'core-js/modules/es.typed-array.reduce-right': 229,
  98750. 'core-js/modules/es.typed-array.reverse': 231,
  98751. 'core-js/modules/es.typed-array.set': 232,
  98752. 'core-js/modules/es.typed-array.slice': 233,
  98753. 'core-js/modules/es.typed-array.some': 234,
  98754. 'core-js/modules/es.typed-array.sort': 235,
  98755. 'core-js/modules/es.typed-array.subarray': 236,
  98756. 'core-js/modules/es.typed-array.to-locale-string': 237,
  98757. 'core-js/modules/es.typed-array.to-string': 238
  98758. }
  98759. ],
  98760. 334: [
  98761. function(_dereq_, module, exports) {
  98762. 'use strict';
  98763. _dereq_('core-js/modules/es.array.map');
  98764. Object.defineProperty(exports, '__esModule', { value: true });
  98765. exports.default = void 0;
  98766. var _main = _interopRequireDefault(_dereq_('../core/main'));
  98767. function _interopRequireDefault(obj) {
  98768. return obj && obj.__esModule ? obj : { default: obj };
  98769. }
  98770. _main.default.RenderBuffer = function(size, src, dst, attr, renderer, map) {
  98771. this.size = size; // the number of FLOATs in each vertex
  98772. this.src = src; // the name of the model's source array
  98773. this.dst = dst; // the name of the geometry's buffer
  98774. this.attr = attr; // the name of the vertex attribute
  98775. this._renderer = renderer;
  98776. this.map = map; // optional, a transformation function to apply to src
  98777. };
  98778. /**
  98779. * Enables and binds the buffers used by shader when the appropriate data exists in geometry.
  98780. * Must always be done prior to drawing geometry in WebGL.
  98781. * @param {p5.Geometry} geometry Geometry that is going to be drawn
  98782. * @param {p5.Shader} shader Active shader
  98783. * @private
  98784. */
  98785. _main.default.RenderBuffer.prototype._prepareBuffer = function(geometry, shader) {
  98786. var attributes = shader.attributes;
  98787. var gl = this._renderer.GL;
  98788. var model;
  98789. if (geometry.model) {
  98790. model = geometry.model;
  98791. } else {
  98792. model = geometry;
  98793. }
  98794. // loop through each of the buffer definitions
  98795. var attr = attributes[this.attr];
  98796. if (!attr) {
  98797. return;
  98798. }
  98799. // check if the model has the appropriate source array
  98800. var buffer = geometry[this.dst];
  98801. var src = model[this.src];
  98802. if (src.length > 0) {
  98803. // check if we need to create the GL buffer
  98804. var createBuffer = !buffer;
  98805. if (createBuffer) {
  98806. // create and remember the buffer
  98807. geometry[this.dst] = buffer = gl.createBuffer();
  98808. }
  98809. // bind the buffer
  98810. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  98811. // check if we need to fill the buffer with data
  98812. if (createBuffer || model.dirtyFlags[this.src] !== false) {
  98813. var map = this.map;
  98814. // get the values from the model, possibly transformed
  98815. var values = map ? map(src) : src;
  98816. // fill the buffer with the values
  98817. this._renderer._bindBuffer(buffer, gl.ARRAY_BUFFER, values);
  98818. // mark the model's source array as clean
  98819. model.dirtyFlags[this.src] = false;
  98820. }
  98821. // enable the attribute
  98822. shader.enableAttrib(attr, this.size);
  98823. }
  98824. };
  98825. var _default = _main.default.RenderBuffer;
  98826. exports.default = _default;
  98827. },
  98828. { '../core/main': 283, 'core-js/modules/es.array.map': 177 }
  98829. ],
  98830. 335: [
  98831. function(_dereq_, module, exports) {
  98832. 'use strict';
  98833. function _typeof(obj) {
  98834. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  98835. _typeof = function _typeof(obj) {
  98836. return typeof obj;
  98837. };
  98838. } else {
  98839. _typeof = function _typeof(obj) {
  98840. return obj &&
  98841. typeof Symbol === 'function' &&
  98842. obj.constructor === Symbol &&
  98843. obj !== Symbol.prototype
  98844. ? 'symbol'
  98845. : typeof obj;
  98846. };
  98847. }
  98848. return _typeof(obj);
  98849. }
  98850. _dereq_('core-js/modules/es.symbol');
  98851. _dereq_('core-js/modules/es.symbol.description');
  98852. _dereq_('core-js/modules/es.symbol.iterator');
  98853. _dereq_('core-js/modules/es.array.fill');
  98854. _dereq_('core-js/modules/es.array.iterator');
  98855. _dereq_('core-js/modules/es.object.to-string');
  98856. _dereq_('core-js/modules/es.string.iterator');
  98857. _dereq_('core-js/modules/es.typed-array.float32-array');
  98858. _dereq_('core-js/modules/es.typed-array.copy-within');
  98859. _dereq_('core-js/modules/es.typed-array.every');
  98860. _dereq_('core-js/modules/es.typed-array.fill');
  98861. _dereq_('core-js/modules/es.typed-array.filter');
  98862. _dereq_('core-js/modules/es.typed-array.find');
  98863. _dereq_('core-js/modules/es.typed-array.find-index');
  98864. _dereq_('core-js/modules/es.typed-array.for-each');
  98865. _dereq_('core-js/modules/es.typed-array.includes');
  98866. _dereq_('core-js/modules/es.typed-array.index-of');
  98867. _dereq_('core-js/modules/es.typed-array.iterator');
  98868. _dereq_('core-js/modules/es.typed-array.join');
  98869. _dereq_('core-js/modules/es.typed-array.last-index-of');
  98870. _dereq_('core-js/modules/es.typed-array.map');
  98871. _dereq_('core-js/modules/es.typed-array.reduce');
  98872. _dereq_('core-js/modules/es.typed-array.reduce-right');
  98873. _dereq_('core-js/modules/es.typed-array.reverse');
  98874. _dereq_('core-js/modules/es.typed-array.set');
  98875. _dereq_('core-js/modules/es.typed-array.slice');
  98876. _dereq_('core-js/modules/es.typed-array.some');
  98877. _dereq_('core-js/modules/es.typed-array.sort');
  98878. _dereq_('core-js/modules/es.typed-array.subarray');
  98879. _dereq_('core-js/modules/es.typed-array.to-locale-string');
  98880. _dereq_('core-js/modules/es.typed-array.to-string');
  98881. _dereq_('core-js/modules/web.dom-collections.iterator');
  98882. Object.defineProperty(exports, '__esModule', { value: true });
  98883. exports.default = void 0;
  98884. var _main = _interopRequireDefault(_dereq_('../core/main'));
  98885. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  98886. _dereq_('./p5.RenderBuffer');
  98887. function _getRequireWildcardCache() {
  98888. if (typeof WeakMap !== 'function') return null;
  98889. var cache = new WeakMap();
  98890. _getRequireWildcardCache = function _getRequireWildcardCache() {
  98891. return cache;
  98892. };
  98893. return cache;
  98894. }
  98895. function _interopRequireWildcard(obj) {
  98896. if (obj && obj.__esModule) {
  98897. return obj;
  98898. }
  98899. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  98900. return { default: obj };
  98901. }
  98902. var cache = _getRequireWildcardCache();
  98903. if (cache && cache.has(obj)) {
  98904. return cache.get(obj);
  98905. }
  98906. var newObj = {};
  98907. var hasPropertyDescriptor =
  98908. Object.defineProperty && Object.getOwnPropertyDescriptor;
  98909. for (var key in obj) {
  98910. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  98911. var desc = hasPropertyDescriptor
  98912. ? Object.getOwnPropertyDescriptor(obj, key)
  98913. : null;
  98914. if (desc && (desc.get || desc.set)) {
  98915. Object.defineProperty(newObj, key, desc);
  98916. } else {
  98917. newObj[key] = obj[key];
  98918. }
  98919. }
  98920. }
  98921. newObj.default = obj;
  98922. if (cache) {
  98923. cache.set(obj, newObj);
  98924. }
  98925. return newObj;
  98926. }
  98927. function _interopRequireDefault(obj) {
  98928. return obj && obj.__esModule ? obj : { default: obj };
  98929. }
  98930. /**
  98931. * Welcome to RendererGL Immediate Mode.
  98932. * Immediate mode is used for drawing custom shapes
  98933. * from a set of vertices. Immediate Mode is activated
  98934. * when you call <a href="#/p5/beginShape">beginShape()</a> & de-activated when you call <a href="#/p5/endShape">endShape()</a>.
  98935. * Immediate mode is a style of programming borrowed
  98936. * from OpenGL's (now-deprecated) immediate mode.
  98937. * It differs from p5.js' default, Retained Mode, which caches
  98938. * geometries and buffers on the CPU to reduce the number of webgl
  98939. * draw calls. Retained mode is more efficient & performative,
  98940. * however, Immediate Mode is useful for sketching quick
  98941. * geometric ideas.
  98942. */ /**
  98943. * Begin shape drawing. This is a helpful way of generating
  98944. * custom shapes quickly. However in WEBGL mode, application
  98945. * performance will likely drop as a result of too many calls to
  98946. * <a href="#/p5/beginShape">beginShape()</a> / <a href="#/p5/endShape">endShape()</a>. As a high performance alternative,
  98947. * please use p5.js geometry primitives.
  98948. * @private
  98949. * @method beginShape
  98950. * @param {Number} mode webgl primitives mode. beginShape supports the
  98951. * following modes:
  98952. * POINTS,LINES,LINE_STRIP,LINE_LOOP,TRIANGLES,
  98953. * TRIANGLE_STRIP, TRIANGLE_FAN and TESS(WEBGL only)
  98954. * @chainable
  98955. */ _main.default.RendererGL.prototype.beginShape = function(mode) {
  98956. this.immediateMode.shapeMode =
  98957. mode !== undefined ? mode : constants.TRIANGLE_FAN;
  98958. this.immediateMode.geometry.reset();
  98959. return this;
  98960. };
  98961. /**
  98962. * adds a vertex to be drawn in a custom Shape.
  98963. * @private
  98964. * @method vertex
  98965. * @param {Number} x x-coordinate of vertex
  98966. * @param {Number} y y-coordinate of vertex
  98967. * @param {Number} z z-coordinate of vertex
  98968. * @chainable
  98969. * @TODO implement handling of <a href="#/p5.Vector">p5.Vector</a> args
  98970. */ _main.default.RendererGL.prototype.vertex = function(x, y) {
  98971. var z, u, v;
  98972. // default to (x, y) mode: all other arugments assumed to be 0.
  98973. z = u = v = 0;
  98974. if (arguments.length === 3) {
  98975. // (x, y, z) mode: (u, v) assumed to be 0.
  98976. z = arguments[2];
  98977. } else if (arguments.length === 4) {
  98978. // (x, y, u, v) mode: z assumed to be 0.
  98979. u = arguments[2];
  98980. v = arguments[3];
  98981. } else if (arguments.length === 5) {
  98982. // (x, y, z, u, v) mode
  98983. z = arguments[2];
  98984. u = arguments[3];
  98985. v = arguments[4];
  98986. }
  98987. var vert = new _main.default.Vector(x, y, z);
  98988. this.immediateMode.geometry.vertices.push(vert);
  98989. this.immediateMode.geometry.vertexNormals.push(this._currentNormal);
  98990. var vertexColor = this.curFillColor || [0.5, 0.5, 0.5, 1.0];
  98991. this.immediateMode.geometry.vertexColors.push(
  98992. vertexColor[0],
  98993. vertexColor[1],
  98994. vertexColor[2],
  98995. vertexColor[3]
  98996. );
  98997. if (this.textureMode === constants.IMAGE) {
  98998. if (this._tex !== null) {
  98999. if (this._tex.width > 0 && this._tex.height > 0) {
  99000. u /= this._tex.width;
  99001. v /= this._tex.height;
  99002. }
  99003. } else if (this._tex === null && arguments.length >= 4) {
  99004. // Only throw this warning if custom uv's have been provided
  99005. console.warn(
  99006. 'You must first call texture() before using' +
  99007. ' vertex() with image based u and v coordinates'
  99008. );
  99009. }
  99010. }
  99011. this.immediateMode.geometry.uvs.push(u, v);
  99012. this.immediateMode._bezierVertex[0] = x;
  99013. this.immediateMode._bezierVertex[1] = y;
  99014. this.immediateMode._bezierVertex[2] = z;
  99015. this.immediateMode._quadraticVertex[0] = x;
  99016. this.immediateMode._quadraticVertex[1] = y;
  99017. this.immediateMode._quadraticVertex[2] = z;
  99018. return this;
  99019. };
  99020. /**
  99021. * Sets the normal to use for subsequent vertices.
  99022. * @method vertexNormal
  99023. * @param {Number} x
  99024. * @param {Number} y
  99025. * @param {Number} z
  99026. * @chainable
  99027. *
  99028. * @method vertexNormal
  99029. * @param {Vector} v
  99030. * @chainable
  99031. */
  99032. _main.default.RendererGL.prototype.normal = function(xorv, y, z) {
  99033. if (xorv instanceof _main.default.Vector) {
  99034. this._currentNormal = xorv;
  99035. } else {
  99036. this._currentNormal = new _main.default.Vector(xorv, y, z);
  99037. }
  99038. return this;
  99039. };
  99040. /**
  99041. * End shape drawing and render vertices to screen.
  99042. * @chainable
  99043. */
  99044. _main.default.RendererGL.prototype.endShape = function(
  99045. mode,
  99046. isCurve,
  99047. isBezier,
  99048. isQuadratic,
  99049. isContour,
  99050. shapeKind
  99051. ) {
  99052. if (this.immediateMode.shapeMode === constants.POINTS) {
  99053. this._drawPoints(
  99054. this.immediateMode.geometry.vertices,
  99055. this.immediateMode.buffers.point
  99056. );
  99057. return this;
  99058. }
  99059. this._processVertices.apply(this, arguments);
  99060. if (this._doFill) {
  99061. if (this.immediateMode.geometry.vertices.length > 1) {
  99062. this._drawImmediateFill();
  99063. }
  99064. }
  99065. if (this._doStroke) {
  99066. if (this.immediateMode.geometry.lineVertices.length > 1) {
  99067. this._drawImmediateStroke();
  99068. }
  99069. }
  99070. this.isBezier = false;
  99071. this.isQuadratic = false;
  99072. this.isCurve = false;
  99073. this.immediateMode._bezierVertex.length = 0;
  99074. this.immediateMode._quadraticVertex.length = 0;
  99075. this.immediateMode._curveVertex.length = 0;
  99076. return this;
  99077. };
  99078. /**
  99079. * Called from endShape(). This function calculates the stroke vertices for custom shapes and
  99080. * tesselates shapes when applicable.
  99081. * @private
  99082. * @param {Number} mode webgl primitives mode. beginShape supports the
  99083. * following modes:
  99084. * POINTS,LINES,LINE_STRIP,LINE_LOOP,TRIANGLES,
  99085. * TRIANGLE_STRIP, TRIANGLE_FAN and TESS(WEBGL only)
  99086. */
  99087. _main.default.RendererGL.prototype._processVertices = function(mode) {
  99088. if (this.immediateMode.geometry.vertices.length === 0) return;
  99089. var calculateStroke = this._doStroke && this.drawMode !== constants.TEXTURE;
  99090. var shouldClose = mode === constants.CLOSE;
  99091. if (calculateStroke) {
  99092. this.immediateMode.geometry.edges = this._calculateEdges(
  99093. this.immediateMode.shapeMode,
  99094. this.immediateMode.geometry.vertices,
  99095. shouldClose
  99096. );
  99097. this.immediateMode.geometry._edgesToVertices();
  99098. }
  99099. // For hollow shapes, user must set mode to TESS
  99100. var convexShape = this.immediateMode.shapeMode === constants.TESS;
  99101. // We tesselate when drawing curves or convex shapes
  99102. var shouldTess =
  99103. (this.isBezier || this.isQuadratic || this.isCurve || convexShape) &&
  99104. this.immediateMode.shapeMode !== constants.LINES;
  99105. if (shouldTess) {
  99106. this._tesselateShape();
  99107. }
  99108. };
  99109. /**
  99110. * Called from _processVertices(). This function calculates the stroke vertices for custom shapes and
  99111. * tesselates shapes when applicable.
  99112. * @private
  99113. * @returns {Array[Number]} indices for custom shape vertices indicating edges.
  99114. */
  99115. _main.default.RendererGL.prototype._calculateEdges = function(
  99116. shapeMode,
  99117. verts,
  99118. shouldClose
  99119. ) {
  99120. var res = [];
  99121. var i = 0;
  99122. switch (shapeMode) {
  99123. case constants.TRIANGLE_STRIP:
  99124. for (i = 0; i < verts.length - 2; i++) {
  99125. res.push([i, i + 1]);
  99126. res.push([i, i + 2]);
  99127. }
  99128. res.push([i, i + 1]);
  99129. break;
  99130. case constants.TRIANGLES:
  99131. for (i = 0; i < verts.length - 2; i = i + 3) {
  99132. res.push([i, i + 1]);
  99133. res.push([i + 1, i + 2]);
  99134. res.push([i + 2, i]);
  99135. }
  99136. break;
  99137. case constants.LINES:
  99138. for (i = 0; i < verts.length - 1; i = i + 2) {
  99139. res.push([i, i + 1]);
  99140. }
  99141. break;
  99142. default:
  99143. for (i = 0; i < verts.length - 1; i++) {
  99144. res.push([i, i + 1]);
  99145. }
  99146. break;
  99147. }
  99148. if (shouldClose) {
  99149. res.push([verts.length - 1, 0]);
  99150. }
  99151. return res;
  99152. };
  99153. /**
  99154. * Called from _processVertices() when applicable. This function tesselates immediateMode.geometry.
  99155. * @private
  99156. */
  99157. _main.default.RendererGL.prototype._tesselateShape = function() {
  99158. this.immediateMode.shapeMode = constants.TRIANGLES;
  99159. var contours = [
  99160. new Float32Array(this._vToNArray(this.immediateMode.geometry.vertices))
  99161. ];
  99162. var polyTriangles = this._triangulate(contours);
  99163. this.immediateMode.geometry.vertices = [];
  99164. for (
  99165. var j = 0, polyTriLength = polyTriangles.length;
  99166. j < polyTriLength;
  99167. j = j + 3
  99168. ) {
  99169. this.vertex(polyTriangles[j], polyTriangles[j + 1], polyTriangles[j + 2]);
  99170. }
  99171. };
  99172. /**
  99173. * Called from endShape(). Responsible for calculating normals, setting shader uniforms,
  99174. * enabling all appropriate buffers, applying color blend, and drawing the fill geometry.
  99175. * @private
  99176. */
  99177. _main.default.RendererGL.prototype._drawImmediateFill = function() {
  99178. var gl = this.GL;
  99179. var shader = this._getImmediateFillShader();
  99180. this._setFillUniforms(shader);
  99181. var _iteratorNormalCompletion = true;
  99182. var _didIteratorError = false;
  99183. var _iteratorError = undefined;
  99184. try {
  99185. for (
  99186. var _iterator = this.immediateMode.buffers.fill[Symbol.iterator](), _step;
  99187. !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
  99188. _iteratorNormalCompletion = true
  99189. ) {
  99190. var buff = _step.value;
  99191. buff._prepareBuffer(this.immediateMode.geometry, shader);
  99192. }
  99193. // LINE_STRIP and LINES are not used for rendering, instead
  99194. // they only indicate a way to modify vertices during the _processVertices() step
  99195. } catch (err) {
  99196. _didIteratorError = true;
  99197. _iteratorError = err;
  99198. } finally {
  99199. try {
  99200. if (!_iteratorNormalCompletion && _iterator.return != null) {
  99201. _iterator.return();
  99202. }
  99203. } finally {
  99204. if (_didIteratorError) {
  99205. throw _iteratorError;
  99206. }
  99207. }
  99208. }
  99209. if (
  99210. this.immediateMode.shapeMode === constants.LINE_STRIP ||
  99211. this.immediateMode.shapeMode === constants.LINES
  99212. ) {
  99213. this.immediateMode.shapeMode = constants.TRIANGLE_FAN;
  99214. }
  99215. this._applyColorBlend(this.curFillColor);
  99216. gl.drawArrays(
  99217. this.immediateMode.shapeMode,
  99218. 0,
  99219. this.immediateMode.geometry.vertices.length
  99220. );
  99221. shader.unbindShader();
  99222. };
  99223. /**
  99224. * Called from endShape(). Responsible for calculating normals, setting shader uniforms,
  99225. * enabling all appropriate buffers, applying color blend, and drawing the stroke geometry.
  99226. * @private
  99227. */
  99228. _main.default.RendererGL.prototype._drawImmediateStroke = function() {
  99229. var gl = this.GL;
  99230. var shader = this._getImmediateStrokeShader();
  99231. this._setStrokeUniforms(shader);
  99232. var _iteratorNormalCompletion2 = true;
  99233. var _didIteratorError2 = false;
  99234. var _iteratorError2 = undefined;
  99235. try {
  99236. for (
  99237. var _iterator2 = this.immediateMode.buffers.stroke[Symbol.iterator](),
  99238. _step2;
  99239. !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);
  99240. _iteratorNormalCompletion2 = true
  99241. ) {
  99242. var buff = _step2.value;
  99243. buff._prepareBuffer(this.immediateMode.geometry, shader);
  99244. }
  99245. } catch (err) {
  99246. _didIteratorError2 = true;
  99247. _iteratorError2 = err;
  99248. } finally {
  99249. try {
  99250. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  99251. _iterator2.return();
  99252. }
  99253. } finally {
  99254. if (_didIteratorError2) {
  99255. throw _iteratorError2;
  99256. }
  99257. }
  99258. }
  99259. this._applyColorBlend(this.curStrokeColor);
  99260. gl.drawArrays(gl.TRIANGLES, 0, this.immediateMode.geometry.lineVertices.length);
  99261. shader.unbindShader();
  99262. };
  99263. var _default = _main.default.RendererGL;
  99264. exports.default = _default;
  99265. },
  99266. {
  99267. '../core/constants': 272,
  99268. '../core/main': 283,
  99269. './p5.RenderBuffer': 334,
  99270. 'core-js/modules/es.array.fill': 168,
  99271. 'core-js/modules/es.array.iterator': 174,
  99272. 'core-js/modules/es.object.to-string': 192,
  99273. 'core-js/modules/es.string.iterator': 201,
  99274. 'core-js/modules/es.symbol': 211,
  99275. 'core-js/modules/es.symbol.description': 209,
  99276. 'core-js/modules/es.symbol.iterator': 210,
  99277. 'core-js/modules/es.typed-array.copy-within': 212,
  99278. 'core-js/modules/es.typed-array.every': 213,
  99279. 'core-js/modules/es.typed-array.fill': 214,
  99280. 'core-js/modules/es.typed-array.filter': 215,
  99281. 'core-js/modules/es.typed-array.find': 217,
  99282. 'core-js/modules/es.typed-array.find-index': 216,
  99283. 'core-js/modules/es.typed-array.float32-array': 218,
  99284. 'core-js/modules/es.typed-array.for-each': 220,
  99285. 'core-js/modules/es.typed-array.includes': 221,
  99286. 'core-js/modules/es.typed-array.index-of': 222,
  99287. 'core-js/modules/es.typed-array.iterator': 225,
  99288. 'core-js/modules/es.typed-array.join': 226,
  99289. 'core-js/modules/es.typed-array.last-index-of': 227,
  99290. 'core-js/modules/es.typed-array.map': 228,
  99291. 'core-js/modules/es.typed-array.reduce': 230,
  99292. 'core-js/modules/es.typed-array.reduce-right': 229,
  99293. 'core-js/modules/es.typed-array.reverse': 231,
  99294. 'core-js/modules/es.typed-array.set': 232,
  99295. 'core-js/modules/es.typed-array.slice': 233,
  99296. 'core-js/modules/es.typed-array.some': 234,
  99297. 'core-js/modules/es.typed-array.sort': 235,
  99298. 'core-js/modules/es.typed-array.subarray': 236,
  99299. 'core-js/modules/es.typed-array.to-locale-string': 237,
  99300. 'core-js/modules/es.typed-array.to-string': 238,
  99301. 'core-js/modules/web.dom-collections.iterator': 244
  99302. }
  99303. ],
  99304. 336: [
  99305. function(_dereq_, module, exports) {
  99306. 'use strict';
  99307. _dereq_('core-js/modules/es.symbol');
  99308. _dereq_('core-js/modules/es.symbol.description');
  99309. _dereq_('core-js/modules/es.symbol.iterator');
  99310. _dereq_('core-js/modules/es.array.fill');
  99311. _dereq_('core-js/modules/es.array.iterator');
  99312. _dereq_('core-js/modules/es.array.some');
  99313. _dereq_('core-js/modules/es.object.keys');
  99314. _dereq_('core-js/modules/es.object.to-string');
  99315. _dereq_('core-js/modules/es.string.iterator');
  99316. _dereq_('core-js/modules/es.typed-array.float32-array');
  99317. _dereq_('core-js/modules/es.typed-array.uint16-array');
  99318. _dereq_('core-js/modules/es.typed-array.uint32-array');
  99319. _dereq_('core-js/modules/es.typed-array.copy-within');
  99320. _dereq_('core-js/modules/es.typed-array.every');
  99321. _dereq_('core-js/modules/es.typed-array.fill');
  99322. _dereq_('core-js/modules/es.typed-array.filter');
  99323. _dereq_('core-js/modules/es.typed-array.find');
  99324. _dereq_('core-js/modules/es.typed-array.find-index');
  99325. _dereq_('core-js/modules/es.typed-array.for-each');
  99326. _dereq_('core-js/modules/es.typed-array.includes');
  99327. _dereq_('core-js/modules/es.typed-array.index-of');
  99328. _dereq_('core-js/modules/es.typed-array.iterator');
  99329. _dereq_('core-js/modules/es.typed-array.join');
  99330. _dereq_('core-js/modules/es.typed-array.last-index-of');
  99331. _dereq_('core-js/modules/es.typed-array.map');
  99332. _dereq_('core-js/modules/es.typed-array.reduce');
  99333. _dereq_('core-js/modules/es.typed-array.reduce-right');
  99334. _dereq_('core-js/modules/es.typed-array.reverse');
  99335. _dereq_('core-js/modules/es.typed-array.set');
  99336. _dereq_('core-js/modules/es.typed-array.slice');
  99337. _dereq_('core-js/modules/es.typed-array.some');
  99338. _dereq_('core-js/modules/es.typed-array.sort');
  99339. _dereq_('core-js/modules/es.typed-array.subarray');
  99340. _dereq_('core-js/modules/es.typed-array.to-locale-string');
  99341. _dereq_('core-js/modules/es.typed-array.to-string');
  99342. _dereq_('core-js/modules/web.dom-collections.iterator');
  99343. Object.defineProperty(exports, '__esModule', { value: true });
  99344. exports.default = void 0;
  99345. var _main = _interopRequireDefault(_dereq_('../core/main'));
  99346. _dereq_('./p5.RendererGL');
  99347. _dereq_('./p5.RenderBuffer');
  99348. function _interopRequireDefault(obj) {
  99349. return obj && obj.__esModule ? obj : { default: obj };
  99350. } //Retained Mode. The default mode for rendering 3D primitives
  99351. //in WEBGL.
  99352. var hashCount = 0;
  99353. /**
  99354. * _initBufferDefaults
  99355. * @private
  99356. * @description initializes buffer defaults. runs each time a new geometry is
  99357. * registered
  99358. * @param {String} gId key of the geometry object
  99359. * @returns {Object} a new buffer object
  99360. */
  99361. _main.default.RendererGL.prototype._initBufferDefaults = function(gId) {
  99362. this._freeBuffers(gId);
  99363. //@TODO remove this limit on hashes in retainedMode.geometry
  99364. hashCount++;
  99365. if (hashCount > 1000) {
  99366. var key = Object.keys(this.retainedMode.geometry)[0];
  99367. delete this.retainedMode.geometry[key];
  99368. hashCount--;
  99369. }
  99370. //create a new entry in our retainedMode.geometry
  99371. return (this.retainedMode.geometry[gId] = {});
  99372. };
  99373. _main.default.RendererGL.prototype._freeBuffers = function(gId) {
  99374. var buffers = this.retainedMode.geometry[gId];
  99375. if (!buffers) {
  99376. return;
  99377. }
  99378. delete this.retainedMode.geometry[gId];
  99379. hashCount--;
  99380. var gl = this.GL;
  99381. if (buffers.indexBuffer) {
  99382. gl.deleteBuffer(buffers.indexBuffer);
  99383. }
  99384. function freeBuffers(defs) {
  99385. var _iteratorNormalCompletion = true;
  99386. var _didIteratorError = false;
  99387. var _iteratorError = undefined;
  99388. try {
  99389. for (
  99390. var _iterator = defs[Symbol.iterator](), _step;
  99391. !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
  99392. _iteratorNormalCompletion = true
  99393. ) {
  99394. var def = _step.value;
  99395. if (buffers[def.dst]) {
  99396. gl.deleteBuffer(buffers[def.dst]);
  99397. buffers[def.dst] = null;
  99398. }
  99399. }
  99400. } catch (err) {
  99401. _didIteratorError = true;
  99402. _iteratorError = err;
  99403. } finally {
  99404. try {
  99405. if (!_iteratorNormalCompletion && _iterator.return != null) {
  99406. _iterator.return();
  99407. }
  99408. } finally {
  99409. if (_didIteratorError) {
  99410. throw _iteratorError;
  99411. }
  99412. }
  99413. }
  99414. }
  99415. // free all the buffers
  99416. freeBuffers(this.retainedMode.buffers.stroke);
  99417. freeBuffers(this.retainedMode.buffers.fill);
  99418. };
  99419. /**
  99420. * creates a buffers object that holds the WebGL render buffers
  99421. * for a geometry.
  99422. * @private
  99423. * @param {String} gId key of the geometry object
  99424. * @param {p5.Geometry} model contains geometry data
  99425. */
  99426. _main.default.RendererGL.prototype.createBuffers = function(gId, model) {
  99427. var gl = this.GL;
  99428. //initialize the gl buffers for our geom groups
  99429. var buffers = this._initBufferDefaults(gId);
  99430. buffers.model = model;
  99431. var indexBuffer = buffers.indexBuffer;
  99432. if (model.faces.length) {
  99433. // allocate space for faces
  99434. if (!indexBuffer) indexBuffer = buffers.indexBuffer = gl.createBuffer();
  99435. var vals = _main.default.RendererGL.prototype._flatten(model.faces);
  99436. // If any face references a vertex with an index greater than the maximum
  99437. // un-singed 16 bit integer, then we need to use a Uint32Array instead of a
  99438. // Uint32Array
  99439. var hasVertexIndicesOverMaxUInt16 = vals.some(function(v) {
  99440. return v > 65535;
  99441. });
  99442. var type = hasVertexIndicesOverMaxUInt16 ? Uint32Array : Uint16Array;
  99443. this._bindBuffer(indexBuffer, gl.ELEMENT_ARRAY_BUFFER, vals, type);
  99444. // If we're using a Uint32Array for our indexBuffer we will need to pass a
  99445. // different enum value to WebGL draw triangles. This happens in
  99446. // the _drawElements function.
  99447. buffers.indexBufferType = hasVertexIndicesOverMaxUInt16
  99448. ? gl.UNSIGNED_INT
  99449. : gl.UNSIGNED_SHORT;
  99450. // the vertex count is based on the number of faces
  99451. buffers.vertexCount = model.faces.length * 3;
  99452. } else {
  99453. // the index buffer is unused, remove it
  99454. if (indexBuffer) {
  99455. gl.deleteBuffer(indexBuffer);
  99456. buffers.indexBuffer = null;
  99457. }
  99458. // the vertex count comes directly from the model
  99459. buffers.vertexCount = model.vertices ? model.vertices.length : 0;
  99460. }
  99461. buffers.lineVertexCount = model.lineVertices ? model.lineVertices.length : 0;
  99462. return buffers;
  99463. };
  99464. /**
  99465. * Draws buffers given a geometry key ID
  99466. * @private
  99467. * @param {String} gId ID in our geom hash
  99468. * @chainable
  99469. */
  99470. _main.default.RendererGL.prototype.drawBuffers = function(gId) {
  99471. var gl = this.GL;
  99472. var geometry = this.retainedMode.geometry[gId];
  99473. if (this._doStroke && geometry.lineVertexCount > 0) {
  99474. var strokeShader = this._getRetainedStrokeShader();
  99475. this._setStrokeUniforms(strokeShader);
  99476. var _iteratorNormalCompletion2 = true;
  99477. var _didIteratorError2 = false;
  99478. var _iteratorError2 = undefined;
  99479. try {
  99480. for (
  99481. var _iterator2 = this.retainedMode.buffers.stroke[Symbol.iterator](),
  99482. _step2;
  99483. !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);
  99484. _iteratorNormalCompletion2 = true
  99485. ) {
  99486. var buff = _step2.value;
  99487. buff._prepareBuffer(geometry, strokeShader);
  99488. }
  99489. } catch (err) {
  99490. _didIteratorError2 = true;
  99491. _iteratorError2 = err;
  99492. } finally {
  99493. try {
  99494. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  99495. _iterator2.return();
  99496. }
  99497. } finally {
  99498. if (_didIteratorError2) {
  99499. throw _iteratorError2;
  99500. }
  99501. }
  99502. }
  99503. this._applyColorBlend(this.curStrokeColor);
  99504. this._drawArrays(gl.TRIANGLES, gId);
  99505. strokeShader.unbindShader();
  99506. }
  99507. if (this._doFill) {
  99508. var fillShader = this._getRetainedFillShader();
  99509. this._setFillUniforms(fillShader);
  99510. var _iteratorNormalCompletion3 = true;
  99511. var _didIteratorError3 = false;
  99512. var _iteratorError3 = undefined;
  99513. try {
  99514. for (
  99515. var _iterator3 = this.retainedMode.buffers.fill[Symbol.iterator](),
  99516. _step3;
  99517. !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done);
  99518. _iteratorNormalCompletion3 = true
  99519. ) {
  99520. var _buff = _step3.value;
  99521. _buff._prepareBuffer(geometry, fillShader);
  99522. }
  99523. } catch (err) {
  99524. _didIteratorError3 = true;
  99525. _iteratorError3 = err;
  99526. } finally {
  99527. try {
  99528. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  99529. _iterator3.return();
  99530. }
  99531. } finally {
  99532. if (_didIteratorError3) {
  99533. throw _iteratorError3;
  99534. }
  99535. }
  99536. }
  99537. if (geometry.indexBuffer) {
  99538. //vertex index buffer
  99539. this._bindBuffer(geometry.indexBuffer, gl.ELEMENT_ARRAY_BUFFER);
  99540. }
  99541. this._applyColorBlend(this.curFillColor);
  99542. this._drawElements(gl.TRIANGLES, gId);
  99543. fillShader.unbindShader();
  99544. }
  99545. return this;
  99546. };
  99547. /**
  99548. * Calls drawBuffers() with a scaled model/view matrix.
  99549. *
  99550. * This is used by various 3d primitive methods (in primitives.js, eg. plane,
  99551. * box, torus, etc...) to allow caching of un-scaled geometries. Those
  99552. * geometries are generally created with unit-length dimensions, cached as
  99553. * such, and then scaled appropriately in this method prior to rendering.
  99554. *
  99555. * @private
  99556. * @method drawBuffersScaled
  99557. * @param {String} gId ID in our geom hash
  99558. * @param {Number} scaleX the amount to scale in the X direction
  99559. * @param {Number} scaleY the amount to scale in the Y direction
  99560. * @param {Number} scaleZ the amount to scale in the Z direction
  99561. */
  99562. _main.default.RendererGL.prototype.drawBuffersScaled = function(
  99563. gId,
  99564. scaleX,
  99565. scaleY,
  99566. scaleZ
  99567. ) {
  99568. var uMVMatrix = this.uMVMatrix.copy();
  99569. try {
  99570. this.uMVMatrix.scale(scaleX, scaleY, scaleZ);
  99571. this.drawBuffers(gId);
  99572. } finally {
  99573. this.uMVMatrix = uMVMatrix;
  99574. }
  99575. };
  99576. _main.default.RendererGL.prototype._drawArrays = function(drawMode, gId) {
  99577. this.GL.drawArrays(
  99578. drawMode,
  99579. 0,
  99580. this.retainedMode.geometry[gId].lineVertexCount
  99581. );
  99582. return this;
  99583. };
  99584. _main.default.RendererGL.prototype._drawElements = function(drawMode, gId) {
  99585. var buffers = this.retainedMode.geometry[gId];
  99586. var gl = this.GL;
  99587. // render the fill
  99588. if (buffers.indexBuffer) {
  99589. // If this model is using a Uint32Array we need to ensure the
  99590. // OES_element_index_uint WebGL extension is enabled.
  99591. if (buffers.indexBufferType === gl.UNSIGNED_INT) {
  99592. if (!gl.getExtension('OES_element_index_uint')) {
  99593. throw new Error(
  99594. 'Unable to render a 3d model with > 65535 triangles. Your web browser does not support the WebGL Extension OES_element_index_uint.'
  99595. );
  99596. }
  99597. }
  99598. // we're drawing faces
  99599. gl.drawElements(
  99600. gl.TRIANGLES,
  99601. buffers.vertexCount,
  99602. buffers.indexBufferType,
  99603. 0
  99604. );
  99605. } else {
  99606. // drawing vertices
  99607. gl.drawArrays(drawMode || gl.TRIANGLES, 0, buffers.vertexCount);
  99608. }
  99609. };
  99610. _main.default.RendererGL.prototype._drawPoints = function(
  99611. vertices,
  99612. vertexBuffer
  99613. ) {
  99614. var gl = this.GL;
  99615. var pointShader = this._getImmediatePointShader();
  99616. this._setPointUniforms(pointShader);
  99617. this._bindBuffer(
  99618. vertexBuffer,
  99619. gl.ARRAY_BUFFER,
  99620. this._vToNArray(vertices),
  99621. Float32Array,
  99622. gl.STATIC_DRAW
  99623. );
  99624. pointShader.enableAttrib(pointShader.attributes.aPosition, 3);
  99625. gl.drawArrays(gl.Points, 0, vertices.length);
  99626. pointShader.unbindShader();
  99627. };
  99628. var _default = _main.default.RendererGL;
  99629. exports.default = _default;
  99630. },
  99631. {
  99632. '../core/main': 283,
  99633. './p5.RenderBuffer': 334,
  99634. './p5.RendererGL': 337,
  99635. 'core-js/modules/es.array.fill': 168,
  99636. 'core-js/modules/es.array.iterator': 174,
  99637. 'core-js/modules/es.array.some': 179,
  99638. 'core-js/modules/es.object.keys': 191,
  99639. 'core-js/modules/es.object.to-string': 192,
  99640. 'core-js/modules/es.string.iterator': 201,
  99641. 'core-js/modules/es.symbol': 211,
  99642. 'core-js/modules/es.symbol.description': 209,
  99643. 'core-js/modules/es.symbol.iterator': 210,
  99644. 'core-js/modules/es.typed-array.copy-within': 212,
  99645. 'core-js/modules/es.typed-array.every': 213,
  99646. 'core-js/modules/es.typed-array.fill': 214,
  99647. 'core-js/modules/es.typed-array.filter': 215,
  99648. 'core-js/modules/es.typed-array.find': 217,
  99649. 'core-js/modules/es.typed-array.find-index': 216,
  99650. 'core-js/modules/es.typed-array.float32-array': 218,
  99651. 'core-js/modules/es.typed-array.for-each': 220,
  99652. 'core-js/modules/es.typed-array.includes': 221,
  99653. 'core-js/modules/es.typed-array.index-of': 222,
  99654. 'core-js/modules/es.typed-array.iterator': 225,
  99655. 'core-js/modules/es.typed-array.join': 226,
  99656. 'core-js/modules/es.typed-array.last-index-of': 227,
  99657. 'core-js/modules/es.typed-array.map': 228,
  99658. 'core-js/modules/es.typed-array.reduce': 230,
  99659. 'core-js/modules/es.typed-array.reduce-right': 229,
  99660. 'core-js/modules/es.typed-array.reverse': 231,
  99661. 'core-js/modules/es.typed-array.set': 232,
  99662. 'core-js/modules/es.typed-array.slice': 233,
  99663. 'core-js/modules/es.typed-array.some': 234,
  99664. 'core-js/modules/es.typed-array.sort': 235,
  99665. 'core-js/modules/es.typed-array.subarray': 236,
  99666. 'core-js/modules/es.typed-array.to-locale-string': 237,
  99667. 'core-js/modules/es.typed-array.to-string': 238,
  99668. 'core-js/modules/es.typed-array.uint16-array': 239,
  99669. 'core-js/modules/es.typed-array.uint32-array': 240,
  99670. 'core-js/modules/web.dom-collections.iterator': 244
  99671. }
  99672. ],
  99673. 337: [
  99674. function(_dereq_, module, exports) {
  99675. 'use strict';
  99676. function _typeof(obj) {
  99677. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  99678. _typeof = function _typeof(obj) {
  99679. return typeof obj;
  99680. };
  99681. } else {
  99682. _typeof = function _typeof(obj) {
  99683. return obj &&
  99684. typeof Symbol === 'function' &&
  99685. obj.constructor === Symbol &&
  99686. obj !== Symbol.prototype
  99687. ? 'symbol'
  99688. : typeof obj;
  99689. };
  99690. }
  99691. return _typeof(obj);
  99692. }
  99693. _dereq_('core-js/modules/es.symbol');
  99694. _dereq_('core-js/modules/es.symbol.description');
  99695. _dereq_('core-js/modules/es.symbol.iterator');
  99696. _dereq_('core-js/modules/es.array.concat');
  99697. _dereq_('core-js/modules/es.array.fill');
  99698. _dereq_('core-js/modules/es.array.filter');
  99699. _dereq_('core-js/modules/es.array.from');
  99700. _dereq_('core-js/modules/es.array.includes');
  99701. _dereq_('core-js/modules/es.array.iterator');
  99702. _dereq_('core-js/modules/es.array.slice');
  99703. _dereq_('core-js/modules/es.object.assign');
  99704. _dereq_('core-js/modules/es.object.to-string');
  99705. _dereq_('core-js/modules/es.regexp.to-string');
  99706. _dereq_('core-js/modules/es.string.includes');
  99707. _dereq_('core-js/modules/es.string.iterator');
  99708. _dereq_('core-js/modules/es.typed-array.float32-array');
  99709. _dereq_('core-js/modules/es.typed-array.float64-array');
  99710. _dereq_('core-js/modules/es.typed-array.int16-array');
  99711. _dereq_('core-js/modules/es.typed-array.uint8-array');
  99712. _dereq_('core-js/modules/es.typed-array.uint16-array');
  99713. _dereq_('core-js/modules/es.typed-array.uint32-array');
  99714. _dereq_('core-js/modules/es.typed-array.copy-within');
  99715. _dereq_('core-js/modules/es.typed-array.every');
  99716. _dereq_('core-js/modules/es.typed-array.fill');
  99717. _dereq_('core-js/modules/es.typed-array.filter');
  99718. _dereq_('core-js/modules/es.typed-array.find');
  99719. _dereq_('core-js/modules/es.typed-array.find-index');
  99720. _dereq_('core-js/modules/es.typed-array.for-each');
  99721. _dereq_('core-js/modules/es.typed-array.includes');
  99722. _dereq_('core-js/modules/es.typed-array.index-of');
  99723. _dereq_('core-js/modules/es.typed-array.iterator');
  99724. _dereq_('core-js/modules/es.typed-array.join');
  99725. _dereq_('core-js/modules/es.typed-array.last-index-of');
  99726. _dereq_('core-js/modules/es.typed-array.map');
  99727. _dereq_('core-js/modules/es.typed-array.reduce');
  99728. _dereq_('core-js/modules/es.typed-array.reduce-right');
  99729. _dereq_('core-js/modules/es.typed-array.reverse');
  99730. _dereq_('core-js/modules/es.typed-array.set');
  99731. _dereq_('core-js/modules/es.typed-array.slice');
  99732. _dereq_('core-js/modules/es.typed-array.some');
  99733. _dereq_('core-js/modules/es.typed-array.sort');
  99734. _dereq_('core-js/modules/es.typed-array.subarray');
  99735. _dereq_('core-js/modules/es.typed-array.to-locale-string');
  99736. _dereq_('core-js/modules/es.typed-array.to-string');
  99737. _dereq_('core-js/modules/web.dom-collections.iterator');
  99738. Object.defineProperty(exports, '__esModule', { value: true });
  99739. exports.default = void 0;
  99740. var _main = _interopRequireDefault(_dereq_('../core/main'));
  99741. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  99742. var _libtess = _interopRequireDefault(_dereq_('libtess'));
  99743. _dereq_('./p5.Shader');
  99744. _dereq_('./p5.Camera');
  99745. _dereq_('../core/p5.Renderer');
  99746. _dereq_('./p5.Matrix');
  99747. var _path = _dereq_('path');
  99748. function _getRequireWildcardCache() {
  99749. if (typeof WeakMap !== 'function') return null;
  99750. var cache = new WeakMap();
  99751. _getRequireWildcardCache = function _getRequireWildcardCache() {
  99752. return cache;
  99753. };
  99754. return cache;
  99755. }
  99756. function _interopRequireWildcard(obj) {
  99757. if (obj && obj.__esModule) {
  99758. return obj;
  99759. }
  99760. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  99761. return { default: obj };
  99762. }
  99763. var cache = _getRequireWildcardCache();
  99764. if (cache && cache.has(obj)) {
  99765. return cache.get(obj);
  99766. }
  99767. var newObj = {};
  99768. var hasPropertyDescriptor =
  99769. Object.defineProperty && Object.getOwnPropertyDescriptor;
  99770. for (var key in obj) {
  99771. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  99772. var desc = hasPropertyDescriptor
  99773. ? Object.getOwnPropertyDescriptor(obj, key)
  99774. : null;
  99775. if (desc && (desc.get || desc.set)) {
  99776. Object.defineProperty(newObj, key, desc);
  99777. } else {
  99778. newObj[key] = obj[key];
  99779. }
  99780. }
  99781. }
  99782. newObj.default = obj;
  99783. if (cache) {
  99784. cache.set(obj, newObj);
  99785. }
  99786. return newObj;
  99787. }
  99788. function _interopRequireDefault(obj) {
  99789. return obj && obj.__esModule ? obj : { default: obj };
  99790. }
  99791. function _toConsumableArray(arr) {
  99792. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
  99793. }
  99794. function _nonIterableSpread() {
  99795. throw new TypeError('Invalid attempt to spread non-iterable instance');
  99796. }
  99797. function _iterableToArray(iter) {
  99798. if (
  99799. Symbol.iterator in Object(iter) ||
  99800. Object.prototype.toString.call(iter) === '[object Arguments]'
  99801. )
  99802. return Array.from(iter);
  99803. }
  99804. function _arrayWithoutHoles(arr) {
  99805. if (Array.isArray(arr)) {
  99806. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  99807. arr2[i] = arr[i];
  99808. }
  99809. return arr2;
  99810. }
  99811. }
  99812. var lightingShader =
  99813. 'precision highp float;\nprecision highp int;\n\nuniform mat4 uViewMatrix;\n\nuniform bool uUseLighting;\n\nuniform int uAmbientLightCount;\nuniform vec3 uAmbientColor[5];\n\nuniform int uDirectionalLightCount;\nuniform vec3 uLightingDirection[5];\nuniform vec3 uDirectionalDiffuseColors[5];\nuniform vec3 uDirectionalSpecularColors[5];\n\nuniform int uPointLightCount;\nuniform vec3 uPointLightLocation[5];\nuniform vec3 uPointLightDiffuseColors[5];\t\nuniform vec3 uPointLightSpecularColors[5];\n\nuniform int uSpotLightCount;\nuniform float uSpotLightAngle[5];\nuniform float uSpotLightConc[5];\nuniform vec3 uSpotLightDiffuseColors[5];\nuniform vec3 uSpotLightSpecularColors[5];\nuniform vec3 uSpotLightLocation[5];\nuniform vec3 uSpotLightDirection[5];\n\nuniform bool uSpecular;\nuniform float uShininess;\n\nuniform float uConstantAttenuation;\nuniform float uLinearAttenuation;\nuniform float uQuadraticAttenuation;\n\nconst float specularFactor = 2.0;\nconst float diffuseFactor = 0.73;\n\nstruct LightResult {\n float specular;\n float diffuse;\n};\n\nfloat _phongSpecular(\n vec3 lightDirection,\n vec3 viewDirection,\n vec3 surfaceNormal,\n float shininess) {\n\n vec3 R = reflect(lightDirection, surfaceNormal);\n return pow(max(0.0, dot(R, viewDirection)), shininess);\n}\n\nfloat _lambertDiffuse(vec3 lightDirection, vec3 surfaceNormal) {\n return max(0.0, dot(-lightDirection, surfaceNormal));\n}\n\nLightResult _light(vec3 viewDirection, vec3 normal, vec3 lightVector) {\n\n vec3 lightDir = normalize(lightVector);\n\n //compute our diffuse & specular terms\n LightResult lr;\n if (uSpecular)\n lr.specular = _phongSpecular(lightDir, viewDirection, normal, uShininess);\n lr.diffuse = _lambertDiffuse(lightDir, normal);\n return lr;\n}\n\nvoid totalLight(\n vec3 modelPosition,\n vec3 normal,\n out vec3 totalDiffuse,\n out vec3 totalSpecular\n) {\n\n totalSpecular = vec3(0.0);\n\n if (!uUseLighting) {\n totalDiffuse = vec3(1.0);\n return;\n }\n\n totalDiffuse = vec3(0.0);\n\n vec3 viewDirection = normalize(-modelPosition);\n\n for (int j = 0; j < 5; j++) {\n if (j < uDirectionalLightCount) {\n vec3 lightVector = (uViewMatrix * vec4(uLightingDirection[j], 0.0)).xyz;\n vec3 lightColor = uDirectionalDiffuseColors[j];\n vec3 specularColor = uDirectionalSpecularColors[j];\n LightResult result = _light(viewDirection, normal, lightVector);\n totalDiffuse += result.diffuse * lightColor;\n totalSpecular += result.specular * lightColor * specularColor;\n }\n\n if (j < uPointLightCount) {\n vec3 lightPosition = (uViewMatrix * vec4(uPointLightLocation[j], 1.0)).xyz;\n vec3 lightVector = modelPosition - lightPosition;\n \n //calculate attenuation\n float lightDistance = length(lightVector);\n float lightFalloff = 1.0 / (uConstantAttenuation + lightDistance * uLinearAttenuation + (lightDistance * lightDistance) * uQuadraticAttenuation);\n vec3 lightColor = lightFalloff * uPointLightDiffuseColors[j];\n vec3 specularColor = lightFalloff * uPointLightSpecularColors[j];\n\n LightResult result = _light(viewDirection, normal, lightVector);\n totalDiffuse += result.diffuse * lightColor;\n totalSpecular += result.specular * lightColor * specularColor;\n }\n\n if(j < uSpotLightCount) {\n vec3 lightPosition = (uViewMatrix * vec4(uSpotLightLocation[j], 1.0)).xyz;\n vec3 lightVector = modelPosition - lightPosition;\n \n float lightDistance = length(lightVector);\n float lightFalloff = 1.0 / (uConstantAttenuation + lightDistance * uLinearAttenuation + (lightDistance * lightDistance) * uQuadraticAttenuation);\n\n vec3 lightDirection = (uViewMatrix * vec4(uSpotLightDirection[j], 0.0)).xyz;\n float spotDot = dot(normalize(lightVector), normalize(lightDirection));\n float spotFalloff;\n if(spotDot < uSpotLightAngle[j]) {\n spotFalloff = 0.0;\n }\n else {\n spotFalloff = pow(spotDot, uSpotLightConc[j]);\n }\n lightFalloff *= spotFalloff;\n\n vec3 lightColor = uSpotLightDiffuseColors[j];\n vec3 specularColor = uSpotLightSpecularColors[j];\n \n LightResult result = _light(viewDirection, normal, lightVector);\n \n totalDiffuse += result.diffuse * lightColor * lightFalloff;\n totalSpecular += result.specular * lightColor * specularColor * lightFalloff;\n }\n }\n\n totalDiffuse *= diffuseFactor;\n totalSpecular *= specularFactor;\n}\n';
  99814. var defaultShaders = {
  99815. immediateVert:
  99816. 'attribute vec3 aPosition;\nattribute vec4 aVertexColor;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform float uResolution;\nuniform float uPointSize;\n\nvarying vec4 vColor;\nvoid main(void) {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vColor = aVertexColor;\n gl_PointSize = uPointSize;\n}\n',
  99817. vertexColorVert:
  99818. 'attribute vec3 aPosition;\nattribute vec4 aVertexColor;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nvarying vec4 vColor;\n\nvoid main(void) {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vColor = aVertexColor;\n}\n',
  99819. vertexColorFrag:
  99820. 'precision mediump float;\nvarying vec4 vColor;\nvoid main(void) {\n gl_FragColor = vColor;\n}',
  99821. normalVert:
  99822. 'attribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec2 aTexCoord;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\n\nvarying vec3 vVertexNormal;\nvarying highp vec2 vVertTexCoord;\n\nvoid main(void) {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vVertexNormal = normalize(vec3( uNormalMatrix * aNormal ));\n vVertTexCoord = aTexCoord;\n}\n',
  99823. normalFrag:
  99824. 'precision mediump float;\nvarying vec3 vVertexNormal;\nvoid main(void) {\n gl_FragColor = vec4(vVertexNormal, 1.0);\n}',
  99825. basicFrag:
  99826. 'precision mediump float;\nuniform vec4 uMaterialColor;\nvoid main(void) {\n gl_FragColor = uMaterialColor;\n}',
  99827. lightVert:
  99828. lightingShader +
  99829. '// include lighting.glgl\n\nattribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec2 aTexCoord;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\n\nvarying highp vec2 vVertTexCoord;\nvarying vec3 vDiffuseColor;\nvarying vec3 vSpecularColor;\n\nvoid main(void) {\n\n vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * viewModelPosition;\n\n vec3 vertexNormal = normalize(uNormalMatrix * aNormal);\n vVertTexCoord = aTexCoord;\n\n totalLight(viewModelPosition.xyz, vertexNormal, vDiffuseColor, vSpecularColor);\n\n for (int i = 0; i < 8; i++) {\n if (i < uAmbientLightCount) {\n vDiffuseColor += uAmbientColor[i];\n }\n }\n}\n',
  99830. lightTextureFrag:
  99831. 'precision highp float;\n\nuniform vec4 uMaterialColor;\nuniform vec4 uTint;\nuniform sampler2D uSampler;\nuniform bool isTexture;\nuniform bool uEmissive;\n\nvarying highp vec2 vVertTexCoord;\nvarying vec3 vDiffuseColor;\nvarying vec3 vSpecularColor;\n\nvoid main(void) {\n if(uEmissive && !isTexture) {\n gl_FragColor = uMaterialColor;\n }\n else {\n gl_FragColor = isTexture ? texture2D(uSampler, vVertTexCoord) * (uTint / vec4(255, 255, 255, 255)) : uMaterialColor;\n gl_FragColor.rgb = gl_FragColor.rgb * vDiffuseColor + vSpecularColor;\n }\n}',
  99832. phongVert:
  99833. 'precision highp float;\nprecision highp int;\n\nattribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec2 aTexCoord;\n\nuniform vec3 uAmbientColor[5];\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\nuniform int uAmbientLightCount;\n\nvarying vec3 vNormal;\nvarying vec2 vTexCoord;\nvarying vec3 vViewPosition;\nvarying vec3 vAmbientColor;\n\nvoid main(void) {\n\n vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0);\n\n // Pass varyings to fragment shader\n vViewPosition = viewModelPosition.xyz;\n gl_Position = uProjectionMatrix * viewModelPosition; \n\n vNormal = uNormalMatrix * aNormal;\n vTexCoord = aTexCoord;\n\n // TODO: this should be a uniform\n vAmbientColor = vec3(0.0);\n for (int i = 0; i < 5; i++) {\n if (i < uAmbientLightCount) {\n vAmbientColor += uAmbientColor[i];\n }\n }\n}\n',
  99834. phongFrag:
  99835. lightingShader +
  99836. '// include lighting.glsl\nprecision highp float;\nprecision highp int;\n\nuniform vec4 uMaterialColor;\nuniform vec4 uTint;\nuniform sampler2D uSampler;\nuniform bool isTexture;\nuniform bool uEmissive;\n\nvarying vec3 vNormal;\nvarying vec2 vTexCoord;\nvarying vec3 vViewPosition;\nvarying vec3 vAmbientColor;\n\nvoid main(void) {\n\n vec3 diffuse;\n vec3 specular;\n totalLight(vViewPosition, normalize(vNormal), diffuse, specular);\n\n if(uEmissive && !isTexture) {\n gl_FragColor = uMaterialColor;\n }\n else {\n gl_FragColor = isTexture ? texture2D(uSampler, vTexCoord) * (uTint / vec4(255, 255, 255, 255)) : uMaterialColor;\n gl_FragColor.rgb = gl_FragColor.rgb * (diffuse + vAmbientColor) + specular;\n }\n}',
  99837. fontVert:
  99838. "precision mediump float;\n\nattribute vec3 aPosition;\nattribute vec2 aTexCoord;\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nuniform vec4 uGlyphRect;\nuniform float uGlyphOffset;\n\nvarying vec2 vTexCoord;\nvarying float w;\n\nvoid main() {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n\n // scale by the size of the glyph's rectangle\n positionVec4.xy *= uGlyphRect.zw - uGlyphRect.xy;\n\n // move to the corner of the glyph\n positionVec4.xy += uGlyphRect.xy;\n\n // move to the letter's line offset\n positionVec4.x += uGlyphOffset;\n \n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vTexCoord = aTexCoord;\n w = gl_Position.w;\n}\n",
  99839. fontFrag:
  99840. "#extension GL_OES_standard_derivatives : enable\nprecision mediump float;\n\n#if 0\n // simulate integer math using floats\n\t#define int float\n\t#define ivec2 vec2\n\t#define INT(x) float(x)\n\n\tint ifloor(float v) { return floor(v); }\n\tivec2 ifloor(vec2 v) { return floor(v); }\n\n#else\n // use native integer math\n\tprecision highp int;\n\t#define INT(x) x\n\n\tint ifloor(float v) { return int(v); }\n\tint ifloor(int v) { return v; }\n\tivec2 ifloor(vec2 v) { return ivec2(v); }\n\n#endif\n\nuniform sampler2D uSamplerStrokes;\nuniform sampler2D uSamplerRowStrokes;\nuniform sampler2D uSamplerRows;\nuniform sampler2D uSamplerColStrokes;\nuniform sampler2D uSamplerCols;\n\nuniform ivec2 uStrokeImageSize;\nuniform ivec2 uCellsImageSize;\nuniform ivec2 uGridImageSize;\n\nuniform ivec2 uGridOffset;\nuniform ivec2 uGridSize;\nuniform vec4 uMaterialColor;\n\nvarying vec2 vTexCoord;\n\n// some helper functions\nint round(float v) { return ifloor(v + 0.5); }\nivec2 round(vec2 v) { return ifloor(v + 0.5); }\nfloat saturate(float v) { return clamp(v, 0.0, 1.0); }\nvec2 saturate(vec2 v) { return clamp(v, 0.0, 1.0); }\n\nint mul(float v1, int v2) {\n return ifloor(v1 * float(v2));\n}\n\nivec2 mul(vec2 v1, ivec2 v2) {\n return ifloor(v1 * vec2(v2) + 0.5);\n}\n\n// unpack a 16-bit integer from a float vec2\nint getInt16(vec2 v) {\n ivec2 iv = round(v * 255.0);\n return iv.x * INT(128) + iv.y;\n}\n\nvec2 pixelScale;\nvec2 coverage = vec2(0.0);\nvec2 weight = vec2(0.5);\nconst float minDistance = 1.0/8192.0;\nconst float hardness = 1.05; // amount of antialias\n\n// the maximum number of curves in a glyph\nconst int N = INT(250);\n\n// retrieves an indexed pixel from a sampler\nvec4 getTexel(sampler2D sampler, int pos, ivec2 size) {\n int width = size.x;\n int y = ifloor(pos / width);\n int x = pos - y * width; // pos % width\n\n return texture2D(sampler, (vec2(x, y) + 0.5) / vec2(size));\n}\n\nvoid calulateCrossings(vec2 p0, vec2 p1, vec2 p2, out vec2 C1, out vec2 C2) {\n\n // get the coefficients of the quadratic in t\n vec2 a = p0 - p1 * 2.0 + p2;\n vec2 b = p0 - p1;\n vec2 c = p0 - vTexCoord;\n\n // found out which values of 't' it crosses the axes\n vec2 surd = sqrt(max(vec2(0.0), b * b - a * c));\n vec2 t1 = ((b - surd) / a).yx;\n vec2 t2 = ((b + surd) / a).yx;\n\n // approximate straight lines to avoid rounding errors\n if (abs(a.y) < 0.001)\n t1.x = t2.x = c.y / (2.0 * b.y);\n\n if (abs(a.x) < 0.001)\n t1.y = t2.y = c.x / (2.0 * b.x);\n\n // plug into quadratic formula to find the corrdinates of the crossings\n C1 = ((a * t1 - b * 2.0) * t1 + c) * pixelScale;\n C2 = ((a * t2 - b * 2.0) * t2 + c) * pixelScale;\n}\n\nvoid coverageX(vec2 p0, vec2 p1, vec2 p2) {\n\n vec2 C1, C2;\n calulateCrossings(p0, p1, p2, C1, C2);\n\n // determine on which side of the x-axis the points lie\n bool y0 = p0.y > vTexCoord.y;\n bool y1 = p1.y > vTexCoord.y;\n bool y2 = p2.y > vTexCoord.y;\n\n // could web be under the curve (after t1)?\n if (y1 ? !y2 : y0) {\n // add the coverage for t1\n coverage.x += saturate(C1.x + 0.5);\n // calculate the anti-aliasing for t1\n weight.x = min(weight.x, abs(C1.x));\n }\n\n // are we outside the curve (after t2)?\n if (y1 ? !y0 : y2) {\n // subtract the coverage for t2\n coverage.x -= saturate(C2.x + 0.5);\n // calculate the anti-aliasing for t2\n weight.x = min(weight.x, abs(C2.x));\n }\n}\n\n// this is essentially the same as coverageX, but with the axes swapped\nvoid coverageY(vec2 p0, vec2 p1, vec2 p2) {\n\n vec2 C1, C2;\n calulateCrossings(p0, p1, p2, C1, C2);\n\n bool x0 = p0.x > vTexCoord.x;\n bool x1 = p1.x > vTexCoord.x;\n bool x2 = p2.x > vTexCoord.x;\n\n if (x1 ? !x2 : x0) {\n coverage.y -= saturate(C1.y + 0.5);\n weight.y = min(weight.y, abs(C1.y));\n }\n\n if (x1 ? !x0 : x2) {\n coverage.y += saturate(C2.y + 0.5);\n weight.y = min(weight.y, abs(C2.y));\n }\n}\n\nvoid main() {\n\n // calculate the pixel scale based on screen-coordinates\n pixelScale = hardness / fwidth(vTexCoord);\n\n // which grid cell is this pixel in?\n ivec2 gridCoord = ifloor(vTexCoord * vec2(uGridSize));\n\n // intersect curves in this row\n {\n // the index into the row info bitmap\n int rowIndex = gridCoord.y + uGridOffset.y;\n // fetch the info texel\n vec4 rowInfo = getTexel(uSamplerRows, rowIndex, uGridImageSize);\n // unpack the rowInfo\n int rowStrokeIndex = getInt16(rowInfo.xy);\n int rowStrokeCount = getInt16(rowInfo.zw);\n\n for (int iRowStroke = INT(0); iRowStroke < N; iRowStroke++) {\n if (iRowStroke >= rowStrokeCount)\n break;\n\n // each stroke is made up of 3 points: the start and control point\n // and the start of the next curve.\n // fetch the indices of this pair of strokes:\n vec4 strokeIndices = getTexel(uSamplerRowStrokes, rowStrokeIndex++, uCellsImageSize);\n\n // unpack the stroke index\n int strokePos = getInt16(strokeIndices.xy);\n\n // fetch the two strokes\n vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);\n vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);\n\n // calculate the coverage\n coverageX(stroke0.xy, stroke0.zw, stroke1.xy);\n }\n }\n\n // intersect curves in this column\n {\n int colIndex = gridCoord.x + uGridOffset.x;\n vec4 colInfo = getTexel(uSamplerCols, colIndex, uGridImageSize);\n int colStrokeIndex = getInt16(colInfo.xy);\n int colStrokeCount = getInt16(colInfo.zw);\n \n for (int iColStroke = INT(0); iColStroke < N; iColStroke++) {\n if (iColStroke >= colStrokeCount)\n break;\n\n vec4 strokeIndices = getTexel(uSamplerColStrokes, colStrokeIndex++, uCellsImageSize);\n\n int strokePos = getInt16(strokeIndices.xy);\n vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);\n vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);\n coverageY(stroke0.xy, stroke0.zw, stroke1.xy);\n }\n }\n\n weight = saturate(1.0 - weight * 2.0);\n float distance = max(weight.x + weight.y, minDistance); // manhattan approx.\n float antialias = abs(dot(coverage, weight) / distance);\n float cover = min(abs(coverage.x), abs(coverage.y));\n gl_FragColor = uMaterialColor;\n gl_FragColor.a *= saturate(max(antialias, cover));\n}",
  99841. lineVert:
  99842. "/*\n Part of the Processing project - http://processing.org\n Copyright (c) 2012-15 The Processing Foundation\n Copyright (c) 2004-12 Ben Fry and Casey Reas\n Copyright (c) 2001-04 Massachusetts Institute of Technology\n This library is free software; you can redistribute it and/or\n modify it under the terms of the GNU Lesser General Public\n License as published by the Free Software Foundation, version 2.1.\n This library is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n Lesser General Public License for more details.\n You should have received a copy of the GNU Lesser General\n Public License along with this library; if not, write to the\n Free Software Foundation, Inc., 59 Temple Place, Suite 330,\n Boston, MA 02111-1307 USA\n*/\n\n#define PROCESSING_LINE_SHADER\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform float uStrokeWeight;\n\nuniform vec4 uViewport;\nuniform int uPerspective;\n\nattribute vec4 aPosition;\nattribute vec4 aDirection;\n \nvoid main() {\n // using a scale <1 moves the lines towards the camera\n // in order to prevent popping effects due to half of\n // the line disappearing behind the geometry faces.\n vec3 scale = vec3(0.9995);\n\n vec4 posp = uModelViewMatrix * aPosition;\n vec4 posq = uModelViewMatrix * (aPosition + vec4(aDirection.xyz, 0));\n\n // Moving vertices slightly toward the camera\n // to avoid depth-fighting with the fill triangles.\n // Discussed here:\n // http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=252848 \n posp.xyz = posp.xyz * scale;\n posq.xyz = posq.xyz * scale;\n\n vec4 p = uProjectionMatrix * posp;\n vec4 q = uProjectionMatrix * posq;\n\n // formula to convert from clip space (range -1..1) to screen space (range 0..[width or height])\n // screen_p = (p.xy/p.w + <1,1>) * 0.5 * uViewport.zw\n\n // prevent division by W by transforming the tangent formula (div by 0 causes\n // the line to disappear, see https://github.com/processing/processing/issues/5183)\n // t = screen_q - screen_p\n //\n // tangent is normalized and we don't care which aDirection it points to (+-)\n // t = +- normalize( screen_q - screen_p )\n // t = +- normalize( (q.xy/q.w+<1,1>)*0.5*uViewport.zw - (p.xy/p.w+<1,1>)*0.5*uViewport.zw )\n //\n // extract common factor, <1,1> - <1,1> cancels out\n // t = +- normalize( (q.xy/q.w - p.xy/p.w) * 0.5 * uViewport.zw )\n //\n // convert to common divisor\n // t = +- normalize( ((q.xy*p.w - p.xy*q.w) / (p.w*q.w)) * 0.5 * uViewport.zw )\n //\n // remove the common scalar divisor/factor, not needed due to normalize and +-\n // (keep uViewport - can't remove because it has different components for x and y\n // and corrects for aspect ratio, see https://github.com/processing/processing/issues/5181)\n // t = +- normalize( (q.xy*p.w - p.xy*q.w) * uViewport.zw )\n\n vec2 tangent = normalize((q.xy*p.w - p.xy*q.w) * uViewport.zw);\n\n // flip tangent to normal (it's already normalized)\n vec2 normal = vec2(-tangent.y, tangent.x);\n\n float thickness = aDirection.w * uStrokeWeight;\n vec2 offset = normal * thickness / 2.0;\n\n vec2 curPerspScale;\n\n if(uPerspective == 1) {\n // Perspective ---\n // convert from world to clip by multiplying with projection scaling factor\n // to get the right thickness (see https://github.com/processing/processing/issues/5182)\n // invert Y, projections in Processing invert Y\n curPerspScale = (uProjectionMatrix * vec4(1, -1, 0, 0)).xy;\n } else {\n // No Perspective ---\n // multiply by W (to cancel out division by W later in the pipeline) and\n // convert from screen to clip (derived from clip to screen above)\n curPerspScale = p.w / (0.5 * uViewport.zw);\n }\n\n gl_Position.xy = p.xy + offset.xy * curPerspScale;\n gl_Position.zw = p.zw;\n}\n",
  99843. lineFrag:
  99844. 'precision mediump float;\nprecision mediump int;\n\nuniform vec4 uMaterialColor;\n\nvoid main() {\n gl_FragColor = uMaterialColor;\n}',
  99845. pointVert:
  99846. 'attribute vec3 aPosition;\nuniform float uPointSize;\nvarying float vStrokeWeight;\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nvoid main() {\n\tvec4 positionVec4 = vec4(aPosition, 1.0);\n\tgl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n\tgl_PointSize = uPointSize;\n\tvStrokeWeight = uPointSize;\n}',
  99847. pointFrag:
  99848. 'precision mediump float;\nprecision mediump int;\nuniform vec4 uMaterialColor;\nvarying float vStrokeWeight;\n\nvoid main(){\n\tfloat mask = 0.0;\n\n\t// make a circular mask using the gl_PointCoord (goes from 0 - 1 on a point)\n // might be able to get a nicer edge on big strokeweights with smoothstep but slightly less performant\n\n\tmask = step(0.98, length(gl_PointCoord * 2.0 - 1.0));\n\n\t// if strokeWeight is 1 or less lets just draw a square\n\t// this prevents weird artifacting from carving circles when our points are really small\n\t// if strokeWeight is larger than 1, we just use it as is\n\n\tmask = mix(0.0, mask, clamp(floor(vStrokeWeight - 0.5),0.0,1.0));\n\n\t// throw away the borders of the mask\n // otherwise we get weird alpha blending issues\n\n\tif(mask > 0.98){\n discard;\n \t}\n\n \tgl_FragColor = vec4(uMaterialColor.rgb * (1.0 - mask), uMaterialColor.a) ;\n}'
  99849. };
  99850. /**
  99851. * 3D graphics class
  99852. * @private
  99853. * @class p5.RendererGL
  99854. * @constructor
  99855. * @extends p5.Renderer
  99856. * @todo extend class to include public method for offscreen
  99857. * rendering (FBO).
  99858. */
  99859. _main.default.RendererGL = function(elt, pInst, isMainCanvas, attr) {
  99860. _main.default.Renderer.call(this, elt, pInst, isMainCanvas);
  99861. this._setAttributeDefaults(pInst);
  99862. this._initContext();
  99863. this.isP3D = true; //lets us know we're in 3d mode
  99864. // This redundant property is useful in reminding you that you are
  99865. // interacting with WebGLRenderingContext, still worth considering future removal
  99866. this.GL = this.drawingContext;
  99867. this._pInst._setProperty('drawingContext', this.drawingContext);
  99868. // erasing
  99869. this._isErasing = false;
  99870. // lights
  99871. this._enableLighting = false;
  99872. this.ambientLightColors = [];
  99873. this.specularColors = [1, 1, 1];
  99874. this.directionalLightDirections = [];
  99875. this.directionalLightDiffuseColors = [];
  99876. this.directionalLightSpecularColors = [];
  99877. this.pointLightPositions = [];
  99878. this.pointLightDiffuseColors = [];
  99879. this.pointLightSpecularColors = [];
  99880. this.spotLightPositions = [];
  99881. this.spotLightDirections = [];
  99882. this.spotLightDiffuseColors = [];
  99883. this.spotLightSpecularColors = [];
  99884. this.spotLightAngle = [];
  99885. this.spotLightConc = [];
  99886. this.drawMode = constants.FILL;
  99887. this.curFillColor = this._cachedFillStyle = [1, 1, 1, 1];
  99888. this.curStrokeColor = this._cachedStrokeStyle = [0, 0, 0, 1];
  99889. this.curBlendMode = constants.BLEND;
  99890. this._cachedBlendMode = undefined;
  99891. this.blendExt = this.GL.getExtension('EXT_blend_minmax');
  99892. this._isBlending = false;
  99893. this._useSpecularMaterial = false;
  99894. this._useEmissiveMaterial = false;
  99895. this._useNormalMaterial = false;
  99896. this._useShininess = 1;
  99897. this._tint = [255, 255, 255, 255];
  99898. // lightFalloff variables
  99899. this.constantAttenuation = 1;
  99900. this.linearAttenuation = 0;
  99901. this.quadraticAttenuation = 0;
  99902. /**
  99903. * model view, projection, & normal
  99904. * matrices
  99905. */
  99906. this.uMVMatrix = new _main.default.Matrix();
  99907. this.uPMatrix = new _main.default.Matrix();
  99908. this.uNMatrix = new _main.default.Matrix('mat3');
  99909. // Current vertex normal
  99910. this._currentNormal = new _main.default.Vector(0, 0, 1);
  99911. // Camera
  99912. this._curCamera = new _main.default.Camera(this);
  99913. this._curCamera._computeCameraDefaultSettings();
  99914. this._curCamera._setDefaultCamera();
  99915. this._defaultLightShader = undefined;
  99916. this._defaultImmediateModeShader = undefined;
  99917. this._defaultNormalShader = undefined;
  99918. this._defaultColorShader = undefined;
  99919. this._defaultPointShader = undefined;
  99920. this.userFillShader = undefined;
  99921. this.userStrokeShader = undefined;
  99922. this.userPointShader = undefined;
  99923. // Default drawing is done in Retained Mode
  99924. // Geometry and Material hashes stored here
  99925. this.retainedMode = {
  99926. geometry: {},
  99927. buffers: {
  99928. // prettier-ignore
  99929. stroke: [
  99930. new _main.default.RenderBuffer(3, 'lineVertices', 'lineVertexBuffer', 'aPosition', this, this._flatten),
  99931. new _main.default.RenderBuffer(4, 'lineNormals', 'lineNormalBuffer', 'aDirection', this, this._flatten)],
  99932. // prettier-ignore
  99933. fill: [
  99934. new _main.default.RenderBuffer(3, 'vertices', 'vertexBuffer', 'aPosition', this, this._vToNArray),
  99935. new _main.default.RenderBuffer(3, 'vertexNormals', 'normalBuffer', 'aNormal', this, this._vToNArray),
  99936. new _main.default.RenderBuffer(4, 'vertexColors', 'colorBuffer', 'aMaterialColor', this),
  99937. new _main.default.RenderBuffer(3, 'vertexAmbients', 'ambientBuffer', 'aAmbientColor', this),
  99938. //new BufferDef(3, 'vertexSpeculars', 'specularBuffer', 'aSpecularColor'),
  99939. new _main.default.RenderBuffer(2, 'uvs', 'uvBuffer', 'aTexCoord', this, this._flatten)],
  99940. // prettier-ignore
  99941. text: [
  99942. new _main.default.RenderBuffer(3, 'vertices', 'vertexBuffer', 'aPosition', this, this._vToNArray),
  99943. new _main.default.RenderBuffer(2, 'uvs', 'uvBuffer', 'aTexCoord', this, this._flatten)]
  99944. }
  99945. };
  99946. // Immediate Mode
  99947. // Geometry and Material hashes stored here
  99948. this.immediateMode = {
  99949. geometry: new _main.default.Geometry(),
  99950. shapeMode: constants.TRIANGLE_FAN,
  99951. _bezierVertex: [],
  99952. _quadraticVertex: [],
  99953. _curveVertex: [],
  99954. buffers: {
  99955. // prettier-ignore
  99956. fill: [
  99957. new _main.default.RenderBuffer(3, 'vertices', 'vertexBuffer', 'aPosition', this, this._vToNArray),
  99958. new _main.default.RenderBuffer(3, 'vertexNormals', 'normalBuffer', 'aNormal', this, this._vToNArray),
  99959. new _main.default.RenderBuffer(4, 'vertexColors', 'colorBuffer', 'aVertexColor', this),
  99960. new _main.default.RenderBuffer(3, 'vertexAmbients', 'ambientBuffer', 'aAmbientColor', this),
  99961. new _main.default.RenderBuffer(2, 'uvs', 'uvBuffer', 'aTexCoord', this, this._flatten)],
  99962. // prettier-ignore
  99963. stroke: [
  99964. new _main.default.RenderBuffer(3, 'lineVertices', 'lineVertexBuffer', 'aPosition', this, this._flatten),
  99965. new _main.default.RenderBuffer(4, 'lineNormals', 'lineNormalBuffer', 'aDirection', this, this._flatten)],
  99966. point: this.GL.createBuffer()
  99967. }
  99968. };
  99969. this.pointSize = 5.0; //default point size
  99970. this.curStrokeWeight = 1;
  99971. // array of textures created in this gl context via this.getTexture(src)
  99972. this.textures = [];
  99973. this.textureMode = constants.IMAGE;
  99974. // default wrap settings
  99975. this.textureWrapX = constants.CLAMP;
  99976. this.textureWrapY = constants.CLAMP;
  99977. this._tex = null;
  99978. this._curveTightness = 6;
  99979. // lookUpTable for coefficients needed to be calculated for bezierVertex, same are used for curveVertex
  99980. this._lookUpTableBezier = [];
  99981. // lookUpTable for coefficients needed to be calculated for quadraticVertex
  99982. this._lookUpTableQuadratic = [];
  99983. // current curveDetail in the Bezier lookUpTable
  99984. this._lutBezierDetail = 0;
  99985. // current curveDetail in the Quadratic lookUpTable
  99986. this._lutQuadraticDetail = 0;
  99987. this._tessy = this._initTessy();
  99988. this.fontInfos = {};
  99989. this._curShader = undefined;
  99990. return this;
  99991. };
  99992. _main.default.RendererGL.prototype = Object.create(
  99993. _main.default.Renderer.prototype
  99994. );
  99995. //////////////////////////////////////////////
  99996. // Setting
  99997. //////////////////////////////////////////////
  99998. _main.default.RendererGL.prototype._setAttributeDefaults = function(pInst) {
  99999. // See issue #3850, safer to enable AA in Safari
  100000. var applyAA = navigator.userAgent.toLowerCase().includes('safari');
  100001. var defaults = {
  100002. alpha: true,
  100003. depth: true,
  100004. stencil: true,
  100005. antialias: applyAA,
  100006. premultipliedAlpha: false,
  100007. preserveDrawingBuffer: true,
  100008. perPixelLighting: true
  100009. };
  100010. if (pInst._glAttributes === null) {
  100011. pInst._glAttributes = defaults;
  100012. } else {
  100013. pInst._glAttributes = Object.assign(defaults, pInst._glAttributes);
  100014. }
  100015. return;
  100016. };
  100017. _main.default.RendererGL.prototype._initContext = function() {
  100018. try {
  100019. this.drawingContext =
  100020. this.canvas.getContext('webgl', this._pInst._glAttributes) ||
  100021. this.canvas.getContext('experimental-webgl', this._pInst._glAttributes);
  100022. if (this.drawingContext === null) {
  100023. throw new Error('Error creating webgl context');
  100024. } else {
  100025. var gl = this.drawingContext;
  100026. gl.enable(gl.DEPTH_TEST);
  100027. gl.depthFunc(gl.LEQUAL);
  100028. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  100029. this._viewport = this.drawingContext.getParameter(
  100030. this.drawingContext.VIEWPORT
  100031. );
  100032. }
  100033. } catch (er) {
  100034. throw er;
  100035. }
  100036. };
  100037. //This is helper function to reset the context anytime the attributes
  100038. //are changed with setAttributes()
  100039. _main.default.RendererGL.prototype._resetContext = function(options, callback) {
  100040. var w = this.width;
  100041. var h = this.height;
  100042. var defaultId = this.canvas.id;
  100043. var isPGraphics = this._pInst instanceof _main.default.Graphics;
  100044. if (isPGraphics) {
  100045. var pg = this._pInst;
  100046. pg.canvas.parentNode.removeChild(pg.canvas);
  100047. pg.canvas = document.createElement('canvas');
  100048. var node = pg._pInst._userNode || document.body;
  100049. node.appendChild(pg.canvas);
  100050. _main.default.Element.call(pg, pg.canvas, pg._pInst);
  100051. pg.width = w;
  100052. pg.height = h;
  100053. } else {
  100054. var c = this.canvas;
  100055. if (c) {
  100056. c.parentNode.removeChild(c);
  100057. }
  100058. c = document.createElement('canvas');
  100059. c.id = defaultId;
  100060. if (this._pInst._userNode) {
  100061. this._pInst._userNode.appendChild(c);
  100062. } else {
  100063. document.body.appendChild(c);
  100064. }
  100065. this._pInst.canvas = c;
  100066. }
  100067. var renderer = new _main.default.RendererGL(
  100068. this._pInst.canvas,
  100069. this._pInst,
  100070. !isPGraphics
  100071. );
  100072. this._pInst._setProperty('_renderer', renderer);
  100073. renderer.resize(w, h);
  100074. renderer._applyDefaults();
  100075. if (!isPGraphics) {
  100076. this._pInst._elements.push(renderer);
  100077. }
  100078. if (typeof callback === 'function') {
  100079. //setTimeout with 0 forces the task to the back of the queue, this ensures that
  100080. //we finish switching out the renderer
  100081. setTimeout(function() {
  100082. callback.apply(window._renderer, options);
  100083. }, 0);
  100084. }
  100085. };
  100086. /**
  100087. * @module Rendering
  100088. * @submodule Rendering
  100089. * @for p5
  100090. */
  100091. /**
  100092. * Set attributes for the WebGL Drawing context.
  100093. * This is a way of adjusting how the WebGL
  100094. * renderer works to fine-tune the display and performance.
  100095. *
  100096. * Note that this will reinitialize the drawing context
  100097. * if called after the WebGL canvas is made.
  100098. *
  100099. * If an object is passed as the parameter, all attributes
  100100. * not declared in the object will be set to defaults.
  100101. *
  100102. * The available attributes are:
  100103. * <br>
  100104. * alpha - indicates if the canvas contains an alpha buffer
  100105. * default is true
  100106. *
  100107. * depth - indicates whether the drawing buffer has a depth buffer
  100108. * of at least 16 bits - default is true
  100109. *
  100110. * stencil - indicates whether the drawing buffer has a stencil buffer
  100111. * of at least 8 bits
  100112. *
  100113. * antialias - indicates whether or not to perform anti-aliasing
  100114. * default is false (true in Safari)
  100115. *
  100116. * premultipliedAlpha - indicates that the page compositor will assume
  100117. * the drawing buffer contains colors with pre-multiplied alpha
  100118. * default is false
  100119. *
  100120. * preserveDrawingBuffer - if true the buffers will not be cleared and
  100121. * and will preserve their values until cleared or overwritten by author
  100122. * (note that p5 clears automatically on draw loop)
  100123. * default is true
  100124. *
  100125. * perPixelLighting - if true, per-pixel lighting will be used in the
  100126. * lighting shader otherwise per-vertex lighting is used.
  100127. * default is true.
  100128. *
  100129. * @method setAttributes
  100130. * @for p5
  100131. * @param {String} key Name of attribute
  100132. * @param {Boolean} value New value of named attribute
  100133. * @example
  100134. * <div>
  100135. * <code>
  100136. * function setup() {
  100137. * createCanvas(100, 100, WEBGL);
  100138. * }
  100139. *
  100140. * function draw() {
  100141. * background(255);
  100142. * push();
  100143. * rotateZ(frameCount * 0.02);
  100144. * rotateX(frameCount * 0.02);
  100145. * rotateY(frameCount * 0.02);
  100146. * fill(0, 0, 0);
  100147. * box(50);
  100148. * pop();
  100149. * }
  100150. * </code>
  100151. * </div>
  100152. * <br>
  100153. * Now with the antialias attribute set to true.
  100154. * <br>
  100155. * <div>
  100156. * <code>
  100157. * function setup() {
  100158. * setAttributes('antialias', true);
  100159. * createCanvas(100, 100, WEBGL);
  100160. * }
  100161. *
  100162. * function draw() {
  100163. * background(255);
  100164. * push();
  100165. * rotateZ(frameCount * 0.02);
  100166. * rotateX(frameCount * 0.02);
  100167. * rotateY(frameCount * 0.02);
  100168. * fill(0, 0, 0);
  100169. * box(50);
  100170. * pop();
  100171. * }
  100172. * </code>
  100173. * </div>
  100174. *
  100175. * <div>
  100176. * <code>
  100177. * // press the mouse button to disable perPixelLighting
  100178. * function setup() {
  100179. * createCanvas(100, 100, WEBGL);
  100180. * noStroke();
  100181. * fill(255);
  100182. * }
  100183. *
  100184. * let lights = [
  100185. * { c: '#f00', t: 1.12, p: 1.91, r: 0.2 },
  100186. * { c: '#0f0', t: 1.21, p: 1.31, r: 0.2 },
  100187. * { c: '#00f', t: 1.37, p: 1.57, r: 0.2 },
  100188. * { c: '#ff0', t: 1.12, p: 1.91, r: 0.7 },
  100189. * { c: '#0ff', t: 1.21, p: 1.31, r: 0.7 },
  100190. * { c: '#f0f', t: 1.37, p: 1.57, r: 0.7 }
  100191. * ];
  100192. *
  100193. * function draw() {
  100194. * let t = millis() / 1000 + 1000;
  100195. * background(0);
  100196. * directionalLight(color('#222'), 1, 1, 1);
  100197. *
  100198. * for (let i = 0; i < lights.length; i++) {
  100199. * let light = lights[i];
  100200. * pointLight(
  100201. * color(light.c),
  100202. * p5.Vector.fromAngles(t * light.t, t * light.p, width * light.r)
  100203. * );
  100204. * }
  100205. *
  100206. * specularMaterial(255);
  100207. * sphere(width * 0.1);
  100208. *
  100209. * rotateX(t * 0.77);
  100210. * rotateY(t * 0.83);
  100211. * rotateZ(t * 0.91);
  100212. * torus(width * 0.3, width * 0.07, 24, 10);
  100213. * }
  100214. *
  100215. * function mousePressed() {
  100216. * setAttributes('perPixelLighting', false);
  100217. * noStroke();
  100218. * fill(255);
  100219. * }
  100220. * function mouseReleased() {
  100221. * setAttributes('perPixelLighting', true);
  100222. * noStroke();
  100223. * fill(255);
  100224. * }
  100225. * </code>
  100226. * </div>
  100227. *
  100228. * @alt a rotating cube with smoother edges
  100229. */
  100230. /**
  100231. * @method setAttributes
  100232. * @for p5
  100233. * @param {Object} obj object with key-value pairs
  100234. */
  100235. _main.default.prototype.setAttributes = function(key, value) {
  100236. if (typeof this._glAttributes === 'undefined') {
  100237. console.log(
  100238. 'You are trying to use setAttributes on a p5.Graphics object ' +
  100239. 'that does not use a WEBGL renderer.'
  100240. );
  100241. return;
  100242. }
  100243. var unchanged = true;
  100244. if (typeof value !== 'undefined') {
  100245. //first time modifying the attributes
  100246. if (this._glAttributes === null) {
  100247. this._glAttributes = {};
  100248. }
  100249. if (this._glAttributes[key] !== value) {
  100250. //changing value of previously altered attribute
  100251. this._glAttributes[key] = value;
  100252. unchanged = false;
  100253. }
  100254. //setting all attributes with some change
  100255. } else if (key instanceof Object) {
  100256. if (this._glAttributes !== key) {
  100257. this._glAttributes = key;
  100258. unchanged = false;
  100259. }
  100260. }
  100261. //@todo_FES
  100262. if (!this._renderer.isP3D || unchanged) {
  100263. return;
  100264. }
  100265. if (!this._setupDone) {
  100266. for (var x in this._renderer.retainedMode.geometry) {
  100267. if (this._renderer.retainedMode.geometry.hasOwnProperty(x)) {
  100268. console.error(
  100269. 'Sorry, Could not set the attributes, you need to call setAttributes() ' +
  100270. 'before calling the other drawing methods in setup()'
  100271. );
  100272. return;
  100273. }
  100274. }
  100275. }
  100276. this.push();
  100277. this._renderer._resetContext();
  100278. this.pop();
  100279. if (this._renderer._curCamera) {
  100280. this._renderer._curCamera._renderer = this._renderer;
  100281. }
  100282. };
  100283. /**
  100284. * @class p5.RendererGL
  100285. */
  100286. _main.default.RendererGL.prototype._update = function() {
  100287. // reset model view and apply initial camera transform
  100288. // (containing only look at info; no projection).
  100289. this.uMVMatrix.set(
  100290. this._curCamera.cameraMatrix.mat4[0],
  100291. this._curCamera.cameraMatrix.mat4[1],
  100292. this._curCamera.cameraMatrix.mat4[2],
  100293. this._curCamera.cameraMatrix.mat4[3],
  100294. this._curCamera.cameraMatrix.mat4[4],
  100295. this._curCamera.cameraMatrix.mat4[5],
  100296. this._curCamera.cameraMatrix.mat4[6],
  100297. this._curCamera.cameraMatrix.mat4[7],
  100298. this._curCamera.cameraMatrix.mat4[8],
  100299. this._curCamera.cameraMatrix.mat4[9],
  100300. this._curCamera.cameraMatrix.mat4[10],
  100301. this._curCamera.cameraMatrix.mat4[11],
  100302. this._curCamera.cameraMatrix.mat4[12],
  100303. this._curCamera.cameraMatrix.mat4[13],
  100304. this._curCamera.cameraMatrix.mat4[14],
  100305. this._curCamera.cameraMatrix.mat4[15]
  100306. );
  100307. // reset light data for new frame.
  100308. this.ambientLightColors.length = 0;
  100309. this.specularColors = [1, 1, 1];
  100310. this.directionalLightDirections.length = 0;
  100311. this.directionalLightDiffuseColors.length = 0;
  100312. this.directionalLightSpecularColors.length = 0;
  100313. this.pointLightPositions.length = 0;
  100314. this.pointLightDiffuseColors.length = 0;
  100315. this.pointLightSpecularColors.length = 0;
  100316. this.spotLightPositions.length = 0;
  100317. this.spotLightDirections.length = 0;
  100318. this.spotLightDiffuseColors.length = 0;
  100319. this.spotLightSpecularColors.length = 0;
  100320. this.spotLightAngle.length = 0;
  100321. this.spotLightConc.length = 0;
  100322. this._enableLighting = false;
  100323. //reset tint value for new frame
  100324. this._tint = [255, 255, 255, 255];
  100325. //Clear depth every frame
  100326. this.GL.clear(this.GL.DEPTH_BUFFER_BIT);
  100327. };
  100328. /**
  100329. * [background description]
  100330. */
  100331. _main.default.RendererGL.prototype.background = function() {
  100332. var _this$_pInst;
  100333. var _col = (_this$_pInst = this._pInst).color.apply(_this$_pInst, arguments);
  100334. var _r = _col.levels[0] / 255;
  100335. var _g = _col.levels[1] / 255;
  100336. var _b = _col.levels[2] / 255;
  100337. var _a = _col.levels[3] / 255;
  100338. this.GL.clearColor(_r, _g, _b, _a);
  100339. this.GL.clear(this.GL.COLOR_BUFFER_BIT);
  100340. };
  100341. //////////////////////////////////////////////
  100342. // COLOR
  100343. //////////////////////////////////////////////
  100344. /**
  100345. * Basic fill material for geometry with a given color
  100346. * @method fill
  100347. * @class p5.RendererGL
  100348. * @param {Number|Number[]|String|p5.Color} v1 gray value,
  100349. * red or hue value (depending on the current color mode),
  100350. * or color Array, or CSS color string
  100351. * @param {Number} [v2] green or saturation value
  100352. * @param {Number} [v3] blue or brightness value
  100353. * @param {Number} [a] opacity
  100354. * @chainable
  100355. * @example
  100356. * <div>
  100357. * <code>
  100358. * function setup() {
  100359. * createCanvas(200, 200, WEBGL);
  100360. * }
  100361. *
  100362. * function draw() {
  100363. * background(0);
  100364. * noStroke();
  100365. * fill(100, 100, 240);
  100366. * rotateX(frameCount * 0.01);
  100367. * rotateY(frameCount * 0.01);
  100368. * box(75, 75, 75);
  100369. * }
  100370. * </code>
  100371. * </div>
  100372. *
  100373. * @alt
  100374. * black canvas with purple cube spinning
  100375. */
  100376. _main.default.RendererGL.prototype.fill = function(v1, v2, v3, a) {
  100377. //see material.js for more info on color blending in webgl
  100378. var color = _main.default.prototype.color.apply(this._pInst, arguments);
  100379. this.curFillColor = color._array;
  100380. this.drawMode = constants.FILL;
  100381. this._useNormalMaterial = false;
  100382. this._tex = null;
  100383. };
  100384. /**
  100385. * Basic stroke material for geometry with a given color
  100386. * @method stroke
  100387. * @param {Number|Number[]|String|p5.Color} v1 gray value,
  100388. * red or hue value (depending on the current color mode),
  100389. * or color Array, or CSS color string
  100390. * @param {Number} [v2] green or saturation value
  100391. * @param {Number} [v3] blue or brightness value
  100392. * @param {Number} [a] opacity
  100393. * @example
  100394. * <div>
  100395. * <code>
  100396. * function setup() {
  100397. * createCanvas(200, 200, WEBGL);
  100398. * }
  100399. *
  100400. * function draw() {
  100401. * background(0);
  100402. * stroke(240, 150, 150);
  100403. * fill(100, 100, 240);
  100404. * rotateX(frameCount * 0.01);
  100405. * rotateY(frameCount * 0.01);
  100406. * box(75, 75, 75);
  100407. * }
  100408. * </code>
  100409. * </div>
  100410. *
  100411. * @alt
  100412. * black canvas with purple cube with pink outline spinning
  100413. */
  100414. _main.default.RendererGL.prototype.stroke = function(r, g, b, a) {
  100415. //@todo allow transparency in stroking currently doesn't have
  100416. //any impact and causes problems with specularMaterial
  100417. arguments[3] = 255;
  100418. var color = _main.default.prototype.color.apply(this._pInst, arguments);
  100419. this.curStrokeColor = color._array;
  100420. };
  100421. _main.default.RendererGL.prototype.strokeCap = function(cap) {
  100422. // @TODO : to be implemented
  100423. console.error('Sorry, strokeCap() is not yet implemented in WEBGL mode');
  100424. };
  100425. _main.default.RendererGL.prototype.strokeJoin = function(join) {
  100426. // @TODO : to be implemented
  100427. // https://processing.org/reference/strokeJoin_.html
  100428. console.error('Sorry, strokeJoin() is not yet implemented in WEBGL mode');
  100429. };
  100430. _main.default.RendererGL.prototype.filter = function(filterType) {
  100431. // filter can be achieved using custom shaders.
  100432. // https://github.com/aferriss/p5jsShaderExamples
  100433. // https://itp-xstory.github.io/p5js-shaders/#/
  100434. console.error('filter() does not work in WEBGL mode');
  100435. };
  100436. _main.default.RendererGL.prototype.blendMode = function(mode) {
  100437. if (
  100438. mode === constants.DARKEST ||
  100439. mode === constants.LIGHTEST ||
  100440. mode === constants.ADD ||
  100441. mode === constants.BLEND ||
  100442. mode === constants.SUBTRACT ||
  100443. mode === constants.SCREEN ||
  100444. mode === constants.EXCLUSION ||
  100445. mode === constants.REPLACE ||
  100446. mode === constants.MULTIPLY ||
  100447. mode === constants.REMOVE
  100448. )
  100449. this.curBlendMode = mode;
  100450. else if (
  100451. mode === constants.BURN ||
  100452. mode === constants.OVERLAY ||
  100453. mode === constants.HARD_LIGHT ||
  100454. mode === constants.SOFT_LIGHT ||
  100455. mode === constants.DODGE
  100456. ) {
  100457. console.warn(
  100458. 'BURN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, and DODGE only work for blendMode in 2D mode.'
  100459. );
  100460. }
  100461. };
  100462. _main.default.RendererGL.prototype.erase = function(opacityFill, opacityStroke) {
  100463. if (!this._isErasing) {
  100464. this._applyBlendMode(constants.REMOVE);
  100465. this._isErasing = true;
  100466. this._cachedFillStyle = this.curFillColor.slice();
  100467. this.curFillColor = [1, 1, 1, opacityFill / 255];
  100468. this._cachedStrokeStyle = this.curStrokeColor.slice();
  100469. this.curStrokeColor = [1, 1, 1, opacityStroke / 255];
  100470. }
  100471. };
  100472. _main.default.RendererGL.prototype.noErase = function() {
  100473. if (this._isErasing) {
  100474. this._isErasing = false;
  100475. this.curFillColor = this._cachedFillStyle.slice();
  100476. this.curStrokeColor = this._cachedStrokeStyle.slice();
  100477. this.blendMode(this._cachedBlendMode);
  100478. }
  100479. };
  100480. /**
  100481. * Change weight of stroke
  100482. * @method strokeWeight
  100483. * @param {Number} stroke weight to be used for drawing
  100484. * @example
  100485. * <div>
  100486. * <code>
  100487. * function setup() {
  100488. * createCanvas(200, 400, WEBGL);
  100489. * setAttributes('antialias', true);
  100490. * }
  100491. *
  100492. * function draw() {
  100493. * background(0);
  100494. * noStroke();
  100495. * translate(0, -100, 0);
  100496. * stroke(240, 150, 150);
  100497. * fill(100, 100, 240);
  100498. * push();
  100499. * strokeWeight(8);
  100500. * rotateX(frameCount * 0.01);
  100501. * rotateY(frameCount * 0.01);
  100502. * sphere(75);
  100503. * pop();
  100504. * push();
  100505. * translate(0, 200, 0);
  100506. * strokeWeight(1);
  100507. * rotateX(frameCount * 0.01);
  100508. * rotateY(frameCount * 0.01);
  100509. * sphere(75);
  100510. * pop();
  100511. * }
  100512. * </code>
  100513. * </div>
  100514. *
  100515. * @alt
  100516. * black canvas with two purple rotating spheres with pink
  100517. * outlines the sphere on top has much heavier outlines,
  100518. */
  100519. _main.default.RendererGL.prototype.strokeWeight = function(w) {
  100520. if (this.curStrokeWeight !== w) {
  100521. this.pointSize = w;
  100522. this.curStrokeWeight = w;
  100523. }
  100524. };
  100525. // x,y are canvas-relative (pre-scaled by _pixelDensity)
  100526. _main.default.RendererGL.prototype._getPixel = function(x, y) {
  100527. var imageData, index;
  100528. imageData = new Uint8Array(4);
  100529. // prettier-ignore
  100530. this.drawingContext.readPixels(
  100531. x, y, 1, 1,
  100532. this.drawingContext.RGBA, this.drawingContext.UNSIGNED_BYTE,
  100533. imageData);
  100534. index = 0;
  100535. return [
  100536. imageData[index + 0],
  100537. imageData[index + 1],
  100538. imageData[index + 2],
  100539. imageData[index + 3]
  100540. ];
  100541. };
  100542. /**
  100543. * Loads the pixels data for this canvas into the pixels[] attribute.
  100544. * Note that updatePixels() and set() do not work.
  100545. * Any pixel manipulation must be done directly to the pixels[] array.
  100546. *
  100547. * @private
  100548. * @method loadPixels
  100549. */
  100550. _main.default.RendererGL.prototype.loadPixels = function() {
  100551. var pixelsState = this._pixelsState;
  100552. //@todo_FES
  100553. if (this._pInst._glAttributes.preserveDrawingBuffer !== true) {
  100554. console.log(
  100555. 'loadPixels only works in WebGL when preserveDrawingBuffer ' + 'is true.'
  100556. );
  100557. return;
  100558. }
  100559. //if there isn't a renderer-level temporary pixels buffer
  100560. //make a new one
  100561. var pixels = pixelsState.pixels;
  100562. var len = this.GL.drawingBufferWidth * this.GL.drawingBufferHeight * 4;
  100563. if (!(pixels instanceof Uint8Array) || pixels.length !== len) {
  100564. pixels = new Uint8Array(len);
  100565. this._pixelsState._setProperty('pixels', pixels);
  100566. }
  100567. var pd = this._pInst._pixelDensity;
  100568. // prettier-ignore
  100569. this.GL.readPixels(
  100570. 0, 0, this.width * pd, this.height * pd,
  100571. this.GL.RGBA, this.GL.UNSIGNED_BYTE,
  100572. pixels);
  100573. };
  100574. //////////////////////////////////////////////
  100575. // HASH | for geometry
  100576. //////////////////////////////////////////////
  100577. _main.default.RendererGL.prototype.geometryInHash = function(gId) {
  100578. return this.retainedMode.geometry[gId] !== undefined;
  100579. };
  100580. /**
  100581. * [resize description]
  100582. * @private
  100583. * @param {Number} w [description]
  100584. * @param {Number} h [description]
  100585. */
  100586. _main.default.RendererGL.prototype.resize = function(w, h) {
  100587. _main.default.Renderer.prototype.resize.call(this, w, h);
  100588. this.GL.viewport(0, 0, this.GL.drawingBufferWidth, this.GL.drawingBufferHeight);
  100589. this._viewport = this.GL.getParameter(this.GL.VIEWPORT);
  100590. this._curCamera._resize();
  100591. //resize pixels buffer
  100592. var pixelsState = this._pixelsState;
  100593. if (typeof pixelsState.pixels !== 'undefined') {
  100594. pixelsState._setProperty(
  100595. 'pixels',
  100596. new Uint8Array(this.GL.drawingBufferWidth * this.GL.drawingBufferHeight * 4)
  100597. );
  100598. }
  100599. };
  100600. /**
  100601. * clears color and depth buffers
  100602. * with r,g,b,a
  100603. * @private
  100604. * @param {Number} r normalized red val.
  100605. * @param {Number} g normalized green val.
  100606. * @param {Number} b normalized blue val.
  100607. * @param {Number} a normalized alpha val.
  100608. */
  100609. _main.default.RendererGL.prototype.clear = function() {
  100610. var _r = (arguments.length <= 0 ? undefined : arguments[0]) || 0;
  100611. var _g = (arguments.length <= 1 ? undefined : arguments[1]) || 0;
  100612. var _b = (arguments.length <= 2 ? undefined : arguments[2]) || 0;
  100613. var _a = (arguments.length <= 3 ? undefined : arguments[3]) || 0;
  100614. this.GL.clearColor(_r, _g, _b, _a);
  100615. this.GL.clear(this.GL.COLOR_BUFFER_BIT | this.GL.DEPTH_BUFFER_BIT);
  100616. };
  100617. _main.default.RendererGL.prototype.applyMatrix = function(a, b, c, d, e, f) {
  100618. if (arguments.length === 16) {
  100619. _main.default.Matrix.prototype.apply.apply(this.uMVMatrix, arguments);
  100620. } else {
  100621. // prettier-ignore
  100622. this.uMVMatrix.apply([
  100623. a, b, 0, 0,
  100624. c, d, 0, 0,
  100625. 0, 0, 1, 0,
  100626. e, f, 0, 1]);
  100627. }
  100628. };
  100629. /**
  100630. * [translate description]
  100631. * @private
  100632. * @param {Number} x [description]
  100633. * @param {Number} y [description]
  100634. * @param {Number} z [description]
  100635. * @chainable
  100636. * @todo implement handle for components or vector as args
  100637. */
  100638. _main.default.RendererGL.prototype.translate = function(x, y, z) {
  100639. if (x instanceof _main.default.Vector) {
  100640. z = x.z;
  100641. y = x.y;
  100642. x = x.x;
  100643. }
  100644. this.uMVMatrix.translate([x, y, z]);
  100645. return this;
  100646. };
  100647. /**
  100648. * Scales the Model View Matrix by a vector
  100649. * @private
  100650. * @param {Number | p5.Vector | Array} x [description]
  100651. * @param {Number} [y] y-axis scalar
  100652. * @param {Number} [z] z-axis scalar
  100653. * @chainable
  100654. */
  100655. _main.default.RendererGL.prototype.scale = function(x, y, z) {
  100656. this.uMVMatrix.scale(x, y, z);
  100657. return this;
  100658. };
  100659. _main.default.RendererGL.prototype.rotate = function(rad, axis) {
  100660. if (typeof axis === 'undefined') {
  100661. return this.rotateZ(rad);
  100662. }
  100663. _main.default.Matrix.prototype.rotate.apply(this.uMVMatrix, arguments);
  100664. return this;
  100665. };
  100666. _main.default.RendererGL.prototype.rotateX = function(rad) {
  100667. this.rotate(rad, 1, 0, 0);
  100668. return this;
  100669. };
  100670. _main.default.RendererGL.prototype.rotateY = function(rad) {
  100671. this.rotate(rad, 0, 1, 0);
  100672. return this;
  100673. };
  100674. _main.default.RendererGL.prototype.rotateZ = function(rad) {
  100675. this.rotate(rad, 0, 0, 1);
  100676. return this;
  100677. };
  100678. _main.default.RendererGL.prototype.push = function() {
  100679. // get the base renderer style
  100680. var style = _main.default.Renderer.prototype.push.apply(this);
  100681. // add webgl-specific style properties
  100682. var properties = style.properties;
  100683. properties.uMVMatrix = this.uMVMatrix.copy();
  100684. properties.uPMatrix = this.uPMatrix.copy();
  100685. properties._curCamera = this._curCamera;
  100686. // make a copy of the current camera for the push state
  100687. // this preserves any references stored using 'createCamera'
  100688. this._curCamera = this._curCamera.copy();
  100689. properties.ambientLightColors = this.ambientLightColors.slice();
  100690. properties.specularColors = this.specularColors.slice();
  100691. properties.directionalLightDirections = this.directionalLightDirections.slice();
  100692. properties.directionalLightDiffuseColors = this.directionalLightDiffuseColors.slice();
  100693. properties.directionalLightSpecularColors = this.directionalLightSpecularColors.slice();
  100694. properties.pointLightPositions = this.pointLightPositions.slice();
  100695. properties.pointLightDiffuseColors = this.pointLightDiffuseColors.slice();
  100696. properties.pointLightSpecularColors = this.pointLightSpecularColors.slice();
  100697. properties.spotLightPositions = this.spotLightPositions.slice();
  100698. properties.spotLightDirections = this.spotLightDirections.slice();
  100699. properties.spotLightDiffuseColors = this.spotLightDiffuseColors.slice();
  100700. properties.spotLightSpecularColors = this.spotLightSpecularColors.slice();
  100701. properties.spotLightAngle = this.spotLightAngle.slice();
  100702. properties.spotLightConc = this.spotLightConc.slice();
  100703. properties.userFillShader = this.userFillShader;
  100704. properties.userStrokeShader = this.userStrokeShader;
  100705. properties.userPointShader = this.userPointShader;
  100706. properties.pointSize = this.pointSize;
  100707. properties.curStrokeWeight = this.curStrokeWeight;
  100708. properties.curStrokeColor = this.curStrokeColor;
  100709. properties.curFillColor = this.curFillColor;
  100710. properties._useSpecularMaterial = this._useSpecularMaterial;
  100711. properties._useEmissiveMaterial = this._useEmissiveMaterial;
  100712. properties._useShininess = this._useShininess;
  100713. properties.constantAttenuation = this.constantAttenuation;
  100714. properties.linearAttenuation = this.linearAttenuation;
  100715. properties.quadraticAttenuation = this.quadraticAttenuation;
  100716. properties._enableLighting = this._enableLighting;
  100717. properties._useNormalMaterial = this._useNormalMaterial;
  100718. properties._tex = this._tex;
  100719. properties.drawMode = this.drawMode;
  100720. properties._currentNormal = this._currentNormal;
  100721. return style;
  100722. };
  100723. _main.default.RendererGL.prototype.resetMatrix = function() {
  100724. this.uMVMatrix = _main.default.Matrix.identity(this._pInst);
  100725. return this;
  100726. };
  100727. //////////////////////////////////////////////
  100728. // SHADER
  100729. //////////////////////////////////////////////
  100730. /*
  100731. * shaders are created and cached on a per-renderer basis,
  100732. * on the grounds that each renderer will have its own gl context
  100733. * and the shader must be valid in that context.
  100734. */
  100735. _main.default.RendererGL.prototype._getImmediateStrokeShader = function() {
  100736. // select the stroke shader to use
  100737. var stroke = this.userStrokeShader;
  100738. if (!stroke || !stroke.isStrokeShader()) {
  100739. return this._getLineShader();
  100740. }
  100741. return stroke;
  100742. };
  100743. _main.default.RendererGL.prototype._getRetainedStrokeShader =
  100744. _main.default.RendererGL.prototype._getImmediateStrokeShader;
  100745. /*
  100746. * selects which fill shader should be used based on renderer state,
  100747. * for use with begin/endShape and immediate vertex mode.
  100748. */
  100749. _main.default.RendererGL.prototype._getImmediateFillShader = function() {
  100750. var fill = this.userFillShader;
  100751. if (this._useNormalMaterial) {
  100752. if (!fill || !fill.isNormalShader()) {
  100753. return this._getNormalShader();
  100754. }
  100755. }
  100756. if (this._enableLighting) {
  100757. if (!fill || !fill.isLightShader()) {
  100758. return this._getLightShader();
  100759. }
  100760. } else if (this._tex) {
  100761. if (!fill || !fill.isTextureShader()) {
  100762. return this._getLightShader();
  100763. }
  100764. } else if (!fill /*|| !fill.isColorShader()*/) {
  100765. return this._getImmediateModeShader();
  100766. }
  100767. return fill;
  100768. };
  100769. /*
  100770. * selects which fill shader should be used based on renderer state
  100771. * for retained mode.
  100772. */
  100773. _main.default.RendererGL.prototype._getRetainedFillShader = function() {
  100774. if (this._useNormalMaterial) {
  100775. return this._getNormalShader();
  100776. }
  100777. var fill = this.userFillShader;
  100778. if (this._enableLighting) {
  100779. if (!fill || !fill.isLightShader()) {
  100780. return this._getLightShader();
  100781. }
  100782. } else if (this._tex) {
  100783. if (!fill || !fill.isTextureShader()) {
  100784. return this._getLightShader();
  100785. }
  100786. } else if (!fill /* || !fill.isColorShader()*/) {
  100787. return this._getColorShader();
  100788. }
  100789. return fill;
  100790. };
  100791. _main.default.RendererGL.prototype._getImmediatePointShader = function() {
  100792. // select the point shader to use
  100793. var point = this.userPointShader;
  100794. if (!point || !point.isPointShader()) {
  100795. return this._getPointShader();
  100796. }
  100797. return point;
  100798. };
  100799. _main.default.RendererGL.prototype._getRetainedLineShader =
  100800. _main.default.RendererGL.prototype._getImmediateLineShader;
  100801. _main.default.RendererGL.prototype._getLightShader = function() {
  100802. if (!this._defaultLightShader) {
  100803. if (this._pInst._glAttributes.perPixelLighting) {
  100804. this._defaultLightShader = new _main.default.Shader(
  100805. this,
  100806. defaultShaders.phongVert,
  100807. defaultShaders.phongFrag
  100808. );
  100809. } else {
  100810. this._defaultLightShader = new _main.default.Shader(
  100811. this,
  100812. defaultShaders.lightVert,
  100813. defaultShaders.lightTextureFrag
  100814. );
  100815. }
  100816. }
  100817. return this._defaultLightShader;
  100818. };
  100819. _main.default.RendererGL.prototype._getImmediateModeShader = function() {
  100820. if (!this._defaultImmediateModeShader) {
  100821. this._defaultImmediateModeShader = new _main.default.Shader(
  100822. this,
  100823. defaultShaders.immediateVert,
  100824. defaultShaders.vertexColorFrag
  100825. );
  100826. }
  100827. return this._defaultImmediateModeShader;
  100828. };
  100829. _main.default.RendererGL.prototype._getNormalShader = function() {
  100830. if (!this._defaultNormalShader) {
  100831. this._defaultNormalShader = new _main.default.Shader(
  100832. this,
  100833. defaultShaders.normalVert,
  100834. defaultShaders.normalFrag
  100835. );
  100836. }
  100837. return this._defaultNormalShader;
  100838. };
  100839. _main.default.RendererGL.prototype._getColorShader = function() {
  100840. if (!this._defaultColorShader) {
  100841. this._defaultColorShader = new _main.default.Shader(
  100842. this,
  100843. defaultShaders.normalVert,
  100844. defaultShaders.basicFrag
  100845. );
  100846. }
  100847. return this._defaultColorShader;
  100848. };
  100849. _main.default.RendererGL.prototype._getPointShader = function() {
  100850. if (!this._defaultPointShader) {
  100851. this._defaultPointShader = new _main.default.Shader(
  100852. this,
  100853. defaultShaders.pointVert,
  100854. defaultShaders.pointFrag
  100855. );
  100856. }
  100857. return this._defaultPointShader;
  100858. };
  100859. _main.default.RendererGL.prototype._getLineShader = function() {
  100860. if (!this._defaultLineShader) {
  100861. this._defaultLineShader = new _main.default.Shader(
  100862. this,
  100863. defaultShaders.lineVert,
  100864. defaultShaders.lineFrag
  100865. );
  100866. }
  100867. return this._defaultLineShader;
  100868. };
  100869. _main.default.RendererGL.prototype._getFontShader = function() {
  100870. if (!this._defaultFontShader) {
  100871. this.GL.getExtension('OES_standard_derivatives');
  100872. this._defaultFontShader = new _main.default.Shader(
  100873. this,
  100874. defaultShaders.fontVert,
  100875. defaultShaders.fontFrag
  100876. );
  100877. }
  100878. return this._defaultFontShader;
  100879. };
  100880. _main.default.RendererGL.prototype._getEmptyTexture = function() {
  100881. if (!this._emptyTexture) {
  100882. // a plain white texture RGBA, full alpha, single pixel.
  100883. var im = new _main.default.Image(1, 1);
  100884. im.set(0, 0, 255);
  100885. this._emptyTexture = new _main.default.Texture(this, im);
  100886. }
  100887. return this._emptyTexture;
  100888. };
  100889. _main.default.RendererGL.prototype.getTexture = function(img) {
  100890. var textures = this.textures;
  100891. var _iteratorNormalCompletion = true;
  100892. var _didIteratorError = false;
  100893. var _iteratorError = undefined;
  100894. try {
  100895. for (
  100896. var _iterator = textures[Symbol.iterator](), _step;
  100897. !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
  100898. _iteratorNormalCompletion = true
  100899. ) {
  100900. var texture = _step.value;
  100901. if (texture.src === img) return texture;
  100902. }
  100903. } catch (err) {
  100904. _didIteratorError = true;
  100905. _iteratorError = err;
  100906. } finally {
  100907. try {
  100908. if (!_iteratorNormalCompletion && _iterator.return != null) {
  100909. _iterator.return();
  100910. }
  100911. } finally {
  100912. if (_didIteratorError) {
  100913. throw _iteratorError;
  100914. }
  100915. }
  100916. }
  100917. var tex = new _main.default.Texture(this, img);
  100918. textures.push(tex);
  100919. return tex;
  100920. };
  100921. _main.default.RendererGL.prototype._setStrokeUniforms = function(strokeShader) {
  100922. strokeShader.bindShader();
  100923. // set the uniform values
  100924. strokeShader.setUniform('uMaterialColor', this.curStrokeColor);
  100925. strokeShader.setUniform('uStrokeWeight', this.curStrokeWeight);
  100926. };
  100927. _main.default.RendererGL.prototype._setFillUniforms = function(fillShader) {
  100928. fillShader.bindShader();
  100929. // TODO: optimize
  100930. fillShader.setUniform('uMaterialColor', this.curFillColor);
  100931. fillShader.setUniform('isTexture', !!this._tex);
  100932. if (this._tex) {
  100933. fillShader.setUniform('uSampler', this._tex);
  100934. }
  100935. fillShader.setUniform('uTint', this._tint);
  100936. fillShader.setUniform('uSpecular', this._useSpecularMaterial);
  100937. fillShader.setUniform('uEmissive', this._useEmissiveMaterial);
  100938. fillShader.setUniform('uShininess', this._useShininess);
  100939. fillShader.setUniform('uUseLighting', this._enableLighting);
  100940. var pointLightCount = this.pointLightDiffuseColors.length / 3;
  100941. fillShader.setUniform('uPointLightCount', pointLightCount);
  100942. fillShader.setUniform('uPointLightLocation', this.pointLightPositions);
  100943. fillShader.setUniform('uPointLightDiffuseColors', this.pointLightDiffuseColors);
  100944. fillShader.setUniform(
  100945. 'uPointLightSpecularColors',
  100946. this.pointLightSpecularColors
  100947. );
  100948. var directionalLightCount = this.directionalLightDiffuseColors.length / 3;
  100949. fillShader.setUniform('uDirectionalLightCount', directionalLightCount);
  100950. fillShader.setUniform('uLightingDirection', this.directionalLightDirections);
  100951. fillShader.setUniform(
  100952. 'uDirectionalDiffuseColors',
  100953. this.directionalLightDiffuseColors
  100954. );
  100955. fillShader.setUniform(
  100956. 'uDirectionalSpecularColors',
  100957. this.directionalLightSpecularColors
  100958. );
  100959. // TODO: sum these here...
  100960. var ambientLightCount = this.ambientLightColors.length / 3;
  100961. fillShader.setUniform('uAmbientLightCount', ambientLightCount);
  100962. fillShader.setUniform('uAmbientColor', this.ambientLightColors);
  100963. var spotLightCount = this.spotLightDiffuseColors.length / 3;
  100964. fillShader.setUniform('uSpotLightCount', spotLightCount);
  100965. fillShader.setUniform('uSpotLightAngle', this.spotLightAngle);
  100966. fillShader.setUniform('uSpotLightConc', this.spotLightConc);
  100967. fillShader.setUniform('uSpotLightDiffuseColors', this.spotLightDiffuseColors);
  100968. fillShader.setUniform('uSpotLightSpecularColors', this.spotLightSpecularColors);
  100969. fillShader.setUniform('uSpotLightLocation', this.spotLightPositions);
  100970. fillShader.setUniform('uSpotLightDirection', this.spotLightDirections);
  100971. fillShader.setUniform('uConstantAttenuation', this.constantAttenuation);
  100972. fillShader.setUniform('uLinearAttenuation', this.linearAttenuation);
  100973. fillShader.setUniform('uQuadraticAttenuation', this.quadraticAttenuation);
  100974. fillShader.bindTextures();
  100975. };
  100976. _main.default.RendererGL.prototype._setPointUniforms = function(pointShader) {
  100977. pointShader.bindShader();
  100978. // set the uniform values
  100979. pointShader.setUniform('uMaterialColor', this.curStrokeColor);
  100980. // @todo is there an instance where this isn't stroke weight?
  100981. // should be they be same var?
  100982. pointShader.setUniform(
  100983. 'uPointSize',
  100984. this.pointSize * this._pInst._pixelDensity
  100985. );
  100986. };
  100987. /* Binds a buffer to the drawing context
  100988. * when passed more than two arguments it also updates or initializes
  100989. * the data associated with the buffer
  100990. */
  100991. _main.default.RendererGL.prototype._bindBuffer = function(
  100992. buffer,
  100993. target,
  100994. values,
  100995. type,
  100996. usage
  100997. ) {
  100998. if (!target) target = this.GL.ARRAY_BUFFER;
  100999. this.GL.bindBuffer(target, buffer);
  101000. if (values !== undefined) {
  101001. var data = new (type || Float32Array)(values);
  101002. this.GL.bufferData(target, data, usage || this.GL.STATIC_DRAW);
  101003. }
  101004. };
  101005. ///////////////////////////////
  101006. //// UTILITY FUNCTIONS
  101007. //////////////////////////////
  101008. _main.default.RendererGL.prototype._arraysEqual = function(a, b) {
  101009. var aLength = a.length;
  101010. if (aLength !== b.length) return false;
  101011. for (var i = 0; i < aLength; i++) {
  101012. if (a[i] !== b[i]) return false;
  101013. }
  101014. return true;
  101015. };
  101016. _main.default.RendererGL.prototype._isTypedArray = function(arr) {
  101017. var res = false;
  101018. res = arr instanceof Float32Array;
  101019. res = arr instanceof Float64Array;
  101020. res = arr instanceof Int16Array;
  101021. res = arr instanceof Uint16Array;
  101022. res = arr instanceof Uint32Array;
  101023. return res;
  101024. };
  101025. /**
  101026. * turn a two dimensional array into one dimensional array
  101027. * @private
  101028. * @param {Array} arr 2-dimensional array
  101029. * @return {Array} 1-dimensional array
  101030. * [[1, 2, 3],[4, 5, 6]] -> [1, 2, 3, 4, 5, 6]
  101031. */
  101032. _main.default.RendererGL.prototype._flatten = function(arr) {
  101033. //when empty, return empty
  101034. if (arr.length === 0) {
  101035. return [];
  101036. } else if (arr.length > 20000) {
  101037. //big models , load slower to avoid stack overflow
  101038. //faster non-recursive flatten via axelduch
  101039. //stackoverflow.com/questions/27266550/how-to-flatten-nested-array-in-javascript
  101040. var _toString = Object.prototype.toString;
  101041. var arrayTypeStr = '[object Array]';
  101042. var result = [];
  101043. var nodes = arr.slice();
  101044. var node;
  101045. node = nodes.pop();
  101046. do {
  101047. if (_toString.call(node) === arrayTypeStr) {
  101048. nodes.push.apply(nodes, _toConsumableArray(node));
  101049. } else {
  101050. result.push(node);
  101051. }
  101052. } while (nodes.length && (node = nodes.pop()) !== undefined);
  101053. result.reverse(); // we reverse result to restore the original order
  101054. return result;
  101055. } else {
  101056. var _ref;
  101057. //otherwise if model within limits for browser
  101058. //use faster recursive loading
  101059. return (_ref = []).concat.apply(_ref, _toConsumableArray(arr));
  101060. }
  101061. };
  101062. /**
  101063. * turn a p5.Vector Array into a one dimensional number array
  101064. * @private
  101065. * @param {p5.Vector[]} arr an array of p5.Vector
  101066. * @return {Number[]} a one dimensional array of numbers
  101067. * [p5.Vector(1, 2, 3), p5.Vector(4, 5, 6)] ->
  101068. * [1, 2, 3, 4, 5, 6]
  101069. */
  101070. _main.default.RendererGL.prototype._vToNArray = function(arr) {
  101071. var ret = [];
  101072. var _iteratorNormalCompletion2 = true;
  101073. var _didIteratorError2 = false;
  101074. var _iteratorError2 = undefined;
  101075. try {
  101076. for (
  101077. var _iterator2 = arr[Symbol.iterator](), _step2;
  101078. !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);
  101079. _iteratorNormalCompletion2 = true
  101080. ) {
  101081. var item = _step2.value;
  101082. ret.push(item.x, item.y, item.z);
  101083. }
  101084. } catch (err) {
  101085. _didIteratorError2 = true;
  101086. _iteratorError2 = err;
  101087. } finally {
  101088. try {
  101089. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  101090. _iterator2.return();
  101091. }
  101092. } finally {
  101093. if (_didIteratorError2) {
  101094. throw _iteratorError2;
  101095. }
  101096. }
  101097. }
  101098. return ret;
  101099. };
  101100. /**
  101101. * ensures that p5 is using a 3d renderer. throws an error if not.
  101102. */
  101103. _main.default.prototype._assert3d = function(name) {
  101104. if (!this._renderer.isP3D)
  101105. throw new Error(
  101106. ''.concat(
  101107. name,
  101108. "() is only supported in WEBGL mode. If you'd like to use 3D graphics and WebGL, see https://p5js.org/examples/form-3d-primitives.html for more information."
  101109. )
  101110. );
  101111. };
  101112. // function to initialize GLU Tesselator
  101113. _main.default.RendererGL.prototype._initTessy = function initTesselator() {
  101114. // function called for each vertex of tesselator output
  101115. function vertexCallback(data, polyVertArray) {
  101116. polyVertArray[polyVertArray.length] = data[0];
  101117. polyVertArray[polyVertArray.length] = data[1];
  101118. polyVertArray[polyVertArray.length] = data[2];
  101119. }
  101120. function begincallback(type) {
  101121. if (type !== _libtess.default.primitiveType.GL_TRIANGLES) {
  101122. console.log('expected TRIANGLES but got type: '.concat(type));
  101123. }
  101124. }
  101125. function errorcallback(errno) {
  101126. console.log('error callback');
  101127. console.log('error number: '.concat(errno));
  101128. }
  101129. // callback for when segments intersect and must be split
  101130. function combinecallback(coords, data, weight) {
  101131. return [coords[0], coords[1], coords[2]];
  101132. }
  101133. function edgeCallback(flag) {
  101134. // don't really care about the flag, but need no-strip/no-fan behavior
  101135. }
  101136. var tessy = new _libtess.default.GluTesselator();
  101137. tessy.gluTessCallback(
  101138. _libtess.default.gluEnum.GLU_TESS_VERTEX_DATA,
  101139. vertexCallback
  101140. );
  101141. tessy.gluTessCallback(_libtess.default.gluEnum.GLU_TESS_BEGIN, begincallback);
  101142. tessy.gluTessCallback(_libtess.default.gluEnum.GLU_TESS_ERROR, errorcallback);
  101143. tessy.gluTessCallback(
  101144. _libtess.default.gluEnum.GLU_TESS_COMBINE,
  101145. combinecallback
  101146. );
  101147. tessy.gluTessCallback(
  101148. _libtess.default.gluEnum.GLU_TESS_EDGE_FLAG,
  101149. edgeCallback
  101150. );
  101151. return tessy;
  101152. };
  101153. _main.default.RendererGL.prototype._triangulate = function(contours) {
  101154. // libtess will take 3d verts and flatten to a plane for tesselation
  101155. // since only doing 2d tesselation here, provide z=1 normal to skip
  101156. // iterating over verts only to get the same answer.
  101157. // comment out to test normal-generation code
  101158. this._tessy.gluTessNormal(0, 0, 1);
  101159. var triangleVerts = [];
  101160. this._tessy.gluTessBeginPolygon(triangleVerts);
  101161. for (var i = 0; i < contours.length; i++) {
  101162. this._tessy.gluTessBeginContour();
  101163. var contour = contours[i];
  101164. for (var j = 0; j < contour.length; j += 3) {
  101165. var coords = [contour[j], contour[j + 1], contour[j + 2]];
  101166. this._tessy.gluTessVertex(coords, coords);
  101167. }
  101168. this._tessy.gluTessEndContour();
  101169. }
  101170. // finish polygon
  101171. this._tessy.gluTessEndPolygon();
  101172. return triangleVerts;
  101173. };
  101174. // function to calculate BezierVertex Coefficients
  101175. _main.default.RendererGL.prototype._bezierCoefficients = function(t) {
  101176. var t2 = t * t;
  101177. var t3 = t2 * t;
  101178. var mt = 1 - t;
  101179. var mt2 = mt * mt;
  101180. var mt3 = mt2 * mt;
  101181. return [mt3, 3 * mt2 * t, 3 * mt * t2, t3];
  101182. };
  101183. // function to calculate QuadraticVertex Coefficients
  101184. _main.default.RendererGL.prototype._quadraticCoefficients = function(t) {
  101185. var t2 = t * t;
  101186. var mt = 1 - t;
  101187. var mt2 = mt * mt;
  101188. return [mt2, 2 * mt * t, t2];
  101189. };
  101190. // function to convert Bezier coordinates to Catmull Rom Splines
  101191. _main.default.RendererGL.prototype._bezierToCatmull = function(w) {
  101192. var p1 = w[1];
  101193. var p2 = w[1] + (w[2] - w[0]) / this._curveTightness;
  101194. var p3 = w[2] - (w[3] - w[1]) / this._curveTightness;
  101195. var p4 = w[2];
  101196. var p = [p1, p2, p3, p4];
  101197. return p;
  101198. };
  101199. var _default = _main.default.RendererGL;
  101200. exports.default = _default;
  101201. },
  101202. {
  101203. '../core/constants': 272,
  101204. '../core/main': 283,
  101205. '../core/p5.Renderer': 286,
  101206. './p5.Camera': 331,
  101207. './p5.Matrix': 333,
  101208. './p5.Shader': 338,
  101209. 'core-js/modules/es.array.concat': 166,
  101210. 'core-js/modules/es.array.fill': 168,
  101211. 'core-js/modules/es.array.filter': 169,
  101212. 'core-js/modules/es.array.from': 171,
  101213. 'core-js/modules/es.array.includes': 172,
  101214. 'core-js/modules/es.array.iterator': 174,
  101215. 'core-js/modules/es.array.slice': 178,
  101216. 'core-js/modules/es.object.assign': 188,
  101217. 'core-js/modules/es.object.to-string': 192,
  101218. 'core-js/modules/es.regexp.to-string': 197,
  101219. 'core-js/modules/es.string.includes': 200,
  101220. 'core-js/modules/es.string.iterator': 201,
  101221. 'core-js/modules/es.symbol': 211,
  101222. 'core-js/modules/es.symbol.description': 209,
  101223. 'core-js/modules/es.symbol.iterator': 210,
  101224. 'core-js/modules/es.typed-array.copy-within': 212,
  101225. 'core-js/modules/es.typed-array.every': 213,
  101226. 'core-js/modules/es.typed-array.fill': 214,
  101227. 'core-js/modules/es.typed-array.filter': 215,
  101228. 'core-js/modules/es.typed-array.find': 217,
  101229. 'core-js/modules/es.typed-array.find-index': 216,
  101230. 'core-js/modules/es.typed-array.float32-array': 218,
  101231. 'core-js/modules/es.typed-array.float64-array': 219,
  101232. 'core-js/modules/es.typed-array.for-each': 220,
  101233. 'core-js/modules/es.typed-array.includes': 221,
  101234. 'core-js/modules/es.typed-array.index-of': 222,
  101235. 'core-js/modules/es.typed-array.int16-array': 223,
  101236. 'core-js/modules/es.typed-array.iterator': 225,
  101237. 'core-js/modules/es.typed-array.join': 226,
  101238. 'core-js/modules/es.typed-array.last-index-of': 227,
  101239. 'core-js/modules/es.typed-array.map': 228,
  101240. 'core-js/modules/es.typed-array.reduce': 230,
  101241. 'core-js/modules/es.typed-array.reduce-right': 229,
  101242. 'core-js/modules/es.typed-array.reverse': 231,
  101243. 'core-js/modules/es.typed-array.set': 232,
  101244. 'core-js/modules/es.typed-array.slice': 233,
  101245. 'core-js/modules/es.typed-array.some': 234,
  101246. 'core-js/modules/es.typed-array.sort': 235,
  101247. 'core-js/modules/es.typed-array.subarray': 236,
  101248. 'core-js/modules/es.typed-array.to-locale-string': 237,
  101249. 'core-js/modules/es.typed-array.to-string': 238,
  101250. 'core-js/modules/es.typed-array.uint16-array': 239,
  101251. 'core-js/modules/es.typed-array.uint32-array': 240,
  101252. 'core-js/modules/es.typed-array.uint8-array': 241,
  101253. 'core-js/modules/web.dom-collections.iterator': 244,
  101254. libtess: 256,
  101255. path: 259
  101256. }
  101257. ],
  101258. 338: [
  101259. function(_dereq_, module, exports) {
  101260. 'use strict';
  101261. _dereq_('core-js/modules/es.symbol');
  101262. _dereq_('core-js/modules/es.symbol.description');
  101263. _dereq_('core-js/modules/es.symbol.iterator');
  101264. _dereq_('core-js/modules/es.array.index-of');
  101265. _dereq_('core-js/modules/es.array.iterator');
  101266. _dereq_('core-js/modules/es.array.slice');
  101267. _dereq_('core-js/modules/es.function.name');
  101268. _dereq_('core-js/modules/es.object.to-string');
  101269. _dereq_('core-js/modules/es.string.iterator');
  101270. _dereq_('core-js/modules/web.dom-collections.iterator');
  101271. Object.defineProperty(exports, '__esModule', { value: true });
  101272. exports.default = void 0;
  101273. var _main = _interopRequireDefault(_dereq_('../core/main'));
  101274. function _interopRequireDefault(obj) {
  101275. return obj && obj.__esModule ? obj : { default: obj };
  101276. }
  101277. /**
  101278. * This module defines the p5.Shader class
  101279. * @module Lights, Camera
  101280. * @submodule Material
  101281. * @for p5
  101282. * @requires core
  101283. */ /**
  101284. * Shader class for WEBGL Mode
  101285. * @class p5.Shader
  101286. * @constructor
  101287. * @param {p5.RendererGL} renderer an instance of p5.RendererGL that
  101288. * will provide the GL context for this new p5.Shader
  101289. * @param {String} vertSrc source code for the vertex shader (as a string)
  101290. * @param {String} fragSrc source code for the fragment shader (as a string)
  101291. */ _main.default.Shader = function(renderer, vertSrc, fragSrc) {
  101292. // TODO: adapt this to not take ids, but rather,
  101293. // to take the source for a vertex and fragment shader
  101294. // to enable custom shaders at some later date
  101295. this._renderer = renderer;
  101296. this._vertSrc = vertSrc;
  101297. this._fragSrc = fragSrc;
  101298. this._vertShader = -1;
  101299. this._fragShader = -1;
  101300. this._glProgram = 0;
  101301. this._loadedAttributes = false;
  101302. this.attributes = {};
  101303. this._loadedUniforms = false;
  101304. this.uniforms = {};
  101305. this._bound = false;
  101306. this.samplers = [];
  101307. };
  101308. /**
  101309. * Creates, compiles, and links the shader based on its
  101310. * sources for the vertex and fragment shaders (provided
  101311. * to the constructor). Populates known attributes and
  101312. * uniforms from the shader.
  101313. * @method init
  101314. * @chainable
  101315. * @private
  101316. */
  101317. _main.default.Shader.prototype.init = function() {
  101318. if (this._glProgram === 0 /* or context is stale? */) {
  101319. var gl = this._renderer.GL;
  101320. // @todo: once custom shading is allowed,
  101321. // friendly error messages should be used here to share
  101322. // compiler and linker errors.
  101323. //set up the shader by
  101324. // 1. creating and getting a gl id for the shader program,
  101325. // 2. compliling its vertex & fragment sources,
  101326. // 3. linking the vertex and fragment shaders
  101327. this._vertShader = gl.createShader(gl.VERTEX_SHADER);
  101328. //load in our default vertex shader
  101329. gl.shaderSource(this._vertShader, this._vertSrc);
  101330. gl.compileShader(this._vertShader);
  101331. // if our vertex shader failed compilation?
  101332. if (!gl.getShaderParameter(this._vertShader, gl.COMPILE_STATUS)) {
  101333. console.error(
  101334. 'Yikes! An error occurred compiling the vertex shader:'.concat(
  101335. gl.getShaderInfoLog(this._vertShader)
  101336. )
  101337. );
  101338. return null;
  101339. }
  101340. this._fragShader = gl.createShader(gl.FRAGMENT_SHADER);
  101341. //load in our material frag shader
  101342. gl.shaderSource(this._fragShader, this._fragSrc);
  101343. gl.compileShader(this._fragShader);
  101344. // if our frag shader failed compilation?
  101345. if (!gl.getShaderParameter(this._fragShader, gl.COMPILE_STATUS)) {
  101346. console.error(
  101347. 'Darn! An error occurred compiling the fragment shader:'.concat(
  101348. gl.getShaderInfoLog(this._fragShader)
  101349. )
  101350. );
  101351. return null;
  101352. }
  101353. this._glProgram = gl.createProgram();
  101354. gl.attachShader(this._glProgram, this._vertShader);
  101355. gl.attachShader(this._glProgram, this._fragShader);
  101356. gl.linkProgram(this._glProgram);
  101357. if (!gl.getProgramParameter(this._glProgram, gl.LINK_STATUS)) {
  101358. console.error(
  101359. 'Snap! Error linking shader program: '.concat(
  101360. gl.getProgramInfoLog(this._glProgram)
  101361. )
  101362. );
  101363. }
  101364. this._loadAttributes();
  101365. this._loadUniforms();
  101366. }
  101367. return this;
  101368. };
  101369. /**
  101370. * Queries the active attributes for this shader and loads
  101371. * their names and locations into the attributes array.
  101372. * @method _loadAttributes
  101373. * @private
  101374. */
  101375. _main.default.Shader.prototype._loadAttributes = function() {
  101376. if (this._loadedAttributes) {
  101377. return;
  101378. }
  101379. this.attributes = {};
  101380. var gl = this._renderer.GL;
  101381. var numAttributes = gl.getProgramParameter(
  101382. this._glProgram,
  101383. gl.ACTIVE_ATTRIBUTES
  101384. );
  101385. for (var i = 0; i < numAttributes; ++i) {
  101386. var attributeInfo = gl.getActiveAttrib(this._glProgram, i);
  101387. var name = attributeInfo.name;
  101388. var location = gl.getAttribLocation(this._glProgram, name);
  101389. var attribute = {};
  101390. attribute.name = name;
  101391. attribute.location = location;
  101392. attribute.index = i;
  101393. attribute.type = attributeInfo.type;
  101394. attribute.size = attributeInfo.size;
  101395. this.attributes[name] = attribute;
  101396. }
  101397. this._loadedAttributes = true;
  101398. };
  101399. /**
  101400. * Queries the active uniforms for this shader and loads
  101401. * their names and locations into the uniforms array.
  101402. * @method _loadUniforms
  101403. * @private
  101404. */
  101405. _main.default.Shader.prototype._loadUniforms = function() {
  101406. if (this._loadedUniforms) {
  101407. return;
  101408. }
  101409. var gl = this._renderer.GL;
  101410. // Inspect shader and cache uniform info
  101411. var numUniforms = gl.getProgramParameter(this._glProgram, gl.ACTIVE_UNIFORMS);
  101412. var samplerIndex = 0;
  101413. for (var i = 0; i < numUniforms; ++i) {
  101414. var uniformInfo = gl.getActiveUniform(this._glProgram, i);
  101415. var uniform = {};
  101416. uniform.location = gl.getUniformLocation(this._glProgram, uniformInfo.name);
  101417. uniform.size = uniformInfo.size;
  101418. var uniformName = uniformInfo.name;
  101419. //uniforms thats are arrays have their name returned as
  101420. //someUniform[0] which is a bit silly so we trim it
  101421. //off here. The size property tells us that its an array
  101422. //so we dont lose any information by doing this
  101423. if (uniformInfo.size > 1) {
  101424. uniformName = uniformName.substring(0, uniformName.indexOf('[0]'));
  101425. }
  101426. uniform.name = uniformName;
  101427. uniform.type = uniformInfo.type;
  101428. uniform._cachedData = undefined;
  101429. if (uniform.type === gl.SAMPLER_2D) {
  101430. uniform.samplerIndex = samplerIndex;
  101431. samplerIndex++;
  101432. this.samplers.push(uniform);
  101433. }
  101434. uniform.isArray =
  101435. uniform.type === gl.FLOAT_MAT3 ||
  101436. uniform.type === gl.FLOAT_MAT4 ||
  101437. uniform.type === gl.FLOAT_VEC2 ||
  101438. uniform.type === gl.FLOAT_VEC3 ||
  101439. uniform.type === gl.FLOAT_VEC4 ||
  101440. uniform.type === gl.INT_VEC2 ||
  101441. uniform.type === gl.INT_VEC3 ||
  101442. uniform.type === gl.INT_VEC4;
  101443. this.uniforms[uniformName] = uniform;
  101444. }
  101445. this._loadedUniforms = true;
  101446. };
  101447. _main.default.Shader.prototype.compile = function() {
  101448. // TODO
  101449. };
  101450. /**
  101451. * initializes (if needed) and binds the shader program.
  101452. * @method bindShader
  101453. * @private
  101454. */
  101455. _main.default.Shader.prototype.bindShader = function() {
  101456. this.init();
  101457. if (!this._bound) {
  101458. this.useProgram();
  101459. this._bound = true;
  101460. this._setMatrixUniforms();
  101461. this.setUniform('uViewport', this._renderer._viewport);
  101462. }
  101463. };
  101464. /**
  101465. * @method unbindShader
  101466. * @chainable
  101467. * @private
  101468. */
  101469. _main.default.Shader.prototype.unbindShader = function() {
  101470. if (this._bound) {
  101471. this.unbindTextures();
  101472. //this._renderer.GL.useProgram(0); ??
  101473. this._bound = false;
  101474. }
  101475. return this;
  101476. };
  101477. _main.default.Shader.prototype.bindTextures = function() {
  101478. var gl = this._renderer.GL;
  101479. var _iteratorNormalCompletion = true;
  101480. var _didIteratorError = false;
  101481. var _iteratorError = undefined;
  101482. try {
  101483. for (
  101484. var _iterator = this.samplers[Symbol.iterator](), _step;
  101485. !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
  101486. _iteratorNormalCompletion = true
  101487. ) {
  101488. var uniform = _step.value;
  101489. var tex = uniform.texture;
  101490. if (tex === undefined) {
  101491. // user hasn't yet supplied a texture for this slot.
  101492. // (or there may not be one--maybe just lighting),
  101493. // so we supply a default texture instead.
  101494. tex = this._renderer._getEmptyTexture();
  101495. }
  101496. gl.activeTexture(gl.TEXTURE0 + uniform.samplerIndex);
  101497. tex.bindTexture();
  101498. tex.update();
  101499. gl.uniform1i(uniform.location, uniform.samplerIndex);
  101500. }
  101501. } catch (err) {
  101502. _didIteratorError = true;
  101503. _iteratorError = err;
  101504. } finally {
  101505. try {
  101506. if (!_iteratorNormalCompletion && _iterator.return != null) {
  101507. _iterator.return();
  101508. }
  101509. } finally {
  101510. if (_didIteratorError) {
  101511. throw _iteratorError;
  101512. }
  101513. }
  101514. }
  101515. };
  101516. _main.default.Shader.prototype.updateTextures = function() {
  101517. var _iteratorNormalCompletion2 = true;
  101518. var _didIteratorError2 = false;
  101519. var _iteratorError2 = undefined;
  101520. try {
  101521. for (
  101522. var _iterator2 = this.samplers[Symbol.iterator](), _step2;
  101523. !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);
  101524. _iteratorNormalCompletion2 = true
  101525. ) {
  101526. var uniform = _step2.value;
  101527. var tex = uniform.texture;
  101528. if (tex) {
  101529. tex.update();
  101530. }
  101531. }
  101532. } catch (err) {
  101533. _didIteratorError2 = true;
  101534. _iteratorError2 = err;
  101535. } finally {
  101536. try {
  101537. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  101538. _iterator2.return();
  101539. }
  101540. } finally {
  101541. if (_didIteratorError2) {
  101542. throw _iteratorError2;
  101543. }
  101544. }
  101545. }
  101546. };
  101547. _main.default.Shader.prototype.unbindTextures = function() {
  101548. // TODO: migrate stuff from material.js here
  101549. // - OR - have material.js define this function
  101550. };
  101551. _main.default.Shader.prototype._setMatrixUniforms = function() {
  101552. this.setUniform('uProjectionMatrix', this._renderer.uPMatrix.mat4);
  101553. if (this.isStrokeShader()) {
  101554. if (this._renderer._curCamera.cameraType === 'default') {
  101555. // strokes scale up as they approach camera, default
  101556. this.setUniform('uPerspective', 1);
  101557. } else {
  101558. // strokes have uniform scale regardless of distance from camera
  101559. this.setUniform('uPerspective', 0);
  101560. }
  101561. }
  101562. this.setUniform('uModelViewMatrix', this._renderer.uMVMatrix.mat4);
  101563. this.setUniform('uViewMatrix', this._renderer._curCamera.cameraMatrix.mat4);
  101564. if (this.uniforms.uNormalMatrix) {
  101565. this._renderer.uNMatrix.inverseTranspose(this._renderer.uMVMatrix);
  101566. this.setUniform('uNormalMatrix', this._renderer.uNMatrix.mat3);
  101567. }
  101568. };
  101569. /**
  101570. * @method useProgram
  101571. * @chainable
  101572. * @private
  101573. */
  101574. _main.default.Shader.prototype.useProgram = function() {
  101575. var gl = this._renderer.GL;
  101576. if (this._renderer._curShader !== this) {
  101577. gl.useProgram(this._glProgram);
  101578. this._renderer._curShader = this;
  101579. }
  101580. return this;
  101581. };
  101582. /**
  101583. * Wrapper around gl.uniform functions.
  101584. * As we store uniform info in the shader we can use that
  101585. * to do type checking on the supplied data and call
  101586. * the appropriate function.
  101587. * @method setUniform
  101588. * @chainable
  101589. * @param {String} uniformName the name of the uniform in the
  101590. * shader program
  101591. * @param {Object|Number|Boolean|Number[]} data the data to be associated
  101592. * with that uniform; type varies (could be a single numerical value, array,
  101593. * matrix, or texture / sampler reference)
  101594. *
  101595. * @example
  101596. * <div modernizr='webgl'>
  101597. * <code>
  101598. * // Click within the image to toggle the value of uniforms
  101599. * // Note: for an alternative approach to the same example,
  101600. * // involving toggling between shaders please refer to:
  101601. * // https://p5js.org/reference/#/p5/shader
  101602. *
  101603. * let grad;
  101604. * let showRedGreen = false;
  101605. *
  101606. * function preload() {
  101607. * // note that we are using two instances
  101608. * // of the same vertex and fragment shaders
  101609. * grad = loadShader('assets/shader.vert', 'assets/shader-gradient.frag');
  101610. * }
  101611. *
  101612. * function setup() {
  101613. * createCanvas(100, 100, WEBGL);
  101614. * shader(grad);
  101615. * noStroke();
  101616. * }
  101617. *
  101618. * function draw() {
  101619. * // update the offset values for each scenario,
  101620. * // moving the "grad" shader in either vertical or
  101621. * // horizontal direction each with differing colors
  101622. *
  101623. * if (showRedGreen === true) {
  101624. * grad.setUniform('colorCenter', [1, 0, 0]);
  101625. * grad.setUniform('colorBackground', [0, 1, 0]);
  101626. * grad.setUniform('offset', [sin(millis() / 2000), 1]);
  101627. * } else {
  101628. * grad.setUniform('colorCenter', [1, 0.5, 0]);
  101629. * grad.setUniform('colorBackground', [0.226, 0, 0.615]);
  101630. * grad.setUniform('offset', [0, sin(millis() / 2000) + 1]);
  101631. * }
  101632. * quad(-1, -1, 1, -1, 1, 1, -1, 1);
  101633. * }
  101634. *
  101635. * function mouseClicked() {
  101636. * showRedGreen = !showRedGreen;
  101637. * }
  101638. * </code>
  101639. * </div>
  101640. *
  101641. * @alt
  101642. * canvas toggles between a circular gradient of orange and blue vertically. and a circular gradient of red and green moving horizontally when mouse is clicked/pressed.
  101643. */
  101644. _main.default.Shader.prototype.setUniform = function(uniformName, data) {
  101645. var uniform = this.uniforms[uniformName];
  101646. if (!uniform) {
  101647. return;
  101648. }
  101649. var gl = this._renderer.GL;
  101650. if (uniform.isArray) {
  101651. if (
  101652. uniform._cachedData &&
  101653. this._renderer._arraysEqual(uniform._cachedData, data)
  101654. ) {
  101655. return;
  101656. } else {
  101657. uniform._cachedData = data.slice(0);
  101658. }
  101659. } else if (uniform._cachedData && uniform._cachedData === data) {
  101660. return;
  101661. } else {
  101662. uniform._cachedData = data;
  101663. }
  101664. var location = uniform.location;
  101665. this.useProgram();
  101666. switch (uniform.type) {
  101667. case gl.BOOL:
  101668. if (data === true) {
  101669. gl.uniform1i(location, 1);
  101670. } else {
  101671. gl.uniform1i(location, 0);
  101672. }
  101673. break;
  101674. case gl.INT:
  101675. if (uniform.size > 1) {
  101676. data.length && gl.uniform1iv(location, data);
  101677. } else {
  101678. gl.uniform1i(location, data);
  101679. }
  101680. break;
  101681. case gl.FLOAT:
  101682. if (uniform.size > 1) {
  101683. data.length && gl.uniform1fv(location, data);
  101684. } else {
  101685. gl.uniform1f(location, data);
  101686. }
  101687. break;
  101688. case gl.FLOAT_MAT3:
  101689. gl.uniformMatrix3fv(location, false, data);
  101690. break;
  101691. case gl.FLOAT_MAT4:
  101692. gl.uniformMatrix4fv(location, false, data);
  101693. break;
  101694. case gl.FLOAT_VEC2:
  101695. if (uniform.size > 1) {
  101696. data.length && gl.uniform2fv(location, data);
  101697. } else {
  101698. gl.uniform2f(location, data[0], data[1]);
  101699. }
  101700. break;
  101701. case gl.FLOAT_VEC3:
  101702. if (uniform.size > 1) {
  101703. data.length && gl.uniform3fv(location, data);
  101704. } else {
  101705. gl.uniform3f(location, data[0], data[1], data[2]);
  101706. }
  101707. break;
  101708. case gl.FLOAT_VEC4:
  101709. if (uniform.size > 1) {
  101710. data.length && gl.uniform4fv(location, data);
  101711. } else {
  101712. gl.uniform4f(location, data[0], data[1], data[2], data[3]);
  101713. }
  101714. break;
  101715. case gl.INT_VEC2:
  101716. if (uniform.size > 1) {
  101717. data.length && gl.uniform2iv(location, data);
  101718. } else {
  101719. gl.uniform2i(location, data[0], data[1]);
  101720. }
  101721. break;
  101722. case gl.INT_VEC3:
  101723. if (uniform.size > 1) {
  101724. data.length && gl.uniform3iv(location, data);
  101725. } else {
  101726. gl.uniform3i(location, data[0], data[1], data[2]);
  101727. }
  101728. break;
  101729. case gl.INT_VEC4:
  101730. if (uniform.size > 1) {
  101731. data.length && gl.uniform4iv(location, data);
  101732. } else {
  101733. gl.uniform4i(location, data[0], data[1], data[2], data[3]);
  101734. }
  101735. break;
  101736. case gl.SAMPLER_2D:
  101737. gl.activeTexture(gl.TEXTURE0 + uniform.samplerIndex);
  101738. uniform.texture = this._renderer.getTexture(data);
  101739. gl.uniform1i(uniform.location, uniform.samplerIndex);
  101740. break;
  101741. //@todo complete all types
  101742. }
  101743. return this;
  101744. };
  101745. /* NONE OF THIS IS FAST OR EFFICIENT BUT BEAR WITH ME
  101746. *
  101747. * these shader "type" query methods are used by various
  101748. * facilities of the renderer to determine if changing
  101749. * the shader type for the required action (for example,
  101750. * do we need to load the default lighting shader if the
  101751. * current shader cannot handle lighting?)
  101752. *
  101753. **/
  101754. _main.default.Shader.prototype.isLightShader = function() {
  101755. return (
  101756. this.attributes.aNormal !== undefined ||
  101757. this.uniforms.uUseLighting !== undefined ||
  101758. this.uniforms.uAmbientLightCount !== undefined ||
  101759. this.uniforms.uDirectionalLightCount !== undefined ||
  101760. this.uniforms.uPointLightCount !== undefined ||
  101761. this.uniforms.uAmbientColor !== undefined ||
  101762. this.uniforms.uDirectionalDiffuseColors !== undefined ||
  101763. this.uniforms.uDirectionalSpecularColors !== undefined ||
  101764. this.uniforms.uPointLightLocation !== undefined ||
  101765. this.uniforms.uPointLightDiffuseColors !== undefined ||
  101766. this.uniforms.uPointLightSpecularColors !== undefined ||
  101767. this.uniforms.uLightingDirection !== undefined ||
  101768. this.uniforms.uSpecular !== undefined
  101769. );
  101770. };
  101771. _main.default.Shader.prototype.isNormalShader = function() {
  101772. return this.attributes.aNormal !== undefined;
  101773. };
  101774. _main.default.Shader.prototype.isTextureShader = function() {
  101775. return this.samplerIndex > 0;
  101776. };
  101777. _main.default.Shader.prototype.isColorShader = function() {
  101778. return (
  101779. this.attributes.aVertexColor !== undefined ||
  101780. this.uniforms.uMaterialColor !== undefined
  101781. );
  101782. };
  101783. _main.default.Shader.prototype.isTexLightShader = function() {
  101784. return this.isLightShader() && this.isTextureShader();
  101785. };
  101786. _main.default.Shader.prototype.isStrokeShader = function() {
  101787. return this.uniforms.uStrokeWeight !== undefined;
  101788. };
  101789. /**
  101790. * @method enableAttrib
  101791. * @chainable
  101792. * @private
  101793. */
  101794. _main.default.Shader.prototype.enableAttrib = function(
  101795. attr,
  101796. size,
  101797. type,
  101798. normalized,
  101799. stride,
  101800. offset
  101801. ) {
  101802. if (attr) {
  101803. if (
  101804. typeof IS_MINIFIED === 'undefined' &&
  101805. this.attributes[attr.name] !== attr
  101806. ) {
  101807. console.warn(
  101808. 'The attribute "'.concat(
  101809. attr.name,
  101810. '"passed to enableAttrib does not belong to this shader.'
  101811. )
  101812. );
  101813. }
  101814. var loc = attr.location;
  101815. if (loc !== -1) {
  101816. var gl = this._renderer.GL;
  101817. if (!attr.enabled) {
  101818. gl.enableVertexAttribArray(loc);
  101819. attr.enabled = true;
  101820. }
  101821. this._renderer.GL.vertexAttribPointer(
  101822. loc,
  101823. size,
  101824. type || gl.FLOAT,
  101825. normalized || false,
  101826. stride || 0,
  101827. offset || 0
  101828. );
  101829. }
  101830. }
  101831. return this;
  101832. };
  101833. var _default = _main.default.Shader;
  101834. exports.default = _default;
  101835. },
  101836. {
  101837. '../core/main': 283,
  101838. 'core-js/modules/es.array.index-of': 173,
  101839. 'core-js/modules/es.array.iterator': 174,
  101840. 'core-js/modules/es.array.slice': 178,
  101841. 'core-js/modules/es.function.name': 181,
  101842. 'core-js/modules/es.object.to-string': 192,
  101843. 'core-js/modules/es.string.iterator': 201,
  101844. 'core-js/modules/es.symbol': 211,
  101845. 'core-js/modules/es.symbol.description': 209,
  101846. 'core-js/modules/es.symbol.iterator': 210,
  101847. 'core-js/modules/web.dom-collections.iterator': 244
  101848. }
  101849. ],
  101850. 339: [
  101851. function(_dereq_, module, exports) {
  101852. 'use strict';
  101853. function _typeof(obj) {
  101854. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  101855. _typeof = function _typeof(obj) {
  101856. return typeof obj;
  101857. };
  101858. } else {
  101859. _typeof = function _typeof(obj) {
  101860. return obj &&
  101861. typeof Symbol === 'function' &&
  101862. obj.constructor === Symbol &&
  101863. obj !== Symbol.prototype
  101864. ? 'symbol'
  101865. : typeof obj;
  101866. };
  101867. }
  101868. return _typeof(obj);
  101869. }
  101870. _dereq_('core-js/modules/es.array.iterator');
  101871. _dereq_('core-js/modules/es.object.to-string');
  101872. _dereq_('core-js/modules/es.typed-array.uint8-array');
  101873. _dereq_('core-js/modules/es.typed-array.copy-within');
  101874. _dereq_('core-js/modules/es.typed-array.every');
  101875. _dereq_('core-js/modules/es.typed-array.fill');
  101876. _dereq_('core-js/modules/es.typed-array.filter');
  101877. _dereq_('core-js/modules/es.typed-array.find');
  101878. _dereq_('core-js/modules/es.typed-array.find-index');
  101879. _dereq_('core-js/modules/es.typed-array.for-each');
  101880. _dereq_('core-js/modules/es.typed-array.includes');
  101881. _dereq_('core-js/modules/es.typed-array.index-of');
  101882. _dereq_('core-js/modules/es.typed-array.iterator');
  101883. _dereq_('core-js/modules/es.typed-array.join');
  101884. _dereq_('core-js/modules/es.typed-array.last-index-of');
  101885. _dereq_('core-js/modules/es.typed-array.map');
  101886. _dereq_('core-js/modules/es.typed-array.reduce');
  101887. _dereq_('core-js/modules/es.typed-array.reduce-right');
  101888. _dereq_('core-js/modules/es.typed-array.reverse');
  101889. _dereq_('core-js/modules/es.typed-array.set');
  101890. _dereq_('core-js/modules/es.typed-array.slice');
  101891. _dereq_('core-js/modules/es.typed-array.some');
  101892. _dereq_('core-js/modules/es.typed-array.sort');
  101893. _dereq_('core-js/modules/es.typed-array.subarray');
  101894. _dereq_('core-js/modules/es.typed-array.to-locale-string');
  101895. _dereq_('core-js/modules/es.typed-array.to-string');
  101896. Object.defineProperty(exports, '__esModule', { value: true });
  101897. exports.default = void 0;
  101898. var _main = _interopRequireDefault(_dereq_('../core/main'));
  101899. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  101900. function _getRequireWildcardCache() {
  101901. if (typeof WeakMap !== 'function') return null;
  101902. var cache = new WeakMap();
  101903. _getRequireWildcardCache = function _getRequireWildcardCache() {
  101904. return cache;
  101905. };
  101906. return cache;
  101907. }
  101908. function _interopRequireWildcard(obj) {
  101909. if (obj && obj.__esModule) {
  101910. return obj;
  101911. }
  101912. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  101913. return { default: obj };
  101914. }
  101915. var cache = _getRequireWildcardCache();
  101916. if (cache && cache.has(obj)) {
  101917. return cache.get(obj);
  101918. }
  101919. var newObj = {};
  101920. var hasPropertyDescriptor =
  101921. Object.defineProperty && Object.getOwnPropertyDescriptor;
  101922. for (var key in obj) {
  101923. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  101924. var desc = hasPropertyDescriptor
  101925. ? Object.getOwnPropertyDescriptor(obj, key)
  101926. : null;
  101927. if (desc && (desc.get || desc.set)) {
  101928. Object.defineProperty(newObj, key, desc);
  101929. } else {
  101930. newObj[key] = obj[key];
  101931. }
  101932. }
  101933. }
  101934. newObj.default = obj;
  101935. if (cache) {
  101936. cache.set(obj, newObj);
  101937. }
  101938. return newObj;
  101939. }
  101940. function _interopRequireDefault(obj) {
  101941. return obj && obj.__esModule ? obj : { default: obj };
  101942. }
  101943. /**
  101944. * This module defines the p5.Texture class
  101945. * @module Lights, Camera
  101946. * @submodule Material
  101947. * @for p5
  101948. * @requires core
  101949. */ /**
  101950. * Texture class for WEBGL Mode
  101951. * @private
  101952. * @class p5.Texture
  101953. * @param {p5.RendererGL} renderer an instance of p5.RendererGL that
  101954. * will provide the GL context for this new p5.Texture
  101955. * @param {p5.Image|p5.Graphics|p5.Element|p5.MediaElement|ImageData} [obj] the
  101956. * object containing the image data to store in the texture.
  101957. */ _main.default.Texture = function(renderer, obj) {
  101958. this._renderer = renderer;
  101959. var gl = this._renderer.GL;
  101960. this.src = obj;
  101961. this.glTex = undefined;
  101962. this.glTarget = gl.TEXTURE_2D;
  101963. this.glFormat = gl.RGBA;
  101964. this.mipmaps = false;
  101965. this.glMinFilter = gl.LINEAR;
  101966. this.glMagFilter = gl.LINEAR;
  101967. this.glWrapS = gl.CLAMP_TO_EDGE;
  101968. this.glWrapT = gl.CLAMP_TO_EDGE;
  101969. // used to determine if this texture might need constant updating
  101970. // because it is a video or gif.
  101971. this.isSrcMediaElement =
  101972. typeof _main.default.MediaElement !== 'undefined' &&
  101973. obj instanceof _main.default.MediaElement;
  101974. this._videoPrevUpdateTime = 0;
  101975. this.isSrcHTMLElement =
  101976. typeof _main.default.Element !== 'undefined' &&
  101977. obj instanceof _main.default.Element &&
  101978. !(obj instanceof _main.default.Graphics);
  101979. this.isSrcP5Image = obj instanceof _main.default.Image;
  101980. this.isSrcP5Graphics = obj instanceof _main.default.Graphics;
  101981. this.isImageData = typeof ImageData !== 'undefined' && obj instanceof ImageData;
  101982. var textureData = this._getTextureDataFromSource();
  101983. this.width = textureData.width;
  101984. this.height = textureData.height;
  101985. this.init(textureData);
  101986. return this;
  101987. };
  101988. _main.default.Texture.prototype._getTextureDataFromSource = function() {
  101989. var textureData;
  101990. if (this.isSrcP5Image) {
  101991. // param is a p5.Image
  101992. textureData = this.src.canvas;
  101993. } else if (
  101994. this.isSrcMediaElement ||
  101995. this.isSrcP5Graphics ||
  101996. this.isSrcHTMLElement
  101997. ) {
  101998. // if param is a video HTML element
  101999. textureData = this.src.elt;
  102000. } else if (this.isImageData) {
  102001. textureData = this.src;
  102002. }
  102003. return textureData;
  102004. };
  102005. /**
  102006. * Initializes common texture parameters, creates a gl texture,
  102007. * tries to upload the texture for the first time if data is
  102008. * already available.
  102009. * @private
  102010. * @method init
  102011. */
  102012. _main.default.Texture.prototype.init = function(data) {
  102013. var gl = this._renderer.GL;
  102014. this.glTex = gl.createTexture();
  102015. this.glWrapS = this._renderer.textureWrapX;
  102016. this.glWrapT = this._renderer.textureWrapY;
  102017. this.setWrapMode(this.glWrapS, this.glWrapT);
  102018. this.bindTexture();
  102019. //gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
  102020. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.glMagFilter);
  102021. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.glMinFilter);
  102022. if (
  102023. this.width === 0 ||
  102024. this.height === 0 ||
  102025. (this.isSrcMediaElement && !this.src.loadedmetadata)
  102026. ) {
  102027. // assign a 1x1 empty texture initially, because data is not yet ready,
  102028. // so that no errors occur in gl console!
  102029. var tmpdata = new Uint8Array([1, 1, 1, 1]);
  102030. gl.texImage2D(
  102031. this.glTarget,
  102032. 0,
  102033. gl.RGBA,
  102034. 1,
  102035. 1,
  102036. 0,
  102037. this.glFormat,
  102038. gl.UNSIGNED_BYTE,
  102039. tmpdata
  102040. );
  102041. } else {
  102042. // data is ready: just push the texture!
  102043. gl.texImage2D(
  102044. this.glTarget,
  102045. 0,
  102046. this.glFormat,
  102047. this.glFormat,
  102048. gl.UNSIGNED_BYTE,
  102049. data
  102050. );
  102051. }
  102052. };
  102053. /**
  102054. * Checks if the source data for this texture has changed (if it's
  102055. * easy to do so) and reuploads the texture if necessary. If it's not
  102056. * possible or to expensive to do a calculation to determine wheter or
  102057. * not the data has occurred, this method simply re-uploads the texture.
  102058. * @method update
  102059. */
  102060. _main.default.Texture.prototype.update = function() {
  102061. var data = this.src;
  102062. if (data.width === 0 || data.height === 0) {
  102063. return false; // nothing to do!
  102064. }
  102065. var textureData = this._getTextureDataFromSource();
  102066. var updated = false;
  102067. var gl = this._renderer.GL;
  102068. // pull texture from data, make sure width & height are appropriate
  102069. if (textureData.width !== this.width || textureData.height !== this.height) {
  102070. updated = true;
  102071. // make sure that if the width and height of this.src have changed
  102072. // for some reason, we update our metadata and upload the texture again
  102073. this.width = textureData.width;
  102074. this.height = textureData.height;
  102075. if (this.isSrcP5Image) {
  102076. data.setModified(false);
  102077. } else if (this.isSrcMediaElement || this.isSrcHTMLElement) {
  102078. // on the first frame the metadata comes in, the size will be changed
  102079. // from 0 to actual size, but pixels may not be available.
  102080. // flag for update in a future frame.
  102081. // if we don't do this, a paused video, for example, may not
  102082. // send the first frame to texture memory.
  102083. data.setModified(true);
  102084. }
  102085. } else if (this.isSrcP5Image) {
  102086. // for an image, we only update if the modified field has been set,
  102087. // for example, by a call to p5.Image.set
  102088. if (data.isModified()) {
  102089. updated = true;
  102090. data.setModified(false);
  102091. }
  102092. } else if (this.isSrcMediaElement) {
  102093. // for a media element (video), we'll check if the current time in
  102094. // the video frame matches the last time. if it doesn't match, the
  102095. // video has advanced or otherwise been taken to a new frame,
  102096. // and we need to upload it.
  102097. if (data.isModified()) {
  102098. // p5.MediaElement may have also had set/updatePixels, etc. called
  102099. // on it and should be updated, or may have been set for the first
  102100. // time!
  102101. updated = true;
  102102. data.setModified(false);
  102103. } else if (data.loadedmetadata) {
  102104. // if the meta data has been loaded, we can ask the video
  102105. // what it's current position (in time) is.
  102106. if (this._videoPrevUpdateTime !== data.time()) {
  102107. // update the texture in gpu mem only if the current
  102108. // video timestamp does not match the timestamp of the last
  102109. // time we uploaded this texture (and update the time we
  102110. // last uploaded, too)
  102111. this._videoPrevUpdateTime = data.time();
  102112. updated = true;
  102113. }
  102114. }
  102115. } else if (this.isImageData) {
  102116. if (data._dirty) {
  102117. data._dirty = false;
  102118. updated = true;
  102119. }
  102120. } else {
  102121. /* data instanceof p5.Graphics, probably */
  102122. // there is not enough information to tell if the texture can be
  102123. // conditionally updated; so to be safe, we just go ahead and upload it.
  102124. updated = true;
  102125. }
  102126. if (updated) {
  102127. this.bindTexture();
  102128. gl.texImage2D(
  102129. this.glTarget,
  102130. 0,
  102131. this.glFormat,
  102132. this.glFormat,
  102133. gl.UNSIGNED_BYTE,
  102134. textureData
  102135. );
  102136. }
  102137. return updated;
  102138. };
  102139. /**
  102140. * Binds the texture to the appropriate GL target.
  102141. * @method bindTexture
  102142. */
  102143. _main.default.Texture.prototype.bindTexture = function() {
  102144. // bind texture using gl context + glTarget and
  102145. // generated gl texture object
  102146. var gl = this._renderer.GL;
  102147. gl.bindTexture(this.glTarget, this.glTex);
  102148. return this;
  102149. };
  102150. /**
  102151. * Unbinds the texture from the appropriate GL target.
  102152. * @method unbindTexture
  102153. */
  102154. _main.default.Texture.prototype.unbindTexture = function() {
  102155. // unbind per above, disable texturing on glTarget
  102156. var gl = this._renderer.GL;
  102157. gl.bindTexture(this.glTarget, null);
  102158. };
  102159. /**
  102160. * Sets how a texture is be interpolated when upscaled or downscaled.
  102161. * Nearest filtering uses nearest neighbor scaling when interpolating
  102162. * Linear filtering uses WebGL's linear scaling when interpolating
  102163. * @method setInterpolation
  102164. * @param {String} downScale Specifies the texture filtering when
  102165. * textures are shrunk. Options are LINEAR or NEAREST
  102166. * @param {String} upScale Specifies the texture filtering when
  102167. * textures are magnified. Options are LINEAR or NEAREST
  102168. * @todo implement mipmapping filters
  102169. */
  102170. _main.default.Texture.prototype.setInterpolation = function(downScale, upScale) {
  102171. var gl = this._renderer.GL;
  102172. if (downScale === constants.NEAREST) {
  102173. this.glMinFilter = gl.NEAREST;
  102174. } else {
  102175. this.glMinFilter = gl.LINEAR;
  102176. }
  102177. if (upScale === constants.NEAREST) {
  102178. this.glMagFilter = gl.NEAREST;
  102179. } else {
  102180. this.glMagFilter = gl.LINEAR;
  102181. }
  102182. this.bindTexture();
  102183. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.glMinFilter);
  102184. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.glMagFilter);
  102185. this.unbindTexture();
  102186. };
  102187. /**
  102188. * Sets the texture wrapping mode. This controls how textures behave
  102189. * when their uv's go outside of the 0 - 1 range. There are three options:
  102190. * CLAMP, REPEAT, and MIRROR. REPEAT & MIRROR are only available if the texture
  102191. * is a power of two size (128, 256, 512, 1024, etc.).
  102192. * @method setWrapMode
  102193. * @param {String} wrapX Controls the horizontal texture wrapping behavior
  102194. * @param {String} wrapY Controls the vertical texture wrapping behavior
  102195. */
  102196. _main.default.Texture.prototype.setWrapMode = function(wrapX, wrapY) {
  102197. var gl = this._renderer.GL;
  102198. // for webgl 1 we need to check if the texture is power of two
  102199. // if it isn't we will set the wrap mode to CLAMP
  102200. // webgl2 will support npot REPEAT and MIRROR but we don't check for it yet
  102201. var isPowerOfTwo = function isPowerOfTwo(x) {
  102202. return (x & (x - 1)) === 0;
  102203. };
  102204. var widthPowerOfTwo = isPowerOfTwo(this.width);
  102205. var heightPowerOfTwo = isPowerOfTwo(this.height);
  102206. if (wrapX === constants.REPEAT) {
  102207. if (widthPowerOfTwo && heightPowerOfTwo) {
  102208. this.glWrapS = gl.REPEAT;
  102209. } else {
  102210. console.warn(
  102211. 'You tried to set the wrap mode to REPEAT but the texture size is not a power of two. Setting to CLAMP instead'
  102212. );
  102213. this.glWrapS = gl.CLAMP_TO_EDGE;
  102214. }
  102215. } else if (wrapX === constants.MIRROR) {
  102216. if (widthPowerOfTwo && heightPowerOfTwo) {
  102217. this.glWrapS = gl.MIRRORED_REPEAT;
  102218. } else {
  102219. console.warn(
  102220. 'You tried to set the wrap mode to MIRROR but the texture size is not a power of two. Setting to CLAMP instead'
  102221. );
  102222. this.glWrapS = gl.CLAMP_TO_EDGE;
  102223. }
  102224. } else {
  102225. // falling back to default if didn't get a proper mode
  102226. this.glWrapS = gl.CLAMP_TO_EDGE;
  102227. }
  102228. if (wrapY === constants.REPEAT) {
  102229. if (widthPowerOfTwo && heightPowerOfTwo) {
  102230. this.glWrapT = gl.REPEAT;
  102231. } else {
  102232. console.warn(
  102233. 'You tried to set the wrap mode to REPEAT but the texture size is not a power of two. Setting to CLAMP instead'
  102234. );
  102235. this.glWrapT = gl.CLAMP_TO_EDGE;
  102236. }
  102237. } else if (wrapY === constants.MIRROR) {
  102238. if (widthPowerOfTwo && heightPowerOfTwo) {
  102239. this.glWrapT = gl.MIRRORED_REPEAT;
  102240. } else {
  102241. console.warn(
  102242. 'You tried to set the wrap mode to MIRROR but the texture size is not a power of two. Setting to CLAMP instead'
  102243. );
  102244. this.glWrapT = gl.CLAMP_TO_EDGE;
  102245. }
  102246. } else {
  102247. // falling back to default if didn't get a proper mode
  102248. this.glWrapT = gl.CLAMP_TO_EDGE;
  102249. }
  102250. this.bindTexture();
  102251. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this.glWrapS);
  102252. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this.glWrapT);
  102253. this.unbindTexture();
  102254. };
  102255. var _default = _main.default.Texture;
  102256. exports.default = _default;
  102257. },
  102258. {
  102259. '../core/constants': 272,
  102260. '../core/main': 283,
  102261. 'core-js/modules/es.array.iterator': 174,
  102262. 'core-js/modules/es.object.to-string': 192,
  102263. 'core-js/modules/es.typed-array.copy-within': 212,
  102264. 'core-js/modules/es.typed-array.every': 213,
  102265. 'core-js/modules/es.typed-array.fill': 214,
  102266. 'core-js/modules/es.typed-array.filter': 215,
  102267. 'core-js/modules/es.typed-array.find': 217,
  102268. 'core-js/modules/es.typed-array.find-index': 216,
  102269. 'core-js/modules/es.typed-array.for-each': 220,
  102270. 'core-js/modules/es.typed-array.includes': 221,
  102271. 'core-js/modules/es.typed-array.index-of': 222,
  102272. 'core-js/modules/es.typed-array.iterator': 225,
  102273. 'core-js/modules/es.typed-array.join': 226,
  102274. 'core-js/modules/es.typed-array.last-index-of': 227,
  102275. 'core-js/modules/es.typed-array.map': 228,
  102276. 'core-js/modules/es.typed-array.reduce': 230,
  102277. 'core-js/modules/es.typed-array.reduce-right': 229,
  102278. 'core-js/modules/es.typed-array.reverse': 231,
  102279. 'core-js/modules/es.typed-array.set': 232,
  102280. 'core-js/modules/es.typed-array.slice': 233,
  102281. 'core-js/modules/es.typed-array.some': 234,
  102282. 'core-js/modules/es.typed-array.sort': 235,
  102283. 'core-js/modules/es.typed-array.subarray': 236,
  102284. 'core-js/modules/es.typed-array.to-locale-string': 237,
  102285. 'core-js/modules/es.typed-array.to-string': 238,
  102286. 'core-js/modules/es.typed-array.uint8-array': 241
  102287. }
  102288. ],
  102289. 340: [
  102290. function(_dereq_, module, exports) {
  102291. 'use strict';
  102292. function _typeof(obj) {
  102293. if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
  102294. _typeof = function _typeof(obj) {
  102295. return typeof obj;
  102296. };
  102297. } else {
  102298. _typeof = function _typeof(obj) {
  102299. return obj &&
  102300. typeof Symbol === 'function' &&
  102301. obj.constructor === Symbol &&
  102302. obj !== Symbol.prototype
  102303. ? 'symbol'
  102304. : typeof obj;
  102305. };
  102306. }
  102307. return _typeof(obj);
  102308. }
  102309. _dereq_('core-js/modules/es.symbol');
  102310. _dereq_('core-js/modules/es.symbol.description');
  102311. _dereq_('core-js/modules/es.symbol.iterator');
  102312. _dereq_('core-js/modules/es.array.iterator');
  102313. _dereq_('core-js/modules/es.object.to-string');
  102314. _dereq_('core-js/modules/es.regexp.exec');
  102315. _dereq_('core-js/modules/es.string.iterator');
  102316. _dereq_('core-js/modules/es.string.split');
  102317. _dereq_('core-js/modules/es.string.sub');
  102318. _dereq_('core-js/modules/web.dom-collections.iterator');
  102319. var _main = _interopRequireDefault(_dereq_('../core/main'));
  102320. var constants = _interopRequireWildcard(_dereq_('../core/constants'));
  102321. _dereq_('./p5.Shader');
  102322. _dereq_('./p5.RendererGL.Retained');
  102323. function _getRequireWildcardCache() {
  102324. if (typeof WeakMap !== 'function') return null;
  102325. var cache = new WeakMap();
  102326. _getRequireWildcardCache = function _getRequireWildcardCache() {
  102327. return cache;
  102328. };
  102329. return cache;
  102330. }
  102331. function _interopRequireWildcard(obj) {
  102332. if (obj && obj.__esModule) {
  102333. return obj;
  102334. }
  102335. if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
  102336. return { default: obj };
  102337. }
  102338. var cache = _getRequireWildcardCache();
  102339. if (cache && cache.has(obj)) {
  102340. return cache.get(obj);
  102341. }
  102342. var newObj = {};
  102343. var hasPropertyDescriptor =
  102344. Object.defineProperty && Object.getOwnPropertyDescriptor;
  102345. for (var key in obj) {
  102346. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  102347. var desc = hasPropertyDescriptor
  102348. ? Object.getOwnPropertyDescriptor(obj, key)
  102349. : null;
  102350. if (desc && (desc.get || desc.set)) {
  102351. Object.defineProperty(newObj, key, desc);
  102352. } else {
  102353. newObj[key] = obj[key];
  102354. }
  102355. }
  102356. }
  102357. newObj.default = obj;
  102358. if (cache) {
  102359. cache.set(obj, newObj);
  102360. }
  102361. return newObj;
  102362. }
  102363. function _interopRequireDefault(obj) {
  102364. return obj && obj.__esModule ? obj : { default: obj };
  102365. }
  102366. // Text/Typography
  102367. // @TODO:
  102368. _main.default.RendererGL.prototype._applyTextProperties = function() {
  102369. //@TODO finish implementation
  102370. //console.error('text commands not yet implemented in webgl');
  102371. };
  102372. _main.default.RendererGL.prototype.textWidth = function(s) {
  102373. if (this._isOpenType()) {
  102374. return this._textFont._textWidth(s, this._textSize);
  102375. }
  102376. return 0; // TODO: error
  102377. };
  102378. // rendering constants
  102379. // the number of rows/columns dividing each glyph
  102380. var charGridWidth = 9;
  102381. var charGridHeight = charGridWidth;
  102382. // size of the image holding the bezier stroke info
  102383. var strokeImageWidth = 64;
  102384. var strokeImageHeight = 64;
  102385. // size of the image holding the stroke indices for each row/col
  102386. var gridImageWidth = 64;
  102387. var gridImageHeight = 64;
  102388. // size of the image holding the offset/length of each row/col stripe
  102389. var cellImageWidth = 64;
  102390. var cellImageHeight = 64;
  102391. /**
  102392. * @private
  102393. * @class ImageInfos
  102394. * @param {Integer} width
  102395. * @param {Integer} height
  102396. *
  102397. * the ImageInfos class holds a list of ImageDatas of a given size.
  102398. */
  102399. function ImageInfos(width, height) {
  102400. this.width = width;
  102401. this.height = height;
  102402. this.infos = []; // the list of images
  102403. /**
  102404. *
  102405. * @method findImage
  102406. * @param {Integer} space
  102407. * @return {Object} contains the ImageData, and pixel index into that
  102408. * ImageData where the free space was allocated.
  102409. *
  102410. * finds free space of a given size in the ImageData list
  102411. */
  102412. this.findImage = function(space) {
  102413. var imageSize = this.width * this.height;
  102414. if (space > imageSize) throw new Error('font is too complex to render in 3D');
  102415. // search through the list of images, looking for one with
  102416. // anough unused space.
  102417. var imageInfo, imageData;
  102418. for (var ii = this.infos.length - 1; ii >= 0; --ii) {
  102419. var imageInfoTest = this.infos[ii];
  102420. if (imageInfoTest.index + space < imageSize) {
  102421. // found one
  102422. imageInfo = imageInfoTest;
  102423. imageData = imageInfoTest.imageData;
  102424. break;
  102425. }
  102426. }
  102427. if (!imageInfo) {
  102428. try {
  102429. // create a new image
  102430. imageData = new ImageData(this.width, this.height);
  102431. } catch (err) {
  102432. // for browsers that don't support ImageData constructors (ie IE11)
  102433. // create an ImageData using the old method
  102434. var canvas = document.getElementsByTagName('canvas')[0];
  102435. var created = !canvas;
  102436. if (!canvas) {
  102437. // create a temporary canvas
  102438. canvas = document.createElement('canvas');
  102439. canvas.style.display = 'none';
  102440. document.body.appendChild(canvas);
  102441. }
  102442. var ctx = canvas.getContext('2d');
  102443. if (ctx) {
  102444. imageData = ctx.createImageData(this.width, this.height);
  102445. }
  102446. if (created) {
  102447. // distroy the temporary canvas, if necessary
  102448. document.body.removeChild(canvas);
  102449. }
  102450. }
  102451. // construct & dd the new image info
  102452. imageInfo = { index: 0, imageData: imageData };
  102453. this.infos.push(imageInfo);
  102454. }
  102455. var index = imageInfo.index;
  102456. imageInfo.index += space; // move to the start of the next image
  102457. imageData._dirty = true;
  102458. return { imageData: imageData, index: index };
  102459. };
  102460. }
  102461. /**
  102462. * @function setPixel
  102463. * @param {Object} imageInfo
  102464. * @param {Number} r
  102465. * @param {Number} g
  102466. * @param {Number} b
  102467. * @param {Number} a
  102468. *
  102469. * writes the next pixel into an indexed ImageData
  102470. */
  102471. function setPixel(imageInfo, r, g, b, a) {
  102472. var imageData = imageInfo.imageData;
  102473. var pixels = imageData.data;
  102474. var index = imageInfo.index++ * 4;
  102475. pixels[index++] = r;
  102476. pixels[index++] = g;
  102477. pixels[index++] = b;
  102478. pixels[index++] = a;
  102479. }
  102480. var SQRT3 = Math.sqrt(3);
  102481. /**
  102482. * @private
  102483. * @class FontInfo
  102484. * @param {Object} font an opentype.js font object
  102485. *
  102486. * contains cached images and glyph information for an opentype font
  102487. */
  102488. var FontInfo = function FontInfo(font) {
  102489. this.font = font;
  102490. // the bezier curve coordinates
  102491. this.strokeImageInfos = new ImageInfos(strokeImageWidth, strokeImageHeight);
  102492. // lists of curve indices for each row/column slice
  102493. this.colDimImageInfos = new ImageInfos(gridImageWidth, gridImageHeight);
  102494. this.rowDimImageInfos = new ImageInfos(gridImageWidth, gridImageHeight);
  102495. // the offset & length of each row/col slice in the glyph
  102496. this.colCellImageInfos = new ImageInfos(cellImageWidth, cellImageHeight);
  102497. this.rowCellImageInfos = new ImageInfos(cellImageWidth, cellImageHeight);
  102498. // the cached information for each glyph
  102499. this.glyphInfos = {};
  102500. /**
  102501. * @method getGlyphInfo
  102502. * @param {Glyph} glyph the x positions of points in the curve
  102503. * @returns {Object} the glyphInfo for that glyph
  102504. *
  102505. * calculates rendering info for a glyph, including the curve information,
  102506. * row & column stripes compiled into textures.
  102507. */
  102508. this.getGlyphInfo = function(glyph) {
  102509. // check the cache
  102510. var gi = this.glyphInfos[glyph.index];
  102511. if (gi) return gi;
  102512. // get the bounding box of the glyph from opentype.js
  102513. var bb = glyph.getBoundingBox();
  102514. var xMin = bb.x1;
  102515. var yMin = bb.y1;
  102516. var gWidth = bb.x2 - xMin;
  102517. var gHeight = bb.y2 - yMin;
  102518. var cmds = glyph.path.commands;
  102519. // don't bother rendering invisible glyphs
  102520. if (gWidth === 0 || gHeight === 0 || !cmds.length) {
  102521. return (this.glyphInfos[glyph.index] = {});
  102522. }
  102523. var i;
  102524. var strokes = []; // the strokes in this glyph
  102525. var rows = []; // the indices of strokes in each row
  102526. var cols = []; // the indices of strokes in each column
  102527. for (i = charGridWidth - 1; i >= 0; --i) {
  102528. cols.push([]);
  102529. }
  102530. for (i = charGridHeight - 1; i >= 0; --i) {
  102531. rows.push([]);
  102532. }
  102533. /**
  102534. * @function push
  102535. * @param {Number[]} xs the x positions of points in the curve
  102536. * @param {Number[]} ys the y positions of points in the curve
  102537. * @param {Object} v the curve information
  102538. *
  102539. * adds a curve to the rows & columns that it intersects with
  102540. */
  102541. function push(xs, ys, v) {
  102542. var index = strokes.length; // the index of this stroke
  102543. strokes.push(v); // add this stroke to the list
  102544. /**
  102545. * @function minMax
  102546. * @param {Number[]} rg the list of values to compare
  102547. * @param {Number} min the initial minimum value
  102548. * @param {Number} max the initial maximum value
  102549. *
  102550. * find the minimum & maximum value in a list of values
  102551. */
  102552. function minMax(rg, min, max) {
  102553. for (var _i = rg.length; _i-- > 0; ) {
  102554. var _v = rg[_i];
  102555. if (min > _v) min = _v;
  102556. if (max < _v) max = _v;
  102557. }
  102558. return { min: min, max: max };
  102559. }
  102560. // loop through the rows & columns that the curve intersects
  102561. // adding the curve to those slices
  102562. var mmX = minMax(xs, 1, 0);
  102563. var ixMin = Math.max(Math.floor(mmX.min * charGridWidth), 0);
  102564. var ixMax = Math.min(Math.ceil(mmX.max * charGridWidth), charGridWidth);
  102565. for (var iCol = ixMin; iCol < ixMax; ++iCol) {
  102566. cols[iCol].push(index);
  102567. }
  102568. var mmY = minMax(ys, 1, 0);
  102569. var iyMin = Math.max(Math.floor(mmY.min * charGridHeight), 0);
  102570. var iyMax = Math.min(Math.ceil(mmY.max * charGridHeight), charGridHeight);
  102571. for (var iRow = iyMin; iRow < iyMax; ++iRow) {
  102572. rows[iRow].push(index);
  102573. }
  102574. }
  102575. /**
  102576. * @function clamp
  102577. * @param {Number} v the value to clamp
  102578. * @param {Number} min the minimum value
  102579. * @param {Number} max the maxmimum value
  102580. *
  102581. * clamps a value between a minimum & maximum value
  102582. */
  102583. function clamp(v, min, max) {
  102584. if (v < min) return min;
  102585. if (v > max) return max;
  102586. return v;
  102587. }
  102588. /**
  102589. * @function byte
  102590. * @param {Number} v the value to scale
  102591. *
  102592. * converts a floating-point number in the range 0-1 to a byte 0-255
  102593. */
  102594. function byte(v) {
  102595. return clamp(255 * v, 0, 255);
  102596. }
  102597. /**
  102598. * @private
  102599. * @class Cubic
  102600. * @param {Number} p0 the start point of the curve
  102601. * @param {Number} c0 the first control point
  102602. * @param {Number} c1 the second control point
  102603. * @param {Number} p1 the end point
  102604. *
  102605. * a cubic curve
  102606. */
  102607. function Cubic(p0, c0, c1, p1) {
  102608. this.p0 = p0;
  102609. this.c0 = c0;
  102610. this.c1 = c1;
  102611. this.p1 = p1;
  102612. /**
  102613. * @method toQuadratic
  102614. * @return {Object} the quadratic approximation
  102615. *
  102616. * converts the cubic to a quadtratic approximation by
  102617. * picking an appropriate quadratic control point
  102618. */
  102619. this.toQuadratic = function() {
  102620. return {
  102621. x: this.p0.x,
  102622. y: this.p0.y,
  102623. x1: this.p1.x,
  102624. y1: this.p1.y,
  102625. cx: ((this.c0.x + this.c1.x) * 3 - (this.p0.x + this.p1.x)) / 4,
  102626. cy: ((this.c0.y + this.c1.y) * 3 - (this.p0.y + this.p1.y)) / 4
  102627. };
  102628. };
  102629. /**
  102630. * @method quadError
  102631. * @return {Number} the error
  102632. *
  102633. * calculates the magnitude of error of this curve's
  102634. * quadratic approximation.
  102635. */
  102636. this.quadError = function() {
  102637. return (
  102638. _main.default.Vector.sub(
  102639. _main.default.Vector.sub(this.p1, this.p0),
  102640. _main.default.Vector.mult(
  102641. _main.default.Vector.sub(this.c1, this.c0),
  102642. 3
  102643. )
  102644. ).mag() / 2
  102645. );
  102646. };
  102647. /**
  102648. * @method split
  102649. * @param {Number} t the value (0-1) at which to split
  102650. * @return {Cubic} the second part of the curve
  102651. *
  102652. * splits the cubic into two parts at a point 't' along the curve.
  102653. * this cubic keeps its start point and its end point becomes the
  102654. * point at 't'. the 'end half is returned.
  102655. */
  102656. this.split = function(t) {
  102657. var m1 = _main.default.Vector.lerp(this.p0, this.c0, t);
  102658. var m2 = _main.default.Vector.lerp(this.c0, this.c1, t);
  102659. var mm1 = _main.default.Vector.lerp(m1, m2, t);
  102660. this.c1 = _main.default.Vector.lerp(this.c1, this.p1, t);
  102661. this.c0 = _main.default.Vector.lerp(m2, this.c1, t);
  102662. var pt = _main.default.Vector.lerp(mm1, this.c0, t);
  102663. var part1 = new Cubic(this.p0, m1, mm1, pt);
  102664. this.p0 = pt;
  102665. return part1;
  102666. };
  102667. /**
  102668. * @method splitInflections
  102669. * @return {Cubic[]} the non-inflecting pieces of this cubic
  102670. *
  102671. * returns an array containing 0, 1 or 2 cubics split resulting
  102672. * from splitting this cubic at its inflection points.
  102673. * this cubic is (potentially) altered and returned in the list.
  102674. */
  102675. this.splitInflections = function() {
  102676. var a = _main.default.Vector.sub(this.c0, this.p0);
  102677. var b = _main.default.Vector.sub(
  102678. _main.default.Vector.sub(this.c1, this.c0),
  102679. a
  102680. );
  102681. var c = _main.default.Vector.sub(
  102682. _main.default.Vector.sub(_main.default.Vector.sub(this.p1, this.c1), a),
  102683. _main.default.Vector.mult(b, 2)
  102684. );
  102685. var cubics = [];
  102686. // find the derivative coefficients
  102687. var A = b.x * c.y - b.y * c.x;
  102688. if (A !== 0) {
  102689. var B = a.x * c.y - a.y * c.x;
  102690. var C = a.x * b.y - a.y * b.x;
  102691. var disc = B * B - 4 * A * C;
  102692. if (disc >= 0) {
  102693. if (A < 0) {
  102694. A = -A;
  102695. B = -B;
  102696. C = -C;
  102697. }
  102698. var Q = Math.sqrt(disc);
  102699. var t0 = (-B - Q) / (2 * A); // the first inflection point
  102700. var t1 = (-B + Q) / (2 * A); // the second inflection point
  102701. // test if the first inflection point lies on the curve
  102702. if (t0 > 0 && t0 < 1) {
  102703. // split at the first inflection point
  102704. cubics.push(this.split(t0));
  102705. // scale t2 into the second part
  102706. t1 = 1 - (1 - t1) / (1 - t0);
  102707. }
  102708. // test if the second inflection point lies on the curve
  102709. if (t1 > 0 && t1 < 1) {
  102710. // split at the second inflection point
  102711. cubics.push(this.split(t1));
  102712. }
  102713. }
  102714. }
  102715. cubics.push(this);
  102716. return cubics;
  102717. };
  102718. }
  102719. /**
  102720. * @function cubicToQuadratics
  102721. * @param {Number} x0
  102722. * @param {Number} y0
  102723. * @param {Number} cx0
  102724. * @param {Number} cy0
  102725. * @param {Number} cx1
  102726. * @param {Number} cy1
  102727. * @param {Number} x1
  102728. * @param {Number} y1
  102729. * @returns {Cubic[]} an array of cubics whose quadratic approximations
  102730. * closely match the civen cubic.
  102731. *
  102732. * converts a cubic curve to a list of quadratics.
  102733. */
  102734. function cubicToQuadratics(x0, y0, cx0, cy0, cx1, cy1, x1, y1) {
  102735. // create the Cubic object and split it at its inflections
  102736. var cubics = new Cubic(
  102737. new _main.default.Vector(x0, y0),
  102738. new _main.default.Vector(cx0, cy0),
  102739. new _main.default.Vector(cx1, cy1),
  102740. new _main.default.Vector(x1, y1)
  102741. ).splitInflections();
  102742. var qs = []; // the final list of quadratics
  102743. var precision = 30 / SQRT3;
  102744. // for each of the non-inflected pieces of the original cubic
  102745. var _iteratorNormalCompletion = true;
  102746. var _didIteratorError = false;
  102747. var _iteratorError = undefined;
  102748. try {
  102749. for (
  102750. var _iterator = cubics[Symbol.iterator](), _step;
  102751. !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
  102752. _iteratorNormalCompletion = true
  102753. ) {
  102754. var cubic = _step.value;
  102755. // the cubic is iteratively split in 3 pieces:
  102756. // the first piece is accumulated in 'qs', the result.
  102757. // the last piece is accumulated in 'tail', temporarily.
  102758. // the middle piece is repeatedly split again, while necessary.
  102759. var tail = [];
  102760. var t3 = void 0;
  102761. for (;;) {
  102762. // calculate this cubic's precision
  102763. t3 = precision / cubic.quadError();
  102764. if (t3 >= 0.5 * 0.5 * 0.5) {
  102765. break; // not too bad, we're done
  102766. }
  102767. // find a split point based on the error
  102768. var t = Math.pow(t3, 1.0 / 3.0);
  102769. // split the cubic in 3
  102770. var start = cubic.split(t);
  102771. var middle = cubic.split(1 - t / (1 - t));
  102772. qs.push(start); // the first part
  102773. tail.push(cubic); // the last part
  102774. cubic = middle; // iterate on the middle piece
  102775. }
  102776. if (t3 < 1) {
  102777. // a little excess error, split the middle in two
  102778. qs.push(cubic.split(0.5));
  102779. }
  102780. // add the middle piece to the result
  102781. qs.push(cubic);
  102782. // finally add the tail, reversed, onto the result
  102783. Array.prototype.push.apply(qs, tail.reverse());
  102784. }
  102785. } catch (err) {
  102786. _didIteratorError = true;
  102787. _iteratorError = err;
  102788. } finally {
  102789. try {
  102790. if (!_iteratorNormalCompletion && _iterator.return != null) {
  102791. _iterator.return();
  102792. }
  102793. } finally {
  102794. if (_didIteratorError) {
  102795. throw _iteratorError;
  102796. }
  102797. }
  102798. }
  102799. return qs;
  102800. }
  102801. /**
  102802. * @function pushLine
  102803. * @param {Number} x0
  102804. * @param {Number} y0
  102805. * @param {Number} x1
  102806. * @param {Number} y1
  102807. *
  102808. * add a straight line to the row/col grid of a glyph
  102809. */
  102810. function pushLine(x0, y0, x1, y1) {
  102811. var mx = (x0 + x1) / 2;
  102812. var my = (y0 + y1) / 2;
  102813. push([x0, x1], [y0, y1], { x: x0, y: y0, cx: mx, cy: my });
  102814. }
  102815. /**
  102816. * @function samePoint
  102817. * @param {Number} x0
  102818. * @param {Number} y0
  102819. * @param {Number} x1
  102820. * @param {Number} y1
  102821. * @return {Boolean} true if the two points are sufficiently close
  102822. *
  102823. * tests if two points are close enough to be considered the same
  102824. */
  102825. function samePoint(x0, y0, x1, y1) {
  102826. return Math.abs(x1 - x0) < 0.00001 && Math.abs(y1 - y0) < 0.00001;
  102827. }
  102828. var x0, y0, xs, ys;
  102829. var _iteratorNormalCompletion2 = true;
  102830. var _didIteratorError2 = false;
  102831. var _iteratorError2 = undefined;
  102832. try {
  102833. for (
  102834. var _iterator2 = cmds[Symbol.iterator](), _step2;
  102835. !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);
  102836. _iteratorNormalCompletion2 = true
  102837. ) {
  102838. var cmd = _step2.value;
  102839. // scale the coordinates to the range 0-1
  102840. var x1 = (cmd.x - xMin) / gWidth;
  102841. var y1 = (cmd.y - yMin) / gHeight;
  102842. // don't bother if this point is the same as the last
  102843. if (samePoint(x0, y0, x1, y1)) continue;
  102844. switch (cmd.type) {
  102845. case 'M': {
  102846. // move
  102847. xs = x1;
  102848. ys = y1;
  102849. break;
  102850. }
  102851. case 'L': {
  102852. // line
  102853. pushLine(x0, y0, x1, y1);
  102854. break;
  102855. }
  102856. case 'Q': {
  102857. // quadratic
  102858. var cx = (cmd.x1 - xMin) / gWidth;
  102859. var cy = (cmd.y1 - yMin) / gHeight;
  102860. push([x0, x1, cx], [y0, y1, cy], { x: x0, y: y0, cx: cx, cy: cy });
  102861. break;
  102862. }
  102863. case 'Z': {
  102864. // end
  102865. if (!samePoint(x0, y0, xs, ys)) {
  102866. // add an extra line closing the loop, if necessary
  102867. pushLine(x0, y0, xs, ys);
  102868. strokes.push({ x: xs, y: ys });
  102869. } else {
  102870. strokes.push({ x: x0, y: y0 });
  102871. }
  102872. break;
  102873. }
  102874. case 'C': {
  102875. // cubic
  102876. var cx1 = (cmd.x1 - xMin) / gWidth;
  102877. var cy1 = (cmd.y1 - yMin) / gHeight;
  102878. var cx2 = (cmd.x2 - xMin) / gWidth;
  102879. var cy2 = (cmd.y2 - yMin) / gHeight;
  102880. var qs = cubicToQuadratics(x0, y0, cx1, cy1, cx2, cy2, x1, y1);
  102881. for (var iq = 0; iq < qs.length; iq++) {
  102882. var q = qs[iq].toQuadratic();
  102883. push([q.x, q.x1, q.cx], [q.y, q.y1, q.cy], q);
  102884. }
  102885. break;
  102886. }
  102887. default:
  102888. throw new Error('unknown command type: '.concat(cmd.type));
  102889. }
  102890. x0 = x1;
  102891. y0 = y1;
  102892. }
  102893. // allocate space for the strokes
  102894. } catch (err) {
  102895. _didIteratorError2 = true;
  102896. _iteratorError2 = err;
  102897. } finally {
  102898. try {
  102899. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  102900. _iterator2.return();
  102901. }
  102902. } finally {
  102903. if (_didIteratorError2) {
  102904. throw _iteratorError2;
  102905. }
  102906. }
  102907. }
  102908. var strokeCount = strokes.length;
  102909. var strokeImageInfo = this.strokeImageInfos.findImage(strokeCount);
  102910. var strokeOffset = strokeImageInfo.index;
  102911. // fill the stroke image
  102912. for (var il = 0; il < strokeCount; ++il) {
  102913. var s = strokes[il];
  102914. setPixel(strokeImageInfo, byte(s.x), byte(s.y), byte(s.cx), byte(s.cy));
  102915. }
  102916. /**
  102917. * @function layout
  102918. * @param {Number[][]} dim
  102919. * @param {ImageInfo[]} dimImageInfos
  102920. * @param {ImageInfo[]} cellImageInfos
  102921. * @return {Object}
  102922. *
  102923. * lays out the curves in a dimension (row or col) into two
  102924. * images, one for the indices of the curves themselves, and
  102925. * one containing the offset and length of those index spans.
  102926. */
  102927. function layout(dim, dimImageInfos, cellImageInfos) {
  102928. var dimLength = dim.length; // the number of slices in this dimension
  102929. var dimImageInfo = dimImageInfos.findImage(dimLength);
  102930. var dimOffset = dimImageInfo.index;
  102931. // calculate the total number of stroke indices in this dimension
  102932. var totalStrokes = 0;
  102933. for (var id = 0; id < dimLength; ++id) {
  102934. totalStrokes += dim[id].length;
  102935. }
  102936. // allocate space for the stroke indices
  102937. var cellImageInfo = cellImageInfos.findImage(totalStrokes);
  102938. // for each slice in the glyph
  102939. for (var _i2 = 0; _i2 < dimLength; ++_i2) {
  102940. var strokeIndices = dim[_i2];
  102941. var _strokeCount = strokeIndices.length;
  102942. var cellLineIndex = cellImageInfo.index;
  102943. // write the offset and count into the glyph slice image
  102944. setPixel(
  102945. dimImageInfo,
  102946. cellLineIndex >> 7,
  102947. cellLineIndex & 0x7f,
  102948. _strokeCount >> 7,
  102949. _strokeCount & 0x7f
  102950. );
  102951. // for each stroke index in that slice
  102952. for (var iil = 0; iil < _strokeCount; ++iil) {
  102953. // write the stroke index into the slice's image
  102954. var strokeIndex = strokeIndices[iil] + strokeOffset;
  102955. setPixel(cellImageInfo, strokeIndex >> 7, strokeIndex & 0x7f, 0, 0);
  102956. }
  102957. }
  102958. return {
  102959. cellImageInfo: cellImageInfo,
  102960. dimOffset: dimOffset,
  102961. dimImageInfo: dimImageInfo
  102962. };
  102963. }
  102964. // initialize the info for this glyph
  102965. gi = this.glyphInfos[glyph.index] = {
  102966. glyph: glyph,
  102967. uGlyphRect: [bb.x1, -bb.y1, bb.x2, -bb.y2],
  102968. strokeImageInfo: strokeImageInfo,
  102969. strokes: strokes,
  102970. colInfo: layout(cols, this.colDimImageInfos, this.colCellImageInfos),
  102971. rowInfo: layout(rows, this.rowDimImageInfos, this.rowCellImageInfos)
  102972. };
  102973. gi.uGridOffset = [gi.colInfo.dimOffset, gi.rowInfo.dimOffset];
  102974. return gi;
  102975. };
  102976. };
  102977. _main.default.RendererGL.prototype._renderText = function(p, line, x, y, maxY) {
  102978. if (!this._textFont || typeof this._textFont === 'string') {
  102979. console.log(
  102980. 'WEBGL: you must load and set a font before drawing text. See `loadFont` and `textFont` for more details.'
  102981. );
  102982. return;
  102983. }
  102984. if (y >= maxY || !this._doFill) {
  102985. return; // don't render lines beyond our maxY position
  102986. }
  102987. if (!this._isOpenType()) {
  102988. console.log(
  102989. 'WEBGL: only Opentype (.otf) and Truetype (.ttf) fonts are supported'
  102990. );
  102991. return p;
  102992. }
  102993. p.push(); // fix to #803
  102994. // remember this state, so it can be restored later
  102995. var doStroke = this._doStroke;
  102996. var drawMode = this.drawMode;
  102997. this._doStroke = false;
  102998. this.drawMode = constants.TEXTURE;
  102999. // get the cached FontInfo object
  103000. var font = this._textFont.font;
  103001. var fontInfo = this._textFont._fontInfo;
  103002. if (!fontInfo) {
  103003. fontInfo = this._textFont._fontInfo = new FontInfo(font);
  103004. }
  103005. // calculate the alignment and move/scale the view accordingly
  103006. var pos = this._textFont._handleAlignment(this, line, x, y);
  103007. var fontSize = this._textSize;
  103008. var scale = fontSize / font.unitsPerEm;
  103009. this.translate(pos.x, pos.y, 0);
  103010. this.scale(scale, scale, 1);
  103011. // initialize the font shader
  103012. var gl = this.GL;
  103013. var initializeShader = !this._defaultFontShader;
  103014. var sh = this._getFontShader();
  103015. sh.init();
  103016. sh.bindShader(); // first time around, bind the shader fully
  103017. if (initializeShader) {
  103018. // these are constants, really. just initialize them one-time.
  103019. sh.setUniform('uGridImageSize', [gridImageWidth, gridImageHeight]);
  103020. sh.setUniform('uCellsImageSize', [cellImageWidth, cellImageHeight]);
  103021. sh.setUniform('uStrokeImageSize', [strokeImageWidth, strokeImageHeight]);
  103022. sh.setUniform('uGridSize', [charGridWidth, charGridHeight]);
  103023. }
  103024. this._applyColorBlend(this.curFillColor);
  103025. var g = this.retainedMode.geometry['glyph'];
  103026. if (!g) {
  103027. // create the geometry for rendering a quad
  103028. var geom = (this._textGeom = new _main.default.Geometry(1, 1, function() {
  103029. for (var i = 0; i <= 1; i++) {
  103030. for (var j = 0; j <= 1; j++) {
  103031. this.vertices.push(new _main.default.Vector(j, i, 0));
  103032. this.uvs.push(j, i);
  103033. }
  103034. }
  103035. }));
  103036. geom.computeFaces().computeNormals();
  103037. g = this.createBuffers('glyph', geom);
  103038. }
  103039. // bind the shader buffers
  103040. var _iteratorNormalCompletion3 = true;
  103041. var _didIteratorError3 = false;
  103042. var _iteratorError3 = undefined;
  103043. try {
  103044. for (
  103045. var _iterator3 = this.retainedMode.buffers.text[Symbol.iterator](), _step3;
  103046. !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done);
  103047. _iteratorNormalCompletion3 = true
  103048. ) {
  103049. var buff = _step3.value;
  103050. buff._prepareBuffer(g, sh);
  103051. }
  103052. } catch (err) {
  103053. _didIteratorError3 = true;
  103054. _iteratorError3 = err;
  103055. } finally {
  103056. try {
  103057. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  103058. _iterator3.return();
  103059. }
  103060. } finally {
  103061. if (_didIteratorError3) {
  103062. throw _iteratorError3;
  103063. }
  103064. }
  103065. }
  103066. this._bindBuffer(g.indexBuffer, gl.ELEMENT_ARRAY_BUFFER);
  103067. // this will have to do for now...
  103068. sh.setUniform('uMaterialColor', this.curFillColor);
  103069. try {
  103070. var dx = 0; // the x position in the line
  103071. var glyphPrev = null; // the previous glyph, used for kerning
  103072. // fetch the glyphs in the line of text
  103073. var glyphs = font.stringToGlyphs(line);
  103074. var _iteratorNormalCompletion4 = true;
  103075. var _didIteratorError4 = false;
  103076. var _iteratorError4 = undefined;
  103077. try {
  103078. for (
  103079. var _iterator4 = glyphs[Symbol.iterator](), _step4;
  103080. !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done);
  103081. _iteratorNormalCompletion4 = true
  103082. ) {
  103083. var glyph = _step4.value;
  103084. // kern
  103085. if (glyphPrev) dx += font.getKerningValue(glyphPrev, glyph);
  103086. var gi = fontInfo.getGlyphInfo(glyph);
  103087. if (gi.uGlyphRect) {
  103088. var rowInfo = gi.rowInfo;
  103089. var colInfo = gi.colInfo;
  103090. sh.setUniform('uSamplerStrokes', gi.strokeImageInfo.imageData);
  103091. sh.setUniform('uSamplerRowStrokes', rowInfo.cellImageInfo.imageData);
  103092. sh.setUniform('uSamplerRows', rowInfo.dimImageInfo.imageData);
  103093. sh.setUniform('uSamplerColStrokes', colInfo.cellImageInfo.imageData);
  103094. sh.setUniform('uSamplerCols', colInfo.dimImageInfo.imageData);
  103095. sh.setUniform('uGridOffset', gi.uGridOffset);
  103096. sh.setUniform('uGlyphRect', gi.uGlyphRect);
  103097. sh.setUniform('uGlyphOffset', dx);
  103098. sh.bindTextures(); // afterwards, only textures need updating
  103099. // draw it
  103100. gl.drawElements(gl.TRIANGLES, 6, this.GL.UNSIGNED_SHORT, 0);
  103101. }
  103102. dx += glyph.advanceWidth;
  103103. glyphPrev = glyph;
  103104. }
  103105. } catch (err) {
  103106. _didIteratorError4 = true;
  103107. _iteratorError4 = err;
  103108. } finally {
  103109. try {
  103110. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  103111. _iterator4.return();
  103112. }
  103113. } finally {
  103114. if (_didIteratorError4) {
  103115. throw _iteratorError4;
  103116. }
  103117. }
  103118. }
  103119. } finally {
  103120. // clean up
  103121. sh.unbindShader();
  103122. this._doStroke = doStroke;
  103123. this.drawMode = drawMode;
  103124. p.pop();
  103125. }
  103126. return p;
  103127. };
  103128. },
  103129. {
  103130. '../core/constants': 272,
  103131. '../core/main': 283,
  103132. './p5.RendererGL.Retained': 336,
  103133. './p5.Shader': 338,
  103134. 'core-js/modules/es.array.iterator': 174,
  103135. 'core-js/modules/es.object.to-string': 192,
  103136. 'core-js/modules/es.regexp.exec': 196,
  103137. 'core-js/modules/es.string.iterator': 201,
  103138. 'core-js/modules/es.string.split': 206,
  103139. 'core-js/modules/es.string.sub': 207,
  103140. 'core-js/modules/es.symbol': 211,
  103141. 'core-js/modules/es.symbol.description': 209,
  103142. 'core-js/modules/es.symbol.iterator': 210,
  103143. 'core-js/modules/web.dom-collections.iterator': 244
  103144. }
  103145. ],
  103146. 341: [
  103147. function(_dereq_, module, exports) {
  103148. module.exports = {
  103149. fes: {
  103150. autoplay:
  103151. "The media that tried to play (with '{{src}}') wasn't allowed to by this browser, most likely due to the browser's autoplay policy. Check out {{link}} for more information about why.",
  103152. checkUserDefinedFns:
  103153. "It seems that you may have accidentally written {{name}} instead of {{actualName}}.\n\nPlease correct it if it's not intentional.",
  103154. fileLoadError: {
  103155. bytes:
  103156. 'It looks like there was a problem loading your file. {{suggestion}}',
  103157. font: 'It looks like there was a problem loading your font. {{suggestion}}',
  103158. gif:
  103159. 'There was some trouble loading your GIF. Make sure that your GIF is using 87a or 89a encoding.',
  103160. image:
  103161. 'It looks like there was a problem loading your image. {{suggestion}}',
  103162. json:
  103163. 'It looks like there was a problem loading your JSON file. {{suggestion}}',
  103164. large:
  103165. "If your large file isn't fetched successfully, we recommend splitting the file into smaller segments and fetching those.",
  103166. strings:
  103167. 'It looks like there was a problem loading your text file. {{suggestion}}',
  103168. suggestion:
  103169. 'Try checking if the file path ({{filePath}}) is correct, hosting the file online, or running a local server. (More info at {{link}})',
  103170. table:
  103171. 'It looks like there was a problem loading your table file. {{suggestion}}',
  103172. xml:
  103173. 'It looks like there was a problem loading your XML file. {{suggestion}}'
  103174. },
  103175. friendlyParamError: {
  103176. type_EMPTY_VAR:
  103177. '{{func}}() was expecting {{formatType}} for the {{position}} parameter, received an empty variable instead. {{location}}\n\nIf not intentional, this is often a problem with scope: {{link}}',
  103178. type_TOO_FEW_ARGUMENTS:
  103179. '{{func}}() was expecting at least {{minParams}} arguments, but received only {{argCount}}. {{location}}',
  103180. type_TOO_MANY_ARGUMENTS:
  103181. '{{func}}() was expecting no more than {{maxParams}} arguments, but received {{argCount}}. {{location}}',
  103182. type_WRONG_TYPE:
  103183. '{{func}}() was expecting {{formatType}} for the {{position}} parameter, received {{argType}} instead. {{location}}'
  103184. },
  103185. globalErrors: {
  103186. reference: {
  103187. notDefined:
  103188. 'There\'s an error due to "{{symbol}}" not being defined in the current scope {{location}}.\n\nIf you have defined it in your code, you should check its scope, spelling, and letter-casing (JavaScript is case-sensitive). For more:\n{{url1}}\n{{url2}}'
  103189. },
  103190. stackSubseq:
  103191. '▶️ Called from line {{line}} in "{{func}}" in {{file}} ({{location}})\n\n',
  103192. stackTop:
  103193. '▶️ Error at line {{line}} in "{{func}}" in {{file}} ({{location}})\n\n',
  103194. syntax: {
  103195. invalidToken:
  103196. "There's a syntax error due to a symbol that JavaScript doesn't recognize or didn't expect at its place.\nFor more: {{url}}",
  103197. unexpectedToken:
  103198. "There's a syntax error due to a symbol that wasn't expected at its place.\nUsually this is due to a typo. Check the line number in the error below for anything missing/extra.\nFor more: {{url}}"
  103199. },
  103200. type: {
  103201. notfunc:
  103202. 'There\'s an error as "{{symbol}}" could not be called as a function {{location}}.\nCheck the spelling, letter-casing (JavaScript is case-sensitive) and its type.\nFor more: {{url}}',
  103203. notfuncObj:
  103204. 'There\'s an error as "{{symbol}}" could not be called as a function {{location}}.\nVerify whether "{{obj}}" has "{{symbol}}" in it and check the spelling, letter-casing (JavaScript is case-sensitive) and its type.\nFor more: {{url}}'
  103205. }
  103206. },
  103207. libraryError:
  103208. 'An error with message "{{error}}" occured inside the p5js library when {{func}} was called {{location}}\n\nIf not stated otherwise, it might be an issue with the arguments passed to {{func}}.',
  103209. location: '(on line {{line}} in {{file}} [{{location}}])',
  103210. misspelling:
  103211. 'It seems that you may have accidentally written "{{name}}" instead of "{{actualName}}" {{location}}.\n\nPlease correct it to {{actualName}} if you wish to use the {{type}} from p5.js',
  103212. misspelling_plural:
  103213. 'It seems that you may have accidentally written "{{name}}" {{location}}.\n\nYou may have meant one of the following:\n{{suggestions}}',
  103214. misusedTopLevel:
  103215. "Did you just try to use p5.js's {{symbolName}} {{symbolType}}? If so, you may want to move it into your sketch's setup() function.\n\nFor more details, see: {{link}}",
  103216. positions: {
  103217. p_1: 'first',
  103218. p_10: 'tenth',
  103219. p_11: 'eleventh',
  103220. p_12: 'twelfth',
  103221. p_2: 'second',
  103222. p_3: 'third',
  103223. p_4: 'fourth',
  103224. p_5: 'fifth',
  103225. p_6: 'sixth',
  103226. p_7: 'seventh',
  103227. p_8: 'eighth',
  103228. p_9: 'ninth'
  103229. },
  103230. pre: '\n🌸 p5.js says: {{message}}',
  103231. welcome:
  103232. 'Welcome! This is your friendly debugger. To turn me off, switch to using p5.min.js.',
  103233. wrongPreload:
  103234. 'An error with message "{{error}}" occured inside the p5js library when "{{func}}" was called {{location}}.\n\nIf not stated otherwise, it might be due to "{{func}}" being called from preload. Nothing besides load calls (loadImage, loadJSON, loadFont, loadStrings, etc.) should be inside the preload function.'
  103235. }
  103236. };
  103237. },
  103238. {}
  103239. ],
  103240. 342: [
  103241. function(_dereq_, module, exports) {
  103242. 'use strict';
  103243. Object.defineProperty(exports, '__esModule', { value: true });
  103244. exports.languages = exports.default = void 0;
  103245. var _translation = _interopRequireDefault(_dereq_('./en/translation'));
  103246. function _interopRequireDefault(obj) {
  103247. return obj && obj.__esModule ? obj : { default: obj };
  103248. }
  103249. // Only one language is imported above. This is intentional as other languages
  103250. // will be hosted online and then downloaded whenever needed
  103251. /**
  103252. * Here, we define a default/fallback language which we can use without internet.
  103253. * You won't have to change this when adding a new language.
  103254. *
  103255. * `translation` is the namespace we are using for our initial set of strings
  103256. */ var _default = {
  103257. en: {
  103258. translation: _translation.default
  103259. }
  103260. };
  103261. /**
  103262. * This is a list of languages that we have added so far.
  103263. * If you have just added a new language (yay!), add its key to the list below
  103264. * (`en` is english, `es` es español). Also add its export to
  103265. * dev.js, which is another file in this folder.
  103266. */ exports.default = _default;
  103267. var languages = ['en', 'es'];
  103268. exports.languages = languages;
  103269. },
  103270. { './en/translation': 341 }
  103271. ]
  103272. },
  103273. {},
  103274. [267]
  103275. )(267);
  103276. });