12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688486894869048691486924869348694486954869648697486984869948700487014870248703487044870548706487074870848709487104871148712487134871448715487164871748718487194872048721487224872348724487254872648727487284872948730487314873248733487344873548736487374873848739487404874148742487434874448745487464874748748487494875048751487524875348754487554875648757487584875948760487614876248763487644876548766487674876848769487704877148772487734877448775487764877748778487794878048781487824878348784487854878648787487884878948790487914879248793487944879548796487974879848799488004880148802488034880448805488064880748808488094881048811488124881348814488154881648817488184881948820488214882248823488244882548826488274882848829488304883148832488334883448835488364883748838488394884048841488424884348844488454884648847488484884948850488514885248853488544885548856488574885848859488604886148862488634886448865488664886748868488694887048871488724887348874488754887648877488784887948880488814888248883488844888548886488874888848889488904889148892488934889448895488964889748898488994890048901489024890348904489054890648907489084890948910489114891248913489144891548916489174891848919489204892148922489234892448925489264892748928489294893048931489324893348934489354893648937489384893948940489414894248943489444894548946489474894848949489504895148952489534895448955489564895748958489594896048961489624896348964489654896648967489684896948970489714897248973489744897548976489774897848979489804898148982489834898448985489864898748988489894899048991489924899348994489954899648997489984899949000490014900249003490044900549006490074900849009490104901149012490134901449015490164901749018490194902049021490224902349024490254902649027490284902949030490314903249033490344903549036490374903849039490404904149042490434904449045490464904749048490494905049051490524905349054490554905649057490584905949060490614906249063490644906549066490674906849069490704907149072490734907449075490764907749078490794908049081490824908349084490854908649087490884908949090490914909249093490944909549096490974909849099491004910149102491034910449105491064910749108491094911049111491124911349114491154911649117491184911949120491214912249123491244912549126491274912849129491304913149132491334913449135491364913749138491394914049141491424914349144491454914649147491484914949150491514915249153491544915549156491574915849159491604916149162491634916449165491664916749168491694917049171491724917349174491754917649177491784917949180491814918249183491844918549186491874918849189491904919149192491934919449195491964919749198491994920049201492024920349204492054920649207492084920949210492114921249213492144921549216492174921849219492204922149222492234922449225492264922749228492294923049231492324923349234492354923649237492384923949240492414924249243492444924549246492474924849249492504925149252492534925449255492564925749258492594926049261492624926349264492654926649267492684926949270492714927249273492744927549276492774927849279492804928149282492834928449285492864928749288492894929049291492924929349294492954929649297492984929949300493014930249303493044930549306493074930849309493104931149312493134931449315493164931749318493194932049321493224932349324493254932649327493284932949330493314933249333493344933549336493374933849339493404934149342493434934449345493464934749348493494935049351493524935349354493554935649357493584935949360493614936249363493644936549366493674936849369493704937149372493734937449375493764937749378493794938049381493824938349384493854938649387493884938949390493914939249393493944939549396493974939849399494004940149402494034940449405494064940749408494094941049411494124941349414494154941649417494184941949420494214942249423494244942549426494274942849429494304943149432494334943449435494364943749438494394944049441494424944349444494454944649447494484944949450494514945249453494544945549456494574945849459494604946149462494634946449465494664946749468494694947049471494724947349474494754947649477494784947949480494814948249483494844948549486494874948849489494904949149492494934949449495494964949749498494994950049501495024950349504495054950649507495084950949510495114951249513495144951549516495174951849519495204952149522495234952449525495264952749528495294953049531495324953349534495354953649537495384953949540495414954249543495444954549546495474954849549495504955149552495534955449555495564955749558495594956049561495624956349564495654956649567495684956949570495714957249573495744957549576495774957849579495804958149582495834958449585495864958749588495894959049591495924959349594495954959649597495984959949600496014960249603496044960549606496074960849609496104961149612496134961449615496164961749618496194962049621496224962349624496254962649627496284962949630496314963249633496344963549636496374963849639496404964149642496434964449645496464964749648496494965049651496524965349654496554965649657496584965949660496614966249663496644966549666496674966849669496704967149672496734967449675496764967749678496794968049681496824968349684496854968649687496884968949690496914969249693496944969549696496974969849699497004970149702497034970449705497064970749708497094971049711497124971349714497154971649717497184971949720497214972249723497244972549726497274972849729497304973149732497334973449735497364973749738497394974049741497424974349744497454974649747497484974949750497514975249753497544975549756497574975849759497604976149762497634976449765497664976749768497694977049771497724977349774497754977649777497784977949780497814978249783497844978549786497874978849789497904979149792497934979449795497964979749798497994980049801498024980349804498054980649807498084980949810498114981249813498144981549816498174981849819498204982149822498234982449825498264982749828498294983049831498324983349834498354983649837498384983949840498414984249843498444984549846498474984849849498504985149852498534985449855498564985749858498594986049861498624986349864498654986649867498684986949870498714987249873498744987549876498774987849879498804988149882498834988449885498864988749888498894989049891498924989349894498954989649897498984989949900499014990249903499044990549906499074990849909499104991149912499134991449915499164991749918499194992049921499224992349924499254992649927499284992949930499314993249933499344993549936499374993849939499404994149942499434994449945499464994749948499494995049951499524995349954499554995649957499584995949960499614996249963499644996549966499674996849969499704997149972499734997449975499764997749978499794998049981499824998349984499854998649987499884998949990499914999249993499944999549996499974999849999500005000150002500035000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850029500305003150032500335003450035500365003750038500395004050041500425004350044500455004650047500485004950050500515005250053500545005550056500575005850059500605006150062500635006450065500665006750068500695007050071500725007350074500755007650077500785007950080500815008250083500845008550086500875008850089500905009150092500935009450095500965009750098500995010050101501025010350104501055010650107501085010950110501115011250113501145011550116501175011850119501205012150122501235012450125501265012750128501295013050131501325013350134501355013650137501385013950140501415014250143501445014550146501475014850149501505015150152501535015450155501565015750158501595016050161501625016350164501655016650167501685016950170501715017250173501745017550176501775017850179501805018150182501835018450185501865018750188501895019050191501925019350194501955019650197501985019950200502015020250203502045020550206502075020850209502105021150212502135021450215502165021750218502195022050221502225022350224502255022650227502285022950230502315023250233502345023550236502375023850239502405024150242502435024450245502465024750248502495025050251502525025350254502555025650257502585025950260502615026250263502645026550266502675026850269502705027150272502735027450275502765027750278502795028050281502825028350284502855028650287502885028950290502915029250293502945029550296502975029850299503005030150302503035030450305503065030750308503095031050311503125031350314503155031650317503185031950320503215032250323503245032550326503275032850329503305033150332503335033450335503365033750338503395034050341503425034350344503455034650347503485034950350503515035250353503545035550356503575035850359503605036150362503635036450365503665036750368503695037050371503725037350374503755037650377503785037950380503815038250383503845038550386503875038850389503905039150392503935039450395503965039750398503995040050401504025040350404504055040650407504085040950410504115041250413504145041550416504175041850419504205042150422504235042450425504265042750428504295043050431504325043350434504355043650437504385043950440504415044250443504445044550446504475044850449504505045150452504535045450455504565045750458504595046050461504625046350464504655046650467504685046950470504715047250473504745047550476504775047850479504805048150482504835048450485504865048750488504895049050491504925049350494504955049650497504985049950500505015050250503505045050550506505075050850509505105051150512505135051450515505165051750518505195052050521505225052350524505255052650527505285052950530505315053250533505345053550536505375053850539505405054150542505435054450545505465054750548505495055050551505525055350554505555055650557505585055950560505615056250563505645056550566505675056850569505705057150572505735057450575505765057750578505795058050581505825058350584505855058650587505885058950590505915059250593505945059550596505975059850599506005060150602506035060450605506065060750608506095061050611506125061350614506155061650617506185061950620506215062250623506245062550626506275062850629506305063150632506335063450635506365063750638506395064050641506425064350644506455064650647506485064950650506515065250653506545065550656506575065850659506605066150662506635066450665506665066750668506695067050671506725067350674506755067650677506785067950680506815068250683506845068550686506875068850689506905069150692506935069450695506965069750698506995070050701507025070350704507055070650707507085070950710507115071250713507145071550716507175071850719507205072150722507235072450725507265072750728507295073050731507325073350734507355073650737507385073950740507415074250743507445074550746507475074850749507505075150752507535075450755507565075750758507595076050761507625076350764507655076650767507685076950770507715077250773507745077550776507775077850779507805078150782507835078450785507865078750788507895079050791507925079350794507955079650797507985079950800508015080250803508045080550806508075080850809508105081150812508135081450815508165081750818508195082050821508225082350824508255082650827508285082950830508315083250833508345083550836508375083850839508405084150842508435084450845508465084750848508495085050851508525085350854508555085650857508585085950860508615086250863508645086550866508675086850869508705087150872508735087450875508765087750878508795088050881508825088350884508855088650887508885088950890508915089250893508945089550896508975089850899509005090150902509035090450905509065090750908509095091050911509125091350914509155091650917509185091950920509215092250923509245092550926509275092850929509305093150932509335093450935509365093750938509395094050941509425094350944509455094650947509485094950950509515095250953509545095550956509575095850959509605096150962509635096450965509665096750968509695097050971509725097350974509755097650977509785097950980509815098250983509845098550986509875098850989509905099150992509935099450995509965099750998509995100051001510025100351004510055100651007510085100951010510115101251013510145101551016510175101851019510205102151022510235102451025510265102751028510295103051031510325103351034510355103651037510385103951040510415104251043510445104551046510475104851049510505105151052510535105451055510565105751058510595106051061510625106351064510655106651067510685106951070510715107251073510745107551076510775107851079510805108151082510835108451085510865108751088510895109051091510925109351094510955109651097510985109951100511015110251103511045110551106511075110851109511105111151112511135111451115511165111751118511195112051121511225112351124511255112651127511285112951130511315113251133511345113551136511375113851139511405114151142511435114451145511465114751148511495115051151511525115351154511555115651157511585115951160511615116251163511645116551166511675116851169511705117151172511735117451175511765117751178511795118051181511825118351184511855118651187511885118951190511915119251193511945119551196511975119851199512005120151202512035120451205512065120751208512095121051211512125121351214512155121651217512185121951220512215122251223512245122551226512275122851229512305123151232512335123451235512365123751238512395124051241512425124351244512455124651247512485124951250512515125251253512545125551256512575125851259512605126151262512635126451265512665126751268512695127051271512725127351274512755127651277512785127951280512815128251283512845128551286512875128851289512905129151292512935129451295512965129751298512995130051301513025130351304513055130651307513085130951310513115131251313513145131551316513175131851319513205132151322513235132451325513265132751328513295133051331513325133351334513355133651337513385133951340513415134251343513445134551346513475134851349513505135151352513535135451355513565135751358513595136051361513625136351364513655136651367513685136951370513715137251373513745137551376513775137851379513805138151382513835138451385513865138751388513895139051391513925139351394513955139651397513985139951400514015140251403514045140551406514075140851409514105141151412514135141451415514165141751418514195142051421514225142351424514255142651427514285142951430514315143251433514345143551436514375143851439514405144151442514435144451445514465144751448514495145051451514525145351454514555145651457514585145951460514615146251463514645146551466514675146851469514705147151472514735147451475514765147751478514795148051481514825148351484514855148651487514885148951490514915149251493514945149551496514975149851499515005150151502515035150451505515065150751508515095151051511515125151351514515155151651517515185151951520515215152251523515245152551526515275152851529515305153151532515335153451535515365153751538515395154051541515425154351544515455154651547515485154951550515515155251553515545155551556515575155851559515605156151562515635156451565515665156751568515695157051571515725157351574515755157651577515785157951580515815158251583515845158551586515875158851589515905159151592515935159451595515965159751598515995160051601516025160351604516055160651607516085160951610516115161251613516145161551616516175161851619516205162151622516235162451625516265162751628516295163051631516325163351634516355163651637516385163951640516415164251643516445164551646516475164851649516505165151652516535165451655516565165751658516595166051661516625166351664516655166651667516685166951670516715167251673516745167551676516775167851679516805168151682516835168451685516865168751688516895169051691516925169351694516955169651697516985169951700517015170251703517045170551706517075170851709517105171151712517135171451715517165171751718517195172051721517225172351724517255172651727517285172951730517315173251733517345173551736517375173851739517405174151742517435174451745517465174751748517495175051751517525175351754517555175651757517585175951760517615176251763517645176551766517675176851769517705177151772517735177451775517765177751778517795178051781517825178351784517855178651787517885178951790517915179251793517945179551796517975179851799518005180151802518035180451805518065180751808518095181051811518125181351814518155181651817518185181951820518215182251823518245182551826518275182851829518305183151832518335183451835518365183751838518395184051841518425184351844518455184651847518485184951850518515185251853518545185551856518575185851859518605186151862518635186451865518665186751868518695187051871518725187351874518755187651877518785187951880518815188251883518845188551886518875188851889518905189151892518935189451895518965189751898518995190051901519025190351904519055190651907519085190951910519115191251913519145191551916519175191851919519205192151922519235192451925519265192751928519295193051931519325193351934519355193651937519385193951940519415194251943519445194551946519475194851949519505195151952519535195451955519565195751958519595196051961519625196351964519655196651967519685196951970519715197251973519745197551976519775197851979519805198151982519835198451985519865198751988519895199051991519925199351994519955199651997519985199952000520015200252003520045200552006520075200852009520105201152012520135201452015520165201752018520195202052021520225202352024520255202652027520285202952030520315203252033520345203552036520375203852039520405204152042520435204452045520465204752048520495205052051520525205352054520555205652057520585205952060520615206252063520645206552066520675206852069520705207152072520735207452075520765207752078520795208052081520825208352084520855208652087520885208952090520915209252093520945209552096520975209852099521005210152102521035210452105521065210752108521095211052111521125211352114521155211652117521185211952120521215212252123521245212552126521275212852129521305213152132521335213452135521365213752138521395214052141521425214352144521455214652147521485214952150521515215252153521545215552156521575215852159521605216152162521635216452165521665216752168521695217052171521725217352174521755217652177521785217952180521815218252183521845218552186521875218852189521905219152192521935219452195521965219752198521995220052201522025220352204522055220652207522085220952210522115221252213522145221552216522175221852219522205222152222522235222452225522265222752228522295223052231522325223352234522355223652237522385223952240522415224252243522445224552246522475224852249522505225152252522535225452255522565225752258522595226052261522625226352264522655226652267522685226952270522715227252273522745227552276522775227852279522805228152282522835228452285522865228752288522895229052291522925229352294522955229652297522985229952300523015230252303523045230552306523075230852309523105231152312523135231452315523165231752318523195232052321523225232352324523255232652327523285232952330523315233252333523345233552336523375233852339523405234152342523435234452345523465234752348523495235052351523525235352354523555235652357523585235952360523615236252363523645236552366523675236852369523705237152372523735237452375523765237752378523795238052381523825238352384523855238652387523885238952390523915239252393523945239552396523975239852399524005240152402524035240452405524065240752408524095241052411524125241352414524155241652417524185241952420524215242252423524245242552426524275242852429524305243152432524335243452435524365243752438524395244052441524425244352444524455244652447524485244952450524515245252453524545245552456524575245852459524605246152462524635246452465524665246752468524695247052471524725247352474524755247652477524785247952480524815248252483524845248552486524875248852489524905249152492524935249452495524965249752498524995250052501525025250352504525055250652507525085250952510525115251252513525145251552516525175251852519525205252152522525235252452525525265252752528525295253052531525325253352534525355253652537525385253952540525415254252543525445254552546525475254852549525505255152552525535255452555525565255752558525595256052561525625256352564525655256652567525685256952570525715257252573525745257552576525775257852579525805258152582525835258452585525865258752588525895259052591525925259352594525955259652597525985259952600526015260252603526045260552606526075260852609526105261152612526135261452615526165261752618526195262052621526225262352624526255262652627526285262952630526315263252633526345263552636526375263852639526405264152642526435264452645526465264752648526495265052651526525265352654526555265652657526585265952660526615266252663526645266552666526675266852669526705267152672526735267452675526765267752678526795268052681526825268352684526855268652687526885268952690526915269252693526945269552696526975269852699527005270152702527035270452705527065270752708527095271052711527125271352714527155271652717527185271952720527215272252723527245272552726527275272852729527305273152732527335273452735527365273752738527395274052741527425274352744527455274652747527485274952750527515275252753527545275552756527575275852759527605276152762527635276452765527665276752768527695277052771527725277352774527755277652777527785277952780527815278252783527845278552786527875278852789527905279152792527935279452795527965279752798527995280052801528025280352804528055280652807528085280952810528115281252813528145281552816528175281852819528205282152822528235282452825528265282752828528295283052831528325283352834528355283652837528385283952840528415284252843528445284552846528475284852849528505285152852528535285452855528565285752858528595286052861528625286352864528655286652867528685286952870528715287252873528745287552876528775287852879528805288152882528835288452885528865288752888528895289052891528925289352894528955289652897528985289952900529015290252903529045290552906529075290852909529105291152912529135291452915529165291752918529195292052921529225292352924529255292652927529285292952930529315293252933529345293552936529375293852939529405294152942529435294452945529465294752948529495295052951529525295352954529555295652957529585295952960529615296252963529645296552966529675296852969529705297152972529735297452975529765297752978529795298052981529825298352984529855298652987529885298952990529915299252993529945299552996529975299852999530005300153002530035300453005530065300753008530095301053011530125301353014530155301653017530185301953020530215302253023530245302553026530275302853029530305303153032530335303453035530365303753038530395304053041530425304353044530455304653047530485304953050530515305253053530545305553056530575305853059530605306153062530635306453065530665306753068530695307053071530725307353074530755307653077530785307953080530815308253083530845308553086530875308853089530905309153092530935309453095530965309753098530995310053101531025310353104531055310653107531085310953110531115311253113531145311553116531175311853119531205312153122531235312453125531265312753128531295313053131531325313353134531355313653137531385313953140531415314253143531445314553146531475314853149531505315153152531535315453155531565315753158531595316053161531625316353164531655316653167531685316953170531715317253173531745317553176531775317853179531805318153182531835318453185531865318753188531895319053191531925319353194531955319653197531985319953200532015320253203532045320553206532075320853209532105321153212532135321453215532165321753218532195322053221532225322353224532255322653227532285322953230532315323253233532345323553236532375323853239532405324153242532435324453245532465324753248532495325053251532525325353254532555325653257532585325953260532615326253263532645326553266532675326853269532705327153272532735327453275532765327753278532795328053281532825328353284532855328653287532885328953290532915329253293532945329553296532975329853299533005330153302533035330453305533065330753308533095331053311533125331353314533155331653317533185331953320533215332253323533245332553326533275332853329533305333153332533335333453335533365333753338533395334053341533425334353344533455334653347533485334953350533515335253353533545335553356533575335853359533605336153362533635336453365533665336753368533695337053371533725337353374533755337653377533785337953380533815338253383533845338553386533875338853389533905339153392533935339453395533965339753398533995340053401534025340353404534055340653407534085340953410534115341253413534145341553416534175341853419534205342153422534235342453425534265342753428534295343053431534325343353434534355343653437534385343953440534415344253443534445344553446534475344853449534505345153452534535345453455534565345753458534595346053461534625346353464534655346653467534685346953470534715347253473534745347553476534775347853479534805348153482534835348453485534865348753488534895349053491534925349353494534955349653497534985349953500535015350253503535045350553506535075350853509535105351153512535135351453515535165351753518535195352053521535225352353524535255352653527535285352953530535315353253533535345353553536535375353853539535405354153542535435354453545535465354753548535495355053551535525355353554535555355653557535585355953560535615356253563535645356553566535675356853569535705357153572535735357453575535765357753578535795358053581535825358353584535855358653587535885358953590535915359253593535945359553596535975359853599536005360153602536035360453605536065360753608536095361053611536125361353614536155361653617536185361953620536215362253623536245362553626536275362853629536305363153632536335363453635536365363753638536395364053641536425364353644536455364653647536485364953650536515365253653536545365553656536575365853659536605366153662536635366453665536665366753668536695367053671536725367353674536755367653677536785367953680536815368253683536845368553686536875368853689536905369153692536935369453695536965369753698536995370053701537025370353704537055370653707537085370953710537115371253713537145371553716537175371853719537205372153722537235372453725537265372753728537295373053731537325373353734537355373653737537385373953740537415374253743537445374553746537475374853749537505375153752537535375453755537565375753758537595376053761537625376353764537655376653767537685376953770537715377253773537745377553776537775377853779537805378153782537835378453785537865378753788537895379053791537925379353794537955379653797537985379953800538015380253803538045380553806538075380853809538105381153812538135381453815538165381753818538195382053821538225382353824538255382653827538285382953830538315383253833538345383553836538375383853839538405384153842538435384453845538465384753848538495385053851538525385353854538555385653857538585385953860538615386253863538645386553866538675386853869538705387153872538735387453875538765387753878538795388053881538825388353884538855388653887538885388953890538915389253893538945389553896538975389853899539005390153902539035390453905539065390753908539095391053911539125391353914539155391653917539185391953920539215392253923539245392553926539275392853929539305393153932539335393453935539365393753938539395394053941539425394353944539455394653947539485394953950539515395253953539545395553956539575395853959539605396153962539635396453965539665396753968539695397053971539725397353974539755397653977539785397953980539815398253983539845398553986539875398853989539905399153992539935399453995539965399753998539995400054001540025400354004540055400654007540085400954010540115401254013540145401554016540175401854019540205402154022540235402454025540265402754028540295403054031540325403354034540355403654037540385403954040540415404254043540445404554046540475404854049540505405154052540535405454055540565405754058540595406054061540625406354064540655406654067540685406954070540715407254073540745407554076540775407854079540805408154082540835408454085540865408754088540895409054091540925409354094540955409654097540985409954100541015410254103541045410554106541075410854109541105411154112541135411454115541165411754118541195412054121541225412354124541255412654127541285412954130541315413254133541345413554136541375413854139541405414154142541435414454145541465414754148541495415054151541525415354154541555415654157541585415954160541615416254163541645416554166541675416854169541705417154172541735417454175541765417754178541795418054181541825418354184541855418654187541885418954190541915419254193541945419554196541975419854199542005420154202542035420454205542065420754208542095421054211542125421354214542155421654217542185421954220542215422254223542245422554226542275422854229542305423154232542335423454235542365423754238542395424054241542425424354244542455424654247542485424954250542515425254253542545425554256542575425854259542605426154262542635426454265542665426754268542695427054271542725427354274542755427654277542785427954280542815428254283542845428554286542875428854289542905429154292542935429454295542965429754298542995430054301543025430354304543055430654307543085430954310543115431254313543145431554316543175431854319543205432154322543235432454325543265432754328543295433054331543325433354334543355433654337543385433954340543415434254343543445434554346543475434854349543505435154352543535435454355543565435754358543595436054361543625436354364543655436654367543685436954370543715437254373543745437554376543775437854379543805438154382543835438454385543865438754388543895439054391543925439354394543955439654397543985439954400544015440254403544045440554406544075440854409544105441154412544135441454415544165441754418544195442054421544225442354424544255442654427544285442954430544315443254433544345443554436544375443854439544405444154442544435444454445544465444754448544495445054451544525445354454544555445654457544585445954460544615446254463544645446554466544675446854469544705447154472544735447454475544765447754478544795448054481544825448354484544855448654487544885448954490544915449254493544945449554496544975449854499545005450154502545035450454505545065450754508545095451054511545125451354514545155451654517545185451954520545215452254523545245452554526545275452854529545305453154532545335453454535545365453754538545395454054541545425454354544545455454654547545485454954550545515455254553545545455554556545575455854559545605456154562545635456454565545665456754568545695457054571545725457354574545755457654577545785457954580545815458254583545845458554586545875458854589545905459154592545935459454595545965459754598545995460054601546025460354604546055460654607546085460954610546115461254613546145461554616546175461854619546205462154622546235462454625546265462754628546295463054631546325463354634546355463654637546385463954640546415464254643546445464554646546475464854649546505465154652546535465454655546565465754658546595466054661546625466354664546655466654667546685466954670546715467254673546745467554676546775467854679546805468154682546835468454685546865468754688546895469054691546925469354694546955469654697546985469954700547015470254703547045470554706547075470854709547105471154712547135471454715547165471754718547195472054721547225472354724547255472654727547285472954730547315473254733547345473554736547375473854739547405474154742547435474454745547465474754748547495475054751547525475354754547555475654757547585475954760547615476254763547645476554766547675476854769547705477154772547735477454775547765477754778547795478054781547825478354784547855478654787547885478954790547915479254793547945479554796547975479854799548005480154802548035480454805548065480754808548095481054811548125481354814548155481654817548185481954820548215482254823548245482554826548275482854829548305483154832548335483454835548365483754838548395484054841548425484354844548455484654847548485484954850548515485254853548545485554856548575485854859548605486154862548635486454865548665486754868548695487054871548725487354874548755487654877548785487954880548815488254883548845488554886548875488854889548905489154892548935489454895548965489754898548995490054901549025490354904549055490654907549085490954910549115491254913549145491554916549175491854919549205492154922549235492454925549265492754928549295493054931549325493354934549355493654937549385493954940549415494254943549445494554946549475494854949549505495154952549535495454955549565495754958549595496054961549625496354964549655496654967549685496954970549715497254973549745497554976549775497854979549805498154982549835498454985549865498754988549895499054991549925499354994549955499654997549985499955000550015500255003550045500555006550075500855009550105501155012550135501455015550165501755018550195502055021550225502355024550255502655027550285502955030550315503255033550345503555036550375503855039550405504155042550435504455045550465504755048550495505055051550525505355054550555505655057550585505955060550615506255063550645506555066550675506855069550705507155072550735507455075550765507755078550795508055081550825508355084550855508655087550885508955090550915509255093550945509555096550975509855099551005510155102551035510455105551065510755108551095511055111551125511355114551155511655117551185511955120551215512255123551245512555126551275512855129551305513155132551335513455135551365513755138551395514055141551425514355144551455514655147551485514955150551515515255153551545515555156551575515855159551605516155162551635516455165551665516755168551695517055171551725517355174551755517655177551785517955180551815518255183551845518555186551875518855189551905519155192551935519455195551965519755198551995520055201552025520355204552055520655207552085520955210552115521255213552145521555216552175521855219552205522155222552235522455225552265522755228552295523055231552325523355234552355523655237552385523955240552415524255243552445524555246552475524855249552505525155252552535525455255552565525755258552595526055261552625526355264552655526655267552685526955270552715527255273552745527555276552775527855279552805528155282552835528455285552865528755288552895529055291552925529355294552955529655297552985529955300553015530255303553045530555306553075530855309553105531155312553135531455315553165531755318553195532055321553225532355324553255532655327553285532955330553315533255333553345533555336553375533855339553405534155342553435534455345553465534755348553495535055351553525535355354553555535655357553585535955360553615536255363553645536555366553675536855369553705537155372553735537455375553765537755378553795538055381553825538355384553855538655387553885538955390553915539255393553945539555396553975539855399554005540155402554035540455405554065540755408554095541055411554125541355414554155541655417554185541955420554215542255423554245542555426554275542855429554305543155432554335543455435554365543755438554395544055441554425544355444554455544655447554485544955450554515545255453554545545555456554575545855459554605546155462554635546455465554665546755468554695547055471554725547355474554755547655477554785547955480554815548255483554845548555486554875548855489554905549155492554935549455495554965549755498554995550055501555025550355504555055550655507555085550955510555115551255513555145551555516555175551855519555205552155522555235552455525555265552755528555295553055531555325553355534555355553655537555385553955540555415554255543555445554555546555475554855549555505555155552555535555455555555565555755558555595556055561555625556355564555655556655567555685556955570555715557255573555745557555576555775557855579555805558155582555835558455585555865558755588555895559055591555925559355594555955559655597555985559955600556015560255603556045560555606556075560855609556105561155612556135561455615556165561755618556195562055621556225562355624556255562655627556285562955630556315563255633556345563555636556375563855639556405564155642556435564455645556465564755648556495565055651556525565355654556555565655657556585565955660556615566255663556645566555666556675566855669556705567155672556735567455675556765567755678556795568055681556825568355684556855568655687556885568955690556915569255693556945569555696556975569855699557005570155702557035570455705557065570755708557095571055711557125571355714557155571655717557185571955720557215572255723557245572555726557275572855729557305573155732557335573455735557365573755738557395574055741557425574355744557455574655747557485574955750557515575255753557545575555756557575575855759557605576155762557635576455765557665576755768557695577055771557725577355774557755577655777557785577955780557815578255783557845578555786557875578855789557905579155792557935579455795557965579755798557995580055801558025580355804558055580655807558085580955810558115581255813558145581555816558175581855819558205582155822558235582455825558265582755828558295583055831558325583355834558355583655837558385583955840558415584255843558445584555846558475584855849558505585155852558535585455855558565585755858558595586055861558625586355864558655586655867558685586955870558715587255873558745587555876558775587855879558805588155882558835588455885558865588755888558895589055891558925589355894558955589655897558985589955900559015590255903559045590555906559075590855909559105591155912559135591455915559165591755918559195592055921559225592355924559255592655927559285592955930559315593255933559345593555936559375593855939559405594155942559435594455945559465594755948559495595055951559525595355954559555595655957559585595955960559615596255963559645596555966559675596855969559705597155972559735597455975559765597755978559795598055981559825598355984559855598655987559885598955990559915599255993559945599555996559975599855999560005600156002560035600456005560065600756008560095601056011560125601356014560155601656017560185601956020560215602256023560245602556026560275602856029560305603156032560335603456035560365603756038560395604056041560425604356044560455604656047560485604956050560515605256053560545605556056560575605856059560605606156062560635606456065560665606756068560695607056071560725607356074560755607656077560785607956080560815608256083560845608556086560875608856089560905609156092560935609456095560965609756098560995610056101561025610356104561055610656107561085610956110561115611256113561145611556116561175611856119561205612156122561235612456125561265612756128561295613056131561325613356134561355613656137561385613956140561415614256143561445614556146561475614856149561505615156152561535615456155561565615756158561595616056161561625616356164561655616656167561685616956170561715617256173561745617556176561775617856179561805618156182561835618456185561865618756188561895619056191561925619356194561955619656197561985619956200562015620256203562045620556206562075620856209562105621156212562135621456215562165621756218562195622056221562225622356224562255622656227562285622956230562315623256233562345623556236562375623856239562405624156242562435624456245562465624756248562495625056251562525625356254562555625656257562585625956260562615626256263562645626556266562675626856269562705627156272562735627456275562765627756278562795628056281562825628356284562855628656287562885628956290562915629256293562945629556296562975629856299563005630156302563035630456305563065630756308563095631056311563125631356314563155631656317563185631956320563215632256323563245632556326563275632856329563305633156332563335633456335563365633756338563395634056341563425634356344563455634656347563485634956350563515635256353563545635556356563575635856359563605636156362563635636456365563665636756368563695637056371563725637356374563755637656377563785637956380563815638256383563845638556386563875638856389563905639156392563935639456395563965639756398563995640056401564025640356404564055640656407564085640956410564115641256413564145641556416564175641856419564205642156422564235642456425564265642756428564295643056431564325643356434564355643656437564385643956440564415644256443564445644556446564475644856449564505645156452564535645456455564565645756458564595646056461564625646356464564655646656467564685646956470564715647256473564745647556476564775647856479564805648156482564835648456485564865648756488564895649056491564925649356494564955649656497564985649956500565015650256503565045650556506565075650856509565105651156512565135651456515565165651756518565195652056521565225652356524565255652656527565285652956530565315653256533565345653556536565375653856539565405654156542565435654456545565465654756548565495655056551565525655356554565555655656557565585655956560565615656256563565645656556566565675656856569565705657156572565735657456575565765657756578565795658056581565825658356584565855658656587565885658956590565915659256593565945659556596565975659856599566005660156602566035660456605566065660756608566095661056611566125661356614566155661656617566185661956620566215662256623566245662556626566275662856629566305663156632566335663456635566365663756638566395664056641566425664356644566455664656647566485664956650566515665256653566545665556656566575665856659566605666156662566635666456665566665666756668566695667056671566725667356674566755667656677566785667956680566815668256683566845668556686566875668856689566905669156692566935669456695566965669756698566995670056701567025670356704567055670656707567085670956710567115671256713567145671556716567175671856719567205672156722567235672456725567265672756728567295673056731567325673356734567355673656737567385673956740567415674256743567445674556746567475674856749567505675156752567535675456755567565675756758567595676056761567625676356764567655676656767567685676956770567715677256773567745677556776567775677856779567805678156782567835678456785567865678756788567895679056791567925679356794567955679656797567985679956800568015680256803568045680556806568075680856809568105681156812568135681456815568165681756818568195682056821568225682356824568255682656827568285682956830568315683256833568345683556836568375683856839568405684156842568435684456845568465684756848568495685056851568525685356854568555685656857568585685956860568615686256863568645686556866568675686856869568705687156872568735687456875568765687756878568795688056881568825688356884568855688656887568885688956890568915689256893568945689556896568975689856899569005690156902569035690456905569065690756908569095691056911569125691356914569155691656917569185691956920569215692256923569245692556926569275692856929569305693156932569335693456935569365693756938569395694056941569425694356944569455694656947569485694956950569515695256953569545695556956569575695856959569605696156962569635696456965569665696756968569695697056971569725697356974569755697656977569785697956980569815698256983569845698556986569875698856989569905699156992569935699456995569965699756998569995700057001570025700357004570055700657007570085700957010570115701257013570145701557016570175701857019570205702157022570235702457025570265702757028570295703057031570325703357034570355703657037570385703957040570415704257043570445704557046570475704857049570505705157052570535705457055570565705757058570595706057061570625706357064570655706657067570685706957070570715707257073570745707557076570775707857079570805708157082570835708457085570865708757088570895709057091570925709357094570955709657097570985709957100571015710257103571045710557106571075710857109571105711157112571135711457115571165711757118571195712057121571225712357124571255712657127571285712957130571315713257133571345713557136571375713857139571405714157142571435714457145571465714757148571495715057151571525715357154571555715657157571585715957160571615716257163571645716557166571675716857169571705717157172571735717457175571765717757178571795718057181571825718357184571855718657187571885718957190571915719257193571945719557196571975719857199572005720157202572035720457205572065720757208572095721057211572125721357214572155721657217572185721957220572215722257223572245722557226572275722857229572305723157232572335723457235572365723757238572395724057241572425724357244572455724657247572485724957250572515725257253572545725557256572575725857259572605726157262572635726457265572665726757268572695727057271572725727357274572755727657277572785727957280572815728257283572845728557286572875728857289572905729157292572935729457295572965729757298572995730057301573025730357304573055730657307573085730957310573115731257313573145731557316573175731857319573205732157322573235732457325573265732757328573295733057331573325733357334573355733657337573385733957340573415734257343573445734557346573475734857349573505735157352573535735457355573565735757358573595736057361573625736357364573655736657367573685736957370573715737257373573745737557376573775737857379573805738157382573835738457385573865738757388573895739057391573925739357394573955739657397573985739957400574015740257403574045740557406574075740857409574105741157412574135741457415574165741757418574195742057421574225742357424574255742657427574285742957430574315743257433574345743557436574375743857439574405744157442574435744457445574465744757448574495745057451574525745357454574555745657457574585745957460574615746257463574645746557466574675746857469574705747157472574735747457475574765747757478574795748057481574825748357484574855748657487574885748957490574915749257493574945749557496574975749857499575005750157502575035750457505575065750757508575095751057511575125751357514575155751657517575185751957520575215752257523575245752557526575275752857529575305753157532575335753457535575365753757538575395754057541575425754357544575455754657547575485754957550575515755257553575545755557556575575755857559575605756157562575635756457565575665756757568575695757057571575725757357574575755757657577575785757957580575815758257583575845758557586575875758857589575905759157592575935759457595575965759757598575995760057601576025760357604576055760657607576085760957610576115761257613576145761557616576175761857619576205762157622576235762457625576265762757628576295763057631576325763357634576355763657637576385763957640576415764257643576445764557646576475764857649576505765157652576535765457655576565765757658576595766057661576625766357664576655766657667576685766957670576715767257673576745767557676576775767857679576805768157682576835768457685576865768757688576895769057691576925769357694576955769657697576985769957700577015770257703577045770557706577075770857709577105771157712577135771457715577165771757718577195772057721577225772357724577255772657727577285772957730577315773257733577345773557736577375773857739577405774157742577435774457745577465774757748577495775057751577525775357754577555775657757577585775957760577615776257763577645776557766577675776857769577705777157772577735777457775577765777757778577795778057781577825778357784577855778657787577885778957790577915779257793577945779557796577975779857799578005780157802578035780457805578065780757808578095781057811578125781357814578155781657817578185781957820578215782257823578245782557826578275782857829578305783157832578335783457835578365783757838578395784057841578425784357844578455784657847578485784957850578515785257853578545785557856578575785857859578605786157862578635786457865578665786757868578695787057871578725787357874578755787657877578785787957880578815788257883578845788557886578875788857889578905789157892578935789457895578965789757898578995790057901579025790357904579055790657907579085790957910579115791257913579145791557916579175791857919579205792157922579235792457925579265792757928579295793057931579325793357934579355793657937579385793957940579415794257943579445794557946579475794857949579505795157952579535795457955579565795757958579595796057961579625796357964579655796657967579685796957970579715797257973579745797557976579775797857979579805798157982579835798457985579865798757988579895799057991579925799357994579955799657997579985799958000580015800258003580045800558006580075800858009580105801158012580135801458015580165801758018580195802058021580225802358024580255802658027580285802958030580315803258033580345803558036580375803858039580405804158042580435804458045580465804758048580495805058051580525805358054580555805658057580585805958060580615806258063580645806558066580675806858069580705807158072580735807458075580765807758078580795808058081580825808358084580855808658087580885808958090580915809258093580945809558096580975809858099581005810158102581035810458105581065810758108581095811058111581125811358114581155811658117581185811958120581215812258123581245812558126581275812858129581305813158132581335813458135581365813758138581395814058141581425814358144581455814658147581485814958150581515815258153581545815558156581575815858159581605816158162581635816458165581665816758168581695817058171581725817358174581755817658177581785817958180581815818258183581845818558186581875818858189581905819158192581935819458195581965819758198581995820058201582025820358204582055820658207582085820958210582115821258213582145821558216582175821858219582205822158222582235822458225582265822758228582295823058231582325823358234582355823658237582385823958240582415824258243582445824558246582475824858249582505825158252582535825458255582565825758258582595826058261582625826358264582655826658267582685826958270582715827258273582745827558276582775827858279582805828158282582835828458285582865828758288582895829058291582925829358294582955829658297582985829958300583015830258303583045830558306583075830858309583105831158312583135831458315583165831758318583195832058321583225832358324583255832658327583285832958330583315833258333583345833558336583375833858339583405834158342583435834458345583465834758348583495835058351583525835358354583555835658357583585835958360583615836258363583645836558366583675836858369583705837158372583735837458375583765837758378583795838058381583825838358384583855838658387583885838958390583915839258393583945839558396583975839858399584005840158402584035840458405584065840758408584095841058411584125841358414584155841658417584185841958420584215842258423584245842558426584275842858429584305843158432584335843458435584365843758438584395844058441584425844358444584455844658447584485844958450584515845258453584545845558456584575845858459584605846158462584635846458465584665846758468584695847058471584725847358474584755847658477584785847958480584815848258483584845848558486584875848858489584905849158492584935849458495584965849758498584995850058501585025850358504585055850658507585085850958510585115851258513585145851558516585175851858519585205852158522585235852458525585265852758528585295853058531585325853358534585355853658537585385853958540585415854258543585445854558546585475854858549585505855158552585535855458555585565855758558585595856058561585625856358564585655856658567585685856958570585715857258573585745857558576585775857858579585805858158582585835858458585585865858758588585895859058591585925859358594585955859658597585985859958600586015860258603586045860558606586075860858609586105861158612586135861458615586165861758618586195862058621586225862358624586255862658627586285862958630586315863258633586345863558636586375863858639586405864158642586435864458645586465864758648586495865058651586525865358654586555865658657586585865958660586615866258663586645866558666586675866858669586705867158672586735867458675586765867758678586795868058681586825868358684586855868658687586885868958690586915869258693586945869558696586975869858699587005870158702587035870458705587065870758708587095871058711587125871358714587155871658717587185871958720587215872258723587245872558726587275872858729587305873158732587335873458735587365873758738587395874058741587425874358744587455874658747587485874958750587515875258753587545875558756587575875858759587605876158762587635876458765587665876758768587695877058771587725877358774587755877658777587785877958780587815878258783587845878558786587875878858789587905879158792587935879458795587965879758798587995880058801588025880358804588055880658807588085880958810588115881258813588145881558816588175881858819588205882158822588235882458825588265882758828588295883058831588325883358834588355883658837588385883958840588415884258843588445884558846588475884858849588505885158852588535885458855588565885758858588595886058861588625886358864588655886658867588685886958870588715887258873588745887558876588775887858879588805888158882588835888458885588865888758888588895889058891588925889358894588955889658897588985889958900589015890258903589045890558906589075890858909589105891158912589135891458915589165891758918589195892058921589225892358924589255892658927589285892958930589315893258933589345893558936589375893858939589405894158942589435894458945589465894758948589495895058951589525895358954589555895658957589585895958960589615896258963589645896558966589675896858969589705897158972589735897458975589765897758978589795898058981589825898358984589855898658987589885898958990589915899258993589945899558996589975899858999590005900159002590035900459005590065900759008590095901059011590125901359014590155901659017590185901959020590215902259023590245902559026590275902859029590305903159032590335903459035590365903759038590395904059041590425904359044590455904659047590485904959050590515905259053590545905559056590575905859059590605906159062590635906459065590665906759068590695907059071590725907359074590755907659077590785907959080590815908259083590845908559086590875908859089590905909159092590935909459095590965909759098590995910059101591025910359104591055910659107591085910959110591115911259113591145911559116591175911859119591205912159122591235912459125591265912759128591295913059131591325913359134591355913659137591385913959140591415914259143591445914559146591475914859149591505915159152591535915459155591565915759158591595916059161591625916359164591655916659167591685916959170591715917259173591745917559176591775917859179591805918159182591835918459185591865918759188591895919059191591925919359194591955919659197591985919959200592015920259203592045920559206592075920859209592105921159212592135921459215592165921759218592195922059221592225922359224592255922659227592285922959230592315923259233592345923559236592375923859239592405924159242592435924459245592465924759248592495925059251592525925359254592555925659257592585925959260592615926259263592645926559266592675926859269592705927159272592735927459275592765927759278592795928059281592825928359284592855928659287592885928959290592915929259293592945929559296592975929859299593005930159302593035930459305593065930759308593095931059311593125931359314593155931659317593185931959320593215932259323593245932559326593275932859329593305933159332593335933459335593365933759338593395934059341593425934359344593455934659347593485934959350593515935259353593545935559356593575935859359593605936159362593635936459365593665936759368593695937059371593725937359374593755937659377593785937959380593815938259383593845938559386593875938859389593905939159392593935939459395593965939759398593995940059401594025940359404594055940659407594085940959410594115941259413594145941559416594175941859419594205942159422594235942459425594265942759428594295943059431594325943359434594355943659437594385943959440594415944259443594445944559446594475944859449594505945159452594535945459455594565945759458594595946059461594625946359464594655946659467594685946959470594715947259473594745947559476594775947859479594805948159482594835948459485594865948759488594895949059491594925949359494594955949659497594985949959500595015950259503595045950559506595075950859509595105951159512595135951459515595165951759518595195952059521595225952359524595255952659527595285952959530595315953259533595345953559536595375953859539595405954159542595435954459545595465954759548595495955059551595525955359554595555955659557595585955959560595615956259563595645956559566595675956859569595705957159572595735957459575595765957759578595795958059581595825958359584595855958659587595885958959590595915959259593595945959559596595975959859599596005960159602596035960459605596065960759608596095961059611596125961359614596155961659617596185961959620596215962259623596245962559626596275962859629596305963159632596335963459635596365963759638596395964059641596425964359644596455964659647596485964959650596515965259653596545965559656596575965859659596605966159662596635966459665596665966759668596695967059671596725967359674596755967659677596785967959680596815968259683596845968559686596875968859689596905969159692596935969459695596965969759698596995970059701597025970359704597055970659707597085970959710597115971259713597145971559716597175971859719597205972159722597235972459725597265972759728597295973059731597325973359734597355973659737597385973959740597415974259743597445974559746597475974859749597505975159752597535975459755597565975759758597595976059761597625976359764597655976659767597685976959770597715977259773597745977559776597775977859779597805978159782597835978459785597865978759788597895979059791597925979359794597955979659797597985979959800598015980259803598045980559806598075980859809598105981159812598135981459815598165981759818598195982059821598225982359824598255982659827598285982959830598315983259833598345983559836598375983859839598405984159842598435984459845598465984759848598495985059851598525985359854598555985659857598585985959860598615986259863598645986559866598675986859869598705987159872598735987459875598765987759878598795988059881598825988359884598855988659887598885988959890598915989259893598945989559896598975989859899599005990159902599035990459905599065990759908599095991059911599125991359914599155991659917599185991959920599215992259923599245992559926599275992859929599305993159932599335993459935599365993759938599395994059941599425994359944599455994659947599485994959950599515995259953599545995559956599575995859959599605996159962599635996459965599665996759968599695997059971599725997359974599755997659977599785997959980599815998259983599845998559986599875998859989599905999159992599935999459995599965999759998599996000060001600026000360004600056000660007600086000960010600116001260013600146001560016600176001860019600206002160022600236002460025600266002760028600296003060031600326003360034600356003660037600386003960040600416004260043600446004560046600476004860049600506005160052600536005460055600566005760058600596006060061600626006360064600656006660067600686006960070600716007260073600746007560076600776007860079600806008160082600836008460085600866008760088600896009060091600926009360094600956009660097600986009960100601016010260103601046010560106601076010860109601106011160112601136011460115601166011760118601196012060121601226012360124601256012660127601286012960130601316013260133601346013560136601376013860139601406014160142601436014460145601466014760148601496015060151601526015360154601556015660157601586015960160601616016260163601646016560166601676016860169601706017160172601736017460175601766017760178601796018060181601826018360184601856018660187601886018960190601916019260193601946019560196601976019860199602006020160202602036020460205602066020760208602096021060211602126021360214602156021660217602186021960220602216022260223602246022560226602276022860229602306023160232602336023460235602366023760238602396024060241602426024360244602456024660247602486024960250602516025260253602546025560256602576025860259602606026160262602636026460265602666026760268602696027060271602726027360274602756027660277602786027960280602816028260283602846028560286602876028860289602906029160292602936029460295602966029760298602996030060301603026030360304603056030660307603086030960310603116031260313603146031560316603176031860319603206032160322603236032460325603266032760328603296033060331603326033360334603356033660337603386033960340603416034260343603446034560346603476034860349603506035160352603536035460355603566035760358603596036060361603626036360364603656036660367603686036960370603716037260373603746037560376603776037860379603806038160382603836038460385603866038760388603896039060391603926039360394603956039660397603986039960400604016040260403604046040560406604076040860409604106041160412604136041460415604166041760418604196042060421604226042360424604256042660427604286042960430604316043260433604346043560436604376043860439604406044160442604436044460445604466044760448604496045060451604526045360454604556045660457604586045960460604616046260463604646046560466604676046860469604706047160472604736047460475604766047760478604796048060481604826048360484604856048660487604886048960490604916049260493604946049560496604976049860499605006050160502605036050460505605066050760508605096051060511605126051360514605156051660517605186051960520605216052260523605246052560526605276052860529605306053160532605336053460535605366053760538605396054060541605426054360544605456054660547605486054960550605516055260553605546055560556605576055860559605606056160562605636056460565605666056760568605696057060571605726057360574605756057660577605786057960580605816058260583605846058560586605876058860589605906059160592605936059460595605966059760598605996060060601606026060360604606056060660607606086060960610606116061260613606146061560616606176061860619606206062160622606236062460625606266062760628606296063060631606326063360634606356063660637606386063960640606416064260643606446064560646606476064860649606506065160652606536065460655606566065760658606596066060661606626066360664606656066660667606686066960670606716067260673606746067560676606776067860679606806068160682606836068460685606866068760688606896069060691606926069360694606956069660697606986069960700607016070260703607046070560706607076070860709607106071160712607136071460715607166071760718607196072060721607226072360724607256072660727607286072960730607316073260733607346073560736607376073860739607406074160742607436074460745607466074760748607496075060751607526075360754607556075660757607586075960760607616076260763607646076560766607676076860769607706077160772607736077460775607766077760778607796078060781607826078360784607856078660787607886078960790607916079260793607946079560796607976079860799608006080160802608036080460805608066080760808608096081060811608126081360814608156081660817608186081960820608216082260823608246082560826608276082860829608306083160832608336083460835608366083760838608396084060841608426084360844608456084660847608486084960850608516085260853608546085560856608576085860859608606086160862608636086460865608666086760868608696087060871608726087360874608756087660877608786087960880608816088260883608846088560886608876088860889608906089160892608936089460895608966089760898608996090060901609026090360904609056090660907609086090960910609116091260913609146091560916609176091860919609206092160922609236092460925609266092760928609296093060931609326093360934609356093660937609386093960940609416094260943609446094560946609476094860949609506095160952609536095460955609566095760958609596096060961609626096360964609656096660967609686096960970609716097260973609746097560976609776097860979609806098160982609836098460985609866098760988609896099060991609926099360994609956099660997609986099961000610016100261003610046100561006610076100861009610106101161012610136101461015610166101761018610196102061021610226102361024610256102661027610286102961030610316103261033610346103561036610376103861039610406104161042610436104461045610466104761048610496105061051610526105361054610556105661057610586105961060610616106261063610646106561066610676106861069610706107161072610736107461075610766107761078610796108061081610826108361084610856108661087610886108961090610916109261093610946109561096610976109861099611006110161102611036110461105611066110761108611096111061111611126111361114611156111661117611186111961120611216112261123611246112561126611276112861129611306113161132611336113461135611366113761138611396114061141611426114361144611456114661147611486114961150611516115261153611546115561156611576115861159611606116161162611636116461165611666116761168611696117061171611726117361174611756117661177611786117961180611816118261183611846118561186611876118861189611906119161192611936119461195611966119761198611996120061201612026120361204612056120661207612086120961210612116121261213612146121561216612176121861219612206122161222612236122461225612266122761228612296123061231612326123361234612356123661237612386123961240612416124261243612446124561246612476124861249612506125161252612536125461255612566125761258612596126061261612626126361264612656126661267612686126961270612716127261273612746127561276612776127861279612806128161282612836128461285612866128761288612896129061291612926129361294612956129661297612986129961300613016130261303613046130561306613076130861309613106131161312613136131461315613166131761318613196132061321613226132361324613256132661327613286132961330613316133261333613346133561336613376133861339613406134161342613436134461345613466134761348613496135061351613526135361354613556135661357613586135961360613616136261363613646136561366613676136861369613706137161372613736137461375613766137761378613796138061381613826138361384613856138661387613886138961390613916139261393613946139561396613976139861399614006140161402614036140461405614066140761408614096141061411614126141361414614156141661417614186141961420614216142261423614246142561426614276142861429614306143161432614336143461435614366143761438614396144061441614426144361444614456144661447614486144961450614516145261453614546145561456614576145861459614606146161462614636146461465614666146761468614696147061471614726147361474614756147661477614786147961480614816148261483614846148561486614876148861489614906149161492614936149461495614966149761498614996150061501615026150361504615056150661507615086150961510615116151261513615146151561516615176151861519615206152161522615236152461525615266152761528615296153061531615326153361534615356153661537615386153961540615416154261543615446154561546615476154861549615506155161552615536155461555615566155761558615596156061561615626156361564615656156661567615686156961570615716157261573615746157561576615776157861579615806158161582615836158461585615866158761588615896159061591615926159361594615956159661597615986159961600616016160261603616046160561606616076160861609616106161161612616136161461615616166161761618616196162061621616226162361624616256162661627616286162961630616316163261633616346163561636616376163861639616406164161642616436164461645616466164761648616496165061651616526165361654616556165661657616586165961660616616166261663616646166561666616676166861669616706167161672616736167461675616766167761678616796168061681616826168361684616856168661687616886168961690616916169261693616946169561696616976169861699617006170161702617036170461705617066170761708617096171061711617126171361714617156171661717617186171961720617216172261723617246172561726617276172861729617306173161732617336173461735617366173761738617396174061741617426174361744617456174661747617486174961750617516175261753617546175561756617576175861759617606176161762617636176461765617666176761768617696177061771617726177361774617756177661777617786177961780617816178261783617846178561786617876178861789617906179161792617936179461795617966179761798617996180061801618026180361804618056180661807618086180961810618116181261813618146181561816618176181861819618206182161822618236182461825618266182761828618296183061831618326183361834618356183661837618386183961840618416184261843618446184561846618476184861849618506185161852618536185461855618566185761858618596186061861618626186361864618656186661867618686186961870618716187261873618746187561876618776187861879618806188161882618836188461885618866188761888618896189061891618926189361894618956189661897618986189961900619016190261903619046190561906619076190861909619106191161912619136191461915619166191761918619196192061921619226192361924619256192661927619286192961930619316193261933619346193561936619376193861939619406194161942619436194461945619466194761948619496195061951619526195361954619556195661957619586195961960619616196261963619646196561966619676196861969619706197161972619736197461975619766197761978619796198061981619826198361984619856198661987619886198961990619916199261993619946199561996619976199861999620006200162002620036200462005620066200762008620096201062011620126201362014620156201662017620186201962020620216202262023620246202562026620276202862029620306203162032620336203462035620366203762038620396204062041620426204362044620456204662047620486204962050620516205262053620546205562056620576205862059620606206162062620636206462065620666206762068620696207062071620726207362074620756207662077620786207962080620816208262083620846208562086620876208862089620906209162092620936209462095620966209762098620996210062101621026210362104621056210662107621086210962110621116211262113621146211562116621176211862119621206212162122621236212462125621266212762128621296213062131621326213362134621356213662137621386213962140621416214262143621446214562146621476214862149621506215162152621536215462155621566215762158621596216062161621626216362164621656216662167621686216962170621716217262173621746217562176621776217862179621806218162182621836218462185621866218762188621896219062191621926219362194621956219662197621986219962200622016220262203622046220562206622076220862209622106221162212622136221462215622166221762218622196222062221622226222362224622256222662227622286222962230622316223262233622346223562236622376223862239622406224162242622436224462245622466224762248622496225062251622526225362254622556225662257622586225962260622616226262263622646226562266622676226862269622706227162272622736227462275622766227762278622796228062281622826228362284622856228662287622886228962290622916229262293622946229562296622976229862299623006230162302623036230462305623066230762308623096231062311623126231362314623156231662317623186231962320623216232262323623246232562326623276232862329623306233162332623336233462335623366233762338623396234062341623426234362344623456234662347623486234962350623516235262353623546235562356623576235862359623606236162362623636236462365623666236762368623696237062371623726237362374623756237662377623786237962380623816238262383623846238562386623876238862389623906239162392623936239462395623966239762398623996240062401624026240362404624056240662407624086240962410624116241262413624146241562416624176241862419624206242162422624236242462425624266242762428624296243062431624326243362434624356243662437624386243962440624416244262443624446244562446624476244862449624506245162452624536245462455624566245762458624596246062461624626246362464624656246662467624686246962470624716247262473624746247562476624776247862479624806248162482624836248462485624866248762488624896249062491624926249362494624956249662497624986249962500625016250262503625046250562506625076250862509625106251162512625136251462515625166251762518625196252062521625226252362524625256252662527625286252962530625316253262533625346253562536625376253862539625406254162542625436254462545625466254762548625496255062551625526255362554625556255662557625586255962560625616256262563625646256562566625676256862569625706257162572625736257462575625766257762578625796258062581625826258362584625856258662587625886258962590625916259262593625946259562596625976259862599626006260162602626036260462605626066260762608626096261062611626126261362614626156261662617626186261962620626216262262623626246262562626626276262862629626306263162632626336263462635626366263762638626396264062641626426264362644626456264662647626486264962650626516265262653626546265562656626576265862659626606266162662626636266462665626666266762668626696267062671626726267362674626756267662677626786267962680626816268262683626846268562686626876268862689626906269162692626936269462695626966269762698626996270062701627026270362704627056270662707627086270962710627116271262713627146271562716627176271862719627206272162722627236272462725627266272762728627296273062731627326273362734627356273662737627386273962740627416274262743627446274562746627476274862749627506275162752627536275462755627566275762758627596276062761627626276362764627656276662767627686276962770627716277262773627746277562776627776277862779627806278162782627836278462785627866278762788627896279062791627926279362794627956279662797627986279962800628016280262803628046280562806628076280862809628106281162812628136281462815628166281762818628196282062821628226282362824628256282662827628286282962830628316283262833628346283562836628376283862839628406284162842628436284462845628466284762848628496285062851628526285362854628556285662857628586285962860628616286262863628646286562866628676286862869628706287162872628736287462875628766287762878628796288062881628826288362884628856288662887628886288962890628916289262893628946289562896628976289862899629006290162902629036290462905629066290762908629096291062911629126291362914629156291662917629186291962920629216292262923629246292562926629276292862929629306293162932629336293462935629366293762938629396294062941629426294362944629456294662947629486294962950629516295262953629546295562956629576295862959629606296162962629636296462965629666296762968629696297062971629726297362974629756297662977629786297962980629816298262983629846298562986629876298862989629906299162992629936299462995629966299762998629996300063001630026300363004630056300663007630086300963010630116301263013630146301563016630176301863019630206302163022630236302463025630266302763028630296303063031630326303363034630356303663037630386303963040630416304263043630446304563046630476304863049630506305163052630536305463055630566305763058630596306063061630626306363064630656306663067630686306963070630716307263073630746307563076630776307863079630806308163082630836308463085630866308763088630896309063091630926309363094630956309663097630986309963100631016310263103631046310563106631076310863109631106311163112631136311463115631166311763118631196312063121631226312363124631256312663127631286312963130631316313263133631346313563136631376313863139631406314163142631436314463145631466314763148631496315063151631526315363154631556315663157631586315963160631616316263163631646316563166631676316863169631706317163172631736317463175631766317763178631796318063181631826318363184631856318663187631886318963190631916319263193631946319563196631976319863199632006320163202632036320463205632066320763208632096321063211632126321363214632156321663217632186321963220632216322263223632246322563226632276322863229632306323163232632336323463235632366323763238632396324063241632426324363244632456324663247632486324963250632516325263253632546325563256632576325863259632606326163262632636326463265632666326763268632696327063271632726327363274632756327663277632786327963280632816328263283632846328563286632876328863289632906329163292632936329463295632966329763298632996330063301633026330363304633056330663307633086330963310633116331263313633146331563316633176331863319633206332163322633236332463325633266332763328633296333063331633326333363334633356333663337633386333963340633416334263343633446334563346633476334863349633506335163352633536335463355633566335763358633596336063361633626336363364633656336663367633686336963370633716337263373633746337563376633776337863379633806338163382633836338463385633866338763388633896339063391633926339363394633956339663397633986339963400634016340263403634046340563406634076340863409634106341163412634136341463415634166341763418634196342063421634226342363424634256342663427634286342963430634316343263433634346343563436634376343863439634406344163442634436344463445634466344763448634496345063451634526345363454634556345663457634586345963460634616346263463634646346563466634676346863469634706347163472634736347463475634766347763478634796348063481634826348363484634856348663487634886348963490634916349263493634946349563496634976349863499635006350163502635036350463505635066350763508635096351063511635126351363514635156351663517635186351963520635216352263523635246352563526635276352863529635306353163532635336353463535635366353763538635396354063541635426354363544635456354663547635486354963550635516355263553635546355563556635576355863559635606356163562635636356463565635666356763568635696357063571635726357363574635756357663577635786357963580635816358263583635846358563586635876358863589635906359163592635936359463595635966359763598635996360063601636026360363604636056360663607636086360963610636116361263613636146361563616636176361863619636206362163622636236362463625636266362763628636296363063631636326363363634636356363663637636386363963640636416364263643636446364563646636476364863649636506365163652636536365463655636566365763658636596366063661636626366363664636656366663667636686366963670636716367263673636746367563676636776367863679636806368163682636836368463685636866368763688636896369063691636926369363694636956369663697636986369963700637016370263703637046370563706637076370863709637106371163712637136371463715637166371763718637196372063721637226372363724637256372663727637286372963730637316373263733637346373563736637376373863739637406374163742637436374463745637466374763748637496375063751637526375363754637556375663757637586375963760637616376263763637646376563766637676376863769637706377163772637736377463775637766377763778637796378063781637826378363784637856378663787637886378963790637916379263793637946379563796637976379863799638006380163802638036380463805638066380763808638096381063811638126381363814638156381663817638186381963820638216382263823638246382563826638276382863829638306383163832638336383463835638366383763838638396384063841638426384363844638456384663847638486384963850638516385263853638546385563856638576385863859638606386163862638636386463865638666386763868638696387063871638726387363874638756387663877638786387963880638816388263883638846388563886638876388863889638906389163892638936389463895638966389763898638996390063901639026390363904639056390663907639086390963910639116391263913639146391563916639176391863919639206392163922639236392463925639266392763928639296393063931639326393363934639356393663937639386393963940639416394263943639446394563946639476394863949639506395163952639536395463955639566395763958639596396063961639626396363964639656396663967639686396963970639716397263973639746397563976639776397863979639806398163982639836398463985639866398763988639896399063991639926399363994639956399663997639986399964000640016400264003640046400564006640076400864009640106401164012640136401464015640166401764018640196402064021640226402364024640256402664027640286402964030640316403264033640346403564036640376403864039640406404164042640436404464045640466404764048640496405064051640526405364054640556405664057640586405964060640616406264063640646406564066640676406864069640706407164072640736407464075640766407764078640796408064081640826408364084640856408664087640886408964090640916409264093640946409564096640976409864099641006410164102641036410464105641066410764108641096411064111641126411364114641156411664117641186411964120641216412264123641246412564126641276412864129641306413164132641336413464135641366413764138641396414064141641426414364144641456414664147641486414964150641516415264153641546415564156641576415864159641606416164162641636416464165641666416764168641696417064171641726417364174641756417664177641786417964180641816418264183641846418564186641876418864189641906419164192641936419464195641966419764198641996420064201642026420364204642056420664207642086420964210642116421264213642146421564216642176421864219642206422164222642236422464225642266422764228642296423064231642326423364234642356423664237642386423964240642416424264243642446424564246642476424864249642506425164252642536425464255642566425764258642596426064261642626426364264642656426664267642686426964270642716427264273642746427564276642776427864279642806428164282642836428464285642866428764288642896429064291642926429364294642956429664297642986429964300643016430264303643046430564306643076430864309643106431164312643136431464315643166431764318643196432064321643226432364324643256432664327643286432964330643316433264333643346433564336643376433864339643406434164342643436434464345643466434764348643496435064351643526435364354643556435664357643586435964360643616436264363643646436564366643676436864369643706437164372643736437464375643766437764378643796438064381643826438364384643856438664387643886438964390643916439264393643946439564396643976439864399644006440164402644036440464405644066440764408644096441064411644126441364414644156441664417644186441964420644216442264423644246442564426644276442864429644306443164432644336443464435644366443764438644396444064441644426444364444644456444664447644486444964450644516445264453644546445564456644576445864459644606446164462644636446464465644666446764468644696447064471644726447364474644756447664477644786447964480644816448264483644846448564486644876448864489644906449164492644936449464495644966449764498644996450064501645026450364504645056450664507645086450964510645116451264513645146451564516645176451864519645206452164522645236452464525645266452764528645296453064531645326453364534645356453664537645386453964540645416454264543645446454564546645476454864549645506455164552645536455464555645566455764558645596456064561645626456364564645656456664567645686456964570645716457264573645746457564576645776457864579645806458164582645836458464585645866458764588645896459064591645926459364594645956459664597645986459964600646016460264603646046460564606646076460864609646106461164612646136461464615646166461764618646196462064621646226462364624646256462664627646286462964630646316463264633646346463564636646376463864639646406464164642646436464464645646466464764648646496465064651646526465364654646556465664657646586465964660646616466264663646646466564666646676466864669646706467164672646736467464675646766467764678646796468064681646826468364684646856468664687646886468964690646916469264693646946469564696646976469864699647006470164702647036470464705647066470764708647096471064711647126471364714647156471664717647186471964720647216472264723647246472564726647276472864729647306473164732647336473464735647366473764738647396474064741647426474364744647456474664747647486474964750647516475264753647546475564756647576475864759647606476164762647636476464765647666476764768647696477064771647726477364774647756477664777647786477964780647816478264783647846478564786647876478864789647906479164792647936479464795647966479764798647996480064801648026480364804648056480664807648086480964810648116481264813648146481564816648176481864819648206482164822648236482464825648266482764828648296483064831648326483364834648356483664837648386483964840648416484264843648446484564846648476484864849648506485164852648536485464855648566485764858648596486064861648626486364864648656486664867648686486964870648716487264873648746487564876648776487864879648806488164882648836488464885648866488764888648896489064891648926489364894648956489664897648986489964900649016490264903649046490564906649076490864909649106491164912649136491464915649166491764918649196492064921649226492364924649256492664927649286492964930649316493264933649346493564936649376493864939649406494164942649436494464945649466494764948649496495064951649526495364954649556495664957649586495964960649616496264963649646496564966649676496864969649706497164972649736497464975649766497764978649796498064981649826498364984649856498664987649886498964990649916499264993649946499564996649976499864999650006500165002650036500465005650066500765008650096501065011650126501365014650156501665017650186501965020650216502265023650246502565026650276502865029650306503165032650336503465035650366503765038650396504065041650426504365044650456504665047650486504965050650516505265053650546505565056650576505865059650606506165062650636506465065650666506765068650696507065071650726507365074650756507665077650786507965080650816508265083650846508565086650876508865089650906509165092650936509465095650966509765098650996510065101651026510365104651056510665107651086510965110651116511265113651146511565116651176511865119651206512165122651236512465125651266512765128651296513065131651326513365134651356513665137651386513965140651416514265143651446514565146651476514865149651506515165152651536515465155651566515765158651596516065161651626516365164651656516665167651686516965170651716517265173651746517565176651776517865179651806518165182651836518465185651866518765188651896519065191651926519365194651956519665197651986519965200652016520265203652046520565206652076520865209652106521165212652136521465215652166521765218652196522065221652226522365224652256522665227652286522965230652316523265233652346523565236652376523865239652406524165242652436524465245652466524765248652496525065251652526525365254652556525665257652586525965260652616526265263652646526565266652676526865269652706527165272652736527465275652766527765278652796528065281652826528365284652856528665287652886528965290652916529265293652946529565296652976529865299653006530165302653036530465305653066530765308653096531065311653126531365314653156531665317653186531965320653216532265323653246532565326653276532865329653306533165332653336533465335653366533765338653396534065341653426534365344653456534665347653486534965350653516535265353653546535565356653576535865359653606536165362653636536465365653666536765368653696537065371653726537365374653756537665377653786537965380653816538265383653846538565386653876538865389653906539165392653936539465395653966539765398653996540065401654026540365404654056540665407654086540965410654116541265413654146541565416654176541865419654206542165422654236542465425654266542765428654296543065431654326543365434654356543665437654386543965440654416544265443654446544565446654476544865449654506545165452654536545465455654566545765458654596546065461654626546365464654656546665467654686546965470654716547265473654746547565476654776547865479654806548165482654836548465485654866548765488654896549065491654926549365494654956549665497654986549965500655016550265503655046550565506655076550865509655106551165512655136551465515655166551765518655196552065521655226552365524655256552665527655286552965530655316553265533655346553565536655376553865539655406554165542655436554465545655466554765548655496555065551655526555365554655556555665557655586555965560655616556265563655646556565566655676556865569655706557165572655736557465575655766557765578655796558065581655826558365584655856558665587655886558965590655916559265593655946559565596655976559865599656006560165602656036560465605656066560765608656096561065611656126561365614656156561665617656186561965620656216562265623656246562565626656276562865629656306563165632656336563465635656366563765638656396564065641656426564365644656456564665647656486564965650656516565265653656546565565656656576565865659656606566165662656636566465665656666566765668656696567065671656726567365674656756567665677656786567965680656816568265683656846568565686656876568865689656906569165692656936569465695656966569765698656996570065701657026570365704657056570665707657086570965710657116571265713657146571565716657176571865719657206572165722657236572465725657266572765728657296573065731657326573365734657356573665737657386573965740657416574265743657446574565746657476574865749657506575165752657536575465755657566575765758657596576065761657626576365764657656576665767657686576965770657716577265773657746577565776657776577865779657806578165782657836578465785657866578765788657896579065791657926579365794657956579665797657986579965800658016580265803658046580565806658076580865809658106581165812658136581465815658166581765818658196582065821658226582365824658256582665827658286582965830658316583265833658346583565836658376583865839658406584165842658436584465845658466584765848658496585065851658526585365854658556585665857658586585965860658616586265863658646586565866658676586865869658706587165872658736587465875658766587765878658796588065881658826588365884658856588665887658886588965890658916589265893658946589565896658976589865899659006590165902659036590465905659066590765908659096591065911659126591365914659156591665917659186591965920659216592265923659246592565926659276592865929659306593165932659336593465935659366593765938659396594065941659426594365944659456594665947659486594965950659516595265953659546595565956659576595865959659606596165962659636596465965659666596765968659696597065971659726597365974659756597665977659786597965980659816598265983659846598565986659876598865989659906599165992659936599465995659966599765998659996600066001660026600366004660056600666007660086600966010660116601266013660146601566016660176601866019660206602166022660236602466025660266602766028660296603066031660326603366034660356603666037660386603966040660416604266043660446604566046660476604866049660506605166052660536605466055660566605766058660596606066061660626606366064660656606666067660686606966070660716607266073660746607566076660776607866079660806608166082660836608466085660866608766088660896609066091660926609366094660956609666097660986609966100661016610266103661046610566106661076610866109661106611166112661136611466115661166611766118661196612066121661226612366124661256612666127661286612966130661316613266133661346613566136661376613866139661406614166142661436614466145661466614766148661496615066151661526615366154661556615666157661586615966160661616616266163661646616566166661676616866169661706617166172661736617466175661766617766178661796618066181661826618366184661856618666187661886618966190661916619266193661946619566196661976619866199662006620166202662036620466205662066620766208662096621066211662126621366214662156621666217662186621966220662216622266223662246622566226662276622866229662306623166232662336623466235662366623766238662396624066241662426624366244662456624666247662486624966250662516625266253662546625566256662576625866259662606626166262662636626466265662666626766268662696627066271662726627366274662756627666277662786627966280662816628266283662846628566286662876628866289662906629166292662936629466295662966629766298662996630066301663026630366304663056630666307663086630966310663116631266313663146631566316663176631866319663206632166322663236632466325663266632766328663296633066331663326633366334663356633666337663386633966340663416634266343663446634566346663476634866349663506635166352663536635466355663566635766358663596636066361663626636366364663656636666367663686636966370663716637266373663746637566376663776637866379663806638166382663836638466385663866638766388663896639066391663926639366394663956639666397663986639966400664016640266403664046640566406664076640866409664106641166412664136641466415664166641766418664196642066421664226642366424664256642666427664286642966430664316643266433664346643566436664376643866439664406644166442664436644466445664466644766448664496645066451664526645366454664556645666457664586645966460664616646266463664646646566466664676646866469664706647166472664736647466475664766647766478664796648066481664826648366484664856648666487664886648966490664916649266493664946649566496664976649866499665006650166502665036650466505665066650766508665096651066511665126651366514665156651666517665186651966520665216652266523665246652566526665276652866529665306653166532665336653466535665366653766538665396654066541665426654366544665456654666547665486654966550665516655266553665546655566556665576655866559665606656166562665636656466565665666656766568665696657066571665726657366574665756657666577665786657966580665816658266583665846658566586665876658866589665906659166592665936659466595665966659766598665996660066601666026660366604666056660666607666086660966610666116661266613666146661566616666176661866619666206662166622666236662466625666266662766628666296663066631666326663366634666356663666637666386663966640666416664266643666446664566646666476664866649666506665166652666536665466655666566665766658666596666066661666626666366664666656666666667666686666966670666716667266673666746667566676666776667866679666806668166682666836668466685666866668766688666896669066691666926669366694666956669666697666986669966700667016670266703667046670566706667076670866709667106671166712667136671466715667166671766718667196672066721667226672366724667256672666727667286672966730667316673266733667346673566736667376673866739667406674166742667436674466745667466674766748667496675066751667526675366754667556675666757667586675966760667616676266763667646676566766667676676866769667706677166772667736677466775667766677766778667796678066781667826678366784667856678666787667886678966790667916679266793667946679566796667976679866799668006680166802668036680466805668066680766808668096681066811668126681366814668156681666817668186681966820668216682266823668246682566826668276682866829668306683166832668336683466835668366683766838668396684066841668426684366844668456684666847668486684966850668516685266853668546685566856668576685866859668606686166862668636686466865668666686766868668696687066871668726687366874668756687666877668786687966880668816688266883668846688566886668876688866889668906689166892668936689466895668966689766898668996690066901669026690366904669056690666907669086690966910669116691266913669146691566916669176691866919669206692166922669236692466925669266692766928669296693066931669326693366934669356693666937669386693966940669416694266943669446694566946669476694866949669506695166952669536695466955669566695766958669596696066961669626696366964669656696666967669686696966970669716697266973669746697566976669776697866979669806698166982669836698466985669866698766988669896699066991669926699366994669956699666997669986699967000670016700267003670046700567006670076700867009670106701167012670136701467015670166701767018670196702067021670226702367024670256702667027670286702967030670316703267033670346703567036670376703867039670406704167042670436704467045670466704767048670496705067051670526705367054670556705667057670586705967060670616706267063670646706567066670676706867069670706707167072670736707467075670766707767078670796708067081670826708367084670856708667087670886708967090670916709267093670946709567096670976709867099671006710167102671036710467105671066710767108671096711067111671126711367114671156711667117671186711967120671216712267123671246712567126671276712867129671306713167132671336713467135671366713767138671396714067141671426714367144671456714667147671486714967150671516715267153671546715567156671576715867159671606716167162671636716467165671666716767168671696717067171671726717367174671756717667177671786717967180671816718267183671846718567186671876718867189671906719167192671936719467195671966719767198671996720067201672026720367204672056720667207672086720967210672116721267213672146721567216672176721867219672206722167222672236722467225672266722767228672296723067231672326723367234672356723667237672386723967240672416724267243672446724567246672476724867249672506725167252672536725467255672566725767258672596726067261672626726367264672656726667267672686726967270672716727267273672746727567276672776727867279672806728167282672836728467285672866728767288672896729067291672926729367294672956729667297672986729967300673016730267303673046730567306673076730867309673106731167312673136731467315673166731767318673196732067321673226732367324673256732667327673286732967330673316733267333673346733567336673376733867339673406734167342673436734467345673466734767348673496735067351673526735367354673556735667357673586735967360673616736267363673646736567366673676736867369673706737167372673736737467375673766737767378673796738067381673826738367384673856738667387673886738967390673916739267393673946739567396673976739867399674006740167402674036740467405674066740767408674096741067411674126741367414674156741667417674186741967420674216742267423674246742567426674276742867429674306743167432674336743467435674366743767438674396744067441674426744367444674456744667447674486744967450674516745267453674546745567456674576745867459674606746167462674636746467465674666746767468674696747067471674726747367474674756747667477674786747967480674816748267483674846748567486674876748867489674906749167492674936749467495674966749767498674996750067501675026750367504675056750667507675086750967510675116751267513675146751567516675176751867519675206752167522675236752467525675266752767528675296753067531675326753367534675356753667537675386753967540675416754267543675446754567546675476754867549675506755167552675536755467555675566755767558675596756067561675626756367564675656756667567675686756967570675716757267573675746757567576675776757867579675806758167582675836758467585675866758767588675896759067591675926759367594675956759667597675986759967600676016760267603676046760567606676076760867609676106761167612676136761467615676166761767618676196762067621676226762367624676256762667627676286762967630676316763267633676346763567636676376763867639676406764167642676436764467645676466764767648676496765067651676526765367654676556765667657676586765967660676616766267663676646766567666676676766867669676706767167672676736767467675676766767767678676796768067681676826768367684676856768667687676886768967690676916769267693676946769567696676976769867699677006770167702677036770467705677066770767708677096771067711677126771367714677156771667717677186771967720677216772267723677246772567726677276772867729677306773167732677336773467735677366773767738677396774067741677426774367744677456774667747677486774967750677516775267753677546775567756677576775867759677606776167762677636776467765677666776767768677696777067771677726777367774677756777667777677786777967780677816778267783677846778567786677876778867789677906779167792677936779467795677966779767798677996780067801678026780367804678056780667807678086780967810678116781267813678146781567816678176781867819678206782167822678236782467825678266782767828678296783067831678326783367834678356783667837678386783967840678416784267843678446784567846678476784867849678506785167852678536785467855678566785767858678596786067861678626786367864678656786667867678686786967870678716787267873678746787567876678776787867879678806788167882678836788467885678866788767888678896789067891678926789367894678956789667897678986789967900679016790267903679046790567906679076790867909679106791167912679136791467915679166791767918679196792067921679226792367924679256792667927679286792967930679316793267933679346793567936679376793867939679406794167942679436794467945679466794767948679496795067951679526795367954679556795667957679586795967960679616796267963679646796567966679676796867969679706797167972679736797467975679766797767978679796798067981679826798367984679856798667987679886798967990679916799267993679946799567996679976799867999680006800168002680036800468005680066800768008680096801068011680126801368014680156801668017680186801968020680216802268023680246802568026680276802868029680306803168032680336803468035680366803768038680396804068041680426804368044680456804668047680486804968050680516805268053680546805568056680576805868059680606806168062680636806468065680666806768068680696807068071680726807368074680756807668077680786807968080680816808268083680846808568086680876808868089680906809168092680936809468095680966809768098680996810068101681026810368104681056810668107681086810968110681116811268113681146811568116681176811868119681206812168122681236812468125681266812768128681296813068131681326813368134681356813668137681386813968140681416814268143681446814568146681476814868149681506815168152681536815468155681566815768158681596816068161681626816368164681656816668167681686816968170681716817268173681746817568176681776817868179681806818168182681836818468185681866818768188681896819068191681926819368194681956819668197681986819968200682016820268203682046820568206682076820868209682106821168212682136821468215682166821768218682196822068221682226822368224682256822668227682286822968230682316823268233682346823568236682376823868239682406824168242682436824468245682466824768248682496825068251682526825368254682556825668257682586825968260682616826268263682646826568266682676826868269682706827168272682736827468275682766827768278682796828068281682826828368284682856828668287682886828968290682916829268293682946829568296682976829868299683006830168302683036830468305683066830768308683096831068311683126831368314683156831668317683186831968320683216832268323683246832568326683276832868329683306833168332683336833468335683366833768338683396834068341683426834368344683456834668347683486834968350683516835268353683546835568356683576835868359683606836168362683636836468365683666836768368683696837068371683726837368374683756837668377683786837968380683816838268383683846838568386683876838868389683906839168392683936839468395683966839768398683996840068401684026840368404684056840668407684086840968410684116841268413684146841568416684176841868419684206842168422684236842468425684266842768428684296843068431684326843368434684356843668437684386843968440684416844268443684446844568446684476844868449684506845168452684536845468455684566845768458684596846068461684626846368464684656846668467684686846968470684716847268473684746847568476684776847868479684806848168482684836848468485684866848768488684896849068491684926849368494684956849668497684986849968500685016850268503685046850568506685076850868509685106851168512685136851468515685166851768518685196852068521685226852368524685256852668527685286852968530685316853268533685346853568536685376853868539685406854168542685436854468545685466854768548685496855068551685526855368554685556855668557685586855968560685616856268563685646856568566685676856868569685706857168572685736857468575685766857768578685796858068581685826858368584685856858668587685886858968590685916859268593685946859568596685976859868599686006860168602686036860468605686066860768608686096861068611686126861368614686156861668617686186861968620686216862268623686246862568626686276862868629686306863168632686336863468635686366863768638686396864068641686426864368644686456864668647686486864968650686516865268653686546865568656686576865868659686606866168662686636866468665686666866768668686696867068671686726867368674686756867668677686786867968680686816868268683686846868568686686876868868689686906869168692686936869468695686966869768698686996870068701687026870368704687056870668707687086870968710687116871268713687146871568716687176871868719687206872168722687236872468725687266872768728687296873068731687326873368734687356873668737687386873968740687416874268743687446874568746687476874868749687506875168752687536875468755687566875768758687596876068761687626876368764687656876668767687686876968770687716877268773687746877568776687776877868779687806878168782687836878468785687866878768788687896879068791687926879368794687956879668797687986879968800688016880268803688046880568806688076880868809688106881168812688136881468815688166881768818688196882068821688226882368824688256882668827688286882968830688316883268833688346883568836688376883868839688406884168842688436884468845688466884768848688496885068851688526885368854688556885668857688586885968860688616886268863688646886568866688676886868869688706887168872688736887468875688766887768878688796888068881688826888368884688856888668887688886888968890688916889268893688946889568896688976889868899689006890168902689036890468905689066890768908689096891068911689126891368914689156891668917689186891968920689216892268923689246892568926689276892868929689306893168932689336893468935689366893768938689396894068941689426894368944689456894668947689486894968950689516895268953689546895568956689576895868959689606896168962689636896468965689666896768968689696897068971689726897368974689756897668977689786897968980689816898268983689846898568986689876898868989689906899168992689936899468995689966899768998689996900069001690026900369004690056900669007690086900969010690116901269013690146901569016690176901869019690206902169022690236902469025690266902769028690296903069031690326903369034690356903669037690386903969040690416904269043690446904569046690476904869049690506905169052690536905469055690566905769058690596906069061690626906369064690656906669067690686906969070690716907269073690746907569076690776907869079690806908169082690836908469085690866908769088690896909069091690926909369094690956909669097690986909969100691016910269103691046910569106691076910869109691106911169112691136911469115691166911769118691196912069121691226912369124691256912669127691286912969130691316913269133691346913569136691376913869139691406914169142691436914469145691466914769148691496915069151691526915369154691556915669157691586915969160691616916269163691646916569166691676916869169691706917169172691736917469175691766917769178691796918069181691826918369184691856918669187691886918969190691916919269193691946919569196691976919869199692006920169202692036920469205692066920769208692096921069211692126921369214692156921669217692186921969220692216922269223692246922569226692276922869229692306923169232692336923469235692366923769238692396924069241692426924369244692456924669247692486924969250692516925269253692546925569256692576925869259692606926169262692636926469265692666926769268692696927069271692726927369274692756927669277692786927969280692816928269283692846928569286692876928869289692906929169292692936929469295692966929769298692996930069301693026930369304693056930669307693086930969310693116931269313693146931569316693176931869319693206932169322693236932469325693266932769328693296933069331693326933369334693356933669337693386933969340693416934269343693446934569346693476934869349693506935169352693536935469355693566935769358693596936069361693626936369364693656936669367693686936969370693716937269373693746937569376693776937869379693806938169382693836938469385693866938769388693896939069391693926939369394693956939669397693986939969400694016940269403694046940569406694076940869409694106941169412694136941469415694166941769418694196942069421694226942369424694256942669427694286942969430694316943269433694346943569436694376943869439694406944169442694436944469445694466944769448694496945069451694526945369454694556945669457694586945969460694616946269463694646946569466694676946869469694706947169472694736947469475694766947769478694796948069481694826948369484694856948669487694886948969490694916949269493694946949569496694976949869499695006950169502695036950469505695066950769508695096951069511695126951369514695156951669517695186951969520695216952269523695246952569526695276952869529695306953169532695336953469535695366953769538695396954069541695426954369544695456954669547695486954969550695516955269553695546955569556695576955869559695606956169562695636956469565695666956769568695696957069571695726957369574695756957669577695786957969580695816958269583695846958569586695876958869589695906959169592695936959469595695966959769598695996960069601696026960369604696056960669607696086960969610696116961269613696146961569616696176961869619696206962169622696236962469625696266962769628696296963069631696326963369634696356963669637696386963969640696416964269643696446964569646696476964869649696506965169652696536965469655696566965769658696596966069661696626966369664696656966669667696686966969670696716967269673696746967569676696776967869679696806968169682696836968469685696866968769688696896969069691696926969369694696956969669697696986969969700697016970269703697046970569706697076970869709697106971169712697136971469715697166971769718697196972069721697226972369724697256972669727697286972969730697316973269733697346973569736697376973869739697406974169742697436974469745697466974769748697496975069751697526975369754697556975669757697586975969760697616976269763697646976569766697676976869769697706977169772697736977469775697766977769778697796978069781697826978369784697856978669787697886978969790697916979269793697946979569796697976979869799698006980169802698036980469805698066980769808698096981069811698126981369814698156981669817698186981969820698216982269823698246982569826698276982869829698306983169832698336983469835698366983769838698396984069841698426984369844698456984669847698486984969850698516985269853698546985569856698576985869859698606986169862698636986469865698666986769868698696987069871698726987369874698756987669877698786987969880698816988269883698846988569886698876988869889698906989169892698936989469895698966989769898698996990069901699026990369904699056990669907699086990969910699116991269913699146991569916699176991869919699206992169922699236992469925699266992769928699296993069931699326993369934699356993669937699386993969940699416994269943699446994569946699476994869949699506995169952699536995469955699566995769958699596996069961699626996369964699656996669967699686996969970699716997269973699746997569976699776997869979699806998169982699836998469985699866998769988699896999069991699926999369994699956999669997699986999970000700017000270003700047000570006700077000870009700107001170012700137001470015700167001770018700197002070021700227002370024700257002670027700287002970030700317003270033700347003570036700377003870039700407004170042700437004470045700467004770048700497005070051700527005370054700557005670057700587005970060700617006270063700647006570066700677006870069700707007170072700737007470075700767007770078700797008070081700827008370084700857008670087700887008970090700917009270093700947009570096700977009870099701007010170102701037010470105701067010770108701097011070111701127011370114701157011670117701187011970120701217012270123701247012570126701277012870129701307013170132701337013470135701367013770138701397014070141701427014370144701457014670147701487014970150701517015270153701547015570156701577015870159701607016170162701637016470165701667016770168701697017070171701727017370174701757017670177701787017970180701817018270183701847018570186701877018870189701907019170192701937019470195701967019770198701997020070201702027020370204702057020670207702087020970210702117021270213702147021570216702177021870219702207022170222702237022470225702267022770228702297023070231702327023370234702357023670237702387023970240702417024270243702447024570246702477024870249702507025170252702537025470255702567025770258702597026070261702627026370264702657026670267702687026970270702717027270273702747027570276702777027870279702807028170282702837028470285702867028770288702897029070291702927029370294702957029670297702987029970300703017030270303703047030570306703077030870309703107031170312703137031470315703167031770318703197032070321703227032370324703257032670327703287032970330703317033270333703347033570336703377033870339703407034170342703437034470345703467034770348703497035070351703527035370354703557035670357703587035970360703617036270363703647036570366703677036870369703707037170372703737037470375703767037770378703797038070381703827038370384703857038670387703887038970390703917039270393703947039570396703977039870399704007040170402704037040470405704067040770408704097041070411704127041370414704157041670417704187041970420704217042270423704247042570426704277042870429704307043170432704337043470435704367043770438704397044070441704427044370444704457044670447704487044970450704517045270453704547045570456704577045870459704607046170462704637046470465704667046770468704697047070471704727047370474704757047670477704787047970480704817048270483704847048570486704877048870489704907049170492704937049470495704967049770498704997050070501705027050370504705057050670507705087050970510705117051270513705147051570516705177051870519705207052170522705237052470525705267052770528705297053070531705327053370534705357053670537705387053970540705417054270543705447054570546705477054870549705507055170552705537055470555705567055770558705597056070561705627056370564705657056670567705687056970570705717057270573705747057570576705777057870579705807058170582705837058470585705867058770588705897059070591705927059370594705957059670597705987059970600706017060270603706047060570606706077060870609706107061170612706137061470615706167061770618706197062070621706227062370624706257062670627706287062970630706317063270633706347063570636706377063870639706407064170642706437064470645706467064770648706497065070651706527065370654706557065670657706587065970660706617066270663706647066570666706677066870669706707067170672706737067470675706767067770678706797068070681706827068370684706857068670687706887068970690706917069270693706947069570696706977069870699707007070170702707037070470705707067070770708707097071070711707127071370714707157071670717707187071970720707217072270723707247072570726707277072870729707307073170732707337073470735707367073770738707397074070741707427074370744707457074670747707487074970750707517075270753707547075570756707577075870759707607076170762707637076470765707667076770768707697077070771707727077370774707757077670777707787077970780707817078270783707847078570786707877078870789707907079170792707937079470795707967079770798707997080070801708027080370804708057080670807708087080970810708117081270813708147081570816708177081870819708207082170822708237082470825708267082770828708297083070831708327083370834708357083670837708387083970840708417084270843708447084570846708477084870849708507085170852708537085470855708567085770858708597086070861708627086370864708657086670867708687086970870708717087270873708747087570876708777087870879708807088170882708837088470885708867088770888708897089070891708927089370894708957089670897708987089970900709017090270903709047090570906709077090870909709107091170912709137091470915709167091770918709197092070921709227092370924709257092670927709287092970930709317093270933709347093570936709377093870939709407094170942709437094470945709467094770948709497095070951709527095370954709557095670957709587095970960709617096270963709647096570966709677096870969709707097170972709737097470975709767097770978709797098070981709827098370984709857098670987709887098970990709917099270993709947099570996709977099870999710007100171002710037100471005710067100771008710097101071011710127101371014710157101671017710187101971020710217102271023710247102571026710277102871029 |
- (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
- "use strict";
- module.exports = asPromise;
- /**
- * Callback as used by {@link util.asPromise}.
- * @typedef asPromiseCallback
- * @type {function}
- * @param {Error|null} error Error, if any
- * @param {...*} params Additional arguments
- * @returns {undefined}
- */
- /**
- * Returns a promise from a node-style callback function.
- * @memberof util
- * @param {asPromiseCallback} fn Function to call
- * @param {*} ctx Function context
- * @param {...*} params Function arguments
- * @returns {Promise<*>} Promisified function
- */
- function asPromise(fn, ctx/*, varargs */) {
- var params = new Array(arguments.length - 1),
- offset = 0,
- index = 2,
- pending = true;
- while (index < arguments.length)
- params[offset++] = arguments[index++];
- return new Promise(function executor(resolve, reject) {
- params[offset] = function callback(err/*, varargs */) {
- if (pending) {
- pending = false;
- if (err)
- reject(err);
- else {
- var params = new Array(arguments.length - 1),
- offset = 0;
- while (offset < params.length)
- params[offset++] = arguments[offset];
- resolve.apply(null, params);
- }
- }
- };
- try {
- fn.apply(ctx || null, params);
- } catch (err) {
- if (pending) {
- pending = false;
- reject(err);
- }
- }
- });
- }
- },{}],2:[function(require,module,exports){
- "use strict";
- /**
- * A minimal base64 implementation for number arrays.
- * @memberof util
- * @namespace
- */
- var base64 = exports;
- /**
- * Calculates the byte length of a base64 encoded string.
- * @param {string} string Base64 encoded string
- * @returns {number} Byte length
- */
- base64.length = function length(string) {
- var p = string.length;
- if (!p)
- return 0;
- var n = 0;
- while (--p % 4 > 1 && string.charAt(p) === "=")
- ++n;
- return Math.ceil(string.length * 3) / 4 - n;
- };
- // Base64 encoding table
- var b64 = new Array(64);
- // Base64 decoding table
- var s64 = new Array(123);
- // 65..90, 97..122, 48..57, 43, 47
- for (var i = 0; i < 64;)
- s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
- /**
- * Encodes a buffer to a base64 encoded string.
- * @param {Uint8Array} buffer Source buffer
- * @param {number} start Source start
- * @param {number} end Source end
- * @returns {string} Base64 encoded string
- */
- base64.encode = function encode(buffer, start, end) {
- var parts = null,
- chunk = [];
- var i = 0, // output index
- j = 0, // goto index
- t; // temporary
- while (start < end) {
- var b = buffer[start++];
- switch (j) {
- case 0:
- chunk[i++] = b64[b >> 2];
- t = (b & 3) << 4;
- j = 1;
- break;
- case 1:
- chunk[i++] = b64[t | b >> 4];
- t = (b & 15) << 2;
- j = 2;
- break;
- case 2:
- chunk[i++] = b64[t | b >> 6];
- chunk[i++] = b64[b & 63];
- j = 0;
- break;
- }
- if (i > 8191) {
- (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
- i = 0;
- }
- }
- if (j) {
- chunk[i++] = b64[t];
- chunk[i++] = 61;
- if (j === 1)
- chunk[i++] = 61;
- }
- if (parts) {
- if (i)
- parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
- return parts.join("");
- }
- return String.fromCharCode.apply(String, chunk.slice(0, i));
- };
- var invalidEncoding = "invalid encoding";
- /**
- * Decodes a base64 encoded string to a buffer.
- * @param {string} string Source string
- * @param {Uint8Array} buffer Destination buffer
- * @param {number} offset Destination offset
- * @returns {number} Number of bytes written
- * @throws {Error} If encoding is invalid
- */
- base64.decode = function decode(string, buffer, offset) {
- var start = offset;
- var j = 0, // goto index
- t; // temporary
- for (var i = 0; i < string.length;) {
- var c = string.charCodeAt(i++);
- if (c === 61 && j > 1)
- break;
- if ((c = s64[c]) === undefined)
- throw Error(invalidEncoding);
- switch (j) {
- case 0:
- t = c;
- j = 1;
- break;
- case 1:
- buffer[offset++] = t << 2 | (c & 48) >> 4;
- t = c;
- j = 2;
- break;
- case 2:
- buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
- t = c;
- j = 3;
- break;
- case 3:
- buffer[offset++] = (t & 3) << 6 | c;
- j = 0;
- break;
- }
- }
- if (j === 1)
- throw Error(invalidEncoding);
- return offset - start;
- };
- /**
- * Tests if the specified string appears to be base64 encoded.
- * @param {string} string String to test
- * @returns {boolean} `true` if probably base64 encoded, otherwise false
- */
- base64.test = function test(string) {
- return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
- };
- },{}],3:[function(require,module,exports){
- "use strict";
- module.exports = EventEmitter;
- /**
- * Constructs a new event emitter instance.
- * @classdesc A minimal event emitter.
- * @memberof util
- * @constructor
- */
- function EventEmitter() {
- /**
- * Registered listeners.
- * @type {Object.<string,*>}
- * @private
- */
- this._listeners = {};
- }
- /**
- * Registers an event listener.
- * @param {string} evt Event name
- * @param {function} fn Listener
- * @param {*} [ctx] Listener context
- * @returns {util.EventEmitter} `this`
- */
- EventEmitter.prototype.on = function on(evt, fn, ctx) {
- (this._listeners[evt] || (this._listeners[evt] = [])).push({
- fn : fn,
- ctx : ctx || this
- });
- return this;
- };
- /**
- * Removes an event listener or any matching listeners if arguments are omitted.
- * @param {string} [evt] Event name. Removes all listeners if omitted.
- * @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
- * @returns {util.EventEmitter} `this`
- */
- EventEmitter.prototype.off = function off(evt, fn) {
- if (evt === undefined)
- this._listeners = {};
- else {
- if (fn === undefined)
- this._listeners[evt] = [];
- else {
- var listeners = this._listeners[evt];
- for (var i = 0; i < listeners.length;)
- if (listeners[i].fn === fn)
- listeners.splice(i, 1);
- else
- ++i;
- }
- }
- return this;
- };
- /**
- * Emits an event by calling its listeners with the specified arguments.
- * @param {string} evt Event name
- * @param {...*} args Arguments
- * @returns {util.EventEmitter} `this`
- */
- EventEmitter.prototype.emit = function emit(evt) {
- var listeners = this._listeners[evt];
- if (listeners) {
- var args = [],
- i = 1;
- for (; i < arguments.length;)
- args.push(arguments[i++]);
- for (i = 0; i < listeners.length;)
- listeners[i].fn.apply(listeners[i++].ctx, args);
- }
- return this;
- };
- },{}],4:[function(require,module,exports){
- "use strict";
- module.exports = factory(factory);
- /**
- * Reads / writes floats / doubles from / to buffers.
- * @name util.float
- * @namespace
- */
- /**
- * Writes a 32 bit float to a buffer using little endian byte order.
- * @name util.float.writeFloatLE
- * @function
- * @param {number} val Value to write
- * @param {Uint8Array} buf Target buffer
- * @param {number} pos Target buffer offset
- * @returns {undefined}
- */
- /**
- * Writes a 32 bit float to a buffer using big endian byte order.
- * @name util.float.writeFloatBE
- * @function
- * @param {number} val Value to write
- * @param {Uint8Array} buf Target buffer
- * @param {number} pos Target buffer offset
- * @returns {undefined}
- */
- /**
- * Reads a 32 bit float from a buffer using little endian byte order.
- * @name util.float.readFloatLE
- * @function
- * @param {Uint8Array} buf Source buffer
- * @param {number} pos Source buffer offset
- * @returns {number} Value read
- */
- /**
- * Reads a 32 bit float from a buffer using big endian byte order.
- * @name util.float.readFloatBE
- * @function
- * @param {Uint8Array} buf Source buffer
- * @param {number} pos Source buffer offset
- * @returns {number} Value read
- */
- /**
- * Writes a 64 bit double to a buffer using little endian byte order.
- * @name util.float.writeDoubleLE
- * @function
- * @param {number} val Value to write
- * @param {Uint8Array} buf Target buffer
- * @param {number} pos Target buffer offset
- * @returns {undefined}
- */
- /**
- * Writes a 64 bit double to a buffer using big endian byte order.
- * @name util.float.writeDoubleBE
- * @function
- * @param {number} val Value to write
- * @param {Uint8Array} buf Target buffer
- * @param {number} pos Target buffer offset
- * @returns {undefined}
- */
- /**
- * Reads a 64 bit double from a buffer using little endian byte order.
- * @name util.float.readDoubleLE
- * @function
- * @param {Uint8Array} buf Source buffer
- * @param {number} pos Source buffer offset
- * @returns {number} Value read
- */
- /**
- * Reads a 64 bit double from a buffer using big endian byte order.
- * @name util.float.readDoubleBE
- * @function
- * @param {Uint8Array} buf Source buffer
- * @param {number} pos Source buffer offset
- * @returns {number} Value read
- */
- // Factory function for the purpose of node-based testing in modified global environments
- function factory(exports) {
- // float: typed array
- if (typeof Float32Array !== "undefined") (function() {
- var f32 = new Float32Array([ -0 ]),
- f8b = new Uint8Array(f32.buffer),
- le = f8b[3] === 128;
- function writeFloat_f32_cpy(val, buf, pos) {
- f32[0] = val;
- buf[pos ] = f8b[0];
- buf[pos + 1] = f8b[1];
- buf[pos + 2] = f8b[2];
- buf[pos + 3] = f8b[3];
- }
- function writeFloat_f32_rev(val, buf, pos) {
- f32[0] = val;
- buf[pos ] = f8b[3];
- buf[pos + 1] = f8b[2];
- buf[pos + 2] = f8b[1];
- buf[pos + 3] = f8b[0];
- }
- /* istanbul ignore next */
- exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
- /* istanbul ignore next */
- exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
- function readFloat_f32_cpy(buf, pos) {
- f8b[0] = buf[pos ];
- f8b[1] = buf[pos + 1];
- f8b[2] = buf[pos + 2];
- f8b[3] = buf[pos + 3];
- return f32[0];
- }
- function readFloat_f32_rev(buf, pos) {
- f8b[3] = buf[pos ];
- f8b[2] = buf[pos + 1];
- f8b[1] = buf[pos + 2];
- f8b[0] = buf[pos + 3];
- return f32[0];
- }
- /* istanbul ignore next */
- exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
- /* istanbul ignore next */
- exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
- // float: ieee754
- })(); else (function() {
- function writeFloat_ieee754(writeUint, val, buf, pos) {
- var sign = val < 0 ? 1 : 0;
- if (sign)
- val = -val;
- if (val === 0)
- writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
- else if (isNaN(val))
- writeUint(2143289344, buf, pos);
- else if (val > 3.4028234663852886e+38) // +-Infinity
- writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
- else if (val < 1.1754943508222875e-38) // denormal
- writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
- else {
- var exponent = Math.floor(Math.log(val) / Math.LN2),
- mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
- writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
- }
- }
- exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
- exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
- function readFloat_ieee754(readUint, buf, pos) {
- var uint = readUint(buf, pos),
- sign = (uint >> 31) * 2 + 1,
- exponent = uint >>> 23 & 255,
- mantissa = uint & 8388607;
- return exponent === 255
- ? mantissa
- ? NaN
- : sign * Infinity
- : exponent === 0 // denormal
- ? sign * 1.401298464324817e-45 * mantissa
- : sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
- }
- exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
- exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
- })();
- // double: typed array
- if (typeof Float64Array !== "undefined") (function() {
- var f64 = new Float64Array([-0]),
- f8b = new Uint8Array(f64.buffer),
- le = f8b[7] === 128;
- function writeDouble_f64_cpy(val, buf, pos) {
- f64[0] = val;
- buf[pos ] = f8b[0];
- buf[pos + 1] = f8b[1];
- buf[pos + 2] = f8b[2];
- buf[pos + 3] = f8b[3];
- buf[pos + 4] = f8b[4];
- buf[pos + 5] = f8b[5];
- buf[pos + 6] = f8b[6];
- buf[pos + 7] = f8b[7];
- }
- function writeDouble_f64_rev(val, buf, pos) {
- f64[0] = val;
- buf[pos ] = f8b[7];
- buf[pos + 1] = f8b[6];
- buf[pos + 2] = f8b[5];
- buf[pos + 3] = f8b[4];
- buf[pos + 4] = f8b[3];
- buf[pos + 5] = f8b[2];
- buf[pos + 6] = f8b[1];
- buf[pos + 7] = f8b[0];
- }
- /* istanbul ignore next */
- exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
- /* istanbul ignore next */
- exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
- function readDouble_f64_cpy(buf, pos) {
- f8b[0] = buf[pos ];
- f8b[1] = buf[pos + 1];
- f8b[2] = buf[pos + 2];
- f8b[3] = buf[pos + 3];
- f8b[4] = buf[pos + 4];
- f8b[5] = buf[pos + 5];
- f8b[6] = buf[pos + 6];
- f8b[7] = buf[pos + 7];
- return f64[0];
- }
- function readDouble_f64_rev(buf, pos) {
- f8b[7] = buf[pos ];
- f8b[6] = buf[pos + 1];
- f8b[5] = buf[pos + 2];
- f8b[4] = buf[pos + 3];
- f8b[3] = buf[pos + 4];
- f8b[2] = buf[pos + 5];
- f8b[1] = buf[pos + 6];
- f8b[0] = buf[pos + 7];
- return f64[0];
- }
- /* istanbul ignore next */
- exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
- /* istanbul ignore next */
- exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
- // double: ieee754
- })(); else (function() {
- function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
- var sign = val < 0 ? 1 : 0;
- if (sign)
- val = -val;
- if (val === 0) {
- writeUint(0, buf, pos + off0);
- writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
- } else if (isNaN(val)) {
- writeUint(0, buf, pos + off0);
- writeUint(2146959360, buf, pos + off1);
- } else if (val > 1.7976931348623157e+308) { // +-Infinity
- writeUint(0, buf, pos + off0);
- writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
- } else {
- var mantissa;
- if (val < 2.2250738585072014e-308) { // denormal
- mantissa = val / 5e-324;
- writeUint(mantissa >>> 0, buf, pos + off0);
- writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
- } else {
- var exponent = Math.floor(Math.log(val) / Math.LN2);
- if (exponent === 1024)
- exponent = 1023;
- mantissa = val * Math.pow(2, -exponent);
- writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
- writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
- }
- }
- }
- exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
- exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
- function readDouble_ieee754(readUint, off0, off1, buf, pos) {
- var lo = readUint(buf, pos + off0),
- hi = readUint(buf, pos + off1);
- var sign = (hi >> 31) * 2 + 1,
- exponent = hi >>> 20 & 2047,
- mantissa = 4294967296 * (hi & 1048575) + lo;
- return exponent === 2047
- ? mantissa
- ? NaN
- : sign * Infinity
- : exponent === 0 // denormal
- ? sign * 5e-324 * mantissa
- : sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
- }
- exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
- exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
- })();
- return exports;
- }
- // uint helpers
- function writeUintLE(val, buf, pos) {
- buf[pos ] = val & 255;
- buf[pos + 1] = val >>> 8 & 255;
- buf[pos + 2] = val >>> 16 & 255;
- buf[pos + 3] = val >>> 24;
- }
- function writeUintBE(val, buf, pos) {
- buf[pos ] = val >>> 24;
- buf[pos + 1] = val >>> 16 & 255;
- buf[pos + 2] = val >>> 8 & 255;
- buf[pos + 3] = val & 255;
- }
- function readUintLE(buf, pos) {
- return (buf[pos ]
- | buf[pos + 1] << 8
- | buf[pos + 2] << 16
- | buf[pos + 3] << 24) >>> 0;
- }
- function readUintBE(buf, pos) {
- return (buf[pos ] << 24
- | buf[pos + 1] << 16
- | buf[pos + 2] << 8
- | buf[pos + 3]) >>> 0;
- }
- },{}],5:[function(require,module,exports){
- "use strict";
- module.exports = inquire;
- /**
- * Requires a module only if available.
- * @memberof util
- * @param {string} moduleName Module to require
- * @returns {?Object} Required module if available and not empty, otherwise `null`
- */
- function inquire(moduleName) {
- try {
- var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
- if (mod && (mod.length || Object.keys(mod).length))
- return mod;
- } catch (e) {} // eslint-disable-line no-empty
- return null;
- }
- },{}],6:[function(require,module,exports){
- "use strict";
- module.exports = pool;
- /**
- * An allocator as used by {@link util.pool}.
- * @typedef PoolAllocator
- * @type {function}
- * @param {number} size Buffer size
- * @returns {Uint8Array} Buffer
- */
- /**
- * A slicer as used by {@link util.pool}.
- * @typedef PoolSlicer
- * @type {function}
- * @param {number} start Start offset
- * @param {number} end End offset
- * @returns {Uint8Array} Buffer slice
- * @this {Uint8Array}
- */
- /**
- * A general purpose buffer pool.
- * @memberof util
- * @function
- * @param {PoolAllocator} alloc Allocator
- * @param {PoolSlicer} slice Slicer
- * @param {number} [size=8192] Slab size
- * @returns {PoolAllocator} Pooled allocator
- */
- function pool(alloc, slice, size) {
- var SIZE = size || 8192;
- var MAX = SIZE >>> 1;
- var slab = null;
- var offset = SIZE;
- return function pool_alloc(size) {
- if (size < 1 || size > MAX)
- return alloc(size);
- if (offset + size > SIZE) {
- slab = alloc(SIZE);
- offset = 0;
- }
- var buf = slice.call(slab, offset, offset += size);
- if (offset & 7) // align to 32 bit
- offset = (offset | 7) + 1;
- return buf;
- };
- }
- },{}],7:[function(require,module,exports){
- "use strict";
- /**
- * A minimal UTF8 implementation for number arrays.
- * @memberof util
- * @namespace
- */
- var utf8 = exports;
- /**
- * Calculates the UTF8 byte length of a string.
- * @param {string} string String
- * @returns {number} Byte length
- */
- utf8.length = function utf8_length(string) {
- var len = 0,
- c = 0;
- for (var i = 0; i < string.length; ++i) {
- c = string.charCodeAt(i);
- if (c < 128)
- len += 1;
- else if (c < 2048)
- len += 2;
- else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
- ++i;
- len += 4;
- } else
- len += 3;
- }
- return len;
- };
- /**
- * Reads UTF8 bytes as a string.
- * @param {Uint8Array} buffer Source buffer
- * @param {number} start Source start
- * @param {number} end Source end
- * @returns {string} String read
- */
- utf8.read = function utf8_read(buffer, start, end) {
- var len = end - start;
- if (len < 1)
- return "";
- var parts = null,
- chunk = [],
- i = 0, // char offset
- t; // temporary
- while (start < end) {
- t = buffer[start++];
- if (t < 128)
- chunk[i++] = t;
- else if (t > 191 && t < 224)
- chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
- else if (t > 239 && t < 365) {
- t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
- chunk[i++] = 0xD800 + (t >> 10);
- chunk[i++] = 0xDC00 + (t & 1023);
- } else
- chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
- if (i > 8191) {
- (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
- i = 0;
- }
- }
- if (parts) {
- if (i)
- parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
- return parts.join("");
- }
- return String.fromCharCode.apply(String, chunk.slice(0, i));
- };
- /**
- * Writes a string as UTF8 bytes.
- * @param {string} string Source string
- * @param {Uint8Array} buffer Destination buffer
- * @param {number} offset Destination offset
- * @returns {number} Bytes written
- */
- utf8.write = function utf8_write(string, buffer, offset) {
- var start = offset,
- c1, // character 1
- c2; // character 2
- for (var i = 0; i < string.length; ++i) {
- c1 = string.charCodeAt(i);
- if (c1 < 128) {
- buffer[offset++] = c1;
- } else if (c1 < 2048) {
- buffer[offset++] = c1 >> 6 | 192;
- buffer[offset++] = c1 & 63 | 128;
- } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
- c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
- ++i;
- buffer[offset++] = c1 >> 18 | 240;
- buffer[offset++] = c1 >> 12 & 63 | 128;
- buffer[offset++] = c1 >> 6 & 63 | 128;
- buffer[offset++] = c1 & 63 | 128;
- } else {
- buffer[offset++] = c1 >> 12 | 224;
- buffer[offset++] = c1 >> 6 & 63 | 128;
- buffer[offset++] = c1 & 63 | 128;
- }
- }
- return offset - start;
- };
- },{}],8:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [op[0] & 2, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var tf = require("@tensorflow/tfjs");
- var tfjs_1 = require("@tensorflow/tfjs");
- var util_1 = require("./util");
- var KNNClassifier = (function () {
- function KNNClassifier() {
- this.classDatasetMatrices = {};
- this.classExampleCount = {};
- }
- KNNClassifier.prototype.addExample = function (example, classIndex) {
- var _this = this;
- if (this.exampleShape == null) {
- this.exampleShape = example.shape;
- }
- if (!tfjs_1.util.arraysEqual(this.exampleShape, example.shape)) {
- throw new Error("Example shape provided, " + example.shape + " does not match " +
- ("previously provided example shapes " + this.exampleShape + "."));
- }
- if (!Number.isInteger(classIndex)) {
- throw new Error("classIndex must be an integer, got " + classIndex + ".");
- }
- this.clearTrainDatasetMatrix();
- tf.tidy(function () {
- var normalizedExample = _this.normalizeVectorToUnitLength(example.flatten());
- var exampleSize = normalizedExample.shape[0];
- if (_this.classDatasetMatrices[classIndex] == null) {
- _this.classDatasetMatrices[classIndex] =
- normalizedExample.as2D(1, exampleSize);
- }
- else {
- var newTrainLogitsMatrix = _this.classDatasetMatrices[classIndex]
- .as2D(_this.classExampleCount[classIndex], exampleSize)
- .concat(normalizedExample.as2D(1, exampleSize), 0);
- _this.classDatasetMatrices[classIndex].dispose();
- _this.classDatasetMatrices[classIndex] = newTrainLogitsMatrix;
- }
- tf.keep(_this.classDatasetMatrices[classIndex]);
- if (_this.classExampleCount[classIndex] == null) {
- _this.classExampleCount[classIndex] = 0;
- }
- _this.classExampleCount[classIndex]++;
- });
- };
- KNNClassifier.prototype.similarities = function (input) {
- var _this = this;
- return tf.tidy(function () {
- var normalizedExample = _this.normalizeVectorToUnitLength(input.flatten());
- var exampleSize = normalizedExample.shape[0];
- if (_this.trainDatasetMatrix == null) {
- var newTrainLogitsMatrix = null;
- for (var i in _this.classDatasetMatrices) {
- newTrainLogitsMatrix = util_1.concatWithNulls(newTrainLogitsMatrix, _this.classDatasetMatrices[i]);
- }
- _this.trainDatasetMatrix = newTrainLogitsMatrix;
- }
- if (_this.trainDatasetMatrix == null) {
- console.warn('Cannot predict without providing training examples.');
- return null;
- }
- tf.keep(_this.trainDatasetMatrix);
- var numExamples = _this.getNumExamples();
- return _this.trainDatasetMatrix.as2D(numExamples, exampleSize)
- .matMul(normalizedExample.as2D(exampleSize, 1))
- .as1D();
- });
- };
- KNNClassifier.prototype.predictClass = function (input, k) {
- if (k === void 0) { k = 3; }
- return __awaiter(this, void 0, void 0, function () {
- var knn, kVal, topKIndices, _a;
- var _this = this;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- if (k < 1) {
- throw new Error("Please provide a positive integer k value to predictClass.");
- }
- knn = tf.tidy(function () { return _this.similarities(input).asType('float32'); });
- kVal = Math.min(k, this.getNumExamples());
- _a = util_1.topK;
- return [4, knn.data()];
- case 1:
- topKIndices = _a.apply(void 0, [_b.sent(), kVal]).indices;
- knn.dispose();
- return [2, this.calculateTopClass(topKIndices, kVal)];
- }
- });
- });
- };
- KNNClassifier.prototype.clearClass = function (classIndex) {
- if (this.classDatasetMatrices[classIndex] == null) {
- throw new Error('Cannot clear invalid class ${classIndex}');
- }
- delete this.classDatasetMatrices[classIndex];
- delete this.classExampleCount[classIndex];
- this.clearTrainDatasetMatrix();
- };
- KNNClassifier.prototype.clearAllClasses = function () {
- for (var i in this.classDatasetMatrices) {
- this.clearClass(+i);
- }
- };
- KNNClassifier.prototype.getClassExampleCount = function () {
- return this.classExampleCount;
- };
- KNNClassifier.prototype.getClassifierDataset = function () {
- return this.classDatasetMatrices;
- };
- KNNClassifier.prototype.getNumClasses = function () {
- return Object.keys(this.classExampleCount).length;
- };
- KNNClassifier.prototype.setClassifierDataset = function (classDatasetMatrices) {
- this.clearTrainDatasetMatrix();
- this.classDatasetMatrices = classDatasetMatrices;
- for (var i in classDatasetMatrices) {
- this.classExampleCount[i] = classDatasetMatrices[i].shape[0];
- }
- };
- KNNClassifier.prototype.calculateTopClass = function (topKIndices, kVal) {
- var exampleClass = -1;
- var confidences = {};
- if (topKIndices == null) {
- return { classIndex: exampleClass, confidences: confidences };
- }
- var indicesForClasses = [];
- for (var i in this.classDatasetMatrices) {
- var num = this.classExampleCount[i];
- if (+i > 0) {
- num += indicesForClasses[+i - 1];
- }
- indicesForClasses.push(num);
- }
- var topKCountsForClasses = Array(Object.keys(this.classDatasetMatrices).length).fill(0);
- for (var i = 0; i < topKIndices.length; i++) {
- for (var classId = 0; classId < indicesForClasses.length; classId++) {
- if (topKIndices[i] < indicesForClasses[classId]) {
- topKCountsForClasses[classId]++;
- break;
- }
- }
- }
- var topConfidence = 0;
- for (var i in this.classDatasetMatrices) {
- var probability = topKCountsForClasses[i] / kVal;
- if (probability > topConfidence) {
- topConfidence = probability;
- exampleClass = +i;
- }
- confidences[i] = probability;
- }
- return { classIndex: exampleClass, confidences: confidences };
- };
- KNNClassifier.prototype.clearTrainDatasetMatrix = function () {
- if (this.trainDatasetMatrix != null) {
- this.trainDatasetMatrix.dispose();
- this.trainDatasetMatrix = null;
- }
- };
- KNNClassifier.prototype.normalizeVectorToUnitLength = function (vec) {
- return tf.tidy(function () {
- var sqrtSum = vec.norm();
- return tf.div(vec, sqrtSum);
- });
- };
- KNNClassifier.prototype.getNumExamples = function () {
- var total = 0;
- for (var i in this.classDatasetMatrices) {
- total += this.classExampleCount[+i];
- }
- return total;
- };
- KNNClassifier.prototype.dispose = function () {
- this.clearTrainDatasetMatrix();
- for (var i in this.classDatasetMatrices) {
- this.classDatasetMatrices[i].dispose();
- }
- };
- return KNNClassifier;
- }());
- exports.KNNClassifier = KNNClassifier;
- function create() {
- return new KNNClassifier();
- }
- exports.create = create;
- },{"./util":9,"@tensorflow/tfjs":205}],9:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- function concatWithNulls(ndarray1, ndarray2) {
- if (ndarray1 == null && ndarray2 == null) {
- return null;
- }
- if (ndarray1 == null) {
- return ndarray2.clone();
- }
- else if (ndarray2 === null) {
- return ndarray1.clone();
- }
- return ndarray1.concat(ndarray2, 0);
- }
- exports.concatWithNulls = concatWithNulls;
- function topK(values, k) {
- var valuesAndIndices = [];
- for (var i = 0; i < values.length; i++) {
- valuesAndIndices.push({ value: values[i], index: i });
- }
- valuesAndIndices.sort(function (a, b) {
- return b.value - a.value;
- });
- var topkValues = new Float32Array(k);
- var topkIndices = new Int32Array(k);
- for (var i = 0; i < k; i++) {
- topkValues[i] = valuesAndIndices[i].value;
- topkIndices[i] = valuesAndIndices[i].index;
- }
- return { values: topkValues, indices: topkIndices };
- }
- exports.topK = topK;
- },{}],10:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.IMAGENET_CLASSES = {
- 0: 'tench, Tinca tinca',
- 1: 'goldfish, Carassius auratus',
- 2: 'great white shark, white shark, man-eater, man-eating shark, ' +
- 'Carcharodon carcharias',
- 3: 'tiger shark, Galeocerdo cuvieri',
- 4: 'hammerhead, hammerhead shark',
- 5: 'electric ray, crampfish, numbfish, torpedo',
- 6: 'stingray',
- 7: 'cock',
- 8: 'hen',
- 9: 'ostrich, Struthio camelus',
- 10: 'brambling, Fringilla montifringilla',
- 11: 'goldfinch, Carduelis carduelis',
- 12: 'house finch, linnet, Carpodacus mexicanus',
- 13: 'junco, snowbird',
- 14: 'indigo bunting, indigo finch, indigo bird, Passerina cyanea',
- 15: 'robin, American robin, Turdus migratorius',
- 16: 'bulbul',
- 17: 'jay',
- 18: 'magpie',
- 19: 'chickadee',
- 20: 'water ouzel, dipper',
- 21: 'kite',
- 22: 'bald eagle, American eagle, Haliaeetus leucocephalus',
- 23: 'vulture',
- 24: 'great grey owl, great gray owl, Strix nebulosa',
- 25: 'European fire salamander, Salamandra salamandra',
- 26: 'common newt, Triturus vulgaris',
- 27: 'eft',
- 28: 'spotted salamander, Ambystoma maculatum',
- 29: 'axolotl, mud puppy, Ambystoma mexicanum',
- 30: 'bullfrog, Rana catesbeiana',
- 31: 'tree frog, tree-frog',
- 32: 'tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui',
- 33: 'loggerhead, loggerhead turtle, Caretta caretta',
- 34: 'leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea',
- 35: 'mud turtle',
- 36: 'terrapin',
- 37: 'box turtle, box tortoise',
- 38: 'banded gecko',
- 39: 'common iguana, iguana, Iguana iguana',
- 40: 'American chameleon, anole, Anolis carolinensis',
- 41: 'whiptail, whiptail lizard',
- 42: 'agama',
- 43: 'frilled lizard, Chlamydosaurus kingi',
- 44: 'alligator lizard',
- 45: 'Gila monster, Heloderma suspectum',
- 46: 'green lizard, Lacerta viridis',
- 47: 'African chameleon, Chamaeleo chamaeleon',
- 48: 'Komodo dragon, Komodo lizard, dragon lizard, giant lizard, ' +
- 'Varanus komodoensis',
- 49: 'African crocodile, Nile crocodile, Crocodylus niloticus',
- 50: 'American alligator, Alligator mississipiensis',
- 51: 'triceratops',
- 52: 'thunder snake, worm snake, Carphophis amoenus',
- 53: 'ringneck snake, ring-necked snake, ring snake',
- 54: 'hognose snake, puff adder, sand viper',
- 55: 'green snake, grass snake',
- 56: 'king snake, kingsnake',
- 57: 'garter snake, grass snake',
- 58: 'water snake',
- 59: 'vine snake',
- 60: 'night snake, Hypsiglena torquata',
- 61: 'boa constrictor, Constrictor constrictor',
- 62: 'rock python, rock snake, Python sebae',
- 63: 'Indian cobra, Naja naja',
- 64: 'green mamba',
- 65: 'sea snake',
- 66: 'horned viper, cerastes, sand viper, horned asp, Cerastes cornutus',
- 67: 'diamondback, diamondback rattlesnake, Crotalus adamanteus',
- 68: 'sidewinder, horned rattlesnake, Crotalus cerastes',
- 69: 'trilobite',
- 70: 'harvestman, daddy longlegs, Phalangium opilio',
- 71: 'scorpion',
- 72: 'black and gold garden spider, Argiope aurantia',
- 73: 'barn spider, Araneus cavaticus',
- 74: 'garden spider, Aranea diademata',
- 75: 'black widow, Latrodectus mactans',
- 76: 'tarantula',
- 77: 'wolf spider, hunting spider',
- 78: 'tick',
- 79: 'centipede',
- 80: 'black grouse',
- 81: 'ptarmigan',
- 82: 'ruffed grouse, partridge, Bonasa umbellus',
- 83: 'prairie chicken, prairie grouse, prairie fowl',
- 84: 'peacock',
- 85: 'quail',
- 86: 'partridge',
- 87: 'African grey, African gray, Psittacus erithacus',
- 88: 'macaw',
- 89: 'sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita',
- 90: 'lorikeet',
- 91: 'coucal',
- 92: 'bee eater',
- 93: 'hornbill',
- 94: 'hummingbird',
- 95: 'jacamar',
- 96: 'toucan',
- 97: 'drake',
- 98: 'red-breasted merganser, Mergus serrator',
- 99: 'goose',
- 100: 'black swan, Cygnus atratus',
- 101: 'tusker',
- 102: 'echidna, spiny anteater, anteater',
- 103: 'platypus, duckbill, duckbilled platypus, duck-billed platypus, ' +
- 'Ornithorhynchus anatinus',
- 104: 'wallaby, brush kangaroo',
- 105: 'koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus',
- 106: 'wombat',
- 107: 'jelly fish',
- 108: 'sea anemone, anemone',
- 109: 'brain coral',
- 110: 'flatworm, platyhelminth',
- 111: 'nematode, nematode worm, roundworm',
- 112: 'conch',
- 113: 'snail',
- 114: 'slug',
- 115: 'sea slug, nudibranch',
- 116: 'chiton, coat-of-mail shell, sea cradle, polyplacophore',
- 117: 'chambered nautilus, pearly nautilus, nautilus',
- 118: 'Dungeness crab, Cancer magister',
- 119: 'rock crab, Cancer irroratus',
- 120: 'fiddler crab',
- 121: 'king crab, Alaska crab, Alaskan king crab, Alaska king crab, ' +
- 'Paralithodes camtschatica',
- 122: 'American lobster, Northern lobster, Maine lobster, Homarus americanus',
- 123: 'spiny lobster, langouste, rock lobster, crawfish, crayfish, sea ' +
- 'crawfish',
- 124: 'crayfish, crawfish, crawdad, crawdaddy',
- 125: 'hermit crab',
- 126: 'isopod',
- 127: 'white stork, Ciconia ciconia',
- 128: 'black stork, Ciconia nigra',
- 129: 'spoonbill',
- 130: 'flamingo',
- 131: 'little blue heron, Egretta caerulea',
- 132: 'American egret, great white heron, Egretta albus',
- 133: 'bittern',
- 134: 'crane',
- 135: 'limpkin, Aramus pictus',
- 136: 'European gallinule, Porphyrio porphyrio',
- 137: 'American coot, marsh hen, mud hen, water hen, Fulica americana',
- 138: 'bustard',
- 139: 'ruddy turnstone, Arenaria interpres',
- 140: 'red-backed sandpiper, dunlin, Erolia alpina',
- 141: 'redshank, Tringa totanus',
- 142: 'dowitcher',
- 143: 'oystercatcher, oyster catcher',
- 144: 'pelican',
- 145: 'king penguin, Aptenodytes patagonica',
- 146: 'albatross, mollymawk',
- 147: 'grey whale, gray whale, devilfish, Eschrichtius gibbosus, ' +
- 'Eschrichtius robustus',
- 148: 'killer whale, killer, orca, grampus, sea wolf, Orcinus orca',
- 149: 'dugong, Dugong dugon',
- 150: 'sea lion',
- 151: 'Chihuahua',
- 152: 'Japanese spaniel',
- 153: 'Maltese dog, Maltese terrier, Maltese',
- 154: 'Pekinese, Pekingese, Peke',
- 155: 'Shih-Tzu',
- 156: 'Blenheim spaniel',
- 157: 'papillon',
- 158: 'toy terrier',
- 159: 'Rhodesian ridgeback',
- 160: 'Afghan hound, Afghan',
- 161: 'basset, basset hound',
- 162: 'beagle',
- 163: 'bloodhound, sleuthhound',
- 164: 'bluetick',
- 165: 'black-and-tan coonhound',
- 166: 'Walker hound, Walker foxhound',
- 167: 'English foxhound',
- 168: 'redbone',
- 169: 'borzoi, Russian wolfhound',
- 170: 'Irish wolfhound',
- 171: 'Italian greyhound',
- 172: 'whippet',
- 173: 'Ibizan hound, Ibizan Podenco',
- 174: 'Norwegian elkhound, elkhound',
- 175: 'otterhound, otter hound',
- 176: 'Saluki, gazelle hound',
- 177: 'Scottish deerhound, deerhound',
- 178: 'Weimaraner',
- 179: 'Staffordshire bullterrier, Staffordshire bull terrier',
- 180: 'American Staffordshire terrier, Staffordshire terrier, American pit ' +
- 'bull terrier, pit bull terrier',
- 181: 'Bedlington terrier',
- 182: 'Border terrier',
- 183: 'Kerry blue terrier',
- 184: 'Irish terrier',
- 185: 'Norfolk terrier',
- 186: 'Norwich terrier',
- 187: 'Yorkshire terrier',
- 188: 'wire-haired fox terrier',
- 189: 'Lakeland terrier',
- 190: 'Sealyham terrier, Sealyham',
- 191: 'Airedale, Airedale terrier',
- 192: 'cairn, cairn terrier',
- 193: 'Australian terrier',
- 194: 'Dandie Dinmont, Dandie Dinmont terrier',
- 195: 'Boston bull, Boston terrier',
- 196: 'miniature schnauzer',
- 197: 'giant schnauzer',
- 198: 'standard schnauzer',
- 199: 'Scotch terrier, Scottish terrier, Scottie',
- 200: 'Tibetan terrier, chrysanthemum dog',
- 201: 'silky terrier, Sydney silky',
- 202: 'soft-coated wheaten terrier',
- 203: 'West Highland white terrier',
- 204: 'Lhasa, Lhasa apso',
- 205: 'flat-coated retriever',
- 206: 'curly-coated retriever',
- 207: 'golden retriever',
- 208: 'Labrador retriever',
- 209: 'Chesapeake Bay retriever',
- 210: 'German short-haired pointer',
- 211: 'vizsla, Hungarian pointer',
- 212: 'English setter',
- 213: 'Irish setter, red setter',
- 214: 'Gordon setter',
- 215: 'Brittany spaniel',
- 216: 'clumber, clumber spaniel',
- 217: 'English springer, English springer spaniel',
- 218: 'Welsh springer spaniel',
- 219: 'cocker spaniel, English cocker spaniel, cocker',
- 220: 'Sussex spaniel',
- 221: 'Irish water spaniel',
- 222: 'kuvasz',
- 223: 'schipperke',
- 224: 'groenendael',
- 225: 'malinois',
- 226: 'briard',
- 227: 'kelpie',
- 228: 'komondor',
- 229: 'Old English sheepdog, bobtail',
- 230: 'Shetland sheepdog, Shetland sheep dog, Shetland',
- 231: 'collie',
- 232: 'Border collie',
- 233: 'Bouvier des Flandres, Bouviers des Flandres',
- 234: 'Rottweiler',
- 235: 'German shepherd, German shepherd dog, German police dog, alsatian',
- 236: 'Doberman, Doberman pinscher',
- 237: 'miniature pinscher',
- 238: 'Greater Swiss Mountain dog',
- 239: 'Bernese mountain dog',
- 240: 'Appenzeller',
- 241: 'EntleBucher',
- 242: 'boxer',
- 243: 'bull mastiff',
- 244: 'Tibetan mastiff',
- 245: 'French bulldog',
- 246: 'Great Dane',
- 247: 'Saint Bernard, St Bernard',
- 248: 'Eskimo dog, husky',
- 249: 'malamute, malemute, Alaskan malamute',
- 250: 'Siberian husky',
- 251: 'dalmatian, coach dog, carriage dog',
- 252: 'affenpinscher, monkey pinscher, monkey dog',
- 253: 'basenji',
- 254: 'pug, pug-dog',
- 255: 'Leonberg',
- 256: 'Newfoundland, Newfoundland dog',
- 257: 'Great Pyrenees',
- 258: 'Samoyed, Samoyede',
- 259: 'Pomeranian',
- 260: 'chow, chow chow',
- 261: 'keeshond',
- 262: 'Brabancon griffon',
- 263: 'Pembroke, Pembroke Welsh corgi',
- 264: 'Cardigan, Cardigan Welsh corgi',
- 265: 'toy poodle',
- 266: 'miniature poodle',
- 267: 'standard poodle',
- 268: 'Mexican hairless',
- 269: 'timber wolf, grey wolf, gray wolf, Canis lupus',
- 270: 'white wolf, Arctic wolf, Canis lupus tundrarum',
- 271: 'red wolf, maned wolf, Canis rufus, Canis niger',
- 272: 'coyote, prairie wolf, brush wolf, Canis latrans',
- 273: 'dingo, warrigal, warragal, Canis dingo',
- 274: 'dhole, Cuon alpinus',
- 275: 'African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus',
- 276: 'hyena, hyaena',
- 277: 'red fox, Vulpes vulpes',
- 278: 'kit fox, Vulpes macrotis',
- 279: 'Arctic fox, white fox, Alopex lagopus',
- 280: 'grey fox, gray fox, Urocyon cinereoargenteus',
- 281: 'tabby, tabby cat',
- 282: 'tiger cat',
- 283: 'Persian cat',
- 284: 'Siamese cat, Siamese',
- 285: 'Egyptian cat',
- 286: 'cougar, puma, catamount, mountain lion, painter, panther, ' +
- 'Felis concolor',
- 287: 'lynx, catamount',
- 288: 'leopard, Panthera pardus',
- 289: 'snow leopard, ounce, Panthera uncia',
- 290: 'jaguar, panther, Panthera onca, Felis onca',
- 291: 'lion, king of beasts, Panthera leo',
- 292: 'tiger, Panthera tigris',
- 293: 'cheetah, chetah, Acinonyx jubatus',
- 294: 'brown bear, bruin, Ursus arctos',
- 295: 'American black bear, black bear, Ursus americanus, Euarctos ' +
- 'americanus',
- 296: 'ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus',
- 297: 'sloth bear, Melursus ursinus, Ursus ursinus',
- 298: 'mongoose',
- 299: 'meerkat, mierkat',
- 300: 'tiger beetle',
- 301: 'ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle',
- 302: 'ground beetle, carabid beetle',
- 303: 'long-horned beetle, longicorn, longicorn beetle',
- 304: 'leaf beetle, chrysomelid',
- 305: 'dung beetle',
- 306: 'rhinoceros beetle',
- 307: 'weevil',
- 308: 'fly',
- 309: 'bee',
- 310: 'ant, emmet, pismire',
- 311: 'grasshopper, hopper',
- 312: 'cricket',
- 313: 'walking stick, walkingstick, stick insect',
- 314: 'cockroach, roach',
- 315: 'mantis, mantid',
- 316: 'cicada, cicala',
- 317: 'leafhopper',
- 318: 'lacewing, lacewing fly',
- 319: 'dragonfly, darning needle, devil\'s darning needle, sewing needle, ' +
- 'snake feeder, snake doctor, mosquito hawk, skeeter hawk',
- 320: 'damselfly',
- 321: 'admiral',
- 322: 'ringlet, ringlet butterfly',
- 323: 'monarch, monarch butterfly, milkweed butterfly, Danaus plexippus',
- 324: 'cabbage butterfly',
- 325: 'sulphur butterfly, sulfur butterfly',
- 326: 'lycaenid, lycaenid butterfly',
- 327: 'starfish, sea star',
- 328: 'sea urchin',
- 329: 'sea cucumber, holothurian',
- 330: 'wood rabbit, cottontail, cottontail rabbit',
- 331: 'hare',
- 332: 'Angora, Angora rabbit',
- 333: 'hamster',
- 334: 'porcupine, hedgehog',
- 335: 'fox squirrel, eastern fox squirrel, Sciurus niger',
- 336: 'marmot',
- 337: 'beaver',
- 338: 'guinea pig, Cavia cobaya',
- 339: 'sorrel',
- 340: 'zebra',
- 341: 'hog, pig, grunter, squealer, Sus scrofa',
- 342: 'wild boar, boar, Sus scrofa',
- 343: 'warthog',
- 344: 'hippopotamus, hippo, river horse, Hippopotamus amphibius',
- 345: 'ox',
- 346: 'water buffalo, water ox, Asiatic buffalo, Bubalus bubalis',
- 347: 'bison',
- 348: 'ram, tup',
- 349: 'bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky ' +
- 'Mountain sheep, Ovis canadensis',
- 350: 'ibex, Capra ibex',
- 351: 'hartebeest',
- 352: 'impala, Aepyceros melampus',
- 353: 'gazelle',
- 354: 'Arabian camel, dromedary, Camelus dromedarius',
- 355: 'llama',
- 356: 'weasel',
- 357: 'mink',
- 358: 'polecat, fitch, foulmart, foumart, Mustela putorius',
- 359: 'black-footed ferret, ferret, Mustela nigripes',
- 360: 'otter',
- 361: 'skunk, polecat, wood pussy',
- 362: 'badger',
- 363: 'armadillo',
- 364: 'three-toed sloth, ai, Bradypus tridactylus',
- 365: 'orangutan, orang, orangutang, Pongo pygmaeus',
- 366: 'gorilla, Gorilla gorilla',
- 367: 'chimpanzee, chimp, Pan troglodytes',
- 368: 'gibbon, Hylobates lar',
- 369: 'siamang, Hylobates syndactylus, Symphalangus syndactylus',
- 370: 'guenon, guenon monkey',
- 371: 'patas, hussar monkey, Erythrocebus patas',
- 372: 'baboon',
- 373: 'macaque',
- 374: 'langur',
- 375: 'colobus, colobus monkey',
- 376: 'proboscis monkey, Nasalis larvatus',
- 377: 'marmoset',
- 378: 'capuchin, ringtail, Cebus capucinus',
- 379: 'howler monkey, howler',
- 380: 'titi, titi monkey',
- 381: 'spider monkey, Ateles geoffroyi',
- 382: 'squirrel monkey, Saimiri sciureus',
- 383: 'Madagascar cat, ring-tailed lemur, Lemur catta',
- 384: 'indri, indris, Indri indri, Indri brevicaudatus',
- 385: 'Indian elephant, Elephas maximus',
- 386: 'African elephant, Loxodonta africana',
- 387: 'lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens',
- 388: 'giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca',
- 389: 'barracouta, snoek',
- 390: 'eel',
- 391: 'coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus ' +
- 'kisutch',
- 392: 'rock beauty, Holocanthus tricolor',
- 393: 'anemone fish',
- 394: 'sturgeon',
- 395: 'gar, garfish, garpike, billfish, Lepisosteus osseus',
- 396: 'lionfish',
- 397: 'puffer, pufferfish, blowfish, globefish',
- 398: 'abacus',
- 399: 'abaya',
- 400: 'academic gown, academic robe, judge\'s robe',
- 401: 'accordion, piano accordion, squeeze box',
- 402: 'acoustic guitar',
- 403: 'aircraft carrier, carrier, flattop, attack aircraft carrier',
- 404: 'airliner',
- 405: 'airship, dirigible',
- 406: 'altar',
- 407: 'ambulance',
- 408: 'amphibian, amphibious vehicle',
- 409: 'analog clock',
- 410: 'apiary, bee house',
- 411: 'apron',
- 412: 'ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, ' +
- 'dustbin, trash barrel, trash bin',
- 413: 'assault rifle, assault gun',
- 414: 'backpack, back pack, knapsack, packsack, rucksack, haversack',
- 415: 'bakery, bakeshop, bakehouse',
- 416: 'balance beam, beam',
- 417: 'balloon',
- 418: 'ballpoint, ballpoint pen, ballpen, Biro',
- 419: 'Band Aid',
- 420: 'banjo',
- 421: 'bannister, banister, balustrade, balusters, handrail',
- 422: 'barbell',
- 423: 'barber chair',
- 424: 'barbershop',
- 425: 'barn',
- 426: 'barometer',
- 427: 'barrel, cask',
- 428: 'barrow, garden cart, lawn cart, wheelbarrow',
- 429: 'baseball',
- 430: 'basketball',
- 431: 'bassinet',
- 432: 'bassoon',
- 433: 'bathing cap, swimming cap',
- 434: 'bath towel',
- 435: 'bathtub, bathing tub, bath, tub',
- 436: 'beach wagon, station wagon, wagon, estate car, beach waggon, station ' +
- 'waggon, waggon',
- 437: 'beacon, lighthouse, beacon light, pharos',
- 438: 'beaker',
- 439: 'bearskin, busby, shako',
- 440: 'beer bottle',
- 441: 'beer glass',
- 442: 'bell cote, bell cot',
- 443: 'bib',
- 444: 'bicycle-built-for-two, tandem bicycle, tandem',
- 445: 'bikini, two-piece',
- 446: 'binder, ring-binder',
- 447: 'binoculars, field glasses, opera glasses',
- 448: 'birdhouse',
- 449: 'boathouse',
- 450: 'bobsled, bobsleigh, bob',
- 451: 'bolo tie, bolo, bola tie, bola',
- 452: 'bonnet, poke bonnet',
- 453: 'bookcase',
- 454: 'bookshop, bookstore, bookstall',
- 455: 'bottlecap',
- 456: 'bow',
- 457: 'bow tie, bow-tie, bowtie',
- 458: 'brass, memorial tablet, plaque',
- 459: 'brassiere, bra, bandeau',
- 460: 'breakwater, groin, groyne, mole, bulwark, seawall, jetty',
- 461: 'breastplate, aegis, egis',
- 462: 'broom',
- 463: 'bucket, pail',
- 464: 'buckle',
- 465: 'bulletproof vest',
- 466: 'bullet train, bullet',
- 467: 'butcher shop, meat market',
- 468: 'cab, hack, taxi, taxicab',
- 469: 'caldron, cauldron',
- 470: 'candle, taper, wax light',
- 471: 'cannon',
- 472: 'canoe',
- 473: 'can opener, tin opener',
- 474: 'cardigan',
- 475: 'car mirror',
- 476: 'carousel, carrousel, merry-go-round, roundabout, whirligig',
- 477: 'carpenter\'s kit, tool kit',
- 478: 'carton',
- 479: 'car wheel',
- 480: 'cash machine, cash dispenser, automated teller machine, automatic ' +
- 'teller machine, automated teller, automatic teller, ATM',
- 481: 'cassette',
- 482: 'cassette player',
- 483: 'castle',
- 484: 'catamaran',
- 485: 'CD player',
- 486: 'cello, violoncello',
- 487: 'cellular telephone, cellular phone, cellphone, cell, mobile phone',
- 488: 'chain',
- 489: 'chainlink fence',
- 490: 'chain mail, ring mail, mail, chain armor, chain armour, ring armor, ' +
- 'ring armour',
- 491: 'chain saw, chainsaw',
- 492: 'chest',
- 493: 'chiffonier, commode',
- 494: 'chime, bell, gong',
- 495: 'china cabinet, china closet',
- 496: 'Christmas stocking',
- 497: 'church, church building',
- 498: 'cinema, movie theater, movie theatre, movie house, picture palace',
- 499: 'cleaver, meat cleaver, chopper',
- 500: 'cliff dwelling',
- 501: 'cloak',
- 502: 'clog, geta, patten, sabot',
- 503: 'cocktail shaker',
- 504: 'coffee mug',
- 505: 'coffeepot',
- 506: 'coil, spiral, volute, whorl, helix',
- 507: 'combination lock',
- 508: 'computer keyboard, keypad',
- 509: 'confectionery, confectionary, candy store',
- 510: 'container ship, containership, container vessel',
- 511: 'convertible',
- 512: 'corkscrew, bottle screw',
- 513: 'cornet, horn, trumpet, trump',
- 514: 'cowboy boot',
- 515: 'cowboy hat, ten-gallon hat',
- 516: 'cradle',
- 517: 'crane',
- 518: 'crash helmet',
- 519: 'crate',
- 520: 'crib, cot',
- 521: 'Crock Pot',
- 522: 'croquet ball',
- 523: 'crutch',
- 524: 'cuirass',
- 525: 'dam, dike, dyke',
- 526: 'desk',
- 527: 'desktop computer',
- 528: 'dial telephone, dial phone',
- 529: 'diaper, nappy, napkin',
- 530: 'digital clock',
- 531: 'digital watch',
- 532: 'dining table, board',
- 533: 'dishrag, dishcloth',
- 534: 'dishwasher, dish washer, dishwashing machine',
- 535: 'disk brake, disc brake',
- 536: 'dock, dockage, docking facility',
- 537: 'dogsled, dog sled, dog sleigh',
- 538: 'dome',
- 539: 'doormat, welcome mat',
- 540: 'drilling platform, offshore rig',
- 541: 'drum, membranophone, tympan',
- 542: 'drumstick',
- 543: 'dumbbell',
- 544: 'Dutch oven',
- 545: 'electric fan, blower',
- 546: 'electric guitar',
- 547: 'electric locomotive',
- 548: 'entertainment center',
- 549: 'envelope',
- 550: 'espresso maker',
- 551: 'face powder',
- 552: 'feather boa, boa',
- 553: 'file, file cabinet, filing cabinet',
- 554: 'fireboat',
- 555: 'fire engine, fire truck',
- 556: 'fire screen, fireguard',
- 557: 'flagpole, flagstaff',
- 558: 'flute, transverse flute',
- 559: 'folding chair',
- 560: 'football helmet',
- 561: 'forklift',
- 562: 'fountain',
- 563: 'fountain pen',
- 564: 'four-poster',
- 565: 'freight car',
- 566: 'French horn, horn',
- 567: 'frying pan, frypan, skillet',
- 568: 'fur coat',
- 569: 'garbage truck, dustcart',
- 570: 'gasmask, respirator, gas helmet',
- 571: 'gas pump, gasoline pump, petrol pump, island dispenser',
- 572: 'goblet',
- 573: 'go-kart',
- 574: 'golf ball',
- 575: 'golfcart, golf cart',
- 576: 'gondola',
- 577: 'gong, tam-tam',
- 578: 'gown',
- 579: 'grand piano, grand',
- 580: 'greenhouse, nursery, glasshouse',
- 581: 'grille, radiator grille',
- 582: 'grocery store, grocery, food market, market',
- 583: 'guillotine',
- 584: 'hair slide',
- 585: 'hair spray',
- 586: 'half track',
- 587: 'hammer',
- 588: 'hamper',
- 589: 'hand blower, blow dryer, blow drier, hair dryer, hair drier',
- 590: 'hand-held computer, hand-held microcomputer',
- 591: 'handkerchief, hankie, hanky, hankey',
- 592: 'hard disc, hard disk, fixed disk',
- 593: 'harmonica, mouth organ, harp, mouth harp',
- 594: 'harp',
- 595: 'harvester, reaper',
- 596: 'hatchet',
- 597: 'holster',
- 598: 'home theater, home theatre',
- 599: 'honeycomb',
- 600: 'hook, claw',
- 601: 'hoopskirt, crinoline',
- 602: 'horizontal bar, high bar',
- 603: 'horse cart, horse-cart',
- 604: 'hourglass',
- 605: 'iPod',
- 606: 'iron, smoothing iron',
- 607: 'jack-o\'-lantern',
- 608: 'jean, blue jean, denim',
- 609: 'jeep, landrover',
- 610: 'jersey, T-shirt, tee shirt',
- 611: 'jigsaw puzzle',
- 612: 'jinrikisha, ricksha, rickshaw',
- 613: 'joystick',
- 614: 'kimono',
- 615: 'knee pad',
- 616: 'knot',
- 617: 'lab coat, laboratory coat',
- 618: 'ladle',
- 619: 'lampshade, lamp shade',
- 620: 'laptop, laptop computer',
- 621: 'lawn mower, mower',
- 622: 'lens cap, lens cover',
- 623: 'letter opener, paper knife, paperknife',
- 624: 'library',
- 625: 'lifeboat',
- 626: 'lighter, light, igniter, ignitor',
- 627: 'limousine, limo',
- 628: 'liner, ocean liner',
- 629: 'lipstick, lip rouge',
- 630: 'Loafer',
- 631: 'lotion',
- 632: 'loudspeaker, speaker, speaker unit, loudspeaker system, speaker ' +
- 'system',
- 633: 'loupe, jeweler\'s loupe',
- 634: 'lumbermill, sawmill',
- 635: 'magnetic compass',
- 636: 'mailbag, postbag',
- 637: 'mailbox, letter box',
- 638: 'maillot',
- 639: 'maillot, tank suit',
- 640: 'manhole cover',
- 641: 'maraca',
- 642: 'marimba, xylophone',
- 643: 'mask',
- 644: 'matchstick',
- 645: 'maypole',
- 646: 'maze, labyrinth',
- 647: 'measuring cup',
- 648: 'medicine chest, medicine cabinet',
- 649: 'megalith, megalithic structure',
- 650: 'microphone, mike',
- 651: 'microwave, microwave oven',
- 652: 'military uniform',
- 653: 'milk can',
- 654: 'minibus',
- 655: 'miniskirt, mini',
- 656: 'minivan',
- 657: 'missile',
- 658: 'mitten',
- 659: 'mixing bowl',
- 660: 'mobile home, manufactured home',
- 661: 'Model T',
- 662: 'modem',
- 663: 'monastery',
- 664: 'monitor',
- 665: 'moped',
- 666: 'mortar',
- 667: 'mortarboard',
- 668: 'mosque',
- 669: 'mosquito net',
- 670: 'motor scooter, scooter',
- 671: 'mountain bike, all-terrain bike, off-roader',
- 672: 'mountain tent',
- 673: 'mouse, computer mouse',
- 674: 'mousetrap',
- 675: 'moving van',
- 676: 'muzzle',
- 677: 'nail',
- 678: 'neck brace',
- 679: 'necklace',
- 680: 'nipple',
- 681: 'notebook, notebook computer',
- 682: 'obelisk',
- 683: 'oboe, hautboy, hautbois',
- 684: 'ocarina, sweet potato',
- 685: 'odometer, hodometer, mileometer, milometer',
- 686: 'oil filter',
- 687: 'organ, pipe organ',
- 688: 'oscilloscope, scope, cathode-ray oscilloscope, CRO',
- 689: 'overskirt',
- 690: 'oxcart',
- 691: 'oxygen mask',
- 692: 'packet',
- 693: 'paddle, boat paddle',
- 694: 'paddlewheel, paddle wheel',
- 695: 'padlock',
- 696: 'paintbrush',
- 697: 'pajama, pyjama, pj\'s, jammies',
- 698: 'palace',
- 699: 'panpipe, pandean pipe, syrinx',
- 700: 'paper towel',
- 701: 'parachute, chute',
- 702: 'parallel bars, bars',
- 703: 'park bench',
- 704: 'parking meter',
- 705: 'passenger car, coach, carriage',
- 706: 'patio, terrace',
- 707: 'pay-phone, pay-station',
- 708: 'pedestal, plinth, footstall',
- 709: 'pencil box, pencil case',
- 710: 'pencil sharpener',
- 711: 'perfume, essence',
- 712: 'Petri dish',
- 713: 'photocopier',
- 714: 'pick, plectrum, plectron',
- 715: 'pickelhaube',
- 716: 'picket fence, paling',
- 717: 'pickup, pickup truck',
- 718: 'pier',
- 719: 'piggy bank, penny bank',
- 720: 'pill bottle',
- 721: 'pillow',
- 722: 'ping-pong ball',
- 723: 'pinwheel',
- 724: 'pirate, pirate ship',
- 725: 'pitcher, ewer',
- 726: 'plane, carpenter\'s plane, woodworking plane',
- 727: 'planetarium',
- 728: 'plastic bag',
- 729: 'plate rack',
- 730: 'plow, plough',
- 731: 'plunger, plumber\'s helper',
- 732: 'Polaroid camera, Polaroid Land camera',
- 733: 'pole',
- 734: 'police van, police wagon, paddy wagon, patrol wagon, wagon, black ' +
- 'Maria',
- 735: 'poncho',
- 736: 'pool table, billiard table, snooker table',
- 737: 'pop bottle, soda bottle',
- 738: 'pot, flowerpot',
- 739: 'potter\'s wheel',
- 740: 'power drill',
- 741: 'prayer rug, prayer mat',
- 742: 'printer',
- 743: 'prison, prison house',
- 744: 'projectile, missile',
- 745: 'projector',
- 746: 'puck, hockey puck',
- 747: 'punching bag, punch bag, punching ball, punchball',
- 748: 'purse',
- 749: 'quill, quill pen',
- 750: 'quilt, comforter, comfort, puff',
- 751: 'racer, race car, racing car',
- 752: 'racket, racquet',
- 753: 'radiator',
- 754: 'radio, wireless',
- 755: 'radio telescope, radio reflector',
- 756: 'rain barrel',
- 757: 'recreational vehicle, RV, R.V.',
- 758: 'reel',
- 759: 'reflex camera',
- 760: 'refrigerator, icebox',
- 761: 'remote control, remote',
- 762: 'restaurant, eating house, eating place, eatery',
- 763: 'revolver, six-gun, six-shooter',
- 764: 'rifle',
- 765: 'rocking chair, rocker',
- 766: 'rotisserie',
- 767: 'rubber eraser, rubber, pencil eraser',
- 768: 'rugby ball',
- 769: 'rule, ruler',
- 770: 'running shoe',
- 771: 'safe',
- 772: 'safety pin',
- 773: 'saltshaker, salt shaker',
- 774: 'sandal',
- 775: 'sarong',
- 776: 'sax, saxophone',
- 777: 'scabbard',
- 778: 'scale, weighing machine',
- 779: 'school bus',
- 780: 'schooner',
- 781: 'scoreboard',
- 782: 'screen, CRT screen',
- 783: 'screw',
- 784: 'screwdriver',
- 785: 'seat belt, seatbelt',
- 786: 'sewing machine',
- 787: 'shield, buckler',
- 788: 'shoe shop, shoe-shop, shoe store',
- 789: 'shoji',
- 790: 'shopping basket',
- 791: 'shopping cart',
- 792: 'shovel',
- 793: 'shower cap',
- 794: 'shower curtain',
- 795: 'ski',
- 796: 'ski mask',
- 797: 'sleeping bag',
- 798: 'slide rule, slipstick',
- 799: 'sliding door',
- 800: 'slot, one-armed bandit',
- 801: 'snorkel',
- 802: 'snowmobile',
- 803: 'snowplow, snowplough',
- 804: 'soap dispenser',
- 805: 'soccer ball',
- 806: 'sock',
- 807: 'solar dish, solar collector, solar furnace',
- 808: 'sombrero',
- 809: 'soup bowl',
- 810: 'space bar',
- 811: 'space heater',
- 812: 'space shuttle',
- 813: 'spatula',
- 814: 'speedboat',
- 815: 'spider web, spider\'s web',
- 816: 'spindle',
- 817: 'sports car, sport car',
- 818: 'spotlight, spot',
- 819: 'stage',
- 820: 'steam locomotive',
- 821: 'steel arch bridge',
- 822: 'steel drum',
- 823: 'stethoscope',
- 824: 'stole',
- 825: 'stone wall',
- 826: 'stopwatch, stop watch',
- 827: 'stove',
- 828: 'strainer',
- 829: 'streetcar, tram, tramcar, trolley, trolley car',
- 830: 'stretcher',
- 831: 'studio couch, day bed',
- 832: 'stupa, tope',
- 833: 'submarine, pigboat, sub, U-boat',
- 834: 'suit, suit of clothes',
- 835: 'sundial',
- 836: 'sunglass',
- 837: 'sunglasses, dark glasses, shades',
- 838: 'sunscreen, sunblock, sun blocker',
- 839: 'suspension bridge',
- 840: 'swab, swob, mop',
- 841: 'sweatshirt',
- 842: 'swimming trunks, bathing trunks',
- 843: 'swing',
- 844: 'switch, electric switch, electrical switch',
- 845: 'syringe',
- 846: 'table lamp',
- 847: 'tank, army tank, armored combat vehicle, armoured combat vehicle',
- 848: 'tape player',
- 849: 'teapot',
- 850: 'teddy, teddy bear',
- 851: 'television, television system',
- 852: 'tennis ball',
- 853: 'thatch, thatched roof',
- 854: 'theater curtain, theatre curtain',
- 855: 'thimble',
- 856: 'thresher, thrasher, threshing machine',
- 857: 'throne',
- 858: 'tile roof',
- 859: 'toaster',
- 860: 'tobacco shop, tobacconist shop, tobacconist',
- 861: 'toilet seat',
- 862: 'torch',
- 863: 'totem pole',
- 864: 'tow truck, tow car, wrecker',
- 865: 'toyshop',
- 866: 'tractor',
- 867: 'trailer truck, tractor trailer, trucking rig, rig, articulated ' +
- 'lorry, semi',
- 868: 'tray',
- 869: 'trench coat',
- 870: 'tricycle, trike, velocipede',
- 871: 'trimaran',
- 872: 'tripod',
- 873: 'triumphal arch',
- 874: 'trolleybus, trolley coach, trackless trolley',
- 875: 'trombone',
- 876: 'tub, vat',
- 877: 'turnstile',
- 878: 'typewriter keyboard',
- 879: 'umbrella',
- 880: 'unicycle, monocycle',
- 881: 'upright, upright piano',
- 882: 'vacuum, vacuum cleaner',
- 883: 'vase',
- 884: 'vault',
- 885: 'velvet',
- 886: 'vending machine',
- 887: 'vestment',
- 888: 'viaduct',
- 889: 'violin, fiddle',
- 890: 'volleyball',
- 891: 'waffle iron',
- 892: 'wall clock',
- 893: 'wallet, billfold, notecase, pocketbook',
- 894: 'wardrobe, closet, press',
- 895: 'warplane, military plane',
- 896: 'washbasin, handbasin, washbowl, lavabo, wash-hand basin',
- 897: 'washer, automatic washer, washing machine',
- 898: 'water bottle',
- 899: 'water jug',
- 900: 'water tower',
- 901: 'whiskey jug',
- 902: 'whistle',
- 903: 'wig',
- 904: 'window screen',
- 905: 'window shade',
- 906: 'Windsor tie',
- 907: 'wine bottle',
- 908: 'wing',
- 909: 'wok',
- 910: 'wooden spoon',
- 911: 'wool, woolen, woollen',
- 912: 'worm fence, snake fence, snake-rail fence, Virginia fence',
- 913: 'wreck',
- 914: 'yawl',
- 915: 'yurt',
- 916: 'web site, website, internet site, site',
- 917: 'comic book',
- 918: 'crossword puzzle, crossword',
- 919: 'street sign',
- 920: 'traffic light, traffic signal, stoplight',
- 921: 'book jacket, dust cover, dust jacket, dust wrapper',
- 922: 'menu',
- 923: 'plate',
- 924: 'guacamole',
- 925: 'consomme',
- 926: 'hot pot, hotpot',
- 927: 'trifle',
- 928: 'ice cream, icecream',
- 929: 'ice lolly, lolly, lollipop, popsicle',
- 930: 'French loaf',
- 931: 'bagel, beigel',
- 932: 'pretzel',
- 933: 'cheeseburger',
- 934: 'hotdog, hot dog, red hot',
- 935: 'mashed potato',
- 936: 'head cabbage',
- 937: 'broccoli',
- 938: 'cauliflower',
- 939: 'zucchini, courgette',
- 940: 'spaghetti squash',
- 941: 'acorn squash',
- 942: 'butternut squash',
- 943: 'cucumber, cuke',
- 944: 'artichoke, globe artichoke',
- 945: 'bell pepper',
- 946: 'cardoon',
- 947: 'mushroom',
- 948: 'Granny Smith',
- 949: 'strawberry',
- 950: 'orange',
- 951: 'lemon',
- 952: 'fig',
- 953: 'pineapple, ananas',
- 954: 'banana',
- 955: 'jackfruit, jak, jack',
- 956: 'custard apple',
- 957: 'pomegranate',
- 958: 'hay',
- 959: 'carbonara',
- 960: 'chocolate sauce, chocolate syrup',
- 961: 'dough',
- 962: 'meat loaf, meatloaf',
- 963: 'pizza, pizza pie',
- 964: 'potpie',
- 965: 'burrito',
- 966: 'red wine',
- 967: 'espresso',
- 968: 'cup',
- 969: 'eggnog',
- 970: 'alp',
- 971: 'bubble',
- 972: 'cliff, drop, drop-off',
- 973: 'coral reef',
- 974: 'geyser',
- 975: 'lakeside, lakeshore',
- 976: 'promontory, headland, head, foreland',
- 977: 'sandbar, sand bar',
- 978: 'seashore, coast, seacoast, sea-coast',
- 979: 'valley, vale',
- 980: 'volcano',
- 981: 'ballplayer, baseball player',
- 982: 'groom, bridegroom',
- 983: 'scuba diver',
- 984: 'rapeseed',
- 985: 'daisy',
- 986: 'yellow lady\'s slipper, yellow lady-slipper, Cypripedium calceolus, ' +
- 'Cypripedium parviflorum',
- 987: 'corn',
- 988: 'acorn',
- 989: 'hip, rose hip, rosehip',
- 990: 'buckeye, horse chestnut, conker',
- 991: 'coral fungus',
- 992: 'agaric',
- 993: 'gyromitra',
- 994: 'stinkhorn, carrion fungus',
- 995: 'earthstar',
- 996: 'hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola ' +
- 'frondosa',
- 997: 'bolete',
- 998: 'ear, spike, capitulum',
- 999: 'toilet tissue, toilet paper, bathroom tissue'
- };
- },{}],11:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var tf = require("@tensorflow/tfjs");
- var imagenet_classes_1 = require("./imagenet_classes");
- // var BASE_PATH = 'https://storage.googleapis.com/tfjs-models/tfjs/';
- var BASE_PATH = 'https://cocorobo.cn/model/';
- var IMAGE_SIZE = 224;
- function load(version, alpha) {
- if (version === void 0) { version = 1; }
- if (alpha === void 0) { alpha = 1.0; }
- return __awaiter(this, void 0, void 0, function () {
- var mobilenet;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (tf == null) {
- throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please " +
- "also include @tensorflow/tfjs on the page before using this model.");
- }
- if (version !== 1) {
- throw new Error("Currently only MobileNet V1 is supported. Got version " + version + ".");
- }
- if ([0.25, 0.50, 0.75, 1.0].indexOf(alpha) === -1) {
- throw new Error("MobileNet constructed with invalid alpha " +
- (alpha + ". Valid multipliers are 0.25, 0.50, 0.75, and 1.0."));
- }
- mobilenet = new MobileNet(version, alpha);
- return [4, mobilenet.load()];
- case 1:
- _a.sent();
- return [2, mobilenet];
- }
- });
- });
- }
- exports.load = load;
- var MobileNet = (function () {
- function MobileNet(version, alpha) {
- this.intermediateModels = {};
- var multiplierStr = ({ 0.25: '0.25', 0.50: '0.50', 0.75: '0.75', 1.0: '1.0' })[alpha];
- this.path = BASE_PATH + "model.json";
- // this.path =
- // BASE_PATH + "mobilenet_v" + version + "_" + multiplierStr + "_" + IMAGE_SIZE + "/" +
- // "model.json";
- this.normalizationOffset = tf.scalar(127.5);
- }
- MobileNet.prototype.load = function () {
- return __awaiter(this, void 0, void 0, function () {
- var _a, result;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- _a = this;
- return [4, tf.loadModel(this.path)];
- case 1:
- _a.model = _b.sent();
- this.endpoints = this.model.layers.map(function (l) { return l.name; });
- result = this.model.predict(tf.zeros([1, IMAGE_SIZE, IMAGE_SIZE, 3]));
- return [4, result.data()];
- case 2:
- _b.sent();
- result.dispose();
- return [2];
- }
- });
- });
- };
- MobileNet.prototype.infer = function (img, endpoint) {
- var _this = this;
- if (endpoint != null && this.endpoints.indexOf(endpoint) === -1) {
- throw new Error("Unknown endpoint " + endpoint + ". Available endpoints: " +
- (this.endpoints + "."));
- }
- return tf.tidy(function () {
- if (!(img instanceof tf.Tensor)) {
- img = tf.fromPixels(img);
- }
- var normalized = img.toFloat()
- .sub(_this.normalizationOffset)
- .div(_this.normalizationOffset);
- var resized = normalized;
- if (img.shape[0] !== IMAGE_SIZE || img.shape[1] !== IMAGE_SIZE) {
- var alignCorners = true;
- resized = tf.image.resizeBilinear(normalized, [IMAGE_SIZE, IMAGE_SIZE], alignCorners);
- }
- var batched = resized.reshape([1, IMAGE_SIZE, IMAGE_SIZE, 3]);
- var model;
- if (endpoint == null) {
- model = _this.model;
- }
- else {
- if (_this.intermediateModels[endpoint] == null) {
- var layer = _this.model.layers.find(function (l) { return l.name === endpoint; });
- _this.intermediateModels[endpoint] =
- tf.model({ inputs: _this.model.inputs, outputs: layer.output });
- }
- model = _this.intermediateModels[endpoint];
- }
- return model.predict(batched);
- });
- };
- MobileNet.prototype.classify = function (img, topk) {
- if (topk === void 0) { topk = 3; }
- return __awaiter(this, void 0, void 0, function () {
- var logits, classes;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- logits = this.infer(img);
- return [4, getTopKClasses(logits, topk)];
- case 1:
- classes = _a.sent();
- logits.dispose();
- return [2, classes];
- }
- });
- });
- };
- return MobileNet;
- }());
- exports.MobileNet = MobileNet;
- function getTopKClasses(logits, topK) {
- return __awaiter(this, void 0, void 0, function () {
- var values, valuesAndIndices, i, topkValues, topkIndices, i, topClassesAndProbs, i;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0: return [4, logits.data()];
- case 1:
- values = _a.sent();
- valuesAndIndices = [];
- for (i = 0; i < values.length; i++) {
- valuesAndIndices.push({ value: values[i], index: i });
- }
- valuesAndIndices.sort(function (a, b) {
- return b.value - a.value;
- });
- topkValues = new Float32Array(topK);
- topkIndices = new Int32Array(topK);
- for (i = 0; i < topK; i++) {
- topkValues[i] = valuesAndIndices[i].value;
- topkIndices[i] = valuesAndIndices[i].index;
- }
- topClassesAndProbs = [];
- for (i = 0; i < topkIndices.length; i++) {
- topClassesAndProbs.push({
- className: imagenet_classes_1.IMAGENET_CLASSES[topkIndices[i]],
- probability: topkValues[i]
- });
- }
- return [2, topClassesAndProbs];
- }
- });
- });
- }
- },{"./imagenet_classes":10,"@tensorflow/tfjs":205}],12:[function(require,module,exports){
- /*eslint-disable block-scoped-var, no-redeclare, no-control-regex, no-prototype-builtins*/
- "use strict";
- var $protobuf = require("protobufjs/minimal");
- var $Reader = $protobuf.Reader, $util = $protobuf.util;
- var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
- $root.tensorflow = (function() {
- var tensorflow = {};
- tensorflow.Any = (function() {
- function Any(p) {
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- Any.prototype.typeUrl = "";
- Any.prototype.value = $util.newBuffer([]);
- Any.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.Any();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.typeUrl = r.string();
- break;
- case 2:
- m.value = r.bytes();
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return Any;
- })();
- tensorflow.DataType = (function() {
- var valuesById = {}, values = Object.create(valuesById);
- values[valuesById[0] = "DT_INVALID"] = 0;
- values[valuesById[1] = "DT_FLOAT"] = 1;
- values[valuesById[2] = "DT_DOUBLE"] = 2;
- values[valuesById[3] = "DT_INT32"] = 3;
- values[valuesById[4] = "DT_UINT8"] = 4;
- values[valuesById[5] = "DT_INT16"] = 5;
- values[valuesById[6] = "DT_INT8"] = 6;
- values[valuesById[7] = "DT_STRING"] = 7;
- values[valuesById[8] = "DT_COMPLEX64"] = 8;
- values[valuesById[9] = "DT_INT64"] = 9;
- values[valuesById[10] = "DT_BOOL"] = 10;
- values[valuesById[11] = "DT_QINT8"] = 11;
- values[valuesById[12] = "DT_QUINT8"] = 12;
- values[valuesById[13] = "DT_QINT32"] = 13;
- values[valuesById[14] = "DT_BFLOAT16"] = 14;
- values[valuesById[101] = "DT_FLOAT_REF"] = 101;
- values[valuesById[102] = "DT_DOUBLE_REF"] = 102;
- values[valuesById[103] = "DT_INT32_REF"] = 103;
- values[valuesById[104] = "DT_UINT8_REF"] = 104;
- values[valuesById[105] = "DT_INT16_REF"] = 105;
- values[valuesById[106] = "DT_INT8_REF"] = 106;
- values[valuesById[107] = "DT_STRING_REF"] = 107;
- values[valuesById[108] = "DT_COMPLEX64_REF"] = 108;
- values[valuesById[109] = "DT_INT64_REF"] = 109;
- values[valuesById[110] = "DT_BOOL_REF"] = 110;
- values[valuesById[111] = "DT_QINT8_REF"] = 111;
- values[valuesById[112] = "DT_QUINT8_REF"] = 112;
- values[valuesById[113] = "DT_QINT32_REF"] = 113;
- values[valuesById[114] = "DT_BFLOAT16_REF"] = 114;
- return values;
- })();
- tensorflow.TensorShape = (function() {
- function TensorShape(p) {
- this.dim = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- TensorShape.prototype.dim = $util.emptyArray;
- TensorShape.prototype.unknownRank = false;
- TensorShape.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.TensorShape();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 2:
- if (!(m.dim && m.dim.length))
- m.dim = [];
- m.dim.push($root.tensorflow.TensorShape.Dim.decode(r, r.uint32()));
- break;
- case 3:
- m.unknownRank = r.bool();
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- TensorShape.Dim = (function() {
- function Dim(p) {
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- Dim.prototype.size = $util.Long ? $util.Long.fromBits(0,0,false) : 0;
- Dim.prototype.name = "";
- Dim.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.TensorShape.Dim();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.size = r.int64();
- break;
- case 2:
- m.name = r.string();
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return Dim;
- })();
- return TensorShape;
- })();
- tensorflow.Tensor = (function() {
- function Tensor(p) {
- this.floatVal = [];
- this.doubleVal = [];
- this.intVal = [];
- this.stringVal = [];
- this.scomplexVal = [];
- this.int64Val = [];
- this.boolVal = [];
- this.uint32Val = [];
- this.uint64Val = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- Tensor.prototype.dtype = 0;
- Tensor.prototype.tensorShape = null;
- Tensor.prototype.versionNumber = 0;
- Tensor.prototype.tensorContent = $util.newBuffer([]);
- Tensor.prototype.floatVal = $util.emptyArray;
- Tensor.prototype.doubleVal = $util.emptyArray;
- Tensor.prototype.intVal = $util.emptyArray;
- Tensor.prototype.stringVal = $util.emptyArray;
- Tensor.prototype.scomplexVal = $util.emptyArray;
- Tensor.prototype.int64Val = $util.emptyArray;
- Tensor.prototype.boolVal = $util.emptyArray;
- Tensor.prototype.uint32Val = $util.emptyArray;
- Tensor.prototype.uint64Val = $util.emptyArray;
- Tensor.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.Tensor();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.dtype = r.int32();
- break;
- case 2:
- m.tensorShape = $root.tensorflow.TensorShape.decode(r, r.uint32());
- break;
- case 3:
- m.versionNumber = r.int32();
- break;
- case 4:
- m.tensorContent = r.bytes();
- break;
- case 5:
- if (!(m.floatVal && m.floatVal.length))
- m.floatVal = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.floatVal.push(r.float());
- } else
- m.floatVal.push(r.float());
- break;
- case 6:
- if (!(m.doubleVal && m.doubleVal.length))
- m.doubleVal = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.doubleVal.push(r.double());
- } else
- m.doubleVal.push(r.double());
- break;
- case 7:
- if (!(m.intVal && m.intVal.length))
- m.intVal = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.intVal.push(r.int32());
- } else
- m.intVal.push(r.int32());
- break;
- case 8:
- if (!(m.stringVal && m.stringVal.length))
- m.stringVal = [];
- m.stringVal.push(r.bytes());
- break;
- case 9:
- if (!(m.scomplexVal && m.scomplexVal.length))
- m.scomplexVal = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.scomplexVal.push(r.float());
- } else
- m.scomplexVal.push(r.float());
- break;
- case 10:
- if (!(m.int64Val && m.int64Val.length))
- m.int64Val = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.int64Val.push(r.int64());
- } else
- m.int64Val.push(r.int64());
- break;
- case 11:
- if (!(m.boolVal && m.boolVal.length))
- m.boolVal = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.boolVal.push(r.bool());
- } else
- m.boolVal.push(r.bool());
- break;
- case 16:
- if (!(m.uint32Val && m.uint32Val.length))
- m.uint32Val = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.uint32Val.push(r.uint32());
- } else
- m.uint32Val.push(r.uint32());
- break;
- case 17:
- if (!(m.uint64Val && m.uint64Val.length))
- m.uint64Val = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.uint64Val.push(r.uint64());
- } else
- m.uint64Val.push(r.uint64());
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return Tensor;
- })();
- tensorflow.AttrValue = (function() {
- function AttrValue(p) {
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- AttrValue.prototype.list = null;
- AttrValue.prototype.s = $util.newBuffer([]);
- AttrValue.prototype.i = $util.Long ? $util.Long.fromBits(0,0,false) : 0;
- AttrValue.prototype.f = 0;
- AttrValue.prototype.b = false;
- AttrValue.prototype.type = 0;
- AttrValue.prototype.shape = null;
- AttrValue.prototype.tensor = null;
- AttrValue.prototype.placeholder = "";
- AttrValue.prototype.func = null;
- var $oneOfFields;
- Object.defineProperty(AttrValue.prototype, "value", {
- get: $util.oneOfGetter($oneOfFields = ["list", "s", "i", "f", "b", "type", "shape", "tensor", "placeholder", "func"]),
- set: $util.oneOfSetter($oneOfFields)
- });
- AttrValue.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.AttrValue();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.list = $root.tensorflow.AttrValue.ListValue.decode(r, r.uint32());
- break;
- case 2:
- m.s = r.bytes();
- break;
- case 3:
- m.i = r.int64();
- break;
- case 4:
- m.f = r.float();
- break;
- case 5:
- m.b = r.bool();
- break;
- case 6:
- m.type = r.int32();
- break;
- case 7:
- m.shape = $root.tensorflow.TensorShape.decode(r, r.uint32());
- break;
- case 8:
- m.tensor = $root.tensorflow.Tensor.decode(r, r.uint32());
- break;
- case 9:
- m.placeholder = r.string();
- break;
- case 10:
- m.func = $root.tensorflow.NameAttrList.decode(r, r.uint32());
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- AttrValue.ListValue = (function() {
- function ListValue(p) {
- this.s = [];
- this.i = [];
- this.f = [];
- this.b = [];
- this.type = [];
- this.shape = [];
- this.tensor = [];
- this.func = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- ListValue.prototype.s = $util.emptyArray;
- ListValue.prototype.i = $util.emptyArray;
- ListValue.prototype.f = $util.emptyArray;
- ListValue.prototype.b = $util.emptyArray;
- ListValue.prototype.type = $util.emptyArray;
- ListValue.prototype.shape = $util.emptyArray;
- ListValue.prototype.tensor = $util.emptyArray;
- ListValue.prototype.func = $util.emptyArray;
- ListValue.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.AttrValue.ListValue();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 2:
- if (!(m.s && m.s.length))
- m.s = [];
- m.s.push(r.bytes());
- break;
- case 3:
- if (!(m.i && m.i.length))
- m.i = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.i.push(r.int64());
- } else
- m.i.push(r.int64());
- break;
- case 4:
- if (!(m.f && m.f.length))
- m.f = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.f.push(r.float());
- } else
- m.f.push(r.float());
- break;
- case 5:
- if (!(m.b && m.b.length))
- m.b = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.b.push(r.bool());
- } else
- m.b.push(r.bool());
- break;
- case 6:
- if (!(m.type && m.type.length))
- m.type = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.type.push(r.int32());
- } else
- m.type.push(r.int32());
- break;
- case 7:
- if (!(m.shape && m.shape.length))
- m.shape = [];
- m.shape.push($root.tensorflow.TensorShape.decode(r, r.uint32()));
- break;
- case 8:
- if (!(m.tensor && m.tensor.length))
- m.tensor = [];
- m.tensor.push($root.tensorflow.Tensor.decode(r, r.uint32()));
- break;
- case 9:
- if (!(m.func && m.func.length))
- m.func = [];
- m.func.push($root.tensorflow.NameAttrList.decode(r, r.uint32()));
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return ListValue;
- })();
- return AttrValue;
- })();
- tensorflow.NameAttrList = (function() {
- function NameAttrList(p) {
- this.attr = {};
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- NameAttrList.prototype.name = "";
- NameAttrList.prototype.attr = $util.emptyObject;
- NameAttrList.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.NameAttrList(), k;
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.name = r.string();
- break;
- case 2:
- r.skip().pos++;
- if (m.attr === $util.emptyObject)
- m.attr = {};
- k = r.string();
- r.pos++;
- m.attr[k] = $root.tensorflow.AttrValue.decode(r, r.uint32());
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return NameAttrList;
- })();
- tensorflow.NodeDef = (function() {
- function NodeDef(p) {
- this.input = [];
- this.attr = {};
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- NodeDef.prototype.name = "";
- NodeDef.prototype.op = "";
- NodeDef.prototype.input = $util.emptyArray;
- NodeDef.prototype.device = "";
- NodeDef.prototype.attr = $util.emptyObject;
- NodeDef.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.NodeDef(), k;
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.name = r.string();
- break;
- case 2:
- m.op = r.string();
- break;
- case 3:
- if (!(m.input && m.input.length))
- m.input = [];
- m.input.push(r.string());
- break;
- case 4:
- m.device = r.string();
- break;
- case 5:
- r.skip().pos++;
- if (m.attr === $util.emptyObject)
- m.attr = {};
- k = r.string();
- r.pos++;
- m.attr[k] = $root.tensorflow.AttrValue.decode(r, r.uint32());
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return NodeDef;
- })();
- tensorflow.VersionDef = (function() {
- function VersionDef(p) {
- this.badConsumers = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- VersionDef.prototype.producer = 0;
- VersionDef.prototype.minConsumer = 0;
- VersionDef.prototype.badConsumers = $util.emptyArray;
- VersionDef.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.VersionDef();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.producer = r.int32();
- break;
- case 2:
- m.minConsumer = r.int32();
- break;
- case 3:
- if (!(m.badConsumers && m.badConsumers.length))
- m.badConsumers = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.badConsumers.push(r.int32());
- } else
- m.badConsumers.push(r.int32());
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return VersionDef;
- })();
- tensorflow.GraphDef = (function() {
- function GraphDef(p) {
- this.node = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- GraphDef.prototype.node = $util.emptyArray;
- GraphDef.prototype.versions = null;
- GraphDef.prototype.library = null;
- GraphDef.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.GraphDef();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- if (!(m.node && m.node.length))
- m.node = [];
- m.node.push($root.tensorflow.NodeDef.decode(r, r.uint32()));
- break;
- case 4:
- m.versions = $root.tensorflow.VersionDef.decode(r, r.uint32());
- break;
- case 2:
- m.library = $root.tensorflow.FunctionDefLibrary.decode(r, r.uint32());
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return GraphDef;
- })();
- tensorflow.CollectionDef = (function() {
- function CollectionDef(p) {
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- CollectionDef.prototype.nodeList = null;
- CollectionDef.prototype.bytesList = null;
- CollectionDef.prototype.int64List = null;
- CollectionDef.prototype.floatList = null;
- CollectionDef.prototype.anyList = null;
- var $oneOfFields;
- Object.defineProperty(CollectionDef.prototype, "kind", {
- get: $util.oneOfGetter($oneOfFields = ["nodeList", "bytesList", "int64List", "floatList", "anyList"]),
- set: $util.oneOfSetter($oneOfFields)
- });
- CollectionDef.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.CollectionDef();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.nodeList = $root.tensorflow.CollectionDef.NodeList.decode(r, r.uint32());
- break;
- case 2:
- m.bytesList = $root.tensorflow.CollectionDef.BytesList.decode(r, r.uint32());
- break;
- case 3:
- m.int64List = $root.tensorflow.CollectionDef.Int64List.decode(r, r.uint32());
- break;
- case 4:
- m.floatList = $root.tensorflow.CollectionDef.FloatList.decode(r, r.uint32());
- break;
- case 5:
- m.anyList = $root.tensorflow.CollectionDef.AnyList.decode(r, r.uint32());
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- CollectionDef.NodeList = (function() {
- function NodeList(p) {
- this.value = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- NodeList.prototype.value = $util.emptyArray;
- NodeList.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.CollectionDef.NodeList();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- if (!(m.value && m.value.length))
- m.value = [];
- m.value.push(r.string());
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return NodeList;
- })();
- CollectionDef.BytesList = (function() {
- function BytesList(p) {
- this.value = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- BytesList.prototype.value = $util.emptyArray;
- BytesList.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.CollectionDef.BytesList();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- if (!(m.value && m.value.length))
- m.value = [];
- m.value.push(r.bytes());
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return BytesList;
- })();
- CollectionDef.Int64List = (function() {
- function Int64List(p) {
- this.value = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- Int64List.prototype.value = $util.emptyArray;
- Int64List.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.CollectionDef.Int64List();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- if (!(m.value && m.value.length))
- m.value = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.value.push(r.int64());
- } else
- m.value.push(r.int64());
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return Int64List;
- })();
- CollectionDef.FloatList = (function() {
- function FloatList(p) {
- this.value = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- FloatList.prototype.value = $util.emptyArray;
- FloatList.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.CollectionDef.FloatList();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- if (!(m.value && m.value.length))
- m.value = [];
- if ((t & 7) === 2) {
- var c2 = r.uint32() + r.pos;
- while (r.pos < c2)
- m.value.push(r.float());
- } else
- m.value.push(r.float());
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return FloatList;
- })();
- CollectionDef.AnyList = (function() {
- function AnyList(p) {
- this.value = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- AnyList.prototype.value = $util.emptyArray;
- AnyList.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.CollectionDef.AnyList();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- if (!(m.value && m.value.length))
- m.value = [];
- m.value.push($root.tensorflow.Any.decode(r, r.uint32()));
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return AnyList;
- })();
- return CollectionDef;
- })();
- tensorflow.SaverDef = (function() {
- function SaverDef(p) {
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- SaverDef.prototype.filenameTensorName = "";
- SaverDef.prototype.saveTensorName = "";
- SaverDef.prototype.restoreOpName = "";
- SaverDef.prototype.maxToKeep = 0;
- SaverDef.prototype.sharded = false;
- SaverDef.prototype.keepCheckpointEveryNHours = 0;
- SaverDef.prototype.version = 0;
- SaverDef.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.SaverDef();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.filenameTensorName = r.string();
- break;
- case 2:
- m.saveTensorName = r.string();
- break;
- case 3:
- m.restoreOpName = r.string();
- break;
- case 4:
- m.maxToKeep = r.int32();
- break;
- case 5:
- m.sharded = r.bool();
- break;
- case 6:
- m.keepCheckpointEveryNHours = r.float();
- break;
- case 7:
- m.version = r.int32();
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- SaverDef.CheckpointFormatVersion = (function() {
- var valuesById = {}, values = Object.create(valuesById);
- values[valuesById[0] = "LEGACY"] = 0;
- values[valuesById[1] = "V1"] = 1;
- values[valuesById[2] = "V2"] = 2;
- return values;
- })();
- return SaverDef;
- })();
- tensorflow.TensorInfo = (function() {
- function TensorInfo(p) {
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- TensorInfo.prototype.name = "";
- TensorInfo.prototype.cooSparse = null;
- TensorInfo.prototype.dtype = 0;
- TensorInfo.prototype.tensorShape = null;
- var $oneOfFields;
- Object.defineProperty(TensorInfo.prototype, "encoding", {
- get: $util.oneOfGetter($oneOfFields = ["name", "cooSparse"]),
- set: $util.oneOfSetter($oneOfFields)
- });
- TensorInfo.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.TensorInfo();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.name = r.string();
- break;
- case 4:
- m.cooSparse = $root.tensorflow.TensorInfo.CooSparse.decode(r, r.uint32());
- break;
- case 2:
- m.dtype = r.int32();
- break;
- case 3:
- m.tensorShape = $root.tensorflow.TensorShape.decode(r, r.uint32());
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- TensorInfo.CooSparse = (function() {
- function CooSparse(p) {
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- CooSparse.prototype.valuesTensorName = "";
- CooSparse.prototype.indicesTensorName = "";
- CooSparse.prototype.denseShapeTensorName = "";
- CooSparse.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.TensorInfo.CooSparse();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.valuesTensorName = r.string();
- break;
- case 2:
- m.indicesTensorName = r.string();
- break;
- case 3:
- m.denseShapeTensorName = r.string();
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return CooSparse;
- })();
- return TensorInfo;
- })();
- tensorflow.SignatureDef = (function() {
- function SignatureDef(p) {
- this.inputs = {};
- this.outputs = {};
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- SignatureDef.prototype.inputs = $util.emptyObject;
- SignatureDef.prototype.outputs = $util.emptyObject;
- SignatureDef.prototype.methodName = "";
- SignatureDef.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.SignatureDef(), k;
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- r.skip().pos++;
- if (m.inputs === $util.emptyObject)
- m.inputs = {};
- k = r.string();
- r.pos++;
- m.inputs[k] = $root.tensorflow.TensorInfo.decode(r, r.uint32());
- break;
- case 2:
- r.skip().pos++;
- if (m.outputs === $util.emptyObject)
- m.outputs = {};
- k = r.string();
- r.pos++;
- m.outputs[k] = $root.tensorflow.TensorInfo.decode(r, r.uint32());
- break;
- case 3:
- m.methodName = r.string();
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return SignatureDef;
- })();
- tensorflow.AssetFileDef = (function() {
- function AssetFileDef(p) {
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- AssetFileDef.prototype.tensorInfo = null;
- AssetFileDef.prototype.filename = "";
- AssetFileDef.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.AssetFileDef();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.tensorInfo = $root.tensorflow.TensorInfo.decode(r, r.uint32());
- break;
- case 2:
- m.filename = r.string();
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return AssetFileDef;
- })();
- tensorflow.OpDef = (function() {
- function OpDef(p) {
- this.inputArg = [];
- this.outputArg = [];
- this.attr = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- OpDef.prototype.name = "";
- OpDef.prototype.inputArg = $util.emptyArray;
- OpDef.prototype.outputArg = $util.emptyArray;
- OpDef.prototype.attr = $util.emptyArray;
- OpDef.prototype.deprecation = null;
- OpDef.prototype.summary = "";
- OpDef.prototype.description = "";
- OpDef.prototype.isCommutative = false;
- OpDef.prototype.isAggregate = false;
- OpDef.prototype.isStateful = false;
- OpDef.prototype.allowsUninitializedInput = false;
- OpDef.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.OpDef();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.name = r.string();
- break;
- case 2:
- if (!(m.inputArg && m.inputArg.length))
- m.inputArg = [];
- m.inputArg.push($root.tensorflow.OpDef.ArgDef.decode(r, r.uint32()));
- break;
- case 3:
- if (!(m.outputArg && m.outputArg.length))
- m.outputArg = [];
- m.outputArg.push($root.tensorflow.OpDef.ArgDef.decode(r, r.uint32()));
- break;
- case 4:
- if (!(m.attr && m.attr.length))
- m.attr = [];
- m.attr.push($root.tensorflow.OpDef.AttrDef.decode(r, r.uint32()));
- break;
- case 8:
- m.deprecation = $root.tensorflow.OpDef.OpDeprecation.decode(r, r.uint32());
- break;
- case 5:
- m.summary = r.string();
- break;
- case 6:
- m.description = r.string();
- break;
- case 18:
- m.isCommutative = r.bool();
- break;
- case 16:
- m.isAggregate = r.bool();
- break;
- case 17:
- m.isStateful = r.bool();
- break;
- case 19:
- m.allowsUninitializedInput = r.bool();
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- OpDef.ArgDef = (function() {
- function ArgDef(p) {
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- ArgDef.prototype.name = "";
- ArgDef.prototype.description = "";
- ArgDef.prototype.type = 0;
- ArgDef.prototype.typeAttr = "";
- ArgDef.prototype.numberAttr = "";
- ArgDef.prototype.typeListAttr = "";
- ArgDef.prototype.isRef = false;
- ArgDef.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.OpDef.ArgDef();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.name = r.string();
- break;
- case 2:
- m.description = r.string();
- break;
- case 3:
- m.type = r.int32();
- break;
- case 4:
- m.typeAttr = r.string();
- break;
- case 5:
- m.numberAttr = r.string();
- break;
- case 6:
- m.typeListAttr = r.string();
- break;
- case 16:
- m.isRef = r.bool();
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return ArgDef;
- })();
- OpDef.AttrDef = (function() {
- function AttrDef(p) {
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- AttrDef.prototype.name = "";
- AttrDef.prototype.type = "";
- AttrDef.prototype.defaultValue = null;
- AttrDef.prototype.description = "";
- AttrDef.prototype.hasMinimum = false;
- AttrDef.prototype.minimum = $util.Long ? $util.Long.fromBits(0,0,false) : 0;
- AttrDef.prototype.allowedValues = null;
- AttrDef.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.OpDef.AttrDef();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.name = r.string();
- break;
- case 2:
- m.type = r.string();
- break;
- case 3:
- m.defaultValue = $root.tensorflow.AttrValue.decode(r, r.uint32());
- break;
- case 4:
- m.description = r.string();
- break;
- case 5:
- m.hasMinimum = r.bool();
- break;
- case 6:
- m.minimum = r.int64();
- break;
- case 7:
- m.allowedValues = $root.tensorflow.AttrValue.decode(r, r.uint32());
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return AttrDef;
- })();
- OpDef.OpDeprecation = (function() {
- function OpDeprecation(p) {
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- OpDeprecation.prototype.version = 0;
- OpDeprecation.prototype.explanation = "";
- OpDeprecation.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.OpDef.OpDeprecation();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.version = r.int32();
- break;
- case 2:
- m.explanation = r.string();
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return OpDeprecation;
- })();
- return OpDef;
- })();
- tensorflow.OpList = (function() {
- function OpList(p) {
- this.op = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- OpList.prototype.op = $util.emptyArray;
- OpList.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.OpList();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- if (!(m.op && m.op.length))
- m.op = [];
- m.op.push($root.tensorflow.OpDef.decode(r, r.uint32()));
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return OpList;
- })();
- tensorflow.MetaGraphDef = (function() {
- function MetaGraphDef(p) {
- this.collectionDef = {};
- this.signatureDef = {};
- this.assetFileDef = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- MetaGraphDef.prototype.metaInfoDef = null;
- MetaGraphDef.prototype.graphDef = null;
- MetaGraphDef.prototype.saverDef = null;
- MetaGraphDef.prototype.collectionDef = $util.emptyObject;
- MetaGraphDef.prototype.signatureDef = $util.emptyObject;
- MetaGraphDef.prototype.assetFileDef = $util.emptyArray;
- MetaGraphDef.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.MetaGraphDef(), k;
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.metaInfoDef = $root.tensorflow.MetaGraphDef.MetaInfoDef.decode(r, r.uint32());
- break;
- case 2:
- m.graphDef = $root.tensorflow.GraphDef.decode(r, r.uint32());
- break;
- case 3:
- m.saverDef = $root.tensorflow.SaverDef.decode(r, r.uint32());
- break;
- case 4:
- r.skip().pos++;
- if (m.collectionDef === $util.emptyObject)
- m.collectionDef = {};
- k = r.string();
- r.pos++;
- m.collectionDef[k] = $root.tensorflow.CollectionDef.decode(r, r.uint32());
- break;
- case 5:
- r.skip().pos++;
- if (m.signatureDef === $util.emptyObject)
- m.signatureDef = {};
- k = r.string();
- r.pos++;
- m.signatureDef[k] = $root.tensorflow.SignatureDef.decode(r, r.uint32());
- break;
- case 6:
- if (!(m.assetFileDef && m.assetFileDef.length))
- m.assetFileDef = [];
- m.assetFileDef.push($root.tensorflow.AssetFileDef.decode(r, r.uint32()));
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- MetaGraphDef.MetaInfoDef = (function() {
- function MetaInfoDef(p) {
- this.tags = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- MetaInfoDef.prototype.metaGraphVersion = "";
- MetaInfoDef.prototype.strippedOpList = null;
- MetaInfoDef.prototype.anyInfo = null;
- MetaInfoDef.prototype.tags = $util.emptyArray;
- MetaInfoDef.prototype.tensorflowVersion = "";
- MetaInfoDef.prototype.tensorflowGitVersion = "";
- MetaInfoDef.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.MetaGraphDef.MetaInfoDef();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.metaGraphVersion = r.string();
- break;
- case 2:
- m.strippedOpList = $root.tensorflow.OpList.decode(r, r.uint32());
- break;
- case 3:
- m.anyInfo = $root.tensorflow.Any.decode(r, r.uint32());
- break;
- case 4:
- if (!(m.tags && m.tags.length))
- m.tags = [];
- m.tags.push(r.string());
- break;
- case 5:
- m.tensorflowVersion = r.string();
- break;
- case 6:
- m.tensorflowGitVersion = r.string();
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return MetaInfoDef;
- })();
- return MetaGraphDef;
- })();
- tensorflow.SavedModel = (function() {
- function SavedModel(p) {
- this.metaGraphs = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- SavedModel.prototype.savedModelSchemaVersion = $util.Long ? $util.Long.fromBits(0,0,false) : 0;
- SavedModel.prototype.metaGraphs = $util.emptyArray;
- SavedModel.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.SavedModel();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.savedModelSchemaVersion = r.int64();
- break;
- case 2:
- if (!(m.metaGraphs && m.metaGraphs.length))
- m.metaGraphs = [];
- m.metaGraphs.push($root.tensorflow.MetaGraphDef.decode(r, r.uint32()));
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return SavedModel;
- })();
- tensorflow.FunctionDefLibrary = (function() {
- function FunctionDefLibrary(p) {
- this["function"] = [];
- this.gradient = [];
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- FunctionDefLibrary.prototype["function"] = $util.emptyArray;
- FunctionDefLibrary.prototype.gradient = $util.emptyArray;
- FunctionDefLibrary.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.FunctionDefLibrary();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- if (!(m["function"] && m["function"].length))
- m["function"] = [];
- m["function"].push($root.tensorflow.FunctionDef.decode(r, r.uint32()));
- break;
- case 2:
- if (!(m.gradient && m.gradient.length))
- m.gradient = [];
- m.gradient.push($root.tensorflow.GradientDef.decode(r, r.uint32()));
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return FunctionDefLibrary;
- })();
- tensorflow.FunctionDef = (function() {
- function FunctionDef(p) {
- this.attr = {};
- this.nodeDef = [];
- this.ret = {};
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- FunctionDef.prototype.signature = null;
- FunctionDef.prototype.attr = $util.emptyObject;
- FunctionDef.prototype.nodeDef = $util.emptyArray;
- FunctionDef.prototype.ret = $util.emptyObject;
- FunctionDef.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.FunctionDef(), k;
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.signature = $root.tensorflow.OpDef.decode(r, r.uint32());
- break;
- case 5:
- r.skip().pos++;
- if (m.attr === $util.emptyObject)
- m.attr = {};
- k = r.string();
- r.pos++;
- m.attr[k] = $root.tensorflow.AttrValue.decode(r, r.uint32());
- break;
- case 3:
- if (!(m.nodeDef && m.nodeDef.length))
- m.nodeDef = [];
- m.nodeDef.push($root.tensorflow.NodeDef.decode(r, r.uint32()));
- break;
- case 4:
- r.skip().pos++;
- if (m.ret === $util.emptyObject)
- m.ret = {};
- k = r.string();
- r.pos++;
- m.ret[k] = r.string();
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return FunctionDef;
- })();
- tensorflow.GradientDef = (function() {
- function GradientDef(p) {
- if (p)
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
- if (p[ks[i]] != null)
- this[ks[i]] = p[ks[i]];
- }
- GradientDef.prototype.functionName = "";
- GradientDef.prototype.gradientFunc = "";
- GradientDef.decode = function decode(r, l) {
- if (!(r instanceof $Reader))
- r = $Reader.create(r);
- var c = l === undefined ? r.len : r.pos + l, m = new $root.tensorflow.GradientDef();
- while (r.pos < c) {
- var t = r.uint32();
- switch (t >>> 3) {
- case 1:
- m.functionName = r.string();
- break;
- case 2:
- m.gradientFunc = r.string();
- break;
- default:
- r.skipType(t & 7);
- break;
- }
- }
- return m;
- };
- return GradientDef;
- })();
- return tensorflow;
- })();
- module.exports = $root;
- },{"protobufjs/minimal":216}],13:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var ExecutionContext = (function () {
- function ExecutionContext(weightMap) {
- this.weightMap = weightMap;
- this.rootContext = { id: 0, frameName: '', iterationId: 0 };
- this.contexts = [this.rootContext];
- this.lastId = 0;
- this.generateCurrentContextIds();
- }
- ExecutionContext.prototype.newFrame = function (id, frameName) {
- return { id: id, frameName: frameName, iterationId: 0 };
- };
- Object.defineProperty(ExecutionContext.prototype, "currentContext", {
- get: function () {
- return this.contexts;
- },
- set: function (contexts) {
- if (this.contexts !== contexts) {
- this.contexts = contexts;
- this.generateCurrentContextIds();
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(ExecutionContext.prototype, "currentContextId", {
- get: function () {
- return this._currentContextIds[0];
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(ExecutionContext.prototype, "currentContextIds", {
- get: function () {
- return this._currentContextIds;
- },
- enumerable: true,
- configurable: true
- });
- ExecutionContext.prototype.generateCurrentContextIds = function () {
- var names = [];
- for (var i = 0; i < this.contexts.length - 1; i++) {
- var contexts = this.contexts.slice(0, this.contexts.length - i);
- names.push(this.contextIdforContexts(contexts));
- }
- names.push('');
- this._currentContextIds = names;
- };
- ExecutionContext.prototype.contextIdforContexts = function (contexts) {
- return contexts ?
- contexts
- .map(function (context) { return (context.id === 0 && context.iterationId === 0) ?
- '' :
- context.frameName + "-" + context.iterationId; })
- .join('/') :
- '';
- };
- ExecutionContext.prototype.enterFrame = function (frameId) {
- if (this.contexts) {
- this.lastId++;
- this.contexts = this.contexts.slice();
- this.contexts.push(this.newFrame(this.lastId, frameId));
- this._currentContextIds.unshift(this.contextIdforContexts(this.contexts));
- }
- };
- ExecutionContext.prototype.exitFrame = function () {
- if (this.contexts && this.contexts.length > 1) {
- this.contexts = this.contexts.slice();
- this.contexts.splice(-1);
- this.currentContextIds.shift();
- }
- else {
- throw new Error('Cannot exit frame, the context is empty');
- }
- };
- ExecutionContext.prototype.nextIteration = function () {
- if (this.contexts && this.contexts.length > 0) {
- this.contexts = this.contexts.slice();
- this.lastId++;
- var context = Object.assign({}, this.contexts[this.contexts.length - 1]);
- context.iterationId += 1;
- context.id = this.lastId;
- this.contexts.splice(-1, 1, context);
- this._currentContextIds.splice(0, 1, this.contextIdforContexts(this.contexts));
- }
- else {
- throw new Error('Cannot increase frame iteration, the context is empty');
- }
- };
- ExecutionContext.prototype.getWeight = function (name) {
- return this.weightMap[name];
- };
- return ExecutionContext;
- }());
- exports.ExecutionContext = ExecutionContext;
- },{}],14:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var Url = require("url");
- var compiled_api_1 = require("../data/compiled_api");
- var operation_mapper_1 = require("../operations/operation_mapper");
- var graph_executor_1 = require("./graph_executor");
- var FrozenModel = (function () {
- function FrozenModel(modelUrl, weightManifestUrl, requestOption) {
- this.modelUrl = modelUrl;
- this.weightManifestUrl = weightManifestUrl;
- this.requestOption = requestOption;
- this.version = 'n/a';
- this.pathPrefix = this.getPathPrefix();
- }
- Object.defineProperty(FrozenModel.prototype, "modelVersion", {
- get: function () {
- return this.version;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(FrozenModel.prototype, "inputNodes", {
- get: function () {
- return this.executor.inputNodes;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(FrozenModel.prototype, "outputNodes", {
- get: function () {
- return this.executor.outputNodes;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(FrozenModel.prototype, "inputs", {
- get: function () {
- return this.executor.inputs;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(FrozenModel.prototype, "outputs", {
- get: function () {
- return this.executor.outputs;
- },
- enumerable: true,
- configurable: true
- });
- FrozenModel.prototype.getPathPrefix = function () {
- var url = Url.parse(this.weightManifestUrl);
- var segments = url.pathname.split('/');
- segments.splice(-1);
- url.pathname = segments.join('/');
- return Url.format(url) + '/';
- };
- FrozenModel.prototype.loadRemoteProtoFile = function () {
- return __awaiter(this, void 0, void 0, function () {
- var response, _a, _b, _c, error_1;
- return __generator(this, function (_d) {
- switch (_d.label) {
- case 0:
- _d.trys.push([0, 3, , 4]);
- return [4, fetch(this.modelUrl, this.requestOption)];
- case 1:
- response = _d.sent();
- _b = (_a = compiled_api_1.tensorflow.GraphDef).decode;
- _c = Uint8Array.bind;
- return [4, response.arrayBuffer()];
- case 2: return [2, _b.apply(_a, [new (_c.apply(Uint8Array, [void 0, _d.sent()]))()])];
- case 3:
- error_1 = _d.sent();
- throw new Error(this.modelUrl + " not found. " + error_1);
- case 4: return [2];
- }
- });
- });
- };
- FrozenModel.prototype.loadWeightManifest = function () {
- return __awaiter(this, void 0, void 0, function () {
- var manifest, _a, error_2;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- _b.trys.push([0, 3, , 4]);
- return [4, fetch(this.weightManifestUrl, this.requestOption)];
- case 1:
- manifest = _b.sent();
- _a = this;
- return [4, manifest.clone().json()];
- case 2:
- _a.weightManifest = _b.sent();
- return [3, 4];
- case 3:
- error_2 = _b.sent();
- throw new Error(this.weightManifestUrl + " not found. " + error_2);
- case 4: return [2];
- }
- });
- });
- };
- FrozenModel.prototype.load = function () {
- return __awaiter(this, void 0, void 0, function () {
- var graphPromise, manifestPromise, graph, weightMap;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- graphPromise = this.loadRemoteProtoFile();
- manifestPromise = this.loadWeightManifest();
- return [4, Promise.all([graphPromise, manifestPromise])];
- case 1:
- graph = (_a.sent())[0];
- this.version = graph.versions.producer + "." + graph.versions.minConsumer;
- return [4, tfc.io.loadWeights(this.weightManifest, this.pathPrefix, undefined, this.requestOption)];
- case 2:
- weightMap = _a.sent();
- this.executor =
- new graph_executor_1.GraphExecutor(operation_mapper_1.OperationMapper.Instance.transformGraph(graph));
- this.executor.weightMap = this.convertTensorMapToTensorsMap(weightMap);
- return [2, true];
- }
- });
- });
- };
- FrozenModel.prototype.predict = function (inputs, config) {
- return this.execute(inputs, this.outputNodes);
- };
- FrozenModel.prototype.constructTensorMap = function (inputs) {
- var inputArray = inputs instanceof tfc.Tensor ? [inputs] : inputs;
- if (inputArray.length !== this.inputNodes.length) {
- throw new Error('Input tensor count mismatch,' +
- ("the frozen model has " + this.inputNodes.length + " placeholders, ") +
- ("while there are " + inputArray.length + " input tensors."));
- }
- return this.inputNodes.reduce(function (map, inputName, i) {
- map[inputName] = inputArray[i];
- return map;
- }, {});
- };
- FrozenModel.prototype.execute = function (inputs, outputs) {
- outputs = outputs || this.outputNodes;
- if (inputs instanceof tfc.Tensor || Array.isArray(inputs)) {
- inputs = this.constructTensorMap(inputs);
- }
- if (this.executor.isControlFlowModel) {
- throw new Error('The model contains control flow ops, ' +
- 'please use executeAsync method');
- }
- var result = this.executor.execute(this.convertTensorMapToTensorsMap(inputs), outputs);
- var keys = Object.keys(result);
- return (Array.isArray(outputs) && outputs.length > 1) ?
- outputs.map(function (node) { return result[node]; }) :
- result[keys[0]];
- };
- FrozenModel.prototype.executeAsync = function (inputs, outputs) {
- return __awaiter(this, void 0, void 0, function () {
- var result, keys;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.executor.isControlFlowModel) {
- throw new Error('The model does not contain control flow ops, ' +
- 'please use execute method for better performance.');
- }
- outputs = outputs || this.outputNodes;
- if (inputs instanceof tfc.Tensor || Array.isArray(inputs)) {
- inputs = this.constructTensorMap(inputs);
- }
- return [4, this.executor.executeAsync(this.convertTensorMapToTensorsMap(inputs), outputs)];
- case 1:
- result = _a.sent();
- keys = Object.keys(result);
- return [2, Array.isArray(outputs) && outputs.length > 1 ?
- outputs.map(function (node) { return result[node]; }) :
- result[keys[0]]];
- }
- });
- });
- };
- FrozenModel.prototype.convertTensorMapToTensorsMap = function (map) {
- return Object.keys(map).reduce(function (newMap, key) {
- newMap[key] = [map[key]];
- return newMap;
- }, {});
- };
- FrozenModel.prototype.dispose = function () {
- this.executor.dispose();
- };
- return FrozenModel;
- }());
- exports.FrozenModel = FrozenModel;
- function loadFrozenModel(modelUrl, weightsManifestUrl, requestOption) {
- return __awaiter(this, void 0, void 0, function () {
- var model;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- model = new FrozenModel(modelUrl, weightsManifestUrl, requestOption);
- return [4, model.load()];
- case 1:
- _a.sent();
- return [2, model];
- }
- });
- });
- }
- exports.loadFrozenModel = loadFrozenModel;
- },{"../data/compiled_api":12,"../operations/operation_mapper":45,"./graph_executor":15,"@tensorflow/tfjs-core":54,"url":239}],15:[function(require,module,exports){
- "use strict";
- var __assign = (this && this.__assign) || Object.assign || function(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
- t[p] = s[p];
- }
- return t;
- };
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var utils_1 = require("../operations/executors/utils");
- var operation_executor_1 = require("../operations/operation_executor");
- var execution_context_1 = require("./execution_context");
- var GraphExecutor = (function () {
- function GraphExecutor(graph) {
- this.graph = graph;
- this.compiledOrder = [];
- this._weightMap = {};
- this.placeholders = graph.placeholders;
- this._outputs = graph.outputs;
- this.compile();
- }
- Object.defineProperty(GraphExecutor.prototype, "weightMap", {
- get: function () {
- return this._weightMap;
- },
- set: function (weightMap) {
- var weightIds = Object.keys(weightMap).map(function (key) { return weightMap[key].map(function (tensor) { return tensor.id; }); });
- this.weightIds = [].concat.apply([], weightIds);
- this._weightMap = weightMap;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GraphExecutor.prototype, "inputs", {
- get: function () {
- return this.placeholders.map(function (node) {
- return {
- name: node.name,
- shape: node.params['shape'] ? node.params['shape'].value :
- undefined,
- dtype: node.params['dtype'] ? node.params['dtype'].value :
- undefined
- };
- });
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GraphExecutor.prototype, "outputs", {
- get: function () {
- return this._outputs.map(function (node) {
- return {
- name: node.name,
- shape: node.params['shape'] ? node.params['shape'].value :
- undefined,
- dtype: node.params['dtype'] ? node.params['dtype'].value :
- undefined
- };
- });
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GraphExecutor.prototype, "inputNodes", {
- get: function () {
- return this.placeholders.map(function (node) { return node.name; });
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GraphExecutor.prototype, "outputNodes", {
- get: function () {
- return this.outputs.map(function (node) { return node.name; });
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GraphExecutor.prototype, "isControlFlowModel", {
- get: function () {
- return this.graph.withControlFlow;
- },
- enumerable: true,
- configurable: true
- });
- GraphExecutor.prototype.compile = function () {
- if (this.graph.withControlFlow) {
- return;
- }
- var stack = this.graph.inputs.slice();
- var visited = {};
- while (stack.length > 0) {
- var node = stack.pop();
- visited[node.name] = true;
- this.compiledOrder.push(node);
- node.children.forEach(function (childNode) {
- if (!visited[childNode.name] && childNode.inputNames.every(function (name) {
- var nodeName = utils_1.getNodeNameAndIndex(name)[0];
- return visited[nodeName];
- })) {
- stack.push(childNode);
- }
- });
- }
- };
- GraphExecutor.prototype.execute = function (inputs, outputs) {
- var _this = this;
- this.checkInput(inputs);
- this.checkInputShapeAndType(inputs);
- var result = tfjs_core_1.tidy(function () {
- var context = new execution_context_1.ExecutionContext(_this._weightMap);
- var tensors = _this.compiledOrder.reduce(function (map, node) {
- map[node.name] = operation_executor_1.executeOp(node, map, context);
- return map;
- }, __assign({}, _this.weightMap, inputs));
- return _this.findOutputs(tensors, context, outputs);
- });
- return result;
- };
- GraphExecutor.prototype.executeAsync = function (inputs, outputs) {
- return __awaiter(this, void 0, void 0, function () {
- var _this = this;
- var context, tensors, results, outputIds, inputIdArray, inputIds;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- this.checkInput(inputs);
- this.checkInputShapeAndType(inputs);
- context = new execution_context_1.ExecutionContext(this._weightMap);
- return [4, this.executeWithControlFlow(inputs, context)];
- case 1:
- tensors = _a.sent();
- results = this.findOutputs(tensors, context, outputs);
- outputIds = Object.keys(results).map(function (key) { return results[key].id; });
- inputIdArray = Object.keys(inputs).map(function (key) { return inputs[key].map(function (input) { return input.id; }); });
- inputIds = [].concat.apply([], inputIdArray);
- Object.keys(tensors).forEach(function (key) {
- var tensorArray = tensors[key];
- tensorArray.forEach(function (tensor) {
- if (tensor && outputIds.indexOf(tensor.id) === -1 &&
- inputIds.indexOf(tensor.id) === -1 &&
- _this.weightIds.indexOf(tensor.id) === -1) {
- tensor.dispose();
- }
- });
- });
- return [2, results];
- }
- });
- });
- };
- GraphExecutor.prototype.executeWithControlFlow = function (inputs, context) {
- return __awaiter(this, void 0, void 0, function () {
- var stack, tensorMap, added, item, tensors, nodeName, _a, _b;
- return __generator(this, function (_c) {
- switch (_c.label) {
- case 0:
- stack = this.graph.inputs.map(function (node) {
- return { node: node, contexts: context.currentContext };
- });
- tensorMap = __assign({}, this.weightMap, inputs);
- added = {};
- _c.label = 1;
- case 1:
- if (!(stack.length > 0)) return [3, 3];
- item = stack.pop();
- context.currentContext = item.contexts;
- tensors = operation_executor_1.executeOp(item.node, tensorMap, context);
- nodeName = utils_1.getNodeNameAndIndex(item.node.name, context)[0];
- _a = tensorMap;
- _b = nodeName;
- return [4, tensors];
- case 2:
- _a[_b] = _c.sent();
- item.node.children.forEach(function (childNode) {
- var nodeName = utils_1.getNodeNameAndIndex(childNode.name, context)[0];
- if (!added[nodeName]) {
- if (childNode.op === 'merge') {
- if (childNode.inputNames.some(function (name) {
- return !!utils_1.getTensor(name, tensorMap, context);
- })) {
- added[nodeName] = true;
- stack.push({ contexts: context.currentContext, node: childNode });
- }
- }
- else if (childNode.inputNames.every(function (name) {
- return !!utils_1.getTensor(name, tensorMap, context);
- })) {
- added[nodeName] = true;
- stack.push({ contexts: context.currentContext, node: childNode });
- }
- }
- });
- return [3, 1];
- case 3: return [2, tensorMap];
- }
- });
- });
- };
- GraphExecutor.prototype.findOutputs = function (tensorMap, context, outputs) {
- if (outputs && !(outputs instanceof Array)) {
- outputs = [outputs];
- }
- var requestedOutputs = (outputs || this.graph.outputs.map(function (node) { return node.name; }));
- return requestedOutputs.reduce(function (map, name) {
- map[name] = utils_1.getTensor(name, tensorMap, context);
- return map;
- }, {});
- };
- GraphExecutor.prototype.dispose = function () {
- var _this = this;
- Object.keys(this.weightMap)
- .forEach(function (key) { return _this.weightMap[key].forEach(function (tensor) { return tensor.dispose(); }); });
- };
- GraphExecutor.prototype.checkInputShapeAndType = function (inputs) {
- this.placeholders.forEach(function (node) {
- var input = inputs[node.name][0];
- if (node.params['shape'] && node.params['shape'].value) {
- var shape_1 = node.params['shape'].value;
- var match = shape_1.length === input.shape.length &&
- input.shape.every(function (dim, index) { return shape_1[index] === -1 || shape_1[index] === dim; });
- tfjs_core_1.util.assert(match, "The shape of dict['" + node.name + "'] provided in model.execute(dict) must be [" + shape_1 + "], but was [" + input.shape + "]");
- }
- if (node.params['dtype'] && node.params['dtype'].value) {
- tfjs_core_1.util.assert(input.dtype === node.params['dtype'].value, "The dtype of dict['" + node.name + "'] provided in model.execute(dict) must be " + node.params['dtype'].value + ", but was " + input.dtype);
- }
- });
- };
- GraphExecutor.prototype.checkInput = function (inputs) {
- var _this = this;
- var inputKeys = Object.keys(inputs);
- var missing = [];
- var extra = [];
- this.inputNodes.forEach(function (name) {
- if (inputKeys.indexOf(name) === -1)
- missing.push(name);
- });
- inputKeys.forEach(function (name) {
- if (_this.inputNodes.indexOf(name) === -1)
- extra.push(name);
- });
- if (missing.length > 0) {
- throw new Error("The dict provided in model.execute(dict) has the keys " +
- ("[" + inputKeys + "], but is missing the required keys: [" + missing + "]."));
- }
- if (extra.length > 0) {
- throw new Error("The dict provided in model.execute(dict) has " +
- ("unused keys: [" + extra + "]. Please provide only the following keys: ") +
- ("[" + this.inputNodes + "]."));
- }
- };
- return GraphExecutor;
- }());
- exports.GraphExecutor = GraphExecutor;
- },{"../operations/executors/utils":30,"../operations/operation_executor":44,"./execution_context":13,"@tensorflow/tfjs-core":54}],16:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var frozen_model_1 = require("./executor/frozen_model");
- exports.FrozenModel = frozen_model_1.FrozenModel;
- exports.loadFrozenModel = frozen_model_1.loadFrozenModel;
- var version_1 = require("./version");
- exports.version_converter = version_1.version;
- },{"./executor/frozen_model":14,"./version":46}],17:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var utils_1 = require("./utils");
- exports.executeOp = function (node, tensorMap, context) {
- switch (node.op) {
- case 'add': {
- return [tfc.add(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'mod':
- return [tfc.mod(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- case 'mul':
- return [tfc.mul(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- case 'div': {
- return [tfc.div(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'floorDiv': {
- return [tfc.floorDiv(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'sub': {
- return [tfc.sub(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'minimum': {
- return [tfc.minimum(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'maximum': {
- return [tfc.maximum(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'pow': {
- return [tfc.pow(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'squaredDifference': {
- return [tfc.squaredDifference(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- default:
- throw TypeError("Node type " + node.op + " is not implemented");
- }
- };
- exports.CATEGORY = 'arithmetic';
- },{"./utils":30,"@tensorflow/tfjs-core":54}],18:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var utils_1 = require("./utils");
- exports.executeOp = function (node, tensorMap, context) {
- switch (node.op) {
- case 'abs':
- return [tfc.abs(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'acos':
- return [tfc.acos(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'acosh':
- return [tfc.acosh(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'asin':
- return [tfc.asin(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'asinh':
- return [tfc.asinh(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'atan':
- return [tfc.atan(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'atanh':
- return [tfc.atanh(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'ceil':
- return [tfc.ceil(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'cos':
- return [tfc.cos(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'cosh':
- return [tfc.cosh(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'elu':
- return [tfc.elu(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'erf':
- return [tfc.erf(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'exp':
- return [tfc.exp(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'expm1': {
- return [tfc.expm1(utils_1.getParamValue('x', node, tensorMap, context))];
- }
- case 'floor':
- return [tfc.floor(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'log':
- return [tfc.log(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'log1p': {
- return [tfc.log1p(utils_1.getParamValue('x', node, tensorMap, context))];
- }
- case 'neg':
- return [tfc.neg(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'reciprocal': {
- return [tfc.reciprocal(utils_1.getParamValue('x', node, tensorMap, context))];
- }
- case 'relu':
- return [tfc.relu(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'round': {
- return [tfc.round(utils_1.getParamValue('x', node, tensorMap, context))];
- }
- case 'selu':
- return [tfc.selu(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'sigmoid':
- return [tfc.sigmoid(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'sin':
- return [tfc.sin(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'sign': {
- return [tfc.sign(utils_1.getParamValue('x', node, tensorMap, context))];
- }
- case 'sinh': {
- return [tfc.sinh(utils_1.getParamValue('x', node, tensorMap, context))];
- }
- case 'softplus': {
- return [tfc.softplus(utils_1.getParamValue('x', node, tensorMap, context))];
- }
- case 'sqrt': {
- return [tfc.sqrt(utils_1.getParamValue('x', node, tensorMap, context))];
- }
- case 'square': {
- return [tfc.square(utils_1.getParamValue('x', node, tensorMap, context))];
- }
- case 'tanh': {
- return [tfc.tanh(utils_1.getParamValue('x', node, tensorMap, context))];
- }
- case 'tan':
- return [tfc.tan(utils_1.getParamValue('x', node, tensorMap, context))];
- case 'clipByValue':
- return [tfc.clipByValue(utils_1.getParamValue('x', node, tensorMap, context), utils_1.getParamValue('clipValueMin', node, tensorMap, context), utils_1.getParamValue('clipValueMax', node, tensorMap, context))];
- case 'rsqrt':
- return [tfc.div(tfc.scalar(1.0, 'float32'), tfc.sqrt(utils_1.getTensor(node.inputNames[0], tensorMap, context)))];
- default:
- throw TypeError("Node type " + node.op + " is not implemented");
- }
- };
- exports.CATEGORY = 'basic_math';
- },{"./utils":30,"@tensorflow/tfjs-core":54}],19:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var utils_1 = require("./utils");
- function executeOp(node, tensorMap, context) {
- return __awaiter(this, void 0, void 0, function () {
- var _a, pred, data_1, inputName, frameId, data, tensor, input;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- _a = node.op;
- switch (_a) {
- case 'loopCond': return [3, 1];
- case 'switch': return [3, 2];
- case 'merge': return [3, 4];
- case 'enter': return [3, 5];
- case 'exit': return [3, 6];
- case 'nextIteration': return [3, 7];
- }
- return [3, 8];
- case 1: return [2, [utils_1.getParamValue('pred', node, tensorMap, context)]];
- case 2:
- pred = utils_1.getParamValue('pred', node, tensorMap, context);
- data_1 = utils_1.getParamValue('data', node, tensorMap, context);
- return [4, pred.data()];
- case 3: return [2, (_b.sent())[0] ? [undefined, data_1] : [data_1, undefined]];
- case 4:
- inputName = node.inputNames.find(function (name) { return utils_1.getTensor(name, tensorMap, context) !== undefined; });
- return [2, inputName ? [utils_1.getTensor(inputName, tensorMap, context)] : undefined];
- case 5:
- frameId = utils_1.getParamValue('frameName', node, tensorMap, context);
- data = utils_1.getParamValue('tensor', node, tensorMap, context);
- context.enterFrame(frameId);
- return [2, [data]];
- case 6:
- tensor = utils_1.getParamValue('tensor', node, tensorMap, context);
- context.exitFrame();
- return [2, [tensor]];
- case 7:
- input = utils_1.getParamValue('tensor', node, tensorMap, context);
- context.nextIteration();
- return [2, [input]];
- case 8: throw TypeError("Node type " + node.op + " is not implemented");
- }
- });
- });
- }
- exports.executeOp = executeOp;
- exports.CATEGORY = 'control';
- },{"./utils":30}],20:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var utils_1 = require("./utils");
- exports.executeOp = function (node, tensorMap, context) {
- switch (node.op) {
- case 'conv1d': {
- var stride = utils_1.getParamValue('stride', node, tensorMap, context);
- var pad = utils_1.getParamValue('pad', node, tensorMap, context);
- var dataFormat = utils_1.getParamValue('dataFormat', node, tensorMap, context)
- .toUpperCase();
- var dilation = utils_1.getParamValue('dilation', node, tensorMap, context);
- return [tfc.conv1d(utils_1.getParamValue('x', node, tensorMap, context), utils_1.getParamValue('filter', node, tensorMap, context), stride, pad, dataFormat, dilation)];
- }
- case 'conv2d': {
- var stride = utils_1.getParamValue('strides', node, tensorMap, context);
- var pad = utils_1.getParamValue('pad', node, tensorMap, context);
- var dataFormat = utils_1.getParamValue('dataFormat', node, tensorMap, context)
- .toUpperCase();
- var dilations = utils_1.getParamValue('dilations', node, tensorMap, context);
- return [tfc.conv2d(utils_1.getParamValue('x', node, tensorMap, context), utils_1.getParamValue('filter', node, tensorMap, context), [stride[1], stride[2]], pad, dataFormat, [dilations[0], dilations[1]])];
- }
- case 'conv2dTranspose': {
- var shape = utils_1.getParamValue('outputShape', node, tensorMap, context);
- var stride = utils_1.getParamValue('strides', node, tensorMap, context);
- var pad = utils_1.getParamValue('pad', node, tensorMap, context);
- return [tfc.conv2dTranspose(utils_1.getParamValue('x', node, tensorMap, context), utils_1.getParamValue('filter', node, tensorMap, context), shape, [stride[1], stride[2]], pad)];
- }
- case 'depthwiseConv2d': {
- var stride = utils_1.getParamValue('strides', node, tensorMap, context);
- var pad = utils_1.getParamValue('pad', node, tensorMap, context);
- var dilations = utils_1.getParamValue('dilations', node, tensorMap, context);
- var dataFormat = utils_1.getParamValue('dataFormat', node, tensorMap, context)
- .toUpperCase();
- return [tfc.depthwiseConv2d(utils_1.getParamValue('input', node, tensorMap, context), utils_1.getParamValue('filter', node, tensorMap, context), [stride[1], stride[2]], pad, dataFormat, [dilations[0], dilations[1]])];
- }
- case 'avgPool': {
- var stride = utils_1.getParamValue('strides', node, tensorMap, context);
- var pad = utils_1.getParamValue('pad', node, tensorMap, context);
- var kernelSize = utils_1.getParamValue('kernelSize', node, tensorMap, context);
- return [tfc.avgPool(utils_1.getParamValue('x', node, tensorMap, context), [kernelSize[1], kernelSize[2]], [stride[1], stride[2]], pad)];
- }
- case 'maxPool': {
- var stride = utils_1.getParamValue('strides', node, tensorMap, context);
- var pad = utils_1.getParamValue('pad', node, tensorMap, context);
- var kernelSize = utils_1.getParamValue('kernelSize', node, tensorMap, context);
- return [tfc.maxPool(utils_1.getParamValue('x', node, tensorMap, context), [kernelSize[1], kernelSize[2]], [stride[1], stride[2]], pad)];
- }
- default:
- throw TypeError("Node type " + node.op + " is not implemented");
- }
- };
- exports.CATEGORY = 'convolution';
- },{"./utils":30,"@tensorflow/tfjs-core":54}],21:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var utils_1 = require("./utils");
- exports.executeOp = function (node, tensorMap, context) {
- switch (node.op) {
- case 'fill': {
- var shape = utils_1.getParamValue('shape', node, tensorMap, context);
- var value = utils_1.getParamValue('value', node, tensorMap, context);
- return [tfc.fill(shape, value)];
- }
- case 'linspace': {
- var start = utils_1.getParamValue('start', node, tensorMap, context);
- var stop_1 = utils_1.getParamValue('stop', node, tensorMap, context);
- var num = utils_1.getParamValue('num', node, tensorMap, context);
- return [tfc.linspace(start, stop_1, num)];
- }
- case 'oneHot': {
- var indices = utils_1.getParamValue('indices', node, tensorMap, context);
- var depth = utils_1.getParamValue('depth', node, tensorMap, context);
- var onValue = utils_1.getParamValue('onValue', node, tensorMap, context);
- var offValue = utils_1.getParamValue('offValue', node, tensorMap, context);
- return [tfc.oneHot(indices, depth, onValue, offValue)];
- }
- case 'ones': {
- return [tfc.ones(utils_1.getParamValue('shape', node, tensorMap, context), utils_1.getParamValue('dtype', node, tensorMap, context))];
- }
- case 'onesLike': {
- return [tfc.onesLike(utils_1.getParamValue('x', node, tensorMap, context))];
- }
- case 'randomUniform': {
- return [tfc.randomUniform(utils_1.getParamValue('shape', node, tensorMap, context), utils_1.getParamValue('minval', node, tensorMap, context), utils_1.getParamValue('maxval', node, tensorMap, context), utils_1.getParamValue('dtype', node, tensorMap, context))];
- }
- case 'range': {
- var start = utils_1.getParamValue('start', node, tensorMap, context);
- var stop_2 = utils_1.getParamValue('stop', node, tensorMap, context);
- var step = utils_1.getParamValue('step', node, tensorMap, context);
- return [tfc.range(start, stop_2, step, utils_1.getParamValue('dtype', node, tensorMap, context))];
- }
- case 'truncatedNormal': {
- var shape = utils_1.getParamValue('shape', node, tensorMap, context);
- var mean = utils_1.getParamValue('mean', node, tensorMap, context);
- var stdDev = utils_1.getParamValue('stdDev', node, tensorMap, context);
- var seed = utils_1.getParamValue('seed', node, tensorMap, context);
- return [tfc.truncatedNormal(shape, mean, stdDev, utils_1.getParamValue('dtype', node, tensorMap, context), seed)];
- }
- case 'zeros': {
- return [tfc.zeros(utils_1.getParamValue('shape', node, tensorMap, context), utils_1.getParamValue('dtype', node, tensorMap, context))];
- }
- case 'zerosLike': {
- return [tfc.zerosLike(utils_1.getParamValue('x', node, tensorMap, context))];
- }
- default:
- throw TypeError("Node type " + node.op + " is not implemented");
- }
- };
- exports.CATEGORY = 'creation';
- },{"./utils":30,"@tensorflow/tfjs-core":54}],22:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var utils_1 = require("./utils");
- exports.executeOp = function (node, tensorMap, context) {
- switch (node.op) {
- case 'const': {
- return tensorMap[node.name];
- }
- case 'placeholder':
- var def = utils_1.getParamValue('default', node, tensorMap, context);
- return [utils_1.getTensor(node.name, tensorMap, context) || def];
- case 'identity':
- case 'stopGradient':
- case 'fakeQuantWithMinMaxVars':
- return [utils_1.getParamValue('x', node, tensorMap, context)];
- case 'snapshot':
- var snapshot = utils_1.getParamValue('x', node, tensorMap, context);
- return [snapshot.clone()];
- case 'shape':
- return [tfc.tensor1d(utils_1.getParamValue('x', node, tensorMap, context).shape, 'int32')];
- case 'size':
- return [tfc.scalar(utils_1.getParamValue('x', node, tensorMap, context).size, 'int32')];
- case 'rank':
- return [tfc.scalar(utils_1.getParamValue('x', node, tensorMap, context).rank, 'int32')];
- case 'noop':
- return [];
- case 'print':
- var input = utils_1.getParamValue('x', node, tensorMap, context);
- var data = utils_1.getParamValue('data', node, tensorMap, context);
- var message = utils_1.getParamValue('message', node, tensorMap, context);
- var summarize = utils_1.getParamValue('summarize', node, tensorMap, context);
- console.warn('The graph has a tf.print() operation,' +
- 'usually used for debugging, which slows down performance.');
- console.log(message);
- for (var i = 0; i < data.length; i++) {
- console.log(Array.prototype.slice.call(data[0].dataSync()).slice(0, summarize));
- }
- return [input];
- default:
- throw TypeError("Node type " + node.op + " is not implemented");
- }
- };
- exports.CATEGORY = 'graph';
- },{"./utils":30,"@tensorflow/tfjs-core":54}],23:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var utils_1 = require("./utils");
- exports.executeOp = function (node, tensorMap, context) {
- switch (node.op) {
- case 'resizeBilinear': {
- var images = utils_1.getParamValue('images', node, tensorMap, context);
- var size = utils_1.getParamValue('size', node, tensorMap, context);
- var alignCorners = utils_1.getParamValue('alignCorners', node, tensorMap, context);
- return [tfc.image.resizeBilinear(images, [size[0], size[1]], alignCorners)];
- }
- case 'resizeNearestNeighbor': {
- var images = utils_1.getParamValue('images', node, tensorMap, context);
- var size = utils_1.getParamValue('size', node, tensorMap, context);
- var alignCorners = utils_1.getParamValue('alignCorners', node, tensorMap, context);
- return [tfc.image.resizeNearestNeighbor(images, [size[0], size[1]], alignCorners)];
- }
- default:
- throw TypeError("Node type " + node.op + " is not implemented");
- }
- };
- exports.CATEGORY = 'image';
- },{"./utils":30,"@tensorflow/tfjs-core":54}],24:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var utils_1 = require("./utils");
- exports.executeOp = function (node, tensorMap, context) {
- switch (node.op) {
- case 'equal': {
- return [tfc.equal(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'notEqual': {
- return [tfc.notEqual(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'greater': {
- return [tfc.greater(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'greaterEqual': {
- return [tfc.greaterEqual(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'less': {
- return [tfc.less(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'lessEqual': {
- return [tfc.lessEqual(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'logicalAnd': {
- return [tfc.logicalAnd(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'logicalNot': {
- return [tfc.logicalNot(utils_1.getParamValue('a', node, tensorMap, context))];
- }
- case 'logicalOr': {
- return [tfc.logicalOr(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- case 'where': {
- return [tfc.where(utils_1.getParamValue('condition', node, tensorMap, context), utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context))];
- }
- default:
- throw TypeError("Node type " + node.op + " is not implemented");
- }
- };
- exports.CATEGORY = 'logical';
- },{"./utils":30,"@tensorflow/tfjs-core":54}],25:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var utils_1 = require("./utils");
- exports.executeOp = function (node, tensorMap, context) {
- switch (node.op) {
- case 'matMul':
- return [tfc.matMul(utils_1.getParamValue('a', node, tensorMap, context), utils_1.getParamValue('b', node, tensorMap, context), utils_1.getParamValue('transposeA', node, tensorMap, context), utils_1.getParamValue('transposeB', node, tensorMap, context))];
- case 'transpose':
- return [tfc.transpose(utils_1.getParamValue('x', node, tensorMap, context), utils_1.getParamValue('perm', node, tensorMap, context))];
- default:
- throw TypeError("Node type " + node.op + " is not implemented");
- }
- };
- exports.CATEGORY = 'matrices';
- },{"./utils":30,"@tensorflow/tfjs-core":54}],26:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var utils_1 = require("./utils");
- exports.executeOp = function (node, tensorMap, context) {
- switch (node.op) {
- case 'batchNormalization': {
- return [tfc.batchNormalization(utils_1.getParamValue('x', node, tensorMap, context), utils_1.getParamValue('mean', node, tensorMap, context), utils_1.getParamValue('variance', node, tensorMap, context), utils_1.getParamValue('epsilon', node, tensorMap, context), utils_1.getParamValue('scale', node, tensorMap, context), utils_1.getParamValue('offset', node, tensorMap, context))];
- }
- case 'localResponseNormalization': {
- return [tfc.localResponseNormalization(utils_1.getParamValue('x', node, tensorMap, context), utils_1.getParamValue('radius', node, tensorMap, context), utils_1.getParamValue('bias', node, tensorMap, context), utils_1.getParamValue('alpha', node, tensorMap, context), utils_1.getParamValue('beta', node, tensorMap, context))];
- }
- case 'softmax': {
- return [tfc.softmax(utils_1.getParamValue('x', node, tensorMap, context))];
- }
- default:
- throw TypeError("Node type " + node.op + " is not implemented");
- }
- };
- exports.CATEGORY = 'normalization';
- },{"./utils":30,"@tensorflow/tfjs-core":54}],27:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var utils_1 = require("./utils");
- exports.executeOp = function (node, tensorMap, context) {
- switch (node.op) {
- case 'max': {
- var axis = utils_1.getParamValue('axis', node, tensorMap, context);
- var keepDims = utils_1.getParamValue('keepDims', node, tensorMap, context);
- return [tfc.max(utils_1.getParamValue('x', node, tensorMap, context), axis, keepDims)];
- }
- case 'mean': {
- var axis = utils_1.getParamValue('axis', node, tensorMap, context);
- var keepDims = utils_1.getParamValue('keepDims', node, tensorMap, context);
- return [tfc.mean(utils_1.getParamValue('x', node, tensorMap, context), axis, keepDims)];
- }
- case 'min': {
- var axis = utils_1.getParamValue('axis', node, tensorMap, context);
- var keepDims = utils_1.getParamValue('keepDims', node, tensorMap, context);
- return [tfc.min(utils_1.getParamValue('x', node, tensorMap, context), axis, keepDims)];
- }
- case 'sum': {
- var axis = utils_1.getParamValue('axis', node, tensorMap, context);
- var keepDims = utils_1.getParamValue('keepDims', node, tensorMap, context);
- return [tfc.sum(utils_1.getParamValue('x', node, tensorMap, context), axis, keepDims)];
- }
- case 'argMax': {
- var axis = utils_1.getParamValue('axis', node, tensorMap, context);
- return [tfc.argMax(utils_1.getParamValue('x', node, tensorMap, context), axis)];
- }
- case 'argMin': {
- var axis = utils_1.getParamValue('axis', node, tensorMap, context);
- return [tfc.argMin(utils_1.getParamValue('x', node, tensorMap, context), axis)];
- }
- default:
- throw TypeError("Node type " + node.op + " is not implemented");
- }
- };
- exports.CATEGORY = 'reduction';
- },{"./utils":30,"@tensorflow/tfjs-core":54}],28:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var utils_1 = require("./utils");
- exports.executeOp = function (node, tensorMap, context) {
- switch (node.op) {
- case 'concat': {
- var axis = utils_1.getParamValue('axis', node, tensorMap, context);
- var inputs = utils_1.getParamValue('tensors', node, tensorMap, context);
- return [tfc.concat(inputs, axis)];
- }
- case 'gather': {
- var axis = utils_1.getParamValue('axis', node, tensorMap, context);
- var input = utils_1.getParamValue('x', node, tensorMap, context);
- var indices = utils_1.getParamValue('indices', node, tensorMap, context);
- return [tfc.gather(input, indices, axis)];
- }
- case 'reverse': {
- var axis = utils_1.getParamValue('axis', node, tensorMap, context);
- var input = utils_1.getParamValue('x', node, tensorMap, context);
- return [tfc.reverse(input, axis)];
- }
- case 'slice': {
- var begin = utils_1.getParamValue('begin', node, tensorMap, context);
- var size = utils_1.getParamValue('size', node, tensorMap, context);
- return [tfc.slice(utils_1.getParamValue('x', node, tensorMap, context), begin, size)];
- }
- case 'stridedSlice': {
- var begin = utils_1.getParamValue('begin', node, tensorMap, context);
- var end = utils_1.getParamValue('end', node, tensorMap, context);
- var strides = utils_1.getParamValue('strides', node, tensorMap, context);
- var beginMask = utils_1.getParamValue('beginMask', node, tensorMap, context);
- var endMask = utils_1.getParamValue('endMask', node, tensorMap, context);
- return [tfc.stridedSlice(utils_1.getParamValue('x', node, tensorMap, context), begin, end, strides, beginMask, endMask)];
- }
- case 'stack': {
- return tfc.tidy(function () {
- var axis = utils_1.getParamValue('axis', node, tensorMap, context);
- var tensors = utils_1.getParamValue('tensors', node, tensorMap, context);
- var shape = tensors[0].shape;
- var squeezedShape = tensors[0].squeeze().shape;
- var mapped = tensors.map(function (tensor) {
- var sameShape = tfc.util.arraysEqual(tensor.shape, shape);
- if (!sameShape &&
- !tfc.util.arraysEqual(tensor.squeeze().shape, squeezedShape)) {
- throw new Error('the input tensors shape does not match');
- }
- return sameShape ? tensor : tensor.reshape(shape);
- });
- return [tfc.stack(mapped, axis)];
- });
- }
- case 'unstack': {
- return tfc.tidy(function () {
- var axis = utils_1.getParamValue('axis', node, tensorMap, context);
- var tensor = utils_1.getParamValue('tensor', node, tensorMap, context);
- return tfc.unstack(tensor, axis);
- });
- }
- case 'tile': {
- var reps = utils_1.getParamValue('reps', node, tensorMap, context);
- return [tfc.tile(utils_1.getParamValue('x', node, tensorMap, context), reps)];
- }
- case 'split': {
- var axis = utils_1.getParamValue('axis', node, tensorMap, context);
- var numOrSizeSplits = utils_1.getParamValue('numOrSizeSplits', node, tensorMap, context);
- return tfc.split(utils_1.getParamValue('x', node, tensorMap, context), numOrSizeSplits, axis);
- }
- default:
- throw TypeError("Node type " + node.op + " is not implemented");
- }
- };
- exports.CATEGORY = 'slice_join';
- },{"./utils":30,"@tensorflow/tfjs-core":54}],29:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var utils_1 = require("./utils");
- exports.executeOp = function (node, tensorMap, context) {
- switch (node.op) {
- case 'cast': {
- return [tfc.cast(utils_1.getParamValue('x', node, tensorMap, context), utils_1.getParamValue('dtype', node, tensorMap, context))];
- }
- case 'expandDims': {
- var axis = node.params['axis'].value;
- return [tfc.expandDims(utils_1.getParamValue('x', node, tensorMap, context), axis)];
- }
- case 'squeeze': {
- var axis = node.params['axis'].value;
- return [tfc.squeeze(utils_1.getParamValue('x', node, tensorMap, context), axis)];
- }
- case 'reshape': {
- return [tfc.reshape(utils_1.getParamValue('x', node, tensorMap, context), utils_1.getParamValue('shape', node, tensorMap, context))];
- }
- case 'pad': {
- return [tfc.pad(utils_1.getParamValue('x', node, tensorMap, context), utils_1.split(utils_1.getParamValue('padding', node, tensorMap, context), 2), utils_1.getParamValue('constantValue', node, tensorMap, context))];
- }
- default:
- throw TypeError("Node type " + node.op + " is not implemented");
- }
- };
- exports.CATEGORY = 'transformation';
- },{"./utils":30,"@tensorflow/tfjs-core":54}],30:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- function getParamValue(paramName, node, tensorMap, context) {
- var param = node.params[paramName];
- if (param && param.inputIndex !== undefined) {
- if (param.type === 'tensor') {
- return getTensor(node.inputNames[param.inputIndex], tensorMap, context);
- }
- if (param.type === 'tensors') {
- var inputs = param.inputIndex === 0 ?
- (param.inputParamLength === 0 ?
- node.inputNames :
- node.inputNames.slice(param.inputIndex, -param.inputParamLength)) :
- node.inputNames.splice(param.inputIndex);
- return inputs.map(function (name) { return getTensor(name, tensorMap, context); });
- }
- var data = Array.prototype.slice.call(getTensor(node.inputNames.slice(param.inputIndex)[0], tensorMap, context)
- .dataSync());
- return param.type === 'number' ? data[0] : data;
- }
- return param && param.value;
- }
- exports.getParamValue = getParamValue;
- function getTensor(name, tensorsMap, context) {
- var _a = parseNodeName(name), nodeName = _a[0], index = _a[1];
- var contextId = context.currentContextIds.find(function (contextId) {
- return !!tensorsMap[getNodeNameWithContextId(nodeName, contextId)];
- });
- return contextId !== undefined ?
- tensorsMap[getNodeNameWithContextId(nodeName, contextId)][index] :
- undefined;
- }
- exports.getTensor = getTensor;
- function getNodeNameAndIndex(inputName, context) {
- var _a = parseNodeName(inputName), nodeName = _a[0], index = _a[1];
- return [
- getNodeNameWithContextId(nodeName, context && context.currentContextId),
- index
- ];
- }
- exports.getNodeNameAndIndex = getNodeNameAndIndex;
- function getNodeNameWithContextId(name, contextId) {
- return !!contextId ? name + "-" + contextId : name;
- }
- function parseNodeName(name) {
- var index = name.lastIndexOf(':');
- if (index === -1)
- return [name, 0];
- var nodeName = name.substring(0, index);
- return [nodeName, Number(name.substring(index + 1))];
- }
- exports.parseNodeName = parseNodeName;
- function split(arr, size) {
- var res = [];
- for (var i = 0; i < arr.length; i += size) {
- res.push(arr.slice(i, i + size));
- }
- return res;
- }
- exports.split = split;
- },{}],31:[function(require,module,exports){
- module.exports=[
- {
- "tfOpName": "Add",
- "dlOpName": "add",
- "category": "arithmetic",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "BiasAdd",
- "dlOpName": "add",
- "category": "arithmetic",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Sub",
- "dlOpName": "sub",
- "category": "arithmetic",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "RealDiv",
- "dlOpName": "div",
- "category": "arithmetic",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Div",
- "dlOpName": "div",
- "category": "arithmetic",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "FloorDiv",
- "dlOpName": "floorDiv",
- "category": "arithmetic",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Mul",
- "dlOpName": "mul",
- "category": "arithmetic",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Maximum",
- "dlOpName": "maximum",
- "category": "arithmetic",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- }
- ]
- },
- {
- "tfOpName": "Minimum",
- "dlOpName": "minimum",
- "category": "arithmetic",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- }
- ]
- },
- {
- "tfOpName": "Pow",
- "dlOpName": "pow",
- "category": "arithmetic",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "SquaredDifference",
- "dlOpName": "squaredDifference",
- "category": "arithmetic",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Mod",
- "dlOpName": "mod",
- "category": "arithmetic",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- }
- ]
- },{}],32:[function(require,module,exports){
- module.exports=[
- {
- "tfOpName": "Abs",
- "dlOpName": "abs",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Acos",
- "dlOpName": "acos",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Asin",
- "dlOpName": "asin",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "atan",
- "dlOpName": "atan",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Ceil",
- "dlOpName": "ceil",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "ClipByValue",
- "dlOpName": "clipByValue",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "clip_value_min",
- "dlParamName": "clipValueMin",
- "type": "number"
- },
- {
- "tfParamName": "clip_value_max",
- "dlParamName": "clipValueMax",
- "type": "number"
- }
- ]
- },
- {
- "tfOpName": "Cos",
- "dlOpName": "cos",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Cosh",
- "dlOpName": "cosh",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Elu",
- "dlOpName": "elu",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Exp",
- "dlOpName": "exp",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Floor",
- "dlOpName": "floor",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Log",
- "dlOpName": "log",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Neg",
- "dlOpName": "neg",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Relu",
- "dlOpName": "relu",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Relu6",
- "dlOpName": "clipByValue",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- },
- {
- "dlParamName": "clipValueMin",
- "type": "number",
- "defaultValue": 0
- },
- {
- "dlParamName": "clipValueMax",
- "type": "number",
- "defaultValue": 6
- }
- ]
- },
- {
- "tfOpName": "Selu",
- "dlOpName": "selu",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Sigmoid",
- "dlOpName": "sigmoid",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Sin",
- "dlOpName": "sin",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Sinh",
- "dlOpName": "sinh",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Sqrt",
- "dlOpName": "sqrt",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Rsqrt",
- "dlOpName": "rsqrt",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Square",
- "dlOpName": "square",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Tan",
- "dlOpName": "tan",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Tanh",
- "dlOpName": "tanh",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Sign",
- "dlOpName": "sign",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Round",
- "dlOpName": "round",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Expm1",
- "dlOpName": "expm1",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Log1p",
- "dlOpName": "log1p",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Reciprocal",
- "dlOpName": "reciprocal",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Reciprocal",
- "dlOpName": "reciprocal",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Softplus",
- "dlOpName": "softplus",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Asinh",
- "dlOpName": "asinh",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Acosh",
- "dlOpName": "acosh",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Atanh",
- "dlOpName": "atanh",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Erf",
- "dlOpName": "erf",
- "category": "basic_math",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- }
- ]
- },{}],33:[function(require,module,exports){
- module.exports=[
- {
- "tfOpName": "LoopCond",
- "dlOpName": "loopCond",
- "category": "control",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "pred",
- "type": "tensor"
- }
- ]
- },
- {
- "tfOpName": "Switch",
- "dlOpName": "switch",
- "category": "control",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "data",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "pred",
- "type": "tensor"
- }
- ]
- },
- {
- "tfOpName": "Merge",
- "dlOpName": "merge",
- "category": "control",
- "params": [
- {
- "tfInputIndex": 0,
- "tfInputParamLength": 0,
- "dlParamName": "tensors",
- "type": "tensors"
- }
- ]
- },
- {
- "tfOpName": "Enter",
- "dlOpName": "enter",
- "category": "control",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "tensor",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- },
- {
- "tfParamName": "frame_name",
- "dlParamName": "frameName",
- "type": "string"
- },
- {
- "tfParamName": "is_constant",
- "dlParamName": "isConstant",
- "type": "bool"
- }
- ]
- },
- {
- "tfOpName": "Exit",
- "dlOpName": "exit",
- "category": "control",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "tensor",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "NextIteration",
- "dlOpName": "nextIteration",
- "category": "control",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "tensor",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- }
- ]
- },{}],34:[function(require,module,exports){
- module.exports=[
- {
- "tfOpName": "AvgPool",
- "dlOpName": "avgPool",
- "category": "convolution",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "strides",
- "dlParamName": "strides",
- "type": "number[]"
- },
- {
- "tfParamName": "padding",
- "dlParamName": "pad",
- "type": "string"
- },
- {
- "tfParamName": "data_format",
- "dlParamName": "dataFormat",
- "type": "string",
- "notSupported": true
- },
- {
- "tfParamName": "ksize",
- "dlParamName": "kernelSize",
- "type": "number[]"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "MaxPool",
- "dlOpName": "maxPool",
- "category": "convolution",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "strides",
- "dlParamName": "strides",
- "type": "number[]"
- },
- {
- "tfParamName": "padding",
- "dlParamName": "pad",
- "type": "string"
- },
- {
- "tfParamName": "data_format",
- "dlParamName": "dataFormat",
- "type": "string",
- "notSupported": true
- },
- {
- "tfParamName": "ksize",
- "dlParamName": "kernelSize",
- "type": "number[]"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Conv1D",
- "dlOpName": "conv1d",
- "category": "convolution",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "filter",
- "type": "tensor"
- },
- {
- "tfParamName": "stride",
- "dlParamName": "stride",
- "type": "number"
- },
- {
- "tfParamName": "padding",
- "dlParamName": "pad",
- "type": "string"
- },
- {
- "tfParamName": "data_format",
- "dlParamName": "dataFormat",
- "type": "string",
- "defaultValue": "NWC"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- },
- {
- "tfParamName": "dilation",
- "dlParamName": "dilation",
- "type": "number",
- "defaultValue": 1
- }
- ]
- },
- {
- "tfOpName": "Conv2D",
- "dlOpName": "conv2d",
- "category": "convolution",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "filter",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- },
- {
- "tfParamName": "strides",
- "dlParamName": "strides",
- "type": "number[]"
- },
- {
- "tfParamName": "padding",
- "dlParamName": "pad",
- "type": "string"
- },
- {
- "tfParamName": "useCudnnOnGpu",
- "dlParamName": "useCudnnOnGpu",
- "type": "bool"
- },
- {
- "tfParamName": "data_format",
- "dlParamName": "dataFormat",
- "type": "string",
- "defaultValue": "NHWC"
- },
- {
- "tfParamName": "dilations",
- "dlParamName": "dilations",
- "type": "number[]"
- }
- ]
- },
- {
- "tfOpName": "Conv2DBackpropInput",
- "dlOpName": "conv2dTranspose",
- "category": "convolution",
- "params": [
- {
- "tfInputIndex": 2,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "filter",
- "type": "tensor"
- },
- {
- "tfInputIndex": 0,
- "dlParamName": "outputShape",
- "type": "number[]"
- },
- {
- "tfParamName": "strides",
- "dlParamName": "strides",
- "type": "number[]"
- },
- {
- "tfParamName": "padding",
- "dlParamName": "pad",
- "type": "string"
- },
- {
- "tfParamName": "data_format",
- "dlParamName": "dataFormat",
- "type": "string",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "DepthwiseConv2d",
- "dlOpName": "depthwiseConv2d",
- "category": "convolution",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "input",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "filter",
- "type": "tensor"
- },
- {
- "tfParamName": "strides",
- "dlParamName": "strides",
- "type": "number[]"
- },
- {
- "tfParamName": "padding",
- "dlParamName": "pad",
- "type": "string"
- },
- {
- "tfParamName": "data_format",
- "dlParamName": "dataFormat",
- "type": "string",
- "defaultValue": "NHWC"
- },
- {
- "tfParamName": "dilations",
- "dlParamName": "dilations",
- "type": "number[]"
- }
- ]
- },
- {
- "tfOpName": "DepthwiseConv2dNative",
- "dlOpName": "depthwiseConv2d",
- "category": "convolution",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "input",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "filter",
- "type": "tensor"
- },
- {
- "tfParamName": "strides",
- "dlParamName": "strides",
- "type": "number[]"
- },
- {
- "tfParamName": "padding",
- "dlParamName": "pad",
- "type": "string"
- },
- {
- "tfParamName": "data_format",
- "dlParamName": "dataFormat",
- "type": "string",
- "defaultValue": "NHWC"
- },
- {
- "tfParamName": "dilations",
- "dlParamName": "dilations",
- "type": "number[]"
- }
- ]
- }
- ]
- },{}],35:[function(require,module,exports){
- module.exports=[
- {
- "tfOpName": "Fill",
- "dlOpName": "fill",
- "category": "creation",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "shape",
- "type": "number[]"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "value",
- "type": "number"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "LinSpace",
- "dlOpName": "linspace",
- "category": "creation",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "start",
- "type": "number"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "stop",
- "type": "number"
- },
- {
- "tfInputIndex": 2,
- "dlParamName": "num",
- "type": "number"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "OneHot",
- "dlOpName": "oneHot",
- "category": "creation",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "indices",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "depth",
- "type": "number"
- },
- {
- "tfInputIndex": 2,
- "dlParamName": "onValue",
- "type": "number",
- "defaultValue": 1
- },
- {
- "tfInputIndex": 3,
- "dlParamName": "offValue",
- "type": "number",
- "defaultValue": 0
- },
- {
- "tfParamName": "axis",
- "dlParamName": "axis",
- "type": "number",
- "notSupported": true
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Ones",
- "dlOpName": "ones",
- "category": "creation",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "shape",
- "type": "number[]"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype"
- }
- ]
- },
- {
- "tfOpName": "OnesLike",
- "dlOpName": "onesLike",
- "category": "creation",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "dtype",
- "dlParamName": "dtype",
- "type": "dtype"
- }
- ]
- },
- {
- "tfOpName": "RandomUniform",
- "dlOpName": "randomUniform",
- "category": "creation",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "shape",
- "type": "number[]"
- },
- {
- "tfParamName": "minval",
- "dlParamName": "minval",
- "type": "number",
- "defaultValue": 0
- },
- {
- "tfParamName": "maxval",
- "dlParamName": "maxval",
- "type": "number",
- "defaultValue": 1
- },
- {
- "tfParamName": "dtype",
- "dlParamName": "dtype",
- "type": "dtype"
- },
- {
- "tfParamName": "seed",
- "dlParamName": "seed",
- "type": "number",
- "defaultValue": 0
- },
- {
- "tfParamName": "seed2",
- "dlParamName": "seed2",
- "type": "number",
- "defaultValue": 0,
- "notSupported": true
- },
- {
- "tfParamName": "T",
- "dlParamName": "T",
- "type": "number",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Range",
- "dlOpName": "range",
- "category": "creation",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "start",
- "type": "number"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "stop",
- "type": "number"
- },
- {
- "tfInputIndex": 2,
- "dlParamName": "step",
- "type": "number",
- "defaultValue": 0
- },
- {
- "tfParamName": "Tidx",
- "dlParamName": "dtype",
- "type": "dtype"
- }
- ]
- },
- {
- "tfOpName": "truncatedNormal",
- "dlOpName": "truncatedNormal",
- "category": "creation",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "shape",
- "type": "number[]"
- },
- {
- "tfParamName": "means",
- "dlParamName": "mean",
- "type": "number",
- "defaultValue": 0.0
- },
- {
- "tfParamName": "stddev",
- "dlParamName": "stdDev",
- "type": "number",
- "defaultValue": 1.0
- },
- {
- "tfParamName": "seed",
- "dlParamName": "seed",
- "type": "number"
- },
- {
- "tfParamName": "seed2",
- "dlParamName": "seed2",
- "type": "number",
- "defaultValue": 0,
- "notSupported": true
- },
- {
- "tfParamName": "dtype",
- "dlParamName": "dtype",
- "type": "dtype"
- },
- {
- "tfParamName": "T",
- "dlParamName": "T",
- "type": "number",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Zeros",
- "dlOpName": "zeros",
- "category": "creation",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "shape",
- "type": "number[]"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype"
- }
- ]
- },
- {
- "tfOpName": "ZerosLike",
- "dlOpName": "zerosLike",
- "category": "creation",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype"
- }
- ]
- }
- ]
- },{}],36:[function(require,module,exports){
- module.exports=[
- {
- "tfOpName": "PlaceholderWithDefault",
- "dlOpName": "placeholder",
- "category": "graph",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "default",
- "type": "tensor"
- },
- {
- "tfParamName": "shape",
- "dlParamName": "shape",
- "type": "shape"
- },
- {
- "tfParamName": "dtype",
- "dlParamName": "dtype",
- "type": "dtype"
- }
- ]
- },
- {
- "tfOpName": "Placeholder",
- "dlOpName": "placeholder",
- "category": "graph",
- "params": [
- {
- "tfParamName": "shape",
- "dlParamName": "shape",
- "type": "shape"
- },
- {
- "tfParamName": "dtype",
- "dlParamName": "dtype",
- "type": "dtype"
- }
- ]
- },
- {
- "tfOpName": "Const",
- "dlOpName": "const",
- "category": "graph"
- },
- {
- "tfOpName": "Identity",
- "dlOpName": "identity",
- "category": "graph",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- }
- ]
- },
- {
- "tfOpName": "Snapshot",
- "dlOpName": "snapshot",
- "category": "graph",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- }
- ]
- },
- {
- "tfOpName": "Rank",
- "dlOpName": "rank",
- "category": "graph",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- }
- ]
- },
- {
- "tfOpName": "Size",
- "dlOpName": "size",
- "category": "graph",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- }
- ]
- },
- {
- "tfOpName": "Shape",
- "dlOpName": "shape",
- "category": "graph",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- }
- ]
- },
- {
- "tfOpName": "Print",
- "dlOpName": "print",
- "category": "graph",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "tfInputParamLength": 1,
- "dlParamName": "data",
- "type": "tensors"
- },
- {
- "tfParamName": "message",
- "dlParamName": "message",
- "type": "string"
- },
- {
- "tfParamName": "first_n",
- "dlParamName": "firstN",
- "type": "number",
- "notSupprted": true
- },
- {
- "tfParamName": "summarize",
- "dlParamName": "summarize",
- "type": "number",
- "defaultValue": 3
- }
- ]
- },
- {
- "tfOpName": "NoOp",
- "dlOpName": "noop",
- "category": "graph",
- "params": []
- },
- {
- "tfOpName": "StopGradient",
- "dlOpName": "stopGradient",
- "category": "graph",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- }
- ]
- },
- {
- "tfOpName": "FakeQuantWithMinMaxVars",
- "dlOpName": "fakeQuantWithMinMaxVars",
- "category": "graph",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "min",
- "dlParamName": "min",
- "type": "number"
- },
- {
- "tfParamName": "max",
- "dlParamName": "max",
- "type": "number"
- }
- ]
- }
- ]
- },{}],37:[function(require,module,exports){
- module.exports=[
- {
- "tfOpName": "ResizeBilinear",
- "dlOpName": "resizeBilinear",
- "category": "image",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "images",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "size",
- "type": "number[]"
- },
- {
- "tfParamName": "align_corners",
- "dlParamName": "alignCorners",
- "type": "bool"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "ResizeNearestNeighbor",
- "dlOpName": "resizeNearestNeighbor",
- "category": "image",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "images",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "size",
- "type": "number[]"
- },
- {
- "tfParamName": "align_corners",
- "dlParamName": "alignCorners",
- "type": "bool"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- }
- ]
- },{}],38:[function(require,module,exports){
- module.exports=[
- {
- "tfOpName": "Equal",
- "dlOpName": "equal",
- "category": "logical",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "NotEqual",
- "dlOpName": "notEqual",
- "category": "logical",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Greater",
- "dlOpName": "greater",
- "category": "logical",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "GreaterEqual",
- "dlOpName": "greaterEqual",
- "category": "logical",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Less",
- "dlOpName": "less",
- "category": "logical",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "LessEqual",
- "dlOpName": "lessEqual",
- "category": "logical",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "LogicalAnd",
- "dlOpName": "logicalAnd",
- "category": "logical",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "LogicalNot",
- "dlOpName": "logicalNot",
- "category": "logical",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "LogicalOr",
- "dlOpName": "logicalOr",
- "category": "logical",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Select",
- "dlOpName": "where",
- "category": "logical",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "condition",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 2,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- }
- ]
- },{}],39:[function(require,module,exports){
- module.exports=[
- {
- "tfOpName": "MatMul",
- "dlOpName": "matMul",
- "category": "matrices",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "a",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "b",
- "type": "tensor"
- },
- {
- "tfParamName": "transpose_a",
- "dlParamName": "transposeA",
- "type": "bool",
- "defaultValue": false
- },
- {
- "tfParamName": "transpose_b",
- "dlParamName": "transposeB",
- "type": "bool",
- "defaultValue": false
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Transpose",
- "dlOpName": "transpose",
- "category": "matrices",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "perm",
- "dlParamName": "perm",
- "type": "number[]"
- },
- {
- "tfParamName": "T",
- "dlParamName": "dtype",
- "type": "dtype",
- "notSupported": true
- }
- ]
- }
- ]
- },{}],40:[function(require,module,exports){
- module.exports=[
- {
- "tfOpName": "FusedBatchNorm",
- "dlOpName": "batchNormalization",
- "category": "normalization",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "scale",
- "type": "tensor"
- },
- {
- "tfInputIndex": 2,
- "dlParamName": "offset",
- "type": "tensor"
- },
- {
- "tfInputIndex": 3,
- "dlParamName": "mean",
- "type": "tensor"
- },
- {
- "tfInputIndex": 4,
- "dlParamName": "variance",
- "type": "tensor"
- },
- {
- "tfParamName": "epsilon",
- "dlParamName": "epsilon",
- "type": "number",
- "defaultValue": 0.001
- },
- {
- "tfParamName": "data_format",
- "dlParamName": "dataFormat",
- "type": "string",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "FusedBatchNormV2",
- "dlOpName": "batchNormalization",
- "category": "normalization",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "scale",
- "type": "tensor"
- },
- {
- "tfInputIndex": 2,
- "dlParamName": "offset",
- "type": "tensor"
- },
- {
- "tfInputIndex": 3,
- "dlParamName": "mean",
- "type": "tensor"
- },
- {
- "tfInputIndex": 4,
- "dlParamName": "variance",
- "type": "tensor"
- },
- {
- "tfParamName": "epsilon",
- "dlParamName": "epsilon",
- "type": "number",
- "defaultValue": 0.001
- },
- {
- "tfParamName": "data_format",
- "dlParamName": "dataFormat",
- "type": "string",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "LRN",
- "dlOpName": "localResponseNormalization",
- "category": "normalization",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "depth_radius",
- "dlParamName": "radius",
- "type": "number",
- "defaultValue": 5
- },
- {
- "tfParamName": "bias",
- "dlParamName": "bias",
- "type": "number",
- "defaultValue": 1.0
- },
- {
- "tfParamName": "alpha",
- "dlParamName": "alpha",
- "type": "number",
- "defaultValue": 1.0
- },
- {
- "tfParamName": "beta",
- "dlParamName": "beta",
- "type": "number",
- "defaultValue": 0.5
- }
- ]
- }, {
- "tfOpName": "Softmax",
- "dlOpName": "softmax",
- "category": "normalization",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- }
- ]
- }
- ]
- },{}],41:[function(require,module,exports){
- module.exports=[
- {
- "tfOpName": "Max",
- "dlOpName": "max",
- "category": "reduction",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "axis",
- "type": "number[]"
- },
- {
- "tfParamName": "keep_dims",
- "dlParamName": "keepDims",
- "type": "bool"
- }
- ]
- },
- {
- "tfOpName": "Mean",
- "dlOpName": "mean",
- "category": "reduction",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "axis",
- "type": "number[]"
- },
- {
- "tfParamName": "keep_dims",
- "dlParamName": "keepDims",
- "type": "bool"
- }
- ]
- },
- {
- "tfOpName": "Min",
- "dlOpName": "min",
- "category": "reduction",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "axis",
- "type": "number[]"
- },
- {
- "tfParamName": "keep_dims",
- "dlParamName": "keepDims",
- "type": "bool"
- }
- ]
- },
- {
- "tfOpName": "Sum",
- "dlOpName": "sum",
- "category": "reduction",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "axis",
- "type": "number[]"
- },
- {
- "tfParamName": "keep_dims",
- "dlParamName": "keepDims",
- "type": "bool"
- }
- ]
- },
- {
- "tfOpName": "ArgMax",
- "dlOpName": "argMax",
- "category": "reduction",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "axis",
- "type": "number"
- }
- ]
- },
- {
- "tfOpName": "ArgMin",
- "dlOpName": "argMin",
- "category": "reduction",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "axis",
- "type": "number"
- }
- ]
- }
- ]
- },{}],42:[function(require,module,exports){
- module.exports=[
- {
- "tfOpName": "ConcatV2",
- "dlOpName": "concat",
- "category": "slice_join",
- "params": [
- {
- "tfInputIndex": 0,
- "tfInputParamLength": 1,
- "dlParamName": "tensors",
- "type": "tensors"
- },
- {
- "tfInputIndex": -1,
- "dlParamName": "axis",
- "type": "number"
- }
- ]
- },
- {
- "tfOpName": "Concat",
- "dlOpName": "concat",
- "category": "slice_join",
- "params": [
- {
- "tfInputIndex": 1,
- "tfInputParamLength": 1,
- "dlParamName": "tensors",
- "type": "tensors"
- },
- {
- "tfInputIndex": 0,
- "dlParamName": "axis",
- "type": "number"
- }
- ]
- },
- {
- "tfOpName": "GatherV2",
- "dlOpName": "gather",
- "category": "slice_join",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "indices",
- "type": "tensor"
- },
- {
- "tfParamName": "axis",
- "dlParamName": "axis",
- "type": "number",
- "defaultValue": 0
- }
- ]
- },
- {
- "tfOpName": "Gather",
- "dlOpName": "gather",
- "category": "slice_join",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "indices",
- "type": "tensor"
- },
- {
- "tfParamName": "axis",
- "dlParamName": "axis",
- "type": "number",
- "defaultValue": 0
- },
- {
- "tfParamName": "validate_indices",
- "dlParamName": "validateIndices",
- "type": "bool",
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Reverse",
- "dlOpName": "reverse",
- "category": "slice_join",
- "params": [{
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "axis",
- "type": "number"
- }
- ]
- },
- {
- "tfOpName": "ReverseV2",
- "dlOpName": "reverse",
- "category": "slice_join",
- "params": [{
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "axis",
- "type": "number"
- }
- ]
- },
- {
- "tfOpName": "Slice",
- "dlOpName": "slice",
- "category": "slice_join",
- "params": [{
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "begin",
- "type": "number[]"
- },
- {
- "tfInputIndex": 2,
- "dlParamName": "size",
- "type": "number[]"
- }
- ]
- },
- {
- "tfOpName": "StridedSlice",
- "dlOpName": "stridedSlice",
- "category": "slice_join",
- "params": [{
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "begin",
- "type": "number[]"
- },
- {
- "tfInputIndex": 2,
- "dlParamName": "end",
- "type": "number[]"
- },
- {
- "tfInputIndex": 3,
- "dlParamName": "strides",
- "type": "number[]"
- },
- {
- "tfParamName": "begin_mask",
- "dlParamName": "beginMask",
- "type": "number",
- "defaultValue": 0
- },
- {
- "tfParamName": "end_mask",
- "dlParamName": "endMask",
- "type": "number",
- "defaultValue": 0
- }
- ]
- },
- {
- "tfOpName": "Pack",
- "dlOpName": "stack",
- "category": "slice_join",
- "params": [{
- "tfInputIndex": 0,
- "tfInputParamLength": 0,
- "dlParamName": "tensors",
- "type": "tensors"
- },
- {
- "tfParamName": "axis",
- "dlParamName": "axis",
- "type": "number",
- "defaultValue": 0
- }
- ]
- },
- {
- "tfOpName": "Unpack",
- "dlOpName": "unstack",
- "category": "slice_join",
- "params": [{
- "tfInputIndex": 0,
- "tfInputParamLength": 0,
- "dlParamName": "tensor",
- "type": "tensor"
- },
- {
- "tfParamName": "axis",
- "dlParamName": "axis",
- "type": "number",
- "defaultValue": 0
- },
- {
- "tfParamName": "num",
- "dlParamName": "num",
- "type": "number",
- "defaultValue": 0,
- "notSupported": true
- }
- ]
- },
- {
- "tfOpName": "Tile",
- "dlOpName": "tile",
- "category": "slice_join",
- "params": [{
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "reps",
- "type": "number[]"
- }
- ]
- },
- {
- "tfOpName": "Split",
- "dlOpName": "split",
- "category": "slice_join",
- "params": [{
- "tfInputIndex": 0,
- "dlParamName": "axis",
- "type": "number",
- "defaultValue": 0
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "num_split",
- "dlParamName": "numOrSizeSplits",
- "type": "number",
- "defaultValue": 1
- }
- ]
- }
- ]
- },{}],43:[function(require,module,exports){
- module.exports=[
- {
- "tfOpName": "Cast",
- "dlOpName": "cast",
- "category": "transformation",
- "params": [
- {
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "SrcT",
- "dlParamName": "sdtype",
- "type": "dtype",
- "notSupported": true
- },
- {
- "tfParamName": "DstT",
- "dlParamName": "dtype",
- "type": "dtype"
- }
- ]
- },
- {
- "tfOpName": "ExpandDims",
- "dlOpName": "expandDims",
- "category": "transformation",
- "params": [{
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "tfParamNameDeprecated": "dim",
- "dlParamName": "axis",
- "type": "number"
- }
- ]
- },
- {
- "tfOpName": "Pad",
- "dlOpName": "pad",
- "category": "transformation",
- "params": [{
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "padding",
- "type": "number[]"
- },
- {
- "tfParamName": "constant_value",
- "dlParamName": "constantValue",
- "type": "number",
- "defaultValue": 0
- }
- ]
- },
- {
- "tfOpName": "PadV2",
- "dlOpName": "pad",
- "category": "transformation",
- "params": [{
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "padding",
- "type": "number[]"
- },
- {
- "tfInputIndex": 2,
- "dlParamName": "constantValue",
- "type": "number",
- "defaultValue": 0
- }
- ]
- },
- {
- "tfOpName": "Reshape",
- "dlOpName": "reshape",
- "category": "transformation",
- "params": [{
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfInputIndex": 1,
- "dlParamName": "shape",
- "type": "number[]"
- }
- ]
- },
- {
- "tfOpName": "Squeeze",
- "dlOpName": "squeeze",
- "category": "transformation",
- "params": [{
- "tfInputIndex": 0,
- "dlParamName": "x",
- "type": "tensor"
- },
- {
- "tfParamName": "axis",
- "tfParamNameDeprecated": "squeeze_dims",
- "dlParamName": "axis",
- "type": "number[]"
- }
- ]
- }
- ]
- },{}],44:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var arithmetic = require("./executors/arithmetic_executor");
- var basicMath = require("./executors/basic_math_executor");
- var control = require("./executors/control_executor");
- var convolution = require("./executors/convolution_executor");
- var creation = require("./executors/creation_executor");
- var graph = require("./executors/graph_executor");
- var image = require("./executors/image_executor");
- var logical = require("./executors/logical_executor");
- var matrices = require("./executors/matrices_executor");
- var normalization = require("./executors/normalization_executor");
- var reduction = require("./executors/reduction_executor");
- var sliceJoin = require("./executors/slice_join_executor");
- var transformation = require("./executors/transformation_executor");
- function executeOp(node, tensorMap, context) {
- switch (node.category) {
- case 'arithmetic':
- return arithmetic.executeOp(node, tensorMap, context);
- case 'basic_math':
- return basicMath.executeOp(node, tensorMap, context);
- case 'control':
- return control.executeOp(node, tensorMap, context);
- case 'convolution':
- return convolution.executeOp(node, tensorMap, context);
- case 'creation':
- return creation.executeOp(node, tensorMap, context);
- case 'image':
- return image.executeOp(node, tensorMap, context);
- case 'graph':
- return graph.executeOp(node, tensorMap, context);
- case 'logical':
- return logical.executeOp(node, tensorMap, context);
- case 'matrices':
- return matrices.executeOp(node, tensorMap, context);
- case 'normalization':
- return normalization.executeOp(node, tensorMap, context);
- case 'reduction':
- return reduction.executeOp(node, tensorMap, context);
- case 'slice_join':
- return sliceJoin.executeOp(node, tensorMap, context);
- case 'transformation':
- return transformation.executeOp(node, tensorMap, context);
- default:
- throw TypeError("Node type " + node.op + " is not implemented");
- }
- }
- exports.executeOp = executeOp;
- },{"./executors/arithmetic_executor":17,"./executors/basic_math_executor":18,"./executors/control_executor":19,"./executors/convolution_executor":20,"./executors/creation_executor":21,"./executors/graph_executor":22,"./executors/image_executor":23,"./executors/logical_executor":24,"./executors/matrices_executor":25,"./executors/normalization_executor":26,"./executors/reduction_executor":27,"./executors/slice_join_executor":28,"./executors/transformation_executor":29}],45:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var compiled_api_1 = require("../data/compiled_api");
- var utils_1 = require("./executors/utils");
- var arithmetic = require("./op_list/arithmetic.json");
- var basicMath = require("./op_list/basic_math.json");
- var control = require("./op_list/control.json");
- var convolution = require("./op_list/convolution.json");
- var creation = require("./op_list/creation.json");
- var graph = require("./op_list/graph.json");
- var image = require("./op_list/image.json");
- var logical = require("./op_list/logical.json");
- var matrices = require("./op_list/matrices.json");
- var normalization = require("./op_list/normalization.json");
- var reduction = require("./op_list/reduction.json");
- var sliceJoin = require("./op_list/slice_join.json");
- var transformation = require("./op_list/transformation.json");
- var CONTROL_FLOW_OPS = ['Switch', 'Merge', 'Enter', 'Exit', 'NextIteration'];
- var OperationMapper = (function () {
- function OperationMapper() {
- var ops = [
- arithmetic, basicMath, control, convolution, creation, logical, image,
- graph, matrices, normalization, reduction, sliceJoin, transformation
- ];
- var mappersJson = [].concat.apply([], ops.map(function (op) { return op.default ? op.default : op; }));
- this.opMappers = mappersJson.reduce(function (map, mapper) {
- map[mapper.tfOpName] = mapper;
- return map;
- }, {});
- }
- Object.defineProperty(OperationMapper, "Instance", {
- get: function () {
- return this._instance || (this._instance = new this());
- },
- enumerable: true,
- configurable: true
- });
- OperationMapper.prototype.isControlFlow = function (node) {
- return CONTROL_FLOW_OPS.some(function (op) { return op === node.op; });
- };
- OperationMapper.prototype.transformGraph = function (graph) {
- var _this = this;
- var tfNodes = graph.node;
- var withControlFlow = false;
- var placeholders = [];
- var nodes = tfNodes.reduce(function (map, node) {
- map[node.name] = _this.mapNode(node);
- if (_this.isControlFlow(node))
- withControlFlow = true;
- if (node.op === 'Placeholder')
- placeholders.push(map[node.name]);
- return map;
- }, {});
- var inputs = [];
- var outputs = [];
- Object.keys(nodes).forEach(function (key) {
- var node = nodes[key];
- node.inputNames.forEach(function (name) {
- var nodeName = utils_1.getNodeNameAndIndex(name)[0];
- node.inputs.push(nodes[nodeName]);
- nodes[nodeName].children.push(node);
- });
- if (node.inputs.length === 0)
- inputs.push(node);
- });
- Object.keys(nodes).forEach(function (key) {
- var node = nodes[key];
- if (node.children.length === 0)
- outputs.push(node);
- });
- return { nodes: nodes, inputs: inputs, outputs: outputs, placeholders: placeholders, withControlFlow: withControlFlow };
- };
- OperationMapper.prototype.mapNode = function (node) {
- var _this = this;
- var mapper = this.opMappers[node.op];
- if (mapper === undefined) {
- throw new Error('Tensorflow Op is not supported: ' + node.op);
- }
- var newNode = {
- name: node.name,
- op: mapper.dlOpName,
- category: mapper.category,
- inputNames: (node.input ||
- []).map(function (input) { return input.startsWith('^') ? input.substr(1) : input; }),
- inputs: [],
- children: [],
- params: {}
- };
- if (!!mapper.params) {
- newNode.params = mapper.params.reduce(function (map, param) {
- var inputIndex = param.tfInputIndex;
- var inputParamLength = param.tfInputParamLength;
- var type = param.type;
- var value = undefined;
- if (inputIndex === undefined) {
- switch (param.type) {
- case 'string':
- value = _this.getStringParam(node.attr, param.tfParamName, param.defaultValue);
- if (value === undefined && !!param.tfParamNameDeprecated) {
- value = _this.getStringParam(node.attr, param.tfParamNameDeprecated, param.defaultValue);
- }
- break;
- case 'number':
- value = _this.getNumberParam(node.attr, param.tfParamName, param.defaultValue);
- if (value === undefined && !!param.tfParamNameDeprecated) {
- value = _this.getNumberParam(node.attr, param.tfParamNameDeprecated, param.defaultValue);
- }
- break;
- case 'number[]':
- value = _this.getNumericArrayParam(node.attr, param.tfParamName, param.defaultValue);
- if (value === undefined && !!param.tfParamNameDeprecated) {
- value = _this.getNumericArrayParam(node.attr, param.tfParamNameDeprecated, param.defaultValue);
- }
- break;
- case 'bool':
- value = _this.getBoolParam(node.attr, param.tfParamName, param.defaultValue);
- if (value === undefined && !!param.tfParamNameDeprecated) {
- value = _this.getBoolParam(node.attr, param.tfParamNameDeprecated, param.defaultValue);
- }
- break;
- case 'shape':
- value = _this.getTensorShapeParam(node.attr, param.tfParamName, param.defaultValue);
- if (value === undefined && !!param.tfParamNameDeprecated) {
- value = _this.getTensorShapeParam(node.attr, param.tfParamNameDeprecated, param.defaultValue);
- }
- break;
- case 'dtype':
- value = _this.getDtypeParam(node.attr, param.tfParamName, param.defaultValue);
- if (value === undefined && !!param.tfParamNameDeprecated) {
- value = _this.getDtypeParam(node.attr, param.tfParamNameDeprecated, param.defaultValue);
- }
- break;
- case 'tensor':
- case 'tensors':
- break;
- default:
- throw new Error("Unsupported param type: " + param.type + " for op: " + node.op);
- }
- }
- map[param.dlParamName] = { value: value, inputIndex: inputIndex, type: type, inputParamLength: inputParamLength };
- return map;
- }, {});
- }
- return newNode;
- };
- OperationMapper.prototype.getStringParam = function (attrs, name, def, keepCase) {
- if (keepCase === void 0) { keepCase = false; }
- var param = attrs[name];
- if (param !== undefined) {
- var value = String.fromCharCode.apply(null, param.s);
- return keepCase ? value : value.toLowerCase();
- }
- return def;
- };
- OperationMapper.prototype.getBoolParam = function (attrs, name, def) {
- var param = attrs[name];
- return param ? param.b : def;
- };
- OperationMapper.prototype.getNumberParam = function (attrs, name, def) {
- var param = attrs[name];
- var value = (param ? ((param.f !== undefined) ? param.f : param.i) : def);
- return (typeof value === 'number') ? value : value['toInt']();
- };
- OperationMapper.prototype.getDtypeParam = function (attrs, name, def) {
- var param = attrs[name];
- if (param && param.type) {
- switch (param.type) {
- case compiled_api_1.tensorflow.DataType.DT_FLOAT:
- return 'float32';
- case compiled_api_1.tensorflow.DataType.DT_INT32:
- return 'int32';
- case compiled_api_1.tensorflow.DataType.DT_BOOL:
- return 'bool';
- default:
- return def;
- }
- }
- return def;
- };
- OperationMapper.prototype.getTensorShapeParam = function (attrs, name, def) {
- var param = attrs[name];
- if (param && param.shape) {
- return param.shape.dim.map(function (dim) { return dim.size; });
- }
- return def;
- };
- OperationMapper.prototype.getNumericArrayParam = function (attrs, name, def) {
- var param = attrs[name];
- if (param) {
- return ((param.list.f && param.list.f.length ? param.list.f :
- param.list.i))
- .map(function (v) { return (typeof v === 'number') ? v : v['toInt'](); });
- }
- return def;
- };
- return OperationMapper;
- }());
- exports.OperationMapper = OperationMapper;
- },{"../data/compiled_api":12,"./executors/utils":30,"./op_list/arithmetic.json":31,"./op_list/basic_math.json":32,"./op_list/control.json":33,"./op_list/convolution.json":34,"./op_list/creation.json":35,"./op_list/graph.json":36,"./op_list/image.json":37,"./op_list/logical.json":38,"./op_list/matrices.json":39,"./op_list/normalization.json":40,"./op_list/reduction.json":41,"./op_list/slice_join.json":42,"./op_list/transformation.json":43}],46:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var version = '0.4.3';
- exports.version = version;
- },{}],47:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("./doc");
- var BrowserUtil = (function () {
- function BrowserUtil() {
- }
- BrowserUtil.nextFrame = function () {
- return new Promise(function (resolve) { return requestAnimationFrame(function () { return resolve(); }); });
- };
- __decorate([
- doc_1.doc({ heading: 'Performance', subheading: 'Timing' })
- ], BrowserUtil, "nextFrame", null);
- return BrowserUtil;
- }());
- exports.BrowserUtil = BrowserUtil;
- },{"./doc":49}],48:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- function isMobile() {
- var a = navigator.userAgent || navigator.vendor || window.opera;
- return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i
- .test(a) ||
- /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i
- .test(a.substr(0, 4));
- }
- exports.isMobile = isMobile;
- },{}],49:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- function doc(info) {
- return function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- };
- }
- exports.doc = doc;
- },{}],50:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("./environment");
- var globals_1 = require("./globals");
- var ops = require("./ops/ops");
- var profiler_1 = require("./profiler");
- var tape_1 = require("./tape");
- var tensor_1 = require("./tensor");
- var util = require("./util");
- var Engine = (function () {
- function Engine(backend, safeMode) {
- this.backend = backend;
- this.safeMode = safeMode;
- this.registeredVariables = {};
- this.refCounter = new WeakMap();
- this.nextTapeNodeId = 0;
- this.numBytes = 0;
- this.numTensors = 0;
- this.numDataBuffers = 0;
- this.gradientScopeCount = 0;
- this.customGradientDepth = 0;
- this.keepTensors = new Set();
- this.activeScope = { track: [] };
- this.scopeStack = [this.activeScope];
- this.profiler = new profiler_1.Profiler(backend);
- }
- Engine.prototype.runKernel = function (forwardFunc, inputs, backwardsFunc) {
- var _this = this;
- var result;
- var saved = [];
- var saveFunc = function (x) {
- saved.push(x);
- return x;
- };
- var scopeName = this.activeScope.name;
- this.customGradientDepth++;
- if (!environment_1.ENV.get('DEBUG')) {
- result = forwardFunc(this.backend, saveFunc);
- }
- else {
- result = this.profiler.profileKernel(scopeName, function () { return forwardFunc(_this.backend, saveFunc); });
- }
- this.customGradientDepth--;
- if (this.shouldRecord()) {
- var tapeNode = {
- id: this.nextTapeNodeId++,
- name: scopeName,
- inputs: inputs,
- output: result,
- };
- if (backwardsFunc != null) {
- tapeNode.gradient = function (dy) { return backwardsFunc(dy, saved); };
- }
- this.activeTape.push(tapeNode);
- }
- return result;
- };
- Engine.prototype.registerTensor = function (a) {
- var refCount = this.refCounter.has(a.dataId) ? this.refCounter.get(a.dataId) : 0;
- this.numTensors++;
- if (refCount === 0) {
- this.numDataBuffers++;
- this.numBytes +=
- util.sizeFromShape(a.shape) * util.bytesPerElement(a.dtype);
- this.backend.register(a.dataId, a.shape, a.dtype);
- }
- this.refCounter.set(a.dataId, refCount + 1);
- if (!(a instanceof tensor_1.Variable)) {
- this.track(a);
- }
- };
- Engine.prototype.registerVariable = function (v) {
- if (this.registeredVariables[v.name] != null) {
- throw new Error("Variable with name " + v.name + " was already registered");
- }
- this.registeredVariables[v.name] = v;
- };
- Engine.prototype.disposeTensor = function (a) {
- if (!this.refCounter.has(a.dataId)) {
- return;
- }
- if (this.keepTensors.has(a.id)) {
- this.keepTensors.delete(a.id);
- }
- this.numTensors--;
- var refCount = this.refCounter.get(a.dataId);
- if (refCount <= 1) {
- this.refCounter.delete(a.dataId);
- this.backend.disposeData(a.dataId);
- this.numDataBuffers--;
- this.numBytes -=
- util.sizeFromShape(a.shape) * util.bytesPerElement(a.dtype);
- }
- else {
- this.refCounter.set(a.dataId, refCount - 1);
- }
- };
- Engine.prototype.disposeVariables = function () {
- for (var varName in this.registeredVariables) {
- var v = this.registeredVariables[varName];
- this.disposeTensor(v);
- delete this.registeredVariables[varName];
- }
- };
- Engine.prototype.memory = function () {
- var info = this.backend.memory();
- info.numTensors = this.numTensors;
- info.numDataBuffers = this.numDataBuffers;
- info.numBytes = this.numBytes;
- return info;
- };
- Engine.prototype.shouldRecord = function () {
- return this.activeTape != null && this.customGradientDepth === 0;
- };
- Engine.prototype.addTapeNode = function (inputs, result, gradientsFunc) {
- var inputsMap = {};
- inputs.forEach(function (input, idx) {
- inputsMap[idx] = input;
- });
- var gradient = function (dy) {
- var res = gradientsFunc(dy);
- var resMap = {};
- res.forEach(function (r, idx) {
- resMap[idx] = function () { return r; };
- });
- return resMap;
- };
- var tapeNode = {
- id: this.nextTapeNodeId++,
- name: this.activeScope.name,
- inputs: inputsMap,
- output: result,
- gradient: gradient
- };
- this.activeTape.push(tapeNode);
- };
- Engine.prototype.keep = function (result) {
- if (this.scopeStack.length === 1 && environment_1.ENV.engine.safeMode) {
- throw new Error('Safe mode is ON. Enclose all tensor operations inside tf.tidy(): ' +
- 'tf.tidy(() => {...}) to avoid memory leaks.');
- }
- this.keepTensors.add(result.id);
- return result;
- };
- Engine.prototype.startScope = function (name, gradientsMode) {
- if (gradientsMode === void 0) { gradientsMode = false; }
- if (gradientsMode && this.gradientScopeCount === 0) {
- this.activeTape = [];
- }
- if (gradientsMode) {
- this.gradientScopeCount++;
- }
- var scopeInfo = { track: [] };
- if (name) {
- scopeInfo.name = name;
- }
- this.scopeStack.push(scopeInfo);
- this.activeScope = scopeInfo;
- };
- Engine.prototype.endScope = function (result, gradientsMode) {
- var _this = this;
- if (gradientsMode === void 0) { gradientsMode = false; }
- if (gradientsMode) {
- this.gradientScopeCount--;
- if (this.gradientScopeCount === 0) {
- this.activeTape = null;
- }
- }
- var tensorsToKeep = new Set(this.keepTensors);
- var tensorsToTrackInParent = util.getTensorsInContainer(result);
- tensorsToTrackInParent.forEach(function (tensor) { return tensorsToKeep.add(tensor.id); });
- for (var i = 0; i < this.activeScope.track.length; i++) {
- var tensor = this.activeScope.track[i];
- if (tensorsToKeep.has(tensor.id)) {
- continue;
- }
- if (this.activeTape != null) {
- tensorsToTrackInParent.push(tensor);
- }
- else {
- tensor.dispose();
- }
- }
- var oldScope = this.scopeStack.pop();
- this.activeScope = this.scopeStack.length === 0 ?
- { track: [] } :
- this.scopeStack[this.scopeStack.length - 1];
- tensorsToTrackInParent.forEach(function (tensor) {
- if (!_this.keepTensors.has(tensor.id) &&
- util.isTensorInList(tensor, oldScope.track)) {
- _this.track(tensor);
- }
- });
- };
- Engine.prototype.gradients = function (f, xs, dy, allowNoGradients) {
- var _this = this;
- if (allowNoGradients === void 0) { allowNoGradients = false; }
- util.assert(xs.length > 0, 'gradients() received an empty list of xs.');
- return globals_1.tidy('gradients', function () {
- var y = f();
- util.assert(y instanceof tensor_1.Tensor, 'The result y returned by f() must be a tensor.');
- var filteredTape = tape_1.getFilteredNodesXToY(_this.activeTape, xs, y);
- if (!allowNoGradients && filteredTape.length === 0 && xs.length > 0) {
- throw new Error('Cannot compute gradient of y=f(x) with respect to x. Make sure ' +
- 'that the f you passed encloses all operations that lead from x ' +
- 'to y.');
- }
- var accumulatedGradientMap = {};
- accumulatedGradientMap[y.id] = (dy == null) ? ops.ones(y.shape) : dy;
- tape_1.backpropagateGradients(accumulatedGradientMap, filteredTape);
- var grads = xs.map(function (x) { return accumulatedGradientMap[x.id]; });
- return { value: y, grads: grads };
- }, true);
- };
- Engine.prototype.customGrad = function (f) {
- var _this = this;
- util.assert(util.isFunction(f), 'The f passed in customGrad(f) must be a function.');
- return function () {
- var inputs = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- inputs[_i] = arguments[_i];
- }
- util.assert(inputs.every(function (t) { return t instanceof tensor_1.Tensor; }), 'The args passed in customGrad(f)(x1, x2,...) must all be tensors');
- _this.customGradientDepth++;
- var gradientsFunc;
- var gradientsMode = true;
- var result = globals_1.tidy(f.name, function () {
- var _a = f.apply(void 0, inputs), value = _a.value, gradFunc = _a.gradFunc;
- util.assert(value instanceof tensor_1.Tensor, 'The function f passed in customGrad(f) must return an object ' +
- 'where `obj.value` is a tensor');
- util.assert(util.isFunction(gradFunc), 'The function f passed in customGrad(f) must return an object ' +
- 'where `obj.gradFunc` is a function.');
- gradientsFunc = gradFunc;
- return value;
- }, gradientsMode);
- _this.customGradientDepth--;
- if (_this.shouldRecord()) {
- var gradFunc = function (dy) {
- var res = gradientsFunc(dy);
- var grads = Array.isArray(res) ? res : [res];
- util.assert(grads.length === inputs.length, 'The function f passed in customGrad(f) must return an object ' +
- 'where `obj.gradFunc` is a function that returns the same ' +
- 'number of tensors as inputs passed to f(...).');
- util.assert(grads.every(function (t) { return t instanceof tensor_1.Tensor; }), 'The function f passed in customGrad(f) must return an object ' +
- 'where `obj.gradFunc` is a function that returns a list of ' +
- 'only tensors.');
- return grads;
- };
- _this.addTapeNode(inputs, result, gradFunc);
- }
- return result;
- };
- };
- Engine.prototype.write = function (dataId, values) {
- this.backend.write(dataId, values);
- };
- Engine.prototype.readSync = function (dataId) {
- return this.backend.readSync(dataId);
- };
- Engine.prototype.read = function (dataId) {
- return this.backend.read(dataId);
- };
- Engine.prototype.fromPixels = function (pixels, numChannels) {
- return this.backend.fromPixels(pixels, numChannels);
- };
- Engine.prototype.time = function (query) {
- return __awaiter(this, void 0, void 0, function () {
- var start, timingInfo;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- start = performance.now();
- return [4, this.backend.time(query)];
- case 1:
- timingInfo = _a.sent();
- timingInfo.wallMs = performance.now() - start;
- return [2, timingInfo];
- }
- });
- });
- };
- Engine.prototype.track = function (result) {
- if (this.scopeStack.length === 1 && this.safeMode) {
- throw new Error('Safe mode is ON. Enclose all tensor operations inside tf.tidy(): ' +
- 'tf.tidy(() => {op();...}); to avoid memory leaks.');
- }
- this.activeScope.track.push(result);
- return result;
- };
- return Engine;
- }());
- exports.Engine = Engine;
- },{"./environment":51,"./globals":52,"./ops/ops":129,"./profiler":155,"./tape":157,"./tensor":158,"./util":164}],51:[function(require,module,exports){
- (function (process,global){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var device_util = require("./device_util");
- var doc_1 = require("./doc");
- var engine_1 = require("./engine");
- var util = require("./util");
- var Type;
- (function (Type) {
- Type[Type["NUMBER"] = 0] = "NUMBER";
- Type[Type["BOOLEAN"] = 1] = "BOOLEAN";
- Type[Type["STRING"] = 2] = "STRING";
- })(Type = exports.Type || (exports.Type = {}));
- exports.URL_PROPERTIES = [
- { name: 'DEBUG', type: Type.BOOLEAN }, { name: 'IS_BROWSER', type: Type.BOOLEAN },
- { name: 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION', type: Type.NUMBER },
- { name: 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE', type: Type.BOOLEAN },
- { name: 'WEBGL_VERSION', type: Type.NUMBER },
- { name: 'WEBGL_RENDER_FLOAT32_ENABLED', type: Type.BOOLEAN },
- { name: 'WEBGL_DOWNLOAD_FLOAT_ENABLED', type: Type.BOOLEAN }, {
- name: 'WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED',
- type: Type.BOOLEAN
- },
- { name: 'BACKEND', type: Type.STRING }
- ];
- var TEST_EPSILON_FLOAT32_ENABLED = 1e-3;
- var TEST_EPSILON_FLOAT32_DISABLED = 1e-1;
- function hasExtension(gl, extensionName) {
- var ext = gl.getExtension(extensionName);
- return ext != null;
- }
- function getWebGLRenderingContext(webGLVersion) {
- if (webGLVersion === 0 || !exports.ENV.get('IS_BROWSER')) {
- throw new Error('Cannot get WebGL rendering context, WebGL is disabled.');
- }
- var tempCanvas = document.createElement('canvas');
- if (webGLVersion === 1) {
- return (tempCanvas.getContext('webgl') ||
- tempCanvas.getContext('experimental-webgl'));
- }
- return tempCanvas.getContext('webgl2');
- }
- function loseContext(gl) {
- if (gl != null) {
- var loseContextExtension = gl.getExtension('WEBGL_lose_context');
- if (loseContextExtension == null) {
- throw new Error('Extension WEBGL_lose_context not supported on this browser.');
- }
- loseContextExtension.loseContext();
- }
- }
- function isWebGLVersionEnabled(webGLVersion) {
- var gl;
- try {
- gl = getWebGLRenderingContext(webGLVersion);
- }
- catch (e) {
- return false;
- }
- if (gl != null) {
- loseContext(gl);
- return true;
- }
- return false;
- }
- function getWebGLDisjointQueryTimerVersion(webGLVersion) {
- if (webGLVersion === 0) {
- return 0;
- }
- var queryTimerVersion;
- var gl = getWebGLRenderingContext(webGLVersion);
- if (hasExtension(gl, 'EXT_disjoint_timer_query_webgl2') &&
- webGLVersion === 2) {
- queryTimerVersion = 2;
- }
- else if (hasExtension(gl, 'EXT_disjoint_timer_query')) {
- queryTimerVersion = 1;
- }
- else {
- queryTimerVersion = 0;
- }
- if (gl != null) {
- loseContext(gl);
- }
- return queryTimerVersion;
- }
- function createFloatTextureAndBindToFramebuffer(gl, webGLVersion) {
- var frameBuffer = gl.createFramebuffer();
- var texture = gl.createTexture();
- gl.bindTexture(gl.TEXTURE_2D, texture);
- var internalFormat = webGLVersion === 2 ? gl.RGBA32F : gl.RGBA;
- gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, 1, 1, 0, gl.RGBA, gl.FLOAT, null);
- gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
- }
- function isRenderToFloatTextureEnabled(webGLVersion) {
- if (webGLVersion === 0) {
- return false;
- }
- var gl = getWebGLRenderingContext(webGLVersion);
- if (webGLVersion === 1) {
- if (!hasExtension(gl, 'OES_texture_float')) {
- return false;
- }
- }
- else {
- if (!hasExtension(gl, 'EXT_color_buffer_float')) {
- return false;
- }
- }
- createFloatTextureAndBindToFramebuffer(gl, webGLVersion);
- var isFrameBufferComplete = gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE;
- loseContext(gl);
- return isFrameBufferComplete;
- }
- function isDownloadFloatTextureEnabled(webGLVersion) {
- if (webGLVersion === 0) {
- return false;
- }
- var gl = getWebGLRenderingContext(webGLVersion);
- if (webGLVersion === 1) {
- if (!hasExtension(gl, 'OES_texture_float')) {
- return false;
- }
- }
- else {
- if (!hasExtension(gl, 'EXT_color_buffer_float')) {
- return false;
- }
- }
- createFloatTextureAndBindToFramebuffer(gl, webGLVersion);
- gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.FLOAT, new Float32Array(4));
- var readPixelsNoError = gl.getError() === gl.NO_ERROR;
- loseContext(gl);
- return readPixelsNoError;
- }
- function isWebGLGetBufferSubDataAsyncExtensionEnabled(webGLVersion) {
- if (webGLVersion > 0) {
- return false;
- }
- if (webGLVersion !== 2) {
- return false;
- }
- var gl = getWebGLRenderingContext(webGLVersion);
- var isEnabled = hasExtension(gl, 'WEBGL_get_buffer_sub_data_async');
- loseContext(gl);
- return isEnabled;
- }
- function isChrome() {
- return navigator != null && navigator.userAgent != null &&
- /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
- }
- var Environment = (function () {
- function Environment(features) {
- this.features = {};
- this.registry = {};
- if (features != null) {
- this.features = features;
- }
- if (this.get('DEBUG')) {
- console.warn('Debugging mode is ON. The output of every math call will ' +
- 'be downloaded to CPU and checked for NaNs. ' +
- 'This significantly impacts performance.');
- }
- }
- Environment.setBackend = function (backendType, safeMode) {
- if (safeMode === void 0) { safeMode = false; }
- if (!(backendType in exports.ENV.registry)) {
- throw new Error("Backend type '" + backendType + "' not found in registry");
- }
- exports.ENV.initBackend(backendType, safeMode);
- };
- Environment.getBackend = function () {
- exports.ENV.initDefaultBackend();
- return exports.ENV.currentBackend;
- };
- Environment.disposeVariables = function () {
- exports.ENV.engine.disposeVariables();
- };
- Environment.memory = function () {
- return exports.ENV.engine.memory();
- };
- Environment.prototype.get = function (feature) {
- if (feature in this.features) {
- return this.features[feature];
- }
- this.features[feature] = this.evaluateFeature(feature);
- return this.features[feature];
- };
- Environment.prototype.getFeatures = function () {
- return this.features;
- };
- Environment.prototype.set = function (feature, value) {
- this.features[feature] = value;
- };
- Environment.prototype.getBestBackendType = function () {
- var _this = this;
- if (Object.keys(this.registry).length === 0) {
- throw new Error('No backend found in registry.');
- }
- var sortedBackends = Object.keys(this.registry)
- .map(function (name) {
- return { name: name, entry: _this.registry[name] };
- })
- .sort(function (a, b) {
- return b.entry.priority - a.entry.priority;
- });
- return sortedBackends[0].name;
- };
- Environment.prototype.evaluateFeature = function (feature) {
- if (feature === 'DEBUG') {
- return false;
- }
- else if (feature === 'IS_BROWSER') {
- return typeof window !== 'undefined';
- }
- else if (feature === 'IS_NODE') {
- return (typeof process !== 'undefined') &&
- (typeof process.versions.node !== 'undefined');
- }
- else if (feature === 'IS_CHROME') {
- return isChrome();
- }
- else if (feature === 'BACKEND') {
- return this.getBestBackendType();
- }
- else if (feature === 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') {
- var webGLVersion = this.get('WEBGL_VERSION');
- if (webGLVersion === 0) {
- return 0;
- }
- return getWebGLDisjointQueryTimerVersion(webGLVersion);
- }
- else if (feature === 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE') {
- return this.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0 &&
- !device_util.isMobile();
- }
- else if (feature === 'WEBGL_VERSION') {
- if (isWebGLVersionEnabled(2)) {
- return 2;
- }
- else if (isWebGLVersionEnabled(1)) {
- return 1;
- }
- return 0;
- }
- else if (feature === 'WEBGL_RENDER_FLOAT32_ENABLED') {
- return isRenderToFloatTextureEnabled(this.get('WEBGL_VERSION'));
- }
- else if (feature === 'WEBGL_DOWNLOAD_FLOAT_ENABLED') {
- return isDownloadFloatTextureEnabled(this.get('WEBGL_VERSION'));
- }
- else if (feature === 'WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED') {
- return isWebGLGetBufferSubDataAsyncExtensionEnabled(this.get('WEBGL_VERSION'));
- }
- else if (feature === 'TEST_EPSILON') {
- if (this.get('WEBGL_RENDER_FLOAT32_ENABLED')) {
- return TEST_EPSILON_FLOAT32_ENABLED;
- }
- return TEST_EPSILON_FLOAT32_DISABLED;
- }
- throw new Error("Unknown feature " + feature + ".");
- };
- Environment.prototype.setFeatures = function (features) {
- this.features = features;
- };
- Environment.prototype.reset = function () {
- this.features = getFeaturesFromURL();
- if (this.globalEngine != null) {
- this.globalEngine = null;
- }
- };
- Environment.prototype.initBackend = function (backendType, safeMode) {
- if (safeMode === void 0) { safeMode = false; }
- this.currentBackend = backendType;
- var backend = exports.ENV.findBackend(backendType);
- this.globalEngine = new engine_1.Engine(backend, safeMode);
- };
- Environment.prototype.findBackend = function (name) {
- if (!(name in this.registry)) {
- return null;
- }
- return this.registry[name].backend;
- };
- Environment.prototype.registerBackend = function (name, factory, priority) {
- if (priority === void 0) { priority = 1; }
- if (name in this.registry) {
- console.warn(name + " backend was already registered");
- }
- try {
- var backend = factory();
- this.registry[name] = { backend: backend, priority: priority };
- return true;
- }
- catch (err) {
- console.warn("Registration of backend " + name + " failed");
- console.warn(err.stack || err.message);
- return false;
- }
- };
- Environment.prototype.removeBackend = function (name) {
- if (!(name in this.registry)) {
- throw new Error(name + " backend not found in registry");
- }
- this.registry[name].backend.dispose();
- delete this.registry[name];
- };
- Object.defineProperty(Environment.prototype, "engine", {
- get: function () {
- this.initDefaultBackend();
- return this.globalEngine;
- },
- enumerable: true,
- configurable: true
- });
- Environment.prototype.initDefaultBackend = function () {
- if (this.globalEngine == null) {
- this.initBackend(exports.ENV.get('BACKEND'), false);
- }
- };
- __decorate([
- doc_1.doc({ heading: 'Environment' })
- ], Environment, "setBackend", null);
- __decorate([
- doc_1.doc({ heading: 'Environment' })
- ], Environment, "getBackend", null);
- __decorate([
- doc_1.doc({ heading: 'Environment' })
- ], Environment, "disposeVariables", null);
- __decorate([
- doc_1.doc({ heading: 'Performance', subheading: 'Memory' })
- ], Environment, "memory", null);
- return Environment;
- }());
- exports.Environment = Environment;
- var TENSORFLOWJS_FLAGS_PREFIX = 'tfjsflags';
- function getFeaturesFromURL() {
- var features = {};
- if (typeof window === 'undefined' || typeof window.location === 'undefined') {
- return features;
- }
- var urlParams = util.getQueryParams(window.location.search);
- if (TENSORFLOWJS_FLAGS_PREFIX in urlParams) {
- var urlFlags_1 = {};
- var keyValues = urlParams[TENSORFLOWJS_FLAGS_PREFIX].split(',');
- keyValues.forEach(function (keyValue) {
- var _a = keyValue.split(':'), key = _a[0], value = _a[1];
- urlFlags_1[key] = value;
- });
- exports.URL_PROPERTIES.forEach(function (urlProperty) {
- if (urlProperty.name in urlFlags_1) {
- console.log("Setting feature override from URL " + urlProperty.name + ": " +
- ("" + urlFlags_1[urlProperty.name]));
- if (urlProperty.type === Type.NUMBER) {
- features[urlProperty.name] = +urlFlags_1[urlProperty.name];
- }
- else if (urlProperty.type === Type.BOOLEAN) {
- features[urlProperty.name] = urlFlags_1[urlProperty.name] === 'true';
- }
- else if (urlProperty.type === Type.STRING) {
- features[urlProperty.name] = urlFlags_1[urlProperty.name];
- }
- else {
- console.warn("Unknown URL param: " + urlProperty.name + ".");
- }
- }
- });
- }
- return features;
- }
- function getGlobalNamespace() {
- var ns;
- if (typeof (window) !== 'undefined') {
- ns = window;
- }
- else if (typeof (global) !== 'undefined') {
- ns = global;
- }
- else {
- throw new Error('Could not find a global object');
- }
- return ns;
- }
- function getOrMakeEnvironment() {
- var ns = getGlobalNamespace();
- ns.ENV = ns.ENV || new Environment(getFeaturesFromURL());
- return ns.ENV;
- }
- exports.ENV = getOrMakeEnvironment();
- }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
- },{"./device_util":48,"./doc":49,"./engine":50,"./util":164,"_process":215}],52:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var gradients_1 = require("./gradients");
- var tracking_1 = require("./tracking");
- exports.tidy = tracking_1.Tracking.tidy;
- exports.keep = tracking_1.Tracking.keep;
- exports.dispose = tracking_1.Tracking.dispose;
- exports.time = tracking_1.Tracking.time;
- exports.grad = gradients_1.Gradients.grad;
- exports.valueAndGrad = gradients_1.Gradients.valueAndGrad;
- exports.grads = gradients_1.Gradients.grads;
- exports.valueAndGrads = gradients_1.Gradients.valueAndGrads;
- exports.variableGrads = gradients_1.Gradients.variableGrads;
- exports.customGrad = gradients_1.Gradients.customGrad;
- },{"./gradients":53,"./tracking":161}],53:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("./doc");
- var environment_1 = require("./environment");
- var globals_1 = require("./globals");
- var tensor_1 = require("./tensor");
- var util = require("./util");
- var Gradients = (function () {
- function Gradients() {
- }
- Gradients.gradScope = function (nameOrScopeFn, scopeFn) {
- return globals_1.tidy(nameOrScopeFn, scopeFn, true);
- };
- Gradients.grad = function (f) {
- util.assert(util.isFunction(f), 'The f passed in grad(f) must be a function');
- return function (x, dy) {
- util.assert(x instanceof tensor_1.Tensor, 'The x passed in grad(f)(x) must be a tensor');
- util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in grad(f)(x, dy) must be a tensor');
- return globals_1.tidy(function () {
- var _a = environment_1.ENV.engine.gradients(function () { return f(x); }, [x], dy), value = _a.value, grads = _a.grads;
- if (dy != null) {
- util.assertShapesMatch(value.shape, dy.shape, 'The shape of dy passed in grad(f)(x, dy) must match the shape ' +
- 'returned by f(x)');
- }
- checkGrads(grads);
- return grads[0];
- });
- };
- };
- Gradients.grads = function (f) {
- util.assert(util.isFunction(f), 'The f passed in grads(f) must be a function');
- return function (args, dy) {
- util.assert(Array.isArray(args) && args.every(function (arg) { return arg instanceof tensor_1.Tensor; }), 'The args passed in grads(f)(args) must be an array of tensors');
- util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in grads(f)(args, dy) must be a tensor');
- return globals_1.tidy(function () {
- var _a = environment_1.ENV.engine.gradients(function () { return f.apply(void 0, args); }, args, dy), value = _a.value, grads = _a.grads;
- if (dy != null) {
- util.assertShapesMatch(value.shape, dy.shape, 'The shape of dy passed in grads(f)([x1,...], dy) must ' +
- 'match the shape returned by f([x1,...])');
- }
- checkGrads(grads);
- return grads;
- });
- };
- };
- Gradients.valueAndGrad = function (f) {
- util.assert(util.isFunction(f), 'The f passed in valueAndGrad(f) must be a function');
- return function (x, dy) {
- util.assert(x instanceof tensor_1.Tensor, 'The x passed in valueAndGrad(f)(x) must be a tensor');
- util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in valueAndGrad(f)(x, dy) must be a tensor');
- var _a = environment_1.ENV.engine.gradients(function () { return f(x); }, [x], dy), grads = _a.grads, value = _a.value;
- checkGrads(grads);
- return { grad: grads[0], value: value };
- };
- };
- Gradients.valueAndGrads = function (f) {
- util.assert(util.isFunction(f), 'The f passed in valueAndGrads(f) must be a function');
- return function (args, dy) {
- util.assert(Array.isArray(args) && args.every(function (arg) { return arg instanceof tensor_1.Tensor; }), 'The args passed in valueAndGrads(f)(args) must be array of tensors');
- util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in valueAndGrads(f)(args, dy) must be a tensor');
- var res = environment_1.ENV.engine.gradients(function () { return f.apply(void 0, args); }, args, dy);
- if (dy != null) {
- util.assertShapesMatch(res.value.shape, dy.shape, 'The shape of dy passed in valueAndGrads(f)([x1,...], dy) must ' +
- 'match the shape returned by f([x1,...])');
- }
- checkGrads(res.grads);
- return res;
- };
- };
- Gradients.variableGrads = function (f, varList) {
- util.assert(util.isFunction(f), 'The f passed in variableGrads(f) must be a function');
- util.assert(varList == null ||
- Array.isArray(varList) && varList.every(function (v) { return v instanceof tensor_1.Variable; }), 'The varList passed in variableGrads(f, varList) must be an array ' +
- 'of variables');
- if (varList == null) {
- varList = [];
- for (var varName in environment_1.ENV.engine.registeredVariables) {
- varList.push(environment_1.ENV.engine.registeredVariables[varName]);
- }
- }
- var originalVarCount = varList.length;
- varList = varList.filter(function (variable) { return variable.trainable; });
- util.assert(varList.length > 0, "variableGrads() expects at least one of the input variables to be " +
- ("trainable, but none of the " + originalVarCount + " variables is ") +
- "trainable.");
- var allowNoGradients = true;
- var _a = environment_1.ENV.engine.gradients(f, varList, null, allowNoGradients), value = _a.value, grads = _a.grads;
- util.assert(grads.some(function (g) { return g != null; }), 'Cannot find a connection between any variable and the result of the ' +
- 'loss function y=f(x). Please make sure the operations that use ' +
- 'variables are inside the function f passed to minimize().');
- util.assert(value.rank === 0, "The f passed in variableGrads(f) must return a scalar, but it " +
- ("returned a rank-" + value.rank + " tensor"));
- var namedGrads = {};
- varList.forEach(function (v, i) {
- if (grads[i] != null) {
- namedGrads[v.name] = grads[i];
- }
- });
- return { value: value, grads: namedGrads };
- };
- Gradients.customGrad = function (f) {
- return environment_1.ENV.engine.customGrad(f);
- };
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Gradients' })
- ], Gradients, "grad", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Gradients' })
- ], Gradients, "grads", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Gradients' })
- ], Gradients, "valueAndGrad", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Gradients' })
- ], Gradients, "valueAndGrads", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Gradients' })
- ], Gradients, "variableGrads", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Gradients' })
- ], Gradients, "customGrad", null);
- return Gradients;
- }());
- exports.Gradients = Gradients;
- function checkGrads(grads) {
- var numNullGradients = grads.filter(function (g) { return g == null; }).length;
- if (numNullGradients > 0) {
- throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that\n the f you passed encloses all operations that lead from x to y.");
- }
- }
- },{"./doc":49,"./environment":51,"./globals":52,"./tensor":158,"./util":164}],54:[function(require,module,exports){
- "use strict";
- function __export(m) {
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
- }
- Object.defineProperty(exports, "__esModule", { value: true });
- require("./kernels/backend_webgl");
- require("./kernels/backend_cpu");
- var browser_util_1 = require("./browser_util");
- var environment = require("./environment");
- exports.environment = environment;
- var environment_1 = require("./environment");
- var io = require("./io/io");
- exports.io = io;
- var serialization = require("./serialization");
- exports.serialization = serialization;
- var test_util = require("./test_util");
- exports.test_util = test_util;
- var util = require("./util");
- exports.util = util;
- var version_1 = require("./version");
- exports.version_core = version_1.version;
- var webgl = require("./webgl");
- exports.webgl = webgl;
- var adadelta_optimizer_1 = require("./optimizers/adadelta_optimizer");
- exports.AdadeltaOptimizer = adadelta_optimizer_1.AdadeltaOptimizer;
- var adagrad_optimizer_1 = require("./optimizers/adagrad_optimizer");
- exports.AdagradOptimizer = adagrad_optimizer_1.AdagradOptimizer;
- var adam_optimizer_1 = require("./optimizers/adam_optimizer");
- exports.AdamOptimizer = adam_optimizer_1.AdamOptimizer;
- var adamax_optimizer_1 = require("./optimizers/adamax_optimizer");
- exports.AdamaxOptimizer = adamax_optimizer_1.AdamaxOptimizer;
- var momentum_optimizer_1 = require("./optimizers/momentum_optimizer");
- exports.MomentumOptimizer = momentum_optimizer_1.MomentumOptimizer;
- var optimizer_1 = require("./optimizers/optimizer");
- exports.Optimizer = optimizer_1.Optimizer;
- var rmsprop_optimizer_1 = require("./optimizers/rmsprop_optimizer");
- exports.RMSPropOptimizer = rmsprop_optimizer_1.RMSPropOptimizer;
- var sgd_optimizer_1 = require("./optimizers/sgd_optimizer");
- exports.SGDOptimizer = sgd_optimizer_1.SGDOptimizer;
- var tensor_1 = require("./tensor");
- exports.Tensor = tensor_1.Tensor;
- exports.TensorBuffer = tensor_1.TensorBuffer;
- exports.variable = tensor_1.variable;
- exports.Variable = tensor_1.Variable;
- var types_1 = require("./types");
- exports.Rank = types_1.Rank;
- __export(require("./ops/ops"));
- var loss_ops_1 = require("./ops/loss_ops");
- exports.Reduction = loss_ops_1.Reduction;
- __export(require("./train"));
- __export(require("./globals"));
- var environment_2 = require("./environment");
- exports.ENV = environment_2.ENV;
- exports.Environment = environment_2.Environment;
- exports.setBackend = environment_1.Environment.setBackend;
- exports.getBackend = environment_1.Environment.getBackend;
- exports.disposeVariables = environment_1.Environment.disposeVariables;
- exports.memory = environment_1.Environment.memory;
- var doc_1 = require("./doc");
- exports.doc = doc_1.doc;
- exports.nextFrame = browser_util_1.BrowserUtil.nextFrame;
- },{"./browser_util":47,"./doc":49,"./environment":51,"./globals":52,"./io/io":58,"./kernels/backend_cpu":65,"./kernels/backend_webgl":67,"./ops/loss_ops":122,"./ops/ops":129,"./optimizers/adadelta_optimizer":145,"./optimizers/adagrad_optimizer":146,"./optimizers/adam_optimizer":147,"./optimizers/adamax_optimizer":148,"./optimizers/momentum_optimizer":149,"./optimizers/optimizer":150,"./optimizers/rmsprop_optimizer":153,"./optimizers/sgd_optimizer":154,"./serialization":156,"./tensor":158,"./test_util":160,"./train":162,"./types":163,"./util":164,"./version":165,"./webgl":166}],55:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../environment");
- var io_utils_1 = require("./io_utils");
- var router_registry_1 = require("./router_registry");
- var DEFAULT_FILE_NAME_PREFIX = 'model';
- var DEFAULT_JSON_EXTENSION_NAME = '.json';
- var DEFAULT_WEIGHT_DATA_EXTENSION_NAME = '.weights.bin';
- var BrowserDownloads = (function () {
- function BrowserDownloads(fileNamePrefix) {
- if (!environment_1.ENV.get('IS_BROWSER')) {
- throw new Error('triggerDownloads() cannot proceed because the current environment ' +
- 'is not a browser.');
- }
- if (fileNamePrefix.startsWith(BrowserDownloads.URL_SCHEME)) {
- fileNamePrefix = fileNamePrefix.slice(BrowserDownloads.URL_SCHEME.length);
- }
- if (fileNamePrefix == null || fileNamePrefix.length === 0) {
- fileNamePrefix = DEFAULT_FILE_NAME_PREFIX;
- }
- this.modelTopologyFileName = fileNamePrefix + DEFAULT_JSON_EXTENSION_NAME;
- this.weightDataFileName =
- fileNamePrefix + DEFAULT_WEIGHT_DATA_EXTENSION_NAME;
- }
- BrowserDownloads.prototype.save = function (modelArtifacts) {
- return __awaiter(this, void 0, void 0, function () {
- var weightsURL, weightsManifest, modelTopologyAndWeightManifest, modelTopologyAndWeightManifestURL, jsonAnchor, weightDataAnchor;
- return __generator(this, function (_a) {
- weightsURL = window.URL.createObjectURL(new Blob([modelArtifacts.weightData], { type: 'application/octet-stream' }));
- if (modelArtifacts.modelTopology instanceof ArrayBuffer) {
- throw new Error('DownloadTrigger.save() does not support saving model topology ' +
- 'in binary formats yet.');
- }
- else {
- weightsManifest = [{
- paths: ['./' + this.weightDataFileName],
- weights: modelArtifacts.weightSpecs
- }];
- modelTopologyAndWeightManifest = {
- modelTopology: modelArtifacts.modelTopology,
- weightsManifest: weightsManifest
- };
- modelTopologyAndWeightManifestURL = window.URL.createObjectURL(new Blob([JSON.stringify(modelTopologyAndWeightManifest)], { type: 'application/json' }));
- jsonAnchor = this.jsonAnchor == null ? document.createElement('a') :
- this.jsonAnchor;
- jsonAnchor.download = this.modelTopologyFileName;
- jsonAnchor.href = modelTopologyAndWeightManifestURL;
- jsonAnchor.click();
- if (modelArtifacts.weightData != null) {
- weightDataAnchor = this.weightDataAnchor == null ?
- document.createElement('a') :
- this.weightDataAnchor;
- weightDataAnchor.download = this.weightDataFileName;
- weightDataAnchor.href = weightsURL;
- weightDataAnchor.click();
- }
- return [2, { modelArtifactsInfo: io_utils_1.getModelArtifactsInfoForJSON(modelArtifacts) }];
- }
- return [2];
- });
- });
- };
- BrowserDownloads.URL_SCHEME = 'downloads://';
- return BrowserDownloads;
- }());
- exports.BrowserDownloads = BrowserDownloads;
- var BrowserFiles = (function () {
- function BrowserFiles(files) {
- if (files == null || files.length < 1) {
- throw new Error("When calling browserFiles, at least 1 file is required, " +
- ("but received " + files));
- }
- this.files = files;
- }
- BrowserFiles.prototype.load = function () {
- return __awaiter(this, void 0, void 0, function () {
- var _this = this;
- var jsonFile, weightFiles;
- return __generator(this, function (_a) {
- jsonFile = this.files[0];
- weightFiles = this.files.slice(1);
- return [2, new Promise(function (resolve, reject) {
- var jsonReader = new FileReader();
- jsonReader.onload = function (event) {
- var modelJSON = JSON.parse(event.target.result);
- var modelTopology = modelJSON.modelTopology;
- if (modelTopology == null) {
- reject(new Error("modelTopology field is missing from file " + jsonFile.name));
- return;
- }
- if (weightFiles.length === 0) {
- resolve({ modelTopology: modelTopology });
- }
- var weightsManifest = modelJSON.weightsManifest;
- if (weightsManifest == null) {
- reject(new Error("weightManifest field is missing from file " + jsonFile.name));
- return;
- }
- var pathToFile;
- try {
- pathToFile =
- _this.checkManifestAndWeightFiles(weightsManifest, weightFiles);
- }
- catch (err) {
- reject(err);
- return;
- }
- var weightSpecs = [];
- var paths = [];
- var perFileBuffers = [];
- weightsManifest.forEach(function (weightsGroup) {
- weightsGroup.paths.forEach(function (path) {
- paths.push(path);
- perFileBuffers.push(null);
- });
- weightSpecs.push.apply(weightSpecs, weightsGroup.weights);
- });
- weightsManifest.forEach(function (weightsGroup) {
- weightsGroup.paths.forEach(function (path) {
- var weightFileReader = new FileReader();
- weightFileReader.onload = function (event) {
- var weightData = event.target.result;
- var index = paths.indexOf(path);
- perFileBuffers[index] = weightData;
- if (perFileBuffers.indexOf(null) === -1) {
- resolve({
- modelTopology: modelTopology,
- weightSpecs: weightSpecs,
- weightData: io_utils_1.concatenateArrayBuffers(perFileBuffers),
- });
- }
- };
- weightFileReader.onerror = function (error) {
- reject("Failed to weights data from file of path '" + path + "'.");
- return;
- };
- weightFileReader.readAsArrayBuffer(pathToFile[path]);
- });
- });
- };
- jsonReader.onerror = function (error) {
- reject("Failed to read model topology and weights manifest JSON " +
- ("from file '" + jsonFile.name + "'. BrowserFiles supports loading ") +
- "Keras-style tf.Model artifacts only.");
- return;
- };
- jsonReader.readAsText(jsonFile);
- })];
- });
- });
- };
- BrowserFiles.prototype.checkManifestAndWeightFiles = function (manifest, files) {
- var basenames = [];
- var fileNames = files.map(function (file) { return io_utils_1.basename(file.name); });
- var pathToFile = {};
- for (var _i = 0, manifest_1 = manifest; _i < manifest_1.length; _i++) {
- var group = manifest_1[_i];
- group.paths.forEach(function (path) {
- var pathBasename = io_utils_1.basename(path);
- if (basenames.indexOf(pathBasename) !== -1) {
- throw new Error("Duplicate file basename found in weights manifest: " +
- ("'" + pathBasename + "'"));
- }
- basenames.push(pathBasename);
- if (fileNames.indexOf(pathBasename) === -1) {
- throw new Error("Weight file with basename '" + pathBasename + "' is not provided.");
- }
- else {
- pathToFile[path] = files[fileNames.indexOf(pathBasename)];
- }
- });
- }
- if (basenames.length !== files.length) {
- throw new Error("Mismatch in the number of files in weights manifest " +
- ("(" + basenames.length + ") and the number of weight files provided ") +
- ("(" + files.length + ")."));
- }
- return pathToFile;
- };
- return BrowserFiles;
- }());
- exports.browserDownloadsRouter = function (url) {
- if (!environment_1.ENV.get('IS_BROWSER')) {
- return null;
- }
- else {
- if (url.startsWith(BrowserDownloads.URL_SCHEME)) {
- return browserDownloads(url.slice(BrowserDownloads.URL_SCHEME.length));
- }
- else {
- return null;
- }
- }
- };
- router_registry_1.IORouterRegistry.registerSaveRouter(exports.browserDownloadsRouter);
- function browserDownloads(fileNamePrefix) {
- if (fileNamePrefix === void 0) { fileNamePrefix = 'model'; }
- return new BrowserDownloads(fileNamePrefix);
- }
- exports.browserDownloads = browserDownloads;
- function browserFiles(files) {
- return new BrowserFiles(files);
- }
- exports.browserFiles = browserFiles;
- },{"../environment":51,"./io_utils":59,"./router_registry":62}],56:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../environment");
- var util_1 = require("../util");
- var io_utils_1 = require("./io_utils");
- var router_registry_1 = require("./router_registry");
- var weights_loader_1 = require("./weights_loader");
- var BrowserHTTPRequest = (function () {
- function BrowserHTTPRequest(path, requestInit) {
- this.DEFAULT_METHOD = 'POST';
- if (!environment_1.ENV.get('IS_BROWSER')) {
- throw new Error('browserHTTPRequest is not supported outside the web browser.');
- }
- util_1.assert(path != null && path.length > 0, 'URL path for browserHTTPRequest must not be null, undefined or ' +
- 'empty.');
- this.path = path;
- if (requestInit != null && requestInit.body != null) {
- throw new Error('requestInit is expected to have no pre-existing body, but has one.');
- }
- this.requestInit = requestInit || {};
- }
- BrowserHTTPRequest.prototype.save = function (modelArtifacts) {
- return __awaiter(this, void 0, void 0, function () {
- var init, weightsManifest, modelTopologyAndWeightManifest, response;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (modelArtifacts.modelTopology instanceof ArrayBuffer) {
- throw new Error('BrowserHTTPRequest.save() does not support saving model topology ' +
- 'in binary formats yet.');
- }
- init = Object.assign({ method: this.DEFAULT_METHOD }, this.requestInit);
- init.body = new FormData();
- weightsManifest = [{
- paths: ['./model.weights.bin'],
- weights: modelArtifacts.weightSpecs,
- }];
- modelTopologyAndWeightManifest = {
- modelTopology: modelArtifacts.modelTopology,
- weightsManifest: weightsManifest
- };
- init.body.append('model.json', new Blob([JSON.stringify(modelTopologyAndWeightManifest)], { type: 'application/json' }), 'model.json');
- if (modelArtifacts.weightData != null) {
- init.body.append('model.weights.bin', new Blob([modelArtifacts.weightData], { type: 'application/octet-stream' }), 'model.weights.bin');
- }
- return [4, fetch(this.path, init)];
- case 1:
- response = _a.sent();
- if (response.status === 200) {
- return [2, {
- modelArtifactsInfo: io_utils_1.getModelArtifactsInfoForJSON(modelArtifacts),
- responses: [response],
- }];
- }
- else {
- throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status " +
- (response.status + "."));
- }
- return [2];
- }
- });
- });
- };
- BrowserHTTPRequest.prototype.load = function () {
- return __awaiter(this, void 0, void 0, function () {
- var modelConfigRequest, modelConfig, modelTopology, weightsManifest, weightSpecs, weightData, weightsManifest_1, _i, weightsManifest_2, entry, pathPrefix_1, fetchURLs_1, _a;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0: return [4, fetch(this.path, this.requestInit)];
- case 1:
- modelConfigRequest = _b.sent();
- return [4, modelConfigRequest.json()];
- case 2:
- modelConfig = _b.sent();
- modelTopology = modelConfig['modelTopology'];
- weightsManifest = modelConfig['weightsManifest'];
- if (modelTopology == null && weightsManifest == null) {
- throw new Error("The JSON from HTTP path " + this.path + " contains neither model " +
- "topology or manifest for weights.");
- }
- if (!(weightsManifest != null)) return [3, 4];
- weightsManifest_1 = modelConfig['weightsManifest'];
- weightSpecs = [];
- for (_i = 0, weightsManifest_2 = weightsManifest_1; _i < weightsManifest_2.length; _i++) {
- entry = weightsManifest_2[_i];
- weightSpecs.push.apply(weightSpecs, entry.weights);
- }
- pathPrefix_1 = this.path.substring(0, this.path.lastIndexOf('/'));
- if (!pathPrefix_1.endsWith('/')) {
- pathPrefix_1 = pathPrefix_1 + '/';
- }
- fetchURLs_1 = [];
- weightsManifest_1.forEach(function (weightsGroup) {
- weightsGroup.paths.forEach(function (path) {
- fetchURLs_1.push(pathPrefix_1 + path);
- });
- });
- _a = io_utils_1.concatenateArrayBuffers;
- return [4, weights_loader_1.loadWeightsAsArrayBuffer(fetchURLs_1, this.requestInit)];
- case 3:
- weightData = _a.apply(void 0, [_b.sent()]);
- _b.label = 4;
- case 4: return [2, { modelTopology: modelTopology, weightSpecs: weightSpecs, weightData: weightData }];
- }
- });
- });
- };
- BrowserHTTPRequest.URL_SCHEMES = ['http://', 'https://'];
- return BrowserHTTPRequest;
- }());
- exports.BrowserHTTPRequest = BrowserHTTPRequest;
- exports.httpRequestRouter = function (url) {
- if (!environment_1.ENV.get('IS_BROWSER')) {
- return null;
- }
- else {
- for (var _i = 0, _a = BrowserHTTPRequest.URL_SCHEMES; _i < _a.length; _i++) {
- var scheme = _a[_i];
- if (url.startsWith(scheme)) {
- return browserHTTPRequest(url);
- }
- }
- return null;
- }
- };
- router_registry_1.IORouterRegistry.registerSaveRouter(exports.httpRequestRouter);
- router_registry_1.IORouterRegistry.registerLoadRouter(exports.httpRequestRouter);
- function browserHTTPRequest(path, requestInit) {
- return new BrowserHTTPRequest(path, requestInit);
- }
- exports.browserHTTPRequest = browserHTTPRequest;
- },{"../environment":51,"../util":164,"./io_utils":59,"./router_registry":62,"./weights_loader":64}],57:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../environment");
- var io_utils_1 = require("./io_utils");
- var model_management_1 = require("./model_management");
- var router_registry_1 = require("./router_registry");
- var DATABASE_NAME = 'tensorflowjs';
- var DATABASE_VERSION = 1;
- var MODEL_STORE_NAME = 'models_store';
- var INFO_STORE_NAME = 'model_info_store';
- function deleteDatabase() {
- return __awaiter(this, void 0, void 0, function () {
- var idbFactory;
- return __generator(this, function (_a) {
- idbFactory = getIndexedDBFactory();
- return [2, new Promise(function (resolve, reject) {
- var deleteRequest = idbFactory.deleteDatabase(DATABASE_NAME);
- deleteRequest.onsuccess = function () { return resolve(); };
- deleteRequest.onerror = function (error) { return reject(error); };
- })];
- });
- });
- }
- exports.deleteDatabase = deleteDatabase;
- function getIndexedDBFactory() {
- if (!environment_1.ENV.get('IS_BROWSER')) {
- throw new Error('Failed to obtain IndexedDB factory because the current environment' +
- 'is not a web browser.');
- }
- var theWindow = window;
- var factory = theWindow.indexedDB || theWindow.mozIndexedDB ||
- theWindow.webkitIndexedDB || theWindow.msIndexedDB ||
- theWindow.shimIndexedDB;
- if (factory == null) {
- throw new Error('The current browser does not appear to support IndexedDB.');
- }
- return factory;
- }
- function setUpDatabase(openRequest) {
- var db = openRequest.result;
- db.createObjectStore(MODEL_STORE_NAME, { keyPath: 'modelPath' });
- db.createObjectStore(INFO_STORE_NAME, { keyPath: 'modelPath' });
- }
- var BrowserIndexedDB = (function () {
- function BrowserIndexedDB(modelPath) {
- this.indexedDB = getIndexedDBFactory();
- if (modelPath == null || !modelPath) {
- throw new Error('For IndexedDB, modelPath must not be null, undefined or empty.');
- }
- this.modelPath = modelPath;
- }
- BrowserIndexedDB.prototype.save = function (modelArtifacts) {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- if (modelArtifacts.modelTopology instanceof ArrayBuffer) {
- throw new Error('BrowserLocalStorage.save() does not support saving model topology ' +
- 'in binary formats yet.');
- }
- return [2, this.databaseAction(this.modelPath, modelArtifacts)];
- });
- });
- };
- BrowserIndexedDB.prototype.load = function () {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- return [2, this.databaseAction(this.modelPath)];
- });
- });
- };
- BrowserIndexedDB.prototype.databaseAction = function (modelPath, modelArtifacts) {
- var _this = this;
- return new Promise(function (resolve, reject) {
- var openRequest = _this.indexedDB.open(DATABASE_NAME, DATABASE_VERSION);
- openRequest.onupgradeneeded = function () { return setUpDatabase(openRequest); };
- openRequest.onsuccess = function () {
- var db = openRequest.result;
- if (modelArtifacts == null) {
- var modelTx = db.transaction(MODEL_STORE_NAME, 'readonly');
- var modelStore = modelTx.objectStore(MODEL_STORE_NAME);
- var getRequest_1 = modelStore.get(_this.modelPath);
- getRequest_1.onsuccess = function () {
- if (getRequest_1.result == null) {
- db.close();
- return reject(new Error("Cannot find model with path '" + _this.modelPath + "' " +
- "in IndexedDB."));
- }
- else {
- resolve(getRequest_1.result.modelArtifacts);
- }
- };
- getRequest_1.onerror = function (error) {
- db.close();
- return reject(getRequest_1.error);
- };
- modelTx.oncomplete = function () { return db.close(); };
- }
- else {
- var modelArtifactsInfo_1 = io_utils_1.getModelArtifactsInfoForJSON(modelArtifacts);
- var infoTx_1 = db.transaction(INFO_STORE_NAME, 'readwrite');
- var infoStore_1 = infoTx_1.objectStore(INFO_STORE_NAME);
- var putInfoRequest_1 = infoStore_1.put({ modelPath: _this.modelPath, modelArtifactsInfo: modelArtifactsInfo_1 });
- var modelTx_1;
- putInfoRequest_1.onsuccess = function () {
- modelTx_1 = db.transaction(MODEL_STORE_NAME, 'readwrite');
- var modelStore = modelTx_1.objectStore(MODEL_STORE_NAME);
- var putModelRequest = modelStore.put({
- modelPath: _this.modelPath,
- modelArtifacts: modelArtifacts,
- modelArtifactsInfo: modelArtifactsInfo_1
- });
- putModelRequest.onsuccess = function () { return resolve({ modelArtifactsInfo: modelArtifactsInfo_1 }); };
- putModelRequest.onerror = function (error) {
- infoStore_1 = infoTx_1.objectStore(INFO_STORE_NAME);
- var deleteInfoRequest = infoStore_1.delete(_this.modelPath);
- deleteInfoRequest.onsuccess = function () {
- db.close();
- return reject(putModelRequest.error);
- };
- deleteInfoRequest.onerror = function (error) {
- db.close();
- return reject(putModelRequest.error);
- };
- };
- };
- putInfoRequest_1.onerror = function (error) {
- db.close();
- return reject(putInfoRequest_1.error);
- };
- infoTx_1.oncomplete = function () {
- if (modelTx_1 == null) {
- db.close();
- }
- else {
- modelTx_1.oncomplete = function () { return db.close(); };
- }
- };
- }
- };
- openRequest.onerror = function (error) { return reject(openRequest.error); };
- });
- };
- BrowserIndexedDB.URL_SCHEME = 'indexeddb://';
- return BrowserIndexedDB;
- }());
- exports.BrowserIndexedDB = BrowserIndexedDB;
- exports.indexedDBRouter = function (url) {
- if (!environment_1.ENV.get('IS_BROWSER')) {
- return null;
- }
- else {
- if (url.startsWith(BrowserIndexedDB.URL_SCHEME)) {
- return browserIndexedDB(url.slice(BrowserIndexedDB.URL_SCHEME.length));
- }
- else {
- return null;
- }
- }
- };
- router_registry_1.IORouterRegistry.registerSaveRouter(exports.indexedDBRouter);
- router_registry_1.IORouterRegistry.registerLoadRouter(exports.indexedDBRouter);
- function browserIndexedDB(modelPath) {
- return new BrowserIndexedDB(modelPath);
- }
- exports.browserIndexedDB = browserIndexedDB;
- function maybeStripScheme(key) {
- return key.startsWith(BrowserIndexedDB.URL_SCHEME) ?
- key.slice(BrowserIndexedDB.URL_SCHEME.length) :
- key;
- }
- var BrowserIndexedDBManager = (function () {
- function BrowserIndexedDBManager() {
- this.indexedDB = getIndexedDBFactory();
- }
- BrowserIndexedDBManager.prototype.listModels = function () {
- return __awaiter(this, void 0, void 0, function () {
- var _this = this;
- return __generator(this, function (_a) {
- return [2, new Promise(function (resolve, reject) {
- var openRequest = _this.indexedDB.open(DATABASE_NAME, DATABASE_VERSION);
- openRequest.onupgradeneeded = function () { return setUpDatabase(openRequest); };
- openRequest.onsuccess = function () {
- var db = openRequest.result;
- var tx = db.transaction(INFO_STORE_NAME, 'readonly');
- var store = tx.objectStore(INFO_STORE_NAME);
- var getAllInfoRequest = store.getAll();
- getAllInfoRequest.onsuccess = function () {
- var out = {};
- for (var _i = 0, _a = getAllInfoRequest.result; _i < _a.length; _i++) {
- var item = _a[_i];
- out[item.modelPath] = item.modelArtifactsInfo;
- }
- resolve(out);
- };
- getAllInfoRequest.onerror = function (error) {
- db.close();
- return reject(getAllInfoRequest.error);
- };
- tx.oncomplete = function () { return db.close(); };
- };
- openRequest.onerror = function (error) { return reject(openRequest.error); };
- })];
- });
- });
- };
- BrowserIndexedDBManager.prototype.removeModel = function (path) {
- return __awaiter(this, void 0, void 0, function () {
- var _this = this;
- return __generator(this, function (_a) {
- path = maybeStripScheme(path);
- return [2, new Promise(function (resolve, reject) {
- var openRequest = _this.indexedDB.open(DATABASE_NAME, DATABASE_VERSION);
- openRequest.onupgradeneeded = function () { return setUpDatabase(openRequest); };
- openRequest.onsuccess = function () {
- var db = openRequest.result;
- var infoTx = db.transaction(INFO_STORE_NAME, 'readwrite');
- var infoStore = infoTx.objectStore(INFO_STORE_NAME);
- var getInfoRequest = infoStore.get(path);
- var modelTx;
- getInfoRequest.onsuccess = function () {
- if (getInfoRequest.result == null) {
- db.close();
- return reject(new Error("Cannot find model with path '" + path + "' " +
- "in IndexedDB."));
- }
- else {
- var deleteInfoRequest = infoStore.delete(path);
- var deleteModelData_1 = function () {
- modelTx = db.transaction(MODEL_STORE_NAME, 'readwrite');
- var modelStore = modelTx.objectStore(MODEL_STORE_NAME);
- var deleteModelRequest = modelStore.delete(path);
- deleteModelRequest.onsuccess = function () {
- return resolve(getInfoRequest.result.modelArtifactsInfo);
- };
- deleteModelRequest.onerror = function (error) {
- return reject(getInfoRequest.error);
- };
- };
- deleteInfoRequest.onsuccess = deleteModelData_1;
- deleteInfoRequest.onerror = function (error) {
- deleteModelData_1();
- db.close();
- return reject(getInfoRequest.error);
- };
- }
- };
- getInfoRequest.onerror = function (error) {
- db.close();
- return reject(getInfoRequest.error);
- };
- infoTx.oncomplete = function () {
- if (modelTx == null) {
- db.close();
- }
- else {
- modelTx.oncomplete = function () { return db.close(); };
- }
- };
- };
- openRequest.onerror = function (error) { return reject(openRequest.error); };
- })];
- });
- });
- };
- return BrowserIndexedDBManager;
- }());
- exports.BrowserIndexedDBManager = BrowserIndexedDBManager;
- if (environment_1.ENV.get('IS_BROWSER')) {
- try {
- model_management_1.ModelStoreManagerRegistry.registerManager(BrowserIndexedDB.URL_SCHEME, new BrowserIndexedDBManager());
- }
- catch (err) {
- }
- }
- },{"../environment":51,"./io_utils":59,"./model_management":61,"./router_registry":62}],58:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- require("./indexed_db");
- require("./local_storage");
- var browser_files_1 = require("./browser_files");
- exports.browserFiles = browser_files_1.browserFiles;
- var browser_http_1 = require("./browser_http");
- exports.browserHTTPRequest = browser_http_1.browserHTTPRequest;
- var io_utils_1 = require("./io_utils");
- exports.concatenateArrayBuffers = io_utils_1.concatenateArrayBuffers;
- exports.decodeWeights = io_utils_1.decodeWeights;
- exports.encodeWeights = io_utils_1.encodeWeights;
- exports.getModelArtifactsInfoForJSON = io_utils_1.getModelArtifactsInfoForJSON;
- var model_management_1 = require("./model_management");
- var router_registry_1 = require("./router_registry");
- var weights_loader_1 = require("./weights_loader");
- exports.loadWeights = weights_loader_1.loadWeights;
- var registerSaveRouter = router_registry_1.IORouterRegistry.registerSaveRouter;
- exports.registerSaveRouter = registerSaveRouter;
- var registerLoadRouter = router_registry_1.IORouterRegistry.registerLoadRouter;
- exports.registerLoadRouter = registerLoadRouter;
- var getSaveHandlers = router_registry_1.IORouterRegistry.getSaveHandlers;
- exports.getSaveHandlers = getSaveHandlers;
- var getLoadHandlers = router_registry_1.IORouterRegistry.getLoadHandlers;
- exports.getLoadHandlers = getLoadHandlers;
- var copyModel = model_management_1.ModelManagement.copyModel;
- exports.copyModel = copyModel;
- var listModels = model_management_1.ModelManagement.listModels;
- exports.listModels = listModels;
- var moveModel = model_management_1.ModelManagement.moveModel;
- exports.moveModel = moveModel;
- var removeModel = model_management_1.ModelManagement.removeModel;
- exports.removeModel = removeModel;
- },{"./browser_files":55,"./browser_http":56,"./indexed_db":57,"./io_utils":59,"./local_storage":60,"./model_management":61,"./router_registry":62,"./weights_loader":64}],59:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var array_ops_1 = require("../ops/array_ops");
- var util_1 = require("../util");
- var types_1 = require("./types");
- function encodeWeights(tensors) {
- return __awaiter(this, void 0, void 0, function () {
- var specs, dataPromises, name_1, t, tensorValues;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- specs = [];
- dataPromises = [];
- for (name_1 in tensors) {
- t = tensors[name_1];
- if (t.dtype !== 'float32' && t.dtype !== 'int32' && t.dtype !== 'bool') {
- throw new Error("Unsupported dtype in weight '" + name_1 + "': " + t.dtype);
- }
- specs.push({ name: name_1, shape: t.shape, dtype: t.dtype });
- dataPromises.push(t.data());
- }
- return [4, Promise.all(dataPromises)];
- case 1:
- tensorValues = _a.sent();
- return [2, { data: concatenateTypedArrays(tensorValues), specs: specs }];
- }
- });
- });
- }
- exports.encodeWeights = encodeWeights;
- function decodeWeights(buffer, specs) {
- var out = {};
- var offset = 0;
- for (var _i = 0, specs_1 = specs; _i < specs_1.length; _i++) {
- var spec = specs_1[_i];
- var name_2 = spec.name;
- var dtype = spec.dtype;
- var shape = spec.shape;
- if (spec.quantization != null) {
- throw new Error("decodeWeights does not support quantization yet, but encountered " +
- ("weight '" + name_2 + " with quantization.'"));
- }
- var size = util_1.sizeFromShape(shape);
- var value = void 0;
- if (dtype === 'float32') {
- value = array_ops_1.ArrayOps.tensor(new Float32Array(buffer, offset, size), shape, 'float32');
- }
- else if (dtype === 'int32') {
- value =
- array_ops_1.ArrayOps.tensor(new Int32Array(buffer, offset, size), shape, 'int32');
- }
- else if (dtype === 'bool') {
- value =
- array_ops_1.ArrayOps.tensor(new Uint8Array(buffer, offset, size), shape, 'bool');
- }
- else {
- throw new Error("Unsupported dtype in weight '" + name_2 + "': " + dtype);
- }
- out[name_2] = value;
- offset += size * types_1.DTYPE_VALUE_SIZE_MAP[dtype];
- }
- return out;
- }
- exports.decodeWeights = decodeWeights;
- function concatenateTypedArrays(xs) {
- if (xs === null) {
- throw new Error("Invalid input value: " + JSON.stringify(xs));
- }
- var totalByteLength = 0;
- xs.forEach(function (x) {
- if (x instanceof Float32Array || x instanceof Int32Array) {
- totalByteLength += x.buffer.byteLength;
- }
- else if (x instanceof Uint8Array) {
- totalByteLength += x.buffer.byteLength;
- }
- else {
- throw new Error("Unsupported TypedArray subtype: " + x.constructor.name);
- }
- });
- var y = new Uint8Array(totalByteLength);
- var offset = 0;
- xs.forEach(function (x) {
- y.set(new Uint8Array(x.buffer), offset);
- offset += x.buffer.byteLength;
- });
- return y.buffer;
- }
- exports.concatenateTypedArrays = concatenateTypedArrays;
- function stringByteLength(str) {
- return new Blob([str]).size;
- }
- exports.stringByteLength = stringByteLength;
- function arrayBufferToBase64String(buffer) {
- return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)));
- }
- exports.arrayBufferToBase64String = arrayBufferToBase64String;
- function base64StringToArrayBuffer(str) {
- var s = atob(str);
- var buffer = new Uint8Array(s.length);
- for (var i = 0; i < s.length; ++i) {
- buffer.set([s.charCodeAt(i)], i);
- }
- return buffer.buffer;
- }
- exports.base64StringToArrayBuffer = base64StringToArrayBuffer;
- function concatenateArrayBuffers(buffers) {
- var totalByteLength = 0;
- buffers.forEach(function (buffer) {
- totalByteLength += buffer.byteLength;
- });
- var temp = new Uint8Array(totalByteLength);
- var offset = 0;
- buffers.forEach(function (buffer) {
- temp.set(new Uint8Array(buffer), offset);
- offset += buffer.byteLength;
- });
- return temp.buffer;
- }
- exports.concatenateArrayBuffers = concatenateArrayBuffers;
- function basename(path) {
- var SEPARATOR = '/';
- path = path.trim();
- while (path.endsWith(SEPARATOR)) {
- path = path.slice(0, path.length - 1);
- }
- var items = path.split(SEPARATOR);
- return items[items.length - 1];
- }
- exports.basename = basename;
- function getModelArtifactsInfoForJSON(modelArtifacts) {
- if (modelArtifacts.modelTopology instanceof ArrayBuffer) {
- throw new Error('Expected JSON model topology, received ArrayBuffer.');
- }
- return {
- dateSaved: new Date(),
- modelTopologyType: 'JSON',
- modelTopologyBytes: modelArtifacts.modelTopology == null ?
- 0 :
- stringByteLength(JSON.stringify(modelArtifacts.modelTopology)),
- weightSpecsBytes: modelArtifacts.weightSpecs == null ?
- 0 :
- stringByteLength(JSON.stringify(modelArtifacts.weightSpecs)),
- weightDataBytes: modelArtifacts.weightData == null ?
- 0 :
- modelArtifacts.weightData.byteLength,
- };
- }
- exports.getModelArtifactsInfoForJSON = getModelArtifactsInfoForJSON;
- },{"../ops/array_ops":108,"../util":164,"./types":63}],60:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../environment");
- var util_1 = require("../util");
- var io_utils_1 = require("./io_utils");
- var model_management_1 = require("./model_management");
- var router_registry_1 = require("./router_registry");
- var PATH_SEPARATOR = '/';
- var PATH_PREFIX = 'tensorflowjs_models';
- var INFO_SUFFIX = 'info';
- var MODEL_TOPOLOGY_SUFFIX = 'model_topology';
- var WEIGHT_SPECS_SUFFIX = 'weight_specs';
- var WEIGHT_DATA_SUFFIX = 'weight_data';
- function purgeLocalStorageArtifacts() {
- if (!environment_1.ENV.get('IS_BROWSER') || typeof window.localStorage === 'undefined') {
- throw new Error('purgeLocalStorageModels() cannot proceed because local storage is ' +
- 'unavailable in the current environment.');
- }
- var LS = window.localStorage;
- var purgedModelPaths = [];
- for (var i = 0; i < LS.length; ++i) {
- var key = LS.key(i);
- var prefix = PATH_PREFIX + PATH_SEPARATOR;
- if (key.startsWith(prefix) && key.length > prefix.length) {
- LS.removeItem(key);
- var modelName = getModelPathFromKey(key);
- if (purgedModelPaths.indexOf(modelName) === -1) {
- purgedModelPaths.push(modelName);
- }
- }
- }
- return purgedModelPaths;
- }
- exports.purgeLocalStorageArtifacts = purgeLocalStorageArtifacts;
- function getModelKeys(path) {
- return {
- info: [PATH_PREFIX, path, INFO_SUFFIX].join(PATH_SEPARATOR),
- topology: [PATH_PREFIX, path, MODEL_TOPOLOGY_SUFFIX].join(PATH_SEPARATOR),
- weightSpecs: [PATH_PREFIX, path, WEIGHT_SPECS_SUFFIX].join(PATH_SEPARATOR),
- weightData: [PATH_PREFIX, path, WEIGHT_DATA_SUFFIX].join(PATH_SEPARATOR)
- };
- }
- function getModelPathFromKey(key) {
- var items = key.split(PATH_SEPARATOR);
- if (items.length < 3) {
- throw new Error("Invalid key format: " + key);
- }
- return items.slice(1, items.length - 1).join(PATH_SEPARATOR);
- }
- function maybeStripScheme(key) {
- return key.startsWith(BrowserLocalStorage.URL_SCHEME) ?
- key.slice(BrowserLocalStorage.URL_SCHEME.length) :
- key;
- }
- var BrowserLocalStorage = (function () {
- function BrowserLocalStorage(modelPath) {
- if (!environment_1.ENV.get('IS_BROWSER') || typeof window.localStorage === 'undefined') {
- throw new Error('The current environment does not support local storage.');
- }
- this.LS = window.localStorage;
- if (modelPath == null || !modelPath) {
- throw new Error('For local storage, modelPath must not be null, undefined or empty.');
- }
- this.modelPath = modelPath;
- this.keys = getModelKeys(this.modelPath);
- }
- BrowserLocalStorage.prototype.save = function (modelArtifacts) {
- return __awaiter(this, void 0, void 0, function () {
- var topology, weightSpecs, modelArtifactsInfo, key;
- return __generator(this, function (_a) {
- if (modelArtifacts.modelTopology instanceof ArrayBuffer) {
- throw new Error('BrowserLocalStorage.save() does not support saving model topology ' +
- 'in binary formats yet.');
- }
- else {
- topology = JSON.stringify(modelArtifacts.modelTopology);
- weightSpecs = JSON.stringify(modelArtifacts.weightSpecs);
- modelArtifactsInfo = io_utils_1.getModelArtifactsInfoForJSON(modelArtifacts);
- try {
- this.LS.setItem(this.keys.info, JSON.stringify(modelArtifactsInfo));
- this.LS.setItem(this.keys.topology, topology);
- this.LS.setItem(this.keys.weightSpecs, weightSpecs);
- this.LS.setItem(this.keys.weightData, io_utils_1.arrayBufferToBase64String(modelArtifacts.weightData));
- return [2, { modelArtifactsInfo: modelArtifactsInfo }];
- }
- catch (err) {
- for (key in this.keys) {
- this.LS.removeItem(this.keys[key]);
- }
- throw new Error("Failed to save model '" + this.modelPath + "' to local storage: " +
- "size quota being exceeded is a possible cause of this failure: " +
- ("modelTopologyBytes=" + modelArtifactsInfo.modelTopologyBytes + ", ") +
- ("weightSpecsBytes=" + modelArtifactsInfo.weightSpecsBytes + ", ") +
- ("weightDataBytes=" + modelArtifactsInfo.weightDataBytes + "."));
- }
- }
- return [2];
- });
- });
- };
- BrowserLocalStorage.prototype.load = function () {
- return __awaiter(this, void 0, void 0, function () {
- var info, out, topology, weightSpecs, weightDataBase64;
- return __generator(this, function (_a) {
- info = JSON.parse(this.LS.getItem(this.keys.info));
- if (info == null) {
- throw new Error("In local storage, there is no model with name '" + this.modelPath + "'");
- }
- if (info.modelTopologyType !== 'JSON') {
- throw new Error('BrowserLocalStorage does not support loading non-JSON model ' +
- 'topology yet.');
- }
- out = {};
- topology = JSON.parse(this.LS.getItem(this.keys.topology));
- if (topology == null) {
- throw new Error("In local storage, the topology of model '" + this.modelPath + "' " +
- "is missing.");
- }
- out.modelTopology = topology;
- weightSpecs = JSON.parse(this.LS.getItem(this.keys.weightSpecs));
- if (weightSpecs == null) {
- throw new Error("In local storage, the weight specs of model '" + this.modelPath + "' " +
- "are missing.");
- }
- out.weightSpecs = weightSpecs;
- weightDataBase64 = this.LS.getItem(this.keys.weightData);
- if (weightDataBase64 == null) {
- throw new Error("In local storage, the binary weight values of model " +
- ("'" + this.modelPath + "' are missing."));
- }
- out.weightData = io_utils_1.base64StringToArrayBuffer(weightDataBase64);
- return [2, out];
- });
- });
- };
- BrowserLocalStorage.URL_SCHEME = 'localstorage://';
- return BrowserLocalStorage;
- }());
- exports.BrowserLocalStorage = BrowserLocalStorage;
- exports.localStorageRouter = function (url) {
- if (!environment_1.ENV.get('IS_BROWSER')) {
- return null;
- }
- else {
- if (url.startsWith(BrowserLocalStorage.URL_SCHEME)) {
- return browserLocalStorage(url.slice(BrowserLocalStorage.URL_SCHEME.length));
- }
- else {
- return null;
- }
- }
- };
- router_registry_1.IORouterRegistry.registerSaveRouter(exports.localStorageRouter);
- router_registry_1.IORouterRegistry.registerLoadRouter(exports.localStorageRouter);
- function browserLocalStorage(modelPath) {
- return new BrowserLocalStorage(modelPath);
- }
- exports.browserLocalStorage = browserLocalStorage;
- var BrowserLocalStorageManager = (function () {
- function BrowserLocalStorageManager() {
- util_1.assert(environment_1.ENV.get('IS_BROWSER'), 'Current environment is not a web browser');
- util_1.assert(typeof window.localStorage !== 'undefined', 'Current browser does not appear to support localStorage');
- this.LS = window.localStorage;
- }
- BrowserLocalStorageManager.prototype.listModels = function () {
- return __awaiter(this, void 0, void 0, function () {
- var out, prefix, suffix, i, key, modelPath;
- return __generator(this, function (_a) {
- out = {};
- prefix = PATH_PREFIX + PATH_SEPARATOR;
- suffix = PATH_SEPARATOR + INFO_SUFFIX;
- for (i = 0; i < this.LS.length; ++i) {
- key = this.LS.key(i);
- if (key.startsWith(prefix) && key.endsWith(suffix)) {
- modelPath = getModelPathFromKey(key);
- out[modelPath] = JSON.parse(this.LS.getItem(key));
- }
- }
- return [2, out];
- });
- });
- };
- BrowserLocalStorageManager.prototype.removeModel = function (path) {
- return __awaiter(this, void 0, void 0, function () {
- var keys, info;
- return __generator(this, function (_a) {
- path = maybeStripScheme(path);
- keys = getModelKeys(path);
- if (this.LS.getItem(keys.info) == null) {
- throw new Error("Cannot find model at path '" + path + "'");
- }
- info = JSON.parse(this.LS.getItem(keys.info));
- this.LS.removeItem(keys.info);
- this.LS.removeItem(keys.topology);
- this.LS.removeItem(keys.weightSpecs);
- this.LS.removeItem(keys.weightData);
- return [2, info];
- });
- });
- };
- return BrowserLocalStorageManager;
- }());
- exports.BrowserLocalStorageManager = BrowserLocalStorageManager;
- if (environment_1.ENV.get('IS_BROWSER')) {
- try {
- model_management_1.ModelStoreManagerRegistry.registerManager(BrowserLocalStorage.URL_SCHEME, new BrowserLocalStorageManager());
- }
- catch (err) {
- }
- }
- },{"../environment":51,"../util":164,"./io_utils":59,"./model_management":61,"./router_registry":62}],61:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var util_1 = require("../util");
- var router_registry_1 = require("./router_registry");
- var URL_SCHEME_SUFFIX = '://';
- var ModelStoreManagerRegistry = (function () {
- function ModelStoreManagerRegistry() {
- this.managers = {};
- }
- ModelStoreManagerRegistry.getInstance = function () {
- if (ModelStoreManagerRegistry.instance == null) {
- ModelStoreManagerRegistry.instance = new ModelStoreManagerRegistry();
- }
- return ModelStoreManagerRegistry.instance;
- };
- ModelStoreManagerRegistry.registerManager = function (scheme, manager) {
- util_1.assert(scheme != null, 'scheme must not be undefined or null.');
- if (scheme.endsWith(URL_SCHEME_SUFFIX)) {
- scheme = scheme.slice(0, scheme.indexOf(URL_SCHEME_SUFFIX));
- }
- util_1.assert(scheme.length > 0, 'scheme must not be an empty string.');
- var registry = ModelStoreManagerRegistry.getInstance();
- util_1.assert(registry.managers[scheme] == null, "A model store manager is already registered for scheme '" + scheme + "'.");
- registry.managers[scheme] = manager;
- };
- ModelStoreManagerRegistry.getManager = function (scheme) {
- var manager = this.getInstance().managers[scheme];
- if (manager == null) {
- throw new Error("Cannot find model manager for scheme '" + scheme + "'");
- }
- return manager;
- };
- ModelStoreManagerRegistry.getSchemes = function () {
- return Object.keys(this.getInstance().managers);
- };
- return ModelStoreManagerRegistry;
- }());
- exports.ModelStoreManagerRegistry = ModelStoreManagerRegistry;
- function parseURL(url) {
- if (url.indexOf(URL_SCHEME_SUFFIX) === -1) {
- throw new Error("The url string provided does not contain a scheme. " +
- "Supported schemes are: " +
- ("" + ModelStoreManagerRegistry.getSchemes().join(',')));
- }
- return {
- scheme: url.split(URL_SCHEME_SUFFIX)[0],
- path: url.split(URL_SCHEME_SUFFIX)[1],
- };
- }
- function cloneModelInternal(sourceURL, destURL, deleteSource) {
- if (deleteSource === void 0) { deleteSource = false; }
- return __awaiter(this, void 0, void 0, function () {
- var loadHandlers, loadHandler, saveHandlers, saveHandler, sourceScheme, sourcePath, sameMedium, modelArtifacts, saveResult;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- util_1.assert(sourceURL !== destURL, "Old path and new path are the same: '" + sourceURL + "'");
- loadHandlers = router_registry_1.IORouterRegistry.getLoadHandlers(sourceURL);
- util_1.assert(loadHandlers.length > 0, "Copying failed because no load handler is found for source URL " + sourceURL + ".");
- util_1.assert(loadHandlers.length < 2, "Copying failed because more than one (" + loadHandlers.length + ") " +
- ("load handlers for source URL " + sourceURL + "."));
- loadHandler = loadHandlers[0];
- saveHandlers = router_registry_1.IORouterRegistry.getSaveHandlers(destURL);
- util_1.assert(saveHandlers.length > 0, "Copying failed because no save handler is found for destination URL " +
- (destURL + "."));
- util_1.assert(saveHandlers.length < 2, "Copying failed because more than one (" + loadHandlers.length + ") " +
- ("save handlers for destination URL " + destURL + "."));
- saveHandler = saveHandlers[0];
- sourceScheme = parseURL(sourceURL).scheme;
- sourcePath = parseURL(sourceURL).path;
- sameMedium = sourceScheme === parseURL(sourceURL).scheme;
- return [4, loadHandler.load()];
- case 1:
- modelArtifacts = _a.sent();
- if (!(deleteSource && sameMedium)) return [3, 3];
- return [4, ModelStoreManagerRegistry.getManager(sourceScheme)
- .removeModel(sourcePath)];
- case 2:
- _a.sent();
- _a.label = 3;
- case 3: return [4, saveHandler.save(modelArtifacts)];
- case 4:
- saveResult = _a.sent();
- if (!(deleteSource && !sameMedium)) return [3, 6];
- return [4, ModelStoreManagerRegistry.getManager(sourceScheme)
- .removeModel(sourcePath)];
- case 5:
- _a.sent();
- _a.label = 6;
- case 6: return [2, saveResult.modelArtifactsInfo];
- }
- });
- });
- }
- var ModelManagement = (function () {
- function ModelManagement() {
- }
- ModelManagement.listModels = function () {
- return __awaiter(this, void 0, void 0, function () {
- var schemes, out, _i, schemes_1, scheme, schemeOut, path, url;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- schemes = ModelStoreManagerRegistry.getSchemes();
- out = {};
- _i = 0, schemes_1 = schemes;
- _a.label = 1;
- case 1:
- if (!(_i < schemes_1.length)) return [3, 4];
- scheme = schemes_1[_i];
- return [4, ModelStoreManagerRegistry.getManager(scheme).listModels()];
- case 2:
- schemeOut = _a.sent();
- for (path in schemeOut) {
- url = scheme + URL_SCHEME_SUFFIX + path;
- out[url] = schemeOut[path];
- }
- _a.label = 3;
- case 3:
- _i++;
- return [3, 1];
- case 4: return [2, out];
- }
- });
- });
- };
- ModelManagement.removeModel = function (url) {
- return __awaiter(this, void 0, void 0, function () {
- var schemeAndPath, manager;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- schemeAndPath = parseURL(url);
- manager = ModelStoreManagerRegistry.getManager(schemeAndPath.scheme);
- return [4, manager.removeModel(schemeAndPath.path)];
- case 1: return [2, _a.sent()];
- }
- });
- });
- };
- ModelManagement.copyModel = function (sourceURL, destURL) {
- return __awaiter(this, void 0, void 0, function () {
- var deleteSource;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- deleteSource = false;
- return [4, cloneModelInternal(sourceURL, destURL, deleteSource)];
- case 1: return [2, _a.sent()];
- }
- });
- });
- };
- ModelManagement.moveModel = function (sourceURL, destURL) {
- return __awaiter(this, void 0, void 0, function () {
- var deleteSource;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- deleteSource = true;
- return [4, cloneModelInternal(sourceURL, destURL, deleteSource)];
- case 1: return [2, _a.sent()];
- }
- });
- });
- };
- __decorate([
- doc_1.doc({ heading: 'Models', subheading: 'Management', namespace: 'io' })
- ], ModelManagement, "listModels", null);
- __decorate([
- doc_1.doc({ heading: 'Models', subheading: 'Management', namespace: 'io' })
- ], ModelManagement, "removeModel", null);
- __decorate([
- doc_1.doc({ heading: 'Models', subheading: 'Management', namespace: 'io' })
- ], ModelManagement, "copyModel", null);
- __decorate([
- doc_1.doc({ heading: 'Models', subheading: 'Management', namespace: 'io' })
- ], ModelManagement, "moveModel", null);
- return ModelManagement;
- }());
- exports.ModelManagement = ModelManagement;
- },{"../doc":49,"../util":164,"./router_registry":62}],62:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var IORouterRegistry = (function () {
- function IORouterRegistry() {
- this.saveRouters = [];
- this.loadRouters = [];
- }
- IORouterRegistry.getInstance = function () {
- if (IORouterRegistry.instance == null) {
- IORouterRegistry.instance = new IORouterRegistry();
- }
- return IORouterRegistry.instance;
- };
- IORouterRegistry.registerSaveRouter = function (saveRouter) {
- IORouterRegistry.getInstance().saveRouters.push(saveRouter);
- };
- IORouterRegistry.registerLoadRouter = function (loadRouter) {
- IORouterRegistry.getInstance().loadRouters.push(loadRouter);
- };
- IORouterRegistry.getSaveHandlers = function (url) {
- return IORouterRegistry.getHandlers(url, 'save');
- };
- IORouterRegistry.getLoadHandlers = function (url) {
- return IORouterRegistry.getHandlers(url, 'load');
- };
- IORouterRegistry.getHandlers = function (url, handlerType) {
- var validHandlers = [];
- var routers = handlerType === 'load' ? this.getInstance().loadRouters :
- this.getInstance().saveRouters;
- routers.forEach(function (router) {
- var handler = router(url);
- if (handler !== null) {
- validHandlers.push(handler);
- }
- });
- return validHandlers;
- };
- return IORouterRegistry;
- }());
- exports.IORouterRegistry = IORouterRegistry;
- },{}],63:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.DTYPE_VALUE_SIZE_MAP = {
- 'float32': 4,
- 'int32': 4,
- 'uint16': 2,
- 'uint8': 1,
- 'bool': 1,
- };
- },{}],64:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var ops_1 = require("../ops/ops");
- var util = require("../util");
- var types_1 = require("./types");
- function loadWeightsAsArrayBuffer(fetchURLs, requestOptions) {
- return __awaiter(this, void 0, void 0, function () {
- var requests, responses, buffers;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- requests = fetchURLs.map(function (fetchURL) { return fetch(fetchURL, requestOptions); });
- return [4, Promise.all(requests)];
- case 1:
- responses = _a.sent();
- return [4, Promise.all(responses.map(function (response) { return response.arrayBuffer(); }))];
- case 2:
- buffers = _a.sent();
- return [2, buffers];
- }
- });
- });
- }
- exports.loadWeightsAsArrayBuffer = loadWeightsAsArrayBuffer;
- function loadWeights(manifest, filePathPrefix, weightNames, requestOptions) {
- if (filePathPrefix === void 0) { filePathPrefix = ''; }
- return __awaiter(this, void 0, void 0, function () {
- var groupIndicesToFetchMap, groupWeightsToFetch, weightsFound, allManifestWeightNames, weightsNotFound, groupIndicesToFetch, fetchUrls, buffers, weightsTensorMap, bufferIndexOffset;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- groupIndicesToFetchMap = manifest.map(function () { return false; });
- groupWeightsToFetch = {};
- weightsFound = weightNames != null ? weightNames.map(function () { return false; }) : [];
- allManifestWeightNames = [];
- manifest.forEach(function (manifestGroupConfig, groupIndex) {
- var groupOffset = 0;
- manifestGroupConfig.weights.forEach(function (weightsEntry) {
- var rawDtype = ('quantization' in weightsEntry) ?
- weightsEntry.quantization.dtype :
- weightsEntry.dtype;
- var weightsBytes = types_1.DTYPE_VALUE_SIZE_MAP[rawDtype] *
- util.sizeFromShape(weightsEntry.shape);
- var enqueueWeightsForFetchingFn = function () {
- groupIndicesToFetchMap[groupIndex] = true;
- if (groupWeightsToFetch[groupIndex] == null) {
- groupWeightsToFetch[groupIndex] = [];
- }
- groupWeightsToFetch[groupIndex].push({
- manifestEntry: weightsEntry,
- groupOffset: groupOffset,
- sizeBytes: weightsBytes
- });
- };
- if (weightNames != null) {
- weightNames.forEach(function (weightName, weightIndex) {
- if (weightName === weightsEntry.name) {
- enqueueWeightsForFetchingFn();
- weightsFound[weightIndex] = true;
- }
- });
- }
- else {
- enqueueWeightsForFetchingFn();
- }
- allManifestWeightNames.push(weightsEntry.name);
- groupOffset += weightsBytes;
- });
- });
- if (!weightsFound.every(function (found) { return found; })) {
- weightsNotFound = weightNames.filter(function (weight, i) { return !weightsFound[i]; });
- throw new Error("Could not find weights in manifest with names: " +
- (weightsNotFound.join(', ') + ". \n") +
- "Manifest JSON has weights with names: " +
- (allManifestWeightNames.join(', ') + "."));
- }
- groupIndicesToFetch = groupIndicesToFetchMap.reduce(function (accumulator, shouldFetch, i) {
- if (shouldFetch) {
- accumulator.push(i);
- }
- return accumulator;
- }, []);
- fetchUrls = [];
- groupIndicesToFetch.forEach(function (i) {
- manifest[i].paths.forEach(function (filepath) {
- var fetchUrl = filePathPrefix +
- (!filePathPrefix.endsWith('/') ? '/' : '') + filepath;
- fetchUrls.push(fetchUrl);
- });
- });
- return [4, loadWeightsAsArrayBuffer(fetchUrls, requestOptions)];
- case 1:
- buffers = _a.sent();
- weightsTensorMap = {};
- bufferIndexOffset = 0;
- groupIndicesToFetch.forEach(function (i) {
- var numBuffers = manifest[i].paths.length;
- var groupBytes = 0;
- for (var i_1 = 0; i_1 < numBuffers; i_1++) {
- groupBytes += buffers[bufferIndexOffset + i_1].byteLength;
- }
- var groupBuffer = new ArrayBuffer(groupBytes);
- var groupByteBuffer = new Uint8Array(groupBuffer);
- var groupBufferOffset = 0;
- for (var i_2 = 0; i_2 < numBuffers; i_2++) {
- var buffer = new Uint8Array(buffers[bufferIndexOffset + i_2]);
- groupByteBuffer.set(buffer, groupBufferOffset);
- groupBufferOffset += buffer.byteLength;
- }
- var weightsEntries = groupWeightsToFetch[i];
- weightsEntries.forEach(function (weightsEntry) {
- var byteBuffer = groupBuffer.slice(weightsEntry.groupOffset, weightsEntry.groupOffset + weightsEntry.sizeBytes);
- var typedArray;
- var dtype = weightsEntry.manifestEntry.dtype;
- if ('quantization' in weightsEntry.manifestEntry) {
- var quantization_1 = weightsEntry.manifestEntry.quantization;
- if (quantization_1.dtype !== 'uint8' && quantization_1.dtype !== 'uint16') {
- throw new Error("Weight " + weightsEntry.manifestEntry.name + " has unknown " +
- ("quantization dtype " + quantization_1.dtype + "."));
- }
- var quantizedArray = (quantization_1.dtype === 'uint8') ?
- new Uint8Array(byteBuffer) :
- new Uint16Array(byteBuffer);
- if (dtype === 'float32') {
- typedArray = Float32Array.from(quantizedArray, function (v) { return v * quantization_1.scale + quantization_1.min; });
- }
- else if (dtype === 'int32') {
- typedArray = Int32Array.from(quantizedArray, function (v) { return Math.round(v * quantization_1.scale + quantization_1.min); });
- }
- else {
- throw new Error("Weight " + weightsEntry.manifestEntry.name + " has a dtype not " +
- ("supported by quantization: " + dtype));
- }
- }
- else {
- if (dtype === 'float32') {
- typedArray = new Float32Array(byteBuffer);
- }
- else if (dtype === 'int32') {
- typedArray = new Int32Array(byteBuffer);
- }
- else {
- throw new Error("Weight " + weightsEntry.manifestEntry.name + " has unknown dtype " +
- (dtype + "."));
- }
- }
- var weightName = weightsEntry.manifestEntry.name;
- if (weightsTensorMap[weightName] != null) {
- throw new Error("Duplicate weight with name " + weightName + ". " +
- "Please make sure weights names are unique in the manifest JSON.");
- }
- weightsTensorMap[weightName] = ops_1.tensor(typedArray, weightsEntry.manifestEntry.shape, weightsEntry.manifestEntry.dtype);
- });
- bufferIndexOffset += numBuffers;
- });
- return [2, weightsTensorMap];
- }
- });
- });
- }
- exports.loadWeights = loadWeights;
- },{"../ops/ops":129,"../util":164,"./types":63}],65:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var seedrandom = require("seedrandom");
- var environment_1 = require("../environment");
- var axis_util = require("../ops/axis_util");
- var broadcast_util = require("../ops/broadcast_util");
- var concat_util = require("../ops/concat_util");
- var erf_util = require("../ops/erf_util");
- var ops = require("../ops/ops");
- var ops_1 = require("../ops/ops");
- var selu_util = require("../ops/selu_util");
- var slice_util_1 = require("../ops/slice_util");
- var tensor_1 = require("../tensor");
- var types = require("../types");
- var util = require("../util");
- var backend_util = require("./backend_util");
- var MathBackendCPU = (function () {
- function MathBackendCPU() {
- this.data = new WeakMap();
- this.firstUse = true;
- if (environment_1.ENV.get('IS_BROWSER')) {
- this.canvas = document.createElement('canvas');
- }
- }
- MathBackendCPU.prototype.register = function (dataId, shape, dtype) {
- if (this.firstUse) {
- this.firstUse = false;
- if (environment_1.ENV.get('IS_NODE')) {
- console.warn('\n============================\n' +
- 'Hi there 👋. Looks like you are running TensorFlow.js in ' +
- 'Node.js. To speed things up dramatically, install our node ' +
- 'backend, which binds to TensorFlow C++, by running ' +
- 'npm i @tensorflow/tfjs-node, ' +
- 'or npm i @tensorflow/tfjs-node-gpu if you have CUDA. ' +
- 'Then call require(\'tensorflow/tfjs-node\'); (-gpu ' +
- 'suffix for CUDA) at the start of your program. ' +
- 'Visit https://github.com/tensorflow/tfjs-node for more details.' +
- '\n============================\n');
- }
- }
- if (this.data.has(dataId)) {
- throw new Error("Data buffer is already registered");
- }
- this.data.set(dataId, null);
- };
- MathBackendCPU.prototype.write = function (dataId, values) {
- if (values == null) {
- throw new Error('MathBackendCPU.write(): values can not be null');
- }
- this.throwIfNoData(dataId);
- this.data.set(dataId, values);
- };
- MathBackendCPU.prototype.fromPixels = function (pixels, numChannels) {
- if (pixels == null) {
- throw new Error('MathBackendCPU.writePixels(): pixels can not be null');
- }
- var vals;
- if (pixels instanceof ImageData) {
- vals = pixels.data;
- }
- else if (pixels instanceof HTMLCanvasElement) {
- vals = pixels.getContext('2d')
- .getImageData(0, 0, pixels.width, pixels.height)
- .data;
- }
- else if (pixels instanceof HTMLImageElement ||
- pixels instanceof HTMLVideoElement) {
- if (this.canvas == null) {
- throw new Error('Can\'t read pixels from HTMLImageElement outside ' +
- 'the browser.');
- }
- this.canvas.width = pixels.width;
- this.canvas.height = pixels.height;
- this.canvas.getContext('2d').drawImage(pixels, 0, 0, pixels.width, pixels.height);
- vals = this.canvas.getContext('2d')
- .getImageData(0, 0, pixels.width, pixels.height)
- .data;
- }
- else {
- throw new Error("pixels is of unknown type: " + pixels.constructor.name);
- }
- var values;
- if (numChannels === 4) {
- values = new Int32Array(vals);
- }
- else {
- var numPixels = pixels.width * pixels.height;
- values = new Int32Array(numPixels * numChannels);
- for (var i = 0; i < numPixels; i++) {
- for (var channel = 0; channel < numChannels; ++channel) {
- values[i * numChannels + channel] = vals[i * 4 + channel];
- }
- }
- }
- var outShape = [pixels.height, pixels.width, numChannels];
- return ops_1.tensor3d(values, outShape, 'int32');
- };
- MathBackendCPU.prototype.read = function (dataId) {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- return [2, this.readSync(dataId)];
- });
- });
- };
- MathBackendCPU.prototype.readSync = function (dataId) {
- this.throwIfNoData(dataId);
- return this.data.get(dataId);
- };
- MathBackendCPU.prototype.disposeData = function (dataId) {
- if (this.data.has(dataId)) {
- this.data.delete(dataId);
- }
- };
- MathBackendCPU.prototype.time = function (f) {
- return __awaiter(this, void 0, void 0, function () {
- var start, kernelMs;
- return __generator(this, function (_a) {
- start = performance.now();
- f();
- kernelMs = performance.now() - start;
- return [2, { kernelMs: kernelMs }];
- });
- });
- };
- MathBackendCPU.prototype.memory = function () {
- return {
- unreliable: true
- };
- };
- MathBackendCPU.prototype.throwIfNoData = function (dataId) {
- if (!this.data.has(dataId)) {
- throw new Error("CPU backend: No data found for this tensor. " +
- "Did you change your backend in the middle of the program? " +
- "New backends can't use Tensors created with previous backends");
- }
- };
- MathBackendCPU.prototype.slice = function (x, begin, size) {
- var buffer = ops.buffer(size, x.dtype);
- for (var i = 0; i < buffer.size; ++i) {
- var loc = buffer.indexToLoc(i);
- var xLoc = loc.map(function (idx, j) { return idx + begin[j]; });
- buffer.set.apply(buffer, [x.get.apply(x, xLoc)].concat(loc));
- }
- return buffer.toTensor();
- };
- MathBackendCPU.prototype.stridedSlice = function (x, begin, end, strides, beginMask, endMask) {
- var _a = slice_util_1.getStridedSlicedInfo(x.shape, begin, end, strides, beginMask, endMask), beginIndex = _a[0], size = _a[1];
- if (size.some(function (axis) { return axis === 0; })) {
- return ops.tensor([], size);
- }
- var buffer = ops.buffer(size, x.dtype);
- for (var i = 0; i < buffer.size; i++) {
- var loc = buffer.indexToLoc(i);
- var newLoc = new Array(loc.length);
- for (var j = 0; j < newLoc.length; j++) {
- newLoc[j] = loc[j] * strides[j] + beginIndex[j];
- }
- buffer.set.apply(buffer, [x.get.apply(x, newLoc)].concat(loc));
- }
- return buffer.toTensor();
- };
- MathBackendCPU.prototype.reverse = function (x, axis) {
- var buffer = ops.buffer(x.shape, x.dtype);
- var xBuffer = x.buffer();
- var _loop_1 = function (i) {
- var outLoc = buffer.indexToLoc(i);
- var inLoc = outLoc.slice();
- axis.forEach(function (ax) { return inLoc[ax] = x.shape[ax] - 1 - inLoc[ax]; });
- buffer.set.apply(buffer, [xBuffer.get.apply(xBuffer, inLoc)].concat(outLoc));
- };
- for (var i = 0; i < buffer.size; i++) {
- _loop_1(i);
- }
- return buffer.toTensor();
- };
- MathBackendCPU.prototype.concat = function (a, b) {
- var outShape = concat_util.computeOutShape(a.shape, b.shape, 1);
- var buffer = ops.buffer(outShape, a.dtype);
- if (a.shape[0] === 1 && b.shape[0] === 1) {
- var aVals = a.dataSync();
- var bVals = b.dataSync();
- var vals = buffer.values;
- vals.set(aVals, 0);
- vals.set(bVals, a.size);
- return buffer.toTensor();
- }
- for (var i = 0; i < outShape[0]; ++i) {
- for (var j = 0; j < a.shape[1]; ++j) {
- buffer.set(a.get(i, j), i, j);
- }
- for (var j = 0; j < b.shape[1]; ++j) {
- buffer.set(b.get(i, j), i, j + a.shape[1]);
- }
- }
- return buffer.toTensor();
- };
- MathBackendCPU.prototype.neg = function (x) {
- return this.multiply(ops.scalar(-1), x);
- };
- MathBackendCPU.prototype.add = function (a, b) {
- return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue + bValue; });
- };
- MathBackendCPU.prototype.subtract = function (a, b) {
- return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue - bValue; });
- };
- MathBackendCPU.prototype.pow = function (a, b) {
- return this.broadcastedBinaryOp(a, b, a.dtype, function (aValue, bValue) { return Math.pow(aValue, bValue); });
- };
- MathBackendCPU.prototype.matMul = function (a, b, transposeA, transposeB) {
- var sharedDim = transposeA ? a.shape[0] : a.shape[1];
- var leftDim = transposeA ? a.shape[1] : a.shape[0];
- var rightDim = transposeB ? b.shape[0] : b.shape[1];
- var aValues = a.dataSync();
- var bValues = b.dataSync();
- var _a = transposeA ? [1, a.strides[0]] : [a.strides[0], 1], aOuterStep = _a[0], aInnerStep = _a[1];
- var _b = transposeB ? [b.strides[0], 1] : [1, b.strides[0]], bOuterStep = _b[0], bInnerStep = _b[1];
- var aOuterEnd = leftDim * aOuterStep;
- var bOuterEnd = rightDim * bOuterStep;
- var result = new Float32Array(leftDim * rightDim);
- var resultIndex = 0;
- for (var aOuter = 0; aOuter < aOuterEnd; aOuter += aOuterStep) {
- for (var bOuter = 0; bOuter < bOuterEnd; bOuter += bOuterStep) {
- var aInner = aOuter;
- var bInner = bOuter;
- var sum = 0;
- for (var k = 0; k < sharedDim; ++k) {
- sum += aValues[aInner] * bValues[bInner];
- aInner += aInnerStep;
- bInner += bInnerStep;
- }
- result[resultIndex++] = sum;
- }
- }
- return ops.tensor2d(result, [leftDim, rightDim]);
- };
- MathBackendCPU.prototype.multiply = function (a, b) {
- return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue * bValue; });
- };
- MathBackendCPU.prototype.realDivide = function (a, b) {
- var op = function (a, b) { return a / b; };
- var outputDtype = 'float32';
- return this.broadcastedBinaryOp(a, b, outputDtype, op);
- };
- MathBackendCPU.prototype.floorDiv = function (a, b) {
- var op = function (a, b) { return Math.floor(a / b); };
- var outputDtype = 'int32';
- return this.broadcastedBinaryOp(a, b, outputDtype, op);
- };
- MathBackendCPU.prototype.sum = function (x, axes) {
- axis_util.assertAxesAreInnerMostDims('sum', axes, x.rank);
- var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];
- var resultDtype = types.upcastType(x.dtype, 'int32');
- var result = ops.zeros(outShape, resultDtype);
- var reduceSize = util.sizeFromShape(reduceShape);
- var vals = result.dataSync();
- var aVals = x.dataSync();
- for (var i = 0; i < vals.length; ++i) {
- var offset = i * reduceSize;
- var sum = 0;
- for (var j = 0; j < reduceSize; ++j) {
- sum += aVals[offset + j];
- }
- vals[i] = sum;
- }
- return result;
- };
- MathBackendCPU.prototype.unsortedSegmentSum = function (x, segmentIds, numSegments) {
- var res = [];
- var numIters = x.rank - segmentIds.rank;
- for (var i = 0; i < numIters; ++i) {
- segmentIds = segmentIds.expandDims(i + 1);
- }
- for (var i = 0; i < numSegments; ++i) {
- var segmentId = ops.scalar(i, 'int32');
- var mask = ops.equal(segmentId, segmentIds).asType('float32');
- var sum = mask.mul(x).sum(0);
- res.push(sum);
- }
- return ops.stack(res);
- };
- MathBackendCPU.prototype.argMin = function (x, axis) {
- var axes = [axis];
- axis_util.assertAxesAreInnerMostDims('argMin', axes, x.rank);
- var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];
- var result = ops.zeros(outShape, 'int32');
- var reduceSize = util.sizeFromShape(reduceShape);
- var vals = result.dataSync();
- var aVals = x.dataSync();
- for (var i = 0; i < vals.length; ++i) {
- var offset = i * reduceSize;
- var min = aVals[offset];
- var minIndex = 0;
- for (var j = 0; j < reduceSize; ++j) {
- var value = aVals[offset + j];
- if (value < min) {
- min = value;
- minIndex = j;
- }
- }
- vals[i] = minIndex;
- }
- return result;
- };
- MathBackendCPU.prototype.argMax = function (x, axis) {
- var axes = [axis];
- axis_util.assertAxesAreInnerMostDims('argMax', axes, x.rank);
- var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];
- var result = ops.zeros(outShape, 'int32');
- var reduceSize = util.sizeFromShape(reduceShape);
- var vals = result.dataSync();
- var aVals = x.dataSync();
- for (var i = 0; i < vals.length; ++i) {
- var offset = i * reduceSize;
- var max = aVals[offset];
- var maxIndex = 0;
- for (var j = 0; j < reduceSize; ++j) {
- var value = aVals[offset + j];
- if (value > max) {
- max = value;
- maxIndex = j;
- }
- }
- vals[i] = maxIndex;
- }
- return result;
- };
- MathBackendCPU.prototype.cumsum = function (x, axis, exclusive, reverse) {
- if (axis !== x.rank - 1) {
- throw new Error("backend.cumsum in CPU expects an inner-most axis=" + (x.rank - 1) + " " +
- ("but got axis=" + axis));
- }
- var resultDtype = types.upcastType(x.dtype, 'int32');
- var result = ops.zeros(x.shape, resultDtype);
- var vals = result.dataSync();
- var aVals = x.dataSync();
- var finalDim = x.shape[x.rank - 1];
- var indexAdjuster = reverse ?
- function (i, j) { return i + finalDim - j - 1; } :
- function (i, j) { return i + j; };
- for (var i = 0; i < aVals.length; i += finalDim) {
- for (var j = 0; j < finalDim; j++) {
- var idx = indexAdjuster(i, j);
- if (j === 0) {
- vals[idx] = exclusive ? 0 : aVals[idx];
- }
- else {
- var prevIdx = indexAdjuster(i, j - 1);
- vals[idx] = exclusive ? aVals[prevIdx] + vals[prevIdx] :
- aVals[idx] + vals[prevIdx];
- }
- }
- }
- return result;
- };
- MathBackendCPU.prototype.equal = function (a, b) {
- return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {
- return (aVal === bVal) ? 1 : 0;
- });
- };
- MathBackendCPU.prototype.notEqual = function (a, b) {
- return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {
- return (aVal !== bVal) ? 1 : 0;
- });
- };
- MathBackendCPU.prototype.less = function (a, b) {
- return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {
- return (aVal < bVal) ? 1 : 0;
- });
- };
- MathBackendCPU.prototype.lessEqual = function (a, b) {
- return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {
- return (aVal <= bVal) ? 1 : 0;
- });
- };
- MathBackendCPU.prototype.greater = function (a, b) {
- return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {
- return (aVal > bVal) ? 1 : 0;
- });
- };
- MathBackendCPU.prototype.greaterEqual = function (a, b) {
- return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {
- return (aVal >= bVal) ? 1 : 0;
- });
- };
- MathBackendCPU.prototype.logicalNot = function (x) {
- var values = x.dataSync();
- var newValues = new Int32Array(values.length);
- for (var i = 0; i < values.length; ++i) {
- newValues[i] = values[i] ? 0 : 1;
- }
- return tensor_1.Tensor.make(x.shape, { values: newValues }, 'bool');
- };
- MathBackendCPU.prototype.logicalAnd = function (a, b) {
- return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {
- return aVal && bVal;
- });
- };
- MathBackendCPU.prototype.logicalOr = function (a, b) {
- return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {
- return aVal || bVal;
- });
- };
- MathBackendCPU.prototype.where = function (condition, a, b, dtype) {
- var values = condition.dataSync();
- var aValues = a.dataSync();
- var bValues = b.dataSync();
- var result = ops.zeros(a.shape, dtype);
- var newValues = result.dataSync();
- var index = 0;
- var offset = condition.rank === 0 || condition.rank > 1 || a.rank === 1 ?
- 1 :
- a.shape[1];
- for (var i = 0; i < values.length; i++) {
- for (var j = 0; j < offset; j++) {
- if (values[i] === 1) {
- newValues[index++] = aValues[i];
- }
- else {
- newValues[index++] = bValues[i];
- }
- }
- }
- return result;
- };
- MathBackendCPU.prototype.topKValues = function (x, k) {
- return this.topK(x, k).values;
- };
- MathBackendCPU.prototype.topKIndices = function (x, k) {
- return this.topK(x, k).indices;
- };
- MathBackendCPU.prototype.topK = function (x, k) {
- var values = x.dataSync();
- var valuesAndIndices = [];
- for (var i = 0; i < values.length; i++) {
- valuesAndIndices.push({ value: values[i], index: i });
- }
- valuesAndIndices.sort(function (a, b) {
- return b.value - a.value;
- });
- var topkValues = util.getTypedArrayFromDType(x.dtype, k);
- var topkIndices = new Int32Array(k);
- for (var i = 0; i < k; i++) {
- topkValues[i] = valuesAndIndices[i].value;
- topkIndices[i] = valuesAndIndices[i].index;
- }
- return {
- values: ops.tensor1d(topkValues, x.dtype),
- indices: ops.tensor1d(topkIndices, 'int32')
- };
- };
- MathBackendCPU.prototype.min = function (x, axes) {
- axis_util.assertAxesAreInnerMostDims('min', axes, x.rank);
- var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];
- var result = ops.zeros(outShape, x.dtype);
- var reduceSize = util.sizeFromShape(reduceShape);
- var vals = result.dataSync();
- var aVals = x.dataSync();
- for (var i = 0; i < vals.length; ++i) {
- var offset = i * reduceSize;
- var min = aVals[offset];
- for (var j = 0; j < reduceSize; ++j) {
- var value = aVals[offset + j];
- if (value < min) {
- min = value;
- }
- }
- vals[i] = min;
- }
- return result;
- };
- MathBackendCPU.prototype.minimum = function (a, b) {
- return this.broadcastedBinaryOp(a, b, a.dtype, function (aVal, bVal) { return Math.min(aVal, bVal); });
- };
- MathBackendCPU.prototype.mod = function (a, b) {
- return this.broadcastedBinaryOp(a, b, a.dtype, function (aVal, bVal) {
- var rem = aVal % bVal;
- if ((aVal < 0 && bVal < 0) || (aVal >= 0 && bVal >= 0)) {
- return rem;
- }
- else {
- return (rem + bVal) % bVal;
- }
- });
- };
- MathBackendCPU.prototype.max = function (x, axes) {
- axis_util.assertAxesAreInnerMostDims('max', axes, x.rank);
- var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];
- var result = ops.zeros(outShape, x.dtype);
- var reduceSize = util.sizeFromShape(reduceShape);
- var vals = result.dataSync();
- var aVals = x.dataSync();
- for (var i = 0; i < vals.length; ++i) {
- var offset = i * reduceSize;
- var max = aVals[offset];
- for (var j = 0; j < reduceSize; ++j) {
- var value = aVals[offset + j];
- if (value > max) {
- max = value;
- }
- }
- vals[i] = max;
- }
- return result;
- };
- MathBackendCPU.prototype.maximum = function (a, b) {
- return this.broadcastedBinaryOp(a, b, a.dtype, function (aVal, bVal) { return Math.max(aVal, bVal); });
- };
- MathBackendCPU.prototype.all = function (x, axes) {
- axis_util.assertAxesAreInnerMostDims('all', axes, x.rank);
- var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];
- var result = ops.zeros(outShape, x.dtype);
- var reduceSize = util.sizeFromShape(reduceShape);
- var vals = result.dataSync();
- var aVals = x.dataSync();
- for (var i = 0; i < vals.length; ++i) {
- var offset = i * reduceSize;
- var all = aVals[offset];
- for (var j = 0; j < reduceSize; ++j) {
- var value = aVals[offset + j];
- all = all && value;
- }
- vals[i] = all;
- }
- return result;
- };
- MathBackendCPU.prototype.squaredDifference = function (a, b) {
- return this.broadcastedBinaryOp(a, b, a.dtype, function (aVal, bVal) {
- var diff = aVal - bVal;
- return diff * diff;
- });
- };
- MathBackendCPU.prototype.ceil = function (x) {
- var values = x.dataSync();
- var newValues = new Float32Array(values.length);
- for (var i = 0; i < values.length; ++i) {
- newValues[i] = Math.ceil(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: newValues });
- };
- MathBackendCPU.prototype.floor = function (x) {
- var values = x.dataSync();
- var newValues = new Float32Array(values.length);
- for (var i = 0; i < values.length; ++i) {
- newValues[i] = Math.floor(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: newValues });
- };
- MathBackendCPU.prototype.sign = function (x) {
- var values = x.dataSync();
- var newValues = new Float32Array(values.length);
- for (var i = 0; i < values.length; ++i) {
- if (values[i] < 0) {
- newValues[i] = -1;
- }
- else if (values[i] > 0) {
- newValues[i] = 1;
- }
- else {
- newValues[i] = 0;
- }
- }
- return tensor_1.Tensor.make(x.shape, { values: newValues });
- };
- MathBackendCPU.prototype.round = function (x) {
- var values = x.dataSync();
- var newValues = new Float32Array(values.length);
- for (var i = 0; i < values.length; ++i) {
- var base = Math.floor(values[i]);
- if (values[i] - base < 0.5) {
- newValues[i] = Math.floor(values[i]);
- }
- else if (values[i] - base > 0.5) {
- newValues[i] = Math.ceil(values[i]);
- }
- else {
- if (base % 2.0 === 0.0) {
- newValues[i] = base;
- }
- else {
- newValues[i] = base + 1.0;
- }
- }
- }
- return tensor_1.Tensor.make(x.shape, { values: newValues });
- };
- MathBackendCPU.prototype.exp = function (x) {
- var values = x.dataSync();
- var newValues = new Float32Array(values.length);
- for (var i = 0; i < values.length; ++i) {
- newValues[i] = Math.exp(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: newValues });
- };
- MathBackendCPU.prototype.expm1 = function (x) {
- var values = x.dataSync();
- var newValues = new Float32Array(values.length);
- for (var i = 0; i < values.length; ++i) {
- newValues[i] = Math.expm1(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: newValues });
- };
- MathBackendCPU.prototype.log = function (x) {
- var values = x.dataSync();
- var newValues = new Float32Array(values.length);
- for (var i = 0; i < values.length; ++i) {
- var value = values[i];
- newValues[i] = Math.log(value);
- }
- return tensor_1.Tensor.make(x.shape, { values: newValues });
- };
- MathBackendCPU.prototype.log1p = function (x) {
- var values = x.dataSync();
- var newValues = new Float32Array(values.length);
- for (var i = 0; i < values.length; ++i) {
- var value = values[i];
- newValues[i] = Math.log1p(value);
- }
- return tensor_1.Tensor.make(x.shape, { values: newValues });
- };
- MathBackendCPU.prototype.sqrt = function (x) {
- var values = x.dataSync();
- var newValues = new Float32Array(values.length);
- for (var i = 0; i < values.length; ++i) {
- var value = values[i];
- newValues[i] = Math.sqrt(value);
- }
- return tensor_1.Tensor.make(x.shape, { values: newValues });
- };
- MathBackendCPU.prototype.rsqrt = function (x) {
- var values = x.dataSync();
- var newValues = new Float32Array(values.length);
- for (var i = 0; i < values.length; ++i) {
- var value = values[i];
- newValues[i] = 1 / Math.sqrt(value);
- }
- return tensor_1.Tensor.make(x.shape, { values: newValues });
- };
- MathBackendCPU.prototype.square = function (x) {
- var values = x.dataSync();
- var newValues = new Float32Array(values.length);
- for (var i = 0; i < values.length; ++i) {
- var value = values[i];
- newValues[i] = value * value;
- }
- return tensor_1.Tensor.make(x.shape, { values: newValues });
- };
- MathBackendCPU.prototype.reciprocal = function (x) {
- var values = x.dataSync();
- var newValues = new Float32Array(values.length);
- for (var i = 0; i < values.length; ++i) {
- newValues[i] = 1 / values[i];
- }
- return tensor_1.Tensor.make(x.shape, { values: newValues });
- };
- MathBackendCPU.prototype.relu = function (x) {
- var res = ops.zeros(x.shape, x.dtype);
- var resVals = res.dataSync();
- var inVals = x.dataSync();
- for (var i = 0; i < inVals.length; ++i) {
- resVals[i] = Math.max(0, inVals[i]);
- }
- return res;
- };
- MathBackendCPU.prototype.elu = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- var v = values[i];
- if (v >= 0) {
- resultValues[i] = v;
- }
- else {
- resultValues[i] = (Math.exp(v) - 1);
- }
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.eluDer = function (dy, y) {
- var resultValues = new Float32Array(y.size);
- var values = y.dataSync();
- var dyValues = dy.dataSync();
- for (var i = 0; i < values.length; ++i) {
- var v = values[i];
- if (v >= 1) {
- resultValues[i] = dyValues[i];
- }
- else {
- resultValues[i] = dyValues[i] * (v + 1);
- }
- }
- return tensor_1.Tensor.make(y.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.selu = function (x) {
- var scaleAlpha = selu_util.SELU_SCALEALPHA;
- var scale = selu_util.SELU_SCALE;
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- var v = values[i];
- if (v >= 0) {
- resultValues[i] = scale * v;
- }
- else {
- resultValues[i] = scaleAlpha * (Math.exp(v) - 1);
- }
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.clip = function (x, min, max) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = Math.min(max, Math.max(min, values[i]));
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.abs = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = Math.abs(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.int = function (x) {
- var resultValues = new Int32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = values[i];
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues }, 'int32');
- };
- MathBackendCPU.prototype.sigmoid = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = 1 / (1 + Math.exp(-values[i]));
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.softplus = function (x) {
- var epsilon = 1.1920928955078125e-7;
- var threshold = Math.log(epsilon) + 2.0;
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- var tooLarge = values[i] > -threshold;
- var tooSmall = values[i] < threshold;
- var expX = Math.exp(values[i]);
- var result = void 0;
- if (tooSmall) {
- result = expX;
- }
- else if (tooLarge) {
- result = values[i];
- }
- else {
- result = Math.log(1.0 + expX);
- }
- resultValues[i] = result;
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.sin = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = Math.sin(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.cos = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = Math.cos(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.tan = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = Math.tan(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.asin = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = Math.asin(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.acos = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = Math.acos(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.atan = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = Math.atan(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.atan2 = function (a, b) {
- return this.broadcastedBinaryOp(a, b, a.dtype, function (aValue, bValue) { return Math.atan2(aValue, bValue); });
- };
- MathBackendCPU.prototype.sinh = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = Math.sinh(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.cosh = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = Math.cosh(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.tanh = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = util.tanh(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.asinh = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = Math.asinh(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.acosh = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = Math.acosh(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.atanh = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- resultValues[i] = Math.atanh(values[i]);
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.erf = function (x) {
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- var p = erf_util.ERF_P;
- var a1 = erf_util.ERF_A1;
- var a2 = erf_util.ERF_A2;
- var a3 = erf_util.ERF_A3;
- var a4 = erf_util.ERF_A4;
- var a5 = erf_util.ERF_A5;
- for (var i = 0; i < values.length; ++i) {
- var v = values[i];
- var t = 1.0 / (1.0 + p * v);
- resultValues[i] = 1.0 -
- (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t *
- Math.exp(-v * v);
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.step = function (x, alpha) {
- if (alpha === void 0) { alpha = 0; }
- var resultValues = new Float32Array(x.size);
- var values = x.dataSync();
- for (var i = 0; i < values.length; ++i) {
- var value = values[i];
- if (isNaN(value)) {
- resultValues[i] = NaN;
- }
- else {
- resultValues[i] = value > 0 ? 1 : alpha;
- }
- }
- return tensor_1.Tensor.make(x.shape, { values: resultValues });
- };
- MathBackendCPU.prototype.conv2d = function (x, filter, convInfo) {
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var dilationHeight = convInfo.dilationHeight;
- var dilationWidth = convInfo.dilationWidth;
- var padLeft = convInfo.padInfo.left;
- var padTop = convInfo.padInfo.top;
- var y = ops.buffer(convInfo.outShape, x.dtype);
- for (var b = 0; b < convInfo.batchSize; ++b) {
- for (var d2 = 0; d2 < convInfo.outChannels; ++d2) {
- for (var yR = 0; yR < convInfo.outHeight; ++yR) {
- var xRCorner = yR * convInfo.strideHeight - padLeft;
- for (var yC = 0; yC < convInfo.outWidth; ++yC) {
- var xCCorner = yC * convInfo.strideWidth - padTop;
- var dotProd = 0;
- for (var wR = 0; wR < filterHeight; wR++) {
- var xR = xRCorner + wR * dilationHeight;
- if (xR < 0 || xR >= convInfo.inHeight) {
- continue;
- }
- for (var wC = 0; wC < filterWidth; wC++) {
- var xC = xCCorner + wC * dilationWidth;
- if (xC < 0 || xC >= convInfo.inWidth) {
- continue;
- }
- for (var d1 = 0; d1 < convInfo.inChannels; ++d1) {
- var pixel = x.get(b, xR, xC, d1);
- var weight = filter.get(wR, wC, d1, d2);
- dotProd += pixel * weight;
- }
- }
- }
- y.set(dotProd, b, yR, yC, d2);
- }
- }
- }
- }
- return y.toTensor();
- };
- MathBackendCPU.prototype.conv2dDerInput = function (dy, filter, convInfo) {
- var dx = ops.buffer(convInfo.inShape, 'float32');
- var dxValues = dx.values;
- var _a = dx.strides, dxS0 = _a[0], dxS1 = _a[1], dxS2 = _a[2];
- var dyValues = dy.dataSync();
- var _b = dy.strides, dyS0 = _b[0], dyS1 = _b[1], dyS2 = _b[2];
- var fltValues = filter.dataSync();
- var _c = filter.strides, fltS0 = _c[0], fltS1 = _c[1], fltS2 = _c[2];
- var batchSize = convInfo.batchSize, filterHeight = convInfo.filterHeight, filterWidth = convInfo.filterWidth, inChannels = convInfo.inChannels, inHeight = convInfo.inHeight, inWidth = convInfo.inWidth, outChannels = convInfo.outChannels, outHeight = convInfo.outHeight, outWidth = convInfo.outWidth, strideHeight = convInfo.strideHeight, strideWidth = convInfo.strideWidth;
- var topPad = filterHeight - 1 - convInfo.padInfo.top;
- var leftPad = filterWidth - 1 - convInfo.padInfo.left;
- for (var b = 0; b < batchSize; ++b) {
- for (var d1 = 0; d1 < inChannels; ++d1) {
- for (var xR = 0; xR < inHeight; ++xR) {
- var xRCorner = xR - topPad;
- var xRMin = Math.max(0, Math.ceil(xRCorner / strideHeight));
- var yRMax = Math.min(outHeight, (filterHeight + xRCorner) / strideHeight);
- for (var xC = 0; xC < inWidth; ++xC) {
- var xCCorner = xC - leftPad;
- var xCMin = Math.max(0, Math.ceil(xCCorner / strideWidth));
- var yCMax = Math.min(outWidth, (filterWidth + xCCorner) / strideWidth);
- var dotProd = 0;
- for (var yR = xRMin; yR < yRMax; ++yR) {
- var wR = yR * strideHeight - xRCorner;
- for (var yC = xCMin; yC < yCMax; ++yC) {
- var wC = yC * strideWidth - xCCorner;
- var dyOffset = dyS0 * b + dyS1 * yR + dyS2 * yC;
- var fltOffset = fltS0 * (filterHeight - 1 - wR) +
- fltS1 * (filterWidth - 1 - wC) + fltS2 * d1;
- for (var d2 = 0; d2 < outChannels; ++d2) {
- var pixel = dyValues[dyOffset + d2];
- var weight = fltValues[fltOffset + d2];
- dotProd += pixel * weight;
- }
- }
- }
- dxValues[dxS0 * b + dxS1 * xR + dxS2 * xC + d1] = dotProd;
- }
- }
- }
- }
- return dx.toTensor();
- };
- MathBackendCPU.prototype.conv2dDerFilter = function (x, dy, convInfo) {
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var dW = ops.buffer(convInfo.filterShape, 'float32');
- var leftPad = convInfo.padInfo.left;
- var topPad = convInfo.padInfo.top;
- for (var wR = 0; wR < filterHeight; ++wR) {
- var yRMin = Math.max(0, Math.ceil((topPad - wR) / strideHeight));
- var yRMax = Math.min(convInfo.outHeight, (convInfo.inHeight + topPad - wR) / strideHeight);
- for (var wC = 0; wC < filterWidth; ++wC) {
- var yCMin = Math.max(0, Math.ceil((leftPad - wC) / strideWidth));
- var yCMax = Math.min(convInfo.outWidth, (convInfo.inWidth + leftPad - wC) / strideWidth);
- for (var d1 = 0; d1 < convInfo.inChannels; ++d1) {
- for (var d2 = 0; d2 < convInfo.outChannels; ++d2) {
- var dotProd = 0;
- for (var b = 0; b < convInfo.batchSize; ++b) {
- for (var yR = yRMin; yR < yRMax; ++yR) {
- var xR = wR + yR * strideHeight - topPad;
- for (var yC = yCMin; yC < yCMax; ++yC) {
- var xC = wC + yC * strideWidth - leftPad;
- dotProd += x.get(b, xR, xC, d1) * dy.get(b, yR, yC, d2);
- }
- }
- }
- dW.set(dotProd, wR, wC, d1, d2);
- }
- }
- }
- }
- return dW.toTensor();
- };
- MathBackendCPU.prototype.depthwiseConv2D = function (x, filter, convInfo) {
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var dilationHeight = convInfo.dilationHeight;
- var dilationWidth = convInfo.dilationWidth;
- var padLeft = convInfo.padInfo.left;
- var padTop = convInfo.padInfo.top;
- var chMul = convInfo.outChannels / convInfo.inChannels;
- var y = ops.buffer(convInfo.outShape, x.dtype);
- for (var b = 0; b < convInfo.batchSize; ++b) {
- for (var d1 = 0; d1 < convInfo.inChannels; ++d1) {
- for (var yR = 0; yR < convInfo.outHeight; ++yR) {
- var xRCorner = yR * convInfo.strideHeight - padLeft;
- for (var yC = 0; yC < convInfo.outWidth; ++yC) {
- var xCCorner = yC * convInfo.strideWidth - padTop;
- for (var q = 0; q < chMul; ++q) {
- var dotProd = 0;
- for (var wR = 0; wR < filterHeight; ++wR) {
- var xR = xRCorner + wR * dilationHeight;
- if (xR < 0 || xR >= convInfo.inHeight) {
- continue;
- }
- for (var wC = 0; wC < filterWidth; ++wC) {
- var xC = xCCorner + wC * dilationWidth;
- if (xC < 0 || xC >= convInfo.inWidth) {
- continue;
- }
- var pixel = x.get(b, xR, xC, d1);
- var weight = filter.get(wR, wC, d1, q);
- dotProd += pixel * weight;
- }
- }
- y.set(dotProd, b, yR, yC, d1 * chMul + q);
- }
- }
- }
- }
- }
- return y.toTensor();
- };
- MathBackendCPU.prototype.depthwiseConv2DDerInput = function (dy, filter, convInfo) {
- var dx = ops.buffer(convInfo.inShape, 'float32');
- var dxValues = dx.values;
- var _a = dx.strides, dxS0 = _a[0], dxS1 = _a[1], dxS2 = _a[2];
- var dyValues = dy.dataSync();
- var _b = dy.strides, dyS0 = _b[0], dyS1 = _b[1], dyS2 = _b[2];
- var fltValues = filter.dataSync();
- var _c = filter.strides, fltS0 = _c[0], fltS1 = _c[1], fltS2 = _c[2];
- var batchSize = convInfo.batchSize, filterHeight = convInfo.filterHeight, filterWidth = convInfo.filterWidth, inChannels = convInfo.inChannels, inHeight = convInfo.inHeight, inWidth = convInfo.inWidth, outChannels = convInfo.outChannels, outHeight = convInfo.outHeight, outWidth = convInfo.outWidth, strideHeight = convInfo.strideHeight, strideWidth = convInfo.strideWidth;
- var topPad = filterHeight - 1 - convInfo.padInfo.top;
- var leftPad = filterWidth - 1 - convInfo.padInfo.left;
- var chMul = outChannels / inChannels;
- for (var b = 0; b < batchSize; ++b) {
- for (var d1 = 0; d1 < inChannels; ++d1) {
- for (var xR = 0; xR < inHeight; ++xR) {
- var xRCorner = xR - topPad;
- var xRMin = Math.max(0, Math.ceil(xRCorner / strideHeight));
- var yRMax = Math.min(outHeight, (filterHeight + xRCorner) / strideHeight);
- for (var xC = 0; xC < inWidth; ++xC) {
- var xCCorner = xC - leftPad;
- var xCMin = Math.max(0, Math.ceil(xCCorner / strideWidth));
- var yCMax = Math.min(outWidth, (filterWidth + xCCorner) / strideWidth);
- var dotProd = 0;
- for (var yR = xRMin; yR < yRMax; ++yR) {
- var wR = yR * strideHeight - xRCorner;
- for (var yC = xCMin; yC < yCMax; ++yC) {
- var wC = yC * strideWidth - xCCorner;
- var dyOffset = dyS0 * b + dyS1 * yR + dyS2 * yC;
- var fltOffset = fltS0 * (filterHeight - 1 - wR) +
- fltS1 * (filterWidth - 1 - wC) + fltS2 * d1;
- for (var dm = 0; dm < chMul; ++dm) {
- var d2 = d1 * chMul + dm;
- var pixel = dyValues[dyOffset + d2];
- var weight = fltValues[fltOffset + dm];
- dotProd += pixel * weight;
- }
- }
- }
- dxValues[dxS0 * b + dxS1 * xR + dxS2 * xC + d1] = dotProd;
- }
- }
- }
- }
- return dx.toTensor();
- };
- MathBackendCPU.prototype.depthwiseConv2DDerFilter = function (x, dy, convInfo) {
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var dW = ops.buffer(convInfo.filterShape, 'float32');
- var leftPad = convInfo.padInfo.left;
- var topPad = convInfo.padInfo.top;
- var chMul = convInfo.outChannels / convInfo.inChannels;
- for (var wR = 0; wR < filterHeight; ++wR) {
- var yRMin = Math.max(0, Math.ceil((topPad - wR) / strideHeight));
- var yRMax = Math.min(convInfo.outHeight, (convInfo.inHeight + topPad - wR) / strideHeight);
- for (var wC = 0; wC < filterWidth; ++wC) {
- var yCMin = Math.max(0, Math.ceil((leftPad - wC) / strideWidth));
- var yCMax = Math.min(convInfo.outWidth, (convInfo.inWidth + leftPad - wC) / strideWidth);
- for (var d2 = 0; d2 < convInfo.outChannels; ++d2) {
- var d1 = Math.trunc(d2 / chMul);
- var dm = d2 % chMul;
- var dotProd = 0;
- for (var b = 0; b < convInfo.batchSize; ++b) {
- for (var yR = yRMin; yR < yRMax; ++yR) {
- var xR = wR + yR * strideHeight - topPad;
- for (var yC = yCMin; yC < yCMax; ++yC) {
- var xC = wC + yC * strideWidth - leftPad;
- dotProd += x.get(b, xR, xC, d1) * dy.get(b, yR, yC, d2);
- }
- }
- }
- dW.set(dotProd, wR, wC, d1, dm);
- }
- }
- }
- return dW.toTensor();
- };
- MathBackendCPU.prototype.tile = function (x, reps) {
- var newShape = new Array(x.rank);
- for (var i = 0; i < newShape.length; i++) {
- newShape[i] = x.shape[i] * reps[i];
- }
- var result = ops.buffer(newShape, x.dtype);
- var xBuf = x.buffer();
- for (var i = 0; i < result.values.length; ++i) {
- var newLoc = result.indexToLoc(i);
- var originalLoc = new Array(x.rank);
- for (var i_1 = 0; i_1 < originalLoc.length; i_1++) {
- originalLoc[i_1] = newLoc[i_1] % x.shape[i_1];
- }
- var originalIndex = xBuf.locToIndex(originalLoc);
- result.values[i] = xBuf.values[originalIndex];
- }
- return result.toTensor();
- };
- MathBackendCPU.prototype.pad = function (x, paddings, constantValue) {
- var outShape = paddings.map(function (p, i) { return p[0] + x.shape[i] + p[1]; });
- var start = paddings.map(function (p) { return p[0]; });
- var xBuffer = x.buffer();
- var buffer = ops.buffer(outShape, x.dtype);
- if (constantValue !== 0) {
- buffer.values.fill(constantValue);
- }
- for (var i = 0; i < x.size; i++) {
- var coords = xBuffer.indexToLoc(i);
- var outCoords = coords.map(function (c, i) { return c + start[i]; });
- buffer.set.apply(buffer, [x.get.apply(x, coords)].concat(outCoords));
- }
- return buffer.toTensor();
- };
- MathBackendCPU.prototype.transpose = function (x, perm) {
- var newShape = new Array(x.rank);
- for (var i = 0; i < newShape.length; i++) {
- newShape[i] = x.shape[perm[i]];
- }
- var values = x.dataSync();
- var result = ops_1.buffer(newShape, x.dtype);
- var xBuf = x.buffer();
- for (var i = 0; i < x.size; ++i) {
- var loc = xBuf.indexToLoc(i);
- var newLoc = new Array(loc.length);
- for (var i_2 = 0; i_2 < newLoc.length; i_2++) {
- newLoc[i_2] = loc[perm[i_2]];
- }
- var newIndex = result.locToIndex(newLoc);
- result.values[newIndex] = values[i];
- }
- return result.toTensor();
- };
- MathBackendCPU.prototype.gather = function (x, indices, axis) {
- var newShape = x.shape.slice();
- var indicesValues = indices.dataSync();
- newShape[axis] = indicesValues.length;
- var result = ops_1.buffer(newShape, x.dtype);
- var xBuf = x.buffer();
- for (var i = 0; i < result.size; ++i) {
- var newLoc = result.indexToLoc(i);
- var originalLoc = newLoc.slice();
- originalLoc[axis] = indicesValues[newLoc[axis]];
- var originalIndex = xBuf.locToIndex(originalLoc);
- result.values[i] = xBuf.values[originalIndex];
- }
- return result.toTensor();
- };
- MathBackendCPU.prototype.pool = function (x, convInfo, poolType) {
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var y = ops.buffer(convInfo.outShape, 'float32');
- var padTop = convInfo.padInfo.top;
- var padLeft = convInfo.padInfo.left;
- for (var b = 0; b < convInfo.batchSize; ++b) {
- for (var d = 0; d < convInfo.inChannels; ++d) {
- for (var yR = 0; yR < convInfo.outHeight; ++yR) {
- var xRCorner = yR * strideHeight - padTop;
- var xRMin = Math.max(0, xRCorner);
- var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner);
- for (var yC = 0; yC < convInfo.outWidth; ++yC) {
- var xCCorner = yC * strideWidth - padLeft;
- var xCMin = Math.max(0, xCCorner);
- var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner);
- var minMaxValue = (poolType === 'max' ? Number.NEGATIVE_INFINITY :
- Number.POSITIVE_INFINITY);
- var avgValue = 0;
- var count = 0;
- for (var xR = xRMin; xR < xRMax; ++xR) {
- for (var xC = xCMin; xC < xCMax; ++xC) {
- var pixel = x.get(b, xR, xC, d);
- if ((poolType === 'max' && pixel > minMaxValue)) {
- minMaxValue = pixel;
- }
- else if (poolType === 'avg') {
- avgValue += pixel;
- count++;
- }
- }
- if (isNaN(minMaxValue)) {
- break;
- }
- }
- y.set(poolType === 'avg' ? avgValue / count : minMaxValue, b, yR, yC, d);
- }
- }
- }
- }
- return y.toTensor();
- };
- MathBackendCPU.prototype.maxPool = function (x, convInfo) {
- return this.pool(x, convInfo, 'max');
- };
- MathBackendCPU.prototype.maxPoolPositions = function (x, convInfo) {
- var maxPositions = ops.buffer(convInfo.outShape, 'int32');
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var padTop = convInfo.padInfo.top;
- var padLeft = convInfo.padInfo.left;
- for (var b = 0; b < convInfo.batchSize; ++b) {
- for (var d = 0; d < convInfo.inChannels; ++d) {
- for (var yR = 0; yR < convInfo.outHeight; ++yR) {
- var xRCorner = yR * strideHeight - padTop;
- var xRMin = Math.max(0, xRCorner);
- var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner);
- for (var yC = 0; yC < convInfo.outWidth; ++yC) {
- var xCCorner = yC * strideWidth - padLeft;
- var xCMin = Math.max(0, xCCorner);
- var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner);
- var maxValue = Number.NEGATIVE_INFINITY;
- var maxPosition = -1;
- for (var xR = xRMin; xR < xRMax; ++xR) {
- var wR = xR - xRCorner;
- for (var xC = xCMin; xC < xCMax; ++xC) {
- var wC = xC - xCCorner;
- var pixel = x.get(b, xR, xC, d);
- if (pixel > maxValue) {
- maxValue = pixel;
- maxPosition = wR * filterWidth + wC;
- }
- }
- }
- maxPositions.set(maxPosition, b, yR, yC, d);
- }
- }
- }
- }
- return maxPositions.toTensor();
- };
- MathBackendCPU.prototype.maxPoolBackprop = function (dy, x, y, convInfo) {
- var maxPositions = this.maxPoolPositions(x, convInfo);
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var padLeft = filterWidth - 1 - convInfo.padInfo.left;
- var padTop = filterHeight - 1 - convInfo.padInfo.top;
- var dx = ops.buffer(x.shape, 'float32');
- for (var b = 0; b < convInfo.batchSize; ++b) {
- for (var d = 0; d < convInfo.inChannels; ++d) {
- for (var dxR = 0; dxR < convInfo.inHeight; ++dxR) {
- for (var dxC = 0; dxC < convInfo.inWidth; ++dxC) {
- var dyRCorner = dxR - padTop;
- var dyCCorner = dxC - padLeft;
- var dotProd = 0;
- for (var wR = 0; wR < filterHeight; ++wR) {
- var dyR = (dyRCorner + wR) / strideHeight;
- if (dyR < 0 || dyR >= convInfo.outHeight ||
- Math.floor(dyR) !== dyR) {
- continue;
- }
- for (var wC = 0; wC < filterWidth; ++wC) {
- var dyC = (dyCCorner + wC) / strideWidth;
- if (dyC < 0 || dyC >= convInfo.outWidth ||
- Math.floor(dyC) !== dyC) {
- continue;
- }
- var maxPos = filterHeight * filterWidth - 1 -
- maxPositions.get(b, dyR, dyC, d);
- var curPos = wR * filterWidth + wC;
- var mask = maxPos === curPos ? 1 : 0;
- if (mask === 0) {
- continue;
- }
- var pixel = dy.get(b, dyR, dyC, d);
- dotProd += pixel * mask;
- }
- }
- dx.set(dotProd, b, dxR, dxC, d);
- }
- }
- }
- }
- return dx.toTensor();
- };
- MathBackendCPU.prototype.avgPoolBackprop = function (dy, x, convInfo) {
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var padLeft = filterWidth - 1 - convInfo.padInfo.left;
- var padTop = filterHeight - 1 - convInfo.padInfo.top;
- var dx = ops.buffer(x.shape, 'float32');
- var avgMultiplier = 1 / (filterHeight * filterWidth);
- for (var b = 0; b < convInfo.batchSize; ++b) {
- for (var d = 0; d < convInfo.inChannels; ++d) {
- for (var dxR = 0; dxR < convInfo.inHeight; ++dxR) {
- for (var dxC = 0; dxC < convInfo.inWidth; ++dxC) {
- var dyRCorner = dxR - padTop;
- var dyCCorner = dxC - padLeft;
- var dotProd = 0;
- for (var wR = 0; wR < filterHeight; ++wR) {
- var dyR = (dyRCorner + wR) / strideHeight;
- if (dyR < 0 || dyR >= convInfo.outHeight ||
- Math.floor(dyR) !== dyR) {
- continue;
- }
- for (var wC = 0; wC < filterWidth; ++wC) {
- var dyC = (dyCCorner + wC) / strideWidth;
- if (dyC < 0 || dyC >= convInfo.outWidth ||
- Math.floor(dyC) !== dyC) {
- continue;
- }
- var pixel = dy.get(b, dyR, dyC, d);
- dotProd += pixel;
- }
- }
- dx.set(dotProd * avgMultiplier, b, dxR, dxC, d);
- }
- }
- }
- }
- return dx.toTensor();
- };
- MathBackendCPU.prototype.cast = function (x, dtype) {
- return backend_util.castTensor(x, dtype, this);
- };
- MathBackendCPU.prototype.reshape = function (x, shape) {
- return backend_util.reshapeTensor(x, shape);
- };
- MathBackendCPU.prototype.avgPool = function (x, convInfo) {
- return this.pool(x, convInfo, 'avg').toFloat();
- };
- MathBackendCPU.prototype.resizeBilinear = function (x, newHeight, newWidth, alignCorners) {
- var _a = x.shape, batch = _a[0], oldHeight = _a[1], oldWidth = _a[2], numChannels = _a[3];
- var output = ops.buffer([batch, newHeight, newWidth, numChannels], x.dtype);
- var effectiveInputSize = [
- (alignCorners && newHeight > 1) ? oldHeight - 1 : oldHeight,
- (alignCorners && newWidth > 1) ? oldWidth - 1 : oldWidth
- ];
- var effectiveOutputSize = [
- (alignCorners && newHeight > 1) ? newHeight - 1 : newHeight,
- (alignCorners && newWidth > 1) ? newWidth - 1 : newWidth
- ];
- for (var b = 0; b < batch; b++) {
- for (var r = 0; r < newHeight; r++) {
- for (var c = 0; c < newWidth; c++) {
- for (var d = 0; d < numChannels; d++) {
- var sourceFracRow = (effectiveInputSize[0]) * r / (effectiveOutputSize[0]);
- var sourceFracCol = (effectiveInputSize[1]) * c / (effectiveOutputSize[1]);
- var sourceRowFloor = Math.floor(sourceFracRow);
- var sourceRowCeil = Math.min(oldHeight - 1, Math.ceil(sourceFracRow));
- var sourceColFloor = Math.floor(sourceFracCol);
- var sourceColCeil = Math.min(oldWidth - 1, Math.ceil(sourceFracCol));
- var topLeft = x.get(b, sourceRowFloor, sourceColFloor, d);
- var bottomLeft = x.get(b, sourceRowCeil, sourceColFloor, d);
- var topRight = x.get(b, sourceRowFloor, sourceColCeil, d);
- var bottomRight = x.get(b, sourceRowCeil, sourceColCeil, d);
- var rowFrac = sourceFracRow - sourceRowFloor;
- var colFrac = sourceFracCol - sourceColFloor;
- var top_1 = topLeft + (topRight - topLeft) * colFrac;
- var bottom = bottomLeft + (bottomRight - bottomLeft) * colFrac;
- var newValue = top_1 + (bottom - top_1) * rowFrac;
- output.set(newValue, b, r, c, d);
- }
- }
- }
- }
- return output.toTensor();
- };
- MathBackendCPU.prototype.resizeBilinearBackprop = function (dy, x, alignCorners) {
- var _a = x.shape, batch = _a[0], xHeight = _a[1], xWidth = _a[2], depth = _a[3];
- var _b = dy.shape, yHeight = _b[1], yWidth = _b[2];
- var output = ops.buffer([batch, xHeight, xWidth, depth], x.dtype);
- var effectiveXSize = [
- (alignCorners && yHeight > 1) ? xHeight - 1 : xHeight,
- (alignCorners && yWidth > 1) ? xWidth - 1 : xWidth
- ];
- var effectiveYSize = [
- (alignCorners && yHeight > 1) ? yHeight - 1 : yHeight,
- (alignCorners && yWidth > 1) ? yWidth - 1 : yWidth
- ];
- var heightScale = effectiveXSize[0] / effectiveYSize[0];
- var widthScale = effectiveXSize[1] / effectiveYSize[1];
- for (var b = 0; b < batch; b++) {
- for (var r = 0; r < yHeight; r++) {
- var dxR = r * heightScale;
- var topDxRIndex = Math.floor(dxR);
- var bottomDxRIndex = Math.min(Math.ceil(dxR), xHeight - 1);
- var dxRLerp = dxR - topDxRIndex;
- var inverseDxRLerp = 1.0 - dxRLerp;
- for (var c = 0; c < yWidth; c++) {
- var dxC = c * widthScale;
- var leftDxCIndex = Math.floor(dxC);
- var rightDxCIndex = Math.min(Math.ceil(dxC), xWidth - 1);
- var dxCLerp = dxC - leftDxCIndex;
- var inverseDxCLerp = 1.0 - dxCLerp;
- for (var d = 0; d < depth; d++) {
- var dyVal = dy.get(b, r, c, d);
- var topLeft = output.get(b, topDxRIndex, leftDxCIndex, d);
- topLeft += dyVal * inverseDxRLerp * inverseDxCLerp;
- output.set(topLeft, b, topDxRIndex, leftDxCIndex, d);
- var topRight = output.get(b, topDxRIndex, rightDxCIndex, d);
- topRight += dyVal * inverseDxRLerp * dxCLerp;
- output.set(topRight, b, topDxRIndex, rightDxCIndex, d);
- var bottomLeft = output.get(b, bottomDxRIndex, leftDxCIndex, d);
- bottomLeft += dyVal * dxRLerp * inverseDxCLerp;
- output.set(bottomLeft, b, bottomDxRIndex, leftDxCIndex, d);
- var bottomRight = output.get(b, bottomDxRIndex, rightDxCIndex, d);
- bottomRight += dyVal * dxRLerp * dxCLerp;
- output.set(bottomRight, b, bottomDxRIndex, rightDxCIndex, d);
- }
- }
- }
- }
- return output.toTensor();
- };
- MathBackendCPU.prototype.resizeNearestNeighbor = function (x, newHeight, newWidth, alignCorners) {
- var _a = x.shape, batch = _a[0], oldHeight = _a[1], oldWidth = _a[2], numChannels = _a[3];
- var output = ops.buffer([batch, newHeight, newWidth, numChannels], x.dtype);
- var effectiveInputSize = alignCorners ? [oldHeight - 1, oldWidth - 1] : [oldHeight, oldWidth];
- var effectiveOutputSize = alignCorners ? [newHeight - 1, newWidth - 1] : [newHeight, newWidth];
- for (var b = 0; b < batch; b++) {
- for (var r = 0; r < newHeight; r++) {
- for (var c = 0; c < newWidth; c++) {
- for (var d = 0; d < numChannels; d++) {
- var sourceFracRow = (effectiveInputSize[0]) * r / (effectiveOutputSize[0]);
- var sourceFracCol = (effectiveInputSize[1]) * c / (effectiveOutputSize[1]);
- var sourceNearestRow = Math.min(oldHeight - 1, alignCorners ? Math.round(sourceFracRow) :
- Math.floor(sourceFracRow));
- var sourceNearestCol = Math.min(oldWidth - 1, alignCorners ? Math.round(sourceFracCol) :
- Math.floor(sourceFracCol));
- var newValue = x.get(b, sourceNearestRow, sourceNearestCol, d);
- output.set(newValue, b, r, c, d);
- }
- }
- }
- }
- return output.toTensor();
- };
- MathBackendCPU.prototype.batchNormalization = function (x, mean, variance, varianceEpsilon, scale, offset) {
- var xValues = x.dataSync();
- var meanValues = mean.dataSync();
- var varianceValues = variance.dataSync();
- var scaleValues = scale ? scale.dataSync() : new Float32Array([1]);
- var offsetValues = offset ? offset.dataSync() : new Float32Array([0]);
- var outValues = new Float32Array(xValues.length);
- for (var i = 0; i < xValues.length; i++) {
- outValues[i] = offsetValues[i % offsetValues.length] +
- (xValues[i] - meanValues[i % meanValues.length]) *
- scaleValues[i % scaleValues.length] /
- Math.sqrt(varianceValues[i % varianceValues.length] + varianceEpsilon);
- }
- return ops_1.tensor4d(outValues, x.shape);
- };
- MathBackendCPU.prototype.localResponseNormalization4D = function (x, radius, bias, alpha, beta) {
- var output = ops.buffer(x.shape, 'float32');
- var rad = radius;
- var maxD = output.shape[3] - 1;
- function sumAcrossChannels(b, r, c, d) {
- var sum = 0.0;
- for (var j = Math.max(0, d - rad); j <= Math.min(d + rad, maxD); j++) {
- var z = x.get(b, r, c, j);
- sum += z * z;
- }
- return sum;
- }
- for (var b = 0; b < output.shape[0]; b++) {
- for (var r = 0; r <= output.shape[1]; r++) {
- for (var c = 0; c < output.shape[2]; c++) {
- for (var d = 0; d < output.shape[3]; d++) {
- var sum = sumAcrossChannels(b, r, c, d);
- var val = x.get(b, r, c, d) * Math.pow(bias + alpha * sum, -beta);
- output.set(val, b, r, c, d);
- }
- }
- }
- }
- return output.toTensor();
- };
- MathBackendCPU.prototype.multinomial = function (logits, normalized, numSamples, seed) {
- var probabilities = normalized ? logits : ops.softmax(logits);
- var batchSize = probabilities.shape[0];
- var numEvents = probabilities.shape[1];
- var res = ops.zeros([batchSize, numSamples], 'int32');
- var resVals = res.dataSync();
- var probVals = probabilities.dataSync();
- for (var b = 0; b < batchSize; ++b) {
- var offset = b * numEvents;
- var cdf = new Float32Array(numEvents - 1);
- cdf[0] = probVals[offset];
- for (var event_1 = 1; event_1 < cdf.length; ++event_1) {
- cdf[event_1] = cdf[event_1 - 1] + probVals[offset + event_1];
- }
- var random = seedrandom.alea(seed.toString());
- var outOffset = b * numSamples;
- for (var sampleId = 0; sampleId < numSamples; ++sampleId) {
- var r = random();
- resVals[outOffset + sampleId] = cdf.length;
- for (var event_2 = 0; event_2 < cdf.length; event_2++) {
- if (r < cdf[event_2]) {
- resVals[outOffset + sampleId] = event_2;
- break;
- }
- }
- }
- }
- return res;
- };
- MathBackendCPU.prototype.oneHot = function (indices, depth, onValue, offValue) {
- var res = new Float32Array(indices.size * depth);
- res.fill(offValue);
- for (var event_3 = 0; event_3 < indices.size; ++event_3) {
- if (indices.get(event_3) >= 0 && indices.get(event_3) < depth) {
- res[event_3 * depth + indices.get(event_3)] = onValue;
- }
- }
- return ops.tensor2d(res, [indices.size, depth], 'int32');
- };
- MathBackendCPU.prototype.broadcastedBinaryOp = function (a, b, dtype, op) {
- var newShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- var result = ops.buffer(newShape, dtype);
- var aValues = a.dataSync();
- var bValues = b.dataSync();
- var aBroadcastDims = broadcast_util.getBroadcastDims(a.shape, newShape);
- var bBroadcastDims = broadcast_util.getBroadcastDims(b.shape, newShape);
- var aBuf = a.buffer();
- var bBuf = b.buffer();
- var _loop_2 = function (i) {
- var loc = result.indexToLoc(i);
- var aLoc = loc.slice(-a.rank);
- aBroadcastDims.forEach(function (d) { return aLoc[d] = 0; });
- var aIndex = aBuf.locToIndex(aLoc);
- var bLoc = loc.slice(-b.rank);
- bBroadcastDims.forEach(function (d) { return bLoc[d] = 0; });
- var bIndex = bBuf.locToIndex(bLoc);
- result.values[i] = op(aValues[aIndex], bValues[bIndex]);
- };
- for (var i = 0; i < result.values.length; ++i) {
- _loop_2(i);
- }
- return result.toTensor();
- };
- MathBackendCPU.prototype.dispose = function () { };
- return MathBackendCPU;
- }());
- exports.MathBackendCPU = MathBackendCPU;
- environment_1.ENV.registerBackend('cpu', function () { return new MathBackendCPU(); }, 1);
- },{"../environment":51,"../ops/axis_util":109,"../ops/broadcast_util":112,"../ops/concat_util":115,"../ops/erf_util":118,"../ops/ops":129,"../ops/selu_util":137,"../ops/slice_util":140,"../tensor":158,"../types":163,"../util":164,"./backend_util":66,"seedrandom":231}],66:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var __1 = require("..");
- var array_ops_1 = require("../ops/array_ops");
- function castTensor(x, dtype, backend) {
- if (!__1.util.hasEncodingLoss(x.dtype, dtype)) {
- return __1.Tensor.make(x.shape, { dataId: x.dataId }, dtype);
- }
- if (dtype === 'int32') {
- return backend.int(x);
- }
- else if (dtype === 'bool') {
- return backend.notEqual(x, array_ops_1.ArrayOps.scalar(0, x.dtype));
- }
- else {
- throw new Error("Error in Cast: unknown dtype argument (" + dtype + ")");
- }
- }
- exports.castTensor = castTensor;
- function reshapeTensor(x, shape) {
- return __1.Tensor.make(shape, { dataId: x.dataId }, x.dtype);
- }
- exports.reshapeTensor = reshapeTensor;
- },{"..":54,"../ops/array_ops":108}],67:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../environment");
- var axis_util = require("../ops/axis_util");
- var ops = require("../ops/ops");
- var reduce_util = require("../ops/reduce_util");
- var segment_util = require("../ops/segment_util");
- var slice_util_1 = require("../ops/slice_util");
- var tensor_1 = require("../tensor");
- var types = require("../types");
- var util = require("../util");
- var backend_util = require("./backend_util");
- var argminmax_gpu_1 = require("./webgl/argminmax_gpu");
- var avg_pool_backprop_gpu_1 = require("./webgl/avg_pool_backprop_gpu");
- var batchnorm_gpu_1 = require("./webgl/batchnorm_gpu");
- var binaryop_gpu = require("./webgl/binaryop_gpu");
- var binaryop_gpu_1 = require("./webgl/binaryop_gpu");
- var clip_gpu_1 = require("./webgl/clip_gpu");
- var concat_gpu_1 = require("./webgl/concat_gpu");
- var conv_backprop_gpu_1 = require("./webgl/conv_backprop_gpu");
- var conv_backprop_gpu_depthwise_1 = require("./webgl/conv_backprop_gpu_depthwise");
- var conv_gpu_1 = require("./webgl/conv_gpu");
- var conv_gpu_depthwise_1 = require("./webgl/conv_gpu_depthwise");
- var cumsum_gpu_1 = require("./webgl/cumsum_gpu");
- var encode_float_gpu_1 = require("./webgl/encode_float_gpu");
- var from_pixels_gpu_1 = require("./webgl/from_pixels_gpu");
- var gather_gpu_1 = require("./webgl/gather_gpu");
- var gpgpu_context_1 = require("./webgl/gpgpu_context");
- var gpgpu_math = require("./webgl/gpgpu_math");
- var gpgpu_util = require("./webgl/gpgpu_util");
- var logical_gpu_1 = require("./webgl/logical_gpu");
- var lrn_gpu_1 = require("./webgl/lrn_gpu");
- var max_pool_backprop_gpu_1 = require("./webgl/max_pool_backprop_gpu");
- var mulmat_gpu_1 = require("./webgl/mulmat_gpu");
- var multinomial_gpu_1 = require("./webgl/multinomial_gpu");
- var onehot_gpu_1 = require("./webgl/onehot_gpu");
- var pad_gpu_1 = require("./webgl/pad_gpu");
- var pool_gpu_1 = require("./webgl/pool_gpu");
- var reduce_gpu_1 = require("./webgl/reduce_gpu");
- var resize_bilinear_backprop_gpu_1 = require("./webgl/resize_bilinear_backprop_gpu");
- var resize_bilinear_gpu_1 = require("./webgl/resize_bilinear_gpu");
- var resize_nearest_neighbor_gpu_1 = require("./webgl/resize_nearest_neighbor_gpu");
- var reverse_gpu_1 = require("./webgl/reverse_gpu");
- var segment_gpu_1 = require("./webgl/segment_gpu");
- var slice_gpu_1 = require("./webgl/slice_gpu");
- var strided_slice_gpu_1 = require("./webgl/strided_slice_gpu");
- var tex_util_1 = require("./webgl/tex_util");
- var texture_manager_1 = require("./webgl/texture_manager");
- var tile_gpu_1 = require("./webgl/tile_gpu");
- var transpose_gpu_1 = require("./webgl/transpose_gpu");
- var unary_op = require("./webgl/unaryop_gpu");
- var unaryop_gpu_1 = require("./webgl/unaryop_gpu");
- var webgl_util = require("./webgl/webgl_util");
- var BEFORE_PAGING_CONSTANT = 300;
- exports.SIZE_UPLOAD_UNIFORM = 32;
- var MathBackendWebGL = (function () {
- function MathBackendWebGL(gpgpu, delayedStorage) {
- if (delayedStorage === void 0) { delayedStorage = true; }
- this.gpgpu = gpgpu;
- this.delayedStorage = delayedStorage;
- this.texData = new WeakMap();
- this.pendingRead = new WeakMap();
- this.pendingDisposal = new WeakSet();
- this.lruDataGPU = [];
- this.numBytesInGPU = 0;
- this.uploadWaitMs = 0;
- this.downloadWaitMs = 0;
- this.binaryCache = {};
- this.disposed = false;
- if (environment_1.ENV.get('WEBGL_VERSION') < 1) {
- throw new Error('WebGL is not supported on this device');
- }
- if (environment_1.ENV.get('IS_BROWSER')) {
- this.canvas = document.createElement('canvas');
- }
- if (gpgpu == null) {
- this.gpgpu = new gpgpu_context_1.GPGPUContext(gpgpu_util.createWebGLContext(this.canvas));
- this.gpgpuCreatedLocally = true;
- }
- else {
- this.gpgpuCreatedLocally = false;
- }
- this.NUM_BYTES_BEFORE_PAGING =
- (window.screen.height * window.screen.width * window.devicePixelRatio) *
- BEFORE_PAGING_CONSTANT;
- this.textureManager = new texture_manager_1.TextureManager(this.gpgpu);
- }
- MathBackendWebGL.prototype.register = function (dataId, shape, dtype) {
- if (this.texData.has(dataId)) {
- throw new Error('Data buffer is already registered');
- }
- this.texData.set(dataId, {
- shape: shape,
- dtype: dtype,
- values: null,
- texture: null,
- texShape: null,
- usage: tex_util_1.TextureUsage.RENDER
- });
- };
- MathBackendWebGL.prototype.fromPixels = function (pixels, numChannels) {
- if (pixels == null) {
- throw new Error('MathBackendWebGL.writePixels(): pixels can not be null');
- }
- var texShape = [pixels.height, pixels.width];
- var outShape = [pixels.height, pixels.width, numChannels];
- if (pixels instanceof HTMLVideoElement) {
- if (this.fromPixelsCanvas == null) {
- if (!environment_1.ENV.get('IS_BROWSER')) {
- throw new Error('Can\'t read pixels from HTMLImageElement outside the browser.');
- }
- if (document.readyState !== 'complete') {
- throw new Error('The DOM is not ready yet. Please call tf.fromPixels() ' +
- 'once the DOM is ready. One way to do that is to add an event ' +
- 'listener for `DOMContentLoaded` on the document object');
- }
- this.fromPixelsCanvas = document.createElement('canvas');
- }
- this.fromPixelsCanvas.width = pixels.width;
- this.fromPixelsCanvas.height = pixels.height;
- this.fromPixelsCanvas.getContext('2d').drawImage(pixels, 0, 0, pixels.width, pixels.height);
- pixels = this.fromPixelsCanvas;
- }
- var tempPixelArray = tensor_1.Tensor.make(texShape, {}, 'int32');
- this.texData.get(tempPixelArray.dataId).usage = tex_util_1.TextureUsage.PIXELS;
- this.gpgpu.uploadPixelDataToTexture(this.getTexture(tempPixelArray.dataId), pixels);
- var program = new from_pixels_gpu_1.FromPixelsProgram(outShape);
- var res = this.compileAndRun(program, [tempPixelArray]);
- tempPixelArray.dispose();
- return res;
- };
- MathBackendWebGL.prototype.write = function (dataId, values) {
- if (values == null) {
- throw new Error('MathBackendWebGL.write(): values can not be null');
- }
- this.throwIfNoData(dataId);
- var texData = this.texData.get(dataId);
- var texture = texData.texture, texShape = texData.texShape, usage = texData.usage;
- if (texture != null) {
- this.releaseTexture(dataId, texture, texShape, usage);
- texData.texture = null;
- texData.texShape = null;
- }
- texData.usage = tex_util_1.TextureUsage.UPLOAD;
- texData.values = values;
- if (!this.delayedStorage) {
- this.uploadToGPU(dataId);
- }
- };
- MathBackendWebGL.prototype.readSync = function (dataId) {
- this.throwIfNoData(dataId);
- var texData = this.texData.get(dataId);
- var shape = texData.shape, texture = texData.texture, values = texData.values, texShape = texData.texShape, dtype = texData.dtype;
- if (values != null) {
- this.cacheOnCPU(dataId);
- return values;
- }
- var shouldTimeProgram = this.activeTimers != null;
- var start;
- if (shouldTimeProgram) {
- start = performance.now();
- }
- var float32Values;
- if (environment_1.ENV.get('WEBGL_DOWNLOAD_FLOAT_ENABLED')) {
- float32Values = this.gpgpu.downloadFloat32MatrixFromOutputTexture(texture, texShape[0], texShape[1]);
- }
- else {
- var tmpTarget = tensor_1.Tensor.make(shape, {});
- this.texData.get(tmpTarget.dataId).usage = tex_util_1.TextureUsage.DOWNLOAD;
- var tmpInput = tensor_1.Tensor.make(shape, { dataId: dataId }, dtype);
- var program = new encode_float_gpu_1.EncodeFloatProgram(shape);
- var res = this.compileAndRun(program, [tmpInput], tmpTarget);
- var tmpData = this.texData.get(tmpTarget.dataId);
- float32Values =
- this.gpgpu.downloadByteEncodedFloatMatrixFromOutputTexture(tmpData.texture, tmpData.texShape[0], tmpData.texShape[1]);
- res.dispose();
- tmpInput.dispose();
- tmpTarget.dispose();
- }
- if (shouldTimeProgram) {
- this.downloadWaitMs += performance.now() - start;
- }
- this.cacheOnCPU(dataId, float32Values);
- return texData.values;
- };
- MathBackendWebGL.prototype.read = function (dataId) {
- return __awaiter(this, void 0, void 0, function () {
- var subscribers_1, texData, texture, values, texShape, float32Values, subscribers, vals;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (this.pendingRead.has(dataId)) {
- subscribers_1 = this.pendingRead.get(dataId);
- return [2, new Promise(function (resolve) { return subscribers_1.push(resolve); })];
- }
- this.throwIfNoData(dataId);
- texData = this.texData.get(dataId);
- texture = texData.texture, values = texData.values, texShape = texData.texShape;
- if (values != null) {
- this.cacheOnCPU(dataId);
- return [2, values];
- }
- if (!environment_1.ENV.get('WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED')) return [3, 2];
- return [4, this.gpgpu.downloadMatrixFromTextureAsync(texture, texShape[0], texShape[1])];
- case 1:
- float32Values = _a.sent();
- this.cacheOnCPU(dataId, float32Values);
- return [2, texData.values];
- case 2:
- if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 0) {
- return [2, this.readSync(dataId)];
- }
- this.pendingRead.set(dataId, []);
- return [4, this.gpgpu.runQuery(function () { })];
- case 3:
- _a.sent();
- subscribers = this.pendingRead.get(dataId);
- this.pendingRead.delete(dataId);
- vals = this.readSync(dataId);
- subscribers.forEach(function (resolve) { return resolve(vals); });
- if (this.pendingDisposal.has(dataId)) {
- this.pendingDisposal.delete(dataId);
- this.disposeData(dataId);
- }
- return [2, vals];
- }
- });
- });
- };
- MathBackendWebGL.prototype.time = function (f) {
- return __awaiter(this, void 0, void 0, function () {
- var oldActiveTimers, newActiveTimers, outerMostTime, flattenedActiveTimers, kernelMs, res;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- oldActiveTimers = this.activeTimers;
- newActiveTimers = [];
- outerMostTime = false;
- if (this.programTimersStack == null) {
- this.programTimersStack = newActiveTimers;
- outerMostTime = true;
- }
- else {
- this.activeTimers.push(newActiveTimers);
- }
- this.activeTimers = newActiveTimers;
- f();
- flattenedActiveTimers = util.flatten(this.activeTimers);
- this.activeTimers = oldActiveTimers;
- if (outerMostTime) {
- this.programTimersStack = null;
- }
- return [4, Promise.all(flattenedActiveTimers).then(function (results) {
- var sum = 0;
- results.forEach(function (result) { return sum += result; });
- return sum;
- })];
- case 1:
- kernelMs = _a.sent();
- res = {
- uploadWaitMs: this.uploadWaitMs,
- downloadWaitMs: this.downloadWaitMs,
- kernelMs: kernelMs,
- wallMs: null
- };
- this.uploadWaitMs = 0;
- this.downloadWaitMs = 0;
- return [2, res];
- }
- });
- });
- };
- MathBackendWebGL.prototype.memory = function () {
- return { unreliable: false, numBytesInGPU: this.numBytesInGPU };
- };
- MathBackendWebGL.prototype.startTimer = function () {
- if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) {
- return this.gpgpu.beginQuery();
- }
- return { startMs: performance.now(), endMs: null };
- };
- MathBackendWebGL.prototype.endTimer = function (query) {
- if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) {
- this.gpgpu.endQuery();
- return query;
- }
- query.endMs = performance.now();
- return query;
- };
- MathBackendWebGL.prototype.getQueryTime = function (query) {
- return __awaiter(this, void 0, void 0, function () {
- var timerQuery;
- return __generator(this, function (_a) {
- if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) {
- return [2, this.gpgpu.pollQueryTime(query)];
- }
- timerQuery = query;
- return [2, timerQuery.endMs - timerQuery.startMs];
- });
- });
- };
- MathBackendWebGL.prototype.disposeData = function (dataId) {
- if (this.pendingDisposal.has(dataId)) {
- return;
- }
- if (this.pendingRead.has(dataId)) {
- this.pendingDisposal.add(dataId);
- return;
- }
- if (this.texData.has(dataId)) {
- var _a = this.texData.get(dataId), texture = _a.texture, texShape = _a.texShape, usage = _a.usage;
- if (texture != null) {
- this.releaseTexture(dataId, texture, texShape, usage);
- }
- this.texData.delete(dataId);
- }
- };
- MathBackendWebGL.prototype.getTexture = function (dataId) {
- this.uploadToGPU(dataId);
- return this.texData.get(dataId).texture;
- };
- MathBackendWebGL.prototype.getGPGPUContext = function () {
- return this.gpgpu;
- };
- MathBackendWebGL.prototype.getCanvas = function () {
- return this.canvas;
- };
- MathBackendWebGL.prototype.slice = function (x, begin, size) {
- var program = new slice_gpu_1.SliceProgram(size);
- var customSetup = program.getCustomSetupFunc(begin);
- return this.compileAndRun(program, [x], null, customSetup);
- };
- MathBackendWebGL.prototype.stridedSlice = function (x, begin, end, strides, beginMask, endMask) {
- var _a = slice_util_1.getStridedSlicedInfo(x.shape, begin, end, strides, beginMask, endMask), beginIndex = _a[0], size = _a[1];
- if (size.some(function (axis) { return axis === 0; })) {
- return ops.tensor([], size);
- }
- var program = new strided_slice_gpu_1.StridedSliceProgram(beginIndex, strides, size);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.reverse = function (x, axis) {
- var program = new reverse_gpu_1.ReverseProgram(x.shape, axis);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.concat = function (a, b) {
- var program = new concat_gpu_1.ConcatProgram(a.shape, b.shape);
- return this.compileAndRun(program, [a, b]);
- };
- MathBackendWebGL.prototype.neg = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.NEG);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.matMul = function (a, b, transposeA, transposeB) {
- var program = new mulmat_gpu_1.MatMulProgram(a.shape, b.shape, transposeA, transposeB);
- return this.compileAndRun(program, [a, b]);
- };
- MathBackendWebGL.prototype.multiply = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MUL, a.shape, b.shape);
- var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype));
- return this.compileAndRun(program, [a, b], output);
- };
- MathBackendWebGL.prototype.batchNormalization = function (x, mean, variance, varianceEpsilon, scale, offset) {
- var inputs = [x, mean, variance];
- var offsetShape = null;
- if (offset != null) {
- offsetShape = offset.shape;
- inputs.push(offset);
- }
- var scaleShape = null;
- if (scale != null) {
- scaleShape = scale.shape;
- inputs.push(scale);
- }
- var program = new batchnorm_gpu_1.BatchNormProgram(x.shape, mean.shape, variance.shape, offsetShape, scaleShape, varianceEpsilon);
- return this.compileAndRun(program, inputs);
- };
- MathBackendWebGL.prototype.localResponseNormalization4D = function (x, radius, bias, alpha, beta) {
- var program = new lrn_gpu_1.LRNProgram(x.shape, radius, bias, alpha, beta);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.tile = function (x, reps) {
- var program = new tile_gpu_1.TileProgram(x.shape, reps);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.pad = function (x, paddings, constantValue) {
- var program = new pad_gpu_1.PadProgram(x.shape, paddings, constantValue);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.transpose = function (x, perm) {
- var program = new transpose_gpu_1.TransposeProgram(x.shape, perm);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.gather = function (x, indices, axis) {
- var program = new gather_gpu_1.GatherProgram(x.shape, indices.size, axis);
- return this.compileAndRun(program, [x, indices]);
- };
- MathBackendWebGL.prototype.reduce = function (x, reduceType, dtype) {
- var batchSize = x.shape[0];
- var inSize = x.shape[1];
- var windowSize = reduce_util.computeOptimalWindowSize(inSize);
- var reduceInfo = { windowSize: windowSize, inSize: inSize, batchSize: batchSize };
- var program = new reduce_gpu_1.ReduceProgram(reduceInfo, reduceType);
- var _a = program.outputShape, rows = _a[0], cols = _a[1];
- var output = this.makeOutputArray([rows, cols], dtype);
- this.compileAndRun(program, [x], output);
- if (output.shape[1] === 1) {
- return output;
- }
- return this.reduce(output, reduceType, dtype);
- };
- MathBackendWebGL.prototype.argReduce = function (x, reduceType, bestIndicesA) {
- if (bestIndicesA === void 0) { bestIndicesA = null; }
- var batchSize = x.shape[0];
- var inSize = x.shape[1];
- if (bestIndicesA != null) {
- batchSize = bestIndicesA.shape[0];
- inSize = bestIndicesA.shape[1];
- }
- var windowSize = reduce_util.computeOptimalWindowSize(inSize);
- var reduceInfo = { windowSize: windowSize, inSize: inSize, batchSize: batchSize };
- var program = new argminmax_gpu_1.ArgMinMaxProgram(reduceInfo, reduceType, bestIndicesA == null);
- var _a = program.outputShape, rows = _a[0], cols = _a[1];
- var output = this.makeOutputArray([rows, cols], 'int32');
- var inputs = [x];
- if (bestIndicesA != null) {
- inputs.push(bestIndicesA);
- }
- this.compileAndRun(program, inputs, output);
- if (output.shape[1] === 1) {
- return output;
- }
- return this.argReduce(x, reduceType, output);
- };
- MathBackendWebGL.prototype.sum = function (x, axes) {
- axis_util.assertAxesAreInnerMostDims('sum', axes, x.rank);
- var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];
- var inSize = util.sizeFromShape(reduceShape);
- var a2D = x.as2D(-1, inSize);
- var outputDType = types.sumOutType(x.dtype);
- return this.reduce(a2D, 'sum', outputDType).reshape(outShape);
- };
- MathBackendWebGL.prototype.unsortedSegmentSum = function (x, segmentIds, numSegments) {
- var axis = 0;
- var permutation = axis_util.getAxesPermutation([axis], x.rank);
- var permutedX = x;
- if (permutation != null) {
- permutedX = x.transpose(permutation);
- axis = axis_util.getInnerMostAxes(1, x.rank)[0];
- }
- var outShape = segment_util.computeOutShape(permutedX.shape, axis, numSegments);
- var inSize = util.sizeFromShape([permutedX.shape[axis]]);
- var a2D = permutedX.as2D(-1, inSize);
- var outputDType = types.sumOutType(x.dtype);
- var result = this.segOpCompute(a2D, 'unsortedSegmentSum', segmentIds, outputDType, numSegments)
- .reshape(outShape);
- if (permutation != null) {
- result = result.transpose(axis_util.getUndoAxesPermutation(permutation));
- }
- return result;
- };
- MathBackendWebGL.prototype.segOpCompute = function (x, segOpType, segmentIds, dtype, numSegments) {
- var batchSize = x.shape[0];
- var inSize = x.shape[1];
- var windowSize = segment_util.segOpComputeOptimalWindowSize(inSize, numSegments);
- var segOpInfo = { windowSize: windowSize, inSize: inSize, batchSize: batchSize, numSegments: numSegments };
- var program = new segment_gpu_1.SegmentOpProgram(segOpInfo, segOpType);
- var _a = program.outputShape, rows = _a[0], cols = _a[1];
- var output = this.makeOutputArray([rows, cols], dtype);
- this.compileAndRun(program, [x, segmentIds], output);
- if (output.shape[1] === numSegments) {
- return output;
- }
- segmentIds = ops.range(0, numSegments).tile([inSize / windowSize]);
- return this.segOpCompute(output, segOpType, segmentIds, dtype, numSegments);
- };
- MathBackendWebGL.prototype.argMin = function (x, axis) {
- var axes = [axis];
- axis_util.assertAxesAreInnerMostDims('argMin', axes, x.rank);
- var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];
- var inSize = util.sizeFromShape(reduceShape);
- var a2D = x.as2D(-1, inSize);
- return this.argReduce(a2D, 'min').reshape(outShape);
- };
- MathBackendWebGL.prototype.argMax = function (x, axis) {
- var axes = [axis];
- axis_util.assertAxesAreInnerMostDims('argMax', axes, x.rank);
- var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];
- var inSize = util.sizeFromShape(reduceShape);
- var a2D = x.as2D(-1, inSize);
- return this.argReduce(a2D, 'max').reshape(outShape);
- };
- MathBackendWebGL.prototype.cumsum = function (x, axis, exclusive, reverse) {
- if (axis !== x.rank - 1) {
- throw new Error("WebGL cumsum shader expects an inner-most axis=" + (x.rank - 1) + " " +
- ("but got axis=" + axis));
- }
- var program = new cumsum_gpu_1.CumSumProgram(x.shape, exclusive, reverse);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.equal = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.EQUAL, a.shape, b.shape);
- var output = this.makeOutputArray(program.outputShape, 'bool');
- return this.compileAndRun(program, [a, b], output);
- };
- MathBackendWebGL.prototype.notEqual = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.NOT_EQUAL, a.shape, b.shape);
- var output = this.makeOutputArray(program.outputShape, 'bool');
- return this.compileAndRun(program, [a, b], output);
- };
- MathBackendWebGL.prototype.less = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LESS, a.shape, b.shape);
- var output = this.makeOutputArray(program.outputShape, 'bool');
- return this.compileAndRun(program, [a, b], output);
- };
- MathBackendWebGL.prototype.lessEqual = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LESS_EQUAL, a.shape, b.shape);
- var output = this.makeOutputArray(program.outputShape, 'bool');
- return this.compileAndRun(program, [a, b], output);
- };
- MathBackendWebGL.prototype.greater = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.GREATER, a.shape, b.shape);
- var output = this.makeOutputArray(program.outputShape, 'bool');
- return this.compileAndRun(program, [a, b], output);
- };
- MathBackendWebGL.prototype.greaterEqual = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.GREATER_EQUAL, a.shape, b.shape);
- var output = this.makeOutputArray(program.outputShape, 'bool');
- return this.compileAndRun(program, [a, b], output);
- };
- MathBackendWebGL.prototype.logicalNot = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LOGICAL_NOT);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.logicalAnd = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LOGICAL_AND, a.shape, b.shape);
- var output = this.makeOutputArray(program.outputShape, 'bool');
- return this.compileAndRun(program, [a, b], output);
- };
- MathBackendWebGL.prototype.logicalOr = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LOGICAL_OR, a.shape, b.shape);
- var output = this.makeOutputArray(program.outputShape, 'bool');
- return this.compileAndRun(program, [a, b], output);
- };
- MathBackendWebGL.prototype.where = function (condition, a, b, dtype) {
- var program = new logical_gpu_1.WhereProgram(condition.rank, a.shape, a.rank);
- var output = this.makeOutputArray(program.outputShape, dtype);
- return this.compileAndRun(program, [condition, a, b], output);
- };
- MathBackendWebGL.prototype.topKValues = function (x, k) {
- throw new Error('topKValues GPU not yet implemented!');
- };
- MathBackendWebGL.prototype.topKIndices = function (x, k) {
- throw new Error('topKIndices GPU not yet implemented!');
- };
- MathBackendWebGL.prototype.min = function (x, axes) {
- axis_util.assertAxesAreInnerMostDims('min', axes, x.rank);
- var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];
- var inSize = util.sizeFromShape(reduceShape);
- var a2D = x.as2D(-1, inSize);
- return this.reduce(a2D, 'min', a2D.dtype).reshape(outShape);
- };
- MathBackendWebGL.prototype.minimum = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MIN, a.shape, b.shape);
- return this.compileAndRun(program, [a, b]);
- };
- MathBackendWebGL.prototype.mod = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MOD, a.shape, b.shape);
- return this.compileAndRun(program, [a, b]);
- };
- MathBackendWebGL.prototype.max = function (x, axes) {
- axis_util.assertAxesAreInnerMostDims('max', axes, x.rank);
- var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];
- var inSize = util.sizeFromShape(reduceShape);
- var a2D = x.as2D(-1, inSize);
- return this.reduce(a2D, 'max', a2D.dtype).reshape(outShape);
- };
- MathBackendWebGL.prototype.maximum = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MAX, a.shape, b.shape);
- return this.compileAndRun(program, [a, b]);
- };
- MathBackendWebGL.prototype.all = function (x, axes) {
- axis_util.assertAxesAreInnerMostDims('all', axes, x.rank);
- var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];
- var inSize = util.sizeFromShape(reduceShape);
- var a2D = x.as2D(-1, inSize);
- return this.reduce(a2D, 'all', a2D.dtype).reshape(outShape);
- };
- MathBackendWebGL.prototype.squaredDifference = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.SQUARED_DIFFERENCE, a.shape, b.shape);
- return this.compileAndRun(program, [a, b]);
- };
- MathBackendWebGL.prototype.realDivide = function (a, b) {
- var op = binaryop_gpu.DIV;
- var outputDtype = 'float32';
- var program = new binaryop_gpu_1.BinaryOpProgram(op, a.shape, b.shape);
- var output = this.makeOutputArray(program.outputShape, outputDtype);
- return this.compileAndRun(program, [a, b], output);
- };
- MathBackendWebGL.prototype.floorDiv = function (a, b) {
- var op = binaryop_gpu.INT_DIV;
- var outputDtype = 'int32';
- var program = new binaryop_gpu_1.BinaryOpProgram(op, a.shape, b.shape);
- var output = this.makeOutputArray(program.outputShape, outputDtype);
- return this.compileAndRun(program, [a, b], output);
- };
- MathBackendWebGL.prototype.add = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.ADD, a.shape, b.shape);
- var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype));
- return this.compileAndRun(program, [a, b], output);
- };
- MathBackendWebGL.prototype.subtract = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.SUB, a.shape, b.shape);
- var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype));
- return this.compileAndRun(program, [a, b], output);
- };
- MathBackendWebGL.prototype.pow = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.POW, a.shape, b.shape);
- var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype));
- return this.compileAndRun(program, [a, b], output);
- };
- MathBackendWebGL.prototype.ceil = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.CEIL);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.floor = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.FLOOR);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.sign = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SIGN);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.round = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ROUND);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.exp = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.EXP);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.expm1 = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.EXPM1);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.log = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LOG);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.log1p = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LOG1P);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.sqrt = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SQRT);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.rsqrt = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.RSQRT);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.square = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SQUARE);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.reciprocal = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.RECIPROCAL);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.relu = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.RELU);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.elu = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ELU);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.eluDer = function (dy, y) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.ELU_DER, dy.shape, y.shape);
- return this.compileAndRun(program, [dy, y]);
- };
- MathBackendWebGL.prototype.selu = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SELU);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.int = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TO_INT);
- var output = this.makeOutputArray(program.outputShape, 'int32');
- return this.compileAndRun(program, [x], output);
- };
- MathBackendWebGL.prototype.clip = function (x, min, max) {
- var program = new clip_gpu_1.ClipProgram(x.shape, min, max);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.abs = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ABS);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.sigmoid = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SIGMOID);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.softplus = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SOFTPLUS);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.sin = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SIN);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.cos = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.COS);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.tan = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TAN);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.asin = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ASIN);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.acos = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ACOS);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.atan = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ATAN);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.atan2 = function (a, b) {
- var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.ATAN2, a.shape, b.shape);
- return this.compileAndRun(program, [a, b]);
- };
- MathBackendWebGL.prototype.sinh = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SINH);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.cosh = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.COSH);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.tanh = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TANH);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.asinh = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ASINH);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.acosh = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ACOSH);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.atanh = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ATANH);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.erf = function (x) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ERF);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.step = function (x, alpha) {
- var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.STEP(alpha));
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.conv2d = function (x, filter, convInfo) {
- var program = new conv_gpu_1.Conv2DProgram(convInfo);
- return this.compileAndRun(program, [x, filter]);
- };
- MathBackendWebGL.prototype.conv2dDerInput = function (dy, filter, convInfo) {
- var program = new conv_backprop_gpu_1.Conv2DDerInputProgram(convInfo);
- return this.compileAndRun(program, [dy, filter]);
- };
- MathBackendWebGL.prototype.conv2dDerFilter = function (x, dy, convInfo) {
- var program = new conv_backprop_gpu_1.Conv2DDerFilterProgram(convInfo);
- return this.compileAndRun(program, [x, dy]);
- };
- MathBackendWebGL.prototype.depthwiseConv2D = function (x, filter, convInfo) {
- var program = new conv_gpu_depthwise_1.DepthwiseConv2DProgram(convInfo);
- return this.compileAndRun(program, [x, filter]);
- };
- MathBackendWebGL.prototype.depthwiseConv2DDerInput = function (dy, filter, convInfo) {
- var program = new conv_backprop_gpu_depthwise_1.DepthwiseConv2DDerInputProgram(convInfo);
- return this.compileAndRun(program, [dy, filter]);
- };
- MathBackendWebGL.prototype.depthwiseConv2DDerFilter = function (x, dy, convInfo) {
- var program = new conv_backprop_gpu_depthwise_1.DepthwiseConv2DDerFilterProgram(convInfo);
- return this.compileAndRun(program, [x, dy]);
- };
- MathBackendWebGL.prototype.maxPool = function (x, convInfo) {
- var program = new pool_gpu_1.Pool2DProgram(convInfo, 'max', false);
- var output = this.makeOutputArray(program.outputShape, x.dtype);
- return this.compileAndRun(program, [x], output);
- };
- MathBackendWebGL.prototype.avgPool = function (x, convInfo) {
- var program = new pool_gpu_1.Pool2DProgram(convInfo, 'avg', false);
- var output = this.makeOutputArray(program.outputShape, 'float32');
- return this.compileAndRun(program, [x], output);
- };
- MathBackendWebGL.prototype.maxPoolBackprop = function (dy, x, y, convInfo) {
- var getPositions = true;
- var maxPoolPositionsProgram = new pool_gpu_1.Pool2DProgram(convInfo, 'max', getPositions);
- var maxPoolPositions = this.compileAndRun(maxPoolPositionsProgram, [x]);
- var maxPoolBackPropProgram = new max_pool_backprop_gpu_1.MaxPool2DBackpropProgram(convInfo);
- var output = this.makeOutputArray(maxPoolBackPropProgram.outputShape, x.dtype);
- var result = this.compileAndRun(maxPoolBackPropProgram, [dy, maxPoolPositions], output);
- maxPoolPositions.dispose();
- return result;
- };
- MathBackendWebGL.prototype.avgPoolBackprop = function (dy, x, convInfo) {
- var avgPoolBackpropProgram = new avg_pool_backprop_gpu_1.AvgPool2DBackpropProgram(convInfo);
- var output = this.makeOutputArray(avgPoolBackpropProgram.outputShape, x.dtype);
- return this.compileAndRun(avgPoolBackpropProgram, [dy], output);
- };
- MathBackendWebGL.prototype.cast = function (x, dtype) {
- return backend_util.castTensor(x, dtype, this);
- };
- MathBackendWebGL.prototype.reshape = function (x, shape) {
- return backend_util.reshapeTensor(x, shape);
- };
- MathBackendWebGL.prototype.resizeBilinear = function (x, newHeight, newWidth, alignCorners) {
- var program = new resize_bilinear_gpu_1.ResizeBilinearProgram(x.shape, newHeight, newWidth, alignCorners);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.resizeBilinearBackprop = function (dy, x, alignCorners) {
- var program = new resize_bilinear_backprop_gpu_1.ResizeBilinearBackpropProgram(dy, x, alignCorners);
- return this.compileAndRun(program, [dy]);
- };
- MathBackendWebGL.prototype.resizeNearestNeighbor = function (x, newHeight, newWidth, alignCorners) {
- var program = new resize_nearest_neighbor_gpu_1.ResizeNearestNeighborProgram(x.shape, newHeight, newWidth, alignCorners);
- return this.compileAndRun(program, [x]);
- };
- MathBackendWebGL.prototype.multinomial = function (logits, normalized, numSamples, seed) {
- var probs = normalized ? logits : ops.softmax(logits);
- var batchSize = probs.shape[0];
- var numOutcomes = probs.shape[1];
- var program = new multinomial_gpu_1.MultinomialProgram(batchSize, numOutcomes, numSamples);
- var output = this.makeOutputArray(program.outputShape, 'int32');
- var customSetup = program.getCustomSetupFunc(seed);
- return this.compileAndRun(program, [probs], output, customSetup);
- };
- MathBackendWebGL.prototype.oneHot = function (indices, depth, onValue, offValue) {
- var program = new onehot_gpu_1.OneHotProgram(indices.size, depth, onValue, offValue);
- return this.compileAndRun(program, [indices]);
- };
- MathBackendWebGL.prototype.makeOutputArray = function (shape, dtype) {
- return tensor_1.Tensor.make(shape, {}, dtype);
- };
- MathBackendWebGL.prototype.compileAndRun = function (program, inputs, output, customSetup) {
- var _this = this;
- if (output == null) {
- output = this.makeOutputArray(program.outputShape, inputs[0].dtype);
- }
- var inputsData = inputs.map(function (tensor) {
- var texData = _this.texData.get(tensor.dataId);
- if (texData.texture == null && tensor.size <= exports.SIZE_UPLOAD_UNIFORM) {
- return { tensor: tensor, texData: null, isUniform: true };
- }
- _this.uploadToGPU(tensor.dataId);
- return { tensor: tensor, texData: texData, isUniform: false };
- });
- this.uploadToGPU(output.dataId);
- var outputData = {
- tensor: output,
- texData: this.texData.get(output.dataId),
- isUniform: false
- };
- var key = gpgpu_math.makeShaderKey(program, inputsData, outputData);
- var binary = this.getAndSaveBinary(key, function () {
- return gpgpu_math.compileProgram(_this.gpgpu, program, inputsData, outputData);
- });
- var shouldTimeProgram = this.activeTimers != null;
- var query;
- if (shouldTimeProgram) {
- query = this.startTimer();
- }
- gpgpu_math.runProgram(binary, inputsData, outputData, customSetup);
- if (this.numBytesInGPU > this.NUM_BYTES_BEFORE_PAGING) {
- var numBytesToPage = this.numBytesInGPU - this.NUM_BYTES_BEFORE_PAGING;
- while (numBytesToPage > 0) {
- var dataId = this.lruDataGPU.shift();
- var _a = this.texData.get(dataId), shape = _a.shape, dtype = _a.dtype;
- numBytesToPage -= this.computeBytes(shape, dtype);
- this.read(dataId);
- }
- }
- if (shouldTimeProgram) {
- query = this.endTimer(query);
- this.activeTimers.push(this.getQueryTime(query));
- }
- return output;
- };
- MathBackendWebGL.prototype.getAndSaveBinary = function (key, getBinary) {
- if (!(key in this.binaryCache)) {
- this.binaryCache[key] = getBinary();
- }
- return this.binaryCache[key];
- };
- MathBackendWebGL.prototype.getTextureManager = function () {
- return this.textureManager;
- };
- MathBackendWebGL.prototype.dispose = function () {
- if (this.disposed) {
- return;
- }
- for (var key in this.binaryCache) {
- this.gpgpu.deleteProgram(this.binaryCache[key].webGLProgram);
- }
- this.textureManager.dispose();
- this.canvas.remove();
- if (this.fromPixelsCanvas != null) {
- this.fromPixelsCanvas.remove();
- }
- if (this.gpgpuCreatedLocally) {
- this.gpgpu.dispose();
- }
- this.disposed = true;
- };
- MathBackendWebGL.prototype.throwIfNoData = function (dataId) {
- if (!this.texData.has(dataId)) {
- throw new Error("WebGL backend: No data found for this tensor. " +
- "Did you change your backend in the middle of the program? " +
- "New backends can't use Tensors created with previous backends");
- }
- };
- MathBackendWebGL.prototype.uploadToGPU = function (dataId) {
- this.throwIfNoData(dataId);
- var texData = this.texData.get(dataId);
- var shape = texData.shape, values = texData.values, texture = texData.texture, dtype = texData.dtype, usage = texData.usage;
- if (texture != null) {
- this.lruDataGPU.splice(this.lruDataGPU.indexOf(dataId), 1);
- this.lruDataGPU.push(dataId);
- return;
- }
- var shouldTimeProgram = this.activeTimers != null;
- var start;
- if (shouldTimeProgram) {
- start = performance.now();
- }
- var texShape = webgl_util.getTextureShapeFromLogicalShape(this.gpgpu.gl, shape);
- texData.texShape = texShape;
- var newTexture = this.acquireTexture(dataId, texShape, usage);
- texData.texture = newTexture;
- if (values != null) {
- this.gpgpu.uploadMatrixToTexture(newTexture, texShape[0], texShape[1], typedArrayToFloat32(values, dtype));
- texData.values = null;
- if (shouldTimeProgram) {
- this.uploadWaitMs += performance.now() - start;
- }
- }
- };
- MathBackendWebGL.prototype.cacheOnCPU = function (dataId, float32Values) {
- var dontKeepCopyOnGPU = this.delayedStorage;
- var texData = this.texData.get(dataId);
- var texture = texData.texture, texShape = texData.texShape, dtype = texData.dtype, usage = texData.usage;
- if (dontKeepCopyOnGPU && texture != null) {
- this.releaseTexture(dataId, texture, texShape, usage);
- texData.texture = null;
- texData.texShape = null;
- }
- if (float32Values != null) {
- texData.values = float32ToTypedArray(float32Values, dtype);
- }
- };
- MathBackendWebGL.prototype.releaseTexture = function (dataId, texture, texShape, texType) {
- var _a = this.texData.get(dataId), shape = _a.shape, dtype = _a.dtype;
- var idx = this.lruDataGPU.indexOf(dataId);
- if (idx >= 0) {
- this.lruDataGPU.splice(idx, 1);
- }
- this.numBytesInGPU -= this.computeBytes(shape, dtype);
- this.textureManager.releaseTexture(texture, texShape, texType);
- };
- MathBackendWebGL.prototype.acquireTexture = function (dataId, texShape, texType) {
- var _a = this.texData.get(dataId), shape = _a.shape, dtype = _a.dtype;
- this.lruDataGPU.push(dataId);
- this.numBytesInGPU += this.computeBytes(shape, dtype);
- return this.textureManager.acquireTexture(texShape, texType);
- };
- MathBackendWebGL.prototype.computeBytes = function (shape, dtype) {
- return util.sizeFromShape(shape) * util.bytesPerElement(dtype);
- };
- return MathBackendWebGL;
- }());
- exports.MathBackendWebGL = MathBackendWebGL;
- if (environment_1.ENV.get('IS_BROWSER')) {
- environment_1.ENV.registerBackend('webgl', function () { return new MathBackendWebGL(); }, 2);
- }
- function float32ToTypedArray(a, dtype) {
- if (dtype === 'float32') {
- return a;
- }
- else if (dtype === 'int32' || dtype === 'bool') {
- var result = (dtype === 'int32') ? new Int32Array(a.length) :
- new Uint8Array(a.length);
- for (var i = 0; i < result.length; ++i) {
- result[i] = Math.round(a[i]);
- }
- return result;
- }
- else {
- throw new Error("Unknown dtype " + dtype);
- }
- }
- function typedArrayToFloat32(a, dtype) {
- return (a instanceof Float32Array) ? a : new Float32Array(a);
- }
- },{"../environment":51,"../ops/axis_util":109,"../ops/ops":129,"../ops/reduce_util":132,"../ops/segment_util":136,"../ops/slice_util":140,"../tensor":158,"../types":163,"../util":164,"./backend_util":66,"./webgl/argminmax_gpu":68,"./webgl/avg_pool_backprop_gpu":69,"./webgl/batchnorm_gpu":70,"./webgl/binaryop_gpu":71,"./webgl/clip_gpu":72,"./webgl/concat_gpu":73,"./webgl/conv_backprop_gpu":74,"./webgl/conv_backprop_gpu_depthwise":75,"./webgl/conv_gpu":76,"./webgl/conv_gpu_depthwise":77,"./webgl/cumsum_gpu":78,"./webgl/encode_float_gpu":79,"./webgl/from_pixels_gpu":80,"./webgl/gather_gpu":81,"./webgl/gpgpu_context":82,"./webgl/gpgpu_math":83,"./webgl/gpgpu_util":84,"./webgl/logical_gpu":85,"./webgl/lrn_gpu":86,"./webgl/max_pool_backprop_gpu":87,"./webgl/mulmat_gpu":88,"./webgl/multinomial_gpu":89,"./webgl/onehot_gpu":90,"./webgl/pad_gpu":91,"./webgl/pool_gpu":92,"./webgl/reduce_gpu":93,"./webgl/resize_bilinear_backprop_gpu":94,"./webgl/resize_bilinear_gpu":95,"./webgl/resize_nearest_neighbor_gpu":96,"./webgl/reverse_gpu":97,"./webgl/segment_gpu":98,"./webgl/slice_gpu":100,"./webgl/strided_slice_gpu":101,"./webgl/tex_util":102,"./webgl/texture_manager":103,"./webgl/tile_gpu":104,"./webgl/transpose_gpu":105,"./webgl/unaryop_gpu":106,"./webgl/webgl_util":107}],68:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var ArgMinMaxProgram = (function () {
- function ArgMinMaxProgram(reduceInfo, op, firstPass) {
- this.variableNames = ['A'];
- var windowSize = reduceInfo.windowSize;
- var batchSize = reduceInfo.batchSize;
- var inSize = reduceInfo.inSize;
- var outSize = Math.ceil(inSize / windowSize);
- if (!firstPass) {
- this.variableNames.push('bestIndicesA');
- }
- this.outputShape = [batchSize, outSize];
- var compOp = (op === 'max') ? '>' : '<';
- var indexSnippet = firstPass ?
- 'inOffset + i;' :
- 'round(getBestIndicesA(batch, inOffset + i));';
- this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * " + windowSize + ";\n\n int bestIndex = 0;\n float bestValue = getA(batch, inOffset);\n\n for (int i = 0; i < " + windowSize + "; i++) {\n int inIdx = " + indexSnippet + ";\n float candidate = getA(batch, inIdx);\n if (candidate " + compOp + " bestValue) {\n bestValue = candidate;\n bestIndex = inIdx;\n }\n }\n setOutput(float(bestIndex));\n }\n ";
- }
- return ArgMinMaxProgram;
- }());
- exports.ArgMinMaxProgram = ArgMinMaxProgram;
- },{}],69:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var AvgPool2DBackpropProgram = (function () {
- function AvgPool2DBackpropProgram(convInfo) {
- this.variableNames = ['dy'];
- this.outputShape = convInfo.inShape;
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var padTop = filterHeight - 1 - convInfo.padInfo.top;
- var padLeft = filterWidth - 1 - convInfo.padInfo.left;
- var avgMultiplier = 1 / (filterHeight * filterWidth);
- this.userCode = "\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n const float avgMultiplier = float(" + avgMultiplier + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + strideHeight + ".0;\n\n if (dyR < 0.0 || dyR >= " + convInfo.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + strideWidth + ".0;\n\n if (dyC < 0.0 || dyC >= " + convInfo.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n\n dotProd += dyValue * avgMultiplier;\n }\n }\n setOutput(dotProd);\n }\n ";
- }
- return AvgPool2DBackpropProgram;
- }());
- exports.AvgPool2DBackpropProgram = AvgPool2DBackpropProgram;
- },{}],70:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var broadcast_util = require("../../ops/broadcast_util");
- var BatchNormProgram = (function () {
- function BatchNormProgram(xShape, meanShape, varianceShape, offsetShape, scaleShape, varianceEpsilon) {
- this.outputShape = [];
- this.supportsBroadcasting = true;
- this.variableNames = ['x', 'mean', 'variance'];
- broadcast_util.assertAndGetBroadcastShape(xShape, meanShape);
- broadcast_util.assertAndGetBroadcastShape(xShape, varianceShape);
- var offsetSnippet = '0.0';
- if (offsetShape != null) {
- broadcast_util.assertAndGetBroadcastShape(xShape, offsetShape);
- this.variableNames.push('offset');
- offsetSnippet = 'getOffsetAtOutCoords()';
- }
- var scaleSnippet = '1.0';
- if (scaleShape != null) {
- broadcast_util.assertAndGetBroadcastShape(xShape, scaleShape);
- this.variableNames.push('scale');
- scaleSnippet = 'getScaleAtOutCoords()';
- }
- this.outputShape = xShape;
- this.userCode = "\n void main() {\n float x = getXAtOutCoords();\n float mean = getMeanAtOutCoords();\n float variance = getVarianceAtOutCoords();\n float offset = " + offsetSnippet + ";\n float scale = " + scaleSnippet + ";\n float inv = scale * inversesqrt(variance + float(" + varianceEpsilon + "));\n setOutput((x - mean) * inv + offset);\n }\n ";
- }
- return BatchNormProgram;
- }());
- exports.BatchNormProgram = BatchNormProgram;
- },{"../../ops/broadcast_util":112}],71:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var broadcast_util = require("../../ops/broadcast_util");
- var CHECK_NAN_SNIPPET = "\n if (isNaN(a)) return a;\n if (isNaN(b)) return b;\n";
- exports.ADD = 'return a + b;';
- exports.SUB = 'return a - b;';
- exports.MUL = 'return a * b;';
- exports.DIV = 'return a / b;';
- exports.INT_DIV = "\n float resultSign = sign(a) * sign(b);\n int ia = round(a);\n int ib = round(b);\n int result = ia / ib;\n int amodb = ia - ib * result;\n\n if (resultSign < 0.0 && amodb != 0) {\n result -= 1;\n }\n return float(result);\n";
- exports.POW = "\n return (round(mod(b, 2.0)) == 0 || round(mod(b, 2.0)) == 2) ?\n pow(abs(a), b) : sign(a) * pow(abs(a), b);\n";
- exports.SQUARED_DIFFERENCE = 'return (a - b) * (a - b);';
- exports.EQUAL = "return float(a == b);";
- exports.NOT_EQUAL = "return float(a != b);";
- exports.LESS = "return float(a < b);";
- exports.LESS_EQUAL = "return float(a <= b);";
- exports.GREATER = "return float(a > b);";
- exports.GREATER_EQUAL = "return float(a >= b);";
- exports.LOGICAL_AND = "return float(a >= 1.0 && b >= 1.0);";
- exports.LOGICAL_OR = "return float(a >= 1.0 || b >= 1.0);";
- exports.MAX = CHECK_NAN_SNIPPET + "\n return max(a, b);\n";
- exports.MIN = CHECK_NAN_SNIPPET + "\n return min(a, b);\n";
- exports.MOD = "return mod(a, b);";
- exports.ATAN2 = CHECK_NAN_SNIPPET + "\n return atan(a, b);\n";
- exports.ELU_DER = "return (b >= 1.0) ? a : a * (b + 1.0);";
- var BinaryOpProgram = (function () {
- function BinaryOpProgram(op, aShape, bShape) {
- this.variableNames = ['A', 'B'];
- this.supportsBroadcasting = true;
- this.outputShape =
- broadcast_util.assertAndGetBroadcastShape(aShape, bShape);
- this.userCode = "\n float binaryOperation(float a, float b) {\n " + op + "\n }\n\n void main() {\n float a = getAAtOutCoords();\n float b = getBAtOutCoords();\n setOutput(binaryOperation(a, b));\n }\n ";
- }
- return BinaryOpProgram;
- }());
- exports.BinaryOpProgram = BinaryOpProgram;
- },{"../../ops/broadcast_util":112}],72:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var ClipProgram = (function () {
- function ClipProgram(aShape, min, max) {
- this.variableNames = ['A'];
- this.outputShape = aShape;
- var minFixed = min.toFixed(20);
- var maxFixed = max.toFixed(20);
- this.userCode = "\n void main() {\n float value = getAAtOutCoords();\n if (isNaN(value)) {\n setOutput(value);\n return;\n }\n\n setOutput(clamp(value, " + minFixed + ", " + maxFixed + "));\n }\n ";
- }
- return ClipProgram;
- }());
- exports.ClipProgram = ClipProgram;
- },{}],73:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var concat_util = require("../../ops/concat_util");
- var ConcatProgram = (function () {
- function ConcatProgram(aShape, bShape) {
- this.variableNames = ['A', 'B'];
- this.outputShape = [];
- this.outputShape =
- concat_util.computeOutShape(aShape, bShape, 1);
- this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int yR = coords.x;\n int yC = coords.y;\n\n float value = 0.0;\n if (yC < " + aShape[1] + ") {\n value = getA(yR, yC);\n } else {\n yC -= " + aShape[1] + ";\n value = getB(yR, yC);\n }\n\n setOutput(value);\n }\n ";
- }
- return ConcatProgram;
- }());
- exports.ConcatProgram = ConcatProgram;
- },{"../../ops/concat_util":115}],74:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var Conv2DDerFilterProgram = (function () {
- function Conv2DDerFilterProgram(convInfo) {
- this.variableNames = ['x', 'dy'];
- this.outputShape = convInfo.filterShape;
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var padTop = convInfo.padInfo.top;
- var padLeft = convInfo.padInfo.left;
- this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int wR = coords.x;\n int wC = coords.y;\n int d1 = coords.z;\n int d2 = coords.w;\n\n // Convolve x(?, ?, d1) with dy(:, :, d2) to get dw(wR, wC, d1, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n\n for (int b = 0; b < " + convInfo.batchSize + "; b++) {\n for (int yR = 0; yR < " + convInfo.outHeight + "; yR++) {\n int xR = wR + yR * " + strideHeight + " - " + padTop + ";\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int yC = 0; yC < " + convInfo.outWidth + "; yC++) {\n int xC = wC + yC * " + strideWidth + " - " + padLeft + ";\n\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n continue;\n }\n\n float dyValue = getDy(b, yR, yC, d2);\n float xValue = getX(b, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n setOutput(dotProd);\n }\n ";
- }
- return Conv2DDerFilterProgram;
- }());
- exports.Conv2DDerFilterProgram = Conv2DDerFilterProgram;
- var Conv2DDerInputProgram = (function () {
- function Conv2DDerInputProgram(convInfo) {
- this.variableNames = ['dy', 'W'];
- this.outputShape = convInfo.inShape;
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var padTop = filterHeight - 1 - convInfo.padInfo.top;
- var padLeft = filterWidth - 1 - convInfo.padInfo.left;
- this.userCode = "\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d1 = coords[3];\n\n ivec2 dyCorner = coords.yz - pads;\n int dyRCorner = dyCorner.x;\n int dyCCorner = dyCorner.y;\n\n // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + strideHeight + ".0;\n\n if (dyR < 0.0 || dyR >= " + convInfo.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = " + filterHeight + " - 1 - wR;\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + strideWidth + ".0;\n\n if (dyC < 0.0 || dyC >= " + convInfo.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = " + filterWidth + " - 1 - wC;\n\n for (int d2 = 0; d2 < " + convInfo.outChannels + "; d2++) {\n float xValue = getDy(batch, idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n }\n }\n }\n setOutput(dotProd);\n }\n ";
- }
- return Conv2DDerInputProgram;
- }());
- exports.Conv2DDerInputProgram = Conv2DDerInputProgram;
- },{}],75:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var DepthwiseConv2DDerFilterProgram = (function () {
- function DepthwiseConv2DDerFilterProgram(convInfo) {
- this.variableNames = ['x', 'dy'];
- this.outputShape = convInfo.filterShape;
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var padTop = convInfo.padInfo.top;
- var padLeft = convInfo.padInfo.left;
- var channelMul = convInfo.outChannels / convInfo.inChannels;
- this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int wR = coords.x;\n int wC = coords.y;\n int d1 = coords.z;\n int dm = coords.w;\n int d2 = d1 * " + channelMul + " + dm;\n\n float dotProd = 0.0;\n\n // TODO: Vec4 over the batch size\n for (int b = 0; b < " + convInfo.batchSize + "; b++) {\n for (int yR = 0; yR < " + convInfo.outHeight + "; yR++) {\n int xR = wR + yR * " + strideHeight + " - " + padTop + ";\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int yC = 0; yC < " + convInfo.outWidth + "; yC++) {\n int xC = wC + yC * " + strideWidth + " - " + padLeft + ";\n\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n continue;\n }\n\n float dyValue = getDy(b, yR, yC, d2);\n float xValue = getX(b, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n setOutput(dotProd);\n }\n ";
- }
- return DepthwiseConv2DDerFilterProgram;
- }());
- exports.DepthwiseConv2DDerFilterProgram = DepthwiseConv2DDerFilterProgram;
- var DepthwiseConv2DDerInputProgram = (function () {
- function DepthwiseConv2DDerInputProgram(convInfo) {
- this.variableNames = ['dy', 'W'];
- this.outputShape = convInfo.inShape;
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var padTop = filterHeight - 1 - convInfo.padInfo.top;
- var padLeft = filterWidth - 1 - convInfo.padInfo.left;
- var channelMul = convInfo.outChannels / convInfo.inChannels;
- this.userCode = "\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d1 = coords[3];\n ivec2 dyCorner = coords.yz - pads;\n int dyRCorner = dyCorner.x;\n int dyCCorner = dyCorner.y;\n\n float dotProd = 0.0;\n\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + strideHeight + ".0;\n\n if (dyR < 0.0 || dyR >= " + convInfo.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = " + filterHeight + " - 1 - wR;\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + strideWidth + ".0;\n\n if (dyC < 0.0 || dyC >= " + convInfo.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = " + filterWidth + " - 1 - wC;\n\n // TODO: Vec4 over the channelMul\n for (int dm = 0; dm < " + channelMul + "; dm++) {\n int d2 = d1 * " + channelMul + " + dm;\n float xValue = getDy(batch, idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, dm);\n dotProd += xValue * wValue;\n }\n }\n }\n setOutput(dotProd);\n }\n ";
- }
- return DepthwiseConv2DDerInputProgram;
- }());
- exports.DepthwiseConv2DDerInputProgram = DepthwiseConv2DDerInputProgram;
- },{}],76:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var Conv2DProgram = (function () {
- function Conv2DProgram(convInfo) {
- this.variableNames = ['x', 'W'];
- this.outputShape = convInfo.outShape;
- var padTop = convInfo.padInfo.top;
- var padLeft = convInfo.padInfo.left;
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var dilationHeight = convInfo.dilationHeight;
- var dilationWidth = convInfo.dilationWidth;
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var inputDepthNearestVec4 = Math.floor(convInfo.inChannels / 4) * 4;
- var inputDepthVec4Remainder = convInfo.inChannels % 4;
- this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d2 = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR * " + dilationHeight + ";\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n int xC = xCCorner + wC * " + dilationWidth + ";\n\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n continue;\n }\n\n for (int d1 = 0; d1 < " + inputDepthNearestVec4 + "; d1 += 4) {\n vec4 xValues = vec4(\n getX(batch, xR, xC, d1),\n getX(batch, xR, xC, d1 + 1),\n getX(batch, xR, xC, d1 + 2),\n getX(batch, xR, xC, d1 + 3)\n );\n vec4 wValues = vec4(\n getW(wR, wC, d1, d2),\n getW(wR, wC, d1 + 1, d2),\n getW(wR, wC, d1 + 2, d2),\n getW(wR, wC, d1 + 3, d2)\n );\n\n dotProd += dot(xValues, wValues);\n }\n\n if (" + (inputDepthVec4Remainder === 1) + ") {\n dotProd +=\n getX(batch, xR, xC, " + inputDepthNearestVec4 + ") *\n getW(wR, wC, " + inputDepthNearestVec4 + ", d2);\n } else if (" + (inputDepthVec4Remainder === 2) + ") {\n vec2 xValues = vec2(\n getX(batch, xR, xC, " + inputDepthNearestVec4 + "),\n getX(batch, xR, xC, " + inputDepthNearestVec4 + " + 1)\n );\n vec2 wValues = vec2(\n getW(wR, wC, " + inputDepthNearestVec4 + ", d2),\n getW(wR, wC, " + inputDepthNearestVec4 + " + 1, d2)\n );\n dotProd += dot(xValues, wValues);\n } else if (" + (inputDepthVec4Remainder === 3) + ") {\n vec3 xValues = vec3(\n getX(batch, xR, xC, " + inputDepthNearestVec4 + "),\n getX(batch, xR, xC, " + inputDepthNearestVec4 + " + 1),\n getX(batch, xR, xC, " + inputDepthNearestVec4 + " + 2)\n );\n vec3 wValues = vec3(\n getW(wR, wC, " + inputDepthNearestVec4 + ", d2),\n getW(wR, wC, " + inputDepthNearestVec4 + " + 1, d2),\n getW(wR, wC, " + inputDepthNearestVec4 + " + 2, d2)\n );\n dotProd += dot(xValues, wValues);\n }\n }\n }\n setOutput(dotProd);\n }\n ";
- }
- return Conv2DProgram;
- }());
- exports.Conv2DProgram = Conv2DProgram;
- },{}],77:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var DepthwiseConv2DProgram = (function () {
- function DepthwiseConv2DProgram(convInfo) {
- this.variableNames = ['x', 'W'];
- this.outputShape = convInfo.outShape;
- var xNumRows = convInfo.inHeight;
- var xNumCols = convInfo.inWidth;
- var padTop = convInfo.padInfo.top;
- var padLeft = convInfo.padInfo.left;
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var dilationHeight = convInfo.dilationHeight;
- var dilationWidth = convInfo.dilationWidth;
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var channelMul = convInfo.outChannels / convInfo.inChannels;
- this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords.x;\n ivec2 xRCCorner = coords.yz * strides - pads;\n int d2 = coords.w;\n int d1 = d2 / " + channelMul + ";\n int q = d2 - d1 * " + channelMul + ";\n\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n // TODO(dsmilkov): Flatten the two for loops and vec4 the operations.\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR * " + dilationHeight + ";\n\n if (xR < 0 || xR >= " + xNumRows + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n int xC = xCCorner + wC * " + dilationWidth + ";\n\n if (xC < 0 || xC >= " + xNumCols + ") {\n continue;\n }\n\n float xVal = getX(batch, xR, xC, d1);\n float wVal = getW(wR, wC, d1, q);\n dotProd += xVal * wVal;\n }\n }\n setOutput(dotProd);\n }\n ";
- }
- return DepthwiseConv2DProgram;
- }());
- exports.DepthwiseConv2DProgram = DepthwiseConv2DProgram;
- },{}],78:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var shader_compiler_1 = require("./shader_compiler");
- var CumSumProgram = (function () {
- function CumSumProgram(shape, exclusive, reverse) {
- this.variableNames = ['x'];
- this.outputShape = shape;
- var rank = shape.length;
- var finalDim = shape[shape.length - 1];
- var comparator = reverse ? '<' : '>';
- this.userCode = "\n int getIndex(int i) {\n " + (reverse ? "return " + finalDim + " -i - 1;" : 'return i;') + "\n }\n\n void main() {\n " + shader_compiler_1.getCoordsDataType(rank) + " coords = getOutputCoords();\n int end = " + getFinalCoord(rank, 'coords') + ";\n float val = 0.0;\n for (int i = " + finalDim + " - 1; i >= 0; i -= 1) {\n int idx = getIndex(i);\n if (idx " + comparator + " end) {\n continue;\n }\n if (idx == end && " + exclusive + ") {\n continue;\n }\n " + getFinalCoord(rank, 'coords') + " = idx;\n val += getX(" + getCoords(rank, 'coords') + ");\n }\n setOutput(val);\n }\n ";
- }
- return CumSumProgram;
- }());
- exports.CumSumProgram = CumSumProgram;
- function getCoords(rank, name) {
- if (rank === 1) {
- return "" + name;
- }
- else if (rank === 2) {
- return name + ".x, " + name + ".y";
- }
- else if (rank === 3) {
- return name + ".x, " + name + ".y, " + name + ".z";
- }
- else if (rank === 4) {
- return name + ".x, " + name + ".y, " + name + ".z, " + name + ".w";
- }
- else {
- throw Error("Cumulative sum for rank " + rank + " is not yet supported");
- }
- }
- function getFinalCoord(rank, name) {
- if (rank === 1) {
- return "" + name;
- }
- else if (rank === 2) {
- return name + ".y";
- }
- else if (rank === 3) {
- return name + ".z";
- }
- else if (rank === 4) {
- return name + ".w";
- }
- else {
- throw Error("Cumulative sum for rank " + rank + " is not yet supported");
- }
- }
- },{"./shader_compiler":99}],79:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var EncodeFloatProgram = (function () {
- function EncodeFloatProgram(outputShape) {
- this.variableNames = ['A'];
- this.outputShape = outputShape;
- this.userCode = "\n const float FLOAT_MAX = 1.70141184e38;\n const float FLOAT_MIN = 1.17549435e-38;\n\n lowp vec4 encode_float(highp float v) {\n if (isNaN(v)) {\n return vec4(255, 255, 255, 255);\n }\n\n highp float av = abs(v);\n\n if(av < FLOAT_MIN) {\n return vec4(0.0, 0.0, 0.0, 0.0);\n } else if(v > FLOAT_MAX) {\n return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;\n } else if(v < -FLOAT_MAX) {\n return vec4(0.0, 0.0, 128.0, 255.0) / 255.0;\n }\n\n highp vec4 c = vec4(0,0,0,0);\n\n highp float e = floor(log2(av));\n highp float m = exp2(fract(log2(av))) - 1.0;\n\n c[2] = floor(128.0 * m);\n m -= c[2] / 128.0;\n c[1] = floor(32768.0 * m);\n m -= c[1] / 32768.0;\n c[0] = floor(8388608.0 * m);\n\n highp float ebias = e + 127.0;\n c[3] = floor(ebias / 2.0);\n ebias -= c[3] * 2.0;\n c[2] += floor(ebias) * 128.0;\n\n c[3] += 128.0 * step(0.0, -v);\n\n return c / 255.0;\n }\n\n void main() {\n float x = getAAtOutCoords();\n gl_FragColor = encode_float(x);\n }\n ";
- }
- return EncodeFloatProgram;
- }());
- exports.EncodeFloatProgram = EncodeFloatProgram;
- },{}],80:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var FromPixelsProgram = (function () {
- function FromPixelsProgram(outputShape) {
- this.variableNames = ['A'];
- var height = outputShape[0], width = outputShape[1];
- this.outputShape = outputShape;
- this.userCode = "\n void main() {\n ivec3 coords = getOutputCoords();\n int texR = coords[0];\n int texC = coords[1];\n int depth = coords[2];\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2(" + width + ".0, " + height + ".0);\n\n vec4 values = texture2D(A, uv);\n float value;\n if (depth == 0) {\n value = values.r;\n } else if (depth == 1) {\n value = values.g;\n } else if (depth == 2) {\n value = values.b;\n } else if (depth == 3) {\n value = values.a;\n }\n\n setOutput(floor(value * 255.0 + 0.5));\n }\n ";
- }
- return FromPixelsProgram;
- }());
- exports.FromPixelsProgram = FromPixelsProgram;
- },{}],81:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var shader_compiler_1 = require("./shader_compiler");
- var GatherProgram = (function () {
- function GatherProgram(aShape, indicesLength, axis) {
- this.variableNames = ['A', 'indices'];
- var outputShape = aShape.slice();
- outputShape[axis] = indicesLength;
- this.outputShape = outputShape;
- this.rank = outputShape.length;
- var dtype = shader_compiler_1.getCoordsDataType(this.rank);
- var sourceCoords = getSourceCoords(aShape, axis);
- this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n setOutput(getA(" + sourceCoords + "));\n }\n ";
- }
- return GatherProgram;
- }());
- exports.GatherProgram = GatherProgram;
- function getSourceCoords(aShape, axis) {
- var rank = aShape.length;
- if (rank > 4) {
- throw Error("Gather for rank " + rank + " is not yet supported");
- }
- if (rank === 1) {
- return "int(getIndices(resRC))";
- }
- var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w'];
- var sourceCoords = [];
- for (var i = 0; i < aShape.length; i++) {
- if (i === axis) {
- sourceCoords.push("int(getIndices(" + currentCoords[i] + "))");
- }
- else {
- sourceCoords.push("" + currentCoords[i]);
- }
- }
- return sourceCoords.join();
- }
- },{"./shader_compiler":99}],82:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../../environment");
- var util = require("../../util");
- var gpgpu_util = require("./gpgpu_util");
- var tex_util = require("./tex_util");
- var webgl_util = require("./webgl_util");
- var GPGPUContext = (function () {
- function GPGPUContext(gl) {
- this.outputTexture = null;
- this.program = null;
- this.disposed = false;
- this.autoDebugValidate = false;
- this.vertexAttrsAreBound = false;
- this.itemsToPoll = [];
- if (gl != null) {
- this.gl = gl;
- }
- else {
- this.gl = gpgpu_util.createWebGLContext();
- }
- if (environment_1.ENV.get('WEBGL_VERSION') === 1) {
- this.textureFloatExtension =
- webgl_util.getExtensionOrThrow(this.gl, 'OES_texture_float');
- this.colorBufferFloatExtension =
- this.gl.getExtension('WEBGL_color_buffer_float');
- if (!environment_1.ENV.get('WEBGL_RENDER_FLOAT32_ENABLED')) {
- this.textureHalfFloatExtension =
- webgl_util.getExtensionOrThrow(this.gl, 'OES_texture_half_float');
- this.colorBufferHalfFloatExtension =
- this.gl.getExtension('EXT_color_buffer_half_float');
- }
- }
- else {
- this.colorBufferFloatExtension =
- webgl_util.getExtensionOrThrow(this.gl, 'EXT_color_buffer_float');
- }
- this.loseContextExtension =
- webgl_util.getExtensionOrThrow(this.gl, 'WEBGL_lose_context');
- if (environment_1.ENV.get('WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED')) {
- this.getBufferSubDataAsyncExtension =
- this.gl.getExtension('WEBGL_get_buffer_sub_data_async');
- }
- this.vertexBuffer = gpgpu_util.createVertexBuffer(this.gl);
- this.indexBuffer = gpgpu_util.createIndexBuffer(this.gl);
- this.framebuffer = webgl_util.createFramebuffer(this.gl);
- this.textureConfig =
- gpgpu_util.getTextureConfig(this.gl, this.textureHalfFloatExtension);
- }
- GPGPUContext.prototype.dispose = function () {
- var _this = this;
- if (this.disposed) {
- return;
- }
- if (this.program != null) {
- console.warn('Disposing a GPGPUContext that still has a bound WebGLProgram.' +
- ' This is probably a resource leak, delete the program with ' +
- 'GPGPUContext.deleteProgram before disposing.');
- }
- if (this.outputTexture != null) {
- console.warn('Disposing a GPGPUContext that still has a bound output matrix ' +
- 'texture. This is probably a resource leak, delete the output ' +
- 'matrix texture with GPGPUContext.deleteMatrixTexture before ' +
- 'disposing.');
- }
- var gl = this.gl;
- webgl_util.callAndCheck(gl, function () { return gl.finish(); });
- webgl_util.callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, null); });
- webgl_util.callAndCheck(gl, function () { return gl.deleteFramebuffer(_this.framebuffer); });
- webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, null); });
- webgl_util.callAndCheck(gl, function () { return gl.deleteBuffer(_this.vertexBuffer); });
- webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null); });
- webgl_util.callAndCheck(gl, function () { return gl.deleteBuffer(_this.indexBuffer); });
- this.loseContextExtension.loseContext();
- this.disposed = true;
- };
- GPGPUContext.prototype.enableAutomaticDebugValidation = function (enabled) {
- this.autoDebugValidate = enabled;
- webgl_util.enableDebugWebGLErrorChecking(enabled);
- };
- GPGPUContext.prototype.createFloat32MatrixTexture = function (rows, columns) {
- this.throwIfDisposed();
- return gpgpu_util.createFloat32MatrixTexture(this.gl, rows, columns, this.textureConfig);
- };
- GPGPUContext.prototype.createFloat16MatrixTexture = function (rows, columns) {
- this.throwIfDisposed();
- return gpgpu_util.createFloat16MatrixTexture(this.gl, rows, columns, this.textureConfig);
- };
- GPGPUContext.prototype.createUnsignedBytesMatrixTexture = function (rows, columns) {
- this.throwIfDisposed();
- return gpgpu_util.createUnsignedBytesMatrixTexture(this.gl, rows, columns, this.textureConfig);
- };
- GPGPUContext.prototype.uploadPixelDataToTexture = function (texture, pixels) {
- this.throwIfDisposed();
- gpgpu_util.uploadPixelDataToTexture(this.gl, texture, pixels);
- };
- GPGPUContext.prototype.createPackedMatrixTexture = function (rows, columns) {
- this.throwIfDisposed();
- return gpgpu_util.createPackedMatrixTexture(this.gl, rows, columns, this.textureConfig);
- };
- GPGPUContext.prototype.deleteMatrixTexture = function (texture) {
- var _this = this;
- this.throwIfDisposed();
- if (this.outputTexture === texture) {
- webgl_util.unbindColorTextureFromFramebuffer(this.gl, this.framebuffer);
- this.outputTexture = null;
- }
- webgl_util.callAndCheck(this.gl, function () { return _this.gl.deleteTexture(texture); });
- };
- GPGPUContext.prototype.uploadMatrixToTexture = function (texture, rows, columns, matrix) {
- this.throwIfDisposed();
- var numChannels = webgl_util.getNumChannels();
- return gpgpu_util.uploadMatrixToTexture(this.gl, texture, rows, columns, matrix, numChannels, this.textureConfig);
- };
- GPGPUContext.prototype.uploadMatrixToPackedTexture = function (texture, rows, columns, matrix) {
- this.throwIfDisposed();
- return gpgpu_util.uploadMatrixToPackedTexture(this.gl, texture, rows, columns, matrix, this.textureConfig);
- };
- GPGPUContext.prototype.downloadFloat32MatrixFromOutputTexture = function (texture, rows, columns) {
- var _this = this;
- return this.downloadMatrixDriver(texture, function () { return gpgpu_util.downloadFloat32MatrixFromOutputTexture(_this.gl, rows, columns, _this.textureConfig); });
- };
- GPGPUContext.prototype.downloadByteEncodedFloatMatrixFromOutputTexture = function (texture, rows, columns) {
- var _this = this;
- return this.downloadMatrixDriver(texture, function () { return gpgpu_util.downloadByteEncodedFloatMatrixFromOutputTexture(_this.gl, rows, columns, _this.textureConfig); });
- };
- GPGPUContext.prototype.downloadMatrixFromTextureAsync = function (texture, rows, columns) {
- return __awaiter(this, void 0, void 0, function () {
- var _this = this;
- return __generator(this, function (_a) {
- if (this.getBufferSubDataAsyncExtension == null) {
- throw new Error("Cannot download matrix from output texture asynchronously, " +
- "WEBGL_get_buffer_sub_data_async is not enabled.");
- }
- return [2, this.downloadMatrixDriverAsync(texture, function () { return gpgpu_util.downloadMatrixFromOutputTextureAsync(_this.gl, _this.getBufferSubDataAsyncExtension, rows, columns, _this.textureConfig); })];
- });
- });
- };
- GPGPUContext.prototype.downloadMatrixFromPackedTexture = function (texture, rows, columns) {
- var _this = this;
- return this.downloadMatrixDriver(texture, function () { return gpgpu_util.downloadMatrixFromPackedOutputTexture(_this.gl, rows, columns, _this.textureConfig); });
- };
- GPGPUContext.prototype.createProgram = function (fragmentShaderSource) {
- this.throwIfDisposed();
- var gl = this.gl;
- var fragmentShader = webgl_util.createFragmentShader(gl, fragmentShaderSource);
- var vertexShader = gpgpu_util.createVertexShader(gl);
- var program = webgl_util.createProgram(gl);
- webgl_util.callAndCheck(gl, function () { return gl.attachShader(program, vertexShader); });
- webgl_util.callAndCheck(gl, function () { return gl.attachShader(program, fragmentShader); });
- webgl_util.linkProgram(gl, program);
- if (this.autoDebugValidate) {
- webgl_util.validateProgram(gl, program);
- }
- if (!this.vertexAttrsAreBound) {
- this.setProgram(program);
- this.vertexAttrsAreBound = gpgpu_util.bindVertexProgramAttributeStreams(gl, this.program, this.vertexBuffer);
- }
- return program;
- };
- GPGPUContext.prototype.deleteProgram = function (program) {
- var _this = this;
- this.throwIfDisposed();
- if (program === this.program) {
- this.program = null;
- }
- if (program != null) {
- webgl_util.callAndCheck(this.gl, function () { return _this.gl.deleteProgram(program); });
- }
- };
- GPGPUContext.prototype.setProgram = function (program) {
- var _this = this;
- this.throwIfDisposed();
- this.program = program;
- if ((this.program != null) && this.autoDebugValidate) {
- webgl_util.validateProgram(this.gl, this.program);
- }
- webgl_util.callAndCheck(this.gl, function () { return _this.gl.useProgram(program); });
- };
- GPGPUContext.prototype.getUniformLocation = function (program, uniformName, shouldThrow) {
- if (shouldThrow === void 0) { shouldThrow = true; }
- this.throwIfDisposed();
- if (shouldThrow) {
- return webgl_util.getProgramUniformLocationOrThrow(this.gl, program, uniformName);
- }
- else {
- return webgl_util.getProgramUniformLocation(this.gl, program, uniformName);
- }
- };
- GPGPUContext.prototype.getAttributeLocation = function (program, attribute) {
- var _this = this;
- this.throwIfDisposed();
- return webgl_util.callAndCheck(this.gl, function () { return _this.gl.getAttribLocation(program, attribute); });
- };
- GPGPUContext.prototype.getUniformLocationNoThrow = function (program, uniformName) {
- this.throwIfDisposed();
- return this.gl.getUniformLocation(program, uniformName);
- };
- GPGPUContext.prototype.setInputMatrixTexture = function (inputMatrixTexture, uniformLocation, textureUnit) {
- this.throwIfDisposed();
- this.throwIfNoProgram();
- webgl_util.bindTextureToProgramUniformSampler(this.gl, this.program, inputMatrixTexture, uniformLocation, textureUnit);
- };
- GPGPUContext.prototype.setOutputMatrixTexture = function (outputMatrixTexture, rows, columns) {
- this.setOutputMatrixTextureDriver(outputMatrixTexture, columns, rows);
- };
- GPGPUContext.prototype.setOutputPackedMatrixTexture = function (outputPackedMatrixTexture, rows, columns) {
- this.throwIfDisposed();
- var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1];
- this.setOutputMatrixTextureDriver(outputPackedMatrixTexture, width, height);
- };
- GPGPUContext.prototype.setOutputMatrixWriteRegion = function (startRow, numRows, startColumn, numColumns) {
- this.setOutputMatrixWriteRegionDriver(startColumn, startRow, numColumns, numRows);
- };
- GPGPUContext.prototype.setOutputPackedMatrixWriteRegion = function (startRow, numRows, startColumn, numColumns) {
- throw new Error('setOutputPackedMatrixWriteRegion not implemented.');
- };
- GPGPUContext.prototype.debugValidate = function () {
- if (this.program != null) {
- webgl_util.validateProgram(this.gl, this.program);
- }
- webgl_util.validateFramebuffer(this.gl);
- };
- GPGPUContext.prototype.executeProgram = function () {
- this.throwIfDisposed();
- this.throwIfNoProgram();
- var gl = this.gl;
- if (this.autoDebugValidate) {
- this.debugValidate();
- }
- webgl_util.callAndCheck(gl, function () { return gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0); });
- };
- GPGPUContext.prototype.blockUntilAllProgramsCompleted = function () {
- var _this = this;
- this.throwIfDisposed();
- webgl_util.callAndCheck(this.gl, function () { return _this.gl.finish(); });
- };
- GPGPUContext.prototype.getQueryTimerExtension = function () {
- if (this.disjointQueryTimerExtension == null) {
- this.disjointQueryTimerExtension =
- webgl_util.getExtensionOrThrow(this.gl, environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2 ?
- 'EXT_disjoint_timer_query_webgl2' :
- 'EXT_disjoint_timer_query');
- }
- return this.disjointQueryTimerExtension;
- };
- GPGPUContext.prototype.getQueryTimerExtensionWebGL2 = function () {
- return this.getQueryTimerExtension();
- };
- GPGPUContext.prototype.getQueryTimerExtensionWebGL1 = function () {
- return this.getQueryTimerExtension();
- };
- GPGPUContext.prototype.runQuery = function (queryFn) {
- var query = this.beginQuery();
- queryFn();
- this.endQuery();
- return this.pollQueryTime(query);
- };
- GPGPUContext.prototype.beginQuery = function () {
- if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2) {
- var gl2 = this.gl;
- var ext_1 = this.getQueryTimerExtensionWebGL2();
- var query_1 = gl2.createQuery();
- gl2.beginQuery(ext_1.TIME_ELAPSED_EXT, query_1);
- return query_1;
- }
- var ext = this.getQueryTimerExtensionWebGL1();
- var query = ext.createQueryEXT();
- ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, query);
- return query;
- };
- GPGPUContext.prototype.endQuery = function () {
- if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2) {
- var gl2 = this.gl;
- var ext_2 = this.getQueryTimerExtensionWebGL2();
- gl2.endQuery(ext_2.TIME_ELAPSED_EXT);
- return;
- }
- var ext = this.getQueryTimerExtensionWebGL1();
- ext.endQueryEXT(ext.TIME_ELAPSED_EXT);
- };
- GPGPUContext.prototype.isQueryAvailable = function (query, queryTimerVersion) {
- if (queryTimerVersion === 0) {
- return true;
- }
- if (queryTimerVersion === 2) {
- var gl2 = this.gl;
- var ext = this.getQueryTimerExtensionWebGL2();
- var available = gl2.getQueryParameter(query, gl2.QUERY_RESULT_AVAILABLE);
- if (this.disjoint == null) {
- this.disjoint = this.gl.getParameter(ext.GPU_DISJOINT_EXT);
- }
- return available && !this.disjoint;
- }
- else {
- var ext = this.getQueryTimerExtensionWebGL1();
- var available = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_AVAILABLE_EXT);
- if (this.disjoint == null) {
- this.disjoint = this.gl.getParameter(ext.GPU_DISJOINT_EXT);
- }
- return available && !this.disjoint;
- }
- };
- GPGPUContext.prototype.pollQueryTime = function (query) {
- var _this = this;
- return new Promise(function (resolve) {
- var queryTimerVersion = environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION');
- _this.addItemToPoll(function () { return _this.isQueryAvailable(query, queryTimerVersion); }, function () { return resolve(_this.getQueryTime(query, queryTimerVersion)); });
- });
- };
- GPGPUContext.prototype.pollItems = function () {
- var index = binSearchLastTrue(this.itemsToPoll.map(function (x) { return x.isDoneFn; }));
- for (var i = 0; i <= index; ++i) {
- var resolveFn = this.itemsToPoll[i].resolveFn;
- resolveFn();
- }
- this.itemsToPoll = this.itemsToPoll.slice(index + 1);
- };
- GPGPUContext.prototype.addItemToPoll = function (isDoneFn, resolveFn) {
- var _this = this;
- this.itemsToPoll.push({ isDoneFn: isDoneFn, resolveFn: resolveFn });
- if (this.itemsToPoll.length > 1) {
- return;
- }
- util.repeatedTry(function () {
- _this.pollItems();
- return _this.itemsToPoll.length === 0;
- });
- };
- GPGPUContext.prototype.getQueryTime = function (query, queryTimerVersion) {
- if (queryTimerVersion === 0) {
- return null;
- }
- if (queryTimerVersion === 2) {
- var gl2 = this.gl;
- var timeElapsedNanos = gl2.getQueryParameter(query, gl2.QUERY_RESULT);
- return timeElapsedNanos / 1000000;
- }
- else {
- var ext = this.getQueryTimerExtensionWebGL1();
- var timeElapsedNanos = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_EXT);
- return timeElapsedNanos / 1000000;
- }
- };
- GPGPUContext.prototype.downloadMatrixDriverSetup = function (texture) {
- this.throwIfDisposed();
- webgl_util.bindColorTextureToFramebuffer(this.gl, texture, this.framebuffer);
- if (this.autoDebugValidate) {
- webgl_util.validateFramebuffer(this.gl);
- }
- };
- GPGPUContext.prototype.downloadMatrixDriverTeardown = function () {
- if (this.outputTexture != null) {
- webgl_util.bindColorTextureToFramebuffer(this.gl, this.outputTexture, this.framebuffer);
- if (this.autoDebugValidate) {
- webgl_util.validateFramebuffer(this.gl);
- }
- }
- else {
- webgl_util.unbindColorTextureFromFramebuffer(this.gl, this.framebuffer);
- }
- };
- GPGPUContext.prototype.downloadMatrixDriver = function (texture, downloadAndDecode) {
- this.downloadMatrixDriverSetup(texture);
- var result = downloadAndDecode();
- this.downloadMatrixDriverTeardown();
- return result;
- };
- GPGPUContext.prototype.downloadMatrixDriverAsync = function (texture, downloadAndDecode) {
- return __awaiter(this, void 0, void 0, function () {
- var result;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- this.downloadMatrixDriverSetup(texture);
- return [4, downloadAndDecode()];
- case 1:
- result = _a.sent();
- this.downloadMatrixDriverTeardown();
- return [2, result];
- }
- });
- });
- };
- GPGPUContext.prototype.setOutputMatrixTextureDriver = function (outputMatrixTextureMaybePacked, width, height) {
- this.throwIfDisposed();
- var gl = this.gl;
- webgl_util.bindColorTextureToFramebuffer(gl, outputMatrixTextureMaybePacked, this.framebuffer);
- if (this.autoDebugValidate) {
- webgl_util.validateFramebuffer(gl);
- }
- this.outputTexture = outputMatrixTextureMaybePacked;
- webgl_util.callAndCheck(gl, function () { return gl.viewport(0, 0, width, height); });
- webgl_util.callAndCheck(gl, function () { return gl.scissor(0, 0, width, height); });
- };
- GPGPUContext.prototype.setOutputMatrixWriteRegionDriver = function (x, y, width, height) {
- var _this = this;
- this.throwIfDisposed();
- webgl_util.callAndCheck(this.gl, function () { return _this.gl.scissor(x, y, width, height); });
- };
- GPGPUContext.prototype.throwIfDisposed = function () {
- if (this.disposed) {
- throw new Error('Attempted to use disposed GPGPUContext.');
- }
- };
- GPGPUContext.prototype.throwIfNoProgram = function () {
- if (this.program == null) {
- throw new Error('No GPU program is currently set.');
- }
- };
- return GPGPUContext;
- }());
- exports.GPGPUContext = GPGPUContext;
- function binSearchLastTrue(arr) {
- var start = 0;
- var end = arr.length - 1;
- var best = -1;
- while (start <= end) {
- var mid = (start + end) >> 1;
- var isDone = arr[mid]();
- if (isDone) {
- best = mid;
- start = mid + 1;
- }
- else {
- end = mid - 1;
- }
- }
- return best;
- }
- exports.binSearchLastTrue = binSearchLastTrue;
- },{"../../environment":51,"../../util":164,"./gpgpu_util":84,"./tex_util":102,"./webgl_util":107}],83:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var util = require("../../util");
- var shader_compiler = require("./shader_compiler");
- function compileProgram(gpgpu, program, inputs, output) {
- var userCode = program.userCode;
- var inputInfos = inputs.map(function (input, i) {
- var shapeInfo = {
- logicalShape: input.tensor.shape,
- texShape: input.isUniform ? null : input.texData.texShape,
- isUniform: input.isUniform
- };
- return { name: program.variableNames[i], shapeInfo: shapeInfo };
- });
- var inShapeInfos = inputInfos.map(function (x) { return x.shapeInfo; });
- var outShapeInfo = {
- logicalShape: output.tensor.shape,
- texShape: output.texData.texShape,
- isUniform: false
- };
- var source = shader_compiler.makeShader(inputInfos, outShapeInfo, userCode, program.supportsBroadcasting === true);
- var webGLProgram = gpgpu.createProgram(source);
- var uniformLocations = {};
- for (var i = 0; i < program.variableNames.length; i++) {
- var uniformName = program.variableNames[i];
- var shouldThrow = false;
- uniformLocations[uniformName] =
- gpgpu.getUniformLocation(webGLProgram, uniformName, shouldThrow);
- }
- return {
- program: program,
- source: source,
- webGLProgram: webGLProgram,
- uniformLocations: uniformLocations,
- gpgpu: gpgpu,
- inShapeInfos: inShapeInfos,
- outShapeInfo: outShapeInfo
- };
- }
- exports.compileProgram = compileProgram;
- function validateBinaryAndProgram(shapeInfos, inputs) {
- if (shapeInfos.length !== inputs.length) {
- throw Error("Binary was compiled with " + shapeInfos.length + " inputs, but " +
- ("was executed with " + inputs.length + " inputs"));
- }
- shapeInfos.forEach(function (s, i) {
- var shapeA = s.logicalShape;
- var input = inputs[i];
- var shapeB = input.tensor.shape;
- if (!util.arraysEqual(shapeA, shapeB)) {
- throw Error("Binary was compiled with different shapes than " +
- ("the current args. Shapes " + shapeA + " and " + shapeB + " must match"));
- }
- if (s.isUniform && input.isUniform) {
- return;
- }
- var texShapeA = s.texShape;
- var texShapeB = input.isUniform ? null : input.texData.texShape;
- if (!util.arraysEqual(texShapeA, texShapeB)) {
- throw Error("Binary was compiled with different texture shapes than the" +
- (" current args. Shape " + texShapeA + " and " + texShapeB + " must match"));
- }
- });
- }
- function runProgram(binary, inputs, output, customSetup) {
- validateBinaryAndProgram(binary.inShapeInfos, inputs);
- validateBinaryAndProgram([binary.outShapeInfo], [output]);
- var outTex = output.texData.texture;
- var outTexShape = output.texData.texShape;
- var gpgpu = binary.gpgpu;
- gpgpu.setOutputMatrixTexture(outTex, outTexShape[0], outTexShape[1]);
- gpgpu.setProgram(binary.webGLProgram);
- inputs.forEach(function (input, i) {
- var variableName = binary.program.variableNames[i];
- var variableUniformLocation = binary.uniformLocations[variableName];
- if (variableUniformLocation != null) {
- if (input.isUniform) {
- if (input.tensor.size === 1) {
- gpgpu.gl.uniform1f(variableUniformLocation, input.tensor.dataSync()[0]);
- }
- else {
- var vals = input.tensor.dataSync();
- if (!(vals instanceof Float32Array)) {
- vals = new Float32Array(vals);
- }
- gpgpu.gl.uniform1fv(variableUniformLocation, vals);
- }
- return;
- }
- var tex = input.texData.texture;
- gpgpu.setInputMatrixTexture(tex, variableUniformLocation, i);
- }
- });
- if (customSetup != null) {
- customSetup(gpgpu, binary.webGLProgram);
- }
- gpgpu.executeProgram();
- }
- exports.runProgram = runProgram;
- function makeShaderKey(program, inputs, output) {
- var keyInputs = '';
- inputs.concat(output).forEach(function (x) {
- keyInputs +=
- x.tensor.shape + "_" + (x.isUniform ? 'uniform' : x.texData.texShape);
- });
- var keyUserCode = program.userCode;
- var keyBroadcast = (program.supportsBroadcasting === true).toString();
- var key = program.constructor.name;
- key += '_' + keyBroadcast + '_' + keyInputs + '_' + keyUserCode;
- return key;
- }
- exports.makeShaderKey = makeShaderKey;
- },{"../../util":164,"./shader_compiler":99}],84:[function(require,module,exports){
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../../environment");
- var tex_util = require("./tex_util");
- var webgl_util = require("./webgl_util");
- function getWebGLContextAttributes() {
- return {
- alpha: false,
- antialias: false,
- premultipliedAlpha: false,
- preserveDrawingBuffer: false,
- depth: false,
- stencil: false,
- failIfMajorPerformanceCaveat: true
- };
- }
- exports.getWebGLContextAttributes = getWebGLContextAttributes;
- function createWebGLContext(canvas) {
- var attributes = getWebGLContextAttributes();
- var gl;
- if (canvas != null) {
- gl = webgl_util.createWebGLRenderingContextFromCanvas(canvas, attributes);
- }
- else {
- gl = webgl_util.createWebGLRenderingContext(attributes);
- }
- webgl_util.callAndCheck(gl, function () { return gl.disable(gl.DEPTH_TEST); });
- webgl_util.callAndCheck(gl, function () { return gl.disable(gl.STENCIL_TEST); });
- webgl_util.callAndCheck(gl, function () { return gl.disable(gl.BLEND); });
- webgl_util.callAndCheck(gl, function () { return gl.disable(gl.DITHER); });
- webgl_util.callAndCheck(gl, function () { return gl.disable(gl.POLYGON_OFFSET_FILL); });
- webgl_util.callAndCheck(gl, function () { return gl.disable(gl.SAMPLE_COVERAGE); });
- webgl_util.callAndCheck(gl, function () { return gl.enable(gl.SCISSOR_TEST); });
- webgl_util.callAndCheck(gl, function () { return gl.enable(gl.CULL_FACE); });
- webgl_util.callAndCheck(gl, function () { return gl.cullFace(gl.BACK); });
- return gl;
- }
- exports.createWebGLContext = createWebGLContext;
- function createVertexShader(gl) {
- var vertexShaderSource = "\n precision highp float;\n attribute vec3 clipSpacePos;\n attribute vec2 uv;\n varying vec2 resultUV;\n\n void main() {\n gl_Position = vec4(clipSpacePos, 1);\n resultUV = uv;\n }";
- return webgl_util.createVertexShader(gl, vertexShaderSource);
- }
- exports.createVertexShader = createVertexShader;
- function createVertexBuffer(gl) {
- var vertexArray = new Float32Array([-1, 1, 0, 0, 1, -1, -1, 0, 0, 0, 1, 1, 0, 1, 1, 1, -1, 0, 1, 0]);
- return webgl_util.createStaticVertexBuffer(gl, vertexArray);
- }
- exports.createVertexBuffer = createVertexBuffer;
- function createIndexBuffer(gl) {
- var triangleVertexIndices = new Uint16Array([0, 1, 2, 2, 1, 3]);
- return webgl_util.createStaticIndexBuffer(gl, triangleVertexIndices);
- }
- exports.createIndexBuffer = createIndexBuffer;
- function getTextureConfig(gl, textureHalfFloatExtension) {
- var glany = gl;
- var internalFormatFloat;
- var internalFormatHalfFloat;
- var internalFormatPackedFloat;
- var textureFormatFloat;
- var downloadTextureFormat;
- var downloadUnpackNumChannels;
- var defaultNumChannels;
- var textureTypeHalfFloat;
- if (environment_1.ENV.get('WEBGL_VERSION') === 2) {
- internalFormatFloat = glany.R32F;
- internalFormatHalfFloat = glany.R16F;
- internalFormatPackedFloat = glany.RGBA32F;
- textureFormatFloat = glany.RED;
- downloadUnpackNumChannels = 4;
- defaultNumChannels = 1;
- textureTypeHalfFloat = glany.HALF_FLOAT;
- }
- else {
- internalFormatFloat = gl.RGBA;
- internalFormatHalfFloat = gl.RGBA;
- internalFormatPackedFloat = glany.RGBA;
- textureFormatFloat = gl.RGBA;
- downloadUnpackNumChannels = 4;
- defaultNumChannels = 4;
- textureTypeHalfFloat = textureHalfFloatExtension != null ?
- textureHalfFloatExtension.HALF_FLOAT_OES :
- null;
- }
- downloadTextureFormat = gl.RGBA;
- return {
- internalFormatFloat: internalFormatFloat,
- internalFormatHalfFloat: internalFormatHalfFloat,
- internalFormatPackedFloat: internalFormatPackedFloat,
- textureFormatFloat: textureFormatFloat,
- downloadTextureFormat: downloadTextureFormat,
- downloadUnpackNumChannels: downloadUnpackNumChannels,
- defaultNumChannels: defaultNumChannels,
- textureTypeHalfFloat: textureTypeHalfFloat
- };
- }
- exports.getTextureConfig = getTextureConfig;
- function createAndConfigureTexture(gl, width, height, internalFormat, textureFormat, textureType) {
- webgl_util.validateTextureSize(gl, width, height);
- var texture = webgl_util.createTexture(gl);
- var tex2d = gl.TEXTURE_2D;
- webgl_util.callAndCheck(gl, function () { return gl.bindTexture(tex2d, texture); });
- webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); });
- webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); });
- webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MIN_FILTER, gl.NEAREST); });
- webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MAG_FILTER, gl.NEAREST); });
- webgl_util.callAndCheck(gl, function () { return gl.texImage2D(tex2d, 0, internalFormat, width, height, 0, textureFormat, textureType, null); });
- webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); });
- return texture;
- }
- function createFloat32MatrixTexture(gl, rows, columns, textureConfig) {
- var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1];
- return createAndConfigureTexture(gl, width, height, textureConfig.internalFormatFloat, textureConfig.textureFormatFloat, gl.FLOAT);
- }
- exports.createFloat32MatrixTexture = createFloat32MatrixTexture;
- function createFloat16MatrixTexture(gl, rows, columns, textureConfig) {
- var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1];
- return createAndConfigureTexture(gl, width, height, textureConfig.internalFormatFloat, textureConfig.textureFormatFloat, textureConfig.textureTypeHalfFloat);
- }
- exports.createFloat16MatrixTexture = createFloat16MatrixTexture;
- function createUnsignedBytesMatrixTexture(gl, rows, columns, textureConfig) {
- var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1];
- return createAndConfigureTexture(gl, width, height, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE);
- }
- exports.createUnsignedBytesMatrixTexture = createUnsignedBytesMatrixTexture;
- function createPackedMatrixTexture(gl, rows, columns, textureConfig) {
- var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1];
- return createAndConfigureTexture(gl, width, height, textureConfig.internalFormatPackedFloat, gl.RGBA, gl.FLOAT);
- }
- exports.createPackedMatrixTexture = createPackedMatrixTexture;
- function bindVertexProgramAttributeStreams(gl, program, vertexBuffer) {
- var posOffset = 0;
- var uvOffset = 3 * 4;
- var stride = (3 * 4) + (2 * 4);
- webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); });
- var success = webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'clipSpacePos', vertexBuffer, 3, stride, posOffset);
- return success &&
- webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'uv', vertexBuffer, 2, stride, uvOffset);
- }
- exports.bindVertexProgramAttributeStreams = bindVertexProgramAttributeStreams;
- function uploadPixelDataToTexture(gl, texture, pixels) {
- webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); });
- webgl_util.callAndCheck(gl, function () { return gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, pixels); });
- webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); });
- }
- exports.uploadPixelDataToTexture = uploadPixelDataToTexture;
- function uploadDataToTexture(gl, texture, width, height, data, textureFormat) {
- webgl_util.validateTextureSize(gl, width, height);
- webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); });
- webgl_util.callAndCheck(gl, function () { return gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height, textureFormat, gl.FLOAT, data); });
- webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); });
- }
- function uploadMatrixToTexture(gl, texture, rows, columns, matrix, numChannels, textureConfig) {
- var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1];
- var unpackedArray;
- if (textureConfig.defaultNumChannels === 1) {
- unpackedArray = matrix;
- }
- else {
- unpackedArray =
- new Float32Array(tex_util.getUnpackedArraySizeFromMatrixSize(matrix.length, numChannels));
- tex_util.encodeMatrixToUnpackedArray(matrix, unpackedArray, numChannels);
- }
- uploadDataToTexture(gl, texture, w, h, unpackedArray, textureConfig.textureFormatFloat);
- }
- exports.uploadMatrixToTexture = uploadMatrixToTexture;
- function uploadMatrixToPackedTexture(gl, texture, rows, columns, matrix, textureConfig) {
- var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1];
- var packedRGBA = new Float32Array(tex_util.getPackedRGBAArraySizeFromMatrixShape(rows, columns));
- tex_util.encodeMatrixToPackedRGBA(matrix, rows, columns, packedRGBA);
- uploadDataToTexture(gl, texture, w, h, packedRGBA, gl.RGBA);
- }
- exports.uploadMatrixToPackedTexture = uploadMatrixToPackedTexture;
- function downloadMatrixFromOutputTextureAsync(gl, getBufferSubDataAsyncExtension, rows, columns, textureConfig) {
- return __awaiter(this, void 0, void 0, function () {
- var gl2, downloadTarget, bufferSizeBytes, buffer, matrix;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- gl2 = gl;
- downloadTarget = new Float32Array(tex_util.getUnpackedArraySizeFromMatrixSize(rows * columns, textureConfig.downloadUnpackNumChannels));
- bufferSizeBytes = downloadTarget instanceof Float32Array ?
- downloadTarget.length * 4 :
- downloadTarget;
- buffer = gl.createBuffer();
- webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl2.PIXEL_PACK_BUFFER, buffer); });
- webgl_util.callAndCheck(gl, function () { return gl.bufferData(gl2.PIXEL_PACK_BUFFER, bufferSizeBytes, gl.STATIC_DRAW); });
- webgl_util.callAndCheck(gl, function () { return gl2.readPixels(0, 0, columns, rows, gl.RGBA, gl.FLOAT, 0); });
- return [4, getBufferSubDataAsyncExtension.getBufferSubDataAsync(gl2.PIXEL_PACK_BUFFER, 0, downloadTarget)];
- case 1:
- _a.sent();
- matrix = new Float32Array(rows * columns);
- tex_util.decodeMatrixFromUnpackedArray(downloadTarget, matrix, textureConfig.downloadUnpackNumChannels);
- return [2, matrix];
- }
- });
- });
- }
- exports.downloadMatrixFromOutputTextureAsync = downloadMatrixFromOutputTextureAsync;
- function downloadFloat32MatrixFromOutputTexture(gl, rows, columns, textureConfig) {
- var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1];
- var downloadTarget = new Float32Array(tex_util.getUnpackedArraySizeFromMatrixSize(rows * columns, textureConfig.downloadUnpackNumChannels));
- webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, w, h, textureConfig.downloadTextureFormat, gl.FLOAT, downloadTarget); });
- var matrix = new Float32Array(rows * columns);
- tex_util.decodeMatrixFromUnpackedArray(downloadTarget, matrix, textureConfig.downloadUnpackNumChannels);
- return matrix;
- }
- exports.downloadFloat32MatrixFromOutputTexture = downloadFloat32MatrixFromOutputTexture;
- function downloadByteEncodedFloatMatrixFromOutputTexture(gl, rows, columns, textureConfig) {
- var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1];
- var numChannels = 4;
- var downloadTarget = new Uint8Array(tex_util.getUnpackedArraySizeFromMatrixSize(rows * columns, numChannels));
- webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, w, h, textureConfig.downloadTextureFormat, gl.UNSIGNED_BYTE, downloadTarget); });
- return new Float32Array(downloadTarget.buffer);
- }
- exports.downloadByteEncodedFloatMatrixFromOutputTexture = downloadByteEncodedFloatMatrixFromOutputTexture;
- function downloadMatrixFromPackedOutputTexture(gl, rows, columns, textureConfig) {
- var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1];
- var packedRGBA = new Float32Array(tex_util.getPackedRGBAArraySizeFromMatrixShape(rows, columns));
- webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, w, h, gl.RGBA, gl.FLOAT, packedRGBA); });
- var matrix = new Float32Array(rows * columns);
- return tex_util.decodeMatrixFromPackedRGBA(packedRGBA, rows, columns, matrix);
- }
- exports.downloadMatrixFromPackedOutputTexture = downloadMatrixFromPackedOutputTexture;
- },{"../../environment":51,"./tex_util":102,"./webgl_util":107}],85:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var shader_compiler_1 = require("./shader_compiler");
- var WhereProgram = (function () {
- function WhereProgram(cRank, shape, rank) {
- this.variableNames = ['c', 'a', 'b'];
- this.outputShape = shape;
- var cCoords;
- var abCoords;
- if (rank > 4) {
- throw Error("Where for rank " + rank + " is not yet supported");
- }
- if (rank === 1) {
- abCoords = "resRC";
- cCoords = "resRC";
- }
- else {
- var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w'];
- var cCoordVars = [];
- var abCoordVars = [];
- for (var i = 0; i < shape.length; i++) {
- abCoordVars.push("" + currentCoords[i]);
- if (i < cRank) {
- cCoordVars.push("" + currentCoords[i]);
- }
- }
- cCoords = cCoordVars.join();
- abCoords = abCoordVars.join();
- }
- var dtype = shader_compiler_1.getCoordsDataType(rank);
- this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n float cVal = getC(" + cCoords + ");\n if (cVal >= 1.0) {\n setOutput(getA(" + abCoords + "));\n } else {\n setOutput(getB(" + abCoords + "));\n }\n }\n ";
- }
- return WhereProgram;
- }());
- exports.WhereProgram = WhereProgram;
- },{"./shader_compiler":99}],86:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var LRNProgram = (function () {
- function LRNProgram(xShape, radius, bias, alpha, beta) {
- this.variableNames = ['x'];
- this.outputShape = [];
- var rad = radius;
- var maxD = xShape[3] - 1;
- this.outputShape = xShape;
- var powOperator;
- var basis = "float(" + bias + ") + float(" + alpha + ") * sum";
- if (beta === 0.5) {
- powOperator = "inversesqrt(" + basis + ")";
- }
- else if (beta === 1.0) {
- powOperator = "1.0/(" + basis + ")";
- }
- else {
- powOperator = "exp(log(" + basis + ") * float(-" + beta + "));";
- }
- this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n int d = coords[3];\n float x = getX(b, r, c, d);\n float sum = 0.0;\n for (int j = -" + rad + "; j <= " + rad + "; j++) {\n int idx = d + j;\n if (idx >= 0 && idx <= " + maxD + ") {\n float z = getX(b, r, c, idx);\n sum += z * z;\n }\n }\n float val = x * " + powOperator + ";\n setOutput(val);\n }\n ";
- }
- return LRNProgram;
- }());
- exports.LRNProgram = LRNProgram;
- },{}],87:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var MaxPool2DBackpropProgram = (function () {
- function MaxPool2DBackpropProgram(convInfo) {
- this.variableNames = ['dy', 'maxPos'];
- this.outputShape = convInfo.inShape;
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var padTop = filterHeight - 1 - convInfo.padInfo.top;
- var padLeft = filterWidth - 1 - convInfo.padInfo.left;
- var lastIndex = filterHeight * filterWidth - 1;
- this.userCode = "\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + strideHeight + ".0;\n\n if (dyR < 0.0 || dyR >= " + convInfo.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + strideWidth + ".0;\n\n if (dyC < 0.0 || dyC >= " + convInfo.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n int maxPosValue = " + lastIndex + " - int(getMaxPos(b, idyR, idyC, d));\n\n // Get the current value, check it against the value from the\n // position matrix.\n int curPosValue = wR * " + filterWidth + " + wC;\n float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n dotProd += dyValue * mask;\n }\n }\n setOutput(dotProd);\n }\n ";
- }
- return MaxPool2DBackpropProgram;
- }());
- exports.MaxPool2DBackpropProgram = MaxPool2DBackpropProgram;
- },{}],88:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var MatMulProgram = (function () {
- function MatMulProgram(aShape, bShape, transposeA, transposeB) {
- if (transposeA === void 0) { transposeA = false; }
- if (transposeB === void 0) { transposeB = false; }
- this.variableNames = ['matrixA', 'matrixB'];
- var outerShapeA = transposeA ? aShape[1] : aShape[0];
- var outerShapeB = transposeB ? bShape[0] : bShape[1];
- var sharedDim = transposeA ? aShape[0] : aShape[1];
- this.outputShape = [outerShapeA, outerShapeB];
- var aSnippetFromOffset = function (vec4Offset, indexVar) {
- return transposeA ? indexVar + " + " + vec4Offset + ", aRow" :
- "aRow, " + indexVar + " + " + vec4Offset;
- };
- var bSnippetFromOffset = function (vec4Offset, indexVar) {
- return transposeB ? "bCol, " + indexVar + " + " + vec4Offset :
- indexVar + " + " + vec4Offset + ", bCol";
- };
- var sharedDimNearestVec4 = Math.floor(sharedDim / 4) * 4;
- var sharedDimVec4Remainder = sharedDim % 4;
- this.userCode = " float dotARowBCol(int aRow, int bCol) {\n float result = 0.0;\n for (int i = 0; i < " + sharedDimNearestVec4 + "; i += 4) {\n vec4 a = vec4(\n getMatrixA(" + aSnippetFromOffset(0, 'i') + "),\n getMatrixA(" + aSnippetFromOffset(1, 'i') + "),\n getMatrixA(" + aSnippetFromOffset(2, 'i') + "),\n getMatrixA(" + aSnippetFromOffset(3, 'i') + ")\n );\n vec4 b = vec4(\n getMatrixB(" + bSnippetFromOffset(0, 'i') + "),\n getMatrixB(" + bSnippetFromOffset(1, 'i') + "),\n getMatrixB(" + bSnippetFromOffset(2, 'i') + "),\n getMatrixB(" + bSnippetFromOffset(3, 'i') + ")\n );\n\n result += dot(a, b);\n }\n\n if (" + (sharedDimVec4Remainder === 1) + ") {\n result += getMatrixA(" + aSnippetFromOffset(0, sharedDimNearestVec4) + ") *\n getMatrixB(" + bSnippetFromOffset(0, sharedDimNearestVec4) + ");\n } else if (" + (sharedDimVec4Remainder === 2) + ") {\n vec2 a = vec2(\n getMatrixA(" + aSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixA(" + aSnippetFromOffset(1, sharedDimNearestVec4) + ")\n );\n vec2 b = vec2(\n getMatrixB(" + bSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixB(" + bSnippetFromOffset(1, sharedDimNearestVec4) + ")\n );\n result += dot(a, b);\n } else if (" + (sharedDimVec4Remainder === 3) + ") {\n vec3 a = vec3(\n getMatrixA(" + aSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixA(" + aSnippetFromOffset(1, sharedDimNearestVec4) + "),\n getMatrixA(" + aSnippetFromOffset(2, sharedDimNearestVec4) + ")\n );\n vec3 b = vec3(\n getMatrixB(" + bSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixB(" + bSnippetFromOffset(1, sharedDimNearestVec4) + "),\n getMatrixB(" + bSnippetFromOffset(2, sharedDimNearestVec4) + ")\n );\n result += dot(a, b);\n }\n\n return result;\n }\n\n void main() {\n ivec2 resRC = getOutputCoords();\n setOutput(dotARowBCol(resRC.x, resRC.y));\n }\n ";
- }
- return MatMulProgram;
- }());
- exports.MatMulProgram = MatMulProgram;
- },{}],89:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var MultinomialProgram = (function () {
- function MultinomialProgram(batchSize, numOutcomes, numSamples) {
- this.variableNames = ['probs'];
- this.outputShape = [batchSize, numSamples];
- this.userCode = "\n uniform float seed;\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n\n float r = random(seed);\n float cdf = 0.0;\n\n for (int i = 0; i < " + (numOutcomes - 1) + "; i++) {\n cdf += getProbs(batch, i);\n\n if (r < cdf) {\n setOutput(float(i));\n return;\n }\n }\n\n // If no other event happened, last event happened.\n setOutput(float(" + (numOutcomes - 1) + "));\n }\n ";
- }
- MultinomialProgram.prototype.getCustomSetupFunc = function (seed) {
- var _this = this;
- return function (gpgpu, webGLProgram) {
- if (_this.seedLoc == null) {
- _this.seedLoc = gpgpu.getUniformLocation(webGLProgram, 'seed');
- }
- gpgpu.gl.uniform1f(_this.seedLoc, seed);
- };
- };
- return MultinomialProgram;
- }());
- exports.MultinomialProgram = MultinomialProgram;
- },{}],90:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var OneHotProgram = (function () {
- function OneHotProgram(numIndices, depth, onValue, offValue) {
- this.variableNames = ['indices'];
- this.outputShape = [numIndices, depth];
- this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int index = round(getIndices(coords.x));\n setOutput(mix(float(" + offValue + "), float(" + onValue + "),\n float(index == coords.y)));\n }\n ";
- }
- return OneHotProgram;
- }());
- exports.OneHotProgram = OneHotProgram;
- },{}],91:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var shader_compiler_1 = require("./shader_compiler");
- var PadProgram = (function () {
- function PadProgram(xShape, paddings, constantValue) {
- this.variableNames = ['x'];
- this.outputShape = paddings.map(function (p, i) { return p[0] + xShape[i] + p[1]; });
- var rank = xShape.length;
- var type = shader_compiler_1.getCoordsDataType(rank);
- var start = paddings.map(function (p) { return p[0]; }).join(',');
- var end = paddings.map(function (p, i) { return p[0] + xShape[i]; }).join(',');
- var unpackedCoords = ['coords[0]', 'coords[1]', 'coords[2]', 'coords[3]'].slice(0, rank);
- if (rank === 1) {
- this.userCode = "\n int start = " + start + ";\n int end = " + end + ";\n\n void main() {\n int outC = getOutputCoords();\n if (outC < start || outC >= end) {\n setOutput(float(" + constantValue + "));\n } else {\n setOutput(getX(outC - start));\n }\n }\n ";
- return;
- }
- this.userCode = "\n " + type + " start = " + type + "(" + start + ");\n " + type + " end = " + type + "(" + end + ");\n\n void main() {\n " + type + " outC = getOutputCoords();\n if (any(lessThan(outC, start)) || any(greaterThanEqual(outC, end))) {\n setOutput(float(" + constantValue + "));\n } else {\n " + type + " coords = outC - start;\n setOutput(getX(" + unpackedCoords + "));\n }\n }\n ";
- }
- return PadProgram;
- }());
- exports.PadProgram = PadProgram;
- },{"./shader_compiler":99}],92:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var Pool2DProgram = (function () {
- function Pool2DProgram(convInfo, poolType, computePositions) {
- this.variableNames = ['x'];
- if (poolType === 'avg' && computePositions) {
- throw new Error('Cannot compute positions for average pool.');
- }
- var filterHeight = convInfo.filterHeight;
- var filterWidth = convInfo.filterWidth;
- var strideHeight = convInfo.strideHeight;
- var strideWidth = convInfo.strideWidth;
- var padTop = convInfo.padInfo.top;
- var padLeft = convInfo.padInfo.left;
- this.outputShape = convInfo.outShape;
- var isAvgPool = poolType === 'avg';
- var initializationValue = '0.0';
- if (!isAvgPool) {
- initializationValue = '-1.0 / 0.0';
- }
- if (computePositions) {
- var compareOp_1 = '>=';
- this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n float minMaxValue = 0.0;\n float minMaxValueFound = 0.0;\n int minMaxPosition = 0;\n float avgValue = 0.0;\n\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n continue;\n }\n\n float value = getX(batch, xR, xC, d);\n\n // If a min / max value has already been found, use it. If not,\n // use the current value.\n float currMinMaxValue = mix(\n value, minMaxValue, minMaxValueFound);\n if (value " + compareOp_1 + " currMinMaxValue) {\n minMaxValue = value;\n minMaxValueFound = 1.0;\n minMaxPosition = wR * " + filterWidth + " + wC;\n }\n }\n }\n setOutput(float(minMaxPosition));\n }\n ";
- return;
- }
- var compareOp = 'max';
- var returnValue = poolType + "(" + poolType + "(" + poolType + "(" +
- 'minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])';
- if (poolType === 'avg') {
- returnValue = "avgValue / count";
- }
- var filterWidthNearestVec4 = Math.floor(filterWidth / 4) * 4;
- var filterWidthVec4Remainder = filterWidth % 4;
- var updateSnippet = "\n if (" + isAvgPool + ") {\n avgValue += dot(values, ones);\n } else {\n minMaxValue = " + compareOp + "(values, minMaxValue);\n }\n ";
- this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n const float initializationValue = " + initializationValue + ";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float count = 0.0;\n\n float getValue(int batch, int xR, int xC, int d) {\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n return initializationValue;\n }\n count += 1.0;\n return getX(batch, xR, xC, d);\n }\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n vec4 minMaxValue = vec4(" + initializationValue + ");\n float avgValue = 0.0;\n count = 0.0;\n\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidthNearestVec4 + "; wC += 4) {\n int xC = xCCorner + wC;\n\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n getValue(batch, xR, xC + 2, d),\n getValue(batch, xR, xC + 3, d)\n );\n\n " + updateSnippet + "\n }\n\n int xC = xCCorner + " + filterWidthNearestVec4 + ";\n if (" + (filterWidthVec4Remainder === 1) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n " + updateSnippet + "\n } else if (" + (filterWidthVec4Remainder === 2) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n initializationValue,\n initializationValue\n );\n\n " + updateSnippet + "\n } else if (" + (filterWidthVec4Remainder === 3) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n getValue(batch, xR, xC + 2, d),\n initializationValue\n );\n\n " + updateSnippet + "\n }\n }\n setOutput(" + returnValue + ");\n }\n ";
- }
- return Pool2DProgram;
- }());
- exports.Pool2DProgram = Pool2DProgram;
- },{}],93:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var ReduceProgram = (function () {
- function ReduceProgram(reduceInfo, reduceType) {
- this.variableNames = ['x'];
- var windowSize = reduceInfo.windowSize;
- var batchSize = reduceInfo.batchSize;
- var inSize = reduceInfo.inSize;
- var outSize = Math.ceil(inSize / windowSize);
- this.outputShape = [batchSize, outSize];
- var initializationValue = '0.0';
- var compareOp = "";
- if (reduceType === 'min') {
- initializationValue = '1.0 / 0.0';
- compareOp = "min";
- }
- else if (reduceType === 'max') {
- initializationValue = '-1.0 / 0.0';
- compareOp = "max";
- }
- var returnValue = reduceType + "(" + reduceType + "(" + reduceType + "(" +
- 'minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])';
- if (reduceType === 'sum') {
- returnValue = "sumValue";
- }
- else if (reduceType === 'all') {
- returnValue = "allValue";
- }
- var windowSizeNearestVec4 = Math.floor(windowSize / 4) * 4;
- var windowSizeVec4Remainder = windowSize % 4;
- var updateSnippet = "\n if (" + (reduceType === 'sum') + ") {\n sumValue += dot(values, ones);\n } else {\n minMaxValue = " + compareOp + "(values, minMaxValue);\n }\n ";
- var vecType = "vec4";
- if (reduceType === 'all') {
- initializationValue = '1.0';
- updateSnippet = "\n bool reducedAllValue = all(values);\n float floatedReducedAllValue = float(reducedAllValue);\n allValue = float(allValue >= 1.0 && floatedReducedAllValue >= 1.0);\n ";
- vecType = "bvec4";
- }
- var checkOutOfBounds = '';
- if (inSize % windowSize > 0) {
- checkOutOfBounds = "\n if (inIdx < 0 || inIdx >= " + inSize + ") {\n return initializationValue;\n }\n ";
- }
- this.userCode = "\n const float initializationValue = " + initializationValue + ";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float getValue(int batch, int inIdx) {\n " + checkOutOfBounds + "\n return getX(batch, inIdx);\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * " + windowSize + ";\n\n vec4 minMaxValue = vec4(" + initializationValue + ");\n float sumValue = 0.0;\n float allValue = 1.0;\n\n for (int i = 0; i < " + windowSizeNearestVec4 + "; i += 4) {\n int inIdx = inOffset + i;\n " + vecType + " values = " + vecType + "(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n getValue(batch, inIdx + 3)\n );\n\n " + updateSnippet + "\n }\n\n int inIdx = inOffset + " + windowSizeNearestVec4 + ";\n if (" + (windowSizeVec4Remainder === 1) + ") {\n " + vecType + " values = " + vecType + "(\n getValue(batch, inIdx),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n " + updateSnippet + "\n } else if (" + (windowSizeVec4Remainder === 2) + ") {\n " + vecType + " values = " + vecType + "(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n initializationValue,\n initializationValue\n );\n\n " + updateSnippet + "\n } else if (" + (windowSizeVec4Remainder === 3) + ") {\n " + vecType + " values = " + vecType + "(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n initializationValue\n );\n\n " + updateSnippet + "\n }\n setOutput(" + returnValue + ");\n }\n ";
- }
- return ReduceProgram;
- }());
- exports.ReduceProgram = ReduceProgram;
- },{}],94:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var ResizeBilinearBackpropProgram = (function () {
- function ResizeBilinearBackpropProgram(dy, x, alignCorners) {
- this.variableNames = ['dy'];
- this.outputShape = [];
- this.outputShape = x.shape;
- var _a = x.shape, xHeight = _a[1], xWidth = _a[2];
- var _b = dy.shape, yHeight = _b[1], yWidth = _b[2];
- var effectiveXSize = [
- (alignCorners && yHeight > 1) ? xHeight - 1 : xHeight,
- (alignCorners && yWidth > 1) ? xWidth - 1 : xWidth
- ];
- var effectiveYSize = [
- (alignCorners && yHeight > 1) ? yHeight - 1 : yHeight,
- (alignCorners && yWidth > 1) ? yWidth - 1 : yWidth
- ];
- var heightScale = effectiveXSize[0] / effectiveYSize[0];
- var widthScale = effectiveXSize[1] / effectiveYSize[1];
- var invHeightScale = 1 / heightScale;
- var invWidthScale = 1 / widthScale;
- var winHeight = (Math.ceil(invHeightScale) * 2) + 2;
- var winWidth = (Math.ceil(invWidthScale) * 2) + 2;
- this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n int r = coords[1];\n int c = coords[2];\n\n float accumulator = 0.0;\n\n const float heightScale = float(" + heightScale + ");\n const float widthScale = float(" + widthScale + ");\n\n const float invHeightScale = float(" + invHeightScale + ");\n const float invWidthScale = float(" + invWidthScale + ");\n\n const int winHeight = int(" + winHeight + ");\n const int winWidth = int(" + winWidth + ");\n\n // Compute bounds for where in dy we will look\n float startRLerp = floor(float(r) * invHeightScale);\n int startDyR = int(startRLerp - float(winHeight / 2));\n\n float startCLerp = floor(float(c) * invWidthScale);\n int startDyC = int(startCLerp - float(winWidth / 2));\n\n // Loop over dy\n for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {\n int dyR = dyROffset + startDyR;\n\n // Guard against the window exceeding the bounds of dy\n if (dyR < 0 || dyR >= " + yHeight + ") {\n continue;\n }\n\n for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {\n int dyC = dyCOffset + startDyC;\n\n // Guard against the window exceeding the bounds of dy\n if (dyC < 0 || dyC >= " + yWidth + ") {\n continue;\n }\n\n float dxR = float(dyR) * heightScale;\n int topDxRIndex = int(floor(dxR));\n int bottomDxRIndex = int(min(ceil(dxR), " + (xHeight - 1) + ".0));\n float dxRLerp = dxR - float(topDxRIndex);\n float inverseDxRLerp = 1.0 - dxRLerp;\n\n float dxC = float(dyC) * widthScale;\n int leftDxCIndex = int(floor(dxC));\n int rightDxCIndex = int(min(ceil(dxC), " + (xWidth - 1) + ".0));\n float dxCLerp = dxC - float(leftDxCIndex);\n float inverseDxCLerp = 1.0 - dxCLerp;\n\n if (r == topDxRIndex && c == leftDxCIndex) {\n // topLeft\n accumulator +=\n getDy(b, dyR, dyC, d) * inverseDxRLerp * inverseDxCLerp;\n }\n\n if (r == topDxRIndex && c == rightDxCIndex) {\n // topRight\n accumulator += getDy(b, dyR, dyC, d) * inverseDxRLerp * dxCLerp;\n }\n\n if (r == bottomDxRIndex && c == leftDxCIndex) {\n // bottomLeft\n accumulator += getDy(b, dyR, dyC, d) * dxRLerp * inverseDxCLerp;\n }\n\n if (r == bottomDxRIndex && c == rightDxCIndex) {\n // bottomRight\n accumulator += getDy(b, dyR, dyC, d) * dxRLerp * dxCLerp;\n }\n }\n }\n // End loop over dy\n\n setOutput(accumulator);\n }\n ";
- }
- return ResizeBilinearBackpropProgram;
- }());
- exports.ResizeBilinearBackpropProgram = ResizeBilinearBackpropProgram;
- },{}],95:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var ResizeBilinearProgram = (function () {
- function ResizeBilinearProgram(inputShape, newHeight, newWidth, alignCorners) {
- this.variableNames = ['A'];
- this.outputShape = [];
- var batch = inputShape[0], oldHeight = inputShape[1], oldWidth = inputShape[2], depth = inputShape[3];
- this.outputShape = [batch, newHeight, newWidth, depth];
- var effectiveInSize = [
- (alignCorners && newHeight > 1) ? oldHeight - 1 : oldHeight,
- (alignCorners && newWidth > 1) ? oldWidth - 1 : oldWidth
- ];
- var effectiveOutSize = [
- (alignCorners && newHeight > 1) ? newHeight - 1 : newHeight,
- (alignCorners && newWidth > 1) ? newWidth - 1 : newWidth
- ];
- this.userCode = "\n const vec2 effectiveInputOverOutputRatioRC = vec2(\n " + effectiveInSize[0] / effectiveOutSize[0] + ",\n " + effectiveInSize[1] / effectiveOutSize[1] + ");\n const vec2 inputShapeRC = vec2(" + oldHeight + ".0, " + oldWidth + ".0);\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n ivec2 yRC = coords.yz;\n\n // Fractional source index.\n vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the four integer indices.\n ivec2 sourceFloorRC = ivec2(sourceFracIndexRC);\n ivec2 sourceCeilRC = ivec2(\n min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));\n\n float topLeft = getA(b, sourceFloorRC.x, sourceFloorRC.y, d);\n float bottomLeft = getA(b, sourceCeilRC.x, sourceFloorRC.y, d);\n float topRight = getA(b, sourceFloorRC.x, sourceCeilRC.y, d);\n float bottomRight = getA(b, sourceCeilRC.x, sourceCeilRC.y, d);\n\n vec2 fracRC = sourceFracIndexRC - vec2(sourceFloorRC);\n\n float top = topLeft + (topRight - topLeft) * fracRC.y;\n float bottom = bottomLeft + (bottomRight - bottomLeft) * fracRC.y;\n float newValue = top + (bottom - top) * fracRC.x;\n\n setOutput(newValue);\n }\n ";
- }
- return ResizeBilinearProgram;
- }());
- exports.ResizeBilinearProgram = ResizeBilinearProgram;
- },{}],96:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var ResizeNearestNeighborProgram = (function () {
- function ResizeNearestNeighborProgram(inputShape, newHeight, newWidth, alignCorners) {
- this.variableNames = ['A'];
- this.outputShape = [];
- var batch = inputShape[0], oldHeight = inputShape[1], oldWidth = inputShape[2], depth = inputShape[3];
- this.outputShape = [batch, newHeight, newWidth, depth];
- var effectiveInSize = alignCorners ? [oldHeight - 1, oldWidth - 1] : [oldHeight, oldWidth];
- var effectiveOutSize = alignCorners ? [newHeight - 1, newWidth - 1] : [newHeight, newWidth];
- var roundBase = alignCorners ? '0.5' : '0.0';
- this.userCode = "\n const vec2 effectiveInputOverOutputRatioRC = vec2(\n " + effectiveInSize[0] / effectiveOutSize[0] + ",\n " + effectiveInSize[1] / effectiveOutSize[1] + ");\n const vec2 inputShapeRC = vec2(" + oldHeight + ".0, " + oldWidth + ".0);\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n ivec2 yRC = coords.yz;\n\n // Fractional source index.\n vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the coordinators of nearest neighbor point.\n ivec2 sourceNearestRC = ivec2(\n min(inputShapeRC - 1.0, floor(sourceFracIndexRC + " + roundBase + ")));\n\n float newValue = getA(b, sourceNearestRC.x, sourceNearestRC.y, d);\n\n setOutput(newValue);\n }\n ";
- }
- return ResizeNearestNeighborProgram;
- }());
- exports.ResizeNearestNeighborProgram = ResizeNearestNeighborProgram;
- },{}],97:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var shader_compiler_1 = require("./shader_compiler");
- var ReverseProgram = (function () {
- function ReverseProgram(xShape, axis) {
- this.variableNames = ['x'];
- var rank = xShape.length;
- if (rank > 4) {
- throw new Error("WebGL backend: Reverse of rank-" + rank + " tensor is not yet supported");
- }
- this.outputShape = xShape;
- if (rank === 1) {
- this.userCode = "\n void main() {\n int coord = getOutputCoords();\n setOutput(getX(" + xShape[0] + " - coord - 1));\n }\n ";
- return;
- }
- var getInCoord = function (i) {
- if (axis.indexOf(i) !== -1 && xShape[i] !== 1) {
- return xShape[i] + " - coords[" + i + "] - 1";
- }
- return "coords[" + i + "]";
- };
- var inCoords = xShape.map(function (_, i) { return getInCoord(i); }).join(',');
- var type = shader_compiler_1.getCoordsDataType(rank);
- this.userCode = "\n void main() {\n " + type + " coords = getOutputCoords();\n setOutput(getX(" + inCoords + "));\n }\n ";
- }
- return ReverseProgram;
- }());
- exports.ReverseProgram = ReverseProgram;
- },{"./shader_compiler":99}],98:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var SegmentOpProgram = (function () {
- function SegmentOpProgram(segOpInfo, segOpType) {
- this.variableNames = ['x', 'segmentIds'];
- var windowSize = segOpInfo.windowSize;
- var batchSize = segOpInfo.batchSize;
- var inSize = segOpInfo.inSize;
- var numSegments = segOpInfo.numSegments;
- var outSize = numSegments * Math.ceil(inSize / windowSize);
- this.outputShape = [batchSize, outSize];
- var initializationValue = '0.0';
- var returnValue = "sumValue";
- var windowSizeNearestVec4 = Math.floor(windowSize / 4) * 4;
- var windowSizeVec4Remainder = windowSize % 4;
- var updateSnippet = "\n sumValue += dot(values, filter);\n ";
- var checkValueOutOfBounds = '';
- if (inSize % windowSize > 0) {
- checkValueOutOfBounds = "\n if (inIdx < 0 || inIdx >= " + inSize + ") {\n return initializationValue;\n }\n ";
- }
- var checkSegmentIdOutOfBounds = '';
- if (inSize % windowSize > 0) {
- checkSegmentIdOutOfBounds = "\n if (inIdx < 0 || inIdx >= " + inSize + ") {\n return -1.0;\n }\n ";
- }
- this.userCode = "\n const float initializationValue = " + initializationValue + ";\n\n float getValue(int batch, int inIdx) {\n " + checkValueOutOfBounds + "\n return getX(batch, inIdx);\n }\n\n float getSegmentIdAtIndex(int inIdx) {\n " + checkSegmentIdOutOfBounds + "\n return getSegmentIds(inIdx);\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = int(floor(float(outIdx) / float(\n " + numSegments + ")) * float(" + windowSize + "));\n int currentSeg = int(mod(float(outIdx), float(" + numSegments + ")));\n\n float sumValue = 0.0;\n\n for (int i = 0; i < " + windowSizeNearestVec4 + "; i += 4) {\n int inIdx = inOffset + i;\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n getValue(batch, inIdx + 3)\n );\n\n vec4 filter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 3)) == currentSeg ? 1 : 0\n );\n\n " + updateSnippet + "\n }\n\n int inIdx = inOffset + " + windowSizeNearestVec4 + ";\n if (" + (windowSizeVec4Remainder === 1) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n int inIdxSeg = int(getSegmentIdAtIndex(inIdx));\n\n vec4 filter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n 0,\n 0,\n 0\n );\n\n " + updateSnippet + "\n } else if (" + (windowSizeVec4Remainder === 2) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n initializationValue,\n initializationValue\n );\n\n vec4 filter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n 0,\n 0\n );\n\n " + updateSnippet + "\n } else if (" + (windowSizeVec4Remainder === 3) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n initializationValue\n );\n\n vec4 filter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,\n 0\n );\n\n " + updateSnippet + "\n }\n setOutput(" + returnValue + ");\n }\n ";
- }
- return SegmentOpProgram;
- }());
- exports.SegmentOpProgram = SegmentOpProgram;
- },{}],99:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var broadcast_util = require("../../ops/broadcast_util");
- var util = require("../../util");
- function makeShader(inputsInfo, outputShape, userCode, broadcast) {
- var inputPrefixSnippet = inputsInfo.map(function (x) {
- var size = util.sizeFromShape(x.shapeInfo.logicalShape);
- if (x.shapeInfo.isUniform) {
- return "uniform float " + x.name + (size > 1 ? "[" + size + "]" : '') + ";";
- }
- return "uniform sampler2D " + x.name + ";";
- });
- inputPrefixSnippet = inputPrefixSnippet.join('\n');
- var inputSamplingSnippet = inputsInfo.map(function (x) { return getInputSamplingSnippet(x, outputShape, broadcast); })
- .join('\n');
- var outTexShape = outputShape.texShape;
- var outputSamplingSnippet = getOutputSamplingSnippet(outputShape.logicalShape, outTexShape);
- var source = [
- SHADER_PREFIX, FLOAT_TEXTURE_SAMPLE_SNIPPET,
- FLOAT_TEXTURE_SETOUTPUT_SNIPPET, inputPrefixSnippet, outputSamplingSnippet,
- inputSamplingSnippet, userCode
- ].join('\n');
- return source;
- }
- exports.makeShader = makeShader;
- function getSamplerFromInInfo(inInfo) {
- var shape = inInfo.shapeInfo.logicalShape;
- switch (shape.length) {
- case 0:
- return getSamplerScalar(inInfo);
- case 1:
- return getSampler1D(inInfo);
- case 2:
- return getSampler2D(inInfo);
- case 3:
- return getSampler3D(inInfo);
- case 4:
- return getSampler4D(inInfo);
- case 5:
- return getSampler5D(inInfo);
- case 6:
- return getSampler6D(inInfo);
- default:
- throw new Error(shape.length + "-D input sampling" +
- " is not yet supported");
- }
- }
- function getInputSamplingSnippet(inInfo, outShapeInfo, broadcast) {
- var res = getSamplerFlat(inInfo);
- res += getSamplerFromInInfo(inInfo);
- if (broadcast ||
- util.arraysEqual(inInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape)) {
- res += getSamplerAtOutputCoords(inInfo, outShapeInfo, broadcast);
- }
- return res;
- }
- function getOutputSamplingSnippet(outShape, outTexShape) {
- switch (outShape.length) {
- case 0:
- return getOutputScalarCoords();
- case 1:
- return getOutput1DCoords(outShape, outTexShape);
- case 2:
- return getOutput2DCoords(outShape, outTexShape);
- case 3:
- return getOutput3DCoords(outShape, outTexShape);
- case 4:
- return getOutput4DCoords(outShape, outTexShape);
- case 5:
- return getOutput5DCoords(outShape, outTexShape);
- case 6:
- return getOutput6DCoords(outShape, outTexShape);
- default:
- throw new Error(outShape.length + "-D output sampling is not yet supported");
- }
- }
- var SAMPLE_1D_SNIPPET = "\nvec2 UVfrom1D(int texNumR, int texNumC, int index) {\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n";
- var SAMPLE_2D_SNIPPET = "\nvec2 UVfrom2D(int texNumR, int texNumC, int numC, int row, int col) {\n int index = row * numC + col;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n";
- var SAMPLE_3D_SNIPPET = "\nvec2 UVfrom3D(int texNumR, int texNumC, int stride0,\n int stride1, int row, int col, int depth) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * stride0 + col * stride1 + depth;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n";
- var SAMPLE_4D_SNIPPET = "\nvec2 UVfrom4D(int texNumR, int texNumC, int stride0,\n int stride1, int stride2, int row, int col, int depth,\n int depth2) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * stride0 + col * stride1 + depth * stride2 + depth2;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n";
- var SAMPLE_5D_SNIPPET = "\nvec2 UVfrom5D(int texNumR, int texNumC, int stride0,\n int stride1, int stride2, int stride3, int row, int col, int depth,\n int depth2, int depth3) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * stride0 + col * stride1 +\n depth * stride2 + depth2 * stride3 + depth3;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n";
- var SAMPLE_6D_SNIPPET = "\nvec2 UVfrom6D(int texNumR, int texNumC, int stride0,\n int stride1, int stride2, int stride3, int stride4,\n int row, int col, int depth, int depth2, int depth3, int depth4) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * stride0 + col * stride1 + depth * stride2 + depth2 *\n stride3 + depth3 * stride4 + depth4;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n";
- var FLOAT_TEXTURE_SAMPLE_SNIPPET = "\n float sampleTexture(sampler2D textureSampler, vec2 uv) {\n return texture2D(textureSampler, uv).r;\n }\n";
- var FLOAT_TEXTURE_SETOUTPUT_SNIPPET = "\n void setOutput(float val) {\n gl_FragColor = vec4(val, 0, 0, 0);\n }\n";
- var SHADER_PREFIX = "\n precision highp float;\n precision highp int;\n varying vec2 resultUV;\n const vec2 halfCR = vec2(0.5, 0.5);\n\n struct ivec5\n {\n int x;\n int y;\n int z;\n int w;\n int u;\n };\n\n struct ivec6\n {\n int x;\n int y;\n int z;\n int w;\n int u;\n int v;\n };\n\n bool isNaN(float val) {\n return (val < 0.0 || 0.0 < val || val == 0.0) ? false : true;\n }\n\n bool hasNaN(vec4 values) {\n vec4 v1 = values * values;\n vec4 v2 = values * values;\n return any(notEqual(v1, v2));\n }\n\n float getNaN(vec4 values) {\n return dot(vec4(1), values);\n }\n\n int round(float value) {\n return int(floor(value + 0.5));\n }\n\n int imod(int x, int y) {\n return x - y * (x / y);\n }\n\n //Based on the work of Dave Hoskins\n //https://www.shadertoy.com/view/4djSRW\n #define HASHSCALE1 443.8975\n float random(float seed){\n vec2 p = resultUV * seed;\n vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);\n p3 += dot(p3, p3.yzx + 19.19);\n return fract((p3.x + p3.y) * p3.z);\n }\n\n " + SAMPLE_1D_SNIPPET + "\n " + SAMPLE_2D_SNIPPET + "\n " + SAMPLE_3D_SNIPPET + "\n " + SAMPLE_4D_SNIPPET + "\n " + SAMPLE_5D_SNIPPET + "\n " + SAMPLE_6D_SNIPPET + "\n";
- function getOutputScalarCoords() {
- return "\n int getOutputCoords() {\n return 0;\n }\n ";
- }
- function getOutput1DCoords(shape, texShape) {
- if (texShape[0] === 1) {
- return "\n int getOutputCoords() {\n return int(resultUV.x * " + texShape[1] + ".0);\n }\n ";
- }
- if (texShape[1] === 1) {
- return "\n int getOutputCoords() {\n return int(resultUV.y * " + texShape[0] + ".0);\n }\n ";
- }
- return "\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n return resTexRC.x * " + texShape[1] + " + resTexRC.y;\n }\n ";
- }
- function getOutput3DCoords(shape, texShape) {
- var stride0 = shape[1] * shape[2];
- var stride1 = shape[2];
- return "\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n int r = index / " + stride0 + ";\n index -= r * " + stride0 + ";\n int c = index / " + stride1 + ";\n int d = index - c * " + stride1 + ";\n return ivec3(r, c, d);\n }\n ";
- }
- function getOutput4DCoords(shape, texShape) {
- var stride2 = shape[3];
- var stride1 = shape[2] * stride2;
- var stride0 = shape[1] * stride1;
- return "\n ivec4 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n\n int r = index / " + stride0 + ";\n index -= r * " + stride0 + ";\n\n int c = index / " + stride1 + ";\n index -= c * " + stride1 + ";\n\n int d = index / " + stride2 + ";\n int d2 = index - d * " + stride2 + ";\n\n return ivec4(r, c, d, d2);\n }\n ";
- }
- function getOutput5DCoords(shape, texShape) {
- var stride3 = shape[4];
- var stride2 = shape[3] * stride3;
- var stride1 = shape[2] * stride2;
- var stride0 = shape[1] * stride1;
- return "\n ivec5 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx * vec2(" + texShape[0] + ",\n " + texShape[1] + "));\n\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n\n int r = index / " + stride0 + ";\n index -= r * " + stride0 + ";\n\n int c = index / " + stride1 + ";\n index -= c * " + stride1 + ";\n\n int d = index / " + stride2 + ";\n index -= d * " + stride2 + ";\n\n int d2 = index / " + stride3 + ";\n int d3 = index - d2 * " + stride3 + ";\n\n ivec5 outShape = ivec5(r, c, d, d2, d3);\n return outShape;\n }\n ";
- }
- function getOutput6DCoords(shape, texShape) {
- var stride4 = shape[5];
- var stride3 = shape[4] * stride4;
- var stride2 = shape[3] * stride3;
- var stride1 = shape[2] * stride2;
- var stride0 = shape[1] * stride1;
- return "\n ivec6 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n\n int r = index / " + stride0 + ";\n index -= r * " + stride0 + ";\n\n int c = index / " + stride1 + ";\n index -= c * " + stride1 + ";\n\n int d = index / " + stride2 + ";\n index -= d * " + stride2 + ";\n\n int d2 = index / " + stride3 + ";\n index -= d2 * " + stride3 + ";\n\n int d3 = index / " + stride4 + ";\n int d4 = index - d3 * " + stride4 + ";\n\n ivec6 result = ivec6(r, c, d, d2, d3, d4);\n return result;\n }\n ";
- }
- function getOutput2DCoords(shape, texShape) {
- if (util.arraysEqual(shape, texShape)) {
- return "\n ivec2 getOutputCoords() {\n return ivec2(resultUV.yx * vec2(" + texShape[0] + ", " + texShape[1] + "));\n }\n ";
- }
- if (shape[1] === 1) {
- return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n return ivec2(index, 0);\n }\n ";
- }
- if (shape[0] === 1) {
- return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n return ivec2(0, index);\n }\n ";
- }
- return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n int r = index / " + shape[1] + ";\n int c = index - r * " + shape[1] + ";\n return ivec2(r, c);\n }\n ";
- }
- function getSamplerScalar(inputInfo) {
- var texName = inputInfo.name;
- var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1);
- if (inputInfo.shapeInfo.isUniform) {
- return "float " + funcName + "() {return " + texName + ";}";
- }
- return "\n float " + funcName + "() {\n return sampleTexture(" + texName + ", halfCR);\n }\n ";
- }
- function getSampler1D(inputInfo) {
- var texName = inputInfo.name;
- var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1);
- return "\n float " + funcName + "(int index) {\n return " + funcName + "Flat(index);\n }\n ";
- }
- function getSampler2D(inputInfo) {
- var shape = inputInfo.shapeInfo.logicalShape;
- var texName = inputInfo.name;
- var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1);
- var texShape = inputInfo.shapeInfo.texShape;
- if (texShape != null && util.arraysEqual(shape, texShape)) {
- var texNumR_1 = texShape[0];
- var texNumC_1 = texShape[1];
- return "\n float " + funcName + "(int row, int col) {\n vec2 uv = (vec2(col, row) + halfCR) / vec2(" + texNumC_1 + ".0, " + texNumR_1 + ".0);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims;
- var squeezedShape = newShape;
- if (squeezedShape.length < shape.length) {
- var newInputInfo = squeezeInputInfo(inputInfo, squeezedShape);
- var params = ['row', 'col'];
- return "\n " + getSamplerFromInInfo(newInputInfo) + "\n float " + funcName + "(int row, int col) {\n return " + funcName + "(" + getSqueezedParams(params, keptDims) + ");\n }\n ";
- }
- if (inputInfo.shapeInfo.isUniform) {
- return "\n float " + funcName + "(int row, int col) {\n int index = row * " + shape[1] + " + col;\n return " + funcName + "Flat(index);\n }\n ";
- }
- var texNumR = texShape[0];
- var texNumC = texShape[1];
- if (texNumC === 1) {
- return "\n float " + funcName + "(int row, int col) {\n int index = row * " + shape[1] + " + col;\n vec2 uv = vec2(0.5, (float(index) + 0.5) / " + texNumR + ".0);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- if (texNumR === 1) {
- return "\n float " + funcName + "(int row, int col) {\n int index = row * " + shape[1] + " + col;\n vec2 uv = vec2((float(index) + 0.5) / " + texNumC + ".0, 0.5);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- return "\n float " + funcName + "(int row, int col) {\n vec2 uv = UVfrom2D(" + texNumR + ", " + texNumC + ", " + shape[1] + ", row, col);\n return sampleTexture(" + texName + ", uv);\n }\n";
- }
- function getSampler3D(inputInfo) {
- var shape = inputInfo.shapeInfo.logicalShape;
- var texName = inputInfo.name;
- var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1);
- var stride0 = shape[1] * shape[2];
- var stride1 = shape[2];
- var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims;
- var squeezedShape = newShape;
- if (squeezedShape.length < shape.length) {
- var newInputInfo = squeezeInputInfo(inputInfo, squeezedShape);
- var params = ['row', 'col', 'depth'];
- return "\n " + getSamplerFromInInfo(newInputInfo) + "\n float " + funcName + "(int row, int col, int depth) {\n return " + funcName + "(" + getSqueezedParams(params, keptDims) + ");\n }\n ";
- }
- if (inputInfo.shapeInfo.isUniform) {
- return "\n float " + funcName + "(int row, int col, int depth) {\n int index = row * " + stride0 + " + col * " + stride1 + " + depth;\n return " + funcName + "Flat(index);\n }\n ";
- }
- var texShape = inputInfo.shapeInfo.texShape;
- var texNumR = texShape[0];
- var texNumC = texShape[1];
- if (texNumC === stride0) {
- return "\n float " + funcName + "(int row, int col, int depth) {\n int texR = row;\n int texC = col * " + stride1 + " + depth;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- if (texNumC === stride1) {
- return "\n float " + funcName + "(int row, int col, int depth) {\n int texR = row * " + shape[1] + " + col;\n int texC = depth;\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- return "\n float " + funcName + "(int row, int col, int depth) {\n vec2 uv = UVfrom3D(\n " + texNumR + ", " + texNumC + ", " + stride0 + ", " + stride1 + ", row, col, depth);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- function getSampler4D(inputInfo) {
- var shape = inputInfo.shapeInfo.logicalShape;
- var texName = inputInfo.name;
- var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1);
- var stride2 = shape[3];
- var stride1 = shape[2] * stride2;
- var stride0 = shape[1] * stride1;
- var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims;
- if (newShape.length < shape.length) {
- var newInputInfo = squeezeInputInfo(inputInfo, newShape);
- var params = ['row', 'col', 'depth', 'depth2'];
- return "\n " + getSamplerFromInInfo(newInputInfo) + "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n return " + funcName + "(" + getSqueezedParams(params, keptDims) + ");\n }\n ";
- }
- if (inputInfo.shapeInfo.isUniform) {
- return "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n int index = row * " + stride0 + " + col * " + stride1 + " +\n depth * " + stride2 + " + depth2;\n return " + funcName + "Flat(index);\n }\n ";
- }
- var texShape = inputInfo.shapeInfo.texShape;
- var texNumR = texShape[0];
- var texNumC = texShape[1];
- if (texNumC === stride0) {
- return "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n int texR = row;\n int texC = col * " + stride1 + " + depth * " + stride2 + " + depth2;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- if (texNumC === stride2) {
- return "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n int texR = row * " + shape[1] * shape[2] + " + col * " + shape[2] + " + depth;\n int texC = depth2;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- return "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n vec2 uv = UVfrom4D(" + texNumR + ", " + texNumC + ", " + stride0 + ", " + stride1 + ",\n " + stride2 + ", row, col, depth, depth2);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- function getSampler5D(inputInfo) {
- var shape = inputInfo.shapeInfo.logicalShape;
- var texName = inputInfo.name;
- var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1);
- var stride3 = shape[4];
- var stride2 = shape[3] * stride3;
- var stride1 = shape[2] * stride2;
- var stride0 = shape[1] * stride1;
- var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims;
- if (newShape.length < shape.length) {
- var newInputInfo = squeezeInputInfo(inputInfo, newShape);
- var params = ['row', 'col', 'depth', 'depth2', 'depth3'];
- return "\n " + getSamplerFromInInfo(newInputInfo) + "\n float " + funcName + "(int row, int col, int depth, int depth2, int depth3) {\n return " + funcName + "(" + getSqueezedParams(params, keptDims) + ");\n }\n ";
- }
- if (inputInfo.shapeInfo.isUniform) {
- return "\n float " + funcName + "(int row, int col, int depth, int depth2, int depth3) {\n int index = row * " + stride0 + " + col * " + stride1 + " +\n depth * " + stride2 + " + depth2 * " + stride3 + " + depth3;\n return " + funcName + "Flat(index);\n }\n ";
- }
- var texShape = inputInfo.shapeInfo.texShape;
- var texNumR = texShape[0];
- var texNumC = texShape[1];
- if (texNumC === stride0) {
- return "\n float " + funcName + "(int row, int col, int depth, int depth2, int depth3) {\n int texR = row;\n int texC = col * " + stride1 + " + depth * " + stride2 + " +\n depth2 * " + stride3 + " + depth3;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- if (texNumC === stride3) {
- return "\n float " + funcName + "(int row, int col, int depth, int depth2, int depth3) {\n int texR = row * " + shape[1] * shape[2] + " + col * " + shape[2] + " +\n depth * " + shape[3] + " + depth2;\n int texC = depth3;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- return "\n float " + funcName + "(int row, int col, int depth, int depth2, int depth3) {\n vec2 uv = UVfrom5D(" + texNumR + ", " + texNumC + ", " + stride0 + ", " + stride1 + ",\n " + stride2 + ", " + stride3 + ", row, col, depth, depth2, depth3);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- function getSampler6D(inputInfo) {
- var shape = inputInfo.shapeInfo.logicalShape;
- var texName = inputInfo.name;
- var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1);
- var stride4 = shape[5];
- var stride3 = shape[4] * stride4;
- var stride2 = shape[3] * stride3;
- var stride1 = shape[2] * stride2;
- var stride0 = shape[1] * stride1;
- var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims;
- if (newShape.length < shape.length) {
- var newInputInfo = squeezeInputInfo(inputInfo, newShape);
- var params = ['row', 'col', 'depth', 'depth2', 'depth3', 'depth4'];
- return "\n " + getSamplerFromInInfo(newInputInfo) + "\n float " + funcName + "(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n return " + funcName + "(" + getSqueezedParams(params, keptDims) + ");\n }\n ";
- }
- if (inputInfo.shapeInfo.isUniform) {
- return "\n float " + funcName + "(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n int index = row * " + stride0 + " + col * " + stride1 + " +\n depth * " + stride2 + " + depth2 * " + stride3 + " + depth3 * " + stride3 + "\n + depth4\n return " + funcName + "Flat(index);\n }\n ";
- }
- var texShape = inputInfo.shapeInfo.texShape;
- var texNumR = texShape[0];
- var texNumC = texShape[1];
- if (texNumC === stride0) {
- return "\n float " + funcName + "(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n int texR = row;\n int texC = col * " + stride1 + " + depth * " + stride2 + " + depth2;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- if (texNumC === stride4) {
- return "\n float " + funcName + "(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n int texR = row * " + shape[1] * shape[2] + " + col * " + shape[2] + " + depth;\n int texC = depth4;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- return "\n float " + funcName + "(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n vec2 uv = UVfrom6D(" + texNumR + ", " + texNumC + ", " + stride0 + ", " + stride1 + ",\n " + stride2 + ", " + stride3 + ", " + stride4 + "\n ,row, col, depth, depth2, depth3, depth4);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- function getSamplerFlat(inputInfo) {
- var texName = inputInfo.name;
- var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1) + 'Flat';
- var inSize = util.sizeFromShape(inputInfo.shapeInfo.logicalShape);
- if (inputInfo.shapeInfo.isUniform) {
- if (inSize === 1) {
- return "float " + funcName + "(int index) {return " + texName + ";}";
- }
- return "\n float " + funcName + "(int index) {\n for (int i = 0; i < " + inSize + "; i++) {\n if (i == index) {\n return " + texName + "[i];\n }\n }\n }\n ";
- }
- var texShape = inputInfo.shapeInfo.texShape;
- var tNumR = texShape[0];
- var tNumC = texShape[1];
- if (tNumC === 1 && tNumR === 1) {
- return "\n float " + funcName + "(int index) {\n return sampleTexture(" + texName + ", halfCR);\n }\n ";
- }
- if (tNumC === 1) {
- return "\n float " + funcName + "(int index) {\n vec2 uv = vec2(0.5, (float(index) + 0.5) / " + tNumR + ".0);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- if (tNumR === 1) {
- return "\n float " + funcName + "(int index) {\n vec2 uv = vec2((float(index) + 0.5) / " + tNumC + ".0, 0.5);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- return "\n float " + funcName + "(int index) {\n vec2 uv = UVfrom1D(" + tNumR + ", " + tNumC + ", index);\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- function getBroadcastOutputCoordsSampler(inputInfo, outShapeInfo, texFuncSnippet, funcName) {
- var inRank = inputInfo.shapeInfo.logicalShape.length;
- var outRank = outShapeInfo.logicalShape.length;
- var type = 'int';
- if (outRank === 2) {
- type = 'ivec2';
- }
- else if (outRank === 3) {
- type = 'ivec3';
- }
- else if (outRank === 4) {
- type = 'ivec4';
- }
- var broadcastDims = broadcast_util.getBroadcastDims(inputInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape);
- var rankDiff = outRank - inRank;
- var coordsSnippet;
- if (inRank === 0) {
- coordsSnippet = '';
- }
- else if (outRank < 2 && broadcastDims.length >= 1) {
- coordsSnippet = 'coords = 0;';
- }
- else {
- coordsSnippet =
- broadcastDims.map(function (d) { return "coords[" + (d + rankDiff) + "] = 0;"; }).join('\n');
- }
- var unpackedCoordsSnippet = '';
- if (outRank < 2 && inRank > 0) {
- unpackedCoordsSnippet = 'coords';
- }
- else {
- unpackedCoordsSnippet = inputInfo.shapeInfo.logicalShape
- .map(function (s, i) { return "coords[" + (i + rankDiff) + "]"; })
- .join(', ');
- }
- return "\n float " + funcName + "() {\n " + type + " coords = getOutputCoords();\n " + coordsSnippet + "\n return get" + texFuncSnippet + "(" + unpackedCoordsSnippet + ");\n }\n ";
- }
- function getSamplerAtOutputCoords(inputInfo, outShapeInfo, supportsBroadcasting) {
- var texName = inputInfo.name;
- var texFuncSnippet = texName.charAt(0).toUpperCase() + texName.slice(1);
- var funcName = 'get' + texFuncSnippet + 'AtOutCoords';
- var broadcastDims = broadcast_util.getBroadcastDims(inputInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape);
- var inRank = inputInfo.shapeInfo.logicalShape.length;
- var outRank = outShapeInfo.logicalShape.length;
- var doBroadcast = supportsBroadcasting && ((outRank > inRank) || broadcastDims.length > 0);
- var broadcastOverOuter = broadcast_util.broadcastDimsAreOuter(broadcastDims);
- var isUniform = inputInfo.shapeInfo.isUniform;
- if (doBroadcast && !broadcastOverOuter) {
- return getBroadcastOutputCoordsSampler(inputInfo, outShapeInfo, texFuncSnippet, funcName);
- }
- var inSize = util.sizeFromShape(inputInfo.shapeInfo.logicalShape);
- var broadcastSnippet = '';
- if (doBroadcast && broadcastOverOuter) {
- broadcastSnippet = "\n int mainPart = index / " + inSize + ";\n index -= mainPart * " + inSize + ";\n ";
- }
- var outTexShape = outShapeInfo.texShape;
- if (isUniform) {
- if (inSize === 1) {
- return "float " + funcName + "() {return " + texName + ";}";
- }
- return "\n float " + funcName + "() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + outTexShape[0] + ", " + outTexShape[1] + "));\n int index = resTexRC.x * " + outTexShape[1] + " + resTexRC.y;\n " + broadcastSnippet + "\n return get" + texFuncSnippet + "Flat(index);\n }\n ";
- }
- var inTexShape = inputInfo.shapeInfo.texShape;
- if (util.arraysEqual(inTexShape, outTexShape)) {
- return "\n float " + funcName + "() {\n return sampleTexture(" + texName + ", resultUV);\n }\n ";
- }
- return "\n float " + funcName + "() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + outTexShape[0] + ", " + outTexShape[1] + "));\n int index = resTexRC.x * " + outTexShape[1] + " + resTexRC.y;\n " + broadcastSnippet + "\n int texR = index / " + inTexShape[1] + ";\n int texC = index - texR * " + inTexShape[1] + ";\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + inTexShape[1] + ".0, " + inTexShape[0] + ".0);\n\n return sampleTexture(" + texName + ", uv);\n }\n ";
- }
- function getCoordsDataType(rank) {
- if (rank <= 1) {
- return 'int';
- }
- else if (rank === 2) {
- return 'ivec2';
- }
- else if (rank === 3) {
- return 'ivec3';
- }
- else if (rank === 4) {
- return 'ivec4';
- }
- else if (rank === 5) {
- return 'ivec5';
- }
- else if (rank === 6) {
- return 'ivec6';
- }
- else {
- throw Error("GPU for rank " + rank + " is not yet supported");
- }
- }
- exports.getCoordsDataType = getCoordsDataType;
- function squeezeInputInfo(inInfo, squeezedShape) {
- var newInputInfo = JSON.parse(JSON.stringify(inInfo));
- newInputInfo.shapeInfo.logicalShape = squeezedShape;
- return newInputInfo;
- }
- function getSqueezedParams(params, keptDims) {
- return keptDims.map(function (d) { return params[d]; }).join(', ');
- }
- },{"../../ops/broadcast_util":112,"../../util":164}],100:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var shader_compiler_1 = require("./shader_compiler");
- var SliceProgram = (function () {
- function SliceProgram(destSize) {
- this.variableNames = ['source'];
- this.outputShape = destSize;
- this.rank = destSize.length;
- var dtype = shader_compiler_1.getCoordsDataType(this.rank);
- var sourceCoords = getCoords(this.rank);
- this.userCode = "\n uniform " + dtype + " start;\n\n void main() {\n " + dtype + " sourceLoc = start + getOutputCoords();\n setOutput(getSource(" + sourceCoords + "));\n }\n ";
- }
- SliceProgram.prototype.getCustomSetupFunc = function (start) {
- var _this = this;
- if (start.length !== this.rank) {
- throw Error("The rank (" + this.rank + ") of the program must match the " +
- ("length of start (" + start.length + ")"));
- }
- return function (gpgpu, webGLProgram) {
- if (_this.startLoc == null) {
- _this.startLoc = gpgpu.getUniformLocationNoThrow(webGLProgram, 'start');
- if (_this.startLoc == null) {
- return;
- }
- }
- if (_this.rank === 1) {
- gpgpu.gl.uniform1i(_this.startLoc, start[0]);
- }
- else if (_this.rank === 2) {
- gpgpu.gl.uniform2i(_this.startLoc, start[0], start[1]);
- }
- else if (_this.rank === 3) {
- gpgpu.gl.uniform3i(_this.startLoc, start[0], start[1], start[2]);
- }
- else if (_this.rank === 4) {
- gpgpu.gl.uniform4i(_this.startLoc, start[0], start[1], start[2], start[3]);
- }
- else {
- throw Error("Slicing for rank " + _this.rank + " is not yet supported");
- }
- };
- };
- return SliceProgram;
- }());
- exports.SliceProgram = SliceProgram;
- function getCoords(rank) {
- if (rank === 1) {
- return 'sourceLoc';
- }
- else if (rank === 2) {
- return 'sourceLoc.x, sourceLoc.y';
- }
- else if (rank === 3) {
- return 'sourceLoc.x, sourceLoc.y, sourceLoc.z';
- }
- else if (rank === 4) {
- return 'sourceLoc.x, sourceLoc.y, sourceLoc.z, sourceLoc.w';
- }
- else {
- throw Error("Slicing for rank " + rank + " is not yet supported");
- }
- }
- },{"./shader_compiler":99}],101:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var shader_compiler_1 = require("./shader_compiler");
- var StridedSliceProgram = (function () {
- function StridedSliceProgram(begin, strides, shape) {
- this.variableNames = ['x'];
- this.outputShape = shape;
- this.rank = shape.length;
- var dtype = shader_compiler_1.getCoordsDataType(this.rank);
- var newCoords = '';
- if (this.rank === 1) {
- newCoords = 'coords * strides + begin';
- }
- else {
- newCoords =
- shape.map(function (_, i) { return "coords[" + i + "] * strides[" + i + "] + begin[" + i + "]"; })
- .join(',');
- }
- this.userCode = "\n " + dtype + " begin = " + dtype + "(" + begin + ");\n " + dtype + " strides = " + dtype + "(" + strides + ");\n\n void main() {\n " + dtype + " coords = getOutputCoords();\n setOutput(getX(" + newCoords + "));\n }\n ";
- }
- return StridedSliceProgram;
- }());
- exports.StridedSliceProgram = StridedSliceProgram;
- },{"./shader_compiler":99}],102:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var TextureUsage;
- (function (TextureUsage) {
- TextureUsage[TextureUsage["RENDER"] = 0] = "RENDER";
- TextureUsage[TextureUsage["UPLOAD"] = 1] = "UPLOAD";
- TextureUsage[TextureUsage["PIXELS"] = 2] = "PIXELS";
- TextureUsage[TextureUsage["DOWNLOAD"] = 3] = "DOWNLOAD";
- })(TextureUsage = exports.TextureUsage || (exports.TextureUsage = {}));
- var PhysicalTextureType;
- (function (PhysicalTextureType) {
- PhysicalTextureType[PhysicalTextureType["FLOAT16"] = 0] = "FLOAT16";
- PhysicalTextureType[PhysicalTextureType["FLOAT32"] = 1] = "FLOAT32";
- PhysicalTextureType[PhysicalTextureType["UNSIGNED_BYTE"] = 2] = "UNSIGNED_BYTE";
- })(PhysicalTextureType = exports.PhysicalTextureType || (exports.PhysicalTextureType = {}));
- function getUnpackedMatrixTextureShapeWidthHeight(rows, columns) {
- return [columns, rows];
- }
- exports.getUnpackedMatrixTextureShapeWidthHeight = getUnpackedMatrixTextureShapeWidthHeight;
- function getUnpackedArraySizeFromMatrixSize(matrixSize, channelsPerTexture) {
- return matrixSize * channelsPerTexture;
- }
- exports.getUnpackedArraySizeFromMatrixSize = getUnpackedArraySizeFromMatrixSize;
- function getColorMatrixTextureShapeWidthHeight(rows, columns) {
- return [columns * 4, rows];
- }
- exports.getColorMatrixTextureShapeWidthHeight = getColorMatrixTextureShapeWidthHeight;
- function getMatrixSizeFromUnpackedArraySize(unpackedSize, channelsPerTexture) {
- if (unpackedSize % channelsPerTexture !== 0) {
- throw new Error("unpackedSize (" + unpackedSize + ") must be a multiple of " +
- ("" + channelsPerTexture));
- }
- return unpackedSize / channelsPerTexture;
- }
- exports.getMatrixSizeFromUnpackedArraySize = getMatrixSizeFromUnpackedArraySize;
- function encodeMatrixToUnpackedArray(matrix, unpackedArray, channelsPerTexture) {
- var requiredSize = getUnpackedArraySizeFromMatrixSize(matrix.length, channelsPerTexture);
- if (unpackedArray.length < requiredSize) {
- throw new Error("unpackedArray length (" + unpackedArray.length + ") must be >= " +
- ("" + requiredSize));
- }
- var dst = 0;
- for (var src = 0; src < matrix.length; ++src) {
- unpackedArray[dst] = matrix[src];
- dst += channelsPerTexture;
- }
- }
- exports.encodeMatrixToUnpackedArray = encodeMatrixToUnpackedArray;
- function decodeMatrixFromUnpackedArray(unpackedArray, matrix, channelsPerTexture) {
- var requiredSize = getMatrixSizeFromUnpackedArraySize(unpackedArray.length, channelsPerTexture);
- if (matrix.length < requiredSize) {
- throw new Error("matrix length (" + matrix.length + ") must be >= " + requiredSize);
- }
- var dst = 0;
- for (var src = 0; src < unpackedArray.length; src += channelsPerTexture) {
- matrix[dst++] = unpackedArray[src];
- }
- }
- exports.decodeMatrixFromUnpackedArray = decodeMatrixFromUnpackedArray;
- function decodeMatrixFromUnpackedColorRGBAArray(unpackedArray, matrix, channels) {
- var requiredSize = unpackedArray.length * channels / 4;
- if (matrix.length < requiredSize) {
- throw new Error("matrix length (" + matrix.length + ") must be >= " + requiredSize);
- }
- var dst = 0;
- for (var src = 0; src < unpackedArray.length; src += 4) {
- for (var c = 0; c < channels; c++) {
- matrix[dst++] = unpackedArray[src + c];
- }
- }
- }
- exports.decodeMatrixFromUnpackedColorRGBAArray = decodeMatrixFromUnpackedColorRGBAArray;
- function getPackedMatrixTextureShapeWidthHeight(rows, columns) {
- return [Math.ceil(columns / 2), Math.ceil(rows / 2)];
- }
- exports.getPackedMatrixTextureShapeWidthHeight = getPackedMatrixTextureShapeWidthHeight;
- function getPackedRGBAArraySizeFromMatrixShape(rows, columns) {
- var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1];
- return w * h * 4;
- }
- exports.getPackedRGBAArraySizeFromMatrixShape = getPackedRGBAArraySizeFromMatrixShape;
- function encodeMatrixToPackedRGBA(matrix, rows, columns, packedRGBA) {
- var requiredSize = getPackedRGBAArraySizeFromMatrixShape(rows, columns);
- if (packedRGBA.length < requiredSize) {
- throw new Error("packedRGBA length (" + packedRGBA.length + ") must be >= " + requiredSize);
- }
- var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), textureWidth = _a[0], textureHeight = _a[1];
- var oddWidth = (columns % 2) === 1;
- var oddHeight = (rows % 2) === 1;
- var widthInFullBlocks = Math.floor(columns / 2);
- var heightInFullBlocks = Math.floor(rows / 2);
- {
- var dstStride = (oddWidth ? 4 : 0);
- var oneRow = columns;
- var dst = 0;
- for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) {
- var matrixSrcRow = (blockY * 2 * columns);
- for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) {
- var matrixSrcCol = blockX * 2;
- var src = matrixSrcRow + matrixSrcCol;
- packedRGBA[dst] = matrix[src];
- packedRGBA[dst + 1] = matrix[src + 1];
- packedRGBA[dst + 2] = matrix[src + oneRow];
- packedRGBA[dst + 3] = matrix[src + oneRow + 1];
- dst += 4;
- }
- dst += dstStride;
- }
- }
- if (oddWidth) {
- var src = columns - 1;
- var dst = (textureWidth - 1) * 4;
- var srcStride = 2 * columns;
- var dstStride = textureWidth * 4;
- for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) {
- packedRGBA[dst] = matrix[src];
- packedRGBA[dst + 2] = matrix[src + columns];
- src += srcStride;
- dst += dstStride;
- }
- }
- if (oddHeight) {
- var src = (rows - 1) * columns;
- var dst = (textureHeight - 1) * textureWidth * 4;
- for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) {
- packedRGBA[dst++] = matrix[src++];
- packedRGBA[dst++] = matrix[src++];
- dst += 2;
- }
- }
- if (oddWidth && oddHeight) {
- packedRGBA[packedRGBA.length - 4] = matrix[matrix.length - 1];
- }
- return packedRGBA;
- }
- exports.encodeMatrixToPackedRGBA = encodeMatrixToPackedRGBA;
- function decodeMatrixFromPackedRGBA(packedRGBA, rows, columns, matrix) {
- var requiredSize = rows * columns;
- if (requiredSize < matrix.length) {
- throw new Error("matrix length (" + matrix.length + ") must be >= " + requiredSize);
- }
- var oddWidth = (columns % 2) === 1;
- var oddHeight = (rows % 2) === 1;
- var widthInFullBlocks = Math.floor(columns / 2);
- var heightInFullBlocks = Math.floor(rows / 2);
- var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), textureWidth = _a[0], textureHeight = _a[1];
- {
- var srcStride = oddWidth ? 4 : 0;
- var dstStride = columns + (oddWidth ? 1 : 0);
- var src = 0;
- var dstRow1 = 0;
- var dstRow2 = columns;
- for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) {
- for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) {
- matrix[dstRow1++] = packedRGBA[src++];
- matrix[dstRow1++] = packedRGBA[src++];
- matrix[dstRow2++] = packedRGBA[src++];
- matrix[dstRow2++] = packedRGBA[src++];
- }
- src += srcStride;
- dstRow1 += dstStride;
- dstRow2 += dstStride;
- }
- }
- if (oddWidth) {
- var src = (textureWidth - 1) * 4;
- var dst = columns - 1;
- var srcStride = textureWidth * 4;
- var dstStride = 2 * columns;
- for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) {
- matrix[dst] = packedRGBA[src];
- matrix[dst + columns] = packedRGBA[src + 2];
- src += srcStride;
- dst += dstStride;
- }
- }
- if (oddHeight) {
- var src = (textureHeight - 1) * textureWidth * 4;
- var dst = (rows - 1) * columns;
- for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) {
- matrix[dst++] = packedRGBA[src++];
- matrix[dst++] = packedRGBA[src++];
- src += 2;
- }
- }
- if (oddWidth && oddHeight) {
- matrix[matrix.length - 1] = packedRGBA[packedRGBA.length - 4];
- }
- return matrix;
- }
- exports.decodeMatrixFromPackedRGBA = decodeMatrixFromPackedRGBA;
- },{}],103:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../../environment");
- var tex_util_1 = require("./tex_util");
- var TextureManager = (function () {
- function TextureManager(gpgpu) {
- this.gpgpu = gpgpu;
- this.numUsedTextures = 0;
- this.numFreeTextures = 0;
- this.freeTextures = {};
- this.logEnabled = false;
- this.usedTextures = {};
- }
- TextureManager.prototype.acquireTexture = function (shapeRC, usage) {
- var physicalTexType = getPhysicalFromLogicalTextureType(usage);
- var shapeKey = getKeyFromTextureShape(shapeRC, physicalTexType);
- if (!(shapeKey in this.freeTextures)) {
- this.freeTextures[shapeKey] = [];
- }
- if (!(shapeKey in this.usedTextures)) {
- this.usedTextures[shapeKey] = [];
- }
- if (this.freeTextures[shapeKey].length > 0) {
- this.numFreeTextures--;
- this.numUsedTextures++;
- this.log();
- var newTexture_1 = this.freeTextures[shapeKey].shift();
- this.usedTextures[shapeKey].push(newTexture_1);
- return newTexture_1;
- }
- this.numUsedTextures++;
- this.log();
- var newTexture;
- if (physicalTexType === tex_util_1.PhysicalTextureType.FLOAT32) {
- newTexture =
- this.gpgpu.createFloat32MatrixTexture(shapeRC[0], shapeRC[1]);
- }
- else if (physicalTexType === tex_util_1.PhysicalTextureType.FLOAT16) {
- newTexture =
- this.gpgpu.createFloat16MatrixTexture(shapeRC[0], shapeRC[1]);
- }
- else if (physicalTexType === tex_util_1.PhysicalTextureType.UNSIGNED_BYTE) {
- newTexture =
- this.gpgpu.createUnsignedBytesMatrixTexture(shapeRC[0], shapeRC[1]);
- }
- this.usedTextures[shapeKey].push(newTexture);
- return newTexture;
- };
- TextureManager.prototype.releaseTexture = function (texture, shape, logicalTexType) {
- var physicalTexType = getPhysicalFromLogicalTextureType(logicalTexType);
- var shapeKey = getKeyFromTextureShape(shape, physicalTexType);
- if (!(shapeKey in this.freeTextures)) {
- this.freeTextures[shapeKey] = [];
- }
- this.freeTextures[shapeKey].push(texture);
- this.numFreeTextures++;
- this.numUsedTextures--;
- var texList = this.usedTextures[shapeKey];
- var texIndex = texList.indexOf(texture);
- if (texIndex < 0) {
- throw new Error('Cannot release a texture that was never provided by this ' +
- 'texture manager');
- }
- texList.splice(texIndex, 1);
- this.log();
- };
- TextureManager.prototype.log = function () {
- if (!this.logEnabled) {
- return;
- }
- var total = this.numFreeTextures + this.numUsedTextures;
- console.log('Free/Used', this.numFreeTextures + " / " + this.numUsedTextures, "(" + total + ")");
- };
- TextureManager.prototype.getNumUsedTextures = function () {
- return this.numUsedTextures;
- };
- TextureManager.prototype.getNumFreeTextures = function () {
- return this.numFreeTextures;
- };
- TextureManager.prototype.dispose = function () {
- var _this = this;
- if (this.freeTextures == null) {
- return;
- }
- for (var texShape in this.freeTextures) {
- this.freeTextures[texShape].forEach(function (tex) {
- _this.gpgpu.deleteMatrixTexture(tex);
- });
- }
- for (var texShape in this.usedTextures) {
- this.usedTextures[texShape].forEach(function (tex) {
- _this.gpgpu.deleteMatrixTexture(tex);
- });
- }
- this.freeTextures = null;
- this.usedTextures = null;
- this.numUsedTextures = 0;
- this.numFreeTextures = 0;
- };
- return TextureManager;
- }());
- exports.TextureManager = TextureManager;
- function getPhysicalFromLogicalTextureType(logicalTexType) {
- if (logicalTexType === tex_util_1.TextureUsage.DOWNLOAD ||
- logicalTexType === tex_util_1.TextureUsage.PIXELS) {
- return tex_util_1.PhysicalTextureType.UNSIGNED_BYTE;
- }
- else if (logicalTexType === tex_util_1.TextureUsage.UPLOAD) {
- return tex_util_1.PhysicalTextureType.FLOAT32;
- }
- else if (logicalTexType === tex_util_1.TextureUsage.RENDER) {
- return environment_1.ENV.get('WEBGL_RENDER_FLOAT32_ENABLED') ?
- tex_util_1.PhysicalTextureType.FLOAT32 :
- tex_util_1.PhysicalTextureType.FLOAT16;
- }
- throw new Error("Unknown logical texture type " + logicalTexType);
- }
- function getKeyFromTextureShape(shapeRowsCol, physicalTexType) {
- return shapeRowsCol[0] + "_" + shapeRowsCol[1] + "_" + physicalTexType;
- }
- },{"../../environment":51,"./tex_util":102}],104:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var shader_compiler_1 = require("./shader_compiler");
- var TileProgram = (function () {
- function TileProgram(aShape, reps) {
- this.variableNames = ['A'];
- var outputShape = new Array(aShape.length);
- for (var i = 0; i < outputShape.length; i++) {
- outputShape[i] = aShape[i] * reps[i];
- }
- this.outputShape = outputShape;
- this.rank = outputShape.length;
- var dtype = shader_compiler_1.getCoordsDataType(this.rank);
- var sourceCoords = getSourceCoords(aShape);
- this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n setOutput(getA(" + sourceCoords + "));\n }\n ";
- }
- return TileProgram;
- }());
- exports.TileProgram = TileProgram;
- function getSourceCoords(aShape) {
- var rank = aShape.length;
- if (rank > 5) {
- throw Error("Tile for rank " + rank + " is not yet supported");
- }
- if (rank === 1) {
- return "imod(resRC, " + aShape[0] + ")";
- }
- var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w', 'resRC.u'];
- var sourceCoords = [];
- for (var i = 0; i < aShape.length; i++) {
- sourceCoords.push("imod(" + currentCoords[i] + ", " + aShape[i] + ")");
- }
- return sourceCoords.join();
- }
- },{"./shader_compiler":99}],105:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var shader_compiler_1 = require("./shader_compiler");
- var TransposeProgram = (function () {
- function TransposeProgram(aShape, newDim) {
- this.variableNames = ['A'];
- var outputShape = new Array(aShape.length);
- for (var i = 0; i < outputShape.length; i++) {
- outputShape[i] = aShape[newDim[i]];
- }
- this.outputShape = outputShape;
- this.rank = outputShape.length;
- var dtype = shader_compiler_1.getCoordsDataType(this.rank);
- var switched = getSwitchedCoords(newDim);
- this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n setOutput(getA(" + switched + "));\n }\n ";
- }
- return TransposeProgram;
- }());
- exports.TransposeProgram = TransposeProgram;
- function getSwitchedCoords(newDim) {
- var rank = newDim.length;
- if (rank > 6) {
- throw Error("Transpose for rank " + rank + " is not yet supported");
- }
- var originalOrder = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w', 'resRC.u', 'resRC.v'];
- var switchedCoords = new Array(rank);
- for (var i = 0; i < newDim.length; i++) {
- switchedCoords[newDim[i]] = originalOrder[i];
- }
- return switchedCoords.join();
- }
- },{"./shader_compiler":99}],106:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var erf_util = require("../../ops/erf_util");
- var selu_util = require("../../ops/selu_util");
- var UnaryOpProgram = (function () {
- function UnaryOpProgram(aShape, opSnippet) {
- this.variableNames = ['A'];
- this.outputShape = aShape;
- this.userCode = "\n float unaryOperation(float x) {\n " + opSnippet + "\n }\n\n void main() {\n float x = getAAtOutCoords();\n float y = unaryOperation(x);\n\n setOutput(y);\n }\n ";
- }
- return UnaryOpProgram;
- }());
- exports.UnaryOpProgram = UnaryOpProgram;
- var CHECK_NAN_SNIPPET = "if (isNaN(x)) return x;";
- exports.ABS = "return abs(x);";
- exports.RELU = CHECK_NAN_SNIPPET + "\n return (x < 0.0) ? 0.0 : x;\n";
- exports.ELU = "return (x >= 0.0) ? x : (exp(x) - 1.0);";
- exports.SELU = "\n // Stable and Attracting Fixed Point (0, 1) for Normalized Weights.\n // see: https://arxiv.org/abs/1706.02515\n float scaleAlpha = " + selu_util.SELU_SCALEALPHA + ";\n float scale = " + selu_util.SELU_SCALE + ";\n return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);\n";
- function STEP(alpha) {
- if (alpha === void 0) { alpha = 0.0; }
- return CHECK_NAN_SNIPPET + ("\n return x > 0.0 ? 1.0 : float(" + alpha + ");\n ");
- }
- exports.STEP = STEP;
- exports.NEG = "return -x;";
- exports.CEIL = "return ceil(x);";
- exports.FLOOR = "return floor(x);";
- exports.SIGN = "\n if (isNaN(x)) { return 0.0; }\n return sign(x);\n";
- exports.ROUND = "\n // OpenGL ES does not support round function.\n // The algorithm is based on banker's rounding.\n float base = floor(x);\n if ((x - base) < 0.5) {\n return floor(x);\n } else if ((x - base) > 0.5) {\n return ceil(x);\n } else {\n if (mod(base, 2.0) == 0.0) {\n return base;\n } else {\n return base + 1.0;\n }\n }\n";
- exports.EXP = "return exp(x);";
- exports.EXPM1 = "return exp(x) - 1.0;";
- exports.LOG = "return log(x);";
- exports.LOG1P = "return log(1.0 + x);";
- exports.SQRT = "return sqrt(x);";
- exports.RSQRT = "return inversesqrt(x);";
- exports.SIGMOID = "return 1.0 / (1.0 + exp(-1.0 * x));";
- exports.SOFTPLUS = "\n float epsilon = 1.1920928955078125e-7;\n float threshold = log(epsilon) + 2.0;\n\n bool too_large = x > -threshold;\n bool too_small = x < threshold;\n\n float result;\n float exp_x = exp(x);\n\n if (too_large){\n result = x;\n }\n else if (too_small){\n result = exp_x;\n }\n else{\n result = log(exp_x + 1.0);\n }\n return result;\n";
- exports.SIN = CHECK_NAN_SNIPPET + "\n return sin(x);\n";
- exports.COS = CHECK_NAN_SNIPPET + "\n return cos(x);\n";
- exports.TAN = "return tan(x);";
- exports.ASIN = "return asin(x);";
- exports.ACOS = "return acos(x);";
- exports.ATAN = CHECK_NAN_SNIPPET + "\n return atan(x);\n";
- exports.SINH = "\n float e2x = exp(x);\n return (e2x - 1.0 / e2x) / 2.0;\n";
- exports.COSH = "\n float e2x = exp(-x);\n return (e2x + 1.0 / e2x) / 2.0;\n";
- exports.TANH = "\n float e2x = exp(-2.0 * abs(x));\n return sign(x) * (1.0 - e2x) / (1.0 + e2x);\n";
- exports.ASINH = "return log(x + sqrt(x * x + 1.0));";
- exports.ACOSH = "return log(x + sqrt(x * x - 1.0));";
- exports.ATANH = "return (log(1.0 + x) - log(1.0 - x)) / 2.0;";
- exports.ERF = "\n // Error function is calculated approximately with elementary function.\n // See \"Handbook of Mathematical Functions with Formulas,\n // Graphs, and Mathematical Tables\", Abramowitz and Stegun.\n float p = " + erf_util.ERF_P + ";\n float a1 = " + erf_util.ERF_A1 + ";\n float a2 = " + erf_util.ERF_A2 + ";\n float a3 = " + erf_util.ERF_A3 + ";\n float a4 = " + erf_util.ERF_A4 + ";\n float a5 = " + erf_util.ERF_A5 + ";\n\n float t = 1.0 / (1.0 + p * x);\n return 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x);\n";
- exports.SQUARE = "return x * x;";
- exports.RECIPROCAL = "return 1.0 / x;";
- exports.LOGICAL_NOT = "return float(!(x >= 1.0));";
- exports.TO_INT = "return float(int(x));";
- },{"../../ops/erf_util":118,"../../ops/selu_util":137}],107:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var MAX_TEXTURE_SIZE = null;
- var util = require("../../util");
- var environment_1 = require("../../environment");
- function createWebGLRenderingContext(attributes) {
- var canvas = document.createElement('canvas');
- canvas.width = 1;
- canvas.height = 1;
- return createWebGLRenderingContextFromCanvas(canvas, attributes);
- }
- exports.createWebGLRenderingContext = createWebGLRenderingContext;
- function createWebGLRenderingContextFromCanvas(canvas, attributes) {
- var gl;
- var webglVersion = environment_1.ENV.get('WEBGL_VERSION');
- if (webglVersion === 2) {
- gl = canvas.getContext('webgl2', attributes);
- }
- else if (webglVersion === 1) {
- gl = (canvas.getContext('webgl', attributes) ||
- canvas.getContext('experimental-webgl', attributes));
- }
- if (webglVersion === 0 || gl == null) {
- throw new Error('This browser does not support WebGL.');
- }
- return gl;
- }
- exports.createWebGLRenderingContextFromCanvas = createWebGLRenderingContextFromCanvas;
- function callAndCheck(gl, func) {
- var returnValue = func();
- checkWebGLError(gl);
- return returnValue;
- }
- exports.callAndCheck = callAndCheck;
- var webGLDebugErrorCheckingEnabled = false;
- function enableDebugWebGLErrorChecking(enabled) {
- webGLDebugErrorCheckingEnabled = enabled;
- }
- exports.enableDebugWebGLErrorChecking = enableDebugWebGLErrorChecking;
- function checkWebGLError(gl) {
- if (webGLDebugErrorCheckingEnabled) {
- var error = gl.getError();
- if (error !== gl.NO_ERROR) {
- throw new Error('WebGL Error: ' + getWebGLErrorMessage(gl, error));
- }
- }
- }
- exports.checkWebGLError = checkWebGLError;
- function getWebGLErrorMessage(gl, status) {
- switch (status) {
- case gl.NO_ERROR:
- return 'NO_ERROR';
- case gl.INVALID_ENUM:
- return 'INVALID_ENUM';
- case gl.INVALID_VALUE:
- return 'INVALID_VALUE';
- case gl.INVALID_OPERATION:
- return 'INVALID_OPERATION';
- case gl.INVALID_FRAMEBUFFER_OPERATION:
- return 'INVALID_FRAMEBUFFER_OPERATION';
- case gl.OUT_OF_MEMORY:
- return 'OUT_OF_MEMORY';
- case gl.CONTEXT_LOST_WEBGL:
- return 'CONTEXT_LOST_WEBGL';
- default:
- return "Unknown error code " + status;
- }
- }
- exports.getWebGLErrorMessage = getWebGLErrorMessage;
- function getExtensionOrThrow(gl, extensionName) {
- return throwIfNull(gl, function () { return gl.getExtension(extensionName); }, 'Extension "' + extensionName + '" not supported on this browser.');
- }
- exports.getExtensionOrThrow = getExtensionOrThrow;
- function createVertexShader(gl, vertexShaderSource) {
- var vertexShader = throwIfNull(gl, function () { return gl.createShader(gl.VERTEX_SHADER); }, 'Unable to create vertex WebGLShader.');
- callAndCheck(gl, function () { return gl.shaderSource(vertexShader, vertexShaderSource); });
- callAndCheck(gl, function () { return gl.compileShader(vertexShader); });
- if (gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS) === false) {
- console.log(gl.getShaderInfoLog(vertexShader));
- throw new Error('Failed to compile vertex shader.');
- }
- return vertexShader;
- }
- exports.createVertexShader = createVertexShader;
- function createFragmentShader(gl, fragmentShaderSource) {
- var fragmentShader = throwIfNull(gl, function () { return gl.createShader(gl.FRAGMENT_SHADER); }, 'Unable to create fragment WebGLShader.');
- callAndCheck(gl, function () { return gl.shaderSource(fragmentShader, fragmentShaderSource); });
- callAndCheck(gl, function () { return gl.compileShader(fragmentShader); });
- if (gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS) === false) {
- logShaderSourceAndInfoLog(fragmentShaderSource, gl.getShaderInfoLog(fragmentShader));
- throw new Error('Failed to compile fragment shader.');
- }
- return fragmentShader;
- }
- exports.createFragmentShader = createFragmentShader;
- var lineNumberRegex = /ERROR: [0-9]+:([0-9]+):/g;
- function logShaderSourceAndInfoLog(shaderSource, shaderInfoLog) {
- var lineNumberRegexResult = lineNumberRegex.exec(shaderInfoLog);
- if (lineNumberRegexResult == null) {
- console.log("Couldn't parse line number in error: " + shaderInfoLog);
- console.log(shaderSource);
- return;
- }
- var lineNumber = +lineNumberRegexResult[1];
- var shaderLines = shaderSource.split('\n');
- var pad = shaderLines.length.toString().length + 2;
- var linesWithLineNumbers = shaderLines.map(function (line, lineNumber) {
- return util.rightPad((lineNumber + 1).toString(), pad) + line;
- });
- var maxLineLength = 0;
- for (var i = 0; i < linesWithLineNumbers.length; i++) {
- maxLineLength = Math.max(linesWithLineNumbers[i].length, maxLineLength);
- }
- var beforeErrorLines = linesWithLineNumbers.slice(0, lineNumber - 1);
- var errorLine = linesWithLineNumbers.slice(lineNumber - 1, lineNumber);
- var afterErrorLines = linesWithLineNumbers.slice(lineNumber);
- console.log(beforeErrorLines.join('\n'));
- console.log(shaderInfoLog.split('\n')[0]);
- console.log("%c " + util.rightPad(errorLine[0], maxLineLength), 'border:1px solid red; background-color:#e3d2d2; color:#a61717');
- console.log(afterErrorLines.join('\n'));
- }
- function createProgram(gl) {
- return throwIfNull(gl, function () { return gl.createProgram(); }, 'Unable to create WebGLProgram.');
- }
- exports.createProgram = createProgram;
- function linkProgram(gl, program) {
- callAndCheck(gl, function () { return gl.linkProgram(program); });
- if (gl.getProgramParameter(program, gl.LINK_STATUS) === false) {
- console.log(gl.getProgramInfoLog(program));
- throw new Error('Failed to link vertex and fragment shaders.');
- }
- }
- exports.linkProgram = linkProgram;
- function validateProgram(gl, program) {
- callAndCheck(gl, function () { return gl.validateProgram(program); });
- if (gl.getProgramParameter(program, gl.VALIDATE_STATUS) === false) {
- console.log(gl.getProgramInfoLog(program));
- throw new Error('Shader program validation failed.');
- }
- }
- exports.validateProgram = validateProgram;
- function createStaticVertexBuffer(gl, data) {
- var buffer = throwIfNull(gl, function () { return gl.createBuffer(); }, 'Unable to create WebGLBuffer');
- callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, buffer); });
- callAndCheck(gl, function () { return gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW); });
- return buffer;
- }
- exports.createStaticVertexBuffer = createStaticVertexBuffer;
- function createStaticIndexBuffer(gl, data) {
- var buffer = throwIfNull(gl, function () { return gl.createBuffer(); }, 'Unable to create WebGLBuffer');
- callAndCheck(gl, function () { return gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer); });
- callAndCheck(gl, function () { return gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, data, gl.STATIC_DRAW); });
- return buffer;
- }
- exports.createStaticIndexBuffer = createStaticIndexBuffer;
- function queryMaxTextureSize(gl) {
- if (MAX_TEXTURE_SIZE != null) {
- return MAX_TEXTURE_SIZE;
- }
- MAX_TEXTURE_SIZE =
- callAndCheck(gl, function () { return gl.getParameter(gl.MAX_TEXTURE_SIZE); });
- return MAX_TEXTURE_SIZE;
- }
- exports.queryMaxTextureSize = queryMaxTextureSize;
- function getNumChannels() {
- if (environment_1.ENV.get('WEBGL_VERSION') === 2) {
- return 1;
- }
- return 4;
- }
- exports.getNumChannels = getNumChannels;
- function createTexture(gl) {
- return throwIfNull(gl, function () { return gl.createTexture(); }, 'Unable to create WebGLTexture.');
- }
- exports.createTexture = createTexture;
- function validateTextureSize(gl, width, height) {
- var maxTextureSize = queryMaxTextureSize(gl);
- if ((width <= 0) || (height <= 0)) {
- var requested = "[" + width + "x" + height + "]";
- throw new Error('Requested texture size ' + requested + ' is invalid.');
- }
- if ((width > maxTextureSize) || (height > maxTextureSize)) {
- var requested = "[" + width + "x" + height + "]";
- var max = "[" + maxTextureSize + "x" + maxTextureSize + "]";
- throw new Error('Requested texture size ' + requested +
- ' greater than WebGL maximum on this browser / GPU ' + max + '.');
- }
- }
- exports.validateTextureSize = validateTextureSize;
- function createFramebuffer(gl) {
- return throwIfNull(gl, function () { return gl.createFramebuffer(); }, 'Unable to create WebGLFramebuffer.');
- }
- exports.createFramebuffer = createFramebuffer;
- function bindVertexBufferToProgramAttribute(gl, program, attribute, buffer, arrayEntriesPerItem, itemStrideInBytes, itemOffsetInBytes) {
- var loc = gl.getAttribLocation(program, attribute);
- if (loc === -1) {
- return false;
- }
- callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, buffer); });
- callAndCheck(gl, function () { return gl.vertexAttribPointer(loc, arrayEntriesPerItem, gl.FLOAT, false, itemStrideInBytes, itemOffsetInBytes); });
- callAndCheck(gl, function () { return gl.enableVertexAttribArray(loc); });
- return true;
- }
- exports.bindVertexBufferToProgramAttribute = bindVertexBufferToProgramAttribute;
- function bindTextureUnit(gl, texture, textureUnit) {
- validateTextureUnit(gl, textureUnit);
- callAndCheck(gl, function () { return gl.activeTexture(gl.TEXTURE0 + textureUnit); });
- callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); });
- }
- exports.bindTextureUnit = bindTextureUnit;
- function unbindTextureUnit(gl, textureUnit) {
- validateTextureUnit(gl, textureUnit);
- callAndCheck(gl, function () { return gl.activeTexture(gl.TEXTURE0 + textureUnit); });
- callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); });
- }
- exports.unbindTextureUnit = unbindTextureUnit;
- function getProgramUniformLocationOrThrow(gl, program, uniformName) {
- return throwIfNull(gl, function () { return gl.getUniformLocation(program, uniformName); }, 'uniform "' + uniformName + '" not present in program.');
- }
- exports.getProgramUniformLocationOrThrow = getProgramUniformLocationOrThrow;
- function getProgramUniformLocation(gl, program, uniformName) {
- return gl.getUniformLocation(program, uniformName);
- }
- exports.getProgramUniformLocation = getProgramUniformLocation;
- function bindTextureToProgramUniformSampler(gl, program, texture, uniformSamplerLocation, textureUnit) {
- callAndCheck(gl, function () { return bindTextureUnit(gl, texture, textureUnit); });
- callAndCheck(gl, function () { return gl.uniform1i(uniformSamplerLocation, textureUnit); });
- }
- exports.bindTextureToProgramUniformSampler = bindTextureToProgramUniformSampler;
- function bindCanvasToFramebuffer(gl) {
- callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, null); });
- callAndCheck(gl, function () { return gl.viewport(0, 0, gl.canvas.width, gl.canvas.height); });
- callAndCheck(gl, function () { return gl.scissor(0, 0, gl.canvas.width, gl.canvas.height); });
- }
- exports.bindCanvasToFramebuffer = bindCanvasToFramebuffer;
- function bindColorTextureToFramebuffer(gl, texture, framebuffer) {
- callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); });
- callAndCheck(gl, function () { return gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); });
- }
- exports.bindColorTextureToFramebuffer = bindColorTextureToFramebuffer;
- function unbindColorTextureFromFramebuffer(gl, framebuffer) {
- callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); });
- callAndCheck(gl, function () { return gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0); });
- }
- exports.unbindColorTextureFromFramebuffer = unbindColorTextureFromFramebuffer;
- function validateFramebuffer(gl) {
- var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
- if (status !== gl.FRAMEBUFFER_COMPLETE) {
- throw new Error('Error binding framebuffer: ' + getFramebufferErrorMessage(gl, status));
- }
- }
- exports.validateFramebuffer = validateFramebuffer;
- function getFramebufferErrorMessage(gl, status) {
- switch (status) {
- case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
- return 'FRAMEBUFFER_INCOMPLETE_ATTACHMENT';
- case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
- return 'FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT';
- case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
- return 'FRAMEBUFFER_INCOMPLETE_DIMENSIONS';
- case gl.FRAMEBUFFER_UNSUPPORTED:
- return 'FRAMEBUFFER_UNSUPPORTED';
- default:
- return "unknown error " + status;
- }
- }
- exports.getFramebufferErrorMessage = getFramebufferErrorMessage;
- function throwIfNull(gl, returnTOrNull, failureMessage) {
- var tOrNull = callAndCheck(gl, function () { return returnTOrNull(); });
- if (tOrNull == null) {
- throw new Error(failureMessage);
- }
- return tOrNull;
- }
- function validateTextureUnit(gl, textureUnit) {
- var maxTextureUnit = gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1;
- var glTextureUnit = textureUnit + gl.TEXTURE0;
- if (glTextureUnit < gl.TEXTURE0 || glTextureUnit > maxTextureUnit) {
- var textureUnitRange = "[gl.TEXTURE0, gl.TEXTURE" + maxTextureUnit + "]";
- throw new Error("textureUnit must be in " + textureUnitRange + ".");
- }
- }
- function getTextureShapeFromLogicalShape(gl, logShape) {
- if (logShape.length !== 2) {
- var squeezeResult = util.squeezeShape(logShape);
- logShape = squeezeResult.newShape;
- }
- var maxTexSize = queryMaxTextureSize(gl);
- var size = util.sizeFromShape(logShape);
- if (logShape.length <= 1 && size <= maxTexSize) {
- return [size, 1];
- }
- else if (logShape.length === 2 && logShape[0] <= maxTexSize &&
- logShape[1] <= maxTexSize) {
- return logShape;
- }
- else if (logShape.length === 3 && logShape[0] <= maxTexSize &&
- logShape[1] * logShape[2] <= maxTexSize) {
- return [logShape[0], logShape[1] * logShape[2]];
- }
- else if (logShape.length === 4 && logShape[0] <= maxTexSize &&
- logShape[1] * logShape[2] * logShape[3] <= maxTexSize) {
- return [logShape[0], logShape[1] * logShape[2] * logShape[3]];
- }
- else {
- return util.sizeToSquarishShape(size);
- }
- }
- exports.getTextureShapeFromLogicalShape = getTextureShapeFromLogicalShape;
- },{"../../environment":51,"../../util":164}],108:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var tensor_1 = require("../tensor");
- var tensor_util = require("../tensor_util");
- var util = require("../util");
- var axis_util = require("./axis_util");
- var axis_util_1 = require("./axis_util");
- var concat_1 = require("./concat");
- var operation_1 = require("./operation");
- var rand_1 = require("./rand");
- var segment_ops_1 = require("./segment_ops");
- var ArrayOps = (function () {
- function ArrayOps() {
- }
- ArrayOps.tensor = function (values, shape, dtype) {
- if (dtype === void 0) { dtype = 'float32'; }
- var inferredShape = util.inferShape(values);
- if (shape != null && inferredShape.length !== 1) {
- util.assertShapesMatch(shape, inferredShape, "Error creating a new Tensor. " +
- ("Inferred shape (" + inferredShape + ") does not match the ") +
- ("provided shape (" + shape + "). "));
- }
- if (!util.isTypedArray(values) && !Array.isArray(values)) {
- values = [values];
- }
- shape = shape || inferredShape;
- return tensor_1.Tensor.make(shape, { values: toTypedArray(values, dtype) }, dtype);
- };
- ArrayOps.scalar = function (value, dtype) {
- if (dtype === void 0) { dtype = 'float32'; }
- if (util.isTypedArray(value) || Array.isArray(value)) {
- throw new Error('Error creating a new Scalar: value must be a primitive ' +
- '(number|boolean)');
- }
- return ArrayOps.tensor(value, [], dtype);
- };
- ArrayOps.tensor1d = function (values, dtype) {
- if (dtype === void 0) { dtype = 'float32'; }
- var inferredShape = util.inferShape(values);
- if (inferredShape.length !== 1) {
- throw new Error('tensor1d() requires values to be a flat/TypedArray');
- }
- return ArrayOps.tensor(values, inferredShape, dtype);
- };
- ArrayOps.tensor2d = function (values, shape, dtype) {
- if (dtype === void 0) { dtype = 'float32'; }
- if (shape != null && shape.length !== 2) {
- throw new Error('tensor2d() requires shape to have two numbers');
- }
- var inferredShape = util.inferShape(values);
- if (inferredShape.length !== 2 && inferredShape.length !== 1) {
- throw new Error('tensor2d() requires values to be number[][] or flat/TypedArray');
- }
- if (inferredShape.length === 1 && shape == null) {
- throw new Error('tensor2d() requires shape to be provided when `values` ' +
- 'are a flat/TypedArray');
- }
- shape = shape || inferredShape;
- return ArrayOps.tensor(values, shape, dtype);
- };
- ArrayOps.tensor3d = function (values, shape, dtype) {
- if (dtype === void 0) { dtype = 'float32'; }
- if (shape != null && shape.length !== 3) {
- throw new Error('tensor3d() requires shape to have three numbers');
- }
- var inferredShape = util.inferShape(values);
- if (inferredShape.length !== 3 && inferredShape.length !== 1) {
- throw new Error('tensor3d() requires values to be number[][][] or flat/TypedArray');
- }
- if (inferredShape.length === 1 && shape == null) {
- throw new Error('tensor3d() requires shape to be provided when `values` ' +
- 'are a flat array');
- }
- shape = shape || inferredShape;
- return ArrayOps.tensor(values, shape, dtype);
- };
- ArrayOps.tensor4d = function (values, shape, dtype) {
- if (dtype === void 0) { dtype = 'float32'; }
- if (shape != null && shape.length !== 4) {
- throw new Error('tensor4d() requires shape to have four numbers');
- }
- var inferredShape = util.inferShape(values);
- if (inferredShape.length !== 4 && inferredShape.length !== 1) {
- throw new Error('tensor4d() requires values to be number[][][][] or flat/TypedArray');
- }
- if (inferredShape.length === 1 && shape == null) {
- throw new Error('tensor4d() requires shape to be provided when `values` ' +
- 'are a flat array');
- }
- shape = shape || inferredShape;
- return ArrayOps.tensor(values, shape, dtype);
- };
- ArrayOps.tensor5d = function (values, shape, dtype) {
- if (dtype === void 0) { dtype = 'float32'; }
- if (shape != null && shape.length !== 5) {
- throw new Error('tensor5d() requires shape to have five numbers');
- }
- var inferredShape = util.inferShape(values);
- if (inferredShape.length !== 5 && inferredShape.length !== 1) {
- throw new Error('tensor5d() requires values to be \
- number[][][][][] or flat/TypedArray');
- }
- if (inferredShape.length === 1 && shape == null) {
- throw new Error('tensor5d() requires shape to be provided when `values` ' +
- 'are a flat array');
- }
- shape = shape || inferredShape;
- return ArrayOps.tensor(values, shape, dtype);
- };
- ArrayOps.tensor6d = function (values, shape, dtype) {
- if (dtype === void 0) { dtype = 'float32'; }
- if (shape != null && shape.length !== 6) {
- throw new Error('tensor6d() requires shape to have six numbers');
- }
- var inferredShape = util.inferShape(values);
- if (inferredShape.length !== 6 && inferredShape.length !== 1) {
- throw new Error('tensor6d() requires values to be number[][][][] or flat/TypedArray');
- }
- if (inferredShape.length === 1 && shape == null) {
- throw new Error('tensor6d() requires shape to be provided when `values` ' +
- 'are a flat array');
- }
- shape = shape ||
- inferredShape;
- return ArrayOps.tensor(values, shape, dtype);
- };
- ArrayOps.ones = function (shape, dtype) {
- if (dtype === void 0) { dtype = 'float32'; }
- var values = makeOnesTypedArray(util.sizeFromShape(shape), dtype);
- return tensor_1.Tensor.make(shape, { values: values }, dtype);
- };
- ArrayOps.zeros = function (shape, dtype) {
- if (dtype === void 0) { dtype = 'float32'; }
- var values = makeZerosTypedArray(util.sizeFromShape(shape), dtype);
- return tensor_1.Tensor.make(shape, { values: values }, dtype);
- };
- ArrayOps.fill = function (shape, value, dtype) {
- if (dtype === void 0) { dtype = 'float32'; }
- var values = util.getTypedArrayFromDType(dtype, util.sizeFromShape(shape));
- values.fill(value);
- return tensor_1.Tensor.make(shape, { values: values }, dtype);
- };
- ArrayOps.onesLike = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'onesLike');
- return ArrayOps.ones(x.shape, x.dtype);
- };
- ArrayOps.zerosLike = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'zerosLike');
- return ArrayOps.zeros(x.shape, x.dtype);
- };
- ArrayOps.clone = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'clone');
- var der = function (dy) {
- return { x: function () { return dy.toFloat(); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) {
- return tensor_1.Tensor.make(x.shape, { dataId: x.dataId }, x.dtype);
- }, { x: x }, der);
- };
- ArrayOps.eye = function (numRows, numColumns, batchShape, dtype) {
- if (dtype === void 0) { dtype = 'float32'; }
- if (numColumns == null) {
- numColumns = numRows;
- }
- var buffer = ArrayOps.buffer([numRows, numColumns], dtype);
- var n = numRows <= numColumns ? numRows : numColumns;
- for (var i = 0; i < n; ++i) {
- buffer.set(1, i, i);
- }
- var out = buffer.toTensor().as2D(numRows, numColumns);
- if (batchShape == null) {
- return out;
- }
- else {
- if (batchShape.length === 1) {
- return ArrayOps.tile(ArrayOps.expandDims(out, 0), [batchShape[0], 1, 1]);
- }
- else if (batchShape.length === 2) {
- return ArrayOps.tile(ArrayOps.expandDims(ArrayOps.expandDims(out, 0), 0), [batchShape[0], batchShape[1], 1, 1]);
- }
- else {
- throw new Error("eye() currently supports only 1D and 2D " +
- ("batchShapes, but received " + batchShape.length + "D."));
- }
- }
- };
- ArrayOps.randomNormal = function (shape, mean, stdDev, dtype, seed) {
- if (mean === void 0) { mean = 0; }
- if (stdDev === void 0) { stdDev = 1; }
- if (dtype != null && dtype === 'bool') {
- throw new Error("Unsupported data type " + dtype);
- }
- var randGauss = new rand_1.MPRandGauss(mean, stdDev, dtype, false, seed);
- var res = ArrayOps.buffer(shape, dtype);
- for (var i = 0; i < res.values.length; i++) {
- res.values[i] = randGauss.nextValue();
- }
- return res.toTensor();
- };
- ArrayOps.truncatedNormal = function (shape, mean, stdDev, dtype, seed) {
- if (mean === void 0) { mean = 0; }
- if (stdDev === void 0) { stdDev = 1; }
- if (dtype != null && dtype === 'bool') {
- throw new Error("Unsupported data type " + dtype);
- }
- var randGauss = new rand_1.MPRandGauss(mean, stdDev, dtype, true, seed);
- var res = ArrayOps.buffer(shape, dtype);
- for (var i = 0; i < res.values.length; i++) {
- res.values[i] = randGauss.nextValue();
- }
- return res.toTensor();
- };
- ArrayOps.randomUniform = function (shape, minval, maxval, dtype) {
- if (minval === void 0) { minval = 0; }
- if (maxval === void 0) { maxval = 1; }
- if (dtype === void 0) { dtype = 'float32'; }
- var res = ArrayOps.buffer(shape, dtype);
- for (var i = 0; i < res.values.length; i++) {
- res.values[i] = util.randUniform(minval, maxval);
- }
- return res.toTensor();
- };
- ArrayOps.rand = function (shape, randFunction, dtype) {
- var size = util.sizeFromShape(shape);
- var values = null;
- if (dtype == null || dtype === 'float32') {
- values = new Float32Array(size);
- }
- else if (dtype === 'int32') {
- values = new Int32Array(size);
- }
- else if (dtype === 'bool') {
- values = new Uint8Array(size);
- }
- else {
- throw new Error("Unknown data type " + dtype);
- }
- for (var i = 0; i < size; i++) {
- values[i] = randFunction();
- }
- return tensor_1.Tensor.make(shape, { values: values }, dtype);
- };
- ArrayOps.multinomial = function (logits, numSamples, seed, normalized) {
- if (normalized === void 0) { normalized = false; }
- util.assertArgumentsAreTensors({ logits: logits }, 'multinomial');
- var numOutcomes = logits.size;
- var origRank = logits.rank;
- if (numOutcomes < 2) {
- throw new Error("Error in multinomial: you need at least 2 outcomes, but got " +
- (numOutcomes + "."));
- }
- if (origRank > 2) {
- throw new Error("Rank of probabilities must be 1 or 2, but is " + origRank);
- }
- seed = seed || Math.random();
- var logits2D = origRank === 1 ? logits.as2D(1, -1) : logits;
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.multinomial(logits2D, normalized, numSamples, seed); }, { logits2D: logits2D });
- return origRank === 1 ? res.as1D() : res;
- };
- ArrayOps.oneHot = function (indices, depth, onValue, offValue) {
- if (onValue === void 0) { onValue = 1; }
- if (offValue === void 0) { offValue = 0; }
- util.assert(indices.dtype === 'int32', 'Indices must be of dtype `int32`');
- if (depth < 2) {
- throw new Error("Error in oneHot: depth must be >=2, but it is " + depth);
- }
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.oneHot(indices, depth, onValue, offValue); }, { indices: indices });
- };
- ArrayOps.fromPixels = function (pixels, numChannels) {
- if (numChannels === void 0) { numChannels = 3; }
- if (numChannels > 4) {
- throw new Error('Cannot construct Tensor with more than 4 channels from pixels.');
- }
- return environment_1.ENV.engine.fromPixels(pixels, numChannels);
- };
- ArrayOps.toPixels = function (img, canvas) {
- return __awaiter(this, void 0, void 0, function () {
- var _a, height, width, depth, minTensor, maxTensor, min, max, data, multiplier, bytes, i, r, g, b, a, j, ctx, imageData;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- util.assertArgumentsAreTensors({ img: img }, 'toPixels');
- if (img.rank !== 2 && img.rank !== 3) {
- throw new Error("toPixels only supports rank 2 or 3 tensors, got rank " + img.rank + ".");
- }
- _a = img.shape.slice(0, 2), height = _a[0], width = _a[1];
- depth = img.rank === 2 ? 1 : img.shape[2];
- if (depth > 4 || depth === 2) {
- throw new Error("toPixels only supports depth of size " +
- ("1, 3 or 4 but got " + depth));
- }
- minTensor = img.min();
- maxTensor = img.max();
- return [4, minTensor.data()];
- case 1:
- min = (_b.sent())[0];
- return [4, maxTensor.data()];
- case 2:
- max = (_b.sent())[0];
- minTensor.dispose();
- maxTensor.dispose();
- if (img.dtype === 'float32') {
- if (min < 0 || max > 1) {
- throw new Error("Tensor values for a float32 Tensor must be in the " +
- ("range [0 - 1] but got range [" + min + " - " + max + "]."));
- }
- }
- else if (img.dtype === 'int32') {
- if (min < 0 || max > 255) {
- throw new Error("Tensor values for a int32 Tensor must be in the " +
- ("range [0 - 255] but got range [" + min + " - " + max + "]."));
- }
- }
- else {
- throw new Error("Unsupported type for toPixels: " + img.dtype + "." +
- " Please use float32 or int32 tensors.");
- }
- return [4, img.data()];
- case 3:
- data = _b.sent();
- multiplier = img.dtype === 'float32' ? 255 : 1;
- bytes = new Uint8ClampedArray(width * height * 4);
- for (i = 0; i < height * width; ++i) {
- r = void 0, g = void 0, b = void 0, a = void 0;
- if (depth === 1) {
- r = data[i] * multiplier;
- g = data[i] * multiplier;
- b = data[i] * multiplier;
- a = 255;
- }
- else if (depth === 3) {
- r = data[i * 3] * multiplier;
- g = data[i * 3 + 1] * multiplier;
- b = data[i * 3 + 2] * multiplier;
- a = 255;
- }
- else if (depth === 4) {
- r = data[i * 4] * multiplier;
- g = data[i * 4 + 1] * multiplier;
- b = data[i * 4 + 2] * multiplier;
- a = data[i * 4 + 3] * multiplier;
- }
- j = i * 4;
- bytes[j + 0] = Math.round(r);
- bytes[j + 1] = Math.round(g);
- bytes[j + 2] = Math.round(b);
- bytes[j + 3] = Math.round(a);
- }
- if (canvas != null) {
- canvas.width = width;
- canvas.height = height;
- ctx = canvas.getContext('2d');
- imageData = new ImageData(bytes, width, height);
- ctx.putImageData(imageData, 0, 0);
- }
- return [2, bytes];
- }
- });
- });
- };
- ArrayOps.reshape = function (x, shape) {
- util.assertArgumentsAreTensors({ x: x }, 'reshape');
- shape = util.inferFromImplicitShape(shape, x.size);
- util.assert(x.size === util.sizeFromShape(shape), 'new shape and old shape must have the same number of elements.');
- var grad = function (dy) {
- return { x: function () { return dy.reshape(x.shape); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.reshape(x, shape); }, { x: x }, grad);
- };
- ArrayOps.squeeze = function (x, axis) {
- util.assertArgumentsAreTensors({ x: x }, 'squeeze');
- return ArrayOps.reshape(x, util.squeezeShape(x.shape, axis).newShape);
- };
- ArrayOps.cast = function (x, dtype) {
- util.assertArgumentsAreTensors({ x: x }, 'cast');
- var grad = function (dy) {
- return { x: function () { return dy.clone(); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.cast(x, dtype); }, { x: x }, grad);
- };
- ArrayOps.tile = function (x, reps) {
- util.assertArgumentsAreTensors({ x: x }, 'tile');
- util.assert(x.rank === reps.length, "Error in transpose: rank of input " + x.rank + " " +
- ("must match length of reps " + reps + "."));
- var grad = function (dy) {
- var derX = function () {
- var xGrad = ArrayOps.zerosLike(x);
- if (x.rank === 1) {
- for (var i = 0; i < reps[0]; ++i) {
- xGrad = xGrad.add(dy.slice([i * x.shape[0]], [x.shape[0]]));
- }
- }
- else if (x.rank === 2) {
- for (var i = 0; i < reps[0]; ++i) {
- for (var j = 0; j < reps[1]; ++j) {
- xGrad = xGrad.add(dy.slice([i * x.shape[0], j * x.shape[1]], [x.shape[0], x.shape[1]]));
- }
- }
- }
- else if (x.rank === 3) {
- for (var i = 0; i < reps[0]; ++i) {
- for (var j = 0; j < reps[1]; ++j) {
- for (var k = 0; k < reps[2]; ++k) {
- xGrad = xGrad.add(dy.slice([i * x.shape[0], j * x.shape[1], k * x.shape[2]], [x.shape[0], x.shape[1], x.shape[2]]));
- }
- }
- }
- }
- else if (x.rank === 4) {
- for (var i = 0; i < reps[0]; ++i) {
- for (var j = 0; j < reps[1]; ++j) {
- for (var k = 0; k < reps[2]; ++k) {
- for (var l = 0; l < reps[3]; ++l) {
- xGrad = xGrad.add(dy.slice([
- i * x.shape[0], j * x.shape[1], k * x.shape[2],
- l * x.shape[3]
- ], [x.shape[0], x.shape[1], x.shape[2], x.shape[3]]));
- }
- }
- }
- }
- }
- else {
- throw new Error("Gradient for tile operation is not implemented for rank-" +
- (x.rank + " tensors yet."));
- }
- return xGrad;
- };
- return { x: derX };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.tile(x, reps); }, { x: x }, grad);
- };
- ArrayOps.gather = function (x, indices, axis) {
- if (axis === void 0) { axis = 0; }
- util.assertArgumentsAreTensors({ x: x, indices: indices }, 'gather');
- util.assert(indices.dtype === 'int32', 'Indices must be of dtype `int32`');
- axis = axis_util_1.parseAxisParam(axis, x.shape)[0];
- var grad = function (dy) {
- var derX = function () {
- if (axis === 0) {
- return segment_ops_1.SegmentOps.unsortedSegmentSum(dy, indices, x.shape[axis]);
- }
- var paramsShape = x.shape;
- var indicesSize = indices.size;
- var outerShape = paramsShape.slice(0, axis);
- var outerDims = outerShape.length;
- var innerShape = paramsShape.slice(axis, paramsShape.length).slice(1);
- var innerDims = innerShape.length;
- var outerAxesIndices = arrayRange(0, outerDims);
- var innerAxesIndices = arrayRange(outerDims + 1, outerDims + 1 + innerDims);
- var valuesShape = arrayConcat([outerShape, [indicesSize], innerShape]);
- var values = dy.reshape(valuesShape);
- var reshapedIndices = indices.reshape([indicesSize]);
- var transposeDims = arrayConcat([[outerDims], outerAxesIndices, innerAxesIndices]);
- var valuesTranspose = values.transpose(transposeDims);
- var paramsGrad = segment_ops_1.SegmentOps.unsortedSegmentSum(valuesTranspose, reshapedIndices, x.shape[axis]);
- var invertTransposeDims = axis_util.getUndoAxesPermutation(transposeDims);
- paramsGrad = paramsGrad.transpose(invertTransposeDims);
- return paramsGrad;
- };
- return { x: derX };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.gather(x, indices, axis); }, { x: x }, grad);
- };
- ArrayOps.pad1d = function (x, paddings, constantValue) {
- if (constantValue === void 0) { constantValue = 0; }
- util.assert(paddings.length === 2, 'Invalid number of paddings. Must be length of 2.');
- return ArrayOps.pad(x, [paddings], constantValue);
- };
- ArrayOps.pad2d = function (x, paddings, constantValue) {
- if (constantValue === void 0) { constantValue = 0; }
- util.assert(paddings.length === 2 && paddings[0].length === 2 &&
- paddings[1].length === 2, 'Invalid number of paddings. Must be length of 2 each.');
- return ArrayOps.pad(x, paddings, constantValue);
- };
- ArrayOps.pad3d = function (x, paddings, constantValue) {
- if (constantValue === void 0) { constantValue = 0; }
- util.assert(paddings.length === 3 && paddings[0].length === 2 &&
- paddings[1].length === 2 && paddings[2].length === 2, 'Invalid number of paddings. Must be length of 2 each.');
- return ArrayOps.pad(x, paddings, constantValue);
- };
- ArrayOps.pad4d = function (x, paddings, constantValue) {
- if (constantValue === void 0) { constantValue = 0; }
- util.assert(paddings.length === 4 && paddings[0].length === 2 &&
- paddings[1].length === 2 && paddings[2].length === 2 &&
- paddings[3].length === 2, 'Invalid number of paddings. Must be length of 2 each.');
- return ArrayOps.pad(x, paddings, constantValue);
- };
- ArrayOps.pad = function (x, paddings, constantValue) {
- if (constantValue === void 0) { constantValue = 0; }
- util.assertArgumentsAreTensors({ x: x }, 'pad');
- if (x.rank === 0) {
- throw new Error('pad(scalar) is not defined. Pass non-scalar to pad');
- }
- var begin = paddings.map(function (p) { return p[0]; });
- var grad = function (dy) {
- return { x: function () { return dy.slice(begin, x.shape); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.pad(x, paddings, constantValue); }, { x: x }, grad);
- };
- ArrayOps.stack = function (tensors, axis) {
- if (axis === void 0) { axis = 0; }
- util.assertArgumentsAreTensors({ tensors: tensors }, 'stack');
- util.assert(tensors.length >= 1, 'Pass at least one tensor to tf.stack');
- if (tensors.length === 1) {
- return tensors[0].expandDims(axis);
- }
- var rank = tensors[0].rank;
- var shape = tensors[0].shape;
- var dtype = tensors[0].dtype;
- util.assert(axis <= rank, 'Axis must be <= rank of the tensor');
- tensors.forEach(function (t) {
- util.assertShapesMatch(shape, t.shape, 'All tensors passed to stack must have matching shapes');
- });
- tensors.forEach(function (t) {
- util.assert(dtype === t.dtype, 'All tensors passed to stack must have matching dtypes');
- });
- var expandedTensors = tensors.map(function (t) { return t.expandDims(axis); });
- return concat_1.ConcatOps.concat(expandedTensors, axis);
- };
- ArrayOps.unstack = function (value, axis) {
- if (axis === void 0) { axis = 0; }
- var num = value.shape[axis];
- var outputShape = Array(value.rank - 1).fill(0);
- var outIndex = 0;
- for (var i = 0; i < value.rank; i++) {
- if (i !== axis) {
- outputShape[outIndex] = value.shape[i];
- outIndex++;
- }
- }
- var splitSizes;
- splitSizes = Array(num).fill(1);
- var begin = Array(value.rank).fill(0);
- var size = value.shape.slice();
- return splitSizes.map(function (s) {
- size[axis] = s;
- var slice = value.slice(begin, size);
- begin[axis] += s;
- return slice.reshape(outputShape);
- });
- };
- ArrayOps.split = function (x, numOrSizeSplits, axis) {
- if (axis === void 0) { axis = 0; }
- util.assertArgumentsAreTensors({ x: x }, 'split');
- axis = axis_util_1.parseAxisParam(axis, x.shape)[0];
- var splitSizes;
- if (typeof (numOrSizeSplits) === 'number') {
- util.assert(x.shape[axis] % numOrSizeSplits === 0, 'Number of splits must evenly divide the axis.');
- splitSizes = Array(numOrSizeSplits).fill(x.shape[axis] / numOrSizeSplits);
- }
- else {
- util.assert(x.shape[axis] === numOrSizeSplits.reduce(function (a, b) { return a + b; }), 'The sum of sizes must match the size of the axis dimension.');
- splitSizes = numOrSizeSplits;
- }
- var begin = Array(x.rank).fill(0);
- var size = x.shape.slice();
- return splitSizes.map(function (s) {
- size[axis] = s;
- var slice = x.slice(begin, size);
- begin[axis] += s;
- return slice;
- });
- };
- ArrayOps.cumsum = function (x, axis, exclusive, reverse) {
- if (axis === void 0) { axis = 0; }
- if (exclusive === void 0) { exclusive = false; }
- if (reverse === void 0) { reverse = false; }
- util.assertArgumentsAreTensors({ x: x }, 'cumsum');
- axis = axis | 0;
- var permutation = axis_util_1.getAxesPermutation([axis], x.rank);
- var permutedX = x;
- if (permutation != null) {
- permutedX = x.transpose(permutation);
- }
- var permutedAxis = axis_util_1.getInnerMostAxes(1, x.rank)[0];
- var grad = function (dy) {
- return { permutedX: function () { return dy.cumsum(axis, exclusive, !reverse); } };
- };
- var value = environment_1.ENV.engine.runKernel(function (backend) { return backend.cumsum(permutedX, permutedAxis, exclusive, reverse); }, { permutedX: permutedX }, grad);
- if (permutation != null) {
- value = value.transpose(permutation);
- }
- return value;
- };
- ArrayOps.expandDims = function (x, axis) {
- if (axis === void 0) { axis = 0; }
- util.assertArgumentsAreTensors({ x: x }, 'expandDims');
- util.assert(axis <= x.rank, 'Axis must be <= rank of the tensor');
- var newShape = x.shape.slice();
- newShape.splice(axis, 0, 1);
- return ArrayOps.reshape(x, newShape);
- };
- ArrayOps.linspace = function (start, stop, num) {
- if (num === 0) {
- throw new Error('Cannot request zero samples');
- }
- var step = (stop - start) / (num - 1);
- var values = makeZerosTypedArray(num, 'float32');
- values[0] = start;
- for (var i = 1; i < values.length; i++) {
- values[i] = values[i - 1] + step;
- }
- return ArrayOps.tensor1d(values, 'float32');
- };
- ArrayOps.range = function (start, stop, step, dtype) {
- if (step === void 0) { step = 1; }
- if (dtype === void 0) { dtype = 'float32'; }
- if (step === 0) {
- throw new Error('Cannot have a step of zero');
- }
- var sameStartStop = start === stop;
- var increasingRangeNegativeStep = start < stop && step < 0;
- var decreasingRangePositiveStep = stop < start && step > 1;
- if (sameStartStop || increasingRangeNegativeStep ||
- decreasingRangePositiveStep) {
- return ArrayOps.zeros([0], dtype);
- }
- var numElements = Math.abs(Math.ceil((stop - start) / step));
- var values = makeZerosTypedArray(numElements, dtype);
- if (stop < start && step === 1) {
- step = -1;
- }
- values[0] = start;
- for (var i = 1; i < values.length; i++) {
- values[i] = values[i - 1] + step;
- }
- return ArrayOps.tensor1d(values, dtype);
- };
- ArrayOps.buffer = function (shape, dtype, values) {
- if (dtype === void 0) { dtype = 'float32'; }
- return new tensor_1.TensorBuffer(shape, dtype, values);
- };
- ArrayOps.print = function (x, verbose) {
- if (verbose === void 0) { verbose = false; }
- console.log(tensor_util.tensorToString(x, verbose));
- };
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], ArrayOps, "tensor", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], ArrayOps, "scalar", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], ArrayOps, "tensor1d", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], ArrayOps, "tensor2d", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], ArrayOps, "tensor3d", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], ArrayOps, "tensor4d", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], ArrayOps, "tensor5d", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], ArrayOps, "tensor6d", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),
- operation_1.operation
- ], ArrayOps, "ones", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),
- operation_1.operation
- ], ArrayOps, "zeros", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),
- operation_1.operation
- ], ArrayOps, "fill", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),
- operation_1.operation
- ], ArrayOps, "onesLike", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),
- operation_1.operation
- ], ArrayOps, "zerosLike", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),
- operation_1.operation
- ], ArrayOps, "clone", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),
- operation_1.operation
- ], ArrayOps, "eye", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),
- operation_1.operation
- ], ArrayOps, "randomNormal", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),
- operation_1.operation
- ], ArrayOps, "truncatedNormal", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),
- operation_1.operation
- ], ArrayOps, "randomUniform", null);
- __decorate([
- operation_1.operation
- ], ArrayOps, "rand", null);
- __decorate([
- operation_1.operation
- ], ArrayOps, "multinomial", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),
- operation_1.operation
- ], ArrayOps, "oneHot", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),
- operation_1.operation
- ], ArrayOps, "fromPixels", null);
- __decorate([
- doc_1.doc({ heading: 'Visualization' })
- ], ArrayOps, "toPixels", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }),
- operation_1.operation
- ], ArrayOps, "reshape", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' })
- ], ArrayOps, "squeeze", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }),
- operation_1.operation
- ], ArrayOps, "cast", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),
- operation_1.operation
- ], ArrayOps, "tile", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),
- operation_1.operation
- ], ArrayOps, "gather", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }),
- operation_1.operation
- ], ArrayOps, "pad", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),
- operation_1.operation
- ], ArrayOps, "stack", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),
- operation_1.operation
- ], ArrayOps, "unstack", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),
- operation_1.operation
- ], ArrayOps, "split", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Scan' })
- ], ArrayOps, "cumsum", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }),
- operation_1.operation
- ], ArrayOps, "expandDims", null);
- __decorate([
- operation_1.operation,
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], ArrayOps, "linspace", null);
- __decorate([
- operation_1.operation,
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], ArrayOps, "range", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], ArrayOps, "buffer", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], ArrayOps, "print", null);
- return ArrayOps;
- }());
- exports.ArrayOps = ArrayOps;
- function makeZerosTypedArray(size, dtype) {
- if (dtype == null || dtype === 'float32') {
- return new Float32Array(size);
- }
- else if (dtype === 'int32') {
- return new Int32Array(size);
- }
- else if (dtype === 'bool') {
- return new Uint8Array(size);
- }
- else {
- throw new Error("Unknown data type $ {dtype}");
- }
- }
- function makeOnesTypedArray(size, dtype) {
- var array = makeZerosTypedArray(size, dtype);
- for (var i = 0; i < array.length; i++) {
- array[i] = 1;
- }
- return array;
- }
- function toTypedArray(a, dtype) {
- if (noConversionNeeded(a, dtype)) {
- return a;
- }
- if (Array.isArray(a)) {
- a = util.flatten(a);
- }
- return util.copyTypedArray(a, dtype);
- }
- function noConversionNeeded(a, dtype) {
- return (a instanceof Float32Array && dtype === 'float32') ||
- (a instanceof Int32Array && dtype === 'int32') ||
- (a instanceof Uint8Array && dtype === 'bool');
- }
- function arrayRange(start, stop) {
- var result = [];
- for (var i = start; i < stop; ++i) {
- result.push(i);
- }
- return result;
- }
- function arrayConcat(arrays) {
- var result = [];
- for (var i = 0; i < arrays.length; ++i) {
- for (var j = 0; j < arrays[i].length; ++j) {
- result.push(arrays[i][j]);
- }
- }
- return result;
- }
- },{"../doc":49,"../environment":51,"../tensor":158,"../tensor_util":159,"../util":164,"./axis_util":109,"./concat":114,"./operation":128,"./rand":131,"./segment_ops":135}],109:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var util = require("../util");
- function axesAreInnerMostDims(axes, rank) {
- for (var i = 0; i < axes.length; ++i) {
- if (axes[axes.length - i - 1] !== rank - 1 - i) {
- return false;
- }
- }
- return true;
- }
- exports.axesAreInnerMostDims = axesAreInnerMostDims;
- function combineLocations(outputLoc, reduceLoc, axes) {
- var rank = outputLoc.length + reduceLoc.length;
- var loc = [];
- var outIdx = 0;
- var reduceIdx = 0;
- for (var dim = 0; dim < rank; dim++) {
- if (axes.indexOf(dim) === -1) {
- loc.push(outputLoc[outIdx++]);
- }
- else {
- loc.push(reduceLoc[reduceIdx++]);
- }
- }
- return loc;
- }
- exports.combineLocations = combineLocations;
- function computeOutAndReduceShapes(aShape, axes) {
- var outShape = [];
- var rank = aShape.length;
- for (var dim = 0; dim < rank; dim++) {
- if (axes.indexOf(dim) === -1) {
- outShape.push(aShape[dim]);
- }
- }
- var reduceShape = axes.map(function (dim) { return aShape[dim]; });
- return [outShape, reduceShape];
- }
- exports.computeOutAndReduceShapes = computeOutAndReduceShapes;
- function expandShapeToKeepDim(shape, axes) {
- var reduceSubShape = axes.map(function (x) { return 1; });
- return combineLocations(shape, reduceSubShape, axes);
- }
- exports.expandShapeToKeepDim = expandShapeToKeepDim;
- function parseAxisParam(axis, shape) {
- var rank = shape.length;
- axis = axis == null ? shape.map(function (s, i) { return i; }) : [].concat(axis);
- util.assert(axis.every(function (ax) { return ax >= -rank && ax < rank; }), "All values in axis param must be in range [-" + rank + ", " + rank + ") but " +
- ("got axis " + axis));
- util.assert(axis.every(function (ax) { return util.isInt(ax); }), "All values in axis param must be integers but " +
- ("got axis " + axis));
- return axis.map(function (a) { return a < 0 ? rank + a : a; });
- }
- exports.parseAxisParam = parseAxisParam;
- function assertAxesAreInnerMostDims(msg, axes, rank) {
- util.assert(axesAreInnerMostDims(axes, rank), msg + " supports only inner-most axes for now. " +
- ("Got axes " + axes + " and rank-" + rank + " input."));
- }
- exports.assertAxesAreInnerMostDims = assertAxesAreInnerMostDims;
- function getAxesPermutation(axes, rank) {
- if (axesAreInnerMostDims(axes, rank)) {
- return null;
- }
- var result = [];
- for (var i = 0; i < rank; ++i) {
- if (axes.indexOf(i) === -1) {
- result.push(i);
- }
- }
- axes.forEach(function (axis) { return result.push(axis); });
- return result;
- }
- exports.getAxesPermutation = getAxesPermutation;
- function getUndoAxesPermutation(axes) {
- return axes.map(function (axis, i) { return [i, axis]; })
- .sort(function (a, b) { return a[1] - b[1]; })
- .map(function (x) { return x[0]; });
- }
- exports.getUndoAxesPermutation = getUndoAxesPermutation;
- function getInnerMostAxes(numAxes, rank) {
- var res = [];
- for (var i = rank - numAxes; i < rank; ++i) {
- res.push(i);
- }
- return res;
- }
- exports.getInnerMostAxes = getInnerMostAxes;
- },{"../util":164}],110:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var util = require("../util");
- var array_ops_1 = require("./array_ops");
- var broadcast_util_1 = require("./broadcast_util");
- var operation_1 = require("./operation");
- var ops_1 = require("./ops");
- var BatchNormOps = (function () {
- function BatchNormOps() {
- }
- BatchNormOps.batchNormalization2d = function (x, mean, variance, varianceEpsilon, scale, offset) {
- if (varianceEpsilon === void 0) { varianceEpsilon = .001; }
- util.assert(x.rank === 2, "Error in batchNormalization3D: x must be rank 3 but got rank " +
- (x.rank + "."));
- util.assert(mean.rank === 2 || mean.rank === 1, "Error in batchNormalization2D: mean must be rank 2 or rank 1 but " +
- ("got rank " + mean.rank + "."));
- util.assert(variance.rank === 2 || variance.rank === 1, "Error in batchNormalization2D: variance must be rank 2 or rank 1 " +
- ("but got rank " + variance.rank + "."));
- if (scale != null) {
- util.assert(scale.rank === 2 || scale.rank === 1, "Error in batchNormalization2D: scale must be rank 2 or rank 1 " +
- ("but got rank " + scale.rank + "."));
- }
- if (offset != null) {
- util.assert(offset.rank === 2 || offset.rank === 1, "Error in batchNormalization2D: offset must be rank 2 or rank 1 " +
- ("but got rank " + offset.rank + "."));
- }
- return BatchNormOps.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset);
- };
- BatchNormOps.batchNormalization3d = function (x, mean, variance, varianceEpsilon, scale, offset) {
- if (varianceEpsilon === void 0) { varianceEpsilon = .001; }
- util.assert(x.rank === 3, "Error in batchNormalization3D: x must be rank 3 but got rank " +
- (x.rank + "."));
- util.assert(mean.rank === 3 || mean.rank === 1, "Error in batchNormalization3D: mean must be rank 3 or rank 1 but " +
- ("got rank " + mean.rank + "."));
- util.assert(variance.rank === 3 || variance.rank === 1, "Error in batchNormalization3D: variance must be rank 3 or rank 1 " +
- ("but got rank " + variance.rank + "."));
- if (scale != null) {
- util.assert(scale.rank === 3 || scale.rank === 1, "Error in batchNormalization3D: scale must be rank 3 or rank 1 " +
- ("but got rank " + scale.rank + "."));
- }
- if (offset != null) {
- util.assert(offset.rank === 3 || offset.rank === 1, "Error in batchNormalization3D: offset must be rank 3 or rank 1 " +
- ("but got rank " + offset.rank + "."));
- }
- return BatchNormOps.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset);
- };
- BatchNormOps.batchNormalization4d = function (x, mean, variance, varianceEpsilon, scale, offset) {
- if (varianceEpsilon === void 0) { varianceEpsilon = .001; }
- util.assert(x.rank === 4, "Error in batchNormalization4D: x must be rank 4 but got rank " +
- (x.rank + "."));
- util.assert(mean.rank === 4 || mean.rank === 1, "Error in batchNormalization4D: mean must be rank 4 or rank 1 but " +
- ("got rank " + mean.rank + "."));
- util.assert(variance.rank === 4 || variance.rank === 1, "Error in batchNormalization4D: variance must be rank 4 or rank 1 " +
- ("but got rank " + variance.rank + "."));
- if (scale != null) {
- util.assert(scale.rank === 4 || scale.rank === 1, "Error in batchNormalization4D: scale must be rank 4 or rank 1 " +
- ("but got rank " + scale.rank + "."));
- }
- if (offset != null) {
- util.assert(offset.rank === 4 || offset.rank === 1, "Error in batchNormalization4D: offset must be rank 4 or rank 1 " +
- ("but got rank " + offset.rank + "."));
- }
- return BatchNormOps.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset);
- };
- BatchNormOps.batchNormalization = function (x, mean, variance, varianceEpsilon, scale, offset) {
- if (varianceEpsilon === void 0) { varianceEpsilon = .001; }
- util.assertArgumentsAreTensors({ x: x, mean: mean, variance: variance }, 'batchNormalization');
- if (scale != null) {
- util.assertArgumentsAreTensors({ scale: scale }, 'batchNormalization');
- }
- if (offset != null) {
- util.assertArgumentsAreTensors({ offset: offset }, 'batchNormalization');
- }
- util.assert(mean.rank === variance.rank, 'Batch normalization gradient requires mean and variance to have ' +
- 'equal ranks.');
- util.assert(offset == null || mean.rank === offset.rank, 'Batch normalization gradient requires mean and offset to have ' +
- 'equal ranks.');
- util.assert(scale == null || mean.rank === scale.rank, 'Batch normalization gradient requires mean and scale to have ' +
- 'equal ranks.');
- var x4D;
- if (x.rank === 0 || x.rank === 1) {
- x4D = x.as4D(1, 1, 1, x.size);
- }
- else if (x.rank === 2) {
- x4D = x.as4D(1, 1, x.shape[0], x.shape[1]);
- }
- else if (x.rank === 3) {
- x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);
- }
- else {
- x4D = x;
- }
- var der = function (dy) {
- var scaleValue = scale == null ? array_ops_1.ArrayOps.scalar(1) : scale;
- var reductionAxes = broadcast_util_1.getReductionAxes(mean.shape, x4D.shape);
- var tileShape = [];
- if (mean.rank === 1) {
- for (var i = 0; i < x4D.shape.length - 1; ++i) {
- tileShape.push(x4D.shape[i]);
- }
- tileShape.push(1);
- }
- var xMinusMean = x.sub(mean);
- var dyTimesScaleValue = dy.mul(scaleValue);
- var oneOverSqrtVariance = ops_1.rsqrt(variance.add(array_ops_1.ArrayOps.scalar(varianceEpsilon)));
- var minusHalfRCube = oneOverSqrtVariance.mul(oneOverSqrtVariance)
- .mul(oneOverSqrtVariance)
- .mul(array_ops_1.ArrayOps.scalar(-0.5));
- var derX = function () {
- if (mean.rank === 1) {
- return dy
- .mul(array_ops_1.ArrayOps.tile(oneOverSqrtVariance.as4D(1, 1, 1, mean.shape[0]), tileShape))
- .mul(scaleValue)
- .reshape(x.shape);
- }
- else {
- return dy.mul(oneOverSqrtVariance).mul(scaleValue).reshape(x.shape);
- }
- };
- var derMean = function () {
- var meanDer = oneOverSqrtVariance.mul(array_ops_1.ArrayOps.scalar(-1)).mul(dyTimesScaleValue);
- if (mean.rank === 1) {
- meanDer = meanDer.sum(reductionAxes);
- }
- return meanDer.reshape(mean.shape);
- };
- var derVariance = function () {
- var varianceDer = minusHalfRCube.mul(xMinusMean).mul(dyTimesScaleValue);
- if (mean.rank === 1) {
- varianceDer = varianceDer.sum(reductionAxes);
- }
- return varianceDer.reshape(mean.shape);
- };
- var derScale = function () {
- var xMinusMean2TimesRsqrt = xMinusMean.mul(oneOverSqrtVariance);
- var scaleDer = dy.mul(xMinusMean2TimesRsqrt);
- if (mean.rank === 1) {
- scaleDer = scaleDer.sum(reductionAxes);
- }
- return scaleDer.reshape(mean.shape);
- };
- var derOffset = function () {
- var offsetDer = dy;
- if (mean.rank === 1) {
- offsetDer = offsetDer.sum(reductionAxes);
- }
- return offsetDer.reshape(mean.shape);
- };
- return {
- x: derX,
- mean: derMean,
- variance: derVariance,
- scale: derScale,
- offset: derOffset
- };
- };
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.batchNormalization(x4D, batchnormReshape4D(mean), batchnormReshape4D(variance), varianceEpsilon, batchnormReshape4D(scale), batchnormReshape4D(offset)); }, { x: x, mean: mean, variance: variance, scale: scale, offset: offset }, der);
- return res.reshape(x.shape);
- };
- __decorate([
- operation_1.operation
- ], BatchNormOps, "batchNormalization2d", null);
- __decorate([
- operation_1.operation
- ], BatchNormOps, "batchNormalization3d", null);
- __decorate([
- operation_1.operation
- ], BatchNormOps, "batchNormalization4d", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Normalization' })
- ], BatchNormOps, "batchNormalization", null);
- return BatchNormOps;
- }());
- exports.BatchNormOps = BatchNormOps;
- function batchnormReshape4D(x) {
- if (x == null) {
- return null;
- }
- if (x.rank === 0) {
- return x.as1D();
- }
- else if (x.rank === 1) {
- return x;
- }
- else if (x.rank === 2) {
- return x.as4D(1, 1, x.shape[0], x.shape[1]);
- }
- else if (x.rank === 3) {
- return x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);
- }
- return x;
- }
- },{"../doc":49,"../environment":51,"../util":164,"./array_ops":108,"./broadcast_util":112,"./operation":128,"./ops":129}],111:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var types_1 = require("../types");
- var util = require("../util");
- var broadcast_util = require("./broadcast_util");
- var operation_1 = require("./operation");
- var ops_1 = require("./ops");
- var BinaryOps = (function () {
- function BinaryOps() {
- }
- BinaryOps.add = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'add');
- util.assertTypesMatch(a, b);
- var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- var der = function (dy) {
- var derA = function () {
- var res = dy;
- var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape);
- if (reduceAxes.length > 0) {
- res = res.sum(reduceAxes);
- }
- return res.reshape(a.shape);
- };
- var derB = function () {
- var res = dy;
- var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape);
- if (reduceAxes.length > 0) {
- res = res.sum(reduceAxes);
- }
- return res.reshape(b.shape);
- };
- return { a: derA, b: derB };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.add(a, b); }, { a: a, b: b }, der);
- };
- BinaryOps.addStrict = function (a, b) {
- util.assertShapesMatch(a.shape, b.shape, 'Error in addStrict: ');
- return a.add(b);
- };
- BinaryOps.sub = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'sub');
- util.assertTypesMatch(a, b);
- var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- var der = function (dy) {
- var derA = function () {
- var res = dy;
- var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape);
- if (reduceAxes.length > 0) {
- res = res.sum(reduceAxes);
- }
- return res.reshape(a.shape);
- };
- var derB = function () {
- var res = dy;
- var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape);
- if (reduceAxes.length > 0) {
- res = res.sum(reduceAxes);
- }
- return res.neg().reshape(b.shape);
- };
- return { a: derA, b: derB };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.subtract(a, b); }, { a: a, b: b }, der);
- };
- BinaryOps.subStrict = function (a, b) {
- util.assertShapesMatch(a.shape, b.shape, 'Error in subStrict: ');
- return a.sub(b);
- };
- BinaryOps.pow = function (base, exp) {
- util.assertArgumentsAreTensors({ base: base, exp: exp }, 'pow');
- var outShape = broadcast_util.assertAndGetBroadcastShape(base.shape, exp.shape);
- base = base.cast(types_1.upcastType(base.dtype, exp.dtype));
- exp = exp.cast(types_1.upcastType(base.dtype, exp.dtype));
- var grad = function (dy, saved) {
- var y = saved[0];
- var derBase = function () {
- var res = dy.mul(exp.toFloat().mul(y.div(base)));
- var reduceAxes = broadcast_util.getReductionAxes(base.shape, outShape);
- if (reduceAxes.length > 0) {
- res = res.sum(reduceAxes);
- }
- return res.reshape(base.shape);
- };
- var derExp = function () {
- var res = dy.mul(y.mul(base.log()).toFloat());
- var reduceAxes = broadcast_util.getReductionAxes(exp.shape, outShape);
- if (reduceAxes.length > 0) {
- res = res.sum(reduceAxes);
- }
- return res.reshape(exp.shape);
- };
- return { base: derBase, exp: derExp };
- };
- return environment_1.ENV.engine.runKernel(function (backend, save) { return save(backend.pow(base, exp)); }, { base: base, exp: exp }, grad);
- };
- BinaryOps.powStrict = function (base, exp) {
- util.assertShapesMatch(base.shape, exp.shape, 'Error in powStrict: ');
- return base.pow(exp);
- };
- BinaryOps.mul = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'mul');
- util.assertTypesMatch(a, b);
- var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- var der = function (dy) {
- var derA = function () {
- var res = dy.mul(b.toFloat());
- var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape);
- if (reduceAxes.length > 0) {
- return res.sum(reduceAxes).reshape(a.shape);
- }
- return res;
- };
- var derB = function () {
- var res = dy.mul(a.toFloat());
- var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape);
- if (reduceAxes.length > 0) {
- return res.sum(reduceAxes).reshape(b.shape);
- }
- return res;
- };
- return { a: derA, b: derB };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.multiply(a, b); }, { a: a, b: b }, der);
- };
- BinaryOps.mulStrict = function (a, b) {
- util.assertShapesMatch(a.shape, b.shape, 'Error in multiplyStrict: ');
- return a.mul(b);
- };
- BinaryOps.div = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'div');
- util.assertTypesMatch(a, b);
- var forwardFunc;
- if (a.dtype === 'int32' && b.dtype === 'int32') {
- return BinaryOps.floorDiv(a, b);
- }
- else {
- forwardFunc = function (backend) { return backend.realDivide(a, b); };
- }
- var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- var der = function (dy) {
- var derA = function () {
- var res = dy.div(b.toFloat());
- var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape);
- if (reduceAxes.length > 0) {
- return res.sum(reduceAxes).reshape(a.shape);
- }
- return res;
- };
- var derB = function () {
- var res = dy.mul(a.toFloat());
- var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape);
- if (reduceAxes.length > 0) {
- res = res.sum(reduceAxes).reshape(b.shape);
- }
- var tmp = b.square();
- return res.div(tmp.toFloat()).neg();
- };
- return { a: derA, b: derB };
- };
- return environment_1.ENV.engine.runKernel(forwardFunc, { a: a, b: b }, der);
- };
- BinaryOps.floorDiv = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'floorDiv');
- util.assertTypesMatch(a, b);
- var forwardFunc = function (backend) { return backend.floorDiv(a, b); };
- var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- var der = function (dy) {
- var derA = function () {
- var res = dy.div(b.toFloat());
- var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape);
- if (reduceAxes.length > 0) {
- return res.sum(reduceAxes).reshape(a.shape);
- }
- return res;
- };
- var derB = function () {
- var res = dy.mul(a.toFloat());
- var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape);
- if (reduceAxes.length > 0) {
- res = res.sum(reduceAxes).reshape(b.shape);
- }
- var tmp = b.square();
- return res.div(tmp.toFloat()).neg();
- };
- return { a: derA, b: derB };
- };
- return environment_1.ENV.engine.runKernel(forwardFunc, { a: a, b: b }, der);
- };
- BinaryOps.divStrict = function (a, b) {
- util.assertShapesMatch(a.shape, b.shape, 'Error in divideStrict: ');
- return a.div(b);
- };
- BinaryOps.mod = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'mod');
- util.assertTypesMatch(a, b);
- var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- var der = function (dy) {
- var derA = function () {
- var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape);
- if (reduceAxes.length > 0) {
- return dy.sum(reduceAxes).reshape(a.shape);
- }
- return dy;
- };
- var derB = function () {
- var res = dy.mul(a.div(b).floor().neg());
- var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape);
- if (reduceAxes.length > 0) {
- return res.sum(reduceAxes).reshape(b.shape);
- }
- return res;
- };
- return { a: derA, b: derB };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.mod(a, b); }, { a: a, b: b }, der);
- };
- BinaryOps.modStrict = function (a, b) {
- util.assertShapesMatch(a.shape, b.shape, 'Error in modStrict: ');
- return a.mod(b);
- };
- BinaryOps.minimum = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'minimum');
- util.assertTypesMatch(a, b);
- if (a.dtype === 'bool') {
- a = a.toInt();
- }
- if (b.dtype === 'bool') {
- b = b.toInt();
- }
- broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- var der = function (dy) {
- var derA = function () { return dy.mul(a.lessEqual(b).toFloat()); };
- var derB = function () { return dy.mul(a.greater(b).toFloat()); };
- return { a: derA, b: derB };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.minimum(a, b); }, { a: a, b: b }, der);
- };
- BinaryOps.minimumStrict = function (a, b) {
- util.assertShapesMatch(a.shape, b.shape, 'Error in minimumStrict: ');
- return a.minimum(b);
- };
- BinaryOps.maximum = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'maximum');
- util.assertTypesMatch(a, b);
- if (a.dtype === 'bool') {
- a = a.toInt();
- }
- if (b.dtype === 'bool') {
- b = b.toInt();
- }
- broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- var der = function (dy) {
- var derA = function () { return dy.mul(a.greaterEqual(b).toFloat()); };
- var derB = function () { return dy.mul(a.less(b).toFloat()); };
- return { a: derA, b: derB };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.maximum(a, b); }, { a: a, b: b }, der);
- };
- BinaryOps.maximumStrict = function (a, b) {
- util.assertShapesMatch(a.shape, b.shape, 'Error in minimumStrict: ');
- return a.maximum(b);
- };
- BinaryOps.squaredDifference = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'squaredDifference');
- util.assertTypesMatch(a, b);
- broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- var der = function (dy) {
- var two = ops_1.scalar(2);
- var derA = function () { return dy.mul(a.sub(b).mul(two)); };
- var derB = function () { return dy.mul(b.sub(a).mul(two)); };
- return { a: derA, b: derB };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.squaredDifference(a, b); }, { a: a, b: b }, der);
- };
- BinaryOps.squaredDifferenceStrict = function (a, b) {
- util.assertShapesMatch(a.shape, b.shape, 'Error in squaredDifferenceStrict: ');
- return a.squaredDifference(b);
- };
- BinaryOps.atan2 = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'atan2');
- util.assertTypesMatch(a, b);
- var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- var der = function (dy) {
- var derA = function () {
- var d = BinaryOps.add(ops_1.square(a), ops_1.square(b));
- var res = dy.mul(b.div(d));
- var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape);
- if (reduceAxes.length > 0) {
- res = res.sum(reduceAxes);
- }
- return res.reshape(a.shape);
- };
- var derB = function () {
- var d = BinaryOps.add(ops_1.square(a), ops_1.square(b));
- var res = ops_1.neg(dy.mul(a.div(d)));
- var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape);
- if (reduceAxes.length > 0) {
- res = res.sum(reduceAxes);
- }
- return res.reshape(b.shape);
- };
- return { a: derA, b: derB };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.atan2(a, b); }, { a: a, b: b }, der);
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),
- operation_1.operation
- ], BinaryOps, "add", null);
- __decorate([
- operation_1.operation
- ], BinaryOps, "addStrict", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),
- operation_1.operation
- ], BinaryOps, "sub", null);
- __decorate([
- operation_1.operation
- ], BinaryOps, "subStrict", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),
- operation_1.operation
- ], BinaryOps, "pow", null);
- __decorate([
- operation_1.operation
- ], BinaryOps, "powStrict", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),
- operation_1.operation
- ], BinaryOps, "mul", null);
- __decorate([
- operation_1.operation
- ], BinaryOps, "mulStrict", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),
- operation_1.operation
- ], BinaryOps, "div", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),
- operation_1.operation
- ], BinaryOps, "floorDiv", null);
- __decorate([
- operation_1.operation
- ], BinaryOps, "divStrict", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),
- operation_1.operation
- ], BinaryOps, "mod", null);
- __decorate([
- operation_1.operation
- ], BinaryOps, "modStrict", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),
- operation_1.operation
- ], BinaryOps, "minimum", null);
- __decorate([
- operation_1.operation
- ], BinaryOps, "minimumStrict", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),
- operation_1.operation
- ], BinaryOps, "maximum", null);
- __decorate([
- operation_1.operation
- ], BinaryOps, "maximumStrict", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),
- operation_1.operation
- ], BinaryOps, "squaredDifference", null);
- __decorate([
- operation_1.operation
- ], BinaryOps, "squaredDifferenceStrict", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], BinaryOps, "atan2", null);
- return BinaryOps;
- }());
- exports.BinaryOps = BinaryOps;
- },{"../doc":49,"../environment":51,"../types":163,"../util":164,"./broadcast_util":112,"./operation":128,"./ops":129}],112:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- function getBroadcastDims(inShape, outShape) {
- var inRank = inShape.length;
- var dims = [];
- for (var i = 0; i < inRank; i++) {
- var dim = inRank - 1 - i;
- var a = inShape[dim] || 1;
- var b = outShape[outShape.length - 1 - i] || 1;
- if (b > 1 && a === 1) {
- dims.unshift(dim);
- }
- }
- return dims;
- }
- exports.getBroadcastDims = getBroadcastDims;
- function getReductionAxes(inShape, outShape) {
- var result = [];
- for (var i = 0; i < outShape.length; i++) {
- var inDim = inShape[inShape.length - i - 1];
- var outAxis = outShape.length - i - 1;
- var outDim = outShape[outAxis];
- if (inDim == null || (inDim === 1 && outDim > 1)) {
- result.unshift(outAxis);
- }
- }
- return result;
- }
- exports.getReductionAxes = getReductionAxes;
- function broadcastDimsAreOuter(dims) {
- for (var i = 0; i < dims.length; i++) {
- if (dims[i] !== i) {
- return false;
- }
- }
- return true;
- }
- exports.broadcastDimsAreOuter = broadcastDimsAreOuter;
- function assertAndGetBroadcastShape(shapeA, shapeB) {
- var result = [];
- var errMsg = "Operands could not be broadcast together with shapes " +
- (shapeA + " and " + shapeB + ".");
- var l = Math.max(shapeA.length, shapeB.length);
- for (var i = 0; i < l; i++) {
- var a = shapeA[shapeA.length - i - 1] || 1;
- var b = shapeB[shapeB.length - i - 1] || 1;
- if (a > 1 && b > 1 && a !== b) {
- throw Error(errMsg);
- }
- result.unshift(Math.max(a, b));
- }
- return result;
- }
- exports.assertAndGetBroadcastShape = assertAndGetBroadcastShape;
- },{}],113:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var util = require("../util");
- var broadcast_util = require("./broadcast_util");
- var operation_1 = require("./operation");
- var CompareOps = (function () {
- function CompareOps() {
- }
- CompareOps.notEqual = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'notEqual');
- util.assertTypesMatch(a, b);
- broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.notEqual(a, b); }, { a: a, b: b });
- };
- CompareOps.notEqualStrict = function (a, b) {
- util.assertShapesMatch(a.shape, b.shape, 'Error in notEqualStrict: ');
- return a.notEqual(b);
- };
- CompareOps.less = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'less');
- util.assertTypesMatch(a, b);
- broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.less(a, b); }, { a: a, b: b });
- };
- CompareOps.lessStrict = function (a, b) {
- util.assertShapesMatch(a.shape, b.shape, 'Error in lessStrict: ');
- return a.less(b);
- };
- CompareOps.equal = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'equal');
- util.assertTypesMatch(a, b);
- broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.equal(a, b); }, { a: a, b: b });
- };
- CompareOps.equalStrict = function (a, b) {
- util.assertShapesMatch(a.shape, b.shape, 'Error in equalStrict: ');
- return a.equal(b);
- };
- CompareOps.lessEqual = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'lessEqual');
- util.assertTypesMatch(a, b);
- broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.lessEqual(a, b); }, { a: a, b: b });
- };
- CompareOps.lessEqualStrict = function (a, b) {
- util.assertShapesMatch(a.shape, b.shape, 'Error in lessEqualStrict: ');
- return a.lessEqual(b);
- };
- CompareOps.greater = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'greater');
- util.assertTypesMatch(a, b);
- broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.greater(a, b); }, { a: a, b: b });
- };
- CompareOps.greaterStrict = function (a, b) {
- util.assertShapesMatch(a.shape, b.shape, 'Error in greaterStrict: ');
- return a.greater(b);
- };
- CompareOps.greaterEqual = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'greaterEqual');
- util.assertTypesMatch(a, b);
- broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.greaterEqual(a, b); }, { a: a, b: b });
- };
- CompareOps.greaterEqualStrict = function (a, b) {
- util.assertShapesMatch(a.shape, b.shape, 'Error in greaterEqualStrict: ');
- return a.greaterEqual(b);
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),
- operation_1.operation
- ], CompareOps, "notEqual", null);
- __decorate([
- operation_1.operation
- ], CompareOps, "notEqualStrict", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),
- operation_1.operation
- ], CompareOps, "less", null);
- __decorate([
- operation_1.operation
- ], CompareOps, "lessStrict", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),
- operation_1.operation
- ], CompareOps, "equal", null);
- __decorate([
- operation_1.operation
- ], CompareOps, "equalStrict", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),
- operation_1.operation
- ], CompareOps, "lessEqual", null);
- __decorate([
- operation_1.operation
- ], CompareOps, "lessEqualStrict", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),
- operation_1.operation
- ], CompareOps, "greater", null);
- __decorate([
- operation_1.operation
- ], CompareOps, "greaterStrict", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),
- operation_1.operation
- ], CompareOps, "greaterEqual", null);
- __decorate([
- operation_1.operation
- ], CompareOps, "greaterEqualStrict", null);
- return CompareOps;
- }());
- exports.CompareOps = CompareOps;
- },{"../doc":49,"../environment":51,"../util":164,"./broadcast_util":112,"./operation":128}],114:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var util = require("../util");
- var axis_util_1 = require("./axis_util");
- var concat_util = require("./concat_util");
- var operation_1 = require("./operation");
- var ConcatOps = (function () {
- function ConcatOps() {
- }
- ConcatOps.concat1d = function (tensors) {
- return ConcatOps.concat(tensors, 0);
- };
- ConcatOps.concat2d = function (tensors, axis) {
- return ConcatOps.concat(tensors, axis);
- };
- ConcatOps.concat3d = function (tensors, axis) {
- return ConcatOps.concat(tensors, axis);
- };
- ConcatOps.concat4d = function (tensors, axis) {
- return ConcatOps.concat(tensors, axis);
- };
- ConcatOps.concat = function (tensors, axis) {
- if (axis === void 0) { axis = 0; }
- util.assert(tensors.length >= 1, 'Pass at least one tensor to concat');
- util.assertArgumentsAreTensors({ tensors: tensors }, 'concat');
- var result = tensors[0];
- if (tensors.length === 1) {
- return result;
- }
- var axes = axis_util_1.parseAxisParam(axis, result.shape);
- for (var i = 1; i < tensors.length; ++i) {
- result = concat2Tensors(result, tensors[i], axes[0]);
- }
- return result;
- };
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),
- operation_1.operation
- ], ConcatOps, "concat", null);
- return ConcatOps;
- }());
- exports.ConcatOps = ConcatOps;
- function concat2Tensors(a, b, axis) {
- concat_util.assertParams(a.shape, b.shape, axis);
- var outShape = concat_util.computeOutShape(a.shape, b.shape, axis);
- var a2D = a.as2D(-1, util.sizeFromShape(a.shape.slice(axis)));
- var b2D = b.as2D(-1, util.sizeFromShape(b.shape.slice(axis)));
- var _a = concat_util.computeGradientSliceShapes(a2D.shape, b2D.shape), aBegin = _a.aBegin, aSize = _a.aSize, bBegin = _a.bBegin, bSize = _a.bSize;
- var der = function (dy) {
- return { a: function () { return dy.slice(aBegin, aSize); }, b: function () { return dy.slice(bBegin, bSize); } };
- };
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.concat(a2D, b2D); }, { a: a2D, b: b2D }, der);
- return res.reshape(outShape);
- }
- },{"../doc":49,"../environment":51,"../util":164,"./axis_util":109,"./concat_util":115,"./operation":128}],115:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var util = require("../util");
- function assertParams(aShape, bShape, axis) {
- var aRank = aShape.length;
- var bRank = bShape.length;
- util.assert(aShape.length === bShape.length, "Error in concat" + aRank + "D: rank of x1 (" + aRank + ") and x2 (" + bRank + ") " +
- "must be the same.");
- util.assert(axis >= 0 && axis < aRank, "Error in concat" + aRank + "D: axis must be " +
- ("between 0 and " + (aRank - 1) + "."));
- for (var i = 0; i < aRank; i++) {
- util.assert((i === axis) || (aShape[i] === bShape[i]), "Error in concat" + aRank + "D: Shape (" + aShape + ") does not match " +
- ("(" + bShape + ") along the non-concatenated axis " + i + "."));
- }
- }
- exports.assertParams = assertParams;
- function computeOutShape1D(x1Shape, x2Shape) {
- util.assert(x1Shape.length === 1 && x2Shape.length === 1, 'x1 and x2 should be 1d array.');
- var outputShape = x1Shape.slice();
- outputShape[0] += x2Shape[0];
- return outputShape;
- }
- exports.computeOutShape1D = computeOutShape1D;
- function computeOutShape(x1Shape, x2Shape, axis) {
- util.assert(x1Shape.length === x2Shape.length, 'x1 and x2 should have the same rank.');
- var outputShape = x1Shape.slice();
- outputShape[axis] += x2Shape[axis];
- return outputShape;
- }
- exports.computeOutShape = computeOutShape;
- function computeGradientSliceShapes(aShape, bShape) {
- return {
- aBegin: [0, 0],
- aSize: aShape,
- bBegin: [0, aShape[1]],
- bSize: bShape
- };
- }
- exports.computeGradientSliceShapes = computeGradientSliceShapes;
- },{"../util":164}],116:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var util = require("../util");
- var conv_util = require("./conv_util");
- var operation_1 = require("./operation");
- var ConvOps = (function () {
- function ConvOps() {
- }
- ConvOps.conv1d = function (x, filter, stride, pad, dataFormat, dilation, dimRoundingMode) {
- if (dataFormat === void 0) { dataFormat = 'NWC'; }
- if (dilation === void 0) { dilation = 1; }
- util.assertArgumentsAreTensors({ x: x, filter: filter }, 'conv1d');
- var x3D = x;
- var reshapedTo3D = false;
- if (x.rank === 2) {
- reshapedTo3D = true;
- x3D = x.as3D(1, x.shape[0], x.shape[1]);
- }
- util.assert(x3D.rank === 3, "Error in conv1d: input must be rank 3, but got rank " + x3D.rank + ".");
- util.assert(filter.rank === 3, "Error in conv1d: filter must be rank 3, but got rank " +
- (filter.rank + "."));
- if (dimRoundingMode != null) {
- util.assert(util.isInt(pad), "Error in conv1d: pad must be an integer when using, " +
- ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + "."));
- }
- util.assert(x3D.shape[2] === filter.shape[1], "Error in conv1d: depth of input (" + x3D.shape[2] + ") must match " +
- ("input depth for filter " + filter.shape[1] + "."));
- util.assert(eitherStridesOrDilationsAreOne(stride, dilation), 'Error in conv1D: Either stride or dilation must be 1. ' +
- ("Got stride " + stride + " and dilation '" + dilation + "'"));
- util.assert(dataFormat === 'NWC', "Error in conv1d: got dataFormat of " + dataFormat + " but only NWC is currently supported.");
- var filter4D = filter.as4D(1, filter.shape[0], filter.shape[1], filter.shape[2]);
- var input4D = x3D.as4D(x3D.shape[0], 1, x3D.shape[1], x3D.shape[2]);
- var strides = [1, stride];
- var dilations = [1, dilation];
- var conv2dDataFormat = 'NHWC';
- var res = ConvOps.conv2d(input4D, filter4D, strides, pad, conv2dDataFormat, dilations, dimRoundingMode);
- if (reshapedTo3D) {
- return res.as2D(res.shape[2], res.shape[3]);
- }
- return res.as3D(res.shape[0], res.shape[2], res.shape[3]);
- };
- ConvOps.conv2d = function (x, filter, strides, pad, dataFormat, dilations, dimRoundingMode) {
- if (dataFormat === void 0) { dataFormat = 'NHWC'; }
- if (dilations === void 0) { dilations = [1, 1]; }
- util.assertArgumentsAreTensors({ x: x, filter: filter }, 'conv2d');
- var x4D = x;
- var reshapedTo4D = false;
- if (x.rank === 3) {
- reshapedTo4D = true;
- x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);
- }
- util.assert(x4D.rank === 4, "Error in conv2d: input must be rank 4, but got rank " + x4D.rank + ".");
- util.assert(filter.rank === 4, "Error in conv2d: filter must be rank 4, but got rank " +
- (filter.rank + "."));
- if (dimRoundingMode != null) {
- util.assert(util.isInt(pad), "Error in conv2d: pad must be an integer when using, " +
- ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + "."));
- }
- util.assert(x4D.shape[3] === filter.shape[2], "Error in conv2d: depth of input (" + x4D.shape[3] + ") must match " +
- ("input depth for filter " + filter.shape[2] + "."));
- util.assert(eitherStridesOrDilationsAreOne(strides, dilations), 'Error in conv2D: Either strides or dilations must be 1. ' +
- ("Got strides " + strides + " and dilations '" + dilations + "'"));
- util.assert(dataFormat === 'NHWC', "Error in conv2d: got dataFormat of " + dataFormat + " but only NHWC is currently supported.");
- var convInfo = conv_util.computeConv2DInfo(x4D.shape, filter.shape, strides, dilations, pad, dimRoundingMode);
- var grad = function (dy) {
- util.assert(tupleValuesAreOne(dilations), 'Error in gradient of conv2D: dilation rates greater than 1 are not' +
- ("yet supported in gradients. Got dilations '" + dilations + "'"));
- return {
- x: function () { return ConvOps.conv2dDerInput(x4D.shape, dy, filter, strides, pad); },
- filter: function () {
- return ConvOps.conv2dDerFilter(x4D, dy, filter.shape, strides, pad);
- }
- };
- };
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.conv2d(x4D, filter, convInfo); }, { x: x4D, filter: filter }, grad);
- if (reshapedTo4D) {
- return res.as3D(res.shape[1], res.shape[2], res.shape[3]);
- }
- return res;
- };
- ConvOps.conv2dDerInput = function (xShape, dy, filter, strides, pad, dimRoundingMode) {
- util.assertArgumentsAreTensors({ dy: dy, filter: filter }, 'conv2dDerInput');
- util.assert(xShape.length === dy.rank, "Length of inShape " +
- ("(" + xShape.length + ") and rank of dy (" + dy.rank + ") must match"));
- var xShape4D = xShape;
- var dy4D = dy;
- var reshapedTo4D = false;
- if (dy.rank === 3) {
- reshapedTo4D = true;
- dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]);
- xShape4D = [1, xShape[0], xShape[1], xShape[2]];
- }
- var inDepth = xShape4D[3];
- var outDepth = dy4D.shape[3];
- util.assert(xShape4D.length === 4, "Error in conv2dDerInput: inShape must be length 4, but got length " +
- (xShape4D.length + "."));
- util.assert(dy4D.rank === 4, "Error in conv2dDerInput: dy must be rank 4, but got " +
- ("rank " + dy4D.rank));
- util.assert(filter.rank === 4, "Error in conv2dDerInput: filter must be rank 4, but got " +
- ("rank " + filter.rank));
- util.assert(inDepth === filter.shape[2], "Error in conv2dDerInput: depth of input (" + inDepth + ") must " +
- ("match input depth for filter " + filter.shape[2] + "."));
- util.assert(outDepth === filter.shape[3], "Error in conv2dDerInput: depth of output (" + outDepth + ") must " +
- ("match output depth for filter " + filter.shape[3] + "."));
- if (dimRoundingMode != null) {
- util.assert(util.isInt(pad), "Error in conv2dDerInput: pad must be an integer when using, " +
- ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + "."));
- }
- var dilations = 1;
- var convInfo = conv_util.computeConv2DInfo(xShape4D, filter.shape, strides, dilations, pad, dimRoundingMode);
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.conv2dDerInput(dy4D, filter, convInfo); }, { dy4D: dy4D });
- if (reshapedTo4D) {
- return res.as3D(res.shape[1], res.shape[2], res.shape[3]);
- }
- return res;
- };
- ConvOps.conv2dDerFilter = function (x, dy, filterShape, strides, pad, dimRoundingMode) {
- util.assertArgumentsAreTensors({ x: x, dy: dy }, 'conv2dDerFilter');
- var x4D = x;
- if (x.rank === 3) {
- x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);
- }
- var dy4D = dy;
- if (dy4D.rank === 3) {
- dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]);
- }
- util.assert(x4D.rank === 4, "Error in conv2dDerFilter: input must be rank 4, but got shape " +
- (x4D.shape + "."));
- util.assert(dy4D.rank === 4, "Error in conv2dDerFilter: dy must be rank 4, but got shape " +
- (dy4D.shape + "."));
- util.assert(filterShape.length === 4, "Error in conv2dDerFilter: filterShape must be length 4, but got " +
- (filterShape + "."));
- util.assert(x4D.shape[3] === filterShape[2], "Error in conv2dDerFilter: depth of input " + x4D.shape[3] + ") must " +
- ("match input depth in filter (" + filterShape[2] + "."));
- util.assert(dy4D.shape[3] === filterShape[3], "Error in conv2dDerFilter: depth of dy (" + dy4D.shape[3] + ") must " +
- ("match output depth for filter (" + filterShape[3] + ")."));
- if (dimRoundingMode != null) {
- util.assert(util.isInt(pad), "Error in conv2dDerFilter: pad must be an integer when using, " +
- ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + "."));
- }
- var dilations = 1;
- var convInfo = conv_util.computeConv2DInfo(x4D.shape, filterShape, strides, dilations, pad, dimRoundingMode);
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.conv2dDerFilter(x4D, dy4D, convInfo); }, { x4D: x4D, dy4D: dy4D });
- };
- ConvOps.conv2dTranspose = function (x, filter, outputShape, strides, pad, dimRoundingMode) {
- util.assertArgumentsAreTensors({ x: x, filter: filter }, 'conv2dTranspose');
- return ConvOps.conv2dDerInput(outputShape, x, filter, strides, pad, dimRoundingMode);
- };
- ConvOps.depthwiseConv2d = function (x, filter, strides, pad, dataFormat, dilations, dimRoundingMode) {
- if (dataFormat === void 0) { dataFormat = 'NHWC'; }
- if (dilations === void 0) { dilations = [1, 1]; }
- util.assertArgumentsAreTensors({ x: x, filter: filter }, 'depthwiseConv2d');
- var x4D = x;
- var reshapedTo4D = false;
- if (x.rank === 3) {
- reshapedTo4D = true;
- x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);
- }
- util.assert(x4D.rank === 4, "Error in depthwiseConv2d: input must be rank 4, but got " +
- ("rank " + x4D.rank + "."));
- util.assert(filter.rank === 4, "Error in depthwiseConv2d: filter must be rank 4, but got rank " +
- (filter.rank + "."));
- util.assert(x4D.shape[3] === filter.shape[2], "Error in depthwiseConv2d: number of input channels " +
- ("(" + x4D.shape[3] + ") must match the inChannels dimension in ") +
- ("filter " + filter.shape[2] + "."));
- if (dilations == null) {
- dilations = [1, 1];
- }
- util.assert(eitherStridesOrDilationsAreOne(strides, dilations), 'Error in depthwiseConv2d: Either strides or dilations must be 1. ' +
- ("Got strides " + strides + " and dilations '" + dilations + "'"));
- if (dimRoundingMode != null) {
- util.assert(util.isInt(pad), "Error in depthwiseConv2d: pad must be an integer when using, " +
- ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + "."));
- }
- var convInfo = conv_util.computeConv2DInfo(x4D.shape, filter.shape, strides, dilations, pad, dimRoundingMode, true);
- var grad = function (dy) {
- util.assert(tupleValuesAreOne(dilations), 'Error in gradient of depthwiseConv2d: dilation rates greater than ' +
- ("1 are not yet supported. Got dilations '" + dilations + "'"));
- return {
- x: function () { return depthwiseConv2dDerInput(x4D.shape, dy, filter, convInfo); },
- filter: function () { return depthwiseConv2dDerFilter(x4D, dy, filter.shape, convInfo); },
- };
- };
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.depthwiseConv2D(x4D, filter, convInfo); }, { x: x4D, filter: filter }, grad);
- if (reshapedTo4D) {
- return res.as3D(res.shape[1], res.shape[2], res.shape[3]);
- }
- return res;
- };
- ConvOps.separableConv2d = function (x, depthwiseFilter, pointwiseFilter, strides, pad, dilation, dataFormat) {
- if (dilation === void 0) { dilation = [1, 1]; }
- if (dataFormat === void 0) { dataFormat = 'NHWC'; }
- util.assertArgumentsAreTensors({ x: x, depthwiseFilter: depthwiseFilter, pointwiseFilter: pointwiseFilter }, 'separableConv2d');
- var x4D = x;
- var reshapedTo4D = false;
- if (x.rank === 3) {
- reshapedTo4D = true;
- x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);
- }
- if (dataFormat === 'NCHW') {
- throw new Error('separableConv2d currently does not support dataFormat NCHW; only ' +
- 'NHWC is supported');
- }
- util.assert(x4D.rank === 4, "Error in separableConv2d: input must be rank 4, but got " +
- ("rank " + x4D.rank + "."));
- util.assert(depthwiseFilter.rank === 4, "Error in separableConv2d: depthwise filter must be rank 4, but got " +
- ("rank " + depthwiseFilter.rank + "."));
- util.assert(pointwiseFilter.rank === 4, "Error in separableConv2d: pointwise filter must be rank 4, but got " +
- ("rank " + depthwiseFilter.rank + "."));
- util.assert(pointwiseFilter.shape[0] === 1, "Error in separableConv2d: the first dimension of pointwise filter " +
- (" must be 1, but got " + pointwiseFilter.shape[0] + "."));
- util.assert(pointwiseFilter.shape[1] === 1, "Error in separableConv2d: the second dimension of pointwise filter " +
- (" must be 1, but got " + pointwiseFilter.shape[1] + "."));
- var inChannels = depthwiseFilter.shape[2];
- var channelMultiplier = depthwiseFilter.shape[3];
- util.assert(pointwiseFilter.shape[2] === inChannels * channelMultiplier, "Error in separableConv2d: the third dimension of pointwise filter " +
- ("must be " + inChannels * channelMultiplier + ", ") +
- ("but got " + pointwiseFilter.shape[2] + "."));
- var depthwise = ConvOps.depthwiseConv2d(x4D, depthwiseFilter, strides, pad, dataFormat, dilation);
- var pointwiseStride = 1;
- var res = ConvOps.conv2d(depthwise, pointwiseFilter, pointwiseStride, 'valid', dataFormat);
- if (reshapedTo4D) {
- return res.as3D(res.shape[1], res.shape[2], res.shape[3]);
- }
- return res;
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }),
- operation_1.operation
- ], ConvOps, "conv1d", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }),
- operation_1.operation
- ], ConvOps, "conv2d", null);
- __decorate([
- operation_1.operation
- ], ConvOps, "conv2dDerInput", null);
- __decorate([
- operation_1.operation
- ], ConvOps, "conv2dDerFilter", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }),
- operation_1.operation
- ], ConvOps, "conv2dTranspose", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }),
- operation_1.operation
- ], ConvOps, "depthwiseConv2d", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }),
- operation_1.operation
- ], ConvOps, "separableConv2d", null);
- return ConvOps;
- }());
- exports.ConvOps = ConvOps;
- function parseTupleParam(param) {
- return typeof param === 'number' ? [param, param] : param;
- }
- function tupleValuesAreOne(param) {
- var _a = parseTupleParam(param), dimA = _a[0], dimB = _a[1];
- return dimA === 1 && dimB === 1;
- }
- function eitherStridesOrDilationsAreOne(strides, dilations) {
- return tupleValuesAreOne(strides) || tupleValuesAreOne(dilations);
- }
- function depthwiseConv2dDerInput(xShape, dy, filter, convInfo) {
- var dy4D = dy;
- var reshapedTo4D = false;
- if (dy.rank === 3) {
- reshapedTo4D = true;
- dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]);
- }
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.depthwiseConv2DDerInput(dy4D, filter, convInfo); }, { dy4D: dy4D });
- if (reshapedTo4D) {
- return res.as3D(res.shape[1], res.shape[2], res.shape[3]);
- }
- return res;
- }
- function depthwiseConv2dDerFilter(x, dy, filterShape, convInfo) {
- var x4D = x;
- if (x.rank === 3) {
- x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);
- }
- var dy4D = dy;
- if (dy4D.rank === 3) {
- dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]);
- }
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.depthwiseConv2DDerFilter(x4D, dy4D, convInfo); }, { x4D: x4D, dy4D: dy4D });
- }
- },{"../doc":49,"../environment":51,"../util":164,"./conv_util":117,"./operation":128}],117:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var util = require("../util");
- function computePool2DInfo(inShape, filterSize, strides, pad, roundingMode, dataFormat) {
- if (dataFormat === void 0) { dataFormat = 'channelsLast'; }
- var _a = parseTupleParam(filterSize), filterHeight = _a[0], filterWidth = _a[1];
- var filterShape;
- if (dataFormat === 'channelsLast') {
- filterShape = [filterHeight, filterWidth, inShape[3], inShape[3]];
- }
- else if (dataFormat === 'channelsFirst') {
- filterShape = [filterHeight, filterWidth, inShape[1], inShape[1]];
- }
- else {
- throw new Error("Unknown dataFormat " + dataFormat);
- }
- var dilations = 1;
- return computeConv2DInfo(inShape, filterShape, strides, dilations, pad, roundingMode, false, dataFormat);
- }
- exports.computePool2DInfo = computePool2DInfo;
- function computeConv2DInfo(inShape, filterShape, strides, dilations, pad, roundingMode, depthwise, dataFormat) {
- if (depthwise === void 0) { depthwise = false; }
- if (dataFormat === void 0) { dataFormat = 'channelsLast'; }
- var _a = [-1, -1, -1, -1], batchSize = _a[0], inHeight = _a[1], inWidth = _a[2], inChannels = _a[3];
- if (dataFormat === 'channelsLast') {
- batchSize = inShape[0], inHeight = inShape[1], inWidth = inShape[2], inChannels = inShape[3];
- }
- else if (dataFormat === 'channelsFirst') {
- batchSize = inShape[0], inChannels = inShape[1], inHeight = inShape[2], inWidth = inShape[3];
- }
- else {
- throw new Error("Unknown dataFormat " + dataFormat);
- }
- var filterHeight = filterShape[0], filterWidth = filterShape[1], filterChannels = filterShape[3];
- var _b = parseTupleParam(strides), strideHeight = _b[0], strideWidth = _b[1];
- var _c = parseTupleParam(dilations), dilationHeight = _c[0], dilationWidth = _c[1];
- var effectiveFilterHeight = getEffectiveFilterSize(filterHeight, dilationHeight);
- var effectiveFilterWidth = getEffectiveFilterSize(filterWidth, dilationWidth);
- var _d = getPadAndOutInfo(pad, inHeight, inWidth, strideHeight, strideWidth, effectiveFilterHeight, effectiveFilterWidth, roundingMode), padInfo = _d.padInfo, outHeight = _d.outHeight, outWidth = _d.outWidth;
- var outChannels = depthwise ? filterChannels * inChannels : filterChannels;
- var outShape;
- if (dataFormat === 'channelsFirst') {
- outShape = [batchSize, outChannels, outHeight, outWidth];
- }
- else if (dataFormat === 'channelsLast') {
- outShape = [batchSize, outHeight, outWidth, outChannels];
- }
- return {
- batchSize: batchSize,
- dataFormat: dataFormat,
- inHeight: inHeight,
- inWidth: inWidth,
- inChannels: inChannels,
- outHeight: outHeight,
- outWidth: outWidth,
- outChannels: outChannels,
- padInfo: padInfo,
- strideHeight: strideHeight,
- strideWidth: strideWidth,
- filterHeight: filterHeight,
- filterWidth: filterWidth,
- dilationHeight: dilationHeight,
- dilationWidth: dilationWidth,
- inShape: inShape,
- outShape: outShape,
- filterShape: filterShape
- };
- }
- exports.computeConv2DInfo = computeConv2DInfo;
- function computeOutputShape3D(inShape, fieldSize, outDepth, stride, zeroPad, roundingMode) {
- if (zeroPad == null) {
- zeroPad = computeDefaultPad(inShape, fieldSize, stride);
- }
- var inputRows = inShape[0];
- var inputCols = inShape[1];
- var outputRows = conditionalRound((inputRows - fieldSize + 2 * zeroPad) / stride + 1, roundingMode);
- util.assert(util.isInt(outputRows), "The output # of rows (" + outputRows + ") must be an integer. Change the " +
- "stride and/or zero pad parameters");
- var outputCols = conditionalRound((inputCols - fieldSize + 2 * zeroPad) / stride + 1, roundingMode);
- util.assert(util.isInt(outputCols), "The output # of columns (" + outputCols + ") must be an integer. Change " +
- "the stride and/or zero pad parameters");
- return [outputRows, outputCols, outDepth];
- }
- function computeDefaultPad(inputShape, fieldSize, stride, dilation) {
- if (dilation === void 0) { dilation = 1; }
- var effectiveFieldSize = getEffectiveFilterSize(fieldSize, dilation);
- return Math.floor((inputShape[0] * (stride - 1) - stride + effectiveFieldSize) / 2);
- }
- exports.computeDefaultPad = computeDefaultPad;
- function parseTupleParam(param) {
- return typeof param === 'number' ? [param, param] : param;
- }
- function getEffectiveFilterSize(filterSize, dilation) {
- if (dilation <= 1) {
- return filterSize;
- }
- return filterSize + (filterSize - 1) * (dilation - 1);
- }
- function getPadAndOutInfo(pad, inHeight, inWidth, strideHeight, strideWidth, filterHeight, filterWidth, roundingMode) {
- var padInfo;
- var outHeight;
- var outWidth;
- if (typeof pad === 'number') {
- var padType = (pad === 0) ? 'VALID' : 'NUMBER';
- padInfo = { top: pad, bottom: pad, left: pad, right: pad, type: padType };
- var outShape = computeOutputShape3D([inHeight, inWidth, 1], filterHeight, 1, strideHeight, pad, roundingMode);
- outHeight = outShape[0];
- outWidth = outShape[1];
- }
- else if (pad === 'same') {
- outHeight = Math.ceil(inHeight / strideHeight);
- outWidth = Math.ceil(inWidth / strideWidth);
- var padAlongHeight = (outHeight - 1) * strideHeight + filterHeight - inHeight;
- var padAlongWidth = (outWidth - 1) * strideWidth + filterWidth - inWidth;
- var top_1 = Math.floor(padAlongHeight / 2);
- var bottom = padAlongHeight - top_1;
- var left = Math.floor(padAlongWidth / 2);
- var right = padAlongWidth - left;
- padInfo = { top: top_1, bottom: bottom, left: left, right: right, type: 'SAME' };
- }
- else if (pad === 'valid') {
- padInfo = { top: 0, bottom: 0, left: 0, right: 0, type: 'VALID' };
- outHeight = Math.ceil((inHeight - filterHeight + 1) / strideHeight);
- outWidth = Math.ceil((inWidth - filterWidth + 1) / strideWidth);
- }
- else {
- throw Error("Unknown padding parameter: " + pad);
- }
- return { padInfo: padInfo, outHeight: outHeight, outWidth: outWidth };
- }
- function conditionalRound(value, roundingMode) {
- if (!roundingMode) {
- return value;
- }
- switch (roundingMode) {
- case 'round':
- return Math.round(value);
- case 'ceil':
- return Math.ceil(value);
- case 'floor':
- return Math.floor(value);
- default:
- throw new Error("Unknown roundingMode " + roundingMode);
- }
- }
- },{"../util":164}],118:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.ERF_P = 0.3275911;
- exports.ERF_A1 = 0.254829592;
- exports.ERF_A2 = -0.284496736;
- exports.ERF_A3 = 1.421413741;
- exports.ERF_A4 = -1.453152027;
- exports.ERF_A5 = 1.061405429;
- },{}],119:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var util = require("../util");
- var operation_1 = require("./operation");
- var ImageOps = (function () {
- function ImageOps() {
- }
- ImageOps.resizeBilinear = function (images, size, alignCorners) {
- if (alignCorners === void 0) { alignCorners = false; }
- util.assertArgumentsAreTensors({ images: images }, 'resizeBilinear');
- util.assert(images.rank === 3 || images.rank === 4, "Error in resizeBilinear: x must be rank 3 or 4, but got " +
- ("rank " + images.rank + "."));
- util.assert(size.length === 2, "Error in resizeBilinear: new shape must 2D, but got shape " +
- (size + "."));
- var batchImages = images;
- var reshapedTo4D = false;
- if (images.rank === 3) {
- reshapedTo4D = true;
- batchImages =
- images.as4D(1, images.shape[0], images.shape[1], images.shape[2]);
- }
- var newHeight = size[0], newWidth = size[1];
- var forward = function (backend, save) {
- return backend.resizeBilinear(batchImages, newHeight, newWidth, alignCorners);
- };
- var backward = function (dy, saved) {
- return {
- batchImages: function () { return environment_1.ENV.engine.runKernel(function (backend) {
- return backend.resizeBilinearBackprop(dy, batchImages, alignCorners);
- }, {}); }
- };
- };
- var res = environment_1.ENV.engine.runKernel(forward, { batchImages: batchImages }, backward);
- if (reshapedTo4D) {
- return res.as3D(res.shape[1], res.shape[2], res.shape[3]);
- }
- return res;
- };
- ImageOps.resizeNearestNeighbor = function (images, size, alignCorners) {
- if (alignCorners === void 0) { alignCorners = false; }
- util.assertArgumentsAreTensors({ images: images }, 'resizeNearestNeighbor');
- util.assert(images.rank === 3 || images.rank === 4, "Error in resizeNearestNeighbor: x must be rank 3 or 4, but got " +
- ("rank " + images.rank + "."));
- util.assert(size.length === 2, "Error in resizeNearestNeighbor: new shape must 2D, but got shape " +
- (size + "."));
- util.assert(images.dtype === 'float32' || images.dtype === 'int32', '`images` must have `int32` or `float32` as dtype');
- var batchImages = images;
- var reshapedTo4D = false;
- if (images.rank === 3) {
- reshapedTo4D = true;
- batchImages =
- images.as4D(1, images.shape[0], images.shape[1], images.shape[2]);
- }
- var newHeight = size[0], newWidth = size[1];
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.resizeNearestNeighbor(batchImages, newHeight, newWidth, alignCorners); }, { batchImages: batchImages });
- if (reshapedTo4D) {
- return res.as3D(res.shape[1], res.shape[2], res.shape[3]);
- }
- return res;
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Images', namespace: 'image' }),
- operation_1.operation
- ], ImageOps, "resizeBilinear", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Images', namespace: 'image' }),
- operation_1.operation
- ], ImageOps, "resizeNearestNeighbor", null);
- return ImageOps;
- }());
- exports.ImageOps = ImageOps;
- },{"../doc":49,"../environment":51,"../util":164,"./operation":128}],120:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var tracking_1 = require("../tracking");
- var util_1 = require("../util");
- var operation_1 = require("./operation");
- var ops_1 = require("./ops");
- var LinalgOps = (function () {
- function LinalgOps() {
- }
- LinalgOps.gramSchmidt = function (xs) {
- var inputIsTensor2D;
- if (Array.isArray(xs)) {
- inputIsTensor2D = false;
- util_1.assert(xs != null && xs.length > 0, 'Gram-Schmidt process: input must not be null, undefined, or empty');
- var dim = xs[0].shape[0];
- for (var i = 1; i < xs.length; ++i) {
- util_1.assert(xs[i].shape[0] === dim, 'Gram-Schmidt: Non-unique lengths found in the input vectors: ' +
- ("(" + xs[i].shape[0] + " vs. " + dim + ")"));
- }
- }
- else {
- inputIsTensor2D = true;
- xs = ops_1.split(xs, xs.shape[0], 0).map(function (x) { return ops_1.squeeze(x, [0]); });
- }
- util_1.assert(xs.length <= xs[0].shape[0], "Gram-Schmidt: Number of vectors (" + xs.length + ") exceeds " +
- ("number of dimensions (" + xs[0].shape[0] + ")."));
- var ys = [];
- var xs1d = xs;
- var _loop_1 = function (i) {
- ys.push(tracking_1.Tracking.tidy(function () {
- var x = xs1d[i];
- if (i > 0) {
- for (var j = 0; j < i; ++j) {
- var proj = ops_1.sum(ys[j].mulStrict(x)).mul(ys[j]);
- x = x.sub(proj);
- }
- }
- return x.div(ops_1.norm(x, 'euclidean'));
- }));
- };
- for (var i = 0; i < xs.length; ++i) {
- _loop_1(i);
- }
- if (inputIsTensor2D) {
- return ops_1.stack(ys, 0);
- }
- else {
- return ys;
- }
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Linear Algebra' }),
- operation_1.operation
- ], LinalgOps, "gramSchmidt", null);
- return LinalgOps;
- }());
- exports.LinalgOps = LinalgOps;
- },{"../doc":49,"../tracking":161,"../util":164,"./operation":128,"./ops":129}],121:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var types = require("../types");
- var util = require("../util");
- var broadcast_util = require("./broadcast_util");
- var operation_1 = require("./operation");
- var ops_1 = require("../ops/ops");
- var LogicalOps = (function () {
- function LogicalOps() {
- }
- LogicalOps.logicalNot = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'logicalNot');
- util.assert(x.dtype === 'bool', 'Error Array must be of type bool.');
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.logicalNot(x); }, { x: x });
- };
- LogicalOps.logicalAnd = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'logicalAnd');
- util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.');
- broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.logicalAnd(a, b); }, { a: a, b: b });
- };
- LogicalOps.logicalOr = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'logicalOr');
- util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.');
- broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.logicalOr(a, b); }, { a: a, b: b });
- };
- LogicalOps.logicalXor = function (a, b) {
- util.assertArgumentsAreTensors({ a: a, b: b }, 'logicalXor');
- util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.');
- broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);
- return LogicalOps.logicalOr(a, b).logicalAnd(LogicalOps.logicalAnd(a, b).logicalNot());
- };
- LogicalOps.where = function (condition, a, b) {
- util.assertArgumentsAreTensors({ condition: condition, a: a, b: b }, 'where');
- util.assert(condition.dtype === 'bool', 'Error Condition must be of type bool.');
- util.assertShapesMatch(a.shape, b.shape, 'Error in where: ');
- if (condition.rank === 1) {
- util.assert(condition.shape[0] === a.shape[0], 'The first dimension of `a` must match the size of `condition`.');
- }
- else {
- util.assertShapesMatch(condition.shape, b.shape, 'Error in where: ');
- }
- var dtype = types.upcastType(a.dtype, b.dtype);
- var grad = function (dy) { return ({
- condition: function () { return ops_1.zerosLike(condition); },
- a: function () { return dy.mul(condition.cast(a.dtype)); },
- b: function () { return dy.mul(condition.logicalNot().cast(b.dtype)); }
- }); };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.where(condition, a, b, dtype); }, { condition: condition, a: a, b: b }, grad);
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),
- operation_1.operation
- ], LogicalOps, "logicalNot", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),
- operation_1.operation
- ], LogicalOps, "logicalAnd", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),
- operation_1.operation
- ], LogicalOps, "logicalOr", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),
- operation_1.operation
- ], LogicalOps, "logicalXor", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),
- operation_1.operation
- ], LogicalOps, "where", null);
- return LogicalOps;
- }());
- exports.LogicalOps = LogicalOps;
- },{"../doc":49,"../environment":51,"../ops/ops":129,"../types":163,"../util":164,"./broadcast_util":112,"./operation":128}],122:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var util = require("../util");
- var operation_1 = require("./operation");
- var ops = require("./ops");
- var Reduction;
- (function (Reduction) {
- Reduction[Reduction["NONE"] = 0] = "NONE";
- Reduction[Reduction["MEAN"] = 1] = "MEAN";
- Reduction[Reduction["SUM"] = 2] = "SUM";
- Reduction[Reduction["SUM_BY_NONZERO_WEIGHTS"] = 3] = "SUM_BY_NONZERO_WEIGHTS";
- })(Reduction = exports.Reduction || (exports.Reduction = {}));
- var LossOps = (function () {
- function LossOps() {
- }
- LossOps.computeWeightedLoss = function (losses, weights, reduction) {
- if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }
- util.assertArgumentsAreTensors({ losses: losses }, 'computeWeightedLoss');
- if (weights != null) {
- util.assertArgumentsAreTensors({ weights: weights }, 'computeWeightedLoss');
- }
- var weightedLoss = (weights == null) ? losses : losses.mul(weights);
- if (reduction === Reduction.NONE) {
- return weightedLoss;
- }
- if (reduction === Reduction.SUM) {
- return weightedLoss.sum();
- }
- if (reduction === Reduction.MEAN) {
- return (weights == null) ? weightedLoss.mean() :
- weightedLoss.sum().div(weights.sum());
- }
- if (reduction === Reduction.SUM_BY_NONZERO_WEIGHTS) {
- if (weights == null) {
- return weightedLoss.sum().div(ops.scalar(losses.size));
- }
- else {
- var numNonZeros = weights.notEqual(ops.scalar(0)).sum().toFloat();
- return weightedLoss.sum().div(numNonZeros);
- }
- }
- throw Error("Unknown reduction: " + reduction);
- };
- LossOps.absoluteDifference = function (labels, predictions, weights, reduction) {
- if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }
- util.assertArgumentsAreTensors({ labels: labels, predictions: predictions }, 'absoluteDifference');
- if (weights != null) {
- util.assertArgumentsAreTensors({ weights: weights }, 'absoluteDifference');
- }
- util.assertShapesMatch(labels.shape, predictions.shape, 'Error in absoluteDifference: ');
- var losses = labels.sub(predictions).abs();
- return LossOps.computeWeightedLoss(losses, weights, reduction);
- };
- LossOps.meanSquaredError = function (labels, predictions, weights, reduction) {
- if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }
- util.assertArgumentsAreTensors({ labels: labels, predictions: predictions }, 'meanSquaredError');
- if (weights != null) {
- util.assertArgumentsAreTensors({ weights: weights }, 'meanSquaredError');
- }
- util.assertShapesMatch(labels.shape, predictions.shape, 'Error in meanSquaredError: ');
- var losses = labels.squaredDifference(predictions);
- return LossOps.computeWeightedLoss(losses, weights, reduction);
- };
- LossOps.cosineDistance = function (labels, predictions, axis, weights, reduction) {
- if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }
- util.assertArgumentsAreTensors({ labels: labels, predictions: predictions }, 'cosineDistance');
- if (weights != null) {
- util.assertArgumentsAreTensors({ weights: weights }, 'cosineDistance');
- }
- util.assertShapesMatch(labels.shape, predictions.shape, 'Error in cosineDistance: ');
- var one = ops.scalar(1);
- var losses = one.sub(labels.mul(predictions).sum(axis, true));
- return LossOps.computeWeightedLoss(losses, weights, reduction);
- };
- LossOps.hingeLoss = function (labels, predictions, weights, reduction) {
- if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }
- util.assertArgumentsAreTensors({ labels: labels, predictions: predictions }, 'hingeLoss');
- if (weights != null) {
- util.assertArgumentsAreTensors({ weights: weights }, 'hingeLoss');
- }
- util.assertShapesMatch(labels.shape, predictions.shape, 'Error in hingeLoss: ');
- var one = ops.scalar(1);
- labels = ops.scalar(2).mul(labels).sub(one);
- var losses = one.sub(labels.mul(predictions)).relu();
- return LossOps.computeWeightedLoss(losses, weights, reduction);
- };
- LossOps.logLoss = function (labels, predictions, weights, epsilon, reduction) {
- if (epsilon === void 0) { epsilon = 1e-7; }
- if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }
- util.assertArgumentsAreTensors({ labels: labels, predictions: predictions }, 'logLoss');
- if (weights != null) {
- util.assertArgumentsAreTensors({ weights: weights }, 'logLoss');
- }
- util.assertShapesMatch(labels.shape, predictions.shape, 'Error in logLoss: ');
- var one = ops.scalar(1);
- var epsilonScalar = ops.scalar(epsilon);
- var losses = labels.mul(predictions.add(epsilonScalar).log())
- .neg()
- .sub(one.sub(labels).mul(one.sub(predictions).add(epsilonScalar).log()));
- return LossOps.computeWeightedLoss(losses, weights, reduction);
- };
- LossOps.huberLoss = function (labels, predictions, weights, delta, reduction) {
- if (delta === void 0) { delta = 1.0; }
- if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }
- util.assertArgumentsAreTensors({ labels: labels, predictions: predictions }, 'huberLoss');
- if (weights != null) {
- util.assertArgumentsAreTensors({ weights: weights }, 'huberLoss');
- }
- util.assertShapesMatch(labels.shape, predictions.shape, 'Error in huberLoss: ');
- var deltaScalar = ops.scalar(delta);
- var error = predictions.sub(labels).abs();
- var quadratic = ops.minimum(error, deltaScalar);
- var linear = error.sub(quadratic);
- var losses = ops.scalar(0.5).mul(quadratic.square()).add(deltaScalar.mul(linear));
- return LossOps.computeWeightedLoss(losses, weights, reduction);
- };
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),
- operation_1.operation
- ], LossOps, "computeWeightedLoss", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),
- operation_1.operation
- ], LossOps, "absoluteDifference", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),
- operation_1.operation
- ], LossOps, "meanSquaredError", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),
- operation_1.operation
- ], LossOps, "cosineDistance", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),
- operation_1.operation
- ], LossOps, "hingeLoss", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),
- operation_1.operation
- ], LossOps, "logLoss", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),
- operation_1.operation
- ], LossOps, "huberLoss", null);
- return LossOps;
- }());
- exports.LossOps = LossOps;
- },{"../doc":49,"../util":164,"./operation":128,"./ops":129}],123:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var util = require("../util");
- var operation_1 = require("./operation");
- var LRNOps = (function () {
- function LRNOps() {
- }
- LRNOps.localResponseNormalization = function (x, depthRadius, bias, alpha, beta) {
- if (depthRadius === void 0) { depthRadius = 5; }
- if (bias === void 0) { bias = 1; }
- if (alpha === void 0) { alpha = 1; }
- if (beta === void 0) { beta = 0.5; }
- util.assertArgumentsAreTensors({ x: x }, 'localResponseNormalization');
- util.assert(x.rank === 4 || x.rank === 3, "Error in localResponseNormalization: x must be rank 3 or 4 but got\n rank " + x.rank + ".");
- util.assert(util.isInt(depthRadius), "Error in localResponseNormalization: depthRadius must be an integer\n but got depthRadius " + depthRadius + ".");
- var x4D = x;
- var reshapedTo4D = false;
- if (x.rank === 3) {
- reshapedTo4D = true;
- x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);
- }
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.localResponseNormalization4D(x4D, depthRadius, bias, alpha, beta); }, { x4D: x4D });
- if (reshapedTo4D) {
- return res.as3D(res.shape[1], res.shape[2], res.shape[3]);
- }
- else {
- return res;
- }
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }),
- operation_1.operation
- ], LRNOps, "localResponseNormalization", null);
- return LRNOps;
- }());
- exports.LRNOps = LRNOps;
- },{"../doc":49,"../environment":51,"../util":164,"./operation":128}],124:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var util = require("../util");
- var operation_1 = require("./operation");
- var LSTMOps = (function () {
- function LSTMOps() {
- }
- LSTMOps.multiRNNCell = function (lstmCells, data, c, h) {
- util.assertArgumentsAreTensors({ data: data, c: c, h: h }, 'multiRNNCell');
- var input = data;
- var newStates = [];
- for (var i = 0; i < lstmCells.length; i++) {
- var output = lstmCells[i](input, c[i], h[i]);
- newStates.push(output[0]);
- newStates.push(output[1]);
- input = output[1];
- }
- var newC = [];
- var newH = [];
- for (var i = 0; i < newStates.length; i += 2) {
- newC.push(newStates[i]);
- newH.push(newStates[i + 1]);
- }
- return [newC, newH];
- };
- LSTMOps.basicLSTMCell = function (forgetBias, lstmKernel, lstmBias, data, c, h) {
- util.assertArgumentsAreTensors({ forgetBias: forgetBias, lstmKernel: lstmKernel, lstmBias: lstmBias, data: data, c: c, h: h }, 'basicLSTMCell');
- var combined = data.concat(h, 1);
- var weighted = combined.matMul(lstmKernel);
- var res = weighted.add(lstmBias);
- var batchSize = res.shape[0];
- var sliceCols = res.shape[1] / 4;
- var sliceSize = [batchSize, sliceCols];
- var i = res.slice([0, 0], sliceSize);
- var j = res.slice([0, sliceCols], sliceSize);
- var f = res.slice([0, sliceCols * 2], sliceSize);
- var o = res.slice([0, sliceCols * 3], sliceSize);
- var newC = i.sigmoid().mulStrict(j.tanh()).addStrict(c.mulStrict(forgetBias.add(f).sigmoid()));
- var newH = newC.tanh().mulStrict(o.sigmoid());
- return [newC, newH];
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'RNN' }),
- operation_1.operation
- ], LSTMOps, "multiRNNCell", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'RNN' }),
- operation_1.operation
- ], LSTMOps, "basicLSTMCell", null);
- return LSTMOps;
- }());
- exports.LSTMOps = LSTMOps;
- },{"../doc":49,"../util":164,"./operation":128}],125:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var util = require("../util");
- var operation_1 = require("./operation");
- var MatmulOps = (function () {
- function MatmulOps() {
- }
- MatmulOps.matMul = function (a, b, transposeA, transposeB) {
- if (transposeA === void 0) { transposeA = false; }
- if (transposeB === void 0) { transposeB = false; }
- util.assertArgumentsAreTensors({ a: a, b: b }, 'matMul');
- var innerShapeA = transposeA ? a.shape[0] : a.shape[1];
- var innerShapeB = transposeB ? b.shape[1] : b.shape[0];
- util.assert(a.rank === 2 && b.rank === 2, "Error in matMul: inputs must be rank 2, got ranks " + a.rank +
- (" and " + b.rank + "."));
- util.assert(innerShapeA === innerShapeB, "Error in matMul: inner shapes (" + innerShapeA + ") and (" +
- (innerShapeB + ") of Tensors with shapes " + a.shape + " and ") +
- (b.shape + " and transposeA=" + transposeA) +
- (" and transposeB=" + transposeB + " must match."));
- var grad = function (dy) {
- if (!transposeA && !transposeB) {
- return {
- a: function () { return dy.matMul(b.toFloat(), false, true); },
- b: function () { return a.toFloat().matMul(dy, true, false); }
- };
- }
- else if (!transposeA && transposeB) {
- return {
- a: function () { return dy.matMul(b.toFloat(), false, false); },
- b: function () { return dy.matMul(a.toFloat(), true, false); }
- };
- }
- else if (transposeA && !transposeB) {
- return {
- a: function () { return b.toFloat().matMul(dy, false, true); },
- b: function () { return a.toFloat().matMul(dy, false, false); }
- };
- }
- else {
- return {
- a: function () { return b.toFloat().matMul(dy, true, true); },
- b: function () { return dy.matMul(a.toFloat(), true, true); }
- };
- }
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.matMul(a, b, transposeA, transposeB); }, { a: a, b: b }, grad);
- };
- MatmulOps.vectorTimesMatrix = function (v, matrix) {
- util.assert(v.rank === 1, "Error in vectorTimesMatrix: first input must be rank 1, but got " +
- ("rank " + v.rank + "."));
- util.assert(matrix.rank === 2, "Error in vectorTimesMatrix: second input must be rank 2, but got " +
- ("rank " + matrix.rank + "."));
- util.assert(v.size === matrix.shape[0], "Error in vectorTimesMatrix: size of vector (" + v.size + ") " +
- ("must match first dimension of matrix (" + matrix.shape[0] + ")"));
- return v.as2D(1, -1).matMul(matrix).as1D();
- };
- MatmulOps.matrixTimesVector = function (matrix, v) {
- util.assert(v.rank === 1, "Error in matrixTimesVector: second input must rank 1, but got " +
- ("rank " + v.rank + "."));
- util.assert(matrix.rank === 2, "Error in matrixTimesVector: first input must be a rank 2, but got " +
- ("rank " + matrix.rank + "."));
- util.assert(v.size === matrix.shape[1], "Error in matrixTimesVector: size of first rank 1 input " + v.size + " " +
- "must match inner dimension of second rank 2 input, but got " +
- ("shape " + matrix.shape + "."));
- return matrix.matMul(v.as2D(-1, 1)).as1D();
- };
- MatmulOps.dotProduct = function (v1, v2) {
- util.assert(v1.rank === 1 && v2.rank === 1, "Error in dotProduct: inputs must be rank 1, but got ranks " +
- (v1.rank + " and " + v2.rank + "."));
- util.assert(v1.size === v2.size, "Error in dotProduct: size of inputs (" + v1.size + ") and (" +
- (v2.size + ") must match."));
- return v1.as2D(1, -1).matMul(v2.as2D(-1, 1)).asScalar();
- };
- MatmulOps.outerProduct = function (v1, v2) {
- util.assert(v1.rank === 1 && v2.rank === 1, "Error in outerProduct: inputs must be rank 1, but got ranks " +
- (v1.rank + " and " + v2.rank + "."));
- return v1.as2D(-1, 1).matMul(v2.as2D(1, -1));
- };
- MatmulOps.dot = function (t1, t2) {
- util.assert((t1.rank === 1 || t1.rank === 2) && (t2.rank === 1 || t2.rank === 2), "Error in dot: inputs must all be rank 1 or 2, but got ranks " +
- (t1.rank + " and " + t2.rank + "."));
- var t1Inner = (t1.rank === 1 ? t1.size : t1.shape[1]);
- var t2Inner = (t2.rank === 1 ? t2.size : t2.shape[0]);
- util.assert(t1Inner === t2Inner, "Error in dot: inner dimensions of inputs must match, but got " +
- (t1Inner + " and " + t2Inner + "."));
- if (t1.rank === 1 && t2.rank === 1) {
- return t1.as2D(1, -1).matMul(t2.as2D(-1, 1)).asScalar();
- }
- else if (t1.rank === 1 && t2.rank === 2) {
- return t1.as2D(1, -1).matMul(t2.as2D(t2.shape[0], t2.shape[1])).as1D();
- }
- else if (t1.rank === 2 && t2.rank === 1) {
- return t1.matMul(t2.as2D(-1, 1)).as1D();
- }
- else {
- return t1.matMul(t2.as2D(t2.shape[0], t2.shape[1]));
- }
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }),
- operation_1.operation
- ], MatmulOps, "matMul", null);
- __decorate([
- operation_1.operation
- ], MatmulOps, "vectorTimesMatrix", null);
- __decorate([
- operation_1.operation
- ], MatmulOps, "matrixTimesVector", null);
- __decorate([
- operation_1.operation
- ], MatmulOps, "dotProduct", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }),
- operation_1.operation
- ], MatmulOps, "outerProduct", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }),
- operation_1.operation
- ], MatmulOps, "dot", null);
- return MatmulOps;
- }());
- exports.MatmulOps = MatmulOps;
- },{"../doc":49,"../environment":51,"../util":164,"./operation":128}],126:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var util = require("../util");
- var array_ops_1 = require("./array_ops");
- var binary_ops_1 = require("./binary_ops");
- var operation_1 = require("./operation");
- var MovingAverageOps = (function () {
- function MovingAverageOps() {
- }
- MovingAverageOps.movingAverage = function (v, x, decay, step, zeroDebias) {
- if (zeroDebias === void 0) { zeroDebias = true; }
- util.assertArgumentsAreTensors({ v: v, x: x }, 'movingAverage');
- util.assertTypesMatch(v, x);
- util.assert(util.arraysEqual(v.shape, x.shape), 'Shape mismatch in v and x');
- var one = array_ops_1.ArrayOps.scalar(1);
- decay = typeof decay === 'number' ? array_ops_1.ArrayOps.scalar(decay) : decay;
- var oneMinusDecay = one.sub(decay);
- var update = x.sub(v).mul(oneMinusDecay);
- if (zeroDebias) {
- util.assert(step != null, 'When using zeroDebias: true, step is required.');
- step = typeof step === 'number' ? array_ops_1.ArrayOps.scalar(step) : step;
- update = update.div(one.sub(binary_ops_1.BinaryOps.pow(decay, step)));
- }
- return v.add(update);
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Moving Average' }),
- operation_1.operation
- ], MovingAverageOps, "movingAverage", null);
- return MovingAverageOps;
- }());
- exports.MovingAverageOps = MovingAverageOps;
- },{"../doc":49,"../util":164,"./array_ops":108,"./binary_ops":111,"./operation":128}],127:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var util = require("../util");
- var axis_util = require("./axis_util");
- var operation_1 = require("./operation");
- var ops = require("./ops");
- var NormOps = (function () {
- function NormOps() {
- }
- NormOps.norm = function (x, ord, axis, keepDims) {
- if (ord === void 0) { ord = 'euclidean'; }
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- util.assertArgumentsAreTensors({ x: x }, 'norm');
- var norm = normImpl(x, ord, axis);
- var keepDimsShape = norm.shape;
- if (keepDims) {
- var axes = axis_util.parseAxisParam(axis, x.shape);
- keepDimsShape = axis_util.expandShapeToKeepDim(norm.shape, axes);
- }
- return norm.reshape(keepDimsShape);
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }),
- operation_1.operation
- ], NormOps, "norm", null);
- return NormOps;
- }());
- exports.NormOps = NormOps;
- function normImpl(x, p, axis) {
- if (axis === void 0) { axis = null; }
- if (x.rank === 0) {
- return x.abs();
- }
- if (x.rank !== 1 && axis === null) {
- return normImpl(x.reshape([-1]), p, axis);
- }
- if (x.rank === 1 || typeof axis === 'number' ||
- axis instanceof Array && axis.length === 1) {
- if (p === 1) {
- return x.abs().sum(axis);
- }
- if (p === Infinity) {
- return x.abs().max(axis);
- }
- if (p === -Infinity) {
- return x.abs().min(axis);
- }
- if (p === 'euclidean' || p === 2) {
- return x.abs().pow(ops.scalar(2, 'int32')).sum(axis).sqrt();
- }
- throw new Error("Error in norm: invalid ord value: " + p);
- }
- if (axis instanceof Array && axis.length === 2) {
- if (p === 1) {
- return x.abs().sum(axis[0]).max(axis[1] - 1);
- }
- if (p === Infinity) {
- return x.abs().sum(axis[1]).max(axis[0]);
- }
- if (p === -Infinity) {
- return x.abs().sum(axis[1]).min(axis[0]);
- }
- if (p === 'fro' || p === 'euclidean') {
- return x.square().sum(axis).sqrt();
- }
- throw new Error("Error in norm: invalid ord value: " + p);
- }
- throw new Error("Error in norm: invalid axis: " + axis);
- }
- },{"../doc":49,"../util":164,"./axis_util":109,"./operation":128,"./ops":129}],128:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var globals_1 = require("../globals");
- function operation(target, name, descriptor) {
- var fn = descriptor.value;
- descriptor.value = function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- return globals_1.tidy(name, function () { return fn.apply(void 0, args); });
- };
- return descriptor;
- }
- exports.operation = operation;
- },{"../globals":52}],129:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var array_ops_1 = require("./array_ops");
- var batchnorm_1 = require("./batchnorm");
- var binary_ops_1 = require("./binary_ops");
- var compare_1 = require("./compare");
- var concat_1 = require("./concat");
- var conv_1 = require("./conv");
- var image_ops_1 = require("./image_ops");
- var linalg_ops_1 = require("./linalg_ops");
- var logical_ops_1 = require("./logical_ops");
- var loss_ops_1 = require("./loss_ops");
- var lrn_1 = require("./lrn");
- var lstm_1 = require("./lstm");
- var matmul_1 = require("./matmul");
- var moving_average_1 = require("./moving_average");
- var norm_1 = require("./norm");
- var pool_1 = require("./pool");
- var reduction_ops_1 = require("./reduction_ops");
- var reverse_1 = require("./reverse");
- var segment_ops_1 = require("./segment_ops");
- var sigmoid_cross_entropy_1 = require("./sigmoid_cross_entropy");
- var slice_1 = require("./slice");
- var softmax_1 = require("./softmax");
- var strided_slice_1 = require("./strided_slice");
- var transpose_1 = require("./transpose");
- var unary_ops_1 = require("./unary_ops");
- exports.batchNormalization = batchnorm_1.BatchNormOps.batchNormalization;
- exports.batchNormalization2d = batchnorm_1.BatchNormOps.batchNormalization2d;
- exports.batchNormalization3d = batchnorm_1.BatchNormOps.batchNormalization3d;
- exports.batchNormalization4d = batchnorm_1.BatchNormOps.batchNormalization4d;
- exports.concat = concat_1.ConcatOps.concat;
- exports.concat1d = concat_1.ConcatOps.concat1d;
- exports.concat2d = concat_1.ConcatOps.concat2d;
- exports.concat3d = concat_1.ConcatOps.concat3d;
- exports.concat4d = concat_1.ConcatOps.concat4d;
- exports.conv1d = conv_1.ConvOps.conv1d;
- exports.conv2d = conv_1.ConvOps.conv2d;
- exports.conv2dTranspose = conv_1.ConvOps.conv2dTranspose;
- exports.depthwiseConv2d = conv_1.ConvOps.depthwiseConv2d;
- exports.separableConv2d = conv_1.ConvOps.separableConv2d;
- exports.matMul = matmul_1.MatmulOps.matMul;
- exports.matrixTimesVector = matmul_1.MatmulOps.matrixTimesVector;
- exports.outerProduct = matmul_1.MatmulOps.outerProduct;
- exports.vectorTimesMatrix = matmul_1.MatmulOps.vectorTimesMatrix;
- exports.dot = matmul_1.MatmulOps.dot;
- exports.avgPool = pool_1.PoolOps.avgPool;
- exports.maxPool = pool_1.PoolOps.maxPool;
- exports.transpose = transpose_1.TransposeOps.transpose;
- exports.reverse = reverse_1.ReverseOps.reverse;
- exports.reverse1d = reverse_1.ReverseOps.reverse1d;
- exports.reverse2d = reverse_1.ReverseOps.reverse2d;
- exports.reverse3d = reverse_1.ReverseOps.reverse3d;
- exports.reverse4d = reverse_1.ReverseOps.reverse4d;
- exports.slice = slice_1.SliceOps.slice;
- exports.slice1d = slice_1.SliceOps.slice1d;
- exports.slice2d = slice_1.SliceOps.slice2d;
- exports.slice3d = slice_1.SliceOps.slice3d;
- exports.slice4d = slice_1.SliceOps.slice4d;
- exports.stridedSlice = strided_slice_1.StridedSliceOps.stridedSlice;
- exports.argMax = reduction_ops_1.ReductionOps.argMax;
- exports.argMin = reduction_ops_1.ReductionOps.argMin;
- exports.logSumExp = reduction_ops_1.ReductionOps.logSumExp;
- exports.max = reduction_ops_1.ReductionOps.max;
- exports.mean = reduction_ops_1.ReductionOps.mean;
- exports.min = reduction_ops_1.ReductionOps.min;
- exports.all = reduction_ops_1.ReductionOps.all;
- exports.moments = reduction_ops_1.ReductionOps.moments;
- exports.sum = reduction_ops_1.ReductionOps.sum;
- exports.unsortedSegmentSum = segment_ops_1.SegmentOps.unsortedSegmentSum;
- exports.equal = compare_1.CompareOps.equal;
- exports.equalStrict = compare_1.CompareOps.equalStrict;
- exports.greater = compare_1.CompareOps.greater;
- exports.greaterStrict = compare_1.CompareOps.greaterStrict;
- exports.greaterEqual = compare_1.CompareOps.greaterEqual;
- exports.greaterEqualStrict = compare_1.CompareOps.greaterEqualStrict;
- exports.less = compare_1.CompareOps.less;
- exports.lessStrict = compare_1.CompareOps.lessStrict;
- exports.lessEqual = compare_1.CompareOps.lessEqual;
- exports.lessEqualStrict = compare_1.CompareOps.lessEqualStrict;
- exports.notEqual = compare_1.CompareOps.notEqual;
- exports.notEqualStrict = compare_1.CompareOps.notEqualStrict;
- exports.logicalNot = logical_ops_1.LogicalOps.logicalNot;
- exports.logicalAnd = logical_ops_1.LogicalOps.logicalAnd;
- exports.logicalOr = logical_ops_1.LogicalOps.logicalOr;
- exports.logicalXor = logical_ops_1.LogicalOps.logicalXor;
- exports.where = logical_ops_1.LogicalOps.where;
- exports.abs = unary_ops_1.UnaryOps.abs;
- exports.acos = unary_ops_1.UnaryOps.acos;
- exports.acosh = unary_ops_1.UnaryOps.acosh;
- exports.asin = unary_ops_1.UnaryOps.asin;
- exports.asinh = unary_ops_1.UnaryOps.asinh;
- exports.atan = unary_ops_1.UnaryOps.atan;
- exports.atanh = unary_ops_1.UnaryOps.atanh;
- exports.ceil = unary_ops_1.UnaryOps.ceil;
- exports.clipByValue = unary_ops_1.UnaryOps.clipByValue;
- exports.cos = unary_ops_1.UnaryOps.cos;
- exports.cosh = unary_ops_1.UnaryOps.cosh;
- exports.elu = unary_ops_1.UnaryOps.elu;
- exports.exp = unary_ops_1.UnaryOps.exp;
- exports.expm1 = unary_ops_1.UnaryOps.expm1;
- exports.floor = unary_ops_1.UnaryOps.floor;
- exports.sign = unary_ops_1.UnaryOps.sign;
- exports.leakyRelu = unary_ops_1.UnaryOps.leakyRelu;
- exports.log = unary_ops_1.UnaryOps.log;
- exports.log1p = unary_ops_1.UnaryOps.log1p;
- exports.logSigmoid = unary_ops_1.UnaryOps.logSigmoid;
- exports.neg = unary_ops_1.UnaryOps.neg;
- exports.prelu = unary_ops_1.UnaryOps.prelu;
- exports.relu = unary_ops_1.UnaryOps.relu;
- exports.reciprocal = unary_ops_1.UnaryOps.reciprocal;
- exports.round = unary_ops_1.UnaryOps.round;
- exports.selu = unary_ops_1.UnaryOps.selu;
- exports.sigmoid = unary_ops_1.UnaryOps.sigmoid;
- exports.sin = unary_ops_1.UnaryOps.sin;
- exports.sinh = unary_ops_1.UnaryOps.sinh;
- exports.softplus = unary_ops_1.UnaryOps.softplus;
- exports.sqrt = unary_ops_1.UnaryOps.sqrt;
- exports.rsqrt = unary_ops_1.UnaryOps.rsqrt;
- exports.square = unary_ops_1.UnaryOps.square;
- exports.step = unary_ops_1.UnaryOps.step;
- exports.tan = unary_ops_1.UnaryOps.tan;
- exports.tanh = unary_ops_1.UnaryOps.tanh;
- exports.erf = unary_ops_1.UnaryOps.erf;
- exports.add = binary_ops_1.BinaryOps.add;
- exports.addStrict = binary_ops_1.BinaryOps.addStrict;
- exports.atan2 = binary_ops_1.BinaryOps.atan2;
- exports.div = binary_ops_1.BinaryOps.div;
- exports.floorDiv = binary_ops_1.BinaryOps.floorDiv;
- exports.divStrict = binary_ops_1.BinaryOps.divStrict;
- exports.maximum = binary_ops_1.BinaryOps.maximum;
- exports.maximumStrict = binary_ops_1.BinaryOps.maximumStrict;
- exports.minimum = binary_ops_1.BinaryOps.minimum;
- exports.minimumStrict = binary_ops_1.BinaryOps.minimumStrict;
- exports.mod = binary_ops_1.BinaryOps.mod;
- exports.modStrict = binary_ops_1.BinaryOps.modStrict;
- exports.mul = binary_ops_1.BinaryOps.mul;
- exports.mulStrict = binary_ops_1.BinaryOps.mulStrict;
- exports.pow = binary_ops_1.BinaryOps.pow;
- exports.powStrict = binary_ops_1.BinaryOps.powStrict;
- exports.sub = binary_ops_1.BinaryOps.sub;
- exports.subStrict = binary_ops_1.BinaryOps.subStrict;
- exports.squaredDifference = binary_ops_1.BinaryOps.squaredDifference;
- exports.squaredDifferenceStrict = binary_ops_1.BinaryOps.squaredDifferenceStrict;
- exports.norm = norm_1.NormOps.norm;
- exports.cast = array_ops_1.ArrayOps.cast;
- exports.clone = array_ops_1.ArrayOps.clone;
- exports.fromPixels = array_ops_1.ArrayOps.fromPixels;
- exports.toPixels = array_ops_1.ArrayOps.toPixels;
- exports.ones = array_ops_1.ArrayOps.ones;
- exports.onesLike = array_ops_1.ArrayOps.onesLike;
- exports.zeros = array_ops_1.ArrayOps.zeros;
- exports.zerosLike = array_ops_1.ArrayOps.zerosLike;
- exports.eye = array_ops_1.ArrayOps.eye;
- exports.rand = array_ops_1.ArrayOps.rand;
- exports.randomNormal = array_ops_1.ArrayOps.randomNormal;
- exports.truncatedNormal = array_ops_1.ArrayOps.truncatedNormal;
- exports.randomUniform = array_ops_1.ArrayOps.randomUniform;
- exports.multinomial = array_ops_1.ArrayOps.multinomial;
- exports.reshape = array_ops_1.ArrayOps.reshape;
- exports.squeeze = array_ops_1.ArrayOps.squeeze;
- exports.tile = array_ops_1.ArrayOps.tile;
- exports.gather = array_ops_1.ArrayOps.gather;
- exports.oneHot = array_ops_1.ArrayOps.oneHot;
- exports.linspace = array_ops_1.ArrayOps.linspace;
- exports.range = array_ops_1.ArrayOps.range;
- exports.buffer = array_ops_1.ArrayOps.buffer;
- exports.fill = array_ops_1.ArrayOps.fill;
- exports.tensor = array_ops_1.ArrayOps.tensor;
- exports.scalar = array_ops_1.ArrayOps.scalar;
- exports.tensor1d = array_ops_1.ArrayOps.tensor1d;
- exports.tensor2d = array_ops_1.ArrayOps.tensor2d;
- exports.tensor3d = array_ops_1.ArrayOps.tensor3d;
- exports.tensor4d = array_ops_1.ArrayOps.tensor4d;
- exports.tensor5d = array_ops_1.ArrayOps.tensor5d;
- exports.tensor6d = array_ops_1.ArrayOps.tensor6d;
- exports.print = array_ops_1.ArrayOps.print;
- exports.expandDims = array_ops_1.ArrayOps.expandDims;
- exports.stack = array_ops_1.ArrayOps.stack;
- exports.unstack = array_ops_1.ArrayOps.unstack;
- exports.split = array_ops_1.ArrayOps.split;
- exports.cumsum = array_ops_1.ArrayOps.cumsum;
- exports.pad = array_ops_1.ArrayOps.pad;
- exports.pad1d = array_ops_1.ArrayOps.pad1d;
- exports.pad2d = array_ops_1.ArrayOps.pad2d;
- exports.pad3d = array_ops_1.ArrayOps.pad3d;
- exports.pad4d = array_ops_1.ArrayOps.pad4d;
- exports.movingAverage = moving_average_1.MovingAverageOps.movingAverage;
- exports.basicLSTMCell = lstm_1.LSTMOps.basicLSTMCell;
- exports.multiRNNCell = lstm_1.LSTMOps.multiRNNCell;
- exports.softmax = softmax_1.SoftmaxOps.softmax;
- exports.sigmoidCrossEntropyWithLogits = sigmoid_cross_entropy_1.SigmoidCrossEntropyOps.sigmoidCrossEntropyWithLogits;
- exports.localResponseNormalization = lrn_1.LRNOps.localResponseNormalization;
- exports.linalg = linalg_ops_1.LinalgOps;
- var operation_1 = require("./operation");
- exports.operation = operation_1.operation;
- var tensor_1 = require("../tensor");
- var types_1 = require("../types");
- [tensor_1.Tensor, types_1.Rank];
- [loss_ops_1.Reduction];
- exports.losses = {
- absoluteDifference: loss_ops_1.LossOps.absoluteDifference,
- computeWeightedLoss: loss_ops_1.LossOps.computeWeightedLoss,
- cosineDistance: loss_ops_1.LossOps.cosineDistance,
- hingeLoss: loss_ops_1.LossOps.hingeLoss,
- huberLoss: loss_ops_1.LossOps.huberLoss,
- logLoss: loss_ops_1.LossOps.logLoss,
- meanSquaredError: loss_ops_1.LossOps.meanSquaredError,
- softmaxCrossEntropy: softmax_1.SoftmaxOps.softmaxCrossEntropy
- };
- exports.image = {
- resizeBilinear: image_ops_1.ImageOps.resizeBilinear,
- resizeNearestNeighbor: image_ops_1.ImageOps.resizeNearestNeighbor,
- };
- },{"../tensor":158,"../types":163,"./array_ops":108,"./batchnorm":110,"./binary_ops":111,"./compare":113,"./concat":114,"./conv":116,"./image_ops":119,"./linalg_ops":120,"./logical_ops":121,"./loss_ops":122,"./lrn":123,"./lstm":124,"./matmul":125,"./moving_average":126,"./norm":127,"./operation":128,"./pool":130,"./reduction_ops":133,"./reverse":134,"./segment_ops":135,"./sigmoid_cross_entropy":138,"./slice":139,"./softmax":141,"./strided_slice":142,"./transpose":143,"./unary_ops":144}],130:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var util = require("../util");
- var conv_util = require("./conv_util");
- var operation_1 = require("./operation");
- var PoolOps = (function () {
- function PoolOps() {
- }
- PoolOps.maxPool = function (x, filterSize, strides, pad, dimRoundingMode) {
- util.assertArgumentsAreTensors({ x: x }, 'maxPool');
- var x4D = x;
- var reshapedTo4D = false;
- if (x.rank === 3) {
- reshapedTo4D = true;
- x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);
- }
- util.assert(x4D.rank === 4, "Error in maxPool: input must be rank 4 but got rank " + x4D.rank + ".");
- if (dimRoundingMode != null) {
- util.assert(util.isInt(pad), "Error in maxPool: pad must be an integer when using, " +
- ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + "."));
- }
- var convInfo = conv_util.computePool2DInfo(x4D.shape, filterSize, strides, pad, dimRoundingMode);
- var grad = function (dy, saved) {
- var y4D = saved[0];
- return {
- x: function () { return PoolOps.maxPoolBackprop(dy, x4D, y4D, filterSize, strides, pad); }
- };
- };
- var res = environment_1.ENV.engine.runKernel(function (backend, save) { return save(backend.maxPool(x4D, convInfo)); }, { x: x4D }, grad);
- if (reshapedTo4D) {
- return res.as3D(res.shape[1], res.shape[2], res.shape[3]);
- }
- return res;
- };
- PoolOps.maxPoolBackprop = function (dy, input, output, filterSize, strides, pad, dimRoundingMode) {
- util.assertArgumentsAreTensors({ dy: dy, input: input, output: output }, 'maxPoolBackprop');
- util.assert(input.rank === dy.rank, "Rank of input (" + input.rank + ") does not match rank of dy (" + dy.rank + ")");
- util.assert(dy.rank === 4, "Error in maxPoolBackprop: dy must be rank 4 but got rank " +
- (dy.rank + "."));
- util.assert(input.rank === 4, "Error in maxPoolBackprop: input must be rank 4 but got rank " +
- (input.rank + "."));
- if (dimRoundingMode != null) {
- util.assert(util.isInt(pad), "Error in maxPoolBackprop: pad must be an integer when using, " +
- ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + "."));
- }
- var convInfo = conv_util.computePool2DInfo(input.shape, filterSize, strides, pad, dimRoundingMode);
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.maxPoolBackprop(dy, input, output, convInfo); }, { dy: dy, input: input });
- return res;
- };
- PoolOps.avgPool = function (x, filterSize, strides, pad, dimRoundingMode) {
- util.assertArgumentsAreTensors({ x: x }, 'avgPool');
- util.assert(x.dtype === 'float32', 'The input dtype to avgPool must be float32');
- var x4D = x;
- var reshapedTo4D = false;
- if (x.rank === 3) {
- reshapedTo4D = true;
- x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);
- }
- util.assert(x4D.rank === 4, "Error in avgPool: x must be rank 4 but got rank " + x4D.rank + ".");
- if (dimRoundingMode != null) {
- util.assert(util.isInt(pad), "Error in avgPool: pad must be an integer when using, " +
- ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + "."));
- }
- var convInfo = conv_util.computePool2DInfo(x4D.shape, filterSize, strides, pad);
- var grad = function (dy) {
- return {
- x: function () { return PoolOps.avgPoolBackprop(dy, x4D, filterSize, strides, pad); }
- };
- };
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.avgPool(x4D, convInfo); }, { x: x4D }, grad);
- res = res.cast(x.dtype);
- if (reshapedTo4D) {
- return res.as3D(res.shape[1], res.shape[2], res.shape[3]);
- }
- return res;
- };
- PoolOps.avgPoolBackprop = function (dy, input, filterSize, strides, pad) {
- util.assertArgumentsAreTensors({ dy: dy, input: input }, 'avgPoolBackprop');
- util.assert(input.rank === dy.rank, "Rank of input (" + input.rank + ") does not match rank of dy (" + dy.rank + ")");
- var input4D = input;
- var dy4D = dy;
- var reshapedTo4D = false;
- if (input.rank === 3) {
- reshapedTo4D = true;
- input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]);
- dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]);
- }
- util.assert(dy4D.rank === 4, "Error in avgPoolBackprop: dy must be rank 4 but got rank " +
- (dy4D.rank + "."));
- util.assert(input4D.rank === 4, "Error in avgPoolBackprop: input must be rank 4 but got rank " +
- (input4D.rank + "."));
- var convInfo = conv_util.computePool2DInfo(input4D.shape, filterSize, strides, pad);
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.avgPoolBackprop(dy4D, input4D, convInfo); }, { dy4D: dy4D, input4D: input4D });
- if (reshapedTo4D) {
- return res.as3D(res.shape[1], res.shape[2], res.shape[3]);
- }
- return res;
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }),
- operation_1.operation
- ], PoolOps, "maxPool", null);
- __decorate([
- operation_1.operation
- ], PoolOps, "maxPoolBackprop", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }),
- operation_1.operation
- ], PoolOps, "avgPool", null);
- __decorate([
- operation_1.operation
- ], PoolOps, "avgPoolBackprop", null);
- return PoolOps;
- }());
- exports.PoolOps = PoolOps;
- },{"../doc":49,"../environment":51,"../util":164,"./conv_util":117,"./operation":128}],131:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var seedrandom = require("seedrandom");
- var MPRandGauss = (function () {
- function MPRandGauss(mean, stdDeviation, dtype, truncated, seed) {
- this.mean = mean;
- this.stdDev = stdDeviation;
- this.dtype = dtype;
- this.nextVal = NaN;
- this.truncated = truncated;
- if (this.truncated) {
- this.upper = this.mean + this.stdDev * 2;
- this.lower = this.mean - this.stdDev * 2;
- }
- var seedValue = seed ? seed : Math.random();
- this.random = seedrandom.alea(seedValue.toString());
- }
- MPRandGauss.prototype.nextValue = function () {
- if (!isNaN(this.nextVal)) {
- var value = this.nextVal;
- this.nextVal = NaN;
- return value;
- }
- var resultX, resultY;
- var isValid = false;
- while (!isValid) {
- var v1 = void 0, v2 = void 0, s = void 0;
- do {
- v1 = 2 * this.random() - 1;
- v2 = 2 * this.random() - 1;
- s = v1 * v1 + v2 * v2;
- } while (s >= 1 || s === 0);
- var mul = Math.sqrt(-2.0 * Math.log(s) / s);
- resultX = this.mean + this.stdDev * v1 * mul;
- resultY = this.mean + this.stdDev * v2 * mul;
- if (!this.truncated || this.isValidTruncated(resultX)) {
- isValid = true;
- }
- }
- if (!this.truncated || this.isValidTruncated(resultY)) {
- this.nextVal = this.convertValue(resultY);
- }
- return this.convertValue(resultX);
- };
- MPRandGauss.prototype.convertValue = function (value) {
- if (this.dtype == null || this.dtype === 'float32') {
- return value;
- }
- return Math.round(value);
- };
- MPRandGauss.prototype.isValidTruncated = function (value) {
- return value <= this.upper && value >= this.lower;
- };
- return MPRandGauss;
- }());
- exports.MPRandGauss = MPRandGauss;
- },{"seedrandom":231}],132:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var util_1 = require("../util");
- exports.PARALLELIZE_THRESHOLD = 30;
- function computeOptimalWindowSize(inSize) {
- if (inSize <= exports.PARALLELIZE_THRESHOLD) {
- return inSize;
- }
- return util_1.nearestDivisor(inSize, Math.floor(Math.sqrt(inSize)));
- }
- exports.computeOptimalWindowSize = computeOptimalWindowSize;
- },{"../util":164}],133:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var globals_1 = require("../globals");
- var util = require("../util");
- var axis_util = require("./axis_util");
- var operation_1 = require("./operation");
- var ops = require("./ops");
- var ReductionOps = (function () {
- function ReductionOps() {
- }
- ReductionOps.logSumExp = function (x, axis, keepDims) {
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- util.assertArgumentsAreTensors({ x: x }, 'logSumExp');
- var axes = axis_util.parseAxisParam(axis, x.shape);
- var xMax = x.max(axes, true);
- var a = x.sub(xMax);
- var b = a.exp();
- var c = b.sum(axes);
- var d = c.log();
- var res = xMax.reshape(d.shape).add(d);
- if (keepDims) {
- var newShape = axis_util.expandShapeToKeepDim(res.shape, axes);
- return res.reshape(newShape);
- }
- return res;
- };
- ReductionOps.sum = function (x, axis, keepDims) {
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- util.assertArgumentsAreTensors({ x: x }, 'sum');
- if (x.dtype === 'bool') {
- x = x.toInt();
- }
- var axes = axis_util.parseAxisParam(axis, x.shape);
- var customOp = globals_1.customGrad(function (x) {
- var permutation = axis_util.getAxesPermutation(axes, x.rank);
- var reductionAxes = axes;
- var permutedX = x;
- if (permutation != null) {
- permutedX = x.transpose(permutation);
- reductionAxes =
- axis_util.getInnerMostAxes(reductionAxes.length, x.rank);
- }
- var value = environment_1.ENV.engine.runKernel(function (backend) { return backend.sum(permutedX, reductionAxes); }, { permutedX: permutedX });
- if (keepDims) {
- var newShape = axis_util.expandShapeToKeepDim(value.shape, axes);
- value = value.reshape(newShape);
- }
- var gradFunc = function (dy) {
- var expandedDyShape = x.shape.slice();
- axes.forEach(function (axis) {
- expandedDyShape[axis] = 1;
- });
- var expandedDy = dy.reshape(expandedDyShape);
- var derX = expandedDy.mul(ops.ones(x.shape, 'float32'));
- return derX;
- };
- return { value: value, gradFunc: gradFunc };
- });
- return customOp(x);
- };
- ReductionOps.mean = function (x, axis, keepDims) {
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- util.assertArgumentsAreTensors({ x: x }, 'mean');
- var axes = axis_util.parseAxisParam(axis, x.shape);
- var shapes = axis_util.computeOutAndReduceShapes(x.shape, axes);
- var reduceShape = shapes[1];
- var reduceSize = util.sizeFromShape(reduceShape);
- var customOp = globals_1.customGrad(function (x) {
- var reduceSizeScalar = ops.scalar(reduceSize);
- var xReduce = reduceSizeScalar.dtype === x.dtype ?
- x :
- x.cast(reduceSizeScalar.dtype);
- var res = xReduce.div(reduceSizeScalar);
- var value = res.sum(axis, keepDims);
- var gradFunc = function (dy) {
- var expandedDyShape = x.shape.slice();
- axes.forEach(function (axis) {
- expandedDyShape[axis] = 1;
- });
- var expandedDy = dy.reshape(expandedDyShape);
- var derX = expandedDy.mul(ops.ones(x.shape, 'float32')).div(reduceSizeScalar);
- return derX;
- };
- return { value: value, gradFunc: gradFunc };
- });
- return customOp(x);
- };
- ReductionOps.min = function (x, axis, keepDims) {
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- util.assertArgumentsAreTensors({ x: x }, 'min');
- var origAxes = axis_util.parseAxisParam(axis, x.shape);
- var axes = origAxes;
- var permutedAxes = axis_util.getAxesPermutation(axes, x.rank);
- if (permutedAxes != null) {
- x = x.transpose(permutedAxes);
- axes = axis_util.getInnerMostAxes(axes.length, x.rank);
- }
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.min(x, axes); }, { x: x });
- if (keepDims) {
- var newShape = axis_util.expandShapeToKeepDim(res.shape, origAxes);
- return res.reshape(newShape);
- }
- return res;
- };
- ReductionOps.max = function (x, axis, keepDims) {
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- util.assertArgumentsAreTensors({ x: x }, 'max');
- var origAxes = axis_util.parseAxisParam(axis, x.shape);
- var axes = origAxes;
- var permutedAxes = axis_util.getAxesPermutation(axes, x.rank);
- if (permutedAxes != null) {
- x = x.transpose(permutedAxes);
- axes = axis_util.getInnerMostAxes(axes.length, x.rank);
- }
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.max(x, axes); }, { x: x });
- if (keepDims) {
- var newShape = axis_util.expandShapeToKeepDim(res.shape, origAxes);
- return res.reshape(newShape);
- }
- return res;
- };
- ReductionOps.argMin = function (x, axis) {
- if (axis === void 0) { axis = 0; }
- util.assertArgumentsAreTensors({ x: x }, 'argMin');
- if (axis == null) {
- axis = 0;
- }
- var axes = axis_util.parseAxisParam(axis, x.shape);
- var permutedAxes = axis_util.getAxesPermutation(axes, x.rank);
- if (permutedAxes != null) {
- x = x.transpose(permutedAxes);
- axes = axis_util.getInnerMostAxes(axes.length, x.rank);
- }
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.argMin(x, axes[0]); }, { x: x });
- };
- ReductionOps.argMax = function (x, axis) {
- if (axis === void 0) { axis = 0; }
- util.assertArgumentsAreTensors({ x: x }, 'argMax');
- if (axis == null) {
- axis = 0;
- }
- var axes = axis_util.parseAxisParam(axis, x.shape);
- var permutedAxes = axis_util.getAxesPermutation(axes, x.rank);
- if (permutedAxes != null) {
- x = x.transpose(permutedAxes);
- axes = axis_util.getInnerMostAxes(axes.length, x.rank);
- }
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.argMax(x, axes[0]); }, { x: x });
- };
- ReductionOps.all = function (x, axis, keepDims) {
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- util.assertArgumentsAreTensors({ x: x }, 'all');
- util.assert(x.dtype === 'bool', 'Error Array must be of type bool.');
- var origAxes = axis_util.parseAxisParam(axis, x.shape);
- var axes = origAxes;
- var permutedAxes = axis_util.getAxesPermutation(axes, x.rank);
- if (permutedAxes != null) {
- x = x.transpose(permutedAxes);
- axes = axis_util.getInnerMostAxes(axes.length, x.rank);
- }
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.all(x, axes); }, { x: x });
- if (keepDims) {
- var newShape = axis_util.expandShapeToKeepDim(res.shape, origAxes);
- return res.reshape(newShape);
- }
- return res;
- };
- ReductionOps.moments = function (x, axis, keepDims) {
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- util.assertArgumentsAreTensors({ x: x }, 'moments');
- var axes = axis_util.parseAxisParam(axis, x.shape);
- var mean = x.mean(axes, keepDims);
- var keepDimsShape = mean.shape;
- if (!keepDims) {
- keepDimsShape = axis_util.expandShapeToKeepDim(mean.shape, axes);
- }
- var devSquared = x.toFloat().sub(mean.reshape(keepDimsShape)).square();
- var variance = devSquared.mean(axes, keepDims);
- return { mean: mean, variance: variance };
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),
- operation_1.operation
- ], ReductionOps, "logSumExp", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),
- operation_1.operation
- ], ReductionOps, "sum", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),
- operation_1.operation
- ], ReductionOps, "mean", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),
- operation_1.operation
- ], ReductionOps, "min", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),
- operation_1.operation
- ], ReductionOps, "max", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),
- operation_1.operation
- ], ReductionOps, "argMin", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),
- operation_1.operation
- ], ReductionOps, "argMax", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),
- operation_1.operation
- ], ReductionOps, "all", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }),
- operation_1.operation
- ], ReductionOps, "moments", null);
- return ReductionOps;
- }());
- exports.ReductionOps = ReductionOps;
- },{"../doc":49,"../environment":51,"../globals":52,"../util":164,"./axis_util":109,"./operation":128,"./ops":129}],134:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var util = require("../util");
- var axis_util_1 = require("./axis_util");
- var operation_1 = require("./operation");
- var ReverseOps = (function () {
- function ReverseOps() {
- }
- ReverseOps.reverse1d = function (x) {
- util.assert(x.rank === 1, "Error in reverse1D: x must be rank 1 but got\n rank " + x.rank + ".");
- return ReverseOps.reverse(x, 0);
- };
- ReverseOps.reverse2d = function (x, axis) {
- util.assert(x.rank === 2, "Error in reverse2D: x must be rank 2 but got\n rank " + x.rank + ".");
- return ReverseOps.reverse(x, axis);
- };
- ReverseOps.reverse3d = function (x, axis) {
- util.assert(x.rank === 3, "Error in reverse3D: x must be rank 3 but got\n rank " + x.rank + ".");
- return ReverseOps.reverse(x, axis);
- };
- ReverseOps.reverse4d = function (x, axis) {
- util.assert(x.rank === 4, "Error in reverse4D: x must be rank 4 but got\n rank " + x.rank + ".");
- return ReverseOps.reverse(x, axis);
- };
- ReverseOps.reverse = function (x, axis) {
- util.assertArgumentsAreTensors({ x: x }, 'reverse');
- if (x.rank === 0) {
- return x.clone();
- }
- var axes = axis_util_1.parseAxisParam(axis, x.shape);
- var grad = function (dy) {
- return { x: function () { return dy.reverse(axes); } };
- };
- var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.reverse(x, axes); }, { x: x }, grad);
- return res.reshapeAs(x);
- };
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),
- operation_1.operation
- ], ReverseOps, "reverse", null);
- return ReverseOps;
- }());
- exports.ReverseOps = ReverseOps;
- },{"../doc":49,"../environment":51,"../util":164,"./axis_util":109,"./operation":128}],135:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var util = require("../util");
- var array_ops_1 = require("./array_ops");
- var binary_ops_1 = require("./binary_ops");
- var compare_1 = require("./compare");
- var logical_ops_1 = require("./logical_ops");
- var operation_1 = require("./operation");
- var SegmentOps = (function () {
- function SegmentOps() {
- }
- SegmentOps.unsortedSegmentSum = function (x, segmentIds, numSegments) {
- util.assertArgumentsAreTensors({ x: x, segmentIds: segmentIds }, 'unsortedSegmentSum');
- util.assert(segmentIds.dtype === 'int32', 'segmentIds must be of dtype `int32`');
- util.assert(util.isInt(numSegments), 'numSegments must be of dtype int');
- var gradFunc = function (dy) {
- var derX = function () {
- return gatherDropNegatives(dy, segmentIds);
- };
- return { x: derX };
- };
- return environment_1.ENV.engine.runKernel(function (backend) {
- return backend.unsortedSegmentSum(x, segmentIds, numSegments);
- }, { x: x }, gradFunc);
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Segment' }),
- operation_1.operation
- ], SegmentOps, "unsortedSegmentSum", null);
- return SegmentOps;
- }());
- exports.SegmentOps = SegmentOps;
- function gatherDropNegatives(x, indices) {
- var zeroClippedIndices = binary_ops_1.BinaryOps.maximum(indices, array_ops_1.ArrayOps.zerosLike(indices));
- var gathered = array_ops_1.ArrayOps.gather(x, zeroClippedIndices);
- var isPositive = compare_1.CompareOps.greaterEqual(indices, array_ops_1.ArrayOps.scalar(0, 'int32'));
- var numIters = gathered.rank - isPositive.rank;
- for (var i = 0; i < numIters; ++i) {
- isPositive = array_ops_1.ArrayOps.expandDims(isPositive, i + 1);
- }
- isPositive =
- logical_ops_1.LogicalOps.logicalAnd(isPositive, array_ops_1.ArrayOps.ones(gathered.shape, 'bool'));
- var zeroSlice = array_ops_1.ArrayOps.zerosLike(gathered);
- return logical_ops_1.LogicalOps.where(isPositive, gathered, zeroSlice);
- }
- },{"../doc":49,"../environment":51,"../util":164,"./array_ops":108,"./binary_ops":111,"./compare":113,"./logical_ops":121,"./operation":128}],136:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var util_1 = require("../util");
- var reduce_util_1 = require("./reduce_util");
- function segOpComputeOptimalWindowSize(inSize, numSegments) {
- var done = false;
- var res;
- if (inSize <= reduce_util_1.PARALLELIZE_THRESHOLD) {
- res = inSize;
- done = true;
- }
- else {
- res = util_1.nearestDivisor(inSize, Math.floor(Math.sqrt(inSize)));
- }
- while (!done) {
- if (res > numSegments || res === inSize) {
- done = true;
- break;
- }
- else {
- res = util_1.nearestDivisor(inSize, res + 1);
- }
- }
- return res;
- }
- exports.segOpComputeOptimalWindowSize = segOpComputeOptimalWindowSize;
- function computeOutShape(aShape, axis, numSegments) {
- var outShape = [];
- var rank = aShape.length;
- for (var dim = 0; dim < rank; dim++) {
- if (dim !== axis) {
- outShape.push(aShape[dim]);
- }
- else {
- outShape.push(numSegments);
- }
- }
- return outShape;
- }
- exports.computeOutShape = computeOutShape;
- },{"../util":164,"./reduce_util":132}],137:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.SELU_SCALEALPHA = 1.7580993408473768599402175208123;
- exports.SELU_SCALE = 1.0507009873554804934193349852946;
- },{}],138:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var util = require("../util");
- var operation_1 = require("./operation");
- var SigmoidCrossEntropyOps = (function () {
- function SigmoidCrossEntropyOps() {
- }
- SigmoidCrossEntropyOps.sigmoidCrossEntropyWithLogits = function (labels, logits) {
- util.assertArgumentsAreTensors({ labels: labels, logits: logits }, 'sigmoidCrossEntropyWithLogits');
- util.assertShapesMatch(labels.shape, logits.shape, 'Error in sigmoidCrossEntropyWithLogits: ');
- var maxOutput = logits.relu();
- var outputXTarget = logits.mul(labels);
- var sigmoidOutput = logits.abs().neg().exp().log1p();
- return maxOutput.sub(outputXTarget).add(sigmoidOutput);
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Cross Entropy' }),
- operation_1.operation
- ], SigmoidCrossEntropyOps, "sigmoidCrossEntropyWithLogits", null);
- return SigmoidCrossEntropyOps;
- }());
- exports.SigmoidCrossEntropyOps = SigmoidCrossEntropyOps;
- },{"../doc":49,"../util":164,"./operation":128}],139:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var util = require("../util");
- var operation_1 = require("./operation");
- var slice_util = require("./slice_util");
- var SliceOps = (function () {
- function SliceOps() {
- }
- SliceOps.slice1d = function (x, begin, size) {
- util.assert(x.rank === 1, "slice1d expects a rank-1 tensor, but got a rank-" + x.rank + " tensor");
- return SliceOps.slice(x, [begin], [size]);
- };
- SliceOps.slice2d = function (x, begin, size) {
- util.assert(x.rank === 2, "slice1d expects a rank-2 tensor, but got a rank-" + x.rank + " tensor");
- return SliceOps.slice(x, begin, size);
- };
- SliceOps.slice3d = function (x, begin, size) {
- util.assert(x.rank === 3, "slice1d expects a rank-3 tensor, but got a rank-" + x.rank + " tensor");
- return SliceOps.slice(x, begin, size);
- };
- SliceOps.slice4d = function (x, begin, size) {
- util.assert(x.rank === 4, "slice1d expects a rank-4 tensor, but got a rank-" + x.rank + " tensor");
- return SliceOps.slice(x, begin, size);
- };
- SliceOps.slice = function (x, begin, size) {
- util.assertArgumentsAreTensors({ x: x }, 'slice');
- if (x.rank === 0) {
- throw new Error('Slicing scalar is not possible');
- }
- var begin_;
- if (typeof begin === 'number') {
- begin_ = [begin].concat(new Array(x.rank - 1).fill(0));
- }
- else if (begin.length < x.rank) {
- begin_ = begin.concat(new Array(x.rank - begin.length).fill(0));
- }
- else {
- begin_ = begin;
- }
- var size_;
- if (size == null) {
- size_ = new Array(x.rank).fill(-1);
- }
- else if (typeof size === 'number') {
- size_ = [size].concat(new Array(x.rank - 1).fill(-1));
- }
- else if (size.length < x.rank) {
- size_ = size.concat(new Array(x.rank - size.length).fill(-1));
- }
- else {
- size_ = size;
- }
- size_ = size_.map(function (d, i) {
- if (d >= 0) {
- return d;
- }
- else {
- util.assert(d === -1, 'Bad value in size');
- return x.shape[i] - begin_[i];
- }
- });
- slice_util.assertParamsValid(x, begin_, size_);
- var inputShape = x.shape;
- var grad = function (dy) {
- var paddings = [];
- for (var i = 0; i < dy.rank; i++) {
- paddings.push([begin_[i], inputShape[i] - begin_[i] - size_[i]]);
- }
- return { x: function () { return dy.pad(paddings); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.slice(x, begin_, size_); }, { x: x }, grad);
- };
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),
- operation_1.operation
- ], SliceOps, "slice", null);
- return SliceOps;
- }());
- exports.SliceOps = SliceOps;
- },{"../doc":49,"../environment":51,"../util":164,"./operation":128,"./slice_util":140}],140:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var util = require("../util");
- function assertParamsValid(input, begin, size) {
- util.assert(input.rank === begin.length, "Error in slice" + input.rank + "D: Length of begin " + begin + " must " +
- ("match the rank of the array (" + input.rank + ")."));
- util.assert(input.rank === size.length, "Error in slice" + input.rank + "D: Length of size " + size + " must " +
- ("match the rank of the array (" + input.rank + ")."));
- for (var i = 0; i < input.rank; ++i) {
- util.assert(begin[i] + size[i] <= input.shape[i], "Error in slice" + input.rank + "D: begin[" + i + "] + size[" + i + "] " +
- ("(" + (begin[i] + size[i]) + ") would overflow input.shape[" + i + "] (" + input.shape[i] + ")"));
- }
- }
- exports.assertParamsValid = assertParamsValid;
- function getStridedSlicedInfo(shape, begin, end, strides, beginMask, endMask) {
- if (beginMask === void 0) { beginMask = 0; }
- if (endMask === void 0) { endMask = 0; }
- var startIndex = [];
- var endIndex = [];
- for (var i = 0; i < shape.length; i++) {
- startIndex[i] = startForAxis(beginMask, begin, strides, shape, i);
- endIndex[i] = stopForAxis(endMask, end, strides, shape, i);
- }
- var size = new Array(shape.length).fill(0);
- size = size.map(function (d, i) {
- var count = 0;
- for (var start = startIndex[i]; !(strides[i] > 0 ? start >= endIndex[i] : start <= endIndex[i]); start += strides[i]) {
- count += 1;
- }
- return count;
- });
- return [startIndex, size];
- }
- exports.getStridedSlicedInfo = getStridedSlicedInfo;
- function startForAxis(beginMask, startIndices, strides, inputShape, axis) {
- var start = startIndices[axis];
- if (beginMask & 1 << axis) {
- if (strides[axis] > 0) {
- start = Number.MIN_SAFE_INTEGER;
- }
- else {
- start = Number.MAX_SAFE_INTEGER;
- }
- }
- var axisSize = inputShape[axis];
- if (start < 0) {
- start += axisSize;
- }
- start = util.clamp(0, start, axisSize - 1);
- return start;
- }
- exports.startForAxis = startForAxis;
- function stopForAxis(endMask, stopIndices, strides, inputShape, axis) {
- var stop = stopIndices[axis];
- if (endMask & (1 << axis)) {
- if (strides[axis] > 0) {
- stop = Number.MAX_SAFE_INTEGER;
- }
- else {
- stop = Number.MIN_SAFE_INTEGER;
- }
- }
- var axisSize = inputShape[axis];
- if (stop < 0) {
- stop += axisSize;
- }
- if (strides[axis] > 0) {
- stop = util.clamp(0, stop, axisSize);
- }
- else {
- stop = util.clamp(-1, stop, axisSize - 1);
- }
- return stop;
- }
- exports.stopForAxis = stopForAxis;
- },{"../util":164}],141:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var globals_1 = require("../globals");
- var util = require("../util");
- var axis_util = require("./axis_util");
- var operation_1 = require("./operation");
- var ops = require("./ops");
- var SoftmaxOps = (function () {
- function SoftmaxOps() {
- }
- SoftmaxOps.softmax = function (logits, dim) {
- if (dim === void 0) { dim = -1; }
- util.assertArgumentsAreTensors({ logits: logits }, 'softmax');
- if (dim === -1) {
- dim = logits.rank - 1;
- }
- if (dim !== logits.rank - 1) {
- throw Error('Softmax along a non-last dimension is not yet supported. ' +
- ("Logits was rank " + logits.rank + " and dim was " + dim));
- }
- var customOp = globals_1.customGrad(function (logits) {
- var keepDims = true;
- var lse = logits.logSumExp([dim], keepDims);
- var logResult = logits.toFloat().sub(lse);
- var y = logResult.exp();
- var gradFunc = function (dy) {
- var dyTimesY = dy.mul(y);
- var keepDims = true;
- return dyTimesY.sub(dyTimesY.sum([dim], keepDims).mul(y));
- };
- return { value: y, gradFunc: gradFunc };
- });
- return customOp(logits);
- };
- SoftmaxOps.softmaxCrossEntropy = function (labels, logits, dim) {
- if (dim === void 0) { dim = -1; }
- util.assertArgumentsAreTensors({ labels: labels, logits: logits }, 'softmaxCrossEntropy');
- util.assertShapesMatch(labels.shape, logits.shape, 'Error in softmaxCrossEntropy: ');
- if (dim === -1) {
- dim = logits.rank - 1;
- }
- if (dim !== logits.rank - 1) {
- throw Error("Softmax cross entropy along a non-last dimension is not yet " +
- ("supported. Labels / logits was rank " + logits.rank + " ") +
- ("and dim was " + dim));
- }
- var customOp = globals_1.customGrad(function (labels, logits) {
- var predictedProbs = logits.softmax(dim);
- var costVector = ops.scalar(1e-5).add(predictedProbs).log().mul(labels).neg();
- var value = costVector.sum([dim]);
- var gradFunc = function (dy) {
- var dyShape = axis_util.expandShapeToKeepDim(dy.shape, [dim]);
- return [
- dy.reshape(dyShape).mul(labels.toFloat().sub(predictedProbs)),
- dy.reshape(dyShape).mul(predictedProbs.sub(labels.toFloat())),
- ];
- };
- return { value: value, gradFunc: gradFunc };
- });
- return customOp(labels, logits);
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }),
- operation_1.operation
- ], SoftmaxOps, "softmax", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),
- operation_1.operation
- ], SoftmaxOps, "softmaxCrossEntropy", null);
- return SoftmaxOps;
- }());
- exports.SoftmaxOps = SoftmaxOps;
- },{"../doc":49,"../globals":52,"../util":164,"./axis_util":109,"./operation":128,"./ops":129}],142:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var util = require("../util");
- var operation_1 = require("./operation");
- var StridedSliceOps = (function () {
- function StridedSliceOps() {
- }
- StridedSliceOps.stridedSlice = function (x, begin, end, strides, beginMask, endMask) {
- if (beginMask === void 0) { beginMask = 0; }
- if (endMask === void 0) { endMask = 0; }
- util.assertArgumentsAreTensors({ x: x }, 'stridedSlice');
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.stridedSlice(x, begin, end, strides, beginMask, endMask); }, { x: x });
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Slicing and Joining' }),
- operation_1.operation
- ], StridedSliceOps, "stridedSlice", null);
- return StridedSliceOps;
- }());
- exports.StridedSliceOps = StridedSliceOps;
- },{"../doc":49,"../environment":51,"../util":164,"./operation":128}],143:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var util = require("../util");
- var axis_util = require("./axis_util");
- var operation_1 = require("./operation");
- var TransposeOps = (function () {
- function TransposeOps() {
- }
- TransposeOps.transpose = function (x, perm) {
- util.assertArgumentsAreTensors({ x: x }, 'transpose');
- if (perm == null) {
- perm = x.shape.map(function (s, i) { return i; }).reverse();
- }
- util.assert(x.rank === perm.length, "Error in transpose: rank of input " + x.rank + " " +
- ("must match length of perm " + perm + "."));
- perm.forEach(function (axis) {
- util.assert(axis >= 0 && axis < x.rank, "All entries in 'perm' must be between 0 and " + (x.rank - 1) +
- (" but got " + perm));
- });
- if (x.rank <= 1) {
- return x.clone();
- }
- var der = function (dy) {
- var undoPerm = axis_util.getUndoAxesPermutation(perm);
- return { x: function () { return dy.transpose(undoPerm); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.transpose(x, perm); }, { x: x }, der);
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }),
- operation_1.operation
- ], TransposeOps, "transpose", null);
- return TransposeOps;
- }());
- exports.TransposeOps = TransposeOps;
- },{"../doc":49,"../environment":51,"../util":164,"./axis_util":109,"./operation":128}],144:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var environment_1 = require("../environment");
- var util = require("../util");
- var operation_1 = require("./operation");
- var ops = require("./ops");
- var ops_1 = require("./ops");
- var selu_util = require("./selu_util");
- var UnaryOps = (function () {
- function UnaryOps() {
- }
- UnaryOps.neg = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'neg');
- var grad = function (dy) {
- return { x: function () { return dy.neg(); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.neg(x); }, { x: x }, grad);
- };
- UnaryOps.ceil = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'ceil');
- var grad = function (dy) {
- return { x: function () { return ops.zerosLike(dy); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.ceil(x); }, { x: x }, grad);
- };
- UnaryOps.floor = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'floor');
- var grad = function (dy) {
- return { x: function () { return ops.zerosLike(dy); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.floor(x); }, { x: x }, grad);
- };
- UnaryOps.sign = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'sign');
- var grad = function (dy) {
- return { x: function () { return ops.zerosLike(dy); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.sign(x); }, { x: x }, grad);
- };
- UnaryOps.round = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'round');
- var grad = function (dy) {
- return { x: function () { return ops.zerosLike(dy); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.round(x); }, { x: x }, grad);
- };
- UnaryOps.exp = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'exp');
- var bck = function (dy, saved) {
- var y = saved[0];
- return { x: function () { return dy.mulStrict(y); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend, save) { return save(backend.exp(x)); }, { x: x }, bck);
- };
- UnaryOps.expm1 = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'expm1');
- var grad = function (dy) {
- return { x: function () { return dy.mulStrict(x.exp()); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.expm1(x); }, { x: x }, grad);
- };
- UnaryOps.log = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'log');
- var grad = function (dy) {
- return { x: function () { return dy.divStrict(x.toFloat()); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.log(x); }, { x: x }, grad);
- };
- UnaryOps.log1p = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'log1p');
- var grad = function (dy) {
- return { x: function () { return dy.divStrict(x.add(ops.scalar(1))); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.log1p(x); }, { x: x }, grad);
- };
- UnaryOps.sqrt = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'sqrt');
- var grad = function (dy) {
- return { x: function () { return dy.divStrict(x.toFloat().sqrt().mul(ops.scalar(2))); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.sqrt(x); }, { x: x }, grad);
- };
- UnaryOps.rsqrt = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'rsqrt');
- var grad = function (dy) {
- return {
- x: function () { return dy.divStrict(x.pow(ops.scalar(1.5)).mul(ops.scalar(2))).neg(); }
- };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.rsqrt(x); }, { x: x }, grad);
- };
- UnaryOps.square = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'square');
- var grad = function (dy) {
- return { x: function () { return dy.mulStrict(x.toFloat().mul(ops.scalar(2))); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.square(x); }, { x: x }, grad);
- };
- UnaryOps.reciprocal = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'reciprocal');
- var grad = function (dy) {
- return { x: function () { return dy.divStrict(x.square().neg()); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.reciprocal(x); }, { x: x }, grad);
- };
- UnaryOps.abs = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'abs');
- var grad = function (dy) {
- return { x: function () { return dy.mulStrict(x.toFloat().step(-1)); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.abs(x); }, { x: x }, grad);
- };
- UnaryOps.clipByValue = function (x, clipValueMin, clipValueMax) {
- util.assertArgumentsAreTensors({ x: x }, 'clipByValue');
- util.assert((clipValueMin <= clipValueMax), "Error in clip: min (" + clipValueMin + ") must be " +
- ("less than or equal to max (" + clipValueMax + ")."));
- var grad = function (dy) {
- return {
- x: function () { return dy.where(x.greaterEqual(ops.scalar(clipValueMin))
- .logicalAnd(x.lessEqual(ops.scalar(clipValueMax))), ops_1.zerosLike(dy)); },
- };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.clip(x, clipValueMin, clipValueMax); }, { x: x }, grad);
- };
- UnaryOps.relu = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'relu');
- if (x.dtype === 'bool') {
- return x.toInt();
- }
- var grad = function (dy) {
- var stepRes = x.step();
- return { x: function () { return dy.mulStrict(stepRes.toFloat()); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.relu(x); }, { x: x }, grad);
- };
- UnaryOps.elu = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'elu');
- var grad = function (dy, saved) {
- var y = saved[0];
- return {
- x: function () {
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.eluDer(dy, y); }, { dy: dy, y: y });
- }
- };
- };
- return environment_1.ENV.engine.runKernel(function (backend, save) { return save(backend.elu(x)); }, { x: x }, grad);
- };
- UnaryOps.selu = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'selu');
- var grad = function (dy) {
- return {
- x: function () {
- var mask = x.greater(ops.scalar(0));
- var scaleAlpha = ops.scalar(selu_util.SELU_SCALEALPHA);
- var scale = ops.scalar(selu_util.SELU_SCALE);
- var greaterThanZeroDer = dy.mul(scale);
- var lessEqualZeroDer = dy.mul(scaleAlpha).mul(x.toFloat().exp());
- return ops.where(mask, greaterThanZeroDer, lessEqualZeroDer);
- }
- };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.selu(x); }, { x: x }, grad);
- };
- UnaryOps.leakyRelu = function (x, alpha) {
- if (alpha === void 0) { alpha = 0.2; }
- util.assertArgumentsAreTensors({ x: x }, 'leakyRelu');
- return ops.maximum(ops.scalar(alpha).mul(x), x);
- };
- UnaryOps.prelu = function (x, alpha) {
- util.assertArgumentsAreTensors({ x: x, alpha: alpha }, 'prelu');
- var zero = ops.scalar(0);
- return ops.maximum(zero, x).add(alpha.mul(ops.minimum(zero, x)));
- };
- UnaryOps.sigmoid = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'sigmoid');
- var grad = function (dy, saved) {
- var y = saved[0];
- return { x: function () { return dy.mulStrict(y.mul(ops.scalar(1).sub(y))); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend, save) { return save(backend.sigmoid(x)); }, { x: x }, grad);
- };
- UnaryOps.logSigmoid = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'logSigmoid');
- var grad = function (dy) {
- return { x: function () { return dy.mulStrict(x.neg().sigmoid()); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.softplus(x.neg()).neg(); }, { x: x }, grad);
- };
- UnaryOps.softplus = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'softplus');
- var grad = function (dy) {
- return { x: function () { return dy.mulStrict(x.sigmoid()); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.softplus(x); }, { x: x }, grad);
- };
- UnaryOps.sin = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'sin');
- var grad = function (dy) {
- return { x: function () { return x.toFloat().cos().mulStrict(dy); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.sin(x); }, { x: x }, grad);
- };
- UnaryOps.cos = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'cos');
- var grad = function (dy) {
- return { x: function () { return x.toFloat().sin().neg().mulStrict(dy); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.cos(x); }, { x: x }, grad);
- };
- UnaryOps.tan = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'tan');
- var grad = function (dy) {
- return { x: function () { return dy.divStrict(x.cos().square()); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.tan(x); }, { x: x }, grad);
- };
- UnaryOps.asin = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'asin');
- var grad = function (dy) {
- return {
- x: function () {
- return dy.divStrict(UnaryOps.sqrt(ops.scalar(1).sub(x.toFloat().square())));
- }
- };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.asin(x); }, { x: x }, grad);
- };
- UnaryOps.acos = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'acos');
- var grad = function (dy) {
- return {
- x: function () {
- return dy.divStrict(UnaryOps.sqrt(ops.scalar(1).sub(x.toFloat().square())))
- .neg();
- }
- };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.acos(x); }, { x: x }, grad);
- };
- UnaryOps.atan = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'atan');
- var grad = function (dy) {
- return { x: function () { return dy.divStrict(ops.scalar(1).add(x.toFloat().square())); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.atan(x); }, { x: x }, grad);
- };
- UnaryOps.sinh = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'sinh');
- var grad = function (dy) {
- return { x: function () { return x.toFloat().cosh().mulStrict(dy); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.sinh(x); }, { x: x }, grad);
- };
- UnaryOps.cosh = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'cosh');
- var grad = function (dy) {
- return { x: function () { return x.toFloat().sinh().mulStrict(dy); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.cosh(x); }, { x: x }, grad);
- };
- UnaryOps.tanh = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'tanh');
- var grad = function (dy, saved) {
- var y = saved[0];
- return { x: function () { return ops.scalar(1).sub(y.square()).mulStrict(dy); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend, save) { return save(backend.tanh(x)); }, { x: x }, grad);
- };
- UnaryOps.asinh = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'asinh');
- var grad = function (dy) {
- return {
- x: function () {
- return dy.divStrict(UnaryOps.sqrt(ops.scalar(1).add(x.toFloat().square())));
- }
- };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.asinh(x); }, { x: x }, grad);
- };
- UnaryOps.acosh = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'acosh');
- var grad = function (dy) {
- return {
- x: function () {
- return dy.divStrict(UnaryOps.sqrt(x.toFloat().square().sub(ops.scalar(1))));
- }
- };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.acosh(x); }, { x: x }, grad);
- };
- UnaryOps.atanh = function (x) {
- util.assertArgumentsAreTensors({ x: x }, 'atanh');
- var grad = function (dy) {
- return { x: function () { return dy.divStrict(ops.scalar(1).sub(x.toFloat().square())); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.atanh(x); }, { x: x }, grad);
- };
- UnaryOps.erf = function (x) {
- util.assert(x.dtype === 'int32' || x.dtype === 'float32', 'Input dtype must be `int32` or `float32`.');
- if (x.dtype === 'int32') {
- x = x.toFloat();
- }
- var grad = function (dy) {
- return {
- x: function () {
- return dy.mulStrict(ops.scalar(2 / Math.sqrt(Math.PI))
- .mul(x.square().neg().exp()));
- }
- };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.erf(x); }, { x: x }, grad);
- };
- UnaryOps.step = function (x, alpha) {
- if (alpha === void 0) { alpha = 0.0; }
- util.assertArgumentsAreTensors({ x: x }, 'step');
- var grad = function (dy) {
- return { x: function () { return ops.zerosLike(dy); } };
- };
- return environment_1.ENV.engine.runKernel(function (backend) { return backend.step(x, alpha); }, { x: x }, grad);
- };
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "neg", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "ceil", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "floor", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "sign", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "round", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "exp", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "expm1", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "log", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "log1p", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "sqrt", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "rsqrt", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "square", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "reciprocal", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "abs", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "clipByValue", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "relu", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "elu", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "selu", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "leakyRelu", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "prelu", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "sigmoid", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "logSigmoid", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "softplus", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "sin", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "cos", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "tan", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "asin", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "acos", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "atan", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "sinh", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "cosh", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "tanh", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "asinh", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "acosh", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "atanh", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "erf", null);
- __decorate([
- doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
- operation_1.operation
- ], UnaryOps, "step", null);
- return UnaryOps;
- }());
- exports.UnaryOps = UnaryOps;
- },{"../doc":49,"../environment":51,"../util":164,"./operation":128,"./ops":129,"./selu_util":137}],145:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../environment");
- var globals_1 = require("../globals");
- var ops_1 = require("../ops/ops");
- var serialization_1 = require("../serialization");
- var optimizer_1 = require("./optimizer");
- var optimizer_utils = require("./optimizer_utils");
- var AdadeltaOptimizer = (function (_super) {
- __extends(AdadeltaOptimizer, _super);
- function AdadeltaOptimizer(learningRate, rho, epsilon) {
- if (epsilon === void 0) { epsilon = null; }
- var _this = _super.call(this) || this;
- _this.learningRate = learningRate;
- _this.rho = rho;
- _this.epsilon = epsilon;
- _this.accumulatedGrads = {};
- _this.accumulatedUpdates = {};
- _this.c = globals_1.keep(ops_1.scalar(-learningRate));
- _this.rhoScalar = globals_1.keep(ops_1.scalar(rho));
- _this.oneMinusRho = globals_1.keep(ops_1.scalar(1 - rho));
- if (epsilon === null) {
- epsilon = optimizer_utils.getOptimizerDefaultEpsilonValue();
- }
- _this.epsilonScalar = globals_1.keep(ops_1.scalar(epsilon));
- return _this;
- }
- AdadeltaOptimizer.prototype.applyGradients = function (variableGradients) {
- var _this = this;
- var _loop_1 = function (variableName) {
- var value = environment_1.ENV.engine.registeredVariables[variableName];
- if (this_1.accumulatedGrads[variableName] == null) {
- var trainable_1 = false;
- globals_1.tidy(function () {
- _this.accumulatedGrads[variableName] =
- ops_1.zerosLike(value).variable(trainable_1);
- });
- }
- if (this_1.accumulatedUpdates[variableName] == null) {
- var trainable_2 = false;
- globals_1.tidy(function () {
- _this.accumulatedUpdates[variableName] =
- ops_1.zerosLike(value).variable(trainable_2);
- });
- }
- var gradient = variableGradients[variableName];
- var accumulatedGrad = this_1.accumulatedGrads[variableName];
- var accumulatedUpdate = this_1.accumulatedUpdates[variableName];
- globals_1.tidy(function () {
- var newAccumulatedGrad = _this.rhoScalar.mul(accumulatedGrad)
- .add(_this.oneMinusRho.mul(gradient.square()));
- var updates = accumulatedUpdate.add(_this.epsilonScalar)
- .sqrt()
- .div(accumulatedGrad.add(_this.epsilonScalar).sqrt())
- .mul(gradient);
- var newAccumulatedUpdate = _this.rhoScalar.mul(accumulatedUpdate)
- .add(_this.oneMinusRho.mul(updates.square()));
- _this.accumulatedGrads[variableName].assign(newAccumulatedGrad);
- _this.accumulatedUpdates[variableName].assign(newAccumulatedUpdate);
- var newValue = _this.c.mul(updates).add(value);
- value.assign(newValue);
- });
- };
- var this_1 = this;
- for (var variableName in variableGradients) {
- _loop_1(variableName);
- }
- };
- AdadeltaOptimizer.prototype.dispose = function () {
- var _this = this;
- this.c.dispose();
- this.epsilonScalar.dispose();
- this.rhoScalar.dispose();
- this.oneMinusRho.dispose();
- if (this.accumulatedUpdates != null) {
- Object.keys(this.accumulatedUpdates)
- .forEach(function (name) { return _this.accumulatedUpdates[name].dispose(); });
- Object.keys(this.accumulatedGrads)
- .forEach(function (name) { return _this.accumulatedGrads[name].dispose(); });
- }
- };
- AdadeltaOptimizer.prototype.getConfig = function () {
- return {
- learningRate: this.learningRate,
- rho: this.rho,
- epsilon: this.epsilon
- };
- };
- AdadeltaOptimizer.fromConfig = function (cls, config) {
- return new cls(config.learningRate, config.rho, config.epsilon);
- };
- AdadeltaOptimizer.className = 'AdadeltaOptimizer';
- return AdadeltaOptimizer;
- }(optimizer_1.Optimizer));
- exports.AdadeltaOptimizer = AdadeltaOptimizer;
- serialization_1.SerializationMap.register(AdadeltaOptimizer);
- },{"../environment":51,"../globals":52,"../ops/ops":129,"../serialization":156,"./optimizer":150,"./optimizer_utils":152}],146:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../environment");
- var globals_1 = require("../globals");
- var ops_1 = require("../ops/ops");
- var serialization_1 = require("../serialization");
- var optimizer_1 = require("./optimizer");
- var optimizer_utils = require("./optimizer_utils");
- var AdagradOptimizer = (function (_super) {
- __extends(AdagradOptimizer, _super);
- function AdagradOptimizer(learningRate, initialAccumulatorValue) {
- if (initialAccumulatorValue === void 0) { initialAccumulatorValue = 0.1; }
- var _this = _super.call(this) || this;
- _this.learningRate = learningRate;
- _this.initialAccumulatorValue = initialAccumulatorValue;
- _this.accumulatedGrads = {};
- _this.c = globals_1.keep(ops_1.scalar(-learningRate));
- var epsilon = optimizer_utils.getOptimizerDefaultEpsilonValue();
- _this.epsilon = globals_1.keep(ops_1.scalar(epsilon));
- return _this;
- }
- AdagradOptimizer.prototype.applyGradients = function (variableGradients) {
- var _this = this;
- var _loop_1 = function (variableName) {
- var value = environment_1.ENV.engine.registeredVariables[variableName];
- if (this_1.accumulatedGrads[variableName] == null) {
- var trainable_1 = false;
- globals_1.tidy(function () {
- _this.accumulatedGrads[variableName] =
- ops_1.fill(value.shape, _this.initialAccumulatorValue)
- .variable(trainable_1);
- });
- }
- var gradient = variableGradients[variableName];
- var accumulatedGrad = this_1.accumulatedGrads[variableName];
- globals_1.tidy(function () {
- var newAccumulatedGrad = accumulatedGrad.add(gradient.square());
- _this.accumulatedGrads[variableName].assign(newAccumulatedGrad);
- var newValue = _this.c
- .mul(gradient.div(newAccumulatedGrad.add(_this.epsilon).sqrt()))
- .add(value);
- value.assign(newValue);
- });
- };
- var this_1 = this;
- for (var variableName in variableGradients) {
- _loop_1(variableName);
- }
- };
- AdagradOptimizer.prototype.dispose = function () {
- var _this = this;
- this.epsilon.dispose();
- this.c.dispose();
- if (this.accumulatedGrads != null) {
- Object.keys(this.accumulatedGrads)
- .forEach(function (name) { return _this.accumulatedGrads[name].dispose(); });
- }
- };
- AdagradOptimizer.prototype.getConfig = function () {
- return {
- learningRate: this.learningRate,
- initialAccumulatorValue: this.initialAccumulatorValue,
- };
- };
- AdagradOptimizer.fromConfig = function (cls, config) {
- return new cls(config.learningRate, config.initialAccumulatorValue);
- };
- AdagradOptimizer.className = 'AdagradOptimizer';
- return AdagradOptimizer;
- }(optimizer_1.Optimizer));
- exports.AdagradOptimizer = AdagradOptimizer;
- serialization_1.SerializationMap.register(AdagradOptimizer);
- },{"../environment":51,"../globals":52,"../ops/ops":129,"../serialization":156,"./optimizer":150,"./optimizer_utils":152}],147:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../environment");
- var globals_1 = require("../globals");
- var ops_1 = require("../ops/ops");
- var serialization_1 = require("../serialization");
- var optimizer_1 = require("./optimizer");
- var optimizer_utils = require("./optimizer_utils");
- var AdamOptimizer = (function (_super) {
- __extends(AdamOptimizer, _super);
- function AdamOptimizer(learningRate, beta1, beta2, epsilon) {
- if (epsilon === void 0) { epsilon = null; }
- var _this = _super.call(this) || this;
- _this.learningRate = learningRate;
- _this.beta1 = beta1;
- _this.beta2 = beta2;
- _this.epsilon = epsilon;
- _this.accumulatedFirstMoment = {};
- _this.accumulatedSecondMoment = {};
- _this.c = globals_1.keep(ops_1.scalar(-learningRate));
- _this.beta1Scalar = globals_1.keep(ops_1.scalar(beta1));
- _this.beta2Scalar = globals_1.keep(ops_1.scalar(beta2));
- globals_1.tidy(function () {
- _this.accBeta1 = ops_1.scalar(beta1).variable();
- _this.accBeta2 = ops_1.scalar(beta2).variable();
- });
- _this.oneMinusBeta1 = globals_1.keep(ops_1.scalar(1 - beta1));
- _this.oneMinusBeta2 = globals_1.keep(ops_1.scalar(1 - beta2));
- _this.one = globals_1.keep(ops_1.scalar(1));
- if (epsilon === null) {
- epsilon = optimizer_utils.getOptimizerDefaultEpsilonValue();
- }
- _this.epsScalar = globals_1.keep(ops_1.scalar(epsilon));
- return _this;
- }
- AdamOptimizer.prototype.applyGradients = function (variableGradients) {
- var _this = this;
- globals_1.tidy(function () {
- var oneMinusAccBeta1 = _this.one.sub(_this.accBeta1);
- var oneMinusAccBeta2 = _this.one.sub(_this.accBeta2);
- for (var variableName in variableGradients) {
- var value = environment_1.ENV.engine.registeredVariables[variableName];
- if (_this.accumulatedFirstMoment[variableName] == null) {
- var trainable = false;
- _this.accumulatedFirstMoment[variableName] =
- ops_1.zerosLike(value).variable(trainable);
- }
- if (_this.accumulatedSecondMoment[variableName] == null) {
- var trainable = false;
- _this.accumulatedSecondMoment[variableName] =
- ops_1.zerosLike(value).variable(trainable);
- }
- var gradient = variableGradients[variableName];
- var firstMoment = _this.accumulatedFirstMoment[variableName];
- var secondMoment = _this.accumulatedSecondMoment[variableName];
- var newFirstMoment = _this.beta1Scalar.mul(firstMoment)
- .add(_this.oneMinusBeta1.mul(gradient));
- var newSecondMoment = _this.beta2Scalar.mul(secondMoment)
- .add(_this.oneMinusBeta2.mul(gradient.square()));
- var biasCorrectedFirstMoment = newFirstMoment.div(oneMinusAccBeta1);
- var biasCorrectedSecondMoment = newSecondMoment.div(oneMinusAccBeta2);
- _this.accumulatedFirstMoment[variableName].assign(newFirstMoment);
- _this.accumulatedSecondMoment[variableName].assign(newSecondMoment);
- var newValue = _this.c
- .mul(biasCorrectedFirstMoment.div(_this.epsScalar.add(biasCorrectedSecondMoment.sqrt())))
- .add(value);
- value.assign(newValue);
- }
- _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1Scalar));
- _this.accBeta2.assign(_this.accBeta2.mul(_this.beta2Scalar));
- });
- };
- AdamOptimizer.prototype.dispose = function () {
- var _this = this;
- this.c.dispose();
- this.epsScalar.dispose();
- this.beta1Scalar.dispose();
- this.beta2Scalar.dispose();
- this.accBeta1.dispose();
- this.accBeta2.dispose();
- this.oneMinusBeta1.dispose();
- this.oneMinusBeta2.dispose();
- this.one.dispose();
- if (this.accumulatedFirstMoment != null) {
- Object.keys(this.accumulatedFirstMoment)
- .forEach(function (name) { return _this.accumulatedFirstMoment[name].dispose(); });
- }
- if (this.accumulatedSecondMoment != null) {
- Object.keys(this.accumulatedSecondMoment)
- .forEach(function (name) { return _this.accumulatedSecondMoment[name].dispose(); });
- }
- };
- AdamOptimizer.prototype.getConfig = function () {
- return {
- learningRate: this.learningRate,
- beta1: this.beta1,
- beta2: this.beta2,
- epsilon: this.epsilon,
- };
- };
- AdamOptimizer.fromConfig = function (cls, config) {
- return new cls(config.learningRate, config.beta1, config.beta2, config.epsilon);
- };
- AdamOptimizer.className = 'AdamOptimizer';
- return AdamOptimizer;
- }(optimizer_1.Optimizer));
- exports.AdamOptimizer = AdamOptimizer;
- serialization_1.SerializationMap.register(AdamOptimizer);
- },{"../environment":51,"../globals":52,"../ops/ops":129,"../serialization":156,"./optimizer":150,"./optimizer_utils":152}],148:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../environment");
- var globals_1 = require("../globals");
- var ops_1 = require("../ops/ops");
- var serialization_1 = require("../serialization");
- var optimizer_1 = require("./optimizer");
- var optimizer_utils = require("./optimizer_utils");
- var AdamaxOptimizer = (function (_super) {
- __extends(AdamaxOptimizer, _super);
- function AdamaxOptimizer(learningRate, beta1, beta2, epsilon, decay) {
- if (epsilon === void 0) { epsilon = null; }
- if (decay === void 0) { decay = 0.0; }
- var _this = _super.call(this) || this;
- _this.learningRate = learningRate;
- _this.beta1 = beta1;
- _this.beta2 = beta2;
- _this.epsilon = epsilon;
- _this.decay = decay;
- _this.accumulatedFirstMoment = {};
- _this.accumulatedWeightedInfNorm = {};
- _this.c = globals_1.keep(ops_1.scalar(-learningRate));
- _this.beta1Scalar = globals_1.keep(ops_1.scalar(beta1));
- _this.beta2Scalar = globals_1.keep(ops_1.scalar(beta2));
- _this.decayScalar = globals_1.keep(ops_1.scalar(decay));
- globals_1.tidy(function () {
- _this.iteration = ops_1.scalar(0).variable();
- _this.accBeta1 = ops_1.scalar(beta1).variable();
- });
- _this.oneMinusBeta1 = globals_1.keep(ops_1.scalar(1 - beta1));
- _this.one = globals_1.keep(ops_1.scalar(1));
- if (epsilon === null) {
- epsilon = optimizer_utils.getOptimizerDefaultEpsilonValue();
- }
- _this.epsScalar = globals_1.keep(ops_1.scalar(epsilon));
- return _this;
- }
- AdamaxOptimizer.prototype.applyGradients = function (variableGradients) {
- var _this = this;
- globals_1.tidy(function () {
- var oneMinusAccBeta1 = _this.one.sub(_this.accBeta1);
- var lr = _this.c.div(_this.one.add(_this.decayScalar.mul(_this.iteration)));
- for (var variableName in variableGradients) {
- var value = environment_1.ENV.engine.registeredVariables[variableName];
- if (_this.accumulatedFirstMoment[variableName] == null) {
- var trainable = false;
- _this.accumulatedFirstMoment[variableName] =
- ops_1.zerosLike(value).variable(trainable);
- }
- if (_this.accumulatedWeightedInfNorm[variableName] == null) {
- var trainable = false;
- _this.accumulatedWeightedInfNorm[variableName] =
- ops_1.zerosLike(value).variable(trainable);
- }
- var gradient = variableGradients[variableName];
- var firstMoment = _this.accumulatedFirstMoment[variableName];
- var weightedInfNorm = _this.accumulatedWeightedInfNorm[variableName];
- var newFirstMoment = _this.beta1Scalar.mul(firstMoment)
- .add(_this.oneMinusBeta1.mul(gradient));
- var ut0 = _this.beta2Scalar.mul(weightedInfNorm);
- var ut1 = gradient.abs();
- var newWeightedInfNorm = ut0.maximum(ut1);
- _this.accumulatedFirstMoment[variableName].assign(newFirstMoment);
- _this.accumulatedWeightedInfNorm[variableName].assign(newWeightedInfNorm);
- var newValue = lr.div(oneMinusAccBeta1)
- .mul(newFirstMoment.div(_this.epsScalar.add(newWeightedInfNorm)))
- .add(value);
- value.assign(newValue);
- }
- _this.iteration.assign(_this.iteration.add(_this.one));
- _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1Scalar));
- });
- };
- AdamaxOptimizer.prototype.dispose = function () {
- var _this = this;
- this.c.dispose();
- this.epsScalar.dispose();
- this.accBeta1.dispose();
- this.beta1Scalar.dispose();
- this.beta2Scalar.dispose();
- this.oneMinusBeta1.dispose();
- this.decayScalar.dispose();
- this.iteration.dispose();
- this.one.dispose();
- if (this.accumulatedFirstMoment != null) {
- Object.keys(this.accumulatedFirstMoment)
- .forEach(function (name) { return _this.accumulatedFirstMoment[name].dispose(); });
- }
- if (this.accumulatedWeightedInfNorm != null) {
- Object.keys(this.accumulatedWeightedInfNorm)
- .forEach(function (name) { return _this.accumulatedWeightedInfNorm[name].dispose(); });
- }
- };
- AdamaxOptimizer.prototype.getConfig = function () {
- return {
- learningRate: this.learningRate,
- beta1: this.beta1,
- beta2: this.beta2,
- epsilon: this.epsilon,
- decay: this.decay
- };
- };
- AdamaxOptimizer.fromConfig = function (cls, config) {
- return new cls(config.learningRate, config.beta1, config.beta2, config.epsilon, config.decay);
- };
- AdamaxOptimizer.className = 'AdamaxOptimizer';
- return AdamaxOptimizer;
- }(optimizer_1.Optimizer));
- exports.AdamaxOptimizer = AdamaxOptimizer;
- serialization_1.SerializationMap.register(AdamaxOptimizer);
- },{"../environment":51,"../globals":52,"../ops/ops":129,"../serialization":156,"./optimizer":150,"./optimizer_utils":152}],149:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../environment");
- var globals_1 = require("../globals");
- var ops_1 = require("../ops/ops");
- var serialization_1 = require("../serialization");
- var sgd_optimizer_1 = require("./sgd_optimizer");
- var MomentumOptimizer = (function (_super) {
- __extends(MomentumOptimizer, _super);
- function MomentumOptimizer(learningRate, momentum, useNesterov) {
- if (useNesterov === void 0) { useNesterov = false; }
- var _this = _super.call(this, learningRate) || this;
- _this.learningRate = learningRate;
- _this.momentum = momentum;
- _this.useNesterov = useNesterov;
- _this.m = ops_1.scalar(_this.momentum);
- _this.accumulations = {};
- return _this;
- }
- MomentumOptimizer.prototype.applyGradients = function (variableGradients) {
- var _this = this;
- var _loop_1 = function (variableName) {
- var value = environment_1.ENV.engine.registeredVariables[variableName];
- if (this_1.accumulations[variableName] == null) {
- var trainable_1 = false;
- globals_1.tidy(function () {
- _this.accumulations[variableName] =
- ops_1.zerosLike(value).variable(trainable_1);
- });
- }
- var accumulation = this_1.accumulations[variableName];
- var gradient = variableGradients[variableName];
- globals_1.tidy(function () {
- var newValue;
- var newAccumulation = _this.m.mul(accumulation).add(gradient);
- if (_this.useNesterov) {
- newValue =
- _this.c.mul(gradient.add(newAccumulation.mul(_this.m))).add(value);
- }
- else {
- newValue = _this.c.mul(newAccumulation).add(value);
- }
- _this.accumulations[variableName].assign(newAccumulation);
- value.assign(newValue);
- });
- };
- var this_1 = this;
- for (var variableName in variableGradients) {
- _loop_1(variableName);
- }
- };
- MomentumOptimizer.prototype.dispose = function () {
- _super.prototype.dispose.call(this);
- this.m.dispose();
- if (this.accumulations != null) {
- for (var variableName in this.accumulations) {
- this.accumulations[variableName].dispose();
- }
- }
- };
- MomentumOptimizer.prototype.setMomentum = function (momentum) {
- this.momentum = momentum;
- };
- MomentumOptimizer.prototype.getConfig = function () {
- return {
- learningRate: this.learningRate,
- momentum: this.momentum,
- useNesterov: this.useNesterov
- };
- };
- MomentumOptimizer.fromConfig = function (cls, config) {
- return new cls(config.learningRate, config.momentum, config.useNesterov);
- };
- MomentumOptimizer.className = 'MomentumOptimizer';
- return MomentumOptimizer;
- }(sgd_optimizer_1.SGDOptimizer));
- exports.MomentumOptimizer = MomentumOptimizer;
- serialization_1.SerializationMap.register(MomentumOptimizer);
- },{"../environment":51,"../globals":52,"../ops/ops":129,"../serialization":156,"./sgd_optimizer":154}],150:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var globals_1 = require("../globals");
- var serialization_1 = require("../serialization");
- var Optimizer = (function (_super) {
- __extends(Optimizer, _super);
- function Optimizer() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Optimizer.prototype.minimize = function (f, returnCost, varList) {
- if (returnCost === void 0) { returnCost = false; }
- var _a = this.computeGradients(f, varList), value = _a.value, grads = _a.grads;
- this.applyGradients(grads);
- var varNames = Object.keys(grads);
- varNames.forEach(function (varName) { return grads[varName].dispose(); });
- if (returnCost) {
- return value;
- }
- else {
- value.dispose();
- return null;
- }
- };
- Optimizer.prototype.computeGradients = function (f, varList) {
- return globals_1.variableGrads(f, varList);
- };
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Optimizers' })
- ], Optimizer.prototype, "minimize", null);
- Optimizer = __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Classes', namespace: 'train' })
- ], Optimizer);
- return Optimizer;
- }(serialization_1.Serializable));
- exports.Optimizer = Optimizer;
- },{"../doc":49,"../globals":52,"../serialization":156}],151:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("../doc");
- var adadelta_optimizer_1 = require("./adadelta_optimizer");
- var adagrad_optimizer_1 = require("./adagrad_optimizer");
- var adam_optimizer_1 = require("./adam_optimizer");
- var adamax_optimizer_1 = require("./adamax_optimizer");
- var momentum_optimizer_1 = require("./momentum_optimizer");
- var rmsprop_optimizer_1 = require("./rmsprop_optimizer");
- var sgd_optimizer_1 = require("./sgd_optimizer");
- var OptimizerConstructors = (function () {
- function OptimizerConstructors() {
- }
- OptimizerConstructors.sgd = function (learningRate) {
- return new sgd_optimizer_1.SGDOptimizer(learningRate);
- };
- OptimizerConstructors.momentum = function (learningRate, momentum, useNesterov) {
- if (useNesterov === void 0) { useNesterov = false; }
- return new momentum_optimizer_1.MomentumOptimizer(learningRate, momentum, useNesterov);
- };
- OptimizerConstructors.rmsprop = function (learningRate, decay, momentum, epsilon, centered) {
- if (decay === void 0) { decay = .9; }
- if (momentum === void 0) { momentum = 0.0; }
- if (epsilon === void 0) { epsilon = null; }
- if (centered === void 0) { centered = false; }
- return new rmsprop_optimizer_1.RMSPropOptimizer(learningRate, decay, momentum, epsilon, centered);
- };
- OptimizerConstructors.adam = function (learningRate, beta1, beta2, epsilon) {
- if (learningRate === void 0) { learningRate = 0.001; }
- if (beta1 === void 0) { beta1 = 0.9; }
- if (beta2 === void 0) { beta2 = 0.999; }
- if (epsilon === void 0) { epsilon = null; }
- return new adam_optimizer_1.AdamOptimizer(learningRate, beta1, beta2, epsilon);
- };
- OptimizerConstructors.adadelta = function (learningRate, rho, epsilon) {
- if (learningRate === void 0) { learningRate = .001; }
- if (rho === void 0) { rho = .95; }
- if (epsilon === void 0) { epsilon = null; }
- return new adadelta_optimizer_1.AdadeltaOptimizer(learningRate, rho, epsilon);
- };
- OptimizerConstructors.adamax = function (learningRate, beta1, beta2, epsilon, decay) {
- if (learningRate === void 0) { learningRate = 0.002; }
- if (beta1 === void 0) { beta1 = 0.9; }
- if (beta2 === void 0) { beta2 = 0.999; }
- if (epsilon === void 0) { epsilon = null; }
- if (decay === void 0) { decay = 0.0; }
- return new adamax_optimizer_1.AdamaxOptimizer(learningRate, beta1, beta2, epsilon, decay);
- };
- OptimizerConstructors.adagrad = function (learningRate, initialAccumulatorValue) {
- if (initialAccumulatorValue === void 0) { initialAccumulatorValue = 0.1; }
- return new adagrad_optimizer_1.AdagradOptimizer(learningRate, initialAccumulatorValue);
- };
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' })
- ], OptimizerConstructors, "sgd", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' })
- ], OptimizerConstructors, "momentum", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' })
- ], OptimizerConstructors, "rmsprop", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' })
- ], OptimizerConstructors, "adam", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' })
- ], OptimizerConstructors, "adadelta", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' })
- ], OptimizerConstructors, "adamax", null);
- __decorate([
- doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' })
- ], OptimizerConstructors, "adagrad", null);
- return OptimizerConstructors;
- }());
- exports.OptimizerConstructors = OptimizerConstructors;
- },{"../doc":49,"./adadelta_optimizer":145,"./adagrad_optimizer":146,"./adam_optimizer":147,"./adamax_optimizer":148,"./momentum_optimizer":149,"./rmsprop_optimizer":153,"./sgd_optimizer":154}],152:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../environment");
- var DEFAULT_FLOAT32_EPSILON = 1e-8;
- var DEFAULT_FLOAT16_EPSILON = 1e-4;
- function getOptimizerDefaultEpsilonValue() {
- if (environment_1.ENV.get('WEBGL_RENDER_FLOAT32_ENABLED')) {
- return DEFAULT_FLOAT32_EPSILON;
- }
- return DEFAULT_FLOAT16_EPSILON;
- }
- exports.getOptimizerDefaultEpsilonValue = getOptimizerDefaultEpsilonValue;
- },{"../environment":51}],153:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../environment");
- var globals_1 = require("../globals");
- var ops_1 = require("../ops/ops");
- var serialization_1 = require("../serialization");
- var optimizer_1 = require("./optimizer");
- var optimizer_utils = require("./optimizer_utils");
- var RMSPropOptimizer = (function (_super) {
- __extends(RMSPropOptimizer, _super);
- function RMSPropOptimizer(learningRate, decay, momentum, epsilon, centered) {
- if (decay === void 0) { decay = 0.9; }
- if (momentum === void 0) { momentum = 0.0; }
- if (epsilon === void 0) { epsilon = null; }
- if (centered === void 0) { centered = false; }
- var _this = _super.call(this) || this;
- _this.learningRate = learningRate;
- _this.decay = decay;
- _this.momentum = momentum;
- _this.epsilon = epsilon;
- _this.accumulatedMeanSquares = {};
- _this.accumulatedMeanGrads = {};
- _this.accumulatedMoments = {};
- _this.c = globals_1.keep(ops_1.scalar(learningRate));
- _this.decayScalar = globals_1.keep(ops_1.scalar(decay));
- _this.momentumScalar = globals_1.keep(ops_1.scalar(momentum));
- _this.oneMinusDecay = globals_1.keep(ops_1.scalar(1 - decay));
- _this.centered = centered;
- if (epsilon === null) {
- epsilon = optimizer_utils.getOptimizerDefaultEpsilonValue();
- }
- _this.epsilonScalar = globals_1.keep(ops_1.scalar(epsilon));
- return _this;
- }
- RMSPropOptimizer.prototype.applyGradients = function (variableGradients) {
- var _this = this;
- var _loop_1 = function (variableName) {
- var value = environment_1.ENV.engine.registeredVariables[variableName];
- if (this_1.accumulatedMeanSquares[variableName] == null) {
- var trainable_1 = false;
- globals_1.tidy(function () {
- _this.accumulatedMeanSquares[variableName] =
- ops_1.zerosLike(value).variable(trainable_1);
- });
- }
- if (this_1.accumulatedMeanGrads[variableName] == null && this_1.centered) {
- var trainable_2 = false;
- globals_1.tidy(function () {
- _this.accumulatedMeanGrads[variableName] =
- ops_1.zerosLike(value).variable(trainable_2);
- });
- }
- if (this_1.accumulatedMoments[variableName] == null) {
- var trainable_3 = false;
- globals_1.tidy(function () {
- _this.accumulatedMoments[variableName] =
- ops_1.zerosLike(value).variable(trainable_3);
- });
- }
- var accumulatedMeanSquare = this_1.accumulatedMeanSquares[variableName];
- var accumulatedMeanGrad = this_1.accumulatedMeanGrads[variableName];
- var accumulatedMoments = this_1.accumulatedMoments[variableName];
- var gradient = variableGradients[variableName];
- globals_1.tidy(function () {
- var newAccumulatedMeanSquare = _this.decayScalar.mul(accumulatedMeanSquare)
- .add(_this.oneMinusDecay.mul(gradient.square()));
- if (_this.centered) {
- var newAccumulatedMeanGrad = _this.decayScalar.mul(accumulatedMeanGrad)
- .add(_this.oneMinusDecay.mul(gradient));
- var newAccumulatedMoments = _this.momentumScalar.mul(accumulatedMoments)
- .add(_this.c.mul(gradient).div(newAccumulatedMeanSquare
- .sub(newAccumulatedMeanGrad.square().add(_this.epsilonScalar))
- .sqrt()));
- _this.accumulatedMeanSquares[variableName].assign(newAccumulatedMeanSquare);
- _this.accumulatedMeanGrads[variableName].assign(newAccumulatedMeanGrad);
- _this.accumulatedMoments[variableName].assign(newAccumulatedMoments);
- var newValue = value.sub(newAccumulatedMoments);
- value.assign(newValue);
- }
- else {
- var newAccumulatedMeanSquare_1 = _this.decayScalar.mul(accumulatedMeanSquare)
- .add(_this.oneMinusDecay.mul(gradient.square()));
- var newAccumulatedMoments = _this.momentumScalar.mul(accumulatedMoments)
- .add(_this.c.mul(gradient).div(newAccumulatedMeanSquare_1.add(_this.epsilonScalar).sqrt()));
- _this.accumulatedMeanSquares[variableName].assign(newAccumulatedMeanSquare_1);
- _this.accumulatedMoments[variableName].assign(newAccumulatedMoments);
- var newValue = value.sub(newAccumulatedMoments);
- value.assign(newValue);
- }
- });
- };
- var this_1 = this;
- for (var variableName in variableGradients) {
- _loop_1(variableName);
- }
- };
- RMSPropOptimizer.prototype.dispose = function () {
- var _this = this;
- this.c.dispose();
- this.epsilonScalar.dispose();
- this.decayScalar.dispose();
- this.momentumScalar.dispose();
- this.oneMinusDecay.dispose();
- if (this.accumulatedMeanSquares != null) {
- Object.keys(this.accumulatedMeanSquares)
- .forEach(function (name) { return _this.accumulatedMeanSquares[name].dispose(); });
- }
- if (this.accumulatedMeanGrads != null && this.centered) {
- Object.keys(this.accumulatedMeanGrads)
- .forEach(function (name) { return _this.accumulatedMeanGrads[name].dispose(); });
- }
- if (this.accumulatedMoments != null) {
- Object.keys(this.accumulatedMoments)
- .forEach(function (name) { return _this.accumulatedMoments[name].dispose(); });
- }
- };
- RMSPropOptimizer.prototype.getConfig = function () {
- return {
- learningRate: this.learningRate,
- decay: this.decay,
- momentum: this.momentum,
- epsilon: this.epsilon,
- centered: this.centered
- };
- };
- RMSPropOptimizer.fromConfig = function (cls, config) {
- return new cls(config.learningRate, config.decay, config.momentum, config.epsilon, config.centered);
- };
- RMSPropOptimizer.className = 'RMSPropOptimizer';
- return RMSPropOptimizer;
- }(optimizer_1.Optimizer));
- exports.RMSPropOptimizer = RMSPropOptimizer;
- serialization_1.SerializationMap.register(RMSPropOptimizer);
- },{"../environment":51,"../globals":52,"../ops/ops":129,"../serialization":156,"./optimizer":150,"./optimizer_utils":152}],154:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("../environment");
- var globals_1 = require("../globals");
- var ops_1 = require("../ops/ops");
- var serialization_1 = require("../serialization");
- var optimizer_1 = require("./optimizer");
- var SGDOptimizer = (function (_super) {
- __extends(SGDOptimizer, _super);
- function SGDOptimizer(learningRate) {
- var _this = _super.call(this) || this;
- _this.learningRate = learningRate;
- _this.setLearningRate(learningRate);
- return _this;
- }
- SGDOptimizer.prototype.applyGradients = function (variableGradients) {
- var _this = this;
- var varNames = Object.keys(variableGradients);
- varNames.forEach(function (varName) {
- var gradient = variableGradients[varName];
- var value = environment_1.ENV.engine.registeredVariables[varName];
- globals_1.tidy(function () {
- var newValue = _this.c.mul(gradient).add(value);
- value.assign(newValue);
- });
- });
- };
- SGDOptimizer.prototype.setLearningRate = function (learningRate) {
- this.learningRate = learningRate;
- if (this.c != null) {
- this.c.dispose();
- }
- this.c = globals_1.keep(ops_1.scalar(-learningRate));
- };
- SGDOptimizer.prototype.dispose = function () {
- this.c.dispose();
- };
- SGDOptimizer.prototype.getConfig = function () {
- return { learningRate: this.learningRate };
- };
- SGDOptimizer.fromConfig = function (cls, config) {
- return new cls(config.learningRate);
- };
- SGDOptimizer.className = 'SGDOptimizer';
- return SGDOptimizer;
- }(optimizer_1.Optimizer));
- exports.SGDOptimizer = SGDOptimizer;
- serialization_1.SerializationMap.register(SGDOptimizer);
- },{"../environment":51,"../globals":52,"../ops/ops":129,"../serialization":156,"./optimizer":150}],155:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var util = require("./util");
- var Profiler = (function () {
- function Profiler(backendTimer, logger) {
- this.backendTimer = backendTimer;
- this.logger = logger;
- if (logger == null) {
- this.logger = new Logger();
- }
- }
- Profiler.prototype.profileKernel = function (name, f) {
- var _this = this;
- var result;
- var holdResultWrapperFn = function () {
- result = f();
- };
- var timer = this.backendTimer.time(holdResultWrapperFn);
- var vals = result.dataSync();
- util.checkForNaN(vals, result.dtype, name);
- timer.then(function (timing) {
- _this.logger.logKernelProfile(name, result, vals, timing.kernelMs);
- });
- return result;
- };
- return Profiler;
- }());
- exports.Profiler = Profiler;
- var Logger = (function () {
- function Logger() {
- }
- Logger.prototype.logKernelProfile = function (name, result, vals, timeMs) {
- var time = util.rightPad(timeMs + "ms", 9);
- var paddedName = util.rightPad(name, 25);
- var rank = result.rank;
- var size = result.size;
- var shape = util.rightPad(result.shape.toString(), 14);
- console.log("%c" + paddedName + "\t%c" + time + "\t%c" + rank + "D " + shape + "\t%c" + size, 'font-weight:bold', 'color:red', 'color:blue', 'color: orange');
- };
- return Logger;
- }());
- exports.Logger = Logger;
- },{"./util":164}],156:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var Serializable = (function () {
- function Serializable() {
- }
- Serializable.prototype.getClassName = function () {
- return this.constructor
- .className;
- };
- Serializable.fromConfig = function (cls, config) {
- return new cls(config);
- };
- return Serializable;
- }());
- exports.Serializable = Serializable;
- var SerializationMap = (function () {
- function SerializationMap() {
- this.classNameMap = {};
- }
- SerializationMap.getMap = function () {
- if (SerializationMap.instance == null) {
- SerializationMap.instance = new SerializationMap();
- }
- return SerializationMap.instance;
- };
- SerializationMap.register = function (cls) {
- this.getMap().classNameMap[cls.className] = [cls, cls.fromConfig];
- };
- return SerializationMap;
- }());
- exports.SerializationMap = SerializationMap;
- },{}],157:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var util = require("./util");
- function getFilteredNodesXToY(tape, xs, y) {
- var tensorsFromX = {};
- var nodesFromX = {};
- for (var i = 0; i < xs.length; i++) {
- tensorsFromX[xs[i].id] = true;
- }
- for (var i = 0; i < tape.length; i++) {
- var node = tape[i];
- var nodeInputs = node.inputs;
- for (var inputName in nodeInputs) {
- var input = nodeInputs[inputName];
- var anyInputFromX = false;
- for (var j = 0; j < xs.length; j++) {
- if (tensorsFromX[input.id]) {
- tensorsFromX[node.output.id] = true;
- anyInputFromX = true;
- nodesFromX[node.id] = true;
- break;
- }
- }
- if (anyInputFromX) {
- break;
- }
- }
- }
- var tensorsLeadToY = {};
- tensorsLeadToY[y.id] = true;
- var nodesToY = {};
- for (var i = tape.length - 1; i >= 0; i--) {
- var node = tape[i];
- var nodeInputs = node.inputs;
- var outputs = [];
- outputs.push(node.output);
- for (var j = 0; j < outputs.length; j++) {
- if (tensorsLeadToY[outputs[j].id]) {
- for (var inputName in nodeInputs) {
- tensorsLeadToY[nodeInputs[inputName].id] = true;
- nodesToY[node.id] = true;
- }
- break;
- }
- }
- }
- var filteredTape = [];
- for (var i = 0; i < tape.length; i++) {
- var node = tape[i];
- if (nodesFromX[node.id] && nodesToY[node.id]) {
- var prunedInputs = {};
- for (var inputName in node.inputs) {
- var nodeInput = node.inputs[inputName];
- if (tensorsFromX[nodeInput.id]) {
- prunedInputs[inputName] = nodeInput;
- }
- }
- var prunedNode = Object.assign({}, node);
- prunedNode.inputs = prunedInputs;
- prunedNode.output = node.output;
- filteredTape.push(prunedNode);
- }
- }
- return filteredTape;
- }
- exports.getFilteredNodesXToY = getFilteredNodesXToY;
- function backpropagateGradients(tensorAccumulatedGradientMap, filteredTape) {
- for (var i = filteredTape.length - 1; i >= 0; i--) {
- var node = filteredTape[i];
- var dy = tensorAccumulatedGradientMap[node.output.id];
- if (node.gradient == null) {
- throw new Error("Cannot compute gradient: gradient function not found " +
- ("for " + node.name + "."));
- }
- var inputGradients = node.gradient(dy);
- for (var inputName in node.inputs) {
- if (!(inputName in inputGradients)) {
- throw new Error("Cannot backprop through input " + inputName + ". " +
- ("Available gradients found: " + Object.keys(inputGradients) + "."));
- }
- var dx = inputGradients[inputName]();
- var x = node.inputs[inputName];
- if (!util.arraysEqual(dx.shape, x.shape)) {
- throw new Error("Error in gradient for op " + node.name + ". The gradient of input " +
- ("'" + inputName + "' has shape '" + dx.shape + "', which does not match ") +
- ("the shape of the input '" + x.shape + "'"));
- }
- if (tensorAccumulatedGradientMap[x.id] == null) {
- tensorAccumulatedGradientMap[x.id] = dx;
- }
- else {
- var curGradient = tensorAccumulatedGradientMap[x.id];
- tensorAccumulatedGradientMap[x.id] = curGradient.add(dx);
- curGradient.dispose();
- }
- }
- }
- }
- exports.backpropagateGradients = backpropagateGradients;
- },{"./util":164}],158:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("./doc");
- var environment_1 = require("./environment");
- var ops = require("./ops/ops");
- var tensor_util = require("./tensor_util");
- var util = require("./util");
- var TensorBuffer = (function () {
- function TensorBuffer(shape, dtype, values) {
- this.dtype = dtype;
- if (values != null) {
- var n = values.length;
- var size = util.sizeFromShape(shape);
- util.assert(n === size, "Length of values '" + n + "' does not match the size " +
- ("inferred by the shape '" + size + "'"));
- }
- this.shape = shape.slice();
- this.values =
- values || util.getTypedArrayFromDType(dtype, util.sizeFromShape(shape));
- this.strides = computeStrides(shape);
- this.size = util.sizeFromShape(shape);
- }
- TensorBuffer.prototype.set = function (value) {
- var locs = [];
- for (var _i = 1; _i < arguments.length; _i++) {
- locs[_i - 1] = arguments[_i];
- }
- if (locs.length === 0) {
- locs = [0];
- }
- util.assert(locs.length === this.rank, "The number of provided coordinates (" + locs.length + ") must " +
- ("match the rank (" + this.rank + ")"));
- var index = this.locToIndex(locs);
- this.values[index] = value;
- };
- TensorBuffer.prototype.get = function () {
- var locs = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- locs[_i] = arguments[_i];
- }
- if (locs.length === 0) {
- locs = [0];
- }
- var index = locs[locs.length - 1];
- for (var i = 0; i < locs.length - 1; ++i) {
- index += this.strides[i] * locs[i];
- }
- return this.values[index];
- };
- TensorBuffer.prototype.locToIndex = function (locs) {
- if (this.rank === 0) {
- return 0;
- }
- else if (this.rank === 1) {
- return locs[0];
- }
- var index = locs[locs.length - 1];
- for (var i = 0; i < locs.length - 1; ++i) {
- index += this.strides[i] * locs[i];
- }
- return index;
- };
- TensorBuffer.prototype.indexToLoc = function (index) {
- if (this.rank === 0) {
- return [];
- }
- else if (this.rank === 1) {
- return [index];
- }
- var locs = new Array(this.shape.length);
- for (var i = 0; i < locs.length - 1; ++i) {
- locs[i] = Math.floor(index / this.strides[i]);
- index -= locs[i] * this.strides[i];
- }
- locs[locs.length - 1] = index;
- return locs;
- };
- Object.defineProperty(TensorBuffer.prototype, "rank", {
- get: function () {
- return this.shape.length;
- },
- enumerable: true,
- configurable: true
- });
- TensorBuffer.prototype.toTensor = function () {
- return Tensor.make(this.shape, { values: this.values }, this.dtype);
- };
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], TensorBuffer.prototype, "set", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], TensorBuffer.prototype, "get", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], TensorBuffer.prototype, "toTensor", null);
- TensorBuffer = __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], TensorBuffer);
- return TensorBuffer;
- }());
- exports.TensorBuffer = TensorBuffer;
- var Tensor = (function () {
- function Tensor(shape, dtype, values, dataId) {
- this.isDisposedInternal = false;
- this.size = util.sizeFromShape(shape);
- if (values != null) {
- util.assert(this.size === values.length, "Constructing tensor of shape (" + this.size + ") should match the " +
- ("length of values (" + values.length + ")"));
- }
- this.shape = shape.slice();
- this.dtype = dtype || 'float32';
- this.strides = computeStrides(shape);
- this.dataId = dataId != null ? dataId : {};
- this.id = Tensor_1.nextId++;
- this.rankType = (this.rank < 5 ? this.rank.toString() : 'higher');
- environment_1.ENV.engine.registerTensor(this);
- if (values != null) {
- environment_1.ENV.engine.write(this.dataId, values);
- }
- }
- Tensor_1 = Tensor;
- Tensor.make = function (shape, data, dtype) {
- return new Tensor_1(shape, dtype, data.values, data.dataId);
- };
- Tensor.prototype.flatten = function () {
- this.throwIfDisposed();
- return this.as1D();
- };
- Tensor.prototype.asScalar = function () {
- this.throwIfDisposed();
- util.assert(this.size === 1, 'The array must have only 1 element.');
- return this.reshape([]);
- };
- Tensor.prototype.as1D = function () {
- this.throwIfDisposed();
- return this.reshape([this.size]);
- };
- Tensor.prototype.as2D = function (rows, columns) {
- this.throwIfDisposed();
- return this.reshape([rows, columns]);
- };
- Tensor.prototype.as3D = function (rows, columns, depth) {
- this.throwIfDisposed();
- return this.reshape([rows, columns, depth]);
- };
- Tensor.prototype.as4D = function (rows, columns, depth, depth2) {
- this.throwIfDisposed();
- return this.reshape([rows, columns, depth, depth2]);
- };
- Tensor.prototype.asType = function (dtype) {
- this.throwIfDisposed();
- return ops.cast(this, dtype);
- };
- Object.defineProperty(Tensor.prototype, "rank", {
- get: function () {
- return this.shape.length;
- },
- enumerable: true,
- configurable: true
- });
- Tensor.prototype.get = function () {
- var locs = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- locs[_i] = arguments[_i];
- }
- util.assert(locs.length === this.rank, 'Number of coordinates in get() must match the rank of the tensor');
- this.throwIfDisposed();
- if (locs.length === 0) {
- locs = [0];
- }
- var index = locs[locs.length - 1];
- for (var i = 0; i < locs.length - 1; ++i) {
- index += this.strides[i] * locs[i];
- }
- return this.dataSync()[index];
- };
- Tensor.prototype.buffer = function () {
- return ops.buffer(this.shape, this.dtype, this.dataSync());
- };
- Tensor.prototype.data = function () {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- this.throwIfDisposed();
- return [2, environment_1.ENV.engine.read(this.dataId)];
- });
- });
- };
- Tensor.prototype.dataSync = function () {
- this.throwIfDisposed();
- return environment_1.ENV.engine.readSync(this.dataId);
- };
- Tensor.prototype.dispose = function () {
- if (this.isDisposed) {
- return;
- }
- environment_1.ENV.engine.disposeTensor(this);
- this.isDisposedInternal = true;
- };
- Object.defineProperty(Tensor.prototype, "isDisposed", {
- get: function () {
- return this.isDisposedInternal;
- },
- enumerable: true,
- configurable: true
- });
- Tensor.prototype.throwIfDisposed = function () {
- if (this.isDisposed) {
- throw new Error("Tensor is disposed.");
- }
- };
- Tensor.prototype.toFloat = function () {
- return this.asType('float32');
- };
- Tensor.prototype.toInt = function () {
- return this.asType('int32');
- };
- Tensor.prototype.toBool = function () {
- return this.asType('bool');
- };
- Tensor.prototype.print = function (verbose) {
- if (verbose === void 0) { verbose = false; }
- return ops.print(this, verbose);
- };
- Tensor.prototype.reshape = function (newShape) {
- this.throwIfDisposed();
- return ops.reshape(this, newShape);
- };
- Tensor.prototype.reshapeAs = function (x) {
- this.throwIfDisposed();
- return this.reshape(x.shape);
- };
- Tensor.prototype.expandDims = function (axis) {
- if (axis === void 0) { axis = 0; }
- return ops.expandDims(this, axis);
- };
- Tensor.prototype.cumsum = function (axis, exclusive, reverse) {
- if (axis === void 0) { axis = 0; }
- if (exclusive === void 0) { exclusive = false; }
- if (reverse === void 0) { reverse = false; }
- return ops.cumsum(this, axis, exclusive, reverse);
- };
- Tensor.prototype.squeeze = function (axis) {
- this.throwIfDisposed();
- return ops.squeeze(this, axis);
- };
- Tensor.prototype.clone = function () {
- this.throwIfDisposed();
- return ops.clone(this);
- };
- Tensor.prototype.toString = function (verbose) {
- if (verbose === void 0) { verbose = false; }
- return tensor_util.tensorToString(this, verbose);
- };
- Tensor.prototype.tile = function (reps) {
- this.throwIfDisposed();
- return ops.tile(this, reps);
- };
- Tensor.prototype.gather = function (indices, axis) {
- if (axis === void 0) { axis = 0; }
- this.throwIfDisposed();
- return ops.gather(this, indices, axis);
- };
- Tensor.prototype.matMul = function (b, transposeA, transposeB) {
- if (transposeA === void 0) { transposeA = false; }
- if (transposeB === void 0) { transposeB = false; }
- this.throwIfDisposed();
- return ops.matMul(this, b, transposeA, transposeB);
- };
- Tensor.prototype.dot = function (b) {
- this.throwIfDisposed();
- return ops.dot(this, b);
- };
- Tensor.prototype.norm = function (ord, axis, keepDims) {
- if (ord === void 0) { ord = 'euclidean'; }
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- this.throwIfDisposed();
- return ops.norm(this, ord, axis, keepDims);
- };
- Tensor.prototype.slice = function (begin, size) {
- this.throwIfDisposed();
- return ops.slice(this, begin, size);
- };
- Tensor.prototype.reverse = function (axis) {
- this.throwIfDisposed();
- return ops.reverse(this, axis);
- };
- Tensor.prototype.concat = function (x, axis) {
- if (axis === void 0) { axis = 0; }
- this.throwIfDisposed();
- return ops.concat([this, x], axis);
- };
- Tensor.prototype.stack = function (x, axis) {
- if (axis === void 0) { axis = 0; }
- return ops.stack([this, x], axis);
- };
- Tensor.prototype.unstack = function (x, axis) {
- if (axis === void 0) { axis = 0; }
- return ops.unstack(this, axis);
- };
- Tensor.prototype.pad = function (paddings, constantValue) {
- if (constantValue === void 0) { constantValue = 0; }
- return ops.pad(this, paddings, constantValue);
- };
- Tensor.prototype.batchNormalization = function (mean, variance, varianceEpsilon, scale, offset) {
- if (varianceEpsilon === void 0) { varianceEpsilon = .001; }
- this.throwIfDisposed();
- return ops.batchNormalization(this, mean, variance, varianceEpsilon, scale, offset);
- };
- Tensor.prototype.all = function (axis, keepDims) {
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- this.throwIfDisposed();
- return ops.all(this, axis, keepDims);
- };
- Tensor.prototype.logSumExp = function (axis, keepDims) {
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- this.throwIfDisposed();
- return ops.logSumExp(this, axis, keepDims);
- };
- Tensor.prototype.sum = function (axis, keepDims) {
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- this.throwIfDisposed();
- return ops.sum(this, axis, keepDims);
- };
- Tensor.prototype.mean = function (axis, keepDims) {
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- this.throwIfDisposed();
- return ops.mean(this, axis, keepDims);
- };
- Tensor.prototype.min = function (axis, keepDims) {
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- this.throwIfDisposed();
- return ops.min(this, axis, keepDims);
- };
- Tensor.prototype.max = function (axis, keepDims) {
- if (axis === void 0) { axis = null; }
- if (keepDims === void 0) { keepDims = false; }
- this.throwIfDisposed();
- return ops.max(this, axis, keepDims);
- };
- Tensor.prototype.argMin = function (axis) {
- if (axis === void 0) { axis = null; }
- this.throwIfDisposed();
- return ops.argMin(this, axis);
- };
- Tensor.prototype.argMax = function (axis) {
- if (axis === void 0) { axis = null; }
- this.throwIfDisposed();
- return ops.argMax(this, axis);
- };
- Tensor.prototype.cast = function (dtype) {
- this.throwIfDisposed();
- return ops.cast(this, dtype);
- };
- Tensor.prototype.add = function (x) {
- this.throwIfDisposed();
- return ops.add(this, x);
- };
- Tensor.prototype.addStrict = function (x) {
- this.throwIfDisposed();
- return ops.addStrict(this, x);
- };
- Tensor.prototype.sub = function (x) {
- this.throwIfDisposed();
- return ops.sub(this, x);
- };
- Tensor.prototype.subStrict = function (x) {
- this.throwIfDisposed();
- return ops.subStrict(this, x);
- };
- Tensor.prototype.pow = function (exp) {
- this.throwIfDisposed();
- return ops.pow(this, exp);
- };
- Tensor.prototype.powStrict = function (exp) {
- this.throwIfDisposed();
- return ops.powStrict(this, exp);
- };
- Tensor.prototype.mul = function (x) {
- this.throwIfDisposed();
- return ops.mul(this, x);
- };
- Tensor.prototype.mulStrict = function (x) {
- this.throwIfDisposed();
- return ops.mulStrict(this, x);
- };
- Tensor.prototype.div = function (x) {
- this.throwIfDisposed();
- return ops.div(this, x);
- };
- Tensor.prototype.floorDiv = function (x) {
- this.throwIfDisposed();
- return ops.floorDiv(this, x);
- };
- Tensor.prototype.divStrict = function (x) {
- this.throwIfDisposed();
- return ops.divStrict(this, x);
- };
- Tensor.prototype.minimum = function (x) {
- this.throwIfDisposed();
- return ops.minimum(this, x);
- };
- Tensor.prototype.minimumStrict = function (x) {
- this.throwIfDisposed();
- return ops.minimumStrict(this, x);
- };
- Tensor.prototype.maximum = function (x) {
- this.throwIfDisposed();
- return ops.maximum(this, x);
- };
- Tensor.prototype.maximumStrict = function (x) {
- this.throwIfDisposed();
- return ops.maximumStrict(this, x);
- };
- Tensor.prototype.mod = function (x) {
- this.throwIfDisposed();
- return ops.mod(this, x);
- };
- Tensor.prototype.modStrict = function (x) {
- this.throwIfDisposed();
- return ops.modStrict(this, x);
- };
- Tensor.prototype.squaredDifference = function (x) {
- this.throwIfDisposed();
- return ops.squaredDifference(this, x);
- };
- Tensor.prototype.squaredDifferenceStrict = function (x) {
- this.throwIfDisposed();
- return ops.squaredDifferenceStrict(this, x);
- };
- Tensor.prototype.transpose = function (perm) {
- this.throwIfDisposed();
- return ops.transpose(this, perm);
- };
- Tensor.prototype.notEqual = function (x) {
- this.throwIfDisposed();
- return ops.notEqual(this, x);
- };
- Tensor.prototype.notEqualStrict = function (x) {
- this.throwIfDisposed();
- return ops.notEqualStrict(this, x);
- };
- Tensor.prototype.less = function (x) {
- this.throwIfDisposed();
- return ops.less(this, x);
- };
- Tensor.prototype.lessStrict = function (x) {
- this.throwIfDisposed();
- return ops.lessStrict(this, x);
- };
- Tensor.prototype.equal = function (x) {
- this.throwIfDisposed();
- return ops.equal(this, x);
- };
- Tensor.prototype.equalStrict = function (x) {
- this.throwIfDisposed();
- return ops.equalStrict(this, x);
- };
- Tensor.prototype.lessEqual = function (x) {
- this.throwIfDisposed();
- return ops.lessEqual(this, x);
- };
- Tensor.prototype.lessEqualStrict = function (x) {
- this.throwIfDisposed();
- return ops.lessEqualStrict(this, x);
- };
- Tensor.prototype.greater = function (x) {
- this.throwIfDisposed();
- return ops.greater(this, x);
- };
- Tensor.prototype.greaterStrict = function (x) {
- this.throwIfDisposed();
- return ops.greaterStrict(this, x);
- };
- Tensor.prototype.greaterEqual = function (x) {
- this.throwIfDisposed();
- return ops.greaterEqual(this, x);
- };
- Tensor.prototype.greaterEqualStrict = function (x) {
- this.throwIfDisposed();
- return ops.greaterEqualStrict(this, x);
- };
- Tensor.prototype.logicalAnd = function (x) {
- this.throwIfDisposed();
- return ops.logicalAnd(this, x);
- };
- Tensor.prototype.logicalOr = function (x) {
- this.throwIfDisposed();
- return ops.logicalOr(this, x);
- };
- Tensor.prototype.logicalNot = function () {
- this.throwIfDisposed();
- return ops.logicalNot(this);
- };
- Tensor.prototype.logicalXor = function (x) {
- this.throwIfDisposed();
- return ops.logicalXor(this, x);
- };
- Tensor.prototype.where = function (condition, x) {
- this.throwIfDisposed();
- return ops.where(condition, this, x);
- };
- Tensor.prototype.neg = function () {
- this.throwIfDisposed();
- return ops.neg(this);
- };
- Tensor.prototype.ceil = function () {
- this.throwIfDisposed();
- return ops.ceil(this);
- };
- Tensor.prototype.floor = function () {
- this.throwIfDisposed();
- return ops.floor(this);
- };
- Tensor.prototype.sign = function () {
- this.throwIfDisposed();
- return ops.sign(this);
- };
- Tensor.prototype.exp = function () {
- this.throwIfDisposed();
- return ops.exp(this);
- };
- Tensor.prototype.expm1 = function () {
- this.throwIfDisposed();
- return ops.expm1(this);
- };
- Tensor.prototype.log = function () {
- this.throwIfDisposed();
- return ops.log(this);
- };
- Tensor.prototype.log1p = function () {
- this.throwIfDisposed();
- return ops.log1p(this);
- };
- Tensor.prototype.sqrt = function () {
- this.throwIfDisposed();
- return ops.sqrt(this);
- };
- Tensor.prototype.rsqrt = function () {
- this.throwIfDisposed();
- return ops.rsqrt(this);
- };
- Tensor.prototype.square = function () {
- this.throwIfDisposed();
- return ops.square(this);
- };
- Tensor.prototype.reciprocal = function () {
- this.throwIfDisposed();
- return ops.reciprocal(this);
- };
- Tensor.prototype.abs = function () {
- this.throwIfDisposed();
- return ops.abs(this);
- };
- Tensor.prototype.clipByValue = function (min, max) {
- this.throwIfDisposed();
- return ops.clipByValue(this, min, max);
- };
- Tensor.prototype.relu = function () {
- this.throwIfDisposed();
- return ops.relu(this);
- };
- Tensor.prototype.elu = function () {
- this.throwIfDisposed();
- return ops.elu(this);
- };
- Tensor.prototype.selu = function () {
- this.throwIfDisposed();
- return ops.selu(this);
- };
- Tensor.prototype.leakyRelu = function (alpha) {
- if (alpha === void 0) { alpha = 0.2; }
- this.throwIfDisposed();
- return ops.leakyRelu(this, alpha);
- };
- Tensor.prototype.prelu = function (alpha) {
- this.throwIfDisposed();
- return ops.prelu(this, alpha);
- };
- Tensor.prototype.sigmoid = function () {
- this.throwIfDisposed();
- return ops.sigmoid(this);
- };
- Tensor.prototype.logSigmoid = function () {
- this.throwIfDisposed();
- return ops.logSigmoid(this);
- };
- Tensor.prototype.softplus = function () {
- this.throwIfDisposed();
- return ops.softplus(this);
- };
- Tensor.prototype.sin = function () {
- this.throwIfDisposed();
- return ops.sin(this);
- };
- Tensor.prototype.cos = function () {
- this.throwIfDisposed();
- return ops.cos(this);
- };
- Tensor.prototype.tan = function () {
- this.throwIfDisposed();
- return ops.tan(this);
- };
- Tensor.prototype.asin = function () {
- this.throwIfDisposed();
- return ops.asin(this);
- };
- Tensor.prototype.acos = function () {
- this.throwIfDisposed();
- return ops.acos(this);
- };
- Tensor.prototype.atan = function () {
- this.throwIfDisposed();
- return ops.atan(this);
- };
- Tensor.prototype.sinh = function () {
- this.throwIfDisposed();
- return ops.sinh(this);
- };
- Tensor.prototype.cosh = function () {
- this.throwIfDisposed();
- return ops.cosh(this);
- };
- Tensor.prototype.tanh = function () {
- this.throwIfDisposed();
- return ops.tanh(this);
- };
- Tensor.prototype.asinh = function () {
- this.throwIfDisposed();
- return ops.asinh(this);
- };
- Tensor.prototype.acosh = function () {
- this.throwIfDisposed();
- return ops.acosh(this);
- };
- Tensor.prototype.atanh = function () {
- this.throwIfDisposed();
- return ops.atanh(this);
- };
- Tensor.prototype.erf = function () {
- this.throwIfDisposed();
- return ops.erf(this);
- };
- Tensor.prototype.round = function () {
- this.throwIfDisposed();
- return ops.round(this);
- };
- Tensor.prototype.step = function (alpha) {
- if (alpha === void 0) { alpha = 0.0; }
- this.throwIfDisposed();
- return ops.step(this, alpha);
- };
- Tensor.prototype.softmax = function (dim) {
- if (dim === void 0) { dim = -1; }
- this.throwIfDisposed();
- return ops.softmax(this, dim);
- };
- Tensor.prototype.resizeBilinear = function (newShape2D, alignCorners) {
- if (alignCorners === void 0) { alignCorners = false; }
- this.throwIfDisposed();
- return ops.image.resizeBilinear(this, newShape2D, alignCorners);
- };
- Tensor.prototype.resizeNearestNeighbor = function (newShape2D, alignCorners) {
- if (alignCorners === void 0) { alignCorners = false; }
- this.throwIfDisposed();
- return ops.image.resizeNearestNeighbor(this, newShape2D, alignCorners);
- };
- Tensor.prototype.conv1d = function (filter, stride, pad, dataFormat, dilation, dimRoundingMode) {
- if (dataFormat === void 0) { dataFormat = 'NWC'; }
- if (dilation === void 0) { dilation = 1; }
- this.throwIfDisposed();
- return ops.conv1d(this, filter, stride, pad, dataFormat, dilation, dimRoundingMode);
- };
- Tensor.prototype.conv2d = function (filter, strides, pad, dataFormat, dilations, dimRoundingMode) {
- if (dataFormat === void 0) { dataFormat = 'NHWC'; }
- if (dilations === void 0) { dilations = [1, 1]; }
- this.throwIfDisposed();
- return ops.conv2d(this, filter, strides, pad, dataFormat, dilations, dimRoundingMode);
- };
- Tensor.prototype.conv2dTranspose = function (filter, outputShape, strides, pad, dimRoundingMode) {
- this.throwIfDisposed();
- return ops.conv2dTranspose(this, filter, outputShape, strides, pad, dimRoundingMode);
- };
- Tensor.prototype.depthwiseConv2D = function (filter, strides, pad, dataFormat, dilations, dimRoundingMode) {
- if (dataFormat === void 0) { dataFormat = 'NHWC'; }
- if (dilations === void 0) { dilations = [1, 1]; }
- this.throwIfDisposed();
- return ops.depthwiseConv2d(this, filter, strides, pad, dataFormat, dilations, dimRoundingMode);
- };
- Tensor.prototype.avgPool = function (filterSize, strides, pad, dimRoundingMode) {
- this.throwIfDisposed();
- return ops.avgPool(this, filterSize, strides, pad, dimRoundingMode);
- };
- Tensor.prototype.maxPool = function (filterSize, strides, pad, dimRoundingMode) {
- this.throwIfDisposed();
- return ops.maxPool(this, filterSize, strides, pad, dimRoundingMode);
- };
- Tensor.prototype.localResponseNormalization = function (radius, bias, alpha, beta) {
- if (radius === void 0) { radius = 5; }
- if (bias === void 0) { bias = 1; }
- if (alpha === void 0) { alpha = 1; }
- if (beta === void 0) { beta = 0.5; }
- return ops.localResponseNormalization(this, radius, bias, alpha, beta);
- };
- Tensor.prototype.variable = function (trainable, name, dtype) {
- if (trainable === void 0) { trainable = true; }
- this.throwIfDisposed();
- return Variable.variable(this, trainable, name, dtype);
- };
- Tensor.prototype.unsortedSegmentSum = function (segmentIds, numSegments) {
- this.throwIfDisposed();
- return ops.unsortedSegmentSum(this, segmentIds, numSegments);
- };
- Tensor.nextId = 0;
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "flatten", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "asScalar", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "as1D", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "as2D", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "as3D", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "as4D", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "asType", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "buffer", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "data", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "dataSync", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "dispose", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "toFloat", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "toInt", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "toBool", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "print", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "reshape", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "reshapeAs", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "expandDims", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "cumsum", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "squeeze", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "clone", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor.prototype, "toString", null);
- Tensor = Tensor_1 = __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Tensor);
- return Tensor;
- var Tensor_1;
- }());
- exports.Tensor = Tensor;
- var Variable = (function (_super) {
- __extends(Variable, _super);
- function Variable(initialValue, trainable, name) {
- if (trainable === void 0) { trainable = true; }
- var _this = _super.call(this, initialValue.shape, initialValue.dtype, null, initialValue.dataId) || this;
- _this.trainable = trainable;
- _this.name = name;
- if (_this.name == null) {
- _this.name = Variable_1.nextVarId.toString();
- Variable_1.nextVarId++;
- }
- environment_1.ENV.engine.registerVariable(_this);
- return _this;
- }
- Variable_1 = Variable;
- Variable.variable = function (initialValue, trainable, name, dtype) {
- if (trainable === void 0) { trainable = true; }
- if (dtype != null && dtype !== initialValue.dtype) {
- initialValue = initialValue.asType(dtype);
- }
- return new Variable_1(initialValue, trainable, name);
- };
- Variable.prototype.assign = function (newValue) {
- if (newValue.dtype !== this.dtype) {
- throw new Error("dtype of the new value (" + newValue.dtype + ") and " +
- ("previous value (" + this.dtype + ") must match"));
- }
- if (!util.arraysEqual(newValue.shape, this.shape)) {
- throw new Error("shape of the new value (" + newValue.shape + ") and " +
- ("previous value (" + this.shape + ") must match"));
- }
- environment_1.ENV.engine.disposeTensor(this);
- this.dataId = newValue.dataId;
- environment_1.ENV.engine.registerTensor(this);
- };
- Variable.nextVarId = 0;
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Variable.prototype, "assign", null);
- __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })
- ], Variable, "variable", null);
- Variable = Variable_1 = __decorate([
- doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })
- ], Variable);
- return Variable;
- var Variable_1;
- }(Tensor));
- exports.Variable = Variable;
- var variable = Variable.variable;
- exports.variable = variable;
- function computeStrides(shape) {
- var rank = shape.length;
- if (rank < 2) {
- return [];
- }
- var strides = new Array(rank - 1);
- strides[rank - 2] = shape[rank - 1];
- for (var i = rank - 3; i >= 0; --i) {
- strides[i] = strides[i + 1] * shape[i + 1];
- }
- return strides;
- }
- },{"./doc":49,"./environment":51,"./ops/ops":129,"./tensor_util":159,"./util":164}],159:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var util = require("./util");
- var FORMAT_LIMIT_NUM_VALS = 20;
- var FORMAT_NUM_FIRST_LAST_VALS = 3;
- var FORMAT_NUM_SIG_DIGITS = 7;
- function tensorToString(t, verbose) {
- var vals = t.dataSync();
- var padPerCol = computeMaxSizePerColumn(t);
- var valsLines = subTensorToString(vals, t.shape, t.strides, padPerCol);
- var lines = ['Tensor'];
- if (verbose) {
- lines.push(" dtype: " + t.dtype);
- lines.push(" rank: " + t.rank);
- lines.push(" shape: [" + t.shape + "]");
- lines.push(" values:");
- }
- lines.push(valsLines.map(function (l) { return ' ' + l; }).join('\n'));
- return lines.join('\n');
- }
- exports.tensorToString = tensorToString;
- function computeMaxSizePerColumn(t) {
- var vals = t.dataSync();
- var n = t.size;
- var numCols = t.strides[t.strides.length - 1];
- var padPerCol = new Array(numCols).fill(0);
- if (t.rank > 1) {
- for (var row = 0; row < n / numCols; row++) {
- var offset = row * numCols;
- for (var j = 0; j < numCols; j++) {
- padPerCol[j] =
- Math.max(padPerCol[j], valToString(vals[offset + j], 0).length);
- }
- }
- }
- return padPerCol;
- }
- function valToString(val, pad) {
- return util.rightPad(parseFloat(val.toFixed(FORMAT_NUM_SIG_DIGITS)).toString(), pad);
- }
- function subTensorToString(vals, shape, strides, padPerCol, isLast) {
- if (isLast === void 0) { isLast = true; }
- var size = shape[0];
- var rank = shape.length;
- if (rank === 0) {
- return [vals[0].toString()];
- }
- if (rank === 1) {
- if (size > FORMAT_LIMIT_NUM_VALS) {
- var firstVals = Array.from(vals.subarray(0, FORMAT_NUM_FIRST_LAST_VALS));
- var lastVals = Array.from(vals.subarray(size - FORMAT_NUM_FIRST_LAST_VALS, size));
- return [
- '[' + firstVals.map(function (x, i) { return valToString(x, padPerCol[i]); }).join(', ') +
- ', ..., ' +
- lastVals
- .map(function (x, i) { return valToString(x, padPerCol[size - FORMAT_NUM_FIRST_LAST_VALS + i]); })
- .join(', ') +
- ']'
- ];
- }
- return [
- '[' +
- Array.from(vals).map(function (x, i) { return valToString(x, padPerCol[i]); }).join(', ') +
- ']'
- ];
- }
- var subshape = shape.slice(1);
- var substrides = strides.slice(1);
- var stride = strides[0];
- var lines = [];
- if (size > FORMAT_LIMIT_NUM_VALS) {
- for (var i = 0; i < FORMAT_NUM_FIRST_LAST_VALS; i++) {
- var start = i * stride;
- var end = start + stride;
- lines.push.apply(lines, subTensorToString(vals.subarray(start, end), subshape, substrides, padPerCol, false));
- }
- lines.push('...');
- for (var i = size - FORMAT_NUM_FIRST_LAST_VALS; i < size; i++) {
- var start = i * stride;
- var end = start + stride;
- lines.push.apply(lines, subTensorToString(vals.subarray(start, end), subshape, substrides, padPerCol, i === size - 1));
- }
- }
- else {
- for (var i = 0; i < size; i++) {
- var start = i * stride;
- var end = start + stride;
- lines.push.apply(lines, subTensorToString(vals.subarray(start, end), subshape, substrides, padPerCol, i === size - 1));
- }
- }
- var sep = rank === 2 ? ',' : '';
- lines[0] = '[' + lines[0] + sep;
- for (var i = 1; i < lines.length - 1; i++) {
- lines[i] = ' ' + lines[i] + sep;
- }
- var newLineSep = ',\n';
- for (var i = 2; i < rank; i++) {
- newLineSep += '\n';
- }
- lines[lines.length - 1] =
- ' ' + lines[lines.length - 1] + ']' + (isLast ? '' : newLineSep);
- return lines;
- }
- },{"./util":164}],160:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var environment_1 = require("./environment");
- var tensor_1 = require("./tensor");
- var util = require("./util");
- exports.WEBGL_ENVS = [
- {
- 'BACKEND': 'test-webgl',
- 'WEBGL_RENDER_FLOAT32_ENABLED': true,
- 'WEBGL_DOWNLOAD_FLOAT_ENABLED': true,
- 'WEBGL_VERSION': 1
- },
- {
- 'BACKEND': 'test-webgl',
- 'WEBGL_RENDER_FLOAT32_ENABLED': true,
- 'WEBGL_DOWNLOAD_FLOAT_ENABLED': true,
- 'WEBGL_VERSION': 2
- }
- ];
- exports.CPU_ENVS = [{ 'BACKEND': 'test-cpu' }];
- exports.CHROME_CPU_ENVS = [{ 'BACKEND': 'test-cpu', 'IS_CHROME': true }];
- exports.NATIVE_ENV = {};
- exports.BROWSER_ENVS = exports.WEBGL_ENVS.concat(exports.CPU_ENVS);
- exports.ALL_ENVS = [exports.NATIVE_ENV].concat(exports.BROWSER_ENVS);
- function expectArraysClose(actual, expected, epsilon) {
- if (epsilon == null) {
- epsilon = environment_1.ENV.get('TEST_EPSILON');
- }
- if (!(actual instanceof tensor_1.Tensor) && !(expected instanceof tensor_1.Tensor)) {
- var aType = actual.constructor.name;
- var bType = expected.constructor.name;
- if (aType !== bType) {
- throw new Error("Arrays are of different type actual: " + aType + " " +
- ("vs expected: " + bType));
- }
- }
- else if (actual instanceof tensor_1.Tensor && expected instanceof tensor_1.Tensor) {
- if (actual.dtype !== expected.dtype) {
- throw new Error("Arrays are of different type actual: " + actual.dtype + " " +
- ("vs expected: " + expected.dtype + "."));
- }
- if (!util.arraysEqual(actual.shape, expected.shape)) {
- throw new Error("Arrays are of different shape actual: " + actual.shape + " " +
- ("vs expected: " + expected.shape + "."));
- }
- }
- var actualValues;
- var expectedValues;
- if (actual instanceof tensor_1.Tensor) {
- actualValues = actual.dataSync();
- }
- else {
- actualValues = actual;
- }
- if (expected instanceof tensor_1.Tensor) {
- expectedValues = expected.dataSync();
- }
- else {
- expectedValues = expected;
- }
- if (actualValues.length !== expectedValues.length) {
- throw new Error("Arrays have different lengths actual: " + actualValues.length + " vs " +
- ("expected: " + expectedValues.length + ".\n") +
- ("Actual: " + actualValues + ".\n") +
- ("Expected: " + expectedValues + "."));
- }
- for (var i = 0; i < expectedValues.length; ++i) {
- var a = actualValues[i];
- var e = expectedValues[i];
- if (!areClose(a, Number(e), epsilon)) {
- throw new Error("Arrays differ: actual[" + i + "] = " + a + ", expected[" + i + "] = " + e + ".\n" +
- ("Actual: " + actualValues + ".\n") +
- ("Expected: " + expectedValues + "."));
- }
- }
- }
- exports.expectArraysClose = expectArraysClose;
- function expectPromiseToFail(fn, done) {
- fn().then(function () { return done.fail(); }, function () { return done(); });
- }
- exports.expectPromiseToFail = expectPromiseToFail;
- function expectArraysEqual(actual, expected) {
- return expectArraysClose(actual, expected, 0);
- }
- exports.expectArraysEqual = expectArraysEqual;
- function expectNumbersClose(a, e, epsilon) {
- if (epsilon == null) {
- epsilon = environment_1.ENV.get('TEST_EPSILON');
- }
- if (!areClose(a, e, epsilon)) {
- throw new Error("Numbers differ: actual === " + a + ", expected === " + e);
- }
- }
- exports.expectNumbersClose = expectNumbersClose;
- function areClose(a, e, epsilon) {
- if (isNaN(a) && isNaN(e)) {
- return true;
- }
- if (isNaN(a) || isNaN(e) || Math.abs(a - e) > epsilon) {
- return false;
- }
- return true;
- }
- function expectValuesInRange(actual, low, high) {
- var actualVals;
- if (actual instanceof tensor_1.Tensor) {
- actualVals = actual.dataSync();
- }
- else {
- actualVals = actual;
- }
- for (var i = 0; i < actualVals.length; i++) {
- if (actualVals[i] < low || actualVals[i] > high) {
- throw new Error("Value out of range:" + actualVals[i] + " low: " + low + ", high: " + high);
- }
- }
- }
- exports.expectValuesInRange = expectValuesInRange;
- function expectArrayBuffersEqual(actual, expected) {
- expect(new Float32Array(actual)).toEqual(new Float32Array(expected));
- }
- exports.expectArrayBuffersEqual = expectArrayBuffersEqual;
- },{"./environment":51,"./tensor":158,"./util":164}],161:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var doc_1 = require("./doc");
- var environment_1 = require("./environment");
- var util_1 = require("./util");
- var Tracking = (function () {
- function Tracking() {
- }
- Tracking.tidy = function (nameOrFn, fn, gradMode) {
- if (gradMode === void 0) { gradMode = false; }
- var name = null;
- if (fn == null) {
- if (typeof nameOrFn !== 'function') {
- throw new Error('Please provide a function to tidy()');
- }
- fn = nameOrFn;
- }
- else {
- if (typeof nameOrFn !== 'string' && !(nameOrFn instanceof String)) {
- throw new Error('When calling with two arguments, the first argument ' +
- 'to tidy() must be a string');
- }
- if (typeof fn !== 'function') {
- throw new Error('When calling with two arguments, the 2nd argument ' +
- 'to tidy() must be a function');
- }
- name = nameOrFn;
- }
- environment_1.ENV.engine.startScope(name, gradMode);
- var result = fn();
- if (result instanceof Promise) {
- console.error('Cannot return a Promise inside of tidy.');
- }
- environment_1.ENV.engine.endScope(result, gradMode);
- return result;
- };
- Tracking.dispose = function (container) {
- var tensors = util_1.getTensorsInContainer(container);
- tensors.forEach(function (tensor) { return tensor.dispose(); });
- };
- Tracking.keep = function (result) {
- return environment_1.ENV.engine.keep(result);
- };
- Tracking.time = function (f) {
- return environment_1.ENV.engine.time(f);
- };
- __decorate([
- doc_1.doc({ heading: 'Performance', subheading: 'Memory' })
- ], Tracking, "tidy", null);
- __decorate([
- doc_1.doc({ heading: 'Performance', subheading: 'Memory' })
- ], Tracking, "dispose", null);
- __decorate([
- doc_1.doc({ heading: 'Performance', subheading: 'Memory' })
- ], Tracking, "keep", null);
- __decorate([
- doc_1.doc({ heading: 'Performance', subheading: 'Timing' })
- ], Tracking, "time", null);
- return Tracking;
- }());
- exports.Tracking = Tracking;
- },{"./doc":49,"./environment":51,"./util":164}],162:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var adadelta_optimizer_1 = require("./optimizers/adadelta_optimizer");
- var adagrad_optimizer_1 = require("./optimizers/adagrad_optimizer");
- var adam_optimizer_1 = require("./optimizers/adam_optimizer");
- var adamax_optimizer_1 = require("./optimizers/adamax_optimizer");
- var momentum_optimizer_1 = require("./optimizers/momentum_optimizer");
- var optimizer_constructors_1 = require("./optimizers/optimizer_constructors");
- var rmsprop_optimizer_1 = require("./optimizers/rmsprop_optimizer");
- var sgd_optimizer_1 = require("./optimizers/sgd_optimizer");
- [momentum_optimizer_1.MomentumOptimizer, sgd_optimizer_1.SGDOptimizer, adadelta_optimizer_1.AdadeltaOptimizer, adagrad_optimizer_1.AdagradOptimizer,
- rmsprop_optimizer_1.RMSPropOptimizer, adamax_optimizer_1.AdamaxOptimizer, adam_optimizer_1.AdamOptimizer];
- exports.train = {
- sgd: optimizer_constructors_1.OptimizerConstructors.sgd,
- momentum: optimizer_constructors_1.OptimizerConstructors.momentum,
- adadelta: optimizer_constructors_1.OptimizerConstructors.adadelta,
- adagrad: optimizer_constructors_1.OptimizerConstructors.adagrad,
- rmsprop: optimizer_constructors_1.OptimizerConstructors.rmsprop,
- adamax: optimizer_constructors_1.OptimizerConstructors.adamax,
- adam: optimizer_constructors_1.OptimizerConstructors.adam
- };
- },{"./optimizers/adadelta_optimizer":145,"./optimizers/adagrad_optimizer":146,"./optimizers/adam_optimizer":147,"./optimizers/adamax_optimizer":148,"./optimizers/momentum_optimizer":149,"./optimizers/optimizer_constructors":151,"./optimizers/rmsprop_optimizer":153,"./optimizers/sgd_optimizer":154}],163:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var DType;
- (function (DType) {
- DType["float32"] = "float32";
- DType["int32"] = "int32";
- DType["bool"] = "bool";
- })(DType = exports.DType || (exports.DType = {}));
- var Rank;
- (function (Rank) {
- Rank["R0"] = "R0";
- Rank["R1"] = "R1";
- Rank["R2"] = "R2";
- Rank["R3"] = "R3";
- Rank["R4"] = "R4";
- Rank["R5"] = "R5";
- Rank["R6"] = "R6";
- })(Rank = exports.Rank || (exports.Rank = {}));
- var UpcastInt32AndMap;
- (function (UpcastInt32AndMap) {
- UpcastInt32AndMap["float32"] = "float32";
- UpcastInt32AndMap["int32"] = "int32";
- UpcastInt32AndMap["bool"] = "int32";
- })(UpcastInt32AndMap || (UpcastInt32AndMap = {}));
- var UpcastBoolAndMap;
- (function (UpcastBoolAndMap) {
- UpcastBoolAndMap["float32"] = "float32";
- UpcastBoolAndMap["int32"] = "int32";
- UpcastBoolAndMap["bool"] = "bool";
- })(UpcastBoolAndMap || (UpcastBoolAndMap = {}));
- var UpcastFloat32AndMap;
- (function (UpcastFloat32AndMap) {
- UpcastFloat32AndMap["float32"] = "float32";
- UpcastFloat32AndMap["int32"] = "float32";
- UpcastFloat32AndMap["bool"] = "float32";
- })(UpcastFloat32AndMap || (UpcastFloat32AndMap = {}));
- var upcastTypeMap = {
- float32: UpcastFloat32AndMap,
- int32: UpcastInt32AndMap,
- bool: UpcastBoolAndMap
- };
- function upcastType(typeA, typeB) {
- return upcastTypeMap[typeA][typeB];
- }
- exports.upcastType = upcastType;
- function sumOutType(type) {
- return upcastType(type, 'int32');
- }
- exports.sumOutType = sumOutType;
- },{}],164:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tensor_1 = require("./tensor");
- function assertArgumentIsTensor(x, argName, functionName) {
- assert(x instanceof tensor_1.Tensor, "Argument '" + argName + "' passed to '" + functionName + "' must be a Tensor, " +
- ("but got " + typeof x + "."));
- }
- function assertArgumentsAreTensors(args, functionName) {
- var _loop_1 = function (argName) {
- var arg = args[argName];
- if (Array.isArray(arg)) {
- arg.forEach(function (t, i) {
- assertArgumentIsTensor(t, argName + "[" + i + "]", functionName);
- });
- }
- else {
- assertArgumentIsTensor(arg, argName, functionName);
- }
- };
- for (var argName in args) {
- _loop_1(argName);
- }
- }
- exports.assertArgumentsAreTensors = assertArgumentsAreTensors;
- function shuffle(array) {
- var counter = array.length;
- var temp = 0;
- var index = 0;
- while (counter > 0) {
- index = (Math.random() * counter) | 0;
- counter--;
- temp = array[counter];
- array[counter] = array[index];
- array[index] = temp;
- }
- }
- exports.shuffle = shuffle;
- function clamp(min, x, max) {
- return Math.max(min, Math.min(x, max));
- }
- exports.clamp = clamp;
- function randUniform(a, b) {
- return Math.random() * (b - a) + a;
- }
- exports.randUniform = randUniform;
- function distSquared(a, b) {
- var result = 0;
- for (var i = 0; i < a.length; i++) {
- var diff = Number(a[i]) - Number(b[i]);
- result += diff * diff;
- }
- return result;
- }
- exports.distSquared = distSquared;
- function assert(expr, msg) {
- if (!expr) {
- throw new Error(msg);
- }
- }
- exports.assert = assert;
- function assertShapesMatch(shapeA, shapeB, errorMessagePrefix) {
- if (errorMessagePrefix === void 0) { errorMessagePrefix = ''; }
- assert(arraysEqual(shapeA, shapeB), errorMessagePrefix + (" Shapes " + shapeA + " and " + shapeB + " must match"));
- }
- exports.assertShapesMatch = assertShapesMatch;
- function assertTypesMatch(a, b) {
- assert(a.dtype === b.dtype, " The dtypes of the first(" + a.dtype + ") and" +
- (" second(" + b.dtype + ") input must match"));
- }
- exports.assertTypesMatch = assertTypesMatch;
- function flatten(arr, ret) {
- if (ret === void 0) { ret = []; }
- if (Array.isArray(arr)) {
- for (var i = 0; i < arr.length; ++i) {
- flatten(arr[i], ret);
- }
- }
- else {
- ret.push(arr);
- }
- return ret;
- }
- exports.flatten = flatten;
- function inferShape(val) {
- if (isTypedArray(val)) {
- return [val.length];
- }
- if (!Array.isArray(val)) {
- return [];
- }
- var shape = [];
- while (val instanceof Array) {
- shape.push(val.length);
- val = val[0];
- }
- return shape;
- }
- exports.inferShape = inferShape;
- function sizeFromShape(shape) {
- if (shape.length === 0) {
- return 1;
- }
- var size = shape[0];
- for (var i = 1; i < shape.length; i++) {
- size *= shape[i];
- }
- return size;
- }
- exports.sizeFromShape = sizeFromShape;
- function isScalarShape(shape) {
- return shape.length === 0;
- }
- exports.isScalarShape = isScalarShape;
- function arraysEqual(n1, n2) {
- if (n1.length !== n2.length) {
- return false;
- }
- for (var i = 0; i < n1.length; i++) {
- if (n1[i] !== n2[i]) {
- return false;
- }
- }
- return true;
- }
- exports.arraysEqual = arraysEqual;
- function isInt(a) {
- return a % 1 === 0;
- }
- exports.isInt = isInt;
- function tanh(x) {
- if (Math.tanh != null) {
- return Math.tanh(x);
- }
- if (x === Infinity) {
- return 1;
- }
- else if (x === -Infinity) {
- return -1;
- }
- else {
- var e2x = Math.exp(2 * x);
- return (e2x - 1) / (e2x + 1);
- }
- }
- exports.tanh = tanh;
- function sizeToSquarishShape(size) {
- for (var a = Math.floor(Math.sqrt(size)); a > 1; --a) {
- if (size % a === 0) {
- return [a, size / a];
- }
- }
- return [1, size];
- }
- exports.sizeToSquarishShape = sizeToSquarishShape;
- function createShuffledIndices(n) {
- var shuffledIndices = new Uint32Array(n);
- for (var i = 0; i < n; ++i) {
- shuffledIndices[i] = i;
- }
- shuffle(shuffledIndices);
- return shuffledIndices;
- }
- exports.createShuffledIndices = createShuffledIndices;
- function rightPad(a, size) {
- if (size <= a.length) {
- return a;
- }
- return a + ' '.repeat(size - a.length);
- }
- exports.rightPad = rightPad;
- function repeatedTry(checkFn, delayFn, maxCounter) {
- if (delayFn === void 0) { delayFn = function (counter) { return 0; }; }
- return new Promise(function (resolve, reject) {
- var tryCount = 0;
- var tryFn = function () {
- if (checkFn()) {
- resolve();
- return;
- }
- tryCount++;
- var nextBackoff = delayFn(tryCount);
- if (maxCounter != null && tryCount >= maxCounter) {
- reject();
- return;
- }
- setTimeout(tryFn, nextBackoff);
- };
- tryFn();
- });
- }
- exports.repeatedTry = repeatedTry;
- function getQueryParams(queryString) {
- var params = {};
- queryString.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, function (s) {
- var t = [];
- for (var _i = 1; _i < arguments.length; _i++) {
- t[_i - 1] = arguments[_i];
- }
- decodeParam(params, t[0], t[1]);
- return t.join('=');
- });
- return params;
- }
- exports.getQueryParams = getQueryParams;
- function decodeParam(params, name, value) {
- params[decodeURIComponent(name)] = decodeURIComponent(value || '');
- }
- function inferFromImplicitShape(shape, size) {
- var shapeProd = 1;
- var implicitIdx = -1;
- for (var i = 0; i < shape.length; ++i) {
- if (shape[i] > 0) {
- shapeProd *= shape[i];
- }
- else if (shape[i] === -1) {
- if (implicitIdx !== -1) {
- throw Error("Shapes can only have 1 implicit size. " +
- ("Found - 1 at dim " + implicitIdx + " and dim " + i));
- }
- implicitIdx = i;
- }
- else if (shape[i] <= 0) {
- throw Error("Shapes can not be <= 0. Found " + shape[i] + " at dim " + i);
- }
- }
- if (implicitIdx === -1) {
- if (size > 0 && size !== shapeProd) {
- throw Error("Size(" + size + ") must match the product of shape " + shape);
- }
- return shape;
- }
- if (size % shapeProd !== 0) {
- throw Error("The implicit shape can't be a fractional number. " +
- ("Got " + size + " / " + shapeProd));
- }
- var newShape = shape.slice();
- newShape[implicitIdx] = size / shapeProd;
- return newShape;
- }
- exports.inferFromImplicitShape = inferFromImplicitShape;
- function squeezeShape(shape, axis) {
- var newShape = [];
- var keptDims = [];
- var j = 0;
- for (var i = 0; i < shape.length; ++i) {
- if (axis != null) {
- if (axis[j] === i && shape[i] > 1) {
- throw new Error("Can't squeeze axis " + i + " since its dim '" + shape[i] + "' is not 1");
- }
- if ((axis[j] == null || axis[j] > i) && shape[i] === 1) {
- newShape.push(shape[i]);
- keptDims.push(i);
- }
- if (axis[j] <= i) {
- j++;
- }
- }
- if (shape[i] > 1) {
- newShape.push(shape[i]);
- keptDims.push(i);
- }
- }
- return { newShape: newShape, keptDims: keptDims };
- }
- exports.squeezeShape = squeezeShape;
- function getTypedArrayFromDType(dtype, size) {
- var values = null;
- if (dtype == null || dtype === 'float32') {
- values = new Float32Array(size);
- }
- else if (dtype === 'int32') {
- values = new Int32Array(size);
- }
- else if (dtype === 'bool') {
- values = new Uint8Array(size);
- }
- else {
- throw new Error("Unknown data type " + dtype);
- }
- return values;
- }
- exports.getTypedArrayFromDType = getTypedArrayFromDType;
- function isTensorInList(tensor, tensorList) {
- for (var i = 0; i < tensorList.length; i++) {
- if (tensorList[i].id === tensor.id) {
- return true;
- }
- }
- return false;
- }
- exports.isTensorInList = isTensorInList;
- function checkForNaN(vals, dtype, name) {
- if (dtype !== 'float32') {
- return;
- }
- for (var i = 0; i < vals.length; i++) {
- if (isNaN(vals[i])) {
- throw Error("The result of the '" + name + "' has NaNs.");
- }
- }
- }
- exports.checkForNaN = checkForNaN;
- function flattenNameArrayMap(nameArrayMap, keys) {
- var xs = [];
- if (nameArrayMap instanceof tensor_1.Tensor) {
- xs.push(nameArrayMap);
- }
- else {
- var xMap = nameArrayMap;
- for (var i = 0; i < keys.length; i++) {
- xs.push(xMap[keys[i]]);
- }
- }
- return xs;
- }
- exports.flattenNameArrayMap = flattenNameArrayMap;
- function unflattenToNameArrayMap(keys, flatArrays) {
- if (keys.length !== flatArrays.length) {
- throw new Error("Cannot unflatten Tensor[], keys and arrays are not of same length.");
- }
- var result = {};
- for (var i = 0; i < keys.length; i++) {
- result[keys[i]] = flatArrays[i];
- }
- return result;
- }
- exports.unflattenToNameArrayMap = unflattenToNameArrayMap;
- function hasEncodingLoss(oldType, newType) {
- if (newType === 'float32') {
- return false;
- }
- if (newType === 'int32' && oldType !== 'float32') {
- return false;
- }
- if (newType === 'bool' && oldType === 'bool') {
- return false;
- }
- return true;
- }
- exports.hasEncodingLoss = hasEncodingLoss;
- function copyTypedArray(array, dtype) {
- if (dtype == null || dtype === 'float32') {
- return new Float32Array(array);
- }
- else if (dtype === 'int32') {
- return new Int32Array(array);
- }
- else if (dtype === 'bool') {
- var bool = new Uint8Array(array.length);
- for (var i = 0; i < bool.length; ++i) {
- if (Math.round(array[i]) !== 0) {
- bool[i] = 1;
- }
- }
- return bool;
- }
- else {
- throw new Error("Unknown data type " + dtype);
- }
- }
- exports.copyTypedArray = copyTypedArray;
- function isTypedArray(a) {
- return a instanceof Float32Array || a instanceof Int32Array ||
- a instanceof Uint8Array;
- }
- exports.isTypedArray = isTypedArray;
- function bytesPerElement(dtype) {
- if (dtype === 'float32' || dtype === 'int32') {
- return 4;
- }
- else if (dtype === 'bool') {
- return 1;
- }
- else {
- throw new Error("Unknown dtype " + dtype);
- }
- }
- exports.bytesPerElement = bytesPerElement;
- function isFunction(f) {
- return !!(f && f.constructor && f.call && f.apply);
- }
- exports.isFunction = isFunction;
- function getTensorsInContainer(result) {
- var list = [];
- var seen = new Set();
- walkTensorContainer(result, list, seen);
- return list;
- }
- exports.getTensorsInContainer = getTensorsInContainer;
- function walkTensorContainer(container, list, seen) {
- if (container == null) {
- return;
- }
- if (container instanceof tensor_1.Tensor) {
- list.push(container);
- return;
- }
- if (!isIterable(container)) {
- return;
- }
- var iterable = container;
- for (var k in iterable) {
- var val = iterable[k];
- if (!seen.has(val)) {
- seen.add(val);
- walkTensorContainer(val, list, seen);
- }
- }
- }
- function nearestDivisor(size, start) {
- for (var i = start; i < size; ++i) {
- if (size % i === 0) {
- return i;
- }
- }
- return size;
- }
- exports.nearestDivisor = nearestDivisor;
- function isIterable(obj) {
- return Array.isArray(obj) || typeof obj === 'object';
- }
- },{"./tensor":158}],165:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var version = '0.11.9';
- exports.version = version;
- },{}],166:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var gpgpu_util = require("./kernels/webgl/gpgpu_util");
- exports.gpgpu_util = gpgpu_util;
- var webgl_util = require("./kernels/webgl/webgl_util");
- exports.webgl_util = webgl_util;
- var backend_webgl_1 = require("./kernels/backend_webgl");
- exports.MathBackendWebGL = backend_webgl_1.MathBackendWebGL;
- var gpgpu_context_1 = require("./kernels/webgl/gpgpu_context");
- exports.GPGPUContext = gpgpu_context_1.GPGPUContext;
- },{"./kernels/backend_webgl":67,"./kernels/webgl/gpgpu_context":82,"./kernels/webgl/gpgpu_util":84,"./kernels/webgl/webgl_util":107}],167:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("./backend/tfjs_backend");
- var generic_utils_1 = require("./utils/generic_utils");
- var Activation = (function (_super) {
- __extends(Activation, _super);
- function Activation() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Activation.prototype.getConfig = function () {
- return {};
- };
- return Activation;
- }(tfjs_core_1.serialization.Serializable));
- exports.Activation = Activation;
- var Elu = (function (_super) {
- __extends(Elu, _super);
- function Elu() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Elu.prototype.apply = function (x, alpha) {
- if (alpha === void 0) { alpha = 1; }
- return K.elu(x, alpha);
- };
- Elu.className = 'elu';
- return Elu;
- }(Activation));
- exports.Elu = Elu;
- tfjs_core_1.serialization.SerializationMap.register(Elu);
- var Selu = (function (_super) {
- __extends(Selu, _super);
- function Selu() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Selu.prototype.apply = function (x) {
- return tfc.selu(x);
- };
- Selu.className = 'selu';
- return Selu;
- }(Activation));
- exports.Selu = Selu;
- tfjs_core_1.serialization.SerializationMap.register(Selu);
- var Relu = (function (_super) {
- __extends(Relu, _super);
- function Relu() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Relu.prototype.apply = function (x) {
- return tfc.relu(x);
- };
- Relu.className = 'relu';
- return Relu;
- }(Activation));
- exports.Relu = Relu;
- tfjs_core_1.serialization.SerializationMap.register(Relu);
- var Relu6 = (function (_super) {
- __extends(Relu6, _super);
- function Relu6() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Relu6.prototype.apply = function (x) {
- return tfjs_core_1.tidy(function () { return tfc.minimum(K.getScalar(6.0), tfc.relu(x)); });
- };
- Relu6.className = 'relu6';
- return Relu6;
- }(Activation));
- exports.Relu6 = Relu6;
- tfjs_core_1.serialization.SerializationMap.register(Relu6);
- var Linear = (function (_super) {
- __extends(Linear, _super);
- function Linear() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Linear.prototype.apply = function (x) {
- return x;
- };
- Linear.className = 'linear';
- return Linear;
- }(Activation));
- exports.Linear = Linear;
- tfjs_core_1.serialization.SerializationMap.register(Linear);
- var Sigmoid = (function (_super) {
- __extends(Sigmoid, _super);
- function Sigmoid() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Sigmoid.prototype.apply = function (x) {
- return tfc.sigmoid(x);
- };
- Sigmoid.className = 'sigmoid';
- return Sigmoid;
- }(Activation));
- exports.Sigmoid = Sigmoid;
- tfjs_core_1.serialization.SerializationMap.register(Sigmoid);
- var HardSigmoid = (function (_super) {
- __extends(HardSigmoid, _super);
- function HardSigmoid() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- HardSigmoid.prototype.apply = function (x) {
- return K.hardSigmoid(x);
- };
- HardSigmoid.className = 'hardSigmoid';
- return HardSigmoid;
- }(Activation));
- exports.HardSigmoid = HardSigmoid;
- tfjs_core_1.serialization.SerializationMap.register(HardSigmoid);
- var Softplus = (function (_super) {
- __extends(Softplus, _super);
- function Softplus() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Softplus.prototype.apply = function (x) {
- return tfc.softplus(x);
- };
- Softplus.className = 'softplus';
- return Softplus;
- }(Activation));
- exports.Softplus = Softplus;
- tfjs_core_1.serialization.SerializationMap.register(Softplus);
- var Softsign = (function (_super) {
- __extends(Softsign, _super);
- function Softsign() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Softsign.prototype.apply = function (x) {
- return K.softsign(x);
- };
- Softsign.className = 'softsign';
- return Softsign;
- }(Activation));
- exports.Softsign = Softsign;
- tfjs_core_1.serialization.SerializationMap.register(Softsign);
- var Tanh = (function (_super) {
- __extends(Tanh, _super);
- function Tanh() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Tanh.prototype.apply = function (x) {
- return tfc.tanh(x);
- };
- Tanh.className = 'tanh';
- return Tanh;
- }(Activation));
- exports.Tanh = Tanh;
- tfjs_core_1.serialization.SerializationMap.register(Tanh);
- var Softmax = (function (_super) {
- __extends(Softmax, _super);
- function Softmax() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Softmax.prototype.apply = function (x, axis) {
- if (axis === void 0) { axis = (-1); }
- return tfc.softmax(x, axis);
- };
- Softmax.className = 'softmax';
- return Softmax;
- }(Activation));
- exports.Softmax = Softmax;
- tfjs_core_1.serialization.SerializationMap.register(Softmax);
- function serializeActivation(activation) {
- return activation.getClassName();
- }
- exports.serializeActivation = serializeActivation;
- function deserializeActivation(config, customObjects) {
- if (customObjects === void 0) { customObjects = {}; }
- return generic_utils_1.deserializeKerasObject(config, tfjs_core_1.serialization.SerializationMap.getMap().classNameMap, customObjects, 'activation');
- }
- exports.deserializeActivation = deserializeActivation;
- function getActivation(identifier) {
- if (identifier == null) {
- var config = { className: 'linear', config: {} };
- return deserializeActivation(config);
- }
- if (typeof identifier === 'string') {
- var config = { className: identifier, config: {} };
- return deserializeActivation(config);
- }
- else if (identifier instanceof Activation) {
- return identifier;
- }
- else {
- return deserializeActivation(identifier);
- }
- }
- exports.getActivation = getActivation;
- },{"./backend/tfjs_backend":169,"./utils/generic_utils":199,"@tensorflow/tfjs-core":54}],168:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var _epsilon = 1e-7;
- function epsilon() {
- return _epsilon;
- }
- exports.epsilon = epsilon;
- function setEpsilon(e) {
- _epsilon = e;
- }
- exports.setEpsilon = setEpsilon;
- function imageDataFormat() {
- return 'channelsLast';
- }
- exports.imageDataFormat = imageDataFormat;
- },{}],169:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var common_1 = require("../common");
- var errors_1 = require("../errors");
- var math_utils = require("../utils/math_utils");
- var variables_1 = require("../variables");
- var common_2 = require("./common");
- var common_3 = require("./common");
- var backend = 'webgl';
- var DEFAULT_DTYPE = 'float32';
- function disposeScalarCache() {
- for (var typeKey in scalarCache) {
- for (var key in scalarCache[typeKey]) {
- scalarCache[typeKey][key].dispose();
- delete scalarCache[typeKey][key];
- }
- }
- }
- exports.disposeScalarCache = disposeScalarCache;
- function setBackend(requestedBackend) {
- tfc.setBackend(requestedBackend);
- backend = requestedBackend;
- disposeScalarCache();
- }
- exports.setBackend = setBackend;
- function getBackend() {
- return backend;
- }
- exports.getBackend = getBackend;
- var scalarCache = {
- float32: {},
- int32: {}
- };
- function getScalar(value, dtype) {
- if (dtype === undefined) {
- dtype = DEFAULT_DTYPE;
- }
- if (scalarCache[dtype][value] == null) {
- scalarCache[dtype][value] = tfjs_core_1.scalar(value, dtype);
- tfc.keep(scalarCache[dtype][value]);
- }
- return scalarCache[dtype][value];
- }
- exports.getScalar = getScalar;
- exports.epsilon = common_2.epsilon;
- function isBackendSymbolic() {
- return false;
- }
- exports.isBackendSymbolic = isBackendSymbolic;
- function shape(x) {
- return x.shape;
- }
- exports.shape = shape;
- function intShape(x) {
- return x.shape;
- }
- exports.intShape = intShape;
- function dtype(x) {
- return (x instanceof tfjs_core_1.Tensor) ? DEFAULT_DTYPE : x.dtype;
- }
- exports.dtype = dtype;
- function countParams(x) {
- var shape = x.shape;
- if (shape.length > 0) {
- return shape.reduce(function (a, b) { return a * b; });
- }
- else {
- return 1;
- }
- }
- exports.countParams = countParams;
- function cast(x, dtype) {
- return x.asType(dtype);
- }
- exports.cast = cast;
- function expandDims(x, axis) {
- if (axis === void 0) { axis = -1; }
- var outShape = shape(x).slice();
- if (axis < 0) {
- axis = outShape.length + axis + 1;
- }
- outShape.splice(axis, 0, 1);
- return x.reshape(outShape);
- }
- exports.expandDims = expandDims;
- function repeat(x, n) {
- return tfjs_core_1.tidy(function () {
- if (x.shape.length !== 2) {
- throw new errors_1.ValueError("repeat() expects a rank-2 tensor, but received a " +
- ("rank-" + x.shape.length + " tensor."));
- }
- var y = expandDims(x, 1);
- return tile(y, [1, n, 1]);
- });
- }
- exports.repeat = repeat;
- function flatten(x) {
- var newShape = [math_utils.arrayProd(x.shape)];
- return x.reshape(newShape);
- }
- exports.flatten = flatten;
- function batchFlatten(x) {
- if (x.rank <= 1) {
- throw new errors_1.ValueError("batchFlatten requires a minimum rank of 2. Got rank: " + x.rank + ".");
- }
- var newShape = [x.shape[0], math_utils.arrayProd(x.shape, 1)];
- return x.reshape(newShape);
- }
- exports.batchFlatten = batchFlatten;
- function sliceAlongFirstAxis(array, start, size) {
- return tfjs_core_1.tidy(function () {
- switch (array.rank) {
- case 1:
- return tfc.slice1d(array, start, size);
- case 2:
- return tfc.slice2d(array, [start, 0], [size, array.shape[1]]);
- case 3:
- return tfc.slice3d(array, [start, 0, 0], [size, array.shape[1], array.shape[2]]);
- case 4:
- return tfc.slice4d(array, [start, 0, 0, 0], [size, array.shape[1], array.shape[2], array.shape[3]]);
- default:
- throw new errors_1.ValueError("sliceAlongFirstAxis() received an unsupported tensor rank: " +
- ("" + array.rank));
- }
- });
- }
- exports.sliceAlongFirstAxis = sliceAlongFirstAxis;
- function sliceAlongLastAxis(array, start, size) {
- return tfjs_core_1.tidy(function () {
- switch (array.rank) {
- case 1:
- return tfc.slice1d(array, start, size);
- case 2:
- return tfc.slice2d(array, [0, start], [array.shape[0], size]);
- case 3:
- return tfc.slice3d(array, [0, 0, start], [array.shape[0], array.shape[1], size]);
- case 4:
- return tfc.slice4d(array, [0, 0, 0, start], [array.shape[0], array.shape[1], array.shape[2], size]);
- default:
- throw new errors_1.ValueError("sliceAlongLastAxis() received an unsupported tensor rank: " +
- ("" + array.rank));
- }
- });
- }
- exports.sliceAlongLastAxis = sliceAlongLastAxis;
- function sliceAlongAxis(array, start, size, axis) {
- return tfjs_core_1.tidy(function () {
- switch (array.rank) {
- case 1:
- return tfc.slice1d(array, start, size);
- case 2:
- switch (axis) {
- case 1:
- return sliceAlongFirstAxis(array, start, size);
- case 2:
- return sliceAlongLastAxis(array, start, size);
- default:
- throw new errors_1.ValueError("The axis is not within the rank of the tensor " +
- ("" + axis));
- }
- case 3:
- switch (axis) {
- case 1:
- return sliceAlongFirstAxis(array, start, size);
- case 2:
- return tfc.slice3d(array, [0, start, 0], [array.shape[0], size, array.shape[2]]);
- case 3:
- return sliceAlongLastAxis(array, start, size);
- default:
- throw new errors_1.ValueError("The axis is not within the rank of the tensor " +
- ("" + axis));
- }
- case 4:
- switch (axis) {
- case 1:
- return sliceAlongFirstAxis(array, start, size);
- case 2:
- return tfc.slice4d(array, [0, start, 0, 0], [array.shape[0], size, array.shape[2], array.shape[3]]);
- case 3:
- return tfc.slice4d(array, [0, 0, start, 0], [array.shape[0], array.shape[1], size, array.shape[3]]);
- case 4:
- return sliceAlongLastAxis(array, start, size);
- default:
- throw new errors_1.ValueError("The axis is not within the rank of the tensor " +
- ("" + axis));
- }
- default:
- throw new errors_1.ValueError("sliceAlongLastAxis() received an unsupported tensor rank: " +
- ("" + array.rank));
- }
- });
- }
- exports.sliceAlongAxis = sliceAlongAxis;
- function concatenate(tensors, axis) {
- if (axis === void 0) { axis = -1; }
- var rank;
- if (axis < 0) {
- rank = tensors[0].rank;
- if (rank !== 0) {
- axis = rank;
- }
- else {
- axis = 0;
- }
- }
- if (axis === tensors[0].rank) {
- axis = -1;
- }
- return tfc.concat(tensors, axis);
- }
- exports.concatenate = concatenate;
- function concatAlongFirstAxis(a, b) {
- switch (a.rank) {
- case 1:
- return tfc.concat1d([a, b]);
- case 2:
- return tfc.concat2d([a, b], 0);
- case 3:
- return tfc.concat3d([a, b], 0);
- case 4:
- return tfc.concat4d([a, b], 0);
- default:
- throw new errors_1.ValueError('concatAlongFirstAxis() received an unsupported tensor rank: ' +
- a.rank);
- }
- }
- exports.concatAlongFirstAxis = concatAlongFirstAxis;
- function tile(x, n) {
- if (!Array.isArray(n)) {
- n = [n];
- }
- if (x.rank !== n.length) {
- throw new errors_1.ValueError("The length of input n (" + n.length + ") does not match " +
- ("the number of dimensions in input x (" + x.rank + ")"));
- }
- return tfc.tile(x, n);
- }
- exports.tile = tile;
- function identity(x) {
- return x.clone();
- }
- exports.identity = identity;
- function eyeVariable(size, dtype, name) {
- return new variables_1.LayerVariable(tfc.eye(size, size, null, dtype), dtype, name);
- }
- exports.eyeVariable = eyeVariable;
- function scalarTimesArray(c, x) {
- return tfc.mul(c, x);
- }
- exports.scalarTimesArray = scalarTimesArray;
- function scalarPlusArray(c, x) {
- return tfc.add(c, x);
- }
- exports.scalarPlusArray = scalarPlusArray;
- function randomNormal(shape, mean, stddev, dtype, seed) {
- if (mean === void 0) { mean = 0.0; }
- if (stddev === void 0) { stddev = 1.0; }
- return tfc.randomNormal(shape, mean, stddev, dtype, seed);
- }
- exports.randomNormal = randomNormal;
- function dot(x, y) {
- if (y.rank !== 2) {
- throw new errors_1.NotImplementedError("dot support for y other than rank 2 is not yet implemented: " +
- ("y shape = " + shape));
- }
- else {
- if (x.rank === 2) {
- return tfc.matMul(x, y);
- }
- else if (x.rank === 3) {
- var xShape0 = x.shape[0];
- var xShape1 = x.shape[1];
- var xShape2 = x.shape[2];
- x = x.reshape([xShape0 * xShape1, xShape2]);
- return tfc.matMul(x, y).reshape([
- xShape0, xShape1, y.shape[1]
- ]);
- }
- else {
- throw new errors_1.NotImplementedError("dot support for x of rank " + x.rank + " is not yet implemented: " +
- ("x shape = " + shape));
- }
- }
- }
- exports.dot = dot;
- function sign(x) {
- return tfjs_core_1.tidy(function () {
- var zerosLikeX = tfjs_core_1.zerosLike(x);
- var onesLikeX = tfjs_core_1.onesLike(x);
- return tfjs_core_1.where(tfc.equal(x, zerosLikeX), zerosLikeX, tfjs_core_1.where(tfc.greater(x, tfjs_core_1.zerosLike(x)), onesLikeX, scalarTimesArray(getScalar(-1), onesLikeX)));
- });
- }
- exports.sign = sign;
- function qr(x) {
- var _a = tfjs_core_1.tidy(function () {
- if (x.shape.length !== 2) {
- throw new errors_1.ValueError("qr() requires a 2D Tensor, but got a " + x.shape.length + "D Tensor.");
- }
- if (x.shape[0] < x.shape[1]) {
- throw new errors_1.ValueError("qr() requires x.shape[0] >= x.shape[1], but got shape: [" + x.shape + "]");
- }
- var m = x.shape[0];
- var n = x.shape[1];
- var q = tfc.eye(m);
- var r = x.clone();
- var one2D = tfjs_core_1.tensor2d([[1]], [1, 1]);
- var w = one2D.clone();
- var _loop_1 = function (j) {
- var rTemp = r;
- var wTemp = w;
- var qTemp = q;
- _a = tfjs_core_1.tidy(function () {
- var rjEnd1 = r.slice([j, j], [m - j, 1]);
- var normX = tfc.norm(rjEnd1);
- var rjj = r.slice([j, j], [1, 1]);
- var s = tfc.neg(sign(rjj));
- var u1 = rjj.sub(tfc.mul(s, normX));
- var wPre = tfc.div(rjEnd1, u1);
- if (wPre.shape[0] === 1) {
- w = one2D.clone();
- }
- else {
- w = one2D.concat(wPre.slice([1, 0], [wPre.shape[0] - 1, wPre.shape[1]]), 0);
- }
- var tau = tfc.neg(tfc.div(tfc.matMul(s, u1), normX));
- var rjEndAll = r.slice([j, 0], [m - j, n]);
- var tauTimesW = tau.mul(w);
- if (j === 0) {
- r = rjEndAll.sub(tauTimesW.matMul(w.transpose().matMul(rjEndAll)));
- }
- else {
- r = r.slice([0, 0], [j, n])
- .concat(rjEndAll.sub(tauTimesW.matMul(w.transpose().matMul(rjEndAll))), 0);
- }
- var qAllJEnd = q.slice([0, j], [m, q.shape[1] - j]);
- if (j === 0) {
- q = qAllJEnd.sub(qAllJEnd.matMul(w).matMul(tauTimesW.transpose()));
- }
- else {
- q = q.slice([0, 0], [m, j])
- .concat(qAllJEnd.sub(qAllJEnd.matMul(w).matMul(tauTimesW.transpose())), 1);
- }
- return [w, r, q];
- }), w = _a[0], r = _a[1], q = _a[2];
- tfjs_core_1.dispose([rTemp, wTemp, qTemp]);
- var _a;
- };
- for (var j = 0; j < n; ++j) {
- _loop_1(j);
- }
- return [q, r];
- }), qOuter = _a[0], rOuter = _a[1];
- return [qOuter, rOuter];
- }
- exports.qr = qr;
- function oneHot(indices, numClasses) {
- return tfjs_core_1.tidy(function () {
- if (indices.rank !== 1) {
- throw new Error('Only 1D one-hot tensors are supported in the ' +
- 'deeplearn backend, at present.');
- }
- indices = indices.toInt();
- return tfc.oneHot(indices, numClasses).toFloat();
- });
- }
- exports.oneHot = oneHot;
- function gather(reference, indices, axis) {
- return tfjs_core_1.tidy(function () {
- if (Array.isArray(indices)) {
- indices = tfjs_core_1.tensor1d(indices, 'int32');
- }
- else {
- indices = indices.toInt();
- }
- return tfc.gather(reference, indices, axis);
- });
- }
- exports.gather = gather;
- function square(x) {
- return tfc.mulStrict(x, x);
- }
- exports.square = square;
- function pow(x, a) {
- return tfjs_core_1.tidy(function () {
- if (typeof (a) === 'number') {
- a = tfjs_core_1.scalar(Math.round(a), 'int32');
- }
- if (a.dtype !== 'int32') {
- throw new errors_1.NotImplementedError("Non-int32 dtype (" + a.dtype + ") is not supported by pow() yet");
- }
- return tfc.pow(x, a);
- });
- }
- exports.pow = pow;
- function biasAdd(x, bias, dataFormat) {
- return tfjs_core_1.tidy(function () {
- if (dataFormat == null) {
- dataFormat = common_3.imageDataFormat();
- }
- common_1.checkDataFormat(dataFormat);
- if (bias.rank !== 1 && bias.rank !== x.rank) {
- throw new errors_1.ValueError('Unexpected bias dimensions: ' + bias.rank +
- '; expected it to be 1 or ' + x.rank);
- }
- var biasShape = bias.shape;
- var y;
- if (x.rank === 5) {
- if (dataFormat === 'channelsFirst') {
- if (biasShape.length === 1) {
- y = x.add(bias.reshape([1, biasShape[0], 1, 1, 1]));
- }
- else {
- y = x.add(bias.reshape([1, biasShape[3], biasShape[0], biasShape[1], biasShape[2]]));
- }
- }
- else if (dataFormat === 'channelsLast') {
- if (biasShape.length === 1) {
- y = x.add(bias.reshape([1, 1, 1, 1, biasShape[0]]));
- }
- else {
- y = x.add(bias.reshape([1].concat(biasShape)));
- }
- }
- }
- else if (x.rank === 4) {
- if (dataFormat === 'channelsFirst') {
- if (biasShape.length === 1) {
- y = x.add(bias.reshape([1, biasShape[0], 1, 1]));
- }
- else {
- y = x.add(bias.reshape([1, biasShape[2], biasShape[0], biasShape[1]]));
- }
- }
- else if (dataFormat === 'channelsLast') {
- if (biasShape.length === 1) {
- y = x.add(bias.reshape([1, 1, 1, biasShape[0]]));
- }
- else {
- y = x.add(bias.reshape([1].concat(biasShape)));
- }
- }
- }
- else if (x.rank === 3) {
- if (dataFormat === 'channelsFirst') {
- if (biasShape.length === 1) {
- y = x.add(bias.reshape([1, biasShape[0], 1]));
- }
- else {
- y = x.add(bias.reshape([1, biasShape[1], biasShape[0]]));
- }
- }
- else if (dataFormat === 'channelsLast') {
- if (biasShape.length === 1) {
- y = x.add(bias.reshape([1, 1, biasShape[0]]));
- }
- else {
- y = x.add(bias.reshape([1].concat(biasShape)));
- }
- }
- }
- else if (x.rank < 3) {
- y = x.add(bias);
- }
- else {
- throw new errors_1.ValueError("Unsupported input rank by biasAdd: " + x.rank);
- }
- return y;
- });
- }
- exports.biasAdd = biasAdd;
- function elu(x, alpha) {
- if (alpha === void 0) { alpha = 1; }
- if (alpha !== 1) {
- throw new errors_1.NotImplementedError("Support for alpha values other than 1 (" + alpha + ") is not implemented " +
- "yet.");
- }
- return tfc.elu(x);
- }
- exports.elu = elu;
- function softsign(x) {
- return tfjs_core_1.tidy(function () { return tfc.div(x, tfc.add(getScalar(1), tfc.abs(x))); });
- }
- exports.softsign = softsign;
- function dropout(x, level, noiseShape, seed) {
- return tfjs_core_1.tidy(function () {
- if (noiseShape != null && !tfjs_core_1.util.arraysEqual(x.shape, noiseShape)) {
- throw new errors_1.NotImplementedError('Non-default noise shape is not implemented yet: ' +
- JSON.stringify(noiseShape));
- }
- if (seed != null) {
- throw new errors_1.NotImplementedError('seed is not implemented for dropout yet.');
- }
- var multiplier = tfc.step(tfc.add(tfc.neg(level), tfc.randomUniform(x.shape, 0, 1, 'float32')));
- multiplier = tfc.mul(tfc.div(getScalar(1), tfc.sub(getScalar(1), level)), multiplier);
- return tfc.mul(x, multiplier);
- });
- }
- exports.dropout = dropout;
- function nameScope(name, fn) {
- return common_1.nameScope(name, fn);
- }
- exports.nameScope = nameScope;
- function floatx() {
- return 'float32';
- }
- exports.floatx = floatx;
- var _uidPrefixes = {};
- function getUid(prefix) {
- if (prefix === void 0) { prefix = ''; }
- if (!(prefix in _uidPrefixes)) {
- _uidPrefixes[prefix] = 0;
- }
- _uidPrefixes[prefix] += 1;
- return prefix + _uidPrefixes[prefix].toString();
- }
- exports.getUid = getUid;
- function hardSigmoid(x) {
- return tfjs_core_1.tidy(function () {
- var y = scalarPlusArray(getScalar(0.5), scalarTimesArray(getScalar(0.2), x));
- return tfc.clipByValue(y, 0, 1);
- });
- }
- exports.hardSigmoid = hardSigmoid;
- function inTrainPhase(x, alt, training) {
- if (training === void 0) { training = false; }
- return training ? x() : alt();
- }
- exports.inTrainPhase = inTrainPhase;
- function gradients(lossFn, variables) {
- var variableList = variables.map(function (variable) { return variable.read(); });
- var valudAndGrads = tfjs_core_1.variableGrads(lossFn, variableList);
- return variables.map(function (variable) { return valudAndGrads.grads[variable.name]; });
- }
- exports.gradients = gradients;
- },{"../common":171,"../errors":176,"../utils/math_utils":201,"../variables":203,"./common":168,"@tensorflow/tfjs-core":54}],170:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("./backend/tfjs_backend");
- var generic_utils = require("./utils/generic_utils");
- var Callback = (function () {
- function Callback() {
- this.validationData = null;
- this.model = null;
- }
- Callback.prototype.setParams = function (params) {
- this.params = params;
- };
- Callback.prototype.setModel = function (model) {
- this.model = model;
- };
- Callback.prototype.onEpochBegin = function (epoch, logs) {
- return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
- return [2];
- }); });
- };
- Callback.prototype.onEpochEnd = function (epoch, logs) {
- return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
- return [2];
- }); });
- };
- Callback.prototype.onBatchBegin = function (batch, logs) {
- return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
- return [2];
- }); });
- };
- Callback.prototype.onBatchEnd = function (batch, logs) {
- return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
- return [2];
- }); });
- };
- Callback.prototype.onTrainBegin = function (logs) {
- return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
- return [2];
- }); });
- };
- Callback.prototype.onTrainEnd = function (logs) {
- return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
- return [2];
- }); });
- };
- return Callback;
- }());
- exports.Callback = Callback;
- var CallbackList = (function () {
- function CallbackList(callbacks, queueLength) {
- if (queueLength === void 0) { queueLength = 10; }
- if (callbacks == null) {
- callbacks = [];
- }
- this.callbacks = callbacks;
- this.queueLength = queueLength;
- }
- CallbackList.prototype.append = function (callback) {
- this.callbacks.push(callback);
- };
- CallbackList.prototype.setParams = function (params) {
- for (var _i = 0, _a = this.callbacks; _i < _a.length; _i++) {
- var callback = _a[_i];
- callback.setParams(params);
- }
- };
- CallbackList.prototype.setModel = function (model) {
- for (var _i = 0, _a = this.callbacks; _i < _a.length; _i++) {
- var callback = _a[_i];
- callback.setModel(model);
- }
- };
- CallbackList.prototype.onEpochBegin = function (epoch, logs) {
- return __awaiter(this, void 0, void 0, function () {
- var _i, _a, callback;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- if (logs == null) {
- logs = {};
- }
- _i = 0, _a = this.callbacks;
- _b.label = 1;
- case 1:
- if (!(_i < _a.length)) return [3, 4];
- callback = _a[_i];
- return [4, callback.onEpochBegin(epoch, logs)];
- case 2:
- _b.sent();
- _b.label = 3;
- case 3:
- _i++;
- return [3, 1];
- case 4: return [2];
- }
- });
- });
- };
- CallbackList.prototype.onEpochEnd = function (epoch, logs) {
- return __awaiter(this, void 0, void 0, function () {
- var _i, _a, callback;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- if (logs == null) {
- logs = {};
- }
- _i = 0, _a = this.callbacks;
- _b.label = 1;
- case 1:
- if (!(_i < _a.length)) return [3, 4];
- callback = _a[_i];
- return [4, callback.onEpochEnd(epoch, logs)];
- case 2:
- _b.sent();
- _b.label = 3;
- case 3:
- _i++;
- return [3, 1];
- case 4: return [2];
- }
- });
- });
- };
- CallbackList.prototype.onBatchBegin = function (batch, logs) {
- return __awaiter(this, void 0, void 0, function () {
- var _i, _a, callback;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- if (logs == null) {
- logs = {};
- }
- _i = 0, _a = this.callbacks;
- _b.label = 1;
- case 1:
- if (!(_i < _a.length)) return [3, 4];
- callback = _a[_i];
- return [4, callback.onBatchBegin(batch, logs)];
- case 2:
- _b.sent();
- _b.label = 3;
- case 3:
- _i++;
- return [3, 1];
- case 4: return [2];
- }
- });
- });
- };
- CallbackList.prototype.onBatchEnd = function (batch, logs) {
- return __awaiter(this, void 0, void 0, function () {
- var _i, _a, callback;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- if (logs == null) {
- logs = {};
- }
- _i = 0, _a = this.callbacks;
- _b.label = 1;
- case 1:
- if (!(_i < _a.length)) return [3, 4];
- callback = _a[_i];
- return [4, callback.onBatchEnd(batch, logs)];
- case 2:
- _b.sent();
- _b.label = 3;
- case 3:
- _i++;
- return [3, 1];
- case 4: return [2];
- }
- });
- });
- };
- CallbackList.prototype.onTrainBegin = function (logs) {
- return __awaiter(this, void 0, void 0, function () {
- var _i, _a, callback;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- if (logs == null) {
- logs = {};
- }
- _i = 0, _a = this.callbacks;
- _b.label = 1;
- case 1:
- if (!(_i < _a.length)) return [3, 4];
- callback = _a[_i];
- return [4, callback.onTrainBegin(logs)];
- case 2:
- _b.sent();
- _b.label = 3;
- case 3:
- _i++;
- return [3, 1];
- case 4: return [2];
- }
- });
- });
- };
- CallbackList.prototype.onTrainEnd = function (logs) {
- return __awaiter(this, void 0, void 0, function () {
- var _i, _a, callback;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- if (logs == null) {
- logs = {};
- }
- _i = 0, _a = this.callbacks;
- _b.label = 1;
- case 1:
- if (!(_i < _a.length)) return [3, 4];
- callback = _a[_i];
- return [4, callback.onTrainEnd(logs)];
- case 2:
- _b.sent();
- _b.label = 3;
- case 3:
- _i++;
- return [3, 1];
- case 4: return [2];
- }
- });
- });
- };
- return CallbackList;
- }());
- exports.CallbackList = CallbackList;
- var BaseLogger = (function (_super) {
- __extends(BaseLogger, _super);
- function BaseLogger() {
- return _super.call(this) || this;
- }
- BaseLogger.prototype.onEpochBegin = function (epoch, logs) {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- this.seen = 0;
- this.totals = {};
- return [2];
- });
- });
- };
- BaseLogger.prototype.onBatchEnd = function (batch, logs) {
- return __awaiter(this, void 0, void 0, function () {
- var _this = this;
- var batchSize, _loop_1, this_1, key;
- return __generator(this, function (_a) {
- if (logs == null) {
- logs = {};
- }
- batchSize = logs['size'] == null ? 0 : logs['size'];
- this.seen += batchSize;
- _loop_1 = function (key) {
- var value = logs[key];
- if (typeof value === 'number') {
- if (!this_1.totals.hasOwnProperty(key)) {
- this_1.totals[key] = 0;
- }
- this_1.totals[key] = this_1.totals[key] + value * batchSize;
- }
- else {
- var oldTotalsToDispose = void 0;
- if (key in this_1.totals) {
- oldTotalsToDispose = this_1.totals[key];
- }
- else {
- this_1.totals[key] = K.getScalar(0);
- }
- this_1.totals[key] = tfjs_core_1.tidy(function () { return K.scalarPlusArray(_this.totals[key], tfjs_core_1.mul(value, K.getScalar(batchSize))); });
- if (oldTotalsToDispose != null) {
- oldTotalsToDispose.dispose();
- }
- }
- };
- this_1 = this;
- for (key in logs) {
- _loop_1(key);
- }
- return [2];
- });
- });
- };
- BaseLogger.prototype.onEpochEnd = function (epoch, logs) {
- return __awaiter(this, void 0, void 0, function () {
- var _this = this;
- var _loop_2, this_2, _i, _a, key;
- return __generator(this, function (_b) {
- if (logs != null) {
- _loop_2 = function (key) {
- if (this_2.totals[key] == null) {
- return "continue";
- }
- if (typeof this_2.totals[key] === 'number') {
- logs[key] = this_2.totals[key] / this_2.seen;
- }
- else {
- tfjs_core_1.tidy(function () {
- logs[key] =
- K.scalarTimesArray(tfjs_core_1.div(K.getScalar(1), K.getScalar(_this.seen)), _this.totals[key]);
- _this.totals[key].dispose();
- tfjs_core_1.keep(logs[key]);
- });
- }
- };
- this_2 = this;
- for (_i = 0, _a = this.params['metrics']; _i < _a.length; _i++) {
- key = _a[_i];
- _loop_2(key);
- }
- }
- return [2];
- });
- });
- };
- return BaseLogger;
- }(Callback));
- exports.BaseLogger = BaseLogger;
- function resolveScalarsInLogs(logs) {
- return __awaiter(this, void 0, void 0, function () {
- var promises, keys, key, value, valueScalar, values, i;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (logs == null) {
- return [2];
- }
- promises = [];
- keys = [];
- for (key in logs) {
- value = logs[key];
- if (typeof value !== 'number') {
- valueScalar = value;
- promises.push(valueScalar.data());
- keys.push(key);
- }
- }
- return [4, Promise.all(promises)];
- case 1:
- values = _a.sent();
- for (i = 0; i < values.length; ++i) {
- logs[keys[i]] = values[i][0];
- }
- return [2];
- }
- });
- });
- }
- exports.resolveScalarsInLogs = resolveScalarsInLogs;
- function disposeTensorsInLogs(logs) {
- if (logs == null) {
- return;
- }
- for (var key in logs) {
- var value = logs[key];
- if (typeof value !== 'number') {
- value.dispose();
- }
- }
- }
- exports.disposeTensorsInLogs = disposeTensorsInLogs;
- var History = (function (_super) {
- __extends(History, _super);
- function History() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- History.prototype.onTrainBegin = function (logs) {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- this.epoch = [];
- this.history = {};
- return [2];
- });
- });
- };
- History.prototype.onEpochEnd = function (epoch, logs) {
- return __awaiter(this, void 0, void 0, function () {
- var key;
- return __generator(this, function (_a) {
- if (logs == null) {
- logs = {};
- }
- this.epoch.push(epoch);
- for (key in logs) {
- if (this.history[key] == null) {
- this.history[key] = [];
- }
- this.history[key].push(logs[key]);
- }
- return [2];
- });
- });
- };
- History.prototype.syncData = function () {
- return __awaiter(this, void 0, void 0, function () {
- var promises, keys, indices, key, valueArray, i, valueScalar, values, n;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- promises = [];
- keys = [];
- indices = [];
- for (key in this.history) {
- valueArray = this.history[key];
- for (i = 0; i < valueArray.length; ++i) {
- if (typeof valueArray[i] !== 'number') {
- valueScalar = valueArray[i];
- promises.push(valueScalar.data());
- keys.push(key);
- indices.push(i);
- }
- }
- }
- return [4, Promise.all(promises)];
- case 1:
- values = _a.sent();
- for (n = 0; n < values.length; ++n) {
- this.history[keys[n]][indices[n]].dispose();
- this.history[keys[n]][indices[n]] = values[n][0];
- }
- return [2];
- }
- });
- });
- };
- return History;
- }(Callback));
- exports.History = History;
- var CustomCallback = (function (_super) {
- __extends(CustomCallback, _super);
- function CustomCallback(config) {
- var _this = _super.call(this) || this;
- _this.trainBegin = config.onTrainBegin;
- _this.trainEnd = config.onTrainEnd;
- _this.epochBegin = config.onEpochBegin;
- _this.epochEnd = config.onEpochEnd;
- _this.batchBegin = config.onBatchBegin;
- _this.batchEnd = config.onBatchEnd;
- return _this;
- }
- CustomCallback.prototype.onEpochBegin = function (epoch, logs) {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!(this.epochBegin != null)) return [3, 3];
- return [4, resolveScalarsInLogs(logs)];
- case 1:
- _a.sent();
- return [4, this.epochBegin(epoch, logs)];
- case 2:
- _a.sent();
- _a.label = 3;
- case 3: return [2];
- }
- });
- });
- };
- CustomCallback.prototype.onEpochEnd = function (epoch, logs) {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!(this.epochEnd != null)) return [3, 3];
- return [4, resolveScalarsInLogs(logs)];
- case 1:
- _a.sent();
- return [4, this.epochEnd(epoch, logs)];
- case 2:
- _a.sent();
- _a.label = 3;
- case 3: return [2];
- }
- });
- });
- };
- CustomCallback.prototype.onBatchBegin = function (batch, logs) {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!(this.batchBegin != null)) return [3, 3];
- return [4, resolveScalarsInLogs(logs)];
- case 1:
- _a.sent();
- return [4, this.batchBegin(batch, logs)];
- case 2:
- _a.sent();
- _a.label = 3;
- case 3: return [2];
- }
- });
- });
- };
- CustomCallback.prototype.onBatchEnd = function (batch, logs) {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!(this.batchEnd != null)) return [3, 3];
- return [4, resolveScalarsInLogs(logs)];
- case 1:
- _a.sent();
- return [4, this.batchEnd(batch, logs)];
- case 2:
- _a.sent();
- _a.label = 3;
- case 3: return [2];
- }
- });
- });
- };
- CustomCallback.prototype.onTrainBegin = function (logs) {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!(this.trainBegin != null)) return [3, 3];
- return [4, resolveScalarsInLogs(logs)];
- case 1:
- _a.sent();
- return [4, this.trainBegin(logs)];
- case 2:
- _a.sent();
- _a.label = 3;
- case 3: return [2];
- }
- });
- });
- };
- CustomCallback.prototype.onTrainEnd = function (logs) {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!(this.trainEnd != null)) return [3, 3];
- return [4, resolveScalarsInLogs(logs)];
- case 1:
- _a.sent();
- return [4, this.trainEnd(logs)];
- case 2:
- _a.sent();
- _a.label = 3;
- case 3: return [2];
- }
- });
- });
- };
- return CustomCallback;
- }(Callback));
- exports.CustomCallback = CustomCallback;
- function standardizeCallbacks(callbacks) {
- if (callbacks == null) {
- return null;
- }
- if (callbacks instanceof Callback) {
- return [callbacks];
- }
- if (Array.isArray(callbacks) && callbacks[0] instanceof Callback) {
- return callbacks;
- }
- var callbackConfigs = generic_utils.toList(callbacks);
- return callbackConfigs.map(function (callbackConfig) { return new CustomCallback(callbackConfig); });
- }
- exports.standardizeCallbacks = standardizeCallbacks;
- },{"./backend/tfjs_backend":169,"./utils/generic_utils":199,"@tensorflow/tfjs-core":54}],171:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var generic_utils_1 = require("./utils/generic_utils");
- var nameMap = new Map();
- exports.VALID_DATA_FORMAT_VALUES = ['channelsFirst', 'channelsLast'];
- function checkDataFormat(value) {
- generic_utils_1.checkStringTypeUnionValue(exports.VALID_DATA_FORMAT_VALUES, 'DataFormat', value);
- }
- exports.checkDataFormat = checkDataFormat;
- exports.VALID_PADDING_MODE_VALUES = ['valid', 'same', 'causal'];
- function checkPaddingMode(value) {
- generic_utils_1.checkStringTypeUnionValue(exports.VALID_PADDING_MODE_VALUES, 'PaddingMode', value);
- }
- exports.checkPaddingMode = checkPaddingMode;
- exports.VALID_POOL_MODE_VALUES = ['max', 'avg'];
- function checkPoolMode(value) {
- generic_utils_1.checkStringTypeUnionValue(exports.VALID_POOL_MODE_VALUES, 'PoolMode', value);
- }
- exports.checkPoolMode = checkPoolMode;
- var _nameScopeStack = [];
- var _nameScopeDivider = '/';
- function nameScope(name, fn) {
- _nameScopeStack.push(name);
- try {
- var val = fn();
- _nameScopeStack.pop();
- return val;
- }
- catch (e) {
- _nameScopeStack.pop();
- throw e;
- }
- }
- exports.nameScope = nameScope;
- function currentNameScopePrefix() {
- if (_nameScopeStack.length === 0) {
- return '';
- }
- else {
- return _nameScopeStack.join(_nameScopeDivider) + _nameScopeDivider;
- }
- }
- function getScopedTensorName(tensorName) {
- if (!isValidTensorName(tensorName)) {
- throw new Error('Not a valid tensor name: \'' + tensorName + '\'');
- }
- return currentNameScopePrefix() + tensorName;
- }
- exports.getScopedTensorName = getScopedTensorName;
- function getUniqueTensorName(scopedName) {
- if (!isValidTensorName(scopedName)) {
- throw new Error('Not a valid tensor name: \'' + scopedName + '\'');
- }
- if (!nameMap.has(scopedName)) {
- nameMap.set(scopedName, 0);
- }
- var index = nameMap.get(scopedName);
- nameMap.set(scopedName, nameMap.get(scopedName) + 1);
- if (index > 0) {
- var result = scopedName + '_' + index;
- nameMap.set(result, 1);
- return result;
- }
- else {
- return scopedName;
- }
- }
- exports.getUniqueTensorName = getUniqueTensorName;
- var tensorNameRegex = new RegExp(/^[A-Za-z][A-Za-z0-9\._\/]*$/);
- function isValidTensorName(name) {
- return name.match(tensorNameRegex) ? true : false;
- }
- exports.isValidTensorName = isValidTensorName;
- },{"./utils/generic_utils":199}],172:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("./backend/tfjs_backend");
- var generic_utils_1 = require("./utils/generic_utils");
- function calcL2Norms(w, axis) {
- return tfjs_core_1.tidy(function () { return tfc.sqrt(tfc.sum(K.square(w), axis, true)); });
- }
- var Constraint = (function (_super) {
- __extends(Constraint, _super);
- function Constraint() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Constraint.prototype.getConfig = function () {
- return {};
- };
- Constraint = __decorate([
- tfjs_core_1.doc({ heading: 'Constraints', subheading: 'Classes', namespace: 'constraints' })
- ], Constraint);
- return Constraint;
- }(tfjs_core_1.serialization.Serializable));
- exports.Constraint = Constraint;
- var MaxNorm = (function (_super) {
- __extends(MaxNorm, _super);
- function MaxNorm(config) {
- var _this = _super.call(this) || this;
- _this.defaultMaxValue = 2;
- _this.defaultAxis = 0;
- _this.maxValue =
- config.maxValue != null ? config.maxValue : _this.defaultMaxValue;
- _this.axis = config.axis != null ? config.axis : _this.defaultAxis;
- return _this;
- }
- MaxNorm.prototype.apply = function (w) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- var norms = calcL2Norms(w, _this.axis);
- var desired = tfc.clipByValue(norms, 0, _this.maxValue);
- return tfc.mul(w, tfc.div(desired, K.scalarPlusArray(K.getScalar(K.epsilon()), norms)));
- });
- };
- MaxNorm.prototype.getConfig = function () {
- return { maxValue: this.maxValue, axis: this.axis };
- };
- MaxNorm.className = 'MaxNorm';
- return MaxNorm;
- }(Constraint));
- exports.MaxNorm = MaxNorm;
- tfjs_core_1.serialization.SerializationMap.register(MaxNorm);
- var UnitNorm = (function (_super) {
- __extends(UnitNorm, _super);
- function UnitNorm(config) {
- var _this = _super.call(this) || this;
- _this.defaultAxis = 0;
- _this.axis = config.axis != null ? config.axis : _this.defaultAxis;
- return _this;
- }
- UnitNorm.prototype.apply = function (w) {
- var _this = this;
- return tfjs_core_1.tidy(function () { return tfc.div(w, K.scalarPlusArray(K.getScalar(K.epsilon()), calcL2Norms(w, _this.axis))); });
- };
- UnitNorm.prototype.getConfig = function () {
- return { axis: this.axis };
- };
- UnitNorm.className = 'UnitNorm';
- return UnitNorm;
- }(Constraint));
- exports.UnitNorm = UnitNorm;
- tfjs_core_1.serialization.SerializationMap.register(UnitNorm);
- var NonNeg = (function (_super) {
- __extends(NonNeg, _super);
- function NonNeg() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- NonNeg.prototype.apply = function (w) {
- return tfc.relu(w);
- };
- NonNeg.className = 'NonNeg';
- return NonNeg;
- }(Constraint));
- exports.NonNeg = NonNeg;
- tfjs_core_1.serialization.SerializationMap.register(NonNeg);
- var MinMaxNorm = (function (_super) {
- __extends(MinMaxNorm, _super);
- function MinMaxNorm(config) {
- var _this = _super.call(this) || this;
- _this.defaultMinValue = 0.0;
- _this.defaultMaxValue = 1.0;
- _this.defaultRate = 1.0;
- _this.defaultAxis = 0;
- _this.minValue =
- config.minValue != null ? config.minValue : _this.defaultMinValue;
- _this.maxValue =
- config.maxValue != null ? config.maxValue : _this.defaultMaxValue;
- _this.rate = config.rate != null ? config.rate : _this.defaultRate;
- _this.axis = config.axis != null ? config.axis : _this.defaultAxis;
- return _this;
- }
- MinMaxNorm.prototype.apply = function (w) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- var norms = calcL2Norms(w, _this.axis);
- var desired = tfc.add(K.scalarTimesArray(K.getScalar(_this.rate), tfc.clipByValue(norms, _this.minValue, _this.maxValue)), K.scalarTimesArray(K.getScalar(1.0 - _this.rate), norms));
- return tfc.mul(w, tfc.div(desired, K.scalarPlusArray(K.getScalar(K.epsilon()), norms)));
- });
- };
- MinMaxNorm.prototype.getConfig = function () {
- return {
- minValue: this.minValue,
- maxValue: this.maxValue,
- rate: this.rate,
- axis: this.axis
- };
- };
- MinMaxNorm.className = 'MinMaxNorm';
- return MinMaxNorm;
- }(Constraint));
- exports.MinMaxNorm = MinMaxNorm;
- tfjs_core_1.serialization.SerializationMap.register(MinMaxNorm);
- exports.CONSTRAINT_IDENTIFIER_REGISTRY_SYMBOL_MAP = {
- 'maxNorm': 'MaxNorm',
- 'minMaxNorm': 'MinMaxNorm',
- 'nonNeg': 'NonNeg',
- 'unitNorm': 'UnitNorm'
- };
- function serializeConstraint(constraint) {
- return generic_utils_1.serializeKerasObject(constraint);
- }
- exports.serializeConstraint = serializeConstraint;
- function deserializeConstraint(config, customObjects) {
- if (customObjects === void 0) { customObjects = {}; }
- return generic_utils_1.deserializeKerasObject(config, tfjs_core_1.serialization.SerializationMap.getMap().classNameMap, customObjects, 'constraint');
- }
- exports.deserializeConstraint = deserializeConstraint;
- function getConstraint(identifier) {
- if (identifier == null) {
- return null;
- }
- if (typeof identifier === 'string') {
- var className = identifier in exports.CONSTRAINT_IDENTIFIER_REGISTRY_SYMBOL_MAP ?
- exports.CONSTRAINT_IDENTIFIER_REGISTRY_SYMBOL_MAP[identifier] :
- identifier;
- var config = { className: className, config: {} };
- return deserializeConstraint(config);
- }
- else if (identifier instanceof Constraint) {
- return identifier;
- }
- else {
- return deserializeConstraint(identifier);
- }
- }
- exports.getConstraint = getConstraint;
- },{"./backend/tfjs_backend":169,"./utils/generic_utils":199,"@tensorflow/tfjs-core":54}],173:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var errors_1 = require("../errors");
- var topology_1 = require("./topology");
- function assertFeedCompatibility(key, val) {
- if (key.dtype != null && key.dtype !== val.dtype) {
- throw new errors_1.ValueError("The dtype of the feed (" + val.dtype + ") is incompatible with that of " +
- ("the key '" + key.name + "' (" + key.dtype + ")."));
- }
- if (key.shape != null) {
- if (key.shape.length !== val.shape.length) {
- throw new errors_1.ValueError("The rank of feed (" + val.shape.length + ") does not match the rank of " +
- ("the key (" + key.shape.length + ")."));
- }
- for (var i = 0; i < key.shape.length; ++i) {
- if (key.shape[i] != null && key.shape[i] !== val.shape[i]) {
- throw new errors_1.ValueError("The " + i + "-th dimension of the feed (" + val.shape[i] + ") is " +
- ("incompatible with that of the key (" + key.shape[i] + ")."));
- }
- }
- }
- }
- var FeedDict = (function () {
- function FeedDict(feeds) {
- this.id2Value = {};
- if (feeds instanceof FeedDict) {
- for (var id in feeds.id2Value) {
- this.id2Value[id] = feeds.id2Value[id];
- }
- }
- else {
- if (feeds == null) {
- return;
- }
- for (var _i = 0, feeds_1 = feeds; _i < feeds_1.length; _i++) {
- var feed = feeds_1[_i];
- this.add(feed.key, feed.value);
- }
- }
- }
- FeedDict.prototype.add = function (key, value) {
- assertFeedCompatibility(key, value);
- if (this.id2Value[key.id] == null) {
- this.id2Value[key.id] = value;
- }
- else {
- throw new errors_1.ValueError("Duplicate key: name=" + key.name + ", id=" + key.id);
- }
- return this;
- };
- FeedDict.prototype.addFeed = function (feed) {
- this.add(feed.key, feed.value);
- };
- FeedDict.prototype.hasKey = function (key) {
- return this.id2Value[key.id] != null;
- };
- FeedDict.prototype.getValue = function (key) {
- if (this.id2Value[key.id] == null) {
- throw new errors_1.ValueError("Nonexistent key: " + JSON.stringify(key));
- }
- else {
- return this.id2Value[key.id];
- }
- };
- return FeedDict;
- }());
- exports.FeedDict = FeedDict;
- function execute(fetches, feedDict, kwargs) {
- var arrayFetches = Array.isArray(fetches);
- var fetchArray = arrayFetches ? fetches : [fetches];
- var outputs = [];
- var internalFeedDict = new FeedDict(feedDict);
- for (var _i = 0, fetchArray_1 = fetchArray; _i < fetchArray_1.length; _i++) {
- var fetch_1 = fetchArray_1[_i];
- outputs.push(executeInternal(fetch_1, internalFeedDict, kwargs));
- }
- return arrayFetches ? outputs : outputs[0];
- }
- exports.execute = execute;
- function executeInternal(fetch, internalFeedDict, kwargs) {
- if (internalFeedDict.hasKey(fetch)) {
- return internalFeedDict.getValue(fetch);
- }
- if (fetch.sourceLayer instanceof topology_1.InputLayer) {
- throw new errors_1.ValueError("Missing a feed value for SymbolicTensor from InputLayer " +
- ("'" + topology_1.InputLayer.name + "'"));
- }
- var inputs = fetch.inputs;
- var inputValues = [];
- for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {
- var input = inputs_1[_i];
- var inputVal = executeInternal(input, internalFeedDict, kwargs);
- inputValues.push(inputVal);
- }
- var output = fetch.sourceLayer.apply(inputValues, kwargs);
- if (!Array.isArray(output)) {
- output = [output];
- }
- var layerOutputs = getNodeOutputs(fetch);
- var outputSymbolicTensors = Array.isArray(layerOutputs) ? layerOutputs : [layerOutputs];
- for (var i = 0; i < outputSymbolicTensors.length; ++i) {
- internalFeedDict.add(outputSymbolicTensors[i], output[i]);
- }
- return output.length === 1 ? output[0] : output[fetch.outputTensorIndex];
- }
- function getNodeOutputs(fetch) {
- var layerOutputs;
- if (fetch.sourceLayer.inboundNodes.length === 1) {
- layerOutputs = fetch.sourceLayer.output;
- }
- else {
- var nodeIndex = null;
- for (var i = 0; i < fetch.sourceLayer.inboundNodes.length; ++i) {
- for (var _i = 0, _a = fetch.sourceLayer.inboundNodes[i]
- .outputTensors; _i < _a.length; _i++) {
- var outputTensor = _a[_i];
- if (outputTensor.id === fetch.id) {
- nodeIndex = i;
- break;
- }
- }
- }
- layerOutputs = fetch.sourceLayer.getOutputAt(nodeIndex);
- }
- return layerOutputs;
- }
- },{"../errors":176,"./topology":174}],174:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("../backend/tfjs_backend");
- var errors_1 = require("../errors");
- var serialization_1 = require("../layers/serialization");
- var types_1 = require("../types");
- var generic_utils = require("../utils/generic_utils");
- var serialization_utils_1 = require("../utils/serialization_utils");
- var variables_1 = require("../variables");
- var version_1 = require("../version");
- var InputSpec = (function () {
- function InputSpec(config) {
- this.dtype = config.dtype;
- this.shape = config.shape;
- if (config.shape != null) {
- this.ndim = config.shape.length;
- }
- else {
- this.ndim = config.ndim;
- }
- this.maxNDim = config.maxNDim;
- this.minNDim = config.minNDim;
- this.axes = config.axes || {};
- }
- return InputSpec;
- }());
- exports.InputSpec = InputSpec;
- var _nextNodeID = 0;
- var Node = (function () {
- function Node(config, callArgs) {
- this.callArgs = callArgs;
- this.id = _nextNodeID++;
- this.outboundLayer = config.outboundLayer;
- this.inboundLayers = config.inboundLayers;
- this.nodeIndices = config.nodeIndices;
- this.tensorIndices = config.tensorIndices;
- this.inputTensors = config.inputTensors;
- this.outputTensors = config.outputTensors;
- this.inputMasks = config.inputMasks;
- this.outputMasks = config.outputMasks;
- this.inputShapes = config.inputShapes;
- this.outputShapes = config.outputShapes;
- for (var _i = 0, _a = config.inboundLayers; _i < _a.length; _i++) {
- var layer = _a[_i];
- if (layer != null) {
- layer.outboundNodes.push(this);
- }
- }
- config.outboundLayer.inboundNodes.push(this);
- }
- Node.prototype.getConfig = function () {
- var inboundNames = [];
- for (var _i = 0, _a = this.inboundLayers; _i < _a.length; _i++) {
- var layer = _a[_i];
- if (layer != null) {
- inboundNames.push(layer.name);
- }
- else {
- inboundNames.push(null);
- }
- }
- return {
- outboundLayer: this.outboundLayer ? this.outboundLayer.name : null,
- inboundLayers: inboundNames,
- nodeIndices: this.nodeIndices,
- tensorIndices: this.tensorIndices
- };
- };
- return Node;
- }());
- exports.Node = Node;
- var _nextLayerID = 0;
- var Layer = (function (_super) {
- __extends(Layer, _super);
- function Layer(config) {
- var _this = _super.call(this) || this;
- _this._callHook = null;
- _this._addedWeightNames = [];
- _this._stateful = false;
- _this.id = _nextLayerID++;
- _this.activityRegularizer = null;
- _this.inputSpec = null;
- _this.supportsMasking = false;
- _this._trainableWeights = [];
- _this._nonTrainableWeights = [];
- _this._losses = [];
- _this._updates = [];
- _this._built = false;
- _this.inboundNodes = [];
- _this.outboundNodes = [];
- var name = config.name;
- if (!name) {
- var prefix = _this.getClassName();
- name = generic_utils.toSnakeCase(prefix) + '_' + K.getUid(prefix);
- }
- _this.name = name;
- _this.trainable = config.trainable == null ? true : config.trainable;
- _this.updatable = config.updatable == null ? true : config.updatable;
- if (config.inputShape != null || config.batchInputShape != null) {
- var batchInputShape = void 0;
- if (config.batchInputShape != null) {
- batchInputShape = config.batchInputShape;
- }
- else if (config.inputShape != null) {
- var batchSize = null;
- if (config.batchSize != null) {
- batchSize = config.batchSize;
- }
- batchInputShape = [batchSize].concat(config.inputShape);
- }
- _this.batchInputShape = batchInputShape;
- var dtype = config.dtype;
- if (dtype == null) {
- dtype = config.inputDType;
- }
- if (dtype == null) {
- dtype = K.floatx();
- }
- _this.dtype = dtype;
- }
- if (config.weights != null) {
- _this.initialWeights = config.weights;
- }
- else {
- _this.initialWeights = null;
- }
- return _this;
- }
- Layer.nodeKey = function (layer, nodeIndex) {
- return layer.name + '_ib-' + nodeIndex.toString();
- };
- Layer.prototype.getNodeAtIndex = function (nodeIndex, attrName) {
- if (this.inboundNodes.length === 0) {
- throw new errors_1.RuntimeError('The layer has never been called ' +
- ("and thus has no defined " + attrName + "."));
- }
- if (this.inboundNodes.length <= nodeIndex) {
- throw new errors_1.ValueError("Asked to get " + attrName + " at node " + nodeIndex + ", " +
- ("but the layer has only " + this.inboundNodes.length + " inbound nodes."));
- }
- return this.inboundNodes[nodeIndex];
- };
- Layer.prototype.getInputAt = function (nodeIndex) {
- return generic_utils.singletonOrArray(this.getNodeAtIndex(nodeIndex, 'input').inputTensors);
- };
- Layer.prototype.getOutputAt = function (nodeIndex) {
- return generic_utils.singletonOrArray(this.getNodeAtIndex(nodeIndex, 'output').outputTensors);
- };
- Object.defineProperty(Layer.prototype, "input", {
- get: function () {
- if (this.inboundNodes.length > 1) {
- throw new errors_1.AttributeError("Layer " + this.name +
- ' has multiple inbound nodes, ' +
- 'hence the notion of "layer input" ' +
- 'is ill-defined. ' +
- 'Use `getInputAt(nodeIndex)` instead.');
- }
- else if (this.inboundNodes.length === 0) {
- throw new errors_1.AttributeError("Layer " + this.name +
- ' is not connected, no input to return.');
- }
- return generic_utils.singletonOrArray(this.getNodeAtIndex(0, 'input').inputTensors);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Layer.prototype, "output", {
- get: function () {
- if (this.inboundNodes.length === 0) {
- throw new errors_1.AttributeError("Layer " + this.name +
- ' has no inbound nodes.');
- }
- if (this.inboundNodes.length > 1) {
- throw new errors_1.AttributeError("Layer " + this.name +
- ' has multiple inbound nodes, ' +
- 'hence the notion of "layer output" ' +
- 'is ill-defined. ' +
- 'Use `getOutputAt(nodeIndex)` instead.');
- }
- return generic_utils.singletonOrArray(this.getNodeAtIndex(0, 'output').outputTensors);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Layer.prototype, "losses", {
- get: function () {
- return this._losses;
- },
- enumerable: true,
- configurable: true
- });
- Layer.prototype.calculateLosses = function () {
- return this.losses.map(function (lossFn) { return lossFn(); });
- };
- Object.defineProperty(Layer.prototype, "updates", {
- get: function () {
- return this._updates;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Layer.prototype, "built", {
- get: function () {
- return this._built;
- },
- set: function (built) {
- this._built = built;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Layer.prototype, "trainableWeights", {
- get: function () {
- if (this.trainable) {
- return this._trainableWeights;
- }
- else {
- return [];
- }
- },
- set: function (weights) {
- this._trainableWeights = weights;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Layer.prototype, "nonTrainableWeights", {
- get: function () {
- if (!this.trainable) {
- return this._trainableWeights.concat(this._nonTrainableWeights);
- }
- else {
- return this._nonTrainableWeights;
- }
- },
- set: function (weights) {
- this._nonTrainableWeights = weights;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Layer.prototype, "weights", {
- get: function () {
- return this.trainableWeights.concat(this.nonTrainableWeights);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Layer.prototype, "stateful", {
- get: function () {
- return this._stateful;
- },
- enumerable: true,
- configurable: true
- });
- Layer.prototype.assertInputCompatibility = function (inputs) {
- inputs = generic_utils.toList(inputs);
- if (this.inputSpec == null || this.inputSpec.length === 0) {
- return;
- }
- var inputSpec = generic_utils.toList(this.inputSpec);
- if (inputs.length !== inputSpec.length) {
- throw new errors_1.ValueError("Layer " + this.name + " expects " + inputSpec.length + " inputs, " +
- ("but it received " + inputs.length + " input tensors. ") +
- ("Input received: " + inputs));
- }
- for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++) {
- var x = inputs[inputIndex];
- var spec = inputSpec[inputIndex];
- if (spec == null) {
- continue;
- }
- var ndim = x.rank;
- if (spec.ndim != null) {
- if (ndim !== spec.ndim) {
- throw new errors_1.ValueError("Input " + inputIndex + " is incompatible with layer " + this.name + ": " +
- ("expected ndim=" + spec.ndim + ", found ndim=" + ndim));
- }
- }
- if (spec.maxNDim != null) {
- if (ndim > spec.maxNDim) {
- throw new errors_1.ValueError("Input " + inputIndex + " is incompatible with layer " + this.name +
- (": expected max_ndim=" + spec.maxNDim + ", found ndim=" + ndim));
- }
- }
- if (spec.minNDim != null) {
- if (ndim < spec.minNDim) {
- throw new errors_1.ValueError("Input " + inputIndex + " is incompatible with layer " + this.name +
- (": expected min_ndim=" + spec.minNDim + ", found ndim=" + ndim + "."));
- }
- }
- if (spec.dtype != null) {
- if (K.dtype(x) !== spec.dtype) {
- var xDType = K.dtype(x);
- throw new errors_1.ValueError("Input " + inputIndex + " is incompatible with layer " + this.name + " " +
- (": expected dtype=" + spec.dtype + ", found dtype=" + xDType + "."));
- }
- }
- if (spec.axes) {
- var xShape = K.intShape(x);
- for (var key in spec.axes) {
- var axis = Number(key);
- var value = spec.axes[key];
- var xShapeAtAxis = axis >= 0 ? xShape[axis] : xShape[xShape.length + axis];
- if (value != null && [value, null].indexOf(xShapeAtAxis) === -1) {
- throw new errors_1.ValueError("Input " + inputIndex + " is incompatible with layer " +
- (this.name + ": expected axis " + axis + " of input shape to ") +
- ("have value " + value + " but got shape " + xShape + "."));
- }
- }
- }
- if (spec.shape != null) {
- var xShape = K.intShape(x);
- for (var i = 0; i < spec.shape.length; ++i) {
- var specDim = spec.shape[i];
- var dim = xShape[i];
- if (specDim != null && dim != null) {
- if (specDim !== dim) {
- throw new errors_1.ValueError("Input " + inputIndex + " is incompatible with layer " +
- (this.name + ": expected shape=" + spec.shape + ", ") +
- 'found shape=${xShape}.');
- }
- }
- }
- }
- }
- };
- Layer.prototype.call = function (inputs, kwargs) {
- return inputs;
- };
- Layer.prototype.invokeCallHook = function (inputs, kwargs) {
- if (this._callHook != null) {
- this._callHook(inputs, kwargs);
- }
- };
- Layer.prototype.setCallHook = function (callHook) {
- this._callHook = callHook;
- };
- Layer.prototype.clearCallHook = function () {
- this._callHook = null;
- };
- Layer.prototype.apply = function (inputs, kwargs) {
- var _this = this;
- kwargs = kwargs || {};
- var inputsList = generic_utils.toList(inputs);
- var allAreSymbolic = true;
- for (var _i = 0, inputsList_1 = inputsList; _i < inputsList_1.length; _i++) {
- var input = inputsList_1[_i];
- if (!(input instanceof types_1.SymbolicTensor)) {
- allAreSymbolic = false;
- break;
- }
- }
- var noneAreSymbolic = true;
- for (var _a = 0, inputsList_2 = inputsList; _a < inputsList_2.length; _a++) {
- var input = inputsList_2[_a];
- if (input instanceof types_1.SymbolicTensor) {
- noneAreSymbolic = false;
- break;
- }
- }
- if (allAreSymbolic === noneAreSymbolic) {
- throw new errors_1.ValueError('Arguments to apply() must be all ' +
- 'SymbolicTensors or all Tensors');
- }
- return K.nameScope(this.name, function () {
- if (!_this.built) {
- _this.assertInputCompatibility(inputs);
- var inputShapes = [];
- for (var _i = 0, _a = generic_utils.toList(inputs); _i < _a.length; _i++) {
- var xElem = _a[_i];
- inputShapes.push(K.intShape(xElem));
- }
- _this.build(generic_utils.singletonOrArray(inputShapes));
- _this.built = true;
- if (_this.initialWeights) {
- _this.setWeights(_this.initialWeights);
- }
- }
- _this.assertInputCompatibility(inputs);
- if (noneAreSymbolic) {
- var output = _this.call(inputs, kwargs);
- var outputList = generic_utils.toList(output);
- var outputListCopy = [];
- for (var _b = 0, outputList_1 = outputList; _b < outputList_1.length; _b++) {
- var x = outputList_1[_b];
- if (inputsList.indexOf(x) !== -1) {
- x = K.identity(x);
- }
- outputListCopy.push(x);
- }
- output = generic_utils.singletonOrArray(outputListCopy);
- if (_this.activityRegularizer != null) {
- throw new errors_1.NotImplementedError('Layer invocation in the presence of activity ' +
- 'regularizer(s) is not supported yet.');
- }
- return output;
- }
- else {
- var inputShape = collectInputShape(inputs);
- var outputShape = _this.computeOutputShape(inputShape);
- var output = void 0;
- var outputDType_1 = guessOutputDType(inputs);
- if (outputShape != null && outputShape.length > 0 &&
- Array.isArray(outputShape[0])) {
- output = outputShape
- .map(function (shape, index) { return new types_1.SymbolicTensor(outputDType_1, shape, _this, generic_utils.toList(inputs), kwargs, _this.name, index); });
- }
- else {
- output = new types_1.SymbolicTensor(outputDType_1, outputShape, _this, generic_utils.toList(inputs), kwargs, _this.name);
- }
- _this.addInboundNode(inputs, output, null, null, inputShape, outputShape, kwargs);
- if (_this.activityRegularizer != null) {
- throw new errors_1.NotImplementedError('Layer invocation in the presence of activity ' +
- 'regularizer(s) is not supported yet.');
- }
- return output;
- }
- });
- };
- Object.defineProperty(Layer.prototype, "outputShape", {
- get: function () {
- if (this.inboundNodes == null || this.inboundNodes.length === 0) {
- throw new errors_1.AttributeError("The layer " + this.name + " has never been called and thus has no " +
- "defined output shape.");
- }
- var allOutputShapes = [];
- for (var _i = 0, _a = this.inboundNodes; _i < _a.length; _i++) {
- var node = _a[_i];
- var shapeString = JSON.stringify(node.outputShapes);
- if (allOutputShapes.indexOf(shapeString) === -1) {
- allOutputShapes.push(shapeString);
- }
- }
- if (allOutputShapes.length === 1) {
- var outputShapes = this.inboundNodes[0].outputShapes;
- if (Array.isArray(outputShapes) && Array.isArray(outputShapes[0]) &&
- outputShapes.length === 1) {
- return outputShapes[0];
- }
- else {
- return outputShapes;
- }
- }
- else {
- throw new errors_1.AttributeError("The layer " + this.name + " has multiple inbound nodes with different " +
- "output shapes. Hence the notion of \"outut shape\" is ill-defined " +
- "for the layer.");
- }
- },
- enumerable: true,
- configurable: true
- });
- Layer.prototype.countParams = function () {
- if (!this.built) {
- throw new errors_1.RuntimeError("You tried to call countParams() on " + this.name + ", " +
- "but the layer is not built yet. Build it first by calling " +
- "build(batchInputShape).");
- }
- return generic_utils.countParamsInWeights(this.weights);
- };
- Layer.prototype.build = function (inputShape) {
- this.built = true;
- };
- Layer.prototype.getWeights = function (trainableOnly) {
- if (trainableOnly === void 0) { trainableOnly = false; }
- return variables_1.batchGetValue(trainableOnly ? this.trainableWeights : this.weights);
- };
- Layer.prototype.setWeights = function (weights) {
- var _this = this;
- tfjs_core_1.tidy(function () {
- var params = _this.weights;
- if (params.length !== weights.length) {
- throw new errors_1.ValueError("You called setWeights(weights) on layer \"" + _this.name + "\" " +
- ("with a weight list of length " + weights.length + ", ") +
- ("but the layer was expecting " + params.length + " weights. ") +
- ("Provided weights: " + weights + "..."));
- }
- if (params.length === 0) {
- return;
- }
- var weightValueTuples = [];
- var paramValues = variables_1.batchGetValue(params);
- for (var i = 0; i < paramValues.length; ++i) {
- var pv = paramValues[i];
- var p = params[i];
- var w = weights[i];
- if (!tfjs_core_1.util.arraysEqual(pv.shape, w.shape)) {
- throw new errors_1.ValueError("Layer weight shape " + pv.shape + " " +
- ("not compatible with provided weight shape " + w.shape));
- }
- weightValueTuples.push([p, w]);
- }
- variables_1.batchSetValue(weightValueTuples);
- });
- };
- Layer.prototype.addWeight = function (name, shape, dtype, initializer, regularizer, trainable, constraint) {
- if (this._addedWeightNames.indexOf(name) !== -1) {
- throw new errors_1.ValueError("Duplicate weight name " + name + " for layer " + this.name);
- }
- this._addedWeightNames.push(name);
- if (dtype == null) {
- dtype = K.floatx();
- }
- var weight = new variables_1.LayerVariable(initializer.apply(shape, dtype), dtype, name, trainable, constraint);
- if (regularizer != null) {
- this.addLoss(function () { return regularizer.apply(weight.read()); });
- }
- if (trainable == null) {
- trainable = true;
- }
- if (trainable) {
- this._trainableWeights.push(weight);
- }
- else {
- this._nonTrainableWeights.push(weight);
- }
- return weight;
- };
- Layer.prototype.addLoss = function (losses) {
- if (losses == null || Array.isArray(losses) && losses.length === 0) {
- return;
- }
- losses = generic_utils.toList(losses);
- if (this._losses !== undefined && this._losses !== null) {
- (_a = this.losses).push.apply(_a, losses);
- }
- var _a;
- };
- Layer.prototype.computeOutputShape = function (inputShape) {
- return inputShape;
- };
- Layer.prototype.computeMask = function (inputs, mask) {
- var _this = this;
- if (!this.supportsMasking) {
- if (mask != null) {
- if (Array.isArray(mask)) {
- mask.forEach(function (maskElement) {
- if (maskElement != null) {
- throw new TypeError("Layer " + _this.name + " does not support masking," +
- 'but was passed an inputMask.');
- }
- });
- }
- else {
- throw new TypeError("Layer " + this.name + " does not support masking," +
- 'but was passed an inputMask.');
- }
- }
- return null;
- }
- return mask;
- };
- Layer.prototype.addInboundNode = function (inputTensors, outputTensors, inputMasks, outputMasks, inputShapes, outputShapes, kwargs) {
- if (kwargs === void 0) { kwargs = null; }
- var inputTensorList = generic_utils.toList(inputTensors);
- outputTensors = generic_utils.toList(outputTensors);
- inputMasks = generic_utils.toList(inputMasks);
- outputMasks = generic_utils.toList(outputMasks);
- inputShapes = generic_utils.normalizeShapeList(inputShapes);
- outputShapes = generic_utils.normalizeShapeList(outputShapes);
- var inboundLayers = [];
- var nodeIndices = [];
- var tensorIndices = [];
- for (var _i = 0, inputTensorList_1 = inputTensorList; _i < inputTensorList_1.length; _i++) {
- var x = inputTensorList_1[_i];
- inboundLayers.push(x.sourceLayer);
- nodeIndices.push(x.nodeIndex);
- tensorIndices.push(x.tensorIndex);
- }
- new Node({
- outboundLayer: this,
- inboundLayers: inboundLayers,
- nodeIndices: nodeIndices,
- tensorIndices: tensorIndices,
- inputTensors: inputTensorList,
- outputTensors: outputTensors,
- inputMasks: inputMasks,
- outputMasks: outputMasks,
- inputShapes: inputShapes,
- outputShapes: outputShapes
- }, kwargs);
- for (var i = 0; i < outputTensors.length; i++) {
- outputTensors[i].sourceLayer = this;
- outputTensors[i].nodeIndex = this.inboundNodes.length - 1;
- outputTensors[i].tensorIndex = i;
- }
- };
- Layer.prototype.getConfig = function () {
- var config = { name: this.name, trainable: this.trainable };
- if (this.batchInputShape != null) {
- config['batchInputShape'] = this.batchInputShape;
- }
- if (this.dtype != null) {
- config['dtype'] = this.dtype;
- }
- return config;
- };
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', 'subheading': 'Classes' })
- ], Layer.prototype, "apply", null);
- Layer = __decorate([
- tfjs_core_1.doc({ heading: 'Layers', subheading: 'Classes', namespace: 'layers' })
- ], Layer);
- return Layer;
- }(tfjs_core_1.serialization.Serializable));
- exports.Layer = Layer;
- function collectInputShape(inputTensors) {
- inputTensors =
- generic_utils.toList(inputTensors);
- var shapes = [];
- for (var _i = 0, inputTensors_1 = inputTensors; _i < inputTensors_1.length; _i++) {
- var x = inputTensors_1[_i];
- shapes.push(K.intShape(x));
- }
- return generic_utils.singletonOrArray(shapes);
- }
- function guessOutputDType(inputTensors) {
- return 'float32';
- }
- var InputLayer = (function (_super) {
- __extends(InputLayer, _super);
- function InputLayer(config) {
- var _this = _super.call(this, {
- dtype: config.dtype,
- name: config.name != null ? config.name : K.getUid('input').toString()
- }) || this;
- if (config.batchSize == null) {
- config.batchSize = null;
- }
- if (config.sparse == null) {
- config.sparse = false;
- }
- _this.trainable = false;
- _this.built = true;
- _this.sparse = config.sparse;
- if (config.inputShape != null && config.batchInputShape != null) {
- throw new errors_1.ValueError('Only provide the inputShape OR ' +
- 'batchInputShape argument to inputLayer, not both at the same time.');
- }
- var batchInputShape = config.batchInputShape;
- if (batchInputShape == null) {
- if (config.inputShape == null) {
- throw new errors_1.ValueError('An InputLayer should be passed either a ' +
- '`batchInputShape` or an `inputShape`.');
- }
- else {
- batchInputShape = [config.batchSize].concat(config.inputShape);
- }
- }
- else {
- if (config.batchSize != null) {
- throw new errors_1.ValueError('Cannot specify batchSize if batchInputShape is' +
- 'specified when creating an InputLayer.');
- }
- }
- var dtype = config.dtype || K.floatx();
- _this.batchInputShape = batchInputShape;
- _this.dtype = dtype;
- _this.inputSpec = [{ shape: batchInputShape }];
- var inputTensor = new types_1.SymbolicTensor(_this.dtype, _this.batchInputShape, _this, [], {}, _this.name);
- inputTensor.nodeIndex = 0;
- inputTensor.tensorIndex = 0;
- new Node({
- outboundLayer: _this,
- inboundLayers: [],
- nodeIndices: [],
- tensorIndices: [],
- inputTensors: [inputTensor],
- outputTensors: [inputTensor],
- inputMasks: [null],
- outputMasks: [null],
- inputShapes: [batchInputShape],
- outputShapes: [batchInputShape]
- });
- return _this;
- }
- InputLayer.prototype.apply = function (inputs, kwargs) {
- throw new errors_1.ValueError('Cannot pass any input to an ' +
- ("InputLayer's apply() method. InputLayer name: " + this.name));
- };
- InputLayer.prototype.getConfig = function () {
- return {
- batchInputShape: this.batchInputShape,
- dtype: this.dtype,
- sparse: this.sparse,
- name: this.name
- };
- };
- InputLayer.className = 'InputLayer';
- return InputLayer;
- }(Layer));
- exports.InputLayer = InputLayer;
- tfjs_core_1.serialization.SerializationMap.register(InputLayer);
- function Input(config) {
- if (config.batchShape == null && config.shape == null) {
- throw new Error('Please provide to Input either a `shape`' +
- ' or a `batchShape` argument. Note that ' +
- '`shape` does not include the batch ' +
- 'dimension.');
- }
- if (config.batchShape != null && config.shape != null) {
- throw new errors_1.ValueError('Please provide either a `shape` or `batchShape` ' +
- 'argument to Input, but not both.');
- }
- var batchShape = config.batchShape;
- if (config.shape != null && batchShape == null) {
- batchShape = [null].concat(config.shape);
- }
- var dtype = config.dtype;
- if (dtype == null) {
- dtype = K.floatx();
- }
- var inputLayer = new InputLayer({
- batchInputShape: batchShape,
- name: config.name,
- dtype: dtype,
- sparse: config.sparse
- });
- var outputs = inputLayer.inboundNodes[0].outputTensors;
- return outputs[0];
- }
- exports.Input = Input;
- var Container = (function (_super) {
- __extends(Container, _super);
- function Container(config) {
- var _this = _super.call(this, {}) || this;
- _this.containerNodes = new Set();
- _this.name = config.name;
- if (_this.name == null) {
- var prefix = _this.getClassName().toLowerCase();
- _this.name = K.getUid(prefix);
- }
- _this.supportsMasking = false;
- _this.trainable = true;
- _this.updatable = true;
- if (Array.isArray(config.inputs)) {
- _this.inputs = config.inputs.slice();
- }
- else {
- _this.inputs = [config.inputs];
- }
- if (Array.isArray(config.outputs)) {
- _this.outputs = config.outputs.slice();
- }
- else {
- _this.outputs = [config.outputs];
- }
- if (generic_utils.unique(_this.inputs).length !== _this.inputs.length) {
- throw new errors_1.ValueError('The list of inputs passed to the model is ' +
- 'redundant. All inputs should only appear once. Found: ' +
- _this.inputs.map(function (x) { return x.name; }));
- }
- if (generic_utils.unique(_this.outputs).length !== _this.outputs.length) {
- console.warn('The list of outputs passed to the model is redundant. ' +
- 'All outputs should only appear once. Found: ' +
- _this.outputs.map(function (x) { return x.name; }));
- }
- _this.inputLayers = [];
- _this.inputLayersNodeIndices = [];
- _this.inputLayersTensorIndices = [];
- _this.outputLayers = [];
- _this.outputLayersNodeIndices = [];
- _this.outputLayersTensorIndices = [];
- _this.layers = [];
- for (var _i = 0, _a = _this.outputs; _i < _a.length; _i++) {
- var x = _a[_i];
- var layer = x.sourceLayer;
- var nodeIndex = x.nodeIndex;
- var tensorIndex = x.tensorIndex;
- _this.outputLayers.push(layer);
- _this.outputLayersNodeIndices.push(nodeIndex);
- _this.outputLayersTensorIndices.push(tensorIndex);
- }
- for (var _b = 0, _c = _this.inputs; _b < _c.length; _b++) {
- var x = _c[_b];
- var layer = x.sourceLayer;
- var nodeIndex = x.nodeIndex;
- var tensorIndex = x.tensorIndex;
- generic_utils.assert(nodeIndex === 0, 'input layer has >1 nodes');
- generic_utils.assert(tensorIndex === 0, 'input layer has >1 tensors');
- _this.inputLayers.push(layer);
- _this.inputLayersNodeIndices.push(nodeIndex);
- _this.inputLayersTensorIndices.push(tensorIndex);
- }
- _this.inputNames = [];
- _this.outputNames = [];
- _this.feedInputShapes = [];
- _this.feedInputNames = [];
- _this.feedOutputNames = [];
- for (var i = 0; i < _this.inputLayers.length; i++) {
- var layer = _this.inputLayers[i];
- if (!(layer instanceof InputLayer)) {
- throw new TypeError('Input layers to a Model must be InputLayer objects. ' +
- ("Received inputs: " + config.inputs + ". ") +
- ("Input " + i + " (0-based) originates ") +
- ("from layer type " + layer.getClassName() + "."));
- }
- _this.inputNames.push(layer.name);
- _this.feedInputShapes.push(layer.batchInputShape);
- _this.feedInputNames.push(layer.name);
- }
- for (var _d = 0, _e = _this.outputLayers; _d < _e.length; _d++) {
- var layer = _e[_d];
- _this.outputNames.push(layer.name);
- }
- _this.internalInputShapes = _this.inputs.map(function (x) { return x.shape; });
- _this.internalOutputShapes = _this.outputs.map(function (x) { return x.shape; });
- var nodesDepths = {};
- var nodeIDToNode = {};
- var layersDepths = {};
- var layerIDToLayer = {};
- var layerIndices = {};
- var nodesInDecreasingDepth = [];
- var buildMapOfGraph = function (tensor, finishedNodes, nodesInProgress, layer, nodeIndex, tensorIndex) {
- if (layer == null || nodeIndex == null || tensorIndex == null) {
- layer = tensor.sourceLayer;
- nodeIndex = tensor.nodeIndex;
- tensorIndex = tensor.tensorIndex;
- }
- var node = layer.inboundNodes[nodeIndex];
- if (nodesInProgress.indexOf(node) !== -1) {
- throw new errors_1.RuntimeError("The tensor " + tensor.name + " at layer \"" + layer.name + "\" " +
- 'is part of a cycle.');
- }
- if (finishedNodes.indexOf(node) !== -1) {
- return;
- }
- _this.containerNodes.add(Container.nodeKey(layer, nodeIndex));
- if (!(layer.id in layerIndices)) {
- layerIndices[layer.id] = Object.keys(layerIndices).length;
- }
- if (nodesInProgress.indexOf(node) === -1) {
- nodesInProgress.push(node);
- }
- var numInboundLayers = node.inboundLayers.length;
- for (var i = 0; i < numInboundLayers; i++) {
- var x = node.inputTensors[i];
- var layer_1 = node.inboundLayers[i];
- var nodeIndex_1 = node.nodeIndices[i];
- var tensorIndex_1 = node.tensorIndices[i];
- buildMapOfGraph(x, finishedNodes, nodesInProgress, layer_1, nodeIndex_1, tensorIndex_1);
- }
- finishedNodes.push(node);
- while (nodesInProgress.indexOf(node) >= 0) {
- nodesInProgress.splice(nodesInProgress.indexOf(node), 1);
- }
- nodesInDecreasingDepth.push(node);
- };
- var finishedNodes = [];
- var nodesInProgress = [];
- for (var _f = 0, _g = _this.outputs; _f < _g.length; _f++) {
- var x = _g[_f];
- buildMapOfGraph(x, finishedNodes, nodesInProgress);
- }
- var reversedNodesInDecreasingDepth = nodesInDecreasingDepth.slice().reverse();
- for (var _h = 0, reversedNodesInDecreasingDepth_1 = reversedNodesInDecreasingDepth; _h < reversedNodesInDecreasingDepth_1.length; _h++) {
- var node = reversedNodesInDecreasingDepth_1[_h];
- nodeIDToNode[node.id] = node;
- if (!(node.id in nodesDepths)) {
- nodesDepths[node.id] = 0;
- }
- var depth = nodesDepths[node.id];
- var previousDepth = (layersDepths[node.outboundLayer.id] == null ?
- 0 :
- layersDepths[node.outboundLayer.id]);
- depth = Math.max(depth, previousDepth);
- layersDepths[node.outboundLayer.id] = depth;
- layerIDToLayer[node.outboundLayer.id] = node.outboundLayer;
- nodesDepths[node.id] = depth;
- for (var i = 0; i < node.inboundLayers.length; i++) {
- var inboundLayer = node.inboundLayers[i];
- var nodeIndex = node.nodeIndices[i];
- var inboundNode = inboundLayer.inboundNodes[nodeIndex];
- var previousDepth_1 = (nodesDepths[inboundNode.id] == null ? 0 :
- nodesDepths[inboundNode.id]);
- nodesDepths[inboundNode.id] = Math.max(depth + 1, previousDepth_1);
- nodeIDToNode[inboundNode.id] = inboundNode;
- }
- }
- var nodesByDepth = {};
- for (var nodeID in nodesDepths) {
- var depth = nodesDepths[nodeID];
- if (!(depth in nodesByDepth)) {
- nodesByDepth[depth] = [];
- }
- nodesByDepth[depth].push(nodeIDToNode[nodeID]);
- }
- var layersByDepth = {};
- for (var layerID in layersDepths) {
- var depth = layersDepths[layerID];
- if (!(depth in layersByDepth)) {
- layersByDepth[depth] = [];
- }
- layersByDepth[depth].push(layerIDToLayer[layerID]);
- }
- var depthKeys = Object.keys(layersByDepth)
- .map(function (x) { return parseInt(x, 10); })
- .sort(generic_utils.reverseNumberCompare);
- _this.layers = [];
- for (var _j = 0, depthKeys_1 = depthKeys; _j < depthKeys_1.length; _j++) {
- var depth = depthKeys_1[_j];
- var layersForDepth = layersByDepth[depth];
- layersForDepth.sort(function (a, b) {
- var aIndex = layerIndices[a.id];
- var bIndex = layerIndices[b.id];
- if (aIndex < bIndex) {
- return -1;
- }
- if (aIndex > bIndex) {
- return 1;
- }
- return 0;
- });
- for (var _k = 0, layersForDepth_1 = layersForDepth; _k < layersForDepth_1.length; _k++) {
- var layer = layersForDepth_1[_k];
- _this.layers.push(layer);
- }
- }
- _this.layersByDepth = layersByDepth;
- depthKeys = Object.keys(nodesByDepth)
- .map(function (x) { return parseInt(x, 10); })
- .sort(generic_utils.reverseNumberCompare);
- var computableTensors = _this.inputs.slice();
- var layersWithCompleteInput = [];
- for (var _l = 0, depthKeys_2 = depthKeys; _l < depthKeys_2.length; _l++) {
- var depth = depthKeys_2[_l];
- for (var _m = 0, _o = nodesByDepth[depth]; _m < _o.length; _m++) {
- var node = _o[_m];
- var layer = node.outboundLayer;
- if (layer != null) {
- for (var _p = 0, _q = node.inputTensors; _p < _q.length; _p++) {
- var x = _q[_p];
- if (computableTensors.indexOf(x) === -1) {
- throw new errors_1.RuntimeError("Graph disconnected: cannot obtain value for tensor " + x +
- (" at layer \"" + layer.name + "\". ") +
- 'The following previous layers were accessed without ' +
- ("issue: " + layersWithCompleteInput));
- }
- }
- for (var _r = 0, _s = node.outputTensors; _r < _s.length; _r++) {
- var x = _s[_r];
- computableTensors.push(x);
- }
- layersWithCompleteInput.push(layer.name);
- }
- }
- }
- _this.nodesByDepth = nodesByDepth;
- var allNames = _this.layers.map(function (x) { return x.name; });
- var _loop_1 = function (name_1) {
- var numOccurrences = allNames.filter(function (x) { return x === name_1; }).length;
- if (numOccurrences !== 1) {
- throw new errors_1.RuntimeError("The name \"" + name_1 + "\" is used " + numOccurrences + " times " +
- 'in the model. All layer names should be unique. Layer names: ' +
- JSON.stringify(allNames));
- }
- };
- for (var _t = 0, allNames_1 = allNames; _t < allNames_1.length; _t++) {
- var name_1 = allNames_1[_t];
- _loop_1(name_1);
- }
- _this.outboundNodes = [];
- _this.inboundNodes = [];
- new Node({
- outboundLayer: _this,
- inboundLayers: [],
- nodeIndices: [],
- tensorIndices: [],
- inputTensors: _this.inputs,
- outputTensors: _this.outputs,
- inputMasks: _this.inputs.map(function (x) { return null; }),
- outputMasks: _this.outputs.map(function (x) { return null; }),
- inputShapes: _this.inputs.map(function (x) { return x.shape; }),
- outputShapes: _this.outputs.map(function (x) { return x.shape; })
- });
- _this.built = true;
- return _this;
- }
- Object.defineProperty(Container.prototype, "trainableWeights", {
- get: function () {
- if (this._trainableWeights.length > 0) {
- throw new errors_1.ValueError('Container instance unexpectedly contains _trainableWeights.' +
- 'The trainable weights of a Container are a union of the ' +
- 'trainable weights of its consituent Layers. Its own ' +
- '_trainableWeights must remain an empty Array.');
- }
- if (!this.trainable) {
- return [];
- }
- var weights = [];
- for (var _i = 0, _a = this.layers; _i < _a.length; _i++) {
- var layer = _a[_i];
- weights = weights.concat(layer.trainableWeights);
- }
- return weights;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Container.prototype, "nonTrainableWeights", {
- get: function () {
- var weights = [];
- for (var _i = 0, _a = this.layers; _i < _a.length; _i++) {
- var layer = _a[_i];
- weights.push.apply(weights, layer.nonTrainableWeights);
- }
- if (!this.trainable) {
- var trainableWeights = [];
- for (var _b = 0, _c = this.layers; _b < _c.length; _b++) {
- var layer = _c[_b];
- trainableWeights.push.apply(trainableWeights, layer.trainableWeights);
- }
- return trainableWeights.concat(weights);
- }
- return weights;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Container.prototype, "weights", {
- get: function () {
- return this.trainableWeights.concat(this.nonTrainableWeights);
- },
- enumerable: true,
- configurable: true
- });
- Container.prototype.loadWeights = function (weightsJSON, skipMismatch, isNamedTensorMap) {
- if (skipMismatch === void 0) { skipMismatch = false; }
- if (isNamedTensorMap === void 0) { isNamedTensorMap = false; }
- if (isNamedTensorMap) {
- loadWeightsFromNamedTensorMap(weightsJSON, this.layers);
- }
- else {
- loadWeightsFromJson(weightsJSON, this.layers, skipMismatch);
- }
- };
- Container.prototype.updatedConfig = function () {
- var theConfig = this.getConfig();
- var modelConfig = {
- className: this.getClassName(),
- config: theConfig,
- kerasVersion: "tfjs-layers " + version_1.version,
- backend: 'TensorFlow.js'
- };
- return modelConfig;
- };
- Container.prototype.toJSON = function (unused, returnString) {
- if (returnString === void 0) { returnString = true; }
- var modelConfig = serialization_utils_1.convertTsToPythonic(this.updatedConfig());
- return returnString ? JSON.stringify(modelConfig) : modelConfig;
- };
- Container.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- inputs = generic_utils.toList(inputs);
- var masks;
- if ('mask' in kwargs) {
- masks = generic_utils.toList(kwargs['mask']);
- }
- else {
- masks = generic_utils.pyListRepeat(null, inputs.length);
- }
- return _this.runInternalGraph(inputs, masks)[0];
- });
- };
- Container.prototype.computeMask = function (inputs, mask) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- inputs = generic_utils.toList(inputs);
- var masks;
- if (mask == null) {
- masks = generic_utils.pyListRepeat(null, inputs.length);
- }
- else {
- masks = generic_utils.toList(mask);
- }
- return _this.runInternalGraph(inputs, masks)[1];
- });
- };
- Container.prototype.computeOutputShape = function (inputShape) {
- var inputShapes = generic_utils.normalizeShapeList(inputShape);
- if (inputShapes.length !== this.inputLayers.length) {
- throw new errors_1.ValueError("Invalid inputShape argument " + inputShape + ": " +
- ("model has " + this.inputLayers.length + " tensor inputs."));
- }
- var layersToOutputShapes = {};
- for (var i = 0; i < inputShapes.length; i++) {
- var layer = this.inputLayers[i];
- var inputShape_1 = inputShapes[i];
- var shapeKey = layer.name + '_0_0';
- layersToOutputShapes[shapeKey] = inputShape_1;
- }
- var depthKeys = Object.keys(this.nodesByDepth)
- .map(function (x) { return parseInt(x, 10); })
- .sort(generic_utils.reverseNumberCompare);
- if (depthKeys.length > 1) {
- for (var _i = 0, depthKeys_3 = depthKeys; _i < depthKeys_3.length; _i++) {
- var depth = depthKeys_3[_i];
- var nodes = this.nodesByDepth[depth];
- for (var _a = 0, nodes_1 = nodes; _a < nodes_1.length; _a++) {
- var node = nodes_1[_a];
- var layer = node.outboundLayer;
- if (this.inputLayers.map(function (x) { return x.id; }).indexOf(layer.id) !== -1) {
- continue;
- }
- var inputShapes_1 = [];
- for (var j = 0; j < node.inboundLayers.length; j++) {
- var inboundLayer = node.inboundLayers[j];
- var nodeIndex_2 = node.nodeIndices[j];
- var tensorIndex = node.tensorIndices[j];
- var shapeKey = inboundLayer.name + "_" + nodeIndex_2 + "_" + tensorIndex;
- var inputShape_2 = layersToOutputShapes[shapeKey];
- inputShapes_1.push(inputShape_2);
- }
- var outputShape = layer.computeOutputShape(generic_utils.singletonOrArray(inputShapes_1));
- var outputShapes_1 = generic_utils.normalizeShapeList(outputShape);
- var nodeIndex = layer.inboundNodes.indexOf(node);
- for (var j = 0; j < outputShapes_1.length; j++) {
- var shapeKey = layer.name + "_" + nodeIndex + "_" + j;
- layersToOutputShapes[shapeKey] = outputShapes_1[j];
- }
- }
- }
- }
- var outputShapes = [];
- var outputShapeKeys = [];
- for (var i = 0; i < this.outputLayers.length; i++) {
- var layer = this.outputLayers[i];
- var nodeIndex = this.outputLayersNodeIndices[i];
- var tensorIndex = this.outputLayersTensorIndices[i];
- var shapeKey = layer.name + "_" + nodeIndex + "_" + tensorIndex;
- outputShapeKeys.push(shapeKey);
- }
- for (var i = 0; i < outputShapeKeys.length; i++) {
- var key = outputShapeKeys[i];
- generic_utils.assert(key in layersToOutputShapes);
- outputShapes.push(layersToOutputShapes[key]);
- }
- return generic_utils.singletonOrArray(outputShapes);
- };
- Container.prototype.runInternalGraph = function (inputs, masks) {
- if (masks == null) {
- masks = generic_utils.pyListRepeat(null, inputs.length);
- }
- var tensorMap = {};
- for (var i = 0; i < this.inputs.length; ++i) {
- var x = this.inputs[i];
- var y = inputs[i];
- var mask = masks[i];
- tensorMap[x.id] = [y, mask];
- }
- var depthKeys = Object.keys(this.nodesByDepth)
- .map(function (x) { return parseInt(x, 10); })
- .sort(generic_utils.reverseNumberCompare);
- for (var _i = 0, depthKeys_4 = depthKeys; _i < depthKeys_4.length; _i++) {
- var depth = depthKeys_4[_i];
- var nodes = this.nodesByDepth[depth];
- for (var _a = 0, nodes_2 = nodes; _a < nodes_2.length; _a++) {
- var node = nodes_2[_a];
- var layer = node.outboundLayer;
- var referenceInputTensors = node.inputTensors;
- var referenceOutputTensors = node.outputTensors;
- var computedData = new Array();
- for (var _b = 0, referenceInputTensors_1 = referenceInputTensors; _b < referenceInputTensors_1.length; _b++) {
- var x = referenceInputTensors_1[_b];
- if (x.id in tensorMap) {
- computedData.push(tensorMap[x.id]);
- }
- }
- if (computedData.length === referenceInputTensors.length) {
- var kwargs = {};
- var computedTensors = void 0;
- var computedMasks = void 0;
- var outputTensors_1 = void 0;
- var outputMasks_1 = void 0;
- if (node.callArgs != null) {
- kwargs = node.callArgs;
- }
- if (computedData.length === 1) {
- var _c = computedData[0], computedTensor = _c[0], computedMask = _c[1];
- if (kwargs.mask == null) {
- kwargs['mask'] = computedMask;
- }
- outputTensors_1 =
- generic_utils.toList(layer.call(computedTensor, kwargs));
- outputMasks_1 = generic_utils.toList(layer.computeMask(computedTensor, computedMask));
- computedTensors = [computedTensor];
- computedMasks = [computedMask];
- }
- else {
- computedTensors = computedData.map(function (x) { return x[0]; });
- computedMasks = computedData.map(function (x) { return x[1]; });
- if (kwargs.mask == null) {
- kwargs['mask'] = computedMasks;
- }
- outputTensors_1 =
- generic_utils.toList(layer.call(computedTensors, kwargs));
- outputMasks_1 = generic_utils.toList(layer.computeMask(computedTensors, computedMasks));
- }
- if (layer.activityRegularizer) {
- throw new errors_1.NotImplementedError('Model invocation with concrete Tensor value(s) in the ' +
- 'presence of activity regularizer(s) is not supported yet.');
- }
- for (var i = 0; i < referenceOutputTensors.length; ++i) {
- var x = referenceOutputTensors[i];
- var y = outputTensors_1[i];
- var mask = outputMasks_1[i];
- tensorMap[x.id] = [y, mask];
- }
- }
- }
- }
- var outputTensors = [];
- var outputMasks = [];
- var outputShapes = [];
- for (var _d = 0, _e = this.outputs; _d < _e.length; _d++) {
- var x = _e[_d];
- generic_utils.assert(x.id in tensorMap, "Could not compute output " + x.name + " : " + x.id);
- var _f = tensorMap[x.id], tensor = _f[0], mask = _f[1];
- outputShapes.push(tensor.shape);
- outputTensors.push(tensor);
- outputMasks.push(mask);
- }
- return [outputTensors, outputMasks, outputShapes];
- };
- Container.prototype.buildNodeConversionMap = function (layers) {
- var nodeConversionMap = {};
- var keptNodes;
- for (var _i = 0, _a = this.layers; _i < _a.length; _i++) {
- var layer = _a[_i];
- keptNodes = layer instanceof Container ? 1 : 0;
- for (var originalNodeIndex = 0; originalNodeIndex < layer.inboundNodes.length; originalNodeIndex++) {
- var nodeKey = Container.nodeKey(layer, originalNodeIndex);
- if (nodeKey in this.containerNodes) {
- nodeConversionMap[nodeKey] = keptNodes;
- keptNodes += 1;
- }
- }
- }
- return nodeConversionMap;
- };
- Container.prototype.getLayer = function (name, index) {
- if (index != null) {
- if (this.layers.length <= index) {
- throw new errors_1.ValueError("Was asked to retrieve layer at index " + index + ", but model only " +
- ("has " + this.layers.length + " layer(s)."));
- }
- else {
- return this.layers[index];
- }
- }
- else {
- if (name == null) {
- throw new errors_1.ValueError('Provide either a layer name or layer index');
- }
- }
- for (var _i = 0, _a = this.layers; _i < _a.length; _i++) {
- var layer = _a[_i];
- if (layer.name === name) {
- return layer;
- }
- }
- throw new errors_1.ValueError("No such layer: " + name);
- };
- Container.prototype.calculateLosses = function () {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- var losses = [];
- for (var _i = 0, _a = _this.layers; _i < _a.length; _i++) {
- var layer = _a[_i];
- for (var nodeIndex = 0; nodeIndex < layer.inboundNodes.length; ++nodeIndex) {
- var nodeKey = Container.nodeKey(layer, nodeIndex);
- if (_this.containerNodes.has(nodeKey)) {
- losses.push.apply(losses, layer.calculateLosses());
- }
- }
- }
- return losses;
- });
- };
- Container.prototype.getConfig = function () {
- var config = { name: this.name };
- var nodeConversionMap = this.buildNodeConversionMap(this.layers);
- var layerConfigs = [];
- for (var _i = 0, _a = this.layers; _i < _a.length; _i++) {
- var layer = _a[_i];
- var layerClassName = layer.getClassName();
- var layerConfig = layer.getConfig();
- var filteredInboundNodes = [];
- for (var originalNodeIndex = 0; originalNodeIndex < layer.inboundNodes.length; originalNodeIndex++) {
- var node = layer.inboundNodes[originalNodeIndex];
- var nodeKey = Container.nodeKey(layer, originalNodeIndex);
- var kwargs = {};
- if (this.containerNodes.has(nodeKey)) {
- if (node.callArgs) {
- var testString = JSON.stringify(node.callArgs);
- if (testString.indexOf('undefined') === -1) {
- kwargs = node.callArgs;
- }
- else {
- console.warn("Layer " + layer.name + " was passed " +
- "non-serializable keyword arguments: " +
- (node.callArgs + ". They will not be included ") +
- "in the serialized model (and thus will be " +
- "missing at deserialization time).");
- kwargs = {};
- }
- }
- if (node.inboundLayers.length > 0) {
- var nodeData = [];
- for (var i = 0; i < node.inboundLayers.length; i++) {
- var inboundLayer = node.inboundLayers[i];
- var nodeIndex = node.nodeIndices[i];
- var tensorIndex = node.tensorIndices[i];
- var nodeKey_1 = Container.nodeKey(inboundLayer, nodeIndex);
- var newNodeIndex = nodeConversionMap[nodeKey_1];
- if (newNodeIndex === null || newNodeIndex === undefined) {
- newNodeIndex = 0;
- }
- nodeData.push([inboundLayer.name, newNodeIndex, tensorIndex, kwargs]);
- }
- filteredInboundNodes.push(nodeData);
- }
- }
- }
- layerConfigs.push({
- name: layer.name,
- className: layerClassName,
- config: layerConfig,
- inboundNodes: filteredInboundNodes
- });
- }
- config['layers'] = layerConfigs;
- var modelInputs = [];
- for (var i = 0; i < this.inputLayers.length; i++) {
- var layer = this.inputLayers[i];
- var nodeIndex = this.inputLayersNodeIndices[i];
- var nodeKey = Container.nodeKey(layer, nodeIndex);
- if (!this.containerNodes.has(nodeKey)) {
- continue;
- }
- var newNodeIndex = nodeConversionMap[nodeKey];
- if (newNodeIndex === null || newNodeIndex === undefined) {
- newNodeIndex = 0;
- }
- var tensorIndex = this.inputLayersTensorIndices[i];
- modelInputs.push([layer.name, newNodeIndex, tensorIndex]);
- }
- config['inputLayers'] = modelInputs;
- var modelOutputs = [];
- for (var i = 0; i < this.outputLayers.length; i++) {
- var layer = this.outputLayers[i];
- var nodeIndex = this.outputLayersNodeIndices[i];
- var nodeKey = Container.nodeKey(layer, nodeIndex);
- if (!this.containerNodes.has(nodeKey)) {
- continue;
- }
- var newNodeIndex = nodeConversionMap[nodeKey];
- if (newNodeIndex === null || newNodeIndex === undefined) {
- newNodeIndex = 0;
- }
- var tensorIndex = this.outputLayersTensorIndices[i];
- modelOutputs.push([layer.name, newNodeIndex, tensorIndex]);
- }
- config['outputLayers'] = modelOutputs;
- return config;
- };
- Container.fromConfig = function (cls, config) {
- var createdLayers = {};
- var unprocessedNodes = {};
- function addUnprocessedNode(layer, nodeData) {
- if (!(layer.name in unprocessedNodes)) {
- unprocessedNodes[layer.name] = [nodeData];
- }
- else {
- unprocessedNodes[layer.name].push(nodeData);
- }
- }
- function processNode(layer, nodeData) {
- var inputTensors = [];
- var kwargs;
- for (var _i = 0, nodeData_1 = nodeData; _i < nodeData_1.length; _i++) {
- var inputData = nodeData_1[_i];
- var inboundLayerName = inputData[0];
- var inboundNodeIndex = inputData[1];
- var inboundTensorIndex = inputData[2];
- if (inputData.length === 3) {
- kwargs = {};
- }
- else if (inputData.length === 4) {
- kwargs = inputData[3];
- }
- else {
- throw new errors_1.ValueError("Improperly formatted model config for layer " + JSON.stringify(layer) + ": " + JSON.stringify(inputData));
- }
- if (!(inboundLayerName in createdLayers)) {
- addUnprocessedNode(layer, nodeData);
- return;
- }
- var inboundLayer = createdLayers[inboundLayerName];
- if (inboundLayer.inboundNodes.length <= inboundNodeIndex) {
- addUnprocessedNode(layer, nodeData);
- return;
- }
- var inboundNode = inboundLayer.inboundNodes[inboundNodeIndex];
- inputTensors.push(inboundNode.outputTensors[inboundTensorIndex]);
- }
- if (inputTensors.length > 0) {
- layer.apply(generic_utils.singletonOrArray(inputTensors), kwargs);
- }
- }
- function processLayer(layerData) {
- var layerName = layerData.name;
- var layer = serialization_1.deserialize(layerData, config.customObjects != null ?
- config.customObjects :
- {});
- createdLayers[layerName] = layer;
- var inboundNodesData = layerData.inboundNodes;
- for (var _i = 0, inboundNodesData_1 = inboundNodesData; _i < inboundNodesData_1.length; _i++) {
- var nodeData = inboundNodesData_1[_i];
- if (!(nodeData instanceof Array)) {
- throw new errors_1.ValueError("Corrupted configuration, expected array for nodeData: " + nodeData);
- }
- addUnprocessedNode(layer, nodeData);
- }
- }
- var name = config.name;
- var layersFromConfig = config.layers;
- for (var _i = 0, layersFromConfig_1 = layersFromConfig; _i < layersFromConfig_1.length; _i++) {
- var layerData = layersFromConfig_1[_i];
- processLayer(layerData);
- }
- while (!generic_utils.isObjectEmpty(unprocessedNodes)) {
- for (var _a = 0, layersFromConfig_2 = layersFromConfig; _a < layersFromConfig_2.length; _a++) {
- var layerData = layersFromConfig_2[_a];
- var layer = createdLayers[layerData.name];
- if (layer.name in unprocessedNodes) {
- for (var _b = 0, _c = unprocessedNodes[layer.name]; _b < _c.length; _b++) {
- var nodeData = _c[_b];
- processNode(layer, nodeData);
- }
- delete unprocessedNodes[layer.name];
- }
- }
- }
- var inputTensors = [];
- var outputTensors = [];
- var inputLayersFromConfig = config.inputLayers;
- for (var _d = 0, inputLayersFromConfig_1 = inputLayersFromConfig; _d < inputLayersFromConfig_1.length; _d++) {
- var layerData = inputLayersFromConfig_1[_d];
- var layerName = layerData[0];
- var nodeIndex = layerData[1];
- var tensorIndex = layerData[2];
- generic_utils.assert(layerName in createdLayers);
- var layer = createdLayers[layerName];
- var layerOutputTensors = layer.inboundNodes[nodeIndex].outputTensors;
- inputTensors.push(layerOutputTensors[tensorIndex]);
- }
- var outputLayersFromConfig = config.outputLayers;
- for (var _e = 0, outputLayersFromConfig_1 = outputLayersFromConfig; _e < outputLayersFromConfig_1.length; _e++) {
- var layerData = outputLayersFromConfig_1[_e];
- var layerName = layerData[0];
- var nodeIndex = layerData[1];
- var tensorIndex = layerData[2];
- generic_utils.assert(layerName in createdLayers);
- var layer = createdLayers[layerName];
- var layerOutputTensors = layer.inboundNodes[nodeIndex].outputTensors;
- outputTensors.push(layerOutputTensors[tensorIndex]);
- }
- return new cls({ inputs: inputTensors, outputs: outputTensors, name: name });
- };
- Object.defineProperty(Container.prototype, "stateful", {
- get: function () {
- if (this._stateful) {
- throw new errors_1.ValueError('Container instance unexpectedly has _stateful = true. The ' +
- 'statefulness of a Container is determined by the Layers it ' +
- 'contains. Its _stateful property must remain the default false.');
- }
- for (var _i = 0, _a = this.layers; _i < _a.length; _i++) {
- var layer = _a[_i];
- if (layer.stateful) {
- return true;
- }
- }
- return false;
- },
- enumerable: true,
- configurable: true
- });
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Classes',
- namespace: 'layers',
- subclasses: ['Model']
- })
- ], Container.prototype, "getLayer", null);
- return Container;
- }(Layer));
- exports.Container = Container;
- function getSourceInputs(tensor, layer, nodeIndex) {
- if (layer == null || (nodeIndex != null && nodeIndex > 0)) {
- layer = tensor.sourceLayer;
- nodeIndex = tensor.nodeIndex;
- }
- if (layer.inboundNodes.length === 0) {
- return [tensor];
- }
- else {
- var node = layer.inboundNodes[nodeIndex];
- if (node.inboundLayers.length === 0) {
- return node.inputTensors;
- }
- else {
- var sourceTensors = [];
- for (var i = 0; i < node.inboundLayers.length; i++) {
- var x = node.inputTensors[i];
- var layer_2 = node.inboundLayers[i];
- var nodeIndex_3 = node.nodeIndices[i];
- var previousSources = getSourceInputs(x, layer_2, nodeIndex_3);
- for (var _i = 0, previousSources_1 = previousSources; _i < previousSources_1.length; _i++) {
- var x_1 = previousSources_1[_i];
- if (sourceTensors.indexOf(x_1) === -1) {
- sourceTensors.push(x_1);
- }
- }
- }
- return sourceTensors;
- }
- }
- }
- exports.getSourceInputs = getSourceInputs;
- function loadTensor(dtype, shape, value) {
- var dataType = generic_utils.stringToDType(dtype);
- return tfjs_core_1.Tensor.make(shape, { values: shape.length === 0 ? value : tfjs_core_1.util.flatten(value) }, dataType);
- }
- function preprocessWeightsForLoading(layer, weights, originalKerasVersion, originalBackend) {
- if (!originalKerasVersion.startsWith('2.')) {
- throw new errors_1.ValueError('Unsupported Keras version in weights being loaded: ' +
- originalKerasVersion);
- }
- return weights;
- }
- function loadWeightsFromNamedTensorMap(weights, layers) {
- var nameToWeight = {};
- var totalWeightsCount = 0;
- for (var _i = 0, layers_1 = layers; _i < layers_1.length; _i++) {
- var layer = layers_1[_i];
- for (var _a = 0, _b = layer.weights; _a < _b.length; _a++) {
- var weight = _b[_a];
- if (nameToWeight[weight.originalName] != null) {
- throw new errors_1.ValueError("Duplicate weight name: " + weight.originalName);
- }
- nameToWeight[weight.originalName] = weight;
- totalWeightsCount++;
- }
- }
- var weightValueTuples = [];
- for (var name_2 in weights) {
- weightValueTuples.push([nameToWeight[name_2], weights[name_2]]);
- delete nameToWeight[name_2];
- }
- var unsetNames = [];
- for (var name_3 in nameToWeight) {
- unsetNames.push(name_3);
- }
- if (unsetNames.length > 0) {
- throw new errors_1.ValueError(unsetNames.length + " of " + totalWeightsCount + " weights are not set: " +
- ("" + unsetNames));
- }
- variables_1.batchSetValue(weightValueTuples);
- }
- exports.loadWeightsFromNamedTensorMap = loadWeightsFromNamedTensorMap;
- function loadWeightsFromJson(weightsJSON, layers, skipMismatch) {
- if (skipMismatch === void 0) { skipMismatch = false; }
- var originalKerasVersion = weightsJSON['keras_version'];
- var originalBackend = weightsJSON['backend'];
- var layerNames = layers.map(function (layer) { return layer.name; });
- var index = {};
- for (var _i = 0, layers_2 = layers; _i < layers_2.length; _i++) {
- var layer = layers_2[_i];
- if (layer.name != null) {
- if (index[layer.name] == null) {
- index[layer.name] = [];
- }
- index[layer.name].push(layer);
- }
- }
- var nameToWeights = weightsJSON['weights'];
- var weightValueTuples = [];
- for (var k = 0; k < layerNames.length; ++k) {
- var name_4 = layerNames[k];
- var layerWeights = nameToWeights[name_4];
- if (layerWeights == null) {
- layerWeights = [];
- }
- var weightValues = [];
- for (var n = 0; n < layerWeights.length; ++n) {
- var weightEntry = layerWeights[n];
- weightValues.push(new variables_1.LayerVariable(loadTensor(weightEntry['dtype'], weightEntry['shape'], weightEntry['value'])));
- }
- for (var _a = 0, _b = index[name_4]; _a < _b.length; _a++) {
- var layer = _b[_a];
- var symbolicWeights = layer.weights;
- weightValues = preprocessWeightsForLoading(layer, weightValues, originalKerasVersion, originalBackend);
- if (weightValues.length !== symbolicWeights.length) {
- if (skipMismatch) {
- console.warn("Skipping loading of weights of layer " + layer.name + " " +
- ("due to mismatch in number of weights: (" + weightValues.length + " ") +
- ("vs " + symbolicWeights.length + ")."));
- }
- else {
- throw new errors_1.ValueError("Layer #" + k + " (named \"" + layer.name + "\") expects " +
- (symbolicWeights.length + " weight(s), but the saved weights ") +
- ("have " + weightValues.length + " element(s)."));
- }
- }
- for (var i = 0; i < weightValues.length; ++i) {
- if (skipMismatch) {
- if (!tfjs_core_1.util.arraysEqual(symbolicWeights[i].shape, weightValues[i].shape)) {
- console.warn("Skipping loading of weights for layer " + layer.name + " due " +
- ("to mismatch in shape (" + symbolicWeights[i].shape + " vs ") +
- (weightValues[i].shape + ")"));
- continue;
- }
- }
- weightValueTuples.push([symbolicWeights[i], weightValues[i].read()]);
- }
- }
- }
- variables_1.batchSetValue(weightValueTuples);
- }
- exports.loadWeightsFromJson = loadWeightsFromJson;
- },{"../backend/tfjs_backend":169,"../errors":176,"../layers/serialization":190,"../types":197,"../utils/generic_utils":199,"../utils/serialization_utils":202,"../variables":203,"../version":204,"@tensorflow/tfjs-core":54}],175:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("../backend/tfjs_backend");
- var callbacks_1 = require("../callbacks");
- var errors_1 = require("../errors");
- var losses = require("../losses");
- var Metrics = require("../metrics");
- var optimizers = require("../optimizers");
- var generic_utils_1 = require("../utils/generic_utils");
- var layer_utils_1 = require("../utils/layer_utils");
- var math_utils_1 = require("../utils/math_utils");
- var executor_1 = require("./executor");
- var topology_1 = require("./topology");
- function isDataTensor(x) {
- return x instanceof tfjs_core_1.Tensor;
- }
- exports.isDataTensor = isDataTensor;
- function isDataArray(x) {
- return Array.isArray(x);
- }
- exports.isDataArray = isDataArray;
- function isDataDict(x) {
- return !isDataTensor(x) && !isDataArray(x);
- }
- exports.isDataDict = isDataDict;
- function standardizeInputData(data, names, shapes, checkBatchAxis, exceptionPrefix) {
- if (checkBatchAxis === void 0) { checkBatchAxis = true; }
- if (exceptionPrefix === void 0) { exceptionPrefix = ''; }
- if (names == null || names.length === 0) {
- if (data != null) {
- var gotUnexpectedData = false;
- if (isDataArray(data) && data.length > 0) {
- gotUnexpectedData = true;
- }
- else if (isDataDict(data)) {
- for (var key in data) {
- if (data.hasOwnProperty(key)) {
- gotUnexpectedData = true;
- break;
- }
- }
- }
- else {
- gotUnexpectedData = true;
- }
- if (gotUnexpectedData) {
- throw new errors_1.ValueError("Error when checking model " + exceptionPrefix + " expected no data, " +
- ("but got " + data));
- }
- }
- return [];
- }
- if (data == null) {
- return names.map(function (name) { return null; });
- }
- var arrays;
- if (isDataDict(data)) {
- data = data;
- arrays = [];
- for (var _i = 0, names_1 = names; _i < names_1.length; _i++) {
- var name_1 = names_1[_i];
- if (data[name_1] == null) {
- throw new errors_1.ValueError("No data provided for \"" + name_1 + "\". Need data for each key in: " +
- ("" + names));
- }
- arrays.push(data[name_1]);
- }
- }
- else if (isDataArray(data)) {
- data = data;
- if (data.length !== names.length) {
- throw new errors_1.ValueError("Error when checking model " + exceptionPrefix + ": the Array of " +
- "Tensors that you are passing to your model is not the size the " +
- ("model expected. Expected to see " + names.length + " Tensor(s), but ") +
- ("instead got the following list of Tensor(s): " + data));
- }
- arrays = data;
- }
- else {
- data = data;
- if (names.length > 1) {
- throw new errors_1.ValueError("The model " + exceptionPrefix + " expects " + names.length + " Tensor(s), " +
- ("but only received one Tensor. Found: Tensor with shape " + data.shape));
- }
- arrays = [data];
- }
- for (var i = 0; i < names.length; ++i) {
- var array = arrays[i];
- if (array.shape.length === 1) {
- arrays[i] = K.expandDims(array, 1);
- }
- }
- if (shapes != null) {
- for (var i = 0; i < names.length; ++i) {
- if (shapes[i] == null) {
- continue;
- }
- var array = arrays[i];
- if (array.shape.length !== shapes[i].length) {
- throw new errors_1.ValueError("Error when checking " + exceptionPrefix + ": expected " + names[i] + " " +
- ("to have " + shapes[i].length + " dimension(s). but got array with ") +
- ("shape " + array.shape));
- }
- for (var j = 0; j < shapes[i].length; ++j) {
- if (j === 0 && !checkBatchAxis) {
- continue;
- }
- var dim = array.shape[j];
- var refDim = shapes[i][j];
- if (refDim != null && refDim >= 0 && dim !== refDim) {
- throw new errors_1.ValueError("Error when checking " + exceptionPrefix + ": expected " + names[i] + " " +
- ("to have shape [" + shapes[i] + "], but got array with shape ") +
- ("[" + array.shape + "]."));
- }
- }
- }
- }
- return arrays;
- }
- exports.standardizeInputData = standardizeInputData;
- function checkArrayLengths(inputs, targets, weights) {
- var setX = generic_utils_1.unique(inputs.map(function (input) { return input.shape[0]; }));
- setX.sort();
- var setY = generic_utils_1.unique(targets.map(function (target) { return target.shape[0]; }));
- setY.sort();
- if (setX.length > 1) {
- throw new errors_1.ValueError("All input Tensors (x) should have the same number of samples. " +
- "Got array shapes: " +
- ("" + JSON.stringify(inputs.map(function (input) { return input.shape; }))));
- }
- if (setY.length > 1) {
- throw new errors_1.ValueError("All target Tensors (y) should have the same number of samples. " +
- "Got array shapes: " +
- ("" + JSON.stringify(targets.map(function (target) { return target.shape; }))));
- }
- if (setX.length > 0 && setY.length > 0 && !tfjs_core_1.util.arraysEqual(setX, setY)) {
- throw new errors_1.ValueError("Input Tensors should have the same number of samples as target " +
- ("Tensors. Found " + setX[0] + " input sample(s) and " + setY[0] + " target ") +
- "sample(s).");
- }
- }
- exports.checkArrayLengths = checkArrayLengths;
- function checkLossAndTargetCompatibility(targets, lossFns, outputShapes) {
- var keyLosses = [
- losses.meanSquaredError, losses.binaryCrossentropy,
- losses.categoricalCrossentropy
- ];
- for (var i = 0; i < targets.length; ++i) {
- var y = targets[i];
- var loss = lossFns[i];
- var shape = outputShapes[i];
- if (loss == null) {
- continue;
- }
- if (loss === losses.categoricalCrossentropy) {
- if (y.shape[y.shape.length - 1] === 1) {
- throw new errors_1.ValueError("You are passing a target array of shape " + y.shape + " while using " +
- "a loss 'categorical_crossentropy'. 'categorical_crossentropy'" +
- "expects targets to be binary matrices (1s and 0s) of shape " +
- "[samples, classes].");
- }
- }
- if (keyLosses.indexOf(loss) !== -1) {
- var slicedYShape = y.shape.slice(1);
- var slicedShape = shape.slice(1);
- for (var j = 0; j < slicedYShape.length; ++j) {
- var targetDim = slicedYShape[j];
- var outDim = slicedShape[j];
- if (outDim != null && targetDim !== outDim) {
- throw new errors_1.ValueError("A target Tensor with shape " + y.shape + " was passed for an " +
- ("output of shape " + shape + ", while using a loss function that ") +
- "expects targets to have the same shape as the output.");
- }
- }
- }
- }
- }
- function makeBatches(size, batchSize) {
- var output = [];
- var batchStart = 0;
- var batchEnd = null;
- while (batchStart < size) {
- batchEnd = batchStart + batchSize;
- if (batchEnd >= size) {
- batchEnd = size;
- }
- output.push([batchStart, batchEnd]);
- batchStart = batchEnd;
- }
- return output;
- }
- exports.makeBatches = makeBatches;
- function sliceArrays(arrays, start, stop) {
- if (arrays == null) {
- return [null];
- }
- else if (Array.isArray(arrays)) {
- return arrays.map(function (array) { return K.sliceAlongFirstAxis(array, start, stop - start); });
- }
- else {
- return K.sliceAlongFirstAxis(arrays, start, stop - start);
- }
- }
- function sliceArraysByIndices(arrays, indices) {
- return tfc.tidy(function () {
- if (arrays == null) {
- return null;
- }
- else if (Array.isArray(arrays)) {
- return arrays.map(function (array) { return sliceArraysByIndices(array, indices); });
- }
- else {
- return K.gather(arrays, indices.dtype === 'int32' ? indices : indices.toInt());
- }
- });
- }
- exports.sliceArraysByIndices = sliceArraysByIndices;
- function checkInputData(data, names, shapes, checkBatchAxis, exceptionPrefix) {
- if (checkBatchAxis === void 0) { checkBatchAxis = true; }
- if (exceptionPrefix === void 0) { exceptionPrefix = ''; }
- var arrays;
- if (Array.isArray(data)) {
- if (data.length !== names.length) {
- throw new errors_1.ValueError("Error when checking model " + exceptionPrefix + ": the Array of " +
- "Tensors that you are passing to your model is not the size the " +
- ("the model expected. Expected to see " + names.length + " Tensor(s),") +
- (" but instead got " + data.length + " Tensors(s)."));
- }
- arrays = data;
- }
- else {
- if (names.length > 1) {
- throw new errors_1.ValueError("The model expects " + names.length + " " + exceptionPrefix + " Tensors, " +
- "but only received one Tensor. Found: array with shape " +
- (JSON.stringify(data.shape) + "."));
- }
- arrays = [data];
- }
- if (shapes != null) {
- for (var i = 0; i < names.length; ++i) {
- if (shapes[i] == null) {
- continue;
- }
- var array = arrays[i];
- if (array.shape.length !== shapes[i].length) {
- throw new errors_1.ValueError("Error when checking " + exceptionPrefix + ": expected " + names[i] + " " +
- ("to have " + shapes[i].length + " dimension(s), but got array with ") +
- ("shape " + JSON.stringify(array.shape)));
- }
- for (var j = 0; j < shapes[i].length; ++j) {
- if (j === 0 && !checkBatchAxis) {
- continue;
- }
- var dim = array.shape[j];
- var refDim = shapes[i][j];
- if (refDim != null) {
- if (refDim !== dim) {
- throw new errors_1.ValueError("Error when checking " + exceptionPrefix + ": expected " +
- (names[i] + " to have shape " + JSON.stringify(shapes[i]) + " but ") +
- ("got array with shape " + JSON.stringify(array.shape) + "."));
- }
- }
- }
- }
- }
- }
- function collectMetrics(metrics, outputNames) {
- if (metrics == null || Array.isArray(metrics) && metrics.length === 0) {
- return outputNames.map(function (name) { return []; });
- }
- if (Array.isArray(metrics)) {
- return outputNames.map(function (name) { return metrics; });
- }
- else if (metrics != null) {
- var nestedMetrics = [];
- for (var _i = 0, outputNames_1 = outputNames; _i < outputNames_1.length; _i++) {
- var name_2 = outputNames_1[_i];
- var outputMetrics = metrics.hasOwnProperty(name_2) ? metrics[name_2] : [];
- if (!Array.isArray(outputMetrics)) {
- outputMetrics = [outputMetrics];
- }
- nestedMetrics.push(outputMetrics);
- }
- return nestedMetrics;
- }
- else {
- throw new TypeError('Type of metrics argument not understood. Expected an Array or ' +
- 'Object, found: ' + metrics);
- }
- }
- var ModelLoggingVerbosity;
- (function (ModelLoggingVerbosity) {
- ModelLoggingVerbosity[ModelLoggingVerbosity["SILENT"] = 0] = "SILENT";
- ModelLoggingVerbosity[ModelLoggingVerbosity["VERBOSE"] = 1] = "VERBOSE";
- })(ModelLoggingVerbosity = exports.ModelLoggingVerbosity || (exports.ModelLoggingVerbosity = {}));
- var Model = (function (_super) {
- __extends(Model, _super);
- function Model(config) {
- return _super.call(this, config) || this;
- }
- Model.prototype.summary = function (lineLength, positions, printFn) {
- if (printFn === void 0) { printFn = console.log; }
- if (!this.built) {
- throw new errors_1.ValueError("This model has never been called, thus its weights have not been " +
- "created yet. So no summary can be displayed. Build the model " +
- "first (e.g., by calling it on some test data).");
- }
- layer_utils_1.printSummary(this, lineLength, positions, printFn);
- };
- Model.prototype.compile = function (config) {
- var _this = this;
- if (config.loss == null) {
- config.loss = [];
- }
- this.loss = config.loss;
- if (typeof config.optimizer === 'string') {
- this.optimizer = optimizers.getOptimizer(config.optimizer);
- }
- else {
- if (!(config.optimizer instanceof tfjs_core_1.Optimizer)) {
- throw new errors_1.ValueError("User-defined optimizer must be an instance of tf.Optimizer.");
- }
- this.optimizer = config.optimizer;
- }
- var lossFunctions = [];
- if (!Array.isArray(config.loss) && typeof config.loss !== 'string' &&
- typeof config.loss !== 'function') {
- config.loss = config.loss;
- for (var name_3 in config.loss) {
- if (this.outputNames.indexOf(name_3) === -1) {
- throw new errors_1.ValueError("Unknown entry in loss dictionary: \"" + name_3 + "\". Only expect the " +
- ("following keys: " + this.outputNames));
- }
- }
- for (var name_4 in this.outputNames) {
- if (config.loss[name_4] == null) {
- console.warn("Output \"" + name_4 + "\" is missing from loss dictionary. We assume " +
- "this was done on purpose, and we will not be expecting data " +
- ("to be passed to " + name_4 + " during training"));
- }
- lossFunctions.push(losses.get(config.loss[name_4]));
- }
- }
- else if (Array.isArray(config.loss)) {
- if (config.loss.length !== this.outputs.length) {
- throw new errors_1.ValueError("When passing an Array as loss, it should have one entry per " +
- ("model output. The model has " + this.outputs.length + " output(s), ") +
- ("but you passed loss=" + config.loss + "."));
- }
- var theLosses = config.loss;
- lossFunctions = theLosses.map(function (l) { return losses.get(l); });
- }
- else {
- var lossFunction_1 = losses.get(config.loss);
- this.outputs.map(function (layer) {
- lossFunctions.push(lossFunction_1);
- });
- }
- this.lossFunctions = lossFunctions;
- this.feedOutputNames = [];
- this.feedOutputShapes = [];
- this.feedLossFns = [];
- for (var i = 0; i < this.outputs.length; ++i) {
- var shape = this.internalOutputShapes[i];
- var name_5 = this.outputNames[i];
- this.feedOutputNames.push(name_5);
- this.feedOutputShapes.push(shape);
- this.feedLossFns.push(this.lossFunctions[i]);
- }
- var skipTargetIndices = [];
- this.metrics = config.metrics;
- this.metricsNames = ['loss'];
- this.metricsTensors = [];
- K.nameScope('loss', function () {
- for (var i = 0; i < _this.outputs.length; ++i) {
- if (skipTargetIndices.indexOf(i) !== -1) {
- continue;
- }
- var weightedLoss = _this.lossFunctions[i];
- if (_this.outputs.length > 1) {
- _this.metricsTensors.push([weightedLoss, i]);
- _this.metricsNames.push(_this.outputNames[i] + '_loss');
- }
- }
- });
- var nestedMetrics = collectMetrics(config.metrics, this.outputNames);
- var appendMetric = function (outputIndex, metricName, metricTensor) {
- if (_this.outputNames.length > 1) {
- metricName = _this.outputNames[outputIndex] + '_' + metricName;
- }
- _this.metricsNames.push(metricName);
- _this.metricsTensors.push([metricTensor, outputIndex]);
- };
- K.nameScope('metric', function () {
- var _loop_1 = function (i) {
- if (skipTargetIndices.indexOf(i) !== -1) {
- return "continue";
- }
- var outputMetrics = nestedMetrics[i];
- var handleMetrics = function (metrics) {
- var metricNamePrefix = '';
- var metricName;
- var accFn;
- var weightedMetricFn;
- var _loop_2 = function (metric) {
- if (['accuracy', 'acc', 'crossentropy', 'ce'].indexOf(metric) !==
- -1) {
- var outputShape = _this.internalOutputShapes[i];
- if (outputShape[outputShape.length - 1] === 1 ||
- _this.lossFunctions[i] === losses.binaryCrossentropy) {
- if (['accuracy', 'acc'].indexOf(metric) !== -1) {
- accFn = Metrics.binaryAccuracy;
- }
- else if (['crossentropy', 'ce'].indexOf(metric) !== -1) {
- accFn = Metrics.binaryCrossentropy;
- }
- }
- else if (_this.lossFunctions[i] ===
- losses.sparseCategoricalCrossentropy) {
- if (['accuracy', 'acc'].indexOf(metric) !== -1) {
- accFn = Metrics.sparseCategoricalAccuracy;
- }
- else if (['crossentropy', 'ce'].indexOf(metric) !== -1) {
- accFn = Metrics.sparseCategoricalCrossentropy;
- }
- }
- else {
- if (['accuracy', 'acc'].indexOf(metric) !== -1) {
- accFn = Metrics.categoricalAccuracy;
- }
- else if (['crossentropy', 'ce'].indexOf(metric) !== -1) {
- accFn = Metrics.categoricalCrossentropy;
- }
- }
- var suffix = void 0;
- if (['accuracy', 'acc'].indexOf(metric) !== -1) {
- suffix = 'acc';
- }
- else if (['crossentropy', 'ce'].indexOf(metric) !== -1) {
- suffix = 'ce';
- }
- weightedMetricFn = accFn;
- metricName = metricNamePrefix + suffix;
- }
- else {
- var metricFn = Metrics.get(metric);
- weightedMetricFn = metricFn;
- metricName = metricNamePrefix + metric;
- }
- var metricResult;
- K.nameScope(metricName, function () {
- metricResult = weightedMetricFn;
- });
- appendMetric(i, metricName, metricResult);
- };
- for (var _i = 0, metrics_1 = metrics; _i < metrics_1.length; _i++) {
- var metric = metrics_1[_i];
- _loop_2(metric);
- }
- };
- handleMetrics(outputMetrics);
- };
- for (var i = 0; i < _this.outputs.length; ++i) {
- _loop_1(i);
- }
- });
- this.collectedTrainableWeights = this.trainableWeights;
- };
- Model.prototype.checkTrainableWeightsConsistency = function () {
- if (this.collectedTrainableWeights == null) {
- return;
- }
- if (this.trainableWeights.length !==
- this.collectedTrainableWeights.length) {
- console.warn('Discrepancy between trainableweights and collected trainable ' +
- 'weights. Did you set `model.trainable` without calling ' +
- '`model.compile()` afterwards?');
- }
- };
- Model.prototype.evaluate = function (x, y, config) {
- if (config === void 0) { config = {}; }
- var batchSize = config.batchSize == null ? 32 : config.batchSize;
- var standardizedOuts = this.standardizeUserData(x, y, true, batchSize);
- var ins = standardizedOuts[0].concat(standardizedOuts[1]);
- this.makeTestFunction();
- var f = this.testFunction;
- var testOuts = this.testLoop(f, ins, batchSize, config.verbose, config.steps);
- return generic_utils_1.singletonOrArray(testOuts);
- };
- Model.prototype.checkNumSamples = function (ins, batchSize, steps, stepsName) {
- if (stepsName === void 0) { stepsName = 'steps'; }
- var numSamples;
- if (steps != null) {
- numSamples = null;
- if (batchSize != null) {
- throw new errors_1.ValueError("If " + stepsName + " is set, batchSize must be null or undefined." +
- ("Got batchSize = " + batchSize));
- }
- }
- else if (ins != null) {
- if (Array.isArray(ins)) {
- numSamples = ins[0].shape[0];
- }
- else {
- numSamples = ins.shape[0];
- }
- }
- else {
- throw new errors_1.ValueError("Either the input data should have a defined shape, or " +
- (stepsName + " shoud be specified."));
- }
- return numSamples;
- };
- Model.prototype.execute = function (inputs, outputs) {
- if (Array.isArray(outputs) && outputs.length === 0) {
- throw new errors_1.ValueError('`outputs` is an empty Array, which is not allowed.');
- }
- var outputsIsArray = Array.isArray(outputs);
- var outputNames = (outputsIsArray ? outputs :
- [outputs]);
- var outputSymbolicTensors = this.retrieveSymbolicTensors(outputNames);
- var feedDict = new executor_1.FeedDict();
- if (inputs instanceof tfjs_core_1.Tensor) {
- inputs = [inputs];
- }
- if (Array.isArray(inputs)) {
- if (inputs.length !== this.inputs.length) {
- throw new errors_1.ValueError("The number of inputs provided (" + inputs.length + ") " +
- "does not match the number of inputs of this model " +
- ("(" + this.inputs.length + ")."));
- }
- for (var i = 0; i < this.inputs.length; ++i) {
- feedDict.add(this.inputs[i], inputs[i]);
- }
- }
- else {
- for (var _i = 0, _a = this.inputs; _i < _a.length; _i++) {
- var input = _a[_i];
- var tensorValue = inputs[input.name];
- if (tensorValue == null) {
- throw new errors_1.ValueError("No value is provided for the model's input " + input.name);
- }
- feedDict.add(input, tensorValue);
- }
- }
- var executeOutputs = executor_1.execute(outputSymbolicTensors, feedDict);
- return outputsIsArray ? executeOutputs : executeOutputs[0];
- };
- Model.prototype.retrieveSymbolicTensors = function (symbolicTensorNames) {
- var outputSymbolicTensors = generic_utils_1.pyListRepeat(null, symbolicTensorNames.length);
- var outputsRemaining = symbolicTensorNames.length;
- for (var _i = 0, _a = this.layers; _i < _a.length; _i++) {
- var layer = _a[_i];
- var layerOutputs = Array.isArray(layer.output) ?
- layer.output :
- [layer.output];
- var layerOutputNames = layerOutputs.map(function (output) { return output.name; });
- for (var i = 0; i < symbolicTensorNames.length; ++i) {
- var index = layerOutputNames.indexOf(symbolicTensorNames[i]);
- if (index !== -1) {
- outputSymbolicTensors[i] = layerOutputs[index];
- outputsRemaining--;
- }
- if (outputsRemaining === 0) {
- break;
- }
- }
- if (outputsRemaining === 0) {
- break;
- }
- }
- if (outputsRemaining > 0) {
- var remainingNames_1 = [];
- outputSymbolicTensors.forEach(function (tensor, i) {
- if (tensor == null) {
- remainingNames_1.push(symbolicTensorNames[i]);
- }
- });
- throw new errors_1.ValueError("Cannot find SymbolicTensors for output name(s): " +
- ("" + JSON.stringify(remainingNames_1)));
- }
- return outputSymbolicTensors;
- };
- Model.prototype.predictLoop = function (ins, batchSize, verbose) {
- var _this = this;
- if (batchSize === void 0) { batchSize = 32; }
- if (verbose === void 0) { verbose = false; }
- var numSamples = this.checkNumSamples(ins);
- if (verbose) {
- throw new errors_1.NotImplementedError('Verbose predictLoop() is not implemented yet.');
- }
- var batches = makeBatches(numSamples, batchSize);
- var outs = [];
- var _loop_3 = function (batchIndex) {
- var batchOuts = tfc.tidy(function () {
- var batchStart = batches[batchIndex][0];
- var batchEnd = batches[batchIndex][1];
- var insBatch = sliceArrays(ins, batchStart, batchEnd);
- var feeds = [];
- if (Array.isArray(insBatch)) {
- for (var i = 0; i < insBatch.length; ++i) {
- feeds.push({ key: _this.inputs[i], value: insBatch[i] });
- }
- }
- else {
- feeds.push({ key: _this.inputs[0], value: insBatch });
- }
- var feedDict = new executor_1.FeedDict(feeds);
- return executor_1.execute(_this.outputs, feedDict);
- });
- if (batchIndex === 0) {
- for (var _i = 0, batchOuts_1 = batchOuts; _i < batchOuts_1.length; _i++) {
- var batchOut = batchOuts_1[_i];
- outs.push(batchOut);
- }
- }
- else {
- for (var i = 0; i < batchOuts.length; ++i) {
- outs[i] = K.concatAlongFirstAxis(outs[i], batchOuts[i]);
- }
- }
- };
- for (var batchIndex = 0; batchIndex < batches.length; ++batchIndex) {
- _loop_3(batchIndex);
- }
- return generic_utils_1.singletonOrArray(outs);
- };
- Model.prototype.predict = function (x, config) {
- if (config === void 0) { config = {}; }
- checkInputData(x, this.inputNames, this.feedInputShapes, false);
- var batchSize = config.batchSize == null ? 32 : config.batchSize;
- return this.predictLoop(x, batchSize);
- };
- Model.prototype.predictOnBatch = function (x) {
- checkInputData(x, this.inputNames, this.feedInputShapes, true);
- return this.predictLoop(x, x.shape[0]);
- };
- Model.prototype.standardizeUserData = function (x, y, checkBatchAxis, batchSize) {
- if (checkBatchAxis === void 0) { checkBatchAxis = true; }
- if (this.optimizer == null) {
- throw new errors_1.RuntimeError('You must compile a model before training/testing. Use ' +
- 'Model.compile(modelCompileConfig).');
- }
- var outputShapes = [];
- for (var i = 0; i < this.feedOutputShapes.length; ++i) {
- var outputShape = this.feedOutputShapes[i];
- var lossFn = this.feedLossFns[i];
- if (lossFn === losses.sparseCategoricalCrossentropy) {
- outputShapes.push(outputShape.slice(0, outputShape.length - 1).concat([1]));
- }
- else {
- outputShapes.push(outputShape);
- }
- }
- x = standardizeInputData(x, this.feedInputNames, this.feedInputShapes, false, 'input');
- y = standardizeInputData(y, this.feedOutputNames, outputShapes, false, 'target');
- checkArrayLengths(x, y, null);
- checkLossAndTargetCompatibility(y, this.feedLossFns, this.feedOutputShapes);
- if (this.stateful && batchSize != null && batchSize > 0) {
- if (x[0].shape[0] % batchSize !== 0) {
- throw new errors_1.ValueError("In a stateful network, you should only pass inputs with a " +
- "number of samples that is divisible by the batch size " +
- (batchSize + ". Found: " + x[0].shape[0] + " sample(s)."));
- }
- }
- return [x, y, null];
- };
- Model.prototype.fitLoop = function (f, ins, outLabels, batchSize, epochs, verbose, callbacks, valF, valIns, shuffle, callbackMetrics, initialEpoch, stepsPerEpoch, validationSteps) {
- if (initialEpoch === void 0) { initialEpoch = 0; }
- return __awaiter(this, void 0, void 0, function () {
- var _this = this;
- var doValidation, numTrainSamples, indexArray, callbackList, _loop_4, this_1, epoch, state_1;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (batchSize == null) {
- batchSize = 32;
- }
- if (epochs == null) {
- epochs = 1;
- }
- if (shuffle == null) {
- shuffle = true;
- }
- if (initialEpoch == null) {
- initialEpoch = 0;
- }
- doValidation = false;
- if (valF != null && valIns != null) {
- doValidation = true;
- }
- if (validationSteps != null) {
- doValidation = true;
- if (stepsPerEpoch == null) {
- throw new errors_1.ValueError('Can only use `validationSteps` when doing step-wise training, ' +
- 'i.e., `stepsPerEpoch` must be set.');
- }
- }
- numTrainSamples = this.checkNumSamples(ins, batchSize, stepsPerEpoch, 'steps_per_epoch');
- if (numTrainSamples != null) {
- indexArray = math_utils_1.range(0, numTrainSamples);
- }
- this.history = new callbacks_1.History();
- if (callbacks == null) {
- callbacks = [new callbacks_1.BaseLogger()];
- }
- else {
- callbacks = [new callbacks_1.BaseLogger()].concat(callbacks);
- }
- callbacks = callbacks.concat([this.history]);
- if (verbose > 0) {
- throw new errors_1.NotImplementedError('Verbose mode is not implemented yet.');
- }
- callbackList = new callbacks_1.CallbackList(callbacks);
- callbackList.setModel(this);
- callbackList.setParams({
- epochs: epochs,
- steps: stepsPerEpoch,
- verbose: verbose,
- doValidation: doValidation,
- metrics: callbackMetrics,
- });
- return [4, callbackList.onTrainBegin()];
- case 1:
- _a.sent();
- this.stopTraining = false;
- _loop_4 = function (epoch) {
- var epochLogs, epochIndexArray1D_1, batches_1, _loop_5, batchIndex, state_2;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0: return [4, callbackList.onEpochBegin(epoch)];
- case 1:
- _a.sent();
- epochLogs = {};
- if (!(stepsPerEpoch != null)) return [3, 2];
- throw new errors_1.NotImplementedError('stepsPerEpoch mode is not implemented yet.');
- case 2:
- if (shuffle === 'batch') {
- throw new errors_1.NotImplementedError('batch shuffling is not implemneted yet');
- }
- else if (shuffle) {
- tfjs_core_1.util.shuffle(indexArray);
- }
- epochIndexArray1D_1 = tfjs_core_1.tensor1d(indexArray);
- batches_1 = makeBatches(numTrainSamples, batchSize);
- _loop_5 = function (batchIndex) {
- var batchLogs;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- batchLogs = {};
- return [4, callbackList.onBatchBegin(batchIndex, batchLogs)];
- case 1:
- _a.sent();
- tfc.tidy(function () {
- var batchStart = batches_1[batchIndex][0];
- var batchEnd = batches_1[batchIndex][1];
- var batchIds = K.sliceAlongFirstAxis(epochIndexArray1D_1, batchStart, batchEnd - batchStart);
- batchLogs['batch'] = batchIndex;
- batchLogs['size'] = batchEnd - batchStart;
- var insBatch = sliceArraysByIndices(ins, batchIds);
- var outs = f(insBatch);
- for (var i = 0; i < outLabels.length; ++i) {
- var label = outLabels[i];
- var out = outs[i];
- batchLogs[label] = out;
- tfc.keep(out);
- }
- if (batchIndex === batches_1.length - 1) {
- if (doValidation) {
- var valOuts = _this.testLoop(valF, valIns, batchSize);
- for (var i = 0; i < outLabels.length; ++i) {
- var label = outLabels[i];
- var out = valOuts[i];
- tfc.keep(out);
- epochLogs['val_' + label] = out;
- }
- }
- }
- });
- return [4, callbackList.onBatchEnd(batchIndex, batchLogs)];
- case 2:
- _a.sent();
- callbacks_1.disposeTensorsInLogs(batchLogs);
- if (this_1.stopTraining) {
- return [2, "break"];
- }
- return [2];
- }
- });
- };
- batchIndex = 0;
- _a.label = 3;
- case 3:
- if (!(batchIndex < batches_1.length)) return [3, 6];
- return [5, _loop_5(batchIndex)];
- case 4:
- state_2 = _a.sent();
- if (state_2 === "break")
- return [3, 6];
- _a.label = 5;
- case 5:
- ++batchIndex;
- return [3, 3];
- case 6:
- epochIndexArray1D_1.dispose();
- _a.label = 7;
- case 7: return [4, callbackList.onEpochEnd(epoch, epochLogs)];
- case 8:
- _a.sent();
- if (this_1.stopTraining) {
- return [2, "break"];
- }
- return [2];
- }
- });
- };
- this_1 = this;
- epoch = initialEpoch;
- _a.label = 2;
- case 2:
- if (!(epoch < epochs)) return [3, 5];
- return [5, _loop_4(epoch)];
- case 3:
- state_1 = _a.sent();
- if (state_1 === "break")
- return [3, 5];
- _a.label = 4;
- case 4:
- ++epoch;
- return [3, 2];
- case 5: return [4, callbackList.onTrainEnd()];
- case 6:
- _a.sent();
- return [4, this.history.syncData()];
- case 7:
- _a.sent();
- return [2, this.history];
- }
- });
- });
- };
- Model.prototype.testLoop = function (f, ins, batchSize, verbose, steps) {
- if (verbose === void 0) { verbose = 0; }
- var numSamples = this.checkNumSamples(ins, batchSize, steps, 'steps');
- var outs = [];
- if (verbose === 1) {
- throw new errors_1.NotImplementedError('Verbose mode is not implemented yet.');
- }
- if (steps != null) {
- throw new errors_1.NotImplementedError('steps mode in testLoop() is not implemented yet');
- }
- else {
- var batches = makeBatches(numSamples, batchSize);
- var indexArray = tfjs_core_1.tensor1d(math_utils_1.range(0, numSamples));
- for (var batchIndex = 0; batchIndex < batches.length; ++batchIndex) {
- var batchStart = batches[batchIndex][0];
- var batchEnd = batches[batchIndex][1];
- var batchIds = K.sliceAlongFirstAxis(indexArray, batchStart, batchEnd - batchStart);
- var insBatch = sliceArraysByIndices(ins, batchIds);
- var batchOuts = f(insBatch);
- if (batchIndex === 0) {
- for (var i = 0; i < batchOuts.length; ++i) {
- outs.push(K.getScalar(0));
- }
- }
- for (var i = 0; i < batchOuts.length; ++i) {
- var batchOut = batchOuts[i];
- outs[i] =
- tfc.add(outs[i], K.scalarTimesArray(K.getScalar(batchEnd - batchStart), batchOut));
- }
- }
- for (var i = 0; i < outs.length; ++i) {
- outs[i] = tfc.div(outs[i], K.getScalar(numSamples));
- }
- }
- return outs;
- };
- Model.prototype.getDedupedMetricsNames = function () {
- var outLabels = this.metricsNames;
- var dedupedOutLabels = [];
- for (var i = 0; i < outLabels.length; ++i) {
- var label = outLabels[i];
- var newLabel = label;
- if (generic_utils_1.count(outLabels, label) > 1) {
- var dupIndex = generic_utils_1.count(outLabels.slice(0, i), label);
- newLabel += "_" + dupIndex;
- }
- dedupedOutLabels.push(newLabel);
- }
- return dedupedOutLabels;
- };
- Model.prototype.makeTestFunction = function () {
- var _this = this;
- this.testFunction = function (data) {
- return tfc.tidy(function () {
- var valOutputs = [];
- var totalLoss;
- var inputs = data.slice(0, _this.inputs.length);
- var targets = data.slice(_this.inputs.length, _this.inputs.length + _this.outputs.length);
- var feeds = [];
- for (var i = 0; i < _this.inputs.length; ++i) {
- feeds.push({ key: _this.inputs[i], value: inputs[i] });
- }
- var feedDict = new executor_1.FeedDict(feeds);
- var outputs = executor_1.execute(_this.outputs, feedDict);
- for (var i = 0; i < _this.lossFunctions.length; ++i) {
- var lossFunction = _this.lossFunctions[i];
- var loss = tfc.mean(lossFunction(targets[i], outputs[i]));
- if (i === 0) {
- totalLoss = loss;
- }
- else {
- totalLoss = tfc.add(totalLoss, loss);
- }
- valOutputs.push(totalLoss);
- }
- for (var i = 0; i < _this.metricsTensors.length; ++i) {
- var metric = _this.metricsTensors[i][0];
- var outputIndex = _this.metricsTensors[i][1];
- var meanMetric = tfc.mean(metric(targets[outputIndex], outputs[outputIndex]));
- valOutputs.push(meanMetric);
- }
- return valOutputs;
- });
- };
- };
- Model.prototype.fit = function (x, y, config) {
- if (config === void 0) { config = {}; }
- return __awaiter(this, void 0, void 0, function () {
- var _this = this;
- var batchSize, standardizedOuts, inputs, targets, doValidation, valX, valY, valIns, needValidationDisposal, valStandardized, splitAt, originalBatchSize, ins, trainFunction, outLabels, valFunction, callbackMetrics, callbacks, out;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- batchSize = config.batchSize == null ? 32 : config.batchSize;
- standardizedOuts = this.standardizeUserData(x, y, false, batchSize);
- inputs = standardizedOuts[0];
- targets = standardizedOuts[1];
- doValidation = false;
- needValidationDisposal = false;
- if (config.validationData != null && config.validationData.length > 0) {
- doValidation = true;
- if (config.validationData.length === 2) {
- valX = config.validationData[0];
- valY = config.validationData[1];
- }
- else if (config.validationData.length === 3) {
- throw new errors_1.NotImplementedError('validationData including sample weights is not supported yet.');
- }
- else {
- throw new errors_1.ValueError("When passing validation data, it must contain 2 (valX, valY) " +
- "or 3 (valX, valY, valSampleWeight) items; " +
- (config.validationData + " is invalid."));
- }
- valStandardized = this.standardizeUserData(valX, valY, true, batchSize);
- valX = valStandardized[0];
- valY = valStandardized[1];
- valIns = valX.concat(valY);
- }
- else if (config.validationSplit != null && config.validationSplit > 0 &&
- config.validationSplit < 1) {
- doValidation = true;
- splitAt = Math.floor(inputs[0].shape[0] * (1 - config.validationSplit));
- originalBatchSize = inputs[0].shape[0];
- valX = sliceArrays(inputs, splitAt, originalBatchSize);
- inputs = sliceArrays(inputs, 0, splitAt);
- valY = sliceArrays(targets, splitAt, originalBatchSize);
- targets = sliceArrays(targets, 0, splitAt);
- needValidationDisposal = true;
- valIns = valX.concat(valY);
- }
- else if (config.validationSteps != null) {
- doValidation = true;
- }
- ins = inputs.concat(targets);
- this.checkTrainableWeightsConsistency();
- trainFunction = function (data) {
- var losses = [];
- var lossValues = [];
- var inputs = data.slice(0, _this.inputs.length);
- var targets = data.slice(_this.inputs.length, _this.inputs.length + _this.outputs.length);
- var metricsValues = [];
- var totalLossFunction = function () {
- var feeds = [];
- for (var i = 0; i < _this.inputs.length; ++i) {
- feeds.push({ key: _this.inputs[i], value: inputs[i] });
- }
- var feedDict = new executor_1.FeedDict(feeds);
- var outputs = executor_1.execute(_this.outputs, feedDict, { 'training': true });
- var totalLoss;
- for (var i = 0; i < _this.lossFunctions.length; ++i) {
- var lossFunction = _this.lossFunctions[i];
- var loss = lossFunction(targets[i], outputs[i]);
- losses.push(loss);
- var meanLoss = tfc.mean(loss);
- lossValues.push(meanLoss);
- if (i === 0) {
- totalLoss = loss;
- }
- else {
- totalLoss = tfc.add(totalLoss, loss);
- }
- }
- for (var i = 0; i < _this.metricsTensors.length; ++i) {
- var metric = _this.metricsTensors[i][0];
- var outputIndex = _this.metricsTensors[i][1];
- var meanMetric = tfc.mean(metric(targets[outputIndex], outputs[outputIndex]));
- tfc.keep(meanMetric);
- metricsValues.push(meanMetric);
- }
- totalLoss = tfc.mean(totalLoss);
- _this.calculateLosses().forEach(function (regularizerLoss) {
- totalLoss = tfc.add(totalLoss, regularizerLoss);
- });
- return totalLoss;
- };
- var variables = _this.collectedTrainableWeights.map(function (param) { return param.read(); });
- var returnCost = true;
- var totalLossValue = _this.optimizer.minimize(totalLossFunction, returnCost, variables);
- return [totalLossValue].concat(metricsValues);
- };
- outLabels = this.getDedupedMetricsNames();
- if (doValidation) {
- this.makeTestFunction();
- valFunction = this.testFunction;
- callbackMetrics =
- outLabels.slice().concat(outLabels.map(function (n) { return 'val_' + n; }));
- }
- else {
- valFunction = null;
- valIns = [];
- callbackMetrics = outLabels.slice();
- }
- callbacks = callbacks_1.standardizeCallbacks(config.callbacks);
- return [4, this.fitLoop(trainFunction, ins, outLabels, batchSize, config.epochs, config.verbose, callbacks, valFunction, valIns, config.shuffle, callbackMetrics, null, null, null)];
- case 1:
- out = _a.sent();
- if (needValidationDisposal) {
- valIns.forEach(function (tensor) { return tensor.dispose(); });
- inputs.forEach(function (tensor) { return tensor.dispose(); });
- targets.forEach(function (tensor) { return tensor.dispose(); });
- }
- return [2, out];
- }
- });
- });
- };
- Model.prototype.getNamedWeights = function (config) {
- var namedWeights = {};
- var trainableOnly = config != null && config.trainableOnly;
- var weights = trainableOnly ? this.trainableWeights : this.weights;
- var weightValues = this.getWeights(trainableOnly);
- for (var i = 0; i < weights.length; ++i) {
- if (trainableOnly && !weights[i].trainable) {
- continue;
- }
- namedWeights[weights[i].originalName] = weightValues[i];
- }
- return namedWeights;
- };
- Model.prototype.save = function (handlerOrURL, config) {
- return __awaiter(this, void 0, void 0, function () {
- var handlers, weightDataAndSpecs, returnString, unusedArg, modelConfig;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (typeof handlerOrURL === 'string') {
- handlers = tfjs_core_1.io.getSaveHandlers(handlerOrURL);
- if (handlers.length === 0) {
- throw new errors_1.ValueError("Cannot find any save handlers for URL '" + handlerOrURL + "'");
- }
- else if (handlers.length > 1) {
- throw new errors_1.ValueError("Found more than one (" + handlers.length + ") save handlers for " +
- ("URL '" + handlerOrURL + "'"));
- }
- handlerOrURL = handlers[0];
- }
- if (handlerOrURL.save == null) {
- throw new errors_1.ValueError('Model.save() cannot proceed because the IOHandler provided does ' +
- 'not have the `save` attribute defined.');
- }
- return [4, tfjs_core_1.io.encodeWeights(this.getNamedWeights(config))];
- case 1:
- weightDataAndSpecs = _a.sent();
- returnString = false;
- unusedArg = null;
- modelConfig = this.toJSON(unusedArg, returnString);
- return [2, handlerOrURL.save({
- modelTopology: modelConfig,
- weightData: weightDataAndSpecs.data,
- weightSpecs: weightDataAndSpecs.specs
- })];
- }
- });
- });
- };
- Model.className = 'Model';
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes' })
- ], Model.prototype, "summary", null);
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes', configParamIndices: [0] })
- ], Model.prototype, "compile", null);
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes', configParamIndices: [2] })
- ], Model.prototype, "evaluate", null);
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes', configParamIndices: [1] })
- ], Model.prototype, "predict", null);
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes' })
- ], Model.prototype, "predictOnBatch", null);
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes', configParamIndices: [2] })
- ], Model.prototype, "fit", null);
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes', configParamIndices: [1] })
- ], Model.prototype, "save", null);
- Model = __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes' })
- ], Model);
- return Model;
- }(topology_1.Container));
- exports.Model = Model;
- tfjs_core_1.serialization.SerializationMap.register(Model);
- },{"../backend/tfjs_backend":169,"../callbacks":170,"../errors":176,"../losses":192,"../metrics":193,"../optimizers":195,"../utils/generic_utils":199,"../utils/layer_utils":200,"../utils/math_utils":201,"./executor":173,"./topology":174,"@tensorflow/tfjs-core":54}],176:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var AttributeError = (function (_super) {
- __extends(AttributeError, _super);
- function AttributeError(message) {
- var _this = _super.call(this, message) || this;
- Object.setPrototypeOf(_this, AttributeError.prototype);
- return _this;
- }
- return AttributeError;
- }(Error));
- exports.AttributeError = AttributeError;
- var RuntimeError = (function (_super) {
- __extends(RuntimeError, _super);
- function RuntimeError(message) {
- var _this = _super.call(this, message) || this;
- Object.setPrototypeOf(_this, RuntimeError.prototype);
- return _this;
- }
- return RuntimeError;
- }(Error));
- exports.RuntimeError = RuntimeError;
- var ValueError = (function (_super) {
- __extends(ValueError, _super);
- function ValueError(message) {
- var _this = _super.call(this, message) || this;
- Object.setPrototypeOf(_this, ValueError.prototype);
- return _this;
- }
- return ValueError;
- }(Error));
- exports.ValueError = ValueError;
- var NotImplementedError = (function (_super) {
- __extends(NotImplementedError, _super);
- function NotImplementedError(message) {
- var _this = _super.call(this, message) || this;
- Object.setPrototypeOf(_this, NotImplementedError.prototype);
- return _this;
- }
- return NotImplementedError;
- }(Error));
- exports.NotImplementedError = NotImplementedError;
- var AssertionError = (function (_super) {
- __extends(AssertionError, _super);
- function AssertionError(message) {
- var _this = _super.call(this, message) || this;
- Object.setPrototypeOf(_this, AssertionError.prototype);
- return _this;
- }
- return AssertionError;
- }(Error));
- exports.AssertionError = AssertionError;
- var IndexError = (function (_super) {
- __extends(IndexError, _super);
- function IndexError(message) {
- var _this = _super.call(this, message) || this;
- Object.setPrototypeOf(_this, IndexError.prototype);
- return _this;
- }
- return IndexError;
- }(Error));
- exports.IndexError = IndexError;
- },{}],177:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var constraints_1 = require("./constraints");
- var topology_1 = require("./engine/topology");
- var training_1 = require("./engine/training");
- var initializers_1 = require("./initializers");
- var advanced_activations_1 = require("./layers/advanced_activations");
- var convolutional_1 = require("./layers/convolutional");
- var convolutional_depthwise_1 = require("./layers/convolutional_depthwise");
- var core_1 = require("./layers/core");
- var embeddings_1 = require("./layers/embeddings");
- var merge_1 = require("./layers/merge");
- var normalization_1 = require("./layers/normalization");
- var padding_1 = require("./layers/padding");
- var pooling_1 = require("./layers/pooling");
- var recurrent_1 = require("./layers/recurrent");
- var wrappers_1 = require("./layers/wrappers");
- var losses_1 = require("./losses");
- var metrics_1 = require("./metrics");
- var models_1 = require("./models");
- var regularizers_1 = require("./regularizers");
- var ModelExports = (function () {
- function ModelExports() {
- }
- ModelExports.model = function (config) {
- return new training_1.Model(config);
- };
- ModelExports.sequential = function (config) {
- return new models_1.Sequential(config);
- };
- ModelExports.loadModel = function (pathOrIOHandler) {
- return models_1.loadModelInternal(pathOrIOHandler);
- };
- ModelExports.input = function (config) {
- return topology_1.Input(config);
- };
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Creation', configParamIndices: [0] })
- ], ModelExports, "model", null);
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Creation', configParamIndices: [0] })
- ], ModelExports, "sequential", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Models',
- subheading: 'Loading',
- useDocsFrom: 'loadModelInternal'
- })
- ], ModelExports, "loadModel", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Models',
- subheading: 'Inputs',
- useDocsFrom: 'Input',
- configParamIndices: [0]
- })
- ], ModelExports, "input", null);
- return ModelExports;
- }());
- exports.ModelExports = ModelExports;
- var LayerExports = (function () {
- function LayerExports() {
- }
- LayerExports.inputLayer = function (config) {
- return new topology_1.InputLayer(config);
- };
- LayerExports.elu = function (config) {
- return new advanced_activations_1.ELU(config);
- };
- LayerExports.leakyReLU = function (config) {
- return new advanced_activations_1.LeakyReLU(config);
- };
- LayerExports.softmax = function (config) {
- return new advanced_activations_1.Softmax(config);
- };
- LayerExports.thresholdedReLU = function (config) {
- return new advanced_activations_1.ThresholdedReLU(config);
- };
- LayerExports.conv1d = function (config) {
- return new convolutional_1.Conv1D(config);
- };
- LayerExports.conv2d = function (config) {
- return new convolutional_1.Conv2D(config);
- };
- LayerExports.conv2dTranspose = function (config) {
- return new convolutional_1.Conv2DTranspose(config);
- };
- LayerExports.separableConv2d = function (config) {
- return new convolutional_1.SeparableConv2D(config);
- };
- LayerExports.cropping2D = function (config) {
- return new convolutional_1.Cropping2D(config);
- };
- LayerExports.upSampling2d = function (config) {
- return new convolutional_1.UpSampling2D(config);
- };
- LayerExports.depthwiseConv2d = function (config) {
- return new convolutional_depthwise_1.DepthwiseConv2D(config);
- };
- LayerExports.activation = function (config) {
- return new core_1.Activation(config);
- };
- LayerExports.dense = function (config) {
- return new core_1.Dense(config);
- };
- LayerExports.dropout = function (config) {
- return new core_1.Dropout(config);
- };
- LayerExports.flatten = function (config) {
- return new core_1.Flatten(config);
- };
- LayerExports.repeatVector = function (config) {
- return new core_1.RepeatVector(config);
- };
- LayerExports.reshape = function (config) {
- return new core_1.Reshape(config);
- };
- LayerExports.embedding = function (config) {
- return new embeddings_1.Embedding(config);
- };
- LayerExports.add = function (config) {
- return new merge_1.Add(config);
- };
- LayerExports.average = function (config) {
- return new merge_1.Average(config);
- };
- LayerExports.concatenate = function (config) {
- return new merge_1.Concatenate(config);
- };
- LayerExports.maximum = function (config) {
- return new merge_1.Maximum(config);
- };
- LayerExports.minimum = function (config) {
- return new merge_1.Minimum(config);
- };
- LayerExports.multiply = function (config) {
- return new merge_1.Multiply(config);
- };
- LayerExports.batchNormalization = function (config) {
- return new normalization_1.BatchNormalization(config);
- };
- LayerExports.zeroPadding2d = function (config) {
- return new padding_1.ZeroPadding2D(config);
- };
- LayerExports.averagePooling1d = function (config) {
- return new pooling_1.AveragePooling1D(config);
- };
- LayerExports.avgPool1d = function (config) {
- return LayerExports.averagePooling1d(config);
- };
- LayerExports.avgPooling1d = function (config) {
- return LayerExports.averagePooling1d(config);
- };
- LayerExports.averagePooling2d = function (config) {
- return new pooling_1.AveragePooling2D(config);
- };
- LayerExports.avgPool2d = function (config) {
- return LayerExports.averagePooling2d(config);
- };
- LayerExports.avgPooling2d = function (config) {
- return LayerExports.averagePooling2d(config);
- };
- LayerExports.globalAveragePooling1d = function (config) {
- return new pooling_1.GlobalAveragePooling1D(config);
- };
- LayerExports.globalAveragePooling2d = function (config) {
- return new pooling_1.GlobalAveragePooling2D(config);
- };
- LayerExports.globalMaxPooling1d = function (config) {
- return new pooling_1.GlobalMaxPooling1D(config);
- };
- LayerExports.globalMaxPooling2d = function (config) {
- return new pooling_1.GlobalMaxPooling2D(config);
- };
- LayerExports.maxPooling1d = function (config) {
- return new pooling_1.MaxPooling1D(config);
- };
- LayerExports.maxPooling2d = function (config) {
- return new pooling_1.MaxPooling2D(config);
- };
- LayerExports.gru = function (config) {
- return new recurrent_1.GRU(config);
- };
- LayerExports.gruCell = function (config) {
- return new recurrent_1.GRUCell(config);
- };
- LayerExports.lstm = function (config) {
- return new recurrent_1.LSTM(config);
- };
- LayerExports.lstmCell = function (config) {
- return new recurrent_1.LSTMCell(config);
- };
- LayerExports.simpleRNN = function (config) {
- return new recurrent_1.SimpleRNN(config);
- };
- LayerExports.simpleRNNCell = function (config) {
- return new recurrent_1.SimpleRNNCell(config);
- };
- LayerExports.rnn = function (config) {
- return new recurrent_1.RNN(config);
- };
- LayerExports.stackedRNNCells = function (config) {
- return new recurrent_1.StackedRNNCells(config);
- };
- LayerExports.bidirectional = function (config) {
- return new wrappers_1.Bidirectional(config);
- };
- LayerExports.timeDistributed = function (config) {
- return new wrappers_1.TimeDistributed(config);
- };
- LayerExports.Layer = topology_1.Layer;
- LayerExports.RNN = recurrent_1.RNN;
- LayerExports.RNNCell = recurrent_1.RNNCell;
- LayerExports.input = ModelExports.input;
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Inputs',
- namespace: 'layers',
- useDocsFrom: 'InputLayer',
- configParamIndices: [0]
- })
- ], LayerExports, "inputLayer", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Advanced Activation',
- namespace: 'layers',
- useDocsFrom: 'ELU',
- configParamIndices: [0]
- })
- ], LayerExports, "elu", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Advanced Activation',
- namespace: 'layers',
- useDocsFrom: 'LeakyReLU',
- configParamIndices: [0]
- })
- ], LayerExports, "leakyReLU", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Advanced Activation',
- namespace: 'layers',
- useDocsFrom: 'Softmax',
- configParamIndices: [0]
- })
- ], LayerExports, "softmax", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Advanced Activation',
- namespace: 'layers',
- useDocsFrom: 'ThresholdedReLU',
- configParamIndices: [0]
- })
- ], LayerExports, "thresholdedReLU", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Convolutional',
- namespace: 'layers',
- useDocsFrom: 'Conv1D',
- configParamIndices: [0]
- })
- ], LayerExports, "conv1d", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Convolutional',
- namespace: 'layers',
- useDocsFrom: 'Conv2D',
- configParamIndices: [0]
- })
- ], LayerExports, "conv2d", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Convolutional',
- namespace: 'layers',
- useDocsFrom: 'Conv2DTranspose',
- configParamIndices: [0]
- })
- ], LayerExports, "conv2dTranspose", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Convolutional',
- namespace: 'layers',
- useDocsFrom: 'SeparableConv2D',
- configParamIndices: [0]
- })
- ], LayerExports, "separableConv2d", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Convolutional',
- namespace: 'layers',
- useDocsFrom: 'Cropping2D',
- configParamIndices: [0]
- })
- ], LayerExports, "cropping2D", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Convolutional',
- namespace: 'layers',
- useDocsFrom: 'UpSampling2D',
- configParamIndices: [0]
- })
- ], LayerExports, "upSampling2d", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Convolutional',
- namespace: 'layers',
- useDocsFrom: 'DepthwiseConv2D',
- configParamIndices: [0]
- })
- ], LayerExports, "depthwiseConv2d", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Basic',
- namespace: 'layers',
- useDocsFrom: 'Activation',
- configParamIndices: [0]
- })
- ], LayerExports, "activation", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Basic',
- namespace: 'layers',
- useDocsFrom: 'Dense',
- configParamIndices: [0]
- })
- ], LayerExports, "dense", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Basic',
- namespace: 'layers',
- useDocsFrom: 'Dropout',
- configParamIndices: [0]
- })
- ], LayerExports, "dropout", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Basic',
- namespace: 'layers',
- useDocsFrom: 'Flatten',
- configParamIndices: [0]
- })
- ], LayerExports, "flatten", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Basic',
- namespace: 'layers',
- useDocsFrom: 'RepeatVector',
- configParamIndices: [0]
- })
- ], LayerExports, "repeatVector", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Basic',
- namespace: 'layers',
- useDocsFrom: 'Reshape',
- configParamIndices: [0]
- })
- ], LayerExports, "reshape", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Basic',
- namespace: 'layers',
- useDocsFrom: 'Embedding',
- configParamIndices: [0]
- })
- ], LayerExports, "embedding", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Merge',
- namespace: 'layers',
- useDocsFrom: 'Add',
- configParamIndices: [0]
- })
- ], LayerExports, "add", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Merge',
- namespace: 'layers',
- useDocsFrom: 'Average',
- configParamIndices: [0]
- })
- ], LayerExports, "average", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Merge',
- namespace: 'layers',
- useDocsFrom: 'Concatenate',
- configParamIndices: [0]
- })
- ], LayerExports, "concatenate", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Merge',
- namespace: 'layers',
- useDocsFrom: 'Maximum',
- configParamIndices: [0]
- })
- ], LayerExports, "maximum", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Merge',
- namespace: 'layers',
- useDocsFrom: 'Minimum',
- configParamIndices: [0]
- })
- ], LayerExports, "minimum", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Merge',
- namespace: 'layers',
- useDocsFrom: 'Multiply',
- configParamIndices: [0]
- })
- ], LayerExports, "multiply", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Normalization',
- namespace: 'layers',
- useDocsFrom: 'BatchNormalization',
- configParamIndices: [0]
- })
- ], LayerExports, "batchNormalization", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Padding',
- namespace: 'layers',
- useDocsFrom: 'ZeroPadding2D',
- configParamIndices: [0]
- })
- ], LayerExports, "zeroPadding2d", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Pooling',
- namespace: 'layers',
- useDocsFrom: 'AveragePooling1D',
- configParamIndices: [0]
- })
- ], LayerExports, "averagePooling1d", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Pooling',
- namespace: 'layers',
- useDocsFrom: 'AveragePooling2D',
- configParamIndices: [0]
- })
- ], LayerExports, "averagePooling2d", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Pooling',
- namespace: 'layers',
- useDocsFrom: 'GlobalAveragePooling1D',
- configParamIndices: [0]
- })
- ], LayerExports, "globalAveragePooling1d", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Pooling',
- namespace: 'layers',
- useDocsFrom: 'GlobalAveragePooling2D',
- configParamIndices: [0]
- })
- ], LayerExports, "globalAveragePooling2d", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Pooling',
- namespace: 'layers',
- useDocsFrom: 'GlobalMaxPooling1D',
- configParamIndices: [0]
- })
- ], LayerExports, "globalMaxPooling1d", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Pooling',
- namespace: 'layers',
- useDocsFrom: 'GlobalMaxPooling2D',
- configParamIndices: [0]
- })
- ], LayerExports, "globalMaxPooling2d", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Pooling',
- namespace: 'layers',
- useDocsFrom: 'MaxPooling1D',
- configParamIndices: [0]
- })
- ], LayerExports, "maxPooling1d", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Pooling',
- namespace: 'layers',
- useDocsFrom: 'MaxPooling2D',
- configParamIndices: [0]
- })
- ], LayerExports, "maxPooling2d", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Recurrent',
- namespace: 'layers',
- useDocsFrom: 'GRU',
- configParamIndices: [0]
- })
- ], LayerExports, "gru", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Recurrent',
- namespace: 'layers',
- useDocsFrom: 'GRUCell',
- configParamIndices: [0]
- })
- ], LayerExports, "gruCell", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Recurrent',
- namespace: 'layers',
- useDocsFrom: 'LSTM',
- configParamIndices: [0]
- })
- ], LayerExports, "lstm", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Recurrent',
- namespace: 'layers',
- useDocsFrom: 'LSTMCell',
- configParamIndices: [0]
- })
- ], LayerExports, "lstmCell", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Recurrent',
- namespace: 'layers',
- useDocsFrom: 'SimpleRNN',
- configParamIndices: [0]
- })
- ], LayerExports, "simpleRNN", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Recurrent',
- namespace: 'layers',
- useDocsFrom: 'SimpleRNNCell',
- configParamIndices: [0]
- })
- ], LayerExports, "simpleRNNCell", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Recurrent',
- namespace: 'layers',
- useDocsFrom: 'RNN',
- configParamIndices: [0]
- })
- ], LayerExports, "rnn", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Recurrent',
- namespace: 'layers',
- useDocsFrom: 'RNN',
- configParamIndices: [0]
- })
- ], LayerExports, "stackedRNNCells", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Wrapper',
- namespace: 'layers',
- useDocsFrom: 'Bidirectional',
- configParamIndices: [0]
- })
- ], LayerExports, "bidirectional", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Layers',
- subheading: 'Wrapper',
- namespace: 'layers',
- useDocsFrom: 'TimeDistributed',
- configParamIndices: [0]
- })
- ], LayerExports, "timeDistributed", null);
- return LayerExports;
- }());
- exports.LayerExports = LayerExports;
- var ConstraintExports = (function () {
- function ConstraintExports() {
- }
- ConstraintExports.maxNorm = function (config) {
- return new constraints_1.MaxNorm(config);
- };
- ConstraintExports.unitNorm = function (config) {
- return new constraints_1.UnitNorm(config);
- };
- ConstraintExports.nonNeg = function () {
- return new constraints_1.NonNeg();
- };
- ConstraintExports.minMaxNorm = function (config) {
- return new constraints_1.MinMaxNorm(config);
- };
- __decorate([
- tfjs_core_1.doc({
- heading: 'Constraints',
- namespace: 'constraints',
- useDocsFrom: 'MaxNorm',
- configParamIndices: [0]
- })
- ], ConstraintExports, "maxNorm", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Constraints',
- namespace: 'constraints',
- useDocsFrom: 'UnitNorm',
- configParamIndices: [0]
- })
- ], ConstraintExports, "unitNorm", null);
- __decorate([
- tfjs_core_1.doc({ heading: 'Constraints', namespace: 'constraints', useDocsFrom: 'NonNeg' })
- ], ConstraintExports, "nonNeg", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Constraints',
- namespace: 'constraints',
- useDocsFrom: 'MinMaxNormConfig',
- configParamIndices: [0]
- })
- ], ConstraintExports, "minMaxNorm", null);
- return ConstraintExports;
- }());
- exports.ConstraintExports = ConstraintExports;
- var InitializerExports = (function () {
- function InitializerExports() {
- }
- InitializerExports.zeros = function () {
- return new initializers_1.Zeros();
- };
- InitializerExports.ones = function () {
- return new initializers_1.Ones();
- };
- InitializerExports.constant = function (config) {
- return new initializers_1.Constant(config);
- };
- InitializerExports.randomUniform = function (config) {
- return new initializers_1.RandomUniform(config);
- };
- InitializerExports.randomNormal = function (config) {
- return new initializers_1.RandomNormal(config);
- };
- InitializerExports.truncatedNormal = function (config) {
- return new initializers_1.TruncatedNormal(config);
- };
- InitializerExports.identity = function (config) {
- return new initializers_1.Identity(config);
- };
- InitializerExports.varianceScaling = function (config) {
- return new initializers_1.VarianceScaling(config);
- };
- InitializerExports.glorotUniform = function (config) {
- return new initializers_1.GlorotUniform(config);
- };
- InitializerExports.glorotNormal = function (config) {
- return new initializers_1.GlorotNormal(config);
- };
- InitializerExports.heNormal = function (config) {
- return new initializers_1.HeNormal(config);
- };
- InitializerExports.leCunNormal = function (config) {
- return new initializers_1.LeCunNormal(config);
- };
- InitializerExports.orthogonal = function (config) {
- return new initializers_1.Orthogonal(config);
- };
- __decorate([
- tfjs_core_1.doc({
- heading: 'Initializers',
- namespace: 'initializers',
- useDocsFrom: 'Zeros'
- })
- ], InitializerExports, "zeros", null);
- __decorate([
- tfjs_core_1.doc({ heading: 'Initializers', namespace: 'initializers', useDocsFrom: 'Ones' })
- ], InitializerExports, "ones", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Initializers',
- namespace: 'initializers',
- useDocsFrom: 'Constant',
- configParamIndices: [0]
- })
- ], InitializerExports, "constant", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Initializers',
- namespace: 'initializers',
- useDocsFrom: 'RandomUniform',
- configParamIndices: [0]
- })
- ], InitializerExports, "randomUniform", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Initializers',
- namespace: 'initializers',
- useDocsFrom: 'RandomNormal',
- configParamIndices: [0]
- })
- ], InitializerExports, "randomNormal", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Initializers',
- namespace: 'initializers',
- useDocsFrom: 'TruncatedNormal',
- configParamIndices: [0]
- })
- ], InitializerExports, "truncatedNormal", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Initializers',
- namespace: 'initializers',
- useDocsFrom: 'Identity',
- configParamIndices: [0]
- })
- ], InitializerExports, "identity", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Initializers',
- namespace: 'initializers',
- useDocsFrom: 'VarianceScaling',
- configParamIndices: [0]
- })
- ], InitializerExports, "varianceScaling", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Initializers',
- namespace: 'initializers',
- useDocsFrom: 'GlorotUniform',
- configParamIndices: [0]
- })
- ], InitializerExports, "glorotUniform", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Initializers',
- namespace: 'initializers',
- useDocsFrom: 'GlorotNormal',
- configParamIndices: [0]
- })
- ], InitializerExports, "glorotNormal", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Initializers',
- namespace: 'initializers',
- useDocsFrom: 'HeNormal',
- configParamIndices: [0]
- })
- ], InitializerExports, "heNormal", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Initializers',
- namespace: 'initializers',
- useDocsFrom: 'LeCunNormal',
- configParamIndices: [0]
- })
- ], InitializerExports, "leCunNormal", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Initializers',
- namespace: 'initializers',
- useDocsFrom: 'Orthogonal',
- configParamIndices: [0]
- })
- ], InitializerExports, "orthogonal", null);
- return InitializerExports;
- }());
- exports.InitializerExports = InitializerExports;
- var MetricExports = (function () {
- function MetricExports() {
- }
- MetricExports.binaryAccuracy = function (yTrue, yPred) {
- return metrics_1.binaryAccuracy(yTrue, yPred);
- };
- MetricExports.binaryCrossentropy = function (yTrue, yPred) {
- return metrics_1.binaryCrossentropy(yTrue, yPred);
- };
- MetricExports.categoricalAccuracy = function (yTrue, yPred) {
- return metrics_1.categoricalAccuracy(yTrue, yPred);
- };
- MetricExports.categoricalCrossentropy = function (yTrue, yPred) {
- return losses_1.categoricalCrossentropy(yTrue, yPred);
- };
- MetricExports.cosineProximity = function (yTrue, yPred) {
- return losses_1.cosineProximity(yTrue, yPred);
- };
- MetricExports.prototype.meanAbsoluteError = function (yTrue, yPred) {
- return losses_1.meanAbsoluteError(yTrue, yPred);
- };
- MetricExports.prototype.meanAbsolutePercentageError = function (yTrue, yPred) {
- return losses_1.meanAbsolutePercentageError(yTrue, yPred);
- };
- MetricExports.prototype.MAPE = function (yTrue, yPred) {
- return losses_1.meanAbsolutePercentageError(yTrue, yPred);
- };
- MetricExports.prototype.mape = function (yTrue, yPred) {
- return losses_1.meanAbsolutePercentageError(yTrue, yPred);
- };
- MetricExports.meanSquaredError = function (yTrue, yPred) {
- return losses_1.meanSquaredError(yTrue, yPred);
- };
- MetricExports.MSE = function (yTrue, yPred) {
- return losses_1.meanSquaredError(yTrue, yPred);
- };
- MetricExports.mse = function (yTrue, yPred) {
- return losses_1.meanSquaredError(yTrue, yPred);
- };
- __decorate([
- tfjs_core_1.doc({
- heading: 'Metrics',
- namespace: 'metrics',
- useDocsFrom: 'meanAbsoluteError'
- })
- ], MetricExports.prototype, "meanAbsoluteError", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Metrics',
- namespace: 'metrics',
- useDocsFrom: 'meanAbsolutePercentageError'
- })
- ], MetricExports.prototype, "meanAbsolutePercentageError", null);
- __decorate([
- tfjs_core_1.doc({ heading: 'Metrics', namespace: 'metrics', useDocsFrom: 'binaryAccuracy' })
- ], MetricExports, "binaryAccuracy", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Metrics',
- namespace: 'metrics',
- useDocsFrom: 'binaryCrossentropy'
- })
- ], MetricExports, "binaryCrossentropy", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Metrics',
- namespace: 'metrics',
- useDocsFrom: 'categoricalAccuracy'
- })
- ], MetricExports, "categoricalAccuracy", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Metrics',
- namespace: 'metrics',
- useDocsFrom: 'categoricalCrossentropy'
- })
- ], MetricExports, "categoricalCrossentropy", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Metrics',
- namespace: 'metrics',
- useDocsFrom: 'cosineProximity'
- })
- ], MetricExports, "cosineProximity", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Metrics',
- namespace: 'metrics',
- useDocsFrom: 'meanSquaredError'
- })
- ], MetricExports, "meanSquaredError", null);
- return MetricExports;
- }());
- exports.MetricExports = MetricExports;
- var RegularizerExports = (function () {
- function RegularizerExports() {
- }
- RegularizerExports.l1l2 = function (config) {
- return new regularizers_1.L1L2(config);
- };
- RegularizerExports.l1 = function (config) {
- return regularizers_1.l1(config);
- };
- RegularizerExports.l2 = function (config) {
- return regularizers_1.l2(config);
- };
- __decorate([
- tfjs_core_1.doc({
- heading: 'Regularizers',
- namespace: 'regularizers',
- useDocsFrom: 'L1L2',
- configParamIndices: [0]
- })
- ], RegularizerExports, "l1l2", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Regularizers',
- namespace: 'regularizers',
- useDocsFrom: 'L1L2',
- configParamIndices: [0]
- })
- ], RegularizerExports, "l1", null);
- __decorate([
- tfjs_core_1.doc({
- heading: 'Regularizers',
- namespace: 'regularizers',
- useDocsFrom: 'L1L2',
- configParamIndices: [0]
- })
- ], RegularizerExports, "l2", null);
- return RegularizerExports;
- }());
- exports.RegularizerExports = RegularizerExports;
- },{"./constraints":172,"./engine/topology":174,"./engine/training":175,"./initializers":179,"./layers/advanced_activations":180,"./layers/convolutional":181,"./layers/convolutional_depthwise":182,"./layers/core":183,"./layers/embeddings":184,"./layers/merge":185,"./layers/normalization":186,"./layers/padding":187,"./layers/pooling":188,"./layers/recurrent":189,"./layers/wrappers":191,"./losses":192,"./metrics":193,"./models":194,"./regularizers":196,"@tensorflow/tfjs-core":54}],178:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var exports_1 = require("./exports");
- var callbacks_1 = require("./callbacks");
- exports.Callback = callbacks_1.Callback;
- exports.CallbackList = callbacks_1.CallbackList;
- exports.CustomCallback = callbacks_1.CustomCallback;
- var training_1 = require("./engine/training");
- exports.Model = training_1.Model;
- var recurrent_1 = require("./layers/recurrent");
- exports.RNN = recurrent_1.RNN;
- var models_1 = require("./models");
- exports.Sequential = models_1.Sequential;
- var types_1 = require("./types");
- exports.SymbolicTensor = types_1.SymbolicTensor;
- var version_1 = require("./version");
- exports.version_layers = version_1.version;
- exports.model = exports_1.ModelExports.model;
- exports.sequential = exports_1.ModelExports.sequential;
- exports.loadModel = exports_1.ModelExports.loadModel;
- exports.input = exports_1.ModelExports.input;
- exports.layers = exports_1.LayerExports;
- exports.constraints = exports_1.ConstraintExports;
- exports.initializers = exports_1.InitializerExports;
- exports.metrics = exports_1.MetricExports;
- exports.regularizers = exports_1.RegularizerExports;
- },{"./callbacks":170,"./engine/training":175,"./exports":177,"./layers/recurrent":189,"./models":194,"./types":197,"./version":204}],179:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("./backend/tfjs_backend");
- var common_1 = require("./common");
- var errors_1 = require("./errors");
- var generic_utils_1 = require("./utils/generic_utils");
- var math_utils_1 = require("./utils/math_utils");
- exports.VALID_FAN_MODE_VALUES = ['fanIn', 'fanOut', 'fanAvg'];
- function checkFanMode(value) {
- generic_utils_1.checkStringTypeUnionValue(exports.VALID_FAN_MODE_VALUES, 'FanMode', value);
- }
- exports.checkFanMode = checkFanMode;
- exports.VALID_DISTRIBUTION_VALUES = ['normal', 'uniform'];
- function checkDistribution(value) {
- generic_utils_1.checkStringTypeUnionValue(exports.VALID_DISTRIBUTION_VALUES, 'Distribution', value);
- }
- exports.checkDistribution = checkDistribution;
- var Initializer = (function (_super) {
- __extends(Initializer, _super);
- function Initializer() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Initializer.prototype.fromConfigUsesCustomObjects = function () {
- return false;
- };
- Initializer.prototype.getConfig = function () {
- return {};
- };
- Initializer = __decorate([
- tfjs_core_1.doc({ heading: 'Initializers', subheading: 'Classes', namespace: 'initializers' })
- ], Initializer);
- return Initializer;
- }(tfjs_core_1.serialization.Serializable));
- exports.Initializer = Initializer;
- var Zeros = (function (_super) {
- __extends(Zeros, _super);
- function Zeros() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Zeros.prototype.apply = function (shape, dtype) {
- return tfjs_core_1.zeros(shape, dtype);
- };
- Zeros.className = 'Zeros';
- return Zeros;
- }(Initializer));
- exports.Zeros = Zeros;
- tfjs_core_1.serialization.SerializationMap.register(Zeros);
- var Ones = (function (_super) {
- __extends(Ones, _super);
- function Ones() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Ones.prototype.apply = function (shape, dtype) {
- return tfjs_core_1.ones(shape, dtype);
- };
- Ones.className = 'Ones';
- return Ones;
- }(Initializer));
- exports.Ones = Ones;
- tfjs_core_1.serialization.SerializationMap.register(Ones);
- var Constant = (function (_super) {
- __extends(Constant, _super);
- function Constant(config) {
- var _this = _super.call(this) || this;
- _this.value = config.value;
- return _this;
- }
- Constant.prototype.apply = function (shape, dtype) {
- var _this = this;
- return tfjs_core_1.tidy(function () { return K.scalarTimesArray(tfjs_core_1.scalar(_this.value), tfjs_core_1.ones(shape, dtype)); });
- };
- Constant.prototype.getConfig = function () {
- return {
- value: this.value,
- };
- };
- Constant.className = 'Constant';
- return Constant;
- }(Initializer));
- exports.Constant = Constant;
- tfjs_core_1.serialization.SerializationMap.register(Constant);
- var RandomUniform = (function (_super) {
- __extends(RandomUniform, _super);
- function RandomUniform(config) {
- var _this = _super.call(this) || this;
- _this.DEFAULT_MINVAL = -0.05;
- _this.DEFAULT_MAXVAL = 0.05;
- _this.minval = config.minval || _this.DEFAULT_MINVAL;
- _this.maxval = config.maxval || _this.DEFAULT_MAXVAL;
- _this.seed = config.seed;
- return _this;
- }
- RandomUniform.prototype.apply = function (shape, dtype) {
- return tfjs_core_1.randomUniform(shape, this.minval, this.maxval, dtype);
- };
- RandomUniform.prototype.getConfig = function () {
- return { minval: this.minval, maxval: this.maxval, seed: this.seed };
- };
- RandomUniform.className = 'RandomUniform';
- return RandomUniform;
- }(Initializer));
- exports.RandomUniform = RandomUniform;
- tfjs_core_1.serialization.SerializationMap.register(RandomUniform);
- var RandomNormal = (function (_super) {
- __extends(RandomNormal, _super);
- function RandomNormal(config) {
- var _this = _super.call(this) || this;
- _this.DEFAULT_MEAN = 0.;
- _this.DEFAULT_STDDEV = 0.05;
- _this.mean = config.mean || _this.DEFAULT_MEAN;
- _this.stddev = config.stddev || _this.DEFAULT_STDDEV;
- _this.seed = config.seed;
- return _this;
- }
- RandomNormal.prototype.apply = function (shape, dtype) {
- if (dtype === 'bool') {
- throw new errors_1.NotImplementedError("randomNormal does not support dType bool.");
- }
- return K.randomNormal(shape, this.mean, this.stddev, dtype, this.seed);
- };
- RandomNormal.prototype.getConfig = function () {
- return { mean: this.mean, stddev: this.stddev, seed: this.seed };
- };
- RandomNormal.className = 'RandomNormal';
- return RandomNormal;
- }(Initializer));
- exports.RandomNormal = RandomNormal;
- tfjs_core_1.serialization.SerializationMap.register(RandomNormal);
- var TruncatedNormal = (function (_super) {
- __extends(TruncatedNormal, _super);
- function TruncatedNormal(config) {
- var _this = _super.call(this) || this;
- _this.DEFAULT_MEAN = 0.;
- _this.DEFAULT_STDDEV = 0.05;
- _this.mean = config.mean || _this.DEFAULT_MEAN;
- _this.stddev = config.stddev || _this.DEFAULT_STDDEV;
- _this.seed = config.seed;
- return _this;
- }
- TruncatedNormal.prototype.apply = function (shape, dtype) {
- if (dtype === 'bool') {
- throw new errors_1.NotImplementedError("truncatedNormal does not support dType bool.");
- }
- return tfjs_core_1.truncatedNormal(shape, this.mean, this.stddev, dtype, this.seed);
- };
- TruncatedNormal.prototype.getConfig = function () {
- return { mean: this.mean, stddev: this.stddev, seed: this.seed };
- };
- TruncatedNormal.className = 'TruncatedNormal';
- return TruncatedNormal;
- }(Initializer));
- exports.TruncatedNormal = TruncatedNormal;
- tfjs_core_1.serialization.SerializationMap.register(TruncatedNormal);
- var Identity = (function (_super) {
- __extends(Identity, _super);
- function Identity(config) {
- var _this = _super.call(this) || this;
- _this.gain = config.gain != null ? tfjs_core_1.scalar(config.gain) : K.getScalar(1.0);
- return _this;
- }
- Identity.prototype.apply = function (shape, dtype) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- if (shape.length !== 2 || shape[0] !== shape[1]) {
- throw new errors_1.ValueError('Identity matrix initializer can only be used for' +
- ' 2D square matrices.');
- }
- else {
- return K.scalarTimesArray(_this.gain, tfjs_core_1.eye(shape[0]));
- }
- });
- };
- Identity.prototype.getConfig = function () {
- return { gain: this.gain.get() };
- };
- Identity.className = 'Identity';
- return Identity;
- }(Initializer));
- exports.Identity = Identity;
- tfjs_core_1.serialization.SerializationMap.register(Identity);
- function computeFans(shape, dataFormat) {
- if (dataFormat === void 0) { dataFormat = 'channelsLast'; }
- var fanIn;
- var fanOut;
- common_1.checkDataFormat(dataFormat);
- if (shape.length === 2) {
- fanIn = shape[0];
- fanOut = shape[1];
- }
- else if ([3, 4, 5].indexOf(shape.length) !== -1) {
- if (dataFormat === 'channelsFirst') {
- var receptiveFieldSize = math_utils_1.arrayProd(shape, 2);
- fanIn = shape[1] * receptiveFieldSize;
- fanOut = shape[0] * receptiveFieldSize;
- }
- else if (dataFormat === 'channelsLast') {
- var receptiveFieldSize = math_utils_1.arrayProd(shape, 0, shape.length - 2);
- fanIn = shape[shape.length - 2] * receptiveFieldSize;
- fanOut = shape[shape.length - 1] * receptiveFieldSize;
- }
- }
- else {
- var shapeProd = math_utils_1.arrayProd(shape);
- fanIn = Math.sqrt(shapeProd);
- fanOut = Math.sqrt(shapeProd);
- }
- return [fanIn, fanOut];
- }
- var VarianceScaling = (function (_super) {
- __extends(VarianceScaling, _super);
- function VarianceScaling(config) {
- var _this = _super.call(this) || this;
- if (config.scale < 0.0) {
- throw new errors_1.ValueError("scale must be a positive float. Got: " + config.scale);
- }
- _this.scale = config.scale == null ? 1.0 : config.scale;
- _this.mode = config.mode;
- checkFanMode(_this.mode);
- _this.distribution = config.distribution;
- checkDistribution(_this.distribution);
- _this.seed = config.seed;
- return _this;
- }
- VarianceScaling.prototype.apply = function (shape, dtype) {
- var fans = computeFans(shape);
- var fanIn = fans[0];
- var fanOut = fans[1];
- var scale = this.scale;
- if (this.mode === 'fanIn') {
- scale /= Math.max(1, fanIn);
- }
- else if (this.mode === 'fanOut') {
- scale /= Math.max(1, fanOut);
- }
- else {
- scale /= Math.max(1, (fanIn + fanOut) / 2);
- }
- if (this.distribution === 'normal') {
- var stddev = Math.sqrt(scale);
- if (dtype === 'bool') {
- throw new errors_1.NotImplementedError(this.getClassName() + " does not support dType bool.");
- }
- return tfjs_core_1.truncatedNormal(shape, 0, stddev, dtype, this.seed);
- }
- else {
- var limit = Math.sqrt(3 * scale);
- return tfjs_core_1.randomUniform(shape, -limit, limit, dtype);
- }
- };
- VarianceScaling.prototype.getConfig = function () {
- return {
- scale: this.scale,
- mode: this.mode,
- distribution: this.distribution,
- seed: this.seed
- };
- };
- VarianceScaling.className = 'VarianceScaling';
- return VarianceScaling;
- }(Initializer));
- exports.VarianceScaling = VarianceScaling;
- tfjs_core_1.serialization.SerializationMap.register(VarianceScaling);
- var GlorotUniform = (function (_super) {
- __extends(GlorotUniform, _super);
- function GlorotUniform(config) {
- return _super.call(this, {
- scale: 1.0,
- mode: 'fanAvg',
- distribution: 'uniform',
- seed: config == null ? null : config.seed
- }) || this;
- }
- GlorotUniform.prototype.getClassName = function () {
- return VarianceScaling.className;
- };
- return GlorotUniform;
- }(VarianceScaling));
- exports.GlorotUniform = GlorotUniform;
- var GlorotNormal = (function (_super) {
- __extends(GlorotNormal, _super);
- function GlorotNormal(config) {
- return _super.call(this, {
- scale: 1.0,
- mode: 'fanAvg',
- distribution: 'normal',
- seed: config == null ? null : config.seed
- }) || this;
- }
- GlorotNormal.prototype.getClassName = function () {
- return VarianceScaling.className;
- };
- return GlorotNormal;
- }(VarianceScaling));
- exports.GlorotNormal = GlorotNormal;
- var HeNormal = (function (_super) {
- __extends(HeNormal, _super);
- function HeNormal(config) {
- return _super.call(this, {
- scale: 2.0,
- mode: 'fanIn',
- distribution: 'normal',
- seed: config == null ? null : config.seed
- }) || this;
- }
- HeNormal.prototype.getClassName = function () {
- return VarianceScaling.className;
- };
- return HeNormal;
- }(VarianceScaling));
- exports.HeNormal = HeNormal;
- var LeCunNormal = (function (_super) {
- __extends(LeCunNormal, _super);
- function LeCunNormal(config) {
- return _super.call(this, {
- scale: 1.0,
- mode: 'fanIn',
- distribution: 'normal',
- seed: config == null ? null : config.seed
- }) || this;
- }
- LeCunNormal.prototype.getClassName = function () {
- return VarianceScaling.className;
- };
- return LeCunNormal;
- }(VarianceScaling));
- exports.LeCunNormal = LeCunNormal;
- var Orthogonal = (function (_super) {
- __extends(Orthogonal, _super);
- function Orthogonal(config) {
- var _this = _super.call(this) || this;
- _this.DEFAULT_GAIN = 1;
- _this.gain = config.gain == null ? _this.DEFAULT_GAIN : config.gain;
- _this.seed = config.seed;
- if (_this.seed != null) {
- throw new errors_1.NotImplementedError('Random seed is not implemented for Orthogonal Initializer yet.');
- }
- return _this;
- }
- Orthogonal.prototype.apply = function (shape, dtype) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- if (shape.length !== 2) {
- throw new errors_1.NotImplementedError('The Orthogonal Initializer does not support non-2D shapes yet.');
- }
- if (shape[0] * shape[1] > 2000) {
- console.warn("Orthogonal initializer is being called on a matrix with more " +
- ("than 2000 (" + shape[0] * shape[1] + ") elements: ") +
- "Slowness may result.");
- }
- var normalizedShape = shape[0] > shape[1] ? [shape[1], shape[0]] : shape;
- var a = K.randomNormal(normalizedShape, 0, 1, 'float32');
- var q = tfjs_core_1.linalg.gramSchmidt(a);
- if (shape[0] > shape[1]) {
- q = q.transpose();
- }
- return K.scalarTimesArray(K.getScalar(_this.gain), q);
- });
- };
- Orthogonal.prototype.getConfig = function () {
- return {
- gain: this.gain,
- seed: this.seed,
- };
- };
- Orthogonal.className = 'Orthogonal';
- return Orthogonal;
- }(Initializer));
- exports.Orthogonal = Orthogonal;
- tfjs_core_1.serialization.SerializationMap.register(Orthogonal);
- exports.INITIALIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP = {
- 'constant': 'Constant',
- 'glorotNormal': 'GlorotNormal',
- 'glorotUniform': 'GlorotUniform',
- 'heNormal': 'HeNormal',
- 'identity': 'Identity',
- 'leCunNormal': 'LeCunNormal',
- 'ones': 'Ones',
- 'orthogonal': 'Orthogonal',
- 'randomNormal': 'RandomNormal',
- 'randomUniform': 'RandomUniform',
- 'truncatedNormal': 'TruncatedNormal',
- 'varianceScaling': 'VarianceScaling',
- 'zeros': 'Zeros'
- };
- function deserializeInitializer(config, customObjects) {
- if (customObjects === void 0) { customObjects = {}; }
- return generic_utils_1.deserializeKerasObject(config, tfjs_core_1.serialization.SerializationMap.getMap().classNameMap, customObjects, 'initializer');
- }
- function serializeInitializer(initializer) {
- return generic_utils_1.serializeKerasObject(initializer);
- }
- exports.serializeInitializer = serializeInitializer;
- function getInitializer(identifier) {
- if (typeof identifier === 'string') {
- var className = identifier in exports.INITIALIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP ?
- exports.INITIALIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP[identifier] :
- identifier;
- if (className === 'GlorotUniform') {
- return new GlorotUniform();
- }
- else if (className === 'GlorotNormal') {
- return new GlorotNormal();
- }
- else if (className === 'HeNormal') {
- return new HeNormal();
- }
- else if (className === 'LeCunNormal') {
- return new LeCunNormal();
- }
- else {
- var config = { className: className, config: {} };
- return deserializeInitializer(config);
- }
- }
- else if (identifier instanceof Initializer) {
- return identifier;
- }
- else {
- return deserializeInitializer(identifier);
- }
- }
- exports.getInitializer = getInitializer;
- },{"./backend/tfjs_backend":169,"./common":171,"./errors":176,"./utils/generic_utils":199,"./utils/math_utils":201,"@tensorflow/tfjs-core":54}],180:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var activations_1 = require("../activations");
- var tfjs_backend_1 = require("../backend/tfjs_backend");
- var tfjs_backend_2 = require("../backend/tfjs_backend");
- var topology_1 = require("../engine/topology");
- var errors_1 = require("../errors");
- var generic_utils = require("../utils/generic_utils");
- var LeakyReLU = (function (_super) {
- __extends(LeakyReLU, _super);
- function LeakyReLU(config) {
- var _this = _super.call(this, config == null ? {} : config) || this;
- _this.DEFAULT_ALPHA = 0.3;
- if (config == null) {
- config = {};
- }
- _this.alpha = config.alpha == null ? _this.DEFAULT_ALPHA : config.alpha;
- return _this;
- }
- LeakyReLU.prototype.call = function (inputs, kwargs) {
- var x = generic_utils.getExactlyOneTensor(inputs);
- return tfjs_core_1.leakyRelu(x, this.alpha);
- };
- LeakyReLU.prototype.computeOutputShape = function (inputShape) {
- return inputShape;
- };
- LeakyReLU.prototype.getConfig = function () {
- var config = { alpha: this.alpha };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- LeakyReLU.className = 'LeakyReLU';
- return LeakyReLU;
- }(topology_1.Layer));
- exports.LeakyReLU = LeakyReLU;
- tfjs_core_1.serialization.SerializationMap.register(LeakyReLU);
- var ELU = (function (_super) {
- __extends(ELU, _super);
- function ELU(config) {
- var _this = _super.call(this, config == null ? {} : config) || this;
- _this.DEFAULT_ALPHA = 1.0;
- if (config == null) {
- config = {};
- }
- if (config.alpha != null && config.alpha !== _this.DEFAULT_ALPHA) {
- throw new errors_1.NotImplementedError("Non-default alpha value (" + config.alpha + ") is not supported by the " +
- "ELU layer yet.");
- }
- _this.alpha = config.alpha == null ? _this.DEFAULT_ALPHA : config.alpha;
- return _this;
- }
- ELU.prototype.call = function (inputs, kwargs) {
- var x = generic_utils.getExactlyOneTensor(inputs);
- return tfjs_core_1.elu(x);
- };
- ELU.prototype.computeOutputShape = function (inputShape) {
- return inputShape;
- };
- ELU.prototype.getConfig = function () {
- var config = { alpha: this.alpha };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- ELU.className = 'ELU';
- return ELU;
- }(topology_1.Layer));
- exports.ELU = ELU;
- tfjs_core_1.serialization.SerializationMap.register(ELU);
- var ThresholdedReLU = (function (_super) {
- __extends(ThresholdedReLU, _super);
- function ThresholdedReLU(config) {
- var _this = _super.call(this, config == null ? {} : config) || this;
- _this.DEFAULT_THETA = 1.0;
- if (config == null) {
- config = {};
- }
- _this.theta = config.theta == null ? _this.DEFAULT_THETA : config.theta;
- _this.thetaTensor = tfjs_backend_2.getScalar(_this.theta);
- return _this;
- }
- ThresholdedReLU.prototype.call = function (inputs, kwargs) {
- var x = generic_utils.getExactlyOneTensor(inputs);
- return x.mul(tfjs_backend_1.cast(x.greater(this.thetaTensor), 'float32'));
- };
- ThresholdedReLU.prototype.computeOutputShape = function (inputShape) {
- return inputShape;
- };
- ThresholdedReLU.prototype.getConfig = function () {
- var config = { theta: this.theta };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- ThresholdedReLU.className = 'ThresholdedReLU';
- return ThresholdedReLU;
- }(topology_1.Layer));
- exports.ThresholdedReLU = ThresholdedReLU;
- tfjs_core_1.serialization.SerializationMap.register(ThresholdedReLU);
- var Softmax = (function (_super) {
- __extends(Softmax, _super);
- function Softmax(config) {
- var _this = _super.call(this, config == null ? {} : config) || this;
- _this.DEFAULT_AXIS = 1.0;
- if (config == null) {
- config = {};
- }
- _this.softmax = new activations_1.Softmax().apply;
- _this.axis = config.axis == null ? _this.DEFAULT_AXIS : config.axis;
- return _this;
- }
- Softmax.prototype.call = function (inputs, kwargs) {
- var x = generic_utils.getExactlyOneTensor(inputs);
- return this.softmax(x, this.axis);
- };
- Softmax.prototype.computeOutputShape = function (inputShape) {
- return inputShape;
- };
- Softmax.prototype.getConfig = function () {
- var config = { axis: this.axis };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- Softmax.className = 'Softmax';
- return Softmax;
- }(topology_1.Layer));
- exports.Softmax = Softmax;
- tfjs_core_1.serialization.SerializationMap.register(Softmax);
- },{"../activations":167,"../backend/tfjs_backend":169,"../engine/topology":174,"../errors":176,"../utils/generic_utils":199,"@tensorflow/tfjs-core":54}],181:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var activations_1 = require("../activations");
- var common_1 = require("../backend/common");
- var K = require("../backend/tfjs_backend");
- var common_2 = require("../common");
- var constraints_1 = require("../constraints");
- var topology_1 = require("../engine/topology");
- var errors_1 = require("../errors");
- var initializers_1 = require("../initializers");
- var regularizers_1 = require("../regularizers");
- var conv_utils_1 = require("../utils/conv_utils");
- var generic_utils = require("../utils/generic_utils");
- function preprocessConv2DInput(x, dataFormat) {
- return tfjs_core_1.tidy(function () {
- common_2.checkDataFormat(dataFormat);
- if (dataFormat === 'channelsFirst') {
- return tfc.transpose(x, [0, 2, 3, 1]);
- }
- else {
- return x;
- }
- });
- }
- exports.preprocessConv2DInput = preprocessConv2DInput;
- function conv1dWithBias(x, kernel, bias, strides, padding, dataFormat, dilationRate) {
- if (strides === void 0) { strides = 1; }
- if (padding === void 0) { padding = 'valid'; }
- if (dilationRate === void 0) { dilationRate = 1; }
- return tfjs_core_1.tidy(function () {
- if (dataFormat == null) {
- dataFormat = common_1.imageDataFormat();
- }
- common_2.checkDataFormat(dataFormat);
- if (x.shape.length !== 3) {
- throw new errors_1.ValueError("The input of a conv1dWithBias operation should be 3, but is " +
- (x.shape.length + " instead."));
- }
- if (kernel.shape.length !== 3) {
- throw new errors_1.ValueError("The kernel for a conv1dWithBias operation should be 3, but is " +
- (kernel.shape.length + " instead"));
- }
- if (bias != null && bias.shape.length !== 1) {
- throw new errors_1.ValueError("The bias for a conv1dWithBias operation should be 1, but is " +
- (kernel.shape.length + " instead"));
- }
- if (dataFormat === 'channelsFirst') {
- x = tfc.transpose(x, [0, 2, 1]);
- }
- if (padding === 'causal') {
- throw new errors_1.NotImplementedError('The support for CAUSAL padding mode in conv1dWithBias is not ' +
- 'implemented yet.');
- }
- var y = tfc.conv1d(x, kernel, strides, padding === 'same' ? 'same' : 'valid', 'NWC', dilationRate);
- if (bias != null) {
- y = K.biasAdd(y, bias);
- }
- return y;
- });
- }
- exports.conv1dWithBias = conv1dWithBias;
- function conv1d(x, kernel, strides, padding, dataFormat, dilationRate) {
- if (strides === void 0) { strides = 1; }
- if (padding === void 0) { padding = 'valid'; }
- if (dilationRate === void 0) { dilationRate = 1; }
- return tfjs_core_1.tidy(function () {
- common_2.checkDataFormat(dataFormat);
- return conv1dWithBias(x, kernel, null, strides, padding, dataFormat, dilationRate);
- });
- }
- exports.conv1d = conv1d;
- function conv2d(x, kernel, strides, padding, dataFormat, dilationRate) {
- if (strides === void 0) { strides = [1, 1]; }
- if (padding === void 0) { padding = 'valid'; }
- return tfjs_core_1.tidy(function () {
- common_2.checkDataFormat(dataFormat);
- return conv2dWithBias(x, kernel, null, strides, padding, dataFormat, dilationRate);
- });
- }
- exports.conv2d = conv2d;
- function conv2dWithBias(x, kernel, bias, strides, padding, dataFormat, dilationRate) {
- if (strides === void 0) { strides = [1, 1]; }
- if (padding === void 0) { padding = 'valid'; }
- return tfjs_core_1.tidy(function () {
- if (dataFormat == null) {
- dataFormat = common_1.imageDataFormat();
- }
- common_2.checkDataFormat(dataFormat);
- if (x.rank !== 3 && x.rank !== 4) {
- throw new errors_1.ValueError("conv2dWithBias expects input to be of rank 3 or 4, but received " +
- (x.rank + "."));
- }
- if (kernel.rank !== 3 && kernel.rank !== 4) {
- throw new errors_1.ValueError("conv2dWithBias expects kernel to be of rank 3 or 4, but received " +
- (x.rank + "."));
- }
- var y = preprocessConv2DInput(x, dataFormat);
- if (padding === 'causal') {
- throw new errors_1.NotImplementedError('The support for CAUSAL padding mode in conv1dWithBias is not ' +
- 'implemented yet.');
- }
- y = tfc.conv2d(y, kernel, strides, padding === 'same' ? 'same' : 'valid', 'NHWC', dilationRate);
- if (bias != null) {
- y = K.biasAdd(y, bias);
- }
- if (dataFormat === 'channelsFirst') {
- y = tfc.transpose(y, [0, 3, 1, 2]);
- }
- return y;
- });
- }
- exports.conv2dWithBias = conv2dWithBias;
- var BaseConv = (function (_super) {
- __extends(BaseConv, _super);
- function BaseConv(rank, config) {
- var _this = _super.call(this, config) || this;
- _this.bias = null;
- _this.DEFAULT_KERNEL_INITIALIZER = 'glorotNormal';
- _this.DEFAULT_BIAS_INITIALIZER = 'zeros';
- BaseConv.verifyConfig(config);
- _this.rank = rank;
- if (_this.rank !== 1 && _this.rank !== 2) {
- throw new errors_1.NotImplementedError("Convolution layer for rank other than 1 or 2 (" + _this.rank + ") is " +
- "not implemented yet.");
- }
- _this.kernelSize = conv_utils_1.normalizeArray(config.kernelSize, rank, 'kernelSize');
- _this.strides = conv_utils_1.normalizeArray(config.strides == null ? 1 : config.strides, rank, 'strides');
- _this.padding = config.padding == null ? 'valid' : config.padding;
- common_2.checkPaddingMode(_this.padding);
- _this.dataFormat =
- config.dataFormat == null ? 'channelsLast' : config.dataFormat;
- common_2.checkDataFormat(_this.dataFormat);
- _this.activation = activations_1.getActivation(config.activation);
- _this.useBias = config.useBias == null ? true : config.useBias;
- _this.biasInitializer =
- initializers_1.getInitializer(config.biasInitializer || _this.DEFAULT_BIAS_INITIALIZER);
- _this.biasConstraint = constraints_1.getConstraint(config.biasConstraint);
- _this.biasRegularizer = regularizers_1.getRegularizer(config.biasRegularizer);
- _this.activityRegularizer = regularizers_1.getRegularizer(config.activityRegularizer);
- _this.dilationRate = config.dilationRate == null ? 1 : config.dilationRate;
- if (_this.rank === 1 &&
- (Array.isArray(_this.dilationRate) &&
- _this.dilationRate.length !== 1)) {
- throw new errors_1.ValueError("dilationRate must be a number or an array of a single number " +
- "for 1D convolution, but received " +
- ("" + JSON.stringify(_this.dilationRate)));
- }
- if (_this.rank === 2) {
- if (typeof _this.dilationRate === 'number') {
- _this.dilationRate = [_this.dilationRate, _this.dilationRate];
- }
- else if (_this.dilationRate.length !== 2) {
- throw new errors_1.ValueError("dilationRate must be a number or array of two numbers for 2D " +
- ("convolution, but received " + JSON.stringify(_this.dilationRate)));
- }
- }
- return _this;
- }
- BaseConv.verifyConfig = function (config) {
- generic_utils.assert('kernelSize' in config, "required key 'kernelSize' not in config");
- if (typeof config.kernelSize !== 'number' &&
- !generic_utils.checkArrayTypeAndLength(config.kernelSize, 'number', 1, 2))
- throw new errors_1.ValueError("BaseConv expects config.kernelSize to be number or number[] with " +
- ("length 1 or 2, but received " + JSON.stringify(config.kernelSize) + "."));
- };
- return BaseConv;
- }(topology_1.Layer));
- exports.BaseConv = BaseConv;
- var Conv = (function (_super) {
- __extends(Conv, _super);
- function Conv(rank, config) {
- var _this = _super.call(this, rank, config) || this;
- _this.kernel = null;
- Conv.verifyConfig(config);
- _this.filters = config.filters;
- _this.kernelInitializer = initializers_1.getInitializer(config.kernelInitializer || _this.DEFAULT_KERNEL_INITIALIZER);
- _this.kernelConstraint = constraints_1.getConstraint(config.kernelConstraint);
- _this.kernelRegularizer = regularizers_1.getRegularizer(config.kernelRegularizer);
- return _this;
- }
- Conv.prototype.build = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- var channelAxis = this.dataFormat === 'channelsFirst' ? 1 : inputShape.length - 1;
- if (inputShape[channelAxis] == null) {
- throw new errors_1.ValueError("The channel dimension of the input should be defined. " +
- ("Found " + inputShape[channelAxis]));
- }
- var inputDim = inputShape[channelAxis];
- var kernelShape = this.kernelSize.concat([inputDim, this.filters]);
- this.kernel = this.addWeight('kernel', kernelShape, null, this.kernelInitializer, this.kernelRegularizer, true, this.kernelConstraint);
- if (this.useBias) {
- this.bias = this.addWeight('bias', [this.filters], null, this.biasInitializer, this.biasRegularizer, true, this.biasConstraint);
- }
- this.inputSpec = [{ ndim: this.rank + 2, axes: (_a = {}, _a[channelAxis] = inputDim, _a) }];
- this.built = true;
- var _a;
- };
- Conv.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- inputs = generic_utils.getExactlyOneTensor(inputs);
- var outputs;
- var biasValue = _this.bias == null ? null : _this.bias.read();
- if (_this.rank === 1) {
- outputs = conv1dWithBias(inputs, _this.kernel.read(), biasValue, _this.strides[0], _this.padding, _this.dataFormat, _this.dilationRate);
- }
- else if (_this.rank === 2) {
- outputs = conv2dWithBias(inputs, _this.kernel.read(), biasValue, _this.strides, _this.padding, _this.dataFormat, _this.dilationRate);
- }
- else if (_this.rank === 3) {
- throw new errors_1.NotImplementedError('3D convolution is not implemented yet.');
- }
- if (_this.activation != null) {
- outputs = _this.activation.apply(outputs);
- }
- return outputs;
- });
- };
- Conv.prototype.computeOutputShape = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- var newSpace = [];
- var space = (this.dataFormat === 'channelsLast') ?
- inputShape.slice(1, inputShape.length - 1) :
- inputShape.slice(2);
- for (var i = 0; i < space.length; ++i) {
- var newDim = conv_utils_1.convOutputLength(space[i], this.kernelSize[i], this.padding, this.strides[i], typeof this.dilationRate === 'number' ? this.dilationRate :
- this.dilationRate[i]);
- newSpace.push(newDim);
- }
- var outputShape = [inputShape[0]];
- if (this.dataFormat === 'channelsLast') {
- outputShape = outputShape.concat(newSpace);
- outputShape.push(this.filters);
- }
- else {
- outputShape.push(this.filters);
- outputShape = outputShape.concat(newSpace);
- }
- return outputShape;
- };
- Conv.prototype.getConfig = function () {
- var config = {
- rank: this.rank,
- filters: this.filters,
- kernelSize: this.kernelSize,
- strides: this.strides,
- padding: this.padding,
- dataFormat: this.dataFormat,
- dilationRate: this.dilationRate,
- activation: activations_1.serializeActivation(this.activation),
- useBias: this.useBias,
- kernelInitializer: initializers_1.serializeInitializer(this.kernelInitializer),
- biasInitializer: initializers_1.serializeInitializer(this.biasInitializer),
- kernelRegularizer: regularizers_1.serializeRegularizer(this.kernelRegularizer),
- biasRegularizer: regularizers_1.serializeRegularizer(this.biasRegularizer),
- activityRegularizer: regularizers_1.serializeRegularizer(this.activityRegularizer),
- kernelConstraint: constraints_1.serializeConstraint(this.kernelConstraint),
- biasConstraint: constraints_1.serializeConstraint(this.biasConstraint)
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- Conv.verifyConfig = function (config) {
- if (!('filters' in config) || typeof config.filters !== 'number' ||
- config.filters < 1) {
- throw new errors_1.ValueError("Convolution layer expected config.filters to be a 'number' > 0 " +
- ("but got " + JSON.stringify(config.filters)));
- }
- };
- return Conv;
- }(BaseConv));
- exports.Conv = Conv;
- var Conv2D = (function (_super) {
- __extends(Conv2D, _super);
- function Conv2D(config) {
- var _this = _super.call(this, 2, config) || this;
- Conv2D.verifyConfig(config);
- return _this;
- }
- Conv2D.prototype.getConfig = function () {
- var config = _super.prototype.getConfig.call(this);
- delete config['rank'];
- return config;
- };
- Conv2D.verifyConfig = function (config) {
- if ((typeof config.kernelSize !== 'number') &&
- !generic_utils.checkArrayTypeAndLength(config.kernelSize, 'number', 1, 2))
- throw new errors_1.ValueError("Conv2D expects config.kernelSize to be number or number[] with " +
- ("length 1 or 2, but received " + JSON.stringify(config.kernelSize) + "."));
- };
- Conv2D.className = 'Conv2D';
- return Conv2D;
- }(Conv));
- exports.Conv2D = Conv2D;
- tfjs_core_1.serialization.SerializationMap.register(Conv2D);
- var Conv2DTranspose = (function (_super) {
- __extends(Conv2DTranspose, _super);
- function Conv2DTranspose(config) {
- var _this = _super.call(this, config) || this;
- _this.inputSpec = [new topology_1.InputSpec({ ndim: 4 })];
- if (_this.padding !== 'same' && _this.padding !== 'valid') {
- throw new errors_1.ValueError("Conv2DTranspose currently supports only padding modes 'same' " +
- ("and 'valid', but received padding mode " + _this.padding));
- }
- return _this;
- }
- Conv2DTranspose.prototype.build = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- if (inputShape.length !== 4) {
- throw new errors_1.ValueError('Input should have rank 4; Received input shape: ' +
- JSON.stringify(inputShape));
- }
- var channelAxis = this.dataFormat === 'channelsFirst' ? 1 : inputShape.length - 1;
- if (inputShape[channelAxis] == null) {
- throw new errors_1.ValueError('The channel dimension of the inputs should be defined. ' +
- 'Found `None`.');
- }
- var inputDim = inputShape[channelAxis];
- var kernelShape = this.kernelSize.concat([this.filters, inputDim]);
- this.kernel = this.addWeight('kernel', kernelShape, 'float32', this.kernelInitializer, this.kernelRegularizer, true, this.kernelConstraint);
- if (this.useBias) {
- this.bias = this.addWeight('bias', [this.filters], 'float32', this.biasInitializer, this.biasRegularizer, true, this.biasConstraint);
- }
- this.inputSpec =
- [new topology_1.InputSpec({ ndim: 4, axes: (_a = {}, _a[channelAxis] = inputDim, _a) })];
- this.built = true;
- var _a;
- };
- Conv2DTranspose.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfc.tidy(function () {
- var input = generic_utils.getExactlyOneTensor(inputs);
- if (input.shape.length !== 4) {
- throw new errors_1.ValueError("Conv2DTranspose.call() expects input tensor to be rank-4, but " +
- ("received a tensor of rank-" + input.shape.length));
- }
- var inputShape = input.shape;
- var batchSize = inputShape[0];
- var hAxis;
- var wAxis;
- if (_this.dataFormat === 'channelsFirst') {
- hAxis = 2;
- wAxis = 3;
- }
- else {
- hAxis = 1;
- wAxis = 2;
- }
- var height = inputShape[hAxis];
- var width = inputShape[wAxis];
- var kernelH = _this.kernelSize[0];
- var kernelW = _this.kernelSize[1];
- var strideH = _this.strides[0];
- var strideW = _this.strides[1];
- var outHeight = conv_utils_1.deconvLength(height, strideH, kernelH, _this.padding);
- var outWidth = conv_utils_1.deconvLength(width, strideW, kernelW, _this.padding);
- var outputShape = [batchSize, outHeight, outWidth, _this.filters];
- if (_this.dataFormat !== 'channelsLast') {
- input = tfc.transpose(input, [0, 2, 3, 1]);
- }
- var outputs = tfc.conv2dTranspose(input, _this.kernel.read(), outputShape, _this.strides, _this.padding);
- if (_this.dataFormat !== 'channelsLast') {
- outputs = tfc.transpose(outputs, [0, 3, 1, 2]);
- }
- if (_this.bias != null) {
- outputs =
- K.biasAdd(outputs, _this.bias.read(), _this.dataFormat);
- }
- if (_this.activation != null) {
- outputs = _this.activation.apply(outputs);
- }
- return outputs;
- });
- };
- Conv2DTranspose.prototype.computeOutputShape = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- var outputShape = inputShape.slice();
- var channelAxis;
- var heightAxis;
- var widthAxis;
- if (this.dataFormat === 'channelsFirst') {
- channelAxis = 1;
- heightAxis = 2;
- widthAxis = 3;
- }
- else {
- channelAxis = 3;
- heightAxis = 1;
- widthAxis = 2;
- }
- var kernelH = this.kernelSize[0];
- var kernelW = this.kernelSize[1];
- var strideH = this.strides[0];
- var strideW = this.strides[1];
- outputShape[channelAxis] = this.filters;
- outputShape[heightAxis] =
- conv_utils_1.deconvLength(outputShape[heightAxis], strideH, kernelH, this.padding);
- outputShape[widthAxis] =
- conv_utils_1.deconvLength(outputShape[widthAxis], strideW, kernelW, this.padding);
- return outputShape;
- };
- Conv2DTranspose.prototype.getConfig = function () {
- var config = _super.prototype.getConfig.call(this);
- delete config['dilationRate'];
- return config;
- };
- Conv2DTranspose.className = 'Conv2DTranspose';
- return Conv2DTranspose;
- }(Conv2D));
- exports.Conv2DTranspose = Conv2DTranspose;
- tfjs_core_1.serialization.SerializationMap.register(Conv2DTranspose);
- var SeparableConv = (function (_super) {
- __extends(SeparableConv, _super);
- function SeparableConv(rank, config) {
- var _this = _super.call(this, rank, config) || this;
- _this.DEFAULT_DEPTHWISE_INITIALIZER = 'glorotUniform';
- _this.DEFAULT_POINTWISE_INITIALIZER = 'glorotUniform';
- _this.depthwiseKernel = null;
- _this.pointwiseKernel = null;
- if (config.filters == null) {
- throw new errors_1.ValueError('The `filters` configuration field is required by SeparableConv, ' +
- 'but is unspecified.');
- }
- if (config.kernelInitializer != null || config.kernelRegularizer != null ||
- config.kernelConstraint != null) {
- throw new errors_1.ValueError('Fields kernelInitializer, kernelRegularizer and kernelConstraint ' +
- 'are invalid for SeparableConv2D. Use depthwiseInitializer, ' +
- 'depthwiseRegularizer, depthwiseConstraint, pointwiseInitializer, ' +
- 'pointwiseRegularizer and pointwiseConstraint instead.');
- }
- if (config.padding != null && config.padding !== 'same' &&
- config.padding !== 'valid') {
- throw new errors_1.ValueError("SeparableConv" + _this.rank + "D supports only padding modes: " +
- ("'same' and 'valid', but received " + JSON.stringify(config.padding)));
- }
- _this.depthMultiplier =
- config.depthMultiplier == null ? 1 : config.depthMultiplier;
- _this.depthwiseInitializer = initializers_1.getInitializer(config.depthwiseInitializer || _this.DEFAULT_DEPTHWISE_INITIALIZER);
- _this.depthwiseRegularizer = regularizers_1.getRegularizer(config.depthwiseRegularizer);
- _this.depthwiseConstraint = constraints_1.getConstraint(config.depthwiseConstraint);
- _this.pointwiseInitializer = initializers_1.getInitializer(config.depthwiseInitializer || _this.DEFAULT_POINTWISE_INITIALIZER);
- _this.pointwiseRegularizer = regularizers_1.getRegularizer(config.pointwiseRegularizer);
- _this.pointwiseConstraint = constraints_1.getConstraint(config.pointwiseConstraint);
- return _this;
- }
- SeparableConv.prototype.build = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- if (inputShape.length < this.rank + 2) {
- throw new errors_1.ValueError("Inputs to SeparableConv" + this.rank + "D should have rank " +
- (this.rank + 2 + ", but received input shape: ") +
- ("" + JSON.stringify(inputShape)));
- }
- var channelAxis = this.dataFormat === 'channelsFirst' ? 1 : inputShape.length - 1;
- if (inputShape[channelAxis] == null || inputShape[channelAxis] < 0) {
- throw new errors_1.ValueError("The channel dimension of the inputs should be defined, " +
- ("but found " + JSON.stringify(inputShape[channelAxis])));
- }
- var inputDim = inputShape[channelAxis];
- var depthwiseKernelShape = this.kernelSize.concat([inputDim, this.depthMultiplier]);
- var pointwiseKernelShape = [];
- for (var i = 0; i < this.rank; ++i) {
- pointwiseKernelShape.push(1);
- }
- pointwiseKernelShape.push(inputDim * this.depthMultiplier, this.filters);
- var trainable = true;
- this.depthwiseKernel = this.addWeight('depthwise_kernel', depthwiseKernelShape, 'float32', this.depthwiseInitializer, this.depthwiseRegularizer, trainable, this.depthwiseConstraint);
- this.pointwiseKernel = this.addWeight('pointwise_kernel', pointwiseKernelShape, 'float32', this.pointwiseInitializer, this.pointwiseRegularizer, trainable, this.pointwiseConstraint);
- if (this.useBias) {
- this.bias = this.addWeight('bias', [this.filters], 'float32', this.biasInitializer, this.biasRegularizer, trainable, this.biasConstraint);
- }
- else {
- this.bias = null;
- }
- this.inputSpec =
- [new topology_1.InputSpec({ ndim: this.rank + 2, axes: (_a = {}, _a[channelAxis] = inputDim, _a) })];
- this.built = true;
- var _a;
- };
- SeparableConv.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- inputs = generic_utils.getExactlyOneTensor(inputs);
- var output;
- if (_this.rank === 1) {
- throw new errors_1.NotImplementedError('1D separable convolution is not implemented yet.');
- }
- else if (_this.rank === 2) {
- if (_this.dataFormat === 'channelsFirst') {
- inputs = tfc.transpose(inputs, [0, 2, 3, 1]);
- }
- output = tfc.separableConv2d(inputs, _this.depthwiseKernel.read(), _this.pointwiseKernel.read(), _this.strides, _this.padding, _this.dilationRate, 'NHWC');
- }
- if (_this.useBias) {
- output = K.biasAdd(output, _this.bias.read(), _this.dataFormat);
- }
- if (_this.activation != null) {
- output = _this.activation.apply(output);
- }
- if (_this.dataFormat === 'channelsFirst') {
- output = tfc.transpose(output, [0, 3, 1, 2]);
- }
- return output;
- });
- };
- SeparableConv.prototype.getConfig = function () {
- var config = _super.prototype.getConfig.call(this);
- delete config['rank'];
- delete config['kernelInitializer'];
- delete config['kernelRegularizer'];
- delete config['kernelConstraint'];
- config['depthwiseInitializer'] =
- initializers_1.serializeInitializer(this.depthwiseInitializer);
- config['pointwiseInitializer'] =
- initializers_1.serializeInitializer(this.pointwiseInitializer);
- config['depthwiseRegularizer'] =
- regularizers_1.serializeRegularizer(this.depthwiseRegularizer);
- config['pointwiseRegularizer'] =
- regularizers_1.serializeRegularizer(this.pointwiseRegularizer);
- config['depthwiseConstraint'] =
- constraints_1.serializeConstraint(this.depthwiseConstraint);
- config['pointwiseConstraint'] =
- constraints_1.serializeConstraint(this.pointwiseConstraint);
- return config;
- };
- SeparableConv.className = 'SeparableConv';
- return SeparableConv;
- }(Conv));
- exports.SeparableConv = SeparableConv;
- var SeparableConv2D = (function (_super) {
- __extends(SeparableConv2D, _super);
- function SeparableConv2D(config) {
- return _super.call(this, 2, config) || this;
- }
- SeparableConv2D.className = 'SeparableConv2D';
- return SeparableConv2D;
- }(SeparableConv));
- exports.SeparableConv2D = SeparableConv2D;
- tfjs_core_1.serialization.SerializationMap.register(SeparableConv2D);
- var Conv1D = (function (_super) {
- __extends(Conv1D, _super);
- function Conv1D(config) {
- var _this = _super.call(this, 1, config) || this;
- Conv1D.verifyConfig(config);
- _this.inputSpec = [{ ndim: 3 }];
- return _this;
- }
- Conv1D.prototype.getConfig = function () {
- var config = _super.prototype.getConfig.call(this);
- delete config['rank'];
- delete config['dataFormat'];
- return config;
- };
- Conv1D.verifyConfig = function (config) {
- if (typeof config.kernelSize !== 'number' &&
- !generic_utils.checkArrayTypeAndLength(config.kernelSize, 'number', 1, 1))
- throw new errors_1.ValueError("Conv1D expects config.kernelSize to be number or number[] with " +
- ("length 1, but received " + JSON.stringify(config.kernelSize) + "."));
- };
- Conv1D.className = 'Conv1D';
- return Conv1D;
- }(Conv));
- exports.Conv1D = Conv1D;
- tfjs_core_1.serialization.SerializationMap.register(Conv1D);
- var Cropping2D = (function (_super) {
- __extends(Cropping2D, _super);
- function Cropping2D(config) {
- var _this = _super.call(this, config) || this;
- if (typeof config.cropping === 'number')
- _this.cropping = [
- [config.cropping, config.cropping], [config.cropping, config.cropping]
- ];
- else if (typeof config.cropping[0] === 'number')
- _this.cropping = [
- [config.cropping[0], config.cropping[0]],
- [config.cropping[1], config.cropping[1]]
- ];
- else
- _this.cropping = config.cropping;
- _this.dataFormat =
- config.dataFormat === undefined ? 'channelsLast' : config.dataFormat;
- _this.inputSpec = [{ ndim: 4 }];
- return _this;
- }
- Cropping2D.prototype.computeOutputShape = function (inputShape) {
- if (this.dataFormat === 'channelsFirst')
- return [
- inputShape[0], inputShape[1],
- inputShape[2] - this.cropping[0][0] - this.cropping[0][1],
- inputShape[2] - this.cropping[1][0] - this.cropping[1][1]
- ];
- else
- return [
- inputShape[0],
- inputShape[1] - this.cropping[0][0] - this.cropping[0][1],
- inputShape[2] - this.cropping[1][0] - this.cropping[1][1], inputShape[3]
- ];
- };
- Cropping2D.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- inputs = generic_utils.getExactlyOneTensor(inputs);
- if (_this.dataFormat === 'channelsLast') {
- var hSliced = K.sliceAlongAxis(inputs, _this.cropping[0][0], inputs.shape[1] - _this.cropping[0][0] - _this.cropping[0][1], 2);
- return K.sliceAlongAxis(hSliced, _this.cropping[1][0], inputs.shape[2] - _this.cropping[1][1] - _this.cropping[1][0], 3);
- }
- else {
- var hSliced = K.sliceAlongAxis(inputs, _this.cropping[0][0], inputs.shape[2] - _this.cropping[0][0] - _this.cropping[0][1], 3);
- return K.sliceAlongAxis(hSliced, _this.cropping[1][0], inputs.shape[3] - _this.cropping[1][1] - _this.cropping[1][0], 4);
- }
- });
- };
- Cropping2D.prototype.getConfig = function () {
- var config = { cropping: this.cropping, dataFormat: this.dataFormat };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- Cropping2D.className = 'Cropping2D';
- return Cropping2D;
- }(topology_1.Layer));
- exports.Cropping2D = Cropping2D;
- tfjs_core_1.serialization.SerializationMap.register(Cropping2D);
- var UpSampling2D = (function (_super) {
- __extends(UpSampling2D, _super);
- function UpSampling2D(config) {
- var _this = _super.call(this, config) || this;
- _this.DEFAULT_SIZE = [2, 2];
- _this.inputSpec = [{ ndim: 4 }];
- _this.size = config.size === undefined ? _this.DEFAULT_SIZE : config.size;
- _this.dataFormat =
- config.dataFormat === undefined ? 'channelsLast' : config.dataFormat;
- return _this;
- }
- UpSampling2D.prototype.computeOutputShape = function (inputShape) {
- if (this.dataFormat === 'channelsFirst') {
- var height = this.size[0] * inputShape[2];
- var width = this.size[1] * inputShape[3];
- return [inputShape[0], inputShape[1], height, width];
- }
- else {
- var height = this.size[0] * inputShape[1];
- var width = this.size[1] * inputShape[2];
- return [inputShape[0], height, width, inputShape[3]];
- }
- };
- UpSampling2D.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfc.tidy(function () {
- var input = generic_utils.getExactlyOneTensor(inputs);
- var inputShape = input.shape;
- if (_this.dataFormat === 'channelsFirst') {
- input = tfc.transpose(input, [0, 2, 3, 1]);
- var height = _this.size[0] * inputShape[2];
- var width = _this.size[1] * inputShape[3];
- var resized = input.resizeNearestNeighbor([height, width]);
- return tfc.transpose(resized, [0, 3, 1, 2]);
- }
- else {
- var height = _this.size[0] * inputShape[1];
- var width = _this.size[1] * inputShape[2];
- return input.resizeNearestNeighbor([height, width]);
- }
- });
- };
- UpSampling2D.prototype.getConfig = function () {
- var config = { size: this.size, dataFormat: this.dataFormat };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- UpSampling2D.className = 'UpSampling2D';
- return UpSampling2D;
- }(topology_1.Layer));
- exports.UpSampling2D = UpSampling2D;
- tfjs_core_1.serialization.SerializationMap.register(UpSampling2D);
- },{"../activations":167,"../backend/common":168,"../backend/tfjs_backend":169,"../common":171,"../constraints":172,"../engine/topology":174,"../errors":176,"../initializers":179,"../regularizers":196,"../utils/conv_utils":198,"../utils/generic_utils":199,"@tensorflow/tfjs-core":54}],182:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var common_1 = require("../backend/common");
- var K = require("../backend/tfjs_backend");
- var common_2 = require("../common");
- var constraints_1 = require("../constraints");
- var errors_1 = require("../errors");
- var initializers_1 = require("../initializers");
- var regularizers_1 = require("../regularizers");
- var conv_utils_1 = require("../utils/conv_utils");
- var generic_utils_1 = require("../utils/generic_utils");
- var convolutional_1 = require("./convolutional");
- function depthwiseConv2d(x, depthwiseKernel, strides, padding, dataFormat, dilationRate) {
- if (strides === void 0) { strides = [1, 1]; }
- if (padding === void 0) { padding = 'valid'; }
- return tfjs_core_1.tidy(function () {
- if (dataFormat == null) {
- dataFormat = common_1.imageDataFormat();
- }
- common_2.checkDataFormat(dataFormat);
- var y = convolutional_1.preprocessConv2DInput(x, dataFormat);
- if (x.rank !== 4) {
- throw new errors_1.ValueError("Input for depthwiseConv2d is required to be 4-D, but is instead " +
- (x.rank + "-D"));
- }
- if (depthwiseKernel.rank !== 4) {
- throw new errors_1.ValueError("depthwiseKernel is required to be 4-D, but is instead " +
- (depthwiseKernel.rank + "-D"));
- }
- y = tfc.depthwiseConv2d(y, depthwiseKernel, strides, padding === 'same' ? 'same' : 'valid', 'NHWC', dilationRate);
- if (dataFormat === 'channelsFirst') {
- y = tfc.transpose(y, [0, 3, 1, 2]);
- }
- return y;
- });
- }
- exports.depthwiseConv2d = depthwiseConv2d;
- var DepthwiseConv2D = (function (_super) {
- __extends(DepthwiseConv2D, _super);
- function DepthwiseConv2D(config) {
- var _this = _super.call(this, 2, config) || this;
- _this.depthwiseKernel = null;
- _this.depthMultiplier =
- config.depthMultiplier == null ? 1 : config.depthMultiplier;
- _this.depthwiseInitializer = initializers_1.getInitializer(config.depthwiseInitializer || _this.DEFAULT_KERNEL_INITIALIZER);
- _this.depthwiseConstraint = constraints_1.getConstraint(config.depthwiseConstraint);
- _this.depthwiseRegularizer = regularizers_1.getRegularizer(config.depthwiseRegularizer);
- return _this;
- }
- DepthwiseConv2D.prototype.build = function (inputShape) {
- inputShape = generic_utils_1.getExactlyOneShape(inputShape);
- if (inputShape.length < 4) {
- throw new errors_1.ValueError("Inputs to DepthwiseConv2D should have rank 4. " +
- ("Received input shape: " + JSON.stringify(inputShape) + "."));
- }
- var channelAxis = this.dataFormat === 'channelsFirst' ? 1 : 3;
- if (inputShape[channelAxis] == null || inputShape[channelAxis] < 0) {
- throw new errors_1.ValueError('The channel dimension of the inputs to DepthwiseConv2D should ' +
- ("be defined, but is not (" + inputShape[channelAxis] + ")."));
- }
- var inputDim = inputShape[channelAxis];
- var depthwiseKernelShape = [
- this.kernelSize[0], this.kernelSize[1], inputDim, this.depthMultiplier
- ];
- this.depthwiseKernel = this.addWeight('depthwise_kernel', depthwiseKernelShape, null, this.depthwiseInitializer, this.depthwiseRegularizer, true, this.depthwiseConstraint);
- if (this.useBias) {
- this.bias = this.addWeight('bias', [inputDim * this.depthMultiplier], null, this.biasInitializer, this.biasRegularizer, true, this.biasConstraint);
- }
- else {
- this.bias = null;
- }
- this.built = true;
- };
- DepthwiseConv2D.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- inputs = generic_utils_1.getExactlyOneTensor(inputs);
- var outputs = depthwiseConv2d(inputs, _this.depthwiseKernel.read(), _this.strides, _this.padding, _this.dataFormat, null);
- if (_this.useBias) {
- outputs = K.biasAdd(outputs, _this.bias.read(), _this.dataFormat);
- }
- if (_this.activation != null) {
- outputs = _this.activation.apply(outputs);
- }
- return outputs;
- });
- };
- DepthwiseConv2D.prototype.computeOutputShape = function (inputShape) {
- inputShape = generic_utils_1.getExactlyOneShape(inputShape);
- var rows = this.dataFormat === 'channelsFirst' ? inputShape[2] : inputShape[1];
- var cols = this.dataFormat === 'channelsFirst' ? inputShape[3] : inputShape[2];
- var outFilters = this.dataFormat === 'channelsFirst' ?
- inputShape[1] * this.depthMultiplier :
- inputShape[3] * this.depthMultiplier;
- var outRows = conv_utils_1.convOutputLength(rows, this.kernelSize[0], this.padding, this.strides[0]);
- var outCols = conv_utils_1.convOutputLength(cols, this.kernelSize[1], this.padding, this.strides[1]);
- if (this.dataFormat === 'channelsFirst') {
- return [inputShape[0], outFilters, outRows, outCols];
- }
- else {
- return [inputShape[0], outRows, outCols, outFilters];
- }
- };
- DepthwiseConv2D.className = 'DepthwiseConv2D';
- return DepthwiseConv2D;
- }(convolutional_1.BaseConv));
- exports.DepthwiseConv2D = DepthwiseConv2D;
- tfjs_core_1.serialization.SerializationMap.register(DepthwiseConv2D);
- },{"../backend/common":168,"../backend/tfjs_backend":169,"../common":171,"../constraints":172,"../errors":176,"../initializers":179,"../regularizers":196,"../utils/conv_utils":198,"../utils/generic_utils":199,"./convolutional":181,"@tensorflow/tfjs-core":54}],183:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var activations_1 = require("../activations");
- var K = require("../backend/tfjs_backend");
- var constraints_1 = require("../constraints");
- var topology_1 = require("../engine/topology");
- var errors_1 = require("../errors");
- var initializers_1 = require("../initializers");
- var regularizers_1 = require("../regularizers");
- var generic_utils = require("../utils/generic_utils");
- var generic_utils_1 = require("../utils/generic_utils");
- var math_utils = require("../utils/math_utils");
- var Dropout = (function (_super) {
- __extends(Dropout, _super);
- function Dropout(config) {
- var _this = _super.call(this, config) || this;
- _this.rate = Math.max(Math.min(config.rate, 1), 0);
- _this.rateScalar = K.getScalar(_this.rate);
- _this.noiseShape = config.noiseShape;
- _this.seed = config.seed;
- if (_this.seed != null) {
- throw new errors_1.NotImplementedError('Non-default seed is not implemented in Dropout layer yet: ' +
- _this.seed);
- }
- _this.supportsMasking = true;
- return _this;
- }
- Dropout.prototype.getNoiseShape = function (input) {
- if (this.noiseShape == null) {
- return this.noiseShape;
- }
- var inputShape = input.shape;
- var noiseShape = [];
- for (var i = 0; i < this.noiseShape.length; ++i) {
- noiseShape.push(this.noiseShape[i] == null ? inputShape[i] : this.noiseShape[i]);
- }
- return noiseShape;
- };
- Dropout.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- _this.invokeCallHook(inputs, kwargs);
- var input = generic_utils.getExactlyOneTensor(inputs);
- if (_this.noiseShape != null &&
- !tfjs_core_1.util.arraysEqual(input.shape, _this.noiseShape)) {
- throw new errors_1.NotImplementedError('Non-default noise shape is not implemented in Dropout ' +
- 'layer yet: ' + JSON.stringify(_this.noiseShape));
- }
- if (0 < _this.rate && _this.rate < 1) {
- var training = kwargs['training'] == null ? false : kwargs['training'];
- var noiseShape_1 = _this.getNoiseShape(input);
- var output = K.inTrainPhase(function () { return K.dropout(input, _this.rateScalar, noiseShape_1, _this.seed); }, function () { return input; }, training);
- return output;
- }
- return inputs;
- });
- };
- Dropout.prototype.getConfig = function () {
- var config = {
- rate: this.rate,
- noiseShape: this.noiseShape,
- seed: this.seed,
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- Dropout.className = 'Dropout';
- return Dropout;
- }(topology_1.Layer));
- exports.Dropout = Dropout;
- tfjs_core_1.serialization.SerializationMap.register(Dropout);
- var Dense = (function (_super) {
- __extends(Dense, _super);
- function Dense(config) {
- var _this = _super.call(this, config) || this;
- _this.activation = null;
- _this.useBias = true;
- _this.kernel = null;
- _this.bias = null;
- _this.DEFAULT_KERNEL_INITIALIZER = 'glorotNormal';
- _this.DEFAULT_BIAS_INITIALIZER = 'zeros';
- if (config.batchInputShape == null && config.inputShape == null &&
- config.inputDim != null) {
- var batchSize = null;
- if (config.batchSize != null) {
- batchSize = config.batchSize;
- }
- _this.batchInputShape = [batchSize, config.inputDim];
- }
- _this.units = config.units;
- _this.activation = activations_1.getActivation(config.activation);
- if (config.useBias != null) {
- _this.useBias = config.useBias;
- }
- _this.kernelInitializer = initializers_1.getInitializer(config.kernelInitializer || _this.DEFAULT_KERNEL_INITIALIZER);
- _this.biasInitializer =
- initializers_1.getInitializer(config.biasInitializer || _this.DEFAULT_BIAS_INITIALIZER);
- _this.kernelConstraint = constraints_1.getConstraint(config.kernelConstraint);
- _this.biasConstraint = constraints_1.getConstraint(config.biasConstraint);
- _this.kernelRegularizer = regularizers_1.getRegularizer(config.kernelRegularizer);
- _this.biasRegularizer = regularizers_1.getRegularizer(config.biasRegularizer);
- _this.activityRegularizer = regularizers_1.getRegularizer(config.activityRegularizer);
- _this.inputSpec = [{ minNDim: 2 }];
- return _this;
- }
- Dense.prototype.build = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- var inputLastDim = inputShape[inputShape.length - 1];
- if (this.kernel == null) {
- this.kernel = this.addWeight('kernel', [inputLastDim, this.units], null, this.kernelInitializer, this.kernelRegularizer, true, this.kernelConstraint);
- if (this.useBias) {
- this.bias = this.addWeight('bias', [this.units], null, this.biasInitializer, this.biasRegularizer, true, this.biasConstraint);
- }
- }
- this.inputSpec = [{ minNDim: 2, axes: (_a = {}, _a[-1] = inputLastDim, _a) }];
- this.built = true;
- var _a;
- };
- Dense.prototype.computeOutputShape = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- var outputShape = inputShape.slice();
- outputShape[outputShape.length - 1] = this.units;
- return outputShape;
- };
- Dense.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- _this.invokeCallHook(inputs, kwargs);
- var input = generic_utils.getExactlyOneTensor(inputs);
- var output = K.dot(input, _this.kernel.read());
- if (_this.bias != null) {
- output = K.biasAdd(output, _this.bias.read());
- }
- if (_this.activation != null) {
- output = _this.activation.apply(output);
- }
- return output;
- });
- };
- Dense.prototype.getConfig = function () {
- var config = {
- units: this.units,
- activation: activations_1.serializeActivation(this.activation),
- useBias: this.useBias,
- kernelInitializer: initializers_1.serializeInitializer(this.kernelInitializer),
- biasInitializer: initializers_1.serializeInitializer(this.biasInitializer),
- kernelRegularizer: regularizers_1.serializeRegularizer(this.kernelRegularizer),
- biasRegularizer: regularizers_1.serializeRegularizer(this.biasRegularizer),
- activityRegularizer: regularizers_1.serializeRegularizer(this.activityRegularizer),
- kernelConstraint: constraints_1.serializeConstraint(this.kernelConstraint),
- biasConstraint: constraints_1.serializeConstraint(this.biasConstraint)
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- Dense.className = 'Dense';
- return Dense;
- }(topology_1.Layer));
- exports.Dense = Dense;
- tfjs_core_1.serialization.SerializationMap.register(Dense);
- var Flatten = (function (_super) {
- __extends(Flatten, _super);
- function Flatten(config) {
- var _this = _super.call(this, config || {}) || this;
- _this.inputSpec = [{ minNDim: 3 }];
- return _this;
- }
- Flatten.prototype.computeOutputShape = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- for (var _i = 0, _a = inputShape.slice(1); _i < _a.length; _i++) {
- var dim = _a[_i];
- if (dim == null) {
- throw new errors_1.ValueError("The shape of the input to \"Flatten\" is not fully defined " +
- ("(got " + inputShape.slice(1) + "). Make sure to pass a complete ") +
- "\"input_shape\" or \"batch_input_shape\" argument to the first " +
- "layer in your model.");
- }
- }
- return [inputShape[0], math_utils.arrayProd(inputShape, 1)];
- };
- Flatten.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- _this.invokeCallHook(inputs, kwargs);
- return K.batchFlatten(generic_utils.getExactlyOneTensor(inputs));
- });
- };
- Flatten.className = 'Flatten';
- return Flatten;
- }(topology_1.Layer));
- exports.Flatten = Flatten;
- tfjs_core_1.serialization.SerializationMap.register(Flatten);
- var Activation = (function (_super) {
- __extends(Activation, _super);
- function Activation(config) {
- var _this = _super.call(this, config) || this;
- _this.supportsMasking = true;
- _this.activation = activations_1.getActivation(config.activation);
- return _this;
- }
- Activation.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- _this.invokeCallHook(inputs, kwargs);
- var input = generic_utils.getExactlyOneTensor(inputs);
- return _this.activation.apply(input);
- });
- };
- Activation.prototype.getConfig = function () {
- var config = { activation: activations_1.serializeActivation(this.activation) };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- Activation.className = 'Activation';
- return Activation;
- }(topology_1.Layer));
- exports.Activation = Activation;
- tfjs_core_1.serialization.SerializationMap.register(Activation);
- var RepeatVector = (function (_super) {
- __extends(RepeatVector, _super);
- function RepeatVector(config) {
- var _this = _super.call(this, config) || this;
- _this.n = config.n;
- _this.inputSpec = [{ ndim: 2 }];
- return _this;
- }
- RepeatVector.prototype.computeOutputShape = function (inputShape) {
- return [inputShape[0], this.n, inputShape[1]];
- };
- RepeatVector.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- inputs = generic_utils_1.getExactlyOneTensor(inputs);
- return K.repeat(inputs, _this.n);
- });
- };
- RepeatVector.prototype.getConfig = function () {
- var config = {
- n: this.n,
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- RepeatVector.className = 'RepeatVector';
- return RepeatVector;
- }(topology_1.Layer));
- exports.RepeatVector = RepeatVector;
- tfjs_core_1.serialization.SerializationMap.register(RepeatVector);
- var Reshape = (function (_super) {
- __extends(Reshape, _super);
- function Reshape(config) {
- var _this = _super.call(this, config) || this;
- _this.targetShape = config.targetShape;
- for (var i = 0; i < _this.targetShape.length; ++i) {
- if (_this.isUnknown(_this.targetShape[i])) {
- _this.targetShape[i] = null;
- }
- }
- return _this;
- }
- Reshape.prototype.isUnknown = function (dim) {
- return dim < 0 || dim == null;
- };
- Reshape.prototype.fixUnknownDimension = function (inputShape, outputShape) {
- var errorMsg = 'Total size of new array must be unchanged.';
- var finalShape = outputShape.slice();
- var known = 1;
- var unknown = null;
- for (var i = 0; i < finalShape.length; ++i) {
- var dim = finalShape[i];
- if (this.isUnknown(dim)) {
- if (unknown === null) {
- unknown = i;
- }
- else {
- throw new errors_1.ValueError('Can only specifiy one unknown dimension.');
- }
- }
- else {
- known *= dim;
- }
- }
- var originalSize = math_utils.arrayProd(inputShape);
- if (unknown !== null) {
- if (known === 0 || originalSize % known !== 0) {
- throw new errors_1.ValueError(errorMsg);
- }
- finalShape[unknown] = originalSize / known;
- }
- else if (originalSize !== known) {
- throw new errors_1.ValueError(errorMsg);
- }
- return finalShape;
- };
- Reshape.prototype.computeOutputShape = function (inputShape) {
- var anyUnknownDims = false;
- for (var i = 0; i < inputShape.length; ++i) {
- if (this.isUnknown(inputShape[i])) {
- anyUnknownDims = true;
- break;
- }
- }
- if (anyUnknownDims) {
- return inputShape.slice(0, 1).concat(this.targetShape);
- }
- else {
- return inputShape.slice(0, 1).concat(this.fixUnknownDimension(inputShape.slice(1), this.targetShape));
- }
- };
- Reshape.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- _this.invokeCallHook(inputs, kwargs);
- var input = generic_utils.getExactlyOneTensor(inputs);
- var inputShape = K.shape(input);
- var outputShape = inputShape.slice(0, 1).concat(_this.fixUnknownDimension(inputShape.slice(1), _this.targetShape));
- return input.reshape(outputShape);
- });
- };
- Reshape.prototype.getConfig = function () {
- var config = {
- targetShape: this.targetShape,
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- Reshape.className = 'Reshape';
- return Reshape;
- }(topology_1.Layer));
- exports.Reshape = Reshape;
- tfjs_core_1.serialization.SerializationMap.register(Reshape);
- },{"../activations":167,"../backend/tfjs_backend":169,"../constraints":172,"../engine/topology":174,"../errors":176,"../initializers":179,"../regularizers":196,"../utils/generic_utils":199,"../utils/math_utils":201,"@tensorflow/tfjs-core":54}],184:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("../backend/tfjs_backend");
- var constraints_1 = require("../constraints");
- var topology_1 = require("../engine/topology");
- var errors_1 = require("../errors");
- var initializers_1 = require("../initializers");
- var regularizers_1 = require("../regularizers");
- var generic_utils = require("../utils/generic_utils");
- var generic_utils_1 = require("../utils/generic_utils");
- var Embedding = (function (_super) {
- __extends(Embedding, _super);
- function Embedding(config) {
- var _this = _super.call(this, config) || this;
- _this.embeddings = null;
- _this.DEFAULT_EMBEDDINGS_INITIALIZER = 'randomUniform';
- if (config.batchInputShape == null && config.inputShape == null) {
- var batchSize = null;
- if (config.batchSize != null) {
- batchSize = config.batchSize;
- }
- if (config.inputLength == null) {
- _this.batchInputShape = [batchSize, null];
- }
- else {
- _this.batchInputShape =
- [batchSize].concat(generic_utils.toList(config.inputLength));
- }
- }
- _this.inputDim = config.inputDim;
- _this.outputDim = config.outputDim;
- _this.embeddingsInitializer = initializers_1.getInitializer(config.embeddingsInitializer || _this.DEFAULT_EMBEDDINGS_INITIALIZER);
- _this.embeddingsRegularizer = regularizers_1.getRegularizer(config.embeddingsRegularizer);
- _this.activityRegularizer = regularizers_1.getRegularizer(config.activityRegularizer);
- _this.embeddingsConstraint = constraints_1.getConstraint(config.embeddingsConstraint);
- _this.maskZero = config.maskZero;
- _this.inputLength = config.inputLength;
- return _this;
- }
- Embedding.prototype.build = function (inputShape) {
- this.embeddings = this.addWeight('embeddings', [this.inputDim, this.outputDim], this.dtype, this.embeddingsInitializer, this.embeddingsRegularizer, true, this.embeddingsConstraint);
- this.built = true;
- };
- Embedding.prototype.computeMask = function (inputs, mask) {
- throw new errors_1.NotImplementedError('computeMask has not been implemented for Embedding yet');
- };
- Embedding.prototype.computeOutputShape = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- if (this.inputLength == null) {
- return inputShape.concat([this.outputDim]);
- }
- var inLens = generic_utils.toList(this.inputLength);
- if (inLens.length !== inputShape.length - 1) {
- throw new errors_1.ValueError("\"inputLength\" is " + this.inputLength + ", but received " +
- ("input shape has shape " + inputShape));
- }
- else {
- var i = 0;
- for (var k = 0; k < inLens.length; ++k) {
- var s1 = inLens[k];
- var s2 = inputShape[k + 1];
- if ((s1 != null) && (s2 != null) && (s1 !== s2)) {
- throw new errors_1.ValueError("\"inputLength\" is " + this.inputLength + ", but received " +
- ("input shape has shape " + inputShape));
- }
- else if (s1 == null) {
- inLens[i] = s2;
- }
- i++;
- }
- }
- return [inputShape[0]].concat(inLens, [this.outputDim]);
- };
- Embedding.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- _this.invokeCallHook(inputs, kwargs);
- var input = generic_utils.getExactlyOneTensor(inputs);
- if (K.dtype(input) !== 'int32') {
- input = K.cast(input, 'int32');
- }
- var output = K.gather(_this.embeddings.read(), input.as1D());
- return output.reshape(generic_utils_1.getExactlyOneShape(_this.computeOutputShape(input.shape)));
- });
- };
- Embedding.prototype.getConfig = function () {
- var config = {
- inputDim: this.inputDim,
- outputDim: this.outputDim,
- embeddingsInitializer: initializers_1.serializeInitializer(this.embeddingsInitializer),
- embeddingsRegularizer: regularizers_1.serializeRegularizer(this.embeddingsRegularizer),
- activityRegularizer: regularizers_1.serializeRegularizer(this.activityRegularizer),
- embeddingsConstraint: constraints_1.serializeConstraint(this.embeddingsConstraint),
- maskZero: this.maskZero,
- inputLength: this.inputLength
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- Embedding.className = 'Embedding';
- return Embedding;
- }(topology_1.Layer));
- exports.Embedding = Embedding;
- tfjs_core_1.serialization.SerializationMap.register(Embedding);
- },{"../backend/tfjs_backend":169,"../constraints":172,"../engine/topology":174,"../errors":176,"../initializers":179,"../regularizers":196,"../utils/generic_utils":199,"@tensorflow/tfjs-core":54}],185:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("../backend/tfjs_backend");
- var topology_1 = require("../engine/topology");
- var errors_1 = require("../errors");
- var generic_utils = require("../utils/generic_utils");
- var mathUtils = require("../utils/math_utils");
- var Merge = (function (_super) {
- __extends(Merge, _super);
- function Merge(config) {
- var _this = _super.call(this, config || {}) || this;
- _this.supportsMasking = true;
- return _this;
- }
- Merge.prototype.mergeFunction = function (inputs) {
- throw new errors_1.NotImplementedError();
- };
- Merge.prototype.computeElementwiseOpOutputShape = function (shape1, shape2) {
- if (shape1 == null || shape2 == null) {
- return null;
- }
- else if (shape1.length < shape2.length) {
- return this.computeElementwiseOpOutputShape(shape2, shape1);
- }
- else if (shape2.length === 0) {
- return shape1;
- }
- var outputShape = shape1.slice(0, shape1.length - shape2.length);
- for (var k = 0; k < shape2.length; ++k) {
- var i = shape1[shape1.length - shape2.length + k];
- var j = shape2[k];
- if (i == null || j == null || i < 0 || j < 0) {
- outputShape.push(null);
- }
- else if (i === 1) {
- outputShape.push(j);
- }
- else if (j === 1) {
- outputShape.push(i);
- }
- else {
- if (i !== j) {
- throw new errors_1.ValueError('Operands could not be broadcast together with shapes ' +
- JSON.stringify(shape1) + ' ' + JSON.stringify(shape2));
- }
- outputShape.push(i);
- }
- }
- return outputShape;
- };
- Merge.prototype.build = function (inputShape) {
- if (Array.isArray(inputShape) && !Array.isArray(inputShape[0])) {
- inputShape = [generic_utils.getExactlyOneShape(inputShape)];
- }
- inputShape = inputShape;
- if (inputShape.length < 2) {
- throw new errors_1.ValueError('A merge layer should be called on an Array of at least 2 inputs.' +
- (" Got " + inputShape.length + " input(s)."));
- }
- var batchSizes = [];
- for (var _i = 0, inputShape_1 = inputShape; _i < inputShape_1.length; _i++) {
- var shape = inputShape_1[_i];
- if (shape != null && shape[0] !== null) {
- batchSizes.push(shape[0]);
- }
- }
- batchSizes = generic_utils.unique(batchSizes);
- if (batchSizes.length > 1) {
- throw new errors_1.ValueError("Can not merge tensors with different batch sizes. " +
- ("Got tensors with shapes: " + JSON.stringify(inputShape) + "."));
- }
- var outputShape = inputShape[0] == null ? null : inputShape[0].slice(1);
- for (var i = 1; i < inputShape.length; ++i) {
- var shape = inputShape[i] == null ? null : inputShape[i].slice(1);
- outputShape = this.computeElementwiseOpOutputShape(outputShape, shape);
- }
- var allRanks = inputShape.map(function (shape) { return shape.length; });
- if (inputShape.indexOf(null) === -1 &&
- generic_utils.unique(allRanks).length === 1) {
- this.reshapeRequired = false;
- }
- else {
- this.reshapeRequired = true;
- }
- };
- Merge.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- inputs = inputs;
- if (_this.reshapeRequired) {
- var reshapedInputs = [];
- var inputDims = inputs.map(function (input) { return input.rank; });
- if (inputDims.indexOf(null) === -1) {
- var maxNDim = mathUtils.max(inputDims);
- for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {
- var x = inputs_1[_i];
- var xNDim = x.rank;
- for (var k = 0; k < maxNDim - xNDim; ++k) {
- x = K.expandDims(x, 1);
- }
- reshapedInputs.push(x);
- }
- return _this.mergeFunction(reshapedInputs);
- }
- else {
- var transposed = false;
- for (var _a = 0, inputs_2 = inputs; _a < inputs_2.length; _a++) {
- var x = inputs_2[_a];
- var xNDim = x.rank;
- if (xNDim == null) {
- var xShape = K.shape(x);
- var batchSize = xShape[0];
- var newShape = xShape.slice(1).concat([batchSize]);
- var xTransposed = x.reshape([batchSize].concat(mathUtils.arrayProd(xShape.slice(1))));
- xTransposed = tfc.transpose(xTransposed, [1, 0]);
- xTransposed = xTransposed.reshape(newShape);
- reshapedInputs.push(xTransposed);
- transposed = true;
- }
- else if (xNDim > 1) {
- var dims = mathUtils.range(1, xNDim).concat([0]);
- reshapedInputs.push(tfc.transpose(x, dims));
- transposed = true;
- }
- else {
- reshapedInputs.push(x);
- }
- }
- var y = _this.mergeFunction(reshapedInputs);
- var yNDim = y.rank;
- if (transposed) {
- if (yNDim == null) {
- var yShape = K.shape(y);
- var yNDim_1 = yShape.length;
- var batchSize = yShape[yNDim_1 - 1];
- var newShape = [batchSize].concat(yShape.slice(0, yShape.length - 1));
- y = tfc.transpose(y.reshape([-1, batchSize]), [1, 0])
- .reshape(newShape);
- }
- else if (yNDim > 1) {
- var dims = [yNDim - 1].concat(mathUtils.range(0, yNDim - 1));
- y = tfc.transpose(y, dims);
- }
- }
- return y;
- }
- }
- else {
- return _this.mergeFunction(inputs);
- }
- });
- };
- Merge.prototype.computeOutputShape = function (inputShape) {
- inputShape = inputShape;
- var outputShape;
- if (inputShape[0] == null) {
- outputShape = null;
- }
- else {
- outputShape = inputShape[0].slice(1);
- }
- for (var i = 1; i < inputShape.length; ++i) {
- var shape = inputShape[i] == null ? null : inputShape[i].slice(1);
- outputShape = this.computeElementwiseOpOutputShape(outputShape, shape);
- }
- var batchSizes = [];
- for (var _i = 0, inputShape_2 = inputShape; _i < inputShape_2.length; _i++) {
- var shape = inputShape_2[_i];
- if (shape != null && shape[0] !== null) {
- batchSizes.push(shape[0]);
- }
- }
- batchSizes = generic_utils.unique(batchSizes);
- if (batchSizes.length === 1) {
- outputShape = batchSizes.concat(outputShape);
- }
- else {
- outputShape = [null].concat(outputShape);
- }
- return outputShape;
- };
- return Merge;
- }(topology_1.Layer));
- exports.Merge = Merge;
- var Add = (function (_super) {
- __extends(Add, _super);
- function Add(config) {
- return _super.call(this, config) || this;
- }
- Add.prototype.mergeFunction = function (inputs) {
- return tfjs_core_1.tidy(function () {
- var output = tfc.zeros(inputs[0].shape);
- for (var _i = 0, inputs_3 = inputs; _i < inputs_3.length; _i++) {
- var input = inputs_3[_i];
- output = tfc.add(output, input);
- }
- return output;
- });
- };
- Add.className = 'Add';
- return Add;
- }(Merge));
- exports.Add = Add;
- tfjs_core_1.serialization.SerializationMap.register(Add);
- function add(config) {
- if (Array.isArray(config)) {
- var layer = new Add({});
- return layer.apply(config);
- }
- else {
- return new Add(config);
- }
- }
- exports.add = add;
- var Multiply = (function (_super) {
- __extends(Multiply, _super);
- function Multiply(config) {
- return _super.call(this, config) || this;
- }
- Multiply.prototype.mergeFunction = function (inputs) {
- return tfjs_core_1.tidy(function () {
- var output = tfc.ones(inputs[0].shape);
- for (var _i = 0, inputs_4 = inputs; _i < inputs_4.length; _i++) {
- var input = inputs_4[_i];
- output = tfc.mul(output, input);
- }
- return output;
- });
- };
- Multiply.className = 'Multiply';
- return Multiply;
- }(Merge));
- exports.Multiply = Multiply;
- tfjs_core_1.serialization.SerializationMap.register(Multiply);
- function multiply(config) {
- if (Array.isArray(config)) {
- var layer = new Multiply({});
- return layer.apply(config);
- }
- else {
- return new Multiply(config);
- }
- }
- exports.multiply = multiply;
- var Average = (function (_super) {
- __extends(Average, _super);
- function Average(config) {
- return _super.call(this, config) || this;
- }
- Average.prototype.mergeFunction = function (inputs) {
- return tfjs_core_1.tidy(function () {
- var output = tfc.zeros(inputs[0].shape);
- for (var _i = 0, inputs_5 = inputs; _i < inputs_5.length; _i++) {
- var input = inputs_5[_i];
- output = tfc.add(output, input);
- }
- return K.scalarTimesArray(K.getScalar(1 / inputs.length), output);
- });
- };
- Average.className = 'Average';
- return Average;
- }(Merge));
- exports.Average = Average;
- tfjs_core_1.serialization.SerializationMap.register(Average);
- function average(config) {
- if (Array.isArray(config)) {
- var layer = new Average({});
- return layer.apply(config);
- }
- else {
- return new Average(config);
- }
- }
- exports.average = average;
- var Maximum = (function (_super) {
- __extends(Maximum, _super);
- function Maximum(config) {
- return _super.call(this, config) || this;
- }
- Maximum.prototype.mergeFunction = function (inputs) {
- return tfjs_core_1.tidy(function () {
- var output = inputs[0];
- for (var i = 1; i < inputs.length; ++i) {
- output = tfc.maximum(output, inputs[i]);
- }
- return output;
- });
- };
- Maximum.className = 'Maximum';
- return Maximum;
- }(Merge));
- exports.Maximum = Maximum;
- tfjs_core_1.serialization.SerializationMap.register(Maximum);
- function maximum(config) {
- if (Array.isArray(config)) {
- var layer = new Maximum({});
- return layer.apply(config);
- }
- else {
- return new Maximum(config);
- }
- }
- exports.maximum = maximum;
- var Minimum = (function (_super) {
- __extends(Minimum, _super);
- function Minimum(config) {
- return _super.call(this, config) || this;
- }
- Minimum.prototype.mergeFunction = function (inputs) {
- return tfjs_core_1.tidy(function () {
- var output = inputs[0];
- for (var i = 1; i < inputs.length; ++i) {
- output = tfc.minimum(output, inputs[i]);
- }
- return output;
- });
- };
- Minimum.className = 'Minimum';
- return Minimum;
- }(Merge));
- exports.Minimum = Minimum;
- tfjs_core_1.serialization.SerializationMap.register(Minimum);
- function minimum(config) {
- if (Array.isArray(config)) {
- var layer = new Minimum({});
- return layer.apply(config);
- }
- else {
- return new Minimum(config);
- }
- }
- exports.minimum = minimum;
- var Concatenate = (function (_super) {
- __extends(Concatenate, _super);
- function Concatenate(config) {
- var _this = _super.call(this, config) || this;
- _this.DEFAULT_AXIS = -1;
- if (config == null) {
- config = {};
- }
- _this.axis = config.axis == null ? _this.DEFAULT_AXIS : config.axis;
- _this.supportsMasking = true;
- _this.reshapeRequired = false;
- return _this;
- }
- Concatenate.prototype.build = function (inputShape) {
- if (!(Array.isArray(inputShape) && Array.isArray(inputShape[0])) ||
- inputShape.length === 1) {
- throw new errors_1.ValueError('A `Concatenate` layer should be called on a list of at least 2 ' +
- 'inputs');
- }
- inputShape = inputShape;
- var allNoneShape = true;
- for (var _i = 0, inputShape_3 = inputShape; _i < inputShape_3.length; _i++) {
- var shape = inputShape_3[_i];
- if (shape != null) {
- allNoneShape = false;
- break;
- }
- }
- if (allNoneShape) {
- return;
- }
- var shapeSet = [];
- for (var i = 0; i < inputShape.length; ++i) {
- var shapeWithoutConcatAxis = inputShape[i].slice();
- shapeWithoutConcatAxis.splice(this.axis, 1);
- var exists = false;
- for (var _a = 0, shapeSet_1 = shapeSet; _a < shapeSet_1.length; _a++) {
- var shape = shapeSet_1[_a];
- if (tfjs_core_1.util.arraysEqual(shape, shapeWithoutConcatAxis)) {
- exists = true;
- break;
- }
- }
- if (!exists) {
- shapeSet.push(shapeWithoutConcatAxis);
- }
- }
- if (shapeSet.length > 1) {
- throw new errors_1.ValueError('A `Concatenate` layer requires inputs with matching shapes ' +
- 'except for the concat axis. Got input shapes: ' +
- JSON.stringify(inputShape));
- }
- };
- Concatenate.prototype.mergeFunction = function (inputs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- return K.concatenate(inputs, _this.axis);
- });
- };
- Concatenate.prototype.computeOutputShape = function (inputShape) {
- if (!(Array.isArray(inputShape) && Array.isArray(inputShape[0]))) {
- throw new errors_1.ValueError('A `Concatenate` layer should be called on a list of inputs.');
- }
- var inputShapes = inputShape;
- var outputShape = inputShapes[0].slice();
- var axis = this.axis < 0 ? outputShape.length + this.axis : this.axis;
- for (var _i = 0, _a = inputShapes.slice(1); _i < _a.length; _i++) {
- var shape = _a[_i];
- if (outputShape[axis] == null || shape[axis] == null) {
- outputShape[axis] = null;
- break;
- }
- outputShape[axis] += shape[axis];
- }
- return outputShape;
- };
- Concatenate.prototype.getConfig = function () {
- var config = {
- 'axis': this.axis,
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- Concatenate.className = 'Concatenate';
- return Concatenate;
- }(Merge));
- exports.Concatenate = Concatenate;
- tfjs_core_1.serialization.SerializationMap.register(Concatenate);
- function concatenate(config) {
- if (Array.isArray(config)) {
- var layer = new Concatenate({});
- return layer.apply(config);
- }
- else {
- return new Concatenate(config);
- }
- }
- exports.concatenate = concatenate;
- },{"../backend/tfjs_backend":169,"../engine/topology":174,"../errors":176,"../utils/generic_utils":199,"../utils/math_utils":201,"@tensorflow/tfjs-core":54}],186:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("../backend/tfjs_backend");
- var constraints_1 = require("../constraints");
- var topology_1 = require("../engine/topology");
- var errors_1 = require("../errors");
- var initializers_1 = require("../initializers");
- var regularizers_1 = require("../regularizers");
- var generic_utils = require("../utils/generic_utils");
- var math_utils = require("../utils/math_utils");
- function batchNormalization(x, mean, variance, beta, gamma, epsilon) {
- if (epsilon === void 0) { epsilon = 1e-3; }
- var out;
- if (x.rank === 2) {
- out = tfc.batchNormalization2d(x, mean, variance, epsilon, gamma, beta);
- }
- else if (x.rank === 3) {
- out = tfc.batchNormalization3d(x, mean, variance, epsilon, gamma, beta);
- }
- else if (x.rank === 4) {
- out = tfc.batchNormalization4d(x, mean, variance, epsilon, gamma, beta);
- }
- else {
- throw new errors_1.NotImplementedError("batchNormalization is not implememnted for array of rank " + x.rank + " " +
- "yet");
- }
- return out;
- }
- exports.batchNormalization = batchNormalization;
- function regularNormalizeBatchInTraining(x, gamma, beta, reductionAxes, epsilon) {
- if (epsilon === void 0) { epsilon = 1e-3; }
- return tfjs_core_1.tidy(function () {
- var meanAndVariance = tfc.moments(x, reductionAxes);
- var mean = meanAndVariance.mean;
- var variance = meanAndVariance.variance;
- var normed = batchNormalization(x, mean, variance, beta, gamma, epsilon);
- return [normed, mean, variance];
- });
- }
- function broadcastNormalizeBatchInTraining(x, gamma, beta, reductionAxes, epsilon) {
- if (epsilon === void 0) { epsilon = 1e-3; }
- return tfjs_core_1.tidy(function () {
- var meanAndVariance = tfc.moments(x, reductionAxes);
- var mean = meanAndVariance.mean;
- var variance = meanAndVariance.variance;
- var targetShape = [];
- for (var _i = 0, _a = math_utils.range(0, x.rank); _i < _a.length; _i++) {
- var axis = _a[_i];
- if (reductionAxes.indexOf(axis) !== -1) {
- targetShape.push(1);
- }
- else {
- targetShape.push(x.shape[axis]);
- }
- }
- var broadcastMean = mean.reshape(targetShape);
- var broadcastVariance = variance.reshape(targetShape);
- var broadcastGamma = gamma == null ? null : gamma.reshape(targetShape);
- var broadcastBeta = beta == null ? null : beta.reshape(targetShape);
- var normed = batchNormalization(x, broadcastMean, broadcastVariance, broadcastBeta, broadcastGamma, epsilon);
- return [normed, mean, variance];
- });
- }
- function normalizeBatchInTraining(x, gamma, beta, reductionAxes, epsilon) {
- if (epsilon === void 0) { epsilon = 1e-3; }
- if (tfjs_core_1.util.arraysEqual(reductionAxes.slice().sort(), math_utils.range(0, x.rank - 1))) {
- return regularNormalizeBatchInTraining(x, gamma, beta, reductionAxes, epsilon);
- }
- else {
- return broadcastNormalizeBatchInTraining(x, gamma, beta, reductionAxes, epsilon);
- }
- }
- exports.normalizeBatchInTraining = normalizeBatchInTraining;
- var BatchNormalization = (function (_super) {
- __extends(BatchNormalization, _super);
- function BatchNormalization(config) {
- var _this = _super.call(this, config) || this;
- _this.supportsMasking = true;
- _this.axis = config.axis == null ? -1 : config.axis;
- _this.momentum = config.momentum == null ? 0.99 : config.momentum;
- _this.epsilon = config.epsilon == null ? 1e-3 : config.epsilon;
- _this.center = config.center == null ? true : config.center;
- _this.scale = config.scale == null ? true : config.scale;
- _this.betaInitializer = initializers_1.getInitializer(config.betaInitializer || 'zeros');
- _this.gammaInitializer = initializers_1.getInitializer(config.gammaInitializer || 'ones');
- _this.movingMeanInitializer =
- initializers_1.getInitializer(config.movingMeanInitializer || 'zeros');
- _this.movingVarianceInitializer =
- initializers_1.getInitializer(config.movingVarianceInitializer || 'ones');
- _this.betaConstraint = constraints_1.getConstraint(config.betaConstraint);
- _this.gammaConstraint = constraints_1.getConstraint(config.gammaConstraint);
- _this.betaRegularizer = regularizers_1.getRegularizer(config.betaRegularizer);
- _this.gammaRegularizer = regularizers_1.getRegularizer(config.gammaRegularizer);
- _this.stepCount = 0;
- return _this;
- }
- BatchNormalization.prototype.build = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- var axis = this.axis >= 0 ? this.axis : (this.axis + inputShape.length);
- var dim = inputShape[axis];
- if (dim == null) {
- throw new errors_1.ValueError("Axis " + axis + " of input tensor should have a defined dimension but " +
- "the layer received an input with shape " +
- (JSON.stringify(inputShape) + "."));
- }
- this.inputSpec =
- [new topology_1.InputSpec({ ndim: inputShape.length, axes: (_a = {}, _a[axis] = dim, _a) })];
- var shape = [dim];
- if (this.scale) {
- this.gamma = this.addWeight('gamma', shape, null, this.gammaInitializer, this.gammaRegularizer, true, this.gammaConstraint);
- }
- if (this.center) {
- this.beta = this.addWeight('beta', shape, null, this.betaInitializer, this.betaRegularizer, true, this.betaConstraint);
- }
- this.movingMean = this.addWeight('moving_mean', shape, null, this.movingMeanInitializer, null, false);
- this.movingVariance = this.addWeight('moving_variance', shape, null, this.movingVarianceInitializer, null, false);
- this.built = true;
- var _a;
- };
- BatchNormalization.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- var training = kwargs['training'] == null ? false : kwargs['training'];
- var input = generic_utils.getExactlyOneTensor(inputs);
- var inputShape = K.shape(input);
- var ndim = inputShape.length;
- var reductionAxes = math_utils.range(0, ndim);
- var axis = _this.axis >= 0 ? _this.axis : (_this.axis + ndim);
- reductionAxes.splice(axis, 1);
- var broadcastShape = generic_utils.pyListRepeat(1, ndim);
- broadcastShape[axis] = inputShape[axis];
- var sortedReductionAxes = reductionAxes.slice();
- sortedReductionAxes.sort();
- var needsBroadcasting = !tfjs_core_1.util.arraysEqual(sortedReductionAxes, math_utils.range(0, ndim).slice(0, ndim - 1));
- var normalizeInference = function () {
- if (needsBroadcasting) {
- var broadcastMovingMean = _this.movingMean.read().reshape(broadcastShape);
- var broadcastMovingVariance = _this.movingVariance.read().reshape(broadcastShape);
- var broadcastBeta = _this.center ? _this.beta.read().reshape(broadcastShape) : null;
- var broadcastGamma = _this.scale ? _this.gamma.read().reshape(broadcastShape) : null;
- return batchNormalization(input, broadcastMovingMean, broadcastMovingVariance, broadcastBeta, broadcastGamma, _this.epsilon);
- }
- else {
- return batchNormalization(input, _this.movingMean.read(), _this.movingVariance.read(), _this.beta == null ? null : _this.beta.read(), _this.gamma == null ? null : _this.gamma.read(), _this.epsilon);
- }
- };
- if (!training) {
- return normalizeInference();
- }
- var _a = normalizeBatchInTraining(input, _this.gamma.read(), _this.beta.read(), reductionAxes, _this.epsilon), normedTraining = _a[0], mean = _a[1], variance = _a[2];
- var sampleSize = math_utils.arrayProd(reductionAxes.map(function (axis) { return input.shape[axis]; }));
- var varianceDebiased = variance.mul(K.getScalar(sampleSize / (sampleSize - (1 + _this.epsilon))));
- var updateMovingMeanAndVariance = function () {
- _this.stepCount++;
- var newMovingMean = tfc.movingAverage(_this.movingMean.read(), mean, _this.momentum, _this.stepCount);
- _this.movingMean.write(newMovingMean);
- var newMovingVariance = tfc.movingAverage(_this.movingVariance.read(), varianceDebiased, _this.momentum, _this.stepCount);
- _this.movingVariance.write(newMovingVariance);
- };
- updateMovingMeanAndVariance();
- return normedTraining;
- });
- };
- BatchNormalization.prototype.getConfig = function () {
- var config = {
- axis: this.axis,
- momentum: this.momentum,
- epsilon: this.epsilon,
- center: this.center,
- scale: this.scale,
- betaInitializer: initializers_1.serializeInitializer(this.betaInitializer),
- gammaInitializer: initializers_1.serializeInitializer(this.gammaInitializer),
- movingMeanInitializer: initializers_1.serializeInitializer(this.movingMeanInitializer),
- movingVarianceInitializer: initializers_1.serializeInitializer(this.movingVarianceInitializer),
- betaRegularizer: regularizers_1.serializeRegularizer(this.betaRegularizer),
- gammaRegularizer: regularizers_1.serializeRegularizer(this.gammaRegularizer),
- betaConstraint: constraints_1.serializeConstraint(this.betaConstraint),
- gammaConstraint: constraints_1.serializeConstraint(this.gammaConstraint)
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- BatchNormalization.className = 'BatchNormalization';
- return BatchNormalization;
- }(topology_1.Layer));
- exports.BatchNormalization = BatchNormalization;
- tfjs_core_1.serialization.SerializationMap.register(BatchNormalization);
- },{"../backend/tfjs_backend":169,"../constraints":172,"../engine/topology":174,"../errors":176,"../initializers":179,"../regularizers":196,"../utils/generic_utils":199,"../utils/math_utils":201,"@tensorflow/tfjs-core":54}],187:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var common_1 = require("../backend/common");
- var topology_1 = require("../engine/topology");
- var errors_1 = require("../errors");
- var generic_utils_1 = require("../utils/generic_utils");
- function temporalPadding(x, padding) {
- return tfjs_core_1.tidy(function () {
- if (x.rank !== 3) {
- throw new errors_1.ValueError("temporalPadding expects input tensor to be 3-D, but received a " +
- (x.rank + "-D tensor."));
- }
- if (padding == null) {
- padding = [1, 1];
- }
- if (padding.length !== 2) {
- throw new errors_1.ValueError("temporalPadding expects input padding pattern to be a length-2 " +
- ("array, but received a length-" + padding.length + " array."));
- }
- var pattern = [[0, 0], padding, [0, 0]];
- return tfc.pad(x, pattern);
- });
- }
- exports.temporalPadding = temporalPadding;
- function spatial2dPadding(x, padding, dataFormat) {
- return tfjs_core_1.tidy(function () {
- if (x.rank !== 4) {
- throw new errors_1.ValueError("temporalPadding expects input tensor to be 4-D, but received a " +
- (x.rank + "-D tensor."));
- }
- if (padding == null) {
- padding = [[1, 1], [1, 1]];
- }
- if (padding.length !== 2 || padding[0].length !== 2 ||
- padding[1].length !== 2) {
- throw new errors_1.ValueError('spatial2dPadding expects `padding` to be an Array of two Arrays, ' +
- 'each of which is an Array of two integers.');
- }
- if (dataFormat == null) {
- dataFormat = common_1.imageDataFormat();
- }
- if (dataFormat !== 'channelsLast' && dataFormat !== 'channelsFirst') {
- throw new errors_1.ValueError("Unknown data format: " + dataFormat + ". " +
- "Supported data formats are 'channelsLast' and 'channelsFirst.");
- }
- var pattern;
- if (dataFormat === 'channelsFirst') {
- pattern = [[0, 0], [0, 0], padding[0], padding[1]];
- }
- else {
- pattern = [[0, 0], padding[0], padding[1], [0, 0]];
- }
- return tfc.pad(x, pattern);
- });
- }
- exports.spatial2dPadding = spatial2dPadding;
- var ZeroPadding2D = (function (_super) {
- __extends(ZeroPadding2D, _super);
- function ZeroPadding2D(config) {
- var _this = this;
- if (config == null) {
- config = {};
- }
- _this = _super.call(this, config) || this;
- _this.dataFormat =
- config.dataFormat == null ? common_1.imageDataFormat() : config.dataFormat;
- if (config.padding == null) {
- _this.padding = [[1, 1], [1, 1]];
- }
- else if (typeof config.padding === 'number') {
- _this.padding =
- [[config.padding, config.padding], [config.padding, config.padding]];
- }
- else {
- config.padding = config.padding;
- if (config.padding.length !== 2) {
- throw new errors_1.ValueError("ZeroPadding2D expects padding to be a length-2 array, but " +
- ("received a length-" + config.padding.length + " array."));
- }
- var heightPadding = void 0;
- var widthPadding = void 0;
- if (typeof config.padding[0] === 'number') {
- heightPadding =
- [config.padding[0], config.padding[0]];
- widthPadding =
- [config.padding[1], config.padding[1]];
- }
- else {
- config.padding = config.padding;
- if (config.padding[0].length !== 2) {
- throw new errors_1.ValueError("ZeroPadding2D expects height padding to be a length-2 array, " +
- ("but received a length-" + config.padding[0].length + " array."));
- }
- heightPadding = config.padding[0];
- if (config.padding[1].length !== 2) {
- throw new errors_1.ValueError("ZeroPadding2D expects width padding to be a length-2 array, " +
- ("but received a length-" + config.padding[1].length + " array."));
- }
- widthPadding = config.padding[1];
- }
- _this.padding = [heightPadding, widthPadding];
- }
- _this.inputSpec = [new topology_1.InputSpec({ ndim: 4 })];
- return _this;
- }
- ZeroPadding2D.prototype.computeOutputShape = function (inputShape) {
- inputShape = generic_utils_1.getExactlyOneShape(inputShape);
- var rows;
- var cols;
- if (this.dataFormat === 'channelsFirst') {
- if (inputShape[2] != null && inputShape[2] >= 0) {
- rows = inputShape[2] + this.padding[0][0] + this.padding[0][1];
- }
- else {
- rows = null;
- }
- if (inputShape[3] != null && inputShape[3] >= 0) {
- cols = inputShape[3] + this.padding[1][0] + this.padding[1][1];
- }
- else {
- cols = null;
- }
- return [inputShape[0], inputShape[1], rows, cols];
- }
- else {
- if (inputShape[1] != null && inputShape[1] >= 0) {
- rows = inputShape[1] + this.padding[0][0] + this.padding[0][1];
- }
- else {
- rows = null;
- }
- if (inputShape[2] != null && inputShape[2] >= 0) {
- cols = inputShape[2] + this.padding[1][0] + this.padding[1][1];
- }
- else {
- cols = null;
- }
- return [inputShape[0], rows, cols, inputShape[3]];
- }
- };
- ZeroPadding2D.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () { return spatial2dPadding(generic_utils_1.getExactlyOneTensor(inputs), _this.padding, _this.dataFormat); });
- };
- ZeroPadding2D.prototype.getConfig = function () {
- var config = {
- padding: this.padding,
- dataFormat: this.dataFormat,
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- ZeroPadding2D.className = 'ZeroPadding2D';
- return ZeroPadding2D;
- }(topology_1.Layer));
- exports.ZeroPadding2D = ZeroPadding2D;
- tfjs_core_1.serialization.SerializationMap.register(ZeroPadding2D);
- },{"../backend/common":168,"../engine/topology":174,"../errors":176,"../utils/generic_utils":199,"@tensorflow/tfjs-core":54}],188:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var common_1 = require("../backend/common");
- var K = require("../backend/tfjs_backend");
- var common_2 = require("../common");
- var topology_1 = require("../engine/topology");
- var topology_2 = require("../engine/topology");
- var errors_1 = require("../errors");
- var conv_utils_1 = require("../utils/conv_utils");
- var generic_utils = require("../utils/generic_utils");
- var convolutional_1 = require("./convolutional");
- function pool2d(x, poolSize, strides, padding, dataFormat, poolMode) {
- return tfjs_core_1.tidy(function () {
- common_2.checkDataFormat(dataFormat);
- common_2.checkPoolMode(poolMode);
- common_2.checkPaddingMode(padding);
- if (strides == null) {
- strides = [1, 1];
- }
- if (padding == null) {
- padding = 'valid';
- }
- if (dataFormat == null) {
- dataFormat = common_1.imageDataFormat();
- }
- if (poolMode == null) {
- poolMode = 'max';
- }
- x = convolutional_1.preprocessConv2DInput(x, dataFormat);
- var y;
- var paddingString = (padding === 'same') ? 'same' : 'valid';
- if (poolMode === 'max') {
- y = tfc.maxPool(x, poolSize, strides, paddingString);
- }
- else {
- y = tfc.avgPool(x, poolSize, strides, paddingString);
- }
- if (dataFormat === 'channelsFirst') {
- y = tfc.transpose(y, [0, 3, 1, 2]);
- }
- return y;
- });
- }
- exports.pool2d = pool2d;
- var Pooling1D = (function (_super) {
- __extends(Pooling1D, _super);
- function Pooling1D(config) {
- var _this = this;
- if (config.poolSize == null) {
- config.poolSize = 2;
- }
- _this = _super.call(this, config) || this;
- if (typeof config.poolSize === 'number') {
- _this.poolSize = [config.poolSize];
- }
- else if (Array.isArray(config.poolSize) &&
- config.poolSize.length === 1 &&
- typeof config.poolSize[0] === 'number') {
- _this.poolSize = config.poolSize;
- }
- else {
- throw new errors_1.ValueError("poolSize for 1D convolutional layer must be a number or an " +
- "Array of a single number, but received " +
- ("" + JSON.stringify(config.poolSize)));
- }
- if (config.strides == null) {
- _this.strides = _this.poolSize;
- }
- else {
- if (typeof config.strides === 'number') {
- _this.strides = [config.strides];
- }
- else if (Array.isArray(config.strides) &&
- config.strides.length === 1 &&
- typeof config.strides[0] === 'number') {
- _this.strides = config.strides;
- }
- else {
- throw new errors_1.ValueError("strides for 1D convolutional layer must be a number or an " +
- "Array of a single number, but received " +
- ("" + JSON.stringify(config.strides)));
- }
- }
- _this.padding = config.padding == null ? 'valid' : config.padding;
- common_2.checkPaddingMode(_this.padding);
- _this.inputSpec = [new topology_1.InputSpec({ ndim: 3 })];
- return _this;
- }
- Pooling1D.prototype.computeOutputShape = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- var length = conv_utils_1.convOutputLength(inputShape[1], this.poolSize[0], this.padding, this.strides[0]);
- return [inputShape[0], length, inputShape[2]];
- };
- Pooling1D.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- _this.invokeCallHook(inputs, kwargs);
- inputs = K.expandDims(generic_utils.getExactlyOneTensor(inputs), 2);
- var output = _this.poolingFunction(generic_utils.getExactlyOneTensor(inputs), [_this.poolSize[0], 1], [_this.strides[0], 1], _this.padding, 'channelsLast');
- return tfc.squeeze(output, [2]);
- });
- };
- Pooling1D.prototype.getConfig = function () {
- var config = {
- poolSize: this.poolSize,
- padding: this.padding,
- strides: this.strides,
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- return Pooling1D;
- }(topology_2.Layer));
- exports.Pooling1D = Pooling1D;
- var MaxPooling1D = (function (_super) {
- __extends(MaxPooling1D, _super);
- function MaxPooling1D(config) {
- return _super.call(this, config) || this;
- }
- MaxPooling1D.prototype.poolingFunction = function (inputs, poolSize, strides, padding, dataFormat) {
- common_2.checkDataFormat(dataFormat);
- common_2.checkPaddingMode(padding);
- return pool2d(inputs, poolSize, strides, padding, dataFormat, 'max');
- };
- MaxPooling1D.className = 'MaxPooling1D';
- return MaxPooling1D;
- }(Pooling1D));
- exports.MaxPooling1D = MaxPooling1D;
- tfjs_core_1.serialization.SerializationMap.register(MaxPooling1D);
- var AveragePooling1D = (function (_super) {
- __extends(AveragePooling1D, _super);
- function AveragePooling1D(config) {
- return _super.call(this, config) || this;
- }
- AveragePooling1D.prototype.poolingFunction = function (inputs, poolSize, strides, padding, dataFormat) {
- common_2.checkDataFormat(dataFormat);
- common_2.checkPaddingMode(padding);
- return pool2d(inputs, poolSize, strides, padding, dataFormat, 'avg');
- };
- AveragePooling1D.className = 'AveragePooling1D';
- return AveragePooling1D;
- }(Pooling1D));
- exports.AveragePooling1D = AveragePooling1D;
- tfjs_core_1.serialization.SerializationMap.register(AveragePooling1D);
- var Pooling2D = (function (_super) {
- __extends(Pooling2D, _super);
- function Pooling2D(config) {
- var _this = this;
- if (config.poolSize == null) {
- config.poolSize = [2, 2];
- }
- _this = _super.call(this, config) || this;
- _this.poolSize = Array.isArray(config.poolSize) ?
- config.poolSize :
- [config.poolSize, config.poolSize];
- if (config.strides == null) {
- _this.strides = _this.poolSize;
- }
- else if (Array.isArray(config.strides)) {
- if (config.strides.length !== 2) {
- throw new errors_1.ValueError("If the strides property of a 2D pooling layer is an Array, " +
- "it is expected to have a length of 2, but received length " +
- (config.strides.length + "."));
- }
- _this.strides = config.strides;
- }
- else {
- _this.strides = [config.strides, config.strides];
- }
- _this.padding = config.padding == null ? 'valid' : config.padding;
- _this.dataFormat =
- config.dataFormat == null ? 'channelsLast' : config.dataFormat;
- common_2.checkDataFormat(_this.dataFormat);
- common_2.checkPaddingMode(_this.padding);
- _this.inputSpec = [new topology_1.InputSpec({ ndim: 4 })];
- return _this;
- }
- Pooling2D.prototype.computeOutputShape = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- var rows = this.dataFormat === 'channelsFirst' ? inputShape[2] : inputShape[1];
- var cols = this.dataFormat === 'channelsFirst' ? inputShape[3] : inputShape[2];
- rows =
- conv_utils_1.convOutputLength(rows, this.poolSize[0], this.padding, this.strides[0]);
- cols =
- conv_utils_1.convOutputLength(cols, this.poolSize[1], this.padding, this.strides[1]);
- if (this.dataFormat === 'channelsFirst') {
- return [inputShape[0], inputShape[1], rows, cols];
- }
- else {
- return [inputShape[0], rows, cols, inputShape[3]];
- }
- };
- Pooling2D.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- _this.invokeCallHook(inputs, kwargs);
- return _this.poolingFunction(generic_utils.getExactlyOneTensor(inputs), _this.poolSize, _this.strides, _this.padding, _this.dataFormat);
- });
- };
- Pooling2D.prototype.getConfig = function () {
- var config = {
- poolSize: this.poolSize,
- padding: this.padding,
- strides: this.strides,
- dataFormat: this.dataFormat
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- return Pooling2D;
- }(topology_2.Layer));
- exports.Pooling2D = Pooling2D;
- var MaxPooling2D = (function (_super) {
- __extends(MaxPooling2D, _super);
- function MaxPooling2D(config) {
- return _super.call(this, config) || this;
- }
- MaxPooling2D.prototype.poolingFunction = function (inputs, poolSize, strides, padding, dataFormat) {
- common_2.checkDataFormat(dataFormat);
- common_2.checkPaddingMode(padding);
- return pool2d(inputs, poolSize, strides, padding, dataFormat, 'max');
- };
- MaxPooling2D.className = 'MaxPooling2D';
- return MaxPooling2D;
- }(Pooling2D));
- exports.MaxPooling2D = MaxPooling2D;
- tfjs_core_1.serialization.SerializationMap.register(MaxPooling2D);
- var AveragePooling2D = (function (_super) {
- __extends(AveragePooling2D, _super);
- function AveragePooling2D(config) {
- return _super.call(this, config) || this;
- }
- AveragePooling2D.prototype.poolingFunction = function (inputs, poolSize, strides, padding, dataFormat) {
- common_2.checkDataFormat(dataFormat);
- common_2.checkPaddingMode(padding);
- return pool2d(inputs, poolSize, strides, padding, dataFormat, 'avg');
- };
- AveragePooling2D.className = 'AveragePooling2D';
- return AveragePooling2D;
- }(Pooling2D));
- exports.AveragePooling2D = AveragePooling2D;
- tfjs_core_1.serialization.SerializationMap.register(AveragePooling2D);
- var GlobalPooling1D = (function (_super) {
- __extends(GlobalPooling1D, _super);
- function GlobalPooling1D(config) {
- var _this = _super.call(this, config) || this;
- _this.inputSpec = [new topology_1.InputSpec({ ndim: 3 })];
- return _this;
- }
- GlobalPooling1D.prototype.computeOutputShape = function (inputShape) {
- return [inputShape[0], inputShape[2]];
- };
- GlobalPooling1D.prototype.call = function (inputs, kwargs) {
- throw new errors_1.NotImplementedError();
- };
- return GlobalPooling1D;
- }(topology_2.Layer));
- exports.GlobalPooling1D = GlobalPooling1D;
- var GlobalAveragePooling1D = (function (_super) {
- __extends(GlobalAveragePooling1D, _super);
- function GlobalAveragePooling1D(config) {
- return _super.call(this, config) || this;
- }
- GlobalAveragePooling1D.prototype.call = function (inputs, kwargs) {
- return tfjs_core_1.tidy(function () {
- var input = generic_utils.getExactlyOneTensor(inputs);
- return tfc.mean(input, 1);
- });
- };
- GlobalAveragePooling1D.className = 'GlobalAveragePooling1D';
- return GlobalAveragePooling1D;
- }(GlobalPooling1D));
- exports.GlobalAveragePooling1D = GlobalAveragePooling1D;
- tfjs_core_1.serialization.SerializationMap.register(GlobalAveragePooling1D);
- var GlobalMaxPooling1D = (function (_super) {
- __extends(GlobalMaxPooling1D, _super);
- function GlobalMaxPooling1D(config) {
- return _super.call(this, config) || this;
- }
- GlobalMaxPooling1D.prototype.call = function (inputs, kwargs) {
- return tfjs_core_1.tidy(function () {
- var input = generic_utils.getExactlyOneTensor(inputs);
- return tfc.max(input, 1);
- });
- };
- GlobalMaxPooling1D.className = 'GlobalMaxPooling1D';
- return GlobalMaxPooling1D;
- }(GlobalPooling1D));
- exports.GlobalMaxPooling1D = GlobalMaxPooling1D;
- tfjs_core_1.serialization.SerializationMap.register(GlobalMaxPooling1D);
- var GlobalPooling2D = (function (_super) {
- __extends(GlobalPooling2D, _super);
- function GlobalPooling2D(config) {
- var _this = _super.call(this, config) || this;
- _this.dataFormat =
- config.dataFormat == null ? 'channelsLast' : config.dataFormat;
- common_2.checkDataFormat(_this.dataFormat);
- _this.inputSpec = [new topology_1.InputSpec({ ndim: 4 })];
- return _this;
- }
- GlobalPooling2D.prototype.computeOutputShape = function (inputShape) {
- inputShape = inputShape;
- if (this.dataFormat === 'channelsLast') {
- return [inputShape[0], inputShape[3]];
- }
- else {
- return [inputShape[0], inputShape[1]];
- }
- };
- GlobalPooling2D.prototype.call = function (inputs, kwargs) {
- throw new errors_1.NotImplementedError();
- };
- GlobalPooling2D.prototype.getConfig = function () {
- var config = { dataFormat: this.dataFormat };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- return GlobalPooling2D;
- }(topology_2.Layer));
- exports.GlobalPooling2D = GlobalPooling2D;
- var GlobalAveragePooling2D = (function (_super) {
- __extends(GlobalAveragePooling2D, _super);
- function GlobalAveragePooling2D() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- GlobalAveragePooling2D.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- var input = generic_utils.getExactlyOneTensor(inputs);
- if (_this.dataFormat === 'channelsLast') {
- return tfc.mean(input, [1, 2]);
- }
- else {
- return tfc.mean(input, [2, 3]);
- }
- });
- };
- GlobalAveragePooling2D.className = 'GlobalAveragePooling2D';
- return GlobalAveragePooling2D;
- }(GlobalPooling2D));
- exports.GlobalAveragePooling2D = GlobalAveragePooling2D;
- tfjs_core_1.serialization.SerializationMap.register(GlobalAveragePooling2D);
- var GlobalMaxPooling2D = (function (_super) {
- __extends(GlobalMaxPooling2D, _super);
- function GlobalMaxPooling2D() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- GlobalMaxPooling2D.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- var input = generic_utils.getExactlyOneTensor(inputs);
- if (_this.dataFormat === 'channelsLast') {
- return tfc.max(input, [1, 2]);
- }
- else {
- return tfc.max(input, [2, 3]);
- }
- });
- };
- GlobalMaxPooling2D.className = 'GlobalMaxPooling2D';
- return GlobalMaxPooling2D;
- }(GlobalPooling2D));
- exports.GlobalMaxPooling2D = GlobalMaxPooling2D;
- tfjs_core_1.serialization.SerializationMap.register(GlobalMaxPooling2D);
- },{"../backend/common":168,"../backend/tfjs_backend":169,"../common":171,"../engine/topology":174,"../errors":176,"../utils/conv_utils":198,"../utils/generic_utils":199,"./convolutional":181,"@tensorflow/tfjs-core":54}],189:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var activations_1 = require("../activations");
- var K = require("../backend/tfjs_backend");
- var constraints_1 = require("../constraints");
- var topology_1 = require("../engine/topology");
- var topology_2 = require("../engine/topology");
- var errors_1 = require("../errors");
- var initializers_1 = require("../initializers");
- var regularizers_1 = require("../regularizers");
- var types_1 = require("../types");
- var generic_utils = require("../utils/generic_utils");
- var math_utils = require("../utils/math_utils");
- var variables_1 = require("../variables");
- var serialization_1 = require("./serialization");
- function rnn(stepFunction, inputs, initialStates, goBackwards, mask, constants, unroll, inputLength) {
- if (goBackwards === void 0) { goBackwards = false; }
- if (unroll === void 0) { unroll = false; }
- var ndim = inputs.shape.length;
- if (ndim < 3) {
- throw new errors_1.ValueError("Input should be at least 3D, but is " + ndim + "D.");
- }
- var axes = [1, 0].concat(math_utils.range(2, ndim));
- inputs = tfc.transpose(inputs, axes);
- if (mask != null) {
- throw new errors_1.NotImplementedError('The rnn() function of the deeplearn.js backend does not support ' +
- 'masking yet.');
- }
- if (constants != null) {
- throw new errors_1.NotImplementedError('The rnn() functoin of the deeplearn.js backend does not support ' +
- 'constants yet.');
- }
- if (unroll) {
- console.warn('Backend rnn(): the unroll = true option is not applicable to the ' +
- 'imperative deeplearn.js backend.');
- }
- if (goBackwards) {
- inputs = tfc.reverse(inputs, 0);
- }
- var outputs;
- var lastOutput;
- var states = initialStates;
- var timeSteps = inputs.shape[0];
- for (var t = 0; t < timeSteps; ++t) {
- var currentInput = K.sliceAlongFirstAxis(inputs, t, 1);
- currentInput = currentInput.reshape(currentInput.shape.slice(1));
- var stepOutputs = stepFunction(currentInput, states);
- lastOutput = stepOutputs[0];
- if (t === 0) {
- outputs = lastOutput.reshape([1].concat(lastOutput.shape));
- }
- else {
- outputs = K.concatAlongFirstAxis(outputs, lastOutput.reshape([1].concat(lastOutput.shape)));
- }
- states = stepOutputs[1];
- }
- return [
- lastOutput,
- tfc.transpose(outputs, [1, 0].concat(math_utils.range(2, outputs.shape.length))),
- states
- ];
- }
- exports.rnn = rnn;
- var RNN = (function (_super) {
- __extends(RNN, _super);
- function RNN(config) {
- var _this = _super.call(this, config) || this;
- var cell;
- if (config.cell == null) {
- throw new errors_1.ValueError('cell property is missing for the constructor of RNN.');
- }
- else if (Array.isArray(config.cell)) {
- cell = new StackedRNNCells({ cells: config.cell });
- }
- else {
- cell = config.cell;
- }
- if (cell.stateSize == null) {
- throw new errors_1.ValueError('The RNN cell should have an attribute `stateSize` (tuple of ' +
- 'integers, one integer per RNN state).');
- }
- _this.cell = cell;
- _this.returnSequences =
- config.returnSequences == null ? false : config.returnSequences;
- _this.returnState = config.returnState == null ? false : config.returnState;
- _this.goBackwards = config.goBackwards == null ? false : config.goBackwards;
- _this._stateful = config.stateful == null ? false : config.stateful;
- _this.unroll = config.unroll == null ? false : config.unroll;
- _this.supportsMasking = true;
- _this.inputSpec = [new topology_1.InputSpec({ ndim: 3 })];
- _this.stateSpec = null;
- _this.states = null;
- _this.numConstants = null;
- return _this;
- }
- RNN.prototype.getStates = function () {
- if (this.states == null) {
- var numStates = Array.isArray(this.cell.stateSize) ? this.cell.stateSize.length : 1;
- return math_utils.range(0, numStates).map(function (x) { return null; });
- }
- else {
- return this.states;
- }
- };
- RNN.prototype.setStates = function (states) {
- this.states = states;
- };
- RNN.prototype.computeOutputShape = function (inputShape) {
- if (generic_utils.isArrayOfShapes(inputShape)) {
- inputShape = inputShape[0];
- }
- inputShape = inputShape;
- var stateSize = this.cell.stateSize;
- if (!Array.isArray(stateSize)) {
- stateSize = [stateSize];
- }
- var outputDim = stateSize[0];
- var outputShape;
- if (this.returnSequences) {
- outputShape = [inputShape[0], inputShape[1], outputDim];
- }
- else {
- outputShape = [inputShape[0], outputDim];
- }
- if (this.returnState) {
- var stateShape = [];
- for (var _i = 0, stateSize_1 = stateSize; _i < stateSize_1.length; _i++) {
- var dim = stateSize_1[_i];
- stateShape.push([inputShape[0], dim]);
- }
- return [outputShape].concat(stateShape);
- }
- else {
- return outputShape;
- }
- };
- RNN.prototype.computeMask = function (inputs, mask) {
- throw new errors_1.NotImplementedError('computeMask has not been implemented for RNN yet');
- };
- RNN.prototype.build = function (inputShape) {
- var constantShape = null;
- if (this.numConstants != null) {
- throw new errors_1.NotImplementedError('Constants support is not implemented in RNN yet.');
- }
- if (generic_utils.isArrayOfShapes(inputShape)) {
- inputShape = inputShape[0];
- }
- inputShape = inputShape;
- var batchSize = this.stateful ? inputShape[0] : null;
- var inputDim = inputShape[inputShape.length - 1];
- this.inputSpec[0] = new topology_1.InputSpec({ shape: [batchSize, null, inputDim] });
- var stepInputShape = [inputShape[0]].concat(inputShape.slice(2));
- if (constantShape != null) {
- throw new errors_1.NotImplementedError('Constants support is not implemented in RNN yet.');
- }
- else {
- this.cell.build(stepInputShape);
- }
- var stateSize;
- if (Array.isArray(this.cell.stateSize)) {
- stateSize = this.cell.stateSize;
- }
- else {
- stateSize = [this.cell.stateSize];
- }
- if (this.stateSpec != null) {
- if (!tfjs_core_1.util.arraysEqual(this.stateSpec.map(function (spec) { return spec.shape[spec.shape.length - 1]; }), stateSize)) {
- throw new errors_1.ValueError("An initialState was passed that is not compatible with " +
- ("cell.stateSize. Received stateSpec=" + this.stateSpec + "; ") +
- ("However cell.stateSize is " + this.cell.stateSize));
- }
- }
- else {
- this.stateSpec =
- stateSize.map(function (dim) { return new topology_1.InputSpec({ shape: [null, dim] }); });
- }
- if (this.stateful) {
- throw new errors_1.NotImplementedError('stateful RNN layer is not implemented yet');
- }
- };
- RNN.prototype.resetStates = function (states) {
- var _this = this;
- tfjs_core_1.tidy(function () {
- if (!_this.stateful) {
- throw new errors_1.AttributeError('Cannot call resetState() on an RNN Layer that is not stateful.');
- }
- var batchSize = _this.inputSpec[0].shape[0];
- if (batchSize == null) {
- throw new errors_1.ValueError('If an RNN is stateful, it needs to know its batch size. Specify ' +
- 'the batch size of your input tensors: \n' +
- '- If using a Sequential model, specify the batch size by ' +
- 'passing a `batchInputShape` option to your first layer.\n' +
- '- If using the functional API, specify the batch size by ' +
- 'passing a `batchShape` option to your Input layer.');
- }
- if (_this.states == null) {
- if (Array.isArray(_this.cell.stateSize)) {
- _this.states =
- _this.cell.stateSize.map(function (dim) { return tfc.zeros([batchSize, dim]); });
- }
- else {
- _this.states = [tfc.zeros([batchSize, _this.cell.stateSize])];
- }
- }
- else if (states == null) {
- if (Array.isArray(_this.cell.stateSize)) {
- _this.states =
- _this.cell.stateSize.map(function (dim) { return tfc.zeros([batchSize, dim]); });
- }
- else {
- _this.states[0] = tfc.zeros([batchSize, _this.cell.stateSize]);
- }
- }
- else {
- if (!Array.isArray(states)) {
- states = [states];
- }
- if (states.length !== _this.states.length) {
- throw new errors_1.ValueError("Layer " + _this.name + " expects " + _this.states.length + " state(s), " +
- ("but it received " + states.length + " state value(s). Input ") +
- ("received: " + states));
- }
- for (var index = 0; index < _this.states.length; ++index) {
- var value = states[index];
- var dim = Array.isArray(_this.cell.stateSize) ?
- _this.cell.stateSize[index] :
- _this.cell.stateSize;
- var expectedShape = [batchSize, dim];
- if (!tfjs_core_1.util.arraysEqual(value.shape, expectedShape)) {
- throw new errors_1.ValueError("State " + index + " is incompatible with layer " + _this.name + ": " +
- ("expected shape=" + expectedShape + ", received shape=" + value.shape));
- }
- _this.states[index] = value;
- }
- }
- });
- };
- RNN.prototype.standardizeArgs = function (inputs, initialState, constants) {
- if (Array.isArray(inputs)) {
- if (initialState != null || constants != null) {
- throw new errors_1.ValueError('When inputs is an array, neither initialState or constants ' +
- 'should be provided');
- }
- if (this.numConstants != null) {
- constants =
- inputs.slice(inputs.length - this.numConstants, inputs.length);
- inputs = inputs.slice(0, inputs.length - this.numConstants);
- }
- if (inputs.length > 1) {
- initialState = inputs.slice(1, inputs.length);
- }
- inputs = inputs[0];
- }
- function toListOrNull(x) {
- if (x == null || Array.isArray(x)) {
- return x;
- }
- else {
- return [x];
- }
- }
- initialState = toListOrNull(initialState);
- constants = toListOrNull(constants);
- return { inputs: inputs, initialState: initialState, constants: constants };
- };
- RNN.prototype.apply = function (inputs, kwargs) {
- var initialState = kwargs == null ? null : kwargs['initialState'];
- var constants = kwargs == null ? null : kwargs['constants'];
- if (kwargs == null) {
- kwargs = {};
- }
- var standardized = this.standardizeArgs(inputs, initialState, constants);
- inputs = standardized.inputs;
- initialState = standardized.initialState;
- constants = standardized.constants;
- var additionalInputs = [];
- var additionalSpecs = [];
- if (initialState != null) {
- kwargs['initialState'] = initialState;
- additionalInputs = additionalInputs.concat(initialState);
- this.stateSpec = [];
- for (var _i = 0, initialState_1 = initialState; _i < initialState_1.length; _i++) {
- var state = initialState_1[_i];
- this.stateSpec.push(new topology_1.InputSpec({ shape: state.shape }));
- }
- additionalSpecs = additionalSpecs.concat(this.stateSpec);
- }
- if (constants != null) {
- kwargs['constants'] = constants;
- additionalInputs = additionalInputs.concat(constants);
- this.numConstants = constants.length;
- }
- var isTensor = additionalInputs[0] instanceof types_1.SymbolicTensor;
- if (isTensor) {
- var fullInput = [inputs].concat(additionalInputs);
- var fullInputSpec = this.inputSpec.concat(additionalSpecs);
- var originalInputSpec = this.inputSpec;
- this.inputSpec = fullInputSpec;
- var output = _super.prototype.apply.call(this, fullInput, kwargs);
- this.inputSpec = originalInputSpec;
- return output;
- }
- else {
- return _super.prototype.apply.call(this, inputs, kwargs);
- }
- };
- RNN.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- var mask = kwargs == null ? null : kwargs['mask'];
- var training = kwargs == null ? null : kwargs['training'];
- var initialState = kwargs == null ? null : kwargs['initialState'];
- inputs = generic_utils.getExactlyOneTensor(inputs);
- if (initialState == null) {
- if (_this.stateful) {
- throw new errors_1.NotImplementedError('stateful RNN layer is not implemented yet.');
- }
- else {
- initialState = _this.getInitialState(inputs);
- }
- }
- if (mask != null) {
- throw new errors_1.NotImplementedError('Masking is not implemented for RNN yet');
- }
- var numStates = Array.isArray(_this.cell.stateSize) ? _this.cell.stateSize.length : 1;
- if (initialState.length !== numStates) {
- throw new errors_1.ValueError("RNN Layer has " + numStates + " state(s) but was passed " +
- (initialState.length + " initial state(s)."));
- }
- var inputShape = inputs.shape;
- var timesteps = inputShape[1];
- if (_this.unroll) {
- console.warn('Ignoring unroll = true for RNN layer, due to imperative backend.');
- }
- var cellCallKwargs = { training: training };
- var step = function (inputs, states) {
- var outputs = _this.cell.call([inputs].concat(states), cellCallKwargs);
- return [outputs[0], outputs.slice(1)];
- };
- var rnnOutputs = rnn(step, inputs, initialState, _this.goBackwards, null, null, _this.unroll, timesteps);
- var lastOutput = rnnOutputs[0];
- var outputs = rnnOutputs[1];
- var states = rnnOutputs[2];
- if (_this.stateful) {
- throw new errors_1.NotImplementedError('stateful RNN layer is not implemented yet');
- }
- var output = _this.returnSequences ? outputs : lastOutput;
- if (_this.returnState) {
- return [output].concat(states);
- }
- else {
- return output;
- }
- });
- };
- RNN.prototype.getInitialState = function (inputs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- var initialState = tfc.zeros(inputs.shape);
- initialState = tfc.sum(initialState, [1, 2]);
- initialState = K.expandDims(initialState);
- if (Array.isArray(_this.cell.stateSize)) {
- return _this.cell.stateSize.map(function (dim) { return dim > 1 ? K.tile(initialState, [1, dim]) : initialState; });
- }
- else {
- return _this.cell.stateSize > 1 ?
- [K.tile(initialState, [1, _this.cell.stateSize])] :
- [initialState];
- }
- });
- };
- Object.defineProperty(RNN.prototype, "trainableWeights", {
- get: function () {
- if (!this.trainable) {
- return [];
- }
- return this.cell.trainableWeights;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(RNN.prototype, "nonTrainableWeights", {
- get: function () {
- if (!this.trainable) {
- return this.cell.weights;
- }
- return this.cell.nonTrainableWeights;
- },
- enumerable: true,
- configurable: true
- });
- RNN.prototype.getConfig = function () {
- var config = {
- returnSequences: this.returnSequences,
- returnState: this.returnState,
- goBackwards: this.goBackwards,
- stateful: this.stateful,
- unroll: this.unroll,
- };
- if (this.numConstants != null) {
- config.numConstants = this.numConstants;
- }
- var cellConfig = this.cell.getConfig();
- config.cell = {
- className: this.cell.getClassName(),
- config: cellConfig,
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- RNN.className = 'RNN';
- return RNN;
- }(topology_2.Layer));
- exports.RNN = RNN;
- tfjs_core_1.serialization.SerializationMap.register(RNN);
- var RNNCell = (function (_super) {
- __extends(RNNCell, _super);
- function RNNCell() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- RNNCell = __decorate([
- tfjs_core_1.doc({ heading: 'Layers', subheading: 'Classes' })
- ], RNNCell);
- return RNNCell;
- }(topology_2.Layer));
- exports.RNNCell = RNNCell;
- var SimpleRNNCell = (function (_super) {
- __extends(SimpleRNNCell, _super);
- function SimpleRNNCell(config) {
- var _this = _super.call(this, config) || this;
- _this.DEFAULT_ACTIVATION = 'tanh';
- _this.DEFAULT_KERNEL_INITIALIZER = 'glorotNormal';
- _this.DEFAULT_RECURRENT_INITIALIZER = 'orthogonal';
- _this.DEFAULT_BIAS_INITIALIZER = 'zeros';
- _this.units = config.units;
- _this.activation = activations_1.getActivation(config.activation == null ? _this.DEFAULT_ACTIVATION :
- config.activation);
- _this.useBias = config.useBias == null ? true : config.useBias;
- _this.kernelInitializer = initializers_1.getInitializer(config.kernelInitializer || _this.DEFAULT_KERNEL_INITIALIZER);
- _this.recurrentInitializer = initializers_1.getInitializer(config.recurrentInitializer || _this.DEFAULT_RECURRENT_INITIALIZER);
- _this.biasInitializer =
- initializers_1.getInitializer(config.biasInitializer || _this.DEFAULT_BIAS_INITIALIZER);
- _this.kernelRegularizer = regularizers_1.getRegularizer(config.kernelRegularizer);
- _this.recurrentRegularizer = regularizers_1.getRegularizer(config.recurrentRegularizer);
- _this.biasRegularizer = regularizers_1.getRegularizer(config.biasRegularizer);
- _this.kernelConstraint = constraints_1.getConstraint(config.kernelConstraint);
- _this.recurrentConstraint = constraints_1.getConstraint(config.recurrentConstraint);
- _this.biasConstraint = constraints_1.getConstraint(config.biasConstraint);
- _this.dropout = math_utils.min([1, math_utils.max([0, config.dropout == null ? 0 : config.dropout])]);
- _this.recurrentDropout = math_utils.min([
- 1,
- math_utils.max([0, config.recurrentDropout == null ? 0 : config.recurrentDropout])
- ]);
- _this.stateSize = _this.units;
- return _this;
- }
- SimpleRNNCell.prototype.build = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- this.kernel = this.addWeight('kernel', [inputShape[inputShape.length - 1], this.units], null, this.kernelInitializer, this.kernelRegularizer, true, this.kernelConstraint);
- this.recurrentKernel = this.addWeight('recurrent_kernel', [this.units, this.units], null, this.recurrentInitializer, this.recurrentRegularizer, true, this.recurrentConstraint);
- if (this.useBias) {
- this.bias = this.addWeight('bias', [this.units], null, this.biasInitializer, this.biasRegularizer, true, this.biasConstraint);
- }
- else {
- this.bias = null;
- }
- this.built = true;
- };
- SimpleRNNCell.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- inputs = inputs;
- if (inputs.length !== 2) {
- throw new errors_1.ValueError("SimpleRNNCell expects 2 input Tensors, got " + inputs.length + ".");
- }
- var prevOutput = inputs[1];
- inputs = inputs[0];
- if (_this.dropout !== 0 || _this.recurrentDropout !== 0) {
- throw new errors_1.NotImplementedError('Dropout is not implemented for SimpleRNNCell yet');
- }
- var h = K.dot(inputs, _this.kernel.read());
- if (_this.bias != null) {
- h = K.biasAdd(h, _this.bias.read());
- }
- var output = tfc.add(h, K.dot(prevOutput, _this.recurrentKernel.read()));
- if (_this.activation != null) {
- output = _this.activation.apply(output);
- }
- return [output, output];
- });
- };
- SimpleRNNCell.prototype.getConfig = function () {
- var config = {
- units: this.units,
- activation: activations_1.serializeActivation(this.activation),
- useBias: this.useBias,
- kernelInitializer: initializers_1.serializeInitializer(this.kernelInitializer),
- recurrentInitializer: initializers_1.serializeInitializer(this.recurrentInitializer),
- biasInitializer: initializers_1.serializeInitializer(this.biasInitializer),
- kernelRegularizer: regularizers_1.serializeRegularizer(this.kernelRegularizer),
- recurrentRegularizer: regularizers_1.serializeRegularizer(this.recurrentRegularizer),
- biasRegularizer: regularizers_1.serializeRegularizer(this.biasRegularizer),
- activityRegularizer: regularizers_1.serializeRegularizer(this.activityRegularizer),
- kernelConstraint: constraints_1.serializeConstraint(this.kernelConstraint),
- recurrentConstraint: constraints_1.serializeConstraint(this.recurrentConstraint),
- biasConstraint: constraints_1.serializeConstraint(this.biasConstraint),
- dropout: this.dropout,
- recurrentDropout: this.recurrentDropout,
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- SimpleRNNCell.className = 'SimpleRNNCell';
- return SimpleRNNCell;
- }(RNNCell));
- exports.SimpleRNNCell = SimpleRNNCell;
- tfjs_core_1.serialization.SerializationMap.register(SimpleRNNCell);
- var SimpleRNN = (function (_super) {
- __extends(SimpleRNN, _super);
- function SimpleRNN(config) {
- var _this = this;
- config.cell = new SimpleRNNCell(config);
- _this = _super.call(this, config) || this;
- return _this;
- }
- SimpleRNN.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- var mask = kwargs == null ? null : kwargs['mask'];
- var training = kwargs == null ? null : kwargs['training'];
- var initialState = kwargs == null ? null : kwargs['initialState'];
- return _super.prototype.call.call(_this, inputs, { mask: mask, training: training, initialState: initialState });
- });
- };
- Object.defineProperty(SimpleRNN.prototype, "units", {
- get: function () {
- return this.cell.units;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SimpleRNN.prototype, "activation", {
- get: function () {
- return this.cell.activation;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SimpleRNN.prototype, "useBias", {
- get: function () {
- return this.cell.useBias;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SimpleRNN.prototype, "kernelInitializer", {
- get: function () {
- return this.cell.kernelInitializer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SimpleRNN.prototype, "recurrentInitializer", {
- get: function () {
- return this.cell.recurrentInitializer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SimpleRNN.prototype, "biasInitializer", {
- get: function () {
- return this.cell.biasInitializer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SimpleRNN.prototype, "kernelRegularizer", {
- get: function () {
- return this.cell.kernelRegularizer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SimpleRNN.prototype, "recurrentRegularizer", {
- get: function () {
- return this.cell.recurrentRegularizer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SimpleRNN.prototype, "biasRegularizer", {
- get: function () {
- return this.cell.biasRegularizer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SimpleRNN.prototype, "kernelConstraint", {
- get: function () {
- return this.cell.kernelConstraint;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SimpleRNN.prototype, "recurrentConstraint", {
- get: function () {
- return this.cell.recurrentConstraint;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SimpleRNN.prototype, "biasConstraint", {
- get: function () {
- return this.cell.biasConstraint;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SimpleRNN.prototype, "dropout", {
- get: function () {
- return this.cell.dropout;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SimpleRNN.prototype, "recurrentDropout", {
- get: function () {
- return this.cell.recurrentDropout;
- },
- enumerable: true,
- configurable: true
- });
- SimpleRNN.prototype.getConfig = function () {
- var config = {
- units: this.units,
- activation: activations_1.serializeActivation(this.activation),
- useBias: this.useBias,
- kernelInitializer: initializers_1.serializeInitializer(this.kernelInitializer),
- recurrentInitializer: initializers_1.serializeInitializer(this.recurrentInitializer),
- biasInitializer: initializers_1.serializeInitializer(this.biasInitializer),
- kernelRegularizer: regularizers_1.serializeRegularizer(this.kernelRegularizer),
- recurrentRegularizer: regularizers_1.serializeRegularizer(this.recurrentRegularizer),
- biasRegularizer: regularizers_1.serializeRegularizer(this.biasRegularizer),
- activityRegularizer: regularizers_1.serializeRegularizer(this.activityRegularizer),
- kernelConstraint: constraints_1.serializeConstraint(this.kernelConstraint),
- recurrentConstraint: constraints_1.serializeConstraint(this.recurrentConstraint),
- biasConstraint: constraints_1.serializeConstraint(this.biasConstraint),
- dropout: this.dropout,
- recurrentDropout: this.recurrentDropout,
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- delete baseConfig['cell'];
- Object.assign(config, baseConfig);
- return config;
- };
- SimpleRNN.className = 'SimpleRNN';
- return SimpleRNN;
- }(RNN));
- exports.SimpleRNN = SimpleRNN;
- tfjs_core_1.serialization.SerializationMap.register(SimpleRNN);
- var GRUCell = (function (_super) {
- __extends(GRUCell, _super);
- function GRUCell(config) {
- var _this = _super.call(this, config) || this;
- _this.DEFAULT_ACTIVATION = 'tanh';
- _this.DEFAULT_RECURRENT_ACTIVATION = 'hardSigmoid';
- _this.DEFAULT_KERNEL_INITIALIZER = 'glorotNormal';
- _this.DEFAULT_RECURRENT_INITIALIZER = 'orthogonal';
- _this.DEFAULT_BIAS_INITIALIZER = 'zeros';
- _this.units = config.units;
- _this.activation = activations_1.getActivation(config.activation === undefined ? _this.DEFAULT_ACTIVATION :
- config.activation);
- _this.recurrentActivation = activations_1.getActivation(config.recurrentActivation === undefined ?
- _this.DEFAULT_RECURRENT_ACTIVATION :
- config.recurrentActivation);
- _this.useBias = config.useBias == null ? true : config.useBias;
- _this.kernelInitializer = initializers_1.getInitializer(config.kernelInitializer || _this.DEFAULT_KERNEL_INITIALIZER);
- _this.recurrentInitializer = initializers_1.getInitializer(config.recurrentInitializer || _this.DEFAULT_RECURRENT_INITIALIZER);
- _this.biasInitializer =
- initializers_1.getInitializer(config.biasInitializer || _this.DEFAULT_BIAS_INITIALIZER);
- _this.kernelRegularizer = regularizers_1.getRegularizer(config.kernelRegularizer);
- _this.recurrentRegularizer = regularizers_1.getRegularizer(config.recurrentRegularizer);
- _this.biasRegularizer = regularizers_1.getRegularizer(config.biasRegularizer);
- _this.kernelConstraint = constraints_1.getConstraint(config.kernelConstraint);
- _this.recurrentConstraint = constraints_1.getConstraint(config.recurrentConstraint);
- _this.biasConstraint = constraints_1.getConstraint(config.biasConstraint);
- _this.dropout = math_utils.min([1, math_utils.max([0, config.dropout == null ? 0 : config.dropout])]);
- _this.recurrentDropout = math_utils.min([
- 1,
- math_utils.max([0, config.recurrentDropout == null ? 0 : config.recurrentDropout])
- ]);
- _this.implementation = config.implementation;
- _this.stateSize = _this.units;
- return _this;
- }
- GRUCell.prototype.build = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- var inputDim = inputShape[inputShape.length - 1];
- this.kernel = this.addWeight('kernel', [inputDim, this.units * 3], null, this.kernelInitializer, this.kernelRegularizer, true, this.kernelConstraint);
- this.recurrentKernel = this.addWeight('recurrent_kernel', [this.units, this.units * 3], null, this.recurrentInitializer, this.recurrentRegularizer, true, this.recurrentConstraint);
- if (this.useBias) {
- this.bias = this.addWeight('bias', [this.units * 3], null, this.biasInitializer, this.biasRegularizer, true, this.biasConstraint);
- }
- else {
- this.bias = null;
- }
- this.built = true;
- };
- GRUCell.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- if (_this.dropout !== 0 || _this.recurrentDropout !== 0) {
- throw new errors_1.NotImplementedError('Dropout is not implemented for GRUCell yet');
- }
- inputs = inputs;
- if (inputs.length !== 2) {
- throw new errors_1.ValueError("GRUCell expects 2 input Tensors (inputs, h, c), got " +
- (inputs.length + "."));
- }
- var hTMinus1 = inputs[1];
- inputs = inputs[0];
- var z;
- var r;
- var hh;
- if (_this.implementation === 1) {
- var kernelZ = K.sliceAlongLastAxis(_this.kernel.read(), 0, _this.units);
- var kernelR = K.sliceAlongLastAxis(_this.kernel.read(), _this.units, _this.units);
- var kernelH = K.sliceAlongLastAxis(_this.kernel.read(), _this.units * 2, _this.units);
- var recurrentKernelZ = K.sliceAlongLastAxis(_this.recurrentKernel.read(), 0, _this.units);
- var recurrentKernelR = K.sliceAlongLastAxis(_this.recurrentKernel.read(), _this.units, _this.units);
- var recurrentKernelH = K.sliceAlongLastAxis(_this.recurrentKernel.read(), _this.units * 2, _this.units);
- var inputsZ = inputs;
- var inputsR = inputs;
- var inputsH = inputs;
- var xZ = K.dot(inputsZ, kernelZ);
- var xR = K.dot(inputsR, kernelR);
- var xH = K.dot(inputsH, kernelH);
- if (_this.useBias) {
- var biasZ = K.sliceAlongFirstAxis(_this.bias.read(), 0, _this.units);
- var biasR = K.sliceAlongFirstAxis(_this.bias.read(), _this.units, _this.units);
- var biasH = K.sliceAlongFirstAxis(_this.bias.read(), _this.units * 2, _this.units);
- xZ = K.biasAdd(xZ, biasZ);
- xR = K.biasAdd(xR, biasR);
- xH = K.biasAdd(xH, biasH);
- }
- var hTMinus1Z = hTMinus1;
- var hTMinus1R = hTMinus1;
- var hTMinus1H = hTMinus1;
- z = _this.recurrentActivation.apply(tfc.add(xZ, K.dot(hTMinus1Z, recurrentKernelZ)));
- r = _this.recurrentActivation.apply(tfc.add(xR, K.dot(hTMinus1R, recurrentKernelR)));
- hh = _this.activation.apply(tfc.add(xH, K.dot(tfc.mul(r, hTMinus1H), recurrentKernelH)));
- }
- else {
- var matrixX = K.dot(inputs, _this.kernel.read());
- if (_this.useBias) {
- matrixX = K.biasAdd(matrixX, _this.bias.read());
- }
- var matrixInner = K.dot(hTMinus1, K.sliceAlongLastAxis(_this.recurrentKernel.read(), 0, 2 * _this.units));
- var xZ = K.sliceAlongLastAxis(matrixX, 0, _this.units);
- var xR = K.sliceAlongLastAxis(matrixX, _this.units, _this.units);
- var recurrentZ = K.sliceAlongLastAxis(matrixInner, 0, _this.units);
- var recurrentR = K.sliceAlongLastAxis(matrixInner, _this.units, _this.units);
- z = _this.recurrentActivation.apply(tfc.add(xZ, recurrentZ));
- r = _this.recurrentActivation.apply(tfc.add(xR, recurrentR));
- var xH = K.sliceAlongLastAxis(matrixX, 2 * _this.units, _this.units);
- var recurrentH = K.dot(tfc.mul(r, hTMinus1), K.sliceAlongLastAxis(_this.recurrentKernel.read(), 2 * _this.units, _this.units));
- hh = _this.activation.apply(tfc.add(xH, recurrentH));
- }
- var h = tfc.add(tfc.mul(z, hTMinus1), tfc.mul(K.scalarPlusArray(K.getScalar(1), tfc.neg(z)), hh));
- return [h, h];
- });
- };
- GRUCell.prototype.getConfig = function () {
- var config = {
- units: this.units,
- activation: activations_1.serializeActivation(this.activation),
- recurrentActivation: activations_1.serializeActivation(this.recurrentActivation),
- useBias: this.useBias,
- kernelInitializer: initializers_1.serializeInitializer(this.kernelInitializer),
- recurrentInitializer: initializers_1.serializeInitializer(this.recurrentInitializer),
- biasInitializer: initializers_1.serializeInitializer(this.biasInitializer),
- kernelRegularizer: regularizers_1.serializeRegularizer(this.kernelRegularizer),
- recurrentRegularizer: regularizers_1.serializeRegularizer(this.recurrentRegularizer),
- biasRegularizer: regularizers_1.serializeRegularizer(this.biasRegularizer),
- activityRegularizer: regularizers_1.serializeRegularizer(this.activityRegularizer),
- kernelConstraint: constraints_1.serializeConstraint(this.kernelConstraint),
- recurrentConstraint: constraints_1.serializeConstraint(this.recurrentConstraint),
- biasConstraint: constraints_1.serializeConstraint(this.biasConstraint),
- dropout: this.dropout,
- recurrentDropout: this.recurrentDropout,
- implementation: this.implementation,
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- GRUCell.className = 'GRUCell';
- return GRUCell;
- }(RNNCell));
- exports.GRUCell = GRUCell;
- tfjs_core_1.serialization.SerializationMap.register(GRUCell);
- var GRU = (function (_super) {
- __extends(GRU, _super);
- function GRU(config) {
- var _this = this;
- if (config.implementation === 0) {
- console.warn('`implementation=0` has been deprecated, and now defaults to ' +
- '`implementation=1`. Please update your layer call.');
- }
- config.cell = new GRUCell(config);
- _this = _super.call(this, config) || this;
- return _this;
- }
- GRU.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- var mask = kwargs == null ? null : kwargs['mask'];
- var training = kwargs == null ? null : kwargs['training'];
- var initialState = kwargs == null ? null : kwargs['initialState'];
- return _super.prototype.call.call(_this, inputs, { mask: mask, training: training, initialState: initialState });
- });
- };
- Object.defineProperty(GRU.prototype, "units", {
- get: function () {
- return this.cell.units;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "activation", {
- get: function () {
- return this.cell.activation;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "recurrentActivation", {
- get: function () {
- return this.cell.recurrentActivation;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "useBias", {
- get: function () {
- return this.cell.useBias;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "kernelInitializer", {
- get: function () {
- return this.cell.kernelInitializer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "recurrentInitializer", {
- get: function () {
- return this.cell.recurrentInitializer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "biasInitializer", {
- get: function () {
- return this.cell.biasInitializer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "kernelRegularizer", {
- get: function () {
- return this.cell.kernelRegularizer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "recurrentRegularizer", {
- get: function () {
- return this.cell.recurrentRegularizer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "biasRegularizer", {
- get: function () {
- return this.cell.biasRegularizer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "kernelConstraint", {
- get: function () {
- return this.cell.kernelConstraint;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "recurrentConstraint", {
- get: function () {
- return this.cell.recurrentConstraint;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "biasConstraint", {
- get: function () {
- return this.cell.biasConstraint;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "dropout", {
- get: function () {
- return this.cell.dropout;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "recurrentDropout", {
- get: function () {
- return this.cell.recurrentDropout;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GRU.prototype, "implementation", {
- get: function () {
- return this.cell.implementation;
- },
- enumerable: true,
- configurable: true
- });
- GRU.prototype.getConfig = function () {
- var config = {
- units: this.units,
- activation: activations_1.serializeActivation(this.activation),
- recurrentActivation: activations_1.serializeActivation(this.recurrentActivation),
- useBias: this.useBias,
- kernelInitializer: initializers_1.serializeInitializer(this.kernelInitializer),
- recurrentInitializer: initializers_1.serializeInitializer(this.recurrentInitializer),
- biasInitializer: initializers_1.serializeInitializer(this.biasInitializer),
- kernelRegularizer: regularizers_1.serializeRegularizer(this.kernelRegularizer),
- recurrentRegularizer: regularizers_1.serializeRegularizer(this.recurrentRegularizer),
- biasRegularizer: regularizers_1.serializeRegularizer(this.biasRegularizer),
- activityRegularizer: regularizers_1.serializeRegularizer(this.activityRegularizer),
- kernelConstraint: constraints_1.serializeConstraint(this.kernelConstraint),
- recurrentConstraint: constraints_1.serializeConstraint(this.recurrentConstraint),
- biasConstraint: constraints_1.serializeConstraint(this.biasConstraint),
- dropout: this.dropout,
- recurrentDropout: this.recurrentDropout,
- implementation: this.implementation,
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- delete baseConfig['cell'];
- Object.assign(config, baseConfig);
- return config;
- };
- GRU.fromConfig = function (cls, config) {
- if (config['implmentation'] === 0) {
- config['implementation'] = 1;
- }
- return new cls(config);
- };
- GRU.className = 'GRU';
- return GRU;
- }(RNN));
- exports.GRU = GRU;
- tfjs_core_1.serialization.SerializationMap.register(GRU);
- var LSTMCell = (function (_super) {
- __extends(LSTMCell, _super);
- function LSTMCell(config) {
- var _this = _super.call(this, config) || this;
- _this.DEFAULT_ACTIVATION = 'tanh';
- _this.DEFAULT_RECURRENT_ACTIVATION = 'hardSigmoid';
- _this.DEFAULT_KERNEL_INITIALIZER = 'glorotNormal';
- _this.DEFAULT_RECURRENT_INITIALIZER = 'orthogonal';
- _this.DEFAULT_BIAS_INITIALIZER = 'zeros';
- _this.units = config.units;
- _this.activation = activations_1.getActivation(config.activation === undefined ? _this.DEFAULT_ACTIVATION :
- config.activation);
- _this.recurrentActivation = activations_1.getActivation(config.recurrentActivation === undefined ?
- _this.DEFAULT_RECURRENT_ACTIVATION :
- config.recurrentActivation);
- _this.useBias = config.useBias == null ? true : config.useBias;
- _this.kernelInitializer = initializers_1.getInitializer(config.kernelInitializer || _this.DEFAULT_KERNEL_INITIALIZER);
- _this.recurrentInitializer = initializers_1.getInitializer(config.recurrentInitializer || _this.DEFAULT_RECURRENT_INITIALIZER);
- _this.biasInitializer =
- initializers_1.getInitializer(config.biasInitializer || _this.DEFAULT_BIAS_INITIALIZER);
- _this.unitForgetBias = config.unitForgetBias;
- _this.kernelRegularizer = regularizers_1.getRegularizer(config.kernelRegularizer);
- _this.recurrentRegularizer = regularizers_1.getRegularizer(config.recurrentRegularizer);
- _this.biasRegularizer = regularizers_1.getRegularizer(config.biasRegularizer);
- _this.kernelConstraint = constraints_1.getConstraint(config.kernelConstraint);
- _this.recurrentConstraint = constraints_1.getConstraint(config.recurrentConstraint);
- _this.biasConstraint = constraints_1.getConstraint(config.biasConstraint);
- _this.dropout = math_utils.min([1, math_utils.max([0, config.dropout == null ? 0 : config.dropout])]);
- _this.recurrentDropout = math_utils.min([
- 1,
- math_utils.max([0, config.recurrentDropout == null ? 0 : config.recurrentDropout])
- ]);
- _this.implementation = config.implementation;
- _this.stateSize = [_this.units, _this.units];
- return _this;
- }
- LSTMCell.prototype.build = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- var inputDim = inputShape[inputShape.length - 1];
- this.kernel = this.addWeight('kernel', [inputDim, this.units * 4], null, this.kernelInitializer, this.kernelRegularizer, true, this.kernelConstraint);
- this.recurrentKernel = this.addWeight('recurrent_kernel', [this.units, this.units * 4], null, this.recurrentInitializer, this.recurrentRegularizer, true, this.recurrentConstraint);
- var biasInitializer;
- if (this.useBias) {
- if (this.unitForgetBias) {
- var capturedBiasInit_1 = this.biasInitializer;
- var capturedUnits_1 = this.units;
- biasInitializer = new (_a = (function (_super) {
- __extends(CustomInit, _super);
- function CustomInit() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- CustomInit.prototype.apply = function (shape, dtype) {
- var bI = capturedBiasInit_1.apply([capturedUnits_1]);
- var bF = (new initializers_1.Ones()).apply([capturedUnits_1]);
- var bCAndH = capturedBiasInit_1.apply([capturedUnits_1 * 2]);
- return K.concatAlongFirstAxis(K.concatAlongFirstAxis(bI, bF), bCAndH);
- };
- return CustomInit;
- }(initializers_1.Initializer)),
- _a.className = 'CustomInit',
- _a)();
- }
- else {
- biasInitializer = this.biasInitializer;
- }
- this.bias = this.addWeight('bias', [this.units * 4], null, biasInitializer, this.biasRegularizer, true, this.biasConstraint);
- }
- else {
- this.bias = null;
- }
- this.built = true;
- var _a;
- };
- LSTMCell.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- if (_this.dropout !== 0 || _this.recurrentDropout !== 0) {
- throw new errors_1.NotImplementedError('Dropout is not implemented for LSTMCell yet');
- }
- inputs = inputs;
- if (inputs.length !== 3) {
- throw new errors_1.ValueError("LSTMCell expects 3 input Tensors (inputs, h, c), got " +
- (inputs.length + "."));
- }
- var hTMinus1 = inputs[1];
- var cTMinus1 = inputs[2];
- inputs = inputs[0];
- var i;
- var f;
- var c;
- var o;
- if (_this.implementation === 1) {
- var kernelI = K.sliceAlongLastAxis(_this.kernel.read(), 0, _this.units);
- var kernelF = K.sliceAlongLastAxis(_this.kernel.read(), _this.units, _this.units);
- var kernelC = K.sliceAlongLastAxis(_this.kernel.read(), _this.units * 2, _this.units);
- var kernelO = K.sliceAlongLastAxis(_this.kernel.read(), _this.units * 3, _this.units);
- var recurrentKernelI = K.sliceAlongLastAxis(_this.recurrentKernel.read(), 0, _this.units);
- var recurrentKernelF = K.sliceAlongLastAxis(_this.recurrentKernel.read(), _this.units, _this.units);
- var recurrentKernelC = K.sliceAlongLastAxis(_this.recurrentKernel.read(), _this.units * 2, _this.units);
- var recurrentKernelO = K.sliceAlongLastAxis(_this.recurrentKernel.read(), _this.units * 3, _this.units);
- var inputsI = inputs;
- var inputsF = inputs;
- var inputsC = inputs;
- var inputsO = inputs;
- var xI = K.dot(inputsI, kernelI);
- var xF = K.dot(inputsF, kernelF);
- var xC = K.dot(inputsC, kernelC);
- var xO = K.dot(inputsO, kernelO);
- if (_this.useBias) {
- var biasI = K.sliceAlongFirstAxis(_this.bias.read(), 0, _this.units);
- var biasF = K.sliceAlongFirstAxis(_this.bias.read(), _this.units, _this.units);
- var biasC = K.sliceAlongFirstAxis(_this.bias.read(), _this.units * 2, _this.units);
- var biasO = K.sliceAlongFirstAxis(_this.bias.read(), _this.units * 3, _this.units);
- xI = K.biasAdd(xI, biasI);
- xF = K.biasAdd(xF, biasF);
- xC = K.biasAdd(xC, biasC);
- xO = K.biasAdd(xO, biasO);
- }
- var hTMinus1I = hTMinus1;
- var hTMinus1F = hTMinus1;
- var hTMinus1C = hTMinus1;
- var hTMinus1O = hTMinus1;
- i = _this.recurrentActivation.apply(tfc.add(xI, K.dot(hTMinus1I, recurrentKernelI)));
- f = _this.recurrentActivation.apply(tfc.add(xF, K.dot(hTMinus1F, recurrentKernelF)));
- c = tfc.add(tfc.mul(f, cTMinus1), tfc.mul(i, _this.activation.apply(tfc.add(xC, K.dot(hTMinus1C, recurrentKernelC)))));
- o = _this.recurrentActivation.apply(tfc.add(xO, K.dot(hTMinus1O, recurrentKernelO)));
- }
- else {
- var z = K.dot(inputs, _this.kernel.read());
- z = tfc.add(z, K.dot(hTMinus1, _this.recurrentKernel.read()));
- if (_this.useBias) {
- z = K.biasAdd(z, _this.bias.read());
- }
- var z0 = K.sliceAlongLastAxis(z, 0, _this.units);
- var z1 = K.sliceAlongLastAxis(z, _this.units, _this.units);
- var z2 = K.sliceAlongLastAxis(z, _this.units * 2, _this.units);
- var z3 = K.sliceAlongLastAxis(z, _this.units * 3, _this.units);
- i = _this.recurrentActivation.apply(z0);
- f = _this.recurrentActivation.apply(z1);
- c = tfc.add(tfc.mul(f, cTMinus1), tfc.mul(i, _this.activation.apply(z2)));
- o = _this.recurrentActivation.apply(z3);
- }
- var h = tfc.mul(o, _this.activation.apply(c));
- return [h, h, c];
- });
- };
- LSTMCell.prototype.getConfig = function () {
- var config = {
- units: this.units,
- activation: activations_1.serializeActivation(this.activation),
- recurrentActivation: activations_1.serializeActivation(this.recurrentActivation),
- useBias: this.useBias,
- kernelInitializer: initializers_1.serializeInitializer(this.kernelInitializer),
- recurrentInitializer: initializers_1.serializeInitializer(this.recurrentInitializer),
- biasInitializer: initializers_1.serializeInitializer(this.biasInitializer),
- unitForgetBias: this.unitForgetBias,
- kernelRegularizer: regularizers_1.serializeRegularizer(this.kernelRegularizer),
- recurrentRegularizer: regularizers_1.serializeRegularizer(this.recurrentRegularizer),
- biasRegularizer: regularizers_1.serializeRegularizer(this.biasRegularizer),
- activityRegularizer: regularizers_1.serializeRegularizer(this.activityRegularizer),
- kernelConstraint: constraints_1.serializeConstraint(this.kernelConstraint),
- recurrentConstraint: constraints_1.serializeConstraint(this.recurrentConstraint),
- biasConstraint: constraints_1.serializeConstraint(this.biasConstraint),
- dropout: this.dropout,
- recurrentDropout: this.recurrentDropout,
- implementation: this.implementation,
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- LSTMCell.className = 'LSTMCell';
- return LSTMCell;
- }(RNNCell));
- exports.LSTMCell = LSTMCell;
- tfjs_core_1.serialization.SerializationMap.register(LSTMCell);
- var LSTM = (function (_super) {
- __extends(LSTM, _super);
- function LSTM(config) {
- var _this = this;
- if (config.implementation === 0) {
- console.warn('`implementation=0` has been deprecated, and now defaults to ' +
- '`implementation=1`. Please update your layer call.');
- }
- config.cell = new LSTMCell(config);
- _this = _super.call(this, config) || this;
- return _this;
- }
- LSTM.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- var mask = kwargs == null ? null : kwargs['mask'];
- var training = kwargs == null ? null : kwargs['training'];
- var initialState = kwargs == null ? null : kwargs['initialState'];
- return _super.prototype.call.call(_this, inputs, { mask: mask, training: training, initialState: initialState });
- });
- };
- Object.defineProperty(LSTM.prototype, "units", {
- get: function () {
- return this.cell.units;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "activation", {
- get: function () {
- return this.cell.activation;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "recurrentActivation", {
- get: function () {
- return this.cell.recurrentActivation;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "useBias", {
- get: function () {
- return this.cell.useBias;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "kernelInitializer", {
- get: function () {
- return this.cell.kernelInitializer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "recurrentInitializer", {
- get: function () {
- return this.cell.recurrentInitializer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "biasInitializer", {
- get: function () {
- return this.cell.biasInitializer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "unitForgetBias", {
- get: function () {
- return this.cell.unitForgetBias;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "kernelRegularizer", {
- get: function () {
- return this.cell.kernelRegularizer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "recurrentRegularizer", {
- get: function () {
- return this.cell.recurrentRegularizer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "biasRegularizer", {
- get: function () {
- return this.cell.biasRegularizer;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "kernelConstraint", {
- get: function () {
- return this.cell.kernelConstraint;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "recurrentConstraint", {
- get: function () {
- return this.cell.recurrentConstraint;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "biasConstraint", {
- get: function () {
- return this.cell.biasConstraint;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "dropout", {
- get: function () {
- return this.cell.dropout;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "recurrentDropout", {
- get: function () {
- return this.cell.recurrentDropout;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(LSTM.prototype, "implementation", {
- get: function () {
- return this.cell.implementation;
- },
- enumerable: true,
- configurable: true
- });
- LSTM.prototype.getConfig = function () {
- var config = {
- units: this.units,
- activation: activations_1.serializeActivation(this.activation),
- recurrentActivation: activations_1.serializeActivation(this.recurrentActivation),
- useBias: this.useBias,
- kernelInitializer: initializers_1.serializeInitializer(this.kernelInitializer),
- recurrentInitializer: initializers_1.serializeInitializer(this.recurrentInitializer),
- biasInitializer: initializers_1.serializeInitializer(this.biasInitializer),
- unitForgetBias: this.unitForgetBias,
- kernelRegularizer: regularizers_1.serializeRegularizer(this.kernelRegularizer),
- recurrentRegularizer: regularizers_1.serializeRegularizer(this.recurrentRegularizer),
- biasRegularizer: regularizers_1.serializeRegularizer(this.biasRegularizer),
- activityRegularizer: regularizers_1.serializeRegularizer(this.activityRegularizer),
- kernelConstraint: constraints_1.serializeConstraint(this.kernelConstraint),
- recurrentConstraint: constraints_1.serializeConstraint(this.recurrentConstraint),
- biasConstraint: constraints_1.serializeConstraint(this.biasConstraint),
- dropout: this.dropout,
- recurrentDropout: this.recurrentDropout,
- implementation: this.implementation,
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- delete baseConfig['cell'];
- Object.assign(config, baseConfig);
- return config;
- };
- LSTM.fromConfig = function (cls, config) {
- if (config['implmentation'] === 0) {
- config['implementation'] = 1;
- }
- return new cls(config);
- };
- LSTM.className = 'LSTM';
- return LSTM;
- }(RNN));
- exports.LSTM = LSTM;
- tfjs_core_1.serialization.SerializationMap.register(LSTM);
- var StackedRNNCells = (function (_super) {
- __extends(StackedRNNCells, _super);
- function StackedRNNCells(config) {
- var _this = _super.call(this, config) || this;
- _this.cells = config.cells;
- return _this;
- }
- Object.defineProperty(StackedRNNCells.prototype, "stateSize", {
- get: function () {
- var stateSize = [];
- for (var _i = 0, _a = this.cells.slice().reverse(); _i < _a.length; _i++) {
- var cell = _a[_i];
- if (Array.isArray(cell.stateSize)) {
- stateSize.push.apply(stateSize, cell.stateSize);
- }
- else {
- stateSize.push(cell.stateSize);
- }
- }
- return stateSize;
- },
- enumerable: true,
- configurable: true
- });
- StackedRNNCells.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- inputs = inputs;
- var states = inputs.slice(1);
- var nestedStates = [];
- for (var _i = 0, _a = _this.cells.slice().reverse(); _i < _a.length; _i++) {
- var cell = _a[_i];
- if (Array.isArray(cell.stateSize)) {
- nestedStates.push(states.splice(0, cell.stateSize.length));
- }
- else {
- nestedStates.push(states.splice(0, 1));
- }
- }
- nestedStates.reverse();
- var newNestedStates = [];
- var callInputs;
- for (var i = 0; i < _this.cells.length; ++i) {
- var cell = _this.cells[i];
- states = nestedStates[i];
- if (i === 0) {
- callInputs = [inputs[0]].concat(states);
- }
- else {
- callInputs = [callInputs[0]].concat(states);
- }
- callInputs = cell.call(callInputs, kwargs);
- newNestedStates.push(callInputs.slice(1));
- }
- states = [];
- for (var _b = 0, _c = newNestedStates.slice().reverse(); _b < _c.length; _b++) {
- var cellStates = _c[_b];
- states.push.apply(states, cellStates);
- }
- return [callInputs[0]].concat(states);
- });
- };
- StackedRNNCells.prototype.build = function (inputShape) {
- if (generic_utils.isArrayOfShapes(inputShape)) {
- inputShape = inputShape[0];
- }
- inputShape = inputShape;
- var outputDim;
- for (var _i = 0, _a = this.cells; _i < _a.length; _i++) {
- var cell = _a[_i];
- cell.build(inputShape);
- if (Array.isArray(cell.stateSize)) {
- outputDim = cell.stateSize[0];
- }
- else {
- outputDim = cell.stateSize;
- }
- inputShape = [inputShape[0], outputDim];
- }
- this.built = true;
- };
- StackedRNNCells.prototype.getConfig = function () {
- var cellConfigs = [];
- for (var _i = 0, _a = this.cells; _i < _a.length; _i++) {
- var cell = _a[_i];
- cellConfigs.push({
- 'className': this.getClassName(),
- 'config': cell.getConfig(),
- });
- }
- var config = { 'cells': cellConfigs };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- StackedRNNCells.fromConfig = function (cls, config, customObjects) {
- if (customObjects === void 0) { customObjects = {}; }
- var cells = [];
- for (var _i = 0, _a = config['cells']; _i < _a.length; _i++) {
- var cellConfig = _a[_i];
- cells.push(serialization_1.deserialize(cellConfig, customObjects));
- }
- return new cls({ cells: cells });
- };
- Object.defineProperty(StackedRNNCells.prototype, "trainableWeights", {
- get: function () {
- if (!this.trainable) {
- return [];
- }
- var weights = [];
- for (var _i = 0, _a = this.cells; _i < _a.length; _i++) {
- var cell = _a[_i];
- weights.push.apply(weights, cell.trainableWeights);
- }
- return weights;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(StackedRNNCells.prototype, "nonTrainableWeights", {
- get: function () {
- var weights = [];
- for (var _i = 0, _a = this.cells; _i < _a.length; _i++) {
- var cell = _a[_i];
- weights.push.apply(weights, cell.nonTrainableWeights);
- }
- if (!this.trainable) {
- var trainableWeights = [];
- for (var _b = 0, _c = this.cells; _b < _c.length; _b++) {
- var cell = _c[_b];
- trainableWeights.push.apply(trainableWeights, cell.trainableWeights);
- }
- return trainableWeights.concat(weights);
- }
- return weights;
- },
- enumerable: true,
- configurable: true
- });
- StackedRNNCells.prototype.getWeights = function () {
- var weights = [];
- for (var _i = 0, _a = this.cells; _i < _a.length; _i++) {
- var cell = _a[_i];
- weights.push.apply(weights, cell.weights);
- }
- return variables_1.batchGetValue(weights);
- };
- StackedRNNCells.prototype.setWeights = function (weights) {
- var tuples = [];
- for (var _i = 0, _a = this.cells; _i < _a.length; _i++) {
- var cell = _a[_i];
- var numParams = cell.weights.length;
- var inputWeights = weights.splice(numParams);
- for (var i = 0; i < cell.weights.length; ++i) {
- tuples.push([cell.weights[i], inputWeights[i]]);
- }
- }
- variables_1.batchSetValue(tuples);
- };
- StackedRNNCells.className = 'StackedRNNCells';
- return StackedRNNCells;
- }(RNNCell));
- exports.StackedRNNCells = StackedRNNCells;
- tfjs_core_1.serialization.SerializationMap.register(StackedRNNCells);
- },{"../activations":167,"../backend/tfjs_backend":169,"../constraints":172,"../engine/topology":174,"../errors":176,"../initializers":179,"../regularizers":196,"../types":197,"../utils/generic_utils":199,"../utils/math_utils":201,"../variables":203,"./serialization":190,"@tensorflow/tfjs-core":54}],190:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var generic_utils_1 = require("../utils/generic_utils");
- function deserialize(config, customObjects) {
- if (customObjects === void 0) { customObjects = {}; }
- return generic_utils_1.deserializeKerasObject(config, tfjs_core_1.serialization.SerializationMap.getMap().classNameMap, customObjects, 'layer');
- }
- exports.deserialize = deserialize;
- },{"../utils/generic_utils":199,"@tensorflow/tfjs-core":54}],191:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("../backend/tfjs_backend");
- var topology_1 = require("../engine/topology");
- var errors_1 = require("../errors");
- var generic_utils = require("../utils/generic_utils");
- var recurrent_1 = require("./recurrent");
- var serialization_1 = require("./serialization");
- var Wrapper = (function (_super) {
- __extends(Wrapper, _super);
- function Wrapper(config) {
- var _this = _super.call(this, config) || this;
- _this.layer = config.layer;
- return _this;
- }
- Wrapper.prototype.build = function (inputShape) {
- this.built = true;
- };
- Object.defineProperty(Wrapper.prototype, "trainable", {
- get: function () {
- if (this.layer != null) {
- return this.layer.trainable;
- }
- else {
- return false;
- }
- },
- set: function (value) {
- if (this.layer != null) {
- this.layer.trainable = value;
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Wrapper.prototype, "trainableWeights", {
- get: function () {
- return this.layer.trainableWeights;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Wrapper.prototype, "nonTrainableWeights", {
- get: function () {
- return this.layer.nonTrainableWeights;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Wrapper.prototype, "updates", {
- get: function () {
- return this.layer._updates;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Wrapper.prototype, "losses", {
- get: function () {
- return this.layer.losses;
- },
- enumerable: true,
- configurable: true
- });
- Wrapper.prototype.getWeights = function () {
- return this.layer.getWeights();
- };
- Wrapper.prototype.setWeights = function (weights) {
- this.layer.setWeights(weights);
- };
- Wrapper.prototype.getConfig = function () {
- var config = {
- 'layer': {
- 'className': this.layer.getClassName(),
- 'config': this.layer.getConfig(),
- }
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- Wrapper.fromConfig = function (cls, config, customObjects) {
- if (customObjects === void 0) { customObjects = {}; }
- var layerConfig = config['layer'];
- var layer = serialization_1.deserialize(layerConfig, customObjects);
- delete config['layer'];
- var newConfig = { layer: layer };
- Object.assign(newConfig, config);
- return new cls(newConfig);
- };
- return Wrapper;
- }(topology_1.Layer));
- exports.Wrapper = Wrapper;
- var TimeDistributed = (function (_super) {
- __extends(TimeDistributed, _super);
- function TimeDistributed(config) {
- var _this = _super.call(this, config) || this;
- _this.supportsMasking = true;
- return _this;
- }
- TimeDistributed.prototype.build = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- if (inputShape.length < 3) {
- throw new errors_1.ValueError("TimeDistributed layer expects an input shape >= 3D, but received " +
- ("input shape " + JSON.stringify(inputShape)));
- }
- this.inputSpec = [{ shape: inputShape }];
- var childInputShape = [inputShape[0]].concat(inputShape.slice(2));
- if (!this.layer.built) {
- this.layer.build(childInputShape);
- this.layer.built = true;
- }
- _super.prototype.build.call(this, inputShape);
- };
- TimeDistributed.prototype.computeOutputShape = function (inputShape) {
- inputShape = generic_utils.getExactlyOneShape(inputShape);
- var childInputShape = [inputShape[0]].concat(inputShape.slice(2));
- var childOutputShape = this.layer.computeOutputShape(childInputShape);
- var timesteps = inputShape[1];
- return [childOutputShape[0], timesteps].concat(childOutputShape.slice(1));
- };
- TimeDistributed.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- inputs = generic_utils.getExactlyOneTensor(inputs);
- var step = function (inputs, states) {
- var output = _this.layer.call(inputs, kwargs);
- return [output, []];
- };
- var rnnOutputs = recurrent_1.rnn(step, inputs, [], false, null, null, false, inputs.shape[1]);
- var y = rnnOutputs[1];
- return y;
- });
- };
- TimeDistributed.className = 'TimeDistributed';
- return TimeDistributed;
- }(Wrapper));
- exports.TimeDistributed = TimeDistributed;
- tfjs_core_1.serialization.SerializationMap.register(TimeDistributed);
- exports.VALID_BIDIRECTIONAL_MERGE_MODES = ['sum', 'mul', 'concat', 'ave'];
- function checkBidirectionalMergeMode(value) {
- generic_utils.checkStringTypeUnionValue(exports.VALID_BIDIRECTIONAL_MERGE_MODES, 'BidirectionalMergeMode', value);
- }
- exports.checkBidirectionalMergeMode = checkBidirectionalMergeMode;
- var Bidirectional = (function (_super) {
- __extends(Bidirectional, _super);
- function Bidirectional(config) {
- var _this = _super.call(this, config) || this;
- var layerConfig = config.layer.getConfig();
- _this.forwardLayer =
- serialization_1.deserialize({ className: config.layer.getClassName(), config: layerConfig });
- layerConfig['goBackwards'] =
- layerConfig['goBackwards'] === true ? false : true;
- _this.backwardLayer =
- serialization_1.deserialize({ className: config.layer.getClassName(), config: layerConfig });
- _this.forwardLayer.name = 'forward_' + _this.forwardLayer.name;
- _this.backwardLayer.name = 'backward_' + _this.backwardLayer.name;
- checkBidirectionalMergeMode(config.mergeMode);
- _this.mergeMode = config.mergeMode;
- if (config.weights) {
- throw new errors_1.NotImplementedError('weights support is not implemented for Bidirectional layer yet.');
- }
- _this._stateful = config.layer.stateful;
- _this.returnSequences = config.layer.returnSequences;
- _this.returnState = config.layer.returnState;
- _this.supportsMasking = true;
- _this._trainable = true;
- _this.inputSpec = config.layer.inputSpec;
- return _this;
- }
- Object.defineProperty(Bidirectional.prototype, "trainable", {
- get: function () {
- return this._trainable;
- },
- set: function (value) {
- this._trainable = value;
- if (this.forwardLayer != null) {
- this.forwardLayer.trainable = value;
- }
- if (this.backwardLayer != null) {
- this.backwardLayer.trainable = value;
- }
- },
- enumerable: true,
- configurable: true
- });
- Bidirectional.prototype.getWeights = function () {
- return this.forwardLayer.getWeights().concat(this.backwardLayer.getWeights());
- };
- Bidirectional.prototype.setWeights = function (weights) {
- var numWeights = weights.length;
- var numeightsOver2 = Math.floor(numWeights / 2);
- this.forwardLayer.setWeights(weights.slice(0, numeightsOver2));
- this.backwardLayer.setWeights(weights.slice(numeightsOver2));
- };
- Bidirectional.prototype.computeOutputShape = function (inputShape) {
- var layerShapes = this.forwardLayer.computeOutputShape(inputShape);
- if (!(Array.isArray(layerShapes) && Array.isArray(layerShapes[0]))) {
- layerShapes = [layerShapes];
- }
- layerShapes = layerShapes;
- var outputShape;
- var outputShapes;
- var stateShape;
- if (this.returnState) {
- stateShape = layerShapes.slice(1);
- outputShape = layerShapes[0];
- }
- else {
- outputShape = layerShapes[0];
- }
- outputShape = outputShape;
- if (this.mergeMode === 'concat') {
- outputShape[outputShape.length - 1] *= 2;
- outputShapes = [outputShape];
- }
- else if (this.mergeMode == null) {
- outputShapes = [outputShape, outputShape.slice()];
- }
- else {
- outputShapes = [outputShape];
- }
- if (this.returnState) {
- if (this.mergeMode == null) {
- return outputShapes.concat(stateShape).concat(stateShape.slice());
- }
- return [outputShape].concat(stateShape).concat(stateShape.slice());
- }
- return generic_utils.singletonOrArray(outputShapes);
- };
- Bidirectional.prototype.apply = function (inputs, kwargs) {
- var initialState = null;
- if (kwargs != null) {
- initialState = kwargs['initialState'];
- }
- if (Array.isArray(inputs)) {
- initialState = inputs.slice(1);
- inputs = inputs[0];
- }
- if (initialState == null || initialState.length === 0) {
- var applyOutputs = _super.prototype.apply.call(this, inputs, kwargs);
- return applyOutputs;
- }
- else {
- throw new errors_1.NotImplementedError('The support for initial states is not implemented for ' +
- 'Bidirectional layers yet.');
- }
- };
- Bidirectional.prototype.call = function (inputs, kwargs) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- if (kwargs['mask'] != null) {
- throw new errors_1.NotImplementedError('The support for masking is not implemented for ' +
- 'Bidirectional layers yet.');
- }
- if (kwargs['initialState'] != null) {
- throw new errors_1.NotImplementedError('The support for initial states is not implemented for ' +
- 'Bidirectional layers yet.');
- }
- var y = _this.forwardLayer.call(inputs, kwargs);
- var yRev = _this.backwardLayer.call(inputs, kwargs);
- var states;
- if (_this.returnState) {
- if (Array.isArray(y)) {
- states = y.slice(1).concat(yRev.slice(1));
- }
- else {
- }
- y = y[0];
- yRev = yRev[0];
- }
- if (_this.returnSequences) {
- yRev = tfc.reverse(yRev, 1);
- }
- var output;
- if (_this.mergeMode === 'concat') {
- output = K.concatenate([y, yRev]);
- }
- else if (_this.mergeMode === 'sum') {
- output = tfc.add(y, yRev);
- }
- else if (_this.mergeMode === 'ave') {
- output = K.scalarTimesArray(K.getScalar(0.5), tfc.add(y, yRev));
- }
- else if (_this.mergeMode === 'mul') {
- output = tfc.mul(y, yRev);
- }
- else if (_this.mergeMode == null) {
- output = [y, yRev];
- }
- if (_this.returnState) {
- if (_this.mergeMode == null) {
- return output.concat(states);
- }
- return [output].concat(states);
- }
- return output;
- });
- };
- Bidirectional.prototype.resetStates = function (states) {
- this.forwardLayer.resetStates();
- this.backwardLayer.resetStates();
- };
- Bidirectional.prototype.build = function (inputShape) {
- var _this = this;
- K.nameScope(this.forwardLayer.name, function () {
- _this.forwardLayer.build(inputShape);
- });
- K.nameScope(this.backwardLayer.name, function () {
- _this.backwardLayer.build(inputShape);
- });
- this.built = true;
- };
- Object.defineProperty(Bidirectional.prototype, "trainableWeights", {
- get: function () {
- return this.forwardLayer.trainableWeights.concat(this.backwardLayer.trainableWeights);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Bidirectional.prototype, "nonTrainableWeights", {
- get: function () {
- return this.forwardLayer.nonTrainableWeights.concat(this.backwardLayer.nonTrainableWeights);
- },
- enumerable: true,
- configurable: true
- });
- Bidirectional.prototype.getConfig = function () {
- var config = {
- 'mergeMode': this.mergeMode,
- };
- var baseConfig = _super.prototype.getConfig.call(this);
- Object.assign(config, baseConfig);
- return config;
- };
- Bidirectional.fromConfig = function (cls, config) {
- var rnnLayer = serialization_1.deserialize(config['layer']);
- delete config['layer'];
- if (config['numConstants'] != null) {
- throw new errors_1.NotImplementedError("Deserialization of a Bidirectional layer with numConstants " +
- "present is not supported yet.");
- }
- var newConfig = config;
- newConfig['layer'] = rnnLayer;
- return new cls(newConfig);
- };
- Bidirectional.className = 'Bidirectional';
- return Bidirectional;
- }(Wrapper));
- exports.Bidirectional = Bidirectional;
- tfjs_core_1.serialization.SerializationMap.register(Bidirectional);
- },{"../backend/tfjs_backend":169,"../engine/topology":174,"../errors":176,"../utils/generic_utils":199,"./recurrent":189,"./serialization":190,"@tensorflow/tfjs-core":54}],192:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("./backend/tfjs_backend");
- var errors_1 = require("./errors");
- function l2Normalize(x, axis) {
- return tfjs_core_1.tidy(function () {
- var squareSum = tfc.sum(K.square(x), axis, true);
- var epsilonTensor = K.scalarTimesArray(tfjs_core_1.scalar(K.epsilon()), tfc.onesLike(x));
- var norm = tfc.sqrt(tfc.maximum(squareSum, epsilonTensor));
- return tfc.div(x, norm);
- });
- }
- exports.l2Normalize = l2Normalize;
- function meanSquaredError(yTrue, yPred) {
- return tfjs_core_1.tidy(function () { return tfc.mean(K.square(tfc.sub(yPred, yTrue)), -1); });
- }
- exports.meanSquaredError = meanSquaredError;
- function meanAbsoluteError(yTrue, yPred) {
- return tfjs_core_1.tidy(function () { return tfc.mean(tfc.abs(tfc.sub(yPred, yTrue)), -1); });
- }
- exports.meanAbsoluteError = meanAbsoluteError;
- function meanAbsolutePercentageError(yTrue, yPred) {
- return tfjs_core_1.tidy(function () {
- var diff = tfc.sub(yTrue, yPred);
- var clippedTrue = tfc.clipByValue(tfc.abs(yTrue), K.epsilon(), Number.MAX_VALUE);
- var absResult = tfc.abs(tfc.div(diff, clippedTrue));
- return K.scalarTimesArray(K.getScalar(100.0), tfc.mean(absResult, -1));
- });
- }
- exports.meanAbsolutePercentageError = meanAbsolutePercentageError;
- function meanSquaredLogarithmicError(yTrue, yPred) {
- return tfjs_core_1.tidy(function () {
- var one = K.getScalar(1.0);
- var clippedPred = tfc.clipByValue(yPred, K.epsilon(), Number.MAX_VALUE);
- var firstLog = tfc.log(K.scalarPlusArray(one, clippedPred));
- var clippedTrue = tfc.clipByValue(yTrue, K.epsilon(), Number.MAX_VALUE);
- var secondLog = tfc.log(K.scalarPlusArray(one, clippedTrue));
- return tfc.mean(K.square(tfc.sub(firstLog, secondLog)), -1);
- });
- }
- exports.meanSquaredLogarithmicError = meanSquaredLogarithmicError;
- function squaredHinge(yTrue, yPred) {
- return tfjs_core_1.tidy(function () {
- var zeroTensor = K.getScalar(0.0);
- var one = K.getScalar(1.0);
- var maxResult = tfc.maximum(zeroTensor, tfc.sub(one, tfc.mul(yTrue, yPred)));
- return tfc.mean(K.square(maxResult), -1);
- });
- }
- exports.squaredHinge = squaredHinge;
- function hinge(yTrue, yPred) {
- return tfjs_core_1.tidy(function () {
- var zeroTensor = K.getScalar(0.0);
- var one = K.getScalar(1.0);
- var maxResult = tfc.maximum(zeroTensor, tfc.sub(one, tfc.mul(yTrue, yPred)));
- return tfc.mean(maxResult, -1);
- });
- }
- exports.hinge = hinge;
- function categoricalHinge(yTrue, yPred) {
- return tfjs_core_1.tidy(function () {
- var zeroTensor = K.getScalar(0.0);
- var one = K.getScalar(1.0);
- var pos = tfc.sum(tfc.mul(yTrue, yPred), -1);
- var neg = tfc.max(tfc.mul(tfc.sub(one, yTrue), yPred), -1);
- return tfc.maximum(zeroTensor, K.scalarPlusArray(one, tfc.sub(neg, pos)));
- });
- }
- exports.categoricalHinge = categoricalHinge;
- function logcosh(yTrue, yPred) {
- return tfjs_core_1.tidy(function () {
- var log2 = K.getScalar(Math.log(2.0));
- var predictionDiff = tfc.sub(yPred, yTrue);
- var logcoshResult = tfc.sub(tfc.add(predictionDiff, tfc.softplus(K.scalarTimesArray(K.getScalar(-2.0), predictionDiff))), log2);
- return tfc.mean(logcoshResult, -1);
- });
- }
- exports.logcosh = logcosh;
- function categoricalCrossentropy(target, output, fromLogits) {
- if (fromLogits === void 0) { fromLogits = false; }
- return tfjs_core_1.tidy(function () {
- if (fromLogits) {
- output = tfc.softmax(output);
- }
- else {
- var outputSum = tfc.sum(output, K.shape(output).length - 1, true);
- output = tfc.div(output, outputSum);
- }
- output = tfc.clipByValue(output, K.epsilon(), 1 - K.epsilon());
- return tfc.neg(tfc.sum(tfc.mul(target.toFloat(), tfc.log(output)), K.shape(output).length - 1));
- });
- }
- exports.categoricalCrossentropy = categoricalCrossentropy;
- function sparseCategoricalCrossentropy(target, output, fromLogits) {
- if (fromLogits === void 0) { fromLogits = false; }
- return tfjs_core_1.tidy(function () {
- var flatTarget = tfc.floor(K.flatten(target)).toInt();
- var outputShape = K.shape(output);
- var oneHotTarget = tfc.oneHot(flatTarget, outputShape[outputShape.length - 1])
- .reshape(outputShape);
- return categoricalCrossentropy(oneHotTarget, output, fromLogits);
- });
- }
- exports.sparseCategoricalCrossentropy = sparseCategoricalCrossentropy;
- function sigmoidCrossEntropyWithLogits(target, output) {
- return tfjs_core_1.tidy(function () {
- var maxOutput = tfc.maximum(output, tfc.zerosLike(output));
- var outputXTarget = tfc.mul(output, target);
- var sigmoidOutput = tfc.log(tfc.add(K.getScalar(1), tfc.exp(tfc.neg(tfc.abs(output)))));
- var result = tfc.add(tfc.sub(maxOutput, outputXTarget), sigmoidOutput);
- return result;
- });
- }
- exports.sigmoidCrossEntropyWithLogits = sigmoidCrossEntropyWithLogits;
- function binaryCrossentropy(yTrue, yPred) {
- return tfjs_core_1.tidy(function () {
- var y;
- y = tfc.clipByValue(yPred, K.epsilon(), 1 - K.epsilon());
- y = tfc.log(tfc.div(y, tfc.sub(tfc.onesLike(y), y)));
- return tfc.mean(sigmoidCrossEntropyWithLogits(yTrue, y), -1);
- });
- }
- exports.binaryCrossentropy = binaryCrossentropy;
- function kullbackLeiblerDivergence(yTrue, yPred) {
- return tfjs_core_1.tidy(function () {
- var clippedTrue = tfc.clipByValue(yTrue, K.epsilon(), 1);
- var clippedPred = tfc.clipByValue(yPred, K.epsilon(), 1);
- return tfc.sum(tfc.mul(yTrue, tfc.log(tfc.div(clippedTrue, clippedPred))), -1);
- });
- }
- exports.kullbackLeiblerDivergence = kullbackLeiblerDivergence;
- function poisson(yTrue, yPred) {
- return tfjs_core_1.tidy(function () {
- var logPred = tfc.log(K.scalarPlusArray(K.getScalar(K.epsilon()), yPred));
- return tfc.mean(tfc.sub(yPred, tfc.mul(yTrue, logPred)), -1);
- });
- }
- exports.poisson = poisson;
- function cosineProximity(yTrue, yPred) {
- return tfjs_core_1.tidy(function () {
- var trueNormalized = l2Normalize(yTrue, -1);
- var predNormalized = l2Normalize(yPred, -1);
- var trueXPred = tfc.mul(trueNormalized, predNormalized);
- return tfc.neg(tfc.sum(trueXPred, -1));
- });
- }
- exports.cosineProximity = cosineProximity;
- exports.mse = meanSquaredError;
- exports.MSE = meanSquaredError;
- exports.mae = meanAbsoluteError;
- exports.MAE = meanAbsoluteError;
- exports.mape = meanAbsolutePercentageError;
- exports.MAPE = meanAbsolutePercentageError;
- exports.msle = meanSquaredLogarithmicError;
- exports.MSLE = meanSquaredLogarithmicError;
- exports.kld = kullbackLeiblerDivergence;
- exports.KLD = kullbackLeiblerDivergence;
- exports.cosine = cosineProximity;
- function get(identifierOrFn) {
- var lossesMap = {
- meanSquaredError: meanSquaredError,
- meanAbsoluteError: meanAbsoluteError,
- meanAbsolutePercentageError: meanAbsolutePercentageError,
- meanSquaredLogarithmicError: meanSquaredLogarithmicError,
- squaredHinge: squaredHinge,
- hinge: hinge,
- categoricalHinge: categoricalHinge,
- logcosh: logcosh,
- categoricalCrossentropy: categoricalCrossentropy,
- sparseCategoricalCrossentropy: sparseCategoricalCrossentropy,
- binaryCrossentropy: binaryCrossentropy,
- kullbackLeiblerDivergence: kullbackLeiblerDivergence,
- poisson: poisson,
- cosineProximity: cosineProximity
- };
- if (typeof identifierOrFn === 'string') {
- if (identifierOrFn in lossesMap) {
- return lossesMap[identifierOrFn];
- }
- throw new errors_1.ValueError("Unknown loss " + identifierOrFn);
- }
- else {
- return identifierOrFn;
- }
- }
- exports.get = get;
- },{"./backend/tfjs_backend":169,"./errors":176,"@tensorflow/tfjs-core":54}],193:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("./backend/tfjs_backend");
- var errors_1 = require("./errors");
- var losses_1 = require("./losses");
- var losses_2 = require("./losses");
- function binaryAccuracy(yTrue, yPred) {
- return tfjs_core_1.tidy(function () {
- var threshold = K.scalarTimesArray(K.getScalar(0.5), tfc.onesLike(yPred));
- var yPredThresholded = K.cast(tfc.greater(yPred, threshold), yTrue.dtype);
- return tfc.mean(tfc.equal(yTrue, yPredThresholded), -1);
- });
- }
- exports.binaryAccuracy = binaryAccuracy;
- function categoricalAccuracy(yTrue, yPred) {
- return tfjs_core_1.tidy(function () { return K.cast(tfc.equal(tfc.argMax(yTrue, -1), tfc.argMax(yPred, -1)), 'float32'); });
- }
- exports.categoricalAccuracy = categoricalAccuracy;
- function binaryCrossentropy(yTrue, yPred) {
- return losses_2.binaryCrossentropy(yTrue, yPred);
- }
- exports.binaryCrossentropy = binaryCrossentropy;
- function sparseCategoricalAccuracy(yTrue, yPred) {
- throw new errors_1.NotImplementedError();
- }
- exports.sparseCategoricalAccuracy = sparseCategoricalAccuracy;
- function topKCategoricalAccuracy(yTrue, yPred) {
- throw new errors_1.NotImplementedError();
- }
- exports.topKCategoricalAccuracy = topKCategoricalAccuracy;
- function sparseTopKCategoricalAccuracy(yTrue, yPred) {
- throw new errors_1.NotImplementedError();
- }
- exports.sparseTopKCategoricalAccuracy = sparseTopKCategoricalAccuracy;
- exports.mse = losses_1.meanSquaredError;
- exports.MSE = losses_1.meanSquaredError;
- exports.mae = losses_1.meanAbsoluteError;
- exports.MAE = losses_1.meanAbsoluteError;
- exports.mape = losses_1.meanAbsolutePercentageError;
- exports.MAPE = losses_1.meanAbsolutePercentageError;
- exports.categoricalCrossentropy = losses_1.categoricalCrossentropy;
- exports.cosine = losses_1.cosineProximity;
- exports.sparseCategoricalCrossentropy = losses_1.sparseCategoricalCrossentropy;
- function get(identifier) {
- var metricsMap = {
- binaryAccuracy: binaryAccuracy,
- categoricalAccuracy: categoricalAccuracy,
- categoricalCrossentropy: exports.categoricalCrossentropy,
- sparseCategoricalCrossentropy: exports.sparseCategoricalCrossentropy,
- mse: exports.mse,
- MSE: exports.MSE,
- mae: exports.mae,
- MAE: exports.MAE,
- mape: exports.mape,
- MAPE: exports.MAPE,
- cosine: exports.cosine,
- };
- if (typeof identifier === 'string' && identifier in metricsMap) {
- return metricsMap[identifier];
- }
- else if (typeof identifier !== 'string' && identifier != null) {
- return identifier;
- }
- else {
- throw new errors_1.ValueError("Unknown metric " + identifier);
- }
- }
- exports.get = get;
- },{"./backend/tfjs_backend":169,"./errors":176,"./losses":192,"@tensorflow/tfjs-core":54}],194:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [0, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("./backend/tfjs_backend");
- var topology_1 = require("./engine/topology");
- var training_1 = require("./engine/training");
- var errors_1 = require("./errors");
- var serialization_1 = require("./layers/serialization");
- var generic_utils = require("./utils/generic_utils");
- var serialization_utils_1 = require("./utils/serialization_utils");
- function modelFromJSON(modelAndWeightsConfig, customObjects) {
- return __awaiter(this, void 0, void 0, function () {
- var modelTopology, tsConfig, model, weightValues, uniqueWeightValues, _i, _a, weight, skipMismatches, isNamedTensorMap;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- modelTopology = modelAndWeightsConfig.modelTopology;
- if (modelTopology['model_config'] != null) {
- modelTopology = modelTopology['model_config'];
- }
- tsConfig = serialization_utils_1.convertPythonicToTs(modelTopology);
- model = serialization_1.deserialize(tsConfig, customObjects);
- if (!(modelAndWeightsConfig.weightsManifest != null)) return [3, 2];
- return [4, tfjs_core_1.io.loadWeights(modelAndWeightsConfig.weightsManifest, modelAndWeightsConfig.pathPrefix, model.weights.map(function (weight) { return weight.originalName; }))];
- case 1:
- weightValues = _b.sent();
- uniqueWeightValues = {};
- for (_i = 0, _a = model.weights; _i < _a.length; _i++) {
- weight = _a[_i];
- uniqueWeightValues[weight.originalName] =
- weightValues[weight.originalName];
- }
- skipMismatches = null;
- isNamedTensorMap = true;
- model.loadWeights(uniqueWeightValues, skipMismatches, isNamedTensorMap);
- _b.label = 2;
- case 2: return [2, model];
- }
- });
- });
- }
- exports.modelFromJSON = modelFromJSON;
- function loadModelInternal(pathOrIOHandler) {
- return __awaiter(this, void 0, void 0, function () {
- var handlers;
- return __generator(this, function (_a) {
- if (typeof pathOrIOHandler === 'string') {
- handlers = tfjs_core_1.io.getLoadHandlers(pathOrIOHandler);
- if (handlers.length === 0) {
- handlers.push(tfjs_core_1.io.browserHTTPRequest(pathOrIOHandler));
- }
- else if (handlers.length > 1) {
- throw new errors_1.ValueError("Found more than one (" + handlers.length + ") load handlers for " +
- ("URL '" + pathOrIOHandler + "'"));
- }
- pathOrIOHandler = handlers[0];
- }
- return [2, loadModelFromIOHandler(pathOrIOHandler)];
- });
- });
- }
- exports.loadModelInternal = loadModelInternal;
- function loadModelFromIOHandler(handler, customObjects) {
- return __awaiter(this, void 0, void 0, function () {
- var artifacts, modelTopology, model, skipMismatch, isNamedTensorMap;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (handler.load == null) {
- throw new errors_1.ValueError('Cannot proceed with model loading because the IOHandler provided ' +
- 'does not have the `load` method implemented.');
- }
- return [4, handler.load()];
- case 1:
- artifacts = _a.sent();
- modelTopology = artifacts.modelTopology;
- if (modelTopology['model_config'] != null) {
- modelTopology = modelTopology['model_config'];
- }
- model = serialization_1.deserialize(serialization_utils_1.convertPythonicToTs(modelTopology), customObjects);
- if (artifacts.weightData != null) {
- if (artifacts.weightSpecs == null) {
- throw new errors_1.ValueError('Model artifacts contains weight data, but not weight specs. ' +
- 'Therefore loading of weights cannot proceed.');
- }
- skipMismatch = false;
- isNamedTensorMap = true;
- model.loadWeights(tfjs_core_1.io.decodeWeights(artifacts.weightData, artifacts.weightSpecs), skipMismatch, isNamedTensorMap);
- }
- return [2, model];
- }
- });
- });
- }
- exports.loadModelFromIOHandler = loadModelFromIOHandler;
- var Sequential = (function (_super) {
- __extends(Sequential, _super);
- function Sequential(config) {
- var _this = _super.call(this, { inputs: [], outputs: [] }) || this;
- config = config || {};
- _this.trainable = true;
- _this._updatable = true;
- _this.built = false;
- _this.name = (config.name != null) ? config.name : K.getUid('sequential_');
- if (config.layers != null) {
- for (var _i = 0, _a = config.layers; _i < _a.length; _i++) {
- var layer = _a[_i];
- _this.add(layer);
- }
- }
- return _this;
- }
- Sequential_1 = Sequential;
- Sequential.prototype.add = function (layer) {
- var isLayerModelInstance = layer instanceof Sequential_1 || layer instanceof training_1.Model;
- var modelLayer;
- if (isLayerModelInstance) {
- modelLayer = layer;
- if (modelLayer.outputs.length !== 1) {
- throw new errors_1.ValueError('All layers in a Sequential model ' +
- 'should have a single output tensor. ' +
- 'For multi-output layers, ' +
- 'use the functional API.');
- }
- if (modelLayer.inputs.length !== 1) {
- throw new errors_1.ValueError('All layers in a Sequential model ' +
- 'should have a single input tensor. ' +
- 'For multi-input layers, ' +
- 'use the functional API.');
- }
- }
- if (this.outputs.length === 0) {
- if (layer.inboundNodes.length === 0) {
- if (layer.batchInputShape == null) {
- throw new errors_1.ValueError('The first layer in a Sequential model must ' +
- 'get an `inputShape` or `batchInputShape` argument.');
- }
- var x = topology_1.Input({
- batchShape: layer.batchInputShape,
- dtype: layer.dtype,
- name: layer.name + '_input'
- });
- layer.apply(x);
- }
- if (isLayerModelInstance) {
- this.outputs = modelLayer.outputs;
- this.inputs = modelLayer.inputs;
- }
- else {
- if (layer.inboundNodes.length !== 1) {
- throw new errors_1.ValueError('A layer added to a Sequential model must not already be ' +
- ("connected somewhere else. Model received layer " + layer.name + " ") +
- ("which has " + layer.inboundNodes.length + " pre-existing inbound ") +
- 'connections.');
- }
- if (layer.inboundNodes[0].outputTensors.length !== 1) {
- throw new errors_1.ValueError('All layers in a Sequential model ' +
- 'should have a single output tensor. ' +
- 'For multi-output layers, ' +
- 'use the functional API.');
- }
- this.outputs = [layer.inboundNodes[0].outputTensors[0]];
- this.inputs = topology_1.getSourceInputs(this.outputs[0]);
- }
- this.inboundNodes = [];
- new topology_1.Node({
- outboundLayer: this,
- inboundLayers: [],
- nodeIndices: [],
- tensorIndices: [],
- inputTensors: this.inputs,
- outputTensors: this.outputs,
- inputMasks: generic_utils.pyListRepeat(null, this.inputs.length),
- outputMasks: [null],
- inputShapes: this.inputs.map(function (x) { return x.shape; }),
- outputShapes: this.outputs[0].shape
- });
- }
- else {
- var outputTensor = layer.apply(this.outputs[0]);
- if (Array.isArray(outputTensor)) {
- throw new TypeError('All layers in a Sequential model ' +
- 'should have a single output tensor. ' +
- 'For multi-output layers, ' +
- 'use the functional API.');
- }
- this.outputs = [outputTensor];
- this.inboundNodes[0].outputTensors = this.outputs;
- this.inboundNodes[0].outputShapes = [this.outputs[0].shape];
- }
- this.layers.push(layer);
- this.built = false;
- };
- Sequential.prototype.pop = function () {
- if (this.layers.length === 0) {
- throw new TypeError('There are no layers in the model.');
- }
- this.layers.pop();
- if (this.layers.length === 0) {
- this.outputs = [];
- this.inboundNodes = [];
- this.outboundNodes = [];
- }
- else {
- var lastLayerIndex = this.layers.length - 1;
- this.layers[lastLayerIndex].outboundNodes = [];
- this.outputs = [this.layers[lastLayerIndex].output];
- this.inboundNodes[0].outputTensors = this.outputs;
- this.inboundNodes[0].outputShapes = [this.outputs[0].shape];
- }
- };
- Sequential.prototype.call = function (inputs, kwargs) {
- if (this.model == null) {
- this.build();
- }
- return this.model.call(inputs, kwargs);
- };
- Sequential.prototype.build = function (inputShape) {
- generic_utils.getExactlyOneShape(inputShape);
- if (this.inputs.length === 0 || this.outputs.length === 0) {
- throw new TypeError('Sequential model cannot be built: model is empty.' +
- ' Add some layers first.');
- }
- this.model = new training_1.Model({
- inputs: this.inputs,
- outputs: this.outputs[0],
- name: this.name + '_model'
- });
- this.model.trainable = this.trainable;
- this.model.updatable = this.updatable;
- this.supportsMasking = this.model.supportsMasking;
- this.inputLayers = this.model.inputLayers;
- this.inputLayersNodeIndices = this.model.inputLayersNodeIndices;
- this.inputLayersTensorIndices = this.model.inputLayersTensorIndices;
- this.outputLayers = this.model.outputLayers;
- this.outputLayersNodeIndices = this.model.outputLayersNodeIndices;
- this.outputLayersTensorIndices = this.model.outputLayersTensorIndices;
- this.nodesByDepth = this.model.nodesByDepth;
- this.containerNodes = this.model.containerNodes;
- this.outputNames = this.model.outputNames;
- this.inputNames = this.model.inputNames;
- this.built = true;
- };
- Sequential.prototype.countParams = function () {
- if (!this.built) {
- this.build();
- }
- return _super.prototype.countParams.call(this);
- };
- Sequential.prototype.summary = function (lineLength, positions, printFn) {
- if (printFn === void 0) { printFn = console.log; }
- if (!this.built) {
- this.build();
- }
- _super.prototype.summary.call(this, lineLength, positions, printFn);
- };
- Sequential.prototype.setWeights = function (weights) {
- if (this.model == null) {
- this.build();
- }
- this.model.setWeights(weights);
- };
- Object.defineProperty(Sequential.prototype, "updatable", {
- get: function () {
- return this._updatable;
- },
- set: function (value) {
- if (this.built) {
- this.model.updatable = value;
- }
- this._updatable = value;
- },
- enumerable: true,
- configurable: true
- });
- Sequential.prototype.evaluate = function (x, y, config) {
- if (config === void 0) { config = {}; }
- if (!this.built) {
- throw new errors_1.RuntimeError('The model needs to be compiled before being used.');
- }
- return this.model.evaluate(x, y, config);
- };
- Sequential.prototype.predict = function (x, config) {
- if (config === void 0) { config = {}; }
- if (this.model == null) {
- this.build();
- }
- return this.model.predict(x, config);
- };
- Sequential.prototype.predictOnBatch = function (x) {
- if (this.model == null) {
- this.build();
- }
- return this.model.predictOnBatch(x);
- };
- Sequential.prototype.compile = function (config) {
- this.build();
- this.model.compile(config);
- this.optimizer = this.model.optimizer;
- this.loss = this.model.loss;
- this.metrics = this.model.metrics;
- this.metricsTensors = this.model.metricsTensors;
- this.metricsNames = this.model.metricsNames;
- };
- Sequential.prototype.fit = function (x, y, config) {
- if (config === void 0) { config = {}; }
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- if (!this.built) {
- throw new errors_1.RuntimeError('The model needs to be compiled before ' +
- 'being used.');
- }
- return [2, this.model.fit(x, y, config)];
- });
- });
- };
- Sequential.fromConfig = function (cls, config) {
- var model = new cls({});
- if (!(model instanceof Sequential_1)) {
- throw new errors_1.ValueError("Sequential.fromConfig called on non-Sequential input: " + model);
- }
- if (!(config instanceof Array)) {
- throw new errors_1.ValueError("Sequential.fromConfig called without an array of configs");
- }
- if (!(config[0].className != null) || config[0]['className'] === 'Merge') {
- throw new errors_1.ValueError('Legacy serialization format not supported yet.');
- }
- for (var _i = 0, _a = config; _i < _a.length; _i++) {
- var conf = _a[_i];
- var layer = serialization_1.deserialize(conf);
- model.add(layer);
- }
- return model;
- };
- Sequential.prototype.getConfig = function () {
- var config = [];
- for (var _i = 0, _a = this.layers; _i < _a.length; _i++) {
- var layer = _a[_i];
- config.push({
- className: layer.getClassName(),
- config: layer.getConfig(),
- });
- }
- return config;
- };
- Sequential.className = 'Sequential';
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes' })
- ], Sequential.prototype, "add", null);
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes' })
- ], Sequential.prototype, "summary", null);
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes', configParamIndices: [2] })
- ], Sequential.prototype, "evaluate", null);
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes', configParamIndices: [1] })
- ], Sequential.prototype, "predict", null);
- __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes', configParamIndices: [2] })
- ], Sequential.prototype, "fit", null);
- Sequential = Sequential_1 = __decorate([
- tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes' })
- ], Sequential);
- return Sequential;
- var Sequential_1;
- }(training_1.Model));
- exports.Sequential = Sequential;
- tfjs_core_1.serialization.SerializationMap.register(Sequential);
- },{"./backend/tfjs_backend":169,"./engine/topology":174,"./engine/training":175,"./errors":176,"./layers/serialization":190,"./utils/generic_utils":199,"./utils/serialization_utils":202,"@tensorflow/tfjs-core":54}],195:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("./backend/tfjs_backend");
- var errors_1 = require("./errors");
- function getOptimizer(identifier) {
- var optimizerMap = {
- 'Adagrad': function () { return tfjs_core_1.train.adagrad(.01); },
- 'Adadelta': function () { return tfjs_core_1.train.adadelta(1.0, 0.95, K.epsilon()); },
- 'Adam': function () { return tfjs_core_1.train.adam(.001, .9, .999, K.epsilon()); },
- 'Adamax': function () { return tfjs_core_1.train.adamax(0.002, .9, .999, K.epsilon(), 0.0); },
- 'RMSProp': function () { return tfjs_core_1.train.rmsprop(.001, .9, null, K.epsilon()); },
- 'SGD': function () { return tfjs_core_1.train.sgd(.01); }
- };
- optimizerMap['adagrad'] = optimizerMap['Adagrad'];
- optimizerMap['adadelta'] = optimizerMap['Adadelta'];
- optimizerMap['adam'] = optimizerMap['Adam'];
- optimizerMap['adamax'] = optimizerMap['Adamax'];
- optimizerMap['rmsprop'] = optimizerMap['RMSProp'];
- optimizerMap['sgd'] = optimizerMap['SGD'];
- if (identifier in optimizerMap) {
- return optimizerMap[identifier]();
- }
- throw new errors_1.ValueError("Unknown Optimizer " + identifier);
- }
- exports.getOptimizer = getOptimizer;
- },{"./backend/tfjs_backend":169,"./errors":176,"@tensorflow/tfjs-core":54}],196:[function(require,module,exports){
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var K = require("./backend/tfjs_backend");
- var generic_utils_1 = require("./utils/generic_utils");
- var Regularizer = (function (_super) {
- __extends(Regularizer, _super);
- function Regularizer() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- return Regularizer;
- }(tfjs_core_1.serialization.Serializable));
- exports.Regularizer = Regularizer;
- var L1L2 = (function (_super) {
- __extends(L1L2, _super);
- function L1L2(config) {
- var _this = _super.call(this) || this;
- var l1 = config == null || config.l1 == null ? 0.01 : config.l1;
- var l2 = config == null || config.l2 == null ? 0.01 : config.l2;
- _this.hasL1 = l1 !== 0;
- _this.hasL2 = l2 !== 0;
- _this.l1 = K.getScalar(l1);
- _this.l2 = K.getScalar(l2);
- return _this;
- }
- L1L2.prototype.apply = function (x) {
- var _this = this;
- return tfjs_core_1.tidy(function () {
- var regularization = tfjs_core_1.zeros([1]);
- if (_this.hasL1) {
- regularization =
- tfjs_core_1.add(regularization, tfjs_core_1.sum(K.scalarTimesArray(_this.l1, tfjs_core_1.abs(x))));
- }
- if (_this.hasL2) {
- regularization =
- tfjs_core_1.add(regularization, tfjs_core_1.sum(K.scalarTimesArray(_this.l2, K.square(x))));
- }
- return regularization.asScalar();
- });
- };
- L1L2.prototype.getConfig = function () {
- return { 'l1': this.l1.dataSync()[0], 'l2': this.l2.dataSync()[0] };
- };
- L1L2.fromConfig = function (cls, config) {
- return new cls({ l1: config.l1, l2: config.l2 });
- };
- L1L2.className = 'L1L2';
- L1L2 = __decorate([
- tfjs_core_1.doc({ heading: 'Regularizers', namespace: 'regularizers' })
- ], L1L2);
- return L1L2;
- }(Regularizer));
- exports.L1L2 = L1L2;
- tfjs_core_1.serialization.SerializationMap.register(L1L2);
- function l1(config) {
- return new L1L2({ l1: config != null ? config.l1 : null, l2: 0 });
- }
- exports.l1 = l1;
- function l2(config) {
- return new L1L2({ l2: config != null ? config.l2 : null, l1: 0 });
- }
- exports.l2 = l2;
- exports.REGULARIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP = {
- 'l1l2': 'L1L2'
- };
- function serializeRegularizer(constraint) {
- return generic_utils_1.serializeKerasObject(constraint);
- }
- exports.serializeRegularizer = serializeRegularizer;
- function deserializeRegularizer(config, customObjects) {
- if (customObjects === void 0) { customObjects = {}; }
- return generic_utils_1.deserializeKerasObject(config, tfjs_core_1.serialization.SerializationMap.getMap().classNameMap, customObjects, 'regularizer');
- }
- exports.deserializeRegularizer = deserializeRegularizer;
- function getRegularizer(identifier) {
- if (identifier == null) {
- return null;
- }
- if (typeof identifier === 'string') {
- var className = identifier in exports.REGULARIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP ?
- exports.REGULARIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP[identifier] :
- identifier;
- var config = { className: className, config: {} };
- return deserializeRegularizer(config);
- }
- else if (identifier instanceof Regularizer) {
- return identifier;
- }
- else {
- return deserializeRegularizer(identifier);
- }
- }
- exports.getRegularizer = getRegularizer;
- },{"./backend/tfjs_backend":169,"./utils/generic_utils":199,"@tensorflow/tfjs-core":54}],197:[function(require,module,exports){
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var common_1 = require("./common");
- var _nextUniqueTensorId = 0;
- function getNextUniqueTensorId() {
- return _nextUniqueTensorId++;
- }
- exports.getNextUniqueTensorId = getNextUniqueTensorId;
- var SymbolicTensor = (function () {
- function SymbolicTensor(dtype, shape, sourceLayer, inputs, callArgs, name, outputTensorIndex) {
- this.dtype = dtype;
- this.shape = shape;
- this.sourceLayer = sourceLayer;
- this.inputs = inputs;
- this.callArgs = callArgs;
- this.outputTensorIndex = outputTensorIndex;
- this.id = getNextUniqueTensorId();
- if (name != null) {
- this.originalName = common_1.getScopedTensorName(name);
- this.name = common_1.getUniqueTensorName(this.originalName);
- }
- this.rank = shape.length;
- }
- SymbolicTensor = __decorate([
- tfjs_core_1.doc({ heading: 'Models', 'subheading': 'Classes' })
- ], SymbolicTensor);
- return SymbolicTensor;
- }());
- exports.SymbolicTensor = SymbolicTensor;
- },{"./common":171,"@tensorflow/tfjs-core":54}],198:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var errors_1 = require("../errors");
- var generic_utils_1 = require("./generic_utils");
- var math_utils_1 = require("./math_utils");
- function normalizeArray(value, n, name) {
- if (typeof value === 'number') {
- return generic_utils_1.pyListRepeat(value, n);
- }
- else {
- if (value.length !== n) {
- throw new errors_1.ValueError("The " + name + " argument must be a tuple of " + n + " integers. Received: " +
- (value.length + " elements."));
- }
- for (var i = 0; i < n; ++i) {
- var singleValue = value[i];
- if (!math_utils_1.isInteger(singleValue)) {
- throw new errors_1.ValueError("The " + name + " argument must be a tuple of " + n + " integers. Received: " +
- (JSON.stringify(value) + " including a non-integer number ") +
- ("" + singleValue));
- }
- }
- return value;
- }
- }
- exports.normalizeArray = normalizeArray;
- function convOutputLength(inputLength, filterSize, padding, stride, dilation) {
- if (dilation === void 0) { dilation = 1; }
- if (inputLength == null) {
- return inputLength;
- }
- var dilatedFilterSize = filterSize + (filterSize - 1) * (dilation - 1);
- var outputLength;
- if (padding === 'same') {
- outputLength = inputLength;
- }
- else {
- outputLength = inputLength - dilatedFilterSize + 1;
- }
- return Math.floor((outputLength + stride - 1) / stride);
- }
- exports.convOutputLength = convOutputLength;
- function deconvLength(dimSize, strideSize, kernelSize, padding) {
- if (dimSize == null) {
- return null;
- }
- if (padding === 'valid') {
- dimSize = dimSize * strideSize + math_utils_1.max([kernelSize - strideSize, 0]);
- }
- else if (padding === 'same') {
- dimSize = dimSize * strideSize;
- }
- else {
- throw new errors_1.ValueError("Unsupport padding mode: " + padding + ".");
- }
- return dimSize;
- }
- exports.deconvLength = deconvLength;
- },{"../errors":176,"./generic_utils":199,"./math_utils":201}],199:[function(require,module,exports){
- "use strict";
- var __assign = (this && this.__assign) || Object.assign || function(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
- t[p] = s[p];
- }
- return t;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var errors_1 = require("../errors");
- function pyListRepeat(value, numValues) {
- if (Array.isArray(value)) {
- var newArray = [];
- for (var i = 0; i < numValues; i++) {
- newArray = newArray.concat(value);
- }
- return newArray;
- }
- else {
- var newArray = new Array(numValues);
- newArray.fill(value);
- return newArray;
- }
- }
- exports.pyListRepeat = pyListRepeat;
- function assert(val, message) {
- if (!val) {
- throw new errors_1.AssertionError(message);
- }
- }
- exports.assert = assert;
- function count(array, refernce) {
- var counter = 0;
- for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
- var item = array_1[_i];
- if (item === refernce) {
- counter++;
- }
- }
- return counter;
- }
- exports.count = count;
- function singletonOrArray(xs) {
- if (xs.length === 1) {
- return xs[0];
- }
- return xs;
- }
- exports.singletonOrArray = singletonOrArray;
- function toList(x) {
- if (Array.isArray(x)) {
- return x;
- }
- return [x];
- }
- exports.toList = toList;
- function objectListUid(objs) {
- var objectList = toList(objs);
- var retVal = '';
- for (var _i = 0, objectList_1 = objectList; _i < objectList_1.length; _i++) {
- var obj = objectList_1[_i];
- if (obj.id == null) {
- throw new errors_1.ValueError("Object " + obj + " passed to objectListUid without an id");
- }
- if (retVal !== '') {
- retVal = retVal + ', ';
- }
- retVal = retVal + Math.abs(obj.id);
- }
- return retVal;
- }
- exports.objectListUid = objectListUid;
- function isArrayOfShapes(x) {
- return Array.isArray(x) && Array.isArray(x[0]);
- }
- exports.isArrayOfShapes = isArrayOfShapes;
- function normalizeShapeList(x) {
- if (x.length === 0) {
- return [];
- }
- if (!Array.isArray(x[0])) {
- return [x];
- }
- return x;
- }
- exports.normalizeShapeList = normalizeShapeList;
- function toSnakeCase(name) {
- var intermediate = name.replace(/(.)([A-Z][a-z0-9]+)/g, '$1_$2');
- var insecure = intermediate.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
- if (insecure[0] !== '_') {
- return insecure;
- }
- return 'private' + insecure;
- }
- exports.toSnakeCase = toSnakeCase;
- function toCamelCase(identifier) {
- if (identifier.length <= 1) {
- return identifier;
- }
- if (identifier.indexOf('_') === -1) {
- return identifier;
- }
- return identifier.replace(/[_]+(\w|$)/g, function (m, p1) { return p1.toUpperCase(); });
- }
- exports.toCamelCase = toCamelCase;
- var _GLOBAL_CUSTOM_OBJECTS = {};
- function serializeKerasObject(instance) {
- if (instance === null || instance === undefined) {
- return null;
- }
- return { className: instance.getClassName(), config: instance.getConfig() };
- }
- exports.serializeKerasObject = serializeKerasObject;
- function deserializeKerasObject(identifier, moduleObjects, customObjects, printableModuleName) {
- if (moduleObjects === void 0) { moduleObjects = {}; }
- if (customObjects === void 0) { customObjects = {}; }
- if (printableModuleName === void 0) { printableModuleName = 'object'; }
- if (typeof identifier === 'string') {
- var functionName = identifier;
- var fn = void 0;
- if (functionName in customObjects) {
- fn = customObjects[functionName];
- }
- else if (functionName in _GLOBAL_CUSTOM_OBJECTS) {
- fn = _GLOBAL_CUSTOM_OBJECTS[functionName];
- }
- else {
- fn = moduleObjects[functionName];
- if (fn == null) {
- throw new errors_1.ValueError("Unknown " + printableModuleName + ": " + identifier);
- }
- }
- return fn;
- }
- else {
- var config = identifier;
- if (config.className == null || config.config == null) {
- throw new errors_1.ValueError(printableModuleName + ": Improper config format: " +
- (JSON.stringify(config) + ".\n") +
- "'className' and 'config' must set.");
- }
- var className = config.className;
- var cls = void 0, fromConfig = void 0;
- if (className in customObjects) {
- _a = customObjects.get(className), cls = _a[0], fromConfig = _a[1];
- }
- else if (className in _GLOBAL_CUSTOM_OBJECTS) {
- _b = _GLOBAL_CUSTOM_OBJECTS.className, cls = _b[0], fromConfig = _b[1];
- }
- else if (className in moduleObjects) {
- _c = moduleObjects[className], cls = _c[0], fromConfig = _c[1];
- }
- if (cls == null) {
- throw new errors_1.ValueError("Unknown " + printableModuleName + ": " + className);
- }
- if (fromConfig != null) {
- var customObjectsCombined = {};
- for (var _i = 0, _d = Object.keys(_GLOBAL_CUSTOM_OBJECTS); _i < _d.length; _i++) {
- var key = _d[_i];
- customObjectsCombined[key] = _GLOBAL_CUSTOM_OBJECTS[key];
- }
- for (var _e = 0, _f = Object.keys(customObjects); _e < _f.length; _e++) {
- var key = _f[_e];
- customObjectsCombined[key] = customObjects[key];
- }
- var nestedConfig = config.config;
- nestedConfig.customObjects = customObjectsCombined;
- var backupCustomObjects = __assign({}, _GLOBAL_CUSTOM_OBJECTS);
- for (var _g = 0, _h = Object.keys(customObjects); _g < _h.length; _g++) {
- var key = _h[_g];
- _GLOBAL_CUSTOM_OBJECTS[key] = customObjects[key];
- }
- var returnObj = fromConfig(cls, config.config);
- _GLOBAL_CUSTOM_OBJECTS = __assign({}, backupCustomObjects);
- return returnObj;
- }
- else {
- var backupCustomObjects = __assign({}, _GLOBAL_CUSTOM_OBJECTS);
- for (var _j = 0, _k = Object.keys(customObjects); _j < _k.length; _j++) {
- var key = _k[_j];
- _GLOBAL_CUSTOM_OBJECTS[key] = customObjects[key];
- }
- var returnObj = new cls(config.config);
- _GLOBAL_CUSTOM_OBJECTS = __assign({}, backupCustomObjects);
- return returnObj;
- }
- }
- var _a, _b, _c;
- }
- exports.deserializeKerasObject = deserializeKerasObject;
- function getExactlyOneTensor(xs) {
- var x;
- if (Array.isArray(xs)) {
- if (xs.length !== 1) {
- throw new errors_1.ValueError("Expected Tensor length to be 1; got " + xs.length);
- }
- x = xs[0];
- }
- else {
- x = xs;
- }
- return x;
- }
- exports.getExactlyOneTensor = getExactlyOneTensor;
- function getExactlyOneShape(shapes) {
- if (Array.isArray(shapes) && Array.isArray(shapes[0])) {
- if (shapes.length === 1) {
- shapes = shapes;
- return shapes[0];
- }
- else {
- throw new errors_1.ValueError("Expected exactly 1 Shape; got " + shapes.length);
- }
- }
- else {
- return shapes;
- }
- }
- exports.getExactlyOneShape = getExactlyOneShape;
- function numberCompare(a, b) {
- return (a < b) ? -1 : ((a > b) ? 1 : 0);
- }
- exports.numberCompare = numberCompare;
- function reverseNumberCompare(a, b) {
- return -1 * numberCompare(a, b);
- }
- exports.reverseNumberCompare = reverseNumberCompare;
- function stringToDType(dtype) {
- switch (dtype) {
- case 'float32':
- return 'float32';
- default:
- throw new errors_1.ValueError("Invalid dtype: " + dtype);
- }
- }
- exports.stringToDType = stringToDType;
- function stringsEqual(xs, ys) {
- if (xs == null || ys == null) {
- return xs === ys;
- }
- if (xs.length !== ys.length) {
- return false;
- }
- for (var i = 0; i < xs.length; ++i) {
- if (xs[i] !== ys[i]) {
- return false;
- }
- }
- return true;
- }
- exports.stringsEqual = stringsEqual;
- function unique(xs) {
- if (xs == null) {
- return xs;
- }
- var out = [];
- for (var _i = 0, xs_1 = xs; _i < xs_1.length; _i++) {
- var x = xs_1[_i];
- if (out.indexOf(x) === -1) {
- out.push(x);
- }
- }
- return out;
- }
- exports.unique = unique;
- function isObjectEmpty(obj) {
- if (obj == null) {
- throw new errors_1.ValueError("Invalid value in obj: " + JSON.stringify(obj));
- }
- for (var key in obj) {
- if (obj.hasOwnProperty(key)) {
- return false;
- }
- }
- return true;
- }
- exports.isObjectEmpty = isObjectEmpty;
- function checkStringTypeUnionValue(values, label, value) {
- if (value == null) {
- return;
- }
- if (values.indexOf(value) < 0) {
- throw new errors_1.ValueError(value + " is not a valid " + label + ". Valid values are " + values + " or null/undefined.");
- }
- }
- exports.checkStringTypeUnionValue = checkStringTypeUnionValue;
- function checkArrayTypeAndLength(x, expectedType, minLength, maxLength) {
- if (minLength === void 0) { minLength = 0; }
- if (maxLength === void 0) { maxLength = Infinity; }
- assert(minLength >= 0);
- assert(maxLength >= minLength);
- return (Array.isArray(x) && x.length >= minLength && x.length <= maxLength &&
- x.every(function (e) { return typeof e === expectedType; }));
- }
- exports.checkArrayTypeAndLength = checkArrayTypeAndLength;
- function countParamsInWeights(weights) {
- var count = 0;
- for (var _i = 0, weights_1 = weights; _i < weights_1.length; _i++) {
- var weight = weights_1[_i];
- if (weight.shape.length === 0) {
- count += 1;
- }
- else {
- count += weight.shape.reduce(function (a, b) { return a * b; });
- }
- }
- return count;
- }
- exports.countParamsInWeights = countParamsInWeights;
- },{"../errors":176}],200:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var generic_utils_1 = require("./generic_utils");
- function printSummary(model, lineLength, positions, printFn) {
- if (printFn === void 0) { printFn = console.log; }
- var sequentialLike = isModelSequentialLike(model);
- var toDisplay = ['Layer (type)', 'Output shape', 'Param #'];
- if (sequentialLike) {
- lineLength = lineLength || 65;
- positions = positions || [0.45, 0.85, 1];
- }
- else {
- lineLength = lineLength || 98;
- positions = positions || [0.33, 0.55, 0.67, 1];
- }
- if (positions[positions.length - 1] <= 1) {
- positions = positions.map(function (p) { return Math.floor(lineLength * p); });
- }
- var relevantNodes;
- if (!sequentialLike) {
- toDisplay.push('Receives inputs');
- relevantNodes = [];
- for (var depth in model.nodesByDepth) {
- relevantNodes.push.apply(relevantNodes, model.nodesByDepth[depth]);
- }
- }
- printFn('_'.repeat(lineLength));
- printRow(toDisplay, positions, printFn);
- printFn('='.repeat(lineLength));
- var layers = model.layers;
- for (var i = 0; i < layers.length; ++i) {
- if (sequentialLike) {
- printLayerSummary(layers[i], positions, printFn);
- }
- else {
- printLayerSummaryWithConnections(layers[i], positions, relevantNodes, printFn);
- }
- printFn((i === layers.length - 1 ? '=' : '_').repeat(lineLength));
- }
- model.checkTrainableWeightsConsistency();
- var trainableCount;
- if (model.collectedTrainableWeights != null) {
- trainableCount =
- generic_utils_1.countParamsInWeights(model.collectedTrainableWeights);
- }
- else {
- trainableCount = generic_utils_1.countParamsInWeights(model.trainableWeights);
- }
- var nonTrainableCount = generic_utils_1.countParamsInWeights(model.nonTrainableWeights);
- printFn("Total params: " + (trainableCount + nonTrainableCount));
- printFn("Trainable params: " + trainableCount);
- printFn("Non-trainable params: " + nonTrainableCount);
- printFn('_'.repeat(lineLength));
- }
- exports.printSummary = printSummary;
- function isModelSequentialLike(model) {
- var sequentialLike = true;
- var nodesByDepth = [];
- var nodes = [];
- for (var depth in model.nodesByDepth) {
- nodesByDepth.push(model.nodesByDepth[depth]);
- }
- for (var _i = 0, nodesByDepth_1 = nodesByDepth; _i < nodesByDepth_1.length; _i++) {
- var depthNodes = nodesByDepth_1[_i];
- if (depthNodes.length > 1 ||
- depthNodes.length === 1 && depthNodes[0].inboundLayers.length > 1) {
- sequentialLike = false;
- break;
- }
- nodes.push.apply(nodes, depthNodes);
- }
- if (sequentialLike) {
- for (var _a = 0, _b = model.layers; _a < _b.length; _a++) {
- var layer = _b[_a];
- var flag = false;
- for (var _c = 0, _d = layer.inboundNodes; _c < _d.length; _c++) {
- var node = _d[_c];
- if (nodes.indexOf(node) !== -1) {
- if (flag) {
- sequentialLike = false;
- break;
- }
- else {
- flag = true;
- }
- }
- }
- if (!sequentialLike) {
- break;
- }
- }
- }
- return sequentialLike;
- }
- function printRow(fields, positions, printFn) {
- if (printFn === void 0) { printFn = console.log; }
- var line = '';
- for (var i = 0; i < fields.length; ++i) {
- if (i > 0) {
- line = line.slice(0, line.length - 1) + ' ';
- }
- line += fields[i];
- line = line.slice(0, positions[i]);
- line += ' '.repeat(positions[i] - line.length);
- }
- printFn(line);
- }
- function printLayerSummary(layer, positions, printFn) {
- var outputShape;
- try {
- outputShape = JSON.stringify(layer.outputShape);
- }
- catch (err) {
- outputShape = 'multiple';
- }
- var name = layer.name;
- var className = layer.getClassName();
- var fields = [name + " (" + className + ")", outputShape, layer.countParams().toString()];
- printRow(fields, positions, printFn);
- }
- function printLayerSummaryWithConnections(layer, positions, relevantNodes, printFn) {
- var outputShape;
- try {
- outputShape = JSON.stringify(layer.outputShape);
- }
- catch (err) {
- outputShape = 'multiple';
- }
- var connections = [];
- for (var _i = 0, _a = layer.inboundNodes; _i < _a.length; _i++) {
- var node = _a[_i];
- if (relevantNodes != null && relevantNodes.length > 0 &&
- relevantNodes.indexOf(node) === -1) {
- continue;
- }
- for (var i = 0; i < node.inboundLayers.length; ++i) {
- var inboundLayer = node.inboundLayers[i].name;
- var inboundLayerIndex = node.nodeIndices[i];
- var inboundTensorIndex = node.tensorIndices[i];
- connections.push(inboundLayer + "[" + inboundLayerIndex + "][" + inboundTensorIndex + "]");
- }
- }
- var name = layer.name;
- var className = layer.getClassName();
- var firstConnection = connections.length === 0 ? '' : connections[0];
- var fields = [
- name + " (" + className + ")", outputShape, layer.countParams().toString(),
- firstConnection
- ];
- printRow(fields, positions, printFn);
- for (var i = 1; i < connections.length; ++i) {
- printRow(['', '', '', connections[i]], positions, printFn);
- }
- }
- },{"./generic_utils":199}],201:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var errors_1 = require("../errors");
- function isInteger(x) {
- return x === parseInt(x.toString(), 10);
- }
- exports.isInteger = isInteger;
- function arrayProd(array, begin, end) {
- if (begin == null) {
- begin = 0;
- }
- if (end == null) {
- end = array.length;
- }
- var prod = 1;
- for (var i = begin; i < end; ++i) {
- prod *= array[i];
- }
- return prod;
- }
- exports.arrayProd = arrayProd;
- function toArray1D(array) {
- array = Array.isArray(array) ? new Float32Array(array) : array;
- return tfjs_core_1.tensor1d(array);
- }
- function min(array) {
- return tfc.min(toArray1D(array)).dataSync()[0];
- }
- exports.min = min;
- function max(array) {
- return tfc.max(toArray1D(array)).dataSync()[0];
- }
- exports.max = max;
- function sum(array) {
- return tfc.sum(toArray1D(array)).dataSync()[0];
- }
- exports.sum = sum;
- function mean(array) {
- return sum(array) / array.length;
- }
- exports.mean = mean;
- function variance(array) {
- var demeaned = tfc.sub(toArray1D(array), tfjs_core_1.scalar(mean(array)));
- var sumSquare = tfc.sum(tfc.mulStrict(demeaned, demeaned)).dataSync()[0];
- return sumSquare / array.length;
- }
- exports.variance = variance;
- function median(array) {
- var arraySorted = array.slice().sort(function (a, b) { return a - b; });
- var lowIdx = Math.floor((arraySorted.length - 1) / 2);
- var highIdx = Math.ceil((arraySorted.length - 1) / 2);
- if (lowIdx === highIdx) {
- return arraySorted[lowIdx];
- }
- return (arraySorted[lowIdx] + arraySorted[highIdx]) / 2;
- }
- exports.median = median;
- function range(begin, end) {
- if (end < begin) {
- throw new errors_1.ValueError("end (" + end + ") < begin (" + begin + ") is forbidden.");
- }
- var out = [];
- for (var i = begin; i < end; ++i) {
- out.push(i);
- }
- return out;
- }
- exports.range = range;
- },{"../errors":176,"@tensorflow/tfjs-core":54}],202:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var generic_utils = require("../utils/generic_utils");
- function isArrayItemInputOrOutputName(key, index, value) {
- return (key === 'inboundNodes' || key === 'outputLayers' ||
- key === 'inputLayers') &&
- index === 0 && typeof value === 'string';
- }
- function convertPythonicToTs(pythonicConfig, key) {
- if (pythonicConfig === null) {
- return null;
- }
- else if (typeof pythonicConfig === 'string') {
- return generic_utils.toCamelCase(pythonicConfig);
- }
- else if ((typeof pythonicConfig === 'number') ||
- (typeof pythonicConfig === 'boolean')) {
- return pythonicConfig;
- }
- else if (pythonicConfig instanceof Array) {
- var tsArray = [];
- var arrayLength = pythonicConfig.length;
- for (var i = 0; i < arrayLength; ++i) {
- var item = pythonicConfig[i];
- if (isArrayItemInputOrOutputName(key, i, item)) {
- tsArray.push(item);
- }
- else {
- tsArray.push(convertPythonicToTs(item, key));
- }
- }
- return tsArray;
- }
- else {
- var tsDict = {};
- for (var _i = 0, _a = Object.keys(pythonicConfig); _i < _a.length; _i++) {
- var pythonicKey = _a[_i];
- var pythonicValue = pythonicConfig[pythonicKey];
- if (pythonicKey === 'name' && typeof pythonicValue === 'string') {
- tsDict[pythonicKey] = pythonicValue;
- }
- else {
- var tsKey = generic_utils.toCamelCase(pythonicKey);
- tsDict[tsKey] = convertPythonicToTs(pythonicValue, tsKey);
- }
- }
- return tsDict;
- }
- }
- exports.convertPythonicToTs = convertPythonicToTs;
- function convertTsToPythonic(tsConfig, key) {
- if (tsConfig === null || tsConfig === undefined) {
- return null;
- }
- else if (typeof tsConfig === 'string') {
- return generic_utils.toSnakeCase(tsConfig);
- }
- else if ((typeof tsConfig === 'number') || (typeof tsConfig === 'boolean')) {
- return tsConfig;
- }
- else if (tsConfig instanceof Array) {
- var pyArray = [];
- var arrayLength = tsConfig.length;
- for (var i = 0; i < arrayLength; ++i) {
- var item = tsConfig[i];
- if (isArrayItemInputOrOutputName(key, i, item)) {
- pyArray.push(item);
- }
- else {
- pyArray.push(convertTsToPythonic(item, key));
- }
- }
- return pyArray;
- }
- else {
- var pyDict = {};
- for (var _i = 0, _a = Object.keys(tsConfig); _i < _a.length; _i++) {
- var tsKey = _a[_i];
- var tsValue = tsConfig[tsKey];
- var pyKey = generic_utils.toSnakeCase(tsKey);
- if ((tsKey === 'name' || tsKey === 'className') &&
- typeof tsValue === 'string') {
- pyDict[pyKey] = tsValue;
- }
- else {
- pyDict[pyKey] = convertTsToPythonic(tsValue, tsKey);
- }
- }
- return pyDict;
- }
- }
- exports.convertTsToPythonic = convertTsToPythonic;
- },{"../utils/generic_utils":199}],203:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var tfc = require("@tensorflow/tfjs-core");
- var tfjs_backend_1 = require("./backend/tfjs_backend");
- var common_1 = require("./common");
- var errors_1 = require("./errors");
- var types_1 = require("./types");
- var DEFAULT_VARIABLE_NAME_PREFIX = 'Variable';
- var LayerVariable = (function () {
- function LayerVariable(val, dtype, name, trainable, constraint) {
- if (dtype === void 0) { dtype = 'float32'; }
- if (name === void 0) { name = DEFAULT_VARIABLE_NAME_PREFIX; }
- if (trainable === void 0) { trainable = true; }
- if (constraint === void 0) { constraint = null; }
- this.dtype = dtype == null ? 'float32' : dtype;
- this.shape = val.shape;
- this.id = types_1.getNextUniqueTensorId();
- name = name == null ? DEFAULT_VARIABLE_NAME_PREFIX : name;
- this.originalName = common_1.getScopedTensorName(name);
- this.name = common_1.getUniqueTensorName(this.originalName);
- this.trainable = trainable;
- this.constraint = constraint;
- this.val = tfc.variable(val, this.trainable, this.name, this.dtype);
- }
- LayerVariable.prototype.read = function () {
- return this.val;
- };
- LayerVariable.prototype.write = function (newVal) {
- checkShapesMatch(this.val, newVal);
- this.val.assign(newVal);
- if (this.constraint != null) {
- this.val.assign(this.constraint.apply(this.val));
- }
- return this;
- };
- return LayerVariable;
- }());
- exports.LayerVariable = LayerVariable;
- function checkShapesMatch(x, y) {
- if (x.shape.toString() !== y.shape.toString()) {
- throw new Error('Shape mismatch: ' + JSON.stringify(x.shape) + ' vs. ' +
- JSON.stringify(y.shape));
- }
- }
- function variable(x, dtype, name, constraint) {
- return new LayerVariable(x, dtype, name, true, constraint);
- }
- exports.variable = variable;
- function zerosVariable(shape, dtype, name) {
- return new LayerVariable(tfc.zeros(shape), dtype, name);
- }
- exports.zerosVariable = zerosVariable;
- function zerosLike(x, dtype, name) {
- return new LayerVariable(tfc.zerosLike(x), dtype, name);
- }
- exports.zerosLike = zerosLike;
- function onesVariable(shape, dtype, name) {
- var allocated = tfc.ones(shape);
- return new LayerVariable(allocated, dtype, name);
- }
- exports.onesVariable = onesVariable;
- function onesLike(x, dtype, name) {
- var allocated = tfc.onesLike(x);
- return new LayerVariable(allocated, dtype, name);
- }
- exports.onesLike = onesLike;
- function eyeVariable(size, dtype, name) {
- return new LayerVariable(tfc.eye(size), dtype, name);
- }
- exports.eyeVariable = eyeVariable;
- function randomUniformVariable(shape, minval, maxval, dtype, seed, name) {
- if (name === void 0) { name = 'randomUniform'; }
- return new LayerVariable(tfc.randomUniform(shape, minval, maxval, dtype), dtype, name);
- }
- exports.randomUniformVariable = randomUniformVariable;
- function truncatedNormalVariable(shape, mean, stddev, dtype, seed, name) {
- if (mean === void 0) { mean = 0.0; }
- if (stddev === void 0) { stddev = 1.0; }
- if (name === void 0) { name = 'truncatedNormal'; }
- if (dtype === 'bool') {
- throw new errors_1.NotImplementedError("randomNormal does not support dType bool.");
- }
- return new LayerVariable(tfc.truncatedNormal(shape, mean, stddev, dtype, seed), dtype, name);
- }
- exports.truncatedNormalVariable = truncatedNormalVariable;
- function randomNormalVariable(shape, mean, stddev, dtype, seed, name) {
- if (mean === void 0) { mean = 0.0; }
- if (stddev === void 0) { stddev = 1.0; }
- if (name === void 0) { name = 'randomNormal'; }
- if (dtype === 'bool') {
- throw new errors_1.NotImplementedError("randomNormalVariable does not support dType bool.");
- }
- return new LayerVariable(tfjs_backend_1.randomNormal(shape, mean, stddev, dtype, seed), dtype, name);
- }
- exports.randomNormalVariable = randomNormalVariable;
- function update(x, xNew) {
- return x.write(xNew);
- }
- exports.update = update;
- function updateAdd(x, increment) {
- return x.write(tfc.add(x.read(), increment));
- }
- exports.updateAdd = updateAdd;
- function updateSub(x, decrement) {
- return x.write(tfc.sub(x.read(), decrement));
- }
- exports.updateSub = updateSub;
- function batchGetValue(xs) {
- return xs.map(function (x) { return x.read(); });
- }
- exports.batchGetValue = batchGetValue;
- function batchSetValue(variablesAndValues) {
- variablesAndValues.map(function (variableAndValue) {
- var variable = variableAndValue[0];
- variable.write(variableAndValue[1]);
- });
- }
- exports.batchSetValue = batchSetValue;
- },{"./backend/tfjs_backend":169,"./common":171,"./errors":176,"./types":197,"@tensorflow/tfjs-core":54}],204:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var version = '0.6.7';
- exports.version = version;
- },{}],205:[function(require,module,exports){
- "use strict";
- function __export(m) {
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
- }
- Object.defineProperty(exports, "__esModule", { value: true });
- __export(require("@tensorflow/tfjs-core"));
- __export(require("@tensorflow/tfjs-layers"));
- __export(require("@tensorflow/tfjs-converter"));
- var tfjs_core_1 = require("@tensorflow/tfjs-core");
- var tfjs_layers_1 = require("@tensorflow/tfjs-layers");
- var tfjs_converter_1 = require("@tensorflow/tfjs-converter");
- var version_1 = require("./version");
- exports.version = {
- 'tfjs-core': tfjs_core_1.version_core,
- 'tfjs-layers': tfjs_layers_1.version_layers,
- 'tfjs-converter': tfjs_converter_1.version_converter,
- 'tfjs': version_1.version
- };
- },{"./version":206,"@tensorflow/tfjs-converter":16,"@tensorflow/tfjs-core":54,"@tensorflow/tfjs-layers":178}],206:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var version = '0.11.7';
- exports.version = version;
- },{}],207:[function(require,module,exports){
- (function (process,global){
- /* @preserve
- * The MIT License (MIT)
- *
- * Copyright (c) 2013-2015 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- /**
- * bluebird build version 3.0.2
- * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, using, timers, filter, any, each
- */
- !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Promise=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof _dereq_=="function"&&_dereq_;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof _dereq_=="function"&&_dereq_;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise) {
- var SomePromiseArray = Promise._SomePromiseArray;
- function any(promises) {
- var ret = new SomePromiseArray(promises);
- var promise = ret.promise();
- ret.setHowMany(1);
- ret.setUnwrap();
- ret.init();
- return promise;
- }
- Promise.any = function (promises) {
- return any(promises);
- };
- Promise.prototype.any = function () {
- return any(this);
- };
- };
- },{}],2:[function(_dereq_,module,exports){
- "use strict";
- var firstLineError;
- try {throw new Error(); } catch (e) {firstLineError = e;}
- var schedule = _dereq_("./schedule");
- var Queue = _dereq_("./queue");
- var util = _dereq_("./util");
- function Async() {
- this._isTickUsed = false;
- this._lateQueue = new Queue(16);
- this._normalQueue = new Queue(16);
- this._haveDrainedQueues = false;
- this._trampolineEnabled = true;
- var self = this;
- this.drainQueues = function () {
- self._drainQueues();
- };
- this._schedule =
- schedule.isStatic ? schedule(this.drainQueues) : schedule;
- }
- Async.prototype.disableTrampolineIfNecessary = function() {
- if (util.hasDevTools) {
- this._trampolineEnabled = false;
- }
- };
- Async.prototype.haveItemsQueued = function () {
- return this._isTickUsed || this._haveDrainedQueues;
- };
- Async.prototype.fatalError = function(e, isNode) {
- if (isNode) {
- process.stderr.write("Fatal " + (e instanceof Error ? e.stack : e));
- process.exit(2);
- } else {
- this.throwLater(e);
- }
- };
- Async.prototype.throwLater = function(fn, arg) {
- if (arguments.length === 1) {
- arg = fn;
- fn = function () { throw arg; };
- }
- if (typeof setTimeout !== "undefined") {
- setTimeout(function() {
- fn(arg);
- }, 0);
- } else try {
- this._schedule(function() {
- fn(arg);
- });
- } catch (e) {
- throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
- }
- };
- function AsyncInvokeLater(fn, receiver, arg) {
- this._lateQueue.push(fn, receiver, arg);
- this._queueTick();
- }
- function AsyncInvoke(fn, receiver, arg) {
- this._normalQueue.push(fn, receiver, arg);
- this._queueTick();
- }
- function AsyncSettlePromises(promise) {
- this._normalQueue._pushOne(promise);
- this._queueTick();
- }
- if (!util.hasDevTools) {
- Async.prototype.invokeLater = AsyncInvokeLater;
- Async.prototype.invoke = AsyncInvoke;
- Async.prototype.settlePromises = AsyncSettlePromises;
- } else {
- if (schedule.isStatic) {
- schedule = function(fn) { setTimeout(fn, 0); };
- }
- Async.prototype.invokeLater = function (fn, receiver, arg) {
- if (this._trampolineEnabled) {
- AsyncInvokeLater.call(this, fn, receiver, arg);
- } else {
- this._schedule(function() {
- setTimeout(function() {
- fn.call(receiver, arg);
- }, 100);
- });
- }
- };
- Async.prototype.invoke = function (fn, receiver, arg) {
- if (this._trampolineEnabled) {
- AsyncInvoke.call(this, fn, receiver, arg);
- } else {
- this._schedule(function() {
- fn.call(receiver, arg);
- });
- }
- };
- Async.prototype.settlePromises = function(promise) {
- if (this._trampolineEnabled) {
- AsyncSettlePromises.call(this, promise);
- } else {
- this._schedule(function() {
- promise._settlePromises();
- });
- }
- };
- }
- Async.prototype.invokeFirst = function (fn, receiver, arg) {
- this._normalQueue.unshift(fn, receiver, arg);
- this._queueTick();
- };
- Async.prototype._drainQueue = function(queue) {
- while (queue.length() > 0) {
- var fn = queue.shift();
- if (typeof fn !== "function") {
- fn._settlePromises();
- continue;
- }
- var receiver = queue.shift();
- var arg = queue.shift();
- fn.call(receiver, arg);
- }
- };
- Async.prototype._drainQueues = function () {
- this._drainQueue(this._normalQueue);
- this._reset();
- this._haveDrainedQueues = true;
- this._drainQueue(this._lateQueue);
- };
- Async.prototype._queueTick = function () {
- if (!this._isTickUsed) {
- this._isTickUsed = true;
- this._schedule(this.drainQueues);
- }
- };
- Async.prototype._reset = function () {
- this._isTickUsed = false;
- };
- module.exports = Async;
- module.exports.firstLineError = firstLineError;
- },{"./queue":26,"./schedule":29,"./util":36}],3:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, INTERNAL, tryConvertToPromise, debug) {
- var calledBind = false;
- var rejectThis = function(_, e) {
- this._reject(e);
- };
- var targetRejected = function(e, context) {
- context.promiseRejectionQueued = true;
- context.bindingPromise._then(rejectThis, rejectThis, null, this, e);
- };
- var bindingResolved = function(thisArg, context) {
- if (((this._bitField & 50397184) === 0)) {
- this._resolveCallback(context.target);
- }
- };
- var bindingRejected = function(e, context) {
- if (!context.promiseRejectionQueued) this._reject(e);
- };
- Promise.prototype.bind = function (thisArg) {
- if (!calledBind) {
- calledBind = true;
- Promise.prototype._propagateFrom = debug.propagateFromFunction();
- Promise.prototype._boundValue = debug.boundValueFunction();
- }
- var maybePromise = tryConvertToPromise(thisArg);
- var ret = new Promise(INTERNAL);
- ret._propagateFrom(this, 1);
- var target = this._target();
- ret._setBoundTo(maybePromise);
- if (maybePromise instanceof Promise) {
- var context = {
- promiseRejectionQueued: false,
- promise: ret,
- target: target,
- bindingPromise: maybePromise
- };
- target._then(INTERNAL, targetRejected, undefined, ret, context);
- maybePromise._then(
- bindingResolved, bindingRejected, undefined, ret, context);
- ret._setOnCancel(maybePromise);
- } else {
- ret._resolveCallback(target);
- }
- return ret;
- };
- Promise.prototype._setBoundTo = function (obj) {
- if (obj !== undefined) {
- this._bitField = this._bitField | 2097152;
- this._boundTo = obj;
- } else {
- this._bitField = this._bitField & (~2097152);
- }
- };
- Promise.prototype._isBound = function () {
- return (this._bitField & 2097152) === 2097152;
- };
- Promise.bind = function (thisArg, value) {
- return Promise.resolve(value).bind(thisArg);
- };
- };
- },{}],4:[function(_dereq_,module,exports){
- "use strict";
- var old;
- if (typeof Promise !== "undefined") old = Promise;
- function noConflict() {
- try { if (Promise === bluebird) Promise = old; }
- catch (e) {}
- return bluebird;
- }
- var bluebird = _dereq_("./promise")();
- bluebird.noConflict = noConflict;
- module.exports = bluebird;
- },{"./promise":22}],5:[function(_dereq_,module,exports){
- "use strict";
- var cr = Object.create;
- if (cr) {
- var callerCache = cr(null);
- var getterCache = cr(null);
- callerCache[" size"] = getterCache[" size"] = 0;
- }
- module.exports = function(Promise) {
- var util = _dereq_("./util");
- var canEvaluate = util.canEvaluate;
- var isIdentifier = util.isIdentifier;
- var getMethodCaller;
- var getGetter;
- if (!true) {
- var makeMethodCaller = function (methodName) {
- return new Function("ensureMethod", " \n\
- return function(obj) { \n\
- 'use strict' \n\
- var len = this.length; \n\
- ensureMethod(obj, 'methodName'); \n\
- switch(len) { \n\
- case 1: return obj.methodName(this[0]); \n\
- case 2: return obj.methodName(this[0], this[1]); \n\
- case 3: return obj.methodName(this[0], this[1], this[2]); \n\
- case 0: return obj.methodName(); \n\
- default: \n\
- return obj.methodName.apply(obj, this); \n\
- } \n\
- }; \n\
- ".replace(/methodName/g, methodName))(ensureMethod);
- };
- var makeGetter = function (propertyName) {
- return new Function("obj", " \n\
- 'use strict'; \n\
- return obj.propertyName; \n\
- ".replace("propertyName", propertyName));
- };
- var getCompiled = function(name, compiler, cache) {
- var ret = cache[name];
- if (typeof ret !== "function") {
- if (!isIdentifier(name)) {
- return null;
- }
- ret = compiler(name);
- cache[name] = ret;
- cache[" size"]++;
- if (cache[" size"] > 512) {
- var keys = Object.keys(cache);
- for (var i = 0; i < 256; ++i) delete cache[keys[i]];
- cache[" size"] = keys.length - 256;
- }
- }
- return ret;
- };
- getMethodCaller = function(name) {
- return getCompiled(name, makeMethodCaller, callerCache);
- };
- getGetter = function(name) {
- return getCompiled(name, makeGetter, getterCache);
- };
- }
- function ensureMethod(obj, methodName) {
- var fn;
- if (obj != null) fn = obj[methodName];
- if (typeof fn !== "function") {
- var message = "Object " + util.classString(obj) + " has no method '" +
- util.toString(methodName) + "'";
- throw new Promise.TypeError(message);
- }
- return fn;
- }
- function caller(obj) {
- var methodName = this.pop();
- var fn = ensureMethod(obj, methodName);
- return fn.apply(obj, this);
- }
- Promise.prototype.call = function (methodName) {
- var args = [].slice.call(arguments, 1);;
- if (!true) {
- if (canEvaluate) {
- var maybeCaller = getMethodCaller(methodName);
- if (maybeCaller !== null) {
- return this._then(
- maybeCaller, undefined, undefined, args, undefined);
- }
- }
- }
- args.push(methodName);
- return this._then(caller, undefined, undefined, args, undefined);
- };
- function namedGetter(obj) {
- return obj[this];
- }
- function indexedGetter(obj) {
- var index = +this;
- if (index < 0) index = Math.max(0, index + obj.length);
- return obj[index];
- }
- Promise.prototype.get = function (propertyName) {
- var isIndex = (typeof propertyName === "number");
- var getter;
- if (!isIndex) {
- if (canEvaluate) {
- var maybeGetter = getGetter(propertyName);
- getter = maybeGetter !== null ? maybeGetter : namedGetter;
- } else {
- getter = namedGetter;
- }
- } else {
- getter = indexedGetter;
- }
- return this._then(getter, undefined, undefined, propertyName, undefined);
- };
- };
- },{"./util":36}],6:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, PromiseArray, apiRejection, debug) {
- var util = _dereq_("./util");
- var tryCatch = util.tryCatch;
- var errorObj = util.errorObj;
- var async = Promise._async;
- Promise.prototype["break"] = Promise.prototype.cancel = function() {
- if (!debug.cancellation()) return this._warn("cancellation is disabled");
- var promise = this;
- var child = promise;
- while (promise.isCancellable()) {
- if (!promise._cancelBy(child)) {
- if (child._isFollowing()) {
- child._followee().cancel();
- } else {
- child._cancelBranched();
- }
- break;
- }
- var parent = promise._cancellationParent;
- if (parent == null || !parent.isCancellable()) {
- if (promise._isFollowing()) {
- promise._followee().cancel();
- } else {
- promise._cancelBranched();
- }
- break;
- } else {
- if (promise._isFollowing()) promise._followee().cancel();
- child = promise;
- promise = parent;
- }
- }
- };
- Promise.prototype._branchHasCancelled = function() {
- this._branchesRemainingToCancel--;
- };
- Promise.prototype._enoughBranchesHaveCancelled = function() {
- return this._branchesRemainingToCancel === undefined ||
- this._branchesRemainingToCancel <= 0;
- };
- Promise.prototype._cancelBy = function(canceller) {
- if (canceller === this) {
- this._branchesRemainingToCancel = 0;
- this._invokeOnCancel();
- return true;
- } else {
- this._branchHasCancelled();
- if (this._enoughBranchesHaveCancelled()) {
- this._invokeOnCancel();
- return true;
- }
- }
- return false;
- };
- Promise.prototype._cancelBranched = function() {
- if (this._enoughBranchesHaveCancelled()) {
- this._cancel();
- }
- };
- Promise.prototype._cancel = function() {
- if (!this.isCancellable()) return;
- this._setCancelled();
- async.invoke(this._cancelPromises, this, undefined);
- };
- Promise.prototype._cancelPromises = function() {
- if (this._length() > 0) this._settlePromises();
- };
- Promise.prototype._unsetOnCancel = function() {
- this._onCancelField = undefined;
- };
- Promise.prototype.isCancellable = function() {
- return this.isPending() && !this.isCancelled();
- };
- Promise.prototype._doInvokeOnCancel = function(onCancelCallback, internalOnly) {
- if (util.isArray(onCancelCallback)) {
- for (var i = 0; i < onCancelCallback.length; ++i) {
- this._doInvokeOnCancel(onCancelCallback[i], internalOnly);
- }
- } else if (onCancelCallback !== undefined) {
- if (typeof onCancelCallback === "function") {
- if (!internalOnly) {
- var e = tryCatch(onCancelCallback).call(this._boundValue());
- if (e === errorObj) {
- this._attachExtraTrace(e.e);
- async.throwLater(e.e);
- }
- }
- } else {
- onCancelCallback._resultCancelled(this);
- }
- }
- };
- Promise.prototype._invokeOnCancel = function() {
- var onCancelCallback = this._onCancel();
- this._unsetOnCancel();
- async.invoke(this._doInvokeOnCancel, this, onCancelCallback);
- };
- Promise.prototype._invokeInternalOnCancel = function() {
- if (this.isCancellable()) {
- this._doInvokeOnCancel(this._onCancel(), true);
- this._unsetOnCancel();
- }
- };
- Promise.prototype._resultCancelled = function() {
- this.cancel();
- };
- };
- },{"./util":36}],7:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(NEXT_FILTER) {
- var util = _dereq_("./util");
- var getKeys = _dereq_("./es5").keys;
- var tryCatch = util.tryCatch;
- var errorObj = util.errorObj;
- function catchFilter(instances, cb, promise) {
- return function(e) {
- var boundTo = promise._boundValue();
- predicateLoop: for (var i = 0; i < instances.length; ++i) {
- var item = instances[i];
- if (item === Error ||
- (item != null && item.prototype instanceof Error)) {
- if (e instanceof item) {
- return tryCatch(cb).call(boundTo, e);
- }
- } else if (typeof item === "function") {
- var matchesPredicate = tryCatch(item).call(boundTo, e);
- if (matchesPredicate === errorObj) {
- return matchesPredicate;
- } else if (matchesPredicate) {
- return tryCatch(cb).call(boundTo, e);
- }
- } else if (util.isObject(e)) {
- var keys = getKeys(item);
- for (var j = 0; j < keys.length; ++j) {
- var key = keys[j];
- if (item[key] != e[key]) {
- continue predicateLoop;
- }
- }
- return tryCatch(cb).call(boundTo, e);
- }
- }
- return NEXT_FILTER;
- };
- }
- return catchFilter;
- };
- },{"./es5":13,"./util":36}],8:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise) {
- var longStackTraces = false;
- var contextStack = [];
- Promise.prototype._promiseCreated = function() {};
- Promise.prototype._pushContext = function() {};
- Promise.prototype._popContext = function() {return 0;};
- Promise._peekContext = Promise.prototype._peekContext = function() {};
- function Context() {
- this._trace = new Context.CapturedTrace(peekContext());
- }
- Context.prototype._pushContext = function () {
- if (this._trace !== undefined) {
- this._trace._promisesCreated = 0;
- contextStack.push(this._trace);
- }
- };
- Context.prototype._popContext = function () {
- if (this._trace !== undefined) {
- var trace = contextStack.pop();
- var ret = trace._promisesCreated;
- trace._promisesCreated = 0;
- return ret;
- }
- return 0;
- };
- function createContext() {
- if (longStackTraces) return new Context();
- }
- function peekContext() {
- var lastIndex = contextStack.length - 1;
- if (lastIndex >= 0) {
- return contextStack[lastIndex];
- }
- return undefined;
- }
- Context.CapturedTrace = null;
- Context.create = createContext;
- Context.activateLongStackTraces = function() {
- longStackTraces = true;
- Promise.prototype._pushContext = Context.prototype._pushContext;
- Promise.prototype._popContext = Context.prototype._popContext;
- Promise._peekContext = Promise.prototype._peekContext = peekContext;
- Promise.prototype._promiseCreated = function() {
- var ctx = this._peekContext();
- if (ctx) ctx._promisesCreated++;
- };
- };
- return Context;
- };
- },{}],9:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, Context) {
- var getDomain = Promise._getDomain;
- var async = Promise._async;
- var Warning = _dereq_("./errors").Warning;
- var util = _dereq_("./util");
- var canAttachTrace = util.canAttachTrace;
- var unhandledRejectionHandled;
- var possiblyUnhandledRejection;
- var bluebirdFramePattern =
- /[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/;
- var stackFramePattern = null;
- var formatStack = null;
- var indentStackFrames = false;
- var printWarning;
- var debugging =!!(true || util.env("BLUEBIRD_DEBUG") ||
- util.env("NODE_ENV") === "development");
- var warnings = !!(util.env("BLUEBIRD_WARNINGS") != 0 &&
- (debugging || util.env("BLUEBIRD_WARNINGS")));
- var longStackTraces = !!(util.env("BLUEBIRD_LONG_STACK_TRACES") != 0 &&
- (debugging || util.env("BLUEBIRD_LONG_STACK_TRACES")));
- Promise.prototype.suppressUnhandledRejections = function() {
- var target = this._target();
- target._bitField = ((target._bitField & (~1048576)) |
- 2097152);
- };
- Promise.prototype._ensurePossibleRejectionHandled = function () {
- if ((this._bitField & 2097152) !== 0) return;
- this._setRejectionIsUnhandled();
- async.invokeLater(this._notifyUnhandledRejection, this, undefined);
- };
- Promise.prototype._notifyUnhandledRejectionIsHandled = function () {
- fireRejectionEvent("rejectionHandled",
- unhandledRejectionHandled, undefined, this);
- };
- Promise.prototype._notifyUnhandledRejection = function () {
- if (this._isRejectionUnhandled()) {
- var reason = this._settledValue();
- this._setUnhandledRejectionIsNotified();
- fireRejectionEvent("unhandledRejection",
- possiblyUnhandledRejection, reason, this);
- }
- };
- Promise.prototype._setUnhandledRejectionIsNotified = function () {
- this._bitField = this._bitField | 262144;
- };
- Promise.prototype._unsetUnhandledRejectionIsNotified = function () {
- this._bitField = this._bitField & (~262144);
- };
- Promise.prototype._isUnhandledRejectionNotified = function () {
- return (this._bitField & 262144) > 0;
- };
- Promise.prototype._setRejectionIsUnhandled = function () {
- this._bitField = this._bitField | 1048576;
- };
- Promise.prototype._unsetRejectionIsUnhandled = function () {
- this._bitField = this._bitField & (~1048576);
- if (this._isUnhandledRejectionNotified()) {
- this._unsetUnhandledRejectionIsNotified();
- this._notifyUnhandledRejectionIsHandled();
- }
- };
- Promise.prototype._isRejectionUnhandled = function () {
- return (this._bitField & 1048576) > 0;
- };
- Promise.prototype._warn = function(message, shouldUseOwnTrace) {
- return warn(message, shouldUseOwnTrace, this);
- };
- Promise.onPossiblyUnhandledRejection = function (fn) {
- var domain = getDomain();
- possiblyUnhandledRejection =
- typeof fn === "function" ? (domain === null ? fn : domain.bind(fn))
- : undefined;
- };
- Promise.onUnhandledRejectionHandled = function (fn) {
- var domain = getDomain();
- unhandledRejectionHandled =
- typeof fn === "function" ? (domain === null ? fn : domain.bind(fn))
- : undefined;
- };
- Promise.longStackTraces = function () {
- if (async.haveItemsQueued() && !config.longStackTraces) {
- throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a");
- }
- if (!config.longStackTraces && longStackTracesIsSupported()) {
- config.longStackTraces = true;
- Promise.prototype._captureStackTrace = longStackTracesCaptureStackTrace;
- Promise.prototype._attachExtraTrace = longStackTracesAttachExtraTrace;
- Context.activateLongStackTraces();
- async.disableTrampolineIfNecessary();
- }
- };
- Promise.hasLongStackTraces = function () {
- return config.longStackTraces && longStackTracesIsSupported();
- };
- Promise.config = function(opts) {
- opts = Object(opts);
- if ("longStackTraces" in opts && opts.longStackTraces) {
- Promise.longStackTraces();
- }
- if ("warnings" in opts) {
- config.warnings = !!opts.warnings;
- }
- if ("cancellation" in opts && opts.cancellation && !config.cancellation) {
- if (async.haveItemsQueued()) {
- throw new Error(
- "cannot enable cancellation after promises are in use");
- }
- Promise.prototype._clearCancellationData =
- cancellationClearCancellationData;
- Promise.prototype._propagateFrom = cancellationPropagateFrom;
- Promise.prototype._onCancel = cancellationOnCancel;
- Promise.prototype._setOnCancel = cancellationSetOnCancel;
- Promise.prototype._attachCancellationCallback =
- cancellationAttachCancellationCallback;
- Promise.prototype._execute = cancellationExecute;
- propagateFromFunction = cancellationPropagateFrom;
- config.cancellation = true;
- }
- };
- Promise.prototype._execute = function(executor, resolve, reject) {
- try {
- executor(resolve, reject);
- } catch (e) {
- return e;
- }
- };
- Promise.prototype._onCancel = function () {};
- Promise.prototype._setOnCancel = function (handler) { ; };
- Promise.prototype._attachCancellationCallback = function(onCancel) {
- ;
- };
- Promise.prototype._captureStackTrace = function () {};
- Promise.prototype._attachExtraTrace = function () {};
- Promise.prototype._clearCancellationData = function() {};
- Promise.prototype._propagateFrom = function (parent, flags) {
- ;
- ;
- };
- function cancellationExecute(executor, resolve, reject) {
- var promise = this;
- try {
- executor(resolve, reject, function(onCancel) {
- if (typeof onCancel !== "function") {
- throw new TypeError("onCancel must be a function, got: " +
- util.toString(onCancel));
- }
- promise._attachCancellationCallback(onCancel);
- });
- } catch (e) {
- return e;
- }
- }
- function cancellationAttachCancellationCallback(onCancel) {
- if (!this.isCancellable()) return this;
- var previousOnCancel = this._onCancel();
- if (previousOnCancel !== undefined) {
- if (util.isArray(previousOnCancel)) {
- previousOnCancel.push(onCancel);
- } else {
- this._setOnCancel([previousOnCancel, onCancel]);
- }
- } else {
- this._setOnCancel(onCancel);
- }
- }
- function cancellationOnCancel() {
- return this._onCancelField;
- }
- function cancellationSetOnCancel(onCancel) {
- this._onCancelField = onCancel;
- }
- function cancellationClearCancellationData() {
- this._cancellationParent = undefined;
- this._onCancelField = undefined;
- }
- function cancellationPropagateFrom(parent, flags) {
- if ((flags & 1) !== 0) {
- this._cancellationParent = parent;
- var branchesRemainingToCancel = parent._branchesRemainingToCancel;
- if (branchesRemainingToCancel === undefined) {
- branchesRemainingToCancel = 0;
- }
- parent._branchesRemainingToCancel = branchesRemainingToCancel + 1;
- }
- if ((flags & 2) !== 0 && parent._isBound()) {
- this._setBoundTo(parent._boundTo);
- }
- }
- function bindingPropagateFrom(parent, flags) {
- if ((flags & 2) !== 0 && parent._isBound()) {
- this._setBoundTo(parent._boundTo);
- }
- }
- var propagateFromFunction = bindingPropagateFrom;
- function boundValueFunction() {
- var ret = this._boundTo;
- if (ret !== undefined) {
- if (ret instanceof Promise) {
- if (ret.isFulfilled()) {
- return ret.value();
- } else {
- return undefined;
- }
- }
- }
- return ret;
- }
- function longStackTracesCaptureStackTrace() {
- this._trace = new CapturedTrace(this._peekContext());
- }
- function longStackTracesAttachExtraTrace(error, ignoreSelf) {
- if (canAttachTrace(error)) {
- var trace = this._trace;
- if (trace !== undefined) {
- if (ignoreSelf) trace = trace._parent;
- }
- if (trace !== undefined) {
- trace.attachExtraTrace(error);
- } else if (!error.__stackCleaned__) {
- var parsed = parseStackAndMessage(error);
- util.notEnumerableProp(error, "stack",
- parsed.message + "\n" + parsed.stack.join("\n"));
- util.notEnumerableProp(error, "__stackCleaned__", true);
- }
- }
- }
- function checkForgottenReturns(returnValue, promisesCreated, name, promise) {
- if (returnValue === undefined &&
- promisesCreated > 0 &&
- config.longStackTraces &&
- config.warnings) {
- var msg = "a promise was created in a " + name +
- " handler but was not returned from it";
- promise._warn(msg);
- }
- }
- function deprecated(name, replacement) {
- var message = name +
- " is deprecated and will be removed in a future version.";
- if (replacement) message += " Use " + replacement + " instead.";
- return warn(message);
- }
- function warn(message, shouldUseOwnTrace, promise) {
- if (!config.warnings) return;
- var warning = new Warning(message);
- var ctx;
- if (shouldUseOwnTrace) {
- promise._attachExtraTrace(warning);
- } else if (config.longStackTraces && (ctx = Promise._peekContext())) {
- ctx.attachExtraTrace(warning);
- } else {
- var parsed = parseStackAndMessage(warning);
- warning.stack = parsed.message + "\n" + parsed.stack.join("\n");
- }
- formatAndLogError(warning, "", true);
- }
- function reconstructStack(message, stacks) {
- for (var i = 0; i < stacks.length - 1; ++i) {
- stacks[i].push("From previous event:");
- stacks[i] = stacks[i].join("\n");
- }
- if (i < stacks.length) {
- stacks[i] = stacks[i].join("\n");
- }
- return message + "\n" + stacks.join("\n");
- }
- function removeDuplicateOrEmptyJumps(stacks) {
- for (var i = 0; i < stacks.length; ++i) {
- if (stacks[i].length === 0 ||
- ((i + 1 < stacks.length) && stacks[i][0] === stacks[i+1][0])) {
- stacks.splice(i, 1);
- i--;
- }
- }
- }
- function removeCommonRoots(stacks) {
- var current = stacks[0];
- for (var i = 1; i < stacks.length; ++i) {
- var prev = stacks[i];
- var currentLastIndex = current.length - 1;
- var currentLastLine = current[currentLastIndex];
- var commonRootMeetPoint = -1;
- for (var j = prev.length - 1; j >= 0; --j) {
- if (prev[j] === currentLastLine) {
- commonRootMeetPoint = j;
- break;
- }
- }
- for (var j = commonRootMeetPoint; j >= 0; --j) {
- var line = prev[j];
- if (current[currentLastIndex] === line) {
- current.pop();
- currentLastIndex--;
- } else {
- break;
- }
- }
- current = prev;
- }
- }
- function cleanStack(stack) {
- var ret = [];
- for (var i = 0; i < stack.length; ++i) {
- var line = stack[i];
- var isTraceLine = " (No stack trace)" === line ||
- stackFramePattern.test(line);
- var isInternalFrame = isTraceLine && shouldIgnore(line);
- if (isTraceLine && !isInternalFrame) {
- if (indentStackFrames && line.charAt(0) !== " ") {
- line = " " + line;
- }
- ret.push(line);
- }
- }
- return ret;
- }
- function stackFramesAsArray(error) {
- var stack = error.stack.replace(/\s+$/g, "").split("\n");
- for (var i = 0; i < stack.length; ++i) {
- var line = stack[i];
- if (" (No stack trace)" === line || stackFramePattern.test(line)) {
- break;
- }
- }
- if (i > 0) {
- stack = stack.slice(i);
- }
- return stack;
- }
- function parseStackAndMessage(error) {
- var stack = error.stack;
- var message = error.toString();
- stack = typeof stack === "string" && stack.length > 0
- ? stackFramesAsArray(error) : [" (No stack trace)"];
- return {
- message: message,
- stack: cleanStack(stack)
- };
- }
- function formatAndLogError(error, title, isSoft) {
- if (typeof console !== "undefined") {
- var message;
- if (util.isObject(error)) {
- var stack = error.stack;
- message = title + formatStack(stack, error);
- } else {
- message = title + String(error);
- }
- if (typeof printWarning === "function") {
- printWarning(message, isSoft);
- } else if (typeof console.log === "function" ||
- typeof console.log === "object") {
- console.log(message);
- }
- }
- }
- function fireRejectionEvent(name, localHandler, reason, promise) {
- var localEventFired = false;
- try {
- if (typeof localHandler === "function") {
- localEventFired = true;
- if (name === "rejectionHandled") {
- localHandler(promise);
- } else {
- localHandler(reason, promise);
- }
- }
- } catch (e) {
- async.throwLater(e);
- }
- var globalEventFired = false;
- try {
- globalEventFired = fireGlobalEvent(name, reason, promise);
- } catch (e) {
- globalEventFired = true;
- async.throwLater(e);
- }
- var domEventFired = false;
- if (fireDomEvent) {
- try {
- domEventFired = fireDomEvent(name.toLowerCase(), {
- reason: reason,
- promise: promise
- });
- } catch (e) {
- domEventFired = true;
- async.throwLater(e);
- }
- }
- if (!globalEventFired && !localEventFired && !domEventFired &&
- name === "unhandledRejection") {
- formatAndLogError(reason, "Unhandled rejection ");
- }
- }
- function formatNonError(obj) {
- var str;
- if (typeof obj === "function") {
- str = "[function " +
- (obj.name || "anonymous") +
- "]";
- } else {
- str = obj && typeof obj.toString === "function"
- ? obj.toString() : util.toString(obj);
- var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/;
- if (ruselessToString.test(str)) {
- try {
- var newStr = JSON.stringify(obj);
- str = newStr;
- }
- catch(e) {
- }
- }
- if (str.length === 0) {
- str = "(empty array)";
- }
- }
- return ("(<" + snip(str) + ">, no stack trace)");
- }
- function snip(str) {
- var maxChars = 41;
- if (str.length < maxChars) {
- return str;
- }
- return str.substr(0, maxChars - 3) + "...";
- }
- function longStackTracesIsSupported() {
- return typeof captureStackTrace === "function";
- }
- var shouldIgnore = function() { return false; };
- var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;
- function parseLineInfo(line) {
- var matches = line.match(parseLineInfoRegex);
- if (matches) {
- return {
- fileName: matches[1],
- line: parseInt(matches[2], 10)
- };
- }
- }
- function setBounds(firstLineError, lastLineError) {
- if (!longStackTracesIsSupported()) return;
- var firstStackLines = firstLineError.stack.split("\n");
- var lastStackLines = lastLineError.stack.split("\n");
- var firstIndex = -1;
- var lastIndex = -1;
- var firstFileName;
- var lastFileName;
- for (var i = 0; i < firstStackLines.length; ++i) {
- var result = parseLineInfo(firstStackLines[i]);
- if (result) {
- firstFileName = result.fileName;
- firstIndex = result.line;
- break;
- }
- }
- for (var i = 0; i < lastStackLines.length; ++i) {
- var result = parseLineInfo(lastStackLines[i]);
- if (result) {
- lastFileName = result.fileName;
- lastIndex = result.line;
- break;
- }
- }
- if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName ||
- firstFileName !== lastFileName || firstIndex >= lastIndex) {
- return;
- }
- shouldIgnore = function(line) {
- if (bluebirdFramePattern.test(line)) return true;
- var info = parseLineInfo(line);
- if (info) {
- if (info.fileName === firstFileName &&
- (firstIndex <= info.line && info.line <= lastIndex)) {
- return true;
- }
- }
- return false;
- };
- }
- function CapturedTrace(parent) {
- this._parent = parent;
- this._promisesCreated = 0;
- var length = this._length = 1 + (parent === undefined ? 0 : parent._length);
- captureStackTrace(this, CapturedTrace);
- if (length > 32) this.uncycle();
- }
- util.inherits(CapturedTrace, Error);
- Context.CapturedTrace = CapturedTrace;
- CapturedTrace.prototype.uncycle = function() {
- var length = this._length;
- if (length < 2) return;
- var nodes = [];
- var stackToIndex = {};
- for (var i = 0, node = this; node !== undefined; ++i) {
- nodes.push(node);
- node = node._parent;
- }
- length = this._length = i;
- for (var i = length - 1; i >= 0; --i) {
- var stack = nodes[i].stack;
- if (stackToIndex[stack] === undefined) {
- stackToIndex[stack] = i;
- }
- }
- for (var i = 0; i < length; ++i) {
- var currentStack = nodes[i].stack;
- var index = stackToIndex[currentStack];
- if (index !== undefined && index !== i) {
- if (index > 0) {
- nodes[index - 1]._parent = undefined;
- nodes[index - 1]._length = 1;
- }
- nodes[i]._parent = undefined;
- nodes[i]._length = 1;
- var cycleEdgeNode = i > 0 ? nodes[i - 1] : this;
- if (index < length - 1) {
- cycleEdgeNode._parent = nodes[index + 1];
- cycleEdgeNode._parent.uncycle();
- cycleEdgeNode._length =
- cycleEdgeNode._parent._length + 1;
- } else {
- cycleEdgeNode._parent = undefined;
- cycleEdgeNode._length = 1;
- }
- var currentChildLength = cycleEdgeNode._length + 1;
- for (var j = i - 2; j >= 0; --j) {
- nodes[j]._length = currentChildLength;
- currentChildLength++;
- }
- return;
- }
- }
- };
- CapturedTrace.prototype.attachExtraTrace = function(error) {
- if (error.__stackCleaned__) return;
- this.uncycle();
- var parsed = parseStackAndMessage(error);
- var message = parsed.message;
- var stacks = [parsed.stack];
- var trace = this;
- while (trace !== undefined) {
- stacks.push(cleanStack(trace.stack.split("\n")));
- trace = trace._parent;
- }
- removeCommonRoots(stacks);
- removeDuplicateOrEmptyJumps(stacks);
- util.notEnumerableProp(error, "stack", reconstructStack(message, stacks));
- util.notEnumerableProp(error, "__stackCleaned__", true);
- };
- var captureStackTrace = (function stackDetection() {
- var v8stackFramePattern = /^\s*at\s*/;
- var v8stackFormatter = function(stack, error) {
- if (typeof stack === "string") return stack;
- if (error.name !== undefined &&
- error.message !== undefined) {
- return error.toString();
- }
- return formatNonError(error);
- };
- if (typeof Error.stackTraceLimit === "number" &&
- typeof Error.captureStackTrace === "function") {
- Error.stackTraceLimit += 6;
- stackFramePattern = v8stackFramePattern;
- formatStack = v8stackFormatter;
- var captureStackTrace = Error.captureStackTrace;
- shouldIgnore = function(line) {
- return bluebirdFramePattern.test(line);
- };
- return function(receiver, ignoreUntil) {
- Error.stackTraceLimit += 6;
- captureStackTrace(receiver, ignoreUntil);
- Error.stackTraceLimit -= 6;
- };
- }
- var err = new Error();
- if (typeof err.stack === "string" &&
- err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) {
- stackFramePattern = /@/;
- formatStack = v8stackFormatter;
- indentStackFrames = true;
- return function captureStackTrace(o) {
- o.stack = new Error().stack;
- };
- }
- var hasStackAfterThrow;
- try { throw new Error(); }
- catch(e) {
- hasStackAfterThrow = ("stack" in e);
- }
- if (!("stack" in err) && hasStackAfterThrow &&
- typeof Error.stackTraceLimit === "number") {
- stackFramePattern = v8stackFramePattern;
- formatStack = v8stackFormatter;
- return function captureStackTrace(o) {
- Error.stackTraceLimit += 6;
- try { throw new Error(); }
- catch(e) { o.stack = e.stack; }
- Error.stackTraceLimit -= 6;
- };
- }
- formatStack = function(stack, error) {
- if (typeof stack === "string") return stack;
- if ((typeof error === "object" ||
- typeof error === "function") &&
- error.name !== undefined &&
- error.message !== undefined) {
- return error.toString();
- }
- return formatNonError(error);
- };
- return null;
- })([]);
- var fireDomEvent;
- var fireGlobalEvent = (function() {
- if (util.isNode) {
- return function(name, reason, promise) {
- if (name === "rejectionHandled") {
- return process.emit(name, promise);
- } else {
- return process.emit(name, reason, promise);
- }
- };
- } else {
- var customEventWorks = false;
- var anyEventWorks = true;
- try {
- var ev = new self.CustomEvent("test");
- customEventWorks = ev instanceof CustomEvent;
- } catch (e) {}
- if (!customEventWorks) {
- try {
- var event = document.createEvent("CustomEvent");
- event.initCustomEvent("testingtheevent", false, true, {});
- self.dispatchEvent(event);
- } catch (e) {
- anyEventWorks = false;
- }
- }
- if (anyEventWorks) {
- fireDomEvent = function(type, detail) {
- var event;
- if (customEventWorks) {
- event = new self.CustomEvent(type, {
- detail: detail,
- bubbles: false,
- cancelable: true
- });
- } else if (self.dispatchEvent) {
- event = document.createEvent("CustomEvent");
- event.initCustomEvent(type, false, true, detail);
- }
- return event ? !self.dispatchEvent(event) : false;
- };
- }
- var toWindowMethodNameMap = {};
- toWindowMethodNameMap["unhandledRejection"] = ("on" +
- "unhandledRejection").toLowerCase();
- toWindowMethodNameMap["rejectionHandled"] = ("on" +
- "rejectionHandled").toLowerCase();
- return function(name, reason, promise) {
- var methodName = toWindowMethodNameMap[name];
- var method = self[methodName];
- if (!method) return false;
- if (name === "rejectionHandled") {
- method.call(self, promise);
- } else {
- method.call(self, reason, promise);
- }
- return true;
- };
- }
- })();
- if (typeof console !== "undefined" && typeof console.warn !== "undefined") {
- printWarning = function (message) {
- console.warn(message);
- };
- if (util.isNode && process.stderr.isTTY) {
- printWarning = function(message, isSoft) {
- var color = isSoft ? "\u001b[33m" : "\u001b[31m";
- process.stderr.write(color + message + "\u001b[0m\n");
- };
- } else if (!util.isNode && typeof (new Error().stack) === "string") {
- printWarning = function(message, isSoft) {
- console.warn("%c" + message,
- isSoft ? "color: darkorange" : "color: red");
- };
- }
- }
- var config = {
- warnings: warnings,
- longStackTraces: false,
- cancellation: false
- };
- if (longStackTraces) Promise.longStackTraces();
- return {
- longStackTraces: function() {
- return config.longStackTraces;
- },
- warnings: function() {
- return config.warnings;
- },
- cancellation: function() {
- return config.cancellation;
- },
- propagateFromFunction: function() {
- return propagateFromFunction;
- },
- boundValueFunction: function() {
- return boundValueFunction;
- },
- checkForgottenReturns: checkForgottenReturns,
- setBounds: setBounds,
- warn: warn,
- deprecated: deprecated,
- CapturedTrace: CapturedTrace
- };
- };
- },{"./errors":12,"./util":36}],10:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise) {
- function returner() {
- return this.value;
- }
- function thrower() {
- throw this.reason;
- }
- Promise.prototype["return"] =
- Promise.prototype.thenReturn = function (value) {
- if (value instanceof Promise) value.suppressUnhandledRejections();
- return this._then(
- returner, undefined, undefined, {value: value}, undefined);
- };
- Promise.prototype["throw"] =
- Promise.prototype.thenThrow = function (reason) {
- return this._then(
- thrower, undefined, undefined, {reason: reason}, undefined);
- };
- Promise.prototype.catchThrow = function (reason) {
- if (arguments.length <= 1) {
- return this._then(
- undefined, thrower, undefined, {reason: reason}, undefined);
- } else {
- var _reason = arguments[1];
- var handler = function() {throw _reason;};
- return this.caught(reason, handler);
- }
- };
- Promise.prototype.catchReturn = function (value) {
- if (arguments.length <= 1) {
- if (value instanceof Promise) value.suppressUnhandledRejections();
- return this._then(
- undefined, returner, undefined, {value: value}, undefined);
- } else {
- var _value = arguments[1];
- if (_value instanceof Promise) _value.suppressUnhandledRejections();
- var handler = function() {return _value;};
- return this.caught(value, handler);
- }
- };
- };
- },{}],11:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var PromiseReduce = Promise.reduce;
- var PromiseAll = Promise.all;
- function promiseAllThis() {
- return PromiseAll(this);
- }
- function PromiseMapSeries(promises, fn) {
- return PromiseReduce(promises, fn, INTERNAL, INTERNAL);
- }
- Promise.prototype.each = function (fn) {
- return this.mapSeries(fn)
- ._then(promiseAllThis, undefined, undefined, this, undefined);
- };
- Promise.prototype.mapSeries = function (fn) {
- return PromiseReduce(this, fn, INTERNAL, INTERNAL);
- };
- Promise.each = function (promises, fn) {
- return PromiseMapSeries(promises, fn)
- ._then(promiseAllThis, undefined, undefined, promises, undefined);
- };
- Promise.mapSeries = PromiseMapSeries;
- };
- },{}],12:[function(_dereq_,module,exports){
- "use strict";
- var es5 = _dereq_("./es5");
- var Objectfreeze = es5.freeze;
- var util = _dereq_("./util");
- var inherits = util.inherits;
- var notEnumerableProp = util.notEnumerableProp;
- function subError(nameProperty, defaultMessage) {
- function SubError(message) {
- if (!(this instanceof SubError)) return new SubError(message);
- notEnumerableProp(this, "message",
- typeof message === "string" ? message : defaultMessage);
- notEnumerableProp(this, "name", nameProperty);
- if (Error.captureStackTrace) {
- Error.captureStackTrace(this, this.constructor);
- } else {
- Error.call(this);
- }
- }
- inherits(SubError, Error);
- return SubError;
- }
- var _TypeError, _RangeError;
- var Warning = subError("Warning", "warning");
- var CancellationError = subError("CancellationError", "cancellation error");
- var TimeoutError = subError("TimeoutError", "timeout error");
- var AggregateError = subError("AggregateError", "aggregate error");
- try {
- _TypeError = TypeError;
- _RangeError = RangeError;
- } catch(e) {
- _TypeError = subError("TypeError", "type error");
- _RangeError = subError("RangeError", "range error");
- }
- var methods = ("join pop push shift unshift slice filter forEach some " +
- "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" ");
- for (var i = 0; i < methods.length; ++i) {
- if (typeof Array.prototype[methods[i]] === "function") {
- AggregateError.prototype[methods[i]] = Array.prototype[methods[i]];
- }
- }
- es5.defineProperty(AggregateError.prototype, "length", {
- value: 0,
- configurable: false,
- writable: true,
- enumerable: true
- });
- AggregateError.prototype["isOperational"] = true;
- var level = 0;
- AggregateError.prototype.toString = function() {
- var indent = Array(level * 4 + 1).join(" ");
- var ret = "\n" + indent + "AggregateError of:" + "\n";
- level++;
- indent = Array(level * 4 + 1).join(" ");
- for (var i = 0; i < this.length; ++i) {
- var str = this[i] === this ? "[Circular AggregateError]" : this[i] + "";
- var lines = str.split("\n");
- for (var j = 0; j < lines.length; ++j) {
- lines[j] = indent + lines[j];
- }
- str = lines.join("\n");
- ret += str + "\n";
- }
- level--;
- return ret;
- };
- function OperationalError(message) {
- if (!(this instanceof OperationalError))
- return new OperationalError(message);
- notEnumerableProp(this, "name", "OperationalError");
- notEnumerableProp(this, "message", message);
- this.cause = message;
- this["isOperational"] = true;
- if (message instanceof Error) {
- notEnumerableProp(this, "message", message.message);
- notEnumerableProp(this, "stack", message.stack);
- } else if (Error.captureStackTrace) {
- Error.captureStackTrace(this, this.constructor);
- }
- }
- inherits(OperationalError, Error);
- var errorTypes = Error["__BluebirdErrorTypes__"];
- if (!errorTypes) {
- errorTypes = Objectfreeze({
- CancellationError: CancellationError,
- TimeoutError: TimeoutError,
- OperationalError: OperationalError,
- RejectionError: OperationalError,
- AggregateError: AggregateError
- });
- notEnumerableProp(Error, "__BluebirdErrorTypes__", errorTypes);
- }
- module.exports = {
- Error: Error,
- TypeError: _TypeError,
- RangeError: _RangeError,
- CancellationError: errorTypes.CancellationError,
- OperationalError: errorTypes.OperationalError,
- TimeoutError: errorTypes.TimeoutError,
- AggregateError: errorTypes.AggregateError,
- Warning: Warning
- };
- },{"./es5":13,"./util":36}],13:[function(_dereq_,module,exports){
- var isES5 = (function(){
- "use strict";
- return this === undefined;
- })();
- if (isES5) {
- module.exports = {
- freeze: Object.freeze,
- defineProperty: Object.defineProperty,
- getDescriptor: Object.getOwnPropertyDescriptor,
- keys: Object.keys,
- names: Object.getOwnPropertyNames,
- getPrototypeOf: Object.getPrototypeOf,
- isArray: Array.isArray,
- isES5: isES5,
- propertyIsWritable: function(obj, prop) {
- var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
- return !!(!descriptor || descriptor.writable || descriptor.set);
- }
- };
- } else {
- var has = {}.hasOwnProperty;
- var str = {}.toString;
- var proto = {}.constructor.prototype;
- var ObjectKeys = function (o) {
- var ret = [];
- for (var key in o) {
- if (has.call(o, key)) {
- ret.push(key);
- }
- }
- return ret;
- };
- var ObjectGetDescriptor = function(o, key) {
- return {value: o[key]};
- };
- var ObjectDefineProperty = function (o, key, desc) {
- o[key] = desc.value;
- return o;
- };
- var ObjectFreeze = function (obj) {
- return obj;
- };
- var ObjectGetPrototypeOf = function (obj) {
- try {
- return Object(obj).constructor.prototype;
- }
- catch (e) {
- return proto;
- }
- };
- var ArrayIsArray = function (obj) {
- try {
- return str.call(obj) === "[object Array]";
- }
- catch(e) {
- return false;
- }
- };
- module.exports = {
- isArray: ArrayIsArray,
- keys: ObjectKeys,
- names: ObjectKeys,
- defineProperty: ObjectDefineProperty,
- getDescriptor: ObjectGetDescriptor,
- freeze: ObjectFreeze,
- getPrototypeOf: ObjectGetPrototypeOf,
- isES5: isES5,
- propertyIsWritable: function() {
- return true;
- }
- };
- }
- },{}],14:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var PromiseMap = Promise.map;
- Promise.prototype.filter = function (fn, options) {
- return PromiseMap(this, fn, options, INTERNAL);
- };
- Promise.filter = function (promises, fn, options) {
- return PromiseMap(promises, fn, options, INTERNAL);
- };
- };
- },{}],15:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, tryConvertToPromise) {
- var util = _dereq_("./util");
- var CancellationError = Promise.CancellationError;
- var errorObj = util.errorObj;
- function FinallyHandlerCancelReaction(finallyHandler) {
- this.finallyHandler = finallyHandler;
- }
- FinallyHandlerCancelReaction.prototype._resultCancelled = function() {
- checkCancel(this.finallyHandler);
- };
- function checkCancel(ctx, reason) {
- if (ctx.cancelPromise != null) {
- if (arguments.length > 1) {
- ctx.cancelPromise._reject(reason);
- } else {
- ctx.cancelPromise._cancel();
- }
- ctx.cancelPromise = null;
- return true;
- }
- return false;
- }
- function succeed() {
- return finallyHandler.call(this, this.promise._target()._settledValue());
- }
- function fail(reason) {
- if (checkCancel(this, reason)) return;
- errorObj.e = reason;
- return errorObj;
- }
- function finallyHandler(reasonOrValue) {
- var promise = this.promise;
- var handler = this.handler;
- if (!this.called) {
- this.called = true;
- var ret = this.type === 0
- ? handler.call(promise._boundValue())
- : handler.call(promise._boundValue(), reasonOrValue);
- if (ret !== undefined) {
- var maybePromise = tryConvertToPromise(ret, promise);
- if (maybePromise instanceof Promise) {
- if (this.cancelPromise != null) {
- if (maybePromise.isCancelled()) {
- var reason =
- new CancellationError("late cancellation observer");
- promise._attachExtraTrace(reason);
- errorObj.e = reason;
- return errorObj;
- } else if (maybePromise.isPending()) {
- maybePromise._attachCancellationCallback(
- new FinallyHandlerCancelReaction(this));
- }
- }
- return maybePromise._then(
- succeed, fail, undefined, this, undefined);
- }
- }
- }
- if (promise.isRejected()) {
- checkCancel(this);
- errorObj.e = reasonOrValue;
- return errorObj;
- } else {
- checkCancel(this);
- return reasonOrValue;
- }
- }
- Promise.prototype._passThrough = function(handler, type, success, fail) {
- if (typeof handler !== "function") return this.then();
- return this._then(success, fail, undefined, {
- promise: this,
- handler: handler,
- called: false,
- cancelPromise: null,
- type: type
- }, undefined);
- };
- Promise.prototype.lastly =
- Promise.prototype["finally"] = function (handler) {
- return this._passThrough(handler,
- 0,
- finallyHandler,
- finallyHandler);
- };
- Promise.prototype.tap = function (handler) {
- return this._passThrough(handler, 1, finallyHandler);
- };
- return finallyHandler;
- };
- },{"./util":36}],16:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise,
- apiRejection,
- INTERNAL,
- tryConvertToPromise,
- Proxyable,
- debug) {
- var errors = _dereq_("./errors");
- var TypeError = errors.TypeError;
- var util = _dereq_("./util");
- var errorObj = util.errorObj;
- var tryCatch = util.tryCatch;
- var yieldHandlers = [];
- function promiseFromYieldHandler(value, yieldHandlers, traceParent) {
- for (var i = 0; i < yieldHandlers.length; ++i) {
- traceParent._pushContext();
- var result = tryCatch(yieldHandlers[i])(value);
- traceParent._popContext();
- if (result === errorObj) {
- traceParent._pushContext();
- var ret = Promise.reject(errorObj.e);
- traceParent._popContext();
- return ret;
- }
- var maybePromise = tryConvertToPromise(result, traceParent);
- if (maybePromise instanceof Promise) return maybePromise;
- }
- return null;
- }
- function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) {
- var promise = this._promise = new Promise(INTERNAL);
- promise._captureStackTrace();
- promise._setOnCancel(this);
- this._stack = stack;
- this._generatorFunction = generatorFunction;
- this._receiver = receiver;
- this._generator = undefined;
- this._yieldHandlers = typeof yieldHandler === "function"
- ? [yieldHandler].concat(yieldHandlers)
- : yieldHandlers;
- this._yieldedPromise = null;
- }
- util.inherits(PromiseSpawn, Proxyable);
- PromiseSpawn.prototype._isResolved = function() {
- return this.promise === null;
- };
- PromiseSpawn.prototype._cleanup = function() {
- this._promise = this._generator = null;
- };
- PromiseSpawn.prototype._promiseCancelled = function() {
- if (this._isResolved()) return;
- var implementsReturn = typeof this._generator["return"] !== "undefined";
- var result;
- if (!implementsReturn) {
- var reason = new Promise.CancellationError(
- "generator .return() sentinel");
- Promise.coroutine.returnSentinel = reason;
- this._promise._attachExtraTrace(reason);
- this._promise._pushContext();
- result = tryCatch(this._generator["throw"]).call(this._generator,
- reason);
- this._promise._popContext();
- if (result === errorObj && result.e === reason) {
- result = null;
- }
- } else {
- this._promise._pushContext();
- result = tryCatch(this._generator["return"]).call(this._generator,
- undefined);
- this._promise._popContext();
- }
- var promise = this._promise;
- this._cleanup();
- if (result === errorObj) {
- promise._rejectCallback(result.e, false);
- } else {
- promise.cancel();
- }
- };
- PromiseSpawn.prototype._promiseFulfilled = function(value) {
- this._yieldedPromise = null;
- this._promise._pushContext();
- var result = tryCatch(this._generator.next).call(this._generator, value);
- this._promise._popContext();
- this._continue(result);
- };
- PromiseSpawn.prototype._promiseRejected = function(reason) {
- this._yieldedPromise = null;
- this._promise._attachExtraTrace(reason);
- this._promise._pushContext();
- var result = tryCatch(this._generator["throw"])
- .call(this._generator, reason);
- this._promise._popContext();
- this._continue(result);
- };
- PromiseSpawn.prototype._resultCancelled = function() {
- if (this._yieldedPromise instanceof Promise) {
- var promise = this._yieldedPromise;
- this._yieldedPromise = null;
- promise.cancel();
- }
- };
- PromiseSpawn.prototype.promise = function () {
- return this._promise;
- };
- PromiseSpawn.prototype._run = function () {
- this._generator = this._generatorFunction.call(this._receiver);
- this._receiver =
- this._generatorFunction = undefined;
- this._promiseFulfilled(undefined);
- };
- PromiseSpawn.prototype._continue = function (result) {
- var promise = this._promise;
- if (result === errorObj) {
- this._cleanup();
- return promise._rejectCallback(result.e, false);
- }
- var value = result.value;
- if (result.done === true) {
- this._cleanup();
- return promise._resolveCallback(value);
- } else {
- var maybePromise = tryConvertToPromise(value, this._promise);
- if (!(maybePromise instanceof Promise)) {
- maybePromise =
- promiseFromYieldHandler(maybePromise,
- this._yieldHandlers,
- this._promise);
- if (maybePromise === null) {
- this._promiseRejected(
- new TypeError(
- "A value %s was yielded that could not be treated as a promise\u000a\u000a See http://goo.gl/MqrFmX\u000a\u000a".replace("%s", value) +
- "From coroutine:\u000a" +
- this._stack.split("\n").slice(1, -7).join("\n")
- )
- );
- return;
- }
- }
- maybePromise = maybePromise._target();
- var bitField = maybePromise._bitField;
- ;
- if (((bitField & 50397184) === 0)) {
- this._yieldedPromise = maybePromise;
- maybePromise._proxy(this, null);
- } else if (((bitField & 33554432) !== 0)) {
- this._promiseFulfilled(maybePromise._value());
- } else if (((bitField & 16777216) !== 0)) {
- this._promiseRejected(maybePromise._reason());
- } else {
- this._promiseCancelled();
- }
- }
- };
- Promise.coroutine = function (generatorFunction, options) {
- if (typeof generatorFunction !== "function") {
- throw new TypeError("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
- }
- var yieldHandler = Object(options).yieldHandler;
- var PromiseSpawn$ = PromiseSpawn;
- var stack = new Error().stack;
- return function () {
- var generator = generatorFunction.apply(this, arguments);
- var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler,
- stack);
- var ret = spawn.promise();
- spawn._generator = generator;
- spawn._promiseFulfilled(undefined);
- return ret;
- };
- };
- Promise.coroutine.addYieldHandler = function(fn) {
- if (typeof fn !== "function") {
- throw new TypeError("expecting a function but got " + util.classString(fn));
- }
- yieldHandlers.push(fn);
- };
- Promise.spawn = function (generatorFunction) {
- debug.deprecated("Promise.spawn()", "Promise.coroutine()");
- if (typeof generatorFunction !== "function") {
- return apiRejection("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
- }
- var spawn = new PromiseSpawn(generatorFunction, this);
- var ret = spawn.promise();
- spawn._run(Promise.spawn);
- return ret;
- };
- };
- },{"./errors":12,"./util":36}],17:[function(_dereq_,module,exports){
- "use strict";
- module.exports =
- function(Promise, PromiseArray, tryConvertToPromise, INTERNAL) {
- var util = _dereq_("./util");
- var canEvaluate = util.canEvaluate;
- var tryCatch = util.tryCatch;
- var errorObj = util.errorObj;
- var reject;
- if (!true) {
- if (canEvaluate) {
- var thenCallback = function(i) {
- return new Function("value", "holder", " \n\
- 'use strict'; \n\
- holder.pIndex = value; \n\
- holder.checkFulfillment(this); \n\
- ".replace(/Index/g, i));
- };
- var promiseSetter = function(i) {
- return new Function("promise", "holder", " \n\
- 'use strict'; \n\
- holder.pIndex = promise; \n\
- ".replace(/Index/g, i));
- };
- var generateHolderClass = function(total) {
- var props = new Array(total);
- for (var i = 0; i < props.length; ++i) {
- props[i] = "this.p" + (i+1);
- }
- var assignment = props.join(" = ") + " = null;";
- var cancellationCode= "var promise;\n" + props.map(function(prop) {
- return " \n\
- promise = " + prop + "; \n\
- if (promise instanceof Promise) { \n\
- promise.cancel(); \n\
- } \n\
- ";
- }).join("\n");
- var passedArguments = props.join(", ");
- var name = "Holder$" + total;
- var code = "return function(tryCatch, errorObj, Promise) { \n\
- 'use strict'; \n\
- function [TheName](fn) { \n\
- [TheProperties] \n\
- this.fn = fn; \n\
- this.now = 0; \n\
- } \n\
- [TheName].prototype.checkFulfillment = function(promise) { \n\
- var now = ++this.now; \n\
- if (now === [TheTotal]) { \n\
- promise._pushContext(); \n\
- var callback = this.fn; \n\
- var ret = tryCatch(callback)([ThePassedArguments]); \n\
- promise._popContext(); \n\
- if (ret === errorObj) { \n\
- promise._rejectCallback(ret.e, false); \n\
- } else { \n\
- promise._resolveCallback(ret); \n\
- } \n\
- } \n\
- }; \n\
- \n\
- [TheName].prototype._resultCancelled = function() { \n\
- [CancellationCode] \n\
- }; \n\
- \n\
- return [TheName]; \n\
- }(tryCatch, errorObj, Promise); \n\
- ";
- code = code.replace(/\[TheName\]/g, name)
- .replace(/\[TheTotal\]/g, total)
- .replace(/\[ThePassedArguments\]/g, passedArguments)
- .replace(/\[TheProperties\]/g, assignment)
- .replace(/\[CancellationCode\]/g, cancellationCode);
- return new Function("tryCatch", "errorObj", "Promise", code)
- (tryCatch, errorObj, Promise);
- };
- var holderClasses = [];
- var thenCallbacks = [];
- var promiseSetters = [];
- for (var i = 0; i < 8; ++i) {
- holderClasses.push(generateHolderClass(i + 1));
- thenCallbacks.push(thenCallback(i + 1));
- promiseSetters.push(promiseSetter(i + 1));
- }
- reject = function (reason) {
- this._reject(reason);
- };
- }}
- Promise.join = function () {
- var last = arguments.length - 1;
- var fn;
- if (last > 0 && typeof arguments[last] === "function") {
- fn = arguments[last];
- if (!true) {
- if (last <= 8 && canEvaluate) {
- var ret = new Promise(INTERNAL);
- ret._captureStackTrace();
- var HolderClass = holderClasses[last - 1];
- var holder = new HolderClass(fn);
- var callbacks = thenCallbacks;
- for (var i = 0; i < last; ++i) {
- var maybePromise = tryConvertToPromise(arguments[i], ret);
- if (maybePromise instanceof Promise) {
- maybePromise = maybePromise._target();
- var bitField = maybePromise._bitField;
- ;
- if (((bitField & 50397184) === 0)) {
- maybePromise._then(callbacks[i], reject,
- undefined, ret, holder);
- promiseSetters[i](maybePromise, holder);
- } else if (((bitField & 33554432) !== 0)) {
- callbacks[i].call(ret,
- maybePromise._value(), holder);
- } else if (((bitField & 16777216) !== 0)) {
- ret._reject(maybePromise._reason());
- } else {
- ret._cancel();
- }
- } else {
- callbacks[i].call(ret, maybePromise, holder);
- }
- }
- if (!ret._isFateSealed()) {
- ret._setAsyncGuaranteed();
- ret._setOnCancel(holder);
- }
- return ret;
- }
- }
- }
- var args = [].slice.call(arguments);;
- if (fn) args.pop();
- var ret = new PromiseArray(args).promise();
- return fn !== undefined ? ret.spread(fn) : ret;
- };
- };
- },{"./util":36}],18:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise,
- PromiseArray,
- apiRejection,
- tryConvertToPromise,
- INTERNAL,
- debug) {
- var getDomain = Promise._getDomain;
- var util = _dereq_("./util");
- var tryCatch = util.tryCatch;
- var errorObj = util.errorObj;
- var EMPTY_ARRAY = [];
- function MappingPromiseArray(promises, fn, limit, _filter) {
- this.constructor$(promises);
- this._promise._captureStackTrace();
- var domain = getDomain();
- this._callback = domain === null ? fn : domain.bind(fn);
- this._preservedValues = _filter === INTERNAL
- ? new Array(this.length())
- : null;
- this._limit = limit;
- this._inFlight = 0;
- this._queue = limit >= 1 ? [] : EMPTY_ARRAY;
- this._init$(undefined, -2);
- }
- util.inherits(MappingPromiseArray, PromiseArray);
- MappingPromiseArray.prototype._init = function () {};
- MappingPromiseArray.prototype._promiseFulfilled = function (value, index) {
- var values = this._values;
- var length = this.length();
- var preservedValues = this._preservedValues;
- var limit = this._limit;
- if (index < 0) {
- index = (index * -1) - 1;
- values[index] = value;
- if (limit >= 1) {
- this._inFlight--;
- this._drainQueue();
- if (this._isResolved()) return true;
- }
- } else {
- if (limit >= 1 && this._inFlight >= limit) {
- values[index] = value;
- this._queue.push(index);
- return false;
- }
- if (preservedValues !== null) preservedValues[index] = value;
- var promise = this._promise;
- var callback = this._callback;
- var receiver = promise._boundValue();
- promise._pushContext();
- var ret = tryCatch(callback).call(receiver, value, index, length);
- var promisesCreated = promise._popContext();
- debug.checkForgottenReturns(
- ret,
- promisesCreated,
- preservedValues !== null ? "Promise.filter" : "Promise.map",
- promise
- );
- if (ret === errorObj) {
- this._reject(ret.e);
- return true;
- }
- var maybePromise = tryConvertToPromise(ret, this._promise);
- if (maybePromise instanceof Promise) {
- maybePromise = maybePromise._target();
- var bitField = maybePromise._bitField;
- ;
- if (((bitField & 50397184) === 0)) {
- if (limit >= 1) this._inFlight++;
- values[index] = maybePromise;
- maybePromise._proxy(this, (index + 1) * -1);
- return false;
- } else if (((bitField & 33554432) !== 0)) {
- ret = maybePromise._value();
- } else if (((bitField & 16777216) !== 0)) {
- this._reject(maybePromise._reason());
- return true;
- } else {
- this._cancel();
- return true;
- }
- }
- values[index] = ret;
- }
- var totalResolved = ++this._totalResolved;
- if (totalResolved >= length) {
- if (preservedValues !== null) {
- this._filter(values, preservedValues);
- } else {
- this._resolve(values);
- }
- return true;
- }
- return false;
- };
- MappingPromiseArray.prototype._drainQueue = function () {
- var queue = this._queue;
- var limit = this._limit;
- var values = this._values;
- while (queue.length > 0 && this._inFlight < limit) {
- if (this._isResolved()) return;
- var index = queue.pop();
- this._promiseFulfilled(values[index], index);
- }
- };
- MappingPromiseArray.prototype._filter = function (booleans, values) {
- var len = values.length;
- var ret = new Array(len);
- var j = 0;
- for (var i = 0; i < len; ++i) {
- if (booleans[i]) ret[j++] = values[i];
- }
- ret.length = j;
- this._resolve(ret);
- };
- MappingPromiseArray.prototype.preservedValues = function () {
- return this._preservedValues;
- };
- function map(promises, fn, options, _filter) {
- if (typeof fn !== "function") {
- return apiRejection("expecting a function but got " + util.classString(fn));
- }
- var limit = typeof options === "object" && options !== null
- ? options.concurrency
- : 0;
- limit = typeof limit === "number" &&
- isFinite(limit) && limit >= 1 ? limit : 0;
- return new MappingPromiseArray(promises, fn, limit, _filter).promise();
- }
- Promise.prototype.map = function (fn, options) {
- return map(this, fn, options, null);
- };
- Promise.map = function (promises, fn, options, _filter) {
- return map(promises, fn, options, _filter);
- };
- };
- },{"./util":36}],19:[function(_dereq_,module,exports){
- "use strict";
- module.exports =
- function(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug) {
- var util = _dereq_("./util");
- var tryCatch = util.tryCatch;
- Promise.method = function (fn) {
- if (typeof fn !== "function") {
- throw new Promise.TypeError("expecting a function but got " + util.classString(fn));
- }
- return function () {
- var ret = new Promise(INTERNAL);
- ret._captureStackTrace();
- ret._pushContext();
- var value = tryCatch(fn).apply(this, arguments);
- ret._popContext();
- ret._resolveFromSyncValue(value);
- return ret;
- };
- };
- Promise.attempt = Promise["try"] = function (fn) {
- if (typeof fn !== "function") {
- return apiRejection("expecting a function but got " + util.classString(fn));
- }
- var ret = new Promise(INTERNAL);
- ret._captureStackTrace();
- ret._pushContext();
- var value;
- if (arguments.length > 1) {
- debug.deprecated("calling Promise.try with more than 1 argument");
- var arg = arguments[1];
- var ctx = arguments[2];
- value = util.isArray(arg) ? tryCatch(fn).apply(ctx, arg)
- : tryCatch(fn).call(ctx, arg);
- } else {
- value = tryCatch(fn)();
- }
- ret._popContext();
- ret._resolveFromSyncValue(value);
- return ret;
- };
- Promise.prototype._resolveFromSyncValue = function (value) {
- if (value === util.errorObj) {
- this._rejectCallback(value.e, false);
- } else {
- this._resolveCallback(value, true);
- }
- };
- };
- },{"./util":36}],20:[function(_dereq_,module,exports){
- "use strict";
- var util = _dereq_("./util");
- var maybeWrapAsError = util.maybeWrapAsError;
- var errors = _dereq_("./errors");
- var OperationalError = errors.OperationalError;
- var es5 = _dereq_("./es5");
- function isUntypedError(obj) {
- return obj instanceof Error &&
- es5.getPrototypeOf(obj) === Error.prototype;
- }
- var rErrorKey = /^(?:name|message|stack|cause)$/;
- function wrapAsOperationalError(obj) {
- var ret;
- if (isUntypedError(obj)) {
- ret = new OperationalError(obj);
- ret.name = obj.name;
- ret.message = obj.message;
- ret.stack = obj.stack;
- var keys = es5.keys(obj);
- for (var i = 0; i < keys.length; ++i) {
- var key = keys[i];
- if (!rErrorKey.test(key)) {
- ret[key] = obj[key];
- }
- }
- return ret;
- }
- util.markAsOriginatingFromRejection(obj);
- return obj;
- }
- function nodebackForPromise(promise, multiArgs) {
- return function(err, value) {
- if (promise === null) return;
- if (err) {
- var wrapped = wrapAsOperationalError(maybeWrapAsError(err));
- promise._attachExtraTrace(wrapped);
- promise._reject(wrapped);
- } else if (!multiArgs) {
- promise._fulfill(value);
- } else {
- var args = [].slice.call(arguments, 1);;
- promise._fulfill(args);
- }
- promise = null;
- };
- }
- module.exports = nodebackForPromise;
- },{"./errors":12,"./es5":13,"./util":36}],21:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise) {
- var util = _dereq_("./util");
- var async = Promise._async;
- var tryCatch = util.tryCatch;
- var errorObj = util.errorObj;
- function spreadAdapter(val, nodeback) {
- var promise = this;
- if (!util.isArray(val)) return successAdapter.call(promise, val, nodeback);
- var ret =
- tryCatch(nodeback).apply(promise._boundValue(), [null].concat(val));
- if (ret === errorObj) {
- async.throwLater(ret.e);
- }
- }
- function successAdapter(val, nodeback) {
- var promise = this;
- var receiver = promise._boundValue();
- var ret = val === undefined
- ? tryCatch(nodeback).call(receiver, null)
- : tryCatch(nodeback).call(receiver, null, val);
- if (ret === errorObj) {
- async.throwLater(ret.e);
- }
- }
- function errorAdapter(reason, nodeback) {
- var promise = this;
- if (!reason) {
- var newReason = new Error(reason + "");
- newReason.cause = reason;
- reason = newReason;
- }
- var ret = tryCatch(nodeback).call(promise._boundValue(), reason);
- if (ret === errorObj) {
- async.throwLater(ret.e);
- }
- }
- Promise.prototype.asCallback = Promise.prototype.nodeify = function (nodeback,
- options) {
- if (typeof nodeback == "function") {
- var adapter = successAdapter;
- if (options !== undefined && Object(options).spread) {
- adapter = spreadAdapter;
- }
- this._then(
- adapter,
- errorAdapter,
- undefined,
- this,
- nodeback
- );
- }
- return this;
- };
- };
- },{"./util":36}],22:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function() {
- var makeSelfResolutionError = function () {
- return new TypeError("circular promise resolution chain\u000a\u000a See http://goo.gl/MqrFmX\u000a");
- };
- var reflectHandler = function() {
- return new Promise.PromiseInspection(this._target());
- };
- var apiRejection = function(msg) {
- return Promise.reject(new TypeError(msg));
- };
- function Proxyable() {}
- var UNDEFINED_BINDING = {};
- var util = _dereq_("./util");
- var getDomain;
- if (util.isNode) {
- getDomain = function() {
- var ret = process.domain;
- if (ret === undefined) ret = null;
- return ret;
- };
- } else {
- getDomain = function() {
- return null;
- };
- }
- util.notEnumerableProp(Promise, "_getDomain", getDomain);
- var es5 = _dereq_("./es5");
- var Async = _dereq_("./async");
- var async = new Async();
- es5.defineProperty(Promise, "_async", {value: async});
- var errors = _dereq_("./errors");
- var TypeError = Promise.TypeError = errors.TypeError;
- Promise.RangeError = errors.RangeError;
- var CancellationError = Promise.CancellationError = errors.CancellationError;
- Promise.TimeoutError = errors.TimeoutError;
- Promise.OperationalError = errors.OperationalError;
- Promise.RejectionError = errors.OperationalError;
- Promise.AggregateError = errors.AggregateError;
- var INTERNAL = function(){};
- var APPLY = {};
- var NEXT_FILTER = {};
- var tryConvertToPromise = _dereq_("./thenables")(Promise, INTERNAL);
- var PromiseArray =
- _dereq_("./promise_array")(Promise, INTERNAL,
- tryConvertToPromise, apiRejection, Proxyable);
- var Context = _dereq_("./context")(Promise);
- /*jshint unused:false*/
- var createContext = Context.create;
- var debug = _dereq_("./debuggability")(Promise, Context);
- var CapturedTrace = debug.CapturedTrace;
- var finallyHandler = _dereq_("./finally")(Promise, tryConvertToPromise);
- var catchFilter = _dereq_("./catch_filter")(NEXT_FILTER);
- var nodebackForPromise = _dereq_("./nodeback");
- var errorObj = util.errorObj;
- var tryCatch = util.tryCatch;
- function check(self, executor) {
- if (typeof executor !== "function") {
- throw new TypeError("expecting a function but got " + util.classString(executor));
- }
- if (self.constructor !== Promise) {
- throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a See http://goo.gl/MqrFmX\u000a");
- }
- }
- function Promise(executor) {
- this._bitField = 0;
- this._fulfillmentHandler0 = undefined;
- this._rejectionHandler0 = undefined;
- this._promise0 = undefined;
- this._receiver0 = undefined;
- if (executor !== INTERNAL) {
- check(this, executor);
- this._resolveFromExecutor(executor);
- }
- this._promiseCreated();
- }
- Promise.prototype.toString = function () {
- return "[object Promise]";
- };
- Promise.prototype.caught = Promise.prototype["catch"] = function (fn) {
- var len = arguments.length;
- if (len > 1) {
- var catchInstances = new Array(len - 1),
- j = 0, i;
- for (i = 0; i < len - 1; ++i) {
- var item = arguments[i];
- if (util.isObject(item)) {
- catchInstances[j++] = item;
- } else {
- return apiRejection("expecting an object but got " + util.classString(item));
- }
- }
- catchInstances.length = j;
- fn = arguments[i];
- return this.then(undefined, catchFilter(catchInstances, fn, this));
- }
- return this.then(undefined, fn);
- };
- Promise.prototype.reflect = function () {
- return this._then(reflectHandler,
- reflectHandler, undefined, this, undefined);
- };
- Promise.prototype.then = function (didFulfill, didReject) {
- if (debug.warnings() && arguments.length > 0 &&
- typeof didFulfill !== "function" &&
- typeof didReject !== "function") {
- var msg = ".then() only accepts functions but was passed: " +
- util.classString(didFulfill);
- if (arguments.length > 1) {
- msg += ", " + util.classString(didReject);
- }
- this._warn(msg);
- }
- return this._then(didFulfill, didReject, undefined, undefined, undefined);
- };
- Promise.prototype.done = function (didFulfill, didReject) {
- var promise =
- this._then(didFulfill, didReject, undefined, undefined, undefined);
- promise._setIsFinal();
- };
- Promise.prototype.spread = function (fn) {
- if (typeof fn !== "function") {
- return apiRejection("expecting a function but got " + util.classString(fn));
- }
- return this.all()._then(fn, undefined, undefined, APPLY, undefined);
- };
- Promise.prototype.toJSON = function () {
- var ret = {
- isFulfilled: false,
- isRejected: false,
- fulfillmentValue: undefined,
- rejectionReason: undefined
- };
- if (this.isFulfilled()) {
- ret.fulfillmentValue = this.value();
- ret.isFulfilled = true;
- } else if (this.isRejected()) {
- ret.rejectionReason = this.reason();
- ret.isRejected = true;
- }
- return ret;
- };
- Promise.prototype.all = function () {
- if (arguments.length > 0) {
- this._warn(".all() was passed arguments but it does not take any");
- }
- return new PromiseArray(this).promise();
- };
- Promise.prototype.error = function (fn) {
- return this.caught(util.originatesFromRejection, fn);
- };
- Promise.is = function (val) {
- return val instanceof Promise;
- };
- Promise.fromNode = Promise.fromCallback = function(fn) {
- var ret = new Promise(INTERNAL);
- var multiArgs = arguments.length > 1 ? !!Object(arguments[1]).multiArgs
- : false;
- var result = tryCatch(fn)(nodebackForPromise(ret, multiArgs));
- if (result === errorObj) {
- ret._rejectCallback(result.e, true);
- }
- if (!ret._isFateSealed()) ret._setAsyncGuaranteed();
- return ret;
- };
- Promise.all = function (promises) {
- return new PromiseArray(promises).promise();
- };
- Promise.cast = function (obj) {
- var ret = tryConvertToPromise(obj);
- if (!(ret instanceof Promise)) {
- ret = new Promise(INTERNAL);
- ret._setFulfilled();
- ret._rejectionHandler0 = obj;
- }
- return ret;
- };
- Promise.resolve = Promise.fulfilled = Promise.cast;
- Promise.reject = Promise.rejected = function (reason) {
- var ret = new Promise(INTERNAL);
- ret._captureStackTrace();
- ret._rejectCallback(reason, true);
- return ret;
- };
- Promise.setScheduler = function(fn) {
- if (typeof fn !== "function") {
- throw new TypeError("expecting a function but got " + util.classString(fn));
- }
- var prev = async._schedule;
- async._schedule = fn;
- return prev;
- };
- Promise.prototype._then = function (
- didFulfill,
- didReject,
- _, receiver,
- internalData
- ) {
- var haveInternalData = internalData !== undefined;
- var promise = haveInternalData ? internalData : new Promise(INTERNAL);
- var target = this._target();
- var bitField = target._bitField;
- if (!haveInternalData) {
- promise._propagateFrom(this, 3);
- promise._captureStackTrace();
- if (receiver === undefined &&
- ((this._bitField & 2097152) !== 0)) {
- if (!((bitField & 50397184) === 0)) {
- receiver = this._boundValue();
- } else {
- receiver = target === this ? undefined : this._boundTo;
- }
- }
- }
- var domain = getDomain();
- if (!((bitField & 50397184) === 0)) {
- var handler, value, settler = target._settlePromiseCtx;
- if (((bitField & 33554432) !== 0)) {
- value = target._rejectionHandler0;
- handler = didFulfill;
- } else if (((bitField & 16777216) !== 0)) {
- value = target._fulfillmentHandler0;
- handler = didReject;
- target._unsetRejectionIsUnhandled();
- } else {
- settler = target._settlePromiseLateCancellationObserver;
- value = new CancellationError("late cancellation observer");
- target._attachExtraTrace(value);
- handler = didReject;
- }
- async.invoke(settler, target, {
- handler: domain === null ? handler
- : (typeof handler === "function" && domain.bind(handler)),
- promise: promise,
- receiver: receiver,
- value: value
- });
- } else {
- target._addCallbacks(didFulfill, didReject, promise, receiver, domain);
- }
- return promise;
- };
- Promise.prototype._length = function () {
- return this._bitField & 65535;
- };
- Promise.prototype._isFateSealed = function () {
- return (this._bitField & 117506048) !== 0;
- };
- Promise.prototype._isFollowing = function () {
- return (this._bitField & 67108864) === 67108864;
- };
- Promise.prototype._setLength = function (len) {
- this._bitField = (this._bitField & -65536) |
- (len & 65535);
- };
- Promise.prototype._setFulfilled = function () {
- this._bitField = this._bitField | 33554432;
- };
- Promise.prototype._setRejected = function () {
- this._bitField = this._bitField | 16777216;
- };
- Promise.prototype._setFollowing = function () {
- this._bitField = this._bitField | 67108864;
- };
- Promise.prototype._setIsFinal = function () {
- this._bitField = this._bitField | 4194304;
- };
- Promise.prototype._isFinal = function () {
- return (this._bitField & 4194304) > 0;
- };
- Promise.prototype._unsetCancelled = function() {
- this._bitField = this._bitField & (~65536);
- };
- Promise.prototype._setCancelled = function() {
- this._bitField = this._bitField | 65536;
- };
- Promise.prototype._setAsyncGuaranteed = function() {
- this._bitField = this._bitField | 134217728;
- };
- Promise.prototype._receiverAt = function (index) {
- var ret = index === 0 ? this._receiver0 : this[
- index * 4 - 4 + 3];
- if (ret === UNDEFINED_BINDING) {
- return undefined;
- } else if (ret === undefined && this._isBound()) {
- return this._boundValue();
- }
- return ret;
- };
- Promise.prototype._promiseAt = function (index) {
- return this[
- index * 4 - 4 + 2];
- };
- Promise.prototype._fulfillmentHandlerAt = function (index) {
- return this[
- index * 4 - 4 + 0];
- };
- Promise.prototype._rejectionHandlerAt = function (index) {
- return this[
- index * 4 - 4 + 1];
- };
- Promise.prototype._boundValue = function() {};
- Promise.prototype._migrateCallback0 = function (follower) {
- var bitField = follower._bitField;
- var fulfill = follower._fulfillmentHandler0;
- var reject = follower._rejectionHandler0;
- var promise = follower._promise0;
- var receiver = follower._receiverAt(0);
- if (receiver === undefined) receiver = UNDEFINED_BINDING;
- this._addCallbacks(fulfill, reject, promise, receiver, null);
- };
- Promise.prototype._migrateCallbackAt = function (follower, index) {
- var fulfill = follower._fulfillmentHandlerAt(index);
- var reject = follower._rejectionHandlerAt(index);
- var promise = follower._promiseAt(index);
- var receiver = follower._receiverAt(index);
- if (receiver === undefined) receiver = UNDEFINED_BINDING;
- this._addCallbacks(fulfill, reject, promise, receiver, null);
- };
- Promise.prototype._addCallbacks = function (
- fulfill,
- reject,
- promise,
- receiver,
- domain
- ) {
- var index = this._length();
- if (index >= 65535 - 4) {
- index = 0;
- this._setLength(0);
- }
- if (index === 0) {
- this._promise0 = promise;
- this._receiver0 = receiver;
- if (typeof fulfill === "function") {
- this._fulfillmentHandler0 =
- domain === null ? fulfill : domain.bind(fulfill);
- }
- if (typeof reject === "function") {
- this._rejectionHandler0 =
- domain === null ? reject : domain.bind(reject);
- }
- } else {
- var base = index * 4 - 4;
- this[base + 2] = promise;
- this[base + 3] = receiver;
- if (typeof fulfill === "function") {
- this[base + 0] =
- domain === null ? fulfill : domain.bind(fulfill);
- }
- if (typeof reject === "function") {
- this[base + 1] =
- domain === null ? reject : domain.bind(reject);
- }
- }
- this._setLength(index + 1);
- return index;
- };
- Promise.prototype._proxy = function (proxyable, arg) {
- this._addCallbacks(undefined, undefined, arg, proxyable, null);
- };
- Promise.prototype._resolveCallback = function(value, shouldBind) {
- if (((this._bitField & 117506048) !== 0)) return;
- if (value === this)
- return this._rejectCallback(makeSelfResolutionError(), false);
- var maybePromise = tryConvertToPromise(value, this);
- if (!(maybePromise instanceof Promise)) return this._fulfill(value);
- if (shouldBind) this._propagateFrom(maybePromise, 2);
- var promise = maybePromise._target();
- var bitField = promise._bitField;
- if (((bitField & 50397184) === 0)) {
- var len = this._length();
- if (len > 0) promise._migrateCallback0(this);
- for (var i = 1; i < len; ++i) {
- promise._migrateCallbackAt(this, i);
- }
- this._setFollowing();
- this._setLength(0);
- this._setFollowee(promise);
- } else if (((bitField & 33554432) !== 0)) {
- this._fulfill(promise._value());
- } else if (((bitField & 16777216) !== 0)) {
- this._reject(promise._reason());
- } else {
- var reason = new CancellationError("late cancellation observer");
- promise._attachExtraTrace(reason);
- this._reject(reason);
- }
- };
- Promise.prototype._rejectCallback = function(reason, synchronous) {
- var trace = util.ensureErrorObject(reason);
- var hasStack = trace === reason;
- if (!hasStack && debug.warnings()) {
- var message = "a promise was rejected with a non-error: " +
- util.classString(reason);
- this._warn(message, true);
- }
- this._attachExtraTrace(trace, synchronous ? hasStack : false);
- this._reject(reason);
- };
- Promise.prototype._resolveFromExecutor = function (executor) {
- var promise = this;
- this._captureStackTrace();
- this._pushContext();
- var synchronous = true;
- var r = this._execute(executor, function(value) {
- promise._resolveCallback(value);
- }, function (reason) {
- promise._rejectCallback(reason, synchronous);
- });
- synchronous = false;
- this._popContext();
- if (r !== undefined) {
- promise._rejectCallback(r, true);
- }
- };
- Promise.prototype._settlePromiseFromHandler = function (
- handler, receiver, value, promise
- ) {
- var bitField = promise._bitField;
- if (((bitField & 65536) !== 0)) return;
- promise._pushContext();
- var x;
- if (receiver === APPLY) {
- if (!value || typeof value.length !== "number") {
- x = errorObj;
- x.e = new TypeError("cannot .spread() a non-array: " +
- util.classString(value));
- } else {
- x = tryCatch(handler).apply(this._boundValue(), value);
- }
- } else {
- x = tryCatch(handler).call(receiver, value);
- }
- var promisesCreatedDuringHandlerInvocation = promise._popContext();
- bitField = promise._bitField;
- if (((bitField & 65536) !== 0)) return;
- if (x === NEXT_FILTER) {
- promise._reject(value);
- } else if (x === errorObj || x === promise) {
- var err = x === promise ? makeSelfResolutionError() : x.e;
- promise._rejectCallback(err, false);
- } else {
- if (x === undefined &&
- promisesCreatedDuringHandlerInvocation > 0 &&
- debug.longStackTraces() &&
- debug.warnings()) {
- promise._warn("a promise was created in a handler but " +
- "none were returned from it", true);
- }
- promise._resolveCallback(x);
- }
- };
- Promise.prototype._target = function() {
- var ret = this;
- while (ret._isFollowing()) ret = ret._followee();
- return ret;
- };
- Promise.prototype._followee = function() {
- return this._rejectionHandler0;
- };
- Promise.prototype._setFollowee = function(promise) {
- this._rejectionHandler0 = promise;
- };
- Promise.prototype._settlePromise = function(promise, handler, receiver, value) {
- var isPromise = promise instanceof Promise;
- var bitField = this._bitField;
- var asyncGuaranteed = ((bitField & 134217728) !== 0);
- if (((bitField & 65536) !== 0)) {
- if (isPromise) promise._invokeInternalOnCancel();
- if (handler === finallyHandler) {
- receiver.cancelPromise = promise;
- if (tryCatch(handler).call(receiver, value) === errorObj) {
- promise._reject(errorObj.e);
- }
- } else if (handler === reflectHandler) {
- promise._fulfill(reflectHandler.call(receiver));
- } else if (receiver instanceof Proxyable) {
- receiver._promiseCancelled(promise);
- } else if (isPromise || promise instanceof PromiseArray) {
- promise._cancel();
- } else {
- receiver.cancel();
- }
- } else if (typeof handler === "function") {
- if (!isPromise) {
- handler.call(receiver, value, promise);
- } else {
- if (asyncGuaranteed) promise._setAsyncGuaranteed();
- this._settlePromiseFromHandler(handler, receiver, value, promise);
- }
- } else if (receiver instanceof Proxyable) {
- if (!receiver._isResolved()) {
- if (((bitField & 33554432) !== 0)) {
- receiver._promiseFulfilled(value, promise);
- } else {
- receiver._promiseRejected(value, promise);
- }
- }
- } else if (isPromise) {
- if (asyncGuaranteed) promise._setAsyncGuaranteed();
- if (((bitField & 33554432) !== 0)) {
- promise._fulfill(value);
- } else {
- promise._reject(value);
- }
- }
- };
- Promise.prototype._settlePromiseLateCancellationObserver = function(ctx) {
- var handler = ctx.handler;
- var promise = ctx.promise;
- var receiver = ctx.receiver;
- var value = ctx.value;
- if (typeof handler === "function") {
- if (!(promise instanceof Promise)) {
- handler.call(receiver, value, promise);
- } else {
- this._settlePromiseFromHandler(handler, receiver, value, promise);
- }
- } else if (promise instanceof Promise) {
- promise._reject(value);
- }
- };
- Promise.prototype._settlePromiseCtx = function(ctx) {
- this._settlePromise(ctx.promise, ctx.handler, ctx.receiver, ctx.value);
- };
- Promise.prototype._settlePromise0 = function(handler, value, bitField) {
- var promise = this._promise0;
- var receiver = this._receiverAt(0);
- this._promise0 = undefined;
- this._receiver0 = undefined;
- this._settlePromise(promise, handler, receiver, value);
- };
- Promise.prototype._clearCallbackDataAtIndex = function(index) {
- var base = index * 4 - 4;
- this[base + 2] =
- this[base + 3] =
- this[base + 0] =
- this[base + 1] = undefined;
- };
- Promise.prototype._fulfill = function (value) {
- var bitField = this._bitField;
- if (((bitField & 117506048) >>> 16)) return;
- if (value === this) {
- var err = makeSelfResolutionError();
- this._attachExtraTrace(err);
- return this._reject(err);
- }
- this._setFulfilled();
- this._rejectionHandler0 = value;
- if ((bitField & 65535) > 0) {
- if (((bitField & 134217728) !== 0)) {
- this._settlePromises();
- } else {
- async.settlePromises(this);
- }
- }
- };
- Promise.prototype._reject = function (reason) {
- var bitField = this._bitField;
- if (((bitField & 117506048) >>> 16)) return;
- this._setRejected();
- this._fulfillmentHandler0 = reason;
- if (this._isFinal()) {
- return async.fatalError(reason, util.isNode);
- }
- if ((bitField & 65535) > 0) {
- if (((bitField & 134217728) !== 0)) {
- this._settlePromises();
- } else {
- async.settlePromises(this);
- }
- } else {
- this._ensurePossibleRejectionHandled();
- }
- };
- Promise.prototype._fulfillPromises = function (len, value) {
- for (var i = 1; i < len; i++) {
- var handler = this._fulfillmentHandlerAt(i);
- var promise = this._promiseAt(i);
- var receiver = this._receiverAt(i);
- this._clearCallbackDataAtIndex(i);
- this._settlePromise(promise, handler, receiver, value);
- }
- };
- Promise.prototype._rejectPromises = function (len, reason) {
- for (var i = 1; i < len; i++) {
- var handler = this._rejectionHandlerAt(i);
- var promise = this._promiseAt(i);
- var receiver = this._receiverAt(i);
- this._clearCallbackDataAtIndex(i);
- this._settlePromise(promise, handler, receiver, reason);
- }
- };
- Promise.prototype._settlePromises = function () {
- var bitField = this._bitField;
- var len = (bitField & 65535);
- if (len > 0) {
- if (((bitField & 16842752) !== 0)) {
- var reason = this._fulfillmentHandler0;
- this._settlePromise0(this._rejectionHandler0, reason, bitField);
- this._rejectPromises(len, reason);
- } else {
- var value = this._rejectionHandler0;
- this._settlePromise0(this._fulfillmentHandler0, value, bitField);
- this._fulfillPromises(len, value);
- }
- this._setLength(0);
- }
- this._clearCancellationData();
- };
- Promise.prototype._settledValue = function() {
- var bitField = this._bitField;
- if (((bitField & 33554432) !== 0)) {
- return this._rejectionHandler0;
- } else if (((bitField & 16777216) !== 0)) {
- return this._fulfillmentHandler0;
- }
- };
- function deferResolve(v) {this.promise._resolveCallback(v);}
- function deferReject(v) {this.promise._rejectCallback(v, false);}
- Promise.defer = Promise.pending = function() {
- debug.deprecated("Promise.defer", "new Promise");
- var promise = new Promise(INTERNAL);
- return {
- promise: promise,
- resolve: deferResolve,
- reject: deferReject
- };
- };
- util.notEnumerableProp(Promise,
- "_makeSelfResolutionError",
- makeSelfResolutionError);
- _dereq_("./method")(Promise, INTERNAL, tryConvertToPromise, apiRejection,
- debug);
- _dereq_("./bind")(Promise, INTERNAL, tryConvertToPromise, debug);
- _dereq_("./cancel")(Promise, PromiseArray, apiRejection, debug);
- _dereq_("./direct_resolve")(Promise);
- _dereq_("./synchronous_inspection")(Promise);
- _dereq_("./join")(
- Promise, PromiseArray, tryConvertToPromise, INTERNAL, debug);
- Promise.Promise = Promise;
- _dereq_('./map.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
- _dereq_('./using.js')(Promise, apiRejection, tryConvertToPromise, createContext, INTERNAL, debug);
- _dereq_('./timers.js')(Promise, INTERNAL);
- _dereq_('./generators.js')(Promise, apiRejection, INTERNAL, tryConvertToPromise, Proxyable, debug);
- _dereq_('./nodeify.js')(Promise);
- _dereq_('./call_get.js')(Promise);
- _dereq_('./props.js')(Promise, PromiseArray, tryConvertToPromise, apiRejection);
- _dereq_('./race.js')(Promise, INTERNAL, tryConvertToPromise, apiRejection);
- _dereq_('./reduce.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
- _dereq_('./settle.js')(Promise, PromiseArray, debug);
- _dereq_('./some.js')(Promise, PromiseArray, apiRejection);
- _dereq_('./promisify.js')(Promise, INTERNAL);
- _dereq_('./any.js')(Promise);
- _dereq_('./each.js')(Promise, INTERNAL);
- _dereq_('./filter.js')(Promise, INTERNAL);
-
- util.toFastProperties(Promise);
- util.toFastProperties(Promise.prototype);
- function fillTypes(value) {
- var p = new Promise(INTERNAL);
- p._fulfillmentHandler0 = value;
- p._rejectionHandler0 = value;
- p._promise0 = value;
- p._receiver0 = value;
- }
- // Complete slack tracking, opt out of field-type tracking and
- // stabilize map
- fillTypes({a: 1});
- fillTypes({b: 2});
- fillTypes({c: 3});
- fillTypes(1);
- fillTypes(function(){});
- fillTypes(undefined);
- fillTypes(false);
- fillTypes(new Promise(INTERNAL));
- debug.setBounds(Async.firstLineError, util.lastLineError);
- return Promise;
- };
- },{"./any.js":1,"./async":2,"./bind":3,"./call_get.js":5,"./cancel":6,"./catch_filter":7,"./context":8,"./debuggability":9,"./direct_resolve":10,"./each.js":11,"./errors":12,"./es5":13,"./filter.js":14,"./finally":15,"./generators.js":16,"./join":17,"./map.js":18,"./method":19,"./nodeback":20,"./nodeify.js":21,"./promise_array":23,"./promisify.js":24,"./props.js":25,"./race.js":27,"./reduce.js":28,"./settle.js":30,"./some.js":31,"./synchronous_inspection":32,"./thenables":33,"./timers.js":34,"./using.js":35,"./util":36}],23:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, INTERNAL, tryConvertToPromise,
- apiRejection, Proxyable) {
- var util = _dereq_("./util");
- var isArray = util.isArray;
- function toResolutionValue(val) {
- switch(val) {
- case -2: return [];
- case -3: return {};
- }
- }
- function PromiseArray(values) {
- var promise = this._promise = new Promise(INTERNAL);
- if (values instanceof Promise) {
- promise._propagateFrom(values, 3);
- }
- promise._setOnCancel(this);
- this._values = values;
- this._length = 0;
- this._totalResolved = 0;
- this._init(undefined, -2);
- }
- util.inherits(PromiseArray, Proxyable);
- PromiseArray.prototype.length = function () {
- return this._length;
- };
- PromiseArray.prototype.promise = function () {
- return this._promise;
- };
- PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
- var values = tryConvertToPromise(this._values, this._promise);
- if (values instanceof Promise) {
- values = values._target();
- var bitField = values._bitField;
- ;
- this._values = values;
- if (((bitField & 50397184) === 0)) {
- this._promise._setAsyncGuaranteed();
- return values._then(
- init,
- this._reject,
- undefined,
- this,
- resolveValueIfEmpty
- );
- } else if (((bitField & 33554432) !== 0)) {
- values = values._value();
- } else if (((bitField & 16777216) !== 0)) {
- return this._reject(values._reason());
- } else {
- return this._cancel();
- }
- }
- values = util.asArray(values);
- if (values === null) {
- var err = apiRejection(
- "expecting an array or an iterable object but got " + util.classString(values)).reason();
- this._promise._rejectCallback(err, false);
- return;
- }
- if (values.length === 0) {
- if (resolveValueIfEmpty === -5) {
- this._resolveEmptyArray();
- }
- else {
- this._resolve(toResolutionValue(resolveValueIfEmpty));
- }
- return;
- }
- this._iterate(values);
- };
- PromiseArray.prototype._iterate = function(values) {
- var len = this.getActualLength(values.length);
- this._length = len;
- this._values = this.shouldCopyValues() ? new Array(len) : this._values;
- var result = this._promise;
- var isResolved = false;
- var bitField = null;
- for (var i = 0; i < len; ++i) {
- var maybePromise = tryConvertToPromise(values[i], result);
- if (maybePromise instanceof Promise) {
- maybePromise = maybePromise._target();
- bitField = maybePromise._bitField;
- } else {
- bitField = null;
- }
- if (isResolved) {
- if (bitField !== null) {
- maybePromise.suppressUnhandledRejections();
- }
- } else if (bitField !== null) {
- if (((bitField & 50397184) === 0)) {
- maybePromise._proxy(this, i);
- this._values[i] = maybePromise;
- } else if (((bitField & 33554432) !== 0)) {
- isResolved = this._promiseFulfilled(maybePromise._value(), i);
- } else if (((bitField & 16777216) !== 0)) {
- isResolved = this._promiseRejected(maybePromise._reason(), i);
- } else {
- isResolved = this._promiseCancelled(i);
- }
- } else {
- isResolved = this._promiseFulfilled(maybePromise, i);
- }
- }
- if (!isResolved) result._setAsyncGuaranteed();
- };
- PromiseArray.prototype._isResolved = function () {
- return this._values === null;
- };
- PromiseArray.prototype._resolve = function (value) {
- this._values = null;
- this._promise._fulfill(value);
- };
- PromiseArray.prototype._cancel = function() {
- if (this._isResolved() || !this._promise.isCancellable()) return;
- this._values = null;
- this._promise._cancel();
- };
- PromiseArray.prototype._reject = function (reason) {
- this._values = null;
- this._promise._rejectCallback(reason, false);
- };
- PromiseArray.prototype._promiseFulfilled = function (value, index) {
- this._values[index] = value;
- var totalResolved = ++this._totalResolved;
- if (totalResolved >= this._length) {
- this._resolve(this._values);
- return true;
- }
- return false;
- };
- PromiseArray.prototype._promiseCancelled = function() {
- this._cancel();
- return true;
- };
- PromiseArray.prototype._promiseRejected = function (reason) {
- this._totalResolved++;
- this._reject(reason);
- return true;
- };
- PromiseArray.prototype._resultCancelled = function() {
- if (this._isResolved()) return;
- var values = this._values;
- this._cancel();
- if (values instanceof Promise) {
- values.cancel();
- } else {
- for (var i = 0; i < values.length; ++i) {
- if (values[i] instanceof Promise) {
- values[i].cancel();
- }
- }
- }
- };
- PromiseArray.prototype.shouldCopyValues = function () {
- return true;
- };
- PromiseArray.prototype.getActualLength = function (len) {
- return len;
- };
- return PromiseArray;
- };
- },{"./util":36}],24:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var THIS = {};
- var util = _dereq_("./util");
- var nodebackForPromise = _dereq_("./nodeback");
- var withAppended = util.withAppended;
- var maybeWrapAsError = util.maybeWrapAsError;
- var canEvaluate = util.canEvaluate;
- var TypeError = _dereq_("./errors").TypeError;
- var defaultSuffix = "Async";
- var defaultPromisified = {__isPromisified__: true};
- var noCopyProps = [
- "arity", "length",
- "name",
- "arguments",
- "caller",
- "callee",
- "prototype",
- "__isPromisified__"
- ];
- var noCopyPropsPattern = new RegExp("^(?:" + noCopyProps.join("|") + ")$");
- var defaultFilter = function(name) {
- return util.isIdentifier(name) &&
- name.charAt(0) !== "_" &&
- name !== "constructor";
- };
- function propsFilter(key) {
- return !noCopyPropsPattern.test(key);
- }
- function isPromisified(fn) {
- try {
- return fn.__isPromisified__ === true;
- }
- catch (e) {
- return false;
- }
- }
- function hasPromisified(obj, key, suffix) {
- var val = util.getDataPropertyOrDefault(obj, key + suffix,
- defaultPromisified);
- return val ? isPromisified(val) : false;
- }
- function checkValid(ret, suffix, suffixRegexp) {
- for (var i = 0; i < ret.length; i += 2) {
- var key = ret[i];
- if (suffixRegexp.test(key)) {
- var keyWithoutAsyncSuffix = key.replace(suffixRegexp, "");
- for (var j = 0; j < ret.length; j += 2) {
- if (ret[j] === keyWithoutAsyncSuffix) {
- throw new TypeError("Cannot promisify an API that has normal methods with '%s'-suffix\u000a\u000a See http://goo.gl/MqrFmX\u000a"
- .replace("%s", suffix));
- }
- }
- }
- }
- }
- function promisifiableMethods(obj, suffix, suffixRegexp, filter) {
- var keys = util.inheritedDataKeys(obj);
- var ret = [];
- for (var i = 0; i < keys.length; ++i) {
- var key = keys[i];
- var value = obj[key];
- var passesDefaultFilter = filter === defaultFilter
- ? true : defaultFilter(key, value, obj);
- if (typeof value === "function" &&
- !isPromisified(value) &&
- !hasPromisified(obj, key, suffix) &&
- filter(key, value, obj, passesDefaultFilter)) {
- ret.push(key, value);
- }
- }
- checkValid(ret, suffix, suffixRegexp);
- return ret;
- }
- var escapeIdentRegex = function(str) {
- return str.replace(/([$])/, "\\$");
- };
- var makeNodePromisifiedEval;
- if (!true) {
- var switchCaseArgumentOrder = function(likelyArgumentCount) {
- var ret = [likelyArgumentCount];
- var min = Math.max(0, likelyArgumentCount - 1 - 3);
- for(var i = likelyArgumentCount - 1; i >= min; --i) {
- ret.push(i);
- }
- for(var i = likelyArgumentCount + 1; i <= 3; ++i) {
- ret.push(i);
- }
- return ret;
- };
- var argumentSequence = function(argumentCount) {
- return util.filledRange(argumentCount, "_arg", "");
- };
- var parameterDeclaration = function(parameterCount) {
- return util.filledRange(
- Math.max(parameterCount, 3), "_arg", "");
- };
- var parameterCount = function(fn) {
- if (typeof fn.length === "number") {
- return Math.max(Math.min(fn.length, 1023 + 1), 0);
- }
- return 0;
- };
- makeNodePromisifiedEval =
- function(callback, receiver, originalName, fn, _, multiArgs) {
- var newParameterCount = Math.max(0, parameterCount(fn) - 1);
- var argumentOrder = switchCaseArgumentOrder(newParameterCount);
- var shouldProxyThis = typeof callback === "string" || receiver === THIS;
- function generateCallForArgumentCount(count) {
- var args = argumentSequence(count).join(", ");
- var comma = count > 0 ? ", " : "";
- var ret;
- if (shouldProxyThis) {
- ret = "ret = callback.call(this, {{args}}, nodeback); break;\n";
- } else {
- ret = receiver === undefined
- ? "ret = callback({{args}}, nodeback); break;\n"
- : "ret = callback.call(receiver, {{args}}, nodeback); break;\n";
- }
- return ret.replace("{{args}}", args).replace(", ", comma);
- }
- function generateArgumentSwitchCase() {
- var ret = "";
- for (var i = 0; i < argumentOrder.length; ++i) {
- ret += "case " + argumentOrder[i] +":" +
- generateCallForArgumentCount(argumentOrder[i]);
- }
- ret += " \n\
- default: \n\
- var args = new Array(len + 1); \n\
- var i = 0; \n\
- for (var i = 0; i < len; ++i) { \n\
- args[i] = arguments[i]; \n\
- } \n\
- args[i] = nodeback; \n\
- [CodeForCall] \n\
- break; \n\
- ".replace("[CodeForCall]", (shouldProxyThis
- ? "ret = callback.apply(this, args);\n"
- : "ret = callback.apply(receiver, args);\n"));
- return ret;
- }
- var getFunctionCode = typeof callback === "string"
- ? ("this != null ? this['"+callback+"'] : fn")
- : "fn";
- var body = "'use strict'; \n\
- var ret = function (Parameters) { \n\
- 'use strict'; \n\
- var len = arguments.length; \n\
- var promise = new Promise(INTERNAL); \n\
- promise._captureStackTrace(); \n\
- var nodeback = nodebackForPromise(promise, " + multiArgs + "); \n\
- var ret; \n\
- var callback = tryCatch([GetFunctionCode]); \n\
- switch(len) { \n\
- [CodeForSwitchCase] \n\
- } \n\
- if (ret === errorObj) { \n\
- promise._rejectCallback(maybeWrapAsError(ret.e), true); \n\
- } \n\
- if (!promise._isFateSealed()) promise._setAsyncGuaranteed(); \n\
- return promise; \n\
- }; \n\
- notEnumerableProp(ret, '__isPromisified__', true); \n\
- return ret; \n\
- ".replace("[CodeForSwitchCase]", generateArgumentSwitchCase())
- .replace("[GetFunctionCode]", getFunctionCode);
- body = body.replace("Parameters", parameterDeclaration(newParameterCount));
- return new Function("Promise",
- "fn",
- "receiver",
- "withAppended",
- "maybeWrapAsError",
- "nodebackForPromise",
- "tryCatch",
- "errorObj",
- "notEnumerableProp",
- "INTERNAL",
- body)(
- Promise,
- fn,
- receiver,
- withAppended,
- maybeWrapAsError,
- nodebackForPromise,
- util.tryCatch,
- util.errorObj,
- util.notEnumerableProp,
- INTERNAL);
- };
- }
- function makeNodePromisifiedClosure(callback, receiver, _, fn, __, multiArgs) {
- var defaultThis = (function() {return this;})();
- var method = callback;
- if (typeof method === "string") {
- callback = fn;
- }
- function promisified() {
- var _receiver = receiver;
- if (receiver === THIS) _receiver = this;
- var promise = new Promise(INTERNAL);
- promise._captureStackTrace();
- var cb = typeof method === "string" && this !== defaultThis
- ? this[method] : callback;
- var fn = nodebackForPromise(promise, multiArgs);
- try {
- cb.apply(_receiver, withAppended(arguments, fn));
- } catch(e) {
- promise._rejectCallback(maybeWrapAsError(e), true);
- }
- if (!promise._isFateSealed()) promise._setAsyncGuaranteed();
- return promise;
- }
- util.notEnumerableProp(promisified, "__isPromisified__", true);
- return promisified;
- }
- var makeNodePromisified = canEvaluate
- ? makeNodePromisifiedEval
- : makeNodePromisifiedClosure;
- function promisifyAll(obj, suffix, filter, promisifier, multiArgs) {
- var suffixRegexp = new RegExp(escapeIdentRegex(suffix) + "$");
- var methods =
- promisifiableMethods(obj, suffix, suffixRegexp, filter);
- for (var i = 0, len = methods.length; i < len; i+= 2) {
- var key = methods[i];
- var fn = methods[i+1];
- var promisifiedKey = key + suffix;
- if (promisifier === makeNodePromisified) {
- obj[promisifiedKey] =
- makeNodePromisified(key, THIS, key, fn, suffix, multiArgs);
- } else {
- var promisified = promisifier(fn, function() {
- return makeNodePromisified(key, THIS, key,
- fn, suffix, multiArgs);
- });
- util.notEnumerableProp(promisified, "__isPromisified__", true);
- obj[promisifiedKey] = promisified;
- }
- }
- util.toFastProperties(obj);
- return obj;
- }
- function promisify(callback, receiver, multiArgs) {
- return makeNodePromisified(callback, receiver, undefined,
- callback, null, multiArgs);
- }
- Promise.promisify = function (fn, options) {
- if (typeof fn !== "function") {
- throw new TypeError("expecting a function but got " + util.classString(fn));
- }
- if (isPromisified(fn)) {
- return fn;
- }
- options = Object(options);
- var receiver = options.context === undefined ? THIS : options.context;
- var multiArgs = !!options.multiArgs;
- var ret = promisify(fn, receiver, multiArgs);
- util.copyDescriptors(fn, ret, propsFilter);
- return ret;
- };
- Promise.promisifyAll = function (target, options) {
- if (typeof target !== "function" && typeof target !== "object") {
- throw new TypeError("the target of promisifyAll must be an object or a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
- }
- options = Object(options);
- var multiArgs = !!options.multiArgs;
- var suffix = options.suffix;
- if (typeof suffix !== "string") suffix = defaultSuffix;
- var filter = options.filter;
- if (typeof filter !== "function") filter = defaultFilter;
- var promisifier = options.promisifier;
- if (typeof promisifier !== "function") promisifier = makeNodePromisified;
- if (!util.isIdentifier(suffix)) {
- throw new RangeError("suffix must be a valid identifier\u000a\u000a See http://goo.gl/MqrFmX\u000a");
- }
- var keys = util.inheritedDataKeys(target);
- for (var i = 0; i < keys.length; ++i) {
- var value = target[keys[i]];
- if (keys[i] !== "constructor" &&
- util.isClass(value)) {
- promisifyAll(value.prototype, suffix, filter, promisifier,
- multiArgs);
- promisifyAll(value, suffix, filter, promisifier, multiArgs);
- }
- }
- return promisifyAll(target, suffix, filter, promisifier, multiArgs);
- };
- };
- },{"./errors":12,"./nodeback":20,"./util":36}],25:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(
- Promise, PromiseArray, tryConvertToPromise, apiRejection) {
- var util = _dereq_("./util");
- var isObject = util.isObject;
- var es5 = _dereq_("./es5");
- var Es6Map;
- if (typeof Map === "function") Es6Map = Map;
- var mapToEntries = (function() {
- var index = 0;
- var size = 0;
- function extractEntry(value, key) {
- this[index] = value;
- this[index + size] = key;
- index++;
- }
- return function mapToEntries(map) {
- size = map.size;
- index = 0;
- var ret = new Array(map.size * 2);
- map.forEach(extractEntry, ret);
- return ret;
- };
- })();
- var entriesToMap = function(entries) {
- var ret = new Es6Map();
- var length = entries.length / 2 | 0;
- for (var i = 0; i < length; ++i) {
- var key = entries[length + i];
- var value = entries[i];
- ret.set(key, value);
- }
- return ret;
- };
- function PropertiesPromiseArray(obj) {
- var isMap = false;
- var entries;
- if (Es6Map !== undefined && obj instanceof Es6Map) {
- entries = mapToEntries(obj);
- isMap = true;
- } else {
- var keys = es5.keys(obj);
- var len = keys.length;
- entries = new Array(len * 2);
- for (var i = 0; i < len; ++i) {
- var key = keys[i];
- entries[i] = obj[key];
- entries[i + len] = key;
- }
- }
- this.constructor$(entries);
- this._isMap = isMap;
- this._init$(undefined, -3);
- }
- util.inherits(PropertiesPromiseArray, PromiseArray);
- PropertiesPromiseArray.prototype._init = function () {};
- PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) {
- this._values[index] = value;
- var totalResolved = ++this._totalResolved;
- if (totalResolved >= this._length) {
- var val;
- if (this._isMap) {
- val = entriesToMap(this._values);
- } else {
- val = {};
- var keyOffset = this.length();
- for (var i = 0, len = this.length(); i < len; ++i) {
- val[this._values[i + keyOffset]] = this._values[i];
- }
- }
- this._resolve(val);
- return true;
- }
- return false;
- };
- PropertiesPromiseArray.prototype.shouldCopyValues = function () {
- return false;
- };
- PropertiesPromiseArray.prototype.getActualLength = function (len) {
- return len >> 1;
- };
- function props(promises) {
- var ret;
- var castValue = tryConvertToPromise(promises);
- if (!isObject(castValue)) {
- return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/MqrFmX\u000a");
- } else if (castValue instanceof Promise) {
- ret = castValue._then(
- Promise.props, undefined, undefined, undefined, undefined);
- } else {
- ret = new PropertiesPromiseArray(castValue).promise();
- }
- if (castValue instanceof Promise) {
- ret._propagateFrom(castValue, 2);
- }
- return ret;
- }
- Promise.prototype.props = function () {
- return props(this);
- };
- Promise.props = function (promises) {
- return props(promises);
- };
- };
- },{"./es5":13,"./util":36}],26:[function(_dereq_,module,exports){
- "use strict";
- function arrayMove(src, srcIndex, dst, dstIndex, len) {
- for (var j = 0; j < len; ++j) {
- dst[j + dstIndex] = src[j + srcIndex];
- src[j + srcIndex] = void 0;
- }
- }
- function Queue(capacity) {
- this._capacity = capacity;
- this._length = 0;
- this._front = 0;
- }
- Queue.prototype._willBeOverCapacity = function (size) {
- return this._capacity < size;
- };
- Queue.prototype._pushOne = function (arg) {
- var length = this.length();
- this._checkCapacity(length + 1);
- var i = (this._front + length) & (this._capacity - 1);
- this[i] = arg;
- this._length = length + 1;
- };
- Queue.prototype._unshiftOne = function(value) {
- var capacity = this._capacity;
- this._checkCapacity(this.length() + 1);
- var front = this._front;
- var i = (((( front - 1 ) &
- ( capacity - 1) ) ^ capacity ) - capacity );
- this[i] = value;
- this._front = i;
- this._length = this.length() + 1;
- };
- Queue.prototype.unshift = function(fn, receiver, arg) {
- this._unshiftOne(arg);
- this._unshiftOne(receiver);
- this._unshiftOne(fn);
- };
- Queue.prototype.push = function (fn, receiver, arg) {
- var length = this.length() + 3;
- if (this._willBeOverCapacity(length)) {
- this._pushOne(fn);
- this._pushOne(receiver);
- this._pushOne(arg);
- return;
- }
- var j = this._front + length - 3;
- this._checkCapacity(length);
- var wrapMask = this._capacity - 1;
- this[(j + 0) & wrapMask] = fn;
- this[(j + 1) & wrapMask] = receiver;
- this[(j + 2) & wrapMask] = arg;
- this._length = length;
- };
- Queue.prototype.shift = function () {
- var front = this._front,
- ret = this[front];
- this[front] = undefined;
- this._front = (front + 1) & (this._capacity - 1);
- this._length--;
- return ret;
- };
- Queue.prototype.length = function () {
- return this._length;
- };
- Queue.prototype._checkCapacity = function (size) {
- if (this._capacity < size) {
- this._resizeTo(this._capacity << 1);
- }
- };
- Queue.prototype._resizeTo = function (capacity) {
- var oldCapacity = this._capacity;
- this._capacity = capacity;
- var front = this._front;
- var length = this._length;
- var moveItemsCount = (front + length) & (oldCapacity - 1);
- arrayMove(this, 0, this, oldCapacity, moveItemsCount);
- };
- module.exports = Queue;
- },{}],27:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(
- Promise, INTERNAL, tryConvertToPromise, apiRejection) {
- var util = _dereq_("./util");
- var raceLater = function (promise) {
- return promise.then(function(array) {
- return race(array, promise);
- });
- };
- function race(promises, parent) {
- var maybePromise = tryConvertToPromise(promises);
- if (maybePromise instanceof Promise) {
- return raceLater(maybePromise);
- } else {
- promises = util.asArray(promises);
- if (promises === null)
- return apiRejection("expecting an array or an iterable object but got " + util.classString(promises));
- }
- var ret = new Promise(INTERNAL);
- if (parent !== undefined) {
- ret._propagateFrom(parent, 3);
- }
- var fulfill = ret._fulfill;
- var reject = ret._reject;
- for (var i = 0, len = promises.length; i < len; ++i) {
- var val = promises[i];
- if (val === undefined && !(i in promises)) {
- continue;
- }
- Promise.cast(val)._then(fulfill, reject, undefined, ret, null);
- }
- return ret;
- }
- Promise.race = function (promises) {
- return race(promises, undefined);
- };
- Promise.prototype.race = function () {
- return race(this, undefined);
- };
- };
- },{"./util":36}],28:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise,
- PromiseArray,
- apiRejection,
- tryConvertToPromise,
- INTERNAL,
- debug) {
- var getDomain = Promise._getDomain;
- var util = _dereq_("./util");
- var tryCatch = util.tryCatch;
- function ReductionPromiseArray(promises, fn, initialValue, _each) {
- this.constructor$(promises);
- var domain = getDomain();
- this._fn = domain === null ? fn : domain.bind(fn);
- if (initialValue !== undefined) {
- initialValue = Promise.resolve(initialValue);
- initialValue._attachCancellationCallback(this);
- }
- this._initialValue = initialValue;
- this._currentCancellable = null;
- this._eachValues = _each === INTERNAL ? [] : undefined;
- this._promise._captureStackTrace();
- this._init$(undefined, -5);
- }
- util.inherits(ReductionPromiseArray, PromiseArray);
- ReductionPromiseArray.prototype._gotAccum = function(accum) {
- if (this._eachValues !== undefined && accum !== INTERNAL) {
- this._eachValues.push(accum);
- }
- };
- ReductionPromiseArray.prototype._eachComplete = function(value) {
- this._eachValues.push(value);
- return this._eachValues;
- };
- ReductionPromiseArray.prototype._init = function() {};
- ReductionPromiseArray.prototype._resolveEmptyArray = function() {
- this._resolve(this._eachValues !== undefined ? this._eachValues
- : this._initialValue);
- };
- ReductionPromiseArray.prototype.shouldCopyValues = function () {
- return false;
- };
- ReductionPromiseArray.prototype._resolve = function(value) {
- this._promise._resolveCallback(value);
- this._values = null;
- };
- ReductionPromiseArray.prototype._resultCancelled = function(sender) {
- if (sender === this._initialValue) return this._cancel();
- if (this._isResolved()) return;
- this._resultCancelled$();
- if (this._currentCancellable instanceof Promise) {
- this._currentCancellable.cancel();
- }
- if (this._initialValue instanceof Promise) {
- this._initialValue.cancel();
- }
- };
- ReductionPromiseArray.prototype._iterate = function (values) {
- this._values = values;
- var value;
- var i;
- var length = values.length;
- if (this._initialValue !== undefined) {
- value = this._initialValue;
- i = 0;
- } else {
- value = Promise.resolve(values[0]);
- i = 1;
- }
- this._currentCancellable = value;
- if (!value.isRejected()) {
- for (; i < length; ++i) {
- var ctx = {
- accum: null,
- value: values[i],
- index: i,
- length: length,
- array: this
- };
- value = value._then(gotAccum, undefined, undefined, ctx, undefined);
- }
- }
- if (this._eachValues !== undefined) {
- value = value
- ._then(this._eachComplete, undefined, undefined, this, undefined);
- }
- value._then(completed, completed, undefined, value, this);
- };
- Promise.prototype.reduce = function (fn, initialValue) {
- return reduce(this, fn, initialValue, null);
- };
- Promise.reduce = function (promises, fn, initialValue, _each) {
- return reduce(promises, fn, initialValue, _each);
- };
- function completed(valueOrReason, array) {
- if (this.isFulfilled()) {
- array._resolve(valueOrReason);
- } else {
- array._reject(valueOrReason);
- }
- }
- function reduce(promises, fn, initialValue, _each) {
- if (typeof fn !== "function") {
- return apiRejection("expecting a function but got " + util.classString(fn));
- }
- var array = new ReductionPromiseArray(promises, fn, initialValue, _each);
- return array.promise();
- }
- function gotAccum(accum) {
- this.accum = accum;
- this.array._gotAccum(accum);
- var value = tryConvertToPromise(this.value, this.array._promise);
- if (value instanceof Promise) {
- this.array._currentCancellable = value;
- return value._then(gotValue, undefined, undefined, this, undefined);
- } else {
- return gotValue.call(this, value);
- }
- }
- function gotValue(value) {
- var array = this.array;
- var promise = array._promise;
- var fn = tryCatch(array._fn);
- promise._pushContext();
- var ret;
- if (array._eachValues !== undefined) {
- ret = fn.call(promise._boundValue(), value, this.index, this.length);
- } else {
- ret = fn.call(promise._boundValue(),
- this.accum, value, this.index, this.length);
- }
- if (ret instanceof Promise) {
- array._currentCancellable = ret;
- }
- var promisesCreated = promise._popContext();
- debug.checkForgottenReturns(
- ret,
- promisesCreated,
- array._eachValues !== undefined ? "Promise.each" : "Promise.reduce",
- promise
- );
- return ret;
- }
- };
- },{"./util":36}],29:[function(_dereq_,module,exports){
- "use strict";
- var util = _dereq_("./util");
- var schedule;
- var noAsyncScheduler = function() {
- throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
- };
- if (util.isNode && typeof MutationObserver === "undefined") {
- var GlobalSetImmediate = global.setImmediate;
- var ProcessNextTick = process.nextTick;
- schedule = util.isRecentNode
- ? function(fn) { GlobalSetImmediate.call(global, fn); }
- : function(fn) { ProcessNextTick.call(process, fn); };
- } else if ((typeof MutationObserver !== "undefined") &&
- !(typeof window !== "undefined" &&
- window.navigator &&
- window.navigator.standalone)) {
- schedule = function(fn) {
- var div = document.createElement("div");
- var observer = new MutationObserver(fn);
- observer.observe(div, {attributes: true});
- return function() { div.classList.toggle("foo"); };
- };
- schedule.isStatic = true;
- } else if (typeof setImmediate !== "undefined") {
- schedule = function (fn) {
- setImmediate(fn);
- };
- } else if (typeof setTimeout !== "undefined") {
- schedule = function (fn) {
- setTimeout(fn, 0);
- };
- } else {
- schedule = noAsyncScheduler;
- }
- module.exports = schedule;
- },{"./util":36}],30:[function(_dereq_,module,exports){
- "use strict";
- module.exports =
- function(Promise, PromiseArray, debug) {
- var PromiseInspection = Promise.PromiseInspection;
- var util = _dereq_("./util");
- function SettledPromiseArray(values) {
- this.constructor$(values);
- }
- util.inherits(SettledPromiseArray, PromiseArray);
- SettledPromiseArray.prototype._promiseResolved = function (index, inspection) {
- this._values[index] = inspection;
- var totalResolved = ++this._totalResolved;
- if (totalResolved >= this._length) {
- this._resolve(this._values);
- return true;
- }
- return false;
- };
- SettledPromiseArray.prototype._promiseFulfilled = function (value, index) {
- var ret = new PromiseInspection();
- ret._bitField = 33554432;
- ret._settledValueField = value;
- return this._promiseResolved(index, ret);
- };
- SettledPromiseArray.prototype._promiseRejected = function (reason, index) {
- var ret = new PromiseInspection();
- ret._bitField = 16777216;
- ret._settledValueField = reason;
- return this._promiseResolved(index, ret);
- };
- Promise.settle = function (promises) {
- debug.deprecated(".settle()", ".reflect()");
- return new SettledPromiseArray(promises).promise();
- };
- Promise.prototype.settle = function () {
- return Promise.settle(this);
- };
- };
- },{"./util":36}],31:[function(_dereq_,module,exports){
- "use strict";
- module.exports =
- function(Promise, PromiseArray, apiRejection) {
- var util = _dereq_("./util");
- var RangeError = _dereq_("./errors").RangeError;
- var AggregateError = _dereq_("./errors").AggregateError;
- var isArray = util.isArray;
- var CANCELLATION = {};
- function SomePromiseArray(values) {
- this.constructor$(values);
- this._howMany = 0;
- this._unwrap = false;
- this._initialized = false;
- }
- util.inherits(SomePromiseArray, PromiseArray);
- SomePromiseArray.prototype._init = function () {
- if (!this._initialized) {
- return;
- }
- if (this._howMany === 0) {
- this._resolve([]);
- return;
- }
- this._init$(undefined, -5);
- var isArrayResolved = isArray(this._values);
- if (!this._isResolved() &&
- isArrayResolved &&
- this._howMany > this._canPossiblyFulfill()) {
- this._reject(this._getRangeError(this.length()));
- }
- };
- SomePromiseArray.prototype.init = function () {
- this._initialized = true;
- this._init();
- };
- SomePromiseArray.prototype.setUnwrap = function () {
- this._unwrap = true;
- };
- SomePromiseArray.prototype.howMany = function () {
- return this._howMany;
- };
- SomePromiseArray.prototype.setHowMany = function (count) {
- this._howMany = count;
- };
- SomePromiseArray.prototype._promiseFulfilled = function (value) {
- this._addFulfilled(value);
- if (this._fulfilled() === this.howMany()) {
- this._values.length = this.howMany();
- if (this.howMany() === 1 && this._unwrap) {
- this._resolve(this._values[0]);
- } else {
- this._resolve(this._values);
- }
- return true;
- }
- return false;
- };
- SomePromiseArray.prototype._promiseRejected = function (reason) {
- this._addRejected(reason);
- return this._checkOutcome();
- };
- SomePromiseArray.prototype._promiseCancelled = function () {
- if (this._values instanceof Promise || this._values == null) {
- return this._cancel();
- }
- this._addRejected(CANCELLATION);
- return this._checkOutcome();
- };
- SomePromiseArray.prototype._checkOutcome = function() {
- if (this.howMany() > this._canPossiblyFulfill()) {
- var e = new AggregateError();
- for (var i = this.length(); i < this._values.length; ++i) {
- if (this._values[i] !== CANCELLATION) {
- e.push(this._values[i]);
- }
- }
- if (e.length > 0) {
- this._reject(e);
- } else {
- this._cancel();
- }
- return true;
- }
- return false;
- };
- SomePromiseArray.prototype._fulfilled = function () {
- return this._totalResolved;
- };
- SomePromiseArray.prototype._rejected = function () {
- return this._values.length - this.length();
- };
- SomePromiseArray.prototype._addRejected = function (reason) {
- this._values.push(reason);
- };
- SomePromiseArray.prototype._addFulfilled = function (value) {
- this._values[this._totalResolved++] = value;
- };
- SomePromiseArray.prototype._canPossiblyFulfill = function () {
- return this.length() - this._rejected();
- };
- SomePromiseArray.prototype._getRangeError = function (count) {
- var message = "Input array must contain at least " +
- this._howMany + " items but contains only " + count + " items";
- return new RangeError(message);
- };
- SomePromiseArray.prototype._resolveEmptyArray = function () {
- this._reject(this._getRangeError(0));
- };
- function some(promises, howMany) {
- if ((howMany | 0) !== howMany || howMany < 0) {
- return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/MqrFmX\u000a");
- }
- var ret = new SomePromiseArray(promises);
- var promise = ret.promise();
- ret.setHowMany(howMany);
- ret.init();
- return promise;
- }
- Promise.some = function (promises, howMany) {
- return some(promises, howMany);
- };
- Promise.prototype.some = function (howMany) {
- return some(this, howMany);
- };
- Promise._SomePromiseArray = SomePromiseArray;
- };
- },{"./errors":12,"./util":36}],32:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise) {
- function PromiseInspection(promise) {
- if (promise !== undefined) {
- promise = promise._target();
- this._bitField = promise._bitField;
- this._settledValueField = promise._isFateSealed()
- ? promise._settledValue() : undefined;
- }
- else {
- this._bitField = 0;
- this._settledValueField = undefined;
- }
- }
- PromiseInspection.prototype._settledValue = function() {
- return this._settledValueField;
- };
- var value = PromiseInspection.prototype.value = function () {
- if (!this.isFulfilled()) {
- throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
- }
- return this._settledValue();
- };
- var reason = PromiseInspection.prototype.error =
- PromiseInspection.prototype.reason = function () {
- if (!this.isRejected()) {
- throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
- }
- return this._settledValue();
- };
- var isFulfilled = PromiseInspection.prototype.isFulfilled = function() {
- return (this._bitField & 33554432) !== 0;
- };
- var isRejected = PromiseInspection.prototype.isRejected = function () {
- return (this._bitField & 16777216) !== 0;
- };
- var isPending = PromiseInspection.prototype.isPending = function () {
- return (this._bitField & 50397184) === 0;
- };
- var isResolved = PromiseInspection.prototype.isResolved = function () {
- return (this._bitField & 50331648) !== 0;
- };
- PromiseInspection.prototype.isCancelled =
- Promise.prototype._isCancelled = function() {
- return (this._bitField & 65536) === 65536;
- };
- Promise.prototype.isCancelled = function() {
- return this._target()._isCancelled();
- };
- Promise.prototype.isPending = function() {
- return isPending.call(this._target());
- };
- Promise.prototype.isRejected = function() {
- return isRejected.call(this._target());
- };
- Promise.prototype.isFulfilled = function() {
- return isFulfilled.call(this._target());
- };
- Promise.prototype.isResolved = function() {
- return isResolved.call(this._target());
- };
- Promise.prototype.value = function() {
- return value.call(this._target());
- };
- Promise.prototype.reason = function() {
- var target = this._target();
- target._unsetRejectionIsUnhandled();
- return reason.call(target);
- };
- Promise.prototype._value = function() {
- return this._settledValue();
- };
- Promise.prototype._reason = function() {
- this._unsetRejectionIsUnhandled();
- return this._settledValue();
- };
- Promise.PromiseInspection = PromiseInspection;
- };
- },{}],33:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var util = _dereq_("./util");
- var errorObj = util.errorObj;
- var isObject = util.isObject;
- function tryConvertToPromise(obj, context) {
- if (isObject(obj)) {
- if (obj instanceof Promise) return obj;
- var then = getThen(obj);
- if (then === errorObj) {
- if (context) context._pushContext();
- var ret = Promise.reject(then.e);
- if (context) context._popContext();
- return ret;
- } else if (typeof then === "function") {
- if (isAnyBluebirdPromise(obj)) {
- var ret = new Promise(INTERNAL);
- obj._then(
- ret._fulfill,
- ret._reject,
- undefined,
- ret,
- null
- );
- return ret;
- }
- return doThenable(obj, then, context);
- }
- }
- return obj;
- }
- function doGetThen(obj) {
- return obj.then;
- }
- function getThen(obj) {
- try {
- return doGetThen(obj);
- } catch (e) {
- errorObj.e = e;
- return errorObj;
- }
- }
- var hasProp = {}.hasOwnProperty;
- function isAnyBluebirdPromise(obj) {
- return hasProp.call(obj, "_promise0");
- }
- function doThenable(x, then, context) {
- var promise = new Promise(INTERNAL);
- var ret = promise;
- if (context) context._pushContext();
- promise._captureStackTrace();
- if (context) context._popContext();
- var synchronous = true;
- var result = util.tryCatch(then).call(x, resolve, reject);
- synchronous = false;
- if (promise && result === errorObj) {
- promise._rejectCallback(result.e, true);
- promise = null;
- }
- function resolve(value) {
- if (!promise) return;
- promise._resolveCallback(value);
- promise = null;
- }
- function reject(reason) {
- if (!promise) return;
- promise._rejectCallback(reason, synchronous);
- promise = null;
- }
- return ret;
- }
- return tryConvertToPromise;
- };
- },{"./util":36}],34:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var util = _dereq_("./util");
- var TimeoutError = Promise.TimeoutError;
- var afterTimeout = function (promise, message) {
- if (!promise.isPending()) return;
- var err;
- if (typeof message !== "string") {
- if (message instanceof Error) {
- err = message;
- } else {
- err = new TimeoutError("operation timed out");
- }
- } else {
- err = new TimeoutError(message);
- }
- util.markAsOriginatingFromRejection(err);
- promise._attachExtraTrace(err);
- promise._reject(err);
- };
- var afterValue = function(value) { return delay(+this).thenReturn(value); };
- var delay = Promise.delay = function (ms, value) {
- var ret;
- if (value !== undefined) {
- ret = Promise.resolve(value)
- ._then(afterValue, null, null, ms, undefined);
- } else {
- ret = new Promise(INTERNAL);
- setTimeout(function() { ret._fulfill(); }, +ms);
- }
- ret._setAsyncGuaranteed();
- return ret;
- };
- Promise.prototype.delay = function (ms) {
- return delay(ms, this);
- };
- function successClear(value) {
- var handle = this;
- if (handle instanceof Number) handle = +handle;
- clearTimeout(handle);
- return value;
- }
- function failureClear(reason) {
- var handle = this;
- if (handle instanceof Number) handle = +handle;
- clearTimeout(handle);
- throw reason;
- }
- Promise.prototype.timeout = function (ms, message) {
- ms = +ms;
- var ret = this.then();
- var handle = setTimeout(function timeoutTimeout() {
- afterTimeout(ret, message);
- }, ms);
- return ret._then(successClear, failureClear, undefined, handle, undefined);
- };
- };
- },{"./util":36}],35:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function (Promise, apiRejection, tryConvertToPromise,
- createContext, INTERNAL, debug) {
- var util = _dereq_("./util");
- var TypeError = _dereq_("./errors").TypeError;
- var inherits = _dereq_("./util").inherits;
- var errorObj = util.errorObj;
- var tryCatch = util.tryCatch;
- function thrower(e) {
- setTimeout(function(){throw e;}, 0);
- }
- function castPreservingDisposable(thenable) {
- var maybePromise = tryConvertToPromise(thenable);
- if (maybePromise !== thenable &&
- typeof thenable._isDisposable === "function" &&
- typeof thenable._getDisposer === "function" &&
- thenable._isDisposable()) {
- maybePromise._setDisposable(thenable._getDisposer());
- }
- return maybePromise;
- }
- function dispose(resources, inspection) {
- var i = 0;
- var len = resources.length;
- var ret = new Promise(INTERNAL);
- function iterator() {
- if (i >= len) return ret._fulfill();
- var maybePromise = castPreservingDisposable(resources[i++]);
- if (maybePromise instanceof Promise &&
- maybePromise._isDisposable()) {
- try {
- maybePromise = tryConvertToPromise(
- maybePromise._getDisposer().tryDispose(inspection),
- resources.promise);
- } catch (e) {
- return thrower(e);
- }
- if (maybePromise instanceof Promise) {
- return maybePromise._then(iterator, thrower,
- null, null, null);
- }
- }
- iterator();
- }
- iterator();
- return ret;
- }
- function Disposer(data, promise, context) {
- this._data = data;
- this._promise = promise;
- this._context = context;
- }
- Disposer.prototype.data = function () {
- return this._data;
- };
- Disposer.prototype.promise = function () {
- return this._promise;
- };
- Disposer.prototype.resource = function () {
- if (this.promise().isFulfilled()) {
- return this.promise().value();
- }
- return null;
- };
- Disposer.prototype.tryDispose = function(inspection) {
- var resource = this.resource();
- var context = this._context;
- if (context !== undefined) context._pushContext();
- var ret = resource !== null
- ? this.doDispose(resource, inspection) : null;
- if (context !== undefined) context._popContext();
- this._promise._unsetDisposable();
- this._data = null;
- return ret;
- };
- Disposer.isDisposer = function (d) {
- return (d != null &&
- typeof d.resource === "function" &&
- typeof d.tryDispose === "function");
- };
- function FunctionDisposer(fn, promise, context) {
- this.constructor$(fn, promise, context);
- }
- inherits(FunctionDisposer, Disposer);
- FunctionDisposer.prototype.doDispose = function (resource, inspection) {
- var fn = this.data();
- return fn.call(resource, resource, inspection);
- };
- function maybeUnwrapDisposer(value) {
- if (Disposer.isDisposer(value)) {
- this.resources[this.index]._setDisposable(value);
- return value.promise();
- }
- return value;
- }
- function ResourceList(length) {
- this.length = length;
- this.promise = null;
- this[length-1] = null;
- }
- ResourceList.prototype._resultCancelled = function() {
- var len = this.length;
- for (var i = 0; i < len; ++i) {
- var item = this[i];
- if (item instanceof Promise) {
- item.cancel();
- }
- }
- };
- Promise.using = function () {
- var len = arguments.length;
- if (len < 2) return apiRejection(
- "you must pass at least 2 arguments to Promise.using");
- var fn = arguments[len - 1];
- if (typeof fn !== "function") {
- return apiRejection("expecting a function but got " + util.classString(fn));
- }
- var input;
- var spreadArgs = true;
- if (len === 2 && Array.isArray(arguments[0])) {
- input = arguments[0];
- len = input.length;
- spreadArgs = false;
- } else {
- input = arguments;
- len--;
- }
- var resources = new ResourceList(len);
- for (var i = 0; i < len; ++i) {
- var resource = input[i];
- if (Disposer.isDisposer(resource)) {
- var disposer = resource;
- resource = resource.promise();
- resource._setDisposable(disposer);
- } else {
- var maybePromise = tryConvertToPromise(resource);
- if (maybePromise instanceof Promise) {
- resource =
- maybePromise._then(maybeUnwrapDisposer, null, null, {
- resources: resources,
- index: i
- }, undefined);
- }
- }
- resources[i] = resource;
- }
- var reflectedResources = new Array(resources.length);
- for (var i = 0; i < reflectedResources.length; ++i) {
- reflectedResources[i] = Promise.resolve(resources[i]).reflect();
- }
- var resultPromise = Promise.all(reflectedResources)
- .then(function(inspections) {
- for (var i = 0; i < inspections.length; ++i) {
- var inspection = inspections[i];
- if (inspection.isRejected()) {
- errorObj.e = inspection.error();
- return errorObj;
- } else if (!inspection.isFulfilled()) {
- resultPromise.cancel();
- return;
- }
- inspections[i] = inspection.value();
- }
- promise._pushContext();
- fn = tryCatch(fn);
- var ret = spreadArgs
- ? fn.apply(undefined, inspections) : fn(inspections);
- var promisesCreated = promise._popContext();
- debug.checkForgottenReturns(
- ret, promisesCreated, "Promise.using", promise);
- return ret;
- });
- var promise = resultPromise.lastly(function() {
- var inspection = new Promise.PromiseInspection(resultPromise);
- return dispose(resources, inspection);
- });
- resources.promise = promise;
- promise._setOnCancel(resources);
- return promise;
- };
- Promise.prototype._setDisposable = function (disposer) {
- this._bitField = this._bitField | 131072;
- this._disposer = disposer;
- };
- Promise.prototype._isDisposable = function () {
- return (this._bitField & 131072) > 0;
- };
- Promise.prototype._getDisposer = function () {
- return this._disposer;
- };
- Promise.prototype._unsetDisposable = function () {
- this._bitField = this._bitField & (~131072);
- this._disposer = undefined;
- };
- Promise.prototype.disposer = function (fn) {
- if (typeof fn === "function") {
- return new FunctionDisposer(fn, this, createContext());
- }
- throw new TypeError();
- };
- };
- },{"./errors":12,"./util":36}],36:[function(_dereq_,module,exports){
- "use strict";
- var es5 = _dereq_("./es5");
- var canEvaluate = typeof navigator == "undefined";
- var errorObj = {e: {}};
- var tryCatchTarget;
- function tryCatcher() {
- try {
- var target = tryCatchTarget;
- tryCatchTarget = null;
- return target.apply(this, arguments);
- } catch (e) {
- errorObj.e = e;
- return errorObj;
- }
- }
- function tryCatch(fn) {
- tryCatchTarget = fn;
- return tryCatcher;
- }
- var inherits = function(Child, Parent) {
- var hasProp = {}.hasOwnProperty;
- function T() {
- this.constructor = Child;
- this.constructor$ = Parent;
- for (var propertyName in Parent.prototype) {
- if (hasProp.call(Parent.prototype, propertyName) &&
- propertyName.charAt(propertyName.length-1) !== "$"
- ) {
- this[propertyName + "$"] = Parent.prototype[propertyName];
- }
- }
- }
- T.prototype = Parent.prototype;
- Child.prototype = new T();
- return Child.prototype;
- };
- function isPrimitive(val) {
- return val == null || val === true || val === false ||
- typeof val === "string" || typeof val === "number";
- }
- function isObject(value) {
- return typeof value === "function" ||
- typeof value === "object" && value !== null;
- }
- function maybeWrapAsError(maybeError) {
- if (!isPrimitive(maybeError)) return maybeError;
- return new Error(safeToString(maybeError));
- }
- function withAppended(target, appendee) {
- var len = target.length;
- var ret = new Array(len + 1);
- var i;
- for (i = 0; i < len; ++i) {
- ret[i] = target[i];
- }
- ret[i] = appendee;
- return ret;
- }
- function getDataPropertyOrDefault(obj, key, defaultValue) {
- if (es5.isES5) {
- var desc = Object.getOwnPropertyDescriptor(obj, key);
- if (desc != null) {
- return desc.get == null && desc.set == null
- ? desc.value
- : defaultValue;
- }
- } else {
- return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
- }
- }
- function notEnumerableProp(obj, name, value) {
- if (isPrimitive(obj)) return obj;
- var descriptor = {
- value: value,
- configurable: true,
- enumerable: false,
- writable: true
- };
- es5.defineProperty(obj, name, descriptor);
- return obj;
- }
- function thrower(r) {
- throw r;
- }
- var inheritedDataKeys = (function() {
- var excludedPrototypes = [
- Array.prototype,
- Object.prototype,
- Function.prototype
- ];
- var isExcludedProto = function(val) {
- for (var i = 0; i < excludedPrototypes.length; ++i) {
- if (excludedPrototypes[i] === val) {
- return true;
- }
- }
- return false;
- };
- if (es5.isES5) {
- var getKeys = Object.getOwnPropertyNames;
- return function(obj) {
- var ret = [];
- var visitedKeys = Object.create(null);
- while (obj != null && !isExcludedProto(obj)) {
- var keys;
- try {
- keys = getKeys(obj);
- } catch (e) {
- return ret;
- }
- for (var i = 0; i < keys.length; ++i) {
- var key = keys[i];
- if (visitedKeys[key]) continue;
- visitedKeys[key] = true;
- var desc = Object.getOwnPropertyDescriptor(obj, key);
- if (desc != null && desc.get == null && desc.set == null) {
- ret.push(key);
- }
- }
- obj = es5.getPrototypeOf(obj);
- }
- return ret;
- };
- } else {
- var hasProp = {}.hasOwnProperty;
- return function(obj) {
- if (isExcludedProto(obj)) return [];
- var ret = [];
- /*jshint forin:false */
- enumeration: for (var key in obj) {
- if (hasProp.call(obj, key)) {
- ret.push(key);
- } else {
- for (var i = 0; i < excludedPrototypes.length; ++i) {
- if (hasProp.call(excludedPrototypes[i], key)) {
- continue enumeration;
- }
- }
- ret.push(key);
- }
- }
- return ret;
- };
- }
- })();
- var thisAssignmentPattern = /this\s*\.\s*\S+\s*=/;
- function isClass(fn) {
- try {
- if (typeof fn === "function") {
- var keys = es5.names(fn.prototype);
- var hasMethods = es5.isES5 && keys.length > 1;
- var hasMethodsOtherThanConstructor = keys.length > 0 &&
- !(keys.length === 1 && keys[0] === "constructor");
- var hasThisAssignmentAndStaticMethods =
- thisAssignmentPattern.test(fn + "") && es5.names(fn).length > 0;
- if (hasMethods || hasMethodsOtherThanConstructor ||
- hasThisAssignmentAndStaticMethods) {
- return true;
- }
- }
- return false;
- } catch (e) {
- return false;
- }
- }
- function toFastProperties(obj) {
- /*jshint -W027,-W055,-W031*/
- function FakeConstructor() {}
- FakeConstructor.prototype = obj;
- var l = 8;
- while (l--) new FakeConstructor();
- return obj;
- eval(obj);
- }
- var rident = /^[a-z$_][a-z$_0-9]*$/i;
- function isIdentifier(str) {
- return rident.test(str);
- }
- function filledRange(count, prefix, suffix) {
- var ret = new Array(count);
- for(var i = 0; i < count; ++i) {
- ret[i] = prefix + i + suffix;
- }
- return ret;
- }
- function safeToString(obj) {
- try {
- return obj + "";
- } catch (e) {
- return "[no string representation]";
- }
- }
- function markAsOriginatingFromRejection(e) {
- try {
- notEnumerableProp(e, "isOperational", true);
- }
- catch(ignore) {}
- }
- function originatesFromRejection(e) {
- if (e == null) return false;
- return ((e instanceof Error["__BluebirdErrorTypes__"].OperationalError) ||
- e["isOperational"] === true);
- }
- function canAttachTrace(obj) {
- return obj instanceof Error && es5.propertyIsWritable(obj, "stack");
- }
- var ensureErrorObject = (function() {
- if (!("stack" in new Error())) {
- return function(value) {
- if (canAttachTrace(value)) return value;
- try {throw new Error(safeToString(value));}
- catch(err) {return err;}
- };
- } else {
- return function(value) {
- if (canAttachTrace(value)) return value;
- return new Error(safeToString(value));
- };
- }
- })();
- function classString(obj) {
- return {}.toString.call(obj);
- }
- function copyDescriptors(from, to, filter) {
- var keys = es5.names(from);
- for (var i = 0; i < keys.length; ++i) {
- var key = keys[i];
- if (filter(key)) {
- try {
- es5.defineProperty(to, key, es5.getDescriptor(from, key));
- } catch (ignore) {}
- }
- }
- }
- var asArray = function(v) {
- if (es5.isArray(v)) {
- return v;
- }
- return null;
- };
- if (typeof Symbol !== "undefined" && Symbol.iterator) {
- var ArrayFrom = typeof Array.from === "function" ? function(v) {
- return Array.from(v);
- } : function(v) {
- var ret = [];
- var it = v[Symbol.iterator]();
- var itResult;
- while (!((itResult = it.next()).done)) {
- ret.push(itResult.value);
- }
- return ret;
- };
- asArray = function(v) {
- if (es5.isArray(v)) {
- return v;
- } else if (v != null && typeof v[Symbol.iterator] === "function") {
- return ArrayFrom(v);
- }
- return null;
- };
- }
- var isNode = typeof process !== "undefined" &&
- classString(process).toLowerCase() === "[object process]";
- function env(key, def) {
- return isNode ? process.env[key] : def;
- }
- var ret = {
- isClass: isClass,
- isIdentifier: isIdentifier,
- inheritedDataKeys: inheritedDataKeys,
- getDataPropertyOrDefault: getDataPropertyOrDefault,
- thrower: thrower,
- isArray: es5.isArray,
- asArray: asArray,
- notEnumerableProp: notEnumerableProp,
- isPrimitive: isPrimitive,
- isObject: isObject,
- canEvaluate: canEvaluate,
- errorObj: errorObj,
- tryCatch: tryCatch,
- inherits: inherits,
- withAppended: withAppended,
- maybeWrapAsError: maybeWrapAsError,
- toFastProperties: toFastProperties,
- filledRange: filledRange,
- toString: safeToString,
- canAttachTrace: canAttachTrace,
- ensureErrorObject: ensureErrorObject,
- originatesFromRejection: originatesFromRejection,
- markAsOriginatingFromRejection: markAsOriginatingFromRejection,
- classString: classString,
- copyDescriptors: copyDescriptors,
- hasDevTools: typeof chrome !== "undefined" && chrome &&
- typeof chrome.loadTimes === "function",
- isNode: isNode,
- env: env
- };
- ret.isRecentNode = ret.isNode && (function() {
- var version = process.versions.node.split(".").map(Number);
- return (version[0] === 0 && version[1] > 10) || (version[0] > 0);
- })();
- if (ret.isNode) ret.toFastProperties(process);
- try {throw new Error(); } catch (e) {ret.lastLineError = e;}
- module.exports = ret;
- },{"./es5":13}]},{},[4])(4)
- }); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; }
- }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
- },{"_process":215}],208:[function(require,module,exports){
- },{}],209:[function(require,module,exports){
- // Generated by CoffeeScript 1.10.0
- var Animator, Decoder, Gif, GifReader, Promise, gifler,
- bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
- GifReader = require('omggif').GifReader;
- Promise = require('bluebird');
- /*---
- head : 'gifler()'
- text :
- - This is the main entrypoint to the library.
- - Prepares and sends an XHR request to load the GIF file.
- - Returns a <b>Gif</b> instance for interacting with the library.
- args :
- url : 'URL to .gif file'
- return : 'a Gif instance object'
- */
- gifler = function(url) {
- var aync, promise, xhr;
- xhr = new XMLHttpRequest();
- xhr.open('GET', url, aync = true);
- xhr.responseType = 'arraybuffer';
- promise = new Promise(function(resolve, reject) {
- return xhr.onload = function(e) {
- return resolve(this.response);
- };
- });
- xhr.send();
- return new Gif(promise);
- };
- Gif = (function() {
- Gif.getCanvasElement = function(selector) {
- var element, ref;
- if (typeof selector === 'string' && ((ref = (element = document.querySelector(selector))) != null ? ref.tagName : void 0) === 'CANVAS') {
- return element;
- } else if ((selector != null ? selector.tagName : void 0) === 'CANVAS') {
- return selector;
- } else {
- throw new Error('Unexpected selector type. Valid types are query-selector-string/canvas-element');
- }
- };
- function Gif(dataPromise) {
- this._animatorPromise = dataPromise.then(function(data) {
- var reader;
- reader = new GifReader(new Uint8Array(data));
- return Decoder.decodeFramesAsync(reader).then(function(frames) {
- return new Animator(reader, frames);
- });
- });
- }
- /*---
- head : 'gif.animate()'
- text :
- - >
- Animates the loaded GIF, drawing each frame into the canvas.
- This matches the look of an <img> tag.
- args :
- selector : 'A <canvas> element or query selector for a <canvas> element.'
- */
- Gif.prototype.animate = function(selector) {
- var canvas;
- canvas = Gif.getCanvasElement(selector);
- return this._animatorPromise.then(function(animator) {
- return animator.animateInCanvas(canvas);
- });
- };
- /*---
- head : 'gif.frames()'
- text :
- - >
- Runs the animation on the loaded GIF, but passes the
- canvas context and GIF frame to the <b>onDrawFrame</b>
- callback for rendering.
- - >
- This gives you complete control of how the frame is drawn
- into the canvas context.
- args :
- selector : 'A <canvas> element or query selector for a <canvas> element.'
- onDrawFrame : 'A callback that will be invoked when each frame should be drawn into the canvas. see Animator.onDrawFrame.'
- setDimesions : 'OPTIONAL. If true, the canvas''s width/height will be set to the dimension of the loaded GIF. default: false.'
- */
- Gif.prototype.frames = function(selector, onDrawFrame, setCanvasDimesions) {
- var canvas;
- if (setCanvasDimesions == null) {
- setCanvasDimesions = false;
- }
- canvas = Gif.getCanvasElement(selector);
- return this._animatorPromise.then(function(animator) {
- animator.onDrawFrame = onDrawFrame;
- return animator.animateInCanvas(canvas, setCanvasDimesions);
- });
- };
- /*---
- head : 'gif.get()'
- text :
- - >
- To get even more control, and for your convenience,
- this method returns a promise that will be fulfilled with
- an <b>Animator</b> instance. The animator will be in an unstarted state,
- but can be started with a call to <b>animator.animateInCanvas()</b>
- */
- Gif.prototype.get = function(callback) {
- return this._animatorPromise;
- };
- return Gif;
- })();
- /*
- These methods decode the pixels for each frame (decompressing and de-interlacing)
- into a Uint8ClampedArray, which is suitable for canvas ImageData.
- */
- Decoder = (function() {
- function Decoder() {}
- Decoder.decodeFramesSync = function(reader) {
- var j, ref, results;
- return (function() {
- results = [];
- for (var j = 0, ref = reader.numFrames(); 0 <= ref ? j < ref : j > ref; 0 <= ref ? j++ : j--){ results.push(j); }
- return results;
- }).apply(this).map(function(frameIndex) {
- return Decoder.decodeFrame(reader, frameIndex);
- });
- };
- Decoder.decodeFramesAsync = function(reader) {
- var concurrency, j, ref, results;
- return Promise.map((function() {
- results = [];
- for (var j = 0, ref = reader.numFrames(); 0 <= ref ? j < ref : j > ref; 0 <= ref ? j++ : j--){ results.push(j); }
- return results;
- }).apply(this), (function(i) {
- return Decoder.decodeFrame(reader, i);
- }), concurrency = 1);
- };
- Decoder.decodeFrame = function(reader, frameIndex) {
- var frameInfo;
- frameInfo = reader.frameInfo(frameIndex);
- frameInfo.pixels = new Uint8ClampedArray(reader.width * reader.height * 4);
- reader.decodeAndBlitFrameRGBA(frameIndex, frameInfo.pixels);
- return frameInfo;
- };
- return Decoder;
- })();
- Animator = (function() {
- /*---
- head : 'animator::createBufferCanvas()'
- text :
- - >
- Creates a buffer canvas element since it is much faster
- to call <b>.putImage()</b> than <b>.putImageData()</b>.
- - >
- The omggif library decodes the pixels into the full gif
- dimensions. We only need to store the frame dimensions,
- so we offset the putImageData call.
- args :
- frame : A frame of the GIF (from the omggif library)
- width : width of the GIF (not the frame)
- height : height of the GIF
- return : A <canvas> element containing the frame's image.
- */
- Animator.createBufferCanvas = function(frame, width, height) {
- var bufferCanvas, bufferContext, imageData;
- bufferCanvas = document.createElement('canvas');
- bufferContext = bufferCanvas.getContext('2d');
- bufferCanvas.width = frame.width;
- bufferCanvas.height = frame.height;
- imageData = bufferContext.createImageData(width, height);
- imageData.data.set(frame.pixels);
- bufferContext.putImageData(imageData, -frame.x, -frame.y);
- return bufferCanvas;
- };
- function Animator(_reader, _frames) {
- var ref;
- this._reader = _reader;
- this._frames = _frames;
- this._advanceFrame = bind(this._advanceFrame, this);
- this._nextFrameRender = bind(this._nextFrameRender, this);
- this._nextFrame = bind(this._nextFrame, this);
- ref = this._reader, this.width = ref.width, this.height = ref.height;
- this._loopCount = this._reader.loopCount();
- this._loops = 0;
- this._frameIndex = 0;
- this._running = false;
- }
- /*---
- head : 'animator.start()'
- text :
- - Starts running the GIF animation loop.
- */
- Animator.prototype.start = function() {
- this._lastTime = new Date().valueOf();
- this._delayCompensation = 0;
- this._running = true;
- setTimeout(this._nextFrame, 0);
- return this;
- };
- /*---
- head : 'animator.stop()'
- text :
- - Stops running the GIF animation loop.
- */
- Animator.prototype.stop = function() {
- this._running = false;
- return this;
- };
- /*---
- head : 'animator.reset()'
- text :
- - Resets the animation loop to the first frame.
- - Does not stop the animation from running.
- */
- Animator.prototype.reset = function() {
- this._frameIndex = 0;
- this._loops = 0;
- return this;
- };
- /*---
- head : 'animator.running()'
- return : A boolean indicating whether or not the animation is running.
- */
- Animator.prototype.running = function() {
- return this._running;
- };
- Animator.prototype._nextFrame = function() {
- requestAnimationFrame(this._nextFrameRender);
- };
- Animator.prototype._nextFrameRender = function() {
- var frame, ref;
- if (!this._running) {
- return;
- }
- frame = this._frames[this._frameIndex];
- if ((ref = this.onFrame) != null) {
- ref.apply(this, [frame, this._frameIndex]);
- }
- return this._enqueueNextFrame();
- };
- Animator.prototype._advanceFrame = function() {
- this._frameIndex += 1;
- if (this._frameIndex >= this._frames.length) {
- if (this._loopCount !== 0 && this._loopCount === this._loops) {
- this.stop();
- } else {
- this._frameIndex = 0;
- this._loops += 1;
- }
- }
- };
- Animator.prototype._enqueueNextFrame = function() {
- var actualDelay, delta, frame, frameDelay;
- this._advanceFrame();
- while (this._running) {
- frame = this._frames[this._frameIndex];
- delta = new Date().valueOf() - this._lastTime;
- this._lastTime += delta;
- this._delayCompensation += delta;
- frameDelay = frame.delay * 10;
- actualDelay = frameDelay - this._delayCompensation;
- this._delayCompensation -= frameDelay;
- if (actualDelay < 0) {
- this._advanceFrame();
- continue;
- } else {
- setTimeout(this._nextFrame, actualDelay);
- break;
- }
- }
- };
- /*---
- head : 'animator.animateInCanvas()'
- text :
- - >
- This method prepares the canvas to be drawn into and sets up
- the callbacks for each frame while the animation is running.
- - >
- To change how each frame is drawn into the canvas, override
- <b>animator.onDrawFrame()</b> before calling this method.
- If <b>animator.onDrawFrame()</b> is not set, we simply draw
- the frame directly into the canvas as is.
- - >
- You may also override <b>animator.onFrame()</b> before calling
- this method. onFrame handles the lazy construction of canvas
- buffers for each frame as well as the disposal method for each frame.
- args :
- canvas : A canvas element.
- setDimensions : 'OPTIONAL. If true, the canvas width/height will be set to match the GIF. default: true.'
- */
- Animator.prototype.animateInCanvas = function(canvas, setDimensions) {
- var ctx;
- if (setDimensions == null) {
- setDimensions = true;
- }
- if (setDimensions) {
- canvas.width = this.width;
- canvas.height = this.height;
- }
- ctx = canvas.getContext('2d');
- if (this.onDrawFrame == null) {
- this.onDrawFrame = function(ctx, frame, i) {
- return ctx.drawImage(frame.buffer, frame.x, frame.y);
- };
- }
- if (this.onFrame == null) {
- this.onFrame = (function(_this) {
- return function(frame, i) {
- var ref, saved;
- if (frame.buffer == null) {
- frame.buffer = Animator.createBufferCanvas(frame, _this.width, _this.height);
- }
- if (typeof _this.disposeFrame === "function") {
- _this.disposeFrame();
- }
- switch (frame.disposal) {
- case 2:
- _this.disposeFrame = function() {
- return ctx.clearRect(0, 0, canvas.width, canvas.height);
- };
- break;
- case 3:
- saved = ctx.getImageData(0, 0, canvas.width, canvas.height);
- _this.disposeFrame = function() {
- return ctx.putImageData(saved, 0, 0);
- };
- break;
- default:
- _this.disposeFrame = null;
- }
- return (ref = _this.onDrawFrame) != null ? ref.apply(_this, [ctx, frame, i]) : void 0;
- };
- })(this);
- }
- this.start();
- return this;
- };
- return Animator;
- })();
- gifler.Gif = Gif;
- gifler.Decoder = Decoder;
- gifler.Animator = Animator;
- if (typeof window !== "undefined" && window !== null) {
- window.gifler = gifler;
- }
- if (typeof module !== "undefined" && module !== null) {
- module.exports = gifler;
- }
- },{"bluebird":207,"omggif":214}],210:[function(require,module,exports){
- (function (global){
- /*!
- * VERSION: 1.9.0
- * DATE: 2017-06-19
- * UPDATES AND DOCS AT: http://greensock.com
- *
- * @license Copyright (c) 2008-2017, GreenSock. All rights reserved.
- * This work is subject to the terms at http://greensock.com/standard-license or for
- * Club GreenSock members, the software agreement that was issued with your membership.
- *
- * @author: Jack Doyle, jack@greensock.com
- **/
- var _gsScope = (typeof(module) !== "undefined" && module.exports && typeof(global) !== "undefined") ? global : this || window; //helps ensure compatibility with AMD/RequireJS and CommonJS/Node
- (_gsScope._gsQueue || (_gsScope._gsQueue = [])).push( function() {
- "use strict";
- var _doc = (_gsScope.document || {}).documentElement,
- _window = _gsScope,
- _max = function(element, axis) {
- var dim = (axis === "x") ? "Width" : "Height",
- scroll = "scroll" + dim,
- client = "client" + dim,
- body = document.body;
- return (element === _window || element === _doc || element === body) ? Math.max(_doc[scroll], body[scroll]) - (_window["inner" + dim] || _doc[client] || body[client]) : element[scroll] - element["offset" + dim];
- },
- _unwrapElement = function(value) {
- if (typeof(value) === "string") {
- value = TweenLite.selector(value);
- }
- if (value.length && value !== _window && value[0] && value[0].style && !value.nodeType) {
- value = value[0];
- }
- return (value === _window || (value.nodeType && value.style)) ? value : null;
- },
- _buildGetter = function(e, axis) { //pass in an element and an axis ("x" or "y") and it'll return a getter function for the scroll position of that element (like scrollTop or scrollLeft, although if the element is the window, it'll use the pageXOffset/pageYOffset or the documentElement's scrollTop/scrollLeft or document.body's. Basically this streamlines things and makes a very fast getter across browsers.
- var p = "scroll" + ((axis === "x") ? "Left" : "Top");
- if (e === _window) {
- if (e.pageXOffset != null) {
- p = "page" + axis.toUpperCase() + "Offset";
- } else if (_doc[p] != null) {
- e = _doc;
- } else {
- e = document.body;
- }
- }
- return function() {
- return e[p];
- };
- },
- _getOffset = function(element, container) {
- var rect = _unwrapElement(element).getBoundingClientRect(),
- isRoot = (!container || container === _window || container === document.body),
- cRect = (isRoot ? _doc : container).getBoundingClientRect(),
- offsets = {x: rect.left - cRect.left, y: rect.top - cRect.top};
- if (!isRoot && container) { //only add the current scroll position if it's not the window/body.
- offsets.x += _buildGetter(container, "x")();
- offsets.y += _buildGetter(container, "y")();
- }
- return offsets;
- },
- _parseVal = function(value, target, axis) {
- var type = typeof(value);
- return !isNaN(value) ? parseFloat(value) : (type === "number" || (type === "string" && value.charAt(1) === "=")) ? value : (value === "max") ? _max(target, axis) : Math.min(_max(target, axis), _getOffset(value, target)[axis]);
- },
- ScrollToPlugin = _gsScope._gsDefine.plugin({
- propName: "scrollTo",
- API: 2,
- global: true,
- version:"1.9.0",
- //called when the tween renders for the first time. This is where initial values should be recorded and any setup routines should run.
- init: function(target, value, tween) {
- this._wdw = (target === _window);
- this._target = target;
- this._tween = tween;
- if (typeof(value) !== "object") {
- value = {y:value}; //if we don't receive an object as the parameter, assume the user intends "y".
- if (typeof(value.y) === "string" && value.y !== "max" && value.y.charAt(1) !== "=") {
- value.x = value.y;
- }
- } else if (value.nodeType) {
- value = {y:value, x:value};
- }
- this.vars = value;
- this._autoKill = (value.autoKill !== false);
- this.getX = _buildGetter(target, "x");
- this.getY = _buildGetter(target, "y");
- this.x = this.xPrev = this.getX();
- this.y = this.yPrev = this.getY();
- if (value.x != null) {
- this._addTween(this, "x", this.x, _parseVal(value.x, target, "x") - (value.offsetX || 0), "scrollTo_x", true);
- this._overwriteProps.push("scrollTo_x");
- } else {
- this.skipX = true;
- }
- if (value.y != null) {
- this._addTween(this, "y", this.y, _parseVal(value.y, target, "y") - (value.offsetY || 0), "scrollTo_y", true);
- this._overwriteProps.push("scrollTo_y");
- } else {
- this.skipY = true;
- }
- return true;
- },
- //called each time the values should be updated, and the ratio gets passed as the only parameter (typically it's a value between 0 and 1, but it can exceed those when using an ease like Elastic.easeOut or Back.easeOut, etc.)
- set: function(v) {
- this._super.setRatio.call(this, v);
- var x = (this._wdw || !this.skipX) ? this.getX() : this.xPrev,
- y = (this._wdw || !this.skipY) ? this.getY() : this.yPrev,
- yDif = y - this.yPrev,
- xDif = x - this.xPrev,
- threshold = ScrollToPlugin.autoKillThreshold;
- if (this.x < 0) { //can't scroll to a position less than 0! Might happen if someone uses a Back.easeOut or Elastic.easeOut when scrolling back to the top of the page (for example)
- this.x = 0;
- }
- if (this.y < 0) {
- this.y = 0;
- }
- if (this._autoKill) {
- //note: iOS has a bug that throws off the scroll by several pixels, so we need to check if it's within 7 pixels of the previous one that we set instead of just looking for an exact match.
- if (!this.skipX && (xDif > threshold || xDif < -threshold) && x < _max(this._target, "x")) {
- this.skipX = true; //if the user scrolls separately, we should stop tweening!
- }
- if (!this.skipY && (yDif > threshold || yDif < -threshold) && y < _max(this._target, "y")) {
- this.skipY = true; //if the user scrolls separately, we should stop tweening!
- }
- if (this.skipX && this.skipY) {
- this._tween.kill();
- if (this.vars.onAutoKill) {
- this.vars.onAutoKill.apply(this.vars.onAutoKillScope || this._tween, this.vars.onAutoKillParams || []);
- }
- }
- }
- if (this._wdw) {
- _window.scrollTo((!this.skipX) ? this.x : x, (!this.skipY) ? this.y : y);
- } else {
- if (!this.skipY) {
- this._target.scrollTop = this.y;
- }
- if (!this.skipX) {
- this._target.scrollLeft = this.x;
- }
- }
- this.xPrev = this.x;
- this.yPrev = this.y;
- }
- }),
- p = ScrollToPlugin.prototype;
- ScrollToPlugin.max = _max;
- ScrollToPlugin.getOffset = _getOffset;
- ScrollToPlugin.buildGetter = _buildGetter;
- ScrollToPlugin.autoKillThreshold = 7;
- p._kill = function(lookup) {
- if (lookup.scrollTo_x) {
- this.skipX = true;
- }
- if (lookup.scrollTo_y) {
- this.skipY = true;
- }
- return this._super._kill.call(this, lookup);
- };
- }); if (_gsScope._gsDefine) { _gsScope._gsQueue.pop()(); }
- //export to AMD/RequireJS and CommonJS/Node (precursor to full modular build system coming at a later date)
- (function(name) {
- "use strict";
- var getGlobal = function() {
- return (_gsScope.GreenSockGlobals || _gsScope)[name];
- };
- if (typeof(module) !== "undefined" && module.exports) { //node
- require("gsap/TweenLite");
- module.exports = getGlobal();
- } else if (typeof(define) === "function" && define.amd) { //AMD
- define(["gsap/TweenLite"], getGlobal);
- }
- }("ScrollToPlugin"));
- }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
- },{"gsap/TweenLite":211}],211:[function(require,module,exports){
- (function (global){
- /*!
- * VERSION: 1.20.2
- * DATE: 2017-06-30
- * UPDATES AND DOCS AT: http://greensock.com
- *
- * @license Copyright (c) 2008-2017, GreenSock. All rights reserved.
- * This work is subject to the terms at http://greensock.com/standard-license or for
- * Club GreenSock members, the software agreement that was issued with your membership.
- *
- * @author: Jack Doyle, jack@greensock.com
- */
- (function(window, moduleName) {
- "use strict";
- var _exports = {},
- _doc = window.document,
- _globals = window.GreenSockGlobals = window.GreenSockGlobals || window;
- if (_globals.TweenLite) {
- return; //in case the core set of classes is already loaded, don't instantiate twice.
- }
- var _namespace = function(ns) {
- var a = ns.split("."),
- p = _globals, i;
- for (i = 0; i < a.length; i++) {
- p[a[i]] = p = p[a[i]] || {};
- }
- return p;
- },
- gs = _namespace("com.greensock"),
- _tinyNum = 0.0000000001,
- _slice = function(a) { //don't use Array.prototype.slice.call(target, 0) because that doesn't work in IE8 with a NodeList that's returned by querySelectorAll()
- var b = [],
- l = a.length,
- i;
- for (i = 0; i !== l; b.push(a[i++])) {}
- return b;
- },
- _emptyFunc = function() {},
- _isArray = (function() { //works around issues in iframe environments where the Array global isn't shared, thus if the object originates in a different window/iframe, "(obj instanceof Array)" will evaluate false. We added some speed optimizations to avoid Object.prototype.toString.call() unless it's absolutely necessary because it's VERY slow (like 20x slower)
- var toString = Object.prototype.toString,
- array = toString.call([]);
- return function(obj) {
- return obj != null && (obj instanceof Array || (typeof(obj) === "object" && !!obj.push && toString.call(obj) === array));
- };
- }()),
- a, i, p, _ticker, _tickerActive,
- _defLookup = {},
- /**
- * @constructor
- * Defines a GreenSock class, optionally with an array of dependencies that must be instantiated first and passed into the definition.
- * This allows users to load GreenSock JS files in any order even if they have interdependencies (like CSSPlugin extends TweenPlugin which is
- * inside TweenLite.js, but if CSSPlugin is loaded first, it should wait to run its code until TweenLite.js loads and instantiates TweenPlugin
- * and then pass TweenPlugin to CSSPlugin's definition). This is all done automatically and internally.
- *
- * Every definition will be added to a "com.greensock" global object (typically window, but if a window.GreenSockGlobals object is found,
- * it will go there as of v1.7). For example, TweenLite will be found at window.com.greensock.TweenLite and since it's a global class that should be available anywhere,
- * it is ALSO referenced at window.TweenLite. However some classes aren't considered global, like the base com.greensock.core.Animation class, so
- * those will only be at the package like window.com.greensock.core.Animation. Again, if you define a GreenSockGlobals object on the window, everything
- * gets tucked neatly inside there instead of on the window directly. This allows you to do advanced things like load multiple versions of GreenSock
- * files and put them into distinct objects (imagine a banner ad uses a newer version but the main site uses an older one). In that case, you could
- * sandbox the banner one like:
- *
- * <script>
- * var gs = window.GreenSockGlobals = {}; //the newer version we're about to load could now be referenced in a "gs" object, like gs.TweenLite.to(...). Use whatever alias you want as long as it's unique, "gs" or "banner" or whatever.
- * </script>
- * <script src="js/greensock/v1.7/TweenMax.js"></script>
- * <script>
- * window.GreenSockGlobals = window._gsQueue = window._gsDefine = null; //reset it back to null (along with the special _gsQueue variable) so that the next load of TweenMax affects the window and we can reference things directly like TweenLite.to(...)
- * </script>
- * <script src="js/greensock/v1.6/TweenMax.js"></script>
- * <script>
- * gs.TweenLite.to(...); //would use v1.7
- * TweenLite.to(...); //would use v1.6
- * </script>
- *
- * @param {!string} ns The namespace of the class definition, leaving off "com.greensock." as that's assumed. For example, "TweenLite" or "plugins.CSSPlugin" or "easing.Back".
- * @param {!Array.<string>} dependencies An array of dependencies (described as their namespaces minus "com.greensock." prefix). For example ["TweenLite","plugins.TweenPlugin","core.Animation"]
- * @param {!function():Object} func The function that should be called and passed the resolved dependencies which will return the actual class for this definition.
- * @param {boolean=} global If true, the class will be added to the global scope (typically window unless you define a window.GreenSockGlobals object)
- */
- Definition = function(ns, dependencies, func, global) {
- this.sc = (_defLookup[ns]) ? _defLookup[ns].sc : []; //subclasses
- _defLookup[ns] = this;
- this.gsClass = null;
- this.func = func;
- var _classes = [];
- this.check = function(init) {
- var i = dependencies.length,
- missing = i,
- cur, a, n, cl;
- while (--i > -1) {
- if ((cur = _defLookup[dependencies[i]] || new Definition(dependencies[i], [])).gsClass) {
- _classes[i] = cur.gsClass;
- missing--;
- } else if (init) {
- cur.sc.push(this);
- }
- }
- if (missing === 0 && func) {
- a = ("com.greensock." + ns).split(".");
- n = a.pop();
- cl = _namespace(a.join("."))[n] = this.gsClass = func.apply(func, _classes);
- //exports to multiple environments
- if (global) {
- _globals[n] = _exports[n] = cl; //provides a way to avoid global namespace pollution. By default, the main classes like TweenLite, Power1, Strong, etc. are added to window unless a GreenSockGlobals is defined. So if you want to have things added to a custom object instead, just do something like window.GreenSockGlobals = {} before loading any GreenSock files. You can even set up an alias like window.GreenSockGlobals = windows.gs = {} so that you can access everything like gs.TweenLite. Also remember that ALL classes are added to the window.com.greensock object (in their respective packages, like com.greensock.easing.Power1, com.greensock.TweenLite, etc.)
- if (typeof(module) !== "undefined" && module.exports) { //node
- if (ns === moduleName) {
- module.exports = _exports[moduleName] = cl;
- for (i in _exports) {
- cl[i] = _exports[i];
- }
- } else if (_exports[moduleName]) {
- _exports[moduleName][n] = cl;
- }
- } else if (typeof(define) === "function" && define.amd){ //AMD
- define((window.GreenSockAMDPath ? window.GreenSockAMDPath + "/" : "") + ns.split(".").pop(), [], function() { return cl; });
- }
- }
- for (i = 0; i < this.sc.length; i++) {
- this.sc[i].check();
- }
- }
- };
- this.check(true);
- },
- //used to create Definition instances (which basically registers a class that has dependencies).
- _gsDefine = window._gsDefine = function(ns, dependencies, func, global) {
- return new Definition(ns, dependencies, func, global);
- },
- //a quick way to create a class that doesn't have any dependencies. Returns the class, but first registers it in the GreenSock namespace so that other classes can grab it (other classes might be dependent on the class).
- _class = gs._class = function(ns, func, global) {
- func = func || function() {};
- _gsDefine(ns, [], function(){ return func; }, global);
- return func;
- };
- _gsDefine.globals = _globals;
- /*
- * ----------------------------------------------------------------
- * Ease
- * ----------------------------------------------------------------
- */
- var _baseParams = [0, 0, 1, 1],
- Ease = _class("easing.Ease", function(func, extraParams, type, power) {
- this._func = func;
- this._type = type || 0;
- this._power = power || 0;
- this._params = extraParams ? _baseParams.concat(extraParams) : _baseParams;
- }, true),
- _easeMap = Ease.map = {},
- _easeReg = Ease.register = function(ease, names, types, create) {
- var na = names.split(","),
- i = na.length,
- ta = (types || "easeIn,easeOut,easeInOut").split(","),
- e, name, j, type;
- while (--i > -1) {
- name = na[i];
- e = create ? _class("easing."+name, null, true) : gs.easing[name] || {};
- j = ta.length;
- while (--j > -1) {
- type = ta[j];
- _easeMap[name + "." + type] = _easeMap[type + name] = e[type] = ease.getRatio ? ease : ease[type] || new ease();
- }
- }
- };
- p = Ease.prototype;
- p._calcEnd = false;
- p.getRatio = function(p) {
- if (this._func) {
- this._params[0] = p;
- return this._func.apply(null, this._params);
- }
- var t = this._type,
- pw = this._power,
- r = (t === 1) ? 1 - p : (t === 2) ? p : (p < 0.5) ? p * 2 : (1 - p) * 2;
- if (pw === 1) {
- r *= r;
- } else if (pw === 2) {
- r *= r * r;
- } else if (pw === 3) {
- r *= r * r * r;
- } else if (pw === 4) {
- r *= r * r * r * r;
- }
- return (t === 1) ? 1 - r : (t === 2) ? r : (p < 0.5) ? r / 2 : 1 - (r / 2);
- };
- //create all the standard eases like Linear, Quad, Cubic, Quart, Quint, Strong, Power0, Power1, Power2, Power3, and Power4 (each with easeIn, easeOut, and easeInOut)
- a = ["Linear","Quad","Cubic","Quart","Quint,Strong"];
- i = a.length;
- while (--i > -1) {
- p = a[i]+",Power"+i;
- _easeReg(new Ease(null,null,1,i), p, "easeOut", true);
- _easeReg(new Ease(null,null,2,i), p, "easeIn" + ((i === 0) ? ",easeNone" : ""));
- _easeReg(new Ease(null,null,3,i), p, "easeInOut");
- }
- _easeMap.linear = gs.easing.Linear.easeIn;
- _easeMap.swing = gs.easing.Quad.easeInOut; //for jQuery folks
- /*
- * ----------------------------------------------------------------
- * EventDispatcher
- * ----------------------------------------------------------------
- */
- var EventDispatcher = _class("events.EventDispatcher", function(target) {
- this._listeners = {};
- this._eventTarget = target || this;
- });
- p = EventDispatcher.prototype;
- p.addEventListener = function(type, callback, scope, useParam, priority) {
- priority = priority || 0;
- var list = this._listeners[type],
- index = 0,
- listener, i;
- if (this === _ticker && !_tickerActive) {
- _ticker.wake();
- }
- if (list == null) {
- this._listeners[type] = list = [];
- }
- i = list.length;
- while (--i > -1) {
- listener = list[i];
- if (listener.c === callback && listener.s === scope) {
- list.splice(i, 1);
- } else if (index === 0 && listener.pr < priority) {
- index = i + 1;
- }
- }
- list.splice(index, 0, {c:callback, s:scope, up:useParam, pr:priority});
- };
- p.removeEventListener = function(type, callback) {
- var list = this._listeners[type], i;
- if (list) {
- i = list.length;
- while (--i > -1) {
- if (list[i].c === callback) {
- list.splice(i, 1);
- return;
- }
- }
- }
- };
- p.dispatchEvent = function(type) {
- var list = this._listeners[type],
- i, t, listener;
- if (list) {
- i = list.length;
- if (i > 1) {
- list = list.slice(0); //in case addEventListener() is called from within a listener/callback (otherwise the index could change, resulting in a skip)
- }
- t = this._eventTarget;
- while (--i > -1) {
- listener = list[i];
- if (listener) {
- if (listener.up) {
- listener.c.call(listener.s || t, {type:type, target:t});
- } else {
- listener.c.call(listener.s || t);
- }
- }
- }
- }
- };
- /*
- * ----------------------------------------------------------------
- * Ticker
- * ----------------------------------------------------------------
- */
- var _reqAnimFrame = window.requestAnimationFrame,
- _cancelAnimFrame = window.cancelAnimationFrame,
- _getTime = Date.now || function() {return new Date().getTime();},
- _lastUpdate = _getTime();
- //now try to determine the requestAnimationFrame and cancelAnimationFrame functions and if none are found, we'll use a setTimeout()/clearTimeout() polyfill.
- a = ["ms","moz","webkit","o"];
- i = a.length;
- while (--i > -1 && !_reqAnimFrame) {
- _reqAnimFrame = window[a[i] + "RequestAnimationFrame"];
- _cancelAnimFrame = window[a[i] + "CancelAnimationFrame"] || window[a[i] + "CancelRequestAnimationFrame"];
- }
- _class("Ticker", function(fps, useRAF) {
- var _self = this,
- _startTime = _getTime(),
- _useRAF = (useRAF !== false && _reqAnimFrame) ? "auto" : false,
- _lagThreshold = 500,
- _adjustedLag = 33,
- _tickWord = "tick", //helps reduce gc burden
- _fps, _req, _id, _gap, _nextTime,
- _tick = function(manual) {
- var elapsed = _getTime() - _lastUpdate,
- overlap, dispatch;
- if (elapsed > _lagThreshold) {
- _startTime += elapsed - _adjustedLag;
- }
- _lastUpdate += elapsed;
- _self.time = (_lastUpdate - _startTime) / 1000;
- overlap = _self.time - _nextTime;
- if (!_fps || overlap > 0 || manual === true) {
- _self.frame++;
- _nextTime += overlap + (overlap >= _gap ? 0.004 : _gap - overlap);
- dispatch = true;
- }
- if (manual !== true) { //make sure the request is made before we dispatch the "tick" event so that timing is maintained. Otherwise, if processing the "tick" requires a bunch of time (like 15ms) and we're using a setTimeout() that's based on 16.7ms, it'd technically take 31.7ms between frames otherwise.
- _id = _req(_tick);
- }
- if (dispatch) {
- _self.dispatchEvent(_tickWord);
- }
- };
- EventDispatcher.call(_self);
- _self.time = _self.frame = 0;
- _self.tick = function() {
- _tick(true);
- };
- _self.lagSmoothing = function(threshold, adjustedLag) {
- _lagThreshold = threshold || (1 / _tinyNum); //zero should be interpreted as basically unlimited
- _adjustedLag = Math.min(adjustedLag, _lagThreshold, 0);
- };
- _self.sleep = function() {
- if (_id == null) {
- return;
- }
- if (!_useRAF || !_cancelAnimFrame) {
- clearTimeout(_id);
- } else {
- _cancelAnimFrame(_id);
- }
- _req = _emptyFunc;
- _id = null;
- if (_self === _ticker) {
- _tickerActive = false;
- }
- };
- _self.wake = function(seamless) {
- if (_id !== null) {
- _self.sleep();
- } else if (seamless) {
- _startTime += -_lastUpdate + (_lastUpdate = _getTime());
- } else if (_self.frame > 10) { //don't trigger lagSmoothing if we're just waking up, and make sure that at least 10 frames have elapsed because of the iOS bug that we work around below with the 1.5-second setTimout().
- _lastUpdate = _getTime() - _lagThreshold + 5;
- }
- _req = (_fps === 0) ? _emptyFunc : (!_useRAF || !_reqAnimFrame) ? function(f) { return setTimeout(f, ((_nextTime - _self.time) * 1000 + 1) | 0); } : _reqAnimFrame;
- if (_self === _ticker) {
- _tickerActive = true;
- }
- _tick(2);
- };
- _self.fps = function(value) {
- if (!arguments.length) {
- return _fps;
- }
- _fps = value;
- _gap = 1 / (_fps || 60);
- _nextTime = this.time + _gap;
- _self.wake();
- };
- _self.useRAF = function(value) {
- if (!arguments.length) {
- return _useRAF;
- }
- _self.sleep();
- _useRAF = value;
- _self.fps(_fps);
- };
- _self.fps(fps);
- //a bug in iOS 6 Safari occasionally prevents the requestAnimationFrame from working initially, so we use a 1.5-second timeout that automatically falls back to setTimeout() if it senses this condition.
- setTimeout(function() {
- if (_useRAF === "auto" && _self.frame < 5 && _doc.visibilityState !== "hidden") {
- _self.useRAF(false);
- }
- }, 1500);
- });
- p = gs.Ticker.prototype = new gs.events.EventDispatcher();
- p.constructor = gs.Ticker;
- /*
- * ----------------------------------------------------------------
- * Animation
- * ----------------------------------------------------------------
- */
- var Animation = _class("core.Animation", function(duration, vars) {
- this.vars = vars = vars || {};
- this._duration = this._totalDuration = duration || 0;
- this._delay = Number(vars.delay) || 0;
- this._timeScale = 1;
- this._active = (vars.immediateRender === true);
- this.data = vars.data;
- this._reversed = (vars.reversed === true);
- if (!_rootTimeline) {
- return;
- }
- if (!_tickerActive) { //some browsers (like iOS 6 Safari) shut down JavaScript execution when the tab is disabled and they [occasionally] neglect to start up requestAnimationFrame again when returning - this code ensures that the engine starts up again properly.
- _ticker.wake();
- }
- var tl = this.vars.useFrames ? _rootFramesTimeline : _rootTimeline;
- tl.add(this, tl._time);
- if (this.vars.paused) {
- this.paused(true);
- }
- });
- _ticker = Animation.ticker = new gs.Ticker();
- p = Animation.prototype;
- p._dirty = p._gc = p._initted = p._paused = false;
- p._totalTime = p._time = 0;
- p._rawPrevTime = -1;
- p._next = p._last = p._onUpdate = p._timeline = p.timeline = null;
- p._paused = false;
- //some browsers (like iOS) occasionally drop the requestAnimationFrame event when the user switches to a different tab and then comes back again, so we use a 2-second setTimeout() to sense if/when that condition occurs and then wake() the ticker.
- var _checkTimeout = function() {
- if (_tickerActive && _getTime() - _lastUpdate > 2000 && _doc.visibilityState !== "hidden") {
- _ticker.wake();
- }
- var t = setTimeout(_checkTimeout, 2000);
- if (t.unref) {
- // allows a node process to exit even if the timeout’s callback hasn't been invoked. Without it, the node process could hang as this function is called every two seconds.
- t.unref();
- }
- };
- _checkTimeout();
- p.play = function(from, suppressEvents) {
- if (from != null) {
- this.seek(from, suppressEvents);
- }
- return this.reversed(false).paused(false);
- };
- p.pause = function(atTime, suppressEvents) {
- if (atTime != null) {
- this.seek(atTime, suppressEvents);
- }
- return this.paused(true);
- };
- p.resume = function(from, suppressEvents) {
- if (from != null) {
- this.seek(from, suppressEvents);
- }
- return this.paused(false);
- };
- p.seek = function(time, suppressEvents) {
- return this.totalTime(Number(time), suppressEvents !== false);
- };
- p.restart = function(includeDelay, suppressEvents) {
- return this.reversed(false).paused(false).totalTime(includeDelay ? -this._delay : 0, (suppressEvents !== false), true);
- };
- p.reverse = function(from, suppressEvents) {
- if (from != null) {
- this.seek((from || this.totalDuration()), suppressEvents);
- }
- return this.reversed(true).paused(false);
- };
- p.render = function(time, suppressEvents, force) {
- //stub - we override this method in subclasses.
- };
- p.invalidate = function() {
- this._time = this._totalTime = 0;
- this._initted = this._gc = false;
- this._rawPrevTime = -1;
- if (this._gc || !this.timeline) {
- this._enabled(true);
- }
- return this;
- };
- p.isActive = function() {
- var tl = this._timeline, //the 2 root timelines won't have a _timeline; they're always active.
- startTime = this._startTime,
- rawTime;
- return (!tl || (!this._gc && !this._paused && tl.isActive() && (rawTime = tl.rawTime(true)) >= startTime && rawTime < startTime + this.totalDuration() / this._timeScale - 0.0000001));
- };
- p._enabled = function (enabled, ignoreTimeline) {
- if (!_tickerActive) {
- _ticker.wake();
- }
- this._gc = !enabled;
- this._active = this.isActive();
- if (ignoreTimeline !== true) {
- if (enabled && !this.timeline) {
- this._timeline.add(this, this._startTime - this._delay);
- } else if (!enabled && this.timeline) {
- this._timeline._remove(this, true);
- }
- }
- return false;
- };
- p._kill = function(vars, target) {
- return this._enabled(false, false);
- };
- p.kill = function(vars, target) {
- this._kill(vars, target);
- return this;
- };
- p._uncache = function(includeSelf) {
- var tween = includeSelf ? this : this.timeline;
- while (tween) {
- tween._dirty = true;
- tween = tween.timeline;
- }
- return this;
- };
- p._swapSelfInParams = function(params) {
- var i = params.length,
- copy = params.concat();
- while (--i > -1) {
- if (params[i] === "{self}") {
- copy[i] = this;
- }
- }
- return copy;
- };
- p._callback = function(type) {
- var v = this.vars,
- callback = v[type],
- params = v[type + "Params"],
- scope = v[type + "Scope"] || v.callbackScope || this,
- l = params ? params.length : 0;
- switch (l) { //speed optimization; call() is faster than apply() so use it when there are only a few parameters (which is by far most common). Previously we simply did var v = this.vars; v[type].apply(v[type + "Scope"] || v.callbackScope || this, v[type + "Params"] || _blankArray);
- case 0: callback.call(scope); break;
- case 1: callback.call(scope, params[0]); break;
- case 2: callback.call(scope, params[0], params[1]); break;
- default: callback.apply(scope, params);
- }
- };
- //----Animation getters/setters --------------------------------------------------------
- p.eventCallback = function(type, callback, params, scope) {
- if ((type || "").substr(0,2) === "on") {
- var v = this.vars;
- if (arguments.length === 1) {
- return v[type];
- }
- if (callback == null) {
- delete v[type];
- } else {
- v[type] = callback;
- v[type + "Params"] = (_isArray(params) && params.join("").indexOf("{self}") !== -1) ? this._swapSelfInParams(params) : params;
- v[type + "Scope"] = scope;
- }
- if (type === "onUpdate") {
- this._onUpdate = callback;
- }
- }
- return this;
- };
- p.delay = function(value) {
- if (!arguments.length) {
- return this._delay;
- }
- if (this._timeline.smoothChildTiming) {
- this.startTime( this._startTime + value - this._delay );
- }
- this._delay = value;
- return this;
- };
- p.duration = function(value) {
- if (!arguments.length) {
- this._dirty = false;
- return this._duration;
- }
- this._duration = this._totalDuration = value;
- this._uncache(true); //true in case it's a TweenMax or TimelineMax that has a repeat - we'll need to refresh the totalDuration.
- if (this._timeline.smoothChildTiming) if (this._time > 0) if (this._time < this._duration) if (value !== 0) {
- this.totalTime(this._totalTime * (value / this._duration), true);
- }
- return this;
- };
- p.totalDuration = function(value) {
- this._dirty = false;
- return (!arguments.length) ? this._totalDuration : this.duration(value);
- };
- p.time = function(value, suppressEvents) {
- if (!arguments.length) {
- return this._time;
- }
- if (this._dirty) {
- this.totalDuration();
- }
- return this.totalTime((value > this._duration) ? this._duration : value, suppressEvents);
- };
- p.totalTime = function(time, suppressEvents, uncapped) {
- if (!_tickerActive) {
- _ticker.wake();
- }
- if (!arguments.length) {
- return this._totalTime;
- }
- if (this._timeline) {
- if (time < 0 && !uncapped) {
- time += this.totalDuration();
- }
- if (this._timeline.smoothChildTiming) {
- if (this._dirty) {
- this.totalDuration();
- }
- var totalDuration = this._totalDuration,
- tl = this._timeline;
- if (time > totalDuration && !uncapped) {
- time = totalDuration;
- }
- this._startTime = (this._paused ? this._pauseTime : tl._time) - ((!this._reversed ? time : totalDuration - time) / this._timeScale);
- if (!tl._dirty) { //for performance improvement. If the parent's cache is already dirty, it already took care of marking the ancestors as dirty too, so skip the function call here.
- this._uncache(false);
- }
- //in case any of the ancestor timelines had completed but should now be enabled, we should reset their totalTime() which will also ensure that they're lined up properly and enabled. Skip for animations that are on the root (wasteful). Example: a TimelineLite.exportRoot() is performed when there's a paused tween on the root, the export will not complete until that tween is unpaused, but imagine a child gets restarted later, after all [unpaused] tweens have completed. The startTime of that child would get pushed out, but one of the ancestors may have completed.
- if (tl._timeline) {
- while (tl._timeline) {
- if (tl._timeline._time !== (tl._startTime + tl._totalTime) / tl._timeScale) {
- tl.totalTime(tl._totalTime, true);
- }
- tl = tl._timeline;
- }
- }
- }
- if (this._gc) {
- this._enabled(true, false);
- }
- if (this._totalTime !== time || this._duration === 0) {
- if (_lazyTweens.length) {
- _lazyRender();
- }
- this.render(time, suppressEvents, false);
- if (_lazyTweens.length) { //in case rendering caused any tweens to lazy-init, we should render them because typically when someone calls seek() or time() or progress(), they expect an immediate render.
- _lazyRender();
- }
- }
- }
- return this;
- };
- p.progress = p.totalProgress = function(value, suppressEvents) {
- var duration = this.duration();
- return (!arguments.length) ? (duration ? this._time / duration : this.ratio) : this.totalTime(duration * value, suppressEvents);
- };
- p.startTime = function(value) {
- if (!arguments.length) {
- return this._startTime;
- }
- if (value !== this._startTime) {
- this._startTime = value;
- if (this.timeline) if (this.timeline._sortChildren) {
- this.timeline.add(this, value - this._delay); //ensures that any necessary re-sequencing of Animations in the timeline occurs to make sure the rendering order is correct.
- }
- }
- return this;
- };
- p.endTime = function(includeRepeats) {
- return this._startTime + ((includeRepeats != false) ? this.totalDuration() : this.duration()) / this._timeScale;
- };
- p.timeScale = function(value) {
- if (!arguments.length) {
- return this._timeScale;
- }
- value = value || _tinyNum; //can't allow zero because it'll throw the math off
- if (this._timeline && this._timeline.smoothChildTiming) {
- var pauseTime = this._pauseTime,
- t = (pauseTime || pauseTime === 0) ? pauseTime : this._timeline.totalTime();
- this._startTime = t - ((t - this._startTime) * this._timeScale / value);
- }
- this._timeScale = value;
- return this._uncache(false);
- };
- p.reversed = function(value) {
- if (!arguments.length) {
- return this._reversed;
- }
- if (value != this._reversed) {
- this._reversed = value;
- this.totalTime(((this._timeline && !this._timeline.smoothChildTiming) ? this.totalDuration() - this._totalTime : this._totalTime), true);
- }
- return this;
- };
- p.paused = function(value) {
- if (!arguments.length) {
- return this._paused;
- }
- var tl = this._timeline,
- raw, elapsed;
- if (value != this._paused) if (tl) {
- if (!_tickerActive && !value) {
- _ticker.wake();
- }
- raw = tl.rawTime();
- elapsed = raw - this._pauseTime;
- if (!value && tl.smoothChildTiming) {
- this._startTime += elapsed;
- this._uncache(false);
- }
- this._pauseTime = value ? raw : null;
- this._paused = value;
- this._active = this.isActive();
- if (!value && elapsed !== 0 && this._initted && this.duration()) {
- raw = tl.smoothChildTiming ? this._totalTime : (raw - this._startTime) / this._timeScale;
- this.render(raw, (raw === this._totalTime), true); //in case the target's properties changed via some other tween or manual update by the user, we should force a render.
- }
- }
- if (this._gc && !value) {
- this._enabled(true, false);
- }
- return this;
- };
- /*
- * ----------------------------------------------------------------
- * SimpleTimeline
- * ----------------------------------------------------------------
- */
- var SimpleTimeline = _class("core.SimpleTimeline", function(vars) {
- Animation.call(this, 0, vars);
- this.autoRemoveChildren = this.smoothChildTiming = true;
- });
- p = SimpleTimeline.prototype = new Animation();
- p.constructor = SimpleTimeline;
- p.kill()._gc = false;
- p._first = p._last = p._recent = null;
- p._sortChildren = false;
- p.add = p.insert = function(child, position, align, stagger) {
- var prevTween, st;
- child._startTime = Number(position || 0) + child._delay;
- if (child._paused) if (this !== child._timeline) { //we only adjust the _pauseTime if it wasn't in this timeline already. Remember, sometimes a tween will be inserted again into the same timeline when its startTime is changed so that the tweens in the TimelineLite/Max are re-ordered properly in the linked list (so everything renders in the proper order).
- child._pauseTime = child._startTime + ((this.rawTime() - child._startTime) / child._timeScale);
- }
- if (child.timeline) {
- child.timeline._remove(child, true); //removes from existing timeline so that it can be properly added to this one.
- }
- child.timeline = child._timeline = this;
- if (child._gc) {
- child._enabled(true, true);
- }
- prevTween = this._last;
- if (this._sortChildren) {
- st = child._startTime;
- while (prevTween && prevTween._startTime > st) {
- prevTween = prevTween._prev;
- }
- }
- if (prevTween) {
- child._next = prevTween._next;
- prevTween._next = child;
- } else {
- child._next = this._first;
- this._first = child;
- }
- if (child._next) {
- child._next._prev = child;
- } else {
- this._last = child;
- }
- child._prev = prevTween;
- this._recent = child;
- if (this._timeline) {
- this._uncache(true);
- }
- return this;
- };
- p._remove = function(tween, skipDisable) {
- if (tween.timeline === this) {
- if (!skipDisable) {
- tween._enabled(false, true);
- }
- if (tween._prev) {
- tween._prev._next = tween._next;
- } else if (this._first === tween) {
- this._first = tween._next;
- }
- if (tween._next) {
- tween._next._prev = tween._prev;
- } else if (this._last === tween) {
- this._last = tween._prev;
- }
- tween._next = tween._prev = tween.timeline = null;
- if (tween === this._recent) {
- this._recent = this._last;
- }
- if (this._timeline) {
- this._uncache(true);
- }
- }
- return this;
- };
- p.render = function(time, suppressEvents, force) {
- var tween = this._first,
- next;
- this._totalTime = this._time = this._rawPrevTime = time;
- while (tween) {
- next = tween._next; //record it here because the value could change after rendering...
- if (tween._active || (time >= tween._startTime && !tween._paused && !tween._gc)) {
- if (!tween._reversed) {
- tween.render((time - tween._startTime) * tween._timeScale, suppressEvents, force);
- } else {
- tween.render(((!tween._dirty) ? tween._totalDuration : tween.totalDuration()) - ((time - tween._startTime) * tween._timeScale), suppressEvents, force);
- }
- }
- tween = next;
- }
- };
- p.rawTime = function() {
- if (!_tickerActive) {
- _ticker.wake();
- }
- return this._totalTime;
- };
- /*
- * ----------------------------------------------------------------
- * TweenLite
- * ----------------------------------------------------------------
- */
- var TweenLite = _class("TweenLite", function(target, duration, vars) {
- Animation.call(this, duration, vars);
- this.render = TweenLite.prototype.render; //speed optimization (avoid prototype lookup on this "hot" method)
- if (target == null) {
- throw "Cannot tween a null target.";
- }
- this.target = target = (typeof(target) !== "string") ? target : TweenLite.selector(target) || target;
- var isSelector = (target.jquery || (target.length && target !== window && target[0] && (target[0] === window || (target[0].nodeType && target[0].style && !target.nodeType)))),
- overwrite = this.vars.overwrite,
- i, targ, targets;
- this._overwrite = overwrite = (overwrite == null) ? _overwriteLookup[TweenLite.defaultOverwrite] : (typeof(overwrite) === "number") ? overwrite >> 0 : _overwriteLookup[overwrite];
- if ((isSelector || target instanceof Array || (target.push && _isArray(target))) && typeof(target[0]) !== "number") {
- this._targets = targets = _slice(target); //don't use Array.prototype.slice.call(target, 0) because that doesn't work in IE8 with a NodeList that's returned by querySelectorAll()
- this._propLookup = [];
- this._siblings = [];
- for (i = 0; i < targets.length; i++) {
- targ = targets[i];
- if (!targ) {
- targets.splice(i--, 1);
- continue;
- } else if (typeof(targ) === "string") {
- targ = targets[i--] = TweenLite.selector(targ); //in case it's an array of strings
- if (typeof(targ) === "string") {
- targets.splice(i+1, 1); //to avoid an endless loop (can't imagine why the selector would return a string, but just in case)
- }
- continue;
- } else if (targ.length && targ !== window && targ[0] && (targ[0] === window || (targ[0].nodeType && targ[0].style && !targ.nodeType))) { //in case the user is passing in an array of selector objects (like jQuery objects), we need to check one more level and pull things out if necessary. Also note that <select> elements pass all the criteria regarding length and the first child having style, so we must also check to ensure the target isn't an HTML node itself.
- targets.splice(i--, 1);
- this._targets = targets = targets.concat(_slice(targ));
- continue;
- }
- this._siblings[i] = _register(targ, this, false);
- if (overwrite === 1) if (this._siblings[i].length > 1) {
- _applyOverwrite(targ, this, null, 1, this._siblings[i]);
- }
- }
- } else {
- this._propLookup = {};
- this._siblings = _register(target, this, false);
- if (overwrite === 1) if (this._siblings.length > 1) {
- _applyOverwrite(target, this, null, 1, this._siblings);
- }
- }
- if (this.vars.immediateRender || (duration === 0 && this._delay === 0 && this.vars.immediateRender !== false)) {
- this._time = -_tinyNum; //forces a render without having to set the render() "force" parameter to true because we want to allow lazying by default (using the "force" parameter always forces an immediate full render)
- this.render(Math.min(0, -this._delay)); //in case delay is negative
- }
- }, true),
- _isSelector = function(v) {
- return (v && v.length && v !== window && v[0] && (v[0] === window || (v[0].nodeType && v[0].style && !v.nodeType))); //we cannot check "nodeType" if the target is window from within an iframe, otherwise it will trigger a security error in some browsers like Firefox.
- },
- _autoCSS = function(vars, target) {
- var css = {},
- p;
- for (p in vars) {
- if (!_reservedProps[p] && (!(p in target) || p === "transform" || p === "x" || p === "y" || p === "width" || p === "height" || p === "className" || p === "border") && (!_plugins[p] || (_plugins[p] && _plugins[p]._autoCSS))) { //note: <img> elements contain read-only "x" and "y" properties. We should also prioritize editing css width/height rather than the element's properties.
- css[p] = vars[p];
- delete vars[p];
- }
- }
- vars.css = css;
- };
- p = TweenLite.prototype = new Animation();
- p.constructor = TweenLite;
- p.kill()._gc = false;
- //----TweenLite defaults, overwrite management, and root updates ----------------------------------------------------
- p.ratio = 0;
- p._firstPT = p._targets = p._overwrittenProps = p._startAt = null;
- p._notifyPluginsOfEnabled = p._lazy = false;
- TweenLite.version = "1.20.2";
- TweenLite.defaultEase = p._ease = new Ease(null, null, 1, 1);
- TweenLite.defaultOverwrite = "auto";
- TweenLite.ticker = _ticker;
- TweenLite.autoSleep = 120;
- TweenLite.lagSmoothing = function(threshold, adjustedLag) {
- _ticker.lagSmoothing(threshold, adjustedLag);
- };
- TweenLite.selector = window.$ || window.jQuery || function(e) {
- var selector = window.$ || window.jQuery;
- if (selector) {
- TweenLite.selector = selector;
- return selector(e);
- }
- return (typeof(_doc) === "undefined") ? e : (_doc.querySelectorAll ? _doc.querySelectorAll(e) : _doc.getElementById((e.charAt(0) === "#") ? e.substr(1) : e));
- };
- var _lazyTweens = [],
- _lazyLookup = {},
- _numbersExp = /(?:(-|-=|\+=)?\d*\.?\d*(?:e[\-+]?\d+)?)[0-9]/ig,
- _relExp = /[\+-]=-?[\.\d]/,
- //_nonNumbersExp = /(?:([\-+](?!(\d|=)))|[^\d\-+=e]|(e(?![\-+][\d])))+/ig,
- _setRatio = function(v) {
- var pt = this._firstPT,
- min = 0.000001,
- val;
- while (pt) {
- val = !pt.blob ? pt.c * v + pt.s : (v === 1 && this.end) ? this.end : v ? this.join("") : this.start;
- if (pt.m) {
- val = pt.m(val, this._target || pt.t);
- } else if (val < min) if (val > -min && !pt.blob) { //prevents issues with converting very small numbers to strings in the browser
- val = 0;
- }
- if (!pt.f) {
- pt.t[pt.p] = val;
- } else if (pt.fp) {
- pt.t[pt.p](pt.fp, val);
- } else {
- pt.t[pt.p](val);
- }
- pt = pt._next;
- }
- },
- //compares two strings (start/end), finds the numbers that are different and spits back an array representing the whole value but with the changing values isolated as elements. For example, "rgb(0,0,0)" and "rgb(100,50,0)" would become ["rgb(", 0, ",", 50, ",0)"]. Notice it merges the parts that are identical (performance optimization). The array also has a linked list of PropTweens attached starting with _firstPT that contain the tweening data (t, p, s, c, f, etc.). It also stores the starting value as a "start" property so that we can revert to it if/when necessary, like when a tween rewinds fully. If the quantity of numbers differs between the start and end, it will always prioritize the end value(s). The pt parameter is optional - it's for a PropTween that will be appended to the end of the linked list and is typically for actually setting the value after all of the elements have been updated (with array.join("")).
- _blobDif = function(start, end, filter, pt) {
- var a = [],
- charIndex = 0,
- s = "",
- color = 0,
- startNums, endNums, num, i, l, nonNumbers, currentNum;
- a.start = start;
- a.end = end;
- start = a[0] = start + ""; //ensure values are strings
- end = a[1] = end + "";
- if (filter) {
- filter(a); //pass an array with the starting and ending values and let the filter do whatever it needs to the values.
- start = a[0];
- end = a[1];
- }
- a.length = 0;
- startNums = start.match(_numbersExp) || [];
- endNums = end.match(_numbersExp) || [];
- if (pt) {
- pt._next = null;
- pt.blob = 1;
- a._firstPT = a._applyPT = pt; //apply last in the linked list (which means inserting it first)
- }
- l = endNums.length;
- for (i = 0; i < l; i++) {
- currentNum = endNums[i];
- nonNumbers = end.substr(charIndex, end.indexOf(currentNum, charIndex)-charIndex);
- s += (nonNumbers || !i) ? nonNumbers : ","; //note: SVG spec allows omission of comma/space when a negative sign is wedged between two numbers, like 2.5-5.3 instead of 2.5,-5.3 but when tweening, the negative value may switch to positive, so we insert the comma just in case.
- charIndex += nonNumbers.length;
- if (color) { //sense rgba() values and round them.
- color = (color + 1) % 5;
- } else if (nonNumbers.substr(-5) === "rgba(") {
- color = 1;
- }
- if (currentNum === startNums[i] || startNums.length <= i) {
- s += currentNum;
- } else {
- if (s) {
- a.push(s);
- s = "";
- }
- num = parseFloat(startNums[i]);
- a.push(num);
- a._firstPT = {_next: a._firstPT, t:a, p: a.length-1, s:num, c:((currentNum.charAt(1) === "=") ? parseInt(currentNum.charAt(0) + "1", 10) * parseFloat(currentNum.substr(2)) : (parseFloat(currentNum) - num)) || 0, f:0, m:(color && color < 4) ? Math.round : 0};
- //note: we don't set _prev because we'll never need to remove individual PropTweens from this list.
- }
- charIndex += currentNum.length;
- }
- s += end.substr(charIndex);
- if (s) {
- a.push(s);
- }
- a.setRatio = _setRatio;
- if (_relExp.test(end)) { //if the end string contains relative values, delete it so that on the final render (in _setRatio()), we don't actually set it to the string with += or -= characters (forces it to use the calculated value).
- a.end = 0;
- }
- return a;
- },
- //note: "funcParam" is only necessary for function-based getters/setters that require an extra parameter like getAttribute("width") and setAttribute("width", value). In this example, funcParam would be "width". Used by AttrPlugin for example.
- _addPropTween = function(target, prop, start, end, overwriteProp, mod, funcParam, stringFilter, index) {
- if (typeof(end) === "function") {
- end = end(index || 0, target);
- }
- var type = typeof(target[prop]),
- getterName = (type !== "function") ? "" : ((prop.indexOf("set") || typeof(target["get" + prop.substr(3)]) !== "function") ? prop : "get" + prop.substr(3)),
- s = (start !== "get") ? start : !getterName ? target[prop] : funcParam ? target[getterName](funcParam) : target[getterName](),
- isRelative = (typeof(end) === "string" && end.charAt(1) === "="),
- pt = {t:target, p:prop, s:s, f:(type === "function"), pg:0, n:overwriteProp || prop, m:(!mod ? 0 : (typeof(mod) === "function") ? mod : Math.round), pr:0, c:isRelative ? parseInt(end.charAt(0) + "1", 10) * parseFloat(end.substr(2)) : (parseFloat(end) - s) || 0},
- blob;
- if (typeof(s) !== "number" || (typeof(end) !== "number" && !isRelative)) {
- if (funcParam || isNaN(s) || (!isRelative && isNaN(end)) || typeof(s) === "boolean" || typeof(end) === "boolean") {
- //a blob (string that has multiple numbers in it)
- pt.fp = funcParam;
- blob = _blobDif(s, (isRelative ? parseFloat(pt.s) + pt.c : end), stringFilter || TweenLite.defaultStringFilter, pt);
- pt = {t: blob, p: "setRatio", s: 0, c: 1, f: 2, pg: 0, n: overwriteProp || prop, pr: 0, m: 0}; //"2" indicates it's a Blob property tween. Needed for RoundPropsPlugin for example.
- } else {
- pt.s = parseFloat(s);
- if (!isRelative) {
- pt.c = (parseFloat(end) - pt.s) || 0;
- }
- }
- }
- if (pt.c) { //only add it to the linked list if there's a change.
- if ((pt._next = this._firstPT)) {
- pt._next._prev = pt;
- }
- this._firstPT = pt;
- return pt;
- }
- },
- _internals = TweenLite._internals = {isArray:_isArray, isSelector:_isSelector, lazyTweens:_lazyTweens, blobDif:_blobDif}, //gives us a way to expose certain private values to other GreenSock classes without contaminating tha main TweenLite object.
- _plugins = TweenLite._plugins = {},
- _tweenLookup = _internals.tweenLookup = {},
- _tweenLookupNum = 0,
- _reservedProps = _internals.reservedProps = {ease:1, delay:1, overwrite:1, onComplete:1, onCompleteParams:1, onCompleteScope:1, useFrames:1, runBackwards:1, startAt:1, onUpdate:1, onUpdateParams:1, onUpdateScope:1, onStart:1, onStartParams:1, onStartScope:1, onReverseComplete:1, onReverseCompleteParams:1, onReverseCompleteScope:1, onRepeat:1, onRepeatParams:1, onRepeatScope:1, easeParams:1, yoyo:1, immediateRender:1, repeat:1, repeatDelay:1, data:1, paused:1, reversed:1, autoCSS:1, lazy:1, onOverwrite:1, callbackScope:1, stringFilter:1, id:1, yoyoEase:1},
- _overwriteLookup = {none:0, all:1, auto:2, concurrent:3, allOnStart:4, preexisting:5, "true":1, "false":0},
- _rootFramesTimeline = Animation._rootFramesTimeline = new SimpleTimeline(),
- _rootTimeline = Animation._rootTimeline = new SimpleTimeline(),
- _nextGCFrame = 30,
- _lazyRender = _internals.lazyRender = function() {
- var i = _lazyTweens.length,
- tween;
- _lazyLookup = {};
- while (--i > -1) {
- tween = _lazyTweens[i];
- if (tween && tween._lazy !== false) {
- tween.render(tween._lazy[0], tween._lazy[1], true);
- tween._lazy = false;
- }
- }
- _lazyTweens.length = 0;
- };
- _rootTimeline._startTime = _ticker.time;
- _rootFramesTimeline._startTime = _ticker.frame;
- _rootTimeline._active = _rootFramesTimeline._active = true;
- setTimeout(_lazyRender, 1); //on some mobile devices, there isn't a "tick" before code runs which means any lazy renders wouldn't run before the next official "tick".
- Animation._updateRoot = TweenLite.render = function() {
- var i, a, p;
- if (_lazyTweens.length) { //if code is run outside of the requestAnimationFrame loop, there may be tweens queued AFTER the engine refreshed, so we need to ensure any pending renders occur before we refresh again.
- _lazyRender();
- }
- _rootTimeline.render((_ticker.time - _rootTimeline._startTime) * _rootTimeline._timeScale, false, false);
- _rootFramesTimeline.render((_ticker.frame - _rootFramesTimeline._startTime) * _rootFramesTimeline._timeScale, false, false);
- if (_lazyTweens.length) {
- _lazyRender();
- }
- if (_ticker.frame >= _nextGCFrame) { //dump garbage every 120 frames or whatever the user sets TweenLite.autoSleep to
- _nextGCFrame = _ticker.frame + (parseInt(TweenLite.autoSleep, 10) || 120);
- for (p in _tweenLookup) {
- a = _tweenLookup[p].tweens;
- i = a.length;
- while (--i > -1) {
- if (a[i]._gc) {
- a.splice(i, 1);
- }
- }
- if (a.length === 0) {
- delete _tweenLookup[p];
- }
- }
- //if there are no more tweens in the root timelines, or if they're all paused, make the _timer sleep to reduce load on the CPU slightly
- p = _rootTimeline._first;
- if (!p || p._paused) if (TweenLite.autoSleep && !_rootFramesTimeline._first && _ticker._listeners.tick.length === 1) {
- while (p && p._paused) {
- p = p._next;
- }
- if (!p) {
- _ticker.sleep();
- }
- }
- }
- };
- _ticker.addEventListener("tick", Animation._updateRoot);
- var _register = function(target, tween, scrub) {
- var id = target._gsTweenID, a, i;
- if (!_tweenLookup[id || (target._gsTweenID = id = "t" + (_tweenLookupNum++))]) {
- _tweenLookup[id] = {target:target, tweens:[]};
- }
- if (tween) {
- a = _tweenLookup[id].tweens;
- a[(i = a.length)] = tween;
- if (scrub) {
- while (--i > -1) {
- if (a[i] === tween) {
- a.splice(i, 1);
- }
- }
- }
- }
- return _tweenLookup[id].tweens;
- },
- _onOverwrite = function(overwrittenTween, overwritingTween, target, killedProps) {
- var func = overwrittenTween.vars.onOverwrite, r1, r2;
- if (func) {
- r1 = func(overwrittenTween, overwritingTween, target, killedProps);
- }
- func = TweenLite.onOverwrite;
- if (func) {
- r2 = func(overwrittenTween, overwritingTween, target, killedProps);
- }
- return (r1 !== false && r2 !== false);
- },
- _applyOverwrite = function(target, tween, props, mode, siblings) {
- var i, changed, curTween, l;
- if (mode === 1 || mode >= 4) {
- l = siblings.length;
- for (i = 0; i < l; i++) {
- if ((curTween = siblings[i]) !== tween) {
- if (!curTween._gc) {
- if (curTween._kill(null, target, tween)) {
- changed = true;
- }
- }
- } else if (mode === 5) {
- break;
- }
- }
- return changed;
- }
- //NOTE: Add 0.0000000001 to overcome floating point errors that can cause the startTime to be VERY slightly off (when a tween's time() is set for example)
- var startTime = tween._startTime + _tinyNum,
- overlaps = [],
- oCount = 0,
- zeroDur = (tween._duration === 0),
- globalStart;
- i = siblings.length;
- while (--i > -1) {
- if ((curTween = siblings[i]) === tween || curTween._gc || curTween._paused) {
- //ignore
- } else if (curTween._timeline !== tween._timeline) {
- globalStart = globalStart || _checkOverlap(tween, 0, zeroDur);
- if (_checkOverlap(curTween, globalStart, zeroDur) === 0) {
- overlaps[oCount++] = curTween;
- }
- } else if (curTween._startTime <= startTime) if (curTween._startTime + curTween.totalDuration() / curTween._timeScale > startTime) if (!((zeroDur || !curTween._initted) && startTime - curTween._startTime <= 0.0000000002)) {
- overlaps[oCount++] = curTween;
- }
- }
- i = oCount;
- while (--i > -1) {
- curTween = overlaps[i];
- if (mode === 2) if (curTween._kill(props, target, tween)) {
- changed = true;
- }
- if (mode !== 2 || (!curTween._firstPT && curTween._initted)) {
- if (mode !== 2 && !_onOverwrite(curTween, tween)) {
- continue;
- }
- if (curTween._enabled(false, false)) { //if all property tweens have been overwritten, kill the tween.
- changed = true;
- }
- }
- }
- return changed;
- },
- _checkOverlap = function(tween, reference, zeroDur) {
- var tl = tween._timeline,
- ts = tl._timeScale,
- t = tween._startTime;
- while (tl._timeline) {
- t += tl._startTime;
- ts *= tl._timeScale;
- if (tl._paused) {
- return -100;
- }
- tl = tl._timeline;
- }
- t /= ts;
- return (t > reference) ? t - reference : ((zeroDur && t === reference) || (!tween._initted && t - reference < 2 * _tinyNum)) ? _tinyNum : ((t += tween.totalDuration() / tween._timeScale / ts) > reference + _tinyNum) ? 0 : t - reference - _tinyNum;
- };
- //---- TweenLite instance methods -----------------------------------------------------------------------------
- p._init = function() {
- var v = this.vars,
- op = this._overwrittenProps,
- dur = this._duration,
- immediate = !!v.immediateRender,
- ease = v.ease,
- i, initPlugins, pt, p, startVars, l;
- if (v.startAt) {
- if (this._startAt) {
- this._startAt.render(-1, true); //if we've run a startAt previously (when the tween instantiated), we should revert it so that the values re-instantiate correctly particularly for relative tweens. Without this, a TweenLite.fromTo(obj, 1, {x:"+=100"}, {x:"-=100"}), for example, would actually jump to +=200 because the startAt would run twice, doubling the relative change.
- this._startAt.kill();
- }
- startVars = {};
- for (p in v.startAt) { //copy the properties/values into a new object to avoid collisions, like var to = {x:0}, from = {x:500}; timeline.fromTo(e, 1, from, to).fromTo(e, 1, to, from);
- startVars[p] = v.startAt[p];
- }
- startVars.overwrite = false;
- startVars.immediateRender = true;
- startVars.lazy = (immediate && v.lazy !== false);
- startVars.startAt = startVars.delay = null; //no nesting of startAt objects allowed (otherwise it could cause an infinite loop).
- startVars.onUpdate = v.onUpdate;
- startVars.onUpdateScope = v.onUpdateScope || v.callbackScope || this;
- this._startAt = TweenLite.to(this.target, 0, startVars);
- if (immediate) {
- if (this._time > 0) {
- this._startAt = null; //tweens that render immediately (like most from() and fromTo() tweens) shouldn't revert when their parent timeline's playhead goes backward past the startTime because the initial render could have happened anytime and it shouldn't be directly correlated to this tween's startTime. Imagine setting up a complex animation where the beginning states of various objects are rendered immediately but the tween doesn't happen for quite some time - if we revert to the starting values as soon as the playhead goes backward past the tween's startTime, it will throw things off visually. Reversion should only happen in TimelineLite/Max instances where immediateRender was false (which is the default in the convenience methods like from()).
- } else if (dur !== 0) {
- return; //we skip initialization here so that overwriting doesn't occur until the tween actually begins. Otherwise, if you create several immediateRender:true tweens of the same target/properties to drop into a TimelineLite or TimelineMax, the last one created would overwrite the first ones because they didn't get placed into the timeline yet before the first render occurs and kicks in overwriting.
- }
- }
- } else if (v.runBackwards && dur !== 0) {
- //from() tweens must be handled uniquely: their beginning values must be rendered but we don't want overwriting to occur yet (when time is still 0). Wait until the tween actually begins before doing all the routines like overwriting. At that time, we should render at the END of the tween to ensure that things initialize correctly (remember, from() tweens go backwards)
- if (this._startAt) {
- this._startAt.render(-1, true);
- this._startAt.kill();
- this._startAt = null;
- } else {
- if (this._time !== 0) { //in rare cases (like if a from() tween runs and then is invalidate()-ed), immediateRender could be true but the initial forced-render gets skipped, so there's no need to force the render in this context when the _time is greater than 0
- immediate = false;
- }
- pt = {};
- for (p in v) { //copy props into a new object and skip any reserved props, otherwise onComplete or onUpdate or onStart could fire. We should, however, permit autoCSS to go through.
- if (!_reservedProps[p] || p === "autoCSS") {
- pt[p] = v[p];
- }
- }
- pt.overwrite = 0;
- pt.data = "isFromStart"; //we tag the tween with as "isFromStart" so that if [inside a plugin] we need to only do something at the very END of a tween, we have a way of identifying this tween as merely the one that's setting the beginning values for a "from()" tween. For example, clearProps in CSSPlugin should only get applied at the very END of a tween and without this tag, from(...{height:100, clearProps:"height", delay:1}) would wipe the height at the beginning of the tween and after 1 second, it'd kick back in.
- pt.lazy = (immediate && v.lazy !== false);
- pt.immediateRender = immediate; //zero-duration tweens render immediately by default, but if we're not specifically instructed to render this tween immediately, we should skip this and merely _init() to record the starting values (rendering them immediately would push them to completion which is wasteful in that case - we'd have to render(-1) immediately after)
- this._startAt = TweenLite.to(this.target, 0, pt);
- if (!immediate) {
- this._startAt._init(); //ensures that the initial values are recorded
- this._startAt._enabled(false); //no need to have the tween render on the next cycle. Disable it because we'll always manually control the renders of the _startAt tween.
- if (this.vars.immediateRender) {
- this._startAt = null;
- }
- } else if (this._time === 0) {
- return;
- }
- }
- }
- this._ease = ease = (!ease) ? TweenLite.defaultEase : (ease instanceof Ease) ? ease : (typeof(ease) === "function") ? new Ease(ease, v.easeParams) : _easeMap[ease] || TweenLite.defaultEase;
- if (v.easeParams instanceof Array && ease.config) {
- this._ease = ease.config.apply(ease, v.easeParams);
- }
- this._easeType = this._ease._type;
- this._easePower = this._ease._power;
- this._firstPT = null;
- if (this._targets) {
- l = this._targets.length;
- for (i = 0; i < l; i++) {
- if ( this._initProps( this._targets[i], (this._propLookup[i] = {}), this._siblings[i], (op ? op[i] : null), i) ) {
- initPlugins = true;
- }
- }
- } else {
- initPlugins = this._initProps(this.target, this._propLookup, this._siblings, op, 0);
- }
- if (initPlugins) {
- TweenLite._onPluginEvent("_onInitAllProps", this); //reorders the array in order of priority. Uses a static TweenPlugin method in order to minimize file size in TweenLite
- }
- if (op) if (!this._firstPT) if (typeof(this.target) !== "function") { //if all tweening properties have been overwritten, kill the tween. If the target is a function, it's probably a delayedCall so let it live.
- this._enabled(false, false);
- }
- if (v.runBackwards) {
- pt = this._firstPT;
- while (pt) {
- pt.s += pt.c;
- pt.c = -pt.c;
- pt = pt._next;
- }
- }
- this._onUpdate = v.onUpdate;
- this._initted = true;
- };
- p._initProps = function(target, propLookup, siblings, overwrittenProps, index) {
- var p, i, initPlugins, plugin, pt, v;
- if (target == null) {
- return false;
- }
- if (_lazyLookup[target._gsTweenID]) {
- _lazyRender(); //if other tweens of the same target have recently initted but haven't rendered yet, we've got to force the render so that the starting values are correct (imagine populating a timeline with a bunch of sequential tweens and then jumping to the end)
- }
- if (!this.vars.css) if (target.style) if (target !== window && target.nodeType) if (_plugins.css) if (this.vars.autoCSS !== false) { //it's so common to use TweenLite/Max to animate the css of DOM elements, we assume that if the target is a DOM element, that's what is intended (a convenience so that users don't have to wrap things in css:{}, although we still recommend it for a slight performance boost and better specificity). Note: we cannot check "nodeType" on the window inside an iframe.
- _autoCSS(this.vars, target);
- }
- for (p in this.vars) {
- v = this.vars[p];
- if (_reservedProps[p]) {
- if (v) if ((v instanceof Array) || (v.push && _isArray(v))) if (v.join("").indexOf("{self}") !== -1) {
- this.vars[p] = v = this._swapSelfInParams(v, this);
- }
- } else if (_plugins[p] && (plugin = new _plugins[p]())._onInitTween(target, this.vars[p], this, index)) {
- //t - target [object]
- //p - property [string]
- //s - start [number]
- //c - change [number]
- //f - isFunction [boolean]
- //n - name [string]
- //pg - isPlugin [boolean]
- //pr - priority [number]
- //m - mod [function | 0]
- this._firstPT = pt = {_next:this._firstPT, t:plugin, p:"setRatio", s:0, c:1, f:1, n:p, pg:1, pr:plugin._priority, m:0};
- i = plugin._overwriteProps.length;
- while (--i > -1) {
- propLookup[plugin._overwriteProps[i]] = this._firstPT;
- }
- if (plugin._priority || plugin._onInitAllProps) {
- initPlugins = true;
- }
- if (plugin._onDisable || plugin._onEnable) {
- this._notifyPluginsOfEnabled = true;
- }
- if (pt._next) {
- pt._next._prev = pt;
- }
- } else {
- propLookup[p] = _addPropTween.call(this, target, p, "get", v, p, 0, null, this.vars.stringFilter, index);
- }
- }
- if (overwrittenProps) if (this._kill(overwrittenProps, target)) { //another tween may have tried to overwrite properties of this tween before init() was called (like if two tweens start at the same time, the one created second will run first)
- return this._initProps(target, propLookup, siblings, overwrittenProps, index);
- }
- if (this._overwrite > 1) if (this._firstPT) if (siblings.length > 1) if (_applyOverwrite(target, this, propLookup, this._overwrite, siblings)) {
- this._kill(propLookup, target);
- return this._initProps(target, propLookup, siblings, overwrittenProps, index);
- }
- if (this._firstPT) if ((this.vars.lazy !== false && this._duration) || (this.vars.lazy && !this._duration)) { //zero duration tweens don't lazy render by default; everything else does.
- _lazyLookup[target._gsTweenID] = true;
- }
- return initPlugins;
- };
- p.render = function(time, suppressEvents, force) {
- var prevTime = this._time,
- duration = this._duration,
- prevRawPrevTime = this._rawPrevTime,
- isComplete, callback, pt, rawPrevTime;
- if (time >= duration - 0.0000001 && time >= 0) { //to work around occasional floating point math artifacts.
- this._totalTime = this._time = duration;
- this.ratio = this._ease._calcEnd ? this._ease.getRatio(1) : 1;
- if (!this._reversed ) {
- isComplete = true;
- callback = "onComplete";
- force = (force || this._timeline.autoRemoveChildren); //otherwise, if the animation is unpaused/activated after it's already finished, it doesn't get removed from the parent timeline.
- }
- if (duration === 0) if (this._initted || !this.vars.lazy || force) { //zero-duration tweens are tricky because we must discern the momentum/direction of time in order to determine whether the starting values should be rendered or the ending values. If the "playhead" of its timeline goes past the zero-duration tween in the forward direction or lands directly on it, the end values should be rendered, but if the timeline's "playhead" moves past it in the backward direction (from a postitive time to a negative time), the starting values must be rendered.
- if (this._startTime === this._timeline._duration) { //if a zero-duration tween is at the VERY end of a timeline and that timeline renders at its end, it will typically add a tiny bit of cushion to the render time to prevent rounding errors from getting in the way of tweens rendering their VERY end. If we then reverse() that timeline, the zero-duration tween will trigger its onReverseComplete even though technically the playhead didn't pass over it again. It's a very specific edge case we must accommodate.
- time = 0;
- }
- if (prevRawPrevTime < 0 || (time <= 0 && time >= -0.0000001) || (prevRawPrevTime === _tinyNum && this.data !== "isPause")) if (prevRawPrevTime !== time) { //note: when this.data is "isPause", it's a callback added by addPause() on a timeline that we should not be triggered when LEAVING its exact start time. In other words, tl.addPause(1).play(1) shouldn't pause.
- force = true;
- if (prevRawPrevTime > _tinyNum) {
- callback = "onReverseComplete";
- }
- }
- this._rawPrevTime = rawPrevTime = (!suppressEvents || time || prevRawPrevTime === time) ? time : _tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient.
- }
- } else if (time < 0.0000001) { //to work around occasional floating point math artifacts, round super small values to 0.
- this._totalTime = this._time = 0;
- this.ratio = this._ease._calcEnd ? this._ease.getRatio(0) : 0;
- if (prevTime !== 0 || (duration === 0 && prevRawPrevTime > 0)) {
- callback = "onReverseComplete";
- isComplete = this._reversed;
- }
- if (time < 0) {
- this._active = false;
- if (duration === 0) if (this._initted || !this.vars.lazy || force) { //zero-duration tweens are tricky because we must discern the momentum/direction of time in order to determine whether the starting values should be rendered or the ending values. If the "playhead" of its timeline goes past the zero-duration tween in the forward direction or lands directly on it, the end values should be rendered, but if the timeline's "playhead" moves past it in the backward direction (from a postitive time to a negative time), the starting values must be rendered.
- if (prevRawPrevTime >= 0 && !(prevRawPrevTime === _tinyNum && this.data === "isPause")) {
- force = true;
- }
- this._rawPrevTime = rawPrevTime = (!suppressEvents || time || prevRawPrevTime === time) ? time : _tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient.
- }
- }
- if (!this._initted || (this._startAt && this._startAt.progress())) { //if we render the very beginning (time == 0) of a fromTo(), we must force the render (normal tweens wouldn't need to render at a time of 0 when the prevTime was also 0). This is also mandatory to make sure overwriting kicks in immediately. Also, we check progress() because if startAt has already rendered at its end, we should force a render at its beginning. Otherwise, if you put the playhead directly on top of where a fromTo({immediateRender:false}) starts, and then move it backwards, the from() won't revert its values.
- force = true;
- }
- } else {
- this._totalTime = this._time = time;
- if (this._easeType) {
- var r = time / duration, type = this._easeType, pow = this._easePower;
- if (type === 1 || (type === 3 && r >= 0.5)) {
- r = 1 - r;
- }
- if (type === 3) {
- r *= 2;
- }
- if (pow === 1) {
- r *= r;
- } else if (pow === 2) {
- r *= r * r;
- } else if (pow === 3) {
- r *= r * r * r;
- } else if (pow === 4) {
- r *= r * r * r * r;
- }
- if (type === 1) {
- this.ratio = 1 - r;
- } else if (type === 2) {
- this.ratio = r;
- } else if (time / duration < 0.5) {
- this.ratio = r / 2;
- } else {
- this.ratio = 1 - (r / 2);
- }
- } else {
- this.ratio = this._ease.getRatio(time / duration);
- }
- }
- if (this._time === prevTime && !force) {
- return;
- } else if (!this._initted) {
- this._init();
- if (!this._initted || this._gc) { //immediateRender tweens typically won't initialize until the playhead advances (_time is greater than 0) in order to ensure that overwriting occurs properly. Also, if all of the tweening properties have been overwritten (which would cause _gc to be true, as set in _init()), we shouldn't continue otherwise an onStart callback could be called for example.
- return;
- } else if (!force && this._firstPT && ((this.vars.lazy !== false && this._duration) || (this.vars.lazy && !this._duration))) {
- this._time = this._totalTime = prevTime;
- this._rawPrevTime = prevRawPrevTime;
- _lazyTweens.push(this);
- this._lazy = [time, suppressEvents];
- return;
- }
- //_ease is initially set to defaultEase, so now that init() has run, _ease is set properly and we need to recalculate the ratio. Overall this is faster than using conditional logic earlier in the method to avoid having to set ratio twice because we only init() once but renderTime() gets called VERY frequently.
- if (this._time && !isComplete) {
- this.ratio = this._ease.getRatio(this._time / duration);
- } else if (isComplete && this._ease._calcEnd) {
- this.ratio = this._ease.getRatio((this._time === 0) ? 0 : 1);
- }
- }
- if (this._lazy !== false) { //in case a lazy render is pending, we should flush it because the new render is occurring now (imagine a lazy tween instantiating and then immediately the user calls tween.seek(tween.duration()), skipping to the end - the end render would be forced, and then if we didn't flush the lazy render, it'd fire AFTER the seek(), rendering it at the wrong time.
- this._lazy = false;
- }
- if (!this._active) if (!this._paused && this._time !== prevTime && time >= 0) {
- this._active = true; //so that if the user renders a tween (as opposed to the timeline rendering it), the timeline is forced to re-render and align it with the proper time/frame on the next rendering cycle. Maybe the tween already finished but the user manually re-renders it as halfway done.
- }
- if (prevTime === 0) {
- if (this._startAt) {
- if (time >= 0) {
- this._startAt.render(time, suppressEvents, force);
- } else if (!callback) {
- callback = "_dummyGS"; //if no callback is defined, use a dummy value just so that the condition at the end evaluates as true because _startAt should render AFTER the normal render loop when the time is negative. We could handle this in a more intuitive way, of course, but the render loop is the MOST important thing to optimize, so this technique allows us to avoid adding extra conditional logic in a high-frequency area.
- }
- }
- if (this.vars.onStart) if (this._time !== 0 || duration === 0) if (!suppressEvents) {
- this._callback("onStart");
- }
- }
- pt = this._firstPT;
- while (pt) {
- if (pt.f) {
- pt.t[pt.p](pt.c * this.ratio + pt.s);
- } else {
- pt.t[pt.p] = pt.c * this.ratio + pt.s;
- }
- pt = pt._next;
- }
- if (this._onUpdate) {
- if (time < 0) if (this._startAt && time !== -0.0001) { //if the tween is positioned at the VERY beginning (_startTime 0) of its parent timeline, it's illegal for the playhead to go back further, so we should not render the recorded startAt values.
- this._startAt.render(time, suppressEvents, force); //note: for performance reasons, we tuck this conditional logic inside less traveled areas (most tweens don't have an onUpdate). We'd just have it at the end before the onComplete, but the values should be updated before any onUpdate is called, so we ALSO put it here and then if it's not called, we do so later near the onComplete.
- }
- if (!suppressEvents) if (this._time !== prevTime || isComplete || force) {
- this._callback("onUpdate");
- }
- }
- if (callback) if (!this._gc || force) { //check _gc because there's a chance that kill() could be called in an onUpdate
- if (time < 0 && this._startAt && !this._onUpdate && time !== -0.0001) { //-0.0001 is a special value that we use when looping back to the beginning of a repeated TimelineMax, in which case we shouldn't render the _startAt values.
- this._startAt.render(time, suppressEvents, force);
- }
- if (isComplete) {
- if (this._timeline.autoRemoveChildren) {
- this._enabled(false, false);
- }
- this._active = false;
- }
- if (!suppressEvents && this.vars[callback]) {
- this._callback(callback);
- }
- if (duration === 0 && this._rawPrevTime === _tinyNum && rawPrevTime !== _tinyNum) { //the onComplete or onReverseComplete could trigger movement of the playhead and for zero-duration tweens (which must discern direction) that land directly back on their start time, we don't want to fire again on the next render. Think of several addPause()'s in a timeline that forces the playhead to a certain spot, but what if it's already paused and another tween is tweening the "time" of the timeline? Each time it moves [forward] past that spot, it would move back, and since suppressEvents is true, it'd reset _rawPrevTime to _tinyNum so that when it begins again, the callback would fire (so ultimately it could bounce back and forth during that tween). Again, this is a very uncommon scenario, but possible nonetheless.
- this._rawPrevTime = 0;
- }
- }
- };
- p._kill = function(vars, target, overwritingTween) {
- if (vars === "all") {
- vars = null;
- }
- if (vars == null) if (target == null || target === this.target) {
- this._lazy = false;
- return this._enabled(false, false);
- }
- target = (typeof(target) !== "string") ? (target || this._targets || this.target) : TweenLite.selector(target) || target;
- var simultaneousOverwrite = (overwritingTween && this._time && overwritingTween._startTime === this._startTime && this._timeline === overwritingTween._timeline),
- i, overwrittenProps, p, pt, propLookup, changed, killProps, record, killed;
- if ((_isArray(target) || _isSelector(target)) && typeof(target[0]) !== "number") {
- i = target.length;
- while (--i > -1) {
- if (this._kill(vars, target[i], overwritingTween)) {
- changed = true;
- }
- }
- } else {
- if (this._targets) {
- i = this._targets.length;
- while (--i > -1) {
- if (target === this._targets[i]) {
- propLookup = this._propLookup[i] || {};
- this._overwrittenProps = this._overwrittenProps || [];
- overwrittenProps = this._overwrittenProps[i] = vars ? this._overwrittenProps[i] || {} : "all";
- break;
- }
- }
- } else if (target !== this.target) {
- return false;
- } else {
- propLookup = this._propLookup;
- overwrittenProps = this._overwrittenProps = vars ? this._overwrittenProps || {} : "all";
- }
- if (propLookup) {
- killProps = vars || propLookup;
- record = (vars !== overwrittenProps && overwrittenProps !== "all" && vars !== propLookup && (typeof(vars) !== "object" || !vars._tempKill)); //_tempKill is a super-secret way to delete a particular tweening property but NOT have it remembered as an official overwritten property (like in BezierPlugin)
- if (overwritingTween && (TweenLite.onOverwrite || this.vars.onOverwrite)) {
- for (p in killProps) {
- if (propLookup[p]) {
- if (!killed) {
- killed = [];
- }
- killed.push(p);
- }
- }
- if ((killed || !vars) && !_onOverwrite(this, overwritingTween, target, killed)) { //if the onOverwrite returned false, that means the user wants to override the overwriting (cancel it).
- return false;
- }
- }
- for (p in killProps) {
- if ((pt = propLookup[p])) {
- if (simultaneousOverwrite) { //if another tween overwrites this one and they both start at exactly the same time, yet this tween has already rendered once (for example, at 0.001) because it's first in the queue, we should revert the values to where they were at 0 so that the starting values aren't contaminated on the overwriting tween.
- if (pt.f) {
- pt.t[pt.p](pt.s);
- } else {
- pt.t[pt.p] = pt.s;
- }
- changed = true;
- }
- if (pt.pg && pt.t._kill(killProps)) {
- changed = true; //some plugins need to be notified so they can perform cleanup tasks first
- }
- if (!pt.pg || pt.t._overwriteProps.length === 0) {
- if (pt._prev) {
- pt._prev._next = pt._next;
- } else if (pt === this._firstPT) {
- this._firstPT = pt._next;
- }
- if (pt._next) {
- pt._next._prev = pt._prev;
- }
- pt._next = pt._prev = null;
- }
- delete propLookup[p];
- }
- if (record) {
- overwrittenProps[p] = 1;
- }
- }
- if (!this._firstPT && this._initted) { //if all tweening properties are killed, kill the tween. Without this line, if there's a tween with multiple targets and then you killTweensOf() each target individually, the tween would technically still remain active and fire its onComplete even though there aren't any more properties tweening.
- this._enabled(false, false);
- }
- }
- }
- return changed;
- };
- p.invalidate = function() {
- if (this._notifyPluginsOfEnabled) {
- TweenLite._onPluginEvent("_onDisable", this);
- }
- this._firstPT = this._overwrittenProps = this._startAt = this._onUpdate = null;
- this._notifyPluginsOfEnabled = this._active = this._lazy = false;
- this._propLookup = (this._targets) ? {} : [];
- Animation.prototype.invalidate.call(this);
- if (this.vars.immediateRender) {
- this._time = -_tinyNum; //forces a render without having to set the render() "force" parameter to true because we want to allow lazying by default (using the "force" parameter always forces an immediate full render)
- this.render(Math.min(0, -this._delay)); //in case delay is negative.
- }
- return this;
- };
- p._enabled = function(enabled, ignoreTimeline) {
- if (!_tickerActive) {
- _ticker.wake();
- }
- if (enabled && this._gc) {
- var targets = this._targets,
- i;
- if (targets) {
- i = targets.length;
- while (--i > -1) {
- this._siblings[i] = _register(targets[i], this, true);
- }
- } else {
- this._siblings = _register(this.target, this, true);
- }
- }
- Animation.prototype._enabled.call(this, enabled, ignoreTimeline);
- if (this._notifyPluginsOfEnabled) if (this._firstPT) {
- return TweenLite._onPluginEvent((enabled ? "_onEnable" : "_onDisable"), this);
- }
- return false;
- };
- //----TweenLite static methods -----------------------------------------------------
- TweenLite.to = function(target, duration, vars) {
- return new TweenLite(target, duration, vars);
- };
- TweenLite.from = function(target, duration, vars) {
- vars.runBackwards = true;
- vars.immediateRender = (vars.immediateRender != false);
- return new TweenLite(target, duration, vars);
- };
- TweenLite.fromTo = function(target, duration, fromVars, toVars) {
- toVars.startAt = fromVars;
- toVars.immediateRender = (toVars.immediateRender != false && fromVars.immediateRender != false);
- return new TweenLite(target, duration, toVars);
- };
- TweenLite.delayedCall = function(delay, callback, params, scope, useFrames) {
- return new TweenLite(callback, 0, {delay:delay, onComplete:callback, onCompleteParams:params, callbackScope:scope, onReverseComplete:callback, onReverseCompleteParams:params, immediateRender:false, lazy:false, useFrames:useFrames, overwrite:0});
- };
- TweenLite.set = function(target, vars) {
- return new TweenLite(target, 0, vars);
- };
- TweenLite.getTweensOf = function(target, onlyActive) {
- if (target == null) { return []; }
- target = (typeof(target) !== "string") ? target : TweenLite.selector(target) || target;
- var i, a, j, t;
- if ((_isArray(target) || _isSelector(target)) && typeof(target[0]) !== "number") {
- i = target.length;
- a = [];
- while (--i > -1) {
- a = a.concat(TweenLite.getTweensOf(target[i], onlyActive));
- }
- i = a.length;
- //now get rid of any duplicates (tweens of arrays of objects could cause duplicates)
- while (--i > -1) {
- t = a[i];
- j = i;
- while (--j > -1) {
- if (t === a[j]) {
- a.splice(i, 1);
- }
- }
- }
- } else if (target._gsTweenID) {
- a = _register(target).concat();
- i = a.length;
- while (--i > -1) {
- if (a[i]._gc || (onlyActive && !a[i].isActive())) {
- a.splice(i, 1);
- }
- }
- }
- return a || [];
- };
- TweenLite.killTweensOf = TweenLite.killDelayedCallsTo = function(target, onlyActive, vars) {
- if (typeof(onlyActive) === "object") {
- vars = onlyActive; //for backwards compatibility (before "onlyActive" parameter was inserted)
- onlyActive = false;
- }
- var a = TweenLite.getTweensOf(target, onlyActive),
- i = a.length;
- while (--i > -1) {
- a[i]._kill(vars, target);
- }
- };
- /*
- * ----------------------------------------------------------------
- * TweenPlugin (could easily be split out as a separate file/class, but included for ease of use (so that people don't need to include another script call before loading plugins which is easy to forget)
- * ----------------------------------------------------------------
- */
- var TweenPlugin = _class("plugins.TweenPlugin", function(props, priority) {
- this._overwriteProps = (props || "").split(",");
- this._propName = this._overwriteProps[0];
- this._priority = priority || 0;
- this._super = TweenPlugin.prototype;
- }, true);
- p = TweenPlugin.prototype;
- TweenPlugin.version = "1.19.0";
- TweenPlugin.API = 2;
- p._firstPT = null;
- p._addTween = _addPropTween;
- p.setRatio = _setRatio;
- p._kill = function(lookup) {
- var a = this._overwriteProps,
- pt = this._firstPT,
- i;
- if (lookup[this._propName] != null) {
- this._overwriteProps = [];
- } else {
- i = a.length;
- while (--i > -1) {
- if (lookup[a[i]] != null) {
- a.splice(i, 1);
- }
- }
- }
- while (pt) {
- if (lookup[pt.n] != null) {
- if (pt._next) {
- pt._next._prev = pt._prev;
- }
- if (pt._prev) {
- pt._prev._next = pt._next;
- pt._prev = null;
- } else if (this._firstPT === pt) {
- this._firstPT = pt._next;
- }
- }
- pt = pt._next;
- }
- return false;
- };
- p._mod = p._roundProps = function(lookup) {
- var pt = this._firstPT,
- val;
- while (pt) {
- val = lookup[this._propName] || (pt.n != null && lookup[ pt.n.split(this._propName + "_").join("") ]);
- if (val && typeof(val) === "function") { //some properties that are very plugin-specific add a prefix named after the _propName plus an underscore, so we need to ignore that extra stuff here.
- if (pt.f === 2) {
- pt.t._applyPT.m = val;
- } else {
- pt.m = val;
- }
- }
- pt = pt._next;
- }
- };
- TweenLite._onPluginEvent = function(type, tween) {
- var pt = tween._firstPT,
- changed, pt2, first, last, next;
- if (type === "_onInitAllProps") {
- //sorts the PropTween linked list in order of priority because some plugins need to render earlier/later than others, like MotionBlurPlugin applies its effects after all x/y/alpha tweens have rendered on each frame.
- while (pt) {
- next = pt._next;
- pt2 = first;
- while (pt2 && pt2.pr > pt.pr) {
- pt2 = pt2._next;
- }
- if ((pt._prev = pt2 ? pt2._prev : last)) {
- pt._prev._next = pt;
- } else {
- first = pt;
- }
- if ((pt._next = pt2)) {
- pt2._prev = pt;
- } else {
- last = pt;
- }
- pt = next;
- }
- pt = tween._firstPT = first;
- }
- while (pt) {
- if (pt.pg) if (typeof(pt.t[type]) === "function") if (pt.t[type]()) {
- changed = true;
- }
- pt = pt._next;
- }
- return changed;
- };
- TweenPlugin.activate = function(plugins) {
- var i = plugins.length;
- while (--i > -1) {
- if (plugins[i].API === TweenPlugin.API) {
- _plugins[(new plugins[i]())._propName] = plugins[i];
- }
- }
- return true;
- };
- //provides a more concise way to define plugins that have no dependencies besides TweenPlugin and TweenLite, wrapping common boilerplate stuff into one function (added in 1.9.0). You don't NEED to use this to define a plugin - the old way still works and can be useful in certain (rare) situations.
- _gsDefine.plugin = function(config) {
- if (!config || !config.propName || !config.init || !config.API) { throw "illegal plugin definition."; }
- var propName = config.propName,
- priority = config.priority || 0,
- overwriteProps = config.overwriteProps,
- map = {init:"_onInitTween", set:"setRatio", kill:"_kill", round:"_mod", mod:"_mod", initAll:"_onInitAllProps"},
- Plugin = _class("plugins." + propName.charAt(0).toUpperCase() + propName.substr(1) + "Plugin",
- function() {
- TweenPlugin.call(this, propName, priority);
- this._overwriteProps = overwriteProps || [];
- }, (config.global === true)),
- p = Plugin.prototype = new TweenPlugin(propName),
- prop;
- p.constructor = Plugin;
- Plugin.API = config.API;
- for (prop in map) {
- if (typeof(config[prop]) === "function") {
- p[map[prop]] = config[prop];
- }
- }
- Plugin.version = config.version;
- TweenPlugin.activate([Plugin]);
- return Plugin;
- };
- //now run through all the dependencies discovered and if any are missing, log that to the console as a warning. This is why it's best to have TweenLite load last - it can check all the dependencies for you.
- a = window._gsQueue;
- if (a) {
- for (i = 0; i < a.length; i++) {
- a[i]();
- }
- for (p in _defLookup) {
- if (!_defLookup[p].func) {
- window.console.log("GSAP encountered missing dependency: " + p);
- }
- }
- }
- _tickerActive = false; //ensures that the first official animation forces a ticker.tick() to update the time when it is instantiated
- })((typeof(module) !== "undefined" && module.exports && typeof(global) !== "undefined") ? global : this || window, "TweenLite");
- }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
- },{}],212:[function(require,module,exports){
- (function (global){
- /*!
- * VERSION: 1.20.2
- * DATE: 2017-06-30
- * UPDATES AND DOCS AT: http://greensock.com
- *
- * Includes all of the following: TweenLite, TweenMax, TimelineLite, TimelineMax, EasePack, CSSPlugin, RoundPropsPlugin, BezierPlugin, AttrPlugin, DirectionalRotationPlugin
- *
- * @license Copyright (c) 2008-2017, GreenSock. All rights reserved.
- * This work is subject to the terms at http://greensock.com/standard-license or for
- * Club GreenSock members, the software agreement that was issued with your membership.
- *
- * @author: Jack Doyle, jack@greensock.com
- **/
- var _gsScope = (typeof(module) !== "undefined" && module.exports && typeof(global) !== "undefined") ? global : this || window; //helps ensure compatibility with AMD/RequireJS and CommonJS/Node
- (_gsScope._gsQueue || (_gsScope._gsQueue = [])).push( function() {
- "use strict";
- _gsScope._gsDefine("TweenMax", ["core.Animation","core.SimpleTimeline","TweenLite"], function(Animation, SimpleTimeline, TweenLite) {
- var _slice = function(a) { //don't use [].slice because that doesn't work in IE8 with a NodeList that's returned by querySelectorAll()
- var b = [],
- l = a.length,
- i;
- for (i = 0; i !== l; b.push(a[i++]));
- return b;
- },
- _applyCycle = function(vars, targets, i) {
- var alt = vars.cycle,
- p, val;
- for (p in alt) {
- val = alt[p];
- vars[p] = (typeof(val) === "function") ? val(i, targets[i]) : val[i % val.length];
- }
- delete vars.cycle;
- },
- TweenMax = function(target, duration, vars) {
- TweenLite.call(this, target, duration, vars);
- this._cycle = 0;
- this._yoyo = (this.vars.yoyo === true || !!this.vars.yoyoEase);
- this._repeat = this.vars.repeat || 0;
- this._repeatDelay = this.vars.repeatDelay || 0;
- this._dirty = true; //ensures that if there is any repeat, the totalDuration will get recalculated to accurately report it.
- this.render = TweenMax.prototype.render; //speed optimization (avoid prototype lookup on this "hot" method)
- },
- _tinyNum = 0.0000000001,
- TweenLiteInternals = TweenLite._internals,
- _isSelector = TweenLiteInternals.isSelector,
- _isArray = TweenLiteInternals.isArray,
- p = TweenMax.prototype = TweenLite.to({}, 0.1, {}),
- _blankArray = [];
- TweenMax.version = "1.20.2";
- p.constructor = TweenMax;
- p.kill()._gc = false;
- TweenMax.killTweensOf = TweenMax.killDelayedCallsTo = TweenLite.killTweensOf;
- TweenMax.getTweensOf = TweenLite.getTweensOf;
- TweenMax.lagSmoothing = TweenLite.lagSmoothing;
- TweenMax.ticker = TweenLite.ticker;
- TweenMax.render = TweenLite.render;
- p.invalidate = function() {
- this._yoyo = (this.vars.yoyo === true || !!this.vars.yoyoEase);
- this._repeat = this.vars.repeat || 0;
- this._repeatDelay = this.vars.repeatDelay || 0;
- this._yoyoEase = null;
- this._uncache(true);
- return TweenLite.prototype.invalidate.call(this);
- };
-
- p.updateTo = function(vars, resetDuration) {
- var curRatio = this.ratio,
- immediate = this.vars.immediateRender || vars.immediateRender,
- p;
- if (resetDuration && this._startTime < this._timeline._time) {
- this._startTime = this._timeline._time;
- this._uncache(false);
- if (this._gc) {
- this._enabled(true, false);
- } else {
- this._timeline.insert(this, this._startTime - this._delay); //ensures that any necessary re-sequencing of Animations in the timeline occurs to make sure the rendering order is correct.
- }
- }
- for (p in vars) {
- this.vars[p] = vars[p];
- }
- if (this._initted || immediate) {
- if (resetDuration) {
- this._initted = false;
- if (immediate) {
- this.render(0, true, true);
- }
- } else {
- if (this._gc) {
- this._enabled(true, false);
- }
- if (this._notifyPluginsOfEnabled && this._firstPT) {
- TweenLite._onPluginEvent("_onDisable", this); //in case a plugin like MotionBlur must perform some cleanup tasks
- }
- if (this._time / this._duration > 0.998) { //if the tween has finished (or come extremely close to finishing), we just need to rewind it to 0 and then render it again at the end which forces it to re-initialize (parsing the new vars). We allow tweens that are close to finishing (but haven't quite finished) to work this way too because otherwise, the values are so small when determining where to project the starting values that binary math issues creep in and can make the tween appear to render incorrectly when run backwards.
- var prevTime = this._totalTime;
- this.render(0, true, false);
- this._initted = false;
- this.render(prevTime, true, false);
- } else {
- this._initted = false;
- this._init();
- if (this._time > 0 || immediate) {
- var inv = 1 / (1 - curRatio),
- pt = this._firstPT, endValue;
- while (pt) {
- endValue = pt.s + pt.c;
- pt.c *= inv;
- pt.s = endValue - pt.c;
- pt = pt._next;
- }
- }
- }
- }
- }
- return this;
- };
-
- p.render = function(time, suppressEvents, force) {
- if (!this._initted) if (this._duration === 0 && this.vars.repeat) { //zero duration tweens that render immediately have render() called from TweenLite's constructor, before TweenMax's constructor has finished setting _repeat, _repeatDelay, and _yoyo which are critical in determining totalDuration() so we need to call invalidate() which is a low-kb way to get those set properly.
- this.invalidate();
- }
- var totalDur = (!this._dirty) ? this._totalDuration : this.totalDuration(),
- prevTime = this._time,
- prevTotalTime = this._totalTime,
- prevCycle = this._cycle,
- duration = this._duration,
- prevRawPrevTime = this._rawPrevTime,
- isComplete, callback, pt, cycleDuration, r, type, pow, rawPrevTime, yoyoEase;
- if (time >= totalDur - 0.0000001 && time >= 0) { //to work around occasional floating point math artifacts.
- this._totalTime = totalDur;
- this._cycle = this._repeat;
- if (this._yoyo && (this._cycle & 1) !== 0) {
- this._time = 0;
- this.ratio = this._ease._calcEnd ? this._ease.getRatio(0) : 0;
- } else {
- this._time = duration;
- this.ratio = this._ease._calcEnd ? this._ease.getRatio(1) : 1;
- }
- if (!this._reversed) {
- isComplete = true;
- callback = "onComplete";
- force = (force || this._timeline.autoRemoveChildren); //otherwise, if the animation is unpaused/activated after it's already finished, it doesn't get removed from the parent timeline.
- }
- if (duration === 0) if (this._initted || !this.vars.lazy || force) { //zero-duration tweens are tricky because we must discern the momentum/direction of time in order to determine whether the starting values should be rendered or the ending values. If the "playhead" of its timeline goes past the zero-duration tween in the forward direction or lands directly on it, the end values should be rendered, but if the timeline's "playhead" moves past it in the backward direction (from a postitive time to a negative time), the starting values must be rendered.
- if (this._startTime === this._timeline._duration) { //if a zero-duration tween is at the VERY end of a timeline and that timeline renders at its end, it will typically add a tiny bit of cushion to the render time to prevent rounding errors from getting in the way of tweens rendering their VERY end. If we then reverse() that timeline, the zero-duration tween will trigger its onReverseComplete even though technically the playhead didn't pass over it again. It's a very specific edge case we must accommodate.
- time = 0;
- }
- if (prevRawPrevTime < 0 || (time <= 0 && time >= -0.0000001) || (prevRawPrevTime === _tinyNum && this.data !== "isPause")) if (prevRawPrevTime !== time) { //note: when this.data is "isPause", it's a callback added by addPause() on a timeline that we should not be triggered when LEAVING its exact start time. In other words, tl.addPause(1).play(1) shouldn't pause.
- force = true;
- if (prevRawPrevTime > _tinyNum) {
- callback = "onReverseComplete";
- }
- }
- this._rawPrevTime = rawPrevTime = (!suppressEvents || time || prevRawPrevTime === time) ? time : _tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient.
- }
-
- } else if (time < 0.0000001) { //to work around occasional floating point math artifacts, round super small values to 0.
- this._totalTime = this._time = this._cycle = 0;
- this.ratio = this._ease._calcEnd ? this._ease.getRatio(0) : 0;
- if (prevTotalTime !== 0 || (duration === 0 && prevRawPrevTime > 0)) {
- callback = "onReverseComplete";
- isComplete = this._reversed;
- }
- if (time < 0) {
- this._active = false;
- if (duration === 0) if (this._initted || !this.vars.lazy || force) { //zero-duration tweens are tricky because we must discern the momentum/direction of time in order to determine whether the starting values should be rendered or the ending values. If the "playhead" of its timeline goes past the zero-duration tween in the forward direction or lands directly on it, the end values should be rendered, but if the timeline's "playhead" moves past it in the backward direction (from a postitive time to a negative time), the starting values must be rendered.
- if (prevRawPrevTime >= 0) {
- force = true;
- }
- this._rawPrevTime = rawPrevTime = (!suppressEvents || time || prevRawPrevTime === time) ? time : _tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient.
- }
- }
- if (!this._initted) { //if we render the very beginning (time == 0) of a fromTo(), we must force the render (normal tweens wouldn't need to render at a time of 0 when the prevTime was also 0). This is also mandatory to make sure overwriting kicks in immediately.
- force = true;
- }
- } else {
- this._totalTime = this._time = time;
- if (this._repeat !== 0) {
- cycleDuration = duration + this._repeatDelay;
- this._cycle = (this._totalTime / cycleDuration) >> 0; //originally _totalTime % cycleDuration but floating point errors caused problems, so I normalized it. (4 % 0.8 should be 0 but some browsers report it as 0.79999999!)
- if (this._cycle !== 0) if (this._cycle === this._totalTime / cycleDuration && prevTotalTime <= time) {
- this._cycle--; //otherwise when rendered exactly at the end time, it will act as though it is repeating (at the beginning)
- }
- this._time = this._totalTime - (this._cycle * cycleDuration);
- if (this._yoyo) if ((this._cycle & 1) !== 0) {
- this._time = duration - this._time;
- yoyoEase = this._yoyoEase || this.vars.yoyoEase; //note: we don't set this._yoyoEase in _init() like we do other properties because it's TweenMax-specific and doing it here allows us to optimize performance (most tweens don't have a yoyoEase). Note that we also must skip the this.ratio calculation further down right after we _init() in this function, because we're doing it here.
- if (yoyoEase) {
- if (!this._yoyoEase) {
- if (yoyoEase === true && !this._initted) { //if it's not initted and yoyoEase is true, this._ease won't have been populated yet so we must discern it here.
- yoyoEase = this.vars.ease;
- this._yoyoEase = yoyoEase = !yoyoEase ? TweenLite.defaultEase : (yoyoEase instanceof Ease) ? yoyoEase : (typeof(yoyoEase) === "function") ? new Ease(yoyoEase, this.vars.easeParams) : Ease.map[yoyoEase] || TweenLite.defaultEase;
- } else {
- this._yoyoEase = yoyoEase = (yoyoEase === true) ? this._ease : (yoyoEase instanceof Ease) ? yoyoEase : Ease.map[yoyoEase];
- }
- }
- this.ratio = yoyoEase ? 1 - yoyoEase.getRatio((duration - this._time) / duration) : 0;
- }
- }
- if (this._time > duration) {
- this._time = duration;
- } else if (this._time < 0) {
- this._time = 0;
- }
- }
- if (this._easeType && !yoyoEase) {
- r = this._time / duration;
- type = this._easeType;
- pow = this._easePower;
- if (type === 1 || (type === 3 && r >= 0.5)) {
- r = 1 - r;
- }
- if (type === 3) {
- r *= 2;
- }
- if (pow === 1) {
- r *= r;
- } else if (pow === 2) {
- r *= r * r;
- } else if (pow === 3) {
- r *= r * r * r;
- } else if (pow === 4) {
- r *= r * r * r * r;
- }
- if (type === 1) {
- this.ratio = 1 - r;
- } else if (type === 2) {
- this.ratio = r;
- } else if (this._time / duration < 0.5) {
- this.ratio = r / 2;
- } else {
- this.ratio = 1 - (r / 2);
- }
- } else if (!yoyoEase) {
- this.ratio = this._ease.getRatio(this._time / duration);
- }
-
- }
-
- if (prevTime === this._time && !force && prevCycle === this._cycle) {
- if (prevTotalTime !== this._totalTime) if (this._onUpdate) if (!suppressEvents) { //so that onUpdate fires even during the repeatDelay - as long as the totalTime changed, we should trigger onUpdate.
- this._callback("onUpdate");
- }
- return;
- } else if (!this._initted) {
- this._init();
- if (!this._initted || this._gc) { //immediateRender tweens typically won't initialize until the playhead advances (_time is greater than 0) in order to ensure that overwriting occurs properly. Also, if all of the tweening properties have been overwritten (which would cause _gc to be true, as set in _init()), we shouldn't continue otherwise an onStart callback could be called for example.
- return;
- } else if (!force && this._firstPT && ((this.vars.lazy !== false && this._duration) || (this.vars.lazy && !this._duration))) { //we stick it in the queue for rendering at the very end of the tick - this is a performance optimization because browsers invalidate styles and force a recalculation if you read, write, and then read style data (so it's better to read/read/read/write/write/write than read/write/read/write/read/write). The down side, of course, is that usually you WANT things to render immediately because you may have code running right after that which depends on the change. Like imagine running TweenLite.set(...) and then immediately after that, creating a nother tween that animates the same property to another value; the starting values of that 2nd tween wouldn't be accurate if lazy is true.
- this._time = prevTime;
- this._totalTime = prevTotalTime;
- this._rawPrevTime = prevRawPrevTime;
- this._cycle = prevCycle;
- TweenLiteInternals.lazyTweens.push(this);
- this._lazy = [time, suppressEvents];
- return;
- }
- //_ease is initially set to defaultEase, so now that init() has run, _ease is set properly and we need to recalculate the ratio. Overall this is faster than using conditional logic earlier in the method to avoid having to set ratio twice because we only init() once but renderTime() gets called VERY frequently.
- if (this._time && !isComplete && !yoyoEase) {
- this.ratio = this._ease.getRatio(this._time / duration);
- } else if (isComplete && this._ease._calcEnd && !yoyoEase) {
- this.ratio = this._ease.getRatio((this._time === 0) ? 0 : 1);
- }
- }
- if (this._lazy !== false) {
- this._lazy = false;
- }
- if (!this._active) if (!this._paused && this._time !== prevTime && time >= 0) {
- this._active = true; //so that if the user renders a tween (as opposed to the timeline rendering it), the timeline is forced to re-render and align it with the proper time/frame on the next rendering cycle. Maybe the tween already finished but the user manually re-renders it as halfway done.
- }
- if (prevTotalTime === 0) {
- if (this._initted === 2 && time > 0) {
- //this.invalidate();
- this._init(); //will just apply overwriting since _initted of (2) means it was a from() tween that had immediateRender:true
- }
- if (this._startAt) {
- if (time >= 0) {
- this._startAt.render(time, suppressEvents, force);
- } else if (!callback) {
- callback = "_dummyGS"; //if no callback is defined, use a dummy value just so that the condition at the end evaluates as true because _startAt should render AFTER the normal render loop when the time is negative. We could handle this in a more intuitive way, of course, but the render loop is the MOST important thing to optimize, so this technique allows us to avoid adding extra conditional logic in a high-frequency area.
- }
- }
- if (this.vars.onStart) if (this._totalTime !== 0 || duration === 0) if (!suppressEvents) {
- this._callback("onStart");
- }
- }
-
- pt = this._firstPT;
- while (pt) {
- if (pt.f) {
- pt.t[pt.p](pt.c * this.ratio + pt.s);
- } else {
- pt.t[pt.p] = pt.c * this.ratio + pt.s;
- }
- pt = pt._next;
- }
-
- if (this._onUpdate) {
- if (time < 0) if (this._startAt && this._startTime) { //if the tween is positioned at the VERY beginning (_startTime 0) of its parent timeline, it's illegal for the playhead to go back further, so we should not render the recorded startAt values.
- this._startAt.render(time, suppressEvents, force); //note: for performance reasons, we tuck this conditional logic inside less traveled areas (most tweens don't have an onUpdate). We'd just have it at the end before the onComplete, but the values should be updated before any onUpdate is called, so we ALSO put it here and then if it's not called, we do so later near the onComplete.
- }
- if (!suppressEvents) if (this._totalTime !== prevTotalTime || callback) {
- this._callback("onUpdate");
- }
- }
- if (this._cycle !== prevCycle) if (!suppressEvents) if (!this._gc) if (this.vars.onRepeat) {
- this._callback("onRepeat");
- }
- if (callback) if (!this._gc || force) { //check gc because there's a chance that kill() could be called in an onUpdate
- if (time < 0 && this._startAt && !this._onUpdate && this._startTime) { //if the tween is positioned at the VERY beginning (_startTime 0) of its parent timeline, it's illegal for the playhead to go back further, so we should not render the recorded startAt values.
- this._startAt.render(time, suppressEvents, force);
- }
- if (isComplete) {
- if (this._timeline.autoRemoveChildren) {
- this._enabled(false, false);
- }
- this._active = false;
- }
- if (!suppressEvents && this.vars[callback]) {
- this._callback(callback);
- }
- if (duration === 0 && this._rawPrevTime === _tinyNum && rawPrevTime !== _tinyNum) { //the onComplete or onReverseComplete could trigger movement of the playhead and for zero-duration tweens (which must discern direction) that land directly back on their start time, we don't want to fire again on the next render. Think of several addPause()'s in a timeline that forces the playhead to a certain spot, but what if it's already paused and another tween is tweening the "time" of the timeline? Each time it moves [forward] past that spot, it would move back, and since suppressEvents is true, it'd reset _rawPrevTime to _tinyNum so that when it begins again, the callback would fire (so ultimately it could bounce back and forth during that tween). Again, this is a very uncommon scenario, but possible nonetheless.
- this._rawPrevTime = 0;
- }
- }
- };
-
- //---- STATIC FUNCTIONS -----------------------------------------------------------------------------------------------------------
-
- TweenMax.to = function(target, duration, vars) {
- return new TweenMax(target, duration, vars);
- };
-
- TweenMax.from = function(target, duration, vars) {
- vars.runBackwards = true;
- vars.immediateRender = (vars.immediateRender != false);
- return new TweenMax(target, duration, vars);
- };
-
- TweenMax.fromTo = function(target, duration, fromVars, toVars) {
- toVars.startAt = fromVars;
- toVars.immediateRender = (toVars.immediateRender != false && fromVars.immediateRender != false);
- return new TweenMax(target, duration, toVars);
- };
-
- TweenMax.staggerTo = TweenMax.allTo = function(targets, duration, vars, stagger, onCompleteAll, onCompleteAllParams, onCompleteAllScope) {
- stagger = stagger || 0;
- var delay = 0,
- a = [],
- finalComplete = function() {
- if (vars.onComplete) {
- vars.onComplete.apply(vars.onCompleteScope || this, arguments);
- }
- onCompleteAll.apply(onCompleteAllScope || vars.callbackScope || this, onCompleteAllParams || _blankArray);
- },
- cycle = vars.cycle,
- fromCycle = (vars.startAt && vars.startAt.cycle),
- l, copy, i, p;
- if (!_isArray(targets)) {
- if (typeof(targets) === "string") {
- targets = TweenLite.selector(targets) || targets;
- }
- if (_isSelector(targets)) {
- targets = _slice(targets);
- }
- }
- targets = targets || [];
- if (stagger < 0) {
- targets = _slice(targets);
- targets.reverse();
- stagger *= -1;
- }
- l = targets.length - 1;
- for (i = 0; i <= l; i++) {
- copy = {};
- for (p in vars) {
- copy[p] = vars[p];
- }
- if (cycle) {
- _applyCycle(copy, targets, i);
- if (copy.duration != null) {
- duration = copy.duration;
- delete copy.duration;
- }
- }
- if (fromCycle) {
- fromCycle = copy.startAt = {};
- for (p in vars.startAt) {
- fromCycle[p] = vars.startAt[p];
- }
- _applyCycle(copy.startAt, targets, i);
- }
- copy.delay = delay + (copy.delay || 0);
- if (i === l && onCompleteAll) {
- copy.onComplete = finalComplete;
- }
- a[i] = new TweenMax(targets[i], duration, copy);
- delay += stagger;
- }
- return a;
- };
-
- TweenMax.staggerFrom = TweenMax.allFrom = function(targets, duration, vars, stagger, onCompleteAll, onCompleteAllParams, onCompleteAllScope) {
- vars.runBackwards = true;
- vars.immediateRender = (vars.immediateRender != false);
- return TweenMax.staggerTo(targets, duration, vars, stagger, onCompleteAll, onCompleteAllParams, onCompleteAllScope);
- };
-
- TweenMax.staggerFromTo = TweenMax.allFromTo = function(targets, duration, fromVars, toVars, stagger, onCompleteAll, onCompleteAllParams, onCompleteAllScope) {
- toVars.startAt = fromVars;
- toVars.immediateRender = (toVars.immediateRender != false && fromVars.immediateRender != false);
- return TweenMax.staggerTo(targets, duration, toVars, stagger, onCompleteAll, onCompleteAllParams, onCompleteAllScope);
- };
-
- TweenMax.delayedCall = function(delay, callback, params, scope, useFrames) {
- return new TweenMax(callback, 0, {delay:delay, onComplete:callback, onCompleteParams:params, callbackScope:scope, onReverseComplete:callback, onReverseCompleteParams:params, immediateRender:false, useFrames:useFrames, overwrite:0});
- };
-
- TweenMax.set = function(target, vars) {
- return new TweenMax(target, 0, vars);
- };
-
- TweenMax.isTweening = function(target) {
- return (TweenLite.getTweensOf(target, true).length > 0);
- };
-
- var _getChildrenOf = function(timeline, includeTimelines) {
- var a = [],
- cnt = 0,
- tween = timeline._first;
- while (tween) {
- if (tween instanceof TweenLite) {
- a[cnt++] = tween;
- } else {
- if (includeTimelines) {
- a[cnt++] = tween;
- }
- a = a.concat(_getChildrenOf(tween, includeTimelines));
- cnt = a.length;
- }
- tween = tween._next;
- }
- return a;
- },
- getAllTweens = TweenMax.getAllTweens = function(includeTimelines) {
- return _getChildrenOf(Animation._rootTimeline, includeTimelines).concat( _getChildrenOf(Animation._rootFramesTimeline, includeTimelines) );
- };
-
- TweenMax.killAll = function(complete, tweens, delayedCalls, timelines) {
- if (tweens == null) {
- tweens = true;
- }
- if (delayedCalls == null) {
- delayedCalls = true;
- }
- var a = getAllTweens((timelines != false)),
- l = a.length,
- allTrue = (tweens && delayedCalls && timelines),
- isDC, tween, i;
- for (i = 0; i < l; i++) {
- tween = a[i];
- if (allTrue || (tween instanceof SimpleTimeline) || ((isDC = (tween.target === tween.vars.onComplete)) && delayedCalls) || (tweens && !isDC)) {
- if (complete) {
- tween.totalTime(tween._reversed ? 0 : tween.totalDuration());
- } else {
- tween._enabled(false, false);
- }
- }
- }
- };
-
- TweenMax.killChildTweensOf = function(parent, complete) {
- if (parent == null) {
- return;
- }
- var tl = TweenLiteInternals.tweenLookup,
- a, curParent, p, i, l;
- if (typeof(parent) === "string") {
- parent = TweenLite.selector(parent) || parent;
- }
- if (_isSelector(parent)) {
- parent = _slice(parent);
- }
- if (_isArray(parent)) {
- i = parent.length;
- while (--i > -1) {
- TweenMax.killChildTweensOf(parent[i], complete);
- }
- return;
- }
- a = [];
- for (p in tl) {
- curParent = tl[p].target.parentNode;
- while (curParent) {
- if (curParent === parent) {
- a = a.concat(tl[p].tweens);
- }
- curParent = curParent.parentNode;
- }
- }
- l = a.length;
- for (i = 0; i < l; i++) {
- if (complete) {
- a[i].totalTime(a[i].totalDuration());
- }
- a[i]._enabled(false, false);
- }
- };
- var _changePause = function(pause, tweens, delayedCalls, timelines) {
- tweens = (tweens !== false);
- delayedCalls = (delayedCalls !== false);
- timelines = (timelines !== false);
- var a = getAllTweens(timelines),
- allTrue = (tweens && delayedCalls && timelines),
- i = a.length,
- isDC, tween;
- while (--i > -1) {
- tween = a[i];
- if (allTrue || (tween instanceof SimpleTimeline) || ((isDC = (tween.target === tween.vars.onComplete)) && delayedCalls) || (tweens && !isDC)) {
- tween.paused(pause);
- }
- }
- };
-
- TweenMax.pauseAll = function(tweens, delayedCalls, timelines) {
- _changePause(true, tweens, delayedCalls, timelines);
- };
-
- TweenMax.resumeAll = function(tweens, delayedCalls, timelines) {
- _changePause(false, tweens, delayedCalls, timelines);
- };
- TweenMax.globalTimeScale = function(value) {
- var tl = Animation._rootTimeline,
- t = TweenLite.ticker.time;
- if (!arguments.length) {
- return tl._timeScale;
- }
- value = value || _tinyNum; //can't allow zero because it'll throw the math off
- tl._startTime = t - ((t - tl._startTime) * tl._timeScale / value);
- tl = Animation._rootFramesTimeline;
- t = TweenLite.ticker.frame;
- tl._startTime = t - ((t - tl._startTime) * tl._timeScale / value);
- tl._timeScale = Animation._rootTimeline._timeScale = value;
- return value;
- };
-
-
- //---- GETTERS / SETTERS ----------------------------------------------------------------------------------------------------------
-
- p.progress = function(value, suppressEvents) {
- return (!arguments.length) ? this._time / this.duration() : this.totalTime( this.duration() * ((this._yoyo && (this._cycle & 1) !== 0) ? 1 - value : value) + (this._cycle * (this._duration + this._repeatDelay)), suppressEvents);
- };
-
- p.totalProgress = function(value, suppressEvents) {
- return (!arguments.length) ? this._totalTime / this.totalDuration() : this.totalTime( this.totalDuration() * value, suppressEvents);
- };
-
- p.time = function(value, suppressEvents) {
- if (!arguments.length) {
- return this._time;
- }
- if (this._dirty) {
- this.totalDuration();
- }
- if (value > this._duration) {
- value = this._duration;
- }
- if (this._yoyo && (this._cycle & 1) !== 0) {
- value = (this._duration - value) + (this._cycle * (this._duration + this._repeatDelay));
- } else if (this._repeat !== 0) {
- value += this._cycle * (this._duration + this._repeatDelay);
- }
- return this.totalTime(value, suppressEvents);
- };
- p.duration = function(value) {
- if (!arguments.length) {
- return this._duration; //don't set _dirty = false because there could be repeats that haven't been factored into the _totalDuration yet. Otherwise, if you create a repeated TweenMax and then immediately check its duration(), it would cache the value and the totalDuration would not be correct, thus repeats wouldn't take effect.
- }
- return Animation.prototype.duration.call(this, value);
- };
- p.totalDuration = function(value) {
- if (!arguments.length) {
- if (this._dirty) {
- //instead of Infinity, we use 999999999999 so that we can accommodate reverses
- this._totalDuration = (this._repeat === -1) ? 999999999999 : this._duration * (this._repeat + 1) + (this._repeatDelay * this._repeat);
- this._dirty = false;
- }
- return this._totalDuration;
- }
- return (this._repeat === -1) ? this : this.duration( (value - (this._repeat * this._repeatDelay)) / (this._repeat + 1) );
- };
-
- p.repeat = function(value) {
- if (!arguments.length) {
- return this._repeat;
- }
- this._repeat = value;
- return this._uncache(true);
- };
-
- p.repeatDelay = function(value) {
- if (!arguments.length) {
- return this._repeatDelay;
- }
- this._repeatDelay = value;
- return this._uncache(true);
- };
-
- p.yoyo = function(value) {
- if (!arguments.length) {
- return this._yoyo;
- }
- this._yoyo = value;
- return this;
- };
-
-
- return TweenMax;
-
- }, true);
- /*
- * ----------------------------------------------------------------
- * TimelineLite
- * ----------------------------------------------------------------
- */
- _gsScope._gsDefine("TimelineLite", ["core.Animation","core.SimpleTimeline","TweenLite"], function(Animation, SimpleTimeline, TweenLite) {
- var TimelineLite = function(vars) {
- SimpleTimeline.call(this, vars);
- this._labels = {};
- this.autoRemoveChildren = (this.vars.autoRemoveChildren === true);
- this.smoothChildTiming = (this.vars.smoothChildTiming === true);
- this._sortChildren = true;
- this._onUpdate = this.vars.onUpdate;
- var v = this.vars,
- val, p;
- for (p in v) {
- val = v[p];
- if (_isArray(val)) if (val.join("").indexOf("{self}") !== -1) {
- v[p] = this._swapSelfInParams(val);
- }
- }
- if (_isArray(v.tweens)) {
- this.add(v.tweens, 0, v.align, v.stagger);
- }
- },
- _tinyNum = 0.0000000001,
- TweenLiteInternals = TweenLite._internals,
- _internals = TimelineLite._internals = {},
- _isSelector = TweenLiteInternals.isSelector,
- _isArray = TweenLiteInternals.isArray,
- _lazyTweens = TweenLiteInternals.lazyTweens,
- _lazyRender = TweenLiteInternals.lazyRender,
- _globals = _gsScope._gsDefine.globals,
- _copy = function(vars) {
- var copy = {}, p;
- for (p in vars) {
- copy[p] = vars[p];
- }
- return copy;
- },
- _applyCycle = function(vars, targets, i) {
- var alt = vars.cycle,
- p, val;
- for (p in alt) {
- val = alt[p];
- vars[p] = (typeof(val) === "function") ? val(i, targets[i]) : val[i % val.length];
- }
- delete vars.cycle;
- },
- _pauseCallback = _internals.pauseCallback = function() {},
- _slice = function(a) { //don't use [].slice because that doesn't work in IE8 with a NodeList that's returned by querySelectorAll()
- var b = [],
- l = a.length,
- i;
- for (i = 0; i !== l; b.push(a[i++]));
- return b;
- },
- p = TimelineLite.prototype = new SimpleTimeline();
- TimelineLite.version = "1.20.2";
- p.constructor = TimelineLite;
- p.kill()._gc = p._forcingPlayhead = p._hasPause = false;
- /* might use later...
- //translates a local time inside an animation to the corresponding time on the root/global timeline, factoring in all nesting and timeScales.
- function localToGlobal(time, animation) {
- while (animation) {
- time = (time / animation._timeScale) + animation._startTime;
- animation = animation.timeline;
- }
- return time;
- }
- //translates the supplied time on the root/global timeline into the corresponding local time inside a particular animation, factoring in all nesting and timeScales
- function globalToLocal(time, animation) {
- var scale = 1;
- time -= localToGlobal(0, animation);
- while (animation) {
- scale *= animation._timeScale;
- animation = animation.timeline;
- }
- return time * scale;
- }
- */
- p.to = function(target, duration, vars, position) {
- var Engine = (vars.repeat && _globals.TweenMax) || TweenLite;
- return duration ? this.add( new Engine(target, duration, vars), position) : this.set(target, vars, position);
- };
- p.from = function(target, duration, vars, position) {
- return this.add( ((vars.repeat && _globals.TweenMax) || TweenLite).from(target, duration, vars), position);
- };
- p.fromTo = function(target, duration, fromVars, toVars, position) {
- var Engine = (toVars.repeat && _globals.TweenMax) || TweenLite;
- return duration ? this.add( Engine.fromTo(target, duration, fromVars, toVars), position) : this.set(target, toVars, position);
- };
- p.staggerTo = function(targets, duration, vars, stagger, position, onCompleteAll, onCompleteAllParams, onCompleteAllScope) {
- var tl = new TimelineLite({onComplete:onCompleteAll, onCompleteParams:onCompleteAllParams, callbackScope:onCompleteAllScope, smoothChildTiming:this.smoothChildTiming}),
- cycle = vars.cycle,
- copy, i;
- if (typeof(targets) === "string") {
- targets = TweenLite.selector(targets) || targets;
- }
- targets = targets || [];
- if (_isSelector(targets)) { //senses if the targets object is a selector. If it is, we should translate it into an array.
- targets = _slice(targets);
- }
- stagger = stagger || 0;
- if (stagger < 0) {
- targets = _slice(targets);
- targets.reverse();
- stagger *= -1;
- }
- for (i = 0; i < targets.length; i++) {
- copy = _copy(vars);
- if (copy.startAt) {
- copy.startAt = _copy(copy.startAt);
- if (copy.startAt.cycle) {
- _applyCycle(copy.startAt, targets, i);
- }
- }
- if (cycle) {
- _applyCycle(copy, targets, i);
- if (copy.duration != null) {
- duration = copy.duration;
- delete copy.duration;
- }
- }
- tl.to(targets[i], duration, copy, i * stagger);
- }
- return this.add(tl, position);
- };
- p.staggerFrom = function(targets, duration, vars, stagger, position, onCompleteAll, onCompleteAllParams, onCompleteAllScope) {
- vars.immediateRender = (vars.immediateRender != false);
- vars.runBackwards = true;
- return this.staggerTo(targets, duration, vars, stagger, position, onCompleteAll, onCompleteAllParams, onCompleteAllScope);
- };
- p.staggerFromTo = function(targets, duration, fromVars, toVars, stagger, position, onCompleteAll, onCompleteAllParams, onCompleteAllScope) {
- toVars.startAt = fromVars;
- toVars.immediateRender = (toVars.immediateRender != false && fromVars.immediateRender != false);
- return this.staggerTo(targets, duration, toVars, stagger, position, onCompleteAll, onCompleteAllParams, onCompleteAllScope);
- };
- p.call = function(callback, params, scope, position) {
- return this.add( TweenLite.delayedCall(0, callback, params, scope), position);
- };
- p.set = function(target, vars, position) {
- position = this._parseTimeOrLabel(position, 0, true);
- if (vars.immediateRender == null) {
- vars.immediateRender = (position === this._time && !this._paused);
- }
- return this.add( new TweenLite(target, 0, vars), position);
- };
- TimelineLite.exportRoot = function(vars, ignoreDelayedCalls) {
- vars = vars || {};
- if (vars.smoothChildTiming == null) {
- vars.smoothChildTiming = true;
- }
- var tl = new TimelineLite(vars),
- root = tl._timeline,
- tween, next;
- if (ignoreDelayedCalls == null) {
- ignoreDelayedCalls = true;
- }
- root._remove(tl, true);
- tl._startTime = 0;
- tl._rawPrevTime = tl._time = tl._totalTime = root._time;
- tween = root._first;
- while (tween) {
- next = tween._next;
- if (!ignoreDelayedCalls || !(tween instanceof TweenLite && tween.target === tween.vars.onComplete)) {
- tl.add(tween, tween._startTime - tween._delay);
- }
- tween = next;
- }
- root.add(tl, 0);
- return tl;
- };
- p.add = function(value, position, align, stagger) {
- var curTime, l, i, child, tl, beforeRawTime;
- if (typeof(position) !== "number") {
- position = this._parseTimeOrLabel(position, 0, true, value);
- }
- if (!(value instanceof Animation)) {
- if ((value instanceof Array) || (value && value.push && _isArray(value))) {
- align = align || "normal";
- stagger = stagger || 0;
- curTime = position;
- l = value.length;
- for (i = 0; i < l; i++) {
- if (_isArray(child = value[i])) {
- child = new TimelineLite({tweens:child});
- }
- this.add(child, curTime);
- if (typeof(child) !== "string" && typeof(child) !== "function") {
- if (align === "sequence") {
- curTime = child._startTime + (child.totalDuration() / child._timeScale);
- } else if (align === "start") {
- child._startTime -= child.delay();
- }
- }
- curTime += stagger;
- }
- return this._uncache(true);
- } else if (typeof(value) === "string") {
- return this.addLabel(value, position);
- } else if (typeof(value) === "function") {
- value = TweenLite.delayedCall(0, value);
- } else {
- throw("Cannot add " + value + " into the timeline; it is not a tween, timeline, function, or string.");
- }
- }
- SimpleTimeline.prototype.add.call(this, value, position);
- if (value._time) { //in case, for example, the _startTime is moved on a tween that has already rendered. Imagine it's at its end state, then the startTime is moved WAY later (after the end of this timeline), it should render at its beginning.
- value.render((this.rawTime() - value._startTime) * value._timeScale, false, false);
- }
- //if the timeline has already ended but the inserted tween/timeline extends the duration, we should enable this timeline again so that it renders properly. We should also align the playhead with the parent timeline's when appropriate.
- if (this._gc || this._time === this._duration) if (!this._paused) if (this._duration < this.duration()) {
- //in case any of the ancestors had completed but should now be enabled...
- tl = this;
- beforeRawTime = (tl.rawTime() > value._startTime); //if the tween is placed on the timeline so that it starts BEFORE the current rawTime, we should align the playhead (move the timeline). This is because sometimes users will create a timeline, let it finish, and much later append a tween and expect it to run instead of jumping to its end state. While technically one could argue that it should jump to its end state, that's not what users intuitively expect.
- while (tl._timeline) {
- if (beforeRawTime && tl._timeline.smoothChildTiming) {
- tl.totalTime(tl._totalTime, true); //moves the timeline (shifts its startTime) if necessary, and also enables it.
- } else if (tl._gc) {
- tl._enabled(true, false);
- }
- tl = tl._timeline;
- }
- }
- return this;
- };
- p.remove = function(value) {
- if (value instanceof Animation) {
- this._remove(value, false);
- var tl = value._timeline = value.vars.useFrames ? Animation._rootFramesTimeline : Animation._rootTimeline; //now that it's removed, default it to the root timeline so that if it gets played again, it doesn't jump back into this timeline.
- value._startTime = (value._paused ? value._pauseTime : tl._time) - ((!value._reversed ? value._totalTime : value.totalDuration() - value._totalTime) / value._timeScale); //ensure that if it gets played again, the timing is correct.
- return this;
- } else if (value instanceof Array || (value && value.push && _isArray(value))) {
- var i = value.length;
- while (--i > -1) {
- this.remove(value[i]);
- }
- return this;
- } else if (typeof(value) === "string") {
- return this.removeLabel(value);
- }
- return this.kill(null, value);
- };
- p._remove = function(tween, skipDisable) {
- SimpleTimeline.prototype._remove.call(this, tween, skipDisable);
- var last = this._last;
- if (!last) {
- this._time = this._totalTime = this._duration = this._totalDuration = 0;
- } else if (this._time > this.duration()) {
- this._time = this._duration;
- this._totalTime = this._totalDuration;
- }
- return this;
- };
- p.append = function(value, offsetOrLabel) {
- return this.add(value, this._parseTimeOrLabel(null, offsetOrLabel, true, value));
- };
- p.insert = p.insertMultiple = function(value, position, align, stagger) {
- return this.add(value, position || 0, align, stagger);
- };
- p.appendMultiple = function(tweens, offsetOrLabel, align, stagger) {
- return this.add(tweens, this._parseTimeOrLabel(null, offsetOrLabel, true, tweens), align, stagger);
- };
- p.addLabel = function(label, position) {
- this._labels[label] = this._parseTimeOrLabel(position);
- return this;
- };
- p.addPause = function(position, callback, params, scope) {
- var t = TweenLite.delayedCall(0, _pauseCallback, params, scope || this);
- t.vars.onComplete = t.vars.onReverseComplete = callback;
- t.data = "isPause";
- this._hasPause = true;
- return this.add(t, position);
- };
- p.removeLabel = function(label) {
- delete this._labels[label];
- return this;
- };
- p.getLabelTime = function(label) {
- return (this._labels[label] != null) ? this._labels[label] : -1;
- };
- p._parseTimeOrLabel = function(timeOrLabel, offsetOrLabel, appendIfAbsent, ignore) {
- var clippedDuration, i;
- //if we're about to add a tween/timeline (or an array of them) that's already a child of this timeline, we should remove it first so that it doesn't contaminate the duration().
- if (ignore instanceof Animation && ignore.timeline === this) {
- this.remove(ignore);
- } else if (ignore && ((ignore instanceof Array) || (ignore.push && _isArray(ignore)))) {
- i = ignore.length;
- while (--i > -1) {
- if (ignore[i] instanceof Animation && ignore[i].timeline === this) {
- this.remove(ignore[i]);
- }
- }
- }
- clippedDuration = (this.duration() > 99999999999) ? this.recent().endTime(false) : this._duration; //in case there's a child that infinitely repeats, users almost never intend for the insertion point of a new child to be based on a SUPER long value like that so we clip it and assume the most recently-added child's endTime should be used instead.
- if (typeof(offsetOrLabel) === "string") {
- return this._parseTimeOrLabel(offsetOrLabel, (appendIfAbsent && typeof(timeOrLabel) === "number" && this._labels[offsetOrLabel] == null) ? timeOrLabel - clippedDuration : 0, appendIfAbsent);
- }
- offsetOrLabel = offsetOrLabel || 0;
- if (typeof(timeOrLabel) === "string" && (isNaN(timeOrLabel) || this._labels[timeOrLabel] != null)) { //if the string is a number like "1", check to see if there's a label with that name, otherwise interpret it as a number (absolute value).
- i = timeOrLabel.indexOf("=");
- if (i === -1) {
- if (this._labels[timeOrLabel] == null) {
- return appendIfAbsent ? (this._labels[timeOrLabel] = clippedDuration + offsetOrLabel) : offsetOrLabel;
- }
- return this._labels[timeOrLabel] + offsetOrLabel;
- }
- offsetOrLabel = parseInt(timeOrLabel.charAt(i-1) + "1", 10) * Number(timeOrLabel.substr(i+1));
- timeOrLabel = (i > 1) ? this._parseTimeOrLabel(timeOrLabel.substr(0, i-1), 0, appendIfAbsent) : clippedDuration;
- } else if (timeOrLabel == null) {
- timeOrLabel = clippedDuration;
- }
- return Number(timeOrLabel) + offsetOrLabel;
- };
- p.seek = function(position, suppressEvents) {
- return this.totalTime((typeof(position) === "number") ? position : this._parseTimeOrLabel(position), (suppressEvents !== false));
- };
- p.stop = function() {
- return this.paused(true);
- };
- p.gotoAndPlay = function(position, suppressEvents) {
- return this.play(position, suppressEvents);
- };
- p.gotoAndStop = function(position, suppressEvents) {
- return this.pause(position, suppressEvents);
- };
- p.render = function(time, suppressEvents, force) {
- if (this._gc) {
- this._enabled(true, false);
- }
- var totalDur = (!this._dirty) ? this._totalDuration : this.totalDuration(),
- prevTime = this._time,
- prevStart = this._startTime,
- prevTimeScale = this._timeScale,
- prevPaused = this._paused,
- tween, isComplete, next, callback, internalForce, pauseTween, curTime;
- if (time >= totalDur - 0.0000001 && time >= 0) { //to work around occasional floating point math artifacts.
- this._totalTime = this._time = totalDur;
- if (!this._reversed) if (!this._hasPausedChild()) {
- isComplete = true;
- callback = "onComplete";
- internalForce = !!this._timeline.autoRemoveChildren; //otherwise, if the animation is unpaused/activated after it's already finished, it doesn't get removed from the parent timeline.
- if (this._duration === 0) if ((time <= 0 && time >= -0.0000001) || this._rawPrevTime < 0 || this._rawPrevTime === _tinyNum) if (this._rawPrevTime !== time && this._first) {
- internalForce = true;
- if (this._rawPrevTime > _tinyNum) {
- callback = "onReverseComplete";
- }
- }
- }
- this._rawPrevTime = (this._duration || !suppressEvents || time || this._rawPrevTime === time) ? time : _tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration timeline or tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient.
- time = totalDur + 0.0001; //to avoid occasional floating point rounding errors - sometimes child tweens/timelines were not being fully completed (their progress might be 0.999999999999998 instead of 1 because when _time - tween._startTime is performed, floating point errors would return a value that was SLIGHTLY off). Try (999999999999.7 - 999999999999) * 1 = 0.699951171875 instead of 0.7.
- } else if (time < 0.0000001) { //to work around occasional floating point math artifacts, round super small values to 0.
- this._totalTime = this._time = 0;
- if (prevTime !== 0 || (this._duration === 0 && this._rawPrevTime !== _tinyNum && (this._rawPrevTime > 0 || (time < 0 && this._rawPrevTime >= 0)))) {
- callback = "onReverseComplete";
- isComplete = this._reversed;
- }
- if (time < 0) {
- this._active = false;
- if (this._timeline.autoRemoveChildren && this._reversed) { //ensures proper GC if a timeline is resumed after it's finished reversing.
- internalForce = isComplete = true;
- callback = "onReverseComplete";
- } else if (this._rawPrevTime >= 0 && this._first) { //when going back beyond the start, force a render so that zero-duration tweens that sit at the very beginning render their start values properly. Otherwise, if the parent timeline's playhead lands exactly at this timeline's startTime, and then moves backwards, the zero-duration tweens at the beginning would still be at their end state.
- internalForce = true;
- }
- this._rawPrevTime = time;
- } else {
- this._rawPrevTime = (this._duration || !suppressEvents || time || this._rawPrevTime === time) ? time : _tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration timeline or tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient.
- if (time === 0 && isComplete) { //if there's a zero-duration tween at the very beginning of a timeline and the playhead lands EXACTLY at time 0, that tween will correctly render its end values, but we need to keep the timeline alive for one more render so that the beginning values render properly as the parent's playhead keeps moving beyond the begining. Imagine obj.x starts at 0 and then we do tl.set(obj, {x:100}).to(obj, 1, {x:200}) and then later we tl.reverse()...the goal is to have obj.x revert to 0. If the playhead happens to land on exactly 0, without this chunk of code, it'd complete the timeline and remove it from the rendering queue (not good).
- tween = this._first;
- while (tween && tween._startTime === 0) {
- if (!tween._duration) {
- isComplete = false;
- }
- tween = tween._next;
- }
- }
- time = 0; //to avoid occasional floating point rounding errors (could cause problems especially with zero-duration tweens at the very beginning of the timeline)
- if (!this._initted) {
- internalForce = true;
- }
- }
- } else {
- if (this._hasPause && !this._forcingPlayhead && !suppressEvents) {
- if (time >= prevTime) {
- tween = this._first;
- while (tween && tween._startTime <= time && !pauseTween) {
- if (!tween._duration) if (tween.data === "isPause" && !tween.ratio && !(tween._startTime === 0 && this._rawPrevTime === 0)) {
- pauseTween = tween;
- }
- tween = tween._next;
- }
- } else {
- tween = this._last;
- while (tween && tween._startTime >= time && !pauseTween) {
- if (!tween._duration) if (tween.data === "isPause" && tween._rawPrevTime > 0) {
- pauseTween = tween;
- }
- tween = tween._prev;
- }
- }
- if (pauseTween) {
- this._time = time = pauseTween._startTime;
- this._totalTime = time + (this._cycle * (this._totalDuration + this._repeatDelay));
- }
- }
- this._totalTime = this._time = this._rawPrevTime = time;
- }
- if ((this._time === prevTime || !this._first) && !force && !internalForce && !pauseTween) {
- return;
- } else if (!this._initted) {
- this._initted = true;
- }
- if (!this._active) if (!this._paused && this._time !== prevTime && time > 0) {
- this._active = true; //so that if the user renders the timeline (as opposed to the parent timeline rendering it), it is forced to re-render and align it with the proper time/frame on the next rendering cycle. Maybe the timeline already finished but the user manually re-renders it as halfway done, for example.
- }
- if (prevTime === 0) if (this.vars.onStart) if (this._time !== 0 || !this._duration) if (!suppressEvents) {
- this._callback("onStart");
- }
- curTime = this._time;
- if (curTime >= prevTime) {
- tween = this._first;
- while (tween) {
- next = tween._next; //record it here because the value could change after rendering...
- if (curTime !== this._time || (this._paused && !prevPaused)) { //in case a tween pauses or seeks the timeline when rendering, like inside of an onUpdate/onComplete
- break;
- } else if (tween._active || (tween._startTime <= curTime && !tween._paused && !tween._gc)) {
- if (pauseTween === tween) {
- this.pause();
- }
- if (!tween._reversed) {
- tween.render((time - tween._startTime) * tween._timeScale, suppressEvents, force);
- } else {
- tween.render(((!tween._dirty) ? tween._totalDuration : tween.totalDuration()) - ((time - tween._startTime) * tween._timeScale), suppressEvents, force);
- }
- }
- tween = next;
- }
- } else {
- tween = this._last;
- while (tween) {
- next = tween._prev; //record it here because the value could change after rendering...
- if (curTime !== this._time || (this._paused && !prevPaused)) { //in case a tween pauses or seeks the timeline when rendering, like inside of an onUpdate/onComplete
- break;
- } else if (tween._active || (tween._startTime <= prevTime && !tween._paused && !tween._gc)) {
- if (pauseTween === tween) {
- pauseTween = tween._prev; //the linked list is organized by _startTime, thus it's possible that a tween could start BEFORE the pause and end after it, in which case it would be positioned before the pause tween in the linked list, but we should render it before we pause() the timeline and cease rendering. This is only a concern when going in reverse.
- while (pauseTween && pauseTween.endTime() > this._time) {
- pauseTween.render( (pauseTween._reversed ? pauseTween.totalDuration() - ((time - pauseTween._startTime) * pauseTween._timeScale) : (time - pauseTween._startTime) * pauseTween._timeScale), suppressEvents, force);
- pauseTween = pauseTween._prev;
- }
- pauseTween = null;
- this.pause();
- }
- if (!tween._reversed) {
- tween.render((time - tween._startTime) * tween._timeScale, suppressEvents, force);
- } else {
- tween.render(((!tween._dirty) ? tween._totalDuration : tween.totalDuration()) - ((time - tween._startTime) * tween._timeScale), suppressEvents, force);
- }
- }
- tween = next;
- }
- }
- if (this._onUpdate) if (!suppressEvents) {
- if (_lazyTweens.length) { //in case rendering caused any tweens to lazy-init, we should render them because typically when a timeline finishes, users expect things to have rendered fully. Imagine an onUpdate on a timeline that reports/checks tweened values.
- _lazyRender();
- }
- this._callback("onUpdate");
- }
- if (callback) if (!this._gc) if (prevStart === this._startTime || prevTimeScale !== this._timeScale) if (this._time === 0 || totalDur >= this.totalDuration()) { //if one of the tweens that was rendered altered this timeline's startTime (like if an onComplete reversed the timeline), it probably isn't complete. If it is, don't worry, because whatever call altered the startTime would complete if it was necessary at the new time. The only exception is the timeScale property. Also check _gc because there's a chance that kill() could be called in an onUpdate
- if (isComplete) {
- if (_lazyTweens.length) { //in case rendering caused any tweens to lazy-init, we should render them because typically when a timeline finishes, users expect things to have rendered fully. Imagine an onComplete on a timeline that reports/checks tweened values.
- _lazyRender();
- }
- if (this._timeline.autoRemoveChildren) {
- this._enabled(false, false);
- }
- this._active = false;
- }
- if (!suppressEvents && this.vars[callback]) {
- this._callback(callback);
- }
- }
- };
- p._hasPausedChild = function() {
- var tween = this._first;
- while (tween) {
- if (tween._paused || ((tween instanceof TimelineLite) && tween._hasPausedChild())) {
- return true;
- }
- tween = tween._next;
- }
- return false;
- };
- p.getChildren = function(nested, tweens, timelines, ignoreBeforeTime) {
- ignoreBeforeTime = ignoreBeforeTime || -9999999999;
- var a = [],
- tween = this._first,
- cnt = 0;
- while (tween) {
- if (tween._startTime < ignoreBeforeTime) {
- //do nothing
- } else if (tween instanceof TweenLite) {
- if (tweens !== false) {
- a[cnt++] = tween;
- }
- } else {
- if (timelines !== false) {
- a[cnt++] = tween;
- }
- if (nested !== false) {
- a = a.concat(tween.getChildren(true, tweens, timelines));
- cnt = a.length;
- }
- }
- tween = tween._next;
- }
- return a;
- };
- p.getTweensOf = function(target, nested) {
- var disabled = this._gc,
- a = [],
- cnt = 0,
- tweens, i;
- if (disabled) {
- this._enabled(true, true); //getTweensOf() filters out disabled tweens, and we have to mark them as _gc = true when the timeline completes in order to allow clean garbage collection, so temporarily re-enable the timeline here.
- }
- tweens = TweenLite.getTweensOf(target);
- i = tweens.length;
- while (--i > -1) {
- if (tweens[i].timeline === this || (nested && this._contains(tweens[i]))) {
- a[cnt++] = tweens[i];
- }
- }
- if (disabled) {
- this._enabled(false, true);
- }
- return a;
- };
- p.recent = function() {
- return this._recent;
- };
- p._contains = function(tween) {
- var tl = tween.timeline;
- while (tl) {
- if (tl === this) {
- return true;
- }
- tl = tl.timeline;
- }
- return false;
- };
- p.shiftChildren = function(amount, adjustLabels, ignoreBeforeTime) {
- ignoreBeforeTime = ignoreBeforeTime || 0;
- var tween = this._first,
- labels = this._labels,
- p;
- while (tween) {
- if (tween._startTime >= ignoreBeforeTime) {
- tween._startTime += amount;
- }
- tween = tween._next;
- }
- if (adjustLabels) {
- for (p in labels) {
- if (labels[p] >= ignoreBeforeTime) {
- labels[p] += amount;
- }
- }
- }
- return this._uncache(true);
- };
- p._kill = function(vars, target) {
- if (!vars && !target) {
- return this._enabled(false, false);
- }
- var tweens = (!target) ? this.getChildren(true, true, false) : this.getTweensOf(target),
- i = tweens.length,
- changed = false;
- while (--i > -1) {
- if (tweens[i]._kill(vars, target)) {
- changed = true;
- }
- }
- return changed;
- };
- p.clear = function(labels) {
- var tweens = this.getChildren(false, true, true),
- i = tweens.length;
- this._time = this._totalTime = 0;
- while (--i > -1) {
- tweens[i]._enabled(false, false);
- }
- if (labels !== false) {
- this._labels = {};
- }
- return this._uncache(true);
- };
- p.invalidate = function() {
- var tween = this._first;
- while (tween) {
- tween.invalidate();
- tween = tween._next;
- }
- return Animation.prototype.invalidate.call(this);;
- };
- p._enabled = function(enabled, ignoreTimeline) {
- if (enabled === this._gc) {
- var tween = this._first;
- while (tween) {
- tween._enabled(enabled, true);
- tween = tween._next;
- }
- }
- return SimpleTimeline.prototype._enabled.call(this, enabled, ignoreTimeline);
- };
- p.totalTime = function(time, suppressEvents, uncapped) {
- this._forcingPlayhead = true;
- var val = Animation.prototype.totalTime.apply(this, arguments);
- this._forcingPlayhead = false;
- return val;
- };
- p.duration = function(value) {
- if (!arguments.length) {
- if (this._dirty) {
- this.totalDuration(); //just triggers recalculation
- }
- return this._duration;
- }
- if (this.duration() !== 0 && value !== 0) {
- this.timeScale(this._duration / value);
- }
- return this;
- };
- p.totalDuration = function(value) {
- if (!arguments.length) {
- if (this._dirty) {
- var max = 0,
- tween = this._last,
- prevStart = 999999999999,
- prev, end;
- while (tween) {
- prev = tween._prev; //record it here in case the tween changes position in the sequence...
- if (tween._dirty) {
- tween.totalDuration(); //could change the tween._startTime, so make sure the tween's cache is clean before analyzing it.
- }
- if (tween._startTime > prevStart && this._sortChildren && !tween._paused) { //in case one of the tweens shifted out of order, it needs to be re-inserted into the correct position in the sequence
- this.add(tween, tween._startTime - tween._delay);
- } else {
- prevStart = tween._startTime;
- }
- if (tween._startTime < 0 && !tween._paused) { //children aren't allowed to have negative startTimes unless smoothChildTiming is true, so adjust here if one is found.
- max -= tween._startTime;
- if (this._timeline.smoothChildTiming) {
- this._startTime += tween._startTime / this._timeScale;
- }
- this.shiftChildren(-tween._startTime, false, -9999999999);
- prevStart = 0;
- }
- end = tween._startTime + (tween._totalDuration / tween._timeScale);
- if (end > max) {
- max = end;
- }
- tween = prev;
- }
- this._duration = this._totalDuration = max;
- this._dirty = false;
- }
- return this._totalDuration;
- }
- return (value && this.totalDuration()) ? this.timeScale(this._totalDuration / value) : this;
- };
- p.paused = function(value) {
- if (!value) { //if there's a pause directly at the spot from where we're unpausing, skip it.
- var tween = this._first,
- time = this._time;
- while (tween) {
- if (tween._startTime === time && tween.data === "isPause") {
- tween._rawPrevTime = 0; //remember, _rawPrevTime is how zero-duration tweens/callbacks sense directionality and determine whether or not to fire. If _rawPrevTime is the same as _startTime on the next render, it won't fire.
- }
- tween = tween._next;
- }
- }
- return Animation.prototype.paused.apply(this, arguments);
- };
- p.usesFrames = function() {
- var tl = this._timeline;
- while (tl._timeline) {
- tl = tl._timeline;
- }
- return (tl === Animation._rootFramesTimeline);
- };
- p.rawTime = function(wrapRepeats) {
- return (wrapRepeats && (this._paused || (this._repeat && this.time() > 0 && this.totalProgress() < 1))) ? this._totalTime % (this._duration + this._repeatDelay) : this._paused ? this._totalTime : (this._timeline.rawTime(wrapRepeats) - this._startTime) * this._timeScale;
- };
- return TimelineLite;
- }, true);
-
-
-
-
-
- /*
- * ----------------------------------------------------------------
- * TimelineMax
- * ----------------------------------------------------------------
- */
- _gsScope._gsDefine("TimelineMax", ["TimelineLite","TweenLite","easing.Ease"], function(TimelineLite, TweenLite, Ease) {
- var TimelineMax = function(vars) {
- TimelineLite.call(this, vars);
- this._repeat = this.vars.repeat || 0;
- this._repeatDelay = this.vars.repeatDelay || 0;
- this._cycle = 0;
- this._yoyo = (this.vars.yoyo === true);
- this._dirty = true;
- },
- _tinyNum = 0.0000000001,
- TweenLiteInternals = TweenLite._internals,
- _lazyTweens = TweenLiteInternals.lazyTweens,
- _lazyRender = TweenLiteInternals.lazyRender,
- _globals = _gsScope._gsDefine.globals,
- _easeNone = new Ease(null, null, 1, 0),
- p = TimelineMax.prototype = new TimelineLite();
- p.constructor = TimelineMax;
- p.kill()._gc = false;
- TimelineMax.version = "1.20.2";
- p.invalidate = function() {
- this._yoyo = (this.vars.yoyo === true);
- this._repeat = this.vars.repeat || 0;
- this._repeatDelay = this.vars.repeatDelay || 0;
- this._uncache(true);
- return TimelineLite.prototype.invalidate.call(this);
- };
- p.addCallback = function(callback, position, params, scope) {
- return this.add( TweenLite.delayedCall(0, callback, params, scope), position);
- };
- p.removeCallback = function(callback, position) {
- if (callback) {
- if (position == null) {
- this._kill(null, callback);
- } else {
- var a = this.getTweensOf(callback, false),
- i = a.length,
- time = this._parseTimeOrLabel(position);
- while (--i > -1) {
- if (a[i]._startTime === time) {
- a[i]._enabled(false, false);
- }
- }
- }
- }
- return this;
- };
- p.removePause = function(position) {
- return this.removeCallback(TimelineLite._internals.pauseCallback, position);
- };
- p.tweenTo = function(position, vars) {
- vars = vars || {};
- var copy = {ease:_easeNone, useFrames:this.usesFrames(), immediateRender:false},
- Engine = (vars.repeat && _globals.TweenMax) || TweenLite,
- duration, p, t;
- for (p in vars) {
- copy[p] = vars[p];
- }
- copy.time = this._parseTimeOrLabel(position);
- duration = (Math.abs(Number(copy.time) - this._time) / this._timeScale) || 0.001;
- t = new Engine(this, duration, copy);
- copy.onStart = function() {
- t.target.paused(true);
- if (t.vars.time !== t.target.time() && duration === t.duration()) { //don't make the duration zero - if it's supposed to be zero, don't worry because it's already initting the tween and will complete immediately, effectively making the duration zero anyway. If we make duration zero, the tween won't run at all.
- t.duration( Math.abs( t.vars.time - t.target.time()) / t.target._timeScale );
- }
- if (vars.onStart) { //in case the user had an onStart in the vars - we don't want to overwrite it.
- vars.onStart.apply(vars.onStartScope || vars.callbackScope || t, vars.onStartParams || []); //don't use t._callback("onStart") or it'll point to the copy.onStart and we'll get a recursion error.
- }
- };
- return t;
- };
- p.tweenFromTo = function(fromPosition, toPosition, vars) {
- vars = vars || {};
- fromPosition = this._parseTimeOrLabel(fromPosition);
- vars.startAt = {onComplete:this.seek, onCompleteParams:[fromPosition], callbackScope:this};
- vars.immediateRender = (vars.immediateRender !== false);
- var t = this.tweenTo(toPosition, vars);
- return t.duration((Math.abs( t.vars.time - fromPosition) / this._timeScale) || 0.001);
- };
- p.render = function(time, suppressEvents, force) {
- if (this._gc) {
- this._enabled(true, false);
- }
- var totalDur = (!this._dirty) ? this._totalDuration : this.totalDuration(),
- dur = this._duration,
- prevTime = this._time,
- prevTotalTime = this._totalTime,
- prevStart = this._startTime,
- prevTimeScale = this._timeScale,
- prevRawPrevTime = this._rawPrevTime,
- prevPaused = this._paused,
- prevCycle = this._cycle,
- tween, isComplete, next, callback, internalForce, cycleDuration, pauseTween, curTime;
- if (time >= totalDur - 0.0000001 && time >= 0) { //to work around occasional floating point math artifacts.
- if (!this._locked) {
- this._totalTime = totalDur;
- this._cycle = this._repeat;
- }
- if (!this._reversed) if (!this._hasPausedChild()) {
- isComplete = true;
- callback = "onComplete";
- internalForce = !!this._timeline.autoRemoveChildren; //otherwise, if the animation is unpaused/activated after it's already finished, it doesn't get removed from the parent timeline.
- if (this._duration === 0) if ((time <= 0 && time >= -0.0000001) || prevRawPrevTime < 0 || prevRawPrevTime === _tinyNum) if (prevRawPrevTime !== time && this._first) {
- internalForce = true;
- if (prevRawPrevTime > _tinyNum) {
- callback = "onReverseComplete";
- }
- }
- }
- this._rawPrevTime = (this._duration || !suppressEvents || time || this._rawPrevTime === time) ? time : _tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration timeline or tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient.
- if (this._yoyo && (this._cycle & 1) !== 0) {
- this._time = time = 0;
- } else {
- this._time = dur;
- time = dur + 0.0001; //to avoid occasional floating point rounding errors - sometimes child tweens/timelines were not being fully completed (their progress might be 0.999999999999998 instead of 1 because when _time - tween._startTime is performed, floating point errors would return a value that was SLIGHTLY off). Try (999999999999.7 - 999999999999) * 1 = 0.699951171875 instead of 0.7. We cannot do less then 0.0001 because the same issue can occur when the duration is extremely large like 999999999999 in which case adding 0.00000001, for example, causes it to act like nothing was added.
- }
- } else if (time < 0.0000001) { //to work around occasional floating point math artifacts, round super small values to 0.
- if (!this._locked) {
- this._totalTime = this._cycle = 0;
- }
- this._time = 0;
- if (prevTime !== 0 || (dur === 0 && prevRawPrevTime !== _tinyNum && (prevRawPrevTime > 0 || (time < 0 && prevRawPrevTime >= 0)) && !this._locked)) { //edge case for checking time < 0 && prevRawPrevTime >= 0: a zero-duration fromTo() tween inside a zero-duration timeline (yeah, very rare)
- callback = "onReverseComplete";
- isComplete = this._reversed;
- }
- if (time < 0) {
- this._active = false;
- if (this._timeline.autoRemoveChildren && this._reversed) {
- internalForce = isComplete = true;
- callback = "onReverseComplete";
- } else if (prevRawPrevTime >= 0 && this._first) { //when going back beyond the start, force a render so that zero-duration tweens that sit at the very beginning render their start values properly. Otherwise, if the parent timeline's playhead lands exactly at this timeline's startTime, and then moves backwards, the zero-duration tweens at the beginning would still be at their end state.
- internalForce = true;
- }
- this._rawPrevTime = time;
- } else {
- this._rawPrevTime = (dur || !suppressEvents || time || this._rawPrevTime === time) ? time : _tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration timeline or tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient.
- if (time === 0 && isComplete) { //if there's a zero-duration tween at the very beginning of a timeline and the playhead lands EXACTLY at time 0, that tween will correctly render its end values, but we need to keep the timeline alive for one more render so that the beginning values render properly as the parent's playhead keeps moving beyond the begining. Imagine obj.x starts at 0 and then we do tl.set(obj, {x:100}).to(obj, 1, {x:200}) and then later we tl.reverse()...the goal is to have obj.x revert to 0. If the playhead happens to land on exactly 0, without this chunk of code, it'd complete the timeline and remove it from the rendering queue (not good).
- tween = this._first;
- while (tween && tween._startTime === 0) {
- if (!tween._duration) {
- isComplete = false;
- }
- tween = tween._next;
- }
- }
- time = 0; //to avoid occasional floating point rounding errors (could cause problems especially with zero-duration tweens at the very beginning of the timeline)
- if (!this._initted) {
- internalForce = true;
- }
- }
- } else {
- if (dur === 0 && prevRawPrevTime < 0) { //without this, zero-duration repeating timelines (like with a simple callback nested at the very beginning and a repeatDelay) wouldn't render the first time through.
- internalForce = true;
- }
- this._time = this._rawPrevTime = time;
- if (!this._locked) {
- this._totalTime = time;
- if (this._repeat !== 0) {
- cycleDuration = dur + this._repeatDelay;
- this._cycle = (this._totalTime / cycleDuration) >> 0; //originally _totalTime % cycleDuration but floating point errors caused problems, so I normalized it. (4 % 0.8 should be 0 but it gets reported as 0.79999999!)
- if (this._cycle !== 0) if (this._cycle === this._totalTime / cycleDuration && prevTotalTime <= time) {
- this._cycle--; //otherwise when rendered exactly at the end time, it will act as though it is repeating (at the beginning)
- }
- this._time = this._totalTime - (this._cycle * cycleDuration);
- if (this._yoyo) if ((this._cycle & 1) !== 0) {
- this._time = dur - this._time;
- }
- if (this._time > dur) {
- this._time = dur;
- time = dur + 0.0001; //to avoid occasional floating point rounding error
- } else if (this._time < 0) {
- this._time = time = 0;
- } else {
- time = this._time;
- }
- }
- }
- if (this._hasPause && !this._forcingPlayhead && !suppressEvents) {
- time = this._time;
- if (time >= prevTime || (this._repeat && prevCycle !== this._cycle)) {
- tween = this._first;
- while (tween && tween._startTime <= time && !pauseTween) {
- if (!tween._duration) if (tween.data === "isPause" && !tween.ratio && !(tween._startTime === 0 && this._rawPrevTime === 0)) {
- pauseTween = tween;
- }
- tween = tween._next;
- }
- } else {
- tween = this._last;
- while (tween && tween._startTime >= time && !pauseTween) {
- if (!tween._duration) if (tween.data === "isPause" && tween._rawPrevTime > 0) {
- pauseTween = tween;
- }
- tween = tween._prev;
- }
- }
- if (pauseTween && pauseTween._startTime < dur) {
- this._time = time = pauseTween._startTime;
- this._totalTime = time + (this._cycle * (this._totalDuration + this._repeatDelay));
- }
- }
- }
- if (this._cycle !== prevCycle) if (!this._locked) {
- /*
- make sure children at the end/beginning of the timeline are rendered properly. If, for example,
- a 3-second long timeline rendered at 2.9 seconds previously, and now renders at 3.2 seconds (which
- would get transated to 2.8 seconds if the timeline yoyos or 0.2 seconds if it just repeats), there
- could be a callback or a short tween that's at 2.95 or 3 seconds in which wouldn't render. So
- we need to push the timeline to the end (and/or beginning depending on its yoyo value). Also we must
- ensure that zero-duration tweens at the very beginning or end of the TimelineMax work.
- */
- var backwards = (this._yoyo && (prevCycle & 1) !== 0),
- wrap = (backwards === (this._yoyo && (this._cycle & 1) !== 0)),
- recTotalTime = this._totalTime,
- recCycle = this._cycle,
- recRawPrevTime = this._rawPrevTime,
- recTime = this._time;
- this._totalTime = prevCycle * dur;
- if (this._cycle < prevCycle) {
- backwards = !backwards;
- } else {
- this._totalTime += dur;
- }
- this._time = prevTime; //temporarily revert _time so that render() renders the children in the correct order. Without this, tweens won't rewind correctly. We could arhictect things in a "cleaner" way by splitting out the rendering queue into a separate method but for performance reasons, we kept it all inside this method.
- this._rawPrevTime = (dur === 0) ? prevRawPrevTime - 0.0001 : prevRawPrevTime;
- this._cycle = prevCycle;
- this._locked = true; //prevents changes to totalTime and skips repeat/yoyo behavior when we recursively call render()
- prevTime = (backwards) ? 0 : dur;
- this.render(prevTime, suppressEvents, (dur === 0));
- if (!suppressEvents) if (!this._gc) {
- if (this.vars.onRepeat) {
- this._cycle = recCycle; //in case the onRepeat alters the playhead or invalidates(), we shouldn't stay locked or use the previous cycle.
- this._locked = false;
- this._callback("onRepeat");
- }
- }
- if (prevTime !== this._time) { //in case there's a callback like onComplete in a nested tween/timeline that changes the playhead position, like via seek(), we should just abort.
- return;
- }
- if (wrap) {
- this._cycle = prevCycle; //if there's an onRepeat, we reverted this above, so make sure it's set properly again. We also unlocked in that scenario, so reset that too.
- this._locked = true;
- prevTime = (backwards) ? dur + 0.0001 : -0.0001;
- this.render(prevTime, true, false);
- }
- this._locked = false;
- if (this._paused && !prevPaused) { //if the render() triggered callback that paused this timeline, we should abort (very rare, but possible)
- return;
- }
- this._time = recTime;
- this._totalTime = recTotalTime;
- this._cycle = recCycle;
- this._rawPrevTime = recRawPrevTime;
- }
- if ((this._time === prevTime || !this._first) && !force && !internalForce && !pauseTween) {
- if (prevTotalTime !== this._totalTime) if (this._onUpdate) if (!suppressEvents) { //so that onUpdate fires even during the repeatDelay - as long as the totalTime changed, we should trigger onUpdate.
- this._callback("onUpdate");
- }
- return;
- } else if (!this._initted) {
- this._initted = true;
- }
- if (!this._active) if (!this._paused && this._totalTime !== prevTotalTime && time > 0) {
- this._active = true; //so that if the user renders the timeline (as opposed to the parent timeline rendering it), it is forced to re-render and align it with the proper time/frame on the next rendering cycle. Maybe the timeline already finished but the user manually re-renders it as halfway done, for example.
- }
- if (prevTotalTime === 0) if (this.vars.onStart) if (this._totalTime !== 0 || !this._totalDuration) if (!suppressEvents) {
- this._callback("onStart");
- }
- curTime = this._time;
- if (curTime >= prevTime) {
- tween = this._first;
- while (tween) {
- next = tween._next; //record it here because the value could change after rendering...
- if (curTime !== this._time || (this._paused && !prevPaused)) { //in case a tween pauses or seeks the timeline when rendering, like inside of an onUpdate/onComplete
- break;
- } else if (tween._active || (tween._startTime <= this._time && !tween._paused && !tween._gc)) {
- if (pauseTween === tween) {
- this.pause();
- }
- if (!tween._reversed) {
- tween.render((time - tween._startTime) * tween._timeScale, suppressEvents, force);
- } else {
- tween.render(((!tween._dirty) ? tween._totalDuration : tween.totalDuration()) - ((time - tween._startTime) * tween._timeScale), suppressEvents, force);
- }
- }
- tween = next;
- }
- } else {
- tween = this._last;
- while (tween) {
- next = tween._prev; //record it here because the value could change after rendering...
- if (curTime !== this._time || (this._paused && !prevPaused)) { //in case a tween pauses or seeks the timeline when rendering, like inside of an onUpdate/onComplete
- break;
- } else if (tween._active || (tween._startTime <= prevTime && !tween._paused && !tween._gc)) {
- if (pauseTween === tween) {
- pauseTween = tween._prev; //the linked list is organized by _startTime, thus it's possible that a tween could start BEFORE the pause and end after it, in which case it would be positioned before the pause tween in the linked list, but we should render it before we pause() the timeline and cease rendering. This is only a concern when going in reverse.
- while (pauseTween && pauseTween.endTime() > this._time) {
- pauseTween.render( (pauseTween._reversed ? pauseTween.totalDuration() - ((time - pauseTween._startTime) * pauseTween._timeScale) : (time - pauseTween._startTime) * pauseTween._timeScale), suppressEvents, force);
- pauseTween = pauseTween._prev;
- }
- pauseTween = null;
- this.pause();
- }
- if (!tween._reversed) {
- tween.render((time - tween._startTime) * tween._timeScale, suppressEvents, force);
- } else {
- tween.render(((!tween._dirty) ? tween._totalDuration : tween.totalDuration()) - ((time - tween._startTime) * tween._timeScale), suppressEvents, force);
- }
- }
- tween = next;
- }
- }
- if (this._onUpdate) if (!suppressEvents) {
- if (_lazyTweens.length) { //in case rendering caused any tweens to lazy-init, we should render them because typically when a timeline finishes, users expect things to have rendered fully. Imagine an onUpdate on a timeline that reports/checks tweened values.
- _lazyRender();
- }
- this._callback("onUpdate");
- }
- if (callback) if (!this._locked) if (!this._gc) if (prevStart === this._startTime || prevTimeScale !== this._timeScale) if (this._time === 0 || totalDur >= this.totalDuration()) { //if one of the tweens that was rendered altered this timeline's startTime (like if an onComplete reversed the timeline), it probably isn't complete. If it is, don't worry, because whatever call altered the startTime would complete if it was necessary at the new time. The only exception is the timeScale property. Also check _gc because there's a chance that kill() could be called in an onUpdate
- if (isComplete) {
- if (_lazyTweens.length) { //in case rendering caused any tweens to lazy-init, we should render them because typically when a timeline finishes, users expect things to have rendered fully. Imagine an onComplete on a timeline that reports/checks tweened values.
- _lazyRender();
- }
- if (this._timeline.autoRemoveChildren) {
- this._enabled(false, false);
- }
- this._active = false;
- }
- if (!suppressEvents && this.vars[callback]) {
- this._callback(callback);
- }
- }
- };
- p.getActive = function(nested, tweens, timelines) {
- if (nested == null) {
- nested = true;
- }
- if (tweens == null) {
- tweens = true;
- }
- if (timelines == null) {
- timelines = false;
- }
- var a = [],
- all = this.getChildren(nested, tweens, timelines),
- cnt = 0,
- l = all.length,
- i, tween;
- for (i = 0; i < l; i++) {
- tween = all[i];
- if (tween.isActive()) {
- a[cnt++] = tween;
- }
- }
- return a;
- };
- p.getLabelAfter = function(time) {
- if (!time) if (time !== 0) { //faster than isNan()
- time = this._time;
- }
- var labels = this.getLabelsArray(),
- l = labels.length,
- i;
- for (i = 0; i < l; i++) {
- if (labels[i].time > time) {
- return labels[i].name;
- }
- }
- return null;
- };
- p.getLabelBefore = function(time) {
- if (time == null) {
- time = this._time;
- }
- var labels = this.getLabelsArray(),
- i = labels.length;
- while (--i > -1) {
- if (labels[i].time < time) {
- return labels[i].name;
- }
- }
- return null;
- };
- p.getLabelsArray = function() {
- var a = [],
- cnt = 0,
- p;
- for (p in this._labels) {
- a[cnt++] = {time:this._labels[p], name:p};
- }
- a.sort(function(a,b) {
- return a.time - b.time;
- });
- return a;
- };
- p.invalidate = function() {
- this._locked = false; //unlock and set cycle in case invalidate() is called from inside an onRepeat
- return TimelineLite.prototype.invalidate.call(this);
- };
- //---- GETTERS / SETTERS -------------------------------------------------------------------------------------------------------
- p.progress = function(value, suppressEvents) {
- return (!arguments.length) ? (this._time / this.duration()) || 0 : this.totalTime( this.duration() * ((this._yoyo && (this._cycle & 1) !== 0) ? 1 - value : value) + (this._cycle * (this._duration + this._repeatDelay)), suppressEvents);
- };
- p.totalProgress = function(value, suppressEvents) {
- return (!arguments.length) ? (this._totalTime / this.totalDuration()) || 0 : this.totalTime( this.totalDuration() * value, suppressEvents);
- };
- p.totalDuration = function(value) {
- if (!arguments.length) {
- if (this._dirty) {
- TimelineLite.prototype.totalDuration.call(this); //just forces refresh
- //Instead of Infinity, we use 999999999999 so that we can accommodate reverses.
- this._totalDuration = (this._repeat === -1) ? 999999999999 : this._duration * (this._repeat + 1) + (this._repeatDelay * this._repeat);
- }
- return this._totalDuration;
- }
- return (this._repeat === -1 || !value) ? this : this.timeScale( this.totalDuration() / value );
- };
- p.time = function(value, suppressEvents) {
- if (!arguments.length) {
- return this._time;
- }
- if (this._dirty) {
- this.totalDuration();
- }
- if (value > this._duration) {
- value = this._duration;
- }
- if (this._yoyo && (this._cycle & 1) !== 0) {
- value = (this._duration - value) + (this._cycle * (this._duration + this._repeatDelay));
- } else if (this._repeat !== 0) {
- value += this._cycle * (this._duration + this._repeatDelay);
- }
- return this.totalTime(value, suppressEvents);
- };
- p.repeat = function(value) {
- if (!arguments.length) {
- return this._repeat;
- }
- this._repeat = value;
- return this._uncache(true);
- };
- p.repeatDelay = function(value) {
- if (!arguments.length) {
- return this._repeatDelay;
- }
- this._repeatDelay = value;
- return this._uncache(true);
- };
- p.yoyo = function(value) {
- if (!arguments.length) {
- return this._yoyo;
- }
- this._yoyo = value;
- return this;
- };
- p.currentLabel = function(value) {
- if (!arguments.length) {
- return this.getLabelBefore(this._time + 0.00000001);
- }
- return this.seek(value, true);
- };
- return TimelineMax;
- }, true);
-
-
-
-
-
-
-
-
- /*
- * ----------------------------------------------------------------
- * BezierPlugin
- * ----------------------------------------------------------------
- */
- (function() {
- var _RAD2DEG = 180 / Math.PI,
- _r1 = [],
- _r2 = [],
- _r3 = [],
- _corProps = {},
- _globals = _gsScope._gsDefine.globals,
- Segment = function(a, b, c, d) {
- if (c === d) { //if c and d match, the final autoRotate value could lock at -90 degrees, so differentiate them slightly.
- c = d - (d - b) / 1000000;
- }
- if (a === b) { //if a and b match, the starting autoRotate value could lock at -90 degrees, so differentiate them slightly.
- b = a + (c - a) / 1000000;
- }
- this.a = a;
- this.b = b;
- this.c = c;
- this.d = d;
- this.da = d - a;
- this.ca = c - a;
- this.ba = b - a;
- },
- _correlate = ",x,y,z,left,top,right,bottom,marginTop,marginLeft,marginRight,marginBottom,paddingLeft,paddingTop,paddingRight,paddingBottom,backgroundPosition,backgroundPosition_y,",
- cubicToQuadratic = function(a, b, c, d) {
- var q1 = {a:a},
- q2 = {},
- q3 = {},
- q4 = {c:d},
- mab = (a + b) / 2,
- mbc = (b + c) / 2,
- mcd = (c + d) / 2,
- mabc = (mab + mbc) / 2,
- mbcd = (mbc + mcd) / 2,
- m8 = (mbcd - mabc) / 8;
- q1.b = mab + (a - mab) / 4;
- q2.b = mabc + m8;
- q1.c = q2.a = (q1.b + q2.b) / 2;
- q2.c = q3.a = (mabc + mbcd) / 2;
- q3.b = mbcd - m8;
- q4.b = mcd + (d - mcd) / 4;
- q3.c = q4.a = (q3.b + q4.b) / 2;
- return [q1, q2, q3, q4];
- },
- _calculateControlPoints = function(a, curviness, quad, basic, correlate) {
- var l = a.length - 1,
- ii = 0,
- cp1 = a[0].a,
- i, p1, p2, p3, seg, m1, m2, mm, cp2, qb, r1, r2, tl;
- for (i = 0; i < l; i++) {
- seg = a[ii];
- p1 = seg.a;
- p2 = seg.d;
- p3 = a[ii+1].d;
- if (correlate) {
- r1 = _r1[i];
- r2 = _r2[i];
- tl = ((r2 + r1) * curviness * 0.25) / (basic ? 0.5 : _r3[i] || 0.5);
- m1 = p2 - (p2 - p1) * (basic ? curviness * 0.5 : (r1 !== 0 ? tl / r1 : 0));
- m2 = p2 + (p3 - p2) * (basic ? curviness * 0.5 : (r2 !== 0 ? tl / r2 : 0));
- mm = p2 - (m1 + (((m2 - m1) * ((r1 * 3 / (r1 + r2)) + 0.5) / 4) || 0));
- } else {
- m1 = p2 - (p2 - p1) * curviness * 0.5;
- m2 = p2 + (p3 - p2) * curviness * 0.5;
- mm = p2 - (m1 + m2) / 2;
- }
- m1 += mm;
- m2 += mm;
- seg.c = cp2 = m1;
- if (i !== 0) {
- seg.b = cp1;
- } else {
- seg.b = cp1 = seg.a + (seg.c - seg.a) * 0.6; //instead of placing b on a exactly, we move it inline with c so that if the user specifies an ease like Back.easeIn or Elastic.easeIn which goes BEYOND the beginning, it will do so smoothly.
- }
- seg.da = p2 - p1;
- seg.ca = cp2 - p1;
- seg.ba = cp1 - p1;
- if (quad) {
- qb = cubicToQuadratic(p1, cp1, cp2, p2);
- a.splice(ii, 1, qb[0], qb[1], qb[2], qb[3]);
- ii += 4;
- } else {
- ii++;
- }
- cp1 = m2;
- }
- seg = a[ii];
- seg.b = cp1;
- seg.c = cp1 + (seg.d - cp1) * 0.4; //instead of placing c on d exactly, we move it inline with b so that if the user specifies an ease like Back.easeOut or Elastic.easeOut which goes BEYOND the end, it will do so smoothly.
- seg.da = seg.d - seg.a;
- seg.ca = seg.c - seg.a;
- seg.ba = cp1 - seg.a;
- if (quad) {
- qb = cubicToQuadratic(seg.a, cp1, seg.c, seg.d);
- a.splice(ii, 1, qb[0], qb[1], qb[2], qb[3]);
- }
- },
- _parseAnchors = function(values, p, correlate, prepend) {
- var a = [],
- l, i, p1, p2, p3, tmp;
- if (prepend) {
- values = [prepend].concat(values);
- i = values.length;
- while (--i > -1) {
- if (typeof( (tmp = values[i][p]) ) === "string") if (tmp.charAt(1) === "=") {
- values[i][p] = prepend[p] + Number(tmp.charAt(0) + tmp.substr(2)); //accommodate relative values. Do it inline instead of breaking it out into a function for speed reasons
- }
- }
- }
- l = values.length - 2;
- if (l < 0) {
- a[0] = new Segment(values[0][p], 0, 0, values[0][p]);
- return a;
- }
- for (i = 0; i < l; i++) {
- p1 = values[i][p];
- p2 = values[i+1][p];
- a[i] = new Segment(p1, 0, 0, p2);
- if (correlate) {
- p3 = values[i+2][p];
- _r1[i] = (_r1[i] || 0) + (p2 - p1) * (p2 - p1);
- _r2[i] = (_r2[i] || 0) + (p3 - p2) * (p3 - p2);
- }
- }
- a[i] = new Segment(values[i][p], 0, 0, values[i+1][p]);
- return a;
- },
- bezierThrough = function(values, curviness, quadratic, basic, correlate, prepend) {
- var obj = {},
- props = [],
- first = prepend || values[0],
- i, p, a, j, r, l, seamless, last;
- correlate = (typeof(correlate) === "string") ? ","+correlate+"," : _correlate;
- if (curviness == null) {
- curviness = 1;
- }
- for (p in values[0]) {
- props.push(p);
- }
- //check to see if the last and first values are identical (well, within 0.05). If so, make seamless by appending the second element to the very end of the values array and the 2nd-to-last element to the very beginning (we'll remove those segments later)
- if (values.length > 1) {
- last = values[values.length - 1];
- seamless = true;
- i = props.length;
- while (--i > -1) {
- p = props[i];
- if (Math.abs(first[p] - last[p]) > 0.05) { //build in a tolerance of +/-0.05 to accommodate rounding errors.
- seamless = false;
- break;
- }
- }
- if (seamless) {
- values = values.concat(); //duplicate the array to avoid contaminating the original which the user may be reusing for other tweens
- if (prepend) {
- values.unshift(prepend);
- }
- values.push(values[1]);
- prepend = values[values.length - 3];
- }
- }
- _r1.length = _r2.length = _r3.length = 0;
- i = props.length;
- while (--i > -1) {
- p = props[i];
- _corProps[p] = (correlate.indexOf(","+p+",") !== -1);
- obj[p] = _parseAnchors(values, p, _corProps[p], prepend);
- }
- i = _r1.length;
- while (--i > -1) {
- _r1[i] = Math.sqrt(_r1[i]);
- _r2[i] = Math.sqrt(_r2[i]);
- }
- if (!basic) {
- i = props.length;
- while (--i > -1) {
- if (_corProps[p]) {
- a = obj[props[i]];
- l = a.length - 1;
- for (j = 0; j < l; j++) {
- r = (a[j+1].da / _r2[j] + a[j].da / _r1[j]) || 0;
- _r3[j] = (_r3[j] || 0) + r * r;
- }
- }
- }
- i = _r3.length;
- while (--i > -1) {
- _r3[i] = Math.sqrt(_r3[i]);
- }
- }
- i = props.length;
- j = quadratic ? 4 : 1;
- while (--i > -1) {
- p = props[i];
- a = obj[p];
- _calculateControlPoints(a, curviness, quadratic, basic, _corProps[p]); //this method requires that _parseAnchors() and _setSegmentRatios() ran first so that _r1, _r2, and _r3 values are populated for all properties
- if (seamless) {
- a.splice(0, j);
- a.splice(a.length - j, j);
- }
- }
- return obj;
- },
- _parseBezierData = function(values, type, prepend) {
- type = type || "soft";
- var obj = {},
- inc = (type === "cubic") ? 3 : 2,
- soft = (type === "soft"),
- props = [],
- a, b, c, d, cur, i, j, l, p, cnt, tmp;
- if (soft && prepend) {
- values = [prepend].concat(values);
- }
- if (values == null || values.length < inc + 1) { throw "invalid Bezier data"; }
- for (p in values[0]) {
- props.push(p);
- }
- i = props.length;
- while (--i > -1) {
- p = props[i];
- obj[p] = cur = [];
- cnt = 0;
- l = values.length;
- for (j = 0; j < l; j++) {
- a = (prepend == null) ? values[j][p] : (typeof( (tmp = values[j][p]) ) === "string" && tmp.charAt(1) === "=") ? prepend[p] + Number(tmp.charAt(0) + tmp.substr(2)) : Number(tmp);
- if (soft) if (j > 1) if (j < l - 1) {
- cur[cnt++] = (a + cur[cnt-2]) / 2;
- }
- cur[cnt++] = a;
- }
- l = cnt - inc + 1;
- cnt = 0;
- for (j = 0; j < l; j += inc) {
- a = cur[j];
- b = cur[j+1];
- c = cur[j+2];
- d = (inc === 2) ? 0 : cur[j+3];
- cur[cnt++] = tmp = (inc === 3) ? new Segment(a, b, c, d) : new Segment(a, (2 * b + a) / 3, (2 * b + c) / 3, c);
- }
- cur.length = cnt;
- }
- return obj;
- },
- _addCubicLengths = function(a, steps, resolution) {
- var inc = 1 / resolution,
- j = a.length,
- d, d1, s, da, ca, ba, p, i, inv, bez, index;
- while (--j > -1) {
- bez = a[j];
- s = bez.a;
- da = bez.d - s;
- ca = bez.c - s;
- ba = bez.b - s;
- d = d1 = 0;
- for (i = 1; i <= resolution; i++) {
- p = inc * i;
- inv = 1 - p;
- d = d1 - (d1 = (p * p * da + 3 * inv * (p * ca + inv * ba)) * p);
- index = j * resolution + i - 1;
- steps[index] = (steps[index] || 0) + d * d;
- }
- }
- },
- _parseLengthData = function(obj, resolution) {
- resolution = resolution >> 0 || 6;
- var a = [],
- lengths = [],
- d = 0,
- total = 0,
- threshold = resolution - 1,
- segments = [],
- curLS = [], //current length segments array
- p, i, l, index;
- for (p in obj) {
- _addCubicLengths(obj[p], a, resolution);
- }
- l = a.length;
- for (i = 0; i < l; i++) {
- d += Math.sqrt(a[i]);
- index = i % resolution;
- curLS[index] = d;
- if (index === threshold) {
- total += d;
- index = (i / resolution) >> 0;
- segments[index] = curLS;
- lengths[index] = total;
- d = 0;
- curLS = [];
- }
- }
- return {length:total, lengths:lengths, segments:segments};
- },
- BezierPlugin = _gsScope._gsDefine.plugin({
- propName: "bezier",
- priority: -1,
- version: "1.3.8",
- API: 2,
- global:true,
- //gets called when the tween renders for the first time. This is where initial values should be recorded and any setup routines should run.
- init: function(target, vars, tween) {
- this._target = target;
- if (vars instanceof Array) {
- vars = {values:vars};
- }
- this._func = {};
- this._mod = {};
- this._props = [];
- this._timeRes = (vars.timeResolution == null) ? 6 : parseInt(vars.timeResolution, 10);
- var values = vars.values || [],
- first = {},
- second = values[0],
- autoRotate = vars.autoRotate || tween.vars.orientToBezier,
- p, isFunc, i, j, prepend;
- this._autoRotate = autoRotate ? (autoRotate instanceof Array) ? autoRotate : [["x","y","rotation",((autoRotate === true) ? 0 : Number(autoRotate) || 0)]] : null;
- for (p in second) {
- this._props.push(p);
- }
- i = this._props.length;
- while (--i > -1) {
- p = this._props[i];
- this._overwriteProps.push(p);
- isFunc = this._func[p] = (typeof(target[p]) === "function");
- first[p] = (!isFunc) ? parseFloat(target[p]) : target[ ((p.indexOf("set") || typeof(target["get" + p.substr(3)]) !== "function") ? p : "get" + p.substr(3)) ]();
- if (!prepend) if (first[p] !== values[0][p]) {
- prepend = first;
- }
- }
- this._beziers = (vars.type !== "cubic" && vars.type !== "quadratic" && vars.type !== "soft") ? bezierThrough(values, isNaN(vars.curviness) ? 1 : vars.curviness, false, (vars.type === "thruBasic"), vars.correlate, prepend) : _parseBezierData(values, vars.type, first);
- this._segCount = this._beziers[p].length;
- if (this._timeRes) {
- var ld = _parseLengthData(this._beziers, this._timeRes);
- this._length = ld.length;
- this._lengths = ld.lengths;
- this._segments = ld.segments;
- this._l1 = this._li = this._s1 = this._si = 0;
- this._l2 = this._lengths[0];
- this._curSeg = this._segments[0];
- this._s2 = this._curSeg[0];
- this._prec = 1 / this._curSeg.length;
- }
- if ((autoRotate = this._autoRotate)) {
- this._initialRotations = [];
- if (!(autoRotate[0] instanceof Array)) {
- this._autoRotate = autoRotate = [autoRotate];
- }
- i = autoRotate.length;
- while (--i > -1) {
- for (j = 0; j < 3; j++) {
- p = autoRotate[i][j];
- this._func[p] = (typeof(target[p]) === "function") ? target[ ((p.indexOf("set") || typeof(target["get" + p.substr(3)]) !== "function") ? p : "get" + p.substr(3)) ] : false;
- }
- p = autoRotate[i][2];
- this._initialRotations[i] = (this._func[p] ? this._func[p].call(this._target) : this._target[p]) || 0;
- this._overwriteProps.push(p);
- }
- }
- this._startRatio = tween.vars.runBackwards ? 1 : 0; //we determine the starting ratio when the tween inits which is always 0 unless the tween has runBackwards:true (indicating it's a from() tween) in which case it's 1.
- return true;
- },
- //called each time the values should be updated, and the ratio gets passed as the only parameter (typically it's a value between 0 and 1, but it can exceed those when using an ease like Elastic.easeOut or Back.easeOut, etc.)
- set: function(v) {
- var segments = this._segCount,
- func = this._func,
- target = this._target,
- notStart = (v !== this._startRatio),
- curIndex, inv, i, p, b, t, val, l, lengths, curSeg;
- if (!this._timeRes) {
- curIndex = (v < 0) ? 0 : (v >= 1) ? segments - 1 : (segments * v) >> 0;
- t = (v - (curIndex * (1 / segments))) * segments;
- } else {
- lengths = this._lengths;
- curSeg = this._curSeg;
- v *= this._length;
- i = this._li;
- //find the appropriate segment (if the currently cached one isn't correct)
- if (v > this._l2 && i < segments - 1) {
- l = segments - 1;
- while (i < l && (this._l2 = lengths[++i]) <= v) { }
- this._l1 = lengths[i-1];
- this._li = i;
- this._curSeg = curSeg = this._segments[i];
- this._s2 = curSeg[(this._s1 = this._si = 0)];
- } else if (v < this._l1 && i > 0) {
- while (i > 0 && (this._l1 = lengths[--i]) >= v) { }
- if (i === 0 && v < this._l1) {
- this._l1 = 0;
- } else {
- i++;
- }
- this._l2 = lengths[i];
- this._li = i;
- this._curSeg = curSeg = this._segments[i];
- this._s1 = curSeg[(this._si = curSeg.length - 1) - 1] || 0;
- this._s2 = curSeg[this._si];
- }
- curIndex = i;
- //now find the appropriate sub-segment (we split it into the number of pieces that was defined by "precision" and measured each one)
- v -= this._l1;
- i = this._si;
- if (v > this._s2 && i < curSeg.length - 1) {
- l = curSeg.length - 1;
- while (i < l && (this._s2 = curSeg[++i]) <= v) { }
- this._s1 = curSeg[i-1];
- this._si = i;
- } else if (v < this._s1 && i > 0) {
- while (i > 0 && (this._s1 = curSeg[--i]) >= v) { }
- if (i === 0 && v < this._s1) {
- this._s1 = 0;
- } else {
- i++;
- }
- this._s2 = curSeg[i];
- this._si = i;
- }
- t = ((i + (v - this._s1) / (this._s2 - this._s1)) * this._prec) || 0;
- }
- inv = 1 - t;
- i = this._props.length;
- while (--i > -1) {
- p = this._props[i];
- b = this._beziers[p][curIndex];
- val = (t * t * b.da + 3 * inv * (t * b.ca + inv * b.ba)) * t + b.a;
- if (this._mod[p]) {
- val = this._mod[p](val, target);
- }
- if (func[p]) {
- target[p](val);
- } else {
- target[p] = val;
- }
- }
- if (this._autoRotate) {
- var ar = this._autoRotate,
- b2, x1, y1, x2, y2, add, conv;
- i = ar.length;
- while (--i > -1) {
- p = ar[i][2];
- add = ar[i][3] || 0;
- conv = (ar[i][4] === true) ? 1 : _RAD2DEG;
- b = this._beziers[ar[i][0]];
- b2 = this._beziers[ar[i][1]];
- if (b && b2) { //in case one of the properties got overwritten.
- b = b[curIndex];
- b2 = b2[curIndex];
- x1 = b.a + (b.b - b.a) * t;
- x2 = b.b + (b.c - b.b) * t;
- x1 += (x2 - x1) * t;
- x2 += ((b.c + (b.d - b.c) * t) - x2) * t;
- y1 = b2.a + (b2.b - b2.a) * t;
- y2 = b2.b + (b2.c - b2.b) * t;
- y1 += (y2 - y1) * t;
- y2 += ((b2.c + (b2.d - b2.c) * t) - y2) * t;
- val = notStart ? Math.atan2(y2 - y1, x2 - x1) * conv + add : this._initialRotations[i];
- if (this._mod[p]) {
- val = this._mod[p](val, target); //for modProps
- }
- if (func[p]) {
- target[p](val);
- } else {
- target[p] = val;
- }
- }
- }
- }
- }
- }),
- p = BezierPlugin.prototype;
- BezierPlugin.bezierThrough = bezierThrough;
- BezierPlugin.cubicToQuadratic = cubicToQuadratic;
- BezierPlugin._autoCSS = true; //indicates that this plugin can be inserted into the "css" object using the autoCSS feature of TweenLite
- BezierPlugin.quadraticToCubic = function(a, b, c) {
- return new Segment(a, (2 * b + a) / 3, (2 * b + c) / 3, c);
- };
- BezierPlugin._cssRegister = function() {
- var CSSPlugin = _globals.CSSPlugin;
- if (!CSSPlugin) {
- return;
- }
- var _internals = CSSPlugin._internals,
- _parseToProxy = _internals._parseToProxy,
- _setPluginRatio = _internals._setPluginRatio,
- CSSPropTween = _internals.CSSPropTween;
- _internals._registerComplexSpecialProp("bezier", {parser:function(t, e, prop, cssp, pt, plugin) {
- if (e instanceof Array) {
- e = {values:e};
- }
- plugin = new BezierPlugin();
- var values = e.values,
- l = values.length - 1,
- pluginValues = [],
- v = {},
- i, p, data;
- if (l < 0) {
- return pt;
- }
- for (i = 0; i <= l; i++) {
- data = _parseToProxy(t, values[i], cssp, pt, plugin, (l !== i));
- pluginValues[i] = data.end;
- }
- for (p in e) {
- v[p] = e[p]; //duplicate the vars object because we need to alter some things which would cause problems if the user plans to reuse the same vars object for another tween.
- }
- v.values = pluginValues;
- pt = new CSSPropTween(t, "bezier", 0, 0, data.pt, 2);
- pt.data = data;
- pt.plugin = plugin;
- pt.setRatio = _setPluginRatio;
- if (v.autoRotate === 0) {
- v.autoRotate = true;
- }
- if (v.autoRotate && !(v.autoRotate instanceof Array)) {
- i = (v.autoRotate === true) ? 0 : Number(v.autoRotate);
- v.autoRotate = (data.end.left != null) ? [["left","top","rotation",i,false]] : (data.end.x != null) ? [["x","y","rotation",i,false]] : false;
- }
- if (v.autoRotate) {
- if (!cssp._transform) {
- cssp._enableTransforms(false);
- }
- data.autoRotate = cssp._target._gsTransform;
- data.proxy.rotation = data.autoRotate.rotation || 0;
- cssp._overwriteProps.push("rotation");
- }
- plugin._onInitTween(data.proxy, v, cssp._tween);
- return pt;
- }});
- };
- p._mod = function(lookup) {
- var op = this._overwriteProps,
- i = op.length,
- val;
- while (--i > -1) {
- val = lookup[op[i]];
- if (val && typeof(val) === "function") {
- this._mod[op[i]] = val;
- }
- }
- };
- p._kill = function(lookup) {
- var a = this._props,
- p, i;
- for (p in this._beziers) {
- if (p in lookup) {
- delete this._beziers[p];
- delete this._func[p];
- i = a.length;
- while (--i > -1) {
- if (a[i] === p) {
- a.splice(i, 1);
- }
- }
- }
- }
- a = this._autoRotate;
- if (a) {
- i = a.length;
- while (--i > -1) {
- if (lookup[a[i][2]]) {
- a.splice(i, 1);
- }
- }
- }
- return this._super._kill.call(this, lookup);
- };
- }());
-
-
-
-
-
-
-
-
- /*
- * ----------------------------------------------------------------
- * CSSPlugin
- * ----------------------------------------------------------------
- */
- _gsScope._gsDefine("plugins.CSSPlugin", ["plugins.TweenPlugin","TweenLite"], function(TweenPlugin, TweenLite) {
- /** @constructor **/
- var CSSPlugin = function() {
- TweenPlugin.call(this, "css");
- this._overwriteProps.length = 0;
- this.setRatio = CSSPlugin.prototype.setRatio; //speed optimization (avoid prototype lookup on this "hot" method)
- },
- _globals = _gsScope._gsDefine.globals,
- _hasPriority, //turns true whenever a CSSPropTween instance is created that has a priority other than 0. This helps us discern whether or not we should spend the time organizing the linked list or not after a CSSPlugin's _onInitTween() method is called.
- _suffixMap, //we set this in _onInitTween() each time as a way to have a persistent variable we can use in other methods like _parse() without having to pass it around as a parameter and we keep _parse() decoupled from a particular CSSPlugin instance
- _cs, //computed style (we store this in a shared variable to conserve memory and make minification tighter
- _overwriteProps, //alias to the currently instantiating CSSPlugin's _overwriteProps array. We use this closure in order to avoid having to pass a reference around from method to method and aid in minification.
- _specialProps = {},
- p = CSSPlugin.prototype = new TweenPlugin("css");
- p.constructor = CSSPlugin;
- CSSPlugin.version = "1.20.0";
- CSSPlugin.API = 2;
- CSSPlugin.defaultTransformPerspective = 0;
- CSSPlugin.defaultSkewType = "compensated";
- CSSPlugin.defaultSmoothOrigin = true;
- p = "px"; //we'll reuse the "p" variable to keep file size down
- CSSPlugin.suffixMap = {top:p, right:p, bottom:p, left:p, width:p, height:p, fontSize:p, padding:p, margin:p, perspective:p, lineHeight:""};
- var _numExp = /(?:\-|\.|\b)(\d|\.|e\-)+/g,
- _relNumExp = /(?:\d|\-\d|\.\d|\-\.\d|\+=\d|\-=\d|\+=.\d|\-=\.\d)+/g,
- _valuesExp = /(?:\+=|\-=|\-|\b)[\d\-\.]+[a-zA-Z0-9]*(?:%|\b)/gi, //finds all the values that begin with numbers or += or -= and then a number. Includes suffixes. We use this to split complex values apart like "1px 5px 20px rgb(255,102,51)"
- _NaNExp = /(?![+-]?\d*\.?\d+|[+-]|e[+-]\d+)[^0-9]/g, //also allows scientific notation and doesn't kill the leading -/+ in -= and +=
- _suffixExp = /(?:\d|\-|\+|=|#|\.)*/g,
- _opacityExp = /opacity *= *([^)]*)/i,
- _opacityValExp = /opacity:([^;]*)/i,
- _alphaFilterExp = /alpha\(opacity *=.+?\)/i,
- _rgbhslExp = /^(rgb|hsl)/,
- _capsExp = /([A-Z])/g,
- _camelExp = /-([a-z])/gi,
- _urlExp = /(^(?:url\(\"|url\())|(?:(\"\))$|\)$)/gi, //for pulling out urls from url(...) or url("...") strings (some browsers wrap urls in quotes, some don't when reporting things like backgroundImage)
- _camelFunc = function(s, g) { return g.toUpperCase(); },
- _horizExp = /(?:Left|Right|Width)/i,
- _ieGetMatrixExp = /(M11|M12|M21|M22)=[\d\-\.e]+/gi,
- _ieSetMatrixExp = /progid\:DXImageTransform\.Microsoft\.Matrix\(.+?\)/i,
- _commasOutsideParenExp = /,(?=[^\)]*(?:\(|$))/gi, //finds any commas that are not within parenthesis
- _complexExp = /[\s,\(]/i, //for testing a string to find if it has a space, comma, or open parenthesis (clues that it's a complex value)
- _DEG2RAD = Math.PI / 180,
- _RAD2DEG = 180 / Math.PI,
- _forcePT = {},
- _dummyElement = {style:{}},
- _doc = _gsScope.document || {createElement: function() {return _dummyElement;}},
- _createElement = function(type, ns) {
- return _doc.createElementNS ? _doc.createElementNS(ns || "http://www.w3.org/1999/xhtml", type) : _doc.createElement(type);
- },
- _tempDiv = _createElement("div"),
- _tempImg = _createElement("img"),
- _internals = CSSPlugin._internals = {_specialProps:_specialProps}, //provides a hook to a few internal methods that we need to access from inside other plugins
- _agent = (_gsScope.navigator || {}).userAgent || "",
- _autoRound,
- _reqSafariFix, //we won't apply the Safari transform fix until we actually come across a tween that affects a transform property (to maintain best performance).
- _isSafari,
- _isFirefox, //Firefox has a bug that causes 3D transformed elements to randomly disappear unless a repaint is forced after each update on each element.
- _isSafariLT6, //Safari (and Android 4 which uses a flavor of Safari) has a bug that prevents changes to "top" and "left" properties from rendering properly if changed on the same frame as a transform UNLESS we set the element's WebkitBackfaceVisibility to hidden (weird, I know). Doing this for Android 3 and earlier seems to actually cause other problems, though (fun!)
- _ieVers,
- _supportsOpacity = (function() { //we set _isSafari, _ieVers, _isFirefox, and _supportsOpacity all in one function here to reduce file size slightly, especially in the minified version.
- var i = _agent.indexOf("Android"),
- a = _createElement("a");
- _isSafari = (_agent.indexOf("Safari") !== -1 && _agent.indexOf("Chrome") === -1 && (i === -1 || parseFloat(_agent.substr(i+8, 2)) > 3));
- _isSafariLT6 = (_isSafari && (parseFloat(_agent.substr(_agent.indexOf("Version/")+8, 2)) < 6));
- _isFirefox = (_agent.indexOf("Firefox") !== -1);
- if ((/MSIE ([0-9]{1,}[\.0-9]{0,})/).exec(_agent) || (/Trident\/.*rv:([0-9]{1,}[\.0-9]{0,})/).exec(_agent)) {
- _ieVers = parseFloat( RegExp.$1 );
- }
- if (!a) {
- return false;
- }
- a.style.cssText = "top:1px;opacity:.55;";
- return /^0.55/.test(a.style.opacity);
- }()),
- _getIEOpacity = function(v) {
- return (_opacityExp.test( ((typeof(v) === "string") ? v : (v.currentStyle ? v.currentStyle.filter : v.style.filter) || "") ) ? ( parseFloat( RegExp.$1 ) / 100 ) : 1);
- },
- _log = function(s) {//for logging messages, but in a way that won't throw errors in old versions of IE.
- if (_gsScope.console) {
- console.log(s);
- }
- },
- _target, //when initting a CSSPlugin, we set this variable so that we can access it from within many other functions without having to pass it around as params
- _index, //when initting a CSSPlugin, we set this variable so that we can access it from within many other functions without having to pass it around as params
- _prefixCSS = "", //the non-camelCase vendor prefix like "-o-", "-moz-", "-ms-", or "-webkit-"
- _prefix = "", //camelCase vendor prefix like "O", "ms", "Webkit", or "Moz".
- // @private feed in a camelCase property name like "transform" and it will check to see if it is valid as-is or if it needs a vendor prefix. It returns the corrected camelCase property name (i.e. "WebkitTransform" or "MozTransform" or "transform" or null if no such property is found, like if the browser is IE8 or before, "transform" won't be found at all)
- _checkPropPrefix = function(p, e) {
- e = e || _tempDiv;
- var s = e.style,
- a, i;
- if (s[p] !== undefined) {
- return p;
- }
- p = p.charAt(0).toUpperCase() + p.substr(1);
- a = ["O","Moz","ms","Ms","Webkit"];
- i = 5;
- while (--i > -1 && s[a[i]+p] === undefined) { }
- if (i >= 0) {
- _prefix = (i === 3) ? "ms" : a[i];
- _prefixCSS = "-" + _prefix.toLowerCase() + "-";
- return _prefix + p;
- }
- return null;
- },
- _getComputedStyle = _doc.defaultView ? _doc.defaultView.getComputedStyle : function() {},
- /**
- * @private Returns the css style for a particular property of an element. For example, to get whatever the current "left" css value for an element with an ID of "myElement", you could do:
- * var currentLeft = CSSPlugin.getStyle( document.getElementById("myElement"), "left");
- *
- * @param {!Object} t Target element whose style property you want to query
- * @param {!string} p Property name (like "left" or "top" or "marginTop", etc.)
- * @param {Object=} cs Computed style object. This just provides a way to speed processing if you're going to get several properties on the same element in quick succession - you can reuse the result of the getComputedStyle() call.
- * @param {boolean=} calc If true, the value will not be read directly from the element's "style" property (if it exists there), but instead the getComputedStyle() result will be used. This can be useful when you want to ensure that the browser itself is interpreting the value.
- * @param {string=} dflt Default value that should be returned in the place of null, "none", "auto" or "auto auto".
- * @return {?string} The current property value
- */
- _getStyle = CSSPlugin.getStyle = function(t, p, cs, calc, dflt) {
- var rv;
- if (!_supportsOpacity) if (p === "opacity") { //several versions of IE don't use the standard "opacity" property - they use things like filter:alpha(opacity=50), so we parse that here.
- return _getIEOpacity(t);
- }
- if (!calc && t.style[p]) {
- rv = t.style[p];
- } else if ((cs = cs || _getComputedStyle(t))) {
- rv = cs[p] || cs.getPropertyValue(p) || cs.getPropertyValue(p.replace(_capsExp, "-$1").toLowerCase());
- } else if (t.currentStyle) {
- rv = t.currentStyle[p];
- }
- return (dflt != null && (!rv || rv === "none" || rv === "auto" || rv === "auto auto")) ? dflt : rv;
- },
- /**
- * @private Pass the target element, the property name, the numeric value, and the suffix (like "%", "em", "px", etc.) and it will spit back the equivalent pixel number.
- * @param {!Object} t Target element
- * @param {!string} p Property name (like "left", "top", "marginLeft", etc.)
- * @param {!number} v Value
- * @param {string=} sfx Suffix (like "px" or "%" or "em")
- * @param {boolean=} recurse If true, the call is a recursive one. In some browsers (like IE7/8), occasionally the value isn't accurately reported initially, but if we run the function again it will take effect.
- * @return {number} value in pixels
- */
- _convertToPixels = _internals.convertToPixels = function(t, p, v, sfx, recurse) {
- if (sfx === "px" || (!sfx && p !== "lineHeight")) { return v; }
- if (sfx === "auto" || !v) { return 0; }
- var horiz = _horizExp.test(p),
- node = t,
- style = _tempDiv.style,
- neg = (v < 0),
- precise = (v === 1),
- pix, cache, time;
- if (neg) {
- v = -v;
- }
- if (precise) {
- v *= 100;
- }
- if (p === "lineHeight" && !sfx) { //special case of when a simple lineHeight (without a unit) is used. Set it to the value, read back the computed value, and then revert.
- cache = _getComputedStyle(t).lineHeight;
- t.style.lineHeight = v;
- pix = parseFloat(_getComputedStyle(t).lineHeight);
- t.style.lineHeight = cache;
- } else if (sfx === "%" && p.indexOf("border") !== -1) {
- pix = (v / 100) * (horiz ? t.clientWidth : t.clientHeight);
- } else {
- style.cssText = "border:0 solid red;position:" + _getStyle(t, "position") + ";line-height:0;";
- if (sfx === "%" || !node.appendChild || sfx.charAt(0) === "v" || sfx === "rem") {
- node = t.parentNode || _doc.body;
- if (_getStyle(node, "display").indexOf("flex") !== -1) { //Edge and IE11 have a bug that causes offsetWidth to report as 0 if the container has display:flex and the child is position:relative. Switching to position: absolute solves it.
- style.position = "absolute";
- }
- cache = node._gsCache;
- time = TweenLite.ticker.frame;
- if (cache && horiz && cache.time === time) { //performance optimization: we record the width of elements along with the ticker frame so that we can quickly get it again on the same tick (seems relatively safe to assume it wouldn't change on the same tick)
- return cache.width * v / 100;
- }
- style[(horiz ? "width" : "height")] = v + sfx;
- } else {
- style[(horiz ? "borderLeftWidth" : "borderTopWidth")] = v + sfx;
- }
- node.appendChild(_tempDiv);
- pix = parseFloat(_tempDiv[(horiz ? "offsetWidth" : "offsetHeight")]);
- node.removeChild(_tempDiv);
- if (horiz && sfx === "%" && CSSPlugin.cacheWidths !== false) {
- cache = node._gsCache = node._gsCache || {};
- cache.time = time;
- cache.width = pix / v * 100;
- }
- if (pix === 0 && !recurse) {
- pix = _convertToPixels(t, p, v, sfx, true);
- }
- }
- if (precise) {
- pix /= 100;
- }
- return neg ? -pix : pix;
- },
- _calculateOffset = _internals.calculateOffset = function(t, p, cs) { //for figuring out "top" or "left" in px when it's "auto". We need to factor in margin with the offsetLeft/offsetTop
- if (_getStyle(t, "position", cs) !== "absolute") { return 0; }
- var dim = ((p === "left") ? "Left" : "Top"),
- v = _getStyle(t, "margin" + dim, cs);
- return t["offset" + dim] - (_convertToPixels(t, p, parseFloat(v), v.replace(_suffixExp, "")) || 0);
- },
- // @private returns at object containing ALL of the style properties in camelCase and their associated values.
- _getAllStyles = function(t, cs) {
- var s = {},
- i, tr, p;
- if ((cs = cs || _getComputedStyle(t, null))) {
- if ((i = cs.length)) {
- while (--i > -1) {
- p = cs[i];
- if (p.indexOf("-transform") === -1 || _transformPropCSS === p) { //Some webkit browsers duplicate transform values, one non-prefixed and one prefixed ("transform" and "WebkitTransform"), so we must weed out the extra one here.
- s[p.replace(_camelExp, _camelFunc)] = cs.getPropertyValue(p);
- }
- }
- } else { //some browsers behave differently - cs.length is always 0, so we must do a for...in loop.
- for (i in cs) {
- if (i.indexOf("Transform") === -1 || _transformProp === i) { //Some webkit browsers duplicate transform values, one non-prefixed and one prefixed ("transform" and "WebkitTransform"), so we must weed out the extra one here.
- s[i] = cs[i];
- }
- }
- }
- } else if ((cs = t.currentStyle || t.style)) {
- for (i in cs) {
- if (typeof(i) === "string" && s[i] === undefined) {
- s[i.replace(_camelExp, _camelFunc)] = cs[i];
- }
- }
- }
- if (!_supportsOpacity) {
- s.opacity = _getIEOpacity(t);
- }
- tr = _getTransform(t, cs, false);
- s.rotation = tr.rotation;
- s.skewX = tr.skewX;
- s.scaleX = tr.scaleX;
- s.scaleY = tr.scaleY;
- s.x = tr.x;
- s.y = tr.y;
- if (_supports3D) {
- s.z = tr.z;
- s.rotationX = tr.rotationX;
- s.rotationY = tr.rotationY;
- s.scaleZ = tr.scaleZ;
- }
- if (s.filters) {
- delete s.filters;
- }
- return s;
- },
- // @private analyzes two style objects (as returned by _getAllStyles()) and only looks for differences between them that contain tweenable values (like a number or color). It returns an object with a "difs" property which refers to an object containing only those isolated properties and values for tweening, and a "firstMPT" property which refers to the first MiniPropTween instance in a linked list that recorded all the starting values of the different properties so that we can revert to them at the end or beginning of the tween - we don't want the cascading to get messed up. The forceLookup parameter is an optional generic object with properties that should be forced into the results - this is necessary for className tweens that are overwriting others because imagine a scenario where a rollover/rollout adds/removes a class and the user swipes the mouse over the target SUPER fast, thus nothing actually changed yet and the subsequent comparison of the properties would indicate they match (especially when px rounding is taken into consideration), thus no tweening is necessary even though it SHOULD tween and remove those properties after the tween (otherwise the inline styles will contaminate things). See the className SpecialProp code for details.
- _cssDif = function(t, s1, s2, vars, forceLookup) {
- var difs = {},
- style = t.style,
- val, p, mpt;
- for (p in s2) {
- if (p !== "cssText") if (p !== "length") if (isNaN(p)) if (s1[p] !== (val = s2[p]) || (forceLookup && forceLookup[p])) if (p.indexOf("Origin") === -1) if (typeof(val) === "number" || typeof(val) === "string") {
- difs[p] = (val === "auto" && (p === "left" || p === "top")) ? _calculateOffset(t, p) : ((val === "" || val === "auto" || val === "none") && typeof(s1[p]) === "string" && s1[p].replace(_NaNExp, "") !== "") ? 0 : val; //if the ending value is defaulting ("" or "auto"), we check the starting value and if it can be parsed into a number (a string which could have a suffix too, like 700px), then we swap in 0 for "" or "auto" so that things actually tween.
- if (style[p] !== undefined) { //for className tweens, we must remember which properties already existed inline - the ones that didn't should be removed when the tween isn't in progress because they were only introduced to facilitate the transition between classes.
- mpt = new MiniPropTween(style, p, style[p], mpt);
- }
- }
- }
- if (vars) {
- for (p in vars) { //copy properties (except className)
- if (p !== "className") {
- difs[p] = vars[p];
- }
- }
- }
- return {difs:difs, firstMPT:mpt};
- },
- _dimensions = {width:["Left","Right"], height:["Top","Bottom"]},
- _margins = ["marginLeft","marginRight","marginTop","marginBottom"],
- /**
- * @private Gets the width or height of an element
- * @param {!Object} t Target element
- * @param {!string} p Property name ("width" or "height")
- * @param {Object=} cs Computed style object (if one exists). Just a speed optimization.
- * @return {number} Dimension (in pixels)
- */
- _getDimension = function(t, p, cs) {
- if ((t.nodeName + "").toLowerCase() === "svg") { //Chrome no longer supports offsetWidth/offsetHeight on SVG elements.
- return (cs || _getComputedStyle(t))[p] || 0;
- } else if (t.getCTM && _isSVG(t)) {
- return t.getBBox()[p] || 0;
- }
- var v = parseFloat((p === "width") ? t.offsetWidth : t.offsetHeight),
- a = _dimensions[p],
- i = a.length;
- cs = cs || _getComputedStyle(t, null);
- while (--i > -1) {
- v -= parseFloat( _getStyle(t, "padding" + a[i], cs, true) ) || 0;
- v -= parseFloat( _getStyle(t, "border" + a[i] + "Width", cs, true) ) || 0;
- }
- return v;
- },
- // @private Parses position-related complex strings like "top left" or "50px 10px" or "70% 20%", etc. which are used for things like transformOrigin or backgroundPosition. Optionally decorates a supplied object (recObj) with the following properties: "ox" (offsetX), "oy" (offsetY), "oxp" (if true, "ox" is a percentage not a pixel value), and "oxy" (if true, "oy" is a percentage not a pixel value)
- _parsePosition = function(v, recObj) {
- if (v === "contain" || v === "auto" || v === "auto auto") { //note: Firefox uses "auto auto" as default whereas Chrome uses "auto".
- return v + " ";
- }
- if (v == null || v === "") {
- v = "0 0";
- }
- var a = v.split(" "),
- x = (v.indexOf("left") !== -1) ? "0%" : (v.indexOf("right") !== -1) ? "100%" : a[0],
- y = (v.indexOf("top") !== -1) ? "0%" : (v.indexOf("bottom") !== -1) ? "100%" : a[1],
- i;
- if (a.length > 3 && !recObj) { //multiple positions
- a = v.split(", ").join(",").split(",");
- v = [];
- for (i = 0; i < a.length; i++) {
- v.push(_parsePosition(a[i]));
- }
- return v.join(",");
- }
- if (y == null) {
- y = (x === "center") ? "50%" : "0";
- } else if (y === "center") {
- y = "50%";
- }
- if (x === "center" || (isNaN(parseFloat(x)) && (x + "").indexOf("=") === -1)) { //remember, the user could flip-flop the values and say "bottom center" or "center bottom", etc. "center" is ambiguous because it could be used to describe horizontal or vertical, hence the isNaN(). If there's an "=" sign in the value, it's relative.
- x = "50%";
- }
- v = x + " " + y + ((a.length > 2) ? " " + a[2] : "");
- if (recObj) {
- recObj.oxp = (x.indexOf("%") !== -1);
- recObj.oyp = (y.indexOf("%") !== -1);
- recObj.oxr = (x.charAt(1) === "=");
- recObj.oyr = (y.charAt(1) === "=");
- recObj.ox = parseFloat(x.replace(_NaNExp, ""));
- recObj.oy = parseFloat(y.replace(_NaNExp, ""));
- recObj.v = v;
- }
- return recObj || v;
- },
- /**
- * @private Takes an ending value (typically a string, but can be a number) and a starting value and returns the change between the two, looking for relative value indicators like += and -= and it also ignores suffixes (but make sure the ending value starts with a number or +=/-= and that the starting value is a NUMBER!)
- * @param {(number|string)} e End value which is typically a string, but could be a number
- * @param {(number|string)} b Beginning value which is typically a string but could be a number
- * @return {number} Amount of change between the beginning and ending values (relative values that have a "+=" or "-=" are recognized)
- */
- _parseChange = function(e, b) {
- if (typeof(e) === "function") {
- e = e(_index, _target);
- }
- return (typeof(e) === "string" && e.charAt(1) === "=") ? parseInt(e.charAt(0) + "1", 10) * parseFloat(e.substr(2)) : (parseFloat(e) - parseFloat(b)) || 0;
- },
- /**
- * @private Takes a value and a default number, checks if the value is relative, null, or numeric and spits back a normalized number accordingly. Primarily used in the _parseTransform() function.
- * @param {Object} v Value to be parsed
- * @param {!number} d Default value (which is also used for relative calculations if "+=" or "-=" is found in the first parameter)
- * @return {number} Parsed value
- */
- _parseVal = function(v, d) {
- if (typeof(v) === "function") {
- v = v(_index, _target);
- }
- return (v == null) ? d : (typeof(v) === "string" && v.charAt(1) === "=") ? parseInt(v.charAt(0) + "1", 10) * parseFloat(v.substr(2)) + d : parseFloat(v) || 0;
- },
- /**
- * @private Translates strings like "40deg" or "40" or 40rad" or "+=40deg" or "270_short" or "-90_cw" or "+=45_ccw" to a numeric radian angle. Of course a starting/default value must be fed in too so that relative values can be calculated properly.
- * @param {Object} v Value to be parsed
- * @param {!number} d Default value (which is also used for relative calculations if "+=" or "-=" is found in the first parameter)
- * @param {string=} p property name for directionalEnd (optional - only used when the parsed value is directional ("_short", "_cw", or "_ccw" suffix). We need a way to store the uncompensated value so that at the end of the tween, we set it to exactly what was requested with no directional compensation). Property name would be "rotation", "rotationX", or "rotationY"
- * @param {Object=} directionalEnd An object that will store the raw end values for directional angles ("_short", "_cw", or "_ccw" suffix). We need a way to store the uncompensated value so that at the end of the tween, we set it to exactly what was requested with no directional compensation.
- * @return {number} parsed angle in radians
- */
- _parseAngle = function(v, d, p, directionalEnd) {
- var min = 0.000001,
- cap, split, dif, result, isRelative;
- if (typeof(v) === "function") {
- v = v(_index, _target);
- }
- if (v == null) {
- result = d;
- } else if (typeof(v) === "number") {
- result = v;
- } else {
- cap = 360;
- split = v.split("_");
- isRelative = (v.charAt(1) === "=");
- dif = (isRelative ? parseInt(v.charAt(0) + "1", 10) * parseFloat(split[0].substr(2)) : parseFloat(split[0])) * ((v.indexOf("rad") === -1) ? 1 : _RAD2DEG) - (isRelative ? 0 : d);
- if (split.length) {
- if (directionalEnd) {
- directionalEnd[p] = d + dif;
- }
- if (v.indexOf("short") !== -1) {
- dif = dif % cap;
- if (dif !== dif % (cap / 2)) {
- dif = (dif < 0) ? dif + cap : dif - cap;
- }
- }
- if (v.indexOf("_cw") !== -1 && dif < 0) {
- dif = ((dif + cap * 9999999999) % cap) - ((dif / cap) | 0) * cap;
- } else if (v.indexOf("ccw") !== -1 && dif > 0) {
- dif = ((dif - cap * 9999999999) % cap) - ((dif / cap) | 0) * cap;
- }
- }
- result = d + dif;
- }
- if (result < min && result > -min) {
- result = 0;
- }
- return result;
- },
- _colorLookup = {aqua:[0,255,255],
- lime:[0,255,0],
- silver:[192,192,192],
- black:[0,0,0],
- maroon:[128,0,0],
- teal:[0,128,128],
- blue:[0,0,255],
- navy:[0,0,128],
- white:[255,255,255],
- fuchsia:[255,0,255],
- olive:[128,128,0],
- yellow:[255,255,0],
- orange:[255,165,0],
- gray:[128,128,128],
- purple:[128,0,128],
- green:[0,128,0],
- red:[255,0,0],
- pink:[255,192,203],
- cyan:[0,255,255],
- transparent:[255,255,255,0]},
- _hue = function(h, m1, m2) {
- h = (h < 0) ? h + 1 : (h > 1) ? h - 1 : h;
- return ((((h * 6 < 1) ? m1 + (m2 - m1) * h * 6 : (h < 0.5) ? m2 : (h * 3 < 2) ? m1 + (m2 - m1) * (2 / 3 - h) * 6 : m1) * 255) + 0.5) | 0;
- },
- /**
- * @private Parses a color (like #9F0, #FF9900, rgb(255,51,153) or hsl(108, 50%, 10%)) into an array with 3 elements for red, green, and blue or if toHSL parameter is true, it will populate the array with hue, saturation, and lightness values. If a relative value is found in an hsl() or hsla() string, it will preserve those relative prefixes and all the values in the array will be strings instead of numbers (in all other cases it will be populated with numbers).
- * @param {(string|number)} v The value the should be parsed which could be a string like #9F0 or rgb(255,102,51) or rgba(255,0,0,0.5) or it could be a number like 0xFF00CC or even a named color like red, blue, purple, etc.
- * @param {(boolean)} toHSL If true, an hsl() or hsla() value will be returned instead of rgb() or rgba()
- * @return {Array.<number>} An array containing red, green, and blue (and optionally alpha) in that order, or if the toHSL parameter was true, the array will contain hue, saturation and lightness (and optionally alpha) in that order. Always numbers unless there's a relative prefix found in an hsl() or hsla() string and toHSL is true.
- */
- _parseColor = CSSPlugin.parseColor = function(v, toHSL) {
- var a, r, g, b, h, s, l, max, min, d, wasHSL;
- if (!v) {
- a = _colorLookup.black;
- } else if (typeof(v) === "number") {
- a = [v >> 16, (v >> 8) & 255, v & 255];
- } else {
- if (v.charAt(v.length - 1) === ",") { //sometimes a trailing comma is included and we should chop it off (typically from a comma-delimited list of values like a textShadow:"2px 2px 2px blue, 5px 5px 5px rgb(255,0,0)" - in this example "blue," has a trailing comma. We could strip it out inside parseComplex() but we'd need to do it to the beginning and ending values plus it wouldn't provide protection from other potential scenarios like if the user passes in a similar value.
- v = v.substr(0, v.length - 1);
- }
- if (_colorLookup[v]) {
- a = _colorLookup[v];
- } else if (v.charAt(0) === "#") {
- if (v.length === 4) { //for shorthand like #9F0
- r = v.charAt(1);
- g = v.charAt(2);
- b = v.charAt(3);
- v = "#" + r + r + g + g + b + b;
- }
- v = parseInt(v.substr(1), 16);
- a = [v >> 16, (v >> 8) & 255, v & 255];
- } else if (v.substr(0, 3) === "hsl") {
- a = wasHSL = v.match(_numExp);
- if (!toHSL) {
- h = (Number(a[0]) % 360) / 360;
- s = Number(a[1]) / 100;
- l = Number(a[2]) / 100;
- g = (l <= 0.5) ? l * (s + 1) : l + s - l * s;
- r = l * 2 - g;
- if (a.length > 3) {
- a[3] = Number(v[3]);
- }
- a[0] = _hue(h + 1 / 3, r, g);
- a[1] = _hue(h, r, g);
- a[2] = _hue(h - 1 / 3, r, g);
- } else if (v.indexOf("=") !== -1) { //if relative values are found, just return the raw strings with the relative prefixes in place.
- return v.match(_relNumExp);
- }
- } else {
- a = v.match(_numExp) || _colorLookup.transparent;
- }
- a[0] = Number(a[0]);
- a[1] = Number(a[1]);
- a[2] = Number(a[2]);
- if (a.length > 3) {
- a[3] = Number(a[3]);
- }
- }
- if (toHSL && !wasHSL) {
- r = a[0] / 255;
- g = a[1] / 255;
- b = a[2] / 255;
- max = Math.max(r, g, b);
- min = Math.min(r, g, b);
- l = (max + min) / 2;
- if (max === min) {
- h = s = 0;
- } else {
- d = max - min;
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
- h = (max === r) ? (g - b) / d + (g < b ? 6 : 0) : (max === g) ? (b - r) / d + 2 : (r - g) / d + 4;
- h *= 60;
- }
- a[0] = (h + 0.5) | 0;
- a[1] = (s * 100 + 0.5) | 0;
- a[2] = (l * 100 + 0.5) | 0;
- }
- return a;
- },
- _formatColors = function(s, toHSL) {
- var colors = s.match(_colorExp) || [],
- charIndex = 0,
- parsed = "",
- i, color, temp;
- if (!colors.length) {
- return s;
- }
- for (i = 0; i < colors.length; i++) {
- color = colors[i];
- temp = s.substr(charIndex, s.indexOf(color, charIndex)-charIndex);
- charIndex += temp.length + color.length;
- color = _parseColor(color, toHSL);
- if (color.length === 3) {
- color.push(1);
- }
- parsed += temp + (toHSL ? "hsla(" + color[0] + "," + color[1] + "%," + color[2] + "%," + color[3] : "rgba(" + color.join(",")) + ")";
- }
- return parsed + s.substr(charIndex);
- },
- _colorExp = "(?:\\b(?:(?:rgb|rgba|hsl|hsla)\\(.+?\\))|\\B#(?:[0-9a-f]{3}){1,2}\\b"; //we'll dynamically build this Regular Expression to conserve file size. After building it, it will be able to find rgb(), rgba(), # (hexadecimal), and named color values like red, blue, purple, etc.
- for (p in _colorLookup) {
- _colorExp += "|" + p + "\\b";
- }
- _colorExp = new RegExp(_colorExp+")", "gi");
- CSSPlugin.colorStringFilter = function(a) {
- var combined = a[0] + " " + a[1],
- toHSL;
- if (_colorExp.test(combined)) {
- toHSL = (combined.indexOf("hsl(") !== -1 || combined.indexOf("hsla(") !== -1);
- a[0] = _formatColors(a[0], toHSL);
- a[1] = _formatColors(a[1], toHSL);
- }
- _colorExp.lastIndex = 0;
- };
- if (!TweenLite.defaultStringFilter) {
- TweenLite.defaultStringFilter = CSSPlugin.colorStringFilter;
- }
- /**
- * @private Returns a formatter function that handles taking a string (or number in some cases) and returning a consistently formatted one in terms of delimiters, quantity of values, etc. For example, we may get boxShadow values defined as "0px red" or "0px 0px 10px rgb(255,0,0)" or "0px 0px 20px 20px #F00" and we need to ensure that what we get back is described with 4 numbers and a color. This allows us to feed it into the _parseComplex() method and split the values up appropriately. The neat thing about this _getFormatter() function is that the dflt defines a pattern as well as a default, so for example, _getFormatter("0px 0px 0px 0px #777", true) not only sets the default as 0px for all distances and #777 for the color, but also sets the pattern such that 4 numbers and a color will always get returned.
- * @param {!string} dflt The default value and pattern to follow. So "0px 0px 0px 0px #777" will ensure that 4 numbers and a color will always get returned.
- * @param {boolean=} clr If true, the values should be searched for color-related data. For example, boxShadow values typically contain a color whereas borderRadius don't.
- * @param {boolean=} collapsible If true, the value is a top/left/right/bottom style one that acts like margin or padding, where if only one value is received, it's used for all 4; if 2 are received, the first is duplicated for 3rd (bottom) and the 2nd is duplicated for the 4th spot (left), etc.
- * @return {Function} formatter function
- */
- var _getFormatter = function(dflt, clr, collapsible, multi) {
- if (dflt == null) {
- return function(v) {return v;};
- }
- var dColor = clr ? (dflt.match(_colorExp) || [""])[0] : "",
- dVals = dflt.split(dColor).join("").match(_valuesExp) || [],
- pfx = dflt.substr(0, dflt.indexOf(dVals[0])),
- sfx = (dflt.charAt(dflt.length - 1) === ")") ? ")" : "",
- delim = (dflt.indexOf(" ") !== -1) ? " " : ",",
- numVals = dVals.length,
- dSfx = (numVals > 0) ? dVals[0].replace(_numExp, "") : "",
- formatter;
- if (!numVals) {
- return function(v) {return v;};
- }
- if (clr) {
- formatter = function(v) {
- var color, vals, i, a;
- if (typeof(v) === "number") {
- v += dSfx;
- } else if (multi && _commasOutsideParenExp.test(v)) {
- a = v.replace(_commasOutsideParenExp, "|").split("|");
- for (i = 0; i < a.length; i++) {
- a[i] = formatter(a[i]);
- }
- return a.join(",");
- }
- color = (v.match(_colorExp) || [dColor])[0];
- vals = v.split(color).join("").match(_valuesExp) || [];
- i = vals.length;
- if (numVals > i--) {
- while (++i < numVals) {
- vals[i] = collapsible ? vals[(((i - 1) / 2) | 0)] : dVals[i];
- }
- }
- return pfx + vals.join(delim) + delim + color + sfx + (v.indexOf("inset") !== -1 ? " inset" : "");
- };
- return formatter;
- }
- formatter = function(v) {
- var vals, a, i;
- if (typeof(v) === "number") {
- v += dSfx;
- } else if (multi && _commasOutsideParenExp.test(v)) {
- a = v.replace(_commasOutsideParenExp, "|").split("|");
- for (i = 0; i < a.length; i++) {
- a[i] = formatter(a[i]);
- }
- return a.join(",");
- }
- vals = v.match(_valuesExp) || [];
- i = vals.length;
- if (numVals > i--) {
- while (++i < numVals) {
- vals[i] = collapsible ? vals[(((i - 1) / 2) | 0)] : dVals[i];
- }
- }
- return pfx + vals.join(delim) + sfx;
- };
- return formatter;
- },
- /**
- * @private returns a formatter function that's used for edge-related values like marginTop, marginLeft, paddingBottom, paddingRight, etc. Just pass a comma-delimited list of property names related to the edges.
- * @param {!string} props a comma-delimited list of property names in order from top to left, like "marginTop,marginRight,marginBottom,marginLeft"
- * @return {Function} a formatter function
- */
- _getEdgeParser = function(props) {
- props = props.split(",");
- return function(t, e, p, cssp, pt, plugin, vars) {
- var a = (e + "").split(" "),
- i;
- vars = {};
- for (i = 0; i < 4; i++) {
- vars[props[i]] = a[i] = a[i] || a[(((i - 1) / 2) >> 0)];
- }
- return cssp.parse(t, vars, pt, plugin);
- };
- },
- // @private used when other plugins must tween values first, like BezierPlugin or ThrowPropsPlugin, etc. That plugin's setRatio() gets called first so that the values are updated, and then we loop through the MiniPropTweens which handle copying the values into their appropriate slots so that they can then be applied correctly in the main CSSPlugin setRatio() method. Remember, we typically create a proxy object that has a bunch of uniquely-named properties that we feed to the sub-plugin and it does its magic normally, and then we must interpret those values and apply them to the css because often numbers must get combined/concatenated, suffixes added, etc. to work with css, like boxShadow could have 4 values plus a color.
- _setPluginRatio = _internals._setPluginRatio = function(v) {
- this.plugin.setRatio(v);
- var d = this.data,
- proxy = d.proxy,
- mpt = d.firstMPT,
- min = 0.000001,
- val, pt, i, str, p;
- while (mpt) {
- val = proxy[mpt.v];
- if (mpt.r) {
- val = Math.round(val);
- } else if (val < min && val > -min) {
- val = 0;
- }
- mpt.t[mpt.p] = val;
- mpt = mpt._next;
- }
- if (d.autoRotate) {
- d.autoRotate.rotation = d.mod ? d.mod(proxy.rotation, this.t) : proxy.rotation; //special case for ModifyPlugin to hook into an auto-rotating bezier
- }
- //at the end, we must set the CSSPropTween's "e" (end) value dynamically here because that's what is used in the final setRatio() method. Same for "b" at the beginning.
- if (v === 1 || v === 0) {
- mpt = d.firstMPT;
- p = (v === 1) ? "e" : "b";
- while (mpt) {
- pt = mpt.t;
- if (!pt.type) {
- pt[p] = pt.s + pt.xs0;
- } else if (pt.type === 1) {
- str = pt.xs0 + pt.s + pt.xs1;
- for (i = 1; i < pt.l; i++) {
- str += pt["xn"+i] + pt["xs"+(i+1)];
- }
- pt[p] = str;
- }
- mpt = mpt._next;
- }
- }
- },
- /**
- * @private @constructor Used by a few SpecialProps to hold important values for proxies. For example, _parseToProxy() creates a MiniPropTween instance for each property that must get tweened on the proxy, and we record the original property name as well as the unique one we create for the proxy, plus whether or not the value needs to be rounded plus the original value.
- * @param {!Object} t target object whose property we're tweening (often a CSSPropTween)
- * @param {!string} p property name
- * @param {(number|string|object)} v value
- * @param {MiniPropTween=} next next MiniPropTween in the linked list
- * @param {boolean=} r if true, the tweened value should be rounded to the nearest integer
- */
- MiniPropTween = function(t, p, v, next, r) {
- this.t = t;
- this.p = p;
- this.v = v;
- this.r = r;
- if (next) {
- next._prev = this;
- this._next = next;
- }
- },
- /**
- * @private Most other plugins (like BezierPlugin and ThrowPropsPlugin and others) can only tween numeric values, but CSSPlugin must accommodate special values that have a bunch of extra data (like a suffix or strings between numeric values, etc.). For example, boxShadow has values like "10px 10px 20px 30px rgb(255,0,0)" which would utterly confuse other plugins. This method allows us to split that data apart and grab only the numeric data and attach it to uniquely-named properties of a generic proxy object ({}) so that we can feed that to virtually any plugin to have the numbers tweened. However, we must also keep track of which properties from the proxy go with which CSSPropTween values and instances. So we create a linked list of MiniPropTweens. Each one records a target (the original CSSPropTween), property (like "s" or "xn1" or "xn2") that we're tweening and the unique property name that was used for the proxy (like "boxShadow_xn1" and "boxShadow_xn2") and whether or not they need to be rounded. That way, in the _setPluginRatio() method we can simply copy the values over from the proxy to the CSSPropTween instance(s). Then, when the main CSSPlugin setRatio() method runs and applies the CSSPropTween values accordingly, they're updated nicely. So the external plugin tweens the numbers, _setPluginRatio() copies them over, and setRatio() acts normally, applying css-specific values to the element.
- * This method returns an object that has the following properties:
- * - proxy: a generic object containing the starting values for all the properties that will be tweened by the external plugin. This is what we feed to the external _onInitTween() as the target
- * - end: a generic object containing the ending values for all the properties that will be tweened by the external plugin. This is what we feed to the external plugin's _onInitTween() as the destination values
- * - firstMPT: the first MiniPropTween in the linked list
- * - pt: the first CSSPropTween in the linked list that was created when parsing. If shallow is true, this linked list will NOT attach to the one passed into the _parseToProxy() as the "pt" (4th) parameter.
- * @param {!Object} t target object to be tweened
- * @param {!(Object|string)} vars the object containing the information about the tweening values (typically the end/destination values) that should be parsed
- * @param {!CSSPlugin} cssp The CSSPlugin instance
- * @param {CSSPropTween=} pt the next CSSPropTween in the linked list
- * @param {TweenPlugin=} plugin the external TweenPlugin instance that will be handling tweening the numeric values
- * @param {boolean=} shallow if true, the resulting linked list from the parse will NOT be attached to the CSSPropTween that was passed in as the "pt" (4th) parameter.
- * @return An object containing the following properties: proxy, end, firstMPT, and pt (see above for descriptions)
- */
- _parseToProxy = _internals._parseToProxy = function(t, vars, cssp, pt, plugin, shallow) {
- var bpt = pt,
- start = {},
- end = {},
- transform = cssp._transform,
- oldForce = _forcePT,
- i, p, xp, mpt, firstPT;
- cssp._transform = null;
- _forcePT = vars;
- pt = firstPT = cssp.parse(t, vars, pt, plugin);
- _forcePT = oldForce;
- //break off from the linked list so the new ones are isolated.
- if (shallow) {
- cssp._transform = transform;
- if (bpt) {
- bpt._prev = null;
- if (bpt._prev) {
- bpt._prev._next = null;
- }
- }
- }
- while (pt && pt !== bpt) {
- if (pt.type <= 1) {
- p = pt.p;
- end[p] = pt.s + pt.c;
- start[p] = pt.s;
- if (!shallow) {
- mpt = new MiniPropTween(pt, "s", p, mpt, pt.r);
- pt.c = 0;
- }
- if (pt.type === 1) {
- i = pt.l;
- while (--i > 0) {
- xp = "xn" + i;
- p = pt.p + "_" + xp;
- end[p] = pt.data[xp];
- start[p] = pt[xp];
- if (!shallow) {
- mpt = new MiniPropTween(pt, xp, p, mpt, pt.rxp[xp]);
- }
- }
- }
- }
- pt = pt._next;
- }
- return {proxy:start, end:end, firstMPT:mpt, pt:firstPT};
- },
- /**
- * @constructor Each property that is tweened has at least one CSSPropTween associated with it. These instances store important information like the target, property, starting value, amount of change, etc. They can also optionally have a number of "extra" strings and numeric values named xs1, xn1, xs2, xn2, xs3, xn3, etc. where "s" indicates string and "n" indicates number. These can be pieced together in a complex-value tween (type:1) that has alternating types of data like a string, number, string, number, etc. For example, boxShadow could be "5px 5px 8px rgb(102, 102, 51)". In that value, there are 6 numbers that may need to tween and then pieced back together into a string again with spaces, suffixes, etc. xs0 is special in that it stores the suffix for standard (type:0) tweens, -OR- the first string (prefix) in a complex-value (type:1) CSSPropTween -OR- it can be the non-tweening value in a type:-1 CSSPropTween. We do this to conserve memory.
- * CSSPropTweens have the following optional properties as well (not defined through the constructor):
- * - l: Length in terms of the number of extra properties that the CSSPropTween has (default: 0). For example, for a boxShadow we may need to tween 5 numbers in which case l would be 5; Keep in mind that the start/end values for the first number that's tweened are always stored in the s and c properties to conserve memory. All additional values thereafter are stored in xn1, xn2, etc.
- * - xfirst: The first instance of any sub-CSSPropTweens that are tweening properties of this instance. For example, we may split up a boxShadow tween so that there's a main CSSPropTween of type:1 that has various xs* and xn* values associated with the h-shadow, v-shadow, blur, color, etc. Then we spawn a CSSPropTween for each of those that has a higher priority and runs BEFORE the main CSSPropTween so that the values are all set by the time it needs to re-assemble them. The xfirst gives us an easy way to identify the first one in that chain which typically ends at the main one (because they're all prepende to the linked list)
- * - plugin: The TweenPlugin instance that will handle the tweening of any complex values. For example, sometimes we don't want to use normal subtweens (like xfirst refers to) to tween the values - we might want ThrowPropsPlugin or BezierPlugin some other plugin to do the actual tweening, so we create a plugin instance and store a reference here. We need this reference so that if we get a request to round values or disable a tween, we can pass along that request.
- * - data: Arbitrary data that needs to be stored with the CSSPropTween. Typically if we're going to have a plugin handle the tweening of a complex-value tween, we create a generic object that stores the END values that we're tweening to and the CSSPropTween's xs1, xs2, etc. have the starting values. We store that object as data. That way, we can simply pass that object to the plugin and use the CSSPropTween as the target.
- * - setRatio: Only used for type:2 tweens that require custom functionality. In this case, we call the CSSPropTween's setRatio() method and pass the ratio each time the tween updates. This isn't quite as efficient as doing things directly in the CSSPlugin's setRatio() method, but it's very convenient and flexible.
- * @param {!Object} t Target object whose property will be tweened. Often a DOM element, but not always. It could be anything.
- * @param {string} p Property to tween (name). For example, to tween element.width, p would be "width".
- * @param {number} s Starting numeric value
- * @param {number} c Change in numeric value over the course of the entire tween. For example, if element.width starts at 5 and should end at 100, c would be 95.
- * @param {CSSPropTween=} next The next CSSPropTween in the linked list. If one is defined, we will define its _prev as the new instance, and the new instance's _next will be pointed at it.
- * @param {number=} type The type of CSSPropTween where -1 = a non-tweening value, 0 = a standard simple tween, 1 = a complex value (like one that has multiple numbers in a comma- or space-delimited string like border:"1px solid red"), and 2 = one that uses a custom setRatio function that does all of the work of applying the values on each update.
- * @param {string=} n Name of the property that should be used for overwriting purposes which is typically the same as p but not always. For example, we may need to create a subtween for the 2nd part of a "clip:rect(...)" tween in which case "p" might be xs1 but "n" is still "clip"
- * @param {boolean=} r If true, the value(s) should be rounded
- * @param {number=} pr Priority in the linked list order. Higher priority CSSPropTweens will be updated before lower priority ones. The default priority is 0.
- * @param {string=} b Beginning value. We store this to ensure that it is EXACTLY what it was when the tween began without any risk of interpretation issues.
- * @param {string=} e Ending value. We store this to ensure that it is EXACTLY what the user defined at the end of the tween without any risk of interpretation issues.
- */
- CSSPropTween = _internals.CSSPropTween = function(t, p, s, c, next, type, n, r, pr, b, e) {
- this.t = t; //target
- this.p = p; //property
- this.s = s; //starting value
- this.c = c; //change value
- this.n = n || p; //name that this CSSPropTween should be associated to (usually the same as p, but not always - n is what overwriting looks at)
- if (!(t instanceof CSSPropTween)) {
- _overwriteProps.push(this.n);
- }
- this.r = r; //round (boolean)
- this.type = type || 0; //0 = normal tween, -1 = non-tweening (in which case xs0 will be applied to the target's property, like tp.t[tp.p] = tp.xs0), 1 = complex-value SpecialProp, 2 = custom setRatio() that does all the work
- if (pr) {
- this.pr = pr;
- _hasPriority = true;
- }
- this.b = (b === undefined) ? s : b;
- this.e = (e === undefined) ? s + c : e;
- if (next) {
- this._next = next;
- next._prev = this;
- }
- },
- _addNonTweeningNumericPT = function(target, prop, start, end, next, overwriteProp) { //cleans up some code redundancies and helps minification. Just a fast way to add a NUMERIC non-tweening CSSPropTween
- var pt = new CSSPropTween(target, prop, start, end - start, next, -1, overwriteProp);
- pt.b = start;
- pt.e = pt.xs0 = end;
- return pt;
- },
- /**
- * Takes a target, the beginning value and ending value (as strings) and parses them into a CSSPropTween (possibly with child CSSPropTweens) that accommodates multiple numbers, colors, comma-delimited values, etc. For example:
- * sp.parseComplex(element, "boxShadow", "5px 10px 20px rgb(255,102,51)", "0px 0px 0px red", true, "0px 0px 0px rgb(0,0,0,0)", pt);
- * It will walk through the beginning and ending values (which should be in the same format with the same number and type of values) and figure out which parts are numbers, what strings separate the numeric/tweenable values, and then create the CSSPropTweens accordingly. If a plugin is defined, no child CSSPropTweens will be created. Instead, the ending values will be stored in the "data" property of the returned CSSPropTween like: {s:-5, xn1:-10, xn2:-20, xn3:255, xn4:0, xn5:0} so that it can be fed to any other plugin and it'll be plain numeric tweens but the recomposition of the complex value will be handled inside CSSPlugin's setRatio().
- * If a setRatio is defined, the type of the CSSPropTween will be set to 2 and recomposition of the values will be the responsibility of that method.
- *
- * @param {!Object} t Target whose property will be tweened
- * @param {!string} p Property that will be tweened (its name, like "left" or "backgroundColor" or "boxShadow")
- * @param {string} b Beginning value
- * @param {string} e Ending value
- * @param {boolean} clrs If true, the value could contain a color value like "rgb(255,0,0)" or "#F00" or "red". The default is false, so no colors will be recognized (a performance optimization)
- * @param {(string|number|Object)} dflt The default beginning value that should be used if no valid beginning value is defined or if the number of values inside the complex beginning and ending values don't match
- * @param {?CSSPropTween} pt CSSPropTween instance that is the current head of the linked list (we'll prepend to this).
- * @param {number=} pr Priority in the linked list order. Higher priority properties will be updated before lower priority ones. The default priority is 0.
- * @param {TweenPlugin=} plugin If a plugin should handle the tweening of extra properties, pass the plugin instance here. If one is defined, then NO subtweens will be created for any extra properties (the properties will be created - just not additional CSSPropTween instances to tween them) because the plugin is expected to do so. However, the end values WILL be populated in the "data" property, like {s:100, xn1:50, xn2:300}
- * @param {function(number)=} setRatio If values should be set in a custom function instead of being pieced together in a type:1 (complex-value) CSSPropTween, define that custom function here.
- * @return {CSSPropTween} The first CSSPropTween in the linked list which includes the new one(s) added by the parseComplex() call.
- */
- _parseComplex = CSSPlugin.parseComplex = function(t, p, b, e, clrs, dflt, pt, pr, plugin, setRatio) {
- //DEBUG: _log("parseComplex: "+p+", b: "+b+", e: "+e);
- b = b || dflt || "";
- if (typeof(e) === "function") {
- e = e(_index, _target);
- }
- pt = new CSSPropTween(t, p, 0, 0, pt, (setRatio ? 2 : 1), null, false, pr, b, e);
- e += ""; //ensures it's a string
- if (clrs && _colorExp.test(e + b)) { //if colors are found, normalize the formatting to rgba() or hsla().
- e = [b, e];
- CSSPlugin.colorStringFilter(e);
- b = e[0];
- e = e[1];
- }
- var ba = b.split(", ").join(",").split(" "), //beginning array
- ea = e.split(", ").join(",").split(" "), //ending array
- l = ba.length,
- autoRound = (_autoRound !== false),
- i, xi, ni, bv, ev, bnums, enums, bn, hasAlpha, temp, cv, str, useHSL;
- if (e.indexOf(",") !== -1 || b.indexOf(",") !== -1) {
- ba = ba.join(" ").replace(_commasOutsideParenExp, ", ").split(" ");
- ea = ea.join(" ").replace(_commasOutsideParenExp, ", ").split(" ");
- l = ba.length;
- }
- if (l !== ea.length) {
- //DEBUG: _log("mismatched formatting detected on " + p + " (" + b + " vs " + e + ")");
- ba = (dflt || "").split(" ");
- l = ba.length;
- }
- pt.plugin = plugin;
- pt.setRatio = setRatio;
- _colorExp.lastIndex = 0;
- for (i = 0; i < l; i++) {
- bv = ba[i];
- ev = ea[i];
- bn = parseFloat(bv);
- //if the value begins with a number (most common). It's fine if it has a suffix like px
- if (bn || bn === 0) {
- pt.appendXtra("", bn, _parseChange(ev, bn), ev.replace(_relNumExp, ""), (autoRound && ev.indexOf("px") !== -1), true);
- //if the value is a color
- } else if (clrs && _colorExp.test(bv)) {
- str = ev.indexOf(")") + 1;
- str = ")" + (str ? ev.substr(str) : ""); //if there's a comma or ) at the end, retain it.
- useHSL = (ev.indexOf("hsl") !== -1 && _supportsOpacity);
- temp = ev; //original string value so we can look for any prefix later.
- bv = _parseColor(bv, useHSL);
- ev = _parseColor(ev, useHSL);
- hasAlpha = (bv.length + ev.length > 6);
- if (hasAlpha && !_supportsOpacity && ev[3] === 0) { //older versions of IE don't support rgba(), so if the destination alpha is 0, just use "transparent" for the end color
- pt["xs" + pt.l] += pt.l ? " transparent" : "transparent";
- pt.e = pt.e.split(ea[i]).join("transparent");
- } else {
- if (!_supportsOpacity) { //old versions of IE don't support rgba().
- hasAlpha = false;
- }
- if (useHSL) {
- pt.appendXtra(temp.substr(0, temp.indexOf("hsl")) + (hasAlpha ? "hsla(" : "hsl("), bv[0], _parseChange(ev[0], bv[0]), ",", false, true)
- .appendXtra("", bv[1], _parseChange(ev[1], bv[1]), "%,", false)
- .appendXtra("", bv[2], _parseChange(ev[2], bv[2]), (hasAlpha ? "%," : "%" + str), false);
- } else {
- pt.appendXtra(temp.substr(0, temp.indexOf("rgb")) + (hasAlpha ? "rgba(" : "rgb("), bv[0], ev[0] - bv[0], ",", true, true)
- .appendXtra("", bv[1], ev[1] - bv[1], ",", true)
- .appendXtra("", bv[2], ev[2] - bv[2], (hasAlpha ? "," : str), true);
- }
- if (hasAlpha) {
- bv = (bv.length < 4) ? 1 : bv[3];
- pt.appendXtra("", bv, ((ev.length < 4) ? 1 : ev[3]) - bv, str, false);
- }
- }
- _colorExp.lastIndex = 0; //otherwise the test() on the RegExp could move the lastIndex and taint future results.
- } else {
- bnums = bv.match(_numExp); //gets each group of numbers in the beginning value string and drops them into an array
- //if no number is found, treat it as a non-tweening value and just append the string to the current xs.
- if (!bnums) {
- pt["xs" + pt.l] += (pt.l || pt["xs" + pt.l]) ? " " + ev : ev;
- //loop through all the numbers that are found and construct the extra values on the pt.
- } else {
- enums = ev.match(_relNumExp); //get each group of numbers in the end value string and drop them into an array. We allow relative values too, like +=50 or -=.5
- if (!enums || enums.length !== bnums.length) {
- //DEBUG: _log("mismatched formatting detected on " + p + " (" + b + " vs " + e + ")");
- return pt;
- }
- ni = 0;
- for (xi = 0; xi < bnums.length; xi++) {
- cv = bnums[xi];
- temp = bv.indexOf(cv, ni);
- pt.appendXtra(bv.substr(ni, temp - ni), Number(cv), _parseChange(enums[xi], cv), "", (autoRound && bv.substr(temp + cv.length, 2) === "px"), (xi === 0));
- ni = temp + cv.length;
- }
- pt["xs" + pt.l] += bv.substr(ni);
- }
- }
- }
- //if there are relative values ("+=" or "-=" prefix), we need to adjust the ending value to eliminate the prefixes and combine the values properly.
- if (e.indexOf("=") !== -1) if (pt.data) {
- str = pt.xs0 + pt.data.s;
- for (i = 1; i < pt.l; i++) {
- str += pt["xs" + i] + pt.data["xn" + i];
- }
- pt.e = str + pt["xs" + i];
- }
- if (!pt.l) {
- pt.type = -1;
- pt.xs0 = pt.e;
- }
- return pt.xfirst || pt;
- },
- i = 9;
- p = CSSPropTween.prototype;
- p.l = p.pr = 0; //length (number of extra properties like xn1, xn2, xn3, etc.
- while (--i > 0) {
- p["xn" + i] = 0;
- p["xs" + i] = "";
- }
- p.xs0 = "";
- p._next = p._prev = p.xfirst = p.data = p.plugin = p.setRatio = p.rxp = null;
- /**
- * Appends and extra tweening value to a CSSPropTween and automatically manages any prefix and suffix strings. The first extra value is stored in the s and c of the main CSSPropTween instance, but thereafter any extras are stored in the xn1, xn2, xn3, etc. The prefixes and suffixes are stored in the xs0, xs1, xs2, etc. properties. For example, if I walk through a clip value like "rect(10px, 5px, 0px, 20px)", the values would be stored like this:
- * xs0:"rect(", s:10, xs1:"px, ", xn1:5, xs2:"px, ", xn2:0, xs3:"px, ", xn3:20, xn4:"px)"
- * And they'd all get joined together when the CSSPlugin renders (in the setRatio() method).
- * @param {string=} pfx Prefix (if any)
- * @param {!number} s Starting value
- * @param {!number} c Change in numeric value over the course of the entire tween. For example, if the start is 5 and the end is 100, the change would be 95.
- * @param {string=} sfx Suffix (if any)
- * @param {boolean=} r Round (if true).
- * @param {boolean=} pad If true, this extra value should be separated by the previous one by a space. If there is no previous extra and pad is true, it will automatically drop the space.
- * @return {CSSPropTween} returns itself so that multiple methods can be chained together.
- */
- p.appendXtra = function(pfx, s, c, sfx, r, pad) {
- var pt = this,
- l = pt.l;
- pt["xs" + l] += (pad && (l || pt["xs" + l])) ? " " + pfx : pfx || "";
- if (!c) if (l !== 0 && !pt.plugin) { //typically we'll combine non-changing values right into the xs to optimize performance, but we don't combine them when there's a plugin that will be tweening the values because it may depend on the values being split apart, like for a bezier, if a value doesn't change between the first and second iteration but then it does on the 3rd, we'll run into trouble because there's no xn slot for that value!
- pt["xs" + l] += s + (sfx || "");
- return pt;
- }
- pt.l++;
- pt.type = pt.setRatio ? 2 : 1;
- pt["xs" + pt.l] = sfx || "";
- if (l > 0) {
- pt.data["xn" + l] = s + c;
- pt.rxp["xn" + l] = r; //round extra property (we need to tap into this in the _parseToProxy() method)
- pt["xn" + l] = s;
- if (!pt.plugin) {
- pt.xfirst = new CSSPropTween(pt, "xn" + l, s, c, pt.xfirst || pt, 0, pt.n, r, pt.pr);
- pt.xfirst.xs0 = 0; //just to ensure that the property stays numeric which helps modern browsers speed up processing. Remember, in the setRatio() method, we do pt.t[pt.p] = val + pt.xs0 so if pt.xs0 is "" (the default), it'll cast the end value as a string. When a property is a number sometimes and a string sometimes, it prevents the compiler from locking in the data type, slowing things down slightly.
- }
- return pt;
- }
- pt.data = {s:s + c};
- pt.rxp = {};
- pt.s = s;
- pt.c = c;
- pt.r = r;
- return pt;
- };
- /**
- * @constructor A SpecialProp is basically a css property that needs to be treated in a non-standard way, like if it may contain a complex value like boxShadow:"5px 10px 15px rgb(255, 102, 51)" or if it is associated with another plugin like ThrowPropsPlugin or BezierPlugin. Every SpecialProp is associated with a particular property name like "boxShadow" or "throwProps" or "bezier" and it will intercept those values in the vars object that's passed to the CSSPlugin and handle them accordingly.
- * @param {!string} p Property name (like "boxShadow" or "throwProps")
- * @param {Object=} options An object containing any of the following configuration options:
- * - defaultValue: the default value
- * - parser: A function that should be called when the associated property name is found in the vars. This function should return a CSSPropTween instance and it should ensure that it is properly inserted into the linked list. It will receive 4 paramters: 1) The target, 2) The value defined in the vars, 3) The CSSPlugin instance (whose _firstPT should be used for the linked list), and 4) A computed style object if one was calculated (this is a speed optimization that allows retrieval of starting values quicker)
- * - formatter: a function that formats any value received for this special property (for example, boxShadow could take "5px 5px red" and format it to "5px 5px 0px 0px red" so that both the beginning and ending values have a common order and quantity of values.)
- * - prefix: if true, we'll determine whether or not this property requires a vendor prefix (like Webkit or Moz or ms or O)
- * - color: set this to true if the value for this SpecialProp may contain color-related values like rgb(), rgba(), etc.
- * - priority: priority in the linked list order. Higher priority SpecialProps will be updated before lower priority ones. The default priority is 0.
- * - multi: if true, the formatter should accommodate a comma-delimited list of values, like boxShadow could have multiple boxShadows listed out.
- * - collapsible: if true, the formatter should treat the value like it's a top/right/bottom/left value that could be collapsed, like "5px" would apply to all, "5px, 10px" would use 5px for top/bottom and 10px for right/left, etc.
- * - keyword: a special keyword that can [optionally] be found inside the value (like "inset" for boxShadow). This allows us to validate beginning/ending values to make sure they match (if the keyword is found in one, it'll be added to the other for consistency by default).
- */
- var SpecialProp = function(p, options) {
- options = options || {};
- this.p = options.prefix ? _checkPropPrefix(p) || p : p;
- _specialProps[p] = _specialProps[this.p] = this;
- this.format = options.formatter || _getFormatter(options.defaultValue, options.color, options.collapsible, options.multi);
- if (options.parser) {
- this.parse = options.parser;
- }
- this.clrs = options.color;
- this.multi = options.multi;
- this.keyword = options.keyword;
- this.dflt = options.defaultValue;
- this.pr = options.priority || 0;
- },
- //shortcut for creating a new SpecialProp that can accept multiple properties as a comma-delimited list (helps minification). dflt can be an array for multiple values (we don't do a comma-delimited list because the default value may contain commas, like rect(0px,0px,0px,0px)). We attach this method to the SpecialProp class/object instead of using a private _createSpecialProp() method so that we can tap into it externally if necessary, like from another plugin.
- _registerComplexSpecialProp = _internals._registerComplexSpecialProp = function(p, options, defaults) {
- if (typeof(options) !== "object") {
- options = {parser:defaults}; //to make backwards compatible with older versions of BezierPlugin and ThrowPropsPlugin
- }
- var a = p.split(","),
- d = options.defaultValue,
- i, temp;
- defaults = defaults || [d];
- for (i = 0; i < a.length; i++) {
- options.prefix = (i === 0 && options.prefix);
- options.defaultValue = defaults[i] || d;
- temp = new SpecialProp(a[i], options);
- }
- },
- //creates a placeholder special prop for a plugin so that the property gets caught the first time a tween of it is attempted, and at that time it makes the plugin register itself, thus taking over for all future tweens of that property. This allows us to not mandate that things load in a particular order and it also allows us to log() an error that informs the user when they attempt to tween an external plugin-related property without loading its .js file.
- _registerPluginProp = _internals._registerPluginProp = function(p) {
- if (!_specialProps[p]) {
- var pluginName = p.charAt(0).toUpperCase() + p.substr(1) + "Plugin";
- _registerComplexSpecialProp(p, {parser:function(t, e, p, cssp, pt, plugin, vars) {
- var pluginClass = _globals.com.greensock.plugins[pluginName];
- if (!pluginClass) {
- _log("Error: " + pluginName + " js file not loaded.");
- return pt;
- }
- pluginClass._cssRegister();
- return _specialProps[p].parse(t, e, p, cssp, pt, plugin, vars);
- }});
- }
- };
- p = SpecialProp.prototype;
- /**
- * Alias for _parseComplex() that automatically plugs in certain values for this SpecialProp, like its property name, whether or not colors should be sensed, the default value, and priority. It also looks for any keyword that the SpecialProp defines (like "inset" for boxShadow) and ensures that the beginning and ending values have the same number of values for SpecialProps where multi is true (like boxShadow and textShadow can have a comma-delimited list)
- * @param {!Object} t target element
- * @param {(string|number|object)} b beginning value
- * @param {(string|number|object)} e ending (destination) value
- * @param {CSSPropTween=} pt next CSSPropTween in the linked list
- * @param {TweenPlugin=} plugin If another plugin will be tweening the complex value, that TweenPlugin instance goes here.
- * @param {function=} setRatio If a custom setRatio() method should be used to handle this complex value, that goes here.
- * @return {CSSPropTween=} First CSSPropTween in the linked list
- */
- p.parseComplex = function(t, b, e, pt, plugin, setRatio) {
- var kwd = this.keyword,
- i, ba, ea, l, bi, ei;
- //if this SpecialProp's value can contain a comma-delimited list of values (like boxShadow or textShadow), we must parse them in a special way, and look for a keyword (like "inset" for boxShadow) and ensure that the beginning and ending BOTH have it if the end defines it as such. We also must ensure that there are an equal number of values specified (we can't tween 1 boxShadow to 3 for example)
- if (this.multi) if (_commasOutsideParenExp.test(e) || _commasOutsideParenExp.test(b)) {
- ba = b.replace(_commasOutsideParenExp, "|").split("|");
- ea = e.replace(_commasOutsideParenExp, "|").split("|");
- } else if (kwd) {
- ba = [b];
- ea = [e];
- }
- if (ea) {
- l = (ea.length > ba.length) ? ea.length : ba.length;
- for (i = 0; i < l; i++) {
- b = ba[i] = ba[i] || this.dflt;
- e = ea[i] = ea[i] || this.dflt;
- if (kwd) {
- bi = b.indexOf(kwd);
- ei = e.indexOf(kwd);
- if (bi !== ei) {
- if (ei === -1) { //if the keyword isn't in the end value, remove it from the beginning one.
- ba[i] = ba[i].split(kwd).join("");
- } else if (bi === -1) { //if the keyword isn't in the beginning, add it.
- ba[i] += " " + kwd;
- }
- }
- }
- }
- b = ba.join(", ");
- e = ea.join(", ");
- }
- return _parseComplex(t, this.p, b, e, this.clrs, this.dflt, pt, this.pr, plugin, setRatio);
- };
- /**
- * Accepts a target and end value and spits back a CSSPropTween that has been inserted into the CSSPlugin's linked list and conforms with all the conventions we use internally, like type:-1, 0, 1, or 2, setting up any extra property tweens, priority, etc. For example, if we have a boxShadow SpecialProp and call:
- * this._firstPT = sp.parse(element, "5px 10px 20px rgb(2550,102,51)", "boxShadow", this);
- * It should figure out the starting value of the element's boxShadow, compare it to the provided end value and create all the necessary CSSPropTweens of the appropriate types to tween the boxShadow. The CSSPropTween that gets spit back should already be inserted into the linked list (the 4th parameter is the current head, so prepend to that).
- * @param {!Object} t Target object whose property is being tweened
- * @param {Object} e End value as provided in the vars object (typically a string, but not always - like a throwProps would be an object).
- * @param {!string} p Property name
- * @param {!CSSPlugin} cssp The CSSPlugin instance that should be associated with this tween.
- * @param {?CSSPropTween} pt The CSSPropTween that is the current head of the linked list (we'll prepend to it)
- * @param {TweenPlugin=} plugin If a plugin will be used to tween the parsed value, this is the plugin instance.
- * @param {Object=} vars Original vars object that contains the data for parsing.
- * @return {CSSPropTween} The first CSSPropTween in the linked list which includes the new one(s) added by the parse() call.
- */
- p.parse = function(t, e, p, cssp, pt, plugin, vars) {
- return this.parseComplex(t.style, this.format(_getStyle(t, this.p, _cs, false, this.dflt)), this.format(e), pt, plugin);
- };
- /**
- * Registers a special property that should be intercepted from any "css" objects defined in tweens. This allows you to handle them however you want without CSSPlugin doing it for you. The 2nd parameter should be a function that accepts 3 parameters:
- * 1) Target object whose property should be tweened (typically a DOM element)
- * 2) The end/destination value (could be a string, number, object, or whatever you want)
- * 3) The tween instance (you probably don't need to worry about this, but it can be useful for looking up information like the duration)
- *
- * Then, your function should return a function which will be called each time the tween gets rendered, passing a numeric "ratio" parameter to your function that indicates the change factor (usually between 0 and 1). For example:
- *
- * CSSPlugin.registerSpecialProp("myCustomProp", function(target, value, tween) {
- * var start = target.style.width;
- * return function(ratio) {
- * target.style.width = (start + value * ratio) + "px";
- * console.log("set width to " + target.style.width);
- * }
- * }, 0);
- *
- * Then, when I do this tween, it will trigger my special property:
- *
- * TweenLite.to(element, 1, {css:{myCustomProp:100}});
- *
- * In the example, of course, we're just changing the width, but you can do anything you want.
- *
- * @param {!string} name Property name (or comma-delimited list of property names) that should be intercepted and handled by your function. For example, if I define "myCustomProp", then it would handle that portion of the following tween: TweenLite.to(element, 1, {css:{myCustomProp:100}})
- * @param {!function(Object, Object, Object, string):function(number)} onInitTween The function that will be called when a tween of this special property is performed. The function will receive 4 parameters: 1) Target object that should be tweened, 2) Value that was passed to the tween, 3) The tween instance itself (rarely used), and 4) The property name that's being tweened. Your function should return a function that should be called on every update of the tween. That function will receive a single parameter that is a "change factor" value (typically between 0 and 1) indicating the amount of change as a ratio. You can use this to determine how to set the values appropriately in your function.
- * @param {number=} priority Priority that helps the engine determine the order in which to set the properties (default: 0). Higher priority properties will be updated before lower priority ones.
- */
- CSSPlugin.registerSpecialProp = function(name, onInitTween, priority) {
- _registerComplexSpecialProp(name, {parser:function(t, e, p, cssp, pt, plugin, vars) {
- var rv = new CSSPropTween(t, p, 0, 0, pt, 2, p, false, priority);
- rv.plugin = plugin;
- rv.setRatio = onInitTween(t, e, cssp._tween, p);
- return rv;
- }, priority:priority});
- };
- //transform-related methods and properties
- CSSPlugin.useSVGTransformAttr = true; //Safari and Firefox both have some rendering bugs when applying CSS transforms to SVG elements, so default to using the "transform" attribute instead (users can override this).
- var _transformProps = ("scaleX,scaleY,scaleZ,x,y,z,skewX,skewY,rotation,rotationX,rotationY,perspective,xPercent,yPercent").split(","),
- _transformProp = _checkPropPrefix("transform"), //the Javascript (camelCase) transform property, like msTransform, WebkitTransform, MozTransform, or OTransform.
- _transformPropCSS = _prefixCSS + "transform",
- _transformOriginProp = _checkPropPrefix("transformOrigin"),
- _supports3D = (_checkPropPrefix("perspective") !== null),
- Transform = _internals.Transform = function() {
- this.perspective = parseFloat(CSSPlugin.defaultTransformPerspective) || 0;
- this.force3D = (CSSPlugin.defaultForce3D === false || !_supports3D) ? false : CSSPlugin.defaultForce3D || "auto";
- },
- _SVGElement = _gsScope.SVGElement,
- _useSVGTransformAttr,
- //Some browsers (like Firefox and IE) don't honor transform-origin properly in SVG elements, so we need to manually adjust the matrix accordingly. We feature detect here rather than always doing the conversion for certain browsers because they may fix the problem at some point in the future.
- _createSVG = function(type, container, attributes) {
- var element = _doc.createElementNS("http://www.w3.org/2000/svg", type),
- reg = /([a-z])([A-Z])/g,
- p;
- for (p in attributes) {
- element.setAttributeNS(null, p.replace(reg, "$1-$2").toLowerCase(), attributes[p]);
- }
- container.appendChild(element);
- return element;
- },
- _docElement = _doc.documentElement || {},
- _forceSVGTransformAttr = (function() {
- //IE and Android stock don't support CSS transforms on SVG elements, so we must write them to the "transform" attribute. We populate this variable in the _parseTransform() method, and only if/when we come across an SVG element
- var force = _ieVers || (/Android/i.test(_agent) && !_gsScope.chrome),
- svg, rect, width;
- if (_doc.createElementNS && !force) { //IE8 and earlier doesn't support SVG anyway
- svg = _createSVG("svg", _docElement);
- rect = _createSVG("rect", svg, {width:100, height:50, x:100});
- width = rect.getBoundingClientRect().width;
- rect.style[_transformOriginProp] = "50% 50%";
- rect.style[_transformProp] = "scaleX(0.5)";
- force = (width === rect.getBoundingClientRect().width && !(_isFirefox && _supports3D)); //note: Firefox fails the test even though it does support CSS transforms in 3D. Since we can't push 3D stuff into the transform attribute, we force Firefox to pass the test here (as long as it does truly support 3D).
- _docElement.removeChild(svg);
- }
- return force;
- })(),
- _parseSVGOrigin = function(e, local, decoratee, absolute, smoothOrigin, skipRecord) {
- var tm = e._gsTransform,
- m = _getMatrix(e, true),
- v, x, y, xOrigin, yOrigin, a, b, c, d, tx, ty, determinant, xOriginOld, yOriginOld;
- if (tm) {
- xOriginOld = tm.xOrigin; //record the original values before we alter them.
- yOriginOld = tm.yOrigin;
- }
- if (!absolute || (v = absolute.split(" ")).length < 2) {
- b = e.getBBox();
- if (b.x === 0 && b.y === 0 && b.width + b.height === 0) { //some browsers (like Firefox) misreport the bounds if the element has zero width and height (it just assumes it's at x:0, y:0), thus we need to manually grab the position in that case.
- b = {x: parseFloat(e.hasAttribute("x") ? e.getAttribute("x") : e.hasAttribute("cx") ? e.getAttribute("cx") : 0) || 0, y: parseFloat(e.hasAttribute("y") ? e.getAttribute("y") : e.hasAttribute("cy") ? e.getAttribute("cy") : 0) || 0, width:0, height:0};
- }
- local = _parsePosition(local).split(" ");
- v = [(local[0].indexOf("%") !== -1 ? parseFloat(local[0]) / 100 * b.width : parseFloat(local[0])) + b.x,
- (local[1].indexOf("%") !== -1 ? parseFloat(local[1]) / 100 * b.height : parseFloat(local[1])) + b.y];
- }
- decoratee.xOrigin = xOrigin = parseFloat(v[0]);
- decoratee.yOrigin = yOrigin = parseFloat(v[1]);
- if (absolute && m !== _identity2DMatrix) { //if svgOrigin is being set, we must invert the matrix and determine where the absolute point is, factoring in the current transforms. Otherwise, the svgOrigin would be based on the element's non-transformed position on the canvas.
- a = m[0];
- b = m[1];
- c = m[2];
- d = m[3];
- tx = m[4];
- ty = m[5];
- determinant = (a * d - b * c);
- if (determinant) { //if it's zero (like if scaleX and scaleY are zero), skip it to avoid errors with dividing by zero.
- x = xOrigin * (d / determinant) + yOrigin * (-c / determinant) + ((c * ty - d * tx) / determinant);
- y = xOrigin * (-b / determinant) + yOrigin * (a / determinant) - ((a * ty - b * tx) / determinant);
- xOrigin = decoratee.xOrigin = v[0] = x;
- yOrigin = decoratee.yOrigin = v[1] = y;
- }
- }
- if (tm) { //avoid jump when transformOrigin is changed - adjust the x/y values accordingly
- if (skipRecord) {
- decoratee.xOffset = tm.xOffset;
- decoratee.yOffset = tm.yOffset;
- tm = decoratee;
- }
- if (smoothOrigin || (smoothOrigin !== false && CSSPlugin.defaultSmoothOrigin !== false)) {
- x = xOrigin - xOriginOld;
- y = yOrigin - yOriginOld;
- //originally, we simply adjusted the x and y values, but that would cause problems if, for example, you created a rotational tween part-way through an x/y tween. Managing the offset in a separate variable gives us ultimate flexibility.
- //tm.x -= x - (x * m[0] + y * m[2]);
- //tm.y -= y - (x * m[1] + y * m[3]);
- tm.xOffset += (x * m[0] + y * m[2]) - x;
- tm.yOffset += (x * m[1] + y * m[3]) - y;
- } else {
- tm.xOffset = tm.yOffset = 0;
- }
- }
- if (!skipRecord) {
- e.setAttribute("data-svg-origin", v.join(" "));
- }
- },
- _getBBoxHack = function(swapIfPossible) { //works around issues in some browsers (like Firefox) that don't correctly report getBBox() on SVG elements inside a <defs> element and/or <mask>. We try creating an SVG, adding it to the documentElement and toss the element in there so that it's definitely part of the rendering tree, then grab the bbox and if it works, we actually swap out the original getBBox() method for our own that does these extra steps whenever getBBox is needed. This helps ensure that performance is optimal (only do all these extra steps when absolutely necessary...most elements don't need it).
- var svg = _createElement("svg", this.ownerSVGElement.getAttribute("xmlns") || "http://www.w3.org/2000/svg"),
- oldParent = this.parentNode,
- oldSibling = this.nextSibling,
- oldCSS = this.style.cssText,
- bbox;
- _docElement.appendChild(svg);
- svg.appendChild(this);
- this.style.display = "block";
- if (swapIfPossible) {
- try {
- bbox = this.getBBox();
- this._originalGetBBox = this.getBBox;
- this.getBBox = _getBBoxHack;
- } catch (e) { }
- } else if (this._originalGetBBox) {
- bbox = this._originalGetBBox();
- }
- if (oldSibling) {
- oldParent.insertBefore(this, oldSibling);
- } else {
- oldParent.appendChild(this);
- }
- _docElement.removeChild(svg);
- this.style.cssText = oldCSS;
- return bbox;
- },
- _getBBox = function(e) {
- try {
- return e.getBBox(); //Firefox throws errors if you try calling getBBox() on an SVG element that's not rendered (like in a <symbol> or <defs>). https://bugzilla.mozilla.org/show_bug.cgi?id=612118
- } catch (error) {
- return _getBBoxHack.call(e, true);
- }
- },
- _isSVG = function(e) { //reports if the element is an SVG on which getBBox() actually works
- return !!(_SVGElement && e.getCTM && _getBBox(e) && (!e.parentNode || e.ownerSVGElement));
- },
- _identity2DMatrix = [1,0,0,1,0,0],
- _getMatrix = function(e, force2D) {
- var tm = e._gsTransform || new Transform(),
- rnd = 100000,
- style = e.style,
- isDefault, s, m, n, dec, none;
- if (_transformProp) {
- s = _getStyle(e, _transformPropCSS, null, true);
- } else if (e.currentStyle) {
- //for older versions of IE, we need to interpret the filter portion that is in the format: progid:DXImageTransform.Microsoft.Matrix(M11=6.123233995736766e-17, M12=-1, M21=1, M22=6.123233995736766e-17, sizingMethod='auto expand') Notice that we need to swap b and c compared to a normal matrix.
- s = e.currentStyle.filter.match(_ieGetMatrixExp);
- s = (s && s.length === 4) ? [s[0].substr(4), Number(s[2].substr(4)), Number(s[1].substr(4)), s[3].substr(4), (tm.x || 0), (tm.y || 0)].join(",") : "";
- }
- isDefault = (!s || s === "none" || s === "matrix(1, 0, 0, 1, 0, 0)");
- if (_transformProp && ((none = (_getComputedStyle(e).display === "none")) || !e.parentNode)) {
- if (none) { //browsers don't report transforms accurately unless the element is in the DOM and has a display value that's not "none". Firefox and Microsoft browsers have a partial bug where they'll report transforms even if display:none BUT not any percentage-based values like translate(-50%, 8px) will be reported as if it's translate(0, 8px).
- n = style.display;
- style.display = "block";
- }
- if (!e.parentNode) {
- dec = 1; //flag
- _docElement.appendChild(e);
- }
- s = _getStyle(e, _transformPropCSS, null, true);
- isDefault = (!s || s === "none" || s === "matrix(1, 0, 0, 1, 0, 0)");
- if (n) {
- style.display = n;
- } else if (none) {
- _removeProp(style, "display");
- }
- if (dec) {
- _docElement.removeChild(e);
- }
- }
- if (tm.svg || (e.getCTM && _isSVG(e))) {
- if (isDefault && (style[_transformProp] + "").indexOf("matrix") !== -1) { //some browsers (like Chrome 40) don't correctly report transforms that are applied inline on an SVG element (they don't get included in the computed style), so we double-check here and accept matrix values
- s = style[_transformProp];
- isDefault = 0;
- }
- m = e.getAttribute("transform");
- if (isDefault && m) {
- if (m.indexOf("matrix") !== -1) { //just in case there's a "transform" value specified as an attribute instead of CSS style. Accept either a matrix() or simple translate() value though.
- s = m;
- isDefault = 0;
- } else if (m.indexOf("translate") !== -1) {
- s = "matrix(1,0,0,1," + m.match(/(?:\-|\b)[\d\-\.e]+\b/gi).join(",") + ")";
- isDefault = 0;
- }
- }
- }
- if (isDefault) {
- return _identity2DMatrix;
- }
- //split the matrix values out into an array (m for matrix)
- m = (s || "").match(_numExp) || [];
- i = m.length;
- while (--i > -1) {
- n = Number(m[i]);
- m[i] = (dec = n - (n |= 0)) ? ((dec * rnd + (dec < 0 ? -0.5 : 0.5)) | 0) / rnd + n : n; //convert strings to Numbers and round to 5 decimal places to avoid issues with tiny numbers. Roughly 20x faster than Number.toFixed(). We also must make sure to round before dividing so that values like 0.9999999999 become 1 to avoid glitches in browser rendering and interpretation of flipped/rotated 3D matrices. And don't just multiply the number by rnd, floor it, and then divide by rnd because the bitwise operations max out at a 32-bit signed integer, thus it could get clipped at a relatively low value (like 22,000.00000 for example).
- }
- return (force2D && m.length > 6) ? [m[0], m[1], m[4], m[5], m[12], m[13]] : m;
- },
- /**
- * Parses the transform values for an element, returning an object with x, y, z, scaleX, scaleY, scaleZ, rotation, rotationX, rotationY, skewX, and skewY properties. Note: by default (for performance reasons), all skewing is combined into skewX and rotation but skewY still has a place in the transform object so that we can record how much of the skew is attributed to skewX vs skewY. Remember, a skewY of 10 looks the same as a rotation of 10 and skewX of -10.
- * @param {!Object} t target element
- * @param {Object=} cs computed style object (optional)
- * @param {boolean=} rec if true, the transform values will be recorded to the target element's _gsTransform object, like target._gsTransform = {x:0, y:0, z:0, scaleX:1...}
- * @param {boolean=} parse if true, we'll ignore any _gsTransform values that already exist on the element, and force a reparsing of the css (calculated style)
- * @return {object} object containing all of the transform properties/values like {x:0, y:0, z:0, scaleX:1...}
- */
- _getTransform = _internals.getTransform = function(t, cs, rec, parse) {
- if (t._gsTransform && rec && !parse) {
- return t._gsTransform; //if the element already has a _gsTransform, use that. Note: some browsers don't accurately return the calculated style for the transform (particularly for SVG), so it's almost always safest to just use the values we've already applied rather than re-parsing things.
- }
- var tm = rec ? t._gsTransform || new Transform() : new Transform(),
- invX = (tm.scaleX < 0), //in order to interpret things properly, we need to know if the user applied a negative scaleX previously so that we can adjust the rotation and skewX accordingly. Otherwise, if we always interpret a flipped matrix as affecting scaleY and the user only wants to tween the scaleX on multiple sequential tweens, it would keep the negative scaleY without that being the user's intent.
- min = 0.00002,
- rnd = 100000,
- zOrigin = _supports3D ? parseFloat(_getStyle(t, _transformOriginProp, cs, false, "0 0 0").split(" ")[2]) || tm.zOrigin || 0 : 0,
- defaultTransformPerspective = parseFloat(CSSPlugin.defaultTransformPerspective) || 0,
- m, i, scaleX, scaleY, rotation, skewX;
- tm.svg = !!(t.getCTM && _isSVG(t));
- if (tm.svg) {
- _parseSVGOrigin(t, _getStyle(t, _transformOriginProp, cs, false, "50% 50%") + "", tm, t.getAttribute("data-svg-origin"));
- _useSVGTransformAttr = CSSPlugin.useSVGTransformAttr || _forceSVGTransformAttr;
- }
- m = _getMatrix(t);
- if (m !== _identity2DMatrix) {
- if (m.length === 16) {
- //we'll only look at these position-related 6 variables first because if x/y/z all match, it's relatively safe to assume we don't need to re-parse everything which risks losing important rotational information (like rotationX:180 plus rotationY:180 would look the same as rotation:180 - there's no way to know for sure which direction was taken based solely on the matrix3d() values)
- var a11 = m[0], a21 = m[1], a31 = m[2], a41 = m[3],
- a12 = m[4], a22 = m[5], a32 = m[6], a42 = m[7],
- a13 = m[8], a23 = m[9], a33 = m[10],
- a14 = m[12], a24 = m[13], a34 = m[14],
- a43 = m[11],
- angle = Math.atan2(a32, a33),
- t1, t2, t3, t4, cos, sin;
- //we manually compensate for non-zero z component of transformOrigin to work around bugs in Safari
- if (tm.zOrigin) {
- a34 = -tm.zOrigin;
- a14 = a13*a34-m[12];
- a24 = a23*a34-m[13];
- a34 = a33*a34+tm.zOrigin-m[14];
- }
- //note for possible future consolidation: rotationX: Math.atan2(a32, a33), rotationY: Math.atan2(-a31, Math.sqrt(a33 * a33 + a32 * a32)), rotation: Math.atan2(a21, a11), skew: Math.atan2(a12, a22). However, it doesn't seem to be quite as reliable as the full-on backwards rotation procedure.
- tm.rotationX = angle * _RAD2DEG;
- //rotationX
- if (angle) {
- cos = Math.cos(-angle);
- sin = Math.sin(-angle);
- t1 = a12*cos+a13*sin;
- t2 = a22*cos+a23*sin;
- t3 = a32*cos+a33*sin;
- a13 = a12*-sin+a13*cos;
- a23 = a22*-sin+a23*cos;
- a33 = a32*-sin+a33*cos;
- a43 = a42*-sin+a43*cos;
- a12 = t1;
- a22 = t2;
- a32 = t3;
- }
- //rotationY
- angle = Math.atan2(-a31, a33);
- tm.rotationY = angle * _RAD2DEG;
- if (angle) {
- cos = Math.cos(-angle);
- sin = Math.sin(-angle);
- t1 = a11*cos-a13*sin;
- t2 = a21*cos-a23*sin;
- t3 = a31*cos-a33*sin;
- a23 = a21*sin+a23*cos;
- a33 = a31*sin+a33*cos;
- a43 = a41*sin+a43*cos;
- a11 = t1;
- a21 = t2;
- a31 = t3;
- }
- //rotationZ
- angle = Math.atan2(a21, a11);
- tm.rotation = angle * _RAD2DEG;
- if (angle) {
- cos = Math.cos(angle);
- sin = Math.sin(angle);
- t1 = a11*cos+a21*sin;
- t2 = a12*cos+a22*sin;
- t3 = a13*cos+a23*sin;
- a21 = a21*cos-a11*sin;
- a22 = a22*cos-a12*sin;
- a23 = a23*cos-a13*sin;
- a11 = t1;
- a12 = t2;
- a13 = t3;
- }
- if (tm.rotationX && Math.abs(tm.rotationX) + Math.abs(tm.rotation) > 359.9) { //when rotationY is set, it will often be parsed as 180 degrees different than it should be, and rotationX and rotation both being 180 (it looks the same), so we adjust for that here.
- tm.rotationX = tm.rotation = 0;
- tm.rotationY = 180 - tm.rotationY;
- }
- //skewX
- angle = Math.atan2(a12, a22);
- //scales
- tm.scaleX = ((Math.sqrt(a11 * a11 + a21 * a21 + a31 * a31) * rnd + 0.5) | 0) / rnd;
- tm.scaleY = ((Math.sqrt(a22 * a22 + a32 * a32) * rnd + 0.5) | 0) / rnd;
- tm.scaleZ = ((Math.sqrt(a13 * a13 + a23 * a23 + a33 * a33) * rnd + 0.5) | 0) / rnd;
- a11 /= tm.scaleX;
- a12 /= tm.scaleY;
- a21 /= tm.scaleX;
- a22 /= tm.scaleY;
- if (Math.abs(angle) > min) {
- tm.skewX = angle * _RAD2DEG;
- a12 = 0; //unskews
- if (tm.skewType !== "simple") {
- tm.scaleY *= 1 / Math.cos(angle); //by default, we compensate the scale based on the skew so that the element maintains a similar proportion when skewed, so we have to alter the scaleY here accordingly to match the default (non-adjusted) skewing that CSS does (stretching more and more as it skews).
- }
- } else {
- tm.skewX = 0;
- }
- /* //for testing purposes
- var transform = "matrix3d(",
- comma = ",",
- zero = "0";
- a13 /= tm.scaleZ;
- a23 /= tm.scaleZ;
- a31 /= tm.scaleX;
- a32 /= tm.scaleY;
- a33 /= tm.scaleZ;
- transform += ((a11 < min && a11 > -min) ? zero : a11) + comma + ((a21 < min && a21 > -min) ? zero : a21) + comma + ((a31 < min && a31 > -min) ? zero : a31);
- transform += comma + ((a41 < min && a41 > -min) ? zero : a41) + comma + ((a12 < min && a12 > -min) ? zero : a12) + comma + ((a22 < min && a22 > -min) ? zero : a22);
- transform += comma + ((a32 < min && a32 > -min) ? zero : a32) + comma + ((a42 < min && a42 > -min) ? zero : a42) + comma + ((a13 < min && a13 > -min) ? zero : a13);
- transform += comma + ((a23 < min && a23 > -min) ? zero : a23) + comma + ((a33 < min && a33 > -min) ? zero : a33) + comma + ((a43 < min && a43 > -min) ? zero : a43) + comma;
- transform += a14 + comma + a24 + comma + a34 + comma + (tm.perspective ? (1 + (-a34 / tm.perspective)) : 1) + ")";
- console.log(transform);
- document.querySelector(".test").style[_transformProp] = transform;
- */
- tm.perspective = a43 ? 1 / ((a43 < 0) ? -a43 : a43) : 0;
- tm.x = a14;
- tm.y = a24;
- tm.z = a34;
- if (tm.svg) {
- tm.x -= tm.xOrigin - (tm.xOrigin * a11 - tm.yOrigin * a12);
- tm.y -= tm.yOrigin - (tm.yOrigin * a21 - tm.xOrigin * a22);
- }
- } else if ((!_supports3D || parse || !m.length || tm.x !== m[4] || tm.y !== m[5] || (!tm.rotationX && !tm.rotationY))) { //sometimes a 6-element matrix is returned even when we performed 3D transforms, like if rotationX and rotationY are 180. In cases like this, we still need to honor the 3D transforms. If we just rely on the 2D info, it could affect how the data is interpreted, like scaleY might get set to -1 or rotation could get offset by 180 degrees. For example, do a TweenLite.to(element, 1, {css:{rotationX:180, rotationY:180}}) and then later, TweenLite.to(element, 1, {css:{rotationX:0}}) and without this conditional logic in place, it'd jump to a state of being unrotated when the 2nd tween starts. Then again, we need to honor the fact that the user COULD alter the transforms outside of CSSPlugin, like by manually applying new css, so we try to sense that by looking at x and y because if those changed, we know the changes were made outside CSSPlugin and we force a reinterpretation of the matrix values. Also, in Webkit browsers, if the element's "display" is "none", its calculated style value will always return empty, so if we've already recorded the values in the _gsTransform object, we'll just rely on those.
- var k = (m.length >= 6),
- a = k ? m[0] : 1,
- b = m[1] || 0,
- c = m[2] || 0,
- d = k ? m[3] : 1;
- tm.x = m[4] || 0;
- tm.y = m[5] || 0;
- scaleX = Math.sqrt(a * a + b * b);
- scaleY = Math.sqrt(d * d + c * c);
- rotation = (a || b) ? Math.atan2(b, a) * _RAD2DEG : tm.rotation || 0; //note: if scaleX is 0, we cannot accurately measure rotation. Same for skewX with a scaleY of 0. Therefore, we default to the previously recorded value (or zero if that doesn't exist).
- skewX = (c || d) ? Math.atan2(c, d) * _RAD2DEG + rotation : tm.skewX || 0;
- tm.scaleX = scaleX;
- tm.scaleY = scaleY;
- tm.rotation = rotation;
- tm.skewX = skewX;
- if (_supports3D) {
- tm.rotationX = tm.rotationY = tm.z = 0;
- tm.perspective = defaultTransformPerspective;
- tm.scaleZ = 1;
- }
- if (tm.svg) {
- tm.x -= tm.xOrigin - (tm.xOrigin * a + tm.yOrigin * c);
- tm.y -= tm.yOrigin - (tm.xOrigin * b + tm.yOrigin * d);
- }
- }
- if (Math.abs(tm.skewX) > 90 && Math.abs(tm.skewX) < 270) {
- if (invX) {
- tm.scaleX *= -1;
- tm.skewX += (tm.rotation <= 0) ? 180 : -180;
- tm.rotation += (tm.rotation <= 0) ? 180 : -180;
- } else {
- tm.scaleY *= -1;
- tm.skewX += (tm.skewX <= 0) ? 180 : -180;
- }
- }
- tm.zOrigin = zOrigin;
- //some browsers have a hard time with very small values like 2.4492935982947064e-16 (notice the "e-" towards the end) and would render the object slightly off. So we round to 0 in these cases. The conditional logic here is faster than calling Math.abs(). Also, browsers tend to render a SLIGHTLY rotated object in a fuzzy way, so we need to snap to exactly 0 when appropriate.
- for (i in tm) {
- if (tm[i] < min) if (tm[i] > -min) {
- tm[i] = 0;
- }
- }
- }
- //DEBUG: _log("parsed rotation of " + t.getAttribute("id")+": "+(tm.rotationX)+", "+(tm.rotationY)+", "+(tm.rotation)+", scale: "+tm.scaleX+", "+tm.scaleY+", "+tm.scaleZ+", position: "+tm.x+", "+tm.y+", "+tm.z+", perspective: "+tm.perspective+ ", origin: "+ tm.xOrigin+ ","+ tm.yOrigin);
- if (rec) {
- t._gsTransform = tm; //record to the object's _gsTransform which we use so that tweens can control individual properties independently (we need all the properties to accurately recompose the matrix in the setRatio() method)
- if (tm.svg) { //if we're supposed to apply transforms to the SVG element's "transform" attribute, make sure there aren't any CSS transforms applied or they'll override the attribute ones. Also clear the transform attribute if we're using CSS, just to be clean.
- if (_useSVGTransformAttr && t.style[_transformProp]) {
- TweenLite.delayedCall(0.001, function(){ //if we apply this right away (before anything has rendered), we risk there being no transforms for a brief moment and it also interferes with adjusting the transformOrigin in a tween with immediateRender:true (it'd try reading the matrix and it wouldn't have the appropriate data in place because we just removed it).
- _removeProp(t.style, _transformProp);
- });
- } else if (!_useSVGTransformAttr && t.getAttribute("transform")) {
- TweenLite.delayedCall(0.001, function(){
- t.removeAttribute("transform");
- });
- }
- }
- }
- return tm;
- },
- //for setting 2D transforms in IE6, IE7, and IE8 (must use a "filter" to emulate the behavior of modern day browser transforms)
- _setIETransformRatio = function(v) {
- var t = this.data, //refers to the element's _gsTransform object
- ang = -t.rotation * _DEG2RAD,
- skew = ang + t.skewX * _DEG2RAD,
- rnd = 100000,
- a = ((Math.cos(ang) * t.scaleX * rnd) | 0) / rnd,
- b = ((Math.sin(ang) * t.scaleX * rnd) | 0) / rnd,
- c = ((Math.sin(skew) * -t.scaleY * rnd) | 0) / rnd,
- d = ((Math.cos(skew) * t.scaleY * rnd) | 0) / rnd,
- style = this.t.style,
- cs = this.t.currentStyle,
- filters, val;
- if (!cs) {
- return;
- }
- val = b; //just for swapping the variables an inverting them (reused "val" to avoid creating another variable in memory). IE's filter matrix uses a non-standard matrix configuration (angle goes the opposite way, and b and c are reversed and inverted)
- b = -c;
- c = -val;
- filters = cs.filter;
- style.filter = ""; //remove filters so that we can accurately measure offsetWidth/offsetHeight
- var w = this.t.offsetWidth,
- h = this.t.offsetHeight,
- clip = (cs.position !== "absolute"),
- m = "progid:DXImageTransform.Microsoft.Matrix(M11=" + a + ", M12=" + b + ", M21=" + c + ", M22=" + d,
- ox = t.x + (w * t.xPercent / 100),
- oy = t.y + (h * t.yPercent / 100),
- dx, dy;
- //if transformOrigin is being used, adjust the offset x and y
- if (t.ox != null) {
- dx = ((t.oxp) ? w * t.ox * 0.01 : t.ox) - w / 2;
- dy = ((t.oyp) ? h * t.oy * 0.01 : t.oy) - h / 2;
- ox += dx - (dx * a + dy * b);
- oy += dy - (dx * c + dy * d);
- }
- if (!clip) {
- m += ", sizingMethod='auto expand')";
- } else {
- dx = (w / 2);
- dy = (h / 2);
- //translate to ensure that transformations occur around the correct origin (default is center).
- m += ", Dx=" + (dx - (dx * a + dy * b) + ox) + ", Dy=" + (dy - (dx * c + dy * d) + oy) + ")";
- }
- if (filters.indexOf("DXImageTransform.Microsoft.Matrix(") !== -1) {
- style.filter = filters.replace(_ieSetMatrixExp, m);
- } else {
- style.filter = m + " " + filters; //we must always put the transform/matrix FIRST (before alpha(opacity=xx)) to avoid an IE bug that slices part of the object when rotation is applied with alpha.
- }
- //at the end or beginning of the tween, if the matrix is normal (1, 0, 0, 1) and opacity is 100 (or doesn't exist), remove the filter to improve browser performance.
- if (v === 0 || v === 1) if (a === 1) if (b === 0) if (c === 0) if (d === 1) if (!clip || m.indexOf("Dx=0, Dy=0") !== -1) if (!_opacityExp.test(filters) || parseFloat(RegExp.$1) === 100) if (filters.indexOf("gradient(" && filters.indexOf("Alpha")) === -1) {
- style.removeAttribute("filter");
- }
- //we must set the margins AFTER applying the filter in order to avoid some bugs in IE8 that could (in rare scenarios) cause them to be ignored intermittently (vibration).
- if (!clip) {
- var mult = (_ieVers < 8) ? 1 : -1, //in Internet Explorer 7 and before, the box model is broken, causing the browser to treat the width/height of the actual rotated filtered image as the width/height of the box itself, but Microsoft corrected that in IE8. We must use a negative offset in IE8 on the right/bottom
- marg, prop, dif;
- dx = t.ieOffsetX || 0;
- dy = t.ieOffsetY || 0;
- t.ieOffsetX = Math.round((w - ((a < 0 ? -a : a) * w + (b < 0 ? -b : b) * h)) / 2 + ox);
- t.ieOffsetY = Math.round((h - ((d < 0 ? -d : d) * h + (c < 0 ? -c : c) * w)) / 2 + oy);
- for (i = 0; i < 4; i++) {
- prop = _margins[i];
- marg = cs[prop];
- //we need to get the current margin in case it is being tweened separately (we want to respect that tween's changes)
- val = (marg.indexOf("px") !== -1) ? parseFloat(marg) : _convertToPixels(this.t, prop, parseFloat(marg), marg.replace(_suffixExp, "")) || 0;
- if (val !== t[prop]) {
- dif = (i < 2) ? -t.ieOffsetX : -t.ieOffsetY; //if another tween is controlling a margin, we cannot only apply the difference in the ieOffsets, so we essentially zero-out the dx and dy here in that case. We record the margin(s) later so that we can keep comparing them, making this code very flexible.
- } else {
- dif = (i < 2) ? dx - t.ieOffsetX : dy - t.ieOffsetY;
- }
- style[prop] = (t[prop] = Math.round( val - dif * ((i === 0 || i === 2) ? 1 : mult) )) + "px";
- }
- }
- },
- /* translates a super small decimal to a string WITHOUT scientific notation
- _safeDecimal = function(n) {
- var s = (n < 0 ? -n : n) + "",
- a = s.split("e-");
- return (n < 0 ? "-0." : "0.") + new Array(parseInt(a[1], 10) || 0).join("0") + a[0].split(".").join("");
- },
- */
- _setTransformRatio = _internals.set3DTransformRatio = _internals.setTransformRatio = function(v) {
- var t = this.data, //refers to the element's _gsTransform object
- style = this.t.style,
- angle = t.rotation,
- rotationX = t.rotationX,
- rotationY = t.rotationY,
- sx = t.scaleX,
- sy = t.scaleY,
- sz = t.scaleZ,
- x = t.x,
- y = t.y,
- z = t.z,
- isSVG = t.svg,
- perspective = t.perspective,
- force3D = t.force3D,
- skewY = t.skewY,
- skewX = t.skewX,
- t1, a11, a12, a13, a21, a22, a23, a31, a32, a33, a41, a42, a43,
- zOrigin, min, cos, sin, t2, transform, comma, zero, skew, rnd;
- if (skewY) { //for performance reasons, we combine all skewing into the skewX and rotation values. Remember, a skewY of 10 degrees looks the same as a rotation of 10 degrees plus a skewX of 10 degrees.
- skewX += skewY;
- angle += skewY;
- }
- //check to see if we should render as 2D (and SVGs must use 2D when _useSVGTransformAttr is true)
- if (((((v === 1 || v === 0) && force3D === "auto" && (this.tween._totalTime === this.tween._totalDuration || !this.tween._totalTime)) || !force3D) && !z && !perspective && !rotationY && !rotationX && sz === 1) || (_useSVGTransformAttr && isSVG) || !_supports3D) { //on the final render (which could be 0 for a from tween), if there are no 3D aspects, render in 2D to free up memory and improve performance especially on mobile devices. Check the tween's totalTime/totalDuration too in order to make sure it doesn't happen between repeats if it's a repeating tween.
- //2D
- if (angle || skewX || isSVG) {
- angle *= _DEG2RAD;
- skew = skewX * _DEG2RAD;
- rnd = 100000;
- a11 = Math.cos(angle) * sx;
- a21 = Math.sin(angle) * sx;
- a12 = Math.sin(angle - skew) * -sy;
- a22 = Math.cos(angle - skew) * sy;
- if (skew && t.skewType === "simple") { //by default, we compensate skewing on the other axis to make it look more natural, but you can set the skewType to "simple" to use the uncompensated skewing that CSS does
- t1 = Math.tan(skew - skewY * _DEG2RAD);
- t1 = Math.sqrt(1 + t1 * t1);
- a12 *= t1;
- a22 *= t1;
- if (skewY) {
- t1 = Math.tan(skewY * _DEG2RAD);
- t1 = Math.sqrt(1 + t1 * t1);
- a11 *= t1;
- a21 *= t1;
- }
- }
- if (isSVG) {
- x += t.xOrigin - (t.xOrigin * a11 + t.yOrigin * a12) + t.xOffset;
- y += t.yOrigin - (t.xOrigin * a21 + t.yOrigin * a22) + t.yOffset;
- if (_useSVGTransformAttr && (t.xPercent || t.yPercent)) { //The SVG spec doesn't support percentage-based translation in the "transform" attribute, so we merge it into the matrix to simulate it.
- min = this.t.getBBox();
- x += t.xPercent * 0.01 * min.width;
- y += t.yPercent * 0.01 * min.height;
- }
- min = 0.000001;
- if (x < min) if (x > -min) {
- x = 0;
- }
- if (y < min) if (y > -min) {
- y = 0;
- }
- }
- transform = (((a11 * rnd) | 0) / rnd) + "," + (((a21 * rnd) | 0) / rnd) + "," + (((a12 * rnd) | 0) / rnd) + "," + (((a22 * rnd) | 0) / rnd) + "," + x + "," + y + ")";
- if (isSVG && _useSVGTransformAttr) {
- this.t.setAttribute("transform", "matrix(" + transform);
- } else {
- //some browsers have a hard time with very small values like 2.4492935982947064e-16 (notice the "e-" towards the end) and would render the object slightly off. So we round to 5 decimal places.
- style[_transformProp] = ((t.xPercent || t.yPercent) ? "translate(" + t.xPercent + "%," + t.yPercent + "%) matrix(" : "matrix(") + transform;
- }
- } else {
- style[_transformProp] = ((t.xPercent || t.yPercent) ? "translate(" + t.xPercent + "%," + t.yPercent + "%) matrix(" : "matrix(") + sx + ",0,0," + sy + "," + x + "," + y + ")";
- }
- return;
- }
- if (_isFirefox) { //Firefox has a bug (at least in v25) that causes it to render the transparent part of 32-bit PNG images as black when displayed inside an iframe and the 3D scale is very small and doesn't change sufficiently enough between renders (like if you use a Power4.easeInOut to scale from 0 to 1 where the beginning values only change a tiny amount to begin the tween before accelerating). In this case, we force the scale to be 0.00002 instead which is visually the same but works around the Firefox issue.
- min = 0.0001;
- if (sx < min && sx > -min) {
- sx = sz = 0.00002;
- }
- if (sy < min && sy > -min) {
- sy = sz = 0.00002;
- }
- if (perspective && !t.z && !t.rotationX && !t.rotationY) { //Firefox has a bug that causes elements to have an odd super-thin, broken/dotted black border on elements that have a perspective set but aren't utilizing 3D space (no rotationX, rotationY, or z).
- perspective = 0;
- }
- }
- if (angle || skewX) {
- angle *= _DEG2RAD;
- cos = a11 = Math.cos(angle);
- sin = a21 = Math.sin(angle);
- if (skewX) {
- angle -= skewX * _DEG2RAD;
- cos = Math.cos(angle);
- sin = Math.sin(angle);
- if (t.skewType === "simple") { //by default, we compensate skewing on the other axis to make it look more natural, but you can set the skewType to "simple" to use the uncompensated skewing that CSS does
- t1 = Math.tan((skewX - skewY) * _DEG2RAD);
- t1 = Math.sqrt(1 + t1 * t1);
- cos *= t1;
- sin *= t1;
- if (t.skewY) {
- t1 = Math.tan(skewY * _DEG2RAD);
- t1 = Math.sqrt(1 + t1 * t1);
- a11 *= t1;
- a21 *= t1;
- }
- }
- }
- a12 = -sin;
- a22 = cos;
- } else if (!rotationY && !rotationX && sz === 1 && !perspective && !isSVG) { //if we're only translating and/or 2D scaling, this is faster...
- style[_transformProp] = ((t.xPercent || t.yPercent) ? "translate(" + t.xPercent + "%," + t.yPercent + "%) translate3d(" : "translate3d(") + x + "px," + y + "px," + z +"px)" + ((sx !== 1 || sy !== 1) ? " scale(" + sx + "," + sy + ")" : "");
- return;
- } else {
- a11 = a22 = 1;
- a12 = a21 = 0;
- }
- // KEY INDEX AFFECTS a[row][column]
- // a11 0 rotation, rotationY, scaleX
- // a21 1 rotation, rotationY, scaleX
- // a31 2 rotationY, scaleX
- // a41 3 rotationY, scaleX
- // a12 4 rotation, skewX, rotationX, scaleY
- // a22 5 rotation, skewX, rotationX, scaleY
- // a32 6 rotationX, scaleY
- // a42 7 rotationX, scaleY
- // a13 8 rotationY, rotationX, scaleZ
- // a23 9 rotationY, rotationX, scaleZ
- // a33 10 rotationY, rotationX, scaleZ
- // a43 11 rotationY, rotationX, perspective, scaleZ
- // a14 12 x, zOrigin, svgOrigin
- // a24 13 y, zOrigin, svgOrigin
- // a34 14 z, zOrigin
- // a44 15
- // rotation: Math.atan2(a21, a11)
- // rotationY: Math.atan2(a13, a33) (or Math.atan2(a13, a11))
- // rotationX: Math.atan2(a32, a33)
- a33 = 1;
- a13 = a23 = a31 = a32 = a41 = a42 = 0;
- a43 = (perspective) ? -1 / perspective : 0;
- zOrigin = t.zOrigin;
- min = 0.000001; //threshold below which browsers use scientific notation which won't work.
- comma = ",";
- zero = "0";
- angle = rotationY * _DEG2RAD;
- if (angle) {
- cos = Math.cos(angle);
- sin = Math.sin(angle);
- a31 = -sin;
- a41 = a43*-sin;
- a13 = a11*sin;
- a23 = a21*sin;
- a33 = cos;
- a43 *= cos;
- a11 *= cos;
- a21 *= cos;
- }
- angle = rotationX * _DEG2RAD;
- if (angle) {
- cos = Math.cos(angle);
- sin = Math.sin(angle);
- t1 = a12*cos+a13*sin;
- t2 = a22*cos+a23*sin;
- a32 = a33*sin;
- a42 = a43*sin;
- a13 = a12*-sin+a13*cos;
- a23 = a22*-sin+a23*cos;
- a33 = a33*cos;
- a43 = a43*cos;
- a12 = t1;
- a22 = t2;
- }
- if (sz !== 1) {
- a13*=sz;
- a23*=sz;
- a33*=sz;
- a43*=sz;
- }
- if (sy !== 1) {
- a12*=sy;
- a22*=sy;
- a32*=sy;
- a42*=sy;
- }
- if (sx !== 1) {
- a11*=sx;
- a21*=sx;
- a31*=sx;
- a41*=sx;
- }
- if (zOrigin || isSVG) {
- if (zOrigin) {
- x += a13*-zOrigin;
- y += a23*-zOrigin;
- z += a33*-zOrigin+zOrigin;
- }
- if (isSVG) { //due to bugs in some browsers, we need to manage the transform-origin of SVG manually
- x += t.xOrigin - (t.xOrigin * a11 + t.yOrigin * a12) + t.xOffset;
- y += t.yOrigin - (t.xOrigin * a21 + t.yOrigin * a22) + t.yOffset;
- }
- if (x < min && x > -min) {
- x = zero;
- }
- if (y < min && y > -min) {
- y = zero;
- }
- if (z < min && z > -min) {
- z = 0; //don't use string because we calculate perspective later and need the number.
- }
- }
- //optimized way of concatenating all the values into a string. If we do it all in one shot, it's slower because of the way browsers have to create temp strings and the way it affects memory. If we do it piece-by-piece with +=, it's a bit slower too. We found that doing it in these sized chunks works best overall:
- transform = ((t.xPercent || t.yPercent) ? "translate(" + t.xPercent + "%," + t.yPercent + "%) matrix3d(" : "matrix3d(");
- transform += ((a11 < min && a11 > -min) ? zero : a11) + comma + ((a21 < min && a21 > -min) ? zero : a21) + comma + ((a31 < min && a31 > -min) ? zero : a31);
- transform += comma + ((a41 < min && a41 > -min) ? zero : a41) + comma + ((a12 < min && a12 > -min) ? zero : a12) + comma + ((a22 < min && a22 > -min) ? zero : a22);
- if (rotationX || rotationY || sz !== 1) { //performance optimization (often there's no rotationX or rotationY, so we can skip these calculations)
- transform += comma + ((a32 < min && a32 > -min) ? zero : a32) + comma + ((a42 < min && a42 > -min) ? zero : a42) + comma + ((a13 < min && a13 > -min) ? zero : a13);
- transform += comma + ((a23 < min && a23 > -min) ? zero : a23) + comma + ((a33 < min && a33 > -min) ? zero : a33) + comma + ((a43 < min && a43 > -min) ? zero : a43) + comma;
- } else {
- transform += ",0,0,0,0,1,0,";
- }
- transform += x + comma + y + comma + z + comma + (perspective ? (1 + (-z / perspective)) : 1) + ")";
- style[_transformProp] = transform;
- };
- p = Transform.prototype;
- p.x = p.y = p.z = p.skewX = p.skewY = p.rotation = p.rotationX = p.rotationY = p.zOrigin = p.xPercent = p.yPercent = p.xOffset = p.yOffset = 0;
- p.scaleX = p.scaleY = p.scaleZ = 1;
- _registerComplexSpecialProp("transform,scale,scaleX,scaleY,scaleZ,x,y,z,rotation,rotationX,rotationY,rotationZ,skewX,skewY,shortRotation,shortRotationX,shortRotationY,shortRotationZ,transformOrigin,svgOrigin,transformPerspective,directionalRotation,parseTransform,force3D,skewType,xPercent,yPercent,smoothOrigin", {parser:function(t, e, parsingProp, cssp, pt, plugin, vars) {
- if (cssp._lastParsedTransform === vars) { return pt; } //only need to parse the transform once, and only if the browser supports it.
- cssp._lastParsedTransform = vars;
- var scaleFunc = (vars.scale && typeof(vars.scale) === "function") ? vars.scale : 0, //if there's a function-based "scale" value, swap in the resulting numeric value temporarily. Otherwise, if it's called for both scaleX and scaleY independently, they may not match (like if the function uses Math.random()).
- swapFunc;
- if (typeof(vars[parsingProp]) === "function") { //whatever property triggers the initial parsing might be a function-based value in which case it already got called in parse(), thus we don't want to call it again in here. The most efficient way to avoid this is to temporarily swap the value directly into the vars object, and then after we do all our parsing in this function, we'll swap it back again.
- swapFunc = vars[parsingProp];
- vars[parsingProp] = e;
- }
- if (scaleFunc) {
- vars.scale = scaleFunc(_index, t);
- }
- var originalGSTransform = t._gsTransform,
- style = t.style,
- min = 0.000001,
- i = _transformProps.length,
- v = vars,
- endRotations = {},
- transformOriginString = "transformOrigin",
- m1 = _getTransform(t, _cs, true, v.parseTransform),
- orig = v.transform && ((typeof(v.transform) === "function") ? v.transform(_index, _target) : v.transform),
- m2, copy, has3D, hasChange, dr, x, y, matrix, p;
- m1.skewType = v.skewType || m1.skewType || CSSPlugin.defaultSkewType;
- cssp._transform = m1;
- if (orig && typeof(orig) === "string" && _transformProp) { //for values like transform:"rotate(60deg) scale(0.5, 0.8)"
- copy = _tempDiv.style; //don't use the original target because it might be SVG in which case some browsers don't report computed style correctly.
- copy[_transformProp] = orig;
- copy.display = "block"; //if display is "none", the browser often refuses to report the transform properties correctly.
- copy.position = "absolute";
- _doc.body.appendChild(_tempDiv);
- m2 = _getTransform(_tempDiv, null, false);
- if (m1.skewType === "simple") { //the default _getTransform() reports the skewX/scaleY as if skewType is "compensated", thus we need to adjust that here if skewType is "simple".
- m2.scaleY *= Math.cos(m2.skewX * _DEG2RAD);
- }
- if (m1.svg) { //if it's an SVG element, x/y part of the matrix will be affected by whatever we use as the origin and the offsets, so compensate here...
- x = m1.xOrigin;
- y = m1.yOrigin;
- m2.x -= m1.xOffset;
- m2.y -= m1.yOffset;
- if (v.transformOrigin || v.svgOrigin) { //if this tween is altering the origin, we must factor that in here. The actual work of recording the transformOrigin values and setting up the PropTween is done later (still inside this function) so we cannot leave the changes intact here - we only want to update the x/y accordingly.
- orig = {};
- _parseSVGOrigin(t, _parsePosition(v.transformOrigin), orig, v.svgOrigin, v.smoothOrigin, true);
- x = orig.xOrigin;
- y = orig.yOrigin;
- m2.x -= orig.xOffset - m1.xOffset;
- m2.y -= orig.yOffset - m1.yOffset;
- }
- if (x || y) {
- matrix = _getMatrix(_tempDiv, true);
- m2.x -= x - (x * matrix[0] + y * matrix[2]);
- m2.y -= y - (x * matrix[1] + y * matrix[3]);
- }
- }
- _doc.body.removeChild(_tempDiv);
- if (!m2.perspective) {
- m2.perspective = m1.perspective; //tweening to no perspective gives very unintuitive results - just keep the same perspective in that case.
- }
- if (v.xPercent != null) {
- m2.xPercent = _parseVal(v.xPercent, m1.xPercent);
- }
- if (v.yPercent != null) {
- m2.yPercent = _parseVal(v.yPercent, m1.yPercent);
- }
- } else if (typeof(v) === "object") { //for values like scaleX, scaleY, rotation, x, y, skewX, and skewY or transform:{...} (object)
- m2 = {scaleX:_parseVal((v.scaleX != null) ? v.scaleX : v.scale, m1.scaleX),
- scaleY:_parseVal((v.scaleY != null) ? v.scaleY : v.scale, m1.scaleY),
- scaleZ:_parseVal(v.scaleZ, m1.scaleZ),
- x:_parseVal(v.x, m1.x),
- y:_parseVal(v.y, m1.y),
- z:_parseVal(v.z, m1.z),
- xPercent:_parseVal(v.xPercent, m1.xPercent),
- yPercent:_parseVal(v.yPercent, m1.yPercent),
- perspective:_parseVal(v.transformPerspective, m1.perspective)};
- dr = v.directionalRotation;
- if (dr != null) {
- if (typeof(dr) === "object") {
- for (copy in dr) {
- v[copy] = dr[copy];
- }
- } else {
- v.rotation = dr;
- }
- }
- if (typeof(v.x) === "string" && v.x.indexOf("%") !== -1) {
- m2.x = 0;
- m2.xPercent = _parseVal(v.x, m1.xPercent);
- }
- if (typeof(v.y) === "string" && v.y.indexOf("%") !== -1) {
- m2.y = 0;
- m2.yPercent = _parseVal(v.y, m1.yPercent);
- }
- m2.rotation = _parseAngle(("rotation" in v) ? v.rotation : ("shortRotation" in v) ? v.shortRotation + "_short" : ("rotationZ" in v) ? v.rotationZ : m1.rotation, m1.rotation, "rotation", endRotations);
- if (_supports3D) {
- m2.rotationX = _parseAngle(("rotationX" in v) ? v.rotationX : ("shortRotationX" in v) ? v.shortRotationX + "_short" : m1.rotationX || 0, m1.rotationX, "rotationX", endRotations);
- m2.rotationY = _parseAngle(("rotationY" in v) ? v.rotationY : ("shortRotationY" in v) ? v.shortRotationY + "_short" : m1.rotationY || 0, m1.rotationY, "rotationY", endRotations);
- }
- m2.skewX = _parseAngle(v.skewX, m1.skewX);
- m2.skewY = _parseAngle(v.skewY, m1.skewY);
- }
- if (_supports3D && v.force3D != null) {
- m1.force3D = v.force3D;
- hasChange = true;
- }
- has3D = (m1.force3D || m1.z || m1.rotationX || m1.rotationY || m2.z || m2.rotationX || m2.rotationY || m2.perspective);
- if (!has3D && v.scale != null) {
- m2.scaleZ = 1; //no need to tween scaleZ.
- }
- while (--i > -1) {
- p = _transformProps[i];
- orig = m2[p] - m1[p];
- if (orig > min || orig < -min || v[p] != null || _forcePT[p] != null) {
- hasChange = true;
- pt = new CSSPropTween(m1, p, m1[p], orig, pt);
- if (p in endRotations) {
- pt.e = endRotations[p]; //directional rotations typically have compensated values during the tween, but we need to make sure they end at exactly what the user requested
- }
- pt.xs0 = 0; //ensures the value stays numeric in setRatio()
- pt.plugin = plugin;
- cssp._overwriteProps.push(pt.n);
- }
- }
- orig = v.transformOrigin;
- if (m1.svg && (orig || v.svgOrigin)) {
- x = m1.xOffset; //when we change the origin, in order to prevent things from jumping we adjust the x/y so we must record those here so that we can create PropTweens for them and flip them at the same time as the origin
- y = m1.yOffset;
- _parseSVGOrigin(t, _parsePosition(orig), m2, v.svgOrigin, v.smoothOrigin);
- pt = _addNonTweeningNumericPT(m1, "xOrigin", (originalGSTransform ? m1 : m2).xOrigin, m2.xOrigin, pt, transformOriginString); //note: if there wasn't a transformOrigin defined yet, just start with the destination one; it's wasteful otherwise, and it causes problems with fromTo() tweens. For example, TweenLite.to("#wheel", 3, {rotation:180, transformOrigin:"50% 50%", delay:1}); TweenLite.fromTo("#wheel", 3, {scale:0.5, transformOrigin:"50% 50%"}, {scale:1, delay:2}); would cause a jump when the from values revert at the beginning of the 2nd tween.
- pt = _addNonTweeningNumericPT(m1, "yOrigin", (originalGSTransform ? m1 : m2).yOrigin, m2.yOrigin, pt, transformOriginString);
- if (x !== m1.xOffset || y !== m1.yOffset) {
- pt = _addNonTweeningNumericPT(m1, "xOffset", (originalGSTransform ? x : m1.xOffset), m1.xOffset, pt, transformOriginString);
- pt = _addNonTweeningNumericPT(m1, "yOffset", (originalGSTransform ? y : m1.yOffset), m1.yOffset, pt, transformOriginString);
- }
- orig = "0px 0px"; //certain browsers (like firefox) completely botch transform-origin, so we must remove it to prevent it from contaminating transforms. We manage it ourselves with xOrigin and yOrigin
- }
- if (orig || (_supports3D && has3D && m1.zOrigin)) { //if anything 3D is happening and there's a transformOrigin with a z component that's non-zero, we must ensure that the transformOrigin's z-component is set to 0 so that we can manually do those calculations to get around Safari bugs. Even if the user didn't specifically define a "transformOrigin" in this particular tween (maybe they did it via css directly).
- if (_transformProp) {
- hasChange = true;
- p = _transformOriginProp;
- orig = (orig || _getStyle(t, p, _cs, false, "50% 50%")) + ""; //cast as string to avoid errors
- pt = new CSSPropTween(style, p, 0, 0, pt, -1, transformOriginString);
- pt.b = style[p];
- pt.plugin = plugin;
- if (_supports3D) {
- copy = m1.zOrigin;
- orig = orig.split(" ");
- m1.zOrigin = ((orig.length > 2 && !(copy !== 0 && orig[2] === "0px")) ? parseFloat(orig[2]) : copy) || 0; //Safari doesn't handle the z part of transformOrigin correctly, so we'll manually handle it in the _set3DTransformRatio() method.
- pt.xs0 = pt.e = orig[0] + " " + (orig[1] || "50%") + " 0px"; //we must define a z value of 0px specifically otherwise iOS 5 Safari will stick with the old one (if one was defined)!
- pt = new CSSPropTween(m1, "zOrigin", 0, 0, pt, -1, pt.n); //we must create a CSSPropTween for the _gsTransform.zOrigin so that it gets reset properly at the beginning if the tween runs backward (as opposed to just setting m1.zOrigin here)
- pt.b = copy;
- pt.xs0 = pt.e = m1.zOrigin;
- } else {
- pt.xs0 = pt.e = orig;
- }
- //for older versions of IE (6-8), we need to manually calculate things inside the setRatio() function. We record origin x and y (ox and oy) and whether or not the values are percentages (oxp and oyp).
- } else {
- _parsePosition(orig + "", m1);
- }
- }
- if (hasChange) {
- cssp._transformType = (!(m1.svg && _useSVGTransformAttr) && (has3D || this._transformType === 3)) ? 3 : 2; //quicker than calling cssp._enableTransforms();
- }
- if (swapFunc) {
- vars[parsingProp] = swapFunc;
- }
- if (scaleFunc) {
- vars.scale = scaleFunc;
- }
- return pt;
- }, prefix:true});
- _registerComplexSpecialProp("boxShadow", {defaultValue:"0px 0px 0px 0px #999", prefix:true, color:true, multi:true, keyword:"inset"});
- _registerComplexSpecialProp("borderRadius", {defaultValue:"0px", parser:function(t, e, p, cssp, pt, plugin) {
- e = this.format(e);
- var props = ["borderTopLeftRadius","borderTopRightRadius","borderBottomRightRadius","borderBottomLeftRadius"],
- style = t.style,
- ea1, i, es2, bs2, bs, es, bn, en, w, h, esfx, bsfx, rel, hn, vn, em;
- w = parseFloat(t.offsetWidth);
- h = parseFloat(t.offsetHeight);
- ea1 = e.split(" ");
- for (i = 0; i < props.length; i++) { //if we're dealing with percentages, we must convert things separately for the horizontal and vertical axis!
- if (this.p.indexOf("border")) { //older browsers used a prefix
- props[i] = _checkPropPrefix(props[i]);
- }
- bs = bs2 = _getStyle(t, props[i], _cs, false, "0px");
- if (bs.indexOf(" ") !== -1) {
- bs2 = bs.split(" ");
- bs = bs2[0];
- bs2 = bs2[1];
- }
- es = es2 = ea1[i];
- bn = parseFloat(bs);
- bsfx = bs.substr((bn + "").length);
- rel = (es.charAt(1) === "=");
- if (rel) {
- en = parseInt(es.charAt(0)+"1", 10);
- es = es.substr(2);
- en *= parseFloat(es);
- esfx = es.substr((en + "").length - (en < 0 ? 1 : 0)) || "";
- } else {
- en = parseFloat(es);
- esfx = es.substr((en + "").length);
- }
- if (esfx === "") {
- esfx = _suffixMap[p] || bsfx;
- }
- if (esfx !== bsfx) {
- hn = _convertToPixels(t, "borderLeft", bn, bsfx); //horizontal number (we use a bogus "borderLeft" property just because the _convertToPixels() method searches for the keywords "Left", "Right", "Top", and "Bottom" to determine of it's a horizontal or vertical property, and we need "border" in the name so that it knows it should measure relative to the element itself, not its parent.
- vn = _convertToPixels(t, "borderTop", bn, bsfx); //vertical number
- if (esfx === "%") {
- bs = (hn / w * 100) + "%";
- bs2 = (vn / h * 100) + "%";
- } else if (esfx === "em") {
- em = _convertToPixels(t, "borderLeft", 1, "em");
- bs = (hn / em) + "em";
- bs2 = (vn / em) + "em";
- } else {
- bs = hn + "px";
- bs2 = vn + "px";
- }
- if (rel) {
- es = (parseFloat(bs) + en) + esfx;
- es2 = (parseFloat(bs2) + en) + esfx;
- }
- }
- pt = _parseComplex(style, props[i], bs + " " + bs2, es + " " + es2, false, "0px", pt);
- }
- return pt;
- }, prefix:true, formatter:_getFormatter("0px 0px 0px 0px", false, true)});
- _registerComplexSpecialProp("borderBottomLeftRadius,borderBottomRightRadius,borderTopLeftRadius,borderTopRightRadius", {defaultValue:"0px", parser:function(t, e, p, cssp, pt, plugin) {
- return _parseComplex(t.style, p, this.format(_getStyle(t, p, _cs, false, "0px 0px")), this.format(e), false, "0px", pt);
- }, prefix:true, formatter:_getFormatter("0px 0px", false, true)});
- _registerComplexSpecialProp("backgroundPosition", {defaultValue:"0 0", parser:function(t, e, p, cssp, pt, plugin) {
- var bp = "background-position",
- cs = (_cs || _getComputedStyle(t, null)),
- bs = this.format( ((cs) ? _ieVers ? cs.getPropertyValue(bp + "-x") + " " + cs.getPropertyValue(bp + "-y") : cs.getPropertyValue(bp) : t.currentStyle.backgroundPositionX + " " + t.currentStyle.backgroundPositionY) || "0 0"), //Internet Explorer doesn't report background-position correctly - we must query background-position-x and background-position-y and combine them (even in IE10). Before IE9, we must do the same with the currentStyle object and use camelCase
- es = this.format(e),
- ba, ea, i, pct, overlap, src;
- if ((bs.indexOf("%") !== -1) !== (es.indexOf("%") !== -1) && es.split(",").length < 2) {
- src = _getStyle(t, "backgroundImage").replace(_urlExp, "");
- if (src && src !== "none") {
- ba = bs.split(" ");
- ea = es.split(" ");
- _tempImg.setAttribute("src", src); //set the temp IMG's src to the background-image so that we can measure its width/height
- i = 2;
- while (--i > -1) {
- bs = ba[i];
- pct = (bs.indexOf("%") !== -1);
- if (pct !== (ea[i].indexOf("%") !== -1)) {
- overlap = (i === 0) ? t.offsetWidth - _tempImg.width : t.offsetHeight - _tempImg.height;
- ba[i] = pct ? (parseFloat(bs) / 100 * overlap) + "px" : (parseFloat(bs) / overlap * 100) + "%";
- }
- }
- bs = ba.join(" ");
- }
- }
- return this.parseComplex(t.style, bs, es, pt, plugin);
- }, formatter:_parsePosition});
- _registerComplexSpecialProp("backgroundSize", {defaultValue:"0 0", formatter:function(v) {
- v += ""; //ensure it's a string
- return _parsePosition(v.indexOf(" ") === -1 ? v + " " + v : v); //if set to something like "100% 100%", Safari typically reports the computed style as just "100%" (no 2nd value), but we should ensure that there are two values, so copy the first one. Otherwise, it'd be interpreted as "100% 0" (wrong).
- }});
- _registerComplexSpecialProp("perspective", {defaultValue:"0px", prefix:true});
- _registerComplexSpecialProp("perspectiveOrigin", {defaultValue:"50% 50%", prefix:true});
- _registerComplexSpecialProp("transformStyle", {prefix:true});
- _registerComplexSpecialProp("backfaceVisibility", {prefix:true});
- _registerComplexSpecialProp("userSelect", {prefix:true});
- _registerComplexSpecialProp("margin", {parser:_getEdgeParser("marginTop,marginRight,marginBottom,marginLeft")});
- _registerComplexSpecialProp("padding", {parser:_getEdgeParser("paddingTop,paddingRight,paddingBottom,paddingLeft")});
- _registerComplexSpecialProp("clip", {defaultValue:"rect(0px,0px,0px,0px)", parser:function(t, e, p, cssp, pt, plugin){
- var b, cs, delim;
- if (_ieVers < 9) { //IE8 and earlier don't report a "clip" value in the currentStyle - instead, the values are split apart into clipTop, clipRight, clipBottom, and clipLeft. Also, in IE7 and earlier, the values inside rect() are space-delimited, not comma-delimited.
- cs = t.currentStyle;
- delim = _ieVers < 8 ? " " : ",";
- b = "rect(" + cs.clipTop + delim + cs.clipRight + delim + cs.clipBottom + delim + cs.clipLeft + ")";
- e = this.format(e).split(",").join(delim);
- } else {
- b = this.format(_getStyle(t, this.p, _cs, false, this.dflt));
- e = this.format(e);
- }
- return this.parseComplex(t.style, b, e, pt, plugin);
- }});
- _registerComplexSpecialProp("textShadow", {defaultValue:"0px 0px 0px #999", color:true, multi:true});
- _registerComplexSpecialProp("autoRound,strictUnits", {parser:function(t, e, p, cssp, pt) {return pt;}}); //just so that we can ignore these properties (not tween them)
- _registerComplexSpecialProp("border", {defaultValue:"0px solid #000", parser:function(t, e, p, cssp, pt, plugin) {
- var bw = _getStyle(t, "borderTopWidth", _cs, false, "0px"),
- end = this.format(e).split(" "),
- esfx = end[0].replace(_suffixExp, "");
- if (esfx !== "px") { //if we're animating to a non-px value, we need to convert the beginning width to that unit.
- bw = (parseFloat(bw) / _convertToPixels(t, "borderTopWidth", 1, esfx)) + esfx;
- }
- return this.parseComplex(t.style, this.format(bw + " " + _getStyle(t, "borderTopStyle", _cs, false, "solid") + " " + _getStyle(t, "borderTopColor", _cs, false, "#000")), end.join(" "), pt, plugin);
- }, color:true, formatter:function(v) {
- var a = v.split(" ");
- return a[0] + " " + (a[1] || "solid") + " " + (v.match(_colorExp) || ["#000"])[0];
- }});
- _registerComplexSpecialProp("borderWidth", {parser:_getEdgeParser("borderTopWidth,borderRightWidth,borderBottomWidth,borderLeftWidth")}); //Firefox doesn't pick up on borderWidth set in style sheets (only inline).
- _registerComplexSpecialProp("float,cssFloat,styleFloat", {parser:function(t, e, p, cssp, pt, plugin) {
- var s = t.style,
- prop = ("cssFloat" in s) ? "cssFloat" : "styleFloat";
- return new CSSPropTween(s, prop, 0, 0, pt, -1, p, false, 0, s[prop], e);
- }});
- //opacity-related
- var _setIEOpacityRatio = function(v) {
- var t = this.t, //refers to the element's style property
- filters = t.filter || _getStyle(this.data, "filter") || "",
- val = (this.s + this.c * v) | 0,
- skip;
- if (val === 100) { //for older versions of IE that need to use a filter to apply opacity, we should remove the filter if opacity hits 1 in order to improve performance, but make sure there isn't a transform (matrix) or gradient in the filters.
- if (filters.indexOf("atrix(") === -1 && filters.indexOf("radient(") === -1 && filters.indexOf("oader(") === -1) {
- t.removeAttribute("filter");
- skip = (!_getStyle(this.data, "filter")); //if a class is applied that has an alpha filter, it will take effect (we don't want that), so re-apply our alpha filter in that case. We must first remove it and then check.
- } else {
- t.filter = filters.replace(_alphaFilterExp, "");
- skip = true;
- }
- }
- if (!skip) {
- if (this.xn1) {
- t.filter = filters = filters || ("alpha(opacity=" + val + ")"); //works around bug in IE7/8 that prevents changes to "visibility" from being applied properly if the filter is changed to a different alpha on the same frame.
- }
- if (filters.indexOf("pacity") === -1) { //only used if browser doesn't support the standard opacity style property (IE 7 and 8). We omit the "O" to avoid case-sensitivity issues
- if (val !== 0 || !this.xn1) { //bugs in IE7/8 won't render the filter properly if opacity is ADDED on the same frame/render as "visibility" changes (this.xn1 is 1 if this tween is an "autoAlpha" tween)
- t.filter = filters + " alpha(opacity=" + val + ")"; //we round the value because otherwise, bugs in IE7/8 can prevent "visibility" changes from being applied properly.
- }
- } else {
- t.filter = filters.replace(_opacityExp, "opacity=" + val);
- }
- }
- };
- _registerComplexSpecialProp("opacity,alpha,autoAlpha", {defaultValue:"1", parser:function(t, e, p, cssp, pt, plugin) {
- var b = parseFloat(_getStyle(t, "opacity", _cs, false, "1")),
- style = t.style,
- isAutoAlpha = (p === "autoAlpha");
- if (typeof(e) === "string" && e.charAt(1) === "=") {
- e = ((e.charAt(0) === "-") ? -1 : 1) * parseFloat(e.substr(2)) + b;
- }
- if (isAutoAlpha && b === 1 && _getStyle(t, "visibility", _cs) === "hidden" && e !== 0) { //if visibility is initially set to "hidden", we should interpret that as intent to make opacity 0 (a convenience)
- b = 0;
- }
- if (_supportsOpacity) {
- pt = new CSSPropTween(style, "opacity", b, e - b, pt);
- } else {
- pt = new CSSPropTween(style, "opacity", b * 100, (e - b) * 100, pt);
- pt.xn1 = isAutoAlpha ? 1 : 0; //we need to record whether or not this is an autoAlpha so that in the setRatio(), we know to duplicate the setting of the alpha in order to work around a bug in IE7 and IE8 that prevents changes to "visibility" from taking effect if the filter is changed to a different alpha(opacity) at the same time. Setting it to the SAME value first, then the new value works around the IE7/8 bug.
- style.zoom = 1; //helps correct an IE issue.
- pt.type = 2;
- pt.b = "alpha(opacity=" + pt.s + ")";
- pt.e = "alpha(opacity=" + (pt.s + pt.c) + ")";
- pt.data = t;
- pt.plugin = plugin;
- pt.setRatio = _setIEOpacityRatio;
- }
- if (isAutoAlpha) { //we have to create the "visibility" PropTween after the opacity one in the linked list so that they run in the order that works properly in IE8 and earlier
- pt = new CSSPropTween(style, "visibility", 0, 0, pt, -1, null, false, 0, ((b !== 0) ? "inherit" : "hidden"), ((e === 0) ? "hidden" : "inherit"));
- pt.xs0 = "inherit";
- cssp._overwriteProps.push(pt.n);
- cssp._overwriteProps.push(p);
- }
- return pt;
- }});
- var _removeProp = function(s, p) {
- if (p) {
- if (s.removeProperty) {
- if (p.substr(0,2) === "ms" || p.substr(0,6) === "webkit") { //Microsoft and some Webkit browsers don't conform to the standard of capitalizing the first prefix character, so we adjust so that when we prefix the caps with a dash, it's correct (otherwise it'd be "ms-transform" instead of "-ms-transform" for IE9, for example)
- p = "-" + p;
- }
- s.removeProperty(p.replace(_capsExp, "-$1").toLowerCase());
- } else { //note: old versions of IE use "removeAttribute()" instead of "removeProperty()"
- s.removeAttribute(p);
- }
- }
- },
- _setClassNameRatio = function(v) {
- this.t._gsClassPT = this;
- if (v === 1 || v === 0) {
- this.t.setAttribute("class", (v === 0) ? this.b : this.e);
- var mpt = this.data, //first MiniPropTween
- s = this.t.style;
- while (mpt) {
- if (!mpt.v) {
- _removeProp(s, mpt.p);
- } else {
- s[mpt.p] = mpt.v;
- }
- mpt = mpt._next;
- }
- if (v === 1 && this.t._gsClassPT === this) {
- this.t._gsClassPT = null;
- }
- } else if (this.t.getAttribute("class") !== this.e) {
- this.t.setAttribute("class", this.e);
- }
- };
- _registerComplexSpecialProp("className", {parser:function(t, e, p, cssp, pt, plugin, vars) {
- var b = t.getAttribute("class") || "", //don't use t.className because it doesn't work consistently on SVG elements; getAttribute("class") and setAttribute("class", value") is more reliable.
- cssText = t.style.cssText,
- difData, bs, cnpt, cnptLookup, mpt;
- pt = cssp._classNamePT = new CSSPropTween(t, p, 0, 0, pt, 2);
- pt.setRatio = _setClassNameRatio;
- pt.pr = -11;
- _hasPriority = true;
- pt.b = b;
- bs = _getAllStyles(t, _cs);
- //if there's a className tween already operating on the target, force it to its end so that the necessary inline styles are removed and the class name is applied before we determine the end state (we don't want inline styles interfering that were there just for class-specific values)
- cnpt = t._gsClassPT;
- if (cnpt) {
- cnptLookup = {};
- mpt = cnpt.data; //first MiniPropTween which stores the inline styles - we need to force these so that the inline styles don't contaminate things. Otherwise, there's a small chance that a tween could start and the inline values match the destination values and they never get cleaned.
- while (mpt) {
- cnptLookup[mpt.p] = 1;
- mpt = mpt._next;
- }
- cnpt.setRatio(1);
- }
- t._gsClassPT = pt;
- pt.e = (e.charAt(1) !== "=") ? e : b.replace(new RegExp("(?:\\s|^)" + e.substr(2) + "(?![\\w-])"), "") + ((e.charAt(0) === "+") ? " " + e.substr(2) : "");
- t.setAttribute("class", pt.e);
- difData = _cssDif(t, bs, _getAllStyles(t), vars, cnptLookup);
- t.setAttribute("class", b);
- pt.data = difData.firstMPT;
- t.style.cssText = cssText; //we recorded cssText before we swapped classes and ran _getAllStyles() because in cases when a className tween is overwritten, we remove all the related tweening properties from that class change (otherwise class-specific stuff can't override properties we've directly set on the target's style object due to specificity).
- pt = pt.xfirst = cssp.parse(t, difData.difs, pt, plugin); //we record the CSSPropTween as the xfirst so that we can handle overwriting propertly (if "className" gets overwritten, we must kill all the properties associated with the className part of the tween, so we can loop through from xfirst to the pt itself)
- return pt;
- }});
- var _setClearPropsRatio = function(v) {
- if (v === 1 || v === 0) if (this.data._totalTime === this.data._totalDuration && this.data.data !== "isFromStart") { //this.data refers to the tween. Only clear at the END of the tween (remember, from() tweens make the ratio go from 1 to 0, so we can't just check that and if the tween is the zero-duration one that's created internally to render the starting values in a from() tween, ignore that because otherwise, for example, from(...{height:100, clearProps:"height", delay:1}) would wipe the height at the beginning of the tween and after 1 second, it'd kick back in).
- var s = this.t.style,
- transformParse = _specialProps.transform.parse,
- a, p, i, clearTransform, transform;
- if (this.e === "all") {
- s.cssText = "";
- clearTransform = true;
- } else {
- a = this.e.split(" ").join("").split(",");
- i = a.length;
- while (--i > -1) {
- p = a[i];
- if (_specialProps[p]) {
- if (_specialProps[p].parse === transformParse) {
- clearTransform = true;
- } else {
- p = (p === "transformOrigin") ? _transformOriginProp : _specialProps[p].p; //ensures that special properties use the proper browser-specific property name, like "scaleX" might be "-webkit-transform" or "boxShadow" might be "-moz-box-shadow"
- }
- }
- _removeProp(s, p);
- }
- }
- if (clearTransform) {
- _removeProp(s, _transformProp);
- transform = this.t._gsTransform;
- if (transform) {
- if (transform.svg) {
- this.t.removeAttribute("data-svg-origin");
- this.t.removeAttribute("transform");
- }
- delete this.t._gsTransform;
- }
- }
- }
- };
- _registerComplexSpecialProp("clearProps", {parser:function(t, e, p, cssp, pt) {
- pt = new CSSPropTween(t, p, 0, 0, pt, 2);
- pt.setRatio = _setClearPropsRatio;
- pt.e = e;
- pt.pr = -10;
- pt.data = cssp._tween;
- _hasPriority = true;
- return pt;
- }});
- p = "bezier,throwProps,physicsProps,physics2D".split(",");
- i = p.length;
- while (i--) {
- _registerPluginProp(p[i]);
- }
- p = CSSPlugin.prototype;
- p._firstPT = p._lastParsedTransform = p._transform = null;
- //gets called when the tween renders for the first time. This kicks everything off, recording start/end values, etc.
- p._onInitTween = function(target, vars, tween, index) {
- if (!target.nodeType) { //css is only for dom elements
- return false;
- }
- this._target = _target = target;
- this._tween = tween;
- this._vars = vars;
- _index = index;
- _autoRound = vars.autoRound;
- _hasPriority = false;
- _suffixMap = vars.suffixMap || CSSPlugin.suffixMap;
- _cs = _getComputedStyle(target, "");
- _overwriteProps = this._overwriteProps;
- var style = target.style,
- v, pt, pt2, first, last, next, zIndex, tpt, threeD;
- if (_reqSafariFix) if (style.zIndex === "") {
- v = _getStyle(target, "zIndex", _cs);
- if (v === "auto" || v === "") {
- //corrects a bug in [non-Android] Safari that prevents it from repainting elements in their new positions if they don't have a zIndex set. We also can't just apply this inside _parseTransform() because anything that's moved in any way (like using "left" or "top" instead of transforms like "x" and "y") can be affected, so it is best to ensure that anything that's tweening has a z-index. Setting "WebkitPerspective" to a non-zero value worked too except that on iOS Safari things would flicker randomly. Plus zIndex is less memory-intensive.
- this._addLazySet(style, "zIndex", 0);
- }
- }
- if (typeof(vars) === "string") {
- first = style.cssText;
- v = _getAllStyles(target, _cs);
- style.cssText = first + ";" + vars;
- v = _cssDif(target, v, _getAllStyles(target)).difs;
- if (!_supportsOpacity && _opacityValExp.test(vars)) {
- v.opacity = parseFloat( RegExp.$1 );
- }
- vars = v;
- style.cssText = first;
- }
- if (vars.className) { //className tweens will combine any differences they find in the css with the vars that are passed in, so {className:"myClass", scale:0.5, left:20} would work.
- this._firstPT = pt = _specialProps.className.parse(target, vars.className, "className", this, null, null, vars);
- } else {
- this._firstPT = pt = this.parse(target, vars, null);
- }
- if (this._transformType) {
- threeD = (this._transformType === 3);
- if (!_transformProp) {
- style.zoom = 1; //helps correct an IE issue.
- } else if (_isSafari) {
- _reqSafariFix = true;
- //if zIndex isn't set, iOS Safari doesn't repaint things correctly sometimes (seemingly at random).
- if (style.zIndex === "") {
- zIndex = _getStyle(target, "zIndex", _cs);
- if (zIndex === "auto" || zIndex === "") {
- this._addLazySet(style, "zIndex", 0);
- }
- }
- //Setting WebkitBackfaceVisibility corrects 3 bugs:
- // 1) [non-Android] Safari skips rendering changes to "top" and "left" that are made on the same frame/render as a transform update.
- // 2) iOS Safari sometimes neglects to repaint elements in their new positions. Setting "WebkitPerspective" to a non-zero value worked too except that on iOS Safari things would flicker randomly.
- // 3) Safari sometimes displayed odd artifacts when tweening the transform (or WebkitTransform) property, like ghosts of the edges of the element remained. Definitely a browser bug.
- //Note: we allow the user to override the auto-setting by defining WebkitBackfaceVisibility in the vars of the tween.
- if (_isSafariLT6) {
- this._addLazySet(style, "WebkitBackfaceVisibility", this._vars.WebkitBackfaceVisibility || (threeD ? "visible" : "hidden"));
- }
- }
- pt2 = pt;
- while (pt2 && pt2._next) {
- pt2 = pt2._next;
- }
- tpt = new CSSPropTween(target, "transform", 0, 0, null, 2);
- this._linkCSSP(tpt, null, pt2);
- tpt.setRatio = _transformProp ? _setTransformRatio : _setIETransformRatio;
- tpt.data = this._transform || _getTransform(target, _cs, true);
- tpt.tween = tween;
- tpt.pr = -1; //ensures that the transforms get applied after the components are updated.
- _overwriteProps.pop(); //we don't want to force the overwrite of all "transform" tweens of the target - we only care about individual transform properties like scaleX, rotation, etc. The CSSPropTween constructor automatically adds the property to _overwriteProps which is why we need to pop() here.
- }
- if (_hasPriority) {
- //reorders the linked list in order of pr (priority)
- while (pt) {
- next = pt._next;
- pt2 = first;
- while (pt2 && pt2.pr > pt.pr) {
- pt2 = pt2._next;
- }
- if ((pt._prev = pt2 ? pt2._prev : last)) {
- pt._prev._next = pt;
- } else {
- first = pt;
- }
- if ((pt._next = pt2)) {
- pt2._prev = pt;
- } else {
- last = pt;
- }
- pt = next;
- }
- this._firstPT = first;
- }
- return true;
- };
- p.parse = function(target, vars, pt, plugin) {
- var style = target.style,
- p, sp, bn, en, bs, es, bsfx, esfx, isStr, rel;
- for (p in vars) {
- es = vars[p]; //ending value string
- if (typeof(es) === "function") {
- es = es(_index, _target);
- }
- sp = _specialProps[p]; //SpecialProp lookup.
- if (sp) {
- pt = sp.parse(target, es, p, this, pt, plugin, vars);
- } else if (p.substr(0,2) === "--") { //for tweening CSS variables (which always start with "--"). To maximize performance and simplicity, we bypass CSSPlugin altogether and just add a normal property tween to the tween instance itself.
- this._tween._propLookup[p] = this._addTween.call(this._tween, target.style, "setProperty", _getComputedStyle(target).getPropertyValue(p) + "", es + "", p, false, p);
- continue;
- } else {
- bs = _getStyle(target, p, _cs) + "";
- isStr = (typeof(es) === "string");
- if (p === "color" || p === "fill" || p === "stroke" || p.indexOf("Color") !== -1 || (isStr && _rgbhslExp.test(es))) { //Opera uses background: to define color sometimes in addition to backgroundColor:
- if (!isStr) {
- es = _parseColor(es);
- es = ((es.length > 3) ? "rgba(" : "rgb(") + es.join(",") + ")";
- }
- pt = _parseComplex(style, p, bs, es, true, "transparent", pt, 0, plugin);
- } else if (isStr && _complexExp.test(es)) {
- pt = _parseComplex(style, p, bs, es, true, null, pt, 0, plugin);
- } else {
- bn = parseFloat(bs);
- bsfx = (bn || bn === 0) ? bs.substr((bn + "").length) : ""; //remember, bs could be non-numeric like "normal" for fontWeight, so we should default to a blank suffix in that case.
- if (bs === "" || bs === "auto") {
- if (p === "width" || p === "height") {
- bn = _getDimension(target, p, _cs);
- bsfx = "px";
- } else if (p === "left" || p === "top") {
- bn = _calculateOffset(target, p, _cs);
- bsfx = "px";
- } else {
- bn = (p !== "opacity") ? 0 : 1;
- bsfx = "";
- }
- }
- rel = (isStr && es.charAt(1) === "=");
- if (rel) {
- en = parseInt(es.charAt(0) + "1", 10);
- es = es.substr(2);
- en *= parseFloat(es);
- esfx = es.replace(_suffixExp, "");
- } else {
- en = parseFloat(es);
- esfx = isStr ? es.replace(_suffixExp, "") : "";
- }
- if (esfx === "") {
- esfx = (p in _suffixMap) ? _suffixMap[p] : bsfx; //populate the end suffix, prioritizing the map, then if none is found, use the beginning suffix.
- }
- es = (en || en === 0) ? (rel ? en + bn : en) + esfx : vars[p]; //ensures that any += or -= prefixes are taken care of. Record the end value before normalizing the suffix because we always want to end the tween on exactly what they intended even if it doesn't match the beginning value's suffix.
- //if the beginning/ending suffixes don't match, normalize them...
- if (bsfx !== esfx) if (esfx !== "" || p === "lineHeight") if (en || en === 0) if (bn) { //note: if the beginning value (bn) is 0, we don't need to convert units!
- bn = _convertToPixels(target, p, bn, bsfx);
- if (esfx === "%") {
- bn /= _convertToPixels(target, p, 100, "%") / 100;
- if (vars.strictUnits !== true) { //some browsers report only "px" values instead of allowing "%" with getComputedStyle(), so we assume that if we're tweening to a %, we should start there too unless strictUnits:true is defined. This approach is particularly useful for responsive designs that use from() tweens.
- bs = bn + "%";
- }
- } else if (esfx === "em" || esfx === "rem" || esfx === "vw" || esfx === "vh") {
- bn /= _convertToPixels(target, p, 1, esfx);
- //otherwise convert to pixels.
- } else if (esfx !== "px") {
- en = _convertToPixels(target, p, en, esfx);
- esfx = "px"; //we don't use bsfx after this, so we don't need to set it to px too.
- }
- if (rel) if (en || en === 0) {
- es = (en + bn) + esfx; //the changes we made affect relative calculations, so adjust the end value here.
- }
- }
- if (rel) {
- en += bn;
- }
- if ((bn || bn === 0) && (en || en === 0)) { //faster than isNaN(). Also, previously we required en !== bn but that doesn't really gain much performance and it prevents _parseToProxy() from working properly if beginning and ending values match but need to get tweened by an external plugin anyway. For example, a bezier tween where the target starts at left:0 and has these points: [{left:50},{left:0}] wouldn't work properly because when parsing the last point, it'd match the first (current) one and a non-tweening CSSPropTween would be recorded when we actually need a normal tween (type:0) so that things get updated during the tween properly.
- pt = new CSSPropTween(style, p, bn, en - bn, pt, 0, p, (_autoRound !== false && (esfx === "px" || p === "zIndex")), 0, bs, es);
- pt.xs0 = esfx;
- //DEBUG: _log("tween "+p+" from "+pt.b+" ("+bn+esfx+") to "+pt.e+" with suffix: "+pt.xs0);
- } else if (style[p] === undefined || !es && (es + "" === "NaN" || es == null)) {
- _log("invalid " + p + " tween value: " + vars[p]);
- } else {
- pt = new CSSPropTween(style, p, en || bn || 0, 0, pt, -1, p, false, 0, bs, es);
- pt.xs0 = (es === "none" && (p === "display" || p.indexOf("Style") !== -1)) ? bs : es; //intermediate value should typically be set immediately (end value) except for "display" or things like borderTopStyle, borderBottomStyle, etc. which should use the beginning value during the tween.
- //DEBUG: _log("non-tweening value "+p+": "+pt.xs0);
- }
- }
- }
- if (plugin) if (pt && !pt.plugin) {
- pt.plugin = plugin;
- }
- }
- return pt;
- };
- //gets called every time the tween updates, passing the new ratio (typically a value between 0 and 1, but not always (for example, if an Elastic.easeOut is used, the value can jump above 1 mid-tween). It will always start and 0 and end at 1.
- p.setRatio = function(v) {
- var pt = this._firstPT,
- min = 0.000001,
- val, str, i;
- //at the end of the tween, we set the values to exactly what we received in order to make sure non-tweening values (like "position" or "float" or whatever) are set and so that if the beginning/ending suffixes (units) didn't match and we normalized to px, the value that the user passed in is used here. We check to see if the tween is at its beginning in case it's a from() tween in which case the ratio will actually go from 1 to 0 over the course of the tween (backwards).
- if (v === 1 && (this._tween._time === this._tween._duration || this._tween._time === 0)) {
- while (pt) {
- if (pt.type !== 2) {
- if (pt.r && pt.type !== -1) {
- val = Math.round(pt.s + pt.c);
- if (!pt.type) {
- pt.t[pt.p] = val + pt.xs0;
- } else if (pt.type === 1) { //complex value (one that typically has multiple numbers inside a string, like "rect(5px,10px,20px,25px)"
- i = pt.l;
- str = pt.xs0 + val + pt.xs1;
- for (i = 1; i < pt.l; i++) {
- str += pt["xn"+i] + pt["xs"+(i+1)];
- }
- pt.t[pt.p] = str;
- }
- } else {
- pt.t[pt.p] = pt.e;
- }
- } else {
- pt.setRatio(v);
- }
- pt = pt._next;
- }
- } else if (v || !(this._tween._time === this._tween._duration || this._tween._time === 0) || this._tween._rawPrevTime === -0.000001) {
- while (pt) {
- val = pt.c * v + pt.s;
- if (pt.r) {
- val = Math.round(val);
- } else if (val < min) if (val > -min) {
- val = 0;
- }
- if (!pt.type) {
- pt.t[pt.p] = val + pt.xs0;
- } else if (pt.type === 1) { //complex value (one that typically has multiple numbers inside a string, like "rect(5px,10px,20px,25px)"
- i = pt.l;
- if (i === 2) {
- pt.t[pt.p] = pt.xs0 + val + pt.xs1 + pt.xn1 + pt.xs2;
- } else if (i === 3) {
- pt.t[pt.p] = pt.xs0 + val + pt.xs1 + pt.xn1 + pt.xs2 + pt.xn2 + pt.xs3;
- } else if (i === 4) {
- pt.t[pt.p] = pt.xs0 + val + pt.xs1 + pt.xn1 + pt.xs2 + pt.xn2 + pt.xs3 + pt.xn3 + pt.xs4;
- } else if (i === 5) {
- pt.t[pt.p] = pt.xs0 + val + pt.xs1 + pt.xn1 + pt.xs2 + pt.xn2 + pt.xs3 + pt.xn3 + pt.xs4 + pt.xn4 + pt.xs5;
- } else {
- str = pt.xs0 + val + pt.xs1;
- for (i = 1; i < pt.l; i++) {
- str += pt["xn"+i] + pt["xs"+(i+1)];
- }
- pt.t[pt.p] = str;
- }
- } else if (pt.type === -1) { //non-tweening value
- pt.t[pt.p] = pt.xs0;
- } else if (pt.setRatio) { //custom setRatio() for things like SpecialProps, external plugins, etc.
- pt.setRatio(v);
- }
- pt = pt._next;
- }
- //if the tween is reversed all the way back to the beginning, we need to restore the original values which may have different units (like % instead of px or em or whatever).
- } else {
- while (pt) {
- if (pt.type !== 2) {
- pt.t[pt.p] = pt.b;
- } else {
- pt.setRatio(v);
- }
- pt = pt._next;
- }
- }
- };
- /**
- * @private
- * Forces rendering of the target's transforms (rotation, scale, etc.) whenever the CSSPlugin's setRatio() is called.
- * Basically, this tells the CSSPlugin to create a CSSPropTween (type 2) after instantiation that runs last in the linked
- * list and calls the appropriate (3D or 2D) rendering function. We separate this into its own method so that we can call
- * it from other plugins like BezierPlugin if, for example, it needs to apply an autoRotation and this CSSPlugin
- * doesn't have any transform-related properties of its own. You can call this method as many times as you
- * want and it won't create duplicate CSSPropTweens.
- *
- * @param {boolean} threeD if true, it should apply 3D tweens (otherwise, just 2D ones are fine and typically faster)
- */
- p._enableTransforms = function(threeD) {
- this._transform = this._transform || _getTransform(this._target, _cs, true); //ensures that the element has a _gsTransform property with the appropriate values.
- this._transformType = (!(this._transform.svg && _useSVGTransformAttr) && (threeD || this._transformType === 3)) ? 3 : 2;
- };
- var lazySet = function(v) {
- this.t[this.p] = this.e;
- this.data._linkCSSP(this, this._next, null, true); //we purposefully keep this._next even though it'd make sense to null it, but this is a performance optimization, as this happens during the while (pt) {} loop in setRatio() at the bottom of which it sets pt = pt._next, so if we null it, the linked list will be broken in that loop.
- };
- /** @private Gives us a way to set a value on the first render (and only the first render). **/
- p._addLazySet = function(t, p, v) {
- var pt = this._firstPT = new CSSPropTween(t, p, 0, 0, this._firstPT, 2);
- pt.e = v;
- pt.setRatio = lazySet;
- pt.data = this;
- };
- /** @private **/
- p._linkCSSP = function(pt, next, prev, remove) {
- if (pt) {
- if (next) {
- next._prev = pt;
- }
- if (pt._next) {
- pt._next._prev = pt._prev;
- }
- if (pt._prev) {
- pt._prev._next = pt._next;
- } else if (this._firstPT === pt) {
- this._firstPT = pt._next;
- remove = true; //just to prevent resetting this._firstPT 5 lines down in case pt._next is null. (optimized for speed)
- }
- if (prev) {
- prev._next = pt;
- } else if (!remove && this._firstPT === null) {
- this._firstPT = pt;
- }
- pt._next = next;
- pt._prev = prev;
- }
- return pt;
- };
- p._mod = function(lookup) {
- var pt = this._firstPT;
- while (pt) {
- if (typeof(lookup[pt.p]) === "function" && lookup[pt.p] === Math.round) { //only gets called by RoundPropsPlugin (ModifyPlugin manages all the rendering internally for CSSPlugin properties that need modification). Remember, we handle rounding a bit differently in this plugin for performance reasons, leveraging "r" as an indicator that the value should be rounded internally..
- pt.r = 1;
- }
- pt = pt._next;
- }
- };
- //we need to make sure that if alpha or autoAlpha is killed, opacity is too. And autoAlpha affects the "visibility" property.
- p._kill = function(lookup) {
- var copy = lookup,
- pt, p, xfirst;
- if (lookup.autoAlpha || lookup.alpha) {
- copy = {};
- for (p in lookup) { //copy the lookup so that we're not changing the original which may be passed elsewhere.
- copy[p] = lookup[p];
- }
- copy.opacity = 1;
- if (copy.autoAlpha) {
- copy.visibility = 1;
- }
- }
- if (lookup.className && (pt = this._classNamePT)) { //for className tweens, we need to kill any associated CSSPropTweens too; a linked list starts at the className's "xfirst".
- xfirst = pt.xfirst;
- if (xfirst && xfirst._prev) {
- this._linkCSSP(xfirst._prev, pt._next, xfirst._prev._prev); //break off the prev
- } else if (xfirst === this._firstPT) {
- this._firstPT = pt._next;
- }
- if (pt._next) {
- this._linkCSSP(pt._next, pt._next._next, xfirst._prev);
- }
- this._classNamePT = null;
- }
- pt = this._firstPT;
- while (pt) {
- if (pt.plugin && pt.plugin !== p && pt.plugin._kill) { //for plugins that are registered with CSSPlugin, we should notify them of the kill.
- pt.plugin._kill(lookup);
- p = pt.plugin;
- }
- pt = pt._next;
- }
- return TweenPlugin.prototype._kill.call(this, copy);
- };
- //used by cascadeTo() for gathering all the style properties of each child element into an array for comparison.
- var _getChildStyles = function(e, props, targets) {
- var children, i, child, type;
- if (e.slice) {
- i = e.length;
- while (--i > -1) {
- _getChildStyles(e[i], props, targets);
- }
- return;
- }
- children = e.childNodes;
- i = children.length;
- while (--i > -1) {
- child = children[i];
- type = child.type;
- if (child.style) {
- props.push(_getAllStyles(child));
- if (targets) {
- targets.push(child);
- }
- }
- if ((type === 1 || type === 9 || type === 11) && child.childNodes.length) {
- _getChildStyles(child, props, targets);
- }
- }
- };
- /**
- * Typically only useful for className tweens that may affect child elements, this method creates a TweenLite
- * and then compares the style properties of all the target's child elements at the tween's start and end, and
- * if any are different, it also creates tweens for those and returns an array containing ALL of the resulting
- * tweens (so that you can easily add() them to a TimelineLite, for example). The reason this functionality is
- * wrapped into a separate static method of CSSPlugin instead of being integrated into all regular className tweens
- * is because it creates entirely new tweens that may have completely different targets than the original tween,
- * so if they were all lumped into the original tween instance, it would be inconsistent with the rest of the API
- * and it would create other problems. For example:
- * - If I create a tween of elementA, that tween instance may suddenly change its target to include 50 other elements (unintuitive if I specifically defined the target I wanted)
- * - We can't just create new independent tweens because otherwise, what happens if the original/parent tween is reversed or pause or dropped into a TimelineLite for tight control? You'd expect that tween's behavior to affect all the others.
- * - Analyzing every style property of every child before and after the tween is an expensive operation when there are many children, so this behavior shouldn't be imposed on all className tweens by default, especially since it's probably rare that this extra functionality is needed.
- *
- * @param {Object} target object to be tweened
- * @param {number} Duration in seconds (or frames for frames-based tweens)
- * @param {Object} Object containing the end values, like {className:"newClass", ease:Linear.easeNone}
- * @return {Array} An array of TweenLite instances
- */
- CSSPlugin.cascadeTo = function(target, duration, vars) {
- var tween = TweenLite.to(target, duration, vars),
- results = [tween],
- b = [],
- e = [],
- targets = [],
- _reservedProps = TweenLite._internals.reservedProps,
- i, difs, p, from;
- target = tween._targets || tween.target;
- _getChildStyles(target, b, targets);
- tween.render(duration, true, true);
- _getChildStyles(target, e);
- tween.render(0, true, true);
- tween._enabled(true);
- i = targets.length;
- while (--i > -1) {
- difs = _cssDif(targets[i], b[i], e[i]);
- if (difs.firstMPT) {
- difs = difs.difs;
- for (p in vars) {
- if (_reservedProps[p]) {
- difs[p] = vars[p];
- }
- }
- from = {};
- for (p in difs) {
- from[p] = b[i][p];
- }
- results.push(TweenLite.fromTo(targets[i], duration, from, difs));
- }
- }
- return results;
- };
- TweenPlugin.activate([CSSPlugin]);
- return CSSPlugin;
- }, true);
-
-
-
-
-
-
-
-
-
-
- /*
- * ----------------------------------------------------------------
- * RoundPropsPlugin
- * ----------------------------------------------------------------
- */
- (function() {
- var RoundPropsPlugin = _gsScope._gsDefine.plugin({
- propName: "roundProps",
- version: "1.6.0",
- priority: -1,
- API: 2,
- //called when the tween renders for the first time. This is where initial values should be recorded and any setup routines should run.
- init: function(target, value, tween) {
- this._tween = tween;
- return true;
- }
- }),
- _roundLinkedList = function(node) {
- while (node) {
- if (!node.f && !node.blob) {
- node.m = Math.round;
- }
- node = node._next;
- }
- },
- p = RoundPropsPlugin.prototype;
- p._onInitAllProps = function() {
- var tween = this._tween,
- rp = (tween.vars.roundProps.join) ? tween.vars.roundProps : tween.vars.roundProps.split(","),
- i = rp.length,
- lookup = {},
- rpt = tween._propLookup.roundProps,
- prop, pt, next;
- while (--i > -1) {
- lookup[rp[i]] = Math.round;
- }
- i = rp.length;
- while (--i > -1) {
- prop = rp[i];
- pt = tween._firstPT;
- while (pt) {
- next = pt._next; //record here, because it may get removed
- if (pt.pg) {
- pt.t._mod(lookup);
- } else if (pt.n === prop) {
- if (pt.f === 2 && pt.t) { //a blob (text containing multiple numeric values)
- _roundLinkedList(pt.t._firstPT);
- } else {
- this._add(pt.t, prop, pt.s, pt.c);
- //remove from linked list
- if (next) {
- next._prev = pt._prev;
- }
- if (pt._prev) {
- pt._prev._next = next;
- } else if (tween._firstPT === pt) {
- tween._firstPT = next;
- }
- pt._next = pt._prev = null;
- tween._propLookup[prop] = rpt;
- }
- }
- pt = next;
- }
- }
- return false;
- };
- p._add = function(target, p, s, c) {
- this._addTween(target, p, s, s + c, p, Math.round);
- this._overwriteProps.push(p);
- };
- }());
- /*
- * ----------------------------------------------------------------
- * AttrPlugin
- * ----------------------------------------------------------------
- */
- (function() {
- _gsScope._gsDefine.plugin({
- propName: "attr",
- API: 2,
- version: "0.6.1",
- //called when the tween renders for the first time. This is where initial values should be recorded and any setup routines should run.
- init: function(target, value, tween, index) {
- var p, end;
- if (typeof(target.setAttribute) !== "function") {
- return false;
- }
- for (p in value) {
- end = value[p];
- if (typeof(end) === "function") {
- end = end(index, target);
- }
- this._addTween(target, "setAttribute", target.getAttribute(p) + "", end + "", p, false, p);
- this._overwriteProps.push(p);
- }
- return true;
- }
- });
- }());
- /*
- * ----------------------------------------------------------------
- * DirectionalRotationPlugin
- * ----------------------------------------------------------------
- */
- _gsScope._gsDefine.plugin({
- propName: "directionalRotation",
- version: "0.3.1",
- API: 2,
- //called when the tween renders for the first time. This is where initial values should be recorded and any setup routines should run.
- init: function(target, value, tween, index) {
- if (typeof(value) !== "object") {
- value = {rotation:value};
- }
- this.finals = {};
- var cap = (value.useRadians === true) ? Math.PI * 2 : 360,
- min = 0.000001,
- p, v, start, end, dif, split;
- for (p in value) {
- if (p !== "useRadians") {
- end = value[p];
- if (typeof(end) === "function") {
- end = end(index, target);
- }
- split = (end + "").split("_");
- v = split[0];
- start = parseFloat( (typeof(target[p]) !== "function") ? target[p] : target[ ((p.indexOf("set") || typeof(target["get" + p.substr(3)]) !== "function") ? p : "get" + p.substr(3)) ]() );
- end = this.finals[p] = (typeof(v) === "string" && v.charAt(1) === "=") ? start + parseInt(v.charAt(0) + "1", 10) * Number(v.substr(2)) : Number(v) || 0;
- dif = end - start;
- if (split.length) {
- v = split.join("_");
- if (v.indexOf("short") !== -1) {
- dif = dif % cap;
- if (dif !== dif % (cap / 2)) {
- dif = (dif < 0) ? dif + cap : dif - cap;
- }
- }
- if (v.indexOf("_cw") !== -1 && dif < 0) {
- dif = ((dif + cap * 9999999999) % cap) - ((dif / cap) | 0) * cap;
- } else if (v.indexOf("ccw") !== -1 && dif > 0) {
- dif = ((dif - cap * 9999999999) % cap) - ((dif / cap) | 0) * cap;
- }
- }
- if (dif > min || dif < -min) {
- this._addTween(target, p, start, start + dif, p);
- this._overwriteProps.push(p);
- }
- }
- }
- return true;
- },
- //called each time the values should be updated, and the ratio gets passed as the only parameter (typically it's a value between 0 and 1, but it can exceed those when using an ease like Elastic.easeOut or Back.easeOut, etc.)
- set: function(ratio) {
- var pt;
- if (ratio !== 1) {
- this._super.setRatio.call(this, ratio);
- } else {
- pt = this._firstPT;
- while (pt) {
- if (pt.f) {
- pt.t[pt.p](this.finals[pt.p]);
- } else {
- pt.t[pt.p] = this.finals[pt.p];
- }
- pt = pt._next;
- }
- }
- }
- })._autoCSS = true;
-
-
-
-
- /*
- * ----------------------------------------------------------------
- * EasePack
- * ----------------------------------------------------------------
- */
- _gsScope._gsDefine("easing.Back", ["easing.Ease"], function(Ease) {
-
- var w = (_gsScope.GreenSockGlobals || _gsScope),
- gs = w.com.greensock,
- _2PI = Math.PI * 2,
- _HALF_PI = Math.PI / 2,
- _class = gs._class,
- _create = function(n, f) {
- var C = _class("easing." + n, function(){}, true),
- p = C.prototype = new Ease();
- p.constructor = C;
- p.getRatio = f;
- return C;
- },
- _easeReg = Ease.register || function(){}, //put an empty function in place just as a safety measure in case someone loads an OLD version of TweenLite.js where Ease.register doesn't exist.
- _wrap = function(name, EaseOut, EaseIn, EaseInOut, aliases) {
- var C = _class("easing."+name, {
- easeOut:new EaseOut(),
- easeIn:new EaseIn(),
- easeInOut:new EaseInOut()
- }, true);
- _easeReg(C, name);
- return C;
- },
- EasePoint = function(time, value, next) {
- this.t = time;
- this.v = value;
- if (next) {
- this.next = next;
- next.prev = this;
- this.c = next.v - value;
- this.gap = next.t - time;
- }
- },
- //Back
- _createBack = function(n, f) {
- var C = _class("easing." + n, function(overshoot) {
- this._p1 = (overshoot || overshoot === 0) ? overshoot : 1.70158;
- this._p2 = this._p1 * 1.525;
- }, true),
- p = C.prototype = new Ease();
- p.constructor = C;
- p.getRatio = f;
- p.config = function(overshoot) {
- return new C(overshoot);
- };
- return C;
- },
- Back = _wrap("Back",
- _createBack("BackOut", function(p) {
- return ((p = p - 1) * p * ((this._p1 + 1) * p + this._p1) + 1);
- }),
- _createBack("BackIn", function(p) {
- return p * p * ((this._p1 + 1) * p - this._p1);
- }),
- _createBack("BackInOut", function(p) {
- return ((p *= 2) < 1) ? 0.5 * p * p * ((this._p2 + 1) * p - this._p2) : 0.5 * ((p -= 2) * p * ((this._p2 + 1) * p + this._p2) + 2);
- })
- ),
- //SlowMo
- SlowMo = _class("easing.SlowMo", function(linearRatio, power, yoyoMode) {
- power = (power || power === 0) ? power : 0.7;
- if (linearRatio == null) {
- linearRatio = 0.7;
- } else if (linearRatio > 1) {
- linearRatio = 1;
- }
- this._p = (linearRatio !== 1) ? power : 0;
- this._p1 = (1 - linearRatio) / 2;
- this._p2 = linearRatio;
- this._p3 = this._p1 + this._p2;
- this._calcEnd = (yoyoMode === true);
- }, true),
- p = SlowMo.prototype = new Ease(),
- SteppedEase, RoughEase, _createElastic;
- p.constructor = SlowMo;
- p.getRatio = function(p) {
- var r = p + (0.5 - p) * this._p;
- if (p < this._p1) {
- return this._calcEnd ? 1 - ((p = 1 - (p / this._p1)) * p) : r - ((p = 1 - (p / this._p1)) * p * p * p * r);
- } else if (p > this._p3) {
- return this._calcEnd ? 1 - (p = (p - this._p3) / this._p1) * p : r + ((p - r) * (p = (p - this._p3) / this._p1) * p * p * p);
- }
- return this._calcEnd ? 1 : r;
- };
- SlowMo.ease = new SlowMo(0.7, 0.7);
- p.config = SlowMo.config = function(linearRatio, power, yoyoMode) {
- return new SlowMo(linearRatio, power, yoyoMode);
- };
- //SteppedEase
- SteppedEase = _class("easing.SteppedEase", function(steps, immediateStart) {
- steps = steps || 1;
- this._p1 = 1 / steps;
- this._p2 = steps + (immediateStart ? 0 : 1);
- this._p3 = immediateStart ? 1 : 0;
- }, true);
- p = SteppedEase.prototype = new Ease();
- p.constructor = SteppedEase;
- p.getRatio = function(p) {
- if (p < 0) {
- p = 0;
- } else if (p >= 1) {
- p = 0.999999999;
- }
- return (((this._p2 * p) | 0) + this._p3) * this._p1;
- };
- p.config = SteppedEase.config = function(steps, immediateStart) {
- return new SteppedEase(steps, immediateStart);
- };
- //RoughEase
- RoughEase = _class("easing.RoughEase", function(vars) {
- vars = vars || {};
- var taper = vars.taper || "none",
- a = [],
- cnt = 0,
- points = (vars.points || 20) | 0,
- i = points,
- randomize = (vars.randomize !== false),
- clamp = (vars.clamp === true),
- template = (vars.template instanceof Ease) ? vars.template : null,
- strength = (typeof(vars.strength) === "number") ? vars.strength * 0.4 : 0.4,
- x, y, bump, invX, obj, pnt;
- while (--i > -1) {
- x = randomize ? Math.random() : (1 / points) * i;
- y = template ? template.getRatio(x) : x;
- if (taper === "none") {
- bump = strength;
- } else if (taper === "out") {
- invX = 1 - x;
- bump = invX * invX * strength;
- } else if (taper === "in") {
- bump = x * x * strength;
- } else if (x < 0.5) { //"both" (start)
- invX = x * 2;
- bump = invX * invX * 0.5 * strength;
- } else { //"both" (end)
- invX = (1 - x) * 2;
- bump = invX * invX * 0.5 * strength;
- }
- if (randomize) {
- y += (Math.random() * bump) - (bump * 0.5);
- } else if (i % 2) {
- y += bump * 0.5;
- } else {
- y -= bump * 0.5;
- }
- if (clamp) {
- if (y > 1) {
- y = 1;
- } else if (y < 0) {
- y = 0;
- }
- }
- a[cnt++] = {x:x, y:y};
- }
- a.sort(function(a, b) {
- return a.x - b.x;
- });
- pnt = new EasePoint(1, 1, null);
- i = points;
- while (--i > -1) {
- obj = a[i];
- pnt = new EasePoint(obj.x, obj.y, pnt);
- }
- this._prev = new EasePoint(0, 0, (pnt.t !== 0) ? pnt : pnt.next);
- }, true);
- p = RoughEase.prototype = new Ease();
- p.constructor = RoughEase;
- p.getRatio = function(p) {
- var pnt = this._prev;
- if (p > pnt.t) {
- while (pnt.next && p >= pnt.t) {
- pnt = pnt.next;
- }
- pnt = pnt.prev;
- } else {
- while (pnt.prev && p <= pnt.t) {
- pnt = pnt.prev;
- }
- }
- this._prev = pnt;
- return (pnt.v + ((p - pnt.t) / pnt.gap) * pnt.c);
- };
- p.config = function(vars) {
- return new RoughEase(vars);
- };
- RoughEase.ease = new RoughEase();
- //Bounce
- _wrap("Bounce",
- _create("BounceOut", function(p) {
- if (p < 1 / 2.75) {
- return 7.5625 * p * p;
- } else if (p < 2 / 2.75) {
- return 7.5625 * (p -= 1.5 / 2.75) * p + 0.75;
- } else if (p < 2.5 / 2.75) {
- return 7.5625 * (p -= 2.25 / 2.75) * p + 0.9375;
- }
- return 7.5625 * (p -= 2.625 / 2.75) * p + 0.984375;
- }),
- _create("BounceIn", function(p) {
- if ((p = 1 - p) < 1 / 2.75) {
- return 1 - (7.5625 * p * p);
- } else if (p < 2 / 2.75) {
- return 1 - (7.5625 * (p -= 1.5 / 2.75) * p + 0.75);
- } else if (p < 2.5 / 2.75) {
- return 1 - (7.5625 * (p -= 2.25 / 2.75) * p + 0.9375);
- }
- return 1 - (7.5625 * (p -= 2.625 / 2.75) * p + 0.984375);
- }),
- _create("BounceInOut", function(p) {
- var invert = (p < 0.5);
- if (invert) {
- p = 1 - (p * 2);
- } else {
- p = (p * 2) - 1;
- }
- if (p < 1 / 2.75) {
- p = 7.5625 * p * p;
- } else if (p < 2 / 2.75) {
- p = 7.5625 * (p -= 1.5 / 2.75) * p + 0.75;
- } else if (p < 2.5 / 2.75) {
- p = 7.5625 * (p -= 2.25 / 2.75) * p + 0.9375;
- } else {
- p = 7.5625 * (p -= 2.625 / 2.75) * p + 0.984375;
- }
- return invert ? (1 - p) * 0.5 : p * 0.5 + 0.5;
- })
- );
- //CIRC
- _wrap("Circ",
- _create("CircOut", function(p) {
- return Math.sqrt(1 - (p = p - 1) * p);
- }),
- _create("CircIn", function(p) {
- return -(Math.sqrt(1 - (p * p)) - 1);
- }),
- _create("CircInOut", function(p) {
- return ((p*=2) < 1) ? -0.5 * (Math.sqrt(1 - p * p) - 1) : 0.5 * (Math.sqrt(1 - (p -= 2) * p) + 1);
- })
- );
- //Elastic
- _createElastic = function(n, f, def) {
- var C = _class("easing." + n, function(amplitude, period) {
- this._p1 = (amplitude >= 1) ? amplitude : 1; //note: if amplitude is < 1, we simply adjust the period for a more natural feel. Otherwise the math doesn't work right and the curve starts at 1.
- this._p2 = (period || def) / (amplitude < 1 ? amplitude : 1);
- this._p3 = this._p2 / _2PI * (Math.asin(1 / this._p1) || 0);
- this._p2 = _2PI / this._p2; //precalculate to optimize
- }, true),
- p = C.prototype = new Ease();
- p.constructor = C;
- p.getRatio = f;
- p.config = function(amplitude, period) {
- return new C(amplitude, period);
- };
- return C;
- };
- _wrap("Elastic",
- _createElastic("ElasticOut", function(p) {
- return this._p1 * Math.pow(2, -10 * p) * Math.sin( (p - this._p3) * this._p2 ) + 1;
- }, 0.3),
- _createElastic("ElasticIn", function(p) {
- return -(this._p1 * Math.pow(2, 10 * (p -= 1)) * Math.sin( (p - this._p3) * this._p2 ));
- }, 0.3),
- _createElastic("ElasticInOut", function(p) {
- return ((p *= 2) < 1) ? -0.5 * (this._p1 * Math.pow(2, 10 * (p -= 1)) * Math.sin( (p - this._p3) * this._p2)) : this._p1 * Math.pow(2, -10 *(p -= 1)) * Math.sin( (p - this._p3) * this._p2 ) * 0.5 + 1;
- }, 0.45)
- );
- //Expo
- _wrap("Expo",
- _create("ExpoOut", function(p) {
- return 1 - Math.pow(2, -10 * p);
- }),
- _create("ExpoIn", function(p) {
- return Math.pow(2, 10 * (p - 1)) - 0.001;
- }),
- _create("ExpoInOut", function(p) {
- return ((p *= 2) < 1) ? 0.5 * Math.pow(2, 10 * (p - 1)) : 0.5 * (2 - Math.pow(2, -10 * (p - 1)));
- })
- );
- //Sine
- _wrap("Sine",
- _create("SineOut", function(p) {
- return Math.sin(p * _HALF_PI);
- }),
- _create("SineIn", function(p) {
- return -Math.cos(p * _HALF_PI) + 1;
- }),
- _create("SineInOut", function(p) {
- return -0.5 * (Math.cos(Math.PI * p) - 1);
- })
- );
- _class("easing.EaseLookup", {
- find:function(s) {
- return Ease.map[s];
- }
- }, true);
- //register the non-standard eases
- _easeReg(w.SlowMo, "SlowMo", "ease,");
- _easeReg(RoughEase, "RoughEase", "ease,");
- _easeReg(SteppedEase, "SteppedEase", "ease,");
- return Back;
-
- }, true);
- });
- if (_gsScope._gsDefine) { _gsScope._gsQueue.pop()(); } //necessary in case TweenLite was already loaded separately.
- /*
- * ----------------------------------------------------------------
- * Base classes like TweenLite, SimpleTimeline, Ease, Ticker, etc.
- * ----------------------------------------------------------------
- */
- (function(window, moduleName) {
- "use strict";
- var _exports = {},
- _doc = window.document,
- _globals = window.GreenSockGlobals = window.GreenSockGlobals || window;
- if (_globals.TweenLite) {
- return; //in case the core set of classes is already loaded, don't instantiate twice.
- }
- var _namespace = function(ns) {
- var a = ns.split("."),
- p = _globals, i;
- for (i = 0; i < a.length; i++) {
- p[a[i]] = p = p[a[i]] || {};
- }
- return p;
- },
- gs = _namespace("com.greensock"),
- _tinyNum = 0.0000000001,
- _slice = function(a) { //don't use Array.prototype.slice.call(target, 0) because that doesn't work in IE8 with a NodeList that's returned by querySelectorAll()
- var b = [],
- l = a.length,
- i;
- for (i = 0; i !== l; b.push(a[i++])) {}
- return b;
- },
- _emptyFunc = function() {},
- _isArray = (function() { //works around issues in iframe environments where the Array global isn't shared, thus if the object originates in a different window/iframe, "(obj instanceof Array)" will evaluate false. We added some speed optimizations to avoid Object.prototype.toString.call() unless it's absolutely necessary because it's VERY slow (like 20x slower)
- var toString = Object.prototype.toString,
- array = toString.call([]);
- return function(obj) {
- return obj != null && (obj instanceof Array || (typeof(obj) === "object" && !!obj.push && toString.call(obj) === array));
- };
- }()),
- a, i, p, _ticker, _tickerActive,
- _defLookup = {},
- /**
- * @constructor
- * Defines a GreenSock class, optionally with an array of dependencies that must be instantiated first and passed into the definition.
- * This allows users to load GreenSock JS files in any order even if they have interdependencies (like CSSPlugin extends TweenPlugin which is
- * inside TweenLite.js, but if CSSPlugin is loaded first, it should wait to run its code until TweenLite.js loads and instantiates TweenPlugin
- * and then pass TweenPlugin to CSSPlugin's definition). This is all done automatically and internally.
- *
- * Every definition will be added to a "com.greensock" global object (typically window, but if a window.GreenSockGlobals object is found,
- * it will go there as of v1.7). For example, TweenLite will be found at window.com.greensock.TweenLite and since it's a global class that should be available anywhere,
- * it is ALSO referenced at window.TweenLite. However some classes aren't considered global, like the base com.greensock.core.Animation class, so
- * those will only be at the package like window.com.greensock.core.Animation. Again, if you define a GreenSockGlobals object on the window, everything
- * gets tucked neatly inside there instead of on the window directly. This allows you to do advanced things like load multiple versions of GreenSock
- * files and put them into distinct objects (imagine a banner ad uses a newer version but the main site uses an older one). In that case, you could
- * sandbox the banner one like:
- *
- * <script>
- * var gs = window.GreenSockGlobals = {}; //the newer version we're about to load could now be referenced in a "gs" object, like gs.TweenLite.to(...). Use whatever alias you want as long as it's unique, "gs" or "banner" or whatever.
- * </script>
- * <script src="js/greensock/v1.7/TweenMax.js"></script>
- * <script>
- * window.GreenSockGlobals = window._gsQueue = window._gsDefine = null; //reset it back to null (along with the special _gsQueue variable) so that the next load of TweenMax affects the window and we can reference things directly like TweenLite.to(...)
- * </script>
- * <script src="js/greensock/v1.6/TweenMax.js"></script>
- * <script>
- * gs.TweenLite.to(...); //would use v1.7
- * TweenLite.to(...); //would use v1.6
- * </script>
- *
- * @param {!string} ns The namespace of the class definition, leaving off "com.greensock." as that's assumed. For example, "TweenLite" or "plugins.CSSPlugin" or "easing.Back".
- * @param {!Array.<string>} dependencies An array of dependencies (described as their namespaces minus "com.greensock." prefix). For example ["TweenLite","plugins.TweenPlugin","core.Animation"]
- * @param {!function():Object} func The function that should be called and passed the resolved dependencies which will return the actual class for this definition.
- * @param {boolean=} global If true, the class will be added to the global scope (typically window unless you define a window.GreenSockGlobals object)
- */
- Definition = function(ns, dependencies, func, global) {
- this.sc = (_defLookup[ns]) ? _defLookup[ns].sc : []; //subclasses
- _defLookup[ns] = this;
- this.gsClass = null;
- this.func = func;
- var _classes = [];
- this.check = function(init) {
- var i = dependencies.length,
- missing = i,
- cur, a, n, cl;
- while (--i > -1) {
- if ((cur = _defLookup[dependencies[i]] || new Definition(dependencies[i], [])).gsClass) {
- _classes[i] = cur.gsClass;
- missing--;
- } else if (init) {
- cur.sc.push(this);
- }
- }
- if (missing === 0 && func) {
- a = ("com.greensock." + ns).split(".");
- n = a.pop();
- cl = _namespace(a.join("."))[n] = this.gsClass = func.apply(func, _classes);
- //exports to multiple environments
- if (global) {
- _globals[n] = _exports[n] = cl; //provides a way to avoid global namespace pollution. By default, the main classes like TweenLite, Power1, Strong, etc. are added to window unless a GreenSockGlobals is defined. So if you want to have things added to a custom object instead, just do something like window.GreenSockGlobals = {} before loading any GreenSock files. You can even set up an alias like window.GreenSockGlobals = windows.gs = {} so that you can access everything like gs.TweenLite. Also remember that ALL classes are added to the window.com.greensock object (in their respective packages, like com.greensock.easing.Power1, com.greensock.TweenLite, etc.)
- if (typeof(module) !== "undefined" && module.exports) { //node
- if (ns === moduleName) {
- module.exports = _exports[moduleName] = cl;
- for (i in _exports) {
- cl[i] = _exports[i];
- }
- } else if (_exports[moduleName]) {
- _exports[moduleName][n] = cl;
- }
- } else if (typeof(define) === "function" && define.amd){ //AMD
- define((window.GreenSockAMDPath ? window.GreenSockAMDPath + "/" : "") + ns.split(".").pop(), [], function() { return cl; });
- }
- }
- for (i = 0; i < this.sc.length; i++) {
- this.sc[i].check();
- }
- }
- };
- this.check(true);
- },
- //used to create Definition instances (which basically registers a class that has dependencies).
- _gsDefine = window._gsDefine = function(ns, dependencies, func, global) {
- return new Definition(ns, dependencies, func, global);
- },
- //a quick way to create a class that doesn't have any dependencies. Returns the class, but first registers it in the GreenSock namespace so that other classes can grab it (other classes might be dependent on the class).
- _class = gs._class = function(ns, func, global) {
- func = func || function() {};
- _gsDefine(ns, [], function(){ return func; }, global);
- return func;
- };
- _gsDefine.globals = _globals;
- /*
- * ----------------------------------------------------------------
- * Ease
- * ----------------------------------------------------------------
- */
- var _baseParams = [0, 0, 1, 1],
- Ease = _class("easing.Ease", function(func, extraParams, type, power) {
- this._func = func;
- this._type = type || 0;
- this._power = power || 0;
- this._params = extraParams ? _baseParams.concat(extraParams) : _baseParams;
- }, true),
- _easeMap = Ease.map = {},
- _easeReg = Ease.register = function(ease, names, types, create) {
- var na = names.split(","),
- i = na.length,
- ta = (types || "easeIn,easeOut,easeInOut").split(","),
- e, name, j, type;
- while (--i > -1) {
- name = na[i];
- e = create ? _class("easing."+name, null, true) : gs.easing[name] || {};
- j = ta.length;
- while (--j > -1) {
- type = ta[j];
- _easeMap[name + "." + type] = _easeMap[type + name] = e[type] = ease.getRatio ? ease : ease[type] || new ease();
- }
- }
- };
- p = Ease.prototype;
- p._calcEnd = false;
- p.getRatio = function(p) {
- if (this._func) {
- this._params[0] = p;
- return this._func.apply(null, this._params);
- }
- var t = this._type,
- pw = this._power,
- r = (t === 1) ? 1 - p : (t === 2) ? p : (p < 0.5) ? p * 2 : (1 - p) * 2;
- if (pw === 1) {
- r *= r;
- } else if (pw === 2) {
- r *= r * r;
- } else if (pw === 3) {
- r *= r * r * r;
- } else if (pw === 4) {
- r *= r * r * r * r;
- }
- return (t === 1) ? 1 - r : (t === 2) ? r : (p < 0.5) ? r / 2 : 1 - (r / 2);
- };
- //create all the standard eases like Linear, Quad, Cubic, Quart, Quint, Strong, Power0, Power1, Power2, Power3, and Power4 (each with easeIn, easeOut, and easeInOut)
- a = ["Linear","Quad","Cubic","Quart","Quint,Strong"];
- i = a.length;
- while (--i > -1) {
- p = a[i]+",Power"+i;
- _easeReg(new Ease(null,null,1,i), p, "easeOut", true);
- _easeReg(new Ease(null,null,2,i), p, "easeIn" + ((i === 0) ? ",easeNone" : ""));
- _easeReg(new Ease(null,null,3,i), p, "easeInOut");
- }
- _easeMap.linear = gs.easing.Linear.easeIn;
- _easeMap.swing = gs.easing.Quad.easeInOut; //for jQuery folks
- /*
- * ----------------------------------------------------------------
- * EventDispatcher
- * ----------------------------------------------------------------
- */
- var EventDispatcher = _class("events.EventDispatcher", function(target) {
- this._listeners = {};
- this._eventTarget = target || this;
- });
- p = EventDispatcher.prototype;
- p.addEventListener = function(type, callback, scope, useParam, priority) {
- priority = priority || 0;
- var list = this._listeners[type],
- index = 0,
- listener, i;
- if (this === _ticker && !_tickerActive) {
- _ticker.wake();
- }
- if (list == null) {
- this._listeners[type] = list = [];
- }
- i = list.length;
- while (--i > -1) {
- listener = list[i];
- if (listener.c === callback && listener.s === scope) {
- list.splice(i, 1);
- } else if (index === 0 && listener.pr < priority) {
- index = i + 1;
- }
- }
- list.splice(index, 0, {c:callback, s:scope, up:useParam, pr:priority});
- };
- p.removeEventListener = function(type, callback) {
- var list = this._listeners[type], i;
- if (list) {
- i = list.length;
- while (--i > -1) {
- if (list[i].c === callback) {
- list.splice(i, 1);
- return;
- }
- }
- }
- };
- p.dispatchEvent = function(type) {
- var list = this._listeners[type],
- i, t, listener;
- if (list) {
- i = list.length;
- if (i > 1) {
- list = list.slice(0); //in case addEventListener() is called from within a listener/callback (otherwise the index could change, resulting in a skip)
- }
- t = this._eventTarget;
- while (--i > -1) {
- listener = list[i];
- if (listener) {
- if (listener.up) {
- listener.c.call(listener.s || t, {type:type, target:t});
- } else {
- listener.c.call(listener.s || t);
- }
- }
- }
- }
- };
- /*
- * ----------------------------------------------------------------
- * Ticker
- * ----------------------------------------------------------------
- */
- var _reqAnimFrame = window.requestAnimationFrame,
- _cancelAnimFrame = window.cancelAnimationFrame,
- _getTime = Date.now || function() {return new Date().getTime();},
- _lastUpdate = _getTime();
- //now try to determine the requestAnimationFrame and cancelAnimationFrame functions and if none are found, we'll use a setTimeout()/clearTimeout() polyfill.
- a = ["ms","moz","webkit","o"];
- i = a.length;
- while (--i > -1 && !_reqAnimFrame) {
- _reqAnimFrame = window[a[i] + "RequestAnimationFrame"];
- _cancelAnimFrame = window[a[i] + "CancelAnimationFrame"] || window[a[i] + "CancelRequestAnimationFrame"];
- }
- _class("Ticker", function(fps, useRAF) {
- var _self = this,
- _startTime = _getTime(),
- _useRAF = (useRAF !== false && _reqAnimFrame) ? "auto" : false,
- _lagThreshold = 500,
- _adjustedLag = 33,
- _tickWord = "tick", //helps reduce gc burden
- _fps, _req, _id, _gap, _nextTime,
- _tick = function(manual) {
- var elapsed = _getTime() - _lastUpdate,
- overlap, dispatch;
- if (elapsed > _lagThreshold) {
- _startTime += elapsed - _adjustedLag;
- }
- _lastUpdate += elapsed;
- _self.time = (_lastUpdate - _startTime) / 1000;
- overlap = _self.time - _nextTime;
- if (!_fps || overlap > 0 || manual === true) {
- _self.frame++;
- _nextTime += overlap + (overlap >= _gap ? 0.004 : _gap - overlap);
- dispatch = true;
- }
- if (manual !== true) { //make sure the request is made before we dispatch the "tick" event so that timing is maintained. Otherwise, if processing the "tick" requires a bunch of time (like 15ms) and we're using a setTimeout() that's based on 16.7ms, it'd technically take 31.7ms between frames otherwise.
- _id = _req(_tick);
- }
- if (dispatch) {
- _self.dispatchEvent(_tickWord);
- }
- };
- EventDispatcher.call(_self);
- _self.time = _self.frame = 0;
- _self.tick = function() {
- _tick(true);
- };
- _self.lagSmoothing = function(threshold, adjustedLag) {
- _lagThreshold = threshold || (1 / _tinyNum); //zero should be interpreted as basically unlimited
- _adjustedLag = Math.min(adjustedLag, _lagThreshold, 0);
- };
- _self.sleep = function() {
- if (_id == null) {
- return;
- }
- if (!_useRAF || !_cancelAnimFrame) {
- clearTimeout(_id);
- } else {
- _cancelAnimFrame(_id);
- }
- _req = _emptyFunc;
- _id = null;
- if (_self === _ticker) {
- _tickerActive = false;
- }
- };
- _self.wake = function(seamless) {
- if (_id !== null) {
- _self.sleep();
- } else if (seamless) {
- _startTime += -_lastUpdate + (_lastUpdate = _getTime());
- } else if (_self.frame > 10) { //don't trigger lagSmoothing if we're just waking up, and make sure that at least 10 frames have elapsed because of the iOS bug that we work around below with the 1.5-second setTimout().
- _lastUpdate = _getTime() - _lagThreshold + 5;
- }
- _req = (_fps === 0) ? _emptyFunc : (!_useRAF || !_reqAnimFrame) ? function(f) { return setTimeout(f, ((_nextTime - _self.time) * 1000 + 1) | 0); } : _reqAnimFrame;
- if (_self === _ticker) {
- _tickerActive = true;
- }
- _tick(2);
- };
- _self.fps = function(value) {
- if (!arguments.length) {
- return _fps;
- }
- _fps = value;
- _gap = 1 / (_fps || 60);
- _nextTime = this.time + _gap;
- _self.wake();
- };
- _self.useRAF = function(value) {
- if (!arguments.length) {
- return _useRAF;
- }
- _self.sleep();
- _useRAF = value;
- _self.fps(_fps);
- };
- _self.fps(fps);
- //a bug in iOS 6 Safari occasionally prevents the requestAnimationFrame from working initially, so we use a 1.5-second timeout that automatically falls back to setTimeout() if it senses this condition.
- setTimeout(function() {
- if (_useRAF === "auto" && _self.frame < 5 && _doc.visibilityState !== "hidden") {
- _self.useRAF(false);
- }
- }, 1500);
- });
- p = gs.Ticker.prototype = new gs.events.EventDispatcher();
- p.constructor = gs.Ticker;
- /*
- * ----------------------------------------------------------------
- * Animation
- * ----------------------------------------------------------------
- */
- var Animation = _class("core.Animation", function(duration, vars) {
- this.vars = vars = vars || {};
- this._duration = this._totalDuration = duration || 0;
- this._delay = Number(vars.delay) || 0;
- this._timeScale = 1;
- this._active = (vars.immediateRender === true);
- this.data = vars.data;
- this._reversed = (vars.reversed === true);
- if (!_rootTimeline) {
- return;
- }
- if (!_tickerActive) { //some browsers (like iOS 6 Safari) shut down JavaScript execution when the tab is disabled and they [occasionally] neglect to start up requestAnimationFrame again when returning - this code ensures that the engine starts up again properly.
- _ticker.wake();
- }
- var tl = this.vars.useFrames ? _rootFramesTimeline : _rootTimeline;
- tl.add(this, tl._time);
- if (this.vars.paused) {
- this.paused(true);
- }
- });
- _ticker = Animation.ticker = new gs.Ticker();
- p = Animation.prototype;
- p._dirty = p._gc = p._initted = p._paused = false;
- p._totalTime = p._time = 0;
- p._rawPrevTime = -1;
- p._next = p._last = p._onUpdate = p._timeline = p.timeline = null;
- p._paused = false;
- //some browsers (like iOS) occasionally drop the requestAnimationFrame event when the user switches to a different tab and then comes back again, so we use a 2-second setTimeout() to sense if/when that condition occurs and then wake() the ticker.
- var _checkTimeout = function() {
- if (_tickerActive && _getTime() - _lastUpdate > 2000 && _doc.visibilityState !== "hidden") {
- _ticker.wake();
- }
- var t = setTimeout(_checkTimeout, 2000);
- if (t.unref) {
- // allows a node process to exit even if the timeout’s callback hasn't been invoked. Without it, the node process could hang as this function is called every two seconds.
- t.unref();
- }
- };
- _checkTimeout();
- p.play = function(from, suppressEvents) {
- if (from != null) {
- this.seek(from, suppressEvents);
- }
- return this.reversed(false).paused(false);
- };
- p.pause = function(atTime, suppressEvents) {
- if (atTime != null) {
- this.seek(atTime, suppressEvents);
- }
- return this.paused(true);
- };
- p.resume = function(from, suppressEvents) {
- if (from != null) {
- this.seek(from, suppressEvents);
- }
- return this.paused(false);
- };
- p.seek = function(time, suppressEvents) {
- return this.totalTime(Number(time), suppressEvents !== false);
- };
- p.restart = function(includeDelay, suppressEvents) {
- return this.reversed(false).paused(false).totalTime(includeDelay ? -this._delay : 0, (suppressEvents !== false), true);
- };
- p.reverse = function(from, suppressEvents) {
- if (from != null) {
- this.seek((from || this.totalDuration()), suppressEvents);
- }
- return this.reversed(true).paused(false);
- };
- p.render = function(time, suppressEvents, force) {
- //stub - we override this method in subclasses.
- };
- p.invalidate = function() {
- this._time = this._totalTime = 0;
- this._initted = this._gc = false;
- this._rawPrevTime = -1;
- if (this._gc || !this.timeline) {
- this._enabled(true);
- }
- return this;
- };
- p.isActive = function() {
- var tl = this._timeline, //the 2 root timelines won't have a _timeline; they're always active.
- startTime = this._startTime,
- rawTime;
- return (!tl || (!this._gc && !this._paused && tl.isActive() && (rawTime = tl.rawTime(true)) >= startTime && rawTime < startTime + this.totalDuration() / this._timeScale - 0.0000001));
- };
- p._enabled = function (enabled, ignoreTimeline) {
- if (!_tickerActive) {
- _ticker.wake();
- }
- this._gc = !enabled;
- this._active = this.isActive();
- if (ignoreTimeline !== true) {
- if (enabled && !this.timeline) {
- this._timeline.add(this, this._startTime - this._delay);
- } else if (!enabled && this.timeline) {
- this._timeline._remove(this, true);
- }
- }
- return false;
- };
- p._kill = function(vars, target) {
- return this._enabled(false, false);
- };
- p.kill = function(vars, target) {
- this._kill(vars, target);
- return this;
- };
- p._uncache = function(includeSelf) {
- var tween = includeSelf ? this : this.timeline;
- while (tween) {
- tween._dirty = true;
- tween = tween.timeline;
- }
- return this;
- };
- p._swapSelfInParams = function(params) {
- var i = params.length,
- copy = params.concat();
- while (--i > -1) {
- if (params[i] === "{self}") {
- copy[i] = this;
- }
- }
- return copy;
- };
- p._callback = function(type) {
- var v = this.vars,
- callback = v[type],
- params = v[type + "Params"],
- scope = v[type + "Scope"] || v.callbackScope || this,
- l = params ? params.length : 0;
- switch (l) { //speed optimization; call() is faster than apply() so use it when there are only a few parameters (which is by far most common). Previously we simply did var v = this.vars; v[type].apply(v[type + "Scope"] || v.callbackScope || this, v[type + "Params"] || _blankArray);
- case 0: callback.call(scope); break;
- case 1: callback.call(scope, params[0]); break;
- case 2: callback.call(scope, params[0], params[1]); break;
- default: callback.apply(scope, params);
- }
- };
- //----Animation getters/setters --------------------------------------------------------
- p.eventCallback = function(type, callback, params, scope) {
- if ((type || "").substr(0,2) === "on") {
- var v = this.vars;
- if (arguments.length === 1) {
- return v[type];
- }
- if (callback == null) {
- delete v[type];
- } else {
- v[type] = callback;
- v[type + "Params"] = (_isArray(params) && params.join("").indexOf("{self}") !== -1) ? this._swapSelfInParams(params) : params;
- v[type + "Scope"] = scope;
- }
- if (type === "onUpdate") {
- this._onUpdate = callback;
- }
- }
- return this;
- };
- p.delay = function(value) {
- if (!arguments.length) {
- return this._delay;
- }
- if (this._timeline.smoothChildTiming) {
- this.startTime( this._startTime + value - this._delay );
- }
- this._delay = value;
- return this;
- };
- p.duration = function(value) {
- if (!arguments.length) {
- this._dirty = false;
- return this._duration;
- }
- this._duration = this._totalDuration = value;
- this._uncache(true); //true in case it's a TweenMax or TimelineMax that has a repeat - we'll need to refresh the totalDuration.
- if (this._timeline.smoothChildTiming) if (this._time > 0) if (this._time < this._duration) if (value !== 0) {
- this.totalTime(this._totalTime * (value / this._duration), true);
- }
- return this;
- };
- p.totalDuration = function(value) {
- this._dirty = false;
- return (!arguments.length) ? this._totalDuration : this.duration(value);
- };
- p.time = function(value, suppressEvents) {
- if (!arguments.length) {
- return this._time;
- }
- if (this._dirty) {
- this.totalDuration();
- }
- return this.totalTime((value > this._duration) ? this._duration : value, suppressEvents);
- };
- p.totalTime = function(time, suppressEvents, uncapped) {
- if (!_tickerActive) {
- _ticker.wake();
- }
- if (!arguments.length) {
- return this._totalTime;
- }
- if (this._timeline) {
- if (time < 0 && !uncapped) {
- time += this.totalDuration();
- }
- if (this._timeline.smoothChildTiming) {
- if (this._dirty) {
- this.totalDuration();
- }
- var totalDuration = this._totalDuration,
- tl = this._timeline;
- if (time > totalDuration && !uncapped) {
- time = totalDuration;
- }
- this._startTime = (this._paused ? this._pauseTime : tl._time) - ((!this._reversed ? time : totalDuration - time) / this._timeScale);
- if (!tl._dirty) { //for performance improvement. If the parent's cache is already dirty, it already took care of marking the ancestors as dirty too, so skip the function call here.
- this._uncache(false);
- }
- //in case any of the ancestor timelines had completed but should now be enabled, we should reset their totalTime() which will also ensure that they're lined up properly and enabled. Skip for animations that are on the root (wasteful). Example: a TimelineLite.exportRoot() is performed when there's a paused tween on the root, the export will not complete until that tween is unpaused, but imagine a child gets restarted later, after all [unpaused] tweens have completed. The startTime of that child would get pushed out, but one of the ancestors may have completed.
- if (tl._timeline) {
- while (tl._timeline) {
- if (tl._timeline._time !== (tl._startTime + tl._totalTime) / tl._timeScale) {
- tl.totalTime(tl._totalTime, true);
- }
- tl = tl._timeline;
- }
- }
- }
- if (this._gc) {
- this._enabled(true, false);
- }
- if (this._totalTime !== time || this._duration === 0) {
- if (_lazyTweens.length) {
- _lazyRender();
- }
- this.render(time, suppressEvents, false);
- if (_lazyTweens.length) { //in case rendering caused any tweens to lazy-init, we should render them because typically when someone calls seek() or time() or progress(), they expect an immediate render.
- _lazyRender();
- }
- }
- }
- return this;
- };
- p.progress = p.totalProgress = function(value, suppressEvents) {
- var duration = this.duration();
- return (!arguments.length) ? (duration ? this._time / duration : this.ratio) : this.totalTime(duration * value, suppressEvents);
- };
- p.startTime = function(value) {
- if (!arguments.length) {
- return this._startTime;
- }
- if (value !== this._startTime) {
- this._startTime = value;
- if (this.timeline) if (this.timeline._sortChildren) {
- this.timeline.add(this, value - this._delay); //ensures that any necessary re-sequencing of Animations in the timeline occurs to make sure the rendering order is correct.
- }
- }
- return this;
- };
- p.endTime = function(includeRepeats) {
- return this._startTime + ((includeRepeats != false) ? this.totalDuration() : this.duration()) / this._timeScale;
- };
- p.timeScale = function(value) {
- if (!arguments.length) {
- return this._timeScale;
- }
- value = value || _tinyNum; //can't allow zero because it'll throw the math off
- if (this._timeline && this._timeline.smoothChildTiming) {
- var pauseTime = this._pauseTime,
- t = (pauseTime || pauseTime === 0) ? pauseTime : this._timeline.totalTime();
- this._startTime = t - ((t - this._startTime) * this._timeScale / value);
- }
- this._timeScale = value;
- return this._uncache(false);
- };
- p.reversed = function(value) {
- if (!arguments.length) {
- return this._reversed;
- }
- if (value != this._reversed) {
- this._reversed = value;
- this.totalTime(((this._timeline && !this._timeline.smoothChildTiming) ? this.totalDuration() - this._totalTime : this._totalTime), true);
- }
- return this;
- };
- p.paused = function(value) {
- if (!arguments.length) {
- return this._paused;
- }
- var tl = this._timeline,
- raw, elapsed;
- if (value != this._paused) if (tl) {
- if (!_tickerActive && !value) {
- _ticker.wake();
- }
- raw = tl.rawTime();
- elapsed = raw - this._pauseTime;
- if (!value && tl.smoothChildTiming) {
- this._startTime += elapsed;
- this._uncache(false);
- }
- this._pauseTime = value ? raw : null;
- this._paused = value;
- this._active = this.isActive();
- if (!value && elapsed !== 0 && this._initted && this.duration()) {
- raw = tl.smoothChildTiming ? this._totalTime : (raw - this._startTime) / this._timeScale;
- this.render(raw, (raw === this._totalTime), true); //in case the target's properties changed via some other tween or manual update by the user, we should force a render.
- }
- }
- if (this._gc && !value) {
- this._enabled(true, false);
- }
- return this;
- };
- /*
- * ----------------------------------------------------------------
- * SimpleTimeline
- * ----------------------------------------------------------------
- */
- var SimpleTimeline = _class("core.SimpleTimeline", function(vars) {
- Animation.call(this, 0, vars);
- this.autoRemoveChildren = this.smoothChildTiming = true;
- });
- p = SimpleTimeline.prototype = new Animation();
- p.constructor = SimpleTimeline;
- p.kill()._gc = false;
- p._first = p._last = p._recent = null;
- p._sortChildren = false;
- p.add = p.insert = function(child, position, align, stagger) {
- var prevTween, st;
- child._startTime = Number(position || 0) + child._delay;
- if (child._paused) if (this !== child._timeline) { //we only adjust the _pauseTime if it wasn't in this timeline already. Remember, sometimes a tween will be inserted again into the same timeline when its startTime is changed so that the tweens in the TimelineLite/Max are re-ordered properly in the linked list (so everything renders in the proper order).
- child._pauseTime = child._startTime + ((this.rawTime() - child._startTime) / child._timeScale);
- }
- if (child.timeline) {
- child.timeline._remove(child, true); //removes from existing timeline so that it can be properly added to this one.
- }
- child.timeline = child._timeline = this;
- if (child._gc) {
- child._enabled(true, true);
- }
- prevTween = this._last;
- if (this._sortChildren) {
- st = child._startTime;
- while (prevTween && prevTween._startTime > st) {
- prevTween = prevTween._prev;
- }
- }
- if (prevTween) {
- child._next = prevTween._next;
- prevTween._next = child;
- } else {
- child._next = this._first;
- this._first = child;
- }
- if (child._next) {
- child._next._prev = child;
- } else {
- this._last = child;
- }
- child._prev = prevTween;
- this._recent = child;
- if (this._timeline) {
- this._uncache(true);
- }
- return this;
- };
- p._remove = function(tween, skipDisable) {
- if (tween.timeline === this) {
- if (!skipDisable) {
- tween._enabled(false, true);
- }
- if (tween._prev) {
- tween._prev._next = tween._next;
- } else if (this._first === tween) {
- this._first = tween._next;
- }
- if (tween._next) {
- tween._next._prev = tween._prev;
- } else if (this._last === tween) {
- this._last = tween._prev;
- }
- tween._next = tween._prev = tween.timeline = null;
- if (tween === this._recent) {
- this._recent = this._last;
- }
- if (this._timeline) {
- this._uncache(true);
- }
- }
- return this;
- };
- p.render = function(time, suppressEvents, force) {
- var tween = this._first,
- next;
- this._totalTime = this._time = this._rawPrevTime = time;
- while (tween) {
- next = tween._next; //record it here because the value could change after rendering...
- if (tween._active || (time >= tween._startTime && !tween._paused && !tween._gc)) {
- if (!tween._reversed) {
- tween.render((time - tween._startTime) * tween._timeScale, suppressEvents, force);
- } else {
- tween.render(((!tween._dirty) ? tween._totalDuration : tween.totalDuration()) - ((time - tween._startTime) * tween._timeScale), suppressEvents, force);
- }
- }
- tween = next;
- }
- };
- p.rawTime = function() {
- if (!_tickerActive) {
- _ticker.wake();
- }
- return this._totalTime;
- };
- /*
- * ----------------------------------------------------------------
- * TweenLite
- * ----------------------------------------------------------------
- */
- var TweenLite = _class("TweenLite", function(target, duration, vars) {
- Animation.call(this, duration, vars);
- this.render = TweenLite.prototype.render; //speed optimization (avoid prototype lookup on this "hot" method)
- if (target == null) {
- throw "Cannot tween a null target.";
- }
- this.target = target = (typeof(target) !== "string") ? target : TweenLite.selector(target) || target;
- var isSelector = (target.jquery || (target.length && target !== window && target[0] && (target[0] === window || (target[0].nodeType && target[0].style && !target.nodeType)))),
- overwrite = this.vars.overwrite,
- i, targ, targets;
- this._overwrite = overwrite = (overwrite == null) ? _overwriteLookup[TweenLite.defaultOverwrite] : (typeof(overwrite) === "number") ? overwrite >> 0 : _overwriteLookup[overwrite];
- if ((isSelector || target instanceof Array || (target.push && _isArray(target))) && typeof(target[0]) !== "number") {
- this._targets = targets = _slice(target); //don't use Array.prototype.slice.call(target, 0) because that doesn't work in IE8 with a NodeList that's returned by querySelectorAll()
- this._propLookup = [];
- this._siblings = [];
- for (i = 0; i < targets.length; i++) {
- targ = targets[i];
- if (!targ) {
- targets.splice(i--, 1);
- continue;
- } else if (typeof(targ) === "string") {
- targ = targets[i--] = TweenLite.selector(targ); //in case it's an array of strings
- if (typeof(targ) === "string") {
- targets.splice(i+1, 1); //to avoid an endless loop (can't imagine why the selector would return a string, but just in case)
- }
- continue;
- } else if (targ.length && targ !== window && targ[0] && (targ[0] === window || (targ[0].nodeType && targ[0].style && !targ.nodeType))) { //in case the user is passing in an array of selector objects (like jQuery objects), we need to check one more level and pull things out if necessary. Also note that <select> elements pass all the criteria regarding length and the first child having style, so we must also check to ensure the target isn't an HTML node itself.
- targets.splice(i--, 1);
- this._targets = targets = targets.concat(_slice(targ));
- continue;
- }
- this._siblings[i] = _register(targ, this, false);
- if (overwrite === 1) if (this._siblings[i].length > 1) {
- _applyOverwrite(targ, this, null, 1, this._siblings[i]);
- }
- }
- } else {
- this._propLookup = {};
- this._siblings = _register(target, this, false);
- if (overwrite === 1) if (this._siblings.length > 1) {
- _applyOverwrite(target, this, null, 1, this._siblings);
- }
- }
- if (this.vars.immediateRender || (duration === 0 && this._delay === 0 && this.vars.immediateRender !== false)) {
- this._time = -_tinyNum; //forces a render without having to set the render() "force" parameter to true because we want to allow lazying by default (using the "force" parameter always forces an immediate full render)
- this.render(Math.min(0, -this._delay)); //in case delay is negative
- }
- }, true),
- _isSelector = function(v) {
- return (v && v.length && v !== window && v[0] && (v[0] === window || (v[0].nodeType && v[0].style && !v.nodeType))); //we cannot check "nodeType" if the target is window from within an iframe, otherwise it will trigger a security error in some browsers like Firefox.
- },
- _autoCSS = function(vars, target) {
- var css = {},
- p;
- for (p in vars) {
- if (!_reservedProps[p] && (!(p in target) || p === "transform" || p === "x" || p === "y" || p === "width" || p === "height" || p === "className" || p === "border") && (!_plugins[p] || (_plugins[p] && _plugins[p]._autoCSS))) { //note: <img> elements contain read-only "x" and "y" properties. We should also prioritize editing css width/height rather than the element's properties.
- css[p] = vars[p];
- delete vars[p];
- }
- }
- vars.css = css;
- };
- p = TweenLite.prototype = new Animation();
- p.constructor = TweenLite;
- p.kill()._gc = false;
- //----TweenLite defaults, overwrite management, and root updates ----------------------------------------------------
- p.ratio = 0;
- p._firstPT = p._targets = p._overwrittenProps = p._startAt = null;
- p._notifyPluginsOfEnabled = p._lazy = false;
- TweenLite.version = "1.20.2";
- TweenLite.defaultEase = p._ease = new Ease(null, null, 1, 1);
- TweenLite.defaultOverwrite = "auto";
- TweenLite.ticker = _ticker;
- TweenLite.autoSleep = 120;
- TweenLite.lagSmoothing = function(threshold, adjustedLag) {
- _ticker.lagSmoothing(threshold, adjustedLag);
- };
- TweenLite.selector = window.$ || window.jQuery || function(e) {
- var selector = window.$ || window.jQuery;
- if (selector) {
- TweenLite.selector = selector;
- return selector(e);
- }
- return (typeof(_doc) === "undefined") ? e : (_doc.querySelectorAll ? _doc.querySelectorAll(e) : _doc.getElementById((e.charAt(0) === "#") ? e.substr(1) : e));
- };
- var _lazyTweens = [],
- _lazyLookup = {},
- _numbersExp = /(?:(-|-=|\+=)?\d*\.?\d*(?:e[\-+]?\d+)?)[0-9]/ig,
- _relExp = /[\+-]=-?[\.\d]/,
- //_nonNumbersExp = /(?:([\-+](?!(\d|=)))|[^\d\-+=e]|(e(?![\-+][\d])))+/ig,
- _setRatio = function(v) {
- var pt = this._firstPT,
- min = 0.000001,
- val;
- while (pt) {
- val = !pt.blob ? pt.c * v + pt.s : (v === 1 && this.end) ? this.end : v ? this.join("") : this.start;
- if (pt.m) {
- val = pt.m(val, this._target || pt.t);
- } else if (val < min) if (val > -min && !pt.blob) { //prevents issues with converting very small numbers to strings in the browser
- val = 0;
- }
- if (!pt.f) {
- pt.t[pt.p] = val;
- } else if (pt.fp) {
- pt.t[pt.p](pt.fp, val);
- } else {
- pt.t[pt.p](val);
- }
- pt = pt._next;
- }
- },
- //compares two strings (start/end), finds the numbers that are different and spits back an array representing the whole value but with the changing values isolated as elements. For example, "rgb(0,0,0)" and "rgb(100,50,0)" would become ["rgb(", 0, ",", 50, ",0)"]. Notice it merges the parts that are identical (performance optimization). The array also has a linked list of PropTweens attached starting with _firstPT that contain the tweening data (t, p, s, c, f, etc.). It also stores the starting value as a "start" property so that we can revert to it if/when necessary, like when a tween rewinds fully. If the quantity of numbers differs between the start and end, it will always prioritize the end value(s). The pt parameter is optional - it's for a PropTween that will be appended to the end of the linked list and is typically for actually setting the value after all of the elements have been updated (with array.join("")).
- _blobDif = function(start, end, filter, pt) {
- var a = [],
- charIndex = 0,
- s = "",
- color = 0,
- startNums, endNums, num, i, l, nonNumbers, currentNum;
- a.start = start;
- a.end = end;
- start = a[0] = start + ""; //ensure values are strings
- end = a[1] = end + "";
- if (filter) {
- filter(a); //pass an array with the starting and ending values and let the filter do whatever it needs to the values.
- start = a[0];
- end = a[1];
- }
- a.length = 0;
- startNums = start.match(_numbersExp) || [];
- endNums = end.match(_numbersExp) || [];
- if (pt) {
- pt._next = null;
- pt.blob = 1;
- a._firstPT = a._applyPT = pt; //apply last in the linked list (which means inserting it first)
- }
- l = endNums.length;
- for (i = 0; i < l; i++) {
- currentNum = endNums[i];
- nonNumbers = end.substr(charIndex, end.indexOf(currentNum, charIndex)-charIndex);
- s += (nonNumbers || !i) ? nonNumbers : ","; //note: SVG spec allows omission of comma/space when a negative sign is wedged between two numbers, like 2.5-5.3 instead of 2.5,-5.3 but when tweening, the negative value may switch to positive, so we insert the comma just in case.
- charIndex += nonNumbers.length;
- if (color) { //sense rgba() values and round them.
- color = (color + 1) % 5;
- } else if (nonNumbers.substr(-5) === "rgba(") {
- color = 1;
- }
- if (currentNum === startNums[i] || startNums.length <= i) {
- s += currentNum;
- } else {
- if (s) {
- a.push(s);
- s = "";
- }
- num = parseFloat(startNums[i]);
- a.push(num);
- a._firstPT = {_next: a._firstPT, t:a, p: a.length-1, s:num, c:((currentNum.charAt(1) === "=") ? parseInt(currentNum.charAt(0) + "1", 10) * parseFloat(currentNum.substr(2)) : (parseFloat(currentNum) - num)) || 0, f:0, m:(color && color < 4) ? Math.round : 0};
- //note: we don't set _prev because we'll never need to remove individual PropTweens from this list.
- }
- charIndex += currentNum.length;
- }
- s += end.substr(charIndex);
- if (s) {
- a.push(s);
- }
- a.setRatio = _setRatio;
- if (_relExp.test(end)) { //if the end string contains relative values, delete it so that on the final render (in _setRatio()), we don't actually set it to the string with += or -= characters (forces it to use the calculated value).
- a.end = 0;
- }
- return a;
- },
- //note: "funcParam" is only necessary for function-based getters/setters that require an extra parameter like getAttribute("width") and setAttribute("width", value). In this example, funcParam would be "width". Used by AttrPlugin for example.
- _addPropTween = function(target, prop, start, end, overwriteProp, mod, funcParam, stringFilter, index) {
- if (typeof(end) === "function") {
- end = end(index || 0, target);
- }
- var type = typeof(target[prop]),
- getterName = (type !== "function") ? "" : ((prop.indexOf("set") || typeof(target["get" + prop.substr(3)]) !== "function") ? prop : "get" + prop.substr(3)),
- s = (start !== "get") ? start : !getterName ? target[prop] : funcParam ? target[getterName](funcParam) : target[getterName](),
- isRelative = (typeof(end) === "string" && end.charAt(1) === "="),
- pt = {t:target, p:prop, s:s, f:(type === "function"), pg:0, n:overwriteProp || prop, m:(!mod ? 0 : (typeof(mod) === "function") ? mod : Math.round), pr:0, c:isRelative ? parseInt(end.charAt(0) + "1", 10) * parseFloat(end.substr(2)) : (parseFloat(end) - s) || 0},
- blob;
- if (typeof(s) !== "number" || (typeof(end) !== "number" && !isRelative)) {
- if (funcParam || isNaN(s) || (!isRelative && isNaN(end)) || typeof(s) === "boolean" || typeof(end) === "boolean") {
- //a blob (string that has multiple numbers in it)
- pt.fp = funcParam;
- blob = _blobDif(s, (isRelative ? parseFloat(pt.s) + pt.c : end), stringFilter || TweenLite.defaultStringFilter, pt);
- pt = {t: blob, p: "setRatio", s: 0, c: 1, f: 2, pg: 0, n: overwriteProp || prop, pr: 0, m: 0}; //"2" indicates it's a Blob property tween. Needed for RoundPropsPlugin for example.
- } else {
- pt.s = parseFloat(s);
- if (!isRelative) {
- pt.c = (parseFloat(end) - pt.s) || 0;
- }
- }
- }
- if (pt.c) { //only add it to the linked list if there's a change.
- if ((pt._next = this._firstPT)) {
- pt._next._prev = pt;
- }
- this._firstPT = pt;
- return pt;
- }
- },
- _internals = TweenLite._internals = {isArray:_isArray, isSelector:_isSelector, lazyTweens:_lazyTweens, blobDif:_blobDif}, //gives us a way to expose certain private values to other GreenSock classes without contaminating tha main TweenLite object.
- _plugins = TweenLite._plugins = {},
- _tweenLookup = _internals.tweenLookup = {},
- _tweenLookupNum = 0,
- _reservedProps = _internals.reservedProps = {ease:1, delay:1, overwrite:1, onComplete:1, onCompleteParams:1, onCompleteScope:1, useFrames:1, runBackwards:1, startAt:1, onUpdate:1, onUpdateParams:1, onUpdateScope:1, onStart:1, onStartParams:1, onStartScope:1, onReverseComplete:1, onReverseCompleteParams:1, onReverseCompleteScope:1, onRepeat:1, onRepeatParams:1, onRepeatScope:1, easeParams:1, yoyo:1, immediateRender:1, repeat:1, repeatDelay:1, data:1, paused:1, reversed:1, autoCSS:1, lazy:1, onOverwrite:1, callbackScope:1, stringFilter:1, id:1, yoyoEase:1},
- _overwriteLookup = {none:0, all:1, auto:2, concurrent:3, allOnStart:4, preexisting:5, "true":1, "false":0},
- _rootFramesTimeline = Animation._rootFramesTimeline = new SimpleTimeline(),
- _rootTimeline = Animation._rootTimeline = new SimpleTimeline(),
- _nextGCFrame = 30,
- _lazyRender = _internals.lazyRender = function() {
- var i = _lazyTweens.length,
- tween;
- _lazyLookup = {};
- while (--i > -1) {
- tween = _lazyTweens[i];
- if (tween && tween._lazy !== false) {
- tween.render(tween._lazy[0], tween._lazy[1], true);
- tween._lazy = false;
- }
- }
- _lazyTweens.length = 0;
- };
- _rootTimeline._startTime = _ticker.time;
- _rootFramesTimeline._startTime = _ticker.frame;
- _rootTimeline._active = _rootFramesTimeline._active = true;
- setTimeout(_lazyRender, 1); //on some mobile devices, there isn't a "tick" before code runs which means any lazy renders wouldn't run before the next official "tick".
- Animation._updateRoot = TweenLite.render = function() {
- var i, a, p;
- if (_lazyTweens.length) { //if code is run outside of the requestAnimationFrame loop, there may be tweens queued AFTER the engine refreshed, so we need to ensure any pending renders occur before we refresh again.
- _lazyRender();
- }
- _rootTimeline.render((_ticker.time - _rootTimeline._startTime) * _rootTimeline._timeScale, false, false);
- _rootFramesTimeline.render((_ticker.frame - _rootFramesTimeline._startTime) * _rootFramesTimeline._timeScale, false, false);
- if (_lazyTweens.length) {
- _lazyRender();
- }
- if (_ticker.frame >= _nextGCFrame) { //dump garbage every 120 frames or whatever the user sets TweenLite.autoSleep to
- _nextGCFrame = _ticker.frame + (parseInt(TweenLite.autoSleep, 10) || 120);
- for (p in _tweenLookup) {
- a = _tweenLookup[p].tweens;
- i = a.length;
- while (--i > -1) {
- if (a[i]._gc) {
- a.splice(i, 1);
- }
- }
- if (a.length === 0) {
- delete _tweenLookup[p];
- }
- }
- //if there are no more tweens in the root timelines, or if they're all paused, make the _timer sleep to reduce load on the CPU slightly
- p = _rootTimeline._first;
- if (!p || p._paused) if (TweenLite.autoSleep && !_rootFramesTimeline._first && _ticker._listeners.tick.length === 1) {
- while (p && p._paused) {
- p = p._next;
- }
- if (!p) {
- _ticker.sleep();
- }
- }
- }
- };
- _ticker.addEventListener("tick", Animation._updateRoot);
- var _register = function(target, tween, scrub) {
- var id = target._gsTweenID, a, i;
- if (!_tweenLookup[id || (target._gsTweenID = id = "t" + (_tweenLookupNum++))]) {
- _tweenLookup[id] = {target:target, tweens:[]};
- }
- if (tween) {
- a = _tweenLookup[id].tweens;
- a[(i = a.length)] = tween;
- if (scrub) {
- while (--i > -1) {
- if (a[i] === tween) {
- a.splice(i, 1);
- }
- }
- }
- }
- return _tweenLookup[id].tweens;
- },
- _onOverwrite = function(overwrittenTween, overwritingTween, target, killedProps) {
- var func = overwrittenTween.vars.onOverwrite, r1, r2;
- if (func) {
- r1 = func(overwrittenTween, overwritingTween, target, killedProps);
- }
- func = TweenLite.onOverwrite;
- if (func) {
- r2 = func(overwrittenTween, overwritingTween, target, killedProps);
- }
- return (r1 !== false && r2 !== false);
- },
- _applyOverwrite = function(target, tween, props, mode, siblings) {
- var i, changed, curTween, l;
- if (mode === 1 || mode >= 4) {
- l = siblings.length;
- for (i = 0; i < l; i++) {
- if ((curTween = siblings[i]) !== tween) {
- if (!curTween._gc) {
- if (curTween._kill(null, target, tween)) {
- changed = true;
- }
- }
- } else if (mode === 5) {
- break;
- }
- }
- return changed;
- }
- //NOTE: Add 0.0000000001 to overcome floating point errors that can cause the startTime to be VERY slightly off (when a tween's time() is set for example)
- var startTime = tween._startTime + _tinyNum,
- overlaps = [],
- oCount = 0,
- zeroDur = (tween._duration === 0),
- globalStart;
- i = siblings.length;
- while (--i > -1) {
- if ((curTween = siblings[i]) === tween || curTween._gc || curTween._paused) {
- //ignore
- } else if (curTween._timeline !== tween._timeline) {
- globalStart = globalStart || _checkOverlap(tween, 0, zeroDur);
- if (_checkOverlap(curTween, globalStart, zeroDur) === 0) {
- overlaps[oCount++] = curTween;
- }
- } else if (curTween._startTime <= startTime) if (curTween._startTime + curTween.totalDuration() / curTween._timeScale > startTime) if (!((zeroDur || !curTween._initted) && startTime - curTween._startTime <= 0.0000000002)) {
- overlaps[oCount++] = curTween;
- }
- }
- i = oCount;
- while (--i > -1) {
- curTween = overlaps[i];
- if (mode === 2) if (curTween._kill(props, target, tween)) {
- changed = true;
- }
- if (mode !== 2 || (!curTween._firstPT && curTween._initted)) {
- if (mode !== 2 && !_onOverwrite(curTween, tween)) {
- continue;
- }
- if (curTween._enabled(false, false)) { //if all property tweens have been overwritten, kill the tween.
- changed = true;
- }
- }
- }
- return changed;
- },
- _checkOverlap = function(tween, reference, zeroDur) {
- var tl = tween._timeline,
- ts = tl._timeScale,
- t = tween._startTime;
- while (tl._timeline) {
- t += tl._startTime;
- ts *= tl._timeScale;
- if (tl._paused) {
- return -100;
- }
- tl = tl._timeline;
- }
- t /= ts;
- return (t > reference) ? t - reference : ((zeroDur && t === reference) || (!tween._initted && t - reference < 2 * _tinyNum)) ? _tinyNum : ((t += tween.totalDuration() / tween._timeScale / ts) > reference + _tinyNum) ? 0 : t - reference - _tinyNum;
- };
- //---- TweenLite instance methods -----------------------------------------------------------------------------
- p._init = function() {
- var v = this.vars,
- op = this._overwrittenProps,
- dur = this._duration,
- immediate = !!v.immediateRender,
- ease = v.ease,
- i, initPlugins, pt, p, startVars, l;
- if (v.startAt) {
- if (this._startAt) {
- this._startAt.render(-1, true); //if we've run a startAt previously (when the tween instantiated), we should revert it so that the values re-instantiate correctly particularly for relative tweens. Without this, a TweenLite.fromTo(obj, 1, {x:"+=100"}, {x:"-=100"}), for example, would actually jump to +=200 because the startAt would run twice, doubling the relative change.
- this._startAt.kill();
- }
- startVars = {};
- for (p in v.startAt) { //copy the properties/values into a new object to avoid collisions, like var to = {x:0}, from = {x:500}; timeline.fromTo(e, 1, from, to).fromTo(e, 1, to, from);
- startVars[p] = v.startAt[p];
- }
- startVars.overwrite = false;
- startVars.immediateRender = true;
- startVars.lazy = (immediate && v.lazy !== false);
- startVars.startAt = startVars.delay = null; //no nesting of startAt objects allowed (otherwise it could cause an infinite loop).
- startVars.onUpdate = v.onUpdate;
- startVars.onUpdateScope = v.onUpdateScope || v.callbackScope || this;
- this._startAt = TweenLite.to(this.target, 0, startVars);
- if (immediate) {
- if (this._time > 0) {
- this._startAt = null; //tweens that render immediately (like most from() and fromTo() tweens) shouldn't revert when their parent timeline's playhead goes backward past the startTime because the initial render could have happened anytime and it shouldn't be directly correlated to this tween's startTime. Imagine setting up a complex animation where the beginning states of various objects are rendered immediately but the tween doesn't happen for quite some time - if we revert to the starting values as soon as the playhead goes backward past the tween's startTime, it will throw things off visually. Reversion should only happen in TimelineLite/Max instances where immediateRender was false (which is the default in the convenience methods like from()).
- } else if (dur !== 0) {
- return; //we skip initialization here so that overwriting doesn't occur until the tween actually begins. Otherwise, if you create several immediateRender:true tweens of the same target/properties to drop into a TimelineLite or TimelineMax, the last one created would overwrite the first ones because they didn't get placed into the timeline yet before the first render occurs and kicks in overwriting.
- }
- }
- } else if (v.runBackwards && dur !== 0) {
- //from() tweens must be handled uniquely: their beginning values must be rendered but we don't want overwriting to occur yet (when time is still 0). Wait until the tween actually begins before doing all the routines like overwriting. At that time, we should render at the END of the tween to ensure that things initialize correctly (remember, from() tweens go backwards)
- if (this._startAt) {
- this._startAt.render(-1, true);
- this._startAt.kill();
- this._startAt = null;
- } else {
- if (this._time !== 0) { //in rare cases (like if a from() tween runs and then is invalidate()-ed), immediateRender could be true but the initial forced-render gets skipped, so there's no need to force the render in this context when the _time is greater than 0
- immediate = false;
- }
- pt = {};
- for (p in v) { //copy props into a new object and skip any reserved props, otherwise onComplete or onUpdate or onStart could fire. We should, however, permit autoCSS to go through.
- if (!_reservedProps[p] || p === "autoCSS") {
- pt[p] = v[p];
- }
- }
- pt.overwrite = 0;
- pt.data = "isFromStart"; //we tag the tween with as "isFromStart" so that if [inside a plugin] we need to only do something at the very END of a tween, we have a way of identifying this tween as merely the one that's setting the beginning values for a "from()" tween. For example, clearProps in CSSPlugin should only get applied at the very END of a tween and without this tag, from(...{height:100, clearProps:"height", delay:1}) would wipe the height at the beginning of the tween and after 1 second, it'd kick back in.
- pt.lazy = (immediate && v.lazy !== false);
- pt.immediateRender = immediate; //zero-duration tweens render immediately by default, but if we're not specifically instructed to render this tween immediately, we should skip this and merely _init() to record the starting values (rendering them immediately would push them to completion which is wasteful in that case - we'd have to render(-1) immediately after)
- this._startAt = TweenLite.to(this.target, 0, pt);
- if (!immediate) {
- this._startAt._init(); //ensures that the initial values are recorded
- this._startAt._enabled(false); //no need to have the tween render on the next cycle. Disable it because we'll always manually control the renders of the _startAt tween.
- if (this.vars.immediateRender) {
- this._startAt = null;
- }
- } else if (this._time === 0) {
- return;
- }
- }
- }
- this._ease = ease = (!ease) ? TweenLite.defaultEase : (ease instanceof Ease) ? ease : (typeof(ease) === "function") ? new Ease(ease, v.easeParams) : _easeMap[ease] || TweenLite.defaultEase;
- if (v.easeParams instanceof Array && ease.config) {
- this._ease = ease.config.apply(ease, v.easeParams);
- }
- this._easeType = this._ease._type;
- this._easePower = this._ease._power;
- this._firstPT = null;
- if (this._targets) {
- l = this._targets.length;
- for (i = 0; i < l; i++) {
- if ( this._initProps( this._targets[i], (this._propLookup[i] = {}), this._siblings[i], (op ? op[i] : null), i) ) {
- initPlugins = true;
- }
- }
- } else {
- initPlugins = this._initProps(this.target, this._propLookup, this._siblings, op, 0);
- }
- if (initPlugins) {
- TweenLite._onPluginEvent("_onInitAllProps", this); //reorders the array in order of priority. Uses a static TweenPlugin method in order to minimize file size in TweenLite
- }
- if (op) if (!this._firstPT) if (typeof(this.target) !== "function") { //if all tweening properties have been overwritten, kill the tween. If the target is a function, it's probably a delayedCall so let it live.
- this._enabled(false, false);
- }
- if (v.runBackwards) {
- pt = this._firstPT;
- while (pt) {
- pt.s += pt.c;
- pt.c = -pt.c;
- pt = pt._next;
- }
- }
- this._onUpdate = v.onUpdate;
- this._initted = true;
- };
- p._initProps = function(target, propLookup, siblings, overwrittenProps, index) {
- var p, i, initPlugins, plugin, pt, v;
- if (target == null) {
- return false;
- }
- if (_lazyLookup[target._gsTweenID]) {
- _lazyRender(); //if other tweens of the same target have recently initted but haven't rendered yet, we've got to force the render so that the starting values are correct (imagine populating a timeline with a bunch of sequential tweens and then jumping to the end)
- }
- if (!this.vars.css) if (target.style) if (target !== window && target.nodeType) if (_plugins.css) if (this.vars.autoCSS !== false) { //it's so common to use TweenLite/Max to animate the css of DOM elements, we assume that if the target is a DOM element, that's what is intended (a convenience so that users don't have to wrap things in css:{}, although we still recommend it for a slight performance boost and better specificity). Note: we cannot check "nodeType" on the window inside an iframe.
- _autoCSS(this.vars, target);
- }
- for (p in this.vars) {
- v = this.vars[p];
- if (_reservedProps[p]) {
- if (v) if ((v instanceof Array) || (v.push && _isArray(v))) if (v.join("").indexOf("{self}") !== -1) {
- this.vars[p] = v = this._swapSelfInParams(v, this);
- }
- } else if (_plugins[p] && (plugin = new _plugins[p]())._onInitTween(target, this.vars[p], this, index)) {
- //t - target [object]
- //p - property [string]
- //s - start [number]
- //c - change [number]
- //f - isFunction [boolean]
- //n - name [string]
- //pg - isPlugin [boolean]
- //pr - priority [number]
- //m - mod [function | 0]
- this._firstPT = pt = {_next:this._firstPT, t:plugin, p:"setRatio", s:0, c:1, f:1, n:p, pg:1, pr:plugin._priority, m:0};
- i = plugin._overwriteProps.length;
- while (--i > -1) {
- propLookup[plugin._overwriteProps[i]] = this._firstPT;
- }
- if (plugin._priority || plugin._onInitAllProps) {
- initPlugins = true;
- }
- if (plugin._onDisable || plugin._onEnable) {
- this._notifyPluginsOfEnabled = true;
- }
- if (pt._next) {
- pt._next._prev = pt;
- }
- } else {
- propLookup[p] = _addPropTween.call(this, target, p, "get", v, p, 0, null, this.vars.stringFilter, index);
- }
- }
- if (overwrittenProps) if (this._kill(overwrittenProps, target)) { //another tween may have tried to overwrite properties of this tween before init() was called (like if two tweens start at the same time, the one created second will run first)
- return this._initProps(target, propLookup, siblings, overwrittenProps, index);
- }
- if (this._overwrite > 1) if (this._firstPT) if (siblings.length > 1) if (_applyOverwrite(target, this, propLookup, this._overwrite, siblings)) {
- this._kill(propLookup, target);
- return this._initProps(target, propLookup, siblings, overwrittenProps, index);
- }
- if (this._firstPT) if ((this.vars.lazy !== false && this._duration) || (this.vars.lazy && !this._duration)) { //zero duration tweens don't lazy render by default; everything else does.
- _lazyLookup[target._gsTweenID] = true;
- }
- return initPlugins;
- };
- p.render = function(time, suppressEvents, force) {
- var prevTime = this._time,
- duration = this._duration,
- prevRawPrevTime = this._rawPrevTime,
- isComplete, callback, pt, rawPrevTime;
- if (time >= duration - 0.0000001 && time >= 0) { //to work around occasional floating point math artifacts.
- this._totalTime = this._time = duration;
- this.ratio = this._ease._calcEnd ? this._ease.getRatio(1) : 1;
- if (!this._reversed ) {
- isComplete = true;
- callback = "onComplete";
- force = (force || this._timeline.autoRemoveChildren); //otherwise, if the animation is unpaused/activated after it's already finished, it doesn't get removed from the parent timeline.
- }
- if (duration === 0) if (this._initted || !this.vars.lazy || force) { //zero-duration tweens are tricky because we must discern the momentum/direction of time in order to determine whether the starting values should be rendered or the ending values. If the "playhead" of its timeline goes past the zero-duration tween in the forward direction or lands directly on it, the end values should be rendered, but if the timeline's "playhead" moves past it in the backward direction (from a postitive time to a negative time), the starting values must be rendered.
- if (this._startTime === this._timeline._duration) { //if a zero-duration tween is at the VERY end of a timeline and that timeline renders at its end, it will typically add a tiny bit of cushion to the render time to prevent rounding errors from getting in the way of tweens rendering their VERY end. If we then reverse() that timeline, the zero-duration tween will trigger its onReverseComplete even though technically the playhead didn't pass over it again. It's a very specific edge case we must accommodate.
- time = 0;
- }
- if (prevRawPrevTime < 0 || (time <= 0 && time >= -0.0000001) || (prevRawPrevTime === _tinyNum && this.data !== "isPause")) if (prevRawPrevTime !== time) { //note: when this.data is "isPause", it's a callback added by addPause() on a timeline that we should not be triggered when LEAVING its exact start time. In other words, tl.addPause(1).play(1) shouldn't pause.
- force = true;
- if (prevRawPrevTime > _tinyNum) {
- callback = "onReverseComplete";
- }
- }
- this._rawPrevTime = rawPrevTime = (!suppressEvents || time || prevRawPrevTime === time) ? time : _tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient.
- }
- } else if (time < 0.0000001) { //to work around occasional floating point math artifacts, round super small values to 0.
- this._totalTime = this._time = 0;
- this.ratio = this._ease._calcEnd ? this._ease.getRatio(0) : 0;
- if (prevTime !== 0 || (duration === 0 && prevRawPrevTime > 0)) {
- callback = "onReverseComplete";
- isComplete = this._reversed;
- }
- if (time < 0) {
- this._active = false;
- if (duration === 0) if (this._initted || !this.vars.lazy || force) { //zero-duration tweens are tricky because we must discern the momentum/direction of time in order to determine whether the starting values should be rendered or the ending values. If the "playhead" of its timeline goes past the zero-duration tween in the forward direction or lands directly on it, the end values should be rendered, but if the timeline's "playhead" moves past it in the backward direction (from a postitive time to a negative time), the starting values must be rendered.
- if (prevRawPrevTime >= 0 && !(prevRawPrevTime === _tinyNum && this.data === "isPause")) {
- force = true;
- }
- this._rawPrevTime = rawPrevTime = (!suppressEvents || time || prevRawPrevTime === time) ? time : _tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient.
- }
- }
- if (!this._initted || (this._startAt && this._startAt.progress())) { //if we render the very beginning (time == 0) of a fromTo(), we must force the render (normal tweens wouldn't need to render at a time of 0 when the prevTime was also 0). This is also mandatory to make sure overwriting kicks in immediately. Also, we check progress() because if startAt has already rendered at its end, we should force a render at its beginning. Otherwise, if you put the playhead directly on top of where a fromTo({immediateRender:false}) starts, and then move it backwards, the from() won't revert its values.
- force = true;
- }
- } else {
- this._totalTime = this._time = time;
- if (this._easeType) {
- var r = time / duration, type = this._easeType, pow = this._easePower;
- if (type === 1 || (type === 3 && r >= 0.5)) {
- r = 1 - r;
- }
- if (type === 3) {
- r *= 2;
- }
- if (pow === 1) {
- r *= r;
- } else if (pow === 2) {
- r *= r * r;
- } else if (pow === 3) {
- r *= r * r * r;
- } else if (pow === 4) {
- r *= r * r * r * r;
- }
- if (type === 1) {
- this.ratio = 1 - r;
- } else if (type === 2) {
- this.ratio = r;
- } else if (time / duration < 0.5) {
- this.ratio = r / 2;
- } else {
- this.ratio = 1 - (r / 2);
- }
- } else {
- this.ratio = this._ease.getRatio(time / duration);
- }
- }
- if (this._time === prevTime && !force) {
- return;
- } else if (!this._initted) {
- this._init();
- if (!this._initted || this._gc) { //immediateRender tweens typically won't initialize until the playhead advances (_time is greater than 0) in order to ensure that overwriting occurs properly. Also, if all of the tweening properties have been overwritten (which would cause _gc to be true, as set in _init()), we shouldn't continue otherwise an onStart callback could be called for example.
- return;
- } else if (!force && this._firstPT && ((this.vars.lazy !== false && this._duration) || (this.vars.lazy && !this._duration))) {
- this._time = this._totalTime = prevTime;
- this._rawPrevTime = prevRawPrevTime;
- _lazyTweens.push(this);
- this._lazy = [time, suppressEvents];
- return;
- }
- //_ease is initially set to defaultEase, so now that init() has run, _ease is set properly and we need to recalculate the ratio. Overall this is faster than using conditional logic earlier in the method to avoid having to set ratio twice because we only init() once but renderTime() gets called VERY frequently.
- if (this._time && !isComplete) {
- this.ratio = this._ease.getRatio(this._time / duration);
- } else if (isComplete && this._ease._calcEnd) {
- this.ratio = this._ease.getRatio((this._time === 0) ? 0 : 1);
- }
- }
- if (this._lazy !== false) { //in case a lazy render is pending, we should flush it because the new render is occurring now (imagine a lazy tween instantiating and then immediately the user calls tween.seek(tween.duration()), skipping to the end - the end render would be forced, and then if we didn't flush the lazy render, it'd fire AFTER the seek(), rendering it at the wrong time.
- this._lazy = false;
- }
- if (!this._active) if (!this._paused && this._time !== prevTime && time >= 0) {
- this._active = true; //so that if the user renders a tween (as opposed to the timeline rendering it), the timeline is forced to re-render and align it with the proper time/frame on the next rendering cycle. Maybe the tween already finished but the user manually re-renders it as halfway done.
- }
- if (prevTime === 0) {
- if (this._startAt) {
- if (time >= 0) {
- this._startAt.render(time, suppressEvents, force);
- } else if (!callback) {
- callback = "_dummyGS"; //if no callback is defined, use a dummy value just so that the condition at the end evaluates as true because _startAt should render AFTER the normal render loop when the time is negative. We could handle this in a more intuitive way, of course, but the render loop is the MOST important thing to optimize, so this technique allows us to avoid adding extra conditional logic in a high-frequency area.
- }
- }
- if (this.vars.onStart) if (this._time !== 0 || duration === 0) if (!suppressEvents) {
- this._callback("onStart");
- }
- }
- pt = this._firstPT;
- while (pt) {
- if (pt.f) {
- pt.t[pt.p](pt.c * this.ratio + pt.s);
- } else {
- pt.t[pt.p] = pt.c * this.ratio + pt.s;
- }
- pt = pt._next;
- }
- if (this._onUpdate) {
- if (time < 0) if (this._startAt && time !== -0.0001) { //if the tween is positioned at the VERY beginning (_startTime 0) of its parent timeline, it's illegal for the playhead to go back further, so we should not render the recorded startAt values.
- this._startAt.render(time, suppressEvents, force); //note: for performance reasons, we tuck this conditional logic inside less traveled areas (most tweens don't have an onUpdate). We'd just have it at the end before the onComplete, but the values should be updated before any onUpdate is called, so we ALSO put it here and then if it's not called, we do so later near the onComplete.
- }
- if (!suppressEvents) if (this._time !== prevTime || isComplete || force) {
- this._callback("onUpdate");
- }
- }
- if (callback) if (!this._gc || force) { //check _gc because there's a chance that kill() could be called in an onUpdate
- if (time < 0 && this._startAt && !this._onUpdate && time !== -0.0001) { //-0.0001 is a special value that we use when looping back to the beginning of a repeated TimelineMax, in which case we shouldn't render the _startAt values.
- this._startAt.render(time, suppressEvents, force);
- }
- if (isComplete) {
- if (this._timeline.autoRemoveChildren) {
- this._enabled(false, false);
- }
- this._active = false;
- }
- if (!suppressEvents && this.vars[callback]) {
- this._callback(callback);
- }
- if (duration === 0 && this._rawPrevTime === _tinyNum && rawPrevTime !== _tinyNum) { //the onComplete or onReverseComplete could trigger movement of the playhead and for zero-duration tweens (which must discern direction) that land directly back on their start time, we don't want to fire again on the next render. Think of several addPause()'s in a timeline that forces the playhead to a certain spot, but what if it's already paused and another tween is tweening the "time" of the timeline? Each time it moves [forward] past that spot, it would move back, and since suppressEvents is true, it'd reset _rawPrevTime to _tinyNum so that when it begins again, the callback would fire (so ultimately it could bounce back and forth during that tween). Again, this is a very uncommon scenario, but possible nonetheless.
- this._rawPrevTime = 0;
- }
- }
- };
- p._kill = function(vars, target, overwritingTween) {
- if (vars === "all") {
- vars = null;
- }
- if (vars == null) if (target == null || target === this.target) {
- this._lazy = false;
- return this._enabled(false, false);
- }
- target = (typeof(target) !== "string") ? (target || this._targets || this.target) : TweenLite.selector(target) || target;
- var simultaneousOverwrite = (overwritingTween && this._time && overwritingTween._startTime === this._startTime && this._timeline === overwritingTween._timeline),
- i, overwrittenProps, p, pt, propLookup, changed, killProps, record, killed;
- if ((_isArray(target) || _isSelector(target)) && typeof(target[0]) !== "number") {
- i = target.length;
- while (--i > -1) {
- if (this._kill(vars, target[i], overwritingTween)) {
- changed = true;
- }
- }
- } else {
- if (this._targets) {
- i = this._targets.length;
- while (--i > -1) {
- if (target === this._targets[i]) {
- propLookup = this._propLookup[i] || {};
- this._overwrittenProps = this._overwrittenProps || [];
- overwrittenProps = this._overwrittenProps[i] = vars ? this._overwrittenProps[i] || {} : "all";
- break;
- }
- }
- } else if (target !== this.target) {
- return false;
- } else {
- propLookup = this._propLookup;
- overwrittenProps = this._overwrittenProps = vars ? this._overwrittenProps || {} : "all";
- }
- if (propLookup) {
- killProps = vars || propLookup;
- record = (vars !== overwrittenProps && overwrittenProps !== "all" && vars !== propLookup && (typeof(vars) !== "object" || !vars._tempKill)); //_tempKill is a super-secret way to delete a particular tweening property but NOT have it remembered as an official overwritten property (like in BezierPlugin)
- if (overwritingTween && (TweenLite.onOverwrite || this.vars.onOverwrite)) {
- for (p in killProps) {
- if (propLookup[p]) {
- if (!killed) {
- killed = [];
- }
- killed.push(p);
- }
- }
- if ((killed || !vars) && !_onOverwrite(this, overwritingTween, target, killed)) { //if the onOverwrite returned false, that means the user wants to override the overwriting (cancel it).
- return false;
- }
- }
- for (p in killProps) {
- if ((pt = propLookup[p])) {
- if (simultaneousOverwrite) { //if another tween overwrites this one and they both start at exactly the same time, yet this tween has already rendered once (for example, at 0.001) because it's first in the queue, we should revert the values to where they were at 0 so that the starting values aren't contaminated on the overwriting tween.
- if (pt.f) {
- pt.t[pt.p](pt.s);
- } else {
- pt.t[pt.p] = pt.s;
- }
- changed = true;
- }
- if (pt.pg && pt.t._kill(killProps)) {
- changed = true; //some plugins need to be notified so they can perform cleanup tasks first
- }
- if (!pt.pg || pt.t._overwriteProps.length === 0) {
- if (pt._prev) {
- pt._prev._next = pt._next;
- } else if (pt === this._firstPT) {
- this._firstPT = pt._next;
- }
- if (pt._next) {
- pt._next._prev = pt._prev;
- }
- pt._next = pt._prev = null;
- }
- delete propLookup[p];
- }
- if (record) {
- overwrittenProps[p] = 1;
- }
- }
- if (!this._firstPT && this._initted) { //if all tweening properties are killed, kill the tween. Without this line, if there's a tween with multiple targets and then you killTweensOf() each target individually, the tween would technically still remain active and fire its onComplete even though there aren't any more properties tweening.
- this._enabled(false, false);
- }
- }
- }
- return changed;
- };
- p.invalidate = function() {
- if (this._notifyPluginsOfEnabled) {
- TweenLite._onPluginEvent("_onDisable", this);
- }
- this._firstPT = this._overwrittenProps = this._startAt = this._onUpdate = null;
- this._notifyPluginsOfEnabled = this._active = this._lazy = false;
- this._propLookup = (this._targets) ? {} : [];
- Animation.prototype.invalidate.call(this);
- if (this.vars.immediateRender) {
- this._time = -_tinyNum; //forces a render without having to set the render() "force" parameter to true because we want to allow lazying by default (using the "force" parameter always forces an immediate full render)
- this.render(Math.min(0, -this._delay)); //in case delay is negative.
- }
- return this;
- };
- p._enabled = function(enabled, ignoreTimeline) {
- if (!_tickerActive) {
- _ticker.wake();
- }
- if (enabled && this._gc) {
- var targets = this._targets,
- i;
- if (targets) {
- i = targets.length;
- while (--i > -1) {
- this._siblings[i] = _register(targets[i], this, true);
- }
- } else {
- this._siblings = _register(this.target, this, true);
- }
- }
- Animation.prototype._enabled.call(this, enabled, ignoreTimeline);
- if (this._notifyPluginsOfEnabled) if (this._firstPT) {
- return TweenLite._onPluginEvent((enabled ? "_onEnable" : "_onDisable"), this);
- }
- return false;
- };
- //----TweenLite static methods -----------------------------------------------------
- TweenLite.to = function(target, duration, vars) {
- return new TweenLite(target, duration, vars);
- };
- TweenLite.from = function(target, duration, vars) {
- vars.runBackwards = true;
- vars.immediateRender = (vars.immediateRender != false);
- return new TweenLite(target, duration, vars);
- };
- TweenLite.fromTo = function(target, duration, fromVars, toVars) {
- toVars.startAt = fromVars;
- toVars.immediateRender = (toVars.immediateRender != false && fromVars.immediateRender != false);
- return new TweenLite(target, duration, toVars);
- };
- TweenLite.delayedCall = function(delay, callback, params, scope, useFrames) {
- return new TweenLite(callback, 0, {delay:delay, onComplete:callback, onCompleteParams:params, callbackScope:scope, onReverseComplete:callback, onReverseCompleteParams:params, immediateRender:false, lazy:false, useFrames:useFrames, overwrite:0});
- };
- TweenLite.set = function(target, vars) {
- return new TweenLite(target, 0, vars);
- };
- TweenLite.getTweensOf = function(target, onlyActive) {
- if (target == null) { return []; }
- target = (typeof(target) !== "string") ? target : TweenLite.selector(target) || target;
- var i, a, j, t;
- if ((_isArray(target) || _isSelector(target)) && typeof(target[0]) !== "number") {
- i = target.length;
- a = [];
- while (--i > -1) {
- a = a.concat(TweenLite.getTweensOf(target[i], onlyActive));
- }
- i = a.length;
- //now get rid of any duplicates (tweens of arrays of objects could cause duplicates)
- while (--i > -1) {
- t = a[i];
- j = i;
- while (--j > -1) {
- if (t === a[j]) {
- a.splice(i, 1);
- }
- }
- }
- } else if (target._gsTweenID) {
- a = _register(target).concat();
- i = a.length;
- while (--i > -1) {
- if (a[i]._gc || (onlyActive && !a[i].isActive())) {
- a.splice(i, 1);
- }
- }
- }
- return a || [];
- };
- TweenLite.killTweensOf = TweenLite.killDelayedCallsTo = function(target, onlyActive, vars) {
- if (typeof(onlyActive) === "object") {
- vars = onlyActive; //for backwards compatibility (before "onlyActive" parameter was inserted)
- onlyActive = false;
- }
- var a = TweenLite.getTweensOf(target, onlyActive),
- i = a.length;
- while (--i > -1) {
- a[i]._kill(vars, target);
- }
- };
- /*
- * ----------------------------------------------------------------
- * TweenPlugin (could easily be split out as a separate file/class, but included for ease of use (so that people don't need to include another script call before loading plugins which is easy to forget)
- * ----------------------------------------------------------------
- */
- var TweenPlugin = _class("plugins.TweenPlugin", function(props, priority) {
- this._overwriteProps = (props || "").split(",");
- this._propName = this._overwriteProps[0];
- this._priority = priority || 0;
- this._super = TweenPlugin.prototype;
- }, true);
- p = TweenPlugin.prototype;
- TweenPlugin.version = "1.19.0";
- TweenPlugin.API = 2;
- p._firstPT = null;
- p._addTween = _addPropTween;
- p.setRatio = _setRatio;
- p._kill = function(lookup) {
- var a = this._overwriteProps,
- pt = this._firstPT,
- i;
- if (lookup[this._propName] != null) {
- this._overwriteProps = [];
- } else {
- i = a.length;
- while (--i > -1) {
- if (lookup[a[i]] != null) {
- a.splice(i, 1);
- }
- }
- }
- while (pt) {
- if (lookup[pt.n] != null) {
- if (pt._next) {
- pt._next._prev = pt._prev;
- }
- if (pt._prev) {
- pt._prev._next = pt._next;
- pt._prev = null;
- } else if (this._firstPT === pt) {
- this._firstPT = pt._next;
- }
- }
- pt = pt._next;
- }
- return false;
- };
- p._mod = p._roundProps = function(lookup) {
- var pt = this._firstPT,
- val;
- while (pt) {
- val = lookup[this._propName] || (pt.n != null && lookup[ pt.n.split(this._propName + "_").join("") ]);
- if (val && typeof(val) === "function") { //some properties that are very plugin-specific add a prefix named after the _propName plus an underscore, so we need to ignore that extra stuff here.
- if (pt.f === 2) {
- pt.t._applyPT.m = val;
- } else {
- pt.m = val;
- }
- }
- pt = pt._next;
- }
- };
- TweenLite._onPluginEvent = function(type, tween) {
- var pt = tween._firstPT,
- changed, pt2, first, last, next;
- if (type === "_onInitAllProps") {
- //sorts the PropTween linked list in order of priority because some plugins need to render earlier/later than others, like MotionBlurPlugin applies its effects after all x/y/alpha tweens have rendered on each frame.
- while (pt) {
- next = pt._next;
- pt2 = first;
- while (pt2 && pt2.pr > pt.pr) {
- pt2 = pt2._next;
- }
- if ((pt._prev = pt2 ? pt2._prev : last)) {
- pt._prev._next = pt;
- } else {
- first = pt;
- }
- if ((pt._next = pt2)) {
- pt2._prev = pt;
- } else {
- last = pt;
- }
- pt = next;
- }
- pt = tween._firstPT = first;
- }
- while (pt) {
- if (pt.pg) if (typeof(pt.t[type]) === "function") if (pt.t[type]()) {
- changed = true;
- }
- pt = pt._next;
- }
- return changed;
- };
- TweenPlugin.activate = function(plugins) {
- var i = plugins.length;
- while (--i > -1) {
- if (plugins[i].API === TweenPlugin.API) {
- _plugins[(new plugins[i]())._propName] = plugins[i];
- }
- }
- return true;
- };
- //provides a more concise way to define plugins that have no dependencies besides TweenPlugin and TweenLite, wrapping common boilerplate stuff into one function (added in 1.9.0). You don't NEED to use this to define a plugin - the old way still works and can be useful in certain (rare) situations.
- _gsDefine.plugin = function(config) {
- if (!config || !config.propName || !config.init || !config.API) { throw "illegal plugin definition."; }
- var propName = config.propName,
- priority = config.priority || 0,
- overwriteProps = config.overwriteProps,
- map = {init:"_onInitTween", set:"setRatio", kill:"_kill", round:"_mod", mod:"_mod", initAll:"_onInitAllProps"},
- Plugin = _class("plugins." + propName.charAt(0).toUpperCase() + propName.substr(1) + "Plugin",
- function() {
- TweenPlugin.call(this, propName, priority);
- this._overwriteProps = overwriteProps || [];
- }, (config.global === true)),
- p = Plugin.prototype = new TweenPlugin(propName),
- prop;
- p.constructor = Plugin;
- Plugin.API = config.API;
- for (prop in map) {
- if (typeof(config[prop]) === "function") {
- p[map[prop]] = config[prop];
- }
- }
- Plugin.version = config.version;
- TweenPlugin.activate([Plugin]);
- return Plugin;
- };
- //now run through all the dependencies discovered and if any are missing, log that to the console as a warning. This is why it's best to have TweenLite load last - it can check all the dependencies for you.
- a = window._gsQueue;
- if (a) {
- for (i = 0; i < a.length; i++) {
- a[i]();
- }
- for (p in _defLookup) {
- if (!_defLookup[p].func) {
- window.console.log("GSAP encountered missing dependency: " + p);
- }
- }
- }
- _tickerActive = false; //ensures that the first official animation forces a ticker.tick() to update the time when it is instantiated
- })((typeof(module) !== "undefined" && module.exports && typeof(global) !== "undefined") ? global : this || window, "TweenMax");
- }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
- },{}],213:[function(require,module,exports){
- /*!
- * html2canvas 1.0.0-rc.7 <https://html2canvas.hertzen.com>
- * Copyright (c) 2020 Niklas von Hertzen <https://hertzen.com>
- * Released under MIT License
- */
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
- typeof define === 'function' && define.amd ? define(factory) :
- (global = global || self, global.html2canvas = factory());
- }(this, function () { 'use strict';
- /*! *****************************************************************************
- Copyright (c) Microsoft Corporation. All rights reserved.
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
- this file except in compliance with the License. You may obtain a copy of the
- License at http://www.apache.org/licenses/LICENSE-2.0
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
- MERCHANTABLITY OR NON-INFRINGEMENT.
- See the Apache Version 2.0 License for specific language governing permissions
- and limitations under the License.
- ***************************************************************************** */
- /* global Reflect, Promise */
- var extendStatics = function(d, b) {
- extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return extendStatics(d, b);
- };
- function __extends(d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- }
- var __assign = function() {
- __assign = Object.assign || function __assign(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
- }
- return t;
- };
- return __assign.apply(this, arguments);
- };
- function __awaiter(thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- }
- function __generator(thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [op[0] & 2, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- }
- var Bounds = /** @class */ (function () {
- function Bounds(x, y, w, h) {
- this.left = x;
- this.top = y;
- this.width = w;
- this.height = h;
- }
- Bounds.prototype.add = function (x, y, w, h) {
- return new Bounds(this.left + x, this.top + y, this.width + w, this.height + h);
- };
- Bounds.fromClientRect = function (clientRect) {
- return new Bounds(clientRect.left, clientRect.top, clientRect.width, clientRect.height);
- };
- return Bounds;
- }());
- var parseBounds = function (node) {
- return Bounds.fromClientRect(node.getBoundingClientRect());
- };
- var parseDocumentSize = function (document) {
- var body = document.body;
- var documentElement = document.documentElement;
- if (!body || !documentElement) {
- throw new Error("Unable to get document size");
- }
- var width = Math.max(Math.max(body.scrollWidth, documentElement.scrollWidth), Math.max(body.offsetWidth, documentElement.offsetWidth), Math.max(body.clientWidth, documentElement.clientWidth));
- var height = Math.max(Math.max(body.scrollHeight, documentElement.scrollHeight), Math.max(body.offsetHeight, documentElement.offsetHeight), Math.max(body.clientHeight, documentElement.clientHeight));
- return new Bounds(0, 0, width, height);
- };
- /*
- * css-line-break 1.1.1 <https://github.com/niklasvh/css-line-break#readme>
- * Copyright (c) 2019 Niklas von Hertzen <https://hertzen.com>
- * Released under MIT License
- */
- var toCodePoints = function (str) {
- var codePoints = [];
- var i = 0;
- var length = str.length;
- while (i < length) {
- var value = str.charCodeAt(i++);
- if (value >= 0xd800 && value <= 0xdbff && i < length) {
- var extra = str.charCodeAt(i++);
- if ((extra & 0xfc00) === 0xdc00) {
- codePoints.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000);
- }
- else {
- codePoints.push(value);
- i--;
- }
- }
- else {
- codePoints.push(value);
- }
- }
- return codePoints;
- };
- var fromCodePoint = function () {
- var codePoints = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- codePoints[_i] = arguments[_i];
- }
- if (String.fromCodePoint) {
- return String.fromCodePoint.apply(String, codePoints);
- }
- var length = codePoints.length;
- if (!length) {
- return '';
- }
- var codeUnits = [];
- var index = -1;
- var result = '';
- while (++index < length) {
- var codePoint = codePoints[index];
- if (codePoint <= 0xffff) {
- codeUnits.push(codePoint);
- }
- else {
- codePoint -= 0x10000;
- codeUnits.push((codePoint >> 10) + 0xd800, codePoint % 0x400 + 0xdc00);
- }
- if (index + 1 === length || codeUnits.length > 0x4000) {
- result += String.fromCharCode.apply(String, codeUnits);
- codeUnits.length = 0;
- }
- }
- return result;
- };
- var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
- // Use a lookup table to find the index.
- var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
- for (var i = 0; i < chars.length; i++) {
- lookup[chars.charCodeAt(i)] = i;
- }
- var decode = function (base64) {
- var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
- if (base64[base64.length - 1] === '=') {
- bufferLength--;
- if (base64[base64.length - 2] === '=') {
- bufferLength--;
- }
- }
- var buffer = typeof ArrayBuffer !== 'undefined' &&
- typeof Uint8Array !== 'undefined' &&
- typeof Uint8Array.prototype.slice !== 'undefined'
- ? new ArrayBuffer(bufferLength)
- : new Array(bufferLength);
- var bytes = Array.isArray(buffer) ? buffer : new Uint8Array(buffer);
- for (i = 0; i < len; i += 4) {
- encoded1 = lookup[base64.charCodeAt(i)];
- encoded2 = lookup[base64.charCodeAt(i + 1)];
- encoded3 = lookup[base64.charCodeAt(i + 2)];
- encoded4 = lookup[base64.charCodeAt(i + 3)];
- bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
- bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
- bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
- }
- return buffer;
- };
- var polyUint16Array = function (buffer) {
- var length = buffer.length;
- var bytes = [];
- for (var i = 0; i < length; i += 2) {
- bytes.push((buffer[i + 1] << 8) | buffer[i]);
- }
- return bytes;
- };
- var polyUint32Array = function (buffer) {
- var length = buffer.length;
- var bytes = [];
- for (var i = 0; i < length; i += 4) {
- bytes.push((buffer[i + 3] << 24) | (buffer[i + 2] << 16) | (buffer[i + 1] << 8) | buffer[i]);
- }
- return bytes;
- };
- /** Shift size for getting the index-2 table offset. */
- var UTRIE2_SHIFT_2 = 5;
- /** Shift size for getting the index-1 table offset. */
- var UTRIE2_SHIFT_1 = 6 + 5;
- /**
- * Shift size for shifting left the index array values.
- * Increases possible data size with 16-bit index values at the cost
- * of compactability.
- * This requires data blocks to be aligned by UTRIE2_DATA_GRANULARITY.
- */
- var UTRIE2_INDEX_SHIFT = 2;
- /**
- * Difference between the two shift sizes,
- * for getting an index-1 offset from an index-2 offset. 6=11-5
- */
- var UTRIE2_SHIFT_1_2 = UTRIE2_SHIFT_1 - UTRIE2_SHIFT_2;
- /**
- * The part of the index-2 table for U+D800..U+DBFF stores values for
- * lead surrogate code _units_ not code _points_.
- * Values for lead surrogate code _points_ are indexed with this portion of the table.
- * Length=32=0x20=0x400>>UTRIE2_SHIFT_2. (There are 1024=0x400 lead surrogates.)
- */
- var UTRIE2_LSCP_INDEX_2_OFFSET = 0x10000 >> UTRIE2_SHIFT_2;
- /** Number of entries in a data block. 32=0x20 */
- var UTRIE2_DATA_BLOCK_LENGTH = 1 << UTRIE2_SHIFT_2;
- /** Mask for getting the lower bits for the in-data-block offset. */
- var UTRIE2_DATA_MASK = UTRIE2_DATA_BLOCK_LENGTH - 1;
- var UTRIE2_LSCP_INDEX_2_LENGTH = 0x400 >> UTRIE2_SHIFT_2;
- /** Count the lengths of both BMP pieces. 2080=0x820 */
- var UTRIE2_INDEX_2_BMP_LENGTH = UTRIE2_LSCP_INDEX_2_OFFSET + UTRIE2_LSCP_INDEX_2_LENGTH;
- /**
- * The 2-byte UTF-8 version of the index-2 table follows at offset 2080=0x820.
- * Length 32=0x20 for lead bytes C0..DF, regardless of UTRIE2_SHIFT_2.
- */
- var UTRIE2_UTF8_2B_INDEX_2_OFFSET = UTRIE2_INDEX_2_BMP_LENGTH;
- var UTRIE2_UTF8_2B_INDEX_2_LENGTH = 0x800 >> 6; /* U+0800 is the first code point after 2-byte UTF-8 */
- /**
- * The index-1 table, only used for supplementary code points, at offset 2112=0x840.
- * Variable length, for code points up to highStart, where the last single-value range starts.
- * Maximum length 512=0x200=0x100000>>UTRIE2_SHIFT_1.
- * (For 0x100000 supplementary code points U+10000..U+10ffff.)
- *
- * The part of the index-2 table for supplementary code points starts
- * after this index-1 table.
- *
- * Both the index-1 table and the following part of the index-2 table
- * are omitted completely if there is only BMP data.
- */
- var UTRIE2_INDEX_1_OFFSET = UTRIE2_UTF8_2B_INDEX_2_OFFSET + UTRIE2_UTF8_2B_INDEX_2_LENGTH;
- /**
- * Number of index-1 entries for the BMP. 32=0x20
- * This part of the index-1 table is omitted from the serialized form.
- */
- var UTRIE2_OMITTED_BMP_INDEX_1_LENGTH = 0x10000 >> UTRIE2_SHIFT_1;
- /** Number of entries in an index-2 block. 64=0x40 */
- var UTRIE2_INDEX_2_BLOCK_LENGTH = 1 << UTRIE2_SHIFT_1_2;
- /** Mask for getting the lower bits for the in-index-2-block offset. */
- var UTRIE2_INDEX_2_MASK = UTRIE2_INDEX_2_BLOCK_LENGTH - 1;
- var slice16 = function (view, start, end) {
- if (view.slice) {
- return view.slice(start, end);
- }
- return new Uint16Array(Array.prototype.slice.call(view, start, end));
- };
- var slice32 = function (view, start, end) {
- if (view.slice) {
- return view.slice(start, end);
- }
- return new Uint32Array(Array.prototype.slice.call(view, start, end));
- };
- var createTrieFromBase64 = function (base64) {
- var buffer = decode(base64);
- var view32 = Array.isArray(buffer) ? polyUint32Array(buffer) : new Uint32Array(buffer);
- var view16 = Array.isArray(buffer) ? polyUint16Array(buffer) : new Uint16Array(buffer);
- var headerLength = 24;
- var index = slice16(view16, headerLength / 2, view32[4] / 2);
- var data = view32[5] === 2
- ? slice16(view16, (headerLength + view32[4]) / 2)
- : slice32(view32, Math.ceil((headerLength + view32[4]) / 4));
- return new Trie(view32[0], view32[1], view32[2], view32[3], index, data);
- };
- var Trie = /** @class */ (function () {
- function Trie(initialValue, errorValue, highStart, highValueIndex, index, data) {
- this.initialValue = initialValue;
- this.errorValue = errorValue;
- this.highStart = highStart;
- this.highValueIndex = highValueIndex;
- this.index = index;
- this.data = data;
- }
- /**
- * Get the value for a code point as stored in the Trie.
- *
- * @param codePoint the code point
- * @return the value
- */
- Trie.prototype.get = function (codePoint) {
- var ix;
- if (codePoint >= 0) {
- if (codePoint < 0x0d800 || (codePoint > 0x0dbff && codePoint <= 0x0ffff)) {
- // Ordinary BMP code point, excluding leading surrogates.
- // BMP uses a single level lookup. BMP index starts at offset 0 in the Trie2 index.
- // 16 bit data is stored in the index array itself.
- ix = this.index[codePoint >> UTRIE2_SHIFT_2];
- ix = (ix << UTRIE2_INDEX_SHIFT) + (codePoint & UTRIE2_DATA_MASK);
- return this.data[ix];
- }
- if (codePoint <= 0xffff) {
- // Lead Surrogate Code Point. A Separate index section is stored for
- // lead surrogate code units and code points.
- // The main index has the code unit data.
- // For this function, we need the code point data.
- // Note: this expression could be refactored for slightly improved efficiency, but
- // surrogate code points will be so rare in practice that it's not worth it.
- ix = this.index[UTRIE2_LSCP_INDEX_2_OFFSET + ((codePoint - 0xd800) >> UTRIE2_SHIFT_2)];
- ix = (ix << UTRIE2_INDEX_SHIFT) + (codePoint & UTRIE2_DATA_MASK);
- return this.data[ix];
- }
- if (codePoint < this.highStart) {
- // Supplemental code point, use two-level lookup.
- ix = UTRIE2_INDEX_1_OFFSET - UTRIE2_OMITTED_BMP_INDEX_1_LENGTH + (codePoint >> UTRIE2_SHIFT_1);
- ix = this.index[ix];
- ix += (codePoint >> UTRIE2_SHIFT_2) & UTRIE2_INDEX_2_MASK;
- ix = this.index[ix];
- ix = (ix << UTRIE2_INDEX_SHIFT) + (codePoint & UTRIE2_DATA_MASK);
- return this.data[ix];
- }
- if (codePoint <= 0x10ffff) {
- return this.data[this.highValueIndex];
- }
- }
- // Fall through. The code point is outside of the legal range of 0..0x10ffff.
- return this.errorValue;
- };
- return Trie;
- }());
- var base64 = 'KwAAAAAAAAAACA4AIDoAAPAfAAACAAAAAAAIABAAGABAAEgAUABYAF4AZgBeAGYAYABoAHAAeABeAGYAfACEAIAAiACQAJgAoACoAK0AtQC9AMUAXgBmAF4AZgBeAGYAzQDVAF4AZgDRANkA3gDmAOwA9AD8AAQBDAEUARoBIgGAAIgAJwEvATcBPwFFAU0BTAFUAVwBZAFsAXMBewGDATAAiwGTAZsBogGkAawBtAG8AcIBygHSAdoB4AHoAfAB+AH+AQYCDgIWAv4BHgImAi4CNgI+AkUCTQJTAlsCYwJrAnECeQKBAk0CiQKRApkCoQKoArACuALAAsQCzAIwANQC3ALkAjAA7AL0AvwCAQMJAxADGAMwACADJgMuAzYDPgOAAEYDSgNSA1IDUgNaA1oDYANiA2IDgACAAGoDgAByA3YDfgOAAIQDgACKA5IDmgOAAIAAogOqA4AAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAK8DtwOAAIAAvwPHA88D1wPfAyAD5wPsA/QD/AOAAIAABAQMBBIEgAAWBB4EJgQuBDMEIAM7BEEEXgBJBCADUQRZBGEEaQQwADAAcQQ+AXkEgQSJBJEEgACYBIAAoASoBK8EtwQwAL8ExQSAAIAAgACAAIAAgACgAM0EXgBeAF4AXgBeAF4AXgBeANUEXgDZBOEEXgDpBPEE+QQBBQkFEQUZBSEFKQUxBTUFPQVFBUwFVAVcBV4AYwVeAGsFcwV7BYMFiwWSBV4AmgWgBacFXgBeAF4AXgBeAKsFXgCyBbEFugW7BcIFwgXIBcIFwgXQBdQF3AXkBesF8wX7BQMGCwYTBhsGIwYrBjMGOwZeAD8GRwZNBl4AVAZbBl4AXgBeAF4AXgBeAF4AXgBeAF4AXgBeAGMGXgBqBnEGXgBeAF4AXgBeAF4AXgBeAF4AXgB5BoAG4wSGBo4GkwaAAIADHgR5AF4AXgBeAJsGgABGA4AAowarBrMGswagALsGwwbLBjAA0wbaBtoG3QbaBtoG2gbaBtoG2gblBusG8wb7BgMHCwcTBxsHCwcjBysHMAc1BzUHOgdCB9oGSgdSB1oHYAfaBloHaAfaBlIH2gbaBtoG2gbaBtoG2gbaBjUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHbQdeAF4ANQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQd1B30HNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1B4MH2gaKB68EgACAAIAAgACAAIAAgACAAI8HlwdeAJ8HpweAAIAArwe3B14AXgC/B8UHygcwANAH2AfgB4AA6AfwBz4B+AcACFwBCAgPCBcIogEYAR8IJwiAAC8INwg/CCADRwhPCFcIXwhnCEoDGgSAAIAAgABvCHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIfQh3CHgIeQh6CHsIfAh9CHcIeAh5CHoIewh8CH0Idwh4CHkIegh7CHwIhAiLCI4IMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwAJYIlgiWCJYIlgiWCJYIlgiWCJYIlgiWCJYIlgiWCJYIlgiWCJYIlgiWCJYIlgiWCJYIlgiWCJYIlgiWCJYIlggwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAANQc1BzUHNQc1BzUHNQc1BzUHNQc1B54INQc1B6II2gaqCLIIugiAAIAAvgjGCIAAgACAAIAAgACAAIAAgACAAIAAywiHAYAA0wiAANkI3QjlCO0I9Aj8CIAAgACAAAIJCgkSCRoJIgknCTYHLwk3CZYIlgiWCJYIlgiWCJYIlgiWCJYIlgiWCJYIlgiWCJYIlgiWCJYIlgiWCJYIlgiWCJYIlgiWCJYIlgiWCJYIlgiAAIAAAAFAAXgBeAGAAcABeAHwAQACQAKAArQC9AJ4AXgBeAE0A3gBRAN4A7AD8AMwBGgEAAKcBNwEFAUwBXAF4QkhCmEKnArcCgAHHAsABz4LAAcABwAHAAd+C6ABoAG+C/4LAAcABwAHAAc+DF4MAAcAB54M3gweDV4Nng3eDaABoAGgAaABoAGgAaABoAGgAaABoAGgAaABoAGgAaABoAGgAaABoAEeDqABVg6WDqABoQ6gAaABoAHXDvcONw/3DvcO9w73DvcO9w73DvcO9w73DvcO9w73DvcO9w73DvcO9w73DvcO9w73DvcO9w73DvcO9w73DvcO9w73DncPAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcAB7cPPwlGCU4JMACAAIAAgABWCV4JYQmAAGkJcAl4CXwJgAkwADAAMAAwAIgJgACLCZMJgACZCZ8JowmrCYAAswkwAF4AXgB8AIAAuwkABMMJyQmAAM4JgADVCTAAMAAwADAAgACAAIAAgACAAIAAgACAAIAAqwYWBNkIMAAwADAAMADdCeAJ6AnuCR4E9gkwAP4JBQoNCjAAMACAABUK0wiAAB0KJAosCjQKgAAwADwKQwqAAEsKvQmdCVMKWwowADAAgACAALcEMACAAGMKgABrCjAAMAAwADAAMAAwADAAMAAwADAAMAAeBDAAMAAwADAAMAAwADAAMAAwADAAMAAwAIkEPQFzCnoKiQSCCooKkAqJBJgKoAqkCokEGAGsCrQKvArBCjAAMADJCtEKFQHZCuEK/gHpCvEKMAAwADAAMACAAIwE+QowAIAAPwEBCzAAMAAwADAAMACAAAkLEQswAIAAPwEZCyELgAAOCCkLMAAxCzkLMAAwADAAMAAwADAAXgBeAEELMAAwADAAMAAwADAAMAAwAEkLTQtVC4AAXAtkC4AAiQkwADAAMAAwADAAMAAwADAAbAtxC3kLgAuFC4sLMAAwAJMLlwufCzAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAApwswADAAMACAAIAAgACvC4AAgACAAIAAgACAALcLMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAvwuAAMcLgACAAIAAgACAAIAAyguAAIAAgACAAIAA0QswADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAANkLgACAAIAA4AswADAAMAAwADAAMAAwADAAMAAwADAAMAAwAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACJCR4E6AswADAAhwHwC4AA+AsADAgMEAwwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMACAAIAAGAwdDCUMMAAwAC0MNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQw1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHPQwwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADUHNQc1BzUHNQc1BzUHNQc2BzAAMAA5DDUHNQc1BzUHNQc1BzUHNQc1BzUHNQdFDDAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAgACAAIAATQxSDFoMMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwAF4AXgBeAF4AXgBeAF4AYgxeAGoMXgBxDHkMfwxeAIUMXgBeAI0MMAAwADAAMAAwAF4AXgCVDJ0MMAAwADAAMABeAF4ApQxeAKsMswy7DF4Awgy9DMoMXgBeAF4AXgBeAF4AXgBeAF4AXgDRDNkMeQBqCeAM3Ax8AOYM7Az0DPgMXgBeAF4AXgBeAF4AXgBeAF4AXgBeAF4AXgBeAF4AXgCgAAANoAAHDQ4NFg0wADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAeDSYNMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwAIAAgACAAIAAgACAAC4NMABeAF4ANg0wADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwAD4NRg1ODVYNXg1mDTAAbQ0wADAAMAAwADAAMAAwADAA2gbaBtoG2gbaBtoG2gbaBnUNeg3CBYANwgWFDdoGjA3aBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gaUDZwNpA2oDdoG2gawDbcNvw3HDdoG2gbPDdYN3A3fDeYN2gbsDfMN2gbaBvoN/g3aBgYODg7aBl4AXgBeABYOXgBeACUG2gYeDl4AJA5eACwO2w3aBtoGMQ45DtoG2gbaBtoGQQ7aBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gZJDjUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1B1EO2gY1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQdZDjUHNQc1BzUHNQc1B2EONQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHaA41BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1B3AO2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gY1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1BzUHNQc1B2EO2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gZJDtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBtoG2gbaBkkOeA6gAKAAoAAwADAAMAAwAKAAoACgAKAAoACgAKAAgA4wADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAD//wQABAAEAAQABAAEAAQABAAEAA0AAwABAAEAAgAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAKABMAFwAeABsAGgAeABcAFgASAB4AGwAYAA8AGAAcAEsASwBLAEsASwBLAEsASwBLAEsAGAAYAB4AHgAeABMAHgBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAFgAbABIAHgAeAB4AUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQABYADQARAB4ABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsABAAEAAQABAAEAAUABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAkAFgAaABsAGwAbAB4AHQAdAB4ATwAXAB4ADQAeAB4AGgAbAE8ATwAOAFAAHQAdAB0ATwBPABcATwBPAE8AFgBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAHQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB0AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgBQAB4AHgAeAB4AUABQAFAAUAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAeAB4AHgAeAFAATwBAAE8ATwBPAEAATwBQAFAATwBQAB4AHgAeAB4AHgAeAB0AHQAdAB0AHgAdAB4ADgBQAFAAUABQAFAAHgAeAB4AHgAeAB4AHgBQAB4AUAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4ABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAJAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAkACQAJAAkACQAJAAkABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAeAB4AHgAeAFAAHgAeAB4AKwArAFAAUABQAFAAGABQACsAKwArACsAHgAeAFAAHgBQAFAAUAArAFAAKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4ABAAEAAQABAAEAAQABAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAUAAeAB4AHgAeAB4AHgArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwAYAA0AKwArAB4AHgAbACsABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQADQAEAB4ABAAEAB4ABAAEABMABAArACsAKwArACsAKwArACsAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAKwArACsAKwArAFYAVgBWAB4AHgArACsAKwArACsAKwArACsAKwArACsAHgAeAB4AHgAeAB4AHgAeAB4AGgAaABoAGAAYAB4AHgAEAAQABAAEAAQABAAEAAQABAAEAAQAEwAEACsAEwATAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABABLAEsASwBLAEsASwBLAEsASwBLABoAGQAZAB4AUABQAAQAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQABMAUAAEAAQABAAEAAQABAAEAB4AHgAEAAQABAAEAAQABABQAFAABAAEAB4ABAAEAAQABABQAFAASwBLAEsASwBLAEsASwBLAEsASwBQAFAAUAAeAB4AUAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwAeAFAABABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEAAQABAAEAFAAKwArACsAKwArACsAKwArACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEAAQAUABQAB4AHgAYABMAUAArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAFAABAAEAAQABAAEAFAABAAEAAQAUAAEAAQABAAEAAQAKwArAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAArACsAHgArAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAeAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABABQAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAFAABAAEAAQABAAEAAQABABQAFAAUABQAFAAUABQAFAAUABQAAQABAANAA0ASwBLAEsASwBLAEsASwBLAEsASwAeAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQAKwBQAFAAUABQAFAAUABQAFAAKwArAFAAUAArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAUABQAFAAUAArAFAAKwArACsAUABQAFAAUAArACsABABQAAQABAAEAAQABAAEAAQAKwArAAQABAArACsABAAEAAQAUAArACsAKwArACsAKwArACsABAArACsAKwArAFAAUAArAFAAUABQAAQABAArACsASwBLAEsASwBLAEsASwBLAEsASwBQAFAAGgAaAFAAUABQAFAAUABMAB4AGwBQAB4AKwArACsABAAEAAQAKwBQAFAAUABQAFAAUAArACsAKwArAFAAUAArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAUABQAFAAUAArAFAAUAArAFAAUAArAFAAUAArACsABAArAAQABAAEAAQABAArACsAKwArAAQABAArACsABAAEAAQAKwArACsABAArACsAKwArACsAKwArAFAAUABQAFAAKwBQACsAKwArACsAKwArACsASwBLAEsASwBLAEsASwBLAEsASwAEAAQAUABQAFAABAArACsAKwArACsAKwArACsAKwArACsABAAEAAQAKwBQAFAAUABQAFAAUABQAFAAUAArAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAUABQAFAAUAArAFAAUAArAFAAUABQAFAAUAArACsABABQAAQABAAEAAQABAAEAAQABAArAAQABAAEACsABAAEAAQAKwArAFAAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAUABQAAQABAArACsASwBLAEsASwBLAEsASwBLAEsASwAeABsAKwArACsAKwArACsAKwBQAAQABAAEAAQABAAEACsABAAEAAQAKwBQAFAAUABQAFAAUABQAFAAKwArAFAAUAArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQAKwArAAQABAArACsABAAEAAQAKwArACsAKwArACsAKwArAAQABAArACsAKwArAFAAUAArAFAAUABQAAQABAArACsASwBLAEsASwBLAEsASwBLAEsASwAeAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwArACsAKwAEAFAAKwBQAFAAUABQAFAAUAArACsAKwBQAFAAUAArAFAAUABQAFAAKwArACsAUABQACsAUAArAFAAUAArACsAKwBQAFAAKwArACsAUABQAFAAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwAEAAQABAAEAAQAKwArACsABAAEAAQAKwAEAAQABAAEACsAKwBQACsAKwArACsAKwArAAQAKwArACsAKwArACsAKwArACsAKwBLAEsASwBLAEsASwBLAEsASwBLAFAAUABQAB4AHgAeAB4AHgAeABsAHgArACsAKwArACsABAAEAAQABAArAFAAUABQAFAAUABQAFAAUAArAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArAFAABAAEAAQABAAEAAQABAArAAQABAAEACsABAAEAAQABAArACsAKwArACsAKwArAAQABAArAFAAUABQACsAKwArACsAKwBQAFAABAAEACsAKwBLAEsASwBLAEsASwBLAEsASwBLACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAB4AUAAEAAQABAArAFAAUABQAFAAUABQAFAAUAArAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAUABQACsAKwAEAFAABAAEAAQABAAEAAQABAArAAQABAAEACsABAAEAAQABAArACsAKwArACsAKwArAAQABAArACsAKwArACsAKwArAFAAKwBQAFAABAAEACsAKwBLAEsASwBLAEsASwBLAEsASwBLACsAUABQACsAKwArACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAFAABAAEAAQABAAEAAQABAArAAQABAAEACsABAAEAAQABABQAB4AKwArACsAKwBQAFAAUAAEAFAAUABQAFAAUABQAFAAUABQAFAABAAEACsAKwBLAEsASwBLAEsASwBLAEsASwBLAFAAUABQAFAAUABQAFAAUABQABoAUABQAFAAUABQAFAAKwArAAQABAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUABQACsAUAArACsAUABQAFAAUABQAFAAUAArACsAKwAEACsAKwArACsABAAEAAQABAAEAAQAKwAEACsABAAEAAQABAAEAAQABAAEACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArAAQABAAeACsAKwArACsAKwArACsAKwArACsAKwArAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXAAqAFwAXAAqACoAKgAqACoAKgAqACsAKwArACsAGwBcAFwAXABcAFwAXABcACoAKgAqACoAKgAqACoAKgAeAEsASwBLAEsASwBLAEsASwBLAEsADQANACsAKwArACsAKwBcAFwAKwBcACsAKwBcAFwAKwBcACsAKwBcACsAKwArACsAKwArAFwAXABcAFwAKwBcAFwAXABcAFwAXABcACsAXABcAFwAKwBcACsAXAArACsAXABcACsAXABcAFwAXAAqAFwAXAAqACoAKgAqACoAKgArACoAKgBcACsAKwBcAFwAXABcAFwAKwBcACsAKgAqACoAKgAqACoAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArAFwAXABcAFwAUAAOAA4ADgAOAB4ADgAOAAkADgAOAA0ACQATABMAEwATABMACQAeABMAHgAeAB4ABAAEAB4AHgAeAB4AHgAeAEsASwBLAEsASwBLAEsASwBLAEsAUABQAFAAUABQAFAAUABQAFAAUAANAAQAHgAEAB4ABAAWABEAFgARAAQABABQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAANAAQABAAEAAQABAANAAQABABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEAAQABAAEACsABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsADQANAB4AHgAeAB4AHgAeAAQAHgAeAB4AHgAeAB4AKwAeAB4ADgAOAA0ADgAeAB4AHgAeAB4ACQAJACsAKwArACsAKwBcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqAFwASwBLAEsASwBLAEsASwBLAEsASwANAA0AHgAeAB4AHgBcAFwAXABcAFwAXAAqACoAKgAqAFwAXABcAFwAKgAqACoAXAAqACoAKgBcAFwAKgAqACoAKgAqACoAKgBcAFwAXAAqACoAKgAqAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAKgAqACoAKgAqACoAKgAqACoAKgAqACoAXAAqAEsASwBLAEsASwBLAEsASwBLAEsAKgAqACoAKgAqACoAUABQAFAAUABQAFAAKwBQACsAKwArACsAKwBQACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAeAFAAUABQAFAAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQACsAKwBQAFAAUABQAFAAUABQACsAUAArAFAAUABQAFAAKwArAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAUAArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAUAArACsAUABQAFAAUABQAFAAUAArAFAAKwBQAFAAUABQACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwAEAAQABAAeAA0AHgAeAB4AHgAeAB4AHgBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAeAB4AHgAeAB4AHgAeAB4AHgAeACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArAFAAUABQAFAAUABQACsAKwANAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAeAB4AUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAA0AUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQABYAEQArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAADQANAA0AUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAABAAEAAQAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAA0ADQArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQAKwArACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQACsABAAEACsAKwArACsAKwArACsAKwArACsAKwArAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXAAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoADQANABUAXAANAB4ADQAbAFwAKgArACsASwBLAEsASwBLAEsASwBLAEsASwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArAB4AHgATABMADQANAA4AHgATABMAHgAEAAQABAAJACsASwBLAEsASwBLAEsASwBLAEsASwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAUABQAFAAUABQAAQABABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABABQACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsAKwArACsABAAEAAQABAAEAAQABAAEAAQABAAEAAQAKwArACsAKwAeACsAKwArABMAEwBLAEsASwBLAEsASwBLAEsASwBLAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcACsAKwBcAFwAXABcAFwAKwArACsAKwArACsAKwArACsAKwArAFwAXABcAFwAXABcAFwAXABcAFwAXABcACsAKwArACsAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAKwArACsAKwArACsASwBLAEsASwBLAEsASwBLAEsASwBcACsAKwArACoAKgBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEACsAKwAeAB4AXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAKgAqACoAKgAqACoAKgAqACoAKgArACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgArACsABABLAEsASwBLAEsASwBLAEsASwBLACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsAKgAqACoAKgAqACoAKgBcACoAKgAqACoAKgAqACsAKwAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAArAAQABAAEAAQABABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQAUABQAFAAUABQAFAAUAArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsADQANAB4ADQANAA0ADQAeAB4AHgAeAB4AHgAeAB4AHgAeAAQABAAEAAQABAAEAAQABAAEAB4AHgAeAB4AHgAeAB4AHgAeACsAKwArAAQABAAEAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAUABQAEsASwBLAEsASwBLAEsASwBLAEsAUABQAFAAUABQAFAAUABQAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAArACsAKwArACsAKwArACsAHgAeAB4AHgBQAFAAUABQAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAArACsAKwANAA0ADQANAA0ASwBLAEsASwBLAEsASwBLAEsASwArACsAKwBQAFAAUABLAEsASwBLAEsASwBLAEsASwBLAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAANAA0AUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAB4AHgAeAB4AHgAeAB4AHgArACsAKwArACsAKwArACsABAAEAAQAHgAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAFAAUABQAFAABABQAFAAUABQAAQABAAEAFAAUAAEAAQABAArACsAKwArACsAKwAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAKwAEAAQABAAEAAQAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArACsAUABQAFAAUABQAFAAKwArAFAAUABQAFAAUABQAFAAUAArAFAAKwBQACsAUAArAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwArAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeACsAHgAeAB4AHgAeAB4AHgAeAFAAHgAeAB4AUABQAFAAKwAeAB4AHgAeAB4AHgAeAB4AHgAeAFAAUABQAFAAKwArAB4AHgAeAB4AHgAeACsAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArACsAUABQAFAAKwAeAB4AHgAeAB4AHgAeAA4AHgArAA0ADQANAA0ADQANAA0ACQANAA0ADQAIAAQACwAEAAQADQAJAA0ADQAMAB0AHQAeABcAFwAWABcAFwAXABYAFwAdAB0AHgAeABQAFAAUAA0AAQABAAQABAAEAAQABAAJABoAGgAaABoAGgAaABoAGgAeABcAFwAdABUAFQAeAB4AHgAeAB4AHgAYABYAEQAVABUAFQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgANAB4ADQANAA0ADQAeAA0ADQANAAcAHgAeAB4AHgArAAQABAAEAAQABAAEAAQABAAEAAQAUABQACsAKwBPAFAAUABQAFAAUAAeAB4AHgAWABEATwBQAE8ATwBPAE8AUABQAFAAUABQAB4AHgAeABYAEQArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAGwAbABsAGwAbABsAGwAaABsAGwAbABsAGwAbABsAGwAbABsAGwAbABsAGwAaABsAGwAbABsAGgAbABsAGgAbABsAGwAbABsAGwAbABsAGwAbABsAGwAbABsAGwAbABsABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAB4AHgBQABoAHgAdAB4AUAAeABoAHgAeAB4AHgAeAB4AHgAeAB4ATwAeAFAAGwAeAB4AUABQAFAAUABQAB4AHgAeAB0AHQAeAFAAHgBQAB4AUAAeAFAATwBQAFAAHgAeAB4AHgAeAB4AHgBQAFAAUABQAFAAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgBQAB4AUABQAFAAUABPAE8AUABQAFAAUABQAE8AUABQAE8AUABPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBQAFAAUABQAE8ATwBPAE8ATwBPAE8ATwBPAE8AUABQAFAAUABQAFAAUABQAFAAHgAeAFAAUABQAFAATwAeAB4AKwArACsAKwAdAB0AHQAdAB0AHQAdAB0AHQAdAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAdAB4AHQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHQAeAB0AHQAeAB4AHgAdAB0AHgAeAB0AHgAeAB4AHQAeAB0AGwAbAB4AHQAeAB4AHgAeAB0AHgAeAB0AHQAdAB0AHgAeAB0AHgAdAB4AHQAdAB0AHQAdAB0AHgAdAB4AHgAeAB4AHgAdAB0AHQAdAB4AHgAeAB4AHQAdAB4AHgAeAB4AHgAeAB4AHgAeAB4AHQAeAB4AHgAdAB4AHgAeAB4AHgAdAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHQAdAB4AHgAdAB0AHQAdAB4AHgAdAB0AHgAeAB0AHQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAdAB0AHgAeAB0AHQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB0AHgAeAB4AHQAeAB4AHgAeAB4AHgAeAB0AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAdAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeABQAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAWABEAFgARAB4AHgAeAB4AHgAeAB0AHgAeAB4AHgAeAB4AHgAlACUAHgAeAB4AHgAeAB4AHgAeAB4AFgARAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeACUAJQAlACUAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBQAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB4AHgAeAB4AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHgAeAB0AHQAdAB0AHgAeAB4AHgAeAB4AHgAeAB4AHgAdAB0AHgAdAB0AHQAdAB0AHQAdAB4AHgAeAB4AHgAeAB4AHgAdAB0AHgAeAB0AHQAeAB4AHgAeAB0AHQAeAB4AHgAeAB0AHQAdAB4AHgAdAB4AHgAdAB0AHQAdAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHQAdAB0AHQAeAB4AHgAeAB4AHgAeAB4AHgAdAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AJQAlACUAJQAeAB0AHQAeAB4AHQAeAB4AHgAeAB0AHQAeAB4AHgAeACUAJQAdAB0AJQAeACUAJQAlACAAJQAlAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AJQAlACUAHgAeAB4AHgAdAB4AHQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHQAdAB4AHQAdAB0AHgAdACUAHQAdAB4AHQAdAB4AHQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAlAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB0AHQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AJQAlACUAJQAlACUAJQAlACUAJQAlACUAHQAdAB0AHQAlAB4AJQAlACUAHQAlACUAHQAdAB0AJQAlAB0AHQAlAB0AHQAlACUAJQAeAB0AHgAeAB4AHgAdAB0AJQAdAB0AHQAdAB0AHQAlACUAJQAlACUAHQAlACUAIAAlAB0AHQAlACUAJQAlACUAJQAlACUAHgAeAB4AJQAlACAAIAAgACAAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAdAB4AHgAeABcAFwAXABcAFwAXAB4AEwATACUAHgAeAB4AFgARABYAEQAWABEAFgARABYAEQAWABEAFgARAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAWABEAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AFgARABYAEQAWABEAFgARABYAEQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeABYAEQAWABEAFgARABYAEQAWABEAFgARABYAEQAWABEAFgARABYAEQAWABEAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AFgARABYAEQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeABYAEQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHQAdAB0AHQAdAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwArAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwArACsAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwAeAB4AHgAeAB4AHgAeAB4AHgArACsAKwArACsAKwArACsAKwArACsAKwArAB4AHgAeAB4AKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAEAAQABAAeAB4AKwArACsAKwArABMADQANAA0AUAATAA0AUABQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAUAANACsAKwArACsAKwArACsAKwArACsAKwArACsAKwAEAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQACsAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQACsAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXAA0ADQANAA0ADQANAA0ADQAeAA0AFgANAB4AHgAXABcAHgAeABcAFwAWABEAFgARABYAEQAWABEADQANAA0ADQATAFAADQANAB4ADQANAB4AHgAeAB4AHgAMAAwADQANAA0AHgANAA0AFgANAA0ADQANAA0ADQANACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACsAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAKwArACsAKwArACsAKwArACsAKwArACsAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwAlACUAJQAlACUAJQAlACUAJQAlACUAJQArACsAKwArAA0AEQARACUAJQBHAFcAVwAWABEAFgARABYAEQAWABEAFgARACUAJQAWABEAFgARABYAEQAWABEAFQAWABEAEQAlAFcAVwBXAFcAVwBXAFcAVwBXAAQABAAEAAQABAAEACUAVwBXAFcAVwA2ACUAJQBXAFcAVwBHAEcAJQAlACUAKwBRAFcAUQBXAFEAVwBRAFcAUQBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFEAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBRAFcAUQBXAFEAVwBXAFcAVwBXAFcAUQBXAFcAVwBXAFcAVwBRAFEAKwArAAQABAAVABUARwBHAFcAFQBRAFcAUQBXAFEAVwBRAFcAUQBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFEAVwBRAFcAUQBXAFcAVwBXAFcAVwBRAFcAVwBXAFcAVwBXAFEAUQBXAFcAVwBXABUAUQBHAEcAVwArACsAKwArACsAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAKwArAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwArACUAJQBXAFcAVwBXACUAJQAlACUAJQAlACUAJQAlACUAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAKwArACsAKwArACUAJQAlACUAKwArACsAKwArACsAKwArACsAKwArACsAUQBRAFEAUQBRAFEAUQBRAFEAUQBRAFEAUQBRAFEAUQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACsAVwBXAFcAVwBXAFcAVwBXAFcAVwAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlAE8ATwBPAE8ATwBPAE8ATwAlAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXACUAJQAlACUAJQAlACUAJQAlACUAVwBXAFcAVwBXAFcAVwBXAFcAVwBXACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAEcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAKwArACsAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAADQATAA0AUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABLAEsASwBLAEsASwBLAEsASwBLAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAFAABAAEAAQABAAeAAQABAAEAAQABAAEAAQABAAEAAQAHgBQAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AUABQAAQABABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAeAA0ADQANAA0ADQArACsAKwArACsAKwArACsAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAFAAUABQAFAAUABQAFAAUABQAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AUAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgBQAB4AHgAeAB4AHgAeAFAAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArAB4AHgAeAB4AHgAeAB4AHgArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAAQAUABQAFAABABQAFAAUABQAAQAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAAQABAAeAB4AHgAeACsAKwArACsAUABQAFAAUABQAFAAHgAeABoAHgArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAADgAOABMAEwArACsAKwArACsAKwArACsABAAEAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAAQABAAEACsAKwArACsAKwArACsAKwANAA0ASwBLAEsASwBLAEsASwBLAEsASwArACsAKwArACsAKwAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABABQAFAAUABQAFAAUAAeAB4AHgBQAA4AUAArACsAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEAA0ADQBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAKwArACsAKwArACsAKwArACsAKwArAB4AWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYACsAKwArAAQAHgAeAB4AHgAeAB4ADQANAA0AHgAeAB4AHgArAFAASwBLAEsASwBLAEsASwBLAEsASwArACsAKwArAB4AHgBcAFwAXABcAFwAKgBcAFwAXABcAFwAXABcAFwAXABcAEsASwBLAEsASwBLAEsASwBLAEsAXABcAFwAXABcACsAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsAKwArACsAKwArACsAKwArAFAAUABQAAQAUABQAFAAUABQAFAAUABQAAQABAArACsASwBLAEsASwBLAEsASwBLAEsASwArACsAHgANAA0ADQBcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAKgAqACoAXAAqACoAKgBcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXAAqAFwAKgAqACoAXABcACoAKgBcAFwAXABcAFwAKgAqAFwAKgBcACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAFwAXABcACoAKgBQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAA0ADQBQAFAAUAAEAAQAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUAArACsAUABQAFAAUABQAFAAKwArAFAAUABQAFAAUABQACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAAQADQAEAAQAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsAVABVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBUAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVACsAKwArACsAKwArACsAKwArACsAKwArAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAKwArACsAKwBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAKwArACsAKwAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXACUAJQBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAJQAlACUAJQAlACUAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAKwArACsAKwArAFYABABWAFYAVgBWAFYAVgBWAFYAVgBWAB4AVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgArAFYAVgBWAFYAVgArAFYAKwBWAFYAKwBWAFYAKwBWAFYAVgBWAFYAVgBWAFYAVgBWAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAEQAWAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUAAaAB4AKwArAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAGAARABEAGAAYABMAEwAWABEAFAArACsAKwArACsAKwAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACUAJQAlACUAJQAWABEAFgARABYAEQAWABEAFgARABYAEQAlACUAFgARACUAJQAlACUAJQAlACUAEQAlABEAKwAVABUAEwATACUAFgARABYAEQAWABEAJQAlACUAJQAlACUAJQAlACsAJQAbABoAJQArACsAKwArAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArAAcAKwATACUAJQAbABoAJQAlABYAEQAlACUAEQAlABEAJQBXAFcAVwBXAFcAVwBXAFcAVwBXABUAFQAlACUAJQATACUAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXABYAJQARACUAJQAlAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwAWACUAEQAlABYAEQARABYAEQARABUAVwBRAFEAUQBRAFEAUQBRAFEAUQBRAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAEcARwArACsAVwBXAFcAVwBXAFcAKwArAFcAVwBXAFcAVwBXACsAKwBXAFcAVwBXAFcAVwArACsAVwBXAFcAKwArACsAGgAbACUAJQAlABsAGwArAB4AHgAeAB4AHgAeAB4AKwArACsAKwArACsAKwArACsAKwAEAAQABAAQAB0AKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsADQANAA0AKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArAB4AHgAeAB4AHgAeAB4AHgAeAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgBQAFAAHgAeAB4AKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArACsAKwArAB4AKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4ABAArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAAQAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsADQBQAFAAUABQACsAKwArACsAUABQAFAAUABQAFAAUABQAA0AUABQAFAAUABQACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwArACsAKwArAB4AKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUAArACsAUAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAUABQACsAKwArAFAAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAA0AUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAB4AHgBQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAUABQACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsADQBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArAB4AUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwBQAFAAUABQAFAABAAEAAQAKwAEAAQAKwArACsAKwArAAQABAAEAAQAUABQAFAAUAArAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsABAAEAAQAKwArACsAKwAEAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsADQANAA0ADQANAA0ADQANAB4AKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAB4AUABQAFAAUABQAFAAUABQAB4AUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEACsAKwArACsAUABQAFAAUABQAA0ADQANAA0ADQANABQAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwANAA0ADQANAA0ADQANAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAHgAeAB4AHgArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwBQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAA0ADQAeAB4AHgAeAB4AKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsABABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAAQABAAEAAQABAAEAAQABAAeAB4AHgANAA0ADQANACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwBLAEsASwBLAEsASwBLAEsASwBLACsAKwArACsAKwArAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsASwBLAEsASwBLAEsASwBLAEsASwANAA0ADQANACsAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAeAA4AUAArACsAKwArACsAKwArACsAKwAEAFAAUABQAFAADQANAB4ADQAeAAQABAAEAB4AKwArAEsASwBLAEsASwBLAEsASwBLAEsAUAAOAFAADQANAA0AKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAAQABAAEAAQABAANAA0AHgANAA0AHgAEACsAUABQAFAAUABQAFAAUAArAFAAKwBQAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAA0AKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAAQABAAEAAQAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsABAAEAAQABAArAFAAUABQAFAAUABQAFAAUAArACsAUABQACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAAQABAArACsABAAEACsAKwAEAAQABAArACsAUAArACsAKwArACsAKwAEACsAKwArACsAKwBQAFAAUABQAFAABAAEACsAKwAEAAQABAAEAAQABAAEACsAKwArAAQABAAEAAQABAArACsAKwArACsAKwArACsAKwArACsABAAEAAQABAAEAAQABABQAFAAUABQAA0ADQANAA0AHgBLAEsASwBLAEsASwBLAEsASwBLACsADQArAB4AKwArAAQABAAEAAQAUABQAB4AUAArACsAKwArACsAKwArACsASwBLAEsASwBLAEsASwBLAEsASwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEACsAKwAEAAQABAAEAAQABAAEAAQABAAOAA0ADQATABMAHgAeAB4ADQANAA0ADQANAA0ADQANAA0ADQANAA0ADQANAA0AUABQAFAAUAAEAAQAKwArAAQADQANAB4AUAArACsAKwArACsAKwArACsAKwArACsASwBLAEsASwBLAEsASwBLAEsASwArACsAKwArACsAKwAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsASwBLAEsASwBLAEsASwBLAEsASwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXAArACsAKwAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAXABcAA0ADQANACoASwBLAEsASwBLAEsASwBLAEsASwBQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwBQAFAABAAEAAQABAAEAAQABAAEAAQABABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAFAABAAEAAQABAAOAB4ADQANAA0ADQAOAB4ABAArACsAKwArACsAKwArACsAUAAEAAQABAAEAAQABAAEAAQABAAEAAQAUABQAFAAUAArACsAUABQAFAAUAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAA0ADQANACsADgAOAA4ADQANACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEACsABAAEAAQABAAEAAQABAAEAFAADQANAA0ADQANACsAKwArACsAKwArACsAKwArACsASwBLAEsASwBLAEsASwBLAEsASwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwAOABMAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAArAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQACsAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAArACsAKwAEACsABAAEACsABAAEAAQABAAEAAQABABQAAQAKwArACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsADQANAA0ADQANACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAASABIAEgAQwBDAEMAUABQAFAAUABDAFAAUABQAEgAQwBIAEMAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAASABDAEMAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABIAEMAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwANAA0AKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArAAQABAAEAAQABAANACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAA0ADQANAB4AHgAeAB4AHgAeAFAAUABQAFAADQAeACsAKwArACsAKwArACsAKwArACsASwBLAEsASwBLAEsASwBLAEsASwArAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAUAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsABAAEAAQABABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAEcARwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwArACsAKwArACsAKwArACsAKwArACsAKwArAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQACsAKwAeAAQABAANAAQABAAEAAQAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeACsAKwArACsAKwArACsAKwArACsAHgAeAB4AHgAeAB4AHgArACsAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4ABAAEAAQABAAEAB4AHgAeAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAHgAeAAQABAAEAAQABAAEAAQAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAEAAQABAAEAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAB4AHgAEAAQABAAeACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwArACsAKwArACsAKwArAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeACsAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArAFAAUAArACsAUAArACsAUABQACsAKwBQAFAAUABQACsAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwBQACsAUABQAFAAUABQAFAAUAArAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArAFAAUABQAFAAKwArAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAKwAeAB4AUABQAFAAUABQACsAUAArACsAKwBQAFAAUABQAFAAUABQACsAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAeAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAFAAUABQAFAAUABQAFAAUABQAFAAUAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAHgAeAB4AHgAeAB4AHgAeAB4AKwArAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAB4AHgAeAB4ABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAB4AHgAeAB4AHgAeAB4AHgAEAB4AHgAeAB4AHgAeAB4AHgAeAB4ABAAeAB4ADQANAA0ADQAeACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAAQABAAEAAQABAArAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsABAAEAAQABAAEAAQABAArAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAArACsABAAEAAQABAAEAAQABAArAAQABAArAAQABAAEAAQABAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAKwArAFAAUABQAFAAUABQAFAAUABQAAQABAAEAAQABAAEAAQAKwArACsAKwArACsAKwArACsAHgAeAB4AHgAEAAQABAAEAAQABAAEACsAKwArACsAKwBLAEsASwBLAEsASwBLAEsASwBLACsAKwArACsAFgAWAFAAUABQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUAArAFAAKwArAFAAKwBQAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAUAArAFAAKwBQACsAKwArACsAKwArAFAAKwArACsAKwBQACsAUAArAFAAKwBQAFAAUAArAFAAUAArAFAAKwArAFAAKwBQACsAUAArAFAAKwBQACsAUABQACsAUAArACsAUABQAFAAUAArAFAAUABQAFAAUABQAFAAKwBQAFAAUABQACsAUABQAFAAUAArAFAAKwBQAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwBQAFAAUAArAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAB4AHgArACsAKwArACsAKwArACsAKwArACsAKwArACsATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwAlACUAJQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAeACUAHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHgAeACUAJQAlACUAHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACkAKQApACkAKQApACkAKQApACkAKQApACkAKQApACkAKQApACkAKQApACkAKQApACkAKQAlACUAJQAlACUAIAAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlAB4AHgAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAHgAeACUAJQAlACUAJQAeACUAJQAlACUAJQAgACAAIAAlACUAIAAlACUAIAAgACAAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAIQAhACEAIQAhACUAJQAgACAAJQAlACAAIAAgACAAIAAgACAAIAAgACAAIAAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAIAAgACAAIAAlACUAJQAlACAAJQAgACAAIAAgACAAIAAgACAAIAAlACUAJQAgACUAJQAlACUAIAAgACAAJQAgACAAIAAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAeACUAHgAlAB4AJQAlACUAJQAlACAAJQAlACUAJQAeACUAHgAeACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAHgAeAB4AHgAeAB4AHgAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlAB4AHgAeAB4AHgAeAB4AHgAeAB4AJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAIAAgACUAJQAlACUAIAAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAIAAlACUAJQAlACAAIAAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAeAB4AHgAeAB4AHgAeAB4AJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlAB4AHgAeAB4AHgAeACUAJQAlACUAJQAlACUAIAAgACAAJQAlACUAIAAgACAAIAAgAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AFwAXABcAFQAVABUAHgAeAB4AHgAlACUAJQAgACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAIAAgACAAJQAlACUAJQAlACUAJQAlACUAIAAlACUAJQAlACUAJQAlACUAJQAlACUAIAAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAlACUAJQAlACUAJQAlACUAJQAlACUAJQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAlACUAJQAlAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AJQAlACUAJQAlACUAJQAlAB4AHgAeAB4AHgAeAB4AHgAeAB4AJQAlACUAJQAlACUAHgAeAB4AHgAeAB4AHgAeACUAJQAlACUAJQAlACUAJQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeACUAJQAlACUAJQAlACUAJQAlACUAJQAlACAAIAAgACAAIAAlACAAIAAlACUAJQAlACUAJQAgACUAJQAlACUAJQAlACUAJQAlACAAIAAgACAAIAAgACAAIAAgACAAJQAlACUAIAAgACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACsAKwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAJQAlACUAJQAlACUAJQAlACUAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAJQAlACUAJQAlACUAJQAlACUAJQAlAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQArAAQAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsA';
- /* @flow */
- var LETTER_NUMBER_MODIFIER = 50;
- // Non-tailorable Line Breaking Classes
- var BK = 1; // Cause a line break (after)
- var CR = 2; // Cause a line break (after), except between CR and LF
- var LF = 3; // Cause a line break (after)
- var CM = 4; // Prohibit a line break between the character and the preceding character
- var NL = 5; // Cause a line break (after)
- var WJ = 7; // Prohibit line breaks before and after
- var ZW = 8; // Provide a break opportunity
- var GL = 9; // Prohibit line breaks before and after
- var SP = 10; // Enable indirect line breaks
- var ZWJ = 11; // Prohibit line breaks within joiner sequences
- // Break Opportunities
- var B2 = 12; // Provide a line break opportunity before and after the character
- var BA = 13; // Generally provide a line break opportunity after the character
- var BB = 14; // Generally provide a line break opportunity before the character
- var HY = 15; // Provide a line break opportunity after the character, except in numeric context
- var CB = 16; // Provide a line break opportunity contingent on additional information
- // Characters Prohibiting Certain Breaks
- var CL = 17; // Prohibit line breaks before
- var CP = 18; // Prohibit line breaks before
- var EX = 19; // Prohibit line breaks before
- var IN = 20; // Allow only indirect line breaks between pairs
- var NS = 21; // Allow only indirect line breaks before
- var OP = 22; // Prohibit line breaks after
- var QU = 23; // Act like they are both opening and closing
- // Numeric Context
- var IS = 24; // Prevent breaks after any and before numeric
- var NU = 25; // Form numeric expressions for line breaking purposes
- var PO = 26; // Do not break following a numeric expression
- var PR = 27; // Do not break in front of a numeric expression
- var SY = 28; // Prevent a break before; and allow a break after
- // Other Characters
- var AI = 29; // Act like AL when the resolvedEAW is N; otherwise; act as ID
- var AL = 30; // Are alphabetic characters or symbols that are used with alphabetic characters
- var CJ = 31; // Treat as NS or ID for strict or normal breaking.
- var EB = 32; // Do not break from following Emoji Modifier
- var EM = 33; // Do not break from preceding Emoji Base
- var H2 = 34; // Form Korean syllable blocks
- var H3 = 35; // Form Korean syllable blocks
- var HL = 36; // Do not break around a following hyphen; otherwise act as Alphabetic
- var ID = 37; // Break before or after; except in some numeric context
- var JL = 38; // Form Korean syllable blocks
- var JV = 39; // Form Korean syllable blocks
- var JT = 40; // Form Korean syllable blocks
- var RI = 41; // Keep pairs together. For pairs; break before and after other classes
- var SA = 42; // Provide a line break opportunity contingent on additional, language-specific context analysis
- var XX = 43; // Have as yet unknown line breaking behavior or unassigned code positions
- var BREAK_MANDATORY = '!';
- var BREAK_NOT_ALLOWED = '×';
- var BREAK_ALLOWED = '÷';
- var UnicodeTrie = createTrieFromBase64(base64);
- var ALPHABETICS = [AL, HL];
- var HARD_LINE_BREAKS = [BK, CR, LF, NL];
- var SPACE = [SP, ZW];
- var PREFIX_POSTFIX = [PR, PO];
- var LINE_BREAKS = HARD_LINE_BREAKS.concat(SPACE);
- var KOREAN_SYLLABLE_BLOCK = [JL, JV, JT, H2, H3];
- var HYPHEN = [HY, BA];
- var codePointsToCharacterClasses = function (codePoints, lineBreak) {
- if (lineBreak === void 0) { lineBreak = 'strict'; }
- var types = [];
- var indicies = [];
- var categories = [];
- codePoints.forEach(function (codePoint, index) {
- var classType = UnicodeTrie.get(codePoint);
- if (classType > LETTER_NUMBER_MODIFIER) {
- categories.push(true);
- classType -= LETTER_NUMBER_MODIFIER;
- }
- else {
- categories.push(false);
- }
- if (['normal', 'auto', 'loose'].indexOf(lineBreak) !== -1) {
- // U+2010, – U+2013, 〜 U+301C, ゠ U+30A0
- if ([0x2010, 0x2013, 0x301c, 0x30a0].indexOf(codePoint) !== -1) {
- indicies.push(index);
- return types.push(CB);
- }
- }
- if (classType === CM || classType === ZWJ) {
- // LB10 Treat any remaining combining mark or ZWJ as AL.
- if (index === 0) {
- indicies.push(index);
- return types.push(AL);
- }
- // LB9 Do not break a combining character sequence; treat it as if it has the line breaking class of
- // the base character in all of the following rules. Treat ZWJ as if it were CM.
- var prev = types[index - 1];
- if (LINE_BREAKS.indexOf(prev) === -1) {
- indicies.push(indicies[index - 1]);
- return types.push(prev);
- }
- indicies.push(index);
- return types.push(AL);
- }
- indicies.push(index);
- if (classType === CJ) {
- return types.push(lineBreak === 'strict' ? NS : ID);
- }
- if (classType === SA) {
- return types.push(AL);
- }
- if (classType === AI) {
- return types.push(AL);
- }
- // For supplementary characters, a useful default is to treat characters in the range 10000..1FFFD as AL
- // and characters in the ranges 20000..2FFFD and 30000..3FFFD as ID, until the implementation can be revised
- // to take into account the actual line breaking properties for these characters.
- if (classType === XX) {
- if ((codePoint >= 0x20000 && codePoint <= 0x2fffd) || (codePoint >= 0x30000 && codePoint <= 0x3fffd)) {
- return types.push(ID);
- }
- else {
- return types.push(AL);
- }
- }
- types.push(classType);
- });
- return [indicies, types, categories];
- };
- var isAdjacentWithSpaceIgnored = function (a, b, currentIndex, classTypes) {
- var current = classTypes[currentIndex];
- if (Array.isArray(a) ? a.indexOf(current) !== -1 : a === current) {
- var i = currentIndex;
- while (i <= classTypes.length) {
- i++;
- var next = classTypes[i];
- if (next === b) {
- return true;
- }
- if (next !== SP) {
- break;
- }
- }
- }
- if (current === SP) {
- var i = currentIndex;
- while (i > 0) {
- i--;
- var prev = classTypes[i];
- if (Array.isArray(a) ? a.indexOf(prev) !== -1 : a === prev) {
- var n = currentIndex;
- while (n <= classTypes.length) {
- n++;
- var next = classTypes[n];
- if (next === b) {
- return true;
- }
- if (next !== SP) {
- break;
- }
- }
- }
- if (prev !== SP) {
- break;
- }
- }
- }
- return false;
- };
- var previousNonSpaceClassType = function (currentIndex, classTypes) {
- var i = currentIndex;
- while (i >= 0) {
- var type = classTypes[i];
- if (type === SP) {
- i--;
- }
- else {
- return type;
- }
- }
- return 0;
- };
- var _lineBreakAtIndex = function (codePoints, classTypes, indicies, index, forbiddenBreaks) {
- if (indicies[index] === 0) {
- return BREAK_NOT_ALLOWED;
- }
- var currentIndex = index - 1;
- if (Array.isArray(forbiddenBreaks) && forbiddenBreaks[currentIndex] === true) {
- return BREAK_NOT_ALLOWED;
- }
- var beforeIndex = currentIndex - 1;
- var afterIndex = currentIndex + 1;
- var current = classTypes[currentIndex];
- // LB4 Always break after hard line breaks.
- // LB5 Treat CR followed by LF, as well as CR, LF, and NL as hard line breaks.
- var before = beforeIndex >= 0 ? classTypes[beforeIndex] : 0;
- var next = classTypes[afterIndex];
- if (current === CR && next === LF) {
- return BREAK_NOT_ALLOWED;
- }
- if (HARD_LINE_BREAKS.indexOf(current) !== -1) {
- return BREAK_MANDATORY;
- }
- // LB6 Do not break before hard line breaks.
- if (HARD_LINE_BREAKS.indexOf(next) !== -1) {
- return BREAK_NOT_ALLOWED;
- }
- // LB7 Do not break before spaces or zero width space.
- if (SPACE.indexOf(next) !== -1) {
- return BREAK_NOT_ALLOWED;
- }
- // LB8 Break before any character following a zero-width space, even if one or more spaces intervene.
- if (previousNonSpaceClassType(currentIndex, classTypes) === ZW) {
- return BREAK_ALLOWED;
- }
- // LB8a Do not break between a zero width joiner and an ideograph, emoji base or emoji modifier.
- if (UnicodeTrie.get(codePoints[currentIndex]) === ZWJ && (next === ID || next === EB || next === EM)) {
- return BREAK_NOT_ALLOWED;
- }
- // LB11 Do not break before or after Word joiner and related characters.
- if (current === WJ || next === WJ) {
- return BREAK_NOT_ALLOWED;
- }
- // LB12 Do not break after NBSP and related characters.
- if (current === GL) {
- return BREAK_NOT_ALLOWED;
- }
- // LB12a Do not break before NBSP and related characters, except after spaces and hyphens.
- if ([SP, BA, HY].indexOf(current) === -1 && next === GL) {
- return BREAK_NOT_ALLOWED;
- }
- // LB13 Do not break before ‘]’ or ‘!’ or ‘;’ or ‘/’, even after spaces.
- if ([CL, CP, EX, IS, SY].indexOf(next) !== -1) {
- return BREAK_NOT_ALLOWED;
- }
- // LB14 Do not break after ‘[’, even after spaces.
- if (previousNonSpaceClassType(currentIndex, classTypes) === OP) {
- return BREAK_NOT_ALLOWED;
- }
- // LB15 Do not break within ‘”[’, even with intervening spaces.
- if (isAdjacentWithSpaceIgnored(QU, OP, currentIndex, classTypes)) {
- return BREAK_NOT_ALLOWED;
- }
- // LB16 Do not break between closing punctuation and a nonstarter (lb=NS), even with intervening spaces.
- if (isAdjacentWithSpaceIgnored([CL, CP], NS, currentIndex, classTypes)) {
- return BREAK_NOT_ALLOWED;
- }
- // LB17 Do not break within ‘——’, even with intervening spaces.
- if (isAdjacentWithSpaceIgnored(B2, B2, currentIndex, classTypes)) {
- return BREAK_NOT_ALLOWED;
- }
- // LB18 Break after spaces.
- if (current === SP) {
- return BREAK_ALLOWED;
- }
- // LB19 Do not break before or after quotation marks, such as ‘ ” ’.
- if (current === QU || next === QU) {
- return BREAK_NOT_ALLOWED;
- }
- // LB20 Break before and after unresolved CB.
- if (next === CB || current === CB) {
- return BREAK_ALLOWED;
- }
- // LB21 Do not break before hyphen-minus, other hyphens, fixed-width spaces, small kana, and other non-starters, or after acute accents.
- if ([BA, HY, NS].indexOf(next) !== -1 || current === BB) {
- return BREAK_NOT_ALLOWED;
- }
- // LB21a Don't break after Hebrew + Hyphen.
- if (before === HL && HYPHEN.indexOf(current) !== -1) {
- return BREAK_NOT_ALLOWED;
- }
- // LB21b Don’t break between Solidus and Hebrew letters.
- if (current === SY && next === HL) {
- return BREAK_NOT_ALLOWED;
- }
- // LB22 Do not break between two ellipses, or between letters, numbers or exclamations and ellipsis.
- if (next === IN && ALPHABETICS.concat(IN, EX, NU, ID, EB, EM).indexOf(current) !== -1) {
- return BREAK_NOT_ALLOWED;
- }
- // LB23 Do not break between digits and letters.
- if ((ALPHABETICS.indexOf(next) !== -1 && current === NU) || (ALPHABETICS.indexOf(current) !== -1 && next === NU)) {
- return BREAK_NOT_ALLOWED;
- }
- // LB23a Do not break between numeric prefixes and ideographs, or between ideographs and numeric postfixes.
- if ((current === PR && [ID, EB, EM].indexOf(next) !== -1) ||
- ([ID, EB, EM].indexOf(current) !== -1 && next === PO)) {
- return BREAK_NOT_ALLOWED;
- }
- // LB24 Do not break between numeric prefix/postfix and letters, or between letters and prefix/postfix.
- if ((ALPHABETICS.indexOf(current) !== -1 && PREFIX_POSTFIX.indexOf(next) !== -1) ||
- (PREFIX_POSTFIX.indexOf(current) !== -1 && ALPHABETICS.indexOf(next) !== -1)) {
- return BREAK_NOT_ALLOWED;
- }
- // LB25 Do not break between the following pairs of classes relevant to numbers:
- if (
- // (PR | PO) × ( OP | HY )? NU
- ([PR, PO].indexOf(current) !== -1 &&
- (next === NU || ([OP, HY].indexOf(next) !== -1 && classTypes[afterIndex + 1] === NU))) ||
- // ( OP | HY ) × NU
- ([OP, HY].indexOf(current) !== -1 && next === NU) ||
- // NU × (NU | SY | IS)
- (current === NU && [NU, SY, IS].indexOf(next) !== -1)) {
- return BREAK_NOT_ALLOWED;
- }
- // NU (NU | SY | IS)* × (NU | SY | IS | CL | CP)
- if ([NU, SY, IS, CL, CP].indexOf(next) !== -1) {
- var prevIndex = currentIndex;
- while (prevIndex >= 0) {
- var type = classTypes[prevIndex];
- if (type === NU) {
- return BREAK_NOT_ALLOWED;
- }
- else if ([SY, IS].indexOf(type) !== -1) {
- prevIndex--;
- }
- else {
- break;
- }
- }
- }
- // NU (NU | SY | IS)* (CL | CP)? × (PO | PR))
- if ([PR, PO].indexOf(next) !== -1) {
- var prevIndex = [CL, CP].indexOf(current) !== -1 ? beforeIndex : currentIndex;
- while (prevIndex >= 0) {
- var type = classTypes[prevIndex];
- if (type === NU) {
- return BREAK_NOT_ALLOWED;
- }
- else if ([SY, IS].indexOf(type) !== -1) {
- prevIndex--;
- }
- else {
- break;
- }
- }
- }
- // LB26 Do not break a Korean syllable.
- if ((JL === current && [JL, JV, H2, H3].indexOf(next) !== -1) ||
- ([JV, H2].indexOf(current) !== -1 && [JV, JT].indexOf(next) !== -1) ||
- ([JT, H3].indexOf(current) !== -1 && next === JT)) {
- return BREAK_NOT_ALLOWED;
- }
- // LB27 Treat a Korean Syllable Block the same as ID.
- if ((KOREAN_SYLLABLE_BLOCK.indexOf(current) !== -1 && [IN, PO].indexOf(next) !== -1) ||
- (KOREAN_SYLLABLE_BLOCK.indexOf(next) !== -1 && current === PR)) {
- return BREAK_NOT_ALLOWED;
- }
- // LB28 Do not break between alphabetics (“at”).
- if (ALPHABETICS.indexOf(current) !== -1 && ALPHABETICS.indexOf(next) !== -1) {
- return BREAK_NOT_ALLOWED;
- }
- // LB29 Do not break between numeric punctuation and alphabetics (“e.g.”).
- if (current === IS && ALPHABETICS.indexOf(next) !== -1) {
- return BREAK_NOT_ALLOWED;
- }
- // LB30 Do not break between letters, numbers, or ordinary symbols and opening or closing parentheses.
- if ((ALPHABETICS.concat(NU).indexOf(current) !== -1 && next === OP) ||
- (ALPHABETICS.concat(NU).indexOf(next) !== -1 && current === CP)) {
- return BREAK_NOT_ALLOWED;
- }
- // LB30a Break between two regional indicator symbols if and only if there are an even number of regional
- // indicators preceding the position of the break.
- if (current === RI && next === RI) {
- var i = indicies[currentIndex];
- var count = 1;
- while (i > 0) {
- i--;
- if (classTypes[i] === RI) {
- count++;
- }
- else {
- break;
- }
- }
- if (count % 2 !== 0) {
- return BREAK_NOT_ALLOWED;
- }
- }
- // LB30b Do not break between an emoji base and an emoji modifier.
- if (current === EB && next === EM) {
- return BREAK_NOT_ALLOWED;
- }
- return BREAK_ALLOWED;
- };
- var cssFormattedClasses = function (codePoints, options) {
- if (!options) {
- options = { lineBreak: 'normal', wordBreak: 'normal' };
- }
- var _a = codePointsToCharacterClasses(codePoints, options.lineBreak), indicies = _a[0], classTypes = _a[1], isLetterNumber = _a[2];
- if (options.wordBreak === 'break-all' || options.wordBreak === 'break-word') {
- classTypes = classTypes.map(function (type) { return ([NU, AL, SA].indexOf(type) !== -1 ? ID : type); });
- }
- var forbiddenBreakpoints = options.wordBreak === 'keep-all'
- ? isLetterNumber.map(function (letterNumber, i) {
- return letterNumber && codePoints[i] >= 0x4e00 && codePoints[i] <= 0x9fff;
- })
- : undefined;
- return [indicies, classTypes, forbiddenBreakpoints];
- };
- var Break = /** @class */ (function () {
- function Break(codePoints, lineBreak, start, end) {
- this.codePoints = codePoints;
- this.required = lineBreak === BREAK_MANDATORY;
- this.start = start;
- this.end = end;
- }
- Break.prototype.slice = function () {
- return fromCodePoint.apply(void 0, this.codePoints.slice(this.start, this.end));
- };
- return Break;
- }());
- var LineBreaker = function (str, options) {
- var codePoints = toCodePoints(str);
- var _a = cssFormattedClasses(codePoints, options), indicies = _a[0], classTypes = _a[1], forbiddenBreakpoints = _a[2];
- var length = codePoints.length;
- var lastEnd = 0;
- var nextIndex = 0;
- return {
- next: function () {
- if (nextIndex >= length) {
- return { done: true, value: null };
- }
- var lineBreak = BREAK_NOT_ALLOWED;
- while (nextIndex < length &&
- (lineBreak = _lineBreakAtIndex(codePoints, classTypes, indicies, ++nextIndex, forbiddenBreakpoints)) ===
- BREAK_NOT_ALLOWED) { }
- if (lineBreak !== BREAK_NOT_ALLOWED || nextIndex === length) {
- var value = new Break(codePoints, lineBreak, lastEnd, nextIndex);
- lastEnd = nextIndex;
- return { value: value, done: false };
- }
- return { done: true, value: null };
- },
- };
- };
- // https://www.w3.org/TR/css-syntax-3
- var TokenType;
- (function (TokenType) {
- TokenType[TokenType["STRING_TOKEN"] = 0] = "STRING_TOKEN";
- TokenType[TokenType["BAD_STRING_TOKEN"] = 1] = "BAD_STRING_TOKEN";
- TokenType[TokenType["LEFT_PARENTHESIS_TOKEN"] = 2] = "LEFT_PARENTHESIS_TOKEN";
- TokenType[TokenType["RIGHT_PARENTHESIS_TOKEN"] = 3] = "RIGHT_PARENTHESIS_TOKEN";
- TokenType[TokenType["COMMA_TOKEN"] = 4] = "COMMA_TOKEN";
- TokenType[TokenType["HASH_TOKEN"] = 5] = "HASH_TOKEN";
- TokenType[TokenType["DELIM_TOKEN"] = 6] = "DELIM_TOKEN";
- TokenType[TokenType["AT_KEYWORD_TOKEN"] = 7] = "AT_KEYWORD_TOKEN";
- TokenType[TokenType["PREFIX_MATCH_TOKEN"] = 8] = "PREFIX_MATCH_TOKEN";
- TokenType[TokenType["DASH_MATCH_TOKEN"] = 9] = "DASH_MATCH_TOKEN";
- TokenType[TokenType["INCLUDE_MATCH_TOKEN"] = 10] = "INCLUDE_MATCH_TOKEN";
- TokenType[TokenType["LEFT_CURLY_BRACKET_TOKEN"] = 11] = "LEFT_CURLY_BRACKET_TOKEN";
- TokenType[TokenType["RIGHT_CURLY_BRACKET_TOKEN"] = 12] = "RIGHT_CURLY_BRACKET_TOKEN";
- TokenType[TokenType["SUFFIX_MATCH_TOKEN"] = 13] = "SUFFIX_MATCH_TOKEN";
- TokenType[TokenType["SUBSTRING_MATCH_TOKEN"] = 14] = "SUBSTRING_MATCH_TOKEN";
- TokenType[TokenType["DIMENSION_TOKEN"] = 15] = "DIMENSION_TOKEN";
- TokenType[TokenType["PERCENTAGE_TOKEN"] = 16] = "PERCENTAGE_TOKEN";
- TokenType[TokenType["NUMBER_TOKEN"] = 17] = "NUMBER_TOKEN";
- TokenType[TokenType["FUNCTION"] = 18] = "FUNCTION";
- TokenType[TokenType["FUNCTION_TOKEN"] = 19] = "FUNCTION_TOKEN";
- TokenType[TokenType["IDENT_TOKEN"] = 20] = "IDENT_TOKEN";
- TokenType[TokenType["COLUMN_TOKEN"] = 21] = "COLUMN_TOKEN";
- TokenType[TokenType["URL_TOKEN"] = 22] = "URL_TOKEN";
- TokenType[TokenType["BAD_URL_TOKEN"] = 23] = "BAD_URL_TOKEN";
- TokenType[TokenType["CDC_TOKEN"] = 24] = "CDC_TOKEN";
- TokenType[TokenType["CDO_TOKEN"] = 25] = "CDO_TOKEN";
- TokenType[TokenType["COLON_TOKEN"] = 26] = "COLON_TOKEN";
- TokenType[TokenType["SEMICOLON_TOKEN"] = 27] = "SEMICOLON_TOKEN";
- TokenType[TokenType["LEFT_SQUARE_BRACKET_TOKEN"] = 28] = "LEFT_SQUARE_BRACKET_TOKEN";
- TokenType[TokenType["RIGHT_SQUARE_BRACKET_TOKEN"] = 29] = "RIGHT_SQUARE_BRACKET_TOKEN";
- TokenType[TokenType["UNICODE_RANGE_TOKEN"] = 30] = "UNICODE_RANGE_TOKEN";
- TokenType[TokenType["WHITESPACE_TOKEN"] = 31] = "WHITESPACE_TOKEN";
- TokenType[TokenType["EOF_TOKEN"] = 32] = "EOF_TOKEN";
- })(TokenType || (TokenType = {}));
- var FLAG_UNRESTRICTED = 1 << 0;
- var FLAG_ID = 1 << 1;
- var FLAG_INTEGER = 1 << 2;
- var FLAG_NUMBER = 1 << 3;
- var LINE_FEED = 0x000a;
- var SOLIDUS = 0x002f;
- var REVERSE_SOLIDUS = 0x005c;
- var CHARACTER_TABULATION = 0x0009;
- var SPACE$1 = 0x0020;
- var QUOTATION_MARK = 0x0022;
- var EQUALS_SIGN = 0x003d;
- var NUMBER_SIGN = 0x0023;
- var DOLLAR_SIGN = 0x0024;
- var PERCENTAGE_SIGN = 0x0025;
- var APOSTROPHE = 0x0027;
- var LEFT_PARENTHESIS = 0x0028;
- var RIGHT_PARENTHESIS = 0x0029;
- var LOW_LINE = 0x005f;
- var HYPHEN_MINUS = 0x002d;
- var EXCLAMATION_MARK = 0x0021;
- var LESS_THAN_SIGN = 0x003c;
- var GREATER_THAN_SIGN = 0x003e;
- var COMMERCIAL_AT = 0x0040;
- var LEFT_SQUARE_BRACKET = 0x005b;
- var RIGHT_SQUARE_BRACKET = 0x005d;
- var CIRCUMFLEX_ACCENT = 0x003d;
- var LEFT_CURLY_BRACKET = 0x007b;
- var QUESTION_MARK = 0x003f;
- var RIGHT_CURLY_BRACKET = 0x007d;
- var VERTICAL_LINE = 0x007c;
- var TILDE = 0x007e;
- var CONTROL = 0x0080;
- var REPLACEMENT_CHARACTER = 0xfffd;
- var ASTERISK = 0x002a;
- var PLUS_SIGN = 0x002b;
- var COMMA = 0x002c;
- var COLON = 0x003a;
- var SEMICOLON = 0x003b;
- var FULL_STOP = 0x002e;
- var NULL = 0x0000;
- var BACKSPACE = 0x0008;
- var LINE_TABULATION = 0x000b;
- var SHIFT_OUT = 0x000e;
- var INFORMATION_SEPARATOR_ONE = 0x001f;
- var DELETE = 0x007f;
- var EOF = -1;
- var ZERO = 0x0030;
- var a = 0x0061;
- var e = 0x0065;
- var f = 0x0066;
- var u = 0x0075;
- var z = 0x007a;
- var A = 0x0041;
- var E = 0x0045;
- var F = 0x0046;
- var U = 0x0055;
- var Z = 0x005a;
- var isDigit = function (codePoint) { return codePoint >= ZERO && codePoint <= 0x0039; };
- var isSurrogateCodePoint = function (codePoint) { return codePoint >= 0xd800 && codePoint <= 0xdfff; };
- var isHex = function (codePoint) {
- return isDigit(codePoint) || (codePoint >= A && codePoint <= F) || (codePoint >= a && codePoint <= f);
- };
- var isLowerCaseLetter = function (codePoint) { return codePoint >= a && codePoint <= z; };
- var isUpperCaseLetter = function (codePoint) { return codePoint >= A && codePoint <= Z; };
- var isLetter = function (codePoint) { return isLowerCaseLetter(codePoint) || isUpperCaseLetter(codePoint); };
- var isNonASCIICodePoint = function (codePoint) { return codePoint >= CONTROL; };
- var isWhiteSpace = function (codePoint) {
- return codePoint === LINE_FEED || codePoint === CHARACTER_TABULATION || codePoint === SPACE$1;
- };
- var isNameStartCodePoint = function (codePoint) {
- return isLetter(codePoint) || isNonASCIICodePoint(codePoint) || codePoint === LOW_LINE;
- };
- var isNameCodePoint = function (codePoint) {
- return isNameStartCodePoint(codePoint) || isDigit(codePoint) || codePoint === HYPHEN_MINUS;
- };
- var isNonPrintableCodePoint = function (codePoint) {
- return ((codePoint >= NULL && codePoint <= BACKSPACE) ||
- codePoint === LINE_TABULATION ||
- (codePoint >= SHIFT_OUT && codePoint <= INFORMATION_SEPARATOR_ONE) ||
- codePoint === DELETE);
- };
- var isValidEscape = function (c1, c2) {
- if (c1 !== REVERSE_SOLIDUS) {
- return false;
- }
- return c2 !== LINE_FEED;
- };
- var isIdentifierStart = function (c1, c2, c3) {
- if (c1 === HYPHEN_MINUS) {
- return isNameStartCodePoint(c2) || isValidEscape(c2, c3);
- }
- else if (isNameStartCodePoint(c1)) {
- return true;
- }
- else if (c1 === REVERSE_SOLIDUS && isValidEscape(c1, c2)) {
- return true;
- }
- return false;
- };
- var isNumberStart = function (c1, c2, c3) {
- if (c1 === PLUS_SIGN || c1 === HYPHEN_MINUS) {
- if (isDigit(c2)) {
- return true;
- }
- return c2 === FULL_STOP && isDigit(c3);
- }
- if (c1 === FULL_STOP) {
- return isDigit(c2);
- }
- return isDigit(c1);
- };
- var stringToNumber = function (codePoints) {
- var c = 0;
- var sign = 1;
- if (codePoints[c] === PLUS_SIGN || codePoints[c] === HYPHEN_MINUS) {
- if (codePoints[c] === HYPHEN_MINUS) {
- sign = -1;
- }
- c++;
- }
- var integers = [];
- while (isDigit(codePoints[c])) {
- integers.push(codePoints[c++]);
- }
- var int = integers.length ? parseInt(fromCodePoint.apply(void 0, integers), 10) : 0;
- if (codePoints[c] === FULL_STOP) {
- c++;
- }
- var fraction = [];
- while (isDigit(codePoints[c])) {
- fraction.push(codePoints[c++]);
- }
- var fracd = fraction.length;
- var frac = fracd ? parseInt(fromCodePoint.apply(void 0, fraction), 10) : 0;
- if (codePoints[c] === E || codePoints[c] === e) {
- c++;
- }
- var expsign = 1;
- if (codePoints[c] === PLUS_SIGN || codePoints[c] === HYPHEN_MINUS) {
- if (codePoints[c] === HYPHEN_MINUS) {
- expsign = -1;
- }
- c++;
- }
- var exponent = [];
- while (isDigit(codePoints[c])) {
- exponent.push(codePoints[c++]);
- }
- var exp = exponent.length ? parseInt(fromCodePoint.apply(void 0, exponent), 10) : 0;
- return sign * (int + frac * Math.pow(10, -fracd)) * Math.pow(10, expsign * exp);
- };
- var LEFT_PARENTHESIS_TOKEN = {
- type: TokenType.LEFT_PARENTHESIS_TOKEN
- };
- var RIGHT_PARENTHESIS_TOKEN = {
- type: TokenType.RIGHT_PARENTHESIS_TOKEN
- };
- var COMMA_TOKEN = { type: TokenType.COMMA_TOKEN };
- var SUFFIX_MATCH_TOKEN = { type: TokenType.SUFFIX_MATCH_TOKEN };
- var PREFIX_MATCH_TOKEN = { type: TokenType.PREFIX_MATCH_TOKEN };
- var COLUMN_TOKEN = { type: TokenType.COLUMN_TOKEN };
- var DASH_MATCH_TOKEN = { type: TokenType.DASH_MATCH_TOKEN };
- var INCLUDE_MATCH_TOKEN = { type: TokenType.INCLUDE_MATCH_TOKEN };
- var LEFT_CURLY_BRACKET_TOKEN = {
- type: TokenType.LEFT_CURLY_BRACKET_TOKEN
- };
- var RIGHT_CURLY_BRACKET_TOKEN = {
- type: TokenType.RIGHT_CURLY_BRACKET_TOKEN
- };
- var SUBSTRING_MATCH_TOKEN = { type: TokenType.SUBSTRING_MATCH_TOKEN };
- var BAD_URL_TOKEN = { type: TokenType.BAD_URL_TOKEN };
- var BAD_STRING_TOKEN = { type: TokenType.BAD_STRING_TOKEN };
- var CDO_TOKEN = { type: TokenType.CDO_TOKEN };
- var CDC_TOKEN = { type: TokenType.CDC_TOKEN };
- var COLON_TOKEN = { type: TokenType.COLON_TOKEN };
- var SEMICOLON_TOKEN = { type: TokenType.SEMICOLON_TOKEN };
- var LEFT_SQUARE_BRACKET_TOKEN = {
- type: TokenType.LEFT_SQUARE_BRACKET_TOKEN
- };
- var RIGHT_SQUARE_BRACKET_TOKEN = {
- type: TokenType.RIGHT_SQUARE_BRACKET_TOKEN
- };
- var WHITESPACE_TOKEN = { type: TokenType.WHITESPACE_TOKEN };
- var EOF_TOKEN = { type: TokenType.EOF_TOKEN };
- var Tokenizer = /** @class */ (function () {
- function Tokenizer() {
- this._value = [];
- }
- Tokenizer.prototype.write = function (chunk) {
- this._value = this._value.concat(toCodePoints(chunk));
- };
- Tokenizer.prototype.read = function () {
- var tokens = [];
- var token = this.consumeToken();
- while (token !== EOF_TOKEN) {
- tokens.push(token);
- token = this.consumeToken();
- }
- return tokens;
- };
- Tokenizer.prototype.consumeToken = function () {
- var codePoint = this.consumeCodePoint();
- switch (codePoint) {
- case QUOTATION_MARK:
- return this.consumeStringToken(QUOTATION_MARK);
- case NUMBER_SIGN:
- var c1 = this.peekCodePoint(0);
- var c2 = this.peekCodePoint(1);
- var c3 = this.peekCodePoint(2);
- if (isNameCodePoint(c1) || isValidEscape(c2, c3)) {
- var flags = isIdentifierStart(c1, c2, c3) ? FLAG_ID : FLAG_UNRESTRICTED;
- var value = this.consumeName();
- return { type: TokenType.HASH_TOKEN, value: value, flags: flags };
- }
- break;
- case DOLLAR_SIGN:
- if (this.peekCodePoint(0) === EQUALS_SIGN) {
- this.consumeCodePoint();
- return SUFFIX_MATCH_TOKEN;
- }
- break;
- case APOSTROPHE:
- return this.consumeStringToken(APOSTROPHE);
- case LEFT_PARENTHESIS:
- return LEFT_PARENTHESIS_TOKEN;
- case RIGHT_PARENTHESIS:
- return RIGHT_PARENTHESIS_TOKEN;
- case ASTERISK:
- if (this.peekCodePoint(0) === EQUALS_SIGN) {
- this.consumeCodePoint();
- return SUBSTRING_MATCH_TOKEN;
- }
- break;
- case PLUS_SIGN:
- if (isNumberStart(codePoint, this.peekCodePoint(0), this.peekCodePoint(1))) {
- this.reconsumeCodePoint(codePoint);
- return this.consumeNumericToken();
- }
- break;
- case COMMA:
- return COMMA_TOKEN;
- case HYPHEN_MINUS:
- var e1 = codePoint;
- var e2 = this.peekCodePoint(0);
- var e3 = this.peekCodePoint(1);
- if (isNumberStart(e1, e2, e3)) {
- this.reconsumeCodePoint(codePoint);
- return this.consumeNumericToken();
- }
- if (isIdentifierStart(e1, e2, e3)) {
- this.reconsumeCodePoint(codePoint);
- return this.consumeIdentLikeToken();
- }
- if (e2 === HYPHEN_MINUS && e3 === GREATER_THAN_SIGN) {
- this.consumeCodePoint();
- this.consumeCodePoint();
- return CDC_TOKEN;
- }
- break;
- case FULL_STOP:
- if (isNumberStart(codePoint, this.peekCodePoint(0), this.peekCodePoint(1))) {
- this.reconsumeCodePoint(codePoint);
- return this.consumeNumericToken();
- }
- break;
- case SOLIDUS:
- if (this.peekCodePoint(0) === ASTERISK) {
- this.consumeCodePoint();
- while (true) {
- var c = this.consumeCodePoint();
- if (c === ASTERISK) {
- c = this.consumeCodePoint();
- if (c === SOLIDUS) {
- return this.consumeToken();
- }
- }
- if (c === EOF) {
- return this.consumeToken();
- }
- }
- }
- break;
- case COLON:
- return COLON_TOKEN;
- case SEMICOLON:
- return SEMICOLON_TOKEN;
- case LESS_THAN_SIGN:
- if (this.peekCodePoint(0) === EXCLAMATION_MARK &&
- this.peekCodePoint(1) === HYPHEN_MINUS &&
- this.peekCodePoint(2) === HYPHEN_MINUS) {
- this.consumeCodePoint();
- this.consumeCodePoint();
- return CDO_TOKEN;
- }
- break;
- case COMMERCIAL_AT:
- var a1 = this.peekCodePoint(0);
- var a2 = this.peekCodePoint(1);
- var a3 = this.peekCodePoint(2);
- if (isIdentifierStart(a1, a2, a3)) {
- var value = this.consumeName();
- return { type: TokenType.AT_KEYWORD_TOKEN, value: value };
- }
- break;
- case LEFT_SQUARE_BRACKET:
- return LEFT_SQUARE_BRACKET_TOKEN;
- case REVERSE_SOLIDUS:
- if (isValidEscape(codePoint, this.peekCodePoint(0))) {
- this.reconsumeCodePoint(codePoint);
- return this.consumeIdentLikeToken();
- }
- break;
- case RIGHT_SQUARE_BRACKET:
- return RIGHT_SQUARE_BRACKET_TOKEN;
- case CIRCUMFLEX_ACCENT:
- if (this.peekCodePoint(0) === EQUALS_SIGN) {
- this.consumeCodePoint();
- return PREFIX_MATCH_TOKEN;
- }
- break;
- case LEFT_CURLY_BRACKET:
- return LEFT_CURLY_BRACKET_TOKEN;
- case RIGHT_CURLY_BRACKET:
- return RIGHT_CURLY_BRACKET_TOKEN;
- case u:
- case U:
- var u1 = this.peekCodePoint(0);
- var u2 = this.peekCodePoint(1);
- if (u1 === PLUS_SIGN && (isHex(u2) || u2 === QUESTION_MARK)) {
- this.consumeCodePoint();
- this.consumeUnicodeRangeToken();
- }
- this.reconsumeCodePoint(codePoint);
- return this.consumeIdentLikeToken();
- case VERTICAL_LINE:
- if (this.peekCodePoint(0) === EQUALS_SIGN) {
- this.consumeCodePoint();
- return DASH_MATCH_TOKEN;
- }
- if (this.peekCodePoint(0) === VERTICAL_LINE) {
- this.consumeCodePoint();
- return COLUMN_TOKEN;
- }
- break;
- case TILDE:
- if (this.peekCodePoint(0) === EQUALS_SIGN) {
- this.consumeCodePoint();
- return INCLUDE_MATCH_TOKEN;
- }
- break;
- case EOF:
- return EOF_TOKEN;
- }
- if (isWhiteSpace(codePoint)) {
- this.consumeWhiteSpace();
- return WHITESPACE_TOKEN;
- }
- if (isDigit(codePoint)) {
- this.reconsumeCodePoint(codePoint);
- return this.consumeNumericToken();
- }
- if (isNameStartCodePoint(codePoint)) {
- this.reconsumeCodePoint(codePoint);
- return this.consumeIdentLikeToken();
- }
- return { type: TokenType.DELIM_TOKEN, value: fromCodePoint(codePoint) };
- };
- Tokenizer.prototype.consumeCodePoint = function () {
- var value = this._value.shift();
- return typeof value === 'undefined' ? -1 : value;
- };
- Tokenizer.prototype.reconsumeCodePoint = function (codePoint) {
- this._value.unshift(codePoint);
- };
- Tokenizer.prototype.peekCodePoint = function (delta) {
- if (delta >= this._value.length) {
- return -1;
- }
- return this._value[delta];
- };
- Tokenizer.prototype.consumeUnicodeRangeToken = function () {
- var digits = [];
- var codePoint = this.consumeCodePoint();
- while (isHex(codePoint) && digits.length < 6) {
- digits.push(codePoint);
- codePoint = this.consumeCodePoint();
- }
- var questionMarks = false;
- while (codePoint === QUESTION_MARK && digits.length < 6) {
- digits.push(codePoint);
- codePoint = this.consumeCodePoint();
- questionMarks = true;
- }
- if (questionMarks) {
- var start_1 = parseInt(fromCodePoint.apply(void 0, digits.map(function (digit) { return (digit === QUESTION_MARK ? ZERO : digit); })), 16);
- var end = parseInt(fromCodePoint.apply(void 0, digits.map(function (digit) { return (digit === QUESTION_MARK ? F : digit); })), 16);
- return { type: TokenType.UNICODE_RANGE_TOKEN, start: start_1, end: end };
- }
- var start = parseInt(fromCodePoint.apply(void 0, digits), 16);
- if (this.peekCodePoint(0) === HYPHEN_MINUS && isHex(this.peekCodePoint(1))) {
- this.consumeCodePoint();
- codePoint = this.consumeCodePoint();
- var endDigits = [];
- while (isHex(codePoint) && endDigits.length < 6) {
- endDigits.push(codePoint);
- codePoint = this.consumeCodePoint();
- }
- var end = parseInt(fromCodePoint.apply(void 0, endDigits), 16);
- return { type: TokenType.UNICODE_RANGE_TOKEN, start: start, end: end };
- }
- else {
- return { type: TokenType.UNICODE_RANGE_TOKEN, start: start, end: start };
- }
- };
- Tokenizer.prototype.consumeIdentLikeToken = function () {
- var value = this.consumeName();
- if (value.toLowerCase() === 'url' && this.peekCodePoint(0) === LEFT_PARENTHESIS) {
- this.consumeCodePoint();
- return this.consumeUrlToken();
- }
- else if (this.peekCodePoint(0) === LEFT_PARENTHESIS) {
- this.consumeCodePoint();
- return { type: TokenType.FUNCTION_TOKEN, value: value };
- }
- return { type: TokenType.IDENT_TOKEN, value: value };
- };
- Tokenizer.prototype.consumeUrlToken = function () {
- var value = [];
- this.consumeWhiteSpace();
- if (this.peekCodePoint(0) === EOF) {
- return { type: TokenType.URL_TOKEN, value: '' };
- }
- var next = this.peekCodePoint(0);
- if (next === APOSTROPHE || next === QUOTATION_MARK) {
- var stringToken = this.consumeStringToken(this.consumeCodePoint());
- if (stringToken.type === TokenType.STRING_TOKEN) {
- this.consumeWhiteSpace();
- if (this.peekCodePoint(0) === EOF || this.peekCodePoint(0) === RIGHT_PARENTHESIS) {
- this.consumeCodePoint();
- return { type: TokenType.URL_TOKEN, value: stringToken.value };
- }
- }
- this.consumeBadUrlRemnants();
- return BAD_URL_TOKEN;
- }
- while (true) {
- var codePoint = this.consumeCodePoint();
- if (codePoint === EOF || codePoint === RIGHT_PARENTHESIS) {
- return { type: TokenType.URL_TOKEN, value: fromCodePoint.apply(void 0, value) };
- }
- else if (isWhiteSpace(codePoint)) {
- this.consumeWhiteSpace();
- if (this.peekCodePoint(0) === EOF || this.peekCodePoint(0) === RIGHT_PARENTHESIS) {
- this.consumeCodePoint();
- return { type: TokenType.URL_TOKEN, value: fromCodePoint.apply(void 0, value) };
- }
- this.consumeBadUrlRemnants();
- return BAD_URL_TOKEN;
- }
- else if (codePoint === QUOTATION_MARK ||
- codePoint === APOSTROPHE ||
- codePoint === LEFT_PARENTHESIS ||
- isNonPrintableCodePoint(codePoint)) {
- this.consumeBadUrlRemnants();
- return BAD_URL_TOKEN;
- }
- else if (codePoint === REVERSE_SOLIDUS) {
- if (isValidEscape(codePoint, this.peekCodePoint(0))) {
- value.push(this.consumeEscapedCodePoint());
- }
- else {
- this.consumeBadUrlRemnants();
- return BAD_URL_TOKEN;
- }
- }
- else {
- value.push(codePoint);
- }
- }
- };
- Tokenizer.prototype.consumeWhiteSpace = function () {
- while (isWhiteSpace(this.peekCodePoint(0))) {
- this.consumeCodePoint();
- }
- };
- Tokenizer.prototype.consumeBadUrlRemnants = function () {
- while (true) {
- var codePoint = this.consumeCodePoint();
- if (codePoint === RIGHT_PARENTHESIS || codePoint === EOF) {
- return;
- }
- if (isValidEscape(codePoint, this.peekCodePoint(0))) {
- this.consumeEscapedCodePoint();
- }
- }
- };
- Tokenizer.prototype.consumeStringSlice = function (count) {
- var SLICE_STACK_SIZE = 60000;
- var value = '';
- while (count > 0) {
- var amount = Math.min(SLICE_STACK_SIZE, count);
- value += fromCodePoint.apply(void 0, this._value.splice(0, amount));
- count -= amount;
- }
- this._value.shift();
- return value;
- };
- Tokenizer.prototype.consumeStringToken = function (endingCodePoint) {
- var value = '';
- var i = 0;
- do {
- var codePoint = this._value[i];
- if (codePoint === EOF || codePoint === undefined || codePoint === endingCodePoint) {
- value += this.consumeStringSlice(i);
- return { type: TokenType.STRING_TOKEN, value: value };
- }
- if (codePoint === LINE_FEED) {
- this._value.splice(0, i);
- return BAD_STRING_TOKEN;
- }
- if (codePoint === REVERSE_SOLIDUS) {
- var next = this._value[i + 1];
- if (next !== EOF && next !== undefined) {
- if (next === LINE_FEED) {
- value += this.consumeStringSlice(i);
- i = -1;
- this._value.shift();
- }
- else if (isValidEscape(codePoint, next)) {
- value += this.consumeStringSlice(i);
- value += fromCodePoint(this.consumeEscapedCodePoint());
- i = -1;
- }
- }
- }
- i++;
- } while (true);
- };
- Tokenizer.prototype.consumeNumber = function () {
- var repr = [];
- var type = FLAG_INTEGER;
- var c1 = this.peekCodePoint(0);
- if (c1 === PLUS_SIGN || c1 === HYPHEN_MINUS) {
- repr.push(this.consumeCodePoint());
- }
- while (isDigit(this.peekCodePoint(0))) {
- repr.push(this.consumeCodePoint());
- }
- c1 = this.peekCodePoint(0);
- var c2 = this.peekCodePoint(1);
- if (c1 === FULL_STOP && isDigit(c2)) {
- repr.push(this.consumeCodePoint(), this.consumeCodePoint());
- type = FLAG_NUMBER;
- while (isDigit(this.peekCodePoint(0))) {
- repr.push(this.consumeCodePoint());
- }
- }
- c1 = this.peekCodePoint(0);
- c2 = this.peekCodePoint(1);
- var c3 = this.peekCodePoint(2);
- if ((c1 === E || c1 === e) && (((c2 === PLUS_SIGN || c2 === HYPHEN_MINUS) && isDigit(c3)) || isDigit(c2))) {
- repr.push(this.consumeCodePoint(), this.consumeCodePoint());
- type = FLAG_NUMBER;
- while (isDigit(this.peekCodePoint(0))) {
- repr.push(this.consumeCodePoint());
- }
- }
- return [stringToNumber(repr), type];
- };
- Tokenizer.prototype.consumeNumericToken = function () {
- var _a = this.consumeNumber(), number = _a[0], flags = _a[1];
- var c1 = this.peekCodePoint(0);
- var c2 = this.peekCodePoint(1);
- var c3 = this.peekCodePoint(2);
- if (isIdentifierStart(c1, c2, c3)) {
- var unit = this.consumeName();
- return { type: TokenType.DIMENSION_TOKEN, number: number, flags: flags, unit: unit };
- }
- if (c1 === PERCENTAGE_SIGN) {
- this.consumeCodePoint();
- return { type: TokenType.PERCENTAGE_TOKEN, number: number, flags: flags };
- }
- return { type: TokenType.NUMBER_TOKEN, number: number, flags: flags };
- };
- Tokenizer.prototype.consumeEscapedCodePoint = function () {
- var codePoint = this.consumeCodePoint();
- if (isHex(codePoint)) {
- var hex = fromCodePoint(codePoint);
- while (isHex(this.peekCodePoint(0)) && hex.length < 6) {
- hex += fromCodePoint(this.consumeCodePoint());
- }
- if (isWhiteSpace(this.peekCodePoint(0))) {
- this.consumeCodePoint();
- }
- var hexCodePoint = parseInt(hex, 16);
- if (hexCodePoint === 0 || isSurrogateCodePoint(hexCodePoint) || hexCodePoint > 0x10ffff) {
- return REPLACEMENT_CHARACTER;
- }
- return hexCodePoint;
- }
- if (codePoint === EOF) {
- return REPLACEMENT_CHARACTER;
- }
- return codePoint;
- };
- Tokenizer.prototype.consumeName = function () {
- var result = '';
- while (true) {
- var codePoint = this.consumeCodePoint();
- if (isNameCodePoint(codePoint)) {
- result += fromCodePoint(codePoint);
- }
- else if (isValidEscape(codePoint, this.peekCodePoint(0))) {
- result += fromCodePoint(this.consumeEscapedCodePoint());
- }
- else {
- this.reconsumeCodePoint(codePoint);
- return result;
- }
- }
- };
- return Tokenizer;
- }());
- var Parser = /** @class */ (function () {
- function Parser(tokens) {
- this._tokens = tokens;
- }
- Parser.create = function (value) {
- var tokenizer = new Tokenizer();
- tokenizer.write(value);
- return new Parser(tokenizer.read());
- };
- Parser.parseValue = function (value) {
- return Parser.create(value).parseComponentValue();
- };
- Parser.parseValues = function (value) {
- return Parser.create(value).parseComponentValues();
- };
- Parser.prototype.parseComponentValue = function () {
- var token = this.consumeToken();
- while (token.type === TokenType.WHITESPACE_TOKEN) {
- token = this.consumeToken();
- }
- if (token.type === TokenType.EOF_TOKEN) {
- throw new SyntaxError("Error parsing CSS component value, unexpected EOF");
- }
- this.reconsumeToken(token);
- var value = this.consumeComponentValue();
- do {
- token = this.consumeToken();
- } while (token.type === TokenType.WHITESPACE_TOKEN);
- if (token.type === TokenType.EOF_TOKEN) {
- return value;
- }
- throw new SyntaxError("Error parsing CSS component value, multiple values found when expecting only one");
- };
- Parser.prototype.parseComponentValues = function () {
- var values = [];
- while (true) {
- var value = this.consumeComponentValue();
- if (value.type === TokenType.EOF_TOKEN) {
- return values;
- }
- values.push(value);
- values.push();
- }
- };
- Parser.prototype.consumeComponentValue = function () {
- var token = this.consumeToken();
- switch (token.type) {
- case TokenType.LEFT_CURLY_BRACKET_TOKEN:
- case TokenType.LEFT_SQUARE_BRACKET_TOKEN:
- case TokenType.LEFT_PARENTHESIS_TOKEN:
- return this.consumeSimpleBlock(token.type);
- case TokenType.FUNCTION_TOKEN:
- return this.consumeFunction(token);
- }
- return token;
- };
- Parser.prototype.consumeSimpleBlock = function (type) {
- var block = { type: type, values: [] };
- var token = this.consumeToken();
- while (true) {
- if (token.type === TokenType.EOF_TOKEN || isEndingTokenFor(token, type)) {
- return block;
- }
- this.reconsumeToken(token);
- block.values.push(this.consumeComponentValue());
- token = this.consumeToken();
- }
- };
- Parser.prototype.consumeFunction = function (functionToken) {
- var cssFunction = {
- name: functionToken.value,
- values: [],
- type: TokenType.FUNCTION
- };
- while (true) {
- var token = this.consumeToken();
- if (token.type === TokenType.EOF_TOKEN || token.type === TokenType.RIGHT_PARENTHESIS_TOKEN) {
- return cssFunction;
- }
- this.reconsumeToken(token);
- cssFunction.values.push(this.consumeComponentValue());
- }
- };
- Parser.prototype.consumeToken = function () {
- var token = this._tokens.shift();
- return typeof token === 'undefined' ? EOF_TOKEN : token;
- };
- Parser.prototype.reconsumeToken = function (token) {
- this._tokens.unshift(token);
- };
- return Parser;
- }());
- var isDimensionToken = function (token) { return token.type === TokenType.DIMENSION_TOKEN; };
- var isNumberToken = function (token) { return token.type === TokenType.NUMBER_TOKEN; };
- var isIdentToken = function (token) { return token.type === TokenType.IDENT_TOKEN; };
- var isStringToken = function (token) { return token.type === TokenType.STRING_TOKEN; };
- var isIdentWithValue = function (token, value) {
- return isIdentToken(token) && token.value === value;
- };
- var nonWhiteSpace = function (token) { return token.type !== TokenType.WHITESPACE_TOKEN; };
- var nonFunctionArgSeparator = function (token) {
- return token.type !== TokenType.WHITESPACE_TOKEN && token.type !== TokenType.COMMA_TOKEN;
- };
- var parseFunctionArgs = function (tokens) {
- var args = [];
- var arg = [];
- tokens.forEach(function (token) {
- if (token.type === TokenType.COMMA_TOKEN) {
- if (arg.length === 0) {
- throw new Error("Error parsing function args, zero tokens for arg");
- }
- args.push(arg);
- arg = [];
- return;
- }
- if (token.type !== TokenType.WHITESPACE_TOKEN) {
- arg.push(token);
- }
- });
- if (arg.length) {
- args.push(arg);
- }
- return args;
- };
- var isEndingTokenFor = function (token, type) {
- if (type === TokenType.LEFT_CURLY_BRACKET_TOKEN && token.type === TokenType.RIGHT_CURLY_BRACKET_TOKEN) {
- return true;
- }
- if (type === TokenType.LEFT_SQUARE_BRACKET_TOKEN && token.type === TokenType.RIGHT_SQUARE_BRACKET_TOKEN) {
- return true;
- }
- return type === TokenType.LEFT_PARENTHESIS_TOKEN && token.type === TokenType.RIGHT_PARENTHESIS_TOKEN;
- };
- var isLength = function (token) {
- return token.type === TokenType.NUMBER_TOKEN || token.type === TokenType.DIMENSION_TOKEN;
- };
- var isLengthPercentage = function (token) {
- return token.type === TokenType.PERCENTAGE_TOKEN || isLength(token);
- };
- var parseLengthPercentageTuple = function (tokens) {
- return tokens.length > 1 ? [tokens[0], tokens[1]] : [tokens[0]];
- };
- var ZERO_LENGTH = {
- type: TokenType.NUMBER_TOKEN,
- number: 0,
- flags: FLAG_INTEGER
- };
- var FIFTY_PERCENT = {
- type: TokenType.PERCENTAGE_TOKEN,
- number: 50,
- flags: FLAG_INTEGER
- };
- var HUNDRED_PERCENT = {
- type: TokenType.PERCENTAGE_TOKEN,
- number: 100,
- flags: FLAG_INTEGER
- };
- var getAbsoluteValueForTuple = function (tuple, width, height) {
- var x = tuple[0], y = tuple[1];
- return [getAbsoluteValue(x, width), getAbsoluteValue(typeof y !== 'undefined' ? y : x, height)];
- };
- var getAbsoluteValue = function (token, parent) {
- if (token.type === TokenType.PERCENTAGE_TOKEN) {
- return (token.number / 100) * parent;
- }
- if (isDimensionToken(token)) {
- switch (token.unit) {
- case 'rem':
- case 'em':
- return 16 * token.number; // TODO use correct font-size
- case 'px':
- default:
- return token.number;
- }
- }
- return token.number;
- };
- var DEG = 'deg';
- var GRAD = 'grad';
- var RAD = 'rad';
- var TURN = 'turn';
- var angle = {
- name: 'angle',
- parse: function (value) {
- if (value.type === TokenType.DIMENSION_TOKEN) {
- switch (value.unit) {
- case DEG:
- return (Math.PI * value.number) / 180;
- case GRAD:
- return (Math.PI / 200) * value.number;
- case RAD:
- return value.number;
- case TURN:
- return Math.PI * 2 * value.number;
- }
- }
- throw new Error("Unsupported angle type");
- }
- };
- var isAngle = function (value) {
- if (value.type === TokenType.DIMENSION_TOKEN) {
- if (value.unit === DEG || value.unit === GRAD || value.unit === RAD || value.unit === TURN) {
- return true;
- }
- }
- return false;
- };
- var parseNamedSide = function (tokens) {
- var sideOrCorner = tokens
- .filter(isIdentToken)
- .map(function (ident) { return ident.value; })
- .join(' ');
- switch (sideOrCorner) {
- case 'to bottom right':
- case 'to right bottom':
- case 'left top':
- case 'top left':
- return [ZERO_LENGTH, ZERO_LENGTH];
- case 'to top':
- case 'bottom':
- return deg(0);
- case 'to bottom left':
- case 'to left bottom':
- case 'right top':
- case 'top right':
- return [ZERO_LENGTH, HUNDRED_PERCENT];
- case 'to right':
- case 'left':
- return deg(90);
- case 'to top left':
- case 'to left top':
- case 'right bottom':
- case 'bottom right':
- return [HUNDRED_PERCENT, HUNDRED_PERCENT];
- case 'to bottom':
- case 'top':
- return deg(180);
- case 'to top right':
- case 'to right top':
- case 'left bottom':
- case 'bottom left':
- return [HUNDRED_PERCENT, ZERO_LENGTH];
- case 'to left':
- case 'right':
- return deg(270);
- }
- return 0;
- };
- var deg = function (deg) { return (Math.PI * deg) / 180; };
- var color = {
- name: 'color',
- parse: function (value) {
- if (value.type === TokenType.FUNCTION) {
- var colorFunction = SUPPORTED_COLOR_FUNCTIONS[value.name];
- if (typeof colorFunction === 'undefined') {
- throw new Error("Attempting to parse an unsupported color function \"" + value.name + "\"");
- }
- return colorFunction(value.values);
- }
- if (value.type === TokenType.HASH_TOKEN) {
- if (value.value.length === 3) {
- var r = value.value.substring(0, 1);
- var g = value.value.substring(1, 2);
- var b = value.value.substring(2, 3);
- return pack(parseInt(r + r, 16), parseInt(g + g, 16), parseInt(b + b, 16), 1);
- }
- if (value.value.length === 4) {
- var r = value.value.substring(0, 1);
- var g = value.value.substring(1, 2);
- var b = value.value.substring(2, 3);
- var a = value.value.substring(3, 4);
- return pack(parseInt(r + r, 16), parseInt(g + g, 16), parseInt(b + b, 16), parseInt(a + a, 16) / 255);
- }
- if (value.value.length === 6) {
- var r = value.value.substring(0, 2);
- var g = value.value.substring(2, 4);
- var b = value.value.substring(4, 6);
- return pack(parseInt(r, 16), parseInt(g, 16), parseInt(b, 16), 1);
- }
- if (value.value.length === 8) {
- var r = value.value.substring(0, 2);
- var g = value.value.substring(2, 4);
- var b = value.value.substring(4, 6);
- var a = value.value.substring(6, 8);
- return pack(parseInt(r, 16), parseInt(g, 16), parseInt(b, 16), parseInt(a, 16) / 255);
- }
- }
- if (value.type === TokenType.IDENT_TOKEN) {
- var namedColor = COLORS[value.value.toUpperCase()];
- if (typeof namedColor !== 'undefined') {
- return namedColor;
- }
- }
- return COLORS.TRANSPARENT;
- }
- };
- var isTransparent = function (color) { return (0xff & color) === 0; };
- var asString = function (color) {
- var alpha = 0xff & color;
- var blue = 0xff & (color >> 8);
- var green = 0xff & (color >> 16);
- var red = 0xff & (color >> 24);
- return alpha < 255 ? "rgba(" + red + "," + green + "," + blue + "," + alpha / 255 + ")" : "rgb(" + red + "," + green + "," + blue + ")";
- };
- var pack = function (r, g, b, a) {
- return ((r << 24) | (g << 16) | (b << 8) | (Math.round(a * 255) << 0)) >>> 0;
- };
- var getTokenColorValue = function (token, i) {
- if (token.type === TokenType.NUMBER_TOKEN) {
- return token.number;
- }
- if (token.type === TokenType.PERCENTAGE_TOKEN) {
- var max = i === 3 ? 1 : 255;
- return i === 3 ? (token.number / 100) * max : Math.round((token.number / 100) * max);
- }
- return 0;
- };
- var rgb = function (args) {
- var tokens = args.filter(nonFunctionArgSeparator);
- if (tokens.length === 3) {
- var _a = tokens.map(getTokenColorValue), r = _a[0], g = _a[1], b = _a[2];
- return pack(r, g, b, 1);
- }
- if (tokens.length === 4) {
- var _b = tokens.map(getTokenColorValue), r = _b[0], g = _b[1], b = _b[2], a = _b[3];
- return pack(r, g, b, a);
- }
- return 0;
- };
- function hue2rgb(t1, t2, hue) {
- if (hue < 0) {
- hue += 1;
- }
- if (hue >= 1) {
- hue -= 1;
- }
- if (hue < 1 / 6) {
- return (t2 - t1) * hue * 6 + t1;
- }
- else if (hue < 1 / 2) {
- return t2;
- }
- else if (hue < 2 / 3) {
- return (t2 - t1) * 6 * (2 / 3 - hue) + t1;
- }
- else {
- return t1;
- }
- }
- var hsl = function (args) {
- var tokens = args.filter(nonFunctionArgSeparator);
- var hue = tokens[0], saturation = tokens[1], lightness = tokens[2], alpha = tokens[3];
- var h = (hue.type === TokenType.NUMBER_TOKEN ? deg(hue.number) : angle.parse(hue)) / (Math.PI * 2);
- var s = isLengthPercentage(saturation) ? saturation.number / 100 : 0;
- var l = isLengthPercentage(lightness) ? lightness.number / 100 : 0;
- var a = typeof alpha !== 'undefined' && isLengthPercentage(alpha) ? getAbsoluteValue(alpha, 1) : 1;
- if (s === 0) {
- return pack(l * 255, l * 255, l * 255, 1);
- }
- var t2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
- var t1 = l * 2 - t2;
- var r = hue2rgb(t1, t2, h + 1 / 3);
- var g = hue2rgb(t1, t2, h);
- var b = hue2rgb(t1, t2, h - 1 / 3);
- return pack(r * 255, g * 255, b * 255, a);
- };
- var SUPPORTED_COLOR_FUNCTIONS = {
- hsl: hsl,
- hsla: hsl,
- rgb: rgb,
- rgba: rgb
- };
- var COLORS = {
- ALICEBLUE: 0xf0f8ffff,
- ANTIQUEWHITE: 0xfaebd7ff,
- AQUA: 0x00ffffff,
- AQUAMARINE: 0x7fffd4ff,
- AZURE: 0xf0ffffff,
- BEIGE: 0xf5f5dcff,
- BISQUE: 0xffe4c4ff,
- BLACK: 0x000000ff,
- BLANCHEDALMOND: 0xffebcdff,
- BLUE: 0x0000ffff,
- BLUEVIOLET: 0x8a2be2ff,
- BROWN: 0xa52a2aff,
- BURLYWOOD: 0xdeb887ff,
- CADETBLUE: 0x5f9ea0ff,
- CHARTREUSE: 0x7fff00ff,
- CHOCOLATE: 0xd2691eff,
- CORAL: 0xff7f50ff,
- CORNFLOWERBLUE: 0x6495edff,
- CORNSILK: 0xfff8dcff,
- CRIMSON: 0xdc143cff,
- CYAN: 0x00ffffff,
- DARKBLUE: 0x00008bff,
- DARKCYAN: 0x008b8bff,
- DARKGOLDENROD: 0xb886bbff,
- DARKGRAY: 0xa9a9a9ff,
- DARKGREEN: 0x006400ff,
- DARKGREY: 0xa9a9a9ff,
- DARKKHAKI: 0xbdb76bff,
- DARKMAGENTA: 0x8b008bff,
- DARKOLIVEGREEN: 0x556b2fff,
- DARKORANGE: 0xff8c00ff,
- DARKORCHID: 0x9932ccff,
- DARKRED: 0x8b0000ff,
- DARKSALMON: 0xe9967aff,
- DARKSEAGREEN: 0x8fbc8fff,
- DARKSLATEBLUE: 0x483d8bff,
- DARKSLATEGRAY: 0x2f4f4fff,
- DARKSLATEGREY: 0x2f4f4fff,
- DARKTURQUOISE: 0x00ced1ff,
- DARKVIOLET: 0x9400d3ff,
- DEEPPINK: 0xff1493ff,
- DEEPSKYBLUE: 0x00bfffff,
- DIMGRAY: 0x696969ff,
- DIMGREY: 0x696969ff,
- DODGERBLUE: 0x1e90ffff,
- FIREBRICK: 0xb22222ff,
- FLORALWHITE: 0xfffaf0ff,
- FORESTGREEN: 0x228b22ff,
- FUCHSIA: 0xff00ffff,
- GAINSBORO: 0xdcdcdcff,
- GHOSTWHITE: 0xf8f8ffff,
- GOLD: 0xffd700ff,
- GOLDENROD: 0xdaa520ff,
- GRAY: 0x808080ff,
- GREEN: 0x008000ff,
- GREENYELLOW: 0xadff2fff,
- GREY: 0x808080ff,
- HONEYDEW: 0xf0fff0ff,
- HOTPINK: 0xff69b4ff,
- INDIANRED: 0xcd5c5cff,
- INDIGO: 0x4b0082ff,
- IVORY: 0xfffff0ff,
- KHAKI: 0xf0e68cff,
- LAVENDER: 0xe6e6faff,
- LAVENDERBLUSH: 0xfff0f5ff,
- LAWNGREEN: 0x7cfc00ff,
- LEMONCHIFFON: 0xfffacdff,
- LIGHTBLUE: 0xadd8e6ff,
- LIGHTCORAL: 0xf08080ff,
- LIGHTCYAN: 0xe0ffffff,
- LIGHTGOLDENRODYELLOW: 0xfafad2ff,
- LIGHTGRAY: 0xd3d3d3ff,
- LIGHTGREEN: 0x90ee90ff,
- LIGHTGREY: 0xd3d3d3ff,
- LIGHTPINK: 0xffb6c1ff,
- LIGHTSALMON: 0xffa07aff,
- LIGHTSEAGREEN: 0x20b2aaff,
- LIGHTSKYBLUE: 0x87cefaff,
- LIGHTSLATEGRAY: 0x778899ff,
- LIGHTSLATEGREY: 0x778899ff,
- LIGHTSTEELBLUE: 0xb0c4deff,
- LIGHTYELLOW: 0xffffe0ff,
- LIME: 0x00ff00ff,
- LIMEGREEN: 0x32cd32ff,
- LINEN: 0xfaf0e6ff,
- MAGENTA: 0xff00ffff,
- MAROON: 0x800000ff,
- MEDIUMAQUAMARINE: 0x66cdaaff,
- MEDIUMBLUE: 0x0000cdff,
- MEDIUMORCHID: 0xba55d3ff,
- MEDIUMPURPLE: 0x9370dbff,
- MEDIUMSEAGREEN: 0x3cb371ff,
- MEDIUMSLATEBLUE: 0x7b68eeff,
- MEDIUMSPRINGGREEN: 0x00fa9aff,
- MEDIUMTURQUOISE: 0x48d1ccff,
- MEDIUMVIOLETRED: 0xc71585ff,
- MIDNIGHTBLUE: 0x191970ff,
- MINTCREAM: 0xf5fffaff,
- MISTYROSE: 0xffe4e1ff,
- MOCCASIN: 0xffe4b5ff,
- NAVAJOWHITE: 0xffdeadff,
- NAVY: 0x000080ff,
- OLDLACE: 0xfdf5e6ff,
- OLIVE: 0x808000ff,
- OLIVEDRAB: 0x6b8e23ff,
- ORANGE: 0xffa500ff,
- ORANGERED: 0xff4500ff,
- ORCHID: 0xda70d6ff,
- PALEGOLDENROD: 0xeee8aaff,
- PALEGREEN: 0x98fb98ff,
- PALETURQUOISE: 0xafeeeeff,
- PALEVIOLETRED: 0xdb7093ff,
- PAPAYAWHIP: 0xffefd5ff,
- PEACHPUFF: 0xffdab9ff,
- PERU: 0xcd853fff,
- PINK: 0xffc0cbff,
- PLUM: 0xdda0ddff,
- POWDERBLUE: 0xb0e0e6ff,
- PURPLE: 0x800080ff,
- REBECCAPURPLE: 0x663399ff,
- RED: 0xff0000ff,
- ROSYBROWN: 0xbc8f8fff,
- ROYALBLUE: 0x4169e1ff,
- SADDLEBROWN: 0x8b4513ff,
- SALMON: 0xfa8072ff,
- SANDYBROWN: 0xf4a460ff,
- SEAGREEN: 0x2e8b57ff,
- SEASHELL: 0xfff5eeff,
- SIENNA: 0xa0522dff,
- SILVER: 0xc0c0c0ff,
- SKYBLUE: 0x87ceebff,
- SLATEBLUE: 0x6a5acdff,
- SLATEGRAY: 0x708090ff,
- SLATEGREY: 0x708090ff,
- SNOW: 0xfffafaff,
- SPRINGGREEN: 0x00ff7fff,
- STEELBLUE: 0x4682b4ff,
- TAN: 0xd2b48cff,
- TEAL: 0x008080ff,
- THISTLE: 0xd8bfd8ff,
- TOMATO: 0xff6347ff,
- TRANSPARENT: 0x00000000,
- TURQUOISE: 0x40e0d0ff,
- VIOLET: 0xee82eeff,
- WHEAT: 0xf5deb3ff,
- WHITE: 0xffffffff,
- WHITESMOKE: 0xf5f5f5ff,
- YELLOW: 0xffff00ff,
- YELLOWGREEN: 0x9acd32ff
- };
- var PropertyDescriptorParsingType;
- (function (PropertyDescriptorParsingType) {
- PropertyDescriptorParsingType[PropertyDescriptorParsingType["VALUE"] = 0] = "VALUE";
- PropertyDescriptorParsingType[PropertyDescriptorParsingType["LIST"] = 1] = "LIST";
- PropertyDescriptorParsingType[PropertyDescriptorParsingType["IDENT_VALUE"] = 2] = "IDENT_VALUE";
- PropertyDescriptorParsingType[PropertyDescriptorParsingType["TYPE_VALUE"] = 3] = "TYPE_VALUE";
- PropertyDescriptorParsingType[PropertyDescriptorParsingType["TOKEN_VALUE"] = 4] = "TOKEN_VALUE";
- })(PropertyDescriptorParsingType || (PropertyDescriptorParsingType = {}));
- var BACKGROUND_CLIP;
- (function (BACKGROUND_CLIP) {
- BACKGROUND_CLIP[BACKGROUND_CLIP["BORDER_BOX"] = 0] = "BORDER_BOX";
- BACKGROUND_CLIP[BACKGROUND_CLIP["PADDING_BOX"] = 1] = "PADDING_BOX";
- BACKGROUND_CLIP[BACKGROUND_CLIP["CONTENT_BOX"] = 2] = "CONTENT_BOX";
- })(BACKGROUND_CLIP || (BACKGROUND_CLIP = {}));
- var backgroundClip = {
- name: 'background-clip',
- initialValue: 'border-box',
- prefix: false,
- type: PropertyDescriptorParsingType.LIST,
- parse: function (tokens) {
- return tokens.map(function (token) {
- if (isIdentToken(token)) {
- switch (token.value) {
- case 'padding-box':
- return BACKGROUND_CLIP.PADDING_BOX;
- case 'content-box':
- return BACKGROUND_CLIP.CONTENT_BOX;
- }
- }
- return BACKGROUND_CLIP.BORDER_BOX;
- });
- }
- };
- var backgroundColor = {
- name: "background-color",
- initialValue: 'transparent',
- prefix: false,
- type: PropertyDescriptorParsingType.TYPE_VALUE,
- format: 'color'
- };
- var parseColorStop = function (args) {
- var color$1 = color.parse(args[0]);
- var stop = args[1];
- return stop && isLengthPercentage(stop) ? { color: color$1, stop: stop } : { color: color$1, stop: null };
- };
- var processColorStops = function (stops, lineLength) {
- var first = stops[0];
- var last = stops[stops.length - 1];
- if (first.stop === null) {
- first.stop = ZERO_LENGTH;
- }
- if (last.stop === null) {
- last.stop = HUNDRED_PERCENT;
- }
- var processStops = [];
- var previous = 0;
- for (var i = 0; i < stops.length; i++) {
- var stop_1 = stops[i].stop;
- if (stop_1 !== null) {
- var absoluteValue = getAbsoluteValue(stop_1, lineLength);
- if (absoluteValue > previous) {
- processStops.push(absoluteValue);
- }
- else {
- processStops.push(previous);
- }
- previous = absoluteValue;
- }
- else {
- processStops.push(null);
- }
- }
- var gapBegin = null;
- for (var i = 0; i < processStops.length; i++) {
- var stop_2 = processStops[i];
- if (stop_2 === null) {
- if (gapBegin === null) {
- gapBegin = i;
- }
- }
- else if (gapBegin !== null) {
- var gapLength = i - gapBegin;
- var beforeGap = processStops[gapBegin - 1];
- var gapValue = (stop_2 - beforeGap) / (gapLength + 1);
- for (var g = 1; g <= gapLength; g++) {
- processStops[gapBegin + g - 1] = gapValue * g;
- }
- gapBegin = null;
- }
- }
- return stops.map(function (_a, i) {
- var color = _a.color;
- return { color: color, stop: Math.max(Math.min(1, processStops[i] / lineLength), 0) };
- });
- };
- var getAngleFromCorner = function (corner, width, height) {
- var centerX = width / 2;
- var centerY = height / 2;
- var x = getAbsoluteValue(corner[0], width) - centerX;
- var y = centerY - getAbsoluteValue(corner[1], height);
- return (Math.atan2(y, x) + Math.PI * 2) % (Math.PI * 2);
- };
- var calculateGradientDirection = function (angle, width, height) {
- var radian = typeof angle === 'number' ? angle : getAngleFromCorner(angle, width, height);
- var lineLength = Math.abs(width * Math.sin(radian)) + Math.abs(height * Math.cos(radian));
- var halfWidth = width / 2;
- var halfHeight = height / 2;
- var halfLineLength = lineLength / 2;
- var yDiff = Math.sin(radian - Math.PI / 2) * halfLineLength;
- var xDiff = Math.cos(radian - Math.PI / 2) * halfLineLength;
- return [lineLength, halfWidth - xDiff, halfWidth + xDiff, halfHeight - yDiff, halfHeight + yDiff];
- };
- var distance = function (a, b) { return Math.sqrt(a * a + b * b); };
- var findCorner = function (width, height, x, y, closest) {
- var corners = [[0, 0], [0, height], [width, 0], [width, height]];
- return corners.reduce(function (stat, corner) {
- var cx = corner[0], cy = corner[1];
- var d = distance(x - cx, y - cy);
- if (closest ? d < stat.optimumDistance : d > stat.optimumDistance) {
- return {
- optimumCorner: corner,
- optimumDistance: d
- };
- }
- return stat;
- }, {
- optimumDistance: closest ? Infinity : -Infinity,
- optimumCorner: null
- }).optimumCorner;
- };
- var calculateRadius = function (gradient, x, y, width, height) {
- var rx = 0;
- var ry = 0;
- switch (gradient.size) {
- case CSSRadialExtent.CLOSEST_SIDE:
- // The ending shape is sized so that that it exactly meets the side of the gradient box closest to the gradient’s center.
- // If the shape is an ellipse, it exactly meets the closest side in each dimension.
- if (gradient.shape === CSSRadialShape.CIRCLE) {
- rx = ry = Math.min(Math.abs(x), Math.abs(x - width), Math.abs(y), Math.abs(y - height));
- }
- else if (gradient.shape === CSSRadialShape.ELLIPSE) {
- rx = Math.min(Math.abs(x), Math.abs(x - width));
- ry = Math.min(Math.abs(y), Math.abs(y - height));
- }
- break;
- case CSSRadialExtent.CLOSEST_CORNER:
- // The ending shape is sized so that that it passes through the corner of the gradient box closest to the gradient’s center.
- // If the shape is an ellipse, the ending shape is given the same aspect-ratio it would have if closest-side were specified.
- if (gradient.shape === CSSRadialShape.CIRCLE) {
- rx = ry = Math.min(distance(x, y), distance(x, y - height), distance(x - width, y), distance(x - width, y - height));
- }
- else if (gradient.shape === CSSRadialShape.ELLIPSE) {
- // Compute the ratio ry/rx (which is to be the same as for "closest-side")
- var c = Math.min(Math.abs(y), Math.abs(y - height)) / Math.min(Math.abs(x), Math.abs(x - width));
- var _a = findCorner(width, height, x, y, true), cx = _a[0], cy = _a[1];
- rx = distance(cx - x, (cy - y) / c);
- ry = c * rx;
- }
- break;
- case CSSRadialExtent.FARTHEST_SIDE:
- // Same as closest-side, except the ending shape is sized based on the farthest side(s)
- if (gradient.shape === CSSRadialShape.CIRCLE) {
- rx = ry = Math.max(Math.abs(x), Math.abs(x - width), Math.abs(y), Math.abs(y - height));
- }
- else if (gradient.shape === CSSRadialShape.ELLIPSE) {
- rx = Math.max(Math.abs(x), Math.abs(x - width));
- ry = Math.max(Math.abs(y), Math.abs(y - height));
- }
- break;
- case CSSRadialExtent.FARTHEST_CORNER:
- // Same as closest-corner, except the ending shape is sized based on the farthest corner.
- // If the shape is an ellipse, the ending shape is given the same aspect ratio it would have if farthest-side were specified.
- if (gradient.shape === CSSRadialShape.CIRCLE) {
- rx = ry = Math.max(distance(x, y), distance(x, y - height), distance(x - width, y), distance(x - width, y - height));
- }
- else if (gradient.shape === CSSRadialShape.ELLIPSE) {
- // Compute the ratio ry/rx (which is to be the same as for "farthest-side")
- var c = Math.max(Math.abs(y), Math.abs(y - height)) / Math.max(Math.abs(x), Math.abs(x - width));
- var _b = findCorner(width, height, x, y, false), cx = _b[0], cy = _b[1];
- rx = distance(cx - x, (cy - y) / c);
- ry = c * rx;
- }
- break;
- }
- if (Array.isArray(gradient.size)) {
- rx = getAbsoluteValue(gradient.size[0], width);
- ry = gradient.size.length === 2 ? getAbsoluteValue(gradient.size[1], height) : rx;
- }
- return [rx, ry];
- };
- var linearGradient = function (tokens) {
- var angle$1 = deg(180);
- var stops = [];
- parseFunctionArgs(tokens).forEach(function (arg, i) {
- if (i === 0) {
- var firstToken = arg[0];
- if (firstToken.type === TokenType.IDENT_TOKEN && firstToken.value === 'to') {
- angle$1 = parseNamedSide(arg);
- return;
- }
- else if (isAngle(firstToken)) {
- angle$1 = angle.parse(firstToken);
- return;
- }
- }
- var colorStop = parseColorStop(arg);
- stops.push(colorStop);
- });
- return { angle: angle$1, stops: stops, type: CSSImageType.LINEAR_GRADIENT };
- };
- var prefixLinearGradient = function (tokens) {
- var angle$1 = deg(180);
- var stops = [];
- parseFunctionArgs(tokens).forEach(function (arg, i) {
- if (i === 0) {
- var firstToken = arg[0];
- if (firstToken.type === TokenType.IDENT_TOKEN &&
- ['top', 'left', 'right', 'bottom'].indexOf(firstToken.value) !== -1) {
- angle$1 = parseNamedSide(arg);
- return;
- }
- else if (isAngle(firstToken)) {
- angle$1 = (angle.parse(firstToken) + deg(270)) % deg(360);
- return;
- }
- }
- var colorStop = parseColorStop(arg);
- stops.push(colorStop);
- });
- return {
- angle: angle$1,
- stops: stops,
- type: CSSImageType.LINEAR_GRADIENT
- };
- };
- var testRangeBounds = function (document) {
- var TEST_HEIGHT = 123;
- if (document.createRange) {
- var range = document.createRange();
- if (range.getBoundingClientRect) {
- var testElement = document.createElement('boundtest');
- testElement.style.height = TEST_HEIGHT + "px";
- testElement.style.display = 'block';
- document.body.appendChild(testElement);
- range.selectNode(testElement);
- var rangeBounds = range.getBoundingClientRect();
- var rangeHeight = Math.round(rangeBounds.height);
- document.body.removeChild(testElement);
- if (rangeHeight === TEST_HEIGHT) {
- return true;
- }
- }
- }
- return false;
- };
- var testCORS = function () { return typeof new Image().crossOrigin !== 'undefined'; };
- var testResponseType = function () { return typeof new XMLHttpRequest().responseType === 'string'; };
- var testSVG = function (document) {
- var img = new Image();
- var canvas = document.createElement('canvas');
- var ctx = canvas.getContext('2d');
- if (!ctx) {
- return false;
- }
- img.src = "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>";
- try {
- ctx.drawImage(img, 0, 0);
- canvas.toDataURL();
- }
- catch (e) {
- return false;
- }
- return true;
- };
- var isGreenPixel = function (data) {
- return data[0] === 0 && data[1] === 255 && data[2] === 0 && data[3] === 255;
- };
- var testForeignObject = function (document) {
- var canvas = document.createElement('canvas');
- var size = 100;
- canvas.width = size;
- canvas.height = size;
- var ctx = canvas.getContext('2d');
- if (!ctx) {
- return Promise.reject(false);
- }
- ctx.fillStyle = 'rgb(0, 255, 0)';
- ctx.fillRect(0, 0, size, size);
- var img = new Image();
- var greenImageSrc = canvas.toDataURL();
- img.src = greenImageSrc;
- var svg = createForeignObjectSVG(size, size, 0, 0, img);
- ctx.fillStyle = 'red';
- ctx.fillRect(0, 0, size, size);
- return loadSerializedSVG(svg)
- .then(function (img) {
- ctx.drawImage(img, 0, 0);
- var data = ctx.getImageData(0, 0, size, size).data;
- ctx.fillStyle = 'red';
- ctx.fillRect(0, 0, size, size);
- var node = document.createElement('div');
- node.style.backgroundImage = "url(" + greenImageSrc + ")";
- node.style.height = size + "px";
- // Firefox 55 does not render inline <img /> tags
- return isGreenPixel(data)
- ? loadSerializedSVG(createForeignObjectSVG(size, size, 0, 0, node))
- : Promise.reject(false);
- })
- .then(function (img) {
- ctx.drawImage(img, 0, 0);
- // Edge does not render background-images
- return isGreenPixel(ctx.getImageData(0, 0, size, size).data);
- })
- .catch(function () { return false; });
- };
- var createForeignObjectSVG = function (width, height, x, y, node) {
- var xmlns = 'http://www.w3.org/2000/svg';
- var svg = document.createElementNS(xmlns, 'svg');
- var foreignObject = document.createElementNS(xmlns, 'foreignObject');
- svg.setAttributeNS(null, 'width', width.toString());
- svg.setAttributeNS(null, 'height', height.toString());
- foreignObject.setAttributeNS(null, 'width', '100%');
- foreignObject.setAttributeNS(null, 'height', '100%');
- foreignObject.setAttributeNS(null, 'x', x.toString());
- foreignObject.setAttributeNS(null, 'y', y.toString());
- foreignObject.setAttributeNS(null, 'externalResourcesRequired', 'true');
- svg.appendChild(foreignObject);
- foreignObject.appendChild(node);
- return svg;
- };
- var loadSerializedSVG = function (svg) {
- return new Promise(function (resolve, reject) {
- var img = new Image();
- img.onload = function () { return resolve(img); };
- img.onerror = reject;
- img.src = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(new XMLSerializer().serializeToString(svg));
- });
- };
- var FEATURES = {
- get SUPPORT_RANGE_BOUNDS() {
- var value = testRangeBounds(document);
- Object.defineProperty(FEATURES, 'SUPPORT_RANGE_BOUNDS', { value: value });
- return value;
- },
- get SUPPORT_SVG_DRAWING() {
- var value = testSVG(document);
- Object.defineProperty(FEATURES, 'SUPPORT_SVG_DRAWING', { value: value });
- return value;
- },
- get SUPPORT_FOREIGNOBJECT_DRAWING() {
- var value = typeof Array.from === 'function' && typeof window.fetch === 'function'
- ? testForeignObject(document)
- : Promise.resolve(false);
- Object.defineProperty(FEATURES, 'SUPPORT_FOREIGNOBJECT_DRAWING', { value: value });
- return value;
- },
- get SUPPORT_CORS_IMAGES() {
- var value = testCORS();
- Object.defineProperty(FEATURES, 'SUPPORT_CORS_IMAGES', { value: value });
- return value;
- },
- get SUPPORT_RESPONSE_TYPE() {
- var value = testResponseType();
- Object.defineProperty(FEATURES, 'SUPPORT_RESPONSE_TYPE', { value: value });
- return value;
- },
- get SUPPORT_CORS_XHR() {
- var value = 'withCredentials' in new XMLHttpRequest();
- Object.defineProperty(FEATURES, 'SUPPORT_CORS_XHR', { value: value });
- return value;
- }
- };
- var Logger = /** @class */ (function () {
- function Logger(_a) {
- var id = _a.id, enabled = _a.enabled;
- this.id = id;
- this.enabled = enabled;
- this.start = Date.now();
- }
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- Logger.prototype.debug = function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- if (this.enabled) {
- // eslint-disable-next-line no-console
- if (typeof window !== 'undefined' && window.console && typeof console.debug === 'function') {
- // eslint-disable-next-line no-console
- console.debug.apply(console, [this.id, this.getTime() + "ms"].concat(args));
- }
- else {
- this.info.apply(this, args);
- }
- }
- };
- Logger.prototype.getTime = function () {
- return Date.now() - this.start;
- };
- Logger.create = function (options) {
- Logger.instances[options.id] = new Logger(options);
- };
- Logger.destroy = function (id) {
- delete Logger.instances[id];
- };
- Logger.getInstance = function (id) {
- var instance = Logger.instances[id];
- if (typeof instance === 'undefined') {
- throw new Error("No logger instance found with id " + id);
- }
- return instance;
- };
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- Logger.prototype.info = function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- if (this.enabled) {
- // eslint-disable-next-line no-console
- if (typeof window !== 'undefined' && window.console && typeof console.info === 'function') {
- // eslint-disable-next-line no-console
- console.info.apply(console, [this.id, this.getTime() + "ms"].concat(args));
- }
- }
- };
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- Logger.prototype.error = function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- if (this.enabled) {
- // eslint-disable-next-line no-console
- if (typeof window !== 'undefined' && window.console && typeof console.error === 'function') {
- // eslint-disable-next-line no-console
- console.error.apply(console, [this.id, this.getTime() + "ms"].concat(args));
- }
- else {
- this.info.apply(this, args);
- }
- }
- };
- Logger.instances = {};
- return Logger;
- }());
- var CacheStorage = /** @class */ (function () {
- function CacheStorage() {
- }
- CacheStorage.create = function (name, options) {
- return (CacheStorage._caches[name] = new Cache(name, options));
- };
- CacheStorage.destroy = function (name) {
- delete CacheStorage._caches[name];
- };
- CacheStorage.open = function (name) {
- var cache = CacheStorage._caches[name];
- if (typeof cache !== 'undefined') {
- return cache;
- }
- throw new Error("Cache with key \"" + name + "\" not found");
- };
- CacheStorage.getOrigin = function (url) {
- var link = CacheStorage._link;
- if (!link) {
- return 'about:blank';
- }
- link.href = url;
- link.href = link.href; // IE9, LOL! - http://jsfiddle.net/niklasvh/2e48b/
- return link.protocol + link.hostname + link.port;
- };
- CacheStorage.isSameOrigin = function (src) {
- return CacheStorage.getOrigin(src) === CacheStorage._origin;
- };
- CacheStorage.setContext = function (window) {
- CacheStorage._link = window.document.createElement('a');
- CacheStorage._origin = CacheStorage.getOrigin(window.location.href);
- };
- CacheStorage.getInstance = function () {
- var current = CacheStorage._current;
- if (current === null) {
- throw new Error("No cache instance attached");
- }
- return current;
- };
- CacheStorage.attachInstance = function (cache) {
- CacheStorage._current = cache;
- };
- CacheStorage.detachInstance = function () {
- CacheStorage._current = null;
- };
- CacheStorage._caches = {};
- CacheStorage._origin = 'about:blank';
- CacheStorage._current = null;
- return CacheStorage;
- }());
- var Cache = /** @class */ (function () {
- function Cache(id, options) {
- this.id = id;
- this._options = options;
- this._cache = {};
- }
- Cache.prototype.addImage = function (src) {
- var result = Promise.resolve();
- if (this.has(src)) {
- return result;
- }
- if (isBlobImage(src) || isRenderable(src)) {
- this._cache[src] = this.loadImage(src);
- return result;
- }
- return result;
- };
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- Cache.prototype.match = function (src) {
- return this._cache[src];
- };
- Cache.prototype.loadImage = function (key) {
- return __awaiter(this, void 0, void 0, function () {
- var isSameOrigin, useCORS, useProxy, src;
- var _this = this;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- isSameOrigin = CacheStorage.isSameOrigin(key);
- useCORS = !isInlineImage(key) && this._options.useCORS === true && FEATURES.SUPPORT_CORS_IMAGES && !isSameOrigin;
- useProxy = !isInlineImage(key) &&
- !isSameOrigin &&
- typeof this._options.proxy === 'string' &&
- FEATURES.SUPPORT_CORS_XHR &&
- !useCORS;
- if (!isSameOrigin && this._options.allowTaint === false && !isInlineImage(key) && !useProxy && !useCORS) {
- return [2 /*return*/];
- }
- src = key;
- if (!useProxy) return [3 /*break*/, 2];
- return [4 /*yield*/, this.proxy(src)];
- case 1:
- src = _a.sent();
- _a.label = 2;
- case 2:
- Logger.getInstance(this.id).debug("Added image " + key.substring(0, 256));
- return [4 /*yield*/, new Promise(function (resolve, reject) {
- var img = new Image();
- img.onload = function () { return resolve(img); };
- img.onerror = reject;
- //ios safari 10.3 taints canvas with data urls unless crossOrigin is set to anonymous
- if (isInlineBase64Image(src) || useCORS) {
- img.crossOrigin = 'anonymous';
- }
- img.src = src;
- if (img.complete === true) {
- // Inline XML images may fail to parse, throwing an Error later on
- setTimeout(function () { return resolve(img); }, 500);
- }
- if (_this._options.imageTimeout > 0) {
- setTimeout(function () { return reject("Timed out (" + _this._options.imageTimeout + "ms) loading image"); }, _this._options.imageTimeout);
- }
- })];
- case 3: return [2 /*return*/, _a.sent()];
- }
- });
- });
- };
- Cache.prototype.has = function (key) {
- return typeof this._cache[key] !== 'undefined';
- };
- Cache.prototype.keys = function () {
- return Promise.resolve(Object.keys(this._cache));
- };
- Cache.prototype.proxy = function (src) {
- var _this = this;
- var proxy = this._options.proxy;
- if (!proxy) {
- throw new Error('No proxy defined');
- }
- var key = src.substring(0, 256);
- return new Promise(function (resolve, reject) {
- var responseType = FEATURES.SUPPORT_RESPONSE_TYPE ? 'blob' : 'text';
- var xhr = new XMLHttpRequest();
- xhr.onload = function () {
- if (xhr.status === 200) {
- if (responseType === 'text') {
- resolve(xhr.response);
- }
- else {
- var reader_1 = new FileReader();
- reader_1.addEventListener('load', function () { return resolve(reader_1.result); }, false);
- reader_1.addEventListener('error', function (e) { return reject(e); }, false);
- reader_1.readAsDataURL(xhr.response);
- }
- }
- else {
- reject("Failed to proxy resource " + key + " with status code " + xhr.status);
- }
- };
- xhr.onerror = reject;
- xhr.open('GET', proxy + "?url=" + encodeURIComponent(src) + "&responseType=" + responseType);
- if (responseType !== 'text' && xhr instanceof XMLHttpRequest) {
- xhr.responseType = responseType;
- }
- if (_this._options.imageTimeout) {
- var timeout_1 = _this._options.imageTimeout;
- xhr.timeout = timeout_1;
- xhr.ontimeout = function () { return reject("Timed out (" + timeout_1 + "ms) proxying " + key); };
- }
- xhr.send();
- });
- };
- return Cache;
- }());
- var INLINE_SVG = /^data:image\/svg\+xml/i;
- var INLINE_BASE64 = /^data:image\/.*;base64,/i;
- var INLINE_IMG = /^data:image\/.*/i;
- var isRenderable = function (src) { return FEATURES.SUPPORT_SVG_DRAWING || !isSVG(src); };
- var isInlineImage = function (src) { return INLINE_IMG.test(src); };
- var isInlineBase64Image = function (src) { return INLINE_BASE64.test(src); };
- var isBlobImage = function (src) { return src.substr(0, 4) === 'blob'; };
- var isSVG = function (src) { return src.substr(-3).toLowerCase() === 'svg' || INLINE_SVG.test(src); };
- var webkitGradient = function (tokens) {
- var angle = deg(180);
- var stops = [];
- var type = CSSImageType.LINEAR_GRADIENT;
- var shape = CSSRadialShape.CIRCLE;
- var size = CSSRadialExtent.FARTHEST_CORNER;
- var position = [];
- parseFunctionArgs(tokens).forEach(function (arg, i) {
- var firstToken = arg[0];
- if (i === 0) {
- if (isIdentToken(firstToken) && firstToken.value === 'linear') {
- type = CSSImageType.LINEAR_GRADIENT;
- return;
- }
- else if (isIdentToken(firstToken) && firstToken.value === 'radial') {
- type = CSSImageType.RADIAL_GRADIENT;
- return;
- }
- }
- if (firstToken.type === TokenType.FUNCTION) {
- if (firstToken.name === 'from') {
- var color$1 = color.parse(firstToken.values[0]);
- stops.push({ stop: ZERO_LENGTH, color: color$1 });
- }
- else if (firstToken.name === 'to') {
- var color$1 = color.parse(firstToken.values[0]);
- stops.push({ stop: HUNDRED_PERCENT, color: color$1 });
- }
- else if (firstToken.name === 'color-stop') {
- var values = firstToken.values.filter(nonFunctionArgSeparator);
- if (values.length === 2) {
- var color$1 = color.parse(values[1]);
- var stop_1 = values[0];
- if (isNumberToken(stop_1)) {
- stops.push({
- stop: { type: TokenType.PERCENTAGE_TOKEN, number: stop_1.number * 100, flags: stop_1.flags },
- color: color$1
- });
- }
- }
- }
- }
- });
- return type === CSSImageType.LINEAR_GRADIENT
- ? {
- angle: (angle + deg(180)) % deg(360),
- stops: stops,
- type: type
- }
- : { size: size, shape: shape, stops: stops, position: position, type: type };
- };
- var CLOSEST_SIDE = 'closest-side';
- var FARTHEST_SIDE = 'farthest-side';
- var CLOSEST_CORNER = 'closest-corner';
- var FARTHEST_CORNER = 'farthest-corner';
- var CIRCLE = 'circle';
- var ELLIPSE = 'ellipse';
- var COVER = 'cover';
- var CONTAIN = 'contain';
- var radialGradient = function (tokens) {
- var shape = CSSRadialShape.CIRCLE;
- var size = CSSRadialExtent.FARTHEST_CORNER;
- var stops = [];
- var position = [];
- parseFunctionArgs(tokens).forEach(function (arg, i) {
- var isColorStop = true;
- if (i === 0) {
- var isAtPosition_1 = false;
- isColorStop = arg.reduce(function (acc, token) {
- if (isAtPosition_1) {
- if (isIdentToken(token)) {
- switch (token.value) {
- case 'center':
- position.push(FIFTY_PERCENT);
- return acc;
- case 'top':
- case 'left':
- position.push(ZERO_LENGTH);
- return acc;
- case 'right':
- case 'bottom':
- position.push(HUNDRED_PERCENT);
- return acc;
- }
- }
- else if (isLengthPercentage(token) || isLength(token)) {
- position.push(token);
- }
- }
- else if (isIdentToken(token)) {
- switch (token.value) {
- case CIRCLE:
- shape = CSSRadialShape.CIRCLE;
- return false;
- case ELLIPSE:
- shape = CSSRadialShape.ELLIPSE;
- return false;
- case 'at':
- isAtPosition_1 = true;
- return false;
- case CLOSEST_SIDE:
- size = CSSRadialExtent.CLOSEST_SIDE;
- return false;
- case COVER:
- case FARTHEST_SIDE:
- size = CSSRadialExtent.FARTHEST_SIDE;
- return false;
- case CONTAIN:
- case CLOSEST_CORNER:
- size = CSSRadialExtent.CLOSEST_CORNER;
- return false;
- case FARTHEST_CORNER:
- size = CSSRadialExtent.FARTHEST_CORNER;
- return false;
- }
- }
- else if (isLength(token) || isLengthPercentage(token)) {
- if (!Array.isArray(size)) {
- size = [];
- }
- size.push(token);
- return false;
- }
- return acc;
- }, isColorStop);
- }
- if (isColorStop) {
- var colorStop = parseColorStop(arg);
- stops.push(colorStop);
- }
- });
- return { size: size, shape: shape, stops: stops, position: position, type: CSSImageType.RADIAL_GRADIENT };
- };
- var prefixRadialGradient = function (tokens) {
- var shape = CSSRadialShape.CIRCLE;
- var size = CSSRadialExtent.FARTHEST_CORNER;
- var stops = [];
- var position = [];
- parseFunctionArgs(tokens).forEach(function (arg, i) {
- var isColorStop = true;
- if (i === 0) {
- isColorStop = arg.reduce(function (acc, token) {
- if (isIdentToken(token)) {
- switch (token.value) {
- case 'center':
- position.push(FIFTY_PERCENT);
- return false;
- case 'top':
- case 'left':
- position.push(ZERO_LENGTH);
- return false;
- case 'right':
- case 'bottom':
- position.push(HUNDRED_PERCENT);
- return false;
- }
- }
- else if (isLengthPercentage(token) || isLength(token)) {
- position.push(token);
- return false;
- }
- return acc;
- }, isColorStop);
- }
- else if (i === 1) {
- isColorStop = arg.reduce(function (acc, token) {
- if (isIdentToken(token)) {
- switch (token.value) {
- case CIRCLE:
- shape = CSSRadialShape.CIRCLE;
- return false;
- case ELLIPSE:
- shape = CSSRadialShape.ELLIPSE;
- return false;
- case CONTAIN:
- case CLOSEST_SIDE:
- size = CSSRadialExtent.CLOSEST_SIDE;
- return false;
- case FARTHEST_SIDE:
- size = CSSRadialExtent.FARTHEST_SIDE;
- return false;
- case CLOSEST_CORNER:
- size = CSSRadialExtent.CLOSEST_CORNER;
- return false;
- case COVER:
- case FARTHEST_CORNER:
- size = CSSRadialExtent.FARTHEST_CORNER;
- return false;
- }
- }
- else if (isLength(token) || isLengthPercentage(token)) {
- if (!Array.isArray(size)) {
- size = [];
- }
- size.push(token);
- return false;
- }
- return acc;
- }, isColorStop);
- }
- if (isColorStop) {
- var colorStop = parseColorStop(arg);
- stops.push(colorStop);
- }
- });
- return { size: size, shape: shape, stops: stops, position: position, type: CSSImageType.RADIAL_GRADIENT };
- };
- var CSSImageType;
- (function (CSSImageType) {
- CSSImageType[CSSImageType["URL"] = 0] = "URL";
- CSSImageType[CSSImageType["LINEAR_GRADIENT"] = 1] = "LINEAR_GRADIENT";
- CSSImageType[CSSImageType["RADIAL_GRADIENT"] = 2] = "RADIAL_GRADIENT";
- })(CSSImageType || (CSSImageType = {}));
- var isLinearGradient = function (background) {
- return background.type === CSSImageType.LINEAR_GRADIENT;
- };
- var isRadialGradient = function (background) {
- return background.type === CSSImageType.RADIAL_GRADIENT;
- };
- var CSSRadialShape;
- (function (CSSRadialShape) {
- CSSRadialShape[CSSRadialShape["CIRCLE"] = 0] = "CIRCLE";
- CSSRadialShape[CSSRadialShape["ELLIPSE"] = 1] = "ELLIPSE";
- })(CSSRadialShape || (CSSRadialShape = {}));
- var CSSRadialExtent;
- (function (CSSRadialExtent) {
- CSSRadialExtent[CSSRadialExtent["CLOSEST_SIDE"] = 0] = "CLOSEST_SIDE";
- CSSRadialExtent[CSSRadialExtent["FARTHEST_SIDE"] = 1] = "FARTHEST_SIDE";
- CSSRadialExtent[CSSRadialExtent["CLOSEST_CORNER"] = 2] = "CLOSEST_CORNER";
- CSSRadialExtent[CSSRadialExtent["FARTHEST_CORNER"] = 3] = "FARTHEST_CORNER";
- })(CSSRadialExtent || (CSSRadialExtent = {}));
- var image = {
- name: 'image',
- parse: function (value) {
- if (value.type === TokenType.URL_TOKEN) {
- var image_1 = { url: value.value, type: CSSImageType.URL };
- CacheStorage.getInstance().addImage(value.value);
- return image_1;
- }
- if (value.type === TokenType.FUNCTION) {
- var imageFunction = SUPPORTED_IMAGE_FUNCTIONS[value.name];
- if (typeof imageFunction === 'undefined') {
- throw new Error("Attempting to parse an unsupported image function \"" + value.name + "\"");
- }
- return imageFunction(value.values);
- }
- throw new Error("Unsupported image type");
- }
- };
- function isSupportedImage(value) {
- return value.type !== TokenType.FUNCTION || SUPPORTED_IMAGE_FUNCTIONS[value.name];
- }
- var SUPPORTED_IMAGE_FUNCTIONS = {
- 'linear-gradient': linearGradient,
- '-moz-linear-gradient': prefixLinearGradient,
- '-ms-linear-gradient': prefixLinearGradient,
- '-o-linear-gradient': prefixLinearGradient,
- '-webkit-linear-gradient': prefixLinearGradient,
- 'radial-gradient': radialGradient,
- '-moz-radial-gradient': prefixRadialGradient,
- '-ms-radial-gradient': prefixRadialGradient,
- '-o-radial-gradient': prefixRadialGradient,
- '-webkit-radial-gradient': prefixRadialGradient,
- '-webkit-gradient': webkitGradient
- };
- var backgroundImage = {
- name: 'background-image',
- initialValue: 'none',
- type: PropertyDescriptorParsingType.LIST,
- prefix: false,
- parse: function (tokens) {
- if (tokens.length === 0) {
- return [];
- }
- var first = tokens[0];
- if (first.type === TokenType.IDENT_TOKEN && first.value === 'none') {
- return [];
- }
- return tokens.filter(function (value) { return nonFunctionArgSeparator(value) && isSupportedImage(value); }).map(image.parse);
- }
- };
- var backgroundOrigin = {
- name: 'background-origin',
- initialValue: 'border-box',
- prefix: false,
- type: PropertyDescriptorParsingType.LIST,
- parse: function (tokens) {
- return tokens.map(function (token) {
- if (isIdentToken(token)) {
- switch (token.value) {
- case 'padding-box':
- return 1 /* PADDING_BOX */;
- case 'content-box':
- return 2 /* CONTENT_BOX */;
- }
- }
- return 0 /* BORDER_BOX */;
- });
- }
- };
- var backgroundPosition = {
- name: 'background-position',
- initialValue: '0% 0%',
- type: PropertyDescriptorParsingType.LIST,
- prefix: false,
- parse: function (tokens) {
- return parseFunctionArgs(tokens)
- .map(function (values) { return values.filter(isLengthPercentage); })
- .map(parseLengthPercentageTuple);
- }
- };
- var BACKGROUND_REPEAT;
- (function (BACKGROUND_REPEAT) {
- BACKGROUND_REPEAT[BACKGROUND_REPEAT["REPEAT"] = 0] = "REPEAT";
- BACKGROUND_REPEAT[BACKGROUND_REPEAT["NO_REPEAT"] = 1] = "NO_REPEAT";
- BACKGROUND_REPEAT[BACKGROUND_REPEAT["REPEAT_X"] = 2] = "REPEAT_X";
- BACKGROUND_REPEAT[BACKGROUND_REPEAT["REPEAT_Y"] = 3] = "REPEAT_Y";
- })(BACKGROUND_REPEAT || (BACKGROUND_REPEAT = {}));
- var backgroundRepeat = {
- name: 'background-repeat',
- initialValue: 'repeat',
- prefix: false,
- type: PropertyDescriptorParsingType.LIST,
- parse: function (tokens) {
- return parseFunctionArgs(tokens)
- .map(function (values) {
- return values
- .filter(isIdentToken)
- .map(function (token) { return token.value; })
- .join(' ');
- })
- .map(parseBackgroundRepeat);
- }
- };
- var parseBackgroundRepeat = function (value) {
- switch (value) {
- case 'no-repeat':
- return BACKGROUND_REPEAT.NO_REPEAT;
- case 'repeat-x':
- case 'repeat no-repeat':
- return BACKGROUND_REPEAT.REPEAT_X;
- case 'repeat-y':
- case 'no-repeat repeat':
- return BACKGROUND_REPEAT.REPEAT_Y;
- case 'repeat':
- default:
- return BACKGROUND_REPEAT.REPEAT;
- }
- };
- var BACKGROUND_SIZE;
- (function (BACKGROUND_SIZE) {
- BACKGROUND_SIZE["AUTO"] = "auto";
- BACKGROUND_SIZE["CONTAIN"] = "contain";
- BACKGROUND_SIZE["COVER"] = "cover";
- })(BACKGROUND_SIZE || (BACKGROUND_SIZE = {}));
- var backgroundSize = {
- name: 'background-size',
- initialValue: '0',
- prefix: false,
- type: PropertyDescriptorParsingType.LIST,
- parse: function (tokens) {
- return parseFunctionArgs(tokens).map(function (values) { return values.filter(isBackgroundSizeInfoToken); });
- }
- };
- var isBackgroundSizeInfoToken = function (value) {
- return isIdentToken(value) || isLengthPercentage(value);
- };
- var borderColorForSide = function (side) { return ({
- name: "border-" + side + "-color",
- initialValue: 'transparent',
- prefix: false,
- type: PropertyDescriptorParsingType.TYPE_VALUE,
- format: 'color'
- }); };
- var borderTopColor = borderColorForSide('top');
- var borderRightColor = borderColorForSide('right');
- var borderBottomColor = borderColorForSide('bottom');
- var borderLeftColor = borderColorForSide('left');
- var borderRadiusForSide = function (side) { return ({
- name: "border-radius-" + side,
- initialValue: '0 0',
- prefix: false,
- type: PropertyDescriptorParsingType.LIST,
- parse: function (tokens) { return parseLengthPercentageTuple(tokens.filter(isLengthPercentage)); }
- }); };
- var borderTopLeftRadius = borderRadiusForSide('top-left');
- var borderTopRightRadius = borderRadiusForSide('top-right');
- var borderBottomRightRadius = borderRadiusForSide('bottom-right');
- var borderBottomLeftRadius = borderRadiusForSide('bottom-left');
- var BORDER_STYLE;
- (function (BORDER_STYLE) {
- BORDER_STYLE[BORDER_STYLE["NONE"] = 0] = "NONE";
- BORDER_STYLE[BORDER_STYLE["SOLID"] = 1] = "SOLID";
- })(BORDER_STYLE || (BORDER_STYLE = {}));
- var borderStyleForSide = function (side) { return ({
- name: "border-" + side + "-style",
- initialValue: 'solid',
- prefix: false,
- type: PropertyDescriptorParsingType.IDENT_VALUE,
- parse: function (style) {
- switch (style) {
- case 'none':
- return BORDER_STYLE.NONE;
- }
- return BORDER_STYLE.SOLID;
- }
- }); };
- var borderTopStyle = borderStyleForSide('top');
- var borderRightStyle = borderStyleForSide('right');
- var borderBottomStyle = borderStyleForSide('bottom');
- var borderLeftStyle = borderStyleForSide('left');
- var borderWidthForSide = function (side) { return ({
- name: "border-" + side + "-width",
- initialValue: '0',
- type: PropertyDescriptorParsingType.VALUE,
- prefix: false,
- parse: function (token) {
- if (isDimensionToken(token)) {
- return token.number;
- }
- return 0;
- }
- }); };
- var borderTopWidth = borderWidthForSide('top');
- var borderRightWidth = borderWidthForSide('right');
- var borderBottomWidth = borderWidthForSide('bottom');
- var borderLeftWidth = borderWidthForSide('left');
- var color$1 = {
- name: "color",
- initialValue: 'transparent',
- prefix: false,
- type: PropertyDescriptorParsingType.TYPE_VALUE,
- format: 'color'
- };
- var display = {
- name: 'display',
- initialValue: 'inline-block',
- prefix: false,
- type: PropertyDescriptorParsingType.LIST,
- parse: function (tokens) {
- return tokens.filter(isIdentToken).reduce(function (bit, token) {
- return bit | parseDisplayValue(token.value);
- }, 0 /* NONE */);
- }
- };
- var parseDisplayValue = function (display) {
- switch (display) {
- case 'block':
- return 2 /* BLOCK */;
- case 'inline':
- return 4 /* INLINE */;
- case 'run-in':
- return 8 /* RUN_IN */;
- case 'flow':
- return 16 /* FLOW */;
- case 'flow-root':
- return 32 /* FLOW_ROOT */;
- case 'table':
- return 64 /* TABLE */;
- case 'flex':
- case '-webkit-flex':
- return 128 /* FLEX */;
- case 'grid':
- case '-ms-grid':
- return 256 /* GRID */;
- case 'ruby':
- return 512 /* RUBY */;
- case 'subgrid':
- return 1024 /* SUBGRID */;
- case 'list-item':
- return 2048 /* LIST_ITEM */;
- case 'table-row-group':
- return 4096 /* TABLE_ROW_GROUP */;
- case 'table-header-group':
- return 8192 /* TABLE_HEADER_GROUP */;
- case 'table-footer-group':
- return 16384 /* TABLE_FOOTER_GROUP */;
- case 'table-row':
- return 32768 /* TABLE_ROW */;
- case 'table-cell':
- return 65536 /* TABLE_CELL */;
- case 'table-column-group':
- return 131072 /* TABLE_COLUMN_GROUP */;
- case 'table-column':
- return 262144 /* TABLE_COLUMN */;
- case 'table-caption':
- return 524288 /* TABLE_CAPTION */;
- case 'ruby-base':
- return 1048576 /* RUBY_BASE */;
- case 'ruby-text':
- return 2097152 /* RUBY_TEXT */;
- case 'ruby-base-container':
- return 4194304 /* RUBY_BASE_CONTAINER */;
- case 'ruby-text-container':
- return 8388608 /* RUBY_TEXT_CONTAINER */;
- case 'contents':
- return 16777216 /* CONTENTS */;
- case 'inline-block':
- return 33554432 /* INLINE_BLOCK */;
- case 'inline-list-item':
- return 67108864 /* INLINE_LIST_ITEM */;
- case 'inline-table':
- return 134217728 /* INLINE_TABLE */;
- case 'inline-flex':
- return 268435456 /* INLINE_FLEX */;
- case 'inline-grid':
- return 536870912 /* INLINE_GRID */;
- }
- return 0 /* NONE */;
- };
- var FLOAT;
- (function (FLOAT) {
- FLOAT[FLOAT["NONE"] = 0] = "NONE";
- FLOAT[FLOAT["LEFT"] = 1] = "LEFT";
- FLOAT[FLOAT["RIGHT"] = 2] = "RIGHT";
- FLOAT[FLOAT["INLINE_START"] = 3] = "INLINE_START";
- FLOAT[FLOAT["INLINE_END"] = 4] = "INLINE_END";
- })(FLOAT || (FLOAT = {}));
- var float = {
- name: 'float',
- initialValue: 'none',
- prefix: false,
- type: PropertyDescriptorParsingType.IDENT_VALUE,
- parse: function (float) {
- switch (float) {
- case 'left':
- return FLOAT.LEFT;
- case 'right':
- return FLOAT.RIGHT;
- case 'inline-start':
- return FLOAT.INLINE_START;
- case 'inline-end':
- return FLOAT.INLINE_END;
- }
- return FLOAT.NONE;
- }
- };
- var letterSpacing = {
- name: 'letter-spacing',
- initialValue: '0',
- prefix: false,
- type: PropertyDescriptorParsingType.VALUE,
- parse: function (token) {
- if (token.type === TokenType.IDENT_TOKEN && token.value === 'normal') {
- return 0;
- }
- if (token.type === TokenType.NUMBER_TOKEN) {
- return token.number;
- }
- if (token.type === TokenType.DIMENSION_TOKEN) {
- return token.number;
- }
- return 0;
- }
- };
- var LINE_BREAK;
- (function (LINE_BREAK) {
- LINE_BREAK["NORMAL"] = "normal";
- LINE_BREAK["STRICT"] = "strict";
- })(LINE_BREAK || (LINE_BREAK = {}));
- var lineBreak = {
- name: 'line-break',
- initialValue: 'normal',
- prefix: false,
- type: PropertyDescriptorParsingType.IDENT_VALUE,
- parse: function (lineBreak) {
- switch (lineBreak) {
- case 'strict':
- return LINE_BREAK.STRICT;
- case 'normal':
- default:
- return LINE_BREAK.NORMAL;
- }
- }
- };
- var lineHeight = {
- name: 'line-height',
- initialValue: 'normal',
- prefix: false,
- type: PropertyDescriptorParsingType.TOKEN_VALUE
- };
- var computeLineHeight = function (token, fontSize) {
- if (isIdentToken(token) && token.value === 'normal') {
- return 1.2 * fontSize;
- }
- else if (token.type === TokenType.NUMBER_TOKEN) {
- return fontSize * token.number;
- }
- else if (isLengthPercentage(token)) {
- return getAbsoluteValue(token, fontSize);
- }
- return fontSize;
- };
- var listStyleImage = {
- name: 'list-style-image',
- initialValue: 'none',
- type: PropertyDescriptorParsingType.VALUE,
- prefix: false,
- parse: function (token) {
- if (token.type === TokenType.IDENT_TOKEN && token.value === 'none') {
- return null;
- }
- return image.parse(token);
- }
- };
- var LIST_STYLE_POSITION;
- (function (LIST_STYLE_POSITION) {
- LIST_STYLE_POSITION[LIST_STYLE_POSITION["INSIDE"] = 0] = "INSIDE";
- LIST_STYLE_POSITION[LIST_STYLE_POSITION["OUTSIDE"] = 1] = "OUTSIDE";
- })(LIST_STYLE_POSITION || (LIST_STYLE_POSITION = {}));
- var listStylePosition = {
- name: 'list-style-position',
- initialValue: 'outside',
- prefix: false,
- type: PropertyDescriptorParsingType.IDENT_VALUE,
- parse: function (position) {
- switch (position) {
- case 'inside':
- return LIST_STYLE_POSITION.INSIDE;
- case 'outside':
- default:
- return LIST_STYLE_POSITION.OUTSIDE;
- }
- }
- };
- var LIST_STYLE_TYPE;
- (function (LIST_STYLE_TYPE) {
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["NONE"] = -1] = "NONE";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["DISC"] = 0] = "DISC";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["CIRCLE"] = 1] = "CIRCLE";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["SQUARE"] = 2] = "SQUARE";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["DECIMAL"] = 3] = "DECIMAL";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["CJK_DECIMAL"] = 4] = "CJK_DECIMAL";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["DECIMAL_LEADING_ZERO"] = 5] = "DECIMAL_LEADING_ZERO";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["LOWER_ROMAN"] = 6] = "LOWER_ROMAN";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["UPPER_ROMAN"] = 7] = "UPPER_ROMAN";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["LOWER_GREEK"] = 8] = "LOWER_GREEK";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["LOWER_ALPHA"] = 9] = "LOWER_ALPHA";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["UPPER_ALPHA"] = 10] = "UPPER_ALPHA";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["ARABIC_INDIC"] = 11] = "ARABIC_INDIC";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["ARMENIAN"] = 12] = "ARMENIAN";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["BENGALI"] = 13] = "BENGALI";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["CAMBODIAN"] = 14] = "CAMBODIAN";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["CJK_EARTHLY_BRANCH"] = 15] = "CJK_EARTHLY_BRANCH";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["CJK_HEAVENLY_STEM"] = 16] = "CJK_HEAVENLY_STEM";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["CJK_IDEOGRAPHIC"] = 17] = "CJK_IDEOGRAPHIC";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["DEVANAGARI"] = 18] = "DEVANAGARI";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["ETHIOPIC_NUMERIC"] = 19] = "ETHIOPIC_NUMERIC";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["GEORGIAN"] = 20] = "GEORGIAN";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["GUJARATI"] = 21] = "GUJARATI";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["GURMUKHI"] = 22] = "GURMUKHI";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["HEBREW"] = 22] = "HEBREW";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["HIRAGANA"] = 23] = "HIRAGANA";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["HIRAGANA_IROHA"] = 24] = "HIRAGANA_IROHA";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["JAPANESE_FORMAL"] = 25] = "JAPANESE_FORMAL";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["JAPANESE_INFORMAL"] = 26] = "JAPANESE_INFORMAL";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["KANNADA"] = 27] = "KANNADA";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["KATAKANA"] = 28] = "KATAKANA";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["KATAKANA_IROHA"] = 29] = "KATAKANA_IROHA";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["KHMER"] = 30] = "KHMER";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["KOREAN_HANGUL_FORMAL"] = 31] = "KOREAN_HANGUL_FORMAL";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["KOREAN_HANJA_FORMAL"] = 32] = "KOREAN_HANJA_FORMAL";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["KOREAN_HANJA_INFORMAL"] = 33] = "KOREAN_HANJA_INFORMAL";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["LAO"] = 34] = "LAO";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["LOWER_ARMENIAN"] = 35] = "LOWER_ARMENIAN";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["MALAYALAM"] = 36] = "MALAYALAM";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["MONGOLIAN"] = 37] = "MONGOLIAN";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["MYANMAR"] = 38] = "MYANMAR";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["ORIYA"] = 39] = "ORIYA";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["PERSIAN"] = 40] = "PERSIAN";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["SIMP_CHINESE_FORMAL"] = 41] = "SIMP_CHINESE_FORMAL";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["SIMP_CHINESE_INFORMAL"] = 42] = "SIMP_CHINESE_INFORMAL";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["TAMIL"] = 43] = "TAMIL";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["TELUGU"] = 44] = "TELUGU";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["THAI"] = 45] = "THAI";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["TIBETAN"] = 46] = "TIBETAN";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["TRAD_CHINESE_FORMAL"] = 47] = "TRAD_CHINESE_FORMAL";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["TRAD_CHINESE_INFORMAL"] = 48] = "TRAD_CHINESE_INFORMAL";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["UPPER_ARMENIAN"] = 49] = "UPPER_ARMENIAN";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["DISCLOSURE_OPEN"] = 50] = "DISCLOSURE_OPEN";
- LIST_STYLE_TYPE[LIST_STYLE_TYPE["DISCLOSURE_CLOSED"] = 51] = "DISCLOSURE_CLOSED";
- })(LIST_STYLE_TYPE || (LIST_STYLE_TYPE = {}));
- var listStyleType = {
- name: 'list-style-type',
- initialValue: 'none',
- prefix: false,
- type: PropertyDescriptorParsingType.IDENT_VALUE,
- parse: function (type) {
- switch (type) {
- case 'disc':
- return LIST_STYLE_TYPE.DISC;
- case 'circle':
- return LIST_STYLE_TYPE.CIRCLE;
- case 'square':
- return LIST_STYLE_TYPE.SQUARE;
- case 'decimal':
- return LIST_STYLE_TYPE.DECIMAL;
- case 'cjk-decimal':
- return LIST_STYLE_TYPE.CJK_DECIMAL;
- case 'decimal-leading-zero':
- return LIST_STYLE_TYPE.DECIMAL_LEADING_ZERO;
- case 'lower-roman':
- return LIST_STYLE_TYPE.LOWER_ROMAN;
- case 'upper-roman':
- return LIST_STYLE_TYPE.UPPER_ROMAN;
- case 'lower-greek':
- return LIST_STYLE_TYPE.LOWER_GREEK;
- case 'lower-alpha':
- return LIST_STYLE_TYPE.LOWER_ALPHA;
- case 'upper-alpha':
- return LIST_STYLE_TYPE.UPPER_ALPHA;
- case 'arabic-indic':
- return LIST_STYLE_TYPE.ARABIC_INDIC;
- case 'armenian':
- return LIST_STYLE_TYPE.ARMENIAN;
- case 'bengali':
- return LIST_STYLE_TYPE.BENGALI;
- case 'cambodian':
- return LIST_STYLE_TYPE.CAMBODIAN;
- case 'cjk-earthly-branch':
- return LIST_STYLE_TYPE.CJK_EARTHLY_BRANCH;
- case 'cjk-heavenly-stem':
- return LIST_STYLE_TYPE.CJK_HEAVENLY_STEM;
- case 'cjk-ideographic':
- return LIST_STYLE_TYPE.CJK_IDEOGRAPHIC;
- case 'devanagari':
- return LIST_STYLE_TYPE.DEVANAGARI;
- case 'ethiopic-numeric':
- return LIST_STYLE_TYPE.ETHIOPIC_NUMERIC;
- case 'georgian':
- return LIST_STYLE_TYPE.GEORGIAN;
- case 'gujarati':
- return LIST_STYLE_TYPE.GUJARATI;
- case 'gurmukhi':
- return LIST_STYLE_TYPE.GURMUKHI;
- case 'hebrew':
- return LIST_STYLE_TYPE.HEBREW;
- case 'hiragana':
- return LIST_STYLE_TYPE.HIRAGANA;
- case 'hiragana-iroha':
- return LIST_STYLE_TYPE.HIRAGANA_IROHA;
- case 'japanese-formal':
- return LIST_STYLE_TYPE.JAPANESE_FORMAL;
- case 'japanese-informal':
- return LIST_STYLE_TYPE.JAPANESE_INFORMAL;
- case 'kannada':
- return LIST_STYLE_TYPE.KANNADA;
- case 'katakana':
- return LIST_STYLE_TYPE.KATAKANA;
- case 'katakana-iroha':
- return LIST_STYLE_TYPE.KATAKANA_IROHA;
- case 'khmer':
- return LIST_STYLE_TYPE.KHMER;
- case 'korean-hangul-formal':
- return LIST_STYLE_TYPE.KOREAN_HANGUL_FORMAL;
- case 'korean-hanja-formal':
- return LIST_STYLE_TYPE.KOREAN_HANJA_FORMAL;
- case 'korean-hanja-informal':
- return LIST_STYLE_TYPE.KOREAN_HANJA_INFORMAL;
- case 'lao':
- return LIST_STYLE_TYPE.LAO;
- case 'lower-armenian':
- return LIST_STYLE_TYPE.LOWER_ARMENIAN;
- case 'malayalam':
- return LIST_STYLE_TYPE.MALAYALAM;
- case 'mongolian':
- return LIST_STYLE_TYPE.MONGOLIAN;
- case 'myanmar':
- return LIST_STYLE_TYPE.MYANMAR;
- case 'oriya':
- return LIST_STYLE_TYPE.ORIYA;
- case 'persian':
- return LIST_STYLE_TYPE.PERSIAN;
- case 'simp-chinese-formal':
- return LIST_STYLE_TYPE.SIMP_CHINESE_FORMAL;
- case 'simp-chinese-informal':
- return LIST_STYLE_TYPE.SIMP_CHINESE_INFORMAL;
- case 'tamil':
- return LIST_STYLE_TYPE.TAMIL;
- case 'telugu':
- return LIST_STYLE_TYPE.TELUGU;
- case 'thai':
- return LIST_STYLE_TYPE.THAI;
- case 'tibetan':
- return LIST_STYLE_TYPE.TIBETAN;
- case 'trad-chinese-formal':
- return LIST_STYLE_TYPE.TRAD_CHINESE_FORMAL;
- case 'trad-chinese-informal':
- return LIST_STYLE_TYPE.TRAD_CHINESE_INFORMAL;
- case 'upper-armenian':
- return LIST_STYLE_TYPE.UPPER_ARMENIAN;
- case 'disclosure-open':
- return LIST_STYLE_TYPE.DISCLOSURE_OPEN;
- case 'disclosure-closed':
- return LIST_STYLE_TYPE.DISCLOSURE_CLOSED;
- case 'none':
- default:
- return LIST_STYLE_TYPE.NONE;
- }
- }
- };
- var marginForSide = function (side) { return ({
- name: "margin-" + side,
- initialValue: '0',
- prefix: false,
- type: PropertyDescriptorParsingType.TOKEN_VALUE
- }); };
- var marginTop = marginForSide('top');
- var marginRight = marginForSide('right');
- var marginBottom = marginForSide('bottom');
- var marginLeft = marginForSide('left');
- var OVERFLOW;
- (function (OVERFLOW) {
- OVERFLOW[OVERFLOW["VISIBLE"] = 0] = "VISIBLE";
- OVERFLOW[OVERFLOW["HIDDEN"] = 1] = "HIDDEN";
- OVERFLOW[OVERFLOW["SCROLL"] = 2] = "SCROLL";
- OVERFLOW[OVERFLOW["AUTO"] = 3] = "AUTO";
- })(OVERFLOW || (OVERFLOW = {}));
- var overflow = {
- name: 'overflow',
- initialValue: 'visible',
- prefix: false,
- type: PropertyDescriptorParsingType.LIST,
- parse: function (tokens) {
- return tokens.filter(isIdentToken).map(function (overflow) {
- switch (overflow.value) {
- case 'hidden':
- return OVERFLOW.HIDDEN;
- case 'scroll':
- return OVERFLOW.SCROLL;
- case 'auto':
- return OVERFLOW.AUTO;
- case 'visible':
- default:
- return OVERFLOW.VISIBLE;
- }
- });
- }
- };
- var OVERFLOW_WRAP;
- (function (OVERFLOW_WRAP) {
- OVERFLOW_WRAP["NORMAL"] = "normal";
- OVERFLOW_WRAP["BREAK_WORD"] = "break-word";
- })(OVERFLOW_WRAP || (OVERFLOW_WRAP = {}));
- var overflowWrap = {
- name: 'overflow-wrap',
- initialValue: 'normal',
- prefix: false,
- type: PropertyDescriptorParsingType.IDENT_VALUE,
- parse: function (overflow) {
- switch (overflow) {
- case 'break-word':
- return OVERFLOW_WRAP.BREAK_WORD;
- case 'normal':
- default:
- return OVERFLOW_WRAP.NORMAL;
- }
- }
- };
- var paddingForSide = function (side) { return ({
- name: "padding-" + side,
- initialValue: '0',
- prefix: false,
- type: PropertyDescriptorParsingType.TYPE_VALUE,
- format: 'length-percentage'
- }); };
- var paddingTop = paddingForSide('top');
- var paddingRight = paddingForSide('right');
- var paddingBottom = paddingForSide('bottom');
- var paddingLeft = paddingForSide('left');
- var TEXT_ALIGN;
- (function (TEXT_ALIGN) {
- TEXT_ALIGN[TEXT_ALIGN["LEFT"] = 0] = "LEFT";
- TEXT_ALIGN[TEXT_ALIGN["CENTER"] = 1] = "CENTER";
- TEXT_ALIGN[TEXT_ALIGN["RIGHT"] = 2] = "RIGHT";
- })(TEXT_ALIGN || (TEXT_ALIGN = {}));
- var textAlign = {
- name: 'text-align',
- initialValue: 'left',
- prefix: false,
- type: PropertyDescriptorParsingType.IDENT_VALUE,
- parse: function (textAlign) {
- switch (textAlign) {
- case 'right':
- return TEXT_ALIGN.RIGHT;
- case 'center':
- case 'justify':
- return TEXT_ALIGN.CENTER;
- case 'left':
- default:
- return TEXT_ALIGN.LEFT;
- }
- }
- };
- var POSITION;
- (function (POSITION) {
- POSITION[POSITION["STATIC"] = 0] = "STATIC";
- POSITION[POSITION["RELATIVE"] = 1] = "RELATIVE";
- POSITION[POSITION["ABSOLUTE"] = 2] = "ABSOLUTE";
- POSITION[POSITION["FIXED"] = 3] = "FIXED";
- POSITION[POSITION["STICKY"] = 4] = "STICKY";
- })(POSITION || (POSITION = {}));
- var position = {
- name: 'position',
- initialValue: 'static',
- prefix: false,
- type: PropertyDescriptorParsingType.IDENT_VALUE,
- parse: function (position) {
- switch (position) {
- case 'relative':
- return POSITION.RELATIVE;
- case 'absolute':
- return POSITION.ABSOLUTE;
- case 'fixed':
- return POSITION.FIXED;
- case 'sticky':
- return POSITION.STICKY;
- }
- return POSITION.STATIC;
- }
- };
- var textShadow = {
- name: 'text-shadow',
- initialValue: 'none',
- type: PropertyDescriptorParsingType.LIST,
- prefix: false,
- parse: function (tokens) {
- if (tokens.length === 1 && isIdentWithValue(tokens[0], 'none')) {
- return [];
- }
- return parseFunctionArgs(tokens).map(function (values) {
- var shadow = {
- color: COLORS.TRANSPARENT,
- offsetX: ZERO_LENGTH,
- offsetY: ZERO_LENGTH,
- blur: ZERO_LENGTH
- };
- var c = 0;
- for (var i = 0; i < values.length; i++) {
- var token = values[i];
- if (isLength(token)) {
- if (c === 0) {
- shadow.offsetX = token;
- }
- else if (c === 1) {
- shadow.offsetY = token;
- }
- else {
- shadow.blur = token;
- }
- c++;
- }
- else {
- shadow.color = color.parse(token);
- }
- }
- return shadow;
- });
- }
- };
- var TEXT_TRANSFORM;
- (function (TEXT_TRANSFORM) {
- TEXT_TRANSFORM[TEXT_TRANSFORM["NONE"] = 0] = "NONE";
- TEXT_TRANSFORM[TEXT_TRANSFORM["LOWERCASE"] = 1] = "LOWERCASE";
- TEXT_TRANSFORM[TEXT_TRANSFORM["UPPERCASE"] = 2] = "UPPERCASE";
- TEXT_TRANSFORM[TEXT_TRANSFORM["CAPITALIZE"] = 3] = "CAPITALIZE";
- })(TEXT_TRANSFORM || (TEXT_TRANSFORM = {}));
- var textTransform = {
- name: 'text-transform',
- initialValue: 'none',
- prefix: false,
- type: PropertyDescriptorParsingType.IDENT_VALUE,
- parse: function (textTransform) {
- switch (textTransform) {
- case 'uppercase':
- return TEXT_TRANSFORM.UPPERCASE;
- case 'lowercase':
- return TEXT_TRANSFORM.LOWERCASE;
- case 'capitalize':
- return TEXT_TRANSFORM.CAPITALIZE;
- }
- return TEXT_TRANSFORM.NONE;
- }
- };
- var transform = {
- name: 'transform',
- initialValue: 'none',
- prefix: true,
- type: PropertyDescriptorParsingType.VALUE,
- parse: function (token) {
- if (token.type === TokenType.IDENT_TOKEN && token.value === 'none') {
- return null;
- }
- if (token.type === TokenType.FUNCTION) {
- var transformFunction = SUPPORTED_TRANSFORM_FUNCTIONS[token.name];
- if (typeof transformFunction === 'undefined') {
- throw new Error("Attempting to parse an unsupported transform function \"" + token.name + "\"");
- }
- return transformFunction(token.values);
- }
- return null;
- }
- };
- var matrix = function (args) {
- var values = args.filter(function (arg) { return arg.type === TokenType.NUMBER_TOKEN; }).map(function (arg) { return arg.number; });
- return values.length === 6 ? values : null;
- };
- // doesn't support 3D transforms at the moment
- var matrix3d = function (args) {
- var values = args.filter(function (arg) { return arg.type === TokenType.NUMBER_TOKEN; }).map(function (arg) { return arg.number; });
- var a1 = values[0], b1 = values[1], _a = values[2], _b = values[3], a2 = values[4], b2 = values[5], _c = values[6], _d = values[7], _e = values[8], _f = values[9], _g = values[10], _h = values[11], a4 = values[12], b4 = values[13], _j = values[14], _k = values[15];
- return values.length === 16 ? [a1, b1, a2, b2, a4, b4] : null;
- };
- var SUPPORTED_TRANSFORM_FUNCTIONS = {
- matrix: matrix,
- matrix3d: matrix3d
- };
- var DEFAULT_VALUE = {
- type: TokenType.PERCENTAGE_TOKEN,
- number: 50,
- flags: FLAG_INTEGER
- };
- var DEFAULT = [DEFAULT_VALUE, DEFAULT_VALUE];
- var transformOrigin = {
- name: 'transform-origin',
- initialValue: '50% 50%',
- prefix: true,
- type: PropertyDescriptorParsingType.LIST,
- parse: function (tokens) {
- var origins = tokens.filter(isLengthPercentage);
- if (origins.length !== 2) {
- return DEFAULT;
- }
- return [origins[0], origins[1]];
- }
- };
- var VISIBILITY;
- (function (VISIBILITY) {
- VISIBILITY[VISIBILITY["VISIBLE"] = 0] = "VISIBLE";
- VISIBILITY[VISIBILITY["HIDDEN"] = 1] = "HIDDEN";
- VISIBILITY[VISIBILITY["COLLAPSE"] = 2] = "COLLAPSE";
- })(VISIBILITY || (VISIBILITY = {}));
- var visibility = {
- name: 'visible',
- initialValue: 'none',
- prefix: false,
- type: PropertyDescriptorParsingType.IDENT_VALUE,
- parse: function (visibility) {
- switch (visibility) {
- case 'hidden':
- return VISIBILITY.HIDDEN;
- case 'collapse':
- return VISIBILITY.COLLAPSE;
- case 'visible':
- default:
- return VISIBILITY.VISIBLE;
- }
- }
- };
- var WORD_BREAK;
- (function (WORD_BREAK) {
- WORD_BREAK["NORMAL"] = "normal";
- WORD_BREAK["BREAK_ALL"] = "break-all";
- WORD_BREAK["KEEP_ALL"] = "keep-all";
- })(WORD_BREAK || (WORD_BREAK = {}));
- var wordBreak = {
- name: 'word-break',
- initialValue: 'normal',
- prefix: false,
- type: PropertyDescriptorParsingType.IDENT_VALUE,
- parse: function (wordBreak) {
- switch (wordBreak) {
- case 'break-all':
- return WORD_BREAK.BREAK_ALL;
- case 'keep-all':
- return WORD_BREAK.KEEP_ALL;
- case 'normal':
- default:
- return WORD_BREAK.NORMAL;
- }
- }
- };
- var zIndex = {
- name: 'z-index',
- initialValue: 'auto',
- prefix: false,
- type: PropertyDescriptorParsingType.VALUE,
- parse: function (token) {
- if (token.type === TokenType.IDENT_TOKEN) {
- return { auto: true, order: 0 };
- }
- if (isNumberToken(token)) {
- return { auto: false, order: token.number };
- }
- throw new Error("Invalid z-index number parsed");
- }
- };
- var opacity = {
- name: 'opacity',
- initialValue: '1',
- type: PropertyDescriptorParsingType.VALUE,
- prefix: false,
- parse: function (token) {
- if (isNumberToken(token)) {
- return token.number;
- }
- return 1;
- }
- };
- var textDecorationColor = {
- name: "text-decoration-color",
- initialValue: 'transparent',
- prefix: false,
- type: PropertyDescriptorParsingType.TYPE_VALUE,
- format: 'color'
- };
- var textDecorationLine = {
- name: 'text-decoration-line',
- initialValue: 'none',
- prefix: false,
- type: PropertyDescriptorParsingType.LIST,
- parse: function (tokens) {
- return tokens
- .filter(isIdentToken)
- .map(function (token) {
- switch (token.value) {
- case 'underline':
- return 1 /* UNDERLINE */;
- case 'overline':
- return 2 /* OVERLINE */;
- case 'line-through':
- return 3 /* LINE_THROUGH */;
- case 'none':
- return 4 /* BLINK */;
- }
- return 0 /* NONE */;
- })
- .filter(function (line) { return line !== 0 /* NONE */; });
- }
- };
- var fontFamily = {
- name: "font-family",
- initialValue: '',
- prefix: false,
- type: PropertyDescriptorParsingType.LIST,
- parse: function (tokens) {
- var accumulator = [];
- var results = [];
- tokens.forEach(function (token) {
- switch (token.type) {
- case TokenType.IDENT_TOKEN:
- case TokenType.STRING_TOKEN:
- accumulator.push(token.value);
- break;
- case TokenType.NUMBER_TOKEN:
- accumulator.push(token.number.toString());
- break;
- case TokenType.COMMA_TOKEN:
- results.push(accumulator.join(' '));
- accumulator.length = 0;
- break;
- }
- });
- if (accumulator.length) {
- results.push(accumulator.join(' '));
- }
- return results.map(function (result) { return (result.indexOf(' ') === -1 ? result : "'" + result + "'"); });
- }
- };
- var fontSize = {
- name: "font-size",
- initialValue: '0',
- prefix: false,
- type: PropertyDescriptorParsingType.TYPE_VALUE,
- format: 'length'
- };
- var fontWeight = {
- name: 'font-weight',
- initialValue: 'normal',
- type: PropertyDescriptorParsingType.VALUE,
- prefix: false,
- parse: function (token) {
- if (isNumberToken(token)) {
- return token.number;
- }
- if (isIdentToken(token)) {
- switch (token.value) {
- case 'bold':
- return 700;
- case 'normal':
- default:
- return 400;
- }
- }
- return 400;
- }
- };
- var fontVariant = {
- name: 'font-variant',
- initialValue: 'none',
- type: PropertyDescriptorParsingType.LIST,
- prefix: false,
- parse: function (tokens) {
- return tokens.filter(isIdentToken).map(function (token) { return token.value; });
- }
- };
- var FONT_STYLE;
- (function (FONT_STYLE) {
- FONT_STYLE["NORMAL"] = "normal";
- FONT_STYLE["ITALIC"] = "italic";
- FONT_STYLE["OBLIQUE"] = "oblique";
- })(FONT_STYLE || (FONT_STYLE = {}));
- var fontStyle = {
- name: 'font-style',
- initialValue: 'normal',
- prefix: false,
- type: PropertyDescriptorParsingType.IDENT_VALUE,
- parse: function (overflow) {
- switch (overflow) {
- case 'oblique':
- return FONT_STYLE.OBLIQUE;
- case 'italic':
- return FONT_STYLE.ITALIC;
- case 'normal':
- default:
- return FONT_STYLE.NORMAL;
- }
- }
- };
- var contains = function (bit, value) { return (bit & value) !== 0; };
- var content = {
- name: 'content',
- initialValue: 'none',
- type: PropertyDescriptorParsingType.LIST,
- prefix: false,
- parse: function (tokens) {
- if (tokens.length === 0) {
- return [];
- }
- var first = tokens[0];
- if (first.type === TokenType.IDENT_TOKEN && first.value === 'none') {
- return [];
- }
- return tokens;
- }
- };
- var counterIncrement = {
- name: 'counter-increment',
- initialValue: 'none',
- prefix: true,
- type: PropertyDescriptorParsingType.LIST,
- parse: function (tokens) {
- if (tokens.length === 0) {
- return null;
- }
- var first = tokens[0];
- if (first.type === TokenType.IDENT_TOKEN && first.value === 'none') {
- return null;
- }
- var increments = [];
- var filtered = tokens.filter(nonWhiteSpace);
- for (var i = 0; i < filtered.length; i++) {
- var counter = filtered[i];
- var next = filtered[i + 1];
- if (counter.type === TokenType.IDENT_TOKEN) {
- var increment = next && isNumberToken(next) ? next.number : 1;
- increments.push({ counter: counter.value, increment: increment });
- }
- }
- return increments;
- }
- };
- var counterReset = {
- name: 'counter-reset',
- initialValue: 'none',
- prefix: true,
- type: PropertyDescriptorParsingType.LIST,
- parse: function (tokens) {
- if (tokens.length === 0) {
- return [];
- }
- var resets = [];
- var filtered = tokens.filter(nonWhiteSpace);
- for (var i = 0; i < filtered.length; i++) {
- var counter = filtered[i];
- var next = filtered[i + 1];
- if (isIdentToken(counter) && counter.value !== 'none') {
- var reset = next && isNumberToken(next) ? next.number : 0;
- resets.push({ counter: counter.value, reset: reset });
- }
- }
- return resets;
- }
- };
- var quotes = {
- name: 'quotes',
- initialValue: 'none',
- prefix: true,
- type: PropertyDescriptorParsingType.LIST,
- parse: function (tokens) {
- if (tokens.length === 0) {
- return null;
- }
- var first = tokens[0];
- if (first.type === TokenType.IDENT_TOKEN && first.value === 'none') {
- return null;
- }
- var quotes = [];
- var filtered = tokens.filter(isStringToken);
- if (filtered.length % 2 !== 0) {
- return null;
- }
- for (var i = 0; i < filtered.length; i += 2) {
- var open_1 = filtered[i].value;
- var close_1 = filtered[i + 1].value;
- quotes.push({ open: open_1, close: close_1 });
- }
- return quotes;
- }
- };
- var getQuote = function (quotes, depth, open) {
- if (!quotes) {
- return '';
- }
- var quote = quotes[Math.min(depth, quotes.length - 1)];
- if (!quote) {
- return '';
- }
- return open ? quote.open : quote.close;
- };
- var boxShadow = {
- name: 'box-shadow',
- initialValue: 'none',
- type: PropertyDescriptorParsingType.LIST,
- prefix: false,
- parse: function (tokens) {
- if (tokens.length === 1 && isIdentWithValue(tokens[0], 'none')) {
- return [];
- }
- return parseFunctionArgs(tokens).map(function (values) {
- var shadow = {
- color: 0x000000ff,
- offsetX: ZERO_LENGTH,
- offsetY: ZERO_LENGTH,
- blur: ZERO_LENGTH,
- spread: ZERO_LENGTH,
- inset: false
- };
- var c = 0;
- for (var i = 0; i < values.length; i++) {
- var token = values[i];
- if (isIdentWithValue(token, 'inset')) {
- shadow.inset = true;
- }
- else if (isLength(token)) {
- if (c === 0) {
- shadow.offsetX = token;
- }
- else if (c === 1) {
- shadow.offsetY = token;
- }
- else if (c === 2) {
- shadow.blur = token;
- }
- else {
- shadow.spread = token;
- }
- c++;
- }
- else {
- shadow.color = color.parse(token);
- }
- }
- return shadow;
- });
- }
- };
- var CSSParsedDeclaration = /** @class */ (function () {
- function CSSParsedDeclaration(declaration) {
- this.backgroundClip = parse(backgroundClip, declaration.backgroundClip);
- this.backgroundColor = parse(backgroundColor, declaration.backgroundColor);
- this.backgroundImage = parse(backgroundImage, declaration.backgroundImage);
- this.backgroundOrigin = parse(backgroundOrigin, declaration.backgroundOrigin);
- this.backgroundPosition = parse(backgroundPosition, declaration.backgroundPosition);
- this.backgroundRepeat = parse(backgroundRepeat, declaration.backgroundRepeat);
- this.backgroundSize = parse(backgroundSize, declaration.backgroundSize);
- this.borderTopColor = parse(borderTopColor, declaration.borderTopColor);
- this.borderRightColor = parse(borderRightColor, declaration.borderRightColor);
- this.borderBottomColor = parse(borderBottomColor, declaration.borderBottomColor);
- this.borderLeftColor = parse(borderLeftColor, declaration.borderLeftColor);
- this.borderTopLeftRadius = parse(borderTopLeftRadius, declaration.borderTopLeftRadius);
- this.borderTopRightRadius = parse(borderTopRightRadius, declaration.borderTopRightRadius);
- this.borderBottomRightRadius = parse(borderBottomRightRadius, declaration.borderBottomRightRadius);
- this.borderBottomLeftRadius = parse(borderBottomLeftRadius, declaration.borderBottomLeftRadius);
- this.borderTopStyle = parse(borderTopStyle, declaration.borderTopStyle);
- this.borderRightStyle = parse(borderRightStyle, declaration.borderRightStyle);
- this.borderBottomStyle = parse(borderBottomStyle, declaration.borderBottomStyle);
- this.borderLeftStyle = parse(borderLeftStyle, declaration.borderLeftStyle);
- this.borderTopWidth = parse(borderTopWidth, declaration.borderTopWidth);
- this.borderRightWidth = parse(borderRightWidth, declaration.borderRightWidth);
- this.borderBottomWidth = parse(borderBottomWidth, declaration.borderBottomWidth);
- this.borderLeftWidth = parse(borderLeftWidth, declaration.borderLeftWidth);
- this.boxShadow = parse(boxShadow, declaration.boxShadow);
- this.color = parse(color$1, declaration.color);
- this.display = parse(display, declaration.display);
- this.float = parse(float, declaration.cssFloat);
- this.fontFamily = parse(fontFamily, declaration.fontFamily);
- this.fontSize = parse(fontSize, declaration.fontSize);
- this.fontStyle = parse(fontStyle, declaration.fontStyle);
- this.fontVariant = parse(fontVariant, declaration.fontVariant);
- this.fontWeight = parse(fontWeight, declaration.fontWeight);
- this.letterSpacing = parse(letterSpacing, declaration.letterSpacing);
- this.lineBreak = parse(lineBreak, declaration.lineBreak);
- this.lineHeight = parse(lineHeight, declaration.lineHeight);
- this.listStyleImage = parse(listStyleImage, declaration.listStyleImage);
- this.listStylePosition = parse(listStylePosition, declaration.listStylePosition);
- this.listStyleType = parse(listStyleType, declaration.listStyleType);
- this.marginTop = parse(marginTop, declaration.marginTop);
- this.marginRight = parse(marginRight, declaration.marginRight);
- this.marginBottom = parse(marginBottom, declaration.marginBottom);
- this.marginLeft = parse(marginLeft, declaration.marginLeft);
- this.opacity = parse(opacity, declaration.opacity);
- var overflowTuple = parse(overflow, declaration.overflow);
- this.overflowX = overflowTuple[0];
- this.overflowY = overflowTuple[overflowTuple.length > 1 ? 1 : 0];
- this.overflowWrap = parse(overflowWrap, declaration.overflowWrap);
- this.paddingTop = parse(paddingTop, declaration.paddingTop);
- this.paddingRight = parse(paddingRight, declaration.paddingRight);
- this.paddingBottom = parse(paddingBottom, declaration.paddingBottom);
- this.paddingLeft = parse(paddingLeft, declaration.paddingLeft);
- this.position = parse(position, declaration.position);
- this.textAlign = parse(textAlign, declaration.textAlign);
- this.textDecorationColor = parse(textDecorationColor, declaration.textDecorationColor || declaration.color);
- this.textDecorationLine = parse(textDecorationLine, declaration.textDecorationLine);
- this.textShadow = parse(textShadow, declaration.textShadow);
- this.textTransform = parse(textTransform, declaration.textTransform);
- this.transform = parse(transform, declaration.transform);
- this.transformOrigin = parse(transformOrigin, declaration.transformOrigin);
- this.visibility = parse(visibility, declaration.visibility);
- this.wordBreak = parse(wordBreak, declaration.wordBreak);
- this.zIndex = parse(zIndex, declaration.zIndex);
- }
- CSSParsedDeclaration.prototype.isVisible = function () {
- return this.display > 0 && this.opacity > 0 && this.visibility === VISIBILITY.VISIBLE;
- };
- CSSParsedDeclaration.prototype.isTransparent = function () {
- return isTransparent(this.backgroundColor);
- };
- CSSParsedDeclaration.prototype.isTransformed = function () {
- return this.transform !== null;
- };
- CSSParsedDeclaration.prototype.isPositioned = function () {
- return this.position !== POSITION.STATIC;
- };
- CSSParsedDeclaration.prototype.isPositionedWithZIndex = function () {
- return this.isPositioned() && !this.zIndex.auto;
- };
- CSSParsedDeclaration.prototype.isFloating = function () {
- return this.float !== FLOAT.NONE;
- };
- CSSParsedDeclaration.prototype.isInlineLevel = function () {
- return (contains(this.display, 4 /* INLINE */) ||
- contains(this.display, 33554432 /* INLINE_BLOCK */) ||
- contains(this.display, 268435456 /* INLINE_FLEX */) ||
- contains(this.display, 536870912 /* INLINE_GRID */) ||
- contains(this.display, 67108864 /* INLINE_LIST_ITEM */) ||
- contains(this.display, 134217728 /* INLINE_TABLE */));
- };
- return CSSParsedDeclaration;
- }());
- var CSSParsedPseudoDeclaration = /** @class */ (function () {
- function CSSParsedPseudoDeclaration(declaration) {
- this.content = parse(content, declaration.content);
- this.quotes = parse(quotes, declaration.quotes);
- }
- return CSSParsedPseudoDeclaration;
- }());
- var CSSParsedCounterDeclaration = /** @class */ (function () {
- function CSSParsedCounterDeclaration(declaration) {
- this.counterIncrement = parse(counterIncrement, declaration.counterIncrement);
- this.counterReset = parse(counterReset, declaration.counterReset);
- }
- return CSSParsedCounterDeclaration;
- }());
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- var parse = function (descriptor, style) {
- var tokenizer = new Tokenizer();
- var value = style !== null && typeof style !== 'undefined' ? style.toString() : descriptor.initialValue;
- tokenizer.write(value);
- var parser = new Parser(tokenizer.read());
- switch (descriptor.type) {
- case PropertyDescriptorParsingType.IDENT_VALUE:
- var token = parser.parseComponentValue();
- return descriptor.parse(isIdentToken(token) ? token.value : descriptor.initialValue);
- case PropertyDescriptorParsingType.VALUE:
- return descriptor.parse(parser.parseComponentValue());
- case PropertyDescriptorParsingType.LIST:
- return descriptor.parse(parser.parseComponentValues());
- case PropertyDescriptorParsingType.TOKEN_VALUE:
- return parser.parseComponentValue();
- case PropertyDescriptorParsingType.TYPE_VALUE:
- switch (descriptor.format) {
- case 'angle':
- return angle.parse(parser.parseComponentValue());
- case 'color':
- return color.parse(parser.parseComponentValue());
- case 'image':
- return image.parse(parser.parseComponentValue());
- case 'length':
- var length_1 = parser.parseComponentValue();
- return isLength(length_1) ? length_1 : ZERO_LENGTH;
- case 'length-percentage':
- var value_1 = parser.parseComponentValue();
- return isLengthPercentage(value_1) ? value_1 : ZERO_LENGTH;
- }
- }
- throw new Error("Attempting to parse unsupported css format type " + descriptor.format);
- };
- var ElementContainer = /** @class */ (function () {
- function ElementContainer(element) {
- this.styles = new CSSParsedDeclaration(window.getComputedStyle(element, null));
- this.textNodes = [];
- this.elements = [];
- if (this.styles.transform !== null && isHTMLElementNode(element)) {
- // getBoundingClientRect takes transforms into account
- element.style.transform = 'none';
- }
- this.bounds = parseBounds(element);
- this.flags = 0;
- }
- return ElementContainer;
- }());
- var TextBounds = /** @class */ (function () {
- function TextBounds(text, bounds) {
- this.text = text;
- this.bounds = bounds;
- }
- return TextBounds;
- }());
- var parseTextBounds = function (value, styles, node) {
- var textList = breakText(value, styles);
- var textBounds = [];
- var offset = 0;
- textList.forEach(function (text) {
- if (styles.textDecorationLine.length || text.trim().length > 0) {
- if (FEATURES.SUPPORT_RANGE_BOUNDS) {
- textBounds.push(new TextBounds(text, getRangeBounds(node, offset, text.length)));
- }
- else {
- var replacementNode = node.splitText(text.length);
- textBounds.push(new TextBounds(text, getWrapperBounds(node)));
- node = replacementNode;
- }
- }
- else if (!FEATURES.SUPPORT_RANGE_BOUNDS) {
- node = node.splitText(text.length);
- }
- offset += text.length;
- });
- return textBounds;
- };
- var getWrapperBounds = function (node) {
- var ownerDocument = node.ownerDocument;
- if (ownerDocument) {
- var wrapper = ownerDocument.createElement('html2canvaswrapper');
- wrapper.appendChild(node.cloneNode(true));
- var parentNode = node.parentNode;
- if (parentNode) {
- parentNode.replaceChild(wrapper, node);
- var bounds = parseBounds(wrapper);
- if (wrapper.firstChild) {
- parentNode.replaceChild(wrapper.firstChild, wrapper);
- }
- return bounds;
- }
- }
- return new Bounds(0, 0, 0, 0);
- };
- var getRangeBounds = function (node, offset, length) {
- var ownerDocument = node.ownerDocument;
- if (!ownerDocument) {
- throw new Error('Node has no owner document');
- }
- var range = ownerDocument.createRange();
- range.setStart(node, offset);
- range.setEnd(node, offset + length);
- return Bounds.fromClientRect(range.getBoundingClientRect());
- };
- var breakText = function (value, styles) {
- return styles.letterSpacing !== 0 ? toCodePoints(value).map(function (i) { return fromCodePoint(i); }) : breakWords(value, styles);
- };
- var breakWords = function (str, styles) {
- var breaker = LineBreaker(str, {
- lineBreak: styles.lineBreak,
- wordBreak: styles.overflowWrap === OVERFLOW_WRAP.BREAK_WORD ? 'break-word' : styles.wordBreak
- });
- var words = [];
- var bk;
- while (!(bk = breaker.next()).done) {
- if (bk.value) {
- words.push(bk.value.slice());
- }
- }
- return words;
- };
- var TextContainer = /** @class */ (function () {
- function TextContainer(node, styles) {
- this.text = transform$1(node.data, styles.textTransform);
- this.textBounds = parseTextBounds(this.text, styles, node);
- }
- return TextContainer;
- }());
- var transform$1 = function (text, transform) {
- switch (transform) {
- case TEXT_TRANSFORM.LOWERCASE:
- return text.toLowerCase();
- case TEXT_TRANSFORM.CAPITALIZE:
- return text.replace(CAPITALIZE, capitalize);
- case TEXT_TRANSFORM.UPPERCASE:
- return text.toUpperCase();
- default:
- return text;
- }
- };
- var CAPITALIZE = /(^|\s|:|-|\(|\))([a-z])/g;
- var capitalize = function (m, p1, p2) {
- if (m.length > 0) {
- return p1 + p2.toUpperCase();
- }
- return m;
- };
- var ImageElementContainer = /** @class */ (function (_super) {
- __extends(ImageElementContainer, _super);
- function ImageElementContainer(img) {
- var _this = _super.call(this, img) || this;
- _this.src = img.currentSrc || img.src;
- _this.intrinsicWidth = img.naturalWidth;
- _this.intrinsicHeight = img.naturalHeight;
- CacheStorage.getInstance().addImage(_this.src);
- return _this;
- }
- return ImageElementContainer;
- }(ElementContainer));
- var CanvasElementContainer = /** @class */ (function (_super) {
- __extends(CanvasElementContainer, _super);
- function CanvasElementContainer(canvas) {
- var _this = _super.call(this, canvas) || this;
- _this.canvas = canvas;
- _this.intrinsicWidth = canvas.width;
- _this.intrinsicHeight = canvas.height;
- return _this;
- }
- return CanvasElementContainer;
- }(ElementContainer));
- var SVGElementContainer = /** @class */ (function (_super) {
- __extends(SVGElementContainer, _super);
- function SVGElementContainer(img) {
- var _this = _super.call(this, img) || this;
- var s = new XMLSerializer();
- _this.svg = "data:image/svg+xml," + encodeURIComponent(s.serializeToString(img));
- _this.intrinsicWidth = img.width.baseVal.value;
- _this.intrinsicHeight = img.height.baseVal.value;
- CacheStorage.getInstance().addImage(_this.svg);
- return _this;
- }
- return SVGElementContainer;
- }(ElementContainer));
- var LIElementContainer = /** @class */ (function (_super) {
- __extends(LIElementContainer, _super);
- function LIElementContainer(element) {
- var _this = _super.call(this, element) || this;
- _this.value = element.value;
- return _this;
- }
- return LIElementContainer;
- }(ElementContainer));
- var OLElementContainer = /** @class */ (function (_super) {
- __extends(OLElementContainer, _super);
- function OLElementContainer(element) {
- var _this = _super.call(this, element) || this;
- _this.start = element.start;
- _this.reversed = typeof element.reversed === 'boolean' && element.reversed === true;
- return _this;
- }
- return OLElementContainer;
- }(ElementContainer));
- var CHECKBOX_BORDER_RADIUS = [
- {
- type: TokenType.DIMENSION_TOKEN,
- flags: 0,
- unit: 'px',
- number: 3
- }
- ];
- var RADIO_BORDER_RADIUS = [
- {
- type: TokenType.PERCENTAGE_TOKEN,
- flags: 0,
- number: 50
- }
- ];
- var reformatInputBounds = function (bounds) {
- if (bounds.width > bounds.height) {
- return new Bounds(bounds.left + (bounds.width - bounds.height) / 2, bounds.top, bounds.height, bounds.height);
- }
- else if (bounds.width < bounds.height) {
- return new Bounds(bounds.left, bounds.top + (bounds.height - bounds.width) / 2, bounds.width, bounds.width);
- }
- return bounds;
- };
- var getInputValue = function (node) {
- var value = node.type === PASSWORD ? new Array(node.value.length + 1).join('\u2022') : node.value;
- return value.length === 0 ? node.placeholder || '' : value;
- };
- var CHECKBOX = 'checkbox';
- var RADIO = 'radio';
- var PASSWORD = 'password';
- var INPUT_COLOR = 0x2a2a2aff;
- var InputElementContainer = /** @class */ (function (_super) {
- __extends(InputElementContainer, _super);
- function InputElementContainer(input) {
- var _this = _super.call(this, input) || this;
- _this.type = input.type.toLowerCase();
- _this.checked = input.checked;
- _this.value = getInputValue(input);
- if (_this.type === CHECKBOX || _this.type === RADIO) {
- _this.styles.backgroundColor = 0xdededeff;
- _this.styles.borderTopColor = _this.styles.borderRightColor = _this.styles.borderBottomColor = _this.styles.borderLeftColor = 0xa5a5a5ff;
- _this.styles.borderTopWidth = _this.styles.borderRightWidth = _this.styles.borderBottomWidth = _this.styles.borderLeftWidth = 1;
- _this.styles.borderTopStyle = _this.styles.borderRightStyle = _this.styles.borderBottomStyle = _this.styles.borderLeftStyle =
- BORDER_STYLE.SOLID;
- _this.styles.backgroundClip = [BACKGROUND_CLIP.BORDER_BOX];
- _this.styles.backgroundOrigin = [0 /* BORDER_BOX */];
- _this.bounds = reformatInputBounds(_this.bounds);
- }
- switch (_this.type) {
- case CHECKBOX:
- _this.styles.borderTopRightRadius = _this.styles.borderTopLeftRadius = _this.styles.borderBottomRightRadius = _this.styles.borderBottomLeftRadius = CHECKBOX_BORDER_RADIUS;
- break;
- case RADIO:
- _this.styles.borderTopRightRadius = _this.styles.borderTopLeftRadius = _this.styles.borderBottomRightRadius = _this.styles.borderBottomLeftRadius = RADIO_BORDER_RADIUS;
- break;
- }
- return _this;
- }
- return InputElementContainer;
- }(ElementContainer));
- var SelectElementContainer = /** @class */ (function (_super) {
- __extends(SelectElementContainer, _super);
- function SelectElementContainer(element) {
- var _this = _super.call(this, element) || this;
- var option = element.options[element.selectedIndex || 0];
- _this.value = option ? option.text || '' : '';
- return _this;
- }
- return SelectElementContainer;
- }(ElementContainer));
- var TextareaElementContainer = /** @class */ (function (_super) {
- __extends(TextareaElementContainer, _super);
- function TextareaElementContainer(element) {
- var _this = _super.call(this, element) || this;
- _this.value = element.value;
- return _this;
- }
- return TextareaElementContainer;
- }(ElementContainer));
- var parseColor = function (value) { return color.parse(Parser.create(value).parseComponentValue()); };
- var IFrameElementContainer = /** @class */ (function (_super) {
- __extends(IFrameElementContainer, _super);
- function IFrameElementContainer(iframe) {
- var _this = _super.call(this, iframe) || this;
- _this.src = iframe.src;
- _this.width = parseInt(iframe.width, 10) || 0;
- _this.height = parseInt(iframe.height, 10) || 0;
- _this.backgroundColor = _this.styles.backgroundColor;
- try {
- if (iframe.contentWindow &&
- iframe.contentWindow.document &&
- iframe.contentWindow.document.documentElement) {
- _this.tree = parseTree(iframe.contentWindow.document.documentElement);
- // http://www.w3.org/TR/css3-background/#special-backgrounds
- var documentBackgroundColor = iframe.contentWindow.document.documentElement
- ? parseColor(getComputedStyle(iframe.contentWindow.document.documentElement)
- .backgroundColor)
- : COLORS.TRANSPARENT;
- var bodyBackgroundColor = iframe.contentWindow.document.body
- ? parseColor(getComputedStyle(iframe.contentWindow.document.body).backgroundColor)
- : COLORS.TRANSPARENT;
- _this.backgroundColor = isTransparent(documentBackgroundColor)
- ? isTransparent(bodyBackgroundColor)
- ? _this.styles.backgroundColor
- : bodyBackgroundColor
- : documentBackgroundColor;
- }
- }
- catch (e) { }
- return _this;
- }
- return IFrameElementContainer;
- }(ElementContainer));
- var LIST_OWNERS = ['OL', 'UL', 'MENU'];
- var parseNodeTree = function (node, parent, root) {
- for (var childNode = node.firstChild, nextNode = void 0; childNode; childNode = nextNode) {
- nextNode = childNode.nextSibling;
- if (isTextNode(childNode) && childNode.data.trim().length > 0) {
- parent.textNodes.push(new TextContainer(childNode, parent.styles));
- }
- else if (isElementNode(childNode)) {
- var container = createContainer(childNode);
- if (container.styles.isVisible()) {
- if (createsRealStackingContext(childNode, container, root)) {
- container.flags |= 4 /* CREATES_REAL_STACKING_CONTEXT */;
- }
- else if (createsStackingContext(container.styles)) {
- container.flags |= 2 /* CREATES_STACKING_CONTEXT */;
- }
- if (LIST_OWNERS.indexOf(childNode.tagName) !== -1) {
- container.flags |= 8 /* IS_LIST_OWNER */;
- }
- parent.elements.push(container);
- if (!isTextareaElement(childNode) && !isSVGElement(childNode) && !isSelectElement(childNode)) {
- parseNodeTree(childNode, container, root);
- }
- }
- }
- }
- };
- var createContainer = function (element) {
- if (isImageElement(element)) {
- return new ImageElementContainer(element);
- }
- if (isCanvasElement(element)) {
- return new CanvasElementContainer(element);
- }
- if (isSVGElement(element)) {
- return new SVGElementContainer(element);
- }
- if (isLIElement(element)) {
- return new LIElementContainer(element);
- }
- if (isOLElement(element)) {
- return new OLElementContainer(element);
- }
- if (isInputElement(element)) {
- return new InputElementContainer(element);
- }
- if (isSelectElement(element)) {
- return new SelectElementContainer(element);
- }
- if (isTextareaElement(element)) {
- return new TextareaElementContainer(element);
- }
- if (isIFrameElement(element)) {
- return new IFrameElementContainer(element);
- }
- return new ElementContainer(element);
- };
- var parseTree = function (element) {
- var container = createContainer(element);
- container.flags |= 4 /* CREATES_REAL_STACKING_CONTEXT */;
- parseNodeTree(element, container, container);
- return container;
- };
- var createsRealStackingContext = function (node, container, root) {
- return (container.styles.isPositionedWithZIndex() ||
- container.styles.opacity < 1 ||
- container.styles.isTransformed() ||
- (isBodyElement(node) && root.styles.isTransparent()));
- };
- var createsStackingContext = function (styles) { return styles.isPositioned() || styles.isFloating(); };
- var isTextNode = function (node) { return node.nodeType === Node.TEXT_NODE; };
- var isElementNode = function (node) { return node.nodeType === Node.ELEMENT_NODE; };
- var isHTMLElementNode = function (node) {
- return isElementNode(node) && typeof node.style !== 'undefined' && !isSVGElementNode(node);
- };
- var isSVGElementNode = function (element) {
- return typeof element.className === 'object';
- };
- var isLIElement = function (node) { return node.tagName === 'LI'; };
- var isOLElement = function (node) { return node.tagName === 'OL'; };
- var isInputElement = function (node) { return node.tagName === 'INPUT'; };
- var isHTMLElement = function (node) { return node.tagName === 'HTML'; };
- var isSVGElement = function (node) { return node.tagName === 'svg'; };
- var isBodyElement = function (node) { return node.tagName === 'BODY'; };
- var isCanvasElement = function (node) { return node.tagName === 'CANVAS'; };
- var isImageElement = function (node) { return node.tagName === 'IMG'; };
- var isIFrameElement = function (node) { return node.tagName === 'IFRAME'; };
- var isStyleElement = function (node) { return node.tagName === 'STYLE'; };
- var isScriptElement = function (node) { return node.tagName === 'SCRIPT'; };
- var isTextareaElement = function (node) { return node.tagName === 'TEXTAREA'; };
- var isSelectElement = function (node) { return node.tagName === 'SELECT'; };
- var CounterState = /** @class */ (function () {
- function CounterState() {
- this.counters = {};
- }
- CounterState.prototype.getCounterValue = function (name) {
- var counter = this.counters[name];
- if (counter && counter.length) {
- return counter[counter.length - 1];
- }
- return 1;
- };
- CounterState.prototype.getCounterValues = function (name) {
- var counter = this.counters[name];
- return counter ? counter : [];
- };
- CounterState.prototype.pop = function (counters) {
- var _this = this;
- counters.forEach(function (counter) { return _this.counters[counter].pop(); });
- };
- CounterState.prototype.parse = function (style) {
- var _this = this;
- var counterIncrement = style.counterIncrement;
- var counterReset = style.counterReset;
- var canReset = true;
- if (counterIncrement !== null) {
- counterIncrement.forEach(function (entry) {
- var counter = _this.counters[entry.counter];
- if (counter && entry.increment !== 0) {
- canReset = false;
- counter[Math.max(0, counter.length - 1)] += entry.increment;
- }
- });
- }
- var counterNames = [];
- if (canReset) {
- counterReset.forEach(function (entry) {
- var counter = _this.counters[entry.counter];
- counterNames.push(entry.counter);
- if (!counter) {
- counter = _this.counters[entry.counter] = [];
- }
- counter.push(entry.reset);
- });
- }
- return counterNames;
- };
- return CounterState;
- }());
- var ROMAN_UPPER = {
- integers: [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1],
- values: ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
- };
- var ARMENIAN = {
- integers: [
- 9000,
- 8000,
- 7000,
- 6000,
- 5000,
- 4000,
- 3000,
- 2000,
- 1000,
- 900,
- 800,
- 700,
- 600,
- 500,
- 400,
- 300,
- 200,
- 100,
- 90,
- 80,
- 70,
- 60,
- 50,
- 40,
- 30,
- 20,
- 10,
- 9,
- 8,
- 7,
- 6,
- 5,
- 4,
- 3,
- 2,
- 1
- ],
- values: [
- 'Ք',
- 'Փ',
- 'Ւ',
- 'Ց',
- 'Ր',
- 'Տ',
- 'Վ',
- 'Ս',
- 'Ռ',
- 'Ջ',
- 'Պ',
- 'Չ',
- 'Ո',
- 'Շ',
- 'Ն',
- 'Յ',
- 'Մ',
- 'Ճ',
- 'Ղ',
- 'Ձ',
- 'Հ',
- 'Կ',
- 'Ծ',
- 'Խ',
- 'Լ',
- 'Ի',
- 'Ժ',
- 'Թ',
- 'Ը',
- 'Է',
- 'Զ',
- 'Ե',
- 'Դ',
- 'Գ',
- 'Բ',
- 'Ա'
- ]
- };
- var HEBREW = {
- integers: [
- 10000,
- 9000,
- 8000,
- 7000,
- 6000,
- 5000,
- 4000,
- 3000,
- 2000,
- 1000,
- 400,
- 300,
- 200,
- 100,
- 90,
- 80,
- 70,
- 60,
- 50,
- 40,
- 30,
- 20,
- 19,
- 18,
- 17,
- 16,
- 15,
- 10,
- 9,
- 8,
- 7,
- 6,
- 5,
- 4,
- 3,
- 2,
- 1
- ],
- values: [
- 'י׳',
- 'ט׳',
- 'ח׳',
- 'ז׳',
- 'ו׳',
- 'ה׳',
- 'ד׳',
- 'ג׳',
- 'ב׳',
- 'א׳',
- 'ת',
- 'ש',
- 'ר',
- 'ק',
- 'צ',
- 'פ',
- 'ע',
- 'ס',
- 'נ',
- 'מ',
- 'ל',
- 'כ',
- 'יט',
- 'יח',
- 'יז',
- 'טז',
- 'טו',
- 'י',
- 'ט',
- 'ח',
- 'ז',
- 'ו',
- 'ה',
- 'ד',
- 'ג',
- 'ב',
- 'א'
- ]
- };
- var GEORGIAN = {
- integers: [
- 10000,
- 9000,
- 8000,
- 7000,
- 6000,
- 5000,
- 4000,
- 3000,
- 2000,
- 1000,
- 900,
- 800,
- 700,
- 600,
- 500,
- 400,
- 300,
- 200,
- 100,
- 90,
- 80,
- 70,
- 60,
- 50,
- 40,
- 30,
- 20,
- 10,
- 9,
- 8,
- 7,
- 6,
- 5,
- 4,
- 3,
- 2,
- 1
- ],
- values: [
- 'ჵ',
- 'ჰ',
- 'ჯ',
- 'ჴ',
- 'ხ',
- 'ჭ',
- 'წ',
- 'ძ',
- 'ც',
- 'ჩ',
- 'შ',
- 'ყ',
- 'ღ',
- 'ქ',
- 'ფ',
- 'ჳ',
- 'ტ',
- 'ს',
- 'რ',
- 'ჟ',
- 'პ',
- 'ო',
- 'ჲ',
- 'ნ',
- 'მ',
- 'ლ',
- 'კ',
- 'ი',
- 'თ',
- 'ჱ',
- 'ზ',
- 'ვ',
- 'ე',
- 'დ',
- 'გ',
- 'ბ',
- 'ა'
- ]
- };
- var createAdditiveCounter = function (value, min, max, symbols, fallback, suffix) {
- if (value < min || value > max) {
- return createCounterText(value, fallback, suffix.length > 0);
- }
- return (symbols.integers.reduce(function (string, integer, index) {
- while (value >= integer) {
- value -= integer;
- string += symbols.values[index];
- }
- return string;
- }, '') + suffix);
- };
- var createCounterStyleWithSymbolResolver = function (value, codePointRangeLength, isNumeric, resolver) {
- var string = '';
- do {
- if (!isNumeric) {
- value--;
- }
- string = resolver(value) + string;
- value /= codePointRangeLength;
- } while (value * codePointRangeLength >= codePointRangeLength);
- return string;
- };
- var createCounterStyleFromRange = function (value, codePointRangeStart, codePointRangeEnd, isNumeric, suffix) {
- var codePointRangeLength = codePointRangeEnd - codePointRangeStart + 1;
- return ((value < 0 ? '-' : '') +
- (createCounterStyleWithSymbolResolver(Math.abs(value), codePointRangeLength, isNumeric, function (codePoint) {
- return fromCodePoint(Math.floor(codePoint % codePointRangeLength) + codePointRangeStart);
- }) +
- suffix));
- };
- var createCounterStyleFromSymbols = function (value, symbols, suffix) {
- if (suffix === void 0) { suffix = '. '; }
- var codePointRangeLength = symbols.length;
- return (createCounterStyleWithSymbolResolver(Math.abs(value), codePointRangeLength, false, function (codePoint) { return symbols[Math.floor(codePoint % codePointRangeLength)]; }) + suffix);
- };
- var CJK_ZEROS = 1 << 0;
- var CJK_TEN_COEFFICIENTS = 1 << 1;
- var CJK_TEN_HIGH_COEFFICIENTS = 1 << 2;
- var CJK_HUNDRED_COEFFICIENTS = 1 << 3;
- var createCJKCounter = function (value, numbers, multipliers, negativeSign, suffix, flags) {
- if (value < -9999 || value > 9999) {
- return createCounterText(value, LIST_STYLE_TYPE.CJK_DECIMAL, suffix.length > 0);
- }
- var tmp = Math.abs(value);
- var string = suffix;
- if (tmp === 0) {
- return numbers[0] + string;
- }
- for (var digit = 0; tmp > 0 && digit <= 4; digit++) {
- var coefficient = tmp % 10;
- if (coefficient === 0 && contains(flags, CJK_ZEROS) && string !== '') {
- string = numbers[coefficient] + string;
- }
- else if (coefficient > 1 ||
- (coefficient === 1 && digit === 0) ||
- (coefficient === 1 && digit === 1 && contains(flags, CJK_TEN_COEFFICIENTS)) ||
- (coefficient === 1 && digit === 1 && contains(flags, CJK_TEN_HIGH_COEFFICIENTS) && value > 100) ||
- (coefficient === 1 && digit > 1 && contains(flags, CJK_HUNDRED_COEFFICIENTS))) {
- string = numbers[coefficient] + (digit > 0 ? multipliers[digit - 1] : '') + string;
- }
- else if (coefficient === 1 && digit > 0) {
- string = multipliers[digit - 1] + string;
- }
- tmp = Math.floor(tmp / 10);
- }
- return (value < 0 ? negativeSign : '') + string;
- };
- var CHINESE_INFORMAL_MULTIPLIERS = '十百千萬';
- var CHINESE_FORMAL_MULTIPLIERS = '拾佰仟萬';
- var JAPANESE_NEGATIVE = 'マイナス';
- var KOREAN_NEGATIVE = '마이너스';
- var createCounterText = function (value, type, appendSuffix) {
- var defaultSuffix = appendSuffix ? '. ' : '';
- var cjkSuffix = appendSuffix ? '、' : '';
- var koreanSuffix = appendSuffix ? ', ' : '';
- var spaceSuffix = appendSuffix ? ' ' : '';
- switch (type) {
- case LIST_STYLE_TYPE.DISC:
- return '•' + spaceSuffix;
- case LIST_STYLE_TYPE.CIRCLE:
- return '◦' + spaceSuffix;
- case LIST_STYLE_TYPE.SQUARE:
- return '◾' + spaceSuffix;
- case LIST_STYLE_TYPE.DECIMAL_LEADING_ZERO:
- var string = createCounterStyleFromRange(value, 48, 57, true, defaultSuffix);
- return string.length < 4 ? "0" + string : string;
- case LIST_STYLE_TYPE.CJK_DECIMAL:
- return createCounterStyleFromSymbols(value, '〇一二三四五六七八九', cjkSuffix);
- case LIST_STYLE_TYPE.LOWER_ROMAN:
- return createAdditiveCounter(value, 1, 3999, ROMAN_UPPER, LIST_STYLE_TYPE.DECIMAL, defaultSuffix).toLowerCase();
- case LIST_STYLE_TYPE.UPPER_ROMAN:
- return createAdditiveCounter(value, 1, 3999, ROMAN_UPPER, LIST_STYLE_TYPE.DECIMAL, defaultSuffix);
- case LIST_STYLE_TYPE.LOWER_GREEK:
- return createCounterStyleFromRange(value, 945, 969, false, defaultSuffix);
- case LIST_STYLE_TYPE.LOWER_ALPHA:
- return createCounterStyleFromRange(value, 97, 122, false, defaultSuffix);
- case LIST_STYLE_TYPE.UPPER_ALPHA:
- return createCounterStyleFromRange(value, 65, 90, false, defaultSuffix);
- case LIST_STYLE_TYPE.ARABIC_INDIC:
- return createCounterStyleFromRange(value, 1632, 1641, true, defaultSuffix);
- case LIST_STYLE_TYPE.ARMENIAN:
- case LIST_STYLE_TYPE.UPPER_ARMENIAN:
- return createAdditiveCounter(value, 1, 9999, ARMENIAN, LIST_STYLE_TYPE.DECIMAL, defaultSuffix);
- case LIST_STYLE_TYPE.LOWER_ARMENIAN:
- return createAdditiveCounter(value, 1, 9999, ARMENIAN, LIST_STYLE_TYPE.DECIMAL, defaultSuffix).toLowerCase();
- case LIST_STYLE_TYPE.BENGALI:
- return createCounterStyleFromRange(value, 2534, 2543, true, defaultSuffix);
- case LIST_STYLE_TYPE.CAMBODIAN:
- case LIST_STYLE_TYPE.KHMER:
- return createCounterStyleFromRange(value, 6112, 6121, true, defaultSuffix);
- case LIST_STYLE_TYPE.CJK_EARTHLY_BRANCH:
- return createCounterStyleFromSymbols(value, '子丑寅卯辰巳午未申酉戌亥', cjkSuffix);
- case LIST_STYLE_TYPE.CJK_HEAVENLY_STEM:
- return createCounterStyleFromSymbols(value, '甲乙丙丁戊己庚辛壬癸', cjkSuffix);
- case LIST_STYLE_TYPE.CJK_IDEOGRAPHIC:
- case LIST_STYLE_TYPE.TRAD_CHINESE_INFORMAL:
- return createCJKCounter(value, '零一二三四五六七八九', CHINESE_INFORMAL_MULTIPLIERS, '負', cjkSuffix, CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS);
- case LIST_STYLE_TYPE.TRAD_CHINESE_FORMAL:
- return createCJKCounter(value, '零壹貳參肆伍陸柒捌玖', CHINESE_FORMAL_MULTIPLIERS, '負', cjkSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS);
- case LIST_STYLE_TYPE.SIMP_CHINESE_INFORMAL:
- return createCJKCounter(value, '零一二三四五六七八九', CHINESE_INFORMAL_MULTIPLIERS, '负', cjkSuffix, CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS);
- case LIST_STYLE_TYPE.SIMP_CHINESE_FORMAL:
- return createCJKCounter(value, '零壹贰叁肆伍陆柒捌玖', CHINESE_FORMAL_MULTIPLIERS, '负', cjkSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS);
- case LIST_STYLE_TYPE.JAPANESE_INFORMAL:
- return createCJKCounter(value, '〇一二三四五六七八九', '十百千万', JAPANESE_NEGATIVE, cjkSuffix, 0);
- case LIST_STYLE_TYPE.JAPANESE_FORMAL:
- return createCJKCounter(value, '零壱弐参四伍六七八九', '拾百千万', JAPANESE_NEGATIVE, cjkSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS);
- case LIST_STYLE_TYPE.KOREAN_HANGUL_FORMAL:
- return createCJKCounter(value, '영일이삼사오육칠팔구', '십백천만', KOREAN_NEGATIVE, koreanSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS);
- case LIST_STYLE_TYPE.KOREAN_HANJA_INFORMAL:
- return createCJKCounter(value, '零一二三四五六七八九', '十百千萬', KOREAN_NEGATIVE, koreanSuffix, 0);
- case LIST_STYLE_TYPE.KOREAN_HANJA_FORMAL:
- return createCJKCounter(value, '零壹貳參四五六七八九', '拾百千', KOREAN_NEGATIVE, koreanSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS);
- case LIST_STYLE_TYPE.DEVANAGARI:
- return createCounterStyleFromRange(value, 0x966, 0x96f, true, defaultSuffix);
- case LIST_STYLE_TYPE.GEORGIAN:
- return createAdditiveCounter(value, 1, 19999, GEORGIAN, LIST_STYLE_TYPE.DECIMAL, defaultSuffix);
- case LIST_STYLE_TYPE.GUJARATI:
- return createCounterStyleFromRange(value, 0xae6, 0xaef, true, defaultSuffix);
- case LIST_STYLE_TYPE.GURMUKHI:
- return createCounterStyleFromRange(value, 0xa66, 0xa6f, true, defaultSuffix);
- case LIST_STYLE_TYPE.HEBREW:
- return createAdditiveCounter(value, 1, 10999, HEBREW, LIST_STYLE_TYPE.DECIMAL, defaultSuffix);
- case LIST_STYLE_TYPE.HIRAGANA:
- return createCounterStyleFromSymbols(value, 'あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわゐゑをん');
- case LIST_STYLE_TYPE.HIRAGANA_IROHA:
- return createCounterStyleFromSymbols(value, 'いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせす');
- case LIST_STYLE_TYPE.KANNADA:
- return createCounterStyleFromRange(value, 0xce6, 0xcef, true, defaultSuffix);
- case LIST_STYLE_TYPE.KATAKANA:
- return createCounterStyleFromSymbols(value, 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヰヱヲン', cjkSuffix);
- case LIST_STYLE_TYPE.KATAKANA_IROHA:
- return createCounterStyleFromSymbols(value, 'イロハニホヘトチリヌルヲワカヨタレソツネナラムウヰノオクヤマケフコエテアサキユメミシヱヒモセス', cjkSuffix);
- case LIST_STYLE_TYPE.LAO:
- return createCounterStyleFromRange(value, 0xed0, 0xed9, true, defaultSuffix);
- case LIST_STYLE_TYPE.MONGOLIAN:
- return createCounterStyleFromRange(value, 0x1810, 0x1819, true, defaultSuffix);
- case LIST_STYLE_TYPE.MYANMAR:
- return createCounterStyleFromRange(value, 0x1040, 0x1049, true, defaultSuffix);
- case LIST_STYLE_TYPE.ORIYA:
- return createCounterStyleFromRange(value, 0xb66, 0xb6f, true, defaultSuffix);
- case LIST_STYLE_TYPE.PERSIAN:
- return createCounterStyleFromRange(value, 0x6f0, 0x6f9, true, defaultSuffix);
- case LIST_STYLE_TYPE.TAMIL:
- return createCounterStyleFromRange(value, 0xbe6, 0xbef, true, defaultSuffix);
- case LIST_STYLE_TYPE.TELUGU:
- return createCounterStyleFromRange(value, 0xc66, 0xc6f, true, defaultSuffix);
- case LIST_STYLE_TYPE.THAI:
- return createCounterStyleFromRange(value, 0xe50, 0xe59, true, defaultSuffix);
- case LIST_STYLE_TYPE.TIBETAN:
- return createCounterStyleFromRange(value, 0xf20, 0xf29, true, defaultSuffix);
- case LIST_STYLE_TYPE.DECIMAL:
- default:
- return createCounterStyleFromRange(value, 48, 57, true, defaultSuffix);
- }
- };
- var IGNORE_ATTRIBUTE = 'data-html2canvas-ignore';
- var DocumentCloner = /** @class */ (function () {
- function DocumentCloner(element, options) {
- this.options = options;
- this.scrolledElements = [];
- this.referenceElement = element;
- this.counters = new CounterState();
- this.quoteDepth = 0;
- if (!element.ownerDocument) {
- throw new Error('Cloned element does not have an owner document');
- }
- this.documentElement = this.cloneNode(element.ownerDocument.documentElement);
- }
- DocumentCloner.prototype.toIFrame = function (ownerDocument, windowSize) {
- var _this = this;
- var iframe = createIFrameContainer(ownerDocument, windowSize);
- if (!iframe.contentWindow) {
- return Promise.reject("Unable to find iframe window");
- }
- var scrollX = ownerDocument.defaultView.pageXOffset;
- var scrollY = ownerDocument.defaultView.pageYOffset;
- var cloneWindow = iframe.contentWindow;
- var documentClone = cloneWindow.document;
- /* Chrome doesn't detect relative background-images assigned in inline <style> sheets when fetched through getComputedStyle
- if window url is about:blank, we can assign the url to current by writing onto the document
- */
- var iframeLoad = iframeLoader(iframe).then(function () { return __awaiter(_this, void 0, void 0, function () {
- var onclone;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- this.scrolledElements.forEach(restoreNodeScroll);
- if (cloneWindow) {
- cloneWindow.scrollTo(windowSize.left, windowSize.top);
- if (/(iPad|iPhone|iPod)/g.test(navigator.userAgent) &&
- (cloneWindow.scrollY !== windowSize.top || cloneWindow.scrollX !== windowSize.left)) {
- documentClone.documentElement.style.top = -windowSize.top + 'px';
- documentClone.documentElement.style.left = -windowSize.left + 'px';
- documentClone.documentElement.style.position = 'absolute';
- }
- }
- onclone = this.options.onclone;
- if (typeof this.clonedReferenceElement === 'undefined') {
- return [2 /*return*/, Promise.reject("Error finding the " + this.referenceElement.nodeName + " in the cloned document")];
- }
- if (!(documentClone.fonts && documentClone.fonts.ready)) return [3 /*break*/, 2];
- return [4 /*yield*/, documentClone.fonts.ready];
- case 1:
- _a.sent();
- _a.label = 2;
- case 2:
- if (typeof onclone === 'function') {
- return [2 /*return*/, Promise.resolve()
- .then(function () { return onclone(documentClone); })
- .then(function () { return iframe; })];
- }
- return [2 /*return*/, iframe];
- }
- });
- }); });
- documentClone.open();
- documentClone.write(serializeDoctype(document.doctype) + "<html></html>");
- // Chrome scrolls the parent document for some reason after the write to the cloned window???
- restoreOwnerScroll(this.referenceElement.ownerDocument, scrollX, scrollY);
- documentClone.replaceChild(documentClone.adoptNode(this.documentElement), documentClone.documentElement);
- documentClone.close();
- return iframeLoad;
- };
- DocumentCloner.prototype.createElementClone = function (node) {
- if (isCanvasElement(node)) {
- return this.createCanvasClone(node);
- }
- /*
- if (isIFrameElement(node)) {
- return this.createIFrameClone(node);
- }
- */
- if (isStyleElement(node)) {
- return this.createStyleClone(node);
- }
- var clone = node.cloneNode(false);
- // @ts-ignore
- if (isImageElement(clone) && clone.loading === 'lazy') {
- // @ts-ignore
- clone.loading = 'eager';
- }
- return clone;
- };
- DocumentCloner.prototype.createStyleClone = function (node) {
- try {
- var sheet = node.sheet;
- if (sheet && sheet.cssRules) {
- var css = [].slice.call(sheet.cssRules, 0).reduce(function (css, rule) {
- if (rule && typeof rule.cssText === 'string') {
- return css + rule.cssText;
- }
- return css;
- }, '');
- var style = node.cloneNode(false);
- style.textContent = css;
- return style;
- }
- }
- catch (e) {
- // accessing node.sheet.cssRules throws a DOMException
- Logger.getInstance(this.options.id).error('Unable to access cssRules property', e);
- if (e.name !== 'SecurityError') {
- throw e;
- }
- }
- return node.cloneNode(false);
- };
- DocumentCloner.prototype.createCanvasClone = function (canvas) {
- if (this.options.inlineImages && canvas.ownerDocument) {
- var img = canvas.ownerDocument.createElement('img');
- try {
- img.src = canvas.toDataURL();
- return img;
- }
- catch (e) {
- Logger.getInstance(this.options.id).info("Unable to clone canvas contents, canvas is tainted");
- }
- }
- var clonedCanvas = canvas.cloneNode(false);
- try {
- clonedCanvas.width = canvas.width;
- clonedCanvas.height = canvas.height;
- var ctx = canvas.getContext('2d');
- var clonedCtx = clonedCanvas.getContext('2d');
- if (clonedCtx) {
- if (ctx) {
- clonedCtx.putImageData(ctx.getImageData(0, 0, canvas.width, canvas.height), 0, 0);
- }
- else {
- clonedCtx.drawImage(canvas, 0, 0);
- }
- }
- return clonedCanvas;
- }
- catch (e) { }
- return clonedCanvas;
- };
- /*
- createIFrameClone(iframe: HTMLIFrameElement) {
- const tempIframe = <HTMLIFrameElement>iframe.cloneNode(false);
- const iframeKey = generateIframeKey();
- tempIframe.setAttribute('data-html2canvas-internal-iframe-key', iframeKey);
- const {width, height} = parseBounds(iframe);
- this.resourceLoader.cache[iframeKey] = getIframeDocumentElement(iframe, this.options)
- .then(documentElement => {
- return this.renderer(
- documentElement,
- {
- allowTaint: this.options.allowTaint,
- backgroundColor: '#ffffff',
- canvas: null,
- imageTimeout: this.options.imageTimeout,
- logging: this.options.logging,
- proxy: this.options.proxy,
- removeContainer: this.options.removeContainer,
- scale: this.options.scale,
- foreignObjectRendering: this.options.foreignObjectRendering,
- useCORS: this.options.useCORS,
- target: new CanvasRenderer(),
- width,
- height,
- x: 0,
- y: 0,
- windowWidth: documentElement.ownerDocument.defaultView.innerWidth,
- windowHeight: documentElement.ownerDocument.defaultView.innerHeight,
- scrollX: documentElement.ownerDocument.defaultView.pageXOffset,
- scrollY: documentElement.ownerDocument.defaultView.pageYOffset
- },
- );
- })
- .then(
- (canvas: HTMLCanvasElement) =>
- new Promise((resolve, reject) => {
- const iframeCanvas = document.createElement('img');
- iframeCanvas.onload = () => resolve(canvas);
- iframeCanvas.onerror = (event) => {
- // Empty iframes may result in empty "data:," URLs, which are invalid from the <img>'s point of view
- // and instead of `onload` cause `onerror` and unhandled rejection warnings
- // https://github.com/niklasvh/html2canvas/issues/1502
- iframeCanvas.src == 'data:,' ? resolve(canvas) : reject(event);
- };
- iframeCanvas.src = canvas.toDataURL();
- if (tempIframe.parentNode && iframe.ownerDocument && iframe.ownerDocument.defaultView) {
- tempIframe.parentNode.replaceChild(
- copyCSSStyles(
- iframe.ownerDocument.defaultView.getComputedStyle(iframe),
- iframeCanvas
- ),
- tempIframe
- );
- }
- })
- );
- return tempIframe;
- }
- */
- DocumentCloner.prototype.cloneNode = function (node) {
- if (isTextNode(node)) {
- return document.createTextNode(node.data);
- }
- if (!node.ownerDocument) {
- return node.cloneNode(false);
- }
- var window = node.ownerDocument.defaultView;
- if (window && isElementNode(node) && (isHTMLElementNode(node) || isSVGElementNode(node))) {
- var clone = this.createElementClone(node);
- var style = window.getComputedStyle(node);
- var styleBefore = window.getComputedStyle(node, ':before');
- var styleAfter = window.getComputedStyle(node, ':after');
- if (this.referenceElement === node && isHTMLElementNode(clone)) {
- this.clonedReferenceElement = clone;
- }
- if (isBodyElement(clone)) {
- createPseudoHideStyles(clone);
- }
- var counters = this.counters.parse(new CSSParsedCounterDeclaration(style));
- var before = this.resolvePseudoContent(node, clone, styleBefore, PseudoElementType.BEFORE);
- for (var child = node.firstChild; child; child = child.nextSibling) {
- if (!isElementNode(child) ||
- (!isScriptElement(child) &&
- !child.hasAttribute(IGNORE_ATTRIBUTE) &&
- (typeof this.options.ignoreElements !== 'function' || !this.options.ignoreElements(child)))) {
- if (!this.options.copyStyles || !isElementNode(child) || !isStyleElement(child)) {
- clone.appendChild(this.cloneNode(child));
- }
- }
- }
- if (before) {
- clone.insertBefore(before, clone.firstChild);
- }
- var after = this.resolvePseudoContent(node, clone, styleAfter, PseudoElementType.AFTER);
- if (after) {
- clone.appendChild(after);
- }
- this.counters.pop(counters);
- if (style && (this.options.copyStyles || isSVGElementNode(node)) && !isIFrameElement(node)) {
- copyCSSStyles(style, clone);
- }
- //this.inlineAllImages(clone);
- if (node.scrollTop !== 0 || node.scrollLeft !== 0) {
- this.scrolledElements.push([clone, node.scrollLeft, node.scrollTop]);
- }
- if ((isTextareaElement(node) || isSelectElement(node)) &&
- (isTextareaElement(clone) || isSelectElement(clone))) {
- clone.value = node.value;
- }
- return clone;
- }
- return node.cloneNode(false);
- };
- DocumentCloner.prototype.resolvePseudoContent = function (node, clone, style, pseudoElt) {
- var _this = this;
- if (!style) {
- return;
- }
- var value = style.content;
- var document = clone.ownerDocument;
- if (!document || !value || value === 'none' || value === '-moz-alt-content' || style.display === 'none') {
- return;
- }
- this.counters.parse(new CSSParsedCounterDeclaration(style));
- var declaration = new CSSParsedPseudoDeclaration(style);
- var anonymousReplacedElement = document.createElement('html2canvaspseudoelement');
- copyCSSStyles(style, anonymousReplacedElement);
- declaration.content.forEach(function (token) {
- if (token.type === TokenType.STRING_TOKEN) {
- anonymousReplacedElement.appendChild(document.createTextNode(token.value));
- }
- else if (token.type === TokenType.URL_TOKEN) {
- var img = document.createElement('img');
- img.src = token.value;
- img.style.opacity = '1';
- anonymousReplacedElement.appendChild(img);
- }
- else if (token.type === TokenType.FUNCTION) {
- if (token.name === 'attr') {
- var attr = token.values.filter(isIdentToken);
- if (attr.length) {
- anonymousReplacedElement.appendChild(document.createTextNode(node.getAttribute(attr[0].value) || ''));
- }
- }
- else if (token.name === 'counter') {
- var _a = token.values.filter(nonFunctionArgSeparator), counter = _a[0], counterStyle = _a[1];
- if (counter && isIdentToken(counter)) {
- var counterState = _this.counters.getCounterValue(counter.value);
- var counterType = counterStyle && isIdentToken(counterStyle)
- ? listStyleType.parse(counterStyle.value)
- : LIST_STYLE_TYPE.DECIMAL;
- anonymousReplacedElement.appendChild(document.createTextNode(createCounterText(counterState, counterType, false)));
- }
- }
- else if (token.name === 'counters') {
- var _b = token.values.filter(nonFunctionArgSeparator), counter = _b[0], delim = _b[1], counterStyle = _b[2];
- if (counter && isIdentToken(counter)) {
- var counterStates = _this.counters.getCounterValues(counter.value);
- var counterType_1 = counterStyle && isIdentToken(counterStyle)
- ? listStyleType.parse(counterStyle.value)
- : LIST_STYLE_TYPE.DECIMAL;
- var separator = delim && delim.type === TokenType.STRING_TOKEN ? delim.value : '';
- var text = counterStates
- .map(function (value) { return createCounterText(value, counterType_1, false); })
- .join(separator);
- anonymousReplacedElement.appendChild(document.createTextNode(text));
- }
- }
- }
- else if (token.type === TokenType.IDENT_TOKEN) {
- switch (token.value) {
- case 'open-quote':
- anonymousReplacedElement.appendChild(document.createTextNode(getQuote(declaration.quotes, _this.quoteDepth++, true)));
- break;
- case 'close-quote':
- anonymousReplacedElement.appendChild(document.createTextNode(getQuote(declaration.quotes, --_this.quoteDepth, false)));
- break;
- default:
- // safari doesn't parse string tokens correctly because of lack of quotes
- anonymousReplacedElement.appendChild(document.createTextNode(token.value));
- }
- }
- });
- anonymousReplacedElement.className = PSEUDO_HIDE_ELEMENT_CLASS_BEFORE + " " + PSEUDO_HIDE_ELEMENT_CLASS_AFTER;
- var newClassName = pseudoElt === PseudoElementType.BEFORE
- ? " " + PSEUDO_HIDE_ELEMENT_CLASS_BEFORE
- : " " + PSEUDO_HIDE_ELEMENT_CLASS_AFTER;
- if (isSVGElementNode(clone)) {
- clone.className.baseValue += newClassName;
- }
- else {
- clone.className += newClassName;
- }
- return anonymousReplacedElement;
- };
- DocumentCloner.destroy = function (container) {
- if (container.parentNode) {
- container.parentNode.removeChild(container);
- return true;
- }
- return false;
- };
- return DocumentCloner;
- }());
- var PseudoElementType;
- (function (PseudoElementType) {
- PseudoElementType[PseudoElementType["BEFORE"] = 0] = "BEFORE";
- PseudoElementType[PseudoElementType["AFTER"] = 1] = "AFTER";
- })(PseudoElementType || (PseudoElementType = {}));
- var createIFrameContainer = function (ownerDocument, bounds) {
- var cloneIframeContainer = ownerDocument.createElement('iframe');
- cloneIframeContainer.className = 'html2canvas-container';
- cloneIframeContainer.style.visibility = 'hidden';
- cloneIframeContainer.style.position = 'fixed';
- cloneIframeContainer.style.left = '-10000px';
- cloneIframeContainer.style.top = '0px';
- cloneIframeContainer.style.border = '0';
- cloneIframeContainer.width = bounds.width.toString();
- cloneIframeContainer.height = bounds.height.toString();
- cloneIframeContainer.scrolling = 'no'; // ios won't scroll without it
- cloneIframeContainer.setAttribute(IGNORE_ATTRIBUTE, 'true');
- ownerDocument.body.appendChild(cloneIframeContainer);
- return cloneIframeContainer;
- };
- var iframeLoader = function (iframe) {
- return new Promise(function (resolve, reject) {
- var cloneWindow = iframe.contentWindow;
- if (!cloneWindow) {
- return reject("No window assigned for iframe");
- }
- var documentClone = cloneWindow.document;
- cloneWindow.onload = iframe.onload = documentClone.onreadystatechange = function () {
- cloneWindow.onload = iframe.onload = documentClone.onreadystatechange = null;
- var interval = setInterval(function () {
- if (documentClone.body.childNodes.length > 0 && documentClone.readyState === 'complete') {
- clearInterval(interval);
- resolve(iframe);
- }
- }, 50);
- };
- });
- };
- var copyCSSStyles = function (style, target) {
- // Edge does not provide value for cssText
- for (var i = style.length - 1; i >= 0; i--) {
- var property = style.item(i);
- // Safari shows pseudoelements if content is set
- if (property !== 'content') {
- target.style.setProperty(property, style.getPropertyValue(property));
- }
- }
- return target;
- };
- var serializeDoctype = function (doctype) {
- var str = '';
- if (doctype) {
- str += '<!DOCTYPE ';
- if (doctype.name) {
- str += doctype.name;
- }
- if (doctype.internalSubset) {
- str += doctype.internalSubset;
- }
- if (doctype.publicId) {
- str += "\"" + doctype.publicId + "\"";
- }
- if (doctype.systemId) {
- str += "\"" + doctype.systemId + "\"";
- }
- str += '>';
- }
- return str;
- };
- var restoreOwnerScroll = function (ownerDocument, x, y) {
- if (ownerDocument &&
- ownerDocument.defaultView &&
- (x !== ownerDocument.defaultView.pageXOffset || y !== ownerDocument.defaultView.pageYOffset)) {
- ownerDocument.defaultView.scrollTo(x, y);
- }
- };
- var restoreNodeScroll = function (_a) {
- var element = _a[0], x = _a[1], y = _a[2];
- element.scrollLeft = x;
- element.scrollTop = y;
- };
- var PSEUDO_BEFORE = ':before';
- var PSEUDO_AFTER = ':after';
- var PSEUDO_HIDE_ELEMENT_CLASS_BEFORE = '___html2canvas___pseudoelement_before';
- var PSEUDO_HIDE_ELEMENT_CLASS_AFTER = '___html2canvas___pseudoelement_after';
- var PSEUDO_HIDE_ELEMENT_STYLE = "{\n content: \"\" !important;\n display: none !important;\n}";
- var createPseudoHideStyles = function (body) {
- createStyles(body, "." + PSEUDO_HIDE_ELEMENT_CLASS_BEFORE + PSEUDO_BEFORE + PSEUDO_HIDE_ELEMENT_STYLE + "\n ." + PSEUDO_HIDE_ELEMENT_CLASS_AFTER + PSEUDO_AFTER + PSEUDO_HIDE_ELEMENT_STYLE);
- };
- var createStyles = function (body, styles) {
- var document = body.ownerDocument;
- if (document) {
- var style = document.createElement('style');
- style.textContent = styles;
- body.appendChild(style);
- }
- };
- var PathType;
- (function (PathType) {
- PathType[PathType["VECTOR"] = 0] = "VECTOR";
- PathType[PathType["BEZIER_CURVE"] = 1] = "BEZIER_CURVE";
- })(PathType || (PathType = {}));
- var equalPath = function (a, b) {
- if (a.length === b.length) {
- return a.some(function (v, i) { return v === b[i]; });
- }
- return false;
- };
- var transformPath = function (path, deltaX, deltaY, deltaW, deltaH) {
- return path.map(function (point, index) {
- switch (index) {
- case 0:
- return point.add(deltaX, deltaY);
- case 1:
- return point.add(deltaX + deltaW, deltaY);
- case 2:
- return point.add(deltaX + deltaW, deltaY + deltaH);
- case 3:
- return point.add(deltaX, deltaY + deltaH);
- }
- return point;
- });
- };
- var Vector = /** @class */ (function () {
- function Vector(x, y) {
- this.type = PathType.VECTOR;
- this.x = x;
- this.y = y;
- }
- Vector.prototype.add = function (deltaX, deltaY) {
- return new Vector(this.x + deltaX, this.y + deltaY);
- };
- return Vector;
- }());
- var lerp = function (a, b, t) {
- return new Vector(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t);
- };
- var BezierCurve = /** @class */ (function () {
- function BezierCurve(start, startControl, endControl, end) {
- this.type = PathType.BEZIER_CURVE;
- this.start = start;
- this.startControl = startControl;
- this.endControl = endControl;
- this.end = end;
- }
- BezierCurve.prototype.subdivide = function (t, firstHalf) {
- var ab = lerp(this.start, this.startControl, t);
- var bc = lerp(this.startControl, this.endControl, t);
- var cd = lerp(this.endControl, this.end, t);
- var abbc = lerp(ab, bc, t);
- var bccd = lerp(bc, cd, t);
- var dest = lerp(abbc, bccd, t);
- return firstHalf ? new BezierCurve(this.start, ab, abbc, dest) : new BezierCurve(dest, bccd, cd, this.end);
- };
- BezierCurve.prototype.add = function (deltaX, deltaY) {
- return new BezierCurve(this.start.add(deltaX, deltaY), this.startControl.add(deltaX, deltaY), this.endControl.add(deltaX, deltaY), this.end.add(deltaX, deltaY));
- };
- BezierCurve.prototype.reverse = function () {
- return new BezierCurve(this.end, this.endControl, this.startControl, this.start);
- };
- return BezierCurve;
- }());
- var isBezierCurve = function (path) { return path.type === PathType.BEZIER_CURVE; };
- var BoundCurves = /** @class */ (function () {
- function BoundCurves(element) {
- var styles = element.styles;
- var bounds = element.bounds;
- var _a = getAbsoluteValueForTuple(styles.borderTopLeftRadius, bounds.width, bounds.height), tlh = _a[0], tlv = _a[1];
- var _b = getAbsoluteValueForTuple(styles.borderTopRightRadius, bounds.width, bounds.height), trh = _b[0], trv = _b[1];
- var _c = getAbsoluteValueForTuple(styles.borderBottomRightRadius, bounds.width, bounds.height), brh = _c[0], brv = _c[1];
- var _d = getAbsoluteValueForTuple(styles.borderBottomLeftRadius, bounds.width, bounds.height), blh = _d[0], blv = _d[1];
- var factors = [];
- factors.push((tlh + trh) / bounds.width);
- factors.push((blh + brh) / bounds.width);
- factors.push((tlv + blv) / bounds.height);
- factors.push((trv + brv) / bounds.height);
- var maxFactor = Math.max.apply(Math, factors);
- if (maxFactor > 1) {
- tlh /= maxFactor;
- tlv /= maxFactor;
- trh /= maxFactor;
- trv /= maxFactor;
- brh /= maxFactor;
- brv /= maxFactor;
- blh /= maxFactor;
- blv /= maxFactor;
- }
- var topWidth = bounds.width - trh;
- var rightHeight = bounds.height - brv;
- var bottomWidth = bounds.width - brh;
- var leftHeight = bounds.height - blv;
- var borderTopWidth = styles.borderTopWidth;
- var borderRightWidth = styles.borderRightWidth;
- var borderBottomWidth = styles.borderBottomWidth;
- var borderLeftWidth = styles.borderLeftWidth;
- var paddingTop = getAbsoluteValue(styles.paddingTop, element.bounds.width);
- var paddingRight = getAbsoluteValue(styles.paddingRight, element.bounds.width);
- var paddingBottom = getAbsoluteValue(styles.paddingBottom, element.bounds.width);
- var paddingLeft = getAbsoluteValue(styles.paddingLeft, element.bounds.width);
- this.topLeftBorderBox =
- tlh > 0 || tlv > 0
- ? getCurvePoints(bounds.left, bounds.top, tlh, tlv, CORNER.TOP_LEFT)
- : new Vector(bounds.left, bounds.top);
- this.topRightBorderBox =
- trh > 0 || trv > 0
- ? getCurvePoints(bounds.left + topWidth, bounds.top, trh, trv, CORNER.TOP_RIGHT)
- : new Vector(bounds.left + bounds.width, bounds.top);
- this.bottomRightBorderBox =
- brh > 0 || brv > 0
- ? getCurvePoints(bounds.left + bottomWidth, bounds.top + rightHeight, brh, brv, CORNER.BOTTOM_RIGHT)
- : new Vector(bounds.left + bounds.width, bounds.top + bounds.height);
- this.bottomLeftBorderBox =
- blh > 0 || blv > 0
- ? getCurvePoints(bounds.left, bounds.top + leftHeight, blh, blv, CORNER.BOTTOM_LEFT)
- : new Vector(bounds.left, bounds.top + bounds.height);
- this.topLeftPaddingBox =
- tlh > 0 || tlv > 0
- ? getCurvePoints(bounds.left + borderLeftWidth, bounds.top + borderTopWidth, Math.max(0, tlh - borderLeftWidth), Math.max(0, tlv - borderTopWidth), CORNER.TOP_LEFT)
- : new Vector(bounds.left + borderLeftWidth, bounds.top + borderTopWidth);
- this.topRightPaddingBox =
- trh > 0 || trv > 0
- ? getCurvePoints(bounds.left + Math.min(topWidth, bounds.width + borderLeftWidth), bounds.top + borderTopWidth, topWidth > bounds.width + borderLeftWidth ? 0 : trh - borderLeftWidth, trv - borderTopWidth, CORNER.TOP_RIGHT)
- : new Vector(bounds.left + bounds.width - borderRightWidth, bounds.top + borderTopWidth);
- this.bottomRightPaddingBox =
- brh > 0 || brv > 0
- ? getCurvePoints(bounds.left + Math.min(bottomWidth, bounds.width - borderLeftWidth), bounds.top + Math.min(rightHeight, bounds.height + borderTopWidth), Math.max(0, brh - borderRightWidth), brv - borderBottomWidth, CORNER.BOTTOM_RIGHT)
- : new Vector(bounds.left + bounds.width - borderRightWidth, bounds.top + bounds.height - borderBottomWidth);
- this.bottomLeftPaddingBox =
- blh > 0 || blv > 0
- ? getCurvePoints(bounds.left + borderLeftWidth, bounds.top + leftHeight, Math.max(0, blh - borderLeftWidth), blv - borderBottomWidth, CORNER.BOTTOM_LEFT)
- : new Vector(bounds.left + borderLeftWidth, bounds.top + bounds.height - borderBottomWidth);
- this.topLeftContentBox =
- tlh > 0 || tlv > 0
- ? getCurvePoints(bounds.left + borderLeftWidth + paddingLeft, bounds.top + borderTopWidth + paddingTop, Math.max(0, tlh - (borderLeftWidth + paddingLeft)), Math.max(0, tlv - (borderTopWidth + paddingTop)), CORNER.TOP_LEFT)
- : new Vector(bounds.left + borderLeftWidth + paddingLeft, bounds.top + borderTopWidth + paddingTop);
- this.topRightContentBox =
- trh > 0 || trv > 0
- ? getCurvePoints(bounds.left + Math.min(topWidth, bounds.width + borderLeftWidth + paddingLeft), bounds.top + borderTopWidth + paddingTop, topWidth > bounds.width + borderLeftWidth + paddingLeft ? 0 : trh - borderLeftWidth + paddingLeft, trv - (borderTopWidth + paddingTop), CORNER.TOP_RIGHT)
- : new Vector(bounds.left + bounds.width - (borderRightWidth + paddingRight), bounds.top + borderTopWidth + paddingTop);
- this.bottomRightContentBox =
- brh > 0 || brv > 0
- ? getCurvePoints(bounds.left + Math.min(bottomWidth, bounds.width - (borderLeftWidth + paddingLeft)), bounds.top + Math.min(rightHeight, bounds.height + borderTopWidth + paddingTop), Math.max(0, brh - (borderRightWidth + paddingRight)), brv - (borderBottomWidth + paddingBottom), CORNER.BOTTOM_RIGHT)
- : new Vector(bounds.left + bounds.width - (borderRightWidth + paddingRight), bounds.top + bounds.height - (borderBottomWidth + paddingBottom));
- this.bottomLeftContentBox =
- blh > 0 || blv > 0
- ? getCurvePoints(bounds.left + borderLeftWidth + paddingLeft, bounds.top + leftHeight, Math.max(0, blh - (borderLeftWidth + paddingLeft)), blv - (borderBottomWidth + paddingBottom), CORNER.BOTTOM_LEFT)
- : new Vector(bounds.left + borderLeftWidth + paddingLeft, bounds.top + bounds.height - (borderBottomWidth + paddingBottom));
- }
- return BoundCurves;
- }());
- var CORNER;
- (function (CORNER) {
- CORNER[CORNER["TOP_LEFT"] = 0] = "TOP_LEFT";
- CORNER[CORNER["TOP_RIGHT"] = 1] = "TOP_RIGHT";
- CORNER[CORNER["BOTTOM_RIGHT"] = 2] = "BOTTOM_RIGHT";
- CORNER[CORNER["BOTTOM_LEFT"] = 3] = "BOTTOM_LEFT";
- })(CORNER || (CORNER = {}));
- var getCurvePoints = function (x, y, r1, r2, position) {
- var kappa = 4 * ((Math.sqrt(2) - 1) / 3);
- var ox = r1 * kappa; // control point offset horizontal
- var oy = r2 * kappa; // control point offset vertical
- var xm = x + r1; // x-middle
- var ym = y + r2; // y-middle
- switch (position) {
- case CORNER.TOP_LEFT:
- return new BezierCurve(new Vector(x, ym), new Vector(x, ym - oy), new Vector(xm - ox, y), new Vector(xm, y));
- case CORNER.TOP_RIGHT:
- return new BezierCurve(new Vector(x, y), new Vector(x + ox, y), new Vector(xm, ym - oy), new Vector(xm, ym));
- case CORNER.BOTTOM_RIGHT:
- return new BezierCurve(new Vector(xm, y), new Vector(xm, y + oy), new Vector(x + ox, ym), new Vector(x, ym));
- case CORNER.BOTTOM_LEFT:
- default:
- return new BezierCurve(new Vector(xm, ym), new Vector(xm - ox, ym), new Vector(x, y + oy), new Vector(x, y));
- }
- };
- var calculateBorderBoxPath = function (curves) {
- return [curves.topLeftBorderBox, curves.topRightBorderBox, curves.bottomRightBorderBox, curves.bottomLeftBorderBox];
- };
- var calculateContentBoxPath = function (curves) {
- return [
- curves.topLeftContentBox,
- curves.topRightContentBox,
- curves.bottomRightContentBox,
- curves.bottomLeftContentBox
- ];
- };
- var calculatePaddingBoxPath = function (curves) {
- return [
- curves.topLeftPaddingBox,
- curves.topRightPaddingBox,
- curves.bottomRightPaddingBox,
- curves.bottomLeftPaddingBox
- ];
- };
- var TransformEffect = /** @class */ (function () {
- function TransformEffect(offsetX, offsetY, matrix) {
- this.type = 0 /* TRANSFORM */;
- this.offsetX = offsetX;
- this.offsetY = offsetY;
- this.matrix = matrix;
- this.target = 2 /* BACKGROUND_BORDERS */ | 4 /* CONTENT */;
- }
- return TransformEffect;
- }());
- var ClipEffect = /** @class */ (function () {
- function ClipEffect(path, target) {
- this.type = 1 /* CLIP */;
- this.target = target;
- this.path = path;
- }
- return ClipEffect;
- }());
- var isTransformEffect = function (effect) {
- return effect.type === 0 /* TRANSFORM */;
- };
- var isClipEffect = function (effect) { return effect.type === 1 /* CLIP */; };
- var StackingContext = /** @class */ (function () {
- function StackingContext(container) {
- this.element = container;
- this.inlineLevel = [];
- this.nonInlineLevel = [];
- this.negativeZIndex = [];
- this.zeroOrAutoZIndexOrTransformedOrOpacity = [];
- this.positiveZIndex = [];
- this.nonPositionedFloats = [];
- this.nonPositionedInlineLevel = [];
- }
- return StackingContext;
- }());
- var ElementPaint = /** @class */ (function () {
- function ElementPaint(element, parentStack) {
- this.container = element;
- this.effects = parentStack.slice(0);
- this.curves = new BoundCurves(element);
- if (element.styles.transform !== null) {
- var offsetX = element.bounds.left + element.styles.transformOrigin[0].number;
- var offsetY = element.bounds.top + element.styles.transformOrigin[1].number;
- var matrix = element.styles.transform;
- this.effects.push(new TransformEffect(offsetX, offsetY, matrix));
- }
- if (element.styles.overflowX !== OVERFLOW.VISIBLE) {
- var borderBox = calculateBorderBoxPath(this.curves);
- var paddingBox = calculatePaddingBoxPath(this.curves);
- if (equalPath(borderBox, paddingBox)) {
- this.effects.push(new ClipEffect(borderBox, 2 /* BACKGROUND_BORDERS */ | 4 /* CONTENT */));
- }
- else {
- this.effects.push(new ClipEffect(borderBox, 2 /* BACKGROUND_BORDERS */));
- this.effects.push(new ClipEffect(paddingBox, 4 /* CONTENT */));
- }
- }
- }
- ElementPaint.prototype.getParentEffects = function () {
- var effects = this.effects.slice(0);
- if (this.container.styles.overflowX !== OVERFLOW.VISIBLE) {
- var borderBox = calculateBorderBoxPath(this.curves);
- var paddingBox = calculatePaddingBoxPath(this.curves);
- if (!equalPath(borderBox, paddingBox)) {
- effects.push(new ClipEffect(paddingBox, 2 /* BACKGROUND_BORDERS */ | 4 /* CONTENT */));
- }
- }
- return effects;
- };
- return ElementPaint;
- }());
- var parseStackTree = function (parent, stackingContext, realStackingContext, listItems) {
- parent.container.elements.forEach(function (child) {
- var treatAsRealStackingContext = contains(child.flags, 4 /* CREATES_REAL_STACKING_CONTEXT */);
- var createsStackingContext = contains(child.flags, 2 /* CREATES_STACKING_CONTEXT */);
- var paintContainer = new ElementPaint(child, parent.getParentEffects());
- if (contains(child.styles.display, 2048 /* LIST_ITEM */)) {
- listItems.push(paintContainer);
- }
- var listOwnerItems = contains(child.flags, 8 /* IS_LIST_OWNER */) ? [] : listItems;
- if (treatAsRealStackingContext || createsStackingContext) {
- var parentStack = treatAsRealStackingContext || child.styles.isPositioned() ? realStackingContext : stackingContext;
- var stack = new StackingContext(paintContainer);
- if (child.styles.isPositioned() || child.styles.opacity < 1 || child.styles.isTransformed()) {
- var order_1 = child.styles.zIndex.order;
- if (order_1 < 0) {
- var index_1 = 0;
- parentStack.negativeZIndex.some(function (current, i) {
- if (order_1 > current.element.container.styles.zIndex.order) {
- index_1 = i;
- return false;
- }
- else if (index_1 > 0) {
- return true;
- }
- return false;
- });
- parentStack.negativeZIndex.splice(index_1, 0, stack);
- }
- else if (order_1 > 0) {
- var index_2 = 0;
- parentStack.positiveZIndex.some(function (current, i) {
- if (order_1 >= current.element.container.styles.zIndex.order) {
- index_2 = i + 1;
- return false;
- }
- else if (index_2 > 0) {
- return true;
- }
- return false;
- });
- parentStack.positiveZIndex.splice(index_2, 0, stack);
- }
- else {
- parentStack.zeroOrAutoZIndexOrTransformedOrOpacity.push(stack);
- }
- }
- else {
- if (child.styles.isFloating()) {
- parentStack.nonPositionedFloats.push(stack);
- }
- else {
- parentStack.nonPositionedInlineLevel.push(stack);
- }
- }
- parseStackTree(paintContainer, stack, treatAsRealStackingContext ? stack : realStackingContext, listOwnerItems);
- }
- else {
- if (child.styles.isInlineLevel()) {
- stackingContext.inlineLevel.push(paintContainer);
- }
- else {
- stackingContext.nonInlineLevel.push(paintContainer);
- }
- parseStackTree(paintContainer, stackingContext, realStackingContext, listOwnerItems);
- }
- if (contains(child.flags, 8 /* IS_LIST_OWNER */)) {
- processListItems(child, listOwnerItems);
- }
- });
- };
- var processListItems = function (owner, elements) {
- var numbering = owner instanceof OLElementContainer ? owner.start : 1;
- var reversed = owner instanceof OLElementContainer ? owner.reversed : false;
- for (var i = 0; i < elements.length; i++) {
- var item = elements[i];
- if (item.container instanceof LIElementContainer &&
- typeof item.container.value === 'number' &&
- item.container.value !== 0) {
- numbering = item.container.value;
- }
- item.listValue = createCounterText(numbering, item.container.styles.listStyleType, true);
- numbering += reversed ? -1 : 1;
- }
- };
- var parseStackingContexts = function (container) {
- var paintContainer = new ElementPaint(container, []);
- var root = new StackingContext(paintContainer);
- var listItems = [];
- parseStackTree(paintContainer, root, root, listItems);
- processListItems(paintContainer.container, listItems);
- return root;
- };
- var parsePathForBorder = function (curves, borderSide) {
- switch (borderSide) {
- case 0:
- return createPathFromCurves(curves.topLeftBorderBox, curves.topLeftPaddingBox, curves.topRightBorderBox, curves.topRightPaddingBox);
- case 1:
- return createPathFromCurves(curves.topRightBorderBox, curves.topRightPaddingBox, curves.bottomRightBorderBox, curves.bottomRightPaddingBox);
- case 2:
- return createPathFromCurves(curves.bottomRightBorderBox, curves.bottomRightPaddingBox, curves.bottomLeftBorderBox, curves.bottomLeftPaddingBox);
- case 3:
- default:
- return createPathFromCurves(curves.bottomLeftBorderBox, curves.bottomLeftPaddingBox, curves.topLeftBorderBox, curves.topLeftPaddingBox);
- }
- };
- var createPathFromCurves = function (outer1, inner1, outer2, inner2) {
- var path = [];
- if (isBezierCurve(outer1)) {
- path.push(outer1.subdivide(0.5, false));
- }
- else {
- path.push(outer1);
- }
- if (isBezierCurve(outer2)) {
- path.push(outer2.subdivide(0.5, true));
- }
- else {
- path.push(outer2);
- }
- if (isBezierCurve(inner2)) {
- path.push(inner2.subdivide(0.5, true).reverse());
- }
- else {
- path.push(inner2);
- }
- if (isBezierCurve(inner1)) {
- path.push(inner1.subdivide(0.5, false).reverse());
- }
- else {
- path.push(inner1);
- }
- return path;
- };
- var paddingBox = function (element) {
- var bounds = element.bounds;
- var styles = element.styles;
- return bounds.add(styles.borderLeftWidth, styles.borderTopWidth, -(styles.borderRightWidth + styles.borderLeftWidth), -(styles.borderTopWidth + styles.borderBottomWidth));
- };
- var contentBox = function (element) {
- var styles = element.styles;
- var bounds = element.bounds;
- var paddingLeft = getAbsoluteValue(styles.paddingLeft, bounds.width);
- var paddingRight = getAbsoluteValue(styles.paddingRight, bounds.width);
- var paddingTop = getAbsoluteValue(styles.paddingTop, bounds.width);
- var paddingBottom = getAbsoluteValue(styles.paddingBottom, bounds.width);
- return bounds.add(paddingLeft + styles.borderLeftWidth, paddingTop + styles.borderTopWidth, -(styles.borderRightWidth + styles.borderLeftWidth + paddingLeft + paddingRight), -(styles.borderTopWidth + styles.borderBottomWidth + paddingTop + paddingBottom));
- };
- var calculateBackgroundPositioningArea = function (backgroundOrigin, element) {
- if (backgroundOrigin === 0 /* BORDER_BOX */) {
- return element.bounds;
- }
- if (backgroundOrigin === 2 /* CONTENT_BOX */) {
- return contentBox(element);
- }
- return paddingBox(element);
- };
- var calculateBackgroundPaintingArea = function (backgroundClip, element) {
- if (backgroundClip === BACKGROUND_CLIP.BORDER_BOX) {
- return element.bounds;
- }
- if (backgroundClip === BACKGROUND_CLIP.CONTENT_BOX) {
- return contentBox(element);
- }
- return paddingBox(element);
- };
- var calculateBackgroundRendering = function (container, index, intrinsicSize) {
- var backgroundPositioningArea = calculateBackgroundPositioningArea(getBackgroundValueForIndex(container.styles.backgroundOrigin, index), container);
- var backgroundPaintingArea = calculateBackgroundPaintingArea(getBackgroundValueForIndex(container.styles.backgroundClip, index), container);
- var backgroundImageSize = calculateBackgroundSize(getBackgroundValueForIndex(container.styles.backgroundSize, index), intrinsicSize, backgroundPositioningArea);
- var sizeWidth = backgroundImageSize[0], sizeHeight = backgroundImageSize[1];
- var position = getAbsoluteValueForTuple(getBackgroundValueForIndex(container.styles.backgroundPosition, index), backgroundPositioningArea.width - sizeWidth, backgroundPositioningArea.height - sizeHeight);
- var path = calculateBackgroundRepeatPath(getBackgroundValueForIndex(container.styles.backgroundRepeat, index), position, backgroundImageSize, backgroundPositioningArea, backgroundPaintingArea);
- var offsetX = Math.round(backgroundPositioningArea.left + position[0]);
- var offsetY = Math.round(backgroundPositioningArea.top + position[1]);
- return [path, offsetX, offsetY, sizeWidth, sizeHeight];
- };
- var isAuto = function (token) { return isIdentToken(token) && token.value === BACKGROUND_SIZE.AUTO; };
- var hasIntrinsicValue = function (value) { return typeof value === 'number'; };
- var calculateBackgroundSize = function (size, _a, bounds) {
- var intrinsicWidth = _a[0], intrinsicHeight = _a[1], intrinsicProportion = _a[2];
- var first = size[0], second = size[1];
- if (isLengthPercentage(first) && second && isLengthPercentage(second)) {
- return [getAbsoluteValue(first, bounds.width), getAbsoluteValue(second, bounds.height)];
- }
- var hasIntrinsicProportion = hasIntrinsicValue(intrinsicProportion);
- if (isIdentToken(first) && (first.value === BACKGROUND_SIZE.CONTAIN || first.value === BACKGROUND_SIZE.COVER)) {
- if (hasIntrinsicValue(intrinsicProportion)) {
- var targetRatio = bounds.width / bounds.height;
- return targetRatio < intrinsicProportion !== (first.value === BACKGROUND_SIZE.COVER)
- ? [bounds.width, bounds.width / intrinsicProportion]
- : [bounds.height * intrinsicProportion, bounds.height];
- }
- return [bounds.width, bounds.height];
- }
- var hasIntrinsicWidth = hasIntrinsicValue(intrinsicWidth);
- var hasIntrinsicHeight = hasIntrinsicValue(intrinsicHeight);
- var hasIntrinsicDimensions = hasIntrinsicWidth || hasIntrinsicHeight;
- // If the background-size is auto or auto auto:
- if (isAuto(first) && (!second || isAuto(second))) {
- // If the image has both horizontal and vertical intrinsic dimensions, it's rendered at that size.
- if (hasIntrinsicWidth && hasIntrinsicHeight) {
- return [intrinsicWidth, intrinsicHeight];
- }
- // If the image has no intrinsic dimensions and has no intrinsic proportions,
- // it's rendered at the size of the background positioning area.
- if (!hasIntrinsicProportion && !hasIntrinsicDimensions) {
- return [bounds.width, bounds.height];
- }
- // TODO If the image has no intrinsic dimensions but has intrinsic proportions, it's rendered as if contain had been specified instead.
- // If the image has only one intrinsic dimension and has intrinsic proportions, it's rendered at the size corresponding to that one dimension.
- // The other dimension is computed using the specified dimension and the intrinsic proportions.
- if (hasIntrinsicDimensions && hasIntrinsicProportion) {
- var width_1 = hasIntrinsicWidth
- ? intrinsicWidth
- : intrinsicHeight * intrinsicProportion;
- var height_1 = hasIntrinsicHeight
- ? intrinsicHeight
- : intrinsicWidth / intrinsicProportion;
- return [width_1, height_1];
- }
- // If the image has only one intrinsic dimension but has no intrinsic proportions,
- // it's rendered using the specified dimension and the other dimension of the background positioning area.
- var width_2 = hasIntrinsicWidth ? intrinsicWidth : bounds.width;
- var height_2 = hasIntrinsicHeight ? intrinsicHeight : bounds.height;
- return [width_2, height_2];
- }
- // If the image has intrinsic proportions, it's stretched to the specified dimension.
- // The unspecified dimension is computed using the specified dimension and the intrinsic proportions.
- if (hasIntrinsicProportion) {
- var width_3 = 0;
- var height_3 = 0;
- if (isLengthPercentage(first)) {
- width_3 = getAbsoluteValue(first, bounds.width);
- }
- else if (isLengthPercentage(second)) {
- height_3 = getAbsoluteValue(second, bounds.height);
- }
- if (isAuto(first)) {
- width_3 = height_3 * intrinsicProportion;
- }
- else if (!second || isAuto(second)) {
- height_3 = width_3 / intrinsicProportion;
- }
- return [width_3, height_3];
- }
- // If the image has no intrinsic proportions, it's stretched to the specified dimension.
- // The unspecified dimension is computed using the image's corresponding intrinsic dimension,
- // if there is one. If there is no such intrinsic dimension,
- // it becomes the corresponding dimension of the background positioning area.
- var width = null;
- var height = null;
- if (isLengthPercentage(first)) {
- width = getAbsoluteValue(first, bounds.width);
- }
- else if (second && isLengthPercentage(second)) {
- height = getAbsoluteValue(second, bounds.height);
- }
- if (width !== null && (!second || isAuto(second))) {
- height =
- hasIntrinsicWidth && hasIntrinsicHeight
- ? (width / intrinsicWidth) * intrinsicHeight
- : bounds.height;
- }
- if (height !== null && isAuto(first)) {
- width =
- hasIntrinsicWidth && hasIntrinsicHeight
- ? (height / intrinsicHeight) * intrinsicWidth
- : bounds.width;
- }
- if (width !== null && height !== null) {
- return [width, height];
- }
- throw new Error("Unable to calculate background-size for element");
- };
- var getBackgroundValueForIndex = function (values, index) {
- var value = values[index];
- if (typeof value === 'undefined') {
- return values[0];
- }
- return value;
- };
- var calculateBackgroundRepeatPath = function (repeat, _a, _b, backgroundPositioningArea, backgroundPaintingArea) {
- var x = _a[0], y = _a[1];
- var width = _b[0], height = _b[1];
- switch (repeat) {
- case BACKGROUND_REPEAT.REPEAT_X:
- return [
- new Vector(Math.round(backgroundPositioningArea.left), Math.round(backgroundPositioningArea.top + y)),
- new Vector(Math.round(backgroundPositioningArea.left + backgroundPositioningArea.width), Math.round(backgroundPositioningArea.top + y)),
- new Vector(Math.round(backgroundPositioningArea.left + backgroundPositioningArea.width), Math.round(height + backgroundPositioningArea.top + y)),
- new Vector(Math.round(backgroundPositioningArea.left), Math.round(height + backgroundPositioningArea.top + y))
- ];
- case BACKGROUND_REPEAT.REPEAT_Y:
- return [
- new Vector(Math.round(backgroundPositioningArea.left + x), Math.round(backgroundPositioningArea.top)),
- new Vector(Math.round(backgroundPositioningArea.left + x + width), Math.round(backgroundPositioningArea.top)),
- new Vector(Math.round(backgroundPositioningArea.left + x + width), Math.round(backgroundPositioningArea.height + backgroundPositioningArea.top)),
- new Vector(Math.round(backgroundPositioningArea.left + x), Math.round(backgroundPositioningArea.height + backgroundPositioningArea.top))
- ];
- case BACKGROUND_REPEAT.NO_REPEAT:
- return [
- new Vector(Math.round(backgroundPositioningArea.left + x), Math.round(backgroundPositioningArea.top + y)),
- new Vector(Math.round(backgroundPositioningArea.left + x + width), Math.round(backgroundPositioningArea.top + y)),
- new Vector(Math.round(backgroundPositioningArea.left + x + width), Math.round(backgroundPositioningArea.top + y + height)),
- new Vector(Math.round(backgroundPositioningArea.left + x), Math.round(backgroundPositioningArea.top + y + height))
- ];
- default:
- return [
- new Vector(Math.round(backgroundPaintingArea.left), Math.round(backgroundPaintingArea.top)),
- new Vector(Math.round(backgroundPaintingArea.left + backgroundPaintingArea.width), Math.round(backgroundPaintingArea.top)),
- new Vector(Math.round(backgroundPaintingArea.left + backgroundPaintingArea.width), Math.round(backgroundPaintingArea.height + backgroundPaintingArea.top)),
- new Vector(Math.round(backgroundPaintingArea.left), Math.round(backgroundPaintingArea.height + backgroundPaintingArea.top))
- ];
- }
- };
- var SMALL_IMAGE = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
- var SAMPLE_TEXT = 'Hidden Text';
- var FontMetrics = /** @class */ (function () {
- function FontMetrics(document) {
- this._data = {};
- this._document = document;
- }
- FontMetrics.prototype.parseMetrics = function (fontFamily, fontSize) {
- var container = this._document.createElement('div');
- var img = this._document.createElement('img');
- var span = this._document.createElement('span');
- var body = this._document.body;
- container.style.visibility = 'hidden';
- container.style.fontFamily = fontFamily;
- container.style.fontSize = fontSize;
- container.style.margin = '0';
- container.style.padding = '0';
- body.appendChild(container);
- img.src = SMALL_IMAGE;
- img.width = 1;
- img.height = 1;
- img.style.margin = '0';
- img.style.padding = '0';
- img.style.verticalAlign = 'baseline';
- span.style.fontFamily = fontFamily;
- span.style.fontSize = fontSize;
- span.style.margin = '0';
- span.style.padding = '0';
- span.appendChild(this._document.createTextNode(SAMPLE_TEXT));
- container.appendChild(span);
- container.appendChild(img);
- var baseline = img.offsetTop - span.offsetTop + 2;
- container.removeChild(span);
- container.appendChild(this._document.createTextNode(SAMPLE_TEXT));
- container.style.lineHeight = 'normal';
- img.style.verticalAlign = 'super';
- var middle = img.offsetTop - container.offsetTop + 2;
- body.removeChild(container);
- return { baseline: baseline, middle: middle };
- };
- FontMetrics.prototype.getMetrics = function (fontFamily, fontSize) {
- var key = fontFamily + " " + fontSize;
- if (typeof this._data[key] === 'undefined') {
- this._data[key] = this.parseMetrics(fontFamily, fontSize);
- }
- return this._data[key];
- };
- return FontMetrics;
- }());
- var MASK_OFFSET = 10000;
- var CanvasRenderer = /** @class */ (function () {
- function CanvasRenderer(options) {
- this._activeEffects = [];
- this.canvas = options.canvas ? options.canvas : document.createElement('canvas');
- this.ctx = this.canvas.getContext('2d');
- this.options = options;
- if (!options.canvas) {
- this.canvas.width = Math.floor(options.width * options.scale);
- this.canvas.height = Math.floor(options.height * options.scale);
- this.canvas.style.width = options.width + "px";
- this.canvas.style.height = options.height + "px";
- }
- this.fontMetrics = new FontMetrics(document);
- this.ctx.scale(this.options.scale, this.options.scale);
- this.ctx.translate(-options.x + options.scrollX, -options.y + options.scrollY);
- this.ctx.textBaseline = 'bottom';
- this._activeEffects = [];
- Logger.getInstance(options.id).debug("Canvas renderer initialized (" + options.width + "x" + options.height + " at " + options.x + "," + options.y + ") with scale " + options.scale);
- }
- CanvasRenderer.prototype.applyEffects = function (effects, target) {
- var _this = this;
- while (this._activeEffects.length) {
- this.popEffect();
- }
- effects.filter(function (effect) { return contains(effect.target, target); }).forEach(function (effect) { return _this.applyEffect(effect); });
- };
- CanvasRenderer.prototype.applyEffect = function (effect) {
- this.ctx.save();
- if (isTransformEffect(effect)) {
- this.ctx.translate(effect.offsetX, effect.offsetY);
- this.ctx.transform(effect.matrix[0], effect.matrix[1], effect.matrix[2], effect.matrix[3], effect.matrix[4], effect.matrix[5]);
- this.ctx.translate(-effect.offsetX, -effect.offsetY);
- }
- if (isClipEffect(effect)) {
- this.path(effect.path);
- this.ctx.clip();
- }
- this._activeEffects.push(effect);
- };
- CanvasRenderer.prototype.popEffect = function () {
- this._activeEffects.pop();
- this.ctx.restore();
- };
- CanvasRenderer.prototype.renderStack = function (stack) {
- return __awaiter(this, void 0, void 0, function () {
- var styles;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- styles = stack.element.container.styles;
- if (!styles.isVisible()) return [3 /*break*/, 2];
- this.ctx.globalAlpha = styles.opacity;
- return [4 /*yield*/, this.renderStackContent(stack)];
- case 1:
- _a.sent();
- _a.label = 2;
- case 2: return [2 /*return*/];
- }
- });
- });
- };
- CanvasRenderer.prototype.renderNode = function (paint) {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!paint.container.styles.isVisible()) return [3 /*break*/, 3];
- return [4 /*yield*/, this.renderNodeBackgroundAndBorders(paint)];
- case 1:
- _a.sent();
- return [4 /*yield*/, this.renderNodeContent(paint)];
- case 2:
- _a.sent();
- _a.label = 3;
- case 3: return [2 /*return*/];
- }
- });
- });
- };
- CanvasRenderer.prototype.renderTextWithLetterSpacing = function (text, letterSpacing) {
- var _this = this;
- if (letterSpacing === 0) {
- this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + text.bounds.height);
- }
- else {
- var letters = toCodePoints(text.text).map(function (i) { return fromCodePoint(i); });
- letters.reduce(function (left, letter) {
- _this.ctx.fillText(letter, left, text.bounds.top + text.bounds.height);
- return left + _this.ctx.measureText(letter).width;
- }, text.bounds.left);
- }
- };
- CanvasRenderer.prototype.createFontStyle = function (styles) {
- var fontVariant = styles.fontVariant
- .filter(function (variant) { return variant === 'normal' || variant === 'small-caps'; })
- .join('');
- var fontFamily = styles.fontFamily.join(', ');
- var fontSize = isDimensionToken(styles.fontSize)
- ? "" + styles.fontSize.number + styles.fontSize.unit
- : styles.fontSize.number + "px";
- return [
- [styles.fontStyle, fontVariant, styles.fontWeight, fontSize, fontFamily].join(' '),
- fontFamily,
- fontSize
- ];
- };
- CanvasRenderer.prototype.renderTextNode = function (text, styles) {
- return __awaiter(this, void 0, void 0, function () {
- var _a, font, fontFamily, fontSize;
- var _this = this;
- return __generator(this, function (_b) {
- _a = this.createFontStyle(styles), font = _a[0], fontFamily = _a[1], fontSize = _a[2];
- this.ctx.font = font;
- text.textBounds.forEach(function (text) {
- _this.ctx.fillStyle = asString(styles.color);
- _this.renderTextWithLetterSpacing(text, styles.letterSpacing);
- var textShadows = styles.textShadow;
- if (textShadows.length && text.text.trim().length) {
- textShadows
- .slice(0)
- .reverse()
- .forEach(function (textShadow) {
- _this.ctx.shadowColor = asString(textShadow.color);
- _this.ctx.shadowOffsetX = textShadow.offsetX.number * _this.options.scale;
- _this.ctx.shadowOffsetY = textShadow.offsetY.number * _this.options.scale;
- _this.ctx.shadowBlur = textShadow.blur.number;
- _this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + text.bounds.height);
- });
- _this.ctx.shadowColor = '';
- _this.ctx.shadowOffsetX = 0;
- _this.ctx.shadowOffsetY = 0;
- _this.ctx.shadowBlur = 0;
- }
- if (styles.textDecorationLine.length) {
- _this.ctx.fillStyle = asString(styles.textDecorationColor || styles.color);
- styles.textDecorationLine.forEach(function (textDecorationLine) {
- switch (textDecorationLine) {
- case 1 /* UNDERLINE */:
- // Draws a line at the baseline of the font
- // TODO As some browsers display the line as more than 1px if the font-size is big,
- // need to take that into account both in position and size
- var baseline = _this.fontMetrics.getMetrics(fontFamily, fontSize).baseline;
- _this.ctx.fillRect(text.bounds.left, Math.round(text.bounds.top + baseline), text.bounds.width, 1);
- break;
- case 2 /* OVERLINE */:
- _this.ctx.fillRect(text.bounds.left, Math.round(text.bounds.top), text.bounds.width, 1);
- break;
- case 3 /* LINE_THROUGH */:
- // TODO try and find exact position for line-through
- var middle = _this.fontMetrics.getMetrics(fontFamily, fontSize).middle;
- _this.ctx.fillRect(text.bounds.left, Math.ceil(text.bounds.top + middle), text.bounds.width, 1);
- break;
- }
- });
- }
- });
- return [2 /*return*/];
- });
- });
- };
- CanvasRenderer.prototype.renderReplacedElement = function (container, curves, image) {
- if (image && container.intrinsicWidth > 0 && container.intrinsicHeight > 0) {
- var box = contentBox(container);
- var path = calculatePaddingBoxPath(curves);
- this.path(path);
- this.ctx.save();
- this.ctx.clip();
- this.ctx.drawImage(image, 0, 0, container.intrinsicWidth, container.intrinsicHeight, box.left, box.top, box.width, box.height);
- this.ctx.restore();
- }
- };
- CanvasRenderer.prototype.renderNodeContent = function (paint) {
- return __awaiter(this, void 0, void 0, function () {
- var container, curves, styles, _i, _a, child, image, e_1, image, e_2, iframeRenderer, canvas, size, bounds, x, textBounds, img, image, url, e_3, bounds;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- this.applyEffects(paint.effects, 4 /* CONTENT */);
- container = paint.container;
- curves = paint.curves;
- styles = container.styles;
- _i = 0, _a = container.textNodes;
- _b.label = 1;
- case 1:
- if (!(_i < _a.length)) return [3 /*break*/, 4];
- child = _a[_i];
- return [4 /*yield*/, this.renderTextNode(child, styles)];
- case 2:
- _b.sent();
- _b.label = 3;
- case 3:
- _i++;
- return [3 /*break*/, 1];
- case 4:
- if (!(container instanceof ImageElementContainer)) return [3 /*break*/, 8];
- _b.label = 5;
- case 5:
- _b.trys.push([5, 7, , 8]);
- return [4 /*yield*/, this.options.cache.match(container.src)];
- case 6:
- image = _b.sent();
- this.renderReplacedElement(container, curves, image);
- return [3 /*break*/, 8];
- case 7:
- e_1 = _b.sent();
- Logger.getInstance(this.options.id).error("Error loading image " + container.src);
- return [3 /*break*/, 8];
- case 8:
- if (container instanceof CanvasElementContainer) {
- this.renderReplacedElement(container, curves, container.canvas);
- }
- if (!(container instanceof SVGElementContainer)) return [3 /*break*/, 12];
- _b.label = 9;
- case 9:
- _b.trys.push([9, 11, , 12]);
- return [4 /*yield*/, this.options.cache.match(container.svg)];
- case 10:
- image = _b.sent();
- this.renderReplacedElement(container, curves, image);
- return [3 /*break*/, 12];
- case 11:
- e_2 = _b.sent();
- Logger.getInstance(this.options.id).error("Error loading svg " + container.svg.substring(0, 255));
- return [3 /*break*/, 12];
- case 12:
- if (!(container instanceof IFrameElementContainer && container.tree)) return [3 /*break*/, 14];
- iframeRenderer = new CanvasRenderer({
- id: this.options.id,
- scale: this.options.scale,
- backgroundColor: container.backgroundColor,
- x: 0,
- y: 0,
- scrollX: 0,
- scrollY: 0,
- width: container.width,
- height: container.height,
- cache: this.options.cache,
- windowWidth: container.width,
- windowHeight: container.height
- });
- return [4 /*yield*/, iframeRenderer.render(container.tree)];
- case 13:
- canvas = _b.sent();
- if (container.width && container.height) {
- this.ctx.drawImage(canvas, 0, 0, container.width, container.height, container.bounds.left, container.bounds.top, container.bounds.width, container.bounds.height);
- }
- _b.label = 14;
- case 14:
- if (container instanceof InputElementContainer) {
- size = Math.min(container.bounds.width, container.bounds.height);
- if (container.type === CHECKBOX) {
- if (container.checked) {
- this.ctx.save();
- this.path([
- new Vector(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79),
- new Vector(container.bounds.left + size * 0.16, container.bounds.top + size * 0.5549),
- new Vector(container.bounds.left + size * 0.27347, container.bounds.top + size * 0.44071),
- new Vector(container.bounds.left + size * 0.39694, container.bounds.top + size * 0.5649),
- new Vector(container.bounds.left + size * 0.72983, container.bounds.top + size * 0.23),
- new Vector(container.bounds.left + size * 0.84, container.bounds.top + size * 0.34085),
- new Vector(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79)
- ]);
- this.ctx.fillStyle = asString(INPUT_COLOR);
- this.ctx.fill();
- this.ctx.restore();
- }
- }
- else if (container.type === RADIO) {
- if (container.checked) {
- this.ctx.save();
- this.ctx.beginPath();
- this.ctx.arc(container.bounds.left + size / 2, container.bounds.top + size / 2, size / 4, 0, Math.PI * 2, true);
- this.ctx.fillStyle = asString(INPUT_COLOR);
- this.ctx.fill();
- this.ctx.restore();
- }
- }
- }
- if (isTextInputElement(container) && container.value.length) {
- this.ctx.font = this.createFontStyle(styles)[0];
- this.ctx.fillStyle = asString(styles.color);
- this.ctx.textBaseline = 'middle';
- this.ctx.textAlign = canvasTextAlign(container.styles.textAlign);
- bounds = contentBox(container);
- x = 0;
- switch (container.styles.textAlign) {
- case TEXT_ALIGN.CENTER:
- x += bounds.width / 2;
- break;
- case TEXT_ALIGN.RIGHT:
- x += bounds.width;
- break;
- }
- textBounds = bounds.add(x, 0, 0, -bounds.height / 2 + 1);
- this.ctx.save();
- this.path([
- new Vector(bounds.left, bounds.top),
- new Vector(bounds.left + bounds.width, bounds.top),
- new Vector(bounds.left + bounds.width, bounds.top + bounds.height),
- new Vector(bounds.left, bounds.top + bounds.height)
- ]);
- this.ctx.clip();
- this.renderTextWithLetterSpacing(new TextBounds(container.value, textBounds), styles.letterSpacing);
- this.ctx.restore();
- this.ctx.textBaseline = 'bottom';
- this.ctx.textAlign = 'left';
- }
- if (!contains(container.styles.display, 2048 /* LIST_ITEM */)) return [3 /*break*/, 20];
- if (!(container.styles.listStyleImage !== null)) return [3 /*break*/, 19];
- img = container.styles.listStyleImage;
- if (!(img.type === CSSImageType.URL)) return [3 /*break*/, 18];
- image = void 0;
- url = img.url;
- _b.label = 15;
- case 15:
- _b.trys.push([15, 17, , 18]);
- return [4 /*yield*/, this.options.cache.match(url)];
- case 16:
- image = _b.sent();
- this.ctx.drawImage(image, container.bounds.left - (image.width + 10), container.bounds.top);
- return [3 /*break*/, 18];
- case 17:
- e_3 = _b.sent();
- Logger.getInstance(this.options.id).error("Error loading list-style-image " + url);
- return [3 /*break*/, 18];
- case 18: return [3 /*break*/, 20];
- case 19:
- if (paint.listValue && container.styles.listStyleType !== LIST_STYLE_TYPE.NONE) {
- this.ctx.font = this.createFontStyle(styles)[0];
- this.ctx.fillStyle = asString(styles.color);
- this.ctx.textBaseline = 'middle';
- this.ctx.textAlign = 'right';
- bounds = new Bounds(container.bounds.left, container.bounds.top + getAbsoluteValue(container.styles.paddingTop, container.bounds.width), container.bounds.width, computeLineHeight(styles.lineHeight, styles.fontSize.number) / 2 + 1);
- this.renderTextWithLetterSpacing(new TextBounds(paint.listValue, bounds), styles.letterSpacing);
- this.ctx.textBaseline = 'bottom';
- this.ctx.textAlign = 'left';
- }
- _b.label = 20;
- case 20: return [2 /*return*/];
- }
- });
- });
- };
- CanvasRenderer.prototype.renderStackContent = function (stack) {
- return __awaiter(this, void 0, void 0, function () {
- var _i, _a, child, _b, _c, child, _d, _e, child, _f, _g, child, _h, _j, child, _k, _l, child, _m, _o, child;
- return __generator(this, function (_p) {
- switch (_p.label) {
- case 0:
- // https://www.w3.org/TR/css-position-3/#painting-order
- // 1. the background and borders of the element forming the stacking context.
- return [4 /*yield*/, this.renderNodeBackgroundAndBorders(stack.element)];
- case 1:
- // https://www.w3.org/TR/css-position-3/#painting-order
- // 1. the background and borders of the element forming the stacking context.
- _p.sent();
- _i = 0, _a = stack.negativeZIndex;
- _p.label = 2;
- case 2:
- if (!(_i < _a.length)) return [3 /*break*/, 5];
- child = _a[_i];
- return [4 /*yield*/, this.renderStack(child)];
- case 3:
- _p.sent();
- _p.label = 4;
- case 4:
- _i++;
- return [3 /*break*/, 2];
- case 5:
- // 3. For all its in-flow, non-positioned, block-level descendants in tree order:
- return [4 /*yield*/, this.renderNodeContent(stack.element)];
- case 6:
- // 3. For all its in-flow, non-positioned, block-level descendants in tree order:
- _p.sent();
- _b = 0, _c = stack.nonInlineLevel;
- _p.label = 7;
- case 7:
- if (!(_b < _c.length)) return [3 /*break*/, 10];
- child = _c[_b];
- return [4 /*yield*/, this.renderNode(child)];
- case 8:
- _p.sent();
- _p.label = 9;
- case 9:
- _b++;
- return [3 /*break*/, 7];
- case 10:
- _d = 0, _e = stack.nonPositionedFloats;
- _p.label = 11;
- case 11:
- if (!(_d < _e.length)) return [3 /*break*/, 14];
- child = _e[_d];
- return [4 /*yield*/, this.renderStack(child)];
- case 12:
- _p.sent();
- _p.label = 13;
- case 13:
- _d++;
- return [3 /*break*/, 11];
- case 14:
- _f = 0, _g = stack.nonPositionedInlineLevel;
- _p.label = 15;
- case 15:
- if (!(_f < _g.length)) return [3 /*break*/, 18];
- child = _g[_f];
- return [4 /*yield*/, this.renderStack(child)];
- case 16:
- _p.sent();
- _p.label = 17;
- case 17:
- _f++;
- return [3 /*break*/, 15];
- case 18:
- _h = 0, _j = stack.inlineLevel;
- _p.label = 19;
- case 19:
- if (!(_h < _j.length)) return [3 /*break*/, 22];
- child = _j[_h];
- return [4 /*yield*/, this.renderNode(child)];
- case 20:
- _p.sent();
- _p.label = 21;
- case 21:
- _h++;
- return [3 /*break*/, 19];
- case 22:
- _k = 0, _l = stack.zeroOrAutoZIndexOrTransformedOrOpacity;
- _p.label = 23;
- case 23:
- if (!(_k < _l.length)) return [3 /*break*/, 26];
- child = _l[_k];
- return [4 /*yield*/, this.renderStack(child)];
- case 24:
- _p.sent();
- _p.label = 25;
- case 25:
- _k++;
- return [3 /*break*/, 23];
- case 26:
- _m = 0, _o = stack.positiveZIndex;
- _p.label = 27;
- case 27:
- if (!(_m < _o.length)) return [3 /*break*/, 30];
- child = _o[_m];
- return [4 /*yield*/, this.renderStack(child)];
- case 28:
- _p.sent();
- _p.label = 29;
- case 29:
- _m++;
- return [3 /*break*/, 27];
- case 30: return [2 /*return*/];
- }
- });
- });
- };
- CanvasRenderer.prototype.mask = function (paths) {
- this.ctx.beginPath();
- this.ctx.moveTo(0, 0);
- this.ctx.lineTo(this.canvas.width, 0);
- this.ctx.lineTo(this.canvas.width, this.canvas.height);
- this.ctx.lineTo(0, this.canvas.height);
- this.ctx.lineTo(0, 0);
- this.formatPath(paths.slice(0).reverse());
- this.ctx.closePath();
- };
- CanvasRenderer.prototype.path = function (paths) {
- this.ctx.beginPath();
- this.formatPath(paths);
- this.ctx.closePath();
- };
- CanvasRenderer.prototype.formatPath = function (paths) {
- var _this = this;
- paths.forEach(function (point, index) {
- var start = isBezierCurve(point) ? point.start : point;
- if (index === 0) {
- _this.ctx.moveTo(start.x, start.y);
- }
- else {
- _this.ctx.lineTo(start.x, start.y);
- }
- if (isBezierCurve(point)) {
- _this.ctx.bezierCurveTo(point.startControl.x, point.startControl.y, point.endControl.x, point.endControl.y, point.end.x, point.end.y);
- }
- });
- };
- CanvasRenderer.prototype.renderRepeat = function (path, pattern, offsetX, offsetY) {
- this.path(path);
- this.ctx.fillStyle = pattern;
- this.ctx.translate(offsetX, offsetY);
- this.ctx.fill();
- this.ctx.translate(-offsetX, -offsetY);
- };
- CanvasRenderer.prototype.resizeImage = function (image, width, height) {
- if (image.width === width && image.height === height) {
- return image;
- }
- var canvas = this.canvas.ownerDocument.createElement('canvas');
- canvas.width = width;
- canvas.height = height;
- var ctx = canvas.getContext('2d');
- ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, width, height);
- return canvas;
- };
- CanvasRenderer.prototype.renderBackgroundImage = function (container) {
- return __awaiter(this, void 0, void 0, function () {
- var index, _loop_1, this_1, _i, _a, backgroundImage;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- index = container.styles.backgroundImage.length - 1;
- _loop_1 = function (backgroundImage) {
- var image, url, e_4, _a, path, x, y, width, height, pattern, _b, path, x, y, width, height, _c, lineLength, x0, x1, y0, y1, canvas, ctx, gradient_1, pattern, _d, path, left, top_1, width, height, position, x, y, _e, rx, ry, radialGradient_1, midX, midY, f, invF;
- return __generator(this, function (_f) {
- switch (_f.label) {
- case 0:
- if (!(backgroundImage.type === CSSImageType.URL)) return [3 /*break*/, 5];
- image = void 0;
- url = backgroundImage.url;
- _f.label = 1;
- case 1:
- _f.trys.push([1, 3, , 4]);
- return [4 /*yield*/, this_1.options.cache.match(url)];
- case 2:
- image = _f.sent();
- return [3 /*break*/, 4];
- case 3:
- e_4 = _f.sent();
- Logger.getInstance(this_1.options.id).error("Error loading background-image " + url);
- return [3 /*break*/, 4];
- case 4:
- if (image) {
- _a = calculateBackgroundRendering(container, index, [
- image.width,
- image.height,
- image.width / image.height
- ]), path = _a[0], x = _a[1], y = _a[2], width = _a[3], height = _a[4];
- pattern = this_1.ctx.createPattern(this_1.resizeImage(image, width, height), 'repeat');
- this_1.renderRepeat(path, pattern, x, y);
- }
- return [3 /*break*/, 6];
- case 5:
- if (isLinearGradient(backgroundImage)) {
- _b = calculateBackgroundRendering(container, index, [null, null, null]), path = _b[0], x = _b[1], y = _b[2], width = _b[3], height = _b[4];
- _c = calculateGradientDirection(backgroundImage.angle, width, height), lineLength = _c[0], x0 = _c[1], x1 = _c[2], y0 = _c[3], y1 = _c[4];
- canvas = document.createElement('canvas');
- canvas.width = width;
- canvas.height = height;
- ctx = canvas.getContext('2d');
- gradient_1 = ctx.createLinearGradient(x0, y0, x1, y1);
- processColorStops(backgroundImage.stops, lineLength).forEach(function (colorStop) {
- return gradient_1.addColorStop(colorStop.stop, asString(colorStop.color));
- });
- ctx.fillStyle = gradient_1;
- ctx.fillRect(0, 0, width, height);
- if (width > 0 && height > 0) {
- pattern = this_1.ctx.createPattern(canvas, 'repeat');
- this_1.renderRepeat(path, pattern, x, y);
- }
- }
- else if (isRadialGradient(backgroundImage)) {
- _d = calculateBackgroundRendering(container, index, [
- null,
- null,
- null
- ]), path = _d[0], left = _d[1], top_1 = _d[2], width = _d[3], height = _d[4];
- position = backgroundImage.position.length === 0 ? [FIFTY_PERCENT] : backgroundImage.position;
- x = getAbsoluteValue(position[0], width);
- y = getAbsoluteValue(position[position.length - 1], height);
- _e = calculateRadius(backgroundImage, x, y, width, height), rx = _e[0], ry = _e[1];
- if (rx > 0 && rx > 0) {
- radialGradient_1 = this_1.ctx.createRadialGradient(left + x, top_1 + y, 0, left + x, top_1 + y, rx);
- processColorStops(backgroundImage.stops, rx * 2).forEach(function (colorStop) {
- return radialGradient_1.addColorStop(colorStop.stop, asString(colorStop.color));
- });
- this_1.path(path);
- this_1.ctx.fillStyle = radialGradient_1;
- if (rx !== ry) {
- midX = container.bounds.left + 0.5 * container.bounds.width;
- midY = container.bounds.top + 0.5 * container.bounds.height;
- f = ry / rx;
- invF = 1 / f;
- this_1.ctx.save();
- this_1.ctx.translate(midX, midY);
- this_1.ctx.transform(1, 0, 0, f, 0, 0);
- this_1.ctx.translate(-midX, -midY);
- this_1.ctx.fillRect(left, invF * (top_1 - midY) + midY, width, height * invF);
- this_1.ctx.restore();
- }
- else {
- this_1.ctx.fill();
- }
- }
- }
- _f.label = 6;
- case 6:
- index--;
- return [2 /*return*/];
- }
- });
- };
- this_1 = this;
- _i = 0, _a = container.styles.backgroundImage.slice(0).reverse();
- _b.label = 1;
- case 1:
- if (!(_i < _a.length)) return [3 /*break*/, 4];
- backgroundImage = _a[_i];
- return [5 /*yield**/, _loop_1(backgroundImage)];
- case 2:
- _b.sent();
- _b.label = 3;
- case 3:
- _i++;
- return [3 /*break*/, 1];
- case 4: return [2 /*return*/];
- }
- });
- });
- };
- CanvasRenderer.prototype.renderBorder = function (color, side, curvePoints) {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- this.path(parsePathForBorder(curvePoints, side));
- this.ctx.fillStyle = asString(color);
- this.ctx.fill();
- return [2 /*return*/];
- });
- });
- };
- CanvasRenderer.prototype.renderNodeBackgroundAndBorders = function (paint) {
- return __awaiter(this, void 0, void 0, function () {
- var styles, hasBackground, borders, backgroundPaintingArea, side, _i, borders_1, border;
- var _this = this;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- this.applyEffects(paint.effects, 2 /* BACKGROUND_BORDERS */);
- styles = paint.container.styles;
- hasBackground = !isTransparent(styles.backgroundColor) || styles.backgroundImage.length;
- borders = [
- { style: styles.borderTopStyle, color: styles.borderTopColor },
- { style: styles.borderRightStyle, color: styles.borderRightColor },
- { style: styles.borderBottomStyle, color: styles.borderBottomColor },
- { style: styles.borderLeftStyle, color: styles.borderLeftColor }
- ];
- backgroundPaintingArea = calculateBackgroundCurvedPaintingArea(getBackgroundValueForIndex(styles.backgroundClip, 0), paint.curves);
- if (!(hasBackground || styles.boxShadow.length)) return [3 /*break*/, 2];
- this.ctx.save();
- this.path(backgroundPaintingArea);
- this.ctx.clip();
- if (!isTransparent(styles.backgroundColor)) {
- this.ctx.fillStyle = asString(styles.backgroundColor);
- this.ctx.fill();
- }
- return [4 /*yield*/, this.renderBackgroundImage(paint.container)];
- case 1:
- _a.sent();
- this.ctx.restore();
- styles.boxShadow
- .slice(0)
- .reverse()
- .forEach(function (shadow) {
- _this.ctx.save();
- var borderBoxArea = calculateBorderBoxPath(paint.curves);
- var maskOffset = shadow.inset ? 0 : MASK_OFFSET;
- var shadowPaintingArea = transformPath(borderBoxArea, -maskOffset + (shadow.inset ? 1 : -1) * shadow.spread.number, (shadow.inset ? 1 : -1) * shadow.spread.number, shadow.spread.number * (shadow.inset ? -2 : 2), shadow.spread.number * (shadow.inset ? -2 : 2));
- if (shadow.inset) {
- _this.path(borderBoxArea);
- _this.ctx.clip();
- _this.mask(shadowPaintingArea);
- }
- else {
- _this.mask(borderBoxArea);
- _this.ctx.clip();
- _this.path(shadowPaintingArea);
- }
- _this.ctx.shadowOffsetX = shadow.offsetX.number + maskOffset;
- _this.ctx.shadowOffsetY = shadow.offsetY.number;
- _this.ctx.shadowColor = asString(shadow.color);
- _this.ctx.shadowBlur = shadow.blur.number;
- _this.ctx.fillStyle = shadow.inset ? asString(shadow.color) : 'rgba(0,0,0,1)';
- _this.ctx.fill();
- _this.ctx.restore();
- });
- _a.label = 2;
- case 2:
- side = 0;
- _i = 0, borders_1 = borders;
- _a.label = 3;
- case 3:
- if (!(_i < borders_1.length)) return [3 /*break*/, 7];
- border = borders_1[_i];
- if (!(border.style !== BORDER_STYLE.NONE && !isTransparent(border.color))) return [3 /*break*/, 5];
- return [4 /*yield*/, this.renderBorder(border.color, side, paint.curves)];
- case 4:
- _a.sent();
- _a.label = 5;
- case 5:
- side++;
- _a.label = 6;
- case 6:
- _i++;
- return [3 /*break*/, 3];
- case 7: return [2 /*return*/];
- }
- });
- });
- };
- CanvasRenderer.prototype.render = function (element) {
- return __awaiter(this, void 0, void 0, function () {
- var stack;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (this.options.backgroundColor) {
- this.ctx.fillStyle = asString(this.options.backgroundColor);
- this.ctx.fillRect(this.options.x - this.options.scrollX, this.options.y - this.options.scrollY, this.options.width, this.options.height);
- }
- stack = parseStackingContexts(element);
- return [4 /*yield*/, this.renderStack(stack)];
- case 1:
- _a.sent();
- this.applyEffects([], 2 /* BACKGROUND_BORDERS */);
- return [2 /*return*/, this.canvas];
- }
- });
- });
- };
- return CanvasRenderer;
- }());
- var isTextInputElement = function (container) {
- if (container instanceof TextareaElementContainer) {
- return true;
- }
- else if (container instanceof SelectElementContainer) {
- return true;
- }
- else if (container instanceof InputElementContainer && container.type !== RADIO && container.type !== CHECKBOX) {
- return true;
- }
- return false;
- };
- var calculateBackgroundCurvedPaintingArea = function (clip, curves) {
- switch (clip) {
- case BACKGROUND_CLIP.BORDER_BOX:
- return calculateBorderBoxPath(curves);
- case BACKGROUND_CLIP.CONTENT_BOX:
- return calculateContentBoxPath(curves);
- case BACKGROUND_CLIP.PADDING_BOX:
- default:
- return calculatePaddingBoxPath(curves);
- }
- };
- var canvasTextAlign = function (textAlign) {
- switch (textAlign) {
- case TEXT_ALIGN.CENTER:
- return 'center';
- case TEXT_ALIGN.RIGHT:
- return 'right';
- case TEXT_ALIGN.LEFT:
- default:
- return 'left';
- }
- };
- var ForeignObjectRenderer = /** @class */ (function () {
- function ForeignObjectRenderer(options) {
- this.canvas = options.canvas ? options.canvas : document.createElement('canvas');
- this.ctx = this.canvas.getContext('2d');
- this.options = options;
- this.canvas.width = Math.floor(options.width * options.scale);
- this.canvas.height = Math.floor(options.height * options.scale);
- this.canvas.style.width = options.width + "px";
- this.canvas.style.height = options.height + "px";
- this.ctx.scale(this.options.scale, this.options.scale);
- this.ctx.translate(-options.x + options.scrollX, -options.y + options.scrollY);
- Logger.getInstance(options.id).debug("EXPERIMENTAL ForeignObject renderer initialized (" + options.width + "x" + options.height + " at " + options.x + "," + options.y + ") with scale " + options.scale);
- }
- ForeignObjectRenderer.prototype.render = function (element) {
- return __awaiter(this, void 0, void 0, function () {
- var svg, img;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- svg = createForeignObjectSVG(Math.max(this.options.windowWidth, this.options.width) * this.options.scale, Math.max(this.options.windowHeight, this.options.height) * this.options.scale, this.options.scrollX * this.options.scale, this.options.scrollY * this.options.scale, element);
- return [4 /*yield*/, loadSerializedSVG$1(svg)];
- case 1:
- img = _a.sent();
- if (this.options.backgroundColor) {
- this.ctx.fillStyle = asString(this.options.backgroundColor);
- this.ctx.fillRect(0, 0, this.options.width * this.options.scale, this.options.height * this.options.scale);
- }
- this.ctx.drawImage(img, -this.options.x * this.options.scale, -this.options.y * this.options.scale);
- return [2 /*return*/, this.canvas];
- }
- });
- });
- };
- return ForeignObjectRenderer;
- }());
- var loadSerializedSVG$1 = function (svg) {
- return new Promise(function (resolve, reject) {
- var img = new Image();
- img.onload = function () {
- resolve(img);
- };
- img.onerror = reject;
- img.src = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(new XMLSerializer().serializeToString(svg));
- });
- };
- var _this = undefined;
- var parseColor$1 = function (value) { return color.parse(Parser.create(value).parseComponentValue()); };
- var html2canvas = function (element, options) {
- if (options === void 0) { options = {}; }
- return renderElement(element, options);
- };
- if (typeof window !== 'undefined') {
- CacheStorage.setContext(window);
- }
- var renderElement = function (element, opts) { return __awaiter(_this, void 0, void 0, function () {
- var ownerDocument, defaultView, instanceName, _a, width, height, left, top, defaultResourceOptions, resourceOptions, defaultOptions, options, windowBounds, documentCloner, clonedElement, container, documentBackgroundColor, bodyBackgroundColor, bgColor, defaultBackgroundColor, backgroundColor, renderOptions, canvas, renderer, root, renderer;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- ownerDocument = element.ownerDocument;
- if (!ownerDocument) {
- throw new Error("Element is not attached to a Document");
- }
- defaultView = ownerDocument.defaultView;
- if (!defaultView) {
- throw new Error("Document is not attached to a Window");
- }
- instanceName = (Math.round(Math.random() * 1000) + Date.now()).toString(16);
- _a = isBodyElement(element) || isHTMLElement(element) ? parseDocumentSize(ownerDocument) : parseBounds(element), width = _a.width, height = _a.height, left = _a.left, top = _a.top;
- defaultResourceOptions = {
- allowTaint: false,
- imageTimeout: 15000,
- proxy: undefined,
- useCORS: false
- };
- resourceOptions = __assign({}, defaultResourceOptions, opts);
- defaultOptions = {
- backgroundColor: '#ffffff',
- cache: opts.cache ? opts.cache : CacheStorage.create(instanceName, resourceOptions),
- logging: true,
- removeContainer: true,
- foreignObjectRendering: false,
- scale: defaultView.devicePixelRatio || 1,
- windowWidth: defaultView.innerWidth,
- windowHeight: defaultView.innerHeight,
- scrollX: defaultView.pageXOffset,
- scrollY: defaultView.pageYOffset,
- x: left,
- y: top,
- width: Math.ceil(width),
- height: Math.ceil(height),
- id: instanceName
- };
- options = __assign({}, defaultOptions, resourceOptions, opts);
- windowBounds = new Bounds(options.scrollX, options.scrollY, options.windowWidth, options.windowHeight);
- Logger.create({ id: instanceName, enabled: options.logging });
- Logger.getInstance(instanceName).debug("Starting document clone");
- documentCloner = new DocumentCloner(element, {
- id: instanceName,
- onclone: options.onclone,
- ignoreElements: options.ignoreElements,
- inlineImages: options.foreignObjectRendering,
- copyStyles: options.foreignObjectRendering
- });
- clonedElement = documentCloner.clonedReferenceElement;
- if (!clonedElement) {
- return [2 /*return*/, Promise.reject("Unable to find element in cloned iframe")];
- }
- return [4 /*yield*/, documentCloner.toIFrame(ownerDocument, windowBounds)];
- case 1:
- container = _b.sent();
- documentBackgroundColor = ownerDocument.documentElement
- ? parseColor$1(getComputedStyle(ownerDocument.documentElement).backgroundColor)
- : COLORS.TRANSPARENT;
- bodyBackgroundColor = ownerDocument.body
- ? parseColor$1(getComputedStyle(ownerDocument.body).backgroundColor)
- : COLORS.TRANSPARENT;
- bgColor = opts.backgroundColor;
- defaultBackgroundColor = typeof bgColor === 'string' ? parseColor$1(bgColor) : bgColor === null ? COLORS.TRANSPARENT : 0xffffffff;
- backgroundColor = element === ownerDocument.documentElement
- ? isTransparent(documentBackgroundColor)
- ? isTransparent(bodyBackgroundColor)
- ? defaultBackgroundColor
- : bodyBackgroundColor
- : documentBackgroundColor
- : defaultBackgroundColor;
- renderOptions = {
- id: instanceName,
- cache: options.cache,
- canvas: options.canvas,
- backgroundColor: backgroundColor,
- scale: options.scale,
- x: options.x,
- y: options.y,
- scrollX: options.scrollX,
- scrollY: options.scrollY,
- width: options.width,
- height: options.height,
- windowWidth: options.windowWidth,
- windowHeight: options.windowHeight
- };
- if (!options.foreignObjectRendering) return [3 /*break*/, 3];
- Logger.getInstance(instanceName).debug("Document cloned, using foreign object rendering");
- renderer = new ForeignObjectRenderer(renderOptions);
- return [4 /*yield*/, renderer.render(clonedElement)];
- case 2:
- canvas = _b.sent();
- return [3 /*break*/, 5];
- case 3:
- Logger.getInstance(instanceName).debug("Document cloned, using computed rendering");
- CacheStorage.attachInstance(options.cache);
- Logger.getInstance(instanceName).debug("Starting DOM parsing");
- root = parseTree(clonedElement);
- CacheStorage.detachInstance();
- if (backgroundColor === root.styles.backgroundColor) {
- root.styles.backgroundColor = COLORS.TRANSPARENT;
- }
- Logger.getInstance(instanceName).debug("Starting renderer");
- renderer = new CanvasRenderer(renderOptions);
- return [4 /*yield*/, renderer.render(root)];
- case 4:
- canvas = _b.sent();
- _b.label = 5;
- case 5:
- if (options.removeContainer === true) {
- if (!DocumentCloner.destroy(container)) {
- Logger.getInstance(instanceName).error("Cannot detach cloned iframe as it is not in the DOM anymore");
- }
- }
- Logger.getInstance(instanceName).debug("Finished rendering");
- Logger.destroy(instanceName);
- CacheStorage.destroy(instanceName);
- return [2 /*return*/, canvas];
- }
- });
- }); };
- return html2canvas;
- }));
- },{}],214:[function(require,module,exports){
- // (c) Dean McNamee <dean@gmail.com>, 2013.
- //
- // https://github.com/deanm/omggif
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //
- // omggif is a JavaScript implementation of a GIF 89a encoder and decoder,
- // including animation and compression. It does not rely on any specific
- // underlying system, so should run in the browser, Node, or Plask.
- function GifWriter(buf, width, height, gopts) {
- var p = 0;
- var gopts = gopts === undefined ? { } : gopts;
- var loop_count = gopts.loop === undefined ? null : gopts.loop;
- var global_palette = gopts.palette === undefined ? null : gopts.palette;
- if (width <= 0 || height <= 0 || width > 65535 || height > 65535)
- throw "Width/Height invalid."
- function check_palette_and_num_colors(palette) {
- var num_colors = palette.length;
- if (num_colors < 2 || num_colors > 256 || num_colors & (num_colors-1))
- throw "Invalid code/color length, must be power of 2 and 2 .. 256.";
- return num_colors;
- }
- // - Header.
- buf[p++] = 0x47; buf[p++] = 0x49; buf[p++] = 0x46; // GIF
- buf[p++] = 0x38; buf[p++] = 0x39; buf[p++] = 0x61; // 89a
- // Handling of Global Color Table (palette) and background index.
- var gp_num_colors_pow2 = 0;
- var background = 0;
- if (global_palette !== null) {
- var gp_num_colors = check_palette_and_num_colors(global_palette);
- while (gp_num_colors >>= 1) ++gp_num_colors_pow2;
- gp_num_colors = 1 << gp_num_colors_pow2;
- --gp_num_colors_pow2;
- if (gopts.background !== undefined) {
- background = gopts.background;
- if (background >= gp_num_colors) throw "Background index out of range.";
- // The GIF spec states that a background index of 0 should be ignored, so
- // this is probably a mistake and you really want to set it to another
- // slot in the palette. But actually in the end most browsers, etc end
- // up ignoring this almost completely (including for dispose background).
- if (background === 0)
- throw "Background index explicitly passed as 0.";
- }
- }
- // - Logical Screen Descriptor.
- // NOTE(deanm): w/h apparently ignored by implementations, but set anyway.
- buf[p++] = width & 0xff; buf[p++] = width >> 8 & 0xff;
- buf[p++] = height & 0xff; buf[p++] = height >> 8 & 0xff;
- // NOTE: Indicates 0-bpp original color resolution (unused?).
- buf[p++] = (global_palette !== null ? 0x80 : 0) | // Global Color Table Flag.
- gp_num_colors_pow2; // NOTE: No sort flag (unused?).
- buf[p++] = background; // Background Color Index.
- buf[p++] = 0; // Pixel aspect ratio (unused?).
- // - Global Color Table
- if (global_palette !== null) {
- for (var i = 0, il = global_palette.length; i < il; ++i) {
- var rgb = global_palette[i];
- buf[p++] = rgb >> 16 & 0xff;
- buf[p++] = rgb >> 8 & 0xff;
- buf[p++] = rgb & 0xff;
- }
- }
- if (loop_count !== null) { // Netscape block for looping.
- if (loop_count < 0 || loop_count > 65535)
- throw "Loop count invalid."
- // Extension code, label, and length.
- buf[p++] = 0x21; buf[p++] = 0xff; buf[p++] = 0x0b;
- // NETSCAPE2.0
- buf[p++] = 0x4e; buf[p++] = 0x45; buf[p++] = 0x54; buf[p++] = 0x53;
- buf[p++] = 0x43; buf[p++] = 0x41; buf[p++] = 0x50; buf[p++] = 0x45;
- buf[p++] = 0x32; buf[p++] = 0x2e; buf[p++] = 0x30;
- // Sub-block
- buf[p++] = 0x03; buf[p++] = 0x01;
- buf[p++] = loop_count & 0xff; buf[p++] = loop_count >> 8 & 0xff;
- buf[p++] = 0x00; // Terminator.
- }
- var ended = false;
- this.addFrame = function(x, y, w, h, indexed_pixels, opts) {
- if (ended === true) { --p; ended = false; } // Un-end.
- opts = opts === undefined ? { } : opts;
- // TODO(deanm): Bounds check x, y. Do they need to be within the virtual
- // canvas width/height, I imagine?
- if (x < 0 || y < 0 || x > 65535 || y > 65535)
- throw "x/y invalid."
- if (w <= 0 || h <= 0 || w > 65535 || h > 65535)
- throw "Width/Height invalid."
- if (indexed_pixels.length < w * h)
- throw "Not enough pixels for the frame size.";
- var using_local_palette = true;
- var palette = opts.palette;
- if (palette === undefined || palette === null) {
- using_local_palette = false;
- palette = global_palette;
- }
- if (palette === undefined || palette === null)
- throw "Must supply either a local or global palette.";
- var num_colors = check_palette_and_num_colors(palette);
- // Compute the min_code_size (power of 2), destroying num_colors.
- var min_code_size = 0;
- while (num_colors >>= 1) ++min_code_size;
- num_colors = 1 << min_code_size; // Now we can easily get it back.
- var delay = opts.delay === undefined ? 0 : opts.delay;
- // From the spec:
- // 0 - No disposal specified. The decoder is
- // not required to take any action.
- // 1 - Do not dispose. The graphic is to be left
- // in place.
- // 2 - Restore to background color. The area used by the
- // graphic must be restored to the background color.
- // 3 - Restore to previous. The decoder is required to
- // restore the area overwritten by the graphic with
- // what was there prior to rendering the graphic.
- // 4-7 - To be defined.
- // NOTE(deanm): Dispose background doesn't really work, apparently most
- // browsers ignore the background palette index and clear to transparency.
- var disposal = opts.disposal === undefined ? 0 : opts.disposal;
- if (disposal < 0 || disposal > 3) // 4-7 is reserved.
- throw "Disposal out of range.";
- var use_transparency = false;
- var transparent_index = 0;
- if (opts.transparent !== undefined && opts.transparent !== null) {
- use_transparency = true;
- transparent_index = opts.transparent;
- if (transparent_index < 0 || transparent_index >= num_colors)
- throw "Transparent color index.";
- }
- if (disposal !== 0 || use_transparency || delay !== 0) {
- // - Graphics Control Extension
- buf[p++] = 0x21; buf[p++] = 0xf9; // Extension / Label.
- buf[p++] = 4; // Byte size.
- buf[p++] = disposal << 2 | (use_transparency === true ? 1 : 0);
- buf[p++] = delay & 0xff; buf[p++] = delay >> 8 & 0xff;
- buf[p++] = transparent_index; // Transparent color index.
- buf[p++] = 0; // Block Terminator.
- }
- // - Image Descriptor
- buf[p++] = 0x2c; // Image Seperator.
- buf[p++] = x & 0xff; buf[p++] = x >> 8 & 0xff; // Left.
- buf[p++] = y & 0xff; buf[p++] = y >> 8 & 0xff; // Top.
- buf[p++] = w & 0xff; buf[p++] = w >> 8 & 0xff;
- buf[p++] = h & 0xff; buf[p++] = h >> 8 & 0xff;
- // NOTE: No sort flag (unused?).
- // TODO(deanm): Support interlace.
- buf[p++] = using_local_palette === true ? (0x80 | (min_code_size-1)) : 0;
- // - Local Color Table
- if (using_local_palette === true) {
- for (var i = 0, il = palette.length; i < il; ++i) {
- var rgb = palette[i];
- buf[p++] = rgb >> 16 & 0xff;
- buf[p++] = rgb >> 8 & 0xff;
- buf[p++] = rgb & 0xff;
- }
- }
- p = GifWriterOutputLZWCodeStream(
- buf, p, min_code_size < 2 ? 2 : min_code_size, indexed_pixels);
- };
- this.end = function() {
- if (ended === false) {
- buf[p++] = 0x3b; // Trailer.
- ended = true;
- }
- return p;
- };
- }
- // Main compression routine, palette indexes -> LZW code stream.
- // |index_stream| must have at least one entry.
- function GifWriterOutputLZWCodeStream(buf, p, min_code_size, index_stream) {
- buf[p++] = min_code_size;
- var cur_subblock = p++; // Pointing at the length field.
- var clear_code = 1 << min_code_size;
- var code_mask = clear_code - 1;
- var eoi_code = clear_code + 1;
- var next_code = eoi_code + 1;
- var cur_code_size = min_code_size + 1; // Number of bits per code.
- var cur_shift = 0;
- // We have at most 12-bit codes, so we should have to hold a max of 19
- // bits here (and then we would write out).
- var cur = 0;
- function emit_bytes_to_buffer(bit_block_size) {
- while (cur_shift >= bit_block_size) {
- buf[p++] = cur & 0xff;
- cur >>= 8; cur_shift -= 8;
- if (p === cur_subblock + 256) { // Finished a subblock.
- buf[cur_subblock] = 255;
- cur_subblock = p++;
- }
- }
- }
- function emit_code(c) {
- cur |= c << cur_shift;
- cur_shift += cur_code_size;
- emit_bytes_to_buffer(8);
- }
- // I am not an expert on the topic, and I don't want to write a thesis.
- // However, it is good to outline here the basic algorithm and the few data
- // structures and optimizations here that make this implementation fast.
- // The basic idea behind LZW is to build a table of previously seen runs
- // addressed by a short id (herein called output code). All data is
- // referenced by a code, which represents one or more values from the
- // original input stream. All input bytes can be referenced as the same
- // value as an output code. So if you didn't want any compression, you
- // could more or less just output the original bytes as codes (there are
- // some details to this, but it is the idea). In order to achieve
- // compression, values greater then the input range (codes can be up to
- // 12-bit while input only 8-bit) represent a sequence of previously seen
- // inputs. The decompressor is able to build the same mapping while
- // decoding, so there is always a shared common knowledge between the
- // encoding and decoder, which is also important for "timing" aspects like
- // how to handle variable bit width code encoding.
- //
- // One obvious but very important consequence of the table system is there
- // is always a unique id (at most 12-bits) to map the runs. 'A' might be
- // 4, then 'AA' might be 10, 'AAA' 11, 'AAAA' 12, etc. This relationship
- // can be used for an effecient lookup strategy for the code mapping. We
- // need to know if a run has been seen before, and be able to map that run
- // to the output code. Since we start with known unique ids (input bytes),
- // and then from those build more unique ids (table entries), we can
- // continue this chain (almost like a linked list) to always have small
- // integer values that represent the current byte chains in the encoder.
- // This means instead of tracking the input bytes (AAAABCD) to know our
- // current state, we can track the table entry for AAAABC (it is guaranteed
- // to exist by the nature of the algorithm) and the next character D.
- // Therefor the tuple of (table_entry, byte) is guaranteed to also be
- // unique. This allows us to create a simple lookup key for mapping input
- // sequences to codes (table indices) without having to store or search
- // any of the code sequences. So if 'AAAA' has a table entry of 12, the
- // tuple of ('AAAA', K) for any input byte K will be unique, and can be our
- // key. This leads to a integer value at most 20-bits, which can always
- // fit in an SMI value and be used as a fast sparse array / object key.
- // Output code for the current contents of the index buffer.
- var ib_code = index_stream[0] & code_mask; // Load first input index.
- var code_table = { }; // Key'd on our 20-bit "tuple".
- emit_code(clear_code); // Spec says first code should be a clear code.
- // First index already loaded, process the rest of the stream.
- for (var i = 1, il = index_stream.length; i < il; ++i) {
- var k = index_stream[i] & code_mask;
- var cur_key = ib_code << 8 | k; // (prev, k) unique tuple.
- var cur_code = code_table[cur_key]; // buffer + k.
- // Check if we have to create a new code table entry.
- if (cur_code === undefined) { // We don't have buffer + k.
- // Emit index buffer (without k).
- // This is an inline version of emit_code, because this is the core
- // writing routine of the compressor (and V8 cannot inline emit_code
- // because it is a closure here in a different context). Additionally
- // we can call emit_byte_to_buffer less often, because we can have
- // 30-bits (from our 31-bit signed SMI), and we know our codes will only
- // be 12-bits, so can safely have 18-bits there without overflow.
- // emit_code(ib_code);
- cur |= ib_code << cur_shift;
- cur_shift += cur_code_size;
- while (cur_shift >= 8) {
- buf[p++] = cur & 0xff;
- cur >>= 8; cur_shift -= 8;
- if (p === cur_subblock + 256) { // Finished a subblock.
- buf[cur_subblock] = 255;
- cur_subblock = p++;
- }
- }
- if (next_code === 4096) { // Table full, need a clear.
- emit_code(clear_code);
- next_code = eoi_code + 1;
- cur_code_size = min_code_size + 1;
- code_table = { };
- } else { // Table not full, insert a new entry.
- // Increase our variable bit code sizes if necessary. This is a bit
- // tricky as it is based on "timing" between the encoding and
- // decoder. From the encoders perspective this should happen after
- // we've already emitted the index buffer and are about to create the
- // first table entry that would overflow our current code bit size.
- if (next_code >= (1 << cur_code_size)) ++cur_code_size;
- code_table[cur_key] = next_code++; // Insert into code table.
- }
- ib_code = k; // Index buffer to single input k.
- } else {
- ib_code = cur_code; // Index buffer to sequence in code table.
- }
- }
- emit_code(ib_code); // There will still be something in the index buffer.
- emit_code(eoi_code); // End Of Information.
- // Flush / finalize the sub-blocks stream to the buffer.
- emit_bytes_to_buffer(1);
- // Finish the sub-blocks, writing out any unfinished lengths and
- // terminating with a sub-block of length 0. If we have already started
- // but not yet used a sub-block it can just become the terminator.
- if (cur_subblock + 1 === p) { // Started but unused.
- buf[cur_subblock] = 0;
- } else { // Started and used, write length and additional terminator block.
- buf[cur_subblock] = p - cur_subblock - 1;
- buf[p++] = 0;
- }
- return p;
- }
- function GifReader(buf) {
- var p = 0;
- // - Header (GIF87a or GIF89a).
- if (buf[p++] !== 0x47 || buf[p++] !== 0x49 || buf[p++] !== 0x46 ||
- buf[p++] !== 0x38 || (buf[p++]+1 & 0xfd) !== 0x38 || buf[p++] !== 0x61) {
- throw "Invalid GIF 87a/89a header.";
- }
- // - Logical Screen Descriptor.
- var width = buf[p++] | buf[p++] << 8;
- var height = buf[p++] | buf[p++] << 8;
- var pf0 = buf[p++]; // <Packed Fields>.
- var global_palette_flag = pf0 >> 7;
- var num_global_colors_pow2 = pf0 & 0x7;
- var num_global_colors = 1 << (num_global_colors_pow2 + 1);
- var background = buf[p++];
- buf[p++]; // Pixel aspect ratio (unused?).
- var global_palette_offset = null;
- if (global_palette_flag) {
- global_palette_offset = p;
- p += num_global_colors * 3; // Seek past palette.
- }
- var no_eof = true;
- var frames = [ ];
- var delay = 0;
- var transparent_index = null;
- var disposal = 0; // 0 - No disposal specified.
- var loop_count = null;
- this.width = width;
- this.height = height;
- while (no_eof && p < buf.length) {
- switch (buf[p++]) {
- case 0x21: // Graphics Control Extension Block
- switch (buf[p++]) {
- case 0xff: // Application specific block
- // Try if it's a Netscape block (with animation loop counter).
- if (buf[p ] !== 0x0b || // 21 FF already read, check block size.
- // NETSCAPE2.0
- buf[p+1 ] == 0x4e && buf[p+2 ] == 0x45 && buf[p+3 ] == 0x54 &&
- buf[p+4 ] == 0x53 && buf[p+5 ] == 0x43 && buf[p+6 ] == 0x41 &&
- buf[p+7 ] == 0x50 && buf[p+8 ] == 0x45 && buf[p+9 ] == 0x32 &&
- buf[p+10] == 0x2e && buf[p+11] == 0x30 &&
- // Sub-block
- buf[p+12] == 0x03 && buf[p+13] == 0x01 && buf[p+16] == 0) {
- p += 14;
- loop_count = buf[p++] | buf[p++] << 8;
- p++; // Skip terminator.
- } else { // We don't know what it is, just try to get past it.
- p += 12;
- while (true) { // Seek through subblocks.
- var block_size = buf[p++];
- if (block_size === 0) break;
- p += block_size;
- }
- }
- break;
- case 0xf9: // Graphics Control Extension
- if (buf[p++] !== 0x4 || buf[p+4] !== 0)
- throw "Invalid graphics extension block.";
- var pf1 = buf[p++];
- delay = buf[p++] | buf[p++] << 8;
- transparent_index = buf[p++];
- if ((pf1 & 1) === 0) transparent_index = null;
- disposal = pf1 >> 2 & 0x7;
- p++; // Skip terminator.
- break;
- case 0xfe: // Comment Extension.
- while (true) { // Seek through subblocks.
- var block_size = buf[p++];
- if (block_size === 0) break;
- // console.log(buf.slice(p, p+block_size).toString('ascii'));
- p += block_size;
- }
- break;
- default:
- throw "Unknown graphic control label: 0x" + buf[p-1].toString(16);
- }
- break;
- case 0x2c: // Image Descriptor.
- var x = buf[p++] | buf[p++] << 8;
- var y = buf[p++] | buf[p++] << 8;
- var w = buf[p++] | buf[p++] << 8;
- var h = buf[p++] | buf[p++] << 8;
- var pf2 = buf[p++];
- var local_palette_flag = pf2 >> 7;
- var interlace_flag = pf2 >> 6 & 1;
- var num_local_colors_pow2 = pf2 & 0x7;
- var num_local_colors = 1 << (num_local_colors_pow2 + 1);
- var palette_offset = global_palette_offset;
- var has_local_palette = false;
- if (local_palette_flag) {
- var has_local_palette = true;
- palette_offset = p; // Override with local palette.
- p += num_local_colors * 3; // Seek past palette.
- }
- var data_offset = p;
- p++; // codesize
- while (true) {
- var block_size = buf[p++];
- if (block_size === 0) break;
- p += block_size;
- }
- frames.push({x: x, y: y, width: w, height: h,
- has_local_palette: has_local_palette,
- palette_offset: palette_offset,
- data_offset: data_offset,
- data_length: p - data_offset,
- transparent_index: transparent_index,
- interlaced: !!interlace_flag,
- delay: delay,
- disposal: disposal});
- break;
- case 0x3b: // Trailer Marker (end of file).
- no_eof = false;
- break;
- default:
- throw "Unknown gif block: 0x" + buf[p-1].toString(16);
- break;
- }
- }
- this.numFrames = function() {
- return frames.length;
- };
- this.loopCount = function() {
- return loop_count;
- };
- this.frameInfo = function(frame_num) {
- if (frame_num < 0 || frame_num >= frames.length)
- throw "Frame index out of range.";
- return frames[frame_num];
- }
- this.decodeAndBlitFrameBGRA = function(frame_num, pixels) {
- var frame = this.frameInfo(frame_num);
- var num_pixels = frame.width * frame.height;
- var index_stream = new Uint8Array(num_pixels); // At most 8-bit indices.
- GifReaderLZWOutputIndexStream(
- buf, frame.data_offset, index_stream, num_pixels);
- var palette_offset = frame.palette_offset;
- // NOTE(deanm): It seems to be much faster to compare index to 256 than
- // to === null. Not sure why, but CompareStub_EQ_STRICT shows up high in
- // the profile, not sure if it's related to using a Uint8Array.
- var trans = frame.transparent_index;
- if (trans === null) trans = 256;
- // We are possibly just blitting to a portion of the entire frame.
- // That is a subrect within the framerect, so the additional pixels
- // must be skipped over after we finished a scanline.
- var framewidth = frame.width;
- var framestride = width - framewidth;
- var xleft = framewidth; // Number of subrect pixels left in scanline.
- // Output indicies of the top left and bottom right corners of the subrect.
- var opbeg = ((frame.y * width) + frame.x) * 4;
- var opend = ((frame.y + frame.height) * width + frame.x) * 4;
- var op = opbeg;
- var scanstride = framestride * 4;
- // Use scanstride to skip past the rows when interlacing. This is skipping
- // 7 rows for the first two passes, then 3 then 1.
- if (frame.interlaced === true) {
- scanstride += width * 4 * 7; // Pass 1.
- }
- var interlaceskip = 8; // Tracking the row interval in the current pass.
- for (var i = 0, il = index_stream.length; i < il; ++i) {
- var index = index_stream[i];
- if (xleft === 0) { // Beginning of new scan line
- op += scanstride;
- xleft = framewidth;
- if (op >= opend) { // Catch the wrap to switch passes when interlacing.
- scanstride = framestride * 4 + width * 4 * (interlaceskip-1);
- // interlaceskip / 2 * 4 is interlaceskip << 1.
- op = opbeg + (framewidth + framestride) * (interlaceskip << 1);
- interlaceskip >>= 1;
- }
- }
- if (index === trans) {
- op += 4;
- } else {
- var r = buf[palette_offset + index * 3];
- var g = buf[palette_offset + index * 3 + 1];
- var b = buf[palette_offset + index * 3 + 2];
- pixels[op++] = b;
- pixels[op++] = g;
- pixels[op++] = r;
- pixels[op++] = 255;
- }
- --xleft;
- }
- };
- // I will go to copy and paste hell one day...
- this.decodeAndBlitFrameRGBA = function(frame_num, pixels) {
- var frame = this.frameInfo(frame_num);
- var num_pixels = frame.width * frame.height;
- var index_stream = new Uint8Array(num_pixels); // At most 8-bit indices.
- GifReaderLZWOutputIndexStream(
- buf, frame.data_offset, index_stream, num_pixels);
- var palette_offset = frame.palette_offset;
- // NOTE(deanm): It seems to be much faster to compare index to 256 than
- // to === null. Not sure why, but CompareStub_EQ_STRICT shows up high in
- // the profile, not sure if it's related to using a Uint8Array.
- var trans = frame.transparent_index;
- if (trans === null) trans = 256;
- // We are possibly just blitting to a portion of the entire frame.
- // That is a subrect within the framerect, so the additional pixels
- // must be skipped over after we finished a scanline.
- var framewidth = frame.width;
- var framestride = width - framewidth;
- var xleft = framewidth; // Number of subrect pixels left in scanline.
- // Output indicies of the top left and bottom right corners of the subrect.
- var opbeg = ((frame.y * width) + frame.x) * 4;
- var opend = ((frame.y + frame.height) * width + frame.x) * 4;
- var op = opbeg;
- var scanstride = framestride * 4;
- // Use scanstride to skip past the rows when interlacing. This is skipping
- // 7 rows for the first two passes, then 3 then 1.
- if (frame.interlaced === true) {
- scanstride += width * 4 * 7; // Pass 1.
- }
- var interlaceskip = 8; // Tracking the row interval in the current pass.
- for (var i = 0, il = index_stream.length; i < il; ++i) {
- var index = index_stream[i];
- if (xleft === 0) { // Beginning of new scan line
- op += scanstride;
- xleft = framewidth;
- if (op >= opend) { // Catch the wrap to switch passes when interlacing.
- scanstride = framestride * 4 + width * 4 * (interlaceskip-1);
- // interlaceskip / 2 * 4 is interlaceskip << 1.
- op = opbeg + (framewidth + framestride) * (interlaceskip << 1);
- interlaceskip >>= 1;
- }
- }
- if (index === trans) {
- op += 4;
- } else {
- var r = buf[palette_offset + index * 3];
- var g = buf[palette_offset + index * 3 + 1];
- var b = buf[palette_offset + index * 3 + 2];
- pixels[op++] = r;
- pixels[op++] = g;
- pixels[op++] = b;
- pixels[op++] = 255;
- }
- --xleft;
- }
- };
- }
- function GifReaderLZWOutputIndexStream(code_stream, p, output, output_length) {
- var min_code_size = code_stream[p++];
- var clear_code = 1 << min_code_size;
- var eoi_code = clear_code + 1;
- var next_code = eoi_code + 1;
- var cur_code_size = min_code_size + 1; // Number of bits per code.
- // NOTE: This shares the same name as the encoder, but has a different
- // meaning here. Here this masks each code coming from the code stream.
- var code_mask = (1 << cur_code_size) - 1;
- var cur_shift = 0;
- var cur = 0;
- var op = 0; // Output pointer.
-
- var subblock_size = code_stream[p++];
- // TODO(deanm): Would using a TypedArray be any faster? At least it would
- // solve the fast mode / backing store uncertainty.
- // var code_table = Array(4096);
- var code_table = new Int32Array(4096); // Can be signed, we only use 20 bits.
- var prev_code = null; // Track code-1.
- while (true) {
- // Read up to two bytes, making sure we always 12-bits for max sized code.
- while (cur_shift < 16) {
- if (subblock_size === 0) break; // No more data to be read.
- cur |= code_stream[p++] << cur_shift;
- cur_shift += 8;
- if (subblock_size === 1) { // Never let it get to 0 to hold logic above.
- subblock_size = code_stream[p++]; // Next subblock.
- } else {
- --subblock_size;
- }
- }
- // TODO(deanm): We should never really get here, we should have received
- // and EOI.
- if (cur_shift < cur_code_size)
- break;
- var code = cur & code_mask;
- cur >>= cur_code_size;
- cur_shift -= cur_code_size;
- // TODO(deanm): Maybe should check that the first code was a clear code,
- // at least this is what you're supposed to do. But actually our encoder
- // now doesn't emit a clear code first anyway.
- if (code === clear_code) {
- // We don't actually have to clear the table. This could be a good idea
- // for greater error checking, but we don't really do any anyway. We
- // will just track it with next_code and overwrite old entries.
- next_code = eoi_code + 1;
- cur_code_size = min_code_size + 1;
- code_mask = (1 << cur_code_size) - 1;
- // Don't update prev_code ?
- prev_code = null;
- continue;
- } else if (code === eoi_code) {
- break;
- }
- // We have a similar situation as the decoder, where we want to store
- // variable length entries (code table entries), but we want to do in a
- // faster manner than an array of arrays. The code below stores sort of a
- // linked list within the code table, and then "chases" through it to
- // construct the dictionary entries. When a new entry is created, just the
- // last byte is stored, and the rest (prefix) of the entry is only
- // referenced by its table entry. Then the code chases through the
- // prefixes until it reaches a single byte code. We have to chase twice,
- // first to compute the length, and then to actually copy the data to the
- // output (backwards, since we know the length). The alternative would be
- // storing something in an intermediate stack, but that doesn't make any
- // more sense. I implemented an approach where it also stored the length
- // in the code table, although it's a bit tricky because you run out of
- // bits (12 + 12 + 8), but I didn't measure much improvements (the table
- // entries are generally not the long). Even when I created benchmarks for
- // very long table entries the complexity did not seem worth it.
- // The code table stores the prefix entry in 12 bits and then the suffix
- // byte in 8 bits, so each entry is 20 bits.
- var chase_code = code < next_code ? code : prev_code;
- // Chase what we will output, either {CODE} or {CODE-1}.
- var chase_length = 0;
- var chase = chase_code;
- while (chase > clear_code) {
- chase = code_table[chase] >> 8;
- ++chase_length;
- }
- var k = chase;
-
- var op_end = op + chase_length + (chase_code !== code ? 1 : 0);
- if (op_end > output_length) {
- console.log("Warning, gif stream longer than expected.");
- return;
- }
- // Already have the first byte from the chase, might as well write it fast.
- output[op++] = k;
- op += chase_length;
- var b = op; // Track pointer, writing backwards.
- if (chase_code !== code) // The case of emitting {CODE-1} + k.
- output[op++] = k;
- chase = chase_code;
- while (chase_length--) {
- chase = code_table[chase];
- output[--b] = chase & 0xff; // Write backwards.
- chase >>= 8; // Pull down to the prefix code.
- }
- if (prev_code !== null && next_code < 4096) {
- code_table[next_code++] = prev_code << 8 | k;
- // TODO(deanm): Figure out this clearing vs code growth logic better. I
- // have an feeling that it should just happen somewhere else, for now it
- // is awkward between when we grow past the max and then hit a clear code.
- // For now just check if we hit the max 12-bits (then a clear code should
- // follow, also of course encoded in 12-bits).
- if (next_code >= code_mask+1 && cur_code_size < 12) {
- ++cur_code_size;
- code_mask = code_mask << 1 | 1;
- }
- }
- prev_code = code;
- }
- if (op !== output_length) {
- console.log("Warning, gif stream shorter than expected.");
- }
- return output;
- }
- try { exports.GifWriter = GifWriter; exports.GifReader = GifReader } catch(e) { } // CommonJS.
- },{}],215:[function(require,module,exports){
- // shim for using process in browser
- var process = module.exports = {};
- // cached from whatever global is present so that test runners that stub it
- // don't break things. But we need to wrap it in a try catch in case it is
- // wrapped in strict mode code which doesn't define any globals. It's inside a
- // function because try/catches deoptimize in certain engines.
- var cachedSetTimeout;
- var cachedClearTimeout;
- function defaultSetTimout() {
- throw new Error('setTimeout has not been defined');
- }
- function defaultClearTimeout () {
- throw new Error('clearTimeout has not been defined');
- }
- (function () {
- try {
- if (typeof setTimeout === 'function') {
- cachedSetTimeout = setTimeout;
- } else {
- cachedSetTimeout = defaultSetTimout;
- }
- } catch (e) {
- cachedSetTimeout = defaultSetTimout;
- }
- try {
- if (typeof clearTimeout === 'function') {
- cachedClearTimeout = clearTimeout;
- } else {
- cachedClearTimeout = defaultClearTimeout;
- }
- } catch (e) {
- cachedClearTimeout = defaultClearTimeout;
- }
- } ())
- function runTimeout(fun) {
- if (cachedSetTimeout === setTimeout) {
- //normal enviroments in sane situations
- return setTimeout(fun, 0);
- }
- // if setTimeout wasn't available but was latter defined
- if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
- cachedSetTimeout = setTimeout;
- return setTimeout(fun, 0);
- }
- try {
- // when when somebody has screwed with setTimeout but no I.E. maddness
- return cachedSetTimeout(fun, 0);
- } catch(e){
- try {
- // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
- return cachedSetTimeout.call(null, fun, 0);
- } catch(e){
- // 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
- return cachedSetTimeout.call(this, fun, 0);
- }
- }
- }
- function runClearTimeout(marker) {
- if (cachedClearTimeout === clearTimeout) {
- //normal enviroments in sane situations
- return clearTimeout(marker);
- }
- // if clearTimeout wasn't available but was latter defined
- if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
- cachedClearTimeout = clearTimeout;
- return clearTimeout(marker);
- }
- try {
- // when when somebody has screwed with setTimeout but no I.E. maddness
- return cachedClearTimeout(marker);
- } catch (e){
- try {
- // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
- return cachedClearTimeout.call(null, marker);
- } catch (e){
- // 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.
- // Some versions of I.E. have different rules for clearTimeout vs setTimeout
- return cachedClearTimeout.call(this, marker);
- }
- }
- }
- var queue = [];
- var draining = false;
- var currentQueue;
- var queueIndex = -1;
- function cleanUpNextTick() {
- if (!draining || !currentQueue) {
- return;
- }
- draining = false;
- if (currentQueue.length) {
- queue = currentQueue.concat(queue);
- } else {
- queueIndex = -1;
- }
- if (queue.length) {
- drainQueue();
- }
- }
- function drainQueue() {
- if (draining) {
- return;
- }
- var timeout = runTimeout(cleanUpNextTick);
- draining = true;
- var len = queue.length;
- while(len) {
- currentQueue = queue;
- queue = [];
- while (++queueIndex < len) {
- if (currentQueue) {
- currentQueue[queueIndex].run();
- }
- }
- queueIndex = -1;
- len = queue.length;
- }
- currentQueue = null;
- draining = false;
- runClearTimeout(timeout);
- }
- process.nextTick = function (fun) {
- var args = new Array(arguments.length - 1);
- if (arguments.length > 1) {
- for (var i = 1; i < arguments.length; i++) {
- args[i - 1] = arguments[i];
- }
- }
- queue.push(new Item(fun, args));
- if (queue.length === 1 && !draining) {
- runTimeout(drainQueue);
- }
- };
- // v8 likes predictible objects
- function Item(fun, array) {
- this.fun = fun;
- this.array = array;
- }
- Item.prototype.run = function () {
- this.fun.apply(null, this.array);
- };
- process.title = 'browser';
- process.browser = true;
- process.env = {};
- process.argv = [];
- process.version = ''; // empty string to avoid regexp issues
- process.versions = {};
- function noop() {}
- process.on = noop;
- process.addListener = noop;
- process.once = noop;
- process.off = noop;
- process.removeListener = noop;
- process.removeAllListeners = noop;
- process.emit = noop;
- process.prependListener = noop;
- process.prependOnceListener = noop;
- process.listeners = function (name) { return [] }
- process.binding = function (name) {
- throw new Error('process.binding is not supported');
- };
- process.cwd = function () { return '/' };
- process.chdir = function (dir) {
- throw new Error('process.chdir is not supported');
- };
- process.umask = function() { return 0; };
- },{}],216:[function(require,module,exports){
- // minimal library entry point.
- "use strict";
- module.exports = require("./src/index-minimal");
- },{"./src/index-minimal":217}],217:[function(require,module,exports){
- "use strict";
- var protobuf = exports;
- /**
- * Build type, one of `"full"`, `"light"` or `"minimal"`.
- * @name build
- * @type {string}
- * @const
- */
- protobuf.build = "minimal";
- // Serialization
- protobuf.Writer = require("./writer");
- protobuf.BufferWriter = require("./writer_buffer");
- protobuf.Reader = require("./reader");
- protobuf.BufferReader = require("./reader_buffer");
- // Utility
- protobuf.util = require("./util/minimal");
- protobuf.rpc = require("./rpc");
- protobuf.roots = require("./roots");
- protobuf.configure = configure;
- /* istanbul ignore next */
- /**
- * Reconfigures the library according to the environment.
- * @returns {undefined}
- */
- function configure() {
- protobuf.Reader._configure(protobuf.BufferReader);
- protobuf.util._configure();
- }
- // Set up buffer utility according to the environment
- protobuf.Writer._configure(protobuf.BufferWriter);
- configure();
- },{"./reader":218,"./reader_buffer":219,"./roots":220,"./rpc":221,"./util/minimal":224,"./writer":225,"./writer_buffer":226}],218:[function(require,module,exports){
- "use strict";
- module.exports = Reader;
- var util = require("./util/minimal");
- var BufferReader; // cyclic
- var LongBits = util.LongBits,
- utf8 = util.utf8;
- /* istanbul ignore next */
- function indexOutOfRange(reader, writeLength) {
- return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len);
- }
- /**
- * Constructs a new reader instance using the specified buffer.
- * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`.
- * @constructor
- * @param {Uint8Array} buffer Buffer to read from
- */
- function Reader(buffer) {
- /**
- * Read buffer.
- * @type {Uint8Array}
- */
- this.buf = buffer;
- /**
- * Read buffer position.
- * @type {number}
- */
- this.pos = 0;
- /**
- * Read buffer length.
- * @type {number}
- */
- this.len = buffer.length;
- }
- var create_array = typeof Uint8Array !== "undefined"
- ? function create_typed_array(buffer) {
- if (buffer instanceof Uint8Array || Array.isArray(buffer))
- return new Reader(buffer);
- throw Error("illegal buffer");
- }
- /* istanbul ignore next */
- : function create_array(buffer) {
- if (Array.isArray(buffer))
- return new Reader(buffer);
- throw Error("illegal buffer");
- };
- /**
- * Creates a new reader using the specified buffer.
- * @function
- * @param {Uint8Array|Buffer} buffer Buffer to read from
- * @returns {Reader|BufferReader} A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader}
- * @throws {Error} If `buffer` is not a valid buffer
- */
- Reader.create = util.Buffer
- ? function create_buffer_setup(buffer) {
- return (Reader.create = function create_buffer(buffer) {
- return util.Buffer.isBuffer(buffer)
- ? new BufferReader(buffer)
- /* istanbul ignore next */
- : create_array(buffer);
- })(buffer);
- }
- /* istanbul ignore next */
- : create_array;
- Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
- /**
- * Reads a varint as an unsigned 32 bit value.
- * @function
- * @returns {number} Value read
- */
- Reader.prototype.uint32 = (function read_uint32_setup() {
- var value = 4294967295; // optimizer type-hint, tends to deopt otherwise (?!)
- return function read_uint32() {
- value = ( this.buf[this.pos] & 127 ) >>> 0; if (this.buf[this.pos++] < 128) return value;
- value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; if (this.buf[this.pos++] < 128) return value;
- value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; if (this.buf[this.pos++] < 128) return value;
- value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; if (this.buf[this.pos++] < 128) return value;
- value = (value | (this.buf[this.pos] & 15) << 28) >>> 0; if (this.buf[this.pos++] < 128) return value;
- /* istanbul ignore if */
- if ((this.pos += 5) > this.len) {
- this.pos = this.len;
- throw indexOutOfRange(this, 10);
- }
- return value;
- };
- })();
- /**
- * Reads a varint as a signed 32 bit value.
- * @returns {number} Value read
- */
- Reader.prototype.int32 = function read_int32() {
- return this.uint32() | 0;
- };
- /**
- * Reads a zig-zag encoded varint as a signed 32 bit value.
- * @returns {number} Value read
- */
- Reader.prototype.sint32 = function read_sint32() {
- var value = this.uint32();
- return value >>> 1 ^ -(value & 1) | 0;
- };
- /* eslint-disable no-invalid-this */
- function readLongVarint() {
- // tends to deopt with local vars for octet etc.
- var bits = new LongBits(0, 0);
- var i = 0;
- if (this.len - this.pos > 4) { // fast route (lo)
- for (; i < 4; ++i) {
- // 1st..4th
- bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
- if (this.buf[this.pos++] < 128)
- return bits;
- }
- // 5th
- bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;
- bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0;
- if (this.buf[this.pos++] < 128)
- return bits;
- i = 0;
- } else {
- for (; i < 3; ++i) {
- /* istanbul ignore if */
- if (this.pos >= this.len)
- throw indexOutOfRange(this);
- // 1st..3th
- bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
- if (this.buf[this.pos++] < 128)
- return bits;
- }
- // 4th
- bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;
- return bits;
- }
- if (this.len - this.pos > 4) { // fast route (hi)
- for (; i < 5; ++i) {
- // 6th..10th
- bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
- if (this.buf[this.pos++] < 128)
- return bits;
- }
- } else {
- for (; i < 5; ++i) {
- /* istanbul ignore if */
- if (this.pos >= this.len)
- throw indexOutOfRange(this);
- // 6th..10th
- bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
- if (this.buf[this.pos++] < 128)
- return bits;
- }
- }
- /* istanbul ignore next */
- throw Error("invalid varint encoding");
- }
- /* eslint-enable no-invalid-this */
- /**
- * Reads a varint as a signed 64 bit value.
- * @name Reader#int64
- * @function
- * @returns {Long} Value read
- */
- /**
- * Reads a varint as an unsigned 64 bit value.
- * @name Reader#uint64
- * @function
- * @returns {Long} Value read
- */
- /**
- * Reads a zig-zag encoded varint as a signed 64 bit value.
- * @name Reader#sint64
- * @function
- * @returns {Long} Value read
- */
- /**
- * Reads a varint as a boolean.
- * @returns {boolean} Value read
- */
- Reader.prototype.bool = function read_bool() {
- return this.uint32() !== 0;
- };
- function readFixed32_end(buf, end) { // note that this uses `end`, not `pos`
- return (buf[end - 4]
- | buf[end - 3] << 8
- | buf[end - 2] << 16
- | buf[end - 1] << 24) >>> 0;
- }
- /**
- * Reads fixed 32 bits as an unsigned 32 bit integer.
- * @returns {number} Value read
- */
- Reader.prototype.fixed32 = function read_fixed32() {
- /* istanbul ignore if */
- if (this.pos + 4 > this.len)
- throw indexOutOfRange(this, 4);
- return readFixed32_end(this.buf, this.pos += 4);
- };
- /**
- * Reads fixed 32 bits as a signed 32 bit integer.
- * @returns {number} Value read
- */
- Reader.prototype.sfixed32 = function read_sfixed32() {
- /* istanbul ignore if */
- if (this.pos + 4 > this.len)
- throw indexOutOfRange(this, 4);
- return readFixed32_end(this.buf, this.pos += 4) | 0;
- };
- /* eslint-disable no-invalid-this */
- function readFixed64(/* this: Reader */) {
- /* istanbul ignore if */
- if (this.pos + 8 > this.len)
- throw indexOutOfRange(this, 8);
- return new LongBits(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4));
- }
- /* eslint-enable no-invalid-this */
- /**
- * Reads fixed 64 bits.
- * @name Reader#fixed64
- * @function
- * @returns {Long} Value read
- */
- /**
- * Reads zig-zag encoded fixed 64 bits.
- * @name Reader#sfixed64
- * @function
- * @returns {Long} Value read
- */
- /**
- * Reads a float (32 bit) as a number.
- * @function
- * @returns {number} Value read
- */
- Reader.prototype.float = function read_float() {
- /* istanbul ignore if */
- if (this.pos + 4 > this.len)
- throw indexOutOfRange(this, 4);
- var value = util.float.readFloatLE(this.buf, this.pos);
- this.pos += 4;
- return value;
- };
- /**
- * Reads a double (64 bit float) as a number.
- * @function
- * @returns {number} Value read
- */
- Reader.prototype.double = function read_double() {
- /* istanbul ignore if */
- if (this.pos + 8 > this.len)
- throw indexOutOfRange(this, 4);
- var value = util.float.readDoubleLE(this.buf, this.pos);
- this.pos += 8;
- return value;
- };
- /**
- * Reads a sequence of bytes preceeded by its length as a varint.
- * @returns {Uint8Array} Value read
- */
- Reader.prototype.bytes = function read_bytes() {
- var length = this.uint32(),
- start = this.pos,
- end = this.pos + length;
- /* istanbul ignore if */
- if (end > this.len)
- throw indexOutOfRange(this, length);
- this.pos += length;
- if (Array.isArray(this.buf)) // plain array
- return this.buf.slice(start, end);
- return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1
- ? new this.buf.constructor(0)
- : this._slice.call(this.buf, start, end);
- };
- /**
- * Reads a string preceeded by its byte length as a varint.
- * @returns {string} Value read
- */
- Reader.prototype.string = function read_string() {
- var bytes = this.bytes();
- return utf8.read(bytes, 0, bytes.length);
- };
- /**
- * Skips the specified number of bytes if specified, otherwise skips a varint.
- * @param {number} [length] Length if known, otherwise a varint is assumed
- * @returns {Reader} `this`
- */
- Reader.prototype.skip = function skip(length) {
- if (typeof length === "number") {
- /* istanbul ignore if */
- if (this.pos + length > this.len)
- throw indexOutOfRange(this, length);
- this.pos += length;
- } else {
- do {
- /* istanbul ignore if */
- if (this.pos >= this.len)
- throw indexOutOfRange(this);
- } while (this.buf[this.pos++] & 128);
- }
- return this;
- };
- /**
- * Skips the next element of the specified wire type.
- * @param {number} wireType Wire type received
- * @returns {Reader} `this`
- */
- Reader.prototype.skipType = function(wireType) {
- switch (wireType) {
- case 0:
- this.skip();
- break;
- case 1:
- this.skip(8);
- break;
- case 2:
- this.skip(this.uint32());
- break;
- case 3:
- while ((wireType = this.uint32() & 7) !== 4) {
- this.skipType(wireType);
- }
- break;
- case 5:
- this.skip(4);
- break;
- /* istanbul ignore next */
- default:
- throw Error("invalid wire type " + wireType + " at offset " + this.pos);
- }
- return this;
- };
- Reader._configure = function(BufferReader_) {
- BufferReader = BufferReader_;
- var fn = util.Long ? "toLong" : /* istanbul ignore next */ "toNumber";
- util.merge(Reader.prototype, {
- int64: function read_int64() {
- return readLongVarint.call(this)[fn](false);
- },
- uint64: function read_uint64() {
- return readLongVarint.call(this)[fn](true);
- },
- sint64: function read_sint64() {
- return readLongVarint.call(this).zzDecode()[fn](false);
- },
- fixed64: function read_fixed64() {
- return readFixed64.call(this)[fn](true);
- },
- sfixed64: function read_sfixed64() {
- return readFixed64.call(this)[fn](false);
- }
- });
- };
- },{"./util/minimal":224}],219:[function(require,module,exports){
- "use strict";
- module.exports = BufferReader;
- // extends Reader
- var Reader = require("./reader");
- (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
- var util = require("./util/minimal");
- /**
- * Constructs a new buffer reader instance.
- * @classdesc Wire format reader using node buffers.
- * @extends Reader
- * @constructor
- * @param {Buffer} buffer Buffer to read from
- */
- function BufferReader(buffer) {
- Reader.call(this, buffer);
- /**
- * Read buffer.
- * @name BufferReader#buf
- * @type {Buffer}
- */
- }
- /* istanbul ignore else */
- if (util.Buffer)
- BufferReader.prototype._slice = util.Buffer.prototype.slice;
- /**
- * @override
- */
- BufferReader.prototype.string = function read_string_buffer() {
- var len = this.uint32(); // modifies pos
- return this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len));
- };
- /**
- * Reads a sequence of bytes preceeded by its length as a varint.
- * @name BufferReader#bytes
- * @function
- * @returns {Buffer} Value read
- */
- },{"./reader":218,"./util/minimal":224}],220:[function(require,module,exports){
- "use strict";
- module.exports = {};
- /**
- * Named roots.
- * This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
- * Can also be used manually to make roots available accross modules.
- * @name roots
- * @type {Object.<string,Root>}
- * @example
- * // pbjs -r myroot -o compiled.js ...
- *
- * // in another module:
- * require("./compiled.js");
- *
- * // in any subsequent module:
- * var root = protobuf.roots["myroot"];
- */
- },{}],221:[function(require,module,exports){
- "use strict";
- /**
- * Streaming RPC helpers.
- * @namespace
- */
- var rpc = exports;
- /**
- * RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets.
- * @typedef RPCImpl
- * @type {function}
- * @param {Method|rpc.ServiceMethod<Message<{}>,Message<{}>>} method Reflected or static method being called
- * @param {Uint8Array} requestData Request data
- * @param {RPCImplCallback} callback Callback function
- * @returns {undefined}
- * @example
- * function rpcImpl(method, requestData, callback) {
- * if (protobuf.util.lcFirst(method.name) !== "myMethod") // compatible with static code
- * throw Error("no such method");
- * asynchronouslyObtainAResponse(requestData, function(err, responseData) {
- * callback(err, responseData);
- * });
- * }
- */
- /**
- * Node-style callback as used by {@link RPCImpl}.
- * @typedef RPCImplCallback
- * @type {function}
- * @param {Error|null} error Error, if any, otherwise `null`
- * @param {Uint8Array|null} [response] Response data or `null` to signal end of stream, if there hasn't been an error
- * @returns {undefined}
- */
- rpc.Service = require("./rpc/service");
- },{"./rpc/service":222}],222:[function(require,module,exports){
- "use strict";
- module.exports = Service;
- var util = require("../util/minimal");
- // Extends EventEmitter
- (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
- /**
- * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
- *
- * Differs from {@link RPCImplCallback} in that it is an actual callback of a service method which may not return `response = null`.
- * @typedef rpc.ServiceMethodCallback
- * @template TRes extends Message<TRes>
- * @type {function}
- * @param {Error|null} error Error, if any
- * @param {TRes} [response] Response message
- * @returns {undefined}
- */
- /**
- * A service method part of a {@link rpc.Service} as created by {@link Service.create}.
- * @typedef rpc.ServiceMethod
- * @template TReq extends Message<TReq>
- * @template TRes extends Message<TRes>
- * @type {function}
- * @param {TReq|Properties<TReq>} request Request message or plain object
- * @param {rpc.ServiceMethodCallback<TRes>} [callback] Node-style callback called with the error, if any, and the response message
- * @returns {Promise<Message<TRes>>} Promise if `callback` has been omitted, otherwise `undefined`
- */
- /**
- * Constructs a new RPC service instance.
- * @classdesc An RPC service as returned by {@link Service#create}.
- * @exports rpc.Service
- * @extends util.EventEmitter
- * @constructor
- * @param {RPCImpl} rpcImpl RPC implementation
- * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
- * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
- */
- function Service(rpcImpl, requestDelimited, responseDelimited) {
- if (typeof rpcImpl !== "function")
- throw TypeError("rpcImpl must be a function");
- util.EventEmitter.call(this);
- /**
- * RPC implementation. Becomes `null` once the service is ended.
- * @type {RPCImpl|null}
- */
- this.rpcImpl = rpcImpl;
- /**
- * Whether requests are length-delimited.
- * @type {boolean}
- */
- this.requestDelimited = Boolean(requestDelimited);
- /**
- * Whether responses are length-delimited.
- * @type {boolean}
- */
- this.responseDelimited = Boolean(responseDelimited);
- }
- /**
- * Calls a service method through {@link rpc.Service#rpcImpl|rpcImpl}.
- * @param {Method|rpc.ServiceMethod<TReq,TRes>} method Reflected or static method
- * @param {Constructor<TReq>} requestCtor Request constructor
- * @param {Constructor<TRes>} responseCtor Response constructor
- * @param {TReq|Properties<TReq>} request Request message or plain object
- * @param {rpc.ServiceMethodCallback<TRes>} callback Service callback
- * @returns {undefined}
- * @template TReq extends Message<TReq>
- * @template TRes extends Message<TRes>
- */
- Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor, request, callback) {
- if (!request)
- throw TypeError("request must be specified");
- var self = this;
- if (!callback)
- return util.asPromise(rpcCall, self, method, requestCtor, responseCtor, request);
- if (!self.rpcImpl) {
- setTimeout(function() { callback(Error("already ended")); }, 0);
- return undefined;
- }
- try {
- return self.rpcImpl(
- method,
- requestCtor[self.requestDelimited ? "encodeDelimited" : "encode"](request).finish(),
- function rpcCallback(err, response) {
- if (err) {
- self.emit("error", err, method);
- return callback(err);
- }
- if (response === null) {
- self.end(/* endedByRPC */ true);
- return undefined;
- }
- if (!(response instanceof responseCtor)) {
- try {
- response = responseCtor[self.responseDelimited ? "decodeDelimited" : "decode"](response);
- } catch (err) {
- self.emit("error", err, method);
- return callback(err);
- }
- }
- self.emit("data", response, method);
- return callback(null, response);
- }
- );
- } catch (err) {
- self.emit("error", err, method);
- setTimeout(function() { callback(err); }, 0);
- return undefined;
- }
- };
- /**
- * Ends this service and emits the `end` event.
- * @param {boolean} [endedByRPC=false] Whether the service has been ended by the RPC implementation.
- * @returns {rpc.Service} `this`
- */
- Service.prototype.end = function end(endedByRPC) {
- if (this.rpcImpl) {
- if (!endedByRPC) // signal end to rpcImpl
- this.rpcImpl(null, null, null);
- this.rpcImpl = null;
- this.emit("end").off();
- }
- return this;
- };
- },{"../util/minimal":224}],223:[function(require,module,exports){
- "use strict";
- module.exports = LongBits;
- var util = require("../util/minimal");
- /**
- * Constructs new long bits.
- * @classdesc Helper class for working with the low and high bits of a 64 bit value.
- * @memberof util
- * @constructor
- * @param {number} lo Low 32 bits, unsigned
- * @param {number} hi High 32 bits, unsigned
- */
- function LongBits(lo, hi) {
- // note that the casts below are theoretically unnecessary as of today, but older statically
- // generated converter code might still call the ctor with signed 32bits. kept for compat.
- /**
- * Low bits.
- * @type {number}
- */
- this.lo = lo >>> 0;
- /**
- * High bits.
- * @type {number}
- */
- this.hi = hi >>> 0;
- }
- /**
- * Zero bits.
- * @memberof util.LongBits
- * @type {util.LongBits}
- */
- var zero = LongBits.zero = new LongBits(0, 0);
- zero.toNumber = function() { return 0; };
- zero.zzEncode = zero.zzDecode = function() { return this; };
- zero.length = function() { return 1; };
- /**
- * Zero hash.
- * @memberof util.LongBits
- * @type {string}
- */
- var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0";
- /**
- * Constructs new long bits from the specified number.
- * @param {number} value Value
- * @returns {util.LongBits} Instance
- */
- LongBits.fromNumber = function fromNumber(value) {
- if (value === 0)
- return zero;
- var sign = value < 0;
- if (sign)
- value = -value;
- var lo = value >>> 0,
- hi = (value - lo) / 4294967296 >>> 0;
- if (sign) {
- hi = ~hi >>> 0;
- lo = ~lo >>> 0;
- if (++lo > 4294967295) {
- lo = 0;
- if (++hi > 4294967295)
- hi = 0;
- }
- }
- return new LongBits(lo, hi);
- };
- /**
- * Constructs new long bits from a number, long or string.
- * @param {Long|number|string} value Value
- * @returns {util.LongBits} Instance
- */
- LongBits.from = function from(value) {
- if (typeof value === "number")
- return LongBits.fromNumber(value);
- if (util.isString(value)) {
- /* istanbul ignore else */
- if (util.Long)
- value = util.Long.fromString(value);
- else
- return LongBits.fromNumber(parseInt(value, 10));
- }
- return value.low || value.high ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;
- };
- /**
- * Converts this long bits to a possibly unsafe JavaScript number.
- * @param {boolean} [unsigned=false] Whether unsigned or not
- * @returns {number} Possibly unsafe number
- */
- LongBits.prototype.toNumber = function toNumber(unsigned) {
- if (!unsigned && this.hi >>> 31) {
- var lo = ~this.lo + 1 >>> 0,
- hi = ~this.hi >>> 0;
- if (!lo)
- hi = hi + 1 >>> 0;
- return -(lo + hi * 4294967296);
- }
- return this.lo + this.hi * 4294967296;
- };
- /**
- * Converts this long bits to a long.
- * @param {boolean} [unsigned=false] Whether unsigned or not
- * @returns {Long} Long
- */
- LongBits.prototype.toLong = function toLong(unsigned) {
- return util.Long
- ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
- /* istanbul ignore next */
- : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };
- };
- var charCodeAt = String.prototype.charCodeAt;
- /**
- * Constructs new long bits from the specified 8 characters long hash.
- * @param {string} hash Hash
- * @returns {util.LongBits} Bits
- */
- LongBits.fromHash = function fromHash(hash) {
- if (hash === zeroHash)
- return zero;
- return new LongBits(
- ( charCodeAt.call(hash, 0)
- | charCodeAt.call(hash, 1) << 8
- | charCodeAt.call(hash, 2) << 16
- | charCodeAt.call(hash, 3) << 24) >>> 0
- ,
- ( charCodeAt.call(hash, 4)
- | charCodeAt.call(hash, 5) << 8
- | charCodeAt.call(hash, 6) << 16
- | charCodeAt.call(hash, 7) << 24) >>> 0
- );
- };
- /**
- * Converts this long bits to a 8 characters long hash.
- * @returns {string} Hash
- */
- LongBits.prototype.toHash = function toHash() {
- return String.fromCharCode(
- this.lo & 255,
- this.lo >>> 8 & 255,
- this.lo >>> 16 & 255,
- this.lo >>> 24 ,
- this.hi & 255,
- this.hi >>> 8 & 255,
- this.hi >>> 16 & 255,
- this.hi >>> 24
- );
- };
- /**
- * Zig-zag encodes this long bits.
- * @returns {util.LongBits} `this`
- */
- LongBits.prototype.zzEncode = function zzEncode() {
- var mask = this.hi >> 31;
- this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
- this.lo = ( this.lo << 1 ^ mask) >>> 0;
- return this;
- };
- /**
- * Zig-zag decodes this long bits.
- * @returns {util.LongBits} `this`
- */
- LongBits.prototype.zzDecode = function zzDecode() {
- var mask = -(this.lo & 1);
- this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
- this.hi = ( this.hi >>> 1 ^ mask) >>> 0;
- return this;
- };
- /**
- * Calculates the length of this longbits when encoded as a varint.
- * @returns {number} Length
- */
- LongBits.prototype.length = function length() {
- var part0 = this.lo,
- part1 = (this.lo >>> 28 | this.hi << 4) >>> 0,
- part2 = this.hi >>> 24;
- return part2 === 0
- ? part1 === 0
- ? part0 < 16384
- ? part0 < 128 ? 1 : 2
- : part0 < 2097152 ? 3 : 4
- : part1 < 16384
- ? part1 < 128 ? 5 : 6
- : part1 < 2097152 ? 7 : 8
- : part2 < 128 ? 9 : 10;
- };
- },{"../util/minimal":224}],224:[function(require,module,exports){
- (function (global){
- "use strict";
- var util = exports;
- // used to return a Promise where callback is omitted
- util.asPromise = require("@protobufjs/aspromise");
- // converts to / from base64 encoded strings
- util.base64 = require("@protobufjs/base64");
- // base class of rpc.Service
- util.EventEmitter = require("@protobufjs/eventemitter");
- // float handling accross browsers
- util.float = require("@protobufjs/float");
- // requires modules optionally and hides the call from bundlers
- util.inquire = require("@protobufjs/inquire");
- // converts to / from utf8 encoded strings
- util.utf8 = require("@protobufjs/utf8");
- // provides a node-like buffer pool in the browser
- util.pool = require("@protobufjs/pool");
- // utility to work with the low and high bits of a 64 bit value
- util.LongBits = require("./longbits");
- // global object reference
- util.global = typeof window !== "undefined" && window
- || typeof global !== "undefined" && global
- || typeof self !== "undefined" && self
- || this; // eslint-disable-line no-invalid-this
- /**
- * An immuable empty array.
- * @memberof util
- * @type {Array.<*>}
- * @const
- */
- util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes
- /**
- * An immutable empty object.
- * @type {Object}
- * @const
- */
- util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes
- /**
- * Whether running within node or not.
- * @memberof util
- * @type {boolean}
- * @const
- */
- util.isNode = Boolean(util.global.process && util.global.process.versions && util.global.process.versions.node);
- /**
- * Tests if the specified value is an integer.
- * @function
- * @param {*} value Value to test
- * @returns {boolean} `true` if the value is an integer
- */
- util.isInteger = Number.isInteger || /* istanbul ignore next */ function isInteger(value) {
- return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
- };
- /**
- * Tests if the specified value is a string.
- * @param {*} value Value to test
- * @returns {boolean} `true` if the value is a string
- */
- util.isString = function isString(value) {
- return typeof value === "string" || value instanceof String;
- };
- /**
- * Tests if the specified value is a non-null object.
- * @param {*} value Value to test
- * @returns {boolean} `true` if the value is a non-null object
- */
- util.isObject = function isObject(value) {
- return value && typeof value === "object";
- };
- /**
- * Checks if a property on a message is considered to be present.
- * This is an alias of {@link util.isSet}.
- * @function
- * @param {Object} obj Plain object or message instance
- * @param {string} prop Property name
- * @returns {boolean} `true` if considered to be present, otherwise `false`
- */
- util.isset =
- /**
- * Checks if a property on a message is considered to be present.
- * @param {Object} obj Plain object or message instance
- * @param {string} prop Property name
- * @returns {boolean} `true` if considered to be present, otherwise `false`
- */
- util.isSet = function isSet(obj, prop) {
- var value = obj[prop];
- if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins
- return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
- return false;
- };
- /**
- * Any compatible Buffer instance.
- * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.
- * @interface Buffer
- * @extends Uint8Array
- */
- /**
- * Node's Buffer class if available.
- * @type {Constructor<Buffer>}
- */
- util.Buffer = (function() {
- try {
- var Buffer = util.inquire("buffer").Buffer;
- // refuse to use non-node buffers if not explicitly assigned (perf reasons):
- return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
- } catch (e) {
- /* istanbul ignore next */
- return null;
- }
- })();
- // Internal alias of or polyfull for Buffer.from.
- util._Buffer_from = null;
- // Internal alias of or polyfill for Buffer.allocUnsafe.
- util._Buffer_allocUnsafe = null;
- /**
- * Creates a new buffer of whatever type supported by the environment.
- * @param {number|number[]} [sizeOrArray=0] Buffer size or number array
- * @returns {Uint8Array|Buffer} Buffer
- */
- util.newBuffer = function newBuffer(sizeOrArray) {
- /* istanbul ignore next */
- return typeof sizeOrArray === "number"
- ? util.Buffer
- ? util._Buffer_allocUnsafe(sizeOrArray)
- : new util.Array(sizeOrArray)
- : util.Buffer
- ? util._Buffer_from(sizeOrArray)
- : typeof Uint8Array === "undefined"
- ? sizeOrArray
- : new Uint8Array(sizeOrArray);
- };
- /**
- * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
- * @type {Constructor<Uint8Array>}
- */
- util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore next */ : Array;
- /**
- * Any compatible Long instance.
- * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.
- * @interface Long
- * @property {number} low Low bits
- * @property {number} high High bits
- * @property {boolean} unsigned Whether unsigned or not
- */
- /**
- * Long.js's Long class if available.
- * @type {Constructor<Long>}
- */
- util.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long
- || /* istanbul ignore next */ util.global.Long
- || util.inquire("long");
- /**
- * Regular expression used to verify 2 bit (`bool`) map keys.
- * @type {RegExp}
- * @const
- */
- util.key2Re = /^true|false|0|1$/;
- /**
- * Regular expression used to verify 32 bit (`int32` etc.) map keys.
- * @type {RegExp}
- * @const
- */
- util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
- /**
- * Regular expression used to verify 64 bit (`int64` etc.) map keys.
- * @type {RegExp}
- * @const
- */
- util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
- /**
- * Converts a number or long to an 8 characters long hash string.
- * @param {Long|number} value Value to convert
- * @returns {string} Hash
- */
- util.longToHash = function longToHash(value) {
- return value
- ? util.LongBits.from(value).toHash()
- : util.LongBits.zeroHash;
- };
- /**
- * Converts an 8 characters long hash string to a long or number.
- * @param {string} hash Hash
- * @param {boolean} [unsigned=false] Whether unsigned or not
- * @returns {Long|number} Original value
- */
- util.longFromHash = function longFromHash(hash, unsigned) {
- var bits = util.LongBits.fromHash(hash);
- if (util.Long)
- return util.Long.fromBits(bits.lo, bits.hi, unsigned);
- return bits.toNumber(Boolean(unsigned));
- };
- /**
- * Merges the properties of the source object into the destination object.
- * @memberof util
- * @param {Object.<string,*>} dst Destination object
- * @param {Object.<string,*>} src Source object
- * @param {boolean} [ifNotSet=false] Merges only if the key is not already set
- * @returns {Object.<string,*>} Destination object
- */
- function merge(dst, src, ifNotSet) { // used by converters
- for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
- if (dst[keys[i]] === undefined || !ifNotSet)
- dst[keys[i]] = src[keys[i]];
- return dst;
- }
- util.merge = merge;
- /**
- * Converts the first character of a string to lower case.
- * @param {string} str String to convert
- * @returns {string} Converted string
- */
- util.lcFirst = function lcFirst(str) {
- return str.charAt(0).toLowerCase() + str.substring(1);
- };
- /**
- * Creates a custom error constructor.
- * @memberof util
- * @param {string} name Error name
- * @returns {Constructor<Error>} Custom error constructor
- */
- function newError(name) {
- function CustomError(message, properties) {
- if (!(this instanceof CustomError))
- return new CustomError(message, properties);
- // Error.call(this, message);
- // ^ just returns a new error instance because the ctor can be called as a function
- Object.defineProperty(this, "message", { get: function() { return message; } });
- /* istanbul ignore next */
- if (Error.captureStackTrace) // node
- Error.captureStackTrace(this, CustomError);
- else
- Object.defineProperty(this, "stack", { value: (new Error()).stack || "" });
- if (properties)
- merge(this, properties);
- }
- (CustomError.prototype = Object.create(Error.prototype)).constructor = CustomError;
- Object.defineProperty(CustomError.prototype, "name", { get: function() { return name; } });
- CustomError.prototype.toString = function toString() {
- return this.name + ": " + this.message;
- };
- return CustomError;
- }
- util.newError = newError;
- /**
- * Constructs a new protocol error.
- * @classdesc Error subclass indicating a protocol specifc error.
- * @memberof util
- * @extends Error
- * @template T extends Message<T>
- * @constructor
- * @param {string} message Error message
- * @param {Object.<string,*>} [properties] Additional properties
- * @example
- * try {
- * MyMessage.decode(someBuffer); // throws if required fields are missing
- * } catch (e) {
- * if (e instanceof ProtocolError && e.instance)
- * console.log("decoded so far: " + JSON.stringify(e.instance));
- * }
- */
- util.ProtocolError = newError("ProtocolError");
- /**
- * So far decoded message instance.
- * @name util.ProtocolError#instance
- * @type {Message<T>}
- */
- /**
- * A OneOf getter as returned by {@link util.oneOfGetter}.
- * @typedef OneOfGetter
- * @type {function}
- * @returns {string|undefined} Set field name, if any
- */
- /**
- * Builds a getter for a oneof's present field name.
- * @param {string[]} fieldNames Field names
- * @returns {OneOfGetter} Unbound getter
- */
- util.oneOfGetter = function getOneOf(fieldNames) {
- var fieldMap = {};
- for (var i = 0; i < fieldNames.length; ++i)
- fieldMap[fieldNames[i]] = 1;
- /**
- * @returns {string|undefined} Set field name, if any
- * @this Object
- * @ignore
- */
- return function() { // eslint-disable-line consistent-return
- for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i)
- if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null)
- return keys[i];
- };
- };
- /**
- * A OneOf setter as returned by {@link util.oneOfSetter}.
- * @typedef OneOfSetter
- * @type {function}
- * @param {string|undefined} value Field name
- * @returns {undefined}
- */
- /**
- * Builds a setter for a oneof's present field name.
- * @param {string[]} fieldNames Field names
- * @returns {OneOfSetter} Unbound setter
- */
- util.oneOfSetter = function setOneOf(fieldNames) {
- /**
- * @param {string} name Field name
- * @returns {undefined}
- * @this Object
- * @ignore
- */
- return function(name) {
- for (var i = 0; i < fieldNames.length; ++i)
- if (fieldNames[i] !== name)
- delete this[fieldNames[i]];
- };
- };
- /**
- * Default conversion options used for {@link Message#toJSON} implementations.
- *
- * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
- *
- * - Longs become strings
- * - Enums become string keys
- * - Bytes become base64 encoded strings
- * - (Sub-)Messages become plain objects
- * - Maps become plain objects with all string keys
- * - Repeated fields become arrays
- * - NaN and Infinity for float and double fields become strings
- *
- * @type {IConversionOptions}
- * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json
- */
- util.toJSONOptions = {
- longs: String,
- enums: String,
- bytes: String,
- json: true
- };
- // Sets up buffer utility according to the environment (called in index-minimal)
- util._configure = function() {
- var Buffer = util.Buffer;
- /* istanbul ignore if */
- if (!Buffer) {
- util._Buffer_from = util._Buffer_allocUnsafe = null;
- return;
- }
- // because node 4.x buffers are incompatible & immutable
- // see: https://github.com/dcodeIO/protobuf.js/pull/665
- util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
- /* istanbul ignore next */
- function Buffer_from(value, encoding) {
- return new Buffer(value, encoding);
- };
- util._Buffer_allocUnsafe = Buffer.allocUnsafe ||
- /* istanbul ignore next */
- function Buffer_allocUnsafe(size) {
- return new Buffer(size);
- };
- };
- }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
- },{"./longbits":223,"@protobufjs/aspromise":1,"@protobufjs/base64":2,"@protobufjs/eventemitter":3,"@protobufjs/float":4,"@protobufjs/inquire":5,"@protobufjs/pool":6,"@protobufjs/utf8":7}],225:[function(require,module,exports){
- "use strict";
- module.exports = Writer;
- var util = require("./util/minimal");
- var BufferWriter; // cyclic
- var LongBits = util.LongBits,
- base64 = util.base64,
- utf8 = util.utf8;
- /**
- * Constructs a new writer operation instance.
- * @classdesc Scheduled writer operation.
- * @constructor
- * @param {function(*, Uint8Array, number)} fn Function to call
- * @param {number} len Value byte length
- * @param {*} val Value to write
- * @ignore
- */
- function Op(fn, len, val) {
- /**
- * Function to call.
- * @type {function(Uint8Array, number, *)}
- */
- this.fn = fn;
- /**
- * Value byte length.
- * @type {number}
- */
- this.len = len;
- /**
- * Next operation.
- * @type {Writer.Op|undefined}
- */
- this.next = undefined;
- /**
- * Value to write.
- * @type {*}
- */
- this.val = val; // type varies
- }
- /* istanbul ignore next */
- function noop() {} // eslint-disable-line no-empty-function
- /**
- * Constructs a new writer state instance.
- * @classdesc Copied writer state.
- * @memberof Writer
- * @constructor
- * @param {Writer} writer Writer to copy state from
- * @ignore
- */
- function State(writer) {
- /**
- * Current head.
- * @type {Writer.Op}
- */
- this.head = writer.head;
- /**
- * Current tail.
- * @type {Writer.Op}
- */
- this.tail = writer.tail;
- /**
- * Current buffer length.
- * @type {number}
- */
- this.len = writer.len;
- /**
- * Next state.
- * @type {State|null}
- */
- this.next = writer.states;
- }
- /**
- * Constructs a new writer instance.
- * @classdesc Wire format writer using `Uint8Array` if available, otherwise `Array`.
- * @constructor
- */
- function Writer() {
- /**
- * Current length.
- * @type {number}
- */
- this.len = 0;
- /**
- * Operations head.
- * @type {Object}
- */
- this.head = new Op(noop, 0, 0);
- /**
- * Operations tail
- * @type {Object}
- */
- this.tail = this.head;
- /**
- * Linked forked states.
- * @type {Object|null}
- */
- this.states = null;
- // When a value is written, the writer calculates its byte length and puts it into a linked
- // list of operations to perform when finish() is called. This both allows us to allocate
- // buffers of the exact required size and reduces the amount of work we have to do compared
- // to first calculating over objects and then encoding over objects. In our case, the encoding
- // part is just a linked list walk calling operations with already prepared values.
- }
- /**
- * Creates a new writer.
- * @function
- * @returns {BufferWriter|Writer} A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer}
- */
- Writer.create = util.Buffer
- ? function create_buffer_setup() {
- return (Writer.create = function create_buffer() {
- return new BufferWriter();
- })();
- }
- /* istanbul ignore next */
- : function create_array() {
- return new Writer();
- };
- /**
- * Allocates a buffer of the specified size.
- * @param {number} size Buffer size
- * @returns {Uint8Array} Buffer
- */
- Writer.alloc = function alloc(size) {
- return new util.Array(size);
- };
- // Use Uint8Array buffer pool in the browser, just like node does with buffers
- /* istanbul ignore else */
- if (util.Array !== Array)
- Writer.alloc = util.pool(Writer.alloc, util.Array.prototype.subarray);
- /**
- * Pushes a new operation to the queue.
- * @param {function(Uint8Array, number, *)} fn Function to call
- * @param {number} len Value byte length
- * @param {number} val Value to write
- * @returns {Writer} `this`
- * @private
- */
- Writer.prototype._push = function push(fn, len, val) {
- this.tail = this.tail.next = new Op(fn, len, val);
- this.len += len;
- return this;
- };
- function writeByte(val, buf, pos) {
- buf[pos] = val & 255;
- }
- function writeVarint32(val, buf, pos) {
- while (val > 127) {
- buf[pos++] = val & 127 | 128;
- val >>>= 7;
- }
- buf[pos] = val;
- }
- /**
- * Constructs a new varint writer operation instance.
- * @classdesc Scheduled varint writer operation.
- * @extends Op
- * @constructor
- * @param {number} len Value byte length
- * @param {number} val Value to write
- * @ignore
- */
- function VarintOp(len, val) {
- this.len = len;
- this.next = undefined;
- this.val = val;
- }
- VarintOp.prototype = Object.create(Op.prototype);
- VarintOp.prototype.fn = writeVarint32;
- /**
- * Writes an unsigned 32 bit value as a varint.
- * @param {number} value Value to write
- * @returns {Writer} `this`
- */
- Writer.prototype.uint32 = function write_uint32(value) {
- // here, the call to this.push has been inlined and a varint specific Op subclass is used.
- // uint32 is by far the most frequently used operation and benefits significantly from this.
- this.len += (this.tail = this.tail.next = new VarintOp(
- (value = value >>> 0)
- < 128 ? 1
- : value < 16384 ? 2
- : value < 2097152 ? 3
- : value < 268435456 ? 4
- : 5,
- value)).len;
- return this;
- };
- /**
- * Writes a signed 32 bit value as a varint.
- * @function
- * @param {number} value Value to write
- * @returns {Writer} `this`
- */
- Writer.prototype.int32 = function write_int32(value) {
- return value < 0
- ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
- : this.uint32(value);
- };
- /**
- * Writes a 32 bit value as a varint, zig-zag encoded.
- * @param {number} value Value to write
- * @returns {Writer} `this`
- */
- Writer.prototype.sint32 = function write_sint32(value) {
- return this.uint32((value << 1 ^ value >> 31) >>> 0);
- };
- function writeVarint64(val, buf, pos) {
- while (val.hi) {
- buf[pos++] = val.lo & 127 | 128;
- val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0;
- val.hi >>>= 7;
- }
- while (val.lo > 127) {
- buf[pos++] = val.lo & 127 | 128;
- val.lo = val.lo >>> 7;
- }
- buf[pos++] = val.lo;
- }
- /**
- * Writes an unsigned 64 bit value as a varint.
- * @param {Long|number|string} value Value to write
- * @returns {Writer} `this`
- * @throws {TypeError} If `value` is a string and no long library is present.
- */
- Writer.prototype.uint64 = function write_uint64(value) {
- var bits = LongBits.from(value);
- return this._push(writeVarint64, bits.length(), bits);
- };
- /**
- * Writes a signed 64 bit value as a varint.
- * @function
- * @param {Long|number|string} value Value to write
- * @returns {Writer} `this`
- * @throws {TypeError} If `value` is a string and no long library is present.
- */
- Writer.prototype.int64 = Writer.prototype.uint64;
- /**
- * Writes a signed 64 bit value as a varint, zig-zag encoded.
- * @param {Long|number|string} value Value to write
- * @returns {Writer} `this`
- * @throws {TypeError} If `value` is a string and no long library is present.
- */
- Writer.prototype.sint64 = function write_sint64(value) {
- var bits = LongBits.from(value).zzEncode();
- return this._push(writeVarint64, bits.length(), bits);
- };
- /**
- * Writes a boolish value as a varint.
- * @param {boolean} value Value to write
- * @returns {Writer} `this`
- */
- Writer.prototype.bool = function write_bool(value) {
- return this._push(writeByte, 1, value ? 1 : 0);
- };
- function writeFixed32(val, buf, pos) {
- buf[pos ] = val & 255;
- buf[pos + 1] = val >>> 8 & 255;
- buf[pos + 2] = val >>> 16 & 255;
- buf[pos + 3] = val >>> 24;
- }
- /**
- * Writes an unsigned 32 bit value as fixed 32 bits.
- * @param {number} value Value to write
- * @returns {Writer} `this`
- */
- Writer.prototype.fixed32 = function write_fixed32(value) {
- return this._push(writeFixed32, 4, value >>> 0);
- };
- /**
- * Writes a signed 32 bit value as fixed 32 bits.
- * @function
- * @param {number} value Value to write
- * @returns {Writer} `this`
- */
- Writer.prototype.sfixed32 = Writer.prototype.fixed32;
- /**
- * Writes an unsigned 64 bit value as fixed 64 bits.
- * @param {Long|number|string} value Value to write
- * @returns {Writer} `this`
- * @throws {TypeError} If `value` is a string and no long library is present.
- */
- Writer.prototype.fixed64 = function write_fixed64(value) {
- var bits = LongBits.from(value);
- return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
- };
- /**
- * Writes a signed 64 bit value as fixed 64 bits.
- * @function
- * @param {Long|number|string} value Value to write
- * @returns {Writer} `this`
- * @throws {TypeError} If `value` is a string and no long library is present.
- */
- Writer.prototype.sfixed64 = Writer.prototype.fixed64;
- /**
- * Writes a float (32 bit).
- * @function
- * @param {number} value Value to write
- * @returns {Writer} `this`
- */
- Writer.prototype.float = function write_float(value) {
- return this._push(util.float.writeFloatLE, 4, value);
- };
- /**
- * Writes a double (64 bit float).
- * @function
- * @param {number} value Value to write
- * @returns {Writer} `this`
- */
- Writer.prototype.double = function write_double(value) {
- return this._push(util.float.writeDoubleLE, 8, value);
- };
- var writeBytes = util.Array.prototype.set
- ? function writeBytes_set(val, buf, pos) {
- buf.set(val, pos); // also works for plain array values
- }
- /* istanbul ignore next */
- : function writeBytes_for(val, buf, pos) {
- for (var i = 0; i < val.length; ++i)
- buf[pos + i] = val[i];
- };
- /**
- * Writes a sequence of bytes.
- * @param {Uint8Array|string} value Buffer or base64 encoded string to write
- * @returns {Writer} `this`
- */
- Writer.prototype.bytes = function write_bytes(value) {
- var len = value.length >>> 0;
- if (!len)
- return this._push(writeByte, 1, 0);
- if (util.isString(value)) {
- var buf = Writer.alloc(len = base64.length(value));
- base64.decode(value, buf, 0);
- value = buf;
- }
- return this.uint32(len)._push(writeBytes, len, value);
- };
- /**
- * Writes a string.
- * @param {string} value Value to write
- * @returns {Writer} `this`
- */
- Writer.prototype.string = function write_string(value) {
- var len = utf8.length(value);
- return len
- ? this.uint32(len)._push(utf8.write, len, value)
- : this._push(writeByte, 1, 0);
- };
- /**
- * Forks this writer's state by pushing it to a stack.
- * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
- * @returns {Writer} `this`
- */
- Writer.prototype.fork = function fork() {
- this.states = new State(this);
- this.head = this.tail = new Op(noop, 0, 0);
- this.len = 0;
- return this;
- };
- /**
- * Resets this instance to the last state.
- * @returns {Writer} `this`
- */
- Writer.prototype.reset = function reset() {
- if (this.states) {
- this.head = this.states.head;
- this.tail = this.states.tail;
- this.len = this.states.len;
- this.states = this.states.next;
- } else {
- this.head = this.tail = new Op(noop, 0, 0);
- this.len = 0;
- }
- return this;
- };
- /**
- * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
- * @returns {Writer} `this`
- */
- Writer.prototype.ldelim = function ldelim() {
- var head = this.head,
- tail = this.tail,
- len = this.len;
- this.reset().uint32(len);
- if (len) {
- this.tail.next = head.next; // skip noop
- this.tail = tail;
- this.len += len;
- }
- return this;
- };
- /**
- * Finishes the write operation.
- * @returns {Uint8Array} Finished buffer
- */
- Writer.prototype.finish = function finish() {
- var head = this.head.next, // skip noop
- buf = this.constructor.alloc(this.len),
- pos = 0;
- while (head) {
- head.fn(head.val, buf, pos);
- pos += head.len;
- head = head.next;
- }
- // this.head = this.tail = null;
- return buf;
- };
- Writer._configure = function(BufferWriter_) {
- BufferWriter = BufferWriter_;
- };
- },{"./util/minimal":224}],226:[function(require,module,exports){
- "use strict";
- module.exports = BufferWriter;
- // extends Writer
- var Writer = require("./writer");
- (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
- var util = require("./util/minimal");
- var Buffer = util.Buffer;
- /**
- * Constructs a new buffer writer instance.
- * @classdesc Wire format writer using node buffers.
- * @extends Writer
- * @constructor
- */
- function BufferWriter() {
- Writer.call(this);
- }
- /**
- * Allocates a buffer of the specified size.
- * @param {number} size Buffer size
- * @returns {Buffer} Buffer
- */
- BufferWriter.alloc = function alloc_buffer(size) {
- return (BufferWriter.alloc = util._Buffer_allocUnsafe)(size);
- };
- var writeBytesBuffer = Buffer && Buffer.prototype instanceof Uint8Array && Buffer.prototype.set.name === "set"
- ? function writeBytesBuffer_set(val, buf, pos) {
- buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
- // also works for plain array values
- }
- /* istanbul ignore next */
- : function writeBytesBuffer_copy(val, buf, pos) {
- if (val.copy) // Buffer values
- val.copy(buf, pos, 0, val.length);
- else for (var i = 0; i < val.length;) // plain array values
- buf[pos++] = val[i++];
- };
- /**
- * @override
- */
- BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
- if (util.isString(value))
- value = util._Buffer_from(value, "base64");
- var len = value.length >>> 0;
- this.uint32(len);
- if (len)
- this._push(writeBytesBuffer, len, value);
- return this;
- };
- function writeStringBuffer(val, buf, pos) {
- if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
- util.utf8.write(val, buf, pos);
- else
- buf.utf8Write(val, pos);
- }
- /**
- * @override
- */
- BufferWriter.prototype.string = function write_string_buffer(value) {
- var len = Buffer.byteLength(value);
- this.uint32(len);
- if (len)
- this._push(writeStringBuffer, len, value);
- return this;
- };
- /**
- * Finishes the write operation.
- * @name BufferWriter#finish
- * @function
- * @returns {Buffer} Finished buffer
- */
- },{"./util/minimal":224,"./writer":225}],227:[function(require,module,exports){
- (function (global){
- /*! https://mths.be/punycode v1.4.1 by @mathias */
- ;(function(root) {
- /** Detect free variables */
- var freeExports = typeof exports == 'object' && exports &&
- !exports.nodeType && exports;
- var freeModule = typeof module == 'object' && module &&
- !module.nodeType && module;
- var freeGlobal = typeof global == 'object' && global;
- if (
- freeGlobal.global === freeGlobal ||
- freeGlobal.window === freeGlobal ||
- freeGlobal.self === freeGlobal
- ) {
- root = freeGlobal;
- }
- /**
- * The `punycode` object.
- * @name punycode
- * @type Object
- */
- var punycode,
- /** Highest positive signed 32-bit float value */
- maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
- /** Bootstring parameters */
- base = 36,
- tMin = 1,
- tMax = 26,
- skew = 38,
- damp = 700,
- initialBias = 72,
- initialN = 128, // 0x80
- delimiter = '-', // '\x2D'
- /** Regular expressions */
- regexPunycode = /^xn--/,
- regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
- regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
- /** Error messages */
- errors = {
- 'overflow': 'Overflow: input needs wider integers to process',
- 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
- 'invalid-input': 'Invalid input'
- },
- /** Convenience shortcuts */
- baseMinusTMin = base - tMin,
- floor = Math.floor,
- stringFromCharCode = String.fromCharCode,
- /** Temporary variable */
- key;
- /*--------------------------------------------------------------------------*/
- /**
- * A generic error utility function.
- * @private
- * @param {String} type The error type.
- * @returns {Error} Throws a `RangeError` with the applicable error message.
- */
- function error(type) {
- throw new RangeError(errors[type]);
- }
- /**
- * A generic `Array#map` utility function.
- * @private
- * @param {Array} array The array to iterate over.
- * @param {Function} callback The function that gets called for every array
- * item.
- * @returns {Array} A new array of values returned by the callback function.
- */
- function map(array, fn) {
- var length = array.length;
- var result = [];
- while (length--) {
- result[length] = fn(array[length]);
- }
- return result;
- }
- /**
- * A simple `Array#map`-like wrapper to work with domain name strings or email
- * addresses.
- * @private
- * @param {String} domain The domain name or email address.
- * @param {Function} callback The function that gets called for every
- * character.
- * @returns {Array} A new string of characters returned by the callback
- * function.
- */
- function mapDomain(string, fn) {
- var parts = string.split('@');
- var result = '';
- if (parts.length > 1) {
- // In email addresses, only the domain name should be punycoded. Leave
- // the local part (i.e. everything up to `@`) intact.
- result = parts[0] + '@';
- string = parts[1];
- }
- // Avoid `split(regex)` for IE8 compatibility. See #17.
- string = string.replace(regexSeparators, '\x2E');
- var labels = string.split('.');
- var encoded = map(labels, fn).join('.');
- return result + encoded;
- }
- /**
- * Creates an array containing the numeric code points of each Unicode
- * character in the string. While JavaScript uses UCS-2 internally,
- * this function will convert a pair of surrogate halves (each of which
- * UCS-2 exposes as separate characters) into a single code point,
- * matching UTF-16.
- * @see `punycode.ucs2.encode`
- * @see <https://mathiasbynens.be/notes/javascript-encoding>
- * @memberOf punycode.ucs2
- * @name decode
- * @param {String} string The Unicode input string (UCS-2).
- * @returns {Array} The new array of code points.
- */
- function ucs2decode(string) {
- var output = [],
- counter = 0,
- length = string.length,
- value,
- extra;
- while (counter < length) {
- value = string.charCodeAt(counter++);
- if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
- // high surrogate, and there is a next character
- extra = string.charCodeAt(counter++);
- if ((extra & 0xFC00) == 0xDC00) { // low surrogate
- output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
- } else {
- // unmatched surrogate; only append this code unit, in case the next
- // code unit is the high surrogate of a surrogate pair
- output.push(value);
- counter--;
- }
- } else {
- output.push(value);
- }
- }
- return output;
- }
- /**
- * Creates a string based on an array of numeric code points.
- * @see `punycode.ucs2.decode`
- * @memberOf punycode.ucs2
- * @name encode
- * @param {Array} codePoints The array of numeric code points.
- * @returns {String} The new Unicode string (UCS-2).
- */
- function ucs2encode(array) {
- return map(array, function(value) {
- var output = '';
- if (value > 0xFFFF) {
- value -= 0x10000;
- output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
- value = 0xDC00 | value & 0x3FF;
- }
- output += stringFromCharCode(value);
- return output;
- }).join('');
- }
- /**
- * Converts a basic code point into a digit/integer.
- * @see `digitToBasic()`
- * @private
- * @param {Number} codePoint The basic numeric code point value.
- * @returns {Number} The numeric value of a basic code point (for use in
- * representing integers) in the range `0` to `base - 1`, or `base` if
- * the code point does not represent a value.
- */
- function basicToDigit(codePoint) {
- if (codePoint - 48 < 10) {
- return codePoint - 22;
- }
- if (codePoint - 65 < 26) {
- return codePoint - 65;
- }
- if (codePoint - 97 < 26) {
- return codePoint - 97;
- }
- return base;
- }
- /**
- * Converts a digit/integer into a basic code point.
- * @see `basicToDigit()`
- * @private
- * @param {Number} digit The numeric value of a basic code point.
- * @returns {Number} The basic code point whose value (when used for
- * representing integers) is `digit`, which needs to be in the range
- * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
- * used; else, the lowercase form is used. The behavior is undefined
- * if `flag` is non-zero and `digit` has no uppercase form.
- */
- function digitToBasic(digit, flag) {
- // 0..25 map to ASCII a..z or A..Z
- // 26..35 map to ASCII 0..9
- return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
- }
- /**
- * Bias adaptation function as per section 3.4 of RFC 3492.
- * https://tools.ietf.org/html/rfc3492#section-3.4
- * @private
- */
- function adapt(delta, numPoints, firstTime) {
- var k = 0;
- delta = firstTime ? floor(delta / damp) : delta >> 1;
- delta += floor(delta / numPoints);
- for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
- delta = floor(delta / baseMinusTMin);
- }
- return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
- }
- /**
- * Converts a Punycode string of ASCII-only symbols to a string of Unicode
- * symbols.
- * @memberOf punycode
- * @param {String} input The Punycode string of ASCII-only symbols.
- * @returns {String} The resulting string of Unicode symbols.
- */
- function decode(input) {
- // Don't use UCS-2
- var output = [],
- inputLength = input.length,
- out,
- i = 0,
- n = initialN,
- bias = initialBias,
- basic,
- j,
- index,
- oldi,
- w,
- k,
- digit,
- t,
- /** Cached calculation results */
- baseMinusT;
- // Handle the basic code points: let `basic` be the number of input code
- // points before the last delimiter, or `0` if there is none, then copy
- // the first basic code points to the output.
- basic = input.lastIndexOf(delimiter);
- if (basic < 0) {
- basic = 0;
- }
- for (j = 0; j < basic; ++j) {
- // if it's not a basic code point
- if (input.charCodeAt(j) >= 0x80) {
- error('not-basic');
- }
- output.push(input.charCodeAt(j));
- }
- // Main decoding loop: start just after the last delimiter if any basic code
- // points were copied; start at the beginning otherwise.
- for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
- // `index` is the index of the next character to be consumed.
- // Decode a generalized variable-length integer into `delta`,
- // which gets added to `i`. The overflow checking is easier
- // if we increase `i` as we go, then subtract off its starting
- // value at the end to obtain `delta`.
- for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
- if (index >= inputLength) {
- error('invalid-input');
- }
- digit = basicToDigit(input.charCodeAt(index++));
- if (digit >= base || digit > floor((maxInt - i) / w)) {
- error('overflow');
- }
- i += digit * w;
- t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
- if (digit < t) {
- break;
- }
- baseMinusT = base - t;
- if (w > floor(maxInt / baseMinusT)) {
- error('overflow');
- }
- w *= baseMinusT;
- }
- out = output.length + 1;
- bias = adapt(i - oldi, out, oldi == 0);
- // `i` was supposed to wrap around from `out` to `0`,
- // incrementing `n` each time, so we'll fix that now:
- if (floor(i / out) > maxInt - n) {
- error('overflow');
- }
- n += floor(i / out);
- i %= out;
- // Insert `n` at position `i` of the output
- output.splice(i++, 0, n);
- }
- return ucs2encode(output);
- }
- /**
- * Converts a string of Unicode symbols (e.g. a domain name label) to a
- * Punycode string of ASCII-only symbols.
- * @memberOf punycode
- * @param {String} input The string of Unicode symbols.
- * @returns {String} The resulting Punycode string of ASCII-only symbols.
- */
- function encode(input) {
- var n,
- delta,
- handledCPCount,
- basicLength,
- bias,
- j,
- m,
- q,
- k,
- t,
- currentValue,
- output = [],
- /** `inputLength` will hold the number of code points in `input`. */
- inputLength,
- /** Cached calculation results */
- handledCPCountPlusOne,
- baseMinusT,
- qMinusT;
- // Convert the input in UCS-2 to Unicode
- input = ucs2decode(input);
- // Cache the length
- inputLength = input.length;
- // Initialize the state
- n = initialN;
- delta = 0;
- bias = initialBias;
- // Handle the basic code points
- for (j = 0; j < inputLength; ++j) {
- currentValue = input[j];
- if (currentValue < 0x80) {
- output.push(stringFromCharCode(currentValue));
- }
- }
- handledCPCount = basicLength = output.length;
- // `handledCPCount` is the number of code points that have been handled;
- // `basicLength` is the number of basic code points.
- // Finish the basic string - if it is not empty - with a delimiter
- if (basicLength) {
- output.push(delimiter);
- }
- // Main encoding loop:
- while (handledCPCount < inputLength) {
- // All non-basic code points < n have been handled already. Find the next
- // larger one:
- for (m = maxInt, j = 0; j < inputLength; ++j) {
- currentValue = input[j];
- if (currentValue >= n && currentValue < m) {
- m = currentValue;
- }
- }
- // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
- // but guard against overflow
- handledCPCountPlusOne = handledCPCount + 1;
- if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
- error('overflow');
- }
- delta += (m - n) * handledCPCountPlusOne;
- n = m;
- for (j = 0; j < inputLength; ++j) {
- currentValue = input[j];
- if (currentValue < n && ++delta > maxInt) {
- error('overflow');
- }
- if (currentValue == n) {
- // Represent delta as a generalized variable-length integer
- for (q = delta, k = base; /* no condition */; k += base) {
- t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
- if (q < t) {
- break;
- }
- qMinusT = q - t;
- baseMinusT = base - t;
- output.push(
- stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
- );
- q = floor(qMinusT / baseMinusT);
- }
- output.push(stringFromCharCode(digitToBasic(q, 0)));
- bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
- delta = 0;
- ++handledCPCount;
- }
- }
- ++delta;
- ++n;
- }
- return output.join('');
- }
- /**
- * Converts a Punycode string representing a domain name or an email address
- * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
- * it doesn't matter if you call it on a string that has already been
- * converted to Unicode.
- * @memberOf punycode
- * @param {String} input The Punycoded domain name or email address to
- * convert to Unicode.
- * @returns {String} The Unicode representation of the given Punycode
- * string.
- */
- function toUnicode(input) {
- return mapDomain(input, function(string) {
- return regexPunycode.test(string)
- ? decode(string.slice(4).toLowerCase())
- : string;
- });
- }
- /**
- * Converts a Unicode string representing a domain name or an email address to
- * Punycode. Only the non-ASCII parts of the domain name will be converted,
- * i.e. it doesn't matter if you call it with a domain that's already in
- * ASCII.
- * @memberOf punycode
- * @param {String} input The domain name or email address to convert, as a
- * Unicode string.
- * @returns {String} The Punycode representation of the given domain name or
- * email address.
- */
- function toASCII(input) {
- return mapDomain(input, function(string) {
- return regexNonASCII.test(string)
- ? 'xn--' + encode(string)
- : string;
- });
- }
- /*--------------------------------------------------------------------------*/
- /** Define the public API */
- punycode = {
- /**
- * A string representing the current Punycode.js version number.
- * @memberOf punycode
- * @type String
- */
- 'version': '1.4.1',
- /**
- * An object of methods to convert from JavaScript's internal character
- * representation (UCS-2) to Unicode code points, and back.
- * @see <https://mathiasbynens.be/notes/javascript-encoding>
- * @memberOf punycode
- * @type Object
- */
- 'ucs2': {
- 'decode': ucs2decode,
- 'encode': ucs2encode
- },
- 'decode': decode,
- 'encode': encode,
- 'toASCII': toASCII,
- 'toUnicode': toUnicode
- };
- /** Expose `punycode` */
- // Some AMD build optimizers, like r.js, check for specific condition patterns
- // like the following:
- if (
- typeof define == 'function' &&
- typeof define.amd == 'object' &&
- define.amd
- ) {
- define('punycode', function() {
- return punycode;
- });
- } else if (freeExports && freeModule) {
- if (module.exports == freeExports) {
- // in Node.js, io.js, or RingoJS v0.8.0+
- freeModule.exports = punycode;
- } else {
- // in Narwhal or RingoJS v0.7.0-
- for (key in punycode) {
- punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
- }
- }
- } else {
- // in Rhino or a web browser
- root.punycode = punycode;
- }
- }(this));
- }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
- },{}],228:[function(require,module,exports){
- // Copyright Joyent, Inc. and other Node contributors.
- //
- // Permission is hereby granted, free of charge, to any person obtaining a
- // copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to permit
- // persons to whom the Software is furnished to do so, subject to the
- // following conditions:
- //
- // The above copyright notice and this permission notice shall be included
- // in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
- // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- // USE OR OTHER DEALINGS IN THE SOFTWARE.
- 'use strict';
- // If obj.hasOwnProperty has been overridden, then calling
- // obj.hasOwnProperty(prop) will break.
- // See: https://github.com/joyent/node/issues/1707
- function hasOwnProperty(obj, prop) {
- return Object.prototype.hasOwnProperty.call(obj, prop);
- }
- module.exports = function(qs, sep, eq, options) {
- sep = sep || '&';
- eq = eq || '=';
- var obj = {};
- if (typeof qs !== 'string' || qs.length === 0) {
- return obj;
- }
- var regexp = /\+/g;
- qs = qs.split(sep);
- var maxKeys = 1000;
- if (options && typeof options.maxKeys === 'number') {
- maxKeys = options.maxKeys;
- }
- var len = qs.length;
- // maxKeys <= 0 means that we should not limit keys count
- if (maxKeys > 0 && len > maxKeys) {
- len = maxKeys;
- }
- for (var i = 0; i < len; ++i) {
- var x = qs[i].replace(regexp, '%20'),
- idx = x.indexOf(eq),
- kstr, vstr, k, v;
- if (idx >= 0) {
- kstr = x.substr(0, idx);
- vstr = x.substr(idx + 1);
- } else {
- kstr = x;
- vstr = '';
- }
- k = decodeURIComponent(kstr);
- v = decodeURIComponent(vstr);
- if (!hasOwnProperty(obj, k)) {
- obj[k] = v;
- } else if (isArray(obj[k])) {
- obj[k].push(v);
- } else {
- obj[k] = [obj[k], v];
- }
- }
- return obj;
- };
- var isArray = Array.isArray || function (xs) {
- return Object.prototype.toString.call(xs) === '[object Array]';
- };
- },{}],229:[function(require,module,exports){
- // Copyright Joyent, Inc. and other Node contributors.
- //
- // Permission is hereby granted, free of charge, to any person obtaining a
- // copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to permit
- // persons to whom the Software is furnished to do so, subject to the
- // following conditions:
- //
- // The above copyright notice and this permission notice shall be included
- // in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
- // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- // USE OR OTHER DEALINGS IN THE SOFTWARE.
- 'use strict';
- var stringifyPrimitive = function(v) {
- switch (typeof v) {
- case 'string':
- return v;
- case 'boolean':
- return v ? 'true' : 'false';
- case 'number':
- return isFinite(v) ? v : '';
- default:
- return '';
- }
- };
- module.exports = function(obj, sep, eq, name) {
- sep = sep || '&';
- eq = eq || '=';
- if (obj === null) {
- obj = undefined;
- }
- if (typeof obj === 'object') {
- return map(objectKeys(obj), function(k) {
- var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
- if (isArray(obj[k])) {
- return map(obj[k], function(v) {
- return ks + encodeURIComponent(stringifyPrimitive(v));
- }).join(sep);
- } else {
- return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
- }
- }).join(sep);
- }
- if (!name) return '';
- return encodeURIComponent(stringifyPrimitive(name)) + eq +
- encodeURIComponent(stringifyPrimitive(obj));
- };
- var isArray = Array.isArray || function (xs) {
- return Object.prototype.toString.call(xs) === '[object Array]';
- };
- function map (xs, f) {
- if (xs.map) return xs.map(f);
- var res = [];
- for (var i = 0; i < xs.length; i++) {
- res.push(f(xs[i], i));
- }
- return res;
- }
- var objectKeys = Object.keys || function (obj) {
- var res = [];
- for (var key in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
- }
- return res;
- };
- },{}],230:[function(require,module,exports){
- 'use strict';
- exports.decode = exports.parse = require('./decode');
- exports.encode = exports.stringify = require('./encode');
- },{"./decode":228,"./encode":229}],231:[function(require,module,exports){
- // A library of seedable RNGs implemented in Javascript.
- //
- // Usage:
- //
- // var seedrandom = require('seedrandom');
- // var random = seedrandom(1); // or any seed.
- // var x = random(); // 0 <= x < 1. Every bit is random.
- // var x = random.quick(); // 0 <= x < 1. 32 bits of randomness.
- // alea, a 53-bit multiply-with-carry generator by Johannes Baagøe.
- // Period: ~2^116
- // Reported to pass all BigCrush tests.
- var alea = require('./lib/alea');
- // xor128, a pure xor-shift generator by George Marsaglia.
- // Period: 2^128-1.
- // Reported to fail: MatrixRank and LinearComp.
- var xor128 = require('./lib/xor128');
- // xorwow, George Marsaglia's 160-bit xor-shift combined plus weyl.
- // Period: 2^192-2^32
- // Reported to fail: CollisionOver, SimpPoker, and LinearComp.
- var xorwow = require('./lib/xorwow');
- // xorshift7, by François Panneton and Pierre L'ecuyer, takes
- // a different approach: it adds robustness by allowing more shifts
- // than Marsaglia's original three. It is a 7-shift generator
- // with 256 bits, that passes BigCrush with no systmatic failures.
- // Period 2^256-1.
- // No systematic BigCrush failures reported.
- var xorshift7 = require('./lib/xorshift7');
- // xor4096, by Richard Brent, is a 4096-bit xor-shift with a
- // very long period that also adds a Weyl generator. It also passes
- // BigCrush with no systematic failures. Its long period may
- // be useful if you have many generators and need to avoid
- // collisions.
- // Period: 2^4128-2^32.
- // No systematic BigCrush failures reported.
- var xor4096 = require('./lib/xor4096');
- // Tyche-i, by Samuel Neves and Filipe Araujo, is a bit-shifting random
- // number generator derived from ChaCha, a modern stream cipher.
- // https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf
- // Period: ~2^127
- // No systematic BigCrush failures reported.
- var tychei = require('./lib/tychei');
- // The original ARC4-based prng included in this library.
- // Period: ~2^1600
- var sr = require('./seedrandom');
- sr.alea = alea;
- sr.xor128 = xor128;
- sr.xorwow = xorwow;
- sr.xorshift7 = xorshift7;
- sr.xor4096 = xor4096;
- sr.tychei = tychei;
- module.exports = sr;
- },{"./lib/alea":232,"./lib/tychei":233,"./lib/xor128":234,"./lib/xor4096":235,"./lib/xorshift7":236,"./lib/xorwow":237,"./seedrandom":238}],232:[function(require,module,exports){
- // A port of an algorithm by Johannes Baagøe <baagoe@baagoe.com>, 2010
- // http://baagoe.com/en/RandomMusings/javascript/
- // https://github.com/nquinlan/better-random-numbers-for-javascript-mirror
- // Original work is under MIT license -
- // Copyright (C) 2010 by Johannes Baagøe <baagoe@baagoe.org>
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- (function(global, module, define) {
- function Alea(seed) {
- var me = this, mash = Mash();
- me.next = function() {
- var t = 2091639 * me.s0 + me.c * 2.3283064365386963e-10; // 2^-32
- me.s0 = me.s1;
- me.s1 = me.s2;
- return me.s2 = t - (me.c = t | 0);
- };
- // Apply the seeding algorithm from Baagoe.
- me.c = 1;
- me.s0 = mash(' ');
- me.s1 = mash(' ');
- me.s2 = mash(' ');
- me.s0 -= mash(seed);
- if (me.s0 < 0) { me.s0 += 1; }
- me.s1 -= mash(seed);
- if (me.s1 < 0) { me.s1 += 1; }
- me.s2 -= mash(seed);
- if (me.s2 < 0) { me.s2 += 1; }
- mash = null;
- }
- function copy(f, t) {
- t.c = f.c;
- t.s0 = f.s0;
- t.s1 = f.s1;
- t.s2 = f.s2;
- return t;
- }
- function impl(seed, opts) {
- var xg = new Alea(seed),
- state = opts && opts.state,
- prng = xg.next;
- prng.int32 = function() { return (xg.next() * 0x100000000) | 0; }
- prng.double = function() {
- return prng() + (prng() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53
- };
- prng.quick = prng;
- if (state) {
- if (typeof(state) == 'object') copy(state, xg);
- prng.state = function() { return copy(xg, {}); }
- }
- return prng;
- }
- function Mash() {
- var n = 0xefc8249d;
- var mash = function(data) {
- data = data.toString();
- for (var i = 0; i < data.length; i++) {
- n += data.charCodeAt(i);
- var h = 0.02519603282416938 * n;
- n = h >>> 0;
- h -= n;
- h *= n;
- n = h >>> 0;
- h -= n;
- n += h * 0x100000000; // 2^32
- }
- return (n >>> 0) * 2.3283064365386963e-10; // 2^-32
- };
- return mash;
- }
- if (module && module.exports) {
- module.exports = impl;
- } else if (define && define.amd) {
- define(function() { return impl; });
- } else {
- this.alea = impl;
- }
- })(
- this,
- (typeof module) == 'object' && module, // present in node.js
- (typeof define) == 'function' && define // present with an AMD loader
- );
- },{}],233:[function(require,module,exports){
- // A Javascript implementaion of the "Tyche-i" prng algorithm by
- // Samuel Neves and Filipe Araujo.
- // See https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf
- (function(global, module, define) {
- function XorGen(seed) {
- var me = this, strseed = '';
- // Set up generator function.
- me.next = function() {
- var b = me.b, c = me.c, d = me.d, a = me.a;
- b = (b << 25) ^ (b >>> 7) ^ c;
- c = (c - d) | 0;
- d = (d << 24) ^ (d >>> 8) ^ a;
- a = (a - b) | 0;
- me.b = b = (b << 20) ^ (b >>> 12) ^ c;
- me.c = c = (c - d) | 0;
- me.d = (d << 16) ^ (c >>> 16) ^ a;
- return me.a = (a - b) | 0;
- };
- /* The following is non-inverted tyche, which has better internal
- * bit diffusion, but which is about 25% slower than tyche-i in JS.
- me.next = function() {
- var a = me.a, b = me.b, c = me.c, d = me.d;
- a = (me.a + me.b | 0) >>> 0;
- d = me.d ^ a; d = d << 16 ^ d >>> 16;
- c = me.c + d | 0;
- b = me.b ^ c; b = b << 12 ^ d >>> 20;
- me.a = a = a + b | 0;
- d = d ^ a; me.d = d = d << 8 ^ d >>> 24;
- me.c = c = c + d | 0;
- b = b ^ c;
- return me.b = (b << 7 ^ b >>> 25);
- }
- */
- me.a = 0;
- me.b = 0;
- me.c = 2654435769 | 0;
- me.d = 1367130551;
- if (seed === Math.floor(seed)) {
- // Integer seed.
- me.a = (seed / 0x100000000) | 0;
- me.b = seed | 0;
- } else {
- // String seed.
- strseed += seed;
- }
- // Mix in string seed, then discard an initial batch of 64 values.
- for (var k = 0; k < strseed.length + 20; k++) {
- me.b ^= strseed.charCodeAt(k) | 0;
- me.next();
- }
- }
- function copy(f, t) {
- t.a = f.a;
- t.b = f.b;
- t.c = f.c;
- t.d = f.d;
- return t;
- };
- function impl(seed, opts) {
- var xg = new XorGen(seed),
- state = opts && opts.state,
- prng = function() { return (xg.next() >>> 0) / 0x100000000; };
- prng.double = function() {
- do {
- var top = xg.next() >>> 11,
- bot = (xg.next() >>> 0) / 0x100000000,
- result = (top + bot) / (1 << 21);
- } while (result === 0);
- return result;
- };
- prng.int32 = xg.next;
- prng.quick = prng;
- if (state) {
- if (typeof(state) == 'object') copy(state, xg);
- prng.state = function() { return copy(xg, {}); }
- }
- return prng;
- }
- if (module && module.exports) {
- module.exports = impl;
- } else if (define && define.amd) {
- define(function() { return impl; });
- } else {
- this.tychei = impl;
- }
- })(
- this,
- (typeof module) == 'object' && module, // present in node.js
- (typeof define) == 'function' && define // present with an AMD loader
- );
- },{}],234:[function(require,module,exports){
- // A Javascript implementaion of the "xor128" prng algorithm by
- // George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper
- (function(global, module, define) {
- function XorGen(seed) {
- var me = this, strseed = '';
- me.x = 0;
- me.y = 0;
- me.z = 0;
- me.w = 0;
- // Set up generator function.
- me.next = function() {
- var t = me.x ^ (me.x << 11);
- me.x = me.y;
- me.y = me.z;
- me.z = me.w;
- return me.w ^= (me.w >>> 19) ^ t ^ (t >>> 8);
- };
- if (seed === (seed | 0)) {
- // Integer seed.
- me.x = seed;
- } else {
- // String seed.
- strseed += seed;
- }
- // Mix in string seed, then discard an initial batch of 64 values.
- for (var k = 0; k < strseed.length + 64; k++) {
- me.x ^= strseed.charCodeAt(k) | 0;
- me.next();
- }
- }
- function copy(f, t) {
- t.x = f.x;
- t.y = f.y;
- t.z = f.z;
- t.w = f.w;
- return t;
- }
- function impl(seed, opts) {
- var xg = new XorGen(seed),
- state = opts && opts.state,
- prng = function() { return (xg.next() >>> 0) / 0x100000000; };
- prng.double = function() {
- do {
- var top = xg.next() >>> 11,
- bot = (xg.next() >>> 0) / 0x100000000,
- result = (top + bot) / (1 << 21);
- } while (result === 0);
- return result;
- };
- prng.int32 = xg.next;
- prng.quick = prng;
- if (state) {
- if (typeof(state) == 'object') copy(state, xg);
- prng.state = function() { return copy(xg, {}); }
- }
- return prng;
- }
- if (module && module.exports) {
- module.exports = impl;
- } else if (define && define.amd) {
- define(function() { return impl; });
- } else {
- this.xor128 = impl;
- }
- })(
- this,
- (typeof module) == 'object' && module, // present in node.js
- (typeof define) == 'function' && define // present with an AMD loader
- );
- },{}],235:[function(require,module,exports){
- // A Javascript implementaion of Richard Brent's Xorgens xor4096 algorithm.
- //
- // This fast non-cryptographic random number generator is designed for
- // use in Monte-Carlo algorithms. It combines a long-period xorshift
- // generator with a Weyl generator, and it passes all common batteries
- // of stasticial tests for randomness while consuming only a few nanoseconds
- // for each prng generated. For background on the generator, see Brent's
- // paper: "Some long-period random number generators using shifts and xors."
- // http://arxiv.org/pdf/1004.3115v1.pdf
- //
- // Usage:
- //
- // var xor4096 = require('xor4096');
- // random = xor4096(1); // Seed with int32 or string.
- // assert.equal(random(), 0.1520436450538547); // (0, 1) range, 53 bits.
- // assert.equal(random.int32(), 1806534897); // signed int32, 32 bits.
- //
- // For nonzero numeric keys, this impelementation provides a sequence
- // identical to that by Brent's xorgens 3 implementaion in C. This
- // implementation also provides for initalizing the generator with
- // string seeds, or for saving and restoring the state of the generator.
- //
- // On Chrome, this prng benchmarks about 2.1 times slower than
- // Javascript's built-in Math.random().
- (function(global, module, define) {
- function XorGen(seed) {
- var me = this;
- // Set up generator function.
- me.next = function() {
- var w = me.w,
- X = me.X, i = me.i, t, v;
- // Update Weyl generator.
- me.w = w = (w + 0x61c88647) | 0;
- // Update xor generator.
- v = X[(i + 34) & 127];
- t = X[i = ((i + 1) & 127)];
- v ^= v << 13;
- t ^= t << 17;
- v ^= v >>> 15;
- t ^= t >>> 12;
- // Update Xor generator array state.
- v = X[i] = v ^ t;
- me.i = i;
- // Result is the combination.
- return (v + (w ^ (w >>> 16))) | 0;
- };
- function init(me, seed) {
- var t, v, i, j, w, X = [], limit = 128;
- if (seed === (seed | 0)) {
- // Numeric seeds initialize v, which is used to generates X.
- v = seed;
- seed = null;
- } else {
- // String seeds are mixed into v and X one character at a time.
- seed = seed + '\0';
- v = 0;
- limit = Math.max(limit, seed.length);
- }
- // Initialize circular array and weyl value.
- for (i = 0, j = -32; j < limit; ++j) {
- // Put the unicode characters into the array, and shuffle them.
- if (seed) v ^= seed.charCodeAt((j + 32) % seed.length);
- // After 32 shuffles, take v as the starting w value.
- if (j === 0) w = v;
- v ^= v << 10;
- v ^= v >>> 15;
- v ^= v << 4;
- v ^= v >>> 13;
- if (j >= 0) {
- w = (w + 0x61c88647) | 0; // Weyl.
- t = (X[j & 127] ^= (v + w)); // Combine xor and weyl to init array.
- i = (0 == t) ? i + 1 : 0; // Count zeroes.
- }
- }
- // We have detected all zeroes; make the key nonzero.
- if (i >= 128) {
- X[(seed && seed.length || 0) & 127] = -1;
- }
- // Run the generator 512 times to further mix the state before using it.
- // Factoring this as a function slows the main generator, so it is just
- // unrolled here. The weyl generator is not advanced while warming up.
- i = 127;
- for (j = 4 * 128; j > 0; --j) {
- v = X[(i + 34) & 127];
- t = X[i = ((i + 1) & 127)];
- v ^= v << 13;
- t ^= t << 17;
- v ^= v >>> 15;
- t ^= t >>> 12;
- X[i] = v ^ t;
- }
- // Storing state as object members is faster than using closure variables.
- me.w = w;
- me.X = X;
- me.i = i;
- }
- init(me, seed);
- }
- function copy(f, t) {
- t.i = f.i;
- t.w = f.w;
- t.X = f.X.slice();
- return t;
- };
- function impl(seed, opts) {
- if (seed == null) seed = +(new Date);
- var xg = new XorGen(seed),
- state = opts && opts.state,
- prng = function() { return (xg.next() >>> 0) / 0x100000000; };
- prng.double = function() {
- do {
- var top = xg.next() >>> 11,
- bot = (xg.next() >>> 0) / 0x100000000,
- result = (top + bot) / (1 << 21);
- } while (result === 0);
- return result;
- };
- prng.int32 = xg.next;
- prng.quick = prng;
- if (state) {
- if (state.X) copy(state, xg);
- prng.state = function() { return copy(xg, {}); }
- }
- return prng;
- }
- if (module && module.exports) {
- module.exports = impl;
- } else if (define && define.amd) {
- define(function() { return impl; });
- } else {
- this.xor4096 = impl;
- }
- })(
- this, // window object or global
- (typeof module) == 'object' && module, // present in node.js
- (typeof define) == 'function' && define // present with an AMD loader
- );
- },{}],236:[function(require,module,exports){
- // A Javascript implementaion of the "xorshift7" algorithm by
- // François Panneton and Pierre L'ecuyer:
- // "On the Xorgshift Random Number Generators"
- // http://saluc.engr.uconn.edu/refs/crypto/rng/panneton05onthexorshift.pdf
- (function(global, module, define) {
- function XorGen(seed) {
- var me = this;
- // Set up generator function.
- me.next = function() {
- // Update xor generator.
- var X = me.x, i = me.i, t, v, w;
- t = X[i]; t ^= (t >>> 7); v = t ^ (t << 24);
- t = X[(i + 1) & 7]; v ^= t ^ (t >>> 10);
- t = X[(i + 3) & 7]; v ^= t ^ (t >>> 3);
- t = X[(i + 4) & 7]; v ^= t ^ (t << 7);
- t = X[(i + 7) & 7]; t = t ^ (t << 13); v ^= t ^ (t << 9);
- X[i] = v;
- me.i = (i + 1) & 7;
- return v;
- };
- function init(me, seed) {
- var j, w, X = [];
- if (seed === (seed | 0)) {
- // Seed state array using a 32-bit integer.
- w = X[0] = seed;
- } else {
- // Seed state using a string.
- seed = '' + seed;
- for (j = 0; j < seed.length; ++j) {
- X[j & 7] = (X[j & 7] << 15) ^
- (seed.charCodeAt(j) + X[(j + 1) & 7] << 13);
- }
- }
- // Enforce an array length of 8, not all zeroes.
- while (X.length < 8) X.push(0);
- for (j = 0; j < 8 && X[j] === 0; ++j);
- if (j == 8) w = X[7] = -1; else w = X[j];
- me.x = X;
- me.i = 0;
- // Discard an initial 256 values.
- for (j = 256; j > 0; --j) {
- me.next();
- }
- }
- init(me, seed);
- }
- function copy(f, t) {
- t.x = f.x.slice();
- t.i = f.i;
- return t;
- }
- function impl(seed, opts) {
- if (seed == null) seed = +(new Date);
- var xg = new XorGen(seed),
- state = opts && opts.state,
- prng = function() { return (xg.next() >>> 0) / 0x100000000; };
- prng.double = function() {
- do {
- var top = xg.next() >>> 11,
- bot = (xg.next() >>> 0) / 0x100000000,
- result = (top + bot) / (1 << 21);
- } while (result === 0);
- return result;
- };
- prng.int32 = xg.next;
- prng.quick = prng;
- if (state) {
- if (state.x) copy(state, xg);
- prng.state = function() { return copy(xg, {}); }
- }
- return prng;
- }
- if (module && module.exports) {
- module.exports = impl;
- } else if (define && define.amd) {
- define(function() { return impl; });
- } else {
- this.xorshift7 = impl;
- }
- })(
- this,
- (typeof module) == 'object' && module, // present in node.js
- (typeof define) == 'function' && define // present with an AMD loader
- );
- },{}],237:[function(require,module,exports){
- // A Javascript implementaion of the "xorwow" prng algorithm by
- // George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper
- (function(global, module, define) {
- function XorGen(seed) {
- var me = this, strseed = '';
- // Set up generator function.
- me.next = function() {
- var t = (me.x ^ (me.x >>> 2));
- me.x = me.y; me.y = me.z; me.z = me.w; me.w = me.v;
- return (me.d = (me.d + 362437 | 0)) +
- (me.v = (me.v ^ (me.v << 4)) ^ (t ^ (t << 1))) | 0;
- };
- me.x = 0;
- me.y = 0;
- me.z = 0;
- me.w = 0;
- me.v = 0;
- if (seed === (seed | 0)) {
- // Integer seed.
- me.x = seed;
- } else {
- // String seed.
- strseed += seed;
- }
- // Mix in string seed, then discard an initial batch of 64 values.
- for (var k = 0; k < strseed.length + 64; k++) {
- me.x ^= strseed.charCodeAt(k) | 0;
- if (k == strseed.length) {
- me.d = me.x << 10 ^ me.x >>> 4;
- }
- me.next();
- }
- }
- function copy(f, t) {
- t.x = f.x;
- t.y = f.y;
- t.z = f.z;
- t.w = f.w;
- t.v = f.v;
- t.d = f.d;
- return t;
- }
- function impl(seed, opts) {
- var xg = new XorGen(seed),
- state = opts && opts.state,
- prng = function() { return (xg.next() >>> 0) / 0x100000000; };
- prng.double = function() {
- do {
- var top = xg.next() >>> 11,
- bot = (xg.next() >>> 0) / 0x100000000,
- result = (top + bot) / (1 << 21);
- } while (result === 0);
- return result;
- };
- prng.int32 = xg.next;
- prng.quick = prng;
- if (state) {
- if (typeof(state) == 'object') copy(state, xg);
- prng.state = function() { return copy(xg, {}); }
- }
- return prng;
- }
- if (module && module.exports) {
- module.exports = impl;
- } else if (define && define.amd) {
- define(function() { return impl; });
- } else {
- this.xorwow = impl;
- }
- })(
- this,
- (typeof module) == 'object' && module, // present in node.js
- (typeof define) == 'function' && define // present with an AMD loader
- );
- },{}],238:[function(require,module,exports){
- /*
- Copyright 2014 David Bau.
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
- (function (pool, math) {
- //
- // The following constants are related to IEEE 754 limits.
- //
- var global = this,
- width = 256, // each RC4 output is 0 <= x < 256
- chunks = 6, // at least six RC4 outputs for each double
- digits = 52, // there are 52 significant digits in a double
- rngname = 'random', // rngname: name for Math.random and Math.seedrandom
- startdenom = math.pow(width, chunks),
- significance = math.pow(2, digits),
- overflow = significance * 2,
- mask = width - 1,
- nodecrypto; // node.js crypto module, initialized at the bottom.
- //
- // seedrandom()
- // This is the seedrandom function described above.
- //
- function seedrandom(seed, options, callback) {
- var key = [];
- options = (options == true) ? { entropy: true } : (options || {});
- // Flatten the seed string or build one from local entropy if needed.
- var shortseed = mixkey(flatten(
- options.entropy ? [seed, tostring(pool)] :
- (seed == null) ? autoseed() : seed, 3), key);
- // Use the seed to initialize an ARC4 generator.
- var arc4 = new ARC4(key);
- // This function returns a random double in [0, 1) that contains
- // randomness in every bit of the mantissa of the IEEE 754 value.
- var prng = function() {
- var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48
- d = startdenom, // and denominator d = 2 ^ 48.
- x = 0; // and no 'extra last byte'.
- while (n < significance) { // Fill up all significant digits by
- n = (n + x) * width; // shifting numerator and
- d *= width; // denominator and generating a
- x = arc4.g(1); // new least-significant-byte.
- }
- while (n >= overflow) { // To avoid rounding up, before adding
- n /= 2; // last byte, shift everything
- d /= 2; // right using integer math until
- x >>>= 1; // we have exactly the desired bits.
- }
- return (n + x) / d; // Form the number within [0, 1).
- };
- prng.int32 = function() { return arc4.g(4) | 0; }
- prng.quick = function() { return arc4.g(4) / 0x100000000; }
- prng.double = prng;
- // Mix the randomness into accumulated entropy.
- mixkey(tostring(arc4.S), pool);
- // Calling convention: what to return as a function of prng, seed, is_math.
- return (options.pass || callback ||
- function(prng, seed, is_math_call, state) {
- if (state) {
- // Load the arc4 state from the given state if it has an S array.
- if (state.S) { copy(state, arc4); }
- // Only provide the .state method if requested via options.state.
- prng.state = function() { return copy(arc4, {}); }
- }
- // If called as a method of Math (Math.seedrandom()), mutate
- // Math.random because that is how seedrandom.js has worked since v1.0.
- if (is_math_call) { math[rngname] = prng; return seed; }
- // Otherwise, it is a newer calling convention, so return the
- // prng directly.
- else return prng;
- })(
- prng,
- shortseed,
- 'global' in options ? options.global : (this == math),
- options.state);
- }
- math['seed' + rngname] = seedrandom;
- //
- // ARC4
- //
- // An ARC4 implementation. The constructor takes a key in the form of
- // an array of at most (width) integers that should be 0 <= x < (width).
- //
- // The g(count) method returns a pseudorandom integer that concatenates
- // the next (count) outputs from ARC4. Its return value is a number x
- // that is in the range 0 <= x < (width ^ count).
- //
- function ARC4(key) {
- var t, keylen = key.length,
- me = this, i = 0, j = me.i = me.j = 0, s = me.S = [];
- // The empty key [] is treated as [0].
- if (!keylen) { key = [keylen++]; }
- // Set up S using the standard key scheduling algorithm.
- while (i < width) {
- s[i] = i++;
- }
- for (i = 0; i < width; i++) {
- s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))];
- s[j] = t;
- }
- // The "g" method returns the next (count) outputs as one number.
- (me.g = function(count) {
- // Using instance members instead of closure state nearly doubles speed.
- var t, r = 0,
- i = me.i, j = me.j, s = me.S;
- while (count--) {
- t = s[i = mask & (i + 1)];
- r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))];
- }
- me.i = i; me.j = j;
- return r;
- // For robust unpredictability, the function call below automatically
- // discards an initial batch of values. This is called RC4-drop[256].
- // See http://google.com/search?q=rsa+fluhrer+response&btnI
- })(width);
- }
- //
- // copy()
- // Copies internal state of ARC4 to or from a plain object.
- //
- function copy(f, t) {
- t.i = f.i;
- t.j = f.j;
- t.S = f.S.slice();
- return t;
- };
- //
- // flatten()
- // Converts an object tree to nested arrays of strings.
- //
- function flatten(obj, depth) {
- var result = [], typ = (typeof obj), prop;
- if (depth && typ == 'object') {
- for (prop in obj) {
- try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {}
- }
- }
- return (result.length ? result : typ == 'string' ? obj : obj + '\0');
- }
- //
- // mixkey()
- // Mixes a string seed into a key that is an array of integers, and
- // returns a shortened string seed that is equivalent to the result key.
- //
- function mixkey(seed, key) {
- var stringseed = seed + '', smear, j = 0;
- while (j < stringseed.length) {
- key[mask & j] =
- mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++));
- }
- return tostring(key);
- }
- //
- // autoseed()
- // Returns an object for autoseeding, using window.crypto and Node crypto
- // module if available.
- //
- function autoseed() {
- try {
- var out;
- if (nodecrypto && (out = nodecrypto.randomBytes)) {
- // The use of 'out' to remember randomBytes makes tight minified code.
- out = out(width);
- } else {
- out = new Uint8Array(width);
- (global.crypto || global.msCrypto).getRandomValues(out);
- }
- return tostring(out);
- } catch (e) {
- var browser = global.navigator,
- plugins = browser && browser.plugins;
- return [+new Date, global, plugins, global.screen, tostring(pool)];
- }
- }
- //
- // tostring()
- // Converts an array of charcodes to a string
- //
- function tostring(a) {
- return String.fromCharCode.apply(0, a);
- }
- //
- // When seedrandom.js is loaded, we immediately mix a few bits
- // from the built-in RNG into the entropy pool. Because we do
- // not want to interfere with deterministic PRNG state later,
- // seedrandom will not call math.random on its own again after
- // initialization.
- //
- mixkey(math.random(), pool);
- //
- // Nodejs and AMD support: export the implementation as a module using
- // either convention.
- //
- if ((typeof module) == 'object' && module.exports) {
- module.exports = seedrandom;
- // When in node.js, try using crypto package for autoseeding.
- try {
- nodecrypto = require('crypto');
- } catch (ex) {}
- } else if ((typeof define) == 'function' && define.amd) {
- define(function() { return seedrandom; });
- }
- // End anonymous scope, and pass initial values.
- })(
- [], // pool: entropy pool starts empty
- Math // math: package containing random, pow, and seedrandom
- );
- },{"crypto":208}],239:[function(require,module,exports){
- // Copyright Joyent, Inc. and other Node contributors.
- //
- // Permission is hereby granted, free of charge, to any person obtaining a
- // copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to permit
- // persons to whom the Software is furnished to do so, subject to the
- // following conditions:
- //
- // The above copyright notice and this permission notice shall be included
- // in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
- // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- // USE OR OTHER DEALINGS IN THE SOFTWARE.
- 'use strict';
- var punycode = require('punycode');
- var util = require('./util');
- exports.parse = urlParse;
- exports.resolve = urlResolve;
- exports.resolveObject = urlResolveObject;
- exports.format = urlFormat;
- exports.Url = Url;
- function Url() {
- this.protocol = null;
- this.slashes = null;
- this.auth = null;
- this.host = null;
- this.port = null;
- this.hostname = null;
- this.hash = null;
- this.search = null;
- this.query = null;
- this.pathname = null;
- this.path = null;
- this.href = null;
- }
- // Reference: RFC 3986, RFC 1808, RFC 2396
- // define these here so at least they only have to be
- // compiled once on the first module load.
- var protocolPattern = /^([a-z0-9.+-]+:)/i,
- portPattern = /:[0-9]*$/,
- // Special case for a simple path URL
- simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
- // RFC 2396: characters reserved for delimiting URLs.
- // We actually just auto-escape these.
- delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
- // RFC 2396: characters not allowed for various reasons.
- unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
- // Allowed by RFCs, but cause of XSS attacks. Always escape these.
- autoEscape = ['\''].concat(unwise),
- // Characters that are never ever allowed in a hostname.
- // Note that any invalid chars are also handled, but these
- // are the ones that are *expected* to be seen, so we fast-path
- // them.
- nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
- hostEndingChars = ['/', '?', '#'],
- hostnameMaxLen = 255,
- hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
- hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
- // protocols that can allow "unsafe" and "unwise" chars.
- unsafeProtocol = {
- 'javascript': true,
- 'javascript:': true
- },
- // protocols that never have a hostname.
- hostlessProtocol = {
- 'javascript': true,
- 'javascript:': true
- },
- // protocols that always contain a // bit.
- slashedProtocol = {
- 'http': true,
- 'https': true,
- 'ftp': true,
- 'gopher': true,
- 'file': true,
- 'http:': true,
- 'https:': true,
- 'ftp:': true,
- 'gopher:': true,
- 'file:': true
- },
- querystring = require('querystring');
- function urlParse(url, parseQueryString, slashesDenoteHost) {
- if (url && util.isObject(url) && url instanceof Url) return url;
- var u = new Url;
- u.parse(url, parseQueryString, slashesDenoteHost);
- return u;
- }
- Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
- if (!util.isString(url)) {
- throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
- }
- // Copy chrome, IE, opera backslash-handling behavior.
- // Back slashes before the query string get converted to forward slashes
- // See: https://code.google.com/p/chromium/issues/detail?id=25916
- var queryIndex = url.indexOf('?'),
- splitter =
- (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
- uSplit = url.split(splitter),
- slashRegex = /\\/g;
- uSplit[0] = uSplit[0].replace(slashRegex, '/');
- url = uSplit.join(splitter);
- var rest = url;
- // trim before proceeding.
- // This is to support parse stuff like " http://foo.com \n"
- rest = rest.trim();
- if (!slashesDenoteHost && url.split('#').length === 1) {
- // Try fast path regexp
- var simplePath = simplePathPattern.exec(rest);
- if (simplePath) {
- this.path = rest;
- this.href = rest;
- this.pathname = simplePath[1];
- if (simplePath[2]) {
- this.search = simplePath[2];
- if (parseQueryString) {
- this.query = querystring.parse(this.search.substr(1));
- } else {
- this.query = this.search.substr(1);
- }
- } else if (parseQueryString) {
- this.search = '';
- this.query = {};
- }
- return this;
- }
- }
- var proto = protocolPattern.exec(rest);
- if (proto) {
- proto = proto[0];
- var lowerProto = proto.toLowerCase();
- this.protocol = lowerProto;
- rest = rest.substr(proto.length);
- }
- // figure out if it's got a host
- // user@server is *always* interpreted as a hostname, and url
- // resolution will treat //foo/bar as host=foo,path=bar because that's
- // how the browser resolves relative URLs.
- if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
- var slashes = rest.substr(0, 2) === '//';
- if (slashes && !(proto && hostlessProtocol[proto])) {
- rest = rest.substr(2);
- this.slashes = true;
- }
- }
- if (!hostlessProtocol[proto] &&
- (slashes || (proto && !slashedProtocol[proto]))) {
- // there's a hostname.
- // the first instance of /, ?, ;, or # ends the host.
- //
- // If there is an @ in the hostname, then non-host chars *are* allowed
- // to the left of the last @ sign, unless some host-ending character
- // comes *before* the @-sign.
- // URLs are obnoxious.
- //
- // ex:
- // http://a@b@c/ => user:a@b host:c
- // http://a@b?@c => user:a host:c path:/?@c
- // v0.12 TODO(isaacs): This is not quite how Chrome does things.
- // Review our test case against browsers more comprehensively.
- // find the first instance of any hostEndingChars
- var hostEnd = -1;
- for (var i = 0; i < hostEndingChars.length; i++) {
- var hec = rest.indexOf(hostEndingChars[i]);
- if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
- hostEnd = hec;
- }
- // at this point, either we have an explicit point where the
- // auth portion cannot go past, or the last @ char is the decider.
- var auth, atSign;
- if (hostEnd === -1) {
- // atSign can be anywhere.
- atSign = rest.lastIndexOf('@');
- } else {
- // atSign must be in auth portion.
- // http://a@b/c@d => host:b auth:a path:/c@d
- atSign = rest.lastIndexOf('@', hostEnd);
- }
- // Now we have a portion which is definitely the auth.
- // Pull that off.
- if (atSign !== -1) {
- auth = rest.slice(0, atSign);
- rest = rest.slice(atSign + 1);
- this.auth = decodeURIComponent(auth);
- }
- // the host is the remaining to the left of the first non-host char
- hostEnd = -1;
- for (var i = 0; i < nonHostChars.length; i++) {
- var hec = rest.indexOf(nonHostChars[i]);
- if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
- hostEnd = hec;
- }
- // if we still have not hit it, then the entire thing is a host.
- if (hostEnd === -1)
- hostEnd = rest.length;
- this.host = rest.slice(0, hostEnd);
- rest = rest.slice(hostEnd);
- // pull out port.
- this.parseHost();
- // we've indicated that there is a hostname,
- // so even if it's empty, it has to be present.
- this.hostname = this.hostname || '';
- // if hostname begins with [ and ends with ]
- // assume that it's an IPv6 address.
- var ipv6Hostname = this.hostname[0] === '[' &&
- this.hostname[this.hostname.length - 1] === ']';
- // validate a little.
- if (!ipv6Hostname) {
- var hostparts = this.hostname.split(/\./);
- for (var i = 0, l = hostparts.length; i < l; i++) {
- var part = hostparts[i];
- if (!part) continue;
- if (!part.match(hostnamePartPattern)) {
- var newpart = '';
- for (var j = 0, k = part.length; j < k; j++) {
- if (part.charCodeAt(j) > 127) {
- // we replace non-ASCII char with a temporary placeholder
- // we need this to make sure size of hostname is not
- // broken by replacing non-ASCII by nothing
- newpart += 'x';
- } else {
- newpart += part[j];
- }
- }
- // we test again with ASCII char only
- if (!newpart.match(hostnamePartPattern)) {
- var validParts = hostparts.slice(0, i);
- var notHost = hostparts.slice(i + 1);
- var bit = part.match(hostnamePartStart);
- if (bit) {
- validParts.push(bit[1]);
- notHost.unshift(bit[2]);
- }
- if (notHost.length) {
- rest = '/' + notHost.join('.') + rest;
- }
- this.hostname = validParts.join('.');
- break;
- }
- }
- }
- }
- if (this.hostname.length > hostnameMaxLen) {
- this.hostname = '';
- } else {
- // hostnames are always lower case.
- this.hostname = this.hostname.toLowerCase();
- }
- if (!ipv6Hostname) {
- // IDNA Support: Returns a punycoded representation of "domain".
- // It only converts parts of the domain name that
- // have non-ASCII characters, i.e. it doesn't matter if
- // you call it with a domain that already is ASCII-only.
- this.hostname = punycode.toASCII(this.hostname);
- }
- var p = this.port ? ':' + this.port : '';
- var h = this.hostname || '';
- this.host = h + p;
- this.href += this.host;
- // strip [ and ] from the hostname
- // the host field still retains them, though
- if (ipv6Hostname) {
- this.hostname = this.hostname.substr(1, this.hostname.length - 2);
- if (rest[0] !== '/') {
- rest = '/' + rest;
- }
- }
- }
- // now rest is set to the post-host stuff.
- // chop off any delim chars.
- if (!unsafeProtocol[lowerProto]) {
- // First, make 100% sure that any "autoEscape" chars get
- // escaped, even if encodeURIComponent doesn't think they
- // need to be.
- for (var i = 0, l = autoEscape.length; i < l; i++) {
- var ae = autoEscape[i];
- if (rest.indexOf(ae) === -1)
- continue;
- var esc = encodeURIComponent(ae);
- if (esc === ae) {
- esc = escape(ae);
- }
- rest = rest.split(ae).join(esc);
- }
- }
- // chop off from the tail first.
- var hash = rest.indexOf('#');
- if (hash !== -1) {
- // got a fragment string.
- this.hash = rest.substr(hash);
- rest = rest.slice(0, hash);
- }
- var qm = rest.indexOf('?');
- if (qm !== -1) {
- this.search = rest.substr(qm);
- this.query = rest.substr(qm + 1);
- if (parseQueryString) {
- this.query = querystring.parse(this.query);
- }
- rest = rest.slice(0, qm);
- } else if (parseQueryString) {
- // no query string, but parseQueryString still requested
- this.search = '';
- this.query = {};
- }
- if (rest) this.pathname = rest;
- if (slashedProtocol[lowerProto] &&
- this.hostname && !this.pathname) {
- this.pathname = '/';
- }
- //to support http.request
- if (this.pathname || this.search) {
- var p = this.pathname || '';
- var s = this.search || '';
- this.path = p + s;
- }
- // finally, reconstruct the href based on what has been validated.
- this.href = this.format();
- return this;
- };
- // format a parsed object into a url string
- function urlFormat(obj) {
- // ensure it's an object, and not a string url.
- // If it's an obj, this is a no-op.
- // this way, you can call url_format() on strings
- // to clean up potentially wonky urls.
- if (util.isString(obj)) obj = urlParse(obj);
- if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
- return obj.format();
- }
- Url.prototype.format = function() {
- var auth = this.auth || '';
- if (auth) {
- auth = encodeURIComponent(auth);
- auth = auth.replace(/%3A/i, ':');
- auth += '@';
- }
- var protocol = this.protocol || '',
- pathname = this.pathname || '',
- hash = this.hash || '',
- host = false,
- query = '';
- if (this.host) {
- host = auth + this.host;
- } else if (this.hostname) {
- host = auth + (this.hostname.indexOf(':') === -1 ?
- this.hostname :
- '[' + this.hostname + ']');
- if (this.port) {
- host += ':' + this.port;
- }
- }
- if (this.query &&
- util.isObject(this.query) &&
- Object.keys(this.query).length) {
- query = querystring.stringify(this.query);
- }
- var search = this.search || (query && ('?' + query)) || '';
- if (protocol && protocol.substr(-1) !== ':') protocol += ':';
- // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
- // unless they had them to begin with.
- if (this.slashes ||
- (!protocol || slashedProtocol[protocol]) && host !== false) {
- host = '//' + (host || '');
- if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
- } else if (!host) {
- host = '';
- }
- if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
- if (search && search.charAt(0) !== '?') search = '?' + search;
- pathname = pathname.replace(/[?#]/g, function(match) {
- return encodeURIComponent(match);
- });
- search = search.replace('#', '%23');
- return protocol + host + pathname + search + hash;
- };
- function urlResolve(source, relative) {
- return urlParse(source, false, true).resolve(relative);
- }
- Url.prototype.resolve = function(relative) {
- return this.resolveObject(urlParse(relative, false, true)).format();
- };
- function urlResolveObject(source, relative) {
- if (!source) return relative;
- return urlParse(source, false, true).resolveObject(relative);
- }
- Url.prototype.resolveObject = function(relative) {
- if (util.isString(relative)) {
- var rel = new Url();
- rel.parse(relative, false, true);
- relative = rel;
- }
- var result = new Url();
- var tkeys = Object.keys(this);
- for (var tk = 0; tk < tkeys.length; tk++) {
- var tkey = tkeys[tk];
- result[tkey] = this[tkey];
- }
- // hash is always overridden, no matter what.
- // even href="" will remove it.
- result.hash = relative.hash;
- // if the relative url is empty, then there's nothing left to do here.
- if (relative.href === '') {
- result.href = result.format();
- return result;
- }
- // hrefs like //foo/bar always cut to the protocol.
- if (relative.slashes && !relative.protocol) {
- // take everything except the protocol from relative
- var rkeys = Object.keys(relative);
- for (var rk = 0; rk < rkeys.length; rk++) {
- var rkey = rkeys[rk];
- if (rkey !== 'protocol')
- result[rkey] = relative[rkey];
- }
- //urlParse appends trailing / to urls like http://www.example.com
- if (slashedProtocol[result.protocol] &&
- result.hostname && !result.pathname) {
- result.path = result.pathname = '/';
- }
- result.href = result.format();
- return result;
- }
- if (relative.protocol && relative.protocol !== result.protocol) {
- // if it's a known url protocol, then changing
- // the protocol does weird things
- // first, if it's not file:, then we MUST have a host,
- // and if there was a path
- // to begin with, then we MUST have a path.
- // if it is file:, then the host is dropped,
- // because that's known to be hostless.
- // anything else is assumed to be absolute.
- if (!slashedProtocol[relative.protocol]) {
- var keys = Object.keys(relative);
- for (var v = 0; v < keys.length; v++) {
- var k = keys[v];
- result[k] = relative[k];
- }
- result.href = result.format();
- return result;
- }
- result.protocol = relative.protocol;
- if (!relative.host && !hostlessProtocol[relative.protocol]) {
- var relPath = (relative.pathname || '').split('/');
- while (relPath.length && !(relative.host = relPath.shift()));
- if (!relative.host) relative.host = '';
- if (!relative.hostname) relative.hostname = '';
- if (relPath[0] !== '') relPath.unshift('');
- if (relPath.length < 2) relPath.unshift('');
- result.pathname = relPath.join('/');
- } else {
- result.pathname = relative.pathname;
- }
- result.search = relative.search;
- result.query = relative.query;
- result.host = relative.host || '';
- result.auth = relative.auth;
- result.hostname = relative.hostname || relative.host;
- result.port = relative.port;
- // to support http.request
- if (result.pathname || result.search) {
- var p = result.pathname || '';
- var s = result.search || '';
- result.path = p + s;
- }
- result.slashes = result.slashes || relative.slashes;
- result.href = result.format();
- return result;
- }
- var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
- isRelAbs = (
- relative.host ||
- relative.pathname && relative.pathname.charAt(0) === '/'
- ),
- mustEndAbs = (isRelAbs || isSourceAbs ||
- (result.host && relative.pathname)),
- removeAllDots = mustEndAbs,
- srcPath = result.pathname && result.pathname.split('/') || [],
- relPath = relative.pathname && relative.pathname.split('/') || [],
- psychotic = result.protocol && !slashedProtocol[result.protocol];
- // if the url is a non-slashed url, then relative
- // links like ../.. should be able
- // to crawl up to the hostname, as well. This is strange.
- // result.protocol has already been set by now.
- // Later on, put the first path part into the host field.
- if (psychotic) {
- result.hostname = '';
- result.port = null;
- if (result.host) {
- if (srcPath[0] === '') srcPath[0] = result.host;
- else srcPath.unshift(result.host);
- }
- result.host = '';
- if (relative.protocol) {
- relative.hostname = null;
- relative.port = null;
- if (relative.host) {
- if (relPath[0] === '') relPath[0] = relative.host;
- else relPath.unshift(relative.host);
- }
- relative.host = null;
- }
- mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
- }
- if (isRelAbs) {
- // it's absolute.
- result.host = (relative.host || relative.host === '') ?
- relative.host : result.host;
- result.hostname = (relative.hostname || relative.hostname === '') ?
- relative.hostname : result.hostname;
- result.search = relative.search;
- result.query = relative.query;
- srcPath = relPath;
- // fall through to the dot-handling below.
- } else if (relPath.length) {
- // it's relative
- // throw away the existing file, and take the new path instead.
- if (!srcPath) srcPath = [];
- srcPath.pop();
- srcPath = srcPath.concat(relPath);
- result.search = relative.search;
- result.query = relative.query;
- } else if (!util.isNullOrUndefined(relative.search)) {
- // just pull out the search.
- // like href='?foo'.
- // Put this after the other two cases because it simplifies the booleans
- if (psychotic) {
- result.hostname = result.host = srcPath.shift();
- //occationaly the auth can get stuck only in host
- //this especially happens in cases like
- //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
- var authInHost = result.host && result.host.indexOf('@') > 0 ?
- result.host.split('@') : false;
- if (authInHost) {
- result.auth = authInHost.shift();
- result.host = result.hostname = authInHost.shift();
- }
- }
- result.search = relative.search;
- result.query = relative.query;
- //to support http.request
- if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
- result.path = (result.pathname ? result.pathname : '') +
- (result.search ? result.search : '');
- }
- result.href = result.format();
- return result;
- }
- if (!srcPath.length) {
- // no path at all. easy.
- // we've already handled the other stuff above.
- result.pathname = null;
- //to support http.request
- if (result.search) {
- result.path = '/' + result.search;
- } else {
- result.path = null;
- }
- result.href = result.format();
- return result;
- }
- // if a url ENDs in . or .., then it must get a trailing slash.
- // however, if it ends in anything else non-slashy,
- // then it must NOT get a trailing slash.
- var last = srcPath.slice(-1)[0];
- var hasTrailingSlash = (
- (result.host || relative.host || srcPath.length > 1) &&
- (last === '.' || last === '..') || last === '');
- // strip single dots, resolve double dots to parent dir
- // if the path tries to go above the root, `up` ends up > 0
- var up = 0;
- for (var i = srcPath.length; i >= 0; i--) {
- last = srcPath[i];
- if (last === '.') {
- srcPath.splice(i, 1);
- } else if (last === '..') {
- srcPath.splice(i, 1);
- up++;
- } else if (up) {
- srcPath.splice(i, 1);
- up--;
- }
- }
- // if the path is allowed to go above the root, restore leading ..s
- if (!mustEndAbs && !removeAllDots) {
- for (; up--; up) {
- srcPath.unshift('..');
- }
- }
- if (mustEndAbs && srcPath[0] !== '' &&
- (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
- srcPath.unshift('');
- }
- if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
- srcPath.push('');
- }
- var isAbsolute = srcPath[0] === '' ||
- (srcPath[0] && srcPath[0].charAt(0) === '/');
- // put the host back
- if (psychotic) {
- result.hostname = result.host = isAbsolute ? '' :
- srcPath.length ? srcPath.shift() : '';
- //occationaly the auth can get stuck only in host
- //this especially happens in cases like
- //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
- var authInHost = result.host && result.host.indexOf('@') > 0 ?
- result.host.split('@') : false;
- if (authInHost) {
- result.auth = authInHost.shift();
- result.host = result.hostname = authInHost.shift();
- }
- }
- mustEndAbs = mustEndAbs || (result.host && srcPath.length);
- if (mustEndAbs && !isAbsolute) {
- srcPath.unshift('');
- }
- if (!srcPath.length) {
- result.pathname = null;
- result.path = null;
- } else {
- result.pathname = srcPath.join('/');
- }
- //to support request.http
- if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
- result.path = (result.pathname ? result.pathname : '') +
- (result.search ? result.search : '');
- }
- result.auth = relative.auth || result.auth;
- result.slashes = result.slashes || relative.slashes;
- result.href = result.format();
- return result;
- };
- Url.prototype.parseHost = function() {
- var host = this.host;
- var port = portPattern.exec(host);
- if (port) {
- port = port[0];
- if (port !== ':') {
- this.port = port.substr(1);
- }
- host = host.substr(0, host.length - port.length);
- }
- if (host) this.hostname = host;
- };
- },{"./util":240,"punycode":227,"querystring":230}],240:[function(require,module,exports){
- 'use strict';
- module.exports = {
- isString: function(arg) {
- return typeof(arg) === 'string';
- },
- isObject: function(arg) {
- return typeof(arg) === 'object' && arg !== null;
- },
- isNull: function(arg) {
- return arg === null;
- },
- isNullOrUndefined: function(arg) {
- return arg == null;
- }
- };
- },{}],241:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _config = require('./../config.js');
- var _config2 = _interopRequireDefault(_config);
- var _tfjs = require('@tensorflow/tfjs');
- var tf = _interopRequireWildcard(_tfjs);
- var _knnClassifier = require('@tensorflow-models/knn-classifier');
- var knnClassifier = _interopRequireWildcard(_knnClassifier);
- var _mobilenet = require('@tensorflow-models/mobilenet');
- var mobilenet = _interopRequireWildcard(_mobilenet);
- var _html2canvas = require('html2canvas');
- var _html2canvas2 = _interopRequireDefault(_html2canvas);
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- /* eslint-disable camelcase, max-lines, */
- var IMAGE_SIZE = 227;
- var INPUT_SIZE = 1000;
- var TOPK = 10;
- var CLASS_COUNT = 3;
- var MEASURE_TIMING_EVERY_NUM_FRAMES = 20;
- var image_format = 'jpeg';
- var image_quality = 90;
- function passThrough() {
- return 0;
- }
- var WebcamClassifier = function () {
- function WebcamClassifier() {
- _classCallCheck(this, WebcamClassifier);
- this.loaded = false;
- this.video = document.createElement('video');
- this.video.setAttribute('autoplay', '');
- this.video.setAttribute('playsinline', '');
- this.video.style.display = 'none';
- // this.video = document.getElementById('output')
- // this.video.addEventListener('loadedmetadata', this.videoLoaded.bind(this));
- this.wasStop = false;
- this.wasStart = false;
- this.blankCanvas = document.createElement('canvas');
- this.blankCanvas.width = 400;
- this.blankCanvas.height = 436;
- this.timer = null;
- this.active = false;
- this.wasActive = false;
- this.stream = null;
- this.latestCanvas = document.createElement('canvas');
- this.latestCanvas.width = 98;
- this.latestCanvas.height = 98;
- this.latestContext = this.latestCanvas.getContext('2d');
- this.thumbCanvas = document.createElement('canvas');
- this.thumbCanvas.width = Math.floor(this.latestCanvas.width / 3) + 1;
- this.thumbCanvas.height = Math.floor(this.latestCanvas.height / 3) + 1;
- this.thumbContext = this.thumbCanvas.getContext('2d');
- this.imgSrc = [];
- this.thumbVideoX = 0;
- this.classNames = _config2.default.classNames;
- this.images = {};
- for (var index = 0; index < this.classNames.length; index += 1) {
- this.images[this.classNames[index]] = {
- index: index,
- down: false,
- imagesCount: 0,
- images: [],
- latestImages: [],
- latestThumbs: []
- };
- }
- this.isDown = false;
- this.current = null;
- this.currentClass = null;
- this.measureTimingCounter = 0;
- this.lastFrameTimeMs = 1000;
- this.classIndices = {};
- this.currentSavedClassIndex = 0;
- this.mappedButtonIndexes = [];
- this.init();
- }
- _createClass(WebcamClassifier, [{
- key: 'startWebcam',
- value: function startWebcam() {
- var _this = this;
- if (this.wasStart) {
- this.startTimer();
- return;
- }
- var video = true;
- if (_config2.default.browserUtils.isMobile) {
- video = { facingMode: _config2.default.isBackFacingCam ? 'environment' : 'user' };
- }
- if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
- navigator.mediaDevices.getUserMedia({
- video: video
- // audio: (GLOBALS.browserUtils.isChrome && !GLOBALS.browserUtils.isMobile)
- }).then(function (stream) {
- _config2.default.isCamGranted = true;
- // if ((GLOBALS.browserUtils.isChrome && !GLOBALS.browserUtils.isMobile)) {
- // GLOBALS.audioContext.createMediaStreamSource(stream);
- // GLOBALS.stream = stream;
- // }
- // console.log("GLOBALS.stream " + GLOBALS.stream)
- // this.activateWebcamButton.style.display = 'none';
- _this.active = true;
- _this.stream = stream;
- _this.video.muted = true;
- _this.video.srcObject = stream;
- _this.video.width = 300;
- _this.video.height = 436;
- // this.videoLoaded();
- _this.video.addEventListener('loadedmetadata', _this.videoLoaded.bind(_this));
- var event = new CustomEvent('webcam-status', { detail: { granted: true } });
- _this.startTimer();
- _this.wasStart = true;
- }).catch(function (error) {
- var event = new CustomEvent('webcam-status', {
- detail: {
- granted: false,
- error: error
- }
- });
- // this.activateWebcamButton.style.display = 'block';
- window.dispatchEvent(event);
- gtag('event', 'webcam_denied');
- });
- }
- document.querySelector(".cam--stop").classList.add("show");
- document.querySelector(".cam--start").style = "display:none";
- }
- }, {
- key: 'stopWebcam',
- value: function stopWebcam() {
- // this.stopTimer();
- if (this.stream) {
- if (this.stream.getTracks()) {
- this.stream.getTracks().forEach(function (track) {
- track.stop();
- });
- }
- if ("srcObject" in this.video) {
- this.video.srcObject = null;
- } else {
- // using URL.createObjectURL() as fallback for old browsers
- this.video.src = null;
- }
- }
- this.stream = null;
- _config2.default.stream = null;
- this.wasStop = true;
- this.wasStart = false;
- // this.video.removeEventListener('loadedmetadata', this.videoLoaded.bind(this));
- document.querySelector(".cam--stop").classList.remove("show");
- document.querySelector(".cam--start").style = "display:flex";
- }
- }, {
- key: 'init',
- value: async function init() {
- this.useFloatTextures = !_config2.default.browserUtils.isMobile && !_config2.default.browserUtils.isSafari;
- tf.ENV.set('WEBGL_DOWNLOAD_FLOAT_ENABLED', false);
- this.classifier = knnClassifier.create();
- // Load mobilenet.
- this.mobilenetModule = await mobilenet.load();
- }
- /**
- * There is an issue with mobilenetModule/knnClassifier where
- * it returns -1 if you don't start with an index of zero
- *
- * In these train/predict methods, we remap the index of 0-2.
- * This way you can train the third model and have it retain
- * the index of 2.
- *
- * We have these super verbosely named functions
- * so it's clear what's happening
- */
- }, {
- key: 'predict',
- value: async function predict(image) {
- var imgFromPixels = tf.fromPixels(image);
- var logits = this.mobilenetModule.infer(imgFromPixels, 'conv_preds');
- var response = await this.classifier.predictClass(logits);
- var newOutput = {
- classIndex: this.mappedButtonIndexes[response.classIndex],
- confidences: {
- 0: 0,
- 1: 0,
- 2: 0
- }
- };
- this.mappedButtonIndexes.forEach(function (index, count) {
- newOutput.confidences[index] = response.confidences[count];
- });
- return newOutput;
- }
- }, {
- key: 'train',
- value: async function train(image, index) {
- if (this.mappedButtonIndexes.indexOf(index) === -1) {
- this.mappedButtonIndexes.push(index);
- }
- var newMappedIndex = this.mappedButtonIndexes.indexOf(index);
- var img = tf.fromPixels(image);
- if (this.mobilenetModule && this.mobilenetModule.infer) {
- var logits = this.mobilenetModule.infer(img, 'conv_preds');
- this.classifier.addExample(logits, newMappedIndex);
- }
- // const logits = this.mobilenetModule.infer(img, 'conv_preds');
- // this.classifier.addExample(logits, newMappedIndex);
- }
- }, {
- key: 'clear',
- value: function clear(index) {
- var newMappedIndex = this.mappedButtonIndexes.indexOf(index);
- this.classifier.clearClass(newMappedIndex);
- }
- }, {
- key: 'deleteClassData',
- value: function deleteClassData(index) {
- _config2.default.clearing = true;
- this.clear(index);
- this.images[this.classNames[index]].imagesCount = 0;
- this.images[this.classNames[index]].latestThumbs = [];
- this.images[this.classNames[index]].latestImages = [];
- _config2.default.soundOutput.pauseCurrentSound();
- setTimeout(function () {
- _config2.default.clearing = false;
- }, 300);
- }
- }, {
- key: 'ready',
- value: function ready() {
- this.startWebcam();
- }
- }, {
- key: 'videoLoaded',
- value: function videoLoaded() {
- var flip = _config2.default.isBackFacingCam ? 1 : -1;
- var videoRatio = this.video.videoWidth / this.video.videoHeight;
- var parent = this.video.parentNode;
- // console.log(this.video.parentNode)
- var parentWidth = parent.offsetWidth;
- var parentHeight = parent.offsetHeight;
- var videoWidth = parentHeight * videoRatio;
- this.video.style.width = videoWidth + 'px';
- this.video.style.height = parentHeight + 'px';
- this.video.style.transform = 'scaleX(' + flip + ') translate(' + 50 * flip * -1 + '%, -50%)';
- // If video is taller:
- if (videoRatio < 1) {
- this.video.style.transform = 'scale(' + flip * 2 + ', 2) translate(' + flip * 20 * -1 + '%, -30%)';
- }
- }
- }, {
- key: 'blur',
- value: function blur() {
- if (this.timer) {
- // this.stopTimer();
- }
- }
- }, {
- key: 'focus',
- value: function focus() {
- if (this.wasActive) {
- this.startTimer();
- }
- }
- }, {
- key: 'buttonDown',
- value: function buttonDown(id, canvas, learningClass) {
- this.current = this.images[id];
- this.current.down = true;
- this.isDown = true;
- this.training = this.current.index;
- this.videoRatio = this.video.videoWidth / this.video.videoHeight;
- this.currentClass = learningClass;
- this.canvasWidth = canvas.width;
- this.canvasHeight = canvas.height;
- this.videoWidth = this.canvasHeight * this.videoRatio;
- this.thumbVideoHeight = this.canvasHeight / 3;
- this.thumbVideoWidth = this.canvasWidth / 3;
- this.thumbVideoWidthReal = this.thumbVideoHeight * this.videoRatio;
- this.thumbVideoX = -(this.thumbVideoWidthReal - this.thumbVideoWidth) / 2;
- this.currentContext = this.currentClass.canvas.getContext('2d');
- }
- }, {
- key: 'buttonUp',
- value: function buttonUp(id) {
- this.images[id].down = false;
- this.isDown = false;
- this.training = -1;
- this.current = null;
- this.currentContext = null;
- this.currentClass = null;
- }
- }, {
- key: 'startTimer',
- value: function startTimer() {
- if (this.timer) {
- this.stopTimer();
- }
- this.video.play();
- this.wasActive = true;
- this.timer = requestAnimationFrame(this.animate.bind(this));
- }
- }, {
- key: 'stopTimer',
- value: function stopTimer() {
- this.active = false;
- this.wasActive = true;
- // this.video.pause();
- cancelAnimationFrame(this.timer);
- if (_config2.default.soundOutput && _config2.default.soundOutput.muteSounds) {
- _config2.default.soundOutput.muteSounds();
- }
- }
- }, {
- key: 'animate',
- value: async function animate() {
- var _this2 = this;
- // Get image data from video element
- var image = this.video;
- var exampleCount = Object.keys(this.classifier.getClassExampleCount()).length;
- if (this.isDown) {
- this.current.imagesCount += 1;
- this.currentClass.setSamples(this.current.imagesCount);
- if (this.current.latestThumbs.length > 8) {
- this.current.latestThumbs.shift();
- }
- if (this.current.latestImages.length > 8) {
- this.current.latestImages.shift();
- }
- // 将canvas 显示到另一画布上
- // 弹框
- var canvas = document.getElementById('output');
- var img = new Image();
- img.src = canvas.toDataURL("image/png");
- if (this.imgSrc[this.training] && this.imgSrc[this.training].length > 0) {
- this.imgSrc[this.training].push(img.src);
- } else {
- this.imgSrc[this.training] = [img.src];
- }
- this.thumbContext.drawImage(canvas, this.thumbVideoX, 0, this.thumbVideoWidthReal, this.thumbVideoHeight);
- var data = this.thumbContext.getImageData(0, 0, this.canvasWidth, this.canvasHeight);
- this.current.latestThumbs.push(data);
- var cols = 0;
- var rows = 0;
- for (var index = 0; index < this.current.latestThumbs.length; index += 1) {
- this.currentContext.putImageData(this.current.latestThumbs[index], (2 - cols) * this.thumbCanvas.width, rows * this.thumbVideoHeight, 0, 0, this.thumbCanvas.width, this.thumbCanvas.height);
- if (cols === 2) {
- rows += 1;
- cols = 0;
- } else {
- cols += 1;
- }
- }
- // Train class if one of the buttons is held down
- // Add current image to classifier
- if (this.training !== -1) {
- this.train(image, this.training);
- }
- } else if (exampleCount > 0) {
- // If any examples have been added, run predict
- var measureTimer = false;
- var start = performance.now();
- measureTimer = this.measureTimingCounter === 0;
- if (exampleCount > 0) {
- var res = await this.predict(image);
- var computeConfidences = function computeConfidences() {
- _config2.default.learningSection.setConfidences(res.confidences);
- _this2.measureTimingCounter = (_this2.measureTimingCounter + 1) % MEASURE_TIMING_EVERY_NUM_FRAMES;
- };
- if (!_config2.default.browserUtils.isSafari || measureTimer || !_config2.default.browserUtils.isMobile) {
- this.lastFrameTimeMs = performance.now() - start;
- computeConfidences();
- } else {
- setTimeout(computeConfidences, this.lastFrameTimeMs);
- }
- } else if (image.dispose) {
- image.dispose();
- }
- }
- this.timer = requestAnimationFrame(this.animate.bind(this));
- }
- }]);
- return WebcamClassifier;
- }();
- /* eslint-disable keyword-spacing */
- /* eslint-enable camelcase, max-lines, keyword-spacing */
- exports.default = WebcamClassifier;
- },{"./../config.js":242,"@tensorflow-models/knn-classifier":8,"@tensorflow-models/mobilenet":11,"@tensorflow/tfjs":205,"html2canvas":213}],242:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var AudioContext = window.AudioContext || window.webkitAudioContext;
- var GLOBALS = {
- button: {
- padding: 0,
- frontHeight: 40,
- states: {
- normal: {
- x: 8,
- y: 8
- },
- pressed: {
- x: 4,
- y: 4
- }
- }
- },
- classNames: ['green', 'purple', 'orange', 'red'],
- colors: {
- 'green': '#2baa5e',
- 'purple': '#c95ac5',
- 'orange': '#dd4d31',
- 'red': '#e8453c'
- },
- rgbaColors: {
- 'green': 'rgba(43, 170, 94, 0.25)',
- 'purple': 'rgba(201, 90, 197, 0.25)',
- 'orange': 'rgba(221, 77, 49, 0.25)',
- 'red': 'rgba(232, 69, 60, 0.25)'
- },
- classId: null,
- predicting: false,
- micThreshold: 25,
- classesTrained: {
- 'green': false,
- 'purple': false,
- 'orange': false
- },
- numClasses: 3,
- audioContext: new AudioContext(),
- isBackFacingCam: false,
- base_url: '//api.cocorobo.cn/',
- // base_url: '//staging.cocorobo.cn/api/', // staging
- USER: {
- api_key: null,
- evnets: null
- },
- port: '',
- iframe: true,
- lang: 'en',
- languare: {
- en: {
- start: "Start",
- input: 'Input',
- learning: "Learning",
- reset: "Reset",
- CloudOutputL: "Cloud",
- SoundOutput: "Sound",
- SpeechOutput: "Speech",
- stop: "Stop",
- epxamples: "Examples",
- green: 'Train Character One',
- purple: 'Train Character Two',
- orange: 'Train Character Three',
- output: 'Output',
- ModuleOutput: "Module",
- training: "Training",
- triggered_green: "You've triggered Character One!",
- triggered_purple: "You've triggered Character Two!",
- triggered_orange: "You've triggered Character Three!",
- no_triggered: "Nothing is triggered",
- select_cloud: "Select your Cloud Event",
- confidence: "Confidence",
- cloud_title: "STATUS:",
- cloud_content: "Nothing is triggered",
- cloud_green: "Character One",
- cloud_purple: "Character Two",
- cloud_orange: "Character Three",
- selectCloud: "- Choose an event here -",
- content: "Play",
- speech_content: "Say"
- },
- hans: {
- start: "开始",
- input: '输入',
- learning: "学习",
- reset: "重置",
- CloudOutputL: "云端",
- SoundOutput: "声音",
- SpeechOutput: "说话",
- stop: "停止",
- epxamples: "训练图像",
- green: '训练人物一',
- purple: '训练人物二',
- orange: '训练人物三',
- output: '输出',
- ModuleOutput: "模块",
- training: "训练中",
- triggered_green: "识别到了人物一!",
- triggered_purple: "识别到了人物二!",
- triggered_orange: "识别到了人物三!",
- no_triggered: "没有识别到任何东西",
- select_cloud: "选择发送云端事件",
- confidence: "置信度",
- cloud_title: "状态:",
- cloud_content: "什么都没有触发",
- cloud_green: "人物一",
- cloud_purple: "人物二",
- cloud_orange: "人物三",
- selectCloud: "- 请在这里选择一个事件 -",
- content: "播放",
- speech_content: "说"
- },
- hant: {
- start: "開始",
- input: '輸入',
- learning: "學習",
- reset: "重置",
- CloudOutputL: "雲端",
- SoundOutput: "聲音",
- SpeechOutput: "說話",
- stop: "停止",
- epxamples: "訓練圖像",
- green: '訓練人物一',
- purple: '訓練人物二',
- orange: '訓練人物三',
- output: '輸出',
- ModuleOutput: "模塊",
- training: "訓練中",
- triggered_green: "識別到了人物一!",
- triggered_purple: "識別到了人物二!",
- triggered_orange: "識別到了人物三!",
- no_triggered: "沒有識別到任何東西",
- select_cloud: "選擇發送雲端事件",
- confidence: "置信度",
- cloud_title: "狀態:",
- cloud_content: "什麼都沒有觸發",
- cloud_green: "人物一",
- cloud_purple: "人物二",
- cloud_orange: "人物三",
- selectCloud: "- 請在這裏選擇一個事件 -",
- content: "播放",
- speech_content: "說"
- }
- }
- };
- exports.default = GLOBALS;
- },{}],243:[function(require,module,exports){
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- // import Wizard from './ui/modules/Wizard.js';
- // import RecordOpener from './ui/components/RecordOpener.js';
- var _gsap = require("gsap");
- var _gsap2 = _interopRequireDefault(_gsap);
- var _config = require("./config.js");
- var _config2 = _interopRequireDefault(_config);
- var _Button = require("./ui/components/Button.js");
- var _Button2 = _interopRequireDefault(_Button);
- var _IntroSection = require("./ui/modules/IntroSection.js");
- var _IntroSection2 = _interopRequireDefault(_IntroSection);
- var _InputSection = require("./ui/modules/InputSection.js");
- var _InputSection2 = _interopRequireDefault(_InputSection);
- var _LearningSection = require("./ui/modules/LearningSection.js");
- var _LearningSection2 = _interopRequireDefault(_LearningSection);
- var _OutputSection = require("./ui/modules/OutputSection.js");
- var _OutputSection2 = _interopRequireDefault(_OutputSection);
- var _Recording = require("./ui/modules/Recording");
- var _Recording2 = _interopRequireDefault(_Recording);
- var _LaunchScreen = require("./ui/modules/wizard/LaunchScreen.js");
- var _LaunchScreen2 = _interopRequireDefault(_LaunchScreen);
- var _QuickLaunch = require("./ui/modules/wizard/QuickLaunch.js");
- var _QuickLaunch2 = _interopRequireDefault(_QuickLaunch);
- var _BrowserUtils = require("./ui/components/BrowserUtils");
- var _BrowserUtils2 = _interopRequireDefault(_BrowserUtils);
- var _Iframe = require("./ui/modules/Iframe.js");
- var _Iframe2 = _interopRequireDefault(_Iframe);
- var _tfjs = require("@tensorflow/tfjs");
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function init() {
- // Shim for forEach for IE/Edge
- if (typeof NodeList.prototype.forEach !== "function") {
- NodeList.prototype.forEach = Array.prototype.forEach;
- }
- _config2.default.browserUtils = new _BrowserUtils2.default();
- // GLOBALS.launchScreen = new LaunchScreen();
- _config2.default.quicklaunch = new _QuickLaunch2.default();
- // GLOBALS.iframePage = new Iframe(document.querySelector("#login_modal"))
- _config2.default.learningSection = new _LearningSection2.default(document.querySelector("#learning-section"));
- _config2.default.inputSection = new _InputSection2.default(document.querySelector("#input-section"));
- _config2.default.outputSection = new _OutputSection2.default(document.querySelector("#output-section"));
- // GLOBALS.recordOpener = new RecordOpener(document.querySelector('#record-open-section'));
- _config2.default.inputSection.ready();
- _config2.default.learningSection.ready();
- // GLOBALS.wizard = new Wizard();
- _config2.default.recordSection = new _Recording2.default(document.querySelector('#recording'));
- if (localStorage.getItem("isBackFacingCam") && localStorage.getItem("isBackFacingCam") === "true") {
- _config2.default.isBackFacingCam = true;
- }
- // Camera status messages per browser
- // if (GLOBALS.browserUtils.isChrome && !GLOBALS.browserUtils.isEdge) {
- // document.querySelector('.input__media__activate').innerHTML = 'To teach your machine, <span class="input__media__activate--desktop"> you need to click up here to turn on your camera and then <a href="#">refresh the page</a>.</span><span class="input__media__activate--mobile"> you need to <a href="#">refresh the page</a> and allow camera access.</span></p>';
- // if (!GLOBALS.browserUtils.isCompatable) {
- // document.querySelector('.wizard__browser-warning').innerHTML = 'Something went wrong and we could not load the site, please try restarting your browser.';
- // }
- // }else if (GLOBALS.browserUtils.isSafari) {
- // document.querySelector('.input__media__activate').innerHTML = 'To teach your machine, you need to turn on your camera. To do this click "Safari" in the menu bar, navigate to "Settings for This Website", in the "Camera" drop down menu choose "Allow" and then <a href="#">refresh the page</a>.';
- // }else if (GLOBALS.browserUtils.isFirefox) {
- // document.querySelector('.input__media__activate').innerHTML = 'To teach your machine, you need to turn on your camera. To do this you need to click this icon <img class="camera-icon" src="assets/ff-camera-icon.png"> to grant access and <a href="#">refresh the page</a>.';
- // }
- _config2.default.quicklaunch.start();
- }
- window.addEventListener("load", init);
- // language('zh-hans');
- // GLOBALS.lang = "hans"
- window.addEventListener("message", function (e) {
- var data = e.data;
- console.log('data', data);
- if ((typeof data === "undefined" ? "undefined" : _typeof(data)) === "object" && data.id === "loginVerify" && data.status === "logged") {
- _config2.default.USER.api_key = data.data.apiKey;
- _config2.default.outputSection.outputs.CloudOutput.getCoCloudEvent();
- _config2.default.lang = data.url.indexOf('zh') > -1 ? data.url.slice(3) : data.url;
- _config2.default.port = data.boards;
- // GLOBALS.iframePage.destory();
- language(data.url);
- if (document.getElementById('port_connect') && data.boards) {
- document.getElementById('portNumber').innerHTML = data.boards;
- document.getElementsByClassName('send_button')[0].classList.add('send_button_color');
- document.getElementsByClassName('send_button')[0].style.display = "block";
- document.getElementsByClassName('send_button')[1].classList.add('send_button_color');
- document.getElementsByClassName('send_button')[1].style.display = "none";
- }
- }
- if (typeof data === "string" && data === "startCam") {
- // GLOBALS.camInput.start();
- setTimeout(function () {
- _config2.default.camInput.webcam_on.click();
- }, 100);
- } else if (typeof data === "string" && data === "stopCam") {
- _config2.default.camInput.webcam_off.click();
- }
- });
- // setTimeout(() => { GLOBALS.camInput.webcam_on.click() }, 1000);
- function language(url) {
- var lang = {
- en: {
- start: "Start",
- input: 'Input',
- learning: "Learning",
- reset: "Big",
- CloudOutputL: "Cloud",
- SoundOutput: "Sound",
- SpeechOutput: "Speech",
- stop: "Stop",
- epxamples: "Examples",
- green: 'Train Character One',
- purple: 'Train Character Two',
- orange: 'Train Character Three',
- outputs: 'Output',
- ModuleOutput: "Module",
- training: "Training",
- triggered_green: "You've triggered Character One!",
- triggered_purple: "You've triggered Character Two!",
- triggered_orange: "You've triggered Character Three!",
- no_triggered: "Nothing is triggered",
- select_cloud: "Select your Cloud Event",
- confidence: "Confidence",
- posenet: "Posenet Result",
- custom_data: "Custom send values",
- cloud_title: "STATUS:",
- cloud_content: "Nothing is triggered",
- cloud_green: "Character One",
- cloud_purple: "Character Two",
- cloud_orange: "Character Three",
- selectCloud: "- Choose an event here -",
- content: "Play"
- },
- hans: {
- start: "开始",
- input: '输入',
- learning: "学习",
- reset: "放大",
- CloudOutputL: "云端",
- SoundOutput: "声音",
- SpeechOutput: "说话",
- stop: "停止",
- epxamples: "训练图像",
- green: '训练人物一',
- purple: '训练人物二',
- orange: '训练人物三',
- outputs: '输出',
- ModuleOutput: "模块",
- training: "训练中",
- triggered_green: "识别到了人物一!",
- triggered_purple: "识别到了人物二!",
- triggered_orange: "识别到了人物三!",
- no_triggered: "没有识别到任何东西",
- select_cloud: "选择发送云端事件",
- confidence: "置信度",
- posenet: "姿态识别结果",
- custom_data: "自定义发送值",
- cloud_title: "状态:",
- cloud_content: "什么都没有触发",
- cloud_green: "人物一",
- cloud_purple: "人物二",
- cloud_orange: "人物三",
- selectCloud: "- 请在这里选择一个事件 -",
- content: "播放"
- },
- hant: {
- start: "開始",
- input: '輸入',
- learning: "學習",
- reset: "放大",
- CloudOutputL: "雲端",
- SoundOutput: "聲音",
- SpeechOutput: "說話",
- stop: "停止",
- epxamples: "訓練圖像",
- green: '訓練人物一',
- purple: '訓練人物二',
- orange: '訓練人物三',
- outputs: '輸出',
- ModuleOutput: "模塊",
- training: "訓練中",
- triggered_green: "識別到了人物一!",
- triggered_purple: "識別到了人物二!",
- triggered_orange: "識別到了人物三!",
- no_triggered: "沒有識別到任何東西",
- select_cloud: "選擇發送雲端事件",
- confidence: "置信度",
- posenet: "姿態識別結果",
- custom_data: "自定義發送值",
- cloud_title: "狀態:",
- cloud_content: "什麼都沒有觸發",
- cloud_green: "人物一",
- cloud_purple: "人物二",
- cloud_orange: "人物三",
- selectCloud: "- 請在這裏選擇一個事件 -",
- content: "播放"
- }
- };
- setTimeout(function () {
- var language = lang.en;
- if (url === 'zh-hans') {
- language = lang.hans;
- } else if (url === 'zh-hant') {
- language = lang.hant;
- } else {
- language = lang.en;
- }
- document.getElementById('input').innerText = language.input;
- document.getElementById('start').innerText = language.start;
- document.getElementById('stop').innerText = language.stop;
- document.getElementById('CloudOutput').innerText = language.CloudOutputL;
- document.getElementById('SoundOutput').innerText = language.SoundOutput;
- document.getElementById('SpeechOutput').innerText = language.SpeechOutput;
- document.getElementById('learning').innerText = language.learning;
- document.getElementById('posenet').innerText = language.posenet;
- document.getElementById('train_green').innerText = language.green;
- document.getElementById('train_purple').innerText = language.purple;
- document.getElementById('train_orange').innerText = language.orange;
- document.getElementById('outputs').innerText = language.outputs;
- // document.getElementById('ModuleOutput').innerText = language.ModuleOutput;
- document.getElementById('cloud_title').innerText = language.cloud_title;
- document.getElementById('cloud__viewer_title').innerText = language.select_cloud;
- document.getElementById('cloud_content').innerText = language.no_triggered;
- document.getElementById('cloud_green').childNodes[1].innerText = language.cloud_green;
- document.getElementById('cloud_purple').childNodes[1].innerText = language.cloud_purple;
- document.getElementById('cloud_orange').childNodes[1].innerText = language.cloud_orange;
- var reset = document.getElementsByClassName('reset_lang');
- for (var i = 0; i < reset.length; i++) {
- reset[i].innerText = language.reset;
- }
- var confidence = document.getElementsByClassName('confidence__status_value');
- for (var _i = 0; _i < confidence.length; _i++) {
- confidence[_i].innerText = language.confidence;
- }
- var examples = document.getElementsByClassName('examples_lang');
- for (var _i2 = 0; _i2 < examples.length; _i2++) {
- examples[_i2].innerText = language.epxamples;
- }
- var custom_data = document.getElementsByClassName('custom_data');
- for (var _i3 = 0; _i3 < custom_data.length; _i3++) {
- custom_data[_i3].setAttribute("placeholder", language.custom_data);
- }
- }, 1000);
- }
- exports.default = _config2.default;
- },{"./config.js":242,"./ui/components/BrowserUtils":251,"./ui/components/Button.js":252,"./ui/modules/Iframe.js":258,"./ui/modules/InputSection.js":259,"./ui/modules/IntroSection.js":260,"./ui/modules/LearningSection.js":262,"./ui/modules/OutputSection.js":263,"./ui/modules/Recording":264,"./ui/modules/wizard/LaunchScreen.js":269,"./ui/modules/wizard/QuickLaunch.js":270,"@tensorflow/tfjs":205,"gsap":212}],244:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- // import 'gifler';
- var _gsap = require('gsap');
- var _gsap2 = _interopRequireDefault(_gsap);
- var _gifCanvas = require('./../ui/components/gifCanvas.js');
- var _gifCanvas2 = _interopRequireDefault(_gifCanvas);
- var _config = require('./../config.js');
- var _config2 = _interopRequireDefault(_config);
- var _tfjs = require('@tensorflow/tfjs');
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- var CloudOutput = function () {
- function CloudOutput() {
- var _this = this;
- _classCallCheck(this, CloudOutput);
- var lang = _config2.default.lang;
- var language = lang === "en" ? _config2.default.languare.en : lang === "hans" ? _config2.default.languare.hans : _config2.default.languare.hant;
- this.id = 'CloudOutput';
- this.element = document.createElement('div');
- this.element.classList.add('output__container');
- this.element.classList.add('cloud_output__container');
- this.classNames = _config2.default.classNames;
- this.colors = _config2.default.colors;
- this.cloudEvent = null;
- this.defaultKeys = ["detectA", "detectB", "detectC"];
- this.defaultValues = ["no", "no", "no"];
- this.defaultTexts = [];
- this.texts = [];
- this.currentIndex = null;
- this.currentClass = null;
- this.resultOffset = 0;
- this.numResults = 10;
- this.defaultTexts.push(language.cloud_green);
- this.defaultTexts.push(language.cloud_purple);
- this.defaultTexts.push(language.cloud_orange);
- this.edit = document.createElement('div');
- this.edit.classList.add('cloud__edit');
- this.editBar = document.createElement('div');
- this.editBar.classList.add('cloud__edit-bar');
- this.borders = [];
- // 并排排列三个结果显示框
- for (var index = 0; index < 3; index += 1) {
- var id = this.classNames[index];
- var text = this.defaultTexts[index];
- this.texts[index] = this.defaultTexts[index];
- var inputClass = document.createElement('div');
- inputClass.classList.add('cloud__thumb');
- inputClass.id = "cloud_" + id;
- inputClass.index = index;
- // inputClass.image = this.defaultclouds[index].cloud;
- var border = document.createElement('div');
- border.classList.add('cloud__thumb-border');
- border.classList.add('cloud__thumb-border--' + id);
- inputClass.appendChild(border);
- var inputContent = document.createElement('div');
- inputContent.classList.add('cloud__horizon_wrapper');
- inputContent.textContent = text;
- inputClass.appendChild(inputContent);
- this.editBar.appendChild(inputClass);
- this.borders.push(border);
- }
- // top-viewer
- this.editViewer = document.createElement('div');
- this.editViewer.classList.add('cloud__edit-viewer');
- this.viewerTitle = document.createElement('div');
- this.viewerTitle.id = "cloud__viewer_title";
- this.viewerTitle.classList.add('cloud__viewer_title');
- this.viewerTitle.textContent = language.select_cloud;
- this.editViewer.appendChild(this.viewerTitle);
- this.viewerSelection = document.createElement('div');
- this.viewerSelection.style = "margin-bottom:12px";
- this.viewerEvent = document.createElement('select');
- this.viewerEvent.style = "padding-left: 15px";
- this.viewerEvent.id = "selectCloud";
- this.viewerEvent.add(new Option(language.selectCloud, ""));
- this.viewerSelection.appendChild(this.viewerEvent);
- this.viewerButton = document.createElement('img');
- this.viewerButton.classList.add('cloud_icons');
- // this.viewerButton.textContent = "autorenew";
- this.viewerButton.src = "./media/refresh_tm.png";
- this.viewerButton.addEventListener('click', function () {
- _this.getCoCloudEvent();
- });
- this.viewerSelection.appendChild(this.viewerButton);
- this.editViewer.appendChild(this.viewerSelection);
- this.viewerOutput = document.createElement('div');
- this.viewerOutput.id = "cloud_output";
- this.viewerOutput.classList.add("cloud_output");
- this.viewerOutput_title = document.createElement('div');
- this.viewerOutput_title.id = "cloud_title";
- this.viewerOutput_title.classList.add("cloud_output_title");
- this.viewerOutput_title.textContent = language.cloud_title;
- this.viewerOutput_content = document.createElement('div');
- this.viewerOutput_content.id = "cloud_content";
- this.viewerOutput_content.classList.add("cloud_output_content");
- this.viewerOutput_content.textContent = language.no_triggered;
- this.viewerOutput_footer = document.createElement('div');
- this.viewerOutput_footer.id = "cloud_footer";
- this.viewerOutput_footer.classList.add("cloud_output_footer");
- this.viewerOutput_footer.textContent = "";
- this.viewerOutput.appendChild(this.viewerOutput_title);
- this.viewerOutput.appendChild(this.viewerOutput_content);
- this.viewerOutput.appendChild(this.viewerOutput_footer);
- this.editViewer.appendChild(this.viewerOutput);
- this.edit.appendChild(this.editViewer);
- //-- horizion
- this.edit.appendChild(this.editBar);
- this.element.appendChild(this.edit);
- }
- _createClass(CloudOutput, [{
- key: 'trigger',
- value: function trigger(index) {
- var _this2 = this;
- var lang = _config2.default.lang;
- var language = lang === "en" ? _config2.default.languare.en : lang === "hans" ? _config2.default.languare.hans : _config2.default.languare.hant;
- if (!_config2.default.clearing) {
- if (this.currentBorder && this.currentClassName) {
- this.currentBorder.classList.remove('cloud__thumb-border--' + this.currentClassName + '-selected');
- }
- var border = this.borders[index];
- var id = this.classNames[index];
- this.currentBorder = border;
- this.currentClassName = id;
- this.currentBorder.classList.add('cloud__thumb-border--' + this.currentClassName + '-selected');
- var textResult = this.texts[index];
- var data = {
- "detectA": "no",
- "detectB": "no",
- "detectC": "no"
- };
- var inputValue = document.getElementsByClassName('custom_data');
- data[this.defaultKeys[index]] = inputValue[index].value || this.defaultTexts[index];
- var output = document.getElementsByClassName('cloud__horizon_wrapper');
- for (var i = 0; i < output.length; i++) {
- var text = inputValue[i] && inputValue[i].value || this.defaultTexts[i];
- if (document.getElementsByClassName('cloud__horizon_wrapper')[i + 3]) {
- document.getElementsByClassName('cloud__horizon_wrapper')[i + 3].innerHTML = text;
- }
- }
- this.edit.appendChild(document.getElementById('coordinate_points'));
- //remove select class mode
- this.classNames.map(function (item) {
- _this2.viewerOutput.classList.remove('cloud_output--' + item);
- });
- this.classNames.map(function (item) {
- if (item != "red") {
- var _card = document.querySelector('#cloud_' + item);
- _card.classList.remove('cloud__thumb--' + item);
- }
- });
- this.viewerOutput_content.classList.remove("cloud_output_trigger");
- this.viewerOutput_content.textContent = language.no_triggered;
- this.viewerOutput_footer.classList.remove("cloud_output_trigger");
- this.viewerOutput_footer.textContent = "";
- //---
- var card = document.querySelector('#cloud_' + this.currentClassName);
- card.classList.add('cloud__thumb--' + this.currentClassName);
- this.viewerOutput.classList.add('cloud_output--' + this.currentClassName);
- this.viewerOutput_content.classList.add("cloud_output_trigger");
- var type = this.currentClassName === "green" ? language.triggered_green : this.currentClassName === "purple" ? language.triggered_purple : language.triggered_orange;
- this.viewerOutput_content.textContent = type;
- // this.viewerOutput_content.textContent = `You've triggered ${this.currentClassName}!`
- this.viewerOutput_footer.classList.add("cloud_output_trigger");
- if (this.currentIndex != index) this.AjaxCloudEvent(data);
- this.currentIndex = index;
- }
- if (_config2.default.clearing) {
- var _card2 = document.querySelector('#cloud_' + this.currentClassName);
- _card2.classList.remove('cloud__thumb--' + this.currentClassName);
- this.classNames.map(function (item) {
- console.log(item);
- _this2.viewerOutput.classList.remove('cloud_output--' + item);
- });
- this.viewerOutput_content.classList.remove("cloud_output_trigger");
- this.viewerOutput_content.textContent = language.no_triggered;
- this.viewerOutput_footer.classList.remove("cloud_output_trigger");
- this.viewerOutput_footer.textContent = "";
- }
- }
- }, {
- key: 'stop',
- value: function stop() {
- this.element.style.display = 'none';
- // this.loadMore.removeEventListener('click', this.loadMoreResults.bind(this));
- }
- }, {
- key: 'start',
- value: function start() {
- this.element.style.display = 'block';
- // this.loadMore.addEventListener('click', this.loadMoreResults.bind(this));
- }
- }, {
- key: 'clear',
- value: function clear() {
- var _this3 = this;
- var lang = _config2.default.lang;
- var language = lang === "en" ? _config2.default.languare.en : lang === "hans" ? _config2.default.languare.hans : _config2.default.languare.hant;
- this.classNames.map(function (item) {
- _this3.viewerOutput.classList.remove('cloud_output--' + item);
- });
- this.classNames.forEach(function (item) {
- if (item != "red") {
- var card = document.querySelector('#cloud_' + item);
- card.classList.remove('cloud__thumb--' + item);
- }
- });
- this.viewerOutput_content.classList.remove("cloud_output_trigger");
- this.viewerOutput_content.textContent = language.no_triggered;
- this.viewerOutput_footer.classList.remove("cloud_output_trigger");
- this.viewerOutput_footer.textContent = "";
- }
- }, {
- key: 'showAnimation',
- value: function showAnimation(index) {
- if (this.gifCanvas) {
- _config2.default.isRecording = true;
- // this.gifCanvas.setSource(url);
- }
- }
- }, {
- key: 'stopAnimation',
- value: function stopAnimation() {
- if (this.gifCanvas) {
- _config2.default.isRecording = false;
- this.gifCanvas.clear();
- }
- }
- }, {
- key: 'getCoCloudEvent',
- value: function getCoCloudEvent() {
- var ajax = new XMLHttpRequest();
- var that = this;
- ajax.onreadystatechange = function () {
- if (this.status === 200 && this.readyState === 4) {
- _config2.default.USER.events = ajax.response;
- that.updateCoEvent();
- }
- };
- var url = _config2.default.base_url + 'iot/data/apikey/' + _config2.default.USER.api_key + '/event/';
- ajax.open('get', url, true);
- ajax.withCredentials = true;
- ajax.send(null);
- }
- }, {
- key: 'updateCoEvent',
- value: function updateCoEvent() {
- var lang = _config2.default.lang;
- var language = lang === "en" ? _config2.default.languare.en : lang === "hans" ? _config2.default.languare.hans : _config2.default.languare.hant;
- var select = document.querySelector("#selectCloud");
- select.innerHTML = "";
- var option0 = document.createElement('option');
- option0.textContent = language.selectCloud;
- option0.value = "";
- select.appendChild(option0);
- // select.empty();
- var events = JSON.parse(_config2.default.USER.events);
- var temp = events.map(function (event) {
- var option = document.createElement('option');
- option.textContent = event.name;
- option.value = event.eventAPIKey;
- select.appendChild(option);
- // select.append(option)
- });
- }
- }, {
- key: 'AjaxCloudEvent',
- value: function AjaxCloudEvent(data) {
- var that = this;
- // var request = new XMLHttpRequest();
- // request.onreadystatechange = function() {
- // if (this.status === 200 && this.readyState === 4) {
- // console.log("You have send data to CocoCloud");
- // that.viewerOutput_footer.textContent = "Event data updated."
- // }
- // };
- // var url = `${GLOBALS.base_url}iot/data/eventAPIKey/${this.viewerEvent.value}`;
- // request.setRequestHeader("Content-type", "application/json");
- // request.open('post', url, true);
- // request.send(data);
- $.ajax(_config2.default.base_url + 'iot/data/eventAPIKey/' + this.viewerEvent.value, {
- type: "POST",
- xhrFields: {
- withCredentials: true
- },
- data: data,
- success: function success() {
- that.viewerOutput_footer.textContent = "Event data updated.";
- },
- error: function error() {
- that.viewerOutput_footer.textContent = "Event data updated fail.";
- }
- });
- }
- }]);
- return CloudOutput;
- }();
- exports.default = CloudOutput;
- },{"./../config.js":242,"./../ui/components/gifCanvas.js":257,"@tensorflow/tfjs":205,"gsap":212}],245:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _gsap = require('gsap');
- var _gsap2 = _interopRequireDefault(_gsap);
- require('gifler');
- var _GifCanvas = require('./../ui/components/GifCanvas.js');
- var _GifCanvas2 = _interopRequireDefault(_GifCanvas);
- var _config = require('./../config.js');
- var _config2 = _interopRequireDefault(_config);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var GIFOutput = function () {
- function GIFOutput() {
- _classCallCheck(this, GIFOutput);
- this.id = 'GIFOutput';
- this.element = document.createElement('div');
- this.element.classList.add('output__container');
- this.classNames = _config2.default.classNames;
- this.colors = _config2.default.colors;
- this.defaultGifs = [];
- this.gifs = [];
- this.currentIndex = null;
- this.currentClass = null;
- this.resultOffset = 0;
- this.numResults = 10;
- this.useCanvas = !_config2.default.browserUtils.isMobile && _config2.default.browserUtils.isChrome;
- if (this.useCanvas) {
- this.gifCanvas = new _GifCanvas2.default();
- }
- this.defaultGifs.push({
- still: 'https://media1.giphy.com/media/vFKqnCdLPNOKc/giphy-downsized_s.gif',
- gif: 'https://media1.giphy.com/media/vFKqnCdLPNOKc/200w.gif'
- });
- this.defaultGifs.push({
- still: 'https://media3.giphy.com/media/14ivBLRRRmyQw0/giphy-downsized_s.gif',
- gif: 'https://media3.giphy.com/media/14ivBLRRRmyQw0/200w.gif'
- });
- this.defaultGifs.push({
- still: 'https://media0.giphy.com/media/I3BLTIP5Gv6h2/giphy-downsized_s.gif',
- gif: 'https://media0.giphy.com/media/I3BLTIP5Gv6h2/200w.gif'
- });
- this.edit = document.createElement('div');
- this.edit.classList.add('gif__edit');
- this.editBar = document.createElement('div');
- this.editBar.classList.add('gif__edit-bar');
- this.borders = [];
- for (var index = 0; index < 3; index += 1) {
- var id = this.classNames[index];
- var image = this.defaultGifs[index].still;
- this.gifs[index] = this.defaultGifs[index];
- var button = document.createElement('div');
- button.classList.add('gif__thumb');
- button.id = id;
- button.index = index;
- button.image = this.defaultGifs[index].gif;
- var border = document.createElement('div');
- border.classList.add('gif__thumb-border');
- border.classList.add('gif__thumb-border--' + id);
- button.appendChild(border);
- var imageWrapper = document.createElement('div');
- imageWrapper.classList.add('gif__thumb-image-wrapper');
- imageWrapper.style.backgroundImage = 'url(' + image + ')';
- button.appendChild(imageWrapper);
- this.editBar.appendChild(button);
- button.imageWrapper = imageWrapper;
- button.addEventListener('mouseenter', this.editThumbOver.bind(this));
- button.addEventListener('mouseleave', this.editThumbOut.bind(this));
- button.addEventListener('click', this.editThumbClick.bind(this));
- this.borders.push(border);
- }
- this.editViewer = document.createElement('div');
- this.editViewer.classList.add('gif__edit-viewer');
- if (this.gifCanvas) {
- this.editViewer.appendChild(this.gifCanvas.getElement());
- this.gifCanvas.getElement().classList.add('gif__canvas');
- }
- this.edit.appendChild(this.editViewer);
- this.edit.appendChild(this.editBar);
- this.search = document.createElement('div');
- this.search.classList.add('gif__search');
- this.search.style.display = 'none';
- this.searchBar = document.createElement('div');
- this.searchBar.classList.add('gif__search-bar');
- this.searchInput = document.createElement('input');
- this.searchInput.setAttribute('placeholder', 'Search Giphy');
- this.searchInput.classList.add('gif__search-input');
- this.searchBar.appendChild(this.searchInput);
- this.searchBackButton = document.createElement('div');
- this.searchBackButton.classList.add('gif__search-back-button');
- this.searchBar.appendChild(this.searchBackButton);
- this.search.appendChild(this.searchBar);
- this.searchScroll = document.createElement('div');
- this.searchScroll.classList.add('gif__search-scroll');
- this.search.appendChild(this.searchScroll);
- this.searchScrollContent = document.createElement('div');
- this.searchScrollContent.classList.add('gif__search-scroll-content');
- var sponsorMessage = document.createElement('div');
- sponsorMessage.classList.add('gif__search-sponsor');
- this.searchScrollContent.appendChild(sponsorMessage);
- this.searchResults = document.createElement('div');
- this.searchResults.classList.add('gif__search-results');
- this.leftColumn = document.createElement('div');
- this.leftColumn.classList.add('gif__search-column');
- this.searchResults.appendChild(this.leftColumn);
- this.rightColumn = document.createElement('div');
- this.rightColumn.classList.add('gif__search-column');
- this.searchResults.appendChild(this.rightColumn);
- this.searchScrollContent.appendChild(this.searchResults);
- this.loadMore = document.createElement('div');
- this.loadMore.classList.add('gif__load-more');
- this.loadMore.textContent = 'Load more';
- this.searchScrollContent.appendChild(this.loadMore);
- this.searchScroll.appendChild(this.searchScrollContent);
- this.edit.appendChild(this.search);
- this.element.appendChild(this.edit);
- }
- _createClass(GIFOutput, [{
- key: 'editThumbOver',
- value: function editThumbOver(event) {
- var image = event.target.image;
- this.editViewer.style.backgroundImage = 'url(' + image + ')';
- this.showAnimation(image);
- }
- }, {
- key: 'editThumbOut',
- value: function editThumbOut(event) {
- this.editViewer.style.backgroundImage = 'none';
- this.stopAnimation();
- }
- }, {
- key: 'editThumbClick',
- value: function editThumbClick(event) {
- this.showSearch(event);
- }
- }, {
- key: 'loadMoreResults',
- value: function loadMoreResults() {
- this.searchGiphy();
- }
- }, {
- key: 'selectImage',
- value: function selectImage(event) {
- var index = this.currentClass.index;
- this.gifs[index] = {
- gif: event.currentTarget.large,
- still: event.currentTarget.still
- };
- this.currentClass.image = this.gifs[index].gif;
- this.currentClass.imageWrapper.style.backgroundImage = 'url(' + this.gifs[index].still + ')';
- this.hideSearch();
- }
- }, {
- key: 'displaySearchResults',
- value: function displaySearchResults(json) {
- this.leftColumn.innerHTML = '';
- this.rightColumn.innerHTML = '';
- var column = this.leftColumn;
- for (var index = 0; index < json.data.length; index += 1) {
- var small = json.data[index].images.fixed_width_small.url;
- // let large = json.data[index].images.downsized.url;
- var large = json.data[index].images.fixed_width.url;
- var still = json.data[index].images.downsized_still.url;
- var image = new Image();
- image.large = large;
- image.still = still;
- image.src = small;
- if (index % 2 === 0) {
- column = this.leftColumn;
- } else {
- column = this.rightColumn;
- }
- image.addEventListener('click', this.selectImage.bind(this));
- column.appendChild(image);
- }
- this.loadMore.style.opacity = 1;
- }
- }, {
- key: 'searchGiphy',
- value: function searchGiphy() {
- var that = this;
- var request = new XMLHttpRequest();
- request.onreadystatechange = function () {
- if (this.status === 200 && this.readyState === 4) {
- var json = JSON.parse(request.responseText);
- that.displaySearchResults(json);
- }
- };
- var url = 'https://api.giphy.com/v1/gifs/search?q=' + encodeURIComponent(this.phrase) + '&api_key=l4FGxiI99hPQ0k6nS&limit=' + this.numResults + '&offset=' + this.resultOffset;
- request.open('get', url, true);
- request.send();
- this.resultOffset += this.numResults;
- }
- }, {
- key: 'searchKeyUp',
- value: function searchKeyUp(event) {
- var value = this.searchInput.value;
- if (value.length > 0) {
- this.phrase = value;
- this.resultOffset = 0;
- this.searchGiphy();
- }
- }
- }, {
- key: 'showSearch',
- value: function showSearch(event) {
- var id = event.currentTarget.getAttribute('id');
- this.currentClass = event.currentTarget;
- this.loadMore.style.opacity = 0;
- this.leftColumn.innerHTML = '';
- this.rightColumn.innerHTML = '';
- this.search.style.display = 'block';
- this.searchInput.className = 'gif__search-input';
- this.searchInput.classList.add('gif__search-input--' + id);
- this.searchBackButton.className = 'gif__search-back-button';
- this.searchBackButton.classList.add('gif__search-back-button--' + id);
- this.searchInput.focus();
- this.searchInput.value = '';
- }
- }, {
- key: 'hideSearch',
- value: function hideSearch() {
- this.search.style.display = 'none';
- }
- }, {
- key: 'trigger',
- value: function trigger(index) {
- if (!_config2.default.clearing) {
- this.currentIndex = index;
- if (this.currentBorder && this.currentClassName) {
- this.currentBorder.classList.remove('gif__thumb-border--' + this.currentClassName + '-selected');
- }
- var border = this.borders[index];
- var id = this.classNames[index];
- this.currentBorder = border;
- this.currentClassName = id;
- this.currentBorder.classList.add('gif__thumb-border--' + this.currentClassName + '-selected');
- var image = this.gifs[this.currentIndex].gif;
- this.editViewer.style.backgroundImage = 'url(' + image + ')';
- this.showAnimation(image);
- }
- if (_config2.default.clearing) {
- this.currentBorder.classList.remove('gif__thumb-border--' + this.currentClassName + '-selected');
- }
- }
- }, {
- key: 'stop',
- value: function stop() {
- this.element.style.display = 'none';
- this.searchInput.removeEventListener('keyup', this.searchKeyUp.bind(this));
- this.searchBackButton.removeEventListener('click', this.hideSearch.bind(this));
- this.loadMore.removeEventListener('click', this.loadMoreResults.bind(this));
- }
- }, {
- key: 'start',
- value: function start() {
- this.element.style.display = 'block';
- this.searchInput.addEventListener('keyup', this.searchKeyUp.bind(this));
- this.searchBackButton.addEventListener('click', this.hideSearch.bind(this));
- this.loadMore.addEventListener('click', this.loadMoreResults.bind(this));
- }
- }, {
- key: 'showAnimation',
- value: function showAnimation(url) {
- if (this.gifCanvas) {
- _config2.default.isRecording = true;
- this.gifCanvas.setSource(url);
- }
- }
- }, {
- key: 'clear',
- value: function clear() {}
- }, {
- key: 'stopAnimation',
- value: function stopAnimation() {
- if (this.gifCanvas) {
- _config2.default.isRecording = false;
- this.gifCanvas.clear();
- }
- }
- }]);
- return GIFOutput;
- }();
- exports.default = GIFOutput;
- },{"./../config.js":242,"./../ui/components/GifCanvas.js":254,"gifler":209,"gsap":212}],246:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- // import 'gifler';
- var _gsap = require('gsap');
- var _gsap2 = _interopRequireDefault(_gsap);
- var _gifCanvas = require('./../ui/components/gifCanvas.js');
- var _gifCanvas2 = _interopRequireDefault(_gifCanvas);
- var _config = require('./../config.js');
- var _config2 = _interopRequireDefault(_config);
- var _tfjs = require('@tensorflow/tfjs');
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- var ModuleOutput = function () {
- function ModuleOutput() {
- var _this = this;
- _classCallCheck(this, ModuleOutput);
- setTimeout(function () {
- var lang = _config2.default.lang;
- var language = lang === "en" ? _config2.default.languare.en : lang === "hans" ? _config2.default.languare.hans : _config2.default.languare.hant;
- _this.id = 'ModuleOutput';
- _this.element = document.createElement('div');
- _this.element.classList.add('output__container');
- _this.element.classList.add('cloud_output__container');
- _this.classNames = _config2.default.classNames;
- _this.colors = _config2.default.colors;
- _this.cloudEvent = null;
- _this.defaultKeys = ["detectA", "detectB", "detectC"];
- _this.defaultValues = ["no", "no", "no"];
- _this.defaultTexts = [];
- _this.texts = [];
- _this.currentIndex = null;
- _this.currentClass = null;
- _this.resultOffset = 0;
- _this.numResults = 10;
- _this.defaultTexts.push(language.cloud_green);
- _this.defaultTexts.push(language.cloud_purple);
- _this.defaultTexts.push(language.cloud_orange);
- _this.edit = document.createElement('div');
- _this.edit.classList.add('module__edit');
- _this.editBar = document.createElement('div');
- _this.editBar.classList.add('cloud__edit-bar');
- _this.borders = [];
- // 并排排列三个结果显示框
- for (var index = 0; index < 3; index += 1) {
- var id = _this.classNames[index];
- var text = _this.defaultTexts[index];
- _this.texts[index] = _this.defaultTexts[index];
- var inputClass = document.createElement('div');
- inputClass.classList.add('cloud__thumb');
- inputClass.id = "module_" + id;
- inputClass.index = index;
- // inputClass.image = this.defaultclouds[index].cloud;
- var border = document.createElement('div');
- border.classList.add('cloud__thumb-border');
- border.classList.add('cloud__thumb-border--' + id);
- inputClass.appendChild(border);
- var inputContent = document.createElement('div');
- inputContent.classList.add('cloud__horizon_wrapper');
- inputContent.textContent = text;
- inputClass.appendChild(inputContent);
- _this.editBar.appendChild(inputClass);
- _this.borders.push(border);
- }
- // top-viewer
- _this.editViewer = document.createElement('div');
- _this.editViewer.classList.add('cloud__edit-viewer');
- _this.viewerTitle = document.createElement('div');
- _this.viewerTitle.classList.add('cloud__viewer_title');
- _this.viewerTitle.textContent = lang == 'en' ? 'Send Module' : lang == 'hant' ? "發送到模塊" : "发送到模块";
- _this.editViewer.appendChild(_this.viewerTitle);
- _this.viewerSelection = document.createElement('div');
- _this.viewerSelection.id = "port_connect";
- _this.viewerSelection.style = "height:40px;text-align:left;line-height:40px;";
- var port = lang == 'en' ? 'Port' : lang == 'hant' ? "端口" : "端口";
- var connects = lang == 'en' ? 'Connect' : lang == 'hant' ? "連接" : "连接";
- var disconnects = lang == 'en' ? 'Disconnect' : lang == 'hant' ? "斷開" : "断开";
- _this.viewerSelection.innerHTML = '<span>' + port + ':</span><span id="portNumber">' + (_config2.default.port ? _config2.default.port : "") + '</span><button class="send_button ' + (_config2.default.port && 'send_button_color') + '" style="display:block">' + connects + '</button><button class="send_button ' + (_config2.default.port && 'send_button_color') + '" style="display:none">' + disconnects + '</button>';
- _this.viewerSelection.addEventListener('click', function (e) {
- var send = document.getElementsByClassName('send_button');
- if (e.target.tagName == "BUTTON") {
- if (send[0].style.display == 'block' && _config2.default.port) {
- send[0].style.display = "none";
- send[1].style.display = "block";
- window.parent.postMessage("open", "*");
- } else if (send[1].style.display == 'block' && _config2.default.port) {
- send[0].style.display = "block";
- send[1].style.display = "none";
- window.parent.postMessage("close", "*");
- }
- }
- });
- // this.viewerSelection.appendChild(this.modulePortNumber)
- _this.editViewer.appendChild(_this.viewerSelection);
- _this.viewerOutput = document.createElement('div');
- _this.viewerOutput.id = "cloud_output";
- _this.viewerOutput.classList.add("cloud_output");
- _this.viewerOutput_title = document.createElement('div');
- _this.viewerOutput_title.id = "cloud_title";
- _this.viewerOutput_title.classList.add("cloud_output_title");
- _this.viewerOutput_title.textContent = language.cloud_title;
- _this.viewerOutput_content = document.createElement('div');
- _this.viewerOutput_content.id = "cloud_content";
- _this.viewerOutput_content.classList.add("cloud_output_content");
- _this.viewerOutput_content.textContent = language.no_triggered;
- _this.viewerOutput_footer = document.createElement('div');
- _this.viewerOutput_footer.id = "cloud_footer";
- _this.viewerOutput_footer.classList.add("cloud_output_footer");
- _this.viewerOutput_footer.textContent = "";
- _this.viewerOutput.appendChild(_this.viewerOutput_title);
- _this.viewerOutput.appendChild(_this.viewerOutput_content);
- _this.viewerOutput.appendChild(_this.viewerOutput_footer);
- _this.editViewer.appendChild(_this.viewerOutput);
- _this.edit.appendChild(_this.editViewer);
- //-- horizion
- _this.edit.appendChild(_this.editBar);
- _this.element.appendChild(_this.edit);
- }, 1500);
- }
- _createClass(ModuleOutput, [{
- key: 'trigger',
- value: function trigger(index) {
- var _this2 = this;
- var lang = _config2.default.lang;
- var language = lang === "en" ? _config2.default.languare.en : lang === "hans" ? _config2.default.languare.hans : _config2.default.languare.hant;
- if (!_config2.default.clearing) {
- if (this.currentBorder && this.currentClassName) {
- this.currentBorder.classList.remove('cloud__thumb-border--' + this.currentClassName + '-selected');
- }
- var border = this.borders[index];
- var id = this.classNames[index];
- this.currentBorder = border;
- this.currentClassName = id;
- this.currentBorder.classList.add('cloud__thumb-border--' + this.currentClassName + '-selected');
- var textResult = this.texts[index];
- var data = {
- "detectA": "no",
- "detectB": "no",
- "detectC": "no"
- };
- var inputValue = document.getElementsByClassName('custom_data');
- data[this.defaultKeys[index]] = inputValue[index].value || this.defaultTexts[index];
- var output = document.getElementsByClassName('cloud__horizon_wrapper');
- for (var i = 0; i < output.length; i++) {
- var text = inputValue[i] && inputValue[i].value || this.defaultTexts[i];
- if (document.getElementsByClassName('cloud__horizon_wrapper')[i + 3]) {
- document.getElementsByClassName('cloud__horizon_wrapper')[i + 3].innerHTML = text;
- }
- }
- this.edit.appendChild(document.getElementById('coordinate_points'));
- //remove select class mode
- this.classNames.map(function (item) {
- _this2.viewerOutput.classList.remove('cloud_output--' + item);
- });
- this.classNames.map(function (item) {
- if (item != "red") {
- var _card = document.querySelector('#module_' + item);
- _card.classList.remove('cloud__thumb--' + item);
- }
- });
- this.viewerOutput_content.classList.remove("cloud_output_trigger");
- this.viewerOutput_content.textContent = language.no_triggered;
- this.viewerOutput_footer.classList.remove("cloud_output_trigger");
- this.viewerOutput_footer.textContent = "";
- //---
- var card = document.querySelector('#module_' + this.currentClassName);
- card.classList.add('cloud__thumb--' + this.currentClassName);
- this.viewerOutput.classList.add('cloud_output--' + this.currentClassName);
- this.viewerOutput_content.classList.add("cloud_output_trigger");
- var type = this.currentClassName === "green" ? language.triggered_green : this.currentClassName === "purple" ? language.triggered_purple : language.triggered_orange;
- this.viewerOutput_content.textContent = type;
- this.viewerOutput_footer.classList.add("cloud_output_trigger");
- if (this.currentIndex != index) this.sendModuleEvent(data);
- this.currentIndex = index;
- }
- if (_config2.default.clearing) {
- var _card2 = document.querySelector('#module_' + this.currentClassName);
- _card2.classList.remove('cloud__thumb--' + this.currentClassName);
- this.classNames.map(function (item) {
- _this2.viewerOutput.classList.remove('cloud_output--' + item);
- });
- this.viewerOutput_content.classList.remove("cloud_output_trigger");
- this.viewerOutput_content.textContent = language.no_triggered;
- this.viewerOutput_footer.classList.remove("cloud_output_trigger");
- this.viewerOutput_footer.textContent = "";
- }
- }
- }, {
- key: 'stop',
- value: function stop() {
- this.element.style.display = 'none';
- // this.loadMore.removeEventListener('click', this.loadMoreResults.bind(this));
- }
- }, {
- key: 'start',
- value: function start() {
- this.element.style.display = 'block';
- // this.loadMore.addEventListener('click', this.loadMoreResults.bind(this));
- }
- }, {
- key: 'clear',
- value: function clear() {
- var _this3 = this;
- var lang = _config2.default.lang;
- var language = lang === "en" ? _config2.default.languare.en : lang === "hans" ? _config2.default.languare.hans : _config2.default.languare.hant;
- this.classNames.map(function (item) {
- _this3.viewerOutput.classList.remove('cloud_output--' + item);
- });
- this.classNames.forEach(function (item) {
- if (item != "red") {
- var card = document.querySelector('#module_' + item);
- card.classList.remove('cloud__thumb--' + item);
- }
- });
- this.viewerOutput_content.classList.remove("cloud_output_trigger");
- this.viewerOutput_content.textContent = language.no_triggered;
- this.viewerOutput_footer.classList.remove("cloud_output_trigger");
- this.viewerOutput_footer.textContent = "";
- }
- }, {
- key: 'showAnimation',
- value: function showAnimation(index) {
- if (this.gifCanvas) {
- _config2.default.isRecording = true;
- // this.gifCanvas.setSource(url);
- }
- }
- }, {
- key: 'stopAnimation',
- value: function stopAnimation() {
- if (this.gifCanvas) {
- _config2.default.isRecording = false;
- this.gifCanvas.clear();
- }
- }
- }, {
- key: 'updateCoEvent',
- value: function updateCoEvent() {
- var lang = _config2.default.lang;
- var language = lang === "en" ? _config2.default.languare.en : lang === "hans" ? _config2.default.languare.hans : _config2.default.languare.hant;
- var select = document.querySelector("#selectCloud");
- select.innerHTML = "";
- var option0 = document.createElement('option');
- option0.textContent = language.selectCloud;
- option0.value = "";
- select.appendChild(option0);
- // select.empty();
- var events = JSON.parse(_config2.default.USER.events);
- var temp = events.map(function (event) {
- var option = document.createElement('option');
- option.textContent = event.name;
- option.value = event.eventAPIKey;
- select.appendChild(option);
- // select.append(option)
- });
- }
- }, {
- key: 'sendModuleEvent',
- value: function sendModuleEvent(data) {
- var that = this;
- // var request = new XMLHttpRequest();
- // request.onreadystatechange = function() {
- // if (this.status === 200 && this.readyState === 4) {
- // console.log("You have send data to CocoCloud");
- // that.viewerOutput_footer.textContent = "Event data updated."
- // }
- // };
- // var url = `${GLOBALS.base_url}iot/data/eventAPIKey/${this.viewerEvent.value}`;
- // request.setRequestHeader("Content-type", "application/json");
- // request.open('post', url, true);
- // request.send(data);
- var datas = {
- posenet: window.dataPosenet,
- data: data
- };
- window.parent.postMessage(datas, "*");
- }
- }]);
- return ModuleOutput;
- }();
- exports.default = ModuleOutput;
- },{"./../config.js":242,"./../ui/components/gifCanvas.js":257,"@tensorflow/tfjs":205,"gsap":212}],247:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var _SoundSearch = require('./sound/SoundSearch.js');
- var _SoundSearch2 = _interopRequireDefault(_SoundSearch);
- var _config = require('./../config.js');
- var _config2 = _interopRequireDefault(_config);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- var SoundOutput = function () {
- function SoundOutput() {
- var _this = this;
- _classCallCheck(this, SoundOutput);
- setTimeout(function () {
- var lang = _config2.default.lang;
- var language = lang === "en" ? _config2.default.languare.en : lang === "hans" ? _config2.default.languare.hans : _config2.default.languare.hant;
- _this.id = 'SoundOutput';
- _this.loaded = false;
- _this.canTrigger = true;
- _this.basePath = 'assets/outputs/sound/sounds/';
- _this.assets = [];
- _this.assets.push('applause.mp3');
- _this.assets.push('bass.mp3');
- _this.assets.push('birds.mp3');
- _this.assets.push('cow.mp3');
- _this.assets.push('drum_joke.mp3');
- _this.assets.push('drum_roll.mp3');
- _this.assets.push('drums_1.mp3');
- _this.assets.push('drums_2.mp3');
- _this.assets.push('fanfare.mp3');
- _this.assets.push('flute_1.mp3');
- _this.assets.push('flute_2.mp3');
- _this.assets.push('flute_3.mp3');
- _this.assets.push('guitar_1.mp3');
- _this.assets.push('guitar_2.mp3');
- _this.assets.push('harp.mp3');
- _this.assets.push('jingle.mp3');
- _this.assets.push('orchestra.mp3');
- _this.assets.push('organ.mp3');
- _this.assets.push('trombone.mp3');
- _this.assets.push('trumpet_1.mp3');
- _this.assets.push('trumpet_2.mp3');
- _this.assets.push('trumpet_3.mp3');
- _this.assets.push('tuba.mp3');
- _this.numAssets = _this.assets.length;
- window.addEventListener('mobileLaunch', _this.touchAudio.bind(_this));
- _this.defaultAssets = [];
- _this.defaultAssets[0] = 'birds.mp3';
- _this.defaultAssets[1] = 'guitar_1.mp3';
- _this.defaultAssets[2] = 'trombone.mp3';
- _this.numLoaded = 0;
- _this.sounds = {};
- _this.currentSound = null;
- _this.currentIcon = null;
- _this.element = document.createElement('div');
- _this.element.classList.add('output__container');
- _this.element.classList.add('output__container--sound');
- _this.classNames = _config2.default.classNames;
- _this.colors = _config2.default.colors;
- _this.numClasses = _config2.default.numClasses;
- _this.loadingScreen = document.createElement('div');
- _this.loadingScreen.classList.add('output__loading-screen');
- _this.loadingScreen.classList.add('output__loading-screen--sound');
- var loadingTitle = document.createElement('div');
- loadingTitle.textContent = 'Loading';
- loadingTitle.classList.add('output__loading-title');
- _this.loadingScreen.appendChild(loadingTitle);
- _this.element.appendChild(_this.loadingScreen);
- _this.offScreen = document.createElement('div');
- _this.offScreen.classList.add('output__sound');
- var options = {};
- options.playCallback = _this.searchResultPlayClick.bind(_this);
- options.selectCallback = _this.searchResultClick.bind(_this);
- options.assets = _this.assets;
- _this.search = new _SoundSearch2.default(options);
- _this.offScreen.appendChild(_this.search.element);
- _this.inputClasses = [];
- _this.lastSound;
- for (var index = 0; index < _this.assets.length; index += 1) {
- var sound = _this.assets[index];
- var audio = new Audio();
- audio.muted = true;
- audio.loop = true;
- audio.addEventListener('canplaythrough', _this.assetLoaded.bind(_this));
- audio.src = _this.basePath + sound;
- _this.sounds[sound] = audio;
- }
- for (var _index = 0; _index < _this.numClasses; _index += 1) {
- var id = _this.classNames[_index];
- var inputClass = document.createElement('div');
- var _sound = _this.defaultAssets[_index];
- inputClass.classList.add('output__sound-class');
- inputClass.classList.add('output__sound-class--' + id);
- var speakerIcon = document.createElement('div');
- speakerIcon.classList.add('output__sound-speaker');
- speakerIcon.classList.add('output__sound-speaker--' + id);
- inputClass.sound = _sound;
- inputClass.icon = speakerIcon;
- var loader = function (el) {
- var ajax = new XMLHttpRequest();
- ajax.open('GET', 'assets/outputs/speaker-icon.svg', true);
- ajax.onload = function (event) {
- el.innerHTML = ajax.responseText;
- };
- ajax.send();
- }(speakerIcon);
- var editIcon = document.createElement('div');
- editIcon.classList.add('output__sound-edit');
- editIcon.classList.add('output__sound-edit--' + id);
- editIcon.setAttribute("data-attr", language.content);
- var input = document.createElement('input');
- input.classId = id;
- input.classList.add('output__sound-input');
- input.classList.add('output__sound-input--' + id);
- input.setAttribute('readonly', 'readonly');
- input.value = _sound;
- inputClass.appendChild(speakerIcon);
- inputClass.appendChild(editIcon);
- inputClass.appendChild(input);
- var deleteIcon = document.createElement('div');
- deleteIcon.classList.add('output__sound-delete');
- inputClass.appendChild(deleteIcon);
- deleteIcon.addEventListener('click', _this.clearInput.bind(_this));
- input.addEventListener('click', _this.editInput.bind(_this));
- document.addEventListener('visibilitychange', _this.handleVisibilityChange.bind(_this), false);
- // speakerIcon.addEventListener('click', this.testSound.bind(this));
- // this.inputClasses[index] = speakerIcon;
- inputClass.input = input;
- _this.inputClasses[_index] = inputClass;
- _this.offScreen.appendChild(inputClass);
- }
- _this.element.appendChild(_this.offScreen);
- _this.speakers = [];
- _this.buildCanvas();
- }, 1500);
- }
- _createClass(SoundOutput, [{
- key: 'handleVisibilityChange',
- value: function handleVisibilityChange() {
- if (_config2.default.outputSection.currentOutput && _config2.default.outputSection.currentOutput.id === 'SoundOutput') {
- if (this.currentSound === null) {
- this.currentSound;
- } else if (document.hidden) {
- this.currentSound.pause();
- } else {
- this.currentSound.play();
- }
- }
- }
- }, {
- key: 'playCurrentSound',
- value: function playCurrentSound() {
- if (this.currentSound) {
- this.currentSound.play();
- }
- }
- }, {
- key: 'pauseCurrentSound',
- value: function pauseCurrentSound() {
- if (this.currentSound) {
- this.currentSound.pause();
- }
- }
- }, {
- key: 'clearInput',
- value: function clearInput(event) {
- if (this.currentSound === this.sounds[event.target.parentNode.sound]) {
- this.currentSound.muted = true;
- this.currentSound = null;
- if (this.currentIcon) {
- this.currentIcon.classList.remove('output__sound-speaker--active');
- this.currentIcon = null;
- }
- }
- event.target.parentNode.sound = null;
- event.target.parentNode.input.value = 'Nothing';
- event.target.parentNode.input.classList.add('output__sound-input--nothing');
- if (this.currentBorder && this.currentClassName) {
- this.currentBorder.classList.remove('output__sound-input--' + this.currentClassName + '-selected');
- }
- }
- }, {
- key: 'searchResultPlayClick',
- value: function searchResultPlayClick(event) {
- event.stopPropagation();
- var sound = event.target.parentNode.value;
- this.lastSound = sound;
- this.playSound(sound);
- }
- }, {
- key: 'searchResultClick',
- value: function searchResultClick(event) {
- var value = event.target.value;
- this.activeInput.value = value;
- this.activeInput.parentNode.sound = value;
- this.activeInput.parentNode.input.classList.remove('output__sound-input--nothing');
- if (this.currentSound) {
- this.currentSound.muted = true;
- this.currentSound = null;
- }
- this.search.hide();
- }
- }, {
- key: 'editInput',
- value: function editInput(event) {
- this.activeInput = event.target;
- var classId = this.activeInput.classId;
- if (this.currentSound) {
- this.currentSound.muted = true;
- this.currentSound = null;
- if (this.currentIcon) {
- this.currentIcon.classList.remove('output__sound-speaker--active');
- this.currentIcon = null;
- }
- }
- this.search.show(classId);
- }
- }, {
- key: 'filterResults',
- value: function filterResults() {
- var phrase = this.searchInput.value;
- }
- }, {
- key: 'soundEnded',
- value: function soundEnded(event) {
- if (this.activeSpeaker) {
- this.currentSound.muted = true;
- this.activeSpeaker.classList.remove('output__sound-speaker--active');
- }
- this.canTrigger = true;
- if (this.currentSound === event.target) {
- this.currentSound.muted = true;
- this.currentSound = null;
- if (this.currentIcon) {
- this.currentIcon.classList.remove('output__sound-speaker--active');
- this.currentIcon = null;
- }
- }
- }
- }, {
- key: 'playSound',
- value: function playSound(sound) {
- this.muteSounds();
- if (!this.search.visible) {
- if (this.currentSound === sound) {
- this.currentSound = null;
- } else if (this.sounds[sound]) {
- this.currentSound = this.sounds[sound];
- this.currentSound.muted = false;
- this.currentSound.currentTime = 0;
- this.currentSound.play();
- this.lastSound = this.currentSound;
- }
- }
- }
- }, {
- key: 'muteSounds',
- value: function muteSounds() {
- if (this.currentSound) {
- this.currentSound.muted = true;
- }
- }
- }, {
- key: 'assetLoaded',
- value: function assetLoaded(event) {
- this.numLoaded += 1;
- if (this.numLoaded === this.numAssets) {
- this.loaded = true;
- for (var index = 0; index < this.numAssets; index += 1) {
- var id = this.assets[index];
- }
- this.showScreen();
- }
- }
- }, {
- key: 'showScreen',
- value: function showScreen() {
- this.loadingScreen.style.display = 'none';
- this.offScreen.style.display = 'block';
- }
- }, {
- key: 'trigger',
- value: function trigger(index) {
- if (!_config2.default.clearing) {
- if (this.currentIndex !== index) {
- this.currentIndex = index;
- var sound = this.inputClasses[this.currentIndex].sound;
- if (sound) {
- this.playSound(sound);
- } else {
- this.muteSounds();
- }
- if (this.currentIcon) {
- this.currentIcon.classList.remove('output__sound-speaker--active');
- }
- if (this.currentBorder && this.currentClassName) {
- this.currentBorder.classList.remove('output__sound-input--' + this.currentClassName + '-selected');
- }
- var border = this.inputClasses[index].input;
- var id = this.classNames[index];
- this.currentClassName = id;
- this.currentBorder = border;
- this.currentBorder.classList.add('output__sound-input--' + this.currentClassName + '-selected');
- this.currentIcon = this.inputClasses[this.currentIndex];
- this.currentIcon.classList.add('output__sound-speaker--active');
- if (this.canvas) {
- sound === null ? sound = '(nothing)' : sound;
- this.updateCanvas(this.currentIndex, sound);
- }
- }
- }
- if (_config2.default.clearing) {
- if (this.currentIcon) {
- this.currentIcon.classList.remove('output__sound-speaker--active');
- }
- if (this.currentBorder && this.currentClassName) {
- this.currentBorder.classList.remove('output__sound-input--' + this.currentClassName + '-selected');
- }
- for (var _index2 = 0; _index2 < this.numAssets; _index2 += 1) {
- var _id = this.assets[_index2];
- this.sounds[_id].pause();
- }
- }
- }
- }, {
- key: 'stop',
- value: function stop() {
- for (var index = 0; index < this.numAssets; index += 1) {
- var id = this.assets[index];
- this.sounds[id].pause();
- }
- this.element.style.display = 'none';
- }
- }, {
- key: 'start',
- value: function start() {
- this.element.style.display = 'block';
- this.handleVisibilityChange();
- }
- }, {
- key: 'clear',
- value: function clear() {}
- }, {
- key: 'buildCanvas',
- value: function buildCanvas() {
- var _this2 = this;
- this.canvas = document.createElement('canvas');
- this.canvas.style.display = 'none';
- this.context = this.canvas.getContext('2d');
- this.canvas.width = 340;
- this.canvas.height = 260;
- this.offScreen.appendChild(this.canvas);
- var img = new Image();
- img.onload = function () {
- _this2.canvasImage = img;
- };
- img.src = 'assets/outputs/speaker-icon.svg';
- }
- }, {
- key: 'updateCanvas',
- value: function updateCanvas(colorId, sound) {
- if (sound === 'null') {
- this.sound = ' ';
- }
- var color = '#2baa5e';
- switch (colorId) {
- case 0:
- color = '#2baa5e';
- break;
- case 1:
- color = '#c95ac5';
- break;
- default:
- case 2:
- color = '#dd4d31';
- break;
- }
- if (this.canvasImage) {
- this.context.globalCompositeOperation = 'source-over';
- this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
- this.context.fillStyle = 'rgb(255, 255, 255)';
- this.context.fillRect(0, 0, 300, 300);
- this.context.drawImage(this.canvasImage, 105, 52, 95, 95);
- this.context.font = '25px Poppins';
- this.context.fillStyle = '#000';
- this.context.fillText(sound, this.canvas.width / 2 - this.context.measureText(sound).width / 2 - 20, 207);
- this.context.globalCompositeOperation = 'screen';
- this.context.fillStyle = color;
- this.context.fillRect(0, 0, 300, 300);
- }
- }
- }, {
- key: 'touchAudio',
- value: function touchAudio() {
- for (var key in this.sounds) {
- /* eslint-disable */
- if (this.sounds.hasOwnProperty(key)) {
- this.sounds[key].play();
- this.sounds[key].pause();
- }
- /* eslint-enable */
- }
- }
- }]);
- return SoundOutput;
- }();
- exports.default = SoundOutput;
- },{"./../config.js":242,"./sound/SoundSearch.js":249}],248:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var _TextToSpeech = require('./speech/TextToSpeech.js');
- var _TextToSpeech2 = _interopRequireDefault(_TextToSpeech);
- var _config = require('./../config.js');
- var _config2 = _interopRequireDefault(_config);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- var SpeechOutput = function () {
- function SpeechOutput() {
- var _this = this;
- _classCallCheck(this, SpeechOutput);
- setTimeout(function () {
- var lang = _config2.default.lang;
- var language = lang === "en" ? _config2.default.languare.en : lang === "hans" ? _config2.default.languare.hans : _config2.default.languare.hant;
- _this.id = 'SpeechOutput';
- _this.canTrigger = true;
- _this.currentSound = null;
- _this.currentIcon = null;
- _this.currentIndex = null;
- _this.textToSpeech = new _TextToSpeech2.default();
- _this.element = document.createElement('div');
- _this.element.classList.add('output__container');
- _this.element.classList.add('output__container--speech');
- _this.defaultMessages = ['Hello', 'Awesome', 'Yes'];
- _this.classNames = _config2.default.classNames;
- _this.colors = _config2.default.colors;
- _this.numClasses = _config2.default.numClasses;
- _this.offScreen = document.createElement('div');
- _this.offScreen.classList.add('output__speech');
- var options = {};
- _this.inputClasses = [];
- for (var index = 0; index < _this.numClasses; index += 1) {
- var id = _this.classNames[index];
- var inputClass = document.createElement('div');
- var message = _this.defaultMessages[index];
- inputClass.defaultMessage = message;
- inputClass.message = message;
- inputClass.classList.add('output__speech-class');
- inputClass.classList.add('output__speech-class--' + id);
- var speakerIcon = document.createElement('div');
- speakerIcon.classList.add('output__speech-speaker');
- speakerIcon.classList.add('output__speech-speaker--' + id);
- var loader = function (el) {
- var ajax = new XMLHttpRequest();
- ajax.open('GET', 'assets/outputs/speaker-icon.svg', true);
- ajax.onload = function (event) {
- el.innerHTML = ajax.responseText;
- };
- ajax.send();
- }(speakerIcon);
- var editIcon = document.createElement('div');
- editIcon.classList.add('output__speech-edit');
- editIcon.classList.add('output__speech-edit--' + id);
- editIcon.setAttribute("data-attr", language.speech_content);
- var input = document.createElement('input');
- input.classId = id;
- input.classList.add('output__speech-input');
- input.classList.add('output__speech-input--' + id);
- input.setAttribute('maxlength', 25);
- input.value = _this.defaultMessages[index];
- inputClass.appendChild(speakerIcon);
- inputClass.appendChild(editIcon);
- inputClass.appendChild(input);
- var deleteIcon = document.createElement('div');
- deleteIcon.classList.add('output__speech-delete');
- inputClass.appendChild(deleteIcon);
- inputClass.input = input;
- inputClass.icon = speakerIcon;
- deleteIcon.addEventListener('click', _this.clearInput.bind(_this));
- input.addEventListener('blur', _this.inputBlur.bind(_this));
- input.addEventListener('keyup', _this.keyUp.bind(_this));
- input.addEventListener('click', _this.editInput.bind(_this));
- // speakerIcon.addEventListener('click', this.playSound.bind(this));
- _this.inputClasses[index] = inputClass;
- _this.element.appendChild(inputClass);
- }
- _this.buildCanvas();
- }, 1500);
- }
- _createClass(SpeechOutput, [{
- key: 'clearInput',
- value: function clearInput(event) {
- event.target.parentNode.message = null;
- event.target.parentNode.input.value = 'Nothing';
- event.target.parentNode.input.classList.add('output__speech-input--nothing');
- }
- }, {
- key: 'keyUp',
- value: function keyUp(event) {
- var message = event.target.value;
- event.target.parentNode.message = message;
- event.target.classList.remove('output__speech-input--nothing');
- }
- }, {
- key: 'inputBlur',
- value: function inputBlur(event) {
- var message = event.target.value;
- event.target.classList.remove('output__speech-input--nothing');
- message = event.target.value;
- event.target.parentNode.message = message;
- }
- }, {
- key: 'editInput',
- value: function editInput(event) {
- event.target.parentNode.input.value = '';
- this.activeInput = event.target;
- var classId = this.activeInput.classId;
- }
- }, {
- key: 'filterResults',
- value: function filterResults() {
- var phrase = this.searchInput.value;
- if (phrase.length === 0) {
- phrase = 'Hello';
- }
- this.ttsItem.children[1].value = '"' + phrase + '"';
- this.ttsItem.value = '"' + phrase + '"';
- }
- }, {
- key: 'soundEnded',
- value: function soundEnded(event) {
- if (this.activeSpeaker) {
- this.activeSpeaker.classList.remove('output__speech-speaker--active');
- }
- this.canTrigger = true;
- if (this.currentSound === event.target) {
- this.currentSound.pause();
- this.currentSound = null;
- if (this.currentIcon) {
- this.currentIcon.classList.remove('output__speech-speaker--active');
- this.currentIcon = null;
- }
- }
- }
- }, {
- key: 'ttsEnded',
- value: function ttsEnded() {
- if (this.activeSpeaker) {
- this.activeSpeaker.classList.remove('output__speech-speaker--active');
- }
- this.canTrigger = true;
- this.currentTTS = null;
- this.currentIcon.classList.remove('output__speech-speaker--active');
- }
- }, {
- key: 'playSound',
- value: function playSound(event) {
- var icon = event.target;
- var sound = icon.parentNode.message;
- if (this.currentIcon) {
- this.currentIcon.classList.remove('output__speech-speaker--active');
- }
- if (this.currentTTS) {
- this.textToSpeech.stop();
- }
- icon.classList.add('output__speech-speaker--active');
- this.textToSpeech.say(sound, this.ttsEnded.bind(this));
- this.currentTTS = true;
- this.currentIcon = icon;
- }
- }, {
- key: 'trigger',
- value: function trigger(index) {
- var overrideAndPlay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
- if (!_config2.default.clearing) {
- if (this.currentIndex !== index || overrideAndPlay) {
- this.canTrigger = false;
- this.currentIndex = index;
- if (this.currentIcon) {
- this.currentIcon.classList.remove('output__speech-speaker--active');
- }
- if (this.currentBorder && this.currentClassName) {
- this.currentBorder.classList.remove('output__speech-input--' + this.currentClassName + '-selected');
- }
- var border = this.inputClasses[index].input;
- var id = this.classNames[index];
- this.currentClassName = id;
- this.currentBorder = border;
- this.currentBorder.classList.add('output__speech-input--' + this.currentClassName + '-selected');
- if (this.currentTTS) {
- this.textToSpeech.stop();
- }
- var icon = this.inputClasses[index].icon;
- var sound = this.inputClasses[index].message;
- if (sound) {
- this.currentIcon = icon;
- this.currentIcon.classList.add('output__speech-speaker--active');
- this.textToSpeech.say(sound, this.ttsEnded.bind(this));
- this.currentTTS = true;
- } else {
- this.canTrigger = true;
- }
- if (this.canvas) {
- sound === null ? sound = '(nothing)' : sound;
- this.updateCanvas(this.currentIndex, sound);
- }
- }
- }
- if (_config2.default.clearing) {
- if (this.currentBorder && this.currentClassName) {
- this.currentBorder.classList.remove('output__speech-input--' + this.currentClassName + '-selected');
- }
- if (this.currentIcon) {
- this.currentIcon.classList.remove('output__speech-speaker--active');
- }
- if (this.currentTTS) {
- this.textToSpeech.stop();
- }
- }
- }
- }, {
- key: 'stop',
- value: function stop() {
- if (this.currentTTS) {
- this.textToSpeech.stop();
- }
- this.element.style.display = 'none';
- }
- }, {
- key: 'start',
- value: function start() {
- this.element.style.display = 'block';
- if (typeof this.currentIndex === 'number') {
- this.trigger(this.currentIndex, true);
- }
- }
- }, {
- key: 'clear',
- value: function clear() {}
- }, {
- key: 'buildCanvas',
- value: function buildCanvas() {
- var _this2 = this;
- this.canvas = document.createElement('canvas');
- this.canvas.style.display = 'none';
- this.context = this.canvas.getContext('2d');
- this.canvas.width = 340;
- this.canvas.height = 260;
- this.element.appendChild(this.canvas);
- var img = new Image();
- img.onload = function () {
- _this2.canvasImage = img;
- };
- img.src = 'assets/outputs/speaker-icon.svg';
- }
- }, {
- key: 'updateCanvas',
- value: function updateCanvas(colorId, sound) {
- if (sound === 'null') {
- this.sound = ' ';
- }
- var color = '#2baa5e';
- switch (colorId) {
- case 0:
- color = '#2baa5e';
- break;
- case 1:
- color = '#c95ac5';
- break;
- default:
- case 2:
- color = '#dd4d31';
- break;
- }
- if (this.canvasImage) {
- this.context.globalCompositeOperation = 'source-over';
- this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
- this.context.fillStyle = 'rgb(255, 255, 255)';
- this.context.fillRect(0, 0, 300, 300);
- this.context.drawImage(this.canvasImage, 105, 52, 95, 95);
- this.context.font = '25px Poppins';
- this.context.fillStyle = '#000';
- this.context.fillText(sound, this.canvas.width / 2 - 21, 207);
- this.context.textAlign = 'center';
- this.context.globalCompositeOperation = 'screen';
- this.context.fillStyle = color;
- this.context.fillRect(0, 0, 300, 300);
- }
- }
- }]);
- return SpeechOutput;
- }();
- exports.default = SpeechOutput;
- },{"./../config.js":242,"./speech/TextToSpeech.js":250}],249:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var SoundSearch = function () {
- function SoundSearch(options) {
- _classCallCheck(this, SoundSearch);
- this.playCallback = options.playCallback;
- this.selectCallback = options.selectCallback;
- this.assets = options.assets;
- this.element = document.createElement('div');
- this.element.classList.add('output__sound-search');
- this.searchBar = document.createElement('div');
- this.searchBar.classList.add('output__sound-search-bar');
- this.element.appendChild(this.searchBar);
- this.searchInput = document.createElement('input');
- this.searchInput.classList.add('output__sound-search-input');
- this.searchBar.appendChild(this.searchInput);
- this.backButton = document.createElement('div');
- this.backButton.addEventListener('click', this.hide.bind(this));
- this.backButton.classList.add('output__sound-back');
- var loader = function (el) {
- var ajax = new XMLHttpRequest();
- ajax.open('GET', 'assets/outputs/back-icon.svg', true);
- ajax.onload = function (event) {
- el.innerHTML = ajax.responseText;
- };
- ajax.send();
- }(this.backButton);
- this.searchBar.appendChild(this.backButton);
- this.searchResults = document.createElement('div');
- this.searchResults.classList.add('output__sound-search-results');
- this.allResults = [];
- for (var index = 0; index < this.assets.length; index += 1) {
- var item = document.createElement('div');
- item.classList.add('output__sound-search-result');
- var icon = document.createElement('div');
- icon.classList.add('output__sound-search-result-icon');
- var label = document.createElement('input');
- label.setAttribute('readonly', 'readonly');
- label.classList.add('output__sound-search-result-input');
- // icon.classList.add('output__sound-search-result-play');
- var _loader = function (el) {
- var ajax = new XMLHttpRequest();
- ajax.open('GET', 'assets/outputs/play-icon.svg', true);
- ajax.onload = function (event) {
- el.innerHTML = ajax.responseText;
- };
- ajax.send();
- }(icon);
- item.value = this.assets[index];
- label.value = item.value;
- icon.addEventListener('click', this.playCallback);
- this.allResults.push(item);
- item.appendChild(icon);
- item.appendChild(label);
- item.addEventListener('click', this.selectCallback);
- this.searchResults.appendChild(item);
- }
- this.element.appendChild(this.searchResults);
- this.searchInput.addEventListener('keyup', this.filterResults.bind(this));
- }
- _createClass(SoundSearch, [{
- key: 'hide',
- value: function hide() {
- this.element.style.display = 'none';
- this.searchResults.className = 'output__sound-search-results';
- this.searchInput.className = 'output__sound-search-input';
- this.backButton.className = 'output__sound-back';
- this.allResults.forEach(function (item) {
- var icon = item.children[0];
- icon.className = 'output__sound-search-result-icon';
- });
- this.visible = false;
- }
- }, {
- key: 'show',
- value: function show(classId) {
- this.element.style.display = 'block';
- this.searchResults.classList.add('output__sound-search-results--' + classId);
- this.searchInput.classList.add('output__sound-search-input--' + classId);
- this.backButton.classList.add('output__sound-back--' + classId);
- this.allResults.forEach(function (item) {
- var icon = item.children[0];
- icon.classList.add('output__sound-search-result-icon--' + classId);
- });
- this.searchInput.focus();
- this.visible = true;
- }
- }, {
- key: 'filterResults',
- value: function filterResults() {
- var phrase = this.searchInput.value;
- var showAll = false;
- if (phrase.length === 0) {
- showAll = true;
- }
- this.allResults.forEach(function (item) {
- if (showAll) {
- item.style.display = 'block';
- } else if (item.value.toLowerCase().indexOf(phrase.toLowerCase()) > -1) {
- item.style.display = 'block';
- } else {
- item.style.display = 'none';
- }
- });
- }
- }]);
- return SoundSearch;
- }();
- exports.default = SoundSearch;
- },{}],250:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var TextToSpeech = function () {
- function TextToSpeech() {
- _classCallCheck(this, TextToSpeech);
- this.voices = [];
- this.voice = null;
- this.message = null;
- if ((typeof speechSynthesis === 'undefined' ? 'undefined' : _typeof(speechSynthesis)) === 'object' && typeof speechSynthesis.onvoiceschanged === 'function') {
- speechSynthesis.onvoiceschanged = this.setVoice;
- }
- }
- _createClass(TextToSpeech, [{
- key: 'setVoice',
- value: function setVoice() {
- this.voices = window.speechSynthesis.getVoices();
- this.voice = this.voices.filter(function (voice) {
- return voice.name === 'Google US English Female';
- })[0];
- }
- }, {
- key: 'stop',
- value: function stop() {
- window.speechSynthesis.cancel();
- }
- }, {
- key: 'say',
- value: function say(text, callback) {
- this.message = new SpeechSynthesisUtterance();
- this.message.text = text;
- this.message.voice = this.voice;
- this.message.rate = 0.9;
- this.message.lang = 'en-US';
- this.message.addEventListener('end', callback);
- window.speechSynthesis.speak(this.message);
- }
- }]);
- return TextToSpeech;
- }();
- exports.default = TextToSpeech;
- },{}],251:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var BrowserUtils = function () {
- function BrowserUtils() {
- _classCallCheck(this, BrowserUtils);
- /* eslint-disable */
- this.isAndroid = navigator.userAgent.toLowerCase().indexOf('android') > -1;
- this.isSafari = navigator.userAgent.indexOf('Safari') > -1;
- this.isFirefox = navigator.userAgent.indexOf('Firefox') > -1;
- this.isIE = navigator.userAgent.indexOf('MSIE') > -1;
- this.isEdge = navigator.userAgent.indexOf('Edge') > -1;
- this.isMobile = false;
- this.isChrome = /chrome/i.test(navigator.userAgent);
- this.isCompatible;
- if (this.isChrome) {
- this.isSafari = false;
- }
- if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0, 4))) {
- this.isMobile = true;
- }
- if (this.isMobile) {
- var androidVersion = this.getAndroidVersion();
- if (androidVersion) {
- this.isSafari = false;
- }
- if (androidVersion && androidVersion >= 7) {
- this.isCompatible = true;
- }
- if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia && this.isSafari) {
- this.isCompatible = true;
- }
- } else {
- if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia && !this.isEdge && !this.isIE) {
- this.isCompatible = true;
- }
- }
- if (this.isCompatible) {
- this.isCompatible = this.webglSupport();
- }
- }
- _createClass(BrowserUtils, [{
- key: 'webglSupport',
- value: function webglSupport() {
- var canvas;
- var ctx;
- var exts;
- var support = false;
- try {
- canvas = document.createElement('canvas');
- ctx = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
- exts = ctx.getSupportedExtensions();
- } catch (e) {
- return support;
- }
- if (ctx !== undefined) {
- support = true;
- }
- for (var i = -1, len = exts.length; ++i < len;) {
- support = true;
- }
- canvas = undefined;
- console.log(support);
- return support;
- }
- }, {
- key: 'getAndroidVersion',
- value: function getAndroidVersion() {
- var ua = navigator.userAgent.toLowerCase();
- var match = ua.match(/android\s([0-9\.]*)/);
- return match ? parseInt(match[1], 10) : false;
- }
- /* eslint-enable */
- }]);
- return BrowserUtils;
- }();
- exports.default = BrowserUtils;
- },{}],252:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var _gsap = require('gsap');
- var _gsap2 = _interopRequireDefault(_gsap);
- var _config = require('./../../config.js');
- var _config2 = _interopRequireDefault(_config);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- var Button = function () {
- function Button(element) {
- var _this = this;
- _classCallCheck(this, Button);
- this.initialElement = element.innerHTML;
- this.element = element;
- element.addEventListener('mousedown', this.mousedown.bind(this));
- element.addEventListener('mouseup', this.mouseup.bind(this));
- element.addEventListener('touchstart', this.mousedown.bind(this));
- element.addEventListener('touchend', this.mouseup.bind(this));
- element.addEventListener('click', this.click.bind(this));
- window.addEventListener('resize', function () {
- clearTimeout(_this.sizeTimeout);
- _this.sizeTimeout = setTimeout(function () {
- _this.size();
- }, 300);
- });
- this.size();
- this.selected = false;
- }
- _createClass(Button, [{
- key: 'click',
- value: function click(event) {
- event.preventDefault();
- }
- }, {
- key: 'select',
- value: function select() {
- this.element.classList.add('button__toggle--selected');
- this.selected = true;
- this.down();
- }
- }, {
- key: 'deselect',
- value: function deselect() {
- this.element.classList.remove('button__toggle--selected');
- this.selected = false;
- this.up();
- }
- }, {
- key: 'mousedown',
- value: function mousedown(event) {
- event.preventDefault();
- this.down();
- }
- }, {
- key: 'mouseup',
- value: function mouseup(event) {
- if (this.selected) {
- return;
- }
- event.preventDefault();
- this.up();
- }
- }, {
- key: 'down',
- value: function down() {
- _gsap2.default.to(this.content, 0.12, {
- x: -(this.depthX - this.depthXPressed),
- y: this.depthY - this.depthYPressed
- });
- }
- }, {
- key: 'up',
- value: function up() {
- _gsap2.default.to(this.content, 0.12, {
- x: 0,
- y: 0
- });
- }
- }, {
- key: 'html',
- value: function html() {
- return this.el;
- }
- }, {
- key: 'setText',
- value: function setText(text) {
- this.label.children[0].innerHTML = text;
- }
- }, {
- key: 'size',
- value: function size() {
- var element = this.element;
- element.innerHTML = this.initialElement;
- element.style.height = 'auto';
- element.style.width = 'auto';
- var textWidth = element.offsetWidth;
- var textHeight = element.offsetHeight;
- var depthX = _config2.default.button.states.normal.x;
- var depthY = _config2.default.button.states.normal.y;
- var depthXPressed = _config2.default.button.states.pressed.x;
- var depthYPressed = _config2.default.button.states.pressed.y;
- if (element.classList.contains('button__toggle')) {
- textWidth += 3.5;
- this.isToggle = true;
- }
- if (element.classList.contains('button--large')) {
- textHeight += 20;
- textWidth += 20;
- }
- var frontWidth = textWidth + _config2.default.button.padding;
- var frontHeight = textHeight < _config2.default.button.frontHeight ? _config2.default.button.frontHeight : textHeight;
- if (element.classList.contains('button--small')) {
- textWidth = 36;
- textHeight = 30;
- frontWidth = textWidth;
- frontHeight = textHeight;
- }
- frontWidth = textWidth - _config2.default.button.states.normal.x;
- var buttonWidth = frontWidth + _config2.default.button.states.normal.x;
- var buttonHeight = frontHeight + _config2.default.button.states.normal.y;
- var colorClass = 'grey';
- element.classList.forEach(function (className) {
- if (className.indexOf('button--color-') > -1) {
- var index = className.indexOf('button--color-') + 'button--color-'.length;
- colorClass = className.slice(index);
- }
- });
- var buttonContent = element.children[0];
- buttonContent.classList.remove('button__content');
- var htmlContent = element.innerHTML;
- element.innerHTML = '';
- element.style.width = buttonWidth + 'px';
- element.style.height = buttonHeight + 'px';
- var mask = document.createElement('div');
- mask.classList.add('button__mask');
- var content = document.createElement('div');
- content.classList.add('button__inner');
- var label = document.createElement('div');
- label.classList.add('button__label');
- label.innerHTML = htmlContent;
- label.style.width = frontWidth + 'px';
- label.style.height = frontHeight + 'px';
- // label.style.lineHeight = frontHeight + 'px';
- label.style.left = depthX + 'px';
- content.appendChild(label);
- label.style.top = '10px';
- this.label = label;
- var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
- svg.setAttribute('width', buttonWidth);
- svg.setAttribute('height', buttonHeight);
- this.svg = svg;
- var frontFace = document.createElementNS('http://www.w3.org/2000/svg', 'path');
- frontFace.classList.add('front-face');
- frontFace.classList.add('front-face--' + colorClass);
- frontFace.setAttribute('d', 'M' + depthX + ' 0 ' + (frontWidth + depthX) + ' 0 ' + (frontWidth + depthX) + ' ' + frontHeight + ' ' + depthX + ' ' + frontHeight + 'z');
- svg.appendChild(frontFace);
- this.frontFace = frontFace;
- var bottomFace = document.createElementNS('http://www.w3.org/2000/svg', 'path');
- bottomFace.classList.add('bottom-face');
- bottomFace.classList.add('bottom-face--' + colorClass);
- bottomFace.setAttribute('d', 'M' + depthX + ' ' + frontHeight + ' ' + (frontWidth + depthX) + ' ' + frontHeight + ' ' + frontWidth + ' ' + (frontHeight + depthY) + ' 0 ' + (frontHeight + depthY) + 'z');
- svg.appendChild(bottomFace);
- this.bottomFace = bottomFace;
- var leftFace = document.createElementNS('http://www.w3.org/2000/svg', 'path');
- leftFace.classList.add('left-face');
- leftFace.classList.add('left-face--' + colorClass);
- leftFace.setAttribute('d', 'M0 ' + depthY + ' ' + depthX + ' 0 ' + depthX + ' ' + frontHeight + ' 0 ' + (frontHeight + depthY) + 'z');
- svg.appendChild(leftFace);
- this.leftFace = leftFace;
- content.appendChild(svg);
- mask.appendChild(content);
- element.appendChild(mask);
- // Editable for reszing
- this.label = label;
- this.svg = svg;
- this.frontFace = frontFace;
- this.bottomFace = bottomFace;
- this.leftFace = leftFace;
- this.parentWidth = element.parentNode.offsetWidth;
- this.buttonWidth = buttonWidth;
- this.buttonHeight = buttonHeight;
- this.textWidth = textWidth;
- this.textHeight = textHeight;
- this.frontWidth = frontWidth;
- this.frontHeight = frontHeight;
- this.depthX = depthX;
- this.depthY = depthY;
- this.depthXPressed = depthXPressed;
- this.depthYPressed = depthYPressed;
- this.buttonWidth = buttonWidth;
- this.buttonHeight = buttonHeight;
- this.content = content;
- this.depthX = depthX;
- this.depthY = depthY;
- this.depthXPressed = depthXPressed;
- this.depthYPressed = depthYPressed;
- this.element = element;
- this.selected = false;
- }
- }]);
- return Button;
- }();
- exports.default = Button;
- },{"./../../config.js":242,"gsap":212}],253:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _config = require('./../../config.js');
- var _config2 = _interopRequireDefault(_config);
- var _WebcamClassifier = require('./../../ai/WebcamClassifier.js');
- var _WebcamClassifier2 = _interopRequireDefault(_WebcamClassifier);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var CamInput = function () {
- function CamInput() {
- var _this = this;
- _classCallCheck(this, CamInput);
- this.element = document.createElement('div');
- this.element.classList.add('input__camera');
- this.webcamClassifier = new _WebcamClassifier2.default();
- this.element.appendChild(this.webcamClassifier.video);
- this.element.appendChild(document.getElementById('output'));
- // this.webcamClassifier.video.setAttribute('muted', 'true');
- // this.webcamClassifier.video.classList.add('input__camera-video');
- // this.webcamClassifier.video.addEventListener(
- // 'loadeddata', this.videoLoaded.bind(this));
- // this.webcamClassifier.video.addEventListener(
- // 'loadeddata', this.webcamClassifier.videoLoaded.bind(this));
- window.addEventListener('resize', this.size.bind(this));
- _config2.default.webcamClassifier = this.webcamClassifier;
- // this.stop();
- this.restartCam = document.querySelector(".cam--start");
- this.restartCam.addEventListener('click', function () {
- document.querySelector(".webcam--on").click();
- _this.start();
- _this.restartCam.style = "display:none";
- _this.stopCam.classList.add("show");
- // this.webcamClassifier.startWebcam();
- _config2.default.learningSection.enable();
- _config2.default.learningSection.undim();
- _config2.default.outputSection.undim();
- _config2.default.outputSection.enable();
- });
- this.stopCam = document.querySelector(".cam--stop");
- this.stopCam.addEventListener('click', function () {
- _this.stop();
- _this.restartCam.style = "display:flex";
- _this.stopCam.classList.remove("show");
- // this.webcamClassifier.stopWebcam();
- // document.querySelector(".webcam--off").click()
- _config2.default.learningSection.disable();
- _config2.default.learningSection.dim();
- _config2.default.outputSection.dim();
- _config2.default.outputSection.disable();
- _config2.default.outputSection.clear();
- _config2.default.learningSection.learningClasses.forEach(function (learningClass) {
- if (learningClass.exampleCounter > 0) learningClass.resetLink.click();
- });
- if (_config2.default.outputSection.currentOutput.clear) _config2.default.outputSection.currentOutput.clear();
- });
- this.webcam_on = document.querySelector(".webcam--on");
- this.webcam_on.addEventListener("click", function () {
- _this.restartCam.click();
- // this.webcamClassifier.startWebcam();
- });
- this.webcam_off = document.querySelector(".webcam--off");
- this.webcam_off.addEventListener("click", function () {
- _this.stopCam.click();
- _this.webcamClassifier.stopWebcam();
- });
- this.webcam_off.click();
- }
- _createClass(CamInput, [{
- key: 'videoLoaded',
- value: function videoLoaded() {
- this.videoWidth = this.webcamClassifier.video.videoWidth;
- this.videoHeight = this.webcamClassifier.video.videoHeight;
- this.videoRatio = this.videoWidth / this.videoHeight;
- this.size();
- }
- }, {
- key: 'start',
- value: function start() {
- this.show();
- if (this.started) {
- return;
- }
- this.started = true;
- // this.webcamClassifier.stopTimer();
- this.webcamClassifier.ready();
- }
- }, {
- key: 'stop',
- value: function stop() {
- this.started = false;
- this.webcamClassifier.stopTimer();
- this.hide();
- }
- }, {
- key: 'hide',
- value: function hide() {
- this.element.style.display = 'none';
- }
- }, {
- key: 'show',
- value: function show() {
- this.element.style.display = 'block';
- this.size();
- }
- }, {
- key: 'renderExamples',
- value: function renderExamples(canvas) {
- // console.log('render', canvas);
- }
- }, {
- key: 'resetClass',
- value: function resetClass(id) {
- this.webcamClassifier.deleteClassData(id);
- }
- }, {
- key: 'size',
- value: function size() {
- this.width = this.element.offsetWidth;
- this.height = this.width;
- this.webcamClassifier.video.width = 300;
- this.webcamClassifier.video.height = 436;
- /*
- if (this.videoRatio > 1) {
- this.webcamClassifier.video.width = this.height * this.videoRatio;
- this.webcamClassifier.video.height = this.height;
- }else {
- this.webcamClassifier.video.width = this.width;
- this.webcamClassifier.video.height = this.width / this.videoRatio;
- }*/
- }
- }]);
- return CamInput;
- }();
- exports.default = CamInput;
- },{"./../../ai/WebcamClassifier.js":241,"./../../config.js":242}],254:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _index = require('../../index');
- var _index2 = _interopRequireDefault(_index);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var GifCanvas = function () {
- function GifCanvas() {
- _classCallCheck(this, GifCanvas);
- this.element = document.createElement('div');
- this.canvas = document.createElement('canvas');
- this.context = this.canvas.getContext('2d');
- this.element.style.display = 'none';
- this.canvas.width = 340;
- this.canvas.height = 260;
- this.canvas.classList.add('gifler-canvas');
- this.canvas.name = 'gif';
- this.element.appendChild(this.canvas);
- this.gifs = {};
- }
- _createClass(GifCanvas, [{
- key: 'setSource',
- value: function setSource(source) {
- if (_index2.default.isRecording) {
- // Downsize the recorder gif
- var smallerSource = source.replace('200w.gif', '200_d.gif');
- if (smallerSource !== this.source) {
- this.clear();
- this.source = smallerSource;
- this.getGifler(smallerSource);
- }
- }
- }
- }, {
- key: 'getGifler',
- value: function getGifler(source) {
- var _this = this;
- return new Promise(function (resolve) {
- if (!_this.gifs[source]) {
- /* eslint-disable */
- window.gifler(source).frames('canvas.gifler-canvas', _this.draw.bind(_this)).then(function (response) {
- _this.gifs[source] = response;
- _this.gifs[source].start();
- resolve(_this.gifs[source]);
- });
- /* eslint-enable */
- }
- if (_this.gifs[source]) {
- _this.gifs[source].start();
- resolve(_this.gifs[source]);
- }
- });
- }
- }, {
- key: 'draw',
- value: function draw(ctx, frame) {
- if (_index2.default.isRecording) {
- var hRatio = this.canvas.width / frame.width;
- var vRatio = this.canvas.height / frame.height;
- var ratio = Math.min(hRatio, vRatio);
- var centerShiftX = (this.canvas.width - frame.width * ratio) / 2;
- var centerShiftY = (this.canvas.height - frame.height * ratio) / 2;
- ctx.drawImage(frame.buffer, 0, 0, frame.width, frame.height, centerShiftX, centerShiftY, frame.width * ratio, frame.height * ratio);
- } else {
- this.clear();
- }
- }
- }, {
- key: 'clear',
- value: function clear() {
- var _this2 = this;
- this.source = null;
- Object.keys(this.gifs).forEach(function (key) {
- var gif = _this2.gifs[key];
- gif.reset();
- gif.stop();
- });
- this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
- }
- }, {
- key: 'getElement',
- value: function getElement() {
- return this.element;
- }
- }]);
- return GifCanvas;
- }();
- exports.default = GifCanvas;
- },{"../../index":243}],255:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var HighlightArrow = function () {
- function HighlightArrow(type) {
- _classCallCheck(this, HighlightArrow);
- this.element = new Image();
- this.element.classList.add('wizard__arrow');
- this.element.width = 200;
- this.element.src = 'assets/arrows/arrow-' + type + '.svg';
- }
- _createClass(HighlightArrow, [{
- key: 'hide',
- value: function hide() {
- this.element.style.display = 'none';
- }
- }, {
- key: 'show',
- value: function show() {
- this.element.style.display = 'block';
- }
- }]);
- return HighlightArrow;
- }();
- exports.default = HighlightArrow;
- },{}],256:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _config = require('./../../config.js');
- var _config2 = _interopRequireDefault(_config);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var Selector = function () {
- function Selector(element) {
- _classCallCheck(this, Selector);
- this.element = element;
- var wrapper = element.parentNode;
- this.element.addEventListener('change', this.change.bind(this));
- this.titleWrapper = document.createElement('div');
- this.titleWrapper.classList.add('output__selector-title-wrapper');
- this.title = document.createElement('span');
- this.title.classList.add('output__selector-title');
- this.titleWrapper.appendChild(this.title);
- wrapper.appendChild(this.titleWrapper);
- this.change();
- }
- _createClass(Selector, [{
- key: 'change',
- value: function change() {
- var value = this.element.value;
- var text = this.element.options[this.element.selectedIndex].textContent;
- this.title.textContent = text;
- }
- }]);
- return Selector;
- }();
- exports.default = Selector;
- },{"./../../config.js":242}],257:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _index = require('../../index');
- var _index2 = _interopRequireDefault(_index);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var GifCanvas = function () {
- function GifCanvas() {
- _classCallCheck(this, GifCanvas);
- this.element = document.createElement('div');
- this.canvas = document.createElement('canvas');
- this.context = this.canvas.getContext('2d');
- this.element.style.display = 'none';
- this.canvas.width = 340;
- this.canvas.height = 260;
- this.canvas.classList.add('gifler-canvas');
- this.canvas.name = 'gif';
- this.element.appendChild(this.canvas);
- this.gifs = {};
- }
- _createClass(GifCanvas, [{
- key: 'setSource',
- value: function setSource(source) {
- if (_index2.default.isRecording) {
- // Downsize the recorder gif
- var smallerSource = source.replace('200w.gif', '200_d.gif');
- if (smallerSource !== this.source) {
- this.clear();
- this.source = smallerSource;
- this.getGifler(smallerSource);
- }
- }
- }
- }, {
- key: 'getGifler',
- value: function getGifler(source) {
- var _this = this;
- return new Promise(function (resolve) {
- if (!_this.gifs[source]) {
- /* eslint-disable */
- window.gifler(source).frames('canvas.gifler-canvas', _this.draw.bind(_this)).then(function (response) {
- _this.gifs[source] = response;
- _this.gifs[source].start();
- resolve(_this.gifs[source]);
- });
- /* eslint-enable */
- }
- if (_this.gifs[source]) {
- _this.gifs[source].start();
- resolve(_this.gifs[source]);
- }
- });
- }
- }, {
- key: 'draw',
- value: function draw(ctx, frame) {
- if (_index2.default.isRecording) {
- var hRatio = this.canvas.width / frame.width;
- var vRatio = this.canvas.height / frame.height;
- var ratio = Math.min(hRatio, vRatio);
- var centerShiftX = (this.canvas.width - frame.width * ratio) / 2;
- var centerShiftY = (this.canvas.height - frame.height * ratio) / 2;
- ctx.drawImage(frame.buffer, 0, 0, frame.width, frame.height, centerShiftX, centerShiftY, frame.width * ratio, frame.height * ratio);
- } else {
- this.clear();
- }
- }
- }, {
- key: 'clear',
- value: function clear() {
- var _this2 = this;
- this.source = null;
- Object.keys(this.gifs).forEach(function (key) {
- var gif = _this2.gifs[key];
- gif.reset();
- gif.stop();
- });
- this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
- }
- }, {
- key: 'getElement',
- value: function getElement() {
- return this.element;
- }
- }]);
- return GifCanvas;
- }();
- exports.default = GifCanvas;
- },{"../../index":243}],258:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _config = require('./../../config.js');
- var _config2 = _interopRequireDefault(_config);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- //class construct for login iframe
- var Iframe = function () {
- function Iframe(element) {
- _classCallCheck(this, Iframe);
- this.parentElement = element;
- this.parentElement.classList.add('iframe_class');
- this.iframe = document.createElement('iframe');
- this.iframe.src = "//cocorobo.cn/login/";
- this.iframe.scrolling = "no";
- this.iframe.classList.add('iframe_class');
- this.parentElement.append(this.iframe);
- }
- _createClass(Iframe, [{
- key: 'destory',
- value: function destory() {
- this.parentElement.innerHTML = "";
- _config2.default.iframe = false;
- }
- }]);
- return Iframe;
- }();
- exports.default = Iframe;
- },{"./../../config.js":242}],259:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _gsap = require('gsap');
- var _gsap2 = _interopRequireDefault(_gsap);
- var _config = require('./../../config.js');
- var _config2 = _interopRequireDefault(_config);
- var _Button = require('./../components/Button.js');
- var _Button2 = _interopRequireDefault(_Button);
- var _CamInput = require('./../components/CamInput.js');
- var _CamInput2 = _interopRequireDefault(_CamInput);
- var _HighlightArrow = require('./../components/HighlightArrow.js');
- var _HighlightArrow2 = _interopRequireDefault(_HighlightArrow);
- var _WizardGIFExample = require('./WizardGIFExample.js');
- var _WizardGIFExample2 = _interopRequireDefault(_WizardGIFExample);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var InputSection = function () {
- function InputSection(element) {
- _classCallCheck(this, InputSection);
- this.element = element;
- // this.camInputToggle = new Button(element.querySelector('#cam-input-toggle'));
- // this.micInputToggle = new Button(element.querySelector('#mic-input-toggle'));
- // this.camInputToggle.deselect();
- // this.micInputToggle.deselect();
- // this.camInputToggle.element.addEventListener('click', this.selectCamInput.bind(this));
- // this.micInputToggle.element.addEventListener('click', this.selectMicInput.bind(this));
- // this.camInputToggle.element.addEventListener('touchend', this.selectCamInput.bind(this));
- // this.micInputToggle.element.addEventListener('touchend', this.selectMicInput.bind(this));
- this.mediaFlipButton = element.querySelector('.input__media__flip');
- this.mediaFlipButton.addEventListener('click', this.flipCamera.bind(this));
- this.inputContainer = element.querySelector('.input__media');
- this.currentInput = null;
- // if (!GLOBALS.browserUtils.isMobile) {
- // this.createMicInput();
- // this.createCamInput();
- // this.selectCamInput();
- // this.camInputToggle.select();
- // }
- this.arrow = new _HighlightArrow2.default(1);
- if (_config2.default.browserUtils.isMobile) {
- _gsap2.default.set(this.arrow.element, {
- rotation: -120,
- scaleX: -0.5,
- x: -20,
- y: -60
- });
- } else {
- _gsap2.default.set(this.arrow.element, {
- rotation: -120,
- scaleX: -0.8,
- x: -20,
- y: -120
- });
- }
- this.element.appendChild(this.arrow.element);
- this.gifs = [];
- var gif1 = new _WizardGIFExample2.default('assets/wizard/1.gif');
- if (_config2.default.browserUtils.isMobile) {
- _gsap2.default.set(gif1.element, {
- rotation: -5,
- scale: 0.65,
- x: 40,
- y: 275
- });
- } else {
- _gsap2.default.set(gif1.element, {
- rotation: -5,
- scale: 0.65,
- x: 70,
- y: -25
- });
- }
- this.element.appendChild(gif1.element);
- this.gifs.push(gif1);
- var gif2 = new _WizardGIFExample2.default('assets/wizard/2.gif');
- if (_config2.default.browserUtils.isMobile) {
- _gsap2.default.set(gif2.element, {
- rotation: -5,
- scale: 0.65,
- x: 40,
- y: 275
- });
- } else {
- _gsap2.default.set(gif2.element, {
- rotation: -5,
- scale: 0.65,
- x: 70,
- y: -25
- });
- }
- this.element.appendChild(gif2.element);
- this.gifs.push(gif2);
- var gif3 = new _WizardGIFExample2.default('assets/wizard/3.gif');
- if (_config2.default.browserUtils.isMobile) {
- _gsap2.default.set(gif3.element, {
- rotation: -5,
- scale: 0.65,
- x: 40,
- y: 275
- });
- } else {
- _gsap2.default.set(gif3.element, {
- rotation: -5,
- scale: 0.65,
- x: 70,
- y: -25
- });
- }
- this.element.appendChild(gif3.element);
- this.gifs.push(gif3);
- var gif4 = new _WizardGIFExample2.default('assets/wizard/4.gif');
- if (_config2.default.browserUtils.isMobile) {
- _gsap2.default.set(gif4.element, {
- rotation: -5,
- scale: 0.65,
- x: 40,
- y: 275
- });
- } else {
- _gsap2.default.set(gif4.element, {
- rotation: -5,
- scale: 0.65,
- x: 70,
- y: -25
- });
- }
- this.element.appendChild(gif4.element);
- this.gifs.push(gif4);
- }
- _createClass(InputSection, [{
- key: 'showGif',
- value: function showGif(index) {
- this.gifs[index].show();
- }
- }, {
- key: 'hideGif',
- value: function hideGif(index) {
- this.gifs[index].hide();
- }
- }, {
- key: 'ready',
- value: function ready() {
- if (!_config2.default.browserUtils.isMobile) {
- this.createCamInput();
- this.selectCamInput();
- }
- }
- }, {
- key: 'highlight',
- value: function highlight() {
- this.arrow.show();
- _gsap2.default.from(this.arrow.element, 0.3, { opacity: 0 });
- }
- }, {
- key: 'dehighlight',
- value: function dehighlight() {
- _gsap2.default.killTweensOf(this.arrow.element);
- this.arrow.hide();
- }
- }, {
- key: 'enable',
- value: function enable(highlight) {
- this.element.classList.remove('section--disabled');
- if (highlight) {
- this.highlight();
- } else {
- this.dehighlight();
- }
- }
- }, {
- key: 'disable',
- value: function disable() {
- this.element.classList.add('section--disabled');
- this.dehighlight();
- }
- }, {
- key: 'dim',
- value: function dim() {
- this.element.classList.add('dimmed');
- }
- }, {
- key: 'undim',
- value: function undim() {
- this.element.classList.remove('dimmed');
- }
- }, {
- key: 'createCamInput',
- value: function createCamInput() {
- if (!this.camInput) {
- this.camInput = new _CamInput2.default();
- this.inputContainer.appendChild(this.camInput.element);
- _config2.default.camInput = this.camInput;
- // GLOBALS.camInput.start();
- }
- }
- }, {
- key: 'selectCamInput',
- value: function selectCamInput() {
- this.createCamInput();
- this.currentInput = this.camInput;
- }
- }, {
- key: 'resetClass',
- value: function resetClass(id) {
- this.camInput.resetClass(id);
- }
- }, {
- key: 'flipCamera',
- value: function flipCamera(event) {
- event.preventDefault();
- if (!_config2.default.browserUtils.isAndroid) {
- _config2.default.isBackFacingCam = !_config2.default.isBackFacingCam;
- _config2.default.webcamClassifier.loaded = false;
- _config2.default.webcamClassifier.ready();
- }
- if (_config2.default.browserUtils.isAndroid) {
- /*eslint-disable */
- if (confirm('Switching camera will clear your trained classes and reload the page.')) {
- /* eslint-enable */
- _config2.default.isBackFacingCam = !_config2.default.isBackFacingCam;
- localStorage.setItem('isBackFacingCam', _config2.default.isBackFacingCam.toString());
- location.reload();
- }
- }
- }
- }]);
- return InputSection;
- }();
- exports.default = InputSection;
- },{"./../../config.js":242,"./../components/Button.js":252,"./../components/CamInput.js":253,"./../components/HighlightArrow.js":255,"./WizardGIFExample.js":268,"gsap":212}],260:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _gsap = require('gsap');
- var _gsap2 = _interopRequireDefault(_gsap);
- var _config = require('./../../config.js');
- var _config2 = _interopRequireDefault(_config);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var IntroSection = function () {
- function IntroSection(element) {
- _classCallCheck(this, IntroSection);
- this.videoPlayButton = element.querySelector('#video-play-link');
- this.videoPlayButton.addEventListener('click', this.openVideoPlayer.bind(this));
- this.closeVideoLink = element.querySelector('#video-close-link');
- this.closeVideoLink.addEventListener('click', this.closeVideoPlayer.bind(this));
- this.videoContainer = element.querySelector('.intro__video');
- _gsap2.default.set(this.videoContainer, {
- transformOrigin: 'top center',
- opacity: 0
- });
- this.player = null;
- this.open = false;
- }
- _createClass(IntroSection, [{
- key: 'startVideo',
- value: function startVideo() {
- this.player.playVideo();
- }
- }, {
- key: 'openVideoPlayer',
- value: function openVideoPlayer() {
- if (this.open) {
- return;
- }
- if (_config2.default.YOUTUBE_API_READY) {
- if (this.player) {
- this.player.seekTo(0);
- } else {
- this.player = new window.YT.Player('intro-video-player', {
- height: '100%',
- width: '100%',
- videoId: 'a1Y73sPHKxw',
- playerVars: {
- autoplay: 0,
- fs: 1,
- loop: 0,
- controls: 1,
- modestbranding: 1,
- rel: 0,
- showinfo: 0
- }
- });
- }
- }
- var videoRatio = 1.7777777778;
- this.open = true;
- this.videoContainer.style.height = 'auto';
- var width = this.videoContainer.offsetWidth;
- var height = width / videoRatio;
- this.videoContainer.style.height = 0 + 'px';
- var that = this;
- _gsap2.default.to(this.videoPlayButton, 0.5, {
- opacity: 0,
- ease: _gsap2.default.Expo.easeOut
- });
- _gsap2.default.to(this.videoContainer, 1, {
- opacity: 1,
- height: height,
- transformOrigin: 'top center',
- ease: _gsap2.default.Expo.easeOut,
- onComplete: that.startVideo.bind(that)
- });
- }
- }, {
- key: 'closeVideoPlayer',
- value: function closeVideoPlayer() {
- this.open = false;
- if (this.player) {
- this.player.pauseVideo();
- }
- _gsap2.default.to(this.videoContainer, 0.75, {
- height: 0,
- opacity: 0,
- ease: _gsap2.default.Expo.easeOut
- });
- _gsap2.default.to(this.videoPlayButton, 0.5, {
- opacity: 1,
- delay: 0.5,
- ease: _gsap2.default.Expo.easeOut
- });
- }
- }]);
- return IntroSection;
- }();
- exports.default = IntroSection;
- },{"./../../config.js":242,"gsap":212}],261:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _config = require('./../../config.js');
- var _config2 = _interopRequireDefault(_config);
- var _gsap = require('gsap');
- var _gsap2 = _interopRequireDefault(_gsap);
- var _Button = require('./../components/Button.js');
- var _Button2 = _interopRequireDefault(_Button);
- var _HighlightArrow = require('./../components/HighlightArrow.js');
- var _HighlightArrow2 = _interopRequireDefault(_HighlightArrow);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var LearningClass = function () {
- function LearningClass(options) {
- _classCallCheck(this, LearningClass);
- this.element = options.element;
- this.section = options.section;
- this.canvas = this.element.querySelector('canvas.examples__viewer');
- this.canvas.width = 98;
- this.canvas.height = 98;
- this.context = this.canvas.getContext('2d');
- this.id = this.element.getAttribute('id');
- this.index = options.index;
- this.button = new _Button2.default(this.element.querySelector('a.button--record'));
- this.button.element.addEventListener('mousedown', this.buttonDown.bind(this));
- this.button.element.addEventListener('touchstart', this.buttonDown.bind(this));
- this.button.element.addEventListener('touchend', this.buttonUp.bind(this));
- this.bigLink = this.element.querySelector('.link--reset');
- this.resetLink = this.element.querySelector('.examples__close_reset');
- this.resetLink.id = this.id + "_link--reset";
- this.bigLink.id = this.id + "_link--big";
- // this.button.element.addEventListener('mouseup', this.buttonUp.bind(this));
- this.exampleCounterElement = this.element.querySelector('.examples__counter');
- this.exampleCounter = 0;
- this.percentage = 0;
- this.percentageElement = this.element.querySelector('.machine__value');
- this.percentageGrey = this.element.querySelector('.machine__percentage--grey');
- this.percentageWhite = this.element.querySelector('.machine__percentage--white');
- this.color = options.color;
- this.rgbaColor = options.rgbaColor;
- this.arrow = new _HighlightArrow2.default(3);
- this.arrow.element.style.left = 100 + '%';
- this.arrow.element.style.top = 100 + '%';
- this.arrow.element.width = 60;
- _gsap2.default.set(this.arrow.element, {
- rotation: 90,
- scale: 1,
- x: 10,
- y: -75
- });
- this.element.appendChild(this.arrow.element);
- this.arrowX = new _HighlightArrow2.default(2);
- this.arrowX.element.style.left = 0 + '%';
- this.arrowX.element.style.top = 0 + '%';
- this.arrowX.element.width = 60;
- _gsap2.default.set(this.arrowX.element, {
- rotation: -90,
- scaleX: -0.8,
- scaleY: 0.8,
- x: 37,
- y: -30
- });
- this.element.appendChild(this.arrowX.element);
- this.resetLink.addEventListener('click', this.resetClass.bind(this));
- this.bigLink.addEventListener('click', this.bigClass.bind(this));
- this.size();
- window.addEventListener('resize', this.size.bind(this));
- }
- _createClass(LearningClass, [{
- key: 'hide',
- value: function hide() {
- this.element.style.display = 'none';
- }
- }, {
- key: 'show',
- value: function show() {
- this.element.style.display = 'flex';
- }
- }, {
- key: 'highlight',
- value: function highlight() {
- this.arrow.show();
- _gsap2.default.from(this.arrow.element, 0.3, {
- opacity: 0,
- x: 40
- });
- }
- }, {
- key: 'dehighlight',
- value: function dehighlight() {
- _gsap2.default.killTweensOf(this.arrow.element);
- this.arrow.hide();
- }
- }, {
- key: 'highlightX',
- value: function highlightX() {
- this.arrowX.show();
- _gsap2.default.from(this.arrowX.element, 0.3, { opacity: 0 });
- }
- }, {
- key: 'dehighlightX',
- value: function dehighlightX() {
- _gsap2.default.killTweensOf(this.arrowX.element);
- this.arrowX.hide();
- }
- }, {
- key: 'clear',
- value: function clear() {
- this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
- this.setSamples(0);
- }
- }, {
- key: 'resetClass',
- value: function resetClass(event) {
- event.preventDefault();
- if (this.exampleCounter > 0) {
- _config2.default.webcamClassifier.imgSrc[this.index] = [];
- _config2.default.inputSection.resetClass(this.index);
- this.clear();
- }
- }
- }, {
- key: 'bigClass',
- value: function bigClass(event) {
- event.preventDefault();
- if (this.exampleCounter > 0) {
- // GLOBALS.inputSection.bigClass(this.index);
- // this.clear();
- var modal = document.createElement('div');
- modal.id = "modal";
- modal.classList.add('modal');
- document.getElementById('wrapper').appendChild(modal);
- var divImg = document.createElement('div');
- divImg.classList.add('modal_div');
- var img = "<span style='left:calc(50% - 500px)' class='leftSpan'><</span>";
- for (var i = 0; i < _config2.default.webcamClassifier.imgSrc[this.index].length; i++) {
- var src = _config2.default.webcamClassifier.imgSrc[this.index][i];
- img = img + ('<img src=' + src + ' />');
- }
- img = img + "<span style='right:calc(50% - 490px)' class='rightSpan'>></span>";
- divImg.innerHTML = img;
- modal.appendChild(divImg);
- modal.addEventListener('click', this.modalHide.bind(this));
- var number = 0;
- var modalScroll = document.getElementsByClassName('modal_div')[0];
- document.getElementsByClassName('leftSpan')[0].onclick = function () {
- number = number - 1000;
- if (number < 0) {
- modalScroll.scrollLeft = 0;
- number = 0;
- } else {
- modalScroll.scrollLeft = number;
- }
- };
- document.getElementsByClassName('rightSpan')[0].onclick = function () {
- number = number + 1000;
- if (number > modalScroll.scrollWidth) {
- modalScroll.scrollLeft = modalScroll.scrollWidth;
- number = modalScroll.scrollWidth;
- } else {
- modalScroll.scrollLeft = number;
- }
- };
- }
- }
- }, {
- key: 'modalHide',
- value: function modalHide(event) {
- console.log();
- if (event.target.tagName !== "IMG" && event.target.tagName !== "SPAN") {
- document.getElementById('wrapper').removeChild(document.getElementById('modal'));
- }
- }
- }, {
- key: 'setSamples',
- value: function setSamples(length) {
- this.exampleCounter = length;
- var text = this.exampleCounter;
- var recommendedNumSamples = _config2.default.inputType === 'cam' ? 30 : 10;
- this.exampleCounterElement.textContent = text;
- if (this.exampleCounter >= recommendedNumSamples && _config2.default.classesTrained[this.id] === false) {
- _config2.default.classesTrained[this.id] = true;
- }
- if (this.exampleCounter > 0) {
- this.resetLink.classList.remove("hide");
- // this.bigClass.classList.remove("hide")
- } else {
- this.resetLink.classList.add("hide");
- // this.bigClass.classList.add("hide")
- }
- }
- }, {
- key: 'setConfidence',
- value: function setConfidence(percentage) {
- if (!_config2.default.clearing) {
- // this.percentage = percentage;
- // this.updatePercentage();
- var that = this;
- _config2.default.recordSection.setMeters(this.id, percentage);
- _gsap2.default.to(this, 0.5, {
- percentage: percentage,
- onUpdate: function onUpdate() {
- that.updatePercentage();
- }
- });
- }
- }
- }, {
- key: 'highlightConfidence',
- value: function highlightConfidence() {
- this.percentageElement.style.background = this.color;
- }
- }, {
- key: 'dehighlightConfidence',
- value: function dehighlightConfidence() {
- this.percentageElement.style.background = '#cfd1d2';
- }
- }, {
- key: 'buttonDown',
- value: function buttonDown() {
- var _this = this;
- var that = this;
- var languare = _config2.default.lang === "en" ? _config2.default.languare.en : _config2.default.lang === "hans" ? _config2.default.languare.hans : _config2.default.languare.hant;
- var text = languare.training;
- this.button.setText(text);
- this.section.startRecording(this.index);
- this.buttonUpEvent = this.buttonUp.bind(this);
- window.addEventListener('mouseup', this.buttonUpEvent);
- _config2.default.recording = true;
- _config2.default.classId = this.id;
- _config2.default.outputSection.toggleSoundOutput(false);
- clearTimeout(this.buttonClickTimeout);
- this.buttonClickTimeout = setTimeout(function () {
- _config2.default.webcamClassifier.buttonDown(_this.id, _this.canvas, _this);
- }, 100);
- gtag('event', 'training', { 'id': this.index });
- }
- }, {
- key: 'buttonUp',
- value: function buttonUp() {
- var languare = _config2.default.lang === "en" ? _config2.default.languare.en : _config2.default.lang === "hans" ? _config2.default.languare.hans : _config2.default.languare.hant;
- var text = "";
- if (this.id == 'green') {
- text = languare.green;
- } else if (this.id == 'purple') {
- text = languare.purple;
- } else if (this.id == 'orange') {
- text = languare.orange;
- }
- this.button.setText(text);
- this.section.stopRecording();
- clearTimeout(this.buttonClickTimeout);
- this.button.up();
- _config2.default.classId = null;
- _config2.default.recording = false;
- _config2.default.outputSection.toggleSoundOutput(true);
- _config2.default.webcamClassifier.buttonUp(this.id, this.canvas);
- if (this.exampleCounter > 0) {
- var event = new CustomEvent('class-trained', {
- detail: {
- id: this.id,
- numSamples: this.exampleCounter
- }
- });
- window.dispatchEvent(event);
- }
- window.removeEventListener('mouseup', this.buttonUpEvent);
- }
- }, {
- key: 'updatePercentage',
- value: function updatePercentage() {
- var _this2 = this;
- var rounded = Math.floor(this.percentage);
- this.percentageElement.style.width = this.percentage + '%';
- this.percentageWhite.textContent = rounded + '%';
- if (this.timer) {
- clearInterval(this.timer);
- }
- this.timer = setInterval(function () {
- _this2.setConfidence(0);
- }, 500);
- }
- }, {
- key: 'size',
- value: function size() {
- this.percentageElement.style.width = 100 + '%';
- var width = this.percentageElement.offsetWidth;
- this.percentageWhite.style.width = width + 'px';
- this.percentageElement.style.width = 0 + '%';
- }
- }, {
- key: 'start',
- value: function start() {
- this.size();
- }
- }]);
- return LearningClass;
- }();
- exports.default = LearningClass;
- },{"./../../config.js":242,"./../components/Button.js":252,"./../components/HighlightArrow.js":255,"gsap":212}],262:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _config = require('./../../config.js');
- var _config2 = _interopRequireDefault(_config);
- var _gsap = require('gsap');
- var _gsap2 = _interopRequireDefault(_gsap);
- var _WiresLeft = require('./WiresLeft.js');
- var _WiresLeft2 = _interopRequireDefault(_WiresLeft);
- var _WiresRight = require('./WiresRight.js');
- var _WiresRight2 = _interopRequireDefault(_WiresRight);
- var _LearningClass = require('./LearningClass.js');
- var _LearningClass2 = _interopRequireDefault(_LearningClass);
- var _TrainingQuality = require('./TrainingQuality.js');
- var _TrainingQuality2 = _interopRequireDefault(_TrainingQuality);
- var _HighlightArrow = require('./../components/HighlightArrow.js');
- var _HighlightArrow2 = _interopRequireDefault(_HighlightArrow);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var LearningSection = function () {
- function LearningSection(element) {
- _classCallCheck(this, LearningSection);
- this.element = element;
- var learningClassesElements = element.querySelectorAll('.learning__class');
- this.condenseElement = element.querySelector('#learning-condensed-button');
- this.condenseElement.addEventListener('click', this.condenseSection.bind(this));
- var learningClasses = [];
- var that = this;
- this.condensed = false;
- that.learningClasses = [];
- var classNames = _config2.default.classNames;
- var colors = _config2.default.colors;
- learningClassesElements.forEach(function (element, index) {
- var id = classNames[index];
- var color = colors[id];
- var rgbaColor = _config2.default.rgbaColors[id];
- var options = {
- index: index,
- element: element,
- section: that,
- color: color,
- rgbaColor: rgbaColor
- };
- var learningClass = new _LearningClass2.default(options);
- learningClass.index = index;
- learningClasses.push(learningClass);
- that.learningClasses[index] = learningClass;
- // learningClass.start();
- });
- // this.trainingQuality = new TrainingQuality(element.querySelector('.quality'));
- this.wiresLeft = new _WiresLeft2.default(document.querySelector('.wires--left'), learningClassesElements);
- this.wiresRight = new _WiresRight2.default(document.querySelector('.wires--right'), learningClassesElements);
- this.highestIndex = null;
- this.currentIndex = null;
- this.arrow = new _HighlightArrow2.default(2);
- _gsap2.default.set(this.arrow.element, {
- rotation: 90,
- scale: 0.6,
- x: 120,
- y: -175
- });
- this.element.appendChild(this.arrow.element);
- }
- _createClass(LearningSection, [{
- key: 'condenseSection',
- value: function condenseSection() {
- this.condensed ? this.element.classList.remove('condensed') : this.element.classList.add('condensed');
- this.condensed ? this.condensed = false : this.condensed = true;
- }
- }, {
- key: 'ready',
- value: function ready() {
- this.learningClasses.forEach(function (learningClass) {
- learningClass.start();
- });
- }
- }, {
- key: 'highlight',
- value: function highlight() {
- this.arrow.show();
- _gsap2.default.from(this.arrow.element, 0.3, { opacity: 0 });
- }
- }, {
- key: 'dehighlight',
- value: function dehighlight() {
- _gsap2.default.killTweensOf(this.arrow.element, 0.3, { opacity: 0 });
- this.arrow.hide();
- }
- }, {
- key: 'enable',
- value: function enable(highlight) {
- this.element.classList.remove('section--disabled');
- this.wiresLeft.element.classList.remove('wires--disabled');
- this.wiresRight.element.classList.remove('wires--disabled');
- if (highlight) {
- this.highlight();
- }
- }
- }, {
- key: 'disable',
- value: function disable() {
- this.element.classList.add('section--disabled');
- this.wiresLeft.element.classList.add('wires--disabled');
- this.wiresRight.element.classList.add('wires--disabled');
- }
- }, {
- key: 'dim',
- value: function dim() {
- this.element.classList.add('dimmed');
- this.wiresLeft.element.classList.add('dimmed');
- this.wiresRight.element.classList.add('dimmed');
- }
- }, {
- key: 'undim',
- value: function undim() {
- this.element.classList.remove('dimmed');
- this.wiresLeft.element.classList.remove('dimmed');
- this.wiresRight.element.classList.remove('dimmed');
- }
- }, {
- key: 'highlightClass',
- value: function highlightClass(index) {
- this.learningClasses[index].highlight();
- }
- }, {
- key: 'dehighlightClass',
- value: function dehighlightClass(index) {
- this.learningClasses[index].dehighlight();
- }
- }, {
- key: 'highlightClassX',
- value: function highlightClassX(index) {
- this.learningClasses[index].highlightX();
- }
- }, {
- key: 'dehighlightClassX',
- value: function dehighlightClassX(index) {
- this.learningClasses[index].dehighlightX();
- }
- }, {
- key: 'enableClass',
- value: function enableClass(index, highlight) {
- this.learningClasses[index].element.classList.remove('learning__class--disabled');
- if (highlight) {
- this.highlightClass(index);
- }
- }
- }, {
- key: 'disableClass',
- value: function disableClass(index) {
- this.learningClasses[index].element.classList.add('learning__class--disabled');
- }
- }, {
- key: 'clearExamples',
- value: function clearExamples() {
- this.learningClasses.forEach(function (learningClass) {
- learningClass.clear();
- learningClass.setConfidence(0);
- learningClass.dehighlightConfidence();
- });
- }
- }, {
- key: 'startRecording',
- value: function startRecording(id) {
- this.wiresLeft.highlight(id);
- }
- }, {
- key: 'stopRecording',
- value: function stopRecording() {
- this.wiresLeft.dehighlight();
- }
- }, {
- key: 'ledOn',
- value: function ledOn(id) {
- this.wiresRight.dehighlight();
- this.wiresRight.highlight(id);
- }
- }, {
- key: 'getMaxIndex',
- value: function getMaxIndex(array) {
- var max = array[0];
- var maxIndex = 0;
- for (var index = 1; index < array.length; index += 1) {
- if (array[index] > max) {
- maxIndex = index;
- max = array[index];
- }
- }
- return maxIndex;
- }
- }, {
- key: 'setConfidences',
- value: function setConfidences(confidences) {
- var confidencesArry = Object.values(confidences);
- var maxIndex = this.getMaxIndex(confidencesArry);
- var maxValue = confidencesArry[maxIndex];
- // if (maxValue > 0.5 && this.currentIndex !== maxIndex) {
- if (maxValue > 0.5) {
- this.currentIndex = maxIndex;
- var id = _config2.default.classNames[this.currentIndex];
- this.ledOn(id);
- _config2.default.outputSection.trigger(id);
- }
- for (var index = 0; index < 3; index += 1) {
- this.learningClasses[index].setConfidence(confidencesArry[index] * 100);
- if (index === maxIndex) {
- this.learningClasses[index].highlightConfidence();
- } else {
- this.learningClasses[index].dehighlightConfidence();
- }
- }
- }
- }, {
- key: 'setQuality',
- value: function setQuality(quality) {
- // this.trainingQuality.setQuality(quality);
- }
- }]);
- return LearningSection;
- }();
- exports.default = LearningSection;
- },{"./../../config.js":242,"./../components/HighlightArrow.js":255,"./LearningClass.js":261,"./TrainingQuality.js":265,"./WiresLeft.js":266,"./WiresRight.js":267,"gsap":212}],263:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _gsap = require('gsap');
- var _gsap2 = _interopRequireDefault(_gsap);
- var _config = require('./../../config.js');
- var _config2 = _interopRequireDefault(_config);
- var _Selector = require('./../components/Selector.js');
- var _Selector2 = _interopRequireDefault(_Selector);
- var _Button = require('./../components/Button.js');
- var _Button2 = _interopRequireDefault(_Button);
- var _CamInput = require('./../components/CamInput.js');
- var _CamInput2 = _interopRequireDefault(_CamInput);
- var _HighlightArrow = require('./../components/HighlightArrow.js');
- var _HighlightArrow2 = _interopRequireDefault(_HighlightArrow);
- var _SpeechOutput = require('./../../outputs/SpeechOutput.js');
- var _SpeechOutput2 = _interopRequireDefault(_SpeechOutput);
- var _GIFOutput = require('./../../outputs/GIFOutput.js');
- var _GIFOutput2 = _interopRequireDefault(_GIFOutput);
- var _CloudOutput = require('./../../outputs/CloudOutput.js');
- var _CloudOutput2 = _interopRequireDefault(_CloudOutput);
- var _SoundOutput = require('./../../outputs/SoundOutput.js');
- var _SoundOutput2 = _interopRequireDefault(_SoundOutput);
- var _ModuleOutput = require('./../../outputs/ModuleOutput.js');
- var _ModuleOutput2 = _interopRequireDefault(_ModuleOutput);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var OutputSection = function () {
- function OutputSection(element) {
- var _this = this;
- _classCallCheck(this, OutputSection);
- this.element = element;
- var outputs = {
- CloudOutput: new _CloudOutput2.default(),
- // GIFOutput: new GIFOutput(),
- SoundOutput: new _SoundOutput2.default(document.querySelector('#SoundOutput')),
- SpeechOutput: new _SpeechOutput2.default(),
- ModuleOutput: new _ModuleOutput2.default()
- };
- _config2.default.soundOutput = outputs.SoundOutput;
- this.ModuleOutput = new _ModuleOutput2.default();
- this.classNames = _config2.default.classNames;
- _config2.default.predicting = true;
- this.outputs = outputs;
- this.loadedOutputs = [];
- var outputLinks = element.querySelectorAll('.output_selector__option');
- outputLinks.forEach(function (link) {
- link.addEventListener('click', _this.changeOutput.bind(_this));
- });
- this.currentLink = element.querySelector('.output_selector__option--selected');
- this.outputContainer = document.querySelector('#output-player');
- this.currentOutput = null;
- this.currentLink.click();
- this.arrow = new _HighlightArrow2.default(1);
- _gsap2.default.set(this.arrow.element, {
- rotation: -50,
- scale: -0.8,
- x: 140,
- y: -100
- });
- this.element.appendChild(this.arrow.element);
- }
- _createClass(OutputSection, [{
- key: 'enable',
- value: function enable() {
- this.element.classList.remove('section--disabled');
- }
- }, {
- key: 'highlight',
- value: function highlight() {
- this.arrow.show();
- _gsap2.default.from(this.arrow.element, 0.3, { opacity: 0 });
- }
- }, {
- key: 'dehighlight',
- value: function dehighlight() {
- _gsap2.default.killTweensOf(this.arrow.element);
- this.arrow.hide();
- }
- }, {
- key: 'disable',
- value: function disable() {
- this.element.classList.add('section--disabled');
- }
- }, {
- key: 'dim',
- value: function dim() {
- this.element.classList.add('dimmed');
- }
- }, {
- key: 'undim',
- value: function undim() {
- this.element.classList.remove('dimmed');
- }
- }, {
- key: 'changeOutput',
- value: function changeOutput(event) {
- if (this.currentLink) {
- this.currentLink.classList.remove('output_selector__option--selected');
- }
- this.currentLink = event.target;
- this.currentLink.classList.add('output_selector__option--selected');
- var outputId = this.currentLink.id;
- if (this.currentOutput) {
- this.currentOutput.stop();
- this.currentOutput = null;
- }
- if (this.outputs[outputId]) {
- this.currentOutput = this.outputs[outputId];
- }
- if (outputId === "ModuleOutput") {
- var lang = _config2.default.lang;
- var port = lang == 'en' ? 'Port' : lang == 'zh-hant' ? "端口" : "端口";
- var connects = lang == 'en' ? 'Connect' : lang == 'zh-hant' ? "連接" : "连接";
- var disconnects = lang == 'en' ? 'Disconnect' : lang == 'zh-hant' ? "斷開" : "断开";
- if (document.getElementById('port_connect')) {
- document.getElementById('port_connect').innerHTML = '<span id="portNumber">' + port + ':</span><span>' + (_config2.default.port ? _config2.default.port : "") + '</span><button class="send_button ' + (_config2.default.port && 'send_button_color') + '" style="display:block">' + connects + '</button><button class="send_button ' + (_config2.default.port && 'send_button_color') + '" style="display:none">' + disconnects + '</button>';
- }
- }
- if (this.currentOutput) {
- this.outputContainer.appendChild(this.currentOutput.element);
- this.currentOutput.start();
- }
- gtag('event', 'select_output', { 'id': outputId });
- }
- }, {
- key: 'toggleSoundOutput',
- value: function toggleSoundOutput(play) {
- if (this.currentOutput.id === 'SoundOutput' && play) {
- _config2.default.soundOutput.playCurrentSound();
- } else if (this.currentOutput.id === 'SoundOutput' && !play) {
- _config2.default.soundOutput.pauseCurrentSound();
- }
- }
- }, {
- key: 'startWizardMode',
- value: function startWizardMode() {
- this.broadcastEvents = true;
- }
- }, {
- key: 'stopWizardMode',
- value: function stopWizardMode() {
- this.broadcastEvents = false;
- }
- }, {
- key: 'trigger',
- value: function trigger(id) {
- var index = this.classNames.indexOf(id);
- this.currentOutput.trigger(index);
- if (this.broadcastEvents) {
- var event = new CustomEvent('class-triggered', { detail: { id: id } });
- window.dispatchEvent(event);
- }
- }
- }, {
- key: 'clear',
- value: function clear() {
- this.currentOutput.clear();
- }
- }]);
- return OutputSection;
- }();
- exports.default = OutputSection;
- },{"./../../config.js":242,"./../../outputs/CloudOutput.js":244,"./../../outputs/GIFOutput.js":245,"./../../outputs/ModuleOutput.js":246,"./../../outputs/SoundOutput.js":247,"./../../outputs/SpeechOutput.js":248,"./../components/Button.js":252,"./../components/CamInput.js":253,"./../components/HighlightArrow.js":255,"./../components/Selector.js":256,"gsap":212}],264:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _Button = require('./../components/Button.js');
- var _Button2 = _interopRequireDefault(_Button);
- var _config = require('./../../config.js');
- var _config2 = _interopRequireDefault(_config);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var Recording = function () {
- function Recording(element) {
- _classCallCheck(this, Recording);
- this.element = element;
- this.canvas = element.querySelector('#recording__canvas');
- this.startButtonText = element.querySelector('#recording__start-text');
- this.downloadPreText = element.querySelector('#pre-download-message');
- this.downloadLinkSection = element.querySelector('.recording-download-container');
- this.downloadLinkButton = element.querySelector('#recording__download');
- this.recordingVideo = element.querySelector('#recording__video');
- this.recordTimer = element.querySelector('#record__timer');
- this.closeButton = element.querySelector('#close__button');
- this.restart = element.querySelector('#restart');
- this.recordMessage = element.querySelector('#message');
- this.recordMessageAlt = element.querySelector('#message-alt');
- this.downloadLinkSection.style.display = 'none';
- this.sharingNotice = element.querySelector('#sharing-notice');
- this.sendSuccess = false;
- this.legal = document.querySelector('#recording__legal');
- this.checkbox = document.querySelector('#recording__checkbox');
- this.recordMessageAlt.style.display = 'none';
- this.recordingVideo.style.display = 'none';
- this.recordingVideo.setAttribute('src', '');
- this.canvas.width = 680;
- this.canvas.height = 340;
- this.video = document.getElementsByTagName('video')[0];
- this.confidence1 = 0;
- this.confidence2 = 0;
- this.confidence3 = 0;
- this.recordedTime = 10;
- this.count = 3;
- this.showing = false;
- this.closeButton.addEventListener('click', this.hide.bind(this));
- this.restart.addEventListener('click', this.reset.bind(this));
- this.recordingState = 'waiting';
- this.RECORD_TIME = 10000;
- this.startButton = new _Button2.default(document.querySelector('#recording__start-button'));
- this.startRecordEvent = this.onRecordButtonClick.bind(this);
- this.checkbox.addEventListener('click', this.toggleCheckbox.bind(this));
- }
- _createClass(Recording, [{
- key: 'toggleCheckbox',
- value: function toggleCheckbox() {
- if (this.checkbox.checked) {
- this.startButton.element.addEventListener('click', this.startRecordEvent);
- this.startButton.element.classList.remove('recording-start__button--disabled');
- } else {
- this.startButton.element.removeEventListener('click', this.startRecordEvent);
- this.startButton.element.classList.add('recording-start__button--disabled');
- }
- }
- }, {
- key: 'setCanvas',
- value: function setCanvas(element) {
- var _this = this;
- this.show();
- if (element.name === 'gif') {
- this.canvasType = 'gif';
- } else {
- this.canvasType = '';
- }
- document.querySelector('#recording__start-button .button__label #icon--record').style.display = 'inline-block';
- document.querySelector('#recording__start-button .button__label #icon--stop').style.display = 'none';
- this.sourceCanvas = element;
- this.context = this.canvas.getContext('2d');
- this.showing = true;
- this.render();
- var img = new Image();
- var stamp = new Image();
- img.onload = function () {
- _this.wiresImage = img;
- };
- stamp.onload = function () {
- _this.stampImage = stamp;
- };
- img.src = 'assets/wires-recorder.png';
- stamp.src = 'assets/madeby.svg';
- }
- }, {
- key: 'render',
- value: function render() {
- if (!this.showing) {
- return;
- }
- this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
- this.context.fillStyle = '#e4e5e6';
- this.context.fillRect(0, 0, 680, 340);
- // call its drawImage() function passing it the source canvas directly
- var maxHeight = 200;
- var videoWidth = 266;
- var padding = 20;
- var startX = 26;
- var startY = 16;
- // White boxes
- this.context.fillStyle = '#fff';
- this.context.fillRect(startX, startY, videoWidth + padding, maxHeight + 70);
- this.context.fillRect(340 + startX, startY, videoWidth + padding, maxHeight + 70);
- // The "Output" Canvas
- if (this.canvasType === 'gif') {
- var _videoWidth = 260;
- this.context.drawImage(this.sourceCanvas, startX + 343 + padding / 2, 45, _videoWidth, _videoWidth - 50);
- } else {
- this.context.drawImage(this.sourceCanvas, startX + 355 + padding / 2, 40, videoWidth, videoWidth - 50);
- }
- if (this.wiresImage) {
- this.context.drawImage(this.wiresImage, startX + 276 + padding / 2, 45, 54, videoWidth - 50);
- }
- if (this.stampImage) {
- this.context.drawImage(this.stampImage, this.canvas.width / 2 - videoWidth * 1.2 / 2, 302, videoWidth * 1.2, 20);
- }
- // Bars to cover it:
- // this.context.fillStyle = '#e4e5e6';
- // this.context.fillRect(startX + 340, 0, videoWidth + padding, startY);
- // this.context.fillStyle = '#fff';
- // this.context.fillRect(startX + 340, startY, videoWidth + padding, padding / 2);
- // this.context.fillRect(startX + 340, maxHeight + startY + padding / 2, videoWidth + padding, 30);
- var barsY = maxHeight + startY + padding;
- var boxSize = (videoWidth - padding) / 3;
- var boxStartX = startX + padding / 2;
- this.context.fillStyle = '#e4e5e6';
- this.context.fillRect(boxStartX, barsY, boxSize, 40);
- this.context.fillStyle = '#2baa5e';
- this.context.fillRect(boxStartX, barsY, boxSize * this.confidence1, 40);
- this.context.fillStyle = '#e4e5e6';
- this.context.fillRect(boxStartX + boxSize + padding / 2, barsY, boxSize, 40);
- this.context.fillStyle = '#c95ac5';
- this.context.fillRect(boxStartX + boxSize + padding / 2, barsY, boxSize * this.confidence2, 40);
- this.context.fillStyle = '#e4e5e6';
- this.context.fillRect(boxStartX + boxSize + boxSize + padding, barsY, boxSize, 40);
- this.context.fillStyle = '#dd4d31';
- this.context.fillRect(boxStartX + boxSize + boxSize + padding, barsY, boxSize * this.confidence3, 40);
- // Video comes in mirrored, so let's flip it:
- this.context.save();
- this.context.scale(-1, 1);
- this.context.drawImage(this.video, -(startX + padding / 2), startY + padding / 2, maxHeight * (360 / 270) * -1, maxHeight);
- this.context.restore();
- //
- // this.context.font = '18px Poppins';
- // this.context.fillStyle = '#000';
- // this.context.fillText('MADE AT: ', startX, 320);
- // this.context.fillStyle = '#3e80f6';
- // this.context.fillText('G.CO/TEACHABLEMACHINE', 110, 320);
- requestAnimationFrame(this.render.bind(this));
- }
- }, {
- key: 'setMeters',
- value: function setMeters(colorId, confidence) {
- if (!this.showing) {
- return;
- }
- var confidencePercentage = confidence / 100;
- switch (colorId) {
- case 'green':
- this.confidence1 = confidencePercentage;
- break;
- case 'purple':
- this.confidence2 = confidencePercentage;
- break;
- case 'orange':
- this.confidence3 = confidencePercentage;
- break;
- default:
- break;
- }
- }
- }, {
- key: 'stopRecording',
- value: function stopRecording() {
- // this.recordingState = 'Facebook';
- if (this.mediaRecorder.state !== 'inactive') {
- this.mediaRecorder.stop();
- }
- clearTimeout(this.recordingTimeout);
- _config2.default.webcamClassifier.stopTimer();
- }
- }, {
- key: 'onRecordButtonClick',
- value: function onRecordButtonClick() {
- switch (this.recordingState) {
- case 'waiting':
- this.countdown();
- break;
- case 'countdown':
- this.stopCountdown();
- break;
- case 'recording':
- if (this.mediaRecorder) {
- if (this.mediaRecorder.state !== 'inactive') {
- this.mediaRecorder.stop();
- this.stopRecording();
- }
- this.recordingState = 'waiting';
- this.recordTimer.style.display = 'none';
- this.startButton.element.classList.remove('animate');
- }
- break;
- case 'shareSuccess':
- this.shareOnFb();
- break;
- case 'successMessage':
- this.recordingState = 'waiting';
- break;
- default:
- break;
- }
- }
- }, {
- key: 'onShareButtonClick',
- value: function onShareButtonClick() {
- this.recordingState = 'waiting';
- this.shareOnFb();
- this.downloadLinkSection.style.marginLeft = 0;
- }
- }, {
- key: 'reset',
- value: function reset() {
- _config2.default.webcamClassifier.startTimer();
- this.recordingState = 'waiting';
- this.recordTimer.style.display = 'block';
- this.startButton.element.style.top = 0;
- this.downloadLinkSection.style.marginLeft = '15px';
- this.recordMessage.style.display = 'block';
- this.recordMessageAlt.style.display = 'none';
- this.startButton.element.style.display = 'inline-block';
- this.legal.style.display = 'block';
- this.downloadLinkSection.style.display = 'none';
- document.querySelector('#recording__start-button .button__label #icon--stop').style.display = 'none';
- document.querySelector('#recording__start-button .button__label #icon--record').style.display = 'inline-block';
- document.querySelector('#recording__start-button .button__label #recording__start-text').innerText = 'Start Recording';
- this.canvas.style.display = 'block';
- this.sharingNotice.style.display = 'none';
- this.recordingVideo.style.display = 'none';
- this.recordingVideo.setAttribute('src', '');
- this.stopRecordingTime();
- this.stopCountdown();
- this.downloadPreText.innerText = '';
- }
- }, {
- key: 'countdown',
- value: function countdown() {
- var _this2 = this;
- this.recordingState = 'countdown';
- this.canvas.style.display = 'block';
- this.recordingVideo.style.display = 'none';
- this.downloadLinkSection.style.display = 'none';
- document.querySelector('#recording__start-button .button__label #icon--record').style.display = 'none';
- document.querySelector('#recording__start-button .button__label #recording__start-text').innerText = this.count;
- this.countdownTimeout = setTimeout(function () {
- _this2.count = _this2.count - 1;
- if (_this2.count > 0) {
- document.querySelector('#recording__start-button .button__label #recording__start-text').innerText = _this2.count;
- _this2.countdown();
- } else {
- _this2.startRecording();
- _this2.recordingTime();
- _this2.count = 3;
- }
- }, 1000);
- }
- }, {
- key: 'recordingTime',
- value: function recordingTime() {
- var _this3 = this;
- this.recordingTimeTimeout = setTimeout(function () {
- _this3.recordedTime = _this3.recordedTime - 1;
- if (_this3.recordedTime > 0) {
- _this3.recordTimer.innerText = '0:0' + _this3.recordedTime;
- _this3.recordingTime();
- } else {
- _this3.recordTimer.innerText = '0:00';
- _this3.recordedTime = 10;
- }
- }, 1000);
- }
- }, {
- key: 'stopRecordingTime',
- value: function stopRecordingTime() {
- this.recordingState = 'waiting';
- if (this.recordingTimeTimeout) {
- clearTimeout(this.recordingTimeTimeout);
- }
- this.recordedTime = 10;
- this.recordTimer.innerText = '0:10';
- }
- }, {
- key: 'stopCountdown',
- value: function stopCountdown() {
- this.recordingState = 'waiting';
- clearTimeout(this.countdownTimeout);
- this.count = 3;
- this.startButton.element.classList.remove('animate');
- document.querySelector('#recording__start-button .button__label #recording__start-text').innerText = 'Start Recording';
- }
- }, {
- key: 'startRecording',
- value: function startRecording() {
- var _this4 = this;
- console.log("start recording");
- this.recordingState = 'recording';
- document.querySelector('#recording__start-button .button__label #icon--stop').style.display = 'inline-block';
- document.querySelector('#recording__start-button .button__label #recording__start-text').innerText = 'Stop Recording';
- var recordedChunks = [];
- this.startButton.element.classList.add('animate');
- var finalStream = new MediaStream();
- var canvasStream = this.canvas.captureStream().getVideoTracks()[0];
- finalStream.addTrack(canvasStream);
- finalStream.addTrack(_config2.default.stream.getAudioTracks()[0]);
- this.mediaRecorder = new MediaRecorder(finalStream);
- this.mediaRecorder.ondataavailable = function (event) {
- if (event.data.size > 0) {
- recordedChunks.push(event.data);
- }
- };
- this.mediaRecorder.start();
- this.mediaRecorder.onstop = function () {
- _this4.blob = new Blob(recordedChunks, { type: 'video/webm' });
- var url = URL.createObjectURL(_this4.blob);
- _this4.canvas.style.display = 'none';
- _this4.recordingVideo.style.display = 'block';
- _this4.recordMessage.style.display = 'none';
- _this4.recordMessageAlt.style.display = 'block';
- _this4.recordTimer.style.display = 'none';
- _this4.startButton.element.style.top = '50px';
- document.querySelector('#recording__start-button .button__label #icon--stop').style.display = 'none';
- document.querySelector('#recording__start-button .button__label #recording__start-text').innerText = '';
- _this4.downloadLinkSection.style.display = 'inline-block';
- _this4.downloadLinkButton.href = url;
- _this4.downloadLinkButton.download = 'teachable-machine.webm';
- _this4.startButton.element.style.display = 'none';
- _this4.legal.style.display = 'none';
- _this4.recordingVideo.setAttribute('src', url);
- // this.sharingNotice.style.display = 'block';
- };
- this.recordingTimeout = setTimeout(function () {
- _this4.startButton.element.classList.remove('animate');
- _this4.stopRecording();
- }, this.RECORD_TIME);
- gtag('event', 'recording_start');
- }
- }, {
- key: 'show',
- value: function show() {
- var _this5 = this;
- this.recordingState = 'waiting';
- this.showing = true;
- this.element.style.opacity = 1;
- this.element.style.pointerEvents = 'initial';
- setTimeout(function () {
- _this5.element.classList.add('fadein');
- }, 1);
- }
- }, {
- key: 'hide',
- value: function hide() {
- var _this6 = this;
- this.element.classList.remove('fadein');
- _config2.default.webcamClassifier.startTimer();
- setTimeout(function () {
- _this6.element.style.opacity = 0;
- _this6.element.style.pointerEvents = 'none';
- _config2.default.isRecording = false;
- if (_this6.video) {
- _this6.recordingVideo.setAttribute('src', '');
- }
- _this6.reset();
- }, 300);
- clearTimeout(this.recordingTimeTimeout);
- clearTimeout(this.countdownTimeout);
- this.showing = false;
- }
- }, {
- key: 'shareOnFb',
- value: function shareOnFb() {
- var _this7 = this;
- this.downloadPreText.innerText = 'Posting... ';
- window.fbWindowCallback = function (data) {
- var formData = new FormData();
- formData.append('code', data);
- var fileOfBlob = new File([_this7.blob], 'share.webm');
- formData.append('video', fileOfBlob);
- var xhr = new XMLHttpRequest();
- xhr.open('POST', '/share-video');
- xhr.onload = function () {
- if (xhr.status === 200) {
- _this7.downloadPreText.innerText = 'Posted to Facebook. ';
- // console.log('Something went wrong. Name is now ' + xhr.responseText);
- } else if (xhr.status !== 200) {
- _this7.downloadPreText.innerText = 'Sorry, something went wrong. ';
- // console.log('Request failed. Returned status of ' + xhr.status);
- }
- };
- xhr.send(formData);
- };
- var popup = window.open('/fb', 'Share on Facebook', 'width=600, height=600');
- popup.focus();
- gtag('event', 'recording_share');
- }
- }]);
- return Recording;
- }();
- exports.default = Recording;
- },{"./../../config.js":242,"./../components/Button.js":252}],265:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _gsap = require('gsap');
- var _gsap2 = _interopRequireDefault(_gsap);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var TrainingQuality = function () {
- function TrainingQuality(element) {
- _classCallCheck(this, TrainingQuality);
- this.element = element;
- this.percentage = 0;
- this.percentageElement = element.querySelector('.machine__value');
- this.percentageGrey = element.querySelector('.machine__percentage--grey');
- this.percentageWhite = element.querySelector('.machine__percentage--white');
- this.label = element.querySelector('.quality__status');
- this.percentageWhite.style.width = this.percentageGrey.offsetWidth + 'px';
- this.updatePercentage();
- }
- _createClass(TrainingQuality, [{
- key: 'updatePercentage',
- value: function updatePercentage() {
- var rounded = Math.floor(this.percentage);
- this.percentageElement.style.width = this.percentage + '%';
- this.percentageGrey.textContent = rounded + '%';
- this.percentageWhite.textContent = rounded + '%';
- }
- }, {
- key: 'setQuality',
- value: function setQuality(quality) {
- // this.percentage = quality * 100;
- // this.updatePercentage();
- var that = this;
- var percentage = quality * 100;
- _gsap2.default.to(that, 0.5, {
- percentage: percentage,
- onUpdate: function onUpdate() {
- // console.log(that.percentage);
- that.updatePercentage();
- }
- });
- if (percentage < 65) {
- this.label.textContent = 'Your machine probably won’t work well';
- } else if (percentage > 90) {
- this.label.textContent = 'Perfect!';
- } else {
- this.label.textContent = 'Looking good';
- }
- }
- }, {
- key: 'start',
- value: function start() {
- // let that = this;
- // TweenMax.to(that, (Math.random() * 4) + 0.5, {
- // percentage: Math.floor(Math.random() * 100),
- // onUpdate: function() {
- // that.updatePercentage();
- // },
- // repeat: -1,
- // yoyo: true
- // });
- }
- }]);
- return TrainingQuality;
- }();
- exports.default = TrainingQuality;
- },{"gsap":212}],266:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var _config = require('./../../config.js');
- var _config2 = _interopRequireDefault(_config);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- var WiresLeft = function () {
- function WiresLeft(element, learningClasses) {
- var _this = this;
- _classCallCheck(this, WiresLeft);
- this.element = element;
- this.learningClasses = learningClasses;
- this.offsetY = 0;
- this.canvas = document.createElement('canvas');
- this.size();
- this.element.appendChild(this.canvas);
- this.wireGeneral = this.element.querySelector('.st0');
- this.wireGreen = this.element.querySelector('.wire-green');
- this.wirePurple = this.element.querySelector('.wire-purple');
- this.wireOrange = this.element.querySelector('.wire-orange');
- this.context = this.canvas.getContext('2d');
- this.vertical = true;
- window.addEventListener('resize', function () {
- if (window.innerWidth <= 900) {
- _this.canvas.style.display = 'none';
- } else {
- _this.canvas.style.display = 'block';
- }
- });
- this.currentAnimator = null;
- this.renderOnce = true;
- this.render();
- }
- _createClass(WiresLeft, [{
- key: 'render',
- value: function render(once) {
- this.context.clearRect(0, 0, this.width, this.height);
- this.context.lineWidth = 3;
- for (var index = 0; index < 3; index += 1) {
- var startY = this.startY + this.startSpace * index;
- var endY = this.endY + this.endSpace * index;
- var start = {
- x: 0,
- y: this.startY + this.startSpace * index
- };
- var end = {
- x: this.endX,
- y: this.endY + this.endSpace * index
- };
- var cp1 = {
- x: 35,
- y: start.y
- };
- var cp2 = {
- x: 10,
- y: end.y
- };
- this.context.strokeStyle = '#cfd1d2';
- if (this.animator[index].highlight) {
- this.context.strokeStyle = this.animator[index].color;
- }
- this.context.beginPath();
- this.context.moveTo(start.x, start.y);
- this.context.bezierCurveTo(cp1.x, cp1.y, cp2.x, cp2.y, end.x, end.y);
- this.context.lineTo(start.x + 100, start.y);
- this.context.stroke();
- }
- if (this.renderOnce) {
- this.renderOnce = false;
- } else {
- this.timer = requestAnimationFrame(this.render.bind(this));
- }
- }
- }, {
- key: 'camMode',
- value: function camMode() {
- if (this.vert) {
- this.element.style.left = 50 + '%';
- }
- this.offsetY = -2;
- this.startY = this.height / 2 + this.offsetY;
- this.renderOnce = true;
- this.render();
- }
- }, {
- key: 'highlight',
- value: function highlight(index) {
- this.currentAnimator = this.animator[index];
- this.currentAnimator.highlight = true;
- this.start();
- switch (index) {
- case 0:
- this.wireGreen.classList.add('animate');
- break;
- case 1:
- this.wireOrange.classList.add('animate');
- break;
- case 2:
- this.wirePurple.classList.add('animate');
- break;
- default:
- }
- }
- }, {
- key: 'dehighlight',
- value: function dehighlight(index) {
- if (this.currentAnimator) {
- this.currentAnimator.highlight = false;
- this.currentAnimator = null;
- this.stop();
- this.renderOnce = true;
- this.render();
- }
- this.wireGreen.classList.remove('animate');
- this.wirePurple.classList.remove('animate');
- this.wireOrange.classList.remove('animate');
- }
- }, {
- key: 'start',
- value: function start() {
- this.stop();
- this.timer = requestAnimationFrame(this.render.bind(this));
- }
- }, {
- key: 'stop',
- value: function stop() {
- if (this.timer) {
- cancelAnimationFrame(this.timer);
- }
- }
- }, {
- key: 'size',
- value: function size() {
- var BREAKPOINT_DESKTOP = 900;
- if (window.innerWidth <= BREAKPOINT_DESKTOP) {
- this.canvas.style.display = 'none';
- }
- this.width = this.element.offsetWidth;
- var firstLearningClass = this.learningClasses[0];
- var lastLearningClass = this.learningClasses[2];
- var classesHeight = lastLearningClass.offsetTop - firstLearningClass.offsetTop;
- this.height = 440;
- // remove offset on desktop
- this.element.setAttribute('style', '');
- this.endSpace = classesHeight / 2;
- this.canvas.width = this.width;
- this.canvas.height = this.height;
- this.startSpace = 3;
- this.startX = 0;
- // this.startY = (this.height / 2);
- this.startY = this.height / 2 + this.offsetY;
- this.endX = this.width;
- this.endY = 80;
- this.animator = {};
- for (var index = 0; index < 3; index += 1) {
- var id = _config2.default.classNames[index];
- this.animator[index] = {
- highlight: false,
- percentage: 0,
- color: _config2.default.colors[id],
- numParticles: 15
- };
- }
- this.renderOnce = true;
- }
- }]);
- return WiresLeft;
- }();
- exports.default = WiresLeft;
- },{"./../../config.js":242}],267:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _config = require('./../../config.js');
- var _config2 = _interopRequireDefault(_config);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var WiresRight = function () {
- function WiresRight(element) {
- var _this = this;
- _classCallCheck(this, WiresRight);
- this.element = element;
- this.canvas = document.createElement('canvas');
- this.bulbVert = true;
- this.bulbSmall = false;
- this.bulbGreen = this.element.querySelector('.wire--right-bulb-green-glow');
- this.bulbPurple = this.element.querySelector('.wire--right-bulb-purple-glow');
- this.bulbOrange = this.element.querySelector('.wire--right-bulb-orange-glow');
- this.element.appendChild(this.canvas);
- this.context = this.canvas.getContext('2d');
- this.offsetY = 0;
- this.animator = {};
- for (var index = 0; index < 3; index += 1) {
- var bulbElement = document.createElement('div');
- bulbElement.classList.add('wires__bulb');
- bulbElement.classList.add('wires__bulb-' + _config2.default.classNames[index]);
- this.size();
- this.element.appendChild(bulbElement);
- this.animator[index] = {
- highlight: false,
- bulb: bulbElement
- };
- }
- window.addEventListener('resize', function () {
- if (window.innerWidth <= 900) {
- _this.canvas.style.display = 'none';
- } else {
- _this.canvas.style.display = 'block';
- }
- });
- window.addEventListener('orientationchange', function () {
- _this.size();
- });
- this.altOffset = 340;
- this.size();
- this.loops = 10;
- this.current = 0;
- this.running = false;
- this.renderOnce = true;
- this.bulbVert ? this.render() : this.renderAlt();
- if (this.bulbVert) {
- this.offsetY = -90;
- this.startY = 190 + this.offsetY;
- this.renderOnce = true;
- this.render();
- } else {
- this.altOffset = 300;
- this.size();
- this.renderAlt();
- }
- }
- _createClass(WiresRight, [{
- key: 'render',
- value: function render(once) {
- this.context.clearRect(0, 0, this.width, this.height);
- this.context.lineWidth = 3;
- for (var index = 0; index < 3; index += 1) {
- var startY = this.startY + this.startSpace * index;
- var start = {
- x: this.startX,
- y: this.startY + this.startSpace * index
- };
- var end = {
- x: this.endX,
- y: this.endY + this.endSpace * index
- };
- var cp1 = {
- x: 5,
- y: start.y
- };
- var cp2 = {
- x: 25,
- y: end.y
- };
- this.context.strokeStyle = '#cfd1d2';
- this.context.beginPath();
- this.context.moveTo(start.x, start.y);
- this.context.bezierCurveTo(cp1.x, cp1.y, cp2.x, cp2.y, end.x, end.y);
- this.context.stroke();
- }
- if (this.renderOnce) {
- this.renderOnce = false;
- } else {
- if (this.current < this.loops) {
- this.current += 1;
- } else {
- this.dehighlight();
- }
- this.running = true;
- this.timer = requestAnimationFrame(this.render.bind(this));
- }
- }
- }, {
- key: 'renderAlt',
- value: function renderAlt(once) {
- this.context.clearRect(0, 0, this.width, this.height);
- this.context.lineWidth = 3;
- for (var index = 0; index < 4; index += 1) {
- var startY = this.startY + this.startSpace * index;
- var start = {
- x: this.startX,
- y: this.startY + this.startSpace * index
- };
- var end = {
- x: this.endX,
- y: this.endY + this.endSpace * index
- };
- this.context.strokeStyle = '#cfd1d2';
- this.context.beginPath();
- this.context.moveTo(start.x, start.y);
- this.context.lineTo(end.x, start.y);
- this.context.stroke();
- }
- if (this.renderOnce) {
- this.renderOnce = false;
- } else {
- if (this.current < this.loops) {
- this.current += 1;
- } else {
- this.dehighlight();
- }
- this.timer = requestAnimationFrame(this.renderAlt.bind(this));
- }
- }
- }, {
- key: 'highlight',
- value: function highlight(id) {
- var index = _config2.default.classNames.indexOf(id);
- // console.log(index);
- // if (this.animator[index]) {
- // let animator = this.animator[index];
- // animator.bulb.classList.add('wires__bulb--selected');
- // this.highlightedLineIndex = index;
- // this.current = 0;
- // this.start();
- // }
- switch (index) {
- case 0:
- this.bulbGreen.classList.add('bulb--selected');
- break;
- case 1:
- this.bulbOrange.classList.add('bulb--selected');
- break;
- case 2:
- this.bulbPurple.classList.add('bulb--selected');
- break;
- default:
- }
- }
- }, {
- key: 'dehighlight',
- value: function dehighlight() {
- this.bulbGreen.classList.remove('bulb--selected');
- this.bulbPurple.classList.remove('bulb--selected');
- this.bulbOrange.classList.remove('bulb--selected');
- }
- }, {
- key: 'start',
- value: function start() {
- if (!this.running) {
- this.timer = requestAnimationFrame(this.bulbVert ? this.render.bind(this) : this.renderAlt.bind(this));
- }
- }
- }, {
- key: 'stop',
- value: function stop() {
- cancelAnimationFrame(this.timer);
- this.running = false;
- }
- }, {
- key: 'size',
- value: function size() {
- var _this2 = this;
- var BREAKPOINT_DESKTOP = 900;
- var BREAKPOINT_MED = 428;
- this.width = this.element.offsetWidth;
- var bulbs = Array.from(document.getElementsByClassName('wires__bulb'));
- this.startSpace = (this.height - 80) / 3;
- // console.log(this.startSpace);
- this.startSpace = 130;
- this.endSpace = (this.height + 45) / 5;
- this.canvas.width = 70;
- this.canvas.height = this.height;
- // this element rotated in css and using height as width
- // if (window.innerWidth >= BREAKPOINT_DESKTOP) {
- this.height = 450;
- // remove offset on desktop
- this.element.setAttribute('style', '');
- bulbs.forEach(function (bulb, index) {
- bulb.style.top = _this2.endY + index * _this2.endSpace + 'px';
- });
- this.bulbVert = true;
- this.startX = 0;
- this.startY = 190 + this.offsetY;
- // this.endSpace = this.height / 5;
- this.endX = this.width;
- // this.endY = (this.height / 2) - (2 * this.endSpace) + 25;
- this.endY = 145;
- if (window.innerWidth <= BREAKPOINT_DESKTOP) {
- this.canvas.style.display = 'none';
- bulbs.forEach(function (bulb, index) {
- bulb.style.top = 'none';
- });
- }
- }
- }]);
- return WiresRight;
- }();
- exports.default = WiresRight;
- },{"./../../config.js":242}],268:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var WizardGIFExample = function () {
- function WizardGIFExample(url) {
- _classCallCheck(this, WizardGIFExample);
- this.element = document.createElement('div');
- this.element.classList.add('wizard__gif');
- var mask = document.createElement('div');
- mask.classList.add('wizard__gif-mask');
- var image = new Image();
- image.classList.add('wizard__gif-image');
- image.src = url;
- mask.appendChild(image);
- this.element.appendChild(mask);
- }
- _createClass(WizardGIFExample, [{
- key: 'show',
- value: function show() {
- this.element.style.display = 'block';
- }
- }, {
- key: 'hide',
- value: function hide() {
- this.element.style.display = 'none';
- }
- }]);
- return WizardGIFExample;
- }();
- exports.default = WizardGIFExample;
- },{}],269:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _gsap = require('gsap');
- var _gsap2 = _interopRequireDefault(_gsap);
- var _ScrollToPlugin = require('gsap/ScrollToPlugin');
- var _ScrollToPlugin2 = _interopRequireDefault(_ScrollToPlugin);
- var _config = require('./../../../config.js');
- var _config2 = _interopRequireDefault(_config);
- var _Button = require('./../../components/Button.js');
- var _Button2 = _interopRequireDefault(_Button);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var LaunchScreen = function () {
- function LaunchScreen() {
- _classCallCheck(this, LaunchScreen);
- this.element = document.querySelector('.intro');
- this.startButton = new _Button2.default(document.querySelector('#start-tutorial-button'));
- this.skipButton = document.querySelector('#skip-tutorial-button');
- this.skipButtonMobile = document.querySelector('#skip-tutorial-button-mobile');
- this.messageIsCompatible = document.querySelector('#is-compatible');
- this.messageIsNotCompatible = document.querySelector('#is-not-compatible');
- this.startButton.element.classList.add('button--disabled');
- document.querySelector('.wizard__launch-skip-paragraph').style.display = 'none';
- document.querySelector('.wizard__browser-warning').style.display = 'block';
- // let facebookButton = document.querySelector('.intro__share-link--facebook');
- // let twitterButton = document.querySelector('.intro__share-link--twitter');
- var intro = document.querySelector('.intro__content-mobile');
- /*eslint-disable */
- var defaultPrevent = function defaultPrevent(event) {
- event.preventDefault();
- };
- /* eslint-enable*/
- intro.addEventListener('touchstart', defaultPrevent);
- intro.addEventListener('touchmove', defaultPrevent);
- // let loader = ((el) => {
- // let ajax = new XMLHttpRequest();
- // ajax.open('GET', 'assets/social-facebook.svg', true);
- // ajax.onload = (event) => {
- // el.innerHTML = ajax.responseText;
- // };
- // ajax.send();
- // })(facebookButton);
- // loader = ((el) => {
- // let ajax = new XMLHttpRequest();
- // ajax.open('GET', 'assets/social-twitter.svg', true);
- // ajax.onload = (event) => {
- // el.innerHTML = ajax.responseText;
- // };
- // ajax.send();
- // })(twitterButton);
- // facebookButton.addEventListener('click', this.openFacebookPopup.bind(this));
- // twitterButton.addEventListener('click', this.openTwitterPopup.bind(this));
- if (_config2.default.browserUtils.isCompatible === true && _config2.default.browserUtils.isMobile === false) {
- this.startButton.element.classList.remove('button--disabled');
- document.querySelector('.wizard__launch-skip-paragraph').style.display = 'block';
- document.querySelector('.wizard__browser-warning').style.display = 'none';
- }
- if (_config2.default.browserUtils.isMobile) {
- this.messageIsCompatible.style.display = 'block';
- } else {
- this.messageIsCompatible.style.display = 'none';
- }
- if (_config2.default.browserUtils.isMobile && !_config2.default.browserUtils.isCompatible) {
- this.messageIsCompatible.style.display = 'none';
- this.messageIsNotCompatible.style.display = 'block';
- }
- this.skipButton.addEventListener('click', this.skipClick.bind(this));
- this.skipButtonMobile.addEventListener('touchend', this.skipClick.bind(this));
- this.skipButtonMobile.addEventListener('click', this.skipClick.bind(this));
- this.startButton.element.addEventListener('click', this.startClick.bind(this));
- this.startButton.element.addEventListener('touchend', this.startClick.bind(this));
- this.startButton.click();
- }
- // openFacebookPopup(event) {
- // event.preventDefault();
- // let url = event.currentTarget.getAttribute('href');
- // /* eslint-disable space-infix-ops */
- // window.open(url, 'fbShareWindow', 'height=450, width=550, top='+(window.innerHeight/2-275)+', left='+(window.innerWidth/2-225)+',toolbar=0, location=0, menubar=0, directories=0, scrollbars=0');
- // /* eslint-enable space-infix-ops */
- // }
- // openTwitterPopup(event) {
- // event.preventDefault();
- // let url = event.currentTarget.getAttribute('href');
- // /* eslint-disable space-infix-ops */
- // window.open(url, 'fbShareWindow', 'height=450, width=600, top='+(window.innerHeight/2-150)+', left='+(window.innerWidth/2-225)+', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0');
- // /* eslint-enable space-infix-ops */
- // }
- _createClass(LaunchScreen, [{
- key: 'skipClick',
- value: function skipClick(event) {
- var _this = this;
- event.preventDefault();
- var intro = document.querySelector('.intro');
- var offset = intro.offsetHeight;
- _config2.default.wizard.skip();
- gtag('event', 'wizard_skip');
- if (_config2.default.browserUtils.isMobile) {
- var msg = new SpeechSynthesisUtterance();
- msg.text = ' ';
- window.speechSynthesis.speak(msg);
- _config2.default.inputSection.createCamInput();
- _config2.default.camInput.start();
- var _event = new CustomEvent('mobileLaunch');
- window.dispatchEvent(_event);
- }
- _gsap2.default.to(intro, 0.5, {
- y: -offset,
- onComplete: function onComplete() {
- _this.destroy();
- if (!_config2.default.browserUtils.isMobile) {
- _config2.default.wizard.startCamera();
- }
- }
- });
- }
- }, {
- key: 'destroy',
- value: function destroy() {
- document.body.classList.remove('no-scroll');
- this.element.style.display = 'none';
- }
- }, {
- key: 'startClick',
- value: function startClick() {
- var _this2 = this;
- var intro = document.querySelector('.intro');
- var offset = intro.offsetHeight;
- if (_config2.default.browserUtils.isMobile || _config2.default.browserUtils.isSafari) {
- _config2.default.inputSection.createCamInput();
- _config2.default.camInput.start();
- _config2.default.wizard.touchPlay();
- var event = new CustomEvent('mobileLaunch');
- window.dispatchEvent(event);
- }
- _gsap2.default.to(intro, 0.5, {
- y: -offset,
- onComplete: function onComplete() {
- _this2.destroy();
- _config2.default.wizard.start();
- _this2.skipButton.click();
- }
- });
- }
- }]);
- return LaunchScreen;
- }();
- exports.default = LaunchScreen;
- },{"./../../../config.js":242,"./../../components/Button.js":252,"gsap":212,"gsap/ScrollToPlugin":210}],270:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- var _gsap = require('gsap');
- var _gsap2 = _interopRequireDefault(_gsap);
- var _ScrollToPlugin = require('gsap/ScrollToPlugin');
- var _ScrollToPlugin2 = _interopRequireDefault(_ScrollToPlugin);
- var _config = require('./../../../config.js');
- var _config2 = _interopRequireDefault(_config);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- // Copyright 2017 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- var QuickLaunch = function () {
- function QuickLaunch() {
- _classCallCheck(this, QuickLaunch);
- this.machine = document.querySelector('.machine');
- this.wrapper = document.querySelector('.wrapper');
- this.size();
- this.resizeEvent = this.size.bind(this);
- window.addEventListener('resize', this.resizeEvent);
- }
- _createClass(QuickLaunch, [{
- key: 'start',
- value: function start() {
- _config2.default.inputSection.enable();
- _config2.default.inputSection.hideGif(0);
- _config2.default.inputSection.hideGif(1);
- _config2.default.inputSection.hideGif(2);
- _config2.default.inputSection.hideGif(3);
- _config2.default.inputSection.undim();
- _config2.default.learningSection.dehighlight();
- _config2.default.learningSection.dehighlightClass(0);
- _config2.default.learningSection.dehighlightClass(1);
- _config2.default.learningSection.dehighlightClass(2);
- _config2.default.learningSection.enable();
- _config2.default.learningSection.enableClass(0);
- _config2.default.learningSection.enableClass(1);
- _config2.default.learningSection.enableClass(2);
- _config2.default.learningSection.undim();
- _config2.default.outputSection.dehighlight();
- _config2.default.outputSection.enable();
- _config2.default.outputSection.undim();
- if (_config2.default.browserUtils.isMobile || _config2.default.browserUtils.isSafari) {
- _config2.default.inputSection.createCamInput();
- var event = new CustomEvent("mobileLaunch");
- window.dispatchEvent(event);
- }
- window.removeEventListener("class-trained", this.classTrainedEvent);
- // setTimeout(() => {
- // document.querySelector(".webcam--off").click();
- // }, 1000);
- }
- }, {
- key: 'size',
- value: function size() {
- this.wrapper.style.height = window.innerHeight + 'px';
- this.machine.style.top = (window.innerHeight - this.machine.offsetHeight) / 2 + 'px';
- }
- }]);
- return QuickLaunch;
- }();
- // import Button from './../../components/Button.js';
- exports.default = QuickLaunch;
- },{"./../../../config.js":242,"gsap":212,"gsap/ScrollToPlugin":210}]},{},[243]);
|