mdc.menu.js 338 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://github.com/material-components/material-components-web/blob/master/LICENSE
  7. */
  8. (function webpackUniversalModuleDefinition(root, factory) {
  9. if(typeof exports === 'object' && typeof module === 'object')
  10. module.exports = factory();
  11. else if(typeof define === 'function' && define.amd)
  12. define("@material/menu", [], factory);
  13. else if(typeof exports === 'object')
  14. exports["menu"] = factory();
  15. else
  16. root["mdc"] = root["mdc"] || {}, root["mdc"]["menu"] = factory();
  17. })(this, function() {
  18. return /******/ (function(modules) { // webpackBootstrap
  19. /******/ // The module cache
  20. /******/ var installedModules = {};
  21. /******/
  22. /******/ // The require function
  23. /******/ function __webpack_require__(moduleId) {
  24. /******/
  25. /******/ // Check if module is in cache
  26. /******/ if(installedModules[moduleId]) {
  27. /******/ return installedModules[moduleId].exports;
  28. /******/ }
  29. /******/ // Create a new module (and put it into the cache)
  30. /******/ var module = installedModules[moduleId] = {
  31. /******/ i: moduleId,
  32. /******/ l: false,
  33. /******/ exports: {}
  34. /******/ };
  35. /******/
  36. /******/ // Execute the module function
  37. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  38. /******/
  39. /******/ // Flag the module as loaded
  40. /******/ module.l = true;
  41. /******/
  42. /******/ // Return the exports of the module
  43. /******/ return module.exports;
  44. /******/ }
  45. /******/
  46. /******/
  47. /******/ // expose the modules object (__webpack_modules__)
  48. /******/ __webpack_require__.m = modules;
  49. /******/
  50. /******/ // expose the module cache
  51. /******/ __webpack_require__.c = installedModules;
  52. /******/
  53. /******/ // define getter function for harmony exports
  54. /******/ __webpack_require__.d = function(exports, name, getter) {
  55. /******/ if(!__webpack_require__.o(exports, name)) {
  56. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  57. /******/ }
  58. /******/ };
  59. /******/
  60. /******/ // define __esModule on exports
  61. /******/ __webpack_require__.r = function(exports) {
  62. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  63. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  64. /******/ }
  65. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  66. /******/ };
  67. /******/
  68. /******/ // create a fake namespace object
  69. /******/ // mode & 1: value is a module id, require it
  70. /******/ // mode & 2: merge all properties of value into the ns
  71. /******/ // mode & 4: return value when already ns object
  72. /******/ // mode & 8|1: behave like require
  73. /******/ __webpack_require__.t = function(value, mode) {
  74. /******/ if(mode & 1) value = __webpack_require__(value);
  75. /******/ if(mode & 8) return value;
  76. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  77. /******/ var ns = Object.create(null);
  78. /******/ __webpack_require__.r(ns);
  79. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  80. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  81. /******/ return ns;
  82. /******/ };
  83. /******/
  84. /******/ // getDefaultExport function for compatibility with non-harmony modules
  85. /******/ __webpack_require__.n = function(module) {
  86. /******/ var getter = module && module.__esModule ?
  87. /******/ function getDefault() { return module['default']; } :
  88. /******/ function getModuleExports() { return module; };
  89. /******/ __webpack_require__.d(getter, 'a', getter);
  90. /******/ return getter;
  91. /******/ };
  92. /******/
  93. /******/ // Object.prototype.hasOwnProperty.call
  94. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  95. /******/
  96. /******/ // __webpack_public_path__
  97. /******/ __webpack_require__.p = "";
  98. /******/
  99. /******/
  100. /******/ // Load entry module and return exports
  101. /******/ return __webpack_require__(__webpack_require__.s = "./packages/mdc-menu/index.ts");
  102. /******/ })
  103. /************************************************************************/
  104. /******/ ({
  105. /***/ "./node_modules/process/browser.js":
  106. /*!*****************************************!*\
  107. !*** ./node_modules/process/browser.js ***!
  108. \*****************************************/
  109. /*! no static exports found */
  110. /***/ (function(module, exports) {
  111. // shim for using process in browser
  112. var process = module.exports = {};
  113. // cached from whatever global is present so that test runners that stub it
  114. // don't break things. But we need to wrap it in a try catch in case it is
  115. // wrapped in strict mode code which doesn't define any globals. It's inside a
  116. // function because try/catches deoptimize in certain engines.
  117. var cachedSetTimeout;
  118. var cachedClearTimeout;
  119. function defaultSetTimout() {
  120. throw new Error('setTimeout has not been defined');
  121. }
  122. function defaultClearTimeout () {
  123. throw new Error('clearTimeout has not been defined');
  124. }
  125. (function () {
  126. try {
  127. if (typeof setTimeout === 'function') {
  128. cachedSetTimeout = setTimeout;
  129. } else {
  130. cachedSetTimeout = defaultSetTimout;
  131. }
  132. } catch (e) {
  133. cachedSetTimeout = defaultSetTimout;
  134. }
  135. try {
  136. if (typeof clearTimeout === 'function') {
  137. cachedClearTimeout = clearTimeout;
  138. } else {
  139. cachedClearTimeout = defaultClearTimeout;
  140. }
  141. } catch (e) {
  142. cachedClearTimeout = defaultClearTimeout;
  143. }
  144. } ())
  145. function runTimeout(fun) {
  146. if (cachedSetTimeout === setTimeout) {
  147. //normal enviroments in sane situations
  148. return setTimeout(fun, 0);
  149. }
  150. // if setTimeout wasn't available but was latter defined
  151. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  152. cachedSetTimeout = setTimeout;
  153. return setTimeout(fun, 0);
  154. }
  155. try {
  156. // when when somebody has screwed with setTimeout but no I.E. maddness
  157. return cachedSetTimeout(fun, 0);
  158. } catch(e){
  159. try {
  160. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  161. return cachedSetTimeout.call(null, fun, 0);
  162. } catch(e){
  163. // 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
  164. return cachedSetTimeout.call(this, fun, 0);
  165. }
  166. }
  167. }
  168. function runClearTimeout(marker) {
  169. if (cachedClearTimeout === clearTimeout) {
  170. //normal enviroments in sane situations
  171. return clearTimeout(marker);
  172. }
  173. // if clearTimeout wasn't available but was latter defined
  174. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  175. cachedClearTimeout = clearTimeout;
  176. return clearTimeout(marker);
  177. }
  178. try {
  179. // when when somebody has screwed with setTimeout but no I.E. maddness
  180. return cachedClearTimeout(marker);
  181. } catch (e){
  182. try {
  183. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  184. return cachedClearTimeout.call(null, marker);
  185. } catch (e){
  186. // 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.
  187. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  188. return cachedClearTimeout.call(this, marker);
  189. }
  190. }
  191. }
  192. var queue = [];
  193. var draining = false;
  194. var currentQueue;
  195. var queueIndex = -1;
  196. function cleanUpNextTick() {
  197. if (!draining || !currentQueue) {
  198. return;
  199. }
  200. draining = false;
  201. if (currentQueue.length) {
  202. queue = currentQueue.concat(queue);
  203. } else {
  204. queueIndex = -1;
  205. }
  206. if (queue.length) {
  207. drainQueue();
  208. }
  209. }
  210. function drainQueue() {
  211. if (draining) {
  212. return;
  213. }
  214. var timeout = runTimeout(cleanUpNextTick);
  215. draining = true;
  216. var len = queue.length;
  217. while(len) {
  218. currentQueue = queue;
  219. queue = [];
  220. while (++queueIndex < len) {
  221. if (currentQueue) {
  222. currentQueue[queueIndex].run();
  223. }
  224. }
  225. queueIndex = -1;
  226. len = queue.length;
  227. }
  228. currentQueue = null;
  229. draining = false;
  230. runClearTimeout(timeout);
  231. }
  232. process.nextTick = function (fun) {
  233. var args = new Array(arguments.length - 1);
  234. if (arguments.length > 1) {
  235. for (var i = 1; i < arguments.length; i++) {
  236. args[i - 1] = arguments[i];
  237. }
  238. }
  239. queue.push(new Item(fun, args));
  240. if (queue.length === 1 && !draining) {
  241. runTimeout(drainQueue);
  242. }
  243. };
  244. // v8 likes predictible objects
  245. function Item(fun, array) {
  246. this.fun = fun;
  247. this.array = array;
  248. }
  249. Item.prototype.run = function () {
  250. this.fun.apply(null, this.array);
  251. };
  252. process.title = 'browser';
  253. process.browser = true;
  254. process.env = {};
  255. process.argv = [];
  256. process.version = ''; // empty string to avoid regexp issues
  257. process.versions = {};
  258. function noop() {}
  259. process.on = noop;
  260. process.addListener = noop;
  261. process.once = noop;
  262. process.off = noop;
  263. process.removeListener = noop;
  264. process.removeAllListeners = noop;
  265. process.emit = noop;
  266. process.prependListener = noop;
  267. process.prependOnceListener = noop;
  268. process.listeners = function (name) { return [] }
  269. process.binding = function (name) {
  270. throw new Error('process.binding is not supported');
  271. };
  272. process.cwd = function () { return '/' };
  273. process.chdir = function (dir) {
  274. throw new Error('process.chdir is not supported');
  275. };
  276. process.umask = function() { return 0; };
  277. /***/ }),
  278. /***/ "./node_modules/safevalues/builders/attribute_builders.js":
  279. /*!****************************************************************!*\
  280. !*** ./node_modules/safevalues/builders/attribute_builders.js ***!
  281. \****************************************************************/
  282. /*! no static exports found */
  283. /***/ (function(module, exports, __webpack_require__) {
  284. "use strict";
  285. /**
  286. * @license
  287. * SPDX-License-Identifier: Apache-2.0
  288. */
  289. Object.defineProperty(exports, "__esModule", { value: true });
  290. exports.safeAttrPrefix = void 0;
  291. __webpack_require__(/*! ../environment/dev */ "./node_modules/safevalues/environment/dev.js");
  292. var attribute_impl_1 = __webpack_require__(/*! ../internals/attribute_impl */ "./node_modules/safevalues/internals/attribute_impl.js");
  293. var string_literal_1 = __webpack_require__(/*! ../internals/string_literal */ "./node_modules/safevalues/internals/string_literal.js");
  294. var sensitive_attributes_1 = __webpack_require__(/*! ./sensitive_attributes */ "./node_modules/safevalues/builders/sensitive_attributes.js");
  295. /**
  296. * Creates a SafeAttributePrefix object from a template literal with no
  297. * interpolations for attributes that share a common prefix guaranteed to be not
  298. * security sensitive.
  299. *
  300. * The template literal is a prefix that makes it obvious this attribute is not
  301. * security sensitive. If it doesn't, this function will throw.
  302. */
  303. function safeAttrPrefix(templ) {
  304. if (true) {
  305. (0, string_literal_1.assertIsTemplateObject)(templ, true, 'safeAttr is a template literal tag function ' +
  306. 'and should be called using the tagged template syntax. ' +
  307. 'For example, safeAttr`foo`;');
  308. }
  309. var attrPrefix = templ[0].toLowerCase();
  310. if (true) {
  311. if (attrPrefix.indexOf('on') === 0 || 'on'.indexOf(attrPrefix) === 0) {
  312. throw new Error("Prefix '".concat(templ[0], "' does not guarantee the attribute ") +
  313. "to be safe as it is also a prefix for event handler attributes" +
  314. "Please use 'addEventListener' to set event handlers.");
  315. }
  316. sensitive_attributes_1.SECURITY_SENSITIVE_ATTRIBUTES.forEach(function (sensitiveAttr) {
  317. if (sensitiveAttr.indexOf(attrPrefix) === 0) {
  318. throw new Error("Prefix '".concat(templ[0], "' does not guarantee the attribute ") +
  319. "to be safe as it is also a prefix for " +
  320. "the security sensitive attribute '".concat(sensitiveAttr, "'. ") +
  321. "Please use native or safe DOM APIs to set the attribute.");
  322. }
  323. });
  324. }
  325. return (0, attribute_impl_1.createAttributePrefix)(attrPrefix);
  326. }
  327. exports.safeAttrPrefix = safeAttrPrefix;
  328. /***/ }),
  329. /***/ "./node_modules/safevalues/builders/html_builders.js":
  330. /*!***********************************************************!*\
  331. !*** ./node_modules/safevalues/builders/html_builders.js ***!
  332. \***********************************************************/
  333. /*! no static exports found */
  334. /***/ (function(module, exports, __webpack_require__) {
  335. "use strict";
  336. /**
  337. * @license
  338. * SPDX-License-Identifier: Apache-2.0
  339. */
  340. Object.defineProperty(exports, "__esModule", { value: true });
  341. exports.concatHtmls = exports.createScriptSrc = exports.createScript = exports.htmlEscape = void 0;
  342. var html_impl_1 = __webpack_require__(/*! ../internals/html_impl */ "./node_modules/safevalues/internals/html_impl.js");
  343. var resource_url_impl_1 = __webpack_require__(/*! ../internals/resource_url_impl */ "./node_modules/safevalues/internals/resource_url_impl.js");
  344. var script_impl_1 = __webpack_require__(/*! ../internals/script_impl */ "./node_modules/safevalues/internals/script_impl.js");
  345. /**
  346. * Returns HTML-escaped text as a `SafeHtml` object.
  347. *
  348. * Available options:
  349. * - `preserveSpaces` turns every second consecutive space character into its
  350. * HTML entity representation (`&#160;`).
  351. * - `preserveNewlines` turns newline characters into breaks (`<br>`).
  352. * - `preserveTabs` wraps tab characters in a span with style=white-space:pre.
  353. */
  354. function htmlEscape(text, options) {
  355. if (options === void 0) { options = {}; }
  356. var htmlEscapedString = htmlEscapeToString(text);
  357. if (options.preserveSpaces) {
  358. // Do this first to ensure we preserve spaces after newlines and tabs.
  359. htmlEscapedString =
  360. htmlEscapedString.replace(/(^|[\r\n\t ]) /g, '$1&#160;');
  361. }
  362. if (options.preserveNewlines) {
  363. htmlEscapedString = htmlEscapedString.replace(/(\r\n|\n|\r)/g, '<br>');
  364. }
  365. if (options.preserveTabs) {
  366. htmlEscapedString = htmlEscapedString.replace(/(\t+)/g, '<span style="white-space:pre">$1</span>');
  367. }
  368. return (0, html_impl_1.createHtml)(htmlEscapedString);
  369. }
  370. exports.htmlEscape = htmlEscape;
  371. /**
  372. * Creates a `SafeHtml` representing a script tag with inline script content.
  373. */
  374. function createScript(script, options) {
  375. if (options === void 0) { options = {}; }
  376. var unwrappedScript = (0, script_impl_1.unwrapScript)(script).toString();
  377. var stringTag = "<script";
  378. if (options.id) {
  379. stringTag += " id=\"".concat(htmlEscapeToString(options.id), "\"");
  380. }
  381. if (options.nonce) {
  382. stringTag += " nonce=\"".concat(htmlEscapeToString(options.nonce), "\"");
  383. }
  384. if (options.type) {
  385. stringTag += " type=\"".concat(htmlEscapeToString(options.type), "\"");
  386. }
  387. stringTag += ">".concat(unwrappedScript, "</script>");
  388. return (0, html_impl_1.createHtml)(stringTag);
  389. }
  390. exports.createScript = createScript;
  391. /**
  392. * Creates a `SafeHtml` representing a script tag with the src attribute.
  393. * This also supports CSP nonces and async loading.
  394. */
  395. function createScriptSrc(src, async, nonce) {
  396. var unwrappedSrc = (0, resource_url_impl_1.unwrapResourceUrl)(src).toString();
  397. var stringTag = "<script src=\"".concat(htmlEscapeToString(unwrappedSrc), "\"");
  398. if (async) {
  399. stringTag += ' async';
  400. }
  401. if (nonce) {
  402. stringTag += " nonce=\"".concat(htmlEscapeToString(nonce), "\"");
  403. }
  404. stringTag += '>\x3c/script>';
  405. return (0, html_impl_1.createHtml)(stringTag);
  406. }
  407. exports.createScriptSrc = createScriptSrc;
  408. /**
  409. * HTML-escapes the given text (`&`, `<`, `>`, `"` and `'`).
  410. */
  411. function htmlEscapeToString(text) {
  412. var escaped = text.replace(/&/g, '&amp;')
  413. .replace(/</g, '&lt;')
  414. .replace(/>/g, '&gt;')
  415. .replace(/"/g, '&quot;')
  416. .replace(/'/g, '&apos;');
  417. return escaped;
  418. }
  419. /** Creates a `SafeHtml` value by concatenating multiple `SafeHtml`s. */
  420. function concatHtmls(htmls) {
  421. return (0, html_impl_1.createHtml)(htmls.map(html_impl_1.unwrapHtml).join(''));
  422. }
  423. exports.concatHtmls = concatHtmls;
  424. /***/ }),
  425. /***/ "./node_modules/safevalues/builders/html_sanitizer/html_sanitizer.js":
  426. /*!***************************************************************************!*\
  427. !*** ./node_modules/safevalues/builders/html_sanitizer/html_sanitizer.js ***!
  428. \***************************************************************************/
  429. /*! no static exports found */
  430. /***/ (function(module, exports, __webpack_require__) {
  431. "use strict";
  432. /**
  433. * @license
  434. * SPDX-License-Identifier: Apache-2.0
  435. */
  436. var __values = (this && this.__values) || function(o) {
  437. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  438. if (m) return m.call(o);
  439. if (o && typeof o.length === "number") return {
  440. next: function () {
  441. if (o && i >= o.length) o = void 0;
  442. return { value: o && o[i++], done: !o };
  443. }
  444. };
  445. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  446. };
  447. var __read = (this && this.__read) || function (o, n) {
  448. var m = typeof Symbol === "function" && o[Symbol.iterator];
  449. if (!m) return o;
  450. var i = m.call(o), r, ar = [], e;
  451. try {
  452. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  453. }
  454. catch (error) { e = { error: error }; }
  455. finally {
  456. try {
  457. if (r && !r.done && (m = i["return"])) m.call(i);
  458. }
  459. finally { if (e) throw e.error; }
  460. }
  461. return ar;
  462. };
  463. Object.defineProperty(exports, "__esModule", { value: true });
  464. exports.sanitizeHtmlToFragment = exports.sanitizeHtmlAssertUnchanged = exports.sanitizeHtml = exports.HtmlSanitizerImpl = void 0;
  465. __webpack_require__(/*! ../../environment/dev */ "./node_modules/safevalues/environment/dev.js");
  466. var html_impl_1 = __webpack_require__(/*! ../../internals/html_impl */ "./node_modules/safevalues/internals/html_impl.js");
  467. /* g3_import_pure from '../../internals/pure' */
  468. var secrets_1 = __webpack_require__(/*! ../../internals/secrets */ "./node_modules/safevalues/internals/secrets.js");
  469. var url_sanitizer_1 = __webpack_require__(/*! ../url_sanitizer */ "./node_modules/safevalues/builders/url_sanitizer.js");
  470. var inert_fragment_1 = __webpack_require__(/*! ./inert_fragment */ "./node_modules/safevalues/builders/html_sanitizer/inert_fragment.js");
  471. var no_clobber_1 = __webpack_require__(/*! ./no_clobber */ "./node_modules/safevalues/builders/html_sanitizer/no_clobber.js");
  472. var default_sanitizer_table_1 = __webpack_require__(/*! ./sanitizer_table/default_sanitizer_table */ "./node_modules/safevalues/builders/html_sanitizer/sanitizer_table/default_sanitizer_table.js");
  473. var sanitizer_table_1 = __webpack_require__(/*! ./sanitizer_table/sanitizer_table */ "./node_modules/safevalues/builders/html_sanitizer/sanitizer_table/sanitizer_table.js");
  474. /** Implementation for `HtmlSanitizer` */
  475. var HtmlSanitizerImpl = /** @class */ (function () {
  476. function HtmlSanitizerImpl(sanitizerTable, token) {
  477. this.sanitizerTable = sanitizerTable;
  478. this.changes = [];
  479. (0, secrets_1.ensureTokenIsValid)(token);
  480. }
  481. HtmlSanitizerImpl.prototype.sanitizeAssertUnchanged = function (html) {
  482. this.changes = [];
  483. var sanitizedHtml = this.sanitize(html);
  484. if (this.changes.length !== 0) {
  485. var message = '';
  486. if (true) {
  487. message =
  488. "Unexpected change to HTML value as a result of sanitization. " +
  489. "Input: \"".concat(html, "\", sanitized output: \"").concat(sanitizedHtml, "\"\n") +
  490. "List of changes:".concat(this.changes.join('\n'));
  491. }
  492. throw new Error(message);
  493. }
  494. return sanitizedHtml;
  495. };
  496. HtmlSanitizerImpl.prototype.sanitize = function (html) {
  497. var fakeRoot = document.createElement('span');
  498. fakeRoot.appendChild(this.sanitizeToFragment(html));
  499. // XML serialization is preferred over HTML serialization as it is
  500. // stricter and makes sure all attributes are properly escaped, avoiding
  501. // cases where the tree might mutate when parsed again later due to the
  502. // complexities of the HTML parsing algorithm
  503. var serializedNewTree = new XMLSerializer().serializeToString(fakeRoot);
  504. // We remove the outer most element as this is the span node created as
  505. // the root for the sanitized tree and contains a spurious xmlns attribute
  506. // from the XML serialization step.
  507. serializedNewTree = serializedNewTree.slice(serializedNewTree.indexOf('>') + 1, serializedNewTree.lastIndexOf('</'));
  508. return (0, html_impl_1.createHtml)(serializedNewTree);
  509. };
  510. HtmlSanitizerImpl.prototype.sanitizeToFragment = function (html) {
  511. var _this = this;
  512. var dirtyFragment = (0, inert_fragment_1.createInertFragment)(html);
  513. var treeWalker = document.createTreeWalker(dirtyFragment, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,
  514. // IE10 and IE11 won't accept a proper `NodeFilter` interface, and
  515. // expect the filtering function to be passed directly. It seems that
  516. // other browsers also do not mind getting the function directly. see
  517. // https://stackoverflow.com/q/38245898
  518. (function (n) { return _this.nodeFilter(n); }),
  519. // @ts-ignore: error TS2554: Expected 1-3 arguments, but got 4.
  520. false);
  521. // `nextNode` is called so we skip the root `DocumentFragment`.
  522. var currentNode = treeWalker.nextNode();
  523. // We create a root element to attach all the children of the body to. We
  524. // use div as it as a semantic-free, generic container and does not
  525. // represent anything. This is removed when we serialize the tree back
  526. // into a string.
  527. var sanitizedFragment = document.createDocumentFragment();
  528. var sanitizedParent = sanitizedFragment;
  529. while (currentNode !== null) {
  530. var sanitizedNode = void 0;
  531. if ((0, no_clobber_1.isText)(currentNode)) {
  532. sanitizedNode = this.sanitizeTextNode(currentNode);
  533. }
  534. else if ((0, no_clobber_1.isElement)(currentNode)) {
  535. sanitizedNode = this.sanitizeElementNode(currentNode);
  536. }
  537. else {
  538. throw new Error('Node is not of type text or element');
  539. }
  540. sanitizedParent.appendChild(sanitizedNode);
  541. // Advance iterator while keeping track of the sanitized parent for the
  542. // current node
  543. currentNode = treeWalker.firstChild();
  544. if (currentNode) {
  545. sanitizedParent = sanitizedNode;
  546. }
  547. else {
  548. while (!(currentNode = treeWalker.nextSibling())) {
  549. if (!(currentNode = treeWalker.parentNode())) {
  550. break;
  551. }
  552. sanitizedParent = sanitizedParent.parentNode;
  553. }
  554. }
  555. }
  556. return sanitizedFragment;
  557. };
  558. HtmlSanitizerImpl.prototype.sanitizeTextNode = function (textNode) {
  559. return document.createTextNode(textNode.data);
  560. };
  561. HtmlSanitizerImpl.prototype.sanitizeElementNode = function (elementNode) {
  562. var e_1, _a;
  563. var elementName = (0, no_clobber_1.getNodeName)(elementNode);
  564. var newNode = document.createElement(elementName);
  565. var dirtyAttributes = elementNode.attributes;
  566. try {
  567. for (var dirtyAttributes_1 = __values(dirtyAttributes), dirtyAttributes_1_1 = dirtyAttributes_1.next(); !dirtyAttributes_1_1.done; dirtyAttributes_1_1 = dirtyAttributes_1.next()) {
  568. var _b = dirtyAttributes_1_1.value, name_1 = _b.name, value = _b.value;
  569. var policy = this.sanitizerTable.getAttributePolicy(name_1, elementName);
  570. if (!this.satisfiesAllConditions(policy.conditions, dirtyAttributes)) {
  571. this.recordChange("Not all conditions satisfied for attribute: ".concat(name_1, "."));
  572. continue;
  573. }
  574. switch (policy.policyAction) {
  575. case sanitizer_table_1.AttributePolicyAction.KEEP:
  576. newNode.setAttribute(name_1, value);
  577. break;
  578. case sanitizer_table_1.AttributePolicyAction.KEEP_AND_SANITIZE_URL:
  579. var sanitizedAttrUrl = (0, url_sanitizer_1.restrictivelySanitizeUrl)(value);
  580. if (sanitizedAttrUrl !== value) {
  581. this.recordChange("Url in attribute ".concat(name_1, " was modified during sanitization. Original url:\"").concat(value, "\" was sanitized to: \"").concat(sanitizedAttrUrl, "\""));
  582. }
  583. newNode.setAttribute(name_1, sanitizedAttrUrl);
  584. break;
  585. case sanitizer_table_1.AttributePolicyAction.KEEP_AND_NORMALIZE:
  586. // We don't consider changing the case of an attribute value to be a
  587. // semantic change
  588. newNode.setAttribute(name_1, value.toLowerCase());
  589. break;
  590. case sanitizer_table_1.AttributePolicyAction.KEEP_AND_SANITIZE_STYLE:
  591. newNode.setAttribute(name_1, value);
  592. break;
  593. case sanitizer_table_1.AttributePolicyAction.DROP:
  594. this.recordChange("Attribute: ".concat(name_1, " was dropped"));
  595. break;
  596. default:
  597. checkExhaustive(policy.policyAction, 'Unhandled AttributePolicyAction case');
  598. }
  599. }
  600. }
  601. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  602. finally {
  603. try {
  604. if (dirtyAttributes_1_1 && !dirtyAttributes_1_1.done && (_a = dirtyAttributes_1.return)) _a.call(dirtyAttributes_1);
  605. }
  606. finally { if (e_1) throw e_1.error; }
  607. }
  608. return newNode;
  609. };
  610. HtmlSanitizerImpl.prototype.nodeFilter = function (node) {
  611. if ((0, no_clobber_1.isText)(node)) {
  612. return NodeFilter.FILTER_ACCEPT;
  613. }
  614. else if (!(0, no_clobber_1.isElement)(node)) {
  615. // Getting a node that is neither an `Element` or a `Text` node. This is
  616. // likely due to something that is not supposed to be an element in user
  617. // code but recognized as such by the TreeWalker (e.g. a polyfill for
  618. // other kind of nodes). Since we can't recognize it as an element, we
  619. // drop the node, but we don't record it as a meaningful change.
  620. return NodeFilter.FILTER_REJECT;
  621. }
  622. var nodeName = (0, no_clobber_1.getNodeName)(node);
  623. if (nodeName === null) {
  624. this.recordChange("Node name was null for node: ".concat(node));
  625. return NodeFilter.FILTER_REJECT;
  626. }
  627. if (this.sanitizerTable.isAllowedElement(nodeName)) {
  628. return NodeFilter.FILTER_ACCEPT;
  629. }
  630. this.recordChange("Element: ".concat(nodeName, " was dropped"));
  631. return NodeFilter.FILTER_REJECT;
  632. };
  633. HtmlSanitizerImpl.prototype.recordChange = function (errorMessage) {
  634. if (true) {
  635. this.changes.push(errorMessage);
  636. }
  637. else {}
  638. };
  639. HtmlSanitizerImpl.prototype.satisfiesAllConditions = function (conditions, attrs) {
  640. var e_2, _a;
  641. var _b;
  642. if (!conditions) {
  643. return true;
  644. }
  645. try {
  646. for (var conditions_1 = __values(conditions), conditions_1_1 = conditions_1.next(); !conditions_1_1.done; conditions_1_1 = conditions_1.next()) {
  647. var _c = __read(conditions_1_1.value, 2), attrName = _c[0], expectedValues = _c[1];
  648. var value = (_b = attrs.getNamedItem(attrName)) === null || _b === void 0 ? void 0 : _b.value;
  649. if (value && !expectedValues.has(value)) {
  650. return false;
  651. }
  652. }
  653. }
  654. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  655. finally {
  656. try {
  657. if (conditions_1_1 && !conditions_1_1.done && (_a = conditions_1.return)) _a.call(conditions_1);
  658. }
  659. finally { if (e_2) throw e_2.error; }
  660. }
  661. return true;
  662. };
  663. return HtmlSanitizerImpl;
  664. }());
  665. exports.HtmlSanitizerImpl = HtmlSanitizerImpl;
  666. var defaultHtmlSanitizer =
  667. /* #__PURE__ */ (function () { return new HtmlSanitizerImpl(default_sanitizer_table_1.defaultSanitizerTable, secrets_1.secretToken); })();
  668. /** Sanitizes untrusted html using the default sanitizer configuration. */
  669. function sanitizeHtml(html) {
  670. return defaultHtmlSanitizer.sanitize(html);
  671. }
  672. exports.sanitizeHtml = sanitizeHtml;
  673. /**
  674. * Sanitizes untrusted html using the default sanitizer configuration. Throws
  675. * an error if the html was changed.
  676. */
  677. function sanitizeHtmlAssertUnchanged(html) {
  678. return defaultHtmlSanitizer.sanitizeAssertUnchanged(html);
  679. }
  680. exports.sanitizeHtmlAssertUnchanged = sanitizeHtmlAssertUnchanged;
  681. /**
  682. * Sanitizes untrusted html using the default sanitizer configuration. Throws
  683. * an error if the html was changed.
  684. */
  685. function sanitizeHtmlToFragment(html) {
  686. return defaultHtmlSanitizer.sanitizeToFragment(html);
  687. }
  688. exports.sanitizeHtmlToFragment = sanitizeHtmlToFragment;
  689. function checkExhaustive(value, msg) {
  690. if (msg === void 0) { msg = "unexpected value ".concat(value, "!"); }
  691. throw new Error(msg);
  692. }
  693. /***/ }),
  694. /***/ "./node_modules/safevalues/builders/html_sanitizer/html_sanitizer_builder.js":
  695. /*!***********************************************************************************!*\
  696. !*** ./node_modules/safevalues/builders/html_sanitizer/html_sanitizer_builder.js ***!
  697. \***********************************************************************************/
  698. /*! no static exports found */
  699. /***/ (function(module, exports, __webpack_require__) {
  700. "use strict";
  701. /**
  702. * @license
  703. * SPDX-License-Identifier: Apache-2.0
  704. */
  705. var __values = (this && this.__values) || function(o) {
  706. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  707. if (m) return m.call(o);
  708. if (o && typeof o.length === "number") return {
  709. next: function () {
  710. if (o && i >= o.length) o = void 0;
  711. return { value: o && o[i++], done: !o };
  712. }
  713. };
  714. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  715. };
  716. var __read = (this && this.__read) || function (o, n) {
  717. var m = typeof Symbol === "function" && o[Symbol.iterator];
  718. if (!m) return o;
  719. var i = m.call(o), r, ar = [], e;
  720. try {
  721. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  722. }
  723. catch (error) { e = { error: error }; }
  724. finally {
  725. try {
  726. if (r && !r.done && (m = i["return"])) m.call(i);
  727. }
  728. finally { if (e) throw e.error; }
  729. }
  730. return ar;
  731. };
  732. Object.defineProperty(exports, "__esModule", { value: true });
  733. exports.HtmlSanitizerBuilder = void 0;
  734. var secrets_1 = __webpack_require__(/*! ../../internals/secrets */ "./node_modules/safevalues/internals/secrets.js");
  735. var html_sanitizer_1 = __webpack_require__(/*! ./html_sanitizer */ "./node_modules/safevalues/builders/html_sanitizer/html_sanitizer.js");
  736. var default_sanitizer_table_1 = __webpack_require__(/*! ./sanitizer_table/default_sanitizer_table */ "./node_modules/safevalues/builders/html_sanitizer/sanitizer_table/default_sanitizer_table.js");
  737. var sanitizer_table_1 = __webpack_require__(/*! ./sanitizer_table/sanitizer_table */ "./node_modules/safevalues/builders/html_sanitizer/sanitizer_table/sanitizer_table.js");
  738. /** This class allows modifications to the default sanitizer configuration. */
  739. var HtmlSanitizerBuilder = /** @class */ (function () {
  740. function HtmlSanitizerBuilder() {
  741. // To denote if the builder has called build() and therefore should make no
  742. // further changes to the sanitizer table.
  743. this.calledBuild = false;
  744. this.sanitizerTable = default_sanitizer_table_1.defaultSanitizerTable;
  745. }
  746. /** Builder option to restrict allowed elements to a smaller subset. */
  747. HtmlSanitizerBuilder.prototype.onlyAllowElements = function (elementSet) {
  748. var e_1, _a;
  749. var allowedElements = new Set();
  750. var allowedElementPolicies = new Map();
  751. try {
  752. for (var elementSet_1 = __values(elementSet), elementSet_1_1 = elementSet_1.next(); !elementSet_1_1.done; elementSet_1_1 = elementSet_1.next()) {
  753. var element = elementSet_1_1.value;
  754. element = element.toUpperCase();
  755. if (!this.sanitizerTable.isAllowedElement(element)) {
  756. throw new Error("Element: ".concat(element, ", is not allowed by html5_contract.textpb"));
  757. }
  758. var elementPolicy = this.sanitizerTable.elementPolicies.get(element);
  759. if (elementPolicy !== undefined) {
  760. allowedElementPolicies.set(element, elementPolicy);
  761. }
  762. else {
  763. allowedElements.add(element);
  764. }
  765. }
  766. }
  767. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  768. finally {
  769. try {
  770. if (elementSet_1_1 && !elementSet_1_1.done && (_a = elementSet_1.return)) _a.call(elementSet_1);
  771. }
  772. finally { if (e_1) throw e_1.error; }
  773. }
  774. this.sanitizerTable = new sanitizer_table_1.SanitizerTable(allowedElements, allowedElementPolicies, this.sanitizerTable.allowedGlobalAttributes, this.sanitizerTable.globalAttributePolicies);
  775. return this;
  776. };
  777. /**
  778. * Builder option to restrict allowed attributes to a smaller subset.
  779. *
  780. * If the attribute isn't currently allowed then it won't be added.
  781. */
  782. HtmlSanitizerBuilder.prototype.onlyAllowAttributes = function (attributeSet) {
  783. var e_2, _a, e_3, _b, e_4, _c;
  784. var allowedGlobalAttributes = new Set();
  785. var globalAttributePolicies = new Map();
  786. var elementPolicies = new Map();
  787. try {
  788. for (var attributeSet_1 = __values(attributeSet), attributeSet_1_1 = attributeSet_1.next(); !attributeSet_1_1.done; attributeSet_1_1 = attributeSet_1.next()) {
  789. var attribute = attributeSet_1_1.value;
  790. if (this.sanitizerTable.allowedGlobalAttributes.has(attribute)) {
  791. allowedGlobalAttributes.add(attribute);
  792. }
  793. if (this.sanitizerTable.globalAttributePolicies.has(attribute)) {
  794. globalAttributePolicies.set(attribute, this.sanitizerTable.globalAttributePolicies.get(attribute));
  795. }
  796. }
  797. }
  798. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  799. finally {
  800. try {
  801. if (attributeSet_1_1 && !attributeSet_1_1.done && (_a = attributeSet_1.return)) _a.call(attributeSet_1);
  802. }
  803. finally { if (e_2) throw e_2.error; }
  804. }
  805. try {
  806. for (var _d = __values(this.sanitizerTable
  807. .elementPolicies.entries()), _e = _d.next(); !_e.done; _e = _d.next()) {
  808. var _f = __read(_e.value, 2), elementName = _f[0], originalElementPolicy = _f[1];
  809. var newElementPolicy = new Map();
  810. try {
  811. for (var _g = (e_4 = void 0, __values(originalElementPolicy
  812. .entries())), _h = _g.next(); !_h.done; _h = _g.next()) {
  813. var _j = __read(_h.value, 2), attribute = _j[0], attributePolicy = _j[1];
  814. if (attributeSet.has(attribute)) {
  815. newElementPolicy.set(attribute, attributePolicy);
  816. }
  817. }
  818. }
  819. catch (e_4_1) { e_4 = { error: e_4_1 }; }
  820. finally {
  821. try {
  822. if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
  823. }
  824. finally { if (e_4) throw e_4.error; }
  825. }
  826. elementPolicies.set(elementName, newElementPolicy);
  827. }
  828. }
  829. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  830. finally {
  831. try {
  832. if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
  833. }
  834. finally { if (e_3) throw e_3.error; }
  835. }
  836. this.sanitizerTable = new sanitizer_table_1.SanitizerTable(this.sanitizerTable.allowedElements, elementPolicies, allowedGlobalAttributes, globalAttributePolicies);
  837. return this;
  838. };
  839. /**
  840. * Allows the set of data attributes passed.
  841. *
  842. * These values must be prefixed with "data-"
  843. *
  844. * If called with onlyAllowElements or onlyAllowAttributes, those methods must
  845. * be called first.
  846. */
  847. HtmlSanitizerBuilder.prototype.allowDataAttributes = function (attributes) {
  848. var e_5, _a;
  849. var allowedGlobalAttributes = new Set(this.sanitizerTable.allowedGlobalAttributes);
  850. try {
  851. for (var attributes_1 = __values(attributes), attributes_1_1 = attributes_1.next(); !attributes_1_1.done; attributes_1_1 = attributes_1.next()) {
  852. var attribute = attributes_1_1.value;
  853. if (attribute.indexOf('data-') !== 0) {
  854. throw new Error("data attribute: ".concat(attribute, " does not begin with the prefix \"data-\""));
  855. }
  856. allowedGlobalAttributes.add(attribute);
  857. }
  858. }
  859. catch (e_5_1) { e_5 = { error: e_5_1 }; }
  860. finally {
  861. try {
  862. if (attributes_1_1 && !attributes_1_1.done && (_a = attributes_1.return)) _a.call(attributes_1);
  863. }
  864. finally { if (e_5) throw e_5.error; }
  865. }
  866. this.sanitizerTable = new sanitizer_table_1.SanitizerTable(this.sanitizerTable.allowedElements, this.sanitizerTable.elementPolicies, allowedGlobalAttributes, this.sanitizerTable.globalAttributePolicies);
  867. return this;
  868. };
  869. /**
  870. * Preserves style attributes. Note that the sanitizer won't parse and
  871. * sanitize the values but keep them as they are. In particular this means
  872. * that the code will be able to call functions that could do undesirable
  873. * things (e.g. `url` to trigger a network request), as well as any custom
  874. * properties or functions defined by the application.
  875. */
  876. HtmlSanitizerBuilder.prototype.allowStyleAttributes = function () {
  877. var globalAttributePolicies = new Map(this.sanitizerTable.globalAttributePolicies);
  878. globalAttributePolicies.set('style', { policyAction: sanitizer_table_1.AttributePolicyAction.KEEP_AND_SANITIZE_STYLE });
  879. this.sanitizerTable = new sanitizer_table_1.SanitizerTable(this.sanitizerTable.allowedElements, this.sanitizerTable.elementPolicies, this.sanitizerTable.allowedGlobalAttributes, globalAttributePolicies);
  880. return this;
  881. };
  882. /**
  883. * Preserves the class attribute on all elements. This means contents can
  884. * adopt CSS styles from other page elements and possibly mask themselves as
  885. * legitimate UI elements, which can lead to phishing.
  886. */
  887. HtmlSanitizerBuilder.prototype.allowClassAttributes = function () {
  888. var globalAttributePolicies = new Map(this.sanitizerTable.globalAttributePolicies);
  889. globalAttributePolicies.set('class', { policyAction: sanitizer_table_1.AttributePolicyAction.KEEP });
  890. this.sanitizerTable = new sanitizer_table_1.SanitizerTable(this.sanitizerTable.allowedElements, this.sanitizerTable.elementPolicies, this.sanitizerTable.allowedGlobalAttributes, globalAttributePolicies);
  891. return this;
  892. };
  893. /**
  894. * Preserves id attributes. This carries moderate risk as it allows an
  895. * element to override other elements with the same ID.
  896. */
  897. HtmlSanitizerBuilder.prototype.allowIdAttributes = function () {
  898. var globalAttributePolicies = new Map(this.sanitizerTable.globalAttributePolicies);
  899. globalAttributePolicies.set('id', { policyAction: sanitizer_table_1.AttributePolicyAction.KEEP });
  900. this.sanitizerTable = new sanitizer_table_1.SanitizerTable(this.sanitizerTable.allowedElements, this.sanitizerTable.elementPolicies, this.sanitizerTable.allowedGlobalAttributes, globalAttributePolicies);
  901. return this;
  902. };
  903. HtmlSanitizerBuilder.prototype.build = function () {
  904. if (this.calledBuild) {
  905. throw new Error('this sanitizer has already called build');
  906. }
  907. this.calledBuild = true;
  908. return new html_sanitizer_1.HtmlSanitizerImpl(this.sanitizerTable, secrets_1.secretToken);
  909. };
  910. return HtmlSanitizerBuilder;
  911. }());
  912. exports.HtmlSanitizerBuilder = HtmlSanitizerBuilder;
  913. /***/ }),
  914. /***/ "./node_modules/safevalues/builders/html_sanitizer/inert_fragment.js":
  915. /*!***************************************************************************!*\
  916. !*** ./node_modules/safevalues/builders/html_sanitizer/inert_fragment.js ***!
  917. \***************************************************************************/
  918. /*! no static exports found */
  919. /***/ (function(module, exports, __webpack_require__) {
  920. "use strict";
  921. /**
  922. * @license
  923. * SPDX-License-Identifier: Apache-2.0
  924. */
  925. Object.defineProperty(exports, "__esModule", { value: true });
  926. exports.createInertFragment = void 0;
  927. var element_1 = __webpack_require__(/*! ../../dom/elements/element */ "./node_modules/safevalues/dom/elements/element.js");
  928. var html_impl_1 = __webpack_require__(/*! ../../internals/html_impl */ "./node_modules/safevalues/internals/html_impl.js");
  929. /**
  930. * Returns a fragment that contains the parsed HTML for `dirtyHtml` without
  931. * executing any of the potential payload.
  932. */
  933. function createInertFragment(dirtyHtml) {
  934. var template = document.createElement('template');
  935. // This call is only used to create an inert tree for the sanitizer to
  936. // further process and is never returned directly to the caller. We can't use
  937. // a reviewed conversion in order to avoid an import loop.
  938. var temporarySafeHtml = (0, html_impl_1.createHtml)(dirtyHtml);
  939. (0, element_1.setInnerHtml)(template, temporarySafeHtml);
  940. return template.content;
  941. }
  942. exports.createInertFragment = createInertFragment;
  943. /***/ }),
  944. /***/ "./node_modules/safevalues/builders/html_sanitizer/no_clobber.js":
  945. /*!***********************************************************************!*\
  946. !*** ./node_modules/safevalues/builders/html_sanitizer/no_clobber.js ***!
  947. \***********************************************************************/
  948. /*! no static exports found */
  949. /***/ (function(module, exports, __webpack_require__) {
  950. "use strict";
  951. /**
  952. * @license
  953. * SPDX-License-Identifier: Apache-2.0
  954. */
  955. Object.defineProperty(exports, "__esModule", { value: true });
  956. exports.isElement = exports.isText = exports.getNodeName = void 0;
  957. /**
  958. * Library that provides safe getters for different node properties and
  959. * checks for clobbering.
  960. */
  961. /** Gets a reasonable nodeName, even for clobbered nodes. */
  962. function getNodeName(node) {
  963. var nodeName = node.nodeName;
  964. // If the property is clobbered, assume it is an `HTMLFormElement`.
  965. return (typeof nodeName === 'string') ? nodeName : 'FORM';
  966. }
  967. exports.getNodeName = getNodeName;
  968. /** Returns true if the object passed is a Text node. */
  969. function isText(node) {
  970. // The property cannot get clobbered on Text nodes.
  971. return node.nodeType === Node.TEXT_NODE;
  972. }
  973. exports.isText = isText;
  974. /** Returns true if the object passed is an Element node. */
  975. function isElement(node) {
  976. var nodeType = node.nodeType;
  977. // If the property is clobbered, we can assume it is an `HTMLFormElement`, and
  978. // thus an `Element`.
  979. return (nodeType === Node.ELEMENT_NODE) || (typeof nodeType !== 'number');
  980. }
  981. exports.isElement = isElement;
  982. /***/ }),
  983. /***/ "./node_modules/safevalues/builders/html_sanitizer/sanitizer_table/default_sanitizer_table.js":
  984. /*!****************************************************************************************************!*\
  985. !*** ./node_modules/safevalues/builders/html_sanitizer/sanitizer_table/default_sanitizer_table.js ***!
  986. \****************************************************************************************************/
  987. /*! no static exports found */
  988. /***/ (function(module, exports, __webpack_require__) {
  989. "use strict";
  990. /**
  991. * @license
  992. * SPDX-License-Identifier: Apache-2.0
  993. */
  994. Object.defineProperty(exports, "__esModule", { value: true });
  995. exports.defaultSanitizerTable = void 0;
  996. var sanitizer_table_1 = __webpack_require__(/*! ./sanitizer_table */ "./node_modules/safevalues/builders/html_sanitizer/sanitizer_table/sanitizer_table.js");
  997. /**
  998. * GENERATED CODE, DO NOT MODIFY
  999. * This SanitizerTable was generated from the checked in html contract:
  1000. * webutil/html/types/codegen/html5_contract.textpb
  1001. *
  1002. * You can regenerate this file with:
  1003. * webutil/html/types/codegen/update_generated_source_files.sh
  1004. */
  1005. exports.defaultSanitizerTable = new sanitizer_table_1.SanitizerTable(new Set([
  1006. 'ARTICLE', 'SECTION', 'NAV', 'ASIDE', 'H1', 'H2',
  1007. 'H3', 'H4', 'H5', 'H6', 'HEADER', 'FOOTER',
  1008. 'ADDRESS', 'P', 'HR', 'PRE', 'BLOCKQUOTE', 'OL',
  1009. 'UL', 'LH', 'LI', 'DL', 'DT', 'DD',
  1010. 'FIGURE', 'FIGCAPTION', 'MAIN', 'DIV', 'EM', 'STRONG',
  1011. 'SMALL', 'S', 'CITE', 'Q', 'DFN', 'ABBR',
  1012. 'RUBY', 'RB', 'RT', 'RTC', 'RP', 'DATA',
  1013. 'TIME', 'CODE', 'VAR', 'SAMP', 'KBD', 'SUB',
  1014. 'SUP', 'I', 'B', 'U', 'MARK', 'BDI',
  1015. 'BDO', 'SPAN', 'BR', 'WBR', 'INS', 'DEL',
  1016. 'PICTURE', 'PARAM', 'TRACK', 'MAP', 'TABLE', 'CAPTION',
  1017. 'COLGROUP', 'COL', 'TBODY', 'THEAD', 'TFOOT', 'TR',
  1018. 'TD', 'TH', 'SELECT', 'DATALIST', 'OPTGROUP', 'OPTION',
  1019. 'OUTPUT', 'PROGRESS', 'METER', 'FIELDSET', 'LEGEND', 'DETAILS',
  1020. 'SUMMARY', 'MENU', 'DIALOG', 'SLOT', 'CANVAS', 'FONT',
  1021. 'CENTER',
  1022. ]), new Map([
  1023. [
  1024. 'A', new Map([
  1025. ['href', { policyAction: sanitizer_table_1.AttributePolicyAction.KEEP_AND_SANITIZE_URL }],
  1026. ])
  1027. ],
  1028. [
  1029. 'AREA', new Map([
  1030. ['href', { policyAction: sanitizer_table_1.AttributePolicyAction.KEEP_AND_SANITIZE_URL }],
  1031. ])
  1032. ],
  1033. [
  1034. 'LINK', new Map([
  1035. [
  1036. 'href', {
  1037. policyAction: sanitizer_table_1.AttributePolicyAction.KEEP_AND_SANITIZE_URL,
  1038. conditions: new Map([[
  1039. 'rel', new Set([
  1040. 'alternate',
  1041. 'author',
  1042. 'bookmark',
  1043. 'canonical',
  1044. 'cite',
  1045. 'help',
  1046. 'icon',
  1047. 'license',
  1048. 'next',
  1049. 'prefetch',
  1050. 'dns-prefetch',
  1051. 'prerender',
  1052. 'preconnect',
  1053. 'preload',
  1054. 'prev',
  1055. 'search',
  1056. 'subresource',
  1057. ])
  1058. ]])
  1059. }
  1060. ],
  1061. ])
  1062. ],
  1063. [
  1064. 'SOURCE', new Map([
  1065. ['src', { policyAction: sanitizer_table_1.AttributePolicyAction.KEEP_AND_SANITIZE_URL }],
  1066. ])
  1067. ],
  1068. [
  1069. 'IMG', new Map([
  1070. ['src', { policyAction: sanitizer_table_1.AttributePolicyAction.KEEP_AND_SANITIZE_URL }],
  1071. ])
  1072. ],
  1073. [
  1074. 'VIDEO', new Map([
  1075. ['src', { policyAction: sanitizer_table_1.AttributePolicyAction.KEEP_AND_SANITIZE_URL }],
  1076. ])
  1077. ],
  1078. [
  1079. 'AUDIO', new Map([
  1080. ['src', { policyAction: sanitizer_table_1.AttributePolicyAction.KEEP_AND_SANITIZE_URL }],
  1081. ])
  1082. ],
  1083. ]), new Set([
  1084. 'title',
  1085. 'aria-atomic',
  1086. 'aria-autocomplete',
  1087. 'aria-busy',
  1088. 'aria-checked',
  1089. 'aria-current',
  1090. 'aria-disabled',
  1091. 'aria-dropeffect',
  1092. 'aria-expanded',
  1093. 'aria-haspopup',
  1094. 'aria-hidden',
  1095. 'aria-invalid',
  1096. 'aria-label',
  1097. 'aria-level',
  1098. 'aria-live',
  1099. 'aria-multiline',
  1100. 'aria-multiselectable',
  1101. 'aria-orientation',
  1102. 'aria-posinset',
  1103. 'aria-pressed',
  1104. 'aria-readonly',
  1105. 'aria-relevant',
  1106. 'aria-required',
  1107. 'aria-selected',
  1108. 'aria-setsize',
  1109. 'aria-sort',
  1110. 'aria-valuemax',
  1111. 'aria-valuemin',
  1112. 'aria-valuenow',
  1113. 'aria-valuetext',
  1114. 'alt',
  1115. 'align',
  1116. 'autocapitalize',
  1117. 'autocomplete',
  1118. 'autocorrect',
  1119. 'autofocus',
  1120. 'autoplay',
  1121. 'bgcolor',
  1122. 'border',
  1123. 'cellpadding',
  1124. 'cellspacing',
  1125. 'checked',
  1126. 'color',
  1127. 'cols',
  1128. 'colspan',
  1129. 'controls',
  1130. 'datetime',
  1131. 'disabled',
  1132. 'download',
  1133. 'draggable',
  1134. 'enctype',
  1135. 'face',
  1136. 'formenctype',
  1137. 'frameborder',
  1138. 'height',
  1139. 'hreflang',
  1140. 'hidden',
  1141. 'ismap',
  1142. 'label',
  1143. 'lang',
  1144. 'loop',
  1145. 'max',
  1146. 'maxlength',
  1147. 'media',
  1148. 'minlength',
  1149. 'min',
  1150. 'multiple',
  1151. 'muted',
  1152. 'nonce',
  1153. 'open',
  1154. 'placeholder',
  1155. 'preload',
  1156. 'rel',
  1157. 'required',
  1158. 'reversed',
  1159. 'role',
  1160. 'rows',
  1161. 'rowspan',
  1162. 'selected',
  1163. 'shape',
  1164. 'size',
  1165. 'sizes',
  1166. 'slot',
  1167. 'span',
  1168. 'spellcheck',
  1169. 'start',
  1170. 'step',
  1171. 'summary',
  1172. 'translate',
  1173. 'type',
  1174. 'valign',
  1175. 'value',
  1176. 'width',
  1177. 'wrap',
  1178. 'itemscope',
  1179. 'itemtype',
  1180. 'itemid',
  1181. 'itemprop',
  1182. 'itemref',
  1183. ]), new Map([
  1184. [
  1185. 'dir', {
  1186. policyAction: sanitizer_table_1.AttributePolicyAction.KEEP_AND_NORMALIZE,
  1187. conditions: new Map([[
  1188. 'dir', new Set([
  1189. 'auto',
  1190. 'ltr',
  1191. 'rtl',
  1192. ])
  1193. ]])
  1194. }
  1195. ],
  1196. [
  1197. 'async', {
  1198. policyAction: sanitizer_table_1.AttributePolicyAction.KEEP_AND_NORMALIZE,
  1199. conditions: new Map([[
  1200. 'async', new Set([
  1201. 'async',
  1202. ])
  1203. ]])
  1204. }
  1205. ],
  1206. ['cite', { policyAction: sanitizer_table_1.AttributePolicyAction.KEEP_AND_SANITIZE_URL }],
  1207. [
  1208. 'loading', {
  1209. policyAction: sanitizer_table_1.AttributePolicyAction.KEEP_AND_NORMALIZE,
  1210. conditions: new Map([[
  1211. 'loading', new Set([
  1212. 'eager',
  1213. 'lazy',
  1214. ])
  1215. ]])
  1216. }
  1217. ],
  1218. ['poster', { policyAction: sanitizer_table_1.AttributePolicyAction.KEEP_AND_SANITIZE_URL }],
  1219. [
  1220. 'target', {
  1221. policyAction: sanitizer_table_1.AttributePolicyAction.KEEP_AND_NORMALIZE,
  1222. conditions: new Map([[
  1223. 'target', new Set([
  1224. '_self',
  1225. '_blank',
  1226. ])
  1227. ]])
  1228. }
  1229. ],
  1230. ]));
  1231. /***/ }),
  1232. /***/ "./node_modules/safevalues/builders/html_sanitizer/sanitizer_table/sanitizer_table.js":
  1233. /*!********************************************************************************************!*\
  1234. !*** ./node_modules/safevalues/builders/html_sanitizer/sanitizer_table/sanitizer_table.js ***!
  1235. \********************************************************************************************/
  1236. /*! no static exports found */
  1237. /***/ (function(module, exports, __webpack_require__) {
  1238. "use strict";
  1239. /**
  1240. * @license
  1241. * SPDX-License-Identifier: Apache-2.0
  1242. */
  1243. Object.defineProperty(exports, "__esModule", { value: true });
  1244. exports.AttributePolicyAction = exports.SanitizerTable = void 0;
  1245. /** Class for holding element and attribute policies used for sanitization. */
  1246. var SanitizerTable = /** @class */ (function () {
  1247. function SanitizerTable(allowedElements, elementPolicies, allowedGlobalAttributes, globalAttributePolicies) {
  1248. this.allowedElements = allowedElements;
  1249. this.elementPolicies = elementPolicies;
  1250. this.allowedGlobalAttributes = allowedGlobalAttributes;
  1251. this.globalAttributePolicies = globalAttributePolicies;
  1252. }
  1253. SanitizerTable.prototype.isAllowedElement = function (elementName) {
  1254. // Note: `HTMLFormElement`s are always dropped, supporting them is very
  1255. // costly because of the DOM clobberring they can cause. The additional code
  1256. // size required to properly work around DOM clobberring issues is large and
  1257. // shouldn't be put on every user of the sanitizer. Thoroughly review
  1258. // b/210975025 and the CLs linked there before you start allowing form
  1259. // elements.
  1260. return elementName.toLowerCase() !== 'form' &&
  1261. (this.allowedElements.has(elementName) ||
  1262. this.elementPolicies.has(elementName));
  1263. };
  1264. SanitizerTable.prototype.getAttributePolicy = function (attributeName, elementName) {
  1265. var elementPolicy = this.elementPolicies.get(elementName);
  1266. if (elementPolicy === null || elementPolicy === void 0 ? void 0 : elementPolicy.has(attributeName)) {
  1267. return elementPolicy.get(attributeName);
  1268. }
  1269. if (this.allowedGlobalAttributes.has(attributeName)) {
  1270. return { policyAction: AttributePolicyAction.KEEP };
  1271. }
  1272. var globalPolicy = this.globalAttributePolicies.get(attributeName);
  1273. return globalPolicy || { policyAction: AttributePolicyAction.DROP };
  1274. };
  1275. return SanitizerTable;
  1276. }());
  1277. exports.SanitizerTable = SanitizerTable;
  1278. /**
  1279. * Values derived from
  1280. * https://godoc.corp.google.com/pkg/google3/third_party/safehtml/sanitizer/policy#AttributePolicy
  1281. */
  1282. var AttributePolicyAction;
  1283. (function (AttributePolicyAction) {
  1284. AttributePolicyAction[AttributePolicyAction["DROP"] = 0] = "DROP";
  1285. AttributePolicyAction[AttributePolicyAction["KEEP"] = 1] = "KEEP";
  1286. AttributePolicyAction[AttributePolicyAction["KEEP_AND_SANITIZE_URL"] = 2] = "KEEP_AND_SANITIZE_URL";
  1287. AttributePolicyAction[AttributePolicyAction["KEEP_AND_NORMALIZE"] = 3] = "KEEP_AND_NORMALIZE";
  1288. AttributePolicyAction[AttributePolicyAction["KEEP_AND_SANITIZE_STYLE"] = 4] = "KEEP_AND_SANITIZE_STYLE";
  1289. })(AttributePolicyAction = exports.AttributePolicyAction || (exports.AttributePolicyAction = {}));
  1290. /***/ }),
  1291. /***/ "./node_modules/safevalues/builders/resource_url_builders.js":
  1292. /*!*******************************************************************!*\
  1293. !*** ./node_modules/safevalues/builders/resource_url_builders.js ***!
  1294. \*******************************************************************/
  1295. /*! no static exports found */
  1296. /***/ (function(module, exports, __webpack_require__) {
  1297. "use strict";
  1298. /**
  1299. * @license
  1300. * SPDX-License-Identifier: Apache-2.0
  1301. */
  1302. Object.defineProperty(exports, "__esModule", { value: true });
  1303. exports.blobUrlFromScript = exports.replaceFragment = exports.appendParams = exports.trustedResourceUrl = void 0;
  1304. __webpack_require__(/*! ../environment/dev */ "./node_modules/safevalues/environment/dev.js");
  1305. var resource_url_impl_1 = __webpack_require__(/*! ../internals/resource_url_impl */ "./node_modules/safevalues/internals/resource_url_impl.js");
  1306. var script_impl_1 = __webpack_require__(/*! ../internals/script_impl */ "./node_modules/safevalues/internals/script_impl.js");
  1307. var string_literal_1 = __webpack_require__(/*! ../internals/string_literal */ "./node_modules/safevalues/internals/string_literal.js");
  1308. /**
  1309. * Check whether the base url contains a valid origin,
  1310. *
  1311. * A string for an origin must contain only alphanumeric or any of the
  1312. * following: `-.:`, and must not be an IP address. Remember that, as per the
  1313. * documentation for TrustedResourceUrl, the origin must be trustworthy.
  1314. *
  1315. * @param base The base url that contains an origin.
  1316. */
  1317. function hasValidOrigin(base) {
  1318. if (!(/^https:\/\//.test(base) || /^\/\//.test(base))) {
  1319. return false;
  1320. }
  1321. var originStart = base.indexOf('//') + 2;
  1322. var originEnd = base.indexOf('/', originStart);
  1323. // If the base url only contains the prefix (e.g. //), or the slash
  1324. // for the origin is right after the prefix (e.g. ///), the origin is
  1325. // missing.
  1326. if (originEnd <= originStart) {
  1327. throw new Error("Can't interpolate data in a url's origin, " +
  1328. "Please make sure to fully specify the origin, terminated with '/'.");
  1329. }
  1330. var origin = base.substring(originStart, originEnd);
  1331. if (!/^[0-9a-z.:-]+$/i.test(origin)) {
  1332. throw new Error('The origin contains unsupported characters.');
  1333. }
  1334. if (!/^[^:]*(:[0-9]+)?$/i.test(origin)) {
  1335. throw new Error('Invalid port number.');
  1336. }
  1337. if (!/(^|\.)[a-z][^.]*$/i.test(origin)) {
  1338. throw new Error('The top-level domain must start with a letter.');
  1339. }
  1340. return true;
  1341. }
  1342. /**
  1343. * Check whether the base url contains a valid about url at its beginning.
  1344. *
  1345. * An about url is either exactly 'about:blank' or 'about:blank#<str>' where
  1346. * <str> can be an arbitrary string.
  1347. *
  1348. * @param base The base url.
  1349. */
  1350. function isValidAboutUrl(base) {
  1351. if (!/^about:blank/.test(base)) {
  1352. return false;
  1353. }
  1354. if (base !== 'about:blank' && !/^about:blank#/.test(base)) {
  1355. throw new Error('The about url is invalid.');
  1356. }
  1357. return true;
  1358. }
  1359. /**
  1360. * Check whether the base url contains a valid path start at its beginning.
  1361. *
  1362. * A valid path start is either a '/' or a '/' followed by at least one
  1363. * character that is not '/' or '\'.
  1364. *
  1365. * @param base The base url.
  1366. */
  1367. function isValidPathStart(base) {
  1368. if (!/^\//.test(base)) {
  1369. return false;
  1370. }
  1371. if ((base === '/') ||
  1372. (base.length > 1 && base[1] !== '/' && base[1] !== '\\')) {
  1373. return true;
  1374. }
  1375. throw new Error('The path start in the url is invalid.');
  1376. }
  1377. /**
  1378. * Builds TrustedResourceUrl from a template literal.
  1379. *
  1380. * This factory is a template literal tag function. It should be called with
  1381. * a template literal, with or without embedded expressions. For example,
  1382. * trustedResourceUrl`//example.com/${bar}`;
  1383. * or
  1384. * trustedResourceUrl`//example.com`;
  1385. *
  1386. * When this function is called with a template literal without any embedded
  1387. * expressions, the template string may contain anything as the whole URL is
  1388. * a compile-time string constant.
  1389. *
  1390. * When this function is called with a template literal that contains embedded
  1391. * expressions, the template must start with one of the following:
  1392. * - `https://<origin>/`
  1393. * - `//<origin>/`
  1394. * - `/<pathStart>`
  1395. * - `about:blank`
  1396. * - `data:`
  1397. *
  1398. * `<origin>` must contain only alphanumeric or any of the following: `-.:`.
  1399. * Remember that, as per the documentation for TrustedResourceUrl, the origin
  1400. * must be trustworthy. An origin of "example.com" could be set with this
  1401. * method, but would tie the security of your site to the security of
  1402. * example.com. Similarly, formats that potentially cover redirects hosted
  1403. * on a trusted origin are problematic, since that could lead to untrusted
  1404. * origins.
  1405. *
  1406. * `<pathStart>` is either an empty string, or a non empty string that does not
  1407. * start with '/' or '\'.
  1408. * In other words, `/<pathStart>` is either a '/' or a
  1409. * '/' followed by at least one character that is not '/' or '\'.
  1410. *
  1411. * `data:` (data URL) does not allow embedded expressions in the template
  1412. * literal input.
  1413. *
  1414. * All embedded expressions are URL encoded when they are interpolated. Do not
  1415. * embed expressions that are already URL encoded as they will be double encoded
  1416. * by the builder.
  1417. *
  1418. * @param templateObj This contains the literal part of the template literal.
  1419. * @param rest This represents the template's embedded expressions.
  1420. */
  1421. function trustedResourceUrl(templateObj) {
  1422. var rest = [];
  1423. for (var _i = 1; _i < arguments.length; _i++) {
  1424. rest[_i - 1] = arguments[_i];
  1425. }
  1426. // Check if templateObj is actually from a template literal.
  1427. if (true) {
  1428. (0, string_literal_1.assertIsTemplateObject)(templateObj, true, 'trustedResourceUrl is a template literal tag function and ' +
  1429. 'can only be called as such (e.g. trustedResourceUrl`/somepath.js`)');
  1430. }
  1431. if (rest.length === 0) {
  1432. return (0, resource_url_impl_1.createResourceUrl)(templateObj[0]);
  1433. }
  1434. var base = templateObj[0].toLowerCase();
  1435. if (true) {
  1436. if (/^data:/.test(base)) {
  1437. throw new Error('Data URLs cannot have expressions in the template literal input.');
  1438. }
  1439. if (!hasValidOrigin(base) && !isValidPathStart(base) &&
  1440. !isValidAboutUrl(base)) {
  1441. throw new Error('Trying to interpolate expressions in an unsupported url format.');
  1442. }
  1443. }
  1444. var urlParts = [templateObj[0]];
  1445. for (var i = 0; i < rest.length; i++) {
  1446. urlParts.push(encodeURIComponent(rest[i]));
  1447. urlParts.push(templateObj[i + 1]);
  1448. }
  1449. return (0, resource_url_impl_1.createResourceUrl)(urlParts.join(''));
  1450. }
  1451. exports.trustedResourceUrl = trustedResourceUrl;
  1452. /**
  1453. * Creates a new TrustedResourceUrl with params added to the URL's search
  1454. * parameters.
  1455. *
  1456. * @param params What to add to the URL. Parameters with value `null` or
  1457. * `undefined` are skipped. Both keys and values will be encoded. Do not pass
  1458. * pre-encoded values as this will result them being double encoded. If the
  1459. * value is an array then the same parameter is added for every element in the
  1460. * array.
  1461. */
  1462. function appendParams(trustedUrl, params) {
  1463. var url = (0, resource_url_impl_1.unwrapResourceUrl)(trustedUrl).toString();
  1464. if (/#/.test(url)) {
  1465. var message = '';
  1466. if (true) {
  1467. message = "Found a hash in url (".concat(url, "), appending not supported");
  1468. }
  1469. throw new Error(message);
  1470. }
  1471. var separator = /\?/.test(url) ? '&' : '?';
  1472. // for-of has a big polyfill.
  1473. // tslint:disable-next-line:ban-iterable-foreach
  1474. params.forEach(function (value, key) {
  1475. var values = (value instanceof Array) ? value : [value];
  1476. for (var i = 0; i < values.length; i++) {
  1477. var v = values[i];
  1478. if (v === null || v === undefined) {
  1479. continue;
  1480. }
  1481. url += separator + encodeURIComponent(key) + '=' +
  1482. encodeURIComponent(String(v));
  1483. separator = '&';
  1484. }
  1485. });
  1486. return (0, resource_url_impl_1.createResourceUrl)(url);
  1487. }
  1488. exports.appendParams = appendParams;
  1489. var BEFORE_FRAGMENT_REGEXP = /[^#]*/;
  1490. /**
  1491. * Creates a new TrustedResourceUrl based on an existing one but with the
  1492. * addition of a fragment (the part after `#`). If the URL already has a
  1493. * fragment, it is replaced with the new one.
  1494. * @param fragment The fragment to add to the URL, verbatim, without the leading
  1495. * `#`. No additional escaping is applied.
  1496. */
  1497. function replaceFragment(trustedUrl, fragment) {
  1498. var urlString = (0, resource_url_impl_1.unwrapResourceUrl)(trustedUrl).toString();
  1499. return (0, resource_url_impl_1.createResourceUrl)(BEFORE_FRAGMENT_REGEXP.exec(urlString)[0] + '#' + fragment);
  1500. }
  1501. exports.replaceFragment = replaceFragment;
  1502. /**
  1503. * Creates a `TrustedResourceUrl` by generating a `Blob` from a
  1504. * `SafeScript` and then calling `URL.createObjectURL` with that `Blob`.
  1505. *
  1506. * Caller must call `URL.revokeObjectUrl()` on the stringified url to
  1507. * release the underlying `Blob`.
  1508. */
  1509. function blobUrlFromScript(safeScript) {
  1510. var scriptContent = (0, script_impl_1.unwrapScript)(safeScript).toString();
  1511. var blob = new Blob([scriptContent], { type: 'text/javascript' });
  1512. return (0, resource_url_impl_1.createResourceUrl)(URL.createObjectURL(blob));
  1513. }
  1514. exports.blobUrlFromScript = blobUrlFromScript;
  1515. /***/ }),
  1516. /***/ "./node_modules/safevalues/builders/script_builders.js":
  1517. /*!*************************************************************!*\
  1518. !*** ./node_modules/safevalues/builders/script_builders.js ***!
  1519. \*************************************************************/
  1520. /*! no static exports found */
  1521. /***/ (function(module, exports, __webpack_require__) {
  1522. "use strict";
  1523. /**
  1524. * @license
  1525. * SPDX-License-Identifier: Apache-2.0
  1526. */
  1527. Object.defineProperty(exports, "__esModule", { value: true });
  1528. exports.safeScriptWithArgs = exports.scriptFromJson = exports.concatScripts = exports.safeScript = void 0;
  1529. __webpack_require__(/*! ../environment/dev */ "./node_modules/safevalues/environment/dev.js");
  1530. var script_impl_1 = __webpack_require__(/*! ../internals/script_impl */ "./node_modules/safevalues/internals/script_impl.js");
  1531. var string_literal_1 = __webpack_require__(/*! ../internals/string_literal */ "./node_modules/safevalues/internals/string_literal.js");
  1532. /**
  1533. * Creates a SafeScript object from a template literal (without any embedded
  1534. * expressions).
  1535. *
  1536. * This function is a template literal tag function. It should be called with
  1537. * a template literal that does not contain any expressions. For example,
  1538. * safeScript`foo`;
  1539. *
  1540. * @param templateObj This contains the literal part of the template literal.
  1541. */
  1542. function safeScript(templateObj) {
  1543. if (true) {
  1544. (0, string_literal_1.assertIsTemplateObject)(templateObj, false, 'safeScript is a template literal tag function ' +
  1545. 'that only accepts template literals without expressions. ' +
  1546. 'For example, safeScript`foo`;');
  1547. }
  1548. return (0, script_impl_1.createScript)(templateObj[0]);
  1549. }
  1550. exports.safeScript = safeScript;
  1551. /** Creates a `SafeScript` value by concatenating multiple `SafeScript`s. */
  1552. function concatScripts(scripts) {
  1553. return (0, script_impl_1.createScript)(scripts.map(script_impl_1.unwrapScript).join(''));
  1554. }
  1555. exports.concatScripts = concatScripts;
  1556. /**
  1557. * Converts a serializable value into JSON that is safe to interpolate into a
  1558. * script context. In particular it escapes < characters so that a value of
  1559. * "</script>" doesn't break out of the context.
  1560. * @param value The value to serialize.
  1561. */
  1562. function scriptFromJson(value) {
  1563. return (0, script_impl_1.createScript)(JSON.stringify(value).replace(/</g, '\\x3c'));
  1564. }
  1565. exports.scriptFromJson = scriptFromJson;
  1566. /**
  1567. * Creates a `SafeScript` object from a template literal (without any embedded
  1568. * expressions) along with additional arguments that the script should have
  1569. * access to. These arguments will be JSON-encoded and passed to the script as
  1570. * a function call.
  1571. * @example
  1572. * ```ts
  1573. * safeScriptWithArgs`function (name, props) {
  1574. * console.log(name + ' is ' + props.age);
  1575. * }`('Bob', { 'age': 42 })
  1576. * ```
  1577. * would return a `SafeScript` that represents the following code:
  1578. * ```js
  1579. * (function (name, props) {
  1580. * console.log(name + ' is ' + props.age);
  1581. * })("Bob",{"age":42})
  1582. * ```
  1583. * @note Be careful when passing objects as arguments, as unquoted property
  1584. * names may be changed during compilation.
  1585. * @param templateObj This contains the literal part of the template literal.
  1586. * @param emptyArgs Expressions that evaluate to the empty string to enable
  1587. * inline comments.
  1588. */
  1589. function safeScriptWithArgs(templateObj) {
  1590. var emptyArgs = [];
  1591. for (var _i = 1; _i < arguments.length; _i++) {
  1592. emptyArgs[_i - 1] = arguments[_i];
  1593. }
  1594. if (true) {
  1595. if (emptyArgs.some(function (a) { return a !== ''; })) {
  1596. throw new Error('safeScriptWithArgs only allows empty string expressions ' +
  1597. 'to enable inline comments.');
  1598. }
  1599. (0, string_literal_1.assertIsTemplateObject)(templateObj, true, 'safeScriptWithArgs is a template literal tag function ' +
  1600. 'that only accepts template literals. ' +
  1601. 'For example, safeScriptWithArgs`foo`;');
  1602. }
  1603. return function () {
  1604. var argValues = [];
  1605. for (var _i = 0; _i < arguments.length; _i++) {
  1606. argValues[_i] = arguments[_i];
  1607. }
  1608. var values = argValues.map(function (v) { return scriptFromJson(v).toString(); });
  1609. return (0, script_impl_1.createScript)("(".concat(templateObj.join(''), ")(").concat(values.join(','), ")"));
  1610. };
  1611. }
  1612. exports.safeScriptWithArgs = safeScriptWithArgs;
  1613. /***/ }),
  1614. /***/ "./node_modules/safevalues/builders/sensitive_attributes.js":
  1615. /*!******************************************************************!*\
  1616. !*** ./node_modules/safevalues/builders/sensitive_attributes.js ***!
  1617. \******************************************************************/
  1618. /*! no static exports found */
  1619. /***/ (function(module, exports, __webpack_require__) {
  1620. "use strict";
  1621. /**
  1622. * @license
  1623. * SPDX-License-Identifier: Apache-2.0
  1624. */
  1625. Object.defineProperty(exports, "__esModule", { value: true });
  1626. exports.SECURITY_SENSITIVE_ATTRIBUTES = void 0;
  1627. // AUTOGENERATED. DO NOT EDIT.
  1628. /**
  1629. * Security sensitive attribute names that should not be set through
  1630. * `setAttribute` or similar functions.
  1631. */
  1632. exports.SECURITY_SENSITIVE_ATTRIBUTES = [
  1633. 'href',
  1634. 'rel',
  1635. 'src',
  1636. 'srcdoc',
  1637. 'action',
  1638. 'formaction',
  1639. 'sandbox',
  1640. 'cite',
  1641. 'poster',
  1642. 'icon',
  1643. ];
  1644. /***/ }),
  1645. /***/ "./node_modules/safevalues/builders/style_builders.js":
  1646. /*!************************************************************!*\
  1647. !*** ./node_modules/safevalues/builders/style_builders.js ***!
  1648. \************************************************************/
  1649. /*! no static exports found */
  1650. /***/ (function(module, exports, __webpack_require__) {
  1651. "use strict";
  1652. /**
  1653. * @license
  1654. * SPDX-License-Identifier: Apache-2.0
  1655. */
  1656. Object.defineProperty(exports, "__esModule", { value: true });
  1657. exports.concatStyles = exports.safeStyle = void 0;
  1658. __webpack_require__(/*! ../environment/dev */ "./node_modules/safevalues/environment/dev.js");
  1659. var string_literal_1 = __webpack_require__(/*! ../internals/string_literal */ "./node_modules/safevalues/internals/string_literal.js");
  1660. var style_impl_1 = __webpack_require__(/*! ../internals/style_impl */ "./node_modules/safevalues/internals/style_impl.js");
  1661. /**
  1662. * Creates a SafeStyle object from a template literal (without any embedded
  1663. * expressions).
  1664. *
  1665. * ` style` should be in the format
  1666. * ` name: value; [name: value; ...]` and must not have any < or >
  1667. * characters in it. This is so that SafeStyle's contract is preserved,
  1668. * allowing the SafeStyle to correctly be interpreted as a sequence of CSS
  1669. * declarations and without affecting the syntactic structure of any
  1670. * surrounding CSS and HTML.
  1671. *
  1672. * This function is a template literal tag function. It should be called with
  1673. * a template literal that does not contain any expressions. For example,
  1674. * safeStyle`foo`;
  1675. * This function first checks if it is called with a literal template, and
  1676. * then performs basic sanity checks on the format of ` style`
  1677. * but does not constrain the format of ` name} and {@code value`, except
  1678. * for disallowing tag characters.
  1679. *
  1680. * @param templateObj This contains the literal part of the template literal.
  1681. */
  1682. function safeStyle(templateObj) {
  1683. if (true) {
  1684. (0, string_literal_1.assertIsTemplateObject)(templateObj, false, 'safeStyle is a template literal tag function ' +
  1685. 'that only accepts template literals without expressions. ' +
  1686. 'For example, safeStyle`foo`;');
  1687. }
  1688. var style = templateObj[0];
  1689. if (true) {
  1690. if (/[<>]/.test(style)) {
  1691. throw new Error('Forbidden characters in style string: ' + style);
  1692. }
  1693. if (!/;$/.test(style)) {
  1694. throw new Error('Style string does not end with ";": ' + style);
  1695. }
  1696. if (!/:/.test(style)) {
  1697. throw new Error('Style string should contain one or more ":": ' + style);
  1698. }
  1699. }
  1700. return (0, style_impl_1.createStyle)(style);
  1701. }
  1702. exports.safeStyle = safeStyle;
  1703. /** Creates a `SafeStyle` value by concatenating multiple `SafeStyle`s. */
  1704. function concatStyles(styles) {
  1705. return (0, style_impl_1.createStyle)(styles.map(style_impl_1.unwrapStyle).join(''));
  1706. }
  1707. exports.concatStyles = concatStyles;
  1708. /***/ }),
  1709. /***/ "./node_modules/safevalues/builders/style_sheet_builders.js":
  1710. /*!******************************************************************!*\
  1711. !*** ./node_modules/safevalues/builders/style_sheet_builders.js ***!
  1712. \******************************************************************/
  1713. /*! no static exports found */
  1714. /***/ (function(module, exports, __webpack_require__) {
  1715. "use strict";
  1716. /**
  1717. * @license
  1718. * SPDX-License-Identifier: Apache-2.0
  1719. */
  1720. Object.defineProperty(exports, "__esModule", { value: true });
  1721. exports.concatStyleSheets = exports.safeStyleSheet = void 0;
  1722. __webpack_require__(/*! ../environment/dev */ "./node_modules/safevalues/environment/dev.js");
  1723. var string_literal_1 = __webpack_require__(/*! ../internals/string_literal */ "./node_modules/safevalues/internals/string_literal.js");
  1724. var style_sheet_impl_1 = __webpack_require__(/*! ../internals/style_sheet_impl */ "./node_modules/safevalues/internals/style_sheet_impl.js");
  1725. /**
  1726. * Creates a SafeStyleSheet object from a template literal (without any
  1727. * embedded expressions).
  1728. *
  1729. * This function is a template literal tag function. It should be called with
  1730. * a template literal that does not contain any expressions. For example,
  1731. * safeStyleSheet`foo`;
  1732. * The argument must not have any < or > characters in it. This is so that
  1733. * SafeStyleSheet's contract is preserved, allowing the SafeStyleSheet to
  1734. * correctly be interpreted as a sequence of CSS declarations and without
  1735. * affecting the syntactic structure of any surrounding CSS and HTML.
  1736. *
  1737. * @param templateObj This contains the literal part of the template literal.
  1738. */
  1739. function safeStyleSheet(templateObj) {
  1740. if (true) {
  1741. (0, string_literal_1.assertIsTemplateObject)(templateObj, false, 'safeStyleSheet is a template literal tag ' +
  1742. 'function that only accepts template literals without ' +
  1743. 'expressions. For example, safeStyleSheet`foo`;');
  1744. }
  1745. var styleSheet = templateObj[0];
  1746. if (true) {
  1747. if (/[<>]/.test(styleSheet)) {
  1748. throw new Error('Forbidden characters in styleSheet string: ' + styleSheet);
  1749. }
  1750. }
  1751. return (0, style_sheet_impl_1.createStyleSheet)(styleSheet);
  1752. }
  1753. exports.safeStyleSheet = safeStyleSheet;
  1754. /**
  1755. * Creates a `SafeStyleSheet` value by concatenating multiple `SafeStyleSheet`s.
  1756. */
  1757. function concatStyleSheets(sheets) {
  1758. return (0, style_sheet_impl_1.createStyleSheet)(sheets.map(style_sheet_impl_1.unwrapStyleSheet).join(''));
  1759. }
  1760. exports.concatStyleSheets = concatStyleSheets;
  1761. /***/ }),
  1762. /***/ "./node_modules/safevalues/builders/url_sanitizer.js":
  1763. /*!***********************************************************!*\
  1764. !*** ./node_modules/safevalues/builders/url_sanitizer.js ***!
  1765. \***********************************************************/
  1766. /*! no static exports found */
  1767. /***/ (function(module, exports, __webpack_require__) {
  1768. "use strict";
  1769. /**
  1770. * @license
  1771. * SPDX-License-Identifier: Apache-2.0
  1772. */
  1773. Object.defineProperty(exports, "__esModule", { value: true });
  1774. exports.restrictivelySanitizeUrl = exports.unwrapUrlOrSanitize = exports.sanitizeJavascriptUrl = void 0;
  1775. /**
  1776. * @fileoverview Provides functions to enforce the SafeUrl contract at the sink
  1777. * level.
  1778. */
  1779. __webpack_require__(/*! ../environment/dev */ "./node_modules/safevalues/environment/dev.js");
  1780. function extractScheme(url) {
  1781. var parsedUrl;
  1782. try {
  1783. parsedUrl = new URL(url);
  1784. }
  1785. catch (e) {
  1786. // According to https://url.spec.whatwg.org/#constructors, the URL
  1787. // constructor with one parameter throws if `url` is not absolute. In this
  1788. // case, we are sure that no explicit scheme (javascript: ) is set.
  1789. // This can also be a URL parsing error, but in this case the URL won't be
  1790. // run anyway.
  1791. return 'https:';
  1792. }
  1793. return parsedUrl.protocol;
  1794. }
  1795. // We can't use an ES6 Set here because gws somehow depends on this code and
  1796. // doesn't want to pay the cost of a polyfill.
  1797. var ALLOWED_SCHEMES = ['data:', 'http:', 'https:', 'mailto:', 'ftp:'];
  1798. /**
  1799. * Checks that the URL scheme is not javascript.
  1800. * The URL parsing relies on the URL API in browsers that support it.
  1801. * @param url The URL to sanitize for a SafeUrl sink.
  1802. * @return undefined if url has a javascript: scheme, the original URL
  1803. * otherwise.
  1804. */
  1805. function sanitizeJavascriptUrl(url) {
  1806. var parsedScheme = extractScheme(url);
  1807. if (parsedScheme === 'javascript:') {
  1808. if (true) {
  1809. console.error("A URL with content '".concat(url, "' was sanitized away."));
  1810. }
  1811. return undefined;
  1812. }
  1813. return url;
  1814. }
  1815. exports.sanitizeJavascriptUrl = sanitizeJavascriptUrl;
  1816. /**
  1817. * Adapter to sanitize string URLs in DOM sink wrappers.
  1818. * @return undefined if the URL was sanitized.
  1819. */
  1820. function unwrapUrlOrSanitize(url) {
  1821. return sanitizeJavascriptUrl(url);
  1822. }
  1823. exports.unwrapUrlOrSanitize = unwrapUrlOrSanitize;
  1824. /**
  1825. * Sanitizes a URL restrictively.
  1826. * This sanitizer protects against XSS and potentially other uncommon and
  1827. * undesirable schemes that an attacker could use for e.g. phishing (tel:,
  1828. * callto: ssh: etc schemes). This sanitizer is primarily meant to be used by
  1829. * the HTML sanitizer.
  1830. */
  1831. function restrictivelySanitizeUrl(url) {
  1832. var parsedScheme = extractScheme(url);
  1833. if (parsedScheme !== undefined &&
  1834. ALLOWED_SCHEMES.indexOf(parsedScheme.toLowerCase()) !== -1) {
  1835. return url;
  1836. }
  1837. return 'about:invalid#zClosurez';
  1838. }
  1839. exports.restrictivelySanitizeUrl = restrictivelySanitizeUrl;
  1840. /***/ }),
  1841. /***/ "./node_modules/safevalues/dom/elements/anchor.js":
  1842. /*!********************************************************!*\
  1843. !*** ./node_modules/safevalues/dom/elements/anchor.js ***!
  1844. \********************************************************/
  1845. /*! no static exports found */
  1846. /***/ (function(module, exports, __webpack_require__) {
  1847. "use strict";
  1848. /**
  1849. * @license
  1850. * SPDX-License-Identifier: Apache-2.0
  1851. */
  1852. Object.defineProperty(exports, "__esModule", { value: true });
  1853. exports.setHref = void 0;
  1854. var url_sanitizer_1 = __webpack_require__(/*! ../../builders/url_sanitizer */ "./node_modules/safevalues/builders/url_sanitizer.js");
  1855. /**
  1856. * Sets the Href attribute from the given Url.
  1857. */
  1858. function setHref(anchor, url) {
  1859. var sanitizedUrl = (0, url_sanitizer_1.unwrapUrlOrSanitize)(url);
  1860. if (sanitizedUrl !== undefined) {
  1861. anchor.href = sanitizedUrl;
  1862. }
  1863. }
  1864. exports.setHref = setHref;
  1865. /***/ }),
  1866. /***/ "./node_modules/safevalues/dom/elements/area.js":
  1867. /*!******************************************************!*\
  1868. !*** ./node_modules/safevalues/dom/elements/area.js ***!
  1869. \******************************************************/
  1870. /*! no static exports found */
  1871. /***/ (function(module, exports, __webpack_require__) {
  1872. "use strict";
  1873. /**
  1874. * @license
  1875. * SPDX-License-Identifier: Apache-2.0
  1876. */
  1877. Object.defineProperty(exports, "__esModule", { value: true });
  1878. exports.setHref = void 0;
  1879. var url_sanitizer_1 = __webpack_require__(/*! ../../builders/url_sanitizer */ "./node_modules/safevalues/builders/url_sanitizer.js");
  1880. /**
  1881. * Sets the Href attribute from the given Url.
  1882. */
  1883. function setHref(area, url) {
  1884. var sanitizedUrl = (0, url_sanitizer_1.unwrapUrlOrSanitize)(url);
  1885. if (sanitizedUrl !== undefined) {
  1886. area.href = sanitizedUrl;
  1887. }
  1888. }
  1889. exports.setHref = setHref;
  1890. /***/ }),
  1891. /***/ "./node_modules/safevalues/dom/elements/button.js":
  1892. /*!********************************************************!*\
  1893. !*** ./node_modules/safevalues/dom/elements/button.js ***!
  1894. \********************************************************/
  1895. /*! no static exports found */
  1896. /***/ (function(module, exports, __webpack_require__) {
  1897. "use strict";
  1898. /**
  1899. * @license
  1900. * SPDX-License-Identifier: Apache-2.0
  1901. */
  1902. Object.defineProperty(exports, "__esModule", { value: true });
  1903. exports.setFormaction = void 0;
  1904. var url_sanitizer_1 = __webpack_require__(/*! ../../builders/url_sanitizer */ "./node_modules/safevalues/builders/url_sanitizer.js");
  1905. /**
  1906. * Sets the Formaction attribute from the given Url.
  1907. */
  1908. function setFormaction(button, url) {
  1909. var sanitizedUrl = (0, url_sanitizer_1.unwrapUrlOrSanitize)(url);
  1910. if (sanitizedUrl !== undefined) {
  1911. button.formAction = sanitizedUrl;
  1912. }
  1913. }
  1914. exports.setFormaction = setFormaction;
  1915. /***/ }),
  1916. /***/ "./node_modules/safevalues/dom/elements/element.js":
  1917. /*!*********************************************************!*\
  1918. !*** ./node_modules/safevalues/dom/elements/element.js ***!
  1919. \*********************************************************/
  1920. /*! no static exports found */
  1921. /***/ (function(module, exports, __webpack_require__) {
  1922. "use strict";
  1923. /**
  1924. * @license
  1925. * SPDX-License-Identifier: Apache-2.0
  1926. */
  1927. var __read = (this && this.__read) || function (o, n) {
  1928. var m = typeof Symbol === "function" && o[Symbol.iterator];
  1929. if (!m) return o;
  1930. var i = m.call(o), r, ar = [], e;
  1931. try {
  1932. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  1933. }
  1934. catch (error) { e = { error: error }; }
  1935. finally {
  1936. try {
  1937. if (r && !r.done && (m = i["return"])) m.call(i);
  1938. }
  1939. finally { if (e) throw e.error; }
  1940. }
  1941. return ar;
  1942. };
  1943. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  1944. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  1945. if (ar || !(i in from)) {
  1946. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  1947. ar[i] = from[i];
  1948. }
  1949. }
  1950. return to.concat(ar || Array.prototype.slice.call(from));
  1951. };
  1952. Object.defineProperty(exports, "__esModule", { value: true });
  1953. exports.setPrefixedAttribute = exports.buildPrefixedAttributeSetter = exports.insertAdjacentHtml = exports.setCssText = exports.setOuterHtml = exports.setInnerHtml = void 0;
  1954. /**
  1955. * @fileoverview This contains safe wrappers for properties that aren't specific
  1956. * to one kind of HTMLElement (like innerHTML), plus other setters and functions
  1957. * that are not tied to elements (like location.href or Worker constructor).
  1958. */
  1959. var attribute_impl_1 = __webpack_require__(/*! ../../internals/attribute_impl */ "./node_modules/safevalues/internals/attribute_impl.js");
  1960. var html_impl_1 = __webpack_require__(/*! ../../internals/html_impl */ "./node_modules/safevalues/internals/html_impl.js");
  1961. var style_impl_1 = __webpack_require__(/*! ../../internals/style_impl */ "./node_modules/safevalues/internals/style_impl.js");
  1962. /**
  1963. * Safely set {@link Element.innerHTML} on a given ShadowRoot or Element which
  1964. * may not be a `<script>` element or a `<style>` element.
  1965. */
  1966. function setInnerHtml(elOrRoot, v) {
  1967. if (isElement(elOrRoot)) {
  1968. throwIfScriptOrStyle(elOrRoot);
  1969. }
  1970. elOrRoot.innerHTML = (0, html_impl_1.unwrapHtml)(v);
  1971. }
  1972. exports.setInnerHtml = setInnerHtml;
  1973. /**
  1974. * Safely set {@link Element.outerHTML} for the given Element.
  1975. */
  1976. function setOuterHtml(e, v) {
  1977. var parent = e.parentElement;
  1978. if (parent !== null) {
  1979. throwIfScriptOrStyle(parent);
  1980. }
  1981. e.outerHTML = (0, html_impl_1.unwrapHtml)(v);
  1982. }
  1983. exports.setOuterHtml = setOuterHtml;
  1984. /**
  1985. * Set `ElementCSSInlineStyle.cssText` for the given `ElementCSSInlineStyle`.
  1986. */
  1987. function setCssText(e, v) {
  1988. e.style.cssText = (0, style_impl_1.unwrapStyle)(v);
  1989. }
  1990. exports.setCssText = setCssText;
  1991. /**
  1992. * Safely call {@link Element.insertAdjacentHTML} for the given Element.
  1993. */
  1994. function insertAdjacentHtml(element, position, v) {
  1995. var tagContext = (position === 'beforebegin' || position === 'afterend') ?
  1996. element.parentElement :
  1997. element;
  1998. if (tagContext !== null) {
  1999. throwIfScriptOrStyle(tagContext);
  2000. }
  2001. element.insertAdjacentHTML(position, (0, html_impl_1.unwrapHtml)(v));
  2002. }
  2003. exports.insertAdjacentHtml = insertAdjacentHtml;
  2004. /**
  2005. * Given a set of known-to-be-safe prefixes (e.g., "data-", "aria-", "js"),
  2006. * return a setter function that allows you to set attributes on an element,
  2007. * as long as the names of the attributes to be set has one of the prefixes.
  2008. *
  2009. * The returned setter ensures that setting any dangerous attribute, e.g.,
  2010. * "src", "href" will cause an exception. This is intended to be used as the
  2011. * safe alterantive of `Element#setAttribute`, when applications need to set
  2012. * attributes that do not have security implications and do not have a
  2013. * corresponding DOM property.
  2014. */
  2015. function buildPrefixedAttributeSetter(prefix) {
  2016. var otherPrefixes = [];
  2017. for (var _i = 1; _i < arguments.length; _i++) {
  2018. otherPrefixes[_i - 1] = arguments[_i];
  2019. }
  2020. var prefixes = __spreadArray([prefix], __read(otherPrefixes), false);
  2021. return function (e, attr, value) {
  2022. setPrefixedAttribute(prefixes, e, attr, value);
  2023. };
  2024. }
  2025. exports.buildPrefixedAttributeSetter = buildPrefixedAttributeSetter;
  2026. /**
  2027. * The safe alternative to Element#setAttribute. The function takes a list of
  2028. * `SafeAttributePrefix`, making developer intention explicit. The attribute
  2029. * to be set must has one of the safe prefixes, otherwise the function throws
  2030. * an Error.
  2031. */
  2032. function setPrefixedAttribute(attrPrefixes, e, attr, value) {
  2033. if (attrPrefixes.length === 0) {
  2034. throw new Error('No prefixes are provided');
  2035. }
  2036. var prefixes = attrPrefixes.map(function (s) { return (0, attribute_impl_1.unwrapAttributePrefix)(s); });
  2037. var attrLower = attr.toLowerCase();
  2038. if (prefixes.every(function (p) { return attrLower.indexOf(p) !== 0; })) {
  2039. throw new Error("Attribute \"".concat(attr, "\" does not match any of the allowed prefixes."));
  2040. }
  2041. e.setAttribute(attr, value);
  2042. }
  2043. exports.setPrefixedAttribute = setPrefixedAttribute;
  2044. function throwIfScriptOrStyle(element) {
  2045. if (element.tagName.toLowerCase() === 'script') {
  2046. throw new Error('Use setTextContent with a SafeScript.');
  2047. }
  2048. else if (element.tagName.toLowerCase() === 'style') {
  2049. throw new Error('Use setTextContent with a SafeStyleSheet.');
  2050. }
  2051. }
  2052. function isElement(elOrRoot) {
  2053. return elOrRoot.tagName !== undefined;
  2054. }
  2055. /***/ }),
  2056. /***/ "./node_modules/safevalues/dom/elements/embed.js":
  2057. /*!*******************************************************!*\
  2058. !*** ./node_modules/safevalues/dom/elements/embed.js ***!
  2059. \*******************************************************/
  2060. /*! no static exports found */
  2061. /***/ (function(module, exports, __webpack_require__) {
  2062. "use strict";
  2063. /**
  2064. * @license
  2065. * SPDX-License-Identifier: Apache-2.0
  2066. */
  2067. Object.defineProperty(exports, "__esModule", { value: true });
  2068. exports.setSrc = void 0;
  2069. var resource_url_impl_1 = __webpack_require__(/*! ../../internals/resource_url_impl */ "./node_modules/safevalues/internals/resource_url_impl.js");
  2070. /**
  2071. * Sets the Src attribute from the given SafeUrl.
  2072. */
  2073. function setSrc(embedEl, url) {
  2074. embedEl.src = (0, resource_url_impl_1.unwrapResourceUrl)(url);
  2075. }
  2076. exports.setSrc = setSrc;
  2077. /***/ }),
  2078. /***/ "./node_modules/safevalues/dom/elements/form.js":
  2079. /*!******************************************************!*\
  2080. !*** ./node_modules/safevalues/dom/elements/form.js ***!
  2081. \******************************************************/
  2082. /*! no static exports found */
  2083. /***/ (function(module, exports, __webpack_require__) {
  2084. "use strict";
  2085. /**
  2086. * @license
  2087. * SPDX-License-Identifier: Apache-2.0
  2088. */
  2089. Object.defineProperty(exports, "__esModule", { value: true });
  2090. exports.setAction = void 0;
  2091. var url_sanitizer_1 = __webpack_require__(/*! ../../builders/url_sanitizer */ "./node_modules/safevalues/builders/url_sanitizer.js");
  2092. /**
  2093. * Sets the Action attribute from the given Url.
  2094. */
  2095. function setAction(form, url) {
  2096. var sanitizedUrl = (0, url_sanitizer_1.unwrapUrlOrSanitize)(url);
  2097. if (sanitizedUrl !== undefined) {
  2098. form.action = sanitizedUrl;
  2099. }
  2100. }
  2101. exports.setAction = setAction;
  2102. /***/ }),
  2103. /***/ "./node_modules/safevalues/dom/elements/iframe.js":
  2104. /*!********************************************************!*\
  2105. !*** ./node_modules/safevalues/dom/elements/iframe.js ***!
  2106. \********************************************************/
  2107. /*! no static exports found */
  2108. /***/ (function(module, exports, __webpack_require__) {
  2109. "use strict";
  2110. /**
  2111. * @license
  2112. * SPDX-License-Identifier: Apache-2.0
  2113. */
  2114. Object.defineProperty(exports, "__esModule", { value: true });
  2115. exports.setSrcdoc = exports.setSrc = void 0;
  2116. /**
  2117. * @fileoverview Safe iframe helpers and go/intents-for-iframes-for-closure
  2118. */
  2119. var html_impl_1 = __webpack_require__(/*! ../../internals/html_impl */ "./node_modules/safevalues/internals/html_impl.js");
  2120. var resource_url_impl_1 = __webpack_require__(/*! ../../internals/resource_url_impl */ "./node_modules/safevalues/internals/resource_url_impl.js");
  2121. /** Sets the Src attribute using a TrustedResourceUrl */
  2122. function setSrc(iframe, v) {
  2123. iframe.src = (0, resource_url_impl_1.unwrapResourceUrl)(v).toString();
  2124. }
  2125. exports.setSrc = setSrc;
  2126. /** Sets the Srcdoc attribute using a SafeHtml */
  2127. function setSrcdoc(iframe, v) {
  2128. iframe.srcdoc = (0, html_impl_1.unwrapHtml)(v);
  2129. }
  2130. exports.setSrcdoc = setSrcdoc;
  2131. /***/ }),
  2132. /***/ "./node_modules/safevalues/dom/elements/input.js":
  2133. /*!*******************************************************!*\
  2134. !*** ./node_modules/safevalues/dom/elements/input.js ***!
  2135. \*******************************************************/
  2136. /*! no static exports found */
  2137. /***/ (function(module, exports, __webpack_require__) {
  2138. "use strict";
  2139. /**
  2140. * @license
  2141. * SPDX-License-Identifier: Apache-2.0
  2142. */
  2143. Object.defineProperty(exports, "__esModule", { value: true });
  2144. exports.setFormaction = void 0;
  2145. var url_sanitizer_1 = __webpack_require__(/*! ../../builders/url_sanitizer */ "./node_modules/safevalues/builders/url_sanitizer.js");
  2146. /**
  2147. * Sets the Formaction attribute from the given Url.
  2148. */
  2149. function setFormaction(input, url) {
  2150. var sanitizedUrl = (0, url_sanitizer_1.unwrapUrlOrSanitize)(url);
  2151. if (sanitizedUrl !== undefined) {
  2152. input.formAction = sanitizedUrl;
  2153. }
  2154. }
  2155. exports.setFormaction = setFormaction;
  2156. /***/ }),
  2157. /***/ "./node_modules/safevalues/dom/elements/link.js":
  2158. /*!******************************************************!*\
  2159. !*** ./node_modules/safevalues/dom/elements/link.js ***!
  2160. \******************************************************/
  2161. /*! no static exports found */
  2162. /***/ (function(module, exports, __webpack_require__) {
  2163. "use strict";
  2164. /**
  2165. * @license
  2166. * SPDX-License-Identifier: Apache-2.0
  2167. */
  2168. Object.defineProperty(exports, "__esModule", { value: true });
  2169. exports.setHrefAndRel = void 0;
  2170. var url_sanitizer_1 = __webpack_require__(/*! ../../builders/url_sanitizer */ "./node_modules/safevalues/builders/url_sanitizer.js");
  2171. var resource_url_impl_1 = __webpack_require__(/*! ../../internals/resource_url_impl */ "./node_modules/safevalues/internals/resource_url_impl.js");
  2172. var SAFE_URL_REL_VALUES = [
  2173. 'alternate',
  2174. 'author',
  2175. 'bookmark',
  2176. 'canonical',
  2177. 'cite',
  2178. 'help',
  2179. 'icon',
  2180. 'license',
  2181. 'next',
  2182. 'prefetch',
  2183. 'dns-prefetch',
  2184. 'prerender',
  2185. 'preconnect',
  2186. 'preload',
  2187. 'prev',
  2188. 'search',
  2189. 'subresource',
  2190. ];
  2191. function setHrefAndRel(link, url, rel) {
  2192. if (url instanceof resource_url_impl_1.TrustedResourceUrl) {
  2193. link.href = (0, resource_url_impl_1.unwrapResourceUrl)(url).toString();
  2194. }
  2195. else {
  2196. if (SAFE_URL_REL_VALUES.indexOf(rel) === -1) {
  2197. throw new Error("TrustedResourceUrl href attribute required with rel=\"".concat(rel, "\""));
  2198. }
  2199. var sanitizedUrl = (0, url_sanitizer_1.unwrapUrlOrSanitize)(url);
  2200. if (sanitizedUrl === undefined) {
  2201. return;
  2202. }
  2203. link.href = sanitizedUrl;
  2204. }
  2205. link.rel = rel;
  2206. }
  2207. exports.setHrefAndRel = setHrefAndRel;
  2208. /***/ }),
  2209. /***/ "./node_modules/safevalues/dom/elements/object.js":
  2210. /*!********************************************************!*\
  2211. !*** ./node_modules/safevalues/dom/elements/object.js ***!
  2212. \********************************************************/
  2213. /*! no static exports found */
  2214. /***/ (function(module, exports, __webpack_require__) {
  2215. "use strict";
  2216. /**
  2217. * @license
  2218. * SPDX-License-Identifier: Apache-2.0
  2219. */
  2220. Object.defineProperty(exports, "__esModule", { value: true });
  2221. exports.setData = void 0;
  2222. var resource_url_impl_1 = __webpack_require__(/*! ../../internals/resource_url_impl */ "./node_modules/safevalues/internals/resource_url_impl.js");
  2223. /** Sets the data attribute using a TrustedResourceUrl */
  2224. function setData(obj, v) {
  2225. obj.data = (0, resource_url_impl_1.unwrapResourceUrl)(v);
  2226. }
  2227. exports.setData = setData;
  2228. /***/ }),
  2229. /***/ "./node_modules/safevalues/dom/elements/script.js":
  2230. /*!********************************************************!*\
  2231. !*** ./node_modules/safevalues/dom/elements/script.js ***!
  2232. \********************************************************/
  2233. /*! no static exports found */
  2234. /***/ (function(module, exports, __webpack_require__) {
  2235. "use strict";
  2236. /**
  2237. * @license
  2238. * SPDX-License-Identifier: Apache-2.0
  2239. */
  2240. Object.defineProperty(exports, "__esModule", { value: true });
  2241. exports.setSrc = exports.setTextContent = void 0;
  2242. var resource_url_impl_1 = __webpack_require__(/*! ../../internals/resource_url_impl */ "./node_modules/safevalues/internals/resource_url_impl.js");
  2243. var script_impl_1 = __webpack_require__(/*! ../../internals/script_impl */ "./node_modules/safevalues/internals/script_impl.js");
  2244. /** Returns CSP nonce, if set for any script tag. */
  2245. function getScriptNonceFromWindow(win) {
  2246. var _a;
  2247. var doc = win.document;
  2248. // document.querySelector can be undefined in non-browser environments.
  2249. var script = (_a = doc.querySelector) === null || _a === void 0 ? void 0 : _a.call(doc, 'script[nonce]');
  2250. if (script) {
  2251. // Try to get the nonce from the IDL property first, because browsers that
  2252. // implement additional nonce protection features (currently only Chrome) to
  2253. // prevent nonce stealing via CSS do not expose the nonce via attributes.
  2254. // See https://github.com/whatwg/html/issues/2369
  2255. return script['nonce'] || script.getAttribute('nonce') || '';
  2256. }
  2257. return '';
  2258. }
  2259. /** Propagates CSP nonce to dynamically created scripts. */
  2260. function setNonceForScriptElement(script) {
  2261. var win = script.ownerDocument && script.ownerDocument.defaultView;
  2262. var nonce = getScriptNonceFromWindow(win || window);
  2263. if (nonce) {
  2264. script.setAttribute('nonce', nonce);
  2265. }
  2266. }
  2267. /** Sets textContent from the given SafeScript. */
  2268. function setTextContent(script, v) {
  2269. script.textContent = (0, script_impl_1.unwrapScript)(v);
  2270. setNonceForScriptElement(script);
  2271. }
  2272. exports.setTextContent = setTextContent;
  2273. /** Sets the Src attribute using a TrustedResourceUrl */
  2274. function setSrc(script, v) {
  2275. script.src = (0, resource_url_impl_1.unwrapResourceUrl)(v);
  2276. setNonceForScriptElement(script);
  2277. }
  2278. exports.setSrc = setSrc;
  2279. /***/ }),
  2280. /***/ "./node_modules/safevalues/dom/elements/style.js":
  2281. /*!*******************************************************!*\
  2282. !*** ./node_modules/safevalues/dom/elements/style.js ***!
  2283. \*******************************************************/
  2284. /*! no static exports found */
  2285. /***/ (function(module, exports, __webpack_require__) {
  2286. "use strict";
  2287. /**
  2288. * @license
  2289. * SPDX-License-Identifier: Apache-2.0
  2290. */
  2291. Object.defineProperty(exports, "__esModule", { value: true });
  2292. exports.setTextContent = void 0;
  2293. var style_sheet_impl_1 = __webpack_require__(/*! ../../internals/style_sheet_impl */ "./node_modules/safevalues/internals/style_sheet_impl.js");
  2294. /** Safe setters for `HTMLStyleElement`s. */
  2295. function setTextContent(elem, safeStyleSheet) {
  2296. elem.textContent = (0, style_sheet_impl_1.unwrapStyleSheet)(safeStyleSheet);
  2297. }
  2298. exports.setTextContent = setTextContent;
  2299. /***/ }),
  2300. /***/ "./node_modules/safevalues/dom/globals/document.js":
  2301. /*!*********************************************************!*\
  2302. !*** ./node_modules/safevalues/dom/globals/document.js ***!
  2303. \*********************************************************/
  2304. /*! no static exports found */
  2305. /***/ (function(module, exports, __webpack_require__) {
  2306. "use strict";
  2307. /**
  2308. * @license
  2309. * SPDX-License-Identifier: Apache-2.0
  2310. */
  2311. Object.defineProperty(exports, "__esModule", { value: true });
  2312. exports.execCommandInsertHtml = exports.execCommand = exports.write = void 0;
  2313. var html_impl_1 = __webpack_require__(/*! ../../internals/html_impl */ "./node_modules/safevalues/internals/html_impl.js");
  2314. /**
  2315. * write safely calls {@link Document.write} on the given {@link Document} with
  2316. * the given {@link SafeHtml}.
  2317. */
  2318. function write(doc, text) {
  2319. doc.write((0, html_impl_1.unwrapHtml)(text));
  2320. }
  2321. exports.write = write;
  2322. /**
  2323. * Safely calls {@link Document.execCommand}. When command is insertHtml, a
  2324. * SafeHtml must be passed in as value.
  2325. */
  2326. function execCommand(doc, command, value) {
  2327. var commandString = String(command);
  2328. var valueArgument = value;
  2329. if (commandString.toLowerCase() === 'inserthtml') {
  2330. valueArgument = (0, html_impl_1.unwrapHtml)(value);
  2331. }
  2332. return doc.execCommand(commandString, /* showUi= */ false, valueArgument);
  2333. }
  2334. exports.execCommand = execCommand;
  2335. /**
  2336. * Safely calls {@link Document.execCommand}('insertHtml').
  2337. * @deprecated Use safeDocument.execCommand.
  2338. */
  2339. function execCommandInsertHtml(doc, html) {
  2340. return doc.execCommand('insertHTML', /* showUi= */ false, (0, html_impl_1.unwrapHtml)(html));
  2341. }
  2342. exports.execCommandInsertHtml = execCommandInsertHtml;
  2343. /***/ }),
  2344. /***/ "./node_modules/safevalues/dom/globals/dom_parser.js":
  2345. /*!***********************************************************!*\
  2346. !*** ./node_modules/safevalues/dom/globals/dom_parser.js ***!
  2347. \***********************************************************/
  2348. /*! no static exports found */
  2349. /***/ (function(module, exports, __webpack_require__) {
  2350. "use strict";
  2351. /**
  2352. * @license
  2353. * SPDX-License-Identifier: Apache-2.0
  2354. */
  2355. Object.defineProperty(exports, "__esModule", { value: true });
  2356. exports.parseFromString = exports.parseHtml = void 0;
  2357. var html_impl_1 = __webpack_require__(/*! ../../internals/html_impl */ "./node_modules/safevalues/internals/html_impl.js");
  2358. /** Safely parses a string using the HTML parser. */
  2359. function parseHtml(parser, html) {
  2360. return parseFromString(parser, html, 'text/html');
  2361. }
  2362. exports.parseHtml = parseHtml;
  2363. /** Safely parses a string using the HTML or XML parser. */
  2364. function parseFromString(parser, content, contentType) {
  2365. return parser.parseFromString((0, html_impl_1.unwrapHtml)(content), contentType);
  2366. }
  2367. exports.parseFromString = parseFromString;
  2368. /***/ }),
  2369. /***/ "./node_modules/safevalues/dom/globals/global.js":
  2370. /*!*******************************************************!*\
  2371. !*** ./node_modules/safevalues/dom/globals/global.js ***!
  2372. \*******************************************************/
  2373. /*! no static exports found */
  2374. /***/ (function(module, exports, __webpack_require__) {
  2375. "use strict";
  2376. /**
  2377. * @license
  2378. * SPDX-License-Identifier: Apache-2.0
  2379. */
  2380. Object.defineProperty(exports, "__esModule", { value: true });
  2381. exports.globalEval = void 0;
  2382. var script_impl_1 = __webpack_require__(/*! ../../internals/script_impl */ "./node_modules/safevalues/internals/script_impl.js");
  2383. /**
  2384. * Evaluates a SafeScript value in the given scope using eval.
  2385. *
  2386. * Strongly consider avoiding this, as eval blocks CSP adoption and does not
  2387. * benefit from compiler optimizations.
  2388. */
  2389. function globalEval(win, script) {
  2390. var trustedScript = (0, script_impl_1.unwrapScript)(script);
  2391. var result = win.eval(trustedScript);
  2392. if (result === trustedScript) {
  2393. // https://crbug.com/1024786 manifesting in workers.
  2394. result = win.eval(trustedScript.toString());
  2395. }
  2396. return result;
  2397. }
  2398. exports.globalEval = globalEval;
  2399. /***/ }),
  2400. /***/ "./node_modules/safevalues/dom/globals/location.js":
  2401. /*!*********************************************************!*\
  2402. !*** ./node_modules/safevalues/dom/globals/location.js ***!
  2403. \*********************************************************/
  2404. /*! no static exports found */
  2405. /***/ (function(module, exports, __webpack_require__) {
  2406. "use strict";
  2407. /**
  2408. * @license
  2409. * SPDX-License-Identifier: Apache-2.0
  2410. */
  2411. Object.defineProperty(exports, "__esModule", { value: true });
  2412. exports.assign = exports.replace = exports.setHref = void 0;
  2413. var url_sanitizer_1 = __webpack_require__(/*! ../../builders/url_sanitizer */ "./node_modules/safevalues/builders/url_sanitizer.js");
  2414. /**
  2415. * setHref safely sets {@link Location.href} on the given {@link Location} with
  2416. * given {@link Url}.
  2417. */
  2418. function setHref(loc, url) {
  2419. var sanitizedUrl = (0, url_sanitizer_1.unwrapUrlOrSanitize)(url);
  2420. if (sanitizedUrl !== undefined) {
  2421. loc.href = sanitizedUrl;
  2422. }
  2423. }
  2424. exports.setHref = setHref;
  2425. /**
  2426. * replace safely calls {@link Location.replace} on the given {@link Location}
  2427. * with given {@link Url}.
  2428. */
  2429. function replace(loc, url) {
  2430. var sanitizedUrl = (0, url_sanitizer_1.unwrapUrlOrSanitize)(url);
  2431. if (sanitizedUrl !== undefined) {
  2432. loc.replace(sanitizedUrl);
  2433. }
  2434. }
  2435. exports.replace = replace;
  2436. /**
  2437. * assign safely calls {@link Location.assign} on the given {@link Location}
  2438. * with given {@link Url}.
  2439. */
  2440. function assign(loc, url) {
  2441. var sanitizedUrl = (0, url_sanitizer_1.unwrapUrlOrSanitize)(url);
  2442. if (sanitizedUrl !== undefined) {
  2443. loc.assign(sanitizedUrl);
  2444. }
  2445. }
  2446. exports.assign = assign;
  2447. /***/ }),
  2448. /***/ "./node_modules/safevalues/dom/globals/range.js":
  2449. /*!******************************************************!*\
  2450. !*** ./node_modules/safevalues/dom/globals/range.js ***!
  2451. \******************************************************/
  2452. /*! no static exports found */
  2453. /***/ (function(module, exports, __webpack_require__) {
  2454. "use strict";
  2455. /**
  2456. * @license
  2457. * SPDX-License-Identifier: Apache-2.0
  2458. */
  2459. Object.defineProperty(exports, "__esModule", { value: true });
  2460. exports.createContextualFragment = void 0;
  2461. var html_impl_1 = __webpack_require__(/*! ../../internals/html_impl */ "./node_modules/safevalues/internals/html_impl.js");
  2462. /** Safely creates a contextualFragment. */
  2463. function createContextualFragment(range, html) {
  2464. return range.createContextualFragment((0, html_impl_1.unwrapHtml)(html));
  2465. }
  2466. exports.createContextualFragment = createContextualFragment;
  2467. /***/ }),
  2468. /***/ "./node_modules/safevalues/dom/globals/service_worker_container.js":
  2469. /*!*************************************************************************!*\
  2470. !*** ./node_modules/safevalues/dom/globals/service_worker_container.js ***!
  2471. \*************************************************************************/
  2472. /*! no static exports found */
  2473. /***/ (function(module, exports, __webpack_require__) {
  2474. "use strict";
  2475. /**
  2476. * @license
  2477. * SPDX-License-Identifier: Apache-2.0
  2478. */
  2479. Object.defineProperty(exports, "__esModule", { value: true });
  2480. exports.register = void 0;
  2481. var resource_url_impl_1 = __webpack_require__(/*! ../../internals/resource_url_impl */ "./node_modules/safevalues/internals/resource_url_impl.js");
  2482. /** Safely registers a service worker by URL */
  2483. function register(container, scriptURL, options) {
  2484. return container.register((0, resource_url_impl_1.unwrapResourceUrl)(scriptURL), options);
  2485. }
  2486. exports.register = register;
  2487. /***/ }),
  2488. /***/ "./node_modules/safevalues/dom/globals/window.js":
  2489. /*!*******************************************************!*\
  2490. !*** ./node_modules/safevalues/dom/globals/window.js ***!
  2491. \*******************************************************/
  2492. /*! no static exports found */
  2493. /***/ (function(module, exports, __webpack_require__) {
  2494. "use strict";
  2495. /**
  2496. * @license
  2497. * SPDX-License-Identifier: Apache-2.0
  2498. */
  2499. Object.defineProperty(exports, "__esModule", { value: true });
  2500. exports.open = void 0;
  2501. var url_sanitizer_1 = __webpack_require__(/*! ../../builders/url_sanitizer */ "./node_modules/safevalues/builders/url_sanitizer.js");
  2502. /**
  2503. * open calls {@link Window.open} on the given {@link Window}, given a
  2504. * target {@link Url}.
  2505. */
  2506. function open(win, url, target, features) {
  2507. var sanitizedUrl = (0, url_sanitizer_1.unwrapUrlOrSanitize)(url);
  2508. if (sanitizedUrl !== undefined) {
  2509. return win.open(sanitizedUrl, target, features);
  2510. }
  2511. return null;
  2512. }
  2513. exports.open = open;
  2514. /***/ }),
  2515. /***/ "./node_modules/safevalues/dom/globals/worker.js":
  2516. /*!*******************************************************!*\
  2517. !*** ./node_modules/safevalues/dom/globals/worker.js ***!
  2518. \*******************************************************/
  2519. /*! no static exports found */
  2520. /***/ (function(module, exports, __webpack_require__) {
  2521. "use strict";
  2522. /**
  2523. * @license
  2524. * SPDX-License-Identifier: Apache-2.0
  2525. */
  2526. var __read = (this && this.__read) || function (o, n) {
  2527. var m = typeof Symbol === "function" && o[Symbol.iterator];
  2528. if (!m) return o;
  2529. var i = m.call(o), r, ar = [], e;
  2530. try {
  2531. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  2532. }
  2533. catch (error) { e = { error: error }; }
  2534. finally {
  2535. try {
  2536. if (r && !r.done && (m = i["return"])) m.call(i);
  2537. }
  2538. finally { if (e) throw e.error; }
  2539. }
  2540. return ar;
  2541. };
  2542. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  2543. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  2544. if (ar || !(i in from)) {
  2545. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  2546. ar[i] = from[i];
  2547. }
  2548. }
  2549. return to.concat(ar || Array.prototype.slice.call(from));
  2550. };
  2551. Object.defineProperty(exports, "__esModule", { value: true });
  2552. exports.importScripts = exports.createShared = exports.create = void 0;
  2553. var resource_url_impl_1 = __webpack_require__(/*! ../../internals/resource_url_impl */ "./node_modules/safevalues/internals/resource_url_impl.js");
  2554. /**
  2555. * Safely creates a Web Worker.
  2556. *
  2557. * Example usage:
  2558. * const trustedResourceUrl = trustedResourceUrl`/safe_script.js`;
  2559. * safedom.safeWorker.create(trustedResourceUrl);
  2560. * which is a safe alternative to
  2561. * new Worker(url);
  2562. * The latter can result in loading untrusted code.
  2563. */
  2564. function create(url, options) {
  2565. return new Worker((0, resource_url_impl_1.unwrapResourceUrl)(url), options);
  2566. }
  2567. exports.create = create;
  2568. /** Safely creates a shared Web Worker. */
  2569. function createShared(url, options) {
  2570. return new SharedWorker((0, resource_url_impl_1.unwrapResourceUrl)(url), options);
  2571. }
  2572. exports.createShared = createShared;
  2573. /** Safely calls importScripts */
  2574. function importScripts(scope) {
  2575. var urls = [];
  2576. for (var _i = 1; _i < arguments.length; _i++) {
  2577. urls[_i - 1] = arguments[_i];
  2578. }
  2579. scope.importScripts.apply(scope, __spreadArray([], __read(urls.map(function (url) { return (0, resource_url_impl_1.unwrapResourceUrl)(url); })), false));
  2580. }
  2581. exports.importScripts = importScripts;
  2582. /***/ }),
  2583. /***/ "./node_modules/safevalues/dom/index.js":
  2584. /*!**********************************************!*\
  2585. !*** ./node_modules/safevalues/dom/index.js ***!
  2586. \**********************************************/
  2587. /*! no static exports found */
  2588. /***/ (function(module, exports, __webpack_require__) {
  2589. "use strict";
  2590. /**
  2591. * @license
  2592. * SPDX-License-Identifier: Apache-2.0
  2593. */
  2594. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  2595. if (k2 === undefined) k2 = k;
  2596. var desc = Object.getOwnPropertyDescriptor(m, k);
  2597. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  2598. desc = { enumerable: true, get: function() { return m[k]; } };
  2599. }
  2600. Object.defineProperty(o, k2, desc);
  2601. }) : (function(o, m, k, k2) {
  2602. if (k2 === undefined) k2 = k;
  2603. o[k2] = m[k];
  2604. }));
  2605. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  2606. Object.defineProperty(o, "default", { enumerable: true, value: v });
  2607. }) : function(o, v) {
  2608. o["default"] = v;
  2609. });
  2610. var __importStar = (this && this.__importStar) || function (mod) {
  2611. if (mod && mod.__esModule) return mod;
  2612. var result = {};
  2613. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  2614. __setModuleDefault(result, mod);
  2615. return result;
  2616. };
  2617. Object.defineProperty(exports, "__esModule", { value: true });
  2618. exports.safeWorker = exports.safeWindow = exports.safeServiceWorkerContainer = exports.safeRange = exports.safeLocation = exports.safeGlobal = exports.safeDomParser = exports.safeDocument = exports.safeStyleEl = exports.safeScriptEl = exports.safeObjectEl = exports.safeLinkEl = exports.safeInputEl = exports.safeIframeEl = exports.safeFormEl = exports.safeEmbedEl = exports.safeElement = exports.safeButtonEl = exports.safeAreaEl = exports.safeAnchorEl = void 0;
  2619. /**
  2620. * @fileoverview This file re-exports all of the wrappers to ensure that we have
  2621. * a clearly defined interface.
  2622. */
  2623. exports.safeAnchorEl = __importStar(__webpack_require__(/*! ./elements/anchor */ "./node_modules/safevalues/dom/elements/anchor.js"));
  2624. exports.safeAreaEl = __importStar(__webpack_require__(/*! ./elements/area */ "./node_modules/safevalues/dom/elements/area.js"));
  2625. exports.safeButtonEl = __importStar(__webpack_require__(/*! ./elements/button */ "./node_modules/safevalues/dom/elements/button.js"));
  2626. exports.safeElement = __importStar(__webpack_require__(/*! ./elements/element */ "./node_modules/safevalues/dom/elements/element.js"));
  2627. exports.safeEmbedEl = __importStar(__webpack_require__(/*! ./elements/embed */ "./node_modules/safevalues/dom/elements/embed.js"));
  2628. exports.safeFormEl = __importStar(__webpack_require__(/*! ./elements/form */ "./node_modules/safevalues/dom/elements/form.js"));
  2629. exports.safeIframeEl = __importStar(__webpack_require__(/*! ./elements/iframe */ "./node_modules/safevalues/dom/elements/iframe.js"));
  2630. exports.safeInputEl = __importStar(__webpack_require__(/*! ./elements/input */ "./node_modules/safevalues/dom/elements/input.js"));
  2631. exports.safeLinkEl = __importStar(__webpack_require__(/*! ./elements/link */ "./node_modules/safevalues/dom/elements/link.js"));
  2632. exports.safeObjectEl = __importStar(__webpack_require__(/*! ./elements/object */ "./node_modules/safevalues/dom/elements/object.js"));
  2633. exports.safeScriptEl = __importStar(__webpack_require__(/*! ./elements/script */ "./node_modules/safevalues/dom/elements/script.js"));
  2634. exports.safeStyleEl = __importStar(__webpack_require__(/*! ./elements/style */ "./node_modules/safevalues/dom/elements/style.js"));
  2635. exports.safeDocument = __importStar(__webpack_require__(/*! ./globals/document */ "./node_modules/safevalues/dom/globals/document.js"));
  2636. exports.safeDomParser = __importStar(__webpack_require__(/*! ./globals/dom_parser */ "./node_modules/safevalues/dom/globals/dom_parser.js"));
  2637. exports.safeGlobal = __importStar(__webpack_require__(/*! ./globals/global */ "./node_modules/safevalues/dom/globals/global.js"));
  2638. exports.safeLocation = __importStar(__webpack_require__(/*! ./globals/location */ "./node_modules/safevalues/dom/globals/location.js"));
  2639. exports.safeRange = __importStar(__webpack_require__(/*! ./globals/range */ "./node_modules/safevalues/dom/globals/range.js"));
  2640. exports.safeServiceWorkerContainer = __importStar(__webpack_require__(/*! ./globals/service_worker_container */ "./node_modules/safevalues/dom/globals/service_worker_container.js"));
  2641. exports.safeWindow = __importStar(__webpack_require__(/*! ./globals/window */ "./node_modules/safevalues/dom/globals/window.js"));
  2642. exports.safeWorker = __importStar(__webpack_require__(/*! ./globals/worker */ "./node_modules/safevalues/dom/globals/worker.js"));
  2643. /***/ }),
  2644. /***/ "./node_modules/safevalues/environment/dev.js":
  2645. /*!****************************************************!*\
  2646. !*** ./node_modules/safevalues/environment/dev.js ***!
  2647. \****************************************************/
  2648. /*! no static exports found */
  2649. /***/ (function(module, exports, __webpack_require__) {
  2650. "use strict";
  2651. /* WEBPACK VAR INJECTION */(function(process) {
  2652. /**
  2653. * @license
  2654. * SPDX-License-Identifier: Apache-2.0
  2655. */
  2656. /**
  2657. * Ensure process.env.NODE_ENV is set even when not running under Webpack or
  2658. * Node. Terser will strip this out of production binaries.
  2659. */
  2660. /*#__PURE__*/ (function () {
  2661. if (typeof process === 'undefined') {
  2662. window.process = { env: { NODE_ENV: 'development' } };
  2663. }
  2664. })();
  2665. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../process/browser.js */ "./node_modules/process/browser.js")))
  2666. /***/ }),
  2667. /***/ "./node_modules/safevalues/index.js":
  2668. /*!******************************************!*\
  2669. !*** ./node_modules/safevalues/index.js ***!
  2670. \******************************************/
  2671. /*! no static exports found */
  2672. /***/ (function(module, exports, __webpack_require__) {
  2673. "use strict";
  2674. /**
  2675. * @license
  2676. * SPDX-License-Identifier: Apache-2.0
  2677. */
  2678. Object.defineProperty(exports, "__esModule", { value: true });
  2679. exports.unwrapStyleSheet = exports.SafeStyleSheet = exports.isStyleSheet = exports.unwrapStyle = exports.SafeStyle = exports.isStyle = exports.unwrapScript = exports.SafeScript = exports.isScript = exports.EMPTY_SCRIPT = exports.unwrapResourceUrl = exports.TrustedResourceUrl = exports.isResourceUrl = exports.unwrapHtml = exports.SafeHtml = exports.isHtml = exports.EMPTY_HTML = exports.unwrapAttributePrefix = exports.SafeAttributePrefix = exports.safeStyleSheet = exports.concatStyleSheets = exports.safeStyle = exports.concatStyles = exports.scriptFromJson = exports.safeScriptWithArgs = exports.safeScript = exports.concatScripts = exports.trustedResourceUrl = exports.replaceFragment = exports.blobUrlFromScript = exports.appendParams = exports.HtmlSanitizerBuilder = exports.sanitizeHtmlToFragment = exports.sanitizeHtmlAssertUnchanged = exports.sanitizeHtml = exports.htmlEscape = exports.createScriptSrc = exports.createScript = exports.concatHtmls = exports.safeAttrPrefix = void 0;
  2680. /** Safe builders */
  2681. var attribute_builders_1 = __webpack_require__(/*! ./builders/attribute_builders */ "./node_modules/safevalues/builders/attribute_builders.js");
  2682. Object.defineProperty(exports, "safeAttrPrefix", { enumerable: true, get: function () { return attribute_builders_1.safeAttrPrefix; } });
  2683. var html_builders_1 = __webpack_require__(/*! ./builders/html_builders */ "./node_modules/safevalues/builders/html_builders.js");
  2684. Object.defineProperty(exports, "concatHtmls", { enumerable: true, get: function () { return html_builders_1.concatHtmls; } });
  2685. Object.defineProperty(exports, "createScript", { enumerable: true, get: function () { return html_builders_1.createScript; } });
  2686. Object.defineProperty(exports, "createScriptSrc", { enumerable: true, get: function () { return html_builders_1.createScriptSrc; } });
  2687. Object.defineProperty(exports, "htmlEscape", { enumerable: true, get: function () { return html_builders_1.htmlEscape; } });
  2688. var html_sanitizer_1 = __webpack_require__(/*! ./builders/html_sanitizer/html_sanitizer */ "./node_modules/safevalues/builders/html_sanitizer/html_sanitizer.js");
  2689. Object.defineProperty(exports, "sanitizeHtml", { enumerable: true, get: function () { return html_sanitizer_1.sanitizeHtml; } });
  2690. Object.defineProperty(exports, "sanitizeHtmlAssertUnchanged", { enumerable: true, get: function () { return html_sanitizer_1.sanitizeHtmlAssertUnchanged; } });
  2691. Object.defineProperty(exports, "sanitizeHtmlToFragment", { enumerable: true, get: function () { return html_sanitizer_1.sanitizeHtmlToFragment; } });
  2692. var html_sanitizer_builder_1 = __webpack_require__(/*! ./builders/html_sanitizer/html_sanitizer_builder */ "./node_modules/safevalues/builders/html_sanitizer/html_sanitizer_builder.js");
  2693. Object.defineProperty(exports, "HtmlSanitizerBuilder", { enumerable: true, get: function () { return html_sanitizer_builder_1.HtmlSanitizerBuilder; } });
  2694. var resource_url_builders_1 = __webpack_require__(/*! ./builders/resource_url_builders */ "./node_modules/safevalues/builders/resource_url_builders.js");
  2695. Object.defineProperty(exports, "appendParams", { enumerable: true, get: function () { return resource_url_builders_1.appendParams; } });
  2696. Object.defineProperty(exports, "blobUrlFromScript", { enumerable: true, get: function () { return resource_url_builders_1.blobUrlFromScript; } });
  2697. Object.defineProperty(exports, "replaceFragment", { enumerable: true, get: function () { return resource_url_builders_1.replaceFragment; } });
  2698. Object.defineProperty(exports, "trustedResourceUrl", { enumerable: true, get: function () { return resource_url_builders_1.trustedResourceUrl; } });
  2699. var script_builders_1 = __webpack_require__(/*! ./builders/script_builders */ "./node_modules/safevalues/builders/script_builders.js");
  2700. Object.defineProperty(exports, "concatScripts", { enumerable: true, get: function () { return script_builders_1.concatScripts; } });
  2701. Object.defineProperty(exports, "safeScript", { enumerable: true, get: function () { return script_builders_1.safeScript; } });
  2702. Object.defineProperty(exports, "safeScriptWithArgs", { enumerable: true, get: function () { return script_builders_1.safeScriptWithArgs; } });
  2703. Object.defineProperty(exports, "scriptFromJson", { enumerable: true, get: function () { return script_builders_1.scriptFromJson; } });
  2704. var style_builders_1 = __webpack_require__(/*! ./builders/style_builders */ "./node_modules/safevalues/builders/style_builders.js");
  2705. Object.defineProperty(exports, "concatStyles", { enumerable: true, get: function () { return style_builders_1.concatStyles; } });
  2706. Object.defineProperty(exports, "safeStyle", { enumerable: true, get: function () { return style_builders_1.safeStyle; } });
  2707. var style_sheet_builders_1 = __webpack_require__(/*! ./builders/style_sheet_builders */ "./node_modules/safevalues/builders/style_sheet_builders.js");
  2708. Object.defineProperty(exports, "concatStyleSheets", { enumerable: true, get: function () { return style_sheet_builders_1.concatStyleSheets; } });
  2709. Object.defineProperty(exports, "safeStyleSheet", { enumerable: true, get: function () { return style_sheet_builders_1.safeStyleSheet; } });
  2710. /** Types, constants and unwrappers */
  2711. var attribute_impl_1 = __webpack_require__(/*! ./internals/attribute_impl */ "./node_modules/safevalues/internals/attribute_impl.js");
  2712. Object.defineProperty(exports, "SafeAttributePrefix", { enumerable: true, get: function () { return attribute_impl_1.SafeAttributePrefix; } });
  2713. Object.defineProperty(exports, "unwrapAttributePrefix", { enumerable: true, get: function () { return attribute_impl_1.unwrapAttributePrefix; } });
  2714. var html_impl_1 = __webpack_require__(/*! ./internals/html_impl */ "./node_modules/safevalues/internals/html_impl.js");
  2715. Object.defineProperty(exports, "EMPTY_HTML", { enumerable: true, get: function () { return html_impl_1.EMPTY_HTML; } });
  2716. Object.defineProperty(exports, "isHtml", { enumerable: true, get: function () { return html_impl_1.isHtml; } });
  2717. Object.defineProperty(exports, "SafeHtml", { enumerable: true, get: function () { return html_impl_1.SafeHtml; } });
  2718. Object.defineProperty(exports, "unwrapHtml", { enumerable: true, get: function () { return html_impl_1.unwrapHtml; } });
  2719. var resource_url_impl_1 = __webpack_require__(/*! ./internals/resource_url_impl */ "./node_modules/safevalues/internals/resource_url_impl.js");
  2720. Object.defineProperty(exports, "isResourceUrl", { enumerable: true, get: function () { return resource_url_impl_1.isResourceUrl; } });
  2721. Object.defineProperty(exports, "TrustedResourceUrl", { enumerable: true, get: function () { return resource_url_impl_1.TrustedResourceUrl; } });
  2722. Object.defineProperty(exports, "unwrapResourceUrl", { enumerable: true, get: function () { return resource_url_impl_1.unwrapResourceUrl; } });
  2723. var script_impl_1 = __webpack_require__(/*! ./internals/script_impl */ "./node_modules/safevalues/internals/script_impl.js");
  2724. Object.defineProperty(exports, "EMPTY_SCRIPT", { enumerable: true, get: function () { return script_impl_1.EMPTY_SCRIPT; } });
  2725. Object.defineProperty(exports, "isScript", { enumerable: true, get: function () { return script_impl_1.isScript; } });
  2726. Object.defineProperty(exports, "SafeScript", { enumerable: true, get: function () { return script_impl_1.SafeScript; } });
  2727. Object.defineProperty(exports, "unwrapScript", { enumerable: true, get: function () { return script_impl_1.unwrapScript; } });
  2728. var style_impl_1 = __webpack_require__(/*! ./internals/style_impl */ "./node_modules/safevalues/internals/style_impl.js");
  2729. Object.defineProperty(exports, "isStyle", { enumerable: true, get: function () { return style_impl_1.isStyle; } });
  2730. Object.defineProperty(exports, "SafeStyle", { enumerable: true, get: function () { return style_impl_1.SafeStyle; } });
  2731. Object.defineProperty(exports, "unwrapStyle", { enumerable: true, get: function () { return style_impl_1.unwrapStyle; } });
  2732. var style_sheet_impl_1 = __webpack_require__(/*! ./internals/style_sheet_impl */ "./node_modules/safevalues/internals/style_sheet_impl.js");
  2733. Object.defineProperty(exports, "isStyleSheet", { enumerable: true, get: function () { return style_sheet_impl_1.isStyleSheet; } });
  2734. Object.defineProperty(exports, "SafeStyleSheet", { enumerable: true, get: function () { return style_sheet_impl_1.SafeStyleSheet; } });
  2735. Object.defineProperty(exports, "unwrapStyleSheet", { enumerable: true, get: function () { return style_sheet_impl_1.unwrapStyleSheet; } });
  2736. /***/ }),
  2737. /***/ "./node_modules/safevalues/internals/attribute_impl.js":
  2738. /*!*************************************************************!*\
  2739. !*** ./node_modules/safevalues/internals/attribute_impl.js ***!
  2740. \*************************************************************/
  2741. /*! no static exports found */
  2742. /***/ (function(module, exports, __webpack_require__) {
  2743. "use strict";
  2744. /**
  2745. * @license
  2746. * SPDX-License-Identifier: Apache-2.0
  2747. */
  2748. var __extends = (this && this.__extends) || (function () {
  2749. var extendStatics = function (d, b) {
  2750. extendStatics = Object.setPrototypeOf ||
  2751. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2752. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  2753. return extendStatics(d, b);
  2754. };
  2755. return function (d, b) {
  2756. if (typeof b !== "function" && b !== null)
  2757. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  2758. extendStatics(d, b);
  2759. function __() { this.constructor = d; }
  2760. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2761. };
  2762. })();
  2763. Object.defineProperty(exports, "__esModule", { value: true });
  2764. exports.unwrapAttributePrefix = exports.createAttributePrefix = exports.SafeAttributePrefix = void 0;
  2765. __webpack_require__(/*! ../environment/dev */ "./node_modules/safevalues/environment/dev.js");
  2766. var secrets_1 = __webpack_require__(/*! ./secrets */ "./node_modules/safevalues/internals/secrets.js");
  2767. /** A prefix with which an attribute is safe to set using plain strings. */
  2768. var SafeAttributePrefix = /** @class */ (function () {
  2769. function SafeAttributePrefix() {
  2770. }
  2771. return SafeAttributePrefix;
  2772. }());
  2773. exports.SafeAttributePrefix = SafeAttributePrefix;
  2774. /** Implementation for `SafeAttributePrefix` */
  2775. var AttributePrefixImpl = /** @class */ (function (_super) {
  2776. __extends(AttributePrefixImpl, _super);
  2777. function AttributePrefixImpl(attrPrefix, token) {
  2778. var _this = _super.call(this) || this;
  2779. if (true) {
  2780. (0, secrets_1.ensureTokenIsValid)(token);
  2781. }
  2782. _this.privateDoNotAccessOrElseWrappedAttrPrefix = attrPrefix;
  2783. return _this;
  2784. }
  2785. AttributePrefixImpl.prototype.toString = function () {
  2786. return this.privateDoNotAccessOrElseWrappedAttrPrefix;
  2787. };
  2788. return AttributePrefixImpl;
  2789. }(SafeAttributePrefix));
  2790. /**
  2791. * Builds a new `SafeAttribute` from the given string, without enforcing
  2792. * safety guarantees. This shouldn't be exposed to application developers, and
  2793. * must only be used as a step towards safe builders or safe constants.
  2794. */
  2795. function createAttributePrefix(attrPrefix) {
  2796. return new AttributePrefixImpl(attrPrefix, secrets_1.secretToken);
  2797. }
  2798. exports.createAttributePrefix = createAttributePrefix;
  2799. /**
  2800. * Returns the string value of the passed `SafeAttributePrefix` object while
  2801. * ensuring it has the correct type.
  2802. */
  2803. function unwrapAttributePrefix(value) {
  2804. if (value instanceof AttributePrefixImpl) {
  2805. return value.privateDoNotAccessOrElseWrappedAttrPrefix;
  2806. }
  2807. else {
  2808. var message = '';
  2809. if (true) {
  2810. message = 'Unexpected type when unwrapping SafeAttributePrefix';
  2811. }
  2812. throw new Error(message);
  2813. }
  2814. }
  2815. exports.unwrapAttributePrefix = unwrapAttributePrefix;
  2816. /***/ }),
  2817. /***/ "./node_modules/safevalues/internals/html_impl.js":
  2818. /*!********************************************************!*\
  2819. !*** ./node_modules/safevalues/internals/html_impl.js ***!
  2820. \********************************************************/
  2821. /*! no static exports found */
  2822. /***/ (function(module, exports, __webpack_require__) {
  2823. "use strict";
  2824. /**
  2825. * @license
  2826. * SPDX-License-Identifier: Apache-2.0
  2827. */
  2828. Object.defineProperty(exports, "__esModule", { value: true });
  2829. exports.unwrapHtml = exports.isHtml = exports.EMPTY_HTML = exports.createHtml = exports.SafeHtml = void 0;
  2830. __webpack_require__(/*! ../environment/dev */ "./node_modules/safevalues/environment/dev.js");
  2831. /* g3_import_pure from './pure' */
  2832. var secrets_1 = __webpack_require__(/*! ./secrets */ "./node_modules/safevalues/internals/secrets.js");
  2833. var trusted_types_1 = __webpack_require__(/*! ./trusted_types */ "./node_modules/safevalues/internals/trusted_types.js");
  2834. /**
  2835. * Runtime implementation of `TrustedHTML` in browsers that don't support it.
  2836. */
  2837. var HtmlImpl = /** @class */ (function () {
  2838. function HtmlImpl(html, token) {
  2839. if (true) {
  2840. (0, secrets_1.ensureTokenIsValid)(token);
  2841. }
  2842. this.privateDoNotAccessOrElseWrappedHtml = html;
  2843. }
  2844. HtmlImpl.prototype.toString = function () {
  2845. return this.privateDoNotAccessOrElseWrappedHtml.toString();
  2846. };
  2847. return HtmlImpl;
  2848. }());
  2849. function createHtmlInternal(html, trusted) {
  2850. return (trusted !== null && trusted !== void 0 ? trusted : new HtmlImpl(html, secrets_1.secretToken));
  2851. }
  2852. var GlobalTrustedHTML = (typeof window !== undefined) ? window.TrustedHTML : undefined;
  2853. /**
  2854. * Also exports the constructor so that instanceof checks work.
  2855. */
  2856. exports.SafeHtml = (GlobalTrustedHTML !== null && GlobalTrustedHTML !== void 0 ? GlobalTrustedHTML : HtmlImpl);
  2857. /**
  2858. * Builds a new `SafeHtml` from the given string, without enforcing safety
  2859. * guarantees. It may cause side effects by creating a Trusted Types policy.
  2860. * This shouldn't be exposed to application developers, and must only be used as
  2861. * a step towards safe builders or safe constants.
  2862. */
  2863. function createHtml(html) {
  2864. var _a;
  2865. /** @noinline */
  2866. var noinlineHtml = html;
  2867. return createHtmlInternal(noinlineHtml, (_a = (0, trusted_types_1.getTrustedTypesPolicy)()) === null || _a === void 0 ? void 0 : _a.createHTML(noinlineHtml));
  2868. }
  2869. exports.createHtml = createHtml;
  2870. /**
  2871. * An empty `SafeHtml` constant.
  2872. * Unlike the function above, using this will not create a policy.
  2873. */
  2874. exports.EMPTY_HTML =
  2875. /* #__PURE__ */ (function () { var _a; return createHtmlInternal('', (_a = (0, trusted_types_1.getTrustedTypes)()) === null || _a === void 0 ? void 0 : _a.emptyHTML); })();
  2876. /**
  2877. * Checks if the given value is a `SafeHtml` instance.
  2878. */
  2879. function isHtml(value) {
  2880. return value instanceof exports.SafeHtml;
  2881. }
  2882. exports.isHtml = isHtml;
  2883. /**
  2884. * Returns the value of the passed `SafeHtml` object while ensuring it
  2885. * has the correct type.
  2886. *
  2887. * Returns a native `TrustedHTML` or a string if Trusted Types are disabled.
  2888. */
  2889. function unwrapHtml(value) {
  2890. var _a;
  2891. if ((_a = (0, trusted_types_1.getTrustedTypes)()) === null || _a === void 0 ? void 0 : _a.isHTML(value)) {
  2892. return value;
  2893. }
  2894. else if (value instanceof HtmlImpl) {
  2895. return value.privateDoNotAccessOrElseWrappedHtml;
  2896. }
  2897. else {
  2898. var message = '';
  2899. if (true) {
  2900. message = 'Unexpected type when unwrapping SafeHtml';
  2901. }
  2902. throw new Error(message);
  2903. }
  2904. }
  2905. exports.unwrapHtml = unwrapHtml;
  2906. /***/ }),
  2907. /***/ "./node_modules/safevalues/internals/resource_url_impl.js":
  2908. /*!****************************************************************!*\
  2909. !*** ./node_modules/safevalues/internals/resource_url_impl.js ***!
  2910. \****************************************************************/
  2911. /*! no static exports found */
  2912. /***/ (function(module, exports, __webpack_require__) {
  2913. "use strict";
  2914. /**
  2915. * @license
  2916. * SPDX-License-Identifier: Apache-2.0
  2917. */
  2918. Object.defineProperty(exports, "__esModule", { value: true });
  2919. exports.unwrapResourceUrl = exports.isResourceUrl = exports.createResourceUrl = exports.TrustedResourceUrl = void 0;
  2920. __webpack_require__(/*! ../environment/dev */ "./node_modules/safevalues/environment/dev.js");
  2921. var secrets_1 = __webpack_require__(/*! ./secrets */ "./node_modules/safevalues/internals/secrets.js");
  2922. var trusted_types_1 = __webpack_require__(/*! ./trusted_types */ "./node_modules/safevalues/internals/trusted_types.js");
  2923. /**
  2924. * Runtime implementation of `TrustedScriptURL` in browsers that don't support
  2925. * it.
  2926. */
  2927. var ResourceUrlImpl = /** @class */ (function () {
  2928. function ResourceUrlImpl(url, token) {
  2929. if (true) {
  2930. (0, secrets_1.ensureTokenIsValid)(token);
  2931. }
  2932. this.privateDoNotAccessOrElseWrappedResourceUrl = url;
  2933. }
  2934. ResourceUrlImpl.prototype.toString = function () {
  2935. return this.privateDoNotAccessOrElseWrappedResourceUrl.toString();
  2936. };
  2937. return ResourceUrlImpl;
  2938. }());
  2939. var GlobalTrustedScriptURL = (typeof window !== undefined) ? window.TrustedScriptURL : undefined;
  2940. /**
  2941. * Also exports the constructor so that instanceof checks work.
  2942. */
  2943. exports.TrustedResourceUrl = (GlobalTrustedScriptURL !== null && GlobalTrustedScriptURL !== void 0 ? GlobalTrustedScriptURL : ResourceUrlImpl);
  2944. /**
  2945. * Builds a new `TrustedResourceUrl` from the given string, without
  2946. * enforcing safety guarantees. It may cause side effects by creating a Trusted
  2947. * Types policy. This shouldn't be exposed to application developers, and must
  2948. * only be used as a step towards safe builders or safe constants.
  2949. */
  2950. function createResourceUrl(url) {
  2951. var _a;
  2952. /** @noinline */
  2953. var noinlineUrl = url;
  2954. var trustedScriptURL = (_a = (0, trusted_types_1.getTrustedTypesPolicy)()) === null || _a === void 0 ? void 0 : _a.createScriptURL(noinlineUrl);
  2955. return (trustedScriptURL !== null && trustedScriptURL !== void 0 ? trustedScriptURL : new ResourceUrlImpl(noinlineUrl, secrets_1.secretToken));
  2956. }
  2957. exports.createResourceUrl = createResourceUrl;
  2958. /**
  2959. * Checks if the given value is a `TrustedResourceUrl` instance.
  2960. */
  2961. function isResourceUrl(value) {
  2962. return value instanceof exports.TrustedResourceUrl;
  2963. }
  2964. exports.isResourceUrl = isResourceUrl;
  2965. /**
  2966. * Returns the value of the passed `TrustedResourceUrl` object while ensuring it
  2967. * has the correct type.
  2968. *
  2969. * Returns a native `TrustedScriptURL` or a string if Trusted Types are
  2970. * disabled.
  2971. */
  2972. function unwrapResourceUrl(value) {
  2973. var _a;
  2974. if ((_a = (0, trusted_types_1.getTrustedTypes)()) === null || _a === void 0 ? void 0 : _a.isScriptURL(value)) {
  2975. return value;
  2976. }
  2977. else if (value instanceof ResourceUrlImpl) {
  2978. return value.privateDoNotAccessOrElseWrappedResourceUrl;
  2979. }
  2980. else {
  2981. var message = '';
  2982. if (true) {
  2983. message = 'Unexpected type when unwrapping TrustedResourceUrl';
  2984. }
  2985. throw new Error(message);
  2986. }
  2987. }
  2988. exports.unwrapResourceUrl = unwrapResourceUrl;
  2989. /***/ }),
  2990. /***/ "./node_modules/safevalues/internals/script_impl.js":
  2991. /*!**********************************************************!*\
  2992. !*** ./node_modules/safevalues/internals/script_impl.js ***!
  2993. \**********************************************************/
  2994. /*! no static exports found */
  2995. /***/ (function(module, exports, __webpack_require__) {
  2996. "use strict";
  2997. /**
  2998. * @license
  2999. * SPDX-License-Identifier: Apache-2.0
  3000. */
  3001. Object.defineProperty(exports, "__esModule", { value: true });
  3002. exports.unwrapScript = exports.isScript = exports.EMPTY_SCRIPT = exports.createScript = exports.SafeScript = void 0;
  3003. __webpack_require__(/*! ../environment/dev */ "./node_modules/safevalues/environment/dev.js");
  3004. /* g3_import_pure from './pure' */
  3005. var secrets_1 = __webpack_require__(/*! ./secrets */ "./node_modules/safevalues/internals/secrets.js");
  3006. var trusted_types_1 = __webpack_require__(/*! ./trusted_types */ "./node_modules/safevalues/internals/trusted_types.js");
  3007. /**
  3008. * Runtime implementation of `TrustedScript` in browswers that don't support it.
  3009. * script element.
  3010. */
  3011. var ScriptImpl = /** @class */ (function () {
  3012. function ScriptImpl(script, token) {
  3013. if (true) {
  3014. (0, secrets_1.ensureTokenIsValid)(token);
  3015. }
  3016. this.privateDoNotAccessOrElseWrappedScript = script;
  3017. }
  3018. ScriptImpl.prototype.toString = function () {
  3019. return this.privateDoNotAccessOrElseWrappedScript.toString();
  3020. };
  3021. return ScriptImpl;
  3022. }());
  3023. function createScriptInternal(script, trusted) {
  3024. return (trusted !== null && trusted !== void 0 ? trusted : new ScriptImpl(script, secrets_1.secretToken));
  3025. }
  3026. var GlobalTrustedScript = (typeof window !== undefined) ? window.TrustedScript : undefined;
  3027. /**
  3028. * Also exports the constructor so that instanceof checks work.
  3029. */
  3030. exports.SafeScript = (GlobalTrustedScript !== null && GlobalTrustedScript !== void 0 ? GlobalTrustedScript : ScriptImpl);
  3031. /**
  3032. * Builds a new `SafeScript` from the given string, without enforcing
  3033. * safety guarantees. It may cause side effects by creating a Trusted Types
  3034. * policy. This shouldn't be exposed to application developers, and must only be
  3035. * used as a step towards safe builders or safe constants.
  3036. */
  3037. function createScript(script) {
  3038. var _a;
  3039. /** @noinline */
  3040. var noinlineScript = script;
  3041. return createScriptInternal(noinlineScript, (_a = (0, trusted_types_1.getTrustedTypesPolicy)()) === null || _a === void 0 ? void 0 : _a.createScript(noinlineScript));
  3042. }
  3043. exports.createScript = createScript;
  3044. /**
  3045. * An empty `SafeScript` constant.
  3046. * Unlike the functions above, using this will not create a policy.
  3047. */
  3048. exports.EMPTY_SCRIPT =
  3049. /* #__PURE__ */ (function () { var _a; return createScriptInternal('', (_a = (0, trusted_types_1.getTrustedTypes)()) === null || _a === void 0 ? void 0 : _a.emptyScript); })();
  3050. /**
  3051. * Checks if the given value is a `SafeScript` instance.
  3052. */
  3053. function isScript(value) {
  3054. return value instanceof exports.SafeScript;
  3055. }
  3056. exports.isScript = isScript;
  3057. /**
  3058. * Returns the value of the passed `SafeScript` object while ensuring it
  3059. * has the correct type.
  3060. *
  3061. * Returns a native `TrustedScript` or a string if Trusted Types are disabled.
  3062. */
  3063. function unwrapScript(value) {
  3064. var _a;
  3065. if ((_a = (0, trusted_types_1.getTrustedTypes)()) === null || _a === void 0 ? void 0 : _a.isScript(value)) {
  3066. return value;
  3067. }
  3068. else if (value instanceof ScriptImpl) {
  3069. return value.privateDoNotAccessOrElseWrappedScript;
  3070. }
  3071. else {
  3072. var message = '';
  3073. if (true) {
  3074. message = 'Unexpected type when unwrapping SafeScript';
  3075. }
  3076. throw new Error(message);
  3077. }
  3078. }
  3079. exports.unwrapScript = unwrapScript;
  3080. /***/ }),
  3081. /***/ "./node_modules/safevalues/internals/secrets.js":
  3082. /*!******************************************************!*\
  3083. !*** ./node_modules/safevalues/internals/secrets.js ***!
  3084. \******************************************************/
  3085. /*! no static exports found */
  3086. /***/ (function(module, exports, __webpack_require__) {
  3087. "use strict";
  3088. /**
  3089. * @license
  3090. * SPDX-License-Identifier: Apache-2.0
  3091. */
  3092. Object.defineProperty(exports, "__esModule", { value: true });
  3093. exports.ensureTokenIsValid = exports.secretToken = void 0;
  3094. /**
  3095. * A secret token that must be passed to safe type constructors. It is only
  3096. * accessible from within safevalues, ensuring that unrestricted safe type
  3097. * creation is only possible within safevalues. In particular, this prevents
  3098. * forgery such as `safeHtmlValue.constructor('javascript:evil')`.
  3099. */
  3100. exports.secretToken = {};
  3101. /**
  3102. * Asserts that the given token matches the secret safevalues token. An
  3103. * exception is thrown if that is not the case.
  3104. */
  3105. function ensureTokenIsValid(token) {
  3106. if (token !== exports.secretToken) {
  3107. throw new Error('Bad secret');
  3108. }
  3109. }
  3110. exports.ensureTokenIsValid = ensureTokenIsValid;
  3111. /***/ }),
  3112. /***/ "./node_modules/safevalues/internals/string_literal.js":
  3113. /*!*************************************************************!*\
  3114. !*** ./node_modules/safevalues/internals/string_literal.js ***!
  3115. \*************************************************************/
  3116. /*! no static exports found */
  3117. /***/ (function(module, exports, __webpack_require__) {
  3118. "use strict";
  3119. /**
  3120. * @license
  3121. * SPDX-License-Identifier: Apache-2.0
  3122. */
  3123. Object.defineProperty(exports, "__esModule", { value: true });
  3124. exports.assertIsTemplateObject = void 0;
  3125. /**
  3126. * An object of type TemplateStringsArray represents the literal part(s) of a
  3127. * template literal. This function checks if a TemplateStringsArray object is
  3128. * actually from a template literal.
  3129. *
  3130. * @param templateObj This contains the literal part of the template literal.
  3131. * @param hasExprs If true, the input template may contain embedded expressions.
  3132. * @param errorMsg The custom error message in case any checks fail.
  3133. */
  3134. function assertIsTemplateObject(templateObj, hasExprs, errorMsg) {
  3135. if (!Array.isArray(templateObj) || !Array.isArray(templateObj.raw) ||
  3136. (!hasExprs && templateObj.length !== 1)) {
  3137. throw new TypeError(errorMsg);
  3138. }
  3139. }
  3140. exports.assertIsTemplateObject = assertIsTemplateObject;
  3141. /***/ }),
  3142. /***/ "./node_modules/safevalues/internals/style_impl.js":
  3143. /*!*********************************************************!*\
  3144. !*** ./node_modules/safevalues/internals/style_impl.js ***!
  3145. \*********************************************************/
  3146. /*! no static exports found */
  3147. /***/ (function(module, exports, __webpack_require__) {
  3148. "use strict";
  3149. /**
  3150. * @license
  3151. * SPDX-License-Identifier: Apache-2.0
  3152. */
  3153. var __extends = (this && this.__extends) || (function () {
  3154. var extendStatics = function (d, b) {
  3155. extendStatics = Object.setPrototypeOf ||
  3156. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3157. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  3158. return extendStatics(d, b);
  3159. };
  3160. return function (d, b) {
  3161. if (typeof b !== "function" && b !== null)
  3162. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  3163. extendStatics(d, b);
  3164. function __() { this.constructor = d; }
  3165. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3166. };
  3167. })();
  3168. Object.defineProperty(exports, "__esModule", { value: true });
  3169. exports.unwrapStyle = exports.isStyle = exports.createStyle = exports.SafeStyle = void 0;
  3170. __webpack_require__(/*! ../environment/dev */ "./node_modules/safevalues/environment/dev.js");
  3171. var secrets_1 = __webpack_require__(/*! ./secrets */ "./node_modules/safevalues/internals/secrets.js");
  3172. /**
  3173. * Sequence of CSS declarations safe to use in style contexts in an HTML
  3174. * document or in DOM APIs.
  3175. */
  3176. var SafeStyle = /** @class */ (function () {
  3177. function SafeStyle() {
  3178. }
  3179. return SafeStyle;
  3180. }());
  3181. exports.SafeStyle = SafeStyle;
  3182. /** Implementation for `SafeStyle` */
  3183. var StyleImpl = /** @class */ (function (_super) {
  3184. __extends(StyleImpl, _super);
  3185. function StyleImpl(style, token) {
  3186. var _this = _super.call(this) || this;
  3187. if (true) {
  3188. (0, secrets_1.ensureTokenIsValid)(token);
  3189. }
  3190. _this.privateDoNotAccessOrElseWrappedStyle = style;
  3191. return _this;
  3192. }
  3193. StyleImpl.prototype.toString = function () {
  3194. return this.privateDoNotAccessOrElseWrappedStyle;
  3195. };
  3196. return StyleImpl;
  3197. }(SafeStyle));
  3198. /**
  3199. * Builds a new `SafeStyle` from the given string, without enforcing
  3200. * safety guarantees. This shouldn't be exposed to application developers, and
  3201. * must only be used as a step towards safe builders or safe constants.
  3202. */
  3203. function createStyle(style) {
  3204. return new StyleImpl(style, secrets_1.secretToken);
  3205. }
  3206. exports.createStyle = createStyle;
  3207. /**
  3208. * Checks if the given value is a `SafeStyle` instance.
  3209. */
  3210. function isStyle(value) {
  3211. return value instanceof StyleImpl;
  3212. }
  3213. exports.isStyle = isStyle;
  3214. /**
  3215. * Returns the string value of the passed `SafeStyle` object while ensuring it
  3216. * has the correct type.
  3217. */
  3218. function unwrapStyle(value) {
  3219. if (value instanceof StyleImpl) {
  3220. return value.privateDoNotAccessOrElseWrappedStyle;
  3221. }
  3222. else {
  3223. var message = '';
  3224. if (true) {
  3225. message = 'Unexpected type when unwrapping SafeStyle';
  3226. }
  3227. throw new Error(message);
  3228. }
  3229. }
  3230. exports.unwrapStyle = unwrapStyle;
  3231. /***/ }),
  3232. /***/ "./node_modules/safevalues/internals/style_sheet_impl.js":
  3233. /*!***************************************************************!*\
  3234. !*** ./node_modules/safevalues/internals/style_sheet_impl.js ***!
  3235. \***************************************************************/
  3236. /*! no static exports found */
  3237. /***/ (function(module, exports, __webpack_require__) {
  3238. "use strict";
  3239. /**
  3240. * @license
  3241. * SPDX-License-Identifier: Apache-2.0
  3242. */
  3243. var __extends = (this && this.__extends) || (function () {
  3244. var extendStatics = function (d, b) {
  3245. extendStatics = Object.setPrototypeOf ||
  3246. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3247. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  3248. return extendStatics(d, b);
  3249. };
  3250. return function (d, b) {
  3251. if (typeof b !== "function" && b !== null)
  3252. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  3253. extendStatics(d, b);
  3254. function __() { this.constructor = d; }
  3255. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3256. };
  3257. })();
  3258. Object.defineProperty(exports, "__esModule", { value: true });
  3259. exports.unwrapStyleSheet = exports.isStyleSheet = exports.createStyleSheet = exports.SafeStyleSheet = void 0;
  3260. __webpack_require__(/*! ../environment/dev */ "./node_modules/safevalues/environment/dev.js");
  3261. var secrets_1 = __webpack_require__(/*! ./secrets */ "./node_modules/safevalues/internals/secrets.js");
  3262. /**
  3263. * A complete CSS style sheet, safe to use in style contexts in an HTML document
  3264. * or DOM APIs.
  3265. */
  3266. var SafeStyleSheet = /** @class */ (function () {
  3267. function SafeStyleSheet() {
  3268. }
  3269. return SafeStyleSheet;
  3270. }());
  3271. exports.SafeStyleSheet = SafeStyleSheet;
  3272. /** Implementation for `SafeStyleSheet` */
  3273. var StyleSheetImpl = /** @class */ (function (_super) {
  3274. __extends(StyleSheetImpl, _super);
  3275. function StyleSheetImpl(styleSheet, token) {
  3276. var _this = _super.call(this) || this;
  3277. if (true) {
  3278. (0, secrets_1.ensureTokenIsValid)(token);
  3279. }
  3280. _this.privateDoNotAccessOrElseWrappedStyleSheet = styleSheet;
  3281. return _this;
  3282. }
  3283. StyleSheetImpl.prototype.toString = function () {
  3284. return this.privateDoNotAccessOrElseWrappedStyleSheet;
  3285. };
  3286. return StyleSheetImpl;
  3287. }(SafeStyleSheet));
  3288. /**
  3289. * Builds a new `SafeStyleSheet` from the given string, without enforcing
  3290. * safety guarantees. This shouldn't be exposed to application developers, and
  3291. * must only be used as a step towards safe builders or safe constants.
  3292. */
  3293. function createStyleSheet(styleSheet) {
  3294. return new StyleSheetImpl(styleSheet, secrets_1.secretToken);
  3295. }
  3296. exports.createStyleSheet = createStyleSheet;
  3297. /**
  3298. * Checks if the given value is a `SafeStyleSheet` instance.
  3299. */
  3300. function isStyleSheet(value) {
  3301. return value instanceof StyleSheetImpl;
  3302. }
  3303. exports.isStyleSheet = isStyleSheet;
  3304. /**
  3305. * Returns the string value of the passed `SafeStyleSheet` object while
  3306. * ensuring it has the correct type.
  3307. */
  3308. function unwrapStyleSheet(value) {
  3309. if (value instanceof StyleSheetImpl) {
  3310. return value.privateDoNotAccessOrElseWrappedStyleSheet;
  3311. }
  3312. else {
  3313. var message = '';
  3314. if (true) {
  3315. message = 'Unexpected type when unwrapping SafeStyleSheet';
  3316. }
  3317. throw new Error(message);
  3318. }
  3319. }
  3320. exports.unwrapStyleSheet = unwrapStyleSheet;
  3321. /***/ }),
  3322. /***/ "./node_modules/safevalues/internals/trusted_types.js":
  3323. /*!************************************************************!*\
  3324. !*** ./node_modules/safevalues/internals/trusted_types.js ***!
  3325. \************************************************************/
  3326. /*! no static exports found */
  3327. /***/ (function(module, exports, __webpack_require__) {
  3328. "use strict";
  3329. /**
  3330. * @license
  3331. * SPDX-License-Identifier: Apache-2.0
  3332. */
  3333. Object.defineProperty(exports, "__esModule", { value: true });
  3334. exports.TEST_ONLY = exports.getTrustedTypesPolicy = exports.getTrustedTypes = void 0;
  3335. /**
  3336. * The name of the Trusted Types policy used by TS safevalues, or empty
  3337. * to disable Trusted Types. This duplicates the 'google#safe', but
  3338. * can be overridden in tests.
  3339. */
  3340. var trustedTypesPolicyName = 'google#safe';
  3341. /** Helper to retrieve the value of `window.trustedTypes`. */
  3342. function trustedTypes() {
  3343. if (typeof window !== 'undefined') {
  3344. return window.trustedTypes;
  3345. }
  3346. return undefined;
  3347. }
  3348. /**
  3349. * Returns window.trustedTypes if Trusted Types are enabled and supported, or
  3350. * null otherwise.
  3351. */
  3352. function getTrustedTypes() {
  3353. var _a;
  3354. return (trustedTypesPolicyName !== '') ? ((_a = trustedTypes()) !== null && _a !== void 0 ? _a : null) : null;
  3355. }
  3356. exports.getTrustedTypes = getTrustedTypes;
  3357. /**
  3358. * The Trusted Types policy used by TS safevalues, or null if Trusted Types
  3359. * are not enabled/supported, or undefined if the policy has not been created
  3360. * yet.
  3361. */
  3362. var trustedTypesPolicy;
  3363. /**
  3364. * Returns the Trusted Types policy used by TS safevalues, or null if Trusted
  3365. * Types are not enabled/supported. The first call to this function will
  3366. * create the policy.
  3367. */
  3368. function getTrustedTypesPolicy() {
  3369. var _a, _b;
  3370. if (trustedTypesPolicy === undefined) {
  3371. try {
  3372. trustedTypesPolicy =
  3373. (_b = (_a = getTrustedTypes()) === null || _a === void 0 ? void 0 : _a.createPolicy(trustedTypesPolicyName, {
  3374. createHTML: function (s) { return s; },
  3375. createScript: function (s) { return s; },
  3376. createScriptURL: function (s) { return s; }
  3377. })) !== null && _b !== void 0 ? _b : null;
  3378. }
  3379. catch (_c) {
  3380. // In Chromium versions before 81, trustedTypes.createPolicy throws if
  3381. // called with a name that is already registered, even if no CSP is set.
  3382. // Until users have largely migrated to 81 or above, catch the error not
  3383. // to break the applications functionally. In such case, the code will
  3384. // fall back to using regular Safe Types.
  3385. trustedTypesPolicy = null;
  3386. }
  3387. }
  3388. return trustedTypesPolicy;
  3389. }
  3390. exports.getTrustedTypesPolicy = getTrustedTypesPolicy;
  3391. /** Helpers for tests. */
  3392. exports.TEST_ONLY = {
  3393. resetDefaults: function () {
  3394. trustedTypesPolicy = undefined;
  3395. trustedTypesPolicyName = 'google#safe';
  3396. },
  3397. setTrustedTypesPolicyName: function (name) {
  3398. trustedTypesPolicyName = name;
  3399. },
  3400. };
  3401. /***/ }),
  3402. /***/ "./packages/mdc-animation/util.ts":
  3403. /*!****************************************!*\
  3404. !*** ./packages/mdc-animation/util.ts ***!
  3405. \****************************************/
  3406. /*! no static exports found */
  3407. /***/ (function(module, exports, __webpack_require__) {
  3408. "use strict";
  3409. /**
  3410. * @license
  3411. * Copyright 2016 Google Inc.
  3412. *
  3413. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3414. * of this software and associated documentation files (the "Software"), to deal
  3415. * in the Software without restriction, including without limitation the rights
  3416. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3417. * copies of the Software, and to permit persons to whom the Software is
  3418. * furnished to do so, subject to the following conditions:
  3419. *
  3420. * The above copyright notice and this permission notice shall be included in
  3421. * all copies or substantial portions of the Software.
  3422. *
  3423. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3424. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3425. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3426. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3427. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3428. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3429. * THE SOFTWARE.
  3430. */
  3431. Object.defineProperty(exports, "__esModule", { value: true });
  3432. exports.getCorrectEventName = exports.getCorrectPropertyName = void 0;
  3433. var cssPropertyNameMap = {
  3434. animation: {
  3435. prefixed: '-webkit-animation',
  3436. standard: 'animation'
  3437. },
  3438. transform: {
  3439. prefixed: '-webkit-transform',
  3440. standard: 'transform'
  3441. },
  3442. transition: {
  3443. prefixed: '-webkit-transition',
  3444. standard: 'transition'
  3445. }
  3446. };
  3447. var jsEventTypeMap = {
  3448. animationend: {
  3449. cssProperty: 'animation',
  3450. prefixed: 'webkitAnimationEnd',
  3451. standard: 'animationend'
  3452. },
  3453. animationiteration: {
  3454. cssProperty: 'animation',
  3455. prefixed: 'webkitAnimationIteration',
  3456. standard: 'animationiteration'
  3457. },
  3458. animationstart: {
  3459. cssProperty: 'animation',
  3460. prefixed: 'webkitAnimationStart',
  3461. standard: 'animationstart'
  3462. },
  3463. transitionend: {
  3464. cssProperty: 'transition',
  3465. prefixed: 'webkitTransitionEnd',
  3466. standard: 'transitionend'
  3467. }
  3468. };
  3469. function isWindow(windowObj) {
  3470. return Boolean(windowObj.document) && typeof windowObj.document.createElement === 'function';
  3471. }
  3472. function getCorrectPropertyName(windowObj, cssProperty) {
  3473. if (isWindow(windowObj) && cssProperty in cssPropertyNameMap) {
  3474. var el = windowObj.document.createElement('div');
  3475. var _a = cssPropertyNameMap[cssProperty],
  3476. standard = _a.standard,
  3477. prefixed = _a.prefixed;
  3478. var isStandard = standard in el.style;
  3479. return isStandard ? standard : prefixed;
  3480. }
  3481. return cssProperty;
  3482. }
  3483. exports.getCorrectPropertyName = getCorrectPropertyName;
  3484. function getCorrectEventName(windowObj, eventType) {
  3485. if (isWindow(windowObj) && eventType in jsEventTypeMap) {
  3486. var el = windowObj.document.createElement('div');
  3487. var _a = jsEventTypeMap[eventType],
  3488. standard = _a.standard,
  3489. prefixed = _a.prefixed,
  3490. cssProperty = _a.cssProperty;
  3491. var isStandard = cssProperty in el.style;
  3492. return isStandard ? standard : prefixed;
  3493. }
  3494. return eventType;
  3495. }
  3496. exports.getCorrectEventName = getCorrectEventName;
  3497. /***/ }),
  3498. /***/ "./packages/mdc-base/component.ts":
  3499. /*!****************************************!*\
  3500. !*** ./packages/mdc-base/component.ts ***!
  3501. \****************************************/
  3502. /*! no static exports found */
  3503. /***/ (function(module, exports, __webpack_require__) {
  3504. "use strict";
  3505. /**
  3506. * @license
  3507. * Copyright 2016 Google Inc.
  3508. *
  3509. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3510. * of this software and associated documentation files (the "Software"), to deal
  3511. * in the Software without restriction, including without limitation the rights
  3512. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3513. * copies of the Software, and to permit persons to whom the Software is
  3514. * furnished to do so, subject to the following conditions:
  3515. *
  3516. * The above copyright notice and this permission notice shall be included in
  3517. * all copies or substantial portions of the Software.
  3518. *
  3519. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3520. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3521. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3522. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3523. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3524. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3525. * THE SOFTWARE.
  3526. */
  3527. var __makeTemplateObject = this && this.__makeTemplateObject || function (cooked, raw) {
  3528. if (Object.defineProperty) {
  3529. Object.defineProperty(cooked, "raw", { value: raw });
  3530. } else {
  3531. cooked.raw = raw;
  3532. }
  3533. return cooked;
  3534. };
  3535. var __read = this && this.__read || function (o, n) {
  3536. var m = typeof Symbol === "function" && o[Symbol.iterator];
  3537. if (!m) return o;
  3538. var i = m.call(o),
  3539. r,
  3540. ar = [],
  3541. e;
  3542. try {
  3543. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
  3544. ar.push(r.value);
  3545. }
  3546. } catch (error) {
  3547. e = { error: error };
  3548. } finally {
  3549. try {
  3550. if (r && !r.done && (m = i["return"])) m.call(i);
  3551. } finally {
  3552. if (e) throw e.error;
  3553. }
  3554. }
  3555. return ar;
  3556. };
  3557. var __spreadArray = this && this.__spreadArray || function (to, from) {
  3558. for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) {
  3559. to[j] = from[i];
  3560. }return to;
  3561. };
  3562. Object.defineProperty(exports, "__esModule", { value: true });
  3563. exports.MDCComponent = void 0;
  3564. var safevalues_1 = __webpack_require__(/*! safevalues */ "./node_modules/safevalues/index.js");
  3565. var dom_1 = __webpack_require__(/*! safevalues/dom */ "./node_modules/safevalues/dom/index.js");
  3566. var foundation_1 = __webpack_require__(/*! ./foundation */ "./packages/mdc-base/foundation.ts");
  3567. function toCamelCase(str) {
  3568. // tslint:disable-next-line:enforce-name-casing
  3569. return String(str).replace(/\-([a-z])/g, function (_, match) {
  3570. return match.toUpperCase();
  3571. });
  3572. }
  3573. /** MDC Component base */
  3574. var MDCComponent = /** @class */function () {
  3575. function MDCComponent(root, foundation) {
  3576. var args = [];
  3577. for (var _i = 2; _i < arguments.length; _i++) {
  3578. args[_i - 2] = arguments[_i];
  3579. }
  3580. this.root = root;
  3581. this.initialize.apply(this, __spreadArray([], __read(args)));
  3582. // Note that we initialize foundation here and not within the constructor's
  3583. // default param so that this.root is defined and can be used within the
  3584. // foundation class.
  3585. this.foundation = foundation === undefined ? this.getDefaultFoundation() : foundation;
  3586. this.foundation.init();
  3587. this.initialSyncWithDOM();
  3588. }
  3589. MDCComponent.attachTo = function (root) {
  3590. // Subclasses which extend MDCBase should provide an attachTo() method that
  3591. // takes a root element and returns an instantiated component with its root
  3592. // set to that element. Also note that in the cases of subclasses, an
  3593. // explicit foundation class will not have to be passed in; it will simply
  3594. // be initialized from getDefaultFoundation().
  3595. return new MDCComponent(root, new foundation_1.MDCFoundation({}));
  3596. };
  3597. /* istanbul ignore next: method param only exists for typing purposes; it does
  3598. * not need to be unit tested */
  3599. // tslint:disable-next-line:enforce-name-casing
  3600. MDCComponent.prototype.initialize = function () {
  3601. var _args = [];
  3602. for (var _i = 0; _i < arguments.length; _i++) {
  3603. _args[_i] = arguments[_i];
  3604. }
  3605. // Subclasses can override this to do any additional setup work that would
  3606. // be considered part of a "constructor". Essentially, it is a hook into the
  3607. // parent constructor before the foundation is initialized. Any additional
  3608. // arguments besides root and foundation will be passed in here.
  3609. };
  3610. MDCComponent.prototype.getDefaultFoundation = function () {
  3611. // Subclasses must override this method to return a properly configured
  3612. // foundation class for the component.
  3613. throw new Error('Subclasses must override getDefaultFoundation to return a properly configured ' + 'foundation class');
  3614. };
  3615. MDCComponent.prototype.initialSyncWithDOM = function () {
  3616. // Subclasses should override this method if they need to perform work to
  3617. // synchronize with a host DOM object. An example of this would be a form
  3618. // control wrapper that needs to synchronize its internal state to some
  3619. // property or attribute of the host DOM. Please note: this is *not* the
  3620. // place to perform DOM reads/writes that would cause layout / paint, as
  3621. // this is called synchronously from within the constructor.
  3622. };
  3623. MDCComponent.prototype.destroy = function () {
  3624. // Subclasses may implement this method to release any resources /
  3625. // deregister any listeners they have attached. An example of this might be
  3626. // deregistering a resize event from the window object.
  3627. this.foundation.destroy();
  3628. };
  3629. MDCComponent.prototype.listen = function (evtType, handler, options) {
  3630. this.root.addEventListener(evtType, handler, options);
  3631. };
  3632. MDCComponent.prototype.unlisten = function (evtType, handler, options) {
  3633. this.root.removeEventListener(evtType, handler, options);
  3634. };
  3635. /**
  3636. * Fires a cross-browser-compatible custom event from the component root of
  3637. * the given type, with the given data.
  3638. */
  3639. MDCComponent.prototype.emit = function (evtType, evtData, shouldBubble) {
  3640. if (shouldBubble === void 0) {
  3641. shouldBubble = false;
  3642. }
  3643. var evt;
  3644. if (typeof CustomEvent === 'function') {
  3645. evt = new CustomEvent(evtType, {
  3646. bubbles: shouldBubble,
  3647. detail: evtData
  3648. });
  3649. } else {
  3650. evt = document.createEvent('CustomEvent');
  3651. evt.initCustomEvent(evtType, shouldBubble, false, evtData);
  3652. }
  3653. this.root.dispatchEvent(evt);
  3654. };
  3655. /**
  3656. * This is a intermediate fix to allow components to use safevalues. This
  3657. * limits setAttribute to setting tabindex, data attributes, and aria
  3658. * attributes.
  3659. *
  3660. * TODO(b/263990206): remove this method and add these directly in each
  3661. * component. This will remove this abstraction and make it clear that the
  3662. * caller can't set any attribute.
  3663. */
  3664. MDCComponent.prototype.safeSetAttribute = function (element, attribute, value) {
  3665. if (attribute.toLowerCase() === 'tabindex') {
  3666. element.tabIndex = Number(value);
  3667. } else if (attribute.indexOf('data-') === 0) {
  3668. var dataKey = toCamelCase(attribute.replace(/^data-/, ''));
  3669. element.dataset[dataKey] = value;
  3670. } else {
  3671. dom_1.safeElement.setPrefixedAttribute([safevalues_1.safeAttrPrefix(templateObject_1 || (templateObject_1 = __makeTemplateObject(["aria-"], ["aria-"]))), safevalues_1.safeAttrPrefix(templateObject_2 || (templateObject_2 = __makeTemplateObject(["role"], ["role"])))], element, attribute, value);
  3672. }
  3673. };
  3674. return MDCComponent;
  3675. }();
  3676. exports.MDCComponent = MDCComponent;
  3677. // tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
  3678. exports.default = MDCComponent;
  3679. var templateObject_1, templateObject_2;
  3680. /***/ }),
  3681. /***/ "./packages/mdc-base/foundation.ts":
  3682. /*!*****************************************!*\
  3683. !*** ./packages/mdc-base/foundation.ts ***!
  3684. \*****************************************/
  3685. /*! no static exports found */
  3686. /***/ (function(module, exports, __webpack_require__) {
  3687. "use strict";
  3688. /**
  3689. * @license
  3690. * Copyright 2016 Google Inc.
  3691. *
  3692. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3693. * of this software and associated documentation files (the "Software"), to deal
  3694. * in the Software without restriction, including without limitation the rights
  3695. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3696. * copies of the Software, and to permit persons to whom the Software is
  3697. * furnished to do so, subject to the following conditions:
  3698. *
  3699. * The above copyright notice and this permission notice shall be included in
  3700. * all copies or substantial portions of the Software.
  3701. *
  3702. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3703. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3704. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3705. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3706. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3707. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3708. * THE SOFTWARE.
  3709. */
  3710. Object.defineProperty(exports, "__esModule", { value: true });
  3711. exports.MDCFoundation = void 0;
  3712. /** MDC Foundation */
  3713. var MDCFoundation = /** @class */function () {
  3714. function MDCFoundation(adapter) {
  3715. if (adapter === void 0) {
  3716. adapter = {};
  3717. }
  3718. this.adapter = adapter;
  3719. }
  3720. Object.defineProperty(MDCFoundation, "cssClasses", {
  3721. get: function get() {
  3722. // Classes extending MDCFoundation should implement this method to return an
  3723. // object which exports every CSS class the foundation class needs as a
  3724. // property. e.g. {ACTIVE: 'mdc-component--active'}
  3725. return {};
  3726. },
  3727. enumerable: false,
  3728. configurable: true
  3729. });
  3730. Object.defineProperty(MDCFoundation, "strings", {
  3731. get: function get() {
  3732. // Classes extending MDCFoundation should implement this method to return an
  3733. // object which exports all semantic strings as constants. e.g. {ARIA_ROLE:
  3734. // 'tablist'}
  3735. return {};
  3736. },
  3737. enumerable: false,
  3738. configurable: true
  3739. });
  3740. Object.defineProperty(MDCFoundation, "numbers", {
  3741. get: function get() {
  3742. // Classes extending MDCFoundation should implement this method to return an
  3743. // object which exports all of its semantic numbers as constants.
  3744. // e.g. {ANIMATION_DELAY_MS: 350}
  3745. return {};
  3746. },
  3747. enumerable: false,
  3748. configurable: true
  3749. });
  3750. Object.defineProperty(MDCFoundation, "defaultAdapter", {
  3751. get: function get() {
  3752. // Classes extending MDCFoundation may choose to implement this getter in
  3753. // order to provide a convenient way of viewing the necessary methods of an
  3754. // adapter. In the future, this could also be used for adapter validation.
  3755. return {};
  3756. },
  3757. enumerable: false,
  3758. configurable: true
  3759. });
  3760. MDCFoundation.prototype.init = function () {
  3761. // Subclasses should override this method to perform initialization routines
  3762. // (registering events, etc.)
  3763. };
  3764. MDCFoundation.prototype.destroy = function () {
  3765. // Subclasses should override this method to perform de-initialization
  3766. // routines (de-registering events, etc.)
  3767. };
  3768. return MDCFoundation;
  3769. }();
  3770. exports.MDCFoundation = MDCFoundation;
  3771. // tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
  3772. exports.default = MDCFoundation;
  3773. /***/ }),
  3774. /***/ "./packages/mdc-dom/keyboard.ts":
  3775. /*!**************************************!*\
  3776. !*** ./packages/mdc-dom/keyboard.ts ***!
  3777. \**************************************/
  3778. /*! no static exports found */
  3779. /***/ (function(module, exports, __webpack_require__) {
  3780. "use strict";
  3781. /**
  3782. * @license
  3783. * Copyright 2020 Google Inc.
  3784. *
  3785. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3786. * of this software and associated documentation files (the "Software"), to deal
  3787. * in the Software without restriction, including without limitation the rights
  3788. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3789. * copies of the Software, and to permit persons to whom the Software is
  3790. * furnished to do so, subject to the following conditions:
  3791. *
  3792. * The above copyright notice and this permission notice shall be included in
  3793. * all copies or substantial portions of the Software.
  3794. *
  3795. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3796. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3797. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3798. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3799. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3800. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3801. * THE SOFTWARE.
  3802. */
  3803. Object.defineProperty(exports, "__esModule", { value: true });
  3804. exports.isNavigationEvent = exports.normalizeKey = exports.KEY = void 0;
  3805. /**
  3806. * KEY provides normalized string values for keys.
  3807. */
  3808. exports.KEY = {
  3809. UNKNOWN: 'Unknown',
  3810. BACKSPACE: 'Backspace',
  3811. ENTER: 'Enter',
  3812. SPACEBAR: 'Spacebar',
  3813. PAGE_UP: 'PageUp',
  3814. PAGE_DOWN: 'PageDown',
  3815. END: 'End',
  3816. HOME: 'Home',
  3817. ARROW_LEFT: 'ArrowLeft',
  3818. ARROW_UP: 'ArrowUp',
  3819. ARROW_RIGHT: 'ArrowRight',
  3820. ARROW_DOWN: 'ArrowDown',
  3821. DELETE: 'Delete',
  3822. ESCAPE: 'Escape',
  3823. TAB: 'Tab'
  3824. };
  3825. var normalizedKeys = new Set();
  3826. // IE11 has no support for new Map with iterable so we need to initialize this
  3827. // by hand.
  3828. normalizedKeys.add(exports.KEY.BACKSPACE);
  3829. normalizedKeys.add(exports.KEY.ENTER);
  3830. normalizedKeys.add(exports.KEY.SPACEBAR);
  3831. normalizedKeys.add(exports.KEY.PAGE_UP);
  3832. normalizedKeys.add(exports.KEY.PAGE_DOWN);
  3833. normalizedKeys.add(exports.KEY.END);
  3834. normalizedKeys.add(exports.KEY.HOME);
  3835. normalizedKeys.add(exports.KEY.ARROW_LEFT);
  3836. normalizedKeys.add(exports.KEY.ARROW_UP);
  3837. normalizedKeys.add(exports.KEY.ARROW_RIGHT);
  3838. normalizedKeys.add(exports.KEY.ARROW_DOWN);
  3839. normalizedKeys.add(exports.KEY.DELETE);
  3840. normalizedKeys.add(exports.KEY.ESCAPE);
  3841. normalizedKeys.add(exports.KEY.TAB);
  3842. var KEY_CODE = {
  3843. BACKSPACE: 8,
  3844. ENTER: 13,
  3845. SPACEBAR: 32,
  3846. PAGE_UP: 33,
  3847. PAGE_DOWN: 34,
  3848. END: 35,
  3849. HOME: 36,
  3850. ARROW_LEFT: 37,
  3851. ARROW_UP: 38,
  3852. ARROW_RIGHT: 39,
  3853. ARROW_DOWN: 40,
  3854. DELETE: 46,
  3855. ESCAPE: 27,
  3856. TAB: 9
  3857. };
  3858. var mappedKeyCodes = new Map();
  3859. // IE11 has no support for new Map with iterable so we need to initialize this
  3860. // by hand.
  3861. mappedKeyCodes.set(KEY_CODE.BACKSPACE, exports.KEY.BACKSPACE);
  3862. mappedKeyCodes.set(KEY_CODE.ENTER, exports.KEY.ENTER);
  3863. mappedKeyCodes.set(KEY_CODE.SPACEBAR, exports.KEY.SPACEBAR);
  3864. mappedKeyCodes.set(KEY_CODE.PAGE_UP, exports.KEY.PAGE_UP);
  3865. mappedKeyCodes.set(KEY_CODE.PAGE_DOWN, exports.KEY.PAGE_DOWN);
  3866. mappedKeyCodes.set(KEY_CODE.END, exports.KEY.END);
  3867. mappedKeyCodes.set(KEY_CODE.HOME, exports.KEY.HOME);
  3868. mappedKeyCodes.set(KEY_CODE.ARROW_LEFT, exports.KEY.ARROW_LEFT);
  3869. mappedKeyCodes.set(KEY_CODE.ARROW_UP, exports.KEY.ARROW_UP);
  3870. mappedKeyCodes.set(KEY_CODE.ARROW_RIGHT, exports.KEY.ARROW_RIGHT);
  3871. mappedKeyCodes.set(KEY_CODE.ARROW_DOWN, exports.KEY.ARROW_DOWN);
  3872. mappedKeyCodes.set(KEY_CODE.DELETE, exports.KEY.DELETE);
  3873. mappedKeyCodes.set(KEY_CODE.ESCAPE, exports.KEY.ESCAPE);
  3874. mappedKeyCodes.set(KEY_CODE.TAB, exports.KEY.TAB);
  3875. var navigationKeys = new Set();
  3876. // IE11 has no support for new Set with iterable so we need to initialize this
  3877. // by hand.
  3878. navigationKeys.add(exports.KEY.PAGE_UP);
  3879. navigationKeys.add(exports.KEY.PAGE_DOWN);
  3880. navigationKeys.add(exports.KEY.END);
  3881. navigationKeys.add(exports.KEY.HOME);
  3882. navigationKeys.add(exports.KEY.ARROW_LEFT);
  3883. navigationKeys.add(exports.KEY.ARROW_UP);
  3884. navigationKeys.add(exports.KEY.ARROW_RIGHT);
  3885. navigationKeys.add(exports.KEY.ARROW_DOWN);
  3886. /**
  3887. * normalizeKey returns the normalized string for a navigational action.
  3888. */
  3889. function normalizeKey(evt) {
  3890. var key = evt.key;
  3891. // If the event already has a normalized key, return it
  3892. if (normalizedKeys.has(key)) {
  3893. return key;
  3894. }
  3895. // tslint:disable-next-line:deprecation
  3896. var mappedKey = mappedKeyCodes.get(evt.keyCode);
  3897. if (mappedKey) {
  3898. return mappedKey;
  3899. }
  3900. return exports.KEY.UNKNOWN;
  3901. }
  3902. exports.normalizeKey = normalizeKey;
  3903. /**
  3904. * isNavigationEvent returns whether the event is a navigation event
  3905. */
  3906. function isNavigationEvent(evt) {
  3907. return navigationKeys.has(normalizeKey(evt));
  3908. }
  3909. exports.isNavigationEvent = isNavigationEvent;
  3910. /***/ }),
  3911. /***/ "./packages/mdc-dom/ponyfill.ts":
  3912. /*!**************************************!*\
  3913. !*** ./packages/mdc-dom/ponyfill.ts ***!
  3914. \**************************************/
  3915. /*! no static exports found */
  3916. /***/ (function(module, exports, __webpack_require__) {
  3917. "use strict";
  3918. /**
  3919. * @license
  3920. * Copyright 2018 Google Inc.
  3921. *
  3922. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3923. * of this software and associated documentation files (the "Software"), to deal
  3924. * in the Software without restriction, including without limitation the rights
  3925. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3926. * copies of the Software, and to permit persons to whom the Software is
  3927. * furnished to do so, subject to the following conditions:
  3928. *
  3929. * The above copyright notice and this permission notice shall be included in
  3930. * all copies or substantial portions of the Software.
  3931. *
  3932. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3933. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3934. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3935. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3936. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3937. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3938. * THE SOFTWARE.
  3939. */
  3940. Object.defineProperty(exports, "__esModule", { value: true });
  3941. exports.estimateScrollWidth = exports.matches = exports.closest = void 0;
  3942. /**
  3943. * @fileoverview A "ponyfill" is a polyfill that doesn't modify the global
  3944. * prototype chain. This makes ponyfills safer than traditional polyfills,
  3945. * especially for libraries like MDC.
  3946. */
  3947. function closest(element, selector) {
  3948. if (element.closest) {
  3949. return element.closest(selector);
  3950. }
  3951. var el = element;
  3952. while (el) {
  3953. if (matches(el, selector)) {
  3954. return el;
  3955. }
  3956. el = el.parentElement;
  3957. }
  3958. return null;
  3959. }
  3960. exports.closest = closest;
  3961. /** Element.matches with support for webkit and IE. */
  3962. function matches(element, selector) {
  3963. var nativeMatches = element.matches || element.webkitMatchesSelector || element.msMatchesSelector;
  3964. return nativeMatches.call(element, selector);
  3965. }
  3966. exports.matches = matches;
  3967. /**
  3968. * Used to compute the estimated scroll width of elements. When an element is
  3969. * hidden due to display: none; being applied to a parent element, the width is
  3970. * returned as 0. However, the element will have a true width once no longer
  3971. * inside a display: none context. This method computes an estimated width when
  3972. * the element is hidden or returns the true width when the element is visble.
  3973. * @param {Element} element the element whose width to estimate
  3974. */
  3975. function estimateScrollWidth(element) {
  3976. // Check the offsetParent. If the element inherits display: none from any
  3977. // parent, the offsetParent property will be null (see
  3978. // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent).
  3979. // This check ensures we only clone the node when necessary.
  3980. var htmlEl = element;
  3981. if (htmlEl.offsetParent !== null) {
  3982. return htmlEl.scrollWidth;
  3983. }
  3984. var clone = htmlEl.cloneNode(true);
  3985. clone.style.setProperty('position', 'absolute');
  3986. clone.style.setProperty('transform', 'translate(-9999px, -9999px)');
  3987. document.documentElement.appendChild(clone);
  3988. var scrollWidth = clone.scrollWidth;
  3989. document.documentElement.removeChild(clone);
  3990. return scrollWidth;
  3991. }
  3992. exports.estimateScrollWidth = estimateScrollWidth;
  3993. /***/ }),
  3994. /***/ "./packages/mdc-list/component.ts":
  3995. /*!****************************************!*\
  3996. !*** ./packages/mdc-list/component.ts ***!
  3997. \****************************************/
  3998. /*! no static exports found */
  3999. /***/ (function(module, exports, __webpack_require__) {
  4000. "use strict";
  4001. /**
  4002. * @license
  4003. * Copyright 2018 Google Inc.
  4004. *
  4005. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4006. * of this software and associated documentation files (the "Software"), to deal
  4007. * in the Software without restriction, including without limitation the rights
  4008. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4009. * copies of the Software, and to permit persons to whom the Software is
  4010. * furnished to do so, subject to the following conditions:
  4011. *
  4012. * The above copyright notice and this permission notice shall be included in
  4013. * all copies or substantial portions of the Software.
  4014. *
  4015. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4016. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4017. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4018. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4019. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4020. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4021. * THE SOFTWARE.
  4022. */
  4023. var __extends = this && this.__extends || function () {
  4024. var _extendStatics = function extendStatics(d, b) {
  4025. _extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
  4026. d.__proto__ = b;
  4027. } || function (d, b) {
  4028. for (var p in b) {
  4029. if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
  4030. }
  4031. };
  4032. return _extendStatics(d, b);
  4033. };
  4034. return function (d, b) {
  4035. if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  4036. _extendStatics(d, b);
  4037. function __() {
  4038. this.constructor = d;
  4039. }
  4040. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4041. };
  4042. }();
  4043. Object.defineProperty(exports, "__esModule", { value: true });
  4044. exports.MDCList = void 0;
  4045. var component_1 = __webpack_require__(/*! @material/base/component */ "./packages/mdc-base/component.ts");
  4046. var ponyfill_1 = __webpack_require__(/*! @material/dom/ponyfill */ "./packages/mdc-dom/ponyfill.ts");
  4047. var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-list/constants.ts");
  4048. var foundation_1 = __webpack_require__(/*! ./foundation */ "./packages/mdc-list/foundation.ts");
  4049. /** MDC List */
  4050. var MDCList = /** @class */function (_super) {
  4051. __extends(MDCList, _super);
  4052. function MDCList() {
  4053. return _super !== null && _super.apply(this, arguments) || this;
  4054. }
  4055. Object.defineProperty(MDCList.prototype, "vertical", {
  4056. set: function set(value) {
  4057. this.foundation.setVerticalOrientation(value);
  4058. },
  4059. enumerable: false,
  4060. configurable: true
  4061. });
  4062. Object.defineProperty(MDCList.prototype, "listElements", {
  4063. get: function get() {
  4064. return Array.from(this.root.querySelectorAll("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS]));
  4065. },
  4066. enumerable: false,
  4067. configurable: true
  4068. });
  4069. Object.defineProperty(MDCList.prototype, "wrapFocus", {
  4070. set: function set(value) {
  4071. this.foundation.setWrapFocus(value);
  4072. },
  4073. enumerable: false,
  4074. configurable: true
  4075. });
  4076. Object.defineProperty(MDCList.prototype, "typeaheadInProgress", {
  4077. /**
  4078. * @return Whether typeahead is currently matching a user-specified prefix.
  4079. */
  4080. get: function get() {
  4081. return this.foundation.isTypeaheadInProgress();
  4082. },
  4083. enumerable: false,
  4084. configurable: true
  4085. });
  4086. Object.defineProperty(MDCList.prototype, "hasTypeahead", {
  4087. /**
  4088. * Sets whether typeahead functionality is enabled on the list.
  4089. * @param hasTypeahead Whether typeahead is enabled.
  4090. */
  4091. set: function set(hasTypeahead) {
  4092. this.foundation.setHasTypeahead(hasTypeahead);
  4093. },
  4094. enumerable: false,
  4095. configurable: true
  4096. });
  4097. Object.defineProperty(MDCList.prototype, "singleSelection", {
  4098. set: function set(isSingleSelectionList) {
  4099. this.foundation.setSingleSelection(isSingleSelectionList);
  4100. },
  4101. enumerable: false,
  4102. configurable: true
  4103. });
  4104. Object.defineProperty(MDCList.prototype, "disabledItemsFocusable", {
  4105. set: function set(areDisabledItemsFocusable) {
  4106. this.foundation.setDisabledItemsFocusable(areDisabledItemsFocusable);
  4107. },
  4108. enumerable: false,
  4109. configurable: true
  4110. });
  4111. Object.defineProperty(MDCList.prototype, "selectedIndex", {
  4112. get: function get() {
  4113. return this.foundation.getSelectedIndex();
  4114. },
  4115. set: function set(index) {
  4116. this.foundation.setSelectedIndex(index);
  4117. },
  4118. enumerable: false,
  4119. configurable: true
  4120. });
  4121. MDCList.attachTo = function (root) {
  4122. return new MDCList(root);
  4123. };
  4124. MDCList.prototype.initialSyncWithDOM = function () {
  4125. this.isEvolutionEnabled = constants_1.evolutionAttribute in this.root.dataset;
  4126. if (this.isEvolutionEnabled) {
  4127. this.classNameMap = constants_1.evolutionClassNameMap;
  4128. } else if (ponyfill_1.matches(this.root, constants_1.strings.DEPRECATED_SELECTOR)) {
  4129. this.classNameMap = constants_1.deprecatedClassNameMap;
  4130. } else {
  4131. this.classNameMap = Object.values(constants_1.cssClasses).reduce(function (obj, className) {
  4132. obj[className] = className;
  4133. return obj;
  4134. }, {});
  4135. }
  4136. this.handleClick = this.handleClickEvent.bind(this);
  4137. this.handleKeydown = this.handleKeydownEvent.bind(this);
  4138. this.focusInEventListener = this.handleFocusInEvent.bind(this);
  4139. this.focusOutEventListener = this.handleFocusOutEvent.bind(this);
  4140. this.listen('keydown', this.handleKeydown);
  4141. this.listen('click', this.handleClick);
  4142. this.listen('focusin', this.focusInEventListener);
  4143. this.listen('focusout', this.focusOutEventListener);
  4144. this.layout();
  4145. this.initializeListType();
  4146. this.ensureFocusable();
  4147. };
  4148. MDCList.prototype.destroy = function () {
  4149. this.unlisten('keydown', this.handleKeydown);
  4150. this.unlisten('click', this.handleClick);
  4151. this.unlisten('focusin', this.focusInEventListener);
  4152. this.unlisten('focusout', this.focusOutEventListener);
  4153. };
  4154. MDCList.prototype.layout = function () {
  4155. var direction = this.root.getAttribute(constants_1.strings.ARIA_ORIENTATION);
  4156. this.vertical = direction !== constants_1.strings.ARIA_ORIENTATION_HORIZONTAL;
  4157. var itemSelector = "." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS] + ":not([tabindex])";
  4158. var childSelector = constants_1.strings.FOCUSABLE_CHILD_ELEMENTS;
  4159. // List items need to have at least tabindex=-1 to be focusable.
  4160. var itemEls = this.root.querySelectorAll(itemSelector);
  4161. if (itemEls.length) {
  4162. Array.prototype.forEach.call(itemEls, function (el) {
  4163. el.setAttribute('tabindex', '-1');
  4164. });
  4165. }
  4166. // Child button/a elements are not tabbable until the list item is focused.
  4167. var focusableChildEls = this.root.querySelectorAll(childSelector);
  4168. if (focusableChildEls.length) {
  4169. Array.prototype.forEach.call(focusableChildEls, function (el) {
  4170. el.setAttribute('tabindex', '-1');
  4171. });
  4172. }
  4173. if (this.isEvolutionEnabled) {
  4174. this.foundation.setUseSelectedAttribute(true);
  4175. }
  4176. this.foundation.layout();
  4177. };
  4178. /**
  4179. * Extracts the primary text from a list item.
  4180. * @param item The list item element.
  4181. * @return The primary text in the element.
  4182. */
  4183. MDCList.prototype.getPrimaryText = function (item) {
  4184. var _a;
  4185. var primaryText = item.querySelector("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS]);
  4186. if (this.isEvolutionEnabled || primaryText) {
  4187. return (_a = primaryText === null || primaryText === void 0 ? void 0 : primaryText.textContent) !== null && _a !== void 0 ? _a : '';
  4188. }
  4189. var singleLineText = item.querySelector("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_TEXT_CLASS]);
  4190. return singleLineText && singleLineText.textContent || '';
  4191. };
  4192. /**
  4193. * Initialize selectedIndex value based on pre-selected list items.
  4194. */
  4195. MDCList.prototype.initializeListType = function () {
  4196. var _this = this;
  4197. this.isInteractive = ponyfill_1.matches(this.root, constants_1.strings.ARIA_INTERACTIVE_ROLES_SELECTOR);
  4198. if (this.isEvolutionEnabled && this.isInteractive) {
  4199. var selection = Array.from(this.root.querySelectorAll(constants_1.strings.SELECTED_ITEM_SELECTOR), function (listItem) {
  4200. return _this.listElements.indexOf(listItem);
  4201. });
  4202. if (ponyfill_1.matches(this.root, constants_1.strings.ARIA_MULTI_SELECTABLE_SELECTOR)) {
  4203. this.selectedIndex = selection;
  4204. } else if (selection.length > 0) {
  4205. this.selectedIndex = selection[0];
  4206. }
  4207. return;
  4208. }
  4209. var checkboxListItems = this.root.querySelectorAll(constants_1.strings.ARIA_ROLE_CHECKBOX_SELECTOR);
  4210. var radioSelectedListItem = this.root.querySelector(constants_1.strings.ARIA_CHECKED_RADIO_SELECTOR);
  4211. if (checkboxListItems.length) {
  4212. var preselectedItems = this.root.querySelectorAll(constants_1.strings.ARIA_CHECKED_CHECKBOX_SELECTOR);
  4213. this.selectedIndex = Array.from(preselectedItems, function (listItem) {
  4214. return _this.listElements.indexOf(listItem);
  4215. });
  4216. } else if (radioSelectedListItem) {
  4217. this.selectedIndex = this.listElements.indexOf(radioSelectedListItem);
  4218. }
  4219. };
  4220. /**
  4221. * Updates the list item at itemIndex to the desired isEnabled state.
  4222. * @param itemIndex Index of the list item
  4223. * @param isEnabled Sets the list item to enabled or disabled.
  4224. */
  4225. MDCList.prototype.setEnabled = function (itemIndex, isEnabled) {
  4226. this.foundation.setEnabled(itemIndex, isEnabled);
  4227. };
  4228. /**
  4229. * Given the next desired character from the user, adds it to the typeahead
  4230. * buffer. Then, attempts to find the next option matching the buffer. Wraps
  4231. * around if at the end of options.
  4232. *
  4233. * @param nextChar The next character to add to the prefix buffer.
  4234. * @param startingIndex The index from which to start matching. Defaults to
  4235. * the currently focused index.
  4236. * @return The index of the matched item.
  4237. */
  4238. MDCList.prototype.typeaheadMatchItem = function (nextChar, startingIndex) {
  4239. return this.foundation.typeaheadMatchItem(nextChar, startingIndex, /** skipFocus */true);
  4240. };
  4241. MDCList.prototype.getDefaultFoundation = function () {
  4242. var _this = this;
  4243. // DO NOT INLINE this variable. For backward compatibility, foundations take
  4244. // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
  4245. // methods, we need a separate, strongly typed adapter variable.
  4246. var adapter = {
  4247. addClassForElementIndex: function addClassForElementIndex(index, className) {
  4248. var element = _this.listElements[index];
  4249. if (element) {
  4250. element.classList.add(_this.classNameMap[className]);
  4251. }
  4252. },
  4253. focusItemAtIndex: function focusItemAtIndex(index) {
  4254. var _a;
  4255. (_a = _this.listElements[index]) === null || _a === void 0 ? void 0 : _a.focus();
  4256. },
  4257. getAttributeForElementIndex: function getAttributeForElementIndex(index, attr) {
  4258. return _this.listElements[index].getAttribute(attr);
  4259. },
  4260. getFocusedElementIndex: function getFocusedElementIndex() {
  4261. return _this.listElements.indexOf(document.activeElement);
  4262. },
  4263. getListItemCount: function getListItemCount() {
  4264. return _this.listElements.length;
  4265. },
  4266. getPrimaryTextAtIndex: function getPrimaryTextAtIndex(index) {
  4267. return _this.getPrimaryText(_this.listElements[index]);
  4268. },
  4269. hasCheckboxAtIndex: function hasCheckboxAtIndex(index) {
  4270. var listItem = _this.listElements[index];
  4271. return !!listItem.querySelector(constants_1.strings.CHECKBOX_SELECTOR);
  4272. },
  4273. hasRadioAtIndex: function hasRadioAtIndex(index) {
  4274. var listItem = _this.listElements[index];
  4275. return !!listItem.querySelector(constants_1.strings.RADIO_SELECTOR);
  4276. },
  4277. isCheckboxCheckedAtIndex: function isCheckboxCheckedAtIndex(index) {
  4278. var listItem = _this.listElements[index];
  4279. var toggleEl = listItem.querySelector(constants_1.strings.CHECKBOX_SELECTOR);
  4280. return toggleEl.checked;
  4281. },
  4282. isFocusInsideList: function isFocusInsideList() {
  4283. return _this.root !== document.activeElement && _this.root.contains(document.activeElement);
  4284. },
  4285. isRootFocused: function isRootFocused() {
  4286. return document.activeElement === _this.root;
  4287. },
  4288. listItemAtIndexHasClass: function listItemAtIndexHasClass(index, className) {
  4289. return _this.listElements[index].classList.contains(_this.classNameMap[className]);
  4290. },
  4291. notifyAction: function notifyAction(index) {
  4292. _this.emit(constants_1.strings.ACTION_EVENT, { index: index }, /** shouldBubble */true);
  4293. },
  4294. notifySelectionChange: function notifySelectionChange(changedIndices) {
  4295. _this.emit(constants_1.strings.SELECTION_CHANGE_EVENT, { changedIndices: changedIndices },
  4296. /** shouldBubble */true);
  4297. },
  4298. removeClassForElementIndex: function removeClassForElementIndex(index, className) {
  4299. var element = _this.listElements[index];
  4300. if (element) {
  4301. element.classList.remove(_this.classNameMap[className]);
  4302. }
  4303. },
  4304. setAttributeForElementIndex: function setAttributeForElementIndex(index, attr, value) {
  4305. var element = _this.listElements[index];
  4306. if (element) {
  4307. _this.safeSetAttribute(element, attr, value);
  4308. }
  4309. },
  4310. setCheckedCheckboxOrRadioAtIndex: function setCheckedCheckboxOrRadioAtIndex(index, isChecked) {
  4311. var listItem = _this.listElements[index];
  4312. var toggleEl = listItem.querySelector(constants_1.strings.CHECKBOX_RADIO_SELECTOR);
  4313. toggleEl.checked = isChecked;
  4314. var event = document.createEvent('Event');
  4315. event.initEvent('change', true, true);
  4316. toggleEl.dispatchEvent(event);
  4317. },
  4318. setTabIndexForListItemChildren: function setTabIndexForListItemChildren(listItemIndex, tabIndexValue) {
  4319. var element = _this.listElements[listItemIndex];
  4320. var selector = constants_1.strings.CHILD_ELEMENTS_TO_TOGGLE_TABINDEX;
  4321. Array.prototype.forEach.call(element.querySelectorAll(selector), function (el) {
  4322. el.tabIndex = Number(tabIndexValue);
  4323. });
  4324. }
  4325. };
  4326. return new foundation_1.MDCListFoundation(adapter);
  4327. };
  4328. /**
  4329. * Ensures that at least one item is focusable if the list is interactive and
  4330. * doesn't specify a suitable tabindex.
  4331. */
  4332. MDCList.prototype.ensureFocusable = function () {
  4333. if (this.isEvolutionEnabled && this.isInteractive) {
  4334. if (!this.root.querySelector("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS] + "[tabindex=\"0\"]")) {
  4335. var index = this.initialFocusIndex();
  4336. if (index !== -1) {
  4337. this.listElements[index].tabIndex = 0;
  4338. }
  4339. }
  4340. }
  4341. };
  4342. MDCList.prototype.initialFocusIndex = function () {
  4343. if (this.selectedIndex instanceof Array && this.selectedIndex.length > 0) {
  4344. return this.selectedIndex[0];
  4345. }
  4346. if (typeof this.selectedIndex === 'number' && this.selectedIndex !== constants_1.numbers.UNSET_INDEX) {
  4347. return this.selectedIndex;
  4348. }
  4349. var el = this.root.querySelector("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS] + ":not(." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS] + ")");
  4350. if (el === null) {
  4351. return -1;
  4352. }
  4353. return this.getListItemIndex(el);
  4354. };
  4355. /**
  4356. * Used to figure out which list item this event is targeting. Or returns -1
  4357. * if there is no list item
  4358. */
  4359. MDCList.prototype.getListItemIndex = function (el) {
  4360. var nearestParent = ponyfill_1.closest(el, "." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS] + ", ." + this.classNameMap[constants_1.cssClasses.ROOT]);
  4361. // Get the index of the element if it is a list item.
  4362. if (nearestParent && ponyfill_1.matches(nearestParent, "." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS])) {
  4363. return this.listElements.indexOf(nearestParent);
  4364. }
  4365. return -1;
  4366. };
  4367. /**
  4368. * Used to figure out which element was clicked before sending the event to
  4369. * the foundation.
  4370. */
  4371. MDCList.prototype.handleFocusInEvent = function (evt) {
  4372. var index = this.getListItemIndex(evt.target);
  4373. this.foundation.handleFocusIn(index);
  4374. };
  4375. /**
  4376. * Used to figure out which element was clicked before sending the event to
  4377. * the foundation.
  4378. */
  4379. MDCList.prototype.handleFocusOutEvent = function (evt) {
  4380. var index = this.getListItemIndex(evt.target);
  4381. this.foundation.handleFocusOut(index);
  4382. };
  4383. /**
  4384. * Used to figure out which element was focused when keydown event occurred
  4385. * before sending the event to the foundation.
  4386. */
  4387. MDCList.prototype.handleKeydownEvent = function (evt) {
  4388. var index = this.getListItemIndex(evt.target);
  4389. var target = evt.target;
  4390. this.foundation.handleKeydown(evt, target.classList.contains(this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS]), index);
  4391. };
  4392. /**
  4393. * Used to figure out which element was clicked before sending the event to
  4394. * the foundation.
  4395. */
  4396. MDCList.prototype.handleClickEvent = function (evt) {
  4397. var index = this.getListItemIndex(evt.target);
  4398. var target = evt.target;
  4399. this.foundation.handleClick(index, ponyfill_1.matches(target, constants_1.strings.CHECKBOX_RADIO_SELECTOR), evt);
  4400. };
  4401. return MDCList;
  4402. }(component_1.MDCComponent);
  4403. exports.MDCList = MDCList;
  4404. /***/ }),
  4405. /***/ "./packages/mdc-list/constants.ts":
  4406. /*!****************************************!*\
  4407. !*** ./packages/mdc-list/constants.ts ***!
  4408. \****************************************/
  4409. /*! no static exports found */
  4410. /***/ (function(module, exports, __webpack_require__) {
  4411. "use strict";
  4412. /**
  4413. * @license
  4414. * Copyright 2018 Google Inc.
  4415. *
  4416. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4417. * of this software and associated documentation files (the "Software"), to deal
  4418. * in the Software without restriction, including without limitation the rights
  4419. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4420. * copies of the Software, and to permit persons to whom the Software is
  4421. * furnished to do so, subject to the following conditions:
  4422. *
  4423. * The above copyright notice and this permission notice shall be included in
  4424. * all copies or substantial portions of the Software.
  4425. *
  4426. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4427. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4428. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4429. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4430. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4431. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4432. * THE SOFTWARE.
  4433. */
  4434. var _a, _b;
  4435. Object.defineProperty(exports, "__esModule", { value: true });
  4436. exports.evolutionClassNameMap = exports.evolutionAttribute = exports.deprecatedClassNameMap = exports.numbers = exports.cssClasses = exports.strings = void 0;
  4437. var cssClasses = {
  4438. LIST_ITEM_ACTIVATED_CLASS: 'mdc-list-item--activated',
  4439. LIST_ITEM_CLASS: 'mdc-list-item',
  4440. LIST_ITEM_DISABLED_CLASS: 'mdc-list-item--disabled',
  4441. LIST_ITEM_SELECTED_CLASS: 'mdc-list-item--selected',
  4442. LIST_ITEM_TEXT_CLASS: 'mdc-list-item__text',
  4443. LIST_ITEM_PRIMARY_TEXT_CLASS: 'mdc-list-item__primary-text',
  4444. ROOT: 'mdc-list'
  4445. };
  4446. exports.cssClasses = cssClasses;
  4447. var evolutionClassNameMap = (_a = {}, _a["" + cssClasses.LIST_ITEM_ACTIVATED_CLASS] = 'mdc-list-item--activated', _a["" + cssClasses.LIST_ITEM_CLASS] = 'mdc-list-item', _a["" + cssClasses.LIST_ITEM_DISABLED_CLASS] = 'mdc-list-item--disabled', _a["" + cssClasses.LIST_ITEM_SELECTED_CLASS] = 'mdc-list-item--selected', _a["" + cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS] = 'mdc-list-item__primary-text', _a["" + cssClasses.ROOT] = 'mdc-list', _a);
  4448. exports.evolutionClassNameMap = evolutionClassNameMap;
  4449. var deprecatedClassNameMap = (_b = {}, _b["" + cssClasses.LIST_ITEM_ACTIVATED_CLASS] = 'mdc-deprecated-list-item--activated', _b["" + cssClasses.LIST_ITEM_CLASS] = 'mdc-deprecated-list-item', _b["" + cssClasses.LIST_ITEM_DISABLED_CLASS] = 'mdc-deprecated-list-item--disabled', _b["" + cssClasses.LIST_ITEM_SELECTED_CLASS] = 'mdc-deprecated-list-item--selected', _b["" + cssClasses.LIST_ITEM_TEXT_CLASS] = 'mdc-deprecated-list-item__text', _b["" + cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS] = 'mdc-deprecated-list-item__primary-text', _b["" + cssClasses.ROOT] = 'mdc-deprecated-list', _b);
  4450. exports.deprecatedClassNameMap = deprecatedClassNameMap;
  4451. var strings = {
  4452. ACTION_EVENT: 'MDCList:action',
  4453. SELECTION_CHANGE_EVENT: 'MDCList:selectionChange',
  4454. ARIA_CHECKED: 'aria-checked',
  4455. ARIA_CHECKED_CHECKBOX_SELECTOR: '[role="checkbox"][aria-checked="true"]',
  4456. ARIA_CHECKED_RADIO_SELECTOR: '[role="radio"][aria-checked="true"]',
  4457. ARIA_CURRENT: 'aria-current',
  4458. ARIA_DISABLED: 'aria-disabled',
  4459. ARIA_ORIENTATION: 'aria-orientation',
  4460. ARIA_ORIENTATION_HORIZONTAL: 'horizontal',
  4461. ARIA_ROLE_CHECKBOX_SELECTOR: '[role="checkbox"]',
  4462. ARIA_SELECTED: 'aria-selected',
  4463. ARIA_INTERACTIVE_ROLES_SELECTOR: '[role="listbox"], [role="menu"]',
  4464. ARIA_MULTI_SELECTABLE_SELECTOR: '[aria-multiselectable="true"]',
  4465. CHECKBOX_RADIO_SELECTOR: 'input[type="checkbox"], input[type="radio"]',
  4466. CHECKBOX_SELECTOR: 'input[type="checkbox"]',
  4467. CHILD_ELEMENTS_TO_TOGGLE_TABINDEX: "\n ." + cssClasses.LIST_ITEM_CLASS + " button:not(:disabled),\n ." + cssClasses.LIST_ITEM_CLASS + " a,\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " button:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " a\n ",
  4468. DEPRECATED_SELECTOR: '.mdc-deprecated-list',
  4469. FOCUSABLE_CHILD_ELEMENTS: "\n ." + cssClasses.LIST_ITEM_CLASS + " button:not(:disabled),\n ." + cssClasses.LIST_ITEM_CLASS + " a,\n ." + cssClasses.LIST_ITEM_CLASS + " input[type=\"radio\"]:not(:disabled),\n ." + cssClasses.LIST_ITEM_CLASS + " input[type=\"checkbox\"]:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " button:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " a,\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " input[type=\"radio\"]:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " input[type=\"checkbox\"]:not(:disabled)\n ",
  4470. RADIO_SELECTOR: 'input[type="radio"]',
  4471. SELECTED_ITEM_SELECTOR: '[aria-selected="true"], [aria-current="true"]'
  4472. };
  4473. exports.strings = strings;
  4474. var numbers = {
  4475. UNSET_INDEX: -1,
  4476. TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS: 300
  4477. };
  4478. exports.numbers = numbers;
  4479. var evolutionAttribute = 'evolution';
  4480. exports.evolutionAttribute = evolutionAttribute;
  4481. /***/ }),
  4482. /***/ "./packages/mdc-list/events.ts":
  4483. /*!*************************************!*\
  4484. !*** ./packages/mdc-list/events.ts ***!
  4485. \*************************************/
  4486. /*! no static exports found */
  4487. /***/ (function(module, exports, __webpack_require__) {
  4488. "use strict";
  4489. /**
  4490. * @license
  4491. * Copyright 2020 Google Inc.
  4492. *
  4493. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4494. * of this software and associated documentation files (the "Software"), to deal
  4495. * in the Software without restriction, including without limitation the rights
  4496. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4497. * copies of the Software, and to permit persons to whom the Software is
  4498. * furnished to do so, subject to the following conditions:
  4499. *
  4500. * The above copyright notice and this permission notice shall be included in
  4501. * all copies or substantial portions of the Software.
  4502. *
  4503. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4504. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4505. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4506. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4507. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4508. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4509. * THE SOFTWARE.
  4510. */
  4511. Object.defineProperty(exports, "__esModule", { value: true });
  4512. exports.preventDefaultEvent = void 0;
  4513. var ELEMENTS_KEY_ALLOWED_IN = ['input', 'button', 'textarea', 'select'];
  4514. /**
  4515. * Ensures that preventDefault is only called if the containing element
  4516. * doesn't consume the event, and it will cause an unintended scroll.
  4517. *
  4518. * @param evt keyboard event to be prevented.
  4519. */
  4520. var preventDefaultEvent = function preventDefaultEvent(evt) {
  4521. var target = evt.target;
  4522. if (!target) {
  4523. return;
  4524. }
  4525. var tagName = ("" + target.tagName).toLowerCase();
  4526. if (ELEMENTS_KEY_ALLOWED_IN.indexOf(tagName) === -1) {
  4527. evt.preventDefault();
  4528. }
  4529. };
  4530. exports.preventDefaultEvent = preventDefaultEvent;
  4531. /***/ }),
  4532. /***/ "./packages/mdc-list/foundation.ts":
  4533. /*!*****************************************!*\
  4534. !*** ./packages/mdc-list/foundation.ts ***!
  4535. \*****************************************/
  4536. /*! no static exports found */
  4537. /***/ (function(module, exports, __webpack_require__) {
  4538. "use strict";
  4539. /**
  4540. * @license
  4541. * Copyright 2018 Google Inc.
  4542. *
  4543. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4544. * of this software and associated documentation files (the "Software"), to deal
  4545. * in the Software without restriction, including without limitation the rights
  4546. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4547. * copies of the Software, and to permit persons to whom the Software is
  4548. * furnished to do so, subject to the following conditions:
  4549. *
  4550. * The above copyright notice and this permission notice shall be included in
  4551. * all copies or substantial portions of the Software.
  4552. *
  4553. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4554. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4555. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4556. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4557. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4558. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4559. * THE SOFTWARE.
  4560. */
  4561. var __extends = this && this.__extends || function () {
  4562. var _extendStatics = function extendStatics(d, b) {
  4563. _extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
  4564. d.__proto__ = b;
  4565. } || function (d, b) {
  4566. for (var p in b) {
  4567. if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
  4568. }
  4569. };
  4570. return _extendStatics(d, b);
  4571. };
  4572. return function (d, b) {
  4573. if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  4574. _extendStatics(d, b);
  4575. function __() {
  4576. this.constructor = d;
  4577. }
  4578. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4579. };
  4580. }();
  4581. var __assign = this && this.__assign || function () {
  4582. __assign = Object.assign || function (t) {
  4583. for (var s, i = 1, n = arguments.length; i < n; i++) {
  4584. s = arguments[i];
  4585. for (var p in s) {
  4586. if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  4587. }
  4588. }
  4589. return t;
  4590. };
  4591. return __assign.apply(this, arguments);
  4592. };
  4593. var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
  4594. if (k2 === undefined) k2 = k;
  4595. Object.defineProperty(o, k2, { enumerable: true, get: function get() {
  4596. return m[k];
  4597. } });
  4598. } : function (o, m, k, k2) {
  4599. if (k2 === undefined) k2 = k;
  4600. o[k2] = m[k];
  4601. });
  4602. var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
  4603. Object.defineProperty(o, "default", { enumerable: true, value: v });
  4604. } : function (o, v) {
  4605. o["default"] = v;
  4606. });
  4607. var __importStar = this && this.__importStar || function (mod) {
  4608. if (mod && mod.__esModule) return mod;
  4609. var result = {};
  4610. if (mod != null) for (var k in mod) {
  4611. if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  4612. }__setModuleDefault(result, mod);
  4613. return result;
  4614. };
  4615. var __read = this && this.__read || function (o, n) {
  4616. var m = typeof Symbol === "function" && o[Symbol.iterator];
  4617. if (!m) return o;
  4618. var i = m.call(o),
  4619. r,
  4620. ar = [],
  4621. e;
  4622. try {
  4623. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
  4624. ar.push(r.value);
  4625. }
  4626. } catch (error) {
  4627. e = { error: error };
  4628. } finally {
  4629. try {
  4630. if (r && !r.done && (m = i["return"])) m.call(i);
  4631. } finally {
  4632. if (e) throw e.error;
  4633. }
  4634. }
  4635. return ar;
  4636. };
  4637. var __spreadArray = this && this.__spreadArray || function (to, from) {
  4638. for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) {
  4639. to[j] = from[i];
  4640. }return to;
  4641. };
  4642. var __values = this && this.__values || function (o) {
  4643. var s = typeof Symbol === "function" && Symbol.iterator,
  4644. m = s && o[s],
  4645. i = 0;
  4646. if (m) return m.call(o);
  4647. if (o && typeof o.length === "number") return {
  4648. next: function next() {
  4649. if (o && i >= o.length) o = void 0;
  4650. return { value: o && o[i++], done: !o };
  4651. }
  4652. };
  4653. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  4654. };
  4655. Object.defineProperty(exports, "__esModule", { value: true });
  4656. exports.MDCListFoundation = void 0;
  4657. var foundation_1 = __webpack_require__(/*! @material/base/foundation */ "./packages/mdc-base/foundation.ts");
  4658. var keyboard_1 = __webpack_require__(/*! @material/dom/keyboard */ "./packages/mdc-dom/keyboard.ts");
  4659. var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-list/constants.ts");
  4660. var events_1 = __webpack_require__(/*! ./events */ "./packages/mdc-list/events.ts");
  4661. var typeahead = __importStar(__webpack_require__(/*! ./typeahead */ "./packages/mdc-list/typeahead.ts"));
  4662. function isNumberArray(selectedIndex) {
  4663. return selectedIndex instanceof Array;
  4664. }
  4665. /** List of modifier keys to consider while handling keyboard events. */
  4666. var handledModifierKeys = ['Alt', 'Control', 'Meta', 'Shift'];
  4667. /** Checks if the event has the given modifier keys. */
  4668. function createModifierChecker(event) {
  4669. var eventModifiers = new Set(event ? handledModifierKeys.filter(function (m) {
  4670. return event.getModifierState(m);
  4671. }) : []);
  4672. return function (modifiers) {
  4673. return modifiers.every(function (m) {
  4674. return eventModifiers.has(m);
  4675. }) && modifiers.length === eventModifiers.size;
  4676. };
  4677. }
  4678. /** MDC List Foundation */
  4679. var MDCListFoundation = /** @class */function (_super) {
  4680. __extends(MDCListFoundation, _super);
  4681. function MDCListFoundation(adapter) {
  4682. var _this = _super.call(this, __assign(__assign({}, MDCListFoundation.defaultAdapter), adapter)) || this;
  4683. _this.wrapFocus = false;
  4684. _this.isVertical = true;
  4685. _this.isSingleSelectionList = false;
  4686. _this.areDisabledItemsFocusable = false;
  4687. _this.selectedIndex = constants_1.numbers.UNSET_INDEX;
  4688. _this.focusedItemIndex = constants_1.numbers.UNSET_INDEX;
  4689. _this.useActivatedClass = false;
  4690. _this.useSelectedAttr = false;
  4691. _this.ariaCurrentAttrValue = null;
  4692. _this.isCheckboxList = false;
  4693. _this.isRadioList = false;
  4694. _this.lastSelectedIndex = null;
  4695. _this.hasTypeahead = false;
  4696. // Transiently holds current typeahead prefix from user.
  4697. _this.typeaheadState = typeahead.initState();
  4698. _this.sortedIndexByFirstChar = new Map();
  4699. return _this;
  4700. }
  4701. Object.defineProperty(MDCListFoundation, "strings", {
  4702. get: function get() {
  4703. return constants_1.strings;
  4704. },
  4705. enumerable: false,
  4706. configurable: true
  4707. });
  4708. Object.defineProperty(MDCListFoundation, "cssClasses", {
  4709. get: function get() {
  4710. return constants_1.cssClasses;
  4711. },
  4712. enumerable: false,
  4713. configurable: true
  4714. });
  4715. Object.defineProperty(MDCListFoundation, "numbers", {
  4716. get: function get() {
  4717. return constants_1.numbers;
  4718. },
  4719. enumerable: false,
  4720. configurable: true
  4721. });
  4722. Object.defineProperty(MDCListFoundation, "defaultAdapter", {
  4723. get: function get() {
  4724. return {
  4725. addClassForElementIndex: function addClassForElementIndex() {
  4726. return undefined;
  4727. },
  4728. focusItemAtIndex: function focusItemAtIndex() {
  4729. return undefined;
  4730. },
  4731. getAttributeForElementIndex: function getAttributeForElementIndex() {
  4732. return null;
  4733. },
  4734. getFocusedElementIndex: function getFocusedElementIndex() {
  4735. return 0;
  4736. },
  4737. getListItemCount: function getListItemCount() {
  4738. return 0;
  4739. },
  4740. hasCheckboxAtIndex: function hasCheckboxAtIndex() {
  4741. return false;
  4742. },
  4743. hasRadioAtIndex: function hasRadioAtIndex() {
  4744. return false;
  4745. },
  4746. isCheckboxCheckedAtIndex: function isCheckboxCheckedAtIndex() {
  4747. return false;
  4748. },
  4749. isFocusInsideList: function isFocusInsideList() {
  4750. return false;
  4751. },
  4752. isRootFocused: function isRootFocused() {
  4753. return false;
  4754. },
  4755. listItemAtIndexHasClass: function listItemAtIndexHasClass() {
  4756. return false;
  4757. },
  4758. notifyAction: function notifyAction() {
  4759. return undefined;
  4760. },
  4761. notifySelectionChange: function notifySelectionChange() {},
  4762. removeClassForElementIndex: function removeClassForElementIndex() {
  4763. return undefined;
  4764. },
  4765. setAttributeForElementIndex: function setAttributeForElementIndex() {
  4766. return undefined;
  4767. },
  4768. setCheckedCheckboxOrRadioAtIndex: function setCheckedCheckboxOrRadioAtIndex() {
  4769. return undefined;
  4770. },
  4771. setTabIndexForListItemChildren: function setTabIndexForListItemChildren() {
  4772. return undefined;
  4773. },
  4774. getPrimaryTextAtIndex: function getPrimaryTextAtIndex() {
  4775. return '';
  4776. }
  4777. };
  4778. },
  4779. enumerable: false,
  4780. configurable: true
  4781. });
  4782. MDCListFoundation.prototype.layout = function () {
  4783. if (this.adapter.getListItemCount() === 0) {
  4784. return;
  4785. }
  4786. // TODO(b/172274142): consider all items when determining the list's type.
  4787. if (this.adapter.hasCheckboxAtIndex(0)) {
  4788. this.isCheckboxList = true;
  4789. this.selectedIndex = [];
  4790. } else if (this.adapter.hasRadioAtIndex(0)) {
  4791. this.isRadioList = true;
  4792. } else {
  4793. this.maybeInitializeSingleSelection();
  4794. }
  4795. if (this.hasTypeahead) {
  4796. this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
  4797. }
  4798. };
  4799. /** Returns the index of the item that was last focused. */
  4800. MDCListFoundation.prototype.getFocusedItemIndex = function () {
  4801. return this.focusedItemIndex;
  4802. };
  4803. /** Toggles focus wrapping with keyboard navigation. */
  4804. MDCListFoundation.prototype.setWrapFocus = function (value) {
  4805. this.wrapFocus = value;
  4806. };
  4807. /**
  4808. * Toggles orientation direction for keyboard navigation (true for vertical,
  4809. * false for horizontal).
  4810. */
  4811. MDCListFoundation.prototype.setVerticalOrientation = function (value) {
  4812. this.isVertical = value;
  4813. };
  4814. /** Toggles single-selection behavior. */
  4815. MDCListFoundation.prototype.setSingleSelection = function (value) {
  4816. this.isSingleSelectionList = value;
  4817. if (value) {
  4818. this.maybeInitializeSingleSelection();
  4819. this.selectedIndex = this.getSelectedIndexFromDOM();
  4820. }
  4821. };
  4822. MDCListFoundation.prototype.setDisabledItemsFocusable = function (value) {
  4823. this.areDisabledItemsFocusable = value;
  4824. };
  4825. /**
  4826. * Automatically determines whether the list is single selection list. If so,
  4827. * initializes the internal state to match the selected item.
  4828. */
  4829. MDCListFoundation.prototype.maybeInitializeSingleSelection = function () {
  4830. var selectedItemIndex = this.getSelectedIndexFromDOM();
  4831. if (selectedItemIndex === constants_1.numbers.UNSET_INDEX) return;
  4832. var hasActivatedClass = this.adapter.listItemAtIndexHasClass(selectedItemIndex, constants_1.cssClasses.LIST_ITEM_ACTIVATED_CLASS);
  4833. if (hasActivatedClass) {
  4834. this.setUseActivatedClass(true);
  4835. }
  4836. this.isSingleSelectionList = true;
  4837. this.selectedIndex = selectedItemIndex;
  4838. };
  4839. /** @return Index of the first selected item based on the DOM state. */
  4840. MDCListFoundation.prototype.getSelectedIndexFromDOM = function () {
  4841. var selectedIndex = constants_1.numbers.UNSET_INDEX;
  4842. var listItemsCount = this.adapter.getListItemCount();
  4843. for (var i = 0; i < listItemsCount; i++) {
  4844. var hasSelectedClass = this.adapter.listItemAtIndexHasClass(i, constants_1.cssClasses.LIST_ITEM_SELECTED_CLASS);
  4845. var hasActivatedClass = this.adapter.listItemAtIndexHasClass(i, constants_1.cssClasses.LIST_ITEM_ACTIVATED_CLASS);
  4846. if (!(hasSelectedClass || hasActivatedClass)) {
  4847. continue;
  4848. }
  4849. selectedIndex = i;
  4850. break;
  4851. }
  4852. return selectedIndex;
  4853. };
  4854. /**
  4855. * Sets whether typeahead is enabled on the list.
  4856. * @param hasTypeahead Whether typeahead is enabled.
  4857. */
  4858. MDCListFoundation.prototype.setHasTypeahead = function (hasTypeahead) {
  4859. this.hasTypeahead = hasTypeahead;
  4860. if (hasTypeahead) {
  4861. this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
  4862. }
  4863. };
  4864. /**
  4865. * @return Whether typeahead is currently matching a user-specified prefix.
  4866. */
  4867. MDCListFoundation.prototype.isTypeaheadInProgress = function () {
  4868. return this.hasTypeahead && typeahead.isTypingInProgress(this.typeaheadState);
  4869. };
  4870. /** Toggle use of the "activated" CSS class. */
  4871. MDCListFoundation.prototype.setUseActivatedClass = function (useActivated) {
  4872. this.useActivatedClass = useActivated;
  4873. };
  4874. /**
  4875. * Toggles use of the selected attribute (true for aria-selected, false for
  4876. * aria-checked).
  4877. */
  4878. MDCListFoundation.prototype.setUseSelectedAttribute = function (useSelected) {
  4879. this.useSelectedAttr = useSelected;
  4880. };
  4881. MDCListFoundation.prototype.getSelectedIndex = function () {
  4882. return this.selectedIndex;
  4883. };
  4884. MDCListFoundation.prototype.setSelectedIndex = function (index, options) {
  4885. if (options === void 0) {
  4886. options = {};
  4887. }
  4888. if (!this.isIndexValid(index)) {
  4889. return;
  4890. }
  4891. if (this.isCheckboxList) {
  4892. this.setCheckboxAtIndex(index, options);
  4893. } else if (this.isRadioList) {
  4894. this.setRadioAtIndex(index, options);
  4895. } else {
  4896. this.setSingleSelectionAtIndex(index, options);
  4897. }
  4898. };
  4899. /**
  4900. * Focus in handler for the list items.
  4901. */
  4902. MDCListFoundation.prototype.handleFocusIn = function (listItemIndex) {
  4903. if (listItemIndex >= 0) {
  4904. this.focusedItemIndex = listItemIndex;
  4905. this.adapter.setAttributeForElementIndex(listItemIndex, 'tabindex', '0');
  4906. this.adapter.setTabIndexForListItemChildren(listItemIndex, '0');
  4907. }
  4908. };
  4909. /**
  4910. * Focus out handler for the list items.
  4911. */
  4912. MDCListFoundation.prototype.handleFocusOut = function (listItemIndex) {
  4913. var _this = this;
  4914. if (listItemIndex >= 0) {
  4915. this.adapter.setAttributeForElementIndex(listItemIndex, 'tabindex', '-1');
  4916. this.adapter.setTabIndexForListItemChildren(listItemIndex, '-1');
  4917. }
  4918. /**
  4919. * Between Focusout & Focusin some browsers do not have focus on any
  4920. * element. Setting a delay to wait till the focus is moved to next element.
  4921. */
  4922. setTimeout(function () {
  4923. if (!_this.adapter.isFocusInsideList()) {
  4924. _this.setTabindexToFirstSelectedOrFocusedItem();
  4925. }
  4926. }, 0);
  4927. };
  4928. MDCListFoundation.prototype.isIndexDisabled = function (index) {
  4929. return this.adapter.listItemAtIndexHasClass(index, constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS);
  4930. };
  4931. /**
  4932. * Key handler for the list.
  4933. */
  4934. MDCListFoundation.prototype.handleKeydown = function (event, isRootListItem, listItemIndex) {
  4935. var _this = this;
  4936. var _a;
  4937. var isArrowLeft = keyboard_1.normalizeKey(event) === 'ArrowLeft';
  4938. var isArrowUp = keyboard_1.normalizeKey(event) === 'ArrowUp';
  4939. var isArrowRight = keyboard_1.normalizeKey(event) === 'ArrowRight';
  4940. var isArrowDown = keyboard_1.normalizeKey(event) === 'ArrowDown';
  4941. var isHome = keyboard_1.normalizeKey(event) === 'Home';
  4942. var isEnd = keyboard_1.normalizeKey(event) === 'End';
  4943. var isEnter = keyboard_1.normalizeKey(event) === 'Enter';
  4944. var isSpace = keyboard_1.normalizeKey(event) === 'Spacebar';
  4945. // The keys for forward and back differ based on list orientation.
  4946. var isForward = this.isVertical && isArrowDown || !this.isVertical && isArrowRight;
  4947. var isBack = this.isVertical && isArrowUp || !this.isVertical && isArrowLeft;
  4948. // Have to check both upper and lower case, because having caps lock on
  4949. // affects the value.
  4950. var isLetterA = event.key === 'A' || event.key === 'a';
  4951. var eventHasModifiers = createModifierChecker(event);
  4952. if (this.adapter.isRootFocused()) {
  4953. if ((isBack || isEnd) && eventHasModifiers([])) {
  4954. event.preventDefault();
  4955. this.focusLastElement();
  4956. } else if ((isForward || isHome) && eventHasModifiers([])) {
  4957. event.preventDefault();
  4958. this.focusFirstElement();
  4959. } else if (isBack && eventHasModifiers(['Shift']) && this.isCheckboxList) {
  4960. event.preventDefault();
  4961. var focusedIndex = this.focusLastElement();
  4962. if (focusedIndex !== -1) {
  4963. this.setSelectedIndexOnAction(focusedIndex, false);
  4964. }
  4965. } else if (isForward && eventHasModifiers(['Shift']) && this.isCheckboxList) {
  4966. event.preventDefault();
  4967. var focusedIndex = this.focusFirstElement();
  4968. if (focusedIndex !== -1) {
  4969. this.setSelectedIndexOnAction(focusedIndex, false);
  4970. }
  4971. }
  4972. if (this.hasTypeahead) {
  4973. var handleKeydownOpts = {
  4974. event: event,
  4975. focusItemAtIndex: function focusItemAtIndex(index) {
  4976. _this.focusItemAtIndex(index);
  4977. },
  4978. focusedItemIndex: -1,
  4979. isTargetListItem: isRootListItem,
  4980. sortedIndexByFirstChar: this.sortedIndexByFirstChar,
  4981. isItemAtIndexDisabled: function isItemAtIndexDisabled(index) {
  4982. return _this.isIndexDisabled(index);
  4983. }
  4984. };
  4985. typeahead.handleKeydown(handleKeydownOpts, this.typeaheadState);
  4986. }
  4987. return;
  4988. }
  4989. var currentIndex = this.adapter.getFocusedElementIndex();
  4990. if (currentIndex === -1) {
  4991. currentIndex = listItemIndex;
  4992. if (currentIndex < 0) {
  4993. // If this event doesn't have a mdc-list-item ancestor from the
  4994. // current list (not from a sublist), return early.
  4995. return;
  4996. }
  4997. }
  4998. if (isForward && eventHasModifiers([])) {
  4999. events_1.preventDefaultEvent(event);
  5000. this.focusNextElement(currentIndex);
  5001. } else if (isBack && eventHasModifiers([])) {
  5002. events_1.preventDefaultEvent(event);
  5003. this.focusPrevElement(currentIndex);
  5004. } else if (isForward && eventHasModifiers(['Shift']) && this.isCheckboxList) {
  5005. events_1.preventDefaultEvent(event);
  5006. var focusedIndex = this.focusNextElement(currentIndex);
  5007. if (focusedIndex !== -1) {
  5008. this.setSelectedIndexOnAction(focusedIndex, false);
  5009. }
  5010. } else if (isBack && eventHasModifiers(['Shift']) && this.isCheckboxList) {
  5011. events_1.preventDefaultEvent(event);
  5012. var focusedIndex = this.focusPrevElement(currentIndex);
  5013. if (focusedIndex !== -1) {
  5014. this.setSelectedIndexOnAction(focusedIndex, false);
  5015. }
  5016. } else if (isHome && eventHasModifiers([])) {
  5017. events_1.preventDefaultEvent(event);
  5018. this.focusFirstElement();
  5019. } else if (isEnd && eventHasModifiers([])) {
  5020. events_1.preventDefaultEvent(event);
  5021. this.focusLastElement();
  5022. } else if (isHome && eventHasModifiers(['Control', 'Shift']) && this.isCheckboxList) {
  5023. events_1.preventDefaultEvent(event);
  5024. if (this.isIndexDisabled(currentIndex)) {
  5025. return;
  5026. }
  5027. this.focusFirstElement();
  5028. this.toggleCheckboxRange(0, currentIndex, currentIndex);
  5029. } else if (isEnd && eventHasModifiers(['Control', 'Shift']) && this.isCheckboxList) {
  5030. events_1.preventDefaultEvent(event);
  5031. if (this.isIndexDisabled(currentIndex)) {
  5032. return;
  5033. }
  5034. this.focusLastElement();
  5035. this.toggleCheckboxRange(currentIndex, this.adapter.getListItemCount() - 1, currentIndex);
  5036. } else if (isLetterA && eventHasModifiers(['Control']) && this.isCheckboxList) {
  5037. event.preventDefault();
  5038. this.checkboxListToggleAll(this.selectedIndex === constants_1.numbers.UNSET_INDEX ? [] : this.selectedIndex, true);
  5039. } else if ((isEnter || isSpace) && (eventHasModifiers([]) || eventHasModifiers(['Alt']))) {
  5040. if (isRootListItem) {
  5041. // Return early if enter key is pressed on anchor element which triggers
  5042. // synthetic MouseEvent event.
  5043. var target = event.target;
  5044. if (target && target.tagName === 'A' && isEnter) {
  5045. return;
  5046. }
  5047. events_1.preventDefaultEvent(event);
  5048. if (this.isIndexDisabled(currentIndex)) {
  5049. return;
  5050. }
  5051. if (!this.isTypeaheadInProgress()) {
  5052. if (this.isSelectableList()) {
  5053. this.setSelectedIndexOnAction(currentIndex, false);
  5054. }
  5055. this.adapter.notifyAction(currentIndex);
  5056. }
  5057. }
  5058. } else if ((isEnter || isSpace) && eventHasModifiers(['Shift']) && this.isCheckboxList) {
  5059. // Return early if enter key is pressed on anchor element which triggers
  5060. // synthetic MouseEvent event.
  5061. var target = event.target;
  5062. if (target && target.tagName === 'A' && isEnter) {
  5063. return;
  5064. }
  5065. events_1.preventDefaultEvent(event);
  5066. if (this.isIndexDisabled(currentIndex)) {
  5067. return;
  5068. }
  5069. if (!this.isTypeaheadInProgress()) {
  5070. this.toggleCheckboxRange((_a = this.lastSelectedIndex) !== null && _a !== void 0 ? _a : currentIndex, currentIndex, currentIndex);
  5071. this.adapter.notifyAction(currentIndex);
  5072. }
  5073. }
  5074. if (this.hasTypeahead) {
  5075. var handleKeydownOpts = {
  5076. event: event,
  5077. focusItemAtIndex: function focusItemAtIndex(index) {
  5078. _this.focusItemAtIndex(index);
  5079. },
  5080. focusedItemIndex: this.focusedItemIndex,
  5081. isTargetListItem: isRootListItem,
  5082. sortedIndexByFirstChar: this.sortedIndexByFirstChar,
  5083. isItemAtIndexDisabled: function isItemAtIndexDisabled(index) {
  5084. return _this.isIndexDisabled(index);
  5085. }
  5086. };
  5087. typeahead.handleKeydown(handleKeydownOpts, this.typeaheadState);
  5088. }
  5089. };
  5090. /**
  5091. * Click handler for the list.
  5092. *
  5093. * @param index Index for the item that has been clicked.
  5094. * @param isCheckboxAlreadyUpdatedInAdapter Whether the checkbox for
  5095. * the list item has already been updated in the adapter. This attribute
  5096. * should be set to `true` when e.g. the click event directly landed on
  5097. * the underlying native checkbox element which would cause the checked
  5098. * state to be already toggled within `adapter.isCheckboxCheckedAtIndex`.
  5099. */
  5100. MDCListFoundation.prototype.handleClick = function (index, isCheckboxAlreadyUpdatedInAdapter, event) {
  5101. var _a;
  5102. var eventHasModifiers = createModifierChecker(event);
  5103. if (index === constants_1.numbers.UNSET_INDEX) {
  5104. return;
  5105. }
  5106. if (this.isIndexDisabled(index)) {
  5107. return;
  5108. }
  5109. if (eventHasModifiers([])) {
  5110. if (this.isSelectableList()) {
  5111. this.setSelectedIndexOnAction(index, isCheckboxAlreadyUpdatedInAdapter);
  5112. }
  5113. this.adapter.notifyAction(index);
  5114. } else if (this.isCheckboxList && eventHasModifiers(['Shift'])) {
  5115. this.toggleCheckboxRange((_a = this.lastSelectedIndex) !== null && _a !== void 0 ? _a : index, index, index);
  5116. this.adapter.notifyAction(index);
  5117. }
  5118. };
  5119. /**
  5120. * Focuses the next element on the list.
  5121. */
  5122. MDCListFoundation.prototype.focusNextElement = function (index) {
  5123. var count = this.adapter.getListItemCount();
  5124. var nextIndex = index;
  5125. var firstChecked = null;
  5126. do {
  5127. nextIndex++;
  5128. if (nextIndex >= count) {
  5129. if (this.wrapFocus) {
  5130. nextIndex = 0;
  5131. } else {
  5132. // Return early because last item is already focused.
  5133. return index;
  5134. }
  5135. }
  5136. if (nextIndex === firstChecked) {
  5137. return -1;
  5138. }
  5139. firstChecked = firstChecked !== null && firstChecked !== void 0 ? firstChecked : nextIndex;
  5140. } while (!this.areDisabledItemsFocusable && this.isIndexDisabled(nextIndex));
  5141. this.focusItemAtIndex(nextIndex);
  5142. return nextIndex;
  5143. };
  5144. /**
  5145. * Focuses the previous element on the list.
  5146. */
  5147. MDCListFoundation.prototype.focusPrevElement = function (index) {
  5148. var count = this.adapter.getListItemCount();
  5149. var prevIndex = index;
  5150. var firstChecked = null;
  5151. do {
  5152. prevIndex--;
  5153. if (prevIndex < 0) {
  5154. if (this.wrapFocus) {
  5155. prevIndex = count - 1;
  5156. } else {
  5157. // Return early because first item is already focused.
  5158. return index;
  5159. }
  5160. }
  5161. if (prevIndex === firstChecked) {
  5162. return -1;
  5163. }
  5164. firstChecked = firstChecked !== null && firstChecked !== void 0 ? firstChecked : prevIndex;
  5165. } while (!this.areDisabledItemsFocusable && this.isIndexDisabled(prevIndex));
  5166. this.focusItemAtIndex(prevIndex);
  5167. return prevIndex;
  5168. };
  5169. MDCListFoundation.prototype.focusFirstElement = function () {
  5170. // Pass -1 to `focusNextElement`, since it will incremement to 0 and focus
  5171. // the first element.
  5172. return this.focusNextElement(-1);
  5173. };
  5174. MDCListFoundation.prototype.focusLastElement = function () {
  5175. // Pass the length of the list to `focusNextElement` since it will decrement
  5176. // to length - 1 and focus the last element.
  5177. return this.focusPrevElement(this.adapter.getListItemCount());
  5178. };
  5179. MDCListFoundation.prototype.focusInitialElement = function () {
  5180. var initialIndex = this.getFirstSelectedOrFocusedItemIndex();
  5181. if (initialIndex !== constants_1.numbers.UNSET_INDEX) {
  5182. this.focusItemAtIndex(initialIndex);
  5183. }
  5184. return initialIndex;
  5185. };
  5186. /**
  5187. * @param itemIndex Index of the list item
  5188. * @param isEnabled Sets the list item to enabled or disabled.
  5189. */
  5190. MDCListFoundation.prototype.setEnabled = function (itemIndex, isEnabled) {
  5191. if (!this.isIndexValid(itemIndex, false)) {
  5192. return;
  5193. }
  5194. if (isEnabled) {
  5195. this.adapter.removeClassForElementIndex(itemIndex, constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS);
  5196. this.adapter.setAttributeForElementIndex(itemIndex, constants_1.strings.ARIA_DISABLED, 'false');
  5197. } else {
  5198. this.adapter.addClassForElementIndex(itemIndex, constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS);
  5199. this.adapter.setAttributeForElementIndex(itemIndex, constants_1.strings.ARIA_DISABLED, 'true');
  5200. }
  5201. };
  5202. MDCListFoundation.prototype.setSingleSelectionAtIndex = function (index, options) {
  5203. if (options === void 0) {
  5204. options = {};
  5205. }
  5206. if (this.selectedIndex === index && !options.forceUpdate) {
  5207. return;
  5208. }
  5209. var selectedClassName = constants_1.cssClasses.LIST_ITEM_SELECTED_CLASS;
  5210. if (this.useActivatedClass) {
  5211. selectedClassName = constants_1.cssClasses.LIST_ITEM_ACTIVATED_CLASS;
  5212. }
  5213. if (this.selectedIndex !== constants_1.numbers.UNSET_INDEX) {
  5214. this.adapter.removeClassForElementIndex(this.selectedIndex, selectedClassName);
  5215. }
  5216. this.setAriaForSingleSelectionAtIndex(index);
  5217. this.setTabindexAtIndex(index);
  5218. if (index !== constants_1.numbers.UNSET_INDEX) {
  5219. this.adapter.addClassForElementIndex(index, selectedClassName);
  5220. }
  5221. this.selectedIndex = index;
  5222. // If the selected value has changed through user interaction,
  5223. // we want to notify the selection change to the adapter.
  5224. if (options.isUserInteraction && !options.forceUpdate) {
  5225. this.adapter.notifySelectionChange([index]);
  5226. }
  5227. };
  5228. /**
  5229. * Sets aria attribute for single selection at given index.
  5230. */
  5231. MDCListFoundation.prototype.setAriaForSingleSelectionAtIndex = function (index) {
  5232. // Detect the presence of aria-current and get the value only during list
  5233. // initialization when it is in unset state.
  5234. if (this.selectedIndex === constants_1.numbers.UNSET_INDEX && index !== constants_1.numbers.UNSET_INDEX) {
  5235. this.ariaCurrentAttrValue = this.adapter.getAttributeForElementIndex(index, constants_1.strings.ARIA_CURRENT);
  5236. }
  5237. var isAriaCurrent = this.ariaCurrentAttrValue !== null;
  5238. var ariaAttribute = isAriaCurrent ? constants_1.strings.ARIA_CURRENT : constants_1.strings.ARIA_SELECTED;
  5239. if (this.selectedIndex !== constants_1.numbers.UNSET_INDEX) {
  5240. this.adapter.setAttributeForElementIndex(this.selectedIndex, ariaAttribute, 'false');
  5241. }
  5242. if (index !== constants_1.numbers.UNSET_INDEX) {
  5243. var ariaAttributeValue = isAriaCurrent ? this.ariaCurrentAttrValue : 'true';
  5244. this.adapter.setAttributeForElementIndex(index, ariaAttribute, ariaAttributeValue);
  5245. }
  5246. };
  5247. /**
  5248. * Returns the attribute to use for indicating selection status.
  5249. */
  5250. MDCListFoundation.prototype.getSelectionAttribute = function () {
  5251. return this.useSelectedAttr ? constants_1.strings.ARIA_SELECTED : constants_1.strings.ARIA_CHECKED;
  5252. };
  5253. /**
  5254. * Toggles radio at give index. Radio doesn't change the checked state if it
  5255. * is already checked.
  5256. */
  5257. MDCListFoundation.prototype.setRadioAtIndex = function (index, options) {
  5258. if (options === void 0) {
  5259. options = {};
  5260. }
  5261. var selectionAttribute = this.getSelectionAttribute();
  5262. this.adapter.setCheckedCheckboxOrRadioAtIndex(index, true);
  5263. if (this.selectedIndex === index && !options.forceUpdate) {
  5264. return;
  5265. }
  5266. if (this.selectedIndex !== constants_1.numbers.UNSET_INDEX) {
  5267. this.adapter.setAttributeForElementIndex(this.selectedIndex, selectionAttribute, 'false');
  5268. }
  5269. this.adapter.setAttributeForElementIndex(index, selectionAttribute, 'true');
  5270. this.selectedIndex = index;
  5271. // If the selected value has changed through user interaction,
  5272. // we want to notify the selection change to the adapter.
  5273. if (options.isUserInteraction && !options.forceUpdate) {
  5274. this.adapter.notifySelectionChange([index]);
  5275. }
  5276. };
  5277. MDCListFoundation.prototype.setCheckboxAtIndex = function (indices, options) {
  5278. if (options === void 0) {
  5279. options = {};
  5280. }
  5281. var currentIndex = this.selectedIndex;
  5282. // If this update is not triggered by a user interaction, we do not
  5283. // need to know about the currently selected indices and can avoid
  5284. // constructing the `Set` for performance reasons.
  5285. var currentlySelected = options.isUserInteraction ? new Set(currentIndex === constants_1.numbers.UNSET_INDEX ? [] : currentIndex) : null;
  5286. var selectionAttribute = this.getSelectionAttribute();
  5287. var changedIndices = [];
  5288. for (var i = 0; i < this.adapter.getListItemCount(); i++) {
  5289. if (options.omitDisabledItems && this.isIndexDisabled(i)) {
  5290. continue;
  5291. }
  5292. var previousIsChecked = currentlySelected === null || currentlySelected === void 0 ? void 0 : currentlySelected.has(i);
  5293. var newIsChecked = indices.indexOf(i) >= 0;
  5294. // If the selection has changed for this item, we keep track of it
  5295. // so that we can notify the adapter.
  5296. if (newIsChecked !== previousIsChecked) {
  5297. changedIndices.push(i);
  5298. }
  5299. this.adapter.setCheckedCheckboxOrRadioAtIndex(i, newIsChecked);
  5300. this.adapter.setAttributeForElementIndex(i, selectionAttribute, newIsChecked ? 'true' : 'false');
  5301. }
  5302. this.selectedIndex = options.omitDisabledItems ? this.resolveSelectedIndices(indices) : indices;
  5303. // If the selected value has changed through user interaction,
  5304. // we want to notify the selection change to the adapter.
  5305. if (options.isUserInteraction && changedIndices.length) {
  5306. this.adapter.notifySelectionChange(changedIndices);
  5307. }
  5308. };
  5309. /**
  5310. * Helper method for ensuring that the list of selected indices remains
  5311. * accurate when calling setCheckboxAtIndex with omitDisabledItems set to
  5312. * true.
  5313. */
  5314. MDCListFoundation.prototype.resolveSelectedIndices = function (setCheckedItems) {
  5315. var _this = this;
  5316. var currentlySelectedItems = this.selectedIndex === constants_1.numbers.UNSET_INDEX ? [] : this.selectedIndex;
  5317. var currentlySelectedDisabledItems = currentlySelectedItems.filter(function (i) {
  5318. return _this.isIndexDisabled(i);
  5319. });
  5320. var enabledSetCheckedItems = setCheckedItems.filter(function (i) {
  5321. return !_this.isIndexDisabled(i);
  5322. });
  5323. // Updated selectedIndex should be the enabled setCheckedItems + any missing
  5324. // selected disabled items.
  5325. var updatedSelectedItems = __spreadArray([], __read(new Set(__spreadArray(__spreadArray([], __read(enabledSetCheckedItems)), __read(currentlySelectedDisabledItems)))));
  5326. return updatedSelectedItems.sort(function (a, b) {
  5327. return a - b;
  5328. });
  5329. };
  5330. /**
  5331. * Toggles the state of all checkboxes in the given range (inclusive) based
  5332. * on the state of the checkbox at the `toggleIndex`. To determine whether
  5333. * to set the given range to checked or unchecked, read the value of the
  5334. * checkbox at the `toggleIndex` and negate it. Then apply that new checked
  5335. * state to all checkboxes in the range.
  5336. * @param fromIndex The start of the range of checkboxes to toggle
  5337. * @param toIndex The end of the range of checkboxes to toggle
  5338. * @param toggleIndex The index that will be used to determine the new state
  5339. * of the given checkbox range.
  5340. */
  5341. MDCListFoundation.prototype.toggleCheckboxRange = function (fromIndex, toIndex, toggleIndex) {
  5342. this.lastSelectedIndex = toggleIndex;
  5343. var currentlySelected = new Set(this.selectedIndex === constants_1.numbers.UNSET_INDEX ? [] : this.selectedIndex);
  5344. var newIsChecked = !(currentlySelected === null || currentlySelected === void 0 ? void 0 : currentlySelected.has(toggleIndex));
  5345. var _a = __read([fromIndex, toIndex].sort(), 2),
  5346. startIndex = _a[0],
  5347. endIndex = _a[1];
  5348. var selectionAttribute = this.getSelectionAttribute();
  5349. var changedIndices = [];
  5350. for (var i = startIndex; i <= endIndex; i++) {
  5351. if (this.isIndexDisabled(i)) {
  5352. continue;
  5353. }
  5354. var previousIsChecked = currentlySelected.has(i);
  5355. // If the selection has changed for this item, we keep track of it
  5356. // so that we can notify the adapter.
  5357. if (newIsChecked !== previousIsChecked) {
  5358. changedIndices.push(i);
  5359. this.adapter.setCheckedCheckboxOrRadioAtIndex(i, newIsChecked);
  5360. this.adapter.setAttributeForElementIndex(i, selectionAttribute, "" + newIsChecked);
  5361. if (newIsChecked) {
  5362. currentlySelected.add(i);
  5363. } else {
  5364. currentlySelected.delete(i);
  5365. }
  5366. }
  5367. }
  5368. // If the selected value has changed, update and notify the selection
  5369. // change to the adapter.
  5370. if (changedIndices.length) {
  5371. this.selectedIndex = __spreadArray([], __read(currentlySelected));
  5372. this.adapter.notifySelectionChange(changedIndices);
  5373. }
  5374. };
  5375. MDCListFoundation.prototype.setTabindexAtIndex = function (index) {
  5376. if (this.focusedItemIndex === constants_1.numbers.UNSET_INDEX && index !== 0 && index !== constants_1.numbers.UNSET_INDEX) {
  5377. // If some list item was selected set first list item's tabindex to -1.
  5378. // Generally, tabindex is set to 0 on first list item of list that has
  5379. // no preselected items.
  5380. this.adapter.setAttributeForElementIndex(0, 'tabindex', '-1');
  5381. } else if (this.focusedItemIndex >= 0 && this.focusedItemIndex !== index) {
  5382. this.adapter.setAttributeForElementIndex(this.focusedItemIndex, 'tabindex', '-1');
  5383. }
  5384. // Set the previous selection's tabindex to -1. We need this because
  5385. // in selection menus that are not visible, programmatically setting an
  5386. // option will not change focus but will change where tabindex should be
  5387. // 0.
  5388. if (!(this.selectedIndex instanceof Array) && this.selectedIndex !== index && this.focusedItemIndex !== constants_1.numbers.UNSET_INDEX) {
  5389. this.adapter.setAttributeForElementIndex(this.selectedIndex, 'tabindex', '-1');
  5390. }
  5391. if (index !== constants_1.numbers.UNSET_INDEX) {
  5392. this.adapter.setAttributeForElementIndex(index, 'tabindex', '0');
  5393. }
  5394. };
  5395. /**
  5396. * @return Return true if it is single selectin list, checkbox list or radio
  5397. * list.
  5398. */
  5399. MDCListFoundation.prototype.isSelectableList = function () {
  5400. return this.isSingleSelectionList || this.isCheckboxList || this.isRadioList;
  5401. };
  5402. MDCListFoundation.prototype.setTabindexToFirstSelectedOrFocusedItem = function () {
  5403. var targetIndex = this.getFirstSelectedOrFocusedItemIndex();
  5404. this.setTabindexAtIndex(targetIndex);
  5405. };
  5406. MDCListFoundation.prototype.getFirstSelectedOrFocusedItemIndex = function () {
  5407. var e_1, _a;
  5408. var firstFocusableListItem = this.getFirstEnabledItem();
  5409. if (this.adapter.getListItemCount() === 0) {
  5410. return constants_1.numbers.UNSET_INDEX;
  5411. }
  5412. // Action lists retain focus on the most recently focused item.
  5413. if (!this.isSelectableList()) {
  5414. return Math.max(this.focusedItemIndex, firstFocusableListItem);
  5415. }
  5416. // Single-selection lists focus the selected item.
  5417. if (typeof this.selectedIndex === 'number' && this.selectedIndex !== constants_1.numbers.UNSET_INDEX) {
  5418. return this.areDisabledItemsFocusable && this.isIndexDisabled(this.selectedIndex) ? firstFocusableListItem : this.selectedIndex;
  5419. }
  5420. // Multiple-selection lists focus the first enabled selected item.
  5421. if (isNumberArray(this.selectedIndex) && this.selectedIndex.length > 0) {
  5422. var sorted = __spreadArray([], __read(this.selectedIndex)).sort(function (a, b) {
  5423. return a - b;
  5424. });
  5425. try {
  5426. for (var sorted_1 = __values(sorted), sorted_1_1 = sorted_1.next(); !sorted_1_1.done; sorted_1_1 = sorted_1.next()) {
  5427. var index = sorted_1_1.value;
  5428. if (this.isIndexDisabled(index) && !this.areDisabledItemsFocusable) {
  5429. continue;
  5430. } else {
  5431. return index;
  5432. }
  5433. }
  5434. } catch (e_1_1) {
  5435. e_1 = { error: e_1_1 };
  5436. } finally {
  5437. try {
  5438. if (sorted_1_1 && !sorted_1_1.done && (_a = sorted_1.return)) _a.call(sorted_1);
  5439. } finally {
  5440. if (e_1) throw e_1.error;
  5441. }
  5442. }
  5443. }
  5444. // Selection lists without a selection focus the first item.
  5445. return firstFocusableListItem;
  5446. };
  5447. MDCListFoundation.prototype.getFirstEnabledItem = function () {
  5448. var listSize = this.adapter.getListItemCount();
  5449. var i = 0;
  5450. while (i < listSize) {
  5451. if (!this.isIndexDisabled(i)) {
  5452. break;
  5453. }
  5454. i++;
  5455. }
  5456. return i === listSize ? constants_1.numbers.UNSET_INDEX : i;
  5457. };
  5458. MDCListFoundation.prototype.isIndexValid = function (index, validateListType) {
  5459. var _this = this;
  5460. if (validateListType === void 0) {
  5461. validateListType = true;
  5462. }
  5463. if (index instanceof Array) {
  5464. if (!this.isCheckboxList && validateListType) {
  5465. throw new Error('MDCListFoundation: Array of index is only supported for checkbox based list');
  5466. }
  5467. if (index.length === 0) {
  5468. return true;
  5469. } else {
  5470. return index.some(function (i) {
  5471. return _this.isIndexInRange(i);
  5472. });
  5473. }
  5474. } else if (typeof index === 'number') {
  5475. if (this.isCheckboxList && validateListType) {
  5476. throw new Error("MDCListFoundation: Expected array of index for checkbox based list but got number: " + index);
  5477. }
  5478. return this.isIndexInRange(index) || this.isSingleSelectionList && index === constants_1.numbers.UNSET_INDEX;
  5479. } else {
  5480. return false;
  5481. }
  5482. };
  5483. MDCListFoundation.prototype.isIndexInRange = function (index) {
  5484. var listSize = this.adapter.getListItemCount();
  5485. return index >= 0 && index < listSize;
  5486. };
  5487. /**
  5488. * Sets selected index on user action, toggles checkboxes in checkbox lists
  5489. * by default, unless `isCheckboxAlreadyUpdatedInAdapter` is set to `true`.
  5490. *
  5491. * In cases where `isCheckboxAlreadyUpdatedInAdapter` is set to `true`, the
  5492. * UI is just updated to reflect the value returned by the adapter.
  5493. *
  5494. * When calling this, make sure user interaction does not toggle disabled
  5495. * list items.
  5496. */
  5497. MDCListFoundation.prototype.setSelectedIndexOnAction = function (index, isCheckboxAlreadyUpdatedInAdapter) {
  5498. this.lastSelectedIndex = index;
  5499. if (this.isCheckboxList) {
  5500. this.toggleCheckboxAtIndex(index, isCheckboxAlreadyUpdatedInAdapter);
  5501. this.adapter.notifySelectionChange([index]);
  5502. } else {
  5503. this.setSelectedIndex(index, { isUserInteraction: true });
  5504. }
  5505. };
  5506. MDCListFoundation.prototype.toggleCheckboxAtIndex = function (index, isCheckboxAlreadyUpdatedInAdapter) {
  5507. var selectionAttribute = this.getSelectionAttribute();
  5508. var adapterIsChecked = this.adapter.isCheckboxCheckedAtIndex(index);
  5509. // By default the checked value from the adapter is toggled unless the
  5510. // checked state in the adapter has already been updated beforehand.
  5511. // This can be happen when the underlying native checkbox has already
  5512. // been updated through the native click event.
  5513. var newCheckedValue;
  5514. if (isCheckboxAlreadyUpdatedInAdapter) {
  5515. newCheckedValue = adapterIsChecked;
  5516. } else {
  5517. newCheckedValue = !adapterIsChecked;
  5518. this.adapter.setCheckedCheckboxOrRadioAtIndex(index, newCheckedValue);
  5519. }
  5520. this.adapter.setAttributeForElementIndex(index, selectionAttribute, newCheckedValue ? 'true' : 'false');
  5521. // If none of the checkbox items are selected and selectedIndex is not
  5522. // initialized then provide a default value.
  5523. var selectedIndexes = this.selectedIndex === constants_1.numbers.UNSET_INDEX ? [] : this.selectedIndex.slice();
  5524. if (newCheckedValue) {
  5525. selectedIndexes.push(index);
  5526. } else {
  5527. selectedIndexes = selectedIndexes.filter(function (i) {
  5528. return i !== index;
  5529. });
  5530. }
  5531. this.selectedIndex = selectedIndexes;
  5532. };
  5533. MDCListFoundation.prototype.focusItemAtIndex = function (index) {
  5534. this.adapter.focusItemAtIndex(index);
  5535. this.focusedItemIndex = index;
  5536. };
  5537. MDCListFoundation.prototype.getEnabledListItemCount = function () {
  5538. var listSize = this.adapter.getListItemCount();
  5539. var adjustedCount = 0;
  5540. for (var i = 0; i < listSize; i++) {
  5541. if (!this.isIndexDisabled(i)) {
  5542. adjustedCount++;
  5543. }
  5544. }
  5545. return adjustedCount;
  5546. };
  5547. MDCListFoundation.prototype.checkboxListToggleAll = function (currentlySelectedIndices, isUserInteraction) {
  5548. var _this = this;
  5549. var enabledListItemCount = this.getEnabledListItemCount();
  5550. var totalListItemCount = this.adapter.getListItemCount();
  5551. var currentlyEnabledSelectedIndices = currentlySelectedIndices.filter(function (i) {
  5552. return !_this.isIndexDisabled(i);
  5553. });
  5554. // If all items are selected, deselect everything.
  5555. // We check >= rather than === to `enabledListItemCount` since a disabled
  5556. // item could be selected, and we don't take that into consideration when
  5557. // toggling the other checkbox values.
  5558. if (currentlyEnabledSelectedIndices.length >= enabledListItemCount) {
  5559. // Use omitDisabledItems option to ensure disabled selected items are not
  5560. // de-selected.
  5561. this.setCheckboxAtIndex([], { isUserInteraction: isUserInteraction, omitDisabledItems: true });
  5562. } else {
  5563. // Otherwise select all enabled options.
  5564. var allIndexes = [];
  5565. for (var i = 0; i < totalListItemCount; i++) {
  5566. if (!this.isIndexDisabled(i) || currentlySelectedIndices.indexOf(i) > -1) {
  5567. allIndexes.push(i);
  5568. }
  5569. }
  5570. // Use omitDisabledItems option to ensure disabled selected items are not
  5571. // de-selected.
  5572. this.setCheckboxAtIndex(allIndexes, { isUserInteraction: isUserInteraction, omitDisabledItems: true });
  5573. }
  5574. };
  5575. /**
  5576. * Given the next desired character from the user, adds it to the typeahead
  5577. * buffer. Then, attempts to find the next option matching the buffer. Wraps
  5578. * around if at the end of options.
  5579. *
  5580. * @param nextChar The next character to add to the prefix buffer.
  5581. * @param startingIndex The index from which to start matching. Only
  5582. * relevant when starting a new match sequence. To start a new match
  5583. * sequence, clear the buffer using `clearTypeaheadBuffer`, or wait for
  5584. * the buffer to clear after a set interval defined in list foundation.
  5585. * Defaults to the currently focused index.
  5586. * @return The index of the matched item, or -1 if no match.
  5587. */
  5588. MDCListFoundation.prototype.typeaheadMatchItem = function (nextChar, startingIndex, skipFocus) {
  5589. var _this = this;
  5590. if (skipFocus === void 0) {
  5591. skipFocus = false;
  5592. }
  5593. var opts = {
  5594. focusItemAtIndex: function focusItemAtIndex(index) {
  5595. _this.focusItemAtIndex(index);
  5596. },
  5597. focusedItemIndex: startingIndex ? startingIndex : this.focusedItemIndex,
  5598. nextChar: nextChar,
  5599. sortedIndexByFirstChar: this.sortedIndexByFirstChar,
  5600. skipFocus: skipFocus,
  5601. isItemAtIndexDisabled: function isItemAtIndexDisabled(index) {
  5602. return _this.isIndexDisabled(index);
  5603. }
  5604. };
  5605. return typeahead.matchItem(opts, this.typeaheadState);
  5606. };
  5607. /**
  5608. * Initializes the MDCListTextAndIndex data structure by indexing the
  5609. * current list items by primary text.
  5610. *
  5611. * @return The primary texts of all the list items sorted by first
  5612. * character.
  5613. */
  5614. MDCListFoundation.prototype.typeaheadInitSortedIndex = function () {
  5615. return typeahead.initSortedIndex(this.adapter.getListItemCount(), this.adapter.getPrimaryTextAtIndex);
  5616. };
  5617. /**
  5618. * Clears the typeahead buffer.
  5619. */
  5620. MDCListFoundation.prototype.clearTypeaheadBuffer = function () {
  5621. typeahead.clearBuffer(this.typeaheadState);
  5622. };
  5623. return MDCListFoundation;
  5624. }(foundation_1.MDCFoundation);
  5625. exports.MDCListFoundation = MDCListFoundation;
  5626. // tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
  5627. exports.default = MDCListFoundation;
  5628. /***/ }),
  5629. /***/ "./packages/mdc-list/typeahead.ts":
  5630. /*!****************************************!*\
  5631. !*** ./packages/mdc-list/typeahead.ts ***!
  5632. \****************************************/
  5633. /*! no static exports found */
  5634. /***/ (function(module, exports, __webpack_require__) {
  5635. "use strict";
  5636. /**
  5637. * @license
  5638. * Copyright 2020 Google Inc.
  5639. *
  5640. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5641. * of this software and associated documentation files (the "Software"), to deal
  5642. * in the Software without restriction, including without limitation the rights
  5643. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  5644. * copies of the Software, and to permit persons to whom the Software is
  5645. * furnished to do so, subject to the following conditions:
  5646. *
  5647. * The above copyright notice and this permission notice shall be included in
  5648. * all copies or substantial portions of the Software.
  5649. *
  5650. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  5651. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  5652. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  5653. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  5654. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  5655. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  5656. * THE SOFTWARE.
  5657. */
  5658. Object.defineProperty(exports, "__esModule", { value: true });
  5659. exports.handleKeydown = exports.clearBuffer = exports.isTypingInProgress = exports.matchItem = exports.initSortedIndex = exports.initState = void 0;
  5660. var keyboard_1 = __webpack_require__(/*! @material/dom/keyboard */ "./packages/mdc-dom/keyboard.ts");
  5661. var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-list/constants.ts");
  5662. var events_1 = __webpack_require__(/*! ./events */ "./packages/mdc-list/events.ts");
  5663. /**
  5664. * Initializes a state object for typeahead. Use the same reference for calls to
  5665. * typeahead functions.
  5666. *
  5667. * @return The current state of the typeahead process. Each state reference
  5668. * represents a typeahead instance as the reference is typically mutated
  5669. * in-place.
  5670. */
  5671. function initState() {
  5672. var state = {
  5673. bufferClearTimeout: 0,
  5674. currentFirstChar: '',
  5675. sortedIndexCursor: 0,
  5676. typeaheadBuffer: ''
  5677. };
  5678. return state;
  5679. }
  5680. exports.initState = initState;
  5681. /**
  5682. * Initializes typeahead state by indexing the current list items by primary
  5683. * text into the sortedIndexByFirstChar data structure.
  5684. *
  5685. * @param listItemCount numer of items in the list
  5686. * @param getPrimaryTextByItemIndex function that returns the primary text at a
  5687. * given index
  5688. *
  5689. * @return Map that maps the first character of the primary text to the full
  5690. * list text and its index
  5691. */
  5692. function initSortedIndex(listItemCount, getPrimaryTextByItemIndex) {
  5693. var sortedIndexByFirstChar = new Map();
  5694. // Aggregate item text to index mapping
  5695. for (var i = 0; i < listItemCount; i++) {
  5696. var primaryText = getPrimaryTextByItemIndex(i).trim();
  5697. if (!primaryText) {
  5698. continue;
  5699. }
  5700. var firstChar = primaryText[0].toLowerCase();
  5701. if (!sortedIndexByFirstChar.has(firstChar)) {
  5702. sortedIndexByFirstChar.set(firstChar, []);
  5703. }
  5704. sortedIndexByFirstChar.get(firstChar).push({ text: primaryText.toLowerCase(), index: i });
  5705. }
  5706. // Sort the mapping
  5707. // TODO(b/157162694): Investigate replacing forEach with Map.values()
  5708. sortedIndexByFirstChar.forEach(function (values) {
  5709. values.sort(function (first, second) {
  5710. return first.index - second.index;
  5711. });
  5712. });
  5713. return sortedIndexByFirstChar;
  5714. }
  5715. exports.initSortedIndex = initSortedIndex;
  5716. /**
  5717. * Given the next desired character from the user, it attempts to find the next
  5718. * list option matching the buffer. Wraps around if at the end of options.
  5719. *
  5720. * @param opts Options and accessors
  5721. * - nextChar - the next character to match against items
  5722. * - sortedIndexByFirstChar - output of `initSortedIndex(...)`
  5723. * - focusedItemIndex - the index of the currently focused item
  5724. * - focusItemAtIndex - function that focuses a list item at given index
  5725. * - skipFocus - whether or not to focus the matched item
  5726. * - isItemAtIndexDisabled - function that determines whether an item at a
  5727. * given index is disabled
  5728. * @param state The typeahead state instance. See `initState`.
  5729. *
  5730. * @return The index of the matched item, or -1 if no match.
  5731. */
  5732. function matchItem(opts, state) {
  5733. var nextChar = opts.nextChar,
  5734. focusItemAtIndex = opts.focusItemAtIndex,
  5735. sortedIndexByFirstChar = opts.sortedIndexByFirstChar,
  5736. focusedItemIndex = opts.focusedItemIndex,
  5737. skipFocus = opts.skipFocus,
  5738. isItemAtIndexDisabled = opts.isItemAtIndexDisabled;
  5739. clearTimeout(state.bufferClearTimeout);
  5740. state.bufferClearTimeout = setTimeout(function () {
  5741. clearBuffer(state);
  5742. }, constants_1.numbers.TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS);
  5743. state.typeaheadBuffer = state.typeaheadBuffer + nextChar;
  5744. var index;
  5745. if (state.typeaheadBuffer.length === 1) {
  5746. index = matchFirstChar(sortedIndexByFirstChar, focusedItemIndex, isItemAtIndexDisabled, state);
  5747. } else {
  5748. index = matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state);
  5749. }
  5750. if (index !== -1 && !skipFocus) {
  5751. focusItemAtIndex(index);
  5752. }
  5753. return index;
  5754. }
  5755. exports.matchItem = matchItem;
  5756. /**
  5757. * Matches the user's single input character in the buffer to the
  5758. * next option that begins with such character. Wraps around if at
  5759. * end of options. Returns -1 if no match is found.
  5760. */
  5761. function matchFirstChar(sortedIndexByFirstChar, focusedItemIndex, isItemAtIndexDisabled, state) {
  5762. var firstChar = state.typeaheadBuffer[0];
  5763. var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
  5764. if (!itemsMatchingFirstChar) {
  5765. return -1;
  5766. }
  5767. // Has the same firstChar been recently matched?
  5768. // Also, did starting index remain the same between key presses?
  5769. // If both hold true, simply increment index.
  5770. if (firstChar === state.currentFirstChar && itemsMatchingFirstChar[state.sortedIndexCursor].index === focusedItemIndex) {
  5771. state.sortedIndexCursor = (state.sortedIndexCursor + 1) % itemsMatchingFirstChar.length;
  5772. var newIndex = itemsMatchingFirstChar[state.sortedIndexCursor].index;
  5773. if (!isItemAtIndexDisabled(newIndex)) {
  5774. return newIndex;
  5775. }
  5776. }
  5777. // If we're here, it means one of the following happened:
  5778. // - either firstChar or startingIndex has changed, invalidating the
  5779. // cursor.
  5780. // - The next item of typeahead is disabled, so we have to look further.
  5781. state.currentFirstChar = firstChar;
  5782. var newCursorPosition = -1;
  5783. var cursorPosition;
  5784. // Find the first non-disabled item as a fallback.
  5785. for (cursorPosition = 0; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
  5786. if (!isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
  5787. newCursorPosition = cursorPosition;
  5788. break;
  5789. }
  5790. }
  5791. // Advance cursor to first item matching the firstChar that is positioned
  5792. // after starting item. Cursor is unchanged from fallback if there's no
  5793. // such item.
  5794. for (; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
  5795. if (itemsMatchingFirstChar[cursorPosition].index > focusedItemIndex && !isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
  5796. newCursorPosition = cursorPosition;
  5797. break;
  5798. }
  5799. }
  5800. if (newCursorPosition !== -1) {
  5801. state.sortedIndexCursor = newCursorPosition;
  5802. return itemsMatchingFirstChar[state.sortedIndexCursor].index;
  5803. }
  5804. return -1;
  5805. }
  5806. /**
  5807. * Attempts to find the next item that matches all of the typeahead buffer.
  5808. * Wraps around if at end of options. Returns -1 if no match is found.
  5809. */
  5810. function matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state) {
  5811. var firstChar = state.typeaheadBuffer[0];
  5812. var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
  5813. if (!itemsMatchingFirstChar) {
  5814. return -1;
  5815. }
  5816. // Do nothing if text already matches
  5817. var startingItem = itemsMatchingFirstChar[state.sortedIndexCursor];
  5818. if (startingItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0 && !isItemAtIndexDisabled(startingItem.index)) {
  5819. return startingItem.index;
  5820. }
  5821. // Find next item that matches completely; if no match, we'll eventually
  5822. // loop around to same position
  5823. var cursorPosition = (state.sortedIndexCursor + 1) % itemsMatchingFirstChar.length;
  5824. var nextCursorPosition = -1;
  5825. while (cursorPosition !== state.sortedIndexCursor) {
  5826. var currentItem = itemsMatchingFirstChar[cursorPosition];
  5827. var matches = currentItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0;
  5828. var isEnabled = !isItemAtIndexDisabled(currentItem.index);
  5829. if (matches && isEnabled) {
  5830. nextCursorPosition = cursorPosition;
  5831. break;
  5832. }
  5833. cursorPosition = (cursorPosition + 1) % itemsMatchingFirstChar.length;
  5834. }
  5835. if (nextCursorPosition !== -1) {
  5836. state.sortedIndexCursor = nextCursorPosition;
  5837. return itemsMatchingFirstChar[state.sortedIndexCursor].index;
  5838. }
  5839. return -1;
  5840. }
  5841. /**
  5842. * Whether or not the given typeahead instaance state is currently typing.
  5843. *
  5844. * @param state The typeahead state instance. See `initState`.
  5845. */
  5846. function isTypingInProgress(state) {
  5847. return state.typeaheadBuffer.length > 0;
  5848. }
  5849. exports.isTypingInProgress = isTypingInProgress;
  5850. /**
  5851. * Clears the typeahaed buffer so that it resets item matching to the first
  5852. * character.
  5853. *
  5854. * @param state The typeahead state instance. See `initState`.
  5855. */
  5856. function clearBuffer(state) {
  5857. state.typeaheadBuffer = '';
  5858. }
  5859. exports.clearBuffer = clearBuffer;
  5860. /**
  5861. * Given a keydown event, it calculates whether or not to automatically focus a
  5862. * list item depending on what was typed mimicking the typeahead functionality
  5863. * of a standard <select> element that is open.
  5864. *
  5865. * @param opts Options and accessors
  5866. * - event - the KeyboardEvent to handle and parse
  5867. * - sortedIndexByFirstChar - output of `initSortedIndex(...)`
  5868. * - focusedItemIndex - the index of the currently focused item
  5869. * - focusItemAtIndex - function that focuses a list item at given index
  5870. * - isItemAtFocusedIndexDisabled - whether or not the currently focused item
  5871. * is disabled
  5872. * - isTargetListItem - whether or not the event target is a list item
  5873. * @param state The typeahead state instance. See `initState`.
  5874. *
  5875. * @return index of the item matched by the keydown. -1 if not matched.
  5876. */
  5877. function handleKeydown(opts, state) {
  5878. var event = opts.event,
  5879. isTargetListItem = opts.isTargetListItem,
  5880. focusedItemIndex = opts.focusedItemIndex,
  5881. focusItemAtIndex = opts.focusItemAtIndex,
  5882. sortedIndexByFirstChar = opts.sortedIndexByFirstChar,
  5883. isItemAtIndexDisabled = opts.isItemAtIndexDisabled;
  5884. var isArrowLeft = keyboard_1.normalizeKey(event) === 'ArrowLeft';
  5885. var isArrowUp = keyboard_1.normalizeKey(event) === 'ArrowUp';
  5886. var isArrowRight = keyboard_1.normalizeKey(event) === 'ArrowRight';
  5887. var isArrowDown = keyboard_1.normalizeKey(event) === 'ArrowDown';
  5888. var isHome = keyboard_1.normalizeKey(event) === 'Home';
  5889. var isEnd = keyboard_1.normalizeKey(event) === 'End';
  5890. var isEnter = keyboard_1.normalizeKey(event) === 'Enter';
  5891. var isSpace = keyboard_1.normalizeKey(event) === 'Spacebar';
  5892. if (event.altKey || event.ctrlKey || event.metaKey || isArrowLeft || isArrowUp || isArrowRight || isArrowDown || isHome || isEnd || isEnter) {
  5893. return -1;
  5894. }
  5895. var isCharacterKey = !isSpace && event.key.length === 1;
  5896. if (isCharacterKey) {
  5897. events_1.preventDefaultEvent(event);
  5898. var matchItemOpts = {
  5899. focusItemAtIndex: focusItemAtIndex,
  5900. focusedItemIndex: focusedItemIndex,
  5901. nextChar: event.key.toLowerCase(),
  5902. sortedIndexByFirstChar: sortedIndexByFirstChar,
  5903. skipFocus: false,
  5904. isItemAtIndexDisabled: isItemAtIndexDisabled
  5905. };
  5906. return matchItem(matchItemOpts, state);
  5907. }
  5908. if (!isSpace) {
  5909. return -1;
  5910. }
  5911. if (isTargetListItem) {
  5912. events_1.preventDefaultEvent(event);
  5913. }
  5914. var typeaheadOnListItem = isTargetListItem && isTypingInProgress(state);
  5915. if (typeaheadOnListItem) {
  5916. var matchItemOpts = {
  5917. focusItemAtIndex: focusItemAtIndex,
  5918. focusedItemIndex: focusedItemIndex,
  5919. nextChar: ' ',
  5920. sortedIndexByFirstChar: sortedIndexByFirstChar,
  5921. skipFocus: false,
  5922. isItemAtIndexDisabled: isItemAtIndexDisabled
  5923. };
  5924. // space participates in typeahead matching if in rapid typing mode
  5925. return matchItem(matchItemOpts, state);
  5926. }
  5927. return -1;
  5928. }
  5929. exports.handleKeydown = handleKeydown;
  5930. /***/ }),
  5931. /***/ "./packages/mdc-menu-surface/component.ts":
  5932. /*!************************************************!*\
  5933. !*** ./packages/mdc-menu-surface/component.ts ***!
  5934. \************************************************/
  5935. /*! no static exports found */
  5936. /***/ (function(module, exports, __webpack_require__) {
  5937. "use strict";
  5938. /**
  5939. * @license
  5940. * Copyright 2018 Google Inc.
  5941. *
  5942. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5943. * of this software and associated documentation files (the "Software"), to deal
  5944. * in the Software without restriction, including without limitation the rights
  5945. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  5946. * copies of the Software, and to permit persons to whom the Software is
  5947. * furnished to do so, subject to the following conditions:
  5948. *
  5949. * The above copyright notice and this permission notice shall be included in
  5950. * all copies or substantial portions of the Software.
  5951. *
  5952. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  5953. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  5954. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  5955. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  5956. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  5957. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  5958. * THE SOFTWARE.
  5959. */
  5960. var __extends = this && this.__extends || function () {
  5961. var _extendStatics = function extendStatics(d, b) {
  5962. _extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
  5963. d.__proto__ = b;
  5964. } || function (d, b) {
  5965. for (var p in b) {
  5966. if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
  5967. }
  5968. };
  5969. return _extendStatics(d, b);
  5970. };
  5971. return function (d, b) {
  5972. if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  5973. _extendStatics(d, b);
  5974. function __() {
  5975. this.constructor = d;
  5976. }
  5977. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5978. };
  5979. }();
  5980. Object.defineProperty(exports, "__esModule", { value: true });
  5981. exports.MDCMenuSurface = void 0;
  5982. var util_1 = __webpack_require__(/*! @material/animation/util */ "./packages/mdc-animation/util.ts");
  5983. var component_1 = __webpack_require__(/*! @material/base/component */ "./packages/mdc-base/component.ts");
  5984. var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-menu-surface/constants.ts");
  5985. var foundation_1 = __webpack_require__(/*! ./foundation */ "./packages/mdc-menu-surface/foundation.ts");
  5986. /** MDC Menu Surface */
  5987. var MDCMenuSurface = /** @class */function (_super) {
  5988. __extends(MDCMenuSurface, _super);
  5989. function MDCMenuSurface() {
  5990. return _super !== null && _super.apply(this, arguments) || this;
  5991. }
  5992. MDCMenuSurface.attachTo = function (root) {
  5993. return new MDCMenuSurface(root);
  5994. };
  5995. MDCMenuSurface.prototype.initialSyncWithDOM = function () {
  5996. var _this = this;
  5997. var parentEl = this.root.parentElement;
  5998. this.anchorElement = parentEl && parentEl.classList.contains(constants_1.cssClasses.ANCHOR) ? parentEl : null;
  5999. if (this.root.classList.contains(constants_1.cssClasses.FIXED)) {
  6000. this.setFixedPosition(true);
  6001. }
  6002. this.handleKeydown = function (event) {
  6003. _this.foundation.handleKeydown(event);
  6004. };
  6005. this.handleBodyClick = function (event) {
  6006. _this.foundation.handleBodyClick(event);
  6007. };
  6008. // capture so that no race between handleBodyClick and quickOpen when
  6009. // menusurface opened on button click which registers this listener
  6010. this.registerBodyClickListener = function () {
  6011. document.body.addEventListener('click', _this.handleBodyClick, { capture: true });
  6012. };
  6013. this.deregisterBodyClickListener = function () {
  6014. document.body.removeEventListener('click', _this.handleBodyClick, { capture: true });
  6015. };
  6016. this.listen('keydown', this.handleKeydown);
  6017. this.listen(constants_1.strings.OPENED_EVENT, this.registerBodyClickListener);
  6018. this.listen(constants_1.strings.CLOSED_EVENT, this.deregisterBodyClickListener);
  6019. };
  6020. MDCMenuSurface.prototype.destroy = function () {
  6021. this.unlisten('keydown', this.handleKeydown);
  6022. this.unlisten(constants_1.strings.OPENED_EVENT, this.registerBodyClickListener);
  6023. this.unlisten(constants_1.strings.CLOSED_EVENT, this.deregisterBodyClickListener);
  6024. _super.prototype.destroy.call(this);
  6025. };
  6026. MDCMenuSurface.prototype.isOpen = function () {
  6027. return this.foundation.isOpen();
  6028. };
  6029. MDCMenuSurface.prototype.open = function () {
  6030. this.foundation.open();
  6031. };
  6032. MDCMenuSurface.prototype.close = function (skipRestoreFocus) {
  6033. if (skipRestoreFocus === void 0) {
  6034. skipRestoreFocus = false;
  6035. }
  6036. this.foundation.close(skipRestoreFocus);
  6037. };
  6038. Object.defineProperty(MDCMenuSurface.prototype, "quickOpen", {
  6039. set: function set(quickOpen) {
  6040. this.foundation.setQuickOpen(quickOpen);
  6041. },
  6042. enumerable: false,
  6043. configurable: true
  6044. });
  6045. /**
  6046. * Sets the foundation to use page offsets for a positioning when the menu is
  6047. * hoisted to the body.
  6048. */
  6049. MDCMenuSurface.prototype.setIsHoisted = function (isHoisted) {
  6050. this.foundation.setIsHoisted(isHoisted);
  6051. };
  6052. /** Sets the element that the menu-surface is anchored to. */
  6053. MDCMenuSurface.prototype.setMenuSurfaceAnchorElement = function (element) {
  6054. this.anchorElement = element;
  6055. };
  6056. /** Sets the menu-surface to position: fixed. */
  6057. MDCMenuSurface.prototype.setFixedPosition = function (isFixed) {
  6058. if (isFixed) {
  6059. this.root.classList.add(constants_1.cssClasses.FIXED);
  6060. } else {
  6061. this.root.classList.remove(constants_1.cssClasses.FIXED);
  6062. }
  6063. this.foundation.setFixedPosition(isFixed);
  6064. };
  6065. /**
  6066. * Sets the absolute x/y position to position based on. Requires the menu to
  6067. * be hoisted.
  6068. */
  6069. MDCMenuSurface.prototype.setAbsolutePosition = function (x, y) {
  6070. this.foundation.setAbsolutePosition(x, y);
  6071. this.setIsHoisted(true);
  6072. };
  6073. /**
  6074. * @param corner Default anchor corner alignment of top-left surface corner.
  6075. */
  6076. MDCMenuSurface.prototype.setAnchorCorner = function (corner) {
  6077. this.foundation.setAnchorCorner(corner);
  6078. };
  6079. MDCMenuSurface.prototype.setAnchorMargin = function (margin) {
  6080. this.foundation.setAnchorMargin(margin);
  6081. };
  6082. MDCMenuSurface.prototype.getDefaultFoundation = function () {
  6083. var _this = this;
  6084. // DO NOT INLINE this variable. For backward compatibility, foundations take
  6085. // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
  6086. // methods, we need a separate, strongly typed adapter variable.
  6087. // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
  6088. var adapter = {
  6089. addClass: function addClass(className) {
  6090. _this.root.classList.add(className);
  6091. },
  6092. removeClass: function removeClass(className) {
  6093. _this.root.classList.remove(className);
  6094. },
  6095. hasClass: function hasClass(className) {
  6096. return _this.root.classList.contains(className);
  6097. },
  6098. hasAnchor: function hasAnchor() {
  6099. return !!_this.anchorElement;
  6100. },
  6101. notifyClose: function notifyClose() {
  6102. _this.emit(foundation_1.MDCMenuSurfaceFoundation.strings.CLOSED_EVENT, {});
  6103. },
  6104. notifyClosing: function notifyClosing() {
  6105. _this.emit(foundation_1.MDCMenuSurfaceFoundation.strings.CLOSING_EVENT, {});
  6106. },
  6107. notifyOpen: function notifyOpen() {
  6108. _this.emit(foundation_1.MDCMenuSurfaceFoundation.strings.OPENED_EVENT, {});
  6109. },
  6110. notifyOpening: function notifyOpening() {
  6111. _this.emit(foundation_1.MDCMenuSurfaceFoundation.strings.OPENING_EVENT, {});
  6112. },
  6113. isElementInContainer: function isElementInContainer(el) {
  6114. return _this.root.contains(el);
  6115. },
  6116. isRtl: function isRtl() {
  6117. return getComputedStyle(_this.root).getPropertyValue('direction') === 'rtl';
  6118. },
  6119. setTransformOrigin: function setTransformOrigin(origin) {
  6120. var propertyName = util_1.getCorrectPropertyName(window, 'transform') + "-origin";
  6121. _this.root.style.setProperty(propertyName, origin);
  6122. },
  6123. isFocused: function isFocused() {
  6124. return document.activeElement === _this.root;
  6125. },
  6126. saveFocus: function saveFocus() {
  6127. _this.previousFocus = document.activeElement;
  6128. },
  6129. restoreFocus: function restoreFocus() {
  6130. if (_this.root.contains(document.activeElement)) {
  6131. if (_this.previousFocus && _this.previousFocus.focus) {
  6132. _this.previousFocus.focus();
  6133. }
  6134. }
  6135. },
  6136. getInnerDimensions: function getInnerDimensions() {
  6137. return { width: _this.root.offsetWidth, height: _this.root.offsetHeight };
  6138. },
  6139. getAnchorDimensions: function getAnchorDimensions() {
  6140. return _this.anchorElement ? _this.anchorElement.getBoundingClientRect() : null;
  6141. },
  6142. getViewportDimensions: function getViewportDimensions() {
  6143. return { width: window.innerWidth, height: window.innerHeight };
  6144. },
  6145. getBodyDimensions: function getBodyDimensions() {
  6146. return {
  6147. width: document.body.clientWidth,
  6148. height: document.body.clientHeight
  6149. };
  6150. },
  6151. getWindowScroll: function getWindowScroll() {
  6152. return { x: window.pageXOffset, y: window.pageYOffset };
  6153. },
  6154. setPosition: function setPosition(position) {
  6155. var rootHTML = _this.root;
  6156. rootHTML.style.left = 'left' in position ? position.left + "px" : '';
  6157. rootHTML.style.right = 'right' in position ? position.right + "px" : '';
  6158. rootHTML.style.top = 'top' in position ? position.top + "px" : '';
  6159. rootHTML.style.bottom = 'bottom' in position ? position.bottom + "px" : '';
  6160. },
  6161. setMaxHeight: function setMaxHeight(height) {
  6162. _this.root.style.maxHeight = height;
  6163. },
  6164. registerWindowEventHandler: function registerWindowEventHandler(evtType, handler) {
  6165. window.addEventListener(evtType, handler);
  6166. },
  6167. deregisterWindowEventHandler: function deregisterWindowEventHandler(evtType, handler) {
  6168. window.removeEventListener(evtType, handler);
  6169. }
  6170. };
  6171. // tslint:enable:object-literal-sort-keys
  6172. return new foundation_1.MDCMenuSurfaceFoundation(adapter);
  6173. };
  6174. return MDCMenuSurface;
  6175. }(component_1.MDCComponent);
  6176. exports.MDCMenuSurface = MDCMenuSurface;
  6177. /***/ }),
  6178. /***/ "./packages/mdc-menu-surface/constants.ts":
  6179. /*!************************************************!*\
  6180. !*** ./packages/mdc-menu-surface/constants.ts ***!
  6181. \************************************************/
  6182. /*! no static exports found */
  6183. /***/ (function(module, exports, __webpack_require__) {
  6184. "use strict";
  6185. /**
  6186. * @license
  6187. * Copyright 2018 Google Inc.
  6188. *
  6189. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6190. * of this software and associated documentation files (the "Software"), to deal
  6191. * in the Software without restriction, including without limitation the rights
  6192. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  6193. * copies of the Software, and to permit persons to whom the Software is
  6194. * furnished to do so, subject to the following conditions:
  6195. *
  6196. * The above copyright notice and this permission notice shall be included in
  6197. * all copies or substantial portions of the Software.
  6198. *
  6199. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  6200. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  6201. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  6202. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  6203. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  6204. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  6205. * THE SOFTWARE.
  6206. */
  6207. Object.defineProperty(exports, "__esModule", { value: true });
  6208. exports.Corner = exports.CornerBit = exports.numbers = exports.strings = exports.cssClasses = void 0;
  6209. var cssClasses = {
  6210. ANCHOR: 'mdc-menu-surface--anchor',
  6211. ANIMATING_CLOSED: 'mdc-menu-surface--animating-closed',
  6212. ANIMATING_OPEN: 'mdc-menu-surface--animating-open',
  6213. FIXED: 'mdc-menu-surface--fixed',
  6214. IS_OPEN_BELOW: 'mdc-menu-surface--is-open-below',
  6215. OPEN: 'mdc-menu-surface--open',
  6216. ROOT: 'mdc-menu-surface'
  6217. };
  6218. exports.cssClasses = cssClasses;
  6219. // tslint:disable:object-literal-sort-keys
  6220. var strings = {
  6221. CLOSED_EVENT: 'MDCMenuSurface:closed',
  6222. CLOSING_EVENT: 'MDCMenuSurface:closing',
  6223. OPENED_EVENT: 'MDCMenuSurface:opened',
  6224. OPENING_EVENT: 'MDCMenuSurface:opening',
  6225. FOCUSABLE_ELEMENTS: ['button:not(:disabled)', '[href]:not([aria-disabled="true"])', 'input:not(:disabled)', 'select:not(:disabled)', 'textarea:not(:disabled)', '[tabindex]:not([tabindex="-1"]):not([aria-disabled="true"])'].join(', ')
  6226. };
  6227. exports.strings = strings;
  6228. // tslint:enable:object-literal-sort-keys
  6229. var numbers = {
  6230. /** Total duration of menu-surface open animation. */
  6231. TRANSITION_OPEN_DURATION: 120,
  6232. /** Total duration of menu-surface close animation. */
  6233. TRANSITION_CLOSE_DURATION: 75,
  6234. /**
  6235. * Margin left to the edge of the viewport when menu-surface is at maximum
  6236. * possible height. Also used as a viewport margin.
  6237. */
  6238. MARGIN_TO_EDGE: 32,
  6239. /**
  6240. * Ratio of anchor width to menu-surface width for switching from corner
  6241. * positioning to center positioning.
  6242. */
  6243. ANCHOR_TO_MENU_SURFACE_WIDTH_RATIO: 0.67,
  6244. /**
  6245. * Amount of time to wait before restoring focus when closing the menu
  6246. * surface. This is important because if a touch event triggered the menu
  6247. * close, and the subsequent mouse event occurs after focus is restored, then
  6248. * the restored focus would be lost.
  6249. */
  6250. TOUCH_EVENT_WAIT_MS: 30
  6251. };
  6252. exports.numbers = numbers;
  6253. /**
  6254. * Enum for bits in the {@see Corner) bitmap.
  6255. */
  6256. var CornerBit;
  6257. (function (CornerBit) {
  6258. CornerBit[CornerBit["BOTTOM"] = 1] = "BOTTOM";
  6259. CornerBit[CornerBit["CENTER"] = 2] = "CENTER";
  6260. CornerBit[CornerBit["RIGHT"] = 4] = "RIGHT";
  6261. CornerBit[CornerBit["FLIP_RTL"] = 8] = "FLIP_RTL";
  6262. })(CornerBit || (CornerBit = {}));
  6263. exports.CornerBit = CornerBit;
  6264. /**
  6265. * Enum for representing an element corner for positioning the menu-surface.
  6266. *
  6267. * The START constants map to LEFT if element directionality is left
  6268. * to right and RIGHT if the directionality is right to left.
  6269. * Likewise END maps to RIGHT or LEFT depending on the directionality.
  6270. */
  6271. var Corner;
  6272. (function (Corner) {
  6273. Corner[Corner["TOP_LEFT"] = 0] = "TOP_LEFT";
  6274. Corner[Corner["TOP_RIGHT"] = 4] = "TOP_RIGHT";
  6275. Corner[Corner["BOTTOM_LEFT"] = 1] = "BOTTOM_LEFT";
  6276. Corner[Corner["BOTTOM_RIGHT"] = 5] = "BOTTOM_RIGHT";
  6277. Corner[Corner["TOP_START"] = 8] = "TOP_START";
  6278. Corner[Corner["TOP_END"] = 12] = "TOP_END";
  6279. Corner[Corner["BOTTOM_START"] = 9] = "BOTTOM_START";
  6280. Corner[Corner["BOTTOM_END"] = 13] = "BOTTOM_END";
  6281. })(Corner || (Corner = {}));
  6282. exports.Corner = Corner;
  6283. /***/ }),
  6284. /***/ "./packages/mdc-menu-surface/foundation.ts":
  6285. /*!*************************************************!*\
  6286. !*** ./packages/mdc-menu-surface/foundation.ts ***!
  6287. \*************************************************/
  6288. /*! no static exports found */
  6289. /***/ (function(module, exports, __webpack_require__) {
  6290. "use strict";
  6291. /**
  6292. * @license
  6293. * Copyright 2018 Google Inc.
  6294. *
  6295. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6296. * of this software and associated documentation files (the "Software"), to deal
  6297. * in the Software without restriction, including without limitation the rights
  6298. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  6299. * copies of the Software, and to permit persons to whom the Software is
  6300. * furnished to do so, subject to the following conditions:
  6301. *
  6302. * The above copyright notice and this permission notice shall be included in
  6303. * all copies or substantial portions of the Software.
  6304. *
  6305. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  6306. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  6307. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  6308. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  6309. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  6310. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  6311. * THE SOFTWARE.
  6312. */
  6313. var __extends = this && this.__extends || function () {
  6314. var _extendStatics = function extendStatics(d, b) {
  6315. _extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
  6316. d.__proto__ = b;
  6317. } || function (d, b) {
  6318. for (var p in b) {
  6319. if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
  6320. }
  6321. };
  6322. return _extendStatics(d, b);
  6323. };
  6324. return function (d, b) {
  6325. if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  6326. _extendStatics(d, b);
  6327. function __() {
  6328. this.constructor = d;
  6329. }
  6330. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6331. };
  6332. }();
  6333. var __assign = this && this.__assign || function () {
  6334. __assign = Object.assign || function (t) {
  6335. for (var s, i = 1, n = arguments.length; i < n; i++) {
  6336. s = arguments[i];
  6337. for (var p in s) {
  6338. if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  6339. }
  6340. }
  6341. return t;
  6342. };
  6343. return __assign.apply(this, arguments);
  6344. };
  6345. var __values = this && this.__values || function (o) {
  6346. var s = typeof Symbol === "function" && Symbol.iterator,
  6347. m = s && o[s],
  6348. i = 0;
  6349. if (m) return m.call(o);
  6350. if (o && typeof o.length === "number") return {
  6351. next: function next() {
  6352. if (o && i >= o.length) o = void 0;
  6353. return { value: o && o[i++], done: !o };
  6354. }
  6355. };
  6356. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  6357. };
  6358. Object.defineProperty(exports, "__esModule", { value: true });
  6359. exports.MDCMenuSurfaceFoundation = void 0;
  6360. var foundation_1 = __webpack_require__(/*! @material/base/foundation */ "./packages/mdc-base/foundation.ts");
  6361. var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-menu-surface/constants.ts");
  6362. /** MDC Menu Surface Foundation */
  6363. var MDCMenuSurfaceFoundation = /** @class */function (_super) {
  6364. __extends(MDCMenuSurfaceFoundation, _super);
  6365. function MDCMenuSurfaceFoundation(adapter) {
  6366. var _this = _super.call(this, __assign(__assign({}, MDCMenuSurfaceFoundation.defaultAdapter), adapter)) || this;
  6367. _this.isSurfaceOpen = false;
  6368. _this.isQuickOpen = false;
  6369. _this.isHoistedElement = false;
  6370. _this.isFixedPosition = false;
  6371. _this.isHorizontallyCenteredOnViewport = false;
  6372. _this.maxHeight = 0;
  6373. _this.openBottomBias = 0;
  6374. _this.openAnimationEndTimerId = 0;
  6375. _this.closeAnimationEndTimerId = 0;
  6376. _this.animationRequestId = 0;
  6377. _this.anchorCorner = constants_1.Corner.TOP_START;
  6378. /**
  6379. * Corner of the menu surface to which menu surface is attached to anchor.
  6380. *
  6381. * Anchor corner --->+----------+
  6382. * | ANCHOR |
  6383. * +----------+
  6384. * Origin corner --->+--------------+
  6385. * | |
  6386. * | |
  6387. * | MENU SURFACE |
  6388. * | |
  6389. * | |
  6390. * +--------------+
  6391. */
  6392. _this.originCorner = constants_1.Corner.TOP_START;
  6393. _this.anchorMargin = { top: 0, right: 0, bottom: 0, left: 0 };
  6394. _this.position = { x: 0, y: 0 };
  6395. return _this;
  6396. }
  6397. Object.defineProperty(MDCMenuSurfaceFoundation, "cssClasses", {
  6398. get: function get() {
  6399. return constants_1.cssClasses;
  6400. },
  6401. enumerable: false,
  6402. configurable: true
  6403. });
  6404. Object.defineProperty(MDCMenuSurfaceFoundation, "strings", {
  6405. get: function get() {
  6406. return constants_1.strings;
  6407. },
  6408. enumerable: false,
  6409. configurable: true
  6410. });
  6411. Object.defineProperty(MDCMenuSurfaceFoundation, "numbers", {
  6412. get: function get() {
  6413. return constants_1.numbers;
  6414. },
  6415. enumerable: false,
  6416. configurable: true
  6417. });
  6418. Object.defineProperty(MDCMenuSurfaceFoundation, "Corner", {
  6419. get: function get() {
  6420. return constants_1.Corner;
  6421. },
  6422. enumerable: false,
  6423. configurable: true
  6424. });
  6425. Object.defineProperty(MDCMenuSurfaceFoundation, "defaultAdapter", {
  6426. /**
  6427. * @see {@link MDCMenuSurfaceAdapter} for typing information on parameters and return types.
  6428. */
  6429. get: function get() {
  6430. // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
  6431. return {
  6432. addClass: function addClass() {
  6433. return undefined;
  6434. },
  6435. removeClass: function removeClass() {
  6436. return undefined;
  6437. },
  6438. hasClass: function hasClass() {
  6439. return false;
  6440. },
  6441. hasAnchor: function hasAnchor() {
  6442. return false;
  6443. },
  6444. isElementInContainer: function isElementInContainer() {
  6445. return false;
  6446. },
  6447. isFocused: function isFocused() {
  6448. return false;
  6449. },
  6450. isRtl: function isRtl() {
  6451. return false;
  6452. },
  6453. getInnerDimensions: function getInnerDimensions() {
  6454. return { height: 0, width: 0 };
  6455. },
  6456. getAnchorDimensions: function getAnchorDimensions() {
  6457. return null;
  6458. },
  6459. getViewportDimensions: function getViewportDimensions() {
  6460. return { height: 0, width: 0 };
  6461. },
  6462. getBodyDimensions: function getBodyDimensions() {
  6463. return { height: 0, width: 0 };
  6464. },
  6465. getWindowScroll: function getWindowScroll() {
  6466. return { x: 0, y: 0 };
  6467. },
  6468. setPosition: function setPosition() {
  6469. return undefined;
  6470. },
  6471. setMaxHeight: function setMaxHeight() {
  6472. return undefined;
  6473. },
  6474. setTransformOrigin: function setTransformOrigin() {
  6475. return undefined;
  6476. },
  6477. saveFocus: function saveFocus() {
  6478. return undefined;
  6479. },
  6480. restoreFocus: function restoreFocus() {
  6481. return undefined;
  6482. },
  6483. notifyClose: function notifyClose() {
  6484. return undefined;
  6485. },
  6486. notifyClosing: function notifyClosing() {
  6487. return undefined;
  6488. },
  6489. notifyOpen: function notifyOpen() {
  6490. return undefined;
  6491. },
  6492. notifyOpening: function notifyOpening() {
  6493. return undefined;
  6494. },
  6495. registerWindowEventHandler: function registerWindowEventHandler() {
  6496. return undefined;
  6497. },
  6498. deregisterWindowEventHandler: function deregisterWindowEventHandler() {
  6499. return undefined;
  6500. }
  6501. };
  6502. // tslint:enable:object-literal-sort-keys
  6503. },
  6504. enumerable: false,
  6505. configurable: true
  6506. });
  6507. MDCMenuSurfaceFoundation.prototype.init = function () {
  6508. var _a = MDCMenuSurfaceFoundation.cssClasses,
  6509. ROOT = _a.ROOT,
  6510. OPEN = _a.OPEN;
  6511. if (!this.adapter.hasClass(ROOT)) {
  6512. throw new Error(ROOT + " class required in root element.");
  6513. }
  6514. if (this.adapter.hasClass(OPEN)) {
  6515. this.isSurfaceOpen = true;
  6516. }
  6517. this.resizeListener = this.handleResize.bind(this);
  6518. this.adapter.registerWindowEventHandler('resize', this.resizeListener);
  6519. };
  6520. MDCMenuSurfaceFoundation.prototype.destroy = function () {
  6521. clearTimeout(this.openAnimationEndTimerId);
  6522. clearTimeout(this.closeAnimationEndTimerId);
  6523. // Cancel any currently running animations.
  6524. cancelAnimationFrame(this.animationRequestId);
  6525. this.adapter.deregisterWindowEventHandler('resize', this.resizeListener);
  6526. };
  6527. /**
  6528. * @param corner Default anchor corner alignment of top-left menu surface
  6529. * corner.
  6530. */
  6531. MDCMenuSurfaceFoundation.prototype.setAnchorCorner = function (corner) {
  6532. this.anchorCorner = corner;
  6533. };
  6534. /**
  6535. * Flip menu corner horizontally.
  6536. */
  6537. MDCMenuSurfaceFoundation.prototype.flipCornerHorizontally = function () {
  6538. this.originCorner = this.originCorner ^ constants_1.CornerBit.RIGHT;
  6539. };
  6540. /**
  6541. * @param margin Set of margin values from anchor.
  6542. */
  6543. MDCMenuSurfaceFoundation.prototype.setAnchorMargin = function (margin) {
  6544. this.anchorMargin.top = margin.top || 0;
  6545. this.anchorMargin.right = margin.right || 0;
  6546. this.anchorMargin.bottom = margin.bottom || 0;
  6547. this.anchorMargin.left = margin.left || 0;
  6548. };
  6549. /** Used to indicate if the menu-surface is hoisted to the body. */
  6550. MDCMenuSurfaceFoundation.prototype.setIsHoisted = function (isHoisted) {
  6551. this.isHoistedElement = isHoisted;
  6552. };
  6553. /**
  6554. * Used to set the menu-surface calculations based on a fixed position menu.
  6555. */
  6556. MDCMenuSurfaceFoundation.prototype.setFixedPosition = function (isFixedPosition) {
  6557. this.isFixedPosition = isFixedPosition;
  6558. };
  6559. /**
  6560. * @return Returns true if menu is in fixed (`position: fixed`) position.
  6561. */
  6562. MDCMenuSurfaceFoundation.prototype.isFixed = function () {
  6563. return this.isFixedPosition;
  6564. };
  6565. /** Sets the menu-surface position on the page. */
  6566. MDCMenuSurfaceFoundation.prototype.setAbsolutePosition = function (x, y) {
  6567. this.position.x = this.isFinite(x) ? x : 0;
  6568. this.position.y = this.isFinite(y) ? y : 0;
  6569. };
  6570. /** Sets whether menu-surface should be horizontally centered to viewport. */
  6571. MDCMenuSurfaceFoundation.prototype.setIsHorizontallyCenteredOnViewport = function (isCentered) {
  6572. this.isHorizontallyCenteredOnViewport = isCentered;
  6573. };
  6574. MDCMenuSurfaceFoundation.prototype.setQuickOpen = function (quickOpen) {
  6575. this.isQuickOpen = quickOpen;
  6576. };
  6577. /**
  6578. * Sets maximum menu-surface height on open.
  6579. * @param maxHeight The desired max-height. Set to 0 (default) to
  6580. * automatically calculate max height based on available viewport space.
  6581. */
  6582. MDCMenuSurfaceFoundation.prototype.setMaxHeight = function (maxHeight) {
  6583. this.maxHeight = maxHeight;
  6584. };
  6585. /**
  6586. * Set to a positive integer to influence the menu to preferentially open
  6587. * below the anchor instead of above.
  6588. * @param bias A value of `x` simulates an extra `x` pixels of available space
  6589. * below the menu during positioning calculations.
  6590. */
  6591. MDCMenuSurfaceFoundation.prototype.setOpenBottomBias = function (bias) {
  6592. this.openBottomBias = bias;
  6593. };
  6594. MDCMenuSurfaceFoundation.prototype.isOpen = function () {
  6595. return this.isSurfaceOpen;
  6596. };
  6597. /**
  6598. * Open the menu surface.
  6599. */
  6600. MDCMenuSurfaceFoundation.prototype.open = function () {
  6601. var _this = this;
  6602. if (this.isSurfaceOpen) {
  6603. return;
  6604. }
  6605. this.adapter.notifyOpening();
  6606. this.adapter.saveFocus();
  6607. if (this.isQuickOpen) {
  6608. this.isSurfaceOpen = true;
  6609. this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.OPEN);
  6610. this.dimensions = this.adapter.getInnerDimensions();
  6611. this.autoposition();
  6612. this.adapter.notifyOpen();
  6613. } else {
  6614. this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.ANIMATING_OPEN);
  6615. this.animationRequestId = requestAnimationFrame(function () {
  6616. _this.dimensions = _this.adapter.getInnerDimensions();
  6617. _this.autoposition();
  6618. _this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.OPEN);
  6619. _this.openAnimationEndTimerId = setTimeout(function () {
  6620. _this.openAnimationEndTimerId = 0;
  6621. _this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.ANIMATING_OPEN);
  6622. _this.adapter.notifyOpen();
  6623. }, constants_1.numbers.TRANSITION_OPEN_DURATION);
  6624. });
  6625. this.isSurfaceOpen = true;
  6626. }
  6627. this.adapter.registerWindowEventHandler('resize', this.resizeListener);
  6628. };
  6629. /**
  6630. * Closes the menu surface.
  6631. */
  6632. MDCMenuSurfaceFoundation.prototype.close = function (skipRestoreFocus) {
  6633. var _this = this;
  6634. if (skipRestoreFocus === void 0) {
  6635. skipRestoreFocus = false;
  6636. }
  6637. if (!this.isSurfaceOpen) {
  6638. return;
  6639. }
  6640. this.adapter.notifyClosing();
  6641. this.adapter.deregisterWindowEventHandler('resize', this.resizeListener);
  6642. if (this.isQuickOpen) {
  6643. this.isSurfaceOpen = false;
  6644. if (!skipRestoreFocus) {
  6645. this.maybeRestoreFocus();
  6646. }
  6647. this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.OPEN);
  6648. this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.IS_OPEN_BELOW);
  6649. this.adapter.notifyClose();
  6650. return;
  6651. }
  6652. this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.ANIMATING_CLOSED);
  6653. requestAnimationFrame(function () {
  6654. _this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.OPEN);
  6655. _this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.IS_OPEN_BELOW);
  6656. _this.closeAnimationEndTimerId = setTimeout(function () {
  6657. _this.closeAnimationEndTimerId = 0;
  6658. _this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.ANIMATING_CLOSED);
  6659. _this.adapter.notifyClose();
  6660. }, constants_1.numbers.TRANSITION_CLOSE_DURATION);
  6661. });
  6662. this.isSurfaceOpen = false;
  6663. if (!skipRestoreFocus) {
  6664. this.maybeRestoreFocus();
  6665. }
  6666. };
  6667. /** Handle clicks and close if not within menu-surface element. */
  6668. MDCMenuSurfaceFoundation.prototype.handleBodyClick = function (evt) {
  6669. var el = evt.target;
  6670. if (this.adapter.isElementInContainer(el)) {
  6671. return;
  6672. }
  6673. this.close();
  6674. };
  6675. /** Handle keys that close the surface. */
  6676. MDCMenuSurfaceFoundation.prototype.handleKeydown = function (evt) {
  6677. var keyCode = evt.keyCode,
  6678. key = evt.key;
  6679. var isEscape = key === 'Escape' || keyCode === 27;
  6680. if (isEscape) {
  6681. this.close();
  6682. }
  6683. };
  6684. /** Handles resize events on the window. */
  6685. MDCMenuSurfaceFoundation.prototype.handleResize = function () {
  6686. this.dimensions = this.adapter.getInnerDimensions();
  6687. this.autoposition();
  6688. };
  6689. MDCMenuSurfaceFoundation.prototype.autoposition = function () {
  6690. var _a;
  6691. // Compute measurements for autoposition methods reuse.
  6692. this.measurements = this.getAutoLayoutmeasurements();
  6693. var corner = this.getoriginCorner();
  6694. var maxMenuSurfaceHeight = this.getMenuSurfaceMaxHeight(corner);
  6695. var verticalAlignment = this.hasBit(corner, constants_1.CornerBit.BOTTOM) ? 'bottom' : 'top';
  6696. var horizontalAlignment = this.hasBit(corner, constants_1.CornerBit.RIGHT) ? 'right' : 'left';
  6697. var horizontalOffset = this.getHorizontalOriginOffset(corner);
  6698. var verticalOffset = this.getVerticalOriginOffset(corner);
  6699. var _b = this.measurements,
  6700. anchorSize = _b.anchorSize,
  6701. surfaceSize = _b.surfaceSize;
  6702. var position = (_a = {}, _a[horizontalAlignment] = horizontalOffset, _a[verticalAlignment] = verticalOffset, _a);
  6703. // Center align when anchor width is comparable or greater than menu
  6704. // surface, otherwise keep corner.
  6705. if (anchorSize.width / surfaceSize.width > constants_1.numbers.ANCHOR_TO_MENU_SURFACE_WIDTH_RATIO) {
  6706. horizontalAlignment = 'center';
  6707. }
  6708. // If the menu-surface has been hoisted to the body, it's no longer relative
  6709. // to the anchor element
  6710. if (this.isHoistedElement || this.isFixedPosition) {
  6711. this.adjustPositionForHoistedElement(position);
  6712. }
  6713. this.adapter.setTransformOrigin(horizontalAlignment + " " + verticalAlignment);
  6714. this.adapter.setPosition(position);
  6715. this.adapter.setMaxHeight(maxMenuSurfaceHeight ? maxMenuSurfaceHeight + 'px' : '');
  6716. // If it is opened from the top then add is-open-below class
  6717. if (!this.hasBit(corner, constants_1.CornerBit.BOTTOM)) {
  6718. this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.IS_OPEN_BELOW);
  6719. }
  6720. };
  6721. /**
  6722. * @return Measurements used to position menu surface popup.
  6723. */
  6724. MDCMenuSurfaceFoundation.prototype.getAutoLayoutmeasurements = function () {
  6725. var anchorRect = this.adapter.getAnchorDimensions();
  6726. var bodySize = this.adapter.getBodyDimensions();
  6727. var viewportSize = this.adapter.getViewportDimensions();
  6728. var windowScroll = this.adapter.getWindowScroll();
  6729. if (!anchorRect) {
  6730. // tslint:disable:object-literal-sort-keys Positional properties are more readable when they're grouped together
  6731. anchorRect = {
  6732. top: this.position.y,
  6733. right: this.position.x,
  6734. bottom: this.position.y,
  6735. left: this.position.x,
  6736. width: 0,
  6737. height: 0
  6738. };
  6739. // tslint:enable:object-literal-sort-keys
  6740. }
  6741. return {
  6742. anchorSize: anchorRect,
  6743. bodySize: bodySize,
  6744. surfaceSize: this.dimensions,
  6745. viewportDistance: {
  6746. // tslint:disable:object-literal-sort-keys Positional properties are more readable when they're grouped together
  6747. top: anchorRect.top,
  6748. right: viewportSize.width - anchorRect.right,
  6749. bottom: viewportSize.height - anchorRect.bottom,
  6750. left: anchorRect.left
  6751. },
  6752. viewportSize: viewportSize,
  6753. windowScroll: windowScroll
  6754. };
  6755. };
  6756. /**
  6757. * Computes the corner of the anchor from which to animate and position the
  6758. * menu surface.
  6759. *
  6760. * Only LEFT or RIGHT bit is used to position the menu surface ignoring RTL
  6761. * context. E.g., menu surface will be positioned from right side on TOP_END.
  6762. */
  6763. MDCMenuSurfaceFoundation.prototype.getoriginCorner = function () {
  6764. var corner = this.originCorner;
  6765. var _a = this.measurements,
  6766. viewportDistance = _a.viewportDistance,
  6767. anchorSize = _a.anchorSize,
  6768. surfaceSize = _a.surfaceSize;
  6769. var MARGIN_TO_EDGE = MDCMenuSurfaceFoundation.numbers.MARGIN_TO_EDGE;
  6770. var isAnchoredToBottom = this.hasBit(this.anchorCorner, constants_1.CornerBit.BOTTOM);
  6771. var availableTop;
  6772. var availableBottom;
  6773. if (isAnchoredToBottom) {
  6774. availableTop = viewportDistance.top - MARGIN_TO_EDGE + this.anchorMargin.bottom;
  6775. availableBottom = viewportDistance.bottom - MARGIN_TO_EDGE - this.anchorMargin.bottom;
  6776. } else {
  6777. availableTop = viewportDistance.top - MARGIN_TO_EDGE + this.anchorMargin.top;
  6778. availableBottom = viewportDistance.bottom - MARGIN_TO_EDGE + anchorSize.height - this.anchorMargin.top;
  6779. }
  6780. var isAvailableBottom = availableBottom - surfaceSize.height > 0;
  6781. if (!isAvailableBottom && availableTop > availableBottom + this.openBottomBias) {
  6782. // Attach bottom side of surface to the anchor.
  6783. corner = this.setBit(corner, constants_1.CornerBit.BOTTOM);
  6784. }
  6785. var isRtl = this.adapter.isRtl();
  6786. var isFlipRtl = this.hasBit(this.anchorCorner, constants_1.CornerBit.FLIP_RTL);
  6787. var hasRightBit = this.hasBit(this.anchorCorner, constants_1.CornerBit.RIGHT) || this.hasBit(corner, constants_1.CornerBit.RIGHT);
  6788. // Whether surface attached to right side of anchor element.
  6789. var isAnchoredToRight = false;
  6790. // Anchored to start
  6791. if (isRtl && isFlipRtl) {
  6792. isAnchoredToRight = !hasRightBit;
  6793. } else {
  6794. // Anchored to right
  6795. isAnchoredToRight = hasRightBit;
  6796. }
  6797. var availableLeft;
  6798. var availableRight;
  6799. if (isAnchoredToRight) {
  6800. availableLeft = viewportDistance.left + anchorSize.width + this.anchorMargin.left;
  6801. availableRight = viewportDistance.right - this.anchorMargin.left;
  6802. } else {
  6803. availableLeft = viewportDistance.left + this.anchorMargin.left;
  6804. availableRight = viewportDistance.right + anchorSize.width - this.anchorMargin.left;
  6805. }
  6806. var isAvailableLeft = availableLeft - surfaceSize.width > 0;
  6807. var isAvailableRight = availableRight - surfaceSize.width > 0;
  6808. var isOriginCornerAlignedToEnd = this.hasBit(corner, constants_1.CornerBit.FLIP_RTL) && this.hasBit(corner, constants_1.CornerBit.RIGHT);
  6809. if (isAvailableRight && isOriginCornerAlignedToEnd && isRtl || !isAvailableLeft && isOriginCornerAlignedToEnd) {
  6810. // Attach left side of surface to the anchor.
  6811. corner = this.unsetBit(corner, constants_1.CornerBit.RIGHT);
  6812. } else if (isAvailableLeft && isAnchoredToRight && isRtl || isAvailableLeft && !isAnchoredToRight && hasRightBit || !isAvailableRight && availableLeft >= availableRight) {
  6813. // Attach right side of surface to the anchor.
  6814. corner = this.setBit(corner, constants_1.CornerBit.RIGHT);
  6815. }
  6816. return corner;
  6817. };
  6818. /**
  6819. * @param corner Origin corner of the menu surface.
  6820. * @return Maximum height of the menu surface, based on available space. 0
  6821. * indicates should not be set.
  6822. */
  6823. MDCMenuSurfaceFoundation.prototype.getMenuSurfaceMaxHeight = function (corner) {
  6824. if (this.maxHeight > 0) {
  6825. return this.maxHeight;
  6826. }
  6827. var viewportDistance = this.measurements.viewportDistance;
  6828. var maxHeight = 0;
  6829. var isBottomAligned = this.hasBit(corner, constants_1.CornerBit.BOTTOM);
  6830. var isBottomAnchored = this.hasBit(this.anchorCorner, constants_1.CornerBit.BOTTOM);
  6831. var MARGIN_TO_EDGE = MDCMenuSurfaceFoundation.numbers.MARGIN_TO_EDGE;
  6832. // When maximum height is not specified, it is handled from CSS.
  6833. if (isBottomAligned) {
  6834. maxHeight = viewportDistance.top + this.anchorMargin.top - MARGIN_TO_EDGE;
  6835. if (!isBottomAnchored) {
  6836. maxHeight += this.measurements.anchorSize.height;
  6837. }
  6838. } else {
  6839. maxHeight = viewportDistance.bottom - this.anchorMargin.bottom + this.measurements.anchorSize.height - MARGIN_TO_EDGE;
  6840. if (isBottomAnchored) {
  6841. maxHeight -= this.measurements.anchorSize.height;
  6842. }
  6843. }
  6844. return maxHeight;
  6845. };
  6846. /**
  6847. * @param corner Origin corner of the menu surface.
  6848. * @return Horizontal offset of menu surface origin corner from corresponding
  6849. * anchor corner.
  6850. */
  6851. MDCMenuSurfaceFoundation.prototype.getHorizontalOriginOffset = function (corner) {
  6852. var anchorSize = this.measurements.anchorSize;
  6853. // isRightAligned corresponds to using the 'right' property on the surface.
  6854. var isRightAligned = this.hasBit(corner, constants_1.CornerBit.RIGHT);
  6855. var avoidHorizontalOverlap = this.hasBit(this.anchorCorner, constants_1.CornerBit.RIGHT);
  6856. if (isRightAligned) {
  6857. var rightOffset = avoidHorizontalOverlap ? anchorSize.width - this.anchorMargin.left : this.anchorMargin.right;
  6858. // For hoisted or fixed elements, adjust the offset by the difference
  6859. // between viewport width and body width so when we calculate the right
  6860. // value (`adjustPositionForHoistedElement`) based on the element
  6861. // position, the right property is correct.
  6862. if (this.isHoistedElement || this.isFixedPosition) {
  6863. return rightOffset - (this.measurements.viewportSize.width - this.measurements.bodySize.width);
  6864. }
  6865. return rightOffset;
  6866. }
  6867. return avoidHorizontalOverlap ? anchorSize.width - this.anchorMargin.right : this.anchorMargin.left;
  6868. };
  6869. /**
  6870. * @param corner Origin corner of the menu surface.
  6871. * @return Vertical offset of menu surface origin corner from corresponding
  6872. * anchor corner.
  6873. */
  6874. MDCMenuSurfaceFoundation.prototype.getVerticalOriginOffset = function (corner) {
  6875. var anchorSize = this.measurements.anchorSize;
  6876. var isBottomAligned = this.hasBit(corner, constants_1.CornerBit.BOTTOM);
  6877. var avoidVerticalOverlap = this.hasBit(this.anchorCorner, constants_1.CornerBit.BOTTOM);
  6878. var y = 0;
  6879. if (isBottomAligned) {
  6880. y = avoidVerticalOverlap ? anchorSize.height - this.anchorMargin.top : -this.anchorMargin.bottom;
  6881. } else {
  6882. y = avoidVerticalOverlap ? anchorSize.height + this.anchorMargin.bottom : this.anchorMargin.top;
  6883. }
  6884. return y;
  6885. };
  6886. /**
  6887. * Calculates the offsets for positioning the menu-surface when the
  6888. * menu-surface has been hoisted to the body.
  6889. */
  6890. MDCMenuSurfaceFoundation.prototype.adjustPositionForHoistedElement = function (position) {
  6891. var e_1, _a;
  6892. var _b = this.measurements,
  6893. windowScroll = _b.windowScroll,
  6894. viewportDistance = _b.viewportDistance,
  6895. surfaceSize = _b.surfaceSize,
  6896. viewportSize = _b.viewportSize;
  6897. var props = Object.keys(position);
  6898. try {
  6899. for (var props_1 = __values(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
  6900. var prop = props_1_1.value;
  6901. var value = position[prop] || 0;
  6902. if (this.isHorizontallyCenteredOnViewport && (prop === 'left' || prop === 'right')) {
  6903. position[prop] = (viewportSize.width - surfaceSize.width) / 2;
  6904. continue;
  6905. }
  6906. // Hoisted surfaces need to have the anchor elements location on the page
  6907. // added to the position properties for proper alignment on the body.
  6908. value += viewportDistance[prop];
  6909. // Surfaces that are absolutely positioned need to have additional
  6910. // calculations for scroll and bottom positioning.
  6911. if (!this.isFixedPosition) {
  6912. if (prop === 'top') {
  6913. value += windowScroll.y;
  6914. } else if (prop === 'bottom') {
  6915. value -= windowScroll.y;
  6916. } else if (prop === 'left') {
  6917. value += windowScroll.x;
  6918. } else {
  6919. // prop === 'right'
  6920. value -= windowScroll.x;
  6921. }
  6922. }
  6923. position[prop] = value;
  6924. }
  6925. } catch (e_1_1) {
  6926. e_1 = { error: e_1_1 };
  6927. } finally {
  6928. try {
  6929. if (props_1_1 && !props_1_1.done && (_a = props_1.return)) _a.call(props_1);
  6930. } finally {
  6931. if (e_1) throw e_1.error;
  6932. }
  6933. }
  6934. };
  6935. /**
  6936. * The last focused element when the menu surface was opened should regain
  6937. * focus, if the user is focused on or within the menu surface when it is
  6938. * closed.
  6939. */
  6940. MDCMenuSurfaceFoundation.prototype.maybeRestoreFocus = function () {
  6941. var _this = this;
  6942. var isRootFocused = this.adapter.isFocused();
  6943. var ownerDocument = this.adapter.getOwnerDocument ? this.adapter.getOwnerDocument() : document;
  6944. var childHasFocus = ownerDocument.activeElement && this.adapter.isElementInContainer(ownerDocument.activeElement);
  6945. if (isRootFocused || childHasFocus) {
  6946. // Wait before restoring focus when closing the menu surface. This is
  6947. // important because if a touch event triggered the menu close, and the
  6948. // subsequent mouse event occurs after focus is restored, then the
  6949. // restored focus would be lost.
  6950. setTimeout(function () {
  6951. _this.adapter.restoreFocus();
  6952. }, constants_1.numbers.TOUCH_EVENT_WAIT_MS);
  6953. }
  6954. };
  6955. MDCMenuSurfaceFoundation.prototype.hasBit = function (corner, bit) {
  6956. return Boolean(corner & bit); // tslint:disable-line:no-bitwise
  6957. };
  6958. MDCMenuSurfaceFoundation.prototype.setBit = function (corner, bit) {
  6959. return corner | bit; // tslint:disable-line:no-bitwise
  6960. };
  6961. MDCMenuSurfaceFoundation.prototype.unsetBit = function (corner, bit) {
  6962. return corner ^ bit;
  6963. };
  6964. /**
  6965. * isFinite that doesn't force conversion to number type.
  6966. * Equivalent to Number.isFinite in ES2015, which is not supported in IE.
  6967. */
  6968. MDCMenuSurfaceFoundation.prototype.isFinite = function (num) {
  6969. return typeof num === 'number' && isFinite(num);
  6970. };
  6971. return MDCMenuSurfaceFoundation;
  6972. }(foundation_1.MDCFoundation);
  6973. exports.MDCMenuSurfaceFoundation = MDCMenuSurfaceFoundation;
  6974. // tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
  6975. exports.default = MDCMenuSurfaceFoundation;
  6976. /***/ }),
  6977. /***/ "./packages/mdc-menu/adapter.ts":
  6978. /*!**************************************!*\
  6979. !*** ./packages/mdc-menu/adapter.ts ***!
  6980. \**************************************/
  6981. /*! no static exports found */
  6982. /***/ (function(module, exports, __webpack_require__) {
  6983. "use strict";
  6984. /**
  6985. * @license
  6986. * Copyright 2018 Google Inc.
  6987. *
  6988. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6989. * of this software and associated documentation files (the "Software"), to deal
  6990. * in the Software without restriction, including without limitation the rights
  6991. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  6992. * copies of the Software, and to permit persons to whom the Software is
  6993. * furnished to do so, subject to the following conditions:
  6994. *
  6995. * The above copyright notice and this permission notice shall be included in
  6996. * all copies or substantial portions of the Software.
  6997. *
  6998. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  6999. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  7000. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  7001. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  7002. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  7003. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  7004. * THE SOFTWARE.
  7005. */
  7006. Object.defineProperty(exports, "__esModule", { value: true });
  7007. /***/ }),
  7008. /***/ "./packages/mdc-menu/component.ts":
  7009. /*!****************************************!*\
  7010. !*** ./packages/mdc-menu/component.ts ***!
  7011. \****************************************/
  7012. /*! no static exports found */
  7013. /***/ (function(module, exports, __webpack_require__) {
  7014. "use strict";
  7015. /**
  7016. * @license
  7017. * Copyright 2018 Google Inc.
  7018. *
  7019. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7020. * of this software and associated documentation files (the "Software"), to deal
  7021. * in the Software without restriction, including without limitation the rights
  7022. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7023. * copies of the Software, and to permit persons to whom the Software is
  7024. * furnished to do so, subject to the following conditions:
  7025. *
  7026. * The above copyright notice and this permission notice shall be included in
  7027. * all copies or substantial portions of the Software.
  7028. *
  7029. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  7030. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  7031. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  7032. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  7033. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  7034. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  7035. * THE SOFTWARE.
  7036. */
  7037. var __extends = this && this.__extends || function () {
  7038. var _extendStatics = function extendStatics(d, b) {
  7039. _extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
  7040. d.__proto__ = b;
  7041. } || function (d, b) {
  7042. for (var p in b) {
  7043. if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
  7044. }
  7045. };
  7046. return _extendStatics(d, b);
  7047. };
  7048. return function (d, b) {
  7049. if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  7050. _extendStatics(d, b);
  7051. function __() {
  7052. this.constructor = d;
  7053. }
  7054. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7055. };
  7056. }();
  7057. Object.defineProperty(exports, "__esModule", { value: true });
  7058. exports.MDCMenu = void 0;
  7059. var component_1 = __webpack_require__(/*! @material/base/component */ "./packages/mdc-base/component.ts");
  7060. var ponyfill_1 = __webpack_require__(/*! @material/dom/ponyfill */ "./packages/mdc-dom/ponyfill.ts");
  7061. var component_2 = __webpack_require__(/*! @material/list/component */ "./packages/mdc-list/component.ts");
  7062. var constants_1 = __webpack_require__(/*! @material/list/constants */ "./packages/mdc-list/constants.ts");
  7063. var foundation_1 = __webpack_require__(/*! @material/list/foundation */ "./packages/mdc-list/foundation.ts");
  7064. var component_3 = __webpack_require__(/*! @material/menu-surface/component */ "./packages/mdc-menu-surface/component.ts");
  7065. var foundation_2 = __webpack_require__(/*! @material/menu-surface/foundation */ "./packages/mdc-menu-surface/foundation.ts");
  7066. var constants_2 = __webpack_require__(/*! ./constants */ "./packages/mdc-menu/constants.ts");
  7067. var foundation_3 = __webpack_require__(/*! ./foundation */ "./packages/mdc-menu/foundation.ts");
  7068. /** MDC Menu */
  7069. var MDCMenu = /** @class */function (_super) {
  7070. __extends(MDCMenu, _super);
  7071. function MDCMenu() {
  7072. return _super !== null && _super.apply(this, arguments) || this;
  7073. }
  7074. MDCMenu.attachTo = function (root) {
  7075. return new MDCMenu(root);
  7076. };
  7077. MDCMenu.prototype.initialize = function (menuSurfaceFactory, listFactory) {
  7078. if (menuSurfaceFactory === void 0) {
  7079. menuSurfaceFactory = function menuSurfaceFactory(el) {
  7080. return new component_3.MDCMenuSurface(el);
  7081. };
  7082. }
  7083. if (listFactory === void 0) {
  7084. listFactory = function listFactory(el) {
  7085. return new component_2.MDCList(el);
  7086. };
  7087. }
  7088. this.menuSurfaceFactory = menuSurfaceFactory;
  7089. this.listFactory = listFactory;
  7090. };
  7091. MDCMenu.prototype.initialSyncWithDOM = function () {
  7092. var _this = this;
  7093. this.menuSurface = this.menuSurfaceFactory(this.root);
  7094. var list = this.root.querySelector(constants_2.strings.LIST_SELECTOR);
  7095. if (list) {
  7096. this.list = this.listFactory(list);
  7097. this.list.wrapFocus = true;
  7098. } else {
  7099. this.list = null;
  7100. }
  7101. this.handleKeydown = function (evt) {
  7102. _this.foundation.handleKeydown(evt);
  7103. };
  7104. this.handleItemAction = function (evt) {
  7105. _this.foundation.handleItemAction(_this.items[evt.detail.index]);
  7106. };
  7107. this.handleMenuSurfaceOpened = function () {
  7108. _this.foundation.handleMenuSurfaceOpened();
  7109. };
  7110. this.menuSurface.listen(foundation_2.MDCMenuSurfaceFoundation.strings.OPENED_EVENT, this.handleMenuSurfaceOpened);
  7111. this.listen('keydown', this.handleKeydown);
  7112. this.listen(foundation_1.MDCListFoundation.strings.ACTION_EVENT, this.handleItemAction);
  7113. };
  7114. MDCMenu.prototype.destroy = function () {
  7115. if (this.list) {
  7116. this.list.destroy();
  7117. }
  7118. this.menuSurface.destroy();
  7119. this.menuSurface.unlisten(foundation_2.MDCMenuSurfaceFoundation.strings.OPENED_EVENT, this.handleMenuSurfaceOpened);
  7120. this.unlisten('keydown', this.handleKeydown);
  7121. this.unlisten(foundation_1.MDCListFoundation.strings.ACTION_EVENT, this.handleItemAction);
  7122. _super.prototype.destroy.call(this);
  7123. };
  7124. Object.defineProperty(MDCMenu.prototype, "open", {
  7125. get: function get() {
  7126. return this.menuSurface.isOpen();
  7127. },
  7128. set: function set(value) {
  7129. if (value) {
  7130. this.menuSurface.open();
  7131. } else {
  7132. this.menuSurface.close();
  7133. }
  7134. },
  7135. enumerable: false,
  7136. configurable: true
  7137. });
  7138. Object.defineProperty(MDCMenu.prototype, "wrapFocus", {
  7139. get: function get() {
  7140. return this.list ? this.list.wrapFocus : false;
  7141. },
  7142. set: function set(value) {
  7143. if (this.list) {
  7144. this.list.wrapFocus = value;
  7145. }
  7146. },
  7147. enumerable: false,
  7148. configurable: true
  7149. });
  7150. Object.defineProperty(MDCMenu.prototype, "hasTypeahead", {
  7151. /**
  7152. * Sets whether the menu has typeahead functionality.
  7153. * @param value Whether typeahead is enabled.
  7154. */
  7155. set: function set(value) {
  7156. if (this.list) {
  7157. this.list.hasTypeahead = value;
  7158. }
  7159. },
  7160. enumerable: false,
  7161. configurable: true
  7162. });
  7163. Object.defineProperty(MDCMenu.prototype, "typeaheadInProgress", {
  7164. /**
  7165. * @return Whether typeahead logic is currently matching some user prefix.
  7166. */
  7167. get: function get() {
  7168. return this.list ? this.list.typeaheadInProgress : false;
  7169. },
  7170. enumerable: false,
  7171. configurable: true
  7172. });
  7173. /**
  7174. * Given the next desired character from the user, adds it to the typeahead
  7175. * buffer. Then, attempts to find the next option matching the buffer. Wraps
  7176. * around if at the end of options.
  7177. *
  7178. * @param nextChar The next character to add to the prefix buffer.
  7179. * @param startingIndex The index from which to start matching. Only relevant
  7180. * when starting a new match sequence. To start a new match sequence,
  7181. * clear the buffer using `clearTypeaheadBuffer`, or wait for the buffer
  7182. * to clear after a set interval defined in list foundation. Defaults to
  7183. * the currently focused index.
  7184. * @return The index of the matched item, or -1 if no match.
  7185. */
  7186. MDCMenu.prototype.typeaheadMatchItem = function (nextChar, startingIndex) {
  7187. if (this.list) {
  7188. return this.list.typeaheadMatchItem(nextChar, startingIndex);
  7189. }
  7190. return -1;
  7191. };
  7192. /**
  7193. * Layout the underlying list element in the case of any dynamic updates
  7194. * to its structure.
  7195. */
  7196. MDCMenu.prototype.layout = function () {
  7197. if (this.list) {
  7198. this.list.layout();
  7199. }
  7200. };
  7201. Object.defineProperty(MDCMenu.prototype, "items", {
  7202. /**
  7203. * Return the items within the menu. Note that this only contains the set of
  7204. * elements within the items container that are proper list items, and not
  7205. * supplemental / presentational DOM elements.
  7206. */
  7207. get: function get() {
  7208. return this.list ? this.list.listElements : [];
  7209. },
  7210. enumerable: false,
  7211. configurable: true
  7212. });
  7213. Object.defineProperty(MDCMenu.prototype, "singleSelection", {
  7214. /**
  7215. * Turns on/off the underlying list's single selection mode. Used mainly
  7216. * by select menu.
  7217. *
  7218. * @param singleSelection Whether to enable single selection mode.
  7219. */
  7220. set: function set(singleSelection) {
  7221. if (this.list) {
  7222. this.list.singleSelection = singleSelection;
  7223. }
  7224. },
  7225. enumerable: false,
  7226. configurable: true
  7227. });
  7228. Object.defineProperty(MDCMenu.prototype, "selectedIndex", {
  7229. /**
  7230. * Retrieves the selected index. Only applicable to select menus.
  7231. * @return The selected index, which is a number for single selection and
  7232. * radio lists, and an array of numbers for checkbox lists.
  7233. */
  7234. get: function get() {
  7235. return this.list ? this.list.selectedIndex : constants_1.numbers.UNSET_INDEX;
  7236. },
  7237. /**
  7238. * Sets the selected index of the list. Only applicable to select menus.
  7239. * @param index The selected index, which is a number for single selection and
  7240. * radio lists, and an array of numbers for checkbox lists.
  7241. */
  7242. set: function set(index) {
  7243. if (this.list) {
  7244. this.list.selectedIndex = index;
  7245. }
  7246. },
  7247. enumerable: false,
  7248. configurable: true
  7249. });
  7250. Object.defineProperty(MDCMenu.prototype, "quickOpen", {
  7251. set: function set(quickOpen) {
  7252. this.menuSurface.quickOpen = quickOpen;
  7253. },
  7254. enumerable: false,
  7255. configurable: true
  7256. });
  7257. /**
  7258. * Sets default focus state where the menu should focus every time when menu
  7259. * is opened. Focuses the list root (`DefaultFocusState.LIST_ROOT`) element by
  7260. * default.
  7261. * @param focusState Default focus state.
  7262. */
  7263. MDCMenu.prototype.setDefaultFocusState = function (focusState) {
  7264. this.foundation.setDefaultFocusState(focusState);
  7265. };
  7266. /**
  7267. * @param corner Default anchor corner alignment of top-left menu corner.
  7268. */
  7269. MDCMenu.prototype.setAnchorCorner = function (corner) {
  7270. this.menuSurface.setAnchorCorner(corner);
  7271. };
  7272. MDCMenu.prototype.setAnchorMargin = function (margin) {
  7273. this.menuSurface.setAnchorMargin(margin);
  7274. };
  7275. /**
  7276. * Sets the list item as the selected row at the specified index.
  7277. * @param index Index of list item within menu.
  7278. */
  7279. MDCMenu.prototype.setSelectedIndex = function (index) {
  7280. this.foundation.setSelectedIndex(index);
  7281. };
  7282. /**
  7283. * Sets the enabled state to isEnabled for the menu item at the given index.
  7284. * @param index Index of the menu item
  7285. * @param isEnabled The desired enabled state of the menu item.
  7286. */
  7287. MDCMenu.prototype.setEnabled = function (index, isEnabled) {
  7288. this.foundation.setEnabled(index, isEnabled);
  7289. };
  7290. /**
  7291. * @return The item within the menu at the index specified.
  7292. */
  7293. MDCMenu.prototype.getOptionByIndex = function (index) {
  7294. var items = this.items;
  7295. if (index < items.length) {
  7296. return this.items[index];
  7297. } else {
  7298. return null;
  7299. }
  7300. };
  7301. /**
  7302. * @param index A menu item's index.
  7303. * @return The primary text within the menu at the index specified.
  7304. */
  7305. MDCMenu.prototype.getPrimaryTextAtIndex = function (index) {
  7306. var item = this.getOptionByIndex(index);
  7307. if (item && this.list) {
  7308. return this.list.getPrimaryText(item) || '';
  7309. }
  7310. return '';
  7311. };
  7312. MDCMenu.prototype.setFixedPosition = function (isFixed) {
  7313. this.menuSurface.setFixedPosition(isFixed);
  7314. };
  7315. MDCMenu.prototype.setIsHoisted = function (isHoisted) {
  7316. this.menuSurface.setIsHoisted(isHoisted);
  7317. };
  7318. MDCMenu.prototype.setAbsolutePosition = function (x, y) {
  7319. this.menuSurface.setAbsolutePosition(x, y);
  7320. };
  7321. /**
  7322. * Sets the element that the menu-surface is anchored to.
  7323. */
  7324. MDCMenu.prototype.setAnchorElement = function (element) {
  7325. this.menuSurface.anchorElement = element;
  7326. };
  7327. MDCMenu.prototype.getDefaultFoundation = function () {
  7328. var _this = this;
  7329. // DO NOT INLINE this variable. For backward compatibility, foundations take
  7330. // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
  7331. // methods, we need a separate, strongly typed adapter variable.
  7332. // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
  7333. var adapter = {
  7334. addClassToElementAtIndex: function addClassToElementAtIndex(index, className) {
  7335. var list = _this.items;
  7336. list[index].classList.add(className);
  7337. },
  7338. removeClassFromElementAtIndex: function removeClassFromElementAtIndex(index, className) {
  7339. var list = _this.items;
  7340. list[index].classList.remove(className);
  7341. },
  7342. addAttributeToElementAtIndex: function addAttributeToElementAtIndex(index, attr, value) {
  7343. var list = _this.items;
  7344. _this.safeSetAttribute(list[index], attr, value);
  7345. },
  7346. removeAttributeFromElementAtIndex: function removeAttributeFromElementAtIndex(index, attr) {
  7347. var list = _this.items;
  7348. list[index].removeAttribute(attr);
  7349. },
  7350. getAttributeFromElementAtIndex: function getAttributeFromElementAtIndex(index, attr) {
  7351. var list = _this.items;
  7352. return list[index].getAttribute(attr);
  7353. },
  7354. elementContainsClass: function elementContainsClass(element, className) {
  7355. return element.classList.contains(className);
  7356. },
  7357. closeSurface: function closeSurface(skipRestoreFocus) {
  7358. _this.menuSurface.close(skipRestoreFocus);
  7359. },
  7360. getElementIndex: function getElementIndex(element) {
  7361. return _this.items.indexOf(element);
  7362. },
  7363. notifySelected: function notifySelected(evtData) {
  7364. _this.emit(constants_2.strings.SELECTED_EVENT, {
  7365. index: evtData.index,
  7366. item: _this.items[evtData.index]
  7367. });
  7368. },
  7369. getMenuItemCount: function getMenuItemCount() {
  7370. return _this.items.length;
  7371. },
  7372. focusItemAtIndex: function focusItemAtIndex(index) {
  7373. _this.items[index].focus();
  7374. },
  7375. focusListRoot: function focusListRoot() {
  7376. _this.root.querySelector(constants_2.strings.LIST_SELECTOR).focus();
  7377. },
  7378. isSelectableItemAtIndex: function isSelectableItemAtIndex(index) {
  7379. return !!ponyfill_1.closest(_this.items[index], "." + constants_2.cssClasses.MENU_SELECTION_GROUP);
  7380. },
  7381. getSelectedSiblingOfItemAtIndex: function getSelectedSiblingOfItemAtIndex(index) {
  7382. var selectionGroupEl = ponyfill_1.closest(_this.items[index], "." + constants_2.cssClasses.MENU_SELECTION_GROUP);
  7383. var selectedItemEl = selectionGroupEl.querySelector("." + constants_2.cssClasses.MENU_SELECTED_LIST_ITEM);
  7384. return selectedItemEl ? _this.items.indexOf(selectedItemEl) : -1;
  7385. }
  7386. };
  7387. // tslint:enable:object-literal-sort-keys
  7388. return new foundation_3.MDCMenuFoundation(adapter);
  7389. };
  7390. return MDCMenu;
  7391. }(component_1.MDCComponent);
  7392. exports.MDCMenu = MDCMenu;
  7393. /***/ }),
  7394. /***/ "./packages/mdc-menu/constants.ts":
  7395. /*!****************************************!*\
  7396. !*** ./packages/mdc-menu/constants.ts ***!
  7397. \****************************************/
  7398. /*! no static exports found */
  7399. /***/ (function(module, exports, __webpack_require__) {
  7400. "use strict";
  7401. /**
  7402. * @license
  7403. * Copyright 2018 Google Inc.
  7404. *
  7405. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7406. * of this software and associated documentation files (the "Software"), to deal
  7407. * in the Software without restriction, including without limitation the rights
  7408. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7409. * copies of the Software, and to permit persons to whom the Software is
  7410. * furnished to do so, subject to the following conditions:
  7411. *
  7412. * The above copyright notice and this permission notice shall be included in
  7413. * all copies or substantial portions of the Software.
  7414. *
  7415. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  7416. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  7417. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  7418. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  7419. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  7420. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  7421. * THE SOFTWARE.
  7422. */
  7423. Object.defineProperty(exports, "__esModule", { value: true });
  7424. exports.DefaultFocusState = exports.numbers = exports.strings = exports.cssClasses = void 0;
  7425. var cssClasses = {
  7426. MENU_SELECTED_LIST_ITEM: 'mdc-menu-item--selected',
  7427. MENU_SELECTION_GROUP: 'mdc-menu__selection-group',
  7428. ROOT: 'mdc-menu'
  7429. };
  7430. exports.cssClasses = cssClasses;
  7431. var strings = {
  7432. ARIA_CHECKED_ATTR: 'aria-checked',
  7433. ARIA_DISABLED_ATTR: 'aria-disabled',
  7434. CHECKBOX_SELECTOR: 'input[type="checkbox"]',
  7435. LIST_SELECTOR: '.mdc-list,.mdc-deprecated-list',
  7436. SELECTED_EVENT: 'MDCMenu:selected',
  7437. SKIP_RESTORE_FOCUS: 'data-menu-item-skip-restore-focus'
  7438. };
  7439. exports.strings = strings;
  7440. var numbers = {
  7441. FOCUS_ROOT_INDEX: -1
  7442. };
  7443. exports.numbers = numbers;
  7444. var DefaultFocusState;
  7445. (function (DefaultFocusState) {
  7446. DefaultFocusState[DefaultFocusState["NONE"] = 0] = "NONE";
  7447. DefaultFocusState[DefaultFocusState["LIST_ROOT"] = 1] = "LIST_ROOT";
  7448. DefaultFocusState[DefaultFocusState["FIRST_ITEM"] = 2] = "FIRST_ITEM";
  7449. DefaultFocusState[DefaultFocusState["LAST_ITEM"] = 3] = "LAST_ITEM";
  7450. })(DefaultFocusState || (DefaultFocusState = {}));
  7451. exports.DefaultFocusState = DefaultFocusState;
  7452. /***/ }),
  7453. /***/ "./packages/mdc-menu/foundation.ts":
  7454. /*!*****************************************!*\
  7455. !*** ./packages/mdc-menu/foundation.ts ***!
  7456. \*****************************************/
  7457. /*! no static exports found */
  7458. /***/ (function(module, exports, __webpack_require__) {
  7459. "use strict";
  7460. /**
  7461. * @license
  7462. * Copyright 2018 Google Inc.
  7463. *
  7464. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7465. * of this software and associated documentation files (the "Software"), to deal
  7466. * in the Software without restriction, including without limitation the rights
  7467. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7468. * copies of the Software, and to permit persons to whom the Software is
  7469. * furnished to do so, subject to the following conditions:
  7470. *
  7471. * The above copyright notice and this permission notice shall be included in
  7472. * all copies or substantial portions of the Software.
  7473. *
  7474. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  7475. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  7476. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  7477. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  7478. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  7479. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  7480. * THE SOFTWARE.
  7481. */
  7482. var __extends = this && this.__extends || function () {
  7483. var _extendStatics = function extendStatics(d, b) {
  7484. _extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
  7485. d.__proto__ = b;
  7486. } || function (d, b) {
  7487. for (var p in b) {
  7488. if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
  7489. }
  7490. };
  7491. return _extendStatics(d, b);
  7492. };
  7493. return function (d, b) {
  7494. if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  7495. _extendStatics(d, b);
  7496. function __() {
  7497. this.constructor = d;
  7498. }
  7499. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7500. };
  7501. }();
  7502. var __assign = this && this.__assign || function () {
  7503. __assign = Object.assign || function (t) {
  7504. for (var s, i = 1, n = arguments.length; i < n; i++) {
  7505. s = arguments[i];
  7506. for (var p in s) {
  7507. if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  7508. }
  7509. }
  7510. return t;
  7511. };
  7512. return __assign.apply(this, arguments);
  7513. };
  7514. Object.defineProperty(exports, "__esModule", { value: true });
  7515. exports.MDCMenuFoundation = void 0;
  7516. var foundation_1 = __webpack_require__(/*! @material/base/foundation */ "./packages/mdc-base/foundation.ts");
  7517. var constants_1 = __webpack_require__(/*! @material/list/constants */ "./packages/mdc-list/constants.ts");
  7518. var constants_2 = __webpack_require__(/*! ./constants */ "./packages/mdc-menu/constants.ts");
  7519. /** MDC Menu Foundation */
  7520. var MDCMenuFoundation = /** @class */function (_super) {
  7521. __extends(MDCMenuFoundation, _super);
  7522. function MDCMenuFoundation(adapter) {
  7523. var _this = _super.call(this, __assign(__assign({}, MDCMenuFoundation.defaultAdapter), adapter)) || this;
  7524. _this.defaultFocusState = constants_2.DefaultFocusState.LIST_ROOT;
  7525. _this.selectedIndex = -1;
  7526. return _this;
  7527. }
  7528. Object.defineProperty(MDCMenuFoundation, "cssClasses", {
  7529. get: function get() {
  7530. return constants_2.cssClasses;
  7531. },
  7532. enumerable: false,
  7533. configurable: true
  7534. });
  7535. Object.defineProperty(MDCMenuFoundation, "strings", {
  7536. get: function get() {
  7537. return constants_2.strings;
  7538. },
  7539. enumerable: false,
  7540. configurable: true
  7541. });
  7542. Object.defineProperty(MDCMenuFoundation, "numbers", {
  7543. get: function get() {
  7544. return constants_2.numbers;
  7545. },
  7546. enumerable: false,
  7547. configurable: true
  7548. });
  7549. Object.defineProperty(MDCMenuFoundation, "defaultAdapter", {
  7550. /**
  7551. * @see {@link MDCMenuAdapter} for typing information on parameters and return types.
  7552. */
  7553. get: function get() {
  7554. // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
  7555. return {
  7556. addClassToElementAtIndex: function addClassToElementAtIndex() {
  7557. return undefined;
  7558. },
  7559. removeClassFromElementAtIndex: function removeClassFromElementAtIndex() {
  7560. return undefined;
  7561. },
  7562. addAttributeToElementAtIndex: function addAttributeToElementAtIndex() {
  7563. return undefined;
  7564. },
  7565. removeAttributeFromElementAtIndex: function removeAttributeFromElementAtIndex() {
  7566. return undefined;
  7567. },
  7568. getAttributeFromElementAtIndex: function getAttributeFromElementAtIndex() {
  7569. return null;
  7570. },
  7571. elementContainsClass: function elementContainsClass() {
  7572. return false;
  7573. },
  7574. closeSurface: function closeSurface() {
  7575. return undefined;
  7576. },
  7577. getElementIndex: function getElementIndex() {
  7578. return -1;
  7579. },
  7580. notifySelected: function notifySelected() {
  7581. return undefined;
  7582. },
  7583. getMenuItemCount: function getMenuItemCount() {
  7584. return 0;
  7585. },
  7586. focusItemAtIndex: function focusItemAtIndex() {
  7587. return undefined;
  7588. },
  7589. focusListRoot: function focusListRoot() {
  7590. return undefined;
  7591. },
  7592. getSelectedSiblingOfItemAtIndex: function getSelectedSiblingOfItemAtIndex() {
  7593. return -1;
  7594. },
  7595. isSelectableItemAtIndex: function isSelectableItemAtIndex() {
  7596. return false;
  7597. }
  7598. };
  7599. // tslint:enable:object-literal-sort-keys
  7600. },
  7601. enumerable: false,
  7602. configurable: true
  7603. });
  7604. MDCMenuFoundation.prototype.destroy = function () {
  7605. this.adapter.closeSurface();
  7606. };
  7607. MDCMenuFoundation.prototype.handleKeydown = function (evt) {
  7608. var key = evt.key,
  7609. keyCode = evt.keyCode;
  7610. var isTab = key === 'Tab' || keyCode === 9;
  7611. if (isTab) {
  7612. this.adapter.closeSurface( /** skipRestoreFocus */true);
  7613. }
  7614. };
  7615. MDCMenuFoundation.prototype.handleItemAction = function (listItem) {
  7616. var index = this.adapter.getElementIndex(listItem);
  7617. if (index < 0) {
  7618. return;
  7619. }
  7620. this.adapter.notifySelected({ index: index });
  7621. var skipRestoreFocus = this.adapter.getAttributeFromElementAtIndex(index, constants_2.strings.SKIP_RESTORE_FOCUS) === 'true';
  7622. this.adapter.closeSurface(skipRestoreFocus);
  7623. if (this.adapter.isSelectableItemAtIndex(index)) {
  7624. this.setSelectedIndex(index);
  7625. }
  7626. };
  7627. MDCMenuFoundation.prototype.handleMenuSurfaceOpened = function () {
  7628. switch (this.defaultFocusState) {
  7629. case constants_2.DefaultFocusState.FIRST_ITEM:
  7630. this.adapter.focusItemAtIndex(0);
  7631. break;
  7632. case constants_2.DefaultFocusState.LAST_ITEM:
  7633. this.adapter.focusItemAtIndex(this.adapter.getMenuItemCount() - 1);
  7634. break;
  7635. case constants_2.DefaultFocusState.NONE:
  7636. // Do nothing.
  7637. break;
  7638. default:
  7639. this.adapter.focusListRoot();
  7640. break;
  7641. }
  7642. };
  7643. /**
  7644. * Sets default focus state where the menu should focus every time when menu
  7645. * is opened. Focuses the list root (`DefaultFocusState.LIST_ROOT`) element by
  7646. * default.
  7647. */
  7648. MDCMenuFoundation.prototype.setDefaultFocusState = function (focusState) {
  7649. this.defaultFocusState = focusState;
  7650. };
  7651. /** @return Index of the currently selected list item within the menu. */
  7652. MDCMenuFoundation.prototype.getSelectedIndex = function () {
  7653. return this.selectedIndex;
  7654. };
  7655. /**
  7656. * Selects the list item at `index` within the menu.
  7657. * @param index Index of list item within the menu.
  7658. */
  7659. MDCMenuFoundation.prototype.setSelectedIndex = function (index) {
  7660. this.validatedIndex(index);
  7661. if (!this.adapter.isSelectableItemAtIndex(index)) {
  7662. throw new Error('MDCMenuFoundation: No selection group at specified index.');
  7663. }
  7664. var prevSelectedIndex = this.adapter.getSelectedSiblingOfItemAtIndex(index);
  7665. if (prevSelectedIndex >= 0) {
  7666. this.adapter.removeAttributeFromElementAtIndex(prevSelectedIndex, constants_2.strings.ARIA_CHECKED_ATTR);
  7667. this.adapter.removeClassFromElementAtIndex(prevSelectedIndex, constants_2.cssClasses.MENU_SELECTED_LIST_ITEM);
  7668. }
  7669. this.adapter.addClassToElementAtIndex(index, constants_2.cssClasses.MENU_SELECTED_LIST_ITEM);
  7670. this.adapter.addAttributeToElementAtIndex(index, constants_2.strings.ARIA_CHECKED_ATTR, 'true');
  7671. this.selectedIndex = index;
  7672. };
  7673. /**
  7674. * Sets the enabled state to isEnabled for the menu item at the given index.
  7675. * @param index Index of the menu item
  7676. * @param isEnabled The desired enabled state of the menu item.
  7677. */
  7678. MDCMenuFoundation.prototype.setEnabled = function (index, isEnabled) {
  7679. this.validatedIndex(index);
  7680. if (isEnabled) {
  7681. this.adapter.removeClassFromElementAtIndex(index, constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS);
  7682. this.adapter.addAttributeToElementAtIndex(index, constants_2.strings.ARIA_DISABLED_ATTR, 'false');
  7683. } else {
  7684. this.adapter.addClassToElementAtIndex(index, constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS);
  7685. this.adapter.addAttributeToElementAtIndex(index, constants_2.strings.ARIA_DISABLED_ATTR, 'true');
  7686. }
  7687. };
  7688. MDCMenuFoundation.prototype.validatedIndex = function (index) {
  7689. var menuSize = this.adapter.getMenuItemCount();
  7690. var isIndexInRange = index >= 0 && index < menuSize;
  7691. if (!isIndexInRange) {
  7692. throw new Error('MDCMenuFoundation: No list item at specified index.');
  7693. }
  7694. };
  7695. return MDCMenuFoundation;
  7696. }(foundation_1.MDCFoundation);
  7697. exports.MDCMenuFoundation = MDCMenuFoundation;
  7698. // tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
  7699. exports.default = MDCMenuFoundation;
  7700. /***/ }),
  7701. /***/ "./packages/mdc-menu/index.ts":
  7702. /*!************************************!*\
  7703. !*** ./packages/mdc-menu/index.ts ***!
  7704. \************************************/
  7705. /*! no static exports found */
  7706. /***/ (function(module, exports, __webpack_require__) {
  7707. "use strict";
  7708. /**
  7709. * @license
  7710. * Copyright 2019 Google Inc.
  7711. *
  7712. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7713. * of this software and associated documentation files (the "Software"), to deal
  7714. * in the Software without restriction, including without limitation the rights
  7715. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7716. * copies of the Software, and to permit persons to whom the Software is
  7717. * furnished to do so, subject to the following conditions:
  7718. *
  7719. * The above copyright notice and this permission notice shall be included in
  7720. * all copies or substantial portions of the Software.
  7721. *
  7722. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  7723. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  7724. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  7725. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  7726. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  7727. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  7728. * THE SOFTWARE.
  7729. */
  7730. var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
  7731. if (k2 === undefined) k2 = k;
  7732. Object.defineProperty(o, k2, { enumerable: true, get: function get() {
  7733. return m[k];
  7734. } });
  7735. } : function (o, m, k, k2) {
  7736. if (k2 === undefined) k2 = k;
  7737. o[k2] = m[k];
  7738. });
  7739. var __exportStar = this && this.__exportStar || function (m, exports) {
  7740. for (var p in m) {
  7741. if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
  7742. }
  7743. };
  7744. Object.defineProperty(exports, "__esModule", { value: true });
  7745. exports.Corner = void 0;
  7746. var constants_1 = __webpack_require__(/*! @material/menu-surface/constants */ "./packages/mdc-menu-surface/constants.ts"); // for backward compatibility
  7747. Object.defineProperty(exports, "Corner", { enumerable: true, get: function get() {
  7748. return constants_1.Corner;
  7749. } });
  7750. __exportStar(__webpack_require__(/*! ./adapter */ "./packages/mdc-menu/adapter.ts"), exports);
  7751. __exportStar(__webpack_require__(/*! ./component */ "./packages/mdc-menu/component.ts"), exports);
  7752. __exportStar(__webpack_require__(/*! ./constants */ "./packages/mdc-menu/constants.ts"), exports);
  7753. __exportStar(__webpack_require__(/*! ./foundation */ "./packages/mdc-menu/foundation.ts"), exports);
  7754. __exportStar(__webpack_require__(/*! ./types */ "./packages/mdc-menu/types.ts"), exports);
  7755. /***/ }),
  7756. /***/ "./packages/mdc-menu/types.ts":
  7757. /*!************************************!*\
  7758. !*** ./packages/mdc-menu/types.ts ***!
  7759. \************************************/
  7760. /*! no static exports found */
  7761. /***/ (function(module, exports, __webpack_require__) {
  7762. "use strict";
  7763. /**
  7764. * @license
  7765. * Copyright 2019 Google Inc.
  7766. *
  7767. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7768. * of this software and associated documentation files (the "Software"), to deal
  7769. * in the Software without restriction, including without limitation the rights
  7770. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7771. * copies of the Software, and to permit persons to whom the Software is
  7772. * furnished to do so, subject to the following conditions:
  7773. *
  7774. * The above copyright notice and this permission notice shall be included in
  7775. * all copies or substantial portions of the Software.
  7776. *
  7777. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  7778. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  7779. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  7780. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  7781. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  7782. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  7783. * THE SOFTWARE.
  7784. */
  7785. Object.defineProperty(exports, "__esModule", { value: true });
  7786. /***/ })
  7787. /******/ });
  7788. });
  7789. //# sourceMappingURL=mdc.menu.js.map